[Mlir-commits] [mlir] 0210a3d - [MLIR] Update DRR doc with returnType directive

Jeff Niu llvmlistbot at llvm.org
Wed Oct 6 10:32:44 PDT 2021


Author: Mogball
Date: 2021-10-06T17:32:40Z
New Revision: 0210a3de7b74e58aad45eb718acf8df69eb42291

URL: https://github.com/llvm/llvm-project/commit/0210a3de7b74e58aad45eb718acf8df69eb42291
DIFF: https://github.com/llvm/llvm-project/commit/0210a3de7b74e58aad45eb718acf8df69eb42291.diff

LOG: [MLIR] Update DRR doc with returnType directive

Add missing documentation.

Reviewed By: Chia-hungDuan, jpienaar

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

Added: 
    

Modified: 
    mlir/docs/DeclarativeRewrites.md

Removed: 
    


################################################################################
diff  --git a/mlir/docs/DeclarativeRewrites.md b/mlir/docs/DeclarativeRewrites.md
index 8dac27d83e86..7b6537b9b0ed 100644
--- a/mlir/docs/DeclarativeRewrites.md
+++ b/mlir/docs/DeclarativeRewrites.md
@@ -714,7 +714,7 @@ string may be specified as an attribute. The following locations are created:
 *   If no symbol is specified then string must be specified and a NamedLoc is
     created instead;
 
-`location` must be used as the last argument to an op creation. For example,
+`location` must be used as a trailing argument to an op creation. For example,
 
 ```tablegen
 def : Pat<(LocSrc1Op:$src1 (LocSrc2Op:$src2 ...),
@@ -745,6 +745,34 @@ def : Pat<(Foo $input), (replaceWithValue $input)>;
 The above pattern removes the `Foo` and replaces all uses of `Foo` with
 `$input`.
 
+### `returnType`
+
+The `returnType` directive allows patterns to directly specify return types for
+replacement ops that lack return type inference with op traits or user-defined
+builders with return type deduction.
+
+The `returnType` directive must be used as a trailing argument to a node
+describing a replacement op. The directive comes in three forms:
+
+* `(returnType $value)`: copy the type of the operand or result bound to
+  `value`.
+* `(returnType "$_builder.getI32Type()")`: a string literal embedding C++. The
+  embedded snippet is expected to return a `Type` or a `TypeRange`.
+* `(returnType (NativeCodeCall<"myFunc($0)"> $value))`: a DAG node with a native
+  code call that can be passed any bound variables arguments.
+
+Specify multiple return types with a mix of any of the above. Example:
+
+```tablegen
+def : Pat<(SourceOp $arg0, $arg1),
+          (OpA $arg0, (TwoResultOp:$res__1 $arg1,
+                         (returnType $arg1, "$_builder.getI64Type()")))>;
+```
+
+Explicitly-specified return types will take precedence over return types
+inferred from op traits or user-defined builders. The return types of values
+replacing root op results cannot be overridden.
+
 ## Debugging Tips
 
 ### Run `mlir-tblgen` to see the generated content


        


More information about the Mlir-commits mailing list