free_methods was a bad base for callgraph walks, use methods which have no callers...
authorMatthias Braun <matze@braunis.de>
Tue, 23 Sep 2008 12:32:08 +0000 (12:32 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 23 Sep 2008 12:32:08 +0000 (12:32 +0000)
[r22197]

include/libfirm/callgraph.h
ir/ana/callgraph.c
ir/opt/opt_inline.c

index 5a9cdc7..139f00a 100644 (file)
@@ -126,8 +126,8 @@ typedef void callgraph_walk_func(ir_graph *g, void *env);
  * @param post - walker function, executed after the predecessor of a node are visited
  * @param env  - environment, passed to pre and post
  */
-void callgraph_walk(ir_entity **roots, unsigned n_roots,
-               callgraph_walk_func *pre, callgraph_walk_func *post, void *env);
+void callgraph_walk(callgraph_walk_func *pre, callgraph_walk_func *post,
+                    void *env);
 
 /**
  * Compute the backedges that represent recursions and a looptree.
index b9102de..dac267e 100644 (file)
@@ -386,28 +386,22 @@ static void do_walk(ir_graph *irg, callgraph_walk_func *pre, callgraph_walk_func
                post(irg, env);
 }
 
-void callgraph_walk(ir_entity **roots, unsigned n_roots,
-               callgraph_walk_func *pre, callgraph_walk_func *post, void *env) {
+void callgraph_walk(callgraph_walk_func *pre, callgraph_walk_func *post, void *env) {
        int i, n_irgs = get_irp_n_irgs();
-       unsigned r;
        ++master_cg_visited;
 
-       for (r = 0; r < n_roots; ++r) {
-               ir_graph *irg = get_entity_irg(roots[r]);
-               if (irg == NULL)
-                       continue;
+       /* roots are methods which have no callers in the current program */
+       for (i = 0; i < n_irgs; ++i) {
+               ir_graph *irg = get_irp_irg(i);
 
-               do_walk(irg, pre, post, env);
+               if (get_irg_n_callers(irg) == 0)
+                       do_walk(irg, pre, post, env);
        }
 
-       /* cgana "optimizes" the graph instead of just analysing it so the
-        * roots list isn't even correct anymore when passed to this method...
-        * so we hack around this and search for more unreferenced/free
-        * methods... */
+       /* in case of unreachable call loops we haven't visited some irgs yet */
        for (i = 0; i < n_irgs; i++) {
                ir_graph *irg = get_irp_irg(i);
-               if (!cg_irg_visited(irg))
-                       do_walk(irg, pre, post, env);
+               do_walk(irg, pre, post, env);
        }
 }
 
index a0514b2..ffa5fbf 100644 (file)
@@ -1964,11 +1964,13 @@ static int calc_inline_benefice(ir_node *call, ir_graph *callee, unsigned *local
        }
 
        callee_env = get_irg_link(callee);
-       if (get_entity_visibility(ent) == visibility_local &&
-           callee_env->n_callers_orig == 1 &&
-           callee != current_ir_graph) {
+       if (callee_env->n_callers == 1 && callee != current_ir_graph) {
                /* we are the only caller, give big bonus */
-               weight += 5000;
+               if (get_entity_visibility(ent) == visibility_local) {
+                       weight += 5000;
+               } else {
+                       weight += 200;
+               }
        }
 
        /* do not inline big functions */
@@ -2018,19 +2020,20 @@ static void callgraph_walker(ir_graph *irg, void *data)
 
 static ir_graph **create_irg_list(void)
 {
-       ir_entity **roots;
+       ir_entity **free_methods;
        int       arr_len;
        int       n_irgs = get_irp_n_irgs();
 
-       cgana(&arr_len, &roots);
+       cgana(&arr_len, &free_methods);
+       xfree(free_methods);
+
        compute_callgraph();
 
        last_irg = 0;
        irgs     = xmalloc(n_irgs * sizeof(*irgs));
        memset(irgs, 0, sizeof(n_irgs * sizeof(*irgs)));
 
-       callgraph_walk(roots, arr_len, NULL, callgraph_walker, NULL);
-       xfree(roots);
+       callgraph_walk(NULL, callgraph_walker, NULL);
        assert(n_irgs == last_irg);
 
        return irgs;