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
This commit is contained in:
Duncan P. N. Exon Smith 2015-01-22 23:10:55 +00:00
parent cee1699e9f
commit a791aea5ae
4 changed files with 22 additions and 22 deletions

View File

@ -1073,7 +1073,7 @@ class GenericDebugNode : public DebugNode {
void recalculateHash(); void recalculateHash();
static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag, static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
MDString *Header, StringRef Header,
ArrayRef<Metadata *> DwarfOps, ArrayRef<Metadata *> DwarfOps,
StorageType Storage, StorageType Storage,
bool ShouldCreate = true); bool ShouldCreate = true);
@ -1087,25 +1087,24 @@ class GenericDebugNode : public DebugNode {
public: public:
unsigned getHash() const { return SubclassData32; } unsigned getHash() const { return SubclassData32; }
static GenericDebugNode *get(LLVMContext &Context, static GenericDebugNode *get(LLVMContext &Context, unsigned Tag,
unsigned Tag, StringRef Header,
MDString *Header,
ArrayRef<Metadata *> DwarfOps) { ArrayRef<Metadata *> DwarfOps) {
return getImpl(Context, Tag, Header, DwarfOps, Uniqued); return getImpl(Context, Tag, Header, DwarfOps, Uniqued);
} }
static GenericDebugNode *getIfExists(LLVMContext &Context, unsigned Tag, static GenericDebugNode *getIfExists(LLVMContext &Context, unsigned Tag,
MDString *Header, StringRef Header,
ArrayRef<Metadata *> DwarfOps) { ArrayRef<Metadata *> DwarfOps) {
return getImpl(Context, Tag, Header, DwarfOps, Uniqued, return getImpl(Context, Tag, Header, DwarfOps, Uniqued,
/* ShouldCreate */ false); /* ShouldCreate */ false);
} }
static GenericDebugNode *getDistinct(LLVMContext &Context, unsigned Tag, static GenericDebugNode *getDistinct(LLVMContext &Context, unsigned Tag,
MDString *Header, StringRef Header,
ArrayRef<Metadata *> DwarfOps) { ArrayRef<Metadata *> DwarfOps) {
return getImpl(Context, Tag, Header, DwarfOps, Distinct); return getImpl(Context, Tag, Header, DwarfOps, Distinct);
} }
static TempGenericDebugNode getTemporary(LLVMContext &Context, unsigned Tag, static TempGenericDebugNode getTemporary(LLVMContext &Context, unsigned Tag,
MDString *Header, StringRef Header,
ArrayRef<Metadata *> DwarfOps) { ArrayRef<Metadata *> DwarfOps) {
return TempGenericDebugNode( return TempGenericDebugNode(
getImpl(Context, Tag, Header, DwarfOps, Temporary)); getImpl(Context, Tag, Header, DwarfOps, Temporary));
@ -1115,7 +1114,11 @@ public:
TempGenericDebugNode clone() const { return cloneImpl(); } TempGenericDebugNode clone() const { return cloneImpl(); }
unsigned getTag() const { return SubclassData16; } unsigned getTag() const { return SubclassData16; }
MDString *getHeader() const { return cast_or_null<MDString>(getOperand(0)); } StringRef getHeader() const {
if (auto *S = cast_or_null<MDString>(getOperand(0)))
return S->getString();
return StringRef();
}
op_iterator dwarf_op_begin() const { return op_begin() + 1; } op_iterator dwarf_op_begin() const { return op_begin() + 1; }
op_iterator dwarf_op_end() const { return op_end(); } op_iterator dwarf_op_end() const { return op_end(); }

View File

@ -288,8 +288,8 @@ struct MDLocationInfo {
struct GenericDebugNodeInfo { struct GenericDebugNodeInfo {
struct KeyTy : MDNodeOpsKey { struct KeyTy : MDNodeOpsKey {
unsigned Tag; unsigned Tag;
MDString *Header; StringRef Header;
KeyTy(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps) KeyTy(unsigned Tag, StringRef Header, ArrayRef<Metadata *> DwarfOps)
: MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
KeyTy(GenericDebugNode *N) KeyTy(GenericDebugNode *N)
: MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {} : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {}

View File

@ -760,14 +760,10 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
} }
GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag, GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
MDString *Header, StringRef Header,
ArrayRef<Metadata *> DwarfOps, ArrayRef<Metadata *> DwarfOps,
StorageType Storage, StorageType Storage,
bool ShouldCreate) { bool ShouldCreate) {
// Canonicalize empty string to a nullptr.
if (Header && Header->getString().empty())
Header = nullptr;
unsigned Hash = 0; unsigned Hash = 0;
if (Storage == Uniqued) { if (Storage == Uniqued) {
GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps); GenericDebugNodeInfo::KeyTy Key(Tag, Header, DwarfOps);
@ -780,7 +776,9 @@ GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
} }
Metadata *PreOps[] = {Header}; // Use a nullptr for empty headers.
Metadata *PreOps[] = {Header.empty() ? nullptr
: MDString::get(Context, Header)};
return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode( return storeImpl(new (DwarfOps.size() + 1) GenericDebugNode(
Context, Storage, Hash, Tag, PreOps, DwarfOps), Context, Storage, Hash, Tag, PreOps, DwarfOps),
Storage, Context.pImpl->GenericDebugNodes); Storage, Context.pImpl->GenericDebugNodes);

View File

@ -575,14 +575,14 @@ TEST_F(MDLocationTest, getTemporary) {
typedef MetadataTest GenericDebugNodeTest; typedef MetadataTest GenericDebugNodeTest;
TEST_F(GenericDebugNodeTest, get) { TEST_F(GenericDebugNodeTest, get) {
auto *Header = MDString::get(Context, "header"); StringRef Header = "header";
auto *Empty = MDNode::get(Context, None); auto *Empty = MDNode::get(Context, None);
Metadata *Ops1[] = {Empty}; Metadata *Ops1[] = {Empty};
auto *N = GenericDebugNode::get(Context, 15, Header, Ops1); auto *N = GenericDebugNode::get(Context, 15, Header, Ops1);
EXPECT_EQ(15u, N->getTag()); EXPECT_EQ(15u, N->getTag());
EXPECT_EQ(2u, N->getNumOperands()); EXPECT_EQ(2u, N->getNumOperands());
EXPECT_EQ(Header, N->getHeader()); EXPECT_EQ(Header, N->getHeader());
EXPECT_EQ(Header, N->getOperand(0)); EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0));
EXPECT_EQ(1u, N->getNumDwarfOperands()); EXPECT_EQ(1u, N->getNumDwarfOperands());
EXPECT_EQ(Empty, N->getDwarfOperand(0)); EXPECT_EQ(Empty, N->getDwarfOperand(0));
EXPECT_EQ(Empty, N->getOperand(1)); EXPECT_EQ(Empty, N->getOperand(1));
@ -609,10 +609,9 @@ TEST_F(GenericDebugNodeTest, get) {
TEST_F(GenericDebugNodeTest, getEmptyHeader) { TEST_F(GenericDebugNodeTest, getEmptyHeader) {
// Canonicalize !"" to null. // Canonicalize !"" to null.
auto *Header = MDString::get(Context, ""); auto *N = GenericDebugNode::get(Context, 15, StringRef(), None);
EXPECT_NE(nullptr, Header); EXPECT_EQ(StringRef(), N->getHeader());
auto *N = GenericDebugNode::get(Context, 15, Header, None); EXPECT_EQ(nullptr, N->getOperand(0));
EXPECT_EQ(nullptr, N->getHeader());
} }
typedef MetadataTest MetadataAsValueTest; typedef MetadataTest MetadataAsValueTest;