1
1
//! Performs various peephole optimizations.
2
2
3
3
use crate :: transform:: { MirPass , MirSource } ;
4
- use rustc_data_structures:: fx:: FxHashMap ;
4
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5
+ use rustc_hir:: Mutability ;
5
6
use rustc_index:: vec:: Idx ;
6
7
use rustc_middle:: mir:: visit:: { MutVisitor , Visitor } ;
7
8
use rustc_middle:: mir:: {
8
- Body , Constant , Local , Location , Mutability , Operand , Place , PlaceRef , ProjectionElem , Rvalue ,
9
+ Body , Constant , Local , Location , Operand , Place , PlaceRef , ProjectionElem , Rvalue ,
9
10
} ;
10
11
use rustc_middle:: ty:: { self , TyCtxt } ;
11
12
use std:: mem;
@@ -39,7 +40,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
39
40
}
40
41
41
42
fn visit_rvalue ( & mut self , rvalue : & mut Rvalue < ' tcx > , location : Location ) {
42
- if let Some ( mtbl ) = self . optimizations . and_stars . remove ( & location) {
43
+ if self . optimizations . and_stars . remove ( & location) {
43
44
debug ! ( "replacing `&*`: {:?}" , rvalue) ;
44
45
let new_place = match rvalue {
45
46
Rvalue :: Ref ( _, _, place) => {
@@ -57,10 +58,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
57
58
}
58
59
_ => bug ! ( "Detected `&*` but didn't find `&*`!" ) ,
59
60
} ;
60
- * rvalue = Rvalue :: Use ( match mtbl {
61
- Mutability :: Mut => Operand :: Move ( new_place) ,
62
- Mutability :: Not => Operand :: Copy ( new_place) ,
63
- } ) ;
61
+ * rvalue = Rvalue :: Use ( Operand :: Copy ( new_place) )
64
62
}
65
63
66
64
if let Some ( constant) = self . optimizations . arrays_lengths . remove ( & location) {
@@ -93,8 +91,8 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
93
91
{
94
92
// The dereferenced place must have type `&_`.
95
93
let ty = Place :: ty_from ( local, proj_base, self . body , self . tcx ) . ty ;
96
- if let ty:: Ref ( _, _, mtbl ) = ty. kind {
97
- self . optimizations . and_stars . insert ( location, mtbl ) ;
94
+ if let ty:: Ref ( _, _, Mutability :: Not ) = ty. kind {
95
+ self . optimizations . and_stars . insert ( location) ;
98
96
}
99
97
}
100
98
}
@@ -114,6 +112,6 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
114
112
115
113
#[ derive( Default ) ]
116
114
struct OptimizationList < ' tcx > {
117
- and_stars : FxHashMap < Location , Mutability > ,
115
+ and_stars : FxHashSet < Location > ,
118
116
arrays_lengths : FxHashMap < Location , Constant < ' tcx > > ,
119
117
}
0 commit comments