diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-11-14 01:17:09 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-11-14 01:17:09 +0000 |
commit | f17e740157d17effc513037fd4f86c02deb913f7 (patch) | |
tree | d5482733d1f6826ab402eaee7f87b0122f7efe30 /llvm/lib/IR/Metadata.cpp | |
parent | 59f34bbb76640673cac808b6c92cbc876aa3be52 (diff) | |
download | bcm5719-llvm-f17e740157d17effc513037fd4f86c02deb913f7.tar.gz bcm5719-llvm-f17e740157d17effc513037fd4f86c02deb913f7.zip |
IR: Rewrite uniquing and creation of MDString
Stop using `Value::getName()` to get the string behind an `MDString`.
Switch to `StringMapEntry<MDString>` so that we can find the string by
its coallocation.
This is part of PR21532.
llvm-svn: 221960
Diffstat (limited to 'llvm/lib/IR/Metadata.cpp')
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 8d616cfb0d6..bc9682976b8 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -37,13 +37,21 @@ MDString::MDString(LLVMContext &C) : Value(Type::getMetadataTy(C), Value::MDStringVal) {} MDString *MDString::get(LLVMContext &Context, StringRef Str) { - LLVMContextImpl *pImpl = Context.pImpl; - StringMapEntry<Value*> &Entry = - pImpl->MDStringCache.GetOrCreateValue(Str); - Value *&S = Entry.getValue(); - if (!S) S = new MDString(Context); - S->setValueName(&Entry); - return cast<MDString>(S); + auto &Store = Context.pImpl->MDStringCache; + auto I = Store.find(Str); + if (I != Store.end()) + return &I->second; + + auto *Entry = + StringMapEntry<MDString>::Create(Str, Store.getAllocator(), Context); + bool WasInserted = Store.insert(Entry); + (void)WasInserted; + assert(WasInserted && "Expected entry to be inserted"); + return &Entry->second; +} + +StringRef MDString::getString() const { + return StringMapEntry<MDString>::GetStringMapEntryFromValue(*this).first(); } //===----------------------------------------------------------------------===// |