Commit e36a82c5 authored by Matthias Braun's avatar Matthias Braun
Browse files

cleanup ircons code; add current_ir_graph independent construction bits;...

cleanup ircons code; add current_ir_graph independent construction bits; new_ir_graph does not set current_ir_graph anymore

[r28042]
parent 842280b6
......@@ -1148,17 +1148,15 @@ FIRM_API ir_node *new_rd_Block(dbg_info *db, ir_graph *irg, int arity, ir_node *
*
* @param *db A pointer for debug information.
* @param *irg The IR graph the node belongs to.
* @param *block The IR block the node belongs to.
*/
FIRM_API ir_node *new_rd_Start(dbg_info *db, ir_node *block);
FIRM_API ir_node *new_rd_Start(dbg_info *db, ir_graph *irg);
/** Constructor for a End node.
*
* @param *db A pointer for debug information.
* @param *irg The IR graph the node belongs to.
* @param *block The IR block the node belongs to.
*/
FIRM_API ir_node *new_rd_End(dbg_info *db, ir_node *block);
FIRM_API ir_node *new_rd_End(dbg_info *db, ir_graph *irg);
/** Constructor for a Jmp node.
*
......@@ -1975,17 +1973,11 @@ FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block,
*/
FIRM_API ir_node *new_r_Block(ir_graph *irg, int arity, ir_node *in[]);
/** Constructor for a Start node.
*
* @param *block The IR block the node belongs to.
*/
FIRM_API ir_node *new_r_Start(ir_node *block);
/** Constructor for a Start node. */
FIRM_API ir_node *new_r_Start(ir_graph *irg);
/** Constructor for a End node.
*
* @param *block The IR block the node belongs to.
*/
FIRM_API ir_node *new_r_End(ir_node *block);
/** Constructor for a End node. */
FIRM_API ir_node *new_r_End(ir_graph *irg);
/** Constructor for a Jmp node.
*
......@@ -2682,9 +2674,11 @@ FIRM_API ir_node *new_r_ASM(ir_node *block,
* @param target The new current block.
*/
FIRM_API void set_cur_block(ir_node *target);
FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
/** Returns the current block of the current graph. */
FIRM_API ir_node *get_cur_block(void);
FIRM_API ir_node *get_r_cur_block(ir_graph *irg);
/** Constructor for a Block node.
*
......@@ -4215,6 +4209,8 @@ FIRM_API ir_node *new_Dummy(ir_mode *mode);
*/
FIRM_API ir_node *new_d_immBlock(dbg_info *db);
FIRM_API ir_node *new_immBlock(void);
FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
/** Add a control flow edge to an immature block. */
FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
......@@ -4232,8 +4228,8 @@ FIRM_API void mature_immBlock(ir_node *block);
* @param pos The position/id of the local variable.
* @param *mode The mode of the value to get.
*/
FIRM_API ir_node *get_d_value(dbg_info *db, int pos, ir_mode *mode);
FIRM_API ir_node *get_value(int pos, ir_mode *mode);
FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
/**
* Try to guess the mode of a local variable.
......@@ -4256,6 +4252,7 @@ FIRM_API ir_mode *ir_guess_mode(int pos);
* @param *value The new value written to the local variable.
*/
FIRM_API void set_value(int pos, ir_node *value);
FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
/**
* Find the value number for a node in the current block.
......@@ -4274,6 +4271,7 @@ FIRM_API int find_value(ir_node *value);
* state value.
*/
FIRM_API ir_node *get_store(void);
FIRM_API ir_node *get_r_store(ir_graph *irg);
/** Remark a new definition of the memory state.
*
......@@ -4283,6 +4281,7 @@ FIRM_API ir_node *get_store(void);
* @param *store The new memory state.
*/
FIRM_API void set_store(ir_node *store);
FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
/** keep this node alive even if End is not control-reachable from it
*
......@@ -4290,10 +4289,6 @@ FIRM_API void set_store(ir_node *store);
*/
FIRM_API void keep_alive(ir_node *ka);
/** Returns the frame type of the current graph */
FIRM_API ir_type *get_cur_frame_type(void);
/* --- initialize and finalize IR construction --- */
/** Puts the graph into state "phase_high" */
......
......@@ -135,9 +135,8 @@ FIRM_API void set_current_ir_graph(ir_graph *graph);
* represent a procedure in FIRM.
*
* It allocates an ir_graph and sets the field irg of the entity ent
* as well as current_ir_graph to point to this graph.
* Further it allocates the following nodes needed for every
* procedure:
* to point to this graph. Further it allocates the following nodes needed
* for every procedure:
*
* - The start block containing a start node and Proj nodes for it's
* seven results (X, M, P, P, P, T, P).
......@@ -243,11 +242,6 @@ FIRM_API ir_node *get_irg_args(const ir_graph *irg);
/** Sets the node that represents the argument pointer of the given IR graph. */
FIRM_API void set_irg_args(ir_graph *irg, ir_node *node);
/** Returns the current block of an IR graph. */
FIRM_API ir_node *get_irg_current_block(const ir_graph *irg);
/** Sets the current block of an IR graph. */
FIRM_API void set_irg_current_block(ir_graph *irg, ir_node *node);
/** Returns the Bad node of the given IR graph. Use new_Bad() instead!! */
FIRM_API ir_node *get_irg_bad(const ir_graph *irg);
FIRM_API void set_irg_bad(ir_graph *irg, ir_node *node);
......
......@@ -701,7 +701,6 @@ static ir_node *get_end_of_block_insertion_point(ir_node* block)
static void create_memperms(be_fec_env_t *env)
{
ir_graph *irg = env->irg;
memperm_t *memperm;
for (memperm = set_first(env->memperms); memperm != NULL; memperm = set_next(env->memperms)) {
......@@ -733,7 +732,6 @@ static void create_memperms(be_fec_env_t *env)
be_set_MemPerm_in_entity(mempermnode, i, entry->in);
be_set_MemPerm_out_entity(mempermnode, i, entry->out);
set_irg_current_block(irg, memperm->block);
proj = new_r_Proj(mempermnode, get_irn_mode(arg), i);
set_irn_n(entry->node, entry->pos, proj);
......
......@@ -116,12 +116,14 @@ static ir_node *create_phi(be_ssa_construction_env_t *env, ir_node *block,
int i, n_preds = get_Block_n_cfgpreds(block);
ir_graph *irg = get_Block_irg(block);
ir_node **ins = ALLOCAN(ir_node*, n_preds);
ir_node *dummy;
ir_node *phi;
assert(n_preds > 1);
dummy = new_r_Dummy(irg, env->mode);
for (i = 0; i < n_preds; ++i) {
ins[i] = new_r_Unknown(irg, env->mode);
ins[i] = dummy;
}
phi = be_new_Phi(block, n_preds, ins, env->mode, env->phi_cls);
if (env->new_phis != NULL) {
......
......@@ -161,6 +161,7 @@ static void spill_phi(minibelady_env_t *env, ir_node *phi)
ir_node *block = get_nodes_block(phi);
int arity = get_irn_arity(phi);
ir_node **in = ALLOCAN(ir_node*, arity);
ir_node *dummy = new_r_Dummy(irg, mode_M);
ir_node *spill_to_kill = NULL;
spill_info_t *spill_info;
int i;
......@@ -175,7 +176,7 @@ static void spill_phi(minibelady_env_t *env, ir_node *phi)
/* create a new phi-M with bad preds */
for (i = 0; i < arity; ++i) {
in[i] = new_r_Unknown(irg, mode_M);
in[i] = dummy;
}
DBG((dbg, LEVEL_2, "\tcreate Phi-M for %+F\n", phi));
......
......@@ -22,7 +22,7 @@
* @brief Various irnode constructors. Automatic construction of SSA
* representation.
* @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler
Michael Beck
* Michael Beck, Matthias Braun
* @version $Id$
*/
#include "config.h"
......@@ -44,39 +44,30 @@
#include "irflag_t.h"
#include "error.h"
/* when we need verifying */
#ifdef NDEBUG
# define IRN_VERIFY_IRG(res, irg)
#else
# define IRN_VERIFY_IRG(res, irg) irn_verify_irg(res, irg)
#endif /* NDEBUG */
#include "gen_ir_cons.c.inl"
/**
* Language dependent variable initialization callback.
*/
static uninitialized_local_variable_func_t *default_initialize_local_variable = NULL;
#include "gen_ir_cons.c.inl"
static ir_node *new_bd_Start(dbg_info *db, ir_node *block)
ir_node *new_rd_Start(dbg_info *db, ir_graph *irg)
{
ir_node *res;
ir_graph *irg = get_irn_irg(block);
res = new_ir_node(db, irg, block, op_Start, mode_T, 0, NULL);
ir_node *block = get_irg_start_block(irg);
ir_node *res = new_ir_node(db, irg, block, op_Start, mode_T, 0, NULL);
IRN_VERIFY_IRG(res, irg);
res = optimize_node(res);
irn_verify_irg(res, irg);
return res;
}
static ir_node *new_bd_End(dbg_info *db, ir_node *block)
ir_node *new_rd_End(dbg_info *db, ir_graph *irg)
{
ir_node *res;
ir_graph *irg = get_irn_irg(block);
res = new_ir_node(db, irg, block, op_End, mode_X, -1, NULL);
ir_node *block = get_irg_end_block(irg);
ir_node *res = new_ir_node(db, irg, block, op_End, mode_X, -1, NULL);
IRN_VERIFY_IRG(res, irg);
res = optimize_node(res);
irn_verify_irg(res, irg);
return res;
}
......@@ -84,66 +75,50 @@ static ir_node *new_bd_End(dbg_info *db, ir_node *block)
* Creates a Phi node with all predecessors. Calling this constructor
* is only allowed if the corresponding block is mature.
*/
static ir_node *new_bd_Phi(dbg_info *db, ir_node *block, int arity, ir_node **in, ir_mode *mode)
ir_node *new_rd_Phi(dbg_info *db, ir_node *block, int arity, ir_node **in,
ir_mode *mode)
{
ir_node *res;
ir_graph *irg = get_irn_irg(block);
int i;
int has_unknown = 0;
/* Don't assert that block matured: the use of this constructor is strongly
restricted ... */
if (get_Block_matured(block))
assert(get_irn_arity(block) == arity);
res = new_ir_node(db, irg, block, op_Phi, mode, arity, in);
ir_node *res = new_ir_node(db, irg, block, op_Phi, mode, arity, in);
res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);
for (i = arity - 1; i >= 0; --i)
if (is_Unknown(in[i])) {
has_unknown = 1;
break;
}
if (!has_unknown) res = optimize_node(res);
IRN_VERIFY_IRG(res, irg);
res = optimize_node(res);
irn_verify_irg(res, irg);
/* Memory Phis in endless loops must be kept alive.
As we can't distinguish these easily we keep all of them alive. */
if (is_Phi(res) && mode == mode_M)
add_End_keepalive(get_irg_end(irg), res);
return res;
} /* new_bd_Phi */
}
static ir_node *new_bd_Const_type(dbg_info *db, tarval *con, ir_type *tp)
ir_node *new_rd_Const_type(dbg_info *db, ir_graph *irg, tarval *con,
ir_type *tp)
{
ir_node *res;
ir_graph *irg = current_ir_graph;
res = new_ir_node(db, irg, get_irg_start_block(irg), op_Const, get_tarval_mode(con), 0, NULL);
ir_node *block = get_irg_start_block(irg);
ir_mode *mode = get_tarval_mode(con);
ir_node *res = new_ir_node(db, irg, block, op_Const, mode, 0, NULL);
res->attr.con.tarval = con;
set_Const_type(res, tp); /* Call method because of complex assertion. */
res = optimize_node (res);
assert(get_Const_type(res) == tp);
IRN_VERIFY_IRG(res, irg);
irn_verify_irg(res, irg);
return res;
} /* new_bd_Const_type */
}
static ir_node *new_bd_Const(dbg_info *db, tarval *con)
ir_node *new_rd_Const(dbg_info *db, ir_graph *irg, tarval *con)
{
ir_graph *irg = current_ir_graph;
return new_rd_Const_type(db, irg, con, firm_unknown_type);
} /* new_bd_Const */
}
static ir_node *new_bd_Const_long(dbg_info *db, ir_mode *mode, long value)
ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg, ir_mode *mode,
long value)
{
ir_graph *irg = current_ir_graph;
return new_rd_Const(db, irg, new_tarval_from_long(value, mode));
} /* new_bd_Const_long */
}
static ir_node *new_bd_defaultProj(dbg_info *db, ir_node *arg, long max_proj)
ir_node *new_rd_defaultProj(dbg_info *db, ir_node *arg, long max_proj)
{
ir_node *res;
......@@ -151,40 +126,13 @@ static ir_node *new_bd_defaultProj(dbg_info *db, ir_node *arg, long max_proj)
arg->attr.cond.default_proj = max_proj;
res = new_rd_Proj(db, arg, mode_X, max_proj);
return res;
} /* new_bd_defaultProj */
static ir_node *new_bd_Sel(dbg_info *db, ir_node *block, ir_node *store,
ir_node *objptr, int arity, ir_node **in,
ir_entity *ent)
{
ir_node **r_in;
ir_node *res;
int r_arity;
ir_graph *irg = get_irn_irg(block);
ir_mode *mode = is_Method_type(get_entity_type(ent)) ? mode_P_code : mode_P_data;
assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
r_arity = arity + 2;
NEW_ARR_A(ir_node *, r_in, r_arity); /* uses alloca */
r_in[0] = store;
r_in[1] = objptr;
memcpy(&r_in[2], in, sizeof(ir_node *) * arity);
/*
* Sel's can select functions which should be of mode mode_P_code.
*/
res = new_ir_node(db, irg, block, op_Sel, mode, r_arity, r_in);
res->attr.sel.entity = ent;
res = optimize_node(res);
IRN_VERIFY_IRG(res, irg);
return res;
} /* new_bd_Sel */
}
static ir_node *new_bd_SymConst_type(dbg_info *db, ir_node *block,
ir_mode *mode, symconst_symbol value,
symconst_kind symkind, ir_type *tp)
ir_node *new_rd_SymConst_type(dbg_info *db, ir_graph *irg, ir_mode *mode,
symconst_symbol value, symconst_kind symkind,
ir_type *tp)
{
ir_graph *irg = get_irn_irg(block);
ir_node *block = get_irg_start_block(irg);
ir_node *res = new_ir_node(db, irg, block, op_SymConst, mode, 0, NULL);
res->attr.symc.kind = symkind;
......@@ -192,30 +140,32 @@ static ir_node *new_bd_SymConst_type(dbg_info *db, ir_node *block,
res->attr.symc.tp = tp;
res = optimize_node(res);
IRN_VERIFY_IRG(res, irg);
irn_verify_irg(res, irg);
return res;
} /* new_bd_SymConst_type */
}
static ir_node *new_bd_Sync(dbg_info *db, ir_node *block)
ir_node *new_rd_Sync(dbg_info *db, ir_node *block, int arity, ir_node *in[])
{
ir_node *res;
ir_graph *irg = get_irn_irg(block);
ir_node *res = new_ir_node(db, irg, block, op_Sync, mode_M, -1, NULL);
int i;
for (i = 0; i < arity; ++i)
add_Sync_pred(res, in[i]);
res = new_ir_node(db, irg, block, op_Sync, mode_M, -1, NULL);
/* no need to call optimize node here, Sync are always created with no predecessors */
IRN_VERIFY_IRG(res, irg);
res = optimize_node(res);
irn_verify_irg(res, irg);
return res;
} /* new_bd_Sync */
}
static ir_node *new_bd_ASM(dbg_info *db, ir_node *block, int arity,
ir_node *in[], ir_asm_constraint *inputs, int n_outs,
ir_node *new_rd_ASM(dbg_info *db, ir_node *block, int arity, ir_node *in[],
ir_asm_constraint *inputs, int n_outs,
ir_asm_constraint *outputs, int n_clobber,
ident *clobber[], ident *text)
{
ir_node *res;
ir_graph *irg = get_irn_irg(block);
ir_node *res = new_ir_node(db, irg, block, op_ASM, mode_T, arity, in);
res = new_ir_node(db, irg, block, op_ASM, mode_T, arity, in);
res->attr.assem.pin_state = op_pin_state_pinned;
res->attr.assem.input_constraints
= NEW_ARR_D(ir_asm_constraint, irg->obst, arity);
......@@ -229,179 +179,64 @@ static ir_node *new_bd_ASM(dbg_info *db, ir_node *block, int arity,
memcpy(res->attr.assem.clobbers, clobber, sizeof(clobber[0]) * n_clobber);
res = optimize_node(res);
IRN_VERIFY_IRG(res, irg);
irn_verify_irg(res, irg);
return res;
} /* new_bd_ASM */
/* --------------------------------------------- */
/* private interfaces, for professional use only */
/* --------------------------------------------- */
ir_node *new_rd_Start(dbg_info *db, ir_node *block)
{
return new_bd_Start(db, block);
}
ir_node *new_rd_End(dbg_info *db, ir_node *block)
{
return new_bd_End(db, block);
}
/* Creates a Phi node with all predecessors. Calling this constructor
is only allowed if the corresponding block is mature. */
ir_node *new_rd_Phi(dbg_info *db, ir_node *block, int arity, ir_node **in, ir_mode *mode)
{
ir_node *res;
ir_graph *rem = current_ir_graph;
current_ir_graph = get_Block_irg(block);
res = new_bd_Phi(db, block,arity, in, mode);
current_ir_graph = rem;
return res;
} /* new_rd_Phi */
ir_node *new_rd_Const_type(dbg_info *db, ir_graph *irg, tarval *con, ir_type *tp)
{
ir_node *res;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
res = new_bd_Const_type(db, con, tp);
current_ir_graph = rem;
return res;
} /* new_rd_Const_type */
ir_node *new_rd_Const(dbg_info *db, ir_graph *irg, tarval *con)
{
ir_node *res;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
res = new_bd_Const_type(db, con, firm_unknown_type);
current_ir_graph = rem;
return res;
} /* new_rd_Const */
ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg, ir_mode *mode, long value)
{
return new_rd_Const(db, irg, new_tarval_from_long(value, mode));
} /* new_rd_Const_long */
ir_node *new_rd_defaultProj(dbg_info *db, ir_node *arg, long max_proj)
{
return new_bd_defaultProj(db, arg, max_proj);
} /* new_rd_defaultProj */
ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
ir_node *objptr, ir_entity *ent)
{
ir_node *res;
ir_graph *rem = current_ir_graph;
current_ir_graph = get_Block_irg(block);
res = new_bd_Sel(db, block, store, objptr, 0, NULL, ent);
current_ir_graph = rem;
return res;
} /* new_rd_simpleSel */
ir_node *new_rd_SymConst_type(dbg_info *db, ir_graph *irg, ir_mode *mode,
symconst_symbol value, symconst_kind symkind,
ir_type *tp)
{
ir_node *res;
ir_graph *rem = current_ir_graph;
ir_node *block = get_irg_start_block(irg);
current_ir_graph = irg;
res = new_bd_SymConst_type(db, block, mode, value, symkind, tp);
current_ir_graph = rem;
return res;
} /* new_rd_SymConst_type */
return new_rd_Sel(db, block, store, objptr, 0, NULL, ent);
}
ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
symconst_symbol value, symconst_kind symkind)
{
return new_rd_SymConst_type(db, irg, mode, value, symkind, firm_unknown_type);
} /* new_rd_SymConst */
}
ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_entity *symbol, ir_type *tp)
{
symconst_symbol sym;
sym.entity_p = symbol;
return new_rd_SymConst_type(db, irg, mode, sym, symconst_addr_ent, tp);
} /* new_rd_SymConst_addr_ent */
}
ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_entity *symbol, ir_type *tp)
{
symconst_symbol sym;
sym.entity_p = symbol;
return new_rd_SymConst_type(db, irg, mode, sym, symconst_ofs_ent, tp);
} /* new_rd_SymConst_ofs_ent */
}
ir_node *new_rd_SymConst_type_tag(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_type *symbol, ir_type *tp)
{
symconst_symbol sym;
sym.type_p = symbol;
return new_rd_SymConst_type(db, irg, mode, sym, symconst_type_tag, tp);
} /* new_rd_SymConst_type_tag */
}
ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_type *symbol, ir_type *tp)
{
symconst_symbol sym;
sym.type_p = symbol;
return new_rd_SymConst_type(db, irg, mode, sym, symconst_type_size, tp);
} /* new_rd_SymConst_size */
}
ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg, ir_mode *mode, ir_type *symbol, ir_type *tp)
{
symconst_symbol sym;
sym.type_p = symbol;
return new_rd_SymConst_type(db, irg, mode, sym, symconst_type_align, tp);
} /* new_rd_SymConst_align */
ir_node *new_rd_Sync(dbg_info *db, ir_node *block, int arity, ir_node *in[])
{
ir_node *res;
ir_graph *rem = current_ir_graph;
int i;
current_ir_graph = get_Block_irg(block);
res = new_bd_Sync(db, block);
current_ir_graph = rem;
for (i = 0; i < arity; ++i)
add_Sync_pred(res, in[i]);
return res;
} /* new_rd_Sync */
ir_node *new_rd_ASM(dbg_info *db, ir_node *block,
int arity, ir_node *in[], ir_asm_constraint *inputs,
int n_outs, ir_asm_constraint *outputs,
int n_clobber, ident *clobber[], ident *text)
{
ir_node *res;
ir_graph *rem = current_ir_graph;
current_ir_graph = get_Block_irg(block);
res = new_bd_ASM(db, block, arity, in, inputs, n_outs, outputs, n_clobber, clobber, text);
current_ir_graph = rem;
return res;
} /* new_rd_ASM */
}
ir_node *new_r_Start(ir_node *block)
ir_node *new_r_Start(ir_graph *irg)
{
return new_rd_Start(NULL, block);
return new_rd_Start(NULL, irg);
}
ir_node *new_r_End(ir_node *block)
ir_node *new_r_End(ir_graph *irg)
{
return new_rd_End(NULL, block);
return new_rd_End(NULL, irg);
}
ir_node *new_r_Const(ir_graph *irg, tarval *con)
{
......@@ -466,9 +301,9 @@ ir_node *new_d_Start(dbg_info *db)
op_Start, mode_T, 0, NULL);
res = optimize_node(res);
IRN_VERIFY_IRG(res, current_ir_graph);
irn_verify_irg(res, current_ir_graph);