X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana2%2Fpto_comp.c;h=854d2171e2f43903ca11646b1629b4a2d25763d9;hb=78ad7c028e8395a6a5f1ea8eb1f86bf5ea2c682c;hp=fc1fd4c41cf37041191974f834083db954f37302;hpb=da1c9c1ca15f82f494b3f36d215a150c940acd3e;p=libfirm diff --git a/ir/ana2/pto_comp.c b/ir/ana2/pto_comp.c index fc1fd4c41..854d2171e 100644 --- a/ir/ana2/pto_comp.c +++ b/ir/ana2/pto_comp.c @@ -1,17 +1,31 @@ /* -*- c -*- */ /* - Project: libFIRM - File name: ir/ana/pto_comp.c - Purpose: Main Implementation of PTO - Author: Florian - Modified by: - Created: Sat Nov 13 19:35:27 CET 2004 - CVS-ID: $Id$ - Copyright: (c) 1999-2004 Universität Karlsruhe - Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE. -*/ - + * Copyrigth (C) 1995-2007 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. + */ + +/** + * @file + * @brief Main Implementation of PTO + * @author Florian + * @date Sat Nov 13 19:35:27 CET 2004 + * @version $Id$ + */ # ifdef HAVE_CONFIG_H # include "config.h" # endif @@ -29,7 +43,7 @@ # include "pto_mod.h" # include "irnode_t.h" -# include "irprog.h" +# include "irprog_t.h" # include "xmalloc.h" # include "irmemwalk.h" @@ -38,6 +52,8 @@ # include "ecg.h" +# include "gnu_ext.h" + /* Local Defines: */ /* Local Data Types: */ @@ -70,7 +86,7 @@ static void pto_end_block (ir_node*, pto_env_t*); static int add_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) { int change = FALSE; - type *meth = get_entity_type (get_irg_entity (graph)); + ir_type *meth = get_entity_type (get_irg_entity (graph)); ir_node **args = get_irg_proj_args (graph); int i, n_args; @@ -78,8 +94,9 @@ static int add_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) n_args = get_Call_n_params (call); - DBGPRINT (1, (stdout, "add_graph_args(): args of %s[%li] -> 0x%08x\n", - OPNAME (call), OPNUM (call), (void*) graph)); + DBGPRINT (1, (stdout, "%s: args of %s[%li] -> 0x%08x\n", + __FUNCTION__, + OPNAME (call), OPNUM (call), (int) graph)); for (i = 0; i < n_args; i ++) { if (NULL != args [i]) { @@ -93,7 +110,8 @@ static int add_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) change |= qset_insert_all (frm_pto->values, arg_pto->values); - DBGPRINT (2, (stdout, "add_graph_args(): arg [%i]: -> %s[%li] (%i) -> %s[%li] (%i)\n", + DBGPRINT (2, (stdout, "%s: arg [%i]: -> %s[%li] (%i) -> %s[%li] (%i)\n", + __FUNCTION__, i, OPNAME (call_arg), OPNUM (call_arg), arg_pto->values->id, @@ -109,7 +127,7 @@ static int add_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) /* Transfer the actual arguments to the formal arguments */ static void set_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) { - type *meth = get_entity_type (get_irg_entity (graph)); + ir_type *meth = get_entity_type (get_irg_entity (graph)); ir_node **args = get_irg_proj_args (graph); int i, n_args; @@ -125,7 +143,8 @@ static void set_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) assert (pto); set_node_pto (args [i], pto); - DBGPRINT (1, (stdout, "set_graph_args(): arg [%i]: %s[%li] -> %s[%li] (%i)\n", + DBGPRINT (1, (stdout, "%s: arg [%i]: %s[%li] -> %s[%li] (%i)\n", + __FUNCTION__, i, OPNAME (call_arg), OPNUM (call_arg), OPNAME (args [i]), OPNUM (args [i]), @@ -138,7 +157,7 @@ static void set_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) /* Transfer the graph's result to the call */ static int set_graph_result (ir_graph *graph, ir_node *call) { - type *tp = get_entity_type (get_irg_entity (graph)); + ir_type *tp = get_entity_type (get_irg_entity (graph)); ir_node *end_block; pto_t *ret_pto, *call_pto; int change; @@ -162,16 +181,16 @@ static int set_graph_result (ir_graph *graph, ir_node *call) assert (call_pto); - DBGPRINT (0, (stdout, "set_graph_result(): before change args\n")); - DBGEXE (0, pto_print_pto (end_block)); - DBGEXE (0, pto_print_pto (call)); + DBGPRINT (1, (stdout, "%s: before change args\n", __FUNCTION__)); + DBGEXE (1, pto_print_pto (end_block)); + DBGEXE (1, pto_print_pto (call)); change = qset_insert_all (call_pto->values, ret_pto->values); if (change) { - DBGPRINT (0, (stdout, "set_graph_result(): after change args\n")); - DBGEXE (0, pto_print_pto (end_block)); - DBGEXE (0, pto_print_pto (call)); + DBGPRINT (1, (stdout, "%s: after change args\n", __FUNCTION__)); + DBGEXE (1, pto_print_pto (end_block)); + DBGEXE (1, pto_print_pto (call)); /* assert (0); */ } @@ -182,8 +201,7 @@ static int set_graph_result (ir_graph *graph, ir_node *call) static pto_t *get_pto_proj (ir_node *proj, pto_env_t *env) { ir_node *proj_in = get_Proj_pred (proj); - const long proj_proj = get_Proj_proj (proj); - const opcode in_op = get_irn_opcode (proj_in); + const ir_opcode in_op = get_irn_opcode (proj_in); pto_t *in_pto = NULL; pto_t *proj_pto = NULL; /* get_node_pto (proj); */ @@ -195,7 +213,7 @@ static pto_t *get_pto_proj (ir_node *proj, pto_env_t *env) return (NULL); case (iro_Proj): { /* ProjT (Start), ProjT (Call) */ - opcode in_in_op; + ir_opcode in_in_op; long proj_in_proj; proj_in_in = get_Proj_pred (proj_in); @@ -229,7 +247,7 @@ static pto_t *get_pto_proj (ir_node *proj, pto_env_t *env) } case (iro_Load): /* ProjV (Load) */ - assert (pn_Load_res == proj_proj); + assert (pn_Load_res == get_Proj_proj(proj)); /* FALLTHROUGH */ case (iro_Call): /* ProjT (Call) */ /* FALLTHROUGH */ @@ -244,7 +262,7 @@ static pto_t *get_pto_proj (ir_node *proj, pto_env_t *env) return (in_pto); } default: - fprintf (stderr, "get_pto_proj(): not handled: proj (%s[%li])\n", + fprintf (stderr, "get_pto_proj(/*todo*/): not handled: proj (%s[%li])\n", get_op_name (get_irn_op (proj_in)), get_irn_node_nr (proj_in)); assert (0 && "Proj(?)"); @@ -306,7 +324,7 @@ static pto_t *get_pto_ret (ir_node *ret, pto_env_t *env) assert (pto); - DBGPRINT (9, (stdout, "get_pto_ret(): ")); + DBGPRINT (9, (stdout, "%s: ", __FUNCTION__)); DBGEXE (9, pto_print_pto (ret)); return (pto); @@ -316,9 +334,10 @@ static pto_t *get_pto_ret (ir_node *ret, pto_env_t *env) /* Dispatch to propagate PTO values */ static pto_t *get_pto (ir_node *node, pto_env_t *env) { - const opcode op = get_irn_opcode (node); + const ir_opcode op = get_irn_opcode (node); - DBGPRINT (2, (stdout, "get_pto (%s[%li])\n", + DBGPRINT (2, (stdout, "%s (%s[%li])\n", + __FUNCTION__, OPNAME (node), OPNUM (node))); switch (op) { @@ -340,7 +359,8 @@ static pto_t *get_pto (ir_node *node, pto_env_t *env) } default: /* stopgap measure */ - fprintf (stderr, "get_pto(): not handled: node[%li].op = %s\n", + fprintf (stderr, "%s: not handled: node[%li].op = %s\n", + __FUNCTION__, get_irn_node_nr (node), get_op_name (get_irn_op (node))); assert (0 && "something not handled"); @@ -353,11 +373,12 @@ static pto_t *get_pto (ir_node *node, pto_env_t *env) static void pto_load (ir_node *load, pto_env_t *pto_env) { ir_node *ptr; - entity *ent; + ir_entity *ent; /* perform load */ - DBGPRINT (2, (stdout, "pto_load() (%s[%li]): pto = 0x%08x\n", - OPNAME (load), OPNUM (load), (void*) get_node_pto (load))); + DBGPRINT (2, (stdout, "%s (%s[%li]): pto = 0x%08x\n", + __FUNCTION__, + OPNAME (load), OPNUM (load), (int) get_node_pto (load))); ptr = get_Load_ptr (load); @@ -372,8 +393,9 @@ static void pto_load (ir_node *load, pto_env_t *pto_env) assert (ptr_pto); - DBGPRINT (1, (stdout, "pto_load() (%s[%li]): ptr = 0x%08x\n", - OPNAME (ptr), OPNUM (ptr), (void*) ptr_pto)); + DBGPRINT (1, (stdout, "%s (%s[%li]): ptr = 0x%08x\n", + __FUNCTION__, + OPNAME (ptr), OPNUM (ptr), (int) ptr_pto)); pto_env->change |= mod_load (load, ent, ptr_pto); } @@ -382,11 +404,12 @@ static void pto_load (ir_node *load, pto_env_t *pto_env) static void pto_store (ir_node *store, pto_env_t *pto_env) { ir_node *ptr, *val; - entity *ent; + ir_entity *ent; pto_t *ptr_pto, *val_pto; /* perform store */ - DBGPRINT (2, (stdout, "pto_store() (%s[%li]) (no pto)\n", + DBGPRINT (2, (stdout, "%s (%s[%li]) (no pto)\n", + __FUNCTION__, OPNAME (store), OPNUM (store))); ptr = get_Store_ptr (store); @@ -404,10 +427,12 @@ static void pto_store (ir_node *store, pto_env_t *pto_env) assert (ptr_pto); assert (val_pto); - DBGPRINT (2, (stdout, "pto_store() (%s[%li]): ptr_pto = 0x%08x\n", - OPNAME (ptr), OPNUM (ptr), (void*) ptr_pto)); - DBGPRINT (2, (stdout, "pto_store() (%s[%li]): val_pto = 0x%08x\n", - OPNAME (val), OPNUM (val), (void*) val_pto)); + DBGPRINT (2, (stdout, "%s (%s[%li]): ptr_pto = 0x%08x\n", + __FUNCTION__, + OPNAME (ptr), OPNUM (ptr), (int) ptr_pto)); + DBGPRINT (2, (stdout, "%s (%s[%li]): val_pto = 0x%08x\n", + __FUNCTION__, + OPNAME (val), OPNUM (val), (int) val_pto)); pto_env->change |= mod_store (store, ent, ptr_pto, val_pto); } @@ -417,21 +442,21 @@ static void pto_method (ir_node *call, pto_env_t *pto_env) int i; callEd_info_t *callEd_info; - DBGPRINT (2, (stdout, "pto_method():%i (%s[%li]): pto = 0x%08x\n", - __LINE__, OPNAME (call), OPNUM (call), - (void*) get_node_pto (call))); + DBGPRINT (2, (stdout, "%s:%i (%s[%li]): pto = 0x%08x\n", + __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call), + (int) get_node_pto (call))); callEd_info = ecg_get_callEd_info (call); if (NULL == callEd_info) { - DBGPRINT (2, (stdout, "pto_method():%i (%s[%li]), no graph\n", - __LINE__, OPNAME (call), OPNUM (call))); + DBGPRINT (2, (stdout, "%s:%i (%s[%li]), no graph\n", + __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call))); } i = 0; while (NULL != callEd_info) { - DBGPRINT (2, (stdout, "pto_method():%i (%s[%li]), graph %i\n", - __LINE__, OPNAME (call), OPNUM (call), i ++)); + DBGPRINT (2, (stdout, "%s:%i (%s[%li]), graph %i\n", + __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call), i ++)); pto_call (callEd_info->callEd, call, pto_env); @@ -442,10 +467,10 @@ static void pto_method (ir_node *call, pto_env_t *pto_env) /* Perform the appropriate action on the given node */ static void pto_node_node(ir_node *node, pto_env_t *pto_env) { - opcode op = get_irn_opcode (node); + ir_opcode op = get_irn_opcode (node); - DBGPRINT (1, (stdout, "pto_node_node() (%s[%li])\n", - OPNAME (node), OPNUM (node))); + DBGPRINT (1, (stdout, "%s (%s[%li])\n", + __FUNCTION__, OPNAME (node), OPNUM (node))); switch (op) { case (iro_Start): /* nothing */ break; @@ -491,7 +516,8 @@ static void pto_node_node(ir_node *node, pto_env_t *pto_env) default: /* stopgap measure */ - fprintf (stderr, "pto_node_node(): not handled: node[%li].op = %s\n", + fprintf (stderr, "%s: not handled: node[%li].op = %s\n", + __FUNCTION__, get_irn_node_nr (node), get_op_name (get_irn_op (node))); assert (0 && "something not handled"); @@ -510,7 +536,8 @@ static void pto_node_post (ir_node *node, void *env) { pto_env_t *pto_env = (pto_env_t*) env; - DBGPRINT (999, (stdout, "pto_node_post() (%s[%li])\n", + DBGPRINT (999, (stdout, "%s (%s[%li])\n", + __FUNCTION__, OPNAME (node), OPNUM (node))); pto_node_node (node, pto_env); @@ -528,12 +555,13 @@ static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env) int change = FALSE; /* only for debugging stuff: */ - entity *ent = get_irg_entity (graph); + ir_entity *ent = get_irg_entity (graph); const char *ent_name = (char*) get_entity_name (ent); const char *own_name = (char*) get_type_name (get_entity_owner (ent)); /* perform call */ - DBGPRINT (2, (stdout, "pto_call() (%s[%li]) to \"%s.%s\"\n", + DBGPRINT (2, (stdout, "%s (%s[%li]) to \"%s.%s\"\n", + __FUNCTION__, OPNAME (call), OPNUM (call), own_name, ent_name)); @@ -573,7 +601,8 @@ static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env) int rec_change; /* handle recursion */ - DBGPRINT (0, (stdout, "pto_call(): recursion into \"%s.%s\"\n", + DBGPRINT (0, (stdout, "%s: recursion into \"%s.%s\"\n", + __FUNCTION__, own_name, ent_name)); /* Find 'right' enclosing pto_env */ enc_env = pto_env; @@ -587,18 +616,18 @@ static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env) /* Re-Set arguments */ rec_change = add_graph_args (graph, call, pto_env); - DBGPRINT (1, (stdout, "pto_call(): return in:")); + DBGPRINT (1, (stdout, "%s: return in:", __FUNCTION__)); DBGEXE (1, pto_print_pto (get_irg_end_block (graph))); if (rec_change) { - DBGPRINT (0, (stdout, "pto_call(): change args")); + DBGPRINT (0, (stdout, "%s: change args\n", __FUNCTION__)); } rec_change |= set_graph_result (graph, call); if (rec_change) { - DBGPRINT (0, (stdout, "pto_call(): return out:")); - DBGEXE (0, pto_print_pto (get_irg_end_block (graph))); + DBGPRINT (1, (stdout, "%s: return out:", __FUNCTION__)); + DBGEXE (1, pto_print_pto (get_irg_end_block (graph))); } # if 0 @@ -616,14 +645,15 @@ static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env) static void pto_raise (ir_node *raise, pto_env_t *pto_env) { /* perform raise */ - DBGPRINT (2, (stdout, "pto_raise() (%s[%li]): pto = 0x%08x\n", - OPNAME (raise), OPNUM (raise), (void*) get_node_pto (raise))); + DBGPRINT (2, (stdout, "%s (%s[%li]): pto = 0x%08x\n", + __FUNCTION__, + OPNAME (raise), OPNUM (raise), (int) get_node_pto (raise))); } static void pto_end_block (ir_node *end_block, pto_env_t *pto_env) { /* perform end block */ - type *tp = get_entity_type (get_irg_entity (get_irn_irg (end_block))); + ir_type *tp = get_entity_type (get_irg_entity (get_irn_irg (end_block))); pto_t *end_pto; int i, n_ins; @@ -633,13 +663,14 @@ static void pto_end_block (ir_node *end_block, pto_env_t *pto_env) tp = get_method_res_type (tp, 0); - if (mode_P != get_type_mode (tp)) { + if (! mode_is_reference(get_type_mode (tp))) { return; } - DBGPRINT (2, (stdout, "pto_end_block() (%s[%li]): pto = 0x%08x\n", + DBGPRINT (2, (stdout, "%s (%s[%li]): pto = 0x%08x\n", + __FUNCTION__, OPNAME (end_block), OPNUM (end_block), - (void*) get_node_pto (end_block))); + (int) get_node_pto (end_block))); end_pto = get_node_pto (end_block); @@ -664,31 +695,36 @@ static void pto_end_block (ir_node *end_block, pto_env_t *pto_env) void pto_graph (ir_graph *graph, int ctx_idx, pto_env_t *enc_env) { int run; + pto_env_t *pto_env; /* Also exported, since we need it in 'pto.c' */ - pto_env_t pto_env; - pto_env.enc_env = enc_env; - pto_env.graph = graph; - pto_env.ctx_idx = ctx_idx; - pto_env.change = TRUE; + pto_env = xmalloc (sizeof (pto_env_t)); + pto_env->enc_env = enc_env; + pto_env->graph = graph; + pto_env->ctx_idx = ctx_idx; + pto_env->change = TRUE; /* HERE ("start"); */ - DBGPRINT (2, (stdout, "pto_graph(): start for ctx %i\n", + DBGPRINT (2, (stdout, "%s: start for ctx %i\n", + __FUNCTION__, ctx_idx)); /* todo (here): iterate, obey 'changed' attribute */ run = 0; - while (0 != pto_env.change) { + while (0 != pto_env->change) { run ++; - pto_env.change = FALSE; - pto_graph_pass (graph, &pto_env); + pto_env->change = FALSE; + pto_graph_pass (graph, pto_env); } - DBGPRINT (1, (stdout, "pto_graph(): %i runs on \"%s.%s\"\n", + DBGPRINT (1, (stdout, "%s: %i runs on \"%s.%s\"\n", + __FUNCTION__, run, get_type_name (get_entity_owner (get_irg_entity (graph))), get_entity_name (get_irg_entity (graph)))); + memset (pto_env, 0, sizeof (pto_env_t)); + free (pto_env); /* HERE ("end"); */ } @@ -733,6 +769,34 @@ pto_t *get_alloc_pto (ir_node *alloc) /* $Log$ + Revision 1.21 2007/03/22 10:39:33 matze + a bunch of fixes to make firm work with NDEBUG and without DEBUG_libfirm + + Revision 1.20 2007/01/16 15:45:42 beck + renamed type opcode to ir_opcode + + Revision 1.19 2006/12/13 19:46:47 beck + rename type entity into ir_entity + + Revision 1.18 2006/01/13 22:57:41 beck + renamed all types 'type' to 'ir_type' + used mode_is_reference instead of != mode_P test + + Revision 1.17 2005/02/25 16:48:21 liekweg + fix typo + + Revision 1.16 2005/01/27 15:51:19 liekweg + whitespace change + + Revision 1.15 2005/01/14 14:14:26 liekweg + fix gnu extension, fix fprintf's + + Revision 1.14 2005/01/14 13:37:26 liekweg + fix allocation (size); don't cast malloc + + Revision 1.13 2005/01/10 17:26:34 liekweg + fixup printfs, don't put environments on the stack + Revision 1.12 2004/12/23 15:46:19 beck removed unneeded allocations