various changes to get firm faster
authorGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Thu, 8 Jul 2004 15:51:24 +0000 (15:51 +0000)
committerGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Thu, 8 Jul 2004 15:51:24 +0000 (15:51 +0000)
[r3377]

19 files changed:
ir/ir/ircgopt.c
ir/ir/irgopt.c
ir/ir/irgwalk.c
ir/ir/irnode.c
ir/ir/irnode.h
ir/ir/iropt.c
ir/ir/irprog.c
ir/ir/irprog_t.h
ir/stat/firmstat.h
ir/tr/type.c
ir/tr/type_identify.c
ir/tv/tv.c
testprograms/Makefile.in
testprograms/array-stack_example.c
testprograms/call_str_example.c
testprograms/endless_loop.c
testprograms/oo_inline_example.c
testprograms/oo_program_example.c
testprograms/while_example.c

index 06cef83..0771b27 100644 (file)
@@ -24,7 +24,7 @@
 #include "array.h"
 #include "irprog.h"
 #include "irgwalk.h"
-#include "irloop.h"
+#include "irloop_t.h"
 #include "irflag_t.h"
 
 static void clear_link(ir_node * node, void * env) {
index 7798f0f..733fe7d 100644 (file)
 # include <config.h>
 #endif
 
-# include <assert.h>
-# include <stdbool.h>
-
-# include "irprog.h"
-# include "irgopt.h"
-# include "irnode_t.h"
-# include "irgraph_t.h"
-# include "iropt_t.h"
-# include "irgwalk.h"
-# include "ircons_t.h"
-# include "irgmod.h"
-# include "array.h"
-# include "pset.h"
-# include "eset.h"
-# include "pdeq.h"       /* Fuer code placement */
-# include "irouts.h"
-# include "irloop.h"
-# include "irbackedge_t.h"
-# include "irflag_t.h"
-# include "firmstat.h"
-# include "cgana.h"
+#include <assert.h>
+#include <stdbool.h>
+
+#include "irnode_t.h"
+#include "irgraph_t.h"
+#include "irprog_t.h"
+
+#include "ircons.h"
+#include "iropt_t.h"
+#include "irgopt.h"
+#include "irgmod.h"
+#include "irgwalk.h"
+
+#include "array.h"
+#include "pset.h"
+#include "eset.h"
+#include "pdeq.h"       /* Fuer code placement */
+
+#include "irouts.h"
+#include "irloop_t.h"
+#include "irbackedge_t.h"
+#include "cgana.h"
+
+#include "irflag_t.h"
+#include "firmstat.h"
 
 /* Defined in iropt.c */
 pset *new_identities (void);
index 79c334c..efcfefa 100644 (file)
@@ -120,12 +120,71 @@ static void collect_irgs(ir_node * node, eset * irg_set) {
   }
 }
 
