Skip to content

Commit

Permalink
[GlobalISel] Cleanup Combine.td
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pierre-vh committed Sep 5, 2023
1 parent aaf6755 commit 4e513f6
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 85 deletions.
98 changes: 34 additions & 64 deletions llvm/include/llvm/Target/GlobalISel/Combine.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,42 +51,33 @@ 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)
/// See GIDefKind for details.
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
Expand All @@ -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.
//
Expand All @@ -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">;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/AArch64/AArch64Combine.td
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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,
fold_global_offset]> {
let CombineAllMethodName = "tryCombineAllImpl";
}

def AArch64O0PreLegalizerCombiner: GICombinerHelper<
def AArch64O0PreLegalizerCombiner: GICombiner<
"AArch64O0PreLegalizerCombinerImpl", [optnone_combines]> {
let CombineAllMethodName = "tryCombineAllImpl";
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUCombine.td
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ 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,
rcp_sqrt_to_rsq, sign_extension_in_reg]> {
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,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Mips/MipsCombine.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

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

def MipsPostLegalizerCombiner: GICombinerHelper<
def MipsPostLegalizerCombiner: GICombiner<
"MipsPostLegalizerCombinerImpl", []> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def Test0 : GICombineRule<
),
(apply (COPY $dst, (i32 0)), "APPLY ${cst0}")>;

def MyCombiner: GICombinerHelper<"GenMyCombiner", [
def MyCombiner: GICombiner<"GenMyCombiner", [
Test0
]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
]>;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/TableGen/GlobalISel/CombinerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 4e513f6

Please sign in to comment.