17#include <mlir/Analysis/DataFlow/DenseAnalysis.h>
19#include <llvm/ADT/PointerUnion.h>
24using TranslationMap = std::unordered_map<SourceRef, SourceRefLatticeValue, SourceRef::Hash>;
39 using ArrayTy = std::vector<std::unique_ptr<SourceRefLatticeValue>>;
73 std::pair<SourceRefLatticeValue, mlir::ChangeResult>
77 std::pair<SourceRefLatticeValue, mlir::ChangeResult>
85 mlir::ChangeResult
write(
87 bool joinWithExisting =
false
96 mlir::FailureOr<std::pair<SourceRefLatticeValue, mlir::ChangeResult>>
102 mlir::FailureOr<std::pair<SourceRefLatticeValue, mlir::ChangeResult>>
107 mlir::FailureOr<std::pair<SourceRefLatticeValue, mlir::ChangeResult>>
108 extract(
const std::vector<SourceRefIndex> &indices)
const;
120 virtual mlir::FailureOr<std::pair<SourceRefLatticeValue, mlir::ChangeResult>>
122 llvm::function_ref<mlir::FailureOr<SourceRef>(
const SourceRef &)> transform
132 using ValueTy = llvm::PointerUnion<mlir::Value, mlir::Operation *>;
133 using Ref2Val = mlir::DenseMap<SourceRef, mlir::DenseSet<ValueTy>>;
141 static mlir::FailureOr<SourceRef>
getSourceRef(mlir::Value val);
144 using AbstractSparseLattice::AbstractSparseLattice;
146 mlir::ChangeResult
join(
const AbstractSparseLattice &rhs)
override;
147 mlir::ChangeResult
meet(
const AbstractSparseLattice &rhs)
override;
148 void print(mlir::raw_ostream &os)
const override;
164raw_ostream &
operator<<(raw_ostream &os, llvm::PointerUnion<mlir::Value, mlir::Operation *> ptr);
This file provides LLZK's sparse forward data-flow analysis compatibility layer.
A value at a given point of the SourceRefLattice.
mlir::ChangeResult write(const std::vector< SourceRefIndex > &indices, const SourceRefLatticeValue &rhs, bool joinWithExisting=false)
Update the element or subarray selected by indices.
virtual ~SourceRefLatticeValue()=default
SourceRefLatticeValue & operator=(const SourceRefLatticeValue &)=default
mlir::FailureOr< std::pair< SourceRefLatticeValue, mlir::ChangeResult > > referencePodRecord(mlir::StringAttr recordName) const
Add the given pod recordName to the SourceRefs contained within this value.
mlir::ChangeResult remove(const SourceRef &ref)
Remove ref from this value's reference set or, for an array, from every element.
SourceRefLatticeValue(SourceRefLatticeValue &&)=default
mlir::ChangeResult replacePrefixesScalar(const TranslationMap &translation)
Replace matching prefixes in a scalar value without dropping unmatched references.
SourceRefLatticeValue(mlir::ArrayRef< int64_t > shape)
mlir::FailureOr< std::pair< SourceRefLatticeValue, mlir::ChangeResult > > referenceMember(SymbolLookupResult< component::MemberDefOp > memberRef) const
Add the given memberRef to the SourceRefs contained within this value.
virtual mlir::FailureOr< std::pair< SourceRefLatticeValue, mlir::ChangeResult > > elementwiseTransform(llvm::function_ref< mlir::FailureOr< SourceRef >(const SourceRef &)> transform) const
Perform a recursive transformation over all elements of this value and return a new value with the mo...
const SourceRef & getSingleValue() const
mlir::ChangeResult insert(const SourceRef &rhs)
Directly insert the ref into this value.
SourceRefLatticeValue(const SourceRefLatticeValue &)=default
std::pair< SourceRefLatticeValue, mlir::ChangeResult > translate(const TranslationMap &translation) const
Translate contained references using translation and return the transformed value.
mlir::FailureOr< 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.
SourceRefLatticeValue(ScalarTy s)
mlir::ChangeResult translateScalar(const TranslationMap &translation)
Translate this value using the translation map, assuming this value is a scalar.
SourceRefLatticeValue & operator=(SourceRefLatticeValue &&)=default
SourceRefLatticeValue(SourceRef r)
std::pair< SourceRefLatticeValue, mlir::ChangeResult > replacePrefixes(const TranslationMap &translation) const
Replace matching SourceRef prefixes and leave unmatched references unchanged.
Sparse SSA-value lattice for SourceRef propagation.
mlir::ChangeResult join(const AbstractSparseLattice &rhs) override
mlir::ChangeResult setValue(const LatticeValue &newValue)
mlir::DenseMap< SourceRef, mlir::DenseSet< ValueTy > > Ref2Val
mlir::ChangeResult meet(const AbstractSparseLattice &rhs) override
static SourceRefLatticeValue getDefaultValue(ValueTy v)
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, an allocation-like op result,...
const LatticeValue & getValue() const
llvm::PointerUnion< mlir::Value, mlir::Operation * > ValueTy
SourceRefLatticeValue LatticeValue
A reference to a "source", which is the base value from which other SSA values are derived.
const std::vector< int64_t > & getArrayShape() const
bool isSingleValue() const
const ScalarTy & getScalarValue() const
raw_ostream & operator<<(raw_ostream &os, llvm::PointerUnion< mlir::Value, mlir::Operation * > ptr)
mlir::dataflow::AbstractSparseLattice AbstractSparseLattice
void ensure(bool condition, const llvm::Twine &errMsg)
std::unordered_map< SourceRef, SourceRefLatticeValue, SourceRef::Hash > TranslationMap