3 use rustc_middle::mir::coverage::*;
4 use rustc_middle::mir::Coverage;
5 use rustc_middle::mir::SourceScope;
9 impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10 pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage, scope: SourceScope) {
11 // Determine the instance that coverage data was originally generated for.
12 let instance = if let Some(inlined) = scope.inlined_instance(&self.mir.source_scopes) {
13 self.monomorphize(inlined)
18 let Coverage { kind, code_region } = coverage;
20 CoverageKind::Counter { function_source_hash, id } => {
21 if bx.set_function_source_hash(instance, function_source_hash) {
22 // If `set_function_source_hash()` returned true, the coverage map is enabled,
23 // so continue adding the counter.
24 if let Some(code_region) = code_region {
25 // Note: Some counters do not have code regions, but may still be referenced
26 // from expressions. In that case, don't add the counter to the coverage map,
27 // but do inject the counter intrinsic.
28 bx.add_coverage_counter(instance, id, code_region);
31 let coverageinfo = bx.tcx().coverageinfo(instance.def);
33 let fn_name = bx.get_pgo_func_name_var(instance);
34 let hash = bx.const_u64(function_source_hash);
35 let num_counters = bx.const_u32(coverageinfo.num_counters);
36 let index = bx.const_u32(id.zero_based_index());
38 "codegen intrinsic instrprof.increment(fn_name={:?}, hash={:?}, num_counters={:?}, index={:?})",
39 fn_name, hash, num_counters, index,
41 bx.instrprof_increment(fn_name, hash, num_counters, index);
44 CoverageKind::Expression { id, lhs, op, rhs } => {
45 bx.add_coverage_counter_expression(instance, id, lhs, op, rhs, code_region);
47 CoverageKind::Unreachable => {
48 bx.add_coverage_unreachable(
50 code_region.expect("unreachable regions always have code regions"),