nir: fix memory leak in nir_cf_list_clone
[mesa.git] / src / compiler / nir / nir_liveness.c
index 69c6fd93b5857663291c4a21259bd81b167eb760..16dbeb4a22302a231ba3d662a1b61ec9544b69c3 100644 (file)
@@ -46,6 +46,9 @@ struct live_ssa_defs_state {
    unsigned num_ssa_defs;
    unsigned bitset_words;
 
+   /* Used in propagate_across_edge() */
+   BITSET_WORD *tmp_live;
+
    nir_block_worklist worklist;
 };
 
@@ -121,7 +124,7 @@ static bool
 propagate_across_edge(nir_block *pred, nir_block *succ,
                       struct live_ssa_defs_state *state)
 {
-   NIR_VLA(BITSET_WORD, live, state->bitset_words);
+   BITSET_WORD *live = state->tmp_live;
    memcpy(live, succ->live_in, state->bitset_words * sizeof *live);
 
    nir_foreach_instr(instr, succ) {
@@ -138,7 +141,7 @@ propagate_across_edge(nir_block *pred, nir_block *succ,
          break;
       nir_phi_instr *phi = nir_instr_as_phi(instr);
 
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          if (src->pred == pred) {
             set_src_live(&src->src, live);
             break;
@@ -176,6 +179,7 @@ nir_live_ssa_defs_impl(nir_function_impl *impl)
     * blocks to the worklist.
     */
    state.bitset_words = BITSET_WORDS(state.num_ssa_defs);
+   state.tmp_live = rzalloc_array(impl, BITSET_WORD, state.bitset_words);
    nir_foreach_block(block, impl) {
       init_liveness_block(block, &state);
    }
@@ -218,7 +222,6 @@ nir_live_ssa_defs_impl(nir_function_impl *impl)
        * changed, add the predecessor to the work list so that we ensure
        * that the new information is used.
        */
-      struct set_entry *entry;
       set_foreach(block->predecessors, entry) {
          nir_block *pred = (nir_block *)entry->key;
          if (propagate_across_edge(pred, block, &state))
@@ -226,6 +229,7 @@ nir_live_ssa_defs_impl(nir_function_impl *impl)
       }
    }
 
+   ralloc_free(state.tmp_live);
    nir_block_worklist_fini(&state.worklist);
 }