From a248c45e005248c54704f7c616ccb8b7efe191e5 Mon Sep 17 00:00:00 2001 From: Zhou Sheng Date: Fri, 20 Feb 2009 16:31:35 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65123 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/Mem2Reg.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/Transforms/Utils/Mem2Reg.cpp b/lib/Transforms/Utils/Mem2Reg.cpp index 2b06d778e14..33fcd8c4860 100644 --- a/lib/Transforms/Utils/Mem2Reg.cpp +++ b/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 X("mem2reg", "Promote Memory to Register"); +/// Remove the invalid or redundant debug information. +static void CleanDbgInfo(Function& F) { + std::vector 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(I) && isa(NextI)) + DeadDbgs.push_back(I); + else if (isa(I) && isa(NextI)) + DeadDbgs.push_back(I); + } + } + + while (!DeadDbgs.empty()) { + Instruction *Inst = DeadDbgs.back(); + DeadDbgs.pop_back(); + Inst->eraseFromParent(); + } +} + bool PromotePass::runOnFunction(Function &F) { std::vector 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; } -- 2.34.1