@@ -16,14 +16,14 @@ use rustc_codegen_ssa::common::TypeKind;
1616use rustc_codegen_ssa:: glue;
1717use rustc_codegen_ssa:: mir:: operand:: { OperandRef , OperandValue } ;
1818use rustc_codegen_ssa:: mir:: place:: PlaceRef ;
19+ use rustc_codegen_ssa:: mir:: FunctionCx ;
1920use rustc_codegen_ssa:: traits:: * ;
2021use rustc_codegen_ssa:: MemFlags ;
2122use rustc_hir as hir;
2223use rustc_middle:: ty:: layout:: { FnAbiExt , HasTyCtxt } ;
2324use rustc_middle:: ty:: { self , Ty } ;
2425use rustc_middle:: { bug, span_bug} ;
2526use rustc_span:: Span ;
26- use rustc_span:: Symbol ;
2727use rustc_target:: abi:: { self , HasDataLayout , LayoutOf , Primitive } ;
2828use rustc_target:: spec:: PanicStrategy ;
2929
@@ -82,14 +82,14 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Valu
8282}
8383
8484impl IntrinsicCallMethods < ' tcx > for Builder < ' a , ' ll , ' tcx > {
85- fn codegen_intrinsic_call (
85+ fn codegen_intrinsic_call < ' b , Bx : BuilderMethods < ' b , ' tcx > > (
8686 & mut self ,
87+ fx : & FunctionCx < ' b , ' tcx , Bx > ,
8788 instance : ty:: Instance < ' tcx > ,
8889 fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
8990 args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
9091 llresult : & ' ll Value ,
9192 span : Span ,
92- caller_instance : ty:: Instance < ' tcx > ,
9393 ) {
9494 let tcx = self . tcx ;
9595 let callee_ty = instance. monomorphic_ty ( tcx) ;
@@ -141,26 +141,17 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
141141 self . call ( llfn, & [ ] , None )
142142 }
143143 "count_code_region" => {
144- if let ty:: InstanceDef :: Item ( fn_def_id) = caller_instance. def {
145- let caller_fn_path = tcx. def_path_str ( fn_def_id) ;
146- debug ! (
147- "count_code_region to llvm.instrprof.increment(fn_name={})" ,
148- caller_fn_path
149- ) ;
150-
151- // FIXME(richkadel): (1) Replace raw function name with mangled function name;
152- // (2) Replace hardcoded `1234` in `hash` with a computed hash (as discussed in)
153- // the MCP (compiler-team/issues/278); and replace the hardcoded `1` for
154- // `num_counters` with the actual number of counters per function (when the
155- // changes are made to inject more than one counter per function).
156- let ( fn_name, _len_val) = self . const_str ( Symbol :: intern ( & caller_fn_path) ) ;
157- let index = args[ 0 ] . immediate ( ) ;
158- let hash = self . const_u64 ( 1234 ) ;
159- let num_counters = self . const_u32 ( 1 ) ;
160- self . instrprof_increment ( fn_name, hash, num_counters, index)
161- } else {
162- bug ! ( "intrinsic count_code_region: no src.instance" ) ;
163- }
144+ let coverage_data = fx. mir . coverage_data . as_ref ( ) . unwrap ( ) ;
145+ let mangled_fn = tcx. symbol_name ( fx. instance ) ;
146+ let ( mangled_fn_name, _len_val) = self . const_str ( mangled_fn. name ) ;
147+ let hash = self . const_u64 ( coverage_data. hash ) ;
148+ let index = args[ 0 ] . immediate ( ) ;
149+ let num_counters = self . const_u32 ( coverage_data. num_counters as u32 ) ;
150+ debug ! (
151+ "count_code_region to LLVM intrinsic instrprof.increment(fn_name={}, hash={:?}, num_counters={:?}, index={:?})" ,
152+ mangled_fn. name, hash, index, num_counters
153+ ) ;
154+ self . instrprof_increment ( mangled_fn_name, hash, num_counters, index)
164155 }
165156 "va_start" => self . va_start ( args[ 0 ] . immediate ( ) ) ,
166157 "va_end" => self . va_end ( args[ 0 ] . immediate ( ) ) ,
0 commit comments