Skip to content

Commit 2f60813

Browse files
committed
[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
1 parent 655714a commit 2f60813

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

llvm/lib/Target/Mips/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ tablegen(LLVM MipsGenDAGISel.inc -gen-dag-isel)
99
tablegen(LLVM MipsGenDisassemblerTables.inc -gen-disassembler)
1010
tablegen(LLVM MipsGenFastISel.inc -gen-fast-isel)
1111
tablegen(LLVM MipsGenGlobalISel.inc -gen-global-isel)
12-
tablegen(LLVM MipsGenPostLegalizeGICombiner.inc -gen-global-isel-combiner
13-
-combiners="MipsPostLegalizerCombinerHelper")
12+
tablegen(LLVM MipsGenPostLegalizeGICombiner.inc -gen-global-isel-combiner-matchtable
13+
-combiners="MipsPostLegalizerCombiner")
1414
tablegen(LLVM MipsGenInstrInfo.inc -gen-instr-info)
1515
tablegen(LLVM MipsGenMCCodeEmitter.inc -gen-emitter)
1616
tablegen(LLVM MipsGenMCPseudoLowering.inc -gen-pseudo-lowering)

llvm/lib/Target/Mips/MipsCombine.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

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

11-
def MipsPostLegalizerCombinerHelper: GICombinerHelper<
12-
"MipsGenPostLegalizerCombinerHelper", []> {
13-
let DisableRuleOption = "mipspostlegalizercombiner-disable-rule";
11+
def MipsPostLegalizerCombiner: GICombinerHelper<
12+
"MipsPostLegalizerCombinerImpl", []> {
1413
}
15-

llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,84 @@
1818
#include "llvm/CodeGen/GlobalISel/Combiner.h"
1919
#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
2020
#include "llvm/CodeGen/GlobalISel/CombinerInfo.h"
21+
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h"
22+
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
2123
#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h"
2224
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
2325
#include "llvm/CodeGen/MachineDominators.h"
2426
#include "llvm/CodeGen/TargetPassConfig.h"
2527
#include "llvm/Target/TargetMachine.h"
2628

29+
#define GET_GICOMBINER_DEPS
30+
#include "MipsGenPostLegalizeGICombiner.inc"
31+
#undef GET_GICOMBINER_DEPS
32+
2733
#define DEBUG_TYPE "mips-postlegalizer-combiner"
2834

2935
using namespace llvm;
3036
using namespace MIPatternMatch;
3137

32-
#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
38+
namespace {
39+
#define GET_GICOMBINER_TYPES
3340
#include "MipsGenPostLegalizeGICombiner.inc"
34-
#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
41+
#undef GET_GICOMBINER_TYPES
3542

36-
namespace {
37-
#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
43+
class MipsPostLegalizerCombinerImpl : public GIMatchTableExecutor {
44+
protected:
45+
CombinerHelper &Helper;
46+
const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig;
47+
48+
const MipsSubtarget &STI;
49+
GISelChangeObserver &Observer;
50+
MachineIRBuilder &B;
51+
MachineFunction &MF;
52+
53+
MachineRegisterInfo &MRI;
54+
55+
public:
56+
MipsPostLegalizerCombinerImpl(
57+
const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig,
58+
const MipsSubtarget &STI, GISelChangeObserver &Observer,
59+
MachineIRBuilder &B, CombinerHelper &Helper);
60+
61+
static const char *getName() { return "MipsPostLegalizerCombiner"; }
62+
63+
bool tryCombineAll(MachineInstr &I) const;
64+
65+
private:
66+
#define GET_GICOMBINER_CLASS_MEMBERS
67+
#include "MipsGenPostLegalizeGICombiner.inc"
68+
#undef GET_GICOMBINER_CLASS_MEMBERS
69+
};
70+
71+
#define GET_GICOMBINER_IMPL
3872
#include "MipsGenPostLegalizeGICombiner.inc"
39-
#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
73+
#undef GET_GICOMBINER_IMPL
74+
75+
MipsPostLegalizerCombinerImpl::MipsPostLegalizerCombinerImpl(
76+
const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig,
77+
const MipsSubtarget &STI, GISelChangeObserver &Observer,
78+
MachineIRBuilder &B, CombinerHelper &Helper)
79+
: Helper(Helper), RuleConfig(RuleConfig), STI(STI), Observer(Observer),
80+
B(B), MF(B.getMF()), MRI(*B.getMRI()),
81+
#define GET_GICOMBINER_CONSTRUCTOR_INITS
82+
#include "MipsGenPostLegalizeGICombiner.inc"
83+
#undef GET_GICOMBINER_CONSTRUCTOR_INITS
84+
{
85+
}
4086

4187
class MipsPostLegalizerCombinerInfo final : public CombinerInfo {
4288
GISelKnownBits *KB;
4389

4490
public:
45-
MipsGenPostLegalizerCombinerHelperRuleConfig GeneratedRuleCfg;
91+
MipsPostLegalizerCombinerImplRuleConfig RuleConfig;
4692

4793
MipsPostLegalizerCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize,
4894
GISelKnownBits *KB, const MipsLegalizerInfo *LI)
4995
: CombinerInfo(/*AllowIllegalOps*/ false, /*ShouldLegalizeIllegal*/ true,
5096
/*LegalizerInfo*/ LI, EnableOpt, OptSize, MinSize),
5197
KB(KB) {
52-
if (!GeneratedRuleCfg.parseCommandLineOption())
98+
if (!RuleConfig.parseCommandLineOption())
5399
report_fatal_error("Invalid rule identifier");
54100
}
55101

@@ -60,17 +106,14 @@ class MipsPostLegalizerCombinerInfo final : public CombinerInfo {
60106
bool MipsPostLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
61107
MachineInstr &MI,
62108
MachineIRBuilder &B) const {
63-
109+
const auto &STI = MI.getMF()->getSubtarget<MipsSubtarget>();
64110
CombinerHelper Helper(Observer, B, /* IsPreLegalize*/ false, KB,
65111
/*DominatorTree*/ nullptr, LInfo);
66-
MipsGenPostLegalizerCombinerHelper Generated(GeneratedRuleCfg, Helper);
67-
return Generated.tryCombineAll(Observer, MI, B, Helper);
112+
MipsPostLegalizerCombinerImpl Impl(RuleConfig, STI, Observer, B, Helper);
113+
Impl.setupMF(*MI.getMF(), KB);
114+
return Impl.tryCombineAll(MI);
68115
}
69116

70-
#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
71-
#include "MipsGenPostLegalizeGICombiner.inc"
72-
#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
73-
74117
// Pass boilerplate
75118
// ================
76119

0 commit comments

Comments
 (0)