[llvm-commits] [llvm] r65123 - /llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp

Zhou Sheng zhousheng00 at gmail.com
Fri Feb 20 08:31:36 PST 2009


Author: sheng
Date: Fri Feb 20 10:31:35 2009
New Revision: 65123

URL: http://llvm.org/viewvc/llvm-project?rev=65123&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp

Modified: llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp?rev=65123&r1=65122&r2=65123&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Mem2Reg.cpp Fri Feb 20 10:31:35 2009
@@ -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 @@
 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 @@
     if (Allocas.empty()) break;
 
     PromoteMemToReg(Allocas, DT, DF);
+    CleanDbgInfo(F);
     NumPromoted += Allocas.size();
     Changed = true;
   }





More information about the llvm-commits mailing list