aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-11-07 01:30:07 +0000
committerDevang Patel <dpatel@apple.com>2008-11-07 01:30:07 +0000
commit180ffaef18bdd0b1b972657b949c67cf96a20a48 (patch)
tree50338ecc0e0349bad82ef8d41883d512e2e3a630 /lib/Transforms/Utils/PromoteMemoryToRegister.cpp
parent89217a6f1852e764e58c489872b2d155dc2b7b8b (diff)
Handle (delete) dbg intrinsics while promoting alloca.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58826 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/PromoteMemoryToRegister.cpp')
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 2c1ad10517..0866a1361f 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -22,6 +22,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/ADT/DenseMap.h"
@@ -79,7 +80,18 @@ bool llvm::isAllocaPromotable(const AllocaInst *AI) {
if (SI->isVolatile())
return false;
} else {
- return false; // Not a load or store.
+ const BitCastInst *BC = dyn_cast<BitCastInst>(*UI);
+ if (!BC)
+ return false; // Not a load or store or dbg intrinsic.
+ Value::use_const_iterator BCUI = BC->use_begin(), BCUE = BC->use_end();
+ if (BCUI == BCUE)
+ return false; // Not a dbg intrinsic.
+ const DbgInfoIntrinsic *DI = dyn_cast<DbgInfoIntrinsic>(*BCUI);
+ if (!DI)
+ return false; // Not a dbg intrinsic.
+ BCUI++;
+ if (BCUI != BCUE)
+ return false; // Not a dbg intrinsic use.
}
return true;
@@ -275,14 +287,21 @@ namespace {
/// ivars.
void AnalyzeAlloca(AllocaInst *AI) {
clear();
-
+
// As we scan the uses of the alloca instruction, keep track of stores,
// and decide whether all of the loads and stores to the alloca are within
// the same basic block.
for (Value::use_iterator U = AI->use_begin(), E = AI->use_end();
U != E; ++U) {
Instruction *User = cast<Instruction>(*U);
- if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
+ if (BitCastInst *BC = dyn_cast<BitCastInst>(User)) {
+ // Remove dbg intrinsic uses now.
+ Value::use_iterator BCUI = BC->use_begin();
+ DbgInfoIntrinsic *DI = cast<DbgInfoIntrinsic>(*BCUI);
+ assert (BCUI + 1 == BC->use_end() && "Unexpected alloca uses!");
+ DI->eraseFromParent();
+ BC->eraseFromParent();
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
// Remember the basic blocks which define new values for the alloca
DefiningBlocks.push_back(SI->getParent());
AllocaPointerVal = SI->getOperand(0);