From 1ea24954c6d19e3788434ec3fb0ae5a7d3413517 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 6 Apr 2015 19:49:39 +0000 Subject: [PATCH] DebugInfo: Remove DIDescriptor::Verify() Remove `DIDescriptor::Verify()` and the `Verify()`s from subclasses. They had already been gutted, and just did an `isa<>` check. In a couple of cases I've temporarily dropped the check entirely, but subsequent commits are going to disallow conversions to the `DIDescriptor`s directly from `MDNode`, so the checks will come back in another form soon enough. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234201 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineInstr.h | 4 +- include/llvm/CodeGen/MachineInstrBuilder.h | 6 +- include/llvm/IR/DebugInfo.h | 33 ----------- lib/CodeGen/AsmPrinter/DebugLocEntry.h | 2 +- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 2 - lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 8 +-- lib/CodeGen/AsmPrinter/DwarfDebug.h | 1 - lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 4 +- lib/IR/DIBuilder.cpp | 23 ++------ lib/IR/DebugInfo.cpp | 61 --------------------- lib/Transforms/IPO/StripSymbols.cpp | 4 -- unittests/IR/IRBuilderTest.cpp | 4 +- 12 files changed, 17 insertions(+), 135 deletions(-) diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index 333dcdb3eff..9097150ab62 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -248,9 +248,7 @@ public: /// this DBG_VALUE instruction. DIVariable getDebugVariable() const { assert(isDebugValue() && "not a DBG_VALUE"); - DIVariable Var(getOperand(2).getMetadata()); - assert(Var.Verify() && "not a DIVariable"); - return Var; + return cast(getOperand(2).getMetadata()); } /// \brief Return the complex address expression referenced by diff --git a/include/llvm/CodeGen/MachineInstrBuilder.h b/include/llvm/CodeGen/MachineInstrBuilder.h index eb8ea524148..925fe4bcf1f 100644 --- a/include/llvm/CodeGen/MachineInstrBuilder.h +++ b/include/llvm/CodeGen/MachineInstrBuilder.h @@ -174,7 +174,7 @@ public: const MachineInstrBuilder &addMetadata(const MDNode *MD) const { MI->addOperand(*MF, MachineOperand::CreateMetadata(MD)); - assert((MI->isDebugValue() ? MI->getDebugVariable().Verify() : true) && + assert((MI->isDebugValue() ? MI->getDebugVariable().isVariable() : true) && "first MDNode argument of a DBG_VALUE not a DIVariable"); return *this; } @@ -355,7 +355,7 @@ inline MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID, bool IsIndirect, unsigned Reg, unsigned Offset, const MDNode *Variable, const MDNode *Expr) { - assert(DIVariable(Variable).Verify() && "not a DIVariable"); + assert(isa(Variable) && "not a DIVariable"); assert(DIExpression(Expr)->isValid() && "not a DIExpression"); assert(DIVariable(Variable)->isValidLocationForIntrinsic(DL) && "Expected inlined-at fields to agree"); @@ -384,7 +384,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, const MCInstrDesc &MCID, bool IsIndirect, unsigned Reg, unsigned Offset, const MDNode *Variable, const MDNode *Expr) { - assert(DIVariable(Variable).Verify() && "not a DIVariable"); + assert(isa(Variable) && "not a DIVariable"); assert(DIExpression(Expr)->isValid() && "not a DIExpression"); MachineFunction &MF = *BB.getParent(); MachineInstr *MI = diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index e478f7c1b55..2fa68982ac8 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -98,8 +98,6 @@ protected: public: explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {} - bool Verify() const; - MDNode *get() const { return const_cast(DbgNode); } operator MDNode *() const { return get(); } MDNode *operator->() const { return get(); } @@ -188,7 +186,6 @@ public: int64_t getLo() const { return get()->getLo(); } int64_t getCount() const { return get()->getCount(); } - bool Verify() const; }; /// \brief This descriptor holds an array of nodes with type T. @@ -227,7 +224,6 @@ public: StringRef getName() const { return get()->getName(); } int64_t getEnumValue() const { return get()->getValue(); } - bool Verify() const; }; template class DIRef; @@ -355,8 +351,6 @@ public: return *get(); } - bool Verify() const; - DIScopeRef getContext() const { return DIScopeRef::get(get()->getScope()); } StringRef getName() const { return get()->getName(); } unsigned getLineNumber() const { return get()->getLine(); } @@ -416,8 +410,6 @@ public: } unsigned getEncoding() const { return get()->getEncoding(); } - - bool Verify() const; }; /// \brief A simple derived type @@ -465,8 +457,6 @@ public: return nullptr; } - - bool Verify() const; }; /// \brief Types that refer to multiple other types. @@ -528,8 +518,6 @@ public: return DIArray(get()->getTemplateParams()); } MDString *getIdentifier() const { return get()->getRawIdentifier(); } - - bool Verify() const; }; class DISubroutineType : public DICompositeType { @@ -568,7 +556,6 @@ public: /// \brief Retrieve the MDNode for the directory/file pair. MDNode *getFileNode() const { return get(); } - bool Verify() const; }; /// \brief A wrapper for a compile unit. @@ -614,8 +601,6 @@ public: return get()->getSplitDebugFilename(); } unsigned getEmissionKind() const { return get()->getEmissionKind(); } - - bool Verify() const; }; /// \brief This is a wrapper for a subprogram (e.g. a function). @@ -662,8 +647,6 @@ public: return DITypeRef::get(get()->getContainingType()); } - bool Verify() const; - /// \brief Check if this provides debugging information for the function F. bool describes(const Function *F); @@ -744,7 +727,6 @@ public: return N->getColumn(); return 0; } - bool Verify() const; }; /// \brief This is a wrapper for a lexical block with a filename change. @@ -768,7 +750,6 @@ public: unsigned getColumnNumber() const { return getScope().getColumnNumber(); } DILexicalBlock getScope() const { return DILexicalBlock(get()->getScope()); } unsigned getDiscriminator() const { return get()->getDiscriminator(); } - bool Verify() const; }; /// \brief A wrapper for a C++ style name space. @@ -790,7 +771,6 @@ public: StringRef getName() const { return get()->getName(); } unsigned getLineNumber() const { return get()->getLine(); } DIScope getContext() const { return DIScope(get()->getScope()); } - bool Verify() const; }; /// \brief This is a wrapper for template type parameter. @@ -813,7 +793,6 @@ public: StringRef getName() const { return get()->getName(); } DITypeRef getType() const { return DITypeRef::get(get()->getType()); } - bool Verify() const; }; /// \brief This is a wrapper for template value parameter. @@ -837,7 +816,6 @@ public: StringRef getName() const { return get()->getName(); } DITypeRef getType() const { return DITypeRef::get(get()->getType()); } Metadata *getValue() const { return get()->getValue(); } - bool Verify() const; }; /// \brief This is a wrapper for a global variable. @@ -880,8 +858,6 @@ public: DIDerivedType getStaticDataMemberDeclaration() const { return DIDerivedType(get()->getStaticDataMemberDeclaration()); } - - bool Verify() const; }; /// \brief This is a wrapper for a variable (e.g. parameter, local, global etc). @@ -922,8 +898,6 @@ public: /// \brief If this variable is inlined then return inline location. MDNode *getInlinedAt() const { return DIDescriptor(get()->getInlinedAt()); } - bool Verify() const; - /// \brief Check if this is a "__block" variable (Apple Blocks). bool isBlockByrefVariable(const DITypeIdentifierMap &Map) const { return (getType().resolve(Map)).isBlockByrefStruct(); @@ -960,9 +934,6 @@ public: return *get(); } - // Don't call this. Call isValid() directly. - bool Verify() const = delete; - /// \brief Return the number of elements in the complex expression. unsigned getNumElements() const { return get()->getNumElements(); } @@ -1063,7 +1034,6 @@ public: } StringRef getFilename() const { return getScope().getFilename(); } StringRef getDirectory() const { return getScope().getDirectory(); } - bool Verify() const; bool atSameLineAs(const DILocation &Other) const { return (getLineNumber() == Other.getLineNumber() && getFilename() == Other.getFilename()); @@ -1140,8 +1110,6 @@ public: /// \note Objective-C doesn't have an ODR, so there is no benefit in storing /// the type as a DITypeRef here. DIType getType() const { return DIType(get()->getType()); } - - bool Verify() const; }; /// \brief An imported module (C++ using directive or similar). @@ -1167,7 +1135,6 @@ public: } unsigned getLineNumber() const { return get()->getLine(); } StringRef getName() const { return get()->getName(); } - bool Verify() const; }; /// \brief Find subprogram that is enclosing this scope. diff --git a/lib/CodeGen/AsmPrinter/DebugLocEntry.h b/lib/CodeGen/AsmPrinter/DebugLocEntry.h index 6914bbe9a59..0b5b8580cd8 100644 --- a/lib/CodeGen/AsmPrinter/DebugLocEntry.h +++ b/lib/CodeGen/AsmPrinter/DebugLocEntry.h @@ -42,7 +42,7 @@ public: } Value(const MDNode *Var, const MDNode *Expr, MachineLocation Loc) : Variable(Var), Expression(Expr), EntryKind(E_Location), Loc(Loc) { - assert(DIVariable(Var).Verify()); + assert(isa(Var)); assert(DIExpression(Expr)->isValid()); } diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index eee5fc537da..5eb7915f9ed 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -637,8 +637,6 @@ DwarfCompileUnit::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) { std::unique_ptr DwarfCompileUnit::constructImportedEntityDIE(const DIImportedEntity &Module) { - assert(Module.Verify() && - "Use one of the MDNode * overloads to handle invalid metadata"); std::unique_ptr IMDie = make_unique((dwarf::Tag)Module.getTag()); insertDIE(Module, IMDie.get()); DIE *EntityDie; diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 6927f2c0870..ca8554185e6 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -421,7 +421,6 @@ DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) { void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N) { DIImportedEntity Module(N); - assert(Module.Verify()); if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext())) D->addChild(TheCU.constructImportedEntityDIE(Module)); } @@ -1499,9 +1498,10 @@ static void emitDebugLocValue(const AsmPrinter &AP, Streamer); // Regular entry. if (Value.isInt()) { - DIBasicType BTy(DV.getType().resolve(TypeIdentifierMap)); - if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed || - BTy.getEncoding() == dwarf::DW_ATE_signed_char)) + MDType *T = DV.getType().resolve(TypeIdentifierMap); + auto *B = dyn_cast(T); + if (B && (B->getEncoding() == dwarf::DW_ATE_signed || + B->getEncoding() == dwarf::DW_ATE_signed_char)) DwarfExpr.AddSignedConstant(Value.getInt()); else DwarfExpr.AddUnsignedConstant(Value.getInt()); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 74db3efcea6..993d421b7aa 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -88,7 +88,6 @@ public: : Var(V), Expr(1, E), TheDIE(nullptr), DotDebugLocOffset(~0U), MInsn(nullptr), DD(DD) { FrameIndex.push_back(FI); - assert(Var.Verify()); assert(!E || E->isValid()); } diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index f6af73fe20e..dc234dde7f4 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -440,8 +440,6 @@ void DwarfUnit::addSourceLine(DIE &Die, DIObjCProperty Ty) { /// addSourceLine - Add location information to specified debug information /// entry. void DwarfUnit::addSourceLine(DIE &Die, DINameSpace NS) { - assert(NS.Verify()); - addSourceLine(Die, NS.getLineNumber(), NS.getFilename(), NS.getDirectory()); } @@ -1571,7 +1569,7 @@ void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) { /// getOrCreateStaticMemberDIE - Create new DIE for C++ static member. DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) { - if (!DT.Verify()) + if (!DT) return nullptr; // Construct the context before querying for the existence of the DIE in case diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 2bddc3f7f05..35e0ffc8c0d 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -175,7 +175,6 @@ createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context, Metadata *NS, unsigned Line, StringRef Name, SmallVectorImpl &AllImportedModules) { DIImportedEntity M = MDImportedEntity::get(C, Tag, Context, NS, Line, Name); - assert(M.Verify() && "Imported module should be valid"); AllImportedModules.emplace_back(M.get()); return M; } @@ -741,33 +740,23 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNo) { - DINameSpace R = MDNamespace::get(VMContext, getNonCompileUnitScope(Scope), - File, Name, LineNo); - assert(R.Verify() && - "createNameSpace should return a verifiable DINameSpace"); - return R; + return MDNamespace::get(VMContext, getNonCompileUnitScope(Scope), File, Name, + LineNo); } DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, DIFile File, unsigned Discriminator) { - DILexicalBlockFile R = MDLexicalBlockFile::get( - VMContext, Scope, File.getFileNode(), Discriminator); - assert( - R.Verify() && - "createLexicalBlockFile should return a verifiable DILexicalBlockFile"); - return R; + return MDLexicalBlockFile::get(VMContext, Scope, File.getFileNode(), + Discriminator); } DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, unsigned Line, unsigned Col) { // Make these distinct, to avoid merging two lexical blocks on the same // file/line/column. - DILexicalBlock R = MDLexicalBlock::getDistinct( - VMContext, getNonCompileUnitScope(Scope), File.getFileNode(), Line, Col); - assert(R.Verify() && - "createLexicalBlock should return a verifiable DILexicalBlock"); - return R; + return MDLexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), + File.getFileNode(), Line, Col); } static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index f92d0b6bce2..1ad9dcae3ad 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -80,22 +80,6 @@ unsigned DIDescriptor::splitFlags(unsigned Flags, return Flags; } -bool DIDescriptor::Verify() const { - return DbgNode && - (DIDerivedType(DbgNode).Verify() || - DICompositeType(DbgNode).Verify() || DIBasicType(DbgNode).Verify() || - DIVariable(DbgNode).Verify() || DISubprogram(DbgNode).Verify() || - DIGlobalVariable(DbgNode).Verify() || DIFile(DbgNode).Verify() || - DICompileUnit(DbgNode).Verify() || DINameSpace(DbgNode).Verify() || - DILexicalBlock(DbgNode).Verify() || - DILexicalBlockFile(DbgNode).Verify() || - DISubrange(DbgNode).Verify() || DIEnumerator(DbgNode).Verify() || - DIObjCProperty(DbgNode).Verify() || - DITemplateTypeParameter(DbgNode).Verify() || - DITemplateValueParameter(DbgNode).Verify() || - DIImportedEntity(DbgNode).Verify()); -} - static Metadata *getField(const MDNode *DbgNode, unsigned Elt) { if (!DbgNode || Elt >= DbgNode->getNumOperands()) return nullptr; @@ -175,9 +159,6 @@ void DIDescriptor::replaceAllUsesWith(MDNode *D) { Node->replaceAllUsesWith(D); } -bool DICompileUnit::Verify() const { return isCompileUnit(); } -bool DIObjCProperty::Verify() const { return isObjCProperty(); } - #ifndef NDEBUG /// \brief Check if a value can be a reference to a type. static bool isTypeRef(const Metadata *MD) { @@ -207,43 +188,6 @@ static bool isDescriptorRef(const Metadata *MD) { } #endif -bool DIType::Verify() const { return isType(); } -bool DIBasicType::Verify() const { return isBasicType(); } -bool DIDerivedType::Verify() const { return isDerivedType(); } -bool DICompositeType::Verify() const { return isCompositeType(); } -bool DISubprogram::Verify() const { return isSubprogram(); } -bool DIGlobalVariable::Verify() const { return isGlobalVariable(); } -bool DIVariable::Verify() const { return isVariable(); } - -bool DILocation::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DINameSpace::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DIFile::Verify() const { return dyn_cast_or_null(DbgNode); } -bool DIEnumerator::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DISubrange::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DILexicalBlock::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DILexicalBlockFile::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DITemplateTypeParameter::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DITemplateValueParameter::Verify() const { - return dyn_cast_or_null(DbgNode); -} -bool DIImportedEntity::Verify() const { - return dyn_cast_or_null(DbgNode); -} - void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) { TypedTrackingMDRef N(get()); if (Elements) @@ -342,18 +286,15 @@ StringRef DIScope::getDirectory() const { } void DICompileUnit::replaceSubprograms(DIArray Subprograms) { - assert(Verify() && "Expected compile unit"); get()->replaceSubprograms(cast_or_null(Subprograms.get())); } void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) { - assert(Verify() && "Expected compile unit"); get()->replaceGlobalVariables(cast_or_null(GlobalVariables.get())); } DILocation DILocation::copyWithNewScope(LLVMContext &Ctx, DILexicalBlockFile NewScope) { - assert(Verify()); assert(NewScope && "Expected valid scope"); const auto *Old = cast(DbgNode); @@ -368,13 +309,11 @@ unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) { DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope, LLVMContext &VMContext) { - assert(DIVariable(DV).Verify() && "Expected a DIVariable"); return cast(DV) ->withInline(cast_or_null(InlinedScope)); } DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) { - assert(DIVariable(DV).Verify() && "Expected a DIVariable"); return cast(DV)->withoutInline(); } diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp index 816978ea9ce..b5d5476d417 100644 --- a/lib/Transforms/IPO/StripSymbols.cpp +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -306,14 +306,11 @@ bool StripDeadDebugInfo::runOnModule(Module &M) { DenseSet VisitedSet; for (DICompileUnit DIC : F.compile_units()) { - assert(DIC.Verify() && "DIC must verify as a DICompileUnit."); - // Create our live subprogram list. DIArray SPs = DIC.getSubprograms(); bool SubprogramChange = false; for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) { DISubprogram DISP(SPs.getElement(i)); - assert(DISP.Verify() && "DISP must verify as a DISubprogram."); // Make sure we visit each subprogram only once. if (!VisitedSet.insert(DISP).second) @@ -331,7 +328,6 @@ bool StripDeadDebugInfo::runOnModule(Module &M) { bool GlobalVariableChange = false; for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) { DIGlobalVariable DIG(GVs.getElement(i)); - assert(DIG.Verify() && "DIG must verify as DIGlobalVariable."); // Make sure we only visit each global variable only once. if (!VisitedSet.insert(DIG).second) diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index c721ef508bf..cf189b1fb11 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/unittests/IR/IRBuilderTest.cpp @@ -296,9 +296,7 @@ TEST_F(IRBuilderTest, DIBuilder) { auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, "F.CBL", "/", "llvm-cobol74", true, "", 0); auto Type = DIB.createSubroutineType(File, DIB.getOrCreateTypeArray(None)); - auto SP = DIB.createFunction(CU, "foo", "", File, 1, Type, - false, true, 1, 0, true, F); - EXPECT_TRUE(SP.Verify()); + DIB.createFunction(CU, "foo", "", File, 1, Type, false, true, 1, 0, true, F); AllocaInst *I = Builder.CreateAlloca(Builder.getInt8Ty()); auto BarSP = DIB.createFunction(CU, "bar", "", File, 1, Type, false, true, 1, 0, true, nullptr); -- 2.34.1