Skip to content

Commit 87a187c

Browse files
authored
[MLIR][NFC] Retire let constructor for Tosa (#134784)
`let constructor` is legacy (do not use in tree!) since the tableGen backend emits most of the glue logic to build a pass.
1 parent 3086546 commit 87a187c

File tree

7 files changed

+15
-50
lines changed

7 files changed

+15
-50
lines changed

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

-6
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ void populateTosaConstantReduction(MLIRContext *ctx,
4141

4242
void populateTosaTypeConversion(TypeConverter &converter);
4343

44-
std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass();
45-
std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass(
46-
const TosaLayerwiseConstantFoldPassOptions &options);
47-
std::unique_ptr<Pass> createTosaInferShapesPass();
48-
std::unique_ptr<Pass> createTosaMakeBroadcastablePass();
4944
std::unique_ptr<Pass> createTosaTestQuantUtilAPIPass();
50-
std::unique_ptr<Pass> createTosaOptionalDecompositions();
5145

5246
#define GEN_PASS_REGISTRATION
5347
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"

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

+5-11
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def TosaLayerwiseConstantFoldPass : Pass<"tosa-layerwise-constant-fold", "func::
2222
Pass that enables folding of full-layer operations on constant tensors.
2323
}];
2424

25-
let constructor = "createTosaLayerwiseConstantFoldPass()";
26-
2725
let options = [
2826
Option<"aggressiveReduceConstant", "aggressive-reduce-constant", "bool",
2927
/*default=*/"false",
@@ -32,22 +30,22 @@ def TosaLayerwiseConstantFoldPass : Pass<"tosa-layerwise-constant-fold", "func::
3230
];
3331
}
3432

