From d7e482d32cf0188a1ed49e76f008837be5cfd720 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 29 Oct 2014 16:25:51 -0700 Subject: nir: Add a function to detect if a block is immediately followed by an if Since we don't actually have an "if" instruction, this is a very common pattern when iterating over instructions. This adds a helper function for it to make things a little less painful. Reviewed-by: Connor Abbott --- src/glsl/nir/nir.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/glsl/nir/nir.c') diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c index 25844dc1b40..3c3afef165a 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -1692,6 +1692,23 @@ nir_foreach_block_reverse(nir_function_impl *impl, nir_foreach_block_cb cb, return true; } +nir_if * +nir_block_following_if(nir_block *block) +{ + if (exec_node_is_tail_sentinel(&block->cf_node.node)) + return NULL; + + if (nir_cf_node_is_last(&block->cf_node)) + return NULL; + + nir_cf_node *next_node = nir_cf_node_next(&block->cf_node); + + if (next_node->type != nir_cf_node_if) + return NULL; + + return nir_cf_node_as_if(next_node); +} + static bool index_block(nir_block *block, void *state) { -- cgit v1.2.3