Commit bd265fc0 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Split TypeConst into Align and Size.

parent b45cfcbd
......@@ -263,16 +263,6 @@ typedef enum mtp_additional_properties {
} mtp_additional_properties;
ENUM_BITSET(mtp_additional_properties)
/**
* @ingroup TypeConst
* This enum names the different kinds of symbolic Constants represented by
* TypeConst.
*/
typedef enum typeconst_kind {
typeconst_size, /**< The TypeConst is the size of the given type. */
typeconst_align, /**< The TypeConst is the alignment of the given type. */
} typeconst_kind;
/** A input/output constraint attribute.
* @ingroup ASM
*/
......
......@@ -340,14 +340,15 @@ static void free_ana_walker(ir_node *node, void *env)
switch (get_irn_opcode(node)) {
/* special nodes */
case iro_Address:
case iro_Align:
case iro_Sel:
case iro_Const:
case iro_Offset:
case iro_Phi:
case iro_Id:
case iro_Proj:
case iro_Size:
case iro_Tuple:
case iro_TypeConst:
/* nothing */
break;
case iro_Call:
......
......@@ -259,9 +259,10 @@ static void handle_if(ir_node *block, ir_node *cmp, ir_relation rel, env_t *env)
/* try to place the constant on the right side for a Confirm */
switch (get_irn_opcode(left)) {
case iro_Address:
case iro_Align:
case iro_Const:
case iro_Offset:
case iro_TypeConst: {
case iro_Size: {
ir_node *t = left;
left = right;
right = t;
......
......@@ -650,19 +650,13 @@ static void emit_init_expression(be_gas_decl_env_t *env, ir_node *init)
be_emit_irprintf("%d", get_entity_offset(get_Offset_entity(init)));
return;
case iro_TypeConst: {
ir_type *const type = get_TypeConst_type(init);
switch (get_TypeConst_kind(init)) {
case typeconst_size:
be_emit_irprintf("%u", get_type_size_bytes(type));
return;
case iro_Align:
be_emit_irprintf("%u", get_type_alignment_bytes(get_Align_type(init)));
return;
case typeconst_align:
be_emit_irprintf("%u", get_type_alignment_bytes(type));
return;
}
panic("invalid TypeConst kind");
}
case iro_Size:
be_emit_irprintf("%u", get_type_size_bytes(get_Size_type(init)));
return;
case iro_Add:
if (!mode_is_int(mode) && !mode_is_reference(mode)) {
......
......@@ -694,18 +694,13 @@ void dump_node_opcode(FILE *F, const ir_node *n)
fprintf(F, "Offset %s", get_entity_name(get_Offset_entity(n)));
break;
case iro_TypeConst: {
ir_type *const type = get_TypeConst_type(n);
switch (get_TypeConst_kind(n)) {
case typeconst_size:
ir_fprintf(F, "TypeC %+F size", type);
break;
case typeconst_align:
ir_fprintf(F, "TypeC %+F align", type);
break;
}
case iro_Align:
ir_fprintf(F, "Align %+F", get_Align_type(n));
break;
case iro_Size:
ir_fprintf(F, "Size %+F", get_Size_type(n));
break;
}
case iro_Load:
if (get_Load_unaligned(n) == align_non_aligned)
......@@ -763,6 +758,7 @@ static void dump_node_mode(FILE *F, const ir_node *n)
iro = get_irn_opcode(n);
switch (iro) {
case iro_Address:
case iro_Align:
case iro_Sel:
case iro_End:
case iro_Return:
......@@ -771,7 +767,7 @@ static void dump_node_mode(FILE *F, const ir_node *n)
case iro_Jmp:
case iro_NoMem:
case iro_Offset:
case iro_TypeConst:
case iro_Size:
break;
default:
mode = get_irn_mode(n);
......@@ -941,9 +937,10 @@ static void dump_node_vcgattr(FILE *F, const ir_node *node, const ir_node *local
print_vcg_color(F, ird_color_memory);
break;
case iro_Address:
case iro_Align:
case iro_Const:
case iro_Offset:
case iro_TypeConst:
case iro_Size:
print_vcg_color(F, ird_color_const);
break;
case iro_Proj:
......@@ -1509,18 +1506,19 @@ static void dump_node2type_edges(ir_node *n, void *env)
assert(n);
switch (get_irn_opcode(n)) {
case iro_Const :
/* @@@ some consts have an entity */
break;
case iro_TypeConst:
print_node_type_edge(F, n, get_TypeConst_type(n), NODE2TYPE_EDGE_ATTR);
{
ir_type *type;
case iro_Align: type = get_Align_type(n); goto type;
case iro_Call: type = get_Call_type(n); goto type;
case iro_Size: type = get_Size_type(n); goto type;
type:
print_node_type_edge(F, n, type, NODE2TYPE_EDGE_ATTR);
break;
}
case iro_Sel:
print_node_ent_edge(F,n,get_Sel_entity(n),NODE2TYPE_EDGE_ATTR);
break;
case iro_Call:
print_node_type_edge(F,n,get_Call_type(n),NODE2TYPE_EDGE_ATTR);
break;
default:
break;
}
......
......@@ -283,22 +283,15 @@ void dump_irnode_to_file(FILE *const F, const ir_node *const n)
dump_entity_to_file(F, get_Offset_entity(n));
break;
case iro_TypeConst: {
ir_type *const type = get_TypeConst_type(n);
switch (get_TypeConst_kind(n)) {
case typeconst_size:
fprintf(F, " kind: size\n");
fprintf(F, " type: ");
dump_type_to_file(F, type);
break;
case typeconst_align:
fprintf(F, " kind: alignment\n");
fprintf(F, " type: ");
dump_type_to_file(F, type);
break;
}
case iro_Align:
fprintf(F, " type: ");
dump_type_to_file(F, get_Align_type(n));
break;
case iro_Size:
fprintf(F, " type: ");
dump_type_to_file(F, get_Size_type(n));
break;
}
case iro_Load:
fprintf(F, " mode of loaded value: %s\n", get_mode_name(get_Load_mode(n)));
......
......@@ -263,12 +263,14 @@ ir_node *duplicate_subgraph(dbg_info *dbg, ir_node *n, ir_node *block)
switch (get_irn_opcode(n)) {
case iro_Address:
return new_rd_Address(dbg, irg, get_Address_entity(n));
case iro_Align:
return new_rd_Align(dbg, irg, mode, get_Align_type(n));
case iro_Const:
return new_rd_Const(dbg, irg, get_Const_tarval(n));
case iro_Offset:
return new_rd_Offset(dbg, irg, mode, get_Offset_entity(n));
case iro_TypeConst:
return new_rd_TypeConst(dbg, irg, mode, get_TypeConst_type(n), get_TypeConst_kind(n));
case iro_Size:
return new_rd_Size(dbg, irg, mode, get_Size_type(n));
case iro_Add:
return new_rd_Add(dbg, block,
duplicate_subgraph(dbg, get_Add_left(n), block),
......
......@@ -1010,10 +1010,11 @@ static void register_get_entity_func(ir_op *op, get_entity_attr_func func)
void ir_register_getter_ops(void)
{
register_get_type_func(op_Align, get_Align_type);
register_get_type_func(op_Builtin, get_Builtin_type);
register_get_type_func(op_Call, get_Call_type);
register_get_type_func(op_CopyB, get_CopyB_type);
register_get_type_func(op_TypeConst, get_TypeConst_type);
register_get_type_func(op_Size, get_Size_type);
register_get_entity_func(op_Address, get_Address_entity);
register_get_entity_func(op_Offset, get_Offset_entity);
......
......@@ -229,9 +229,9 @@ static unsigned hash_entconst(const ir_node *node)
}
/**
* Calculate a hash value of a TypeConst node.
* Calculate a hash value of an Align/Size node.
*/
static unsigned hash_TypeConst(const ir_node *node)
static unsigned hash_typeconst(const ir_node *node)
{
unsigned hash = hash_ptr(node->attr.typec.type);
return hash;
......@@ -273,12 +273,12 @@ static int node_cmp_attr_entconst(const ir_node *a, const ir_node *b)
return pa->entity != pb->entity;
}
/** Compares the attributes of two TypeConst nodes. */
static int node_cmp_attr_TypeConst(const ir_node *a, const ir_node *b)
/** Compares the attributes of two Align/Size nodes. */
static int node_cmp_attr_typeconst(const ir_node *a, const ir_node *b)
{
const typeconst_attr *pa = &a->attr.typec;
const typeconst_attr *pb = &b->attr.typec;
return (pa->kind != pb->kind) || (pa->type != pb->type);
return pa->type != pb->type;
}
/** Compares the attributes of two Call nodes. */
......@@ -599,30 +599,32 @@ void firm_init_op(void)
ir_init_opcodes();
be_init_op();
set_op_cmp_attr(op_Address, node_cmp_attr_entconst);
set_op_cmp_attr(op_ASM, node_cmp_attr_ASM);
set_op_cmp_attr(op_Alloc, node_cmp_attr_Alloc);
set_op_cmp_attr(op_Builtin, node_cmp_attr_Builtin);
set_op_cmp_attr(op_Call, node_cmp_attr_Call);
set_op_cmp_attr(op_Cmp, node_cmp_attr_Cmp);
set_op_cmp_attr(op_Confirm, node_cmp_attr_Confirm);
set_op_cmp_attr(op_Const, node_cmp_attr_Const);
set_op_cmp_attr(op_CopyB, node_cmp_attr_CopyB);
set_op_cmp_attr(op_Div, node_cmp_attr_Div);
set_op_cmp_attr(op_Dummy, node_cmp_attr_Dummy);
set_op_cmp_attr(op_Load, node_cmp_attr_Load);
set_op_cmp_attr(op_Mod, node_cmp_attr_Mod);
set_op_cmp_attr(op_Offset, node_cmp_attr_entconst);
set_op_cmp_attr(op_Phi, node_cmp_attr_Phi);
set_op_cmp_attr(op_Proj, node_cmp_attr_Proj);
set_op_cmp_attr(op_Sel, node_cmp_attr_Sel);
set_op_cmp_attr(op_Store, node_cmp_attr_Store);
set_op_cmp_attr(op_TypeConst,node_cmp_attr_TypeConst);
set_op_hash(op_Address, hash_entconst);
set_op_hash(op_Const, hash_Const);
set_op_hash(op_Offset, hash_entconst);
set_op_hash(op_TypeConst, hash_TypeConst);
set_op_cmp_attr(op_Address, node_cmp_attr_entconst);
set_op_cmp_attr(op_Align, node_cmp_attr_typeconst);
set_op_cmp_attr(op_ASM, node_cmp_attr_ASM);
set_op_cmp_attr(op_Alloc, node_cmp_attr_Alloc);
set_op_cmp_attr(op_Builtin, node_cmp_attr_Builtin);
set_op_cmp_attr(op_Call, node_cmp_attr_Call);
set_op_cmp_attr(op_Cmp, node_cmp_attr_Cmp);
set_op_cmp_attr(op_Confirm, node_cmp_attr_Confirm);
set_op_cmp_attr(op_Const, node_cmp_attr_Const);
set_op_cmp_attr(op_CopyB, node_cmp_attr_CopyB);
set_op_cmp_attr(op_Div, node_cmp_attr_Div);
set_op_cmp_attr(op_Dummy, node_cmp_attr_Dummy);
set_op_cmp_attr(op_Load, node_cmp_attr_Load);
set_op_cmp_attr(op_Mod, node_cmp_attr_Mod);
set_op_cmp_attr(op_Offset, node_cmp_attr_entconst);
set_op_cmp_attr(op_Phi, node_cmp_attr_Phi);
set_op_cmp_attr(op_Proj, node_cmp_attr_Proj);
set_op_cmp_attr(op_Sel, node_cmp_attr_Sel);
set_op_cmp_attr(op_Size, node_cmp_attr_typeconst);
set_op_cmp_attr(op_Store, node_cmp_attr_Store);
set_op_hash(op_Address, hash_entconst);
set_op_hash(op_Align, hash_typeconst);
set_op_hash(op_Const, hash_Const);
set_op_hash(op_Offset, hash_entconst);
set_op_hash(op_Size, hash_typeconst);
set_op_copy_attr(op_Call, call_copy_attr);
set_op_copy_attr(op_Block, block_copy_attr);
......
......@@ -132,26 +132,24 @@ static ir_tarval *computed_value_Offset(const ir_node *n)
}
/**
* Return the value of a 'sizeof' or 'alignof' TypeConst.
* Return the value of an Align.
*/
static ir_tarval *computed_value_TypeConst(const ir_node *n)
static ir_tarval *computed_value_Align(const ir_node *n)
{
switch (get_TypeConst_kind(n)) {
case typeconst_size: {
const ir_type *type = get_TypeConst_type(n);
if (get_type_state(type) == layout_fixed)
return new_tarval_from_long(get_type_size_bytes(type), get_irn_mode(n));
break;
}
case typeconst_align: {
ir_type *type = get_TypeConst_type(n);
if (get_type_state(type) == layout_fixed)
return new_tarval_from_long(get_type_alignment_bytes(type), get_irn_mode(n));
break;
}
default:
break;
}
ir_type *const type = get_Align_type(n);
if (get_type_state(type) == layout_fixed)
return new_tarval_from_long(get_type_alignment_bytes(type), get_irn_mode(n));
return tarval_bad;
}
/**
* Return the value of a Size.
*/
static ir_tarval *computed_value_Size(const ir_node *n)
{
ir_type *const type = get_Size_type(n);
if (get_type_state(type) == layout_fixed)
return new_tarval_from_long(get_type_size_bytes(type), get_irn_mode(n));
return tarval_bad;
}
......@@ -6447,6 +6445,7 @@ static void register_transform_node_func_proj(ir_op *op,
void ir_register_opt_node_ops(void)
{
register_computed_value_func(op_Add, computed_value_Add);
register_computed_value_func(op_Align, computed_value_Align);
register_computed_value_func(op_And, computed_value_And);
register_computed_value_func(op_Cmp, computed_value_Cmp);
register_computed_value_func(op_Confirm, computed_value_Confirm);
......@@ -6463,8 +6462,8 @@ void ir_register_opt_node_ops(void)
register_computed_value_func(op_Shl, computed_value_Shl);
register_computed_value_func(op_Shr, computed_value_Shr);
register_computed_value_func(op_Shrs, computed_value_Shrs);
register_computed_value_func(op_Size, computed_value_Size);
register_computed_value_func(op_Sub, computed_value_Sub);
register_computed_value_func(op_TypeConst,computed_value_TypeConst);
register_computed_value_func_proj(op_Div, computed_value_Proj_Div);
register_computed_value_func_proj(op_Mod, computed_value_Proj_Mod);
......
......@@ -232,8 +232,7 @@ typedef struct entconst_attr {
/** TypeConst attributes. */
typedef struct typeconst_attr {
ir_type *type;
typeconst_kind kind;
ir_type *type;
} typeconst_attr;
/** Sel attributes. */
......
......@@ -543,22 +543,11 @@ static int verify_node_Const(const ir_node *n)
return fine;
}
static int verify_node_Offset(const ir_node *n)
static int verify_node_int(const ir_node *n)
{
return check_mode_func(n, mode_is_int, "int");
}
static int verify_node_TypeConst(const ir_node *n)
{
switch (get_TypeConst_kind(n)) {
case typeconst_size:
case typeconst_align:
return check_mode_func(n, mode_is_int, "int");
}
warn(n, "invalid TypeConst kind");
return false;
}
static int verify_node_Sel(const ir_node *n)
{
bool fine = check_mode_func(n, mode_is_reference, "reference");
......@@ -1260,6 +1249,7 @@ void ir_register_verify_node_ops(void)
{
register_verify_node_func(op_Add, verify_node_Add);
register_verify_node_func(op_Address, verify_node_Address);
register_verify_node_func(op_Align, verify_node_int);
register_verify_node_func(op_Alloc, verify_node_Alloc);
register_verify_node_func(op_And, verify_node_And);
register_verify_node_func(op_Block, verify_node_Block);
......@@ -1283,7 +1273,7 @@ void ir_register_verify_node_ops(void)
register_verify_node_func(op_Mulh, verify_node_Mulh);
register_verify_node_func(op_Mux, verify_node_Mux);
register_verify_node_func(op_Not, verify_node_Not);
register_verify_node_func(op_Offset, verify_node_Offset);
register_verify_node_func(op_Offset, verify_node_int);
register_verify_node_func(op_Or, verify_node_Or);
register_verify_node_func(op_Phi, verify_node_Phi);
register_verify_node_func(op_Proj, verify_node_Proj);
......@@ -1293,12 +1283,12 @@ void ir_register_verify_node_ops(void)
register_verify_node_func(op_Shl, verify_node_Shl);
register_verify_node_func(op_Shr, verify_node_Shr);
register_verify_node_func(op_Shrs, verify_node_Shrs);
register_verify_node_func(op_Size, verify_node_int);
register_verify_node_func(op_Start, verify_node_Start);
register_verify_node_func(op_Store, verify_node_Store);
register_verify_node_func(op_Sub, verify_node_Sub);
register_verify_node_func(op_Switch, verify_node_Switch);
register_verify_node_func(op_Sync, verify_node_Sync);
register_verify_node_func(op_TypeConst,verify_node_TypeConst);
register_verify_node_func_proj(op_Alloc, verify_node_Proj_Alloc);
register_verify_node_func_proj(op_Call, verify_node_Proj_Call);
......
......@@ -202,25 +202,25 @@ static void lower_offset(ir_node *const entc)
}
/**
* Lower a TypeConst node.
* Lower an Align node.
*/
static void lower_typeconst(ir_node *const typec)
static void lower_align(ir_node *const align)
{
ir_type *const tp = get_TypeConst_type(typec);
ir_type *const tp = get_Align_type(align);
assert(get_type_state(tp) == layout_fixed);
/* rewrite the Align node by a Const node */
replace_by_Const(align, get_type_alignment_bytes(tp));
}
switch (get_TypeConst_kind(typec)) {
case typeconst_size:
/* rewrite the TypeConst node by a Const node */
replace_by_Const(typec, get_type_size_bytes(tp));
return;
case typeconst_align:
/* rewrite the TypeConst node by a Const node */
replace_by_Const(typec, get_type_alignment_bytes(tp));
return;
}
panic("invalid TypeConst kind");
/**
* Lower a Size node.
*/
static void lower_size(ir_node *const size)
{
ir_type *const tp = get_Size_type(size);
assert(get_type_state(tp) == layout_fixed);
/* rewrite the Size node by a Const node */
replace_by_Const(size, get_type_size_bytes(tp));
}
/**
......@@ -230,10 +230,11 @@ static void lower_irnode(ir_node *irn, void *env)
{
(void) env;
switch (get_irn_opcode(irn)) {
case iro_Sel: lower_sel(irn); break;
case iro_Offset: lower_offset(irn); break;
case iro_TypeConst: lower_typeconst(irn); break;
default: break;
case iro_Align: lower_align(irn); break;
case iro_Offset: lower_offset(irn); break;
case iro_Sel: lower_sel(irn); break;
case iro_Size: lower_size(irn); break;
default: break;
}
}
......
......@@ -1970,20 +1970,23 @@ static void compute_Offset(node_t *node)
}
/**
* (Re-)compute the type for a TypeConst node.
* (Re-)compute the type for an Align node.
*
* @param node the node
*/
static void compute_TypeConst(node_t *node)
static void compute_Align(node_t *node)
{
ir_node *irn = node->node;
node_t *block = get_irn_node(get_nodes_block(irn));
node->type.tv = computed_value(node->node);
}
if (block->type.tv == tarval_unreachable) {
node->type.tv = tarval_top;
return;
}
node->type.tv = computed_value(irn);
/**
* (Re-)compute the type for a Size node.
*
* @param node the node
*/
static void compute_Size(node_t *node)
{
node->type.tv = computed_value(node->node);
}
/**
......@@ -3379,6 +3382,7 @@ static void set_compute_functions(void)
/* set specific functions */
SET(Address);
SET(Align);
SET(Block);
SET(Unknown);
SET(Bad);
......@@ -3388,13 +3392,13 @@ static void set_compute_functions(void)
SET(Sub);
SET(Eor);
SET(Offset);
SET(TypeConst);
SET(Cmp);
SET(Proj);
SET(Confirm);
SET(Return);
SET(End);
SET(Call);
SET(Size);
}
/**
......
......@@ -1266,7 +1266,7 @@ static unsigned is_hoisting_greedy(ir_node *irn, ir_node *block)
trans_val = identify(trans);
DB((dbg, LEVEL_3, "value %+F\n", trans_val));
if (is_Address(trans_val) || is_Const(trans_val) || is_Offset(trans_val) || is_TypeConst(trans_val)) {
if (is_Address(trans_val) || is_Align(trans_val) || is_Const(trans_val) || is_Offset(trans_val) || is_Size(trans_val)) {
/* existing constant */
if (get_irn_idx(trans_val) < environ->last_idx) {
continue;
......
......@@ -283,7 +283,7 @@ static ir_entity *find_constant_entity(ir_node *ptr)
return NULL;
/* for now, we support only one addition, reassoc should fold all others */
if (!is_Address(ptr) && !is_Offset(ptr) && !is_Sel(ptr) && !is_TypeConst(ptr))
if (!is_Address(ptr) && !is_Align(ptr) && !is_Offset(ptr) && !is_Sel(ptr) && !is_Size(ptr))
return NULL;
} else if (is_Sub(ptr)) {
ir_node *l = get_Sub_left(ptr);
......@@ -294,7 +294,7 @@ static ir_entity *find_constant_entity(ir_node *ptr)
else
return NULL;
/* for now, we support only one substraction, reassoc should fold all others */
if (!is_Address(ptr) && !is_Offset(ptr) && !is_Sel(ptr) && !is_TypeConst(ptr))
if (!is_Address(ptr) && !is_Align(ptr) && !is_Offset(ptr) && !is_Sel(ptr) && !is_Size(ptr))
return NULL;
} else
return NULL;
......
......@@ -264,10 +264,11 @@ static void get_loop_info(ir_node *node, void *env)
break;
case iro_Address:
case iro_Align:
case iro_Confirm:
case iro_Const:
case iro_Offset:
case iro_TypeConst:
case iro_Size:
break;
default:
......@@ -1839,9 +1840,10 @@ static bool is_const(ir_node *const node)
{
switch (get_irn_opcode(node)) {
case iro_Address:
case iro_Align:
case iro_Const:
case iro_Offset:
case iro_TypeConst:
case iro_Size:
return true;
default:
return false;
......
......@@ -39,7 +39,7 @@ typedef struct env_t {
static void occult_const_opt_walker(ir_node *node, void *data)
{
/* Ignore already const nodes */
if (is_Address(node) || is_Const(node) || is_Offset(node) || is_TypeConst(node)) return;
if (is_Address(node) || is_Align(node) || is_Const(node) || is_Offset(node) || is_Size(node)) return;
/* Ignore mode_BB, mode_X, etc */
if (!mode_is_data(get_irn_mode(node))) return;
......
......@@ -395,6 +395,9 @@ static opcode_key_t *opcode(const node_t *node, environment_t *env)
case iro_Address:
key.u.ent = get_Address_entity(irn);
break;
case iro_Align:
key.u.type = get_Align_type(irn);
break;
case iro_Offset:
key.u.ent = get_Offset_entity(irn);
break;
......@@ -416,8 +419,8 @@ static opcode_key_t *opcode(const node_t *node, environment_t *env)
case iro_Builtin:
key.u.intVal = get_Builtin_kind(irn);