diff options
author | pvanhout <pierre.vanhoutryve@amd.com> | 2023-06-27 14:36:52 +0200 |
---|---|---|
committer | pvanhout <pierre.vanhoutryve@amd.com> | 2023-07-11 11:27:14 +0200 |
commit | 2f608131b44c03ef1b358b314e7df169c1e22f53 (patch) | |
tree | f78503f49129f08635b833cec4152f99a53123ba | |
parent | 655714a300ff303a1f283718c34d9e27e096b319 (diff) | |
download | llvm-2f608131b44c03ef1b358b314e7df169c1e22f53.zip llvm-2f608131b44c03ef1b358b314e7df169c1e22f53.tar.gz llvm-2f608131b44c03ef1b358b314e7df169c1e22f53.tar.bz2 |
[MIPS] Use GlobalISel MatchTable Combiner Backend
Depends on D153757
NOTE: This would land iff D153757 (RFC) lands too.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D153861
-rw-r--r-- | llvm/lib/Target/Mips/CMakeLists.txt | 4 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MipsCombine.td | 6 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp | 71 |
3 files changed, 61 insertions, 20 deletions
diff --git a/llvm/lib/Target/Mips/CMakeLists.txt b/llvm/lib/Target/Mips/CMakeLists.txt index 57f2e01..5b70e89 100644 --- a/llvm/lib/Target/Mips/CMakeLists.txt +++ b/llvm/lib/Target/Mips/CMakeLists.txt @@ -9,8 +9,8 @@ tablegen(LLVM MipsGenDAGISel.inc -gen-dag-isel) tablegen(LLVM MipsGenDisassemblerTables.inc -gen-disassembler) tablegen(LLVM MipsGenFastISel.inc -gen-fast-isel) tablegen(LLVM MipsGenGlobalISel.inc -gen-global-isel) -tablegen(LLVM MipsGenPostLegalizeGICombiner.inc -gen-global-isel-combiner - -combiners="MipsPostLegalizerCombinerHelper") +tablegen(LLVM MipsGenPostLegalizeGICombiner.inc -gen-global-isel-combiner-matchtable + -combiners="MipsPostLegalizerCombiner") tablegen(LLVM MipsGenInstrInfo.inc -gen-instr-info) tablegen(LLVM MipsGenMCCodeEmitter.inc -gen-emitter) tablegen(LLVM MipsGenMCPseudoLowering.inc -gen-pseudo-lowering) diff --git a/llvm/lib/Target/Mips/MipsCombine.td b/llvm/lib/Target/Mips/MipsCombine.td index 29550a1..cb15944 100644 --- a/llvm/lib/Target/Mips/MipsCombine.td +++ b/llvm/lib/Target/Mips/MipsCombine.td @@ -8,8 +8,6 @@ include "llvm/Target/GlobalISel/Combine.td" -def MipsPostLegalizerCombinerHelper: GICombinerHelper< - "MipsGenPostLegalizerCombinerHelper", []> { - let DisableRuleOption = "mipspostlegalizercombiner-disable-rule"; +def MipsPostLegalizerCombiner: GICombinerHelper< + "MipsPostLegalizerCombinerImpl", []> { } - diff --git a/llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp b/llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp index c16869a..4247bf9 100644 --- a/llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp +++ b/llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp @@ -18,38 +18,84 @@ #include "llvm/CodeGen/GlobalISel/Combiner.h" #include "llvm/CodeGen/GlobalISel/CombinerHelper.h" #include "llvm/CodeGen/GlobalISel/CombinerInfo.h" +#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h" +#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h" #include "llvm/CodeGen/GlobalISel/GISelKnownBits.h" #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/Target/TargetMachine.h" +#define GET_GICOMBINER_DEPS +#include "MipsGenPostLegalizeGICombiner.inc" +#undef GET_GICOMBINER_DEPS + #define DEBUG_TYPE "mips-postlegalizer-combiner" using namespace llvm; using namespace MIPatternMatch; -#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS +namespace { +#define GET_GICOMBINER_TYPES #include "MipsGenPostLegalizeGICombiner.inc" -#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS +#undef GET_GICOMBINER_TYPES -namespace { -#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H +class MipsPostLegalizerCombinerImpl : public GIMatchTableExecutor { +protected: + CombinerHelper &Helper; + const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig; + + const MipsSubtarget &STI; + GISelChangeObserver &Observer; + MachineIRBuilder &B; + MachineFunction &MF; + + MachineRegisterInfo &MRI; + +public: + MipsPostLegalizerCombinerImpl( + const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig, + const MipsSubtarget &STI, GISelChangeObserver &Observer, + MachineIRBuilder &B, CombinerHelper &Helper); + + static const char *getName() { return "MipsPostLegalizerCombiner"; } + + bool tryCombineAll(MachineInstr &I) const; + +private: +#define GET_GICOMBINER_CLASS_MEMBERS +#include "MipsGenPostLegalizeGICombiner.inc" +#undef GET_GICOMBINER_CLASS_MEMBERS +}; + +#define GET_GICOMBINER_IMPL #include "MipsGenPostLegalizeGICombiner.inc" -#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H +#undef GET_GICOMBINER_IMPL + +MipsPostLegalizerCombinerImpl::MipsPostLegalizerCombinerImpl( + const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig, + const MipsSubtarget &STI, GISelChangeObserver &Observer, + MachineIRBuilder &B, CombinerHelper &Helper) + : Helper(Helper), RuleConfig(RuleConfig), STI(STI), Observer(Observer), + B(B), MF(B.getMF()), MRI(*B.getMRI()), +#define GET_GICOMBINER_CONSTRUCTOR_INITS +#include "MipsGenPostLegalizeGICombiner.inc" +#undef GET_GICOMBINER_CONSTRUCTOR_INITS +{ +} class MipsPostLegalizerCombinerInfo final : public CombinerInfo { GISelKnownBits *KB; public: - MipsGenPostLegalizerCombinerHelperRuleConfig GeneratedRuleCfg; + MipsPostLegalizerCombinerImplRuleConfig RuleConfig; MipsPostLegalizerCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize, GISelKnownBits *KB, const MipsLegalizerInfo *LI) : CombinerInfo(/*AllowIllegalOps*/ false, /*ShouldLegalizeIllegal*/ true, /*LegalizerInfo*/ LI, EnableOpt, OptSize, MinSize), KB(KB) { - if (!GeneratedRuleCfg.parseCommandLineOption()) + if (!RuleConfig.parseCommandLineOption()) report_fatal_error("Invalid rule identifier"); } @@ -60,17 +106,14 @@ public: bool MipsPostLegalizerCombinerInfo::combine(GISelChangeObserver &Observer, MachineInstr &MI, MachineIRBuilder &B) const { - + const auto &STI = MI.getMF()->getSubtarget<MipsSubtarget>(); CombinerHelper Helper(Observer, B, /* IsPreLegalize*/ false, KB, /*DominatorTree*/ nullptr, LInfo); - MipsGenPostLegalizerCombinerHelper Generated(GeneratedRuleCfg, Helper); - return Generated.tryCombineAll(Observer, MI, B, Helper); + MipsPostLegalizerCombinerImpl Impl(RuleConfig, STI, Observer, B, Helper); + Impl.setupMF(*MI.getMF(), KB); + return Impl.tryCombineAll(MI); } -#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP -#include "MipsGenPostLegalizeGICombiner.inc" -#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP - // Pass boilerplate // ================ |