[PATCH] D16597: Query the StringMap only once when creating MDString (NFC)

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 12:34:50 PST 2016


joker.eph created this revision.
joker.eph added a reviewer: dexonsmith.
joker.eph added a subscriber: llvm-commits.

Loading IR with debug info improves MDString::get() from 19ms to 10ms.

http://reviews.llvm.org/D16597

Files:
  include/llvm/IR/Metadata.h
  lib/IR/Metadata.cpp

Index: lib/IR/Metadata.cpp
===================================================================
--- lib/IR/Metadata.cpp
+++ lib/IR/Metadata.cpp
@@ -399,17 +399,12 @@
 
 MDString *MDString::get(LLVMContext &Context, StringRef Str) {
   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(), MDString());
-  bool WasInserted = Store.insert(Entry);
-  (void)WasInserted;
-  assert(WasInserted && "Expected entry to be inserted");
-  Entry->second.Entry = Entry;
-  return &Entry->second;
+  auto I = Store.insert(std::make_pair(Str, MDString()));
+  auto &MapEntry = I.first->getValue();
+  if (!I.second)
+    return &MapEntry;
+  MapEntry.Entry = &*I.first;
+  return &MapEntry;
 }
 
 StringRef MDString::getString() const {
Index: include/llvm/IR/Metadata.h
===================================================================
--- include/llvm/IR/Metadata.h
+++ include/llvm/IR/Metadata.h
@@ -599,9 +599,9 @@
 
   StringMapEntry<MDString> *Entry;
   MDString() : Metadata(MDStringKind, Uniqued), Entry(nullptr) {}
-  MDString(MDString &&) : Metadata(MDStringKind, Uniqued) {}
 
 public:
+  MDString(MDString &&R) : Metadata(MDStringKind, Uniqued), Entry(R.Entry) {}
   static MDString *get(LLVMContext &Context, StringRef Str);
   static MDString *get(LLVMContext &Context, const char *Str) {
     return get(Context, Str ? StringRef(Str) : StringRef());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16597.46033.patch
Type: text/x-patch
Size: 1506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160126/920b0235/attachment.bin>


More information about the llvm-commits mailing list