fixed some depencies between irdump.c and irdumptxt.c
[libfirm] / ir / ana2 / pto.c
index c0b2f78..65c0d1c 100644 (file)
@@ -38,6 +38,7 @@
 # include "irmemwalk.h"
 
 # define DBGPRINT(lvl, msg) if (get_pto_verbose () > lvl) { fprintf msg; }
+# define DBGEXE(lvl, cmd) if (get_pto_verbose () > lvl) { cmd; }
 
 /*
   Local Protos
@@ -66,11 +67,23 @@ static pto_t *compute_pto (ir_node *node, void *env)
 {
   pto_t *node_pto = get_pto (node);
 
+  if ((NULL != node_pto) && (pto_is_dummy (node_pto))) {
+    /* weed out initialisation data as good as possible */
+
+    DBGPRINT (0, (stdout, "%s: dummy pto for (%s[%li])\n",
+                  __FUNCTION__,
+                  get_op_name (get_irn_op (node)),
+                  get_irn_node_nr (node)));
+
+    pto_delete (node_pto);
+    node_pto = NULL;
+  }
+
   if (NULL == node_pto) {
     DBGPRINT (1, (stdout, "%s: must compute pto for %s[%li]\n",
-             __FUNCTION__,
-             get_op_name (get_irn_op (node)),
-             get_irn_node_nr (node)));
+                  __FUNCTION__,
+                  get_op_name (get_irn_op (node)),
+                  get_irn_node_nr (node)));
 
     pto_node (node, env);
 
@@ -100,10 +113,10 @@ static void set_call_args (ir_node *call, ir_graph *graph, void *env)
     if (NULL != args [i-2]) {
       if (mode_P == get_irn_mode (args [i-2])) {
         pto_t *arg_pto = compute_pto (get_irn_n (call, i), env);
-        /* off-by-one because of ProjT bd */
+        /* off-by-two because of ProjT bd */
         set_pto (args [i-2], arg_pto);
       } else {
-        /* nothing */
+        /* not a pointer value */
       }
     }
   }
@@ -118,6 +131,17 @@ static void get_call_ret (ir_node *call, ir_graph *graph, void *env)
   entity *ent = get_irg_ent (graph);
   type *ent_tp = get_entity_type (ent);
 
+  if (NULL != get_pto (call)) {
+    pto_t *old = get_pto (call);
+
+    if (pto_is_dummy (old)) {
+      DBGPRINT (2, (stdout, "%s: dummy pto (0x%08x) from call[%li]\n",
+                    __FUNCTION__, (int) old, get_irn_node_nr (call)));
+    }
+
+    pto_delete (old);
+  }
+
   if (0 != get_method_n_ress (ent_tp)) {
     type *ent_ret_tp = get_method_res_type (ent_tp, 0);
 
@@ -256,14 +280,26 @@ static void pto_node_obj_load (ir_node *load, ir_node *ptr,
   const char *own_name = (char*) get_type_name (get_entity_owner (ent));
 
   DBGPRINT (1, (stdout, "%s for (%s[%li])\n",
-           __FUNCTION__,
-           get_op_name (get_irn_op (ptr)),
-           get_irn_node_nr (ptr)));
+                __FUNCTION__,
+                get_op_name (get_irn_op (ptr)),
+                get_irn_node_nr (ptr)));
+
   if (! is_pointer_type (get_entity_type (ent))) {
     return;
   }
 
