From 0210a3de7b74e58aad45eb718acf8df69eb42291 Mon Sep 17 00:00:00 2001 From: Mogball Date: Fri, 1 Oct 2021 19:56:38 +0000 Subject: [PATCH] [MLIR] Update DRR doc with returnType directive Add missing documentation. Reviewed By: Chia-hungDuan, jpienaar Differential Revision: https://reviews.llvm.org/D110964 --- mlir/docs/DeclarativeRewrites.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mlir/docs/DeclarativeRewrites.md b/mlir/docs/DeclarativeRewrites.md index 8dac27d..7b6537b 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 -- 2.7.4