23 #define GEN_PASS_DEF_AFFINEEXPANDINDEXOPSASAFFINE
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 ExpandAffineIndexOpsAsAffinePass
73 :
public affine::impl::AffineExpandIndexOpsAsAffineBase<
74 ExpandAffineIndexOpsAsAffinePass> {
76 ExpandAffineIndexOpsAsAffinePass() =
default;
78 void runOnOperation()
override {
84 return signalPassFailure();
92 patterns.
insert<LowerDelinearizeIndexOps, LowerLinearizeIndexOps>(
97 return std::make_unique<ExpandAffineIndexOpsAsAffinePass>();
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...
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.
OpFoldResult linearizeIndex(ArrayRef< OpFoldResult > multiIndex, ArrayRef< OpFoldResult > basis, ImplicitLocOpBuilder &builder)
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....
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...