Commit 1d265ff5 authored by Till Riedel's avatar Till Riedel
Browse files

intoduced kind field to mode node graph

added mode.arithmetic
put modes on obstack
eliminated compiler wearnings
beautified code :-)

[r1387]
parent dc30bc05
......@@ -20,7 +20,7 @@ SOURCES += Makefile.in \
ircons.c irgmod.c irgraph_t.h irnode.c iropt.c irvrfy.c \
irgwalk.c irdump.c irgopt.c irnode_t.h iropt_t.h \
irmode.c irop.c irprog.c irflag.c irgraph.c irmode_t.h \
irop_t.h irprog_t.h iropt_dbg.c ircgcons.c ircgopt.c
irop_t.h irprog_t.h ircgcons.c ircgopt.c
include $(topdir)/MakeRules
......
......@@ -137,8 +137,9 @@ new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval
INLINE ir_node *
new_rd_Id (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
{
ir_node *in[1] = {val};
ir_node *in[1];
ir_node *res;
in[0]=val;
res = new_ir_node (db, irg, block, op_Id, mode, 1, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -149,8 +150,9 @@ INLINE ir_node *
new_rd_Proj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
long proj)
{
ir_node *in[1] = {arg};
ir_node *in[1];
ir_node *res;
in[0]=arg;
res = new_ir_node (db, irg, block, op_Proj, mode, 1, in);
res->attr.proj = proj;
......@@ -180,8 +182,9 @@ new_rd_defaultProj (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *arg,
INLINE ir_node *
new_rd_Conv (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
{
ir_node *in[1] = {op};
ir_node *in[1];
ir_node *res;
in[0]=op;
res = new_ir_node (db, irg, block, op_Conv, mode, 1, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -204,8 +207,10 @@ INLINE ir_node *
new_rd_Add (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_Add, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -216,8 +221,10 @@ INLINE ir_node *
new_rd_Sub (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_Sub, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -228,8 +235,9 @@ INLINE ir_node *
new_rd_Minus (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_mode *mode)
{
ir_node *in[1] = {op};
ir_node *in[1];
ir_node *res;
in[0]=op;
res = new_ir_node (db, irg, block, op_Minus, mode, 1, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -240,8 +248,10 @@ INLINE ir_node *
new_rd_Mul (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_Mul, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -252,8 +262,11 @@ INLINE ir_node *
new_rd_Quot (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *memop, ir_node *op1, ir_node *op2)
{
ir_node *in[3] = {memop, op1, op2};
ir_node *in[3] ;
ir_node *res;
in[0] = memop;
in[1] = op1;
in[2] = op2;
res = new_ir_node (db, irg, block, op_Quot, mode_T, 3, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -264,8 +277,11 @@ INLINE ir_node *
new_rd_DivMod (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *memop, ir_node *op1, ir_node *op2)
{
ir_node *in[3] = {memop, op1, op2};
ir_node *in[3];
ir_node *res;
in[0] = memop;
in[1] = op1;
in[2] = op2;
res = new_ir_node (db, irg, block, op_DivMod, mode_T, 3, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -276,8 +292,11 @@ INLINE ir_node *
new_rd_Div (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *memop, ir_node *op1, ir_node *op2)
{
ir_node *in[3] = {memop, op1, op2};
ir_node *in[3];
ir_node *res;
in[0] = memop;
in[1] = op1;
in[2] = op2;
res = new_ir_node (db, irg, block, op_Div, mode_T, 3, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -288,8 +307,11 @@ INLINE ir_node *
new_rd_Mod (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *memop, ir_node *op1, ir_node *op2)
{
ir_node *in[3] = {memop, op1, op2};
ir_node *in[3];
ir_node *res;
in[0] = memop;
in[1] = op1;
in[2] = op2;
res = new_ir_node (db, irg, block, op_Mod, mode_T, 3, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -300,8 +322,10 @@ INLINE ir_node *
new_rd_And (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_And, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -312,8 +336,10 @@ INLINE ir_node *
new_rd_Or (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_Or, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -324,8 +350,10 @@ INLINE ir_node *
new_rd_Eor (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_Eor, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -336,8 +364,9 @@ INLINE ir_node *
new_rd_Not (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_mode *mode)
{
ir_node *in[1] = {op};
ir_node *in[1];
ir_node *res;
in[0] = op;
res = new_ir_node (db, irg, block, op_Not, mode, 1, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -348,8 +377,10 @@ INLINE ir_node *
new_rd_Shl (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_node *k, ir_mode *mode)
{
ir_node *in[2] = {op, k};
ir_node *in[2];
ir_node *res;
in[0] = op;
in[1] = k;
res = new_ir_node (db, irg, block, op_Shl, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -360,8 +391,10 @@ INLINE ir_node *
new_rd_Shr (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_node *k, ir_mode *mode)
{
ir_node *in[2] = {op, k};
ir_node *in[2];
ir_node *res;
in[0] = op;
in[1] = k;
res = new_ir_node (db, irg, block, op_Shr, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -372,8 +405,10 @@ INLINE ir_node *
new_rd_Shrs (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_node *k, ir_mode *mode)
{
ir_node *in[2] = {op, k};
ir_node *in[2];
ir_node *res;
in[0] = op;
in[1] = k;
res = new_ir_node (db, irg, block, op_Shrs, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -384,8 +419,10 @@ INLINE ir_node *
new_rd_Rot (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_node *k, ir_mode *mode)
{
ir_node *in[2] = {op, k};
ir_node *in[2];
ir_node *res;
in[0] = op;
in[1] = k;
res = new_ir_node (db, irg, block, op_Rot, mode, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -396,8 +433,9 @@ INLINE ir_node *
new_rd_Abs (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, ir_mode *mode)
{
ir_node *in[1] = {op};
ir_node *in[1];
ir_node *res;
in[0] = op;
res = new_ir_node (db, irg, block, op_Abs, mode, 1, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -408,8 +446,10 @@ INLINE ir_node *
new_rd_Cmp (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2)
{
ir_node *in[2] = {op1, op2};
ir_node *in[2];
ir_node *res;
in[0] = op1;
in[1] = op2;
res = new_ir_node (db, irg, block, op_Cmp, mode_T, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -429,8 +469,9 @@ new_rd_Jmp (dbg_info* db, ir_graph *irg, ir_node *block)
INLINE ir_node *
new_rd_Cond (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *c)
{
ir_node *in[1] = {c};
ir_node *in[1];
ir_node *res;
in[0] = c;
res = new_ir_node (db, irg, block, op_Cond, mode_T, 1, in);
res->attr.c.kind = dense;
res->attr.c.default_proj = 0;
......@@ -484,8 +525,10 @@ new_rd_Return (dbg_info* db, ir_graph *irg, ir_node *block,
INLINE ir_node *
new_rd_Raise (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store, ir_node *obj)
{
ir_node *in[2] = {store, obj};
ir_node *in[2];
ir_node *res;
in[0] = store;
in[1] = obj;
res = new_ir_node (db, irg, block, op_Raise, mode_T, 2, in);
res = optimize_node (res);
irn_vrfy_irg (res, irg);
......@@ -496,8 +539,10 @@ INLINE ir_node *
new_rd_Load (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *store, ir_node *adr)
{
ir_node *in[2] = {store, adr};
ir_node *in[2];
ir_node *res;
in[0] = store;
in[1] = adr;
res = new_ir_node (db, irg, block, op_Load, mode_T, 2, in);
res = optimize_node (res);
......@@ -509,8 +554,11 @@ INLINE ir_node *
new_rd_Store (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *store, ir_node *adr, ir_node *val)
{
ir_node *in[3] = {store, adr, val};
ir_node *in[3];
ir_node *res;
in[0] = store;
in[1] = adr;
in[2] = val;
res = new_ir_node (db, irg, block, op_Store, mode_T, 3, in);
res = optimize_node (res);
......@@ -523,8 +571,10 @@ INLINE ir_node *
new_rd_Alloc (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
ir_node *size, type *alloc_type, where_alloc where)
{
ir_node *in[2] = {store, size};
ir_node *in[2];
ir_node *res;
in[0] = store;
in[1] = size;
res = new_ir_node (db, irg, block, op_Alloc, mode_T, 2, in);
res->attr.a.where = where;
......@@ -539,8 +589,11 @@ INLINE ir_node *
new_rd_Free (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *store,
ir_node *ptr, ir_node *size, type *free_type)
{
ir_node *in[3] = {store, ptr, size};
ir_node *in[3];
ir_node *res;
in[0] = store;
in[1] = ptr;
in[2] = size;
res = new_ir_node (db, irg, block, op_Free, mode_T, 3, in);
res->attr.f = free_type;
......@@ -647,8 +700,9 @@ new_rd_Unknown (ir_graph *irg)
INLINE ir_node *
new_rd_CallBegin (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *call)
{
ir_node *in[1] = { get_Call_ptr(call) };
ir_node *in[1];
ir_node *res;
in[0] = get_Call_ptr(call);
res = new_ir_node (db, irg, block, op_CallBegin, mode_T, 1, in);
res->attr.callbegin.irg = irg;
res->attr.callbegin.call = call;
......@@ -695,8 +749,9 @@ INLINE ir_node *
new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
long proj)
{
ir_node *in[1] = {arg};
ir_node *in[1];
ir_node *res;
in[0] = arg;
res = new_ir_node (db, irg, block, op_Filter, mode, 1, in);
res->attr.filter.proj = proj;
res->attr.filter.in_cg = NULL;
......
......@@ -210,7 +210,7 @@ copy_preds (ir_node *n, void *env) {
for (i = 0; i < get_irn_arity(n); i++)
if (get_irn_opcode(get_irn_n(n, i)) != iro_Bad) {
set_irn_n (nn, j, get_new_node(get_irn_n(n, i)));
//if (is_backedge(n, i)) set_backedge(nn, j);
/*if (is_backedge(n, i)) set_backedge(nn, j);*/
j++;
}
/* repair the block visited flag from above misuse. Repair it in both
......@@ -234,7 +234,7 @@ copy_preds (ir_node *n, void *env) {
for (i = 0; i < get_irn_arity(n); i++)
if (get_irn_opcode(get_irn_n(block, i)) != iro_Bad) {
set_irn_n (nn, j, get_new_node(get_irn_n(n, i)));
//if (is_backedge(n, i)) set_backedge(nn, j);
/*if (is_backedge(n, i)) set_backedge(nn, j);*/
j++;
}
/* If the pre walker reached this Phi after the post walker visited the
......
......@@ -68,6 +68,8 @@ new_ir_graph (entity *ent, int n_loc)
ir_node *projX;
res = (ir_graph *) malloc (sizeof (ir_graph));
res->kind=k_ir_graph;
current_ir_graph = res;
add_irp_irg(res); /* remember this graph global. */
......@@ -522,9 +524,11 @@ inc_irg_visited (ir_graph *irg)
unsigned long
get_max_irg_visited(void)
{
//int i;
//for(i = 0; i < get_irp_n_irgs(); i++)
// assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
/*
int i;
for(i = 0; i < get_irp_n_irgs(); i++)
assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
*/
return max_irg_visited;
}
......@@ -535,9 +539,11 @@ void set_max_irg_visited(int val) {
unsigned long
inc_max_irg_visited(void)
{
//int i;
// for(i = 0; i < get_irp_n_irgs(); i++)
//assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
/*
int i;
for(i = 0; i < get_irp_n_irgs(); i++)
assert(max_irg_visited >= get_irg_visited(get_irp_irg(i)));
*/
max_irg_visited++;
return max_irg_visited;
}
......
......@@ -23,6 +23,7 @@
/** ir_graph holds all information for a procedure */
struct ir_graph {
firm_kind kind; /**< always set to k_ir_graph*/
/* -- Basics of the representation -- */
struct entity *ent; /**< The entity of this procedure, i.e.,
the type of the procedure and the
......
......@@ -16,7 +16,7 @@
# include <stdlib.h>
# include "irnode.h"
# include "irnode_t.h"
# include "irgraph.h" /* visited flag */
# include "irprog.h"
# include "irgwalk.h"
......@@ -32,7 +32,7 @@ static void irg_walk_cg(ir_node * node, int visited, eset * irg_set,
ir_graph * rem = current_ir_graph;
ir_node * pred;
assert(node);
assert(node && node->kind==k_ir_node);
if (get_irn_visited(node) >= visited) return;
set_irn_visited(node, visited);
......@@ -109,7 +109,7 @@ static void
irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
{
int i;
assert(node);
assert(node && node->kind==k_ir_node);
if (get_irn_visited(node) < get_irg_visited(current_ir_graph)) {
set_irn_visited(node, get_irg_visited(current_ir_graph));
......@@ -129,7 +129,7 @@ irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
assert(node);
assert(node && node->kind==k_ir_node);
if (interprocedural_view) {
eset * irg_set = eset_create();
int visited;
......@@ -337,8 +337,8 @@ void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
/********************************************************************/
typedef struct walk_env {
void *pre;
void *post;
irg_walk_func *pre;
irg_walk_func *post;
void *env;
} walk_env;
......
......@@ -17,7 +17,8 @@
# include <stddef.h>
# include <string.h>
# include "tv.h"
# include "array.h"
# include "obst.h"
# include "misc.h"
#if 0
static long long count = 0;
......@@ -32,12 +33,7 @@ static long long count = 0;
/** dynamic array to hold all modes */
static ir_mode * modes;
/* dynamic arrays to hold special modes' values */
static tarval** modes_min;
static tarval** modes_max;
static tarval** modes_null;
static tarval** modes_one;
static struct obstack modes;
/** number of defined modes */
static int num_modes;
......@@ -49,31 +45,39 @@ static int num_modes;
/**
* Compare modes that don't need to have their code field
* correctly set
*/
static int modes_are_equal(const ir_mode *m, const ir_mode *n)
*
* TODO: Add other fields
**/
inline static int modes_are_equal(const ir_mode *m, const ir_mode *n)
{
if (m == n) return 1;
if ( (m->sort == n->sort) && (m->size == n->size) &&
(m->align == n->align) && (m->sign == n->sign) &&
(m->name == n->name)
)
return 1;
if(!bcmp( m + offsetof(ir_mode,sort) , n + offsetof(ir_mode,sort), offsetof(ir_mode,min)-offsetof(ir_mode,min))) return 1;
return 0;
}
/**
* searches the modes array for the given mode and returns
* searches the modes obstack for the given mode and returns
* a pointer on an equal mode already in the array, NULL if
* none found
*/
static ir_mode *find_mode(ir_mode *m)
static ir_mode *find_mode(const ir_mode *m)
{
int i;
ir_mode *n;
struct _obstack_chunk *p;
p=modes.chunk;
for( n=(ir_mode*) p->contents; (char *)n < modes.next_free; n+=sizeof(ir_mode) )
{
if(modes_are_equal(n,m)) return n;
}
for (i = 0; i < num_modes; i++)
for (p = p->prev; p; p = p->prev)
{
if (modes_are_equal(m, &modes[i])) return &modes[i];
for( n=(ir_mode*) p->contents; (char *)n < p->limit; n+=sizeof(ir_mode) )
{
if(modes_are_equal(n,m)) return n;
}
}
return NULL;
......@@ -84,10 +88,10 @@ static ir_mode *find_mode(ir_mode *m)
*/
static void set_mode_values(ir_mode* mode)
{
modes_min[get_mode_modecode(mode)] = get_tarval_min(mode);
modes_max[get_mode_modecode(mode)] = get_tarval_max(mode);
modes_null[get_mode_modecode(mode)] = get_tarval_null(mode);
modes_one[get_mode_modecode(mode)] = get_tarval_one(mode);
mode->min = get_tarval_min(mode);
mode->max= get_tarval_max(mode);
mode->null= get_tarval_null(mode);
mode->one= get_tarval_one(mode);
}
/* * *
* globals defined in irmode.h
......@@ -153,21 +157,41 @@ INLINE ir_mode *get_modeBAD(void) { ANNOUNCE(); return mode_BAD; }
* Registers a new mode if not defined yet, else returns
* the "equivalent" one.
*/
static ir_mode *register_mode(ir_mode* new_mode)
static ir_mode *register_mode(const ir_mode* new_mode)
{
ir_mode *mode;
ir_mode *mode = NULL;
ANNOUNCE();
assert(new_mode);
/* first check if there already is a matching mode */
mode = find_mode(new_mode);
if (mode) return mode;
/* copy mode struct to modes array */
mode=(ir_mode*) obstack_copy(&modes, new_mode, sizeof(ir_mode));
mode->kind = k_ir_mode;
if(num_modes>=irm_max) mode->code = num_modes;
num_modes++;
if(mode->sort==irms_int_number || mode->sort==irms_float_number || mode->sort==irms_character) set_mode_values(mode);
return mode;
}
/*
* Creates a new mode.
*/
ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int align, int sign, mode_arithmetic arithmetic )
{
ir_mode mode_tmpl;
ir_mode *mode;
/* sanity checks */
switch (new_mode->sort)
switch (sort)
{
case irms_auxiliary:
case irms_control_flow:
case irms_memory:
case irms_internal_boolean:
assert(0 && "internal modes cannot be user defined");
return NULL;
......@@ -182,44 +206,25 @@ static ir_mode *register_mode(ir_mode* new_mode)
case irms_reference:
case irms_character:
break;
default:
assert(0 && "wrong mode sort");
return NULL;
}
mode_tmpl.name = new_id_from_str(name);
mode_tmpl.sort = sort;
mode_tmpl.size = bit_size;
mode_tmpl.align = align;
mode_tmpl.sign = sign ? 1 : 0;
mode_tmpl.arithmetic = arithmetic;
mode_tmpl.tv_priv = NULL;
/* copy mode struct to modes array */
ARR_EXTEND(ir_mode, modes, 1);
ARR_EXTEND(tarval*, modes_min, 1);
ARR_EXTEND(tarval*, modes_max, 1);
ARR_EXTEND(tarval*, modes_null, 1);
ARR_EXTEND(tarval*, modes_one, 1);