diff --git a/llvm/include/llvm/Target/GlobalISel/Combine.td b/llvm/include/llvm/Target/GlobalISel/Combine.td --- a/llvm/include/llvm/Target/GlobalISel/Combine.td +++ b/llvm/include/llvm/Target/GlobalISel/Combine.td @@ -10,6 +10,30 @@ // //===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +// Base Classes +// +// These are the core classes that the combiner backend relies on. +//===----------------------------------------------------------------------===// + +/// All arguments of the defs operator must be subclasses of GIDefKind or +/// sub-dags whose operator is GIDefKindWithArgs. +class GIDefKind; +class GIDefKindWithArgs; + +/// Declare a root node. There must be at least one of these in every combine +/// rule. +def root : GIDefKind; + +def defs; + +def pattern; +def match; +def apply; + +def wip_match_opcode; + // Common base class for GICombineRule and GICombineGroup. class GICombine { // See GICombineGroup. We only declare it here to make the tablegen pass @@ -27,29 +51,22 @@ let Rules = rules; } -class GICombinerHelperArg { - string Type = type; - string Name = name; -} - -// Declares a combiner helper class -class GICombinerHelper rules> +// Declares a combiner implementation class +class GICombiner rules> : GICombineGroup { // The class name to use in the generated output. string Classname = classname; // Combiners can use this so they're free to define tryCombineAll themselves // and do extra work before/after calling the TableGen-erated code. string CombineAllMethodName = "tryCombineAll"; - // The name of a run-time compiler option that will be generated to disable - // specific rules within this combiner. - string DisableRuleOption = ?; - // The state class to inherit from (if any). The generated helper will inherit - // from this class and will forward arguments to its constructors. - string StateClass = ""; - // Any additional arguments that should be appended to the tryCombine*(). - list AdditionalArguments = - [GICombinerHelperArg<"CombinerHelper &", "Helper">]; } + +/// Declares data that is passed from the match stage to the apply stage. +class GIDefMatchData { + /// A C++ type name indicating the storage type. + string Type = type; +} + class GICombineRule : GICombine { /// Defines the external interface of the match rule. This includes: /// * The names of the root nodes (requires at least one) @@ -57,12 +74,10 @@ dag Defs = defs; /// Defines the things which must be true for the pattern to match - /// See GIMatchKind for details. dag Match = match; /// Defines the things which happen after the decision is made to apply a /// combine rule. - /// See GIApplyKind for details. dag Apply = apply; /// Defines the predicates that are checked before the match function @@ -75,20 +90,8 @@ int MaxPermutations = 16; } -/// All arguments of the defs operator must be subclasses of GIDefKind or -/// sub-dags whose operator is GIDefKindWithArgs. -class GIDefKind; -class GIDefKindWithArgs; -/// Declare a root node. There must be at least one of these in every combine -/// rule. -/// TODO: The plan is to elide `root` definitions and determine it from the DAG -/// itself with an overide for situations where the usual determination -/// is incorrect. -def root : GIDefKind; - def gi_mo; def gi_imm; -def pattern; // This is an equivalent of PatFrags but for MIR Patterns. // @@ -107,45 +110,12 @@ list Alternatives = alts; } -/// The operator at the root of a GICombineRule.Defs dag. -def defs; - -/// Declares data that is passed from the match stage to the apply stage. -class GIDefMatchData : GIDefKind { - /// A C++ type name indicating the storage type. - string Type = type; -} +//===----------------------------------------------------------------------===// def extending_load_matchdata : GIDefMatchData<"PreferredTuple">; def indexed_load_store_matchdata : GIDefMatchData<"IndexedLoadStoreMatchInfo">; def instruction_steps_matchdata: GIDefMatchData<"InstructionStepsMatchInfo">; -/// The operator at the root of a GICombineRule.Match dag. -def match; -/// All arguments of the match operator must be either: -/// * A subclass of GIMatchKind -/// * A subclass of GIMatchKindWithArgs -/// * A subclass of Instruction -/// * A MIR code block (deprecated) -/// The GIMatchKind and GIMatchKindWithArgs cases are described in more detail -/// in their definitions below. -/// For the Instruction case, these are collected into a DAG where operand names -/// that occur multiple times introduce edges. -class GIMatchKind; -class GIMatchKindWithArgs; - -/// In lieu of having proper macro support. Trivial one-off opcode checks can be -/// performed with this. -def wip_match_opcode : GIMatchKindWithArgs; - -/// The operator at the root of a GICombineRule.Apply dag. -def apply; -/// All arguments of the apply operator must be subclasses of GIApplyKind, or -/// sub-dags whose operator is GIApplyKindWithArgs, or an MIR block -/// (deprecated). -class GIApplyKind; -class GIApplyKindWithArgs; - def register_matchinfo: GIDefMatchData<"Register">; def int64_matchinfo: GIDefMatchData<"int64_t">; def apint_matchinfo : GIDefMatchData<"APInt">; diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td b/llvm/lib/Target/AArch64/AArch64Combine.td --- a/llvm/lib/Target/AArch64/AArch64Combine.td +++ b/llvm/lib/Target/AArch64/AArch64Combine.td @@ -33,7 +33,7 @@ (apply [{ applyFoldGlobalOffset(*${root}, MRI, B, Observer, ${matchinfo});}]) >; -def AArch64PreLegalizerCombiner: GICombinerHelper< +def AArch64PreLegalizerCombiner: GICombiner< "AArch64PreLegalizerCombinerImpl", [all_combines, fconstant_to_constant, icmp_redundant_trunc, @@ -41,7 +41,7 @@ let CombineAllMethodName = "tryCombineAllImpl"; } -def AArch64O0PreLegalizerCombiner: GICombinerHelper< +def AArch64O0PreLegalizerCombiner: GICombiner< "AArch64O0PreLegalizerCombinerImpl", [optnone_combines]> { let CombineAllMethodName = "tryCombineAllImpl"; } @@ -210,7 +210,7 @@ // (E.g. ones that facilitate matching for the selector) For example, matching // pseudos. def AArch64PostLegalizerLowering - : GICombinerHelper<"AArch64PostLegalizerLoweringImpl", + : GICombiner<"AArch64PostLegalizerLoweringImpl", [shuffle_vector_lowering, vashr_vlshr_imm, icmp_lowering, build_vector_lowering, lower_vector_fcmp, form_truncstore, @@ -219,7 +219,7 @@ // Post-legalization combines which are primarily optimizations. def AArch64PostLegalizerCombiner - : GICombinerHelper<"AArch64PostLegalizerCombinerImpl", + : GICombiner<"AArch64PostLegalizerCombinerImpl", [copy_prop, combines_for_extload, sext_trunc_sextload, mutate_anyext_to_zext, hoist_logic_op_with_same_opcode_hands, diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCombine.td b/llvm/lib/Target/AMDGPU/AMDGPUCombine.td --- a/llvm/lib/Target/AMDGPU/AMDGPUCombine.td +++ b/llvm/lib/Target/AMDGPU/AMDGPUCombine.td @@ -139,13 +139,13 @@ // Combines which should only apply on VI def gfx8_combines : GICombineGroup<[expand_promoted_fmed3]>; -def AMDGPUPreLegalizerCombiner: GICombinerHelper< +def AMDGPUPreLegalizerCombiner: GICombiner< "AMDGPUPreLegalizerCombinerImpl", [all_combines, clamp_i64_to_i16, foldable_fneg]> { let CombineAllMethodName = "tryCombineAllImpl"; } -def AMDGPUPostLegalizerCombiner: GICombinerHelper< +def AMDGPUPostLegalizerCombiner: GICombiner< "AMDGPUPostLegalizerCombinerImpl", [all_combines, gfx6gfx7_combines, gfx8_combines, uchar_to_float, cvt_f32_ubyteN, remove_fcanonicalize, foldable_fneg, @@ -153,7 +153,7 @@ let CombineAllMethodName = "tryCombineAllImpl"; } -def AMDGPURegBankCombiner : GICombinerHelper< +def AMDGPURegBankCombiner : GICombiner< "AMDGPURegBankCombinerImpl", [unmerge_merge, unmerge_cst, unmerge_undef, zext_trunc_fold, int_minmax_to_med3, ptr_add_immed_chain, diff --git a/llvm/lib/Target/Mips/MipsCombine.td b/llvm/lib/Target/Mips/MipsCombine.td --- a/llvm/lib/Target/Mips/MipsCombine.td +++ b/llvm/lib/Target/Mips/MipsCombine.td @@ -8,6 +8,6 @@ include "llvm/Target/GlobalISel/Combine.td" -def MipsPostLegalizerCombiner: GICombinerHelper< +def MipsPostLegalizerCombiner: GICombiner< "MipsPostLegalizerCombinerImpl", []> { } diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td @@ -26,7 +26,7 @@ (match (G_CONSTANT $a, (i32 0))), (apply (G_CONSTANT $a, (i32 42)))>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ InstTest0, InstTest1, CImmInstTest1 diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td @@ -15,7 +15,7 @@ (apply (G_ADD i64:$tmp, $b, i32:$c), (G_ADD i8:$a, $b, i64:$tmp))>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ InstTest0, ]>; diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td @@ -22,7 +22,7 @@ (match (MatchFooPerms $root, (i32 10))), (apply (COPY $root, (i32 0)))>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ Test0 ]>; diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td @@ -26,7 +26,7 @@ ), (apply (COPY $dst, (i32 0)), "APPLY ${cst0}")>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ Test0 ]>; diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td @@ -28,7 +28,7 @@ (match (G_UNMERGE_VALUES $a, $b, $c, $d)), (apply [{ APPLY }])>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ InstTest0, InstTest1, InstTest2, diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td @@ -64,7 +64,7 @@ // TODO: add test with temp reg use -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ WipOpcodeTest0, WipOpcodeTest1, InstTest0, diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td @@ -79,7 +79,7 @@ (match (FooPF $dst)), (apply (COPY $dst, (i32 0)))>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ InstTest0, PatFragTest0 ]>; diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td @@ -273,7 +273,7 @@ // CHECK: error: Failed to parse one or more rules -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ too_many_perms, undef_livein, out_must_be_root, diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td @@ -219,7 +219,7 @@ // CHECK: error: Failed to parse one or more rules -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ root_not_found, misleading_root, cxx_root, diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td --- a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td +++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td @@ -297,7 +297,7 @@ (apply (COPY $a, (i32 0)), (COPY $b, (i32 0)))>; -def MyCombiner: GICombinerHelper<"GenMyCombiner", [ +def MyCombiner: GICombiner<"GenMyCombiner", [ WipOpcodeTest0, WipOpcodeTest1, InstTest0, diff --git a/llvm/utils/TableGen/GlobalISel/CombinerUtils.h b/llvm/utils/TableGen/GlobalISel/CombinerUtils.h --- a/llvm/utils/TableGen/GlobalISel/CombinerUtils.h +++ b/llvm/utils/TableGen/GlobalISel/CombinerUtils.h @@ -31,7 +31,7 @@ /// A convenience function to check that an Init refers to a def that is a /// subclass of the given class and coerce it to a def if it is. This is -/// primarily useful for testing for subclasses of GIMatchKind and similar in +/// primarily useful for testing for subclasses of GIDefKind and similar in /// DagInit's since DagInit's support any type inside them. inline Record *getDefOfSubClass(const Init &N, StringRef Cls) { if (const DefInit *OpI = dyn_cast(&N)) @@ -42,7 +42,7 @@ /// A convenience function to check that an Init refers to a dag whose operator /// is a specific def and coerce it to a dag if it is. This is primarily useful -/// for testing for subclasses of GIMatchKind and similar in DagInit's since +/// for testing for subclasses of GIDefKind and similar in DagInit's since /// DagInit's support any type inside them. inline const DagInit *getDagWithSpecificOperator(const Init &N, StringRef Name) { @@ -56,7 +56,7 @@ /// A convenience function to check that an Init refers to a dag whose operator /// is a def that is a subclass of the given class and coerce it to a dag if it -/// is. This is primarily useful for testing for subclasses of GIMatchKind and +/// is. This is primarily useful for testing for subclasses of GIDefKind and /// similar in DagInit's since DagInit's support any type inside them. inline const DagInit *getDagWithOperatorOfSubClass(const Init &N, StringRef Cls) {