[llvm] [GlobalISel][TableGen] MIR Pattern Variadics (PR #100563)

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 11:30:45 PDT 2024


================
@@ -143,6 +143,57 @@ Semantics:
     (apply (G_FSUB $dst, $src, $tmp),
            (G_FNEG GITypeOf<"$dst">:$tmp, $src))>;
 
+GIVariadic
+~~~~~~~~~~
+
+``GIVariadic<>`` is a ``GISpecialType`` that allows for matching 1 or
+more operands remaining on an instruction.
+
+Type Parameters:
+
+* The minimum number of additional operands to match. Must be greater than zero.
+
+  * Default is 1.
+
+* The maximum number of additional operands to match. Must be strictly greater
+  than the minimum.
+
+  * 0 can be used to indicate there is no upper limit.
+  * Default is 0.
+
+Semantics:
+
+* ``GIVariadic<>`` operands can not be defs.
+* ``GIVariadic<>`` operands can only appear as the last operand in a 'match' pattern.
+* Each instance within a 'match' pattern must be uniquely named.
+* Re-using a ``GIVariadic<>`` operand in an 'apply' pattern will result in all
+  the matched operands being copied from the original instruction.
+* The min/max operands will result in the matcher checking that the number of operands
+  falls within that range.
+* ``GIVariadic<>`` operands can be used in C++ code within a rule, which will
+  result in the operand name being expanded to an iterator range containing all
+  the matched operands, similar to the one returned by ``MachineInstr::operands()``.
+
+.. code-block:: text
+
+  def build_vector_to_unmerge: GICombineRule <
+    (defs root:$root),
+    (match (G_BUILD_VECTOR $root, GIVariadic<>:$args),
+           [{ return checkBuildVectorToUnmerge(${args}); }]),
----------------
tschuett wrote:

Could you spell out the signature of `checkBuildVectorToUnmerge`? In particular, I am interested in the argument type.

https://github.com/llvm/llvm-project/pull/100563


More information about the llvm-commits mailing list