aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-02-11 01:29:06 +0000
committerDevang Patel <dpatel@apple.com>2009-02-11 01:29:06 +0000
commitbd75b8345f9c2a6efd8fb799ba861129fed36ef8 (patch)
treeae0434eec030c9cbedf5a1ce8b5565f87e5fbffd
parent7dfa07f794a5dd4479e80896ef626bbe69455908 (diff)
If llvm.dbg.region.end is disappearing then remove corresponding llvm.dbg.func.start also.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64278 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp24
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp2
-rw-r--r--test/Transforms/SimplifyCFG/dbginfo.ll1
3 files changed, 24 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 7b633b2007..964fcc083d 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -15,6 +15,7 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
#include "llvm/Constant.h"
#include "llvm/Type.h"
#include "llvm/Analysis/AliasAnalysis.h"
@@ -31,7 +32,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
// Can delete self loop.
BB->getSinglePredecessor() == BB) && "Block is not dead!");
TerminatorInst *BBTerm = BB->getTerminator();
-
+ Value *DbgRegionEndContext = NULL;
// Loop through all of our successors and make sure they know that one
// of their predecessors is going away.
for (unsigned i = 0, e = BBTerm->getNumSuccessors(); i != e; ++i)
@@ -40,6 +41,10 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
// Zap all the instructions in the block.
while (!BB->empty()) {
Instruction &I = BB->back();
+ // It is possible to have multiple llvm.dbg.region.end in a block.
+ if (DbgRegionEndInst *DREI = dyn_cast<DbgRegionEndInst>(&I))
+ DbgRegionEndContext = DREI->getContext();
+
// If this instruction is used, replace uses with an arbitrary value.
// Because control flow can't get here, we don't care what we replace the
// value with. Note that since this block is unreachable, and all values
@@ -49,7 +54,22 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
I.replaceAllUsesWith(UndefValue::get(I.getType()));
BB->getInstList().pop_back();
}
-
+
+ if (DbgRegionEndContext) {
+ // Delete corresponding llvm.dbg.func.start from entry block.
+ BasicBlock &Entry = BB->getParent()->getEntryBlock();
+ DbgFuncStartInst *DbgFuncStart = NULL;
+ for (BasicBlock::iterator BI = Entry.begin(), BE = Entry.end();
+ BI != BE; ++BI) {
+ if (DbgFuncStartInst *DFSI = dyn_cast<DbgFuncStartInst>(BI)) {
+ DbgFuncStart = DFSI;
+ break;
+ }
+ }
+ if (DbgFuncStart && DbgFuncStart->getSubprogram() == DbgRegionEndContext)
+ DbgFuncStart->eraseFromParent();
+ }
+
// Zap the block!
BB->eraseFromParent();
}
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index b5d74232fe..86d4a7508c 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1806,7 +1806,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// If we eliminated all predecessors of the block, delete the block now.
if (pred_begin(BB) == pred_end(BB))
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ DeleteDeadBlock(BB);
return true;
}
diff --git a/test/Transforms/SimplifyCFG/dbginfo.ll b/test/Transforms/SimplifyCFG/dbginfo.ll
index c8f39545a9..ddbaccb165 100644
--- a/test/Transforms/SimplifyCFG/dbginfo.ll
+++ b/test/Transforms/SimplifyCFG/dbginfo.ll
@@ -1,4 +1,5 @@
; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep region | count 1
+; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep func.start | count 1
%llvm.dbg.anchor.type = type { i32, i32 }
%llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }
%llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }