From: serge-sans-paille Date: Wed, 2 Feb 2022 12:53:56 +0000 (+0100) Subject: Reduce dependencies on llvm/BinaryFormat/Dwarf.h X-Git-Tag: upstream/15.0.7~17815 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffe8720aa060d66297500f30bb8ad02114e40326;p=platform%2Fupstream%2Fllvm.git Reduce dependencies on llvm/BinaryFormat/Dwarf.h This header is very large (3M Lines once expended) and was included in location where dwarf-specific information were not needed. More specifically, this commit suppresses the dependencies on llvm/BinaryFormat/Dwarf.h in two headers: llvm/IR/IRBuilder.h and llvm/IR/DebugInfoMetadata.h. As these headers (esp. the former) are widely used, this has a decent impact on number of preprocessed lines generated during compilation of LLVM, as showcased below. This is achieved by moving some definitions back to the .cpp file, no performance impact implied[0]. As a consequence of that patch, downstream user may need to manually some extra files: llvm/IR/IRBuilder.h no longer includes llvm/BinaryFormat/Dwarf.h llvm/IR/DebugInfoMetadata.h no longer includes llvm/BinaryFormat/Dwarf.h In some situations, codes maybe relying on the fact that llvm/BinaryFormat/Dwarf.h was including llvm/ADT/Triple.h, this hidden dependency now needs to be explicit. $ clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Transforms/Scalar/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l after: 10978519 before: 11245451 Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup [0] https://llvm-compile-time-tracker.com/compare.php?from=fa7145dfbf94cb93b1c3e610582c495cb806569b&to=995d3e326ee1d9489145e20762c65465a9caeab4&stat=instructions Differential Revision: https://reviews.llvm.org/D118781 --- diff --git a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp index d2ef284..a576ade32 100644 --- a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp @@ -14,6 +14,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Error.h" #include "llvm/Transforms/Utils/ModuleUtils.h" using namespace llvm; diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h index fc461fc..d3aad37 100644 --- a/llvm/include/llvm/IR/DIBuilder.h +++ b/llvm/include/llvm/IR/DIBuilder.h @@ -21,6 +21,7 @@ #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/TrackingMDRef.h" #include "llvm/Support/Casting.h" diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index 9656917..c6ef69e 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -22,7 +22,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" -#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Metadata.h" #include "llvm/Support/Casting.h" @@ -61,6 +60,10 @@ namespace llvm { +namespace dwarf { +enum Tag : uint16_t; +} + extern cl::opt EnableFSDiscriminator; class DITypeRefArray { @@ -156,7 +159,7 @@ protected: void setTag(unsigned Tag) { SubclassData16 = Tag; } public: - dwarf::Tag getTag() const { return (dwarf::Tag)SubclassData16; } + dwarf::Tag getTag() const; /// Debug info flags. /// @@ -267,7 +270,7 @@ public: /// Return a (temporary) clone of this. TempGenericDINode clone() const { return cloneImpl(); } - dwarf::Tag getTag() const { return (dwarf::Tag)SubclassData16; } + dwarf::Tag getTag() const; StringRef getHeader() const { return getStringOperand(0); } MDString *getRawHeader() const { return getOperandAs(0); } @@ -298,8 +301,7 @@ class DISubrange : public DINode { friend class LLVMContextImpl; friend class MDNode; - DISubrange(LLVMContext &C, StorageType Storage, ArrayRef Ops) - : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {} + DISubrange(LLVMContext &C, StorageType Storage, ArrayRef Ops); ~DISubrange() = default; @@ -363,9 +365,7 @@ class DIGenericSubrange : public DINode { friend class MDNode; DIGenericSubrange(LLVMContext &C, StorageType Storage, - ArrayRef Ops) - : DINode(C, DIGenericSubrangeKind, Storage, - dwarf::DW_TAG_generic_subrange, Ops) {} + ArrayRef Ops); ~DIGenericSubrange() = default; @@ -414,11 +414,7 @@ class DIEnumerator : public DINode { APInt Value; DIEnumerator(LLVMContext &C, StorageType Storage, const APInt &Value, - bool IsUnsigned, ArrayRef Ops) - : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops), - Value(Value) { - SubclassData32 = IsUnsigned; - } + bool IsUnsigned, ArrayRef Ops); DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value, bool IsUnsigned, ArrayRef Ops) : DIEnumerator(C, Storage, APInt(64, Value, !IsUnsigned), IsUnsigned, @@ -568,9 +564,7 @@ private: DIFile(LLVMContext &C, StorageType Storage, Optional> CS, Optional Src, - ArrayRef Ops) - : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops), - Checksum(CS), Source(Src) {} + ArrayRef Ops); ~DIFile() = default; static DIFile *getImpl(LLVMContext &Context, StringRef Filename, @@ -1021,42 +1015,19 @@ public: /// Get casted version of extra data. /// @{ - DIType *getClassType() const { - assert(getTag() == dwarf::DW_TAG_ptr_to_member_type); - return cast_or_null(getExtraData()); - } + DIType *getClassType() const; DIObjCProperty *getObjCProperty() const { return dyn_cast_or_null(getExtraData()); } - uint32_t getVBPtrOffset() const { - assert(getTag() == dwarf::DW_TAG_inheritance); - if (auto *CM = cast_or_null(getExtraData())) - if (auto *CI = dyn_cast_or_null(CM->getValue())) - return static_cast(CI->getZExtValue()); - return 0; - } + uint32_t getVBPtrOffset() const; - Constant *getStorageOffsetInBits() const { - assert(getTag() == dwarf::DW_TAG_member && isBitField()); - if (auto *C = cast_or_null(getExtraData())) - return C->getValue(); - return nullptr; - } + Constant *getStorageOffsetInBits() const; - Constant *getConstant() const { - assert(getTag() == dwarf::DW_TAG_member && isStaticMember()); - if (auto *C = cast_or_null(getExtraData())) - return C->getValue(); - return nullptr; - } - Constant *getDiscriminantValue() const { - assert(getTag() == dwarf::DW_TAG_member && !isStaticMember()); - if (auto *C = cast_or_null(getExtraData())) - return C->getValue(); - return nullptr; - } + Constant *getConstant() const; + + Constant *getDiscriminantValue() const; /// @} static bool classof(const Metadata *MD) { @@ -1300,10 +1271,7 @@ class DISubroutineType : public DIType { uint8_t CC; DISubroutineType(LLVMContext &C, StorageType Storage, DIFlags Flags, - uint8_t CC, ArrayRef Ops) - : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, - 0, 0, 0, 0, Flags, Ops), - CC(CC) {} + uint8_t CC, ArrayRef Ops); ~DISubroutineType() = default; static DISubroutineType *getImpl(LLVMContext &Context, DIFlags Flags, @@ -1385,15 +1353,7 @@ private: bool IsOptimized, unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling, unsigned NameTableKind, - bool RangesBaseAddress, ArrayRef Ops) - : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops), - SourceLanguage(SourceLanguage), IsOptimized(IsOptimized), - RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), - DWOId(DWOId), SplitDebugInlining(SplitDebugInlining), - DebugInfoForProfiling(DebugInfoForProfiling), - NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) { - assert(Storage != Uniqued); - } + bool RangesBaseAddress, ArrayRef Ops); ~DICompileUnit() = default; static DICompileUnit * @@ -1872,19 +1832,7 @@ public: static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality = SPFlagNonvirtual, - bool IsMainSubprogram = false) { - // We're assuming virtuality is the low-order field. - static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) && - int(SPFlagPureVirtual) == - int(dwarf::DW_VIRTUALITY_pure_virtual), - "Virtuality constant mismatch"); - return static_cast( - (Virtuality & SPFlagVirtuality) | - (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) | - (IsDefinition ? SPFlagDefinition : SPFlagZero) | - (IsOptimized ? SPFlagOptimized : SPFlagZero) | - (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero)); - } + bool IsMainSubprogram = false); private: DIFlags Flags; @@ -1892,13 +1840,7 @@ private: DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line, unsigned ScopeLine, unsigned VirtualIndex, int ThisAdjustment, - DIFlags Flags, DISPFlags SPFlags, ArrayRef Ops) - : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, - Ops), - Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex), - ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) { - static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range"); - } + DIFlags Flags, DISPFlags SPFlags, ArrayRef Ops); ~DISubprogram() = default; static DISubprogram * @@ -2108,8 +2050,7 @@ public: class DILexicalBlockBase : public DILocalScope { protected: DILexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage, - ArrayRef Ops) - : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {} + ArrayRef Ops); ~DILexicalBlockBase() = default; public: @@ -2301,10 +2242,7 @@ class DINamespace : public DIScope { unsigned ExportSymbols : 1; DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols, - ArrayRef Ops) - : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, - Ops), - ExportSymbols(ExportSymbols) {} + ArrayRef Ops); ~DINamespace() = default; static DINamespace *getImpl(LLVMContext &Context, DIScope *Scope, @@ -2353,9 +2291,7 @@ class DIModule : public DIScope { bool IsDecl; DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo, - bool IsDecl, ArrayRef Ops) - : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops), - LineNo(LineNo), IsDecl(IsDecl) {} + bool IsDecl, ArrayRef Ops); ~DIModule() = default; static DIModule *getImpl(LLVMContext &Context, DIFile *File, DIScope *Scope, @@ -2449,10 +2385,7 @@ class DITemplateTypeParameter : public DITemplateParameter { friend class MDNode; DITemplateTypeParameter(LLVMContext &Context, StorageType Storage, - bool IsDefault, ArrayRef Ops) - : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage, - dwarf::DW_TAG_template_type_parameter, IsDefault, - Ops) {} + bool IsDefault, ArrayRef Ops); ~DITemplateTypeParameter() = default; static DITemplateTypeParameter *getImpl(LLVMContext &Context, StringRef Name, @@ -2541,10 +2474,8 @@ class DIVariable : public DINode { uint32_t AlignInBits; protected: - DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line, - ArrayRef Ops, uint32_t AlignInBits = 0) - : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line), - AlignInBits(AlignInBits) {} + DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line, + ArrayRef Ops, uint32_t AlignInBits = 0); ~DIVariable() = default; public: @@ -2763,9 +2694,7 @@ public: } /// Return whether the first element a DW_OP_deref. - bool startsWithDeref() const { - return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref; - } + bool startsWithDeref() const; /// Holds the characteristics of one fragment of a larger variable. struct FragmentInfo { @@ -2923,10 +2852,7 @@ public: /// Check if the expression consists of exactly one entry value operand. /// (This is the only configuration of entry values that is supported.) - bool isEntryValue() const { - return getNumElements() > 0 && - getElement(0) == dwarf::DW_OP_LLVM_entry_value; - } + bool isEntryValue() const; /// Try to shorten an expression with an initial constant operand. /// Returns a new expression and constant on success, or the original @@ -3057,10 +2983,7 @@ class DICommonBlock : public DIScope { friend class MDNode; DICommonBlock(LLVMContext &Context, StorageType Storage, unsigned LineNo, - ArrayRef Ops) - : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block, - Ops), - LineNo(LineNo) {} + ArrayRef Ops); static DICommonBlock *getImpl(LLVMContext &Context, DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, @@ -3209,8 +3132,7 @@ class DILabel : public DINode { unsigned Line; DILabel(LLVMContext &C, StorageType Storage, unsigned Line, - ArrayRef Ops) - : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {} + ArrayRef Ops); ~DILabel() = default; static DILabel *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, @@ -3276,10 +3198,7 @@ class DIObjCProperty : public DINode { unsigned Attributes; DIObjCProperty(LLVMContext &C, StorageType Storage, unsigned Line, - unsigned Attributes, ArrayRef Ops) - : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, - Ops), - Line(Line), Attributes(Attributes) {} + unsigned Attributes, ArrayRef Ops); ~DIObjCProperty() = default; static DIObjCProperty * diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index dc8c573..7c4f121 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -25,7 +25,7 @@ #include "llvm/IR/ConstantFolder.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" -#include "llvm/IR/DebugInfoMetadata.h" +//#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/FPEnv.h" @@ -218,23 +218,11 @@ public: } /// Get location information used by debugging information. - DebugLoc getCurrentDebugLocation() const { - for (auto &KV : MetadataToCopy) - if (KV.first == LLVMContext::MD_dbg) - return {cast(KV.second)}; - - return {}; - } + DebugLoc getCurrentDebugLocation() const; /// If this builder has a current debug location, set it on the /// specified instruction. - void SetInstDebugLocation(Instruction *I) const { - for (const auto &KV : MetadataToCopy) - if (KV.first == LLVMContext::MD_dbg) { - I->setDebugLoc(DebugLoc(KV.second)); - return; - } - } + void SetInstDebugLocation(Instruction *I) const; /// Add all entries in MetadataToCopy to \p I. void AddMetadataToInst(Instruction *I) const { diff --git a/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp b/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp index 64fd5eb..16e1e83 100644 --- a/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp +++ b/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp @@ -17,6 +17,7 @@ #include "llvm/Analysis/ModuleDebugInfoPrinter.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/Passes.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/PassManager.h" #include "llvm/InitializePasses.h" diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp index 0f41115..158405f 100644 --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/Bitstream/BitstreamReader.h" diff --git a/llvm/lib/CodeGen/LiveDebugVariables.cpp b/llvm/lib/CodeGen/LiveDebugVariables.cpp index 6d80613..378a4d6 100644 --- a/llvm/lib/CodeGen/LiveDebugVariables.cpp +++ b/llvm/lib/CodeGen/LiveDebugVariables.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/LexicalScopes.h" #include "llvm/CodeGen/LiveInterval.h" #include "llvm/CodeGen/LiveIntervals.h" diff --git a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp index 331e032..948aad3 100644 --- a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp @@ -15,6 +15,7 @@ #include "InstrEmitter.h" #include "SDNodeDbgValue.h" #include "llvm/ADT/Statistic.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstrBuilder.h" diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index 367803f..93d86b2 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -12,6 +12,7 @@ #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineMemOperand.h" diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp index 6bcf795..ac34658 100644 --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -16,10 +16,11 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/CodeGen/LiveInterval.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/LiveInterval.h" #include "llvm/CodeGen/TargetFrameLowering.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 11839c7..9902f6f 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -14,6 +14,7 @@ #include "llvm/IR/AutoUpgrade.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Triple.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DiagnosticInfo.h" diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index b9fc526..69370d6 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -15,6 +15,7 @@ #include "MetadataImpl.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Function.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" @@ -180,6 +181,7 @@ void DILocation::decodeDiscriminator(unsigned D, unsigned &BD, unsigned &DF, CI = getUnsignedFromPrefixEncoding( getNextComponentInDiscriminator(getNextComponentInDiscriminator(D))); } +dwarf::Tag DINode::getTag() const { return (dwarf::Tag)SubclassData16; } DINode::DIFlags DINode::getFlag(StringRef Flag) { return StringSwitch(Flag) @@ -282,6 +284,7 @@ static bool isCanonical(const MDString *S) { } #endif +dwarf::Tag GenericDINode::getTag() const { return (dwarf::Tag)SubclassData16; } GenericDINode *GenericDINode::getImpl(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps, @@ -340,6 +343,9 @@ void GenericDINode::recalculateHash() { CLASS(Context, Storage, UNWRAP_ARGS(ARGS), OPS), \ Storage, Context.pImpl->CLASS##s) +DISubrange::DISubrange(LLVMContext &C, StorageType Storage, + ArrayRef Ops) + : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, Ops) {} DISubrange *DISubrange::getImpl(LLVMContext &Context, int64_t Count, int64_t Lo, StorageType Storage, bool ShouldCreate) { auto *CountNode = ConstantAsMetadata::get( @@ -450,6 +456,10 @@ DISubrange::BoundType DISubrange::getStride() const { return BoundType(); } +DIGenericSubrange::DIGenericSubrange(LLVMContext &C, StorageType Storage, + ArrayRef Ops) + : DINode(C, DIGenericSubrangeKind, Storage, dwarf::DW_TAG_generic_subrange, + Ops) {} DIGenericSubrange *DIGenericSubrange::getImpl(LLVMContext &Context, Metadata *CountNode, Metadata *LB, @@ -529,6 +539,13 @@ DIGenericSubrange::BoundType DIGenericSubrange::getStride() const { return BoundType(); } +DIEnumerator::DIEnumerator(LLVMContext &C, StorageType Storage, + const APInt &Value, bool IsUnsigned, + ArrayRef Ops) + : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops), + Value(Value) { + SubclassData32 = IsUnsigned; +} DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value, bool IsUnsigned, MDString *Name, StorageType Storage, bool ShouldCreate) { @@ -580,6 +597,36 @@ DIStringType *DIStringType::getImpl(LLVMContext &Context, unsigned Tag, DEFINE_GETIMPL_STORE(DIStringType, (Tag, SizeInBits, AlignInBits, Encoding), Ops); } +DIType *DIDerivedType::getClassType() const { + assert(getTag() == dwarf::DW_TAG_ptr_to_member_type); + return cast_or_null(getExtraData()); +} +uint32_t DIDerivedType::getVBPtrOffset() const { + assert(getTag() == dwarf::DW_TAG_inheritance); + if (auto *CM = cast_or_null(getExtraData())) + if (auto *CI = dyn_cast_or_null(CM->getValue())) + return static_cast(CI->getZExtValue()); + return 0; +} +Constant *DIDerivedType::getStorageOffsetInBits() const { + assert(getTag() == dwarf::DW_TAG_member && isBitField()); + if (auto *C = cast_or_null(getExtraData())) + return C->getValue(); + return nullptr; +} + +Constant *DIDerivedType::getConstant() const { + assert(getTag() == dwarf::DW_TAG_member && isStaticMember()); + if (auto *C = cast_or_null(getExtraData())) + return C->getValue(); + return nullptr; +} +Constant *DIDerivedType::getDiscriminantValue() const { + assert(getTag() == dwarf::DW_TAG_member && !isStaticMember()); + if (auto *C = cast_or_null(getExtraData())) + return C->getValue(); + return nullptr; +} DIDerivedType *DIDerivedType::getImpl( LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File, @@ -701,6 +748,12 @@ DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context, return nullptr; return Context.pImpl->DITypeMap->lookup(&Identifier); } +DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage, + DIFlags Flags, uint8_t CC, + ArrayRef Ops) + : DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0, + 0, 0, 0, Flags, Ops), + CC(CC) {} DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags, uint8_t CC, Metadata *TypeArray, @@ -711,6 +764,12 @@ DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags, DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops); } +DIFile::DIFile(LLVMContext &C, StorageType Storage, + Optional> CS, Optional Src, + ArrayRef Ops) + : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops), + Checksum(CS), Source(Src) {} + // FIXME: Implement this string-enum correspondence with a .def file and macros, // so that the association is explicit rather than implied. static const char *ChecksumKindName[DIFile::CSK_Last] = { @@ -749,6 +808,20 @@ DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename, Source.getValueOr(nullptr)}; DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops); } +DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage, + unsigned SourceLanguage, bool IsOptimized, + unsigned RuntimeVersion, unsigned EmissionKind, + uint64_t DWOId, bool SplitDebugInlining, + bool DebugInfoForProfiling, unsigned NameTableKind, + bool RangesBaseAddress, ArrayRef Ops) + : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops), + SourceLanguage(SourceLanguage), IsOptimized(IsOptimized), + RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), DWOId(DWOId), + SplitDebugInlining(SplitDebugInlining), + DebugInfoForProfiling(DebugInfoForProfiling), + NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) { + assert(Storage != Uniqued); +} DICompileUnit *DICompileUnit::getImpl( LLVMContext &Context, unsigned SourceLanguage, Metadata *File, @@ -827,6 +900,30 @@ const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) { } return nullptr; } +DISubprogram::DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line, + unsigned ScopeLine, unsigned VirtualIndex, + int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, + ArrayRef Ops) + : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops), + Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex), + ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags) { + static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range"); +} +DISubprogram::DISPFlags +DISubprogram::toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, + unsigned Virtuality, bool IsMainSubprogram) { + // We're assuming virtuality is the low-order field. + static_assert(int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) && + int(SPFlagPureVirtual) == + int(dwarf::DW_VIRTUALITY_pure_virtual), + "Virtuality constant mismatch"); + return static_cast( + (Virtuality & SPFlagVirtuality) | + (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) | + (IsDefinition ? SPFlagDefinition : SPFlagZero) | + (IsOptimized ? SPFlagOptimized : SPFlagZero) | + (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero)); +} DISubprogram *DILocalScope::getSubprogram() const { if (auto *Block = dyn_cast(this)) @@ -915,6 +1012,10 @@ bool DISubprogram::describes(const Function *F) const { assert(F && "Invalid function"); return F->getSubprogram() == this; } +DILexicalBlockBase::DILexicalBlockBase(LLVMContext &C, unsigned ID, + StorageType Storage, + ArrayRef Ops) + : DILocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {} DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope, Metadata *File, unsigned Line, @@ -940,6 +1041,10 @@ DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context, DEFINE_GETIMPL_STORE(DILexicalBlockFile, (Discriminator), Ops); } +DINamespace::DINamespace(LLVMContext &Context, StorageType Storage, + bool ExportSymbols, ArrayRef Ops) + : DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops), + ExportSymbols(ExportSymbols) {} DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, bool ExportSymbols, StorageType Storage, bool ShouldCreate) { @@ -950,6 +1055,11 @@ DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope, DEFINE_GETIMPL_STORE(DINamespace, (ExportSymbols), Ops); } +DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage, + unsigned LineNo, ArrayRef Ops) + : DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block, + Ops), + LineNo(LineNo) {} DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope, Metadata *Decl, MDString *Name, Metadata *File, unsigned LineNo, @@ -961,6 +1071,10 @@ DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope, DEFINE_GETIMPL_STORE(DICommonBlock, (LineNo), Ops); } +DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo, + bool IsDecl, ArrayRef Ops) + : DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops), + LineNo(LineNo), IsDecl(IsDecl) {} DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File, Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, @@ -974,6 +1088,13 @@ DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File, IncludePath, APINotesFile}; DEFINE_GETIMPL_STORE(DIModule, (LineNo, IsDecl), Ops); } +DITemplateTypeParameter::DITemplateTypeParameter(LLVMContext &Context, + StorageType Storage, + bool IsDefault, + ArrayRef Ops) + : DITemplateParameter(Context, DITemplateTypeParameterKind, Storage, + dwarf::DW_TAG_template_type_parameter, IsDefault, + Ops) {} DITemplateTypeParameter * DITemplateTypeParameter::getImpl(LLVMContext &Context, MDString *Name, @@ -1039,6 +1160,11 @@ DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops); } +DIVariable::DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, + signed Line, ArrayRef Ops, + uint32_t AlignInBits) + : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line), + AlignInBits(AlignInBits) {} Optional DIVariable::getSizeInBits() const { // This is used by the Verifier so be mindful of broken types. const Metadata *RawType = getRawType(); @@ -1062,6 +1188,9 @@ Optional DIVariable::getSizeInBits() const { return None; } +DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line, + ArrayRef Ops) + : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {} DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, StorageType Storage, bool ShouldCreate) { @@ -1078,6 +1207,12 @@ DIExpression *DIExpression::getImpl(LLVMContext &Context, DEFINE_GETIMPL_LOOKUP(DIExpression, (Elements)); DEFINE_GETIMPL_STORE_NO_OPS(DIExpression, (Elements)); } +bool DIExpression::isEntryValue() const { + return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_LLVM_entry_value; +} +bool DIExpression::startsWithDeref() const { + return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref; +} unsigned DIExpression::ExprOperand::getSize() const { uint64_t Op = getOp(); @@ -1597,6 +1732,11 @@ DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable, Metadata *Ops[] = {Variable, Expression}; DEFINE_GETIMPL_STORE_NO_CONSTRUCTOR_ARGS(DIGlobalVariableExpression, Ops); } +DIObjCProperty::DIObjCProperty(LLVMContext &C, StorageType Storage, + unsigned Line, unsigned Attributes, + ArrayRef Ops) + : DINode(C, DIObjCPropertyKind, Storage, dwarf::DW_TAG_APPLE_property, Ops), + Line(Line), Attributes(Attributes) {} DIObjCProperty *DIObjCProperty::getImpl( LLVMContext &Context, MDString *Name, Metadata *File, unsigned Line, diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index 22c705c..213f252 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/None.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -68,6 +69,21 @@ Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) { return CreateBitCast(Ptr, getInt8PtrTy(PT->getAddressSpace())); } +DebugLoc IRBuilderBase::getCurrentDebugLocation() const { + for (auto &KV : MetadataToCopy) + if (KV.first == LLVMContext::MD_dbg) + return {cast(KV.second)}; + + return {}; +} +void IRBuilderBase::SetInstDebugLocation(Instruction *I) const { + for (const auto &KV : MetadataToCopy) + if (KV.first == LLVMContext::MD_dbg) { + I->setDebugLoc(DebugLoc(KV.second)); + return; + } +} + static CallInst *createCallHelper(Function *Callee, ArrayRef Ops, IRBuilderBase *Builder, const Twine &Name = "", diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp index d1b901e..6f42baf 100644 --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -19,6 +19,7 @@ #include "MCTargetDesc/AArch64AddressingModes.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineRegisterInfo.h" diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp index 703e356..8a79d24 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -21,11 +21,12 @@ #include "MCTargetDesc/AArch64AddressingModes.h" #include "MCTargetDesc/AArch64MCTargetDesc.h" #include "llvm/ADT/Optional.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h" #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" #include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h" -#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" +#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFunction.h" @@ -38,9 +39,9 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicsAArch64.h" #include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" -#include "llvm/IR/IntrinsicsAArch64.h" #include "llvm/Pass.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp index f91f315..2ab0f5b 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp @@ -19,6 +19,7 @@ //===----------------------------------------------------------------------===// #include "AMDGPU.h" +#include "llvm/ADT/Triple.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/Dominators.h" diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp index 46141e6..89e5a91 100644 --- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp +++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp @@ -77,6 +77,7 @@ #include "BPF.h" #include "BPFCORE.h" #include "BPFTargetMachine.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Instruction.h" diff --git a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp index 6dfb7dc3..8c58aae 100644 --- a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp +++ b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp @@ -12,6 +12,7 @@ #include "BPF.h" #include "BPFCORE.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Instruction.h" diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp index 35363bf..991d659 100644 --- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp @@ -14,6 +14,7 @@ #include "RISCV.h" #include "RISCVMachineFunctionInfo.h" #include "RISCVSubtarget.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstrBuilder.h" diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index b512980..844b78c 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -31,6 +31,7 @@ #include "llvm/Analysis/CallGraphSCCPass.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/LazyCallGraph.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 09930ca..769bfa9 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -21,6 +21,7 @@ #include "llvm/Analysis/PostDominators.h" #include "llvm/Analysis/StackSafetyAnalysis.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index d3b60c7..d5e52a9 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -13,6 +13,7 @@ #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Triple.h" #include "llvm/Analysis/EHPersonalities.h" #include "llvm/Analysis/PostDominators.h" #include "llvm/IR/CFG.h" diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 654f0d2..e5efe58 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -78,6 +78,7 @@ #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" diff --git a/llvm/unittests/IR/DebugTypeODRUniquingTest.cpp b/llvm/unittests/IR/DebugTypeODRUniquingTest.cpp index d25f0d3..e3a7fac 100644 --- a/llvm/unittests/IR/DebugTypeODRUniquingTest.cpp +++ b/llvm/unittests/IR/DebugTypeODRUniquingTest.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/LLVMContext.h" #include "gtest/gtest.h" diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index dd973de..d69e428 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/SetVector.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/IRBuilder.h" using namespace mlir;