X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firmemory.c;h=77e71c3d7602e47dac36a5adfe876b7c63088d59;hb=0cc8bfc863da28d3799e9eca1d1765d564b6e573;hp=8bce1aafd35cdb83189ad1fd3f7f12cc7d87f323;hpb=cae1b4e015e08b55293b80cc988f00516f6c0790;p=libfirm diff --git a/ir/ana/irmemory.c b/ir/ana/irmemory.c index 8bce1aafd..77e71c3d7 100644 --- a/ir/ana/irmemory.c +++ b/ir/ana/irmemory.c @@ -31,6 +31,7 @@ #include #include +#include "adt/pmap.h" #include "irnode_t.h" #include "irgraph_t.h" #include "irprog_t.h" @@ -44,9 +45,11 @@ #include "irprintf.h" #include "debug.h" #include "error.h" +#include "typerep.h" /** The debug handle. */ DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;) +DEBUG_ONLY(static firm_dbg_module_t *dbgcall = NULL;) /** The source language specific language disambiguator function. */ static DISAMBIGUATOR_FUNC language_disambuigator = NULL; @@ -770,7 +773,7 @@ static int is_hidden_cast(ir_mode *mode, ir_mode *ent_mode) { } /* is_hidden_cast */ /** - * Determine the usage state of a node (or it's successor Sels). + * Determine the usage state of a node (or its successor Sels). * * @param irn the node */ @@ -850,13 +853,36 @@ static ir_entity_usage determine_entity_usage(const ir_node *irn, ir_entity *ent } break; -#if 0 - case iro_Phi: - /* TODO implement marker algo */ -#endif + /* skip identities */ + case iro_Id: + res |= determine_entity_usage(succ, entity); + break; + + /* skip tuples */ + case iro_Tuple: { + int input_nr; + for (input_nr = get_Tuple_n_preds(succ) - 1; input_nr >= 0; + --input_nr) { + ir_node *pred = get_Tuple_pred(succ, input_nr); + if (pred == irn) { + int k; + /* we found one input */ + for (k = get_irn_n_outs(succ) - 1; k >= 0; --k) { + ir_node *proj = get_irn_out(succ, k); + + if (is_Proj(proj) && get_Proj_proj(proj) == input_nr) { + res |= determine_entity_usage(proj, entity); + break; + } + } + } + } + break; + } default: - /* another op, we don't know anything */ + /* another op, we don't know anything (we could do more advanced + * things like a dataflow analysis here) */ res |= ir_usage_unknown; break; } @@ -928,38 +954,42 @@ static void init_entity_usage(ir_type * tp) { /* We have to be conservative: All external visible entities are unknown */ for (i = get_compound_n_members(tp) - 1; i >= 0; --i) { - ir_entity *entity = get_compound_member(tp, i); - ir_entity_usage flags = 0; + ir_entity *ent = get_compound_member(tp, i); + ir_entity_usage flags = ir_usage_none; + ir_visibility vis = get_entity_visibility(ent); - if (get_entity_visibility(entity) == visibility_external_visible || - get_entity_visibility(entity) == visibility_external_allocated || - get_entity_stickyness(entity) == stickyness_sticky) { + if (vis == visibility_external_visible || + vis == visibility_external_allocated || + get_entity_stickyness(ent) == stickyness_sticky) { flags |= ir_usage_unknown; } - - set_entity_usage(entity, flags); + set_entity_usage(ent, flags); } } +/** + * Mark all entities used in the initializer as unknown usage. + * + * @param initializer the initializer to check + */ static void check_initializer_nodes(ir_initializer_t *initializer) { - switch (initializer->kind) { - case IR_INITIALIZER_CONST: { - ir_node *n = initializer->consti.value; + unsigned i; + ir_node *n; + switch (initializer->kind) { + case IR_INITIALIZER_CONST: /* let's check if it's an address */ + n = initializer->consti.value; if (is_Global(n)) { ir_entity *ent = get_Global_entity(n); set_entity_usage(ent, ir_usage_unknown); } return; - } case IR_INITIALIZER_TARVAL: case IR_INITIALIZER_NULL: return; - case IR_INITIALIZER_COMPOUND: { - size_t i; - + case IR_INITIALIZER_COMPOUND: for (i = 0; i < initializer->compound.n_initializers; ++i) { ir_initializer_t *sub_initializer = initializer->compound.initializers[i]; @@ -967,12 +997,12 @@ static void check_initializer_nodes(ir_initializer_t *initializer) } return; } - } panic("invalid initializer found"); } /* check_initializer_nodes */ /** - * Mark all entities used in the initializer for the given entity as address taken. + * Mark all entities used in the initializer for the given entity as unknown + * usage. * * @param ent the entity */ @@ -1013,7 +1043,7 @@ static void check_initializer(ir_entity *ent) { /** - * Mark all entities used in initializers as address taken. + * Mark all entities used in initializers as unknown usage. * * @param tp a compound type */ @@ -1041,7 +1071,7 @@ static void print_entity_usage_flags(ir_type *tp) { if (flags == 0) continue; - ir_printf("%+F:"); + ir_printf("%+F:", ent); if (flags & ir_usage_address_taken) printf(" address_taken"); if (flags & ir_usage_read) @@ -1134,14 +1164,10 @@ void assure_irp_globals_entity_usage_computed(void) { void firm_init_memory_disambiguator(void) { FIRM_DBG_REGISTER(dbg, "firm.ana.irmemory"); + FIRM_DBG_REGISTER(dbgcall, "firm.opt.cc"); } -#include -#include "typerep.h" - -DEBUG_ONLY(static firm_dbg_module_t *dbgcall = NULL;) - /** Maps method types to cloned method types. */ static pmap *mtp_map; @@ -1198,8 +1224,6 @@ void mark_private_methods(void) { int i; int changed = 0; - FIRM_DBG_REGISTER(dbgcall, "firm.opt.cc"); - assure_irp_globals_entity_usage_computed(); mtp_map = pmap_create();