public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Daniel Berlin <dberlin@dberlin.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH]: Add annotations for expression and constants
Date: Sun, 06 Jun 2004 18:27:00 -0000	[thread overview]
Message-ID: <1C733CAA-B7D9-11D8-909E-000A95DA505C@dberlin.org> (raw)

This is used by GVN-PRE.

The reason we annotate expressions is so we can cache the value  
handle/number in the expression on the RHS.
This avoids looking expressions up in the hash table again and again to  
get the value number (it's an optimization, not a correctness issue) of  
a particular RHS in different parts of GVN-PRE, such as during phi  
translation. This optimization makes a factor of 2 difference on some  
testcases (particularly those where right now, iterative_hash_expr  
called by DOM is high on the profile).  We can throw away these  
annotations after GVN-PRE is finished, since at that point, all the  
SSA_NAME's are annotated, so they don't waste a ton of memory.

The reason we annotate constants is twofold:
First, consistency.  If you didn't annotate them, you'd start having to  
special casing them where we get value numbers.
Second, not all constants with the same "value" are shared (ie  
different types, etc), but we want to be able to simply do "==" to tell  
if two value handles are the same value.  Thus, we need to annotate  
them with their own value handles so we can do get_value_handle on two  
constants, and == will be true if they have the same value.

All of this is gone over in detail at the top of the new  
tree-ssa-pre.c, of course.


2004-06-05  Daniel Berlin  <dberlin@dberlin.org>

	* tree-flow.h (tree_ann_type): Add CST_ANN, EXPR_ANN.
	(struct cst_ann_d): New.
	(struct expr_ann_d): New.
	(union tree_ann_d): Add cst_ann, expr_ann.
	* tree-dfa.c (create_cst_ann): New function.
	(create_expr_ann): Ditto.
	* tree-flow-inline.h (cst_ann): New function.
	(expr_ann): Ditto.
	(get_cst_ann): Ditto.
	(get_expr_ann): Ditto..

Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-flow.h,v
retrieving revision 2.4
diff -u -3 -p -r2.4 tree-flow.h
--- tree-flow.h	18 May 2004 02:53:55 -0000	2.4
+++ tree-flow.h	6 Jun 2004 16:04:13 -0000
@@ -40,7 +40,8 @@ typedef struct basic_block_def *basic_bl
   
/ 
*----------------------------------------------------------------------- 
----
  		   Tree annotations stored in tree_common.ann
   
------------------------------------------------------------------------ 
---*/
-enum tree_ann_type { TREE_ANN_COMMON, VAR_ANN, STMT_ANN, SSA_NAME_ANN  
};
+enum tree_ann_type { TREE_ANN_COMMON, VAR_ANN, CST_ANN, EXPR_ANN,  
STMT_ANN,
+		     SSA_NAME_ANN };

  struct tree_ann_common_d GTY(())
  {
@@ -277,6 +283,25 @@ struct ssa_name_ann_d GTY(())
       pointer will be represented by this memory tag, instead of the  
type
       tag computed by TBAA.  */
    tree name_mem_tag;
+};
+
+struct cst_ann_d GTY (())
+{
+  struct tree_ann_common_d common;
+
+};
+
+struct expr_ann_d GTY(())
+{
+  struct tree_ann_common_d common;
+
  };


@@ -284,6 +309,8 @@ union tree_ann_d GTY((desc ("ann_type ((
  {
    struct tree_ann_common_d GTY((tag ("TREE_ANN_COMMON"))) common;
    struct var_ann_d GTY((tag ("VAR_ANN"))) decl;
+  struct expr_ann_d GTY((tag ("EXPR_ANN"))) expr;
+  struct cst_ann_d GTY((tag ("CST_ANN"))) cst;
    struct stmt_ann_d GTY((tag ("STMT_ANN"))) stmt;
    struct ssa_name_ann_d GTY((tag ("SSA_NAME_ANN"))) ssa_name;
  };
@@ -292,7 +319,13 @@ typedef union tree_ann_d *tree_ann;
  typedef struct var_ann_d *var_ann_t;
  typedef struct stmt_ann_d *stmt_ann_t;
  typedef struct ssa_name_ann_d *ssa_name_ann_t;
+typedef struct expr_ann_d *expr_ann_t;
+typedef struct cst_ann_d *cst_ann_t;

+static inline cst_ann_t cst_ann (tree);
+static inline cst_ann_t get_cst_ann (tree);
+static inline expr_ann_t expr_ann (tree);
+static inline expr_ann_t get_expr_ann (tree);
  static inline var_ann_t var_ann (tree);
  static inline var_ann_t get_var_ann (tree);
  static inline stmt_ann_t stmt_ann (tree);
@@ -486,6 +519,8 @@ extern void dump_generic_bb (FILE *, bas

  /* In tree-dfa.c  */
  extern var_ann_t create_var_ann (tree);
+extern cst_ann_t create_cst_ann (tree);
+extern expr_ann_t create_expr_ann (tree);
  extern stmt_ann_t create_stmt_ann (tree);
  extern ssa_name_ann_t create_ssa_name_ann (tree);
  extern tree create_phi_node (tree, basic_block);
Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-dfa.c,v
retrieving revision 2.5
diff -u -3 -p -r2.5 tree-dfa.c
--- tree-dfa.c	30 May 2004 18:32:29 -0000	2.5
+++ tree-dfa.c	6 Jun 2004 16:04:13 -0000
@@ -462,6 +462,52 @@ create_stmt_ann (tree t)
  }


+/* Create a new annotation for a constant T.  */
+
+cst_ann_t
+create_cst_ann (tree t)
+{
+  cst_ann_t ann;
+
+#if defined ENABLE_CHECKING
+  if (t == NULL_TREE
+      || (t->common.ann
+	  && t->common.ann->common.type != CST_ANN))
+    abort ();
+#endif
+
+  ann = ggc_alloc (sizeof (*ann));
+  memset ((void *) ann, 0, sizeof (*ann));
+
+  ann->common.type = CST_ANN;
+  t->common.ann = (tree_ann) ann;
+
+  return ann;
+}
+
+/* Create a new annotation for an expression T.  */
+
+expr_ann_t
+create_expr_ann (tree t)
+{
+  expr_ann_t ann;
+
+#if defined ENABLE_CHECKING
+  if (t == NULL_TREE
+      || (t->common.ann
+	  && t->common.ann->common.type != EXPR_ANN))
+    abort ();
+#endif
+
+  ann = ggc_alloc (sizeof (*ann));
+  memset ((void *) ann, 0, sizeof (*ann));
+
+  ann->common.type = EXPR_ANN;
+  t->common.ann = (tree_ann) ann;
+
+  return ann;
+}
+
  /* Create a new annotation for an SSA name T.  */

  ssa_name_ann_t
Index: tree-flow-inline.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-flow-inline.h,v
retrieving revision 2.2
diff -u -3 -p -r2.2 tree-flow-inline.h
--- tree-flow-inline.h	21 May 2004 15:24:54 -0000	2.2
+++ tree-flow-inline.h	6 Jun 2004 16:04:13 -0000
@@ -46,6 +46,47 @@ get_var_ann (tree var)
    return (ann) ? ann : create_var_ann (var);
  }

+
+static inline cst_ann_t
+cst_ann (tree t)
+{
+#if defined ENABLE_CHECKING
+  if (TREE_CODE_CLASS (TREE_CODE (t)) != 'c'
+      || (t->common.ann
+	  && t->common.ann->common.type != CST_ANN))
+    abort ();
+#endif
+
+  return (cst_ann_t) t->common.ann;
+}
+
+static inline cst_ann_t
+get_cst_ann (tree var)
+{
+  cst_ann_t ann = cst_ann (var);
+  return (ann) ? ann : create_cst_ann (var);
+}
+
+static inline expr_ann_t
+expr_ann (tree t)
+{
+#if defined ENABLE_CHECKING
+  if (!EXPR_P (t)
+      || (t->common.ann
+	  && t->common.ann->common.type != EXPR_ANN))
+    abort ();
+#endif
+
+  return (expr_ann_t) t->common.ann;
+}
+
+static inline expr_ann_t
+get_expr_ann (tree var)
+{
+  expr_ann_t ann = expr_ann (var);
+  return (ann) ? ann : create_expr_ann (var);
+}
+
  static inline stmt_ann_t
  stmt_ann (tree t)
  {

             reply	other threads:[~2004-06-06 16:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-06 18:27 Daniel Berlin [this message]
2004-06-10 14:28 ` Diego Novillo
2004-06-10 14:28   ` Daniel Berlin
2004-06-10 14:55     ` Diego Novillo
2004-06-10 15:38       ` Daniel Berlin
2004-06-15 16:14 ` Mark Mitchell
2004-06-15 19:09   ` [PATCH]: Add documentation for functions in tree-flow-inline.h Daniel Berlin
2004-06-15 19:26     ` Mark Mitchell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1C733CAA-B7D9-11D8-909E-000A95DA505C@dberlin.org \
    --to=dberlin@dberlin.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).