summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorZhou Sheng <zhousheng00@gmail.com>2009-02-20 16:31:35 +0000
committerZhou Sheng <zhousheng00@gmail.com>2009-02-20 16:31:35 +0000
commit6a0634d423eed1202936424b73d9f0bf1dab5940 (patch)
tree2c38b808bbbc5e9495f0d07b1c0437892b7f1b7a /llvm/lib/Transforms
parentf13820148bbf9866376e53c9b6930d35b8da699a (diff)
downloadbcm5719-llvm-6a0634d423eed1202936424b73d9f0bf1dab5940.tar.gz
bcm5719-llvm-6a0634d423eed1202936424b73d9f0bf1dab5940.zip
patch to update the line number information in pass -mem2reg.
Currently this pass will delete the variable declaration info, and keep the line number info. But the kept line number info is not updated, and some is redundant or not correct, this patch just updates those info. llvm-svn: 65123
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Utils/Mem2Reg.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Mem2Reg.cpp b/llvm/lib/Transforms/Utils/Mem2Reg.cpp
index 2b06d778e14..33fcd8c4860 100644
--- a/llvm/lib/Transforms/Utils/Mem2Reg.cpp
+++ b/llvm/lib/Transforms/Utils/Mem2Reg.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
+#include "llvm/IntrinsicInst.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Instructions.h"
#include "llvm/Function.h"
@@ -53,6 +54,30 @@ namespace {
char PromotePass::ID = 0;
static RegisterPass<PromotePass> X("mem2reg", "Promote Memory to Register");
+/// Remove the invalid or redundant debug information.
+static void CleanDbgInfo(Function& F) {
+ std::vector<Instruction*> DeadDbgs;
+ for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) {
+ if (BBI->size() <= 1)
+ continue;
+ for (BasicBlock::iterator I = BBI->begin(), E = BBI->getTerminator();
+ I != E; ++I) {
+ BasicBlock::iterator NextI = I;
+ ++NextI;
+ if (isa<DbgStopPointInst>(I) && isa<DbgStopPointInst>(NextI))
+ DeadDbgs.push_back(I);
+ else if (isa<DbgStopPointInst>(I) && isa<BranchInst>(NextI))
+ DeadDbgs.push_back(I);
+ }
+ }
+
+ while (!DeadDbgs.empty()) {
+ Instruction *Inst = DeadDbgs.back();
+ DeadDbgs.pop_back();
+ Inst->eraseFromParent();
+ }
+}
+
bool PromotePass::runOnFunction(Function &F) {
std::vector<AllocaInst*> Allocas;
@@ -76,6 +101,7 @@ bool PromotePass::runOnFunction(Function &F) {
if (Allocas.empty()) break;
PromoteMemToReg(Allocas, DT, DF);
+ CleanDbgInfo(F);
NumPromoted += Allocas.size();
Changed = true;
}
OpenPOWER on IntegriCloud