about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-08 07:08:41 +0000
committerbors <bors@rust-lang.org>2024-10-08 07:08:41 +0000
commitcf24c73141a77db730f4b7fda69dcd7e8b113b51 (patch)
tree036b31c635fb5651cefd0f859046e5a174f8aef2 /compiler/rustc_llvm/llvm-wrapper
parente6c46db4e9fd11e3183c397a59d946731034ede6 (diff)
parentacd64fa0d9e5c17de02a5b2a592163a377e33bcc (diff)
downloadrust-cf24c73141a77db730f4b7fda69dcd7e8b113b51.tar.gz
rust-cf24c73141a77db730f4b7fda69dcd7e8b113b51.zip
Auto merge of #126733 - ZhuUx:llvm-19-adapt, r=Zalathar
[Coverage][MCDC] Adapt mcdc to llvm 19

Related issue: #126672

Also finish task 4 at #124144

[llvm #82448](https://github.com/llvm/llvm-project/pull/82448) has introduced some break changes into mcdc, causing incompatibility between llvm 18 and 19. This draft adapts to that change and gives up supporting for llvm-18.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp45
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp14
2 files changed, 15 insertions, 44 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
index 4532fd8d48d..8ee05977320 100644
--- a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
@@ -88,38 +88,7 @@ struct LLVMRustMCDCParameters {
   LLVMRustMCDCBranchParameters BranchParameters;
 };
 
-// LLVM representations for `MCDCParameters` evolved from LLVM 18 to 19.
-// Look at representations in 18
-// https://github.com/rust-lang/llvm-project/blob/66a2881a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L253-L263
-// and representations in 19
-// https://github.com/llvm/llvm-project/blob/843cc474faefad1d639f4c44c1cf3ad7dbda76c8/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
-#if LLVM_VERSION_LT(19, 0)
-static coverage::CounterMappingRegion::MCDCParameters
-fromRust(LLVMRustMCDCParameters Params) {
-  auto parameter = coverage::CounterMappingRegion::MCDCParameters{};
-  switch (Params.Tag) {
-  case LLVMRustMCDCParametersTag::None:
-    return parameter;
-  case LLVMRustMCDCParametersTag::Decision:
-    parameter.BitmapIdx =
-        static_cast<unsigned>(Params.DecisionParameters.BitmapIdx),
-    parameter.NumConditions =
-        static_cast<unsigned>(Params.DecisionParameters.NumConditions);
-    return parameter;
-  case LLVMRustMCDCParametersTag::Branch:
-    parameter.ID = static_cast<coverage::CounterMappingRegion::MCDCConditionID>(
-        Params.BranchParameters.ConditionID),
-    parameter.FalseID =
-        static_cast<coverage::CounterMappingRegion::MCDCConditionID>(
-            Params.BranchParameters.ConditionIDs[0]),
-    parameter.TrueID =
-        static_cast<coverage::CounterMappingRegion::MCDCConditionID>(
-            Params.BranchParameters.ConditionIDs[1]);
-    return parameter;
-  }
-  report_fatal_error("Bad LLVMRustMCDCParametersTag!");
-}
-#else
+#if LLVM_VERSION_GE(19, 0)
 static coverage::mcdc::Parameters fromRust(LLVMRustMCDCParameters Params) {
   switch (Params.Tag) {
   case LLVMRustMCDCParametersTag::None:
@@ -214,13 +183,17 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
            RustMappingRegions, NumMappingRegions)) {
     MappingRegions.emplace_back(
         fromRust(Region.Count), fromRust(Region.FalseCount),
-#if LLVM_VERSION_LT(19, 0)
-        // LLVM 19 may move this argument to last.
-        fromRust(Region.MCDCParameters),
+#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
+        coverage::CounterMappingRegion::MCDCParameters{},
 #endif
         Region.FileID, Region.ExpandedFileID, // File IDs, then region info.
         Region.LineStart, Region.ColumnStart, Region.LineEnd, Region.ColumnEnd,
-        fromRust(Region.Kind));
+        fromRust(Region.Kind)
+#if LLVM_VERSION_GE(19, 0)
+            ,
+        fromRust(Region.MCDCParameters)
+#endif
+    );
   }
 
   std::vector<coverage::CounterExpression> Expressions;
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index f9fc2bd6da3..8faa5212408 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -1539,23 +1539,21 @@ LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M) {
 
 extern "C" LLVMValueRef
 LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
+#if LLVM_VERSION_GE(19, 0)
   return wrap(llvm::Intrinsic::getDeclaration(
       unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
+#else
+  report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
+#endif
 }
 
 extern "C" LLVMValueRef
 LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
+#if LLVM_VERSION_GE(19, 0)
   return wrap(llvm::Intrinsic::getDeclaration(
       unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
-}
-
-extern "C" LLVMValueRef
-LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
-#if LLVM_VERSION_LT(19, 0)
-  return wrap(llvm::Intrinsic::getDeclaration(
-      unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
 #else
-  report_fatal_error("LLVM 18.0 is required for mcdc intrinsic functions");
+  report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
 #endif
 }