From bc2fbbafd216676ccc7c3abd794ecb7dd1fa631f Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Tue, 24 Jun 2014 12:42:00 -0700 Subject: i965: Add and use foreach_inst_in_block macros. Reviewed-by: Ian Romanick --- src/mesa/drivers/dri/i965/brw_cfg.h | 10 ++++++++++ src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp | 9 ++------- src/mesa/drivers/dri/i965/brw_fs_cse.cpp | 5 +---- src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp | 4 +--- src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp | 5 +---- src/mesa/drivers/dri/i965/brw_fs_saturate_propagation.cpp | 4 +--- src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp | 5 +---- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_cfg.h b/src/mesa/drivers/dri/i965/brw_cfg.h index 9466bd2fdd1..b55eacbec26 100644 --- a/src/mesa/drivers/dri/i965/brw_cfg.h +++ b/src/mesa/drivers/dri/i965/brw_cfg.h @@ -105,4 +105,14 @@ public: }; #endif +#define foreach_inst_in_block(__type, __inst, __block) \ + for (__type *__inst = (__type *)__block->start; \ + __inst != __block->end->next; \ + __inst = (__type *)__inst->next) + +#define foreach_inst_in_block_reverse(__type, __inst, __block) \ + for (__type *__inst = (__type *)__block->end; \ + __inst != __block->start->prev; \ + __inst = (__type *)__inst->prev) + #endif /* BRW_CFG_H */ diff --git a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp index 3c6e616d92a..184a2842093 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp @@ -157,9 +157,7 @@ fs_copy_prop_dataflow::setup_initial_values() for (int b = 0; b < cfg->num_blocks; b++) { bblock_t *block = cfg->blocks[b]; - for (fs_inst *inst = (fs_inst *)block->start; - inst != block->end->next; - inst = (fs_inst *)inst->next) { + foreach_inst_in_block(fs_inst, inst, block) { if (inst->dst.file != GRF) continue; @@ -532,10 +530,7 @@ fs_visitor::opt_copy_propagate_local(void *copy_prop_ctx, bblock_t *block, { bool progress = false; - for (fs_inst *inst = (fs_inst *)block->start; - inst != block->end->next; - inst = (fs_inst *)inst->next) { - + foreach_inst_in_block(fs_inst, inst, block) { /* Try propagating into this instruction. */ for (int i = 0; i < inst->sources; i++) { if (inst->src[i].file != GRF) diff --git a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp index 26873b8427d..e4068fc7087 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp @@ -173,10 +173,7 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb) void *cse_ctx = ralloc_context(NULL); int ip = block->start_ip; - for (fs_inst *inst = (fs_inst *)block->start; - inst != block->end->next; - inst = (fs_inst *) inst->next) { - + foreach_inst_in_block(fs_inst, inst, block) { /* Skip some cases. */ if (is_expression(inst) && !inst->is_partial_write() && (inst->dst.file != HW_REG || inst->dst.is_null())) diff --git a/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp b/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp index 962d8c6f414..3fefe81fa22 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_dead_code_eliminate.cpp @@ -51,9 +51,7 @@ fs_visitor::dead_code_eliminate() memcpy(live, live_intervals->bd[b].liveout, sizeof(BITSET_WORD) * BITSET_WORDS(num_vars)); - for (fs_inst *inst = (fs_inst *)block->end; - inst != block->start->prev; - inst = (fs_inst *)inst->prev) { + foreach_inst_in_block_reverse(fs_inst, inst, block) { if (inst->dst.file == GRF && !inst->has_side_effects() && !inst->writes_flag()) { diff --git a/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp b/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp index d39724a5ce3..0973dc9d83a 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp @@ -144,10 +144,7 @@ fs_live_variables::setup_def_use() if (b > 0) assert(cfg->blocks[b - 1]->end_ip == ip - 1); - for (fs_inst *inst = (fs_inst *)block->start; - inst != block->end->next; - inst = (fs_inst *)inst->next) { - + foreach_inst_in_block(fs_inst, inst, block) { /* Set use[] for this instruction */ for (unsigned int i = 0; i < inst->sources; i++) { fs_reg reg = inst->src[i]; diff --git a/src/mesa/drivers/dri/i965/brw_fs_saturate_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_saturate_propagation.cpp index 29c8b2ea318..079eb2eb795 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_saturate_propagation.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_saturate_propagation.cpp @@ -34,9 +34,7 @@ opt_saturate_propagation_local(fs_visitor *v, bblock_t *block) bool progress = false; int ip = block->start_ip - 1; - for (fs_inst *inst = (fs_inst *)block->start; - inst != block->end->next; - inst = (fs_inst *) inst->next) { + foreach_inst_in_block(fs_inst, inst, block) { ip++; if (inst->opcode != BRW_OPCODE_MOV || diff --git a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp index 7ffa5fe4f46..5f0b696bf1c 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp +++ b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp @@ -72,10 +72,7 @@ vec4_live_variables::setup_def_use() if (b > 0) assert(cfg->blocks[b - 1]->end_ip == ip - 1); - for (vec4_instruction *inst = (vec4_instruction *)block->start; - inst != block->end->next; - inst = (vec4_instruction *)inst->next) { - + foreach_inst_in_block(vec4_instruction, inst, block) { /* Set use[] for this instruction */ for (unsigned int i = 0; i < 3; i++) { if (inst->src[i].file == GRF) { -- cgit v1.2.3