@@ -734,6 +734,36 @@ void SplitEditor::closeIntv() {
734
734
openli_.reset (0 );
735
735
}
736
736
737
+ // / rewrite - Rewrite all uses of reg to use the new registers.
738
+ void SplitEditor::rewrite (unsigned reg) {
739
+ for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin (reg),
740
+ RE = mri_.reg_end (); RI != RE;) {
741
+ MachineOperand &MO = RI.getOperand ();
742
+ MachineInstr *MI = MO.getParent ();
743
+ ++RI;
744
+ if (MI->isDebugValue ()) {
745
+ DEBUG (dbgs () << " Zapping " << *MI);
746
+ // FIXME: We can do much better with debug values.
747
+ MO.setReg (0 );
748
+ continue ;
749
+ }
750
+ SlotIndex Idx = lis_.getInstructionIndex (MI);
751
+ Idx = MO.isUse () ? Idx.getUseIndex () : Idx.getDefIndex ();
752
+ LiveInterval *LI = 0 ;
753
+ for (unsigned i = firstInterval, e = intervals_.size (); i != e; ++i) {
754
+ LiveInterval *testli = intervals_[i];
755
+ if (testli->liveAt (Idx)) {
756
+ LI = testli;
757
+ break ;
758
+ }
759
+ }
760
+ assert (LI && " No register was live at use" );
761
+ MO.setReg (LI->reg );
762
+ DEBUG (dbgs () << " rewrite BB#" << MI->getParent ()->getNumber () << ' \t '
763
+ << Idx << ' \t ' << *MI);
764
+ }
765
+ }
766
+
737
767
void
738
768
SplitEditor::addTruncSimpleRange (SlotIndex Start, SlotIndex End, VNInfo *VNI) {
739
769
// Build vector of iterator pairs from the intervals.
@@ -781,12 +811,7 @@ SplitEditor::addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
781
811
}
782
812
}
783
813
784
- // / rewrite - after all the new live ranges have been created, rewrite
785
- // / instructions using curli to use the new intervals.
786
- void SplitEditor::rewrite () {
787
- assert (!openli_.getLI () && " Previous LI not closed before rewrite" );
788
- assert (dupli_.getLI () && " No dupli for rewrite. Noop spilt?" );
789
-
814
+ void SplitEditor::computeRemainder () {
790
815
// First we need to fill in the live ranges in dupli.
791
816
// If values were redefined, we need a full recoloring with SSA update.
792
817
// If values were truncated, we only need to truncate the ranges.
@@ -827,6 +852,14 @@ void SplitEditor::rewrite() {
827
852
dupli_.addSimpleRange (LR.start , LR.end , LR.valno );
828
853
}
829
854
}
855
+ }
856
+
857
+ void SplitEditor::finish () {
858
+ assert (!openli_.getLI () && " Previous LI not closed before rewrite" );
859
+ assert (dupli_.getLI () && " No dupli for rewrite. Noop spilt?" );
860
+
861
+ // Complete dupli liveness.
862
+ computeRemainder ();
830
863
831
864
// Get rid of unused values and set phi-kill flags.
832
865
dupli_.getLI ()->RenumberValues (lis_);
@@ -843,6 +876,8 @@ void SplitEditor::rewrite() {
843
876
for (unsigned i = 1 ; i != NumComp; ++i)
844
877
intervals_.push_back (createInterval ());
845
878
ConEQ.Distribute (&intervals_[firstComp]);
879
+ // Rewrite uses to the new regs.
880
+ rewrite (dupli_.getLI ()->reg );
846
881
}
847
882
} else {
848
883
DEBUG (dbgs () << " dupli became empty?\n " );
@@ -851,33 +886,7 @@ void SplitEditor::rewrite() {
851
886
}
852
887
853
888
// Rewrite instructions.
854
- const LiveInterval *curli = sa_.getCurLI ();
855
- for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin (curli->reg ),
856
- RE = mri_.reg_end (); RI != RE;) {
857
- MachineOperand &MO = RI.getOperand ();
858
- MachineInstr *MI = MO.getParent ();
859
- ++RI;
860
- if (MI->isDebugValue ()) {
861
- DEBUG (dbgs () << " Zapping " << *MI);
862
- // FIXME: We can do much better with debug values.
863
- MO.setReg (0 );
864
- continue ;
865
- }
866
- SlotIndex Idx = lis_.getInstructionIndex (MI);
867
- Idx = MO.isUse () ? Idx.getUseIndex () : Idx.getDefIndex ();
868
- LiveInterval *LI = 0 ;
869
- for (unsigned i = firstInterval, e = intervals_.size (); i != e; ++i) {
870
- LiveInterval *testli = intervals_[i];
871
- if (testli->liveAt (Idx)) {
872
- LI = testli;
873
- break ;
874
- }
875
- }
876
- assert (LI && " No register was live at use" );
877
- MO.setReg (LI->reg );
878
- DEBUG (dbgs () << " rewrite BB#" << MI->getParent ()->getNumber () << ' \t '
879
- << Idx << ' \t ' << *MI);
880
- }
889
+ rewrite (curli_->reg );
881
890
882
891
// Calculate spill weight and allocation hints for new intervals.
883
892
VirtRegAuxInfo vrai (vrm_.getMachineFunction (), lis_, sa_.loops_ );
@@ -944,7 +953,7 @@ void SplitEditor::splitAroundLoop(const MachineLoop *Loop) {
944
953
945
954
// Done.
946
955
closeIntv ();
947
- rewrite ();
956
+ finish ();
948
957
}
949
958
950
959
@@ -988,7 +997,7 @@ void SplitEditor::splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks) {
988
997
leaveIntvAfter (IP.second );
989
998
closeIntv ();
990
999
}
991
- rewrite ();
1000
+ finish ();
992
1001
}
993
1002
994
1003
@@ -1061,5 +1070,5 @@ void SplitEditor::splitInsideBlock(const MachineBasicBlock *MBB) {
1061
1070
closeIntv ();
1062
1071
}
1063
1072
1064
- rewrite ();
1073
+ finish ();
1065
1074
}
0 commit comments