Skip to content

Commit 959fcc6

Browse files
committed
Rename SplitEditor::rewrite to finish() and break it out into a couple of new
functions: computeRemainder and rewrite. When the remainder breaks up into multiple components, remember to rewrite those uses as well. llvm-svn: 116121
1 parent 5eee9f7 commit 959fcc6

File tree

2 files changed

+56
-40
lines changed

2 files changed

+56
-40
lines changed

llvm/lib/CodeGen/SplitKit.cpp

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,36 @@ void SplitEditor::closeIntv() {
734734
openli_.reset(0);
735735
}
736736

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+
737767
void
738768
SplitEditor::addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
739769
// Build vector of iterator pairs from the intervals.
@@ -781,12 +811,7 @@ SplitEditor::addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
781811
}
782812
}
783813

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() {
790815
// First we need to fill in the live ranges in dupli.
791816
// If values were redefined, we need a full recoloring with SSA update.
792817
// If values were truncated, we only need to truncate the ranges.
@@ -827,6 +852,14 @@ void SplitEditor::rewrite() {
827852
dupli_.addSimpleRange(LR.start, LR.end, LR.valno);
828853
}
829854
}
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();
830863

831864
// Get rid of unused values and set phi-kill flags.
832865
dupli_.getLI()->RenumberValues(lis_);
@@ -843,6 +876,8 @@ void SplitEditor::rewrite() {
843876
for (unsigned i = 1; i != NumComp; ++i)
844877
intervals_.push_back(createInterval());
845878
ConEQ.Distribute(&intervals_[firstComp]);
879+
// Rewrite uses to the new regs.
880+
rewrite(dupli_.getLI()->reg);
846881
}
847882
} else {
848883
DEBUG(dbgs() << " dupli became empty?\n");
@@ -851,33 +886,7 @@ void SplitEditor::rewrite() {
851886
}
852887

853888
// 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);
881890

882891
// Calculate spill weight and allocation hints for new intervals.
883892
VirtRegAuxInfo vrai(vrm_.getMachineFunction(), lis_, sa_.loops_);
@@ -944,7 +953,7 @@ void SplitEditor::splitAroundLoop(const MachineLoop *Loop) {
944953

945954
// Done.
946955
closeIntv();
947-
rewrite();
956+
finish();
948957
}
949958

950959

@@ -988,7 +997,7 @@ void SplitEditor::splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks) {
988997
leaveIntvAfter(IP.second);
989998
closeIntv();
990999
}
991-
rewrite();
1000+
finish();
9921001
}
9931002

9941003

@@ -1061,5 +1070,5 @@ void SplitEditor::splitInsideBlock(const MachineBasicBlock *MBB) {
10611070
closeIntv();
10621071
}
10631072

1064-
rewrite();
1073+
finish();
10651074
}

llvm/lib/CodeGen/SplitKit.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class LiveIntervalMap {
229229
/// - Mark the ranges where the new interval is used with useIntv*
230230
/// - Mark the places where the interval is exited with exitIntv*.
231231
/// - Finish the current interval with closeIntv and repeat from 2.
232-
/// - Rewrite instructions with rewrite().
232+
/// - Rewrite instructions with finish().
233233
///
234234
class SplitEditor {
235235
SplitAnalysis &sa_;
@@ -271,6 +271,13 @@ class SplitEditor {
271271
/// truncating any overlap with intervals_.
272272
void addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI);
273273

274+
/// computeRemainder - Compute the dupli liveness as the complement of all the
275+
/// new intervals.
276+
void computeRemainder();
277+
278+
/// rewrite - Rewrite all uses of reg to use the new registers.
279+
void rewrite(unsigned reg);
280+
274281
public:
275282
/// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
276283
/// Newly created intervals will be appended to newIntervals.
@@ -307,9 +314,9 @@ class SplitEditor {
307314
/// LiveInterval, and ranges can be trimmed.
308315
void closeIntv();
309316

310-
/// rewrite - after all the new live ranges have been created, rewrite
311-
/// instructions using curli to use the new intervals.
312-
void rewrite();
317+
/// finish - after all the new live ranges have been created, compute the
318+
/// remaining live range, and rewrite instructions to use the new registers.
319+
void finish();
313320

314321
// ===--- High level methods ---===
315322

0 commit comments

Comments
 (0)