blob: d3ffb506f1bab4895da90cc44c8e3179d6da81c1 [file] [log] [blame]
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +00001//===-- R600MachineScheduler.cpp - R600 Scheduler Interface -*- C++ -*-----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
11/// \brief R600 Machine Scheduler interface
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000012//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "misched"
16
17#include "R600MachineScheduler.h"
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000018#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Benjamin Kramerd78bb462013-05-23 17:10:37 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000020#include "llvm/Pass.h"
21#include "llvm/PassManager.h"
NAKAMURA Takumi756cf882013-03-11 08:19:28 +000022#include "llvm/Support/raw_ostream.h"
NAKAMURA Takumi756cf882013-03-11 08:19:28 +000023
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000024using namespace llvm;
25
26void R600SchedStrategy::initialize(ScheduleDAGMI *dag) {
Andrew Trickd7f890e2013-12-28 21:56:47 +000027 assert(dag->hasVRegLiveness() && "R600SchedStrategy needs vreg liveness");
28 DAG = static_cast<ScheduleDAGMILive*>(dag);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000029 TII = static_cast<const R600InstrInfo*>(DAG->TII);
30 TRI = static_cast<const R600RegisterInfo*>(DAG->TRI);
Vincent Lejeune7e2c8322013-09-04 19:53:46 +000031 VLIW5 = !DAG->MF.getTarget().getSubtarget<AMDGPUSubtarget>().hasCaymanISA();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000032 MRI = &DAG->MRI;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000033 CurInstKind = IDOther;
34 CurEmitted = 0;
Vincent Lejeune77a83522013-06-29 19:32:43 +000035 OccupedSlotsMask = 31;
Vincent Lejeune80031d9f2013-04-03 16:49:34 +000036 InstKindLimit[IDAlu] = TII->getMaxAlusPerClause();
Vincent Lejeune3d5118c2013-05-17 16:50:56 +000037 InstKindLimit[IDOther] = 32;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000038
39 const AMDGPUSubtarget &ST = DAG->TM.getSubtarget<AMDGPUSubtarget>();
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +000040 InstKindLimit[IDFetch] = ST.getTexVTXClauseSize();
Vincent Lejeuned1a9d182013-06-07 23:30:34 +000041 AluInstCount = 0;
42 FetchInstCount = 0;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000043}
44
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +000045void R600SchedStrategy::MoveUnits(std::vector<SUnit *> &QSrc,
46 std::vector<SUnit *> &QDst)
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000047{
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +000048 QDst.insert(QDst.end(), QSrc.begin(), QSrc.end());
49 QSrc.clear();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000050}
51
Vincent Lejeuned1a9d182013-06-07 23:30:34 +000052static
53unsigned getWFCountLimitedByGPR(unsigned GPRCount) {
54 assert (GPRCount && "GPRCount cannot be 0");
55 return 248 / GPRCount;
56}
57
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000058SUnit* R600SchedStrategy::pickNode(bool &IsTopNode) {
59 SUnit *SU = 0;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000060 NextInstKind = IDOther;
61
Vincent Lejeune3d5118c2013-05-17 16:50:56 +000062 IsTopNode = false;
63
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000064 // check if we might want to switch current clause type
Vincent Lejeune3d5118c2013-05-17 16:50:56 +000065 bool AllowSwitchToAlu = (CurEmitted >= InstKindLimit[CurInstKind]) ||
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +000066 (Available[CurInstKind].empty());
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +000067 bool AllowSwitchFromAlu = (CurEmitted >= InstKindLimit[CurInstKind]) &&
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +000068 (!Available[IDFetch].empty() || !Available[IDOther].empty());
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000069
Vincent Lejeuned1a9d182013-06-07 23:30:34 +000070 if (CurInstKind == IDAlu && !Available[IDFetch].empty()) {
71 // We use the heuristic provided by AMD Accelerated Parallel Processing
72 // OpenCL Programming Guide :
73 // The approx. number of WF that allows TEX inst to hide ALU inst is :
74 // 500 (cycles for TEX) / (AluFetchRatio * 8 (cycles for ALU))
Andrew Trickd7f890e2013-12-28 21:56:47 +000075 float ALUFetchRationEstimate =
Vincent Lejeuned1a9d182013-06-07 23:30:34 +000076 (AluInstCount + AvailablesAluCount() + Pending[IDAlu].size()) /
77 (FetchInstCount + Available[IDFetch].size());
78 unsigned NeededWF = 62.5f / ALUFetchRationEstimate;
79 DEBUG( dbgs() << NeededWF << " approx. Wavefronts Required\n" );
80 // We assume the local GPR requirements to be "dominated" by the requirement
81 // of the TEX clause (which consumes 128 bits regs) ; ALU inst before and
82 // after TEX are indeed likely to consume or generate values from/for the
83 // TEX clause.
84 // Available[IDFetch].size() * 2 : GPRs required in the Fetch clause
85 // We assume that fetch instructions are either TnXYZW = TEX TnXYZW (need
86 // one GPR) or TmXYZW = TnXYZW (need 2 GPR).
87 // (TODO : use RegisterPressure)
88 // If we are going too use too many GPR, we flush Fetch instruction to lower
89 // register pressure on 128 bits regs.
90 unsigned NearRegisterRequirement = 2 * Available[IDFetch].size();
91 if (NeededWF > getWFCountLimitedByGPR(NearRegisterRequirement))
92 AllowSwitchFromAlu = true;
93 }
94
Tom Stellardaad53762013-06-05 03:43:06 +000095 if (!SU && ((AllowSwitchToAlu && CurInstKind != IDAlu) ||
96 (!AllowSwitchFromAlu && CurInstKind == IDAlu))) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000097 // try to pick ALU
98 SU = pickAlu();
Vincent Lejeune4b5b8492013-06-05 20:27:35 +000099 if (!SU && !PhysicalRegCopy.empty()) {
100 SU = PhysicalRegCopy.front();
101 PhysicalRegCopy.erase(PhysicalRegCopy.begin());
102 }
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000103 if (SU) {
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +0000104 if (CurEmitted >= InstKindLimit[IDAlu])
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000105 CurEmitted = 0;
106 NextInstKind = IDAlu;
107 }
108 }
109
110 if (!SU) {
111 // try to pick FETCH
112 SU = pickOther(IDFetch);
113 if (SU)
114 NextInstKind = IDFetch;
115 }
116
117 // try to pick other
118 if (!SU) {
119 SU = pickOther(IDOther);
120 if (SU)
121 NextInstKind = IDOther;
122 }
123
124 DEBUG(
125 if (SU) {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000126 dbgs() << " ** Pick node **\n";
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000127 SU->dump(DAG);
128 } else {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000129 dbgs() << "NO NODE \n";
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000130 for (unsigned i = 0; i < DAG->SUnits.size(); i++) {
131 const SUnit &S = DAG->SUnits[i];
132 if (!S.isScheduled)
133 S.dump(DAG);
134 }
135 }
136 );
137
138 return SU;
139}
140
141void R600SchedStrategy::schedNode(SUnit *SU, bool IsTopNode) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000142 if (NextInstKind != CurInstKind) {
143 DEBUG(dbgs() << "Instruction Type Switch\n");
144 if (NextInstKind != IDAlu)
Vincent Lejeune77a83522013-06-29 19:32:43 +0000145 OccupedSlotsMask |= 31;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000146 CurEmitted = 0;
147 CurInstKind = NextInstKind;
148 }
149
150 if (CurInstKind == IDAlu) {
Vincent Lejeuned1a9d182013-06-07 23:30:34 +0000151 AluInstCount ++;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000152 switch (getAluKind(SU)) {
153 case AluT_XYZW:
154 CurEmitted += 4;
155 break;
156 case AluDiscarded:
157 break;
158 default: {
159 ++CurEmitted;
160 for (MachineInstr::mop_iterator It = SU->getInstr()->operands_begin(),
161 E = SU->getInstr()->operands_end(); It != E; ++It) {
162 MachineOperand &MO = *It;
163 if (MO.isReg() && MO.getReg() == AMDGPU::ALU_LITERAL_X)
164 ++CurEmitted;
165 }
166 }
167 }
168 } else {
169 ++CurEmitted;
170 }
171
172
173 DEBUG(dbgs() << CurEmitted << " Instructions Emitted in this clause\n");
174
175 if (CurInstKind != IDFetch) {
176 MoveUnits(Pending[IDFetch], Available[IDFetch]);
Vincent Lejeuned1a9d182013-06-07 23:30:34 +0000177 } else
178 FetchInstCount++;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000179}
180
Vincent Lejeune4b5b8492013-06-05 20:27:35 +0000181static bool
182isPhysicalRegCopy(MachineInstr *MI) {
183 if (MI->getOpcode() != AMDGPU::COPY)
184 return false;
185
186 return !TargetRegisterInfo::isVirtualRegister(MI->getOperand(1).getReg());
187}
188
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000189void R600SchedStrategy::releaseTopNode(SUnit *SU) {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000190 DEBUG(dbgs() << "Top Releasing ";SU->dump(DAG););
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000191}
192
193void R600SchedStrategy::releaseBottomNode(SUnit *SU) {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000194 DEBUG(dbgs() << "Bottom Releasing ";SU->dump(DAG););
Vincent Lejeune4b5b8492013-06-05 20:27:35 +0000195 if (isPhysicalRegCopy(SU->getInstr())) {
196 PhysicalRegCopy.push_back(SU);
197 return;
198 }
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000199
200 int IK = getInstKind(SU);
Tom Stellardaad53762013-06-05 03:43:06 +0000201
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000202 // There is no export clause, we can schedule one as soon as its ready
203 if (IK == IDOther)
204 Available[IDOther].push_back(SU);
205 else
206 Pending[IK].push_back(SU);
207
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000208}
209
210bool R600SchedStrategy::regBelongsToClass(unsigned Reg,
211 const TargetRegisterClass *RC) const {
212 if (!TargetRegisterInfo::isVirtualRegister(Reg)) {
213 return RC->contains(Reg);
214 } else {
215 return MRI->getRegClass(Reg) == RC;
216 }
217}
218
219R600SchedStrategy::AluKind R600SchedStrategy::getAluKind(SUnit *SU) const {
220 MachineInstr *MI = SU->getInstr();
221
Vincent Lejeune77a83522013-06-29 19:32:43 +0000222 if (TII->isTransOnly(MI))
223 return AluTrans;
224
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000225 switch (MI->getOpcode()) {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000226 case AMDGPU::PRED_X:
227 return AluPredX;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000228 case AMDGPU::INTERP_PAIR_XY:
229 case AMDGPU::INTERP_PAIR_ZW:
230 case AMDGPU::INTERP_VEC_LOAD:
Vincent Lejeune519f21e2013-05-17 16:50:32 +0000231 case AMDGPU::DOT_4:
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000232 return AluT_XYZW;
233 case AMDGPU::COPY:
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000234 if (MI->getOperand(1).isUndef()) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000235 // MI will become a KILL, don't considers it in scheduling
236 return AluDiscarded;
237 }
238 default:
239 break;
240 }
241
242 // Does the instruction take a whole IG ?
Tom Stellardce540332013-06-28 15:46:59 +0000243 // XXX: Is it possible to add a helper function in R600InstrInfo that can
244 // be used here and in R600PacketizerList::isSoloInstruction() ?
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000245 if(TII->isVector(*MI) ||
246 TII->isCubeOp(MI->getOpcode()) ||
Tom Stellardce540332013-06-28 15:46:59 +0000247 TII->isReductionOp(MI->getOpcode()) ||
248 MI->getOpcode() == AMDGPU::GROUP_BARRIER) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000249 return AluT_XYZW;
Tom Stellardce540332013-06-28 15:46:59 +0000250 }
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000251
Tom Stellardc026e8b2013-06-28 15:47:08 +0000252 if (TII->isLDSInstr(MI->getOpcode())) {
253 return AluT_X;
254 }
255
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000256 // Is the result already assigned to a channel ?
257 unsigned DestSubReg = MI->getOperand(0).getSubReg();
258 switch (DestSubReg) {
259 case AMDGPU::sub0:
260 return AluT_X;
261 case AMDGPU::sub1:
262 return AluT_Y;
263 case AMDGPU::sub2:
264 return AluT_Z;
265 case AMDGPU::sub3:
266 return AluT_W;
267 default:
268 break;
269 }
270
271 // Is the result already member of a X/Y/Z/W class ?
272 unsigned DestReg = MI->getOperand(0).getReg();
273 if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_XRegClass) ||
274 regBelongsToClass(DestReg, &AMDGPU::R600_AddrRegClass))
275 return AluT_X;
276 if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_YRegClass))
277 return AluT_Y;
278 if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_ZRegClass))
279 return AluT_Z;
280 if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_WRegClass))
281 return AluT_W;
282 if (regBelongsToClass(DestReg, &AMDGPU::R600_Reg128RegClass))
283 return AluT_XYZW;
284
Tom Stellard7f6fa4c2013-09-12 02:55:06 +0000285 // LDS src registers cannot be used in the Trans slot.
286 if (TII->readsLDSSrcReg(MI))
287 return AluT_XYZW;
288
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000289 return AluAny;
290
291}
292
293int R600SchedStrategy::getInstKind(SUnit* SU) {
294 int Opcode = SU->getInstr()->getOpcode();
295
Vincent Lejeunee958c8e2013-05-17 16:50:37 +0000296 if (TII->usesTextureCache(Opcode) || TII->usesVertexCache(Opcode))
297 return IDFetch;
298
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000299 if (TII->isALUInstr(Opcode)) {
300 return IDAlu;
301 }
302
303 switch (Opcode) {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000304 case AMDGPU::PRED_X:
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000305 case AMDGPU::COPY:
306 case AMDGPU::CONST_COPY:
307 case AMDGPU::INTERP_PAIR_XY:
308 case AMDGPU::INTERP_PAIR_ZW:
309 case AMDGPU::INTERP_VEC_LOAD:
Vincent Lejeune519f21e2013-05-17 16:50:32 +0000310 case AMDGPU::DOT_4:
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000311 return IDAlu;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000312 default:
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000313 return IDOther;
314 }
315}
316
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000317SUnit *R600SchedStrategy::PopInst(std::vector<SUnit *> &Q, bool AnyALU) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000318 if (Q.empty())
319 return NULL;
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000320 for (std::vector<SUnit *>::reverse_iterator It = Q.rbegin(), E = Q.rend();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000321 It != E; ++It) {
322 SUnit *SU = *It;
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000323 InstructionsGroupCandidate.push_back(SU->getInstr());
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000324 if (TII->fitsConstReadLimitations(InstructionsGroupCandidate)
325 && (!AnyALU || !TII->isVectorOnly(SU->getInstr()))
326 ) {
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000327 InstructionsGroupCandidate.pop_back();
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000328 Q.erase((It + 1).base());
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000329 return SU;
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000330 } else {
331 InstructionsGroupCandidate.pop_back();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000332 }
333 }
334 return NULL;
335}
336
337void R600SchedStrategy::LoadAlu() {
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000338 std::vector<SUnit *> &QSrc = Pending[IDAlu];
339 for (unsigned i = 0, e = QSrc.size(); i < e; ++i) {
340 AluKind AK = getAluKind(QSrc[i]);
341 AvailableAlus[AK].push_back(QSrc[i]);
342 }
343 QSrc.clear();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000344}
345
346void R600SchedStrategy::PrepareNextSlot() {
347 DEBUG(dbgs() << "New Slot\n");
348 assert (OccupedSlotsMask && "Slot wasn't filled");
349 OccupedSlotsMask = 0;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000350// if (HwGen == AMDGPUSubtarget::NORTHERN_ISLANDS)
351// OccupedSlotsMask |= 16;
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000352 InstructionsGroupCandidate.clear();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000353 LoadAlu();
354}
355
356void R600SchedStrategy::AssignSlot(MachineInstr* MI, unsigned Slot) {
Tom Stellardc026e8b2013-06-28 15:47:08 +0000357 int DstIndex = TII->getOperandIdx(MI->getOpcode(), AMDGPU::OpName::dst);
358 if (DstIndex == -1) {
359 return;
360 }
361 unsigned DestReg = MI->getOperand(DstIndex).getReg();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000362 // PressureRegister crashes if an operand is def and used in the same inst
363 // and we try to constraint its regclass
364 for (MachineInstr::mop_iterator It = MI->operands_begin(),
365 E = MI->operands_end(); It != E; ++It) {
366 MachineOperand &MO = *It;
367 if (MO.isReg() && !MO.isDef() &&
Tom Stellardc026e8b2013-06-28 15:47:08 +0000368 MO.getReg() == DestReg)
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000369 return;
370 }
371 // Constrains the regclass of DestReg to assign it to Slot
372 switch (Slot) {
373 case 0:
374 MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_XRegClass);
375 break;
376 case 1:
377 MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_YRegClass);
378 break;
379 case 2:
380 MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_ZRegClass);
381 break;
382 case 3:
383 MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_WRegClass);
384 break;
385 }
386}
387
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000388SUnit *R600SchedStrategy::AttemptFillSlot(unsigned Slot, bool AnyAlu) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000389 static const AluKind IndexToID[] = {AluT_X, AluT_Y, AluT_Z, AluT_W};
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000390 SUnit *SlotedSU = PopInst(AvailableAlus[IndexToID[Slot]], AnyAlu);
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000391 if (SlotedSU)
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000392 return SlotedSU;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000393 SUnit *UnslotedSU = PopInst(AvailableAlus[AluAny], AnyAlu);
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000394 if (UnslotedSU)
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000395 AssignSlot(UnslotedSU->getInstr(), Slot);
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000396 return UnslotedSU;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000397}
398
Vincent Lejeuned1a9d182013-06-07 23:30:34 +0000399unsigned R600SchedStrategy::AvailablesAluCount() const {
400 return AvailableAlus[AluAny].size() + AvailableAlus[AluT_XYZW].size() +
401 AvailableAlus[AluT_X].size() + AvailableAlus[AluT_Y].size() +
402 AvailableAlus[AluT_Z].size() + AvailableAlus[AluT_W].size() +
Vincent Lejeune77a83522013-06-29 19:32:43 +0000403 AvailableAlus[AluTrans].size() + AvailableAlus[AluDiscarded].size() +
404 AvailableAlus[AluPredX].size();
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000405}
406
407SUnit* R600SchedStrategy::pickAlu() {
Vincent Lejeuned1a9d182013-06-07 23:30:34 +0000408 while (AvailablesAluCount() || !Pending[IDAlu].empty()) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000409 if (!OccupedSlotsMask) {
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000410 // Bottom up scheduling : predX must comes first
411 if (!AvailableAlus[AluPredX].empty()) {
Vincent Lejeune77a83522013-06-29 19:32:43 +0000412 OccupedSlotsMask |= 31;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000413 return PopInst(AvailableAlus[AluPredX], false);
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000414 }
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000415 // Flush physical reg copies (RA will discard them)
416 if (!AvailableAlus[AluDiscarded].empty()) {
Vincent Lejeune77a83522013-06-29 19:32:43 +0000417 OccupedSlotsMask |= 31;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000418 return PopInst(AvailableAlus[AluDiscarded], false);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000419 }
420 // If there is a T_XYZW alu available, use it
421 if (!AvailableAlus[AluT_XYZW].empty()) {
Vincent Lejeune77a83522013-06-29 19:32:43 +0000422 OccupedSlotsMask |= 15;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000423 return PopInst(AvailableAlus[AluT_XYZW], false);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000424 }
425 }
Vincent Lejeune77a83522013-06-29 19:32:43 +0000426 bool TransSlotOccuped = OccupedSlotsMask & 16;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000427 if (!TransSlotOccuped && VLIW5) {
Vincent Lejeune77a83522013-06-29 19:32:43 +0000428 if (!AvailableAlus[AluTrans].empty()) {
429 OccupedSlotsMask |= 16;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000430 return PopInst(AvailableAlus[AluTrans], false);
431 }
432 SUnit *SU = AttemptFillSlot(3, true);
433 if (SU) {
434 OccupedSlotsMask |= 16;
435 return SU;
Vincent Lejeune77a83522013-06-29 19:32:43 +0000436 }
437 }
Vincent Lejeune3d5118c2013-05-17 16:50:56 +0000438 for (int Chan = 3; Chan > -1; --Chan) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000439 bool isOccupied = OccupedSlotsMask & (1 << Chan);
440 if (!isOccupied) {
Vincent Lejeune7e2c8322013-09-04 19:53:46 +0000441 SUnit *SU = AttemptFillSlot(Chan, false);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000442 if (SU) {
443 OccupedSlotsMask |= (1 << Chan);
Vincent Lejeune0a22bc42013-03-14 15:50:45 +0000444 InstructionsGroupCandidate.push_back(SU->getInstr());
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000445 return SU;
446 }
447 }
448 }
449 PrepareNextSlot();
450 }
451 return NULL;
452}
453
454SUnit* R600SchedStrategy::pickOther(int QID) {
455 SUnit *SU = 0;
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000456 std::vector<SUnit *> &AQ = Available[QID];
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000457
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000458 if (AQ.empty()) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000459 MoveUnits(Pending[QID], AQ);
460 }
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +0000461 if (!AQ.empty()) {
462 SU = AQ.back();
463 AQ.resize(AQ.size() - 1);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +0000464 }
465 return SU;
466}