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_TEXCSAA
, // texture op for coverage sampling
121 OP_TEXPREP
, // turn cube map array into 2d array coordinates
122 OP_SULDB
, // surface load (raw)
123 OP_SULDP
, // surface load (formatted)
124 OP_SUSTB
, // surface store (raw)
125 OP_SUSTP
, // surface store (formatted)
127 OP_SUREDP
, // surface reduction (atomic op)
128 OP_SULEA
, // surface load effective address
129 OP_SUBFM
, // surface bitfield manipulation
130 OP_SUCLAMP
, // clamp surface coordinates
131 OP_SUEAU
, // surface effective address
132 OP_MADSP
, // special integer multiply-add
133 OP_TEXBAR
, // texture dependency barrier
136 OP_RDSV
, // read system value
137 OP_WRSV
, // write system value
141 OP_POPCNT
, // bitcount(src0 & src1)
142 OP_INSBF
, // insert first src1[8:15] bits of src0 into src2 at src1[0:7]
143 OP_EXTBF
, // place bits [K,K+N) of src0 into dst, src1 = 0xNNKK
144 OP_PERMT
, // dst = bytes from src2,src0 selected by src1 (nvc0's src order)
146 OP_BAR
, // execution barrier, sources = { id, thread count, predicate }
147 OP_VADD
, // byte/word vector operations
156 OP_CCTL
, // cache control
160 // various instruction-specific modifier definitions Instruction::subOp
161 // MOV_FINAL marks a MOV originating from an EXPORT (used for placing TEXBARs)
162 #define NV50_IR_SUBOP_MUL_HIGH 1
163 #define NV50_IR_SUBOP_EMIT_RESTART 1
164 #define NV50_IR_SUBOP_LDC_IL 1
165 #define NV50_IR_SUBOP_LDC_IS 2
166 #define NV50_IR_SUBOP_LDC_ISL 3
167 #define NV50_IR_SUBOP_SHIFT_WRAP 1
168 #define NV50_IR_SUBOP_EMU_PRERET 1
169 #define NV50_IR_SUBOP_TEXBAR(n) n
170 #define NV50_IR_SUBOP_MOV_FINAL 1
171 #define NV50_IR_SUBOP_EXTBF_REV 1
172 #define NV50_IR_SUBOP_PERMT_F4E 1
173 #define NV50_IR_SUBOP_PERMT_B4E 2
174 #define NV50_IR_SUBOP_PERMT_RC8 3
175 #define NV50_IR_SUBOP_PERMT_ECL 4
176 #define NV50_IR_SUBOP_PERMT_ECR 5
177 #define NV50_IR_SUBOP_PERMT_RC16 6
178 #define NV50_IR_SUBOP_BAR_SYNC 0
179 #define NV50_IR_SUBOP_BAR_ARRIVE 1
180 #define NV50_IR_SUBOP_BAR_RED_AND 2
181 #define NV50_IR_SUBOP_BAR_RED_OR 3
182 #define NV50_IR_SUBOP_BAR_RED_POPC 4
183 #define NV50_IR_SUBOP_MEMBAR_L 1
184 #define NV50_IR_SUBOP_MEMBAR_S 2
185 #define NV50_IR_SUBOP_MEMBAR_M 3
186 #define NV50_IR_SUBOP_MEMBAR_CTA (0 << 2)
187 #define NV50_IR_SUBOP_MEMBAR_GL (1 << 2)
188 #define NV50_IR_SUBOP_MEMBAR_SYS (2 << 2)
189 #define NV50_IR_SUBOP_MEMBAR_DIR(m) ((m) & 0x3)
190 #define NV50_IR_SUBOP_MEMBAR_SCOPE(m) ((m) & ~0x3)
191 #define NV50_IR_SUBOP_MEMBAR(d,s) \
192 (NV50_IR_SUBOP_MEMBAR_##d | NV50_IR_SUBOP_MEMBAR_##s)
193 #define NV50_IR_SUBOP_ATOM_ADD 0
194 #define NV50_IR_SUBOP_ATOM_MIN 1
195 #define NV50_IR_SUBOP_ATOM_MAX 2
196 #define NV50_IR_SUBOP_ATOM_INC 3
197 #define NV50_IR_SUBOP_ATOM_DEC 4
198 #define NV50_IR_SUBOP_ATOM_AND 5
199 #define NV50_IR_SUBOP_ATOM_OR 6
200 #define NV50_IR_SUBOP_ATOM_XOR 7
201 #define NV50_IR_SUBOP_ATOM_CAS 8
202 #define NV50_IR_SUBOP_ATOM_EXCH 9
203 #define NV50_IR_SUBOP_CCTL_IV 5
204 #define NV50_IR_SUBOP_CCTL_IVALL 6
205 #define NV50_IR_SUBOP_SUST_IGN 0
206 #define NV50_IR_SUBOP_SUST_TRAP 1
207 #define NV50_IR_SUBOP_SUST_SDCL 3
208 #define NV50_IR_SUBOP_SULD_ZERO 0
209 #define NV50_IR_SUBOP_SULD_TRAP 1
210 #define NV50_IR_SUBOP_SULD_SDCL 3
211 #define NV50_IR_SUBOP_SUBFM_3D 1
212 #define NV50_IR_SUBOP_SUCLAMP_2D 0x10
213 #define NV50_IR_SUBOP_SUCLAMP_SD(r, d) (( 0 + (r)) | ((d == 2) ? 0x10 : 0))
214 #define NV50_IR_SUBOP_SUCLAMP_PL(r, d) (( 5 + (r)) | ((d == 2) ? 0x10 : 0))
215 #define NV50_IR_SUBOP_SUCLAMP_BL(r, d) ((10 + (r)) | ((d == 2) ? 0x10 : 0))
216 #define NV50_IR_SUBOP_MADSP_SD 0xffff
217 // Yes, we could represent those with DataType.
218 // Or put the type into operation and have a couple 1000 values in that enum.
219 // This will have to do for now.
220 // The bitfields are supposed to correspond to nve4 ISA.
221 #define NV50_IR_SUBOP_MADSP(a,b,c) (((c) << 8) | ((b) << 4) | (a))
222 #define NV50_IR_SUBOP_V1(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x0000)
223 #define NV50_IR_SUBOP_V2(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x4000)
224 #define NV50_IR_SUBOP_V4(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x8000)
225 #define NV50_IR_SUBOP_Vn(n) ((n) >> 14)
236 TYPE_U64
, // 64 bit operations are only lowered after register allocation
248 CC_NEVER
= CC_FL
, // when used with FILE_FLAGS
251 CC_NOT_P
= CC_EQ
, // when used with FILE_PREDICATE
279 ROUND_M
, // towards -inf
280 ROUND_Z
, // towards 0
281 ROUND_P
, // towards +inf
282 ROUND_NI
, // nearest integer
283 ROUND_MI
, // to integer towards -inf
284 ROUND_ZI
, // to integer towards 0
285 ROUND_PI
, // to integer towards +inf
290 CACHE_CA
, // cache at all levels
291 CACHE_WB
= CACHE_CA
, // cache write back
292 CACHE_CG
, // cache at global level
293 CACHE_CS
, // cache streaming
294 CACHE_CV
, // cache as volatile
295 CACHE_WT
= CACHE_CV
// cache write-through
302 FILE_PREDICATE
, // boolean predicate
303 FILE_FLAGS
, // zero/sign/carry/overflow bits
305 LAST_REGISTER_FILE
= FILE_ADDRESS
,
324 TEX_TARGET_1D_SHADOW
,
325 TEX_TARGET_2D_SHADOW
,
326 TEX_TARGET_CUBE_SHADOW
,
329 TEX_TARGET_2D_MS_ARRAY
,
330 TEX_TARGET_CUBE_ARRAY
,
331 TEX_TARGET_1D_ARRAY_SHADOW
,
332 TEX_TARGET_2D_ARRAY_SHADOW
,
334 TEX_TARGET_RECT_SHADOW
,
335 TEX_TARGET_CUBE_ARRAY_SHADOW
,
347 SV_VERTEX_COUNT
, // gl_PatchVerticesIn
381 class CmpInstruction
;
382 class TexInstruction
;
383 class FlowInstruction
;
388 class ImmediateValue
;
393 int8_t fileIndex
; // signed, may be indirect for CONST[]
394 uint8_t size
; // this should match the Instruction type's size
395 DataType type
; // mainly for pretty printing
397 uint64_t u64
; // immediate values
407 int32_t offset
; // offset from 0 (base of address space)
408 int32_t id
; // register id (< 0 if virtual/unassigned, in units <= 4)
416 // precedence: NOT after SAT after NEG after ABS
417 #define NV50_IR_MOD_ABS (1 << 0)
418 #define NV50_IR_MOD_NEG (1 << 1)
419 #define NV50_IR_MOD_SAT (1 << 2)
420 #define NV50_IR_MOD_NOT (1 << 3)
421 #define NV50_IR_MOD_NEG_ABS (NV50_IR_MOD_NEG | NV50_IR_MOD_ABS)
423 #define NV50_IR_INTERP_MODE_MASK 0x3
424 #define NV50_IR_INTERP_LINEAR (0 << 0)
425 #define NV50_IR_INTERP_PERSPECTIVE (1 << 0)
426 #define NV50_IR_INTERP_FLAT (2 << 0)
427 #define NV50_IR_INTERP_SC (3 << 0) // what exactly is that ?
428 #define NV50_IR_INTERP_SAMPLE_MASK 0xc
429 #define NV50_IR_INTERP_DEFAULT (0 << 2)
430 #define NV50_IR_INTERP_CENTROID (1 << 2)
431 #define NV50_IR_INTERP_OFFSET (2 << 2)
432 #define NV50_IR_INTERP_SAMPLEID (3 << 2)
434 // do we really want this to be a class ?
438 Modifier() : bits(0) { }
439 Modifier(unsigned int m
) : bits(m
) { }
440 Modifier(operation op
);
442 // @return new Modifier applying a after b (asserts if unrepresentable)
443 Modifier
operator*(const Modifier
) const;
444 Modifier
operator*=(const Modifier m
) { *this = *this * m
; return *this; }
445 Modifier
operator==(const Modifier m
) const { return m
.bits
== bits
; }
446 Modifier
operator!=(const Modifier m
) const { return m
.bits
!= bits
; }
448 inline Modifier
operator&(const Modifier m
) const { return bits
& m
.bits
; }
449 inline Modifier
operator|(const Modifier m
) const { return bits
| m
.bits
; }
450 inline Modifier
operator^(const Modifier m
) const { return bits
^ m
.bits
; }
452 operation
getOp() const;
454 inline int neg() const { return (bits
& NV50_IR_MOD_NEG
) ? 1 : 0; }
455 inline int abs() const { return (bits
& NV50_IR_MOD_ABS
) ? 1 : 0; }
457 inline operator bool() const { return bits
? true : false; }
459 void applyTo(ImmediateValue
&imm
) const;
461 int print(char *buf
, size_t size
) const;
470 ValueRef(Value
* = NULL
);
471 ValueRef(const ValueRef
&);
474 inline bool exists() const { return value
!= NULL
; }
477 void set(const ValueRef
&);
478 inline Value
*get() const { return value
; }
479 inline Value
*rep() const;
481 inline Instruction
*getInsn() const { return insn
; }
482 inline void setInsn(Instruction
*inst
) { insn
= inst
; }
484 inline bool isIndirect(int dim
) const { return indirect
[dim
] >= 0; }
485 inline const ValueRef
*getIndirect(int dim
) const;
487 inline DataFile
getFile() const;
488 inline unsigned getSize() const;
490 // SSA: return eventual (traverse MOVs) literal value, if it exists
491 bool getImmediate(ImmediateValue
&) const;
495 int8_t indirect
[2]; // >= 0 if relative to lvalue in insn->src(indirect[i])
498 bool usedAsPtr
; // for printing
508 ValueDef(Value
* = NULL
);
509 ValueDef(const ValueDef
&);
512 inline bool exists() const { return value
!= NULL
; }
514 inline Value
*get() const { return value
; }
515 inline Value
*rep() const;
517 bool mayReplace(const ValueRef
&);
518 void replace(const ValueRef
&, bool doSet
); // replace all uses of the old value
520 inline Instruction
*getInsn() const { return insn
; }
521 inline void setInsn(Instruction
*inst
) { insn
= inst
; }
523 inline DataFile
getFile() const;
524 inline unsigned getSize() const;
526 inline void setSSA(LValue
*);
527 inline const LValue
*preSSA() const;
530 Value
*value
; // should make this LValue * ...
531 LValue
*origin
; // pre SSA value
541 virtual Value
*clone(ClonePolicy
<Function
>&) const = 0;
543 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const = 0;
545 virtual bool equals(const Value
*, bool strict
= false) const;
546 virtual bool interfers(const Value
*) const;
547 virtual bool isUniform() const { return true; }
549 inline Value
*rep() const { return join
; }
551 inline Instruction
*getUniqueInsn() const;
552 inline Instruction
*getInsn() const; // use when uniqueness is certain
554 inline int refCount() { return uses
.size(); }
556 inline LValue
*asLValue();
557 inline Symbol
*asSym();
558 inline ImmediateValue
*asImm();
559 inline const Symbol
*asSym() const;
560 inline const ImmediateValue
*asImm() const;
562 inline bool inFile(DataFile f
) { return reg
.file
== f
; }
564 static inline Value
*get(Iterator
&);
566 std::list
<ValueRef
*> uses
;
567 std::list
<ValueDef
*> defs
;
568 typedef std::list
<ValueRef
*>::iterator UseIterator
;
569 typedef std::list
<ValueRef
*>::const_iterator UseCIterator
;
570 typedef std::list
<ValueDef
*>::iterator DefIterator
;
571 typedef std::list
<ValueDef
*>::const_iterator DefCIterator
;
576 // TODO: these should be in LValue:
581 class LValue
: public Value
584 LValue(Function
*, DataFile file
);
585 LValue(Function
*, LValue
*);
588 virtual bool isUniform() const;
590 virtual LValue
*clone(ClonePolicy
<Function
>&) const;
592 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
595 unsigned compMask
: 8; // compound/component mask
596 unsigned compound
: 1; // used by RA, value involved in split/merge
598 unsigned fixedReg
: 1; // set & used by RA, earlier just use (id < 0)
599 unsigned noSpill
: 1; // do not spill (e.g. if spill temporary already)
602 class Symbol
: public Value
605 Symbol(Program
*, DataFile file
= FILE_MEMORY_CONST
, ubyte fileIdx
= 0);
608 virtual Symbol
*clone(ClonePolicy
<Function
>&) const;
610 virtual bool equals(const Value
*that
, bool strict
) const;
612 virtual bool isUniform() const;
614 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
616 // print with indirect values
617 int print(char *, size_t, Value
*, Value
*, DataType ty
= TYPE_NONE
) const;
619 inline void setFile(DataFile file
, ubyte fileIndex
= 0)
622 reg
.fileIndex
= fileIndex
;
625 inline void setOffset(int32_t offset
);
626 inline void setAddress(Symbol
*base
, int32_t offset
);
627 inline void setSV(SVSemantic sv
, uint32_t idx
= 0);
629 inline const Symbol
*getBase() const { return baseSym
; }
632 Symbol
*baseSym
; // array base for Symbols representing array elements
635 class ImmediateValue
: public Value
639 ImmediateValue(Program
*, uint32_t);
640 ImmediateValue(Program
*, float);
641 ImmediateValue(Program
*, double);
642 // NOTE: not added to program with
643 ImmediateValue(const ImmediateValue
*, DataType ty
);
644 ~ImmediateValue() { };
646 virtual ImmediateValue
*clone(ClonePolicy
<Function
>&) const;
648 virtual bool equals(const Value
*that
, bool strict
) const;
650 // these only work if 'type' is valid (we mostly use untyped literals):
651 bool isInteger(const int ival
) const; // ival is cast to this' type
652 bool isNegative() const;
657 // for constant folding:
658 ImmediateValue
operator+(const ImmediateValue
&) const;
659 ImmediateValue
operator-(const ImmediateValue
&) const;
660 ImmediateValue
operator*(const ImmediateValue
&) const;
661 ImmediateValue
operator/(const ImmediateValue
&) const;
663 ImmediateValue
& operator=(const ImmediateValue
&); // only sets value !
665 bool compare(CondCode cc
, float fval
) const;
667 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
674 Instruction(Function
*, operation
, DataType
);
675 virtual ~Instruction();
677 virtual Instruction
*clone(ClonePolicy
<Function
>&,
678 Instruction
* = NULL
) const;
680 void setDef(int i
, Value
*);
681 void setSrc(int s
, Value
*);
682 void setSrc(int s
, const ValueRef
&);
683 void swapSources(int a
, int b
);
684 void moveSources(int s
, int delta
);
685 bool setIndirect(int s
, int dim
, Value
*);
687 inline ValueRef
& src(int s
) { return srcs
[s
]; }
688 inline ValueDef
& def(int s
) { return defs
[s
]; }
689 inline const ValueRef
& src(int s
) const { return srcs
[s
]; }
690 inline const ValueDef
& def(int s
) const { return defs
[s
]; }
692 inline Value
*getDef(int d
) const { return defs
[d
].get(); }
693 inline Value
*getSrc(int s
) const { return srcs
[s
].get(); }
694 inline Value
*getIndirect(int s
, int dim
) const;
696 inline bool defExists(unsigned d
) const
698 return d
< defs
.size() && defs
[d
].exists();
700 inline bool srcExists(unsigned s
) const
702 return s
< srcs
.size() && srcs
[s
].exists();
705 inline bool constrainedDefs() const;
707 bool setPredicate(CondCode ccode
, Value
*);
708 inline Value
*getPredicate() const;
709 bool writesPredicate() const;
710 inline bool isPredicated() const { return predSrc
>= 0; }
712 inline void setFlagsSrc(int s
, Value
*);
713 inline void setFlagsDef(int d
, Value
*);
714 inline bool usesFlags() const { return flagsSrc
>= 0; }
716 unsigned int defCount() const { return defs
.size(); };
717 unsigned int defCount(unsigned int mask
, bool singleFile
= false) const;
718 unsigned int srcCount() const { return srcs
.size(); };
719 unsigned int srcCount(unsigned int mask
, bool singleFile
= false) const;
721 // save & remove / set indirect[0,1] and predicate source
722 void takeExtraSources(int s
, Value
*[3]);
723 void putExtraSources(int s
, Value
*[3]);
725 inline void setType(DataType type
) { dType
= sType
= type
; }
727 inline void setType(DataType dtype
, DataType stype
)
733 inline bool isPseudo() const { return op
< OP_MOV
; }
736 bool isCommutationLegal(const Instruction
*) const; // must be adjacent !
737 bool isActionEqual(const Instruction
*) const;
738 bool isResultEqual(const Instruction
*) const;
742 inline CmpInstruction
*asCmp();
743 inline TexInstruction
*asTex();
744 inline FlowInstruction
*asFlow();
745 inline const TexInstruction
*asTex() const;
746 inline const CmpInstruction
*asCmp() const;
747 inline const FlowInstruction
*asFlow() const;
753 int serial
; // CFG order
756 DataType dType
; // destination or defining type
757 DataType sType
; // source or secondary type
762 uint16_t subOp
; // quadop, 1 for mul-high, etc.
764 unsigned encSize
: 4; // encoding size in bytes
765 unsigned saturate
: 1; // to [0.0f, 1.0f]
766 unsigned join
: 1; // converge control flow (use OP_JOIN until end)
767 unsigned fixed
: 1; // prevent dead code elimination
768 unsigned terminator
: 1; // end of basic block
769 unsigned ftz
: 1; // flush denormal to zero
770 unsigned dnz
: 1; // denormals, NaN are zero
771 unsigned ipa
: 4; // interpolation mode
773 unsigned perPatch
: 1;
774 unsigned exit
: 1; // terminate program after insn
775 unsigned mask
: 4; // for vector ops
777 int8_t postFactor
; // MUL/DIV(if < 0) by 1 << postFactor
783 uint8_t sched
; // scheduling data (NOTE: maybe move to separate storage)
788 std::deque
<ValueDef
> defs
; // no gaps !
789 std::deque
<ValueRef
> srcs
; // no gaps !
791 // instruction specific methods:
792 // (don't want to subclass, would need more constructors and memory pools)
794 inline void setInterpolate(unsigned int mode
) { ipa
= mode
; }
796 unsigned int getInterpMode() const { return ipa
& 0x3; }
797 unsigned int getSampleMode() const { return ipa
& 0xc; }
814 class TexInstruction
: public Instruction
820 Target(TexTarget targ
= TEX_TARGET_2D
) : target(targ
) { }
822 const char *getName() const { return descTable
[target
].name
; }
823 unsigned int getArgCount() const { return descTable
[target
].argc
; }
824 unsigned int getDim() const { return descTable
[target
].dim
; }
825 int isArray() const { return descTable
[target
].array
? 1 : 0; }
826 int isCube() const { return descTable
[target
].cube
? 1 : 0; }
827 int isShadow() const { return descTable
[target
].shadow
? 1 : 0; }
829 return target
== TEX_TARGET_2D_MS
|| target
== TEX_TARGET_2D_MS_ARRAY
; }
833 target
= TEX_TARGET_2D_ARRAY
;
835 target
= TEX_TARGET_2D
;
839 Target
& operator=(TexTarget targ
)
841 assert(targ
< TEX_TARGET_COUNT
);
846 inline bool operator==(TexTarget targ
) const { return target
== targ
; }
847 inline bool operator!=(TexTarget targ
) const { return target
!= targ
; }
849 enum TexTarget
getEnum() const { return target
; }
862 static const struct Desc descTable
[TEX_TARGET_COUNT
];
865 enum TexTarget target
;
869 TexInstruction(Function
*, operation
);
870 virtual ~TexInstruction();
872 virtual TexInstruction
*clone(ClonePolicy
<Function
>&,
873 Instruction
* = NULL
) const;
875 inline void setTexture(Target targ
, uint8_t r
, uint8_t s
)
882 void setIndirectR(Value
*);
883 void setIndirectS(Value
*);
884 inline Value
*getIndirectR() const;
885 inline Value
*getIndirectS() const;
899 bool liveOnly
; // only execute on live pixels of a quad (optimization)
903 int8_t useOffsets
; // 0, 1, or 4 for textureGatherOffsets
913 class CmpInstruction
: public Instruction
916 CmpInstruction(Function
*, operation
);
918 virtual CmpInstruction
*clone(ClonePolicy
<Function
>&,
919 Instruction
* = NULL
) const;
921 void setCondition(CondCode cond
) { setCond
= cond
; }
922 CondCode
getCondition() const { return setCond
; }
928 class FlowInstruction
: public Instruction
931 FlowInstruction(Function
*, operation
, void *target
);
933 virtual FlowInstruction
*clone(ClonePolicy
<Function
>&,
934 Instruction
* = NULL
) const;
937 unsigned allWarp
: 1;
938 unsigned absolute
: 1;
940 unsigned builtin
: 1; // true for calls to emulation code
941 unsigned indirect
: 1; // target in src(0)
953 BasicBlock(Function
*);
956 BasicBlock
*clone(ClonePolicy
<Function
>&) const;
958 inline int getId() const { return id
; }
959 inline unsigned int getInsnCount() const { return numInsns
; }
960 inline bool isTerminated() const { return exit
&& exit
->terminator
; }
962 bool dominatedBy(BasicBlock
*bb
);
963 inline bool reachableBy(const BasicBlock
*by
, const BasicBlock
*term
);
965 // returns mask of conditional out blocks
966 // e.g. 3 for IF { .. } ELSE { .. } ENDIF, 1 for IF { .. } ENDIF
967 unsigned int initiatesSimpleConditional() const;
970 Function
*getFunction() const { return func
; }
971 Program
*getProgram() const { return program
; }
973 Instruction
*getEntry() const { return entry
; } // first non-phi instruction
974 Instruction
*getPhi() const { return phi
; }
975 Instruction
*getFirst() const { return phi
? phi
: entry
; }
976 Instruction
*getExit() const { return exit
; }
978 void insertHead(Instruction
*);
979 void insertTail(Instruction
*);
980 void insertBefore(Instruction
*, Instruction
*);
981 void insertAfter(Instruction
*, Instruction
*);
982 void remove(Instruction
*);
983 void permuteAdjacent(Instruction
*, Instruction
*);
985 BasicBlock
*idom() const;
987 // NOTE: currently does not rebuild the dominator tree
988 BasicBlock
*splitBefore(Instruction
*, bool attach
= true);
989 BasicBlock
*splitAfter(Instruction
*, bool attach
= true);
991 DLList
& getDF() { return df
; }
992 DLList::Iterator
iterDF() { return df
.iterator(); }
994 static inline BasicBlock
*get(Iterator
&);
995 static inline BasicBlock
*get(Graph::Node
*);
998 Graph::Node cfg
; // first edge is branch *taken* (the ELSE branch)
1007 Instruction
*joinAt
; // for quick reference
1009 bool explicitCont
; // loop headers: true if loop contains continue stmts
1019 unsigned int numInsns
;
1025 void splitCommon(Instruction
*, BasicBlock
*, bool attach
);
1031 Function(Program
*, const char *name
, uint32_t label
);
1034 static inline Function
*get(Graph::Node
*node
);
1036 inline Program
*getProgram() const { return prog
; }
1037 inline const char *getName() const { return name
; }
1038 inline int getId() const { return id
; }
1039 inline uint32_t getLabel() const { return label
; }
1042 void printLiveIntervals() const;
1043 void printCFGraph(const char *filePath
);
1045 bool setEntry(BasicBlock
*);
1046 bool setExit(BasicBlock
*);
1048 unsigned int orderInstructions(ArrayList
&);
1050 inline void add(BasicBlock
*bb
, int& id
) { allBBlocks
.insert(bb
, id
); }
1051 inline void add(Instruction
*insn
, int& id
) { allInsns
.insert(insn
, id
); }
1052 inline void add(LValue
*lval
, int& id
) { allLValues
.insert(lval
, id
); }
1054 inline LValue
*getLValue(int id
);
1056 void buildLiveSets();
1057 void buildDefSets();
1058 bool convertToSSA();
1061 std::deque
<ValueDef
> ins
;
1062 std::deque
<ValueRef
> outs
;
1063 std::deque
<Value
*> clobbers
;
1066 Graph::Node
*cfgExit
;
1068 Graph::Node call
; // node in the call graph
1070 BasicBlock
**bbArray
; // BBs in emission order
1073 unsigned int loopNestingBound
;
1081 uint32_t tlsBase
; // base address for l[] space (if no stack pointer is used)
1084 ArrayList allBBlocks
;
1086 ArrayList allLValues
;
1089 void buildLiveSetsPreSSA(BasicBlock
*, const int sequence
);
1090 void buildDefSetsPreSSA(BasicBlock
*bb
, const int seq
);
1095 const char *const name
;
1102 CG_STAGE_SSA
, // expected directly before register allocation
1112 TYPE_TESSELLATION_CONTROL
,
1113 TYPE_TESSELLATION_EVAL
,
1119 Program(Type type
, Target
*targ
);
1124 Type
getType() const { return progType
; }
1126 inline void add(Function
*fn
, int& id
) { allFuncs
.insert(fn
, id
); }
1127 inline void del(Function
*fn
, int& id
) { allFuncs
.remove(id
); }
1128 inline void add(Value
*rval
, int& id
) { allRValues
.insert(rval
, id
); }
1130 bool makeFromTGSI(struct nv50_ir_prog_info
*);
1131 bool makeFromSM4(struct nv50_ir_prog_info
*);
1132 bool convertToSSA();
1133 bool optimizeSSA(int level
);
1134 bool optimizePostRA(int level
);
1135 bool registerAllocation();
1136 bool emitBinary(struct nv50_ir_prog_info
*);
1138 const Target
*getTarget() const { return target
; }
1141 void emitSymbolTable(struct nv50_ir_prog_info
*);
1151 ArrayList allRValues
;
1155 uint32_t tlsSize
; // size required for FILE_MEMORY_LOCAL
1159 MemoryPool mem_Instruction
;
1160 MemoryPool mem_CmpInstruction
;
1161 MemoryPool mem_TexInstruction
;
1162 MemoryPool mem_FlowInstruction
;
1163 MemoryPool mem_LValue
;
1164 MemoryPool mem_Symbol
;
1165 MemoryPool mem_ImmediateValue
;
1170 void *targetPriv
; // e.g. to carry information between passes
1172 const struct nv50_ir_prog_info
*driver
; // for driver configuration
1174 void releaseInstruction(Instruction
*);
1175 void releaseValue(Value
*);
1178 // TODO: add const version
1182 bool run(Program
*, bool ordered
= false, bool skipPhi
= false);
1183 bool run(Function
*, bool ordered
= false, bool skipPhi
= false);
1186 // return false to continue with next entity on next higher level
1187 virtual bool visit(Function
*) { return true; }
1188 virtual bool visit(BasicBlock
*) { return true; }
1189 virtual bool visit(Instruction
*) { return false; }
1191 bool doRun(Program
*, bool ordered
, bool skipPhi
);
1192 bool doRun(Function
*, bool ordered
, bool skipPhi
);
1200 // =============================================================================
1202 #include "codegen/nv50_ir_inlines.h"
1204 } // namespace nv50_ir
1206 #endif // __NV50_IR_H__