[llvm-commits] [llvm-gcc-4.2] r66919 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: llvm-convert.cpp llvm-debug.cpp llvm-debug.h

Bill Wendling isanbard at gmail.com
Fri Mar 13 11:26:46 PDT 2009


Author: void
Date: Fri Mar 13 13:26:45 2009
New Revision: 66919

URL: http://llvm.org/viewvc/llvm-project?rev=66919&view=rev
Log:
--- Merging (from foreign repository) r66861 into '.':
U    gcc/llvm-convert.cpp
U    gcc/llvm-debug.cpp
U    gcc/llvm-debug.h

Keep track of lexical scopes while emitting debug info.

Modified:
    llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp
    llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp
    llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.h

Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp?rev=66919&r1=66918&r2=66919&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp Fri Mar 13 13:26:45 2009
@@ -895,6 +895,9 @@
 }
 
 Function *TreeToLLVM::EmitFunction() {
+  if (TheDebugInfo)
+    TheDebugInfo->ClearVarCache();
+
   // Set up parameters and prepare for return, for the function.
   StartFunctionBody();
 
@@ -902,12 +905,43 @@
   basic_block bb;
   edge e;
   edge_iterator ei;
+  tree stmt_block = NULL_TREE;
   FOR_EACH_BB (bb) {
     for (block_stmt_iterator bsi = bsi_start (bb); !bsi_end_p (bsi);
          bsi_next (&bsi)) {
       MemRef DestLoc;
       tree stmt = bsi_stmt (bsi);
+      // FIXME : Optimizer and code generator are not doing the right thing yet
+      // while dealing with variable's debug info locations.
+      if (TheDebugInfo && !optimize) {
+        if (stmt_block == NULL_TREE) 
+          // This is beginning of function. llvm.dbg.func.start is emitted so
+          // no need to emit llvm.dbg.region.start here.
+          stmt_block = BLOCK_SUBBLOCKS (stmt);
+        else {
+          tree new_stmt_block = BLOCK_SUBBLOCKS (stmt);
+          if (new_stmt_block) {
+            if (stmt_block != new_stmt_block) {
+              if (BLOCK_SUPERCONTEXT (new_stmt_block) == stmt_block) 
+                // Entering new scope. Emit llvm.dbg.func.start.
+                TheDebugInfo->EmitRegionStart(Builder.GetInsertBlock());
+              else if (BLOCK_SUPERCONTEXT (new_stmt_block) == 
+                       BLOCK_SUPERCONTEXT (stmt_block)) {
+                // Entering new scope at the same level. End previous current 
+                // region by emitting llvm.dbg.region.end. And emit 
+                // llvm.dbg.region.start to start new region.
+                TheDebugInfo->EmitRegionEnd(Builder.GetInsertBlock());
+                TheDebugInfo->EmitRegionStart(Builder.GetInsertBlock());
+              } else
+                // Leaving current scop.e Emit llvm.dbg.region.end.
+                TheDebugInfo->EmitRegionEnd(Builder.GetInsertBlock());
 
+              stmt_block = BLOCK_SUBBLOCKS (stmt);
+            }
+          }
+        }
+      }
+        
       // If this stmt returns an aggregate value (e.g. a call whose result is
       // ignored), create a temporary to receive the value.  Note that we don't
       // do this for MODIFY_EXPRs as an efficiency hack.
@@ -1744,17 +1778,6 @@
       Builder.CreateStore(Constant::getNullValue(T), AI);
     }
   
-  if (TheDebugInfo) {
-    if (DECL_NAME(decl)) {
-      TheDebugInfo->EmitDeclare(decl, dwarf::DW_TAG_auto_variable,
-                                Name, TREE_TYPE(decl), AI,
-                                Builder.GetInsertBlock());
-    } else if (TREE_CODE(decl) == RESULT_DECL) {
-      TheDebugInfo->EmitDeclare(decl, dwarf::DW_TAG_return_variable,
-                                Name, TREE_TYPE(decl), AI,
-                                Builder.GetInsertBlock());
-    }
-  }
 }
 
 //===----------------------------------------------------------------------===//
@@ -5868,6 +5891,7 @@
 //===----------------------------------------------------------------------===//
 
 LValue TreeToLLVM::EmitLV_DECL(tree exp) {
+
   if (TREE_CODE(exp) == PARM_DECL || TREE_CODE(exp) == VAR_DECL || 
       TREE_CODE(exp) == CONST_DECL) {
     // If a static var's type was incomplete when the decl was written,
@@ -5945,6 +5969,14 @@
       Alignment = DECL_ALIGN(exp) / 8;
   }
 
+  if (TheDebugInfo) {
+    if (DECL_NAME(exp))
+      TheDebugInfo->EmitDeclare(exp, dwarf::DW_TAG_auto_variable,
+                                IDENTIFIER_POINTER (DECL_NAME (exp)), 
+                                TREE_TYPE(exp), Decl,
+                                Builder.GetInsertBlock());
+  }
+
   return LValue(BitCastToType(Decl, PTy), Alignment);
 }
 

Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=66919&r1=66918&r2=66919&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Fri Mar 13 13:26:45 2009
@@ -298,6 +298,11 @@
 
   assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
 
+  // Check to see if the compile unit already has created this type.
+  llvm::DIVariable &Slot = VarCache[decl];
+  if (!Slot.isNull())
+    return;
+
   expanded_location Loc = GetNodeLocation(decl, false);
 
   // Construct variable.
@@ -306,6 +311,8 @@
                                 getOrCreateCompileUnit(Loc.file),
                                 Loc.line, getOrCreateType(type));
 
+  VarCache[decl] = D;
+
   // Insert an llvm.dbg.declare into the current block.
   DebugFactory.InsertDeclare(AI, D, CurBB);
 }
@@ -846,6 +853,11 @@
   getOrCreateCompileUnit(main_input_filename, true);
 }
 
+/// ClearDeclCache - Clear variable debug info cache.
+void DebugInfo::ClearVarCache() {
+  VarCache.clear();
+}
+
 /// getOrCreateCompileUnit - Get the compile unit from the cache or 
 /// create a new one if necessary.
 DICompileUnit DebugInfo::getOrCreateCompileUnit(const char *FullPath,

Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.h?rev=66919&r1=66918&r2=66919&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.h (original)
+++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.h Fri Mar 13 13:26:45 2009
@@ -63,6 +63,9 @@
   std::map<tree_node *, DIType> TypeCache;
                                         // Cache of previously constructed 
                                         // Types.
+  std::map<tree_node *, DIVariable> VarCache;
+                                        // Cache of previously constructed 
+                                        // vars in this function.
   std::vector<DIDescriptor> RegionStack;
                                         // Stack to track declarative scopes.
   
@@ -75,6 +78,9 @@
   /// initialization is done.
   void Initialize();
 
+  /// ClearDeclCache - Clear variable debug info cache.
+  void ClearVarCache();
+
   // Accessors.
   void setLocationFile(const char *FullPath) { CurFullPath = FullPath; }
   void setLocationLine(int LineNo)           { CurLineNo = LineNo; }





More information about the llvm-commits mailing list