Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renjisann/add tests #2

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b260126
coverage. Add mcdc coverage option
Apr 2, 2024
c7071c2
coverage. Generate mcdc coverage mappings
Apr 2, 2024
94f2998
coverage. Add llvm wrapper to get mcdc intrinsic functions
Apr 2, 2024
248e1f6
coverage. Generate mcdc instrument when lowering to ir
Apr 2, 2024
0410a96
coverage. fix error on computing conditions num of decisions
Apr 2, 2024
24344d3
coverage. Add warning for decisions with too many conditions
Apr 2, 2024
305b94c
coverage. Add BlockMarker for decisions and inject mcdc statements
Apr 2, 2024
75608af
coverage. Add comment for some functions
Apr 2, 2024
d8f3dde
coverage. Do not check raw logical expressions temporarily
Apr 2, 2024
6cf7f5d
coverage. Let coverage-dump support parsing mcdc info
Apr 3, 2024
5bdc58a
coverage. Add mcdc test for if
Apr 3, 2024
da99de4
coverage. put mcdc warnings in alphabetical order
Apr 3, 2024
e34f966
coverage. MC/DC analysis ignores decisions with only one condition
Apr 3, 2024
55279aa
coverage. Fix mcdc analysis cannot work for nesting if
Apr 3, 2024
482d32e
coverage. Add mcdc test for nested if
Apr 3, 2024
d72e711
coverage. Change assign statements cl does not support on c++17
Lambdaris Apr 4, 2024
eaa4f73
coverage. Add unimplemented mcdc functions for gcc codegen
Lambdaris Apr 4, 2024
4713614
coverage. Allow multi options passed to coverage-options
Lambdaris Apr 4, 2024
9c357e6
coverage. Replace line numbers in mcdc reports with LL
Lambdaris Apr 4, 2024
eeb9fd4
coverage. Improve code style
Lambdaris Apr 4, 2024
c8bf124
coverage. Fix missing LL line number replacement
Lambdaris Apr 4, 2024
29e0881
coverage. Adopt a nicer dereference style for BcbMappingKind
Lambdaris Apr 4, 2024
391ad51
coverage. Adopt nicer code style
Apr 7, 2024
3024f22
coverage. Flatten ffi for MCDCParameter
Apr 7, 2024
2c054b0
coverage. Split structures for mcdc branches and normal branches
Apr 7, 2024
58f62e8
coverage. Allow to be compiled on llvm-17
Apr 8, 2024
2788afe
coverage. Gate mcdc tests by @min-llvm-version
Apr 8, 2024
4723dd0
coverage. Change doc comments of MCDCState::record_conditions to idio…
Apr 8, 2024
8b74525
coverage. Add test cases for while-loops instrumentation
RenjiSann Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
TyAndLayout,
};
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt, Instance};
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::Span;
use rustc_target::abi::{
Expand Down Expand Up @@ -1736,6 +1736,41 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
) {
unimplemented!();
}

fn mcdc_parameters(
&mut self,
_fn_name: Self::Value,
_hash: Self::Value,
_bitmap_bytes: Self::Value,
) -> Self::Value {
unimplemented!();
}

fn mcdc_tvbitmap_update(
&mut self,
_fn_name: Self::Value,
_hash: Self::Value,
_bitmap_bytes: Self::Value,
_bitmap_index: Self::Value,
_mcdc_temp: Self::Value,
) {
unimplemented!();
}

fn mcdc_condbitmap_update(
&mut self,
_fn_name: Self::Value,
_hash: Self::Value,
_cond_loc: Self::Value,
_mcdc_temp: Self::Value,
_bool_value: Self::Value,
) {
unimplemented!();
}

fn mcdc_condbitmap_reset(&mut self, _mcdc_temp: Self::Value) {
unimplemented!();
}
}

impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
Expand Down
129 changes: 128 additions & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::OptLevel;
Expand Down Expand Up @@ -1238,6 +1238,133 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

fn mcdc_parameters(
&mut self,
fn_name: Self::Value,
hash: Self::Value,
bitmap_bytes: Self::Value,
) -> &'ll Value {
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);

assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");

let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
self.cx.type_void(),
);
let args = &[fn_name, hash, bitmap_bytes];
let args = self.check_call("call", llty, llfn, args);

unsafe {
let _ = llvm::LLVMRustBuildCall(
self.llbuilder,
llty,
llfn,
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
[].as_ptr(),
0 as c_uint,
);
// Create condition bitmap named `mcdc.addr`.
let mut bx = Builder::with_cx(self.cx);
bx.position_at_start(llvm::LLVMGetFirstBasicBlock(self.llfn()));
let cond_bitmap = {
let alloca =
llvm::LLVMBuildAlloca(bx.llbuilder, bx.cx.type_i32(), c"mcdc.addr".as_ptr());
llvm::LLVMSetAlignment(alloca, 4);
alloca
};
bx.store(self.const_i32(0), cond_bitmap, self.tcx().data_layout.i32_align.abi);
cond_bitmap
}
}

fn mcdc_tvbitmap_update(
&mut self,
fn_name: Self::Value,
hash: Self::Value,
bitmap_bytes: Self::Value,
bitmap_index: Self::Value,
mcdc_temp: Self::Value,
) {
debug!(
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
);
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");

let llfn =
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[
self.cx.type_ptr(),
self.cx.type_i64(),
self.cx.type_i32(),
self.cx.type_i32(),
self.cx.type_ptr(),
],
self.cx.type_void(),
);
let args = &[fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp];
let args = self.check_call("call", llty, llfn, args);
unsafe {
let _ = llvm::LLVMRustBuildCall(
self.llbuilder,
llty,
llfn,
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
[].as_ptr(),
0 as c_uint,
);
}
}

fn mcdc_condbitmap_update(
&mut self,
fn_name: Self::Value,
hash: Self::Value,
cond_loc: Self::Value,
mcdc_temp: Self::Value,
bool_value: Self::Value,
) {
debug!(
"mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
fn_name, hash, cond_loc, mcdc_temp, bool_value
);
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[
self.cx.type_ptr(),
self.cx.type_i64(),
self.cx.type_i32(),
self.cx.type_ptr(),
self.cx.type_i1(),
],
self.cx.type_void(),
);
let args = &[fn_name, hash, cond_loc, mcdc_temp, bool_value];
self.check_call("call", llty, llfn, args);
unsafe {
let _ = llvm::LLVMRustBuildCall(
self.llbuilder,
llty,
llfn,
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
[].as_ptr(),
0 as c_uint,
);
}
}

fn mcdc_condbitmap_reset(&mut self, mcdc_temp: Self::Value) {
let i32_align = self.tcx().data_layout.i32_align.abi;
self.store(self.const_i32(0), mcdc_temp, i32_align);
}

fn call(
&mut self,
llty: &'ll Type,
Expand Down
Loading