X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firedges_t.h;h=6820ce6532032eb0c9bc4b4512d0d8958405365b;hb=eb38e825ba0a4295779cd431856a379643cb347f;hp=ccac2e16da28a33863aac74796c19d28cd591d5c;hpb=22d85c0a3fd056a84c16a0772e54935c4b87f0f5;p=libfirm diff --git a/ir/ir/iredges_t.h b/ir/ir/iredges_t.h index ccac2e16d..6820ce653 100644 --- a/ir/ir/iredges_t.h +++ b/ir/ir/iredges_t.h @@ -1,14 +1,31 @@ +/* + * 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. + */ /** - * everlasting outs. - * @author Sebastian Hack - * @date 15.1.2005 + * @file + * @brief Everlasting outs -- private header. + * @author Sebastian Hack, Andreas Schoesser + * @date 15.01.2005 */ +#ifndef FIRM_IR_EDGES_T_H +#define FIRM_IR_EDGES_T_H -#ifndef _FIRM_EDGES_T_H -#define _FIRM_EDGES_T_H - -#include "config.h" #include "debug.h" #include "set.h" @@ -17,35 +34,56 @@ #include "irnode_t.h" #include "irgraph_t.h" +#include "iredgekinds.h" #include "iredges.h" -#define DBG_EDGES "edges" +#define get_irn_n_edges_kind(irn, kind) get_irn_n_edges_kind_(irn, kind) +#define get_edge_src_irn(edge) get_edge_src_irn_(edge) +#define get_edge_src_pos(edge) get_edge_src_pos_(edge) +#define get_irn_out_edge_next(irn, last, kind) get_irn_out_edge_next_(irn, last, kind) +#define get_irn_n_edges(irn) get_irn_n_edges_kind_(irn, EDGE_KIND_NORMAL) +#define get_irn_out_edge_first(irn) get_irn_out_edge_first_kind_(irn, EDGE_KIND_NORMAL) +#define get_block_succ_first(irn) get_irn_out_edge_first_kind_(irn, EDGE_KIND_BLOCK) +#define get_block_succ_next(irn, last) get_irn_out_edge_next_(irn, last, EDGE_KIND_BLOCK) /** * An edge. */ -typedef struct _ir_edge_t { +struct ir_edge_t { + ir_node *src; /**< The source node of the edge. */ + int pos; /**< The position of the edge at @p src. */ #ifdef DEBUG_libfirm - long src_nr; /**< The node number of the source node. */ + unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */ #endif - ir_node *src; /**< The source node of the edge. */ - int pos; /**< The position of the edge at @p src. */ struct list_head list; /**< The list head to queue all out edges at a node. */ - unsigned invalid : 1; /**< edges that are removed are marked invalid. */ - unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */ -} ir_edge_t; +}; /** Accessor for private irn info. */ -#define _get_irn_edge_info(irn) ((irn_edge_info_t *) &(irn)->edge_info) +static inline irn_edge_info_t *get_irn_edge_info(ir_node *node, + ir_edge_kind_t kind) +{ + return &node->edge_info[kind]; +} + +static inline const irn_edge_info_t *get_irn_edge_info_const( + const ir_node *node, ir_edge_kind_t kind) +{ + return &node->edge_info[kind]; +} /** Accessor for private irg info. */ -#define _get_irg_edge_info(irg) ((irg_edge_info_t *) &(irg)->edge_info) +static inline irg_edge_info_t *get_irg_edge_info(ir_graph *irg, + ir_edge_kind_t kind) +{ + return &irg->edge_info[kind]; +} -/** - * Convenience macro to get the outs_head from a irn_edge_info_t - * struct. - */ -#define _get_irn_outs_head(irn) (&_get_irn_edge_info(irn)->outs_head) +/** Accessor for private irg info. */ +static inline const irg_edge_info_t *get_irg_edge_info_const( + const ir_graph *irg, ir_edge_kind_t kind) +{ + return &irg->edge_info[kind]; +} /** * Get the first edge pointing to some node. @@ -54,9 +92,11 @@ typedef struct _ir_edge_t { * @param irn The node. * @return The first out edge that points to this node. */ -static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn) +static inline const ir_edge_t *get_irn_out_edge_first_kind_(const ir_node *irn, ir_edge_kind_t kind) { - struct list_head *head = _get_irn_outs_head(irn); + const struct list_head *head; + assert(edges_activated_kind(get_irn_irg(irn), kind)); + head = &get_irn_edge_info_const(irn, kind)->outs_head; return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list); } @@ -66,55 +106,76 @@ static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn) * @param last The last out edge you have seen. * @return The next out edge in @p irn 's out list after @p last. */ -static INLINE const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last) +static inline const ir_edge_t *get_irn_out_edge_next_(const ir_node *irn, const ir_edge_t *last, ir_edge_kind_t kind) { struct list_head *next = last->list.next; - return next == _get_irn_outs_head(irn) ? NULL : list_entry(next, ir_edge_t, list); + const struct list_head *head + = &get_irn_edge_info_const(irn, kind)->outs_head; + return next == head ? NULL : list_entry(next, ir_edge_t, list); } /** - * A convenience iteration macro over all out edges of a node. + * Get the number of edges pointing to a node. * @param irn The node. - * @param edge An @c ir_edge_t pointer which shall be set to the current - * edge. + * @return The number of edges pointing to this node. */ -#define foreach_out_edge(irn,edge) \ - for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge)) +static inline int get_irn_n_edges_kind_(const ir_node *irn, ir_edge_kind_t kind) +{ + return get_irn_edge_info_const(irn, kind)->out_count; +} -/** - * Get the source node of an edge. - * @param edge The edge. - * @return The source node of that edge. - */ -static INLINE ir_node *_get_edge_src_irn(const ir_edge_t *edge) +static inline int edges_activated_kind_(const ir_graph *irg, ir_edge_kind_t kind) { - return edge ? edge->src : NULL; + return get_irg_edge_info_const(irg, kind)->activated; } -/** - * Get the position of an edge. - * @param edge. - * @return The position in the in array of that edges source. - */ -static INLINE int _get_edge_src_pos(const ir_edge_t *edge) +static inline int edges_activated_(const ir_graph *irg) { - return edge ? edge->pos : -1; + return edges_activated_kind(irg, EDGE_KIND_NORMAL) + && edges_activated_kind(irg, EDGE_KIND_BLOCK); } -static INLINE int _edges_activated(const ir_graph *irg) +/** + * Assure, that the edges information is present for a certain graph. + * @param irg The graph. + */ +static inline void edges_assure_kind_(ir_graph *irg, ir_edge_kind_t kind) { - return _get_irg_edge_info(irg)->activated; + if(!edges_activated_kind_(irg, kind)) + edges_activate_kind(irg, kind); } -void edges_reroute(ir_node *old, ir_node *nw, ir_graph *irg); +void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind); -void edges_init_graph(ir_graph *irg); +void edges_node_deleted(ir_node *irn); -void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg); +/** + * A node might be revivaled by CSE. + */ +void edges_node_revival(ir_node *node); + +void edges_invalidate_kind(ir_node *irn, ir_edge_kind_t kind); + +static inline ir_node *get_edge_src_irn_(const ir_edge_t *edge) +{ + return edge->src; +} -void edges_node_deleted(ir_node *old, ir_graph *irg); +static inline int get_edge_src_pos_(const ir_edge_t *edge) +{ + return edge->pos; +} -void edges_invalidate(ir_node *irn, ir_graph *irg); +/** + * Returns the edge object of an outgoing edge at a node. + * @param irn The node at which the edge originates. + * @param pos The position of the edge. + * @param kind The kind of the edge. + * @return The corresponding edge object or NULL, + * if no such edge exists. + */ +FIRM_API const ir_edge_t *get_irn_edge_kind(const ir_node *irn, + int pos, ir_edge_kind_t kind); /** * Initialize the out edges. @@ -122,10 +183,15 @@ void edges_invalidate(ir_node *irn, ir_graph *irg); */ extern void init_edges(void); -#define get_irn_out_edge_first(irn) _get_irn_out_edge_first(irn) -#define get_irn_out_edge_next(irn,last) _get_irn_out_edge_next(irn, last) -#define get_edge_src_irn(edge) _get_edge_src_irn(edge) -#define get_edge_src_pos(edge) _get_edge_src_pos(edge) -#define edges_activated(irg) _edges_activated(irg) +void edges_invalidate_all(ir_node *irn); -#endif /* _FIRM_EDGES_T_H */ +/** + * Helper function to dump the edge set of a graph, + * unused in normal code. + */ +void edges_dump_kind(ir_graph *irg, ir_edge_kind_t kind); + +void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, + ir_graph *irg); + +#endif