From 9c1aa1c021755e9cea1ddb23398e6c3d8e70f03c Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 16 Apr 2015 01:37:00 +0000 Subject: [PATCH] DebugInfo: Gut DIScope, DIEnumerator and DISubrange The only class the still has API left is `DIDescriptor` itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235067 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 80 ++++++------------- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 6 +- lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 18 ++--- .../AsmPrinter/WinCodeViewLineTables.cpp | 6 +- lib/CodeGen/LiveDebugVariables.cpp | 4 +- .../SelectionDAG/SelectionDAGDumper.cpp | 4 +- lib/IR/DIBuilder.cpp | 25 +++--- lib/IR/DebugInfo.cpp | 2 - lib/IR/DebugLoc.cpp | 4 +- lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 6 +- lib/Transforms/Utils/AddDiscriminators.cpp | 4 +- 11 files changed, 61 insertions(+), 98 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 34855acfb21..2d84f0f0ad6 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -137,41 +137,27 @@ DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity) typedef DebugNodeArray DIArray; typedef MDTypeRefArray DITypeArray; -/// \brief This is used to represent ranges, for array bounds. -class DISubrange : public DIDescriptor { -public: - DISubrange() = default; - DISubrange(const MDSubrange *N) : DIDescriptor(N) {} +class DISubrange { + MDSubrange *N; - MDSubrange *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDSubrange *() const { return get(); } - MDSubrange *operator->() const { return get(); } - MDSubrange &operator*() const { return *get(); } +public: + DISubrange(const MDSubrange *N = nullptr) : N(const_cast(N)) {} - int64_t getLo() const { return get()->getLowerBound(); } - int64_t getCount() const { return get()->getCount(); } + operator MDSubrange *() const { return N; } + MDSubrange *operator->() const { return N; } + MDSubrange &operator*() const { return *N; } }; -/// \brief A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). -/// -/// FIXME: it seems strange that this doesn't have either a reference to the -/// type/precision or a file/line pair for location info. -class DIEnumerator : public DIDescriptor { -public: - DIEnumerator() = default; - DIEnumerator(const MDEnumerator *N) : DIDescriptor(N) {} +class DIEnumerator { + MDEnumerator *N; - MDEnumerator *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDEnumerator *() const { return get(); } - MDEnumerator *operator->() const { return get(); } - MDEnumerator &operator*() const { return *get(); } +public: + DIEnumerator(const MDEnumerator *N = nullptr) + : N(const_cast(N)) {} - StringRef getName() const { return get()->getName(); } - int64_t getEnumValue() const { return get()->getValue(); } + operator MDEnumerator *() const { return N; } + MDEnumerator *operator->() const { return N; } + MDEnumerator &operator*() const { return *N; } }; template class DIRef; @@ -179,34 +165,16 @@ typedef DIRef DIDescriptorRef; typedef DIRef DIScopeRef; typedef DIRef DITypeRef; -/// \brief A base class for various scopes. -/// -/// Although, implementation-wise, DIScope is the parent class of most -/// other DIxxx classes, including DIType and its descendants, most of -/// DIScope's descendants are not a substitutable subtype of -/// DIScope. The DIDescriptor::isScope() method only is true for -/// DIScopes that are scopes in the strict lexical scope sense -/// (DICompileUnit, DISubprogram, etc.), but not for, e.g., a DIType. -class DIScope : public DIDescriptor { -public: - DIScope() = default; - DIScope(const MDScope *N) : DIDescriptor(N) {} +class DIScope { + MDScope *N; - MDScope *get() const { return cast_or_null(DIDescriptor::get()); } - operator MDScope *() const { return get(); } - MDScope *operator->() const { return get(); } - MDScope &operator*() const { return *get(); } - - inline DIScopeRef getContext() const; - StringRef getName() const { return get()->getName(); } - StringRef getFilename() const { return get()->getFilename(); } - StringRef getDirectory() const { return get()->getDirectory(); } +public: + DIScope(const MDScope *N = nullptr) : N(const_cast(N)) {} - /// \brief Generate a reference to this DIScope. - /// - /// Uses the type identifier instead of the actual MDNode if possible, to - /// help type uniquing. - DIScopeRef getRef() const; + operator DIDescriptor() const { return N; } + operator MDScope *() const { return N; } + MDScope *operator->() const { return N; } + MDScope &operator*() const { return *N; } }; /// \brief Represents reference to a DIDescriptor. @@ -235,8 +203,6 @@ template <> DIScope DIRef::resolve(const DITypeIdentifierMap &Map) const; template <> DIType DIRef::resolve(const DITypeIdentifierMap &Map) const; -DIScopeRef DIScope::getContext() const { return get()->getScope(); } - class DIType { MDType *N; diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 87fb73284ee..b59c5e3e049 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1251,9 +1251,9 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S, StringRef Dir; unsigned Src = 1; unsigned Discriminator = 0; - if (DIScope Scope = cast_or_null(S)) { - Fn = Scope.getFilename(); - Dir = Scope.getDirectory(); + if (auto *Scope = cast_or_null(S)) { + Fn = Scope->getFilename(); + Dir = Scope->getDirectory(); if (auto *LBF = dyn_cast(Scope)) Discriminator = LBF->getDiscriminator(); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index aa4b7475eea..46f3eb3201d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -903,8 +903,8 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const { SmallVector Parents; while (!isa(Context)) { Parents.push_back(Context); - if (Context.getContext()) - Context = resolve(Context.getContext()); + if (Context->getScope()) + Context = resolve(Context->getScope()); else // Structure, etc types will have a NULL context if they're at the top // level. @@ -916,8 +916,8 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const { for (SmallVectorImpl::reverse_iterator I = Parents.rbegin(), E = Parents.rend(); I != E; ++I) { - DIScope Ctx = *I; - StringRef Name = Ctx.getName(); + const MDScope *Ctx = *I; + StringRef Name = Ctx->getName(); if (Name.empty() && isa(Ctx)) Name = "(anonymous namespace)"; if (!Name.empty()) { @@ -1364,9 +1364,9 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) { // C/C++. The Count value is the number of elements. Values are 64 bit. If // Count == -1 then the array is unbounded and we do not emit // DW_AT_lower_bound and DW_AT_count attributes. - int64_t LowerBound = SR.getLo(); + int64_t LowerBound = SR->getLowerBound(); int64_t DefaultLowerBound = getDefaultLowerBound(); - int64_t Count = SR.getCount(); + int64_t Count = SR->getCount(); if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound) addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound); @@ -1417,12 +1417,12 @@ void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) { // Add enumerators to enumeration type. for (unsigned i = 0, N = Elements.size(); i < N; ++i) { - DIEnumerator Enum = dyn_cast_or_null(Elements[i]); + auto *Enum = dyn_cast_or_null(Elements[i]); if (Enum) { DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer); - StringRef Name = Enum.getName(); + StringRef Name = Enum->getName(); addString(Enumerator, dwarf::DW_AT_name, Name); - int64_t Value = Enum.getEnumValue(); + int64_t Value = Enum->getValue(); addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value); } diff --git a/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp b/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp index d859ee1a083..276e7dfb2eb 100644 --- a/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp +++ b/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp @@ -24,9 +24,9 @@ StringRef WinCodeViewLineTables::getFullFilepath(const MDNode *S) { isa(S)) && "Unexpected scope info"); - DIScope Scope = cast(S); - StringRef Dir = Scope.getDirectory(), - Filename = Scope.getFilename(); + auto *Scope = cast(S); + StringRef Dir = Scope->getDirectory(), + Filename = Scope->getFilename(); char *&Result = DirAndFilenameToFilepathMap[std::make_pair(Dir, Filename)]; if (Result) return Result; diff --git a/lib/CodeGen/LiveDebugVariables.cpp b/lib/CodeGen/LiveDebugVariables.cpp index a07a7c9e567..52532b1495a 100644 --- a/lib/CodeGen/LiveDebugVariables.cpp +++ b/lib/CodeGen/LiveDebugVariables.cpp @@ -362,9 +362,9 @@ static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, if (!DL) return; - DIScope Scope = cast(DL.getScope()); + auto *Scope = cast(DL.getScope()); // Omit the directory, because it's likely to be long and uninteresting. - CommentOS << Scope.getFilename(); + CommentOS << Scope->getFilename(); CommentOS << ':' << DL.getLine(); if (DL.getCol() != 0) CommentOS << ':' << DL.getCol(); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp index e6c34e0116b..636c0a741a7 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -527,8 +527,8 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { if (!L) return; - if (DIScope Scope = L->getScope()) - OS << Scope.getFilename(); + if (auto *Scope = L->getScope()) + OS << Scope->getFilename(); else OS << ""; OS << ':' << L->getLine(); diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 067a7ee820f..893f9f29548 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -348,8 +348,7 @@ DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber, DITemplateTypeParameter DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name, DIType Ty) { - assert((!Context || isa(Context.get())) && - "Expected compile unit"); + assert((!Context || isa(Context)) && "Expected compile unit"); return MDTemplateTypeParameter::get(VMContext, Name, MDTypeRef::get(Ty)); } @@ -357,8 +356,7 @@ static DITemplateValueParameter createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, DIDescriptor Context, StringRef Name, DIType Ty, Metadata *MD) { - assert((!Context || isa(Context.get())) && - "Expected compile unit"); + assert((!Context || isa(Context)) && "Expected compile unit"); return MDTemplateValueParameter::get(VMContext, Tag, Name, MDTypeRef::get(Ty), MD); } @@ -590,10 +588,10 @@ DIGlobalVariable DIBuilder::createGlobalVariable( MDNode *Decl) { checkGlobalVariableScope(Context); - auto *N = MDGlobalVariable::get( - VMContext, cast_or_null(Context.get()), Name, LinkageName, F, - LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true, Val, - cast_or_null(Decl)); + auto *N = MDGlobalVariable::get(VMContext, cast_or_null(Context), + Name, LinkageName, F, LineNumber, + MDTypeRef::get(Ty), isLocalToUnit, true, Val, + cast_or_null(Decl)); AllGVs.push_back(N); return N; } @@ -605,9 +603,10 @@ DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl( checkGlobalVariableScope(Context); return MDGlobalVariable::getTemporary( - VMContext, cast_or_null(Context.get()), Name, LinkageName, - F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val, - cast_or_null(Decl)).release(); + VMContext, cast_or_null(Context), Name, LinkageName, F, + LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val, + cast_or_null(Decl)) + .release(); } DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, @@ -622,8 +621,8 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, DIScope Context = getNonCompileUnitScope(Scope); auto *Node = MDLocalVariable::get( - VMContext, Tag, cast_or_null(Context.get()), Name, File, - LineNo, MDTypeRef::get(Ty), ArgNo, Flags); + VMContext, Tag, cast_or_null(Context), Name, File, LineNo, + MDTypeRef::get(Ty), ArgNo, Flags); if (AlwaysPreserve) { // The optimizer may remove local variable. If there is an interest // to preserve variable info in such situation then stash it in a diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 87e2ce06594..d3388cbabef 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -33,8 +33,6 @@ using namespace llvm; using namespace llvm::dwarf; -DIScopeRef DIScope::getRef() const { return MDScopeRef::get(get()); } - DISubprogram llvm::getDISubprogram(const MDNode *Scope) { if (auto *LocalScope = dyn_cast_or_null(Scope)) return LocalScope->getSubprogram(); diff --git a/lib/IR/DebugLoc.cpp b/lib/IR/DebugLoc.cpp index 984ee248836..d9229483d05 100644 --- a/lib/IR/DebugLoc.cpp +++ b/lib/IR/DebugLoc.cpp @@ -86,8 +86,8 @@ void DebugLoc::print(raw_ostream &OS) const { return; // Print source line info. - DIScope Scope = cast(getScope()); - OS << Scope.getFilename(); + auto *Scope = cast(getScope()); + OS << Scope->getFilename(); OS << ':' << getLine(); if (getCol() != 0) OS << ':' << getCol(); diff --git a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index 20f5b434bbf..9a719644c56 100644 --- a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -129,12 +129,12 @@ void NVPTXAsmPrinter::emitLineNumberAsDotLoc(const MachineInstr &MI) { if (!curLoc) return; - DIScope Scope = cast_or_null(curLoc.getScope()); + auto *Scope = cast_or_null(curLoc.getScope()); if (!Scope) return; - StringRef fileName(Scope.getFilename()); - StringRef dirName(Scope.getDirectory()); + StringRef fileName(Scope->getFilename()); + StringRef dirName(Scope->getDirectory()); SmallString<128> FullPathName = dirName; if (!dirName.empty() && !sys::path::is_absolute(fileName)) { sys::path::append(FullPathName, fileName); diff --git a/lib/Transforms/Utils/AddDiscriminators.cpp b/lib/Transforms/Utils/AddDiscriminators.cpp index 526dc34d65b..c1cd39abea7 100644 --- a/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/lib/Transforms/Utils/AddDiscriminators.cpp @@ -193,8 +193,8 @@ bool AddDiscriminators::runOnFunction(Function &F) { // Create a new lexical scope and compute a new discriminator // number for it. StringRef Filename = FirstDIL->getFilename(); - DIScope Scope = FirstDIL->getScope(); - DIFile File = Builder.createFile(Filename, Scope.getDirectory()); + auto *Scope = FirstDIL->getScope(); + DIFile File = Builder.createFile(Filename, Scope->getDirectory()); // FIXME: Calculate the discriminator here, based on local information, // and delete MDLocation::computeNewDiscriminator(). The current -- 2.34.1