Skip to content

Commit bae21d5

Browse files
committed
Some heuristics for OOO scheduling
1 parent 5224a6b commit bae21d5

File tree

6 files changed

+434
-57
lines changed

6 files changed

+434
-57
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include <cassert>
9595
#include <llvm/Support/raw_ostream.h>
9696
#include <memory>
97+
#include <set>
9798
#include <string>
9899
#include <vector>
99100

@@ -241,12 +242,6 @@ class MachineSchedStrategy {
241242
/// Tell the strategy that MBB is about to be processed.
242243
virtual void enterMBB(MachineBasicBlock *MBB) {};
243244

244-
virtual bool disableForRegionPreRA(MachineBasicBlock::iterator begin,
245-
MachineBasicBlock::iterator end,
246-
unsigned regioninstrs) const {
247-
return false;
248-
}
249-
250245
/// Tell the strategy that current MBB is done.
251246
virtual void leaveMBB() {};
252247

@@ -496,9 +491,7 @@ class ScheduleDAGMILive : public ScheduleDAGMI {
496491
bool disableForRegion(MachineBasicBlock *bb,
497492
MachineBasicBlock::iterator begin,
498493
MachineBasicBlock::iterator end,
499-
unsigned regioninstrs) const override {
500-
return SchedImpl->disableForRegionPreRA(begin, end, regioninstrs);
501-
}
494+
unsigned regioninstrs) const override;
502495

503496
/// Implement ScheduleDAGInstrs interface for scheduling a sequence of
504497
/// reorderable instructions.
@@ -1084,7 +1077,7 @@ class GenericSchedulerBase : public MachineSchedStrategy {
10841077
enum CandReason : uint8_t {
10851078
NoCand, Only1, PhysReg, RegExcess, RegCritical, Stall, Cluster, Weak,
10861079
RegMax, ResourceReduce, ResourceDemand, BotHeightReduce, BotPathReduce,
1087-
TopDepthReduce, TopPathReduce, NextDefUse, NodeOrder};
1080+
TopDepthReduce, TopPathReduce, NextDefUse, RegPressure, NodeOrder};
10881081

10891082
#ifndef NDEBUG
10901083
static const char *getReasonStr(GenericSchedulerBase::CandReason Reason);
@@ -1221,6 +1214,33 @@ int biasPhysReg(const SUnit *SU, bool isTop);
12211214
/// GenericScheduler shrinks the unscheduled zone using heuristics to balance
12221215
/// the schedule.
12231216
class GenericScheduler : public GenericSchedulerBase {
1217+
//// Experimental members for OOO scheduling. ////
1218+
1219+
// TODO: Integrate with SchedDFSResult class.
1220+
// SU -> Nodes above in subtree.
1221+
std::vector<std::set<const SUnit *> > TreeSUs;
1222+
// SU -> Virtual regs defined above in subtree.
1223+
std::vector<std::set<Register> > TreeDefs;
1224+
// SU -> Regs used but not defined above in subtree.
1225+
std::vector<std::set<Register> > TreeUses;
1226+
1227+
// If this SU is non-null, it is the start of a subtree to be scheduled as
1228+
// a unit.
1229+
mutable SUnit *NextSubtreeSU = nullptr;
1230+
// A (small) set of instructions to be scheduled next as a unit.
1231+
std::set<const SUnit *> NextQueue;
1232+
1233+
unsigned DAGHeight;
1234+
unsigned DAGDepth;
1235+
unsigned NumScheduled;
1236+
std::set<Register> LiveRegs; // Currently live registers.
1237+
1238+
void initLiveRegs(ScheduleDAGMILive *DAG);
1239+
void getMIPDiff(const MachineInstr *MI, PressureDiff &PDiff) const;
1240+
void getTreePDiff(unsigned NodeNum, PressureDiff &PDiff) const;
1241+
int comparePDiffs(PressureDiff &PDiff1, PressureDiff &PDiff2) const;
1242+
//// ////
1243+
12241244
public:
12251245
GenericScheduler(const MachineSchedContext *C):
12261246
GenericSchedulerBase(C), Top(SchedBoundary::TopQID, "TopQ"),
@@ -1232,10 +1252,6 @@ class GenericScheduler : public GenericSchedulerBase {
12321252

12331253
void dumpPolicy() const override;
12341254

1235-
bool disableForRegionPreRA(MachineBasicBlock::iterator Begin,
1236-
MachineBasicBlock::iterator End,
1237-
unsigned NumRegionInstrs) const override;
1238-
12391255
bool shouldTrackPressure() const override {
12401256
return RegionPolicy.ShouldTrackPressure;
12411257
}

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ namespace llvm {
322322
virtual bool disableForRegion(MachineBasicBlock *bb,
323323
MachineBasicBlock::iterator begin,
324324
MachineBasicBlock::iterator end,
325-
unsigned regioninstrs) const { return false; }
325+
unsigned regioninstrs) const {
326+
return false;
327+
}
326328

327329
/// Called when the scheduler has finished scheduling the current region.
328330
virtual void exitRegion();

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/ADT/ArrayRef.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringRef.h"
19-
#include "llvm/CodeGen/MachineBasicBlock.h"
2019
#include "llvm/CodeGen/MacroFusion.h"
2120
#include "llvm/CodeGen/PBQPRAConstraint.h"
2221
#include "llvm/CodeGen/SchedulerRegistry.h"
@@ -230,15 +229,6 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
230229
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
231230
unsigned NumRegionInstrs) const {}
232231

233-
/// Allow the subtarget to leave a region untouched. This has purposefully
234-
/// been left a bit untangled from other methods as this is hopefully
235-
/// just a temporary solution.
236-
virtual bool disableForRegionPreRA(MachineBasicBlock::iterator Begin,
237-
MachineBasicBlock::iterator End,
238-
unsigned NumRegionInstrs) const {
239-
return false;
240-
}
241-
242232
// Perform target-specific adjustments to the latency of a schedule
243233
// dependency.
244234
// If a pair of operands is associated with the schedule dependency, DefOpIdx

0 commit comments

Comments
 (0)