i965: Add and use functions to get next/prev blocks.

Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
This commit is contained in:
Matt Turner 2014-09-02 21:07:51 -07:00
parent 444fc0b4a8
commit ef75f60822
6 changed files with 73 additions and 20 deletions

View File

@ -66,6 +66,11 @@ struct bblock_t {
const backend_instruction *start() const; const backend_instruction *start() const;
backend_instruction *end(); backend_instruction *end();
const backend_instruction *end() const; const backend_instruction *end() const;
bblock_t *next();
const bblock_t *next() const;
bblock_t *prev();
const bblock_t *prev() const;
#endif #endif
struct exec_node link; 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); 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 #ifdef __cplusplus
inline backend_instruction * inline backend_instruction *
bblock_t::start() bblock_t::start()
@ -136,6 +165,30 @@ bblock_t::end() const
{ {
return bblock_end_const(this); 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 #endif
struct cfg_t { struct cfg_t {

View File

@ -52,20 +52,20 @@ dead_control_flow_eliminate(backend_visitor *v)
continue; continue;
backend_instruction *if_inst = NULL, *else_inst = NULL; 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) { if (prev_inst->opcode == BRW_OPCODE_ELSE) {
else_inst = prev_inst; else_inst = prev_inst;
else_block = (bblock_t *)endif_block->link.prev; else_block = endif_block->prev();
found = true; found = true;
if (else_block->start_ip == else_block->end_ip) 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 (prev_inst->opcode == BRW_OPCODE_IF) {
if_inst = prev_inst; if_inst = prev_inst;
if_block = else_block != NULL ? (bblock_t *)else_block->link.prev if_block = else_block != NULL ? else_block->prev()
: (bblock_t *)endif_block->link.prev; : endif_block->prev();
found = true; found = true;
} else { } else {
/* Don't remove the ENDIF if we didn't find a dead IF. */ /* 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_inst) {
if (if_block->start_ip == if_block->end_ip) { if (if_block->start_ip == if_block->end_ip) {
earlier_block = (bblock_t *)if_block->link.prev; earlier_block = if_block->prev();
} else { } else {
earlier_block = if_block; earlier_block = if_block;
} }
@ -91,7 +91,7 @@ dead_control_flow_eliminate(backend_visitor *v)
if (endif_inst) { if (endif_inst) {
if (endif_block->start_ip == endif_block->end_ip) { if (endif_block->start_ip == endif_block->end_ip) {
later_block = (bblock_t *)endif_block->link.next; later_block = endif_block->next();
} else { } else {
later_block = endif_block; later_block = endif_block;
} }
@ -114,7 +114,7 @@ dead_control_flow_eliminate(backend_visitor *v)
* __next block pointer was pointing to. * __next block pointer was pointing to.
*/ */
if (endif_block != later_block) { if (endif_block != later_block) {
__next = (bblock_t *)earlier_block->link.next; __next = earlier_block->next();
} }
} }

View File

@ -57,17 +57,17 @@ fs_visitor::opt_peephole_predicated_break()
jump_inst->opcode != BRW_OPCODE_CONTINUE) jump_inst->opcode != BRW_OPCODE_CONTINUE)
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) if (if_inst->opcode != BRW_OPCODE_IF)
continue; 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) if (endif_inst->opcode != BRW_OPCODE_ENDIF)
continue; continue;
bblock_t *jump_block = block; bblock_t *jump_block = block;
bblock_t *if_block = (bblock_t *)jump_block->link.prev; bblock_t *if_block = jump_block->prev();
bblock_t *endif_block = (bblock_t *)jump_block->link.next; bblock_t *endif_block = jump_block->next();
/* For Sandybridge with IF with embedded comparison we need to emit an /* For Sandybridge with IF with embedded comparison we need to emit an
* instruction to set the flag register. * instruction to set the flag register.
@ -84,14 +84,14 @@ fs_visitor::opt_peephole_predicated_break()
bblock_t *earlier_block = if_block; bblock_t *earlier_block = if_block;
if (if_block->start_ip == if_block->end_ip) { 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); if_inst->remove(if_block);
bblock_t *later_block = endif_block; bblock_t *later_block = endif_block;
if (endif_block->start_ip == endif_block->end_ip) { 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); endif_inst->remove(endif_block);

View File

@ -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 /* Skip the first block, since we don't want to count the do the calling
* function found. * function found.
*/ */
for (block = (bblock_t *)block->link.next; for (block = block->next();
depth > 0; depth > 0;
block = (bblock_t *)block->link.next) { block = block->next()) {
if (block->start()->opcode == BRW_OPCODE_DO) if (block->start()->opcode == BRW_OPCODE_DO)
depth++; depth++;
if (block->end()->opcode == BRW_OPCODE_WHILE) { if (block->end()->opcode == BRW_OPCODE_WHILE) {

View File

@ -140,8 +140,8 @@ fs_visitor::opt_peephole_sel()
fs_inst *else_mov[MAX_MOVS] = { NULL }; fs_inst *else_mov[MAX_MOVS] = { NULL };
fs_inst *then_mov[MAX_MOVS] = { NULL }; fs_inst *then_mov[MAX_MOVS] = { NULL };
bblock_t *then_block = (bblock_t *)block->link.next; bblock_t *then_block = block->next();
bblock_t *else_block = (bblock_t *)block->else_block->link.next; bblock_t *else_block = block->else_block->next();
int movs = count_movs_from_if(then_mov, else_mov, then_block, else_block); int movs = count_movs_from_if(then_mov, else_mov, then_block, else_block);

View File

@ -761,9 +761,9 @@ inst_is_in_block(const bblock_t *block, const backend_instruction *inst)
static void static void
adjust_later_block_ips(bblock_t *start_block, int ip_adjustment) 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->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->start_ip += ip_adjustment;
block_iter->end_ip += ip_adjustment; block_iter->end_ip += ip_adjustment;
} }