summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-01-23 16:57:40 -0800
committerJason Ekstrand <[email protected]>2015-01-26 11:24:58 -0800
commit27c6e3e4ca665c528b94937b1b0a7c10de515d89 (patch)
tree8a0be107cd9b3cf5ff26bc3731bbbbd6b9231288 /src
parent9f5fee880470a7e317aad35d4521cd525714455f (diff)
nir: Use pointers for nir_src_copy and nir_dest_copy
This avoids the overhead of copying structures and better matches the newly added nir_alu_src_copy and nir_alu_dest_copy. Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/glsl/nir/nir.c56
-rw-r--r--src/glsl/nir/nir.h4
-rw-r--r--src/glsl/nir/nir_from_ssa.c4
-rw-r--r--src/glsl/nir/nir_lower_atomics.c4
-rw-r--r--src/glsl/nir/nir_lower_io.c8
-rw-r--r--src/glsl/nir/nir_lower_locals_to_regs.c12
-rw-r--r--src/glsl/nir/nir_lower_samplers.cpp2
-rw-r--r--src/glsl/nir/nir_lower_system_values.c2
-rw-r--r--src/glsl/nir/nir_opt_peephole_select.c4
-rw-r--r--src/glsl/nir/nir_search.c4
10 files changed, 47 insertions, 53 deletions
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 0f9bfd947cf..25cdac0e815 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -135,50 +135,44 @@ nir_function_overload_create(nir_function *func)
return overload;
}
-nir_src nir_src_copy(nir_src src, void *mem_ctx)
+void nir_src_copy(nir_src *dest, const nir_src *src, void *mem_ctx)
{
- nir_src ret;
- ret.is_ssa = src.is_ssa;
- if (ret.is_ssa) {
- ret.ssa = src.ssa;
+ dest->is_ssa = src->is_ssa;
+ if (src->is_ssa) {
+ dest->ssa = src->ssa;
} else {
- ret.reg.base_offset = src.reg.base_offset;
- ret.reg.reg = src.reg.reg;
- if (src.reg.indirect) {
- ret.reg.indirect = ralloc(mem_ctx, nir_src);
- *ret.reg.indirect = *src.reg.indirect;
+ dest->reg.base_offset = src->reg.base_offset;
+ dest->reg.reg = src->reg.reg;
+ if (src->reg.indirect) {
+ dest->reg.indirect = ralloc(mem_ctx, nir_src);
+ nir_src_copy(dest->reg.indirect, src->reg.indirect, mem_ctx);
} else {
- ret.reg.indirect = NULL;
+ dest->reg.indirect = NULL;
}
}
-
- return ret;
}
-nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx)
+void nir_dest_copy(nir_dest *dest, const nir_dest *src, void *mem_ctx)
{
- nir_dest ret;
- ret.is_ssa = dest.is_ssa;
- if (ret.is_ssa) {
- ret.ssa = dest.ssa;
+ dest->is_ssa = src->is_ssa;
+ if (src->is_ssa) {
+ dest->ssa = src->ssa;
} else {
- ret.reg.base_offset = dest.reg.base_offset;
- ret.reg.reg = dest.reg.reg;
- if (dest.reg.indirect) {
- ret.reg.indirect = ralloc(mem_ctx, nir_src);
- *ret.reg.indirect = *dest.reg.indirect;
+ dest->reg.base_offset = src->reg.base_offset;
+ dest->reg.reg = src->reg.reg;
+ if (src->reg.indirect) {
+ dest->reg.indirect = ralloc(mem_ctx, nir_src);
+ nir_src_copy(dest->reg.indirect, src->reg.indirect, mem_ctx);
} else {
- ret.reg.indirect = NULL;
+ dest->reg.indirect = NULL;
}
}
-
- return ret;
}
void
nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src, void *mem_ctx)
{
- dest->src = nir_src_copy(src->src, mem_ctx);
+ nir_src_copy(&dest->src, &src->src, mem_ctx);
dest->abs = src->abs;
dest->negate = src->negate;
for (unsigned i = 0; i < 4; i++)
@@ -188,7 +182,7 @@ nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src, void *mem_ctx)
void
nir_alu_dest_copy(nir_alu_dest *dest, const nir_alu_dest *src, void *mem_ctx)
{
- dest->dest = nir_dest_copy(src->dest, mem_ctx);
+ nir_dest_copy(&dest->dest, &src->dest, mem_ctx);
dest->write_mask = src->write_mask;
dest->saturate = src->saturate;
}
@@ -563,7 +557,7 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref)
ret->base_offset = deref->base_offset;
ret->deref_array_type = deref->deref_array_type;
if (deref->deref_array_type == nir_deref_array_type_indirect) {
- ret->indirect = nir_src_copy(deref->indirect, mem_ctx);
+ nir_src_copy(&ret->indirect, &deref->indirect, mem_ctx);
}
ret->deref.type = deref->deref.type;
if (deref->deref.child)
@@ -1829,7 +1823,7 @@ ssa_def_rewrite_uses_src(nir_src *src, void *void_state)
struct ssa_def_rewrite_state *state = void_state;
if (src->is_ssa && src->ssa == state->old)
- *src = nir_src_copy(state->new_src, state->mem_ctx);
+ nir_src_copy(src, &state->new_src, state->mem_ctx);
return true;
}
@@ -1866,7 +1860,7 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src, void *mem_ctx)
nir_if *if_use = (nir_if *)entry->key;
_mesa_set_remove(def->if_uses, entry);
- if_use->condition = nir_src_copy(new_src, mem_ctx);
+ nir_src_copy(&if_use->condition, &new_src, mem_ctx);
_mesa_set_add(new_if_uses, if_use);
}
}
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 0ef83a174c2..3fb9d3b5fbe 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -521,8 +521,8 @@ nir_dest_for_reg(nir_register *reg)
return dest;
}
-nir_src nir_src_copy(nir_src src, void *mem_ctx);
-nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx);
+void nir_src_copy(nir_src *dest, const nir_src *src, void *mem_ctx);
+void nir_dest_copy(nir_dest *dest, const nir_dest *src, void *mem_ctx);
typedef struct {
nir_src src;
diff --git a/src/glsl/nir/nir_from_ssa.c b/src/glsl/nir/nir_from_ssa.c
index 840177bff7e..2e7add38d31 100644
--- a/src/glsl/nir/nir_from_ssa.c
+++ b/src/glsl/nir/nir_from_ssa.c
@@ -352,7 +352,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
nir_parallel_copy_entry);
exec_list_push_tail(&pcopy->entries, &entry->node);
- entry->src = nir_src_copy(src->src, state->dead_ctx);
+ nir_src_copy(&entry->src, &src->src, state->dead_ctx);
_mesa_set_add(src->src.ssa->uses, &pcopy->instr);
nir_ssa_dest_init(&pcopy->instr, &entry->dest,
@@ -622,7 +622,7 @@ emit_copy(nir_parallel_copy_instr *pcopy, nir_src src, nir_src dest_src,
assert(src.reg.reg->num_components >= dest_src.reg.reg->num_components);
nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov);
- mov->src[0].src = nir_src_copy(src, mem_ctx);
+ nir_src_copy(&mov->src[0].src, &src, mem_ctx);
mov->dest.dest = nir_dest_for_reg(dest_src.reg.reg);
mov->dest.write_mask = (1 << dest_src.reg.reg->num_components) - 1;
diff --git a/src/glsl/nir/nir_lower_atomics.c b/src/glsl/nir/nir_lower_atomics.c
index ec582f306c3..6ed53778e18 100644
--- a/src/glsl/nir/nir_lower_atomics.c
+++ b/src/glsl/nir/nir_lower_atomics.c
@@ -88,7 +88,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
nir_alu_instr *mul = nir_alu_instr_create(mem_ctx, nir_op_imul);
nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
mul->dest.write_mask = 0x1;
- mul->src[0].src = nir_src_copy(deref_array->indirect, mem_ctx);
+ nir_src_copy(&mul->src[0].src, &deref_array->indirect, mem_ctx);
mul->src[1].src.is_ssa = true;
mul->src[1].src.ssa = &atomic_counter_size->def;
nir_instr_insert_before(&instr->instr, &mul->instr);
@@ -116,7 +116,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
nir_src_for_ssa(&new_instr->dest.ssa),
mem_ctx);
} else {
- new_instr->dest = nir_dest_copy(instr->dest, mem_ctx);
+ nir_dest_copy(&new_instr->dest, &instr->dest, mem_ctx);
}
nir_instr_insert_before(&instr->instr, &new_instr->instr);
diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
index 8712869a0f5..ddbc249371b 100644
--- a/src/glsl/nir/nir_lower_io.c
+++ b/src/glsl/nir/nir_lower_io.c
@@ -148,8 +148,8 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
nir_op_imul);
mul->src[0].src.is_ssa = true;
mul->src[0].src.ssa = &load_const->def;
- mul->src[1].src = nir_src_copy(deref_array->indirect,
- state->mem_ctx);
+ nir_src_copy(&mul->src[1].src, &deref_array->indirect,
+ state->mem_ctx);
mul->dest.write_mask = 1;
nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
nir_instr_insert_before(instr, &mul->instr);
@@ -239,7 +239,7 @@ nir_lower_io_block(nir_block *block, void *void_state)
nir_src_for_ssa(&load->dest.ssa),
state->mem_ctx);
} else {
- load->dest = nir_dest_copy(intrin->dest, state->mem_ctx);
+ nir_dest_copy(&load->dest, &intrin->dest, state->mem_ctx);
}
nir_instr_insert_before(&intrin->instr, &load->instr);
@@ -272,7 +272,7 @@ nir_lower_io_block(nir_block *block, void *void_state)
store->const_index[0] = offset;
store->const_index[1] = 1;
- store->src[0] = nir_src_copy(intrin->src[0], state->mem_ctx);
+ nir_src_copy(&store->src[0], &intrin->src[0], state->mem_ctx);
if (has_indirect)
store->src[1] = indirect;
diff --git a/src/glsl/nir/nir_lower_locals_to_regs.c b/src/glsl/nir/nir_lower_locals_to_regs.c
index c04cb559239..8c5df7be672 100644
--- a/src/glsl/nir/nir_lower_locals_to_regs.c
+++ b/src/glsl/nir/nir_lower_locals_to_regs.c
@@ -168,14 +168,14 @@ get_deref_reg_src(nir_deref_var *deref, nir_instr *instr,
if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
if (src.reg.indirect == NULL) {
src.reg.indirect = ralloc(state->mem_ctx, nir_src);
- *src.reg.indirect = nir_src_copy(deref_array->indirect,
- state->mem_ctx);
+ nir_src_copy(src.reg.indirect, &deref_array->indirect,
+ state->mem_ctx);
} else {
nir_alu_instr *add = nir_alu_instr_create(state->mem_ctx,
nir_op_iadd);
add->src[0].src = *src.reg.indirect;
- add->src[1].src = nir_src_copy(deref_array->indirect,
- state->mem_ctx);
+ nir_src_copy(&add->src[1].src, &deref_array->indirect,
+ state->mem_ctx);
add->dest.write_mask = 1;
nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, NULL);
nir_instr_insert_before(instr, &add->instr);
@@ -216,7 +216,7 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
nir_src_for_ssa(&mov->dest.dest.ssa),
state->mem_ctx);
} else {
- mov->dest.dest = nir_dest_copy(intrin->dest, state->mem_ctx);
+ nir_dest_copy(&mov->dest.dest, &intrin->dest, state->mem_ctx);
}
nir_instr_insert_before(&intrin->instr, &mov->instr);
@@ -232,7 +232,7 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
&intrin->instr, state);
nir_alu_instr *mov = nir_alu_instr_create(state->mem_ctx, nir_op_imov);
- mov->src[0].src = nir_src_copy(intrin->src[0], state->mem_ctx);
+ nir_src_copy(&mov->src[0].src, &intrin->src[0], state->mem_ctx);
mov->dest.write_mask = (1 << intrin->num_components) - 1;
mov->dest.dest.is_ssa = false;
mov->dest.dest.reg.reg = reg_src.reg.reg;
diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp
index 99f31fc0281..dca086d709e 100644
--- a/src/glsl/nir/nir_lower_samplers.cpp
+++ b/src/glsl/nir/nir_lower_samplers.cpp
@@ -102,7 +102,7 @@ lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,
nir_instr_rewrite_src(&instr->instr,
&instr->src[instr->num_srcs - 1].src,
- nir_src_copy(deref_array->indirect, mem_ctx));
+ deref_array->indirect);
instr->sampler_array_size = glsl_get_length(deref->type);
diff --git a/src/glsl/nir/nir_lower_system_values.c b/src/glsl/nir/nir_lower_system_values.c
index dc12f406e7c..90346c975c1 100644
--- a/src/glsl/nir/nir_lower_system_values.c
+++ b/src/glsl/nir/nir_lower_system_values.c
@@ -76,7 +76,7 @@ convert_instr(nir_intrinsic_instr *instr)
nir_src_for_ssa(&new_instr->dest.ssa),
mem_ctx);
} else {
- new_instr->dest = nir_dest_copy(instr->dest, mem_ctx);
+ nir_dest_copy(&new_instr->dest, &instr->dest, mem_ctx);
}
nir_instr_insert_before(&instr->instr, &new_instr->instr);
diff --git a/src/glsl/nir/nir_opt_peephole_select.c b/src/glsl/nir/nir_opt_peephole_select.c
index 21bdd263bd5..ab08f286f7e 100644
--- a/src/glsl/nir/nir_opt_peephole_select.c
+++ b/src/glsl/nir/nir_opt_peephole_select.c
@@ -135,7 +135,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
nir_phi_instr *phi = nir_instr_as_phi(instr);
nir_alu_instr *sel = nir_alu_instr_create(state->mem_ctx, nir_op_bcsel);
- sel->src[0].src = nir_src_copy(if_stmt->condition, state->mem_ctx);
+ nir_src_copy(&sel->src[0].src, &if_stmt->condition, state->mem_ctx);
/* Splat the condition to all channels */
memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);
@@ -156,7 +156,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
nir_alu_src_copy(&sel->src[idx], &mov->src[0], state->mem_ctx);
} else {
- sel->src[idx].src = nir_src_copy(src->src, state->mem_ctx);
+ nir_src_copy(&sel->src[idx].src, &src->src, state->mem_ctx);
}
}
diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c
index 7ef22e89ab5..18e0330e4ae 100644
--- a/src/glsl/nir/nir_search.c
+++ b/src/glsl/nir/nir_search.c
@@ -233,8 +233,8 @@ construct_value(const nir_search_value *value, nir_alu_type type,
const nir_search_variable *var = nir_search_value_as_variable(value);
assert(state->variables_seen & (1 << var->variable));
- nir_alu_src val = state->variables[var->variable];
- val.src = nir_src_copy(val.src, mem_ctx);
+ nir_alu_src val;
+ nir_alu_src_copy(&val, &state->variables[var->variable], mem_ctx);
return val;
}