Commit d07b7388 authored by Florian Liekweg's avatar Florian Liekweg
Browse files

Bugfixes

[r4462]
parent 4de4d8d2
......@@ -573,7 +573,11 @@ void ecg_iterate_graphs (graph_hnd_t *hnd, void *env)
graph_info_t *ginfo = graph_infos_list;
while (NULL != ginfo) {
hnd (ginfo, env);
/* do not visit graphs that have 0 == ginfo->n_ctxs, since they
are not called */
if (0 != ginfo->n_ctxs) {
hnd (ginfo, env);
}
ginfo = ginfo->prev;
}
......@@ -1109,6 +1113,9 @@ void ecg_ecg ()
/*
$Log$
Revision 1.6 2004/11/24 14:53:55 liekweg
Bugfixes
Revision 1.5 2004/11/20 21:20:29 liekweg
Added iterator functions
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
/*
Project: libFIRM
File name: ir/ana/pto.h
Purpose: Import all includes needed for PTO
Purpose: Import all includes needed for PTO/Entry to PTO
Author: Florian
Modified by:
Created: Sat Nov 13 19:35:27 CET 2004
......@@ -21,6 +21,7 @@
/* ===================================================
Global Defines:
=================================================== */
# define N_INITIAL_OJBS 10
/* ===================================================
Global Data Types:
......@@ -29,6 +30,10 @@
/* ===================================================
Global Prototypes:
=================================================== */
/* Perform PTO on all visible graphs. */
void pto_init (int);
void pto_run (void);
void pto_cleanup (void);
/* ===================================================
Global Variables:
......@@ -41,6 +46,9 @@
/*
$Log$
Revision 1.6 2004/11/24 14:53:55 liekweg
Bugfixes
Revision 1.5 2004/11/18 16:37:07 liekweg
rewrite
......
......@@ -24,6 +24,7 @@
# include "pto_comp.h"
# include "pto_util.h"
# include "pto_name.h"
# include "pto_ctx.h"
# include "irnode.h"
......@@ -40,7 +41,7 @@
/* Local Data Types: */
typedef struct pto_env_str {
int dummy;
int ctx_idx;
} pto_env_t;
......@@ -50,7 +51,6 @@ typedef struct pto_env_str {
char *spaces = NULL;
/* Local Prototypes: */
static void pto_graph (ir_graph*);
static void pto_call (ir_graph*, ir_node*, pto_env_t*);
/* ===================================================
......@@ -66,16 +66,20 @@ static pto_t *get_pto_proj (ir_node *proj)
pto_t *in_pto = NULL;
pto_t *proj_pto = get_node_pto (proj);
ir_node *proj_in_in = NULL;
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);
proj_in_in = get_Proj_pred (proj_in);
const opcode in_in_op = get_irn_opcode (proj_in_in);
const long proj_in_proj = get_Proj_proj (proj_in);
assert ((pn_Start_T_args == proj_in_proj) ||
(pn_Call_T_result == proj_in_proj));
switch (in_in_op) {
case (iro_Start): /* ProjArg (ProjT (Start)) */
......@@ -105,7 +109,7 @@ static pto_t *get_pto_proj (ir_node *proj)
if (NULL != proj_pto) {
return (proj_pto);
} else {
in_pto = get_alloc_pto (proj_in);
in_pto = get_node_pto (proj_in);
assert (in_pto);
set_node_pto (proj, in_pto);
......@@ -126,6 +130,20 @@ static pto_t *get_pto_phi (ir_node *phi)
return (NULL);
}
static pto_t *get_pto_sel (ir_node *sel)
{
pto_t *pto = get_node_pto (sel);
if (NULL == pto) {
ir_node *in = get_Sel_ptr (sel);
pto = get_node_pto (in);
set_node_pto (sel, pto);
}
return (pto);
}
static pto_t *get_pto_ret (ir_node *ret)
{
pto_t *pto = get_node_pto (ret);
......@@ -150,6 +168,7 @@ static pto_t *get_pto (ir_node *node)
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_Sel): return (get_pto_sel (node));
case (iro_Return): return (get_pto_ret (node));
default:
......@@ -168,20 +187,25 @@ static pto_t *get_pto (ir_node *node)
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)));
DBGPRINT (0, (stdout, "%s (%s[%li]): pto = %p\n", __FUNCTION__, OPNAME (load), OPNUM (load), (void*) get_node_pto (load)));
ir_node *ptr = get_Load_ptr (load);
pto_t *ptr_pto = get_pto (ptr);
DBGPRINT (0, (stdout, "%s (%s[%li]): ptr = %p\n", __FUNCTION__, OPNAME (ptr), OPNUM (ptr), (void*) ptr_pto));
}
static void pto_store (ir_node *store, pto_env_t *pto_env)
{
/* perform store */
DBGPRINT (0, (stdout, "%s (%s[%li])\n", __FUNCTION__,
DBGPRINT (0, (stdout, "%s (%s[%li]) (no pto)\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)));
DBGPRINT (0, (stdout, "%s:%i (%s[%li]): pto = %p\n",
__FUNCTION__, __LINE__, OPNAME (call), OPNUM (call), (void*) get_node_pto (call)));
callEd_info_t *callEd_info = ecg_get_callEd_info (call);
......@@ -190,7 +214,11 @@ static void pto_method (ir_node *call, pto_env_t *pto_env)
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);
/* dike this out until we do procedure arguments and return
values */
if (0) {
pto_call (callEd_info->callEd, call, pto_env);
}
callEd_info = callEd_info->prev;
}
......@@ -221,11 +249,11 @@ static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env)
/* Todo: Compute Arguments */
/* Initialise Alloc Names and Node values */
pto_reset_graph_pto (graph, ctx_idx);
/* Initialise Alloc Names and Node values (nope, done in pto_graph ()) */
/* pto_reset_graph_pto (graph, ctx_idx); */
/* Visit/Iterate Graph */
pto_graph (graph);
pto_graph (graph, ctx_idx);
/* Restore CTX */
set_curr_ctx (old_ctx);
......@@ -249,15 +277,16 @@ 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 (0, (stdout, "%s (%s[%li])\n", __FUNCTION__,
OPNAME (raise), OPNUM (raise)));
DBGPRINT (0, (stdout, "%s (%s[%li]): pto = %p\n", __FUNCTION__,
OPNAME (raise), OPNUM (raise), (void*) get_node_pto (raise)));
}
static void pto_end_block (ir_node *end_block, pto_env_t *pto_env)
{
/* perform end block */
DBGPRINT (0, (stdout, "%s (%s[%li])\n", __FUNCTION__,
OPNAME (end_block), OPNUM (end_block)));
DBGPRINT (0, (stdout, "%s (%s[%li]): pto = %p\n", __FUNCTION__,
OPNAME (end_block), OPNUM (end_block),
(void*) get_node_pto (end_block)));
}
/* Perform the appropriate action on the given node */
......@@ -349,11 +378,23 @@ static void pto_graph_pass (ir_graph *graph, void *pto_env)
}
/* ===================================================
Exported Implementation:
=================================================== */
/* Main loop: Initialise and iterate over the given graph */
static void pto_graph (ir_graph *graph)
void pto_graph (ir_graph *graph, int ctx_idx)
{
pto_env_t *pto_env = xmalloc (sizeof (pto_env_t));
HERE ("start");
pto_env->ctx_idx = ctx_idx;
/* HERE ("start"); */
DBGPRINT (0, (stdout, "%s: start for ctx %i\n",
__FUNCTION__,
ctx_idx));
/* todo: pto_reset_graph_pto */
pto_reset_graph_pto (graph, ctx_idx);
/* todo (here): iterate, obey 'changed' attribute */
pto_graph_pass (graph, pto_env);
......@@ -363,27 +404,6 @@ static void pto_graph (ir_graph *graph)
HERE ("end");
}
/* "Fake" the arguments to the main method */
static void fake_main_args (ir_graph *graph)
{
HERE ("start");
/* todo: fake the arguments to the main method */
HERE ("end");
}
/* Helper to pto_init */
static void pto_init_graph_wrapper (graph_info_t *ginfo, void *__unused)
{
ir_graph *graph = ginfo->graph;
pto_init_graph (graph);
}
/* ===================================================
Exported Implementation:
=================================================== */
/* Set the PTO value for the given non-alloc node */
void set_node_pto (ir_node *node, pto_t *pto)
{
......@@ -418,70 +438,12 @@ pto_t *get_alloc_pto (ir_node *alloc)
return (alloc_pto -> curr_pto);
}
/* Initialise the module (not in pto_init.c because it's the entry to pto) */
void pto_init ()
{
HERE ("start");
ecg_init (1);
/* todo: initialise globals etc */
pto_init_type_names ();
/* todo: allocate ctx-sens names for allocs and set ... etc etc */
pto_init_type_names ();
ecg_iterate_graphs (pto_init_graph_wrapper, NULL);
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 */
spaces -= 511; /* hope that all changes to spaces are
properly nested */
memset (spaces, 0x00, 512);
free (spaces);
/* clean up ecg infos */
ecg_cleanup ();
HERE ("end");
}
/*
$Log$
Revision 1.3 2004/11/24 14:53:55 liekweg
Bugfixes
Revision 1.2 2004/11/20 21:21:56 liekweg
Finalise initialisation
......
......@@ -16,7 +16,9 @@
# ifndef _PTO_COMP_
# define _PTO_COMP_
# include "pto.h"
# include "irnode.h"
# include "qset.h"
/* ===================================================
Global Defines:
......@@ -26,7 +28,7 @@
Global Data Types:
=================================================== */
typedef struct pto_str {
int dummy;
qset_t *values;
} pto_t;
typedef struct alloc_pto_str {
......@@ -38,6 +40,9 @@ typedef struct alloc_pto_str {
/* ===================================================
Global Prototypes:
=================================================== */
/* Main loop: Initialise the graph for the given ctx_idx and iterate over it */
void pto_graph (ir_graph*, int);
/* 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 */
......@@ -50,11 +55,6 @@ void set_alloc_pto (ir_node*, alloc_pto_t*);
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:
=================================================== */
......@@ -66,6 +66,9 @@ void pto_cleanup (void);
/*
$Log$
Revision 1.2 2004/11/24 14:53:55 liekweg
Bugfixes
Revision 1.1 2004/11/18 16:37:34 liekweg
rewritten
......
......@@ -26,7 +26,7 @@
# include "ecg.h"
# include "irnode.h"
# include "xmalloc.h"
/* # include "xmalloc.h" */
/* Local Defines: */
......@@ -85,6 +85,9 @@ ctx_info_t *set_curr_ctx (ctx_info_t *ctx)
/*
$Log$
Revision 1.3 2004/11/24 14:53:55 liekweg
Bugfixes
Revision 1.2 2004/11/20 21:21:35 liekweg
Add pto_ctx_allocs
......
......@@ -23,7 +23,7 @@
# include "pto_debug.h"
# include "irnode.h"
# include "xmalloc.h"
/* # include "xmalloc.h" */
/* Local Defines: */
......@@ -56,6 +56,9 @@ void set_dbg_lvl (int lvl)
/*
$Log$
Revision 1.2 2004/11/24 14:53:56 liekweg
Bugfixes
Revision 1.1 2004/11/18 16:37:34 liekweg
rewritten
......
......@@ -23,7 +23,7 @@
# 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 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)
......@@ -47,6 +47,9 @@ void set_dbg_lvl (int);
/*
$Log$
Revision 1.2 2004/11/24 14:53:56 liekweg
Bugfixes
Revision 1.1 2004/11/18 16:37:34 liekweg
rewritten
......
......@@ -20,15 +20,23 @@
pto_init: Initialisation Functions
*/
# include <obstack.h>
# include <string.h>
# include "pto.h"
# include "pto_init.h"
# include "pto_debug.h"
# include "pto_comp.h"
# include "pto_name.h"
# include "pto_util.h"
# include "typewalk.h"
# include "irgwalk.h"
# include "xmalloc.h"
/* Local Defines: */
# define obstack_chunk_alloc xmalloc
# define obstack_chunk_free free
/* Local Data Types: */
typedef struct init_env_str
......@@ -42,6 +50,9 @@ typedef struct reset_env_str
} reset_env_t;
/* Local Variables: */
extern struct obstack *qset_obst; /* from pto_name */
static struct obstack *pto_obst = NULL; /* all pto_t's go onto this one */
/* Local Prototypes: */
......@@ -51,28 +62,45 @@ typedef struct reset_env_str
/* Allocate a new pto */
static pto_t *new_pto (ir_node *node)
{
/* dummy implementation for fake_pto */
pto_t *pto = xmalloc (sizeof (pto_t));
pto_t *pto = obstack_alloc (pto_obst, sizeof (pto_t));
pto->values = qset_new (N_INITIAL_OJBS, qset_obst);
return (pto);
}
/* Allocate a new alloc_pto */
static alloc_pto_t *new_alloc_pto (ir_node *node, int n_ctxs)
static alloc_pto_t *new_alloc_pto (ir_node *alloc, int n_ctxs)
{
assert (iro_Alloc == get_irn_opcode (alloc));
int i;
/* dummy implementation for testing */
alloc_pto_t *alloc_pto = xmalloc (sizeof (alloc_pto_t));
alloc_pto_t *alloc_pto = obstack_alloc (pto_obst, sizeof (alloc_pto_t));
type *tp = get_Alloc_type (alloc);
alloc_pto->ptos = (pto_t**) xmalloc (n_ctxs * sizeof (pto_t*));
alloc_pto->ptos = (pto_t**) obstack_alloc (pto_obst, n_ctxs * sizeof (pto_t*));
for (i = 0; i < n_ctxs; i ++) {
alloc_pto->ptos [i] = new_pto (node);
desc_t *desc = new_name (tp, alloc);
alloc_pto->ptos [i] = new_pto (alloc);
qset_insert (alloc_pto->ptos [i]->values, desc);
}
return (alloc_pto);
}
/* Allocate a new pto for a symconst */
static pto_t* new_symconst_pto (ir_node *symconst)
{
assert (iro_SymConst == get_irn_opcode (symconst));
pto_t *pto = new_pto (symconst);
entity *ent = get_SymConst_entity (symconst);
desc_t *desc = new_ent_name (ent);
qset_insert (pto->values, desc);
return (pto);
}
/* Helper to pto_init --- clear the link fields of class types */
static void clear_type_link (type_or_ent *thing, void *__unused)
......@@ -121,13 +149,13 @@ static void reset_node_pto (ir_node *node, void *env)
case (iro_Const):
case (iro_Call):
case (iro_Phi): {
/* todo: allocate 'empty' pto values */
/* allocate 'empty' pto values */
pto_t *pto = new_pto (node);
set_node_pto (node, pto);
} break;
case (iro_Alloc): {
/* todo: set alloc to 'right' current pto */
/* set alloc to 'right' current pto */
alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (node);
alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
} break;
......@@ -139,7 +167,7 @@ static void reset_node_pto (ir_node *node, void *env)
}
/* Temporary fix until we get 'real' ptos: Allocate some dummy for pto */
static void init_alloc_pto (ir_node *node, void *env)
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;
......@@ -147,20 +175,43 @@ static void init_alloc_pto (ir_node *node, void *env)
const opcode op = get_irn_opcode (node);
switch (op) {
case (iro_Load):
case (iro_SymConst):
case (iro_Const):
case (iro_Call):
case (iro_Phi): {
/* nothing (handled by init_node_pto) */
} break;
case (iro_SymConst): {
const symconst_kind kind = get_SymConst_kind (node);
if ((kind == symconst_addr_name) || (kind == symconst_addr_ent)) {
entity *ent = get_SymConst_entity (node);
if (is_pointer_type (get_entity_type (ent))) {
DBGPRINT (0, (stdout, "%s: new name \"%s\" for symconst \"%s[%li]\"\n",
__FUNCTION__,
get_entity_name (ent),
OPNAME (node),
OPNUM (node)));
pto_t *symconst_pto = new_symconst_pto (node);
set_node_pto (node, symconst_pto);
}
}
} break;
case (iro_Alloc): {
/* todo: alloc 'right' ptos */
type *tp = get_Alloc_type (node); /* debugging only */
alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
set_alloc_pto (node, alloc_pto);
} break;
DBGPRINT (0, (stdout, "%s: %i names \"%s\" for alloc \"%s[%li]\"\n",
__FUNCTION__,
n_ctxs,
get_type_name (tp),
OPNAME (node),
OPNUM (node)));
} break;
case (iro_Load):
case (iro_Call):
case (iro_Phi):
case (iro_Const):
/* nothing --- handled by reset_node_pto on each pass */
break;
default: {
/* nothing */
} break;
......@@ -179,7 +230,10 @@ static void pto_init_graph_allocs (ir_graph *graph)
HERE ("start");
irg_walk_graph (graph, init_alloc_pto, NULL, init_env);
irg_walk_graph (graph, init_pto, NULL, init_env);
memset (init_env, 0x00, sizeof (init_env_t));
free (init_env);
HERE ("end");
}
......@@ -187,6 +241,67 @@ static void pto_init_graph_allocs (ir_graph *graph)
/* ===================================================
Exported Implementation:
=================================================== */
/* "Fake" the arguments to the main method */
void fake_main_args (ir_graph *graph)
{