16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Support/Casting.h"
18 #include "llvm/Support/Debug.h"
21 #define DEBUG_TYPE "constant-propagation"
32 os <<
"<UNINITIALIZED>";
49 LLVM_DEBUG(llvm::dbgs() <<
"SCP: Visiting operation: " << *op <<
"\n");
62 for (
auto *operandLattice : operands) {
63 if (operandLattice->getValue().isUninitialized())
65 constantOperands.push_back(operandLattice->getValue().getConstantValue());
78 if (failed(op->
fold(constantOperands, foldResults))) {
86 if (foldResults.empty()) {
94 assert(foldResults.size() == op->
getNumResults() &&
"invalid result size");
95 for (
const auto it : llvm::zip(results, foldResults)) {
100 if (
Attribute attr = llvm::dyn_cast_if_present<Attribute>(foldResult)) {
101 LLVM_DEBUG(llvm::dbgs() <<
"Folded to constant: " << attr <<
"\n");
105 LLVM_DEBUG(llvm::dbgs()
106 <<
"Folded to value: " << foldResult.get<
Value>() <<
"\n");
Attributes are known-constant values of operations.
void print(raw_ostream &os, bool elideType=false) const
Print the attribute.
void propagateIfChanged(AnalysisState *state, ChangeResult changed)
Propagate an update to a state if it changed.
This class represents a single result from folding an operation.
Operation is the basic unit of execution within MLIR.
DictionaryAttr getAttrDictionary()
Return all of the attributes on this operation as a DictionaryAttr.
LogicalResult fold(ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
Attempt to fold this operation with the specified constant operand values.
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
void setAttrs(DictionaryAttr newAttrs)
Set the attributes from a dictionary on this operation.
unsigned getNumRegions()
Returns the number of regions held by this operation.
unsigned getNumOperands()
operand_range getOperands()
Returns an iterator on the underlying Value's.
void setOperands(ValueRange operands)
Replace the current operands of this operation with the ones provided in 'operands'.
unsigned getNumResults()
Return the number of results held by this operation.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
void join(AbstractSparseLattice *lhs, const AbstractSparseLattice &rhs)
Join the lattice element and propagate and update if it changed.
This lattice value represents a known constant value of a lattice.
Attribute getConstantValue() const
Get the constant value. Returns null if no value was determined.
bool isUninitialized() const
Whether the state is uninitialized.
void print(raw_ostream &os) const
Print the constant value.
static ConstantValue getUnknownConstant()
The state where the constant value is unknown.
This class represents a lattice holding a specific value of type ValueT.
ChangeResult join(const AbstractSparseLattice &rhs) override
Join the information contained in the 'rhs' lattice into this lattice.
void setToEntryState(Lattice< ConstantValue > *lattice) override
Set the given lattice element(s) at control flow entry point(s).
LogicalResult visitOperation(Operation *op, ArrayRef< const Lattice< ConstantValue > * > operands, ArrayRef< Lattice< ConstantValue > * > results) override
Visit an operation with the lattices of its operands.
Lattice< ConstantValue > * getLatticeElement(Value value) override
Get the lattice element for a value.
void setAllToEntryStates(ArrayRef< Lattice< ConstantValue > * > lattices)
Include the generated interface declarations.