[RISCV] Enable MachineOutliner by default under -Oz for RISCV
Enable default outlining when the function has the minsize attribute. `addr-label.ll` crashed after enabling this, so a barrier is added before instruction selection as a workaround. Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D122213
This commit is contained in:
@@ -47,6 +47,7 @@ add_llvm_target(RISCVCodeGen
|
||||
Analysis
|
||||
AsmPrinter
|
||||
Core
|
||||
IPO
|
||||
CodeGen
|
||||
MC
|
||||
RISCVDesc
|
||||
|
||||
@@ -1196,6 +1196,11 @@ enum MachineOutlinerConstructionID {
|
||||
MachineOutlinerDefault
|
||||
};
|
||||
|
||||
bool RISCVInstrInfo::shouldOutlineFromFunctionByDefault(
|
||||
MachineFunction &MF) const {
|
||||
return MF.getFunction().hasMinSize();
|
||||
}
|
||||
|
||||
outliner::OutlinedFunction RISCVInstrInfo::getOutliningCandidateInfo(
|
||||
std::vector<outliner::Candidate> &RepeatedSequenceLocs) const {
|
||||
|
||||
|
||||
@@ -135,6 +135,8 @@ public:
|
||||
virtual bool isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
|
||||
unsigned &Flags) const override;
|
||||
|
||||
bool shouldOutlineFromFunctionByDefault(MachineFunction &MF) const override;
|
||||
|
||||
// Calculate target-specific information for a set of outlining candidates.
|
||||
outliner::OutlinedFunction getOutliningCandidateInfo(
|
||||
std::vector<outliner::Candidate> &RepeatedSequenceLocs) const override;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "llvm/MC/TargetRegistry.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
using namespace llvm;
|
||||
|
||||
static cl::opt<bool> EnableRedundantCopyElimination(
|
||||
@@ -80,6 +81,7 @@ RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT,
|
||||
|
||||
// RISC-V supports the MachineOutliner.
|
||||
setMachineOutliner(true);
|
||||
setSupportsDefaultOutlining(true);
|
||||
}
|
||||
|
||||
const RISCVSubtarget *
|
||||
@@ -141,6 +143,7 @@ public:
|
||||
}
|
||||
|
||||
void addIRPasses() override;
|
||||
bool addPreISel() override;
|
||||
bool addInstSelector() override;
|
||||
bool addIRTranslator() override;
|
||||
bool addLegalizeMachineIR() override;
|
||||
@@ -167,6 +170,16 @@ void RISCVPassConfig::addIRPasses() {
|
||||
TargetPassConfig::addIRPasses();
|
||||
}
|
||||
|
||||
bool RISCVPassConfig::addPreISel() {
|
||||
if (TM->getOptLevel() != CodeGenOpt::None) {
|
||||
// Add a barrier before instruction selection so that we will not get
|
||||
// deleted block address after enabling default outlining. See D99707 for
|
||||
// more details.
|
||||
addPass(createBarrierNoopPass());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RISCVPassConfig::addInstSelector() {
|
||||
addPass(createRISCVISelDag(getRISCVTargetMachine()));
|
||||
|
||||
|
||||
@@ -60,9 +60,12 @@
|
||||
; CHECK-NEXT: CodeGen Prepare
|
||||
; CHECK-NEXT: Dominator Tree Construction
|
||||
; CHECK-NEXT: Exception handling preparation
|
||||
; CHECK-NEXT: A No-Op Barrier Pass
|
||||
; CHECK-NEXT: FunctionPass Manager
|
||||
; CHECK-NEXT: Safe Stack instrumentation pass
|
||||
; CHECK-NEXT: Insert stack protectors
|
||||
; CHECK-NEXT: Module Verifier
|
||||
; CHECK-NEXT: Dominator Tree Construction
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Natural Loop Information
|
||||
@@ -151,6 +154,8 @@
|
||||
; CHECK-NEXT: Contiguously Lay Out Funclets
|
||||
; CHECK-NEXT: StackMap Liveness Analysis
|
||||
; CHECK-NEXT: Live DEBUG_VALUE analysis
|
||||
; CHECK-NEXT: Machine Outliner
|
||||
; CHECK-NEXT: FunctionPass Manager
|
||||
; CHECK-NEXT: RISCV pseudo instruction expansion pass
|
||||
; CHECK-NEXT: RISCV atomic pseudo instruction expansion pass
|
||||
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
|
||||
|
||||
Reference in New Issue
Block a user