Skip to content

Commit 005353a

Browse files
committed
Revert "Move to FoldMemRefAliasOps"
This reverts commit 06e2831.
1 parent 97ec2bf commit 005353a

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

mlir/include/mlir/Dialect/AMDGPU/Transforms/Passes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class ConversionTarget;
2222
namespace amdgpu {
2323

2424
#define GEN_PASS_DECL_AMDGPUEMULATEATOMICSPASS
25-
#define GEN_PASS_DECL_AMDGPURESOLVESTRIDEDMETADATAPASS
25+
#define GEN_PASS_DECL_AMDGPUFOLDSUBVIEWOPSPASS
2626
#define GEN_PASS_DECL_AMDGPUMASKEDLOADTOLOADPASS
27+
#define GEN_PASS_DECL_AMDGPURESOLVESTRIDEDMETADATAPASS
2728
#define GEN_PASS_REGISTRATION
2829
#include "mlir/Dialect/AMDGPU/Transforms/Passes.h.inc"
2930

@@ -38,6 +39,9 @@ void populateAmdgpuResolveStridedMetadataPatterns(RewritePatternSet &patterns,
3839
void populateAmdgpuMaskedloadToLoadPatterns(RewritePatternSet &patterns,
3940
PatternBenefit benefit = 1);
4041

42+
void populateAmdgpuFoldSubviewOpsPatterns(RewritePatternSet &patterns,
43+
PatternBenefit benefit = 1);
44+
4145
} // namespace amdgpu
4246
} // namespace mlir
4347

