1
1
use std:: cell:: { OnceCell , RefCell } ;
2
2
use std:: ffi:: { CStr , CString } ;
3
3
4
- use rustc_abi:: Size ;
5
4
use rustc_codegen_ssa:: traits:: {
6
- BuilderMethods , ConstCodegenMethods , CoverageInfoBuilderMethods , MiscCodegenMethods ,
5
+ ConstCodegenMethods , CoverageInfoBuilderMethods , MiscCodegenMethods ,
7
6
} ;
8
- use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
7
+ use rustc_data_structures:: fx:: FxIndexMap ;
9
8
use rustc_middle:: mir:: coverage:: CoverageKind ;
10
9
use rustc_middle:: ty:: Instance ;
11
10
use tracing:: { debug, instrument} ;
@@ -28,34 +27,13 @@ pub(crate) struct CguCoverageContext<'ll, 'tcx> {
28
27
/// symbol name, and `llvm-cov` will exit fatally if it can't resolve that
29
28
/// hash back to an entry in the binary's `__llvm_prf_names` linker section.
30
29
pub ( crate ) pgo_func_name_var_map : RefCell < FxIndexMap < Instance < ' tcx > , & ' ll llvm:: Value > > ,
31
- pub ( crate ) mcdc_condition_bitmap_map : RefCell < FxHashMap < Instance < ' tcx > , Vec < & ' ll llvm:: Value > > > ,
32
30
33
31
covfun_section_name : OnceCell < CString > ,
34
32
}
35
33
36
34
impl < ' ll , ' tcx > CguCoverageContext < ' ll , ' tcx > {
37
35
pub ( crate ) fn new ( ) -> Self {
38
- Self {
39
- pgo_func_name_var_map : Default :: default ( ) ,
40
- mcdc_condition_bitmap_map : Default :: default ( ) ,
41
- covfun_section_name : Default :: default ( ) ,
42
- }
43
- }
44
-
45
- /// LLVM use a temp value to record evaluated mcdc test vector of each decision, which is
46
- /// called condition bitmap. In order to handle nested decisions, several condition bitmaps can
47
- /// be allocated for a function body. These values are named `mcdc.addr.{i}` and are a 32-bit
48
- /// integers. They respectively hold the condition bitmaps for decisions with a depth of `i`.
49
- fn try_get_mcdc_condition_bitmap (
50
- & self ,
51
- instance : & Instance < ' tcx > ,
52
- decision_depth : u16 ,
53
- ) -> Option < & ' ll llvm:: Value > {
54
- self . mcdc_condition_bitmap_map
55
- . borrow ( )
56
- . get ( instance)
57
- . and_then ( |bitmap_map| bitmap_map. get ( decision_depth as usize ) )
58
- . copied ( ) // Dereference Option<&&Value> to Option<&Value>
36
+ Self { pgo_func_name_var_map : Default :: default ( ) , covfun_section_name : Default :: default ( ) }
59
37
}
60
38
61
39
/// Returns the list of instances considered "used" in this CGU, as
@@ -105,38 +83,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
105
83
}
106
84
107
85
impl < ' tcx > CoverageInfoBuilderMethods < ' tcx > for Builder < ' _ , ' _ , ' tcx > {
108
- fn init_coverage ( & mut self , instance : Instance < ' tcx > ) {
109
- let Some ( function_coverage_info) =
110
- self . tcx . instance_mir ( instance. def ) . function_coverage_info . as_deref ( )
111
- else {
112
- return ;
113
- } ;
114
-
115
- // If there are no MC/DC bitmaps to set up, return immediately.
116
- if function_coverage_info. mcdc_bitmap_bits == 0 {
117
- return ;
118
- }
119
-
120
- let fn_name = self . ensure_pgo_func_name_var ( instance) ;
121
- let hash = self . const_u64 ( function_coverage_info. function_source_hash ) ;
122
- let bitmap_bits = self . const_u32 ( function_coverage_info. mcdc_bitmap_bits as u32 ) ;
123
- self . mcdc_parameters ( fn_name, hash, bitmap_bits) ;
124
-
125
- // Create pointers named `mcdc.addr.{i}` to stack-allocated condition bitmaps.
126
- let mut cond_bitmaps = vec ! [ ] ;
127
- for i in 0 ..function_coverage_info. mcdc_num_condition_bitmaps {
128
- // MC/DC intrinsics will perform loads/stores that use the ABI default
129
- // alignment for i32, so our variable declaration should match.
130
- let align = self . tcx . data_layout . i32_align . abi ;
131
- let cond_bitmap = self . alloca ( Size :: from_bytes ( 4 ) , align) ;
132
- llvm:: set_value_name ( cond_bitmap, format ! ( "mcdc.addr.{i}" ) . as_bytes ( ) ) ;
133
- self . store ( self . const_i32 ( 0 ) , cond_bitmap, align) ;
134
- cond_bitmaps. push ( cond_bitmap) ;
135
- }
136
-
137
- self . coverage_cx ( ) . mcdc_condition_bitmap_map . borrow_mut ( ) . insert ( instance, cond_bitmaps) ;
138
- }
139
-
140
86
#[ instrument( level = "debug" , skip( self ) ) ]
141
87
fn add_coverage ( & mut self , instance : Instance < ' tcx > , kind : & CoverageKind ) {
142
88
// Our caller should have already taken care of inlining subtleties,
@@ -153,7 +99,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
153
99
// When that happens, we currently just discard those statements, so
154
100
// the corresponding code will be undercounted.
155
101
// FIXME(Zalathar): Find a better solution for mixed-coverage builds.
156
- let Some ( coverage_cx ) = & bx. cx . coverage_cx else { return } ;
102
+ let Some ( _coverage_cx ) = & bx. cx . coverage_cx else { return } ;
157
103
158
104
let Some ( function_coverage_info) =
159
105
bx. tcx . instance_mir ( instance. def ) . function_coverage_info . as_deref ( )
@@ -185,30 +131,6 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
185
131
}
186
132
// If a BCB doesn't have an associated physical counter, there's nothing to codegen.
187
133
CoverageKind :: VirtualCounter { .. } => { }
188
- CoverageKind :: CondBitmapUpdate { index, decision_depth } => {
189
- let cond_bitmap = coverage_cx
190
- . try_get_mcdc_condition_bitmap ( & instance, decision_depth)
191
- . expect ( "mcdc cond bitmap should have been allocated for updating" ) ;
192
- let cond_index = bx. const_i32 ( index as i32 ) ;
193
- bx. mcdc_condbitmap_update ( cond_index, cond_bitmap) ;
194
- }
195
- CoverageKind :: TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
196
- let cond_bitmap =
197
- coverage_cx. try_get_mcdc_condition_bitmap ( & instance, decision_depth) . expect (
198
- "mcdc cond bitmap should have been allocated for merging \
199
- into the global bitmap",
200
- ) ;
201
- assert ! (
202
- bitmap_idx as usize <= function_coverage_info. mcdc_bitmap_bits,
203
- "bitmap index of the decision out of range"
204
- ) ;
205
-
206
- let fn_name = bx. ensure_pgo_func_name_var ( instance) ;
207
- let hash = bx. const_u64 ( function_coverage_info. function_source_hash ) ;
208
- let bitmap_index = bx. const_u32 ( bitmap_idx) ;
209
- bx. mcdc_tvbitmap_update ( fn_name, hash, bitmap_index, cond_bitmap) ;
210
- bx. mcdc_condbitmap_reset ( cond_bitmap) ;
211
- }
212
134
}
213
135
}
214
136
}
0 commit comments