From ef75f60822b71a5ac1715f0e3d9b04b9f7e9020f Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Tue, 2 Sep 2014 21:07:51 -0700 Subject: i965: Add and use functions to get next/prev blocks. Reviewed-by: Topi Pohjolainen --- src/mesa/drivers/dri/i965/brw_cfg.h | 53 ++++++++++++++++++++++ .../drivers/dri/i965/brw_dead_control_flow.cpp | 16 +++---- .../dri/i965/brw_fs_peephole_predicated_break.cpp | 12 ++--- src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp | 4 +- src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp | 4 +- src/mesa/drivers/dri/i965/brw_shader.cpp | 4 +- 6 files changed, 73 insertions(+), 20 deletions(-) (limited to 'src/mesa/drivers/dri/i965') diff --git a/src/mesa/drivers/dri/i965/brw_cfg.h b/src/mesa/drivers/dri/i965/brw_cfg.h index a8b20af11ff..c06ed61a79f 100644 --- a/src/mesa/drivers/dri/i965/brw_cfg.h +++ b/src/mesa/drivers/dri/i965/brw_cfg.h @@ -66,6 +66,11 @@ struct bblock_t { const backend_instruction *start() const; backend_instruction *end(); const backend_instruction *end() const; + + bblock_t *next(); + const bblock_t *next() const; + bblock_t *prev(); + const bblock_t *prev() const; #endif struct exec_node link; @@ -112,6 +117,30 @@ bblock_end_const(const struct bblock_t *block) return (const struct backend_instruction *)exec_list_get_tail_const(&block->instructions); } +static inline struct bblock_t * +bblock_next(struct bblock_t *block) +{ + return (struct bblock_t *)block->link.next; +} + +static inline const struct bblock_t * +bblock_next_const(const struct bblock_t *block) +{ + return (const struct bblock_t *)block->link.next; +} + +static inline struct bblock_t * +bblock_prev(struct bblock_t *block) +{ + return (struct bblock_t *)block->link.prev; +} + +static inline const struct bblock_t * +bblock_prev_const(const struct bblock_t *block) +{ + return (const struct bblock_t *)block->link.prev; +} + #ifdef __cplusplus inline backend_instruction * bblock_t::start() @@ -136,6 +165,30 @@ bblock_t::end() const { return bblock_end_const(this); } + +inline bblock_t * +bblock_t::next() +{ + return bblock_next(this); +} + +inline const bblock_t * +bblock_t::next() const +{ + return bblock_next_const(this); +} + +inline bblock_t * +bblock_t::prev() +{ + return bblock_prev(this); +} + +inline const bblock_t * +bblock_t::prev() const +{ + return bblock_prev_const(this); +} #endif struct cfg_t { diff --git a/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp b/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp index 557c3ad7506..4c9d7b95db8 100644 --- a/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp +++ b/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp @@ -52,20 +52,20 @@ dead_control_flow_eliminate(backend_visitor *v) continue; backend_instruction *if_inst = NULL, *else_inst = NULL; - backend_instruction *prev_inst = ((bblock_t *)endif_block->link.prev)->end(); + backend_instruction *prev_inst = endif_block->prev()->end(); if (prev_inst->opcode == BRW_OPCODE_ELSE) { else_inst = prev_inst; - else_block = (bblock_t *)endif_block->link.prev; + else_block = endif_block->prev(); found = true; if (else_block->start_ip == else_block->end_ip) - prev_inst = ((bblock_t *)else_block->link.prev)->end(); + prev_inst = else_block->prev()->end(); } if (prev_inst->opcode == BRW_OPCODE_IF) { if_inst = prev_inst; - if_block = else_block != NULL ? (bblock_t *)else_block->link.prev - : (bblock_t *)endif_block->link.prev; + if_block = else_block != NULL ? else_block->prev() + : endif_block->prev(); found = true; } else { /* Don't remove the ENDIF if we didn't find a dead IF. */ @@ -77,7 +77,7 @@ dead_control_flow_eliminate(backend_visitor *v) if (if_inst) { if (if_block->start_ip == if_block->end_ip) { - earlier_block = (bblock_t *)if_block->link.prev; + earlier_block = if_block->prev(); } else { earlier_block = if_block; } @@ -91,7 +91,7 @@ dead_control_flow_eliminate(backend_visitor *v) if (endif_inst) { if (endif_block->start_ip == endif_block->end_ip) { - later_block = (bblock_t *)endif_block->link.next; + later_block = endif_block->next(); } else { later_block = endif_block; } @@ -114,7 +114,7 @@ dead_control_flow_eliminate(backend_visitor *v) * __next block pointer was pointing to. */ if (endif_block != later_block) { - __next = (bblock_t *)earlier_block->link.next; + __next = earlier_block->next(); } } diff --git a/src/mesa/drivers/dri/i965/brw_fs_peephole_predicated_break.cpp b/src/mesa/drivers/dri/i965/brw_fs_peephole_predicated_break.cpp index 802b8de54b2..31b287aae36 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_peephole_predicated_break.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_peephole_predicated_break.cpp @@ -57,17 +57,17 @@ fs_visitor::opt_peephole_predicated_break() jump_inst->opcode != BRW_OPCODE_CONTINUE) continue; - fs_inst *if_inst = (fs_inst *)((bblock_t *)block->link.prev)->end(); + fs_inst *if_inst = (fs_inst *)block->prev()->end(); if (if_inst->opcode != BRW_OPCODE_IF) continue; - fs_inst *endif_inst = (fs_inst *)((bblock_t *)block->link.next)->start(); + fs_inst *endif_inst = (fs_inst *)block->next()->start(); if (endif_inst->opcode != BRW_OPCODE_ENDIF) continue; bblock_t *jump_block = block; - bblock_t *if_block = (bblock_t *)jump_block->link.prev; - bblock_t *endif_block = (bblock_t *)jump_block->link.next; + bblock_t *if_block = jump_block->prev(); + bblock_t *endif_block = jump_block->next(); /* For Sandybridge with IF with embedded comparison we need to emit an * instruction to set the flag register. @@ -84,14 +84,14 @@ fs_visitor::opt_peephole_predicated_break() bblock_t *earlier_block = if_block; if (if_block->start_ip == if_block->end_ip) { - earlier_block = (bblock_t *)if_block->link.prev; + earlier_block = if_block->prev(); } if_inst->remove(if_block); bblock_t *later_block = endif_block; if (endif_block->start_ip == endif_block->end_ip) { - later_block = (bblock_t *)endif_block->link.next; + later_block = endif_block->next(); } endif_inst->remove(endif_block); diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp index e03fc6950aa..33829d253e7 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp @@ -200,9 +200,9 @@ count_to_loop_end(const bblock_t *block) /* Skip the first block, since we don't want to count the do the calling * function found. */ - for (block = (bblock_t *)block->link.next; + for (block = block->next(); depth > 0; - block = (bblock_t *)block->link.next) { + block = block->next()) { if (block->start()->opcode == BRW_OPCODE_DO) depth++; if (block->end()->opcode == BRW_OPCODE_WHILE) { diff --git a/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp b/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp index 2941d65b021..c3bfd00e70d 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_sel_peephole.cpp @@ -140,8 +140,8 @@ fs_visitor::opt_peephole_sel() fs_inst *else_mov[MAX_MOVS] = { NULL }; fs_inst *then_mov[MAX_MOVS] = { NULL }; - bblock_t *then_block = (bblock_t *)block->link.next; - bblock_t *else_block = (bblock_t *)block->else_block->link.next; + bblock_t *then_block = block->next(); + bblock_t *else_block = block->else_block->next(); int movs = count_movs_from_if(then_mov, else_mov, then_block, else_block); diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp index 5f7a55c2f14..92089dbf8a7 100644 --- a/src/mesa/drivers/dri/i965/brw_shader.cpp +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp @@ -761,9 +761,9 @@ inst_is_in_block(const bblock_t *block, const backend_instruction *inst) static void adjust_later_block_ips(bblock_t *start_block, int ip_adjustment) { - for (bblock_t *block_iter = (bblock_t *)start_block->link.next; + for (bblock_t *block_iter = start_block->next(); !block_iter->link.is_tail_sentinel(); - block_iter = (bblock_t *)block_iter->link.next) { + block_iter = block_iter->next()) { block_iter->start_ip += ip_adjustment; block_iter->end_ip += ip_adjustment; } -- cgit v1.2.3