[llvm-commits] [llvm-gcc-4.2] r66861 - in /llvm-gcc-4.2/trunk/gcc: llvm-convert.cpp llvm-debug.cpp llvm-debug.h
Devang Patel
dpatel at apple.com
Thu Mar 12 18:06:42 PDT 2009
Author: dpatel
Date: Thu Mar 12 20:06:42 2009
New Revision: 66861
URL: http://llvm.org/viewvc/llvm-project?rev=66861&view=rev
Log:
Keep track of lexical scopes while emitting debug info.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
llvm-gcc-4.2/trunk/gcc/llvm-debug.h
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=66861&r1=66860&r2=66861&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Thu Mar 12 20:06:42 2009
@@ -714,6 +714,9 @@
}
Function *TreeToLLVM::EmitFunction() {
+ if (TheDebugInfo)
+ TheDebugInfo->ClearVarCache();
+
// Set up parameters and prepare for return, for the function.
StartFunctionBody();
@@ -721,12 +724,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.
@@ -1540,17 +1574,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());
- }
- }
}
//===----------------------------------------------------------------------===//
@@ -5709,6 +5732,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,
@@ -5786,6 +5810,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/trunk/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=66861&r1=66860&r2=66861&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Thu Mar 12 20:06:42 2009
@@ -294,6 +294,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.
@@ -302,6 +307,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);
}
@@ -843,6 +850,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/trunk/gcc/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.h?rev=66861&r1=66860&r2=66861&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.h Thu Mar 12 20:06:42 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