[mlir][docs] A friendlier improvement for the Toy tutorial chapter 4.
authorChenggang Zhao <lyricz@yeah.net>
Wed, 25 Aug 2021 00:41:35 +0000 (00:41 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Wed, 25 Aug 2021 00:44:51 +0000 (00:44 +0000)
Add notes for discarding private-visible functions in the Toy tutorial chapter 4.

Reviewed By: mehdi_amini

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

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

index 5eaa215..78cdfec 100644 (file)
@@ -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.