Derive DIType from DIScope. This simplifies getContext() where for members the context is a type. This also eliminates need of CompileUnitMaps maintained by dwarf writer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97990 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2010-03-08 22:02:50 +00:00
parent f17f5ebbdc
commit 77bf295dbb
4 changed files with 31 additions and 47 deletions

View File

@@ -172,7 +172,7 @@ namespace llvm {
/// DIType - This is a wrapper for a type. /// DIType - This is a wrapper for a type.
/// FIXME: Types should be factored much better so that CV qualifiers and /// FIXME: Types should be factored much better so that CV qualifiers and
/// others do not require a huge and empty descriptor full of zeros. /// others do not require a huge and empty descriptor full of zeros.
class DIType : public DIDescriptor { class DIType : public DIScope {
public: public:
enum { enum {
FlagPrivate = 1 << 0, FlagPrivate = 1 << 0,
@@ -188,7 +188,7 @@ namespace llvm {
protected: protected:
// This ctor is used when the Tag has already been validated by a derived // This ctor is used when the Tag has already been validated by a derived
// ctor. // ctor.
DIType(MDNode *N, bool, bool) : DIDescriptor(N) {} DIType(MDNode *N, bool, bool) : DIScope(N) {}
public: public:
@@ -199,7 +199,7 @@ namespace llvm {
explicit DIType() {} explicit DIType() {}
virtual ~DIType() {} virtual ~DIType() {}
DIDescriptor getContext() const { return getDescriptorField(1); } DIScope getContext() const { return getFieldAs<DIScope>(1); }
StringRef getName() const { return getStringField(2); } StringRef getName() const { return getStringField(2); }
DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
unsigned getLineNumber() const { return getUnsignedField(4); } unsigned getLineNumber() const { return getUnsignedField(4); }
@@ -234,6 +234,8 @@ namespace llvm {
bool isValid() const { bool isValid() const {
return DbgNode && (isBasicType() || isDerivedType() || isCompositeType()); return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
} }
StringRef getFilename() const { return getCompileUnit().getFilename();}
StringRef getDirectory() const { return getCompileUnit().getDirectory();}
/// dump - print type. /// dump - print type.
void dump() const; void dump() const;
}; };
@@ -305,7 +307,7 @@ namespace llvm {
public: public:
virtual ~DIGlobal() {} virtual ~DIGlobal() {}
DIDescriptor getContext() const { return getDescriptorField(2); } DIScope getContext() const { return getFieldAs<DIScope>(2); }
StringRef getName() const { return getStringField(3); } StringRef getName() const { return getStringField(3); }
StringRef getDisplayName() const { return getStringField(4); } StringRef getDisplayName() const { return getStringField(4); }
StringRef getLinkageName() const { return getStringField(5); } StringRef getLinkageName() const { return getStringField(5); }
@@ -327,7 +329,7 @@ namespace llvm {
public: public:
explicit DISubprogram(MDNode *N = 0) : DIScope(N) {} explicit DISubprogram(MDNode *N = 0) : DIScope(N) {}
DIDescriptor getContext() const { return getDescriptorField(2); } DIScope getContext() const { return getFieldAs<DIScope>(2); }
StringRef getName() const { return getStringField(3); } StringRef getName() const { return getStringField(3); }
StringRef getDisplayName() const { return getStringField(4); } StringRef getDisplayName() const { return getStringField(4); }
StringRef getLinkageName() const { return getStringField(5); } StringRef getLinkageName() const { return getStringField(5); }
@@ -396,7 +398,7 @@ namespace llvm {
explicit DIVariable(MDNode *N = 0) explicit DIVariable(MDNode *N = 0)
: DIDescriptor(N) {} : DIDescriptor(N) {}
DIDescriptor getContext() const { return getDescriptorField(1); } DIScope getContext() const { return getFieldAs<DIScope>(1); }
StringRef getName() const { return getStringField(2); } StringRef getName() const { return getStringField(2); }
DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
unsigned getLineNumber() const { return getUnsignedField(4); } unsigned getLineNumber() const { return getUnsignedField(4); }

View File

@@ -243,7 +243,7 @@ bool DIDescriptor::isEnumerator() const {
// Simple Descriptor Constructors and other Methods // Simple Descriptor Constructors and other Methods
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
DIType::DIType(MDNode *N) : DIDescriptor(N) { DIType::DIType(MDNode *N) : DIScope(N) {
if (!N) return; if (!N) return;
if (!isBasicType() && !isDerivedType() && !isCompositeType()) { if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
DbgNode = 0; DbgNode = 0;
@@ -412,6 +412,8 @@ bool DISubprogram::describes(const Function *F) {
} }
StringRef DIScope::getFilename() const { StringRef DIScope::getFilename() const {
if (!DbgNode)
return StringRef();
if (isLexicalBlock()) if (isLexicalBlock())
return DILexicalBlock(DbgNode).getFilename(); return DILexicalBlock(DbgNode).getFilename();
if (isSubprogram()) if (isSubprogram())
@@ -420,11 +422,15 @@ StringRef DIScope::getFilename() const {
return DICompileUnit(DbgNode).getFilename(); return DICompileUnit(DbgNode).getFilename();
if (isNameSpace()) if (isNameSpace())
return DINameSpace(DbgNode).getFilename(); return DINameSpace(DbgNode).getFilename();
if (isType())
return DIType(DbgNode).getFilename();
assert(0 && "Invalid DIScope!"); assert(0 && "Invalid DIScope!");
return StringRef(); return StringRef();
} }
StringRef DIScope::getDirectory() const { StringRef DIScope::getDirectory() const {
if (!DbgNode)
return StringRef();
if (isLexicalBlock()) if (isLexicalBlock())
return DILexicalBlock(DbgNode).getDirectory(); return DILexicalBlock(DbgNode).getDirectory();
if (isSubprogram()) if (isSubprogram())
@@ -433,6 +439,8 @@ StringRef DIScope::getDirectory() const {
return DICompileUnit(DbgNode).getDirectory(); return DICompileUnit(DbgNode).getDirectory();
if (isNameSpace()) if (isNameSpace())
return DINameSpace(DbgNode).getDirectory(); return DINameSpace(DbgNode).getDirectory();
if (isType())
return DIType(DbgNode).getDirectory();
assert(0 && "Invalid DIScope!"); assert(0 && "Invalid DIScope!");
return StringRef(); return StringRef();
} }

View File

@@ -417,7 +417,8 @@ void DwarfDebug::addSourceLine(DIE *Die, const DIVariable *V) {
return; return;
unsigned Line = V->getLineNumber(); unsigned Line = V->getLineNumber();
unsigned FileID = findCompileUnit(V->getCompileUnit())->getID(); unsigned FileID = GetOrCreateSourceID(V->getContext().getDirectory(),
V->getContext().getFilename());
assert(FileID && "Invalid file id"); assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@@ -431,7 +432,8 @@ void DwarfDebug::addSourceLine(DIE *Die, const DIGlobal *G) {
return; return;
unsigned Line = G->getLineNumber(); unsigned Line = G->getLineNumber();
unsigned FileID = findCompileUnit(G->getCompileUnit())->getID(); unsigned FileID = GetOrCreateSourceID(G->getContext().getDirectory(),
G->getContext().getFilename());
assert(FileID && "Invalid file id"); assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@@ -447,9 +449,11 @@ void DwarfDebug::addSourceLine(DIE *Die, const DISubprogram *SP) {
if (SP->getLineNumber() == 0) if (SP->getLineNumber() == 0)
return; return;
unsigned Line = SP->getLineNumber(); unsigned Line = SP->getLineNumber();
unsigned FileID = findCompileUnit(SP->getCompileUnit())->getID(); if (!SP->getContext().Verify())
return;
unsigned FileID = GetOrCreateSourceID(SP->getContext().getDirectory(),
SP->getContext().getFilename());
assert(FileID && "Invalid file id"); assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@@ -464,7 +468,10 @@ void DwarfDebug::addSourceLine(DIE *Die, const DIType *Ty) {
return; return;
unsigned Line = Ty->getLineNumber(); unsigned Line = Ty->getLineNumber();
unsigned FileID = findCompileUnit(CU)->getID(); if (!Ty->getContext().Verify())
return;
unsigned FileID = GetOrCreateSourceID(Ty->getContext().getDirectory(),
Ty->getContext().getFilename());
assert(FileID && "Invalid file id"); assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@@ -1233,16 +1240,6 @@ DIE *DwarfDebug::createSubprogramDIE(const DISubprogram &SP, bool MakeDecl) {
return SPDie; return SPDie;
} }
/// findCompileUnit - Get the compile unit for the given descriptor.
///
CompileUnit *DwarfDebug::findCompileUnit(DICompileUnit Unit) {
DenseMap<Value *, CompileUnit *>::const_iterator I =
CompileUnitMap.find(Unit.getNode());
if (I == CompileUnitMap.end())
return constructCompileUnit(Unit.getNode());
return I->second;
}
/// getUpdatedDbgScope - Find or create DbgScope assicated with the instruction. /// getUpdatedDbgScope - Find or create DbgScope assicated with the instruction.
/// Initialize scope and update scope hierarchy. /// Initialize scope and update scope hierarchy.
DbgScope *DwarfDebug::getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, DbgScope *DwarfDebug::getUpdatedDbgScope(MDNode *N, const MachineInstr *MI,
@@ -1676,8 +1673,6 @@ CompileUnit *DwarfDebug::constructCompileUnit(MDNode *N) {
ModuleCU = Unit; ModuleCU = Unit;
} }
CompileUnitMap[DIUnit.getNode()] = Unit;
CompileUnits.push_back(Unit);
return Unit; return Unit;
} }
@@ -1783,17 +1778,8 @@ void DwarfDebug::beginModule(Module *M, MachineModuleInfo *mmi) {
E = DbgFinder.compile_unit_end(); I != E; ++I) E = DbgFinder.compile_unit_end(); I != E; ++I)
constructCompileUnit(*I); constructCompileUnit(*I);
if (CompileUnits.empty()) {
if (TimePassesIsEnabled)
DebugTimer->stopTimer();
return;
}
// If main compile unit for this module is not seen than randomly
// select first compile unit.
if (!ModuleCU) if (!ModuleCU)
ModuleCU = CompileUnits[0]; return;
// Create DIEs for each subprogram. // Create DIEs for each subprogram.
for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(), for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),

View File

@@ -62,14 +62,6 @@ class DwarfDebug : public DwarfPrinter {
// Attributes used to construct specific Dwarf sections. // Attributes used to construct specific Dwarf sections.
// //
/// CompileUnitMap - A map of global variables representing compile units to
/// compile units.
DenseMap<Value *, CompileUnit *> CompileUnitMap;
/// CompileUnits - All the compile units in this module.
///
SmallVector<CompileUnit *, 8> CompileUnits;
/// ModuleCU - All DIEs are inserted in ModuleCU. /// ModuleCU - All DIEs are inserted in ModuleCU.
CompileUnit *ModuleCU; CompileUnit *ModuleCU;
@@ -357,10 +349,6 @@ class DwarfDebug : public DwarfPrinter {
/// createSubprogramDIE - Create new DIE using SP. /// createSubprogramDIE - Create new DIE using SP.
DIE *createSubprogramDIE(const DISubprogram &SP, bool MakeDecl = false); DIE *createSubprogramDIE(const DISubprogram &SP, bool MakeDecl = false);
/// findCompileUnit - Get the compile unit for the given descriptor.
///
CompileUnit *findCompileUnit(DICompileUnit Unit);
/// getUpdatedDbgScope - Find or create DbgScope assicated with /// getUpdatedDbgScope - Find or create DbgScope assicated with
/// the instruction. Initialize scope and update scope hierarchy. /// the instruction. Initialize scope and update scope hierarchy.
DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt); DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt);