Skip to content

Commit

Permalink
Revert "[Attributor] Replace AAValueSimplify with AAPotentialValues"
Browse files Browse the repository at this point in the history
This reverts commit da50dab.

Patch broke AMD GPU OpenMP offload buildbots.
https://lab.llvm.org/buildbot/#/builders/193/builds/13246
  • Loading branch information
jdoerfert committed Jun 9, 2022
1 parent 746908a commit 6555558
Show file tree
Hide file tree
Showing 73 changed files with 3,676 additions and 4,924 deletions.
105 changes: 12 additions & 93 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Expand Up @@ -118,9 +118,7 @@
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DOTGraphTraits.h"
Expand Down Expand Up @@ -156,7 +154,6 @@ namespace AA {
enum ValueScope : uint8_t {
Intraprocedural = 1,
Interprocedural = 2,
AnyScope = Intraprocedural | Interprocedural,
};

struct ValueAndContext : public std::pair<Value *, const Instruction *> {
Expand Down Expand Up @@ -219,11 +216,12 @@ Constant *getInitialValueForObj(Value &Obj, Type &Ty,
/// \returns True if \p Objects contains all assumed underlying objects, and
/// false if something went wrong and the objects could not be
/// determined.
bool getAssumedUnderlyingObjects(
Attributor &A, const Value &Ptr, SmallSetVector<Value *, 8> &Objects,
const AbstractAttribute &QueryingAA, const Instruction *CtxI,
bool &UsedAssumedInformation, AA::ValueScope VS = AA::Interprocedural,
SmallPtrSetImpl<Value *> *SeenObjects = nullptr);
bool getAssumedUnderlyingObjects(Attributor &A, const Value &Ptr,
SmallVectorImpl<Value *> &Objects,
const AbstractAttribute &QueryingAA,
const Instruction *CtxI,
bool &UsedAssumedInformation,
AA::ValueScope VS = Interprocedural);

/// Collect all potential values \p LI could read into \p PotentialValues. That
/// is, the only values read by \p LI are assumed to be known and all are in
Expand Down Expand Up @@ -306,24 +304,6 @@ struct DenseMapInfo<AA::ValueAndContext>
}
};

template <>
struct DenseMapInfo<AA::ValueScope> : public DenseMapInfo<unsigned char> {
using Base = DenseMapInfo<unsigned char>;
static inline AA::ValueScope getEmptyKey() {
return AA::ValueScope(Base::getEmptyKey());
}
static inline AA::ValueScope getTombstoneKey() {
return AA::ValueScope(Base::getTombstoneKey());
}
static unsigned getHashValue(const AA::ValueScope &S) {
return Base::getHashValue(S);
}

static bool isEqual(const AA::ValueScope &LHS, const AA::ValueScope &RHS) {
return Base::isEqual(LHS, RHS);
}
};

/// The value passed to the line option that defines the maximal initialization
/// chain length.
extern unsigned MaxInitializationChainLength;
Expand Down Expand Up @@ -1683,34 +1663,22 @@ struct Attributor {
/// return None, otherwise return `nullptr`.
Optional<Value *> getAssumedSimplified(const IRPosition &IRP,
const AbstractAttribute &AA,
bool &UsedAssumedInformation,
AA::ValueScope S) {
return getAssumedSimplified(IRP, &AA, UsedAssumedInformation, S);
bool &UsedAssumedInformation) {
return getAssumedSimplified(IRP, &AA, UsedAssumedInformation);
}
Optional<Value *> getAssumedSimplified(const Value &V,
const AbstractAttribute &AA,
bool &UsedAssumedInformation,
AA::ValueScope S) {
bool &UsedAssumedInformation) {
return getAssumedSimplified(IRPosition::value(V), AA,
UsedAssumedInformation, S);
UsedAssumedInformation);
}

/// If \p V is assumed simplified, return it, if it is unclear yet,
/// return None, otherwise return `nullptr`. Same as the public version
/// except that it can be used without recording dependences on any \p AA.
Optional<Value *> getAssumedSimplified(const IRPosition &V,
const AbstractAttribute *AA,
bool &UsedAssumedInformation,
AA::ValueScope S);

/// Try to simplify \p IRP and in the scope \p S. If successful, true is
/// returned and all potential values \p IRP can take are put into \p Values.
/// If false is returned no other information is valid.
bool getAssumedSimplifiedValues(const IRPosition &IRP,
const AbstractAttribute *AA,
SmallVectorImpl<AA::ValueAndContext> &Values,
AA::ValueScope S,
bool &UsedAssumedInformation);
bool &UsedAssumedInformation);

