24 #define GEN_PASS_DEF_SIMPLIFYAFFINESTRUCTURES
25 #include "mlir/Dialect/Affine/Passes.h.inc"
29 #define DEBUG_TYPE "simplify-affine-structure"
40 struct SimplifyAffineStructures
41 :
public affine::impl::SimplifyAffineStructuresBase<
42 SimplifyAffineStructures> {
43 void runOnOperation()
override;
47 template <
typename AttributeT>
48 void simplifyAndUpdateAttribute(
Operation *op, StringAttr name,
50 auto &simplified = simplifiedAttributes[attr];
51 if (simplified == attr)
57 auto value = attr.getValue();
58 auto simplifiedValue = simplify(value);
59 if (simplifiedValue == value) {
84 std::unique_ptr<OperationPass<func::FuncOp>>
86 return std::make_unique<SimplifyAffineStructures>();
89 void SimplifyAffineStructures::runOnOperation() {
90 auto func = getOperation();
91 simplifiedAttributes.clear();
93 AffineApplyOp::getCanonicalizationPatterns(patterns, func.getContext());
94 AffineForOp::getCanonicalizationPatterns(patterns, func.getContext());
95 AffineIfOp::getCanonicalizationPatterns(patterns, func.getContext());
103 if (auto mapAttr = dyn_cast<AffineMapAttr>(attr.getValue()))
104 simplifyAndUpdateAttribute(op, attr.getName(), mapAttr);
105 else if (auto setAttr = dyn_cast<IntegerSetAttr>(attr.getValue()))
106 simplifyAndUpdateAttribute(op, attr.getName(), setAttr);
109 if (isa<AffineForOp, AffineIfOp, AffineApplyOp>(op))
110 opsToSimplify.push_back(op);
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
This class represents a frozen set of patterns that can be processed by a pattern applicator.
This class allows control over how the GreedyPatternRewriteDriver works.
GreedyRewriteStrictness strictMode
Strict mode can restrict the ops that are added to the worklist during the rewrite.
An integer set representing a conjunction of one or more affine equalities and inequalities.
Operation is the basic unit of execution within MLIR.
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
IntegerSet simplifyIntegerSet(IntegerSet set)
Simplify the integer set by simplifying the underlying affine expressions by flattening and some simp...
std::unique_ptr< OperationPass< func::FuncOp > > createSimplifyAffineStructuresPass()
Creates a simplification pass for affine structures (maps and sets).
Include the generated interface declarations.
LogicalResult applyOpPatternsAndFold(ArrayRef< Operation * > ops, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr, bool *allErased=nullptr)
Rewrite the specified ops by repeatedly applying the highest benefit patterns in a greedy worklist dr...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
@ ExistingAndNewOps
Only pre-existing and newly created ops are processed.
A mutable affine map. Its affine expressions are however unique.
AffineMap getAffineMap() const
Get the AffineMap corresponding to this MutableAffineMap.
void simplify()
Simplify the (result) expressions in this map using analysis (used by.