DebugInfo: Remove DIScope

Replace uses of `DIScope` with `MDScope*`.  There was one spot where
I've left an `MDScope*` uninitialized (where `DIScope` would have been
default-initialized to `nullptr`) -- this is intentional, since the
if/else that follows should unconditional assign it to a value.

llvm-svn: 235327
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-20 18:32:29 +00:00
parent e77a58f25d
commit 4fbe63c785
6 changed files with 49 additions and 67 deletions

View File

@ -93,13 +93,13 @@ class ExprAST;
} }
static IRBuilder<> Builder(getGlobalContext()); static IRBuilder<> Builder(getGlobalContext());
struct DebugInfo { struct DebugInfo {
DICompileUnit TheCU; MDCompileUnit *TheCU;
DIType DblTy; MDType *DblTy;
std::vector<DIScope *> LexicalBlocks; std::vector<MDScope *> LexicalBlocks;
std::map<const PrototypeAST *, DIScope> FnScopeMap; std::map<const PrototypeAST *, MDScope *> FnScopeMap;
void emitLocation(ExprAST *AST); void emitLocation(ExprAST *AST);
DIType getDoubleTy(); MDType *getDoubleTy();
} KSDbgInfo; } KSDbgInfo;
static std::string IdentifierStr; // Filled in if tok_identifier static std::string IdentifierStr; // Filled in if tok_identifier
@ -816,7 +816,7 @@ static PrototypeAST *ParseExtern() {
static DIBuilder *DBuilder; static DIBuilder *DBuilder;
DIType DebugInfo::getDoubleTy() { MDType *DebugInfo::getDoubleTy() {
if (DblTy) if (DblTy)
return DblTy; return DblTy;
@ -836,9 +836,9 @@ void DebugInfo::emitLocation(ExprAST *AST) {
DebugLoc::get(AST->getLine(), AST->getCol(), Scope)); DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
} }
static MDSubroutineType *CreateFunctionType(unsigned NumArgs, DIFile Unit) { static MDSubroutineType *CreateFunctionType(unsigned NumArgs, MDFile *Unit) {
SmallVector<Metadata *, 8> EltTys; SmallVector<Metadata *, 8> EltTys;
DIType DblTy = KSDbgInfo.getDoubleTy(); MDType *DblTy = KSDbgInfo.getDoubleTy();
// Add the result type. // Add the result type.
EltTys.push_back(DblTy); EltTys.push_back(DblTy);
@ -846,8 +846,8 @@ static MDSubroutineType *CreateFunctionType(unsigned NumArgs, DIFile Unit) {
for (unsigned i = 0, e = NumArgs; i != e; ++i) for (unsigned i = 0, e = NumArgs; i != e; ++i)
EltTys.push_back(DblTy); EltTys.push_back(DblTy);
DITypeArray EltTypeArray = DBuilder->getOrCreateTypeArray(EltTys); return DBuilder->createSubroutineType(Unit,
return DBuilder->createSubroutineType(Unit, EltTypeArray); DBuilder->getOrCreateTypeArray(EltTys));
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -1224,12 +1224,12 @@ Function *PrototypeAST::Codegen() {
AI->setName(Args[Idx]); AI->setName(Args[Idx]);
// Create a subprogram DIE for this function. // Create a subprogram DIE for this function.
DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(), MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
KSDbgInfo.TheCU->getDirectory()); KSDbgInfo.TheCU->getDirectory());
MDScope *FContext = Unit; MDScope *FContext = Unit;
unsigned LineNo = Line; unsigned LineNo = Line;
unsigned ScopeLine = Line; unsigned ScopeLine = Line;
DISubprogram SP = DBuilder->createFunction( MDSubprogram *SP = DBuilder->createFunction(
FContext, Name, StringRef(), Unit, LineNo, FContext, Name, StringRef(), Unit, LineNo,
CreateFunctionType(Args.size(), Unit), false /* internal linkage */, CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F); true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
@ -1247,15 +1247,15 @@ void PrototypeAST::CreateArgumentAllocas(Function *F) {
AllocaInst *Alloca = CreateEntryBlockAlloca(F, Args[Idx]); AllocaInst *Alloca = CreateEntryBlockAlloca(F, Args[Idx]);
// Create a debug descriptor for the variable. // Create a debug descriptor for the variable.
DIScope *Scope = KSDbgInfo.LexicalBlocks.back(); MDScope *Scope = KSDbgInfo.LexicalBlocks.back();
DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(), MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
KSDbgInfo.TheCU->getDirectory()); KSDbgInfo.TheCU->getDirectory());
DIVariable D = DBuilder->createLocalVariable(dwarf::DW_TAG_arg_variable, MDLocalVariable *D = DBuilder->createLocalVariable(
*Scope, Args[Idx], Unit, Line, dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
KSDbgInfo.getDoubleTy(), Idx); KSDbgInfo.getDoubleTy(), Idx);
DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(), DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
DebugLoc::get(Line, 0, *Scope), DebugLoc::get(Line, 0, Scope),
Builder.GetInsertBlock()); Builder.GetInsertBlock());
// Store the initial value into the alloca. // Store the initial value into the alloca.

View File

@ -52,7 +52,6 @@ class DILexicalBlock;
class DILexicalBlockFile; class DILexicalBlockFile;
class DIVariable; class DIVariable;
class DIType; class DIType;
class DIScope;
class DIObjCProperty; class DIObjCProperty;
/// \brief Maps from type identifier to the actual MDNode. /// \brief Maps from type identifier to the actual MDNode.
@ -64,7 +63,6 @@ typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
template <> struct simplify_type<DESC>; template <> struct simplify_type<DESC>;
DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange) DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange)
DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator) DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator)
DECLARE_SIMPLIFY_DESCRIPTOR(DIScope)
DECLARE_SIMPLIFY_DESCRIPTOR(DIType) DECLARE_SIMPLIFY_DESCRIPTOR(DIType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIBasicType) DECLARE_SIMPLIFY_DESCRIPTOR(DIBasicType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIDerivedType) DECLARE_SIMPLIFY_DESCRIPTOR(DIDerivedType)
@ -112,24 +110,12 @@ public:
MDEnumerator &operator*() const { return *N; } MDEnumerator &operator*() const { return *N; }
}; };
class DIScope {
MDScope *N;
public:
DIScope(const MDScope *N = nullptr) : N(const_cast<MDScope *>(N)) {}
operator MDScope *() const { return N; }
MDScope *operator->() const { return N; }
MDScope &operator*() const { return *N; }
};
class DIType { class DIType {
MDType *N; MDType *N;
public: public:
DIType(const MDType *N = nullptr) : N(const_cast<MDType *>(N)) {} DIType(const MDType *N = nullptr) : N(const_cast<MDType *>(N)) {}
operator DIScope() const { return N; }
operator MDType *() const { return N; } operator MDType *() const { return N; }
MDType *operator->() const { return N; } MDType *operator->() const { return N; }
MDType &operator*() const { return *N; } MDType &operator*() const { return *N; }
@ -194,7 +180,6 @@ class DIFile {
public: public:
DIFile(const MDFile *N = nullptr) : N(const_cast<MDFile *>(N)) {} DIFile(const MDFile *N = nullptr) : N(const_cast<MDFile *>(N)) {}
operator DIScope() const { return N; }
operator MDFile *() const { return N; } operator MDFile *() const { return N; }
MDFile *operator->() const { return N; } MDFile *operator->() const { return N; }
MDFile &operator*() const { return *N; } MDFile &operator*() const { return *N; }
@ -207,7 +192,6 @@ public:
DICompileUnit(const MDCompileUnit *N = nullptr) DICompileUnit(const MDCompileUnit *N = nullptr)
: N(const_cast<MDCompileUnit *>(N)) {} : N(const_cast<MDCompileUnit *>(N)) {}
operator DIScope() const { return N; }
operator MDCompileUnit *() const { return N; } operator MDCompileUnit *() const { return N; }
MDCompileUnit *operator->() const { return N; } MDCompileUnit *operator->() const { return N; }
MDCompileUnit &operator*() const { return *N; } MDCompileUnit &operator*() const { return *N; }
@ -220,7 +204,6 @@ public:
DISubprogram(const MDSubprogram *N = nullptr) DISubprogram(const MDSubprogram *N = nullptr)
: N(const_cast<MDSubprogram *>(N)) {} : N(const_cast<MDSubprogram *>(N)) {}
operator DIScope() const { return N; }
operator MDSubprogram *() const { return N; } operator MDSubprogram *() const { return N; }
MDSubprogram *operator->() const { return N; } MDSubprogram *operator->() const { return N; }
MDSubprogram &operator*() const { return *N; } MDSubprogram &operator*() const { return *N; }
@ -257,7 +240,6 @@ public:
DINameSpace(const MDNamespace *N = nullptr) DINameSpace(const MDNamespace *N = nullptr)
: N(const_cast<MDNamespace *>(N)) {} : N(const_cast<MDNamespace *>(N)) {}
operator DIScope() const { return N; }
operator MDNamespace *() const { return N; } operator MDNamespace *() const { return N; }
MDNamespace *operator->() const { return N; } MDNamespace *operator->() const { return N; }
MDNamespace &operator*() const { return *N; } MDNamespace &operator*() const { return *N; }
@ -366,7 +348,6 @@ public:
template <> struct simplify_type<DESC> : simplify_type<const DESC> {}; template <> struct simplify_type<DESC> : simplify_type<const DESC> {};
SIMPLIFY_DESCRIPTOR(DISubrange) SIMPLIFY_DESCRIPTOR(DISubrange)
SIMPLIFY_DESCRIPTOR(DIEnumerator) SIMPLIFY_DESCRIPTOR(DIEnumerator)
SIMPLIFY_DESCRIPTOR(DIScope)
SIMPLIFY_DESCRIPTOR(DIType) SIMPLIFY_DESCRIPTOR(DIType)
SIMPLIFY_DESCRIPTOR(DIBasicType) SIMPLIFY_DESCRIPTOR(DIBasicType)
SIMPLIFY_DESCRIPTOR(DIDerivedType) SIMPLIFY_DESCRIPTOR(DIDerivedType)

View File

@ -104,8 +104,8 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable GV) {
assert(GV); assert(GV);
DIScope GVContext = GV->getScope(); auto *GVContext = GV->getScope();
DIType GTy = DD->resolve(GV->getType()); auto *GTy = DD->resolve(GV->getType());
// Construct the context before querying for the existence of the DIE in // Construct the context before querying for the existence of the DIE in
// case such construction creates the DIE. // case such construction creates the DIE.
@ -113,8 +113,7 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable GV) {
// Add to map. // Add to map.
DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV); DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
DIScope DeclContext; MDScope *DeclContext;
if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) { if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
DeclContext = resolve(SDMDecl->getScope()); DeclContext = resolve(SDMDecl->getScope());
assert(SDMDecl->isStaticMember() && "Expected static member decl"); assert(SDMDecl->isStaticMember() && "Expected static member decl");
@ -306,7 +305,7 @@ void DwarfCompileUnit::constructScopeDIE(
if (!Scope || !Scope->getScopeNode()) if (!Scope || !Scope->getScopeNode())
return; return;
DIScope DS(Scope->getScopeNode()); auto *DS = Scope->getScopeNode();
assert((Scope->getInlinedAt() || !isa<MDSubprogram>(DS)) && assert((Scope->getInlinedAt() || !isa<MDSubprogram>(DS)) &&
"Only handle inlined subprograms here, use " "Only handle inlined subprograms here, use "
@ -419,8 +418,8 @@ void DwarfCompileUnit::attachRangesOrLowHighPC(
std::unique_ptr<DIE> std::unique_ptr<DIE>
DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) { DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) {
assert(Scope->getScopeNode()); assert(Scope->getScopeNode());
DIScope DS(Scope->getScopeNode()); auto *DS = Scope->getScopeNode();
DISubprogram InlinedSP = getDISubprogram(DS); auto *InlinedSP = getDISubprogram(DS);
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
// was inlined from another compile unit. // was inlined from another compile unit.
DIE *OriginDIE = DU->getAbstractSPDies()[InlinedSP]; DIE *OriginDIE = DU->getAbstractSPDies()[InlinedSP];
@ -708,7 +707,7 @@ void DwarfCompileUnit::emitHeader(bool UseOffsets) {
/// addGlobalName - Add a new global name to the compile unit. /// addGlobalName - Add a new global name to the compile unit.
void DwarfCompileUnit::addGlobalName(StringRef Name, DIE &Die, void DwarfCompileUnit::addGlobalName(StringRef Name, DIE &Die,
DIScope Context) { const MDScope *Context) {
if (includeMinimalInlineScopes()) if (includeMinimalInlineScopes())
return; return;
std::string FullName = getParentContextString(Context) + Name.str(); std::string FullName = getParentContextString(Context) + Name.str();
@ -716,8 +715,8 @@ void DwarfCompileUnit::addGlobalName(StringRef Name, DIE &Die,
} }
/// Add a new global type to the unit. /// Add a new global type to the unit.
void DwarfCompileUnit::addGlobalType(DIType Ty, const DIE &Die, void DwarfCompileUnit::addGlobalType(const MDType *Ty, const DIE &Die,
DIScope Context) { const MDScope *Context) {
if (includeMinimalInlineScopes()) if (includeMinimalInlineScopes())
return; return;
std::string FullName = getParentContextString(Context) + Ty->getName().str(); std::string FullName = getParentContextString(Context) + Ty->getName().str();
@ -809,7 +808,7 @@ void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form,
void DwarfCompileUnit::applySubprogramAttributesToDefinition(DISubprogram SP, void DwarfCompileUnit::applySubprogramAttributesToDefinition(DISubprogram SP,
DIE &SPDie) { DIE &SPDie) {
auto *SPDecl = SP->getDeclaration(); auto *SPDecl = SP->getDeclaration();
DIScope Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope()); auto *Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope());
applySubprogramAttributes(SP, SPDie, includeMinimalInlineScopes()); applySubprogramAttributes(SP, SPDie, includeMinimalInlineScopes());
addGlobalName(SP->getName(), SPDie, Context); addGlobalName(SP->getName(), SPDie, Context);
} }

View File

@ -183,10 +183,11 @@ public:
} }
/// Add a new global name to the compile unit. /// Add a new global name to the compile unit.
void addGlobalName(StringRef Name, DIE &Die, DIScope Context) override; void addGlobalName(StringRef Name, DIE &Die, const MDScope *Context) override;
/// Add a new global type to the compile unit. /// Add a new global type to the compile unit.
void addGlobalType(DIType Ty, const DIE &Die, DIScope Context) override; void addGlobalType(const MDType *Ty, const DIE &Die,
const MDScope *Context) override;
const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; } const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; } const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }

View File

@ -772,7 +772,7 @@ void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) {
} }
/// getOrCreateContextDIE - Get context owner's DIE. /// getOrCreateContextDIE - Get context owner's DIE.
DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) { DIE *DwarfUnit::getOrCreateContextDIE(const MDScope *Context) {
if (!Context || isa<MDFile>(Context)) if (!Context || isa<MDFile>(Context))
return &getUnitDie(); return &getUnitDie();
if (auto *T = dyn_cast<MDType>(Context)) if (auto *T = dyn_cast<MDType>(Context))
@ -785,7 +785,7 @@ DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) {
} }
DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) { DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
DIScope Context = resolve(Ty->getScope()); auto *Context = resolve(Ty->getScope());
DIE *ContextDIE = getOrCreateContextDIE(Context); DIE *ContextDIE = getOrCreateContextDIE(Context);
if (DIE *TyDIE = getDIE(Ty)) if (DIE *TyDIE = getDIE(Ty))
@ -817,7 +817,7 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
// Construct the context before querying for the existence of the DIE in case // Construct the context before querying for the existence of the DIE in case
// such construction creates the DIE. // such construction creates the DIE.
DIScope Context = resolve(Ty->getScope()); auto *Context = resolve(Ty->getScope());
DIE *ContextDIE = getOrCreateContextDIE(Context); DIE *ContextDIE = getOrCreateContextDIE(Context);
assert(ContextDIE); assert(ContextDIE);
@ -846,8 +846,8 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
return &TyDIE; return &TyDIE;
} }
void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty, void DwarfUnit::updateAcceleratorTables(const MDScope *Context,
const DIE &TyDIE) { const MDType *Ty, const DIE &TyDIE) {
if (!Ty->getName().empty() && !Ty->isForwardDecl()) { if (!Ty->getName().empty() && !Ty->isForwardDecl()) {
bool IsImplementation = 0; bool IsImplementation = 0;
if (auto *CT = dyn_cast<MDCompositeTypeBase>(Ty)) { if (auto *CT = dyn_cast<MDCompositeTypeBase>(Ty)) {
@ -890,7 +890,7 @@ void DwarfUnit::addType(DIE &Entity, DIType Ty, dwarf::Attribute Attribute) {
/// it as a string. This is done at the metadata level because DIEs may /// it as a string. This is done at the metadata level because DIEs may
/// not currently have been added to the parent context and walking the /// not currently have been added to the parent context and walking the
/// DIEs looking for names is more expensive than walking the metadata. /// DIEs looking for names is more expensive than walking the metadata.
std::string DwarfUnit::getParentContextString(DIScope Context) const { std::string DwarfUnit::getParentContextString(const MDScope *Context) const {
if (!Context) if (!Context)
return ""; return "";
@ -899,7 +899,7 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const {
return ""; return "";
std::string CS; std::string CS;
SmallVector<DIScope, 1> Parents; SmallVector<const MDScope *, 1> Parents;
while (!isa<MDCompileUnit>(Context)) { while (!isa<MDCompileUnit>(Context)) {
Parents.push_back(Context); Parents.push_back(Context);
if (Context->getScope()) if (Context->getScope())
@ -912,9 +912,7 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const {
// Reverse iterate over our list to go from the outermost construct to the // Reverse iterate over our list to go from the outermost construct to the
// innermost. // innermost.
for (SmallVectorImpl<DIScope>::reverse_iterator I = Parents.rbegin(), for (auto I = Parents.rbegin(), E = Parents.rend(); I != E; ++I) {
E = Parents.rend();
I != E; ++I) {
const MDScope *Ctx = *I; const MDScope *Ctx = *I;
StringRef Name = Ctx->getName(); StringRef Name = Ctx->getName();
if (Name.empty() && isa<MDNamespace>(Ctx)) if (Name.empty() && isa<MDNamespace>(Ctx))

View File

@ -153,13 +153,15 @@ public:
/// getParentContextString - Get a string containing the language specific /// getParentContextString - Get a string containing the language specific
/// context for a global name. /// context for a global name.
std::string getParentContextString(DIScope Context) const; std::string getParentContextString(const MDScope *Context) const;
/// Add a new global name to the compile unit. /// Add a new global name to the compile unit.
virtual void addGlobalName(StringRef Name, DIE &Die, DIScope Context) {} virtual void addGlobalName(StringRef Name, DIE &Die, const MDScope *Context) {
}
/// Add a new global type to the compile unit. /// Add a new global type to the compile unit.
virtual void addGlobalType(DIType Ty, const DIE &Die, DIScope Context) {} virtual void addGlobalType(const MDType *Ty, const DIE &Die,
const MDScope *Context) {}
/// addAccelNamespace - Add a new name to the namespace accelerator table. /// addAccelNamespace - Add a new name to the namespace accelerator table.
void addAccelNamespace(StringRef Name, const DIE &Die); void addAccelNamespace(StringRef Name, const DIE &Die);
@ -302,7 +304,7 @@ public:
DIE *createTypeDIE(DICompositeType Ty); DIE *createTypeDIE(DICompositeType Ty);
/// getOrCreateContextDIE - Get context owner's DIE. /// getOrCreateContextDIE - Get context owner's DIE.
DIE *getOrCreateContextDIE(DIScope Context); DIE *getOrCreateContextDIE(const MDScope *Context);
/// constructContainingTypeDIEs - Construct DIEs for types that contain /// constructContainingTypeDIEs - Construct DIEs for types that contain
/// vtables. /// vtables.
@ -402,7 +404,8 @@ private:
/// If this is a named finished type then include it in the list of types for /// If this is a named finished type then include it in the list of types for
/// the accelerator tables. /// the accelerator tables.
void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE &TyDIE); void updateAcceleratorTables(const MDScope *Context, const MDType *Ty,
const DIE &TyDIE);
virtual bool isDwoUnit() const = 0; virtual bool isDwoUnit() const = 0;
}; };