[llvm] r367950 - [Attributor][NFCI] Avoid duplication of the InformationCache reference

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 16:26:06 PDT 2019


Author: jdoerfert
Date: Mon Aug  5 16:26:06 2019
New Revision: 367950

URL: http://llvm.org/viewvc/llvm-project?rev=367950&view=rev
Log:
[Attributor][NFCI] Avoid duplication of the InformationCache reference

Summary:
Instead of storing the reference to the InformationCache we now pass it
whenever it might be needed.

Reviewers: sstefan1, uenoku

Subscribers: hiraditya, bollu, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65709

Modified:
    llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
    llvm/trunk/lib/Transforms/IPO/Attributor.cpp

Modified: llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/Attributor.h?rev=367950&r1=367949&r2=367950&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/Attributor.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/Attributor.h Mon Aug  5 16:26:06 2019
@@ -156,7 +156,7 @@ struct Attributor {
   /// as the Attributor is not destroyed (it owns the attributes now).
   ///
   /// \Returns CHANGED if the IR was changed, otherwise UNCHANGED.
-  ChangeStatus run();
+  ChangeStatus run(InformationCache &InfoCache);
 
   /// Lookup an abstract attribute of type \p AAType anchored at value \p V and
   /// argument number \p ArgNo. If no attribute is found and \p V is a call base
@@ -557,15 +557,11 @@ struct AbstractAttribute {
   ///
   /// \param AssociatedVal The value this abstract attribute is associated with.
   /// \param AnchoredVal The value this abstract attributes is anchored at.
-  /// \param InfoCache Cached information accessible to the abstract attribute.
-  AbstractAttribute(Value *AssociatedVal, Value &AnchoredVal,
-                    InformationCache &InfoCache)
-      : AssociatedVal(AssociatedVal), AnchoredVal(AnchoredVal),
-        InfoCache(InfoCache) {}
+  AbstractAttribute(Value *AssociatedVal, Value &AnchoredVal)
+      : AssociatedVal(AssociatedVal), AnchoredVal(AnchoredVal) {}
 
   /// An abstract attribute associated with and anchored at \p V.
-  AbstractAttribute(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(&V, V, InfoCache) {}
+  AbstractAttribute(Value &V) : AbstractAttribute(&V, V) {}
 
   /// Virtual destructor.
   virtual ~AbstractAttribute() {}
@@ -578,7 +574,7 @@ struct AbstractAttribute {
   ///  - perform any work that is not going to change over time, e.g., determine
   ///    a subset of the IR, or attributes in-flight, that have to be looked at
   ///    in the `updateImpl` method.
-  virtual void initialize(Attributor &A) {}
+  virtual void initialize(Attributor &A, InformationCache &InfoCache) {}
 
   /// Return the internal abstract state for inspection.
   virtual const AbstractState &getState() const = 0;
@@ -642,7 +638,7 @@ protected:
   /// otherwise it delegates to `AbstractAttribute::updateImpl`.
   ///
   /// \Return CHANGED if the internal state changed, otherwise UNCHANGED.
-  ChangeStatus update(Attributor &A);
+  ChangeStatus update(Attributor &A, InformationCache &InfoCache);
 
   /// Hook for the Attributor to trigger the manifestation of the information
   /// represented by the abstract attribute in the LLVM-IR.
@@ -660,16 +656,14 @@ protected:
   /// the current information is still valid or adjust it otherwise.
   ///
   /// \Return CHANGED if the internal state changed, otherwise UNCHANGED.
-  virtual ChangeStatus updateImpl(Attributor &A) = 0;
+  virtual ChangeStatus updateImpl(Attributor &A,
+                                  InformationCache &InfoCache) = 0;
 
   /// The value this abstract attribute is associated with.
   Value *AssociatedVal;
 
   /// The value this abstract attribute is anchored at.
   Value &AnchoredVal;
-
-  /// The information cache accessible to this abstract attribute.
-  InformationCache &InfoCache;
 };
 
 /// Forward declarations of output streams for debug purposes.
@@ -694,8 +688,7 @@ Pass *createAttributorLegacyPass();
 /// An abstract attribute for the returned values of a function.
 struct AAReturnedValues : public AbstractAttribute {
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAReturnedValues(Function &F, InformationCache &InfoCache)
-      : AbstractAttribute(F, InfoCache) {}
+  AAReturnedValues(Function &F) : AbstractAttribute(F) {}
 
   /// Check \p Pred on all returned values.
   ///
@@ -715,8 +708,7 @@ struct AAReturnedValues : public Abstrac
 
 struct AANoUnwind : public AbstractAttribute {
   /// An abstract interface for all nosync attributes.
-  AANoUnwind(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AANoUnwind(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::getAttrKind()/
   Attribute::AttrKind getAttrKind() const override { return ID; }
@@ -732,8 +724,7 @@ struct AANoUnwind : public AbstractAttri
 
 struct AANoSync : public AbstractAttribute {
   /// An abstract interface for all nosync attributes.
-  AANoSync(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AANoSync(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::getAttrKind().
   Attribute::AttrKind getAttrKind() const override { return ID; }
@@ -752,13 +743,11 @@ struct AANoSync : public AbstractAttribu
 struct AANonNull : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AANonNull(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AANonNull(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AANonNull(Value *AssociatedVal, Value &AnchoredValue,
-            InformationCache &InfoCache)
-      : AbstractAttribute(AssociatedVal, AnchoredValue, InfoCache) {}
+  AANonNull(Value *AssociatedVal, Value &AnchoredValue)
+      : AbstractAttribute(AssociatedVal, AnchoredValue) {}
 
   /// Return true if we assume that the underlying value is nonnull.
   virtual bool isAssumedNonNull() const = 0;
@@ -777,8 +766,7 @@ struct AANonNull : public AbstractAttrib
 struct AANoRecurse : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AANoRecurse(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AANoRecurse(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::getAttrKind()
   virtual Attribute::AttrKind getAttrKind() const override {
@@ -799,8 +787,7 @@ struct AANoRecurse : public AbstractAttr
 struct AAWillReturn : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAWillReturn(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AAWillReturn(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::getAttrKind()
   virtual Attribute::AttrKind getAttrKind() const override {
@@ -821,8 +808,7 @@ struct AAWillReturn : public AbstractAtt
 struct AANoAlias : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AANoAlias(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AANoAlias(Value &V) : AbstractAttribute(V) {}
 
   /// Return true if we assume that the underlying value is alias.
   virtual bool isAssumedNoAlias() const = 0;
@@ -841,8 +827,7 @@ struct AANoAlias : public AbstractAttrib
 struct AANoReturn : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AANoReturn(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AANoReturn(Value &V) : AbstractAttribute(V) {}
 
   /// Return true if the underlying object is known to never return.
   virtual bool isKnownNoReturn() const = 0;
@@ -861,8 +846,7 @@ struct AANoReturn : public AbstractAttri
 struct AAIsDead : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAIsDead(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AAIsDead(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::getAttrKind()
   Attribute::AttrKind getAttrKind() const override { return ID; }
@@ -901,13 +885,11 @@ struct AAIsDead : public AbstractAttribu
 struct AADereferenceable : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AADereferenceable(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AADereferenceable(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AADereferenceable(Value *AssociatedVal, Value &AnchoredValue,
-                    InformationCache &InfoCache)
-      : AbstractAttribute(AssociatedVal, AnchoredValue, InfoCache) {}
+  AADereferenceable(Value *AssociatedVal, Value &AnchoredValue)
+      : AbstractAttribute(AssociatedVal, AnchoredValue) {}
 
   /// Return true if we assume that the underlying value is nonnull.
   virtual bool isAssumedNonNull() const = 0;
@@ -940,13 +922,11 @@ struct AADereferenceable : public Abstra
 struct AAAlign : public AbstractAttribute {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAAlign(Value &V, InformationCache &InfoCache)
-      : AbstractAttribute(V, InfoCache) {}
+  AAAlign(Value &V) : AbstractAttribute(V) {}
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAAlign(Value *AssociatedVal, Value &AnchoredValue,
-          InformationCache &InfoCache)
-      : AbstractAttribute(AssociatedVal, AnchoredValue, InfoCache) {}
+  AAAlign(Value *AssociatedVal, Value &AnchoredValue)
+      : AbstractAttribute(AssociatedVal, AnchoredValue) {}
 
   /// See AbastractState::getAttrKind().
   Attribute::AttrKind getAttrKind() const override { return ID; }

Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=367950&r1=367949&r2=367950&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Mon Aug  5 16:26:06 2019
@@ -335,14 +335,15 @@ static bool addIfNotExistent(LLVMContext
   llvm_unreachable("Expected enum or string attribute!");
 }
 
-ChangeStatus AbstractAttribute::update(Attributor &A) {
+ChangeStatus AbstractAttribute::update(Attributor &A,
+                                       InformationCache &InfoCache) {
   ChangeStatus HasChanged = ChangeStatus::UNCHANGED;
   if (getState().isAtFixpoint())
     return HasChanged;
 
   LLVM_DEBUG(dbgs() << "[Attributor] Update: " << *this << "\n");
 
-  HasChanged = updateImpl(A);
+  HasChanged = updateImpl(A, InfoCache);
 
   LLVM_DEBUG(dbgs() << "[Attributor] Update " << HasChanged << " " << *this
                     << "\n");
@@ -444,8 +445,7 @@ static int getArgNo(Value &V) {
 
 struct AANoUnwindFunction : AANoUnwind, BooleanState {
 
-  AANoUnwindFunction(Function &F, InformationCache &InfoCache)
-      : AANoUnwind(F, InfoCache) {}
+  AANoUnwindFunction(Function &F) : AANoUnwind(F) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -461,7 +461,7 @@ struct AANoUnwindFunction : AANoUnwind,
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AANoUnwind::isAssumedNoUnwind().
   bool isAssumedNoUnwind() const override { return getAssumed(); }
@@ -470,7 +470,8 @@ struct AANoUnwindFunction : AANoUnwind,
   bool isKnownNoUnwind() const override { return getKnown(); }
 };
 
-ChangeStatus AANoUnwindFunction::updateImpl(Attributor &A) {
+ChangeStatus AANoUnwindFunction::updateImpl(Attributor &A,
+                                            InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   // The map from instruction opcodes to those instructions in the function.
@@ -545,14 +546,13 @@ class AAReturnedValuesImpl final : publi
 
 public:
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAReturnedValuesImpl(Function &F, InformationCache &InfoCache)
-      : AAReturnedValues(F, InfoCache) {
+  AAReturnedValuesImpl(Function &F) : AAReturnedValues(F) {
     // We do not have an associated argument yet.
     AssociatedVal = nullptr;
   }
 
   /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     // Reset the state.
     AssociatedVal = nullptr;
     IsFixed = false;
@@ -600,7 +600,7 @@ public:
   ManifestPosition getManifestPosition() const override { return MP_ARGUMENT; }
 
   /// See AbstractAttribute::updateImpl(Attributor &A).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// Return the number of potential return values, -1 if unknown.
   size_t getNumReturnValues() const {
@@ -736,7 +736,8 @@ bool AAReturnedValuesImpl::checkForallRe
   return true;
 }
 
-ChangeStatus AAReturnedValuesImpl::updateImpl(Attributor &A) {
+ChangeStatus AAReturnedValuesImpl::updateImpl(Attributor &A,
+                                              InformationCache &InfoCache) {
 
   // Check if we know of any values returned by the associated function,
   // if not, we are done.
@@ -863,8 +864,7 @@ ChangeStatus AAReturnedValuesImpl::updat
 
 struct AANoSyncFunction : AANoSync, BooleanState {
 
-  AANoSyncFunction(Function &F, InformationCache &InfoCache)
-      : AANoSync(F, InfoCache) {}
+  AANoSyncFunction(Function &F) : AANoSync(F) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -880,7 +880,7 @@ struct AANoSyncFunction : AANoSync, Bool
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AANoSync::isAssumedNoSync()
   bool isAssumedNoSync() const override { return getAssumed(); }
@@ -990,7 +990,8 @@ bool AANoSyncFunction::isVolatile(Instru
   }
 }
 
-ChangeStatus AANoSyncFunction::updateImpl(Attributor &A) {
+ChangeStatus AANoSyncFunction::updateImpl(Attributor &A,
+                                          InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   auto *LivenessAA = A.getAAFor<AAIsDead>(*this, F);
@@ -1053,8 +1054,7 @@ ChangeStatus AANoSyncFunction::updateImp
 struct AANoFreeFunction : AbstractAttribute, BooleanState {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AANoFreeFunction(Function &F, InformationCache &InfoCache)
-      : AbstractAttribute(F, InfoCache) {}
+  AANoFreeFunction(Function &F) : AbstractAttribute(F) {}
 
   /// See AbstractAttribute::getState()
   ///{
@@ -1071,7 +1071,7 @@ struct AANoFreeFunction : AbstractAttrib
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AbstractAttribute::getAttrKind().
   Attribute::AttrKind getAttrKind() const override { return ID; }
@@ -1086,7 +1086,8 @@ struct AANoFreeFunction : AbstractAttrib
   static constexpr Attribute::AttrKind ID = Attribute::NoFree;
 };
 
-ChangeStatus AANoFreeFunction::updateImpl(Attributor &A) {
+ChangeStatus AANoFreeFunction::updateImpl(Attributor &A,
+                                          InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   auto *LivenessAA = A.getAAFor<AAIsDead>(*this, F);
@@ -1115,12 +1116,10 @@ ChangeStatus AANoFreeFunction::updateImp
 /// ------------------------ NonNull Argument Attribute ------------------------
 struct AANonNullImpl : AANonNull, BooleanState {
 
-  AANonNullImpl(Value &V, InformationCache &InfoCache)
-      : AANonNull(V, InfoCache) {}
+  AANonNullImpl(Value &V) : AANonNull(V) {}
 
-  AANonNullImpl(Value *AssociatedVal, Value &AnchoredValue,
-                InformationCache &InfoCache)
-      : AANonNull(AssociatedVal, AnchoredValue, InfoCache) {}
+  AANonNullImpl(Value *AssociatedVal, Value &AnchoredValue)
+      : AANonNull(AssociatedVal, AnchoredValue) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -1180,14 +1179,13 @@ AANonNullImpl::generatePredicate(Attribu
 /// NonNull attribute for function return value.
 struct AANonNullReturned : AANonNullImpl {
 
-  AANonNullReturned(Function &F, InformationCache &InfoCache)
-      : AANonNullImpl(F, InfoCache) {}
+  AANonNullReturned(Function &F) : AANonNullImpl(F) {}
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override { return MP_RETURNED; }
 
   /// See AbstractAttriubute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
 
     // Already nonnull.
@@ -1199,10 +1197,11 @@ struct AANonNullReturned : AANonNullImpl
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 };
 
-ChangeStatus AANonNullReturned::updateImpl(Attributor &A) {
+ChangeStatus AANonNullReturned::updateImpl(Attributor &A,
+                                           InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   auto *AARetVal = A.getAAFor<AAReturnedValues>(*this, F);
@@ -1220,34 +1219,32 @@ ChangeStatus AANonNullReturned::updateIm
 /// NonNull attribute for function argument.
 struct AANonNullArgument : AANonNullImpl {
 
-  AANonNullArgument(Argument &A, InformationCache &InfoCache)
-      : AANonNullImpl(A, InfoCache) {}
+  AANonNullArgument(Argument &A) : AANonNullImpl(A) {}
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override { return MP_ARGUMENT; }
 
   /// See AbstractAttriubute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Argument *Arg = cast<Argument>(getAssociatedValue());
     if (Arg->hasNonNullAttr())
       indicateOptimisticFixpoint();
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 };
 
 /// NonNull attribute for a call site argument.
 struct AANonNullCallSiteArgument : AANonNullImpl {
 
   /// See AANonNullImpl::AANonNullImpl(...).
-  AANonNullCallSiteArgument(CallSite CS, unsigned ArgNo,
-                            InformationCache &InfoCache)
-      : AANonNullImpl(CS.getArgOperand(ArgNo), *CS.getInstruction(), InfoCache),
+  AANonNullCallSiteArgument(CallSite CS, unsigned ArgNo)
+      : AANonNullImpl(CS.getArgOperand(ArgNo), *CS.getInstruction()),
         ArgNo(ArgNo) {}
 
   /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     CallSite CS(&getAnchoredValue());
     if (CS.paramHasAttr(ArgNo, getAttrKind()) ||
         CS.paramHasAttr(ArgNo, Attribute::Dereferenceable) ||
@@ -1257,7 +1254,7 @@ struct AANonNullCallSiteArgument : AANon
   }
 
   /// See AbstractAttribute::updateImpl(Attributor &A).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override {
@@ -1270,7 +1267,9 @@ struct AANonNullCallSiteArgument : AANon
 private:
   unsigned ArgNo;
 };
-ChangeStatus AANonNullArgument::updateImpl(Attributor &A) {
+
+ChangeStatus AANonNullArgument::updateImpl(Attributor &A,
+                                           InformationCache &InfoCache) {
   Function &F = getAnchorScope();
   Argument &Arg = cast<Argument>(getAnchoredValue());
 
@@ -1304,7 +1303,9 @@ ChangeStatus AANonNullArgument::updateIm
   return ChangeStatus::UNCHANGED;
 }
 
-ChangeStatus AANonNullCallSiteArgument::updateImpl(Attributor &A) {
+ChangeStatus
+AANonNullCallSiteArgument::updateImpl(Attributor &A,
+                                      InformationCache &InfoCache) {
   // NOTE: Never look at the argument of the callee in this method.
   //       If we do this, "nonnull" is always deduced because of the assumption.
 
@@ -1323,8 +1324,7 @@ ChangeStatus AANonNullCallSiteArgument::
 struct AAWillReturnImpl : public AAWillReturn, BooleanState {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAWillReturnImpl(Function &F, InformationCache &InfoCache)
-      : AAWillReturn(F, InfoCache) {}
+  AAWillReturnImpl(Function &F) : AAWillReturn(F) {}
 
   /// See AAWillReturn::isKnownWillReturn().
   bool isKnownWillReturn() const override { return getKnown(); }
@@ -1347,17 +1347,16 @@ struct AAWillReturnImpl : public AAWillR
 struct AAWillReturnFunction final : AAWillReturnImpl {
 
   /// See AbstractAttribute::AbstractAttribute(...).
-  AAWillReturnFunction(Function &F, InformationCache &InfoCache)
-      : AAWillReturnImpl(F, InfoCache) {}
+  AAWillReturnFunction(Function &F) : AAWillReturnImpl(F) {}
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override { return MP_FUNCTION; }
 
   /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override;
+  void initialize(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 };
 
 // Helper function that checks whether a function has any cycle.
@@ -1382,14 +1381,16 @@ bool containsCycle(Function &F) {
 //        We have to allow some patterns.
 bool containsPossiblyEndlessLoop(Function &F) { return containsCycle(F); }
 
-void AAWillReturnFunction::initialize(Attributor &A) {
+void AAWillReturnFunction::initialize(Attributor &A,
+                                      InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   if (containsPossiblyEndlessLoop(F))
     indicatePessimisticFixpoint();
 }
 
-ChangeStatus AAWillReturnFunction::updateImpl(Attributor &A) {
+ChangeStatus AAWillReturnFunction::updateImpl(Attributor &A,
+                                              InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   // The map from instruction opcodes to those instructions in the function.
@@ -1433,8 +1434,7 @@ ChangeStatus AAWillReturnFunction::updat
 
 struct AANoAliasImpl : AANoAlias, BooleanState {
 
-  AANoAliasImpl(Value &V, InformationCache &InfoCache)
-      : AANoAlias(V, InfoCache) {}
+  AANoAliasImpl(Value &V) : AANoAlias(V) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -1456,8 +1456,7 @@ struct AANoAliasImpl : AANoAlias, Boolea
 /// NoAlias attribute for function return value.
 struct AANoAliasReturned : AANoAliasImpl {
 
-  AANoAliasReturned(Function &F, InformationCache &InfoCache)
-      : AANoAliasImpl(F, InfoCache) {}
+  AANoAliasReturned(Function &F) : AANoAliasImpl(F) {}
 
   /// See AbstractAttribute::getManifestPosition().
   virtual ManifestPosition getManifestPosition() const override {
@@ -1465,7 +1464,7 @@ struct AANoAliasReturned : AANoAliasImpl
   }
 
   /// See AbstractAttriubute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
 
     // Already noalias.
@@ -1476,10 +1475,12 @@ struct AANoAliasReturned : AANoAliasImpl
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  virtual ChangeStatus updateImpl(Attributor &A) override;
+  virtual ChangeStatus updateImpl(Attributor &A,
+                                  InformationCache &InfoCache) override;
 };
 
-ChangeStatus AANoAliasReturned::updateImpl(Attributor &A) {
+ChangeStatus AANoAliasReturned::updateImpl(Attributor &A,
+                                           InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
   auto *AARetValImpl = A.getAAFor<AAReturnedValuesImpl>(*this, F);
@@ -1524,8 +1525,7 @@ ChangeStatus AANoAliasReturned::updateIm
 
 struct AAIsDeadFunction : AAIsDead, BooleanState {
 
-  AAIsDeadFunction(Function &F, InformationCache &InfoCache)
-      : AAIsDead(F, InfoCache) {}
+  AAIsDeadFunction(Function &F) : AAIsDead(F) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -1536,7 +1536,7 @@ struct AAIsDeadFunction : AAIsDead, Bool
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override { return MP_FUNCTION; }
 
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
 
     ToBeExploredPaths.insert(&(F.getEntryBlock().front()));
@@ -1625,7 +1625,7 @@ struct AAIsDeadFunction : AAIsDead, Bool
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AAIsDead::isAssumedDead(BasicBlock *).
   bool isAssumedDead(const BasicBlock *BB) const override {
@@ -1743,7 +1743,8 @@ const Instruction *AAIsDeadFunction::fin
   return nullptr;
 }
 
-ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {
+ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A,
+                                          InformationCache &InfoCache) {
   // Temporary collection to iterate over existing noreturn instructions. This
   // will alow easier modification of NoReturnCalls collection
   SmallVector<const Instruction *, 8> NoReturnChanged;
@@ -1844,12 +1845,10 @@ struct DerefState : AbstractState {
 };
 struct AADereferenceableImpl : AADereferenceable, DerefState {
 
-  AADereferenceableImpl(Value &V, InformationCache &InfoCache)
-      : AADereferenceable(V, InfoCache) {}
+  AADereferenceableImpl(Value &V) : AADereferenceable(V) {}
 
-  AADereferenceableImpl(Value *AssociatedVal, Value &AnchoredValue,
-                        InformationCache &InfoCache)
-      : AADereferenceable(AssociatedVal, AnchoredValue, InfoCache) {}
+  AADereferenceableImpl(Value *AssociatedVal, Value &AnchoredValue)
+      : AADereferenceable(AssociatedVal, AnchoredValue) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -1915,7 +1914,7 @@ struct AADereferenceableImpl : AADerefer
   uint64_t computeAssumedDerefenceableBytes(Attributor &A, Value &V,
                                             bool &IsNonNull, bool &IsGlobal);
 
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
     unsigned AttrIdx =
         getAttrIndex(getManifestPosition(), getArgNo(getAnchoredValue()));
@@ -1939,14 +1938,13 @@ struct AADereferenceableImpl : AADerefer
 };
 
 struct AADereferenceableReturned : AADereferenceableImpl {
-  AADereferenceableReturned(Function &F, InformationCache &InfoCache)
-      : AADereferenceableImpl(F, InfoCache) {}
+  AADereferenceableReturned(Function &F) : AADereferenceableImpl(F) {}
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override { return MP_RETURNED; }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 };
 
 // Helper function that returns dereferenceable bytes.
@@ -1994,7 +1992,10 @@ uint64_t AADereferenceableImpl::computeA
   IsNonNull = false;
   return 0;
 }
-ChangeStatus AADereferenceableReturned::updateImpl(Attributor &A) {
+
+ChangeStatus
+AADereferenceableReturned::updateImpl(Attributor &A,
+                                      InformationCache &InfoCache) {
   Function &F = getAnchorScope();
   auto BeforeState = static_cast<DerefState>(*this);
 
@@ -2024,17 +2025,18 @@ ChangeStatus AADereferenceableReturned::
 }
 
 struct AADereferenceableArgument : AADereferenceableImpl {
-  AADereferenceableArgument(Argument &A, InformationCache &InfoCache)
-      : AADereferenceableImpl(A, InfoCache) {}
+  AADereferenceableArgument(Argument &A) : AADereferenceableImpl(A) {}
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override { return MP_ARGUMENT; }
 
   /// See AbstractAttribute::updateImpl(...).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 };
 
-ChangeStatus AADereferenceableArgument::updateImpl(Attributor &A) {
+ChangeStatus
+AADereferenceableArgument::updateImpl(Attributor &A,
+                                      InformationCache &InfoCache) {
   Function &F = getAnchorScope();
   Argument &Arg = cast<Argument>(getAnchoredValue());
 
@@ -2083,14 +2085,12 @@ ChangeStatus AADereferenceableArgument::
 struct AADereferenceableCallSiteArgument : AADereferenceableImpl {
 
   /// See AADereferenceableImpl::AADereferenceableImpl(...).
-  AADereferenceableCallSiteArgument(CallSite CS, unsigned ArgNo,
-                                    InformationCache &InfoCache)
-      : AADereferenceableImpl(CS.getArgOperand(ArgNo), *CS.getInstruction(),
-                              InfoCache),
+  AADereferenceableCallSiteArgument(CallSite CS, unsigned ArgNo)
+      : AADereferenceableImpl(CS.getArgOperand(ArgNo), *CS.getInstruction()),
         ArgNo(ArgNo) {}
 
   /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     CallSite CS(&getAnchoredValue());
     if (CS.paramHasAttr(ArgNo, Attribute::Dereferenceable))
       takeKnownDerefBytesMaximum(
@@ -2102,7 +2102,7 @@ struct AADereferenceableCallSiteArgument
   }
 
   /// See AbstractAttribute::updateImpl(Attributor &A).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override {
@@ -2116,7 +2116,9 @@ private:
   unsigned ArgNo;
 };
 
-ChangeStatus AADereferenceableCallSiteArgument::updateImpl(Attributor &A) {
+ChangeStatus
+AADereferenceableCallSiteArgument::updateImpl(Attributor &A,
+                                              InformationCache &InfoCache) {
   // NOTE: Never look at the argument of the callee in this method.
   //       If we do this, "dereferenceable" is always deduced because of the
   //       assumption.
@@ -2144,13 +2146,10 @@ struct AAAlignImpl : AAAlign, IntegerSta
   // Max alignemnt value allowed in IR
   static const unsigned MAX_ALIGN = 1U << 29;
 
-  AAAlignImpl(Value *AssociatedVal, Value &AnchoredValue,
-              InformationCache &InfoCache)
-      : AAAlign(AssociatedVal, AnchoredValue, InfoCache),
-        IntegerState(MAX_ALIGN) {}
+  AAAlignImpl(Value *AssociatedVal, Value &AnchoredValue)
+      : AAAlign(AssociatedVal, AnchoredValue), IntegerState(MAX_ALIGN) {}
 
-  AAAlignImpl(Value &V, InformationCache &InfoCache)
-      : AAAlignImpl(&V, V, InfoCache) {}
+  AAAlignImpl(Value &V) : AAAlignImpl(&V, V) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -2171,7 +2170,7 @@ struct AAAlignImpl : AAAlign, IntegerSta
   unsigned getKnownAlign() const override { return getKnown(); }
 
   /// See AbstractAttriubute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
 
     unsigned AttrIdx =
@@ -2194,8 +2193,7 @@ struct AAAlignImpl : AAAlign, IntegerSta
 /// Align attribute for function return value.
 struct AAAlignReturned : AAAlignImpl {
 
-  AAAlignReturned(Function &F, InformationCache &InfoCache)
-      : AAAlignImpl(F, InfoCache) {}
+  AAAlignReturned(Function &F) : AAAlignImpl(F) {}
 
   /// See AbstractAttribute::getManifestPosition().
   virtual ManifestPosition getManifestPosition() const override {
@@ -2203,10 +2201,11 @@ struct AAAlignReturned : AAAlignImpl {
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  virtual ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 };
 
-ChangeStatus AAAlignReturned::updateImpl(Attributor &A) {
+ChangeStatus AAAlignReturned::updateImpl(Attributor &A,
+                                         InformationCache &InfoCache) {
   Function &F = getAnchorScope();
   auto *AARetValImpl = A.getAAFor<AAReturnedValuesImpl>(*this, F);
   if (!AARetValImpl)
@@ -2242,8 +2241,7 @@ ChangeStatus AAAlignReturned::updateImpl
 /// Align attribute for function argument.
 struct AAAlignArgument : AAAlignImpl {
 
-  AAAlignArgument(Argument &A, InformationCache &InfoCache)
-      : AAAlignImpl(A, InfoCache) {}
+  AAAlignArgument(Argument &A) : AAAlignImpl(A) {}
 
   /// See AbstractAttribute::getManifestPosition().
   virtual ManifestPosition getManifestPosition() const override {
@@ -2251,10 +2249,12 @@ struct AAAlignArgument : AAAlignImpl {
   }
 
   /// See AbstractAttribute::updateImpl(...).
-  virtual ChangeStatus updateImpl(Attributor &A) override;
+  virtual ChangeStatus updateImpl(Attributor &A,
+                                  InformationCache &InfoCache) override;
 };
 
-ChangeStatus AAAlignArgument::updateImpl(Attributor &A) {
+ChangeStatus AAAlignArgument::updateImpl(Attributor &A,
+                                         InformationCache &InfoCache) {
 
   Function &F = getAnchorScope();
   Argument &Arg = cast<Argument>(getAnchoredValue());
@@ -2294,20 +2294,19 @@ ChangeStatus AAAlignArgument::updateImpl
 struct AAAlignCallSiteArgument : AAAlignImpl {
 
   /// See AANonNullImpl::AANonNullImpl(...).
-  AAAlignCallSiteArgument(CallSite CS, unsigned ArgNo,
-                          InformationCache &InfoCache)
-      : AAAlignImpl(CS.getArgOperand(ArgNo), *CS.getInstruction(), InfoCache),
+  AAAlignCallSiteArgument(CallSite CS, unsigned ArgNo)
+      : AAAlignImpl(CS.getArgOperand(ArgNo), *CS.getInstruction()),
         ArgNo(ArgNo) {}
 
   /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     CallSite CS(&getAnchoredValue());
     takeKnownMaximum(getAssociatedValue()->getPointerAlignment(
         getAnchorScope().getParent()->getDataLayout()));
   }
 
   /// See AbstractAttribute::updateImpl(Attributor &A).
-  ChangeStatus updateImpl(Attributor &A) override;
+  ChangeStatus updateImpl(Attributor &A, InformationCache &InfoCache) override;
 
   /// See AbstractAttribute::getManifestPosition().
   ManifestPosition getManifestPosition() const override {
@@ -2321,7 +2320,8 @@ private:
   unsigned ArgNo;
 };
 
-ChangeStatus AAAlignCallSiteArgument::updateImpl(Attributor &A) {
+ChangeStatus AAAlignCallSiteArgument::updateImpl(Attributor &A,
+                                                 InformationCache &InfoCache) {
   // NOTE: Never look at the argument of the callee in this method.
   //       If we do this, "align" is always deduced because of the assumption.
 
@@ -2343,8 +2343,7 @@ ChangeStatus AAAlignCallSiteArgument::up
 /// ------------------ Function No-Return Attribute ----------------------------
 struct AANoReturnFunction final : public AANoReturn, BooleanState {
 
-  AANoReturnFunction(Function &F, InformationCache &InfoCache)
-      : AANoReturn(F, InfoCache) {}
+  AANoReturnFunction(Function &F) : AANoReturn(F) {}
 
   /// See AbstractAttribute::getState()
   /// {
@@ -2367,14 +2366,15 @@ struct AANoReturnFunction final : public
   }
 
   /// See AbstractAttribute::initialize(...).
-  void initialize(Attributor &A) override {
+  void initialize(Attributor &A, InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
     if (F.hasFnAttribute(getAttrKind()))
       indicateOptimisticFixpoint();
   }
 
   /// See AbstractAttribute::updateImpl(Attributor &A).
-  virtual ChangeStatus updateImpl(Attributor &A) override {
+  virtual ChangeStatus updateImpl(Attributor &A,
+                                  InformationCache &InfoCache) override {
     Function &F = getAnchorScope();
 
     // The map from instruction opcodes to those instructions in the function.
@@ -2444,10 +2444,10 @@ bool Attributor::checkForAllCallSites(Fu
   return true;
 }
 
-ChangeStatus Attributor::run() {
+ChangeStatus Attributor::run(InformationCache &InfoCache) {
   // Initialize all abstract attributes.
   for (AbstractAttribute *AA : AllAbstractAttributes)
-    AA->initialize(*this);
+    AA->initialize(*this, InfoCache);
 
   LLVM_DEBUG(dbgs() << "[Attributor] Identified and initialized "
                     << AllAbstractAttributes.size()
@@ -2479,7 +2479,7 @@ ChangeStatus Attributor::run() {
     // Update all abstract attribute in the work list and record the ones that
     // changed.
     for (AbstractAttribute *AA : Worklist)
-      if (AA->update(*this) == ChangeStatus::CHANGED)
+      if (AA->update(*this, InfoCache) == ChangeStatus::CHANGED)
         ChangedAAs.push_back(AA);
 
     // Reset the work list and repopulate with the changed abstract attributes.
@@ -2563,7 +2563,7 @@ ChangeStatus Attributor::run() {
   if (VerifyAttributor && FinishedAtFixpoint &&
       ManifestChange == ChangeStatus::CHANGED) {
     VerifyAttributor = false;
-    ChangeStatus VerifyStatus = run();
+    ChangeStatus VerifyStatus = run(InfoCache);
     if (VerifyStatus != ChangeStatus::UNCHANGED)
       llvm_unreachable(
           "Attributor verification failed, re-run did result in an IR change "
@@ -2583,22 +2583,22 @@ void Attributor::identifyDefaultAbstract
     DenseSet</* Attribute::AttrKind */ unsigned> *Whitelist) {
 
   // Check for dead BasicBlocks in every function.
-  registerAA(*new AAIsDeadFunction(F, InfoCache));
+  registerAA(*new AAIsDeadFunction(F));
 
   // Every function might be "will-return".
-  registerAA(*new AAWillReturnFunction(F, InfoCache));
+  registerAA(*new AAWillReturnFunction(F));
 
   // Every function can be nounwind.
-  registerAA(*new AANoUnwindFunction(F, InfoCache));
+  registerAA(*new AANoUnwindFunction(F));
 
   // Every function might be marked "nosync"
-  registerAA(*new AANoSyncFunction(F, InfoCache));
+  registerAA(*new AANoSyncFunction(F));
 
   // Every function might be "no-free".
-  registerAA(*new AANoFreeFunction(F, InfoCache));
+  registerAA(*new AANoFreeFunction(F));
 
   // Every function might be "no-return".
-  registerAA(*new AANoReturnFunction(F, InfoCache));
+  registerAA(*new AANoReturnFunction(F));
 
   // Return attributes are only appropriate if the return type is non void.
   Type *ReturnType = F.getReturnType();
@@ -2606,26 +2606,26 @@ void Attributor::identifyDefaultAbstract
     // Argument attribute "returned" --- Create only one per function even
     // though it is an argument attribute.
     if (!Whitelist || Whitelist->count(AAReturnedValues::ID))
-      registerAA(*new AAReturnedValuesImpl(F, InfoCache));
+      registerAA(*new AAReturnedValuesImpl(F));
 
     if (ReturnType->isPointerTy()) {
       // Every function with pointer return type might be marked align.
       if (!Whitelist || Whitelist->count(AAAlignReturned::ID))
-        registerAA(*new AAAlignReturned(F, InfoCache));
+        registerAA(*new AAAlignReturned(F));
 
       // Every function with pointer return type might be marked nonnull.
       if (!Whitelist || Whitelist->count(AANonNullReturned::ID))
-        registerAA(*new AANonNullReturned(F, InfoCache));
+        registerAA(*new AANonNullReturned(F));
 
       // Every function with pointer return type might be marked noalias.
       if (!Whitelist || Whitelist->count(AANoAliasReturned::ID))
-        registerAA(*new AANoAliasReturned(F, InfoCache));
+        registerAA(*new AANoAliasReturned(F));
 
       // Every function with pointer return type might be marked
       // dereferenceable.
       if (ReturnType->isPointerTy() &&
           (!Whitelist || Whitelist->count(AADereferenceableReturned::ID)))
-        registerAA(*new AADereferenceableReturned(F, InfoCache));
+        registerAA(*new AADereferenceableReturned(F));
     }
   }
 
@@ -2633,15 +2633,15 @@ void Attributor::identifyDefaultAbstract
     if (Arg.getType()->isPointerTy()) {
       // Every argument with pointer type might be marked nonnull.
       if (!Whitelist || Whitelist->count(AANonNullArgument::ID))
-        registerAA(*new AANonNullArgument(Arg, InfoCache));
+        registerAA(*new AANonNullArgument(Arg));
 
       // Every argument with pointer type might be marked dereferenceable.
       if (!Whitelist || Whitelist->count(AADereferenceableArgument::ID))
-        registerAA(*new AADereferenceableArgument(Arg, InfoCache));
+        registerAA(*new AADereferenceableArgument(Arg));
 
       // Every argument with pointer type might be marked align.
       if (!Whitelist || Whitelist->count(AAAlignArgument::ID))
-        registerAA(*new AAAlignArgument(Arg, InfoCache));
+        registerAA(*new AAAlignArgument(Arg));
     }
   }
 
@@ -2687,17 +2687,16 @@ void Attributor::identifyDefaultAbstract
 
         // Call site argument attribute "non-null".
         if (!Whitelist || Whitelist->count(AANonNullCallSiteArgument::ID))
-          registerAA(*new AANonNullCallSiteArgument(CS, i, InfoCache), i);
+          registerAA(*new AANonNullCallSiteArgument(CS, i), i);
 
         // Call site argument attribute "dereferenceable".
         if (!Whitelist ||
             Whitelist->count(AADereferenceableCallSiteArgument::ID))
-          registerAA(*new AADereferenceableCallSiteArgument(CS, i, InfoCache),
-                     i);
+          registerAA(*new AADereferenceableCallSiteArgument(CS, i), i);
 
         // Call site argument attribute "align".
         if (!Whitelist || Whitelist->count(AAAlignCallSiteArgument::ID))
-          registerAA(*new AAAlignCallSiteArgument(CS, i, InfoCache), i);
+          registerAA(*new AAAlignCallSiteArgument(CS, i), i);
       }
     }
   }
@@ -2781,7 +2780,7 @@ static bool runAttributorOnModule(Module
     A.identifyDefaultAbstractAttributes(F, InfoCache);
   }
 
-  return A.run() == ChangeStatus::CHANGED;
+  return A.run(InfoCache) == ChangeStatus::CHANGED;
 }
 
 PreservedAnalyses AttributorPass::run(Module &M, ModuleAnalysisManager &AM) {




More information about the llvm-commits mailing list