summaryrefslogtreecommitdiffstats
path: root/llvm/lib
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
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')
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp2
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h2
-rw-r--r--llvm/lib/IR/Metadata.cpp22
3 files changed, 17 insertions, 9 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 09bf6b123a9..df3449d12c8 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -135,7 +135,7 @@ LLVMContextImpl::~LLVMContextImpl() {
"Destroying all MDNodes didn't empty the Context's sets.");
// Destroy MDStrings.
- DeleteContainerSeconds(MDStringCache);
+ MDStringCache.clear();
}
// ConstantsContext anchors
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index bd0097c31ba..3190c22fceb 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -261,7 +261,7 @@ public:
FoldingSet<AttributeSetImpl> AttrsLists;
FoldingSet<AttributeSetNode> AttrsSetNodes;
- StringMap<Value*> MDStringCache;
+ StringMap<MDString> MDStringCache;
FoldingSet<MDNode> MDNodeSet;
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