[llvm] r266761 - Linker: Avoid constructing ValueMap::MDMapT

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 09:57:24 PDT 2016


Author: dexonsmith
Date: Tue Apr 19 11:57:24 2016
New Revision: 266761

URL: http://llvm.org/viewvc/llvm-project?rev=266761&view=rev
Log:
Linker: Avoid constructing ValueMap::MDMapT

Calling ValueMap::MD lazily constructs a ValueMap, which mallocs the
buckets.  Instead of swapping constructed maps, move around the
underlying Optional<MDMapT>.  This gets rid of some unnecessary malloc
traffic from r266579 (not that it showed up on a profile).

Modified:
    llvm/trunk/include/llvm/IR/ValueMap.h
    llvm/trunk/lib/Linker/IRMover.cpp

Modified: llvm/trunk/include/llvm/IR/ValueMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ValueMap.h?rev=266761&r1=266760&r2=266761&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ValueMap.h (original)
+++ llvm/trunk/include/llvm/IR/ValueMap.h Tue Apr 19 11:57:24 2016
@@ -109,6 +109,7 @@ public:
       MDMap.emplace();
     return *MDMap;
   }
+  Optional<MDMapT> &getMDMap() { return MDMap; }
 
   bool mayMapMetadata() const { return MayMapMetadata; }
   void enableMapMetadata() { MayMapMetadata = true; }

Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=266761&r1=266760&r2=266761&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Tue Apr 19 11:57:24 2016
@@ -483,11 +483,11 @@ public:
                &GValMaterializer),
         AliasMCID(Mapper.registerAlternateMappingContext(AliasValueMap,
                                                          &LValMaterializer)) {
-    ValueMap.MD().swap(SharedMDs);
+    ValueMap.getMDMap() = std::move(SharedMDs);
     for (GlobalValue *GV : ValuesToLink)
       maybeAdd(GV);
   }
-  ~IRLinker() { ValueMap.MD().swap(SharedMDs); }
+  ~IRLinker() { SharedMDs = std::move(*ValueMap.getMDMap()); }
 
   bool run();
   Value *materializeDeclFor(Value *V, bool ForAlias);




More information about the llvm-commits mailing list