26 #define DEBUG_TYPE "machine-scheduler" 36 CurInstKind = IDOther;
38 OccupedSlotsMask = 31;
39 InstKindLimit[IDAlu] = TII->getMaxAlusPerClause();
40 InstKindLimit[IDOther] = 32;
46 void R600SchedStrategy::MoveUnits(std::vector<SUnit *> &QSrc,
47 std::vector<SUnit *> &QDst)
49 QDst.insert(QDst.end(), QSrc.begin(), QSrc.end());
54 assert (GPRCount &&
"GPRCount cannot be 0");
55 return 248 / GPRCount;
60 NextInstKind = IDOther;
65 bool AllowSwitchToAlu = (CurEmitted >= InstKindLimit[CurInstKind]) ||
66 (Available[CurInstKind].empty());
67 bool AllowSwitchFromAlu = (CurEmitted >= InstKindLimit[CurInstKind]) &&
68 (!Available[IDFetch].empty() || !Available[IDOther].empty());
70 if (CurInstKind == IDAlu && !Available[IDFetch].empty()) {
75 float ALUFetchRationEstimate =
76 (AluInstCount + AvailablesAluCount() + Pending[IDAlu].size()) /
77 (FetchInstCount + Available[IDFetch].
size());
78 if (ALUFetchRationEstimate == 0) {
79 AllowSwitchFromAlu =
true;
81 unsigned NeededWF = 62.5f / ALUFetchRationEstimate;
82 LLVM_DEBUG(
dbgs() << NeededWF <<
" approx. Wavefronts Required\n");
93 unsigned NearRegisterRequirement = 2 * Available[IDFetch].size();
95 AllowSwitchFromAlu =
true;
99 if (!SU && ((AllowSwitchToAlu && CurInstKind != IDAlu) ||
100 (!AllowSwitchFromAlu && CurInstKind == IDAlu))) {
103 if (!SU && !PhysicalRegCopy.empty()) {
104 SU = PhysicalRegCopy.front();
105 PhysicalRegCopy.erase(PhysicalRegCopy.begin());
108 if (CurEmitted >= InstKindLimit[IDAlu])
110 NextInstKind = IDAlu;
116 SU = pickOther(IDFetch);
118 NextInstKind = IDFetch;
123 SU = pickOther(IDOther);
125 NextInstKind = IDOther;
129 dbgs() <<
" ** Pick node **\n";
132 dbgs() <<
"NO NODE \n";
133 for (
unsigned i = 0; i < DAG->
SUnits.size(); i++) {
144 if (NextInstKind != CurInstKind) {
146 if (NextInstKind != IDAlu)
147 OccupedSlotsMask |= 31;
149 CurInstKind = NextInstKind;
152 if (CurInstKind == IDAlu) {
154 switch (getAluKind(SU)) {
165 if (MO.
isReg() && MO.
getReg() == R600::ALU_LITERAL_X)
174 LLVM_DEBUG(
dbgs() << CurEmitted <<
" Instructions Emitted in this clause\n");
176 if (CurInstKind != IDFetch) {
177 MoveUnits(Pending[IDFetch], Available[IDFetch]);
197 PhysicalRegCopy.push_back(SU);
201 int IK = getInstKind(SU);
205 Available[IDOther].push_back(SU);
207 Pending[IK].push_back(SU);
211 bool R600SchedStrategy::regBelongsToClass(
unsigned Reg,
220 R600SchedStrategy::AluKind R600SchedStrategy::getAluKind(
SUnit *SU)
const {
229 case R600::INTERP_PAIR_XY:
230 case R600::INTERP_PAIR_ZW:
231 case R600::INTERP_VEC_LOAD:
249 MI->
getOpcode() == R600::GROUP_BARRIER) {
259 switch (DestSubReg) {
274 if (regBelongsToClass(DestReg, &R600::R600_TReg32_XRegClass) ||
275 regBelongsToClass(DestReg, &R600::R600_AddrRegClass))
277 if (regBelongsToClass(DestReg, &R600::R600_TReg32_YRegClass))
279 if (regBelongsToClass(DestReg, &R600::R600_TReg32_ZRegClass))
281 if (regBelongsToClass(DestReg, &R600::R600_TReg32_WRegClass))
283 if (regBelongsToClass(DestReg, &R600::R600_Reg128RegClass))
293 int R600SchedStrategy::getInstKind(
SUnit* SU) {
306 case R600::CONST_COPY:
307 case R600::INTERP_PAIR_XY:
308 case R600::INTERP_PAIR_ZW:
309 case R600::INTERP_VEC_LOAD:
317 SUnit *R600SchedStrategy::PopInst(std::vector<SUnit *> &Q,
bool AnyALU) {
320 for (std::vector<SUnit *>::reverse_iterator It = Q.rbegin(),
E = Q.rend();
323 InstructionsGroupCandidate.push_back(SU->
getInstr());
326 InstructionsGroupCandidate.pop_back();
327 Q.erase((It + 1).base());
330 InstructionsGroupCandidate.pop_back();
336 void R600SchedStrategy::LoadAlu() {
337 std::vector<SUnit *> &QSrc = Pending[IDAlu];
338 for (
unsigned i = 0, e = QSrc.size(); i < e; ++i) {
339 AluKind AK = getAluKind(QSrc[i]);
340 AvailableAlus[AK].push_back(QSrc[i]);
345 void R600SchedStrategy::PrepareNextSlot() {
347 assert (OccupedSlotsMask &&
"Slot wasn't filled");
348 OccupedSlotsMask = 0;
351 InstructionsGroupCandidate.clear();
355 void R600SchedStrategy::AssignSlot(
MachineInstr*
MI,
unsigned Slot) {
357 if (DstIndex == -1) {
387 SUnit *R600SchedStrategy::AttemptFillSlot(
unsigned Slot,
bool AnyAlu) {
388 static const AluKind IndexToID[] = {AluT_X, AluT_Y, AluT_Z, AluT_W};
389 SUnit *SlotedSU = PopInst(AvailableAlus[IndexToID[Slot]], AnyAlu);
392 SUnit *UnslotedSU = PopInst(AvailableAlus[AluAny], AnyAlu);
394 AssignSlot(UnslotedSU->
getInstr(), Slot);
398 unsigned R600SchedStrategy::AvailablesAluCount()
const {
399 return AvailableAlus[AluAny].size() + AvailableAlus[AluT_XYZW].size() +
400 AvailableAlus[AluT_X].size() + AvailableAlus[AluT_Y].size() +
401 AvailableAlus[AluT_Z].size() + AvailableAlus[AluT_W].size() +
402 AvailableAlus[AluTrans].size() + AvailableAlus[AluDiscarded].size() +
403 AvailableAlus[AluPredX].size();
406 SUnit* R600SchedStrategy::pickAlu() {
407 while (AvailablesAluCount() || !Pending[IDAlu].empty()) {
408 if (!OccupedSlotsMask) {
410 if (!AvailableAlus[AluPredX].empty()) {
411 OccupedSlotsMask |= 31;
412 return PopInst(AvailableAlus[AluPredX],
false);
415 if (!AvailableAlus[AluDiscarded].empty()) {
416 OccupedSlotsMask |= 31;
417 return PopInst(AvailableAlus[AluDiscarded],
false);
420 if (!AvailableAlus[AluT_XYZW].empty()) {
421 OccupedSlotsMask |= 15;
422 return PopInst(AvailableAlus[AluT_XYZW],
false);
425 bool TransSlotOccuped = OccupedSlotsMask & 16;
426 if (!TransSlotOccuped && VLIW5) {
427 if (!AvailableAlus[AluTrans].empty()) {
428 OccupedSlotsMask |= 16;
429 return PopInst(AvailableAlus[AluTrans],
false);
431 SUnit *SU = AttemptFillSlot(3,
true);
433 OccupedSlotsMask |= 16;
437 for (
int Chan = 3; Chan > -1; --Chan) {
438 bool isOccupied = OccupedSlotsMask & (1 << Chan);
440 SUnit *SU = AttemptFillSlot(Chan,
false);
442 OccupedSlotsMask |= (1 << Chan);
443 InstructionsGroupCandidate.push_back(SU->
getInstr());
453 SUnit* R600SchedStrategy::pickOther(
int QID) {
455 std::vector<SUnit *> &AQ = Available[QID];
458 MoveUnits(Pending[QID], AQ);
mop_iterator operands_end()
void schedNode(SUnit *SU, bool IsTopNode) override
Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an instruction and updated scheduled/rem...
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
AMDGPU specific subclass of TargetSubtarget.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Compute iterated dominance frontiers using a linear time algorithm.
Interface definition for R600InstrInfo.
void initialize(ScheduleDAGMI *dag) override
Initialize the strategy after building the DAG for a new region.
void dump(const ScheduleDAG *G) const
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned getSubReg() const
R600 Machine Scheduler interface.
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
virtual bool hasVRegLiveness() const
Return true if this DAG supports VReg liveness and RegPressure.
bool isScheduled
True once scheduled.
void releaseBottomNode(SUnit *SU) override
When all successor dependencies have been resolved, free this node for bottom-up scheduling.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool usesVertexCache(unsigned Opcode) const
SUnit * pickNode(bool &IsTopNode) override
Pick the next node to schedule, or return NULL.
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isPhysicalRegCopy(MachineInstr *MI)
void releaseTopNode(SUnit *SU) override
When all predecessor dependencies have been resolved, free this node for top-down scheduling...
bool isLDSInstr(unsigned Opcode) const
int getOperandIdx(const MachineInstr &MI, unsigned Op) const
Get the index of Op in the MachineInstr.
bool isVectorOnly(unsigned Opcode) const
bool fitsConstReadLimitations(const std::vector< MachineInstr *> &) const
An instruction group can only access 2 channel pair (either [XY] or [ZW]) from KCache bank on R700+...
bool isTransOnly(unsigned Opcode) const
bool isVector(const MachineInstr &MI) const
Vector instructions are instructions that must fill all instruction slots within an instruction group...
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
MachineOperand class - Representation of each machine instruction operand.
bool hasCaymanISA() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isALUInstr(unsigned Opcode) const
static unsigned getWFCountLimitedByGPR(unsigned GPRCount)
bool readsLDSSrcReg(const MachineInstr &MI) const
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
short getTexVTXClauseSize() const
bool isReductionOp(unsigned opcode) const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
mop_iterator operands_begin()
std::vector< SUnit > SUnits
The scheduling units.
const MachineOperand & getOperand(unsigned i) const
bool usesTextureCache(unsigned Opcode) const
Scheduling unit. This is a node in the scheduling DAG.
bool isCubeOp(unsigned opcode) const