11use  std:: cell:: { OnceCell ,  RefCell } ; 
22use  std:: ffi:: { CStr ,  CString } ; 
33
4- use  rustc_abi:: Size ; 
54use  rustc_codegen_ssa:: traits:: { 
6-     BuilderMethods ,   ConstCodegenMethods ,  CoverageInfoBuilderMethods ,  MiscCodegenMethods , 
5+     ConstCodegenMethods ,  CoverageInfoBuilderMethods ,  MiscCodegenMethods , 
76} ; 
8- use  rustc_data_structures:: fx:: { FxHashMap ,   FxIndexMap } ; 
7+ use  rustc_data_structures:: fx:: FxIndexMap ; 
98use  rustc_middle:: mir:: coverage:: CoverageKind ; 
109use  rustc_middle:: ty:: Instance ; 
1110use  tracing:: { debug,  instrument} ; 
@@ -28,34 +27,13 @@ pub(crate) struct CguCoverageContext<'ll, 'tcx> {
2827/// symbol name, and `llvm-cov` will exit fatally if it can't resolve that 
2928/// hash back to an entry in the binary's `__llvm_prf_names` linker section. 
3029pub ( 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 > > > , 
3230
3331    covfun_section_name :  OnceCell < CString > , 
3432} 
3533
3634impl < ' ll ,  ' tcx >  CguCoverageContext < ' ll ,  ' tcx >  { 
3735    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 ( )  } 
5937    } 
6038
6139    /// Returns the list of instances considered "used" in this CGU, as 
@@ -105,38 +83,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
10583} 
10684
10785impl < ' 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- 
14086    #[ instrument( level = "debug" ,  skip( self ) ) ]  
14187    fn  add_coverage ( & mut  self ,  instance :  Instance < ' tcx > ,  kind :  & CoverageKind )  { 
14288        // Our caller should have already taken care of inlining subtleties, 
@@ -153,7 +99,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
15399        // When that happens, we currently just discard those statements, so 
154100        // the corresponding code will be undercounted. 
155101        // 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  } ; 
157103
158104        let  Some ( function_coverage_info)  =
159105            bx. tcx . instance_mir ( instance. def ) . function_coverage_info . as_deref ( ) 
@@ -185,30 +131,6 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
185131            } 
186132            // If a BCB doesn't have an associated physical counter, there's nothing to codegen. 
187133            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- , 
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-             } 
212134        } 
213135    } 
214136} 
0 commit comments