~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to lib/Target/R600/R600MachineScheduler.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#define DEBUG_TYPE "misched"
17
17
 
18
18
#include "R600MachineScheduler.h"
 
19
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
19
20
#include "llvm/CodeGen/MachineRegisterInfo.h"
20
 
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
21
21
#include "llvm/Pass.h"
22
22
#include "llvm/PassManager.h"
23
23
#include "llvm/Support/raw_ostream.h"
24
 
#include <set>
25
24
 
26
25
using namespace llvm;
27
26
 
31
30
  TII = static_cast<const R600InstrInfo*>(DAG->TII);
32
31
  TRI = static_cast<const R600RegisterInfo*>(DAG->TRI);
33
32
  MRI = &DAG->MRI;
34
 
  Available[IDAlu]->clear();
35
 
  Available[IDFetch]->clear();
36
 
  Available[IDOther]->clear();
37
33
  CurInstKind = IDOther;
38
34
  CurEmitted = 0;
39
35
  OccupedSlotsMask = 15;
40
36
  InstKindLimit[IDAlu] = TII->getMaxAlusPerClause();
41
 
 
 
37
  InstKindLimit[IDOther] = 32;
42
38
 
43
39
  const AMDGPUSubtarget &ST = DAG->TM.getSubtarget<AMDGPUSubtarget>();
44
 
  if (ST.device()->getGeneration() <= AMDGPUDeviceInfo::HD5XXX) {
45
 
    InstKindLimit[IDFetch] = 7; // 8 minus 1 for security
46
 
  } else {
47
 
    InstKindLimit[IDFetch] = 15; // 16 minus 1 for security
48
 
  }
 
40
  InstKindLimit[IDFetch] = ST.getTexVTXClauseSize();
49
41
}
50
42
 
51
 
void R600SchedStrategy::MoveUnits(ReadyQueue *QSrc, ReadyQueue *QDst)
 
43
void R600SchedStrategy::MoveUnits(std::vector<SUnit *> &QSrc,
 
44
                                  std::vector<SUnit *> &QDst)
52
45
{
53
 
  if (QSrc->empty())
54
 
    return;
55
 
  for (ReadyQueue::iterator I = QSrc->begin(),
56
 
      E = QSrc->end(); I != E; ++I) {
57
 
    (*I)->NodeQueueId &= ~QSrc->getID();
58
 
    QDst->push(*I);
59
 
  }
60
 
  QSrc->clear();
 
46
  QDst.insert(QDst.end(), QSrc.begin(), QSrc.end());
 
47
  QSrc.clear();
61
48
}
62
49
 
