X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbelive_t.h;h=086171b53ce345692d746d6a6dea949a44a53e41;hb=1670ff3bb630369f79c4f2a1846ebcf32fe19133;hp=5d446caa2b45b39dcecd2a08e72e733fe7f26620;hpb=9b060a71a2667ced8d103023eda0ff710e799867;p=libfirm diff --git a/ir/be/belive_t.h b/ir/be/belive_t.h index 5d446caa2..086171b53 100644 --- a/ir/be/belive_t.h +++ b/ir/be/belive_t.h @@ -7,74 +7,138 @@ #ifndef _BELIVE_T_H #define _BELIVE_T_H -#include "config.h" +#include "firm_config.h" + +#include "irgraph_t.h" +#include "iredges_t.h" #include "belive.h" #include "pset.h" +#include "set.h" +#include "list.h" +#include "hashptr.h" + +typedef enum _live_state_t { + live_state_in = 1, + live_state_end = 2, + live_state_out = 4, + live_state_block = 8, +} live_state_t; + +typedef struct _irn_live_t { + const ir_node *block; + const ir_node *irn; + unsigned state; + struct _irn_live_t *next; +} irn_live_t; + +typedef struct _irg_live_info_t { + set *live; +} irg_live_info_t; + +extern size_t live_irg_data_offset; + +#define get_irg_live_info(irg) (get_irg_data(irg, irg_live_info_t, live_irg_data_offset)) + +#define live_is_in(live) (((live)->state & live_state_in) != 0) +#define live_is_end(live) (((live)->state & live_state_end) != 0) +#define live_is_out(live) (((live)->state & live_state_out) != 0) + +static INLINE irn_live_t *_get_or_set_live(const ir_node *block, + const ir_node *irn, int state) +{ + irg_live_info_t *live_info = get_irg_live_info(get_irn_irg(block)); + irn_live_t *live, templ; + unsigned hash = HASH_PTR(block) + 37 * HASH_PTR(irn); -typedef struct _block_live_info_t { - pset *in; /**< The set of all values live in at that block. */ - pset *out; /**< The set of all values live out. */ -} block_live_info_t; + templ.block = block; + templ.irn = irn; + templ.state = -1; + templ.next = NULL; -typedef struct _node_live_info_t { - int is_phi_op; /**< Marks the node as a phi operand. */ -} node_live_info_t; + live = set_insert(live_info->live, &templ, sizeof(templ), hash); + if(live->state == -1) { -typedef struct _live_info_t { - union { - block_live_info_t block; - node_live_info_t node; - } v; -} live_info_t; + if(!is_Block(irn)) { + irn_live_t *bl_live = _get_or_set_live(block, block, live_state_block); + live->next = bl_live->next; + bl_live->next = live; + } -extern size_t live_irn_data_offset; + live->state = state; + } -#define get_irn_live_info(irn) get_irn_data(irn, live_info_t, live_irn_data_offset) -#define get_live_info_irn(inf) get_irn_data_base(inf, live_irn_data_offset) + live->state |= state; -#define get_block_live_info(irn) (&(get_irn_live_info(irn)->v.block)) -#define get_node_live_info(irn) (&(get_irn_live_info(irn)->v.node)) + return live; +} -static INLINE int __is_phi_operand(const ir_node *irn) +static INLINE int _is_live_in(const ir_node *block, const ir_node *irn) { - assert(!is_Block(irn) && "No block node allowed here"); - return get_node_live_info(irn)->is_phi_op; + return (_get_or_set_live(block, irn, 0)->state & live_state_in) != 0; } -static INLINE int __is_live_in(const ir_node *block, const ir_node *irn) +static INLINE int _is_live_out(const ir_node *block, const ir_node *irn) { - block_live_info_t *info = get_block_live_info(block); + return (_get_or_set_live(block, irn, 0)->state & live_state_out) != 0; +} - assert(is_Block(block) && "Need a block here"); - return pset_find_ptr(info->in, irn) != NULL; +static INLINE int _is_live_end(const ir_node *block, const ir_node *irn) +{ + return (_get_or_set_live(block, irn, 0)->state & live_state_end) != 0; } -static INLINE int __is_live_out(const ir_node *block, const ir_node *irn) +#define live_foreach(block, live_info) \ + for(live_info = _get_or_set_live(block, block, 0)->next; live_info; live_info = live_info->next) + +static INLINE void _put_live(const ir_node *block, int state, pset *s) { - block_live_info_t *info = get_block_live_info(block); + irn_live_t *live; - assert(is_Block(block) && "Need a block here"); - return pset_find_ptr(info->out, irn) != NULL; + live_foreach(block, live) { + if(live->state & state) + pset_insert_ptr(s, live->irn); + } } -static INLINE pset *__get_live_in(const ir_node *block) +static INLINE pset *_put_live_in(const ir_node *block, pset *s) { - assert(is_Block(block) && "Need a block here"); - return get_block_live_info(block)->in; + _put_live(block, live_state_in, s); + return s; } -static INLINE pset *__get_live_out(const ir_node *block) +static INLINE pset *_put_live_out(const ir_node *block, pset *s) { - assert(is_Block(block) && "Need a block here"); - return get_block_live_info(block)->out; + _put_live(block, live_state_out, s); + return s; } -#define is_phi_operand(irn) __is_phi_operand(irn) -#define is_live_in(bl,irn) __is_live_in(bl, irn) -#define is_live_out(bl,irn) __is_live_out(bl, irn) -#define get_live_in(bl) __get_live_in(bl) -#define get_live_out(bl) __get_live_out(bl) +static INLINE pset *_put_live_end(const ir_node *block, pset *s) +{ + _put_live(block, live_state_end, s); + return s; +} + +static INLINE int _is_phi_arg(const ir_node *irn) +{ + const ir_edge_t *edge; + + assert(edges_activated(get_irn_irg(irn)) && "Please compute the out edges"); + foreach_out_edge(irn, edge) + if(is_Phi(edge->src)) + return 1; + + return 0; +} + + +#define is_live_in(bl,irn) _is_live_in(bl, irn) +#define is_live_out(bl,irn) _is_live_out(bl, irn) +#define is_live_end(bl,irn) _is_live_end(bl, irn) +#define put_live_in(bl,s) _put_live_in(bl, s) +#define put_live_out(bl,s) _put_live_out(bl, s) +#define put_live_end(bl,s) _put_live_end(bl, s) +#define is_phi_arg(irn) _is_phi_arg(irn) /** * Initialize the liveness module.