|
| 1 | +//===- XeGPUOptimizeTranspose.cpp - XeGPU optimize transpose ----*- 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 | + |
| 9 | +#include "mlir/Dialect/MemRef/IR/MemRef.h" |
| 10 | +#include "mlir/Dialect/SCF/Transforms/Patterns.h" |
| 11 | +#include "mlir/Dialect/Vector/IR/VectorOps.h" |
| 12 | +#include "mlir/Dialect/XeGPU/IR/XeGPU.h" |
| 13 | +#include "mlir/Dialect/XeGPU/Transforms/Passes.h" |
| 14 | +#include "mlir/Dialect/XeGPU/Transforms/Transforms.h" |
| 15 | +#include "mlir/Transforms/DialectConversion.h" |
| 16 | +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" |
| 17 | + |
| 18 | +namespace mlir { |
| 19 | +namespace xegpu { |
| 20 | +#define GEN_PASS_DEF_XEGPUOPTIMIZETRANSPOSE |
| 21 | +#include "mlir/Dialect/XeGPU/Transforms/Passes.h.inc" |
| 22 | +} // namespace xegpu |
| 23 | +} // namespace mlir |
| 24 | + |
| 25 | +#define DEBUG_TYPE "xegpu-optimize-transpose" |
| 26 | +#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ") |
| 27 | + |
| 28 | +using namespace mlir; |
| 29 | + |
| 30 | +namespace { |
| 31 | + |
| 32 | +class XeGPULoadNdPattern final : public OpConversionPattern<xegpu::LoadNdOp> { |
| 33 | +public: |
| 34 | + using OpConversionPattern<xegpu::LoadNdOp>::OpConversionPattern; |
| 35 | + LogicalResult |
| 36 | + matchAndRewrite(xegpu::LoadNdOp loadOp, OpAdaptor adaptor, |
| 37 | + ConversionPatternRewriter &rewriter) const override { |
| 38 | + return success(); |
| 39 | + } |
| 40 | +}; |
| 41 | +} // namespace |
| 42 | + |
| 43 | +void xegpu::populateXeGPUOptimizeTransposePatterns( |
| 44 | + RewritePatternSet &patterns) { |
| 45 | + patterns.add<XeGPULoadNdPattern>(patterns.getContext()); |
| 46 | +} |
| 47 | + |
| 48 | +namespace { |
| 49 | + |
| 50 | +struct XeGPUOptimizeTransposePass final |
| 51 | + : public xegpu::impl::XeGPUOptimizeTransposeBase< |
| 52 | + XeGPUOptimizeTransposePass> { |
| 53 | + void runOnOperation() override { |
| 54 | + MLIRContext &context = getContext(); |
| 55 | + TypeConverter converter; |
| 56 | + RewritePatternSet patterns(&context); |
| 57 | + ConversionTarget target(context); |
| 58 | + scf::populateSCFStructuralTypeConversionsAndLegality(converter, patterns, |
| 59 | + target); |
| 60 | + xegpu::populateXeGPUOptimizeTransposePatterns(patterns); |
| 61 | + if (failed(applyPartialConversion(getOperation(), target, |
| 62 | + std::move(patterns)))) { |
| 63 | + DBGS() << "Optimize transpose pass failed.\n"; |
| 64 | + return signalPassFailure(); |
| 65 | + } |
| 66 | + } |
| 67 | +}; |
| 68 | + |
| 69 | +} // namespace |
0 commit comments