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
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/MachinePipeliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MachinePipeliner : public MachineFunctionPass {
const MachineDominatorTree *MDT = nullptr;
const InstrItineraryData *InstrItins = nullptr;
const TargetInstrInfo *TII = nullptr;
RegisterClassInfo RegClassInfo;
RegisterClassInfo *RegClassInfo = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RegisterClassInfo *RegClassInfo = nullptr;
const RegisterClassInfo *RegClassInfo = nullptr;

bool disabledByPragma = false;
unsigned II_setByPragma = 0;

Expand Down
6 changes: 0 additions & 6 deletions llvm/include/llvm/CodeGen/MachineScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ struct LLVM_ABI MachineSchedContext {
const TargetMachine *TM = nullptr;
AAResults *AA = nullptr;
LiveIntervals *LIS = nullptr;

RegisterClassInfo *RegClassInfo;

MachineSchedContext();
MachineSchedContext &operator=(const MachineSchedContext &other) = delete;
MachineSchedContext(const MachineSchedContext &other) = delete;
virtual ~MachineSchedContext();
};

/// MachineSchedRegistry provides a selection of available machine instruction
Expand Down
45 changes: 45 additions & 0 deletions llvm/include/llvm/CodeGen/RegisterClassInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/MC/MCRegister.h"
#include "llvm/Support/Compiler.h"
Expand All @@ -27,6 +29,8 @@

namespace llvm {

class MachineRegisterClassAnalysis;

class RegisterClassInfo {
struct RCInfo {
unsigned Tag = 0;
Expand Down Expand Up @@ -94,6 +98,14 @@ class RegisterClassInfo {
LLVM_ABI void runOnMachineFunction(const MachineFunction &MF,
bool Rev = false);

bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
MachineFunctionAnalysisManager::Invalidator &) {
// Check whether the analysis has been explicitly invalidated. Otherwise,
// it's stateless and remains preserved.
auto PAC = PA.getChecker<MachineRegisterClassAnalysis>();
return !PAC.preservedWhenStateless();
}

/// getNumAllocatableRegs - Returns the number of actually allocatable
/// registers in RC in the current function.
unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const {
Expand Down Expand Up @@ -158,6 +170,39 @@ class RegisterClassInfo {
LLVM_ABI unsigned computePSetLimit(unsigned Idx) const;
};

class MachineRegisterClassAnalysis
: public AnalysisInfoMixin<MachineRegisterClassAnalysis> {
friend AnalysisInfoMixin<MachineRegisterClassAnalysis>;

static AnalysisKey Key;

public:
using Result = RegisterClassInfo;

Result run(MachineFunction &, MachineFunctionAnalysisManager &);
};

class MachineRegisterClassInfoWrapperPass : public MachineFunctionPass {
virtual void anchor();

RegisterClassInfo RCI;

public:
static char ID;

MachineRegisterClassInfoWrapperPass();

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}

bool runOnMachineFunction(MachineFunction &MF) override;

RegisterClassInfo &getRCI() { return RCI; }
const RegisterClassInfo &getRCI() const { return RCI; }
};

} // end namespace llvm

#endif // LLVM_CODEGEN_REGISTERCLASSINFO_H
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ LLVM_ABI void initializeStaticDataAnnotatorPass(PassRegistry &);
LLVM_ABI void initializeMachinePipelinerPass(PassRegistry &);
LLVM_ABI void initializeMachinePostDominatorTreeWrapperPassPass(PassRegistry &);
LLVM_ABI void initializeMachineRegionInfoPassPass(PassRegistry &);
LLVM_ABI void initializeMachineRegisterClassInfoWrapperPassPass(PassRegistry &);
LLVM_ABI void
initializeMachineSanitizerBinaryMetadataLegacyPass(PassRegistry &);
LLVM_ABI void initializeMIR2VecVocabLegacyAnalysisPass(PassRegistry &);
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Passes/MachinePassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ MACHINE_FUNCTION_ANALYSIS("machine-opt-remark-emitter",
MachineOptimizationRemarkEmitterAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
MachinePostDominatorTreeAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-reg-class-info",
MachineRegisterClassAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-trace-metrics", MachineTraceMetricsAnalysis())
MACHINE_FUNCTION_ANALYSIS("machine-uniformity", MachineUniformityAnalysis())
MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/CodeGen/BreakFalseDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BreakFalseDeps : public MachineFunctionPass {
MachineFunction *MF = nullptr;
const TargetInstrInfo *TII = nullptr;
const TargetRegisterInfo *TRI = nullptr;
RegisterClassInfo RegClassInfo;
RegisterClassInfo *RegClassInfo = nullptr;

/// List of undefined register reads in this block in forward order.
std::vector<std::pair<MachineInstr *, unsigned>> UndefReads;
Expand All @@ -57,6 +57,7 @@ class BreakFalseDeps : public MachineFunctionPass {

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
AU.addRequired<MachineRegisterClassInfoWrapperPass>();
AU.addRequired<ReachingDefInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}
Expand Down Expand Up @@ -101,6 +102,7 @@ class BreakFalseDeps : public MachineFunctionPass {

char BreakFalseDeps::ID = 0;
INITIALIZE_PASS_BEGIN(BreakFalseDeps, DEBUG_TYPE, "BreakFalseDeps", false, false)
INITIALIZE_PASS_DEPENDENCY(MachineRegisterClassInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(ReachingDefInfoWrapperPass)
INITIALIZE_PASS_END(BreakFalseDeps, DEBUG_TYPE, "BreakFalseDeps", false, false)

Expand Down Expand Up @@ -151,7 +153,7 @@ bool BreakFalseDeps::pickBestRegisterForUndef(MachineInstr *MI, unsigned OpIdx,
// max clearance or clearance higher than Pref.
unsigned MaxClearance = 0;
unsigned MaxClearanceReg = OriginalReg;
ArrayRef<MCPhysReg> Order = RegClassInfo.getOrder(OpRC);
ArrayRef<MCPhysReg> Order = RegClassInfo->getOrder(OpRC);
for (MCPhysReg Reg : Order) {
unsigned Clearance = RDI->getClearance(MI, Reg);
if (Clearance <= MaxClearance)
Expand Down Expand Up @@ -282,10 +284,9 @@ bool BreakFalseDeps::runOnMachineFunction(MachineFunction &mf) {
MF = &mf;
TII = MF->getSubtarget().getInstrInfo();
TRI = MF->getSubtarget().getRegisterInfo();
RegClassInfo = &getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI();
RDI = &getAnalysis<ReachingDefInfoWrapperPass>().getRDI();

RegClassInfo.runOnMachineFunction(mf, /*Rev=*/true);

LLVM_DEBUG(dbgs() << "********** BREAK FALSE DEPENDENCIES **********\n");

// Skip Dead blocks due to ReachingDefAnalysis has no idea about instructions
Expand Down
9 changes: 6 additions & 3 deletions llvm/lib/CodeGen/MachineCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MachineCombiner : public MachineFunctionPass {
MachineTraceMetrics::Ensemble *TraceEnsemble = nullptr;
MachineBlockFrequencyInfo *MBFI = nullptr;
ProfileSummaryInfo *PSI = nullptr;
RegisterClassInfo RegClassInfo;
RegisterClassInfo *RegClassInfo = nullptr;

TargetSchedModel TSchedModel;

Expand Down Expand Up @@ -130,6 +130,7 @@ char &llvm::MachineCombinerID = MachineCombiner::ID;
INITIALIZE_PASS_BEGIN(MachineCombiner, DEBUG_TYPE,
"Machine InstCombiner", false, false)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineRegisterClassInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineTraceMetricsWrapperPass)
INITIALIZE_PASS_END(MachineCombiner, DEBUG_TYPE, "Machine InstCombiner",
false, false)
Expand All @@ -139,6 +140,8 @@ void MachineCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<MachineDominatorTreeWrapperPass>();
AU.addRequired<MachineLoopInfoWrapperPass>();
AU.addPreserved<MachineLoopInfoWrapperPass>();
AU.addRequired<MachineRegisterClassInfoWrapperPass>();
AU.addPreserved<MachineRegisterClassInfoWrapperPass>();
AU.addRequired<MachineTraceMetricsWrapperPass>();
AU.addPreserved<MachineTraceMetricsWrapperPass>();
AU.addRequired<LazyMachineBlockFrequencyInfoPass>();
Expand Down Expand Up @@ -570,7 +573,7 @@ bool MachineCombiner::combineInstructions(MachineBasicBlock *MBB) {
bool OptForSize = llvm::shouldOptimizeForSize(MBB, PSI, MBFI);

bool DoRegPressureReduce =
TII->shouldReduceRegisterPressure(MBB, &RegClassInfo);
TII->shouldReduceRegisterPressure(MBB, RegClassInfo);

while (BlockIter != MBB->end()) {
auto &MI = *BlockIter++;
Expand Down Expand Up @@ -729,7 +732,7 @@ bool MachineCombiner::runOnMachineFunction(MachineFunction &MF) {
&getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI() :
nullptr;
TraceEnsemble = nullptr;
RegClassInfo.runOnMachineFunction(MF);
RegClassInfo = &getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI();

LLVM_DEBUG(dbgs() << getPassName() << ": " << MF.getName() << '\n');
if (!TII->useMachineCombiner()) {
Expand Down
10 changes: 7 additions & 3 deletions llvm/lib/CodeGen/MachinePipeliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineRegisterClassInfoWrapperPass)
INITIALIZE_PASS_END(MachinePipeliner, DEBUG_TYPE,
"Modulo Software Pipelining", false, false)

Expand Down Expand Up @@ -385,8 +386,8 @@ bool MachinePipeliner::runOnMachineFunction(MachineFunction &mf) {
MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
RegClassInfo = &getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI();
TII = MF->getSubtarget().getInstrInfo();
RegClassInfo.runOnMachineFunction(*MF);

for (const auto &L : *MLI)
scheduleLoop(*L);
Expand Down Expand Up @@ -671,7 +672,7 @@ bool MachinePipeliner::swingModuloScheduler(MachineLoop &L) {

AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
SwingSchedulerDAG SMS(
*this, L, getAnalysis<LiveIntervalsWrapperPass>().getLIS(), RegClassInfo,
*this, L, getAnalysis<LiveIntervalsWrapperPass>().getLIS(), *RegClassInfo,
II_setByPragma, LI.LoopPipelinerInfo.get(), AA);

MachineBasicBlock *MBB = L.getHeader();
Expand Down Expand Up @@ -702,6 +703,8 @@ void MachinePipeliner::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineDominatorTreeWrapperPass>();
AU.addRequired<LiveIntervalsWrapperPass>();
AU.addRequired<MachineOptimizationRemarkEmitterPass>();
AU.addRequired<MachineRegisterClassInfoWrapperPass>();
AU.addPreserved<MachineRegisterClassInfoWrapperPass>();
AU.addRequired<TargetPassConfig>();
MachineFunctionPass::getAnalysisUsage(AU);
}
Expand All @@ -714,7 +717,8 @@ bool MachinePipeliner::runWindowScheduler(MachineLoop &L) {
Context.TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
Context.AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
Context.LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
Context.RegClassInfo->runOnMachineFunction(*MF);
Context.RegClassInfo =
&getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI();
WindowScheduler WS(&Context, L);
return WS.run();
}
Expand Down
22 changes: 11 additions & 11 deletions llvm/lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,6 @@ void ScheduleDAGMutation::anchor() {}
// Machine Instruction Scheduling Pass and Registry
//===----------------------------------------------------------------------===//

MachineSchedContext::MachineSchedContext() {
RegClassInfo = new RegisterClassInfo();
}

MachineSchedContext::~MachineSchedContext() {
delete RegClassInfo;
}

namespace llvm {
namespace impl_detail {

Expand All @@ -332,6 +324,7 @@ class MachineSchedulerImpl : public MachineSchedulerBase {
MachineDominatorTree &MDT;
AAResults &AA;
LiveIntervals &LIS;
RegisterClassInfo &RegClassInfo;
};

MachineSchedulerImpl() = default;
Expand Down Expand Up @@ -432,6 +425,8 @@ void MachineSchedulerLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<SlotIndexesWrapperPass>();
AU.addRequired<LiveIntervalsWrapperPass>();
AU.addPreserved<LiveIntervalsWrapperPass>();
AU.addRequired<MachineRegisterClassInfoWrapperPass>();
AU.addPreserved<MachineRegisterClassInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}

Expand All @@ -444,6 +439,7 @@ INITIALIZE_PASS_BEGIN(PostMachineSchedulerLegacy, "postmisched",
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineRegisterClassInfoWrapperPass)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort this alphabetically with the other pass dependencies

INITIALIZE_PASS_END(PostMachineSchedulerLegacy, "postmisched",
"PostRA Machine Instruction Scheduler", false, false)

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

if (VerifyScheduling) {
LLVM_DEBUG(LIS->dump());
Expand All @@ -564,7 +561,6 @@ bool MachineSchedulerImpl::run(MachineFunction &Func, const TargetMachine &TM,
else
MF->verify(*MFAM, MSchedBanner, &errs());
}
RegClassInfo->runOnMachineFunction(*MF);

// Instantiate the selected scheduler for this target, function, and
// optimization level.
Expand Down Expand Up @@ -660,8 +656,11 @@ bool MachineSchedulerLegacy::runOnMachineFunction(MachineFunction &MF) {
auto &TM = getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
auto &LIS = getAnalysis<LiveIntervalsWrapperPass>().getLIS();
auto &RegClassInfo =
getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI();

Impl.setLegacyPass(this);
return Impl.run(MF, TM, {MLI, MDT, AA, LIS});
return Impl.run(MF, TM, {MLI, MDT, AA, LIS, RegClassInfo});
}

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

Expand Down
Loading
Loading