Commit 274626e2 authored by Matthias Braun's avatar Matthias Braun
Browse files

make unique types/entities part of irprog

unknown_type, code_type, none_type, unknown_entity reference are hold in
the irprog now. This makes handling more consistent since now all types
and entities are equally part of irprog.
parent a276562e
......@@ -689,9 +689,6 @@ FIRM_API ir_type *get_entity_repr_class(const ir_entity *ent);
* - link = NULL
*/
/** A variable that contains the only unknown entity. */
FIRM_API ir_entity *unknown_entity;
/** Returns the @link unknown_entity unknown entity @endlink. */
FIRM_API ir_entity *get_unknown_entity(void);
......@@ -2081,8 +2078,6 @@ FIRM_API const tp_op *get_tpop_primitive(void);
* - size: 0
* @{
*/
/** A variable that contains the only none type. */
FIRM_API ir_type *firm_none_type;
/** Returns the none type. */
FIRM_API ir_type *get_none_type(void);
/** Checks whether type @p type is the none type. */
......@@ -2103,8 +2098,6 @@ FIRM_API const tp_op *get_tpop_none(void);
/** @defgroup code_type Code
* @{
*/
/** A variable that contains the only code type. */
FIRM_API ir_type *firm_code_type;
/** Returns the code type. */
FIRM_API ir_type *get_code_type(void);
/**
......@@ -2137,8 +2130,6 @@ FIRM_API const tp_op *get_tpop_code_type(void);
* - size: 0
* @{
*/
/** A variable that contains the only unknown type. */
FIRM_API ir_type *firm_unknown_type;
/** Returns the unknown type. */
FIRM_API ir_type *get_unknown_type(void);
/** Checks whether type @p type is the unknown type */
......
......@@ -98,7 +98,7 @@ static ptr_access_kind analyze_arg(ir_node *arg, ptr_access_kind bits)
meth_ent = get_Call_callee(succ, c);
/* unknown_entity is used to signal that we don't know what is called */
if (meth_ent == unknown_entity) {
if (is_unknown_entity(meth_ent)) {
bits |= ptr_access_all;
break;
}
......
......@@ -619,7 +619,7 @@ static void callee_ana_proj(ir_node *node, long n, pset *methods)
if (is_Tuple(pred)) {
callee_ana_proj(get_Tuple_pred(pred, get_Proj_proj(node)), n, methods);
} else {
pset_insert_ptr(methods, unknown_entity); /* free method -> unknown */
pset_insert_ptr(methods, get_unknown_entity()); /* free method -> unknown */
}
}
break;
......@@ -630,7 +630,7 @@ static void callee_ana_proj(ir_node *node, long n, pset *methods)
break;
default:
pset_insert_ptr(methods, unknown_entity); /* free method -> unknown */
pset_insert_ptr(methods, get_unknown_entity()); /* free method -> unknown */
break;
}
}
......@@ -655,7 +655,7 @@ static void callee_ana_node(ir_node *node, pset *methods)
case iro_Const:
/* A direct address call. We tread this as an external
call and ignore it completely. */
pset_insert_ptr(methods, unknown_entity); /* free method -> unknown */
pset_insert_ptr(methods, get_unknown_entity()); /* free method -> unknown */
break;
case iro_SymConst: {
......@@ -673,7 +673,7 @@ static void callee_ana_node(ir_node *node, pset *methods)
if (ent != NULL) {
pset_insert_ptr(methods, ent);
} else {
pset_insert_ptr(methods, unknown_entity);
pset_insert_ptr(methods, get_unknown_entity());
}
}
break;
......@@ -708,7 +708,7 @@ static void callee_ana_node(ir_node *node, pset *methods)
case iro_Sub:
case iro_Conv:
/* extern */
pset_insert_ptr(methods, unknown_entity); /* free method -> unknown */
pset_insert_ptr(methods, get_unknown_entity()); /* free method -> unknown */
break;
default:
......@@ -736,9 +736,9 @@ static void callee_walker(ir_node *call, void *env)
foreach_pset(methods, ir_entity*, ent) {
arr[i] = ent;
/* we want the unknown_entity on the zero position for easy tests later */
if (ent == unknown_entity) {
if (is_unknown_entity(ent)) {
arr[i] = arr[0];
arr[0] = unknown_entity;
arr[0] = get_unknown_entity();
}
++i;
}
......
......@@ -865,7 +865,7 @@ static ir_node *adjust_alloc(be_abi_irg_t *env, ir_node *alloc, ir_node *curr_sp
count = get_Alloc_count(alloc);
/* we might need to multiply the count with the element size */
if (type != firm_unknown_type && get_type_size_bytes(type) != 1) {
if (!is_unknown_type(type) && get_type_size_bytes(type) != 1) {
ir_mode *mode = get_irn_mode(count);
ir_tarval *tv = new_tarval_from_long(get_type_size_bytes(type),
mode);
......@@ -930,7 +930,7 @@ static ir_node *adjust_free(be_abi_irg_t *env, ir_node *free, ir_node *curr_sp)
assert(get_Free_where(free) == stack_alloc);
/* we might need to multiply the size with the element size */
if (type != firm_unknown_type && get_type_size_bytes(type) != 1) {
if (!is_unknown_type(type) && get_type_size_bytes(type) != 1) {
ir_tarval *tv = new_tarval_from_long(get_type_size_bytes(type), mode_Iu);
ir_node *cnst = new_rd_Const(dbg, irg, tv);
ir_node *mul = new_rd_Mul(dbg, block, get_Free_count(free),
......
......@@ -1547,7 +1547,7 @@ char const *be_gas_get_private_prefix(void)
void be_gas_emit_entity(const ir_entity *entity)
{
if (entity->type == firm_code_type) {
if (entity->type == get_code_type()) {
ir_label_t label = get_entity_label(entity);
be_emit_irprintf("%s_%lu", be_gas_get_private_prefix(), label);
return;
......@@ -1585,7 +1585,7 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
ir_linkage linkage = get_entity_linkage(entity);
/* block labels are already emittet in the code */
if (type == firm_code_type)
if (type == get_code_type())
return;
/* we already emitted all methods. Except for the trampolines which
......
......@@ -517,7 +517,7 @@ static void walk_type(type_or_ent tore, void *ctx)
tp = tore.typ;
/* ignore the unknown type */
if (tp == firm_unknown_type)
if (is_unknown_type(tp))
return;
} else {
return;
......
......@@ -2022,7 +2022,7 @@ static ir_node *gen_Alloc(ir_node *node)
if (get_Alloc_where(node) != stack_alloc)
panic("only stack-alloc supported in sparc backend (at %+F)", node);
/* lowerer should have transformed all allocas to byte size */
if (type != get_unknown_type() && get_type_size_bytes(type) != 1)
if (!is_unknown_type(type) && get_type_size_bytes(type) != 1)
panic("Found non-byte alloc in sparc backend (at %+F)", node);
if (is_Const(size)) {
......@@ -2082,7 +2082,7 @@ static ir_node *gen_Free(ir_node *node)
if (get_Alloc_where(node) != stack_alloc)
panic("only stack-alloc supported in sparc backend (at %+F)", node);
/* lowerer should have transformed all allocas to byte size */
if (type != get_unknown_type() && get_type_size_bytes(type) != 1)
if (!is_unknown_type(type) && get_type_size_bytes(type) != 1)
panic("Found non-byte alloc in sparc backend (at %+F)", node);
if (is_Const(size)) {
......
......@@ -102,10 +102,6 @@ void ir_init(void)
/* Builds a construct allowing to access all information to be constructed
later. */
init_irprog_2();
/* Initialize the type module and construct some idents needed. */
ir_init_type();
/* initialize the entity module */
ir_init_entity();
/* class cast optimization */
firm_init_class_casts_opt();
/* memory disambiguation */
......@@ -127,9 +123,6 @@ void ir_finish(void)
{
free_ir_prog();
ir_finish_entity();
ir_finish_type();
finish_tarval();
finish_mode();
finish_tpop();
......
......@@ -815,7 +815,7 @@ static int dump_node_typeinfo(FILE *F, const ir_node *n)
if (get_irg_typeinfo_state(current_ir_graph) == ir_typeinfo_consistent ||
get_irg_typeinfo_state(current_ir_graph) == ir_typeinfo_inconsistent) {
ir_type *tp = get_irn_typeinfo_type(n);
if (tp != firm_none_type) {
if (tp != get_none_type()) {
ir_fprintf(F, "[%+F]", tp);
} else {
fprintf(F, "[] ");
......
......@@ -315,7 +315,7 @@ void dump_irnode_to_file(FILE *F, const ir_node *n)
if (get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_consistent ||
get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_inconsistent )
if (get_irn_typeinfo_type(n) != firm_none_type)
if (get_irn_typeinfo_type(n) != get_none_type())
ir_fprintf (F, " Analysed type: %s\n", get_irn_typeinfo_type(n));
}
......
......@@ -122,6 +122,7 @@ typedef enum keyword_t {
kw_segment_type,
kw_type,
kw_typegraph,
kw_unknown,
} keyword_t;
typedef struct symbol_t {
......@@ -247,6 +248,7 @@ static void symtbl_init(void)
INSERTKEYWORD(segment_type);
INSERTKEYWORD(type);
INSERTKEYWORD(typegraph);
INSERTKEYWORD(unknown);
INSERTENUM(tt_align, align_non_aligned);
INSERTENUM(tt_align, align_is_aligned);
......@@ -397,15 +399,20 @@ static void write_entity_ref(write_env_t *env, ir_entity *entity)
static void write_type_ref(write_env_t *env, ir_type *type)
{
if (type == firm_unknown_type) {
switch (get_type_tpop_code(type)) {
case tpo_unknown:
write_symbol(env, "unknown");
} else if (type == firm_none_type) {
return;
case tpo_none:
write_symbol(env, "none");
} else if (type == firm_code_type) {
return;
case tpo_code:
write_symbol(env, "code");
} else {
write_long(env, get_type_nr(type));
return;
default:
break;
}
write_long(env, get_type_nr(type));
}
static void write_string(write_env_t *env, const char *string)
......@@ -617,7 +624,7 @@ static void write_type_primitive(write_env_t *env, ir_type *tp)
write_type_common(env, tp);
write_mode_ref(env, get_type_mode(tp));
if (base_type == NULL)
base_type = firm_none_type;
base_type = get_none_type();
write_type_ref(env, base_type);
fputc('\n', env->file);
}
......@@ -772,6 +779,10 @@ static void write_entity(write_env_t *env, ir_entity *ent)
case IR_ENTITY_LABEL: write_symbol(env, "label"); break;
case IR_ENTITY_COMPOUND_MEMBER: write_symbol(env, "compound_member"); break;
case IR_ENTITY_PARAMETER: write_symbol(env, "parameter"); break;
case IR_ENTITY_UNKNOWN:
write_symbol(env, "unknown");
write_long(env, get_entity_nr(ent));
return;
}
write_long(env, get_entity_nr(ent));
......@@ -830,6 +841,7 @@ static void write_entity(write_env_t *env, ir_entity *ent)
}
break;
}
case IR_ENTITY_UNKNOWN:
case IR_ENTITY_LABEL:
case IR_ENTITY_METHOD:
break;
......@@ -1474,11 +1486,11 @@ static ir_type *get_type(read_env_t *env, long typenr)
ir_type *type = (ir_type *) get_id(env, typenr);
if (type == NULL) {
parse_error(env, "Type %ld not defined (yet?)\n", typenr);
return firm_unknown_type;
return get_unknown_type();
}
if (type->kind != k_type) {
parse_error(env, "Object %ld is not a type (but should be)\n", typenr);
return firm_unknown_type;
return get_unknown_type();
}
return type;
}
......@@ -1488,15 +1500,15 @@ static ir_type *read_type_ref(read_env_t *env)
char *str = read_word(env);
if (strcmp(str, "none") == 0) {
obstack_free(&env->obst, str);
return firm_none_type;
return get_none_type();
}
if (strcmp(str, "unknown") == 0) {
obstack_free(&env->obst, str);
return firm_unknown_type;
return get_unknown_type();
}
if (strcmp(str, "code") == 0) {
obstack_free(&env->obst, str);
return firm_code_type;
return get_code_type();
}
long nr = atol(str);
obstack_free(&env->obst, str);
......@@ -1507,7 +1519,7 @@ static ir_type *read_type_ref(read_env_t *env)
static ir_entity *create_error_entity(void)
{
ir_entity *res = new_entity(get_glob_type(), new_id_from_str("error"),
firm_unknown_type);
get_unknown_type());
return res;
}
......@@ -1833,7 +1845,7 @@ static void read_type(read_env_t *env)
ir_mode *mode = read_mode_ref(env);
ir_type *base_type = read_type_ref(env);
type = new_type_primitive(mode);
if (base_type != firm_none_type) {
if (base_type != get_none_type()) {
set_primitive_base_type(type, base_type);
}
goto finish_type;
......@@ -1875,6 +1887,13 @@ finish_type:
set_id(env, typenr, type);
}
static void read_unknown_entity(read_env_t *env)
{
long entnr = read_long(env);
ir_entity *entity = get_unknown_entity();
set_id(env, entnr, entity);
}
/** Reads an entity description and remembers it by its id. */
static void read_entity(read_env_t *env, ir_entity_kind kind)
{
......@@ -1952,6 +1971,8 @@ static void read_entity(read_env_t *env, ir_entity_kind kind)
ir_label_t nr = get_irp_next_label_nr();
entity = new_label_entity(nr);
break;
case IR_ENTITY_UNKNOWN:
panic("read_entity with IR_ENTITY_UNKNOWN?");
}
}
......@@ -2006,6 +2027,9 @@ static void read_typegraph(read_env_t *env)
case kw_parameter:
read_entity(env, IR_ENTITY_PARAMETER);
break;
case kw_unknown:
read_unknown_entity(env);
break;
default:
parse_error(env, "type graph element not supported yet: %d\n", kwkind);
skip_to(env, '\n');
......
......@@ -1513,7 +1513,7 @@ static ir_entity *get_SymConst_attr_entity(const ir_node *self)
static ir_type *get_Null_type(const ir_node *n)
{
(void) n;
return firm_unknown_type;
return get_unknown_type();
}
void firm_set_default_get_type_attr(unsigned code, ir_op_ops *ops)
......
......@@ -76,7 +76,7 @@ static ir_prog *new_incomplete_ir_prog(void)
* @param irp the (yet incomplete) irp
* @param module_name the (module) name for this irp
*/
static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name)
static void complete_ir_prog(ir_prog *irp, const char *module_name)
{
#define IDENT(x) new_id_from_chars(x, sizeof(x) - 1)
......@@ -104,10 +104,6 @@ static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name)
irp->phase_state = phase_building;
irp->class_cast_state = ir_class_casts_transitive;
irp->globals_entity_usage_state = ir_entity_usage_not_computed;
current_ir_graph = irp->const_code_irg;
return irp;
#undef IDENT
}
......@@ -118,12 +114,16 @@ void init_irprog_1(void)
void init_irprog_2(void)
{
(void)complete_ir_prog(irp, INITAL_PROG_NAME);
complete_ir_prog(irp, INITAL_PROG_NAME);
ir_init_type(irp);
ir_init_entity(irp);
}
ir_prog *new_ir_prog(const char *name)
{
return complete_ir_prog(new_incomplete_ir_prog(), name);
ir_prog *irp = new_incomplete_ir_prog();
complete_ir_prog(irp, name);
return irp;
}
void free_ir_prog(void)
......
......@@ -622,8 +622,12 @@ struct ir_prog {
to allocate nodes the represent values
of constant entities. It is not meant as
a procedure. */
ir_entity *unknown_entity; /**< unique 'unknown'-entity */
ir_type *segment_types[IR_SEGMENT_LAST+1];
ir_type **types; /**< A list of all types in the ir. */
ir_type *none_type; /**< unique 'none'-type */
ir_type *code_type; /**< unique 'code'-type */
ir_type *unknown_type; /**< unique 'unknown'-type */
ir_mode **modes; /**< A list of all modes in the ir. */
ir_op **opcodes; /**< A list of all opcodes in the ir. */
ident **global_asms; /**< An array of global ASM insertions. */
......
......@@ -655,7 +655,7 @@ static int verify_node_Proj_Proj(const ir_node *p)
(proj >= 0 && mode_is_datab(mode)),
"wrong Proj from Proj from Call", 0);
mt = get_Call_type(pred);
ASSERT_AND_RET(mt == get_unknown_type() || is_Method_type(mt),
ASSERT_AND_RET(is_unknown_type(mt) || is_Method_type(mt),
"wrong call type on call", 0);
ASSERT_AND_RET(
(proj < (int)get_method_n_ress(mt)),
......
......@@ -140,7 +140,7 @@ static void lower_alloca_free(ir_node *node, void *data)
ir_nodeset_insert(&transformed, node);
size = get_type_size_bytes(type);
if (type == get_unknown_type())
if (is_unknown_type(type))
size = 1;
if (size == 1 && stack_alignment <= 1)
return;
......
......@@ -293,7 +293,7 @@ int i_mapper_alloca(ir_node *call, void *ctx)
op = new_rd_Conv(dbg, block, op, mode);
}
irn = new_rd_Alloc(dbg, block, mem, op, firm_unknown_type, stack_alloc);
irn = new_rd_Alloc(dbg, block, mem, op, get_unknown_type(), stack_alloc);
mem = new_rd_Proj(dbg, irn, mode_M, pn_Alloc_M);
irn = new_rd_Proj(dbg, irn, get_modeP_data(), pn_Alloc_res);
if (ir_throws_exception(call)) {
......
......@@ -192,7 +192,7 @@ static int can_escape(ir_node *n)
size_t j;
ent = get_Call_callee(succ, --k);
if (ent == unknown_entity) {
if (is_unknown_entity(ent)) {
/* we don't know what will be called, a possible escape */
return 1;
}
......@@ -414,7 +414,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env)
}
}
if (tp && tp != firm_unknown_type) {
if (tp && !is_unknown_type(tp)) {
/* we could determine the type, so we could place it on the frame */
dbg = get_irn_dbg_info(alloc);
blk = get_nodes_block(alloc);
......
......@@ -112,7 +112,7 @@ static void collect_const_and_pure_calls(ir_node *node, void *env)
or_prop = 0;
for (i = 0; i < n_callees; ++i) {
ent = get_Call_callee(call, i);
if (ent == unknown_entity) {
if (is_unknown_entity(ent)) {
/* we don't know which entity is called here */
return;
}
......@@ -284,7 +284,7 @@ static void collect_nothrow_calls(ir_node *node, void *env)
prop = mtp_property_nothrow;
for (i = 0; i < n_callees; ++i) {
ent = get_Call_callee(call, i);
if (ent == unknown_entity) {
if (is_unknown_entity(ent)) {
/* we don't know which entity is called here */
return;
}
......@@ -865,7 +865,7 @@ static mtp_additional_properties check_nothrow_or_malloc(ir_graph *irg, int top)
for (i = 0; i < n_callees; ++i) {
ir_entity *ent = get_Call_callee(res, i);
if (ent == unknown_entity) {
if (is_unknown_entity(ent)) {
/* we don't know which entity is called here */
curr_prop &= ~mtp_property_malloc;
break;
......@@ -923,7 +923,7 @@ static mtp_additional_properties check_nothrow_or_malloc(ir_graph *irg, int top)
for (i = 0; i < n_callees; ++i) {
ir_entity *ent = get_Call_callee(pred, i);
if (ent == unknown_entity) {
if (is_unknown_entity(ent)) {
/* we don't know which entity is called here */
curr_prop &= ~mtp_property_nothrow;
break;
......
......@@ -62,7 +62,7 @@ static gen_pointer_type_to_func gen_pointer_type_to = default_gen_pointer_type_t
static ir_type *default_gen_pointer_type_to(ir_type *tp)
{
ir_type *res = find_pointer_type_to_type(tp);
if (res == firm_unknown_type)
if (is_unknown_type(res))
res = new_type_pointer(tp);
return res;
......
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