aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/nir/nir_opt_peephole_ffma.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-04-24 10:16:27 -0700
committerJason Ekstrand <[email protected]>2015-05-08 17:16:13 -0700
commitf752effa087f29faddabac047683d16416d178d9 (patch)
tree4330f1886dd69bcbe03837e55c43a42df89c098e /src/glsl/nir/nir_opt_peephole_ffma.c
parent2c2cd368aad9167816547aa86009c9cb489255c0 (diff)
nir/nir: Use a linked list instead of a hash set for use/def sets
This commit switches us from the current setup of using hash sets for use/def sets to using linked lists. Doing so should save us quite a bit of memory because we aren't carrying around 3 hash sets per register and 2 per SSA value. It should also save us CPU time because adding/removing things from use/def sets is 4 pointer manipulations instead of a hash lookup. Running shader-db 50 times with USE_NIR=0, NIR, and NIR + use/def lists: GLSL IR Only: 586.4 +/- 1.653833 NIR with hash sets: 675.4 +/- 2.502108 NIR + use/def lists: 641.2 +/- 1.557043 I also ran a memory usage experiment with Ken's patch to delete GLSL IR and keep NIR. This patch cuts an aditional 42.9 MiB of ralloc'd memory over and above what we gained by deleting the GLSL IR on the same dota trace. On the code complexity side of things, some things are now much easier and others are a bit harder. One of the operations we perform constantly in optimization passes is to replace one source with another. Due to the fact that an instruction can use the same SSA value multiple times, we had to iterate through the sources of the instruction and determine if the use we were replacing was the only one before removing it from the set of uses. With this patch, uses are per-source not per-instruction so we can just remove it safely. On the other hand, trying to iterate over all of the instructions that use a given value is more difficult. Fortunately, the two places we do that are the ffma peephole where it doesn't matter and GCM where we already gracefully handle duplicates visits to an instruction. Another aspect here is that using linked lists in this way can be tricky to get right. With sets, things were quite forgiving and the worst that happened if you didn't properly remove a use was that it would get caught in the validator. With linked lists, it can lead to linked list corruption which can be harder to track. However, we do just as much validation of the linked lists as we did of the sets so the validator should still catch these problems. While working on this series, the vast majority of the bugs I had to fix were caught by assertions. I don't think the lists are going to be that much worse than the sets. Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/glsl/nir/nir_opt_peephole_ffma.c')
-rw-r--r--src/glsl/nir/nir_opt_peephole_ffma.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/glsl/nir/nir_opt_peephole_ffma.c b/src/glsl/nir/nir_opt_peephole_ffma.c
index 9d5646fe65e..b430eac8eab 100644
--- a/src/glsl/nir/nir_opt_peephole_ffma.c
+++ b/src/glsl/nir/nir_opt_peephole_ffma.c
@@ -41,12 +41,11 @@ struct peephole_ffma_state {
static inline bool
are_all_uses_fadd(nir_ssa_def *def)
{
- if (def->if_uses->entries > 0)
+ if (!list_empty(&def->if_uses))
return false;
- struct set_entry *use_iter;
- set_foreach(def->uses, use_iter) {
- nir_instr *use_instr = (nir_instr *)use_iter->key;
+ nir_foreach_use(def, use_src) {
+ nir_instr *use_instr = use_src->parent_instr;
if (use_instr->type != nir_instr_type_alu)
return false;
@@ -220,7 +219,7 @@ nir_opt_peephole_ffma_block(nir_block *block, void *void_state)
state->mem_ctx);
nir_instr_insert_before(&add->instr, &ffma->instr);
- assert(add->dest.dest.ssa.uses->entries == 0);
+ assert(list_empty(&add->dest.dest.ssa.uses));
nir_instr_remove(&add->instr);
state->progress = true;