From 391d038495706070a79f042b2928eea7936c8f33 Mon Sep 17 00:00:00 2001 From: Sebastian Hack Date: Fri, 17 Mar 2006 09:37:53 +0000 Subject: [PATCH] Moved several functions here. --- ir/be/belive.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ ir/be/belive.h | 36 +++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/ir/be/belive.c b/ir/be/belive.c index d49d09b76..6d4724491 100644 --- a/ir/be/belive.c +++ b/ir/be/belive.c @@ -14,6 +14,9 @@ #include "beutil.h" #include "belive_t.h" +#include "besched_t.h" + +#define DBG_MODULE "firm.be.liveness" FIRM_IMPL2(is_live_in, int, const ir_node *, const ir_node *) FIRM_IMPL2(is_live_out, int, const ir_node *, const ir_node *) @@ -267,3 +270,61 @@ void be_check_dominance(ir_graph *irg) { irg_walk_graph(irg, dom_check, NULL, NULL); } + +pset *be_liveness_transfer(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *irn, pset *live) +{ + firm_dbg_module_t *dbg = firm_dbg_register(DBG_MODULE); + int i, n; + ir_node *x; + + DBG((dbg, LEVEL_1, "%+F\n", irn)); + for(x = pset_first(live); x; x = pset_next(live)) + DBG((dbg, LEVEL_1, "\tlive: %+F\n", x)); + + if(arch_irn_consider_in_reg_alloc(arch_env, cls, irn)) + pset_remove_ptr(live, irn); + + for(i = 0, n = get_irn_arity(irn); i < n; ++i) { + ir_node *op = get_irn_n(irn, i); + + if(arch_irn_consider_in_reg_alloc(arch_env, cls, op)) + pset_insert_ptr(live, op); + } + + return live; +} + +pset *be_liveness_end_of_block(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *bl, pset *live) +{ + irn_live_t *li; + + live_foreach(bl, li) { + ir_node *irn = (ir_node *) li->irn; + if(live_is_end(li) && arch_irn_consider_in_reg_alloc(arch_env, cls, irn)) + pset_insert_ptr(live, irn); + } + + return live; +} + +pset *be_liveness_nodes_live_at(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live) +{ + firm_dbg_module_t *dbg = firm_dbg_register(DBG_MODULE); + const ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos); + ir_node *irn; + + be_liveness_end_of_block(arch_env, cls, bl, live); + + sched_foreach_reverse(bl, irn) { + /* + * If we encounter the node we want to insert the Perm after, + * exit immediately, so that this node is still live + */ + if(irn == pos) + return live; + + be_liveness_transfer(arch_env, cls, irn, live); + } + + return live; +} diff --git a/ir/be/belive.h b/ir/be/belive.h index f1be34a2b..ff0deb751 100644 --- a/ir/be/belive.h +++ b/ir/be/belive.h @@ -8,6 +8,9 @@ #define _BELIVE_H #include "firm_types.h" +#include "pset.h" +#include "bearch_t.h" + #include /** @@ -60,4 +63,37 @@ int (is_live_end)(const ir_node *block, const ir_node *irn); */ void be_check_dominance(ir_graph *irg); +/** + * The liveness transfer function. + * Updates a live set over a single step from a given node to its predecessor. + * Everything defined at the node is removed from the set, the uses of the node get inserted. + * @param arch_env The architecture environment. + * @param cls The register class to consider. + * @param irn The node at which liveness should be computed. + * @param live The set of nodes live before @p irn. This set gets modified by updating it to + * the nodes live after irn. + * @return live. + */ +pset *be_liveness_transfer(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *irn, pset *live); + +/** + * Put all node live at the end of a block into a set. + * @param arch_env The architecture environment. + * @param cls The register class to consider. + * @param bl The block. + * @param live The set to put them into. + * @return live. + */ +pset *be_liveness_end_of_block(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *bl, pset *live); + +/** + * Compute a set of nodes which are live at another node. + * @param arch_env The architecture environment. + * @param cls The register class to consider. + * @param pos The node. + * @param live The set to put them into. + * @return live. + */ +pset *be_liveness_nodes_live_at(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live); + #endif /* _BELIVE_H */ -- 2.20.1