Skip to content

Commit 3609cec

Browse files
author
zhuyunxing
committed
coverage. Add llvm wrapper to get mcdc intrinsic functions
1 parent afaaf37 commit 3609cec

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,114 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12401240
}
12411241
}
12421242

1243+
fn mcdc_parameters(
1244+
&mut self,
1245+
fn_name: Self::Value,
1246+
hash: Self::Value,
1247+
bitmap_bytes: Self::Value,
1248+
) {
1249+
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);
1250+
1251+
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
1252+
let llty = self.cx.type_func(
1253+
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
1254+
self.cx.type_void(),
1255+
);
1256+
let args = &[fn_name, hash, bitmap_bytes];
1257+
let args = self.check_call("call", llty, llfn, args);
1258+
1259+
unsafe {
1260+
let _ = llvm::LLVMRustBuildCall(
1261+
self.llbuilder,
1262+
llty,
1263+
llfn,
1264+
args.as_ptr() as *const &llvm::Value,
1265+
args.len() as c_uint,
1266+
[].as_ptr(),
1267+
0 as c_uint,
1268+
);
1269+
}
1270+
}
1271+
1272+
fn mcdc_tvbitmap_update(
1273+
&mut self,
1274+
fn_name: Self::Value,
1275+
hash: Self::Value,
1276+
bitmap_bytes: Self::Value,
1277+
bitmap_index: Self::Value,
1278+
mcdc_temp: Self::Value,
1279+
) {
1280+
debug!(
1281+
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
1282+
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
1283+
);
1284+
1285+
let llfn =
1286+
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
1287+
let llty = self.cx.type_func(
1288+
&[
1289+
self.cx.type_ptr(),
1290+
self.cx.type_i64(),
1291+
self.cx.type_i32(),
1292+
self.cx.type_i32(),
1293+
self.cx.type_ptr(),
1294+
],
1295+
self.cx.type_void(),
1296+
);
1297+
let args = &[fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp];
1298+
let args = self.check_call("call", llty, llfn, args);
1299+
unsafe {
1300+
let _ = llvm::LLVMRustBuildCall(
1301+
self.llbuilder,
1302+
llty,
1303+
llfn,
1304+
args.as_ptr() as *const &llvm::Value,
1305+
args.len() as c_uint,
1306+
[].as_ptr(),
1307+
0 as c_uint,
1308+
);
1309+
}
1310+
}
1311+
1312+
fn mcdc_condbitmap_update(
1313+
&mut self,
1314+
fn_name: Self::Value,
1315+
hash: Self::Value,
1316+
cond_loc: Self::Value,
1317+
mcdc_temp: Self::Value,
1318+
bool_value: Self::Value,
1319+
) {
1320+
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
1321+
let llty = self.cx.type_func(
1322+
&[
1323+
self.cx.type_ptr(),
1324+
self.cx.type_i64(),
1325+
self.cx.type_i32(),
1326+
self.cx.type_ptr(),
1327+
self.cx.type_bool(),
1328+
],
1329+
self.cx.type_void(),
1330+
);
1331+
let args = &[fn_name, hash, cond_loc, mcdc_temp, bool_value];
1332+
let args = self.check_call("call", llty, llfn, args);
1333+
unsafe {
1334+
let _ = llvm::LLVMRustBuildCall(
1335+
self.llbuilder,
1336+
llty,
1337+
llfn,
1338+
args.as_ptr() as *const &llvm::Value,
1339+
args.len() as c_uint,
1340+
[].as_ptr(),
1341+
0 as c_uint,
1342+
);
1343+
}
1344+
}
1345+
1346+
fn mcdc_condbitmap_reset(&mut self, mcdc_temp: Self::Value) {
1347+
let i32_align = self.tcx().data_layout.i32_align.abi;
1348+
self.store(self.const_i32(0), mcdc_temp, i32_align);
1349+
}
1350+
12431351
fn call(
12441352
&mut self,
12451353
llty: &'ll Type,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,10 @@ extern "C" {
16311631

16321632
// Miscellaneous instructions
16331633
pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
1634+
pub fn LLVMRustGetInstrProfMCDCParametersIntrinsic(M: &Module) -> &Value;
1635+
pub fn LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(M: &Module) -> &Value;
1636+
pub fn LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(M: &Module) -> &Value;
1637+
16341638
pub fn LLVMRustBuildCall<'a>(
16351639
B: &Builder<'a>,
16361640
Ty: &'a Type,

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,33 @@ pub trait BuilderMethods<'a, 'tcx>:
405405
index: Self::Value,
406406
);
407407

408+
fn mcdc_parameters(
409+
&mut self,
410+
fn_name: Self::Value,
411+
hash: Self::Value,
412+
bitmap_bytes: Self::Value,
413+
);
414+
415+
fn mcdc_condbitmap_update(
416+
&mut self,
417+
fn_name: Self::Value,
418+
hash: Self::Value,
419+
cond_loc: Self::Value,
420+
mcdc_temp: Self::Value,
421+
bool_value: Self::Value,
422+
);
423+
424+
fn mcdc_tvbitmap_update(
425+
&mut self,
426+
fn_name: Self::Value,
427+
hash: Self::Value,
428+
bitmap_bytes: Self::Value,
429+
bitmap_index: Self::Value,
430+
mcdc_temp: Self::Value,
431+
);
432+
433+
fn mcdc_condbitmap_reset(&mut self, mcdc_temp: Self::Value);
434+
408435
fn call(
409436
&mut self,
410437
llty: Self::Type,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,21 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M)
15461546
unwrap(M), llvm::Intrinsic::instrprof_increment));
15471547
}
15481548

1549+
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
1550+
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1551+
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_parameters));
1552+
}
1553+
1554+
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
1555+
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1556+
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1557+
}
1558+
1559+
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
1560+
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1561+
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
1562+
}
1563+
15491564
extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,
15501565
LLVMValueRef Dst, unsigned DstAlign,
15511566
LLVMValueRef Src, unsigned SrcAlign,

0 commit comments

Comments
 (0)