From: Duncan P. N. Exon Smith Date: Tue, 14 Apr 2015 03:01:27 +0000 (+0000) Subject: DebugInfo: Gut DINamespace and DITemplate*Parameter X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=41ed49389bc67e1855aeb6a026acb4992424a245;p=oota-llvm.git DebugInfo: Gut DINamespace and DITemplate*Parameter Continue gutting `DIDescriptor` subclasses, turning them into as-bare-as-possible pointer wrappers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234843 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index ca3b0d173db..2108830d2a1 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -519,58 +519,42 @@ public: unsigned getDiscriminator() const { return get()->getDiscriminator(); } }; -/// \brief A wrapper for a C++ style name space. -class DINameSpace : public DIScope { -public: - DINameSpace() = default; - DINameSpace(const MDNamespace *N) : DIScope(N) {} +class DINameSpace { + MDNamespace *N; - MDNamespace *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDNamespace *() const { return get(); } - MDNamespace *operator->() const { return get(); } - MDNamespace &operator*() const { return *get(); } +public: + DINameSpace(const MDNamespace *N = nullptr) + : N(const_cast(N)) {} - StringRef getName() const { return get()->getName(); } - unsigned getLineNumber() const { return get()->getLine(); } - DIScope getContext() const { return DIScope(get()->getScope()); } + operator DIDescriptor() const { return N; } + operator DIScope() const { return N; } + operator MDNamespace *() const { return N; } + MDNamespace *operator->() const { return N; } + MDNamespace &operator*() const { return *N; } }; -/// \brief This is a wrapper for template type parameter. -class DITemplateTypeParameter : public DIDescriptor { -public: - DITemplateTypeParameter() = default; - DITemplateTypeParameter(const MDTemplateTypeParameter *N) : DIDescriptor(N) {} +class DITemplateTypeParameter { + MDTemplateTypeParameter *N; - MDTemplateTypeParameter *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDTemplateTypeParameter *() const { return get(); } - MDTemplateTypeParameter *operator->() const { return get(); } - MDTemplateTypeParameter &operator*() const { return *get(); } +public: + DITemplateTypeParameter(const MDTemplateTypeParameter *N = nullptr) + : N(const_cast(N)) {} - StringRef getName() const { return get()->getName(); } - DITypeRef getType() const { return get()->getType(); } + operator MDTemplateTypeParameter *() const { return N; } + MDTemplateTypeParameter *operator->() const { return N; } + MDTemplateTypeParameter &operator*() const { return *N; } }; -/// \brief This is a wrapper for template value parameter. -class DITemplateValueParameter : public DIDescriptor { -public: - DITemplateValueParameter() = default; - DITemplateValueParameter(const MDTemplateValueParameter *N) - : DIDescriptor(N) {} +class DITemplateValueParameter { + MDTemplateValueParameter *N; - MDTemplateValueParameter *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDTemplateValueParameter *() const { return get(); } - MDTemplateValueParameter *operator->() const { return get(); } - MDTemplateValueParameter &operator*() const { return *get(); } +public: + DITemplateValueParameter(const MDTemplateValueParameter *N = nullptr) + : N(const_cast(N)) {} - StringRef getName() const { return get()->getName(); } - DITypeRef getType() const { return get()->getType(); } - Metadata *getValue() const { return get()->getValue(); } + operator MDTemplateValueParameter *() const { return N; } + MDTemplateValueParameter *operator->() const { return N; } + MDTemplateValueParameter &operator*() const { return *N; } }; class DIGlobalVariable { @@ -598,7 +582,6 @@ public: MDLocalVariable &operator*() const { return *N; } }; - class DIExpression { MDExpression *N; diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 9ee5f10bd03..f2e3b8feefa 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -438,7 +438,7 @@ void DwarfUnit::addSourceLine(DIE &Die, DIObjCProperty Ty) { /// addSourceLine - Add location information to specified debug information /// entry. void DwarfUnit::addSourceLine(DIE &Die, DINameSpace NS) { - addSourceLine(Die, NS.getLineNumber(), NS.getFilename(), NS.getDirectory()); + addSourceLine(Die, NS->getLine(), NS->getFilename(), NS->getDirectory()); } /// addRegisterOp - Add register operand. @@ -1145,10 +1145,10 @@ void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer, DIE &ParamDIE = createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer); // Add the type if it exists, it could be void and therefore no type. - if (TP.getType()) - addType(ParamDIE, resolve(TP.getType())); - if (!TP.getName().empty()) - addString(ParamDIE, dwarf::DW_AT_name, TP.getName()); + if (TP->getType()) + addType(ParamDIE, resolve(TP->getType())); + if (!TP->getName().empty()) + addString(ParamDIE, dwarf::DW_AT_name, TP->getName()); } /// constructTemplateValueParameterDIE - Construct new DIE for the given @@ -1156,17 +1156,17 @@ void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer, void DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer, DITemplateValueParameter VP) { - DIE &ParamDIE = createAndAddDIE(VP.getTag(), Buffer); + DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer); // Add the type if there is one, template template and template parameter // packs will not have a type. - if (VP.getTag() == dwarf::DW_TAG_template_value_parameter) - addType(ParamDIE, resolve(VP.getType())); - if (!VP.getName().empty()) - addString(ParamDIE, dwarf::DW_AT_name, VP.getName()); - if (Metadata *Val = VP.getValue()) { + if (VP->getTag() == dwarf::DW_TAG_template_value_parameter) + addType(ParamDIE, resolve(VP->getType())); + if (!VP->getName().empty()) + addString(ParamDIE, dwarf::DW_AT_name, VP->getName()); + if (Metadata *Val = VP->getValue()) { if (ConstantInt *CI = mdconst::dyn_extract(Val)) - addConstantValue(ParamDIE, CI, resolve(VP.getType())); + addConstantValue(ParamDIE, CI, resolve(VP->getType())); else if (GlobalValue *GV = mdconst::dyn_extract(Val)) { // For declaration non-type template parameters (such as global values and // functions) @@ -1176,11 +1176,11 @@ DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer, // parameter, rather than a pointer to it. addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value); addBlock(ParamDIE, dwarf::DW_AT_location, Loc); - } else if (VP.getTag() == dwarf::DW_TAG_GNU_template_template_param) { + } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) { assert(isa(Val)); addString(ParamDIE, dwarf::DW_AT_GNU_template_name, cast(Val)->getString()); - } else if (VP.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) { + } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) { addTemplateParams(ParamDIE, cast(Val)); } } @@ -1190,19 +1190,19 @@ DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer, DIE *DwarfUnit::getOrCreateNameSpace(DINameSpace NS) { // Construct the context before querying for the existence of the DIE in case // such construction creates the DIE. - DIE *ContextDIE = getOrCreateContextDIE(NS.getContext()); + DIE *ContextDIE = getOrCreateContextDIE(NS->getScope()); if (DIE *NDie = getDIE(NS)) return NDie; DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); - StringRef Name = NS.getName(); + StringRef Name = NS->getName(); if (!Name.empty()) - addString(NDie, dwarf::DW_AT_name, NS.getName()); + addString(NDie, dwarf::DW_AT_name, NS->getName()); else Name = "(anonymous namespace)"; DD->addAccelNamespace(Name, NDie); - addGlobalName(Name, NDie, NS.getContext()); + addGlobalName(Name, NDie, NS->getScope()); addSourceLine(NDie, NS); return &NDie; } diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 87cd3ef44d8..2b7d7f04083 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -224,8 +224,8 @@ void DebugInfoFinder::processScope(DIScope Scope) { return; if (DILexicalBlock LB = dyn_cast(Scope)) { processScope(LB.getContext()); - } else if (DINameSpace NS = dyn_cast(Scope)) { - processScope(NS.getContext()); + } else if (auto *NS = dyn_cast(Scope)) { + processScope(NS->getScope()); } } @@ -235,12 +235,10 @@ void DebugInfoFinder::processSubprogram(DISubprogram SP) { processScope(SP.getContext().resolve(TypeIdentifierMap)); processType(SP.getType()); for (auto *Element : SP.getTemplateParams()) { - if (DITemplateTypeParameter TType = - dyn_cast(Element)) { - processType(TType.getType().resolve(TypeIdentifierMap)); - } else if (DITemplateValueParameter TVal = - dyn_cast(Element)) { - processType(TVal.getType().resolve(TypeIdentifierMap)); + if (auto *TType = dyn_cast(Element)) { + processType(TType->getType().resolve(TypeIdentifierMap)); + } else if (auto *TVal = dyn_cast(Element)) { + processType(TVal->getType().resolve(TypeIdentifierMap)); } } } diff --git a/tools/opt/BreakpointPrinter.cpp b/tools/opt/BreakpointPrinter.cpp index eb89b9bca80..846211ba781 100644 --- a/tools/opt/BreakpointPrinter.cpp +++ b/tools/opt/BreakpointPrinter.cpp @@ -30,10 +30,10 @@ struct BreakpointPrinter : public ModulePass { BreakpointPrinter(raw_ostream &out) : ModulePass(ID), Out(out) {} void getContextName(DIDescriptor Context, std::string &N) { - if (DINameSpace NS = dyn_cast(Context)) { - if (!NS.getName().empty()) { - getContextName(NS.getContext(), N); - N = N + NS.getName().str() + "::"; + if (auto *NS = dyn_cast(Context)) { + if (!NS->getName().empty()) { + getContextName(NS->getScope(), N); + N = N + NS->getName().str() + "::"; } } else if (DIType TY = dyn_cast(Context)) { if (!TY.getName().empty()) {