Skip to content

Commit 8502ba1

Browse files
authored
[MLIR][NFC] Retire let constructor for MemRef (#134788)
let constructor is legacy (do not use in tree!) since the tableGen backend emits most of the glue logic to build a pass. Note: The following constructor has been retired: ```cpp std::unique_ptr<Pass> createExpandReallocPass(bool emitDeallocs = true); ``` To update your codebase, replace it with the new options-based API: ```cpp memref::ExpandReallocPassOptions expandAllocPassOptions{ /*emitDeallocs=*/false}; pm.addPass(memref::createExpandReallocPass(expandAllocPassOptions)); ```
1 parent 8158d43 commit 8502ba1

File tree

10 files changed

+33
-102
lines changed

10 files changed

+33
-102
lines changed

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

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,14 @@ class VectorDialect;
3737
} // namespace vector
3838

3939
namespace memref {
40+
4041
//===----------------------------------------------------------------------===//
4142
// Passes
4243
//===----------------------------------------------------------------------===//
4344

4445
#define GEN_PASS_DECL
4546
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
4647

47-
/// Creates an instance of the ExpandOps pass that legalizes memref dialect ops
48-
/// to be convertible to LLVM. For example, `memref.reshape` gets converted to
49-
/// `memref_reinterpret_cast`.
50-
std::unique_ptr<Pass> createExpandOpsPass();
51-
52-
/// Creates an operation pass to fold memref aliasing ops into consumer
53-
/// load/store ops into `patterns`.
54-
std::unique_ptr<Pass> createFoldMemRefAliasOpsPass();
55-
56-
/// Creates an interprocedural pass to normalize memrefs to have a trivial
57-
/// (identity) layout map.
58-
std::unique_ptr<OperationPass<ModuleOp>> createNormalizeMemRefsPass();
59-
60-
/// Creates an operation pass to resolve `memref.dim` operations with values
61-
/// that are defined by operations that implement the
62-
/// `ReifyRankedShapedTypeOpInterface`, in terms of shapes of its input
63-
/// operands.
64-
std::unique_ptr<Pass> createResolveRankedShapeTypeResultDimsPass();
65-
66-
/// Creates an operation pass to resolve `memref.dim` operations with values
67-
/// that are defined by operations that implement the
68-
/// `InferShapedTypeOpInterface` or the `ReifyRankedShapedTypeOpInterface`,
69-
/// in terms of shapes of its input operands.
70-
std::unique_ptr<Pass> createResolveShapedTypeResultDimsPass();
71-
72-
/// Creates an operation pass to expand some memref operation into
73-
/// easier to reason about operations.
74-
std::unique_ptr<Pass> createExpandStridedMetadataPass();
75-
76-
/// Creates an operation pass to expand `memref.realloc` operations into their
77-
/// components.
78-
std::unique_ptr<Pass> createExpandReallocPass(bool emitDeallocs = true);
79-
8048
//===----------------------------------------------------------------------===//
8149
// Registration
8250
//===----------------------------------------------------------------------===//

mlir/include/mlir/Dialect/MemRef/Transforms/Passes.td

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111

1212
include "mlir/Pass/PassBase.td"
1313

14-
def ExpandOps : Pass<"memref-expand"> {
14+
def ExpandOpsPass : Pass<"memref-expand"> {
1515
let summary = "Legalize memref operations to be convertible to LLVM.";
16-
let constructor = "mlir::memref::createExpandOpsPass()";
1716
}
1817

19-
def FoldMemRefAliasOps : Pass<"fold-memref-alias-ops"> {
18+
def FoldMemRefAliasOpsPass : Pass<"fold-memref-alias-ops"> {
2019
let summary = "Fold memref alias ops into consumer load/store ops";
2120
let description = [{
2221
The pass folds loading/storing from/to memref aliasing ops to loading/storing
2322
from/to the original memref.
2423
}];
25-
let constructor = "mlir::memref::createFoldMemRefAliasOpsPass()";
2624
let dependentDialects = [
2725
"affine::AffineDialect", "memref::MemRefDialect", "vector::VectorDialect"
2826
];
@@ -44,9 +42,9 @@ def MemRefEmulateWideInt : Pass<"memref-emulate-wide-int"> {
4442
let dependentDialects = ["vector::VectorDialect"];
4543
}
4644

47-
def NormalizeMemRefs : Pass<"normalize-memrefs", "ModuleOp"> {
45+
def NormalizeMemRefsPass : Pass<"normalize-memrefs", "ModuleOp"> {
4846
let summary = "Normalize memrefs";
49-
let description = [{
47+
let description = [{
5048
This pass transforms memref types with a non-trivial
5149
[layout map](https://mlir.llvm.org/docs/Dialects/Builtin/#affine-map-layout)
5250
into memref types with an identity layout map, e.g. (i, j) -> (i, j). This
@@ -155,40 +153,36 @@ def NormalizeMemRefs : Pass<"normalize-memrefs", "ModuleOp"> {
155153
}
156154
```
157155
}];
158-
let constructor = "mlir::memref::createNormalizeMemRefsPass()";
159156
let dependentDialects = ["affine::AffineDialect"];
160157
}
161158

162-
def ResolveRankedShapeTypeResultDims :
163-
Pass<"resolve-ranked-shaped-type-result-dims"> {
159+
def ResolveRankedShapeTypeResultDimsPass
160+
: Pass<"resolve-ranked-shaped-type-result-dims"> {
164161
let summary = "Resolve memref.dim of result values of ranked shape type";
165162
let description = [{
166163
The pass resolves memref.dim of result of operations that
167164
implement the `ReifyRankedShapedTypeOpInterface` in terms of
168165
shapes of its operands.
169166
}];
170-
let constructor =
171-
"mlir::memref::createResolveRankedShapeTypeResultDimsPass()";
172167
let dependentDialects = [
173168
"memref::MemRefDialect", "tensor::TensorDialect"
174169
];
175170
}
176171

177-
def ResolveShapedTypeResultDims : Pass<"resolve-shaped-type-result-dims"> {
172+
def ResolveShapedTypeResultDimsPass : Pass<"resolve-shaped-type-result-dims"> {
178173
let summary = "Resolve memref.dim of result values";
179174
let description = [{
180175
The pass resolves memref.dim of result of operations that
181176
implement the `InferShapedTypeOpInterface` or
182177
`ReifyRankedShapedTypeOpInterface` in terms of shapes of its
183178
operands.
184179
}];
185-
let constructor = "mlir::memref::createResolveShapedTypeResultDimsPass()";
186180
let dependentDialects = [
187181
"affine::AffineDialect", "memref::MemRefDialect", "tensor::TensorDialect"
188182
];
189183
}
190184

191-
def ExpandStridedMetadata : Pass<"expand-strided-metadata"> {
185+
def ExpandStridedMetadataPass : Pass<"expand-strided-metadata"> {
192186
let summary = "Expand memref operations into easier to analyze constructs";
193187
let description = [{
194188
The pass expands memref operations that modify the metadata of a memref
@@ -205,13 +199,12 @@ def ExpandStridedMetadata : Pass<"expand-strided-metadata"> {
205199
- `memref.extract_strided_metadata`
206200
- `memref.subview`
207201
}];
208-
let constructor = "mlir::memref::createExpandStridedMetadataPass()";
209202
let dependentDialects = [
210203
"affine::AffineDialect", "memref::MemRefDialect"
211204
];
212205
}
213206

214-
def ExpandRealloc : Pass<"expand-realloc"> {
207+
def ExpandReallocPass : Pass<"expand-realloc"> {
215208
let summary = "Expand memref.realloc operations into its components";
216209
let description = [{
217210
The `memref.realloc` operation performs a conditional allocation and copy to
@@ -243,11 +236,10 @@ def ExpandRealloc : Pass<"expand-realloc"> {
243236
}
244237
```
245238
}];
246-
let options = [
247-
Option<"emitDeallocs", "emit-deallocs", "bool", /*default=*/"true",
248-
"Emit deallocation operations for the original MemRef">,
239+
let options = [Option<"emitDeallocs", "emit-deallocs", "bool",
240+
/*default=*/"true",
241+
"Emit deallocation operations for the original MemRef">,
249242
];
250-
let constructor = "mlir::memref::createExpandReallocPass()";
251243
let dependentDialects = [
252244
"arith::ArithDialect", "scf::SCFDialect", "memref::MemRefDialect"
253245
];

mlir/lib/Dialect/Bufferization/Pipelines/BufferizationPipelines.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
void mlir::bufferization::buildBufferDeallocationPipeline(
2222
OpPassManager &pm, const BufferDeallocationPipelineOptions &options) {
23-
pm.addPass(memref::createExpandReallocPass(/*emitDeallocs=*/false));
23+
memref::ExpandReallocPassOptions expandAllocPassOptions{
24+
/*emitDeallocs=*/false};
25+
pm.addPass(memref::createExpandReallocPass(expandAllocPassOptions));
2426
pm.addPass(createCanonicalizerPass());
2527

2628
OwnershipBasedBufferDeallocationPassOptions deallocationOptions{

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace mlir {
2626
namespace memref {
27-
#define GEN_PASS_DEF_EXPANDOPS
27+
#define GEN_PASS_DEF_EXPANDOPSPASS
2828
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
2929
} // namespace memref
3030
} // namespace mlir
@@ -130,7 +130,7 @@ struct MemRefReshapeOpConverter : public OpRewritePattern<memref::ReshapeOp> {
130130
}
131131
};
132132

133-
struct ExpandOpsPass : public memref::impl::ExpandOpsBase<ExpandOpsPass> {
133+
struct ExpandOpsPass : public memref::impl::ExpandOpsPassBase<ExpandOpsPass> {
134134
void runOnOperation() override {
135135
MLIRContext &ctx = getContext();
136136

@@ -161,7 +161,3 @@ void mlir::memref::populateExpandOpsPatterns(RewritePatternSet &patterns) {
161161
patterns.add<AtomicRMWOpConverter, MemRefReshapeOpConverter>(
162162
patterns.getContext());
163163
}
164-
165-
std::unique_ptr<Pass> mlir::memref::createExpandOpsPass() {
166-
return std::make_unique<ExpandOpsPass>();
167-
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace mlir {
1818
namespace memref {
19-
#define GEN_PASS_DEF_EXPANDREALLOC
19+
#define GEN_PASS_DEF_EXPANDREALLOCPASS
2020
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
2121
} // namespace memref
2222
} // namespace mlir
@@ -142,11 +142,9 @@ struct ExpandReallocOpPattern : public OpRewritePattern<memref::ReallocOp> {
142142
};
143143

144144
struct ExpandReallocPass
145-
: public memref::impl::ExpandReallocBase<ExpandReallocPass> {
146-
ExpandReallocPass(bool emitDeallocs)
147-
: memref::impl::ExpandReallocBase<ExpandReallocPass>() {
148-
this->emitDeallocs.setValue(emitDeallocs);
149-
}
145+
: public memref::impl::ExpandReallocPassBase<ExpandReallocPass> {
146+
using Base::Base;
147+
150148
void runOnOperation() override {
151149
MLIRContext &ctx = getContext();
152150

@@ -169,7 +167,3 @@ void mlir::memref::populateExpandReallocPatterns(RewritePatternSet &patterns,
169167
bool emitDeallocs) {
170168
patterns.add<ExpandReallocOpPattern>(patterns.getContext(), emitDeallocs);
171169
}
172-
173-
std::unique_ptr<Pass> mlir::memref::createExpandReallocPass(bool emitDeallocs) {
174-
return std::make_unique<ExpandReallocPass>(emitDeallocs);
175-
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
namespace mlir {
3030
namespace memref {
31-
#define GEN_PASS_DEF_EXPANDSTRIDEDMETADATA
31+
#define GEN_PASS_DEF_EXPANDSTRIDEDMETADATAPASS
3232
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
3333
} // namespace memref
3434
} // namespace mlir
@@ -1213,7 +1213,7 @@ void memref::populateResolveExtractStridedMetadataPatterns(
12131213
namespace {
12141214

12151215
struct ExpandStridedMetadataPass final
1216-
: public memref::impl::ExpandStridedMetadataBase<
1216+
: public memref::impl::ExpandStridedMetadataPassBase<
12171217
ExpandStridedMetadataPass> {
12181218
void runOnOperation() override;
12191219
};
@@ -1225,7 +1225,3 @@ void ExpandStridedMetadataPass::runOnOperation() {
12251225
memref::populateExpandStridedMetadataPatterns(patterns);
12261226
(void)applyPatternsGreedily(getOperation(), std::move(patterns));
12271227
}
1228-
1229-
std::unique_ptr<Pass> memref::createExpandStridedMetadataPass() {
1230-
return std::make_unique<ExpandStridedMetadataPass>();
1231-
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
namespace mlir {
3737
namespace memref {
38-
#define GEN_PASS_DEF_FOLDMEMREFALIASOPS
38+
#define GEN_PASS_DEF_FOLDMEMREFALIASOPSPASS
3939
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
4040
} // namespace memref
4141
} // namespace mlir
@@ -848,7 +848,7 @@ void memref::populateFoldMemRefAliasOpPatterns(RewritePatternSet &patterns) {
848848
namespace {
849849

850850
struct FoldMemRefAliasOpsPass final
851-
: public memref::impl::FoldMemRefAliasOpsBase<FoldMemRefAliasOpsPass> {
851+
: public memref::impl::FoldMemRefAliasOpsPassBase<FoldMemRefAliasOpsPass> {
852852
void runOnOperation() override;
853853
};
854854

@@ -859,7 +859,3 @@ void FoldMemRefAliasOpsPass::runOnOperation() {
859859
memref::populateFoldMemRefAliasOpPatterns(patterns);
860860
(void)applyPatternsGreedily(getOperation(), std::move(patterns));
861861
}
862-
863-
std::unique_ptr<Pass> memref::createFoldMemRefAliasOpsPass() {
864-
return std::make_unique<FoldMemRefAliasOpsPass>();
865-
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace mlir {
2323
namespace memref {
24-
#define GEN_PASS_DEF_NORMALIZEMEMREFS
24+
#define GEN_PASS_DEF_NORMALIZEMEMREFSPASS
2525
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
2626
} // namespace memref
2727
} // namespace mlir
@@ -40,7 +40,7 @@ namespace {
4040
/// to call a non-normalizable function, we treat that function as
4141
/// non-normalizable as well. We assume external functions to be normalizable.
4242
struct NormalizeMemRefs
43-
: public memref::impl::NormalizeMemRefsBase<NormalizeMemRefs> {
43+
: public memref::impl::NormalizeMemRefsPassBase<NormalizeMemRefs> {
4444
void runOnOperation() override;
4545
void normalizeFuncOpMemRefs(func::FuncOp funcOp, ModuleOp moduleOp);
4646
bool areMemRefsNormalizable(func::FuncOp funcOp);
@@ -53,11 +53,6 @@ struct NormalizeMemRefs
5353

5454
} // namespace
5555

56-
std::unique_ptr<OperationPass<ModuleOp>>
57-
mlir::memref::createNormalizeMemRefsPass() {
58-
return std::make_unique<NormalizeMemRefs>();
59-
}
60-
6156
void NormalizeMemRefs::runOnOperation() {
6257
LLVM_DEBUG(llvm::dbgs() << "Normalizing Memrefs...\n");
6358
ModuleOp moduleOp = getOperation();

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
namespace mlir {
2727
namespace memref {
28-
#define GEN_PASS_DEF_RESOLVERANKEDSHAPETYPERESULTDIMS
29-
#define GEN_PASS_DEF_RESOLVESHAPEDTYPERESULTDIMS
28+
#define GEN_PASS_DEF_RESOLVERANKEDSHAPETYPERESULTDIMSPASS
29+
#define GEN_PASS_DEF_RESOLVESHAPEDTYPERESULTDIMSPASS
3030
#include "mlir/Dialect/MemRef/Transforms/Passes.h.inc"
3131
} // namespace memref
3232
} // namespace mlir
@@ -164,13 +164,13 @@ struct IterArgsToInitArgs : public OpRewritePattern<tensor::DimOp> {
164164

165165
namespace {
166166
struct ResolveRankedShapeTypeResultDimsPass final
167-
: public memref::impl::ResolveRankedShapeTypeResultDimsBase<
167+
: public memref::impl::ResolveRankedShapeTypeResultDimsPassBase<
168168
ResolveRankedShapeTypeResultDimsPass> {
169169
void runOnOperation() override;
170170
};
171171

172172
struct ResolveShapedTypeResultDimsPass final
173-
: public memref::impl::ResolveShapedTypeResultDimsBase<
173+
: public memref::impl::ResolveShapedTypeResultDimsPassBase<
174174
ResolveShapedTypeResultDimsPass> {
175175
void runOnOperation() override;
176176
};
@@ -206,11 +206,3 @@ void ResolveShapedTypeResultDimsPass::runOnOperation() {
206206
if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
207207
return signalPassFailure();
208208
}
209-
210-
std::unique_ptr<Pass> memref::createResolveShapedTypeResultDimsPass() {
211-
return std::make_unique<ResolveShapedTypeResultDimsPass>();
212-
}
213-
214-
std::unique_ptr<Pass> memref::createResolveRankedShapeTypeResultDimsPass() {
215-
return std::make_unique<ResolveRankedShapeTypeResultDimsPass>();
216-
}

mlir/test/python/pass_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def testInvalidNesting():
130130
try:
131131
pm = PassManager.parse("func.func(normalize-memrefs)")
132132
except ValueError as e:
133-
# CHECK: ValueError exception: Can't add pass 'NormalizeMemRefs' restricted to 'builtin.module' on a PassManager intended to run on 'func.func', did you intend to nest?
133+
# CHECK: ValueError exception: Can't add pass 'NormalizeMemRefsPass' restricted to 'builtin.module' on a PassManager intended to run on 'func.func', did you intend to nest?
134134
log("ValueError exception:", e)
135135
else:
136136
log("Exception not produced")

0 commit comments

Comments
 (0)