llvm.org GIT mirror llvm / cee1699
IR: DwarfNode => DebugNode, NFC These things are potentially used for non-DWARF data (see the discussion in PR22235), so take the `Dwarf` out of the name. Since the new name gives fewer clues, update the doxygen to properly describe what they are. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226874 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
7 changed file(s) with 73 addition(s) and 69 deletion(s). Raw diff Collapse all Expand all
4848 HANDLE_MDNODE_BRANCH(MDNode)
4949 HANDLE_MDNODE_LEAF(MDTuple)
5050 HANDLE_MDNODE_LEAF(MDLocation)
51 HANDLE_MDNODE_BRANCH(DwarfNode)
52 HANDLE_MDNODE_LEAF(GenericDwarfNode)
51 HANDLE_MDNODE_BRANCH(DebugNode)
52 HANDLE_MDNODE_LEAF(GenericDebugNode)
5353
5454 #undef HANDLE_METADATA
5555 #undef HANDLE_METADATA_LEAF
6060 enum MetadataKind {
6161 MDTupleKind,
6262 MDLocationKind,
63 GenericDwarfNodeKind,
63 GenericDebugNodeKind,
6464 ConstantAsMetadataKind,
6565 LocalAsMetadataKind,
6666 MDStringKind
866866 static bool classof(const Metadata *MD) {
867867 return MD->getMetadataID() == MDTupleKind ||
868868 MD->getMetadataID() == MDLocationKind ||
869 MD->getMetadataID() == GenericDwarfNodeKind;
869 MD->getMetadataID() == GenericDebugNodeKind;
870870 }
871871
872872 /// \brief Check whether MDNode is a vtable access.
10241024 }
10251025 };
10261026
1027 /// \brief Tagged dwarf node.
1028 ///
1029 /// A metadata node with a DWARF tag.
1030 class DwarfNode : public MDNode {
1027 /// \brief Tagged DWARF-like metadata node.
1028 ///
1029 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
1030 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
1031 /// potentially used for non-DWARF output.
1032 class DebugNode : public MDNode {
10311033 friend class LLVMContextImpl;
10321034 friend class MDNode;
10331035
10341036 protected:
1035 DwarfNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1037 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
10361038 ArrayRef Ops1, ArrayRef Ops2 = None)
10371039 : MDNode(C, ID, Storage, Ops1, Ops2) {
10381040 assert(Tag < 1u << 16);
10391041 SubclassData16 = Tag;
10401042 }
1041 ~DwarfNode() {}
1043 ~DebugNode() {}
10421044
10431045 public:
10441046 unsigned getTag() const { return SubclassData16; }
10451047
10461048 static bool classof(const Metadata *MD) {
1047 return MD->getMetadataID() == GenericDwarfNodeKind;
1048 }
1049 };
1050
1051 /// \brief Generic tagged dwarf node.
1052 ///
1053 /// A generic metadata node with a DWARF tag that doesn't have special
1054 /// handling.
1055 class GenericDwarfNode : public DwarfNode {
1049 return MD->getMetadataID() == GenericDebugNodeKind;
1050 }
1051 };
1052
1053 /// \brief Generic tagged DWARF-like metadata node.
1054 ///
1055 /// An un-specialized DWARF-like metadata node. The first operand is a
1056 /// (possibly empty) null-separated \a MDString header that contains arbitrary
1057 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
1058 /// to other metadata.
1059 class GenericDebugNode : public DebugNode {
10561060 friend class LLVMContextImpl;
10571061 friend class MDNode;
10581062
1059 GenericDwarfNode(LLVMContext &C, StorageType Storage, unsigned Hash,
1063 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
10601064 unsigned Tag, ArrayRef Ops1,
10611065 ArrayRef Ops2)
1062 : DwarfNode(C, GenericDwarfNodeKind, Storage, Tag, Ops1, Ops2) {
1066 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
10631067 setHash(Hash);
10641068 }
1065 ~GenericDwarfNode() { dropAllReferences(); }
1069 ~GenericDebugNode() { dropAllReferences(); }
10661070
10671071 void setHash(unsigned Hash) { SubclassData32 = Hash; }
10681072 void recalculateHash();
10691073
1070 static GenericDwarfNode *getImpl(LLVMContext &Context, unsigned Tag,
1074 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
10711075 MDString *Header,
10721076 ArrayRef DwarfOps,
10731077 StorageType Storage,
10741078 bool ShouldCreate = true);
10751079
1076 TempGenericDwarfNode cloneImpl() const {
1080 TempGenericDebugNode cloneImpl() const {
10771081 return getTemporary(
10781082 getContext(), getTag(), getHeader(),
10791083 SmallVector(dwarf_op_begin(), dwarf_op_end()));
10821086 public:
10831087 unsigned getHash() const { return SubclassData32; }
10841088
1085 static GenericDwarfNode *get(LLVMContext &Context,
1089 static GenericDebugNode *get(LLVMContext &Context,
10861090 unsigned Tag,
10871091 MDString *Header,
10881092 ArrayRef DwarfOps) {
10891093 return getImpl(Context, Tag, Header, DwarfOps, Uniqued);
10901094 }
1091 static GenericDwarfNode *getIfExists(LLVMContext &Context, unsigned Tag,
1095 static GenericDebugNode *getIfExists(LLVMContext &Context, unsigned Tag,
10921096 MDString *Header,
10931097 ArrayRef DwarfOps) {
10941098 return getImpl(Context, Tag, Header, DwarfOps, Uniqued,
10951099 /* ShouldCreate */ false);
10961100 }
1097 static GenericDwarfNode *getDistinct(LLVMContext &Context, unsigned Tag,
1101 static GenericDebugNode *getDistinct(LLVMContext &Context, unsigned Tag,
10981102 MDString *Header,
10991103 ArrayRef DwarfOps) {
11001104 return getImpl(Context, Tag, Header, DwarfOps, Distinct);
11011105 }
1102 static TempGenericDwarfNode getTemporary(LLVMContext &Context, unsigned Tag,
1106 static TempGenericDebugNode getTemporary(LLVMContext &Context, unsigned Tag,
11031107 MDString *Header,
11041108 ArrayRef DwarfOps) {
1105 return TempGenericDwarfNode(
1109 return TempGenericDebugNode(
11061110 getImpl(Context, Tag, Header, DwarfOps, Temporary));
11071111 }
11081112
11091113 /// \brief Return a (temporary) clone of this.
1110 TempGenericDwarfNode clone() const { return cloneImpl(); }
1114 TempGenericDebugNode clone() const { return cloneImpl(); }
11111115
11121116 unsigned getTag() const { return SubclassData16; }
11131117 MDString *getHeader() const { return cast_or_null(getOperand(0)); }
11271131 }
11281132
11291133 static bool classof(const Metadata *MD) {
1130 return MD->getMetadataID() == GenericDwarfNodeKind;
1134 return MD->getMetadataID() == GenericDebugNodeKind;
11311135 }
11321136 };
11331137
790790 Record.clear();
791791 }
792792
793 static void WriteGenericDwarfNode(const GenericDwarfNode *,
793 static void WriteGenericDebugNode(const GenericDebugNode *,
794794 const ValueEnumerator &, BitstreamWriter &,
795795 SmallVectorImpl &, unsigned) {
796796 llvm_unreachable("unimplemented");
842842 }
843843
844844 unsigned MDTupleAbbrev = 0;
845 unsigned GenericDwarfNodeAbbrev = 0;
845 unsigned GenericDebugNodeAbbrev = 0;
846846 SmallVector Record;
847847 for (const Metadata *MD : MDs) {
848848 if (const MDNode *N = dyn_cast(MD)) {
12851285 }
12861286 } // end namespace
12871287
1288 static void writeGenericDwarfNode(raw_ostream &, const GenericDwarfNode *,
1288 static void writeGenericDebugNode(raw_ostream &, const GenericDebugNode *,
12891289 TypePrinting *, SlotTracker *,
12901290 const Module *) {
12911291 llvm_unreachable("Unimplemented write");
283283 }
284284 };
285285
286 /// \brief DenseMapInfo for GenericDwarfNode.
287 struct GenericDwarfNodeInfo {
286 /// \brief DenseMapInfo for GenericDebugNode.
287 struct GenericDebugNodeInfo {
288288 struct KeyTy : MDNodeOpsKey {
289289 unsigned Tag;
290290 MDString *Header;
291291 KeyTy(unsigned Tag, MDString *Header, ArrayRef DwarfOps)
292292 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
293 KeyTy(GenericDwarfNode *N)
293 KeyTy(GenericDebugNode *N)
294294 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {}
295295
296 bool operator==(const GenericDwarfNode *RHS) const {
296 bool operator==(const GenericDebugNode *RHS) const {
297297 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
298298 return false;
299299 return Tag == RHS->getTag() && Header == RHS->getHeader() &&
300300 compareOps(RHS, 1);
301301 }
302302
303 static unsigned calculateHash(GenericDwarfNode *N) {
303 static unsigned calculateHash(GenericDebugNode *N) {
304304 return MDNodeOpsKey::calculateHash(N, 1);
305305 }
306306 };
307 static inline GenericDwarfNode *getEmptyKey() {
308 return DenseMapInfo::getEmptyKey();
309 }
310 static inline GenericDwarfNode *getTombstoneKey() {
311 return DenseMapInfo::getTombstoneKey();
307 static inline GenericDebugNode *getEmptyKey() {
308 return DenseMapInfo::getEmptyKey();
309 }
310 static inline GenericDebugNode *getTombstoneKey() {
311 return DenseMapInfo::getTombstoneKey();
312312 }
313313 static unsigned getHashValue(const KeyTy &Key) {
314314 return hash_combine(Key.getHash(), Key.Tag, Key.Header);
315315 }
316 static unsigned getHashValue(const GenericDwarfNode *U) {
316 static unsigned getHashValue(const GenericDebugNode *U) {
317317 return hash_combine(U->getHash(), U->getTag(), U->getHeader());
318318 }
319 static bool isEqual(const KeyTy &LHS, const GenericDwarfNode *RHS) {
320 return LHS == RHS;
321 }
322 static bool isEqual(const GenericDwarfNode *LHS,
323 const GenericDwarfNode *RHS) {
319 static bool isEqual(const KeyTy &LHS, const GenericDebugNode *RHS) {
320 return LHS == RHS;
321 }
322 static bool isEqual(const GenericDebugNode *LHS,
323 const GenericDebugNode *RHS) {
324324 return LHS == RHS;
325325 }
326326 };
357357
358358 DenseSet MDTuples;
359359 DenseSet MDLocations;
360 DenseSetwarfNode *, GenericDwarfNodeInfo> GenericDwarfNodes;
360 DenseSetebugNode *, GenericDebugNodeInfo> GenericDebugNodes;
361361
362362 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
363363 // aren't in the MDNodeSet, but they're still shared between objects, so no
540540 setHash(MDTupleInfo::KeyTy::calculateHash(this));
541541 }
542542
543 void GenericDwarfNode::recalculateHash() {
544 setHash(GenericDwarfNodeInfo::KeyTy::calculateHash(this));
543 void GenericDebugNode::recalculateHash() {
544 setHash(GenericDebugNodeInfo::KeyTy::calculateHash(this));
545545 }
546546
547547 void MDNode::dropAllReferences() {
758758 Storage, Context.pImpl->MDLocations);
759759 }
760760
761 GenericDwarfNode *GenericDwarfNode::getImpl(LLVMContext &Context, unsigned Tag,
761 GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
762762 MDString *Header,
763763 ArrayRef DwarfOps,
764764 StorageType Storage,
769769
770770 unsigned Hash = 0;
771771 if (Storage == Uniqued) {
772 GenericDwarfNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
773 if (auto *N = getUniqued(Context.pImpl->GenericDwarfNodes, Key))
772 GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
773 if (auto *N = getUniqued(Context.pImpl->GenericDebugNodes, Key))
774774 return N;
775775 if (!ShouldCreate)
776776 return nullptr;
780780 }
781781
782782 Metadata *PreOps[] = {Header};
783 return storeImpl(new (DwarfOps.size() + 1) GenericDwarfNode(
783 return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
784784 Context, Storage, Hash, Tag, PreOps, DwarfOps),
785 Storage, Context.pImpl->GenericDwarfNodes);
785 Storage, Context.pImpl->GenericDebugNodes);
786786 }
787787
788788 void MDNode::deleteTemporary(MDNode *N) {
571571 EXPECT_FALSE(L->isResolved());
572572 }
573573
574 typedef MetadataTest GenericDwarfNodeTest;
575
576 TEST_F(GenericDwarfNodeTest, get) {
574 typedef MetadataTest GenericDebugNodeTest;
575
576 TEST_F(GenericDebugNodeTest, get) {
577577 auto *Header = MDString::get(Context, "header");
578578 auto *Empty = MDNode::get(Context, None);
579579 Metadata *Ops1[] = {Empty};
580 auto *N = GenericDwarfNode::get(Context, 15, Header, Ops1);
580 auto *N = GenericDebugNode::get(Context, 15, Header, Ops1);
581581 EXPECT_EQ(15u, N->getTag());
582582 EXPECT_EQ(2u, N->getNumOperands());
583583 EXPECT_EQ(Header, N->getHeader());
587587 EXPECT_EQ(Empty, N->getOperand(1));
588588 ASSERT_TRUE(N->isUniqued());
589589
590 EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops1));
590 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1));
591591
592592 N->replaceOperandWith(1, nullptr);
593593 EXPECT_EQ(15u, N->getTag());
596596 ASSERT_TRUE(N->isUniqued());
597597
598598 Metadata *Ops2[] = {nullptr};
599 EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops2));
599 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops2));
600600
601601 N->replaceDwarfOperandWith(0, Empty);
602602 EXPECT_EQ(15u, N->getTag());
603603 EXPECT_EQ(Header, N->getHeader());
604604 EXPECT_EQ(Empty, N->getDwarfOperand(0));
605605 ASSERT_TRUE(N->isUniqued());
606 EXPECT_EQ(N, GenericDwarfNode::get(Context, 15, Header, Ops1));
607 }
608
609 TEST_F(GenericDwarfNodeTest, getEmptyHeader) {
606 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1));
607 }
608
609 TEST_F(GenericDebugNodeTest, getEmptyHeader) {
610610 // Canonicalize !"" to null.
611611 auto *Header = MDString::get(Context, "");
612612 EXPECT_NE(nullptr, Header);
613 auto *N = GenericDwarfNode::get(Context, 15, Header, None);
613 auto *N = GenericDebugNode::get(Context, 15, Header, None);
614614 EXPECT_EQ(nullptr, N->getHeader());
615615 }
616616