iredges: introduce new reroute_edges_except
authorMatthias Braun <matthias.braun@kit.edu>
Thu, 21 Jun 2012 09:46:29 +0000 (11:46 +0200)
committerMatthias Braun <matthias.braun@kit.edu>
Thu, 21 Jun 2012 09:46:29 +0000 (11:46 +0200)
I expect this to be a common pattern

include/libfirm/iredges.h
ir/ir/iredges.c

index 2819722..8847378 100644 (file)
@@ -161,6 +161,13 @@ FIRM_API void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind);
  */
 FIRM_API void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind);
 
+/**
+ * reroutes (normal) edges from an old node to a new node, except for the
+ * @p exception which keeps its input even if it is old.
+ */
+FIRM_API void edges_reroute_except(ir_node *old, ir_node *nw,
+                                   ir_node *exception);
+
 /**
  * Verifies the out edges of graph @p irg.
  * @return 1 if a problem was found, 0 otherwise
index c83d497..cb163b1 100644 (file)
@@ -657,6 +657,18 @@ void edges_reroute_kind(ir_node *from, ir_node *to, ir_edge_kind_t kind)
        }
 }
 
+void edges_reroute_except(ir_node *from, ir_node *to, ir_node *exception)
+{
+       const ir_edge_t *edge;
+       const ir_edge_t *next;
+       foreach_out_edge_safe(from, edge, next) {
+               ir_node *src = get_edge_src_irn(edge);
+               if (src == exception)
+                       continue;
+               set_irn_n(src, edge->pos, to);
+       }
+}
+
 static void verify_set_presence(ir_node *irn, void *data)
 {
        build_walker *w     = (build_walker*)data;