spirv: Make vtn_case a vtn_cf_node

Cherry-pick'd from 255aacbec14c2d11d7756ec94b95244165120ff6

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3820>
Change-Id: I6d095387e07bea82329011708dd1b44eaca262ba
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/403194
Reviewed-by: John Bauman <jbauman@google.com>
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 700caf8..f3c9010 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -413,6 +413,7 @@
    if (case_block->switch_case == NULL) {
       struct vtn_case *c = ralloc(b, struct vtn_case);
 
+      c->node.type = vtn_cf_node_type_case;
       list_inithead(&c->body);
       c->start_block = case_block;
       c->fallthrough = NULL;
@@ -420,7 +421,7 @@
       c->is_default = false;
       c->visited = false;
 
-      list_addtail(&c->link, &swtch->cases);
+      list_addtail(&c->node.link, &swtch->cases);
 
       case_block->switch_case = c;
    }
@@ -443,7 +444,7 @@
 
    cse->visited = true;
 
-   list_del(&cse->link);
+   list_del(&cse->node.link);
 
    if (cse->fallthrough) {
       vtn_order_case(swtch, cse->fallthrough);
@@ -455,9 +456,9 @@
        * can't break ordering because the DFS ensures that this case is
        * visited before anything that falls through to it.
        */
-      list_addtail(&cse->link, &cse->fallthrough->link);
+      list_addtail(&cse->node.link, &cse->fallthrough->node.link);
    } else {
-      list_add(&cse->link, &swtch->cases);
+      list_add(&cse->node.link, &swtch->cases);
    }
 }
 
@@ -699,7 +700,8 @@
           * the blocks, we also gather the much-needed fall-through
           * information.
           */
-         list_for_each_entry(struct vtn_case, cse, &swtch->cases, link) {
+         vtn_foreach_cf_node(case_node, &swtch->cases) {
+            struct vtn_case *cse = vtn_cf_node_as_case(case_node);
             vtn_assert(cse->start_block != break_block);
             vtn_cfg_walk_blocks(b, &cse->body, cse->start_block, cse,
                                 break_block, loop_break, loop_cont, NULL);
@@ -863,7 +865,8 @@
 {
    if (cse->is_default) {
       nir_ssa_def *any = nir_imm_false(&b->nb);
-      list_for_each_entry(struct vtn_case, other, &swtch->cases, link) {
+      vtn_foreach_cf_node(other_node, &swtch->cases) {
+         struct vtn_case *other = vtn_cf_node_as_case(other_node);
          if (other->is_default)
             continue;
 
@@ -1052,7 +1055,9 @@
          nir_ssa_def *sel = vtn_ssa_value(b, vtn_switch->selector)->def;
 
          /* Now we can walk the list of cases and actually emit code */
-         list_for_each_entry(struct vtn_case, cse, &vtn_switch->cases, link) {
+         vtn_foreach_cf_node(case_node, &vtn_switch->cases) {
+            struct vtn_case *cse = vtn_cf_node_as_case(case_node);
+
             /* Figure out the condition */
             nir_ssa_def *cond =
                vtn_switch_case_condition(b, vtn_switch, sel, cse);
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index a042afe..1c84a2c 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -135,6 +135,7 @@
    vtn_cf_node_type_block,
    vtn_cf_node_type_if,
    vtn_cf_node_type_loop,
+   vtn_cf_node_type_case,
    vtn_cf_node_type_switch,
 };
 
@@ -172,7 +173,7 @@
 };
 
 struct vtn_case {
-   struct list_head link;
+   struct vtn_cf_node node;
 
    struct list_head body;
 
@@ -253,6 +254,7 @@
 VTN_DECL_CF_NODE_CAST(block)
 VTN_DECL_CF_NODE_CAST(loop)
 VTN_DECL_CF_NODE_CAST(if)
+VTN_DECL_CF_NODE_CAST(case)
 VTN_DECL_CF_NODE_CAST(switch)
 
 #define vtn_foreach_cf_node(node, cf_list) \