nv50/ir: change the way float face is returned
[mesa.git] / src / gallium / drivers / nouveau / codegen / nv50_ir_lowering_nvc0.cpp
1 /*
2 * Copyright 2011 Christoph Bumiller
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 #include "codegen/nv50_ir.h"
24 #include "codegen/nv50_ir_build_util.h"
25
26 #include "codegen/nv50_ir_target_nvc0.h"
27 #include "codegen/nv50_ir_lowering_nvc0.h"
28
29 #include <limits>
30
31 namespace nv50_ir {
32
33 #define QOP_ADD 0
34 #define QOP_SUBR 1
35 #define QOP_SUB 2
36 #define QOP_MOV2 3
37
38 // UL UR LL LR
39 #define QUADOP(q, r, s, t) \
40 ((QOP_##q << 6) | (QOP_##r << 4) | \
41 (QOP_##s << 2) | (QOP_##t << 0))
42
43 void
44 NVC0LegalizeSSA::handleDIV(Instruction *i)
45 {
46 FlowInstruction *call;
47 int builtin;
48 Value *def[2];
49
50 bld.setPosition(i, false);
51 def[0] = bld.mkMovToReg(0, i->getSrc(0))->getDef(0);
52 def[1] = bld.mkMovToReg(1, i->getSrc(1))->getDef(0);
53 switch (i->dType) {
54 case TYPE_U32: builtin = NVC0_BUILTIN_DIV_U32; break;
55 case TYPE_S32: builtin = NVC0_BUILTIN_DIV_S32; break;
56 default:
57 return;
58 }
59 call = bld.mkFlow(OP_CALL, NULL, CC_ALWAYS, NULL);
60 bld.mkMov(i->getDef(0), def[(i->op == OP_DIV) ? 0 : 1]);
61 bld.mkClobber(FILE_GPR, (i->op == OP_DIV) ? 0xe : 0xd, 2);
62 bld.mkClobber(FILE_PREDICATE, (i->dType == TYPE_S32) ? 0xf : 0x3, 0);
63
64 call->fixed = 1;
65 call->absolute = call->builtin = 1;
66 call->target.builtin = builtin;
67 delete_Instruction(prog, i);
68 }
69
70 void
71 NVC0LegalizeSSA::handleRCPRSQ(Instruction *i)
72 {
73 // TODO
74 }
75
76 bool
77 NVC0LegalizeSSA::visit(Function *fn)
78 {
79 bld.setProgram(fn->getProgram());
80 return true;
81 }
82
83 bool
84 NVC0LegalizeSSA::visit(BasicBlock *bb)
85 {
86 Instruction *next;
87 for (Instruction *i = bb->getEntry(); i; i = next) {
88 next = i->next;
89 if (i->dType == TYPE_F32)
90 continue;
91 switch (i->op) {
92 case OP_DIV:
93 case OP_MOD:
94 handleDIV(i);
95 break;
96 case OP_RCP:
97 case OP_RSQ:
98 if (i->dType == TYPE_F64)
99 handleRCPRSQ(i);
100 break;
101 default:
102 break;
103 }
104 }
105 return true;
106 }
107
108 NVC0LegalizePostRA::NVC0LegalizePostRA(const Program *prog)
109 : rZero(NULL),
110 carry(NULL),
111 needTexBar(prog->getTarget()->getChipset() >= 0xe0)
112 {
113 }
114
115 bool
116 NVC0LegalizePostRA::insnDominatedBy(const Instruction *later,
117 const Instruction *early) const
118 {
119 if (early->bb == later->bb)
120 return early->serial < later->serial;
121 return later->bb->dominatedBy(early->bb);
122 }
123
124 void
125 NVC0LegalizePostRA::addTexUse(std::list<TexUse> &uses,
126 Instruction *usei, const Instruction *insn)
127 {
128 bool add = true;
129 for (std::list<TexUse>::iterator it = uses.begin();
130 it != uses.end();) {
131 if (insnDominatedBy(usei, it->insn)) {
132 add = false;
133 break;
134 }
135 if (insnDominatedBy(it->insn, usei))
136 it = uses.erase(it);
137 else
138 ++it;
139 }
140 if (add)
141 uses.push_back(TexUse(usei, insn));
142 }
143
144 void
145 NVC0LegalizePostRA::findOverwritingDefs(const Instruction *texi,
146 Instruction *insn,
147 const BasicBlock *term,
148 std::list<TexUse> &uses)
149 {
150 while (insn->op == OP_MOV && insn->getDef(0)->equals(insn->getSrc(0)))
151 insn = insn->getSrc(0)->getUniqueInsn();
152
153 if (!insn->bb->reachableBy(texi->bb, term))
154 return;
155
156 switch (insn->op) {
157 /* Values not connected to the tex's definition through any of these should
158 * not be conflicting.
159 */
160 case OP_SPLIT:
161 case OP_MERGE:
162 case OP_PHI:
163 case OP_UNION:
164 /* recurse again */
165 for (int s = 0; insn->srcExists(s); ++s)
166 findOverwritingDefs(texi, insn->getSrc(s)->getUniqueInsn(), term,
167 uses);
168 break;
169 default:
170 // if (!isTextureOp(insn->op)) // TODO: are TEXes always ordered ?
171 addTexUse(uses, insn, texi);
172 break;
173 }
174 }
175
176 void
177 NVC0LegalizePostRA::findFirstUses(
178 const Instruction *texi,
179 const Instruction *insn,
180 std::list<TexUse> &uses,
181 std::tr1::unordered_set<const Instruction *>& visited)
182 {
183 for (int d = 0; insn->defExists(d); ++d) {
184 Value *v = insn->getDef(d);
185 for (Value::UseIterator u = v->uses.begin(); u != v->uses.end(); ++u) {
186 Instruction *usei = (*u)->getInsn();
187
188 // NOTE: In case of a loop that overwrites a value but never uses
189 // it, it can happen that we have a cycle of uses that consists only
190 // of phis and no-op moves and will thus cause an infinite loop here
191 // since these are not considered actual uses.
192 // The most obvious (and perhaps the only) way to prevent this is to
193 // remember which instructions we've already visited.
194
195 if (visited.find(usei) != visited.end())
196 continue;
197
198 visited.insert(usei);
199
200 if (usei->op == OP_PHI || usei->op == OP_UNION) {
201 // need a barrier before WAW cases
202 for (int s = 0; usei->srcExists(s); ++s) {
203 Instruction *defi = usei->getSrc(s)->getUniqueInsn();
204 if (defi && &usei->src(s) != *u)
205 findOverwritingDefs(texi, defi, usei->bb, uses);
206 }
207 }
208
209 if (usei->op == OP_SPLIT ||
210 usei->op == OP_MERGE ||
211 usei->op == OP_PHI ||
212 usei->op == OP_UNION) {
213 // these uses don't manifest in the machine code
214 findFirstUses(texi, usei, uses, visited);
215 } else
216 if (usei->op == OP_MOV && usei->getDef(0)->equals(usei->getSrc(0)) &&
217 usei->subOp != NV50_IR_SUBOP_MOV_FINAL) {
218 findFirstUses(texi, usei, uses, visited);
219 } else {
220 addTexUse(uses, usei, insn);
221 }
222 }
223 }
224 }
225
226 // Texture barriers:
227 // This pass is a bit long and ugly and can probably be optimized.
228 //
229 // 1. obtain a list of TEXes and their outputs' first use(s)
230 // 2. calculate the barrier level of each first use (minimal number of TEXes,
231 // over all paths, between the TEX and the use in question)
232 // 3. for each barrier, if all paths from the source TEX to that barrier
233 // contain a barrier of lesser level, it can be culled
234 bool
235 NVC0LegalizePostRA::insertTextureBarriers(Function *fn)
236 {
237 std::list<TexUse> *uses;
238 std::vector<Instruction *> texes;
239 std::vector<int> bbFirstTex;
240 std::vector<int> bbFirstUse;
241 std::vector<int> texCounts;
242 std::vector<TexUse> useVec;
243 ArrayList insns;
244
245 fn->orderInstructions(insns);
246
247 texCounts.resize(fn->allBBlocks.getSize(), 0);
248 bbFirstTex.resize(fn->allBBlocks.getSize(), insns.getSize());
249 bbFirstUse.resize(fn->allBBlocks.getSize(), insns.getSize());
250
251 // tag BB CFG nodes by their id for later
252 for (ArrayList::Iterator i = fn->allBBlocks.iterator(); !i.end(); i.next()) {
253 BasicBlock *bb = reinterpret_cast<BasicBlock *>(i.get());
254 if (bb)
255 bb->cfg.tag = bb->getId();
256 }
257
258 // gather the first uses for each TEX
259 for (int i = 0; i < insns.getSize(); ++i) {
260 Instruction *tex = reinterpret_cast<Instruction *>(insns.get(i));
261 if (isTextureOp(tex->op)) {
262 texes.push_back(tex);
263 if (!texCounts.at(tex->bb->getId()))
264 bbFirstTex[tex->bb->getId()] = texes.size() - 1;
265 texCounts[tex->bb->getId()]++;
266 }
267 }
268 insns.clear();
269 if (texes.empty())
270 return false;
271 uses = new std::list<TexUse>[texes.size()];
272 if (!uses)
273 return false;
274 for (size_t i = 0; i < texes.size(); ++i) {
275 std::tr1::unordered_set<const Instruction *> visited;
276 findFirstUses(texes[i], texes[i], uses[i], visited);
277 }
278
279 // determine the barrier level at each use
280 for (size_t i = 0; i < texes.size(); ++i) {
281 for (std::list<TexUse>::iterator u = uses[i].begin(); u != uses[i].end();
282 ++u) {
283 BasicBlock *tb = texes[i]->bb;
284 BasicBlock *ub = u->insn->bb;
285 if (tb == ub) {
286 u->level = 0;
287 for (size_t j = i + 1; j < texes.size() &&
288 texes[j]->bb == tb && texes[j]->serial < u->insn->serial;
289 ++j)
290 u->level++;
291 } else {
292 u->level = fn->cfg.findLightestPathWeight(&tb->cfg,
293 &ub->cfg, texCounts);
294 if (u->level < 0) {
295 WARN("Failed to find path TEX -> TEXBAR\n");
296 u->level = 0;
297 continue;
298 }
299 // this counted all TEXes in the origin block, correct that
300 u->level -= i - bbFirstTex.at(tb->getId()) + 1 /* this TEX */;
301 // and did not count the TEXes in the destination block, add those
302 for (size_t j = bbFirstTex.at(ub->getId()); j < texes.size() &&
303 texes[j]->bb == ub && texes[j]->serial < u->insn->serial;
304 ++j)
305 u->level++;
306 }
307 assert(u->level >= 0);
308 useVec.push_back(*u);
309 }
310 }
311 delete[] uses;
312
313 // insert the barriers
314 for (size_t i = 0; i < useVec.size(); ++i) {
315 Instruction *prev = useVec[i].insn->prev;
316 if (useVec[i].level < 0)
317 continue;
318 if (prev && prev->op == OP_TEXBAR) {
319 if (prev->subOp > useVec[i].level)
320 prev->subOp = useVec[i].level;
321 prev->setSrc(prev->srcCount(), useVec[i].tex->getDef(0));
322 } else {
323 Instruction *bar = new_Instruction(func, OP_TEXBAR, TYPE_NONE);
324 bar->fixed = 1;
325 bar->subOp = useVec[i].level;
326 // make use explicit to ease latency calculation
327 bar->setSrc(bar->srcCount(), useVec[i].tex->getDef(0));
328 useVec[i].insn->bb->insertBefore(useVec[i].insn, bar);
329 }
330 }
331
332 if (fn->getProgram()->optLevel < 3)
333 return true;
334
335 std::vector<Limits> limitT, limitB, limitS; // entry, exit, single
336
337 limitT.resize(fn->allBBlocks.getSize(), Limits(0, 0));
338 limitB.resize(fn->allBBlocks.getSize(), Limits(0, 0));
339 limitS.resize(fn->allBBlocks.getSize());
340
341 // cull unneeded barriers (should do that earlier, but for simplicity)
342 IteratorRef bi = fn->cfg.iteratorCFG();
343 // first calculate min/max outstanding TEXes for each BB
344 for (bi->reset(); !bi->end(); bi->next()) {
345 Graph::Node *n = reinterpret_cast<Graph::Node *>(bi->get());
346 BasicBlock *bb = BasicBlock::get(n);
347 int min = 0;
348 int max = std::numeric_limits<int>::max();
349 for (Instruction *i = bb->getFirst(); i; i = i->next) {
350 if (isTextureOp(i->op)) {
351 min++;
352 if (max < std::numeric_limits<int>::max())
353 max++;
354 } else
355 if (i->op == OP_TEXBAR) {
356 min = MIN2(min, i->subOp);
357 max = MIN2(max, i->subOp);
358 }
359 }
360 // limits when looking at an isolated block
361 limitS[bb->getId()].min = min;
362 limitS[bb->getId()].max = max;
363 }
364 // propagate the min/max values
365 for (unsigned int l = 0; l <= fn->loopNestingBound; ++l) {
366 for (bi->reset(); !bi->end(); bi->next()) {
367 Graph::Node *n = reinterpret_cast<Graph::Node *>(bi->get());
368 BasicBlock *bb = BasicBlock::get(n);
369 const int bbId = bb->getId();
370 for (Graph::EdgeIterator ei = n->incident(); !ei.end(); ei.next()) {
371 BasicBlock *in = BasicBlock::get(ei.getNode());
372 const int inId = in->getId();
373 limitT[bbId].min = MAX2(limitT[bbId].min, limitB[inId].min);
374 limitT[bbId].max = MAX2(limitT[bbId].max, limitB[inId].max);
375 }
376 // I just hope this is correct ...
377 if (limitS[bbId].max == std::numeric_limits<int>::max()) {
378 // no barrier
379 limitB[bbId].min = limitT[bbId].min + limitS[bbId].min;
380 limitB[bbId].max = limitT[bbId].max + limitS[bbId].min;
381 } else {
382 // block contained a barrier
383 limitB[bbId].min = MIN2(limitS[bbId].max,
384 limitT[bbId].min + limitS[bbId].min);
385 limitB[bbId].max = MIN2(limitS[bbId].max,
386 limitT[bbId].max + limitS[bbId].min);
387 }
388 }
389 }
390 // finally delete unnecessary barriers
391 for (bi->reset(); !bi->end(); bi->next()) {
392 Graph::Node *n = reinterpret_cast<Graph::Node *>(bi->get());
393 BasicBlock *bb = BasicBlock::get(n);
394 Instruction *prev = NULL;
395 Instruction *next;
396 int max = limitT[bb->getId()].max;
397 for (Instruction *i = bb->getFirst(); i; i = next) {
398 next = i->next;
399 if (i->op == OP_TEXBAR) {
400 if (i->subOp >= max) {
401 delete_Instruction(prog, i);
402 i = NULL;
403 } else {
404 max = i->subOp;
405 if (prev && prev->op == OP_TEXBAR && prev->subOp >= max) {
406 delete_Instruction(prog, prev);
407 prev = NULL;
408 }
409 }
410 } else
411 if (isTextureOp(i->op)) {
412 max++;
413 }
414 if (i && !i->isNop())
415 prev = i;
416 }
417 }
418 return true;
419 }
420
421 bool
422 NVC0LegalizePostRA::visit(Function *fn)
423 {
424 if (needTexBar)
425 insertTextureBarriers(fn);
426
427 rZero = new_LValue(fn, FILE_GPR);
428 carry = new_LValue(fn, FILE_FLAGS);
429
430 rZero->reg.data.id = prog->getTarget()->getFileSize(FILE_GPR);
431 carry->reg.data.id = 0;
432
433 return true;
434 }
435
436 void
437 NVC0LegalizePostRA::replaceZero(Instruction *i)
438 {
439 for (int s = 0; i->srcExists(s); ++s) {
440 if (s == 2 && i->op == OP_SUCLAMP)
441 continue;
442 ImmediateValue *imm = i->getSrc(s)->asImm();
443 if (imm && imm->reg.data.u64 == 0)
444 i->setSrc(s, rZero);
445 }
446 }
447
448 // replace CONT with BRA for single unconditional continue
449 bool
450 NVC0LegalizePostRA::tryReplaceContWithBra(BasicBlock *bb)
451 {
452 if (bb->cfg.incidentCount() != 2 || bb->getEntry()->op != OP_PRECONT)
453 return false;
454 Graph::EdgeIterator ei = bb->cfg.incident();
455 if (ei.getType() != Graph::Edge::BACK)
456 ei.next();
457 if (ei.getType() != Graph::Edge::BACK)
458 return false;
459 BasicBlock *contBB = BasicBlock::get(ei.getNode());
460
461 if (!contBB->getExit() || contBB->getExit()->op != OP_CONT ||
462 contBB->getExit()->getPredicate())
463 return false;
464 contBB->getExit()->op = OP_BRA;
465 bb->remove(bb->getEntry()); // delete PRECONT
466
467 ei.next();
468 assert(ei.end() || ei.getType() != Graph::Edge::BACK);
469 return true;
470 }
471
472 // replace branches to join blocks with join ops
473 void
474 NVC0LegalizePostRA::propagateJoin(BasicBlock *bb)
475 {
476 if (bb->getEntry()->op != OP_JOIN || bb->getEntry()->asFlow()->limit)
477 return;
478 for (Graph::EdgeIterator ei = bb->cfg.incident(); !ei.end(); ei.next()) {
479 BasicBlock *in = BasicBlock::get(ei.getNode());
480 Instruction *exit = in->getExit();
481 if (!exit) {
482 in->insertTail(new FlowInstruction(func, OP_JOIN, bb));
483 // there should always be a terminator instruction
484 WARN("inserted missing terminator in BB:%i\n", in->getId());
485 } else
486 if (exit->op == OP_BRA) {
487 exit->op = OP_JOIN;
488 exit->asFlow()->limit = 1; // must-not-propagate marker
489 }
490 }
491 bb->remove(bb->getEntry());
492 }
493
494 bool
495 NVC0LegalizePostRA::visit(BasicBlock *bb)
496 {
497 Instruction *i, *next;
498
499 // remove pseudo operations and non-fixed no-ops, split 64 bit operations
500 for (i = bb->getFirst(); i; i = next) {
501 next = i->next;
502 if (i->op == OP_EMIT || i->op == OP_RESTART) {
503 if (!i->getDef(0)->refCount())
504 i->setDef(0, NULL);
505 if (i->src(0).getFile() == FILE_IMMEDIATE)
506 i->setSrc(0, rZero); // initial value must be 0
507 replaceZero(i);
508 } else
509 if (i->isNop()) {
510 bb->remove(i);
511 } else {
512 // TODO: Move this to before register allocation for operations that
513 // need the $c register !
514 if (typeSizeof(i->dType) == 8) {
515 Instruction *hi;
516 hi = BuildUtil::split64BitOpPostRA(func, i, rZero, carry);
517 if (hi)
518 next = hi;
519 }
520
521 if (i->op != OP_MOV && i->op != OP_PFETCH)
522 replaceZero(i);
523 }
524 }
525 if (!bb->getEntry())
526 return true;
527
528 if (!tryReplaceContWithBra(bb))
529 propagateJoin(bb);
530
531 return true;
532 }
533
534 NVC0LoweringPass::NVC0LoweringPass(Program *prog) : targ(prog->getTarget())
535 {
536 bld.setProgram(prog);
537 gMemBase = NULL;
538 }
539
540 bool
541 NVC0LoweringPass::visit(Function *fn)
542 {
543 if (prog->getType() == Program::TYPE_GEOMETRY) {
544 assert(!strncmp(fn->getName(), "MAIN", 4));
545 // TODO: when we generate actual functions pass this value along somehow
546 bld.setPosition(BasicBlock::get(fn->cfg.getRoot()), false);
547 gpEmitAddress = bld.loadImm(NULL, 0)->asLValue();
548 if (fn->cfgExit) {
549 bld.setPosition(BasicBlock::get(fn->cfgExit)->getExit(), false);
550 bld.mkMovToReg(0, gpEmitAddress);
551 }
552 }
553 return true;
554 }
555
556 bool
557 NVC0LoweringPass::visit(BasicBlock *bb)
558 {
559 return true;
560 }
561
562 inline Value *
563 NVC0LoweringPass::loadTexHandle(Value *ptr, unsigned int slot)
564 {
565 uint8_t b = prog->driver->io.resInfoCBSlot;
566 uint32_t off = prog->driver->io.texBindBase + slot * 4;
567 return bld.
568 mkLoadv(TYPE_U32, bld.mkSymbol(FILE_MEMORY_CONST, b, TYPE_U32, off), ptr);
569 }
570
571 // move array source to first slot, convert to u16, add indirections
572 bool
573 NVC0LoweringPass::handleTEX(TexInstruction *i)
574 {
575 const int dim = i->tex.target.getDim() + i->tex.target.isCube();
576 const int arg = i->tex.target.getArgCount();
577 const int lyr = arg - (i->tex.target.isMS() ? 2 : 1);
578 const int chipset = prog->getTarget()->getChipset();
579
580 // Arguments to the TEX instruction are a little insane. Even though the
581 // encoding is identical between SM20 and SM30, the arguments mean
582 // different things between Fermi and Kepler+. A lot of arguments are
583 // optional based on flags passed to the instruction. This summarizes the
584 // order of things.
585 //
586 // Fermi:
587 // array/indirect
588 // coords
589 // sample
590 // lod bias
591 // depth compare
592 // offsets:
593 // - tg4: 8 bits each, either 2 (1 offset reg) or 8 (2 offset reg)
594 // - other: 4 bits each, single reg
595 //
596 // Kepler+:
597 // indirect handle
598 // array (+ offsets for txd in upper 16 bits)
599 // coords
600 // sample
601 // lod bias
602 // depth compare
603 // offsets (same as fermi, except txd which takes it with array)
604 //
605 // Maxwell (tex):
606 // array
607 // coords
608 // indirect handle
609 // sample
610 // lod bias
611 // depth compare
612 // offsets
613 //
614 // Maxwell (txd):
615 // indirect handle
616 // coords
617 // array + offsets
618 // derivatives
619
620 if (chipset >= NVISA_GK104_CHIPSET) {
621 if (i->tex.rIndirectSrc >= 0 || i->tex.sIndirectSrc >= 0) {
622 // XXX this ignores tsc, and assumes a 1:1 mapping
623 assert(i->tex.rIndirectSrc >= 0);
624 Value *hnd = loadTexHandle(
625 bld.mkOp2v(OP_SHL, TYPE_U32, bld.getSSA(),
626 i->getIndirectR(), bld.mkImm(2)),
627 i->tex.r);
628 i->tex.r = 0xff;
629 i->tex.s = 0x1f;
630 i->setIndirectR(hnd);
631 i->setIndirectS(NULL);
632 } else if (i->tex.r == i->tex.s) {
633 i->tex.r += prog->driver->io.texBindBase / 4;
634 i->tex.s = 0; // only a single cX[] value possible here
635 } else {
636 Value *hnd = bld.getScratch();
637 Value *rHnd = loadTexHandle(NULL, i->tex.r);
638 Value *sHnd = loadTexHandle(NULL, i->tex.s);
639
640 bld.mkOp3(OP_INSBF, TYPE_U32, hnd, rHnd, bld.mkImm(0x1400), sHnd);
641
642 i->tex.r = 0; // not used for indirect tex
643 i->tex.s = 0;
644 i->setIndirectR(hnd);
645 }
646 if (i->tex.target.isArray()) {
647 LValue *layer = new_LValue(func, FILE_GPR);
648 Value *src = i->getSrc(lyr);
649 const int sat = (i->op == OP_TXF) ? 1 : 0;
650 DataType sTy = (i->op == OP_TXF) ? TYPE_U32 : TYPE_F32;
651 bld.mkCvt(OP_CVT, TYPE_U16, layer, sTy, src)->saturate = sat;
652 if (i->op != OP_TXD || chipset < NVISA_GM107_CHIPSET) {
653 for (int s = dim; s >= 1; --s)
654 i->setSrc(s, i->getSrc(s - 1));
655 i->setSrc(0, layer);
656 } else {
657 i->setSrc(dim, layer);
658 }
659 }
660 // Move the indirect reference to the first place
661 if (i->tex.rIndirectSrc >= 0 && (
662 i->op == OP_TXD || chipset < NVISA_GM107_CHIPSET)) {
663 Value *hnd = i->getIndirectR();
664
665 i->setIndirectR(NULL);
666 i->moveSources(0, 1);
667 i->setSrc(0, hnd);
668 i->tex.rIndirectSrc = 0;
669 i->tex.sIndirectSrc = -1;
670 }
671 } else
672 // (nvc0) generate and move the tsc/tic/array source to the front
673 if (i->tex.target.isArray() || i->tex.rIndirectSrc >= 0 || i->tex.sIndirectSrc >= 0) {
674 LValue *src = new_LValue(func, FILE_GPR); // 0xttxsaaaa
675
676 Value *ticRel = i->getIndirectR();
677 Value *tscRel = i->getIndirectS();
678
679 if (ticRel) {
680 i->setSrc(i->tex.rIndirectSrc, NULL);
681 if (i->tex.r)
682 ticRel = bld.mkOp2v(OP_ADD, TYPE_U32, bld.getScratch(),
683 ticRel, bld.mkImm(i->tex.r));
684 }
685 if (tscRel) {
686 i->setSrc(i->tex.sIndirectSrc, NULL);
687 if (i->tex.s)
688 tscRel = bld.mkOp2v(OP_ADD, TYPE_U32, bld.getScratch(),
689 tscRel, bld.mkImm(i->tex.s));
690 }
691
692 Value *arrayIndex = i->tex.target.isArray() ? i->getSrc(lyr) : NULL;
693 for (int s = dim; s >= 1; --s)
694 i->setSrc(s, i->getSrc(s - 1));
695 i->setSrc(0, arrayIndex);
696
697 if (arrayIndex) {
698 int sat = (i->op == OP_TXF) ? 1 : 0;
699 DataType sTy = (i->op == OP_TXF) ? TYPE_U32 : TYPE_F32;
700 bld.mkCvt(OP_CVT, TYPE_U16, src, sTy, arrayIndex)->saturate = sat;
701 } else {
702 bld.loadImm(src, 0);
703 }
704
705 if (ticRel)
706 bld.mkOp3(OP_INSBF, TYPE_U32, src, ticRel, bld.mkImm(0x0917), src);
707 if (tscRel)
708 bld.mkOp3(OP_INSBF, TYPE_U32, src, tscRel, bld.mkImm(0x0710), src);
709
710 i->setSrc(0, src);
711 }
712
713 // For nvc0, the sample id has to be in the second operand, as the offset
714 // does. Right now we don't know how to pass both in, and this case can't
715 // happen with OpenGL. On nve0, the sample id is part of the texture
716 // coordinate argument.
717 assert(chipset >= NVISA_GK104_CHIPSET ||
718 !i->tex.useOffsets || !i->tex.target.isMS());
719
720 // offset is between lod and dc
721 if (i->tex.useOffsets) {
722 int n, c;
723 int s = i->srcCount(0xff, true);
724 if (i->op != OP_TXD || chipset < NVISA_GK104_CHIPSET) {
725 if (i->tex.target.isShadow())
726 s--;
727 if (i->srcExists(s)) // move potential predicate out of the way
728 i->moveSources(s, 1);
729 if (i->tex.useOffsets == 4 && i->srcExists(s + 1))
730 i->moveSources(s + 1, 1);
731 }
732 if (i->op == OP_TXG) {
733 // Either there is 1 offset, which goes into the 2 low bytes of the
734 // first source, or there are 4 offsets, which go into 2 sources (8
735 // values, 1 byte each).
736 Value *offs[2] = {NULL, NULL};
737 for (n = 0; n < i->tex.useOffsets; n++) {
738 for (c = 0; c < 2; ++c) {
739 if ((n % 2) == 0 && c == 0)
740 offs[n / 2] = i->offset[n][c].get();
741 else
742 bld.mkOp3(OP_INSBF, TYPE_U32,
743 offs[n / 2],
744 i->offset[n][c].get(),
745 bld.mkImm(0x800 | ((n * 16 + c * 8) % 32)),
746 offs[n / 2]);
747 }
748 }
749 i->setSrc(s, offs[0]);
750 if (offs[1])
751 i->setSrc(s + 1, offs[1]);
752 } else {
753 unsigned imm = 0;
754 assert(i->tex.useOffsets == 1);
755 for (c = 0; c < 3; ++c) {
756 ImmediateValue val;
757 if (!i->offset[0][c].getImmediate(val))
758 assert(!"non-immediate offset passed to non-TXG");
759 imm |= (val.reg.data.u32 & 0xf) << (c * 4);
760 }
761 if (i->op == OP_TXD && chipset >= NVISA_GK104_CHIPSET) {
762 // The offset goes into the upper 16 bits of the array index. So
763 // create it if it's not already there, and INSBF it if it already
764 // is.
765 s = (i->tex.rIndirectSrc >= 0) ? 1 : 0;
766 if (chipset >= NVISA_GM107_CHIPSET)
767 s += dim;
768 if (i->tex.target.isArray()) {
769 bld.mkOp3(OP_INSBF, TYPE_U32, i->getSrc(s),
770 bld.loadImm(NULL, imm), bld.mkImm(0xc10),
771 i->getSrc(s));
772 } else {
773 i->moveSources(s, 1);
774 i->setSrc(s, bld.loadImm(NULL, imm << 16));
775 }
776 } else {
777 i->setSrc(s, bld.loadImm(NULL, imm));
778 }
779 }
780 }
781
782 if (chipset >= NVISA_GK104_CHIPSET) {
783 //
784 // If TEX requires more than 4 sources, the 2nd register tuple must be
785 // aligned to 4, even if it consists of just a single 4-byte register.
786 //
787 // XXX HACK: We insert 0 sources to avoid the 5 or 6 regs case.
788 //
789 int s = i->srcCount(0xff, true);
790 if (s > 4 && s < 7) {
791 if (i->srcExists(s)) // move potential predicate out of the way
792 i->moveSources(s, 7 - s);
793 while (s < 7)
794 i->setSrc(s++, bld.loadImm(NULL, 0));
795 }
796 }
797
798 return true;
799 }
800
801 bool
802 NVC0LoweringPass::handleManualTXD(TexInstruction *i)
803 {
804 static const uint8_t qOps[4][2] =
805 {
806 { QUADOP(MOV2, ADD, MOV2, ADD), QUADOP(MOV2, MOV2, ADD, ADD) }, // l0
807 { QUADOP(SUBR, MOV2, SUBR, MOV2), QUADOP(MOV2, MOV2, ADD, ADD) }, // l1
808 { QUADOP(MOV2, ADD, MOV2, ADD), QUADOP(SUBR, SUBR, MOV2, MOV2) }, // l2
809 { QUADOP(SUBR, MOV2, SUBR, MOV2), QUADOP(SUBR, SUBR, MOV2, MOV2) }, // l3
810 };
811 Value *def[4][4];
812 Value *crd[3];
813 Instruction *tex;
814 Value *zero = bld.loadImm(bld.getSSA(), 0);
815 int l, c;
816 const int dim = i->tex.target.getDim();
817 const int array = i->tex.target.isArray();
818
819 i->op = OP_TEX; // no need to clone dPdx/dPdy later
820
821 for (c = 0; c < dim; ++c)
822 crd[c] = bld.getScratch();
823
824 bld.mkOp(OP_QUADON, TYPE_NONE, NULL);
825 for (l = 0; l < 4; ++l) {
826 // mov coordinates from lane l to all lanes
827 for (c = 0; c < dim; ++c)
828 bld.mkQuadop(0x00, crd[c], l, i->getSrc(c + array), zero);
829 // add dPdx from lane l to lanes dx
830 for (c = 0; c < dim; ++c)
831 bld.mkQuadop(qOps[l][0], crd[c], l, i->dPdx[c].get(), crd[c]);
832 // add dPdy from lane l to lanes dy
833 for (c = 0; c < dim; ++c)
834 bld.mkQuadop(qOps[l][1], crd[c], l, i->dPdy[c].get(), crd[c]);
835 // texture
836 bld.insert(tex = cloneForward(func, i));
837 for (c = 0; c < dim; ++c)
838 tex->setSrc(c + array, crd[c]);
839 // save results
840 for (c = 0; i->defExists(c); ++c) {
841 Instruction *mov;
842 def[c][l] = bld.getSSA();
843 mov = bld.mkMov(def[c][l], tex->getDef(c));
844 mov->fixed = 1;
845 mov->lanes = 1 << l;
846 }
847 }
848 bld.mkOp(OP_QUADPOP, TYPE_NONE, NULL);
849
850 for (c = 0; i->defExists(c); ++c) {
851 Instruction *u = bld.mkOp(OP_UNION, TYPE_U32, i->getDef(c));
852 for (l = 0; l < 4; ++l)
853 u->setSrc(l, def[c][l]);
854 }
855
856 i->bb->remove(i);
857 return true;
858 }
859
860 bool
861 NVC0LoweringPass::handleTXD(TexInstruction *txd)
862 {
863 int dim = txd->tex.target.getDim();
864 unsigned arg = txd->tex.target.getArgCount();
865 unsigned expected_args = arg;
866 const int chipset = prog->getTarget()->getChipset();
867
868 if (chipset >= NVISA_GK104_CHIPSET) {
869 if (!txd->tex.target.isArray() && txd->tex.useOffsets)
870 expected_args++;
871 if (txd->tex.rIndirectSrc >= 0 || txd->tex.sIndirectSrc >= 0)
872 expected_args++;
873 } else {
874 if (txd->tex.useOffsets)
875 expected_args++;
876 if (!txd->tex.target.isArray() && (
877 txd->tex.rIndirectSrc >= 0 || txd->tex.sIndirectSrc >= 0))
878 expected_args++;
879 }
880
881 if (expected_args > 4 ||
882 dim > 2 ||
883 txd->tex.target.isShadow() ||
884 txd->tex.target.isCube())
885 txd->op = OP_TEX;
886
887 handleTEX(txd);
888 while (txd->srcExists(arg))
889 ++arg;
890
891 txd->tex.derivAll = true;
892 if (txd->op == OP_TEX)
893 return handleManualTXD(txd);
894
895 assert(arg == expected_args);
896 for (int c = 0; c < dim; ++c) {
897 txd->setSrc(arg + c * 2 + 0, txd->dPdx[c]);
898 txd->setSrc(arg + c * 2 + 1, txd->dPdy[c]);
899 txd->dPdx[c].set(NULL);
900 txd->dPdy[c].set(NULL);
901 }
902 return true;
903 }
904
905 bool
906 NVC0LoweringPass::handleTXQ(TexInstruction *txq)
907 {
908 // TODO: indirect resource/sampler index
909 return true;
910 }
911
912 bool
913 NVC0LoweringPass::handleTXLQ(TexInstruction *i)
914 {
915 /* The outputs are inverted compared to what the TGSI instruction
916 * expects. Take that into account in the mask.
917 */
918 assert((i->tex.mask & ~3) == 0);
919 if (i->tex.mask == 1)
920 i->tex.mask = 2;
921 else if (i->tex.mask == 2)
922 i->tex.mask = 1;
923 handleTEX(i);
924 bld.setPosition(i, true);
925
926 /* The returned values are not quite what we want:
927 * (a) convert from s16/u16 to f32
928 * (b) multiply by 1/256
929 */
930 for (int def = 0; def < 2; ++def) {
931 if (!i->defExists(def))
932 continue;
933 enum DataType type = TYPE_S16;
934 if (i->tex.mask == 2 || def > 0)
935 type = TYPE_U16;
936 bld.mkCvt(OP_CVT, TYPE_F32, i->getDef(def), type, i->getDef(def));
937 bld.mkOp2(OP_MUL, TYPE_F32, i->getDef(def),
938 i->getDef(def), bld.loadImm(NULL, 1.0f / 256));
939 }
940 if (i->tex.mask == 3) {
941 LValue *t = new_LValue(func, FILE_GPR);
942 bld.mkMov(t, i->getDef(0));
943 bld.mkMov(i->getDef(0), i->getDef(1));
944 bld.mkMov(i->getDef(1), t);
945 }
946 return true;
947 }
948
949
950 bool
951 NVC0LoweringPass::handleATOM(Instruction *atom)
952 {
953 SVSemantic sv;
954
955 switch (atom->src(0).getFile()) {
956 case FILE_MEMORY_LOCAL:
957 sv = SV_LBASE;
958 break;
959 case FILE_MEMORY_SHARED:
960 sv = SV_SBASE;
961 break;
962 default:
963 assert(atom->src(0).getFile() == FILE_MEMORY_GLOBAL);
964 return true;
965 }
966 Value *base =
967 bld.mkOp1v(OP_RDSV, TYPE_U32, bld.getScratch(), bld.mkSysVal(sv, 0));
968 Value *ptr = atom->getIndirect(0, 0);
969
970 atom->setSrc(0, cloneShallow(func, atom->getSrc(0)));
971 atom->getSrc(0)->reg.file = FILE_MEMORY_GLOBAL;
972 if (ptr)
973 base = bld.mkOp2v(OP_ADD, TYPE_U32, base, base, ptr);
974 atom->setIndirect(0, 0, base);
975
976 return true;
977 }
978
979 bool
980 NVC0LoweringPass::handleCasExch(Instruction *cas, bool needCctl)
981 {
982 if (cas->subOp != NV50_IR_SUBOP_ATOM_CAS &&
983 cas->subOp != NV50_IR_SUBOP_ATOM_EXCH)
984 return false;
985 bld.setPosition(cas, true);
986
987 if (needCctl) {
988 Instruction *cctl = bld.mkOp1(OP_CCTL, TYPE_NONE, NULL, cas->getSrc(0));
989 cctl->setIndirect(0, 0, cas->getIndirect(0, 0));
990 cctl->fixed = 1;
991 cctl->subOp = NV50_IR_SUBOP_CCTL_IV;
992 if (cas->isPredicated())
993 cctl->setPredicate(cas->cc, cas->getPredicate());
994 }
995
996 if (cas->defExists(0) && cas->subOp == NV50_IR_SUBOP_ATOM_CAS) {
997 // CAS is crazy. It's 2nd source is a double reg, and the 3rd source
998 // should be set to the high part of the double reg or bad things will
999 // happen elsewhere in the universe.
1000 // Also, it sometimes returns the new value instead of the old one
1001 // under mysterious circumstances.
1002 Value *dreg = bld.getSSA(8);
1003 bld.setPosition(cas, false);
1004 bld.mkOp2(OP_MERGE, TYPE_U64, dreg, cas->getSrc(1), cas->getSrc(2));
1005 cas->setSrc(1, dreg);
1006 }
1007
1008 return true;
1009 }
1010
1011 inline Value *
1012 NVC0LoweringPass::loadResInfo32(Value *ptr, uint32_t off)
1013 {
1014 uint8_t b = prog->driver->io.resInfoCBSlot;
1015 off += prog->driver->io.suInfoBase;
1016 return bld.
1017 mkLoadv(TYPE_U32, bld.mkSymbol(FILE_MEMORY_CONST, b, TYPE_U32, off), ptr);
1018 }
1019
1020 inline Value *
1021 NVC0LoweringPass::loadMsInfo32(Value *ptr, uint32_t off)
1022 {
1023 uint8_t b = prog->driver->io.msInfoCBSlot;
1024 off += prog->driver->io.msInfoBase;
1025 return bld.
1026 mkLoadv(TYPE_U32, bld.mkSymbol(FILE_MEMORY_CONST, b, TYPE_U32, off), ptr);
1027 }
1028
1029 /* On nvc0, surface info is obtained via the surface binding points passed
1030 * to the SULD/SUST instructions.
1031 * On nve4, surface info is stored in c[] and is used by various special
1032 * instructions, e.g. for clamping coordiantes or generating an address.
1033 * They couldn't just have added an equivalent to TIC now, couldn't they ?
1034 */
1035 #define NVE4_SU_INFO_ADDR 0x00
1036 #define NVE4_SU_INFO_FMT 0x04
1037 #define NVE4_SU_INFO_DIM_X 0x08
1038 #define NVE4_SU_INFO_PITCH 0x0c
1039 #define NVE4_SU_INFO_DIM_Y 0x10
1040 #define NVE4_SU_INFO_ARRAY 0x14
1041 #define NVE4_SU_INFO_DIM_Z 0x18
1042 #define NVE4_SU_INFO_UNK1C 0x1c
1043 #define NVE4_SU_INFO_WIDTH 0x20
1044 #define NVE4_SU_INFO_HEIGHT 0x24
1045 #define NVE4_SU_INFO_DEPTH 0x28
1046 #define NVE4_SU_INFO_TARGET 0x2c
1047 #define NVE4_SU_INFO_CALL 0x30
1048 #define NVE4_SU_INFO_RAW_X 0x34
1049 #define NVE4_SU_INFO_MS_X 0x38
1050 #define NVE4_SU_INFO_MS_Y 0x3c
1051
1052 #define NVE4_SU_INFO__STRIDE 0x40
1053
1054 #define NVE4_SU_INFO_DIM(i) (0x08 + (i) * 8)
1055 #define NVE4_SU_INFO_SIZE(i) (0x20 + (i) * 4)
1056 #define NVE4_SU_INFO_MS(i) (0x38 + (i) * 4)
1057
1058 static inline uint16_t getSuClampSubOp(const TexInstruction *su, int c)
1059 {
1060 switch (su->tex.target.getEnum()) {
1061 case TEX_TARGET_BUFFER: return NV50_IR_SUBOP_SUCLAMP_PL(0, 1);
1062 case TEX_TARGET_RECT: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1063 case TEX_TARGET_1D: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1064 case TEX_TARGET_1D_ARRAY: return (c == 1) ?
1065 NV50_IR_SUBOP_SUCLAMP_PL(0, 2) :
1066 NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1067 case TEX_TARGET_2D: return NV50_IR_SUBOP_SUCLAMP_BL(0, 2);
1068 case TEX_TARGET_2D_MS: return NV50_IR_SUBOP_SUCLAMP_BL(0, 2);
1069 case TEX_TARGET_2D_ARRAY: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1070 case TEX_TARGET_2D_MS_ARRAY: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1071 case TEX_TARGET_3D: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1072 case TEX_TARGET_CUBE: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1073 case TEX_TARGET_CUBE_ARRAY: return NV50_IR_SUBOP_SUCLAMP_SD(0, 2);
1074 default:
1075 assert(0);
1076 return 0;
1077 }
1078 }
1079
1080 void
1081 NVC0LoweringPass::adjustCoordinatesMS(TexInstruction *tex)
1082 {
1083 const uint16_t base = tex->tex.r * NVE4_SU_INFO__STRIDE;
1084 const int arg = tex->tex.target.getArgCount();
1085
1086 if (tex->tex.target == TEX_TARGET_2D_MS)
1087 tex->tex.target = TEX_TARGET_2D;
1088 else
1089 if (tex->tex.target == TEX_TARGET_2D_MS_ARRAY)
1090 tex->tex.target = TEX_TARGET_2D_ARRAY;
1091 else
1092 return;
1093
1094 Value *x = tex->getSrc(0);
1095 Value *y = tex->getSrc(1);
1096 Value *s = tex->getSrc(arg - 1);
1097
1098 Value *tx = bld.getSSA(), *ty = bld.getSSA(), *ts = bld.getSSA();
1099
1100 Value *ms_x = loadResInfo32(NULL, base + NVE4_SU_INFO_MS(0));
1101 Value *ms_y = loadResInfo32(NULL, base + NVE4_SU_INFO_MS(1));
1102
1103 bld.mkOp2(OP_SHL, TYPE_U32, tx, x, ms_x);
1104 bld.mkOp2(OP_SHL, TYPE_U32, ty, y, ms_y);
1105
1106 s = bld.mkOp2v(OP_AND, TYPE_U32, ts, s, bld.loadImm(NULL, 0x7));
1107 s = bld.mkOp2v(OP_SHL, TYPE_U32, ts, ts, bld.mkImm(3));
1108
1109 Value *dx = loadMsInfo32(ts, 0x0);
1110 Value *dy = loadMsInfo32(ts, 0x4);
1111
1112 bld.mkOp2(OP_ADD, TYPE_U32, tx, tx, dx);
1113 bld.mkOp2(OP_ADD, TYPE_U32, ty, ty, dy);
1114
1115 tex->setSrc(0, tx);
1116 tex->setSrc(1, ty);
1117 tex->moveSources(arg, -1);
1118 }
1119
1120 // Sets 64-bit "generic address", predicate and format sources for SULD/SUST.
1121 // They're computed from the coordinates using the surface info in c[] space.
1122 void
1123 NVC0LoweringPass::processSurfaceCoordsNVE4(TexInstruction *su)
1124 {
1125 Instruction *insn;
1126 const bool atom = su->op == OP_SUREDB || su->op == OP_SUREDP;
1127 const bool raw =
1128 su->op == OP_SULDB || su->op == OP_SUSTB || su->op == OP_SUREDB;
1129 const int idx = su->tex.r;
1130 const int dim = su->tex.target.getDim();
1131 const int arg = dim + (su->tex.target.isArray() ? 1 : 0);
1132 const uint16_t base = idx * NVE4_SU_INFO__STRIDE;
1133 int c;
1134 Value *zero = bld.mkImm(0);
1135 Value *p1 = NULL;
1136 Value *v;
1137 Value *src[3];
1138 Value *bf, *eau, *off;
1139 Value *addr, *pred;
1140
1141 off = bld.getScratch(4);
1142 bf = bld.getScratch(4);
1143 addr = bld.getSSA(8);
1144 pred = bld.getScratch(1, FILE_PREDICATE);
1145
1146 bld.setPosition(su, false);
1147
1148 adjustCoordinatesMS(su);
1149
1150 // calculate clamped coordinates
1151 for (c = 0; c < arg; ++c) {
1152 src[c] = bld.getScratch();
1153 if (c == 0 && raw)
1154 v = loadResInfo32(NULL, base + NVE4_SU_INFO_RAW_X);
1155 else
1156 v = loadResInfo32(NULL, base + NVE4_SU_INFO_DIM(c));
1157 bld.mkOp3(OP_SUCLAMP, TYPE_S32, src[c], su->getSrc(c), v, zero)
1158 ->subOp = getSuClampSubOp(su, c);
1159 }
1160 for (; c < 3; ++c)
1161 src[c] = zero;
1162
1163 // set predicate output
1164 if (su->tex.target == TEX_TARGET_BUFFER) {
1165 src[0]->getInsn()->setFlagsDef(1, pred);
1166 } else
1167 if (su->tex.target.isArray()) {
1168 p1 = bld.getSSA(1, FILE_PREDICATE);
1169 src[dim]->getInsn()->setFlagsDef(1, p1);
1170 }
1171
1172 // calculate pixel offset
1173 if (dim == 1) {
1174 if (su->tex.target != TEX_TARGET_BUFFER)
1175 bld.mkOp2(OP_AND, TYPE_U32, off, src[0], bld.loadImm(NULL, 0xffff));
1176 } else
1177 if (dim == 3) {
1178 v = loadResInfo32(NULL, base + NVE4_SU_INFO_UNK1C);
1179 bld.mkOp3(OP_MADSP, TYPE_U32, off, src[2], v, src[1])
1180 ->subOp = NV50_IR_SUBOP_MADSP(4,2,8); // u16l u16l u16l
1181
1182 v = loadResInfo32(NULL, base + NVE4_SU_INFO_PITCH);
1183 bld.mkOp3(OP_MADSP, TYPE_U32, off, off, v, src[0])
1184 ->subOp = NV50_IR_SUBOP_MADSP(0,2,8); // u32 u16l u16l
1185 } else {
1186 assert(dim == 2);
1187 v = loadResInfo32(NULL, base + NVE4_SU_INFO_PITCH);
1188 bld.mkOp3(OP_MADSP, TYPE_U32, off, src[1], v, src[0])
1189 ->subOp = su->tex.target.isArray() ?
1190 NV50_IR_SUBOP_MADSP_SD : NV50_IR_SUBOP_MADSP(4,2,8); // u16l u16l u16l
1191 }
1192
1193 // calculate effective address part 1
1194 if (su->tex.target == TEX_TARGET_BUFFER) {
1195 if (raw) {
1196 bf = src[0];
1197 } else {
1198 v = loadResInfo32(NULL, base + NVE4_SU_INFO_FMT);
1199 bld.mkOp3(OP_VSHL, TYPE_U32, bf, src[0], v, zero)
1200 ->subOp = NV50_IR_SUBOP_V1(7,6,8|2);
1201 }
1202 } else {
1203 Value *y = src[1];
1204 Value *z = src[2];
1205 uint16_t subOp = 0;
1206
1207 switch (dim) {
1208 case 1:
1209 y = zero;
1210 z = zero;
1211 break;
1212 case 2:
1213 z = off;
1214 if (!su->tex.target.isArray()) {
1215 z = loadResInfo32(NULL, base + NVE4_SU_INFO_UNK1C);
1216 subOp = NV50_IR_SUBOP_SUBFM_3D;
1217 }
1218 break;
1219 default:
1220 subOp = NV50_IR_SUBOP_SUBFM_3D;
1221 assert(dim == 3);
1222 break;
1223 }
1224 insn = bld.mkOp3(OP_SUBFM, TYPE_U32, bf, src[0], y, z);
1225 insn->subOp = subOp;
1226 insn->setFlagsDef(1, pred);
1227 }
1228
1229 // part 2
1230 v = loadResInfo32(NULL, base + NVE4_SU_INFO_ADDR);
1231
1232 if (su->tex.target == TEX_TARGET_BUFFER) {
1233 eau = v;
1234 } else {
1235 eau = bld.mkOp3v(OP_SUEAU, TYPE_U32, bld.getScratch(4), off, bf, v);
1236 }
1237 // add array layer offset
1238 if (su->tex.target.isArray()) {
1239 v = loadResInfo32(NULL, base + NVE4_SU_INFO_ARRAY);
1240 if (dim == 1)
1241 bld.mkOp3(OP_MADSP, TYPE_U32, eau, src[1], v, eau)
1242 ->subOp = NV50_IR_SUBOP_MADSP(4,0,0); // u16 u24 u32
1243 else
1244 bld.mkOp3(OP_MADSP, TYPE_U32, eau, v, src[2], eau)
1245 ->subOp = NV50_IR_SUBOP_MADSP(0,0,0); // u32 u24 u32
1246 // combine predicates
1247 assert(p1);
1248 bld.mkOp2(OP_OR, TYPE_U8, pred, pred, p1);
1249 }
1250
1251 if (atom) {
1252 Value *lo = bf;
1253 if (su->tex.target == TEX_TARGET_BUFFER) {
1254 lo = zero;
1255 bld.mkMov(off, bf);
1256 }
1257 // bf == g[] address & 0xff
1258 // eau == g[] address >> 8
1259 bld.mkOp3(OP_PERMT, TYPE_U32, bf, lo, bld.loadImm(NULL, 0x6540), eau);
1260 bld.mkOp3(OP_PERMT, TYPE_U32, eau, zero, bld.loadImm(NULL, 0x0007), eau);
1261 } else
1262 if (su->op == OP_SULDP && su->tex.target == TEX_TARGET_BUFFER) {
1263 // Convert from u32 to u8 address format, which is what the library code
1264 // doing SULDP currently uses.
1265 // XXX: can SUEAU do this ?
1266 // XXX: does it matter that we don't mask high bytes in bf ?
1267 // Grrr.
1268 bld.mkOp2(OP_SHR, TYPE_U32, off, bf, bld.mkImm(8));
1269 bld.mkOp2(OP_ADD, TYPE_U32, eau, eau, off);
1270 }
1271
1272 bld.mkOp2(OP_MERGE, TYPE_U64, addr, bf, eau);
1273
1274 if (atom && su->tex.target == TEX_TARGET_BUFFER)
1275 bld.mkOp2(OP_ADD, TYPE_U64, addr, addr, off);
1276
1277 // let's just set it 0 for raw access and hope it works
1278 v = raw ?
1279 bld.mkImm(0) : loadResInfo32(NULL, base + NVE4_SU_INFO_FMT);
1280
1281 // get rid of old coordinate sources, make space for fmt info and predicate
1282 su->moveSources(arg, 3 - arg);
1283 // set 64 bit address and 32-bit format sources
1284 su->setSrc(0, addr);
1285 su->setSrc(1, v);
1286 su->setSrc(2, pred);
1287 }
1288
1289 void
1290 NVC0LoweringPass::handleSurfaceOpNVE4(TexInstruction *su)
1291 {
1292 processSurfaceCoordsNVE4(su);
1293
1294 // Who do we hate more ? The person who decided that nvc0's SULD doesn't
1295 // have to support conversion or the person who decided that, in OpenCL,
1296 // you don't have to specify the format here like you do in OpenGL ?
1297
1298 if (su->op == OP_SULDP) {
1299 // We don't patch shaders. Ever.
1300 // You get an indirect call to our library blob here.
1301 // But at least it's uniform.
1302 FlowInstruction *call;
1303 LValue *p[3];
1304 LValue *r[5];
1305 uint16_t base = su->tex.r * NVE4_SU_INFO__STRIDE + NVE4_SU_INFO_CALL;
1306
1307 for (int i = 0; i < 4; ++i)
1308 (r[i] = bld.getScratch(4, FILE_GPR))->reg.data.id = i;
1309 for (int i = 0; i < 3; ++i)
1310 (p[i] = bld.getScratch(1, FILE_PREDICATE))->reg.data.id = i;
1311 (r[4] = bld.getScratch(8, FILE_GPR))->reg.data.id = 4;
1312
1313 bld.mkMov(p[1], bld.mkImm((su->cache == CACHE_CA) ? 1 : 0), TYPE_U8);
1314 bld.mkMov(p[2], bld.mkImm((su->cache == CACHE_CG) ? 1 : 0), TYPE_U8);
1315 bld.mkMov(p[0], su->getSrc(2), TYPE_U8);
1316 bld.mkMov(r[4], su->getSrc(0), TYPE_U64);
1317 bld.mkMov(r[2], su->getSrc(1), TYPE_U32);
1318
1319 call = bld.mkFlow(OP_CALL, NULL, su->cc, su->getPredicate());
1320
1321 call->indirect = 1;
1322 call->absolute = 1;
1323 call->setSrc(0, bld.mkSymbol(FILE_MEMORY_CONST,
1324 prog->driver->io.resInfoCBSlot, TYPE_U32,
1325 prog->driver->io.suInfoBase + base));
1326 call->setSrc(1, r[2]);
1327 call->setSrc(2, r[4]);
1328 for (int i = 0; i < 3; ++i)
1329 call->setSrc(3 + i, p[i]);
1330 for (int i = 0; i < 4; ++i) {
1331 call->setDef(i, r[i]);
1332 bld.mkMov(su->getDef(i), r[i]);
1333 }
1334 call->setDef(4, p[1]);
1335 delete_Instruction(bld.getProgram(), su);
1336 }
1337
1338 if (su->op == OP_SUREDB || su->op == OP_SUREDP) {
1339 // FIXME: for out of bounds access, destination value will be undefined !
1340 Value *pred = su->getSrc(2);
1341 CondCode cc = CC_NOT_P;
1342 if (su->getPredicate()) {
1343 pred = bld.getScratch(1, FILE_PREDICATE);
1344 cc = su->cc;
1345 if (cc == CC_NOT_P) {
1346 bld.mkOp2(OP_OR, TYPE_U8, pred, su->getPredicate(), su->getSrc(2));
1347 } else {
1348 bld.mkOp2(OP_AND, TYPE_U8, pred, su->getPredicate(), su->getSrc(2));
1349 pred->getInsn()->src(1).mod = Modifier(NV50_IR_MOD_NOT);
1350 }
1351 }
1352 Instruction *red = bld.mkOp(OP_ATOM, su->dType, su->getDef(0));
1353 red->subOp = su->subOp;
1354 if (!gMemBase)
1355 gMemBase = bld.mkSymbol(FILE_MEMORY_GLOBAL, 0, TYPE_U32, 0);
1356 red->setSrc(0, gMemBase);
1357 red->setSrc(1, su->getSrc(3));
1358 if (su->subOp == NV50_IR_SUBOP_ATOM_CAS)
1359 red->setSrc(2, su->getSrc(4));
1360 red->setIndirect(0, 0, su->getSrc(0));
1361 red->setPredicate(cc, pred);
1362 delete_Instruction(bld.getProgram(), su);
1363 handleCasExch(red, true);
1364 } else {
1365 su->sType = (su->tex.target == TEX_TARGET_BUFFER) ? TYPE_U32 : TYPE_U8;
1366 }
1367 }
1368
1369 bool
1370 NVC0LoweringPass::handleWRSV(Instruction *i)
1371 {
1372 Instruction *st;
1373 Symbol *sym;
1374 uint32_t addr;
1375
1376 // must replace, $sreg are not writeable
1377 addr = targ->getSVAddress(FILE_SHADER_OUTPUT, i->getSrc(0)->asSym());
1378 if (addr >= 0x400)
1379 return false;
1380 sym = bld.mkSymbol(FILE_SHADER_OUTPUT, 0, i->sType, addr);
1381
1382 st = bld.mkStore(OP_EXPORT, i->dType, sym, i->getIndirect(0, 0),
1383 i->getSrc(1));
1384 st->perPatch = i->perPatch;
1385
1386 bld.getBB()->remove(i);
1387 return true;
1388 }
1389
1390 void
1391 NVC0LoweringPass::readTessCoord(LValue *dst, int c)
1392 {
1393 Value *laneid = bld.getSSA();
1394 Value *x, *y;
1395
1396 bld.mkOp1(OP_RDSV, TYPE_U32, laneid, bld.mkSysVal(SV_LANEID, 0));
1397
1398 if (c == 0) {
1399 x = dst;
1400 y = NULL;
1401 } else
1402 if (c == 1) {
1403 x = NULL;
1404 y = dst;
1405 } else {
1406 assert(c == 2);
1407 x = bld.getSSA();
1408 y = bld.getSSA();
1409 }
1410 if (x)
1411 bld.mkFetch(x, TYPE_F32, FILE_SHADER_OUTPUT, 0x2f0, NULL, laneid);
1412 if (y)
1413 bld.mkFetch(y, TYPE_F32, FILE_SHADER_OUTPUT, 0x2f4, NULL, laneid);
1414
1415 if (c == 2) {
1416 bld.mkOp2(OP_ADD, TYPE_F32, dst, x, y);
1417 bld.mkOp2(OP_SUB, TYPE_F32, dst, bld.loadImm(NULL, 1.0f), dst);
1418 }
1419 }
1420
1421 bool
1422 NVC0LoweringPass::handleRDSV(Instruction *i)
1423 {
1424 Symbol *sym = i->getSrc(0)->asSym();
1425 const SVSemantic sv = sym->reg.data.sv.sv;
1426 Value *vtx = NULL;
1427 Instruction *ld;
1428 uint32_t addr = targ->getSVAddress(FILE_SHADER_INPUT, sym);
1429
1430 if (addr >= 0x400) {
1431 // mov $sreg
1432 if (sym->reg.data.sv.index == 3) {
1433 // TGSI backend may use 4th component of TID,NTID,CTAID,NCTAID
1434 i->op = OP_MOV;
1435 i->setSrc(0, bld.mkImm((sv == SV_NTID || sv == SV_NCTAID) ? 1 : 0));
1436 }
1437 return true;
1438 }
1439
1440 switch (sv) {
1441 case SV_POSITION:
1442 assert(prog->getType() == Program::TYPE_FRAGMENT);
1443 if (i->srcExists(1)) {
1444 // Pass offset through to the interpolation logic
1445 ld = bld.mkInterp(NV50_IR_INTERP_LINEAR | NV50_IR_INTERP_OFFSET,
1446 i->getDef(0), addr, NULL);
1447 ld->setSrc(1, i->getSrc(1));
1448 } else {
1449 bld.mkInterp(NV50_IR_INTERP_LINEAR, i->getDef(0), addr, NULL);
1450 }
1451 break;
1452 case SV_FACE:
1453 {
1454 Value *face = i->getDef(0);
1455 bld.mkInterp(NV50_IR_INTERP_FLAT, face, addr, NULL);
1456 if (i->dType == TYPE_F32) {
1457 bld.mkOp2(OP_OR, TYPE_U32, face, face, bld.mkImm(0x00000001));
1458 bld.mkOp1(OP_NEG, TYPE_S32, face, face);
1459 bld.mkCvt(OP_CVT, TYPE_F32, face, TYPE_S32, face);
1460 }
1461 }
1462 break;
1463 case SV_TESS_COORD:
1464 assert(prog->getType() == Program::TYPE_TESSELLATION_EVAL);
1465 readTessCoord(i->getDef(0)->asLValue(), i->getSrc(0)->reg.data.sv.index);
1466 break;
1467 case SV_NTID:
1468 case SV_NCTAID:
1469 case SV_GRIDID:
1470 assert(targ->getChipset() >= NVISA_GK104_CHIPSET); // mov $sreg otherwise
1471 if (sym->reg.data.sv.index == 3) {
1472 i->op = OP_MOV;
1473 i->setSrc(0, bld.mkImm(sv == SV_GRIDID ? 0 : 1));
1474 return true;
1475 }
1476 addr += prog->driver->prop.cp.gridInfoBase;
1477 bld.mkLoad(TYPE_U32, i->getDef(0),
1478 bld.mkSymbol(FILE_MEMORY_CONST, 0, TYPE_U32, addr), NULL);
1479 break;
1480 case SV_SAMPLE_INDEX:
1481 // TODO: Properly pass source as an address in the PIX address space
1482 // (which can be of the form [r0+offset]). But this is currently
1483 // unnecessary.
1484 ld = bld.mkOp1(OP_PIXLD, TYPE_U32, i->getDef(0), bld.mkImm(0));
1485 ld->subOp = NV50_IR_SUBOP_PIXLD_SAMPLEID;
1486 break;
1487 case SV_SAMPLE_POS: {
1488 Value *off = new_LValue(func, FILE_GPR);
1489 ld = bld.mkOp1(OP_PIXLD, TYPE_U32, i->getDef(0), bld.mkImm(0));
1490 ld->subOp = NV50_IR_SUBOP_PIXLD_SAMPLEID;
1491 bld.mkOp2(OP_SHL, TYPE_U32, off, i->getDef(0), bld.mkImm(3));
1492 bld.mkLoad(TYPE_F32,
1493 i->getDef(0),
1494 bld.mkSymbol(
1495 FILE_MEMORY_CONST, prog->driver->io.resInfoCBSlot,
1496 TYPE_U32, prog->driver->io.sampleInfoBase +
1497 4 * sym->reg.data.sv.index),
1498 off);
1499 break;
1500 }
1501 case SV_SAMPLE_MASK:
1502 ld = bld.mkOp1(OP_PIXLD, TYPE_U32, i->getDef(0), bld.mkImm(0));
1503 ld->subOp = NV50_IR_SUBOP_PIXLD_COVMASK;
1504 break;
1505 default:
1506 if (prog->getType() == Program::TYPE_TESSELLATION_EVAL)
1507 vtx = bld.mkOp1v(OP_PFETCH, TYPE_U32, bld.getSSA(), bld.mkImm(0));
1508 ld = bld.mkFetch(i->getDef(0), i->dType,
1509 FILE_SHADER_INPUT, addr, i->getIndirect(0, 0), vtx);
1510 ld->perPatch = i->perPatch;
1511 break;
1512 }
1513 bld.getBB()->remove(i);
1514 return true;
1515 }
1516
1517 bool
1518 NVC0LoweringPass::handleDIV(Instruction *i)
1519 {
1520 if (!isFloatType(i->dType))
1521 return true;
1522 bld.setPosition(i, false);
1523 Instruction *rcp = bld.mkOp1(OP_RCP, i->dType, bld.getSSA(), i->getSrc(1));
1524 i->op = OP_MUL;
1525 i->setSrc(1, rcp->getDef(0));
1526 return true;
1527 }
1528
1529 bool
1530 NVC0LoweringPass::handleMOD(Instruction *i)
1531 {
1532 if (i->dType != TYPE_F32)
1533 return true;
1534 LValue *value = bld.getScratch();
1535 bld.mkOp1(OP_RCP, TYPE_F32, value, i->getSrc(1));
1536 bld.mkOp2(OP_MUL, TYPE_F32, value, i->getSrc(0), value);
1537 bld.mkOp1(OP_TRUNC, TYPE_F32, value, value);
1538 bld.mkOp2(OP_MUL, TYPE_F32, value, i->getSrc(1), value);
1539 i->op = OP_SUB;
1540 i->setSrc(1, value);
1541 return true;
1542 }
1543
1544 bool
1545 NVC0LoweringPass::handleSQRT(Instruction *i)
1546 {
1547 Instruction *rsq = bld.mkOp1(OP_RSQ, TYPE_F32,
1548 bld.getSSA(), i->getSrc(0));
1549 i->op = OP_MUL;
1550 i->setSrc(1, rsq->getDef(0));
1551
1552 return true;
1553 }
1554
1555 bool
1556 NVC0LoweringPass::handlePOW(Instruction *i)
1557 {
1558 LValue *val = bld.getScratch();
1559
1560 bld.mkOp1(OP_LG2, TYPE_F32, val, i->getSrc(0));
1561 bld.mkOp2(OP_MUL, TYPE_F32, val, i->getSrc(1), val)->dnz = 1;
1562 bld.mkOp1(OP_PREEX2, TYPE_F32, val, val);
1563
1564 i->op = OP_EX2;
1565 i->setSrc(0, val);
1566 i->setSrc(1, NULL);
1567
1568 return true;
1569 }
1570
1571 bool
1572 NVC0LoweringPass::handleEXPORT(Instruction *i)
1573 {
1574 if (prog->getType() == Program::TYPE_FRAGMENT) {
1575 int id = i->getSrc(0)->reg.data.offset / 4;
1576
1577 if (i->src(0).isIndirect(0)) // TODO, ugly
1578 return false;
1579 i->op = OP_MOV;
1580 i->subOp = NV50_IR_SUBOP_MOV_FINAL;
1581 i->src(0).set(i->src(1));
1582 i->setSrc(1, NULL);
1583 i->setDef(0, new_LValue(func, FILE_GPR));
1584 i->getDef(0)->reg.data.id = id;
1585
1586 prog->maxGPR = MAX2(prog->maxGPR, id);
1587 } else
1588 if (prog->getType() == Program::TYPE_GEOMETRY) {
1589 i->setIndirect(0, 1, gpEmitAddress);
1590 }
1591 return true;
1592 }
1593
1594 bool
1595 NVC0LoweringPass::handleOUT(Instruction *i)
1596 {
1597 Instruction *prev = i->prev;
1598 ImmediateValue stream, prevStream;
1599
1600 // Only merge if the stream ids match. Also, note that the previous
1601 // instruction would have already been lowered, so we take arg1 from it.
1602 if (i->op == OP_RESTART && prev && prev->op == OP_EMIT &&
1603 i->src(0).getImmediate(stream) &&
1604 prev->src(1).getImmediate(prevStream) &&
1605 stream.reg.data.u32 == prevStream.reg.data.u32) {
1606 i->prev->subOp = NV50_IR_SUBOP_EMIT_RESTART;
1607 delete_Instruction(prog, i);
1608 } else {
1609 assert(gpEmitAddress);
1610 i->setDef(0, gpEmitAddress);
1611 i->setSrc(1, i->getSrc(0));
1612 i->setSrc(0, gpEmitAddress);
1613 }
1614 return true;
1615 }
1616
1617 // Generate a binary predicate if an instruction is predicated by
1618 // e.g. an f32 value.
1619 void
1620 NVC0LoweringPass::checkPredicate(Instruction *insn)
1621 {
1622 Value *pred = insn->getPredicate();
1623 Value *pdst;
1624
1625 if (!pred || pred->reg.file == FILE_PREDICATE)
1626 return;
1627 pdst = new_LValue(func, FILE_PREDICATE);
1628
1629 // CAUTION: don't use pdst->getInsn, the definition might not be unique,
1630 // delay turning PSET(FSET(x,y),0) into PSET(x,y) to a later pass
1631
1632 bld.mkCmp(OP_SET, CC_NEU, insn->dType, pdst, insn->dType, bld.mkImm(0), pred);
1633
1634 insn->setPredicate(insn->cc, pdst);
1635 }
1636
1637 //
1638 // - add quadop dance for texturing
1639 // - put FP outputs in GPRs
1640 // - convert instruction sequences
1641 //
1642 bool
1643 NVC0LoweringPass::visit(Instruction *i)
1644 {
1645 bld.setPosition(i, false);
1646
1647 if (i->cc != CC_ALWAYS)
1648 checkPredicate(i);
1649
1650 switch (i->op) {
1651 case OP_TEX:
1652 case OP_TXB:
1653 case OP_TXL:
1654 case OP_TXF:
1655 case OP_TXG:
1656 return handleTEX(i->asTex());
1657 case OP_TXD:
1658 return handleTXD(i->asTex());
1659 case OP_TXLQ:
1660 return handleTXLQ(i->asTex());
1661 case OP_TXQ:
1662 return handleTXQ(i->asTex());
1663 case OP_EX2:
1664 bld.mkOp1(OP_PREEX2, TYPE_F32, i->getDef(0), i->getSrc(0));
1665 i->setSrc(0, i->getDef(0));
1666 break;
1667 case OP_POW:
1668 return handlePOW(i);
1669 case OP_DIV:
1670 return handleDIV(i);
1671 case OP_MOD:
1672 return handleMOD(i);
1673 case OP_SQRT:
1674 return handleSQRT(i);
1675 case OP_EXPORT:
1676 return handleEXPORT(i);
1677 case OP_EMIT:
1678 case OP_RESTART:
1679 return handleOUT(i);
1680 case OP_RDSV:
1681 return handleRDSV(i);
1682 case OP_WRSV:
1683 return handleWRSV(i);
1684 case OP_LOAD:
1685 if (i->src(0).getFile() == FILE_SHADER_INPUT) {
1686 if (prog->getType() == Program::TYPE_COMPUTE) {
1687 i->getSrc(0)->reg.file = FILE_MEMORY_CONST;
1688 i->getSrc(0)->reg.fileIndex = 0;
1689 } else
1690 if (prog->getType() == Program::TYPE_GEOMETRY &&
1691 i->src(0).isIndirect(0)) {
1692 // XXX: this assumes vec4 units
1693 Value *ptr = bld.mkOp2v(OP_SHL, TYPE_U32, bld.getSSA(),
1694 i->getIndirect(0, 0), bld.mkImm(4));
1695 i->setIndirect(0, 0, ptr);
1696 } else {
1697 i->op = OP_VFETCH;
1698 assert(prog->getType() != Program::TYPE_FRAGMENT); // INTERP
1699 }
1700 } else if (i->src(0).getFile() == FILE_MEMORY_CONST) {
1701 if (i->src(0).isIndirect(1)) {
1702 Value *ptr;
1703 if (i->src(0).isIndirect(0))
1704 ptr = bld.mkOp3v(OP_INSBF, TYPE_U32, bld.getSSA(),
1705 i->getIndirect(0, 1), bld.mkImm(0x1010),
1706 i->getIndirect(0, 0));
1707 else
1708 ptr = bld.mkOp2v(OP_SHL, TYPE_U32, bld.getSSA(),
1709 i->getIndirect(0, 1), bld.mkImm(16));
1710 i->setIndirect(0, 1, NULL);
1711 i->setIndirect(0, 0, ptr);
1712 i->subOp = NV50_IR_SUBOP_LDC_IS;
1713 }
1714 }
1715 break;
1716 case OP_ATOM:
1717 {
1718 const bool cctl = i->src(0).getFile() == FILE_MEMORY_GLOBAL;
1719 handleATOM(i);
1720 handleCasExch(i, cctl);
1721 }
1722 break;
1723 case OP_SULDB:
1724 case OP_SULDP:
1725 case OP_SUSTB:
1726 case OP_SUSTP:
1727 case OP_SUREDB:
1728 case OP_SUREDP:
1729 if (targ->getChipset() >= NVISA_GK104_CHIPSET)
1730 handleSurfaceOpNVE4(i->asTex());
1731 break;
1732 default:
1733 break;
1734 }
1735 return true;
1736 }
1737
1738 bool
1739 TargetNVC0::runLegalizePass(Program *prog, CGStage stage) const
1740 {
1741 if (stage == CG_STAGE_PRE_SSA) {
1742 NVC0LoweringPass pass(prog);
1743 return pass.run(prog, false, true);
1744 } else
1745 if (stage == CG_STAGE_POST_RA) {
1746 NVC0LegalizePostRA pass(prog);
1747 return pass.run(prog, false, true);
1748 } else
1749 if (stage == CG_STAGE_SSA) {
1750 NVC0LegalizeSSA pass;
1751 return pass.run(prog, false, true);
1752 }
1753 return false;
1754 }
1755
1756 } // namespace nv50_ir