llvm.org GIT mirror llvm / a791aea
IR: Change GenericDwarfNode::getHeader() to StringRef Simplify the API to use a `StringRef` directly rather than exposing the `MDString` bits underneath. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226876 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
4 changed file(s) with 22 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
10721072 void recalculateHash();
10731073
10741074 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
1075 MDString *Header,
1075 StringRef Header,
10761076 ArrayRef DwarfOps,
10771077 StorageType Storage,
10781078 bool ShouldCreate = true);
10861086 public:
10871087 unsigned getHash() const { return SubclassData32; }
10881088
1089 static GenericDebugNode *get(LLVMContext &Context,
1090 unsigned Tag,
1091 MDString *Header,
1089 static GenericDebugNode *get(LLVMContext &Context, unsigned Tag,
1090 StringRef Header,
10921091 ArrayRef DwarfOps) {
10931092 return getImpl(Context, Tag, Header, DwarfOps, Uniqued);
10941093 }
10951094 static GenericDebugNode *getIfExists(LLVMContext &Context, unsigned Tag,
1096 MDString *Header,
1095 StringRef Header,
10971096 ArrayRef DwarfOps) {
10981097 return getImpl(Context, Tag, Header, DwarfOps, Uniqued,
10991098 /* ShouldCreate */ false);
11001099 }
11011100 static GenericDebugNode *getDistinct(LLVMContext &Context, unsigned Tag,
1102 MDString *Header,
1101 StringRef Header,
11031102 ArrayRef DwarfOps) {
11041103 return getImpl(Context, Tag, Header, DwarfOps, Distinct);
11051104 }
11061105 static TempGenericDebugNode getTemporary(LLVMContext &Context, unsigned Tag,
1107 MDString *Header,
1106 StringRef Header,
11081107 ArrayRef DwarfOps) {
11091108 return TempGenericDebugNode(
11101109 getImpl(Context, Tag, Header, DwarfOps, Temporary));
11141113 TempGenericDebugNode clone() const { return cloneImpl(); }
11151114
11161115 unsigned getTag() const { return SubclassData16; }
1117 MDString *getHeader() const { return cast_or_null(getOperand(0)); }
1116 StringRef getHeader() const {
1117 if (auto *S = cast_or_null(getOperand(0)))
1118 return S->getString();
1119 return StringRef();
1120 }
11181121
11191122 op_iterator dwarf_op_begin() const { return op_begin() + 1; }
11201123 op_iterator dwarf_op_end() const { return op_end(); }
287287 struct GenericDebugNodeInfo {
288288 struct KeyTy : MDNodeOpsKey {
289289 unsigned Tag;
290 MDString *Header;
291 KeyTy(unsigned Tag, MDString *Header, ArrayRef DwarfOps)
290 StringRef Header;
291 KeyTy(unsigned Tag, StringRef Header, ArrayRef DwarfOps)
292292 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
293293 KeyTy(GenericDebugNode *N)
294294 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {}
759759 }
760760
761761 GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
762 MDString *Header,
762 StringRef Header,
763763 ArrayRef DwarfOps,
764764 StorageType Storage,
765765 bool ShouldCreate) {
766 // Canonicalize empty string to a nullptr.
767 if (Header && Header->getString().empty())
768 Header = nullptr;
769
770766 unsigned Hash = 0;
771767 if (Storage == Uniqued) {
772768 GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
779775 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
780776 }
781777
782 Metadata *PreOps[] = {Header};
778 // Use a nullptr for empty headers.
779 Metadata *PreOps[] = {Header.empty() ? nullptr
780 : MDString::get(Context, Header)};
783781 return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
784782 Context, Storage, Hash, Tag, PreOps, DwarfOps),
785783 Storage, Context.pImpl->GenericDebugNodes);
574574 typedef MetadataTest GenericDebugNodeTest;
575575
576576 TEST_F(GenericDebugNodeTest, get) {
577 auto *Header = MDString::get(Context, "header");
577 StringRef Header = "header";
578578 auto *Empty = MDNode::get(Context, None);
579579 Metadata *Ops1[] = {Empty};
580580 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());
584 EXPECT_EQ(Header, N->getOperand(0));
584 EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0));
585585 EXPECT_EQ(1u, N->getNumDwarfOperands());
586586 EXPECT_EQ(Empty, N->getDwarfOperand(0));
587587 EXPECT_EQ(Empty, N->getOperand(1));
608608
609609 TEST_F(GenericDebugNodeTest, getEmptyHeader) {
610610 // Canonicalize !"" to null.
611 auto *Header = MDString::get(Context, "");
612 EXPECT_NE(nullptr, Header);
613 auto *N = GenericDebugNode::get(Context, 15, Header, None);
614 EXPECT_EQ(nullptr, N->getHeader());
611 auto *N = GenericDebugNode::get(Context, 15, StringRef(), None);
612 EXPECT_EQ(StringRef(), N->getHeader());
613 EXPECT_EQ(nullptr, N->getOperand(0));
615614 }
616615
617616 typedef MetadataTest MetadataAsValueTest;