diff --git a/include/llvm/IR/Metadata.def b/include/llvm/IR/Metadata.def index a8cf28a95bb..a61446be2a4 100644 --- a/include/llvm/IR/Metadata.def +++ b/include/llvm/IR/Metadata.def @@ -49,8 +49,8 @@ HANDLE_METADATA_LEAF(LocalAsMetadata) HANDLE_MDNODE_BRANCH(MDNode) HANDLE_MDNODE_LEAF(MDTuple) HANDLE_MDNODE_LEAF(MDLocation) -HANDLE_MDNODE_BRANCH(DwarfNode) -HANDLE_MDNODE_LEAF(GenericDwarfNode) +HANDLE_MDNODE_BRANCH(DebugNode) +HANDLE_MDNODE_LEAF(GenericDebugNode) #undef HANDLE_METADATA #undef HANDLE_METADATA_LEAF diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index 5a2630b64e8..025ad7f0e52 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -61,7 +61,7 @@ public: enum MetadataKind { MDTupleKind, MDLocationKind, - GenericDwarfNodeKind, + GenericDebugNodeKind, ConstantAsMetadataKind, LocalAsMetadataKind, MDStringKind @@ -867,7 +867,7 @@ public: static bool classof(const Metadata *MD) { return MD->getMetadataID() == MDTupleKind || MD->getMetadataID() == MDLocationKind || - MD->getMetadataID() == GenericDwarfNodeKind; + MD->getMetadataID() == GenericDebugNodeKind; } /// \brief Check whether MDNode is a vtable access. @@ -1025,56 +1025,60 @@ public: } }; -/// \brief Tagged dwarf node. +/// \brief Tagged DWARF-like metadata node. /// -/// A metadata node with a DWARF tag. -class DwarfNode : public MDNode { +/// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*, +/// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's +/// potentially used for non-DWARF output. +class DebugNode : public MDNode { friend class LLVMContextImpl; friend class MDNode; protected: - DwarfNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, + DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag, ArrayRef Ops1, ArrayRef Ops2 = None) : MDNode(C, ID, Storage, Ops1, Ops2) { assert(Tag < 1u << 16); SubclassData16 = Tag; } - ~DwarfNode() {} + ~DebugNode() {} public: unsigned getTag() const { return SubclassData16; } static bool classof(const Metadata *MD) { - return MD->getMetadataID() == GenericDwarfNodeKind; + return MD->getMetadataID() == GenericDebugNodeKind; } }; -/// \brief Generic tagged dwarf node. +/// \brief Generic tagged DWARF-like metadata node. /// -/// A generic metadata node with a DWARF tag that doesn't have special -/// handling. -class GenericDwarfNode : public DwarfNode { +/// An un-specialized DWARF-like metadata node. The first operand is a +/// (possibly empty) null-separated \a MDString header that contains arbitrary +/// fields. The remaining operands are \a dwarf_operands(), and are pointers +/// to other metadata. +class GenericDebugNode : public DebugNode { friend class LLVMContextImpl; friend class MDNode; - GenericDwarfNode(LLVMContext &C, StorageType Storage, unsigned Hash, + GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash, unsigned Tag, ArrayRef Ops1, ArrayRef Ops2) - : DwarfNode(C, GenericDwarfNodeKind, Storage, Tag, Ops1, Ops2) { + : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) { setHash(Hash); } - ~GenericDwarfNode() { dropAllReferences(); } + ~GenericDebugNode() { dropAllReferences(); } void setHash(unsigned Hash) { SubclassData32 = Hash; } void recalculateHash(); - static GenericDwarfNode *getImpl(LLVMContext &Context, unsigned Tag, + static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps, StorageType Storage, bool ShouldCreate = true); - TempGenericDwarfNode cloneImpl() const { + TempGenericDebugNode cloneImpl() const { return getTemporary( getContext(), getTag(), getHeader(), SmallVector(dwarf_op_begin(), dwarf_op_end())); @@ -1083,32 +1087,32 @@ class GenericDwarfNode : public DwarfNode { public: unsigned getHash() const { return SubclassData32; } - static GenericDwarfNode *get(LLVMContext &Context, + static GenericDebugNode *get(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps) { return getImpl(Context, Tag, Header, DwarfOps, Uniqued); } - static GenericDwarfNode *getIfExists(LLVMContext &Context, unsigned Tag, + static GenericDebugNode *getIfExists(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps) { return getImpl(Context, Tag, Header, DwarfOps, Uniqued, /* ShouldCreate */ false); } - static GenericDwarfNode *getDistinct(LLVMContext &Context, unsigned Tag, + static GenericDebugNode *getDistinct(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps) { return getImpl(Context, Tag, Header, DwarfOps, Distinct); } - static TempGenericDwarfNode getTemporary(LLVMContext &Context, unsigned Tag, + static TempGenericDebugNode getTemporary(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps) { - return TempGenericDwarfNode( + return TempGenericDebugNode( getImpl(Context, Tag, Header, DwarfOps, Temporary)); } /// \brief Return a (temporary) clone of this. - TempGenericDwarfNode clone() const { return cloneImpl(); } + TempGenericDebugNode clone() const { return cloneImpl(); } unsigned getTag() const { return SubclassData16; } MDString *getHeader() const { return cast_or_null(getOperand(0)); } @@ -1128,7 +1132,7 @@ public: } static bool classof(const Metadata *MD) { - return MD->getMetadataID() == GenericDwarfNodeKind; + return MD->getMetadataID() == GenericDebugNodeKind; } }; diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 567e935cfa3..118edc15ce6 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -791,7 +791,7 @@ static void WriteMDLocation(const MDLocation *N, const ValueEnumerator &VE, Record.clear(); } -static void WriteGenericDwarfNode(const GenericDwarfNode *, +static void WriteGenericDebugNode(const GenericDebugNode *, const ValueEnumerator &, BitstreamWriter &, SmallVectorImpl &, unsigned) { llvm_unreachable("unimplemented"); @@ -843,7 +843,7 @@ static void WriteModuleMetadata(const Module *M, } unsigned MDTupleAbbrev = 0; - unsigned GenericDwarfNodeAbbrev = 0; + unsigned GenericDebugNodeAbbrev = 0; SmallVector Record; for (const Metadata *MD : MDs) { if (const MDNode *N = dyn_cast(MD)) { diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 56355cc913c..d52ac87c983 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1286,7 +1286,7 @@ raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { } } // end namespace -static void writeGenericDwarfNode(raw_ostream &, const GenericDwarfNode *, +static void writeGenericDebugNode(raw_ostream &, const GenericDebugNode *, TypePrinting *, SlotTracker *, const Module *) { llvm_unreachable("Unimplemented write"); diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index 4d3fa4462a3..a009262f80e 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -284,44 +284,44 @@ struct MDLocationInfo { } }; -/// \brief DenseMapInfo for GenericDwarfNode. -struct GenericDwarfNodeInfo { +/// \brief DenseMapInfo for GenericDebugNode. +struct GenericDebugNodeInfo { struct KeyTy : MDNodeOpsKey { unsigned Tag; MDString *Header; KeyTy(unsigned Tag, MDString *Header, ArrayRef DwarfOps) : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} - KeyTy(GenericDwarfNode *N) + KeyTy(GenericDebugNode *N) : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {} - bool operator==(const GenericDwarfNode *RHS) const { + bool operator==(const GenericDebugNode *RHS) const { if (RHS == getEmptyKey() || RHS == getTombstoneKey()) return false; return Tag == RHS->getTag() && Header == RHS->getHeader() && compareOps(RHS, 1); } - static unsigned calculateHash(GenericDwarfNode *N) { + static unsigned calculateHash(GenericDebugNode *N) { return MDNodeOpsKey::calculateHash(N, 1); } }; - static inline GenericDwarfNode *getEmptyKey() { - return DenseMapInfo::getEmptyKey(); + static inline GenericDebugNode *getEmptyKey() { + return DenseMapInfo::getEmptyKey(); } - static inline GenericDwarfNode *getTombstoneKey() { - return DenseMapInfo::getTombstoneKey(); + static inline GenericDebugNode *getTombstoneKey() { + return DenseMapInfo::getTombstoneKey(); } static unsigned getHashValue(const KeyTy &Key) { return hash_combine(Key.getHash(), Key.Tag, Key.Header); } - static unsigned getHashValue(const GenericDwarfNode *U) { + static unsigned getHashValue(const GenericDebugNode *U) { return hash_combine(U->getHash(), U->getTag(), U->getHeader()); } - static bool isEqual(const KeyTy &LHS, const GenericDwarfNode *RHS) { + static bool isEqual(const KeyTy &LHS, const GenericDebugNode *RHS) { return LHS == RHS; } - static bool isEqual(const GenericDwarfNode *LHS, - const GenericDwarfNode *RHS) { + static bool isEqual(const GenericDebugNode *LHS, + const GenericDebugNode *RHS) { return LHS == RHS; } }; @@ -358,7 +358,7 @@ public: DenseSet MDTuples; DenseSet MDLocations; - DenseSet GenericDwarfNodes; + DenseSet GenericDebugNodes; // MDNodes may be uniqued or not uniqued. When they're not uniqued, they // aren't in the MDNodeSet, but they're still shared between objects, so no diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index fac9268f786..e55d287e63a 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -541,8 +541,8 @@ void MDTuple::recalculateHash() { setHash(MDTupleInfo::KeyTy::calculateHash(this)); } -void GenericDwarfNode::recalculateHash() { - setHash(GenericDwarfNodeInfo::KeyTy::calculateHash(this)); +void GenericDebugNode::recalculateHash() { + setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this)); } void MDNode::dropAllReferences() { @@ -759,7 +759,7 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line, Storage, Context.pImpl->MDLocations); } -GenericDwarfNode *GenericDwarfNode::getImpl(LLVMContext &Context, unsigned Tag, +GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag, MDString *Header, ArrayRef DwarfOps, StorageType Storage, @@ -770,8 +770,8 @@ GenericDwarfNode *GenericDwarfNode::getImpl(LLVMContext &Context, unsigned Tag, unsigned Hash = 0; if (Storage == Uniqued) { - GenericDwarfNodeInfo::KeyTy Key(Tag, Header, DwarfOps); - if (auto *N = getUniqued(Context.pImpl->GenericDwarfNodes, Key)) + GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps); + if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key)) return N; if (!ShouldCreate) return nullptr; @@ -781,9 +781,9 @@ GenericDwarfNode *GenericDwarfNode::getImpl(LLVMContext &Context, unsigned Tag, } Metadata *PreOps[] = {Header}; - return storeImpl(new (DwarfOps.size() + 1) GenericDwarfNode( + return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode( Context, Storage, Hash, Tag, PreOps, DwarfOps), - Storage, Context.pImpl->GenericDwarfNodes); + Storage, Context.pImpl->GenericDebugNodes); } void MDNode::deleteTemporary(MDNode *N) { diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index b2205776f64..39692d6945c 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -572,13 +572,13 @@ TEST_F(MDLocationTest, getTemporary) { EXPECT_FALSE(L->isResolved()); } -typedef MetadataTest GenericDwarfNodeTest; +typedef MetadataTest GenericDebugNodeTest; -TEST_F(GenericDwarfNodeTest, get) { +TEST_F(GenericDebugNodeTest, get) { auto *Header = MDString::get(Context, "header"); auto *Empty = MDNode::get(Context, None); Metadata *Ops1[] = {Empty}; - auto *N = GenericDwarfNode::get(Context, 15, Header, Ops1); + auto *N = GenericDebugNode::get(Context, 15, Header, Ops1); EXPECT_EQ(15u, N->getTag()); EXPECT_EQ(2u, N->getNumOperands()); EXPECT_EQ(Header, N->getHeader()); @@ -588,7 +588,7 @@ TEST_F(GenericDwarfNodeTest, get) { EXPECT_EQ(Empty, N->getOperand(1)); ASSERT_TRUE(N->isUniqued()); - EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops1)); + EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1)); N->replaceOperandWith(1, nullptr); EXPECT_EQ(15u, N->getTag()); @@ -597,21 +597,21 @@ TEST_F(GenericDwarfNodeTest, get) { ASSERT_TRUE(N->isUniqued()); Metadata *Ops2[] = {nullptr}; - EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops2)); + EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops2)); N->replaceDwarfOperandWith(0, Empty); EXPECT_EQ(15u, N->getTag()); EXPECT_EQ(Header, N->getHeader()); EXPECT_EQ(Empty, N->getDwarfOperand(0)); ASSERT_TRUE(N->isUniqued()); - EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops1)); + EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1)); } -TEST_F(GenericDwarfNodeTest, getEmptyHeader) { +TEST_F(GenericDebugNodeTest, getEmptyHeader) { // Canonicalize !"" to null. auto *Header = MDString::get(Context, ""); EXPECT_NE(nullptr, Header); - auto *N = GenericDwarfNode::get(Context, 15, Header, None); + auto *N = GenericDebugNode::get(Context, 15, Header, None); EXPECT_EQ(nullptr, N->getHeader()); }