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]: Add annotations for expression and constants


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)
 {


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