Skip to content

Commit f789616

Browse files
committed
mcdc-coverage: Add utils for instrprof.mcdc.parameters intrinsic
1 parent 5c5cd19 commit f789616

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,38 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12381238
}
12391239
}
12401240

1241+
fn instrprof_mcdc_parameters(
1242+
&mut self,
1243+
fn_name: Self::Value,
1244+
hash: Self::Value,
1245+
num_bitmap_bytes: Self::Value,
1246+
) {
1247+
debug!(
1248+
"instrprof_mcdc_parameters() with args ({:?}, {:?}, {:?})",
1249+
fn_name, hash, num_bitmap_bytes
1250+
);
1251+
1252+
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
1253+
let llty = self.cx.type_func(
1254+
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
1255+
self.cx.type_void(),
1256+
);
1257+
let args = &[fn_name, hash, num_bitmap_bytes];
1258+
let args = self.check_call("call", llty, llfn, args);
1259+
1260+
unsafe {
1261+
let _ = llvm::LLVMRustBuildCall(
1262+
self.llbuilder,
1263+
llty,
1264+
llfn,
1265+
args.as_ptr() as *const &llvm::Value,
1266+
args.len() as c_uint,
1267+
[].as_ptr(),
1268+
0 as c_uint,
1269+
);
1270+
}
1271+
}
1272+
12411273
fn call(
12421274
&mut self,
12431275
llty: &'ll Type,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,7 @@ extern "C" {
16311631

16321632
// Miscellaneous instructions
16331633
pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
1634+
pub fn LLVMRustGetInstrProfMCDCParametersIntrinsic(M: &Module) -> &Value;
16341635
pub fn LLVMRustBuildCall<'a>(
16351636
B: &Builder<'a>,
16361637
Ty: &'a Type,

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ pub trait BuilderMethods<'a, 'tcx>:
382382
index: Self::Value,
383383
);
384384

385+
fn instrprof_mcdc_parameters(
386+
&mut self,
387+
fn_name: Self::Value,
388+
hash: Self::Value,
389+
num_bitmap_bytes: Self::Value
390+
);
391+
385392
fn call(
386393
&mut self,
387394
llty: Self::Type,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,11 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M)
15281528
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_increment));
15291529
}
15301530

1531+
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
1532+
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1533+
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_parameters));
1534+
}
1535+
15311536
extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,
15321537
LLVMValueRef Dst, unsigned DstAlign,
15331538
LLVMValueRef Src, unsigned SrcAlign,

0 commit comments

Comments
 (0)