}
bblock_t::bblock_t() :
- start_ip(0), end_ip(0), block_num(0)
+ start_ip(0), end_ip(0), num(0)
{
start = NULL;
end = NULL;
}
block->start_ip = ip;
- block->block_num = num_blocks++;
+ block->num = num_blocks++;
block_list.push_tail(&block->link);
*cur = block;
}
blocks = ralloc_array(mem_ctx, bblock_t *, num_blocks);
int i = 0;
- foreach_list_typed(bblock_t, block, link, &block_list) {
+ foreach_block (block, this) {
blocks[i++] = block;
}
assert(i == num_blocks);
void
cfg_t::dump(backend_visitor *v)
{
- for (int b = 0; b < this->num_blocks; b++) {
- bblock_t *block = this->blocks[b];
- fprintf(stderr, "START B%d", b);
+ foreach_block (block, this) {
+ fprintf(stderr, "START B%d", block->num);
foreach_list_typed(bblock_link, link, link, &block->parents) {
fprintf(stderr, " <-B%d",
- link->block->block_num);
+ link->block->num);
}
fprintf(stderr, "\n");
block->dump(v);
- fprintf(stderr, "END B%d", b);
+ fprintf(stderr, "END B%d", block->num);
foreach_list_typed(bblock_link, link, link, &block->children) {
fprintf(stderr, " ->B%d",
- link->block->block_num);
+ link->block->num);
}
fprintf(stderr, "\n");
}
struct exec_list parents;
struct exec_list children;
- int block_num;
+ int num;
/* If the current basic block ends in an IF, ELSE, or ENDIF instruction,
* these pointers will hold the locations of the other associated control
foreach_block (__block, __cfg) \
foreach_inst_in_block (__type, __inst, __block)
+#define foreach_block(__block, __cfg) \
+ foreach_list_typed (bblock_t, __block, link, &(__cfg)->block_list)
+
#define foreach_inst_in_block(__type, __inst, __block) \
for (__type *__inst = (__type *)__block->start; \
__inst != __block->end->next; \
v->calculate_cfg();
- for (int b = 0; b < v->cfg->num_blocks; b++) {
- bblock_t *block = v->cfg->blocks[b];
+ foreach_block (block, v->cfg) {
bool found = false;
/* ENDIF instructions, by definition, can only be found at the start of
bd = rzalloc_array(mem_ctx, struct block_data, cfg->num_blocks);
num_acp = 0;
- for (int b = 0; b < cfg->num_blocks; b++) {
+ foreach_block (block, cfg) {
for (int i = 0; i < ACP_HASH_SIZE; i++) {
- num_acp += out_acp[b][i].length();
+ num_acp += out_acp[block->num][i].length();
}
}
bitset_words = BITSET_WORDS(num_acp);
int next_acp = 0;
- for (int b = 0; b < cfg->num_blocks; b++) {
- bd[b].livein = rzalloc_array(bd, BITSET_WORD, bitset_words);
- bd[b].liveout = rzalloc_array(bd, BITSET_WORD, bitset_words);
- bd[b].copy = rzalloc_array(bd, BITSET_WORD, bitset_words);
- bd[b].kill = rzalloc_array(bd, BITSET_WORD, bitset_words);
+ foreach_block (block, cfg) {
+ bd[block->num].livein = rzalloc_array(bd, BITSET_WORD, bitset_words);
+ bd[block->num].liveout = rzalloc_array(bd, BITSET_WORD, bitset_words);
+ bd[block->num].copy = rzalloc_array(bd, BITSET_WORD, bitset_words);
+ bd[block->num].kill = rzalloc_array(bd, BITSET_WORD, bitset_words);
for (int i = 0; i < ACP_HASH_SIZE; i++) {
- foreach_in_list(acp_entry, entry, &out_acp[b][i]) {
+ foreach_in_list(acp_entry, entry, &out_acp[block->num][i]) {
acp[next_acp] = entry;
/* opt_copy_propagate_local populates out_acp with copies created
* in a block which are still live at the end of the block. This
* is exactly what we want in the COPY set.
*/
- BITSET_SET(bd[b].copy, next_acp);
+ BITSET_SET(bd[block->num].copy, next_acp);
next_acp++;
}
fs_copy_prop_dataflow::setup_initial_values()
{
/* Initialize the COPY and KILL sets. */
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
foreach_inst_in_block(fs_inst, inst, block) {
if (inst->dst.file != GRF)
continue;
for (int i = 0; i < num_acp; i++) {
if (inst->overwrites_reg(acp[i]->dst) ||
inst->overwrites_reg(acp[i]->src)) {
- BITSET_SET(bd[b].kill, i);
+ BITSET_SET(bd[block->num].kill, i);
}
}
}
* For the others, set liveout to 0 (the empty set) and livein to ~0
* (the universal set).
*/
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
+ foreach_block (block, cfg) {
if (block->parents.is_empty()) {
for (int i = 0; i < bitset_words; i++) {
- bd[b].livein[i] = 0u;
- bd[b].liveout[i] = bd[b].copy[i];
+ bd[block->num].livein[i] = 0u;
+ bd[block->num].liveout[i] = bd[block->num].copy[i];
}
} else {
for (int i = 0; i < bitset_words; i++) {
- bd[b].liveout[i] = 0u;
- bd[b].livein[i] = ~0u;
+ bd[block->num].liveout[i] = 0u;
+ bd[block->num].livein[i] = ~0u;
}
}
}
progress = false;
/* Update liveout for all blocks. */
- for (int b = 0; b < cfg->num_blocks; b++) {
- if (cfg->blocks[b]->parents.is_empty())
+ foreach_block (block, cfg) {
+ if (block->parents.is_empty())
continue;
for (int i = 0; i < bitset_words; i++) {
- const BITSET_WORD old_liveout = bd[b].liveout[i];
+ const BITSET_WORD old_liveout = bd[block->num].liveout[i];
- bd[b].liveout[i] =
- bd[b].copy[i] | (bd[b].livein[i] & ~bd[b].kill[i]);
+ bd[block->num].liveout[i] =
+ bd[block->num].copy[i] | (bd[block->num].livein[i] &
+ ~bd[block->num].kill[i]);
- if (old_liveout != bd[b].liveout[i])
+ if (old_liveout != bd[block->num].liveout[i])
progress = true;
}
}
/* Update livein for all blocks. If a copy is live out of all parent
* blocks, it's live coming in to this block.
*/
- for (int b = 0; b < cfg->num_blocks; b++) {
- if (cfg->blocks[b]->parents.is_empty())
+ foreach_block (block, cfg) {
+ if (block->parents.is_empty())
continue;
for (int i = 0; i < bitset_words; i++) {
- const BITSET_WORD old_livein = bd[b].livein[i];
+ const BITSET_WORD old_livein = bd[block->num].livein[i];
- bd[b].livein[i] = ~0u;
- foreach_list_typed(bblock_link, link, link, &cfg->blocks[b]->parents) {
- bblock_t *block = link->block;
- bd[b].livein[i] &= bd[block->block_num].liveout[i];
+ bd[block->num].livein[i] = ~0u;
+ foreach_list_typed(bblock_link, parent_link, link, &block->parents) {
+ bblock_t *parent = parent_link->block;
+ bd[block->num].livein[i] &= bd[parent->num].liveout[i];
}
- if (old_livein != bd[b].livein[i])
+ if (old_livein != bd[block->num].livein[i])
progress = true;
}
}
void
fs_copy_prop_dataflow::dump_block_data() const
{
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
- fprintf(stderr, "Block %d [%d, %d] (parents ", block->block_num,
+ foreach_block (block, cfg) {
+ fprintf(stderr, "Block %d [%d, %d] (parents ", block->num,
block->start_ip, block->end_ip);
foreach_list_typed(bblock_link, link, link, &block->parents) {
bblock_t *parent = link->block;
- fprintf(stderr, "%d ", parent->block_num);
+ fprintf(stderr, "%d ", parent->num);
}
fprintf(stderr, "):\n");
fprintf(stderr, " livein = 0x");
for (int i = 0; i < bitset_words; i++)
- fprintf(stderr, "%08x", bd[b].livein[i]);
+ fprintf(stderr, "%08x", bd[block->num].livein[i]);
fprintf(stderr, ", liveout = 0x");
for (int i = 0; i < bitset_words; i++)
- fprintf(stderr, "%08x", bd[b].liveout[i]);
+ fprintf(stderr, "%08x", bd[block->num].liveout[i]);
fprintf(stderr, ",\n copy = 0x");
for (int i = 0; i < bitset_words; i++)
- fprintf(stderr, "%08x", bd[b].copy[i]);
+ fprintf(stderr, "%08x", bd[block->num].copy[i]);
fprintf(stderr, ", kill = 0x");
for (int i = 0; i < bitset_words; i++)
- fprintf(stderr, "%08x", bd[b].kill[i]);
+ fprintf(stderr, "%08x", bd[block->num].kill[i]);
fprintf(stderr, "\n");
}
}
/* First, walk through each block doing local copy propagation and getting
* the set of copies available at the end of the block.
*/
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
progress = opt_copy_propagate_local(copy_prop_ctx, block,
- out_acp[b]) || progress;
+ out_acp[block->num]) || progress;
}
/* Do dataflow analysis for those available copies. */
/* Next, re-run local copy propagation, this time with the set of copies
* provided by the dataflow analysis available at the start of a block.
*/
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
+ foreach_block (block, cfg) {
exec_list in_acp[ACP_HASH_SIZE];
for (int i = 0; i < dataflow.num_acp; i++) {
- if (BITSET_TEST(dataflow.bd[b].livein, i)) {
+ if (BITSET_TEST(dataflow.bd[block->num].livein, i)) {
struct acp_entry *entry = dataflow.acp[i];
in_acp[entry->dst.reg % ACP_HASH_SIZE].push_tail(entry);
}
calculate_live_intervals();
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
progress = opt_cse_local(block) || progress;
}
int num_vars = live_intervals->num_vars;
BITSET_WORD *live = ralloc_array(NULL, BITSET_WORD, BITSET_WORDS(num_vars));
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
- memcpy(live, live_intervals->bd[b].liveout,
+ foreach_block (block, cfg) {
+ memcpy(live, live_intervals->bd[block->num].liveout,
sizeof(BITSET_WORD) * BITSET_WORDS(num_vars));
foreach_inst_in_block_reverse(fs_inst, inst, block) {
* channel) without having completely defined that variable within the
* block.
*/
- if (!BITSET_TEST(bd[block->block_num].def, var))
- BITSET_SET(bd[block->block_num].use, var);
+ if (!BITSET_TEST(bd[block->num].def, var))
+ BITSET_SET(bd[block->num].use, var);
}
void
* screens off previous updates of that variable (VGRF channel).
*/
if (inst->dst.file == GRF && !inst->is_partial_write()) {
- if (!BITSET_TEST(bd[block->block_num].use, var))
- BITSET_SET(bd[block->block_num].def, var);
+ if (!BITSET_TEST(bd[block->num].use, var))
+ BITSET_SET(bd[block->num].def, var);
}
}
{
int ip = 0;
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
assert(ip == block->start_ip);
- if (b > 0)
- assert(cfg->blocks[b - 1]->end_ip == ip - 1);
+ if (block->num > 0)
+ assert(cfg->blocks[block->num - 1]->end_ip == ip - 1);
foreach_inst_in_block(fs_inst, inst, block) {
/* Set use[] for this instruction */
while (cont) {
cont = false;
- for (int b = 0; b < cfg->num_blocks; b++) {
+ foreach_block (block, cfg) {
/* Update livein */
for (int i = 0; i < bitset_words; i++) {
- BITSET_WORD new_livein = (bd[b].use[i] |
- (bd[b].liveout[i] & ~bd[b].def[i]));
- if (new_livein & ~bd[b].livein[i]) {
- bd[b].livein[i] |= new_livein;
+ BITSET_WORD new_livein = (bd[block->num].use[i] |
+ (bd[block->num].liveout[i] &
+ ~bd[block->num].def[i]));
+ if (new_livein & ~bd[block->num].livein[i]) {
+ bd[block->num].livein[i] |= new_livein;
cont = true;
}
}
/* Update liveout */
- foreach_list_typed(bblock_link, link, link, &cfg->blocks[b]->children) {
- bblock_t *block = link->block;
+ foreach_list_typed(bblock_link, child_link, link, &block->children) {
+ bblock_t *child = child_link->block;
for (int i = 0; i < bitset_words; i++) {
- BITSET_WORD new_liveout = (bd[block->block_num].livein[i] &
- ~bd[b].liveout[i]);
+ BITSET_WORD new_liveout = (bd[child->num].livein[i] &
+ ~bd[block->num].liveout[i]);
if (new_liveout) {
- bd[b].liveout[i] |= new_liveout;
+ bd[block->num].liveout[i] |= new_liveout;
cont = true;
}
}
void
fs_live_variables::compute_start_end()
{
- for (int b = 0; b < cfg->num_blocks; b++) {
+ foreach_block (block, cfg) {
for (int i = 0; i < num_vars; i++) {
- if (BITSET_TEST(bd[b].livein, i)) {
- start[i] = MIN2(start[i], cfg->blocks[b]->start_ip);
- end[i] = MAX2(end[i], cfg->blocks[b]->start_ip);
+ if (BITSET_TEST(bd[block->num].livein, i)) {
+ start[i] = MIN2(start[i], block->start_ip);
+ end[i] = MAX2(end[i], block->start_ip);
}
- if (BITSET_TEST(bd[b].liveout, i)) {
- start[i] = MIN2(start[i], cfg->blocks[b]->end_ip);
- end[i] = MAX2(end[i], cfg->blocks[b]->end_ip);
+ if (BITSET_TEST(bd[block->num].liveout, i)) {
+ start[i] = MIN2(start[i], block->end_ip);
+ end[i] = MAX2(end[i], block->end_ip);
}
}
calculate_cfg();
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
/* BREAK and CONTINUE instructions, by definition, can only be found at
* the ends of basic blocks.
*/
if_inst->remove();
endif_inst->remove();
- /* By removing the ENDIF instruction we removed a basic block. Skip over
- * it for the next iteration.
- */
- b++;
-
progress = true;
}
calculate_live_intervals();
- for (int b = 0; b < cfg->num_blocks; b++) {
- progress = opt_saturate_propagation_local(this, cfg->blocks[b])
- || progress;
+ foreach_block (block, cfg) {
+ progress = opt_saturate_propagation_local(this, block) || progress;
}
if (progress)
calculate_cfg();
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
/* IF instructions, by definition, can only be found at the ends of
* basic blocks.
*/
assert(prog_data->total_grf ||
!"Must be called after register allocation");
- for (int i = 0; i < cfg->num_blocks; i++) {
- bblock_t *bblock = cfg->blocks[i];
-
+ foreach_block (block, cfg) {
memset(last_grf_write, 0, sizeof(last_grf_write));
memset(last_mrf_write, 0, sizeof(last_mrf_write));
- foreach_inst_in_block (vec4_instruction, inst, bblock) {
+ foreach_inst_in_block (vec4_instruction, inst, block) {
/* If we read from a register that we were doing dependency control
* on, don't do dependency control across the read.
*/
calculate_live_intervals();
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
progress = opt_cse_local(block) || progress;
}
{
int ip = 0;
- for (int b = 0; b < cfg->num_blocks; b++) {
- bblock_t *block = cfg->blocks[b];
-
+ foreach_block (block, cfg) {
assert(ip == block->start_ip);
- if (b > 0)
- assert(cfg->blocks[b - 1]->end_ip == ip - 1);
+ if (block->num > 0)
+ assert(cfg->blocks[block->num - 1]->end_ip == ip - 1);
foreach_inst_in_block(vec4_instruction, inst, block) {
/* Set use[] for this instruction */
for (int j = 0; j < 4; j++) {
int c = BRW_GET_SWZ(inst->src[i].swizzle, j);
- if (!BITSET_TEST(bd[b].def, reg * 4 + c))
- BITSET_SET(bd[b].use, reg * 4 + c);
+ if (!BITSET_TEST(bd[block->num].def, reg * 4 + c))
+ BITSET_SET(bd[block->num].use, reg * 4 + c);
}
}
}
for (int c = 0; c < 4; c++) {
if (inst->dst.writemask & (1 << c)) {
int reg = inst->dst.reg;
- if (!BITSET_TEST(bd[b].use, reg * 4 + c))
- BITSET_SET(bd[b].def, reg * 4 + c);
+ if (!BITSET_TEST(bd[block->num].use, reg * 4 + c))
+ BITSET_SET(bd[block->num].def, reg * 4 + c);
}
}
}
while (cont) {
cont = false;
- for (int b = 0; b < cfg->num_blocks; b++) {
+ foreach_block (block, cfg) {
/* Update livein */
for (int i = 0; i < bitset_words; i++) {
- BITSET_WORD new_livein = (bd[b].use[i] |
- (bd[b].liveout[i] & ~bd[b].def[i]));
- if (new_livein & ~bd[b].livein[i]) {
- bd[b].livein[i] |= new_livein;
+ BITSET_WORD new_livein = (bd[block->num].use[i] |
+ (bd[block->num].liveout[i] &
+ ~bd[block->num].def[i]));
+ if (new_livein & ~bd[block->num].livein[i]) {
+ bd[block->num].livein[i] |= new_livein;
cont = true;
}
}
/* Update liveout */
- foreach_list_typed(bblock_link, link, link, &cfg->blocks[b]->children) {
- bblock_t *block = link->block;
+ foreach_list_typed(bblock_link, child_link, link, &block->children) {
+ bblock_t *child = child_link->block;
for (int i = 0; i < bitset_words; i++) {
- BITSET_WORD new_liveout = (bd[block->block_num].livein[i] &
- ~bd[b].liveout[i]);
+ BITSET_WORD new_liveout = (bd[child->num].livein[i] &
+ ~bd[block->num].liveout[i]);
if (new_liveout) {
- bd[b].liveout[i] |= new_liveout;
+ bd[block->num].liveout[i] |= new_liveout;
cont = true;
}
}
calculate_cfg();
vec4_live_variables livevars(this, cfg);
- for (int b = 0; b < cfg->num_blocks; b++) {
+ foreach_block (block, cfg) {
for (int i = 0; i < livevars.num_vars; i++) {
- if (BITSET_TEST(livevars.bd[b].livein, i)) {
- start[i] = MIN2(start[i], cfg->blocks[b]->start_ip);
- end[i] = MAX2(end[i], cfg->blocks[b]->start_ip);
+ if (BITSET_TEST(livevars.bd[block->num].livein, i)) {
+ start[i] = MIN2(start[i], block->start_ip);
+ end[i] = MAX2(end[i], block->start_ip);
}
- if (BITSET_TEST(livevars.bd[b].liveout, i)) {
- start[i] = MIN2(start[i], cfg->blocks[b]->end_ip);
- end[i] = MAX2(end[i], cfg->blocks[b]->end_ip);
+ if (BITSET_TEST(livevars.bd[block->num].liveout, i)) {
+ start[i] = MIN2(start[i], block->end_ip);
+ end[i] = MAX2(end[i], block->end_ip);
}
}
}
int end_offset = annotation[i + 1].offset;
if (annotation[i].block_start) {
- fprintf(stderr, " START B%d", annotation[i].block_start->block_num);
+ fprintf(stderr, " START B%d", annotation[i].block_start->num);
foreach_list_typed(struct bblock_link, predecessor_link, link,
&annotation[i].block_start->parents) {
struct bblock_t *predecessor_block = predecessor_link->block;
- fprintf(stderr, " <-B%d", predecessor_block->block_num);
+ fprintf(stderr, " <-B%d", predecessor_block->num);
}
fprintf(stderr, "\n");
}
brw_disassemble(brw, assembly, start_offset, end_offset, stderr);
if (annotation[i].block_end) {
- fprintf(stderr, " END B%d", annotation[i].block_end->block_num);
+ fprintf(stderr, " END B%d", annotation[i].block_end->num);
foreach_list_typed(struct bblock_link, successor_link, link,
&annotation[i].block_end->children) {
struct bblock_t *successor_block = successor_link->block;
- fprintf(stderr, " ->B%d", successor_block->block_num);
+ fprintf(stderr, " ->B%d", successor_block->num);
}
fprintf(stderr, "\n");
}