X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana2%2Fpto_init.c;h=221b325e9f41548ad2e065e3cf28b51666b8dae7;hb=29902f3b814d06659a96397214bc3f491895415b;hp=0d416206be43f1b5c54d3df452a1f7ebec92bf63;hpb=5940b77567126bc51a3225d166716ba1bca784ee;p=libfirm diff --git a/ir/ana2/pto_init.c b/ir/ana2/pto_init.c index 0d416206b..221b325e9 100644 --- a/ir/ana2/pto_init.c +++ b/ir/ana2/pto_init.c @@ -1,17 +1,31 @@ /* -*- c -*- */ /* - Project: libFIRM - File name: ir/ana/pto_init.c - Purpose: Initialisation Functions - 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. -*/ - + * Copyright (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 Initialisation Functions + * @author Florian + * @date Sat Nov 13 19:35:27 CET 2004 + * @version $Id$ + */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -20,9 +34,15 @@ pto_init: Initialisation Functions */ -# include +# include +#ifdef HAVE_STRING_H # include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +# include "obst.h" # include "pto.h" # include "pto_init.h" # include "pto_debug.h" @@ -32,8 +52,11 @@ # include "typewalk.h" # include "irgwalk.h" +# include "tv.h" # include "xmalloc.h" +# include "gnu_ext.h" + /* Local Defines: */ # define obstack_chunk_alloc xmalloc # define obstack_chunk_free free @@ -59,7 +82,7 @@ static struct obstack *pto_obst = NULL; /* all pto_t's go onto this one */ /* =================================================== Local Implementation: =================================================== */ -/* Allocate a new pto */ +/** Allocate a new pto */ static pto_t *new_pto (ir_node *node) { pto_t *pto = obstack_alloc (pto_obst, sizeof (pto_t)); @@ -68,12 +91,12 @@ static pto_t *new_pto (ir_node *node) return (pto); } -/* Allocate a new alloc_pto */ +/** Allocate a new alloc_pto */ static alloc_pto_t *new_alloc_pto (ir_node *alloc, int n_ctxs) { int i; - alloc_pto_t *alloc_pto = obstack_alloc (pto_obst, sizeof(*alloc_pto)); - type *tp; + alloc_pto_t *alloc_pto = obstack_alloc (pto_obst, sizeof (alloc_pto_t)); + ir_type *tp; assert (op_Alloc == get_irn_op(alloc)); @@ -90,11 +113,11 @@ static alloc_pto_t *new_alloc_pto (ir_node *alloc, int n_ctxs) return (alloc_pto); } -/* Allocate a new pto for a symconst */ +/** Allocate a new pto for a symconst */ static pto_t* new_symconst_pto (ir_node *symconst) { pto_t *pto; - entity *ent; + ir_entity *ent; desc_t *desc = NULL; assert (op_SymConst == get_irn_op(symconst)); @@ -116,7 +139,8 @@ static pto_t* new_symconst_pto (ir_node *symconst) } else if (is_Class_type (get_entity_type (ent))) { desc = new_name (get_entity_type (ent), symconst, -1); } else { - fprintf (stderr, "new_symconst_pto(): not handled: %s[%li] (\"%s\")\n", + fprintf (stderr, "%s: not handled: %s[%li] (\"%s\")\n", + __FUNCTION__, get_op_name (get_irn_op (symconst)), get_irn_node_nr (symconst), get_entity_name (ent)); @@ -134,42 +158,44 @@ static pto_t* new_symconst_pto (ir_node *symconst) static void clear_type_link (type_or_ent *thing, void *_unused) { if (is_type (thing)) { - type *tp = (type*) thing; + ir_type *tp = (ir_type*) thing; if (is_Class_type (tp)) { - DBGPRINT (1, (stdout, "clear_type_link() (\"%s\")\n", + DBGPRINT (1, (stdout, "%s (\"%s\")\n", + __FUNCTION__, get_type_name (tp))); set_type_link (tp, NULL); } } else if (is_entity (thing)) { - entity *ent = (entity*) thing; + ir_entity *ent = (ir_entity*) thing; - DBGPRINT (1, (stdout, "clear_type_link() (\"%s\")\n", + DBGPRINT (1, (stdout, "%s (\"%s\")\n", + __FUNCTION__, get_entity_name (ent))); set_entity_link (ent, NULL); } } -/* Helper to pto_init_graph --- clear the links of the given node */ +/** Helper to pto_init_graph --- clear the links of the given node */ static void clear_node_link (ir_node *node, void *_unused) { set_irn_link (node, NULL); } -/* Helper to pto_init_graph --- clear the links of all nodes */ +/** Helper to pto_init_graph --- clear the links of all nodes */ static void clear_graph_links (ir_graph *graph) { irg_walk_graph (graph, clear_node_link, NULL, NULL); } -/* Reset ALL the pto values for a new pass */ +/** Reset ALL the pto values for a new pass */ static void reset_node_pto (ir_node *node, void *env) { reset_env_t *reset_env = (reset_env_t*) env; int ctx_idx = reset_env->ctx_idx; - opcode op = get_irn_opcode (node); + ir_opcode op = get_irn_opcode (node); /* HERE ("start"); */ @@ -188,20 +214,23 @@ static void reset_node_pto (ir_node *node, void *env) alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (node); alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx]; - DBGPRINT (1, (stdout, "reset_node_pto(): setting pto of \"%s[%li]\" for ctx %i\n", + DBGPRINT (1, (stdout, "%s: setting pto of \"%s[%li]\" for ctx %i\n", + __FUNCTION__, OPNAME (node), OPNUM (node), ctx_idx)); assert (alloc_pto->curr_pto); } break; + case (iro_Const): case (iro_SymConst): { /* nothing, leave as-is */ } break; default: { /* basically, nothing */ - DBGPRINT (2, (stdout, "reset_node_pto(): resetting pto of \"%s[%li]\"\n", + DBGPRINT (2, (stdout, "%s: resetting pto of \"%s[%li]\"\n", + __FUNCTION__, OPNAME (node), OPNUM (node))); set_node_pto (node, NULL); @@ -211,25 +240,26 @@ static void reset_node_pto (ir_node *node, void *env) /* HERE ("end"); */ } -/* Initialise primary name sources */ +/** Initialise primary name sources */ static void init_pto (ir_node *node, void *env) { init_env_t *init_env = (init_env_t*) env; int n_ctxs = init_env->n_ctxs; - opcode op = get_irn_opcode (node); + ir_opcode op = get_irn_opcode (node); switch (op) { case (iro_SymConst): { - if (mode_is_reference(get_irn_mode (node))) { - entity *ent = get_SymConst_entity (node); - type *tp = get_entity_type (ent); + if (mode_is_reference (get_irn_mode (node))) { + ir_entity *ent = get_SymConst_entity (node); + ir_type *tp = get_entity_type (ent); if (is_Class_type (tp) || is_Pointer_type (tp)) { pto_t *symconst_pto = new_symconst_pto (node); set_node_pto (node, symconst_pto); /* debugging only */ - DBGPRINT (1, (stdout, "init_pto(): new name \"%s\" for \"%s[%li]\"\n", + DBGPRINT (1, (stdout, "%s: new name \"%s\" for \"%s[%li]\"\n", + __FUNCTION__, get_entity_name (ent), OPNAME (node), OPNUM (node))); @@ -239,18 +269,30 @@ static void init_pto (ir_node *node, void *env) case (iro_Alloc): { alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs); - type *tp; + ir_type *tp; set_alloc_pto (node, alloc_pto); tp = get_Alloc_type (node); /* debugging only */ - DBGPRINT (1, (stdout, "init_pto(): %i names \"%s\" for \"%s[%li]\"\n", + DBGPRINT (1, (stdout, "%s: %i names \"%s\" for \"%s[%li]\"\n", + __FUNCTION__, n_ctxs, get_type_name (tp), OPNAME (node), OPNUM (node))); } break; + case (iro_Const): { + tarval *tv = get_Const_tarval (node); + + /* only need 'NULL' pointer constants */ + if (mode_P == get_tarval_mode (tv)) { + if (get_tarval_null (mode_P) == tv) { + pto_t *pto = new_pto (node); + set_node_pto (node, pto); + } + } + } break; case (iro_Load): case (iro_Call): case (iro_Phi): @@ -263,19 +305,22 @@ static void init_pto (ir_node *node, void *env) } -/* Initialise the given graph for a new pass run */ +/** Initialise the given graph for a new pass run */ static void pto_init_graph_allocs (ir_graph *graph) { graph_info_t *ginfo = ecg_get_info (graph); - init_env_t init_env; + init_env_t *init_env; - init_env.n_ctxs = ginfo->n_ctxs; + init_env = xmalloc (sizeof (init_env_t)); + init_env->n_ctxs = ginfo->n_ctxs; /* HERE ("start"); */ - irg_walk_graph (graph, init_pto, NULL, &init_env); + irg_walk_graph (graph, init_pto, NULL, init_env); /* HERE ("end"); */ + memset (init_env, 0x00, sizeof (init_env_t)); + free (init_env); } /* =================================================== @@ -286,10 +331,10 @@ void fake_main_args (ir_graph *graph) { /* HERE ("start"); */ - entity *ent = get_irg_entity (graph); - type *mtp = get_entity_type (ent); + ir_entity *ent = get_irg_entity (graph); + ir_type *mtp = get_entity_type (ent); ir_node **args = find_irg_args (graph); - type *ctp = get_method_param_type (mtp, 1); /* ctp == char[]*[]* */ + ir_type *ctp = get_method_param_type (mtp, 1); /* ctp == char[]*[]* */ desc_t *arg_desc; pto_t *arg_pto; @@ -309,8 +354,9 @@ void fake_main_args (ir_graph *graph) set_node_pto (args [1], arg_pto); - DBGPRINT (1, (stdout, "fake_main_args():%i (%s[%li])\n", - __LINE__, OPNAME (args [1]), OPNUM (args [1]))); + DBGPRINT (1, (stdout, "%s:%i (%s[%li])\n", + __FUNCTION__, __LINE__, + OPNAME (args [1]), OPNUM (args [1]))); # ifdef TEST_MAIN_TYPE ctp = get_array_element_type (ctp); /* ctp == char[]* */ @@ -332,7 +378,7 @@ void fake_main_args (ir_graph *graph) /* Initialise the Init module */ void pto_init_init (void) { - pto_obst = xmalloc(sizeof(*pto_obst)); + pto_obst = (struct obstack*) xmalloc (sizeof (struct obstack)); obstack_init (pto_obst); } @@ -341,14 +387,14 @@ void pto_init_init (void) void pto_init_cleanup (void) { obstack_free (pto_obst, NULL); - memset (pto_obst, 0, sizeof (*pto_obst)); + memset (pto_obst, 0x00, sizeof (struct obstack)); free (pto_obst); pto_obst = NULL; } /* Initialise the Names of the Types/Entities */ -void pto_init_type_names () +void pto_init_type_names (void) { /* HERE ("start"); */ type_walk (clear_type_link, NULL, NULL); @@ -363,11 +409,12 @@ void pto_init_graph (ir_graph *graph) const int n_ctxs = ginfo->n_ctxs; /* 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)); - DBGPRINT (2, (stdout, "pto_init_graph(): init \"%s.%s\" for %i ctxs\n", + DBGPRINT (2, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", + __FUNCTION__, own_name, ent_name, n_ctxs)); /* HERE ("start"); */ @@ -386,19 +433,51 @@ void pto_init_graph (ir_graph *graph) /* Reset the given graph for a new pass run */ void pto_reset_graph_pto (ir_graph *graph, int ctx_idx) { - reset_env_t reset_env; - reset_env.ctx_idx = ctx_idx; + reset_env_t *reset_env; + + reset_env = (reset_env_t*) xmalloc (sizeof (reset_env_t)); + reset_env->ctx_idx = ctx_idx; /* HERE ("start"); */ - irg_walk_graph (graph, reset_node_pto, NULL, &reset_env); + irg_walk_graph (graph, reset_node_pto, NULL, reset_env); /* HERE ("end"); */ + memset (reset_env, 0x00, sizeof (reset_env_t)); + free (reset_env); } /* $Log$ + Revision 1.23 2007/01/16 15:45:42 beck + renamed type opcode to ir_opcode + + Revision 1.22 2006/12/13 19:46:47 beck + rename type entity into ir_entity + + Revision 1.21 2006/06/08 10:49:07 beck + renamed type to ir_type + + Revision 1.20 2005/12/05 12:19:54 beck + added missing include (not anymore included in libFirm) + + Revision 1.19 2005/06/17 17:42:32 beck + added doxygen docu + fixed (void) function headers + + Revision 1.18 2005/02/16 13:27:52 beck + added needed tv.h include + + Revision 1.17 2005/01/14 14:12:51 liekweg + prepare gnu extension fix + + Revision 1.16 2005/01/14 13:36:50 liekweg + don't put environments on the stack; handle consts + + Revision 1.15 2005/01/10 17:26:34 liekweg + fixup printfs, don't put environments on the stack + Revision 1.14 2005/01/05 14:25:54 beck renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG fronten