[PATCH] D63315: [Attributor] Regularly clear dependences to remove spurious ones

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 22:02:37 PDT 2019


jdoerfert created this revision.
jdoerfert added reviewers: uenoku, sstefan1, homerdin, hfinkel, fedor.sergeev, spatel, nlopes, nicholas, reames, chandlerc.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.

As dependences between abstract attributes can become stale, e.g., if
one was sufficient to imply another one at some point but it has since
been wakened to the point it is not usable for the formerly implied one.
To weed out spurious dependences, and thereby eliminate unneeded
updates, we introduce an option to determine how often the dependence
cache is cleared and recomputed during the fixpoint iteration.

Note that the initial value is set to 0 which disables recomputation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63315

Files:
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/Attributor.cpp


Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -64,6 +64,11 @@
                           cl::desc("Maximal number of fixpoint iterations."),
                           cl::init(32));
 
+static cl::opt<unsigned> DepRecInterval(
+    "attributor-dependence-recompute-interval", cl::Hidden,
+    cl::desc("Number of iterations until dependences are recomputed."),
+    cl::init(0));
+
 static cl::opt<bool> DisableAttributor(
     "attributor-disable", cl::Hidden,
     cl::desc("Disable the attributor inter-procedural deduction pass."),
@@ -675,10 +680,21 @@
   SetVector<AbstractAttribute *> Worklist;
   Worklist.insert(AllAbstractAttributes.begin(), AllAbstractAttributes.end());
 
+  bool RecomputeDependences = false;
+
   do {
     LLVM_DEBUG(dbgs() << "\n\n[Attributor] #Iteration: " << IterationCounter
                       << ", Worklist size: " << Worklist.size() << "\n");
 
+    // If dependences (=QueryMap) are recomputed we have to look at all abstract
+    // attributes again, regardless of what changed in the last iteration.
+    if (RecomputeDependences) {
+      QueryMap.clear();
+      ChangedAAs.clear();
+      Worklist.insert(AllAbstractAttributes.begin(),
+                      AllAbstractAttributes.end());
+    }
+
     // Add all abstract attributes that are potentially dependent on one that
     // changed to the work list.
     for (AbstractAttribute *ChangedAA : ChangedAAs) {
@@ -695,10 +711,16 @@
       if (AA->update(*this) == ChangeStatus::CHANGED)
         ChangedAAs.push_back(AA);
 
+    // Check if we recompute the dependences in the next iteration.
+    RecomputeDependences =
+        (DependenceRecomputeInterval > 0 &&
+         IterationCounter % DependenceRecomputeInterval == 0);
+
     // Reset the work list and repopulate with the changed abstract attributes.
     // Note that dependent ones are added above.
     Worklist.clear();
-    Worklist.insert(ChangedAAs.begin(), ChangedAAs.end());
+    if (!RecomputeDependences)
+      Worklist.insert(ChangedAAs.begin(), ChangedAAs.end());
 
   } while (!Worklist.empty() && ++IterationCounter < MaxFixpointIterations);
 
@@ -987,7 +1009,7 @@
 
   // Create an Attributor and initially empty information cache that is filled
   // while we identify default attribute opportunities.
-  Attributor A;
+  Attributor A(DepRecInterval);
   InformationCache InfoCache;
 
   for (Function &F : M) {
Index: llvm/include/llvm/Transforms/IPO/Attributor.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/Attributor.h
+++ llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -149,6 +149,14 @@
 /// NOTE: The mechanics of adding a new "concrete" abstract attribute are
 ///       described in the file comment.
 struct Attributor {
+  /// Constructor
+  ///
+  /// \param DependenceRecomputeInterval Number of iterations until the
+  ///        dependences between abstract attributes are recomputed.
+  Attributor(unsigned DependenceRecomputeInterval)
+      : DependenceRecomputeInterval(DependenceRecomputeInterval) {}
+
+  /// Destructor
   ~Attributor() { DeleteContainerPointers(AllAbstractAttributes); }
 
   /// Run the analyses until a fixpoint is reached or enforced (timeout).
@@ -298,6 +306,10 @@
   QueryMapTy QueryMap;
   ///}
 
+  /// Number of iterations until the dependences between abstract attributes are
+  /// recomputed.
+  const unsigned DependenceRecomputeInterval;
+
   /// Check if the state of the abstract attribute \p AA may depend on
   /// information derived from a non-exact definition.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63315.204697.patch
Type: text/x-patch
Size: 3729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190614/274693c2/attachment.bin>


More information about the llvm-commits mailing list