[llvm] 9c5ad62 - Revert "[RISCV][GISEL] Introduce the RISCVPostLegalizerLowering pass (#108991)"
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 07:09:11 PDT 2024
Author: Michael Maitland
Date: 2024-09-20T07:01:17-07:00
New Revision: 9c5ad62e7440423fbcd2d84c8f0347a5f000400e
URL: https://github.com/llvm/llvm-project/commit/9c5ad62e7440423fbcd2d84c8f0347a5f000400e
DIFF: https://github.com/llvm/llvm-project/commit/9c5ad62e7440423fbcd2d84c8f0347a5f000400e.diff
LOG: Revert "[RISCV][GISEL] Introduce the RISCVPostLegalizerLowering pass (#108991)"
This reverts commit 64972834c193632cbc47e54c0f0c721636b077e6.
Based on the discussions in #108991 that happened post merge, we have decided
to remove this pass in favor of generating `RISCV::G_*` opcodes in the legalizer.
We may reconsider moving that code elsewhere in the future so that we can do
a better job during generic combines. We don't feel that doing it in instruciton
selection is the right decision today. Firstly, it requires us to manually
do regbankselect on the newly introduced instructions. Secondly, it is more
difficult to test since the test output will contain whatever `RISCV::G_*`
instructions select to (instead of `RISCV::G_*`).
My personal opinion is that the legalizer pass can be split into an early
legalizer and a late legalizer, both before regbankselect. The first legalizer
would not introduce target specific generic opcodes and the generic combiner
would run after it. The second legalizer would introduce the target specific
generic opcodes. I think this approach is better than the lowerer because the
legalizer guarantees that whatever we lower to is legal, and apparently because
it is more performant at compared to the lowerer (although, I'm not sure how
true this is).
Added:
Modified:
llvm/lib/Target/RISCV/CMakeLists.txt
llvm/lib/Target/RISCV/RISCV.h
llvm/lib/Target/RISCV/RISCVCombine.td
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
llvm/test/CodeGen/RISCV/GlobalISel/gisel-commandline-option.ll
Removed:
llvm/lib/Target/RISCV/GISel/RISCVPostLegalizerLowering.cpp
################################################################################
diff --git a/llvm/lib/Target/RISCV/CMakeLists.txt b/llvm/lib/Target/RISCV/CMakeLists.txt
index fb5edfa4765fb5..574f1756cc733d 100644
--- a/llvm/lib/Target/RISCV/CMakeLists.txt
+++ b/llvm/lib/Target/RISCV/CMakeLists.txt
@@ -24,8 +24,6 @@ tablegen(LLVM RISCVGenPreLegalizeGICombiner.inc -gen-global-isel-combiner
-combiners="RISCVPreLegalizerCombiner")
tablegen(LLVM RISCVGenPostLegalizeGICombiner.inc -gen-global-isel-combiner
-combiners="RISCVPostLegalizerCombiner")
-tablegen(LLVM RISCVGenPostLegalizeGILowering.inc -gen-global-isel-combiner
- -combiners="RISCVPostLegalizerLowering")
add_public_tablegen_target(RISCVCommonTableGen)
@@ -66,7 +64,6 @@ add_llvm_target(RISCVCodeGen
GISel/RISCVInstructionSelector.cpp
GISel/RISCVLegalizerInfo.cpp
GISel/RISCVPostLegalizerCombiner.cpp
- GISel/RISCVPostLegalizerLowering.cpp
GISel/RISCVO0PreLegalizerCombiner.cpp
GISel/RISCVPreLegalizerCombiner.cpp
GISel/RISCVRegisterBankInfo.cpp
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVPostLegalizerLowering.cpp b/llvm/lib/Target/RISCV/GISel/RISCVPostLegalizerLowering.cpp
deleted file mode 100644
index 66db15e3a2e28c..00000000000000
--- a/llvm/lib/Target/RISCV/GISel/RISCVPostLegalizerLowering.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-//===--------------- RISCVPostLegalizerLowering.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 lowering for instructions.
-///
-/// This is used to offload pattern matching from the selector.
-///
-/// General optimization combines should be handled by either the
-/// RISCVPostLegalizerCombiner or the RISCVPreLegalizerCombiner.
-///
-//===----------------------------------------------------------------------===//
-
-#include "RISCVSubtarget.h"
-
-#include "llvm/CodeGen/GlobalISel/Combiner.h"
-#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
-#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
-#include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/TargetPassConfig.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/Support/Debug.h"
-
-#define GET_GICOMBINER_DEPS
-#include "RISCVGenPostLegalizeGILowering.inc"
-#undef GET_GICOMBINER_DEPS
-
-#define DEBUG_TYPE "riscv-postlegalizer-lowering"
-
-using namespace llvm;
-
-namespace {
-
-#define GET_GICOMBINER_TYPES
-#include "RISCVGenPostLegalizeGILowering.inc"
-#undef GET_GICOMBINER_TYPES
-
-class RISCVPostLegalizerLoweringImpl : public Combiner {
-protected:
- // TODO: Make CombinerHelper methods const.
- mutable CombinerHelper Helper;
- const RISCVPostLegalizerLoweringImplRuleConfig &RuleConfig;
- const RISCVSubtarget &STI;
-
-public:
- RISCVPostLegalizerLoweringImpl(
- MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
- GISelCSEInfo *CSEInfo,
- const RISCVPostLegalizerLoweringImplRuleConfig &RuleConfig,
- const RISCVSubtarget &STI);
-
- static const char *getName() { return "RISCVPreLegalizerCombiner"; }
-
- bool tryCombineAll(MachineInstr &I) const override;
-
-private:
-#define GET_GICOMBINER_CLASS_MEMBERS
-#include "RISCVGenPostLegalizeGILowering.inc"
-#undef GET_GICOMBINER_CLASS_MEMBERS
-};
-
-#define GET_GICOMBINER_IMPL
-#include "RISCVGenPostLegalizeGILowering.inc"
-#undef GET_GICOMBINER_IMPL
-
-RISCVPostLegalizerLoweringImpl::RISCVPostLegalizerLoweringImpl(
- MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
- GISelCSEInfo *CSEInfo,
- const RISCVPostLegalizerLoweringImplRuleConfig &RuleConfig,
- const RISCVSubtarget &STI)
- : Combiner(MF, CInfo, TPC, /*KB*/ nullptr, CSEInfo),
- Helper(Observer, B, /*IsPreLegalize*/ true), RuleConfig(RuleConfig),
- STI(STI),
-#define GET_GICOMBINER_CONSTRUCTOR_INITS
-#include "RISCVGenPostLegalizeGILowering.inc"
-#undef GET_GICOMBINER_CONSTRUCTOR_INITS
-{
-}
-
-class RISCVPostLegalizerLowering : public MachineFunctionPass {
-public:
- static char ID;
-
- RISCVPostLegalizerLowering();
-
- StringRef getPassName() const override {
- return "RISCVPostLegalizerLowering";
- }
-
- bool runOnMachineFunction(MachineFunction &MF) override;
- void getAnalysisUsage(AnalysisUsage &AU) const override;
-
-private:
- RISCVPostLegalizerLoweringImplRuleConfig RuleConfig;
-};
-} // end anonymous namespace
-
-void RISCVPostLegalizerLowering::getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequired<TargetPassConfig>();
- AU.setPreservesCFG();
- getSelectionDAGFallbackAnalysisUsage(AU);
- MachineFunctionPass::getAnalysisUsage(AU);
-}
-
-RISCVPostLegalizerLowering::RISCVPostLegalizerLowering()
- : MachineFunctionPass(ID) {
- if (!RuleConfig.parseCommandLineOption())
- report_fatal_error("Invalid rule identifier");
-}
-
-bool RISCVPostLegalizerLowering::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();
-
- const RISCVSubtarget &ST = MF.getSubtarget<RISCVSubtarget>();
- CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
- /*LegalizerInfo*/ nullptr, /*OptEnabled=*/true,
- F.hasOptSize(), F.hasMinSize());
- // Disable fixed-point iteration to reduce compile-time
- CInfo.MaxIterations = 1;
- CInfo.ObserverLvl = CombinerInfo::ObserverLevel::SinglePass;
- // PostLegalizerCombiner performs DCE, so a full DCE pass is unnecessary.
- CInfo.EnableFullDCE = false;
- RISCVPostLegalizerLoweringImpl Impl(MF, CInfo, TPC, /*CSEInfo*/ nullptr,
- RuleConfig, ST);
- return Impl.combineMachineInstrs();
-}
-
-char RISCVPostLegalizerLowering::ID = 0;
-INITIALIZE_PASS_BEGIN(RISCVPostLegalizerLowering, DEBUG_TYPE,
- "Lower RISC-V MachineInstrs after legalization", false,
- false)
-INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
-INITIALIZE_PASS_END(RISCVPostLegalizerLowering, DEBUG_TYPE,
- "Lower RISC-V MachineInstrs after legalization", false,
- false)
-
-namespace llvm {
-FunctionPass *createRISCVPostLegalizerLowering() {
- return new RISCVPostLegalizerLowering();
-}
-} // end namespace llvm
diff --git a/llvm/lib/Target/RISCV/RISCV.h b/llvm/lib/Target/RISCV/RISCV.h
index f2fb32a8b63bce..482c0cce78b10f 100644
--- a/llvm/lib/Target/RISCV/RISCV.h
+++ b/llvm/lib/Target/RISCV/RISCV.h
@@ -102,9 +102,6 @@ void initializeRISCVO0PreLegalizerCombinerPass(PassRegistry &);
FunctionPass *createRISCVPreLegalizerCombiner();
void initializeRISCVPreLegalizerCombinerPass(PassRegistry &);
-
-FunctionPass *createRISCVPostLegalizerLowering();
-void initializeRISCVPostLegalizerLoweringPass(PassRegistry &);
} // namespace llvm
#endif
diff --git a/llvm/lib/Target/RISCV/RISCVCombine.td b/llvm/lib/Target/RISCV/RISCVCombine.td
index d48698ae6f2bfb..3a5afb1b075c9e 100644
--- a/llvm/lib/Target/RISCV/RISCVCombine.td
+++ b/llvm/lib/Target/RISCV/RISCVCombine.td
@@ -19,13 +19,6 @@ def RISCVO0PreLegalizerCombiner: GICombiner<
"RISCVO0PreLegalizerCombinerImpl", [optnone_combines]> {
}
-// Post-legalization combines which should happen at all optimization levels.
-// (E.g. ones that facilitate matching for the selector) For example, matching
-// pseudos.
-def RISCVPostLegalizerLowering
- : GICombiner<"RISCVPostLegalizerLoweringImpl", []> {
-}
-
// Post-legalization combines which are primarily optimizations.
// TODO: Add more combines.
def RISCVPostLegalizerCombiner
diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 912887ba191609..6a72857b93b6c7 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -111,7 +111,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
initializeRISCVO0PreLegalizerCombinerPass(*PR);
initializeRISCVPreLegalizerCombinerPass(*PR);
initializeRISCVPostLegalizerCombinerPass(*PR);
- initializeRISCVPostLegalizerLoweringPass(*PR);
initializeKCFIPass(*PR);
initializeRISCVDeadRegisterDefinitionsPass(*PR);
initializeRISCVMakeCompressibleOptPass(*PR);
@@ -484,7 +483,6 @@ bool RISCVPassConfig::addLegalizeMachineIR() {
void RISCVPassConfig::addPreRegBankSelect() {
if (getOptLevel() != CodeGenOptLevel::None)
addPass(createRISCVPostLegalizerCombiner());
- addPass(createRISCVPostLegalizerLowering());
}
bool RISCVPassConfig::addRegBankSelect() {
diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/gisel-commandline-option.ll b/llvm/test/CodeGen/RISCV/GlobalISel/gisel-commandline-option.ll
index 75607bb81ff513..82c66c23b26ba9 100644
--- a/llvm/test/CodeGen/RISCV/GlobalISel/gisel-commandline-option.ll
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/gisel-commandline-option.ll
@@ -23,7 +23,6 @@
; ENABLED-NEXT: Legalizer
; ENABLED-O1-NEXT: MachineDominator Tree Construction
; ENABLED-O1-NEXT: RISCVPostLegalizerCombiner
-; ENABLED-NEXT: RISCVPostLegalizerLowering
; ENABLED-NEXT: RegBankSelect
; ENABLED-NEXT: Analysis for ComputingKnownBits
; ENABLED-O1-NEXT: Lazy Branch Probability Analysis
More information about the llvm-commits
mailing list