added macro foreach_out_edges_safe(), which allows an iteration over a
[libfirm] / ir / ir / iredges.h
index d726ab2..23c7a5d 100644 (file)
@@ -47,6 +47,23 @@ const ir_edge_t *get_irn_out_edge_next(const ir_node *irn,
 #define foreach_out_edge(irn,edge) \
        for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge))
 
+/**
+ * A convenience iteration macro over all out edges of a node, which is safe
+ * against alteration of the current edge.
+ * @param irn The node.
+ * @param edge An @c ir_edge_t pointer which shall be set to the current
+ * edge.
+ * @param ne The next edge, enables alteration safe erge processing.
+ */
+#define foreach_out_edge_safe(irn,edge,ne) \
+       for( \
+               (edge) = (get_irn_out_edge_first(irn)), \
+                       (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL); \
+               edge; \
+               (edge) = (ne), (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL) \
+       )
+
+
 /**
  * A convenience iteration macro for all control flow edges
  * leaving a block, and thus are cf successor edges.
@@ -77,6 +94,16 @@ int get_irn_n_edges(const ir_node *irn);
  */
 extern int get_edge_src_pos(const ir_edge_t *edge);
 
+/**
+ * Get the edge object of an outgoing edge at a node.
+ * @param   irg The graph, the node is in.
+ * @param   irn The node at which the edge originates.
+ * @param   pos The position of the edge.
+ * @return      The corresponding edge object or NULL,
+ *              if no such edge exists.
+ */
+const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *irn, int pos);
+
 /**
  * Check, if the out edges are activated.
  * @param irg The graph.