i965/cfg: Embed exec_node in bblock_link.
authorMatt Turner <mattst88@gmail.com>
Mon, 12 May 2014 21:40:40 +0000 (14:40 -0700)
committerMatt Turner <mattst88@gmail.com>
Thu, 15 May 2014 22:45:40 +0000 (15:45 -0700)
In order to remove bblock_link's inheritance of exec_node. Also makes
linked list walk code much nicer.

Acked-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_cfg.cpp
src/mesa/drivers/dri/i965/brw_cfg.h
src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp
src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp

index 53281c6faa0dfa0aa2d372dd5662e926748917e1..a806714c20306214e1346b7c0b83ae2344ca5206 100644 (file)
@@ -38,11 +38,18 @@ pop_stack(exec_list *list)
 {
    bblock_link *link = (bblock_link *)list->get_tail();
    bblock_t *block = link->block;
-   link->remove();
+   link->link.remove();
 
    return block;
 }
 
+static exec_node *
+link(void *mem_ctx, bblock_t *block)
+{
+   bblock_link *l = new(mem_ctx) bblock_link(block);
+   return &l->link;
+}
+
 bblock_t::bblock_t() :
    start_ip(0), end_ip(0), block_num(0)
 {
@@ -60,8 +67,8 @@ bblock_t::bblock_t() :
 void
 bblock_t::add_successor(void *mem_ctx, bblock_t *successor)
 {
-   successor->parents.push_tail(new(mem_ctx) bblock_link(this));
-   children.push_tail(new(mem_ctx) bblock_link(successor));
+   successor->parents.push_tail(link(mem_ctx, this));
+   children.push_tail(link(mem_ctx, successor));
 }
 
 void
@@ -113,8 +120,8 @@ cfg_t::cfg_t(exec_list *instructions)
         /* Push our information onto a stack so we can recover from
          * nested ifs.
          */
-        if_stack.push_tail(new(mem_ctx) bblock_link(cur_if));
-        else_stack.push_tail(new(mem_ctx) bblock_link(cur_else));
+        if_stack.push_tail(link(mem_ctx, cur_if));
+        else_stack.push_tail(link(mem_ctx, cur_else));
 
         cur_if = cur;
         cur_else = NULL;
@@ -190,8 +197,8 @@ cfg_t::cfg_t(exec_list *instructions)
         /* Push our information onto a stack so we can recover from
          * nested loops.
          */
-        do_stack.push_tail(new(mem_ctx) bblock_link(cur_do));
-        while_stack.push_tail(new(mem_ctx) bblock_link(cur_while));
+        do_stack.push_tail(link(mem_ctx, cur_do));
+        while_stack.push_tail(link(mem_ctx, cur_while));
 
         /* Set up the block just after the while.  Don't know when exactly
          * it will start, yet.
@@ -275,7 +282,7 @@ cfg_t::set_next_block(bblock_t **cur, bblock_t *block, int ip)
 
    block->start_ip = ip;
    block->block_num = num_blocks++;
-   block_list.push_tail(new(mem_ctx) bblock_link(block));
+   block_list.push_tail(link(mem_ctx, block));
    *cur = block;
 }
 
@@ -285,8 +292,7 @@ cfg_t::make_block_array()
    blocks = ralloc_array(mem_ctx, bblock_t *, num_blocks);
 
    int i = 0;
-   foreach_list(block_node, &block_list) {
-      bblock_link *link = (bblock_link *)block_node;
+   foreach_list_typed(bblock_link, link, link, &block_list) {
       blocks[i++] = link->block;
    }
    assert(i == num_blocks);
@@ -298,16 +304,14 @@ 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_list(node, &block->parents) {
-         bblock_link *link = (bblock_link *)node;
+      foreach_list_typed(bblock_link, link, link, &block->parents) {
          fprintf(stderr, " <-B%d",
                  link->block->block_num);
       }
       fprintf(stderr, "\n");
       block->dump(v);
       fprintf(stderr, "END B%d", b);
-      foreach_list(node, &block->children) {
-         bblock_link *link = (bblock_link *)node;
+      foreach_list_typed(bblock_link, link, link, &block->children) {
          fprintf(stderr, " ->B%d",
                  link->block->block_num);
       }
index 0a88d25d664b8dcea03f3a4f0cd23c9a8b58162b..9466bd2fdd1e1490219f8867001c09005f179278 100644 (file)
@@ -33,7 +33,7 @@
 
 struct bblock_t;
 
-struct bblock_link : public exec_node {
+struct bblock_link {
 #ifdef __cplusplus
    DECLARE_RALLOC_CXX_OPERATORS(bblock_link)
 
@@ -43,6 +43,7 @@ struct bblock_link : public exec_node {
    }
 #endif
 
+   struct exec_node link;
    struct bblock_t *block;
 };
 
index a148c5473b7a803fd139150e92c4bf6525e98a4a..069b60fe22a8d4dfb90b58a2be9e1e6ea02ff90a 100644 (file)
@@ -232,8 +232,7 @@ fs_copy_prop_dataflow::run()
             const BITSET_WORD old_livein = bd[b].livein[i];
 
             bd[b].livein[i] = ~0u;
-            foreach_list(block_node, &cfg->blocks[b]->parents) {
-               bblock_link *link = (bblock_link *)block_node;
+            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];
             }
@@ -252,8 +251,8 @@ fs_copy_prop_dataflow::dump_block_data() const
       bblock_t *block = cfg->blocks[b];
       fprintf(stderr, "Block %d [%d, %d] (parents ", block->block_num,
              block->start_ip, block->end_ip);
-      foreach_list(block_node, &block->parents) {
-         bblock_t *parent = ((bblock_link *) block_node)->block;
+      foreach_list_typed(bblock_link, link, link, &block->parents) {
+         bblock_t *parent = link->block;
          fprintf(stderr, "%d ", parent->block_num);
       }
       fprintf(stderr, "):\n");
index 7969b67a567d8c1546e3e2ba6f3005592366b77b..a3ccf9931a77053652112414da21e9e633635951 100644 (file)
@@ -201,8 +201,7 @@ fs_live_variables::compute_live_variables()
         }
 
         /* Update liveout */
-        foreach_list(block_node, &cfg->blocks[b]->children) {
-           bblock_link *link = (bblock_link *)block_node;
+        foreach_list_typed(bblock_link, link, link, &cfg->blocks[b]->children) {
            bblock_t *block = link->block;
 
            for (int i = 0; i < bitset_words; i++) {
index cdbffc9ff39fbc4eb37e4ab11de1877eff17b560..7ffa5fe4f464d45b45961ab7718520e3b3cd40f4 100644 (file)
@@ -136,8 +136,7 @@ vec4_live_variables::compute_live_variables()
         }
 
         /* Update liveout */
-        foreach_list(block_node, &cfg->blocks[b]->children) {
-           bblock_link *link = (bblock_link *)block_node;
+        foreach_list_typed(bblock_link, link, link, &cfg->blocks[b]->children) {
            bblock_t *block = link->block;
 
            for (int i = 0; i < bitset_words; i++) {