Skip to content

Commit 4e513f6

Browse files
committed
[GlobalISel] Cleanup Combine.td
Now that the old backend is gone, clean-up a few things that no longer make sense and tidy up the file a bit. Depends on D158710 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D158714
1 parent aaf6755 commit 4e513f6

15 files changed

+55
-85
lines changed

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
14+
//===----------------------------------------------------------------------===//
15+
// Base Classes
16+
//
17+
// These are the core classes that the combiner backend relies on.
18+
//===----------------------------------------------------------------------===//
19+
20+
/// All arguments of the defs operator must be subclasses of GIDefKind or
21+
/// sub-dags whose operator is GIDefKindWithArgs.
22+
class GIDefKind;
23+
class GIDefKindWithArgs;
24+
25+
/// Declare a root node. There must be at least one of these in every combine
26+
/// rule.
27+
def root : GIDefKind;
28+
29+
def defs;
30+
31+
def pattern;
32+
def match;
33+
def apply;
34+
35+
def wip_match_opcode;
36+
1337
// Common base class for GICombineRule and GICombineGroup.
1438
class GICombine {
1539
// See GICombineGroup. We only declare it here to make the tablegen pass
@@ -27,42 +51,33 @@ class GICombineGroup<list<GICombine> rules> : GICombine {
2751
let Rules = rules;
2852
}
2953

30-
class GICombinerHelperArg<string type, string name> {
31-
string Type = type;
32-
string Name = name;
33-
}
34-
35-
// Declares a combiner helper class
36-
class GICombinerHelper<string classname, list<GICombine> rules>
54+
// Declares a combiner implementation class
55+
class GICombiner<string classname, list<GICombine> rules>
3756
: GICombineGroup<rules> {
3857
// The class name to use in the generated output.
3958
string Classname = classname;
4059
// Combiners can use this so they're free to define tryCombineAll themselves
4160
// and do extra work before/after calling the TableGen-erated code.
4261
string CombineAllMethodName = "tryCombineAll";
43-
// The name of a run-time compiler option that will be generated to disable
44-
// specific rules within this combiner.
45-
string DisableRuleOption = ?;
46-
// The state class to inherit from (if any). The generated helper will inherit
47-
// from this class and will forward arguments to its constructors.
48-
string StateClass = "";
49-
// Any additional arguments that should be appended to the tryCombine*().
50-
list<GICombinerHelperArg> AdditionalArguments =
51-
[GICombinerHelperArg<"CombinerHelper &", "Helper">];
5262
}
63+
64+
/// Declares data that is passed from the match stage to the apply stage.
65+
class GIDefMatchData<string type> {
66+
/// A C++ type name indicating the storage type.
67+
string Type = type;
68+
}
69+
5370
class GICombineRule<dag defs, dag match, dag apply> : GICombine {
5471
/// Defines the external interface of the match rule. This includes:
5572
/// * The names of the root nodes (requires at least one)
5673
/// See GIDefKind for details.
5774
dag Defs = defs;
5875

5976
/// Defines the things which must be true for the pattern to match
60-
/// See GIMatchKind for details.
6177
dag Match = match;
6278

6379
/// Defines the things which happen after the decision is made to apply a
6480
/// combine rule.
65-
/// See GIApplyKind for details.
6681
dag Apply = apply;
6782

6883
/// Defines the predicates that are checked before the match function
@@ -75,20 +90,8 @@ class GICombineRule<dag defs, dag match, dag apply> : GICombine {
7590
int MaxPermutations = 16;
7691
}
7792

78-
/// All arguments of the defs operator must be subclasses of GIDefKind or
79-
/// sub-dags whose operator is GIDefKindWithArgs.
80-
class GIDefKind;
81-
class GIDefKindWithArgs;
82-
/// Declare a root node. There must be at least one of these in every combine
83-
/// rule.
84-
/// TODO: The plan is to elide `root` definitions and determine it from the DAG
85-
/// itself with an overide for situations where the usual determination
86-
/// is incorrect.
87-
def root : GIDefKind;
88-
8993
def gi_mo;
9094
def gi_imm;
91-
def pattern;
9295

9396
// This is an equivalent of PatFrags but for MIR Patterns.
9497
//
@@ -107,45 +110,12 @@ class GICombinePatFrag<dag outs, dag ins, list<dag> alts> {
107110
list<dag> Alternatives = alts;
108111
}
109112

110-
/// The operator at the root of a GICombineRule.Defs dag.
111-
def defs;
112-
113-
/// Declares data that is passed from the match stage to the apply stage.
114-
class GIDefMatchData<string type> : GIDefKind {
115-
/// A C++ type name indicating the storage type.
116-
string Type = type;
117-
}
113+
//===----------------------------------------------------------------------===//
118114

119115
def extending_load_matchdata : GIDefMatchData<"PreferredTuple">;
120116
def indexed_load_store_matchdata : GIDefMatchData<"IndexedLoadStoreMatchInfo">;
121117
def instruction_steps_matchdata: GIDefMatchData<"InstructionStepsMatchInfo">;
122118

123-
/// The operator at the root of a GICombineRule.Match dag.
124-
def match;
125-
/// All arguments of the match operator must be either:
126-
/// * A subclass of GIMatchKind
127-
/// * A subclass of GIMatchKindWithArgs
128-
/// * A subclass of Instruction
129-
/// * A MIR code block (deprecated)
130-
/// The GIMatchKind and GIMatchKindWithArgs cases are described in more detail
131-
/// in their definitions below.
132-
/// For the Instruction case, these are collected into a DAG where operand names
133-
/// that occur multiple times introduce edges.
134-
class GIMatchKind;
135-
class GIMatchKindWithArgs;
136-
137-
/// In lieu of having proper macro support. Trivial one-off opcode checks can be
138-
/// performed with this.
139-
def wip_match_opcode : GIMatchKindWithArgs;
140-
141-
/// The operator at the root of a GICombineRule.Apply dag.
142-
def apply;
143-
/// All arguments of the apply operator must be subclasses of GIApplyKind, or
144-
/// sub-dags whose operator is GIApplyKindWithArgs, or an MIR block
145-
/// (deprecated).
146-
class GIApplyKind;
147-
class GIApplyKindWithArgs;
148-
149119
def register_matchinfo: GIDefMatchData<"Register">;
150120
def int64_matchinfo: GIDefMatchData<"int64_t">;
151121
def apint_matchinfo : GIDefMatchData<"APInt">;

llvm/lib/Target/AArch64/AArch64Combine.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def fold_global_offset : GICombineRule<
3333
(apply [{ applyFoldGlobalOffset(*${root}, MRI, B, Observer, ${matchinfo});}])
3434
>;
3535

36-
def AArch64PreLegalizerCombiner: GICombinerHelper<
36+
def AArch64PreLegalizerCombiner: GICombiner<
3737
"AArch64PreLegalizerCombinerImpl", [all_combines,
3838
fconstant_to_constant,
3939
icmp_redundant_trunc,
4040
fold_global_offset]> {
4141
let CombineAllMethodName = "tryCombineAllImpl";
4242
}
4343

44-
def AArch64O0PreLegalizerCombiner: GICombinerHelper<
44+
def AArch64O0PreLegalizerCombiner: GICombiner<
4545
"AArch64O0PreLegalizerCombinerImpl", [optnone_combines]> {
4646
let CombineAllMethodName = "tryCombineAllImpl";
4747
}
@@ -210,7 +210,7 @@ def vector_sext_inreg_to_shift : GICombineRule<
210210
// (E.g. ones that facilitate matching for the selector) For example, matching
211211
// pseudos.
212212
def AArch64PostLegalizerLowering
213-
: GICombinerHelper<"AArch64PostLegalizerLoweringImpl",
213+
: GICombiner<"AArch64PostLegalizerLoweringImpl",
214214
[shuffle_vector_lowering, vashr_vlshr_imm,
215215
icmp_lowering, build_vector_lowering,
216216
lower_vector_fcmp, form_truncstore,
@@ -219,7 +219,7 @@ def AArch64PostLegalizerLowering
219219

220220
// Post-legalization combines which are primarily optimizations.
221221
def AArch64PostLegalizerCombiner
222-
: GICombinerHelper<"AArch64PostLegalizerCombinerImpl",
222+
: GICombiner<"AArch64PostLegalizerCombinerImpl",
223223
[copy_prop, combines_for_extload,
224224
sext_trunc_sextload, mutate_anyext_to_zext,
225225
hoist_logic_op_with_same_opcode_hands,

llvm/lib/Target/AMDGPU/AMDGPUCombine.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,21 @@ def gfx6gfx7_combines : GICombineGroup<[fcmp_select_to_fmin_fmax_legacy]>;
139139
// Combines which should only apply on VI
140140
def gfx8_combines : GICombineGroup<[expand_promoted_fmed3]>;
141141

142-
def AMDGPUPreLegalizerCombiner: GICombinerHelper<
142+
def AMDGPUPreLegalizerCombiner: GICombiner<
143143
"AMDGPUPreLegalizerCombinerImpl",
144144
[all_combines, clamp_i64_to_i16, foldable_fneg]> {
145145
let CombineAllMethodName = "tryCombineAllImpl";
146146
}
147147

148-
def AMDGPUPostLegalizerCombiner: GICombinerHelper<
148+
def AMDGPUPostLegalizerCombiner: GICombiner<
149149
"AMDGPUPostLegalizerCombinerImpl",
150150
[all_combines, gfx6gfx7_combines, gfx8_combines,
151151
uchar_to_float, cvt_f32_ubyteN, remove_fcanonicalize, foldable_fneg,
152152
rcp_sqrt_to_rsq, sign_extension_in_reg]> {
153153
let CombineAllMethodName = "tryCombineAllImpl";
154154
}
155155

156-
def AMDGPURegBankCombiner : GICombinerHelper<
156+
def AMDGPURegBankCombiner : GICombiner<
157157
"AMDGPURegBankCombinerImpl",
158158
[unmerge_merge, unmerge_cst, unmerge_undef,
159159
zext_trunc_fold, int_minmax_to_med3, ptr_add_immed_chain,

llvm/lib/Target/Mips/MipsCombine.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
include "llvm/Target/GlobalISel/Combine.td"
1010

11-
def MipsPostLegalizerCombiner: GICombinerHelper<
11+
def MipsPostLegalizerCombiner: GICombiner<
1212
"MipsPostLegalizerCombinerImpl", []> {
1313
}

llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def CImmInstTest1 : GICombineRule<
2626
(match (G_CONSTANT $a, (i32 0))),
2727
(apply (G_CONSTANT $a, (i32 42)))>;
2828

29-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
29+
def MyCombiner: GICombiner<"GenMyCombiner", [
3030
InstTest0,
3131
InstTest1,
3232
CImmInstTest1

llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def InstTest0 : GICombineRule<
1515
(apply (G_ADD i64:$tmp, $b, i32:$c),
1616
(G_ADD i8:$a, $b, i64:$tmp))>;
1717

18-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
18+
def MyCombiner: GICombiner<"GenMyCombiner", [
1919
InstTest0,
2020
]>;
2121

llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def Test0 : GICombineRule<
2222
(match (MatchFooPerms $root, (i32 10))),
2323
(apply (COPY $root, (i32 0)))>;
2424

25-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
25+
def MyCombiner: GICombiner<"GenMyCombiner", [
2626
Test0
2727
]>;
2828

llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def Test0 : GICombineRule<
2626
),
2727
(apply (COPY $dst, (i32 0)), "APPLY ${cst0}")>;
2828

29-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
29+
def MyCombiner: GICombiner<"GenMyCombiner", [
3030
Test0
3131
]>;
3232

llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def InstTest3 : GICombineRule<
2828
(match (G_UNMERGE_VALUES $a, $b, $c, $d)),
2929
(apply [{ APPLY }])>;
3030

31-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
31+
def MyCombiner: GICombiner<"GenMyCombiner", [
3232
InstTest0,
3333
InstTest1,
3434
InstTest2,

llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def PatFragTest0 : GICombineRule<
6464

6565
// TODO: add test with temp reg use
6666

67-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
67+
def MyCombiner: GICombiner<"GenMyCombiner", [
6868
WipOpcodeTest0,
6969
WipOpcodeTest1,
7070
InstTest0,

llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def PatFragTest0 : GICombineRule<
7979
(match (FooPF $dst)),
8080
(apply (COPY $dst, (i32 0)))>;
8181

82-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
82+
def MyCombiner: GICombiner<"GenMyCombiner", [
8383
InstTest0,
8484
PatFragTest0
8585
]>;

llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def root_def_has_multi_defs : GICombineRule<
273273

274274
// CHECK: error: Failed to parse one or more rules
275275

276-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
276+
def MyCombiner: GICombiner<"GenMyCombiner", [
277277
too_many_perms,
278278
undef_livein,
279279
out_must_be_root,

llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def def_named_imm_apply : GICombineRule<
219219

220220
// CHECK: error: Failed to parse one or more rules
221221

222-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
222+
def MyCombiner: GICombiner<"GenMyCombiner", [
223223
root_not_found,
224224
misleading_root,
225225
cxx_root,

llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def VariadicsOutTest : GICombineRule<
297297
(apply (COPY $a, (i32 0)),
298298
(COPY $b, (i32 0)))>;
299299

300-
def MyCombiner: GICombinerHelper<"GenMyCombiner", [
300+
def MyCombiner: GICombiner<"GenMyCombiner", [
301301
WipOpcodeTest0,
302302
WipOpcodeTest1,
303303
InstTest0,

llvm/utils/TableGen/GlobalISel/CombinerUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ inline bool isSpecificDef(const Init &N, StringRef Def) {
3131

3232
/// A convenience function to check that an Init refers to a def that is a
3333
/// subclass of the given class and coerce it to a def if it is. This is
34-
/// primarily useful for testing for subclasses of GIMatchKind and similar in
34+
/// primarily useful for testing for subclasses of GIDefKind and similar in
3535
/// DagInit's since DagInit's support any type inside them.
3636
inline Record *getDefOfSubClass(const Init &N, StringRef Cls) {
3737
if (const DefInit *OpI = dyn_cast<DefInit>(&N))
@@ -42,7 +42,7 @@ inline Record *getDefOfSubClass(const Init &N, StringRef Cls) {
4242

4343
/// A convenience function to check that an Init refers to a dag whose operator
4444
/// is a specific def and coerce it to a dag if it is. This is primarily useful
45-
/// for testing for subclasses of GIMatchKind and similar in DagInit's since
45+
/// for testing for subclasses of GIDefKind and similar in DagInit's since
4646
/// DagInit's support any type inside them.
4747
inline const DagInit *getDagWithSpecificOperator(const Init &N,
4848
StringRef Name) {
@@ -56,7 +56,7 @@ inline const DagInit *getDagWithSpecificOperator(const Init &N,
5656

5757
/// A convenience function to check that an Init refers to a dag whose operator
5858
/// is a def that is a subclass of the given class and coerce it to a dag if it
59-
/// is. This is primarily useful for testing for subclasses of GIMatchKind and
59+
/// is. This is primarily useful for testing for subclasses of GIDefKind and
6060
/// similar in DagInit's since DagInit's support any type inside them.
6161
inline const DagInit *getDagWithOperatorOfSubClass(const Init &N,
6262
StringRef Cls) {

0 commit comments

Comments
 (0)