make remove_irp_irg API private
authorMatthias Braun <matze@braunis.de>
Mon, 29 Oct 2012 12:48:22 +0000 (13:48 +0100)
committerMatthias Braun <matze@braunis.de>
Mon, 29 Oct 2012 16:48:54 +0000 (17:48 +0100)
Because otherwise we confuse users with free_ir_graph vs.
remove_irp_irg. Change it so that free_ir_graph also removes the graph
from the irp list.

include/libfirm/irprog.h
ir/ir/irgraph.c
ir/ir/irprog.c
ir/ir/irprog_t.h
ir/opt/garbage_collect.c
ir/opt/ircgopt.c

index 6fff640..9da39be 100644 (file)
@@ -163,16 +163,6 @@ FIRM_API ir_graph *get_irp_main_irg(void);
 /** Sets the main routine of the compiled program. */
 FIRM_API void set_irp_main_irg(ir_graph *main_irg);
 
-/** Adds irg to the list of ir graphs in the current irp. */
-FIRM_API void add_irp_irg(ir_graph *irg);
-
-/** Removes irg from the list of irgs and
-    shrinks the list by one. */
-FIRM_API void remove_irp_irg_from_list(ir_graph *irg);
-/** Removes irg from the list of irgs, deallocates it and
-    shrinks the list by one. */
-FIRM_API void remove_irp_irg(ir_graph *irg);
-
 /** returns the biggest not used irg index number */
 FIRM_API size_t get_irp_last_idx(void);
 
index faa4967..7d0e5b4 100644 (file)
@@ -396,6 +396,7 @@ void free_ir_graph(ir_graph *irg)
        assert(is_ir_graph(irg));
 
        edges_deactivate(irg);
+       remove_irp_irg(irg);
 
        hook_free_graph(irg);
        free_irg_outs(irg);
index fed0831..1fbcf35 100644 (file)
@@ -125,6 +125,9 @@ ir_prog *new_ir_prog(const char *name)
 
 void free_ir_prog(void)
 {
+       if (irp == NULL)
+               return;
+
        size_t i;
        /* must iterate backwards here */
        for (i = get_irp_n_irgs(); i > 0;)
@@ -196,7 +199,7 @@ void add_irp_irg(ir_graph *irg)
        ARR_APP1(ir_graph *, irp->graphs, irg);
 }
 
-void remove_irp_irg_from_list(ir_graph *irg)
+void remove_irp_irg(ir_graph *irg)
 {
        size_t i, l;
 
@@ -213,12 +216,6 @@ void remove_irp_irg_from_list(ir_graph *irg)
        }
 }
 
-void remove_irp_irg(ir_graph *irg)
-{
-       free_ir_graph(irg);
-       remove_irp_irg_from_list(irg);
-}
-
 size_t (get_irp_n_irgs)(void)
 {
        return get_irp_n_irgs_();
index c17a5ba..4c400e2 100644 (file)
@@ -119,6 +119,13 @@ void add_irp_type(ir_type *typ);
     shrinks the list by one. */
 void remove_irp_type(ir_type *typ);
 
+/** Adds irg to the list of ir graphs in the current irp. */
+FIRM_API void add_irp_irg(ir_graph *irg);
+
+/** Removes irg from the list of irgs and
+    shrinks the list by one. */
+FIRM_API void remove_irp_irg(ir_graph *irg);
+
 /* Inline functions. */
 #define get_irp_n_irgs()                 get_irp_n_irgs_()
 #define get_irp_irg(pos)                 get_irp_irg_(pos)
index ddaf9fd..4892264 100644 (file)
@@ -160,8 +160,8 @@ 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) */
+        * (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);
@@ -170,7 +170,7 @@ void garbage_collect_entities(void)
                        continue;
 
                DB((dbg, LEVEL_1, "  freeing method %+F\n", entity));
-               remove_irp_irg(irg);
+               free_ir_graph(irg);
        }
 
        /* we can now remove all non-visited (global) entities */
index df3738e..d49701b 100644 (file)
@@ -63,7 +63,6 @@ static void collect_call(ir_node *node, void *env)
 void gc_irgs(size_t n_keep, ir_entity ** keep_arr)
 {
        void * MARK = &MARK; /* @@@ gefaehrlich!!! Aber wir markieren hoechstens zu viele ... */
-       size_t i, n;
 
        FIRM_DBG_REGISTER(dbg, "firm.opt.cgopt");
 
@@ -122,7 +121,7 @@ void gc_irgs(size_t n_keep, ir_entity ** keep_arr)
        }
 
        /* clean */
-       for (i = 0, n = get_irp_n_irgs(); i < n; ++i) {
+       for (size_t i = get_irp_n_irgs()-1; i-- > 0; ) {
                ir_graph  *irg = get_irp_irg(i);
                ir_entity *ent = get_irg_entity(irg);
 
@@ -130,9 +129,7 @@ void gc_irgs(size_t n_keep, ir_entity ** keep_arr)
                        continue;
 
                DB((dbg, LEVEL_1, "  freeing method %+F\n", ent));
-               remove_irp_irg(irg);
-
-               free_entity(ent);
+               free_ir_graph(irg);
        }
 }