+static void
+irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void * env) {
+  int i;
+  set_irn_visited(node, current_ir_graph->visited);
+
+  pre(node, env);
+
+  if (node->op != op_Block) {
+    ir_node *pred = get_irn_n(node, -1);
+    if (pred->visited < current_ir_graph->visited)
+      irg_walk_2_pre(pred, pre, env);
+  }
+  for (i = get_irn_arity(node) - 1; i >= 0; --i) {
+    ir_node *pred = get_irn_n(node, i);
+    if (pred->visited < current_ir_graph->visited)
+      irg_walk_2_pre(pred, pre, env);
+  }
+}
+
+static void
+irg_walk_2_post(ir_node *node, irg_walk_func *post, void * env) {
+  int i;
+  set_irn_visited(node, current_ir_graph->visited);
+
+  if (node->op != op_Block) {
+    ir_node *pred = get_irn_n(node, -1);
+    if (pred->visited < current_ir_graph->visited)
+      irg_walk_2_post(pred, post, env);
+  }
+  for (i = get_irn_arity(node) - 1; i >= 0; --i) {
+    ir_node *pred = get_irn_n(node, i);
+    if (pred->visited < current_ir_graph->visited)
+      irg_walk_2_post(pred, post, env);
+  }
+
+  post(node, env);
+}
+
+static void
+irg_walk_2_both(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env) {
+  int i;
+  set_irn_visited(node, current_ir_graph->visited);
+
+  pre(node, env);
+
+  if (node->op != op_Block) {
+    ir_node *pred = get_irn_n(node, -1);
+    if (pred->visited < current_ir_graph->visited)
+      irg_walk_2_both(pred, pre, post, env);
+  }
+  for (i = get_irn_arity(node) - 1; i >= 0; --i) {
+    ir_node *pred = get_irn_n(node, i);
+    if (pred->visited < current_ir_graph->visited)
+      irg_walk_2_both(pred, pre, post, env);
+  }
+
+  post(node, env);
+}
+
+
 static void
 irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
 {
+#if 0 /* safe, old */
   int i;
-  assert(node && node->kind==k_ir_node);
-#if 0 /* safe */
   if (get_irn_visited(node) < get_irg_visited(current_ir_graph)) {
     set_irn_visited(node, get_irg_visited(current_ir_graph));
 
@@ -139,7 +198,9 @@ irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
     if (post) post(node, env);
   }
 #else /* faster */
+#if 0
   if (node->visited < current_ir_graph->visited) {
+    int i;
     set_irn_visited(node, current_ir_graph->visited);
 
     if (pre) pre(node, env);
@@ -151,6 +212,13 @@ irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
 
     if (post) post(node, env);
   }
+#else /* even faster */
+  if (node->visited < current_ir_graph->visited) {
+    if      (!post) irg_walk_2_pre (node, pre, env);
+    else if (!pre)  irg_walk_2_post(node, post, env);
+    else            irg_walk_2_both(node, pre, post, env);
+  }
+#endif
 #endif
 }
 
