[llvm-commits] [llvm] r65356 - in /llvm/branches/Apple/Dib: lib/CodeGen/AsmPrinter/DwarfWriter.cpp lib/Transforms/Utils/BasicBlockUtils.cpp lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/dbginfo.ll

Bill Wendling isanbard at gmail.com
Mon Feb 23 16:47:20 PST 2009


Author: void
Date: Mon Feb 23 18:47:19 2009
New Revision: 65356

URL: http://llvm.org/viewvc/llvm-project?rev=65356&view=rev
Log:
--- Merging (from foreign repository) r65352 into '.':
U    lib/CodeGen/AsmPrinter/DwarfWriter.cpp

If there is not any debug info available for any global variables and any
subprograms then there is not any debug info to emit.

--- Merging (from foreign repository) r65353 into '.':
U    test/Transforms/SimplifyCFG/dbginfo.ll
U    lib/Transforms/Utils/SimplifyCFG.cpp
U    lib/Transforms/Utils/BasicBlockUtils.cpp

While folding unconditional return move DbgRegionEndInst into the predecessor,
instead of removing it. This fixes following tests from llvmgcc42 testsuite.

gcc.c-torture/execute/20000605-3.c
gcc.c-torture/execute/20020619-1.c
gcc.c-torture/execute/20030920-1.c
gcc.c-torture/execute/loop-ivopts-1.c

Modified:
    llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
    llvm/branches/Apple/Dib/lib/Transforms/Utils/BasicBlockUtils.cpp
    llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/branches/Apple/Dib/test/Transforms/SimplifyCFG/dbginfo.ll

Modified: llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=65356&r1=65355&r2=65356&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Mon Feb 23 18:47:19 2009
@@ -2823,11 +2823,13 @@
   }
 
   /// ConstructGlobalVariableDIEs - Create DIEs for each of the externally 
-  /// visible global variables.
-  void ConstructGlobalVariableDIEs() {
+  /// visible global variables. Return true if at least one global DIE is
+  /// created.
+  bool ConstructGlobalVariableDIEs() {
     std::string GVName = "llvm.dbg.global_variables";
     std::vector<GlobalVariable*> Result;
     getGlobalVariablesUsing(*M, GVName, Result);
+    bool result = false;
     for (std::vector<GlobalVariable *>::iterator GVI = Result.begin(),
            GVE = Result.end(); GVI != GVE; ++GVI) {
       DIGlobalVariable DI_GV(*GVI);
@@ -2850,22 +2852,24 @@
 
       //Add to map.
       Slot = VariableDie;
-
       //Add to context owner.
       DW_Unit->getDie()->AddChild(VariableDie);
-
       //Expose as global. FIXME - need to check external flag.
       DW_Unit->AddGlobal(DI_GV.getName(), VariableDie);
+     
+      if (!result)
+        result = true;
     }
+    return result;
   }
 
   /// ConstructSubprograms - Create DIEs for each of the externally visible
-  /// subprograms.
-  void ConstructSubprograms() {
-
+  /// subprograms. Return true if at least one subprogram DIE is created.
+  bool ConstructSubprograms() {
     std::string SPName = "llvm.dbg.subprograms";
     std::vector<GlobalVariable*> Result;
     getGlobalVariablesUsing(*M, SPName, Result);
+    bool result = false;
     for (std::vector<GlobalVariable *>::iterator RI = Result.begin(),
            RE = Result.end(); RI != RE; ++RI) {
 
@@ -2891,7 +2895,11 @@
       Unit->getDie()->AddChild(SubprogramDie);
       //Expose as global.
       Unit->AddGlobal(SP.getName(), SubprogramDie);
+      
+      if (!result)
+        result = true;
     }
+    return result;
   }
 
 public:
@@ -2927,15 +2935,20 @@
     if (DW_CUs.empty())
       return;
 
-    MMI = mmi;
-    shouldEmit = true;
-    MMI->setDebugInfoAvailability(true);
-
     // Create DIEs for each of the externally visible global variables.
-    ConstructGlobalVariableDIEs();
+    bool globalDIEs = ConstructGlobalVariableDIEs();
 
     // Create DIEs for each of the externally visible subprograms.
-    ConstructSubprograms();
+    bool subprogramDIEs = ConstructSubprograms();
+
+    // If there is not any debug info available for any global variables
+    // and any subprograms then there is not any debug info to emit.
+    if (!globalDIEs && !subprogramDIEs)
+      return;
+
+    MMI = mmi;
+    shouldEmit = true;
+    MMI->setDebugInfoAvailability(true);
 
     // Prime section data.
     SectionMap.insert(TAI->getTextSection());

Modified: llvm/branches/Apple/Dib/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=65356&r1=65355&r2=65356&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/Utils/BasicBlockUtils.cpp Mon Feb 23 18:47:19 2009
@@ -15,7 +15,6 @@
 #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"
@@ -32,7 +31,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)
@@ -41,10 +40,6 @@
   // 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
@@ -54,22 +49,7 @@
       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/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp?rev=65356&r1=65355&r2=65356&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp Mon Feb 23 18:47:19 2009
@@ -1789,6 +1789,13 @@
           Instruction *NewRet = RI->clone();
           Pred->getInstList().push_back(NewRet);
 
+          BasicBlock::iterator BBI = RI;
+          if (BBI != BB->begin()) {
+            // Move region end info into the predecessor.
+            if (DbgRegionEndInst *DREI = dyn_cast<DbgRegionEndInst>(--BBI))
+              DREI->moveBefore(NewRet);
+          }
+
           // If the return instruction returns a value, and if the value was a
           // PHI node in "BB", propagate the right value into the return.
           for (User::op_iterator i = NewRet->op_begin(), e = NewRet->op_end();
@@ -1806,7 +1813,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.
-          DeleteDeadBlock(BB);
+          M->getBasicBlockList().erase(BB);
 
         return true;
       }

Modified: llvm/branches/Apple/Dib/test/Transforms/SimplifyCFG/dbginfo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/Transforms/SimplifyCFG/dbginfo.ll?rev=65356&r1=65355&r2=65356&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/test/Transforms/SimplifyCFG/dbginfo.ll (original)
+++ llvm/branches/Apple/Dib/test/Transforms/SimplifyCFG/dbginfo.ll Mon Feb 23 18:47:19 2009
@@ -1,5 +1,7 @@
-; 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
+; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep region | count 2
+; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep func.start | count 2
+; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | not grep "br label"
+
 	%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