13
13
//! Move resolution.
14
14
15
15
use super :: {
16
- Env , InsertMovePrio , InsertedMove , LiveRangeFlag , LiveRangeIndex , RedundantMoveEliminator ,
17
- VRegIndex , SLOT_NONE ,
16
+ Env , InsertMovePrio , InsertedMove , InsertedMoves , LiveRangeFlag , LiveRangeIndex ,
17
+ RedundantMoveEliminator , VRegIndex , SLOT_NONE ,
18
18
} ;
19
19
use crate :: ion:: data_structures:: {
20
20
u128_key, u64_key, BlockparamIn , BlockparamOut , CodeRange , FixedRegFixupLevel , LiveRangeKey ,
@@ -24,7 +24,7 @@ use crate::ion::reg_traversal::RegTraversalIter;
24
24
use crate :: moves:: { MoveAndScratchResolver , ParallelMoves } ;
25
25
use crate :: {
26
26
Allocation , Block , Edit , Function , FxHashMap , Inst , InstPosition , OperandConstraint ,
27
- OperandKind , OperandPos , PReg , ProgPoint , RegClass , SpillSlot , VReg ,
27
+ OperandKind , OperandPos , PReg , ProgPoint , RegClass , SpillSlot ,
28
28
} ;
29
29
use alloc:: vec:: Vec ;
30
30
use alloc:: { format, vec} ;
@@ -41,39 +41,6 @@ impl<'a, F: Function> Env<'a, F> {
41
41
pos == self . cfginfo . block_exit [ block. index ( ) ]
42
42
}
43
43
44
- pub fn insert_move (
45
- & mut self ,
46
- pos : ProgPoint ,
47
- prio : InsertMovePrio ,
48
- from_alloc : Allocation ,
49
- to_alloc : Allocation ,
50
- to_vreg : VReg ,
51
- ) {
52
- trace ! (
53
- "insert_move: pos {:?} prio {:?} from_alloc {:?} to_alloc {:?} to_vreg {:?}" ,
54
- pos,
55
- prio,
56
- from_alloc,
57
- to_alloc,
58
- to_vreg
59
- ) ;
60
- if let Some ( from) = from_alloc. as_reg ( ) {
61
- debug_assert_eq ! ( from. class( ) , to_vreg. class( ) ) ;
62
- }
63
- if let Some ( to) = to_alloc. as_reg ( ) {
64
- debug_assert_eq ! ( to. class( ) , to_vreg. class( ) ) ;
65
- }
66
- self . inserted_moves . push ( InsertedMove {
67
- pos_prio : PosWithPrio {
68
- pos,
69
- prio : prio as u32 ,
70
- } ,
71
- from_alloc,
72
- to_alloc,
73
- to_vreg,
74
- } ) ;
75
- }
76
-
77
44
pub fn get_alloc ( & self , inst : Inst , slot : usize ) -> Allocation {
78
45
let inst_allocs = & self . allocs [ self . inst_alloc_offsets [ inst. index ( ) ] as usize ..] ;
79
46
inst_allocs[ slot]
@@ -102,11 +69,13 @@ impl<'a, F: Function> Env<'a, F> {
102
69
}
103
70
}
104
71
105
- pub fn apply_allocations_and_insert_moves ( & mut self ) {
72
+ pub fn apply_allocations_and_insert_moves ( & mut self ) -> InsertedMoves {
106
73
trace ! ( "apply_allocations_and_insert_moves" ) ;
107
74
trace ! ( "blockparam_ins: {:?}" , self . blockparam_ins) ;
108
75
trace ! ( "blockparam_outs: {:?}" , self . blockparam_outs) ;
109
76
77
+ let mut inserted_moves = InsertedMoves :: default ( ) ;
78
+
110
79
// Now that all splits are done, we can pay the cost once to
111
80
// sort VReg range lists and update with the final ranges.
112
81
for vreg in & mut self . vregs {
@@ -394,7 +363,7 @@ impl<'a, F: Function> Env<'a, F> {
394
363
vreg. index( )
395
364
) ;
396
365
debug_assert_eq ! ( range. from. pos( ) , InstPosition :: Before ) ;
397
- self . insert_move (
366
+ inserted_moves . push (
398
367
range. from ,
399
368
InsertMovePrio :: Regular ,
400
369
prev_alloc,
@@ -670,7 +639,7 @@ impl<'a, F: Function> Env<'a, F> {
670
639
) ;
671
640
672
641
let ( pos, prio) = choose_move_location ( self , dest. from , dest. to ) ;
673
- self . insert_move ( pos, prio, src, dest. alloc , vreg) ;
642
+ inserted_moves . push ( pos, prio, src, dest. alloc , vreg) ;
674
643
}
675
644
}
676
645
@@ -710,7 +679,13 @@ impl<'a, F: Function> Env<'a, F> {
710
679
711
680
let ( pos, prio) =
712
681
choose_move_location ( self , dest. from_block , dest. to_block ) ;
713
- self . insert_move ( pos, prio, src. alloc , dest. alloc , self . vreg ( dest. to_vreg ) ) ;
682
+ inserted_moves. push (
683
+ pos,
684
+ prio,
685
+ src. alloc ,
686
+ dest. alloc ,
687
+ self . vreg ( dest. to_vreg ) ,
688
+ ) ;
714
689
715
690
// We don't advance the block_param_sources iterator here because there
716
691
// could be additional destinations that would take from that source. Thus,
@@ -740,7 +715,7 @@ impl<'a, F: Function> Env<'a, F> {
740
715
FixedRegFixupLevel :: Initial => InsertMovePrio :: MultiFixedRegInitial ,
741
716
FixedRegFixupLevel :: Secondary => InsertMovePrio :: MultiFixedRegSecondary ,
742
717
} ;
743
- self . insert_move ( fixup. pos , prio, from_alloc, to_alloc, self . vreg ( fixup. vreg ) ) ;
718
+ inserted_moves . push ( fixup. pos , prio, from_alloc, to_alloc, self . vreg ( fixup. vreg ) ) ;
744
719
self . set_alloc (
745
720
fixup. pos . inst ( ) ,
746
721
fixup. to_slot as usize ,
@@ -819,7 +794,7 @@ impl<'a, F: Function> Env<'a, F> {
819
794
) ;
820
795
}
821
796
let input_operand = self . func . inst_operands ( inst) [ input_idx] ;
822
- self . insert_move (
797
+ inserted_moves . push (
823
798
ProgPoint :: before ( inst) ,
824
799
InsertMovePrio :: ReusedInput ,
825
800
input_alloc,
@@ -835,13 +810,16 @@ impl<'a, F: Function> Env<'a, F> {
835
810
// Sort the debug-locations vector; we provide this
836
811
// invariant to the client.
837
812
self . debug_locations . sort_unstable ( ) ;
813
+
814
+ inserted_moves
838
815
}
839
816
840
- pub fn resolve_inserted_moves ( & mut self ) {
817
+ pub fn resolve_inserted_moves ( & mut self , mut inserted_moves : InsertedMoves ) {
841
818
// For each program point, gather all moves together. Then
842
819
// resolve (see cases below).
843
820
let mut i = 0 ;
844
- self . inserted_moves
821
+ inserted_moves
822
+ . moves
845
823
. sort_unstable_by_key ( |m| m. pos_prio . key ( ) ) ;
846
824
847
825
// Redundant-move elimination state tracker.
@@ -897,13 +875,13 @@ impl<'a, F: Function> Env<'a, F> {
897
875
898
876
let mut last_pos = ProgPoint :: before ( Inst :: new ( 0 ) ) ;
899
877
900
- while i < self . inserted_moves . len ( ) {
878
+ while i < inserted_moves. moves . len ( ) {
901
879
let start = i;
902
- let pos_prio = self . inserted_moves [ i] . pos_prio ;
903
- while i < self . inserted_moves . len ( ) && self . inserted_moves [ i] . pos_prio == pos_prio {
880
+ let pos_prio = inserted_moves. moves [ i] . pos_prio ;
881
+ while i < inserted_moves. moves . len ( ) && inserted_moves. moves [ i] . pos_prio == pos_prio {
904
882
i += 1 ;
905
883
}
906
- let moves = & self . inserted_moves [ start..i] ;
884
+ let moves = & inserted_moves. moves [ start..i] ;
907
885
908
886
redundant_move_process_side_effects ( self , & mut redundant_moves, last_pos, pos_prio. pos ) ;
909
887
last_pos = pos_prio. pos ;
@@ -919,9 +897,6 @@ impl<'a, F: Function> Env<'a, F> {
919
897
let mut vec_moves: SmallVec < [ InsertedMove ; 8 ] > = smallvec ! [ ] ;
920
898
921
899
for m in moves {
922
- if m. from_alloc == m. to_alloc {
923
- continue ;
924
- }
925
900
match m. to_vreg . class ( ) {
926
901
RegClass :: Int => {
927
902
int_moves. push ( m. clone ( ) ) ;
0 commit comments