Commit 20f95aba authored by Matthias Braun's avatar Matthias Braun
Browse files

rename copy_const_value to duplicate_subgraph, remove is_irn_const_expression

also move copy_const_value from typerep/entity to irgmod.
parent 60e3e721
......@@ -75,6 +75,18 @@ FIRM_API ir_node *part_block_edges(ir_node *node);
*/
FIRM_API void kill_node(ir_node *node);
/**
* Creates a copy of the subgraph starting at node @p n.
* This currently only works for subgraphs containing only arithmetic nodes
* (= enough for everything that can be found on the const code irg).
*
* @param dbg debug info for all newly created nodes
* @param n the node
* @param to_block block to copy to
*/
FIRM_API ir_node *duplicate_subgraph(dbg_info *dbg, ir_node *n,
ir_node *to_block);
#include "end.h"
#endif
......@@ -457,25 +457,6 @@ FIRM_API size_t get_entity_parameter_number(const ir_entity *entity);
*/
FIRM_API void set_entity_parameter_number(ir_entity *entity, size_t n);
/**
* Returns true if the the node is representable as code on
* const_code_irg.
*
* @deprecated This function is not used by libFirm and stays here
* only as a helper for the old Jack frontend.
*/
FIRM_API int is_irn_const_expression(ir_node *n);
/**
* Copies a Firm subgraph that complies to the restrictions for
* constant expressions to block.
*
* @param dbg debug info for all newly created nodes
* @param n the node
* @param to_block block to copy to
*/
FIRM_API ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *to_block);
/** Returns initial value of entity with atomic type @p ent. */
FIRM_API ir_node *get_atomic_ent_value(const ir_entity *ent);
/** Sets initial value of entity with atomic type @p ent to node @p val.
......
......@@ -255,3 +255,62 @@ void kill_node(ir_node *node)
/* noone is allowed to reference this node anymore */
set_irn_op(node, op_Deleted);
}
ir_node *duplicate_subgraph(dbg_info *dbg, ir_node *n, ir_node *block)
{
ir_graph *irg = get_irn_irg(block);
ir_mode *mode = get_irn_mode(n);
switch (get_irn_opcode(n)) {
case iro_Const:
return new_rd_Const(dbg, irg, get_Const_tarval(n));
case iro_SymConst:
return new_rd_SymConst(dbg, irg, mode,
get_SymConst_symbol(n), get_SymConst_kind(n));
case iro_Add:
return new_rd_Add(dbg, block,
duplicate_subgraph(dbg, get_Add_left(n), block),
duplicate_subgraph(dbg, get_Add_right(n), block),
mode);
case iro_Sub:
return new_rd_Sub(dbg, block,
duplicate_subgraph(dbg, get_Sub_left(n), block),
duplicate_subgraph(dbg, get_Sub_right(n), block),
mode);
case iro_Mul:
return new_rd_Mul(dbg, block,
duplicate_subgraph(dbg, get_Mul_left(n), block),
duplicate_subgraph(dbg, get_Mul_right(n), block),
mode);
case iro_And:
return new_rd_And(dbg, block,
duplicate_subgraph(dbg, get_And_left(n), block),
duplicate_subgraph(dbg, get_And_right(n), block),
mode);
case iro_Or:
return new_rd_Or(dbg, block,
duplicate_subgraph(dbg, get_Or_left(n), block),
duplicate_subgraph(dbg, get_Or_right(n), block),
mode);
case iro_Eor:
return new_rd_Eor(dbg, block,
duplicate_subgraph(dbg, get_Eor_left(n), block),
duplicate_subgraph(dbg, get_Eor_right(n), block),
mode);
case iro_Conv:
return new_rd_Conv(dbg, block,
duplicate_subgraph(dbg, get_Conv_op(n), block),
mode);
case iro_Minus:
return new_rd_Minus(dbg, block,
duplicate_subgraph(dbg, get_Minus_op(n), block),
mode);
case iro_Not:
return new_rd_Not(dbg, block,
duplicate_subgraph(dbg, get_Not_op(n), block), mode);
case iro_Unknown:
return new_r_Unknown(irg, mode);
default:
break;
}
panic("opcode invalid or not implemented %+F", n);
}
......@@ -94,12 +94,12 @@ static void lower_sel(ir_node *sel)
ub = get_array_upper_bound(arr_ty, dim);
if (! is_Unknown(lb))
lb = new_rd_Conv(dbg, bl, copy_const_value(get_irn_dbg_info(sel), lb, bl), mode_Int);
lb = new_rd_Conv(dbg, bl, duplicate_subgraph(get_irn_dbg_info(sel), lb, bl), mode_Int);
else
lb = NULL;
if (! is_Unknown(ub))
ub = new_rd_Conv(dbg, bl, copy_const_value(get_irn_dbg_info(sel), ub, bl), mode_Int);
ub = new_rd_Conv(dbg, bl, duplicate_subgraph(get_irn_dbg_info(sel), ub, bl), mode_Int);
else
ub = NULL;
......
......@@ -917,7 +917,7 @@ ir_node *can_replace_load_by_const(const ir_node *load, ir_node *c)
ir_mode *l_mode = get_Load_mode(load);
ir_node *block = get_nodes_block(load);
dbg_info *dbgi = get_irn_dbg_info(load);
ir_node *res = copy_const_value(dbgi, c, block);
ir_node *res = duplicate_subgraph(dbgi, c, block);
if (c_mode != l_mode) {
/* check, if the mode matches OR can be easily converted info */
......
......@@ -472,92 +472,6 @@ void set_atomic_ent_value(ir_entity *entity, ir_node *val)
entity->initializer = initializer;
}
int is_irn_const_expression(ir_node *n)
{
/* we are in danger iff an exception will arise. TODO: be more precisely,
* for instance Div. will NOT rise if divisor != 0 */
if (is_binop(n) && !is_fragile_op(n))
return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
switch (get_irn_opcode(n)) {
case iro_Const:
case iro_SymConst:
case iro_Unknown:
return 1;
case iro_Conv:
return is_irn_const_expression(get_irn_n(n, 0));
default:
break;
}
return 0;
}
ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
{
ir_graph *irg = get_irn_irg(block);
/* @@@ GL I think we should implement this using the routines from irgopt
* for dead node elimination/inlineing. */
ir_mode *m = get_irn_mode(n);
ir_node *nn;
switch (get_irn_opcode(n)) {
case iro_Const:
nn = new_rd_Const(dbg, irg, get_Const_tarval(n));
break;
case iro_SymConst:
nn = new_rd_SymConst(dbg, irg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n));
break;
case iro_Add:
nn = new_rd_Add(dbg, block,
copy_const_value(dbg, get_Add_left(n), block),
copy_const_value(dbg, get_Add_right(n), block), m);
break;
case iro_Sub:
nn = new_rd_Sub(dbg, block,
copy_const_value(dbg, get_Sub_left(n), block),
copy_const_value(dbg, get_Sub_right(n), block), m);
break;
case iro_Mul:
nn = new_rd_Mul(dbg, block,
copy_const_value(dbg, get_Mul_left(n), block),
copy_const_value(dbg, get_Mul_right(n), block), m);
break;
case iro_And:
nn = new_rd_And(dbg, block,
copy_const_value(dbg, get_And_left(n), block),
copy_const_value(dbg, get_And_right(n), block), m);
break;
case iro_Or:
nn = new_rd_Or(dbg, block,
copy_const_value(dbg, get_Or_left(n), block),
copy_const_value(dbg, get_Or_right(n), block), m);
break;
case iro_Eor:
nn = new_rd_Eor(dbg, block,
copy_const_value(dbg, get_Eor_left(n), block),
copy_const_value(dbg, get_Eor_right(n), block), m);
break;
case iro_Conv:
nn = new_rd_Conv(dbg, block,
copy_const_value(dbg, get_Conv_op(n), block), m);
break;
case iro_Minus:
nn = new_rd_Minus(dbg, block,
copy_const_value(dbg, get_Minus_op(n), block), m);
break;
case iro_Not:
nn = new_rd_Not(dbg, block,
copy_const_value(dbg, get_Not_op(n), block), m);
break;
case iro_Unknown:
nn = new_r_Unknown(irg, m);
break;
default:
panic("opcode invalid or not implemented %+F", n);
}
return nn;
}
const char *get_initializer_kind_name(ir_initializer_kind_t ini)
{
#define X(a) case a: return #a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment