forked from OSchip/llvm-project
[Attributor] Reuse existing logic to avoid duplication
There was a TODO in AAValueConstantRangeArgument to reuse AAArgumentFromCallSiteArguments. We now do this by allowing new States to be build from the bestState.
This commit is contained in:
parent
224085409d
commit
ea5fabe60c
|
@ -1223,8 +1223,14 @@ template <typename base_ty, base_ty BestState, base_ty WorstState>
|
|||
struct IntegerStateBase : public AbstractState {
|
||||
using base_t = base_ty;
|
||||
|
||||
IntegerStateBase() {}
|
||||
IntegerStateBase(base_t Assumed) : Assumed(Assumed) {}
|
||||
|
||||
/// Return the best possible representable state.
|
||||
static constexpr base_t getBestState() { return BestState; }
|
||||
static constexpr base_t getBestState(const IntegerStateBase &) {
|
||||
return getBestState();
|
||||
}
|
||||
|
||||
/// Return the worst possible representable state.
|
||||
static constexpr base_t getWorstState() { return WorstState; }
|
||||
|
@ -1366,8 +1372,19 @@ template <typename base_ty = uint32_t, base_ty BestState = ~base_ty(0),
|
|||
base_ty WorstState = 0>
|
||||
struct IncIntegerState
|
||||
: public IntegerStateBase<base_ty, BestState, WorstState> {
|
||||
using super = IntegerStateBase<base_ty, BestState, WorstState>;
|
||||
using base_t = base_ty;
|
||||
|
||||
IncIntegerState() : super() {}
|
||||
IncIntegerState(base_t Assumed) : super(Assumed) {}
|
||||
|
||||
/// Return the best possible representable state.
|
||||
static constexpr base_t getBestState() { return BestState; }
|
||||
static constexpr base_t
|
||||
getBestState(const IncIntegerState<base_ty, BestState, WorstState> &) {
|
||||
return getBestState();
|
||||
}
|
||||
|
||||
/// Take minimum of assumed and \p Value.
|
||||
IncIntegerState &takeAssumedMinimum(base_t Value) {
|
||||
// Make sure we never loose "known value".
|
||||
|
@ -1436,8 +1453,12 @@ private:
|
|||
|
||||
/// Simple wrapper for a single bit (boolean) state.
|
||||
struct BooleanState : public IntegerStateBase<bool, 1, 0> {
|
||||
using super = IntegerStateBase<bool, 1, 0>;
|
||||
using base_t = IntegerStateBase::base_t;
|
||||
|
||||
BooleanState() : super() {}
|
||||
BooleanState(base_t Assumed) : super(Assumed) {}
|
||||
|
||||
/// Set the assumed value to \p Value but never below the known one.
|
||||
void setAssumed(bool Value) { Assumed &= (Known | Value); }
|
||||
|
||||
|
@ -1488,6 +1509,10 @@ struct IntegerRangeState : public AbstractState {
|
|||
: BitWidth(BitWidth), Assumed(ConstantRange::getEmpty(BitWidth)),
|
||||
Known(ConstantRange::getFull(BitWidth)) {}
|
||||
|
||||
IntegerRangeState(const ConstantRange &CR)
|
||||
: BitWidth(CR.getBitWidth()), Assumed(CR),
|
||||
Known(getWorstState(CR.getBitWidth())) {}
|
||||
|
||||
/// Return the worst possible representable state.
|
||||
static ConstantRange getWorstState(uint32_t BitWidth) {
|
||||
return ConstantRange::getFull(BitWidth);
|
||||
|
@ -1497,6 +1522,9 @@ struct IntegerRangeState : public AbstractState {
|
|||
static ConstantRange getBestState(uint32_t BitWidth) {
|
||||
return ConstantRange::getEmpty(BitWidth);
|
||||
}
|
||||
static ConstantRange getBestState(const IntegerRangeState &IRS) {
|
||||
return getBestState(IRS.getBitWidth());
|
||||
}
|
||||
|
||||
/// Return associated values' bit width.
|
||||
uint32_t getBitWidth() const { return BitWidth; }
|
||||
|
@ -2085,6 +2113,9 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute>,
|
|||
/// State for dereferenceable attribute
|
||||
struct DerefState : AbstractState {
|
||||
|
||||
static DerefState getBestState() { return DerefState(); }
|
||||
static DerefState getBestState(const DerefState &) { return getBestState(); }
|
||||
|
||||
/// State representing for dereferenceable bytes.
|
||||
IncIntegerState<> DerefBytesState;
|
||||
|
||||
|
|
|
@ -807,7 +807,7 @@ struct AAArgumentFromCallSiteArguments : public Base {
|
|||
|
||||
/// See AbstractAttribute::updateImpl(...).
|
||||
ChangeStatus updateImpl(Attributor &A) override {
|
||||
StateType S;
|
||||
StateType S(StateType::getBestState(this->getState()));
|
||||
clampCallSiteArgumentStates<AAType, StateType>(A, *this, S);
|
||||
// TODO: If we know we visited all incoming values, thus no are assumed
|
||||
// dead, we can take the known information from the state T.
|
||||
|
@ -5449,23 +5449,13 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
|
|||
}
|
||||
};
|
||||
|
||||
struct AAValueConstantRangeArgument final : public AAValueConstantRangeImpl {
|
||||
|
||||
struct AAValueConstantRangeArgument final
|
||||
: AAArgumentFromCallSiteArguments<
|
||||
AAValueConstantRange, AAValueConstantRangeImpl, IntegerRangeState> {
|
||||
AAValueConstantRangeArgument(const IRPosition &IRP)
|
||||
: AAValueConstantRangeImpl(IRP) {}
|
||||
|
||||
/// See AbstractAttribute::updateImpl(...).
|
||||
ChangeStatus updateImpl(Attributor &A) override {
|
||||
// TODO: Use AAArgumentFromCallSiteArguments
|
||||
|
||||
IntegerRangeState S(getBitWidth());
|
||||
clampCallSiteArgumentStates<AAValueConstantRange, IntegerRangeState>(
|
||||
A, *this, S);
|
||||
|
||||
// TODO: If we know we visited all incoming values, thus no are assumed
|
||||
// dead, we can take the known information from the state T.
|
||||
return clampStateAndIndicateChange<IntegerRangeState>(this->getState(), S);
|
||||
}
|
||||
: AAArgumentFromCallSiteArguments<
|
||||
AAValueConstantRange, AAValueConstantRangeImpl, IntegerRangeState>(
|
||||
IRP) {}
|
||||
|
||||
/// See AbstractAttribute::trackStatistics()
|
||||
void trackStatistics() const override {
|
||||
|
|
Loading…
Reference in New Issue