added functions and macro to iterate over all node in the phase, having some data...
authorChristian Würdig <chriswue@ipd.info.uni-karlsruhe.de>
Fri, 13 Oct 2006 08:01:38 +0000 (08:01 +0000)
committerChristian Würdig <chriswue@ipd.info.uni-karlsruhe.de>
Fri, 13 Oct 2006 08:01:38 +0000 (08:01 +0000)
[r8345]

ir/ir/irphase.c
ir/ir/irphase_t.h

index 75d8ecb..e934a30 100644 (file)
@@ -82,3 +82,23 @@ void phase_reinit_single_irn_data(phase_t *phase, ir_node *irn)
        if (phase->data_ptr[idx])
                phase->data_init(phase, irn, phase->data_ptr[idx]);
 }
+
+ir_node *phase_get_first_node(phase_t *phase) {
+       int i;
+
+       for (i = 0; i < phase->n_data_ptr;  ++i)
+               if (phase->data_ptr[i])
+                       return get_idx_irn(phase->irg, i);
+
+       return NULL;
+}
+
+ir_node *phase_get_next_node(phase_t *phase, ir_node *start) {
+       int i;
+
+       for (i = get_irn_idx(start) + 1; i < phase->n_data_ptr; ++i)
+               if (phase->data_ptr[i])
+                       return get_idx_irn(phase->irg, i);
+
+       return NULL;
+}
index 9329ab5..ae30de2 100644 (file)
@@ -85,6 +85,28 @@ void phase_reinit_irn_data(phase_t *phase);
  */
 void phase_reinit_single_irn_data(phase_t *phase, ir_node *irn);
 
+/**
+ * Returns the first node of the phase having some data assigned.
+ * @param phase The phase.
+ * @return The first irn having some data assigned, NULL otherwise
+ */
+ir_node *phase_get_first_node(phase_t *phase);
+
+/**
+ * Returns the next node after @p start having some data assigned.
+ * @param phase The phase.
+ * @param start The node to start from
+ * @return The next node after start having some data assigned, NULL otherwise
+ */
+ir_node *phase_get_next_node(phase_t *phase, ir_node *start);
+
+/**
+ * Convenience macro to iterate over all nodes of a phase
+ * having some data assigned.
+ */
+#define foreach_phase_irn(phase, irn) \
+       for (irn = phase_get_first_node(phase); irn; irn = phase_get_next_node(phase, irn))
+
 /**
  * Get the name of the phase.
  */
@@ -202,5 +224,4 @@ static INLINE void *_phase_get_or_set_irn_data(phase_t *ph, ir_node *irn)
        return res;
 }
 
-
 #endif /* _FIRM_IR_PHASE_T_H */