/// Register \p CB as a simplification callback.
/// `Attributor::getAssumedSimplified` will use these callbacks before
Expand Down Expand Up @@ -4440,10 +4408,6 @@ template <typename MemberTy> struct PotentialValuesState : AbstractState {
return *this;
}

bool contains(const MemberTy &V) const {
return !isValidState() ? true : Set.contains(V);
}

protected:
SetTy &getAssumedSet() {
assert(isValidState() && "This set shoud not be used when it is invalid!");
Expand Down Expand Up @@ -4525,12 +4489,9 @@ template <typename MemberTy> struct PotentialValuesState : AbstractState {
};

using PotentialConstantIntValuesState = PotentialValuesState<APInt>;
using PotentialLLVMValuesState =
PotentialValuesState<std::pair<AA::ValueAndContext, AA::ValueScope>>;

raw_ostream &operator<<(raw_ostream &OS,
const PotentialConstantIntValuesState &R);
raw_ostream &operator<<(raw_ostream &OS, const PotentialLLVMValuesState &R);

/// An abstract interface for potential values analysis.
///
Expand All @@ -4546,7 +4507,7 @@ raw_ostream &operator<<(raw_ostream &OS, const PotentialLLVMValuesState &R);
/// 2. We tried to initialize on a Value that we cannot handle (e.g. an
/// operator we do not currently handle).
///
/// For non constant integers see AAPotentialValues.
/// TODO: Support values other than constant integers.
struct AAPotentialConstantValues
: public StateWrapper<PotentialConstantIntValuesState, AbstractAttribute> {
using Base = StateWrapper<PotentialConstantIntValuesState, AbstractAttribute>;
Expand Down Expand Up @@ -4600,48 +4561,6 @@ struct AAPotentialConstantValues
static const char ID;
};

struct AAPotentialValues
: public StateWrapper<PotentialLLVMValuesState, AbstractAttribute> {
using Base = StateWrapper<PotentialLLVMValuesState, AbstractAttribute>;
AAPotentialValues(const IRPosition &IRP, Attributor &A) : Base(IRP) {}

/// See AbstractAttribute::getState(...).
PotentialLLVMValuesState &getState() override { return *this; }
const PotentialLLVMValuesState &getState() const override { return *this; }

/// Create an abstract attribute view for the position \p IRP.
static AAPotentialValues &createForPosition(const IRPosition &IRP,
Attributor &A);

/// Extract the single value in \p Values if any.
static Value *getSingleValue(Attributor &A, const AbstractAttribute &AA,
const IRPosition &IRP,
SmallVectorImpl<AA::ValueAndContext> &Values);

/// See AbstractAttribute::getName()
const std::string getName() const override { return "AAPotentialValues"; }

/// See AbstractAttribute::getIdAddr()
const char *getIdAddr() const override { return &ID; }

/// This function should return true if the type of the \p AA is
/// AAPotentialValues
static bool classof(const AbstractAttribute *AA) {
return (AA->getIdAddr() == &ID);
}

/// Unique ID (due to the unique address)
static const char ID;

private:
virtual bool
getAssumedSimplifiedValues(Attributor &A,
SmallVectorImpl<AA::ValueAndContext> &Values,
AA::ValueScope) const = 0;

friend struct Attributor;
};

/// An abstract interface for all noundef attributes.
struct AANoUndef
: public IRAttribute<Attribute::NoUndef,
Expand Down

0 comments on commit 6555558

Please sign in to comment.