Commit 41b022e5 authored by Florian Liekweg's avatar Florian Liekweg
Browse files

Moved memwalk stuf into irmemwalk

Moved lset stuff into lset
Moved typalise stuff into typalise

[r4175]
parent 41c7a004
......@@ -13,14 +13,14 @@
top_srcdir := @top_srcdir@
srcdir = @srcdir@
topdir = ../..
subdir := ir/ana
subdir := ir/ana2
INSTALL_HEADERS = pto.h ecg.h \
INSTALL_HEADERS = pto.h ecg.h irmemwalk.h lset.h typalise.h \
SOURCES = $(INSTALL_HEADERS)
SOURCES += Makefile.in \
pto.c ecg.c
pto.c ecg.c irmemwalk.c lset.c typalise.c
include $(topdir)/MakeRules
......
This diff is collapsed.
/* -*- c -*- */
/*
* Project: libFIRM
* File name: ir/ana2/irmemwalk.c
* Purpose: walk along memory edges
* Author: Florian
* Modified by:
* Created: Mon 18 Oct 2004
* CVS-ID: $Id$
* Copyright: (c) 1999-2004 Universitt Karlsruhe
* Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
/*
Walk over a firm graph along its memory edges.
Any number of graphs can be visited at the same time, but no graph
can be traversed more than once at any time.
*/
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
# include "irgwalk.h" /* for irg_walk_func */
# include "xmalloc.h"
# ifndef TRUE
# define TRUE 1
# define FALSE 0
# endif /* not defined TRUE */
/*
Data
*/
/* environment for a single memory walker */
typedef struct walk_mem_env_str {
ir_graph *graph; /* the graph we're visiting */
int visited; /* 'visited' marker */
irg_walk_func *pre; /* pre action */
irg_walk_func *post; /* post action */
void *env; /* user-defined environment */
struct walk_mem_env_str *prev; /* link up walking instances */
/* what else? */
} walk_mem_env_t;
/*
Globals
*/
/* Link up walking instances */
static walk_mem_env_t *walk_envs = NULL;
/*
Walk over the firm nodes of a graph via the memory edges (only)
starting from a node that has a memory input.
*/
static void irg_walk_mem_node (ir_node *node,
walk_mem_env_t *walk_env)
{
const opcode op = get_irn_opcode (node);
ir_node *in = NULL;
if (get_irn_visited (node) >= walk_env->visited) {
return;
} else {
set_irn_visited (node, walk_env->visited + 1);
}
fprintf (stdout, "Node (0x%08x).op = %s\n", (int)
node,
get_op_name (get_irn_op (node)));
if (NULL != walk_env->pre) {
walk_env->pre (node, walk_env->env);
}
switch (op) {
case (iro_Start): {
} break;
case (iro_Load): {
in = get_Load_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Store): {
in = get_Store_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Alloc): {
in = get_Alloc_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Free): {
in = get_Free_mem (node);
/* WTF? */
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Raise): {
in = get_Raise_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Sel): {
in = get_Sel_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Call): {
in = get_Call_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Return): {
in = get_Return_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Proj): {
in = get_Proj_pred (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Phi): {
int i;
int n_ins = get_irn_arity (node);
for (i = 0; i < n_ins; i ++) {
in = get_irn_n (node, i);
irg_walk_mem_node (in, walk_env);
}
} break;
case (iro_Div): {
in = get_Div_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Quot): {
in = get_Quot_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_Mod): {
in = get_Mod_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
case (iro_DivMod): {
in = get_DivMod_mem (node);
irg_walk_mem_node (in, walk_env);
} break;
default: {
assert (0 && "something not handled");
}
}
if (NULL != walk_env->post) {
walk_env->post (node, walk_env->env);
}
}
/*
See whether the given graph is being visited right now.
We can't be visiting a graph multiple times.
*/
int get_irg_is_mem_visited (ir_graph *graph)
{
walk_mem_env_t *walk_env = walk_envs;
while (NULL != walk_env) {
if (graph == walk_env->graph) {
return (TRUE);
}
walk_env = walk_env->prev;
}
return (FALSE);
}
/*
Walk over the nodes of the given graph via the memory edges (only).
Each graph can only be subject to this walk once at any given time.
*/
void irg_walk_mem (ir_graph *graph,
irg_walk_func *pre, irg_walk_func *post,
void *env)
{
int i;
ir_node *ret = NULL;
ir_node *end = get_irg_end_block (graph);
int n_ins;
walk_mem_env_t *walk_env = (walk_mem_env_t*) xmalloc (sizeof (walk_mem_env_t));
assert (! get_irg_is_mem_visited (graph));
walk_env->graph = graph;
inc_irg_visited (walk_env->graph);
walk_env->visited = get_irg_visited (graph);
walk_env->prev = walk_envs;
walk_envs = walk_env;
walk_env->pre = pre;
walk_env->post = post;
walk_env->env = env;
/* 'graph' is not actually being visited right now, but it should be reported that way */
assert (get_irg_is_mem_visited (graph));
/* all return nodes */
n_ins = get_irn_arity (end);
for (i = 0; i < n_ins; i ++) {
ret = get_irn_n (end, i);
irg_walk_mem_node (ret, walk_env);
}
/*
The end NODE sometimes has some more ins. not sure whether we need to walk them.
*/
/* allow only properly nested calls right now */
assert (walk_envs == walk_env);
walk_envs = walk_envs->prev;
free (walk_env);
assert (! get_irg_is_mem_visited (graph));
}
/* -*- c -*- */
/*
* Project: libFIRM
* File name: ir/ana2/irmemwalk.h
* Purpose: walk along memory edges
* Author: Florian
* Modified by:
* Created: Mon 18 Oct 2004
* CVS-ID: $Id$
* Copyright: (c) 1999-2004 Universitt Karlsruhe
* Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
# ifndef _IRMEMWALK_H_
# define _IRMEMWALK_H_
# include "irgraph.h"
# include "irgwalk.h"
void irg_walk_mem (ir_graph*, irg_walk_func*, irg_walk_func*, void*);
int get_irg_is_mem_visited (ir_graph*);
# endif /* not defined _IRMEMWALK_H_ */
/*
$Log$
Revision 1.1 2004/10/21 11:09:37 liekweg
Moved memwalk stuf into irmemwalk
Moved lset stuff into lset
Moved typalise stuff into typalise
*/
/* -*- c -*- */
/*
* Project: libFIRM
* File name: ir/ana2/lset.c
* Purpose: Lists, err, Sets
* Author: Florian
* Modified by:
* Created: Mon 18 Oct 2004
* CVS-ID: $Id$
* Copyright: (c) 1999-2004 Universitt Karlsruhe
* Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
# include "lset.h"
# include "xmalloc.h"
# ifndef TRUE
# define TRUE 1
# define FALSE 0
# endif /* not defined TRUE */
# include <assert.h>
# include <string.h> /* need memset */
/*
Lists, err, Sets
*/
/* create a new lset */
lset_t *lset_create (void)
{
lset_t *lset = xmalloc (sizeof (lset_t));
return (lset);
}
/* check whether the lset contains an entry for the given data */
int lset_contains (lset_t *lset, void *data)
{
lset_entry_t *entry = lset->first;
while (NULL != entry) {
if (data == entry->data) {
return (TRUE);
}
entry = entry->next;
}
return (FALSE);
}
/* check whether the given lset is empty */
int lset_empty (lset_t *lset)
{
return (NULL == lset->first);
}
/* insert the data into the lset (unless there's an entry for it
already) */
void lset_insert (lset_t *lset, void *data)
{
if (! lset_contains (lset, data)) {
lset_entry_t *entry = xmalloc (sizeof (lset_entry_t));
entry->data = data;
entry->next = lset->first;
lset->first = entry;
if (NULL == lset->last) {
lset->last = entry;
}
lset->n_entries ++;
}
}
/* insert all entries from src into tgt */
void lset_insert_all (lset_t *tgt, lset_t *src)
{
lset_entry_t *curs = src->first;
while (NULL != curs) {
lset_insert (tgt, curs->data);
curs = curs->next;
}
}
/* append src to tgt. src is deallocated. */
void lset_append (lset_t *tgt, lset_t *src)
{
assert (! tgt->last->next);
tgt->last->next = src->first;
tgt->last = src->last;
tgt->n_entries += src->n_entries;
memset (src, 0x00, sizeof (lset_t));
free (src);
}
/* remove the entry for the given data element from the lset. return
TRUE iff it was on the list in the first place, FALSE else */
int lset_remove (lset_t *lset, void *data)
{
lset_entry_t *entry = lset->first;
lset_entry_t *prev = NULL;
while (NULL != entry) {
if (data == entry->data) {
/* ok, dike it out */
if (NULL == prev) { /* ok, it's lset->first that needs diking */
lset->first = entry->next;
} else {
prev->next = entry->next;
}
memset (entry, 0x00, sizeof (lset_entry_t));
free (entry);
lset->n_entries --;
return (TRUE);
}
prev = entry;
entry = entry->next;
}
return (FALSE);
}
/* prepare the given lset for an iteration. return the first element. */
void *lset_first (lset_t *lset)
{
lset->curs = lset->first;
if (lset->first) {
return (lset->first->data);
} else {
return (NULL);
}
}
/* after calling lset_first, get the next element, if applicable, or
NULL */
void *lset_next (lset_t *lset)
{
lset->curs = lset->curs->next;
if (lset->curs) {
return (lset->curs->data);
} else {
return (NULL);
}
}
/* say how many entries there are in the given lset */
int lset_n_entries (lset_t *lset)
{
return (lset->n_entries);
}
/* deallocate the lset and all of its entries */
void lset_destroy (lset_t *lset)
{
lset_entry_t *curs = lset->first;
while (NULL != curs) {
lset_entry_t *tmp = curs->next;
memset (curs, 0x00, sizeof (lset_entry_t));
free (curs);
curs = tmp;
}
memset (lset, 0x00, sizeof (lset_t));
free (lset);
}
/*
$Log$
Revision 1.1 2004/10/21 11:09:37 liekweg
Moved memwalk stuf into irmemwalk
Moved lset stuff into lset
Moved typalise stuff into typalise
*/
/* -*- c -*- */
/*
* Project: libFIRM
* File name: ir/ana2/lset.h
* Purpose: Lists, err, Sets
* Author: Florian
* Modified by:
* Created: Mon 18 Oct 2004
* CVS-ID: $Id$
* Copyright: (c) 1999-2004 Universität Karlsruhe
* Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
# ifndef _LSET_H_
# define _LSET_H_
/*
Data Types and Structures
*/
/* Lists, err, Sets */
typedef struct lset_entry
{
void *data;
struct lset_entry *next;
} lset_entry_t;
typedef struct lset
{
lset_entry_t *first;
lset_entry_t *last; /* useful for lset_append */
lset_entry_t *curs; /* for lset_first/lset_next */
int n_entries;
} lset_t;
/* create a new lset */
lset_t *lset_create (void);
/* check whether the lset contains an entry for the given data */
int lset_contains (lset_t*, void*);
/* check whether the given lset is empty */
int lset_empty (lset_t*);
/* insert the data into the lset (unless there's an entry for it
already) */
void lset_insert (lset_t*, void*);
/* insert all entries from src into tgt */
void lset_insert_all (lset_t*, lset_t*);
/* append src to tgt. src is deallocated. */
void lset_append (lset_t*, lset_t*);
/* remove the entry for the given data element from the lset. return
TRUE iff it was on the list in the first place, FALSE else */
int lset_remove (lset_t*, void*);
/* prepare the given lset for an iteration. return the first element. */
void *lset_first (lset_t*);
/* after calling lset_first, get the next element, if applicable, or
NULL */
void *lset_next (lset_t*);
/* say how many entries there are in the given lset */
int lset_n_entries (lset_t*);
/* deallocate the lset and all of its entries */
void lset_destroy (lset_t*);
# endif /* not defined _LSET_H_ */
/*
$Log$
Revision 1.1 2004/10/21 11:09:37 liekweg
Moved memwalk stuf into irmemwalk
Moved lset stuff into lset
Moved typalise stuff into typalise
*/
......@@ -2,7 +2,7 @@
/*
* Project: libFIRM
* File name: ir/ana/pto.c
* File name: ir/ana2/pto.c
* Purpose: Pto
* Author: Florian
* Modified by:
......@@ -19,46 +19,38 @@
# include "pto.h"
# include "entity.h"
# include "irnode_t.h"
# include "irprog_t.h"
# include "eset.h"
/* # include "eset.h" */
# include "irgraph.h"
# include "irgwalk.h"
# include "irgmod.h"
# include "irvrfy.h"
# include "trvrfy.h"
# include "xmalloc.h"
# include "irmemwalk.h"
# ifndef TRUE
# define TRUE 1
# define FALSE 0
# endif /* not defined TRUE */
typedef struct walk_mem_env_str {
ir_graph *graph; /* the graph we're visiting */
int visited; /* 'visited' marker */
irg_walk_func *pre; /* pre action */
irg_walk_func *post; /* post action */
void *env; /* user-defined environment */
struct walk_mem_env_str *prev; /* link up walking instances */
/* what else? */
} walk_mem_env_t;
/* Link up walking instances */
static walk_mem_env_t *walk_envs = NULL;
/* MEMORY WALK */
/* BEGIN TEST */
static void print_node_pre (ir_node *node, void *__unused)
/*
static void pto_node_pre (ir_node *node, void *__unused)
{
fprintf (stdout, "PRE MEM Node (0x%08x) (%s)\n",
(int) node,
get_op_name (get_irn_op (node)));
}
}
*/
static void print_node_post (ir_node *node, void *__unused)
static void pto_node_post (ir_node *node, void *__unused)
{
const opcode op = get_irn_opcode (node);
......@@ -89,204 +81,21 @@ static void print_node_post (ir_node *node, void *__unused)