17#include <llvm/ADT/PointerUnion.h>
22using TranslationMap = std::unordered_map<SourceRef, SourceRefLatticeValue, SourceRef::Hash>;
37 using ArrayTy = std::vector<std::unique_ptr<SourceRefLatticeValue>>;
60 std::pair<SourceRefLatticeValue, mlir::ChangeResult>
69 std::pair<SourceRefLatticeValue, mlir::ChangeResult>
74 std::pair<SourceRefLatticeValue, mlir::ChangeResult>
75 extract(
const std::vector<SourceRefIndex> &indices)
const;
84 virtual std::pair<SourceRefLatticeValue, mlir::ChangeResult>
93 using ValueTy = llvm::PointerUnion<mlir::Value, mlir::Operation *>;
94 using ValueMap = mlir::DenseMap<ValueTy, SourceRefLatticeValue>;
98 using Ref2Val = mlir::DenseMap<SourceRef, mlir::DenseSet<ValueTy>>;
99 using AbstractDenseLattice::AbstractDenseLattice;
107 static mlir::FailureOr<SourceRef>
getSourceRef(mlir::Value val);
112 mlir::ChangeResult
join(
const AbstractDenseLattice &rhs)
override {
117 mlir::ChangeResult
meet(
const AbstractDenseLattice & )
override {
118 llvm::report_fatal_error(
"meet operation is not supported for SourceRefLattice");
119 return mlir::ChangeResult::NoChange;
122 void print(mlir::raw_ostream &os)
const override;
138 size_t size()
const {
return valMap.size(); }
144 ValueMap::iterator
begin() {
return valMap.begin(); }
145 ValueMap::iterator
end() {
return valMap.end(); }
146 ValueMap::const_iterator
begin()
const {
return valMap.begin(); }
147 ValueMap::const_iterator
end()
const {
return valMap.end(); }
161raw_ostream &
operator<<(raw_ostream &os, llvm::PointerUnion<mlir::Value, mlir::Operation *> ptr);
This file implements (LLZK-tailored) dense data-flow analysis using the data-flow analysis framework.
A value at a given point of the SourceRefLattice.
virtual std::pair< SourceRefLatticeValue, mlir::ChangeResult > elementwiseTransform(llvm::function_ref< SourceRef(const SourceRef &)> transform) const
Perform a recursive transformation over all elements of this value and return a new value with the mo...
std::pair< SourceRefLatticeValue, mlir::ChangeResult > extract(const std::vector< SourceRefIndex > &indices) const
Perform an array.extract or array.read operation, depending on how many indices are provided.
virtual ~SourceRefLatticeValue()=default
std::pair< SourceRefLatticeValue, mlir::ChangeResult > referenceField(SymbolLookupResult< component::FieldDefOp > fieldRef) const
Add the given fieldRef to the SourceRefs contained within this value.
SourceRefLatticeValue(mlir::ArrayRef< int64_t > shape)
const SourceRef & getSingleValue() const
mlir::ChangeResult insert(const SourceRef &rhs)
Directly insert the ref into this value.
std::pair< SourceRefLatticeValue, mlir::ChangeResult > translate(const TranslationMap &translation) const
For the refs contained in this value, translate them given the translation map and return the transfo...
SourceRefLatticeValue(ScalarTy s)
mlir::ChangeResult translateScalar(const TranslationMap &translation)
Translate this value using the translation map, assuming this value is a scalar.
SourceRefLatticeValue(SourceRef r)
A lattice for use in dense analysis.
mlir::ChangeResult join(const AbstractDenseLattice &rhs) override
Maximum upper bound.
const ValueMap & getMap() const
mlir::ChangeResult meet(const AbstractDenseLattice &) override
Minimum lower bound.
mlir::DenseMap< SourceRef, mlir::DenseSet< ValueTy > > Ref2Val
ValueMap::const_iterator end() const
friend mlir::raw_ostream & operator<<(mlir::raw_ostream &os, const SourceRefLattice &v)
const Ref2Val & getRef2Val() const
mlir::DenseMap< ValueTy, SourceRefLatticeValue > ValueMap
mlir::DenseSet< ValueTy > ValueSet
void print(mlir::raw_ostream &os) const override
static mlir::FailureOr< SourceRef > getSourceRef(mlir::Value val)
If val is the source of other values (i.e., a block argument from the function args or a constant),...
ValueSet lookupValues(const SourceRef &r) const
mlir::ChangeResult setValues(const ValueMap &rhs)
SourceRefLatticeValue getOrDefault(ValueTy v) const
mlir::ChangeResult setValue(ValueTy v, const SourceRefLatticeValue &rhs)
ValueMap::iterator begin()
ValueMap::const_iterator begin() const
llvm::PointerUnion< mlir::Value, mlir::Operation * > ValueTy
SourceRefLatticeValue getReturnValue(unsigned i) const
A reference to a "source", which is the base value from which other SSA values are derived.
bool isSingleValue() const
const ScalarTy & getScalarValue() const
raw_ostream & operator<<(raw_ostream &os, llvm::PointerUnion< mlir::Value, mlir::Operation * > ptr)
mlir::dataflow::AbstractDenseLattice AbstractDenseLattice
void ensure(bool condition, const llvm::Twine &errMsg)
std::unordered_map< SourceRef, SourceRefLatticeValue, SourceRef::Hash > TranslationMap