Alyssa Rosenzweig | 5f7a3ba | 2020-03-03 15:39:04 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com> |
| 3 | * Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com> |
| 4 | * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com> |
| 5 | * Copyright (C) 2019-2020 Collabora, Ltd. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include "bi_print.h" |
| 28 | |
| 29 | const char * |
Alyssa Rosenzweig | d797822 | 2020-03-18 13:23:00 -0400 | [diff] [blame] | 30 | bi_clause_type_name(enum bifrost_clause_type T) |
| 31 | { |
| 32 | switch (T) { |
| 33 | case BIFROST_CLAUSE_NONE: return ""; |
| 34 | case BIFROST_CLAUSE_LOAD_VARY: return "load_vary"; |
| 35 | case BIFROST_CLAUSE_UBO: return "ubo"; |
| 36 | case BIFROST_CLAUSE_TEX: return "tex"; |
| 37 | case BIFROST_CLAUSE_SSBO_LOAD: return "load"; |
| 38 | case BIFROST_CLAUSE_SSBO_STORE: return "store"; |
| 39 | case BIFROST_CLAUSE_BLEND: return "blend"; |
| 40 | case BIFROST_CLAUSE_ATEST: return "atest"; |
| 41 | case BIFROST_CLAUSE_64BIT: return "64"; |
| 42 | default: return "??"; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | const char * |
Alyssa Rosenzweig | 5f7a3ba | 2020-03-03 15:39:04 -0500 | [diff] [blame] | 47 | bi_output_mod_name(enum bifrost_outmod mod) |
| 48 | { |
| 49 | switch (mod) { |
| 50 | case BIFROST_NONE: return ""; |
| 51 | case BIFROST_POS: return ".pos"; |
| 52 | case BIFROST_SAT_SIGNED: return ".sat_signed"; |
| 53 | case BIFROST_SAT: return ".sat"; |
| 54 | default: return "invalid"; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | const char * |
| 59 | bi_minmax_mode_name(enum bifrost_minmax_mode mod) |
| 60 | { |
| 61 | switch (mod) { |
| 62 | case BIFROST_MINMAX_NONE: return ""; |
| 63 | case BIFROST_NAN_WINS: return ".nan_wins"; |
| 64 | case BIFROST_SRC1_WINS: return ".src1_wins"; |
| 65 | case BIFROST_SRC0_WINS: return ".src0_wins"; |
| 66 | default: return "invalid"; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const char * |
| 71 | bi_round_mode_name(enum bifrost_roundmode mod) |
| 72 | { |
| 73 | switch (mod) { |
| 74 | case BIFROST_RTE: return ""; |
| 75 | case BIFROST_RTP: return ".rtp"; |
| 76 | case BIFROST_RTN: return ".rtn"; |
| 77 | case BIFROST_RTZ: return ".rtz"; |
| 78 | default: return "invalid"; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | const char * |
| 83 | bi_csel_cond_name(enum bifrost_csel_cond cond) |
| 84 | { |
| 85 | switch (cond) { |
| 86 | case BIFROST_FEQ_F: return "feq.f"; |
| 87 | case BIFROST_FGT_F: return "fgt.f"; |
| 88 | case BIFROST_FGE_F: return "fge.f"; |
| 89 | case BIFROST_IEQ_F: return "ieq.f"; |
| 90 | case BIFROST_IGT_I: return "igt.i"; |
| 91 | case BIFROST_IGE_I: return "uge.i"; |
| 92 | case BIFROST_UGT_I: return "ugt.i"; |
| 93 | case BIFROST_UGE_I: return "uge.i"; |
| 94 | default: return "invalid"; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | const char * |
Alyssa Rosenzweig | aef0f00 | 2020-03-04 09:21:25 -0500 | [diff] [blame] | 99 | bi_interp_mode_name(enum bifrost_interp_mode mode) |
| 100 | { |
| 101 | switch (mode) { |
| 102 | case BIFROST_INTERP_PER_FRAG: return ".per_frag"; |
| 103 | case BIFROST_INTERP_CENTROID: return ".centroid"; |
| 104 | case BIFROST_INTERP_DEFAULT: return ""; |
| 105 | case BIFROST_INTERP_EXPLICIT: return ".explicit"; |
| 106 | default: return ".unknown"; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | const char * |
Alyssa Rosenzweig | 5f7a3ba | 2020-03-03 15:39:04 -0500 | [diff] [blame] | 111 | bi_ldst_type_name(enum bifrost_ldst_type type) |
| 112 | { |
| 113 | switch (type) { |
| 114 | case BIFROST_LDST_F16: return "f16"; |
| 115 | case BIFROST_LDST_F32: return "f32"; |
| 116 | case BIFROST_LDST_I32: return "i32"; |
| 117 | case BIFROST_LDST_U32: return "u32"; |
| 118 | default: return "invalid"; |
| 119 | } |
| 120 | } |
| 121 | |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 122 | /* The remaining functions in this file are for IR-internal |
| 123 | * structures; the disassembler doesn't use them */ |
Alyssa Rosenzweig | 5f7a3ba | 2020-03-03 15:39:04 -0500 | [diff] [blame] | 124 | |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 125 | static const char * |
| 126 | bi_class_name(enum bi_class cl) |
| 127 | { |
| 128 | switch (cl) { |
| 129 | case BI_ADD: return "add"; |
| 130 | case BI_ATEST: return "atest"; |
| 131 | case BI_BRANCH: return "branch"; |
| 132 | case BI_CMP: return "cmp"; |
| 133 | case BI_BLEND: return "blend"; |
| 134 | case BI_BITWISE: return "bitwise"; |
| 135 | case BI_CONVERT: return "convert"; |
| 136 | case BI_CSEL: return "csel"; |
| 137 | case BI_DISCARD: return "discard"; |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 138 | case BI_FMA: return "fma"; |
| 139 | case BI_FREXP: return "frexp"; |
Alyssa Rosenzweig | 55f0d81 | 2020-03-10 08:03:20 -0400 | [diff] [blame] | 140 | case BI_ISUB: return "isub"; |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 141 | case BI_LOAD: return "load"; |
Alyssa Rosenzweig | 1ead0d3 | 2020-03-06 09:52:09 -0500 | [diff] [blame] | 142 | case BI_LOAD_UNIFORM: return "load_uniform"; |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 143 | case BI_LOAD_ATTR: return "load_attr"; |
| 144 | case BI_LOAD_VAR: return "load_var"; |
| 145 | case BI_LOAD_VAR_ADDRESS: return "load_var_address"; |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 146 | case BI_MINMAX: return "minmax"; |
| 147 | case BI_MOV: return "mov"; |
| 148 | case BI_SHIFT: return "shift"; |
| 149 | case BI_STORE: return "store"; |
| 150 | case BI_STORE_VAR: return "store_var"; |
| 151 | case BI_SPECIAL: return "special"; |
| 152 | case BI_SWIZZLE: return "swizzle"; |
| 153 | case BI_TEX: return "tex"; |
| 154 | case BI_ROUND: return "round"; |
| 155 | default: return "unknown_class"; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static void |
Alyssa Rosenzweig | 806533b | 2020-03-05 17:49:45 -0500 | [diff] [blame] | 160 | bi_print_index(FILE *fp, bi_instruction *ins, unsigned index) |
| 161 | { |
| 162 | if (!index) |
| 163 | fprintf(fp, "_"); |
| 164 | else if (index & BIR_INDEX_REGISTER) |
| 165 | fprintf(fp, "br%u", index & ~BIR_INDEX_REGISTER); |
| 166 | else if (index & BIR_INDEX_UNIFORM) |
| 167 | fprintf(fp, "u%u", index & ~BIR_INDEX_UNIFORM); |
| 168 | else if (index & BIR_INDEX_CONSTANT) |
Alyssa Rosenzweig | 11bccb0 | 2020-03-21 18:42:58 -0400 | [diff] [blame] | 169 | fprintf(fp, "#0x%" PRIx64, bi_get_immediate(ins, index)); |
Alyssa Rosenzweig | 806533b | 2020-03-05 17:49:45 -0500 | [diff] [blame] | 170 | else if (index & BIR_INDEX_ZERO) |
| 171 | fprintf(fp, "#0"); |
| 172 | else if (index & BIR_IS_REG) |
| 173 | fprintf(fp, "r%u", index >> 1); |
| 174 | else |
| 175 | fprintf(fp, "%u", (index >> 1) - 1); |
| 176 | } |
| 177 | |
| 178 | static void |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 179 | bi_print_src(FILE *fp, bi_instruction *ins, unsigned s) |
| 180 | { |
| 181 | unsigned src = ins->src[s]; |
| 182 | bool mods = bi_has_source_mods(ins); |
| 183 | bool abs = ins->src_abs[s] && mods; |
| 184 | bool neg = ins->src_neg[s] && mods; |
| 185 | |
| 186 | if (neg) |
| 187 | fprintf(fp, "-"); |
| 188 | |
| 189 | if (abs) |
| 190 | fprintf(fp, "abs("); |
| 191 | |
Alyssa Rosenzweig | 806533b | 2020-03-05 17:49:45 -0500 | [diff] [blame] | 192 | bi_print_index(fp, ins, src); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 193 | |
| 194 | if (abs) |
| 195 | fprintf(fp, ")"); |
| 196 | } |
| 197 | |
| 198 | /* Prints a NIR ALU type in Bifrost-style ".f32" ".i8" etc */ |
| 199 | |
| 200 | static void |
| 201 | bi_print_alu_type(nir_alu_type t, FILE *fp) |
| 202 | { |
| 203 | unsigned size = nir_alu_type_get_type_size(t); |
| 204 | nir_alu_type base = nir_alu_type_get_base_type(t); |
| 205 | |
| 206 | switch (base) { |
| 207 | case nir_type_int: |
| 208 | fprintf(fp, ".i"); |
| 209 | break; |
| 210 | case nir_type_uint: |
| 211 | fprintf(fp, ".u"); |
| 212 | break; |
| 213 | case nir_type_bool: |
| 214 | fprintf(fp, ".b"); |
| 215 | break; |
| 216 | case nir_type_float: |
| 217 | fprintf(fp, ".f"); |
| 218 | break; |
| 219 | default: |
| 220 | fprintf(fp, ".unknown"); |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | fprintf(fp, "%u", size); |
| 225 | } |
| 226 | |
| 227 | static void |
Alyssa Rosenzweig | 795646d | 2020-03-09 14:09:04 -0400 | [diff] [blame] | 228 | bi_print_swizzle(bi_instruction *ins, unsigned src, FILE *fp) |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 229 | { |
Alyssa Rosenzweig | cd7fec7 | 2020-03-21 17:41:34 -0400 | [diff] [blame] | 230 | unsigned size = nir_alu_type_get_type_size(ins->dest_type); |
Alyssa Rosenzweig | 795646d | 2020-03-09 14:09:04 -0400 | [diff] [blame] | 231 | unsigned count = (size == 64) ? 1 : (32 / size); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 232 | |
| 233 | fprintf(fp, "."); |
| 234 | |
| 235 | for (unsigned u = 0; u < count; ++u) { |
Alyssa Rosenzweig | 795646d | 2020-03-09 14:09:04 -0400 | [diff] [blame] | 236 | assert(ins->swizzle[src][u] < 4); |
| 237 | fputc("xyzw"[ins->swizzle[src][u]], fp); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | static const char * |
| 242 | bi_bitwise_op_name(enum bi_bitwise_op op) |
| 243 | { |
| 244 | switch (op) { |
| 245 | case BI_BITWISE_AND: return "and"; |
| 246 | case BI_BITWISE_OR: return "or"; |
| 247 | case BI_BITWISE_XOR: return "xor"; |
| 248 | default: return "invalid"; |
| 249 | } |
| 250 | } |
| 251 | |
Alyssa Rosenzweig | b674e39 | 2020-03-09 21:20:03 -0400 | [diff] [blame] | 252 | static const char * |
| 253 | bi_special_op_name(enum bi_special_op op) |
| 254 | { |
| 255 | switch (op) { |
| 256 | case BI_SPECIAL_FRCP: return "frcp"; |
| 257 | case BI_SPECIAL_FRSQ: return "frsq"; |
| 258 | case BI_SPECIAL_FATAN: return "fatan"; |
| 259 | case BI_SPECIAL_FSIN: return "fsin"; |
| 260 | case BI_SPECIAL_FCOS: return "fcos"; |
| 261 | case BI_SPECIAL_FEXP: return "fexp"; |
| 262 | case BI_SPECIAL_FLOG2: return "flog2"; |
| 263 | case BI_SPECIAL_FLOGE: return "flog"; |
| 264 | default: return "invalid"; |
| 265 | } |
| 266 | } |
| 267 | |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 268 | static void |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 269 | bi_print_load_vary(struct bi_load_vary *load, FILE *fp) |
| 270 | { |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 271 | fprintf(fp, "%s", bi_interp_mode_name(load->interp_mode)); |
| 272 | |
| 273 | if (load->reuse) |
| 274 | fprintf(fp, ".reuse"); |
| 275 | |
| 276 | if (load->flat) |
| 277 | fprintf(fp, ".flat"); |
| 278 | } |
| 279 | |
| 280 | static const char * |
| 281 | bi_cond_name(enum bi_cond cond) |
| 282 | { |
| 283 | switch (cond) { |
Alyssa Rosenzweig | 20c7d57 | 2020-03-10 08:47:20 -0400 | [diff] [blame] | 284 | case BI_COND_ALWAYS: return "always"; |
| 285 | case BI_COND_LT: return "lt"; |
| 286 | case BI_COND_LE: return "le"; |
| 287 | case BI_COND_GE: return "ge"; |
| 288 | case BI_COND_GT: return "gt"; |
| 289 | case BI_COND_EQ: return "eq"; |
| 290 | case BI_COND_NE: return "ne"; |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 291 | default: return "invalid"; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | static void |
| 296 | bi_print_branch(struct bi_branch *branch, FILE *fp) |
| 297 | { |
Alyssa Rosenzweig | 20c7d57 | 2020-03-10 08:47:20 -0400 | [diff] [blame] | 298 | fprintf(fp, ".%s", bi_cond_name(branch->cond)); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Alyssa Rosenzweig | e9d480c | 2020-03-09 14:25:00 -0400 | [diff] [blame] | 301 | static void |
| 302 | bi_print_writemask(bi_instruction *ins, FILE *fp) |
| 303 | { |
Alyssa Rosenzweig | 69c66ff | 2020-03-09 19:52:56 -0400 | [diff] [blame] | 304 | unsigned bits_per_comp = nir_alu_type_get_type_size(ins->dest_type); |
| 305 | assert(bits_per_comp); |
Alyssa Rosenzweig | cd7fec7 | 2020-03-21 17:41:34 -0400 | [diff] [blame] | 306 | unsigned bytes_per_comp = bits_per_comp / 8; |
Alyssa Rosenzweig | e9d480c | 2020-03-09 14:25:00 -0400 | [diff] [blame] | 307 | unsigned comps = 16 / bytes_per_comp; |
| 308 | unsigned smask = (1 << bytes_per_comp) - 1; |
| 309 | fprintf(fp, "."); |
| 310 | |
| 311 | for (unsigned i = 0; i < comps; ++i) { |
| 312 | unsigned masked = (ins->writemask >> (i * bytes_per_comp)) & smask; |
| 313 | if (!masked) |
| 314 | continue; |
| 315 | |
| 316 | assert(masked == smask); |
| 317 | assert(i < 4); |
| 318 | fputc("xyzw"[i], fp); |
| 319 | } |
| 320 | } |
| 321 | |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 322 | void |
| 323 | bi_print_instruction(bi_instruction *ins, FILE *fp) |
| 324 | { |
| 325 | if (ins->type == BI_MINMAX) |
| 326 | fprintf(fp, "%s", ins->op.minmax == BI_MINMAX_MIN ? "min" : "max"); |
| 327 | else if (ins->type == BI_BITWISE) |
| 328 | fprintf(fp, "%s", bi_bitwise_op_name(ins->op.bitwise)); |
| 329 | else if (ins->type == BI_ROUND) |
| 330 | fprintf(fp, ins->op.round == BI_ROUND_MODE ? "roundMode": "round"); |
Alyssa Rosenzweig | b674e39 | 2020-03-09 21:20:03 -0400 | [diff] [blame] | 331 | else if (ins->type == BI_SPECIAL) |
| 332 | fprintf(fp, "%s", bi_special_op_name(ins->op.special)); |
Alyssa Rosenzweig | 20c7d57 | 2020-03-10 08:47:20 -0400 | [diff] [blame] | 333 | else if (ins->type == BI_CMP) |
| 334 | fprintf(fp, "%s", bi_cond_name(ins->op.compare)); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 335 | else |
| 336 | fprintf(fp, "%s", bi_class_name(ins->type)); |
| 337 | |
| 338 | if (ins->type == BI_MINMAX) |
| 339 | fprintf(fp, "%s", bi_minmax_mode_name(ins->minmax)); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 340 | else if (ins->type == BI_LOAD_VAR) |
| 341 | bi_print_load_vary(&ins->load_vary, fp); |
| 342 | else if (ins->type == BI_BRANCH) |
| 343 | bi_print_branch(&ins->branch, fp); |
| 344 | else if (ins->type == BI_CSEL) |
Alyssa Rosenzweig | 20c7d57 | 2020-03-10 08:47:20 -0400 | [diff] [blame] | 345 | fprintf(fp, ".%s", bi_cond_name(ins->csel_cond)); |
Alyssa Rosenzweig | 92a4f26 | 2020-03-06 09:25:58 -0500 | [diff] [blame] | 346 | else if (ins->type == BI_BLEND) |
| 347 | fprintf(fp, ".loc%u", ins->blend_location); |
Alyssa Rosenzweig | 9213b25 | 2020-03-20 12:38:53 -0400 | [diff] [blame] | 348 | else if (ins->type == BI_STORE || ins->type == BI_STORE_VAR) |
| 349 | fprintf(fp, ".v%u", ins->store_channels); |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 350 | |
| 351 | if (ins->dest) |
| 352 | bi_print_alu_type(ins->dest_type, fp); |
| 353 | |
| 354 | if (bi_has_outmod(ins)) |
| 355 | fprintf(fp, "%s", bi_output_mod_name(ins->outmod)); |
| 356 | |
| 357 | if (bi_class_props[ins->type] & BI_ROUNDMODE) |
| 358 | fprintf(fp, "%s", bi_round_mode_name(ins->roundmode)); |
| 359 | |
| 360 | fprintf(fp, " "); |
Alyssa Rosenzweig | 806533b | 2020-03-05 17:49:45 -0500 | [diff] [blame] | 361 | bi_print_index(fp, ins, ins->dest); |
Alyssa Rosenzweig | e9d480c | 2020-03-09 14:25:00 -0400 | [diff] [blame] | 362 | |
| 363 | if (ins->dest) |
| 364 | bi_print_writemask(ins, fp); |
| 365 | |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 366 | fprintf(fp, ", "); |
| 367 | |
| 368 | bi_foreach_src(ins, s) { |
| 369 | bi_print_src(fp, ins, s); |
| 370 | |
Alyssa Rosenzweig | 6409896 | 2020-03-10 08:47:39 -0400 | [diff] [blame] | 371 | if (ins->src[s] && !(ins->src[s] & (BIR_INDEX_CONSTANT | BIR_INDEX_ZERO))) { |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 372 | bi_print_alu_type(ins->src_types[s], fp); |
Alyssa Rosenzweig | 6409896 | 2020-03-10 08:47:39 -0400 | [diff] [blame] | 373 | bi_print_swizzle(ins, s, fp); |
| 374 | } |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 375 | |
| 376 | if (s < BIR_SRC_COUNT) |
| 377 | fprintf(fp, ", "); |
| 378 | } |
| 379 | |
Alyssa Rosenzweig | 7fd22c3 | 2020-03-05 16:33:09 -0500 | [diff] [blame] | 380 | if (ins->type == BI_BRANCH) { |
| 381 | if (ins->branch.target) |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 382 | fprintf(fp, "-> block%u", ins->branch.target->base.name); |
Alyssa Rosenzweig | 7fd22c3 | 2020-03-05 16:33:09 -0500 | [diff] [blame] | 383 | else |
| 384 | fprintf(fp, "-> blockhole"); |
| 385 | } |
| 386 | |
Alyssa Rosenzweig | bde54cb | 2020-03-04 09:21:50 -0500 | [diff] [blame] | 387 | fprintf(fp, "\n"); |
| 388 | } |
Alyssa Rosenzweig | 919cdf1 | 2020-03-05 07:57:49 -0500 | [diff] [blame] | 389 | |
| 390 | void |
| 391 | bi_print_bundle(bi_bundle *bundle, FILE *fp) |
| 392 | { |
| 393 | bi_instruction *ins[2] = { bundle->fma, bundle->add }; |
| 394 | |
| 395 | for (unsigned i = 0; i < 2; ++i) { |
| 396 | if (ins[i]) |
| 397 | bi_print_instruction(ins[i], fp); |
| 398 | else |
| 399 | fprintf(fp, "nop\n"); |
| 400 | } |
| 401 | } |
| 402 | |
Alyssa Rosenzweig | c316d15 | 2020-03-05 08:10:02 -0500 | [diff] [blame] | 403 | void |
| 404 | bi_print_clause(bi_clause *clause, FILE *fp) |
| 405 | { |
| 406 | fprintf(fp, "\tid(%u)", clause->scoreboard_id); |
| 407 | |
| 408 | if (clause->dependencies) { |
Alyssa Rosenzweig | 0b0be49 | 2020-03-06 19:27:25 -0500 | [diff] [blame] | 409 | fprintf(fp, ", wait("); |
Alyssa Rosenzweig | c316d15 | 2020-03-05 08:10:02 -0500 | [diff] [blame] | 410 | |
| 411 | for (unsigned i = 0; i < 8; ++i) { |
| 412 | if (clause->dependencies & (1 << i)) |
| 413 | fprintf(fp, "%u ", i); |
| 414 | } |
| 415 | |
| 416 | fprintf(fp, ")"); |
| 417 | } |
| 418 | |
| 419 | if (!clause->back_to_back) |
| 420 | fprintf(fp, " nbb %s", clause->branch_conditional ? "branch-cond" : "branch-uncond"); |
| 421 | |
| 422 | if (clause->data_register_write_barrier) |
| 423 | fprintf(fp, " drwb"); |
| 424 | |
| 425 | fprintf(fp, "\n"); |
| 426 | |
| 427 | if (clause->instruction_count) { |
| 428 | assert(!clause->bundle_count); |
| 429 | |
| 430 | for (unsigned i = 0; i < clause->instruction_count; ++i) |
| 431 | bi_print_instruction(clause->instructions[i], fp); |
| 432 | } else { |
| 433 | assert(clause->bundle_count); |
| 434 | |
| 435 | for (unsigned i = 0; i < clause->bundle_count; ++i) |
| 436 | bi_print_bundle(&clause->bundles[i], fp); |
| 437 | } |
| 438 | |
| 439 | if (clause->constant_count) { |
| 440 | for (unsigned i = 0; i < clause->constant_count; ++i) |
| 441 | fprintf(fp, "%" PRIx64 " ", clause->constants[i]); |
| 442 | |
| 443 | fprintf(fp, "\n"); |
| 444 | } |
| 445 | } |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 446 | |
| 447 | void |
| 448 | bi_print_block(bi_block *block, FILE *fp) |
| 449 | { |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 450 | fprintf(fp, "block%u {\n", block->base.name); |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 451 | |
| 452 | if (block->scheduled) { |
| 453 | bi_foreach_clause_in_block(block, clause) |
| 454 | bi_print_clause(clause, fp); |
| 455 | } else { |
| 456 | bi_foreach_instr_in_block(block, ins) |
| 457 | bi_print_instruction(ins, fp); |
| 458 | } |
| 459 | |
Alyssa Rosenzweig | 5c7ee8a | 2020-03-05 10:28:13 -0500 | [diff] [blame] | 460 | fprintf(fp, "}"); |
| 461 | |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 462 | if (block->base.successors[0]) { |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 463 | fprintf(fp, " -> "); |
| 464 | |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 465 | pan_foreach_successor((&block->base), succ) |
| 466 | fprintf(fp, "block%u ", succ->name); |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 467 | } |
| 468 | |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 469 | if (block->base.predecessors->entries) { |
Alyssa Rosenzweig | 5c7ee8a | 2020-03-05 10:28:13 -0500 | [diff] [blame] | 470 | fprintf(fp, " from"); |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 471 | |
Alyssa Rosenzweig | 5c7ee8a | 2020-03-05 10:28:13 -0500 | [diff] [blame] | 472 | bi_foreach_predecessor(block, pred) |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 473 | fprintf(fp, " block%u", pred->base.name); |
Alyssa Rosenzweig | 5c7ee8a | 2020-03-05 10:28:13 -0500 | [diff] [blame] | 474 | } |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 475 | |
Alyssa Rosenzweig | 5c7ee8a | 2020-03-05 10:28:13 -0500 | [diff] [blame] | 476 | fprintf(fp, "\n\n"); |
Alyssa Rosenzweig | c152d4c | 2020-03-05 08:22:07 -0500 | [diff] [blame] | 477 | } |
Alyssa Rosenzweig | bc5724f | 2020-03-05 08:23:43 -0500 | [diff] [blame] | 478 | |
| 479 | void |
| 480 | bi_print_shader(bi_context *ctx, FILE *fp) |
| 481 | { |
| 482 | bi_foreach_block(ctx, block) |
Alyssa Rosenzweig | 9b75f41 | 2020-03-11 14:35:38 -0400 | [diff] [blame] | 483 | bi_print_block((bi_block *) block, fp); |
Alyssa Rosenzweig | bc5724f | 2020-03-05 08:23:43 -0500 | [diff] [blame] | 484 | } |