@@ -23,7 +23,6 @@ use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
2323use rustc_middle:: ty:: { self , Ty } ;
2424use rustc_middle:: { bug, span_bug} ;
2525use rustc_span:: Span ;
26- use rustc_span:: Symbol ;
2726use rustc_target:: abi:: { self , HasDataLayout , LayoutOf , Primitive } ;
2827use rustc_target:: spec:: PanicStrategy ;
2928
@@ -141,26 +140,20 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
141140 self . call ( llfn, & [ ] , None )
142141 }
143142 "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- }
143+ // FIXME(richkadel): The current implementation assumes the MIR for the given
144+ // caller_instance represents a single function. Validate and/or correct if inlining
145+ // and/or monomorphization invalidates these assumptions.
146+ let coverage_data = tcx. coverage_data ( caller_instance. def_id ( ) ) ;
147+ let mangled_fn = tcx. symbol_name ( caller_instance) ;
148+ let ( mangled_fn_name, _len_val) = self . const_str ( mangled_fn. name ) ;
149+ let hash = self . const_u64 ( coverage_data. hash ) ;
150+ let num_counters = self . const_u32 ( coverage_data. num_counters ) ;
151+ let index = args[ 0 ] . immediate ( ) ;
152+ debug ! (
153+ "count_code_region to LLVM intrinsic instrprof.increment(fn_name={}, hash={:?}, num_counters={:?}, index={:?})" ,
154+ mangled_fn. name, hash, num_counters, index
155+ ) ;
156+ self . instrprof_increment ( mangled_fn_name, hash, num_counters, index)
164157 }
165158 "va_start" => self . va_start ( args[ 0 ] . immediate ( ) ) ,
166159 "va_end" => self . va_end ( args[ 0 ] . immediate ( ) ) ,
0 commit comments