projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make sure we emit a section for pubnames even if that section is
[oota-llvm.git]
/
lib
/
CodeGen
/
PHIElimination.cpp
diff --git
a/lib/CodeGen/PHIElimination.cpp
b/lib/CodeGen/PHIElimination.cpp
index aa84a60efdefce7b5026568a622418948ba898d9..e6ffb714aa99398fda1877393fe5410a083bec76 100644
(file)
--- a/
lib/CodeGen/PHIElimination.cpp
+++ b/
lib/CodeGen/PHIElimination.cpp
@@
-40,6
+40,11
@@
DisableEdgeSplitting("disable-phi-elim-edge-splitting", cl::init(false),
cl::Hidden, cl::desc("Disable critical edge splitting "
"during PHI elimination"));
cl::Hidden, cl::desc("Disable critical edge splitting "
"during PHI elimination"));
+static cl::opt<bool>
+SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false),
+ cl::Hidden, cl::desc("Split all critical edges during "
+ "PHI elimination"));
+
namespace {
class PHIElimination : public MachineFunctionPass {
MachineRegisterInfo *MRI; // Machine register information
namespace {
class PHIElimination : public MachineFunctionPass {
MachineRegisterInfo *MRI; // Machine register information
@@
-61,7
+66,7
@@
namespace {
///
bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
void LowerPHINode(MachineBasicBlock &MBB,
///
bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
void LowerPHINode(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator
AfterPHIs
It);
+ MachineBasicBlock::iterator
LastPHI
It);
/// analyzePHINodes - Gather information about the PHI nodes in
/// here. In particular, we want to map the number of uses of a virtual
/// analyzePHINodes - Gather information about the PHI nodes in
/// here. In particular, we want to map the number of uses of a virtual
@@
-111,6
+116,7
@@
INITIALIZE_PASS_END(PHIElimination, "phi-node-elimination",
void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<LiveVariables>();
void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<LiveVariables>();
+ AU.addPreserved<SlotIndexes>();
AU.addPreserved<LiveIntervals>();
AU.addPreserved<MachineDominatorTree>();
AU.addPreserved<MachineLoopInfo>();
AU.addPreserved<LiveIntervals>();
AU.addPreserved<MachineDominatorTree>();
AU.addPreserved<MachineLoopInfo>();
@@
-157,8
+163,8
@@
bool PHIElimination::runOnMachineFunction(MachineFunction &MF) {
// Clean up the lowered PHI instructions.
for (LoweredPHIMap::iterator I = LoweredPHIs.begin(), E = LoweredPHIs.end();
I != E; ++I) {
// Clean up the lowered PHI instructions.
for (LoweredPHIMap::iterator I = LoweredPHIs.begin(), E = LoweredPHIs.end();
I != E; ++I) {
- if (LIS)
- LIS->RemoveMachineInstrFromMaps(I->first);
+
if (LIS)
+
LIS->RemoveMachineInstrFromMaps(I->first);
MF.DeleteMachineInstr(I->first);
}
MF.DeleteMachineInstr(I->first);
}
@@
-166,9
+172,6
@@
bool PHIElimination::runOnMachineFunction(MachineFunction &MF) {
ImpDefs.clear();
VRegPHIUseCount.clear();
ImpDefs.clear();
VRegPHIUseCount.clear();
- if (LIS)
- MF.verify(this, "After PHI elimination");
-
return Changed;
}
return Changed;
}
@@
-182,10
+185,11
@@
bool PHIElimination::EliminatePHINodes(MachineFunction &MF,
// Get an iterator to the first instruction after the last PHI node (this may
// also be the end of the basic block).
// Get an iterator to the first instruction after the last PHI node (this may
// also be the end of the basic block).
- MachineBasicBlock::iterator AfterPHIsIt = MBB.SkipPHIsAndLabels(MBB.begin());
+ MachineBasicBlock::iterator LastPHIIt =
+ prior(MBB.SkipPHIsAndLabels(MBB.begin()));
while (MBB.front().isPHI())
while (MBB.front().isPHI())
- LowerPHINode(MBB,
AfterPHIs
It);
+ LowerPHINode(MBB,
LastPHI
It);
return true;
}
return true;
}
@@
-215,8
+219,11
@@
static bool isSourceDefinedByImplicitDef(const MachineInstr *MPhi,
/// LowerPHINode - Lower the PHI node at the top of the specified block,
///
void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
/// LowerPHINode - Lower the PHI node at the top of the specified block,
///
void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator
AfterPHIs
It) {
+ MachineBasicBlock::iterator
LastPHI
It) {
++NumLowered;
++NumLowered;
+
+ MachineBasicBlock::iterator AfterPHIsIt = llvm::next(LastPHIIt);
+
// Unlink the PHI node from the basic block, but don't delete the PHI yet.
MachineInstr *MPhi = MBB.remove(MBB.begin());
// Unlink the PHI node from the basic block, but don't delete the PHI yet.
MachineInstr *MPhi = MBB.remove(MBB.begin());
@@
-300,14
+307,13
@@
void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
// Update LiveIntervals for the new copy or implicit def.
if (LIS) {
MachineInstr *NewInstr = prior(AfterPHIsIt);
// Update LiveIntervals for the new copy or implicit def.
if (LIS) {
MachineInstr *NewInstr = prior(AfterPHIsIt);
- LIS->InsertMachineInstrInMaps(NewInstr);
+
SlotIndex DestCopyIndex =
LIS->InsertMachineInstrInMaps(NewInstr);
SlotIndex MBBStartIndex = LIS->getMBBStartIdx(&MBB);
SlotIndex MBBStartIndex = LIS->getMBBStartIdx(&MBB);
- SlotIndex DestCopyIndex = LIS->getInstructionIndex(NewInstr);
if (IncomingReg) {
// Add the region from the beginning of MBB to the copy instruction to
// IncomingReg's live interval.
if (IncomingReg) {
// Add the region from the beginning of MBB to the copy instruction to
// IncomingReg's live interval.
- LiveInterval &IncomingLI = LIS->
getOrCreate
Interval(IncomingReg);
+ LiveInterval &IncomingLI = LIS->
createEmpty
Interval(IncomingReg);
VNInfo *IncomingVNI = IncomingLI.getVNInfoAt(MBBStartIndex);
if (!IncomingVNI)
IncomingVNI = IncomingLI.getNextValue(MBBStartIndex,
VNInfo *IncomingVNI = IncomingLI.getVNInfoAt(MBBStartIndex);
if (!IncomingVNI)
IncomingVNI = IncomingLI.getNextValue(MBBStartIndex,
@@
-317,8
+323,10
@@
void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
IncomingVNI));
}
IncomingVNI));
}
- LiveInterval &DestLI = LIS->getOrCreateInterval(DestReg);
- if (NewInstr->getOperand(0).isDead()) {
+ LiveInterval &DestLI = LIS->getInterval(DestReg);
+ assert(DestLI.begin() != DestLI.end() &&
+ "PHIs should have nonempty LiveIntervals.");
+ if (DestLI.endIndex().isDead()) {
// A dead PHI's live range begins and ends at the start of the MBB, but
// the lowered copy, which will still be dead, needs to begin and end at
// the copy instruction.
// A dead PHI's live range begins and ends at the start of the MBB, but
// the lowered copy, which will still be dead, needs to begin and end at
// the copy instruction.
@@
-462,7
+470,11
@@
void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
bool isLiveOut = false;
for (MachineBasicBlock::succ_iterator SI = opBlock.succ_begin(),
SE = opBlock.succ_end(); SI != SE; ++SI) {
bool isLiveOut = false;
for (MachineBasicBlock::succ_iterator SI = opBlock.succ_begin(),
SE = opBlock.succ_end(); SI != SE; ++SI) {
- if (SrcLI.liveAt(LIS->getMBBStartIdx(*SI))) {
+ SlotIndex startIdx = LIS->getMBBStartIdx(*SI);
+ VNInfo *VNI = SrcLI.getVNInfoAt(startIdx);
+
+ // Definitions by other PHIs are not truly live-in for our purposes.
+ if (VNI && VNI->def != startIdx) {
isLiveOut = true;
break;
}
isLiveOut = true;
break;
}
@@
-550,10
+562,10
@@
bool PHIElimination::SplitPHIEdges(MachineFunction &MF,
// Avoid splitting backedges of loops. It would introduce small
// out-of-line blocks into the loop which is very bad for code placement.
// Avoid splitting backedges of loops. It would introduce small
// out-of-line blocks into the loop which is very bad for code placement.
- if (PreMBB == &MBB)
+ if (PreMBB == &MBB
&& !SplitAllCriticalEdges
)
continue;
const MachineLoop *PreLoop = MLI ? MLI->getLoopFor(PreMBB) : 0;
continue;
const MachineLoop *PreLoop = MLI ? MLI->getLoopFor(PreMBB) : 0;
- if (IsLoopHeader && PreLoop == CurLoop)
+ if (IsLoopHeader && PreLoop == CurLoop
&& !SplitAllCriticalEdges
)
continue;
// LV doesn't consider a phi use live-out, so isLiveOut only returns true
continue;
// LV doesn't consider a phi use live-out, so isLiveOut only returns true
@@
-562,7
+574,7
@@
bool PHIElimination::SplitPHIEdges(MachineFunction &MF,
// there is a risk it may not be coalesced away.
//
// If the copy would be a kill, there is no need to split the edge.
// there is a risk it may not be coalesced away.
//
// If the copy would be a kill, there is no need to split the edge.
- if (!isLiveOutPastPHIs(Reg, PreMBB))
+ if (!isLiveOutPastPHIs(Reg, PreMBB)
&& !SplitAllCriticalEdges
)
continue;
DEBUG(dbgs() << PrintReg(Reg) << " live-out before critical edge BB#"
continue;
DEBUG(dbgs() << PrintReg(Reg) << " live-out before critical edge BB#"
@@
-577,7
+589,7
@@
bool PHIElimination::SplitPHIEdges(MachineFunction &MF,
// is likely to be left after coalescing. If we are looking at a loop
// exiting edge, split it so we won't insert code in the loop, otherwise
// don't bother.
// is likely to be left after coalescing. If we are looking at a loop
// exiting edge, split it so we won't insert code in the loop, otherwise
// don't bother.
- bool ShouldSplit = !isLiveIn(Reg, &MBB);
+ bool ShouldSplit = !isLiveIn(Reg, &MBB)
|| SplitAllCriticalEdges
;
// Check for a loop exiting edge.
if (!ShouldSplit && CurLoop != PreLoop) {
// Check for a loop exiting edge.
if (!ShouldSplit && CurLoop != PreLoop) {