23#define GEN_PASS_DEF_AFFINEEXPANDINDEXOPSASAFFINE
24#include "mlir/Dialect/Affine/Passes.h.inc"
34struct LowerDelinearizeIndexOps
36 using OpRewritePattern<AffineDelinearizeIndexOp>::OpRewritePattern;
37 LogicalResult matchAndRewrite(AffineDelinearizeIndexOp op,
38 PatternRewriter &rewriter)
const override {
39 FailureOr<SmallVector<Value>> multiIndex =
40 delinearizeIndex(rewriter, op->getLoc(), op.getLinearIndex(),
41 op.getEffectiveBasis(),
false);
51struct LowerLinearizeIndexOps final :
OpRewritePattern<AffineLinearizeIndexOp> {
53 LogicalResult matchAndRewrite(AffineLinearizeIndexOp op,
54 PatternRewriter &rewriter)
const override {
56 if (op.getMultiIndex().empty()) {
61 SmallVector<OpFoldResult> multiIndex =
63 OpFoldResult linearIndex =
64 linearizeIndex(rewriter, op.getLoc(), multiIndex, op.getMixedBasis());
65 Value linearIndexValue =
72class ExpandAffineIndexOpsAsAffinePass
74 ExpandAffineIndexOpsAsAffinePass> {
76 ExpandAffineIndexOpsAsAffinePass() =
default;
78 void runOnOperation()
override {
83 return signalPassFailure();
91 patterns.insert<LowerDelinearizeIndexOps, LowerLinearizeIndexOps>(
96 return std::make_unique<ExpandAffineIndexOpsAsAffinePass>();
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...
std::unique_ptr< Pass > createAffineExpandIndexOpsAsAffinePass()
Creates a pass to expand affine index operations into affine.apply operations.
void populateAffineExpandIndexOpsAsAffinePatterns(RewritePatternSet &patterns)
Populate patterns that expand affine index operations into their equivalent affine....
Value linearizeIndex(ValueRange indices, ArrayRef< int64_t > strides, int64_t offset, Type integerType, Location loc, OpBuilder &builder)
Generates IR to perform index linearization with the given indices and their corresponding strides,...
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(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...
Value getValueOrCreateConstantIntOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
const FrozenRewritePatternSet & patterns
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...