aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv/vtn_cfg.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2020-02-12 14:00:23 -0600
committerMarge Bot <[email protected]>2020-04-03 20:54:00 +0000
commit8c5c65d0d6a64a3bcc057e5cf61a94eda4b72f86 (patch)
tree609c7ce1b72d7764f9bc413f119acad68ad3186d /src/compiler/spirv/vtn_cfg.c
parent991c4261604b136cac0770c7d6c7345ea134129c (diff)
spirv: Add a vtn_block() helper
Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3820>
Diffstat (limited to 'src/compiler/spirv/vtn_cfg.c')
-rw-r--r--src/compiler/spirv/vtn_cfg.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 25e2f285e79..e07ccf70e30 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -24,6 +24,12 @@
#include "vtn_private.h"
#include "nir/nir_vla.h"
+static struct vtn_block *
+vtn_block(struct vtn_builder *b, uint32_t value_id)
+{
+ return vtn_value(b, value_id, vtn_value_type_block)->block;
+}
+
static struct vtn_pointer *
vtn_load_param_pointer(struct vtn_builder *b,
struct vtn_type *param_type,
@@ -394,8 +400,7 @@ vtn_add_case(struct vtn_builder *b, struct vtn_switch *swtch,
struct vtn_block *break_block,
uint32_t block_id, uint64_t val, bool is_default)
{
- struct vtn_block *case_block =
- vtn_value(b, block_id, vtn_value_type_block)->block;
+ struct vtn_block *case_block = vtn_block(b, block_id);
/* Don't create dummy cases that just break */
if (case_block == break_block)
@@ -496,10 +501,8 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
list_addtail(&loop->node.link, cf_list);
block->loop = loop;
- struct vtn_block *new_loop_break =
- vtn_value(b, block->merge[1], vtn_value_type_block)->block;
- struct vtn_block *new_loop_cont =
- vtn_value(b, block->merge[2], vtn_value_type_block)->block;
+ struct vtn_block *new_loop_break = vtn_block(b, block->merge[1]);
+ struct vtn_block *new_loop_cont = vtn_block(b, block->merge[2]);
/* Note: This recursive call will start with the current block as
* its start block. If we weren't careful, we would get here
@@ -542,8 +545,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
switch (*block->branch & SpvOpCodeMask) {
case SpvOpBranch: {
- struct vtn_block *branch_block =
- vtn_value(b, block->branch[1], vtn_value_type_block)->block;
+ struct vtn_block *branch_block = vtn_block(b, block->branch[1]);
block->branch_type = vtn_get_branch_type(b, branch_block,
switch_case, switch_break,
@@ -566,10 +568,8 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
return;
case SpvOpBranchConditional: {
- struct vtn_block *then_block =
- vtn_value(b, block->branch[2], vtn_value_type_block)->block;
- struct vtn_block *else_block =
- vtn_value(b, block->branch[3], vtn_value_type_block)->block;
+ struct vtn_block *then_block = vtn_block(b, block->branch[2]);
+ struct vtn_block *else_block = vtn_block(b, block->branch[3]);
struct vtn_if *if_stmt = ralloc(b, struct vtn_if);
@@ -606,8 +606,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
if_stmt->else_type == vtn_branch_type_none) {
/* Neither side of the if is something we can short-circuit. */
vtn_assert((*block->merge & SpvOpCodeMask) == SpvOpSelectionMerge);
- struct vtn_block *merge_block =
- vtn_value(b, block->merge[1], vtn_value_type_block)->block;
+ struct vtn_block *merge_block = vtn_block(b, block->merge[1]);
vtn_cfg_walk_blocks(b, &if_stmt->then_body, then_block,
switch_case, switch_break,
@@ -647,8 +646,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
case SpvOpSwitch: {
vtn_assert((*block->merge & SpvOpCodeMask) == SpvOpSelectionMerge);
- struct vtn_block *break_block =
- vtn_value(b, block->merge[1], vtn_value_type_block)->block;
+ struct vtn_block *break_block = vtn_block(b, block->merge[1]);
struct vtn_switch *swtch = ralloc(b, struct vtn_switch);
@@ -707,8 +705,7 @@ vtn_cfg_walk_blocks(struct vtn_builder *b, struct list_head *cf_list,
* them in fall-through order.
*/
for (const uint32_t *w = block->branch + 2; w < branch_end;) {
- struct vtn_block *case_block =
- vtn_value(b, *w, vtn_value_type_block)->block;
+ struct vtn_block *case_block = vtn_block(b, *w);
if (bitsize <= 32) {
w += 2;
@@ -808,8 +805,7 @@ vtn_handle_phi_second_pass(struct vtn_builder *b, SpvOp opcode,
nir_variable *phi_var = phi_entry->data;
for (unsigned i = 3; i < count; i += 2) {
- struct vtn_block *pred =
- vtn_value(b, w[i + 1], vtn_value_type_block)->block;
+ struct vtn_block *pred = vtn_block(b, w[i + 1]);
/* If block does not have end_nop, that is because it is an unreacheable
* block, and hence it is not worth to handle it */