From 9d7fcf1de04b69d8657671220265f8ec5e1cd274 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 12 Feb 2020 15:00:30 -0600 Subject: [PATCH] spirv: Add cast and loop helpers for vtn_cf_node Reviewed-by: Caio Marcelo de Oliveira Filho Part-of: --- src/compiler/spirv/vtn_cfg.c | 10 +++++----- src/compiler/spirv/vtn_private.h | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c index e07ccf70e30..107755d96ac 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -918,10 +918,10 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, nir_variable *switch_fall_var, bool *has_switch_break, vtn_instruction_handler handler) { - list_for_each_entry(struct vtn_cf_node, node, cf_list, link) { + vtn_foreach_cf_node(node, cf_list) { switch (node->type) { case vtn_cf_node_type_block: { - struct vtn_block *block = (struct vtn_block *)node; + struct vtn_block *block = vtn_cf_node_as_block(node); const uint32_t *block_start = block->label; const uint32_t *block_end = block->merge ? block->merge : @@ -959,7 +959,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, } case vtn_cf_node_type_if: { - struct vtn_if *vtn_if = (struct vtn_if *)node; + struct vtn_if *vtn_if = vtn_cf_node_as_if(node); bool sw_break = false; nir_if *nif = @@ -998,7 +998,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, } case vtn_cf_node_type_loop: { - struct vtn_loop *vtn_loop = (struct vtn_loop *)node; + struct vtn_loop *vtn_loop = vtn_cf_node_as_loop(node); nir_loop *loop = nir_push_loop(&b->nb); loop->control = vtn_loop_control(b, vtn_loop); @@ -1035,7 +1035,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, } case vtn_cf_node_type_switch: { - struct vtn_switch *vtn_switch = (struct vtn_switch *)node; + struct vtn_switch *vtn_switch = vtn_cf_node_as_switch(node); /* First, we create a variable to keep track of whether or not the * switch is still going at any given point. Any switch breaks diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 4b2d28978d9..a042afe4bbe 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -242,6 +242,22 @@ struct vtn_function { SpvFunctionControlMask control; }; +#define VTN_DECL_CF_NODE_CAST(_type) \ +static inline struct vtn_##_type * \ +vtn_cf_node_as_##_type(struct vtn_cf_node *node) \ +{ \ + assert(node->type == vtn_cf_node_type_##_type); \ + return (struct vtn_##_type *)node; \ +} + +VTN_DECL_CF_NODE_CAST(block) +VTN_DECL_CF_NODE_CAST(loop) +VTN_DECL_CF_NODE_CAST(if) +VTN_DECL_CF_NODE_CAST(switch) + +#define vtn_foreach_cf_node(node, cf_list) \ + list_for_each_entry(struct vtn_cf_node, node, cf_list, link) + typedef bool (*vtn_instruction_handler)(struct vtn_builder *, SpvOp, const uint32_t *, unsigned); -- 2.30.2