/*
- * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
* @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.
* - execute the pre function before recursion
* - execute the post function after recursion
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
+#include "config.h"
+#include <stdlib.h>
#include <stdio.h>
#include "entity_t.h"
#include "irgraph_t.h"
#include "irnode_t.h"
#include "irgwalk.h"
+#include "error.h"
/**
* The walker environment
static void irn_type_walker(
ir_node *node, type_walk_func *pre, type_walk_func *post, void *env);
+static void walk_initializer(ir_initializer_t *initializer,
+ type_walk_func *pre, type_walk_func *post,
+ void *env)
+{
+ switch (initializer->kind) {
+ case IR_INITIALIZER_CONST:
+ irn_type_walker(initializer->consti.value, pre, post, env);
+ return;
+ case IR_INITIALIZER_TARVAL:
+ case IR_INITIALIZER_NULL:
+ return;
+
+ case IR_INITIALIZER_COMPOUND: {
+ size_t i;
+ for (i = 0; i < initializer->compound.n_initializers; ++i) {
+ ir_initializer_t *subinitializer
+ = initializer->compound.initializers[i];
+ walk_initializer(subinitializer, pre, post, env);
+ }
+ return;
+ }
+ }
+ panic("invalid initializer found");
+}
+
/**
* Main walker: walks over all used types/entities of a
* type entity.
*/
-static void do_type_walk(type_or_ent *tore,
+static void do_type_walk(type_or_ent tore,
type_walk_func *pre,
type_walk_func *post,
void *env)
{
- int i, n_types, n_mem;
- ir_entity *ent = NULL;
- ir_type *tp = NULL;
- ir_node *n;
+ int i, n_types, n_mem;
+ ir_entity *ent = NULL;
+ ir_type *tp = NULL;
+ ir_node *n;
+ type_or_ent cont;
/* marked? */
- switch (get_kind(tore)) {
+ switch (get_kind(tore.ent)) {
case k_entity:
- ent = (ir_entity *)tore;
- if (entity_visited(ent)) return;
+ ent = tore.ent;
+ if (entity_visited(ent))
+ return;
+ mark_entity_visited(ent);
break;
case k_type:
- tp = skip_tid((ir_type *)tore);
- if (type_visited(tp)) return;
+ tp = tore.typ;
+ if (type_visited(tp))
+ return;
+ mark_type_visited(tp);
break;
default:
break;
pre(tore, env);
/* iterate */
- switch (get_kind(tore)) {
+ switch (get_kind(tore.ent)) {
case k_entity:
- mark_entity_visited(ent);
- do_type_walk((type_or_ent *)get_entity_owner(ent), pre, post, env);
- do_type_walk((type_or_ent *)get_entity_type(ent), pre, post, env);
-
- if (get_entity_variability(ent) != variability_uninitialized) {
- /* walk over the value types */
- if (is_atomic_entity(ent)) {
- n = get_atomic_ent_value(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);
+
+ /* 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)
- do_type_walk((type_or_ent *)get_class_supertype(tp, i), pre, post, env);
-
+ for (i = 0; i < n_types; ++i) {
+ cont.typ = get_class_supertype(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
n_mem = get_class_n_members(tp);
- for (i = 0; i < n_mem; ++i)
- do_type_walk((type_or_ent *)get_class_member(tp, i), pre, post, env);
-
+ for (i = 0; i < n_mem; ++i) {
+ cont.ent = get_class_member(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
n_types = get_class_n_subtypes(tp);
- for (i = 0; i < n_types; ++i)
- do_type_walk((type_or_ent *)get_class_subtype(tp, i), pre, post, env);
+ for (i = 0; i < n_types; ++i) {
+ cont.typ = get_class_subtype(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
break;
case tpo_struct:
n_mem = get_struct_n_members(tp);
- for (i = 0; i < n_mem; ++i)
- do_type_walk((type_or_ent *)get_struct_member(tp, i), pre, post, env);
+ for (i = 0; i < n_mem; ++i) {
+ cont.ent = get_struct_member(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
break;
case tpo_method:
n_mem = get_method_n_params(tp);
- for (i = 0; i < n_mem; ++i)
- do_type_walk((type_or_ent *)get_method_param_type(tp, i), pre, post, env);
-
+ for (i = 0; i < n_mem; ++i) {
+ cont.typ = get_method_param_type(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
n_mem = get_method_n_ress(tp);
- for (i = 0; i < n_mem; ++i)
- do_type_walk((type_or_ent *)get_method_res_type(tp, i), pre, post, env);
+ for (i = 0; i < n_mem; ++i) {
+ cont.typ = get_method_res_type(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
break;
case tpo_union:
n_mem = get_union_n_members(tp);
- for (i = 0; i < n_mem; ++i)
- do_type_walk((type_or_ent *)get_union_member(tp, i), pre, post, env);
+ for (i = 0; i < n_mem; ++i) {
+ cont.ent = get_union_member(tp, i);
+ do_type_walk(cont, pre, post, env);
+ }
break;
case tpo_array:
- do_type_walk((type_or_ent *)get_array_element_type(tp),
- pre, post, env);
- do_type_walk((type_or_ent *)get_array_element_entity(tp),
- pre, post, env);
+ cont.typ = get_array_element_type(tp);
+ do_type_walk(cont, pre, post, env);
+ cont.ent = get_array_element_entity(tp);
+ do_type_walk(cont, pre, post, env);
break;
case tpo_enumeration:
break;
case tpo_pointer:
- do_type_walk((type_or_ent *)get_pointer_points_to_type(tp),
- pre, post, env);
+ cont.typ = get_pointer_points_to_type(tp);
+ 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;
}
/* execute post method */
if (post)
post(tore, env);
-
- return;
}
/** Check whether node contains types or entities as an attribute.
static void irn_type_walker(
ir_node *node, type_walk_func *pre, type_walk_func *post, void *env)
{
- ir_entity *ent;
- ir_type *tp;
+ type_or_ent cont;
assert(node);
- ent = get_irn_entity_attr(node);
- if (ent)
- do_type_walk((type_or_ent *)ent, pre, post, env);
- tp = get_irn_type_attr(node);
- if (tp)
- do_type_walk((type_or_ent *)tp, pre, post, env);
+ cont.ent = get_irn_entity_attr(node);
+ if (cont.ent)
+ do_type_walk(cont, pre, post, env);
+ cont.typ = get_irn_type_attr(node);
+ if (cont.typ)
+ do_type_walk(cont, pre, post, env);
}
/** 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;
}
/* walker: walks over all types */
-void type_walk(type_walk_func *pre, type_walk_func *post, void *env) {
- int i, n_types = get_irp_n_types();
+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) {
- do_type_walk((type_or_ent *)get_irp_type(i), pre, post, env);
+ cont.typ = get_irp_type(i);
+ do_type_walk(cont, pre, post, 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);
}
- do_type_walk((type_or_ent *)get_glob_type(), pre, post, env);
}
void type_walk_irg(ir_graph *irg,
/* this is needed to pass the parameters to the walker that actually
walks the type information */
type_walk_env type_env;
+ type_or_ent cont;
type_env.pre = pre;
type_env.post = post;
current_ir_graph = irg;
- /* We walk over the irg to find all irnodes that contain an attribute
+ /* We walk over the irg to find all IR-nodes that contain an attribute
with type information. If we find one we call a type walker to
touch the reachable type information.
- The same type can be referenced by several irnodes. To avoid
+ The same type can be referenced by several IR-nodes. To avoid
repeated visits of the same type node we must decrease the
type visited flag for each walk. This is done in start_type_walk().
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);
- do_type_walk((type_or_ent *)get_irg_entity(irg), pre, post, env);
+ cont.ent = get_irg_entity(irg);
+ do_type_walk(cont, pre, post, env);
- do_type_walk((type_or_ent *)get_irg_frame_type(irg), pre, post, env);
+ cont.typ = get_irg_frame_type(irg);
+ do_type_walk(cont, pre, post, env);
current_ir_graph = rem;
- return;
+ irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED);
}
-static void type_walk_s2s_2(type_or_ent *tore,
+static void type_walk_s2s_2(type_or_ent tore,
type_walk_func *pre,
type_walk_func *post,
void *env)
{
- int i, n;
+ type_or_ent cont;
+ int i, n;
/* marked? */
- switch (get_kind(tore)) {
+ switch (get_kind(tore.ent)) {
case k_entity:
- if (entity_visited((ir_entity *)tore)) return;
+ if (entity_visited(tore.ent)) return;
break;
case k_type:
- if (type_id == get_type_tpop((ir_type*)tore)) {
- type_walk_s2s_2((type_or_ent *)skip_tid((ir_type *)tore), pre, post, env);
- return;
- }
- if (type_visited((ir_type *)tore)) return;
+ if (type_visited(tore.typ)) return;
break;
default:
break;
}
/* iterate */
- switch (get_kind(tore)) {
+ switch (get_kind(tore.typ)) {
case k_type:
{
- ir_type *tp = (ir_type *)tore;
+ ir_type *tp = tore.typ;
mark_type_visited(tp);
switch (get_type_tpop_code(tp)) {
case tpo_class:
{
n = get_class_n_supertypes(tp);
for (i = 0; i < n; ++i) {
- type_walk_s2s_2((type_or_ent *)get_class_supertype(tp, i), pre, post, env);
+ cont.typ = get_class_supertype(tp, i);
+ type_walk_s2s_2(cont, pre, post, env);
}
/* execute pre method */
if (pre)
pre(tore, env);
- tp = skip_tid((ir_type*)tore);
n = get_class_n_subtypes(tp);
for (i = 0; i < n; ++i) {
- type_walk_s2s_2((type_or_ent *)get_class_subtype(tp, i), pre, post, env);
+ cont.typ = get_class_subtype(tp, i);
+ type_walk_s2s_2(cont, pre, post, env);
}
/* execute post method */
case tpo_enumeration:
case tpo_pointer:
case tpo_primitive:
- case tpo_id:
/* dont care */
break;
default:
}
} break; /* end case k_type */
case k_entity:
- /* dont care */
+ /* don't care */
break;
default:
printf(" *** Faulty type or entity! \n");
break;
}
- return;
}
void type_walk_super2sub(type_walk_func *pre,
type_walk_func *post,
void *env)
{
- int i, n_types = get_irp_n_types();
- ir_type *tp;
+ type_or_ent cont;
+ int i, n_types = get_irp_n_types();
+ irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED);
inc_master_type_visited();
- type_walk_s2s_2((type_or_ent *)get_glob_type(), pre, post, env);
+ cont.typ = get_glob_type();
+ type_walk_s2s_2(cont, pre, post, env);
for (i = 0; i < n_types; ++i) {
- tp = get_irp_type(i);
- type_walk_s2s_2((type_or_ent *)tp, pre, post, env);
+ 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) {
- int i, n;
+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;
/* marked? */
- switch (get_kind(tore)) {
+ switch (get_kind(tore.ent)) {
case k_entity:
- if (entity_visited((ir_entity *)tore)) return;
+ if (entity_visited(tore.ent))
+ return;
break;
case k_type:
- if (type_id == get_type_tpop((ir_type*)tore)) {
- type_walk_super_2((type_or_ent *)skip_tid((ir_type *)tore), pre, post, env);
+ if (type_visited(tore.typ))
return;
- }
- if (type_visited((ir_type *)tore)) return;
break;
default:
break;
}
/* iterate */
- switch (get_kind(tore)) {
+ switch (get_kind(tore.typ)) {
case k_type:
{
- ir_type *tp = (ir_type *)tore;
+ ir_type *tp = tore.typ;
mark_type_visited(tp);
switch (get_type_tpop_code(tp)) {
case tpo_class:
/* execute pre method */
if (pre)
pre(tore, env);
- tp = skip_tid((ir_type*)tore);
n = get_class_n_supertypes(tp);
for (i = 0; i < n; ++i) {
- type_walk_super_2((type_or_ent *)get_class_supertype(tp, i), pre,
- post, env);
+ cont.typ = get_class_supertype(tp, i);
+ type_walk_super_2(cont, pre, post, env);
}
/* execute post method */
case tpo_enumeration:
case tpo_pointer:
case tpo_primitive:
- case tpo_id:
- /* dont care */
+ /* don't care */
break;
default:
printf(" *** Faulty type! \n");
}
} break; /* end case k_type */
case k_entity:
- /* dont care */
+ /* don't care */
break;
default:
printf(" *** Faulty type or entity! \n");
break;
}
- return;
}
-void type_walk_super(type_walk_func *pre,
- type_walk_func *post,
- void *env) {
- int i, n_types = get_irp_n_types();
- ir_type *tp;
+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();
- type_walk_super_2((type_or_ent *)get_glob_type(), pre, post, env);
+ cont.typ = get_glob_type();
+ type_walk_super_2(cont, pre, post, env);
for (i = 0; i < n_types; ++i) {
- tp = get_irp_type(i);
- type_walk_super_2((type_or_ent *)tp, pre, post, env);
+ 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;
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);
/* execute post method */
if (post)
post(tp, env);
-
- return;
}
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);
class_walk_s2s_2(tp, pre, post, env);
}
}
+ irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED);
}
case tpo_enumeration:
case tpo_pointer:
case tpo_primitive:
- case tpo_id:
default:
break;
}