From 2af1a7e6b74e4bd6f03647f77ae42b5581bd78cd Mon Sep 17 00:00:00 2001 From: Daniel Grund Date: Sat, 15 Jan 2005 16:33:00 +0000 Subject: [PATCH] Comments, beautify, and new header --- ir/be/bephicongr.c | 73 ++++++++++++++++++++++++++------------------ ir/be/bephicongr.h | 33 ++++++++++++++++++++ ir/be/bephicongr_t.h | 17 ++++++++--- 3 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 ir/be/bephicongr.h diff --git a/ir/be/bephicongr.c b/ir/be/bephicongr.c index 05635d274..3a6427e2a 100644 --- a/ir/be/bephicongr.c +++ b/ir/be/bephicongr.c @@ -7,31 +7,22 @@ #include #include -#include "config.h" -#include "irgraph.h" -#include "irnode.h" -#include "irop.h" -#include "irprog.h" #include "debug.h" -#include "pset.h" - +#include "impl.h" +#include "irprog.h" +#include "irgwalk.h" +#include "irop.h" #include "bephicongr_t.h" -#include "beutil.h" #define DEBUG_LVL 0 size_t phi_irn_data_offset = 0; static firm_dbg_module_t *dbgphi = NULL; -void be_phi_congr_class_init(void) { - dbgphi = firm_dbg_register("Phi classes"); - firm_dbg_set_mask(dbgphi, DEBUG_LVL); - phi_irn_data_offset = register_additional_node_data(sizeof(phi_info_t)); -} - -#define get_phi(irn) get_irn_phi_info(irn)->phi -#define set_phi(irn, p) get_irn_phi_info(irn)->phi = p -#define set_phi_class(irn, cls) get_irn_phi_info(irn)->phi_class = cls +#define _get_phi(irn) get_irn_phi_info(irn)->phi +#define _set_phi(irn, p) get_irn_phi_info(irn)->phi = p +#define _get_phi_class(irn) get_irn_phi_info(irn)->phi_class +#define _set_phi_class(irn, cls) get_irn_phi_info(irn)->phi_class = cls #define is_Const(n) (get_irn_opcode(n) == iro_Const) @@ -45,7 +36,7 @@ void be_phi_congr_class_init(void) { static INLINE void phi_class_insert(pset *class, ir_node *phi, ir_node *member) { DBG((dbgphi, 1, "\tinsert %n in %n\n", member, phi)); if (!(is_Const(member) && CONSTS_SPLIT_PHI_CLASSES)) - set_phi(member, phi); + _set_phi(member, phi); pset_insert_ptr(class, member); } @@ -63,14 +54,14 @@ static void phi_class_union(ir_node *n, ir_node *new_tgt) { DBG((dbgphi, 1, "\tcorrect %n\n", n)); /* copy all class members from n to new_tgt. Duplicates eliminated by pset */ - src = get_phi_class(n); - tgt = get_phi_class(new_tgt); + src = _get_phi_class(n); + tgt = _get_phi_class(new_tgt); for (p = (ir_node *)pset_first(src); p; p = (ir_node *)pset_next(src)) phi_class_insert(tgt, new_tgt, p); /* phi class of n is no longer needed */ del_pset(src); - set_phi_class(n, NULL); + _set_phi_class(n, NULL); } @@ -85,10 +76,10 @@ static void det_phi_congr_class(ir_node *curr_phi) { assert(is_Phi(curr_phi) && "This must be a phi node."); DBG((dbgphi, 1, "Det. phi class of %n.\n", curr_phi)); - pc = get_phi_class(curr_phi); + pc = _get_phi_class(curr_phi); if (!pc) { pc = pset_new_ptr(2); - set_phi_class(curr_phi, pc); + _set_phi_class(curr_phi, pc); phi_class_insert(pc, curr_phi, curr_phi); } @@ -98,7 +89,7 @@ static void det_phi_congr_class(ir_node *curr_phi) { arg = get_irn_n(curr_phi, i); DBG((dbgphi, 1, " Arg %n\n", arg)); - phi = get_phi(arg); + phi = _get_phi(arg); if (phi == NULL) { /* Argument is not assigned to another phi class. */ phi_class_insert(pc, curr_phi, arg); } else if (phi != curr_phi) { @@ -106,14 +97,29 @@ static void det_phi_congr_class(ir_node *curr_phi) { phi_class_union(phi, curr_phi); } } - DBG((dbgphi, 1, "Size now: %d\n", pset_count(get_phi_class(curr_phi)))); + DBG((dbgphi, 1, "Size now: %d\n", pset_count(_get_phi_class(curr_phi)))); } -/** - * Determines the phi congruence classes of - * all phi nodes in a given pset - */ +static void phi_node_walker(ir_node *node, void *env) { + if (is_Phi(node) && mode_is_datab(get_irn_mode(node))) + det_phi_congr_class(node); +} + + +void be_phi_congr_compute(ir_graph *irg) { + irg_walk_graph(irg, phi_node_walker, NULL, NULL); +} + + +pset *get_phi_class(const ir_node *irn) { + ir_node *phi = _get_phi(irn); + if (phi) + return _get_phi_class(phi); + else + return NULL; +} + pset *be_phi_congr_classes(pset *all_phi_nodes) { int i; ir_node *phi; @@ -126,10 +132,17 @@ pset *be_phi_congr_classes(pset *all_phi_nodes) { /* store them in a pset for fast retrieval */ all_phi_classes = pset_new_ptr(64); for (i = 0, phi = (ir_node *)pset_first(all_phi_nodes); phi; phi = (ir_node *)pset_next(all_phi_nodes)) { - phi_class = get_phi_class(phi); + phi_class = _get_phi_class(phi); if (phi_class) pset_insert_ptr(all_phi_classes, phi_class); } return all_phi_classes; } + + +void be_phi_congr_class_init(void) { + dbgphi = firm_dbg_register("Phi classes"); + firm_dbg_set_mask(dbgphi, DEBUG_LVL); + phi_irn_data_offset = register_additional_node_data(sizeof(phi_info_t)); +} diff --git a/ir/be/bephicongr.h b/ir/be/bephicongr.h new file mode 100644 index 000000000..b88428ba7 --- /dev/null +++ b/ir/be/bephicongr.h @@ -0,0 +1,33 @@ +/** + * Analysis to compute phi congruence classes. + * @author Daniel Grund + * @date 15.01.2005 + */ + +#ifndef _BEPHICONGR_H +#define _BEPHICONGR_H + +#include "pset.h" +#include "irgraph.h" +#include "irnode.h" + +/** + * Initialize data structures + */ +void be_phi_congr_class_init(void); + +/** + * Computes all phi classes of an irg. + * @param irg The ir-graph to compute the classes for. + * @return Sets the internal data structures. + */ +void be_phi_congr_class_compute(ir_graph *irg); + +/** + * @param irn A node to get the phi class for + * @return A pset containing all members of the phi class @p irn belongs to. + * If @p irn is not member of a phi class NULL is returned. + */ +pset *get_phi_class(const ir_node *irn); + +#endif diff --git a/ir/be/bephicongr_t.h b/ir/be/bephicongr_t.h index a747a875c..4aca0d8f0 100644 --- a/ir/be/bephicongr_t.h +++ b/ir/be/bephicongr_t.h @@ -1,4 +1,5 @@ /** + * Analysis to conmpute phi congruence classes. * @author Daniel Grund * @date 09.12.2004 */ @@ -6,8 +7,7 @@ #ifndef _BEPHICONGR_T_H #define _BEPHICONGR_T_H -#include "pset.h" -#include "irnode.h" +#include "bephicongr.h" typedef struct _phi_info_t { ir_node *phi; /**< For all nodes of a phi class points to a phi node @@ -19,18 +19,25 @@ typedef struct _phi_info_t { extern size_t phi_irn_data_offset; +#define get_irn_phi_info(irn) get_irn_data(irn, phi_info_t, phi_irn_data_offset) + /** * Setting this to 0 will treat const nodes like * all other nodes when computing phi congruence classes. * A non zero value results in splitting phi congruence * classes at all const nodes (except they do share * some non-const nodes too) + * + * If constants are localized this is irrelevant. Set to 0 in this case. */ #define CONSTS_SPLIT_PHI_CLASSES 0 -#define get_irn_phi_info(irn) get_irn_data(irn, phi_info_t, phi_irn_data_offset) -#define get_phi_class(irn) get_irn_phi_info(irn)->phi_class /* Only for phi nodes */ -void be_phi_congr_class_init(void); +/** + * Computes all phi classes of an irg. All phi nodes of this irg must be + * contained in @p all_phi_nodes. Otherwise the results will be incorrect. + * @param all_phi_nodes All phi nodes of an irg. + * @return A set containing all phi classes as psets + */ pset *be_phi_congr_classes(pset *all_phi_nodes); -- 2.20.1