becopyheur4: Clean up co_mst_irn_init().
[libfirm] / ir / opt / garbage_collect.c
index d065773..15bf04d 100644 (file)
@@ -1,27 +1,12 @@
 /*
- * Copyright (C) 2010 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
  * @brief    Removal of unreachable methods.
  * @author   Matthias Braun
- * @version  $Id$
  */
 #include "config.h"
 
@@ -36,7 +21,7 @@
 #include "error.h"
 #include "debug.h"
 
-DEBUG_ONLY(static firm_dbg_module_t *dbg);
+DEBUG_ONLY(static firm_dbg_module_t *dbg;)
 
 static void visit_entity(ir_entity *entity);
 
@@ -65,7 +50,6 @@ static void start_visit_node(ir_node *node)
        if (get_irg_visited(irg) < get_max_irg_visited()) {
                set_irg_visited(irg, get_max_irg_visited());
        }
-       current_ir_graph = irg;
        irg_walk_2(node, visit_node, NULL, NULL);
 }
 
@@ -81,7 +65,7 @@ static void visit_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];
                        visit_initializer(subinitializer);
@@ -102,13 +86,6 @@ static void visit_entity(ir_entity *entity)
 
        if (entity->initializer != NULL) {
                visit_initializer(entity->initializer);
-       }  else if (entity_has_compound_ent_values(entity)) {
-               int i;
-               int n_members = get_compound_ent_n_values(entity);
-               for (i = 0; i < n_members; ++i) {
-                       ir_node *node = get_compound_ent_value(entity, i);
-                       start_visit_node(node);
-               }
        }
 
        irg = get_entity_irg(entity);
@@ -124,8 +101,9 @@ static void visit_segment(ir_type *segment)
 
        for (i = 0; i < n_entities; ++i) {
                ir_entity *entity = get_compound_member(segment, i);
-               if (get_entity_visibility(entity) != ir_visibility_default
-                               && !(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER))
+               if (get_entity_visibility(entity) != ir_visibility_external
+                               && !(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER)
+                               && !(get_entity_linkage(entity) & IR_LINKAGE_NO_CODEGEN))
                        continue;
 
                visit_entity(entity);
@@ -144,20 +122,19 @@ static void garbage_collect_in_segment(ir_type *segment)
 
                DB((dbg, LEVEL_1, "  removing entity %+F\n", entity));
 
-               /* TODO: this is O(n^2) improve our interfaces! */
-               remove_class_member(get_entity_owner(entity), entity);
+               free_entity(entity);
        }
 }
 
 void garbage_collect_entities(void)
 {
-       int          i;
+       size_t       i;
        ir_segment_t s;
 
        FIRM_DBG_REGISTER(dbg, "firm.opt.garbagecollect");
 
        /* start a type walk for all externally visible entities */
-       irp_reserve_resources(irp, IR_RESOURCE_TYPE_VISITED);
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_VISITED);
        inc_master_type_visited();
        inc_max_irg_visited();
 
@@ -169,17 +146,17 @@ void garbage_collect_entities(void)
        }
 
        /* remove graphs of non-visited functions
-        * (we have to count backwards so we can safely call remove_irp_irg
-        *  while iterating) */
-       for (i = get_irp_n_irgs()-1; i >= 0; --i) {
-               ir_graph  *irg    = get_irp_irg(i);
+        * (we have to count backwards, because freeing the graph moves the last
+        *  graph in the list to the free position) */
+       for (i = get_irp_n_irgs(); i > 0;) {
+               ir_graph  *irg    = get_irp_irg(--i);
                ir_entity *entity = get_irg_entity(irg);
 
                if (entity_visited(entity))
                        continue;
 
-               DB((dbg, LEVEL_1, "  freeing method %+F\n",     entity));
-               remove_irp_irg(irg);
+               DB((dbg, LEVEL_1, "  freeing method %+F\n", entity));
+               free_ir_graph(irg);
        }
 
        /* we can now remove all non-visited (global) entities */
@@ -187,7 +164,7 @@ void garbage_collect_entities(void)
                ir_type *type = get_segment_type(s);
                garbage_collect_in_segment(type);
        }
-       irp_free_resources(irp, IR_RESOURCE_TYPE_VISITED);
+       irp_free_resources(irp, IRP_RESOURCE_TYPE_VISITED);
 }
 
 ir_prog_pass_t *garbage_collect_entities_pass(const char *name)