xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Target/GlobalISel/Combine.td (revision 68d75eff68281c1b445e3010bb975eae07aac225)
1//===- Combine.td - Combine rule definitions ---------------*- tablegen -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Declare GlobalISel combine rules and provide mechanisms to opt-out.
10//
11//===----------------------------------------------------------------------===//
12
13// Common base class for GICombineRule and GICombineGroup.
14class GICombine {
15  // See GICombineGroup. We only declare it here to make the tablegen pass
16  // simpler.
17  list<GICombine> Rules = ?;
18}
19
20// A group of combine rules that can be added to a GICombiner or another group.
21class 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.
27  let Rules = rules;
28}
29
30// Declares a combiner helper class
31class 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 = ?;
38}
39class 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.
43  dag Defs = defs;
44
45  /// Defines the things which must be true for the pattern to match
46  /// See GIMatchKind for details.
47  dag Match = match;
48
49  /// Defines the things which happen after the decision is made to apply a
50  /// combine rule.
51  /// See GIApplyKind for details.
52  dag Apply = apply;
53}
54
55/// The operator at the root of a GICombineRule.Defs dag.
56def defs;
57
58/// All arguments of the defs operator must be subclasses of GIDefKind or
59/// sub-dags whose operator is GIDefKindWithArgs.
60class GIDefKind;
61class GIDefKindWithArgs;
62/// Declare a root node. There must be at least one of these in every combine
63/// rule.
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
66///       is incorrect.
67def root : GIDefKind;
68
69/// The operator at the root of a GICombineRule.Match dag.
70def match;
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.
79class GIMatchKind;
80class GIMatchKindWithArgs;
81
82/// The operator at the root of a GICombineRule.Apply dag.
83def apply;
84/// All arguments of the apply operator must be subclasses of GIApplyKind, or
85/// sub-dags whose operator is GIApplyKindWithArgs, or an MIR block
86/// (deprecated).
87class GIApplyKind;
88class GIApplyKindWithArgs;
89
90def copy_prop : GICombineRule<
91  (defs root:$d),
92  (match [{ return Helper.matchCombineCopy(${d}); }]),
93  (apply [{ Helper.applyCombineCopy(${d}); }])>;
94def trivial_combines : GICombineGroup<[copy_prop]>;
95
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.
98def elide_br_by_inverting_cond : GICombineRule<
99  (defs root:$d),
100  (match [{ return Helper.matchElideBrByInvertingCond(${d}); }]),
101  (apply [{ Helper.applyElideBrByInvertingCond(${d}); }])>;
102
103def all_combines : GICombineGroup<[trivial_combines]>;
104