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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include "nv50_ir_util.h"
34 #include "nv50_ir_graph.h"
36 #include "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
159 // various instruction-specific modifier definitions Instruction::subOp
160 // MOV_FINAL marks a MOV originating from an EXPORT (used for placing TEXBARs)
161 #define NV50_IR_SUBOP_MUL_HIGH 1
162 #define NV50_IR_SUBOP_EMIT_RESTART 1
163 #define NV50_IR_SUBOP_LDC_IL 1
164 #define NV50_IR_SUBOP_LDC_IS 2
165 #define NV50_IR_SUBOP_LDC_ISL 3
166 #define NV50_IR_SUBOP_SHIFT_WRAP 1
167 #define NV50_IR_SUBOP_EMU_PRERET 1
168 #define NV50_IR_SUBOP_TEXBAR(n) n
169 #define NV50_IR_SUBOP_MOV_FINAL 1
170 #define NV50_IR_SUBOP_EXTBF_REV 1
171 #define NV50_IR_SUBOP_PERMT_F4E 1
172 #define NV50_IR_SUBOP_PERMT_B4E 2
173 #define NV50_IR_SUBOP_PERMT_RC8 3
174 #define NV50_IR_SUBOP_PERMT_ECL 4
175 #define NV50_IR_SUBOP_PERMT_ECR 5
176 #define NV50_IR_SUBOP_PERMT_RC16 6
177 #define NV50_IR_SUBOP_BAR_SYNC 0
178 #define NV50_IR_SUBOP_BAR_ARRIVE 1
179 #define NV50_IR_SUBOP_BAR_RED_AND 2
180 #define NV50_IR_SUBOP_BAR_RED_OR 3
181 #define NV50_IR_SUBOP_BAR_RED_POPC 4
182 #define NV50_IR_SUBOP_MEMBAR_L 1
183 #define NV50_IR_SUBOP_MEMBAR_S 2
184 #define NV50_IR_SUBOP_MEMBAR_M 3
185 #define NV50_IR_SUBOP_MEMBAR_CTA (0 << 2)
186 #define NV50_IR_SUBOP_MEMBAR_GL (1 << 2)
187 #define NV50_IR_SUBOP_MEMBAR_SYS (2 << 2)
188 #define NV50_IR_SUBOP_MEMBAR_DIR(m) ((m) & 0x3)
189 #define NV50_IR_SUBOP_MEMBAR_SCOPE(m) ((m) & ~0x3)
190 #define NV50_IR_SUBOP_MEMBAR(d,s) \
191 (NV50_IR_SUBOP_MEMBAR_##d | NV50_IR_SUBOP_MEMBAR_##s)
192 #define NV50_IR_SUBOP_ATOM_ADD 0
193 #define NV50_IR_SUBOP_ATOM_MIN 1
194 #define NV50_IR_SUBOP_ATOM_MAX 2
195 #define NV50_IR_SUBOP_ATOM_INC 3
196 #define NV50_IR_SUBOP_ATOM_DEC 4
197 #define NV50_IR_SUBOP_ATOM_AND 5
198 #define NV50_IR_SUBOP_ATOM_OR 6
199 #define NV50_IR_SUBOP_ATOM_XOR 7
200 #define NV50_IR_SUBOP_ATOM_CAS 8
201 #define NV50_IR_SUBOP_ATOM_EXCH 9
202 #define NV50_IR_SUBOP_SUST_IGN 0
203 #define NV50_IR_SUBOP_SUST_TRAP 1
204 #define NV50_IR_SUBOP_SUST_SDCL 3
205 #define NV50_IR_SUBOP_SULD_ZERO 0
206 #define NV50_IR_SUBOP_SULD_TRAP 1
207 #define NV50_IR_SUBOP_SULD_SDCL 3
208 #define NV50_IR_SUBOP_SUBFM_3D 1
209 #define NV50_IR_SUBOP_SUCLAMP_2D 0x10
210 #define NV50_IR_SUBOP_SUCLAMP_SD(r, d) (( 0 + (r)) | ((d == 2) ? 0x10 : 0))
211 #define NV50_IR_SUBOP_SUCLAMP_PL(r, d) (( 5 + (r)) | ((d == 2) ? 0x10 : 0))
212 #define NV50_IR_SUBOP_SUCLAMP_BL(r, d) ((10 + (r)) | ((d == 2) ? 0x10 : 0))
213 #define NV50_IR_SUBOP_MADSP_SD 0xffff
214 // Yes, we could represent those with DataType.
215 // Or put the type into operation and have a couple 1000 values in that enum.
216 // This will have to do for now.
217 // The bitfields are supposed to correspond to nve4 ISA.
218 #define NV50_IR_SUBOP_MADSP(a,b,c) (((c) << 8) | ((b) << 4) | (a))
219 #define NV50_IR_SUBOP_V1(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x0000)
220 #define NV50_IR_SUBOP_V2(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x4000)
221 #define NV50_IR_SUBOP_V4(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x8000)
222 #define NV50_IR_SUBOP_Vn(n) ((n) >> 14)
233 TYPE_U64
, // 64 bit operations are only lowered after register allocation
245 CC_NEVER
= CC_FL
, // when used with FILE_FLAGS
248 CC_NOT_P
= CC_EQ
, // when used with FILE_PREDICATE
276 ROUND_M
, // towards -inf
277 ROUND_Z
, // towards 0
278 ROUND_P
, // towards +inf
279 ROUND_NI
, // nearest integer
280 ROUND_MI
, // to integer towards -inf
281 ROUND_ZI
, // to integer towards 0
282 ROUND_PI
, // to integer towards +inf
287 CACHE_CA
, // cache at all levels
288 CACHE_WB
= CACHE_CA
, // cache write back
289 CACHE_CG
, // cache at global level
290 CACHE_CS
, // cache streaming
291 CACHE_CV
, // cache as volatile
292 CACHE_WT
= CACHE_CV
// cache write-through
299 FILE_PREDICATE
, // boolean predicate
300 FILE_FLAGS
, // zero/sign/carry/overflow bits
302 LAST_REGISTER_FILE
= FILE_ADDRESS
,
321 TEX_TARGET_1D_SHADOW
,
322 TEX_TARGET_2D_SHADOW
,
323 TEX_TARGET_CUBE_SHADOW
,
326 TEX_TARGET_2D_MS_ARRAY
,
327 TEX_TARGET_CUBE_ARRAY
,
328 TEX_TARGET_1D_ARRAY_SHADOW
,
329 TEX_TARGET_2D_ARRAY_SHADOW
,
331 TEX_TARGET_RECT_SHADOW
,
332 TEX_TARGET_CUBE_ARRAY_SHADOW
,
344 SV_VERTEX_COUNT
, // gl_PatchVerticesIn
377 class CmpInstruction
;
378 class TexInstruction
;
379 class FlowInstruction
;
384 class ImmediateValue
;
389 int8_t fileIndex
; // signed, may be indirect for CONST[]
390 uint8_t size
; // this should match the Instruction type's size
391 DataType type
; // mainly for pretty printing
393 uint64_t u64
; // immediate values
403 int32_t offset
; // offset from 0 (base of address space)
404 int32_t id
; // register id (< 0 if virtual/unassigned, in units <= 4)
412 // precedence: NOT after SAT after NEG after ABS
413 #define NV50_IR_MOD_ABS (1 << 0)
414 #define NV50_IR_MOD_NEG (1 << 1)
415 #define NV50_IR_MOD_SAT (1 << 2)
416 #define NV50_IR_MOD_NOT (1 << 3)
417 #define NV50_IR_MOD_NEG_ABS (NV50_IR_MOD_NEG | NV50_IR_MOD_ABS)
419 #define NV50_IR_INTERP_MODE_MASK 0x3
420 #define NV50_IR_INTERP_LINEAR (0 << 0)
421 #define NV50_IR_INTERP_PERSPECTIVE (1 << 0)
422 #define NV50_IR_INTERP_FLAT (2 << 0)
423 #define NV50_IR_INTERP_SC (3 << 0) // what exactly is that ?
424 #define NV50_IR_INTERP_SAMPLE_MASK 0xc
425 #define NV50_IR_INTERP_DEFAULT (0 << 2)
426 #define NV50_IR_INTERP_CENTROID (1 << 2)
427 #define NV50_IR_INTERP_OFFSET (2 << 2)
428 #define NV50_IR_INTERP_SAMPLEID (3 << 2)
430 // do we really want this to be a class ?
434 Modifier() : bits(0) { }
435 Modifier(unsigned int m
) : bits(m
) { }
436 Modifier(operation op
);
438 // @return new Modifier applying a after b (asserts if unrepresentable)
439 Modifier
operator*(const Modifier
) const;
440 Modifier
operator*=(const Modifier m
) { *this = *this * m
; return *this; }
441 Modifier
operator==(const Modifier m
) const { return m
.bits
== bits
; }
442 Modifier
operator!=(const Modifier m
) const { return m
.bits
!= bits
; }
444 inline Modifier
operator&(const Modifier m
) const { return bits
& m
.bits
; }
445 inline Modifier
operator|(const Modifier m
) const { return bits
| m
.bits
; }
446 inline Modifier
operator^(const Modifier m
) const { return bits
^ m
.bits
; }
448 operation
getOp() const;
450 inline int neg() const { return (bits
& NV50_IR_MOD_NEG
) ? 1 : 0; }
451 inline int abs() const { return (bits
& NV50_IR_MOD_ABS
) ? 1 : 0; }
453 inline operator bool() const { return bits
? true : false; }
455 void applyTo(ImmediateValue
&imm
) const;
457 int print(char *buf
, size_t size
) const;
466 ValueRef(Value
* = NULL
);
467 ValueRef(const ValueRef
&);
470 inline bool exists() const { return value
!= NULL
; }
473 void set(const ValueRef
&);
474 inline Value
*get() const { return value
; }
475 inline Value
*rep() const;
477 inline Instruction
*getInsn() const { return insn
; }
478 inline void setInsn(Instruction
*inst
) { insn
= inst
; }
480 inline bool isIndirect(int dim
) const { return indirect
[dim
] >= 0; }
481 inline const ValueRef
*getIndirect(int dim
) const;
483 inline DataFile
getFile() const;
484 inline unsigned getSize() const;
486 // SSA: return eventual (traverse MOVs) literal value, if it exists
487 bool getImmediate(ImmediateValue
&) const;
491 int8_t indirect
[2]; // >= 0 if relative to lvalue in insn->src(indirect[i])
494 bool usedAsPtr
; // for printing
504 ValueDef(Value
* = NULL
);
505 ValueDef(const ValueDef
&);
508 inline bool exists() const { return value
!= NULL
; }
510 inline Value
*get() const { return value
; }
511 inline Value
*rep() const;
513 bool mayReplace(const ValueRef
&);
514 void replace(const ValueRef
&, bool doSet
); // replace all uses of the old value
516 inline Instruction
*getInsn() const { return insn
; }
517 inline void setInsn(Instruction
*inst
) { insn
= inst
; }
519 inline DataFile
getFile() const;
520 inline unsigned getSize() const;
522 inline void setSSA(LValue
*);
523 inline const LValue
*preSSA() const;
526 Value
*value
; // should make this LValue * ...
527 LValue
*origin
; // pre SSA value
537 virtual Value
*clone(ClonePolicy
<Function
>&) const = 0;
539 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const = 0;
541 virtual bool equals(const Value
*, bool strict
= false) const;
542 virtual bool interfers(const Value
*) const;
543 virtual bool isUniform() const { return true; }
545 inline Value
*rep() const { return join
; }
547 inline Instruction
*getUniqueInsn() const;
548 inline Instruction
*getInsn() const; // use when uniqueness is certain
550 inline int refCount() { return uses
.size(); }
552 inline LValue
*asLValue();
553 inline Symbol
*asSym();
554 inline ImmediateValue
*asImm();
555 inline const Symbol
*asSym() const;
556 inline const ImmediateValue
*asImm() const;
558 inline bool inFile(DataFile f
) { return reg
.file
== f
; }
560 static inline Value
*get(Iterator
&);
562 std::list
<ValueRef
*> uses
;
563 std::list
<ValueDef
*> defs
;
564 typedef std::list
<ValueRef
*>::iterator UseIterator
;
565 typedef std::list
<ValueRef
*>::const_iterator UseCIterator
;
566 typedef std::list
<ValueDef
*>::iterator DefIterator
;
567 typedef std::list
<ValueDef
*>::const_iterator DefCIterator
;
572 // TODO: these should be in LValue:
577 class LValue
: public Value
580 LValue(Function
*, DataFile file
);
581 LValue(Function
*, LValue
*);
584 virtual bool isUniform() const;
586 virtual LValue
*clone(ClonePolicy
<Function
>&) const;
588 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
591 unsigned compMask
: 8; // compound/component mask
592 unsigned compound
: 1; // used by RA, value involved in split/merge
594 unsigned fixedReg
: 1; // set & used by RA, earlier just use (id < 0)
595 unsigned noSpill
: 1; // do not spill (e.g. if spill temporary already)
598 class Symbol
: public Value
601 Symbol(Program
*, DataFile file
= FILE_MEMORY_CONST
, ubyte fileIdx
= 0);
604 virtual Symbol
*clone(ClonePolicy
<Function
>&) const;
606 virtual bool equals(const Value
*that
, bool strict
) const;
608 virtual bool isUniform() const;
610 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
612 // print with indirect values
613 int print(char *, size_t, Value
*, Value
*, DataType ty
= TYPE_NONE
) const;
615 inline void setFile(DataFile file
, ubyte fileIndex
= 0)
618 reg
.fileIndex
= fileIndex
;
621 inline void setOffset(int32_t offset
);
622 inline void setAddress(Symbol
*base
, int32_t offset
);
623 inline void setSV(SVSemantic sv
, uint32_t idx
= 0);
625 inline const Symbol
*getBase() const { return baseSym
; }
628 Symbol
*baseSym
; // array base for Symbols representing array elements
631 class ImmediateValue
: public Value
635 ImmediateValue(Program
*, uint32_t);
636 ImmediateValue(Program
*, float);
637 ImmediateValue(Program
*, double);
638 // NOTE: not added to program with
639 ImmediateValue(const ImmediateValue
*, DataType ty
);
640 ~ImmediateValue() { };
642 virtual ImmediateValue
*clone(ClonePolicy
<Function
>&) const;
644 virtual bool equals(const Value
*that
, bool strict
) const;
646 // these only work if 'type' is valid (we mostly use untyped literals):
647 bool isInteger(const int ival
) const; // ival is cast to this' type
648 bool isNegative() const;
653 // for constant folding:
654 ImmediateValue
operator+(const ImmediateValue
&) const;
655 ImmediateValue
operator-(const ImmediateValue
&) const;
656 ImmediateValue
operator*(const ImmediateValue
&) const;
657 ImmediateValue
operator/(const ImmediateValue
&) const;
659 ImmediateValue
& operator=(const ImmediateValue
&); // only sets value !
661 bool compare(CondCode cc
, float fval
) const;
663 virtual int print(char *, size_t, DataType ty
= TYPE_NONE
) const;
670 Instruction(Function
*, operation
, DataType
);
671 virtual ~Instruction();
673 virtual Instruction
*clone(ClonePolicy
<Function
>&,
674 Instruction
* = NULL
) const;
676 void setDef(int i
, Value
*);
677 void setSrc(int s
, Value
*);
678 void setSrc(int s
, const ValueRef
&);
679 void swapSources(int a
, int b
);
680 void moveSources(int s
, int delta
);
681 bool setIndirect(int s
, int dim
, Value
*);
683 inline ValueRef
& src(int s
) { return srcs
[s
]; }
684 inline ValueDef
& def(int s
) { return defs
[s
]; }
685 inline const ValueRef
& src(int s
) const { return srcs
[s
]; }
686 inline const ValueDef
& def(int s
) const { return defs
[s
]; }
688 inline Value
*getDef(int d
) const { return defs
[d
].get(); }
689 inline Value
*getSrc(int s
) const { return srcs
[s
].get(); }
690 inline Value
*getIndirect(int s
, int dim
) const;
692 inline bool defExists(unsigned d
) const
694 return d
< defs
.size() && defs
[d
].exists();
696 inline bool srcExists(unsigned s
) const
698 return s
< srcs
.size() && srcs
[s
].exists();
701 inline bool constrainedDefs() const;
703 bool setPredicate(CondCode ccode
, Value
*);
704 inline Value
*getPredicate() const;
705 bool writesPredicate() const;
706 inline bool isPredicated() const { return predSrc
>= 0; }
708 inline void setFlagsSrc(int s
, Value
*);
709 inline void setFlagsDef(int d
, Value
*);
710 inline bool usesFlags() const { return flagsSrc
>= 0; }
712 unsigned int defCount() const { return defs
.size(); };
713 unsigned int defCount(unsigned int mask
, bool singleFile
= false) const;
714 unsigned int srcCount() const { return srcs
.size(); };
715 unsigned int srcCount(unsigned int mask
, bool singleFile
= false) const;
717 // save & remove / set indirect[0,1] and predicate source
718 void takeExtraSources(int s
, Value
*[3]);
719 void putExtraSources(int s
, Value
*[3]);
721 inline void setType(DataType type
) { dType
= sType
= type
; }
723 inline void setType(DataType dtype
, DataType stype
)
729 inline bool isPseudo() const { return op
< OP_MOV
; }
732 bool isCommutationLegal(const Instruction
*) const; // must be adjacent !
733 bool isActionEqual(const Instruction
*) const;
734 bool isResultEqual(const Instruction
*) const;
738 inline CmpInstruction
*asCmp();
739 inline TexInstruction
*asTex();
740 inline FlowInstruction
*asFlow();
741 inline const TexInstruction
*asTex() const;
742 inline const CmpInstruction
*asCmp() const;
743 inline const FlowInstruction
*asFlow() const;
749 int serial
; // CFG order
752 DataType dType
; // destination or defining type
753 DataType sType
; // source or secondary type
758 uint16_t subOp
; // quadop, 1 for mul-high, etc.
760 unsigned encSize
: 4; // encoding size in bytes
761 unsigned saturate
: 1; // to [0.0f, 1.0f]
762 unsigned join
: 1; // converge control flow (use OP_JOIN until end)
763 unsigned fixed
: 1; // prevent dead code elimination
764 unsigned terminator
: 1; // end of basic block
765 unsigned ftz
: 1; // flush denormal to zero
766 unsigned dnz
: 1; // denormals, NaN are zero
767 unsigned ipa
: 4; // interpolation mode
769 unsigned perPatch
: 1;
770 unsigned exit
: 1; // terminate program after insn
771 unsigned mask
: 4; // for vector ops
773 int8_t postFactor
; // MUL/DIV(if < 0) by 1 << postFactor
779 uint8_t sched
; // scheduling data (NOTE: maybe move to separate storage)
784 std::deque
<ValueDef
> defs
; // no gaps !
785 std::deque
<ValueRef
> srcs
; // no gaps !
787 // instruction specific methods:
788 // (don't want to subclass, would need more constructors and memory pools)
790 inline void setInterpolate(unsigned int mode
) { ipa
= mode
; }
792 unsigned int getInterpMode() const { return ipa
& 0x3; }
793 unsigned int getSampleMode() const { return ipa
& 0xc; }
810 class TexInstruction
: public Instruction
816 Target(TexTarget targ
= TEX_TARGET_2D
) : target(targ
) { }
818 const char *getName() const { return descTable
[target
].name
; }
819 unsigned int getArgCount() const { return descTable
[target
].argc
; }
820 unsigned int getDim() const { return descTable
[target
].dim
; }
821 int isArray() const { return descTable
[target
].array
? 1 : 0; }
822 int isCube() const { return descTable
[target
].cube
? 1 : 0; }
823 int isShadow() const { return descTable
[target
].shadow
? 1 : 0; }
825 Target
& operator=(TexTarget targ
)
827 assert(targ
< TEX_TARGET_COUNT
);
832 inline bool operator==(TexTarget targ
) const { return target
== targ
; }
833 inline bool operator!=(TexTarget targ
) const { return target
!= targ
; }
835 enum TexTarget
getEnum() const { return target
; }
848 static const struct Desc descTable
[TEX_TARGET_COUNT
];
851 enum TexTarget target
;
855 TexInstruction(Function
*, operation
);
856 virtual ~TexInstruction();
858 virtual TexInstruction
*clone(ClonePolicy
<Function
>&,
859 Instruction
* = NULL
) const;
861 inline void setTexture(Target targ
, uint8_t r
, uint8_t s
)
868 inline Value
*getIndirectR() const;
869 inline Value
*getIndirectS() const;
883 bool liveOnly
; // only execute on live pixels of a quad (optimization)
887 int8_t useOffsets
; // 0, 1, or 4 for textureGatherOffsets
897 class CmpInstruction
: public Instruction
900 CmpInstruction(Function
*, operation
);
902 virtual CmpInstruction
*clone(ClonePolicy
<Function
>&,
903 Instruction
* = NULL
) const;
905 void setCondition(CondCode cond
) { setCond
= cond
; }
906 CondCode
getCondition() const { return setCond
; }
912 class FlowInstruction
: public Instruction
915 FlowInstruction(Function
*, operation
, void *target
);
917 virtual FlowInstruction
*clone(ClonePolicy
<Function
>&,
918 Instruction
* = NULL
) const;
921 unsigned allWarp
: 1;
922 unsigned absolute
: 1;
924 unsigned builtin
: 1; // true for calls to emulation code
925 unsigned indirect
: 1; // target in src(0)
937 BasicBlock(Function
*);
940 BasicBlock
*clone(ClonePolicy
<Function
>&) const;
942 inline int getId() const { return id
; }
943 inline unsigned int getInsnCount() const { return numInsns
; }
944 inline bool isTerminated() const { return exit
&& exit
->terminator
; }
946 bool dominatedBy(BasicBlock
*bb
);
947 inline bool reachableBy(const BasicBlock
*by
, const BasicBlock
*term
);
949 // returns mask of conditional out blocks
950 // e.g. 3 for IF { .. } ELSE { .. } ENDIF, 1 for IF { .. } ENDIF
951 unsigned int initiatesSimpleConditional() const;
954 Function
*getFunction() const { return func
; }
955 Program
*getProgram() const { return program
; }
957 Instruction
*getEntry() const { return entry
; } // first non-phi instruction
958 Instruction
*getPhi() const { return phi
; }
959 Instruction
*getFirst() const { return phi
? phi
: entry
; }
960 Instruction
*getExit() const { return exit
; }
962 void insertHead(Instruction
*);
963 void insertTail(Instruction
*);
964 void insertBefore(Instruction
*, Instruction
*);
965 void insertAfter(Instruction
*, Instruction
*);
966 void remove(Instruction
*);
967 void permuteAdjacent(Instruction
*, Instruction
*);
969 BasicBlock
*idom() const;
971 // NOTE: currently does not rebuild the dominator tree
972 BasicBlock
*splitBefore(Instruction
*, bool attach
= true);
973 BasicBlock
*splitAfter(Instruction
*, bool attach
= true);
975 DLList
& getDF() { return df
; }
976 DLList::Iterator
iterDF() { return df
.iterator(); }
978 static inline BasicBlock
*get(Iterator
&);
979 static inline BasicBlock
*get(Graph::Node
*);
982 Graph::Node cfg
; // first edge is branch *taken* (the ELSE branch)
991 Instruction
*joinAt
; // for quick reference
993 bool explicitCont
; // loop headers: true if loop contains continue stmts
1003 unsigned int numInsns
;
1009 void splitCommon(Instruction
*, BasicBlock
*, bool attach
);
1015 Function(Program
*, const char *name
, uint32_t label
);
1018 static inline Function
*get(Graph::Node
*node
);
1020 inline Program
*getProgram() const { return prog
; }
1021 inline const char *getName() const { return name
; }
1022 inline int getId() const { return id
; }
1023 inline uint32_t getLabel() const { return label
; }
1026 void printLiveIntervals() const;
1027 void printCFGraph(const char *filePath
);
1029 bool setEntry(BasicBlock
*);
1030 bool setExit(BasicBlock
*);
1032 unsigned int orderInstructions(ArrayList
&);
1034 inline void add(BasicBlock
*bb
, int& id
) { allBBlocks
.insert(bb
, id
); }
1035 inline void add(Instruction
*insn
, int& id
) { allInsns
.insert(insn
, id
); }
1036 inline void add(LValue
*lval
, int& id
) { allLValues
.insert(lval
, id
); }
1038 inline LValue
*getLValue(int id
);
1040 void buildLiveSets();
1041 void buildDefSets();
1042 bool convertToSSA();
1045 std::deque
<ValueDef
> ins
;
1046 std::deque
<ValueRef
> outs
;
1047 std::deque
<Value
*> clobbers
;
1050 Graph::Node
*cfgExit
;
1052 Graph::Node call
; // node in the call graph
1054 BasicBlock
**bbArray
; // BBs in emission order
1057 unsigned int loopNestingBound
;
1065 uint32_t tlsBase
; // base address for l[] space (if no stack pointer is used)
1068 ArrayList allBBlocks
;
1070 ArrayList allLValues
;
1073 void buildLiveSetsPreSSA(BasicBlock
*, const int sequence
);
1074 void buildDefSetsPreSSA(BasicBlock
*bb
, const int seq
);
1079 const char *const name
;
1086 CG_STAGE_SSA
, // expected directly before register allocation
1096 TYPE_TESSELLATION_CONTROL
,
1097 TYPE_TESSELLATION_EVAL
,
1103 Program(Type type
, Target
*targ
);
1108 Type
getType() const { return progType
; }
1110 inline void add(Function
*fn
, int& id
) { allFuncs
.insert(fn
, id
); }
1111 inline void del(Function
*fn
, int& id
) { allFuncs
.remove(id
); }
1112 inline void add(Value
*rval
, int& id
) { allRValues
.insert(rval
, id
); }
1114 bool makeFromTGSI(struct nv50_ir_prog_info
*);
1115 bool makeFromSM4(struct nv50_ir_prog_info
*);
1116 bool convertToSSA();
1117 bool optimizeSSA(int level
);
1118 bool optimizePostRA(int level
);
1119 bool registerAllocation();
1120 bool emitBinary(struct nv50_ir_prog_info
*);
1122 const Target
*getTarget() const { return target
; }
1125 void emitSymbolTable(struct nv50_ir_prog_info
*);
1135 ArrayList allRValues
;
1139 uint32_t tlsSize
; // size required for FILE_MEMORY_LOCAL
1143 MemoryPool mem_Instruction
;
1144 MemoryPool mem_CmpInstruction
;
1145 MemoryPool mem_TexInstruction
;
1146 MemoryPool mem_FlowInstruction
;
1147 MemoryPool mem_LValue
;
1148 MemoryPool mem_Symbol
;
1149 MemoryPool mem_ImmediateValue
;
1154 void *targetPriv
; // e.g. to carry information between passes
1156 const struct nv50_ir_prog_info
*driver
; // for driver configuration
1158 void releaseInstruction(Instruction
*);
1159 void releaseValue(Value
*);
1162 // TODO: add const version
1166 bool run(Program
*, bool ordered
= false, bool skipPhi
= false);
1167 bool run(Function
*, bool ordered
= false, bool skipPhi
= false);
1170 // return false to continue with next entity on next higher level
1171 virtual bool visit(Function
*) { return true; }
1172 virtual bool visit(BasicBlock
*) { return true; }
1173 virtual bool visit(Instruction
*) { return false; }
1175 bool doRun(Program
*, bool ordered
, bool skipPhi
);
1176 bool doRun(Function
*, bool ordered
, bool skipPhi
);
1184 // =============================================================================
1186 #include "nv50_ir_inlines.h"
1188 } // namespace nv50_ir
1190 #endif // __NV50_IR_H__