1
- use super :: Error ;
2
-
3
1
use itertools:: Itertools ;
4
- use rustc_data_structures:: fx:: FxHashMap ;
5
2
use rustc_data_structures:: graph:: dominators:: { self , Dominators } ;
6
3
use rustc_data_structures:: graph:: { self , GraphSuccessors , WithNumNodes , WithStartNode } ;
7
4
use rustc_index:: bit_set:: BitSet ;
8
5
use rustc_index:: { IndexSlice , IndexVec } ;
9
- use rustc_middle:: mir:: coverage:: * ;
10
6
use rustc_middle:: mir:: { self , BasicBlock , BasicBlockData , Terminator , TerminatorKind } ;
11
7
12
8
use std:: cmp:: Ordering ;
@@ -15,10 +11,7 @@ use std::ops::{Index, IndexMut};
15
11
const ID_SEPARATOR : & str = "," ;
16
12
17
13
/// A coverage-specific simplification of the MIR control flow graph (CFG). The `CoverageGraph`s
18
- /// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s, plus a
19
- /// `CoverageKind` counter (to be added by `CoverageCounters::make_bcb_counters`), and an optional
20
- /// set of additional counters--if needed--to count incoming edges, if there are more than one.
21
- /// (These "edge counters" are eventually converted into new MIR `BasicBlock`s.)
14
+ /// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s.
22
15
#[ derive( Debug ) ]
23
16
pub ( super ) struct CoverageGraph {
24
17
bcbs : IndexVec < BasicCoverageBlock , BasicCoverageBlockData > ,
@@ -195,13 +188,6 @@ impl CoverageGraph {
195
188
self . bcbs . iter_enumerated ( )
196
189
}
197
190
198
- #[ inline( always) ]
199
- pub fn iter_enumerated_mut (
200
- & mut self ,
201
- ) -> impl Iterator < Item = ( BasicCoverageBlock , & mut BasicCoverageBlockData ) > {
202
- self . bcbs . iter_enumerated_mut ( )
203
- }
204
-
205
191
#[ inline( always) ]
206
192
pub fn bcb_from_bb ( & self , bb : BasicBlock ) -> Option < BasicCoverageBlock > {
207
193
if bb. index ( ) < self . bb_to_bcb . len ( ) { self . bb_to_bcb [ bb] } else { None }
@@ -320,14 +306,12 @@ rustc_index::newtype_index! {
320
306
#[ derive( Debug , Clone ) ]
321
307
pub ( super ) struct BasicCoverageBlockData {
322
308
pub basic_blocks : Vec < BasicBlock > ,
323
- pub counter_kind : Option < CoverageKind > ,
324
- edge_from_bcbs : Option < FxHashMap < BasicCoverageBlock , CoverageKind > > ,
325
309
}
326
310
327
311
impl BasicCoverageBlockData {
328
312
pub fn from ( basic_blocks : Vec < BasicBlock > ) -> Self {
329
313
assert ! ( basic_blocks. len( ) > 0 ) ;
330
- Self { basic_blocks, counter_kind : None , edge_from_bcbs : None }
314
+ Self { basic_blocks }
331
315
}
332
316
333
317
#[ inline( always) ]
@@ -345,80 +329,6 @@ impl BasicCoverageBlockData {
345
329
& mir_body[ self . last_bb ( ) ] . terminator ( )
346
330
}
347
331
348
- pub fn set_counter ( & mut self , counter_kind : CoverageKind ) -> Result < Operand , Error > {
349
- debug_assert ! (
350
- // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
351
- // have an expression (to be injected into an existing `BasicBlock` represented by this
352
- // `BasicCoverageBlock`).
353
- self . edge_from_bcbs. is_none( ) || counter_kind. is_expression( ) ,
354
- "attempt to add a `Counter` to a BCB target with existing incoming edge counters"
355
- ) ;
356
- let operand = counter_kind. as_operand ( ) ;
357
- if let Some ( replaced) = self . counter_kind . replace ( counter_kind) {
358
- Error :: from_string ( format ! (
359
- "attempt to set a BasicCoverageBlock coverage counter more than once; \
360
- {self:?} already had counter {replaced:?}",
361
- ) )
362
- } else {
363
- Ok ( operand)
364
- }
365
- }
366
-
367
- #[ inline( always) ]
368
- pub fn counter ( & self ) -> Option < & CoverageKind > {
369
- self . counter_kind . as_ref ( )
370
- }
371
-
372
- #[ inline( always) ]
373
- pub fn take_counter ( & mut self ) -> Option < CoverageKind > {
374
- self . counter_kind . take ( )
375
- }
376
-
377
- pub fn set_edge_counter_from (
378
- & mut self ,
379
- from_bcb : BasicCoverageBlock ,
380
- counter_kind : CoverageKind ,
381
- ) -> Result < Operand , Error > {
382
- if level_enabled ! ( tracing:: Level :: DEBUG ) {
383
- // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
384
- // have an expression (to be injected into an existing `BasicBlock` represented by this
385
- // `BasicCoverageBlock`).
386
- if self . counter_kind . as_ref ( ) . is_some_and ( |c| !c. is_expression ( ) ) {
387
- return Error :: from_string ( format ! (
388
- "attempt to add an incoming edge counter from {from_bcb:?} when the target BCB already \
389
- has a `Counter`"
390
- ) ) ;
391
- }
392
- }
393
- let operand = counter_kind. as_operand ( ) ;
394
- if let Some ( replaced) =
395
- self . edge_from_bcbs . get_or_insert_default ( ) . insert ( from_bcb, counter_kind)
396
- {
397
- Error :: from_string ( format ! (
398
- "attempt to set an edge counter more than once; from_bcb: \
399
- {from_bcb:?} already had counter {replaced:?}",
400
- ) )
401
- } else {
402
- Ok ( operand)
403
- }
404
- }
405
-
406
- #[ inline]
407
- pub fn edge_counter_from ( & self , from_bcb : BasicCoverageBlock ) -> Option < & CoverageKind > {
408
- if let Some ( edge_from_bcbs) = & self . edge_from_bcbs {
409
- edge_from_bcbs. get ( & from_bcb)
410
- } else {
411
- None
412
- }
413
- }
414
-
415
- #[ inline]
416
- pub fn take_edge_counters (
417
- & mut self ,
418
- ) -> Option < impl Iterator < Item = ( BasicCoverageBlock , CoverageKind ) > > {
419
- self . edge_from_bcbs . take ( ) . map ( |m| m. into_iter ( ) )
420
- }
421
-
422
332
pub fn id ( & self ) -> String {
423
333
format ! ( "@{}" , self . basic_blocks. iter( ) . map( |bb| bb. index( ) . to_string( ) ) . join( ID_SEPARATOR ) )
424
334
}
@@ -448,17 +358,6 @@ impl BcbBranch {
448
358
Self { edge_from_bcb, target_bcb : to_bcb }
449
359
}
450
360
451
- pub fn counter < ' a > (
452
- & self ,
453
- basic_coverage_blocks : & ' a CoverageGraph ,
454
- ) -> Option < & ' a CoverageKind > {
455
- if let Some ( from_bcb) = self . edge_from_bcb {
456
- basic_coverage_blocks[ self . target_bcb ] . edge_counter_from ( from_bcb)
457
- } else {
458
- basic_coverage_blocks[ self . target_bcb ] . counter ( )
459
- }
460
- }
461
-
462
361
pub fn is_only_path_to_target ( & self ) -> bool {
463
362
self . edge_from_bcb . is_none ( )
464
363
}
0 commit comments