MLIR 22.0.0git
XeGPUFoldAliasOps.cpp
Go to the documentation of this file.
1//===- XeGPUFoldAliasOps.cpp - XeGPU alias ops folders ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
16
17namespace mlir {
18namespace xegpu {
19#define GEN_PASS_DEF_XEGPUFOLDALIASOPS
20#include "mlir/Dialect/XeGPU/Transforms/Passes.h.inc"
21} // namespace xegpu
22} // namespace mlir
23
24#define DEBUG_TYPE "xegpu-fold-alias-ops"
25#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
26
27using namespace mlir;
28
29namespace {
30/// Merges subview operation with xegpu.create_nd_tdesc operation.
31class XegpuCreateNdDescOpSubViewOpFolder final
32 : public OpRewritePattern<xegpu::CreateNdDescOp> {
33public:
34 using OpRewritePattern<xegpu::CreateNdDescOp>::OpRewritePattern;
35
36 LogicalResult matchAndRewrite(xegpu::CreateNdDescOp descOp,
37 PatternRewriter &rewriter) const override;
38};
39} // namespace
40
41LogicalResult XegpuCreateNdDescOpSubViewOpFolder::matchAndRewrite(
42 xegpu::CreateNdDescOp descOp, PatternRewriter &rewriter) const {
43 auto subViewOp = descOp.getSource().getDefiningOp<memref::SubViewOp>();
44
45 if (!subViewOp)
46 return rewriter.notifyMatchFailure(descOp, "not a subview producer");
47 if (!subViewOp.hasUnitStride())
48 return rewriter.notifyMatchFailure(descOp, "requires unit strides");
49
50 SmallVector<Value> resolvedOffsets;
52 rewriter, descOp.getLoc(), subViewOp.getMixedOffsets(),
53 subViewOp.getMixedStrides(), subViewOp.getDroppedDims(),
54 descOp.getMixedOffsets(), resolvedOffsets);
55
56 rewriter.replaceOpWithNewOp<xegpu::CreateNdDescOp>(
57 descOp, descOp.getTensorDesc().getType(), subViewOp.getSource(),
58 getAsOpFoldResult(resolvedOffsets));
59
60 return success();
61}
62
64 patterns.add<XegpuCreateNdDescOpSubViewOpFolder>(patterns.getContext());
65}
66
67namespace {
68
69struct XeGPUFoldAliasOpsPass final
70 : public xegpu::impl::XeGPUFoldAliasOpsBase<XeGPUFoldAliasOpsPass> {
71 void runOnOperation() override;
72};
73
74} // namespace
75
76void XeGPUFoldAliasOpsPass::runOnOperation() {
77 RewritePatternSet patterns(&getContext());
79 (void)applyPatternsGreedily(getOperation(), std::move(patterns));
80}
return success()
b getContext())
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
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 resolveIndicesIntoOpWithOffsetsAndStrides(RewriterBase &rewriter, Location loc, ArrayRef< OpFoldResult > mixedSourceOffsets, ArrayRef< OpFoldResult > mixedSourceStrides, const llvm::SmallBitVector &rankReducedDims, ArrayRef< OpFoldResult > consumerIndices, SmallVectorImpl< Value > &resolvedIndices)
Given the 'consumerIndices' of a load/store operation operating on an op with offsets and strides,...
void populateXeGPUFoldAliasOpsPatterns(RewritePatternSet &patterns)
Appends patterns for folding aliasing ops into XeGPU ops into patterns.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition Utils.cpp:304
LogicalResult applyPatternsGreedily(Region &region, 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
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...