Skip to content

Commit b3d6585

Browse files
committed
coverage: Emit MC/DC intrinsics using the normal helper method
1 parent 4923e85 commit b3d6585

File tree

5 files changed

+14
-77
lines changed

5 files changed

+14
-77
lines changed

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+9-46
Original file line numberDiff line numberDiff line change
@@ -1654,80 +1654,43 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16541654
///
16551655
/// [`CodeGenPGO::emitMCDCParameters`]:
16561656
/// https://github.com/rust-lang/llvm-project/blob/5399a24/clang/lib/CodeGen/CodeGenPGO.cpp#L1124
1657+
#[instrument(level = "debug", skip(self))]
16571658
pub(crate) fn mcdc_parameters(
16581659
&mut self,
16591660
fn_name: &'ll Value,
16601661
hash: &'ll Value,
16611662
bitmap_bits: &'ll Value,
16621663
) {
1663-
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bits);
1664-
16651664
assert!(
16661665
crate::llvm_util::get_version() >= (19, 0, 0),
16671666
"MCDC intrinsics require LLVM 19 or later"
16681667
);
1669-
1670-
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
1671-
let llty = self.cx.type_func(
1672-
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
1673-
self.cx.type_void(),
1674-
);
1675-
let args = &[fn_name, hash, bitmap_bits];
1676-
let args = self.check_call("call", llty, llfn, args);
1677-
1678-
unsafe {
1679-
let _ = llvm::LLVMRustBuildCall(
1680-
self.llbuilder,
1681-
llty,
1682-
llfn,
1683-
args.as_ptr() as *const &llvm::Value,
1684-
args.len() as c_uint,
1685-
[].as_ptr(),
1686-
0 as c_uint,
1687-
);
1688-
}
1668+
self.call_intrinsic("llvm.instrprof.mcdc.parameters", &[fn_name, hash, bitmap_bits]);
16891669
}
16901670

1671+
#[instrument(level = "debug", skip(self))]
16911672
pub(crate) fn mcdc_tvbitmap_update(
16921673
&mut self,
16931674
fn_name: &'ll Value,
16941675
hash: &'ll Value,
16951676
bitmap_index: &'ll Value,
16961677
mcdc_temp: &'ll Value,
16971678
) {
1698-
debug!(
1699-
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?})",
1700-
fn_name, hash, bitmap_index, mcdc_temp
1701-
);
17021679
assert!(
17031680
crate::llvm_util::get_version() >= (19, 0, 0),
17041681
"MCDC intrinsics require LLVM 19 or later"
17051682
);
1706-
1707-
let llfn =
1708-
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
1709-
let llty = self.cx.type_func(
1710-
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32(), self.cx.type_ptr()],
1711-
self.cx.type_void(),
1712-
);
17131683
let args = &[fn_name, hash, bitmap_index, mcdc_temp];
1714-
let args = self.check_call("call", llty, llfn, args);
1715-
unsafe {
1716-
let _ = llvm::LLVMRustBuildCall(
1717-
self.llbuilder,
1718-
llty,
1719-
llfn,
1720-
args.as_ptr() as *const &llvm::Value,
1721-
args.len() as c_uint,
1722-
[].as_ptr(),
1723-
0 as c_uint,
1724-
);
1725-
}
1684+
self.call_intrinsic("llvm.instrprof.mcdc.tvbitmap.update", args);
1685+
}
1686+
1687+
#[instrument(level = "debug", skip(self))]
1688+
pub(crate) fn mcdc_condbitmap_reset(&mut self, mcdc_temp: &'ll Value) {
17261689
self.store(self.const_i32(0), mcdc_temp, self.tcx.data_layout.i32_align.abi);
17271690
}
17281691

1692+
#[instrument(level = "debug", skip(self))]
17291693
pub(crate) fn mcdc_condbitmap_update(&mut self, cond_index: &'ll Value, mcdc_temp: &'ll Value) {
1730-
debug!("mcdc_condbitmap_update() with args ({:?}, {:?})", cond_index, mcdc_temp);
17311694
assert!(
17321695
crate::llvm_util::get_version() >= (19, 0, 0),
17331696
"MCDC intrinsics require LLVM 19 or later"

Diff for: compiler/rustc_codegen_llvm/src/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ impl<'ll> CodegenCx<'ll, '_> {
10991099

11001100
if self.sess().instrument_coverage() {
11011101
ifn!("llvm.instrprof.increment", fn(ptr, t_i64, t_i32, t_i32) -> void);
1102+
if crate::llvm_util::get_version() >= (19, 0, 0) {
1103+
ifn!("llvm.instrprof.mcdc.parameters", fn(ptr, t_i64, t_i32) -> void);
1104+
ifn!("llvm.instrprof.mcdc.tvbitmap.update", fn(ptr, t_i64, t_i32, ptr) -> void);
1105+
}
11021106
}
11031107

11041108
ifn!("llvm.type.test", fn(ptr, t_metadata) -> i1);

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
208208
let hash = bx.const_u64(function_coverage_info.function_source_hash);
209209
let bitmap_index = bx.const_u32(bitmap_idx);
210210
bx.mcdc_tvbitmap_update(fn_name, hash, bitmap_index, cond_bitmap);
211+
bx.mcdc_condbitmap_reset(cond_bitmap);
211212
}
212213
}
213214
}

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1615,9 +1615,6 @@ unsafe extern "C" {
16151615
pub fn LLVMRustSetAllowReassoc(Instr: &Value);
16161616

16171617
// Miscellaneous instructions
1618-
pub fn LLVMRustGetInstrProfMCDCParametersIntrinsic(M: &Module) -> &Value;
1619-
pub fn LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(M: &Module) -> &Value;
1620-
16211618
pub fn LLVMRustBuildCall<'a>(
16221619
B: &Builder<'a>,
16231620
Ty: &'a Type,

Diff for: compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-28
Original file line numberDiff line numberDiff line change
@@ -1531,34 +1531,6 @@ extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMTypeRef Ty,
15311531
ArrayRef<OperandBundleDef>(OpBundles)));
15321532
}
15331533

1534-
extern "C" LLVMValueRef
1535-
LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
1536-
#if LLVM_VERSION_LT(19, 0)
1537-
report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
1538-
#endif
1539-
#if LLVM_VERSION_GE(20, 0)
1540-
return wrap(llvm::Intrinsic::getOrInsertDeclaration(
1541-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
1542-
#else
1543-
return wrap(llvm::Intrinsic::getDeclaration(
1544-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
1545-
#endif
1546-
}
1547-
1548-
extern "C" LLVMValueRef
1549-
LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
1550-
#if LLVM_VERSION_LT(19, 0)
1551-
report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
1552-
#endif
1553-
#if LLVM_VERSION_GE(20, 0)
1554-
return wrap(llvm::Intrinsic::getOrInsertDeclaration(
1555-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1556-
#else
1557-
return wrap(llvm::Intrinsic::getDeclaration(
1558-
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1559-
#endif
1560-
}
1561-
15621534
extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst,
15631535
unsigned DstAlign, LLVMValueRef Src,
15641536
unsigned SrcAlign,

0 commit comments

Comments
 (0)