becopyopt: Remove the unnecessary attribute name from struct copy_opt_t.
[libfirm] / ir / tr / typewalk.c
index 1b64e9b..c510a4e 100644 (file)
@@ -1,28 +1,13 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
- * @file    typewalk.c
+ * @file
  * @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.
@@ -42,6 +27,7 @@
 #include "irnode_t.h"
 #include "irgwalk.h"
 #include "error.h"
+#include "ircons.h"
 
 /**
  * The walker environment
@@ -60,7 +46,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 +56,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);
@@ -90,10 +76,9 @@ static void do_type_walk(type_or_ent tore,
                          type_walk_func *post,
                          void *env)
 {
-       int         i, n_types, n_mem;
+       size_t      i, n_types, n_mem;
        ir_entity   *ent = NULL;
        ir_type     *tp = NULL;
-       ir_node     *n;
        type_or_ent cont;
 
        /* marked? */
@@ -102,11 +87,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 +106,18 @@ 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);
-                               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);
-                               }
-                       }
+               /* walk over the value types */
+               if (ent->initializer != NULL) {
+                       walk_initializer(ent->initializer, 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 +181,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,8 +222,9 @@ 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) {
-       type_walk_env *env = ctx;
+static void start_type_walk(ir_node *node, void *ctx)
+{
+       type_walk_env *env = (type_walk_env*)ctx;
        type_walk_func *pre;
        type_walk_func *post;
        void *envi;
@@ -262,11 +236,12 @@ static void start_type_walk(ir_node *node, void *ctx) {
        irn_type_walker(node, pre, post, envi);
 }
 
-/* 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)
+{
+       size_t      i, n_types = get_irp_n_types();
        type_or_ent cont;
 
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_VISITED);
        inc_master_type_visited();
        for (i = 0; i < n_types; ++i) {
                cont.typ = get_irp_type(i);
@@ -274,19 +249,7 @@ 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);
-}
-
-void type_walk_plus_frames(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);
-       }
+       irp_free_resources(irp, IRP_RESOURCE_TYPE_VISITED);
 }
 
 void type_walk_irg(ir_graph *irg,
@@ -315,6 +278,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, IRP_RESOURCE_TYPE_VISITED);
        inc_master_type_visited();
        irg_walk(get_irg_end(irg), start_type_walk, NULL, &type_env);
 
@@ -325,6 +289,7 @@ void type_walk_irg(ir_graph *irg,
        do_type_walk(cont, pre, post, env);
 
        current_ir_graph = rem;
+       irp_free_resources(irp, IRP_RESOURCE_TYPE_VISITED);
 }
 
 static void type_walk_s2s_2(type_or_ent tore,
@@ -333,7 +298,6 @@ static void type_walk_s2s_2(type_or_ent tore,
                             void *env)
 {
        type_or_ent cont;
-       int         i, n;
 
        /* marked? */
        switch (get_kind(tore.ent)) {
@@ -341,11 +305,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:
@@ -361,6 +320,8 @@ static void type_walk_s2s_2(type_or_ent tore,
                        switch (get_type_tpop_code(tp)) {
                        case tpo_class:
                                {
+                                       size_t i, n;
+
                                        n = get_class_n_supertypes(tp);
                                        for (i = 0; i < n; ++i) {
                                                cont.typ = get_class_supertype(tp, i);
@@ -369,7 +330,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) {
@@ -389,7 +349,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:
@@ -411,8 +370,9 @@ void type_walk_super2sub(type_walk_func *pre,
                          void *env)
 {
        type_or_ent cont;
-       int         i, n_types = get_irp_n_types();
+       size_t      i, n_types = get_irp_n_types();
 
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_VISITED);
        inc_master_type_visited();
        cont.typ = get_glob_type();
        type_walk_s2s_2(cont, pre, post, env);
@@ -420,17 +380,15 @@ 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, IRP_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;
 
        /* marked? */
        switch (get_kind(tore.ent)) {
@@ -439,11 +397,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;
@@ -460,10 +413,11 @@ type_walk_super_2(type_or_ent tore,
                        switch (get_type_tpop_code(tp)) {
                        case tpo_class:
                                {
+                                       size_t i, n;
+
                                        /* execute pre method */
                                        if (pre)
                                                pre(tore, env);
-                                       tp = skip_tid(tp);
 
                                        n = get_class_n_supertypes(tp);
                                        for (i = 0; i < n; ++i) {
@@ -483,7 +437,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:
@@ -500,12 +453,12 @@ type_walk_super_2(type_or_ent tore,
        }
 }
 
-void type_walk_super(type_walk_func *pre,
-                     type_walk_func *post,
-                     void *env) {
-       int         i, n_types = get_irp_n_types();
+void type_walk_super(type_walk_func *pre, type_walk_func *post, void *env)
+{
+       size_t      i, n_types = get_irp_n_types();
        type_or_ent cont;
 
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_VISITED);
        inc_master_type_visited();
        cont.typ = get_glob_type();
        type_walk_super_2(cont, pre, post, env);
@@ -513,23 +466,20 @@ 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, IRP_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;
+       size_t i, n;
 
        /* marked? */
        if (type_visited(tp)) return;
 
-       assert(is_Class_type(tp));
        /* Assure all supertypes are visited before */
        n = get_class_n_supertypes(tp);
        for (i = 0; i < n; ++i) {
@@ -543,7 +493,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);
@@ -557,29 +506,30 @@ void class_walk_super2sub(class_walk_func *pre,
                           class_walk_func *post,
                           void *env)
 {
-       int i, n_types = get_irp_n_types();
+       size_t i, n_types = get_irp_n_types();
        ir_type *tp;
 
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_VISITED);
        inc_master_type_visited();
        for (i = 0; i < n_types; i++) {
                tp = get_irp_type(i);
                if (is_Class_type(tp) &&
                    (get_class_n_supertypes(tp) == 0) &&
-                   type_not_visited(tp)) {
-                       assert(! is_frame_type(tp));
-                       assert(tp != get_glob_type());
+                   type_not_visited(tp) &&
+                   (! is_frame_type(tp)) &&
+                   (tp != get_glob_type())) {
                        class_walk_s2s_2(tp, pre, post, env);
                }
        }
+       irp_free_resources(irp, IRP_RESOURCE_TYPE_VISITED);
 }
 
 
-/* Walks over all entities in the type */
 void walk_types_entities(ir_type *tp,
                          entity_walk_func *doit,
                          void *env)
 {
-       int i, n;
+       size_t i, n;
 
        switch (get_type_tpop_code(tp)) {
        case tpo_class:
@@ -604,7 +554,6 @@ void walk_types_entities(ir_type *tp,
        case tpo_enumeration:
        case tpo_pointer:
        case tpo_primitive:
-       case tpo_id:
        default:
                break;
        }