1 //===- Combine.td - Combine rule definitions ---------------*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Declare GlobalISel combine rules and provide mechanisms to opt-out.
11 //===----------------------------------------------------------------------===//
13 // Common base class for GICombineRule and GICombineGroup.
15 // See GICombineGroup. We only declare it here to make the tablegen pass
17 list<GICombine> Rules = ?;
20 // A group of combine rules that can be added to a GICombiner or another group.
21 class GICombineGroup<list<GICombine> rules> : GICombine {
22 // The rules contained in this group. The rules in a group are flattened into
23 // a single list and sorted into whatever order is most efficient. However,
24 // they will never be re-ordered such that behaviour differs from the
25 // specified order. It is therefore possible to use the order of rules in this
26 // list to describe priorities.
30 // Declares a combiner helper class
31 class GICombinerHelper<string classname, list<GICombine> rules>
32 : GICombineGroup<rules> {
33 // The class name to use in the generated output.
34 string Classname = classname;
35 // The name of a run-time compiler option that will be generated to disable
36 // specific rules within this combiner.
37 string DisableRuleOption = ?;
39 class GICombineRule<dag defs, dag match, dag apply> : GICombine {
40 /// Defines the external interface of the match rule. This includes:
41 /// * The names of the root nodes (requires at least one)
42 /// See GIDefKind for details.
45 /// Defines the things which must be true for the pattern to match
46 /// See GIMatchKind for details.
49 /// Defines the things which happen after the decision is made to apply a
51 /// See GIApplyKind for details.
55 /// The operator at the root of a GICombineRule.Defs dag.
58 /// All arguments of the defs operator must be subclasses of GIDefKind or
59 /// sub-dags whose operator is GIDefKindWithArgs.
61 class GIDefKindWithArgs;
62 /// Declare a root node. There must be at least one of these in every combine
64 /// TODO: The plan is to elide `root` definitions and determine it from the DAG
65 /// itself with an overide for situations where the usual determination
69 /// The operator at the root of a GICombineRule.Match dag.
71 /// All arguments of the match operator must be either:
72 /// * A subclass of GIMatchKind
73 /// * A subclass of GIMatchKindWithArgs
74 /// * A MIR code block (deprecated)
75 /// The GIMatchKind and GIMatchKindWithArgs cases are described in more detail
76 /// in their definitions below.
77 /// For the Instruction case, these are collected into a DAG where operand names
78 /// that occur multiple times introduce edges.
80 class GIMatchKindWithArgs;
82 /// The operator at the root of a GICombineRule.Apply dag.
84 /// All arguments of the apply operator must be subclasses of GIApplyKind, or
85 /// sub-dags whose operator is GIApplyKindWithArgs, or an MIR block
88 class GIApplyKindWithArgs;
90 def copy_prop : GICombineRule<
92 (match [{ return Helper.matchCombineCopy(${d}); }]),
93 (apply [{ Helper.applyCombineCopy(${d}); }])>;
94 def trivial_combines : GICombineGroup<[copy_prop]>;
96 // FIXME: Is there a reason this wasn't in tryCombine? I've left it out of
97 // all_combines because it wasn't there.
98 def elide_br_by_inverting_cond : GICombineRule<
100 (match [{ return Helper.matchElideBrByInvertingCond(${d}); }]),
101 (apply [{ Helper.applyElideBrByInvertingCond(${d}); }])>;
103 def all_combines : GICombineGroup<[trivial_combines]>;