Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/include/llvm/CodeGen/MachineScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachinePassRegistry.h"
#include "llvm/CodeGen/RegisterPressure.h"
#include "llvm/CodeGen/ScheduleDAG.h"
Expand Down Expand Up @@ -147,6 +148,7 @@ struct LLVM_ABI MachineSchedContext {
const TargetMachine *TM = nullptr;
AAResults *AA = nullptr;
LiveIntervals *LIS = nullptr;
MachineBlockFrequencyInfo *MBFI = nullptr;

RegisterClassInfo *RegClassInfo;

Expand Down Expand Up @@ -309,6 +311,7 @@ class LLVM_ABI ScheduleDAGMI : public ScheduleDAGInstrs {
protected:
AAResults *AA;
LiveIntervals *LIS;
MachineBlockFrequencyInfo *MBFI;
std::unique_ptr<MachineSchedStrategy> SchedImpl;

/// Ordered list of DAG postprocessing steps.
Expand All @@ -330,7 +333,7 @@ class LLVM_ABI ScheduleDAGMI : public ScheduleDAGInstrs {
ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
bool RemoveKillFlags)
: ScheduleDAGInstrs(*C->MF, C->MLI, RemoveKillFlags), AA(C->AA),
LIS(C->LIS), SchedImpl(std::move(S)) {}
LIS(C->LIS), MBFI(C->MBFI), SchedImpl(std::move(S)) {}

// Provide a vtable anchor
~ScheduleDAGMI() override;
Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class MachineSchedulerImpl : public MachineSchedulerBase {
MachineDominatorTree &MDT;
AAResults &AA;
LiveIntervals &LIS;
MachineBlockFrequencyInfo &MBFI;
};

MachineSchedulerImpl() = default;
Expand Down Expand Up @@ -415,6 +416,7 @@ INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass);
INITIALIZE_PASS_END(MachineSchedulerLegacy, DEBUG_TYPE,
"Machine Instruction Scheduler", false, false)

Expand All @@ -432,6 +434,8 @@ void MachineSchedulerLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<SlotIndexesWrapperPass>();
AU.addRequired<LiveIntervalsWrapperPass>();
AU.addPreserved<LiveIntervalsWrapperPass>();
AU.addRequired<MachineBlockFrequencyInfoWrapperPass>();
AU.addPreserved<MachineBlockFrequencyInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}

Expand Down Expand Up @@ -555,6 +559,7 @@ bool MachineSchedulerImpl::run(MachineFunction &Func, const TargetMachine &TM,
this->TM = &TM;
AA = &Analyses.AA;
LIS = &Analyses.LIS;
MBFI = &Analyses.MBFI;

if (VerifyScheduling) {
LLVM_DEBUG(LIS->dump());
Expand Down Expand Up @@ -660,8 +665,9 @@ bool MachineSchedulerLegacy::runOnMachineFunction(MachineFunction &MF) {
auto &TM = getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
auto &LIS = getAnalysis<LiveIntervalsWrapperPass>().getLIS();
auto &MBFI = getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
Impl.setLegacyPass(this);
return Impl.run(MF, TM, {MLI, MDT, AA, LIS});
return Impl.run(MF, TM, {MLI, MDT, AA, LIS, MBFI});
}

MachineSchedulerPass::MachineSchedulerPass(const TargetMachine *TM)
Expand Down Expand Up @@ -693,8 +699,9 @@ MachineSchedulerPass::run(MachineFunction &MF,
.getManager();
auto &AA = FAM.getResult<AAManager>(MF.getFunction());
auto &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
auto &MBFI = MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
Impl->setMFAM(&MFAM);
bool Changed = Impl->run(MF, *TM, {MLI, MDT, AA, LIS});
bool Changed = Impl->run(MF, *TM, {MLI, MDT, AA, LIS, MBFI});
if (!Changed)
return PreservedAnalyses::all();

Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/CodeGen/PHIElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/LiveVariables.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
Expand Down Expand Up @@ -181,6 +182,7 @@ PHIEliminationPass::run(MachineFunction &MF,
PA.preserve<MachineDominatorTreeAnalysis>();
PA.preserve<MachinePostDominatorTreeAnalysis>();
PA.preserve<MachineLoopAnalysis>();
PA.preserve<MachineBlockFrequencyAnalysis>();
return PA;
}

Expand Down Expand Up @@ -208,6 +210,7 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<MachineDominatorTreeWrapperPass>();
AU.addPreserved<MachinePostDominatorTreeWrapperPass>();
AU.addPreserved<MachineLoopInfoWrapperPass>();
AU.addPreserved<MachineBlockFrequencyInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}

Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/CodeGen/UnreachableBlockElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ class UnreachableBlockElimLegacyPass : public FunctionPass {

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addPreserved<DominatorTreeWrapperPass>();
AU.addPreserved<MachineBlockFrequencyInfoWrapperPass>();
}
};
}
Expand All @@ -69,6 +71,7 @@ PreservedAnalyses UnreachableBlockElimPass::run(Function &F,
return PreservedAnalyses::all();
PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
PA.preserve<MachineBlockFrequencyAnalysis>();
return PA;
}

Expand Down Expand Up @@ -106,6 +109,7 @@ void UnreachableMachineBlockElimLegacy::getAnalysisUsage(
AnalysisUsage &AU) const {
AU.addPreserved<MachineLoopInfoWrapperPass>();
AU.addPreserved<MachineDominatorTreeWrapperPass>();
AU.addPreserved<MachineBlockFrequencyInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}

Expand All @@ -120,7 +124,8 @@ UnreachableMachineBlockElimPass::run(MachineFunction &MF,

return getMachineFunctionPassPreservedAnalyses()
.preserve<MachineLoopAnalysis>()
.preserve<MachineDominatorTreeAnalysis>();
.preserve<MachineDominatorTreeAnalysis>()
.preserve<MachineBlockFrequencyAnalysis>();
}

bool UnreachableMachineBlockElimLegacy::runOnMachineFunction(
Expand Down
28 changes: 28 additions & 0 deletions llvm/lib/Target/AMDGPU/GCNRegPressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ struct GCNRegPressure {
DynamicVGPRBlockSize));
}

unsigned getVGPRSpills(MachineFunction &MF) {
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
if (!ST.hasGFX90AInsts())
return 0;

std::pair<unsigned, unsigned> MaxVectorRegs =
ST.getMaxNumVectorRegs(MF.getFunction());
unsigned ArchVGPRThreshold = MaxVectorRegs.first;
unsigned AGPRThreshold = MaxVectorRegs.second;

unsigned ArchPressure = getArchVGPRNum();
unsigned AGPRPressure = getAGPRNum();

unsigned ArchSpill = ArchPressure > ArchVGPRThreshold
? (ArchPressure - ArchVGPRThreshold)
: 0;
unsigned AGPRSpill =
AGPRPressure > AGPRThreshold ? (AGPRPressure - AGPRThreshold) : 0;

unsigned CombinedThreshold = ST.getMaxNumVGPRs(MF);
unsigned UnifiedPressure = getVGPRNum(/*UnifiedVGPRFile=*/true);
unsigned UnifiedSpill = UnifiedPressure > CombinedThreshold
? (UnifiedPressure - CombinedThreshold)
: 0;

return std::max(UnifiedSpill, (ArchSpill + AGPRSpill));
}

void inc(unsigned Reg,
LaneBitmask PrevMask,
LaneBitmask NewMask,
Expand Down
Loading