summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Metadata.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-11-14 01:17:09 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-11-14 01:17:09 +0000
commitf17e740157d17effc513037fd4f86c02deb913f7 (patch)
treed5482733d1f6826ab402eaee7f87b0122f7efe30 /llvm/lib/IR/Metadata.cpp
parent59f34bbb76640673cac808b6c92cbc876aa3be52 (diff)
downloadbcm5719-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.cpp22
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();
}
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud