nir: Fix dom_children memory leak
If nir_metadata_dominance
is updated multiple times, the dominance child array allocations from previous updates, which are created in the same context as the entire nir_function_impl
, won't be abandoned.
I wasn't able to find any locations where freeing is currently done, so I think my change is necessary, and I'm not freeing them twice.
This fix uses reralloc
— though it wastes some time copying the previous data if a reallocation happens, I'm expecting (though I'm not sure if my assumption is true in reality) that the dominance children of many blocks will stay the same often after cases of dominance metadata invalidation, so it may be cheaper than freeing and reallocating all arrays at every update? But an alternate implementation would free dom_children
and set it to NULL
in init_block
.
Regarding the changes to nir_block_create
— I see that the instance of the nir_block
structure is allocated with rzalloc
, so all its fields are zero or NULL
initially, but later certain fields are set to NULL
there explicitly. Should I keep the zeroing I added to clearly express the intention for that field specifically (the first operation that sets dom_children
to something useful explicitly expects NULL
there initially; though this is not necessary for num_dom_children
, but for consistency, and maybe to avoid the assumption there that reallocation doesn't need the original size), or would it be better to leave it as is or even remove all other existing zeroing there for consistency?