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: Modifier()620 Modifier() : bits(0) { } Modifier(unsigned int m)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 neg()636 inline int neg() const { return (bits & NV50_IR_MOD_NEG) ? 1 : 0; } abs()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 exists()658 inline bool exists() const { return value != NULL; } 659 660 void set(Value *); 661 void set(const ValueRef&); get()662 inline Value *get() const { return value; } 663 inline Value *rep() const; 664 getInsn()665 inline Instruction *getInsn() const { return insn; } setInsn(Instruction * inst)666 inline void setInsn(Instruction *inst) { insn = inst; } 667 isIndirect(int dim)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 exists()697 inline bool exists() const { return value != NULL; } 698 get()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 getInsn()705 inline Instruction *getInsn() const { return insn; } setInsn(Instruction * inst)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(); ~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; isUniform()735 virtual bool isUniform() const { return true; } 736 rep()737 inline Value *rep() const { return join; } 738 739 inline Instruction *getUniqueInsn() const; 740 inline Instruction *getInsn() const; // use when uniqueness is certain 741 refCount()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 inFile(DataFile f)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 *); ~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 fixedReg : 1; // set & used by RA, earlier just use (id < 0) 787 unsigned noSpill : 1; // do not spill (e.g. if spill temporary already) 788 }; 789 790 class Symbol : public Value 791 { 792 public: 793 Symbol(Program *, DataFile file = FILE_MEMORY_CONST, uint8_t fileIdx = 0); ~Symbol()794 ~Symbol() { } 795 796 virtual Symbol *clone(ClonePolicy<Function>&) const; 797 798 virtual bool equals(const Value *that, bool strict) const; 799 800 virtual bool isUniform() const; 801 802 virtual int print(char *, size_t, DataType ty = TYPE_NONE) const; 803 804 // print with indirect values 805 int print(char *, size_t, Value *, Value *, DataType ty = TYPE_NONE) const; 806 807 inline void setFile(DataFile file, uint8_t fileIndex = 0) 808 { 809 reg.file = file; 810 reg.fileIndex = fileIndex; 811 } 812 813 inline void setOffset(int32_t offset); 814 inline void setAddress(Symbol *base, int32_t offset); 815 inline void setSV(SVSemantic sv, uint32_t idx = 0); 816 getBase()817 inline const Symbol *getBase() const { return baseSym; } 818 819 private: 820 Symbol *baseSym; // array base for Symbols representing array elements 821 }; 822 823 class ImmediateValue : public Value 824 { 825 public: ImmediateValue()826 ImmediateValue() { } 827 ImmediateValue(Program *, uint32_t); 828 ImmediateValue(Program *, float); 829 ImmediateValue(Program *, double); 830 // NOTE: not added to program with 831 ImmediateValue(const ImmediateValue *, DataType ty); ~ImmediateValue()832 ~ImmediateValue() { }; 833 834 virtual ImmediateValue *clone(ClonePolicy<Function>&) const; 835 836 virtual bool equals(const Value *that, bool strict) const; 837 838 // these only work if 'type' is valid (we mostly use untyped literals): 839 bool isInteger(const int ival) const; // ival is cast to this' type 840 bool isNegative() const; 841 bool isPow2() const; 842 843 void applyLog2(); 844 845 // for constant folding: 846 ImmediateValue operator+(const ImmediateValue&) const; 847 ImmediateValue operator-(const ImmediateValue&) const; 848 ImmediateValue operator*(const ImmediateValue&) const; 849 ImmediateValue operator/(const ImmediateValue&) const; 850 851 ImmediateValue& operator=(const ImmediateValue&); // only sets value ! 852 853 bool compare(CondCode cc, float fval) const; 854 855 virtual int print(char *, size_t, DataType ty = TYPE_NONE) const; 856 }; 857 858 class Instruction 859 { 860 public: 861 Instruction(); 862 Instruction(Function *, operation, DataType); 863 virtual ~Instruction(); 864 865 Instruction(const Instruction&) = delete; 866 Instruction& operator=(const Instruction&) = delete; 867 868 virtual Instruction *clone(ClonePolicy<Function>&, 869 Instruction * = NULL) const; 870 871 void setDef(int i, Value *); 872 void setSrc(int s, Value *); 873 void setSrc(int s, const ValueRef&); 874 void swapSources(int a, int b); 875 void moveSources(int s, int delta); 876 bool setIndirect(int s, int dim, Value *); 877 src(int s)878 inline ValueRef& src(int s) { return srcs[s]; } def(int s)879 inline ValueDef& def(int s) { return defs[s]; } src(int s)880 inline const ValueRef& src(int s) const { return srcs[s]; } def(int s)881 inline const ValueDef& def(int s) const { return defs[s]; } 882 getDef(int d)883 inline Value *getDef(int d) const { return defs[d].get(); } getSrc(int s)884 inline Value *getSrc(int s) const { return srcs[s].get(); } 885 inline Value *getIndirect(int s, int dim) const; 886 defExists(unsigned d)887 inline bool defExists(unsigned d) const 888 { 889 return d < defs.size() && defs[d].exists(); 890 } srcExists(unsigned s)891 inline bool srcExists(unsigned s) const 892 { 893 return s < srcs.size() && srcs[s].exists(); 894 } 895 896 inline bool constrainedDefs() const; 897 898 bool setPredicate(CondCode ccode, Value *); 899 inline Value *getPredicate() const; 900 bool writesPredicate() const; isPredicated()901 inline bool isPredicated() const { return predSrc >= 0; } 902 903 inline void setFlagsSrc(int s, Value *); 904 inline void setFlagsDef(int d, Value *); usesFlags()905 inline bool usesFlags() const { return flagsSrc >= 0; } 906 defCount()907 unsigned int defCount() const { return defs.size(); }; 908 unsigned int defCount(unsigned int mask, bool singleFile = false) const; srcCount()909 unsigned int srcCount() const { return srcs.size(); }; 910 unsigned int srcCount(unsigned int mask, bool singleFile = false) const; 911 912 // save & remove / set indirect[0,1] and predicate source 913 void takeExtraSources(int s, Value *[3]); 914 void putExtraSources(int s, Value *[3]); 915 setType(DataType type)916 inline void setType(DataType type) { dType = sType = type; } 917 setType(DataType dtype,DataType stype)918 inline void setType(DataType dtype, DataType stype) 919 { 920 dType = dtype; 921 sType = stype; 922 } 923 isPseudo()924 inline bool isPseudo() const { return op < OP_MOV; } 925 bool isDead() const; 926 bool isNop() const; 927 bool isCommutationLegal(const Instruction *) const; // must be adjacent ! 928 bool isActionEqual(const Instruction *) const; 929 bool isResultEqual(const Instruction *) const; 930 931 // check whether the defs interfere with srcs and defs of another instruction 932 bool canCommuteDefDef(const Instruction *) const; 933 bool canCommuteDefSrc(const Instruction *) const; 934 935 void print() const; 936 937 inline CmpInstruction *asCmp(); 938 inline TexInstruction *asTex(); 939 inline FlowInstruction *asFlow(); 940 inline const TexInstruction *asTex() const; 941 inline const CmpInstruction *asCmp() const; 942 inline const FlowInstruction *asFlow() const; 943 944 public: 945 Instruction *next; 946 Instruction *prev; 947 int id; 948 int serial; // CFG order 949 950 operation op; 951 DataType dType; // destination or defining type 952 DataType sType; // source or secondary type 953 CondCode cc; 954 RoundMode rnd; 955 CacheMode cache; 956 957 uint16_t subOp; // quadop, 1 for mul-high, etc. 958 959 unsigned encSize : 5; // encoding size in bytes 960 unsigned saturate : 1; // to [0.0f, 1.0f] 961 unsigned join : 1; // converge control flow (use OP_JOIN until end) 962 unsigned fixed : 1; // prevent dead code elimination 963 unsigned terminator : 1; // end of basic block 964 unsigned ftz : 1; // flush denormal to zero 965 unsigned dnz : 1; // denormals, NaN are zero 966 unsigned ipa : 4; // interpolation mode 967 unsigned lanes : 4; 968 unsigned perPatch : 1; 969 unsigned exit : 1; // terminate program after insn 970 unsigned mask : 4; // for vector ops 971 // prevent algebraic optimisations that aren't bit-for-bit identical 972 unsigned precise : 1; 973 974 int8_t postFactor; // MUL/DIV(if < 0) by 1 << postFactor 975 976 int8_t predSrc; 977 int8_t flagsDef; 978 int8_t flagsSrc; 979 980 uint32_t sched; // scheduling data (NOTE: maybe move to separate storage) 981 982 BasicBlock *bb; 983 984 protected: 985 std::deque<ValueDef> defs; // no gaps ! 986 std::deque<ValueRef> srcs; // no gaps ! 987 988 // instruction specific methods: 989 // (don't want to subclass, would need more constructors and memory pools) 990 public: setInterpolate(unsigned int mode)991 inline void setInterpolate(unsigned int mode) { ipa = mode; } 992 getInterpMode()993 unsigned int getInterpMode() const { return ipa & 0x3; } getSampleMode()994 unsigned int getSampleMode() const { return ipa & 0xc; } 995 996 private: 997 void init(); 998 }; 999 1000 enum TexQuery 1001 { 1002 TXQ_DIMS, /* x, y, z, levels */ 1003 TXQ_TYPE, /* ?, ?, samples, ? */ 1004 TXQ_SAMPLE_POSITION, 1005 TXQ_FILTER, 1006 TXQ_LOD, 1007 TXQ_WRAP, 1008 TXQ_BORDER_COLOUR 1009 }; 1010 1011 class TexInstruction : public Instruction 1012 { 1013 public: 1014 class Target 1015 { 1016 public: target(targ)1017 Target(TexTarget targ = TEX_TARGET_1D) : target(targ) { } 1018 getName()1019 const char *getName() const { return descTable[target].name; } getArgCount()1020 unsigned int getArgCount() const { return descTable[target].argc; } getDim()1021 unsigned int getDim() const { return descTable[target].dim; } isArray()1022 int isArray() const { return descTable[target].array ? 1 : 0; } isCube()1023 int isCube() const { return descTable[target].cube ? 1 : 0; } isShadow()1024 int isShadow() const { return descTable[target].shadow ? 1 : 0; } isMS()1025 int isMS() const { 1026 return target == TEX_TARGET_2D_MS || target == TEX_TARGET_2D_MS_ARRAY; } clearMS()1027 void clearMS() { 1028 if (isMS()) { 1029 if (isArray()) 1030 target = TEX_TARGET_2D_ARRAY; 1031 else 1032 target = TEX_TARGET_2D; 1033 } 1034 } 1035 1036 Target& operator=(TexTarget targ) 1037 { 1038 assert(targ < TEX_TARGET_COUNT); 1039 target = targ; 1040 return *this; 1041 } 1042 1043 inline bool operator==(TexTarget targ) const { return target == targ; } 1044 inline bool operator!=(TexTarget targ) const { return target != targ; } 1045 getEnum()1046 enum TexTarget getEnum() const { return target; } 1047 1048 private: 1049 struct Desc 1050 { 1051 char name[19]; 1052 uint8_t dim; 1053 uint8_t argc; 1054 bool array; 1055 bool cube; 1056 bool shadow; 1057 }; 1058 1059 static const struct Desc descTable[TEX_TARGET_COUNT]; 1060 1061 private: 1062 enum TexTarget target; 1063 }; 1064 1065 public: 1066 struct ImgFormatDesc 1067 { 1068 char name[19]; 1069 uint8_t components; 1070 uint8_t bits[4]; 1071 ImgType type; 1072 bool bgra; 1073 }; 1074 1075 static const struct ImgFormatDesc formatTable[IMG_FORMAT_COUNT]; 1076 static const struct ImgFormatDesc *translateImgFormat( 1077 enum pipe_format format); 1078 1079 public: 1080 TexInstruction(Function *, operation); 1081 virtual ~TexInstruction(); 1082 1083 virtual TexInstruction *clone(ClonePolicy<Function>&, 1084 Instruction * = NULL) const; 1085 setTexture(Target targ,uint8_t r,uint8_t s)1086 inline void setTexture(Target targ, uint8_t r, uint8_t s) 1087 { 1088 tex.r = r; 1089 tex.s = s; 1090 tex.target = targ; 1091 } 1092 1093 void setIndirectR(Value *); 1094 void setIndirectS(Value *); 1095 inline Value *getIndirectR() const; 1096 inline Value *getIndirectS() const; 1097 1098 public: 1099 struct { 1100 Target target; 1101 1102 uint16_t r; 1103 uint16_t s; 1104 int8_t rIndirectSrc; 1105 int8_t sIndirectSrc; 1106 1107 uint8_t mask; 1108 uint8_t gatherComp; 1109 1110 bool liveOnly; // only execute on live pixels of a quad (optimization) 1111 bool levelZero; 1112 bool derivAll; 1113 bool bindless; 1114 1115 int8_t useOffsets; // 0, 1, or 4 for textureGatherOffsets 1116 int8_t offset[3]; // only used on nv50 1117 1118 enum TexQuery query; 1119 const struct ImgFormatDesc *format; 1120 1121 bool scalar; // for GM107s TEXS, TLDS, TLD4S 1122 } tex; 1123 1124 ValueRef dPdx[3]; 1125 ValueRef dPdy[3]; 1126 ValueRef offset[4][3]; 1127 }; 1128 1129 class CmpInstruction : public Instruction 1130 { 1131 public: 1132 CmpInstruction(Function *, operation); 1133 1134 virtual CmpInstruction *clone(ClonePolicy<Function>&, 1135 Instruction * = NULL) const; 1136 setCondition(CondCode cond)1137 void setCondition(CondCode cond) { setCond = cond; } getCondition()1138 CondCode getCondition() const { return setCond; } 1139 1140 public: 1141 CondCode setCond; 1142 }; 1143 1144 class FlowInstruction : public Instruction 1145 { 1146 public: 1147 FlowInstruction(Function *, operation, void *target); 1148 1149 virtual FlowInstruction *clone(ClonePolicy<Function>&, 1150 Instruction * = NULL) const; 1151 1152 public: 1153 unsigned allWarp : 1; 1154 unsigned absolute : 1; 1155 unsigned limit : 1; 1156 unsigned builtin : 1; // true for calls to emulation code 1157 unsigned indirect : 1; // target in src(0) 1158 1159 union { 1160 BasicBlock *bb; 1161 int builtin; 1162 Function *fn; 1163 } target; 1164 }; 1165 1166 class BasicBlock 1167 { 1168 public: 1169 BasicBlock(Function *); 1170 ~BasicBlock(); 1171 1172 BasicBlock(const BasicBlock&) = delete; 1173 BasicBlock& operator=(const BasicBlock&) = delete; 1174 1175 BasicBlock *clone(ClonePolicy<Function>&) const; 1176 getId()1177 inline int getId() const { return id; } getInsnCount()1178 inline unsigned int getInsnCount() const { return numInsns; } isTerminated()1179 inline bool isTerminated() const { return exit && exit->terminator; } 1180 1181 bool dominatedBy(BasicBlock *bb); 1182 inline bool reachableBy(const BasicBlock *by, const BasicBlock *term); 1183 1184 // returns mask of conditional out blocks 1185 // e.g. 3 for IF { .. } ELSE { .. } ENDIF, 1 for IF { .. } ENDIF 1186 unsigned int initiatesSimpleConditional() const; 1187 1188 public: getFunction()1189 Function *getFunction() const { return func; } getProgram()1190 Program *getProgram() const { return program; } 1191 getEntry()1192 Instruction *getEntry() const { return entry; } // first non-phi instruction getPhi()1193 Instruction *getPhi() const { return phi; } getFirst()1194 Instruction *getFirst() const { return phi ? phi : entry; } getExit()1195 Instruction *getExit() const { return exit; } 1196 1197 void insertHead(Instruction *); 1198 void insertTail(Instruction *); 1199 void insertBefore(Instruction *, Instruction *); 1200 void insertAfter(Instruction *, Instruction *); 1201 void remove(Instruction *); 1202 void permuteAdjacent(Instruction *, Instruction *); 1203 1204 BasicBlock *idom() const; 1205 1206 // NOTE: currently does not rebuild the dominator tree 1207 BasicBlock *splitBefore(Instruction *, bool attach = true); 1208 BasicBlock *splitAfter(Instruction *, bool attach = true); 1209 getDF()1210 DLList& getDF() { return df; } iterDF()1211 DLList::Iterator iterDF() { return df.iterator(); } 1212 1213 static inline BasicBlock *get(Iterator&); 1214 static inline BasicBlock *get(Graph::Node *); 1215 1216 public: 1217 Graph::Node cfg; // first edge is branch *taken* (the ELSE branch) 1218 Graph::Node dom; 1219 1220 BitSet liveSet; 1221 BitSet defSet; 1222 1223 uint32_t binPos; 1224 uint32_t binSize; 1225 1226 Instruction *joinAt; // for quick reference 1227 1228 bool explicitCont; // loop headers: true if loop contains continue stmts 1229 1230 private: 1231 int id; 1232 DLList df; 1233 1234 Instruction *phi; 1235 Instruction *entry; 1236 Instruction *exit; 1237 1238 unsigned int numInsns; 1239 1240 private: 1241 Function *func; 1242 Program *program; 1243 1244 void splitCommon(Instruction *, BasicBlock *, bool attach); 1245 }; 1246 1247 class Function 1248 { 1249 public: 1250 Function(Program *, const char *name, uint32_t label); 1251 ~Function(); 1252 1253 Function(const Function&) = delete; 1254 Function& operator=(const Function&) = delete; 1255 1256 static inline Function *get(Graph::Node *node); 1257 getProgram()1258 inline Program *getProgram() const { return prog; } getName()1259 inline const char *getName() const { return name; } getId()1260 inline int getId() const { return id; } getLabel()1261 inline uint32_t getLabel() const { return label; } 1262 1263 void print(); 1264 void printLiveIntervals() const; 1265 void printCFGraph(const char *filePath); 1266 1267 bool setEntry(BasicBlock *); 1268 bool setExit(BasicBlock *); 1269 1270 unsigned int orderInstructions(ArrayList&); 1271 add(BasicBlock * bb,int & id)1272 inline void add(BasicBlock *bb, int& id) { allBBlocks.insert(bb, id); } add(Instruction * insn,int & id)1273 inline void add(Instruction *insn, int& id) { allInsns.insert(insn, id); } add(LValue * lval,int & id)1274 inline void add(LValue *lval, int& id) { allLValues.insert(lval, id); } 1275 1276 inline LValue *getLValue(int id); 1277 1278 void buildLiveSets(); 1279 bool convertToSSA(); 1280 1281 public: 1282 std::deque<ValueDef> ins; 1283 std::deque<ValueRef> outs; 1284 std::deque<Value *> clobbers; 1285 1286 Graph cfg; 1287 Graph::Node *cfgExit; 1288 Graph *domTree; 1289 Graph::Node call; // node in the call graph 1290 1291 BasicBlock **bbArray; // BBs in emission order 1292 int bbCount; 1293 1294 unsigned int loopNestingBound; 1295 int regClobberMax; 1296 1297 uint32_t binPos; 1298 uint32_t binSize; 1299 1300 uint32_t tlsBase; // base address for l[] space (if no stack pointer is used) 1301 uint32_t tlsSize; 1302 1303 ArrayList allBBlocks; 1304 ArrayList allInsns; 1305 ArrayList allLValues; 1306 1307 private: 1308 void buildLiveSetsPreSSA(BasicBlock *, const int sequence); 1309 void buildDefSetsPreSSA(BasicBlock *bb, const int seq); 1310 1311 private: 1312 uint32_t label; 1313 int id; 1314 const char *const name; 1315 Program *prog; 1316 }; 1317 1318 enum CGStage 1319 { 1320 CG_STAGE_PRE_SSA, 1321 CG_STAGE_SSA, // expected directly before register allocation 1322 CG_STAGE_POST_RA 1323 }; 1324 1325 class Program 1326 { 1327 public: 1328 enum Type 1329 { 1330 TYPE_VERTEX, 1331 TYPE_TESSELLATION_CONTROL, 1332 TYPE_TESSELLATION_EVAL, 1333 TYPE_GEOMETRY, 1334 TYPE_FRAGMENT, 1335 TYPE_COMPUTE 1336 }; 1337 1338 Program(Type type, Target *targ); 1339 ~Program(); 1340 1341 Program(const Program&) = delete; 1342 Program& operator=(const Program&) = delete; 1343 1344 void print(); 1345 getType()1346 Type getType() const { return progType; } 1347 add(Function * fn,int & id)1348 inline void add(Function *fn, int& id) { allFuncs.insert(fn, id); } del(Function * fn,int & id)1349 inline void del(Function *fn, int& id) { allFuncs.remove(id); } add(Value * rval,int & id)1350 inline void add(Value *rval, int& id) { allRValues.insert(rval, id); } 1351 1352 bool makeFromNIR(struct nv50_ir_prog_info *, 1353 struct nv50_ir_prog_info_out *); 1354 bool convertToSSA(); 1355 bool optimizeSSA(int level); 1356 bool optimizePostRA(int level); 1357 bool registerAllocation(); 1358 bool emitBinary(struct nv50_ir_prog_info_out *); 1359 getTarget()1360 const Target *getTarget() const { return target; } 1361 1362 private: 1363 Type progType; 1364 Target *target; 1365 1366 public: 1367 Function *main; 1368 Graph calls; 1369 1370 ArrayList allFuncs; 1371 ArrayList allRValues; 1372 1373 uint32_t *code; 1374 uint32_t binSize; 1375 uint32_t tlsSize; // size required for FILE_MEMORY_LOCAL 1376 1377 int maxGPR; 1378 bool fp64; 1379 bool persampleInvocation; 1380 1381 MemoryPool mem_Instruction; 1382 MemoryPool mem_CmpInstruction; 1383 MemoryPool mem_TexInstruction; 1384 MemoryPool mem_FlowInstruction; 1385 MemoryPool mem_LValue; 1386 MemoryPool mem_Symbol; 1387 MemoryPool mem_ImmediateValue; 1388 1389 uint32_t dbgFlags; 1390 uint8_t optLevel; 1391 1392 void *targetPriv; // e.g. to carry information between passes 1393 1394 const struct nv50_ir_prog_info *driver; // for driver configuration 1395 const struct nv50_ir_prog_info_out *driver_out; // for driver configuration 1396 1397 void releaseInstruction(Instruction *); 1398 void releaseValue(Value *); 1399 }; 1400 1401 // TODO: add const version 1402 class Pass 1403 { 1404 public: 1405 bool run(Program *, bool ordered = false, bool skipPhi = false); 1406 bool run(Function *, bool ordered = false, bool skipPhi = false); 1407 1408 private: 1409 bool doRun(Program *, bool ordered, bool skipPhi); 1410 bool doRun(Function *, bool ordered, bool skipPhi); 1411 1412 protected: 1413 // return false to continue with next entity on next higher level visit(Function *)1414 virtual bool visit(Function *) { return true; } visit(BasicBlock *)1415 virtual bool visit(BasicBlock *) { return true; } visit(Instruction *)1416 virtual bool visit(Instruction *) { return false; } 1417 1418 bool err; 1419 Function *func; 1420 Program *prog; 1421 }; 1422 1423 // ============================================================================= 1424 1425 #include "nv50_ir_inlines.h" 1426 1427 } // namespace nv50_ir 1428 1429 #endif // __NV50_IR_H__ 1430