becopyilp: Do not advertise the switch to dump the solution, because this is not...
[libfirm] / ir / opt / parallelize_mem.c
index 8332dd0..75bd5a2 100644 (file)
@@ -1,27 +1,12 @@
 /*
- * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
  * @file
  * @brief   parallelizing Load/Store optimisation
  * @author  Christoph Mallon
- * @version $Id: $
  */
 #include "config.h"
 
@@ -42,7 +27,7 @@
 #include "irflag_t.h"
 #include "irprintf.h"
 #include "irpass.h"
-#include "opt_manage.h"
+#include "iredges.h"
 
 typedef struct parallelize_info
 {
@@ -192,45 +177,32 @@ static void walker(ir_node *proj, void *env)
        }
 
        n = ir_nodeset_size(&pi.user_mem);
-       if (n != 0) { /* nothing happened otherwise */
-               ir_graph               *irg  = get_irn_irg(block);
-               ir_node                *sync;
-               ir_node               **in;
-               ir_nodeset_iterator_t   iter;
-               size_t                  i;
+       if (n > 0) { /* nothing happened otherwise */
+               ir_node  *sync;
+               ir_node **in   = XMALLOCN(ir_node*, n+1);
+               size_t    i;
 
-               ++n;
-               NEW_ARR_A(ir_node*, in, n);
                i = 0;
-               in[i++] = new_r_Unknown(irg, mode_M);
-               ir_nodeset_iterator_init(&iter, &pi.user_mem);
-               for (;;) {
-                       ir_node* p = ir_nodeset_iterator_next(&iter);
-                       if (p == NULL) break;
-                       in[i++] = p;
+               in[i++] = proj;
+               foreach_ir_nodeset(&pi.user_mem, node, iter) {
+                       in[i++] = node;
                }
-               assert(i == n);
-               sync = new_r_Sync(block, n, in);
-               exchange(proj, sync);
-
-               assert((long)pn_Load_M == (long)pn_Store_M);
-               proj = new_r_Proj(mem_op, mode_M, pn_Load_M);
-               set_Sync_pred(sync, 0, proj);
+               assert(i == n+1);
+               sync = new_r_Sync(block, i, in);
+               xfree(in);
+               edges_reroute_except(proj, sync, sync);
 
                n = ir_nodeset_size(&pi.this_mem);
-               ir_nodeset_iterator_init(&iter, &pi.this_mem);
                if (n == 1) {
-                       sync = ir_nodeset_iterator_next(&iter);
+                       sync = ir_nodeset_first(&pi.this_mem);
                } else {
-                       NEW_ARR_A(ir_node*, in, n);
+                       in = XMALLOCN(ir_node*, n);
                        i = 0;
-                       for (;;) {
-                               ir_node* p = ir_nodeset_iterator_next(&iter);
-                               if (p == NULL) break;
-                               in[i++] = p;
+                       foreach_ir_nodeset(&pi.this_mem, node, iter) {
+                               in[i++] = node;
                        }
                        assert(i == n);
-                       sync = new_r_Sync(block, n, in);
+                       sync = new_r_Sync(block, i, in);
                }
                set_memop_mem(mem_op, sync);
        }
@@ -239,22 +211,11 @@ static void walker(ir_node *proj, void *env)
        ir_nodeset_destroy(&pi.user_mem);
 }
 
-static ir_graph_state_t do_parallelize_mem(ir_graph *irg)
-{
-       irg_walk_graph(irg, NULL, walker, NULL);
-
-       return 0;
-}
-
-optdesc_t opt_parallel_mem = {
-       "parallel-mem",
-       0,
-       do_parallelize_mem,
-};
-
 void opt_parallelize_mem(ir_graph *irg)
 {
-       perform_irg_optimization(irg, &opt_parallel_mem);
+       assure_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES);
+       irg_walk_graph(irg, NULL, walker, NULL);
+       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_CONTROL_FLOW);
 }
 
 ir_graph_pass_t *opt_parallelize_mem_pass(const char *name)