summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/DemoteRegToStack.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-09-27 19:39:00 +0000
committerChris Lattner <sabre@nondot.org>2005-09-27 19:39:00 +0000
commit6d7277b3b4c4847a39841cdac3e3fd29bd54fa85 (patch)
tree6644a17033d47892cf61c717e212589863e7e1d7 /lib/Transforms/Utils/DemoteRegToStack.cpp
parentcc0f703f421a5893cf3203c0aa35d597dbdee195 (diff)
downloadllvm-6d7277b3b4c4847a39841cdac3e3fd29bd54fa85.tar.gz
llvm-6d7277b3b4c4847a39841cdac3e3fd29bd54fa85.tar.bz2
llvm-6d7277b3b4c4847a39841cdac3e3fd29bd54fa85.tar.xz
allow demotion to volatile values, add support for invoke
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23473 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/DemoteRegToStack.cpp')
-rw-r--r--lib/Transforms/Utils/DemoteRegToStack.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/Transforms/Utils/DemoteRegToStack.cpp b/lib/Transforms/Utils/DemoteRegToStack.cpp
index ecd92f7fdb..bbf998d790 100644
--- a/lib/Transforms/Utils/DemoteRegToStack.cpp
+++ b/lib/Transforms/Utils/DemoteRegToStack.cpp
@@ -29,7 +29,7 @@ using namespace llvm;
/// invalidating the SSA information for the value. It returns the pointer to
/// the alloca inserted to create a stack slot for I.
///
-AllocaInst* llvm::DemoteRegToStack(Instruction &I) {
+AllocaInst* llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads) {
if (I.use_empty()) return 0; // nothing to do!
// Create a stack slot to hold the value.
@@ -57,7 +57,7 @@ AllocaInst* llvm::DemoteRegToStack(Instruction &I) {
Value *&V = Loads[PN->getIncomingBlock(i)];
if (V == 0) {
// Insert the load into the predecessor block
- V = new LoadInst(Slot, I.getName()+".reload",
+ V = new LoadInst(Slot, I.getName()+".reload", VolatileLoads,
PN->getIncomingBlock(i)->getTerminator());
}
PN->setIncomingValue(i, V);
@@ -65,7 +65,7 @@ AllocaInst* llvm::DemoteRegToStack(Instruction &I) {
} else {
// If this is a normal instruction, just insert a load.
- Value *V = new LoadInst(Slot, I.getName()+".reload", U);
+ Value *V = new LoadInst(Slot, I.getName()+".reload", VolatileLoads, U);
U->replaceUsesOfWith(&I, V);
}
}
@@ -74,18 +74,21 @@ AllocaInst* llvm::DemoteRegToStack(Instruction &I) {
// Insert stores of the computed value into the stack slot. We have to be
// careful is I is an invoke instruction though, because we can't insert the
// store AFTER the terminator instruction.
+ BasicBlock::iterator InsertPt;
if (!isa<TerminatorInst>(I)) {
- BasicBlock::iterator InsertPt = &I;
- for (++InsertPt; isa<PHINode>(InsertPt); ++InsertPt)
- /* empty */; // Don't insert before any PHI nodes.
- new StoreInst(&I, Slot, InsertPt);
+ InsertPt = &I;
} else {
- // FIXME: We cannot yet demote invoke instructions to the stack, because
- // doing so would require breaking critical edges. This should be fixed
- // eventually.
- assert(0 &&
- "Cannot demote the value computed by an invoke instruction yet!");
+ // We cannot demote invoke instructions to the stack if their normal edge
+ // is critical.
+ InvokeInst &II = cast<InvokeInst>(I);
+ assert(II.getNormalDest()->getSinglePredecessor() &&
+ "Cannot demote invoke with a critical successor!");
+ InsertPt = II.getNormalDest()->begin();
}
+ for (++InsertPt; isa<PHINode>(InsertPt); ++InsertPt)
+ /* empty */; // Don't insert before any PHI nodes.
+ new StoreInst(&I, Slot, InsertPt);
+
return Slot;
}