Skip to content

Commit 57540c9

Browse files
committed
[mlir] Replace toy::DeadFunctionEliminationPass with symbolDCEPass.
Summary: The dead function elimination pass in toy was a temporary stopgap until we had proper dead function elimination support in MLIR. Now that this functionality is available, this pass is no longer necessary. Differential Revision: https://reviews.llvm.org/D72483
1 parent f4261e1 commit 57540c9

25 files changed

+30
-253
lines changed

mlir/examples/toy/Ch4/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ add_toy_chapter(toyc-ch4
1313
parser/AST.cpp
1414
mlir/MLIRGen.cpp
1515
mlir/Dialect.cpp
16-
mlir/DeadFunctionEliminationPass.cpp
1716
mlir/ShapeInferencePass.cpp
1817
mlir/ToyCombine.cpp
1918
)

mlir/examples/toy/Ch4/include/toy/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Pass;
2020

2121
namespace toy {
2222
std::unique_ptr<Pass> createShapeInferencePass();
23-
std::unique_ptr<Pass> createDeadFunctionEliminationPass();
2423
} // end namespace toy
2524
} // end namespace mlir
2625

mlir/examples/toy/Ch4/mlir/DeadFunctionEliminationPass.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

mlir/examples/toy/Ch4/mlir/MLIRGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class MLIRGenImpl {
170170
getType(VarType{})));
171171
}
172172

173+
// If this function isn't main, then set the visibility to private.
174+
if (funcAST.getProto()->getName() != "main")
175+
function.setVisibility(mlir::FuncOp::Visibility::Private);
176+
173177
return function;
174178
}
175179

