optimized construction of const nodes: time critical in jack compiler
authorGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Mon, 5 Jul 2004 14:27:17 +0000 (14:27 +0000)
committerGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Mon, 5 Jul 2004 14:27:17 +0000 (14:27 +0000)
[r3305]

ir/ir/ircons.c
ir/ir/iropt.c

index 1d881c3..d479d42 100644 (file)
@@ -21,7 +21,7 @@
 # include "ircons.h"
 # include "firm_common_t.h"
 # include "irvrfy.h"
-# include "irop.h"
+# include "irop_t.h"
 # include "iropt_t.h"
 # include "irgmod.h"
 # include "array.h"
@@ -132,17 +132,13 @@ INLINE ir_node *
 new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, type *tp)
 {
   ir_node *res;
-  res = new_ir_node (db, irg, block, op_Const, mode, 0, NULL);
+  res = new_ir_node (db, irg, irg->start_block, op_Const, mode, 0, NULL);
   res->attr.con.tv = con;
   set_Const_type(res, tp);  /* Call method because of complex assertion. */
   res = optimize_node (res);
   assert(get_Const_type(res) == tp);
   irn_vrfy_irg (res, irg);
 
-#if 0
-  res = local_optimize_newby (res);
-# endif
-
   return res;
 }
 
@@ -150,8 +146,10 @@ INLINE ir_node *
 new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
 {
   type *tp = unknown_type;
+  /* removing this somehow causes errors in jack. */
   if (tarval_is_entity(con))
     tp = find_pointer_type_to_type(get_entity_type(get_tarval_entity(con)));
+
   return new_rd_Const_type (db, irg, block, mode, con, tp);
 }
 
index 574e492..8daff11 100644 (file)
@@ -1482,27 +1482,35 @@ vt_cmp (const void *elt, const void *key)
   return 0;
 }
 
-/**
+/*
  * Calculate a hash value of a node.
  */
-static unsigned
+unsigned
 ir_node_hash (ir_node *node)
 {
   unsigned h;
   int i, irn_arity;
 
-  /* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
-  h = irn_arity = get_irn_arity(node);
+  if (node->op == op_Const) {
+    /* special value for const, as they only differ in their tarval. */
+    /* @@@ What about SymConst? */
+    h = ((unsigned) node->attr.con.tv)>>3 ;
+    h = 9*h + (unsigned)get_irn_mode(node);
+  } else {
 
-  /* consider all in nodes... except the block. */
-  for (i = 0;  i < irn_arity;  i++) {
-    h = 9*h + (unsigned long)get_irn_n(node, i);
-  }
+    /* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
+    h = irn_arity = get_irn_arity(node);
 
-  /* ...mode,... */
-  h = 9*h + (unsigned long) get_irn_mode (node);
-  /* ...and code */
-  h = 9*h + (unsigned long) get_irn_op (node);
+    /* consider all in nodes... except the block. */
+    for (i = 0;  i < irn_arity;  i++) {
+      h = 9*h + (unsigned)get_irn_n(node, i);
+    }
+
+    /* ...mode,... */
+    h = 9*h + (unsigned) get_irn_mode (node);
+    /* ...and code */
+    h = 9*h + (unsigned) get_irn_op (node);
+  }
 
   return h;
 }
@@ -1522,6 +1530,10 @@ del_identities (pset *value_table)
 /**
  * Return the canonical node computing the same value as n.
  * Looks up the node in a hash table.
+ *
+ * For Const nodes this is performed in the constructor, too.  Const
+ * nodes are extremely time critical because of their frequent use in
+ * constant string arrays.
  */
 static INLINE ir_node *
 identify (pset *value_table, ir_node *n)
@@ -1550,7 +1562,7 @@ identify (pset *value_table, ir_node *n)
 
 /**
  * During construction we set the pinned flag in the graph right when the
- * optimizatin is performed.  The flag turning on procedure global cse could
+ * optimization is performed.  The flag turning on procedure global cse could
  * be changed between two allocations.  This way we are safe.
  */
 static INLINE ir_node *