2 * Copyright 2011 Christoph Bumiller
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include "codegen/nv50_ir.h"
24 #include "codegen/nv50_ir_target.h"
25 #include "codegen/nv50_ir_driver.h"
28 #include "nouveau_debug.h"
29 #include "nv50/nv50_program.h"
34 Modifier::Modifier(operation op
)
37 case OP_NEG
: bits
= NV50_IR_MOD_NEG
; break;
38 case OP_ABS
: bits
= NV50_IR_MOD_ABS
; break;
39 case OP_SAT
: bits
= NV50_IR_MOD_SAT
; break;
40 case OP_NOT
: bits
= NV50_IR_MOD_NOT
; break;
47 Modifier
Modifier::operator*(const Modifier m
) const
52 if (this->bits
& NV50_IR_MOD_ABS
)
53 b
&= ~NV50_IR_MOD_NEG
;
55 a
= (this->bits
^ b
) & (NV50_IR_MOD_NOT
| NV50_IR_MOD_NEG
);
56 c
= (this->bits
| m
.bits
) & (NV50_IR_MOD_ABS
| NV50_IR_MOD_SAT
);
58 return Modifier(a
| c
);
61 ValueRef::ValueRef(Value
*v
) : value(NULL
), insn(NULL
)
69 ValueRef::ValueRef(const ValueRef
& ref
) : value(NULL
), insn(ref
.insn
)
72 usedAsPtr
= ref
.usedAsPtr
;
80 bool ValueRef::getImmediate(ImmediateValue
&imm
) const
82 const ValueRef
*src
= this;
84 DataType type
= src
->insn
->sType
;
88 if (src
->insn
->sType
!= type
)
92 if (src
->getFile() == FILE_IMMEDIATE
) {
93 imm
= *(src
->value
->asImm());
94 // The immediate's type isn't required to match its use, it's
95 // more of a hint; applying a modifier makes use of that hint.
101 Instruction
*insn
= src
->value
->getUniqueInsn();
103 if (insn
&& insn
->op
== OP_MOV
) {
106 WARN("OP_MOV with modifier encountered !\n");
114 ValueDef::ValueDef(Value
*v
) : value(NULL
), insn(NULL
)
119 ValueDef::ValueDef(const ValueDef
& def
) : value(NULL
), insn(NULL
)
124 ValueDef::~ValueDef()
130 ValueRef::set(const ValueRef
&ref
)
132 this->set(ref
.get());
134 indirect
[0] = ref
.indirect
[0];
135 indirect
[1] = ref
.indirect
[1];
139 ValueRef::set(Value
*refVal
)
144 value
->uses
.erase(this);
146 refVal
->uses
.insert(this);
152 ValueDef::set(Value
*defVal
)
157 value
->defs
.remove(this);
159 defVal
->defs
.push_back(this);
164 // Check if we can replace this definition's value by the value in @rep,
165 // including the source modifiers, i.e. make sure that all uses support
168 ValueDef::mayReplace(const ValueRef
&rep
)
173 if (!insn
|| !insn
->bb
) // Unbound instruction ?
176 const Target
*target
= insn
->bb
->getProgram()->getTarget();
178 for (Value::UseIterator it
= value
->uses
.begin(); it
!= value
->uses
.end();
180 Instruction
*insn
= (*it
)->getInsn();
183 for (int i
= 0; insn
->srcExists(i
); ++i
) {
184 if (insn
->src(i
).get() == value
) {
185 // If there are multiple references to us we'd have to check if the
186 // combination of mods is still supported, but just bail for now.
187 if (&insn
->src(i
) != (*it
))
192 assert(s
>= 0); // integrity of uses list
194 if (!target
->isModSupported(insn
, s
, rep
.mod
))
201 ValueDef::replace(const ValueRef
&repVal
, bool doSet
)
203 assert(mayReplace(repVal
));
205 if (value
== repVal
.get())
208 while (!value
->uses
.empty()) {
209 ValueRef
*ref
= *value
->uses
.begin();
210 ref
->set(repVal
.get());
211 ref
->mod
*= repVal
.mod
;
221 memset(®
, 0, sizeof(reg
));
225 LValue::LValue(Function
*fn
, DataFile file
)
228 reg
.size
= (file
!= FILE_PREDICATE
) ? 4 : 1;
237 fn
->add(this, this->id
);
240 LValue::LValue(Function
*fn
, LValue
*lval
)
244 reg
.file
= lval
->reg
.file
;
245 reg
.size
= lval
->reg
.size
;
254 fn
->add(this, this->id
);
258 LValue::clone(ClonePolicy
<Function
>& pol
) const
260 LValue
*that
= new_LValue(pol
.context(), reg
.file
);
262 pol
.set
<Value
>(this, that
);
264 that
->reg
.size
= this->reg
.size
;
265 that
->reg
.type
= this->reg
.type
;
266 that
->reg
.data
= this->reg
.data
;
272 LValue::isUniform() const
276 Instruction
*insn
= getInsn();
277 // let's not try too hard here for now ...
278 return !insn
->srcExists(1) && insn
->getSrc(0)->isUniform();
281 Symbol::Symbol(Program
*prog
, DataFile f
, ubyte fidx
)
286 reg
.fileIndex
= fidx
;
289 prog
->add(this, this->id
);
293 Symbol::clone(ClonePolicy
<Function
>& pol
) const
295 Program
*prog
= pol
.context()->getProgram();
297 Symbol
*that
= new_Symbol(prog
, reg
.file
, reg
.fileIndex
);
299 pol
.set
<Value
>(this, that
);
301 that
->reg
.size
= this->reg
.size
;
302 that
->reg
.type
= this->reg
.type
;
303 that
->reg
.data
= this->reg
.data
;
305 that
->baseSym
= this->baseSym
;
311 Symbol::isUniform() const
314 reg
.file
!= FILE_SYSTEM_VALUE
&&
315 reg
.file
!= FILE_MEMORY_LOCAL
&&
316 reg
.file
!= FILE_SHADER_INPUT
;
319 ImmediateValue::ImmediateValue(Program
*prog
, uint32_t uval
)
321 memset(®
, 0, sizeof(reg
));
323 reg
.file
= FILE_IMMEDIATE
;
329 prog
->add(this, this->id
);
332 ImmediateValue::ImmediateValue(Program
*prog
, float fval
)
334 memset(®
, 0, sizeof(reg
));
336 reg
.file
= FILE_IMMEDIATE
;
342 prog
->add(this, this->id
);
345 ImmediateValue::ImmediateValue(Program
*prog
, double dval
)
347 memset(®
, 0, sizeof(reg
));
349 reg
.file
= FILE_IMMEDIATE
;
355 prog
->add(this, this->id
);
358 ImmediateValue::ImmediateValue(const ImmediateValue
*proto
, DataType ty
)
363 reg
.size
= typeSizeof(ty
);
367 ImmediateValue::clone(ClonePolicy
<Function
>& pol
) const
369 Program
*prog
= pol
.context()->getProgram();
370 ImmediateValue
*that
= new_ImmediateValue(prog
, 0u);
372 pol
.set
<Value
>(this, that
);
374 that
->reg
.size
= this->reg
.size
;
375 that
->reg
.type
= this->reg
.type
;
376 that
->reg
.data
= this->reg
.data
;
382 ImmediateValue::isInteger(const int i
) const
386 return reg
.data
.s8
== i
;
388 return reg
.data
.u8
== i
;
390 return reg
.data
.s16
== i
;
392 return reg
.data
.u16
== i
;
395 return reg
.data
.s32
== i
; // as if ...
398 return reg
.data
.s64
== i
; // as if ...
400 return reg
.data
.f32
== static_cast<float>(i
);
402 return reg
.data
.f64
== static_cast<double>(i
);
409 ImmediateValue::isNegative() const
412 case TYPE_S8
: return reg
.data
.s8
< 0;
413 case TYPE_S16
: return reg
.data
.s16
< 0;
415 case TYPE_U32
: return reg
.data
.s32
< 0;
416 case TYPE_F32
: return reg
.data
.u32
& (1 << 31);
417 case TYPE_F64
: return reg
.data
.u64
& (1ULL << 63);
424 ImmediateValue::isPow2() const
429 case TYPE_U32
: return util_is_power_of_two(reg
.data
.u32
);
436 ImmediateValue::applyLog2()
442 assert(!this->isNegative());
447 reg
.data
.u32
= util_logbase2(reg
.data
.u32
);
450 reg
.data
.f32
= log2f(reg
.data
.f32
);
453 reg
.data
.f64
= log2(reg
.data
.f64
);
462 ImmediateValue::compare(CondCode cc
, float fval
) const
464 if (reg
.type
!= TYPE_F32
)
465 ERROR("immediate value is not of type f32");
467 switch (static_cast<CondCode
>(cc
& 7)) {
468 case CC_TR
: return true;
469 case CC_FL
: return false;
470 case CC_LT
: return reg
.data
.f32
< fval
;
471 case CC_LE
: return reg
.data
.f32
<= fval
;
472 case CC_GT
: return reg
.data
.f32
> fval
;
473 case CC_GE
: return reg
.data
.f32
>= fval
;
474 case CC_EQ
: return reg
.data
.f32
== fval
;
475 case CC_NE
: return reg
.data
.f32
!= fval
;
483 ImmediateValue::operator=(const ImmediateValue
&that
)
485 this->reg
= that
.reg
;
490 Value::interfers(const Value
*that
) const
494 if (that
->reg
.file
!= reg
.file
|| that
->reg
.fileIndex
!= reg
.fileIndex
)
500 idA
= this->join
->reg
.data
.offset
;
501 idB
= that
->join
->reg
.data
.offset
;
503 idA
= this->join
->reg
.data
.id
* MIN2(this->reg
.size
, 4);
504 idB
= that
->join
->reg
.data
.id
* MIN2(that
->reg
.size
, 4);
508 return (idA
+ this->reg
.size
> idB
);
511 return (idB
+ that
->reg
.size
> idA
);
517 Value::equals(const Value
*that
, bool strict
) const
522 if (that
->reg
.file
!= reg
.file
|| that
->reg
.fileIndex
!= reg
.fileIndex
)
524 if (that
->reg
.size
!= this->reg
.size
)
527 if (that
->reg
.data
.id
!= this->reg
.data
.id
)
534 ImmediateValue::equals(const Value
*that
, bool strict
) const
536 const ImmediateValue
*imm
= that
->asImm();
539 return reg
.data
.u64
== imm
->reg
.data
.u64
;
543 Symbol::equals(const Value
*that
, bool strict
) const
545 if (reg
.file
!= that
->reg
.file
|| reg
.fileIndex
!= that
->reg
.fileIndex
)
547 assert(that
->asSym());
549 if (this->baseSym
!= that
->asSym()->baseSym
)
552 if (reg
.file
== FILE_SYSTEM_VALUE
)
553 return (this->reg
.data
.sv
.sv
== that
->reg
.data
.sv
.sv
&&
554 this->reg
.data
.sv
.index
== that
->reg
.data
.sv
.index
);
555 return this->reg
.data
.offset
== that
->reg
.data
.offset
;
558 void Instruction::init()
588 Instruction::Instruction()
593 dType
= sType
= TYPE_F32
;
599 Instruction::Instruction(Function
*fn
, operation opr
, DataType ty
)
609 Instruction::~Instruction()
612 Function
*fn
= bb
->getFunction();
614 fn
->allInsns
.remove(id
);
617 for (int s
= 0; srcExists(s
); ++s
)
619 // must unlink defs too since the list pointers will get deallocated
620 for (int d
= 0; defExists(d
); ++d
)
625 Instruction::setDef(int i
, Value
*val
)
627 int size
= defs
.size();
631 defs
[size
++].setInsn(this);
637 Instruction::setSrc(int s
, Value
*val
)
639 int size
= srcs
.size();
643 srcs
[size
++].setInsn(this);
649 Instruction::setSrc(int s
, const ValueRef
& ref
)
651 setSrc(s
, ref
.get());
652 srcs
[s
].mod
= ref
.mod
;
656 Instruction::swapSources(int a
, int b
)
658 Value
*value
= srcs
[a
].get();
659 Modifier m
= srcs
[a
].mod
;
667 static inline void moveSourcesAdjustIndex(int8_t &index
, int s
, int delta
)
672 if ((delta
< 0) && (index
>= (s
+ delta
)))
676 // Moves sources [@s,last_source] by @delta.
677 // If @delta < 0, sources [@s - abs(@delta), @s) are erased.
679 Instruction::moveSources(const int s
, const int delta
)
683 assert(s
+ delta
>= 0);
687 for (k
= 0; srcExists(k
); ++k
) {
688 for (int i
= 0; i
< 2; ++i
)
689 moveSourcesAdjustIndex(src(k
).indirect
[i
], s
, delta
);
691 moveSourcesAdjustIndex(predSrc
, s
, delta
);
692 moveSourcesAdjustIndex(flagsSrc
, s
, delta
);
694 TexInstruction
*tex
= asTex();
695 moveSourcesAdjustIndex(tex
->tex
.rIndirectSrc
, s
, delta
);
696 moveSourcesAdjustIndex(tex
->tex
.sIndirectSrc
, s
, delta
);
701 for (int p
= k
+ delta
; k
>= s
; --k
, --p
)
705 for (p
= s
; p
< k
; ++p
)
706 setSrc(p
+ delta
, src(p
));
707 for (; (p
+ delta
) < k
; ++p
)
708 setSrc(p
+ delta
, NULL
);
713 Instruction::takeExtraSources(int s
, Value
*values
[3])
715 values
[0] = getIndirect(s
, 0);
717 setIndirect(s
, 0, NULL
);
719 values
[1] = getIndirect(s
, 1);
721 setIndirect(s
, 1, NULL
);
723 values
[2] = getPredicate();
725 setPredicate(cc
, NULL
);
729 Instruction::putExtraSources(int s
, Value
*values
[3])
732 setIndirect(s
, 0, values
[0]);
734 setIndirect(s
, 1, values
[1]);
736 setPredicate(cc
, values
[2]);
740 Instruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
743 i
= new_Instruction(pol
.context(), op
, dType
);
744 #ifndef NDEBUG // non-conformant assert, so this is required
745 assert(typeid(*i
) == typeid(*this));
748 pol
.set
<Instruction
>(this, i
);
756 i
->saturate
= saturate
;
764 i
->perPatch
= perPatch
;
766 i
->postFactor
= postFactor
;
768 for (int d
= 0; defExists(d
); ++d
)
769 i
->setDef(d
, pol
.get(getDef(d
)));
771 for (int s
= 0; srcExists(s
); ++s
) {
772 i
->setSrc(s
, pol
.get(getSrc(s
)));
773 i
->src(s
).mod
= src(s
).mod
;
777 i
->predSrc
= predSrc
;
778 i
->flagsDef
= flagsDef
;
779 i
->flagsSrc
= flagsSrc
;
785 Instruction::defCount(unsigned int mask
, bool singleFile
) const
790 unsigned int d
= ffs(mask
);
793 for (i
= d
--; defExists(i
); ++i
)
794 if (getDef(i
)->reg
.file
!= getDef(d
)->reg
.file
)
798 for (n
= 0, i
= 0; this->defExists(i
); ++i
, mask
>>= 1)
804 Instruction::srcCount(unsigned int mask
, bool singleFile
) const
809 unsigned int s
= ffs(mask
);
812 for (i
= s
--; srcExists(i
); ++i
)
813 if (getSrc(i
)->reg
.file
!= getSrc(s
)->reg
.file
)
817 for (n
= 0, i
= 0; this->srcExists(i
); ++i
, mask
>>= 1)
823 Instruction::setIndirect(int s
, int dim
, Value
*value
)
825 assert(this->srcExists(s
));
827 int p
= srcs
[s
].indirect
[dim
];
832 while (p
> 0 && !srcExists(p
- 1))
836 srcs
[p
].usedAsPtr
= (value
!= 0);
837 srcs
[s
].indirect
[dim
] = value
? p
: -1;
842 Instruction::setPredicate(CondCode ccode
, Value
*value
)
848 srcs
[predSrc
].set(NULL
);
855 predSrc
= srcs
.size();
856 while (predSrc
> 0 && !srcExists(predSrc
- 1))
860 setSrc(predSrc
, value
);
865 Instruction::writesPredicate() const
867 for (int d
= 0; defExists(d
); ++d
)
868 if (getDef(d
)->inFile(FILE_PREDICATE
) || getDef(d
)->inFile(FILE_FLAGS
))
874 insnCheckCommutationDefSrc(const Instruction
*a
, const Instruction
*b
)
876 for (int d
= 0; a
->defExists(d
); ++d
)
877 for (int s
= 0; b
->srcExists(s
); ++s
)
878 if (a
->getDef(d
)->interfers(b
->getSrc(s
)))
884 insnCheckCommutationDefDef(const Instruction
*a
, const Instruction
*b
)
886 for (int d
= 0; a
->defExists(d
); ++d
)
887 for (int c
= 0; b
->defExists(c
); ++c
)
888 if (a
->getDef(d
)->interfers(b
->getDef(c
)))
894 Instruction::isCommutationLegal(const Instruction
*i
) const
896 bool ret
= insnCheckCommutationDefDef(this, i
);
897 ret
= ret
&& insnCheckCommutationDefSrc(this, i
);
898 ret
= ret
&& insnCheckCommutationDefSrc(i
, this);
902 TexInstruction::TexInstruction(Function
*fn
, operation op
)
903 : Instruction(fn
, op
, TYPE_F32
)
905 memset(&tex
, 0, sizeof(tex
));
907 tex
.rIndirectSrc
= -1;
908 tex
.sIndirectSrc
= -1;
911 TexInstruction::~TexInstruction()
913 for (int c
= 0; c
< 3; ++c
) {
917 for (int n
= 0; n
< 4; ++n
)
918 for (int c
= 0; c
< 3; ++c
)
919 offset
[n
][c
].set(NULL
);
923 TexInstruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
925 TexInstruction
*tex
= (i
? static_cast<TexInstruction
*>(i
) :
926 new_TexInstruction(pol
.context(), op
));
928 Instruction::clone(pol
, tex
);
930 tex
->tex
= this->tex
;
933 for (unsigned int c
= 0; c
< tex
->tex
.target
.getDim(); ++c
) {
934 tex
->dPdx
[c
].set(dPdx
[c
]);
935 tex
->dPdy
[c
].set(dPdy
[c
]);
939 for (int n
= 0; n
< tex
->tex
.useOffsets
; ++n
)
940 for (int c
= 0; c
< 3; ++c
)
941 tex
->offset
[n
][c
].set(offset
[n
][c
]);
946 const struct TexInstruction::Target::Desc
TexInstruction::Target::descTable
[] =
948 { "1D", 1, 1, false, false, false },
949 { "2D", 2, 2, false, false, false },
950 { "2D_MS", 2, 3, false, false, false },
951 { "3D", 3, 3, false, false, false },
952 { "CUBE", 2, 3, false, true, false },
953 { "1D_SHADOW", 1, 1, false, false, true },
954 { "2D_SHADOW", 2, 2, false, false, true },
955 { "CUBE_SHADOW", 2, 3, false, true, true },
956 { "1D_ARRAY", 1, 2, true, false, false },
957 { "2D_ARRAY", 2, 3, true, false, false },
958 { "2D_MS_ARRAY", 2, 4, true, false, false },
959 { "CUBE_ARRAY", 2, 4, true, true, false },
960 { "1D_ARRAY_SHADOW", 1, 2, true, false, true },
961 { "2D_ARRAY_SHADOW", 2, 3, true, false, true },
962 { "RECT", 2, 2, false, false, false },
963 { "RECT_SHADOW", 2, 2, false, false, true },
964 { "CUBE_ARRAY_SHADOW", 2, 4, true, true, true },
965 { "BUFFER", 1, 1, false, false, false },
969 TexInstruction::setIndirectR(Value
*v
)
971 int p
= ((tex
.rIndirectSrc
< 0) && v
) ? srcs
.size() : tex
.rIndirectSrc
;
973 tex
.rIndirectSrc
= p
;
975 srcs
[p
].usedAsPtr
= !!v
;
980 TexInstruction::setIndirectS(Value
*v
)
982 int p
= ((tex
.sIndirectSrc
< 0) && v
) ? srcs
.size() : tex
.sIndirectSrc
;
984 tex
.sIndirectSrc
= p
;
986 srcs
[p
].usedAsPtr
= !!v
;
990 CmpInstruction::CmpInstruction(Function
*fn
, operation op
)
991 : Instruction(fn
, op
, TYPE_F32
)
997 CmpInstruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
999 CmpInstruction
*cmp
= (i
? static_cast<CmpInstruction
*>(i
) :
1000 new_CmpInstruction(pol
.context(), op
));
1002 Instruction::clone(pol
, cmp
);
1003 cmp
->setCond
= setCond
;
1007 FlowInstruction::FlowInstruction(Function
*fn
, operation op
, void *targ
)
1008 : Instruction(fn
, op
, TYPE_NONE
)
1011 target
.fn
= reinterpret_cast<Function
*>(targ
);
1013 target
.bb
= reinterpret_cast<BasicBlock
*>(targ
);
1016 op
== OP_CONT
|| op
== OP_BREAK
||
1017 op
== OP_RET
|| op
== OP_EXIT
)
1021 terminator
= targ
? 1 : 0;
1023 allWarp
= absolute
= limit
= builtin
= indirect
= 0;
1027 FlowInstruction::clone(ClonePolicy
<Function
>& pol
, Instruction
*i
) const
1029 FlowInstruction
*flow
= (i
? static_cast<FlowInstruction
*>(i
) :
1030 new_FlowInstruction(pol
.context(), op
, NULL
));
1032 Instruction::clone(pol
, flow
);
1033 flow
->allWarp
= allWarp
;
1034 flow
->absolute
= absolute
;
1035 flow
->limit
= limit
;
1036 flow
->builtin
= builtin
;
1039 flow
->target
.builtin
= target
.builtin
;
1042 flow
->target
.fn
= target
.fn
;
1045 flow
->target
.bb
= pol
.get
<BasicBlock
>(target
.bb
);
1050 Program::Program(Type type
, Target
*arch
)
1053 mem_Instruction(sizeof(Instruction
), 6),
1054 mem_CmpInstruction(sizeof(CmpInstruction
), 4),
1055 mem_TexInstruction(sizeof(TexInstruction
), 4),
1056 mem_FlowInstruction(sizeof(FlowInstruction
), 4),
1057 mem_LValue(sizeof(LValue
), 8),
1058 mem_Symbol(sizeof(Symbol
), 7),
1059 mem_ImmediateValue(sizeof(ImmediateValue
), 7)
1066 main
= new Function(this, "MAIN", ~0);
1067 calls
.insert(&main
->call
);
1077 for (ArrayList::Iterator it
= allFuncs
.iterator(); !it
.end(); it
.next())
1078 delete reinterpret_cast<Function
*>(it
.get());
1080 for (ArrayList::Iterator it
= allRValues
.iterator(); !it
.end(); it
.next())
1081 releaseValue(reinterpret_cast<Value
*>(it
.get()));
1084 void Program::releaseInstruction(Instruction
*insn
)
1086 // TODO: make this not suck so much
1088 insn
->~Instruction();
1091 mem_CmpInstruction
.release(insn
);
1094 mem_TexInstruction
.release(insn
);
1097 mem_FlowInstruction
.release(insn
);
1099 mem_Instruction
.release(insn
);
1102 void Program::releaseValue(Value
*value
)
1106 if (value
->asLValue())
1107 mem_LValue
.release(value
);
1110 mem_ImmediateValue
.release(value
);
1113 mem_Symbol
.release(value
);
1117 } // namespace nv50_ir
1122 nv50_ir_init_prog_info(struct nv50_ir_prog_info
*info
)
1124 #if defined(PIPE_SHADER_HULL) && defined(PIPE_SHADER_DOMAIN)
1125 if (info
->type
== PIPE_SHADER_HULL
|| info
->type
== PIPE_SHADER_DOMAIN
) {
1126 info
->prop
.tp
.domain
= PIPE_PRIM_MAX
;
1127 info
->prop
.tp
.outputPrim
= PIPE_PRIM_MAX
;
1130 if (info
->type
== PIPE_SHADER_GEOMETRY
) {
1131 info
->prop
.gp
.instanceCount
= 1;
1132 info
->prop
.gp
.maxVertices
= 1;
1134 info
->io
.pointSize
= 0xff;
1135 info
->io
.instanceId
= 0xff;
1136 info
->io
.vertexId
= 0xff;
1137 info
->io
.edgeFlagIn
= 0xff;
1138 info
->io
.edgeFlagOut
= 0xff;
1139 info
->io
.fragDepth
= 0xff;
1140 info
->io
.sampleMask
= 0xff;
1141 info
->io
.backFaceColor
[0] = info
->io
.backFaceColor
[1] = 0xff;
1145 nv50_ir_generate_code(struct nv50_ir_prog_info
*info
)
1149 nv50_ir::Program::Type type
;
1151 nv50_ir_init_prog_info(info
);
1153 #define PROG_TYPE_CASE(a, b) \
1154 case PIPE_SHADER_##a: type = nv50_ir::Program::TYPE_##b; break
1156 switch (info
->type
) {
1157 PROG_TYPE_CASE(VERTEX
, VERTEX
);
1158 PROG_TYPE_CASE(TESS_CTRL
, TESSELLATION_CONTROL
);
1159 PROG_TYPE_CASE(TESS_EVAL
, TESSELLATION_EVAL
);
1160 PROG_TYPE_CASE(GEOMETRY
, GEOMETRY
);
1161 PROG_TYPE_CASE(FRAGMENT
, FRAGMENT
);
1162 PROG_TYPE_CASE(COMPUTE
, COMPUTE
);
1164 type
= nv50_ir::Program::TYPE_COMPUTE
;
1167 INFO_DBG(info
->dbgFlags
, VERBOSE
, "translating program of type %u\n", type
);
1169 nv50_ir::Target
*targ
= nv50_ir::Target::create(info
->target
);
1173 nv50_ir::Program
*prog
= new nv50_ir::Program(type
, targ
);
1176 prog
->driver
= info
;
1177 prog
->dbgFlags
= info
->dbgFlags
;
1178 prog
->optLevel
= info
->optLevel
;
1180 switch (info
->bin
.sourceRep
) {
1186 ret
= prog
->makeFromSM4(info
) ? 0 : -2;
1191 ret
= prog
->makeFromTGSI(info
) ? 0 : -2;
1196 if (prog
->dbgFlags
& NV50_IR_DEBUG_VERBOSE
)
1199 targ
->parseDriverInfo(info
);
1200 prog
->getTarget()->runLegalizePass(prog
, nv50_ir::CG_STAGE_PRE_SSA
);
1202 prog
->convertToSSA();
1204 if (prog
->dbgFlags
& NV50_IR_DEBUG_VERBOSE
)
1207 prog
->optimizeSSA(info
->optLevel
);
1208 prog
->getTarget()->runLegalizePass(prog
, nv50_ir::CG_STAGE_SSA
);
1210 if (prog
->dbgFlags
& NV50_IR_DEBUG_BASIC
)
1213 if (!prog
->registerAllocation()) {
1217 prog
->getTarget()->runLegalizePass(prog
, nv50_ir::CG_STAGE_POST_RA
);
1219 prog
->optimizePostRA(info
->optLevel
);
1221 if (!prog
->emitBinary(info
)) {
1227 INFO_DBG(prog
->dbgFlags
, VERBOSE
, "nv50_ir_generate_code: ret = %i\n", ret
);
1229 info
->bin
.maxGPR
= prog
->maxGPR
;
1230 info
->bin
.code
= prog
->code
;
1231 info
->bin
.codeSize
= prog
->binSize
;
1232 info
->bin
.tlsSpace
= prog
->tlsSize
;
1235 nv50_ir::Target::destroy(targ
);