[Mlir-commits] [mlir] 2b2c13e - [mlir][docs] A friendlier improvement for the Toy tutorial chapter 4.

Mehdi Amini llvmlistbot at llvm.org
Tue Aug 24 17:45:01 PDT 2021


Author: Chenggang Zhao
Date: 2021-08-25T00:44:51Z
New Revision: 2b2c13e672bdbf812b8bb47f0575e534b3c9c8c6

URL: https://github.com/llvm/llvm-project/commit/2b2c13e672bdbf812b8bb47f0575e534b3c9c8c6
DIFF: https://github.com/llvm/llvm-project/commit/2b2c13e672bdbf812b8bb47f0575e534b3c9c8c6.diff

LOG: [mlir][docs] A friendlier improvement for the Toy tutorial chapter 4.

Add notes for discarding private-visible functions in the Toy tutorial chapter 4.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D108026

Added: 
    

Modified: 
    mlir/docs/Tutorials/Toy/Ch-4.md

Removed: 
    


################################################################################
diff  --git a/mlir/docs/Tutorials/Toy/Ch-4.md b/mlir/docs/Tutorials/Toy/Ch-4.md
index 5eaa2156a8458..78cdfec4e4b2f 100644
--- a/mlir/docs/Tutorials/Toy/Ch-4.md
+++ b/mlir/docs/Tutorials/Toy/Ch-4.md
@@ -95,6 +95,22 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
 };
 ```
 
+Besides, the inliner will only discard private-visible unused function
+definitions. We also have to set the visibility of functions (except the
+main function) in the MLIR generator.
+
+```c++
+/// Emit a new function and add it to the MLIR module.
+mlir::FuncOp mlirGen(FunctionAST &funcAST) {
+  ...
+  // If this function isn't main, then set the visibility to private.
+  if (funcAST.getProto()->getName() != "main")
+    function.setPrivate();
+
+  return function;
+}
+```
+
 We then register our dialect interface directly on the Toy dialect, similarly to
 how we did for operations.
 


        


More information about the Mlir-commits mailing list