Skip to content
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

[MLIR][NFC] Retire let constructor for Shape and MLProgram #128869

Merged
merged 2 commits into from
Feb 27, 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
2 changes: 0 additions & 2 deletions mlir/include/mlir/Dialect/MLProgram/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ namespace ml_program {
// Registration
//===----------------------------------------------------------------------===//

std::unique_ptr<OperationPass<ModuleOp>> createMLProgramPipelineGlobalsPass();

/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "mlir/Dialect/MLProgram/Transforms/Passes.h.inc"
Expand Down
4 changes: 2 additions & 2 deletions mlir/include/mlir/Dialect/MLProgram/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

include "mlir/Pass/PassBase.td"

def MLProgramPipelineGlobals : Pass<"mlprogram-pipeline-globals", "ModuleOp"> {
def MLProgramPipelineGlobalsPass
: Pass<"mlprogram-pipeline-globals", "ModuleOp"> {
let summary = "Optimize `ml_program` global operations for read and store";
let description = [{
`ml_program`'s load and store operations can be optimized for
Expand All @@ -21,7 +22,6 @@ def MLProgramPipelineGlobals : Pass<"mlprogram-pipeline-globals", "ModuleOp"> {
The pass is designed to handle both nested regions and function calls
safely.
}];
let constructor = "mlir::ml_program::createMLProgramPipelineGlobalsPass()";
}

#endif // MLIR_DIALECT_MLPROGRAM_TRANSFORMS_PASSES
10 changes: 0 additions & 10 deletions mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ namespace mlir {
#define GEN_PASS_DECL
#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"

/// Creates an instance of the ShapeToShapeLowering pass that legalizes Shape
/// dialect to be convertible to Arith. For example, `shape.num_elements` get
/// transformed to `shape.reduce`, which can be lowered to SCF and Arith.
std::unique_ptr<Pass> createShapeToShapeLowering();

/// Collects a set of patterns to rewrite ops within the Shape dialect.
void populateShapeRewritePatterns(RewritePatternSet &patterns);

Expand All @@ -45,11 +40,6 @@ void populateShapeRewritePatterns(RewritePatternSet &patterns);
//
// After this pass, no cstr_ operations exist.
void populateRemoveShapeConstraintsPatterns(RewritePatternSet &patterns);
std::unique_ptr<OperationPass<func::FuncOp>> createRemoveShapeConstraintsPass();

/// Outline the shape computation part by adding shape.func and populate
/// conrresponding mapping infomation into ShapeMappingAnalysis.
std::unique_ptr<OperationPass<ModuleOp>> createOutlineShapeComputationPass();

//===----------------------------------------------------------------------===//
// Registration
Expand Down
11 changes: 5 additions & 6 deletions mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

include "mlir/Pass/PassBase.td"

def OutlineShapeComputation : Pass<"outline-shape-computation", "ModuleOp"> {
def OutlineShapeComputationPass
: Pass<"outline-shape-computation", "ModuleOp"> {
let summary = "Using shape.func to preserve shape computation";
let description = [{
This pass outlines the shape computation part in high level IR by adding
Expand Down Expand Up @@ -89,18 +90,16 @@ def OutlineShapeComputation : Pass<"outline-shape-computation", "ModuleOp"> {
// - Shape for: %1 = "test.concat"(%0, %arg1) {axis = 0 : i64} : (tensor<?x4x?xf32>, tensor<2x4x?xf32>) -> tensor<?x4x?xf32> :: @shape_cal_1(<block argument> of type 'tensor<?x4x?xf32>' at index: 0)
```
}];
let constructor = "mlir::createOutlineShapeComputationPass()";
let dependentDialects = ["shape::ShapeDialect"];
}

def RemoveShapeConstraints : Pass<"remove-shape-constraints", "func::FuncOp"> {
def RemoveShapeConstraintsPass
: Pass<"remove-shape-constraints", "func::FuncOp"> {
let summary = "Replace all cstr_ ops with a true witness";
let constructor = "mlir::createRemoveShapeConstraintsPass()";
}

def ShapeToShapeLowering : Pass<"shape-to-shape-lowering", "func::FuncOp"> {
def ShapeToShapeLoweringPass : Pass<"shape-to-shape-lowering", "func::FuncOp"> {
let summary = "Legalize Shape dialect to be convertible to Arith";
let constructor = "mlir::createShapeToShapeLowering()";
}

#endif // MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES
9 changes: 2 additions & 7 deletions mlir/lib/Dialect/MLProgram/Transforms/PipelineGlobalOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

namespace mlir {
namespace ml_program {
#define GEN_PASS_DEF_MLPROGRAMPIPELINEGLOBALS
#define GEN_PASS_DEF_MLPROGRAMPIPELINEGLOBALSPASS
#include "mlir/Dialect/MLProgram/Transforms/Passes.h.inc"

namespace {

class MLProgramPipelineGlobals
: public impl::MLProgramPipelineGlobalsBase<MLProgramPipelineGlobals> {
: public impl::MLProgramPipelineGlobalsPassBase<MLProgramPipelineGlobals> {
public:
void runOnOperation() override;

Expand Down Expand Up @@ -224,10 +224,5 @@ void MLProgramPipelineGlobals::runOnOperation() {

} // namespace

std::unique_ptr<OperationPass<mlir::ModuleOp>>
createMLProgramPipelineGlobalsPass() {
return std::make_unique<MLProgramPipelineGlobals>();
}

} // namespace ml_program
} // namespace mlir
10 changes: 3 additions & 7 deletions mlir/lib/Dialect/Shape/Transforms/OutlineShapeComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <vector>

namespace mlir {
#define GEN_PASS_DEF_OUTLINESHAPECOMPUTATION
#define GEN_PASS_DEF_OUTLINESHAPECOMPUTATIONPASS
#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
} // namespace mlir

Expand Down Expand Up @@ -163,7 +163,8 @@ void constructShapeFunc(
}

struct OutlineShapeComputationPass
: public impl::OutlineShapeComputationBase<OutlineShapeComputationPass> {
: public impl::OutlineShapeComputationPassBase<
OutlineShapeComputationPass> {

void runOnOperation() override;

Expand Down Expand Up @@ -324,8 +325,3 @@ bool OutlineShapeComputationPass::calOnlyUsedByWithShapesRecursively(
}

} // namespace

std::unique_ptr<OperationPass<ModuleOp>>
mlir::createOutlineShapeComputationPass() {
return std::make_unique<OutlineShapeComputationPass>();
}
9 changes: 2 additions & 7 deletions mlir/lib/Dialect/Shape/Transforms/RemoveShapeConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

namespace mlir {
#define GEN_PASS_DEF_REMOVESHAPECONSTRAINTS
#define GEN_PASS_DEF_REMOVESHAPECONSTRAINTSPASS
#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
} // namespace mlir

Expand Down Expand Up @@ -47,7 +47,7 @@ class RemoveCstrEqOp : public OpRewritePattern<shape::CstrEqOp> {

/// Removal pass.
class RemoveShapeConstraintsPass
: public impl::RemoveShapeConstraintsBase<RemoveShapeConstraintsPass> {
: public impl::RemoveShapeConstraintsPassBase<RemoveShapeConstraintsPass> {

void runOnOperation() override {
MLIRContext &ctx = getContext();
Expand All @@ -65,8 +65,3 @@ void mlir::populateRemoveShapeConstraintsPatterns(RewritePatternSet &patterns) {
patterns.add<RemoveCstrBroadcastableOp, RemoveCstrEqOp>(
patterns.getContext());
}

std::unique_ptr<OperationPass<func::FuncOp>>
mlir::createRemoveShapeConstraintsPass() {
return std::make_unique<RemoveShapeConstraintsPass>();
}
8 changes: 2 additions & 6 deletions mlir/lib/Dialect/Shape/Transforms/ShapeToShapeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "mlir/Transforms/DialectConversion.h"

namespace mlir {
#define GEN_PASS_DEF_SHAPETOSHAPELOWERING
#define GEN_PASS_DEF_SHAPETOSHAPELOWERINGPASS
#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
} // namespace mlir

Expand Down Expand Up @@ -59,7 +59,7 @@ NumElementsOpConverter::matchAndRewrite(NumElementsOp op,

namespace {
struct ShapeToShapeLowering
: public impl::ShapeToShapeLoweringBase<ShapeToShapeLowering> {
: public impl::ShapeToShapeLoweringPassBase<ShapeToShapeLowering> {
void runOnOperation() override;
};
} // namespace
Expand All @@ -81,7 +81,3 @@ void ShapeToShapeLowering::runOnOperation() {
void mlir::populateShapeRewritePatterns(RewritePatternSet &patterns) {
patterns.add<NumElementsOpConverter>(patterns.getContext());
}

std::unique_ptr<Pass> mlir::createShapeToShapeLowering() {
return std::make_unique<ShapeToShapeLowering>();
}