19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/TypeSwitch.h"
23 #define GEN_PASS_DEF_LINALGFOLDINTOELEMENTWISEPASS
24 #include "mlir/Dialect/Linalg/Passes.h.inc"
30 #define DEBUG_TYPE "linalg-fold-into-elementwise"
36 LogicalResult matchAndRewrite(ElementwiseOp op,
41 for (
OpOperand *operand : op.getDpsInputOperands()) {
42 AffineMap map = op.getMatchingIndexingMap(operand);
43 auto transposeOp = operand->
get().getDefiningOp<TransposeOp>();
47 newIns.push_back(operand->get());
48 newMaps.push_back(map);
51 newIns.push_back(transposeOp.getInput());
53 newMaps.push_back(transposeOp.getMatchingIndexingMap(
54 transposeOp.getDpsInputOperand(0)));
59 newMaps.push_back(op.getIndexingMapsArray().back());
62 op, newIns, op.getDpsInits()[0], op.getKindAttr(),
68 struct LinalgFoldIntoElementwisePass
69 :
public impl::LinalgFoldIntoElementwisePassBase<
70 LinalgFoldIntoElementwisePass> {
71 using impl::LinalgFoldIntoElementwisePassBase<
72 LinalgFoldIntoElementwisePass>::LinalgFoldIntoElementwisePassBase;
74 void runOnOperation()
override {
75 llvm::outs() <<
"Hellow from fold into elemenwise \n";
81 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...