[llvm-commits] [llvm] r56472 - /llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp
Owen Anderson
resistor at mac.com
Mon Sep 22 14:58:58 PDT 2008
Author: resistor
Date: Mon Sep 22 16:58:58 2008
New Revision: 56472
URL: http://llvm.org/viewvc/llvm-project?rev=56472&view=rev
Log:
Significant improvements to the logic for merging live intervals. This code can't
just use LI::MergeValueAsValue, as its behavior in the presence of overlapping ranges
isn't what StrongPHIElimination wants.
Modified:
llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp
Modified: llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp?rev=56472&r1=56471&r2=56472&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp (original)
+++ llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp Mon Sep 22 16:58:58 2008
@@ -33,6 +33,7 @@
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
using namespace llvm;
namespace {
@@ -546,6 +547,12 @@
}
// Add the renaming set for this PHI node to our overall renaming information
+ for (std::map<unsigned, MachineBasicBlock*>::iterator QI = PHIUnion.begin(),
+ QE = PHIUnion.end(); QI != QE; ++QI) {
+ DOUT << "Adding Renaming: " << QI->first << " -> "
+ << P->getOperand(0).getReg() << "\n";
+ }
+
RenameSets.insert(std::make_pair(P->getOperand(0).getReg(), PHIUnion));
// Remember which registers are already renamed, so that we don't try to
@@ -762,10 +769,19 @@
std::set<unsigned> RegHandled;
for (SmallVector<std::pair<unsigned, MachineInstr*>, 4>::iterator I =
InsertedPHIDests.begin(), E = InsertedPHIDests.end(); I != E; ++I) {
- if (RegHandled.insert(I->first).second &&
- !LI.getOrCreateInterval(I->first).liveAt(
- LI.getMBBEndIdx(I->second->getParent())))
- LI.addLiveRangeToEndOfBlock(I->first, I->second);
+ if (RegHandled.insert(I->first).second) {
+ LiveInterval& Int = LI.getOrCreateInterval(I->first);
+ unsigned instrIdx = LI.getInstructionIndex(I->second);
+ if (Int.liveAt(LiveIntervals::getDefIndex(instrIdx)))
+ Int.removeRange(LiveIntervals::getDefIndex(instrIdx),
+ LI.getMBBEndIdx(I->second->getParent())+1,
+ true);
+
+ LiveRange R = LI.addLiveRangeToEndOfBlock(I->first, I->second);
+ R.valno->copy = I->second;
+ R.valno->def =
+ LiveIntervals::getDefIndex(LI.getInstructionIndex(I->second));
+ }
}
}
@@ -836,20 +852,39 @@
LiveInterval& RHS = LI.getOrCreateInterval(secondary);
LI.computeNumbering();
-
- SmallVector<VNInfo*, 4> VNSet (RHS.vni_begin(), RHS.vni_end());
+
DenseMap<VNInfo*, VNInfo*> VNMap;
- for (SmallVector<VNInfo*, 4>::iterator VI = VNSet.begin(),
- VE = VNSet.end(); VI != VE; ++VI) {
- VNInfo* NewVN = LHS.getNextValue((*VI)->def,
- (*VI)->copy,
- LI.getVNInfoAllocator());
- LHS.MergeValueInAsValue(RHS, *VI, NewVN);
- RHS.removeValNo(*VI);
+ for (LiveInterval::iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
+ LiveRange R = *I;
+
+ unsigned Start = R.start;
+ unsigned End = R.end;
+ if (LHS.liveAt(Start))
+ LHS.removeRange(Start, End, true);
+
+ if (const LiveRange* ER = LHS.getLiveRangeContaining(End))
+ End = ER->start;
+
+ LiveInterval::iterator RI = std::upper_bound(LHS.begin(), LHS.end(), R);
+ if (RI != LHS.end() && RI->start < End)
+ End = RI->start;
+
+ if (Start != End) {
+ VNInfo* OldVN = R.valno;
+ VNInfo*& NewVN = VNMap[OldVN];
+ if (!NewVN) {
+ NewVN = LHS.getNextValue(OldVN->def,
+ OldVN->copy,
+ LI.getVNInfoAllocator());
+ NewVN->kills = OldVN->kills;
+ }
+
+ LiveRange LR (Start, End, NewVN);
+ LHS.addRange(LR);
+ }
}
- if (RHS.empty())
- LI.removeInterval(RHS.reg);
+ LI.removeInterval(RHS.reg);
}
bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
@@ -881,6 +916,7 @@
unsigned reg = OI->first;
++OI;
I->second.erase(reg);
+ DOUT << "Removing Renaming: " << reg << " -> " << I->first << "\n";
}
}
}
@@ -897,6 +933,8 @@
while (I->second.size()) {
std::map<unsigned, MachineBasicBlock*>::iterator SI = I->second.begin();
+ DOUT << "Renaming: " << SI->first << " -> " << I->first << "\n";
+
if (SI->first != I->first) {
mergeLiveIntervals(I->first, SI->first);
Fn.getRegInfo().replaceRegWith(SI->first, I->first);
More information about the llvm-commits
mailing list