nir: Switch the arguments to nir_foreach_use and friends
[mesa.git] / src / compiler / nir / nir.c
index da016b4bd71e2c59036d6fa9e9ed7f3aee92e42b..867a43cefbdfe0d1415bc64ff5c58cf4c459f64e 100644 (file)
@@ -981,7 +981,7 @@ static bool
 visit_parallel_copy_dest(nir_parallel_copy_instr *instr,
                          nir_foreach_dest_cb cb, void *state)
 {
-   nir_foreach_parallel_copy_entry(instr, entry) {
+   nir_foreach_parallel_copy_entry(entry, instr) {
       if (!cb(&entry->dest, state))
          return false;
    }
@@ -1162,7 +1162,7 @@ visit_load_const_src(nir_load_const_instr *instr, nir_foreach_src_cb cb,
 static bool
 visit_phi_src(nir_phi_instr *instr, nir_foreach_src_cb cb, void *state)
 {
-   nir_foreach_phi_src(instr, src) {
+   nir_foreach_phi_src(src, instr) {
       if (!visit_src(&src->src, cb, state))
          return false;
    }
@@ -1174,7 +1174,7 @@ static bool
 visit_parallel_copy_src(nir_parallel_copy_instr *instr,
                         nir_foreach_src_cb cb, void *state)
 {
-   nir_foreach_parallel_copy_entry(instr, entry) {
+   nir_foreach_parallel_copy_entry(entry, instr) {
       if (!visit_src(&entry->src, cb, state))
          return false;
    }
@@ -1419,10 +1419,10 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src)
 {
    assert(!new_src.is_ssa || def != new_src.ssa);
 
-   nir_foreach_use_safe(def, use_src)
+   nir_foreach_use_safe(use_src, def)
       nir_instr_rewrite_src(use_src->parent_instr, use_src, new_src);
 
-   nir_foreach_if_use_safe(def, use_src)
+   nir_foreach_if_use_safe(use_src, def)
       nir_if_rewrite_condition(use_src->parent_if, new_src);
 }
 
@@ -1462,7 +1462,7 @@ nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src,
 {
    assert(!new_src.is_ssa || def != new_src.ssa);
 
-   nir_foreach_use_safe(def, use_src) {
+   nir_foreach_use_safe(use_src, def) {
       assert(use_src->parent_instr != def->parent_instr);
       /* Since def already dominates all of its uses, the only way a use can
        * not be dominated by after_me is if it is between def and after_me in
@@ -1472,7 +1472,7 @@ nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src,
          nir_instr_rewrite_src(use_src->parent_instr, use_src, new_src);
    }
 
-   nir_foreach_if_use_safe(def, use_src)
+   nir_foreach_if_use_safe(use_src, def)
       nir_if_rewrite_condition(use_src->parent_if, new_src);
 }
 
@@ -1480,7 +1480,7 @@ uint8_t
 nir_ssa_def_components_read(nir_ssa_def *def)
 {
    uint8_t read_mask = 0;
-   nir_foreach_use(def, use) {
+   nir_foreach_use(use, def) {
       if (use->parent_instr->type == nir_instr_type_alu) {
          nir_alu_instr *alu = nir_instr_as_alu(use->parent_instr);
          nir_alu_src *alu_src = exec_node_data(nir_alu_src, use, src);
@@ -1673,13 +1673,6 @@ nir_block_get_following_loop(nir_block *block)
 
    return nir_cf_node_as_loop(next_node);
 }
-static bool
-index_block(nir_block *block, void *state)
-{
-   unsigned *index = state;
-   block->index = (*index)++;
-   return true;
-}
 
 void
 nir_index_blocks(nir_function_impl *impl)
@@ -1689,7 +1682,9 @@ nir_index_blocks(nir_function_impl *impl)
    if (impl->valid_metadata & nir_metadata_block_index)
       return;
 
-   nir_foreach_block_call(impl, index_block, &index);
+   nir_foreach_block(block, impl) {
+      block->index = index++;
+   }
 
    impl->num_blocks = index;
 }
@@ -1703,15 +1698,6 @@ index_ssa_def_cb(nir_ssa_def *def, void *state)
    return true;
 }
 
-static bool
-index_ssa_block(nir_block *block, void *state)
-{
-   nir_foreach_instr(block, instr)
-      nir_foreach_ssa_def(instr, index_ssa_def_cb, state);
-
-   return true;
-}
-
 /**
  * The indices are applied top-to-bottom which has the very nice property
  * that, if A dominates B, then A->index <= B->index.
@@ -1720,18 +1706,13 @@ void
 nir_index_ssa_defs(nir_function_impl *impl)
 {
    unsigned index = 0;
-   nir_foreach_block_call(impl, index_ssa_block, &index);
-   impl->ssa_alloc = index;
-}
 
-static bool
-index_instrs_block(nir_block *block, void *state)
-{
-   unsigned *index = state;
-   nir_foreach_instr(block, instr)
-      instr->index = (*index)++;
+   nir_foreach_block(block, impl) {
+      nir_foreach_instr(instr, block)
+         nir_foreach_ssa_def(instr, index_ssa_def_cb, &index);
+   }
 
-   return true;
+   impl->ssa_alloc = index;
 }
 
 /**
@@ -1742,7 +1723,12 @@ unsigned
 nir_index_instrs(nir_function_impl *impl)
 {
    unsigned index = 0;
-   nir_foreach_block_call(impl, index_instrs_block, &index);
+
+   nir_foreach_block(block, impl) {
+      nir_foreach_instr(instr, block)
+         instr->index = index++;
+   }
+
    return index;
 }