ScheduleDAGInstrs: Remove IsPostRA flag; NFC

ScheduleDAGInstrs doesn't behave differently before or after register
allocation. It was only used in a method of MachineSchedulerBase which
behaved differently in MachineScheduler/PostMachineScheduler. Change
this to let MachineScheduler/PostMachineScheduler just pass in a
parameter to that function.

The order of the LiveIntervals* and bool RemoveKillFlags paramters have
been switched to make out-of-tree code fail instead of unintentionally
passing a value intended for the IsPostRA flag to the (previously
following and default initialized) RemoveKillFlags.

Differential Revision: http://reviews.llvm.org/D14245

llvm-svn: 251883
This commit is contained in:
Matthias Braun 2015-11-03 01:53:29 +00:00
parent c0d8f0ca7d
commit 93563e7032
9 changed files with 35 additions and 53 deletions

View File

@ -106,7 +106,7 @@ protected:
std::map<MachineInstr*, SUnit*> MIToSUnit; std::map<MachineInstr*, SUnit*> MIToSUnit;
public: public:
VLIWPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI, bool IsPostRA); VLIWPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI);
virtual ~VLIWPacketizerList(); virtual ~VLIWPacketizerList();

View File

@ -254,9 +254,8 @@ protected:
#endif #endif
public: public:
ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S, ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
bool IsPostRA) bool RemoveKillFlags)
: ScheduleDAGInstrs(*C->MF, C->MLI, IsPostRA, : ScheduleDAGInstrs(*C->MF, C->MLI, C->LIS, RemoveKillFlags),
/*RemoveKillFlags=*/IsPostRA, C->LIS),
AA(C->AA), SchedImpl(std::move(S)), Topo(SUnits, &ExitSU), CurrentTop(), AA(C->AA), SchedImpl(std::move(S)), Topo(SUnits, &ExitSU), CurrentTop(),
CurrentBottom(), NextClusterPred(nullptr), NextClusterSucc(nullptr) { CurrentBottom(), NextClusterPred(nullptr), NextClusterSucc(nullptr) {
#ifndef NDEBUG #ifndef NDEBUG
@ -386,7 +385,7 @@ protected:
public: public:
ScheduleDAGMILive(MachineSchedContext *C, ScheduleDAGMILive(MachineSchedContext *C,
std::unique_ptr<MachineSchedStrategy> S) std::unique_ptr<MachineSchedStrategy> S)
: ScheduleDAGMI(C, std::move(S), /*IsPostRA=*/false), : ScheduleDAGMI(C, std::move(S), /*RemoveKillFlags=*/false),
RegClassInfo(C->RegClassInfo), DFSResult(nullptr), RegClassInfo(C->RegClassInfo), DFSResult(nullptr),
ShouldTrackPressure(false), RPTracker(RegPressure), ShouldTrackPressure(false), RPTracker(RegPressure),
TopRPTracker(TopPressure), BotRPTracker(BotPressure) {} TopRPTracker(TopPressure), BotRPTracker(BotPressure) {}

View File

@ -226,7 +226,7 @@ public:
/// ///
/// This can also be used to plug a new MachineSchedStrategy into an instance /// This can also be used to plug a new MachineSchedStrategy into an instance
/// of the standard ScheduleDAGMI: /// of the standard ScheduleDAGMI:
/// return new ScheduleDAGMI(C, make_unique<MyStrategy>(C), /* IsPostRA= */false) /// return new ScheduleDAGMI(C, make_unique<MyStrategy>(C), /*RemoveKillFlags=*/false)
/// ///
/// Return NULL to select the default (generic) machine scheduler. /// Return NULL to select the default (generic) machine scheduler.
virtual ScheduleDAGInstrs * virtual ScheduleDAGInstrs *

View File

@ -84,9 +84,6 @@ namespace llvm {
/// TargetSchedModel provides an interface to the machine model. /// TargetSchedModel provides an interface to the machine model.
TargetSchedModel SchedModel; TargetSchedModel SchedModel;
/// isPostRA flag indicates vregs cannot be present.
bool IsPostRA;
/// True if the DAG builder should remove kill flags (in preparation for /// True if the DAG builder should remove kill flags (in preparation for
/// rescheduling). /// rescheduling).
bool RemoveKillFlags; bool RemoveKillFlags;
@ -154,14 +151,11 @@ namespace llvm {
public: public:
explicit ScheduleDAGInstrs(MachineFunction &mf, explicit ScheduleDAGInstrs(MachineFunction &mf,
const MachineLoopInfo *mli, const MachineLoopInfo *mli,
bool IsPostRAFlag, LiveIntervals *LIS = nullptr,
bool RemoveKillFlags = false, bool RemoveKillFlags = false);
LiveIntervals *LIS = nullptr);
~ScheduleDAGInstrs() override {} ~ScheduleDAGInstrs() override {}
bool isPostRA() const { return IsPostRA; }
/// \brief Expose LiveIntervals for use in DAG mutators and such. /// \brief Expose LiveIntervals for use in DAG mutators and such.
LiveIntervals *getLIS() const { return LIS; } LiveIntervals *getLIS() const { return LIS; }

View File

@ -105,16 +105,15 @@ namespace llvm {
// Schedule method to build the dependence graph. // Schedule method to build the dependence graph.
class DefaultVLIWScheduler : public ScheduleDAGInstrs { class DefaultVLIWScheduler : public ScheduleDAGInstrs {
public: public:
DefaultVLIWScheduler(MachineFunction &MF, MachineLoopInfo &MLI, DefaultVLIWScheduler(MachineFunction &MF, MachineLoopInfo &MLI);
bool IsPostRA);
// Schedule - Actual scheduling work. // Schedule - Actual scheduling work.
void schedule() override; void schedule() override;
}; };
} }
DefaultVLIWScheduler::DefaultVLIWScheduler(MachineFunction &MF, DefaultVLIWScheduler::DefaultVLIWScheduler(MachineFunction &MF,
MachineLoopInfo &MLI, bool IsPostRA) MachineLoopInfo &MLI)
: ScheduleDAGInstrs(MF, &MLI, IsPostRA) { : ScheduleDAGInstrs(MF, &MLI) {
CanHandleTerminators = true; CanHandleTerminators = true;
} }
@ -125,11 +124,11 @@ void DefaultVLIWScheduler::schedule() {
// VLIWPacketizerList Ctor // VLIWPacketizerList Ctor
VLIWPacketizerList::VLIWPacketizerList(MachineFunction &MF, VLIWPacketizerList::VLIWPacketizerList(MachineFunction &MF,
MachineLoopInfo &MLI, bool IsPostRA) MachineLoopInfo &MLI)
: MF(MF) { : MF(MF) {
TII = MF.getSubtarget().getInstrInfo(); TII = MF.getSubtarget().getInstrInfo();
ResourceTracker = TII->CreateTargetScheduleState(MF.getSubtarget()); ResourceTracker = TII->CreateTargetScheduleState(MF.getSubtarget());
VLIWScheduler = new DefaultVLIWScheduler(MF, MLI, IsPostRA); VLIWScheduler = new DefaultVLIWScheduler(MF, MLI);
} }
// VLIWPacketizerList Dtor // VLIWPacketizerList Dtor

View File

@ -111,7 +111,7 @@ public:
void print(raw_ostream &O, const Module* = nullptr) const override; void print(raw_ostream &O, const Module* = nullptr) const override;
protected: protected:
void scheduleRegions(ScheduleDAGInstrs &Scheduler); void scheduleRegions(ScheduleDAGInstrs &Scheduler, bool FixKillFlags);
}; };
/// MachineScheduler runs after coalescing and before register allocation. /// MachineScheduler runs after coalescing and before register allocation.
@ -340,7 +340,7 @@ bool MachineScheduler::runOnMachineFunction(MachineFunction &mf) {
// Instantiate the selected scheduler for this target, function, and // Instantiate the selected scheduler for this target, function, and
// optimization level. // optimization level.
std::unique_ptr<ScheduleDAGInstrs> Scheduler(createMachineScheduler()); std::unique_ptr<ScheduleDAGInstrs> Scheduler(createMachineScheduler());
scheduleRegions(*Scheduler); scheduleRegions(*Scheduler, false);
DEBUG(LIS->dump()); DEBUG(LIS->dump());
if (VerifyScheduling) if (VerifyScheduling)
@ -368,7 +368,7 @@ bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) {
// Instantiate the selected scheduler for this target, function, and // Instantiate the selected scheduler for this target, function, and
// optimization level. // optimization level.
std::unique_ptr<ScheduleDAGInstrs> Scheduler(createPostMachineScheduler()); std::unique_ptr<ScheduleDAGInstrs> Scheduler(createPostMachineScheduler());
scheduleRegions(*Scheduler); scheduleRegions(*Scheduler, true);
if (VerifyScheduling) if (VerifyScheduling)
MF->verify(this, "After post machine scheduling."); MF->verify(this, "After post machine scheduling.");
@ -388,15 +388,14 @@ bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) {
static bool isSchedBoundary(MachineBasicBlock::iterator MI, static bool isSchedBoundary(MachineBasicBlock::iterator MI,
MachineBasicBlock *MBB, MachineBasicBlock *MBB,
MachineFunction *MF, MachineFunction *MF,
const TargetInstrInfo *TII, const TargetInstrInfo *TII) {
bool IsPostRA) {
return MI->isCall() || TII->isSchedulingBoundary(MI, MBB, *MF); return MI->isCall() || TII->isSchedulingBoundary(MI, MBB, *MF);
} }
/// Main driver for both MachineScheduler and PostMachineScheduler. /// Main driver for both MachineScheduler and PostMachineScheduler.
void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler) { void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
bool FixKillFlags) {
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
bool IsPostRA = Scheduler.isPostRA();
// Visit all machine basic blocks. // Visit all machine basic blocks.
// //
@ -434,7 +433,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler) {
// Avoid decrementing RegionEnd for blocks with no terminator. // Avoid decrementing RegionEnd for blocks with no terminator.
if (RegionEnd != MBB->end() || if (RegionEnd != MBB->end() ||
isSchedBoundary(&*std::prev(RegionEnd), &*MBB, MF, TII, IsPostRA)) { isSchedBoundary(&*std::prev(RegionEnd), &*MBB, MF, TII)) {
--RegionEnd; --RegionEnd;
// Count the boundary instruction. // Count the boundary instruction.
--RemainingInstrs; --RemainingInstrs;
@ -445,7 +444,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler) {
unsigned NumRegionInstrs = 0; unsigned NumRegionInstrs = 0;
MachineBasicBlock::iterator I = RegionEnd; MachineBasicBlock::iterator I = RegionEnd;
for(;I != MBB->begin(); --I, --RemainingInstrs) { for(;I != MBB->begin(); --I, --RemainingInstrs) {
if (isSchedBoundary(&*std::prev(I), &*MBB, MF, TII, IsPostRA)) if (isSchedBoundary(&*std::prev(I), &*MBB, MF, TII))
break; break;
if (!I->isDebugValue()) if (!I->isDebugValue())
++NumRegionInstrs; ++NumRegionInstrs;
@ -461,8 +460,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler) {
Scheduler.exitRegion(); Scheduler.exitRegion();
continue; continue;
} }
DEBUG(dbgs() << "********** " << ((Scheduler.isPostRA()) ? "PostRA " : "") DEBUG(dbgs() << "********** MI Scheduling **********\n");
<< "MI Scheduling **********\n");
DEBUG(dbgs() << MF->getName() DEBUG(dbgs() << MF->getName()
<< ":BB#" << MBB->getNumber() << " " << MBB->getName() << ":BB#" << MBB->getNumber() << " " << MBB->getName()
<< "\n From: " << *I << " To: "; << "\n From: " << *I << " To: ";
@ -489,11 +487,11 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler) {
} }
assert(RemainingInstrs == 0 && "Instruction count mismatch!"); assert(RemainingInstrs == 0 && "Instruction count mismatch!");
Scheduler.finishBlock(); Scheduler.finishBlock();
if (Scheduler.isPostRA()) { // FIXME: Ideally, no further passes should rely on kill flags. However,
// FIXME: Ideally, no further passes should rely on kill flags. However, // thumb2 size reduction is currently an exception, so the PostMIScheduler
// thumb2 size reduction is currently an exception. // needs to do this.
Scheduler.fixupKills(&*MBB); if (FixKillFlags)
} Scheduler.fixupKills(&*MBB);
} }
Scheduler.finalizeSchedule(); Scheduler.finalizeSchedule();
} }

View File

@ -196,7 +196,7 @@ SchedulePostRATDList::SchedulePostRATDList(
const RegisterClassInfo &RCI, const RegisterClassInfo &RCI,
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode, TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
SmallVectorImpl<const TargetRegisterClass *> &CriticalPathRCs) SmallVectorImpl<const TargetRegisterClass *> &CriticalPathRCs)
: ScheduleDAGInstrs(MF, &MLI, /*IsPostRA=*/true), AA(AA), EndIndex(0) { : ScheduleDAGInstrs(MF, &MLI), AA(AA), EndIndex(0) {
const InstrItineraryData *InstrItins = const InstrItineraryData *InstrItins =
MF.getSubtarget().getInstrItineraryData(); MF.getSubtarget().getInstrItineraryData();

View File

@ -51,15 +51,12 @@ static cl::opt<bool> UseTBAA("use-tbaa-in-sched-mi", cl::Hidden,
ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf, ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf,
const MachineLoopInfo *mli, const MachineLoopInfo *mli,
bool IsPostRAFlag, bool RemoveKillFlags, LiveIntervals *LIS,
LiveIntervals *lis) bool RemoveKillFlags)
: ScheduleDAG(mf), MLI(mli), MFI(mf.getFrameInfo()), LIS(lis), : ScheduleDAG(mf), MLI(mli), MFI(mf.getFrameInfo()), LIS(LIS),
IsPostRA(IsPostRAFlag), RemoveKillFlags(RemoveKillFlags), RemoveKillFlags(RemoveKillFlags), CanHandleTerminators(false),
CanHandleTerminators(false), FirstDbgValue(nullptr) { FirstDbgValue(nullptr) {
assert((IsPostRA || LIS) && "PreRA scheduling requires LiveIntervals");
DbgValues.clear(); DbgValues.clear();
assert(!(IsPostRA && MRI.getNumVirtRegs()) &&
"Virtual registers must be removed prior to PostRA scheduling");
const TargetSubtargetInfo &ST = mf.getSubtarget(); const TargetSubtargetInfo &ST = mf.getSubtarget();
SchedModel.init(ST.getSchedModel(), &ST, TII); SchedModel.init(ST.getSchedModel(), &ST, TII);
@ -230,11 +227,8 @@ void ScheduleDAGInstrs::addSchedBarrierDeps() {
if (TRI->isPhysicalRegister(Reg)) if (TRI->isPhysicalRegister(Reg))
Uses.insert(PhysRegSUOper(&ExitSU, -1, Reg)); Uses.insert(PhysRegSUOper(&ExitSU, -1, Reg));
else { else if (MO.readsReg()) // ignore undef operands
assert(!IsPostRA && "Virtual register encountered after regalloc."); addVRegUseDeps(&ExitSU, i);
if (MO.readsReg()) // ignore undef operands
addVRegUseDeps(&ExitSU, i);
}
} }
} else { } else {
// For others, e.g. fallthrough, conditional branch, assume the exit // For others, e.g. fallthrough, conditional branch, assume the exit
@ -831,7 +825,6 @@ void ScheduleDAGInstrs::buildSchedGraph(AliasAnalysis *AA,
if (TRI->isPhysicalRegister(Reg)) if (TRI->isPhysicalRegister(Reg))
addPhysRegDeps(SU, j); addPhysRegDeps(SU, j);
else { else {
assert(!IsPostRA && "Virtual register encountered!");
if (MO.isDef()) { if (MO.isDef()) {
HasVRegDef = true; HasVRegDef = true;
addVRegDefDeps(SU, j); addVRegDefDeps(SU, j);

View File

@ -149,8 +149,7 @@ private:
public: public:
// Ctor. // Ctor.
R600PacketizerList(MachineFunction &MF, MachineLoopInfo &MLI) R600PacketizerList(MachineFunction &MF, MachineLoopInfo &MLI)
: VLIWPacketizerList(MF, MLI, true), : VLIWPacketizerList(MF, MLI), TII(static_cast<const R600InstrInfo *>(
TII(static_cast<const R600InstrInfo *>(
MF.getSubtarget().getInstrInfo())), MF.getSubtarget().getInstrInfo())),
TRI(TII->getRegisterInfo()) { TRI(TII->getRegisterInfo()) {
VLIW5 = !MF.getSubtarget<AMDGPUSubtarget>().hasCaymanISA(); VLIW5 = !MF.getSubtarget<AMDGPUSubtarget>().hasCaymanISA();