From: Michael Beck Date: Fri, 24 Oct 2008 01:37:03 +0000 (+0000) Subject: - add a hook for normalizing a node X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=b2acbde76f0c656402423fc2b9faeb61f150db10;p=libfirm - add a hook for normalizing a node - used new hook to count number of normalizations [r23155] --- diff --git a/include/libfirm/irhooks.h b/include/libfirm/irhooks.h index 0f9c840fb..c08eb02cf 100644 --- a/include/libfirm/irhooks.h +++ b/include/libfirm/irhooks.h @@ -59,6 +59,7 @@ typedef enum { HOOK_OPT_CONFIRM_C, /**< a value was substituted by a const due to a Confirm */ HOOK_OPT_CONFIRM_E, /**< a value was evaluated due to a Confirm */ HOOK_OPT_EXC_REM, /**< a exception edge was removed due to a Confirmation prove */ + HOOK_OPT_NORMALIZE, /**< a commutative node was normalized */ HOOK_LOWERED, /**< lowered */ HOOK_BACKEND, /**< a backend transformation */ HOOK_OPT_LAST @@ -104,6 +105,9 @@ typedef struct hook_entry { /** This hook is called, before a node is changed into an Id node. */ void (*_hook_turn_into_id)(void *context, ir_node *node); + /** This hook is called, after a commutative node was normalized. */ + void (*_hook_normalize)(void *context, ir_node *node); + /** This hook is called, after a new graph was created and before the first block * on this graph is build. */ void (*_hook_new_graph)(void *context, ir_graph *irg, ir_entity *ent); @@ -187,6 +191,7 @@ typedef enum { hook_set_irn_n, hook_replace, hook_turn_into_id, + hook_normalize, hook_new_graph, hook_free_graph, hook_irg_walk, @@ -248,6 +253,7 @@ extern hook_entry_t *hooks[hook_last]; hook_exec(hook_set_irn_n, (ctx, src, pos, tgt, old_tgt)) #define hook_replace(old, nw) hook_exec(hook_replace, (ctx, old, nw)) #define hook_turn_into_id(node) hook_exec(hook_turn_into_id, (ctx, node)) +#define hook_normalize(node) hook_exec(hook_normalize, (ctx, node)) #define hook_new_graph(irg, ent) hook_exec(hook_new_graph, (ctx, irg, ent)) #define hook_free_graph(irg) hook_exec(hook_free_graph, (ctx, irg)) #define hook_irg_walk(irg, pre, post) hook_exec(hook_irg_walk, (ctx, irg, pre, post)) diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 016bed4e2..4aaa5335b 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -46,6 +46,7 @@ #include "opt_confirms.h" #include "opt_polymorphy.h" #include "irtools.h" +#include "irhooks.h" #include "array_t.h" /* Make types visible to allow most efficient access */ @@ -6047,6 +6048,7 @@ static void normalize_node(ir_node *n) { if (!operands_are_normalized(l, r)) { set_binop_left(n, r); set_binop_right(n, l); + hook_normalize(n); } } } /* normalize_node */ diff --git a/ir/stat/firmstat.c b/ir/stat/firmstat.c index 853a8b5de..55f61937c 100644 --- a/ir/stat/firmstat.c +++ b/ir/stat/firmstat.c @@ -210,6 +210,7 @@ static void opcode_clear_entry(node_entry_t *elem) { cnt_clr(&elem->cnt_alive); cnt_clr(&elem->new_node); cnt_clr(&elem->into_Id); + cnt_clr(&elem->normalized); } /* opcode_clear_entry */ /** @@ -1536,6 +1537,36 @@ static void stat_turn_into_id(void *ctx, ir_node *node) { STAT_LEAVE; } /* stat_turn_into_id */ +/** + * Hook: A node is normalized + * + * @param ctx the hook context + * @param node the IR node that was normalized + */ +static void stat_normalize(void *ctx, ir_node *node) { + (void) ctx; + if (! status->stat_options) + return; + + STAT_ENTER; + { + node_entry_t *entry; + graph_entry_t *graph; + ir_op *op = stat_get_irn_op(node); + + /* increase global value */ + graph = graph_get_entry(NULL, status->irg_hash); + entry = opcode_get_entry(op, graph->opcode_hash); + cnt_inc(&entry->normalized); + + /* increase local value */ + graph = graph_get_entry(current_ir_graph, status->irg_hash); + entry = opcode_get_entry(op, graph->opcode_hash); + cnt_inc(&entry->normalized); + } + STAT_LEAVE; +} /* stat_normalize */ + /** * Hook: A new graph was created * @@ -2204,6 +2235,7 @@ void firm_init_stat(unsigned enable_options) HOOK(hook_free_ir_op, stat_free_ir_op); HOOK(hook_new_node, stat_new_node); HOOK(hook_turn_into_id, stat_turn_into_id); + HOOK(hook_normalize, stat_normalize); HOOK(hook_new_graph, stat_new_graph); HOOK(hook_free_graph, stat_free_graph); HOOK(hook_irg_walk, stat_irg_walk); diff --git a/ir/stat/firmstat_t.h b/ir/stat/firmstat_t.h index a344186b0..60b2288da 100644 --- a/ir/stat/firmstat_t.h +++ b/ir/stat/firmstat_t.h @@ -103,6 +103,7 @@ typedef struct _node_entry_t { counter_t cnt_alive; /**< amount of nodes in this entry */ counter_t new_node; /**< amount of new nodes for this entry */ counter_t into_Id; /**< amount of nodes that turned into Id's for this entry */ + counter_t normalized; /**< amount of nodes that normalized for this entry */ const ir_op *op; /**< the op for this entry */ } node_entry_t; diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index 5b72eb365..c6b654b3e 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -61,6 +61,7 @@ static const struct { { HOOK_OPT_CONFIRM_C, "Confirm-based optimization: replaced by const" }, { HOOK_OPT_CONFIRM_E, "Confirm-based optimization: evaluated" }, { HOOK_OPT_EXC_REM, "a exception edge was removed due to a Confirmation prove" }, + { HOOK_OPT_NORMALIZE, "a commutative node was normalized" }, { HOOK_LOWERED, "Lowered" }, { HOOK_BACKEND, "Backend transformation" }, { FS_OPT_NEUTRAL_0, "algebraic simplification: a op 0 = 0 op a = a" }, @@ -190,29 +191,34 @@ static void simple_dump_opcode_hash(dumper_t *dmp, pset *set) counter_t f_alive; counter_t f_new_node; counter_t f_Id; + counter_t f_normlized; cnt_clr(&f_alive); cnt_clr(&f_new_node); cnt_clr(&f_Id); + cnt_clr(&f_normlized); - fprintf(dmp->f, "%-16s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id"); + fprintf(dmp->f, "%-16s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id", "normalized"); foreach_pset(set, entry) { fprintf(dmp->f, "%-16s %8u %8u %8u\n", get_id_str(entry->op->name), cnt_to_uint(&entry->cnt_alive), cnt_to_uint(&entry->new_node), - cnt_to_uint(&entry->into_Id) + cnt_to_uint(&entry->into_Id), + cnt_to_uint(&entry->normalized) ); - cnt_add(&f_alive, &entry->cnt_alive); - cnt_add(&f_new_node, &entry->new_node); - cnt_add(&f_Id, &entry->into_Id); + cnt_add(&f_alive, &entry->cnt_alive); + cnt_add(&f_new_node, &entry->new_node); + cnt_add(&f_Id, &entry->into_Id); + cnt_add(&f_normlized, &entry->normalized); } /* foreach_pset */ fprintf(dmp->f, "-------------------------------------------\n"); - fprintf(dmp->f, "%-16s %8u %8u %8u\n", "Sum", + fprintf(dmp->f, "%-16s %8u %8u %8u %8u\n", "Sum", cnt_to_uint(&f_alive), cnt_to_uint(&f_new_node), - cnt_to_uint(&f_Id) + cnt_to_uint(&f_Id), + cnt_to_uint(&f_normlized) ); } /* simple_dump_opcode_hash */