mlir/lib/Dialect/AMDGPU/Transforms/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
add_mlir_dialect_library(MLIRAMDGPUTransforms
22
EmulateAtomics.cpp
3-
ResolveStridedMetadata.cpp
3+
FoldSubviewOps.cpp
44
MaskedloadToLoad.cpp
5+
ResolveStridedMetadata.cpp
56

67
ADDITIONAL_HEADER_DIRS
78
{$MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/AMDGPU/Transforms
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===- FoldSubviewOps.cpp - AMDGPU fold subview ops ---------------------===//
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/AMDGPU/Transforms/Passes.h"
10+
11+
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h"
12+
#include "mlir/Dialect/Affine/ViewLikeInterfaceUtils.h"
13+
#include "mlir/Dialect/MemRef/IR/MemRef.h"
14+
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
15+
16+
namespace mlir::amdgpu {
17+
#define GEN_PASS_DEF_AMDGPUFOLDSUBVIEWOPSPASS
18+
#include "mlir/Dialect/AMDGPU/Transforms/Passes.h.inc"
19+
} // namespace mlir::amdgpu
20+
21+
using namespace mlir;
22+
using namespace mlir::amdgpu;
23+
24+
namespace {
25+
struct AmdgpuFoldSubviewOpsPass
26+
: public amdgpu::impl::AmdgpuFoldSubviewOpsPassBase<
27+
AmdgpuFoldSubviewOpsPass> {
28+
void runOnOperation() override {
29+
RewritePatternSet patterns(&getContext());
30+
populateAmdgpuFoldSubviewOpsPatterns(patterns);
31+
if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
32+
signalPassFailure();
33+
}
34+
};
35+
36+
struct FoldSubviewIntoGatherToLDSOp : public OpRewritePattern<GatherToLDSOp> {
37+
using OpRewritePattern<GatherToLDSOp>::OpRewritePattern;
38+
LogicalResult matchAndRewrite(GatherToLDSOp op,
39+
PatternRewriter &rewriter) const override {
40+
Location loc = op.getLoc();
41+
42+
// Check if the source is a subview operation:
43+
auto subviewOp = dyn_cast<memref::SubViewOp>(op.getSrc().getDefiningOp());
44+
if (!subviewOp)
45+
return rewriter.notifyMatchFailure(
46+
loc, "GatherToLDSOp folding is currently supported only when the "
47+
"source is a SubviewOp. This is one specific pattern, and other "
48+
"scenarios may be added in the future.");
49+
50+
SmallVector<Value> sourceIndices;
51+
mlir::affine::resolveIndicesIntoOpWithOffsetsAndStrides(
52+
rewriter, loc, subviewOp.getMixedOffsets(), subviewOp.getMixedStrides(),
53+
subviewOp.getDroppedDims(), op.getSrcIndices(), sourceIndices);
54+
55+
rewriter.replaceOpWithNewOp<GatherToLDSOp>(
56+
op, subviewOp.getSource(), sourceIndices, op.getDst(),
57+
op.getDstIndices(), op.getTransferType());
58+
59+
return success();
60+
}
61+
};
62+
} // namespace
63+
64+
void mlir::amdgpu::populateAmdgpuFoldSubviewOpsPatterns(
65+
RewritePatternSet &patterns, PatternBenefit benefit) {
66+
patterns.add<FoldSubviewIntoGatherToLDSOp>(patterns.getContext(), benefit);
67+
}

mlir/lib/Dialect/MemRef/Transforms/FoldMemRefAliasOps.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
2121
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
2222
#include "mlir/Dialect/NVGPU/IR/NVGPUDialect.h"
23-
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h"
2423
#include "mlir/Dialect/Vector/IR/VectorOps.h"
2524
#include "mlir/IR/AffineMap.h"
2625
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
@@ -733,32 +732,6 @@ LogicalResult NVGPUAsyncCopyOpSubViewOpFolder::matchAndRewrite(
733732
return success();
734733
}
735734

736-
struct FoldSubviewIntoGatherToLDSOp
737-
: public OpRewritePattern<amdgpu::GatherToLDSOp> {
738-
using OpRewritePattern<amdgpu::GatherToLDSOp>::OpRewritePattern;
739-
LogicalResult
740-
matchAndRewrite(amdgpu::GatherToLDSOp op, PatternRewriter &rewriter) const override {
741-
Location loc = op.getLoc();
742-
743-
// Check if the source is a subview operation:
744-
auto subviewOp = dyn_cast<memref::SubViewOp>(op.getSrc().getDefiningOp());
745-
if (!subviewOp)
746-
return rewriter.notifyMatchFailure(
747-
loc, "GatherToLDSOp can only be folded if the source is a SubviewOp");
748-
749-
SmallVector<Value> sourceIndices;
750-
mlir::affine::resolveIndicesIntoOpWithOffsetsAndStrides(
751-
rewriter, loc, subviewOp.getMixedOffsets(), subviewOp.getMixedStrides(),
752-
subviewOp.getDroppedDims(), op.getSrcIndices(), sourceIndices);
753-
754-
rewriter.replaceOpWithNewOp<admgpu::GatherToLDSOp>(
755-
op, subviewOp.getSource(), sourceIndices, op.getDst(), op.getDstIndices(),
756-
op.getTransferType());
757-
758-
return success();
759-
}
760-
};
761-
762735
void memref::populateFoldMemRefAliasOpPatterns(RewritePatternSet &patterns) {
763736
patterns.add<LoadOpOfSubViewOpFolder<affine::AffineLoadOp>,
764737
LoadOpOfSubViewOpFolder<memref::LoadOp>,
@@ -789,8 +762,8 @@ void memref::populateFoldMemRefAliasOpPatterns(RewritePatternSet &patterns) {
789762
StoreOpOfCollapseShapeOpFolder<memref::StoreOp>,
790763
StoreOpOfCollapseShapeOpFolder<vector::StoreOp>,
791764
StoreOpOfCollapseShapeOpFolder<vector::MaskedStoreOp>,
792-
SubViewOfSubViewFolder, NVGPUAsyncCopyOpSubViewOpFolder,
793-
FoldSubviewIntoGatherToLDSOp>(patterns.getContext());
765+
SubViewOfSubViewFolder, NVGPUAsyncCopyOpSubViewOpFolder>(
766+
patterns.getContext());
794767
}
795768

796769
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)