Skip to content

[MLIR][NFC] Retire let constructor for Tosa #134784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions mlir/include/mlir/Dialect/Tosa/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ void populateTosaConstantReduction(MLIRContext *ctx,

void populateTosaTypeConversion(TypeConverter &converter);

std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass();
std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass(
const TosaLayerwiseConstantFoldPassOptions &options);
std::unique_ptr<Pass> createTosaInferShapesPass();
std::unique_ptr<Pass> createTosaMakeBroadcastablePass();
std::unique_ptr<Pass> createTosaTestQuantUtilAPIPass();
std::unique_ptr<Pass> createTosaOptionalDecompositions();

#define GEN_PASS_REGISTRATION
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
Expand Down
16 changes: 5 additions & 11 deletions mlir/include/mlir/Dialect/Tosa/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ def TosaLayerwiseConstantFoldPass : Pass<"tosa-layerwise-constant-fold", "func::
Pass that enables folding of full-layer operations on constant tensors.
}];

let constructor = "createTosaLayerwiseConstantFoldPass()";

let options = [
Option<"aggressiveReduceConstant", "aggressive-reduce-constant", "bool",
/*default=*/"false",
Expand All @@ -32,22 +30,22 @@ def TosaLayerwiseConstantFoldPass : Pass<"tosa-layerwise-constant-fold", "func::
];
}

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

let constructor = "createTosaInferShapesPass()";
let dependentDialects = [
"func::FuncDialect",
"tensor::TensorDialect",
"tosa::TosaDialect",
];
}

def TosaMakeBroadcastable : Pass<"tosa-make-broadcastable", "func::FuncOp"> {
def TosaMakeBroadcastablePass
: Pass<"tosa-make-broadcastable", "func::FuncOp"> {
let summary = "TOSA rank Reshape to enable Broadcasting";
let description = [{
Pass that enables broadcast by making all input arrays have the same
Expand All @@ -56,19 +54,15 @@ def TosaMakeBroadcastable : Pass<"tosa-make-broadcastable", "func::FuncOp"> {
approach similar to step 1 of Numpy 4-step broadcasting:
https://numpy.org/doc/stable/reference/ufuncs.html#broadcasting
}];

let constructor = "createTosaMakeBroadcastablePass()";
}

def TosaOptionalDecompositions
: Pass<"tosa-optional-decompositions", "func::FuncOp"> {
def TosaOptionalDecompositionsPass
: Pass<"tosa-optional-decompositions", "func::FuncOp"> {
let summary = "Applies Tosa operations optional decompositions";
let description = [{
Pass to apply the Tosa operations decompositions
exposed as populate functions in include/mlir/Dialect/Tosa/Transforms/Passes.h
}];

let constructor = "tosa::createTosaOptionalDecompositions()";
}

def TosaLevelType : I32EnumAttr<"TosaLevelEnum", "Tosa level",
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void mlir::tosa::addTosaToLinalgPasses(
std::optional<tosa::TosaValidationOptions> validationOptions) {
// Optional decompositions are designed to benefit linalg.
if (!options.disableTosaDecompositions)
pm.addNestedPass<func::FuncOp>(tosa::createTosaOptionalDecompositions());
pm.addNestedPass<func::FuncOp>(
tosa::createTosaOptionalDecompositionsPass());
pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());

pm.addNestedPass<func::FuncOp>(tosa::createTosaInferShapesPass());
Expand Down
10 changes: 3 additions & 7 deletions mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace mlir {
namespace tosa {
#define GEN_PASS_DEF_TOSAINFERSHAPES
#define GEN_PASS_DEF_TOSAINFERSHAPESPASS
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
} // namespace tosa
} // namespace mlir
Expand Down Expand Up @@ -333,7 +333,7 @@ void validateSameOperandsAndResultRankTrait(Region &region) {
/// Pass that performs shape propagation across TOSA operations. This includes
/// migrating to within the regions of if/while operations.
struct TosaInferShapes
: public tosa::impl::TosaInferShapesBase<TosaInferShapes> {
: public tosa::impl::TosaInferShapesPassBase<TosaInferShapes> {
public:
void runOnOperation() override {
func::FuncOp func = getOperation();
Expand All @@ -344,8 +344,4 @@ struct TosaInferShapes
validateSameOperandsAndResultRankTrait(func.getBody());
}
};
} // namespace

std::unique_ptr<Pass> mlir::tosa::createTosaInferShapesPass() {
return std::make_unique<TosaInferShapes>();
}
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ void populateTosaOpsCanonicalizationPatterns(MLIRContext *ctx,
struct TosaLayerwiseConstantFoldPass
: public tosa::impl::TosaLayerwiseConstantFoldPassBase<
TosaLayerwiseConstantFoldPass> {
TosaLayerwiseConstantFoldPass(
const TosaLayerwiseConstantFoldPassOptions &options)
: TosaLayerwiseConstantFoldPassBase(options) {}
using Base::Base;

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

} // namespace

std::unique_ptr<Pass> mlir::tosa::createTosaLayerwiseConstantFoldPass() {
return std::make_unique<TosaLayerwiseConstantFoldPass>(
TosaLayerwiseConstantFoldPassOptions{false});
}

std::unique_ptr<Pass> mlir::tosa::createTosaLayerwiseConstantFoldPass(
const TosaLayerwiseConstantFoldPassOptions &options) {
return std::make_unique<TosaLayerwiseConstantFoldPass>(options);
}
8 changes: 2 additions & 6 deletions mlir/lib/Dialect/Tosa/Transforms/TosaMakeBroadcastable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace mlir {
namespace tosa {
#define GEN_PASS_DEF_TOSAMAKEBROADCASTABLE
#define GEN_PASS_DEF_TOSAMAKEBROADCASTABLEPASS
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
} // namespace tosa
} // namespace mlir
Expand Down Expand Up @@ -219,7 +219,7 @@ namespace {
/// Pass that enables broadcast by making all input arrays have the same
/// number of dimensions. Insert RESHAPE operations to lower rank operand
struct TosaMakeBroadcastable
: public tosa::impl::TosaMakeBroadcastableBase<TosaMakeBroadcastable> {
: public tosa::impl::TosaMakeBroadcastablePassBase<TosaMakeBroadcastable> {
public:
void runOnOperation() override {
auto func = getOperation();
Expand Down Expand Up @@ -250,7 +250,3 @@ struct TosaMakeBroadcastable
}
};
} // namespace

std::unique_ptr<Pass> mlir::tosa::createTosaMakeBroadcastablePass() {
return std::make_unique<TosaMakeBroadcastable>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace mlir {
namespace tosa {
#define GEN_PASS_DEF_TOSAOPTIONALDECOMPOSITIONS
#define GEN_PASS_DEF_TOSAOPTIONALDECOMPOSITIONSPASS
#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
} // namespace tosa
} // namespace mlir
Expand All @@ -31,7 +31,7 @@ using namespace mlir;
namespace {

struct TosaOptionalDecompositions
: public tosa::impl::TosaOptionalDecompositionsBase<
: public tosa::impl::TosaOptionalDecompositionsPassBase<
TosaOptionalDecompositions> {
void runOnOperation() override {
auto *ctx = &getContext();
Expand All @@ -47,7 +47,3 @@ struct TosaOptionalDecompositions
};

} // namespace

std::unique_ptr<Pass> mlir::tosa::createTosaOptionalDecompositions() {
return std::make_unique<TosaOptionalDecompositions>();
}