[llvm] r242891 - [GMR] Switch to a DenseMap and clean up the iteration loop. NFC.

Chandler Carruth chandlerc at gmail.com
Wed Jul 22 04:36:09 PDT 2015


Author: chandlerc
Date: Wed Jul 22 06:36:09 2015
New Revision: 242891

URL: http://llvm.org/viewvc/llvm-project?rev=242891&view=rev
Log:
[GMR] Switch to a DenseMap and clean up the iteration loop. NFC.

Since we have to iterate this map not that infrequently, we should use
a map that is efficient for iteration. It is also almost certainly much
faster for lookups as well. There is more to do in terms of reducing the
wasted overhead of GMR's runtime though. Not sure how much is worthwhile
though.

The loop improvements should hopefully address the code review that
Duncan gave when he saw this code as I moved it around.

Modified:
    llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp

Modified: llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp?rev=242891&r1=242890&r2=242891&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp Wed Jul 22 06:36:09 2015
@@ -97,7 +97,7 @@ class GlobalsModRef : public ModulePass,
 
   /// AllocsForIndirectGlobals - If an instruction allocates memory for an
   /// indirect global, this map indicates which one.
-  std::map<const Value *, const GlobalValue *> AllocsForIndirectGlobals;
+  DenseMap<const Value *, const GlobalValue *> AllocsForIndirectGlobals;
 
   /// FunctionInfo - For each function, keep track of what globals are
   /// modified or read.
@@ -120,16 +120,11 @@ class GlobalsModRef : public ModulePass,
           // any AllocRelatedValues for it.
           if (GMR.IndirectGlobals.erase(GV)) {
             // Remove any entries in AllocsForIndirectGlobals for this global.
-            for (std::map<const Value *, const GlobalValue *>::iterator
-                     I = GMR.AllocsForIndirectGlobals.begin(),
-                     E = GMR.AllocsForIndirectGlobals.end();
-                 I != E;) {
-              if (I->second == GV) {
-                GMR.AllocsForIndirectGlobals.erase(I++);
-              } else {
-                ++I;
-              }
-            }
+            for (auto I = GMR.AllocsForIndirectGlobals.begin(),
+                      E = GMR.AllocsForIndirectGlobals.end();
+                 I != E; ++I)
+              if (I->second == GV)
+                GMR.AllocsForIndirectGlobals.erase(I);
           }
         }
       }





More information about the llvm-commits mailing list