aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineSSAUpdater.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-12-04 00:09:05 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-12-04 00:09:05 +0000
commite156f611abc45a71e25c301378a1d01c9f98103c (patch)
treea7c3d9777c52fc0f3e8727dfc91f345dd6e04afd /llvm/lib/CodeGen/MachineSSAUpdater.cpp
parent9f545181f7265b7559691da411b845ebba4d91c8 (diff)
downloadllvm-e156f611abc45a71e25c301378a1d01c9f98103c.zip
llvm-e156f611abc45a71e25c301378a1d01c9f98103c.tar.gz
llvm-e156f611abc45a71e25c301378a1d01c9f98103c.tar.bz2
- If the reaching definition is an undef and the use is a PHI, add the implicit_def to the end of the source block.
- When reaching value is replaced with another, update the cache as well. llvm-svn: 90501
Diffstat (limited to 'llvm/lib/CodeGen/MachineSSAUpdater.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineSSAUpdater.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/MachineSSAUpdater.cpp b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
index 644cb9d..31662b3 100644
--- a/llvm/lib/CodeGen/MachineSSAUpdater.cpp
+++ b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
@@ -194,17 +194,22 @@ void MachineSSAUpdater::RewriteUse(MachineOperand &U) {
if (UseMI->getOpcode() == TargetInstrInfo::PHI) {
MachineBasicBlock *SourceBB = findCorrespondingPred(UseMI, &U);
NewVR = GetValueAtEndOfBlock(SourceBB);
- } else {
- NewVR = GetValueInMiddleOfBlock(UseMI->getParent());
- }
-
- if (NewVR == ~0U) {
// Insert an implicit_def to represent an undef value.
MachineInstr *NewDef = InsertNewDef(TargetInstrInfo::IMPLICIT_DEF,
- UseMI->getParent(), UseMI, VRC,MRI,TII);
+ SourceBB,SourceBB->getFirstTerminator(),
+ VRC, MRI, TII);
NewVR = NewDef->getOperand(0).getReg();
+ } else {
+ NewVR = GetValueInMiddleOfBlock(UseMI->getParent());
+ if (NewVR == ~0U) {
+ // Insert an implicit_def to represent an undef value.
+ MachineInstr *NewDef = InsertNewDef(TargetInstrInfo::IMPLICIT_DEF,
+ UseMI->getParent(), UseMI,
+ VRC, MRI, TII);
+ NewVR = NewDef->getOperand(0).getReg();
+ }
}
-
+
U.setReg(NewVR);
}
@@ -281,7 +286,7 @@ unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){
/// this block is involved in a loop, a no-entry PHI node will have been
/// inserted as InsertedVal. Otherwise, we'll still have the null we inserted
/// above.
- unsigned InsertedVal = AvailableVals[BB];
+ unsigned &InsertedVal = AvailableVals[BB];
// If all the predecessor values are the same then we don't need to insert a
// PHI. This is the simple and common case.
@@ -294,10 +299,10 @@ unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){
assert(InsertedVal != SingularValue && "Dead loop?");
MRI->replaceRegWith(InsertedVal, SingularValue);
OldVal->eraseFromParent();
- } else {
- InsertedVal = SingularValue;
}
+ InsertedVal = SingularValue;
+
// Drop the entries we added in IncomingPredInfo to restore the stack.
IncomingPredInfo.erase(IncomingPredInfo.begin()+FirstPredInfoEntry,
IncomingPredInfo.end());
@@ -348,5 +353,4 @@ unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){
}
return InsertedVal;
-
}