nir: Combine if_uses with instruction uses

Every nir_ssa_def is part of a chain of uses, implemented with doubly linked
lists.  That means each requires 2 * 64-bit = 16 bytes per def, which is
memory intensive. Together they require 32 bytes per def. Not cool.

To cut that memory use in half, we can combine the two linked lists into a
single use list that contains both regular instruction uses and if-uses. To do
this, we augment the nir_src with a boolean "is_if", and reimplement the
abstract if-uses operations on top of that list. That boolean should fit into
the padding already in nir_src so should not actually affect memory use, and in
the future we sneak it into the bottom bit of a pointer.

However, this creates a new inefficiency: now iterating over regular uses
separate from if-uses is (nominally) more expensive. It turns out virtually
every caller of nir_foreach_if_use(_safe) also calls nir_foreach_use(_safe)
immediately before, so we rewrite most of the callers to instead call a new
single `nir_foreach_use_including_if(_safe)` which predicates the logic based on
`src->is_if`. This should mitigate the performance difference.

There's a bit of churn, but this is largely a mechanical set of changes.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22343>
This commit is contained in:
Alyssa Rosenzweig
2023-04-06 13:19:31 -04:00
committed by Marge Bot
parent fd9c69218a
commit 7f6491b76d
38 changed files with 329 additions and 372 deletions

View File

@@ -178,8 +178,8 @@ instr_cost(loop_info_state *state, nir_instr *instr,
/* Also if the selects condition is only used by the select then
* remove that alu instructons cost from the cost total also.
*/
if (!list_is_empty(&sel_alu->dest.dest.ssa.if_uses) ||
!list_is_singular(&sel_alu->dest.dest.ssa.uses))
if (!list_is_singular(&sel_alu->dest.dest.ssa.uses) ||
nir_ssa_def_used_by_if(&sel_alu->dest.dest.ssa))
return 0;
else
return -1;