63
50
SUnit* R600SchedStrategy::pickNode(bool &IsTopNode) {
64
51
  SUnit *SU = 0;
65
 
  IsTopNode = true;
66
52
  NextInstKind = IDOther;
67
53
 
 
54
  IsTopNode = false;
 
55
 
68
56
  // check if we might want to switch current clause type
69
 
  bool AllowSwitchToAlu = (CurInstKind == IDOther) ||
70
 
      (CurEmitted > InstKindLimit[CurInstKind]) ||
71
 
      (Available[CurInstKind]->empty());
72
 
  bool AllowSwitchFromAlu = (CurEmitted > InstKindLimit[CurInstKind]) &&
73
 
      (!Available[IDFetch]->empty() || !Available[IDOther]->empty());
 
57
  bool AllowSwitchToAlu = (CurEmitted >= InstKindLimit[CurInstKind]) ||
 
58
      (Available[CurInstKind].empty());
 
59
  bool AllowSwitchFromAlu = (CurEmitted >= InstKindLimit[CurInstKind]) &&
 
60
      (!Available[IDFetch].empty() || !Available[IDOther].empty());
74
61
 
75
62
  if ((AllowSwitchToAlu && CurInstKind != IDAlu) ||
76
63
      (!AllowSwitchFromAlu && CurInstKind == IDAlu)) {
77
64
    // try to pick ALU
78
65
    SU = pickAlu();
79
66
    if (SU) {
80
 
      if (CurEmitted >  InstKindLimit[IDAlu])
 
67
      if (CurEmitted >= InstKindLimit[IDAlu])
81
68
        CurEmitted = 0;
82
69
      NextInstKind = IDAlu;
83
70
    }
99
86
 
100
87
  DEBUG(
101
88
      if (SU) {
102
 
        dbgs() << "picked node: ";
 
89
        dbgs() << " ** Pick node **\n";
103
90
        SU->dump(DAG);
104
91
      } else {
105
 
        dbgs() << "NO NODE ";
106
 
        for (int i = 0; i < IDLast; ++i) {
107
 
          Available[i]->dump();
108
 
          Pending[i]->dump();
109
 
        }
 
92
        dbgs() << "NO NODE \n";
110
93
        for (unsigned i = 0; i < DAG->SUnits.size(); i++) {
111
94
          const SUnit &S = DAG->SUnits[i];
112
95
          if (!S.isScheduled)
120
103
 
121
104
void R600SchedStrategy::schedNode(SUnit *SU, bool IsTopNode) {
122
105
 
123
 
  DEBUG(dbgs() << "scheduled: ");
124
 
  DEBUG(SU->dump(DAG));
125
 
 
126
106
  if (NextInstKind != CurInstKind) {
127
107
    DEBUG(dbgs() << "Instruction Type Switch\n");
128
108
    if (NextInstKind != IDAlu)
158
138
  if (CurInstKind != IDFetch) {
159
139
    MoveUnits(Pending[IDFetch], Available[IDFetch]);
160
140
  }
161
 
  MoveUnits(Pending[IDOther], Available[IDOther]);
162
141
}
163
142
 
164
143
void R600SchedStrategy::releaseTopNode(SUnit *SU) {
 
144
  DEBUG(dbgs() << "Top Releasing ";SU->dump(DAG););
 
145
 
 
146
}
 
147
 
 
148
void R600SchedStrategy::releaseBottomNode(SUnit *SU) {
 
149
  DEBUG(dbgs() << "Bottom Releasing ";SU->dump(DAG););
 
150
 
165
151
  int IK = getInstKind(SU);
166
 
 
167
 
  DEBUG(dbgs() << IK << " <= ");
168
 
  DEBUG(SU->dump(DAG));
169
 
 
170
 
  Pending[IK]->push(SU);
171
 
}
172
 
 
173
 
void R600SchedStrategy::releaseBottomNode(SUnit *SU) {
 
152
  // There is no export clause, we can schedule one as soon as its ready
 
153
  if (IK == IDOther)
 
154
    Available[IDOther].push_back(SU);
 
155
  else
 
156
    Pending[IK].push_back(SU);
 
157
 
174
158
}
175
159
 
176
160
bool R600SchedStrategy::regBelongsToClass(unsigned Reg,
186
170
  MachineInstr *MI = SU->getInstr();
187
171
 
188
172
    switch (MI->getOpcode()) {
 
173
    case AMDGPU::PRED_X:
 
174
      return AluPredX;
189
175
    case AMDGPU::INTERP_PAIR_XY:
190
176
    case AMDGPU::INTERP_PAIR_ZW:
191
177
    case AMDGPU::INTERP_VEC_LOAD:
 
178
    case AMDGPU::DOT_4:
192
179
      return AluT_XYZW;
193
180
    case AMDGPU::COPY:
194
 
      if (TargetRegisterInfo::isPhysicalRegister(MI->getOperand(1).getReg())) {
195
 
        // %vregX = COPY Tn_X is likely to be discarded in favor of an
196
 
        // assignement of Tn_X to %vregX, don't considers it in scheduling
197
 
        return AluDiscarded;
198
 
      }
199
 
      else if (MI->getOperand(1).isUndef()) {
 
181
      if (MI->getOperand(1).isUndef()) {
200
182
        // MI will become a KILL, don't considers it in scheduling
201
183
        return AluDiscarded;
202
184
      }
246
228
int R600SchedStrategy::getInstKind(SUnit* SU) {
247
229
  int Opcode = SU->getInstr()->getOpcode();
248
230
 
 
231
  if (TII->usesTextureCache(Opcode) || TII->usesVertexCache(Opcode))
 
232
    return IDFetch;
 
233
 
249
234
  if (TII->isALUInstr(Opcode)) {
250
235
    return IDAlu;
251
236
  }
252
237
 
253
238
  switch (Opcode) {
 
239
  case AMDGPU::PRED_X:
254
240
  case AMDGPU::COPY:
255
241
  case AMDGPU::CONST_COPY:
256
242
  case AMDGPU::INTERP_PAIR_XY:
257
243
  case AMDGPU::INTERP_PAIR_ZW:
258
244
  case AMDGPU::INTERP_VEC_LOAD:
259
 
  case AMDGPU::DOT4_eg_pseudo:
260
 
  case AMDGPU::DOT4_r600_pseudo:
 
245
  case AMDGPU::DOT_4:
261
246
    return IDAlu;
262
 
  case AMDGPU::TEX_VTX_CONSTBUF:
263
 
  case AMDGPU::TEX_VTX_TEXBUF:
264
 
  case AMDGPU::TEX_LD:
265
 
  case AMDGPU::TEX_GET_TEXTURE_RESINFO:
266
 
  case AMDGPU::TEX_GET_GRADIENTS_H:
267
 
  case AMDGPU::TEX_GET_GRADIENTS_V:
268
 
  case AMDGPU::TEX_SET_GRADIENTS_H:
269
 
  case AMDGPU::TEX_SET_GRADIENTS_V:
270
 
  case AMDGPU::TEX_SAMPLE:
271
 
  case AMDGPU::TEX_SAMPLE_C:
272
 
  case AMDGPU::TEX_SAMPLE_L:
273
 
  case AMDGPU::TEX_SAMPLE_C_L:
274
 
  case AMDGPU::TEX_SAMPLE_LB:
275
 
  case AMDGPU::TEX_SAMPLE_C_LB:
276
 
  case AMDGPU::TEX_SAMPLE_G:
277
 
  case AMDGPU::TEX_SAMPLE_C_G:
278
 
  case AMDGPU::TXD:
279
 
  case AMDGPU::TXD_SHADOW:
280
 
    return IDFetch;
281
247
  default:
282
 
    DEBUG(
283
 
        dbgs() << "other inst: ";
284
 
        SU->dump(DAG);
285
 
    );
286
248
    return IDOther;
287
249
  }
288
250
}
289
251
 
290
 
SUnit *R600SchedStrategy::PopInst(std::multiset<SUnit *, CompareSUnit> &Q) {
 
252
SUnit *R600SchedStrategy::PopInst(std::vector<SUnit *> &Q) {
291
253
  if (Q.empty())
292
254
    return NULL;
293
 
  for (std::set<SUnit *, CompareSUnit>::iterator It = Q.begin(), E = Q.end();
 
255
  for (std::vector<SUnit *>::reverse_iterator It = Q.rbegin(), E = Q.rend();
294
256
      It != E; ++It) {
295
257
    SUnit *SU = *It;
296
258
    InstructionsGroupCandidate.push_back(SU->getInstr());
297
259
    if (TII->canBundle(InstructionsGroupCandidate)) {
298
260
      InstructionsGroupCandidate.pop_back();
299
 
      Q.erase(It);
 
261
      Q.erase((It + 1).base());
300
262
      return SU;
301
263
    } else {
302
264
      InstructionsGroupCandidate.pop_back();
306
268
}
307
269
 
308
270
void R600SchedStrategy::LoadAlu() {
309
 
  ReadyQueue *QSrc = Pending[IDAlu];
310
 
  for (ReadyQueue::iterator I = QSrc->begin(),
311
 
        E = QSrc->end(); I != E; ++I) {
312
 
      (*I)->NodeQueueId &= ~QSrc->getID();
313
 
      AluKind AK = getAluKind(*I);
314
 
      AvailableAlus[AK].insert(*I);
315
 
    }
316
 
    QSrc->clear();
 
271
  std::vector<SUnit *> &QSrc = Pending[IDAlu];
 
272
  for (unsigned i = 0, e = QSrc.size(); i < e; ++i) {
 
273
    AluKind AK = getAluKind(QSrc[i]);
 
274
    AvailableAlus[AK].push_back(QSrc[i]);
 
275
  }
 
276
  QSrc.clear();
317
277
}
318
278
 
319
279
void R600SchedStrategy::PrepareNextSlot() {
355
315
SUnit *R600SchedStrategy::AttemptFillSlot(unsigned Slot) {
356
316
  static const AluKind IndexToID[] = {AluT_X, AluT_Y, AluT_Z, AluT_W};
357
317
  SUnit *SlotedSU = PopInst(AvailableAlus[IndexToID[Slot]]);
 
318
  if (SlotedSU)
 
319
    return SlotedSU;
358
320
  SUnit *UnslotedSU = PopInst(AvailableAlus[AluAny]);
359
 
  if (!UnslotedSU) {
360
 
    return SlotedSU;
361
 
  } else if (!SlotedSU) {
 
321
  if (UnslotedSU)
362
322
    AssignSlot(UnslotedSU->getInstr(), Slot);
363
 
    return UnslotedSU;
364
 
  } else {
365
 
    //Determine which one to pick (the lesser one)
366
 
    if (CompareSUnit()(SlotedSU, UnslotedSU)) {
367
 
      AvailableAlus[AluAny].insert(UnslotedSU);
368
 
      return SlotedSU;
369
 
    } else {
370
 
      AvailableAlus[IndexToID[Slot]].insert(SlotedSU);
371
 
      AssignSlot(UnslotedSU->getInstr(), Slot);
372
 
      return UnslotedSU;
373
 
    }
374
 
  }
 
323
  return UnslotedSU;
375
324
}
376
325
 
377
326
bool R600SchedStrategy::isAvailablesAluEmpty() const {
378
 
  return Pending[IDAlu]->empty() && AvailableAlus[AluAny].empty() &&
 
327
  return Pending[IDAlu].empty() && AvailableAlus[AluAny].empty() &&
379
328
      AvailableAlus[AluT_XYZW].empty() && AvailableAlus[AluT_X].empty() &&
380
329
      AvailableAlus[AluT_Y].empty() && AvailableAlus[AluT_Z].empty() &&
381
 
      AvailableAlus[AluT_W].empty() && AvailableAlus[AluDiscarded].empty();
 
330
      AvailableAlus[AluT_W].empty() && AvailableAlus[AluDiscarded].empty() &&
 
331
      AvailableAlus[AluPredX].empty();
382
332
}
383
333
 
384
334
SUnit* R600SchedStrategy::pickAlu() {
385
335
  while (!isAvailablesAluEmpty()) {
386
336
    if (!OccupedSlotsMask) {
 
337
      // Bottom up scheduling : predX must comes first
 
338
      if (!AvailableAlus[AluPredX].empty()) {
 
339
        OccupedSlotsMask = 15;
 
340
        return PopInst(AvailableAlus[AluPredX]);
 
341
      }
387
342
      // Flush physical reg copies (RA will discard them)
388
343
      if (!AvailableAlus[AluDiscarded].empty()) {
389
344
        OccupedSlotsMask = 15;
395
350
        return PopInst(AvailableAlus[AluT_XYZW]);
396
351
      }
397
352
    }
398
 
    for (unsigned Chan = 0; Chan < 4; ++Chan) {
 
353
    for (int Chan = 3; Chan > -1; --Chan) {
399
354
      bool isOccupied = OccupedSlotsMask & (1 << Chan);
400
355
      if (!isOccupied) {
401
356
        SUnit *SU = AttemptFillSlot(Chan);
413
368
 
414
369
SUnit* R600SchedStrategy::pickOther(int QID) {
415
370
  SUnit *SU = 0;
416
 
  ReadyQueue *AQ = Available[QID];
 
371
  std::vector<SUnit *> &AQ = Available[QID];
417
372
 
418
 
  if (AQ->empty()) {
 
373
  if (AQ.empty()) {
419
374
    MoveUnits(Pending[QID], AQ);
420
375
  }
421
 
  if (!AQ->empty()) {
422
 
    SU = *AQ->begin();
423
 
    AQ->remove(AQ->begin());
 
376
  if (!AQ.empty()) {
 
377
    SU = AQ.back();
 
378
    AQ.resize(AQ.size() - 1);
424
379
  }
425
380
  return SU;
426
381
}