[llvm] r266907 - IR: Stop copying vectors of TrackingMDRef in DIBuilder

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 13:03:59 PDT 2016


Author: dexonsmith
Date: Wed Apr 20 15:03:59 2016
New Revision: 266907

URL: http://llvm.org/viewvc/llvm-project?rev=266907&view=rev
Log:
IR: Stop copying vectors of TrackingMDRef in DIBuilder

No real functionality change here, just avoiding an unnecessary copy of
std::vector<TrackingMDRef> for every subprogram with variables.

Modified:
    llvm/trunk/lib/IR/DIBuilder.cpp

Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=266907&r1=266906&r2=266907&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Wed Apr 20 15:03:59 2016
@@ -97,12 +97,18 @@ void DIBuilder::finalize() {
 
   DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
   auto resolveVariables = [&](DISubprogram *SP) {
-    if (MDTuple *Temp = SP->getVariables().get()) {
-      const auto &PV = PreservedVariables.lookup(SP);
-      SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
-      DINodeArray AV = getOrCreateArray(Variables);
-      TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
-    }
+    MDTuple *Temp = SP->getVariables().get();
+    if (!Temp)
+      return;
+
+    SmallVector<Metadata *, 4> Variables;
+
+    auto PV = PreservedVariables.find(SP);
+    if (PV != PreservedVariables.end())
+      Variables.append(PV->second.begin(), PV->second.end());
+
+    DINodeArray AV = getOrCreateArray(Variables);
+    TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
   };
   for (auto *SP : SPs)
     resolveVariables(SP);




More information about the llvm-commits mailing list