diff options
-rw-r--r-- | src/compiler/nir/nir.h | 8 | ||||
-rw-r--r-- | src/compiler/nir/nir_opt_find_array_copies.c | 10 | ||||
-rw-r--r-- | src/compiler/nir/nir_split_vars.c | 10 | ||||
-rw-r--r-- | src/compiler/nir/tests/vars_tests.cpp | 27 | ||||
-rw-r--r-- | src/intel/compiler/brw_fs_nir.cpp | 15 |
5 files changed, 19 insertions, 51 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 91ab40a9482..2a381d28d7c 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2748,12 +2748,6 @@ bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state); nir_const_value *nir_src_as_const_value(nir_src src); -static inline struct nir_instr * -nir_src_instr(const struct nir_src *src) -{ - return src->is_ssa ? src->ssa->parent_instr : NULL; -} - #define NIR_SRC_AS_(name, c_type, type_enum, cast_macro) \ static inline c_type * \ nir_src_as_ ## name (nir_src src) \ @@ -2763,6 +2757,8 @@ nir_src_as_ ## name (nir_src src) \ } NIR_SRC_AS_(alu_instr, nir_alu_instr, nir_instr_type_alu, nir_instr_as_alu) +NIR_SRC_AS_(intrinsic, nir_intrinsic_instr, + nir_instr_type_intrinsic, nir_instr_as_intrinsic) bool nir_src_is_dynamically_uniform(nir_src src); bool nir_srcs_equal(nir_src src1, nir_src src2); diff --git a/src/compiler/nir/nir_opt_find_array_copies.c b/src/compiler/nir/nir_opt_find_array_copies.c index e50264c5900..1573cce8374 100644 --- a/src/compiler/nir/nir_opt_find_array_copies.c +++ b/src/compiler/nir/nir_opt_find_array_copies.c @@ -37,14 +37,8 @@ index_ssa_def_cb(nir_ssa_def *def, void *state) static nir_deref_instr * get_deref_for_load_src(nir_src src, unsigned first_valid_load) { - if (!src.is_ssa) - return NULL; - - if (src.ssa->parent_instr->type != nir_instr_type_intrinsic) - return NULL; - - nir_intrinsic_instr *load = nir_instr_as_intrinsic(src.ssa->parent_instr); - if (load->intrinsic != nir_intrinsic_load_deref) + nir_intrinsic_instr *load = nir_src_as_intrinsic(src); + if (load == NULL || load->intrinsic != nir_intrinsic_load_deref) return NULL; if (load->dest.ssa.index < first_valid_load) diff --git a/src/compiler/nir/nir_split_vars.c b/src/compiler/nir/nir_split_vars.c index c6fe1b59a65..5e799d2dc57 100644 --- a/src/compiler/nir/nir_split_vars.c +++ b/src/compiler/nir/nir_split_vars.c @@ -1030,14 +1030,8 @@ mark_deref_used(nir_deref_instr *deref, static bool src_is_load_deref(nir_src src, nir_src deref_src) { - assert(src.is_ssa); - assert(deref_src.is_ssa); - - if (src.ssa->parent_instr->type != nir_instr_type_intrinsic) - return false; - - nir_intrinsic_instr *load = nir_instr_as_intrinsic(src.ssa->parent_instr); - if (load->intrinsic != nir_intrinsic_load_deref) + nir_intrinsic_instr *load = nir_src_as_intrinsic(src); + if (load == NULL || load->intrinsic != nir_intrinsic_load_deref) return false; assert(load->src[0].is_ssa); diff --git a/src/compiler/nir/tests/vars_tests.cpp b/src/compiler/nir/tests/vars_tests.cpp index d27a9c0fb1d..06e5dbc8ba7 100644 --- a/src/compiler/nir/tests/vars_tests.cpp +++ b/src/compiler/nir/tests/vars_tests.cpp @@ -993,8 +993,7 @@ TEST_F(nir_combine_stores_test, non_overlapping_stores) nir_alu_instr *vec = nir_src_as_alu_instr(combined->src[1]); ASSERT_TRUE(vec); for (int i = 0; i < 4; i++) { - nir_intrinsic_instr *load = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[i].src)); + nir_intrinsic_instr *load = nir_src_as_intrinsic(vec->src[i].src); ASSERT_EQ(load->intrinsic, nir_intrinsic_load_deref); ASSERT_EQ(nir_intrinsic_get_var(load, 0), v[i]) << "Source value for component " << i << " of store is wrong"; @@ -1034,22 +1033,18 @@ TEST_F(nir_combine_stores_test, overlapping_stores) ASSERT_TRUE(vec); /* Component x comes from v[0]. */ - nir_intrinsic_instr *load_for_x = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[0].src)); + nir_intrinsic_instr *load_for_x = nir_src_as_intrinsic(vec->src[0].src); ASSERT_EQ(nir_intrinsic_get_var(load_for_x, 0), v[0]); ASSERT_EQ(vec->src[0].swizzle[0], 0); /* Component y comes from v[1]. */ - nir_intrinsic_instr *load_for_y = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[1].src)); + nir_intrinsic_instr *load_for_y = nir_src_as_intrinsic(vec->src[1].src); ASSERT_EQ(nir_intrinsic_get_var(load_for_y, 0), v[1]); ASSERT_EQ(vec->src[1].swizzle[0], 1); /* Components z and w come from v[2]. */ - nir_intrinsic_instr *load_for_z = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[2].src)); - nir_intrinsic_instr *load_for_w = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[3].src)); + nir_intrinsic_instr *load_for_z = nir_src_as_intrinsic(vec->src[2].src); + nir_intrinsic_instr *load_for_w = nir_src_as_intrinsic(vec->src[3].src); ASSERT_EQ(load_for_z, load_for_w); ASSERT_EQ(nir_intrinsic_get_var(load_for_z, 0), v[2]); ASSERT_EQ(vec->src[2].swizzle[0], 2); @@ -1104,26 +1099,22 @@ TEST_F(nir_combine_stores_test, direct_array_derefs) ASSERT_TRUE(vec); /* Component x comes from v[0]. */ - nir_intrinsic_instr *load_for_x = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[0].src)); + nir_intrinsic_instr *load_for_x = nir_src_as_intrinsic(vec->src[0].src); ASSERT_EQ(nir_intrinsic_get_var(load_for_x, 0), v[0]); ASSERT_EQ(vec->src[0].swizzle[0], 0); /* Component y comes from v[1]. */ - nir_intrinsic_instr *load_for_y = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[1].src)); + nir_intrinsic_instr *load_for_y = nir_src_as_intrinsic(vec->src[1].src); ASSERT_EQ(nir_intrinsic_get_var(load_for_y, 0), v[1]); ASSERT_EQ(vec->src[1].swizzle[0], 1); /* Components z comes from s[0]. */ - nir_intrinsic_instr *load_for_z = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[2].src)); + nir_intrinsic_instr *load_for_z = nir_src_as_intrinsic(vec->src[2].src); ASSERT_EQ(nir_intrinsic_get_var(load_for_z, 0), s[0]); ASSERT_EQ(vec->src[2].swizzle[0], 0); /* Component w comes from s[1]. */ - nir_intrinsic_instr *load_for_w = - nir_instr_as_intrinsic(nir_src_instr(&vec->src[3].src)); + nir_intrinsic_instr *load_for_w = nir_src_as_intrinsic(vec->src[3].src); ASSERT_EQ(nir_intrinsic_get_var(load_for_w, 0), s[1]); ASSERT_EQ(vec->src[3].swizzle[0], 0); } diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp index ac566be7476..397d1f5980a 100644 --- a/src/intel/compiler/brw_fs_nir.cpp +++ b/src/intel/compiler/brw_fs_nir.cpp @@ -558,14 +558,8 @@ bool fs_visitor::optimize_frontfacing_ternary(nir_alu_instr *instr, const fs_reg &result) { - if (!instr->src[0].src.is_ssa || - instr->src[0].src.ssa->parent_instr->type != nir_instr_type_intrinsic) - return false; - - nir_intrinsic_instr *src0 = - nir_instr_as_intrinsic(instr->src[0].src.ssa->parent_instr); - - if (src0->intrinsic != nir_intrinsic_load_front_face) + nir_intrinsic_instr *src0 = nir_src_as_intrinsic(instr->src[0].src); + if (src0 == NULL || src0->intrinsic != nir_intrinsic_load_front_face) return false; if (!nir_src_is_const(instr->src[1].src) || @@ -2527,9 +2521,8 @@ fs_visitor::nir_emit_tcs_intrinsic(const fs_builder &bld, retype(brw_vec1_grf(1 + (vertex >> 3), vertex & 7), BRW_REGISTER_TYPE_UD)); } else if (tcs_prog_data->instances == 1 && - vertex_src.is_ssa && - vertex_src.ssa->parent_instr->type == nir_instr_type_intrinsic && - nir_instr_as_intrinsic(vertex_src.ssa->parent_instr)->intrinsic == nir_intrinsic_load_invocation_id) { + nir_src_as_intrinsic(vertex_src) != NULL && + nir_src_as_intrinsic(vertex_src)->intrinsic == nir_intrinsic_load_invocation_id) { /* For the common case of only 1 instance, an array index of * gl_InvocationID means reading g1. Skip all the indirect work. */ |