35-
def TosaInferShapes : Pass<"tosa-infer-shapes", "func::FuncOp"> {
33+
def TosaInferShapesPass : Pass<"tosa-infer-shapes", "func::FuncOp"> {
3634
let summary = "Propagate shapes across TOSA operations";
3735
let description = [{
3836
Pass that uses operand types and propagates shapes to TOSA operations.
3937
This includes legalizing rankless and dynamic shapes towards static.
4038
}];
4139

42-
let constructor = "createTosaInferShapesPass()";
4340
let dependentDialects = [
4441
"func::FuncDialect",
4542
"tensor::TensorDialect",
4643
"tosa::TosaDialect",
4744
];
4845
}
4946

50-
def TosaMakeBroadcastable : Pass<"tosa-make-broadcastable", "func::FuncOp"> {
47+
def TosaMakeBroadcastablePass
48+
: Pass<"tosa-make-broadcastable", "func::FuncOp"> {
5149
let summary = "TOSA rank Reshape to enable Broadcasting";
5250
let description = [{
5351
Pass that enables broadcast by making all input arrays have the same
@@ -56,19 +54,15 @@ def TosaMakeBroadcastable : Pass<"tosa-make-broadcastable", "func::FuncOp"> {
5654
approach similar to step 1 of Numpy 4-step broadcasting:
5755
https://numpy.org/doc/stable/reference/ufuncs.html#broadcasting
5856
}];
59-
60-
let constructor = "createTosaMakeBroadcastablePass()";
6157
}
6258

63-
def TosaOptionalDecompositions
64-
: Pass<"tosa-optional-decompositions", "func::FuncOp"> {
59+
def TosaOptionalDecompositionsPass
60+
: Pass<"tosa-optional-decompositions", "func::FuncOp"> {
6561
let summary = "Applies Tosa operations optional decompositions";
6662
let description = [{
6763
Pass to apply the Tosa operations decompositions
6864
exposed as populate functions in include/mlir/Dialect/Tosa/Transforms/Passes.h
6965
}];
70-
71-
let constructor = "tosa::createTosaOptionalDecompositions()";
7266
}
7367

7468
def TosaLevelType : I32EnumAttr<"TosaLevelEnum", "Tosa level",

mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ void mlir::tosa::addTosaToLinalgPasses(
8585
std::optional<tosa::TosaValidationOptions> validationOptions) {
8686
// Optional decompositions are designed to benefit linalg.
8787
if (!options.disableTosaDecompositions)
88-
pm.addNestedPass<func::FuncOp>(tosa::createTosaOptionalDecompositions());
88+
pm.addNestedPass<func::FuncOp>(
89+
tosa::createTosaOptionalDecompositionsPass());
8990
pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
9091

9192
pm.addNestedPass<func::FuncOp>(tosa::createTosaInferShapesPass());

mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace mlir {
2727
namespace tosa {
28-
#define GEN_PASS_DEF_TOSAINFERSHAPES
28+
#define GEN_PASS_DEF_TOSAINFERSHAPESPASS
2929
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
3030
} // namespace tosa
3131
} // namespace mlir
@@ -333,7 +333,7 @@ void validateSameOperandsAndResultRankTrait(Region &region) {
333333
/// Pass that performs shape propagation across TOSA operations. This includes
334334
/// migrating to within the regions of if/while operations.
335335
struct TosaInferShapes
336-
: public tosa::impl::TosaInferShapesBase<TosaInferShapes> {
336+
: public tosa::impl::TosaInferShapesPassBase<TosaInferShapes> {
337337
public:
338338
void runOnOperation() override {
339339
func::FuncOp func = getOperation();
@@ -344,8 +344,4 @@ struct TosaInferShapes
344344
validateSameOperandsAndResultRankTrait(func.getBody());
345345
}
346346
};
347-
} // namespace
348-
349-
std::unique_ptr<Pass> mlir::tosa::createTosaInferShapesPass() {
350-
return std::make_unique<TosaInferShapes>();
351-
}
347+
} // namespace

mlir/lib/Dialect/Tosa/Transforms/TosaLayerwiseConstantFoldPass.cpp

+1-13
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ void populateTosaOpsCanonicalizationPatterns(MLIRContext *ctx,
4545
struct TosaLayerwiseConstantFoldPass
4646
: public tosa::impl::TosaLayerwiseConstantFoldPassBase<
4747
TosaLayerwiseConstantFoldPass> {
48-
TosaLayerwiseConstantFoldPass(
49-
const TosaLayerwiseConstantFoldPassOptions &options)
50-
: TosaLayerwiseConstantFoldPassBase(options) {}
48+
using Base::Base;
5149

5250
void runOnOperation() override {
5351
auto *ctx = &getContext();
@@ -66,13 +64,3 @@ struct TosaLayerwiseConstantFoldPass
6664
};
6765

6866
} // namespace
69-
70-
std::unique_ptr<Pass> mlir::tosa::createTosaLayerwiseConstantFoldPass() {
71-
return std::make_unique<TosaLayerwiseConstantFoldPass>(
72-
TosaLayerwiseConstantFoldPassOptions{false});
73-
}
74-
75-
std::unique_ptr<Pass> mlir::tosa::createTosaLayerwiseConstantFoldPass(
76-
const TosaLayerwiseConstantFoldPassOptions &options) {
77-
return std::make_unique<TosaLayerwiseConstantFoldPass>(options);
78-
}

mlir/lib/Dialect/Tosa/Transforms/TosaMakeBroadcastable.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace mlir {
2323
namespace tosa {
24-
#define GEN_PASS_DEF_TOSAMAKEBROADCASTABLE
24+
#define GEN_PASS_DEF_TOSAMAKEBROADCASTABLEPASS
2525
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
2626
} // namespace tosa
2727
} // namespace mlir
@@ -219,7 +219,7 @@ namespace {
219219
/// Pass that enables broadcast by making all input arrays have the same
220220
/// number of dimensions. Insert RESHAPE operations to lower rank operand
221221
struct TosaMakeBroadcastable
222-
: public tosa::impl::TosaMakeBroadcastableBase<TosaMakeBroadcastable> {
222+
: public tosa::impl::TosaMakeBroadcastablePassBase<TosaMakeBroadcastable> {
223223
public:
224224
void runOnOperation() override {
225225
auto func = getOperation();
@@ -250,7 +250,3 @@ struct TosaMakeBroadcastable
250250
}
251251
};
252252
} // namespace
253-
254-
std::unique_ptr<Pass> mlir::tosa::createTosaMakeBroadcastablePass() {
255-
return std::make_unique<TosaMakeBroadcastable>();
256-
}

mlir/lib/Dialect/Tosa/Transforms/TosaOptionalDecompositions.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace mlir {
2323
namespace tosa {
24-
#define GEN_PASS_DEF_TOSAOPTIONALDECOMPOSITIONS
24+
#define GEN_PASS_DEF_TOSAOPTIONALDECOMPOSITIONSPASS
2525
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
2626
} // namespace tosa
2727
} // namespace mlir
@@ -31,7 +31,7 @@ using namespace mlir;
3131
namespace {
3232

3333
struct TosaOptionalDecompositions
34-
: public tosa::impl::TosaOptionalDecompositionsBase<
34+
: public tosa::impl::TosaOptionalDecompositionsPassBase<
3535
TosaOptionalDecompositions> {
3636
void runOnOperation() override {
3737
auto *ctx = &getContext();
@@ -47,7 +47,3 @@ struct TosaOptionalDecompositions
4747
};
4848

4949
} // namespace
50-
51-
std::unique_ptr<Pass> mlir::tosa::createTosaOptionalDecompositions() {
52-
return std::make_unique<TosaOptionalDecompositions>();
53-
}

0 commit comments

Comments
 (0)