summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-04-17 17:10:18 -0500
committerJason Ekstrand <[email protected]>2019-04-18 17:12:44 +0000
commit85c35885b383477ac4f92a11695fc85c6d45c98c (patch)
treeb9cb1e3ce1c4e484908019ec13d55ed9e7bae288 /src
parenteee994e769259887ea17ec653ee1ea277416ea8b (diff)
nir: Rework nir_src_as_alu_instr to not take a pointer
Other nir_src_as_* functions just take a nir_src. It's not that much more memory copying and the constness preserving really isn't worth the cognitive dissonance. Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/nir/nir.h12
-rw-r--r--src/compiler/nir/nir_instr_set.c10
-rw-r--r--src/compiler/nir/tests/vars_tests.cpp12
-rw-r--r--src/intel/compiler/brw_fs_nir.cpp10
4 files changed, 18 insertions, 26 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 672151f3279..91ab40a9482 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2756,16 +2756,10 @@ nir_src_instr(const struct nir_src *src)
#define NIR_SRC_AS_(name, c_type, type_enum, cast_macro) \
static inline c_type * \
-nir_src_as_ ## name (nir_src *src) \
+nir_src_as_ ## name (nir_src src) \
{ \
- return src->is_ssa && src->ssa->parent_instr->type == type_enum \
- ? cast_macro(src->ssa->parent_instr) : NULL; \
-} \
-static inline const c_type * \
-nir_src_as_ ## name ## _const(const nir_src *src) \
-{ \
- return src->is_ssa && src->ssa->parent_instr->type == type_enum \
- ? cast_macro(src->ssa->parent_instr) : NULL; \
+ return src.is_ssa && src.ssa->parent_instr->type == type_enum \
+ ? cast_macro(src.ssa->parent_instr) : NULL; \
}
NIR_SRC_AS_(alu_instr, nir_alu_instr, nir_instr_type_alu, nir_instr_as_alu)
diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c
index 6605d2a1ab3..bd62bc974ed 100644
--- a/src/compiler/nir/nir_instr_set.c
+++ b/src/compiler/nir/nir_instr_set.c
@@ -281,10 +281,10 @@ nir_srcs_equal(nir_src src1, nir_src src2)
* that instruction is returned as a \c nir_alu_instr. Otherwise \c NULL is
* returned.
*/
-static const nir_alu_instr *
-get_neg_instr(const nir_src *s)
+static nir_alu_instr *
+get_neg_instr(nir_src s)
{
- const nir_alu_instr *const alu = nir_src_as_alu_instr_const(s);
+ nir_alu_instr *alu = nir_src_as_alu_instr(s);
return alu != NULL && (alu->op == nir_op_fneg || alu->op == nir_op_ineg)
? alu : NULL;
@@ -440,7 +440,7 @@ nir_alu_srcs_negative_equal(const nir_alu_instr *alu1,
uint8_t alu1_swizzle[4] = {0};
nir_src alu1_actual_src;
- const nir_alu_instr *const neg1 = get_neg_instr(&alu1->src[src1].src);
+ nir_alu_instr *neg1 = get_neg_instr(alu1->src[src1].src);
if (neg1) {
parity = !parity;
@@ -457,7 +457,7 @@ nir_alu_srcs_negative_equal(const nir_alu_instr *alu1,
uint8_t alu2_swizzle[4] = {0};
nir_src alu2_actual_src;
- const nir_alu_instr *const neg2 = get_neg_instr(&alu2->src[src2].src);
+ nir_alu_instr *neg2 = get_neg_instr(alu2->src[src2].src);
if (neg2) {
parity = !parity;
diff --git a/src/compiler/nir/tests/vars_tests.cpp b/src/compiler/nir/tests/vars_tests.cpp
index 9e0b5d2c0df..d27a9c0fb1d 100644
--- a/src/compiler/nir/tests/vars_tests.cpp
+++ b/src/compiler/nir/tests/vars_tests.cpp
@@ -509,7 +509,7 @@ TEST_F(nir_copy_prop_vars_test, load_direct_array_deref_on_vector_reuses_previou
ASSERT_TRUE(store->src[1].is_ssa);
/* NOTE: The ALU instruction is how we get the vec.y. */
- ASSERT_TRUE(nir_src_as_alu_instr(&store->src[1]));
+ ASSERT_TRUE(nir_src_as_alu_instr(store->src[1]));
}
TEST_F(nir_copy_prop_vars_test, load_direct_array_deref_on_vector_reuses_previous_copy)
@@ -567,7 +567,7 @@ TEST_F(nir_copy_prop_vars_test, load_direct_array_deref_on_vector_gets_reused)
nir_intrinsic_instr *store = get_intrinsic(nir_intrinsic_store_deref, 1);
ASSERT_TRUE(store->src[1].is_ssa);
- ASSERT_TRUE(nir_src_as_alu_instr(&store->src[1]));
+ ASSERT_TRUE(nir_src_as_alu_instr(store->src[1]));
}
TEST_F(nir_copy_prop_vars_test, store_load_direct_array_deref_on_vector)
@@ -612,7 +612,7 @@ TEST_F(nir_copy_prop_vars_test, store_load_direct_array_deref_on_vector)
/* Fourth store will compose first and second store values. */
nir_intrinsic_instr *fourth_store = get_intrinsic(nir_intrinsic_store_deref, 3);
ASSERT_TRUE(fourth_store->src[1].is_ssa);
- EXPECT_TRUE(nir_src_as_alu_instr(&fourth_store->src[1]));
+ EXPECT_TRUE(nir_src_as_alu_instr(fourth_store->src[1]));
}
TEST_F(nir_copy_prop_vars_test, store_load_indirect_array_deref_on_vector)
@@ -990,7 +990,7 @@ TEST_F(nir_combine_stores_test, non_overlapping_stores)
ASSERT_EQ(nir_intrinsic_write_mask(combined), 0xf);
ASSERT_EQ(nir_intrinsic_get_var(combined, 0), out);
- nir_alu_instr *vec = nir_src_as_alu_instr(&combined->src[1]);
+ 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 =
@@ -1030,7 +1030,7 @@ TEST_F(nir_combine_stores_test, overlapping_stores)
ASSERT_EQ(nir_intrinsic_write_mask(combined), 0xf);
ASSERT_EQ(nir_intrinsic_get_var(combined, 0), out);
- nir_alu_instr *vec = nir_src_as_alu_instr(&combined->src[1]);
+ nir_alu_instr *vec = nir_src_as_alu_instr(combined->src[1]);
ASSERT_TRUE(vec);
/* Component x comes from v[0]. */
@@ -1100,7 +1100,7 @@ TEST_F(nir_combine_stores_test, direct_array_derefs)
ASSERT_EQ(nir_intrinsic_write_mask(combined), 0xf);
ASSERT_EQ(nir_intrinsic_get_var(combined, 0), out);
- nir_alu_instr *vec = nir_src_as_alu_instr(&combined->src[1]);
+ nir_alu_instr *vec = nir_src_as_alu_instr(combined->src[1]);
ASSERT_TRUE(vec);
/* Component x comes from v[0]. */
diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp
index f611b261784..ac566be7476 100644
--- a/src/intel/compiler/brw_fs_nir.cpp
+++ b/src/intel/compiler/brw_fs_nir.cpp
@@ -387,7 +387,7 @@ fs_visitor::nir_emit_if(nir_if *if_stmt)
/* If the condition has the form !other_condition, use other_condition as
* the source, but invert the predicate on the if instruction.
*/
- nir_alu_instr *const cond = nir_src_as_alu_instr(&if_stmt->condition);
+ nir_alu_instr *cond = nir_src_as_alu_instr(if_stmt->condition);
if (cond != NULL && cond->op == nir_op_inot) {
assert(!cond->src[0].negate);
assert(!cond->src[0].abs);
@@ -754,8 +754,7 @@ fs_visitor::resolve_inot_sources(const fs_builder &bld, nir_alu_instr *instr,
fs_reg *op)
{
for (unsigned i = 0; i < 2; i++) {
- nir_alu_instr *const inot_instr =
- nir_src_as_alu_instr(&instr->src[i].src);
+ nir_alu_instr *inot_instr = nir_src_as_alu_instr(instr->src[i].src);
if (inot_instr != NULL && inot_instr->op == nir_op_inot &&
!inot_instr->src[0].abs && !inot_instr->src[0].negate) {
@@ -778,7 +777,7 @@ fs_visitor::try_emit_b2fi_of_inot(const fs_builder &bld,
if (devinfo->gen < 6 || devinfo->gen >= 12)
return false;
- nir_alu_instr *const inot_instr = nir_src_as_alu_instr(&instr->src[0].src);
+ nir_alu_instr *inot_instr = nir_src_as_alu_instr(instr->src[0].src);
if (inot_instr == NULL || inot_instr->op != nir_op_inot)
return false;
@@ -1242,8 +1241,7 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
case nir_op_inot:
if (devinfo->gen >= 8) {
- nir_alu_instr *const inot_src_instr =
- nir_src_as_alu_instr(&instr->src[0].src);
+ nir_alu_instr *inot_src_instr = nir_src_as_alu_instr(instr->src[0].src);
if (inot_src_instr != NULL &&
(inot_src_instr->op == nir_op_ior ||