From e1e844d6b0997b58625a59ab79d2f9aaf9c71bfd Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Wed, 14 Aug 2019 21:35:20 +0000 Subject: [PATCH] [Attributor][NFC] Add merge/join/clamp operators to the IntegerState Differential Revision: https://reviews.llvm.org/D66146 llvm-svn: 368925 --- llvm/include/llvm/Transforms/IPO/Attributor.h | 25 +++++++++++++++++++++++++ llvm/lib/Transforms/IPO/Attributor.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index ed3e572..484dd0c 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -887,6 +887,31 @@ struct IntegerState : public AbstractState { this->getKnown() == R.getKnown(); } + /// Inequality for IntegerState. + bool operator!=(const IntegerState &R) const { return !(*this == R); } + + /// "Clamp" this state with \p R. The result is the maximum of the known + /// information but the minimum of the assumed. + IntegerState operator^=(const IntegerState &R) { + takeKnownMaximum(R.Known); + takeAssumedMinimum(R.Assumed); + return *this; + } + + /// Make this the minimum, known and assumed, of this state and \p R. + IntegerState operator&=(const IntegerState &R) { + Known = std::min(Known, R.Known); + Assumed = std::min(Assumed, R.Assumed); + return *this; + } + + /// Make this the maximum, known and assumed, of this state and \p R. + IntegerState operator|=(const IntegerState &R) { + Known = std::max(Known, R.Known); + Assumed = std::max(Assumed, R.Assumed); + return *this; + } + private: /// The known state encoding in an integer of type base_t. base_t Known = getWorstState(); diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index b5d80dc..4a1b352 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1650,6 +1650,30 @@ struct DerefState : AbstractState { return this->DerefBytesState == R.DerefBytesState && this->GlobalState == R.GlobalState; } + + /// Inequality for IntegerState. + bool operator!=(const DerefState &R) { return !(*this == R); } + + /// See IntegerState::operator^= + DerefState operator^=(const DerefState &R) { + DerefBytesState ^= R.DerefBytesState; + GlobalState ^= R.GlobalState; + return *this; + } + + /// See IntegerState::operator&= + DerefState operator&=(const DerefState &R) { + DerefBytesState &= R.DerefBytesState; + GlobalState &= R.GlobalState; + return *this; + } + + /// See IntegerState::operator|= + DerefState operator|=(const DerefState &R) { + DerefBytesState |= R.DerefBytesState; + GlobalState |= R.GlobalState; + return *this; + } }; struct AADereferenceableImpl : AADereferenceable, DerefState { -- 2.7.4