[llvm-commits] [llvm] r64278 - in /llvm/trunk: lib/Transforms/Utils/BasicBlockUtils.cpp lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/dbginfo.ll

Devang Patel dpatel at apple.com
Tue Feb 10 17:29:06 PST 2009


Author: dpatel
Date: Tue Feb 10 19:29:06 2009
New Revision: 64278

URL: http://llvm.org/viewvc/llvm-project?rev=64278&view=rev
Log:
If llvm.dbg.region.end is disappearing then remove corresponding llvm.dbg.func.start also.

Modified:
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/trunk/test/Transforms/SimplifyCFG/dbginfo.ll

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

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Tue Feb 10 19:29:06 2009
@@ -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 @@
          // 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 @@
   // 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 @@
       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();
 }

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

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Feb 10 19:29:06 2009
@@ -1806,7 +1806,7 @@
         // 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;
       }

Modified: llvm/trunk/test/Transforms/SimplifyCFG/dbginfo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/dbginfo.ll?rev=64278&r1=64277&r2=64278&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/dbginfo.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/dbginfo.ll Tue Feb 10 19:29:06 2009
@@ -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* }





More information about the llvm-commits mailing list