@@ -16,14 +16,14 @@ use rustc_codegen_ssa::common::TypeKind;
16
16
use rustc_codegen_ssa:: glue;
17
17
use rustc_codegen_ssa:: mir:: operand:: { OperandRef , OperandValue } ;
18
18
use rustc_codegen_ssa:: mir:: place:: PlaceRef ;
19
+ use rustc_codegen_ssa:: mir:: FunctionCx ;
19
20
use rustc_codegen_ssa:: traits:: * ;
20
21
use rustc_codegen_ssa:: MemFlags ;
21
22
use rustc_hir as hir;
22
23
use rustc_middle:: ty:: layout:: { FnAbiExt , HasTyCtxt } ;
23
24
use rustc_middle:: ty:: { self , Ty } ;
24
25
use rustc_middle:: { bug, span_bug} ;
25
26
use rustc_span:: Span ;
26
- use rustc_span:: Symbol ;
27
27
use rustc_target:: abi:: { self , HasDataLayout , LayoutOf , Primitive } ;
28
28
use rustc_target:: spec:: PanicStrategy ;
29
29
@@ -82,14 +82,14 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Valu
82
82
}
83
83
84
84
impl IntrinsicCallMethods < ' tcx > for Builder < ' a , ' ll , ' tcx > {
85
- fn codegen_intrinsic_call (
85
+ fn codegen_intrinsic_call < ' b , Bx : BuilderMethods < ' b , ' tcx > > (
86
86
& mut self ,
87
+ fx : & FunctionCx < ' b , ' tcx , Bx > ,
87
88
instance : ty:: Instance < ' tcx > ,
88
89
fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
89
90
args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
90
91
llresult : & ' ll Value ,
91
92
span : Span ,
92
- caller_instance : ty:: Instance < ' tcx > ,
93
93
) {
94
94
let tcx = self . tcx ;
95
95
let callee_ty = instance. monomorphic_ty ( tcx) ;
@@ -141,26 +141,17 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
141
141
self . call ( llfn, & [ ] , None )
142
142
}
143
143
"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)
164
155
}
165
156
"va_start" => self . va_start ( args[ 0 ] . immediate ( ) ) ,
166
157
"va_end" => self . va_end ( args[ 0 ] . immediate ( ) ) ,
0 commit comments