-  DBGPRINT (2, (stdout, "%s: obj load from ent (0x%08x) \"%s.%s\"\n",
+  if (NULL != get_pto (load)) {
+    pto_t *old = get_pto (load);
+
+    if (pto_is_dummy (old)) {
+      DBGPRINT (1, (stdout, "%s: dummy pto (0x%08x) from load[%li]\n",
+                    __FUNCTION__, (int) old, get_irn_node_nr (load)));
+    }
+
+    pto_delete (old);
+  }
+
+  DBGPRINT (1, (stdout, "%s: obj load from ent (0x%08x) \"%s.%s\"\n",
                 __FUNCTION__,
                 (int) ent,
                 own_name,
@@ -271,24 +307,26 @@ static void pto_node_obj_load (ir_node *load, ir_node *ptr,
 
   pto_t *ptr_objs = compute_pto (ptr, env);
   qset_t *objs = ptr_objs->objs;
-
   pto_t *res = pto_new_empty (load);
-
-  /* todo: iterate over 'objs' ... for each obj in objs, perform
-     lookup using 'ent' ... assemble results in new qset ... return
-     that as the new value */
-
   obj_desc_t *obj_desc = (obj_desc_t*) qset_start (objs);
 
+  DBGPRINT (1, (stdout, "%s: ptr_pto = ", __FUNCTION__));
+  DBGEXE (1, qset_print (objs, stdout));
+
   while (NULL != obj_desc) {
     qset_t *cnts = pto_lookup (obj_desc, ent);
 
+    DBGPRINT (1, (stdout, "%s: cnts = ", __FUNCTION__));
+    DBGEXE (1, qset_print (cnts, stdout));
+
     pto_add_all_names (res, cnts);
 
     obj_desc = (obj_desc_t*) qset_next (objs);
   }
 
   set_pto (load, res);
+
+  DBGPRINT (1, (stdout, "%s\n", __FUNCTION__));
 }
 
 static void pto_node_arr_load (ir_node *load, ir_node *ptr,
@@ -315,7 +353,7 @@ static void pto_node_arr_load (ir_node *load, ir_node *ptr,
     return;
   }
 
-  DBGPRINT (2, (stdout, "%s: array load from ent (0x%08x) \"%s.%s\"\n",
+  DBGPRINT (1, (stdout, "%s: array load from ent (0x%08x) \"%s.%s\"\n",
                 __FUNCTION__,
                 (int) ent,
                 own_name,
@@ -400,7 +438,7 @@ static void pto_node_obj_store (ir_node *store,
   const char *ent_name = (char*) get_entity_name (ent);
   const char *own_name = (char*) get_type_name (get_entity_owner (ent));
 
-  DBGPRINT (1, (stdout, "%s: obj store from ent (0x%08x) \"%s.%s\"\n",
+  DBGPRINT (1, (stdout, "%s: obj store to ent (0x%08x) \"%s.%s\"\n",
                 __FUNCTION__,
                 (int) ent, own_name, ent_name));
 
@@ -411,13 +449,24 @@ static void pto_node_obj_store (ir_node *store,
 
   obj_desc_t *obj_desc = (obj_desc_t*) qset_start (objs);
 
+  DBGPRINT (1, (stdout, "%s: ptr_pto = ", __FUNCTION__));
+  DBGEXE (1, qset_print (objs, stdout));
+
+  DBGPRINT (1, (stdout, "%s: ptr_val = ", __FUNCTION__));
+  DBGEXE (1, qset_print (vals, stdout));
+
   while (NULL != obj_desc) {
     qset_t *cnts = pto_lookup (obj_desc, ent);
 
     qset_insert_all (cnts, vals);
 
+    DBGPRINT (1, (stdout, "%s: cnts = ", __FUNCTION__));
+    DBGEXE (1, qset_print (cnts, stdout));
+
     obj_desc = (obj_desc_t*) qset_next (objs);
   }
+
+  DBGPRINT (1, (stdout, "%s\n", __FUNCTION__));
 }
 
 static void pto_node_arr_store (ir_node *store,
@@ -437,7 +486,7 @@ static void pto_node_arr_store (ir_node *store,
   const char *ent_name = (char*) get_entity_name (ent);
   const char *own_name = (char*) get_type_name (get_entity_owner (ent));
 
-  DBGPRINT (1, (stdout, "%s: array store from ent (0x%08x) \"%s.%s\"\n",
+  DBGPRINT (1, (stdout, "%s: array store to ent (0x%08x) \"%s.%s\"\n",
                 __FUNCTION__,
                 (int) ent, own_name, ent_name));
 
@@ -493,12 +542,24 @@ static void pto_node_alloc (ir_node *alloc, void *env)
     so far: nothing to do
     todo:
     invent new name
- */
+  */
+
+  if (NULL == get_pto (alloc)) {
+    type *tp = get_Alloc_type (alloc);
 
-  type *tp = get_Alloc_type (alloc);
+    pto_t *alloc_pto = pto_new_name (alloc, tp);
+    set_pto (alloc, alloc_pto);
+    DBGPRINT (0, (stdout, "%s (%s[%li]): new pto\n",
+                  __FUNCTION__,
+                  get_op_name (get_irn_op (alloc)),
+                  get_irn_node_nr (alloc)));
+  } else {
+    DBGPRINT (0, (stdout, "%s (%s[%li]): reusing pto\n",
+                  __FUNCTION__,
+                  get_op_name (get_irn_op (alloc)),
+                  get_irn_node_nr (alloc)));
+  }
 
-  pto_t *alloc_pto = pto_new_name (alloc, tp);
-  set_pto (alloc, alloc_pto);
 }
 
 static void pto_node_free (ir_node *free, void *env)
@@ -565,7 +626,7 @@ static void pto_node_call (ir_node *call, void *env)
   ir_node *ptr = get_Call_ptr (call);
   entity *ent = get_ptr_ent (ptr);
 
-  DBGPRINT (0, (stdout, "%s (%s[%li])\n",
+  DBGPRINT (1, (stdout, "%s (%s[%li])\n",
                 __FUNCTION__,
                 get_op_name (get_irn_op (call)),
                 get_irn_node_nr (call)));
@@ -589,10 +650,8 @@ static void pto_node_call (ir_node *call, void *env)
       get_call_ret (call, graph, env);
     }
   } else {
-    DBGPRINT (0, (stdout, "%s:%i: Warning: no graph for ent \"%s.%s\"\n",
-                  __FILE__, __LINE__, own_name, ent_name));
-    DBGPRINT (0, (stdout, "%s:%i: Warning: no graph for call call[%li]\n",
-                  __FILE__, __LINE__, get_irn_node_nr (call)));
+    DBGPRINT (0, (stdout, "%s:%i: Warning: no graph for ent \"%s.%s\" in call[%li]\n",
+                  __FILE__, __LINE__, own_name, ent_name, get_irn_node_nr (call)));
   }
 }
 
@@ -656,7 +715,7 @@ static void pto_node_phi (ir_node *phi, void *env)
 
     pto_t *in_pto = compute_pto (in, env);
 
-    DBGPRINT (1, (stdout, "%s: IN PHI Node (%ld) (%s) (pto = 0x%08x)\n",
+    DBGPRINT (0, (stdout, "%s: IN PHI Node (%ld) (%s) (pto = 0x%08x)\n",
                   __FUNCTION__,
                   get_irn_node_nr (in),
                   get_op_name (get_irn_op (in)),
@@ -676,7 +735,7 @@ static void pto_node_cnst (ir_node *cnst, void *env)
     if this represents something nameable, name it
   */
   type *tp = get_Const_type (cnst);
-  pto_t *cnst_pto = pto_new_name (cnst, tp);
+  pto_t *cnst_pto = pto_new_name (cnst, tp); /* WRONG */
 
 
   set_pto (cnst, cnst_pto);
@@ -691,12 +750,36 @@ static void pto_node_sym_cnst (ir_node *sym_cnst, void *env)
     todo:
     if this represents something nameable, name it
   */
-  type *tp = get_entity_type (get_SymConst_entity (sym_cnst));
+  entity *ent = get_SymConst_entity (sym_cnst);
+  type *tp = get_entity_type (ent);
+
+  if (is_pointer_type (tp)) {
+    tp = get_pointer_points_to_type (tp);
+    pto_t *sym_cnst_pto = (pto_t*) get_entity_link (ent);
+
+    DBGPRINT (2, (stdout, "%s: SymConst (%ld) (%s)\n",
+                  __FUNCTION__,
+                  get_irn_node_nr (sym_cnst),
+                  get_op_name (get_irn_op (sym_cnst))));
 
-  if (is_class_type (tp)) {
-  pto_t *sym_cnst_pto = pto_new_name (sym_cnst, tp);
 
-  set_pto (sym_cnst, sym_cnst_pto);
+    if (NULL == sym_cnst_pto) {
+      sym_cnst_pto = pto_new_name (sym_cnst, tp);
+
+      DBGPRINT (1, (stdout, "%s: SymConst (%ld) (%s): NEW PTO\n",
+                    __FUNCTION__,
+                    get_irn_node_nr (sym_cnst),
+                    get_op_name (get_irn_op (sym_cnst))));
+
+      set_entity_link (ent, sym_cnst_pto);
+    } else {
+      DBGPRINT (1, (stdout, "%s: SymConst (%ld) (%s): reusing pto\n",
+                    __FUNCTION__,
+                    get_irn_node_nr (sym_cnst),
+                    get_op_name (get_irn_op (sym_cnst))));
+    }
+
+    set_pto (sym_cnst, sym_cnst_pto);
   } else {
     /* nothing to do */
   }
@@ -711,12 +794,13 @@ static void pto_node_end_block (ir_node *end, void *env)
     todo:
     collect results, set to node.
   */
-  type *tp = get_entity_type (get_irg_entity (get_irn_irg (end)));
+  entity *ent = get_irg_entity (get_irn_irg (end));
+  type *tp = get_entity_type (ent);
 
-    DBGPRINT (2, (stdout, "%s: End Block (%ld) (%s)\n",
-                  __FUNCTION__,
-                  get_irn_node_nr (end),
-                  get_op_name (get_irn_op (end))));
+  DBGPRINT (2, (stdout, "%s: End Block (%ld) (%s)\n",
+                __FUNCTION__,
+                get_irn_node_nr (end),
+                get_op_name (get_irn_op (end))));
 
   if (0 != get_method_n_ress (tp)) {
     tp = get_method_res_type (tp, 0);
@@ -724,13 +808,17 @@ static void pto_node_end_block (ir_node *end, void *env)
     if (mode_P == get_type_mode (tp)) {
       int i;
       int n_ins = get_irn_arity (end);
-      pto_t *end_pto = pto_new_name (end, get_pointer_points_to_type (tp));
+      pto_t *end_pto = pto_new_empty (end);
 
       for (i = 0; i < n_ins; i ++) {
         ir_node *ret = get_irn_n (end, i);
 
-        pto_t *ret_pto = get_pto (ret);
-        assert (ret_pto);
+        if (iro_Return == get_irn_opcode (ret)) {
+          pto_t *ret_pto = get_pto (ret);
+          assert (ret_pto);
+
+          pto_add_all_names (end_pto, ret_pto->objs);
+        }
       }
 
       set_pto (end, end_pto);
@@ -817,8 +905,8 @@ static void pto_node (ir_node *node, void *env)
   case (iro_DivMod):
     set_pto (node, NULL);
     break;
-    /* stopgap measure */
   default: {
+    /* stopgap measure */
     DBGPRINT (0, (stdout, "%s: not handled: node[%li].op = %s\n",
                   __FUNCTION__,
                   get_irn_node_nr (node),
@@ -858,11 +946,18 @@ static void clear_type_link (type_or_ent *thing, void *__unused)
     type *tp = (type*) thing;
 
     if (is_class_type (tp)) {
-      DBGPRINT (4, (stdout, "%s (\"%s\")\n",
+      DBGPRINT (1, (stdout, "%s (\"%s\")\n",
                     __FUNCTION__, get_type_name (tp)));
 
       set_type_link (tp, NULL);
     }
+  } else if (is_entity (thing)) {
+    entity *ent = (entity*) thing;
+
+    DBGPRINT (1, (stdout, "%s (\"%s\")\n",
+                  __FUNCTION__, get_entity_name (ent)));
+
+    set_entity_link (ent, NULL);
   }
 }
 
@@ -920,6 +1015,7 @@ void pto_run (int do_verbose)
 {
   /* int i; */
   set_pto_verbose (do_verbose);
+  set_pto_verbose (2);
 
   DBGPRINT (0, (stdout, "START PTO\n"));
 
@@ -973,6 +1069,12 @@ void pto_cleanup ()
 \f
 /*
  * $Log$
+ * Revision 1.6  2004/11/09 16:47:09  liekweg
+ * fix SymConst handling
+ *
+ * Revision 1.5  2004/11/08 12:33:06  liekweg
+ * initialisation; sanitize print levels, misc fixes
+ *
  * Revision 1.4  2004/11/04 14:58:38  liekweg
  * expanded pto, added initialisation, added debugging printing
  *