Debian Codegraph @

src/gallium/drivers/nouveau/codegen/nv50_ir.h

raw
1 /*
2 * Copyright 2011 Christoph Bumiller
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 #ifndef __NV50_IR_H__
24 #define __NV50_IR_H__
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <deque>
30 #include <list>
31 #include <unordered_set>
32 #include <vector>
33
34 #include "nv50_ir_util.h"
35 #include "nv50_ir_graph.h"
36
37 #include "nv50_ir_driver.h"
38
39 namespace nv50_ir {
40
41 enum operation
42 {
43 OP_NOP = 0,
44 OP_PHI,
45 OP_UNION, // unify a new definition and several source values
46 OP_SPLIT, // $r0d -> { $r0, $r1 } ($r0d and $r0/$r1 will be coalesced)
47 OP_MERGE, // opposite of split, e.g. combine 2 32 bit into a 64 bit value
48 OP_MOV, // simple copy, no modifiers allowed
49 OP_LOAD,
50 OP_STORE,
51 OP_ADD, // NOTE: add u64 + u32 is legal for targets w/o 64-bit integer adds
52 OP_SUB,
53 OP_MUL,
54 OP_DIV,
55 OP_MOD,
56 OP_MAD,
57 OP_FMA,
58 OP_SAD, // abs(src0 - src1) + src2
59 OP_SHLADD,
60 // extended multiply-add (GM107+), does a lot of things.
61 // see envytools for detailed documentation
62 OP_XMAD,
63 OP_ABS,
64 OP_NEG,
65 OP_NOT,
66 OP_AND,
67 OP_OR,
68 OP_XOR,
69 OP_LOP3_LUT,
70 OP_SHL,
71 OP_SHR,
72 OP_SHF,
73 OP_MAX,
74 OP_MIN,
75 OP_SAT, // CLAMP(f32, 0.0, 1.0)
76 OP_CEIL,
77 OP_FLOOR,
78 OP_TRUNC,
79 OP_CVT,
80 OP_SET_AND, // dst = (src0 CMP src1) & src2
81 OP_SET_OR,
82 OP_SET_XOR,
83 OP_SET,
84 OP_SELP, // dst = src2 ? src0 : src1
85 OP_SLCT, // dst = (src2 CMP 0) ? src0 : src1
86 OP_RCP,
87 OP_RSQ,
88 OP_LG2,
89 OP_SIN,
90 OP_COS,
91 OP_EX2,
92 OP_PRESIN,
93 OP_PREEX2,
94 OP_SQRT,
95 OP_BRA,
96 OP_CALL,
97 OP_RET,
98 OP_CONT,
99 OP_BREAK,
100 OP_PRERET,
101 OP_PRECONT,
102 OP_PREBREAK,
103 OP_BRKPT, // breakpoint (not related to loops)
104 OP_JOINAT, // push control flow convergence point
105 OP_JOIN, // converge
106 OP_DISCARD,
107 OP_EXIT,
108 OP_MEMBAR, // memory barrier (mfence, lfence, sfence)
109 OP_VFETCH, // indirection 0 in attribute space, indirection 1 is vertex base
110 OP_PFETCH, // fetch base address of vertex src0 (immediate) [+ src1]
111 OP_AFETCH, // fetch base address of shader input (a[%r1+0x10])
112 OP_EXPORT,
113 OP_LINTERP,
114 OP_PINTERP,
115 OP_EMIT, // emit vertex
116 OP_RESTART, // restart primitive
117 OP_FINAL, // finish emitting primitives
118 OP_TEX,
119 OP_TXB, // texture bias
120 OP_TXL, // texture lod
121 OP_TXF, // texel fetch
122 OP_TXQ, // texture size query
123 OP_TXD, // texture derivatives
124 OP_TXG, // texture gather
125 OP_TXLQ, // texture query lod
126 OP_TEXCSAA, // texture op for coverage sampling
127 OP_TEXPREP, // turn cube map array into 2d array coordinates
128 OP_SULDB, // surface load (raw)
129 OP_SULDP, // surface load (formatted)
130 OP_SUSTB, // surface store (raw)
131 OP_SUSTP, // surface store (formatted)
132 OP_SUREDB,
133 OP_SUREDP, // surface reduction (atomic op)
134 OP_SULEA, // surface load effective address
135 OP_SUBFM, // surface bitfield manipulation
136 OP_SUCLAMP, // clamp surface coordinates
137 OP_SUEAU, // surface effective address
138 OP_SUQ, // surface query
139 OP_MADSP, // special integer multiply-add
140 OP_TEXBAR, // texture dependency barrier
141 OP_DFDX,
142 OP_DFDY,
143 OP_RDSV, // read system value
144 OP_PIXLD, // get info about raster object or surfaces
145 OP_QUADOP,
146 OP_QUADON,
147 OP_QUADPOP,
148 OP_POPCNT, // bitcount(src0 & src1)
149 OP_INSBF, // insert first src1[8:15] bits of src0 into src2 at src1[0:7]
150 OP_EXTBF, // place bits [K,K+N) of src0 into dst, src1 = 0xNNKK
151 OP_BFIND, // find highest/lowest set bit
152 OP_BREV, // bitfield reverse
153 OP_BMSK, // bitfield mask
154 OP_PERMT, // dst = bytes from src2,src0 selected by src1 (nvc0's src order)
155 OP_SGXT,
156 OP_ATOM,
157 OP_BAR, // execution barrier, sources = { id, thread count, predicate }
158 OP_VADD, // byte/word vector operations
159 OP_VAVG,
160 OP_VMIN,
161 OP_VMAX,
162 OP_VSAD,
163 OP_VSET,
164 OP_VSHR,
165 OP_VSHL,
166 OP_VSEL,
167 OP_CCTL, // cache control
168 OP_SHFL, // warp shuffle
169 OP_VOTE,
170 OP_BUFQ, // buffer query
171 OP_WARPSYNC,
172 OP_LAST
173 };
174
175 // various instruction-specific modifier definitions Instruction::subOp
176 // MOV_FINAL marks a MOV originating from an EXPORT (used for placing TEXBARs)
177 #define NV50_IR_SUBOP_MUL_HIGH 1
178 #define NV50_IR_SUBOP_EMIT_RESTART 1
179 #define NV50_IR_SUBOP_LDC_IL 1
180 #define NV50_IR_SUBOP_LDC_IS 2
181 #define NV50_IR_SUBOP_LDC_ISL 3
182 #define NV50_IR_SUBOP_SHIFT_WRAP 1
183 #define NV50_IR_SUBOP_SHIFT_HIGH 2
184 #define NV50_IR_SUBOP_EMU_PRERET 1
185 #define NV50_IR_SUBOP_TEXBAR(n) n
186 #define NV50_IR_SUBOP_MOV_FINAL 1
187 #define NV50_IR_SUBOP_EXTBF_REV 1
188 #define NV50_IR_SUBOP_BFIND_SAMT 1
189 #define NV50_IR_SUBOP_RCPRSQ_64H 1
190 #define NV50_IR_SUBOP_PERMT_F4E 1
191 #define NV50_IR_SUBOP_PERMT_B4E 2
192 #define NV50_IR_SUBOP_PERMT_RC8 3
193 #define NV50_IR_SUBOP_PERMT_ECL 4
194 #define NV50_IR_SUBOP_PERMT_ECR 5
195 #define NV50_IR_SUBOP_PERMT_RC16 6
196 #define NV50_IR_SUBOP_BAR_SYNC 0
197 #define NV50_IR_SUBOP_BAR_ARRIVE 1
198 #define NV50_IR_SUBOP_BAR_RED_AND 2
199 #define NV50_IR_SUBOP_BAR_RED_OR 3
200 #define NV50_IR_SUBOP_BAR_RED_POPC 4
201 #define NV50_IR_SUBOP_MEMBAR_L 1
202 #define NV50_IR_SUBOP_MEMBAR_S 2
203 #define NV50_IR_SUBOP_MEMBAR_M 3
204 #define NV50_IR_SUBOP_MEMBAR_CTA (0 << 2)
205 #define NV50_IR_SUBOP_MEMBAR_GL (1 << 2)
206 #define NV50_IR_SUBOP_MEMBAR_SYS (2 << 2)
207 #define NV50_IR_SUBOP_MEMBAR_DIR(m) ((m) & 0x3)
208 #define NV50_IR_SUBOP_MEMBAR_SCOPE(m) ((m) & ~0x3)
209 #define NV50_IR_SUBOP_MEMBAR(d,s) \
210 (NV50_IR_SUBOP_MEMBAR_##d | NV50_IR_SUBOP_MEMBAR_##s)
211 #define NV50_IR_SUBOP_ATOM_ADD 0
212 #define NV50_IR_SUBOP_ATOM_MIN 1
213 #define NV50_IR_SUBOP_ATOM_MAX 2
214 #define NV50_IR_SUBOP_ATOM_INC 3
215 #define NV50_IR_SUBOP_ATOM_DEC 4
216 #define NV50_IR_SUBOP_ATOM_AND 5
217 #define NV50_IR_SUBOP_ATOM_OR 6
218 #define NV50_IR_SUBOP_ATOM_XOR 7
219 #define NV50_IR_SUBOP_ATOM_CAS 8
220 #define NV50_IR_SUBOP_ATOM_EXCH 9
221 #define NV50_IR_SUBOP_CCTL_IV 5
222 #define NV50_IR_SUBOP_CCTL_IVALL 6
223 #define NV50_IR_SUBOP_SUST_IGN 0
224 #define NV50_IR_SUBOP_SUST_TRAP 1
225 #define NV50_IR_SUBOP_SUST_SDCL 3
226 #define NV50_IR_SUBOP_SULD_ZERO 0
227 #define NV50_IR_SUBOP_SULD_TRAP 1
228 #define NV50_IR_SUBOP_SULD_SDCL 3
229 #define NV50_IR_SUBOP_SUBFM_3D 1
230 #define NV50_IR_SUBOP_SUCLAMP_2D 0x10
231 #define NV50_IR_SUBOP_SUCLAMP_SD(r, d) (( 0 + (r)) | ((d == 2) ? 0x10 : 0))
232 #define NV50_IR_SUBOP_SUCLAMP_PL(r, d) (( 5 + (r)) | ((d == 2) ? 0x10 : 0))
233 #define NV50_IR_SUBOP_SUCLAMP_BL(r, d) ((10 + (r)) | ((d == 2) ? 0x10 : 0))
234 #define NV50_IR_SUBOP_PIXLD_COUNT 0
235 #define NV50_IR_SUBOP_PIXLD_COVMASK 1
236 #define NV50_IR_SUBOP_PIXLD_COVERED 2
237 #define NV50_IR_SUBOP_PIXLD_OFFSET 3
238 #define NV50_IR_SUBOP_PIXLD_CENT_OFFSET 4
239 #define NV50_IR_SUBOP_PIXLD_SAMPLEID 5
240 #define NV50_IR_SUBOP_SHFL_IDX 0
241 #define NV50_IR_SUBOP_SHFL_UP 1
242 #define NV50_IR_SUBOP_SHFL_DOWN 2
243 #define NV50_IR_SUBOP_SHFL_BFLY 3
244 #define NV50_IR_SUBOP_LOAD_LOCKED 1
245 #define NV50_IR_SUBOP_STORE_UNLOCKED 2
246 #define NV50_IR_SUBOP_MADSP_SD 0xffff
247 // Yes, we could represent those with DataType.
248 // Or put the type into operation and have a couple 1000 values in that enum.
249 // This will have to do for now.
250 // The bitfields are supposed to correspond to nve4 ISA.
251 #define NV50_IR_SUBOP_MADSP(a,b,c) (((c) << 8) | ((b) << 4) | (a))
252 #define NV50_IR_SUBOP_V1(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x0000)
253 #define NV50_IR_SUBOP_V2(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x4000)
254 #define NV50_IR_SUBOP_V4(d,a,b) (((d) << 10) | ((b) << 5) | (a) | 0x8000)
255 #define NV50_IR_SUBOP_Vn(n) ((n) >> 14)
256 #define NV50_IR_SUBOP_VOTE_ALL 0
257 #define NV50_IR_SUBOP_VOTE_ANY 1
258 #define NV50_IR_SUBOP_VOTE_UNI 2
259 #define NV50_IR_SUBOP_LOP3_LUT_SRC0 0xf0
260 #define NV50_IR_SUBOP_LOP3_LUT_SRC1 0xcc
261 #define NV50_IR_SUBOP_LOP3_LUT_SRC2 0xaa
262 #define NV50_IR_SUBOP_LOP3_LUT(exp) ({ \
263 uint8_t a = NV50_IR_SUBOP_LOP3_LUT_SRC0; \
264 uint8_t b = NV50_IR_SUBOP_LOP3_LUT_SRC1; \
265 uint8_t c = NV50_IR_SUBOP_LOP3_LUT_SRC2; \
266 (uint8_t)(exp); \
267 })
268 #define NV50_IR_SUBOP_BMSK_C (0 << 0)
269 #define NV50_IR_SUBOP_BMSK_W (1 << 0)
270
271 #define NV50_IR_SUBOP_MINMAX_LOW 1
272 #define NV50_IR_SUBOP_MINMAX_MED 2
273 #define NV50_IR_SUBOP_MINMAX_HIGH 3
274
275 #define NV50_IR_SUBOP_SHF_L (0 << 0)
276 #define NV50_IR_SUBOP_SHF_R (1 << 0)
277 #define NV50_IR_SUBOP_SHF_LO (0 << 1)
278 #define NV50_IR_SUBOP_SHF_HI (1 << 1)
279 #define NV50_IR_SUBOP_SHF_C (0 << 2)
280 #define NV50_IR_SUBOP_SHF_W (1 << 2)
281
282 #define NV50_IR_SUBOP_VFETCH_PHYS 1
283
284 // xmad(src0, src1, 0) << 16 + src2
285 #define NV50_IR_SUBOP_XMAD_PSL (1 << 0)
286 // (xmad(src0, src1, src2) & 0xffff) | (src1 << 16)
287 #define NV50_IR_SUBOP_XMAD_MRG (1 << 1)
288 // xmad(src0, src1, src2.lo)
289 #define NV50_IR_SUBOP_XMAD_CLO (1 << 2)
290 // xmad(src0, src1, src2.hi)
291 #define NV50_IR_SUBOP_XMAD_CHI (2 << 2)
292 // if both operands to the multiplication are non-zero, subtract 65536 for each
293 // negative operand
294 #define NV50_IR_SUBOP_XMAD_CSFU (3 << 2)
295 // xmad(src0, src1, src2) + src1 << 16
296 #define NV50_IR_SUBOP_XMAD_CBCC (4 << 2)
297 #define NV50_IR_SUBOP_XMAD_CMODE_SHIFT 2
298 #define NV50_IR_SUBOP_XMAD_CMODE_MASK (0x7 << NV50_IR_SUBOP_XMAD_CMODE_SHIFT)
299
300 // use the high 16 bits instead of the low 16 bits for the multiplication.
301 // if the instruction's sType is signed, sign extend the operand from 16 bits
302 // to 32 before multiplication.
303 #define NV50_IR_SUBOP_XMAD_H1_SHIFT 5
304 #define NV50_IR_SUBOP_XMAD_H1(i) (1 << (NV50_IR_SUBOP_XMAD_H1_SHIFT + (i)))
305 #define NV50_IR_SUBOP_XMAD_H1_MASK (0x3 << NV50_IR_SUBOP_XMAD_H1_SHIFT)
306
307 enum DataType
308 {
309 TYPE_NONE,
310 TYPE_U8,
311 TYPE_S8,
312 TYPE_U16,
313 TYPE_S16,
314 TYPE_U32,
315 TYPE_S32,
316 TYPE_U64, // 64 bit operations are only lowered after register allocation
317 TYPE_S64,
318 TYPE_F16,
319 TYPE_F32,
320 TYPE_F64,
321 TYPE_B96,
322 TYPE_B128
323 };
324
325 enum CondCode
326 {
327 CC_FL = 0,
328 CC_NEVER = CC_FL, // when used with FILE_FLAGS
329 CC_LT = 1,
330 CC_EQ = 2,
331 CC_NOT_P = CC_EQ, // when used with FILE_PREDICATE
332 CC_LE = 3,
333 CC_GT = 4,
334 CC_NE = 5,
335 CC_P = CC_NE,
336 CC_GE = 6,
337 CC_TR = 7,
338 CC_ALWAYS = CC_TR,
339 CC_U = 8,
340 CC_LTU = 9,
341 CC_EQU = 10,
342 CC_LEU = 11,
343 CC_GTU = 12,
344 CC_NEU = 13,
345 CC_GEU = 14,
346 CC_NO = 0x10,
347 CC_NC = 0x11,
348 CC_NS = 0x12,
349 CC_NA = 0x13,
350 CC_A = 0x14,
351 CC_S = 0x15,
352 CC_C = 0x16,
353 CC_O = 0x17
354 };
355
356 enum RoundMode
357 {
358 ROUND_N, // nearest
359 ROUND_M, // towards -inf
360 ROUND_Z, // towards 0
361 ROUND_P, // towards +inf
362 ROUND_NI, // nearest integer
363 ROUND_MI, // to integer towards -inf
364 ROUND_ZI, // to integer towards 0
365 ROUND_PI, // to integer towards +inf
366 };
367
368 enum CacheMode
369 {
370 CACHE_CA, // cache at all levels
371 CACHE_WB = CACHE_CA, // cache write back
372 CACHE_CG, // cache at global level
373 CACHE_CS, // cache streaming
374 CACHE_CV, // cache as volatile
375 CACHE_WT = CACHE_CV // cache write-through
376 };
377
378 enum DataFile
379 {
380 FILE_NULL = 0,
381 FILE_GPR,
382 FILE_PREDICATE, // boolean predicate
383 FILE_FLAGS, // zero/sign/carry/overflow bits
384 FILE_ADDRESS,
385 FILE_BARRIER,
386 LAST_REGISTER_FILE = FILE_BARRIER,
387 FILE_IMMEDIATE,
388 FILE_MEMORY_CONST,
389 FILE_SHADER_INPUT,
390 FILE_SHADER_OUTPUT,
391 FILE_MEMORY_BUFFER,
392 FILE_MEMORY_GLOBAL,
393 FILE_MEMORY_SHARED,
394 FILE_MEMORY_LOCAL,
395 FILE_SYSTEM_VALUE,
396 FILE_THREAD_STATE, // "special" barrier registers
397 DATA_FILE_COUNT
398 };
399
400 enum TexTarget
401 {
402 TEX_TARGET_1D,
403 TEX_TARGET_2D,
404 TEX_TARGET_2D_MS,
405 TEX_TARGET_3D,
406 TEX_TARGET_CUBE,
407 TEX_TARGET_1D_SHADOW,
408 TEX_TARGET_2D_SHADOW,
409 TEX_TARGET_CUBE_SHADOW,
410 TEX_TARGET_1D_ARRAY,
411 TEX_TARGET_2D_ARRAY,
412 TEX_TARGET_2D_MS_ARRAY,
413 TEX_TARGET_CUBE_ARRAY,
414 TEX_TARGET_1D_ARRAY_SHADOW,
415 TEX_TARGET_2D_ARRAY_SHADOW,
416 TEX_TARGET_RECT,
417 TEX_TARGET_RECT_SHADOW,
418 TEX_TARGET_CUBE_ARRAY_SHADOW,
419 TEX_TARGET_BUFFER,
420 TEX_TARGET_COUNT
421 };
422
423 enum ImgFormat
424 {
425 FMT_RGBA32F,
426 FMT_RGBA16F,
427 FMT_RG32F,
428 FMT_RG16F,
429 FMT_R11G11B10F,
430 FMT_R32F,
431 FMT_R16F,
432
433 FMT_RGBA32UI,
434 FMT_RGBA16UI,
435 FMT_RGB10A2UI,
436 FMT_RGBA8UI,
437 FMT_RG32UI,
438 FMT_RG16UI,
439 FMT_RG8UI,
440 FMT_R32UI,
441 FMT_R16UI,
442 FMT_R8UI,
443
444 FMT_RGBA32I,
445 FMT_RGBA16I,
446 FMT_RGBA8I,
447 FMT_RG32I,
448 FMT_RG16I,
449 FMT_RG8I,
450 FMT_R32I,
451 FMT_R16I,
452 FMT_R8I,
453
454 FMT_RGBA16,
455 FMT_RGB10A2,
456 FMT_RGBA8,
457 FMT_RG16,
458 FMT_RG8,
459 FMT_R16,
460 FMT_R8,
461
462 FMT_RGBA16_SNORM,
463 FMT_RGBA8_SNORM,
464 FMT_RG16_SNORM,
465 FMT_RG8_SNORM,
466 FMT_R16_SNORM,
467 FMT_R8_SNORM,
468
469 FMT_BGRA8,
470
471 IMG_FORMAT_COUNT,
472 };
473
474 enum ImgType {
475 UINT,
476 SINT,
477 UNORM,
478 SNORM,
479 FLOAT,
480 };
481
482 enum SVSemantic
483 {
484 SV_POSITION, // WPOS
485 SV_VERTEX_ID,
486 SV_INSTANCE_ID,
487 SV_INVOCATION_ID,
488 SV_PRIMITIVE_ID,
489 SV_VERTEX_COUNT, // gl_PatchVerticesIn
490 SV_LAYER,
491 SV_VIEWPORT_INDEX,
492 SV_VIEWPORT_MASK,
493 SV_YDIR,
494 SV_FACE,
495 SV_POINT_SIZE,
496 SV_POINT_COORD,
497 SV_CLIP_DISTANCE,
498 SV_SAMPLE_INDEX,
499 SV_SAMPLE_POS,
500 SV_SAMPLE_MASK,
501 SV_TESS_OUTER,
502 SV_TESS_INNER,
503 SV_TESS_COORD,
504 SV_TID,
505 SV_COMBINED_TID,
506 SV_CTAID,
507 SV_NTID,
508 SV_GRIDID,
509 SV_NCTAID,
510 SV_LANEID,
511 SV_PHYSID,
512 SV_NPHYSID,
513 SV_CLOCK,
514 SV_LBASE,
515 SV_SBASE,
516 SV_VERTEX_STRIDE,
517 SV_INVOCATION_INFO,
518 SV_THREAD_KILL,
519 SV_BASEVERTEX,
520 SV_BASEINSTANCE,
521 SV_DRAWID,
522 SV_WORK_DIM,
523 SV_LANEMASK_EQ,
524 SV_LANEMASK_LT,
525 SV_LANEMASK_LE,
526 SV_LANEMASK_GT,
527 SV_LANEMASK_GE,
528 SV_UNDEFINED,
529 SV_LAST
530 };
531
532 enum TSSemantic
533 {
534 // 0-15 are fixed ones on Volta/Turing
535 TS_THREAD_STATE_ENUM0 = 0,
536 TS_THREAD_STATE_ENUM1 = 1,
537 TS_THREAD_STATE_ENUM2 = 2,
538 TS_THREAD_STATE_ENUM3 = 3,
539 TS_THREAD_STATE_ENUM4 = 4,
540 TS_TRAP_RETURN_PC_LO = 5,
541 TS_TRAP_RETURN_PC_HI = 6,
542 TS_TRAP_RETURN_MASK = 7,
543 TS_MEXITED = 8,
544 TS_MKILL = 9,
545 TS_MACTIVE = 10,
546 TS_MATEXIT = 11,
547 TS_OPT_STACK = 12,
548 TS_API_CALL_DEPTH = 13,
549 TS_ATEXIT_PC_LO = 14,
550 TS_ATEXIT_PC_HI = 15,
551 // special ones to make our life easier
552 TS_PQUAD_MACTIVE,
553 };
554
555 class Program;
556 class Function;
557 class BasicBlock;
558
559 class Target;
560
561 class Instruction;
562 class CmpInstruction;
563 class TexInstruction;
564 class FlowInstruction;
565
566 class Value;
567 class LValue;
568 class Symbol;
569 class ImmediateValue;
570
571 struct Storage
572 {
573 DataFile file;
574 int8_t fileIndex; // signed, may be indirect for CONST[]
575 uint8_t size; // this should match the Instruction type's size
576 DataType type; // mainly for pretty printing
577 union {
578 uint64_t u64; // immediate values
579 uint32_t u32;
580 uint16_t u16;
581 uint8_t u8;
582 int64_t s64;
583 int32_t s32;
584 int16_t s16;
585 int8_t s8;
586 float f32;
587 double f64;
588 int32_t offset; // offset from 0 (base of address space)
589 int32_t id; // register id (< 0 if virtual/unassigned, in units <= 4)
590 struct {
591 SVSemantic sv;
592 int index;
593 } sv;
594 TSSemantic ts;
595 } data;
596 };
597
598 // precedence: NOT after SAT after NEG after ABS
599 #define NV50_IR_MOD_ABS (1 << 0)
600 #define NV50_IR_MOD_NEG (1 << 1)
601 #define NV50_IR_MOD_SAT (1 << 2)
602 #define NV50_IR_MOD_NOT (1 << 3)
603 #define NV50_IR_MOD_NEG_ABS (NV50_IR_MOD_NEG | NV50_IR_MOD_ABS)
604
605 #define NV50_IR_INTERP_MODE_MASK 0x3
606 #define NV50_IR_INTERP_LINEAR (0 << 0)
607 #define NV50_IR_INTERP_PERSPECTIVE (1 << 0)
608 #define NV50_IR_INTERP_FLAT (2 << 0)
609 #define NV50_IR_INTERP_SC (3 << 0) // what exactly is that ?
610 #define NV50_IR_INTERP_SAMPLE_MASK 0xc
611 #define NV50_IR_INTERP_DEFAULT (0 << 2)
612 #define NV50_IR_INTERP_CENTROID (1 << 2)
613 #define NV50_IR_INTERP_OFFSET (2 << 2)
614 #define NV50_IR_INTERP_SAMPLEID (3 << 2)
615
616 // do we really want this to be a class ?
617 class Modifier
618 {
619 public:
620 Modifier() : bits(0) { }
621 Modifier(unsigned int m) : bits(m) { }
622 Modifier(operation op);
623
624 // @return new Modifier applying a after b (asserts if unrepresentable)
625 Modifier operator*(const Modifier) const;
626 Modifier operator*=(const Modifier m) { *this = *this * m; return *this; }
627 Modifier operator==(const Modifier m) const { return m.bits == bits; }
628 Modifier operator!=(const Modifier m) const { return m.bits != bits; }
629
630 inline Modifier operator&(const Modifier m) const { return bits & m.bits; }
631 inline Modifier operator|(const Modifier m) const { return bits | m.bits; }
632 inline Modifier operator^(const Modifier m) const { return bits ^ m.bits; }
633
634 operation getOp() const;
635
636 inline int neg() const { return (bits & NV50_IR_MOD_NEG) ? 1 : 0; }
637 inline int abs() const { return (bits & NV50_IR_MOD_ABS) ? 1 : 0; }
638
639 inline operator bool() const { return bits ? true : false; }
640
641 void applyTo(ImmediateValue &imm) const;
642
643 int print(char *buf, size_t size) const;
644
645 private:
646 uint8_t bits;
647 };
648
649 class ValueRef
650 {
651 public:
652 ValueRef(Value * = NULL);
653 ValueRef(const ValueRef&);
654 ~ValueRef();
655
656 ValueRef& operator=(const ValueRef&) = delete;
657
658 inline bool exists() const { return value != NULL; }
659
660 void set(Value *);
661 void set(const ValueRef&);
662 inline Value *get() const { return value; }
663 inline Value *rep() const;
664
665 inline Instruction *getInsn() const { return insn; }
666 inline void setInsn(Instruction *inst) { insn = inst; }
667
668 inline bool isIndirect(int dim) const { return indirect[dim] >= 0; }
669 inline const ValueRef *getIndirect(int dim) const;
670
671 inline DataFile getFile() const;
672 inline unsigned getSize() const;
673
674 // SSA: return eventual (traverse MOVs) literal value, if it exists
675 bool getImmediate(ImmediateValue&) const;
676
677 public:
678 Modifier mod;
679 int8_t indirect[2]; // >= 0 if relative to lvalue in insn->src(indirect[i])
680
681 bool usedAsPtr; // for printing
682
683 private:
684 Value *value;
685 Instruction *insn;
686 };
687
688 class ValueDef
689 {
690 public:
691 ValueDef(Value * = NULL);
692 ValueDef(const ValueDef&);
693 ~ValueDef();
694
695 ValueDef& operator=(const ValueDef&) = delete;
696
697 inline bool exists() const { return value != NULL; }
698
699 inline Value *get() const { return value; }
700 inline Value *rep() const;
701 void set(Value *);
702 bool mayReplace(const ValueRef &);
703 void replace(const ValueRef &, bool doSet); // replace all uses of the old value
704
705 inline Instruction *getInsn() const { return insn; }
706 inline void setInsn(Instruction *inst) { insn = inst; }
707
708 inline DataFile getFile() const;
709 inline unsigned getSize() const;
710
711 inline void setSSA(LValue *);
712 inline const LValue *preSSA() const;
713
714 private:
715 Value *value; // should make this LValue * ...
716 LValue *origin; // pre SSA value
717 Instruction *insn;
718 };
719
720 class Value
721 {
722 public:
723 Value();
724 virtual ~Value() { }
725
726 Value(const Value&) = delete;
727 Value& operator=(const Value&) = delete;
728
729 virtual Value *clone(ClonePolicy<Function>&) const = 0;
730
731 virtual int print(char *, size_t, DataType ty = TYPE_NONE) const = 0;
732
733 virtual bool equals(const Value *, bool strict = false) const;
734 virtual bool interfers(const Value *) const;
735 virtual bool isUniform() const { return true; }
736
737 inline Value *rep() const { return join; }
738
739 inline Instruction *getUniqueInsn() const;
740 inline Instruction *getInsn() const; // use when uniqueness is certain
741
742 inline int refCount() { return uses.size(); }
743
744 inline LValue *asLValue();
745 inline Symbol *asSym();
746 inline ImmediateValue *asImm();
747 inline const Symbol *asSym() const;
748 inline const ImmediateValue *asImm() const;
749
750 inline bool inFile(DataFile f) const { return reg.file == f; }
751
752 static inline Value *get(Iterator&);
753
754 std::unordered_set<ValueRef *> uses;
755 std::list<ValueDef *> defs;
756 typedef std::unordered_set<ValueRef *>::iterator UseIterator;
757 typedef std::unordered_set<ValueRef *>::const_iterator UseCIterator;
758 typedef std::list<ValueDef *>::iterator DefIterator;
759 typedef std::list<ValueDef *>::const_iterator DefCIterator;
760
761 int id;
762 Storage reg;
763
764 // TODO: these should be in LValue:
765 Interval livei;
766 Value *join;
767 };
768
769 class LValue : public Value
770 {
771 public:
772 LValue(Function *, DataFile file);
773 LValue(Function *, LValue *);
774 ~LValue() { }
775
776 virtual bool isUniform() const;
777
778 virtual LValue *clone(ClonePolicy<Function>&) const;
779
780 virtual int print(char *, size_t, DataType ty = TYPE_NONE) const;
781
782 public:
783 unsigned compMask : 8; // compound/component mask
784 unsigned compound : 1; // used by RA, value involved in split/merge
785 unsigned ssa : 1;
786 unsigned noSpill : 1; // do not spill (e.g. if spill temporary already)
787 };
788
789 class Symbol : public Value
790 {
791 public:
792 Symbol(Program *, DataFile file = FILE_MEMORY_CONST, uint8_t fileIdx = 0);
793 ~Symbol() { }
794
795 virtual Symbol *clone(ClonePolicy<Function>&) const;
796
797 virtual bool equals(const Value *that, bool strict) const;
798
799 virtual bool isUniform() const;
800
801 virtual int print(char *, size_t, DataType ty = TYPE_NONE) const;
802
803 // print with indirect values
804 int print(char *, size_t, Value *, Value *, DataType ty = TYPE_NONE) const;
805
806 inline void setFile(DataFile file, uint8_t fileIndex = 0)
807 {
808 reg.file = file;
809 reg.fileIndex = fileIndex;
810 }
811
812 inline void setOffset(int32_t offset);
813 inline void setAddress(Symbol *base, int32_t offset);
814 inline void setSV(SVSemantic sv, uint32_t idx = 0);
815
816 inline const Symbol *getBase() const { return baseSym; }
817
818 private:
819 Symbol *baseSym; // array base for Symbols representing array elements
820 };
821
822 class ImmediateValue : public Value
823 {
824 public:
825 ImmediateValue() { }
826 ImmediateValue(Program *, uint32_t);
827 ImmediateValue(Program *, float);
828 ImmediateValue(Program *, double);
829 // NOTE: not added to program with
830 ImmediateValue(const ImmediateValue *, DataType ty);
831 ~ImmediateValue() { };
832
833 virtual ImmediateValue *clone(ClonePolicy<Function>&) const;
834
835 virtual bool equals(const Value *that, bool strict) const;
836
837 // these only work if 'type' is valid (we mostly use untyped literals):
838 bool isInteger(const int ival) const; // ival is cast to this' type
839 bool isNegative() const;
840 bool isPow2() const;
841
842 void applyLog2();
843
844 // for constant folding:
845 ImmediateValue operator+(const ImmediateValue&) const;
846 ImmediateValue operator-(const ImmediateValue&) const;
847 ImmediateValue operator*(const ImmediateValue&) const;
848 ImmediateValue operator/(const ImmediateValue&) const;
849
850 ImmediateValue& operator=(const ImmediateValue&); // only sets value !
851
852 bool compare(CondCode cc, float fval) const;
853
854 virtual int print(char *, size_t, DataType ty = TYPE_NONE) const;
855 };
856
857 class Instruction
858 {
859 public:
860 Instruction();
861 Instruction(Function *, operation, DataType);
862 virtual ~Instruction();
863
864 Instruction(const Instruction&) = delete;
865 Instruction& operator=(const Instruction&) = delete;
866
867 virtual Instruction *clone(ClonePolicy<Function>&,
868 Instruction * = NULL) const;
869
870 void setDef(int i, Value *);
871 void setSrc(int s, Value *);
872 void setSrc(int s, const ValueRef&);
873 void swapSources(int a, int b);
874 void moveSources(int s, int delta);
875 bool setIndirect(int s, int dim, Value *);
876
877 inline ValueRef& src(int s) { return srcs[s]; }
878 inline ValueDef& def(int s) { return defs[s]; }
879 inline const ValueRef& src(int s) const { return srcs[s]; }
880 inline const ValueDef& def(int s) const { return defs[s]; }
881
882 inline Value *getDef(int d) const { return defs[d].get(); }
883 inline Value *getSrc(int s) const { return srcs[s].get(); }
884 inline Value *getIndirect(int s, int dim) const;
885
886 inline bool defExists(unsigned d) const
887 {
888 return d < defs.size() && defs[d].exists();
889 }
890 inline bool srcExists(unsigned s) const
891 {
892 return s < srcs.size() && srcs[s].exists();
893 }
894
895 inline bool constrainedDefs() const;
896
897 bool setPredicate(CondCode ccode, Value *);
898 inline Value *getPredicate() const;
899 bool writesPredicate() const;
900 inline bool isPredicated() const { return predSrc >= 0; }
901
902 inline void setFlagsSrc(int s, Value *);
903 inline void setFlagsDef(int d, Value *);
904 inline bool usesFlags() const { return flagsSrc >= 0; }
905
906 unsigned int defCount() const { return defs.size(); };
907 unsigned int defCount(unsigned int mask, bool singleFile = false) const;
908 unsigned int srcCount() const { return srcs.size(); };
909 unsigned int srcCount(unsigned int mask, bool singleFile = false) const;
910
911 // save & remove / set indirect[0,1] and predicate source
912 void takeExtraSources(int s, Value *[3]);
913 void putExtraSources(int s, Value *[3]);
914
915 inline void setType(DataType type) { dType = sType = type; }
916
917 inline void setType(DataType dtype, DataType stype)
918 {
919 dType = dtype;
920 sType = stype;
921 }
922
923 inline bool isPseudo() const { return op < OP_MOV; }
924 bool isDead() const;
925 bool isNop() const;
926 bool isCommutationLegal(const Instruction *) const; // must be adjacent !
927 bool isActionEqual(const Instruction *) const;
928 bool isResultEqual(const Instruction *) const;
929
930 // check whether the defs interfere with srcs and defs of another instruction
931 bool canCommuteDefDef(const Instruction *) const;
932 bool canCommuteDefSrc(const Instruction *) const;
933
934 void print() const;
935
936 inline CmpInstruction *asCmp();
937 inline TexInstruction *asTex();
938 inline FlowInstruction *asFlow();
939 inline const TexInstruction *asTex() const;
940 inline const CmpInstruction *asCmp() const;
941 inline const FlowInstruction *asFlow() const;
942
943 public:
944 Instruction *next;
945 Instruction *prev;
946 int id;
947 int serial; // CFG order
948
949 operation op;
950 DataType dType; // destination or defining type
951 DataType sType; // source or secondary type
952 CondCode cc;
953 RoundMode rnd;
954 CacheMode cache;
955
956 uint16_t subOp; // quadop, 1 for mul-high, etc.
957
958 unsigned encSize : 5; // encoding size in bytes
959 unsigned saturate : 1; // to [0.0f, 1.0f]
960 unsigned join : 1; // converge control flow (use OP_JOIN until end)
961 unsigned fixed : 1; // prevent dead code elimination
962 unsigned terminator : 1; // end of basic block
963 unsigned ftz : 1; // flush denormal to zero
964 unsigned dnz : 1; // denormals, NaN are zero
965 unsigned ipa : 4; // interpolation mode
966 unsigned lanes : 4;
967 unsigned perPatch : 1;
968 unsigned exit : 1; // terminate program after insn
969 unsigned mask : 4; // for vector ops
970 // prevent algebraic optimisations that aren't bit-for-bit identical
971 unsigned precise : 1;
972
973 int8_t postFactor; // MUL/DIV(if < 0) by 1 << postFactor
974
975 int8_t predSrc;
976 int8_t flagsDef;
977 int8_t flagsSrc;
978
979 uint32_t sched; // scheduling data (NOTE: maybe move to separate storage)
980
981 BasicBlock *bb;
982
983 protected:
984 std::deque<ValueDef> defs; // no gaps !
985 std::deque<ValueRef> srcs; // no gaps !
986
987 // instruction specific methods:
988 // (don't want to subclass, would need more constructors and memory pools)
989 public:
990 inline void setInterpolate(unsigned int mode) { ipa = mode; }
991
992 unsigned int getInterpMode() const { return ipa & 0x3; }
993 unsigned int getSampleMode() const { return ipa & 0xc; }
994
995 private:
996 void init();
997 };
998
999 enum TexQuery
1000 {
1001 TXQ_DIMS, /* x, y, z, levels */
1002 TXQ_TYPE, /* ?, ?, samples, ? */
1003 TXQ_SAMPLE_POSITION,
1004 TXQ_FILTER,
1005 TXQ_LOD,
1006 TXQ_WRAP,
1007 TXQ_BORDER_COLOUR
1008 };
1009
1010 class TexInstruction : public Instruction
1011 {
1012 public:
1013 class Target
1014 {
1015 public:
1016 Target(TexTarget targ = TEX_TARGET_1D) : target(targ) { }
1017
1018 const char *getName() const { return descTable[target].name; }
1019 unsigned int getArgCount() const { return descTable[target].argc; }
1020 unsigned int getDim() const { return descTable[target].dim; }
1021 int isArray() const { return descTable[target].array ? 1 : 0; }
1022 int isCube() const { return descTable[target].cube ? 1 : 0; }
1023 int isShadow() const { return descTable[target].shadow ? 1 : 0; }
1024 int isMS() const {
1025 return target == TEX_TARGET_2D_MS || target == TEX_TARGET_2D_MS_ARRAY; }
1026 void clearMS() {
1027 if (isMS()) {
1028 if (isArray())
1029 target = TEX_TARGET_2D_ARRAY;
1030 else
1031 target = TEX_TARGET_2D;
1032 }
1033 }
1034
1035 Target& operator=(TexTarget targ)
1036 {
1037 assert(targ < TEX_TARGET_COUNT);
1038 target = targ;
1039 return *this;
1040 }
1041
1042 inline bool operator==(TexTarget targ) const { return target == targ; }
1043 inline bool operator!=(TexTarget targ) const { return target != targ; }
1044
1045 enum TexTarget getEnum() const { return target; }
1046
1047 private:
1048 struct Desc
1049 {
1050 char name[19];
1051 uint8_t dim;
1052 uint8_t argc;
1053 bool array;
1054 bool cube;
1055 bool shadow;
1056 };
1057
1058 static const struct Desc descTable[TEX_TARGET_COUNT];
1059
1060 private:
1061 enum TexTarget target;
1062 };
1063
1064 public:
1065 struct ImgFormatDesc
1066 {
1067 char name[19];
1068 uint8_t components;
1069 uint8_t bits[4];
1070 ImgType type;
1071 bool bgra;
1072 };
1073
1074 static const struct ImgFormatDesc formatTable[IMG_FORMAT_COUNT];
1075 static const struct ImgFormatDesc *translateImgFormat(
1076 enum pipe_format format);
1077
1078 public:
1079 TexInstruction(Function *, operation);
1080 virtual ~TexInstruction();
1081
1082 virtual TexInstruction *clone(ClonePolicy<Function>&,
1083 Instruction * = NULL) const;
1084
1085 inline void setTexture(Target targ, uint8_t r, uint8_t s)
1086 {
1087 tex.r = r;
1088 tex.s = s;
1089 tex.target = targ;
1090 }
1091
1092 void setIndirectR(Value *);
1093 void setIndirectS(Value *);
1094 inline Value *getIndirectR() const;
1095 inline Value *getIndirectS() const;
1096
1097 public:
1098 struct {
1099 Target target;
1100
1101 uint16_t r;
1102 uint16_t s;
1103 int8_t rIndirectSrc;
1104 int8_t sIndirectSrc;
1105
1106 uint8_t mask;
1107 uint8_t gatherComp;
1108
1109 bool liveOnly; // only execute on live pixels of a quad (optimization)
1110 bool levelZero;
1111 bool derivAll;
1112 bool bindless;
1113
1114 int8_t useOffsets; // 0, 1, or 4 for textureGatherOffsets
1115 int8_t offset[3]; // only used on nv50
1116
1117 enum TexQuery query;
1118 const struct ImgFormatDesc *format;
1119
1120 bool scalar; // for GM107s TEXS, TLDS, TLD4S
1121 } tex;
1122
1123 ValueRef dPdx[3];
1124 ValueRef dPdy[3];
1125 ValueRef offset[4][3];
1126 };
1127
1128 class CmpInstruction : public Instruction
1129 {
1130 public:
1131 CmpInstruction(Function *, operation);
1132
1133 virtual CmpInstruction *clone(ClonePolicy<Function>&,
1134 Instruction * = NULL) const;
1135
1136 void setCondition(CondCode cond) { setCond = cond; }
1137 CondCode getCondition() const { return setCond; }
1138
1139 public:
1140 CondCode setCond;
1141 };
1142
1143 class FlowInstruction : public Instruction
1144 {
1145 public:
1146 FlowInstruction(Function *, operation, void *target);
1147
1148 virtual FlowInstruction *clone(ClonePolicy<Function>&,
1149 Instruction * = NULL) const;
1150
1151 public:
1152 unsigned allWarp : 1;
1153 unsigned absolute : 1;
1154 unsigned limit : 1;
1155 unsigned builtin : 1; // true for calls to emulation code
1156 unsigned indirect : 1; // target in src(0)
1157
1158 union {
1159 BasicBlock *bb;
1160 int builtin;
1161 Function *fn;
1162 } target;
1163 };
1164
1165 class BasicBlock
1166 {
1167 public:
1168 BasicBlock(Function *);
1169 ~BasicBlock();
1170
1171 BasicBlock(const BasicBlock&) = delete;
1172 BasicBlock& operator=(const BasicBlock&) = delete;
1173
1174 BasicBlock *clone(ClonePolicy<Function>&) const;
1175
1176 inline int getId() const { return id; }
1177 inline unsigned int getInsnCount() const { return numInsns; }
1178 inline bool isTerminated() const { return exit && exit->terminator; }
1179
1180 bool dominatedBy(BasicBlock *bb);
1181 inline bool reachableBy(const BasicBlock *by, const BasicBlock *term);
1182
1183 // returns mask of conditional out blocks
1184 // e.g. 3 for IF { .. } ELSE { .. } ENDIF, 1 for IF { .. } ENDIF
1185 unsigned int initiatesSimpleConditional() const;
1186
1187 public:
1188 Function *getFunction() const { return func; }
1189 Program *getProgram() const { return program; }
1190
1191 Instruction *getEntry() const { return entry; } // first non-phi instruction
1192 Instruction *getPhi() const { return phi; }
1193 Instruction *getFirst() const { return phi ? phi : entry; }
1194 Instruction *getExit() const { return exit; }
1195
1196 void insertHead(Instruction *);
1197 void insertTail(Instruction *);
1198 void insertBefore(Instruction *, Instruction *);
1199 void insertAfter(Instruction *, Instruction *);
1200 void remove(Instruction *);
1201 void permuteAdjacent(Instruction *, Instruction *);
1202
1203 BasicBlock *idom() const;
1204
1205 // NOTE: currently does not rebuild the dominator tree
1206 BasicBlock *splitBefore(Instruction *, bool attach = true);
1207 BasicBlock *splitAfter(Instruction *, bool attach = true);
1208
1209 DLList& getDF() { return df; }
1210 DLList::Iterator iterDF() { return df.iterator(); }
1211
1212 static inline BasicBlock *get(Iterator&);
1213 static inline BasicBlock *get(Graph::Node *);
1214
1215 public:
1216 Graph::Node cfg; // first edge is branch *taken* (the ELSE branch)
1217 Graph::Node dom;
1218
1219 BitSet liveSet;
1220 BitSet defSet;
1221
1222 uint32_t binPos;
1223 uint32_t binSize;
1224
1225 Instruction *joinAt; // for quick reference
1226
1227 bool explicitCont; // loop headers: true if loop contains continue stmts
1228
1229 private:
1230 int id;
1231 DLList df;
1232
1233 Instruction *phi;
1234 Instruction *entry;
1235 Instruction *exit;
1236
1237 unsigned int numInsns;
1238
1239 private:
1240 Function *func;
1241 Program *program;
1242
1243 void splitCommon(Instruction *, BasicBlock *, bool attach);
1244 };
1245
1246 class Function
1247 {
1248 public:
1249 Function(Program *, const char *name, uint32_t label);
1250 ~Function();
1251
1252 Function(const Function&) = delete;
1253 Function& operator=(const Function&) = delete;
1254
1255 static inline Function *get(Graph::Node *node);
1256
1257 inline Program *getProgram() const { return prog; }
1258 inline const char *getName() const { return name; }
1259 inline int getId() const { return id; }
1260 inline uint32_t getLabel() const { return label; }
1261
1262 void print();
1263 void printLiveIntervals() const;
1264 void printCFGraph(const char *filePath);
1265
1266 bool setEntry(BasicBlock *);
1267 bool setExit(BasicBlock *);
1268
1269 unsigned int orderInstructions(ArrayList&);
1270
1271 inline void add(BasicBlock *bb, int& id) { allBBlocks.insert(bb, id); }
1272 inline void add(Instruction *insn, int& id) { allInsns.insert(insn, id); }
1273 inline void add(LValue *lval, int& id) { allLValues.insert(lval, id); }
1274
1275 inline LValue *getLValue(int id);
1276
1277 void buildLiveSets();
1278 bool convertToSSA();
1279
1280 public:
1281 std::deque<ValueDef> ins;
1282 std::deque<ValueRef> outs;
1283 std::deque<Value *> clobbers;
1284
1285 Graph cfg;
1286 Graph::Node *cfgExit;
1287 Graph *domTree;
1288 Graph::Node call; // node in the call graph
1289
1290 BasicBlock **bbArray; // BBs in emission order
1291 int bbCount;
1292
1293 unsigned int loopNestingBound;
1294 int regClobberMax;
1295
1296 uint32_t binPos;
1297 uint32_t binSize;
1298
1299 uint32_t tlsBase; // base address for l[] space (if no stack pointer is used)
1300 uint32_t tlsSize;
1301
1302 ArrayList allBBlocks;
1303 ArrayList allInsns;
1304 ArrayList allLValues;
1305
1306 private:
1307 void buildLiveSetsPreSSA(BasicBlock *, const int sequence);
1308 void buildDefSetsPreSSA(BasicBlock *bb, const int seq);
1309
1310 private:
1311 uint32_t label;
1312 int id;
1313 const char *const name;
1314 Program *prog;
1315 };
1316
1317 enum CGStage
1318 {
1319 CG_STAGE_PRE_SSA,
1320 CG_STAGE_SSA, // expected directly before register allocation
1321 CG_STAGE_POST_RA
1322 };
1323
1324 class Program
1325 {
1326 public:
1327 enum Type
1328 {
1329 TYPE_VERTEX,
1330 TYPE_TESSELLATION_CONTROL,
1331 TYPE_TESSELLATION_EVAL,
1332 TYPE_GEOMETRY,
1333 TYPE_FRAGMENT,
1334 TYPE_COMPUTE
1335 };
1336
1337 Program(Type type, Target *targ);
1338 ~Program();
1339
1340 Program(const Program&) = delete;
1341 Program& operator=(const Program&) = delete;
1342
1343 void print();
1344
1345 Type getType() const { return progType; }
1346
1347 inline void add(Function *fn, int& id) { allFuncs.insert(fn, id); }
1348 inline void del(Function *fn, int& id) { allFuncs.remove(id); }
1349 inline void add(Value *rval, int& id) { allRValues.insert(rval, id); }
1350
1351 bool makeFromNIR(struct nv50_ir_prog_info *,
1352 struct nv50_ir_prog_info_out *);
1353 bool convertToSSA();
1354 bool optimizeSSA(int level);
1355 bool optimizePostRA(int level);
1356 bool registerAllocation();
1357 bool emitBinary(struct nv50_ir_prog_info_out *);
1358
1359 const Target *getTarget() const { return target; }
1360
1361 private:
1362 Type progType;
1363 Target *target;
1364
1365 public:
1366 Function *main;
1367 Graph calls;
1368
1369 ArrayList allFuncs;
1370 ArrayList allRValues;
1371
1372 uint32_t *code;
1373 uint32_t binSize;
1374 uint32_t tlsSize; // size required for FILE_MEMORY_LOCAL
1375
1376 int maxGPR;
1377 bool fp64;
1378 bool persampleInvocation;
1379
1380 MemoryPool mem_Instruction;
1381 MemoryPool mem_CmpInstruction;
1382 MemoryPool mem_TexInstruction;
1383 MemoryPool mem_FlowInstruction;
1384 MemoryPool mem_LValue;
1385 MemoryPool mem_Symbol;
1386 MemoryPool mem_ImmediateValue;
1387
1388 uint32_t dbgFlags;
1389 uint8_t optLevel;
1390
1391 void *targetPriv; // e.g. to carry information between passes
1392
1393 const struct nv50_ir_prog_info *driver; // for driver configuration
1394 const struct nv50_ir_prog_info_out *driver_out; // for driver configuration
1395
1396 void releaseInstruction(Instruction *);
1397 void releaseValue(Value *);
1398 };
1399
1400 // TODO: add const version
1401 class Pass
1402 {
1403 public:
1404 bool run(Program *, bool ordered = false, bool skipPhi = false);
1405 bool run(Function *, bool ordered = false, bool skipPhi = false);
1406
1407 private:
1408 bool doRun(Program *, bool ordered, bool skipPhi);
1409 bool doRun(Function *, bool ordered, bool skipPhi);
1410
1411 protected:
1412 // return false to continue with next entity on next higher level
1413 virtual bool visit(Function *) { return true; }
1414 virtual bool visit(BasicBlock *) { return true; }
1415 virtual bool visit(Instruction *) { return false; }
1416
1417 bool err;
1418 Function *func;
1419 Program *prog;
1420 };
1421
1422 // =============================================================================
1423
1424 #include "nv50_ir_inlines.h"
1425
1426 } // namespace nv50_ir
1427
1428 #endif // __NV50_IR_H__