20#define DEBUG_TYPE "machine-scheduler"
27 VLIW5 = !ST.hasCaymanISA();
29 CurInstKind = IDOther;
31 OccupiedSlotsMask = 31;
32 InstKindLimit[IDAlu] = TII->getMaxAlusPerClause();
33 InstKindLimit[IDOther] = 32;
34 InstKindLimit[IDFetch] = ST.getTexVTXClauseSize();
39void R600SchedStrategy::MoveUnits(std::vector<SUnit *> &QSrc,
40 std::vector<SUnit *> &QDst)
47 assert (GPRCount &&
"GPRCount cannot be 0");
48 return 248 / GPRCount;
53 NextInstKind = IDOther;
58 bool AllowSwitchToAlu = (CurEmitted >= InstKindLimit[CurInstKind]) ||
59 (Available[CurInstKind].empty());
60 bool AllowSwitchFromAlu = (CurEmitted >= InstKindLimit[CurInstKind]) &&
61 (!Available[IDFetch].empty() || !Available[IDOther].empty());
63 if (CurInstKind == IDAlu && !Available[IDFetch].empty()) {
68 float ALUFetchRationEstimate =
69 (AluInstCount + AvailablesAluCount() + Pending[IDAlu].size()) /
70 (FetchInstCount + Available[IDFetch].
size());
71 if (ALUFetchRationEstimate == 0) {
72 AllowSwitchFromAlu =
true;
74 unsigned NeededWF = 62.5f / ALUFetchRationEstimate;
75 LLVM_DEBUG(
dbgs() << NeededWF <<
" approx. Wavefronts Required\n");
86 unsigned NearRegisterRequirement = 2 * Available[IDFetch].size();
88 AllowSwitchFromAlu =
true;
92 if (!SU && ((AllowSwitchToAlu && CurInstKind != IDAlu) ||
93 (!AllowSwitchFromAlu && CurInstKind == IDAlu))) {
96 if (!SU && !PhysicalRegCopy.empty()) {
97 SU = PhysicalRegCopy.front();
98 PhysicalRegCopy.erase(PhysicalRegCopy.begin());
101 if (CurEmitted >= InstKindLimit[IDAlu])
103 NextInstKind = IDAlu;
109 SU = pickOther(IDFetch);
111 NextInstKind = IDFetch;
116 SU = pickOther(IDOther);
118 NextInstKind = IDOther;
122 dbgs() <<
" ** Pick node **\n";
125 dbgs() <<
"NO NODE \n";
126 for (
const SUnit &S : DAG->SUnits)
135 if (NextInstKind != CurInstKind) {
137 if (NextInstKind != IDAlu)
138 OccupiedSlotsMask |= 31;
140 CurInstKind = NextInstKind;
143 if (CurInstKind == IDAlu) {
145 switch (getAluKind(SU)) {
156 if (MO.
isReg() && MO.
getReg() == R600::ALU_LITERAL_X)
165 LLVM_DEBUG(
dbgs() << CurEmitted <<
" Instructions Emitted in this clause\n");
167 if (CurInstKind != IDFetch) {
168 MoveUnits(Pending[IDFetch], Available[IDFetch]);
175 if (
MI->getOpcode() != R600::COPY)
178 return !
MI->getOperand(1).getReg().isVirtual();
188 PhysicalRegCopy.push_back(SU);
192 int IK = getInstKind(SU);
196 Available[IDOther].push_back(SU);
198 Pending[IK].push_back(SU);
202bool R600SchedStrategy::regBelongsToClass(
Register Reg,
204 if (!Reg.isVirtual())
206 return MRI->getRegClass(Reg) == RC;
209R600SchedStrategy::AluKind R600SchedStrategy::getAluKind(
SUnit *SU)
const {
212 if (
TII->isTransOnly(*
MI))
215 switch (
MI->getOpcode()) {
218 case R600::INTERP_PAIR_XY:
219 case R600::INTERP_PAIR_ZW:
220 case R600::INTERP_VEC_LOAD:
224 if (
MI->getOperand(1).isUndef()) {
236 if(TII->isVector(*
MI) ||
237 TII->isCubeOp(
MI->getOpcode()) ||
238 TII->isReductionOp(
MI->getOpcode()) ||
239 MI->getOpcode() == R600::GROUP_BARRIER) {
243 if (TII->isLDSInstr(
MI->getOpcode())) {
248 unsigned DestSubReg =
MI->getOperand(0).getSubReg();
249 switch (DestSubReg) {
263 Register DestReg =
MI->getOperand(0).getReg();
264 if (regBelongsToClass(DestReg, &R600::R600_TReg32_XRegClass) ||
265 regBelongsToClass(DestReg, &R600::R600_AddrRegClass))
267 if (regBelongsToClass(DestReg, &R600::R600_TReg32_YRegClass))
269 if (regBelongsToClass(DestReg, &R600::R600_TReg32_ZRegClass))
271 if (regBelongsToClass(DestReg, &R600::R600_TReg32_WRegClass))
273 if (regBelongsToClass(DestReg, &R600::R600_Reg128RegClass))
277 if (TII->readsLDSSrcReg(*
MI))
283int R600SchedStrategy::getInstKind(
SUnit* SU) {
286 if (TII->usesTextureCache(Opcode) || TII->usesVertexCache(Opcode))
289 if (TII->isALUInstr(Opcode)) {
296 case R600::CONST_COPY:
297 case R600::INTERP_PAIR_XY:
298 case R600::INTERP_PAIR_ZW:
299 case R600::INTERP_VEC_LOAD:
307SUnit *R600SchedStrategy::PopInst(std::vector<SUnit *> &Q,
bool AnyALU) {
310 for (std::vector<SUnit *>::reverse_iterator It = Q.rbegin(),
E = Q.rend();
313 InstructionsGroupCandidate.push_back(SU->
getInstr());
314 if (TII->fitsConstReadLimitations(InstructionsGroupCandidate) &&
315 (!AnyALU || !TII->isVectorOnly(*SU->
getInstr()))) {
316 InstructionsGroupCandidate.pop_back();
317 Q.erase((It + 1).base());
320 InstructionsGroupCandidate.pop_back();
325void R600SchedStrategy::LoadAlu() {
326 std::vector<SUnit *> &QSrc = Pending[IDAlu];
327 for (SUnit *SU : QSrc) {
328 AluKind AK = getAluKind(SU);
329 AvailableAlus[AK].push_back(SU);
334void R600SchedStrategy::PrepareNextSlot() {
336 assert(OccupiedSlotsMask &&
"Slot wasn't filled");
337 OccupiedSlotsMask = 0;
340 InstructionsGroupCandidate.clear();
344void R600SchedStrategy::AssignSlot(
MachineInstr*
MI,
unsigned Slot) {
345 int DstIndex = TII->getOperandIdx(
MI->getOpcode(), R600::OpName::dst);
346 if (DstIndex == -1) {
349 Register DestReg =
MI->getOperand(DstIndex).getReg();
352 for (
const MachineOperand &MO :
MI->all_uses())
353 if (MO.getReg() == DestReg)
358 MRI->constrainRegClass(DestReg, &R600::R600_TReg32_XRegClass);
361 MRI->constrainRegClass(DestReg, &R600::R600_TReg32_YRegClass);
364 MRI->constrainRegClass(DestReg, &R600::R600_TReg32_ZRegClass);
367 MRI->constrainRegClass(DestReg, &R600::R600_TReg32_WRegClass);
372SUnit *R600SchedStrategy::AttemptFillSlot(
unsigned Slot,
bool AnyAlu) {
373 static const AluKind IndexToID[] = {AluT_X, AluT_Y, AluT_Z, AluT_W};
374 SUnit *SlotedSU = PopInst(AvailableAlus[IndexToID[Slot]], AnyAlu);
377 SUnit *UnslotedSU = PopInst(AvailableAlus[AluAny], AnyAlu);
379 AssignSlot(UnslotedSU->
getInstr(), Slot);
383unsigned R600SchedStrategy::AvailablesAluCount()
const {
384 return AvailableAlus[AluAny].size() + AvailableAlus[AluT_XYZW].size() +
385 AvailableAlus[AluT_X].size() + AvailableAlus[AluT_Y].size() +
386 AvailableAlus[AluT_Z].size() + AvailableAlus[AluT_W].size() +
387 AvailableAlus[AluTrans].size() + AvailableAlus[AluDiscarded].size() +
388 AvailableAlus[AluPredX].size();
391SUnit* R600SchedStrategy::pickAlu() {
392 while (AvailablesAluCount() || !Pending[IDAlu].
empty()) {
393 if (!OccupiedSlotsMask) {
395 if (!AvailableAlus[AluPredX].
empty()) {
396 OccupiedSlotsMask |= 31;
397 return PopInst(AvailableAlus[AluPredX],
false);
400 if (!AvailableAlus[AluDiscarded].
empty()) {
401 OccupiedSlotsMask |= 31;
402 return PopInst(AvailableAlus[AluDiscarded],
false);
405 if (!AvailableAlus[AluT_XYZW].
empty()) {
406 OccupiedSlotsMask |= 15;
407 return PopInst(AvailableAlus[AluT_XYZW],
false);
410 bool TransSlotOccupied = OccupiedSlotsMask & 16;
411 if (!TransSlotOccupied && VLIW5) {
412 if (!AvailableAlus[AluTrans].
empty()) {
413 OccupiedSlotsMask |= 16;
414 return PopInst(AvailableAlus[AluTrans],
false);
416 SUnit *SU = AttemptFillSlot(3,
true);
418 OccupiedSlotsMask |= 16;
422 for (
int Chan = 3; Chan > -1; --Chan) {
423 bool isOccupied = OccupiedSlotsMask & (1 << Chan);
425 SUnit *SU = AttemptFillSlot(Chan,
false);
427 OccupiedSlotsMask |= (1 << Chan);
428 InstructionsGroupCandidate.push_back(SU->
getInstr());
438SUnit* R600SchedStrategy::pickOther(
int QID) {
440 std::vector<SUnit *> &AQ = Available[QID];
443 MoveUnits(Pending[QID], AQ);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
Promote Memory to Register
Provides R600 specific target descriptions.
static unsigned getWFCountLimitedByGPR(unsigned GPRCount)
static bool isPhysicalRegCopy(MachineInstr *MI)
R600 Machine Scheduler interface.
AMDGPU R600 specific subclass of TargetSubtarget.
MachineRegisterInfo & MRI
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
Representation of each machine instruction.
mop_iterator operands_begin()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
mop_iterator operands_end()
MachineOperand * mop_iterator
iterator/begin/end - Iterate over all operands of a machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
void initialize(ScheduleDAGMI *dag) override
Initialize the strategy after building the DAG for a new region.
SUnit * pickNode(bool &IsTopNode) override
Pick the next node to schedule, or return NULL.
void releaseBottomNode(SUnit *SU) override
When all successor dependencies have been resolved, free this node for bottom-up scheduling.
void releaseTopNode(SUnit *SU) override
When all predecessor dependencies have been resolved, free this node for top-down scheduling.
void schedNode(SUnit *SU, bool IsTopNode) override
Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an instruction and updated scheduled/rem...
Wrapper class representing virtual and physical registers.
Scheduling unit. This is a node in the scheduling DAG.
bool isScheduled
True once scheduled.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
virtual bool hasVRegLiveness() const
Return true if this DAG supports VReg liveness and RegPressure.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MCRegisterClass TargetRegisterClass