[PATCH] D86635: [Attributor] Add getter of abstract attributes for the manifestation stage

Shinji Okumura via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 09:09:54 PDT 2020


okura created this revision.
Herald added a reviewer: uenoku.
Herald added subscribers: llvm-commits, kuter, uenoku.
Herald added a reviewer: homerdin.
Herald added a project: LLVM.
okura requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added a subscriber: bbn.

If we query an AA with `Attributor::getAAFor` in `AbstractAttribute::manifest`, the AA may be updated.
So this patch introduces a new getter, which is guaranteed not to update AA.


https://reviews.llvm.org/D86635

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


Index: llvm/include/llvm/Transforms/IPO/Attributor.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/Attributor.h
+++ llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -965,6 +965,19 @@
                                     /* ForceUpdate */ true);
   }
 
+  /// Return abstract attribute of type \p AAType at position \p IRP. If the AA
+  /// has not been initialized, this initializes it and forces it to indicate
+  /// a pessimistic fixpoint. This is useful when we want to query abstract
+  /// attributes after we are done with the update stage e.g. in
+  /// AbstractAttribute::manifest.
+  template <typename AAType>
+  const AAType &getAAAfterIterationFor(const IRPosition &IRP) {
+    return getOrCreateAAFor<AAType>(IRP, nullptr, /* TrackDependence */ false,
+                                    DepClassTy::OPTIONAL,
+                                    /* ForceUpdate */ false,
+                                    /* AfterIteration */ true);
+  }
+
   /// The version of getAAFor that allows to omit a querying abstract
   /// attribute. Using this after Attributor started running is restricted to
   /// only the Attributor itself. Initial seeding of AAs can be done via this
@@ -974,10 +987,13 @@
                                  const AbstractAttribute *QueryingAA = nullptr,
                                  bool TrackDependence = false,
                                  DepClassTy DepClass = DepClassTy::OPTIONAL,
-                                 bool ForceUpdate = false) {
+                                 bool ForceUpdate = false,
+                                 bool AfterIteration = false) {
     if (AAType *AAPtr = lookupAAFor<AAType>(IRP, QueryingAA, TrackDependence)) {
-      if (ForceUpdate)
+      if (ForceUpdate) {
+        assert(!AfterIteration && "We cannot update AA after iteration!");
         updateAA(*AAPtr);
+      }
       return *AAPtr;
     }
 
@@ -1020,6 +1036,13 @@
       return AA;
     }
 
+    // If this is queried after the update stage, we immediately force it to
+    // indicate a pessimistic fixpoint.
+    if (AfterIteration) {
+      AA.getState().indicatePessimisticFixpoint();
+      return AA;
+    }
+
     // Allow seeded attributes to declare dependencies.
     // Remember the seeding state.
     bool OldSeedingPeriod = SeedingPeriod;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86635.288001.patch
Type: text/x-patch
Size: 2366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200826/1cc2487c/attachment.bin>


More information about the llvm-commits mailing list