23 #define GEN_PASS_DEF_AFFINEEXPANDINDEXOPS
24 #include "mlir/Dialect/Affine/Passes.h.inc"
34 struct LowerDelinearizeIndexOps
37 LogicalResult matchAndRewrite(AffineDelinearizeIndexOp op,
39 FailureOr<SmallVector<Value>> multiIndex =
41 op.getEffectiveBasis(),
false);
42 if (failed(multiIndex))
51 struct LowerLinearizeIndexOps final :
OpRewritePattern<AffineLinearizeIndexOp> {
53 LogicalResult matchAndRewrite(AffineLinearizeIndexOp op,
56 if (op.getMultiIndex().empty()) {
64 linearizeIndex(rewriter, op.getLoc(), multiIndex, op.getMixedBasis());
65 Value linearIndexValue =
72 class ExpandAffineIndexOpsPass
73 :
public affine::impl::AffineExpandIndexOpsBase<ExpandAffineIndexOpsPass> {
75 ExpandAffineIndexOpsPass() =
default;
77 void runOnOperation()
override {
83 return signalPassFailure();
91 patterns.
insert<LowerDelinearizeIndexOps, LowerLinearizeIndexOps>(
96 return std::make_unique<ExpandAffineIndexOpsPass>();
static MLIRContext * getContext(OpFoldResult val)
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents a single result from folding an operation.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
RewritePatternSet & insert(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
MLIRContext * getContext() const
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
std::unique_ptr< Pass > createAffineExpandIndexOpsPass()
Creates a pass to expand affine index operations into more fundamental operations (not necessarily re...
FailureOr< SmallVector< Value > > delinearizeIndex(OpBuilder &b, Location loc, Value linearIndex, ArrayRef< Value > basis, bool hasOuterBound=true)
Generate the IR to delinearize linearIndex given the basis and return the multi-index.
void populateAffineExpandIndexOpsPatterns(RewritePatternSet &patterns)
Populate patterns that expand affine index operations into more fundamental operations (not necessari...
OpFoldResult linearizeIndex(ArrayRef< OpFoldResult > multiIndex, ArrayRef< OpFoldResult > basis, ImplicitLocOpBuilder &builder)
Include the generated interface declarations.
Value getValueOrCreateConstantIntOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
LogicalResult applyPatternsAndFoldGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
OpFoldResult getAsOpFoldResult(Value val)
Given a value, try to extract a constant Attribute.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...