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