nir/deref: add helpers to lazily create paths

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7511>
This commit is contained in:
Rhys Perry 2020-11-10 10:13:04 +00:00
parent 7d8c06d484
commit abc3225927
2 changed files with 30 additions and 0 deletions

View File

@ -641,6 +641,26 @@ nir_compare_derefs(nir_deref_instr *a, nir_deref_instr *b)
return result;
}
nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref)
{
if (!deref->_path) {
deref->_path = ralloc(mem_ctx, nir_deref_path);
nir_deref_path_init(deref->_path, deref->instr, mem_ctx);
}
return deref->_path;
}
nir_deref_compare_result nir_compare_derefs_and_paths(void *mem_ctx,
nir_deref_and_path *a,
nir_deref_and_path *b)
{
if (a->instr == b->instr) /* nir_compare_derefs has a fast path if a == b */
return nir_compare_derefs(a->instr, b->instr);
return nir_compare_deref_paths(nir_get_deref_path(mem_ctx, a),
nir_get_deref_path(mem_ctx, b));
}
struct rematerialize_deref_state {
bool progress;
nir_builder builder;

View File

@ -44,6 +44,11 @@ typedef struct {
nir_deref_instr **path;
} nir_deref_path;
typedef struct {
nir_deref_instr *instr;
nir_deref_path *_path;
} nir_deref_and_path;
void nir_deref_path_init(nir_deref_path *path,
nir_deref_instr *deref, void *mem_ctx);
void nir_deref_path_finish(nir_deref_path *path);
@ -54,6 +59,8 @@ unsigned nir_deref_instr_get_const_offset(nir_deref_instr *deref,
nir_ssa_def *nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
glsl_type_size_align_func size_align);
nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref);
typedef enum {
nir_derefs_do_not_alias = 0,
nir_derefs_equal_bit = (1 << 0),
@ -64,6 +71,9 @@ typedef enum {
nir_deref_compare_result nir_compare_deref_paths(nir_deref_path *a_path, nir_deref_path *b_path);
nir_deref_compare_result nir_compare_derefs(nir_deref_instr *a, nir_deref_instr *b);
nir_deref_compare_result nir_compare_derefs_and_paths(void *mem_ctx,
nir_deref_and_path *a,
nir_deref_and_path *b);
#ifdef __cplusplus
} /* extern "C" */