}
static bool
-block_has_no_side_effects(nir_block *block, void *state)
+cf_node_has_side_effects(nir_cf_node *node)
{
- (void) state;
+ nir_foreach_block_in_cf_node(block, node) {
+ nir_foreach_instr(block, instr) {
+ if (instr->type == nir_instr_type_call)
+ return true;
- nir_foreach_instr(block, instr) {
- if (instr->type == nir_instr_type_call)
- return false;
+ /* Return instructions can cause us to skip over other side-effecting
+ * instructions after the loop, so consider them to have side effects
+ * here.
+ */
- /* Return instructions can cause us to skip over other side-effecting
- * instructions after the loop, so consider them to have side effects
- * here.
- */
+ if (instr->type == nir_instr_type_jump &&
+ nir_instr_as_jump(instr)->type == nir_jump_return)
+ return true;
- if (instr->type == nir_instr_type_jump &&
- nir_instr_as_jump(instr)->type == nir_jump_return)
- return false;
-
- if (instr->type != nir_instr_type_intrinsic)
- continue;
+ if (instr->type != nir_instr_type_intrinsic)
+ continue;
- nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
- if (!nir_intrinsic_infos[intrin->intrinsic].flags &
- NIR_INTRINSIC_CAN_ELIMINATE)
- return false;
+ nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+ if (!nir_intrinsic_infos[intrin->intrinsic].flags &
+ NIR_INTRINSIC_CAN_ELIMINATE)
+ return true;
+ }
}
- return true;
+ return false;
}
static bool
nir_block_first_instr(after)->type == nir_instr_type_phi)
return false;
- if (!nir_foreach_block_in_cf_node_call(&loop->cf_node, block_has_no_side_effects,
- NULL))
+ if (cf_node_has_side_effects(&loop->cf_node))
return false;
nir_function_impl *impl = nir_cf_node_get_function(&loop->cf_node);