mlir/examples/toy/Ch4/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int dumpMLIR() {
119119

120120
// Inline all functions into main and then delete them.
121121
pm.addPass(mlir::createInlinerPass());
122-
pm.addPass(mlir::toy::createDeadFunctionEliminationPass());
122+
pm.addPass(mlir::createSymbolDCEPass());
123123

124124
// Now that there is only one function, we can infer the shapes of each of
125125
// the operations.

mlir/examples/toy/Ch5/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ add_toy_chapter(toyc-ch5
1313
parser/AST.cpp
1414
mlir/MLIRGen.cpp
1515
mlir/Dialect.cpp
16-
mlir/DeadFunctionEliminationPass.cpp
1716
mlir/LowerToAffineLoops.cpp
1817
mlir/ShapeInferencePass.cpp
1918
mlir/ToyCombine.cpp

mlir/examples/toy/Ch5/include/toy/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace mlir {
1919
class Pass;
2020

2121
namespace toy {
22-
std::unique_ptr<Pass> createDeadFunctionEliminationPass();
2322
std::unique_ptr<Pass> createShapeInferencePass();
2423

2524
/// Create a pass for lowering to operations in the `Affine` and `Std` dialects,

mlir/examples/toy/Ch5/mlir/DeadFunctionEliminationPass.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

mlir/examples/toy/Ch5/mlir/MLIRGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class MLIRGenImpl {
170170
getType(VarType{})));
171171
}
172172

173+
// If this function isn't main, then set the visibility to private.
174+
if (funcAST.getProto()->getName() != "main")
175+
function.setVisibility(mlir::FuncOp::Visibility::Private);
176+
173177
return function;
174178
}
175179

mlir/examples/toy/Ch5/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int dumpMLIR() {
124124
if (enableOpt || isLoweringToAffine) {
125125
// Inline all functions into main and then delete them.
126126
pm.addPass(mlir::createInlinerPass());
127-
pm.addPass(mlir::toy::createDeadFunctionEliminationPass());
127+
pm.addPass(mlir::createSymbolDCEPass());
128128

129129
// Now that there is only one function, we can infer the shapes of each of
130130
// the operations.

mlir/examples/toy/Ch6/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_toy_chapter(toyc-ch6
1414
parser/AST.cpp
1515
mlir/MLIRGen.cpp
1616
mlir/Dialect.cpp
17-
mlir/DeadFunctionEliminationPass.cpp
1817
mlir/LowerToAffineLoops.cpp
1918
mlir/LowerToLLVM.cpp
2019
mlir/ShapeInferencePass.cpp

mlir/examples/toy/Ch6/include/toy/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace mlir {
1919
class Pass;
2020

2121
namespace toy {
22-
std::unique_ptr<Pass> createDeadFunctionEliminationPass();
2322
std::unique_ptr<Pass> createShapeInferencePass();
2423

2524
/// Create a pass for lowering to operations in the `Affine` and `Std` dialects,

mlir/examples/toy/Ch6/mlir/DeadFunctionEliminationPass.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

mlir/examples/toy/Ch6/mlir/MLIRGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class MLIRGenImpl {
170170
getType(VarType{})));
171171
}
172172

173+
// If this function isn't main, then set the visibility to private.
174+
if (funcAST.getProto()->getName() != "main")
175+
function.setVisibility(mlir::FuncOp::Visibility::Private);
176+
173177
return function;
174178
}
175179

mlir/examples/toy/Ch6/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
138138
if (enableOpt || isLoweringToAffine) {
139139
// Inline all functions into main and then delete them.
140140
pm.addPass(mlir::createInlinerPass());
141-
pm.addPass(mlir::toy::createDeadFunctionEliminationPass());
141+
pm.addPass(mlir::createSymbolDCEPass());
142142

143143
// Now that there is only one function, we can infer the shapes of each of
144144
// the operations.

mlir/examples/toy/Ch7/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_toy_chapter(toyc-ch7
1414
parser/AST.cpp
1515
mlir/MLIRGen.cpp
1616
mlir/Dialect.cpp
17-
mlir/DeadFunctionEliminationPass.cpp
1817
mlir/LowerToAffineLoops.cpp
1918
mlir/LowerToLLVM.cpp
2019
mlir/ShapeInferencePass.cpp

mlir/examples/toy/Ch7/include/toy/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace mlir {
1919
class Pass;
2020

2121
namespace toy {
22-
std::unique_ptr<Pass> createDeadFunctionEliminationPass();
2322
std::unique_ptr<Pass> createShapeInferencePass();
2423

2524
/// Create a pass for lowering to operations in the `Affine` and `Std` dialects,

mlir/examples/toy/Ch7/mlir/DeadFunctionEliminationPass.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

mlir/examples/toy/Ch7/mlir/MLIRGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ class MLIRGenImpl {
223223
*returnOp.operand_type_begin()));
224224
}
225225

226+
// If this function isn't main, then set the visibility to private.
227+
if (funcAST.getProto()->getName() != "main")
228+
function.setVisibility(mlir::FuncOp::Visibility::Private);
229+
226230
return function;
227231
}
228232

mlir/examples/toy/Ch7/toyc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
138138
if (enableOpt || isLoweringToAffine) {
139139
// Inline all functions into main and then delete them.
140140
pm.addPass(mlir::createInlinerPass());
141-
pm.addPass(mlir::toy::createDeadFunctionEliminationPass());
141+
pm.addPass(mlir::createSymbolDCEPass());
142142

143143
// Now that there is only one function, we can infer the shapes of each of
144144
// the operations.

mlir/test/Examples/Toy/Ch4/shape_inference.mlir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
// Check the result of inlining+shape inference on an input module.
44

5-
func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> {
5+
func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64>
6+
attributes { sym_visibility = "private" } {
67
%0 = "toy.transpose"(%arg0) : (tensor<*xf64>) -> tensor<*xf64>
78
%1 = "toy.transpose"(%arg1) : (tensor<*xf64>) -> tensor<*xf64>
89
%2 = "toy.mul"(%0, %1) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64>

0 commit comments

Comments
 (0)