#define foreach_block_safe(__block, __cfg) \
foreach_list_typed_safe (bblock_t, __block, link, &(__cfg)->block_list)
+#define foreach_block_reverse_safe(__block, __cfg) \
+ foreach_list_typed_reverse_safe (bblock_t, __block, link, &(__cfg)->block_list)
+
#define foreach_inst_in_block(__type, __inst, __block) \
foreach_in_list(__type, __inst, &(__block)->instructions)
BITSET_WORD *live = ralloc_array(NULL, BITSET_WORD, BITSET_WORDS(num_vars));
BITSET_WORD *flag_live = ralloc_array(NULL, BITSET_WORD, 1);
- foreach_block (block, cfg) {
+ foreach_block_reverse_safe(block, cfg) {
memcpy(live, live_intervals->block_data[block->num].liveout,
sizeof(BITSET_WORD) * BITSET_WORDS(num_vars));
memcpy(flag_live, live_intervals->block_data[block->num].flag_liveout,
sizeof(BITSET_WORD));
- foreach_inst_in_block_reverse(fs_inst, inst, block) {
+ foreach_inst_in_block_reverse_safe(fs_inst, inst, block) {
if (inst->dst.file == VGRF && !inst->has_side_effects()) {
bool result_live = false;
inst->dst = fs_reg(retype(brw_null_reg(), inst->dst.type));
} else {
inst->opcode = BRW_OPCODE_NOP;
- continue;
}
}
}
if (!BITSET_TEST(flag_live, inst->flag_subreg)) {
inst->opcode = BRW_OPCODE_NOP;
progress = true;
- continue;
}
}
!inst->writes_accumulator) {
inst->opcode = BRW_OPCODE_NOP;
progress = true;
- continue;
}
if (inst->dst.file == VGRF) {
BITSET_CLEAR(flag_live, inst->flag_subreg);
}
- /* Don't mark dead instructions' sources as live */
- if (inst->opcode == BRW_OPCODE_NOP)
+ if (inst->opcode == BRW_OPCODE_NOP) {
+ inst->remove(block);
continue;
+ }
for (int i = 0; i < inst->sources; i++) {
if (inst->src[i].file == VGRF) {
ralloc_free(live);
ralloc_free(flag_live);
- if (progress) {
- foreach_block_and_inst_safe (block, backend_instruction, inst, cfg) {
- if (inst->opcode == BRW_OPCODE_NOP) {
- inst->remove(block);
- }
- }
-
+ if (progress)
invalidate_live_intervals();
- }
return progress;
}
BITSET_WORD *live = ralloc_array(NULL, BITSET_WORD, BITSET_WORDS(num_vars));
BITSET_WORD *flag_live = ralloc_array(NULL, BITSET_WORD, 1);
- foreach_block(block, cfg) {
+ foreach_block_reverse_safe(block, cfg) {
memcpy(live, live_intervals->block_data[block->num].liveout,
sizeof(BITSET_WORD) * BITSET_WORDS(num_vars));
memcpy(flag_live, live_intervals->block_data[block->num].flag_liveout,
sizeof(BITSET_WORD));
- foreach_inst_in_block_reverse(vec4_instruction, inst, block) {
+ foreach_inst_in_block_reverse_safe(vec4_instruction, inst, block) {
if ((inst->dst.file == VGRF && !inst->has_side_effects()) ||
(inst->dst.is_null() && inst->writes_flag())){
bool result_live[4] = { false };
inst->dst = dst_reg(retype(brw_null_reg(), inst->dst.type));
} else {
inst->opcode = BRW_OPCODE_NOP;
- continue;
+ break;
}
}
}
if (!combined_live) {
inst->opcode = BRW_OPCODE_NOP;
progress = true;
- continue;
}
}
BITSET_CLEAR(flag_live, c);
}
- /* Don't mark dead instructions' sources as live */
- if (inst->opcode == BRW_OPCODE_NOP)
+ if (inst->opcode == BRW_OPCODE_NOP) {
+ inst->remove(block);
continue;
+ }
for (int i = 0; i < 3; i++) {
if (inst->src[i].file == VGRF) {
ralloc_free(live);
ralloc_free(flag_live);
- if (progress) {
- foreach_block_and_inst_safe(block, backend_instruction, inst, cfg) {
- if (inst->opcode == BRW_OPCODE_NOP) {
- inst->remove(block);
- }
- }
-
+ if (progress)
invalidate_live_intervals();
- }
return progress;
}