From: Jason Ekstrand Date: Fri, 19 Oct 2018 14:35:49 +0000 (-0500) Subject: nir/builder: Add a nir_imm_true/false helpers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ff45649bc2fc3b048a8ae19cd67ec1e8e8eeb7a8;p=mesa.git nir/builder: Add a nir_imm_true/false helpers Reviewed-by: Ian Romanick Reviewed-by: Eric Anholt --- diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 398fa68c251..5ea0a5a2637 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -205,6 +205,29 @@ nir_build_imm(nir_builder *build, unsigned num_components, return &load_const->def; } +static inline nir_ssa_def * +nir_imm_bool(nir_builder *build, bool x) +{ + nir_const_value v; + + memset(&v, 0, sizeof(v)); + v.u32[0] = x ? NIR_TRUE : NIR_FALSE; + + return nir_build_imm(build, 1, 32, v); +} + +static inline nir_ssa_def * +nir_imm_true(nir_builder *build) +{ + return nir_imm_bool(build, true); +} + +static inline nir_ssa_def * +nir_imm_false(nir_builder *build) +{ + return nir_imm_bool(build, false); +} + static inline nir_ssa_def * nir_imm_float(nir_builder *build, float x) { @@ -489,7 +512,7 @@ nir_bany_inequal(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1) static inline nir_ssa_def * nir_bany(nir_builder *b, nir_ssa_def *src) { - return nir_bany_inequal(b, src, nir_imm_int(b, 0)); + return nir_bany_inequal(b, src, nir_imm_false(b)); } static inline nir_ssa_def * diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c index 0d7f165b406..50acc858605 100644 --- a/src/compiler/nir/nir_lower_int64.c +++ b/src/compiler/nir/nir_lower_int64.c @@ -86,7 +86,7 @@ lower_udiv64_mod64(nir_builder *b, nir_ssa_def *n, nir_ssa_def *d, * this is always true within the if statement. */ if (n->num_components == 1) - need_high_div = nir_imm_int(b, NIR_TRUE); + need_high_div = nir_imm_true(b); nir_ssa_def *log2_d_lo = nir_ufind_msb(b, d_lo); diff --git a/src/compiler/nir/nir_lower_returns.c b/src/compiler/nir/nir_lower_returns.c index 9c4881112e3..292671ea8cb 100644 --- a/src/compiler/nir/nir_lower_returns.c +++ b/src/compiler/nir/nir_lower_returns.c @@ -198,11 +198,11 @@ lower_returns_in_block(nir_block *block, struct lower_returns_state *state) /* Initialize the variable to 0 */ b->cursor = nir_before_cf_list(&b->impl->body); - nir_store_var(b, state->return_flag, nir_imm_int(b, NIR_FALSE), 1); + nir_store_var(b, state->return_flag, nir_imm_false(b), 1); } b->cursor = nir_after_block(block); - nir_store_var(b, state->return_flag, nir_imm_int(b, NIR_TRUE), 1); + nir_store_var(b, state->return_flag, nir_imm_true(b), 1); if (state->loop) { /* We're in a loop; we need to break out of it. */ diff --git a/src/compiler/nir/nir_lower_subgroups.c b/src/compiler/nir/nir_lower_subgroups.c index ee5e8bd644b..70d736b040f 100644 --- a/src/compiler/nir/nir_lower_subgroups.c +++ b/src/compiler/nir/nir_lower_subgroups.c @@ -300,7 +300,7 @@ lower_subgroups_intrin(nir_builder *b, nir_intrinsic_instr *intrin, case nir_intrinsic_vote_feq: case nir_intrinsic_vote_ieq: if (options->lower_vote_trivial) - return nir_imm_int(b, NIR_TRUE); + return nir_imm_true(b); if (options->lower_vote_eq_to_ballot) return lower_vote_eq_to_ballot(b, intrin, options); diff --git a/src/compiler/nir/nir_opt_intrinsics.c b/src/compiler/nir/nir_opt_intrinsics.c index 0bc2f0b3c82..7b054faa204 100644 --- a/src/compiler/nir/nir_opt_intrinsics.c +++ b/src/compiler/nir/nir_opt_intrinsics.c @@ -53,7 +53,7 @@ opt_intrinsics_impl(nir_function_impl *impl) case nir_intrinsic_vote_feq: case nir_intrinsic_vote_ieq: if (nir_src_is_const(intrin->src[0])) - replacement = nir_imm_int(&b, NIR_TRUE); + replacement = nir_imm_true(&b); break; default: break; diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c index 38ccd62ae17..6860e7dc090 100644 --- a/src/compiler/spirv/vtn_alu.c +++ b/src/compiler/spirv/vtn_alu.c @@ -494,7 +494,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode, default: vtn_fail("invalid number of components"); } val->ssa->def = nir_build_alu(&b->nb, op, src[0], - nir_imm_int(&b->nb, NIR_FALSE), + nir_imm_false(&b->nb), NULL, NULL); } break; @@ -511,7 +511,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode, default: vtn_fail("invalid number of components"); } val->ssa->def = nir_build_alu(&b->nb, op, src[0], - nir_imm_int(&b->nb, NIR_TRUE), + nir_imm_true(&b->nb), NULL, NULL); } break; diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c index 87149905ed1..1da235becc5 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -723,7 +723,7 @@ vtn_emit_branch(struct vtn_builder *b, enum vtn_branch_type branch_type, { switch (branch_type) { case vtn_branch_type_switch_break: - nir_store_var(&b->nb, switch_fall_var, nir_imm_int(&b->nb, NIR_FALSE), 1); + nir_store_var(&b->nb, switch_fall_var, nir_imm_false(&b->nb), 1); *has_switch_break = true; break; case vtn_branch_type_switch_fallthrough: @@ -841,7 +841,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, nir_local_variable_create(b->nb.impl, glsl_bool_type(), "cont"); b->nb.cursor = nir_before_cf_node(&loop->cf_node); - nir_store_var(&b->nb, do_cont, nir_imm_int(&b->nb, NIR_FALSE), 1); + nir_store_var(&b->nb, do_cont, nir_imm_false(&b->nb), 1); b->nb.cursor = nir_before_cf_list(&loop->body); @@ -852,7 +852,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, nir_pop_if(&b->nb, cont_if); - nir_store_var(&b->nb, do_cont, nir_imm_int(&b->nb, NIR_TRUE), 1); + nir_store_var(&b->nb, do_cont, nir_imm_true(&b->nb), 1); b->has_loop_continue = true; } @@ -870,7 +870,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, */ nir_variable *fall_var = nir_local_variable_create(b->nb.impl, glsl_bool_type(), "fall"); - nir_store_var(&b->nb, fall_var, nir_imm_int(&b->nb, NIR_FALSE), 1); + nir_store_var(&b->nb, fall_var, nir_imm_false(&b->nb), 1); /* Next, we gather up all of the conditions. We have to do this * up-front because we also need to build an "any" condition so @@ -918,7 +918,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list, nir_if *case_if = nir_push_if(&b->nb, cond); bool has_break = false; - nir_store_var(&b->nb, fall_var, nir_imm_int(&b->nb, NIR_TRUE), 1); + nir_store_var(&b->nb, fall_var, nir_imm_true(&b->nb), 1); vtn_emit_cf_list(b, &cse->body, fall_var, &has_break, handler); (void)has_break; /* We don't care */ diff --git a/src/intel/compiler/brw_nir_lower_image_load_store.c b/src/intel/compiler/brw_nir_lower_image_load_store.c index e8083a80cb7..1a7671b74b1 100644 --- a/src/intel/compiler/brw_nir_lower_image_load_store.c +++ b/src/intel/compiler/brw_nir_lower_image_load_store.c @@ -123,7 +123,7 @@ image_coord_is_in_bounds(nir_builder *b, nir_deref_instr *deref, nir_ssa_def *cmp = nir_ilt(b, coord, size); unsigned coord_comps = glsl_get_sampler_coordinate_components(deref->type); - nir_ssa_def *in_bounds = nir_imm_int(b, NIR_TRUE); + nir_ssa_def *in_bounds = nir_imm_true(b); for (unsigned i = 0; i < coord_comps; i++) in_bounds = nir_iand(b, in_bounds, nir_channel(b, cmp, i));