diff options
author | Kai Nacke <kai@redstar.de> | 2022-06-26 22:13:33 -0400 |
---|---|---|
committer | Kai Nacke <kai@redstar.de> | 2022-11-13 11:07:28 -0500 |
commit | 650a9560af49e2f19db08d64cc8b64e1fb0477cb (patch) | |
tree | c8220188ca0d6093920cc852388e81bd0785ca58 | |
parent | f313fed7d9bb5a51567fdb4640977f6b045afe4a (diff) | |
download | llvm-650a9560af49e2f19db08d64cc8b64e1fb0477cb.zip llvm-650a9560af49e2f19db08d64cc8b64e1fb0477cb.tar.gz llvm-650a9560af49e2f19db08d64cc8b64e1fb0477cb.tar.bz2 |
[m88k] Add empty post-legalizer pass.
-rw-r--r-- | llvm/lib/Target/M88k/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Target/M88k/GISel/M88kPostLegalizerCombiner.cpp | 164 | ||||
-rw-r--r-- | llvm/lib/Target/M88k/M88k.h | 2 | ||||
-rw-r--r-- | llvm/lib/Target/M88k/M88kCombine.td | 15 | ||||
-rw-r--r-- | llvm/lib/Target/M88k/M88kTargetMachine.cpp | 3 |
5 files changed, 178 insertions, 7 deletions
diff --git a/llvm/lib/Target/M88k/CMakeLists.txt b/llvm/lib/Target/M88k/CMakeLists.txt index f976ec5..75b0fa1 100644 --- a/llvm/lib/Target/M88k/CMakeLists.txt +++ b/llvm/lib/Target/M88k/CMakeLists.txt @@ -30,6 +30,7 @@ add_llvm_target(M88kCodeGen GISel/M88kInstructionSelector.cpp GISel/M88kLegalizerInfo.cpp GISel/M88kPreLegalizerCombiner.cpp + GISel/M88kPostLegalizerCombiner.cpp GISel/M88kPostLegalizerLowering.cpp GISel/M88kRegisterBankInfo.cpp M88kAsmPrinter.cpp diff --git a/llvm/lib/Target/M88k/GISel/M88kPostLegalizerCombiner.cpp b/llvm/lib/Target/M88k/GISel/M88kPostLegalizerCombiner.cpp new file mode 100644 index 0000000..8f4322f --- /dev/null +++ b/llvm/lib/Target/M88k/GISel/M88kPostLegalizerCombiner.cpp @@ -0,0 +1,164 @@ +//=== M88kPostLegalizer.cpp --------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Post-legalization combines on generic MachineInstrs. +/// +/// The combines here must preserve instruction legality. +/// +/// Lowering combines (e.g. pseudo matching) should be handled by +/// M88kPostLegalizerLowering. +/// +/// Combines which don't rely on instruction legality should go in the +/// M88kPostLegalizerCombiner. +/// +//===----------------------------------------------------------------------===// + +#include "GISel/M88kGlobalISelUtils.h" +#include "M88kTargetMachine.h" +#include "llvm/CodeGen/GlobalISel/CSEInfo.h" +#include "llvm/CodeGen/GlobalISel/Combiner.h" +#include "llvm/CodeGen/GlobalISel/CombinerHelper.h" +#include "llvm/CodeGen/GlobalISel/CombinerInfo.h" +#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h" +#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" +#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" +#include "llvm/CodeGen/MachineDominators.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/TargetPassConfig.h" +#include "llvm/IR/Instructions.h" +#include "llvm/Support/Debug.h" + +#define DEBUG_TYPE "m88k-postlegalizer-combiner" + +using namespace llvm; +using namespace MIPatternMatch; + +#define M88KPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS +#include "M88kGenPostLegalizeGICombiner.inc" +#undef M88KPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS + +namespace { +#define M88KPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H +#include "M88kGenPostLegalizeGICombiner.inc" +#undef M88KPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H + +class M88kPostLegalizerCombinerInfo : public CombinerInfo { + GISelKnownBits *KB; + MachineDominatorTree *MDT; + M88kGenPostLegalizerCombinerHelperRuleConfig GeneratedRuleCfg; + +public: + M88kPostLegalizerCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize, + GISelKnownBits *KB, MachineDominatorTree *MDT) + : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false, + /*LegalizerInfo*/ nullptr, EnableOpt, OptSize, MinSize), + KB(KB), MDT(MDT) { + if (!GeneratedRuleCfg.parseCommandLineOption()) + report_fatal_error("Invalid rule identifier"); + } + + virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI, + MachineIRBuilder &B) const override; +}; + +bool M88kPostLegalizerCombinerInfo::combine(GISelChangeObserver &Observer, + MachineInstr &MI, + MachineIRBuilder &B) const { + const auto *LI = + MI.getParent()->getParent()->getSubtarget().getLegalizerInfo(); + CombinerHelper Helper(Observer, B, KB, MDT, LI); + M88kGenPostLegalizerCombinerHelper Generated(GeneratedRuleCfg); + return Generated.tryCombineAll(Observer, MI, B, Helper); +} + +#define M88KPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP +#include "M88kGenPostLegalizeGICombiner.inc" +#undef M88KPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP + +// Pass boilerplate +// ================ + +class M88kPostLegalizerCombiner : public MachineFunctionPass { + bool IsOptNone; +public: + static char ID; + + M88kPostLegalizerCombiner(bool IsOptNone = false); + + StringRef getPassName() const override { return "M88kPostLegalizerCombiner"; } + + bool runOnMachineFunction(MachineFunction &MF) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override; +}; +} // end anonymous namespace + +void M88kPostLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired<TargetPassConfig>(); + AU.setPreservesCFG(); + getSelectionDAGFallbackAnalysisUsage(AU); + AU.addRequired<GISelKnownBitsAnalysis>(); + AU.addPreserved<GISelKnownBitsAnalysis>(); + if (!IsOptNone) { + AU.addRequired<MachineDominatorTree>(); + AU.addPreserved<MachineDominatorTree>(); + AU.addRequired<GISelCSEAnalysisWrapperPass>(); + AU.addPreserved<GISelCSEAnalysisWrapperPass>(); + } + MachineFunctionPass::getAnalysisUsage(AU); +} + +M88kPostLegalizerCombiner::M88kPostLegalizerCombiner(bool IsOptNone) + : MachineFunctionPass(ID), IsOptNone(IsOptNone) { + initializeM88kPostLegalizerCombinerPass(*PassRegistry::getPassRegistry()); +} + +bool M88kPostLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) { + if (MF.getProperties().hasProperty( + MachineFunctionProperties::Property::FailedISel)) + return false; + assert(MF.getProperties().hasProperty( + MachineFunctionProperties::Property::Legalized) && + "Expected a legalized function?"); + auto *TPC = &getAnalysis<TargetPassConfig>(); + const Function &F = MF.getFunction(); + bool EnableOpt = + MF.getTarget().getOptLevel() != CodeGenOpt::None && !skipFunction(F); + GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF); + MachineDominatorTree *MDT = + IsOptNone ? nullptr : &getAnalysis<MachineDominatorTree>(); + M88kPostLegalizerCombinerInfo PCInfo(EnableOpt, F.hasOptSize(), + F.hasMinSize(), KB, MDT); + GISelCSEInfo *CSEInfo = nullptr; + if (!IsOptNone) { + GISelCSEAnalysisWrapper &Wrapper = + getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper(); + CSEInfo = &Wrapper.get(TPC->getCSEConfig()); + } + Combiner C(PCInfo, TPC); + return C.combineMachineInstrs(MF, CSEInfo); +} + +char M88kPostLegalizerCombiner::ID = 0; +INITIALIZE_PASS_BEGIN(M88kPostLegalizerCombiner, DEBUG_TYPE, + "Combine M88k machine instrs before legalization", false, + false) +INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) +INITIALIZE_PASS_DEPENDENCY(GISelKnownBitsAnalysis) +INITIALIZE_PASS_END(M88kPostLegalizerCombiner, DEBUG_TYPE, + "Combine M88k machine instrs before legalization", false, + false) + +namespace llvm { +FunctionPass *createM88kPostLegalizerCombiner(bool IsOptNone) { + return new M88kPostLegalizerCombiner(IsOptNone); +} +} // end namespace llvm diff --git a/llvm/lib/Target/M88k/M88k.h b/llvm/lib/Target/M88k/M88k.h index f11ad52..5f8194b 100644 --- a/llvm/lib/Target/M88k/M88k.h +++ b/llvm/lib/Target/M88k/M88k.h @@ -33,10 +33,12 @@ InstructionSelector * createM88kInstructionSelector(const M88kTargetMachine &, const M88kSubtarget &, const M88kRegisterBankInfo &); FunctionPass *createM88kPreLegalizerCombiner(); +FunctionPass *createM88kPostLegalizerCombiner(bool IsOptNone); FunctionPass *createM88kPostLegalizerLowering(); FunctionPass *createM88kDelaySlotFiller(); void initializeM88kPreLegalizerCombinerPass(PassRegistry &Registry); +void initializeM88kPostLegalizerCombinerPass(PassRegistry &Registry); void initializeM88kPostLegalizerLoweringPass(PassRegistry &Registry); void initializeM88kDelaySlotFillerPass(PassRegistry &Registry); diff --git a/llvm/lib/Target/M88k/M88kCombine.td b/llvm/lib/Target/M88k/M88kCombine.td index 6d56293..91020f3 100644 --- a/llvm/lib/Target/M88k/M88kCombine.td +++ b/llvm/lib/Target/M88k/M88kCombine.td @@ -48,6 +48,14 @@ def M88kPreLegalizerCombinerHelper: GICombinerHelper< let AdditionalArguments = []; } +// Post-legalization combines which are primarily optimizations. +def M88kPostLegalizerCombinerHelper: GICombinerHelper< + "M88kGenPostLegalizerCombinerHelper", []> { + let DisableRuleOption = "m88kpostlegalizercombiner-disable-rule"; +// let StateClass = "M88kPostLegalizerCombinerHelperState"; +// let AdditionalArguments = []; +} + // Lower // G_SHL $dst, (G_AND $src, (2**width - 1)), offset // to @@ -68,10 +76,3 @@ def M88kPostLegalizerLoweringHelper [shiftand_to_mak]> { let DisableRuleOption = "m88kpostlegalizerlowering-disable-rule"; } - -// Post-legalization combines which are primarily optimizations. -def M88kPostLegalizerCombinerHelper - : GICombinerHelper<"M88kGenPostLegalizerCombinerHelper", - []> { - let DisableRuleOption = "m88kpostlegalizercombiner-disable-rule"; -} diff --git a/llvm/lib/Target/M88k/M88kTargetMachine.cpp b/llvm/lib/Target/M88k/M88kTargetMachine.cpp index a7dddbb..01a237d 100644 --- a/llvm/lib/Target/M88k/M88kTargetMachine.cpp +++ b/llvm/lib/Target/M88k/M88kTargetMachine.cpp @@ -41,6 +41,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM88kTarget() { PassRegistry &PR = *PassRegistry::getPassRegistry(); initializeGlobalISel(PR); initializeM88kPreLegalizerCombinerPass(PR); + initializeM88kPostLegalizerCombinerPass(PR); initializeM88kPostLegalizerLoweringPass(PR); initializeM88kDelaySlotFillerPass(PR); } @@ -191,6 +192,8 @@ bool M88kPassConfig::addLegalizeMachineIR() { } void M88kPassConfig::addPreRegBankSelect() { + bool IsOptNone = getOptLevel() == CodeGenOpt::None; + addPass(createM88kPostLegalizerCombiner(IsOptNone)); addPass(createM88kPostLegalizerLowering()); } |