diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -100,6 +100,35 @@ BaseTy getAssumed() const { return Assumed; } protected: + /// Copy the bits set in \p BitsEncoding from \p From to \p To. + static void copyBits(BaseTy &To, const BaseTy From, BaseTy BitsEncoding) { + BaseTy UnaffectedBits = To & (~BitsEncoding); + BaseTy AffectedBits = From & BitsEncoding; + To = UnaffectedBits | AffectedBits; + } + + /// Set the bits of \p Target also set in \p BitsEncoding. + static void setBits(BaseTy &Target, BaseTy BitsEncoding) { + Target = Target | BitsEncoding; + } + + /// Unset the bits of \p Target also set in \p BitsEncoding. + static BaseTy &unsetBits(BaseTy &Target, BaseTy BitsEncoding) { + Target = Target & ~BitsEncoding; + return Target; + } + + /// Intersect the bits of \p Target also set in \p BitsEncoding. + static BaseTy &intersectBits(BaseTy &Target, BaseTy BitsEncoding) { + Target = Target & BitsEncoding; + return Target; + } + + /// Return true if the bits set in \p BitsEncoding are set in \p Source. + static bool testBits(BaseTy Source, BaseTy BitsEncoding) { + return (Source & BitsEncoding) == BitsEncoding; + } + /// The known state encoding in an integer of type BaseTy. BaseTy Known; @@ -691,17 +720,17 @@ /// See AANoCapture::isAssumedNoCapture(...). bool isAssumedNoCapture() const override { - return getAssumed() == BEST_STATE; + return testBits(getAssumed(), NOT_CAPTURED | NOT_RETURNED); } /// See AANoCapture::isKnownNoCaptureMaybeReturned(...). bool isKnownNoCaptureMaybeReturned() const override { - return getKnown() & NOT_CAPTURED; + return testBits(getKnown(), NOT_CAPTURED); } /// See AANoCapture::isAssumedNoCaptureMaybeReturned(...). bool isAssumedNoCaptureMaybeReturned() const override { - return getAssumed() & NOT_CAPTURED; + return testBits(getAssumed(), NOT_CAPTURED); } /// see AbstractAttribute::isAssumedNoCaptureMaybeReturned(...). @@ -926,7 +955,7 @@ if (!AssumedNoCapture) indicateFixpoint(/* Optimistic */ false); else if (MaybeReturned) - Assumed = Known | (Assumed & ~NOT_RETURNED); + setBits(unsetBits(Assumed, NOT_RETURNED), Known); return (AssumedState == getAssumed()) ? ChangeStatus::UNCHANGED : ChangeStatus::CHANGED;