19 #include "llvm/ADT/SmallVector.h"
22 #define GEN_PASS_DEF_LINALGFOLDINTOELEMENTWISEPASS
23 #include "mlir/Dialect/Linalg/Passes.h.inc"
29 #define DEBUG_TYPE "linalg-fold-into-elementwise"
35 LogicalResult matchAndRewrite(ElementwiseOp op,
40 for (
OpOperand *operand : op.getDpsInputOperands()) {
41 AffineMap map = op.getMatchingIndexingMap(operand);
42 auto transposeOp = operand->
get().getDefiningOp<TransposeOp>();
46 newIns.push_back(operand->get());
47 newMaps.push_back(map);
50 newIns.push_back(transposeOp.getInput());
52 newMaps.push_back(transposeOp.getMatchingIndexingMap(
53 transposeOp.getDpsInputOperand(0)));
58 newMaps.push_back(op.getIndexingMapsArray().back());
61 op, newIns, op.getDpsInits()[0], op.getKindAttr(),
67 struct LinalgFoldIntoElementwisePass
68 :
public impl::LinalgFoldIntoElementwisePassBase<
69 LinalgFoldIntoElementwisePass> {
70 using impl::LinalgFoldIntoElementwisePassBase<
71 LinalgFoldIntoElementwisePass>::LinalgFoldIntoElementwisePassBase;
73 void runOnOperation()
override {
79 return signalPassFailure();
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
bool isIdentity() const
Returns true if this affine map is an identity affine map.
ArrayAttr getAffineMapArrayAttr(ArrayRef< AffineMap > values)
This class represents an operand of an operation.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
void populateLinalgFoldIntoElementwisePatterns(RewritePatternSet &patterns)
Populates patterns with patterns that fold operations like linalg.transform into elementwise op map.
Include the generated interface declarations.
const FrozenRewritePatternSet GreedyRewriteConfig bool * changed
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...
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...