| 1 |
|
| 2 |
> |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include "util/ralloc.h" |
| 10 |
#include "util/u_math.h" |
| 11 |
|
| 12 |
#include "ir3.h" |
| 13 |
#include "ir3_shader.h" |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
struct ir3_legalize_ctx { |
| 31 |
struct ir3_compiler *compiler; |
| 32 |
struct ir3_shader_variant *so; |
| 33 |
mesa_shader_stage type; |
| 34 |
int max_bary; |
| 35 |
bool early_input_release; |
| 36 |
bool has_inputs; |
| 37 |
bool has_tex_prefetch; |
| 38 |
}; |
| 39 |
|
| 40 |
struct ir3_legalize_block_data { |
| 41 |
bool valid; |
| 42 |
struct ir3_legalize_state begin_state; |
| 43 |
struct ir3_legalize_state state; |
| 44 |
}; |
| 45 |
|
| 46 |
static inline bool |
| 47 |
needs_ss_war(struct ir3_legalize_state *state, struct ir3_register *dst, |
| 48 |
bool is_scalar_alu, enum ir3_instruction_flags cur_flags) |
| 49 |
{ |
| 50 |
if (regmask_get(&state->needs_ss_war, dst)) |
| 51 |
return true; |
| 52 |
if (!(cur_flags & IR3_INSTR_SY) && |
| 53 |
regmask_get(&state->needs_ss_or_sy_war, dst)) { |
| 54 |
return true; |
| 55 |
} |
| 56 |
|
| 57 |
if (!is_scalar_alu) { |
| 58 |
if (regmask_get(&state->needs_ss_scalar_war, dst)) |
| 59 |
return true; |
| 60 |
if (!(cur_flags & IR3_INSTR_SY) && |
| 61 |
regmask_get(&state->needs_ss_or_sy_scalar_war, dst)) { |
| 62 |
return true; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
static inline bool |
| 70 |
needs_sy_war(struct ir3_legalize_state *state, struct ir3_register *dst) |
| 71 |
{ |
| 72 |
return regmask_get(&state->needs_sy_war, dst); |
| 73 |
} |
| 74 |
|
| 75 |
enum ir3_instruction_flags |
| 76 |
ir3_required_sync_flags(struct ir3_legalize_state *state, |
| 77 |
struct ir3_compiler *compiler, |
| 78 |
struct ir3_instruction *n) |
| 79 |
{ |
| 80 |
if (n->opc == OPC_SHPE) { |
| 81 |
return IR3_INSTR_SS | IR3_INSTR_SY; |
| 82 |
} |
| 83 |
|
| 84 |
enum ir3_instruction_flags flags = 0; |
| 85 |
bool n_is_scalar_alu = is_scalar_alu(n, compiler); |
| 86 |
|
| 87 |
if (state->force_ss) { |
| 88 |
flags |= IR3_INSTR_SS; |
| 89 |
} |
| 90 |
|
| 91 |
if (state->force_sy) { |
| 92 |
flags |= IR3_INSTR_SY; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
for (unsigned i = 0; i < n->dsts_count + n->srcs_count; i++) { |
| 102 |
struct ir3_register *reg; |
| 103 |
if (i < n->dsts_count) |
| 104 |
reg = n->dsts[i]; |
| 105 |
else |
| 106 |
reg = n->srcs[i - n->dsts_count]; |
| 107 |
|
| 108 |
if (reg->flags & IR3_REG_DUMMY) |
| 109 |
continue; |
| 110 |
|
| 111 |
if (is_reg_gpr(reg)) { |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
if (regmask_get(&state->needs_ss, reg)) { |
| 118 |
flags |= IR3_INSTR_SS; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
if (n_is_scalar_alu) { |
| 133 |
|
| 134 |
if (regmask_get((reg->flags & IR3_REG_HALF) |
| 135 |
? &state->needs_ss_scalar_half |
| 136 |
: &state->needs_ss_scalar_full, |
| 137 |
reg)) { |
| 138 |
flags |= IR3_INSTR_SS; |
| 139 |
} |
| 140 |
} else { |
| 141 |
|
| 142 |
if (regmask_get(&state->needs_ss_scalar_half, reg) || |
| 143 |
regmask_get(&state->needs_ss_scalar_full, reg)) { |
| 144 |
flags |= IR3_INSTR_SS; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
if (regmask_get(&state->needs_sy, reg)) { |
| 149 |
flags |= IR3_INSTR_SY; |
| 150 |
} |
| 151 |
} else if ((reg->flags & IR3_REG_CONST)) { |
| 152 |
if (reg->flags & IR3_REG_RELATIV) { |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
if (!BITSET_IS_EMPTY(state->needs_ss_for_const)) { |
| 157 |
flags |= IR3_INSTR_SS; |
| 158 |
} |
| 159 |
if (!BITSET_IS_EMPTY(state->needs_sy_for_const)) { |
| 160 |
flags |= IR3_INSTR_SY; |
| 161 |
} |
| 162 |
} else { |
| 163 |
if (BITSET_TEST(state->needs_ss_for_const, reg->num)) { |
| 164 |
flags |= IR3_INSTR_SS; |
| 165 |
} |
| 166 |
if (BITSET_TEST(state->needs_sy_for_const, reg->num)) { |
| 167 |
flags |= IR3_INSTR_SY; |
| 168 |
} |
| 169 |
} |
| 170 |
} else if (!(reg->flags & (IR3_REG_IMMED | IR3_REG_RT))) { |
| 171 |
if (regmask_get(&state->needs_ss, reg)) { |
| 172 |
flags |= IR3_INSTR_SS; |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
foreach_dst (reg, n) { |
| 178 |
if (reg->flags & (IR3_REG_RT | IR3_REG_DUMMY)) |
| 179 |
continue; |
| 180 |
if (needs_sy_war(state, reg)) { |
| 181 |
flags |= IR3_INSTR_SY; |
| 182 |
} |
| 183 |
if (needs_ss_war(state, reg, n_is_scalar_alu, flags)) { |
| 184 |
flags |= IR3_INSTR_SS; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
return flags; |
| 189 |
} |
| 190 |
|
| 191 |
static inline void |
| 192 |
apply_ss(struct ir3_legalize_state *state, bool mergedregs) |
| 193 |
{ |
| 194 |
regmask_init(&state->needs_ss_war, mergedregs); |
| 195 |
regmask_init(&state->needs_ss_or_sy_war, mergedregs); |
| 196 |
regmask_init(&state->needs_ss, mergedregs); |
| 197 |
regmask_init(&state->needs_ss_scalar_war, mergedregs); |
| 198 |
regmask_init(&state->needs_ss_or_sy_scalar_war, mergedregs); |
| 199 |
regmask_init(&state->needs_ss_scalar_full, mergedregs); |
| 200 |
regmask_init(&state->needs_ss_scalar_half, mergedregs); |
| 201 |
BITSET_ZERO(state->needs_ss_for_const); |
| 202 |
state->force_ss = false; |
| 203 |
} |
| 204 |
|
| 205 |
static inline void |
| 206 |
apply_sy(struct ir3_legalize_state *state, bool mergedregs) |
| 207 |
{ |
| 208 |
regmask_init(&state->needs_sy, mergedregs); |
| 209 |
regmask_init(&state->needs_sy_war, mergedregs); |
| 210 |
regmask_init(&state->needs_ss_or_sy_war, mergedregs); |
| 211 |
regmask_init(&state->needs_ss_or_sy_scalar_war, mergedregs); |
| 212 |
BITSET_ZERO(state->needs_sy_for_const); |
| 213 |
state->force_sy = false; |
| 214 |
} |
| 215 |
|
| 216 |
static void |
| 217 |
sync_update(struct ir3_legalize_state *state, struct ir3_compiler *compiler, |
| 218 |
struct ir3_instruction *n) |
| 219 |
{ |
| 220 |
if (n->flags & IR3_INSTR_SS) |
| 221 |
apply_ss(state, compiler->mergedregs); |
| 222 |
if (n->flags & IR3_INSTR_SY) |
| 223 |
apply_sy(state, compiler->mergedregs); |
| 224 |
|
| 225 |
if (is_barrier(n)) { |
| 226 |
state->force_ss = true; |
| 227 |
state->force_sy = true; |
| 228 |
} else { |
| 229 |
state->force_ss = false; |
| 230 |
state->force_sy = false; |
| 231 |
} |
| 232 |
|
| 233 |
bool n_is_scalar_alu = is_scalar_alu(n, compiler); |
| 234 |
|
| 235 |
if (is_sfu(n) || n->opc == OPC_SHFL) |
| 236 |
regmask_set(&state->needs_ss, n->dsts[0]); |
| 237 |
|
| 238 |
foreach_dst (dst, n) { |
| 239 |
if (dst->flags & IR3_REG_SHARED) { |
| 240 |
if (n_is_scalar_alu) { |
| 241 |
if (dst->flags & IR3_REG_HALF) |
| 242 |
regmask_set(&state->needs_ss_scalar_full, dst); |
| 243 |
else |
| 244 |
regmask_set(&state->needs_ss_scalar_half, dst); |
| 245 |
} else { |
| 246 |
regmask_set(&state->needs_ss, dst); |
| 247 |
} |
| 248 |
} else if (reg_is_addr1(dst) && n->block->in_early_preamble) { |
| 249 |
regmask_set(&state->needs_ss, dst); |
| 250 |
} else if (dst->flags & IR3_REG_UNIFORM) { |
| 251 |
regmask_set(&state->needs_ss, dst); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
if (is_tex_or_prefetch(n) && !has_dummy_dst(n)) { |
| 256 |
regmask_set(&state->needs_sy, n->dsts[0]); |
| 257 |
} else if (n->opc == OPC_RESINFO && !has_dummy_dst(n)) { |
| 258 |
regmask_set(&state->needs_ss, n->dsts[0]); |
| 259 |
} else if (is_load(n)) { |
| 260 |
if (is_local_mem_load(n)) |
| 261 |
regmask_set(&state->needs_ss, n->dsts[0]); |
| 262 |
else |
| 263 |
regmask_set(&state->needs_sy, n->dsts[0]); |
| 264 |
} else if (is_atomic(n->opc)) { |
| 265 |
if (is_bindless_atomic(n->opc)) { |
| 266 |
regmask_set(&state->needs_sy, n->srcs[2]); |
| 267 |
} else if (is_global_a3xx_atomic(n->opc) || |
| 268 |
is_global_a6xx_atomic(n->opc)) { |
| 269 |
regmask_set(&state->needs_sy, n->dsts[0]); |
| 270 |
} else { |
| 271 |
regmask_set(&state->needs_ss, n->dsts[0]); |
| 272 |
} |
| 273 |
} else if (n->opc == OPC_PUSH_CONSTS_LOAD_MACRO) { |
| 274 |
unsigned const_dst = n->push_consts.dst_base; |
| 275 |
unsigned const_size = n->push_consts.src_size * 2; |
| 276 |
BITSET_SET_COUNT(state->needs_ss_for_const, const_dst, const_size); |
| 277 |
} else if (n->opc == OPC_STC) { |
| 278 |
unsigned const_dst = n->cat6.dst_offset; |
| 279 |
unsigned const_size = n->cat6.iim_val; |
| 280 |
BITSET_SET_COUNT(state->needs_ss_for_const, const_dst, const_size); |
| 281 |
} else if (n->opc == OPC_LDC_K) { |
| 282 |
unsigned const_dst = n->cat6.dst_offset; |
| 283 |
unsigned const_size = n->cat6.iim_val * 4; |
| 284 |
BITSET_SET_COUNT(state->needs_sy_for_const, const_dst, const_size); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
if (is_war_hazard_producer(n)) { |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
bool needs_ss = is_ss_producer(n) || is_store(n) || n->opc == OPC_STC; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
bool needs_sy = n->opc == OPC_RAY_INTERSECTION; |
| 309 |
|
| 310 |
if (n_is_scalar_alu) { |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
regmask_t *mask = needs_ss ? &state->needs_ss_scalar_war |
| 317 |
: &state->needs_ss_or_sy_scalar_war; |
| 318 |
|
| 319 |
foreach_src (reg, n) { |
| 320 |
if ((reg->flags & IR3_REG_SHARED) || is_reg_a0(reg)) { |
| 321 |
regmask_set(mask, reg); |
| 322 |
} |
| 323 |
} |
| 324 |
} else { |
| 325 |
regmask_t *mask = needs_sy ? &state->needs_sy_war |
| 326 |
: needs_ss ? &state->needs_ss_war |
| 327 |
: &state->needs_ss_or_sy_war; |
| 328 |
|
| 329 |
foreach_src (reg, n) { |
| 330 |
if (!(reg->flags & (IR3_REG_IMMED | IR3_REG_CONST))) { |
| 331 |
regmask_set(mask, reg); |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
void |
| 339 |
ir3_init_legalize_state(struct ir3_legalize_state *state, |
| 340 |
struct ir3_compiler *compiler) |
| 341 |
{ |
| 342 |
regmask_init(&state->needs_ss_war, compiler->mergedregs); |
| 343 |
regmask_init(&state->needs_sy_war, compiler->mergedregs); |
| 344 |
regmask_init(&state->needs_ss_or_sy_war, compiler->mergedregs); |
| 345 |
regmask_init(&state->needs_ss_scalar_war, compiler->mergedregs); |
| 346 |
regmask_init(&state->needs_ss_or_sy_scalar_war, compiler->mergedregs); |
| 347 |
regmask_init(&state->needs_ss_scalar_full, compiler->mergedregs); |
| 348 |
regmask_init(&state->needs_ss_scalar_half, compiler->mergedregs); |
| 349 |
regmask_init(&state->needs_ss, compiler->mergedregs); |
| 350 |
regmask_init(&state->needs_sy, compiler->mergedregs); |
| 351 |
} |
| 352 |
|
| 353 |
static struct ir3_legalize_state * |
| 354 |
get_block_legalize_state(struct ir3_block *block) |
| 355 |
{ |
| 356 |
struct ir3_legalize_block_data *bd = block->data; |
| 357 |
return &bd->state; |
| 358 |
} |
| 359 |
|
| 360 |
void |
| 361 |
ir3_merge_pred_legalize_states(struct ir3_legalize_state *state, |
| 362 |
struct ir3_block *block, |
| 363 |
ir3_get_block_legalize_state_cb get_state) |
| 364 |
{ |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
for (unsigned i = 0; i < block->predecessors_count; i++) { |
| 375 |
struct ir3_block *predecessor = block->predecessors[i]; |
| 376 |
struct ir3_legalize_state *pstate = get_state(predecessor); |
| 377 |
|
| 378 |
if (!pstate) { |
| 379 |
continue; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
regmask_or(&state->needs_ss, &state->needs_ss, &pstate->needs_ss); |
| 386 |
regmask_or(&state->needs_ss_war, &state->needs_ss_war, |
| 387 |
&pstate->needs_ss_war); |
| 388 |
regmask_or(&state->needs_sy_war, &state->needs_sy_war, |
| 389 |
&pstate->needs_sy_war); |
| 390 |
regmask_or(&state->needs_ss_or_sy_war, &state->needs_ss_or_sy_war, |
| 391 |
&pstate->needs_ss_or_sy_war); |
| 392 |
regmask_or(&state->needs_sy, &state->needs_sy, &pstate->needs_sy); |
| 393 |
BITSET_OR(state->needs_ss_for_const, state->needs_ss_for_const, |
| 394 |
pstate->needs_ss_for_const); |
| 395 |
BITSET_OR(state->needs_sy_for_const, state->needs_sy_for_const, |
| 396 |
pstate->needs_sy_for_const); |
| 397 |
state->force_ss |= pstate->force_ss; |
| 398 |
state->force_sy |= pstate->force_sy; |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
for (unsigned i = 0; i < ARRAY_SIZE(state->pred_ready); i++) |
| 407 |
state->pred_ready[i] = |
| 408 |
MAX2(state->pred_ready[i], |
| 409 |
MAX2(pstate->pred_ready[i], pstate->cycle) - pstate->cycle); |
| 410 |
for (unsigned i = 0; i < ARRAY_SIZE(state->alu_nop.full_ready); i++) { |
| 411 |
state->alu_nop.full_ready[i] = MAX2( |
| 412 |
state->alu_nop.full_ready[i], |
| 413 |
MAX2(pstate->alu_nop.full_ready[i], pstate->cycle) - pstate->cycle); |
| 414 |
state->alu_nop.half_ready[i] = MAX2( |
| 415 |
state->alu_nop.half_ready[i], |
| 416 |
MAX2(pstate->alu_nop.half_ready[i], pstate->cycle) - pstate->cycle); |
| 417 |
state->non_alu_nop.full_ready[i] = |
| 418 |
MAX2(state->non_alu_nop.full_ready[i], |
| 419 |
MAX2(pstate->non_alu_nop.full_ready[i], pstate->cycle) - |
| 420 |
pstate->cycle); |
| 421 |
state->non_alu_nop.half_ready[i] = |
| 422 |
MAX2(state->non_alu_nop.half_ready[i], |
| 423 |
MAX2(pstate->non_alu_nop.half_ready[i], pstate->cycle) - |
| 424 |
pstate->cycle); |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
for (unsigned i = 0; i < block->physical_predecessors_count; i++) { |
| 432 |
struct ir3_block *predecessor = block->physical_predecessors[i]; |
| 433 |
struct ir3_legalize_state *pstate = get_state(predecessor); |
| 434 |
|
| 435 |
if (!pstate) { |
| 436 |
continue; |
| 437 |
} |
| 438 |
|
| 439 |
regmask_or_shared(&state->needs_ss, &state->needs_ss, &pstate->needs_ss); |
| 440 |
regmask_or_shared(&state->needs_ss_scalar_full, |
| 441 |
&state->needs_ss_scalar_full, |
| 442 |
&pstate->needs_ss_scalar_full); |
| 443 |
regmask_or_shared(&state->needs_ss_scalar_half, |
| 444 |
&state->needs_ss_scalar_half, |
| 445 |
&pstate->needs_ss_scalar_half); |
| 446 |
regmask_or_shared(&state->needs_ss_scalar_war, |
| 447 |
&state->needs_ss_scalar_war, |
| 448 |
&pstate->needs_ss_scalar_war); |
| 449 |
regmask_or_shared(&state->needs_ss_or_sy_scalar_war, |
| 450 |
&state->needs_ss_or_sy_scalar_war, |
| 451 |
&pstate->needs_ss_or_sy_scalar_war); |
| 452 |
} |
| 453 |
|
| 454 |
mesa_shader_stage stage = block->shader->type; |
| 455 |
|
| 456 |
if (stage == MESA_SHADER_TESS_CTRL || stage == MESA_SHADER_GEOMETRY) { |
| 457 |
if (block == ir3_start_block(block->shader)) { |
| 458 |
state->force_ss = true; |
| 459 |
state->force_sy = true; |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
static bool |
| 465 |
count_instruction(struct ir3_instruction *n, struct ir3_compiler *compiler) |
| 466 |
{ |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
return (is_alu(n) && !is_scalar_alu(n, compiler)) || |
| 472 |
(is_flow(n) && (n->opc != OPC_JUMP) && (n->opc != OPC_BR) && |
| 473 |
(n->opc != OPC_BRAA) && (n->opc != OPC_BRAO)); |
| 474 |
} |
| 475 |
|
| 476 |
static unsigned * |
| 477 |
get_ready_slot(struct ir3_legalize_state *state, |
| 478 |
struct ir3_register *reg, unsigned num, |
| 479 |
bool consumer_alu, bool matching_size) |
| 480 |
{ |
| 481 |
if (reg->flags & IR3_REG_PREDICATE) { |
| 482 |
assert(num == reg->num); |
| 483 |
assert(reg_num(reg) == REG_P0); |
| 484 |
return &state->pred_ready[reg_comp(reg)]; |
| 485 |
} |
| 486 |
if (reg->num == regid(REG_A0, 0)) |
| 487 |
return &state->addr_ready[0]; |
| 488 |
if (reg->num == regid(REG_A0, 1)) |
| 489 |
return &state->addr_ready[1]; |
| 490 |
struct ir3_nop_state *nop = |
| 491 |
consumer_alu ? &state->alu_nop : &state->non_alu_nop; |
| 492 |
assert(!(reg->flags & IR3_REG_SHARED)); |
| 493 |
if (reg->flags & IR3_REG_HALF) { |
| 494 |
if (matching_size) { |
| 495 |
assert(num < ARRAY_SIZE(nop->half_ready)); |
| 496 |
return &nop->half_ready[num]; |
| 497 |
} else { |
| 498 |
assert(num / 2 < ARRAY_SIZE(nop->full_ready)); |
| 499 |
return &nop->full_ready[num / 2]; |
| 500 |
} |
| 501 |
} else { |
| 502 |
if (matching_size) { |
| 503 |
assert(num < ARRAY_SIZE(nop->full_ready)); |
| 504 |
return &nop->full_ready[num]; |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
else if (num * 2 < ARRAY_SIZE(nop->half_ready)) |
| 511 |
return &nop->half_ready[num * 2]; |
| 512 |
else |
| 513 |
return NULL; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
unsigned |
| 518 |
ir3_required_delay(struct ir3_legalize_state *state, |
| 519 |
struct ir3_compiler *compiler, struct ir3_instruction *instr) |
| 520 |
{ |
| 521 |
|
| 522 |
if (instr->opc == OPC_END || instr->opc == OPC_CHMASK) |
| 523 |
return 0; |
| 524 |
|
| 525 |
unsigned delay = 0; |
| 526 |
foreach_src_n (src, n, instr) { |
| 527 |
if (src->flags & (IR3_REG_CONST | IR3_REG_IMMED | IR3_REG_SHARED)) |
| 528 |
continue; |
| 529 |
|
| 530 |
unsigned elems = post_ra_reg_elems(src); |
| 531 |
unsigned num = post_ra_reg_num(src); |
| 532 |
unsigned src_cycle = |
| 533 |
state->cycle + ir3_src_read_delay(compiler, instr, n); |
| 534 |
|
| 535 |
for (unsigned elem = 0; elem < elems; elem++, num++) { |
| 536 |
unsigned ready_cycle = |
| 537 |
*get_ready_slot(state, src, num, is_alu(instr), true); |
| 538 |
delay = MAX2(delay, MAX2(ready_cycle, src_cycle) - src_cycle); |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
if (instr->repeat && !(src->flags & IR3_REG_RELATIV)) |
| 544 |
src_cycle++; |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
return delay; |
| 549 |
} |
| 550 |
|
| 551 |
static void |
| 552 |
delay_update(struct ir3_compiler *compiler, |
| 553 |
struct ir3_legalize_state *state, |
| 554 |
struct ir3_instruction *instr) |
| 555 |
{ |
| 556 |
if (writes_addr1(instr) && instr->block->in_early_preamble) |
| 557 |
return; |
| 558 |
|
| 559 |
foreach_dst_n (dst, n, instr) { |
| 560 |
if (dst->flags & (IR3_REG_RT | IR3_REG_DUMMY)) |
| 561 |
continue; |
| 562 |
|
| 563 |
unsigned elems = post_ra_reg_elems(dst); |
| 564 |
unsigned num = post_ra_reg_num(dst); |
| 565 |
unsigned dst_cycle = state->cycle; |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
if (instr->opc == OPC_SCT || instr->opc == OPC_SWZ) |
| 571 |
dst_cycle += n; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
if (dst->flags & IR3_REG_RELATIV) |
| 578 |
dst_cycle += instr->repeat; |
| 579 |
|
| 580 |
if (dst->flags & (IR3_REG_SHARED | IR3_REG_UNIFORM)) |
| 581 |
continue; |
| 582 |
|
| 583 |
for (unsigned elem = 0; elem < elems; elem++, num++) { |
| 584 |
|
| 585 |
if (!(dst->flags & IR3_REG_RELATIV) && !(dst->wrmask & (1 << elem))) |
| 586 |
continue; |
| 587 |
|
| 588 |
for (unsigned consumer_alu = 0; consumer_alu < 2; consumer_alu++) { |
| 589 |
for (unsigned matching_size = 0; matching_size < 2; matching_size++) { |
| 590 |
unsigned *ready_slot = |
| 591 |
get_ready_slot(state, dst, num, consumer_alu, matching_size); |
| 592 |
|
| 593 |
if (!ready_slot) |
| 594 |
continue; |
| 595 |
|
| 596 |
bool reset_ready_slot = false; |
| 597 |
unsigned delay = 0; |
| 598 |
if (!is_alu(instr)) { |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
reset_ready_slot = true; |
| 605 |
} else if ((dst->flags & IR3_REG_PREDICATE) || |
| 606 |
reg_num(dst) == REG_A0) { |
| 607 |
delay = compiler->delay_slots.non_alu; |
| 608 |
if (!matching_size) |
| 609 |
continue; |
| 610 |
} else { |
| 611 |
delay = (consumer_alu && matching_size) |
| 612 |
? compiler->delay_slots.alu_to_alu |
| 613 |
: compiler->delay_slots.non_alu; |
| 614 |
} |
| 615 |
|
| 616 |
if (!matching_size) { |
| 617 |
for (unsigned i = 0; i < reg_elem_size(dst); i++) { |
| 618 |
ready_slot[i] = |
| 619 |
reset_ready_slot ? 0 : |
| 620 |
MAX2(ready_slot[i], dst_cycle + delay); |
| 621 |
} |
| 622 |
} else { |
| 623 |
*ready_slot = |
| 624 |
reset_ready_slot ? 0 : |
| 625 |
MAX2(*ready_slot, dst_cycle + delay); |
| 626 |
} |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
if (instr->repeat && !(dst->flags & IR3_REG_RELATIV)) |
| 634 |
dst_cycle++; |
| 635 |
} |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
void |
| 640 |
ir3_update_legalize_state(struct ir3_legalize_state *state, |
| 641 |
struct ir3_compiler *compiler, |
| 642 |
struct ir3_instruction *n) |
| 643 |
{ |
| 644 |
sync_update(state, compiler, n); |
| 645 |
|
| 646 |
bool count = count_instruction(n, compiler); |
| 647 |
if (count) |
| 648 |
state->cycle += 1; |
| 649 |
|
| 650 |
delay_update(compiler, state, n); |
| 651 |
|
| 652 |
if (count) |
| 653 |
state->cycle += n->repeat + n->nop; |
| 654 |
} |
| 655 |
|
| 656 |
static struct ir3_instruction * |
| 657 |
insert_nop_flags(struct ir3_legalize_ctx *ctx, |
| 658 |
struct ir3_legalize_state *state, |
| 659 |
struct ir3_instruction *last_n, |
| 660 |
struct ir3_builder *build, |
| 661 |
enum ir3_instruction_flags flags) |
| 662 |
{ |
| 663 |
if (last_n && last_n->opc == OPC_NOP) { |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
last_n->flags |= flags; |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
sync_update(state, ctx->compiler, last_n); |
| 674 |
} else { |
| 675 |
struct ir3_instruction *nop = ir3_NOP(build); |
| 676 |
nop->flags |= flags; |
| 677 |
ir3_update_legalize_state(state, ctx->compiler, nop); |
| 678 |
last_n = nop; |
| 679 |
} |
| 680 |
|
| 681 |
return last_n; |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
static bool |
| 700 |
legalize_block(struct ir3_legalize_ctx *ctx, struct ir3_block *block) |
| 701 |
{ |
| 702 |
struct ir3_legalize_block_data *bd = block->data; |
| 703 |
|
| 704 |
if (bd->valid) |
| 705 |
return false; |
| 706 |
|
| 707 |
struct ir3_instruction *last_n = NULL; |
| 708 |
struct list_head instr_list; |
| 709 |
struct ir3_legalize_state prev_state = bd->state; |
| 710 |
struct ir3_legalize_state *state = &bd->begin_state; |
| 711 |
bool last_input_needs_ss = false; |
| 712 |
struct ir3_builder build = ir3_builder_at(ir3_after_block(block)); |
| 713 |
|
| 714 |
ir3_merge_pred_legalize_states(state, block, get_block_legalize_state); |
| 715 |
|
| 716 |
memcpy(&bd->state, state, sizeof(*state)); |
| 717 |
state = &bd->state; |
| 718 |
|
| 719 |
unsigned input_count = 0; |
| 720 |
|
| 721 |
foreach_instr (n, &block->instr_list) { |
| 722 |
if (is_input(n)) { |
| 723 |
input_count++; |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
unsigned inputs_remaining = input_count; |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
assert(input_count == 0 || !ctx->early_input_release || |
| 733 |
block == ir3_after_preamble(block->shader)); |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
list_replace(&block->instr_list, &instr_list); |
| 739 |
list_inithead(&block->instr_list); |
| 740 |
|
| 741 |
state->cycle = 0; |
| 742 |
|
| 743 |
foreach_instr_safe (n, &instr_list) { |
| 744 |
unsigned i; |
| 745 |
|
| 746 |
n->flags &= ~(IR3_INSTR_SS | IR3_INSTR_SY); |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
if (is_meta(n) && (n->opc != OPC_META_TEX_PREFETCH)) |
| 752 |
continue; |
| 753 |
|
| 754 |
if (is_input(n)) { |
| 755 |
struct ir3_register *inloc = n->srcs[0]; |
| 756 |
assert(inloc->flags & IR3_REG_IMMED); |
| 757 |
|
| 758 |
int last_inloc = |
| 759 |
inloc->iim_val + ((inloc->flags & IR3_REG_R) ? n->repeat : 0); |
| 760 |
ctx->max_bary = MAX2(ctx->max_bary, last_inloc); |
| 761 |
} |
| 762 |
|
| 763 |
bool n_is_scalar_alu = is_scalar_alu(n, ctx->compiler); |
| 764 |
|
| 765 |
enum ir3_instruction_flags sync_flags = |
| 766 |
ir3_required_sync_flags(state, ctx->compiler, n); |
| 767 |
n->flags |= sync_flags; |
| 768 |
|
| 769 |
if (sync_flags & IR3_INSTR_SS) { |
| 770 |
last_input_needs_ss = false; |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
if (block->in_early_preamble) { |
| 775 |
if (writes_addr1(n) || (n->opc == OPC_LDC)) |
| 776 |
n->flags |= IR3_INSTR_U; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
if ((n->opc == OPC_SHPE) && (ctx->compiler->gen >= 8) && |
| 781 |
block->in_early_preamble && |
| 782 |
regmask_get_any_shared(&state->needs_sy)) { |
| 783 |
last_n = insert_nop_flags(ctx, state, last_n, &build, IR3_INSTR_SY); |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
if ((n->flags & IR3_INSTR_SS) && !supports_ss(n)) { |
| 792 |
last_n = insert_nop_flags(ctx, state, last_n, &build, IR3_INSTR_SS); |
| 793 |
n->flags &= ~IR3_INSTR_SS; |
| 794 |
} |
| 795 |
|
| 796 |
unsigned delay = ir3_required_delay(state, ctx->compiler, n); |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
if ((delay > 0) && (ctx->compiler->gen >= 6) && last_n && |
| 804 |
!n_is_scalar_alu && |
| 805 |
((opc_cat(last_n->opc) == 2) || (opc_cat(last_n->opc) == 3)) && |
| 806 |
(last_n->repeat == 0)) { |
| 807 |
|
| 808 |
unsigned transfer = MIN2(delay, 3 - last_n->nop); |
| 809 |
last_n->nop += transfer; |
| 810 |
delay -= transfer; |
| 811 |
state->cycle += transfer; |
| 812 |
} |
| 813 |
|
| 814 |
if ((delay > 0) && last_n && (last_n->opc == OPC_NOP)) { |
| 815 |
|
| 816 |
unsigned transfer = MIN2(delay, 5 - last_n->repeat); |
| 817 |
last_n->repeat += transfer; |
| 818 |
delay -= transfer; |
| 819 |
state->cycle += transfer; |
| 820 |
} |
| 821 |
|
| 822 |
if (delay > 0) { |
| 823 |
assert(delay <= 6); |
| 824 |
ir3_NOP(&build)->repeat = delay - 1; |
| 825 |
state->cycle += delay; |
| 826 |
} |
| 827 |
|
| 828 |
if (ctx->compiler->samgq_workaround && |
| 829 |
!is_compute_or_frag(ctx->type) && |
| 830 |
n->opc == OPC_SAMGQ) { |
| 831 |
struct ir3_instruction *samgp; |
| 832 |
|
| 833 |
list_delinit(&n->node); |
| 834 |
|
| 835 |
for (i = 0; i < 4; i++) { |
| 836 |
samgp = ir3_instr_clone(n); |
| 837 |
samgp->opc = OPC_SAMGP0 + i; |
| 838 |
if (i > 1) |
| 839 |
samgp->flags |= IR3_INSTR_SY; |
| 840 |
} |
| 841 |
} else { |
| 842 |
list_delinit(&n->node); |
| 843 |
list_addtail(&n->node, &block->instr_list); |
| 844 |
} |
| 845 |
|
| 846 |
if (n->opc == OPC_META_TEX_PREFETCH) { |
| 847 |
assert(n->dsts_count > 0); |
| 848 |
ctx->has_tex_prefetch = true; |
| 849 |
} |
| 850 |
|
| 851 |
if (n->opc == OPC_RESINFO && !has_dummy_dst(n)) { |
| 852 |
ir3_update_legalize_state(state, ctx->compiler, n); |
| 853 |
|
| 854 |
n = ir3_NOP(&build); |
| 855 |
n->flags |= IR3_INSTR_SS; |
| 856 |
last_input_needs_ss = false; |
| 857 |
} |
| 858 |
|
| 859 |
if (is_ssbo(n->opc) || is_global_a3xx_atomic(n->opc) || |
| 860 |
is_bindless_atomic(n->opc)) |
| 861 |
ctx->so->has_ssbo = true; |
| 862 |
|
| 863 |
if (ctx->early_input_release && is_input(n)) { |
| 864 |
last_input_needs_ss |= (n->opc == OPC_LDLV); |
| 865 |
|
| 866 |
assert(inputs_remaining > 0); |
| 867 |
inputs_remaining--; |
| 868 |
if (inputs_remaining == 0) { |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
struct ir3_instruction *last_input = n; |
| 877 |
if (n->opc == OPC_LDLV) { |
| 878 |
struct ir3_instruction *baryf; |
| 879 |
|
| 880 |
|
| 881 |
baryf = ir3_build_instr(&build, OPC_BARY_F, 1, 2); |
| 882 |
ir3_dst_create(baryf, regid(63, 0), 0); |
| 883 |
ir3_src_create(baryf, 0, IR3_REG_IMMED)->iim_val = 0; |
| 884 |
ir3_src_create(baryf, regid(0, 0), 0); |
| 885 |
|
| 886 |
last_input = baryf; |
| 887 |
} |
| 888 |
|
| 889 |
last_input->dsts[0]->flags |= IR3_REG_EI; |
| 890 |
if (last_input_needs_ss) { |
| 891 |
last_input->flags |= IR3_INSTR_SS; |
| 892 |
} |
| 893 |
} |
| 894 |
} |
| 895 |
|
| 896 |
ir3_update_legalize_state(state, ctx->compiler, n); |
| 897 |
last_n = n; |
| 898 |
} |
| 899 |
|
| 900 |
assert(inputs_remaining == 0 || !ctx->early_input_release); |
| 901 |
|
| 902 |
if (block == ir3_after_preamble(ctx->so->ir) && |
| 903 |
ctx->has_tex_prefetch && !ctx->has_inputs) { |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
struct ir3_instruction *baryf; |
| 909 |
|
| 910 |
|
| 911 |
baryf = ir3_build_instr(&build, OPC_BARY_F, 1, 2); |
| 912 |
ir3_dst_create(baryf, regid(63, 0), 0)->flags |= IR3_REG_EI; |
| 913 |
ir3_src_create(baryf, 0, IR3_REG_IMMED)->iim_val = 0; |
| 914 |
ir3_src_create(baryf, regid(0, 0), 0); |
| 915 |
|
| 916 |
|
| 917 |
list_delinit(&baryf->node); |
| 918 |
list_add(&baryf->node, &block->instr_list); |
| 919 |
} |
| 920 |
|
| 921 |
bd->valid = true; |
| 922 |
|
| 923 |
if (memcmp(&prev_state, state, sizeof(*state))) { |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
for (unsigned i = 0; i < ARRAY_SIZE(block->successors); i++) { |
| 928 |
if (!block->successors[i]) |
| 929 |
break; |
| 930 |
struct ir3_legalize_block_data *pbd = block->successors[i]->data; |
| 931 |
pbd->valid = false; |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
return true; |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
static bool |
| 947 |
apply_fine_deriv_macro(struct ir3_legalize_ctx *ctx, struct ir3_block *block) |
| 948 |
{ |
| 949 |
struct list_head instr_list; |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
list_replace(&block->instr_list, &instr_list); |
| 955 |
list_inithead(&block->instr_list); |
| 956 |
|
| 957 |
foreach_instr_safe (n, &instr_list) { |
| 958 |
list_addtail(&n->node, &block->instr_list); |
| 959 |
|
| 960 |
if (n->opc == OPC_DSXPP_MACRO || n->opc == OPC_DSYPP_MACRO) { |
| 961 |
n->opc = (n->opc == OPC_DSXPP_MACRO) ? OPC_DSXPP_1 : OPC_DSYPP_1; |
| 962 |
|
| 963 |
struct ir3_instruction *op_p = ir3_instr_clone(n); |
| 964 |
op_p->flags = IR3_INSTR_P; |
| 965 |
|
| 966 |
ctx->so->need_full_quad = true; |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
return true; |
| 971 |
} |
| 972 |
|
| 973 |
static void |
| 974 |
apply_push_consts_load_macro(struct ir3_legalize_ctx *ctx, |
| 975 |
struct ir3_block *block) |
| 976 |
{ |
| 977 |
foreach_instr (n, &block->instr_list) { |
| 978 |
if (n->opc == OPC_PUSH_CONSTS_LOAD_MACRO) { |
| 979 |
struct ir3_instruction *stsc = |
| 980 |
ir3_instr_create_at(ir3_after_instr(n), OPC_STSC, 0, 2); |
| 981 |
ir3_src_create(stsc, 0, IR3_REG_IMMED)->iim_val = |
| 982 |
n->push_consts.dst_base; |
| 983 |
ir3_src_create(stsc, 0, IR3_REG_IMMED)->iim_val = |
| 984 |
n->push_consts.src_base; |
| 985 |
stsc->cat6.iim_val = n->push_consts.src_size; |
| 986 |
stsc->cat6.type = TYPE_U32; |
| 987 |
|
| 988 |
if (ctx->compiler->info->props.stsc_duplication_quirk) { |
| 989 |
struct ir3_builder build = ir3_builder_at(ir3_after_instr(stsc)); |
| 990 |
struct ir3_instruction *nop = ir3_NOP(&build); |
| 991 |
nop->flags |= IR3_INSTR_SS; |
| 992 |
ir3_instr_move_after(ir3_instr_clone(stsc), nop); |
| 993 |
} |
| 994 |
|
| 995 |
list_delinit(&n->node); |
| 996 |
break; |
| 997 |
} else if (!is_meta(n)) { |
| 998 |
break; |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
static struct ir3_block * |
| 1039 |
resolve_dest_block(struct ir3_block *block) |
| 1040 |
{ |
| 1041 |
|
| 1042 |
if (!block->successors[0]) |
| 1043 |
return block; |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
if (block->successors[1] == NULL) { |
| 1053 |
if (list_is_empty(&block->instr_list)) { |
| 1054 |
return block->successors[0]; |
| 1055 |
} else if (list_length(&block->instr_list) == 1) { |
| 1056 |
struct ir3_instruction *instr = |
| 1057 |
list_first_entry(&block->instr_list, struct ir3_instruction, node); |
| 1058 |
if (instr->opc == OPC_JUMP) { |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
if (block->successors[0]->index <= block->index) |
| 1066 |
return block; |
| 1067 |
return block->successors[0]; |
| 1068 |
} |
| 1069 |
} |
| 1070 |
} |
| 1071 |
return block; |
| 1072 |
} |
| 1073 |
|
| 1074 |
static void |
| 1075 |
remove_unused_block(struct ir3_block *old_target) |
| 1076 |
{ |
| 1077 |
list_delinit(&old_target->node); |
| 1078 |
|
| 1079 |
|
| 1080 |
for (unsigned i = 0; i < ARRAY_SIZE(old_target->successors); i++) { |
| 1081 |
if (old_target->successors[i]) { |
| 1082 |
struct ir3_block *succ = old_target->successors[i]; |
| 1083 |
ir3_block_remove_predecessor(succ, old_target); |
| 1084 |
} |
| 1085 |
} |
| 1086 |
} |
| 1087 |
|
| 1088 |
static bool |
| 1089 |
retarget_jump(struct ir3_instruction *instr, struct ir3_block *new_target) |
| 1090 |
{ |
| 1091 |
struct ir3_block *old_target = instr->cat0.target; |
| 1092 |
struct ir3_block *cur_block = instr->block; |
| 1093 |
|
| 1094 |
|
| 1095 |
if (cur_block->successors[0] == old_target) { |
| 1096 |
cur_block->successors[0] = new_target; |
| 1097 |
} else { |
| 1098 |
assert(cur_block->successors[1] == old_target); |
| 1099 |
cur_block->successors[1] = new_target; |
| 1100 |
} |
| 1101 |
|
| 1102 |
|
| 1103 |
ir3_block_add_predecessor(new_target, cur_block); |
| 1104 |
|
| 1105 |
|
| 1106 |
ir3_block_remove_predecessor(old_target, cur_block); |
| 1107 |
|
| 1108 |
instr->cat0.target = new_target; |
| 1109 |
|
| 1110 |
if (old_target->predecessors_count == 0) { |
| 1111 |
remove_unused_block(old_target); |
| 1112 |
return true; |
| 1113 |
} |
| 1114 |
|
| 1115 |
return false; |
| 1116 |
} |
| 1117 |
|
| 1118 |
static bool |
| 1119 |
is_invertible_branch(struct ir3_instruction *instr) |
| 1120 |
{ |
| 1121 |
switch (instr->opc) { |
| 1122 |
case OPC_BR: |
| 1123 |
case OPC_BRAA: |
| 1124 |
case OPC_BRAO: |
| 1125 |
case OPC_BANY: |
| 1126 |
case OPC_BALL: |
| 1127 |
return true; |
| 1128 |
default: |
| 1129 |
return false; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
static bool |
| 1134 |
opt_jump(struct ir3 *ir) |
| 1135 |
{ |
| 1136 |
bool progress = false; |
| 1137 |
|
| 1138 |
unsigned index = 0; |
| 1139 |
foreach_block (block, &ir->block_list) |
| 1140 |
block->index = index++; |
| 1141 |
|
| 1142 |
foreach_block (block, &ir->block_list) { |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
block->physical_successors_count = 0; |
| 1147 |
block->physical_predecessors_count = 0; |
| 1148 |
|
| 1149 |
foreach_instr (instr, &block->instr_list) { |
| 1150 |
if (!is_flow(instr) || !instr->cat0.target) |
| 1151 |
continue; |
| 1152 |
|
| 1153 |
struct ir3_block *tblock = resolve_dest_block(instr->cat0.target); |
| 1154 |
if (tblock != instr->cat0.target) { |
| 1155 |
progress = true; |
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
if (retarget_jump(instr, tblock)) |
| 1161 |
return true; |
| 1162 |
} |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
if (list_is_empty(&block->instr_list)) |
| 1172 |
continue; |
| 1173 |
|
| 1174 |
struct ir3_instruction *jumps[2] = {NULL, NULL}; |
| 1175 |
jumps[0] = |
| 1176 |
list_last_entry(&block->instr_list, struct ir3_instruction, node); |
| 1177 |
if (!list_is_singular(&block->instr_list)) |
| 1178 |
jumps[1] = |
| 1179 |
list_last_entry(&jumps[0]->node, struct ir3_instruction, node); |
| 1180 |
|
| 1181 |
if (jumps[0]->opc == OPC_JUMP) |
| 1182 |
jumps[1] = NULL; |
| 1183 |
else if (!is_invertible_branch(jumps[0]) || !jumps[1] || |
| 1184 |
!is_invertible_branch(jumps[1])) { |
| 1185 |
continue; |
| 1186 |
} |
| 1187 |
|
| 1188 |
for (unsigned i = 0; i < 2; i++) { |
| 1189 |
if (!jumps[i]) |
| 1190 |
continue; |
| 1191 |
struct ir3_block *tblock = jumps[i]->cat0.target; |
| 1192 |
if (&tblock->node == block->node.next) { |
| 1193 |
list_delinit(&jumps[i]->node); |
| 1194 |
progress = true; |
| 1195 |
break; |
| 1196 |
} |
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
return progress; |
| 1201 |
} |
| 1202 |
|
| 1203 |
static void |
| 1204 |
resolve_jumps(struct ir3 *ir) |
| 1205 |
{ |
| 1206 |
foreach_block (block, &ir->block_list) |
| 1207 |
foreach_instr (instr, &block->instr_list) |
| 1208 |
if (is_flow(instr) && instr->cat0.target) { |
| 1209 |
struct ir3_instruction *target = list_first_entry( |
| 1210 |
&instr->cat0.target->instr_list, struct ir3_instruction, node); |
| 1211 |
|
| 1212 |
instr->cat0.immed = (int)target->ip - (int)instr->ip; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
|
| 1216 |
static void |
| 1217 |
mark_jp(struct ir3_block *block) |
| 1218 |
{ |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
assert(!list_is_empty(&block->instr_list)); |
| 1224 |
|
| 1225 |
struct ir3_instruction *target = |
| 1226 |
list_first_entry(&block->instr_list, struct ir3_instruction, node); |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
if (target->opc == OPC_END && block->shader->compiler->gen == 5) { |
| 1232 |
struct ir3_builder build = ir3_builder_at(ir3_before_instr(target)); |
| 1233 |
target = ir3_NOP(&build); |
| 1234 |
} |
| 1235 |
|
| 1236 |
target->flags |= IR3_INSTR_JP; |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
static void |
| 1246 |
mark_xvergence_points(struct ir3 *ir) |
| 1247 |
{ |
| 1248 |
foreach_block (block, &ir->block_list) { |
| 1249 |
if (block->reconvergence_point || block->wave_reconvergence_point) |
| 1250 |
mark_jp(block); |
| 1251 |
} |
| 1252 |
} |
| 1253 |
|
| 1254 |
static void |
| 1255 |
invert_branch(struct ir3_instruction *branch) |
| 1256 |
{ |
| 1257 |
switch (branch->opc) { |
| 1258 |
case OPC_BR: |
| 1259 |
break; |
| 1260 |
case OPC_BALL: |
| 1261 |
branch->opc = OPC_BANY; |
| 1262 |
break; |
| 1263 |
case OPC_BANY: |
| 1264 |
branch->opc = OPC_BALL; |
| 1265 |
break; |
| 1266 |
case OPC_BRAA: |
| 1267 |
branch->opc = OPC_BRAO; |
| 1268 |
break; |
| 1269 |
case OPC_BRAO: |
| 1270 |
branch->opc = OPC_BRAA; |
| 1271 |
break; |
| 1272 |
default: |
| 1273 |
UNREACHABLE("can't get here"); |
| 1274 |
} |
| 1275 |
|
| 1276 |
branch->cat0.inv1 = !branch->cat0.inv1; |
| 1277 |
branch->cat0.inv2 = !branch->cat0.inv2; |
| 1278 |
branch->cat0.target = branch->block->successors[1]; |
| 1279 |
} |
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
static void |
| 1287 |
block_sched(struct ir3 *ir) |
| 1288 |
{ |
| 1289 |
foreach_block (block, &ir->block_list) { |
| 1290 |
struct ir3_instruction *terminator = ir3_block_get_terminator(block); |
| 1291 |
|
| 1292 |
if (block->successors[1]) { |
| 1293 |
|
| 1294 |
struct ir3_instruction *br1, *br2; |
| 1295 |
|
| 1296 |
assert(terminator); |
| 1297 |
unsigned opc = terminator->opc; |
| 1298 |
|
| 1299 |
if (opc == OPC_GETONE || opc == OPC_SHPS || opc == OPC_GETLAST) { |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
assert(terminator->srcs_count == 0); |
| 1305 |
br1 = terminator; |
| 1306 |
br1->cat0.target = block->successors[1]; |
| 1307 |
|
| 1308 |
struct ir3_builder build = ir3_builder_at(ir3_after_block(block)); |
| 1309 |
br2 = ir3_JUMP(&build); |
| 1310 |
br2->cat0.target = block->successors[0]; |
| 1311 |
} else if (opc == OPC_BR || opc == OPC_BRAA || opc == OPC_BRAO || |
| 1312 |
opc == OPC_BALL || opc == OPC_BANY) { |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
br1 = terminator; |
| 1317 |
br2 = ir3_instr_clone(br1); |
| 1318 |
invert_branch(br1); |
| 1319 |
br2->cat0.target = block->successors[0]; |
| 1320 |
} else { |
| 1321 |
assert(opc == OPC_PREDT || opc == OPC_PREDF); |
| 1322 |
|
| 1323 |
|
| 1324 |
terminator->cat0.target = block->successors[0]; |
| 1325 |
continue; |
| 1326 |
} |
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
ir3_instr_move_after(br2, br1); |
| 1332 |
} else if (block->successors[0]) { |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
assert(terminator); |
| 1337 |
assert(terminator->opc == OPC_JUMP || terminator->opc == OPC_PREDT || |
| 1338 |
terminator->opc == OPC_PREDF || terminator->opc == OPC_SHPE); |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
if (terminator->opc == OPC_SHPE) { |
| 1344 |
struct ir3_builder b = ir3_builder_at(ir3_after_instr(terminator)); |
| 1345 |
terminator = ir3_JUMP(&b); |
| 1346 |
} |
| 1347 |
|
| 1348 |
terminator->cat0.target = block->successors[0]; |
| 1349 |
} |
| 1350 |
} |
| 1351 |
} |
| 1352 |
|
| 1353 |
static void |
| 1354 |
add_nop_before_block(struct ir3_block *block, unsigned repeat) |
| 1355 |
{ |
| 1356 |
struct ir3_instruction *nop = ir3_block_get_first_instr(block); |
| 1357 |
|
| 1358 |
if (!nop || nop->opc != OPC_NOP) { |
| 1359 |
struct ir3_builder build = ir3_builder_at(ir3_before_block(block)); |
| 1360 |
nop = ir3_NOP(&build); |
| 1361 |
} |
| 1362 |
|
| 1363 |
nop->repeat = MAX2(nop->repeat, repeat); |
| 1364 |
} |
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
static void |
| 1374 |
add_predication_workaround(struct ir3_compiler *compiler, |
| 1375 |
struct ir3_instruction *predtf, |
| 1376 |
struct ir3_instruction *prede) |
| 1377 |
{ |
| 1378 |
if (predtf && compiler->info->props.predtf_nop_quirk) { |
| 1379 |
add_nop_before_block(predtf->block->predecessors[0]->successors[1], 4); |
| 1380 |
} |
| 1381 |
|
| 1382 |
if (compiler->info->props.prede_nop_quirk) { |
| 1383 |
add_nop_before_block(prede->block->successors[0], 6); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
|
| 1387 |
static void |
| 1388 |
prede_sched(struct ir3 *ir) |
| 1389 |
{ |
| 1390 |
unsigned index = 0; |
| 1391 |
foreach_block (block, &ir->block_list) |
| 1392 |
block->index = index++; |
| 1393 |
|
| 1394 |
foreach_block (block, &ir->block_list) { |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
struct ir3_block *succ0 = block->successors[0]; |
| 1412 |
struct ir3_block *succ1 = block->successors[1]; |
| 1413 |
|
| 1414 |
if (!succ1) |
| 1415 |
continue; |
| 1416 |
|
| 1417 |
struct ir3_instruction *terminator = ir3_block_get_terminator(block); |
| 1418 |
if (!terminator) |
| 1419 |
continue; |
| 1420 |
if (terminator->opc != OPC_PREDT && terminator->opc != OPC_PREDF) |
| 1421 |
continue; |
| 1422 |
|
| 1423 |
assert(!succ0->successors[1] && !succ1->successors[1]); |
| 1424 |
assert(succ0->successors[0] == succ1->successors[0]); |
| 1425 |
assert(succ0->predecessors_count == 1 && succ1->predecessors_count == 1); |
| 1426 |
assert(succ0->index == (block->index + 1)); |
| 1427 |
assert(succ1->index == (block->index + 2)); |
| 1428 |
|
| 1429 |
struct ir3_instruction *succ0_terminator = |
| 1430 |
ir3_block_get_terminator(succ0); |
| 1431 |
assert(succ0_terminator); |
| 1432 |
assert(succ0_terminator->opc == |
| 1433 |
(terminator->opc == OPC_PREDT ? OPC_PREDF : OPC_PREDT)); |
| 1434 |
|
| 1435 |
ASSERTED struct ir3_instruction *succ1_terminator = |
| 1436 |
ir3_block_get_terminator(succ1); |
| 1437 |
assert(!succ1_terminator || (succ1_terminator->opc == OPC_JUMP)); |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
if (!list_is_empty(&succ1->instr_list)) { |
| 1456 |
struct ir3_builder build = |
| 1457 |
ir3_builder_at(ir3_before_terminator(succ1)); |
| 1458 |
struct ir3_instruction *prede = ir3_PREDE(&build); |
| 1459 |
add_predication_workaround(ir->compiler, succ0_terminator, prede); |
| 1460 |
continue; |
| 1461 |
} |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
list_delinit(&succ0_terminator->node); |
| 1479 |
struct ir3_builder build = ir3_builder_at(ir3_before_terminator(succ0)); |
| 1480 |
struct ir3_instruction *prede = ir3_PREDE(&build); |
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
prede->flags |= succ0_terminator->flags; |
| 1486 |
add_predication_workaround(ir->compiler, NULL, prede); |
| 1487 |
remove_unused_block(succ1); |
| 1488 |
block->successors[1] = succ0->successors[0]; |
| 1489 |
ir3_block_add_predecessor(succ0->successors[0], block); |
| 1490 |
} |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
static void |
| 1511 |
kill_sched(struct ir3 *ir, struct ir3_shader_variant *so) |
| 1512 |
{ |
| 1513 |
ir3_count_instructions(ir); |
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
bool always_ends = true; |
| 1519 |
bool added = false; |
| 1520 |
struct ir3_block *last_block = |
| 1521 |
list_last_entry(&ir->block_list, struct ir3_block, node); |
| 1522 |
|
| 1523 |
foreach_block_rev (block, &ir->block_list) { |
| 1524 |
for (unsigned i = 0; i < 2 && block->successors[i]; i++) { |
| 1525 |
if (block->successors[i]->start_ip < block->end_ip) |
| 1526 |
always_ends = false; |
| 1527 |
} |
| 1528 |
|
| 1529 |
if (always_ends) |
| 1530 |
continue; |
| 1531 |
|
| 1532 |
foreach_instr_safe (instr, &block->instr_list) { |
| 1533 |
if (instr->opc != OPC_KILL) |
| 1534 |
continue; |
| 1535 |
|
| 1536 |
struct ir3_instruction *br = |
| 1537 |
ir3_instr_create_at(ir3_after_instr(instr), OPC_BR, 0, 1); |
| 1538 |
ir3_src_create(br, instr->srcs[0]->num, instr->srcs[0]->flags)->wrmask = |
| 1539 |
1; |
| 1540 |
br->cat0.target = |
| 1541 |
list_last_entry(&ir->block_list, struct ir3_block, node); |
| 1542 |
|
| 1543 |
added = true; |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
if (added) { |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
so->branchstack++; |
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
mark_jp(last_block); |
| 1558 |
} |
| 1559 |
} |
| 1560 |
|
| 1561 |
static void |
| 1562 |
dbg_sync_sched(struct ir3 *ir, struct ir3_shader_variant *so) |
| 1563 |
{ |
| 1564 |
foreach_block (block, &ir->block_list) { |
| 1565 |
foreach_instr_safe (instr, &block->instr_list) { |
| 1566 |
if (is_ss_producer(instr) || is_sy_producer(instr)) { |
| 1567 |
struct ir3_builder build = ir3_builder_at(ir3_after_instr(instr)); |
| 1568 |
struct ir3_instruction *nop = ir3_NOP(&build); |
| 1569 |
nop->flags |= IR3_INSTR_SS | IR3_INSTR_SY; |
| 1570 |
} |
| 1571 |
} |
| 1572 |
} |
| 1573 |
} |
| 1574 |
|
| 1575 |
static void |
| 1576 |
dbg_nop_sched(struct ir3 *ir, struct ir3_shader_variant *so) |
| 1577 |
{ |
| 1578 |
foreach_block (block, &ir->block_list) { |
| 1579 |
foreach_instr_safe (instr, &block->instr_list) { |
| 1580 |
struct ir3_builder build = ir3_builder_at(ir3_before_instr(instr)); |
| 1581 |
struct ir3_instruction *nop = ir3_NOP(&build); |
| 1582 |
nop->repeat = 5; |
| 1583 |
} |
| 1584 |
} |
| 1585 |
} |
| 1586 |
|
| 1587 |
static void |
| 1588 |
dbg_expand_rpt(struct ir3 *ir) |
| 1589 |
{ |
| 1590 |
foreach_block (block, &ir->block_list) { |
| 1591 |
foreach_instr_safe (instr, &block->instr_list) { |
| 1592 |
if (instr->repeat == 0 || instr->opc == OPC_NOP || |
| 1593 |
instr->opc == OPC_SWZ || instr->opc == OPC_GAT || |
| 1594 |
instr->opc == OPC_SCT) { |
| 1595 |
continue; |
| 1596 |
} |
| 1597 |
|
| 1598 |
for (unsigned i = 0; i <= instr->repeat; ++i) { |
| 1599 |
struct ir3_instruction *rpt = ir3_instr_clone(instr); |
| 1600 |
ir3_instr_move_before(rpt, instr); |
| 1601 |
rpt->repeat = 0; |
| 1602 |
|
| 1603 |
foreach_dst (dst, rpt) { |
| 1604 |
dst->num += i; |
| 1605 |
dst->wrmask = 1; |
| 1606 |
} |
| 1607 |
|
| 1608 |
foreach_src (src, rpt) { |
| 1609 |
if (!(src->flags & IR3_REG_R)) |
| 1610 |
continue; |
| 1611 |
|
| 1612 |
src->num += i; |
| 1613 |
src->uim_val += i; |
| 1614 |
src->wrmask = 1; |
| 1615 |
src->flags &= ~IR3_REG_R; |
| 1616 |
} |
| 1617 |
} |
| 1618 |
|
| 1619 |
list_delinit(&instr->node); |
| 1620 |
} |
| 1621 |
} |
| 1622 |
} |
| 1623 |
|
| 1624 |
struct ir3_mark_helpers_data { |
| 1625 |
bool valid; |
| 1626 |
regmask_t needs_helpers; |
| 1627 |
}; |
| 1628 |
|
| 1629 |
static void |
| 1630 |
instr_mark_helpers(struct ir3_mark_helpers_data *bd, |
| 1631 |
struct ir3_instruction *instr) |
| 1632 |
{ |
| 1633 |
if (instr->flags & IR3_INSTR_NEEDS_HELPERS) { |
| 1634 |
return; |
| 1635 |
} |
| 1636 |
|
| 1637 |
foreach_dst (dst, instr) { |
| 1638 |
if (dst->flags & (IR3_REG_RT | IR3_REG_DUMMY)) { |
| 1639 |
continue; |
| 1640 |
} |
| 1641 |
|
| 1642 |
if (regmask_get(&bd->needs_helpers, dst)) { |
| 1643 |
instr->flags |= IR3_INSTR_NEEDS_HELPERS; |
| 1644 |
return; |
| 1645 |
} |
| 1646 |
} |
| 1647 |
|
| 1648 |
switch (instr->opc) { |
| 1649 |
case OPC_MOVMSK: |
| 1650 |
case OPC_BRCST_ACTIVE: |
| 1651 |
case OPC_QUAD_SHUFFLE_BRCST: |
| 1652 |
case OPC_QUAD_SHUFFLE_HORIZ: |
| 1653 |
case OPC_QUAD_SHUFFLE_VERT: |
| 1654 |
case OPC_QUAD_SHUFFLE_DIAG: |
| 1655 |
case OPC_BALL: |
| 1656 |
case OPC_BANY: |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
instr->flags |= IR3_INSTR_NEEDS_HELPERS; |
| 1661 |
return; |
| 1662 |
|
| 1663 |
case OPC_SAM: |
| 1664 |
case OPC_SAMB: |
| 1665 |
case OPC_GETLOD: |
| 1666 |
case OPC_DSX: |
| 1667 |
case OPC_DSY: |
| 1668 |
case OPC_DSXPP_1: |
| 1669 |
case OPC_DSYPP_1: { |
| 1670 |
if (instr->opc == OPC_SAM && has_dummy_dst(instr)) { |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
return; |
| 1675 |
} |
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
unsigned nsrcs; |
| 1683 |
unsigned first_src_n = 0; |
| 1684 |
|
| 1685 |
if (instr->opc == OPC_SAM || instr->opc == OPC_SAMB || |
| 1686 |
instr->opc == OPC_GETLOD) { |
| 1687 |
nsrcs = (instr->flags & IR3_INSTR_3D) ? 3 : 2; |
| 1688 |
|
| 1689 |
|
| 1690 |
if (instr->flags & IR3_INSTR_S2EN) { |
| 1691 |
if (instr->srcs[0]->flags & IR3_REG_FIRST_ALIAS) { |
| 1692 |
assert(ir3_alias_group_size(instr, 0) == 2); |
| 1693 |
first_src_n = 2; |
| 1694 |
} else { |
| 1695 |
first_src_n = 1; |
| 1696 |
} |
| 1697 |
} |
| 1698 |
} else { |
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
nsrcs = util_last_bit(instr->dsts[0]->wrmask); |
| 1703 |
} |
| 1704 |
|
| 1705 |
if (instr->srcs[first_src_n]->flags & IR3_REG_FIRST_ALIAS) { |
| 1706 |
assert(first_src_n + nsrcs <= instr->srcs_count); |
| 1707 |
|
| 1708 |
for (unsigned i = first_src_n; i < first_src_n + nsrcs; i++) { |
| 1709 |
struct ir3_register *src = instr->srcs[i]; |
| 1710 |
|
| 1711 |
if (is_reg_gpr(src)) { |
| 1712 |
regmask_set(&bd->needs_helpers, src); |
| 1713 |
} |
| 1714 |
} |
| 1715 |
} else { |
| 1716 |
regmask_set_masked(&bd->needs_helpers, instr->srcs[first_src_n], |
| 1717 |
MASK(nsrcs)); |
| 1718 |
} |
| 1719 |
|
| 1720 |
break; |
| 1721 |
} |
| 1722 |
|
| 1723 |
default: |
| 1724 |
break; |
| 1725 |
} |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
static bool |
| 1739 |
mark_helpers(struct ir3_legalize_ctx *ctx, struct ir3 *ir, |
| 1740 |
struct ir3_shader_variant *so) |
| 1741 |
{ |
| 1742 |
foreach_block (block, &ir->block_list) { |
| 1743 |
struct ir3_mark_helpers_data *bd = |
| 1744 |
ralloc(ctx, struct ir3_mark_helpers_data); |
| 1745 |
bd->valid = false; |
| 1746 |
regmask_init(&bd->needs_helpers, ctx->compiler->mergedregs); |
| 1747 |
block->data = bd; |
| 1748 |
} |
| 1749 |
|
| 1750 |
bool uses_helpers = false; |
| 1751 |
bool progress; |
| 1752 |
|
| 1753 |
do { |
| 1754 |
progress = false; |
| 1755 |
|
| 1756 |
foreach_block_rev (block, &ir->block_list) { |
| 1757 |
struct ir3_mark_helpers_data *bd = block->data; |
| 1758 |
|
| 1759 |
if (bd->valid) { |
| 1760 |
continue; |
| 1761 |
} |
| 1762 |
|
| 1763 |
struct ir3_mark_helpers_data prev_bd = *bd; |
| 1764 |
regmask_init(&bd->needs_helpers, ctx->compiler->mergedregs); |
| 1765 |
bool may_have_needs_helpers_at_entry = true; |
| 1766 |
|
| 1767 |
for (unsigned i = 0; i < ARRAY_SIZE(block->successors); i++) { |
| 1768 |
struct ir3_block *succ = block->successors[i]; |
| 1769 |
if (!succ) { |
| 1770 |
continue; |
| 1771 |
} |
| 1772 |
|
| 1773 |
struct ir3_mark_helpers_data *succ_bd = succ->data; |
| 1774 |
regmask_or(&bd->needs_helpers, &bd->needs_helpers, |
| 1775 |
&succ_bd->needs_helpers); |
| 1776 |
} |
| 1777 |
|
| 1778 |
foreach_instr_rev (instr, &block->instr_list) { |
| 1779 |
instr_mark_helpers(bd, instr); |
| 1780 |
|
| 1781 |
|
| 1782 |
if (instr->flags & IR3_INSTR_NEEDS_HELPERS) { |
| 1783 |
uses_helpers = true; |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
regmask_init(&bd->needs_helpers, ctx->compiler->mergedregs); |
| 1790 |
may_have_needs_helpers_at_entry = false; |
| 1791 |
break; |
| 1792 |
} |
| 1793 |
} |
| 1794 |
|
| 1795 |
bd->valid = true; |
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
if (may_have_needs_helpers_at_entry && |
| 1806 |
memcmp(&prev_bd.needs_helpers, &bd->needs_helpers, |
| 1807 |
sizeof(prev_bd.needs_helpers)) != 0) { |
| 1808 |
progress = true; |
| 1809 |
|
| 1810 |
for (unsigned i = 0; i < block->predecessors_count; i++) { |
| 1811 |
struct ir3_mark_helpers_data *pred_bd = |
| 1812 |
block->predecessors[i]->data; |
| 1813 |
pred_bd->valid = false; |
| 1814 |
} |
| 1815 |
} |
| 1816 |
} |
| 1817 |
} while (progress); |
| 1818 |
|
| 1819 |
struct ir3_block *start_block = ir3_start_block(ir); |
| 1820 |
struct ir3_mark_helpers_data *start_bd = start_block->data; |
| 1821 |
|
| 1822 |
foreach_input (input, ir) { |
| 1823 |
if (regmask_get(&start_bd->needs_helpers, input->dsts[0])) { |
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
struct ir3_instruction *first = ir3_block_get_first_instr(start_block); |
| 1829 |
first->flags |= IR3_INSTR_NEEDS_HELPERS; |
| 1830 |
uses_helpers = true; |
| 1831 |
break; |
| 1832 |
} |
| 1833 |
} |
| 1834 |
|
| 1835 |
return uses_helpers; |
| 1836 |
} |
| 1837 |
|
| 1838 |
struct ir3_end_of_feature_block_data { |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
bool uses_feature_beginning; |
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
bool uses_feature_end; |
| 1850 |
}; |
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
static bool |
| 1863 |
feature_usage_sched(struct ir3_legalize_ctx *ctx, struct ir3 *ir, |
| 1864 |
struct ir3_shader_variant *so, |
| 1865 |
bool (*check_instr)(struct ir3_instruction *), |
| 1866 |
bool (*cheap_instr)(struct ir3_instruction *), |
| 1867 |
uint32_t new_flag) |
| 1868 |
{ |
| 1869 |
bool uses_feature = false; |
| 1870 |
|
| 1871 |
foreach_block (block, &ir->block_list) { |
| 1872 |
struct ir3_end_of_feature_block_data *bd = |
| 1873 |
rzalloc(ctx, struct ir3_end_of_feature_block_data); |
| 1874 |
foreach_instr (instr, &block->instr_list) { |
| 1875 |
if (check_instr(instr)) { |
| 1876 |
uses_feature = true; |
| 1877 |
bd->uses_feature_beginning = true; |
| 1878 |
|
| 1879 |
if (is_terminator(instr)) { |
| 1880 |
bd->uses_feature_end = true; |
| 1881 |
} |
| 1882 |
} |
| 1883 |
|
| 1884 |
if (instr->opc == OPC_SHPE) { |
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
bd->uses_feature_beginning = true; |
| 1889 |
bd->uses_feature_end = true; |
| 1890 |
} |
| 1891 |
} |
| 1892 |
|
| 1893 |
block->data = bd; |
| 1894 |
} |
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
if (!uses_feature) |
| 1902 |
return false; |
| 1903 |
|
| 1904 |
bool progress; |
| 1905 |
do { |
| 1906 |
progress = false; |
| 1907 |
foreach_block_rev (block, &ir->block_list) { |
| 1908 |
struct ir3_end_of_feature_block_data *bd = block->data; |
| 1909 |
|
| 1910 |
if (!bd->uses_feature_beginning) |
| 1911 |
continue; |
| 1912 |
|
| 1913 |
for (unsigned i = 0; i < block->physical_predecessors_count; i++) { |
| 1914 |
struct ir3_block *pred = block->physical_predecessors[i]; |
| 1915 |
struct ir3_end_of_feature_block_data *pred_bd = pred->data; |
| 1916 |
if (!pred_bd->uses_feature_end) { |
| 1917 |
pred_bd->uses_feature_end = true; |
| 1918 |
} |
| 1919 |
if (!pred_bd->uses_feature_beginning) { |
| 1920 |
pred_bd->uses_feature_beginning = true; |
| 1921 |
progress = true; |
| 1922 |
} |
| 1923 |
} |
| 1924 |
} |
| 1925 |
} while (progress); |
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
foreach_block (block, &ir->block_list) { |
| 1931 |
struct ir3_end_of_feature_block_data *bd = block->data; |
| 1932 |
if (bd->uses_feature_end) |
| 1933 |
continue; |
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
bool pred_uses_feature = bd->uses_feature_beginning; |
| 1981 |
for (unsigned i = 0; i < block->physical_predecessors_count; i++) { |
| 1982 |
struct ir3_block *pred = block->physical_predecessors[i]; |
| 1983 |
struct ir3_end_of_feature_block_data *pred_bd = pred->data; |
| 1984 |
if (pred_bd->uses_feature_end) { |
| 1985 |
pred_uses_feature = true; |
| 1986 |
break; |
| 1987 |
} |
| 1988 |
} |
| 1989 |
|
| 1990 |
if (!pred_uses_feature) |
| 1991 |
continue; |
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
struct ir3_instruction *first_instr = NULL; |
| 1998 |
foreach_instr_rev (instr, &block->instr_list) { |
| 1999 |
if (check_instr(instr)) |
| 2000 |
break; |
| 2001 |
first_instr = instr; |
| 2002 |
} |
| 2003 |
|
| 2004 |
bool killed = false; |
| 2005 |
bool expensive_instruction_in_block = false; |
| 2006 |
if (first_instr) { |
| 2007 |
foreach_instr_from (instr, first_instr, &block->instr_list) { |
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
if (instr->opc == OPC_NOP) { |
| 2012 |
instr->flags |= new_flag; |
| 2013 |
killed = true; |
| 2014 |
break; |
| 2015 |
} |
| 2016 |
|
| 2017 |
if (cheap_instr(instr)) |
| 2018 |
continue; |
| 2019 |
if (instr->opc == OPC_PREDE) |
| 2020 |
continue; |
| 2021 |
|
| 2022 |
expensive_instruction_in_block = true; |
| 2023 |
break; |
| 2024 |
} |
| 2025 |
} |
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
if (!killed && (expensive_instruction_in_block || |
| 2032 |
block->successors[0] != ir3_end_block(ir))) { |
| 2033 |
struct ir3_cursor cursor = first_instr ? ir3_before_instr(first_instr) |
| 2034 |
: ir3_before_terminator(block); |
| 2035 |
struct ir3_builder build = ir3_builder_at(cursor); |
| 2036 |
struct ir3_instruction *nop = ir3_NOP(&build); |
| 2037 |
nop->flags |= new_flag; |
| 2038 |
} |
| 2039 |
} |
| 2040 |
|
| 2041 |
return true; |
| 2042 |
} |
| 2043 |
|
| 2044 |
static bool |
| 2045 |
uses_helpers(struct ir3_instruction *instr) |
| 2046 |
{ |
| 2047 |
return !!(instr->flags & IR3_INSTR_NEEDS_HELPERS); |
| 2048 |
} |
| 2049 |
|
| 2050 |
static bool |
| 2051 |
is_cheap_for_eq(struct ir3_instruction *instr) |
| 2052 |
{ |
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
return is_alu(instr) || is_sfu(instr); |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
static void |
| 2069 |
helper_sched(struct ir3_legalize_ctx *ctx, struct ir3 *ir, |
| 2070 |
struct ir3_shader_variant *so) |
| 2071 |
{ |
| 2072 |
if (!feature_usage_sched(ctx, ir, so, uses_helpers, is_cheap_for_eq, |
| 2073 |
IR3_INSTR_EQ) && |
| 2074 |
so->num_sampler_prefetch) { |
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
so->prefetch_end_of_quad = true; |
| 2079 |
} |
| 2080 |
} |
| 2081 |
|
| 2082 |
static bool |
| 2083 |
needs_eolm(struct ir3_instruction *instr) |
| 2084 |
{ |
| 2085 |
switch (instr->opc) { |
| 2086 |
case OPC_STL: |
| 2087 |
case OPC_LDL: |
| 2088 |
case OPC_STLW: |
| 2089 |
case OPC_LDLW: |
| 2090 |
case OPC_ATOMIC_ADD: |
| 2091 |
case OPC_ATOMIC_SUB: |
| 2092 |
case OPC_ATOMIC_XCHG: |
| 2093 |
case OPC_ATOMIC_INC: |
| 2094 |
case OPC_ATOMIC_DEC: |
| 2095 |
case OPC_ATOMIC_CMPXCHG: |
| 2096 |
case OPC_ATOMIC_MIN: |
| 2097 |
case OPC_ATOMIC_MAX: |
| 2098 |
case OPC_ATOMIC_AND: |
| 2099 |
case OPC_ATOMIC_OR: |
| 2100 |
case OPC_ATOMIC_XOR: |
| 2101 |
return true; |
| 2102 |
default: |
| 2103 |
return false; |
| 2104 |
} |
| 2105 |
} |
| 2106 |
|
| 2107 |
static bool |
| 2108 |
needs_eogm(struct ir3_instruction *instr) |
| 2109 |
{ |
| 2110 |
return opc_cat(instr->opc) == 5 || opc_cat(instr->opc) == 6; |
| 2111 |
} |
| 2112 |
|
| 2113 |
static bool |
| 2114 |
is_cheap_for_eolm_eogm(struct ir3_instruction *instr) |
| 2115 |
{ |
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
return false; |
| 2120 |
} |
| 2121 |
|
| 2122 |
struct ir3_last_block_data { |
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
regmask_t will_read; |
| 2128 |
}; |
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
static void |
| 2135 |
track_last(struct ir3_legalize_ctx *ctx, struct ir3 *ir, |
| 2136 |
struct ir3_shader_variant *so) |
| 2137 |
{ |
| 2138 |
foreach_block (block, &ir->block_list) { |
| 2139 |
struct ir3_last_block_data *bd = rzalloc(ctx, struct ir3_last_block_data); |
| 2140 |
|
| 2141 |
regmask_init(&bd->will_read, so->mergedregs); |
| 2142 |
|
| 2143 |
block->data = bd; |
| 2144 |
} |
| 2145 |
|
| 2146 |
bool progress; |
| 2147 |
do { |
| 2148 |
progress = false; |
| 2149 |
regmask_t will_read; |
| 2150 |
regmask_init(&will_read, so->mergedregs); |
| 2151 |
|
| 2152 |
foreach_block_rev (block, &ir->block_list) { |
| 2153 |
struct ir3_last_block_data *bd = block->data; |
| 2154 |
|
| 2155 |
for (unsigned i = 0; i < ARRAY_SIZE(block->successors); i++) { |
| 2156 |
struct ir3_block *succ = block->successors[i]; |
| 2157 |
if (!succ) |
| 2158 |
continue; |
| 2159 |
|
| 2160 |
struct ir3_last_block_data *succ_bd = succ->data; |
| 2161 |
regmask_or(&will_read, &will_read, &succ_bd->will_read); |
| 2162 |
} |
| 2163 |
|
| 2164 |
foreach_instr_rev (instr, &block->instr_list) { |
| 2165 |
for (unsigned i = 0; i < instr->dsts_count; i++) { |
| 2166 |
struct ir3_register *dst = instr->dsts[i]; |
| 2167 |
if (dst->flags & (IR3_REG_IMMED | IR3_REG_CONST | |
| 2168 |
IR3_REG_SHARED | IR3_REG_RT)) { |
| 2169 |
continue; |
| 2170 |
} |
| 2171 |
|
| 2172 |
regmask_clear(&will_read, dst); |
| 2173 |
} |
| 2174 |
|
| 2175 |
for (unsigned i = 0; i < instr->srcs_count; i++) { |
| 2176 |
struct ir3_register *src = instr->srcs[i]; |
| 2177 |
if (src->flags & |
| 2178 |
(IR3_REG_IMMED | IR3_REG_CONST | IR3_REG_SHARED)) { |
| 2179 |
continue; |
| 2180 |
} |
| 2181 |
|
| 2182 |
if (!regmask_get(&will_read, src)) { |
| 2183 |
if (!(src->flags & IR3_REG_LAST_USE)) { |
| 2184 |
progress = true; |
| 2185 |
src->flags |= IR3_REG_LAST_USE; |
| 2186 |
} |
| 2187 |
} else if (src->flags & IR3_REG_LAST_USE) { |
| 2188 |
progress = true; |
| 2189 |
src->flags &= ~IR3_REG_LAST_USE; |
| 2190 |
} |
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
regmask_set(&will_read, src); |
| 2197 |
} |
| 2198 |
} |
| 2199 |
|
| 2200 |
bd->will_read = will_read; |
| 2201 |
} |
| 2202 |
} while (progress); |
| 2203 |
} |
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
struct nop_insert_point { |
| 2211 |
struct ir3_instruction *instr; |
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
unsigned max_nops; |
| 2222 |
}; |
| 2223 |
|
| 2224 |
struct alias_align_ctx { |
| 2225 |
DECLARE_ARRAY(struct nop_insert_point, nop_insert_points); |
| 2226 |
}; |
| 2227 |
|
| 2228 |
#define ICACHE_LINE_INSTRS 16 |
| 2229 |
|
| 2230 |
static unsigned |
| 2231 |
icache_line(unsigned ip) |
| 2232 |
{ |
| 2233 |
return ip / ICACHE_LINE_INSTRS; |
| 2234 |
} |
| 2235 |
|
| 2236 |
static uint8_t * |
| 2237 |
extra_nops(struct ir3_instruction *instr) |
| 2238 |
{ |
| 2239 |
if (instr->opc == OPC_NOP) { |
| 2240 |
return &instr->repeat; |
| 2241 |
} |
| 2242 |
|
| 2243 |
return &instr->nop; |
| 2244 |
} |
| 2245 |
|
| 2246 |
static bool |
| 2247 |
is_insert_point(struct ir3_instruction *instr) |
| 2248 |
{ |
| 2249 |
uint8_t *instr_extra_nops = extra_nops(instr); |
| 2250 |
return *instr_extra_nops != 0; |
| 2251 |
} |
| 2252 |
|
| 2253 |
static void |
| 2254 |
update_last_insert_point_max_nops(struct alias_align_ctx *ctx, |
| 2255 |
unsigned max_nops) |
| 2256 |
{ |
| 2257 |
if (max_nops == 0) { |
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
ctx->nop_insert_points_count = 0; |
| 2262 |
} else if (ctx->nop_insert_points_count != 0) { |
| 2263 |
struct nop_insert_point *last_nop_insert_point = |
| 2264 |
&ctx->nop_insert_points[ctx->nop_insert_points_count - 1]; |
| 2265 |
last_nop_insert_point->max_nops = |
| 2266 |
MIN2(last_nop_insert_point->max_nops, max_nops); |
| 2267 |
} |
| 2268 |
} |
| 2269 |
|
| 2270 |
static void |
| 2271 |
insert_nops(struct ir3_cursor cursor, unsigned n) |
| 2272 |
{ |
| 2273 |
struct ir3_builder b = ir3_builder_at(cursor); |
| 2274 |
|
| 2275 |
for (unsigned i = 0; i < n; i++) { |
| 2276 |
ir3_NOP(&b); |
| 2277 |
} |
| 2278 |
} |
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
static void |
| 2300 |
align_aliases(struct ir3 *ir) |
| 2301 |
{ |
| 2302 |
if (!ir->compiler->has_alias_tex) { |
| 2303 |
return; |
| 2304 |
} |
| 2305 |
|
| 2306 |
struct alias_align_ctx *ctx = rzalloc(ir, struct alias_align_ctx); |
| 2307 |
unsigned ip = 0; |
| 2308 |
|
| 2309 |
foreach_block (block, &ir->block_list) { |
| 2310 |
bool in_alias_sequence = false; |
| 2311 |
|
| 2312 |
foreach_instr (instr, &block->instr_list) { |
| 2313 |
if (instr->opc == OPC_META_TEX_PREFETCH) { |
| 2314 |
|
| 2315 |
continue; |
| 2316 |
} |
| 2317 |
|
| 2318 |
instr->ip = ip++; |
| 2319 |
|
| 2320 |
if (is_insert_point(instr)) { |
| 2321 |
struct nop_insert_point nop_insert_point = { |
| 2322 |
.instr = instr, |
| 2323 |
|
| 2324 |
|
| 2325 |
.max_nops = ~0, |
| 2326 |
}; |
| 2327 |
|
| 2328 |
array_insert(ctx, ctx->nop_insert_points, nop_insert_point); |
| 2329 |
continue; |
| 2330 |
} |
| 2331 |
|
| 2332 |
if (instr->opc != OPC_ALIAS || instr->cat7.alias_scope != ALIAS_TEX) { |
| 2333 |
in_alias_sequence = false; |
| 2334 |
continue; |
| 2335 |
} |
| 2336 |
|
| 2337 |
if (in_alias_sequence) { |
| 2338 |
|
| 2339 |
continue; |
| 2340 |
} |
| 2341 |
|
| 2342 |
in_alias_sequence = true; |
| 2343 |
unsigned num_aliases = instr->cat7.alias_table_size_minus_one + 1; |
| 2344 |
unsigned last_ip = instr->ip + num_aliases; |
| 2345 |
unsigned num_aliases_first_icache_line = |
| 2346 |
num_aliases - (last_ip % ICACHE_LINE_INSTRS); |
| 2347 |
|
| 2348 |
if (icache_line(instr->ip) != icache_line(last_ip)) { |
| 2349 |
unsigned nops_left = num_aliases_first_icache_line; |
| 2350 |
assert(nops_left > 0); |
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
unsigned max_nops = ~0; |
| 2357 |
|
| 2358 |
|
| 2359 |
for (unsigned i = ctx->nop_insert_points_count; i > 0; i--) { |
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
assert(i == ctx->nop_insert_points_count); |
| 2376 |
|
| 2377 |
struct nop_insert_point *nop_insert_point = |
| 2378 |
&ctx->nop_insert_points[i - 1]; |
| 2379 |
|
| 2380 |
max_nops = MIN2(max_nops, nop_insert_point->max_nops); |
| 2381 |
|
| 2382 |
uint8_t *instr_extra_nops = extra_nops(nop_insert_point->instr); |
| 2383 |
unsigned num_nops = MIN3(*instr_extra_nops, nops_left, max_nops); |
| 2384 |
assert(num_nops != 0); |
| 2385 |
|
| 2386 |
insert_nops(ir3_after_instr(nop_insert_point->instr), num_nops); |
| 2387 |
*instr_extra_nops -= num_nops; |
| 2388 |
nops_left -= num_nops; |
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
if (max_nops != ~0) { |
| 2398 |
max_nops -= num_nops; |
| 2399 |
nop_insert_point->max_nops = max_nops; |
| 2400 |
} |
| 2401 |
|
| 2402 |
if (max_nops == 0) { |
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
ctx->nop_insert_points_count = 0; |
| 2407 |
break; |
| 2408 |
} |
| 2409 |
|
| 2410 |
if (*instr_extra_nops == 0) { |
| 2411 |
|
| 2412 |
ctx->nop_insert_points_count--; |
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
update_last_insert_point_max_nops(ctx, max_nops); |
| 2418 |
} else { |
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
assert(nops_left == 0); |
| 2423 |
} |
| 2424 |
|
| 2425 |
if (nops_left == 0) { |
| 2426 |
|
| 2427 |
break; |
| 2428 |
} |
| 2429 |
} |
| 2430 |
|
| 2431 |
|
| 2432 |
insert_nops(ir3_before_instr(instr), nops_left); |
| 2433 |
|
| 2434 |
instr->ip += num_aliases_first_icache_line; |
| 2435 |
assert(util_is_aligned(instr->ip, ICACHE_LINE_INSTRS)); |
| 2436 |
|
| 2437 |
last_ip = instr->ip + num_aliases; |
| 2438 |
assert(icache_line(instr->ip) == icache_line(last_ip)); |
| 2439 |
|
| 2440 |
ip = instr->ip + 1; |
| 2441 |
} |
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
unsigned max_nops = |
| 2448 |
ICACHE_LINE_INSTRS - 1 - last_ip % ICACHE_LINE_INSTRS; |
| 2449 |
update_last_insert_point_max_nops(ctx, max_nops); |
| 2450 |
} |
| 2451 |
} |
| 2452 |
|
| 2453 |
ralloc_free(ctx); |
| 2454 |
} |
| 2455 |
|
| 2456 |
bool |
| 2457 |
ir3_legalize(struct ir3 *ir, struct ir3_shader_variant *so, int *max_bary) |
| 2458 |
{ |
| 2459 |
struct ir3_legalize_ctx *ctx = rzalloc(ir, struct ir3_legalize_ctx); |
| 2460 |
bool progress; |
| 2461 |
|
| 2462 |
ctx->so = so; |
| 2463 |
ctx->max_bary = -1; |
| 2464 |
ctx->compiler = ir->compiler; |
| 2465 |
ctx->type = ir->type; |
| 2466 |
|
| 2467 |
|
| 2468 |
foreach_block (block, &ir->block_list) { |
| 2469 |
struct ir3_legalize_block_data *bd = |
| 2470 |
rzalloc(ctx, struct ir3_legalize_block_data); |
| 2471 |
|
| 2472 |
ir3_init_legalize_state(&bd->state, so->compiler); |
| 2473 |
ir3_init_legalize_state(&bd->begin_state, so->compiler); |
| 2474 |
|
| 2475 |
block->data = bd; |
| 2476 |
} |
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
ctx->early_input_release = true; |
| 2484 |
|
| 2485 |
struct ir3_block *start_block = ir3_after_preamble(ir); |
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
bool gpr_in_preamble = false; |
| 2490 |
bool pred_in_preamble = false; |
| 2491 |
bool relative_in_preamble = false; |
| 2492 |
bool in_preamble = start_block != ir3_start_block(ir); |
| 2493 |
bool has_preamble = start_block != ir3_start_block(ir); |
| 2494 |
|
| 2495 |
foreach_block (block, &ir->block_list) { |
| 2496 |
if (block == start_block) |
| 2497 |
in_preamble = false; |
| 2498 |
|
| 2499 |
foreach_instr (instr, &block->instr_list) { |
| 2500 |
if (is_input(instr)) { |
| 2501 |
ctx->has_inputs = true; |
| 2502 |
if (block != start_block) { |
| 2503 |
ctx->early_input_release = false; |
| 2504 |
} |
| 2505 |
} |
| 2506 |
|
| 2507 |
if (is_meta(instr)) |
| 2508 |
continue; |
| 2509 |
|
| 2510 |
foreach_src (reg, instr) { |
| 2511 |
if (in_preamble) { |
| 2512 |
if (!(reg->flags & IR3_REG_SHARED) && is_reg_gpr(reg)) |
| 2513 |
gpr_in_preamble = true; |
| 2514 |
if (reg->flags & IR3_REG_RELATIV) |
| 2515 |
relative_in_preamble = true; |
| 2516 |
} |
| 2517 |
} |
| 2518 |
|
| 2519 |
foreach_dst (reg, instr) { |
| 2520 |
if (is_dest_gpr(reg)) { |
| 2521 |
if (in_preamble) { |
| 2522 |
if (!(reg->flags & IR3_REG_SHARED)) |
| 2523 |
gpr_in_preamble = true; |
| 2524 |
if (reg->flags & IR3_REG_RELATIV) |
| 2525 |
relative_in_preamble = true; |
| 2526 |
} |
| 2527 |
} |
| 2528 |
} |
| 2529 |
|
| 2530 |
if (in_preamble && writes_pred(instr) && |
| 2531 |
!(instr->dsts[0]->flags & IR3_REG_UNIFORM)) { |
| 2532 |
pred_in_preamble = true; |
| 2533 |
} |
| 2534 |
} |
| 2535 |
} |
| 2536 |
|
| 2537 |
so->early_preamble = has_preamble && !gpr_in_preamble && |
| 2538 |
!pred_in_preamble && !relative_in_preamble && |
| 2539 |
ir->compiler->info->props.has_early_preamble && |
| 2540 |
!(ir3_shader_debug & IR3_DBG_NOEARLYPREAMBLE); |
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
if (so->early_preamble && ir->compiler->gen >= 7) { |
| 2547 |
foreach_block (block, &ir->block_list) { |
| 2548 |
if (block == start_block) |
| 2549 |
break; |
| 2550 |
block->in_early_preamble = true; |
| 2551 |
} |
| 2552 |
} |
| 2553 |
|
| 2554 |
assert(ctx->early_input_release || ctx->compiler->gen >= 5); |
| 2555 |
|
| 2556 |
if (ir3_shader_debug & IR3_DBG_EXPANDRPT) { |
| 2557 |
dbg_expand_rpt(ir); |
| 2558 |
} |
| 2559 |
|
| 2560 |
|
| 2561 |
do { |
| 2562 |
progress = false; |
| 2563 |
foreach_block (block, &ir->block_list) { |
| 2564 |
progress |= legalize_block(ctx, block); |
| 2565 |
} |
| 2566 |
} while (progress); |
| 2567 |
|
| 2568 |
*max_bary = ctx->max_bary; |
| 2569 |
|
| 2570 |
foreach_block (block, &ir->block_list) { |
| 2571 |
struct ir3_instruction *terminator = ir3_block_get_terminator(block); |
| 2572 |
if (terminator && terminator->opc == OPC_GETONE) { |
| 2573 |
apply_push_consts_load_macro(ctx, block->successors[0]); |
| 2574 |
break; |
| 2575 |
} |
| 2576 |
} |
| 2577 |
|
| 2578 |
block_sched(ir); |
| 2579 |
|
| 2580 |
foreach_block (block, &ir->block_list) { |
| 2581 |
progress |= apply_fine_deriv_macro(ctx, block); |
| 2582 |
} |
| 2583 |
|
| 2584 |
bool cfg_changed = false; |
| 2585 |
while (opt_jump(ir)) |
| 2586 |
cfg_changed = true; |
| 2587 |
|
| 2588 |
prede_sched(ir); |
| 2589 |
|
| 2590 |
if (cfg_changed) |
| 2591 |
ir3_calc_reconvergence(so); |
| 2592 |
|
| 2593 |
if (so->type == MESA_SHADER_FRAGMENT) |
| 2594 |
kill_sched(ir, so); |
| 2595 |
|
| 2596 |
if ((so->type == MESA_SHADER_FRAGMENT || ir3_shader_compute(so)) && |
| 2597 |
so->compiler->info->props.has_eolm_eogm) { |
| 2598 |
feature_usage_sched(ctx, ir, so, needs_eolm, is_cheap_for_eolm_eogm, |
| 2599 |
IR3_INSTR_EOLM); |
| 2600 |
feature_usage_sched(ctx, ir, so, needs_eogm, is_cheap_for_eolm_eogm, |
| 2601 |
IR3_INSTR_EOGM); |
| 2602 |
} |
| 2603 |
|
| 2604 |
|
| 2605 |
if (so->type == MESA_SHADER_FRAGMENT && so->need_pixlod && |
| 2606 |
so->compiler->gen >= 6) { |
| 2607 |
if (mark_helpers(ctx, ir, so)) { |
| 2608 |
helper_sched(ctx, ir, so); |
| 2609 |
} else { |
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
so->prefetch_end_of_quad = true; |
| 2614 |
} |
| 2615 |
} |
| 2616 |
|
| 2617 |
if (ir3_shader_debug & IR3_DBG_FULLSYNC) { |
| 2618 |
dbg_sync_sched(ir, so); |
| 2619 |
} |
| 2620 |
|
| 2621 |
if (ir3_shader_debug & IR3_DBG_FULLNOP) { |
| 2622 |
dbg_nop_sched(ir, so); |
| 2623 |
} |
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
if (so->compiler->gen >= 7) |
| 2630 |
track_last(ctx, ir, so); |
| 2631 |
|
| 2632 |
ir3_insert_alias_tex(ir); |
| 2633 |
align_aliases(ir); |
| 2634 |
ir3_count_instructions(ir); |
| 2635 |
resolve_jumps(ir); |
| 2636 |
|
| 2637 |
mark_xvergence_points(ir); |
| 2638 |
|
| 2639 |
ralloc_free(ctx); |
| 2640 |
|
| 2641 |
return true; |
| 2642 |
} |