nir/builder: Add a nir_imm_true/false helpers
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 19 Oct 2018 14:35:49 +0000 (09:35 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 26 Oct 2018 16:45:29 +0000 (11:45 -0500)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/nir/nir_builder.h
src/compiler/nir/nir_lower_int64.c
src/compiler/nir/nir_lower_returns.c
src/compiler/nir/nir_lower_subgroups.c
src/compiler/nir/nir_opt_intrinsics.c
src/compiler/spirv/vtn_alu.c
src/compiler/spirv/vtn_cfg.c
src/intel/compiler/brw_nir_lower_image_load_store.c

index 398fa68c251f19e4b94b96abca82dcd4efc103fe..5ea0a5a2637d8c01b57c19e4b0bd365f43022104 100644 (file)
@@ -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 *
index 0d7f165b4061c7c0581d590fcfd3eeaa76295b32..50acc8586055bc90f93ed14b45b0e38a71cf36f7 100644 (file)
@@ -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);
 
index 9c4881112e30ffc29033be9ce316cd052b459f71..292671ea8cbcd9896e1e56ac77c5c0a69b9442ed 100644 (file)
@@ -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. */
index ee5e8bd644bfb96657d77bcedbdb5731f36ebc53..70d736b040f0dd44a7393f7615c0865ed5ec3772 100644 (file)
@@ -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);
index 0bc2f0b3c82d6724da72a1ca98d33cc5516fa7a6..7b054faa20431bbcd5c76efec5a9bd1b7242c466 100644 (file)
@@ -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;
index 38ccd62ae1766a7d39dd23aad1006e2293169cb7..6860e7dc090f1299ad9b65a584782b64b5e3cdd8 100644 (file)
@@ -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;
index 87149905ed1c978fda3ca1f3c007390bc6eeb0fc..1da235becc5bc3c1eba4b58b39b8c3603d764026 100644 (file)
@@ -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 */
 
index e8083a80cb769a3b7799a9a13b1bd7d43b3c9162..1a7671b74b1b161d68b766fb8dbd7dc08760485e 100644 (file)
@@ -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));