X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftypewalk.c;h=7466b6ecf49b802c273c2a079a9f02dcc7cf6cab;hb=ca42e4ac671c49f7ba8e9dfffd805abf49b2c733;hp=363fddbd688163587e74f069399ed95385ed7d56;hpb=e84184056559e90f2dffc7f7648f40705864e088;p=libfirm diff --git a/ir/tr/typewalk.c b/ir/tr/typewalk.c index 363fddbd6..7466b6ecf 100644 --- a/ir/tr/typewalk.c +++ b/ir/tr/typewalk.c @@ -22,7 +22,7 @@ * @brief Functionality to modify the type graph. * @author Goetz Lindenmaier * @version $Id$ - * @summary + * @brief * * Traverse the type information. The walker walks the whole ir graph * to find the distinct type trees in the type graph forest. @@ -60,7 +60,7 @@ static void walk_initializer(ir_initializer_t *initializer, type_walk_func *pre, type_walk_func *post, void *env) { - switch(initializer->kind) { + switch (initializer->kind) { case IR_INITIALIZER_CONST: irn_type_walker(initializer->consti.value, pre, post, env); return; @@ -70,7 +70,7 @@ static void walk_initializer(ir_initializer_t *initializer, case IR_INITIALIZER_COMPOUND: { size_t i; - for(i = 0; i < initializer->compound.n_initializers; ++i) { + for (i = 0; i < initializer->compound.n_initializers; ++i) { ir_initializer_t *subinitializer = initializer->compound.initializers[i]; walk_initializer(subinitializer, pre, post, env); @@ -102,11 +102,13 @@ static void do_type_walk(type_or_ent tore, ent = tore.ent; if (entity_visited(ent)) return; + mark_entity_visited(ent); break; case k_type: - tp = skip_tid(tore.typ); + tp = tore.typ; if (type_visited(tp)) return; + mark_type_visited(tp); break; default: break; @@ -119,32 +121,24 @@ static void do_type_walk(type_or_ent tore, /* iterate */ switch (get_kind(tore.ent)) { case k_entity: - mark_entity_visited(ent); cont.typ = get_entity_owner(ent); do_type_walk(cont, pre, post, env); cont.typ = get_entity_type(ent); do_type_walk(cont, pre, post, env); - if (get_entity_variability(ent) != variability_uninitialized) { - /* walk over the value types */ - if (ent->has_initializer) { - walk_initializer(ent->attr.initializer, pre, post, env); - } else if (is_atomic_entity(ent)) { - n = get_atomic_ent_value(ent); + /* walk over the value types */ + if (ent->initializer != NULL) { + walk_initializer(ent->initializer, pre, post, env); + } else if (entity_has_compound_ent_values(ent)) { + n_mem = get_compound_ent_n_values(ent); + for (i = 0; i < n_mem; ++i) { + n = get_compound_ent_value(ent, i); irn_type_walker(n, pre, post, env); - } else { - n_mem = get_compound_ent_n_values(ent); - for (i = 0; i < n_mem; ++i) { - n = get_compound_ent_value(ent, i); - irn_type_walker(n, pre, post, env); - } } } break; case k_type: - mark_type_visited(tp); switch (get_type_tpop_code(tp)) { - case tpo_class: n_types = get_class_n_supertypes(tp); for (i = 0; i < n_types; ++i) { @@ -208,13 +202,13 @@ static void do_type_walk(type_or_ent tore, do_type_walk(cont, pre, post, env); break; + case tpo_code: case tpo_primitive: - case tpo_id: case tpo_none: case tpo_unknown: /* a leave. */ break; - default: + case tpo_uninitialized: assert(0 && "Faulty type"); break; } @@ -249,7 +243,8 @@ static void irn_type_walker( /** Check whether node contains types or entities as an attribute. If so start a walk over that information. */ -static void start_type_walk(ir_node *node, void *ctx) { +static void start_type_walk(ir_node *node, void *ctx) +{ type_walk_env *env = ctx; type_walk_func *pre; type_walk_func *post; @@ -263,10 +258,12 @@ static void start_type_walk(ir_node *node, void *ctx) { } /* walker: walks over all types */ -void type_walk(type_walk_func *pre, type_walk_func *post, void *env) { +void type_walk(type_walk_func *pre, type_walk_func *post, void *env) +{ int i, n_types = get_irp_n_types(); type_or_ent cont; + irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED); inc_master_type_visited(); for (i = 0; i < n_types; ++i) { cont.typ = get_irp_type(i); @@ -274,6 +271,31 @@ void type_walk(type_walk_func *pre, type_walk_func *post, void *env) { } cont.typ = get_glob_type(); do_type_walk(cont, pre, post, env); + irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED); +} + +void type_walk_prog(type_walk_func *pre, type_walk_func *post, void *env) +{ + int i, n_irgs = get_irp_n_irgs(); + type_or_ent cont; + + type_walk(pre, post, env); + + for (i = 0; i < n_irgs; ++i) { + ir_graph *irg = get_irp_irg(i); + cont.typ = get_irg_frame_type(irg); + do_type_walk(cont, pre, post, env); + + cont.typ = get_method_value_param_type(get_entity_type(get_irg_entity(irg))); + if (cont.typ) + do_type_walk(cont, pre, post, env); + } + + for (i = IR_SEGMENT_FIRST; i <= IR_SEGMENT_LAST; ++i) { + cont.typ = get_segment_type((ir_segment_t) i); + if (cont.typ) + do_type_walk(cont, pre, post, env); + } } void type_walk_irg(ir_graph *irg, @@ -302,6 +324,7 @@ void type_walk_irg(ir_graph *irg, Here we initially increase the flag. We only call do_type_walk that does not increase the flag. */ + irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED); inc_master_type_visited(); irg_walk(get_irg_end(irg), start_type_walk, NULL, &type_env); @@ -312,6 +335,7 @@ void type_walk_irg(ir_graph *irg, do_type_walk(cont, pre, post, env); current_ir_graph = rem; + irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED); } static void type_walk_s2s_2(type_or_ent tore, @@ -328,11 +352,6 @@ static void type_walk_s2s_2(type_or_ent tore, if (entity_visited(tore.ent)) return; break; case k_type: - if (type_id == get_type_tpop(tore.typ)) { - cont.typ = skip_tid(tore.typ); - type_walk_s2s_2(cont, pre, post, env); - return; - } if (type_visited(tore.typ)) return; break; default: @@ -356,7 +375,6 @@ static void type_walk_s2s_2(type_or_ent tore, /* execute pre method */ if (pre) pre(tore, env); - tp = skip_tid(tp); n = get_class_n_subtypes(tp); for (i = 0; i < n; ++i) { @@ -376,7 +394,6 @@ static void type_walk_s2s_2(type_or_ent tore, case tpo_enumeration: case tpo_pointer: case tpo_primitive: - case tpo_id: /* dont care */ break; default: @@ -400,6 +417,7 @@ void type_walk_super2sub(type_walk_func *pre, type_or_ent cont; int i, n_types = get_irp_n_types(); + irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED); inc_master_type_visited(); cont.typ = get_glob_type(); type_walk_s2s_2(cont, pre, post, env); @@ -407,15 +425,14 @@ void type_walk_super2sub(type_walk_func *pre, cont.typ = get_irp_type(i); type_walk_s2s_2(cont, pre, post, env); } + irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED); } /*****************************************************************************/ -static void -type_walk_super_2(type_or_ent tore, - type_walk_func *pre, - type_walk_func *post, - void *env) { +static void type_walk_super_2(type_or_ent tore, type_walk_func *pre, + type_walk_func *post, void *env) +{ type_or_ent cont; int i, n; @@ -426,11 +443,6 @@ type_walk_super_2(type_or_ent tore, return; break; case k_type: - if (type_id == get_type_tpop(tore.typ)) { - cont.typ = skip_tid(tore.typ); - type_walk_super_2(cont, pre, post, env); - return; - } if (type_visited(tore.typ)) return; break; @@ -450,7 +462,6 @@ type_walk_super_2(type_or_ent tore, /* execute pre method */ if (pre) pre(tore, env); - tp = skip_tid(tp); n = get_class_n_supertypes(tp); for (i = 0; i < n; ++i) { @@ -470,7 +481,6 @@ type_walk_super_2(type_or_ent tore, case tpo_enumeration: case tpo_pointer: case tpo_primitive: - case tpo_id: /* don't care */ break; default: @@ -487,12 +497,12 @@ type_walk_super_2(type_or_ent tore, } } -void type_walk_super(type_walk_func *pre, - type_walk_func *post, - void *env) { +void type_walk_super(type_walk_func *pre, type_walk_func *post, void *env) +{ int i, n_types = get_irp_n_types(); type_or_ent cont; + irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED); inc_master_type_visited(); cont.typ = get_glob_type(); type_walk_super_2(cont, pre, post, env); @@ -500,16 +510,14 @@ void type_walk_super(type_walk_func *pre, cont.typ = get_irp_type(i); type_walk_super_2(cont, pre, post, env); } + irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED); } /*****************************************************************************/ -static void -class_walk_s2s_2(ir_type *tp, - class_walk_func *pre, - class_walk_func *post, - void *env) +static void class_walk_s2s_2(ir_type *tp, class_walk_func *pre, + class_walk_func *post, void *env) { int i, n; @@ -530,7 +538,6 @@ class_walk_s2s_2(ir_type *tp, if (pre) pre(tp, env); - tp = skip_tid(tp); n = get_class_n_subtypes(tp); for (i = 0; i < n; ++i) { class_walk_s2s_2(get_class_subtype(tp, i), pre, post, env); @@ -547,6 +554,7 @@ void class_walk_super2sub(class_walk_func *pre, int i, n_types = get_irp_n_types(); ir_type *tp; + irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED); inc_master_type_visited(); for (i = 0; i < n_types; i++) { tp = get_irp_type(i); @@ -558,6 +566,7 @@ void class_walk_super2sub(class_walk_func *pre, class_walk_s2s_2(tp, pre, post, env); } } + irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED); } @@ -591,7 +600,6 @@ void walk_types_entities(ir_type *tp, case tpo_enumeration: case tpo_pointer: case tpo_primitive: - case tpo_id: default: break; }