@@ -5,97 +5,13 @@ use rustc_index::bit_set::SparseBitMatrix;
5
5
use rustc_index:: interval:: IntervalSet ;
6
6
use rustc_index:: interval:: SparseIntervalMatrix ;
7
7
use rustc_index:: Idx ;
8
- use rustc_index:: IndexVec ;
9
- use rustc_middle:: mir:: { BasicBlock , Body , Location } ;
8
+ use rustc_middle:: mir:: { BasicBlock , Location } ;
10
9
use rustc_middle:: ty:: { self , RegionVid } ;
10
+ use rustc_mir_dataflow:: points:: { DenseLocationMap , PointIndex } ;
11
11
use std:: fmt:: Debug ;
12
12
use std:: rc:: Rc ;
13
13
14
- use crate :: dataflow:: BorrowIndex ;
15
-
16
- /// Maps between a `Location` and a `PointIndex` (and vice versa).
17
- pub ( crate ) struct RegionValueElements {
18
- /// For each basic block, how many points are contained within?
19
- statements_before_block : IndexVec < BasicBlock , usize > ,
20
-
21
- /// Map backward from each point to the basic block that it
22
- /// belongs to.
23
- basic_blocks : IndexVec < PointIndex , BasicBlock > ,
24
-
25
- num_points : usize ,
26
- }
27
-
28
- impl RegionValueElements {
29
- pub ( crate ) fn new ( body : & Body < ' _ > ) -> Self {
30
- let mut num_points = 0 ;
31
- let statements_before_block: IndexVec < BasicBlock , usize > = body
32
- . basic_blocks
33
- . iter ( )
34
- . map ( |block_data| {
35
- let v = num_points;
36
- num_points += block_data. statements . len ( ) + 1 ;
37
- v
38
- } )
39
- . collect ( ) ;
40
- debug ! ( "RegionValueElements: statements_before_block={:#?}" , statements_before_block) ;
41
- debug ! ( "RegionValueElements: num_points={:#?}" , num_points) ;
42
-
43
- let mut basic_blocks = IndexVec :: with_capacity ( num_points) ;
44
- for ( bb, bb_data) in body. basic_blocks . iter_enumerated ( ) {
45
- basic_blocks. extend ( ( 0 ..=bb_data. statements . len ( ) ) . map ( |_| bb) ) ;
46
- }
47
-
48
- Self { statements_before_block, basic_blocks, num_points }
49
- }
50
-
51
- /// Total number of point indices
52
- pub ( crate ) fn num_points ( & self ) -> usize {
53
- self . num_points
54
- }
55
-
56
- /// Converts a `Location` into a `PointIndex`. O(1).
57
- pub ( crate ) fn point_from_location ( & self , location : Location ) -> PointIndex {
58
- let Location { block, statement_index } = location;
59
- let start_index = self . statements_before_block [ block] ;
60
- PointIndex :: new ( start_index + statement_index)
61
- }
62
-
63
- /// Converts a `Location` into a `PointIndex`. O(1).
64
- pub ( crate ) fn entry_point ( & self , block : BasicBlock ) -> PointIndex {
65
- let start_index = self . statements_before_block [ block] ;
66
- PointIndex :: new ( start_index)
67
- }
68
-
69
- /// Return the PointIndex for the block start of this index.
70
- pub ( crate ) fn to_block_start ( & self , index : PointIndex ) -> PointIndex {
71
- PointIndex :: new ( self . statements_before_block [ self . basic_blocks [ index] ] )
72
- }
73
-
74
- /// Converts a `PointIndex` back to a location. O(1).
75
- pub ( crate ) fn to_location ( & self , index : PointIndex ) -> Location {
76
- assert ! ( index. index( ) < self . num_points) ;
77
- let block = self . basic_blocks [ index] ;
78
- let start_index = self . statements_before_block [ block] ;
79
- let statement_index = index. index ( ) - start_index;
80
- Location { block, statement_index }
81
- }
82
-
83
- /// Sometimes we get point-indices back from bitsets that may be
84
- /// out of range (because they round up to the nearest 2^N number
85
- /// of bits). Use this function to filter such points out if you
86
- /// like.
87
- pub ( crate ) fn point_in_range ( & self , index : PointIndex ) -> bool {
88
- index. index ( ) < self . num_points
89
- }
90
- }
91
-
92
- rustc_index:: newtype_index! {
93
- /// A single integer representing a `Location` in the MIR control-flow
94
- /// graph. Constructed efficiently from `RegionValueElements`.
95
- #[ orderable]
96
- #[ debug_format = "PointIndex({})" ]
97
- pub struct PointIndex { }
98
- }
14
+ use crate :: BorrowIndex ;
99
15
100
16
rustc_index:: newtype_index! {
101
17
/// A single integer representing a `ty::Placeholder`.
@@ -123,7 +39,7 @@ pub(crate) enum RegionElement {
123
39
/// an interval matrix storing liveness ranges for each region-vid.
124
40
pub ( crate ) struct LivenessValues {
125
41
/// The map from locations to points.
126
- elements : Rc < RegionValueElements > ,
42
+ elements : Rc < DenseLocationMap > ,
127
43
128
44
/// For each region: the points where it is live.
129
45
points : SparseIntervalMatrix < RegionVid , PointIndex > ,
@@ -155,9 +71,9 @@ impl LiveLoans {
155
71
156
72
impl LivenessValues {
157
73
/// Create an empty map of regions to locations where they're live.
158
- pub ( crate ) fn new ( elements : Rc < RegionValueElements > ) -> Self {
74
+ pub ( crate ) fn new ( elements : Rc < DenseLocationMap > ) -> Self {
159
75
LivenessValues {
160
- points : SparseIntervalMatrix :: new ( elements. num_points ) ,
76
+ points : SparseIntervalMatrix :: new ( elements. num_points ( ) ) ,
161
77
elements,
162
78
loans : None ,
163
79
}
@@ -298,7 +214,7 @@ impl PlaceholderIndices {
298
214
/// it would also contain various points from within the function.
299
215
#[ derive( Clone ) ]
300
216
pub ( crate ) struct RegionValues < N : Idx > {
301
- elements : Rc < RegionValueElements > ,
217
+ elements : Rc < DenseLocationMap > ,
302
218
placeholder_indices : Rc < PlaceholderIndices > ,
303
219
points : SparseIntervalMatrix < N , PointIndex > ,
304
220
free_regions : SparseBitMatrix < N , RegionVid > ,
@@ -313,14 +229,14 @@ impl<N: Idx> RegionValues<N> {
313
229
/// Each of the regions in num_region_variables will be initialized with an
314
230
/// empty set of points and no causal information.
315
231
pub ( crate ) fn new (
316
- elements : & Rc < RegionValueElements > ,
232
+ elements : & Rc < DenseLocationMap > ,
317
233
num_universal_regions : usize ,
318
234
placeholder_indices : & Rc < PlaceholderIndices > ,
319
235
) -> Self {
320
236
let num_placeholders = placeholder_indices. len ( ) ;
321
237
Self {
322
238
elements : elements. clone ( ) ,
323
- points : SparseIntervalMatrix :: new ( elements. num_points ) ,
239
+ points : SparseIntervalMatrix :: new ( elements. num_points ( ) ) ,
324
240
placeholder_indices : placeholder_indices. clone ( ) ,
325
241
free_regions : SparseBitMatrix :: new ( num_universal_regions) ,
326
242
placeholders : SparseBitMatrix :: new ( num_placeholders) ,
@@ -486,7 +402,7 @@ impl ToElementIndex for ty::PlaceholderRegion {
486
402
487
403
/// For debugging purposes, returns a pretty-printed string of the given points.
488
404
pub ( crate ) fn pretty_print_points (
489
- elements : & RegionValueElements ,
405
+ elements : & DenseLocationMap ,
490
406
points : impl IntoIterator < Item = PointIndex > ,
491
407
) -> String {
492
408
pretty_print_region_elements (
0 commit comments