From: Florian Liekweg Date: Thu, 18 Nov 2004 16:37:34 +0000 (+0000) Subject: rewritten X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=ab26e77386f81ec8f84d1bfe41af8ae11be6c913;p=libfirm rewritten [r4429] --- diff --git a/ir/ana2/pto_comp.c b/ir/ana2/pto_comp.c new file mode 100644 index 000000000..b9b68e1bd --- /dev/null +++ b/ir/ana2/pto_comp.c @@ -0,0 +1,476 @@ +/* -*- 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. +*/ + +# ifdef HAVE_CONFIG_H +# include +# endif + +/* + pto_comp: Main Implementation of PTO +*/ + +# include /* for memset */ + +# include "pto_comp.h" +# include "pto_util.h" +# include "pto_ctx.h" + +# include "irnode.h" +# include "irprog.h" +# include "xmalloc.h" +# include "irmemwalk.h" + +# include "pto_debug.h" +# include "pto_init.h" + +# include "ecg.h" + +/* Local Defines: */ + +/* Local Data Types: */ +typedef struct pto_env_str { + int dummy; +} pto_env_t; + + +/* Local Variables: */ + +/* Debug only: */ +char *spaces = NULL; + +/* Local Prototypes: */ +static void pto_graph (ir_graph*); +static void pto_call (ir_graph*, ir_node*, pto_env_t*); + +/* =================================================== + Local Implementation: + =================================================== */ + +/* Propagation of PTO values */ +static pto_t *get_pto_proj (ir_node *proj) +{ + 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); + pto_t *in_pto = NULL; + pto_t *proj_pto = get_node_pto (proj); + + switch (in_op) { + case (iro_Start): /* ProjT (Start) */ + assert (0 && "pto from ProjT(Start) requested"); + + return (NULL); + case (iro_Proj): /* ProjT (Start), ProjT (Call) */ + assert ((pn_Start_T_args == proj_proj) || + (pn_Call_T_result == proj_proj)); + ir_node *proj_in_in = get_Proj_pred (proj_in); + const opcode in_in_op = get_irn_opcode (proj_in_in); + + switch (in_in_op) { + case (iro_Start): /* ProjArg (ProjT (Start)) */ + /* then the pto value must have been set to the node */ + assert (proj_pto); + + return (proj_pto); + case (iro_Call): /* ProjV (ProjT (Call)) */ + if (NULL != proj_pto) { + return (proj_pto); + } else { + in_pto = get_node_pto (proj_in); + set_node_pto (proj, in_pto); + + return (in_pto); + } + default: assert (0 && "Proj(Proj(?))"); + } + /* done with case (in_op == iro_Proj) */ + + case (iro_Load): /* ProjV (Load) */ + assert (pn_Load_res == proj_proj); + /* FALLTHROUGH */ + case (iro_Call): /* ProjT (Call) */ + /* FALLTHROUGH */ + case (iro_Alloc): /* ProjV (Alloc) */ + if (NULL != proj_pto) { + return (proj_pto); + } else { + in_pto = get_alloc_pto (proj_in); + assert (in_pto); + + set_node_pto (proj, in_pto); + return (in_pto); + } + default: + fprintf (stderr, "%s: not handled: proj (%s[%li])\n", + __FUNCTION__, + get_op_name (get_irn_op (proj_in)), + get_irn_node_nr (proj_in)); + assert (0 && "Proj(?)"); + } + +} + +static pto_t *get_pto_phi (ir_node *phi) +{ + return (NULL); +} + +static pto_t *get_pto_ret (ir_node *ret) +{ + pto_t *pto = get_node_pto (ret); + + if (NULL == pto) { + ir_node *in = get_Return_res (ret, 0); + + pto = get_node_pto (in); + set_node_pto (ret, pto); + } + + return (pto); +} + + +/* Dispatch to propagate PTO values */ +static pto_t *get_pto (ir_node *node) +{ + const opcode op = get_irn_opcode (node); + + switch (op) { + case (iro_Cast): return (get_pto (get_Cast_op (node))); + case (iro_Proj): return (get_pto_proj (node)); + case (iro_Phi): return (get_pto_phi (node)); + case (iro_Return): return (get_pto_ret (node)); + + default: + /* stopgap measure */ + 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"); + + } +} + + +/* Actions for the nodes: */ +static void pto_load (ir_node *load, pto_env_t *pto_env) +{ + /* perform load */ + DBGPRINT (0, (stdout, "%s (%s[%li])\n", __FUNCTION__, OPNAME (load), OPNUM (load))); +} + +static void pto_store (ir_node *store, pto_env_t *pto_env) +{ + /* perform store */ + DBGPRINT (0, (stdout, "%s (%s[%li])\n", __FUNCTION__, + OPNAME (store), OPNUM (store))); +} + +static void pto_method (ir_node *call, pto_env_t *pto_env) +{ + DBGPRINT (0, (stdout, "%s:%i (%s[%li])\n", + __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call))); + + callEd_info_t *callEd_info = ecg_get_callEd_info (call); + + int i = 0; + while (NULL != callEd_info) { + DBGPRINT (0, (stdout, "%s:%i (%s[%li]), graph %i\n", + __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call), i ++)); + + pto_call (callEd_info->callEd, call, pto_env); + + callEd_info = callEd_info->prev; + } +} + + +static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env) +{ + /* perform call */ + DBGPRINT (0, (stdout, "%s:%i (%s[%li])\n", + __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call))); + + 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)); + + if (! get_irg_is_mem_visited (graph)) { + graph_info_t *ginfo = ecg_get_info (graph); + + /* Save CTX */ + int ctx_idx = find_ctx_idx (call, ginfo, get_curr_ctx ()); + /* ctx_info_t *call_ctx = find_ctx (call, ginfo, get_curr_ctx ()); */ + ctx_info_t *call_ctx = get_ctx (ginfo, ctx_idx); + ctx_info_t *old_ctx = set_curr_ctx (call_ctx); + DBGPRINT (1, (stdout, "%s>CTX: ", -- spaces)); + DBGEXE (1, ecg_print_ctx (call_ctx, stdout)); + + /* Todo: Compute Arguments */ + + /* Visit Graph */ + pto_graph (graph); + + /* Initialise Alloc Names */ + pto_init_allocs (ginfo, ctx_idx); + + /* Restore CTX */ + set_curr_ctx (old_ctx); + + DBGPRINT (1, (stdout, "%s curr_pto); +} + +/* Initialise the module (should be moved to pto_init) */ +void pto_init () +{ + HERE ("start"); + ecg_init (1); + + /* todo: initialise globals etc */ + pto_init_type_names (); + + spaces = (char*) xmalloc (512 * sizeof (char)); + memset (spaces, ' ', 512); + spaces += 511; + *spaces = '\0'; + + /* initialise for the CTX-sensitive ecg-traversal */ + set_curr_ctx (get_main_ctx ()); + HERE ("end"); +} + +void pto_run (int dbg_lvl) +{ + HERE ("start"); + set_dbg_lvl (dbg_lvl); + + ir_graph *graph = get_irp_main_irg (); + fake_main_args (graph); + + /* todo: clear entity/type links */ + + DBGPRINT (0, (stdout, "START PTO\n")); + DBGPRINT (0, (stdout, "START GRAPH (0x%08x) of \"%s.%s\"\n", + (int) graph, + get_type_name (get_entity_owner (get_irg_entity (graph))), + get_entity_name (get_irg_entity (graph)))); + + /* do we need some kind of environment here? */ + pto_graph (graph); + + DBGPRINT (0, (stdout, "END PTO\n")); + HERE ("end"); +} + +void pto_cleanup () +{ + HERE ("start"); + /* todo: clean up our own mess */ + /* memset (spaces, 0x00, 512); */ + /* free (spaces); */ + + /* clean up ecg infos */ + ecg_cleanup (); + HERE ("end"); +} + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_comp.h b/ir/ana2/pto_comp.h new file mode 100644 index 000000000..dc7e0b6b9 --- /dev/null +++ b/ir/ana2/pto_comp.h @@ -0,0 +1,73 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_comp.h + 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. +*/ + + +# ifndef _PTO_COMP_ +# define _PTO_COMP_ + +# include "irnode.h" + +/* =================================================== + Global Defines: + =================================================== */ + +/* =================================================== + Global Data Types: + =================================================== */ +typedef struct pto_str { + int dummy; +} pto_t; + +typedef struct alloc_pto_str { + int dummy; + pto_t **ptos; /* all names */ + pto_t *curr_pto; /* name for current ctx */ +} alloc_pto_t; + +/* =================================================== + Global Prototypes: + =================================================== */ +/* Set the PTO value for the given node */ +void set_node_pto (ir_node*, pto_t*); +/*Get the PTO value for the given non-alloc node */ +pto_t *get_node_pto (ir_node*); + +/* Set the PTO value for the given alloc node */ +void set_alloc_pto (ir_node*, alloc_pto_t*); + +/*Get the current PTO value for the given alloc node */ +pto_t *get_alloc_pto (ir_node*); + + +/* Perform PTO on all visible graphs. */ +void pto_init (void); +void pto_run (int); +void pto_cleanup (void); + +/* =================================================== + Global Variables: + =================================================== */ + + +# endif /* not defined _PTO_COMP_ */ + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_ctx.c b/ir/ana2/pto_ctx.c new file mode 100644 index 000000000..725797a46 --- /dev/null +++ b/ir/ana2/pto_ctx.c @@ -0,0 +1,93 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_ctx.c + Purpose: ... + 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. +*/ + +# ifdef HAVE_CONFIG_H +# include +# endif + +/* + pto_ctx: ... +*/ + +# include "pto_ctx.h" + +# include "irnode.h" +# include "xmalloc.h" + +# include "pto_debug.h" + +/* Local Defines: */ + +/* Local Data Types: */ + +/* Local Variables: */ +static ctx_info_t *curr_ctx = NULL; + +/* Local Prototypes: */ + +/* =================================================== + Local Implementation: + =================================================== */ + + +/* =================================================== + Exported Implementation: + =================================================== */ +/* Find the appropriate ctx for the given call and the given graph */ +/* ctx_info_t *find_ctx (ir_node *call, graph_info_t *ginfo, ctx_info_t *curr_ctx) */ +int find_ctx_idx (ir_node *call, graph_info_t *ginfo, ctx_info_t *curr_ctx) +{ + int i; + const int n_ctxs = ginfo->n_ctxs; + + for (i = 0; i < n_ctxs; i ++) { + ctx_info_t *ctx = ginfo->ctxs [i]; + + if ((ctx->enc == curr_ctx) && (ctx->call == call)) { + return (i); + } + } + + fflush (stdout); + assert (0 && "CTX not found"); + + return (-1); +} + +/* Get the current ctx */ +ctx_info_t *get_curr_ctx (void) +{ + return (curr_ctx); +} + +/* Set the current ctx to the given ctx. Return the old value */ +ctx_info_t *set_curr_ctx (ctx_info_t *ctx) +{ + ctx_info_t *old_ctx = curr_ctx; + + curr_ctx = ctx; + + return (old_ctx); +} + + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_ctx.h b/ir/ana2/pto_ctx.h new file mode 100644 index 000000000..b7cf7f3bd --- /dev/null +++ b/ir/ana2/pto_ctx.h @@ -0,0 +1,57 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_ctx.h + Purpose: ... + 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. +*/ + + +# ifndef _PTO_CTX_ +# define _PTO_CTX_ + +# include "ecg.h" + +/* =================================================== + Global Defines: + =================================================== */ + +/* =================================================== + Global Data Types: + =================================================== */ + +/* =================================================== + Global Prototypes: + =================================================== */ +/* Find the appropriate ctx for the given call and the given graph */ +/* ctx_info_t *find_ctx (ir_node*, graph_info_t*, ctx_info_t*); */ +int find_ctx_idx (ir_node*, graph_info_t*, ctx_info_t*); + +/* Get the current ctx */ +ctx_info_t *get_curr_ctx (void); + +/* Set the current ctx to the given ctx. Return the old value */ +ctx_info_t *set_curr_ctx (ctx_info_t*); + +/* =================================================== + Global Variables: + =================================================== */ + + +# endif /* not defined _PTO_CTX_ */ + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_debug.c b/ir/ana2/pto_debug.c new file mode 100644 index 000000000..d68f57567 --- /dev/null +++ b/ir/ana2/pto_debug.c @@ -0,0 +1,63 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_debug.c + Purpose: Useful Macros for Debugging + Author: Florian + Modified by: + Created: Sat Nov 13 19:30:21 CET 2004 + CVS-ID: $Id$ + Copyright: (c) 1999-2004 Universität Karlsruhe + Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE. +*/ + +# ifdef HAVE_CONFIG_H +# include +# endif + +/* + pto_debug: Useful Macros for Debugging +*/ + +# include "pto_debug.h" + +# include "irnode.h" +# include "xmalloc.h" + +/* Local Defines: */ + +/* Local Data Types: */ + +/* Local Variables: */ +static int dbg_lvl = 0; + +/* Local Prototypes: */ + +/* =================================================== + Local Implementation: + =================================================== */ + + +/* =================================================== + Exported Implementation: + =================================================== */ +int get_dbg_lvl () +{ + return (dbg_lvl); +} + +void set_dbg_lvl (int lvl) +{ + dbg_lvl = lvl; +} + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_debug.h b/ir/ana2/pto_debug.h new file mode 100644 index 000000000..0a18a4c87 --- /dev/null +++ b/ir/ana2/pto_debug.h @@ -0,0 +1,54 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_debug.h + Purpose: Useful Macros for Debugging + Author: Florian + Modified by: + Created: Sat Nov 13 19:30:21 CET 2004 + CVS-ID: $Id$ + Copyright: (c) 1999-2004 Universität Karlsruhe + Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE. +*/ + + +# ifndef _PTO_DEBUG_ +# define _PTO_DEBUG_ + +/* =================================================== + Global Defines: + =================================================== */ +# define DBGPRINT(lvl, args) if (get_dbg_lvl () > lvl) { fprintf args; } +# define DBGEXE(lvl, cmd) if (get_dbg_lvl () > lvl) {cmd;} +# define OPNAME(node) get_op_name (get_irn_op (node)) +# define OPNUM(node) get_irn_node_nr (node) +# define HERE(msg) fprintf (stdout, "%s:%i: %s\n", __FUNCTION__, __LINE__, msg) +# define HERE2(msg1, msg2) fprintf (stdout, "%s:%i: %s %s\n", __FUNCTION__, __LINE__, msg1, msg2) +# define HERE3(msg1, msg2, msg3) fprintf (stdout, "%s:%i: %s %s %s\n", __FUNCTION__, __LINE__, msg1, msg2, msg3) + +/* =================================================== + Global Data Types: + =================================================== */ + +/* =================================================== + Global Data Prototypes: + =================================================== */ +int get_dbg_lvl (void); +void set_dbg_lvl (int); + +/* =================================================== + Global Variables: + =================================================== */ + +# endif /* not defined _PTO_DEBUG_ */ + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_name.c b/ir/ana2/pto_name.c new file mode 100644 index 000000000..9611252f1 --- /dev/null +++ b/ir/ana2/pto_name.c @@ -0,0 +1,57 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_name.c + Purpose: ... + 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. +*/ + +# ifdef HAVE_CONFIG_H +# include +# endif + +/* + pto_name: ... +*/ + +# include "pto_name.h" + +# include "irnode.h" +# include "xmalloc.h" + +# include "pto_debug.h" + +/* Local Defines: */ + +/* Local Data Types: */ + +/* Local Variables: */ + +/* Local Prototypes: */ + +/* =================================================== + Local Implementation: + =================================================== */ + + +/* =================================================== + Exported Implementation: + =================================================== */ + + + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/ diff --git a/ir/ana2/pto_name.h b/ir/ana2/pto_name.h new file mode 100644 index 000000000..8625d7ea1 --- /dev/null +++ b/ir/ana2/pto_name.h @@ -0,0 +1,46 @@ +/* -*- c -*- */ + +/* + Project: libFIRM + File name: ir/ana/pto_name.h + Purpose: ... + 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. +*/ + + +# ifndef _PTO_NAME_ +# define _PTO_NAME_ + +/* =================================================== + Global Defines: + =================================================== */ + +/* =================================================== + Global Data Types: + =================================================== */ + +/* =================================================== + Global Prototypes: + =================================================== */ + +/* =================================================== + Global Variables: + =================================================== */ + + +# endif /* not defined _PTO_NAME_ */ + + + +/* + $Log$ + Revision 1.1 2004/11/18 16:37:34 liekweg + rewritten + + +*/