From 1a74645a70b38b48ff93251f7e7e51b2ab2ab403 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Sun, 20 Oct 2019 22:28:49 -0500 Subject: [Attributor] Make IntegerState more flexible To make IntegerState more flexible but also less error prone we split it up into (1) incrementing, (2) decrementing, and (3) bit-tracking states. This adds functionality compared to before and disallows misuse, e.g., "incrementing" updates on a bit-tracking state. Part of the change is a single operator in the base class which simplifies helper functions that deal with states. There are certain functional changes but all of which should actually be corrections. --- llvm/lib/Transforms/IPO/Attributor.cpp | 43 ++++++++++++++-------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 95f47345d8f..a811471d37e 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -517,30 +517,17 @@ void IRPosition::verify() { } namespace { -/// Helper functions to clamp a state \p S of type \p StateType with the +/// Helper function to clamp a state \p S of type \p StateType with the /// information in \p R and indicate/return if \p S did change (as-in update is /// required to be run again). -/// -///{ template -ChangeStatus clampStateAndIndicateChange(StateType &S, const StateType &R); - -template <> -ChangeStatus clampStateAndIndicateChange(IntegerState &S, - const IntegerState &R) { +ChangeStatus clampStateAndIndicateChange(StateType &S, const StateType &R) { auto Assumed = S.getAssumed(); S ^= R; return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED : ChangeStatus::CHANGED; } -template <> -ChangeStatus clampStateAndIndicateChange(BooleanState &S, - const BooleanState &R) { - return clampStateAndIndicateChange(S, R); -} -///} - /// Clamp the information known for all returned values of a function /// (identified by \p QueryingAA) into \p S. template @@ -1609,7 +1596,7 @@ struct AANonNullImpl : AANonNull { bool TrackUse = false; getKnownNonNullAndDerefBytesForUse(A, *this, getAssociatedValue(), U, I, IsNonNull, TrackUse); - takeKnownMaximum(IsNonNull); + setKnown(IsNonNull); return TrackUse; } @@ -1661,7 +1648,7 @@ struct AANonNullFloating const DataLayout &DL = A.getDataLayout(); - auto VisitValueCB = [&](Value &V, AAAlign::StateType &T, + auto VisitValueCB = [&](Value &V, AANonNull::StateType &T, bool Stripped) -> bool { const auto &AA = A.getAAFor(*this, IRPosition::value(V)); if (!Stripped && this == &AA) { @@ -2463,10 +2450,10 @@ struct AAIsDeadCallSite final : AAIsDeadImpl { template <> ChangeStatus clampStateAndIndicateChange(DerefState &S, const DerefState &R) { - ChangeStatus CS0 = clampStateAndIndicateChange( + ChangeStatus CS0 = clampStateAndIndicateChange( S.DerefBytesState, R.DerefBytesState); ChangeStatus CS1 = - clampStateAndIndicateChange(S.GlobalState, R.GlobalState); + clampStateAndIndicateChange(S.GlobalState, R.GlobalState); return CS0 | CS1; } @@ -2967,7 +2954,7 @@ struct AANoCaptureImpl : public AANoCapture { /// state in memory and through "returning/throwing", respectively. static void determineFunctionCaptureCapabilities(const IRPosition &IRP, const Function &F, - IntegerState &State) { + BitIntegerState &State) { // TODO: Once we have memory behavior attributes we should use them here. // If we know we cannot communicate or write to memory, we do not care about @@ -3036,7 +3023,7 @@ struct AACaptureUseTracker final : public CaptureTracker { /// the search is stopped with \p CapturedInMemory and \p CapturedInInteger /// conservatively set to true. AACaptureUseTracker(Attributor &A, AANoCapture &NoCaptureAA, - const AAIsDead &IsDeadAA, IntegerState &State, + const AAIsDead &IsDeadAA, BitIntegerState &State, SmallVectorImpl &PotentialCopies, unsigned &RemainingUsesToExplore) : A(A), NoCaptureAA(NoCaptureAA), IsDeadAA(IsDeadAA), State(State), @@ -3155,7 +3142,7 @@ private: const AAIsDead &IsDeadAA; /// The state currently updated. - IntegerState &State; + BitIntegerState &State; /// Set of potential copies of the tracked value. SmallVectorImpl &PotentialCopies; @@ -3238,7 +3225,7 @@ ChangeStatus AANoCaptureImpl::updateImpl(Attributor &A) { while (T.isAssumed(NO_CAPTURE_MAYBE_RETURNED) && Idx < PotentialCopies.size()) Tracker.valueMayBeCaptured(PotentialCopies[Idx++]); - AAAlign::StateType &S = getState(); + AANoCapture::StateType &S = getState(); auto Assumed = S.getAssumed(); S.intersectAssumedBits(T.getAssumed()); return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED @@ -3787,7 +3774,7 @@ struct AAMemoryBehaviorImpl : public AAMemoryBehavior { /// Return the memory behavior information encoded in the IR for \p IRP. static void getKnownStateFromValue(const IRPosition &IRP, - IntegerState &State) { + BitIntegerState &State) { SmallVector Attrs; IRP.getAttrs(AttrKinds, Attrs); for (const Attribute &Attr : Attrs) { @@ -4036,7 +4023,8 @@ struct AAMemoryBehaviorCallSite final : AAMemoryBehaviorImpl { const IRPosition &FnPos = IRPosition::function(*F); auto &FnAA = A.getAAFor(*this, FnPos); return clampStateAndIndicateChange( - getState(), static_cast(FnAA.getState())); + getState(), + static_cast(FnAA.getState())); } /// See AbstractAttribute::trackStatistics() @@ -4903,7 +4891,10 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const IRPosition &Pos) { << Pos.getAnchorValue().getName() << "@" << Pos.getArgNo() << "]}"; } -raw_ostream &llvm::operator<<(raw_ostream &OS, const IntegerState &S) { +template +raw_ostream &llvm:: +operator<<(raw_ostream &OS, + const IntegerStateBase &S) { return OS << "(" << S.getKnown() << "-" << S.getAssumed() << ")" << static_cast(S); } -- cgit v1.2.3