[llvm] [GlobalISel] Add `combine` action for C++ combine rules (PR #135941)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 00:44:20 PDT 2025
================
@@ -370,6 +370,42 @@ The following expansions are available for MIR patterns:
(match (G_ZEXT $root, $src):$mi),
(apply "foobar(${root}.getReg(), ${src}.getReg(), ${mi}->hasImplicitDef())")>;
+``combine`` Operator
+~~~~~~~~~~~~~~~~~~~~
+
+``GICombineRule`` also supports a single ``combine`` pattern, which is a shorter way to
+declare patterns that just match one or more instruction, then defer all remaining matching
+and rewriting logic to C++ code.
+
+.. code-block:: text
+ :caption: Example usage of the combine operator.
+
+ // match + apply
+ def FooLong : GICombineRule<
+ (defs root:$root),
+ (match (G_ZEXT $root, $src):$mi, "return matchFoo(${mi});"),
+ (apply "applyFoo(${mi});")>;
+
+ // combine
+ def FooShort : GICombineRule<
+ (defs root:$root),
+ (combine (G_ZEXT $root, $src):$mi, "return combineFoo(${mi});")>;
----------------
Pierre-vh wrote:
It's the same thing yes. We have a convention that `apply` C++ code does not return anything/cannot fail. It's just a convention and not enforced anywhere AFAIK, so your example would work.
With `(combine` we allow the APPLY code to fail, so it can match/apply all in one.
https://github.com/llvm/llvm-project/pull/135941
More information about the llvm-commits
mailing list