summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compiler/glsl/gl_nir_lower_samplers.c7
-rw-r--r--src/compiler/nir/nir_deref.c14
-rw-r--r--src/compiler/nir/nir_gather_info.c6
-rw-r--r--src/compiler/nir/nir_gs_count_vertices.c7
-rw-r--r--src/compiler/nir/nir_lower_clip.c2
-rw-r--r--src/compiler/nir/nir_lower_indirect_derefs.c4
-rw-r--r--src/compiler/nir/nir_lower_io.c6
-rw-r--r--src/compiler/nir/nir_lower_io_arrays_to_elements.c11
-rw-r--r--src/compiler/nir/nir_lower_locals_to_regs.c6
-rw-r--r--src/compiler/nir/nir_lower_two_sided_color.c2
-rw-r--r--src/compiler/nir/nir_lower_vars_to_ssa.c14
-rw-r--r--src/compiler/nir/nir_opt_dead_cf.c7
-rw-r--r--src/compiler/nir/nir_opt_find_array_copies.c13
-rw-r--r--src/compiler/nir/nir_opt_intrinsics.c4
-rw-r--r--src/compiler/nir/nir_opt_large_constants.c2
-rw-r--r--src/compiler/nir/nir_split_vars.c17
-rw-r--r--src/compiler/nir/tests/vars_tests.cpp10
17 files changed, 56 insertions, 76 deletions
diff --git a/src/compiler/glsl/gl_nir_lower_samplers.c b/src/compiler/glsl/gl_nir_lower_samplers.c
index 593967b7108..1ee075cfd14 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers.c
@@ -57,12 +57,9 @@ lower_tex_src_to_offset(nir_builder *b,
break;
case nir_deref_type_array: {
- nir_const_value *const_deref_index =
- nir_src_as_const_value(deref->arr.index);
-
- if (const_deref_index && index == NULL) {
+ if (nir_src_is_const(deref->arr.index) && index == NULL) {
/* We're still building a direct index */
- base_index += const_deref_index->u32[0] * array_elements;
+ base_index += nir_src_as_uint(deref->arr.index) * array_elements;
} else {
if (index == NULL) {
/* We used to be direct but not anymore */
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 4a87ee84d8a..4a2e81956d1 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -112,7 +112,7 @@ nir_deref_instr_has_indirect(nir_deref_instr *instr)
return true;
if (instr->deref_type == nir_deref_type_array &&
- !nir_src_as_const_value(instr->arr.index))
+ !nir_src_is_const(instr->arr.index))
return true;
instr = nir_deref_instr_parent(instr);
@@ -160,7 +160,7 @@ nir_deref_instr_get_const_offset(nir_deref_instr *deref,
unsigned offset = 0;
for (nir_deref_instr **p = &path.path[1]; *p; p++) {
if ((*p)->deref_type == nir_deref_type_array) {
- offset += nir_src_as_const_value((*p)->arr.index)->u32[0] *
+ offset += nir_src_as_uint((*p)->arr.index) *
type_get_array_stride((*p)->type, size_align);
} else if ((*p)->deref_type == nir_deref_type_struct) {
/* p starts at path[1], so this is safe */
@@ -312,15 +312,13 @@ nir_compare_deref_paths(nir_deref_path *a_path,
b_tail->deref_type == nir_deref_type_array);
assert(a_tail->arr.index.is_ssa && b_tail->arr.index.is_ssa);
- nir_const_value *a_index_const =
- nir_src_as_const_value(a_tail->arr.index);
- nir_const_value *b_index_const =
- nir_src_as_const_value(b_tail->arr.index);
- if (a_index_const && b_index_const) {
+ if (nir_src_is_const(a_tail->arr.index) &&
+ nir_src_is_const(b_tail->arr.index)) {
/* If they're both direct and have different offsets, they
* don't even alias much less anything else.
*/
- if (a_index_const->u32[0] != b_index_const->u32[0])
+ if (nir_src_as_uint(a_tail->arr.index) !=
+ nir_src_as_uint(b_tail->arr.index))
return 0;
} else if (a_tail->arr.index.ssa == b_tail->arr.index.ssa) {
/* They're the same indirect, continue on */
diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c
index 30f0bc721d4..15d38f036b5 100644
--- a/src/compiler/nir/nir_gather_info.c
+++ b/src/compiler/nir/nir_gather_info.c
@@ -108,13 +108,11 @@ get_io_offset(nir_deref_instr *deref, bool is_vertex_input)
for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
if (d->deref_type == nir_deref_type_array) {
- nir_const_value *const_index = nir_src_as_const_value(d->arr.index);
-
- if (!const_index)
+ if (!nir_src_is_const(d->arr.index))
return -1;
offset += glsl_count_attribute_slots(d->type, is_vertex_input) *
- const_index->u32[0];
+ nir_src_as_uint(d->arr.index);
}
/* TODO: we can get the offset for structs here see nir_lower_io() */
}
diff --git a/src/compiler/nir/nir_gs_count_vertices.c b/src/compiler/nir/nir_gs_count_vertices.c
index 7342e4473df..934c46b78f1 100644
--- a/src/compiler/nir/nir_gs_count_vertices.c
+++ b/src/compiler/nir/nir_gs_count_vertices.c
@@ -71,19 +71,18 @@ nir_gs_count_vertices(const nir_shader *shader)
if (!intrin)
continue;
- nir_const_value *val = nir_src_as_const_value(intrin->src[0]);
/* We've found a non-constant value. Bail. */
- if (!val)
+ if (!nir_src_is_const(intrin->src[0]))
return -1;
if (count == -1)
- count = val->i32[0];
+ count = nir_src_as_int(intrin->src[0]);
/* We've found contradictory set_vertex_count intrinsics.
* This can happen if there are early-returns in main() and
* different paths emit different numbers of vertices.
*/
- if (count != val->i32[0])
+ if (count != nir_src_as_int(intrin->src[0]))
return -1;
}
}
diff --git a/src/compiler/nir/nir_lower_clip.c b/src/compiler/nir/nir_lower_clip.c
index ea12f51a7bb..7081295a500 100644
--- a/src/compiler/nir/nir_lower_clip.c
+++ b/src/compiler/nir/nir_lower_clip.c
@@ -107,7 +107,7 @@ find_output_in_block(nir_block *block, unsigned drvloc)
if ((intr->intrinsic == nir_intrinsic_store_output) &&
nir_intrinsic_base(intr) == drvloc) {
assert(intr->src[0].is_ssa);
- assert(nir_src_as_const_value(intr->src[1]));
+ assert(nir_src_is_const(intr->src[1]));
return intr->src[0].ssa;
}
}
diff --git a/src/compiler/nir/nir_lower_indirect_derefs.c b/src/compiler/nir/nir_lower_indirect_derefs.c
index c1f3cf86823..897a0620872 100644
--- a/src/compiler/nir/nir_lower_indirect_derefs.c
+++ b/src/compiler/nir/nir_lower_indirect_derefs.c
@@ -74,7 +74,7 @@ emit_load_store_deref(nir_builder *b, nir_intrinsic_instr *orig_instr,
for (; *deref_arr; deref_arr++) {
nir_deref_instr *deref = *deref_arr;
if (deref->deref_type == nir_deref_type_array &&
- nir_src_as_const_value(deref->arr.index) == NULL) {
+ !nir_src_is_const(deref->arr.index)) {
int length = glsl_get_length(parent->type);
emit_indirect_load_store_deref(b, orig_instr, parent, deref_arr,
@@ -137,7 +137,7 @@ lower_indirect_derefs_block(nir_block *block, nir_builder *b,
nir_deref_instr *base = deref;
while (base->deref_type != nir_deref_type_var) {
if (base->deref_type == nir_deref_type_array &&
- nir_src_as_const_value(base->arr.index) == NULL)
+ !nir_src_is_const(base->arr.index))
has_indirect = true;
base = nir_deref_instr_parent(base);
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index c418433aa52..b3595bb19d5 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -112,10 +112,8 @@ get_io_offset(nir_builder *b, nir_deref_instr *deref,
assert(glsl_type_is_scalar((*p)->type));
/* We always lower indirect dereferences for "compact" array vars. */
- nir_const_value *const_index = nir_src_as_const_value((*p)->arr.index);
- assert(const_index);
-
- const unsigned total_offset = *component + const_index->u32[0];
+ const unsigned index = nir_src_as_uint((*p)->arr.index);
+ const unsigned total_offset = *component + index;
const unsigned slot_offset = total_offset / 4;
*component = total_offset % 4;
return nir_imm_int(b, type_size(glsl_vec4_type()) * slot_offset);
diff --git a/src/compiler/nir/nir_lower_io_arrays_to_elements.c b/src/compiler/nir/nir_lower_io_arrays_to_elements.c
index af33d153ea5..432524c2feb 100644
--- a/src/compiler/nir/nir_lower_io_arrays_to_elements.c
+++ b/src/compiler/nir/nir_lower_io_arrays_to_elements.c
@@ -53,12 +53,11 @@ get_io_offset(nir_builder *b, nir_deref_instr *deref, nir_variable *var,
unsigned offset = 0;
for (; *p; p++) {
if ((*p)->deref_type == nir_deref_type_array) {
- nir_const_value *c = nir_src_as_const_value((*p)->arr.index);
-
- assert(c); /* must not be indirect dereference */
+ /* must not be indirect dereference */
+ unsigned index = nir_src_as_uint((*p)->arr.index);
unsigned size = glsl_count_attribute_slots((*p)->type, false);
- offset += size * c->u32[0];
+ offset += size * index;
unsigned num_elements = glsl_type_is_array((*p)->type) ?
glsl_get_aoa_size((*p)->type) : 1;
@@ -66,7 +65,7 @@ get_io_offset(nir_builder *b, nir_deref_instr *deref, nir_variable *var,
num_elements *= glsl_type_is_matrix(glsl_without_array((*p)->type)) ?
glsl_get_matrix_columns(glsl_without_array((*p)->type)) : 1;
- *element_index += num_elements * c->u32[0];
+ *element_index += num_elements * index;
} else if ((*p)->deref_type == nir_deref_type_struct) {
/* TODO: we could also add struct splitting support to this pass */
break;
@@ -195,7 +194,7 @@ deref_has_indirect(nir_builder *b, nir_variable *var, nir_deref_path *path)
if ((*p)->deref_type != nir_deref_type_array)
continue;
- if (!nir_src_as_const_value((*p)->arr.index))
+ if (!nir_src_is_const((*p)->arr.index))
return true;
}
diff --git a/src/compiler/nir/nir_lower_locals_to_regs.c b/src/compiler/nir/nir_lower_locals_to_regs.c
index ec71f3dacbb..773b7fde6d0 100644
--- a/src/compiler/nir/nir_lower_locals_to_regs.c
+++ b/src/compiler/nir/nir_lower_locals_to_regs.c
@@ -151,9 +151,9 @@ get_deref_reg_src(nir_deref_instr *deref, struct locals_to_regs_state *state)
if (d->deref_type != nir_deref_type_array)
continue;
- nir_const_value *const_index = nir_src_as_const_value(d->arr.index);
- if (const_index && !src.reg.indirect) {
- src.reg.base_offset += const_index->u32[0] * inner_array_size;
+ if (nir_src_is_const(d->arr.index) && !src.reg.indirect) {
+ src.reg.base_offset += nir_src_as_uint(d->arr.index) *
+ inner_array_size;
} else {
if (src.reg.indirect) {
assert(src.reg.base_offset == 0);
diff --git a/src/compiler/nir/nir_lower_two_sided_color.c b/src/compiler/nir/nir_lower_two_sided_color.c
index b6742ab2462..f95a62e780c 100644
--- a/src/compiler/nir/nir_lower_two_sided_color.c
+++ b/src/compiler/nir/nir_lower_two_sided_color.c
@@ -146,7 +146,7 @@ nir_lower_two_sided_color_block(nir_block *block,
unsigned drvloc =
state->colors[idx].front->data.driver_location;
if (nir_intrinsic_base(intr) == drvloc) {
- assert(nir_src_as_const_value(intr->src[0]));
+ assert(nir_src_is_const(intr->src[0]));
break;
}
}
diff --git a/src/compiler/nir/nir_lower_vars_to_ssa.c b/src/compiler/nir/nir_lower_vars_to_ssa.c
index cd679be5be5..b3f29e07b63 100644
--- a/src/compiler/nir/nir_lower_vars_to_ssa.c
+++ b/src/compiler/nir/nir_lower_vars_to_ssa.c
@@ -162,9 +162,8 @@ get_deref_node_recur(nir_deref_instr *deref,
return parent->children[deref->strct.index];
case nir_deref_type_array: {
- nir_const_value *const_index = nir_src_as_const_value(deref->arr.index);
- if (const_index) {
- uint32_t index = const_index->u32[0];
+ if (nir_src_is_const(deref->arr.index)) {
+ uint32_t index = nir_src_as_uint(deref->arr.index);
/* This is possible if a loop unrolls and generates an
* out-of-bounds offset. We need to handle this at least
* somewhat gracefully.
@@ -252,9 +251,7 @@ foreach_deref_node_worker(struct deref_node *node, nir_deref_instr **path,
return;
case nir_deref_type_array: {
- nir_const_value *const_index = nir_src_as_const_value((*path)->arr.index);
- assert(const_index);
- uint32_t index = const_index->u32[0];
+ uint32_t index = nir_src_as_uint((*path)->arr.index);
if (node->children[index]) {
foreach_deref_node_worker(node->children[index],
@@ -318,11 +315,10 @@ path_may_be_aliased_node(struct deref_node *node, nir_deref_instr **path,
}
case nir_deref_type_array: {
- nir_const_value *const_index = nir_src_as_const_value((*path)->arr.index);
- if (!const_index)
+ if (!nir_src_is_const((*path)->arr.index))
return true;
- uint32_t index = const_index->u32[0];
+ uint32_t index = nir_src_as_uint((*path)->arr.index);
/* If there is an indirect at this level, we're aliased. */
if (node->indirect)
diff --git a/src/compiler/nir/nir_opt_dead_cf.c b/src/compiler/nir/nir_opt_dead_cf.c
index e224daa1fda..b547ab600bb 100644
--- a/src/compiler/nir/nir_opt_dead_cf.c
+++ b/src/compiler/nir/nir_opt_dead_cf.c
@@ -235,13 +235,10 @@ dead_cf_block(nir_block *block)
return true;
}
- nir_const_value *const_value =
- nir_src_as_const_value(following_if->condition);
-
- if (!const_value)
+ if (!nir_src_is_const(following_if->condition))
return false;
- opt_constant_if(following_if, const_value->u32[0] != 0);
+ opt_constant_if(following_if, nir_src_as_bool(following_if->condition));
return true;
}
diff --git a/src/compiler/nir/nir_opt_find_array_copies.c b/src/compiler/nir/nir_opt_find_array_copies.c
index 417ad9c55c3..5cfcd73b6b8 100644
--- a/src/compiler/nir/nir_opt_find_array_copies.c
+++ b/src/compiler/nir/nir_opt_find_array_copies.c
@@ -124,8 +124,10 @@ try_match_deref(nir_deref_path *base_path, int *path_array_idx,
case nir_deref_type_array:
assert(b->arr.index.is_ssa && d->arr.index.is_ssa);
- nir_const_value *const_b_idx = nir_src_as_const_value(b->arr.index);
- nir_const_value *const_d_idx = nir_src_as_const_value(d->arr.index);
+ const bool const_b_idx = nir_src_is_const(b->arr.index);
+ const bool const_d_idx = nir_src_is_const(d->arr.index);
+ const unsigned b_idx = const_b_idx ? nir_src_as_uint(b->arr.index) : 0;
+ const unsigned d_idx = const_d_idx ? nir_src_as_uint(d->arr.index) : 0;
/* If we don't have an index into the path yet or if this entry in
* the path is at the array index, see if this is a candidate. We're
@@ -133,8 +135,8 @@ try_match_deref(nir_deref_path *base_path, int *path_array_idx,
* in the search deref.
*/
if ((*path_array_idx < 0 || *path_array_idx == i) &&
- const_b_idx && const_b_idx->u32[0] == 0 &&
- const_d_idx && const_d_idx->u32[0] == arr_idx) {
+ const_b_idx && b_idx == 0 &&
+ const_d_idx && d_idx == arr_idx) {
*path_array_idx = i;
continue;
}
@@ -149,8 +151,7 @@ try_match_deref(nir_deref_path *base_path, int *path_array_idx,
* earlier.
*/
if (b->arr.index.ssa == d->arr.index.ssa ||
- (const_b_idx && const_d_idx &&
- const_b_idx->u32[0] == const_d_idx->u32[0]))
+ (const_b_idx && const_d_idx && b_idx == d_idx))
continue;
goto fail;
diff --git a/src/compiler/nir/nir_opt_intrinsics.c b/src/compiler/nir/nir_opt_intrinsics.c
index 37f08c77ef1..0bc2f0b3c82 100644
--- a/src/compiler/nir/nir_opt_intrinsics.c
+++ b/src/compiler/nir/nir_opt_intrinsics.c
@@ -47,12 +47,12 @@ opt_intrinsics_impl(nir_function_impl *impl)
switch (intrin->intrinsic) {
case nir_intrinsic_vote_any:
case nir_intrinsic_vote_all:
- if (nir_src_as_const_value(intrin->src[0]))
+ if (nir_src_is_const(intrin->src[0]))
replacement = nir_ssa_for_src(&b, intrin->src[0], 1);
break;
case nir_intrinsic_vote_feq:
case nir_intrinsic_vote_ieq:
- if (nir_src_as_const_value(intrin->src[0]))
+ if (nir_src_is_const(intrin->src[0]))
replacement = nir_imm_int(&b, NIR_TRUE);
break;
default:
diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c
index 25a921963df..634913aa9e5 100644
--- a/src/compiler/nir/nir_opt_large_constants.c
+++ b/src/compiler/nir/nir_opt_large_constants.c
@@ -153,7 +153,7 @@ nir_opt_large_constants(nir_shader *shader,
switch (intrin->intrinsic) {
case nir_intrinsic_store_deref:
dst_deref = nir_src_as_deref(intrin->src[0]);
- src_is_const = nir_src_as_const_value(intrin->src[1]);
+ src_is_const = nir_src_is_const(intrin->src[1]);
break;
case nir_intrinsic_load_deref:
diff --git a/src/compiler/nir/nir_split_vars.c b/src/compiler/nir/nir_split_vars.c
index 02aef2a9b47..7eda99819cc 100644
--- a/src/compiler/nir/nir_split_vars.c
+++ b/src/compiler/nir/nir_split_vars.c
@@ -396,7 +396,7 @@ mark_array_deref_used(nir_deref_instr *deref,
for (unsigned i = 0; i < info->num_levels; i++) {
nir_deref_instr *p = path.path[i + 1];
if (p->deref_type == nir_deref_type_array &&
- nir_src_as_const_value(p->arr.index) == NULL)
+ !nir_src_is_const(p->arr.index))
info->levels[i].split = false;
}
}
@@ -566,8 +566,8 @@ array_path_is_out_of_bounds(nir_deref_path *path,
if (p->deref_type == nir_deref_type_array_wildcard)
continue;
- nir_const_value *const_index = nir_src_as_const_value(p->arr.index);
- if (const_index && const_index->u32[0] >= info->levels[i].array_len)
+ if (nir_src_is_const(p->arr.index) &&
+ nir_src_as_uint(p->arr.index) >= info->levels[i].array_len)
return true;
}
@@ -751,7 +751,7 @@ split_array_access_impl(nir_function_impl *impl,
for (unsigned i = 0; i < info->num_levels; i++) {
if (info->levels[i].split) {
nir_deref_instr *p = path.path[i + 1];
- unsigned index = nir_src_as_const_value(p->arr.index)->u32[0];
+ unsigned index = nir_src_as_uint(p->arr.index);
assert(index < info->levels[i].array_len);
split = &split->splits[index];
}
@@ -995,9 +995,8 @@ mark_deref_used(nir_deref_instr *deref,
unsigned max_used;
if (deref->deref_type == nir_deref_type_array) {
- nir_const_value *const_index =
- nir_src_as_const_value(deref->arr.index);
- max_used = const_index ? const_index->u32[0] : UINT_MAX;
+ max_used = nir_src_is_const(deref->arr.index) ?
+ nir_src_as_uint(deref->arr.index) : UINT_MAX;
} else {
/* For wildcards, we read or wrote the whole thing. */
assert(deref->deref_type == nir_deref_type_array_wildcard);
@@ -1316,8 +1315,8 @@ vec_deref_is_oob(nir_deref_instr *deref,
if (p->deref_type == nir_deref_type_array_wildcard)
continue;
- nir_const_value *const_index = nir_src_as_const_value(p->arr.index);
- if (const_index && const_index->u32[0] >= usage->levels[i].array_len) {
+ if (nir_src_is_const(p->arr.index) &&
+ nir_src_as_uint(p->arr.index) >= usage->levels[i].array_len) {
oob = true;
break;
}
diff --git a/src/compiler/nir/tests/vars_tests.cpp b/src/compiler/nir/tests/vars_tests.cpp
index 2896d9fce66..02c53804b84 100644
--- a/src/compiler/nir/tests/vars_tests.cpp
+++ b/src/compiler/nir/tests/vars_tests.cpp
@@ -374,9 +374,8 @@ TEST_F(nir_copy_prop_vars_test, store_store_load_different_components)
if (nir_intrinsic_get_var(store_to_v1, 0) == v[1]) {
ASSERT_TRUE(store_to_v1->src[1].is_ssa);
- nir_const_value *const_index = nir_src_as_const_value(store_to_v1->src[1]);
- ASSERT_TRUE(const_index);
- ASSERT_EQ(const_index->u32[1], 20);
+ ASSERT_TRUE(nir_src_is_const(store_to_v1->src[1]));
+ ASSERT_EQ(nir_src_as_uint(store_to_v1->src[1]), 20);
break;
}
}
@@ -424,9 +423,8 @@ TEST_F(nir_copy_prop_vars_test, store_store_load_different_components_in_many_bl
if (nir_intrinsic_get_var(store_to_v1, 0) == v[1]) {
ASSERT_TRUE(store_to_v1->src[1].is_ssa);
- nir_const_value *const_index = nir_src_as_const_value(store_to_v1->src[1]);
- ASSERT_TRUE(const_index);
- ASSERT_EQ(const_index->u32[1], 20);
+ ASSERT_TRUE(nir_src_is_const(store_to_v1->src[1]));
+ ASSERT_EQ(nir_src_as_uint(store_to_v1->src[1]), 20);
break;
}
}