[PATCH] D15244: [PassManager] Tuning Memory Usage of AnalysisUsage

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 4 12:50:53 PST 2015


reames created this revision.
reames added a reviewer: chandlerc.
reames added a subscriber: llvm-commits.

This patch isn't read for submission yet; it's a vehicle for discussion.

By tuning the initialize sizes of the SmallVector's used by AnalysisUsage, I can cut the memory allocated for all AnalysisUsage objects in the legacy pass manager by nearly 40kb on -O3.  This is over half (original 77kb, new 38kb) of the memory allocated from that site (reporting via massif).  The peak memory usage is reduced from 762 KB to 716 KB.  

I picked these thresholds somewhat at random.  Given the result, I'm really questioning whether small vector is even the right data structure for this case.  Does anyone have any data on the actual numbers of dependencies?  I can measure, but I thought I'd ask first.

Chandler - I haven't examined how AnalysisUsage is used by the new pass manager.  If I tune for performance/memory in the old pass manager, am I going to possible make things worse for the new one?  What do I need to watch out for in expected usage patterns?

http://reviews.llvm.org/D15244

Files:
  include/llvm/IR/LegacyPassManagers.h
  include/llvm/PassAnalysisSupport.h

Index: include/llvm/PassAnalysisSupport.h
===================================================================
--- include/llvm/PassAnalysisSupport.h
+++ include/llvm/PassAnalysisSupport.h
@@ -36,11 +36,14 @@
 ///
 class AnalysisUsage {
 public:
-  typedef SmallVector<AnalysisID, 32> VectorType;
+  typedef SmallVectorImpl<AnalysisID> VectorType;
 
 private:
   /// Sets of analyses required and preserved by a pass
-  VectorType Required, RequiredTransitive, Preserved, Used;
+  SmallVector<AnalysisID, 8> Required;
+  SmallVector<AnalysisID, 32> RequiredTransitive;
+  SmallVector<AnalysisID, 8> Preserved;
+  SmallVector<AnalysisID, 4> Used;
   bool PreservesAll;
 
 public:
Index: include/llvm/IR/LegacyPassManagers.h
===================================================================
--- include/llvm/IR/LegacyPassManagers.h
+++ include/llvm/IR/LegacyPassManagers.h
@@ -264,10 +264,10 @@
       // TODO: We could consider sorting the dependency arrays within the
       // AnalysisUsage (since they are conceptually unordered).
       ID.AddBoolean(AU.getPreservesAll());
-      for (auto &Vec : {AU.getRequiredSet(), AU.getRequiredTransitiveSet(),
-            AU.getPreservedSet(), AU.getUsedSet()}) {
-        ID.AddInteger(Vec.size());
-        for(AnalysisID AID : Vec)
+      for (auto *Vec : {&AU.getRequiredSet(), &AU.getRequiredTransitiveSet(),
+            &AU.getPreservedSet(), &AU.getUsedSet()}) {
+        ID.AddInteger(Vec->size());
+        for(AnalysisID AID : *Vec)
           ID.AddPointer(AID);
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15244.41928.patch
Type: text/x-patch
Size: 1537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151204/b6d9133e/attachment.bin>


More information about the llvm-commits mailing list