Skip to content

Commit 25768f8

Browse files
committed
mcdc-coverage: Add FFI equivalents of MCDC bitmap update intrinsics
1 parent 9fea26a commit 25768f8

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+84
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,90 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12701270
}
12711271
}
12721272

1273+
fn instrprof_mcdc_condbitmap_update(
1274+
&mut self,
1275+
fn_name: Self::Value,
1276+
hash: Self::Value,
1277+
cond_id: Self::Value,
1278+
cond_bitmap_addr: Self::Value,
1279+
cond_result: Self::Value,
1280+
) {
1281+
debug!(
1282+
"instrprof_mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
1283+
fn_name, hash, cond_id, cond_bitmap_addr, cond_result
1284+
);
1285+
1286+
let llfn =
1287+
unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapUpdateIntrinsic(self.cx().llmod) };
1288+
let llty = self.cx.type_func(
1289+
&[
1290+
self.cx.type_ptr(),
1291+
self.cx.type_i64(),
1292+
self.cx.type_i32(),
1293+
self.cx.type_ptr(),
1294+
self.cx.type_i1(),
1295+
],
1296+
self.cx.type_void(),
1297+
);
1298+
1299+
let args = &[fn_name, hash, cond_id, cond_bitmap_addr, cond_result];
1300+
let args = self.check_call("call", llty, llfn, args);
1301+
1302+
unsafe {
1303+
let _ = llvm::LLVMRustBuildCall(
1304+
self.llbuilder,
1305+
llty,
1306+
llfn,
1307+
args.as_ptr(),
1308+
args.len() as c_uint,
1309+
[].as_ptr(),
1310+
0 as c_uint,
1311+
);
1312+
}
1313+
}
1314+
1315+
fn instrprof_mcdc_tvbitmap_update(
1316+
&mut self,
1317+
fn_name: Self::Value,
1318+
hash: Self::Value,
1319+
needed_bytes: Self::Value,
1320+
bitmap_idx: Self::Value,
1321+
cond_bitmap_addr: Self::Value,
1322+
) {
1323+
debug!(
1324+
"instrprof_mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
1325+
fn_name, hash, needed_bytes, bitmap_idx, cond_bitmap_addr
1326+
);
1327+
1328+
let llfn =
1329+
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
1330+
let llty = self.cx.type_func(
1331+
&[
1332+
self.cx.type_ptr(),
1333+
self.cx.type_i64(),
1334+
self.cx.type_i32(),
1335+
self.cx.type_i32(),
1336+
self.cx.type_ptr(),
1337+
],
1338+
self.cx.type_void(),
1339+
);
1340+
1341+
let args = &[fn_name, hash, needed_bytes, bitmap_idx, cond_bitmap_addr];
1342+
let args = self.check_call("call", llty, llfn, args);
1343+
1344+
unsafe {
1345+
let _ = llvm::LLVMRustBuildCall(
1346+
self.llbuilder,
1347+
llty,
1348+
llfn,
1349+
args.as_ptr(),
1350+
args.len() as c_uint,
1351+
[].as_ptr(),
1352+
0 as c_uint,
1353+
);
1354+
}
1355+
}
1356+
12731357
fn call(
12741358
&mut self,
12751359
llty: &'ll Type,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,8 @@ extern "C" {
16321632
// Miscellaneous instructions
16331633
pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
16341634
pub fn LLVMRustGetInstrProfMCDCParametersIntrinsic(M: &Module) -> &Value;
1635+
pub fn LLVMRustGetInstrProfMCDCCondBitmapUpdateIntrinsic(M: &Module) -> &Value;
1636+
pub fn LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(M: &Module) -> &Value;
16351637
pub fn LLVMRustBuildCall<'a>(
16361638
B: &Builder<'a>,
16371639
Ty: &'a Type,

compiler/rustc_codegen_ssa/src/traits/builder.rs

+18
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,24 @@ pub trait BuilderMethods<'a, 'tcx>:
389389
num_bitmap_bytes: Self::Value
390390
);
391391

392+
fn instrprof_mcdc_condbitmap_update(
393+
&mut self,
394+
fn_name: Self::Value,
395+
hash: Self::Value,
396+
cond_id: Self::Value,
397+
cond_bitmap_addr: Self::Value,
398+
cond_result: Self::Value,
399+
);
400+
401+
fn instrprof_mcdc_tvbitmap_update(
402+
&mut self,
403+
fn_name: Self::Value,
404+
hash: Self::Value,
405+
needed_bytes: Self::Value,
406+
bitmap_idx: Self::Value,
407+
cond_bitmap_addr: Self::Value,
408+
);
409+
392410
fn call(
393411
&mut self,
394412
llty: Self::Type,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,16 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRe
15331533
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_parameters));
15341534
}
15351535

1536+
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCCondBitmapUpdateIntrinsic(LLVMModuleRef M) {
1537+
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1538+
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
1539+
}
1540+
1541+
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
1542+
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1543+
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1544+
}
1545+
15361546
extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,
15371547
LLVMValueRef Dst, unsigned DstAlign,
15381548
LLVMValueRef Src, unsigned SrcAlign,

0 commit comments

Comments
 (0)