Skip to content

Commit

Permalink
[MIPS] Use GlobalISel MatchTable Combiner Backend
Browse files Browse the repository at this point in the history
Depends on D153757

NOTE: This would land iff D153757 (RFC) lands too.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D153861
  • Loading branch information
Pierre-vh committed Jul 11, 2023
1 parent 655714a commit 2f60813
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Target/Mips/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/Mips/MipsCombine.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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

def MipsPostLegalizerCombinerHelper: GICombinerHelper<
"MipsGenPostLegalizerCombinerHelper", []> {
let DisableRuleOption = "mipspostlegalizercombiner-disable-rule";
def MipsPostLegalizerCombiner: GICombinerHelper<
"MipsPostLegalizerCombinerImpl", []> {
}

71 changes: 57 additions & 14 deletions llvm/lib/Target/Mips/MipsPostLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -60,17 +106,14 @@ class MipsPostLegalizerCombinerInfo final : public CombinerInfo {
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
// ================

Expand Down

0 comments on commit 2f60813

Please sign in to comment.