From: Christian Würdig Date: Fri, 13 Oct 2006 08:01:38 +0000 (+0000) Subject: added functions and macro to iterate over all node in the phase, having some data... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=2763e57ac1a5a9bd20d50064658a1d20f0be77ca;p=libfirm added functions and macro to iterate over all node in the phase, having some data assigned [r8345] --- diff --git a/ir/ir/irphase.c b/ir/ir/irphase.c index 75d8ecbcb..e934a3039 100644 --- a/ir/ir/irphase.c +++ b/ir/ir/irphase.c @@ -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; +} diff --git a/ir/ir/irphase_t.h b/ir/ir/irphase_t.h index 9329ab595..ae30de233 100644 --- a/ir/ir/irphase_t.h +++ b/ir/ir/irphase_t.h @@ -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 */