diff --git a/mlir/examples/toy/Ch4/CMakeLists.txt b/mlir/examples/toy/Ch4/CMakeLists.txt --- a/mlir/examples/toy/Ch4/CMakeLists.txt +++ b/mlir/examples/toy/Ch4/CMakeLists.txt @@ -13,7 +13,6 @@ parser/AST.cpp mlir/MLIRGen.cpp mlir/Dialect.cpp - mlir/DeadFunctionEliminationPass.cpp mlir/ShapeInferencePass.cpp mlir/ToyCombine.cpp ) diff --git a/mlir/examples/toy/Ch4/include/toy/Passes.h b/mlir/examples/toy/Ch4/include/toy/Passes.h --- a/mlir/examples/toy/Ch4/include/toy/Passes.h +++ b/mlir/examples/toy/Ch4/include/toy/Passes.h @@ -20,7 +20,6 @@ namespace toy { std::unique_ptr createShapeInferencePass(); -std::unique_ptr createDeadFunctionEliminationPass(); } // end namespace toy } // end namespace mlir diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp @@ -170,6 +170,10 @@ getType(VarType{}))); } + // If this function isn't main, then set the visibility to private. + if (funcAST.getProto()->getName() != "main") + function.setVisibility(mlir::FuncOp::Visibility::Private); + return function; } diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -119,7 +119,7 @@ // Inline all functions into main and then delete them. pm.addPass(mlir::createInlinerPass()); - pm.addPass(mlir::toy::createDeadFunctionEliminationPass()); + pm.addPass(mlir::createSymbolDCEPass()); // Now that there is only one function, we can infer the shapes of each of // the operations. diff --git a/mlir/examples/toy/Ch5/CMakeLists.txt b/mlir/examples/toy/Ch5/CMakeLists.txt --- a/mlir/examples/toy/Ch5/CMakeLists.txt +++ b/mlir/examples/toy/Ch5/CMakeLists.txt @@ -13,7 +13,6 @@ parser/AST.cpp mlir/MLIRGen.cpp mlir/Dialect.cpp - mlir/DeadFunctionEliminationPass.cpp mlir/LowerToAffineLoops.cpp mlir/ShapeInferencePass.cpp mlir/ToyCombine.cpp diff --git a/mlir/examples/toy/Ch5/include/toy/Passes.h b/mlir/examples/toy/Ch5/include/toy/Passes.h --- a/mlir/examples/toy/Ch5/include/toy/Passes.h +++ b/mlir/examples/toy/Ch5/include/toy/Passes.h @@ -19,7 +19,6 @@ class Pass; namespace toy { -std::unique_ptr createDeadFunctionEliminationPass(); std::unique_ptr createShapeInferencePass(); /// Create a pass for lowering to operations in the `Affine` and `Std` dialects, diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp @@ -170,6 +170,10 @@ getType(VarType{}))); } + // If this function isn't main, then set the visibility to private. + if (funcAST.getProto()->getName() != "main") + function.setVisibility(mlir::FuncOp::Visibility::Private); + return function; } diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -124,7 +124,7 @@ if (enableOpt || isLoweringToAffine) { // Inline all functions into main and then delete them. pm.addPass(mlir::createInlinerPass()); - pm.addPass(mlir::toy::createDeadFunctionEliminationPass()); + pm.addPass(mlir::createSymbolDCEPass()); // Now that there is only one function, we can infer the shapes of each of // the operations. diff --git a/mlir/examples/toy/Ch6/CMakeLists.txt b/mlir/examples/toy/Ch6/CMakeLists.txt --- a/mlir/examples/toy/Ch6/CMakeLists.txt +++ b/mlir/examples/toy/Ch6/CMakeLists.txt @@ -14,7 +14,6 @@ parser/AST.cpp mlir/MLIRGen.cpp mlir/Dialect.cpp - mlir/DeadFunctionEliminationPass.cpp mlir/LowerToAffineLoops.cpp mlir/LowerToLLVM.cpp mlir/ShapeInferencePass.cpp diff --git a/mlir/examples/toy/Ch6/include/toy/Passes.h b/mlir/examples/toy/Ch6/include/toy/Passes.h --- a/mlir/examples/toy/Ch6/include/toy/Passes.h +++ b/mlir/examples/toy/Ch6/include/toy/Passes.h @@ -19,7 +19,6 @@ class Pass; namespace toy { -std::unique_ptr createDeadFunctionEliminationPass(); std::unique_ptr createShapeInferencePass(); /// Create a pass for lowering to operations in the `Affine` and `Std` dialects, diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp @@ -170,6 +170,10 @@ getType(VarType{}))); } + // If this function isn't main, then set the visibility to private. + if (funcAST.getProto()->getName() != "main") + function.setVisibility(mlir::FuncOp::Visibility::Private); + return function; } diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -138,7 +138,7 @@ if (enableOpt || isLoweringToAffine) { // Inline all functions into main and then delete them. pm.addPass(mlir::createInlinerPass()); - pm.addPass(mlir::toy::createDeadFunctionEliminationPass()); + pm.addPass(mlir::createSymbolDCEPass()); // Now that there is only one function, we can infer the shapes of each of // the operations. diff --git a/mlir/examples/toy/Ch7/CMakeLists.txt b/mlir/examples/toy/Ch7/CMakeLists.txt --- a/mlir/examples/toy/Ch7/CMakeLists.txt +++ b/mlir/examples/toy/Ch7/CMakeLists.txt @@ -14,7 +14,6 @@ parser/AST.cpp mlir/MLIRGen.cpp mlir/Dialect.cpp - mlir/DeadFunctionEliminationPass.cpp mlir/LowerToAffineLoops.cpp mlir/LowerToLLVM.cpp mlir/ShapeInferencePass.cpp diff --git a/mlir/examples/toy/Ch7/include/toy/Passes.h b/mlir/examples/toy/Ch7/include/toy/Passes.h --- a/mlir/examples/toy/Ch7/include/toy/Passes.h +++ b/mlir/examples/toy/Ch7/include/toy/Passes.h @@ -19,7 +19,6 @@ class Pass; namespace toy { -std::unique_ptr createDeadFunctionEliminationPass(); std::unique_ptr createShapeInferencePass(); /// Create a pass for lowering to operations in the `Affine` and `Std` dialects, diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp @@ -223,6 +223,10 @@ *returnOp.operand_type_begin())); } + // If this function isn't main, then set the visibility to private. + if (funcAST.getProto()->getName() != "main") + function.setVisibility(mlir::FuncOp::Visibility::Private); + return function; } diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -138,7 +138,7 @@ if (enableOpt || isLoweringToAffine) { // Inline all functions into main and then delete them. pm.addPass(mlir::createInlinerPass()); - pm.addPass(mlir::toy::createDeadFunctionEliminationPass()); + pm.addPass(mlir::createSymbolDCEPass()); // Now that there is only one function, we can infer the shapes of each of // the operations. diff --git a/mlir/test/Examples/Toy/Ch4/shape_inference.mlir b/mlir/test/Examples/Toy/Ch4/shape_inference.mlir --- a/mlir/test/Examples/Toy/Ch4/shape_inference.mlir +++ b/mlir/test/Examples/Toy/Ch4/shape_inference.mlir @@ -2,7 +2,8 @@ // Check the result of inlining+shape inference on an input module. -func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> { +func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> + attributes { sym_visibility = "private" } { %0 = "toy.transpose"(%arg0) : (tensor<*xf64>) -> tensor<*xf64> %1 = "toy.transpose"(%arg1) : (tensor<*xf64>) -> tensor<*xf64> %2 = "toy.mul"(%0, %1) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64> diff --git a/mlir/test/Examples/Toy/Ch5/shape_inference.mlir b/mlir/test/Examples/Toy/Ch5/shape_inference.mlir --- a/mlir/test/Examples/Toy/Ch5/shape_inference.mlir +++ b/mlir/test/Examples/Toy/Ch5/shape_inference.mlir @@ -2,7 +2,8 @@ // Check the result of inlining+shape inference on an input module. -func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> { +func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> + attributes { sym_visibility = "private" } { %0 = "toy.transpose"(%arg0) : (tensor<*xf64>) -> tensor<*xf64> %1 = "toy.transpose"(%arg1) : (tensor<*xf64>) -> tensor<*xf64> %2 = "toy.mul"(%0, %1) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64> diff --git a/mlir/test/Examples/Toy/Ch6/shape_inference.mlir b/mlir/test/Examples/Toy/Ch6/shape_inference.mlir --- a/mlir/test/Examples/Toy/Ch6/shape_inference.mlir +++ b/mlir/test/Examples/Toy/Ch6/shape_inference.mlir @@ -2,7 +2,8 @@ // Check the result of inlining+shape inference on an input module. -func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> { +func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> + attributes { sym_visibility = "private" } { %0 = "toy.transpose"(%arg0) : (tensor<*xf64>) -> tensor<*xf64> %1 = "toy.transpose"(%arg1) : (tensor<*xf64>) -> tensor<*xf64> %2 = "toy.mul"(%0, %1) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64> diff --git a/mlir/test/Examples/Toy/Ch7/shape_inference.mlir b/mlir/test/Examples/Toy/Ch7/shape_inference.mlir --- a/mlir/test/Examples/Toy/Ch7/shape_inference.mlir +++ b/mlir/test/Examples/Toy/Ch7/shape_inference.mlir @@ -2,7 +2,8 @@ // Check the result of inlining+shape inference on an input module. -func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> { +func @multiply_transpose(%arg0: tensor<*xf64>, %arg1: tensor<*xf64>) -> tensor<*xf64> + attributes { sym_visibility = "private" } { %0 = "toy.transpose"(%arg0) : (tensor<*xf64>) -> tensor<*xf64> %1 = "toy.transpose"(%arg1) : (tensor<*xf64>) -> tensor<*xf64> %2 = "toy.mul"(%0, %1) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64> diff --git a/mlir/test/Examples/Toy/Ch7/struct-codegen.toy b/mlir/test/Examples/Toy/Ch7/struct-codegen.toy --- a/mlir/test/Examples/Toy/Ch7/struct-codegen.toy +++ b/mlir/test/Examples/Toy/Ch7/struct-codegen.toy @@ -1,4 +1,4 @@ -# RUN: toyc-ch7 %s -emit=mlir 2>&1 +# RUN: toyc-ch7 %s -emit=mlir 2>&1 | FileCheck %s # RUN: toyc-ch7 %s -emit=mlir -opt 2>&1 | FileCheck %s --check-prefix=OPT struct Struct { @@ -23,6 +23,7 @@ # CHECK-LABEL: func @multiply_transpose( # CHECK-SAME: [[VAL_0:%.*]]: !toy.struct, tensor<*xf64>>) -> tensor<*xf64> +# CHECK-SAME: attributes {sym_visibility = "private"} # CHECK-NEXT: [[VAL_1:%.*]] = "toy.struct_access"([[VAL_0]]) {index = 0 : i64} : (!toy.struct, tensor<*xf64>>) -> tensor<*xf64> # CHECK-NEXT: [[VAL_2:%.*]] = "toy.transpose"([[VAL_1]]) : (tensor<*xf64>) -> tensor<*xf64> # CHECK-NEXT: [[VAL_3:%.*]] = "toy.struct_access"([[VAL_0]]) {index = 1 : i64} : (!toy.struct, tensor<*xf64>>) -> tensor<*xf64>