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.
33 #include "codegen/nv50_ir_util.h"
34 #include "codegen/nv50_ir_graph.h"
36 #include "codegen/nv50_ir_driver.h"
44 OP_UNION
, // unify a new definition and several source values
45 OP_SPLIT
, // $r0d -> { $r0, $r1 } ($r0d and $r0/$r1 will be coalesced)
46 OP_MERGE
, // opposite of split, e.g. combine 2 32 bit into a 64 bit value
47 OP_CONSTRAINT
, // copy values into consecutive registers
48 OP_MOV
, // simple copy, no modifiers allowed
51 OP_ADD
, // NOTE: add u64 + u32 is legal for targets w/o 64-bit integer adds
58 OP_SAD
, // abs(src0 - src1) + src2
69 OP_SAT
, // CLAMP(f32, 0.0, 1.0)
74 OP_SET_AND
, // dst = (src0 CMP src1) & src2
78 OP_SELP
, // dst = src2 ? src0 : src1
79 OP_SLCT
, // dst = (src2 CMP 0) ? src0 : src1
86 OP_EXP
, // exponential (base M_E)
87 OP_LOG
, // natural logarithm
100 OP_BRKPT
, // breakpoint (not related to loops)
101 OP_JOINAT
, // push control flow convergence point
105 OP_MEMBAR
, // memory barrier (mfence, lfence, sfence)
106 OP_VFETCH
, // indirection 0 in attribute space, indirection 1 is vertex base
107 OP_PFETCH
, // fetch base address of vertex src0 (immediate) [+ src1]
111 OP_EMIT
, // emit vertex
112 OP_RESTART
, // restart primitive
114 OP_TXB
, // texture bias
115 OP_TXL
, // texure lod
116 OP_TXF
, // texel fetch
117 OP_TXQ
, // texture size query
118 OP_TXD
, // texture derivatives
119 OP_TXG
, // texture gather
120 OP_TXLQ
, // texture query lod
121 OP_TEXCSAA
, // texture op for coverage sampling
122 OP_TEXPREP
, // turn cube map array into 2d array coordinates
123 OP_SULDB
, // surface load (raw)
124 OP_SULDP
, // surface load (formatted)
125 OP_SUSTB
, // surface store (raw)
126 OP_SUSTP
, // surface store (formatted)
128 OP_SUREDP
, // surface reduction (atomic op)
129 OP_SULEA
, // surface load effective address
130 OP_SUBFM
, // surface bitfield manipulation
131 OP_SUCLAMP
, // clamp surface coordinates
132 OP_SUEAU
, // surface effective address
133 OP_MADSP
, // special integer multiply-add
134 OP_TEXBAR
, // texture dependency barrier
137 OP_RDSV
, // read system value
138 OP_WRSV
, // write system value
142 OP_POPCNT
, // bitcount(src0 & src1)
143 OP_INSBF
, // insert first src1[8:15] bits of src0 into src2 at src1[0:7]
144 OP_EXTBF
, // place bits [K,K+N) of src0 into dst, src1 = 0xNNKK
145 OP_PERMT
, // dst = bytes from src2,src0 selected by src1 (nvc0's src order)
147 OP_BAR
, // execution barrier, sources = { id, thread count, predicate }
148 OP_VADD
, // byte/word vector operations
157 OP_CCTL
, // cache control
161 // various instruction-specific modifier definitions Instruction::subOp
162 // MOV_FINAL marks a MOV originating from an EXPORT (used for placing TEXBARs)
163 #define NV50_IR_SUBOP_MUL_HIGH 1
164 #define NV50_IR_SUBOP_EMIT_RESTART 1
165 #define NV50_IR_SUBOP_LDC_IL 1
166 #define NV50_IR_SUBOP_LDC_IS 2
167 #define NV50_IR_SUBOP_LDC_ISL 3
168 #define NV50_IR_SUBOP_SHIFT_WRAP 1
169 #define NV50_IR_SUBOP_EMU_PRERET 1
170 #define NV50_IR_SUBOP_TEXBAR(n) n
171 #define NV50_IR_SUBOP_MOV_FINAL 1
172 #define NV50_IR_SUBOP_EXTBF_REV 1
173 #define NV50_IR_SUBOP_PERMT_F4E 1
174 #define NV50_IR_SUBOP_PERMT_B4E 2
175 #define NV50_IR_SUBOP_PERMT_RC8 3
176 #define NV50_IR_SUBOP_PERMT_ECL 4
177 #define NV50_IR_SUBOP_PERMT_ECR 5
178 #define NV50_IR_SUBOP_PERMT_RC16 6
179 #define NV50_IR_SUBOP_BAR_SYNC 0
180 #define NV50_IR_SUBOP_BAR_ARRIVE 1
181 #define NV50_IR_SUBOP_BAR_RED_AND 2
182 #define NV50_IR_SUBOP_BAR_RED_OR 3
183 #define NV50_IR_SUBOP_BAR_RED_POPC 4
184 #define NV50_IR_SUBOP_MEMBAR_L 1
185 #define NV50_IR_SUBOP_MEMBAR_S 2
186 #define NV50_IR_SUBOP_MEMBAR_M 3
187 #define NV50_IR_SUBOP_MEMBAR_CTA (0 << 2)
188 #define NV50_IR_SUBOP_MEMBAR_GL (1 << 2)
189 #define NV50_IR_SUBOP_MEMBAR_SYS (2 << 2)
190 #define NV50_IR_SUBOP_MEMBAR_DIR(m) ((m) & 0x3)
191 #define NV50_IR_SUBOP_MEMBAR_SCOPE(m) ((m) & ~0x3)
192 #define NV50_IR_SUBOP_MEMBAR(d,s) \
193 (NV50_IR_SUBOP_MEMBAR_##d | NV50_IR_SUBOP_MEMBAR_##s)
194 #define NV50_IR_SUBOP_ATOM_ADD 0
195 #define NV50_IR_SUBOP_ATOM_MIN 1
196 #define NV50_IR_SUBOP_ATOM_MAX 2
197 #define NV50_IR_SUBOP_ATOM_INC 3
198 #define NV50_IR_SUBOP_ATOM_DEC 4
199 #define NV50_IR_SUBOP_ATOM_AND 5
200 #define NV50_IR_SUBOP_ATOM_OR 6
201 #define NV50_IR_SUBOP_ATOM_XOR 7
202 #define NV50_IR_SUBOP_ATOM_CAS 8
203 #define NV50_IR_SUBOP_ATOM_EXCH 9
204 #define NV50_IR_SUBOP_CCTL_IV 5
205 #define NV50_IR_SUBOP_CCTL_IVALL 6
206 #define NV50_IR_SUBOP_SUST_IGN 0
207 #define NV50_IR_SUBOP_SUST_TRAP 1
208 #define NV50_IR_SUBOP_SUST_SDCL 3
209 #define NV50_IR_SUBOP_SULD_ZERO 0
210 #define NV50_IR_SUBOP_SULD_TRAP 1
211 #define NV50_IR_SUBOP_SULD_SDCL 3
212 #define NV50_IR_SUBOP_SUBFM_3D 1
213 #define NV50_IR_SUBOP_SUCLAMP_2D 0x10
214 #define NV50_IR_SUBOP_SUCLAMP_SD(r, d) (( 0 + (r)) | ((d == 2) ? 0x10 : 0))
215 #define NV50_IR_SUBOP_SUCLAMP_PL(r, d) (( 5 + (r)) | ((d == 2) ? 0x10 : 0))
216 #define NV50_IR_SUBOP_SUCLAMP_BL(r, d) ((10 + (r)) | ((d == 2) ? 0x10 : 0))
217 #define NV50_IR_SUBOP_MADSP_SD 0xffff
218 // Yes, we could represent those with DataType.
219 // Or put the type into operation and have a couple 1000 values in that enum.
220 // This will have to do for now.
221 // The bitfields are supposed to correspond to nve4 ISA.
222 #define NV50_IR_SUBOP_MADSP(a,b,c) (((c) << 8) | ((b) << 4) | (a))
223 #define NV50_IR_SUBOP_V1(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x0000)
224 #define NV50_IR_SUBOP_V2(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x4000)
225 #define NV50_IR_SUBOP_V4(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x8000)
226 #define NV50_IR_SUBOP_Vn(n) ((n) >> 14)
237 TYPE_U64
, // 64 bit operations are only lowered after register allocation
249 CC_NEVER
= CC_FL
, // when used with FILE_FLAGS
252 CC_NOT_P
= CC_EQ
, // when used with FILE_PREDICATE
280 ROUND_M
, // towards -inf
281 ROUND_Z
, // towards 0
282 ROUND_P
, // towards +inf
283 ROUND_NI
, // nearest integer
284 ROUND_MI
, // to integer towards -inf
285 ROUND_ZI
, // to integer towards 0
286 ROUND_PI
, // to integer towards +inf
291 CACHE_CA
, // cache at all levels
292 CACHE_WB
= CACHE_CA
, // cache write back
293 CACHE_CG
, // cache at global level
294 CACHE_CS
, // cache streaming
295 CACHE_CV
, // cache as volatile
296 CACHE_WT
= CACHE_CV
// cache write-through
303 FILE_PREDICATE
, // boolean predicate
304 FILE_FLAGS
, // zero/sign/carry/overflow bits
306 LAST_REGISTER_FILE
= FILE_ADDRESS
,
325 TEX_TARGET_1D_SHADOW
,
326 TEX_TARGET_2D_SHADOW
,
327 TEX_TARGET_CUBE_SHADOW
,
330 TEX_TARGET_2D_MS_ARRAY
,
331 TEX_TARGET_CUBE_ARRAY
,
332 TEX_TARGET_1D_ARRAY_SHADOW
,
333 TEX_TARGET_2D_ARRAY_SHADOW
,
335 TEX_TARGET_RECT_SHADOW
,
336 TEX_TARGET_CUBE_ARRAY_SHADOW
,
348 SV_VERTEX_COUNT
, // gl_PatchVerticesIn
383 class CmpInstruction
;
384 class TexInstruction
;
385 class FlowInstruction
;
390 class ImmediateValue
;
395 int8_t fileIndex
; // signed, may be indirect for CONST[]
396 uint8_t size
; // this should match the Instruction type's size
397 DataType type
; // mainly for pretty printing
399 uint64_t u64
; // immediate values
409 int32_t offset
; // offset from 0 (base of address space)
410 int32_t id
; // register id (< 0 if virtual/unassigned, in units <= 4)
418 // precedence: NOT after SAT after NEG after ABS
419 #define NV50_IR_MOD_ABS (1 << 0)
420 #define NV50_IR_MOD_NEG (1 << 1)
421 #define NV50_IR_MOD_SAT (1 << 2)
422 #define NV50_IR_MOD_NOT (1 << 3)
423 #define NV50_IR_MOD_NEG_ABS (NV50_IR_MOD_NEG | NV50_IR_MOD_ABS)
425 #define NV50_IR_INTERP_MODE_MASK 0x3
426 #define NV50_IR_INTERP_LINEAR (0 << 0)
427 #define NV50_IR_INTERP_PERSPECTIVE (1 << 0)
428 #define NV50_IR_INTERP_FLAT (2 << 0)
429 #define NV50_IR_INTERP_SC (3 << 0) // what exactly is that ?
430 #define NV50_IR_INTERP_SAMPLE_MASK 0xc
431 #define NV50_IR_INTERP_DEFAULT (0 << 2)
432 #define NV50_IR_INTERP_CENTROID (1 << 2)
433 #define NV50_IR_INTERP_OFFSET (2 << 2)
434 #define NV50_IR_INTERP_SAMPLEID (3 << 2)
436 // do we really want this to be a class ?
440 Modifier() : bits(0) { }
441 Modifier(unsigned int m
) : bits(m
) { }
442 Modifier(operation op
);
444 // @return new Modifier applying a after b (asserts if unrepresentable)
445 Modifier
operator*(const Modifier
) const;
446 Modifier
operator*=(const Modifier m
) { *this = *this * m
; return *this; }
447 Modifier
operator==(const Modifier m
) const { return m
.bits
== bits
; }
448 Modifier
operator!=(const Modifier m
) const { return m
.bits
!= bits
; }
450 inline Modifier
operator&(const Modifier m
) const { return bits
& m
.bits
; }
451 inline Modifier
operator|(const Modifier m
) const { return bits
| m
.bits
; }
452 inline Modifier
operator^(const Modifier m
) const { return bits
^ m
.bits
; }
454 operation
getOp() const;
456 inline int neg() const { return (bits
& NV50_IR_MOD_NEG
) ? 1 : 0; }
457 inline int abs() const { return (bits
& NV50_IR_MOD_ABS
) ? 1 : 0; }
459 inline operator bool() const { return bits
? true : false; }
461 void applyTo(ImmediateValue
&imm
) const;
463 int print(char *buf
, size_t size
) const;
472 ValueRef(Value
* = NULL
);
473 ValueRef(const ValueRef
&);
476 inline bool exists() const { return value
!= NULL
; }
479 void set(const ValueRef
&);
480 inline Value
*get() const { return value
; }
481 inline Value
*rep() const;
483 inline Instruction
*getInsn() const { return insn
; }
484 inline void setInsn(Instruction
*inst
) { insn
= inst
; }
486 inline bool isIndirect(int dim
) const { return indirect
[dim
] >= 0; }
487 inline const ValueRef
*getIndirect(int dim
) const;
489 inline DataFile
getFile() const;
490 inline unsigned getSize() const;
492 // SSA: return eventual (traverse MOVs) literal value, if it exists
493 bool getImmediate(ImmediateValue
&) const;
497 int8_t indirect
[2]; // >= 0 if relative to lvalue in insn->src(indirect[i])
500 bool usedAsPtr
; // for printing
510 ValueDef(Value
* = NULL
);
511 ValueDef(const ValueDef
&);
514 inline bool exists() const { return value
!= NULL
; }
516 inline Value
*get() const { return value
; }
517 inline Value
*rep() const;
519 bool mayReplace(const ValueRef
&);
520 void replace(const ValueRef
&, bool doSet
); // replace all uses of the old value
522 inline Instruction
*getInsn() const { return insn
; }
523 inline void setInsn(Instruction
*inst
) { insn
= inst
; }
525 inline DataFile
getFile() const;
526 inline unsigned getSize() const;
528 inline void setSSA(LValue
*);
529 inline const LValue
*preSSA() const;
532 Value
*value
; // should make this LValue * ...
533 LValue
*origin
; // pre SSA value
543 virtual Value
*clone(ClonePolicy
<Function
>&) const = 0;
545 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const = 0;
547 virtual bool equals(const Value
*, bool strict
= false) const;
548 virtual bool interfers(const Value
*) const;
549 virtual bool isUniform() const { return true; }
551 inline Value
*rep() const { return join
; }
553 inline Instruction
*getUniqueInsn() const;
554 inline Instruction
*getInsn() const; // use when uniqueness is certain
556 inline int refCount() { return uses
.size(); }
558 inline LValue
*asLValue();
559 inline Symbol
*asSym();
560 inline ImmediateValue
*asImm();
561 inline const Symbol
*asSym() const;
562 inline const ImmediateValue
*asImm() const;
564 inline bool inFile(DataFile f
) { return reg
.file
== f
; }
566 static inline Value
*get(Iterator
&);
568 std::list
<ValueRef
*> uses
;
569 std::list
<ValueDef
*> defs
;
570 typedef std::list
<ValueRef
*>::iterator UseIterator
;
571 typedef std::list
<ValueRef
*>::const_iterator UseCIterator
;
572 typedef std::list
<ValueDef
*>::iterator DefIterator
;
573 typedef std::list
<ValueDef
*>::const_iterator DefCIterator
;
578 // TODO: these should be in LValue:
583 class LValue
: public Value
586 LValue(Function
*, DataFile file
);
587 LValue(Function
*, LValue
*);
590 virtual bool isUniform() const;
592 virtual LValue
*clone(ClonePolicy
<Function
>&) const;
594 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
597 unsigned compMask
: 8; // compound/component mask
598 unsigned compound
: 1; // used by RA, value involved in split/merge
600 unsigned fixedReg
: 1; // set & used by RA, earlier just use (id < 0)
601 unsigned noSpill
: 1; // do not spill (e.g. if spill temporary already)
604 class Symbol
: public Value
607 Symbol(Program
*, DataFile file
= FILE_MEMORY_CONST
, ubyte fileIdx
= 0);
610 virtual Symbol
*clone(ClonePolicy
<Function
>&) const;
612 virtual bool equals(const Value
*that
, bool strict
) const;
614 virtual bool isUniform() const;
616 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
618 // print with indirect values
619 int print(char *, size_t, Value
*, Value
*, DataType ty
= TYPE_NONE
) const;
621 inline void setFile(DataFile file
, ubyte fileIndex
= 0)
624 reg
.fileIndex
= fileIndex
;
627 inline void setOffset(int32_t offset
);
628 inline void setAddress(Symbol
*base
, int32_t offset
);
629 inline void setSV(SVSemantic sv
, uint32_t idx
= 0);
631 inline const Symbol
*getBase() const { return baseSym
; }
634 Symbol
*baseSym
; // array base for Symbols representing array elements
637 class ImmediateValue
: public Value
641 ImmediateValue(Program
*, uint32_t);
642 ImmediateValue(Program
*, float);
643 ImmediateValue(Program
*, double);
644 // NOTE: not added to program with
645 ImmediateValue(const ImmediateValue
*, DataType ty
);
646 ~ImmediateValue() { };
648 virtual ImmediateValue
*clone(ClonePolicy
<Function
>&) const;
650 virtual bool equals(const Value
*that
, bool strict
) const;
652 // these only work if 'type' is valid (we mostly use untyped literals):
653 bool isInteger(const int ival
) const; // ival is cast to this' type
654 bool isNegative() const;
659 // for constant folding:
660 ImmediateValue
operator+(const ImmediateValue
&) const;
661 ImmediateValue
operator-(const ImmediateValue
&) const;
662 ImmediateValue
operator*(const ImmediateValue
&) const;
663 ImmediateValue
operator/(const ImmediateValue
&) const;
665 ImmediateValue
& operator=(const ImmediateValue
&); // only sets value !
667 bool compare(CondCode cc
, float fval
) const;
669 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
676 Instruction(Function
*, operation
, DataType
);
677 virtual ~Instruction();
679 virtual Instruction
*clone(ClonePolicy
<Function
>&,
680 Instruction
* = NULL
) const;
682 void setDef(int i
, Value
*);
683 void setSrc(int s
, Value
*);
684 void setSrc(int s
, const ValueRef
&);
685 void swapSources(int a
, int b
);
686 void moveSources(int s
, int delta
);
687 bool setIndirect(int s
, int dim
, Value
*);
689 inline ValueRef
& src(int s
) { return srcs
[s
]; }
690 inline ValueDef
& def(int s
) { return defs
[s
]; }
691 inline const ValueRef
& src(int s
) const { return srcs
[s
]; }
692 inline const ValueDef
& def(int s
) const { return defs
[s
]; }
694 inline Value
*getDef(int d
) const { return defs
[d
].get(); }
695 inline Value
*getSrc(int s
) const { return srcs
[s
].get(); }
696 inline Value
*getIndirect(int s
, int dim
) const;
698 inline bool defExists(unsigned d
) const
700 return d
< defs
.size() && defs
[d
].exists();
702 inline bool srcExists(unsigned s
) const
704 return s
< srcs
.size() && srcs
[s
].exists();
707 inline bool constrainedDefs() const;
709 bool setPredicate(CondCode ccode
, Value
*);
710 inline Value
*getPredicate() const;
711 bool writesPredicate() const;
712 inline bool isPredicated() const { return predSrc
>= 0; }
714 inline void setFlagsSrc(int s
, Value
*);
715 inline void setFlagsDef(int d
, Value
*);
716 inline bool usesFlags() const { return flagsSrc
>= 0; }
718 unsigned int defCount() const { return defs
.size(); };
719 unsigned int defCount(unsigned int mask
, bool singleFile
= false) const;
720 unsigned int srcCount() const { return srcs
.size(); };
721 unsigned int srcCount(unsigned int mask
, bool singleFile
= false) const;
723 // save & remove / set indirect[0,1] and predicate source
724 void takeExtraSources(int s
, Value
*[3]);
725 void putExtraSources(int s
, Value
*[3]);
727 inline void setType(DataType type
) { dType
= sType
= type
; }
729 inline void setType(DataType dtype
, DataType stype
)
735 inline bool isPseudo() const { return op
< OP_MOV
; }
738 bool isCommutationLegal(const Instruction
*) const; // must be adjacent !
739 bool isActionEqual(const Instruction
*) const;
740 bool isResultEqual(const Instruction
*) const;
744 inline CmpInstruction
*asCmp();
745 inline TexInstruction
*asTex();
746 inline FlowInstruction
*asFlow();
747 inline const TexInstruction
*asTex() const;
748 inline const CmpInstruction
*asCmp() const;
749 inline const FlowInstruction
*asFlow() const;
755 int serial
; // CFG order
758 DataType dType
; // destination or defining type
759 DataType sType
; // source or secondary type
764 uint16_t subOp
; // quadop, 1 for mul-high, etc.
766 unsigned encSize
: 4; // encoding size in bytes
767 unsigned saturate
: 1; // to [0.0f, 1.0f]
768 unsigned join
: 1; // converge control flow (use OP_JOIN until end)
769 unsigned fixed
: 1; // prevent dead code elimination
770 unsigned terminator
: 1; // end of basic block
771 unsigned ftz
: 1; // flush denormal to zero
772 unsigned dnz
: 1; // denormals, NaN are zero
773 unsigned ipa
: 4; // interpolation mode
775 unsigned perPatch
: 1;
776 unsigned exit
: 1; // terminate program after insn
777 unsigned mask
: 4; // for vector ops
779 int8_t postFactor
; // MUL/DIV(if < 0) by 1 << postFactor
785 uint8_t sched
; // scheduling data (NOTE: maybe move to separate storage)
790 std::deque
<ValueDef
> defs
; // no gaps !
791 std::deque
<ValueRef
> srcs
; // no gaps !
793 // instruction specific methods:
794 // (don't want to subclass, would need more constructors and memory pools)
796 inline void setInterpolate(unsigned int mode
) { ipa
= mode
; }
798 unsigned int getInterpMode() const { return ipa
& 0x3; }
799 unsigned int getSampleMode() const { return ipa
& 0xc; }
816 class TexInstruction
: public Instruction
822 Target(TexTarget targ
= TEX_TARGET_2D
) : target(targ
) { }
824 const char *getName() const { return descTable
[target
].name
; }
825 unsigned int getArgCount() const { return descTable
[target
].argc
; }
826 unsigned int getDim() const { return descTable
[target
].dim
; }
827 int isArray() const { return descTable
[target
].array
? 1 : 0; }
828 int isCube() const { return descTable
[target
].cube
? 1 : 0; }
829 int isShadow() const { return descTable
[target
].shadow
? 1 : 0; }
831 return target
== TEX_TARGET_2D_MS
|| target
== TEX_TARGET_2D_MS_ARRAY
; }
835 target
= TEX_TARGET_2D_ARRAY
;
837 target
= TEX_TARGET_2D
;
841 Target
& operator=(TexTarget targ
)
843 assert(targ
< TEX_TARGET_COUNT
);
848 inline bool operator==(TexTarget targ
) const { return target
== targ
; }
849 inline bool operator!=(TexTarget targ
) const { return target
!= targ
; }
851 enum TexTarget
getEnum() const { return target
; }
864 static const struct Desc descTable
[TEX_TARGET_COUNT
];
867 enum TexTarget target
;
871 TexInstruction(Function
*, operation
);
872 virtual ~TexInstruction();
874 virtual TexInstruction
*clone(ClonePolicy
<Function
>&,
875 Instruction
* = NULL
) const;
877 inline void setTexture(Target targ
, uint8_t r
, uint8_t s
)
884 void setIndirectR(Value
*);
885 void setIndirectS(Value
*);
886 inline Value
*getIndirectR() const;
887 inline Value
*getIndirectS() const;
901 bool liveOnly
; // only execute on live pixels of a quad (optimization)
905 int8_t useOffsets
; // 0, 1, or 4 for textureGatherOffsets
915 class CmpInstruction
: public Instruction
918 CmpInstruction(Function
*, operation
);
920 virtual CmpInstruction
*clone(ClonePolicy
<Function
>&,
921 Instruction
* = NULL
) const;
923 void setCondition(CondCode cond
) { setCond
= cond
; }
924 CondCode
getCondition() const { return setCond
; }
930 class FlowInstruction
: public Instruction
933 FlowInstruction(Function
*, operation
, void *target
);
935 virtual FlowInstruction
*clone(ClonePolicy
<Function
>&,
936 Instruction
* = NULL
) const;
939 unsigned allWarp
: 1;
940 unsigned absolute
: 1;
942 unsigned builtin
: 1; // true for calls to emulation code
943 unsigned indirect
: 1; // target in src(0)
955 BasicBlock(Function
*);
958 BasicBlock
*clone(ClonePolicy
<Function
>&) const;
960 inline int getId() const { return id
; }
961 inline unsigned int getInsnCount() const { return numInsns
; }
962 inline bool isTerminated() const { return exit
&& exit
->terminator
; }
964 bool dominatedBy(BasicBlock
*bb
);
965 inline bool reachableBy(const BasicBlock
*by
, const BasicBlock
*term
);
967 // returns mask of conditional out blocks
968 // e.g. 3 for IF { .. } ELSE { .. } ENDIF, 1 for IF { .. } ENDIF
969 unsigned int initiatesSimpleConditional() const;
972 Function
*getFunction() const { return func
; }
973 Program
*getProgram() const { return program
; }
975 Instruction
*getEntry() const { return entry
; } // first non-phi instruction
976 Instruction
*getPhi() const { return phi
; }
977 Instruction
*getFirst() const { return phi
? phi
: entry
; }
978 Instruction
*getExit() const { return exit
; }
980 void insertHead(Instruction
*);
981 void insertTail(Instruction
*);
982 void insertBefore(Instruction
*, Instruction
*);
983 void insertAfter(Instruction
*, Instruction
*);
984 void remove(Instruction
*);
985 void permuteAdjacent(Instruction
*, Instruction
*);
987 BasicBlock
*idom() const;
989 // NOTE: currently does not rebuild the dominator tree
990 BasicBlock
*splitBefore(Instruction
*, bool attach
= true);
991 BasicBlock
*splitAfter(Instruction
*, bool attach
= true);
993 DLList
& getDF() { return df
; }
994 DLList::Iterator
iterDF() { return df
.iterator(); }
996 static inline BasicBlock
*get(Iterator
&);
997 static inline BasicBlock
*get(Graph::Node
*);
1000 Graph::Node cfg
; // first edge is branch *taken* (the ELSE branch)
1009 Instruction
*joinAt
; // for quick reference
1011 bool explicitCont
; // loop headers: true if loop contains continue stmts
1021 unsigned int numInsns
;
1027 void splitCommon(Instruction
*, BasicBlock
*, bool attach
);
1033 Function(Program
*, const char *name
, uint32_t label
);
1036 static inline Function
*get(Graph::Node
*node
);
1038 inline Program
*getProgram() const { return prog
; }
1039 inline const char *getName() const { return name
; }
1040 inline int getId() const { return id
; }
1041 inline uint32_t getLabel() const { return label
; }
1044 void printLiveIntervals() const;
1045 void printCFGraph(const char *filePath
);
1047 bool setEntry(BasicBlock
*);
1048 bool setExit(BasicBlock
*);
1050 unsigned int orderInstructions(ArrayList
&);
1052 inline void add(BasicBlock
*bb
, int& id
) { allBBlocks
.insert(bb
, id
); }
1053 inline void add(Instruction
*insn
, int& id
) { allInsns
.insert(insn
, id
); }
1054 inline void add(LValue
*lval
, int& id
) { allLValues
.insert(lval
, id
); }
1056 inline LValue
*getLValue(int id
);
1058 void buildLiveSets();
1059 void buildDefSets();
1060 bool convertToSSA();
1063 std::deque
<ValueDef
> ins
;
1064 std::deque
<ValueRef
> outs
;
1065 std::deque
<Value
*> clobbers
;
1068 Graph::Node
*cfgExit
;
1070 Graph::Node call
; // node in the call graph
1072 BasicBlock
**bbArray
; // BBs in emission order
1075 unsigned int loopNestingBound
;
1083 uint32_t tlsBase
; // base address for l[] space (if no stack pointer is used)
1086 ArrayList allBBlocks
;
1088 ArrayList allLValues
;
1091 void buildLiveSetsPreSSA(BasicBlock
*, const int sequence
);
1092 void buildDefSetsPreSSA(BasicBlock
*bb
, const int seq
);
1097 const char *const name
;
1104 CG_STAGE_SSA
, // expected directly before register allocation
1114 TYPE_TESSELLATION_CONTROL
,
1115 TYPE_TESSELLATION_EVAL
,
1121 Program(Type type
, Target
*targ
);
1126 Type
getType() const { return progType
; }
1128 inline void add(Function
*fn
, int& id
) { allFuncs
.insert(fn
, id
); }
1129 inline void del(Function
*fn
, int& id
) { allFuncs
.remove(id
); }
1130 inline void add(Value
*rval
, int& id
) { allRValues
.insert(rval
, id
); }
1132 bool makeFromTGSI(struct nv50_ir_prog_info
*);
1133 bool makeFromSM4(struct nv50_ir_prog_info
*);
1134 bool convertToSSA();
1135 bool optimizeSSA(int level
);
1136 bool optimizePostRA(int level
);
1137 bool registerAllocation();
1138 bool emitBinary(struct nv50_ir_prog_info
*);
1140 const Target
*getTarget() const { return target
; }
1143 void emitSymbolTable(struct nv50_ir_prog_info
*);
1153 ArrayList allRValues
;
1157 uint32_t tlsSize
; // size required for FILE_MEMORY_LOCAL
1161 MemoryPool mem_Instruction
;
1162 MemoryPool mem_CmpInstruction
;
1163 MemoryPool mem_TexInstruction
;
1164 MemoryPool mem_FlowInstruction
;
1165 MemoryPool mem_LValue
;
1166 MemoryPool mem_Symbol
;
1167 MemoryPool mem_ImmediateValue
;
1172 void *targetPriv
; // e.g. to carry information between passes
1174 const struct nv50_ir_prog_info
*driver
; // for driver configuration
1176 void releaseInstruction(Instruction
*);
1177 void releaseValue(Value
*);
1180 // TODO: add const version
1184 bool run(Program
*, bool ordered
= false, bool skipPhi
= false);
1185 bool run(Function
*, bool ordered
= false, bool skipPhi
= false);
1188 // return false to continue with next entity on next higher level
1189 virtual bool visit(Function
*) { return true; }
1190 virtual bool visit(BasicBlock
*) { return true; }
1191 virtual bool visit(Instruction
*) { return false; }
1193 bool doRun(Program
*, bool ordered
, bool skipPhi
);
1194 bool doRun(Function
*, bool ordered
, bool skipPhi
);
1202 // =============================================================================
1204 #include "codegen/nv50_ir_inlines.h"
1206 } // namespace nv50_ir
1208 #endif // __NV50_IR_H__