This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Speed up genattrtab


Hi!

The following patch speeds up genattrtab on x86_64-linux from
11.17s (average from 10 runs) down to 7.82s (30% speedup; for x86_64-linux
-> ia64-linux cross that's just 17% speedup).
The number of attributes is usually far smaller than the number of
instructions in machine description.
When simplify_test_exp is called during optimize_attrs, we don't
need to look through all instructions to find which value a given
attribute has in a given insn_code instruction, instead we can just
look through the chain of all attribute/value/ie values a given instruction
has.  Tested on x86_64-linux (native) and cross to ia64-linux, genattrtab
generated identical output without and with this patch.

Ok for trunk?

2006-12-29  Jakub Jelinek  <jakub@redhat.com>

	* genattrtab.c (struct attr_value_list, insn_code_values): Move to
	file scope from optimize_attrs.
	(simplify_test_exp): If insn_code_values is not NULL, use it to speed
	up search.
	(optimize_attrs): Clear insn_code_values after freeing it.

--- gcc/genattrtab.c.jj	2006-11-01 10:31:36.000000000 +0100
+++ gcc/genattrtab.c	2006-12-29 11:39:23.000000000 +0100
@@ -1,6 +1,6 @@
 /* Generate code from machine description to compute values of attributes.
    Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
 
 This file is part of GCC.
@@ -189,6 +189,14 @@ struct delay_desc
   int lineno;			/* Line number.  */
 };
 
+struct attr_value_list
+{
+  struct attr_value *av;
+  struct insn_ent *ie;
+  struct attr_desc *attr;
+  struct attr_value_list *next;
+};
+
 /* Listheads of above structures.  */
 
 /* This one is indexed by the first character of the attribute name.  */
@@ -196,6 +204,7 @@ struct delay_desc
 static struct attr_desc *attrs[MAX_ATTRS_INDEX];
 static struct insn_def *defs;
 static struct delay_desc *delays;
+struct attr_value_list **insn_code_values;
 
 /* Other variables.  */
 
@@ -2448,6 +2457,7 @@ simplify_test_exp (rtx exp, int insn_cod
   struct attr_desc *attr;
   struct attr_value *av;
   struct insn_ent *ie;
+  struct attr_value_list *iv;
   int i;
   rtx newexp = exp;
   bool left_alt, right_alt;
@@ -2718,16 +2728,36 @@ simplify_test_exp (rtx exp, int insn_cod
 	 would give this insn the values being tested for.  */
       if (insn_code >= 0
 	  && (attr = find_attr (&XSTR (exp, 0), 0)) != NULL)
-	for (av = attr->first_value; av; av = av->next)
-	  for (ie = av->first_insn; ie; ie = ie->next)
-	    if (ie->def->insn_code == insn_code)
-	      {
-		rtx x;
-		x = evaluate_eq_attr (exp, av->value, insn_code, insn_index);
-		x = SIMPLIFY_TEST_EXP (x, insn_code, insn_index);
-		if (attr_rtx_cost(x) < 20)
-		  return x;
-	      }
+	{
+	  rtx x;
+
+	  av = NULL;
+	  if (insn_code_values)
+	    {
+	      for (iv = insn_code_values[insn_code]; iv; iv = iv->next)
+		if (iv->attr == attr)
+		  {
+		    av = iv->av;
+		    break;
+		  }
+	    }
+	  else
+	    {
+	      for (av = attr->first_value; av; av = av->next)
+		for (ie = av->first_insn; ie; ie = ie->next)
+		  if (ie->def->insn_code == insn_code)
+		    goto got_av;
+	    }
+
+	  if (av)
+	    {
+	    got_av:
+	      x = evaluate_eq_attr (exp, av->value, insn_code, insn_index);
+	      x = SIMPLIFY_TEST_EXP (x, insn_code, insn_index);
+	      if (attr_rtx_cost(x) < 20)
+		return x;
+	    }
+	}
       break;
 
     default:
@@ -2756,14 +2786,6 @@ optimize_attrs (void)
   struct insn_ent *ie;
   rtx newexp;
   int i;
-  struct attr_value_list
-  {
-    struct attr_value *av;
-    struct insn_ent *ie;
-    struct attr_desc *attr;
-    struct attr_value_list *next;
-  };
-  struct attr_value_list **insn_code_values;
   struct attr_value_list *ivbuf;
   struct attr_value_list *iv;
 
@@ -2840,6 +2862,7 @@ optimize_attrs (void)
 
   free (ivbuf);
   free (insn_code_values - 2);
+  insn_code_values = NULL;
 }
 
 /* Clear the ATTR_CURR_SIMPLIFIED_P flag in EXP and its subexpressions.  */

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]