bugfix: missing test for new symconst
[libfirm] / ir / ana / rta.c
index 828bee7..3728f80 100644 (file)
@@ -3,19 +3,19 @@
 /*
  * Project:     libFIRM
  * File name:   ir/ana/rta.c
- * Purpose:     Intraprozedural analyses to improve the call graph estimate.
+ * Purpose:     Interprocedural analysis to improve the call graph estimate.
  * Author:      Florian
  * Modified by:
  * Created:     09.06.2002
  * CVS-ID:      $$
  * Copyright:   (c) 1999-2004 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
 
 /**
  * Intraprozedurale Analyse zur Abschätzung der Aufrufrelation. Es
- * die Menge der instantiierten Klassen bestimmt, und daraus existierende Methoden
- * bestimmt.
+ * die Menge der instantiierten Klassen bestimmt, und daraus eine Abschätzung
+ * der aufgerufenen Methoden bestimmt.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -27,7 +27,7 @@
 #include <stdlib.h>
 
 #include "irnode_t.h"
-#include "irprog.h"
+#include "irprog_t.h"
 
 #include "eset.h"
 #include "irgwalk.h"
@@ -163,12 +163,26 @@ static void rta_act (ir_node *node, void *env)
       if (graph) {
         *change = add_graph (graph);
       } else {
-        /* it's an externally allocated thing. */
+        /* it's an external allocated thing. */
       }
     } else if (iro_SymConst == get_irn_opcode (ptr)) { /* CALL SYMCONST */
+      if (get_SymConst_kind(ptr) == symconst_addr_ent) {
+       ent = get_SymConst_entity (ptr);
+       ir_graph *graph = get_entity_irg (ent);
+       /* don't use get_implementing_graph on a SymConst! */
+       if (graph) {
+         *change = add_graph (graph);
+       } else {
+         /* it's an external allocated thing. */
+       }
+      } else if (get_SymConst_kind(ptr) == symconst_addr_name) {
       /* If this SymConst refers to a method the method is external_visible
          and therefore must be considered live anyways. */
       /* assert (ent && "couldn't determine entity of call to symConst"); */
+      } else {
+       /* other symconst. */
+      }
+
     }
   } else if (iro_Alloc == op) { /* ALLOC */
     type *type = get_Alloc_type (node);
@@ -209,19 +223,16 @@ static int rta_fill_incremental (void)
   /* init_tables has added main_irg to _live_graphs */
 
   /* Need to take care of graphs that are externally
-     visible. Pretend that they are called: */
-
-  if (! whole_world) {
-    for (i = 0; i < get_irp_n_irgs(); i++) {
-      ir_graph *graph = get_irp_irg (i);
-
-      entity *ent = get_irg_entity (graph);
-      if (visibility_external_visible == get_entity_visibility (ent)) {
+     visible or sticky. Pretend that they are called: */
 
-        eset_insert (_live_graphs, graph);
+  for (i = 0; i < get_irp_n_irgs(); i++) {
+    ir_graph *graph = get_irp_irg (i);
+    entity *ent = get_irg_entity (graph);
 
-        /* eset_insert (_live_classes, get_entity_owner (ent)); */
-      }
+    if (((!whole_world) &&
+         (visibility_external_visible == get_entity_visibility (ent))) ||
+        (stickyness_sticky == get_entity_stickyness (ent))) {
+      eset_insert (_live_graphs, graph);
     }
   }
 
@@ -301,8 +312,7 @@ static void force_description (entity *ent, entity *addr)
 
     if (peculiarity_inherited == get_entity_peculiarity (over)) {
       /* We rely on the fact that cse is performed on the const_code_irg. */
-      entity *my_addr =
-        tarval_to_entity(get_Const_tarval(get_atomic_ent_value(over)));
+      entity *my_addr = get_SymConst_entity(get_atomic_ent_value(over));
 
       if (addr == my_addr) {
         force_description (over, addr);
@@ -310,9 +320,9 @@ static void force_description (entity *ent, entity *addr)
     } else if (peculiarity_existent == get_entity_peculiarity (over)) {
       /* check whether 'over' forces 'inheritance' of *our* graph: */
       ir_node *f_addr = get_atomic_ent_value (over);
-      entity *impl_ent = tarval_to_entity (get_Const_tarval (f_addr));
+      entity *impl_ent = get_SymConst_entity (f_addr);
 
-      assert ((get_irn_op(f_addr) == op_Const) && "can't do complex addrs");
+      assert ((get_irn_op(f_addr) == op_SymConst) && "can't do complex addrs");
       if (impl_ent == addr) {
         assert (0 && "gibt's denn sowas");
         force_description (over, addr);
@@ -330,13 +340,21 @@ static void force_description (entity *ent, entity *addr)
 static void remove_irg (ir_graph *graph)
 {
   entity *ent = get_irg_entity (graph);
+  peculiarity pec = get_entity_peculiarity (ent);
 
-/*   DDMEO (get_irg_ent(graph)); */
+  /*   DDMEO (get_irg_ent(graph)); */
 
   /* delete the ir_graph data */
+  set_entity_peculiarity (ent, peculiarity_description);
   remove_irp_irg (graph);
-  /* remove reference to the graph */
-  set_entity_irg (ent, NULL);
+  /* remove_irp_irg also removes the entities' reference to the graph */
+  /*
+    if (NULL != get_entity_irg (ent)) {
+    set_entity_irg (ent, NULL);
+    }
+  */
+  set_entity_peculiarity (ent, pec);
+
   /* find the implementation (graph) from *some* superclass: */
   graph = get_implementing_graph (ent);
 
@@ -365,6 +383,8 @@ static void init_tables (void)
     eset_insert (_live_graphs, get_irp_main_irg ());
   }
 
+  /* Adding the GlobalType is pointless, since its methods are always
+     called via a constant */
   /*
   if (get_glob_type ()) {
     eset_insert (_live_classes, get_glob_type ());
@@ -373,12 +393,11 @@ static void init_tables (void)
 }
 
 /* Initialise the RTA data structures, and perform RTA.
-   @param   do_verbose Iff != 0, print statistics as we go along
+   @param   do_verbose If == 1, print statistics, if > 1, chatter about every detail
    @param   do_whole_world Iff != 0, assume whole-world
 */
 void rta_init (int do_verbose, int do_whole_world)
 {
-  int n_live_graphs = 0;
   int n_runs = 0;
 
 # ifdef DEBUG_libfirm
@@ -396,9 +415,9 @@ void rta_init (int do_verbose, int do_whole_world)
 
   n_runs = rta_fill_incremental ();
 
-  n_live_graphs = stats ();
-
   if (verbose) {
+    int n_live_graphs = stats ();
+
     if (whole_world) {
       printf ("RTA: whole-world assumption\n");
     }
@@ -415,12 +434,15 @@ void rta_init (int do_verbose, int do_whole_world)
 # endif /* defined DEBUG_libfirm */
 }
 
-/* Delete all graphs that we have found to be dead from the program */
+/* Delete all graphs that we have found to be dead from the program
+   If verbose == 1, print statistics, if > 1, chatter about every detail
+*/
 void rta_delete_dead_graphs (void)
 {
   int i;
   int n_graphs = get_irp_n_irgs ();
   ir_graph *graph = NULL;
+  int n_dead_graphs = 0;
 
   if (!get_optimize() || !get_opt_dead_method_elimination()) return;
 
@@ -438,6 +460,7 @@ void rta_delete_dead_graphs (void)
               (visibility_external_visible != get_entity_visibility (ent)));
 # endif /* defined DEBUG_libfirm */
 
+      n_dead_graphs ++;
       eset_insert (dead_graphs, graph);
     }
   }
@@ -447,13 +470,17 @@ void rta_delete_dead_graphs (void)
        graph;
        graph = (ir_graph*) eset_next (dead_graphs)) {
 
-    if (verbose || get_opt_dead_method_elimination_verbose ()) {
+    if ((verbose > 1) || get_opt_dead_method_elimination_verbose ()) {
       fprintf(stdout, "RTA: removing graph of ");
       DDMEO(get_irg_ent (graph));
     }
 
     remove_irg (graph);
   }
+
+  if (verbose) {
+    printf ("RTA: n_dead_graphs = %i\n", n_dead_graphs);
+  }
 }
 
 /* Clean up the RTA data structures.  Call this after calling rta_init */
@@ -517,6 +544,21 @@ void rta_report (void)
 
 /*
  * $Log$
+ * Revision 1.21  2004/07/08 15:50:56  goetz
+ * firmstat added
+ *
+ * Revision 1.20  2004/07/08 11:17:40  goetz
+ * *** empty log message ***
+ *
+ * Revision 1.19  2004/07/06 12:30:37  beyhan
+ * new SymConst semantics
+ *
+ * Revision 1.18  2004/06/27 21:17:41  liekweg
+ * Added comment
+ *
+ * Revision 1.17  2004/06/25 13:45:13  liekweg
+ * observe stickyness; minor refactoring
+ *
  * Revision 1.16  2004/06/24 06:42:14  goetz
  * test of firm flags
  *