- activated WITH_UNKNOWN
[libfirm] / ir / ana / cgana.c
index d4de512..f0459ca 100644 (file)
@@ -31,9 +31,7 @@
  *  methods that are 'free', i.e., their adress is handled by
  *  the program directly, or they are visible external.
  */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #ifdef HAVE_STRING_H
 # include <string.h>
@@ -50,6 +48,7 @@
 #include "ircons.h"
 #include "irgmod.h"
 #include "iropt.h"
+#include "irtools.h"
 
 #include "irflag_t.h"
 #include "dbginfo_t.h"
 
 #include "irdump.h"
 
-#include "irhooks.h"
-
-
-
 /* unambiguous address used as a mark. */
 static void *MARK = &MARK;
 
@@ -347,7 +342,7 @@ static void free_mark_proj(ir_node * node, long n, eset * set) {
                 * op_Tuple oder ein Knoten, der in "free_ana_walker" behandelt
                 * wird. */
                ir_node * pred = get_Proj_pred(node);
-               if (get_irn_link(pred) != MARK && get_irn_op(pred) == op_Tuple) {
+               if (get_irn_link(pred) != MARK && is_Tuple(pred)) {
                        free_mark_proj(get_Tuple_pred(pred, get_Proj_proj(node)), n, set);
                } else {
                        /* nothing: da in "free_ana_walker" behandelt. */
@@ -490,12 +485,15 @@ static void free_ana_walker(ir_node *node, void *env) {
  *
  * which is sometimes used to anchor functions.
  */
-static void add_method_address_intitialzer(ir_initializer_t *initializer,
-                                           eset *set)
+static void add_method_address_inititializer(ir_initializer_t *initializer,
+                                             eset *set)
 {
+       ir_node *n;
+       size_t  i;
+
        switch (initializer->kind) {
-       case IR_INITIALIZER_CONST: {
-               ir_node *n = initializer->consti.value;
+       case IR_INITIALIZER_CONST:
+               n = initializer->consti.value;
 
                /* let's check if it's the address of a function */
                if (is_Global(n)) {
@@ -505,21 +503,17 @@ static void add_method_address_intitialzer(ir_initializer_t *initializer,
                                eset_insert(set, ent);
                }
                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];
-                       add_method_address_intitialzer(sub_initializer, set);
+                       add_method_address_inititializer(sub_initializer, set);
                }
                return;
        }
-       }
        panic("invalid initializer found");
 }
 
@@ -545,7 +539,7 @@ static void add_method_address(ir_entity *ent, eset *set)
                return;
 
        if (ent->has_initializer) {
-               add_method_address_intitialzer(get_entity_initializer(ent), set);
+               add_method_address_inititializer(get_entity_initializer(ent), set);
        } else if (is_atomic_entity(ent)) {
                tp = get_entity_type(ent);
 
@@ -598,20 +592,19 @@ static ir_entity **get_free_methods(int *length)
        for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
                irg = get_irp_irg(i);
                ent = get_irg_entity(irg);
-               /* insert "external visible" methods. */
                if (get_entity_visibility(ent) != visibility_local) {
+                       /* insert non-local (external) methods. */
                        eset_insert(free_set, ent);
-               }
-               /* insert "sticky" methods. */
-               if (get_entity_stickyness(ent) == stickyness_sticky) {
+               } else if (get_entity_stickyness(ent) == stickyness_sticky) {
+                       /* insert "sticky" methods. */
                        eset_insert(free_set, ent);
                }
 
-               set_using_irn_link(irg);
-               /* Find all method entities that gets "visible" trough this graphs,
+               ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
+               /* Find all method entities that gets "visible" through this graphs,
                 * for instance because their address is stored. */
-               irg_walk_graph(irg, NULL, free_ana_walker, free_set);
-               clear_using_irn_link(irg);
+               irg_walk_graph(irg, firm_clear_link, free_ana_walker, free_set);
+               ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
        }
 
        /* insert all methods that are used in global variables initializers */
@@ -633,7 +626,7 @@ static ir_entity **get_free_methods(int *length)
 
        /* Finally, transform the set into an array. */
        *length = eset_count(free_set);
-       arr = xmalloc(sizeof(ir_entity *) * (*length));
+       arr = XMALLOCN(ir_entity*, *length);
        for (i = 0, ent = eset_first(free_set); ent; ent = eset_next(free_set)) {
                arr[i++] = ent;
        }
@@ -743,13 +736,6 @@ static void callee_ana_node(ir_node *node, eset *methods) {
                callee_ana_node(get_Mux_true(node), methods);
                break;
 
-       case iro_Psi:
-               for (i = get_Psi_n_conds(node) - 1; i >= 0; --i) {
-                       callee_ana_node(get_Psi_val(node, i), methods);
-               }
-               callee_ana_node(get_Psi_default(node), methods);
-               break;
-
        case iro_Id:
                callee_ana_node(get_Id_pred(node), methods);
                break;