[llvm] 4e513f6 - [GlobalISel] Cleanup Combine.td

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 4 23:19:15 PDT 2023


Author: pvanhout
Date: 2023-09-05T08:19:06+02:00
New Revision: 4e513f69a155e4010f707ec8f840eac4ccc695fc

URL: https://github.com/llvm/llvm-project/commit/4e513f69a155e4010f707ec8f840eac4ccc695fc
DIFF: https://github.com/llvm/llvm-project/commit/4e513f69a155e4010f707ec8f840eac4ccc695fc.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Target/GlobalISel/Combine.td
    llvm/lib/Target/AArch64/AArch64Combine.td
    llvm/lib/Target/AMDGPU/AMDGPUCombine.td
    llvm/lib/Target/Mips/MipsCombine.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td
    llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td
    llvm/utils/TableGen/GlobalISel/CombinerUtils.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Target/GlobalISel/Combine.td b/llvm/include/llvm/Target/GlobalISel/Combine.td
index 2389187fadf32d..9aaed7983cb1e0 100644
--- 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 @@ class GICombineGroup<list<GICombine> rules> : GICombine {
   let Rules = rules;
 }
 
-class GICombinerHelperArg<string type, string name> {
-  string Type = type;
-  string Name = name;
-}
-
-// Declares a combiner helper class
-class GICombinerHelper<string classname, list<GICombine> rules>
+// Declares a combiner implementation class
+class GICombiner<string classname, list<GICombine> rules>
     : GICombineGroup<rules> {
   // 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<GICombinerHelperArg> AdditionalArguments =
-      [GICombinerHelperArg<"CombinerHelper &", "Helper">];
 }
+
+/// Declares data that is passed from the match stage to the apply stage.
+class GIDefMatchData<string type>  {
+  /// A C++ type name indicating the storage type.
+  string Type = type;
+}
+
 class GICombineRule<dag defs, dag match, dag apply> : 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 @@ class GICombineRule<dag defs, dag match, dag apply> : GICombine {
   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 @@ class GICombineRule<dag defs, dag match, dag apply> : GICombine {
   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 @@ class GICombinePatFrag<dag outs, dag ins, list<dag> alts> {
   list<dag> 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<string type> : 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
index 0c3a0f94d9cf02..6bcb014d22035e 100644
--- a/llvm/lib/Target/AArch64/AArch64Combine.td
+++ b/llvm/lib/Target/AArch64/AArch64Combine.td
@@ -33,7 +33,7 @@ def fold_global_offset : GICombineRule<
   (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 @@ def AArch64PreLegalizerCombiner: GICombinerHelper<
   let CombineAllMethodName = "tryCombineAllImpl";
 }
 
-def AArch64O0PreLegalizerCombiner: GICombinerHelper<
+def AArch64O0PreLegalizerCombiner: GICombiner<
   "AArch64O0PreLegalizerCombinerImpl", [optnone_combines]> {
   let CombineAllMethodName = "tryCombineAllImpl";
 }
@@ -210,7 +210,7 @@ def vector_sext_inreg_to_shift : GICombineRule<
 // (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 @@ def AArch64PostLegalizerLowering
 
 // 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
index b5988d599c5d76..8d4cad4c07bc74 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCombine.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCombine.td
@@ -139,13 +139,13 @@ def gfx6gfx7_combines : GICombineGroup<[fcmp_select_to_fmin_fmax_legacy]>;
 // 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 @@ def AMDGPUPostLegalizerCombiner: GICombinerHelper<
   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
index cb1594421cc588..d757ef9ee0f029 100644
--- 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
index 4dd87a1c815c5c..b3e7ba28b0fa3f 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
@@ -26,7 +26,7 @@ def CImmInstTest1 : GICombineRule<
   (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
index 31969473eca67c..fa2451aa958201 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-operand-types.td
@@ -15,7 +15,7 @@ def InstTest0 : GICombineRule<
   (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
index 41ec2b405a2b52..21a31a9fc5bf5d 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-patfrag-root.td
@@ -22,7 +22,7 @@ def Test0 : GICombineRule<
   (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
index ec521eb159092b..e6825ba6607ea6 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-permutations.td
@@ -26,7 +26,7 @@ def Test0 : GICombineRule<
   ),
   (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
index 3ba34972469e71..cbe20d067fe9b2 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-variadics.td
@@ -28,7 +28,7 @@ def InstTest3 : GICombineRule<
   (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
index 99614f1bce017f..0f20e75d38a5d2 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table.td
@@ -64,7 +64,7 @@ def PatFragTest0 : GICombineRule<
 
 // 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
index 2a0185e744cdc7..c871e603e4e05a 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/operand-types.td
@@ -79,7 +79,7 @@ def PatFragTest0 : GICombineRule<
   (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
index 5d176ec960660d..68bec4fa722d19 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/patfrag-errors.td
@@ -273,7 +273,7 @@ def root_def_has_multi_defs : GICombineRule<
 
 // 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
index 5b3c7f1670b4f7..71dc0490099e48 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td
@@ -219,7 +219,7 @@ def def_named_imm_apply : GICombineRule<
 
 // 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
index 9c3739e4a08ea8..f0f83dd428adbf 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-parsing.td
@@ -297,7 +297,7 @@ def VariadicsOutTest : GICombineRule<
   (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
index 3d34eb450ed2d2..07671efcc57516 100644
--- a/llvm/utils/TableGen/GlobalISel/CombinerUtils.h
+++ b/llvm/utils/TableGen/GlobalISel/CombinerUtils.h
@@ -31,7 +31,7 @@ inline bool isSpecificDef(const Init &N, StringRef Def) {
 
 /// 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<DefInit>(&N))
@@ -42,7 +42,7 @@ inline Record *getDefOfSubClass(const Init &N, StringRef Cls) {
 
 /// 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 @@ inline const DagInit *getDagWithSpecificOperator(const Init &N,
 
 /// 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) {


        


More information about the llvm-commits mailing list