@@ -1754,11 +1754,14 @@ struct IRAttributeManifest {
17541754};
17551755
17561756// / Helper to tie a abstract state implementation to an abstract attribute.
1757- template <typename StateTy, typename Base>
1758- struct StateWrapper : public StateTy , public Base {
1757+ template <typename StateTy, typename Base, class ... Ts >
1758+ struct StateWrapper : public Base , public StateTy {
17591759 // / Provide static access to the type of the state.
17601760 using StateType = StateTy;
17611761
1762+ StateWrapper (const IRPosition &IRP, Ts... Args)
1763+ : Base(IRP), StateTy(Args...) {}
1764+
17621765 // / See AbstractAttribute::getState(...).
17631766 StateType &getState () override { return *this ; }
17641767
@@ -1768,15 +1771,15 @@ struct StateWrapper : public StateTy, public Base {
17681771
17691772// / Helper class that provides common functionality to manifest IR attributes.
17701773template <Attribute::AttrKind AK, typename Base>
1771- struct IRAttribute : public IRPosition , public Base {
1772- IRAttribute (const IRPosition &IRP) : IRPosition(IRP) {}
1773- ~IRAttribute () {}
1774+ struct IRAttribute : public Base {
1775+ IRAttribute (const IRPosition &IRP) : Base(IRP) {}
17741776
17751777 // / See AbstractAttribute::initialize(...).
17761778 virtual void initialize (Attributor &A) override {
17771779 const IRPosition &IRP = this ->getIRPosition ();
17781780 if (isa<UndefValue>(IRP.getAssociatedValue ()) ||
1779- hasAttr (getAttrKind (), /* IgnoreSubsumingPositions */ false , &A)) {
1781+ this ->hasAttr (getAttrKind (), /* IgnoreSubsumingPositions */ false ,
1782+ &A)) {
17801783 this ->getState ().indicateOptimisticFixpoint ();
17811784 return ;
17821785 }
@@ -1796,11 +1799,12 @@ struct IRAttribute : public IRPosition, public Base {
17961799
17971800 // / See AbstractAttribute::manifest(...).
17981801 ChangeStatus manifest (Attributor &A) override {
1799- if (isa<UndefValue>(getIRPosition ().getAssociatedValue ()))
1802+ if (isa<UndefValue>(this -> getIRPosition ().getAssociatedValue ()))
18001803 return ChangeStatus::UNCHANGED;
18011804 SmallVector<Attribute, 4 > DeducedAttrs;
1802- getDeducedAttributes (getAnchorValue ().getContext (), DeducedAttrs);
1803- return IRAttributeManifest::manifestAttrs (A, getIRPosition (), DeducedAttrs);
1805+ getDeducedAttributes (this ->getAnchorValue ().getContext (), DeducedAttrs);
1806+ return IRAttributeManifest::manifestAttrs (A, this ->getIRPosition (),
1807+ DeducedAttrs);
18041808 }
18051809
18061810 // / Return the kind that identifies the abstract attribute implementation.
@@ -1811,9 +1815,6 @@ struct IRAttribute : public IRPosition, public Base {
18111815 SmallVectorImpl<Attribute> &Attrs) const {
18121816 Attrs.emplace_back (Attribute::get (Ctx, getAttrKind ()));
18131817 }
1814-
1815- // / Return an IR position, see struct IRPosition.
1816- const IRPosition &getIRPosition () const override { return *this ; }
18171818};
18181819
18191820// / Base struct for all "concrete attribute" deductions.
@@ -1859,9 +1860,11 @@ struct IRAttribute : public IRPosition, public Base {
18591860// / both directions will be added in the future.
18601861// / NOTE: The mechanics of adding a new "concrete" abstract attribute are
18611862// / described in the file comment.
1862- struct AbstractAttribute {
1863+ struct AbstractAttribute : public IRPosition {
18631864 using StateType = AbstractState;
18641865
1866+ AbstractAttribute (const IRPosition &IRP) : IRPosition(IRP) {}
1867+
18651868 // / Virtual destructor.
18661869 virtual ~AbstractAttribute () {}
18671870
@@ -1880,7 +1883,8 @@ struct AbstractAttribute {
18801883 virtual const StateType &getState () const = 0;
18811884
18821885 // / Return an IR position, see struct IRPosition.
1883- virtual const IRPosition &getIRPosition () const = 0;
1886+ const IRPosition &getIRPosition () const { return *this ; };
1887+ IRPosition &getIRPosition () { return *this ; };
18841888
18851889 // / Helper functions, for debug purposes only.
18861890 // /{
@@ -2096,9 +2100,9 @@ struct AAWillReturn
20962100
20972101// / An abstract attribute for undefined behavior.
20982102struct AAUndefinedBehavior
2099- : public StateWrapper<BooleanState, AbstractAttribute>,
2100- public IRPosition {
2101- AAUndefinedBehavior (const IRPosition &IRP, Attributor &A) : IRPosition (IRP) {}
2103+ : public StateWrapper<BooleanState, AbstractAttribute> {
2104+ using Base = StateWrapper<BooleanState, AbstractAttribute>;
2105+ AAUndefinedBehavior (const IRPosition &IRP, Attributor &A) : Base (IRP) {}
21022106
21032107 // / Return true if "undefined behavior" is assumed.
21042108 bool isAssumedToCauseUB () const { return getAssumed (); }
@@ -2112,9 +2116,6 @@ struct AAUndefinedBehavior
21122116 // / Return true if "undefined behavior" is known for a specific instruction.
21132117 virtual bool isKnownToCauseUB (Instruction *I) const = 0;
21142118
2115- // / Return an IR position, see struct IRPosition.
2116- const IRPosition &getIRPosition () const override { return *this ; }
2117-
21182119 // / Create an abstract attribute view for the position \p IRP.
21192120 static AAUndefinedBehavior &createForPosition (const IRPosition &IRP,
21202121 Attributor &A);
@@ -2124,9 +2125,9 @@ struct AAUndefinedBehavior
21242125};
21252126
21262127// / An abstract interface to determine reachability of point A to B.
2127- struct AAReachability : public StateWrapper <BooleanState, AbstractAttribute>,
2128- public IRPosition {
2129- AAReachability (const IRPosition &IRP, Attributor &A) : IRPosition (IRP) {}
2128+ struct AAReachability : public StateWrapper <BooleanState, AbstractAttribute> {
2129+ using Base = StateWrapper<BooleanState, AbstractAttribute>;
2130+ AAReachability (const IRPosition &IRP, Attributor &A) : Base (IRP) {}
21302131
21312132 // / Returns true if 'From' instruction is assumed to reach, 'To' instruction.
21322133 // / Users should provide two positions they are interested in, and the class
@@ -2143,9 +2144,6 @@ struct AAReachability : public StateWrapper<BooleanState, AbstractAttribute>,
21432144 return isPotentiallyReachable (From, To);
21442145 }
21452146
2146- // / Return an IR position, see struct IRPosition.
2147- const IRPosition &getIRPosition () const override { return *this ; }
2148-
21492147 // / Create an abstract attribute view for the position \p IRP.
21502148 static AAReachability &createForPosition (const IRPosition &IRP,
21512149 Attributor &A);
@@ -2212,9 +2210,9 @@ struct AANoReturn
22122210};
22132211
22142212// / An abstract interface for liveness abstract attribute.
2215- struct AAIsDead : public StateWrapper <BooleanState, AbstractAttribute>,
2216- public IRPosition {
2217- AAIsDead (const IRPosition &IRP, Attributor &A) : IRPosition (IRP) {}
2213+ struct AAIsDead : public StateWrapper <BooleanState, AbstractAttribute> {
2214+ using Base = StateWrapper<BooleanState, AbstractAttribute>;
2215+ AAIsDead (const IRPosition &IRP, Attributor &A) : Base (IRP) {}
22182216
22192217protected:
22202218 // / The query functions are protected such that other attributes need to go
@@ -2253,9 +2251,6 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute>,
22532251 }
22542252
22552253public:
2256- // / Return an IR position, see struct IRPosition.
2257- const IRPosition &getIRPosition () const override { return *this ; }
2258-
22592254 // / Create an abstract attribute view for the position \p IRP.
22602255 static AAIsDead &createForPosition (const IRPosition &IRP, Attributor &A);
22612256
@@ -2531,12 +2526,9 @@ struct AANoCapture
25312526};
25322527
25332528// / An abstract interface for value simplify abstract attribute.
2534- struct AAValueSimplify : public StateWrapper <BooleanState, AbstractAttribute>,
2535- public IRPosition {
2536- AAValueSimplify (const IRPosition &IRP, Attributor &A) : IRPosition(IRP) {}
2537-
2538- // / Return an IR position, see struct IRPosition.
2539- const IRPosition &getIRPosition () const { return *this ; }
2529+ struct AAValueSimplify : public StateWrapper <BooleanState, AbstractAttribute> {
2530+ using Base = StateWrapper<BooleanState, AbstractAttribute>;
2531+ AAValueSimplify (const IRPosition &IRP, Attributor &A) : Base(IRP) {}
25402532
25412533 // / Return an assumed simplified value if a single candidate is found. If
25422534 // / there cannot be one, return original value. If it is not clear yet, return
@@ -2551,19 +2543,16 @@ struct AAValueSimplify : public StateWrapper<BooleanState, AbstractAttribute>,
25512543 static const char ID;
25522544};
25532545
2554- struct AAHeapToStack : public StateWrapper <BooleanState, AbstractAttribute>,
2555- public IRPosition {
2556- AAHeapToStack (const IRPosition &IRP, Attributor &A) : IRPosition (IRP) {}
2546+ struct AAHeapToStack : public StateWrapper <BooleanState, AbstractAttribute> {
2547+ using Base = StateWrapper<BooleanState, AbstractAttribute>;
2548+ AAHeapToStack (const IRPosition &IRP, Attributor &A) : Base (IRP) {}
25572549
25582550 // / Returns true if HeapToStack conversion is assumed to be possible.
25592551 bool isAssumedHeapToStack () const { return getAssumed (); }
25602552
25612553 // / Returns true if HeapToStack conversion is known to be possible.
25622554 bool isKnownHeapToStack () const { return getKnown (); }
25632555
2564- // / Return an IR position, see struct IRPosition.
2565- const IRPosition &getIRPosition () const { return *this ; }
2566-
25672556 // / Create an abstract attribute view for the position \p IRP.
25682557 static AAHeapToStack &createForPosition (const IRPosition &IRP, Attributor &A);
25692558
@@ -2581,9 +2570,10 @@ struct AAHeapToStack : public StateWrapper<BooleanState, AbstractAttribute>,
25812570// / (=nocapture), it is (for now) not written (=readonly & noalias), we know
25822571// / what values are necessary to make the private copy look like the original
25832572// / one, and the values we need can be loaded (=dereferenceable).
2584- struct AAPrivatizablePtr : public StateWrapper <BooleanState, AbstractAttribute>,
2585- public IRPosition {
2586- AAPrivatizablePtr (const IRPosition &IRP, Attributor &A) : IRPosition(IRP) {}
2573+ struct AAPrivatizablePtr
2574+ : public StateWrapper<BooleanState, AbstractAttribute> {
2575+ using Base = StateWrapper<BooleanState, AbstractAttribute>;
2576+ AAPrivatizablePtr (const IRPosition &IRP, Attributor &A) : Base(IRP) {}
25872577
25882578 // / Returns true if pointer privatization is assumed to be possible.
25892579 bool isAssumedPrivatizablePtr () const { return getAssumed (); }
@@ -2595,13 +2585,6 @@ struct AAPrivatizablePtr : public StateWrapper<BooleanState, AbstractAttribute>,
25952585 // / value. None means it is not clear yet, nullptr means there is none.
25962586 virtual Optional<Type *> getPrivatizableType () const = 0;
25972587
2598- // / Return an IR position, see struct IRPosition.
2599- // /
2600- // /{
2601- IRPosition &getIRPosition () { return *this ; }
2602- const IRPosition &getIRPosition () const { return *this ; }
2603- // /}
2604-
26052588 // / Create an abstract attribute view for the position \p IRP.
26062589 static AAPrivatizablePtr &createForPosition (const IRPosition &IRP,
26072590 Attributor &A);
@@ -2820,15 +2803,11 @@ struct AAMemoryLocation
28202803};
28212804
28222805// / An abstract interface for range value analysis.
2823- struct AAValueConstantRange : public IntegerRangeState ,
2824- public AbstractAttribute,
2825- public IRPosition {
2806+ struct AAValueConstantRange
2807+ : public StateWrapper<IntegerRangeState, AbstractAttribute, uint32_t > {
2808+ using Base = StateWrapper<IntegerRangeState, AbstractAttribute, uint32_t >;
28262809 AAValueConstantRange (const IRPosition &IRP, Attributor &A)
2827- : IntegerRangeState(IRP.getAssociatedType()->getIntegerBitWidth ()),
2828- IRPosition(IRP) {}
2829-
2830- // / Return an IR position, see struct IRPosition.
2831- const IRPosition &getIRPosition () const override { return *this ; }
2810+ : Base(IRP, IRP.getAssociatedType()->getIntegerBitWidth ()) {}
28322811
28332812 // / See AbstractAttribute::getState(...).
28342813 IntegerRangeState &getState () override { return *this ; }
0 commit comments