index 603bb90..5fe1675 100644 (file)
@@ -1921,11 +1921,17 @@ skip_nop (ir_node *node) {
   ir_node *pred;
   /* don't assert node !!! */
 
+  if (!node || (node->op != op_Id)) return node;
+
   if (!get_opt_normalize()) return node;
 
   /* Don't use get_Id_pred:  We get into an endless loop for
      self-referencing Ids. */
-  if (node && (node->op == op_Id) && (node != (pred = node->in[0+1]))) {
+  pred = node->in[0+1];
+
+  if (pred->op != op_Id) return pred;
+
+  if (node != pred) {  /* not a self referencing Id. Resolve Id chain. */
     ir_node *rem_pred, *res;
 
     if (pred->op != op_Id) return pred; /* shortcut */
@@ -1933,11 +1939,11 @@ skip_nop (ir_node *node) {
 
     assert (get_irn_arity (node) > 0);
 
-    node->in[0+1] = node;
+    node->in[0+1] = node;   /* turn us into a self referencing Id:  shorten Id cycles. */
     res = skip_nop(rem_pred);
     if (res->op == op_Id) /* self-loop */ return node;
 
-    node->in[0+1] = res;
+    node->in[0+1] = res;    /* Turn Id chain into Ids all referencing the chain end. */
     return res;
   } else {
     return node;
index e17a8de..0f4d84a 100644 (file)
@@ -392,9 +392,6 @@ void     set_Const_type   (ir_node *node, type *tp);
      depends on this tag.  Use the proper access routine after testing
      this flag. */
 
-#define type_tag         symconst_type_tag
-//#define size             symconst_size   geht nicht, benennt auf size in type.c um!
-#define linkage_ptr_info symconst_addr_name
 typedef enum {
   symconst_type_tag,    /**< The SymConst is a type tag for the given type.
                           Type_or_id_p is type *. */
@@ -411,12 +408,15 @@ typedef enum {
 /** SymConst attributes
     This union contains the symbolic information represented by the node  */
 union symconst_symbol {
-  type   *type_p;           //old typ
-  ident  *ident_p;         // old ptrinfo
-  entity *entity_p;        // entity_p
+  type   *type_p;
+  ident  *ident_p;
+  entity *entity_p;
 };
+
+
 typedef union symconst_symbol symconst_symbol;
 
+
 /** Access the kind of the SymConst. */
 symconst_kind get_SymConst_kind (const ir_node *node);
 void          set_SymConst_kind (ir_node *node, symconst_kind num);
index ba6894c..561e050 100644 (file)
@@ -21,7 +21,7 @@
 # include "ircons_t.h"
 # include "irgmod.h"
 # include "irvrfy.h"
-# include "tv.h"
+# include "tv_t.h"
 # include "dbginfo_t.h"
 # include "iropt_dbg.h"
 # include "irflag_t.h"
index 372e456..0c702fb 100644 (file)
@@ -108,9 +108,8 @@ void set_irp_main_irg(ir_graph *main_irg) {
   irp->main_irg = main_irg;
 }
 
-type *get_glob_type(void) {
-  assert(irp);
-  return irp->glob_type = skip_tid(irp->glob_type);
+type *(get_glob_type)(void) {
+  return __get_glob_type();
 }
 
 /* Adds irg to the list of ir graphs in irp. */
@@ -136,16 +135,12 @@ void remove_irp_irg(ir_graph *irg){
   }
 }
 
-int get_irp_n_irgs() {
-  assert (irp && irp->graphs);
-  /* Strangely the first element of the array is NULL.  Why??  */
-  return (ARR_LEN((irp)->graphs) - 1);
+int (get_irp_n_irgs)(void) {
+  return __get_irp_n_irgs();
 }
 
-ir_graph *get_irp_irg(int pos){
-  assert (irp && irp->graphs);
-  /* Strangely the first element of the array is NULL.  Why??  */
-  return irp->graphs[pos+1];
+ir_graph *(get_irp_irg)(int pos){
+  return __get_irp_irg(pos);
 }
 
 void set_irp_irg(int pos, ir_graph *irg) {
@@ -166,17 +161,12 @@ void remove_irp_type(type *typ) {
   remove_irp_type_from_list (typ);
 }
 
-int get_irp_n_types (void) {
-  assert (irp && irp->types);
-  /* Strangely the first element of the array is NULL.  Why??  */
-  return (ARR_LEN((irp)->types) - 1);
+int (get_irp_n_types) (void) {
+  return __get_irp_n_types();
 }
 
-type *get_irp_type(int pos) {
-  assert (irp && irp->types);
-  /* Strangely the first element of the array is NULL.  Why??  */
-  /* Don't set the skip_tid result so that no double entries are generated. */
-  return skip_tid(irp->types[pos+1]);
+type *(get_irp_type) (int pos) {
+  return __get_irp_type(pos);
 }
 
 void  set_irp_type(int pos, type *typ) {
@@ -206,17 +196,19 @@ const char  *get_irp_prog_name(void) {
 }
 
 
-ir_graph *get_const_code_irg(void)
+ir_graph *(get_const_code_irg)(void)
 {
-  return irp->const_code_irg;
+  return __get_const_code_irg();
 }
 
 irg_outs_state get_irp_ip_outs_state() {
   return irp->outs_state;
 }
+
 void set_irp_ip_outs_inconsistent() {
   irp->outs_state = outs_inconsistent;
 }
+
 void      set_irp_ip_outedges(ir_node ** ip_outedges)
 {
   irp -> ip_outedges = ip_outedges;
index 40a12b6..ddaae76 100644 (file)
@@ -25,7 +25,9 @@
 #include "irgraph.h"
 #include "ircgcons.h"
 #include "firm_common_t.h"
+#include "typegmod.h"
 
+#include "array.h"
 
 /** ir_prog */
 struct ir_prog {
@@ -56,9 +58,58 @@ struct ir_prog {
 
 INLINE void remove_irp_type_from_list (type *typ);
 
+static INLINE type *
+__get_glob_type(void) {
+  assert(irp);
+  return irp->glob_type = skip_tid(irp->glob_type);
+}
+
+static INLINE int
+__get_irp_n_irgs(void) {
+  assert (irp && irp->graphs);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  return (ARR_LEN((irp)->graphs) - 1);
+}
+
+static INLINE ir_graph *
+__get_irp_irg(int pos){
+  assert (irp && irp->graphs);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  return irp->graphs[pos+1];
+}
+
+
+static INLINE int
+__get_irp_n_types (void) {
+  assert (irp && irp->types);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  return (ARR_LEN((irp)->types) - 1);
+}
+
+static INLINE type *
+__get_irp_type(int pos) {
+  assert (irp && irp->types);
+  /* Strangely the first element of the array is NULL.  Why??  */
+  /* Don't set the skip_tid result so that no double entries are generated. */
+  return skip_tid(irp->types[pos+1]);
+}
+
 #ifdef DEBUG_libfirm
 /** Returns a new, unique number to number nodes or the like. */
 int get_irp_new_node_nr(void);
 #endif
 
+static INLINE ir_graph *
+__get_const_code_irg(void)
+{
+  return irp->const_code_irg;
+}
+
+#define get_irp_n_irgs()       __get_irp_n_irgs()
+#define get_irp_irg(pos)       __get_irp_irg(pos)
+#define get_irp_n_types()      __get_irp_n_types()
+#define get_irp_type(pos)      __get_irp_type(pos)
+#define get_const_code_irg()   __get_const_code_irg()
+#define get_glob_type()        __get_glob_type()
+
 #endif /* ifndef _IRPROG_T_H_ */
index 581d0cf..752819b 100644 (file)
@@ -33,9 +33,8 @@ typedef enum {
   STAT_OPT_CONST_EVAL, /**< constant evaluation */
   STAT_LOWERED,                /**< lowered */
 
-  STAT_OPT_MAX
-}
-stat_opt_kind;
+  STAT_OPT_MAX        = 10
+} stat_opt_kind;
 
 /**
  * initialize the statistics module.
index eb05740..962d7a3 100644 (file)
 # include <config.h>
 #endif
 
-
 # include <stdlib.h>
 # include <stddef.h>
 # include <string.h>
+
 # include "type_t.h"
-# include "tpop_t.h"
+
 # include "irprog_t.h"
+# include "ircons.h"
+# include "tpop_t.h"
 # include "typegmod.h"
-# include "array.h"
-# include "irprog.h"
 # include "mangle.h"
-# include "tv.h"
-# include "ircons.h"
+# include "tv_t.h"
+
+# include "array.h"
 
 /*******************************************************************/
 /** TYPE                                                          **/
index 1780362..684af48 100644 (file)
 
 #include "type_identify.h"
 
-# include <stdlib.h>
-# include <stddef.h>
-# include <string.h>
-# include "type_t.h"
-# include "tpop_t.h"
-# include "irprog_t.h"
-# include "typegmod.h"
-# include "array.h"
-# include "irprog.h"
-# include "mangle.h"
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+
+#include "type_t.h"
+#include "tpop_t.h"
+#include "irprog_t.h"
+#include "typegmod.h"
+#include "array.h"
+#include "irprog_t.h"
+#include "mangle.h"
 #include "pset.h"
 
 /* The hash set for types. */
index 330b941..92a2aec 100644 (file)
@@ -44,7 +44,6 @@
 #include "set.h"            /* to store tarvals in */
 /* #include "tune.h" */          /* some constants */
 #include "entity_t.h"       /* needed to store pointers to entities */
-#include "irmode.h"         /* defines modes etc */
 #include "irmode_t.h"
 #include "irnode.h"         /* defines boolean return values (pnc_number)*/
 #include "host.h"
index dd47599..dda661f 100644 (file)
@@ -55,7 +55,7 @@ include $(topdir)/MakeRules
 CPPFLAGS += -I$(top_srcdir)/ir/adt -I$(top_srcdir)/ir/common -I$(top_srcdir)/ir/debug \
                -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/tr \
                -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/st  -I$(top_srcdir)/ir/ana \
-               -I$(top_srcdir)/ir/opt
+               -I$(top_srcdir)/ir/opt -I$(top_srcdir)/ir/stat
 
 LDFLAGS = -L$(topdir)
 LDFLAGS+= @LDFLAGS@
index 890d599..9c57e91 100644 (file)
@@ -77,9 +77,10 @@ main(void)
 
   /* build typeinformation of procedure main */
   owner = new_type_class (id_from_str ("ARRAY-STACK_EXAMPLE", 19));
-  proc_main = new_type_method(id_from_str("main_tp", 4), 0, 1);
+  proc_main = new_type_method(id_from_str("main_tp", 7), 0, 1);
   set_method_res_type(proc_main, 0, prim_t_int);
   proc_main_e = new_entity (owner, id_from_str ("main", 4), proc_main);
+  get_entity_ld_name(proc_main_e); /* force name mangling */
 
   /* make type information for the array and set the bounds */
 # define N_DIMS 1
index 604a1d7..f72c96b 100644 (file)
@@ -103,8 +103,9 @@ int main(int argc, char **argv)
 
   /* get the pointer to the procedure from the class type */
   /* this is how a pointer to be fixed by the linker is represented. */
-  proc_ptr = new_SymConst ((type_or_id_p)id_from_str (F_METHODNAME, strlen(F_METHODNAME)),
-                          linkage_ptr_info);
+  symconst_symbol sym;
+  sym.ident_p = new_id_from_str (F_METHODNAME);
+  proc_ptr = new_SymConst (sym, symconst_addr_name);
 
   /* call procedure set_a, first built array with parameters */
   {
index 48b7db3..765c2d3 100644 (file)
@@ -73,6 +73,7 @@ main(void)
 
   owner = new_type_class (id_from_str ("ENDLESS_LOOP_EXAMPLE", 20));
   ent = new_entity (owner, id_from_str ("main", strlen("main")), proc_main);
+  get_entity_ld_name(ent); /* force name mangling */
 
   /* Generates start and end blocks and nodes and a first, initial block */
   irg = new_ir_graph (ent, 4);
index d88c8c2..d8ba70c 100644 (file)
@@ -121,7 +121,8 @@ main(void)
 
   /* There is only one block in main, it contains the allocation and the calls. */
   /* Allocate the defined object and generate the type information. */
-  obj_size = new_SymConst((type_or_id_p)class_prima, size);
+  symconst_symbol sym = { class_prima };
+  obj_size = new_SymConst(sym, symconst_size);
   obj_o    = new_Alloc(get_store(), obj_size, class_prima, heap_alloc);
   set_store(new_Proj(obj_o, mode_M, 0));  /* make the changed memory visible */
   obj_o    = new_Proj(obj_o, mode_P, 2);  /* remember the pointer to the object */
index 0c2de25..a0d31c5 100644 (file)
@@ -119,7 +119,8 @@ main(void)
 
   /* There is only one block in main, it contains the allocation and the calls. */
   /* Allocate the defined object and generate the type information. */
-  obj_size = new_SymConst((type_or_id_p)class_prima, size);
+  symconst_symbol sym = {class_prima};
+  obj_size = new_SymConst(sym, symconst_size);
   obj_o    = new_Alloc(get_store(), obj_size, class_prima, heap_alloc);
   set_store(new_Proj(obj_o, mode_M, 0));  /* make the changed memory visible */
   obj_o    = new_Proj(obj_o, mode_P, 2);  /* remember the pointer to the object */
index 7f62155..302214c 100644 (file)
@@ -68,6 +68,7 @@ main(void)
 
   owner = new_type_class (id_from_str ("WHILE_EXAMPLE", 13));
   ent = new_entity (owner, id_from_str ("main", strlen("main")), proc_main);
+  get_entity_ld_name(ent); /* force name mangling */
 
   /* Generates start and end blocks and nodes and a first, initial block */
   irg = new_ir_graph (ent, 4);