From 274626e2d58cfa247b88ee05adaca8906b025d93 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 15 Dec 2011 14:58:07 +0100 Subject: [PATCH] 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. --- include/libfirm/typerep.h | 9 ------ ir/ana/analyze_irg_args.c | 2 +- ir/ana/cgana.c | 14 ++++----- ir/be/beabi.c | 4 +-- ir/be/begnuas.c | 4 +-- ir/be/bestabs.c | 2 +- ir/be/sparc/sparc_transform.c | 4 +-- ir/common/firm.c | 7 ----- ir/ir/irdump.c | 2 +- ir/ir/irdumptxt.c | 2 +- ir/ir/irio.c | 50 ++++++++++++++++++++++++--------- ir/ir/irnode.c | 2 +- ir/ir/irprog.c | 14 ++++----- ir/ir/irtypes.h | 4 +++ ir/ir/irverify.c | 2 +- ir/lower/lower_alloc.c | 2 +- ir/lower/lower_intrinsics.c | 2 +- ir/opt/escape_ana.c | 4 +-- ir/opt/funccall.c | 8 +++--- ir/opt/tropt.c | 2 +- ir/tr/entity.c | 46 ++++++++++++------------------ ir/tr/entity_t.h | 6 ++-- ir/tr/type.c | 53 +++++++++++++---------------------- ir/tr/type_t.h | 4 +-- 24 files changed, 119 insertions(+), 130 deletions(-) diff --git a/include/libfirm/typerep.h b/include/libfirm/typerep.h index 154adfb6e..489ae3e33 100644 --- a/include/libfirm/typerep.h +++ b/include/libfirm/typerep.h @@ -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 */ diff --git a/ir/ana/analyze_irg_args.c b/ir/ana/analyze_irg_args.c index 7331cc84c..9cf6b2b1c 100644 --- a/ir/ana/analyze_irg_args.c +++ b/ir/ana/analyze_irg_args.c @@ -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; } diff --git a/ir/ana/cgana.c b/ir/ana/cgana.c index 76c152cce..7cc59b2cf 100644 --- a/ir/ana/cgana.c +++ b/ir/ana/cgana.c @@ -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; } diff --git a/ir/be/beabi.c b/ir/be/beabi.c index 9683b4cfd..1e6cb7196 100644 --- a/ir/be/beabi.c +++ b/ir/be/beabi.c @@ -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), diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c index a3a26086d..63a34b0fa 100644 --- a/ir/be/begnuas.c +++ b/ir/be/begnuas.c @@ -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 diff --git a/ir/be/bestabs.c b/ir/be/bestabs.c index 9caf93902..a385da5d4 100644 --- a/ir/be/bestabs.c +++ b/ir/be/bestabs.c @@ -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; diff --git a/ir/be/sparc/sparc_transform.c b/ir/be/sparc/sparc_transform.c index c8f6302de..fffa4ceae 100644 --- a/ir/be/sparc/sparc_transform.c +++ b/ir/be/sparc/sparc_transform.c @@ -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)) { diff --git a/ir/common/firm.c b/ir/common/firm.c index 916fccc65..1241268b2 100644 --- a/ir/common/firm.c +++ b/ir/common/firm.c @@ -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(); diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 08fb15e90..4628990d4 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -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, "[] "); diff --git a/ir/ir/irdumptxt.c b/ir/ir/irdumptxt.c index 2c64ed943..e0d191727 100644 --- a/ir/ir/irdumptxt.c +++ b/ir/ir/irdumptxt.c @@ -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)); } diff --git a/ir/ir/irio.c b/ir/ir/irio.c index 0a6417d2f..fab04b5b0 100644 --- a/ir/ir/irio.c +++ b/ir/ir/irio.c @@ -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'); diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 8b956f353..83b3268fe 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -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) diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index 5a1a10278..74dae2b1f 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -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) diff --git a/ir/ir/irtypes.h b/ir/ir/irtypes.h index bc7acceb9..07317f418 100644 --- a/ir/ir/irtypes.h +++ b/ir/ir/irtypes.h @@ -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. */ diff --git a/ir/ir/irverify.c b/ir/ir/irverify.c index d919256f9..7d4bacc24 100644 --- a/ir/ir/irverify.c +++ b/ir/ir/irverify.c @@ -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)), diff --git a/ir/lower/lower_alloc.c b/ir/lower/lower_alloc.c index 8e33d4d15..4cc4a1e1c 100644 --- a/ir/lower/lower_alloc.c +++ b/ir/lower/lower_alloc.c @@ -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; diff --git a/ir/lower/lower_intrinsics.c b/ir/lower/lower_intrinsics.c index 676fdad1c..4b34720fb 100644 --- a/ir/lower/lower_intrinsics.c +++ b/ir/lower/lower_intrinsics.c @@ -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)) { diff --git a/ir/opt/escape_ana.c b/ir/opt/escape_ana.c index be3ee27c3..484309054 100644 --- a/ir/opt/escape_ana.c +++ b/ir/opt/escape_ana.c @@ -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); diff --git a/ir/opt/funccall.c b/ir/opt/funccall.c index b4fa2c571..a5cddd6f8 100644 --- a/ir/opt/funccall.c +++ b/ir/opt/funccall.c @@ -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; diff --git a/ir/opt/tropt.c b/ir/opt/tropt.c index ab0b18caf..8762a8f43 100644 --- a/ir/opt/tropt.c +++ b/ir/opt/tropt.c @@ -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; diff --git a/ir/tr/entity.c b/ir/tr/entity.c index e7c74a860..5981e3cda 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -44,17 +44,14 @@ #include "error.h" #include "compound_path.h" -/*-----------------------------------------------------------------*/ -/** general **/ -/*-----------------------------------------------------------------*/ - -ir_entity *unknown_entity = NULL; - -ir_entity *get_unknown_entity(void) { return unknown_entity; } - /** The name of the unknown entity. */ #define UNKNOWN_ENTITY_NAME "unknown_entity" +ir_entity *get_unknown_entity(void) +{ + return irp->unknown_entity; +} + /*-----------------------------------------------------------------*/ /* ENTITY */ /*-----------------------------------------------------------------*/ @@ -62,9 +59,7 @@ ir_entity *get_unknown_entity(void) { return unknown_entity; } static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind, ident *name, ir_type *type, dbg_info *dbgi) { - ir_entity *res; - - res = XMALLOCZ(ir_entity); + ir_entity *res = XMALLOCZ(ir_entity); res->kind = k_entity; res->name = name; @@ -161,7 +156,7 @@ ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi) ident *name = id_unique("label_%u"); ir_type *global_type = get_glob_type(); ir_entity *res - = intern_new_entity(global_type, IR_ENTITY_LABEL, name, firm_code_type, + = intern_new_entity(global_type, IR_ENTITY_LABEL, name, get_code_type(), dbgi); res->attr.code_attr.label = label; hook_new_entity(res); @@ -285,7 +280,9 @@ void free_entity(ir_entity *ent) assert(ent && ent->kind == k_entity); free_entity_attrs(ent); +#ifdef DEBUG_libfirm ent->kind = k_BAD; +#endif xfree(ent); } @@ -364,7 +361,7 @@ void set_entity_type(ir_entity *ent, ir_type *type) assert(!is_Method_type(type)); break; case IR_ENTITY_LABEL: - assert(type == firm_code_type); + assert(type == get_code_type()); break; case IR_ENTITY_COMPOUND_MEMBER: break; @@ -1079,26 +1076,19 @@ int entity_has_definition(const ir_entity *entity) || entity_has_compound_ent_values(entity); } -void ir_init_entity(void) +void ir_init_entity(ir_prog *irp) { ident *id = new_id_from_str(UNKNOWN_ENTITY_NAME); - - assert(firm_unknown_type && "Call init_type() before firm_init_entity()!"); - assert(!unknown_entity && "Call firm_init_entity() only once!"); - - unknown_entity = intern_new_entity(NULL, IR_ENTITY_UNKNOWN, id, - firm_unknown_type, NULL); - set_entity_visibility(unknown_entity, ir_visibility_external); - set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity)); - hook_new_entity(unknown_entity); + irp->unknown_entity = intern_new_entity(NULL, IR_ENTITY_UNKNOWN, id, + irp->unknown_type, NULL); + set_entity_visibility(irp->unknown_entity, ir_visibility_external); + set_entity_ld_ident(irp->unknown_entity, id); + hook_new_entity(irp->unknown_entity); } -void ir_finish_entity(void) +void ir_finish_entity(ir_prog *irp) { - if (unknown_entity != NULL) { - free_entity(unknown_entity); - unknown_entity = NULL; - } + free_entity(irp->unknown_entity); } ir_allocation get_entity_allocation(const ir_entity *entity) diff --git a/ir/tr/entity_t.h b/ir/tr/entity_t.h index 120679f1f..e8b6d9d90 100644 --- a/ir/tr/entity_t.h +++ b/ir/tr/entity_t.h @@ -181,9 +181,9 @@ struct ir_entity { }; /** Initialize the entity module. */ -void ir_init_entity(void); +void ir_init_entity(ir_prog *irp); /** Cleanup entity module */ -void ir_finish_entity(void); +void ir_finish_entity(ir_prog *irp); /** * Creates an entity corresponding to the start address of a basic block @@ -359,7 +359,7 @@ static inline void _set_entity_link(ir_entity *ent, void *l) static inline ir_graph *_get_entity_irg(const ir_entity *ent) { assert(ent && ent->kind == k_entity); - if (!is_Method_type(ent->type) || ent == unknown_entity) { + if (!is_Method_type(ent->type) || is_unknown_entity(ent)) { return NULL; } diff --git a/ir/tr/type.c b/ir/tr/type.c index 429c01451..f28e687bd 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -59,56 +59,45 @@ #include "entity_t.h" #include "error.h" #include "dbginfo.h" +#include "irprog_t.h" #include "array.h" -ir_type *firm_none_type; ir_type *get_none_type(void) { - return firm_none_type; + return irp->none_type; } -ir_type *firm_code_type; ir_type *get_code_type(void) { - return firm_code_type; + return irp->code_type; } -ir_type *firm_unknown_type; ir_type *get_unknown_type(void) { - return firm_unknown_type; + return irp->unknown_type; } -void ir_init_type(void) +void ir_init_type(ir_prog *irp) { /* construct none and unknown type. */ - firm_none_type = new_type(tpop_none, mode_BAD, NULL); - set_type_size_bytes(firm_none_type, 0); - set_type_state (firm_none_type, layout_fixed); + irp->none_type = new_type(tpop_none, mode_BAD, NULL); + set_type_size_bytes(irp->none_type, 0); + set_type_state (irp->none_type, layout_fixed); - firm_code_type = new_type(tpop_code, mode_ANY, NULL); - set_type_state(firm_code_type, layout_fixed); + irp->code_type = new_type(tpop_code, mode_ANY, NULL); + set_type_state(irp->code_type, layout_fixed); - firm_unknown_type = new_type(tpop_unknown, mode_ANY, NULL); - set_type_size_bytes(firm_unknown_type, 0); - set_type_state (firm_unknown_type, layout_fixed); + irp->unknown_type = new_type(tpop_unknown, mode_ANY, NULL); + set_type_size_bytes(irp->unknown_type, 0); + set_type_state (irp->unknown_type, layout_fixed); } -void ir_finish_type(void) +void ir_finish_type(ir_prog *irp) { - if (firm_none_type != NULL) { - free_type(firm_none_type); - firm_none_type = NULL; - } - if (firm_code_type != NULL) { - free_type(firm_code_type); - firm_code_type = NULL; - } - if (firm_unknown_type != NULL) { - free_type(firm_unknown_type); - firm_unknown_type = NULL; - } + /** nothing todo. (The none, code, unknown types are in the global type list + * and freed there */ + (void)irp; } ir_visited_t firm_type_visited; @@ -160,9 +149,6 @@ void free_type(ir_type *tp) { const tp_op *op = get_type_tpop(tp); - if ((get_type_tpop(tp) == tpop_none) || (get_type_tpop(tp) == tpop_unknown) - || (get_type_tpop(tp) == tpop_code)) - return; /* Remove from list of all types */ remove_irp_type(tp); /* Free the attributes of the type. */ @@ -171,7 +157,9 @@ void free_type(ir_type *tp) if (op->ops.free_auto_entities) op->ops.free_auto_entities(tp); /* And now the type itself... */ +#ifdef DEBUG_libfirm tp->kind = k_BAD; +#endif free(tp); } @@ -1821,11 +1809,10 @@ ir_type *find_pointer_type_to_type(ir_type *tp) if (is_Pointer_type(found) && get_pointer_points_to_type(found) == tp) return (found); } - return firm_unknown_type; + return get_unknown_type(); } - ir_type *new_d_type_primitive(ir_mode *mode, type_dbg_info *db) { ir_type *res = new_type(type_primitive, mode, db); diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index ba5f2a251..19685bde2 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -236,10 +236,10 @@ int get_class_dfn(const ir_type *clss); void add_compound_member(ir_type *compound, ir_entity *entity); /** Initialize the type module. */ -void ir_init_type(void); +void ir_init_type(ir_prog *irp); /** free internal datastructures of type module */ -void ir_finish_type(void); +void ir_finish_type(ir_prog *irp); /** Clone an existing method type. * -- 2.20.1