Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 1 | //===-- 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 |
| 12 | // TODO: Scheduling is optimised for VLIW4 arch, modify it to support TRANS slot |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #define DEBUG_TYPE "misched" |
| 17 | |
| 18 | #include "R600MachineScheduler.h" |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Benjamin Kramer | 5c35290 | 2013-05-23 17:10:37 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 21 | #include "llvm/Pass.h" |
| 22 | #include "llvm/PassManager.h" |
NAKAMURA Takumi | 3f179b5 | 2013-03-11 08:19:28 +0000 | [diff] [blame] | 23 | #include "llvm/Support/raw_ostream.h" |
NAKAMURA Takumi | 3f179b5 | 2013-03-11 08:19:28 +0000 | [diff] [blame] | 24 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
| 27 | void R600SchedStrategy::initialize(ScheduleDAGMI *dag) { |
| 28 | |
| 29 | DAG = dag; |
| 30 | TII = static_cast<const R600InstrInfo*>(DAG->TII); |
| 31 | TRI = static_cast<const R600RegisterInfo*>(DAG->TRI); |
| 32 | MRI = &DAG->MRI; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 33 | CurInstKind = IDOther; |
| 34 | CurEmitted = 0; |
| 35 | OccupedSlotsMask = 15; |
Vincent Lejeune | dae2a20 | 2013-04-03 16:49:34 +0000 | [diff] [blame] | 36 | InstKindLimit[IDAlu] = TII->getMaxAlusPerClause(); |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 37 | InstKindLimit[IDOther] = 32; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 38 | |
| 39 | const AMDGPUSubtarget &ST = DAG->TM.getSubtarget<AMDGPUSubtarget>(); |
Vincent Lejeune | dcfcf1d | 2013-05-17 16:49:55 +0000 | [diff] [blame] | 40 | InstKindLimit[IDFetch] = ST.getTexVTXClauseSize(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 43 | void R600SchedStrategy::MoveUnits(std::vector<SUnit *> &QSrc, |
| 44 | std::vector<SUnit *> &QDst) |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 45 | { |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 46 | QDst.insert(QDst.end(), QSrc.begin(), QSrc.end()); |
| 47 | QSrc.clear(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | SUnit* R600SchedStrategy::pickNode(bool &IsTopNode) { |
| 51 | SUnit *SU = 0; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 52 | NextInstKind = IDOther; |
| 53 | |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 54 | IsTopNode = false; |
| 55 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 56 | // check if we might want to switch current clause type |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 57 | bool AllowSwitchToAlu = (CurEmitted >= InstKindLimit[CurInstKind]) || |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 58 | (Available[CurInstKind].empty()); |
Vincent Lejeune | dcfcf1d | 2013-05-17 16:49:55 +0000 | [diff] [blame] | 59 | bool AllowSwitchFromAlu = (CurEmitted >= InstKindLimit[CurInstKind]) && |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 60 | (!Available[IDFetch].empty() || !Available[IDOther].empty()); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 61 | |
Tom Stellard | ad7ecc6 | 2013-06-05 03:43:06 +0000 | [diff] [blame^] | 62 | // We want to scheduled AR defs as soon as possible to make sure they aren't |
| 63 | // put in a different ALU clause from their uses. |
| 64 | if (!SU && !UnscheduledARDefs.empty()) { |
| 65 | SU = UnscheduledARDefs[0]; |
| 66 | UnscheduledARDefs.erase(UnscheduledARDefs.begin()); |
| 67 | NextInstKind = IDAlu; |
| 68 | } |
| 69 | |
| 70 | if (!SU && ((AllowSwitchToAlu && CurInstKind != IDAlu) || |
| 71 | (!AllowSwitchFromAlu && CurInstKind == IDAlu))) { |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 72 | // try to pick ALU |
| 73 | SU = pickAlu(); |
| 74 | if (SU) { |
Vincent Lejeune | dcfcf1d | 2013-05-17 16:49:55 +0000 | [diff] [blame] | 75 | if (CurEmitted >= InstKindLimit[IDAlu]) |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 76 | CurEmitted = 0; |
| 77 | NextInstKind = IDAlu; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (!SU) { |
| 82 | // try to pick FETCH |
| 83 | SU = pickOther(IDFetch); |
| 84 | if (SU) |
| 85 | NextInstKind = IDFetch; |
| 86 | } |
| 87 | |
| 88 | // try to pick other |
| 89 | if (!SU) { |
| 90 | SU = pickOther(IDOther); |
| 91 | if (SU) |
| 92 | NextInstKind = IDOther; |
| 93 | } |
| 94 | |
Tom Stellard | ad7ecc6 | 2013-06-05 03:43:06 +0000 | [diff] [blame^] | 95 | // We want to schedule the AR uses as late as possible to make sure that |
| 96 | // the AR defs have been released. |
| 97 | if (!SU && !UnscheduledARUses.empty()) { |
| 98 | SU = UnscheduledARUses[0]; |
| 99 | UnscheduledARUses.erase(UnscheduledARUses.begin()); |
| 100 | NextInstKind = IDAlu; |
| 101 | } |
| 102 | |
| 103 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 104 | DEBUG( |
| 105 | if (SU) { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 106 | dbgs() << " ** Pick node **\n"; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 107 | SU->dump(DAG); |
| 108 | } else { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 109 | dbgs() << "NO NODE \n"; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 110 | for (unsigned i = 0; i < DAG->SUnits.size(); i++) { |
| 111 | const SUnit &S = DAG->SUnits[i]; |
| 112 | if (!S.isScheduled) |
| 113 | S.dump(DAG); |
| 114 | } |
| 115 | } |
| 116 | ); |
| 117 | |
| 118 | return SU; |
| 119 | } |
| 120 | |
| 121 | void R600SchedStrategy::schedNode(SUnit *SU, bool IsTopNode) { |
| 122 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 123 | if (NextInstKind != CurInstKind) { |
| 124 | DEBUG(dbgs() << "Instruction Type Switch\n"); |
| 125 | if (NextInstKind != IDAlu) |
| 126 | OccupedSlotsMask = 15; |
| 127 | CurEmitted = 0; |
| 128 | CurInstKind = NextInstKind; |
| 129 | } |
| 130 | |
| 131 | if (CurInstKind == IDAlu) { |
| 132 | switch (getAluKind(SU)) { |
| 133 | case AluT_XYZW: |
| 134 | CurEmitted += 4; |
| 135 | break; |
| 136 | case AluDiscarded: |
| 137 | break; |
| 138 | default: { |
| 139 | ++CurEmitted; |
| 140 | for (MachineInstr::mop_iterator It = SU->getInstr()->operands_begin(), |
| 141 | E = SU->getInstr()->operands_end(); It != E; ++It) { |
| 142 | MachineOperand &MO = *It; |
| 143 | if (MO.isReg() && MO.getReg() == AMDGPU::ALU_LITERAL_X) |
| 144 | ++CurEmitted; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } else { |
| 149 | ++CurEmitted; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | DEBUG(dbgs() << CurEmitted << " Instructions Emitted in this clause\n"); |
| 154 | |
| 155 | if (CurInstKind != IDFetch) { |
| 156 | MoveUnits(Pending[IDFetch], Available[IDFetch]); |
| 157 | } |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void R600SchedStrategy::releaseTopNode(SUnit *SU) { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 161 | DEBUG(dbgs() << "Top Releasing ";SU->dump(DAG);); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 162 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void R600SchedStrategy::releaseBottomNode(SUnit *SU) { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 166 | DEBUG(dbgs() << "Bottom Releasing ";SU->dump(DAG);); |
| 167 | |
| 168 | int IK = getInstKind(SU); |
Tom Stellard | ad7ecc6 | 2013-06-05 03:43:06 +0000 | [diff] [blame^] | 169 | |
| 170 | // Check for AR register defines |
| 171 | for (MachineInstr::const_mop_iterator I = SU->getInstr()->operands_begin(), |
| 172 | E = SU->getInstr()->operands_end(); |
| 173 | I != E; ++I) { |
| 174 | if (I->isReg() && I->getReg() == AMDGPU::AR_X) { |
| 175 | if (I->isDef()) { |
| 176 | UnscheduledARDefs.push_back(SU); |
| 177 | } else { |
| 178 | UnscheduledARUses.push_back(SU); |
| 179 | } |
| 180 | return; |
| 181 | } |
| 182 | } |
| 183 | |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 184 | // There is no export clause, we can schedule one as soon as its ready |
| 185 | if (IK == IDOther) |
| 186 | Available[IDOther].push_back(SU); |
| 187 | else |
| 188 | Pending[IK].push_back(SU); |
| 189 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | bool R600SchedStrategy::regBelongsToClass(unsigned Reg, |
| 193 | const TargetRegisterClass *RC) const { |
| 194 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 195 | return RC->contains(Reg); |
| 196 | } else { |
| 197 | return MRI->getRegClass(Reg) == RC; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | R600SchedStrategy::AluKind R600SchedStrategy::getAluKind(SUnit *SU) const { |
| 202 | MachineInstr *MI = SU->getInstr(); |
| 203 | |
| 204 | switch (MI->getOpcode()) { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 205 | case AMDGPU::PRED_X: |
| 206 | return AluPredX; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 207 | case AMDGPU::INTERP_PAIR_XY: |
| 208 | case AMDGPU::INTERP_PAIR_ZW: |
| 209 | case AMDGPU::INTERP_VEC_LOAD: |
Vincent Lejeune | 4ed9917 | 2013-05-17 16:50:32 +0000 | [diff] [blame] | 210 | case AMDGPU::DOT_4: |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 211 | return AluT_XYZW; |
| 212 | case AMDGPU::COPY: |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 213 | if (MI->getOperand(1).isUndef()) { |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 214 | // MI will become a KILL, don't considers it in scheduling |
| 215 | return AluDiscarded; |
| 216 | } |
| 217 | default: |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | // Does the instruction take a whole IG ? |
| 222 | if(TII->isVector(*MI) || |
| 223 | TII->isCubeOp(MI->getOpcode()) || |
| 224 | TII->isReductionOp(MI->getOpcode())) |
| 225 | return AluT_XYZW; |
| 226 | |
| 227 | // Is the result already assigned to a channel ? |
| 228 | unsigned DestSubReg = MI->getOperand(0).getSubReg(); |
| 229 | switch (DestSubReg) { |
| 230 | case AMDGPU::sub0: |
| 231 | return AluT_X; |
| 232 | case AMDGPU::sub1: |
| 233 | return AluT_Y; |
| 234 | case AMDGPU::sub2: |
| 235 | return AluT_Z; |
| 236 | case AMDGPU::sub3: |
| 237 | return AluT_W; |
| 238 | default: |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | // Is the result already member of a X/Y/Z/W class ? |
| 243 | unsigned DestReg = MI->getOperand(0).getReg(); |
| 244 | if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_XRegClass) || |
| 245 | regBelongsToClass(DestReg, &AMDGPU::R600_AddrRegClass)) |
| 246 | return AluT_X; |
| 247 | if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_YRegClass)) |
| 248 | return AluT_Y; |
| 249 | if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_ZRegClass)) |
| 250 | return AluT_Z; |
| 251 | if (regBelongsToClass(DestReg, &AMDGPU::R600_TReg32_WRegClass)) |
| 252 | return AluT_W; |
| 253 | if (regBelongsToClass(DestReg, &AMDGPU::R600_Reg128RegClass)) |
| 254 | return AluT_XYZW; |
| 255 | |
| 256 | return AluAny; |
| 257 | |
| 258 | } |
| 259 | |
| 260 | int R600SchedStrategy::getInstKind(SUnit* SU) { |
| 261 | int Opcode = SU->getInstr()->getOpcode(); |
| 262 | |
Vincent Lejeune | f63f85a | 2013-05-17 16:50:37 +0000 | [diff] [blame] | 263 | if (TII->usesTextureCache(Opcode) || TII->usesVertexCache(Opcode)) |
| 264 | return IDFetch; |
| 265 | |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 266 | if (TII->isALUInstr(Opcode)) { |
| 267 | return IDAlu; |
| 268 | } |
| 269 | |
| 270 | switch (Opcode) { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 271 | case AMDGPU::PRED_X: |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 272 | case AMDGPU::COPY: |
| 273 | case AMDGPU::CONST_COPY: |
| 274 | case AMDGPU::INTERP_PAIR_XY: |
| 275 | case AMDGPU::INTERP_PAIR_ZW: |
| 276 | case AMDGPU::INTERP_VEC_LOAD: |
Vincent Lejeune | 4ed9917 | 2013-05-17 16:50:32 +0000 | [diff] [blame] | 277 | case AMDGPU::DOT_4: |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 278 | return IDAlu; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 279 | default: |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 280 | return IDOther; |
| 281 | } |
| 282 | } |
| 283 | |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 284 | SUnit *R600SchedStrategy::PopInst(std::vector<SUnit *> &Q) { |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 285 | if (Q.empty()) |
| 286 | return NULL; |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 287 | for (std::vector<SUnit *>::reverse_iterator It = Q.rbegin(), E = Q.rend(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 288 | It != E; ++It) { |
| 289 | SUnit *SU = *It; |
Vincent Lejeune | 3ab0ba3 | 2013-03-14 15:50:45 +0000 | [diff] [blame] | 290 | InstructionsGroupCandidate.push_back(SU->getInstr()); |
| 291 | if (TII->canBundle(InstructionsGroupCandidate)) { |
| 292 | InstructionsGroupCandidate.pop_back(); |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 293 | Q.erase((It + 1).base()); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 294 | return SU; |
Vincent Lejeune | 3ab0ba3 | 2013-03-14 15:50:45 +0000 | [diff] [blame] | 295 | } else { |
| 296 | InstructionsGroupCandidate.pop_back(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | return NULL; |
| 300 | } |
| 301 | |
| 302 | void R600SchedStrategy::LoadAlu() { |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 303 | std::vector<SUnit *> &QSrc = Pending[IDAlu]; |
| 304 | for (unsigned i = 0, e = QSrc.size(); i < e; ++i) { |
| 305 | AluKind AK = getAluKind(QSrc[i]); |
| 306 | AvailableAlus[AK].push_back(QSrc[i]); |
| 307 | } |
| 308 | QSrc.clear(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void R600SchedStrategy::PrepareNextSlot() { |
| 312 | DEBUG(dbgs() << "New Slot\n"); |
| 313 | assert (OccupedSlotsMask && "Slot wasn't filled"); |
| 314 | OccupedSlotsMask = 0; |
Vincent Lejeune | 3ab0ba3 | 2013-03-14 15:50:45 +0000 | [diff] [blame] | 315 | InstructionsGroupCandidate.clear(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 316 | LoadAlu(); |
| 317 | } |
| 318 | |
| 319 | void R600SchedStrategy::AssignSlot(MachineInstr* MI, unsigned Slot) { |
| 320 | unsigned DestReg = MI->getOperand(0).getReg(); |
| 321 | // PressureRegister crashes if an operand is def and used in the same inst |
| 322 | // and we try to constraint its regclass |
| 323 | for (MachineInstr::mop_iterator It = MI->operands_begin(), |
| 324 | E = MI->operands_end(); It != E; ++It) { |
| 325 | MachineOperand &MO = *It; |
| 326 | if (MO.isReg() && !MO.isDef() && |
| 327 | MO.getReg() == MI->getOperand(0).getReg()) |
| 328 | return; |
| 329 | } |
| 330 | // Constrains the regclass of DestReg to assign it to Slot |
| 331 | switch (Slot) { |
| 332 | case 0: |
| 333 | MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_XRegClass); |
| 334 | break; |
| 335 | case 1: |
| 336 | MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_YRegClass); |
| 337 | break; |
| 338 | case 2: |
| 339 | MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_ZRegClass); |
| 340 | break; |
| 341 | case 3: |
| 342 | MRI->constrainRegClass(DestReg, &AMDGPU::R600_TReg32_WRegClass); |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | SUnit *R600SchedStrategy::AttemptFillSlot(unsigned Slot) { |
| 348 | static const AluKind IndexToID[] = {AluT_X, AluT_Y, AluT_Z, AluT_W}; |
| 349 | SUnit *SlotedSU = PopInst(AvailableAlus[IndexToID[Slot]]); |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 350 | if (SlotedSU) |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 351 | return SlotedSU; |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 352 | SUnit *UnslotedSU = PopInst(AvailableAlus[AluAny]); |
| 353 | if (UnslotedSU) |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 354 | AssignSlot(UnslotedSU->getInstr(), Slot); |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 355 | return UnslotedSU; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | bool R600SchedStrategy::isAvailablesAluEmpty() const { |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 359 | return Pending[IDAlu].empty() && AvailableAlus[AluAny].empty() && |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 360 | AvailableAlus[AluT_XYZW].empty() && AvailableAlus[AluT_X].empty() && |
| 361 | AvailableAlus[AluT_Y].empty() && AvailableAlus[AluT_Z].empty() && |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 362 | AvailableAlus[AluT_W].empty() && AvailableAlus[AluDiscarded].empty() && |
| 363 | AvailableAlus[AluPredX].empty(); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | SUnit* R600SchedStrategy::pickAlu() { |
| 367 | while (!isAvailablesAluEmpty()) { |
| 368 | if (!OccupedSlotsMask) { |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 369 | // Bottom up scheduling : predX must comes first |
| 370 | if (!AvailableAlus[AluPredX].empty()) { |
| 371 | OccupedSlotsMask = 15; |
| 372 | return PopInst(AvailableAlus[AluPredX]); |
| 373 | } |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 374 | // Flush physical reg copies (RA will discard them) |
| 375 | if (!AvailableAlus[AluDiscarded].empty()) { |
| 376 | OccupedSlotsMask = 15; |
| 377 | return PopInst(AvailableAlus[AluDiscarded]); |
| 378 | } |
| 379 | // If there is a T_XYZW alu available, use it |
| 380 | if (!AvailableAlus[AluT_XYZW].empty()) { |
| 381 | OccupedSlotsMask = 15; |
| 382 | return PopInst(AvailableAlus[AluT_XYZW]); |
| 383 | } |
| 384 | } |
Vincent Lejeune | 76fc2d0 | 2013-05-17 16:50:56 +0000 | [diff] [blame] | 385 | for (int Chan = 3; Chan > -1; --Chan) { |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 386 | bool isOccupied = OccupedSlotsMask & (1 << Chan); |
| 387 | if (!isOccupied) { |
| 388 | SUnit *SU = AttemptFillSlot(Chan); |
| 389 | if (SU) { |
| 390 | OccupedSlotsMask |= (1 << Chan); |
Vincent Lejeune | 3ab0ba3 | 2013-03-14 15:50:45 +0000 | [diff] [blame] | 391 | InstructionsGroupCandidate.push_back(SU->getInstr()); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 392 | return SU; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | PrepareNextSlot(); |
| 397 | } |
| 398 | return NULL; |
| 399 | } |
| 400 | |
| 401 | SUnit* R600SchedStrategy::pickOther(int QID) { |
| 402 | SUnit *SU = 0; |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 403 | std::vector<SUnit *> &AQ = Available[QID]; |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 404 | |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 405 | if (AQ.empty()) { |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 406 | MoveUnits(Pending[QID], AQ); |
| 407 | } |
Vincent Lejeune | 21ca0b3 | 2013-05-17 16:50:44 +0000 | [diff] [blame] | 408 | if (!AQ.empty()) { |
| 409 | SU = AQ.back(); |
| 410 | AQ.resize(AQ.size() - 1); |
Vincent Lejeune | 62f38ca | 2013-03-05 18:41:32 +0000 | [diff] [blame] | 411 | } |
| 412 | return SU; |
| 413 | } |
| 414 | |