aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/tree-ssa-pre.c14
-rw-r--r--gcc/tree.c62
-rw-r--r--gcc/tree.h5
4 files changed, 56 insertions, 36 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e84d9cd..190c7e6f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2004-09-11 Zack Weinberg <zack@codesourcery.com>
+
+ * tree.c (tree_code_size): New function, bulk of code from tree_size.
+ (tree_size, make_node): Use it.
+ * tree-ssa-pre.c (init_pre): Use it.
+ * tree.h: Prototype it.
+
2004-09-11 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
* tree-cfg.c (set_bb_for_stmt): Use PHI_BB.
@@ -91,11 +98,11 @@
* tree-pretty-print.c (dump_decl_name): Print unnamed decls as
D.xxx rather than <Dxxx>.
-2004-09-10 Adam Nemet <anemet@lnxw.com>
+2004-09-10 Adam Nemet <anemet@lnxw.com>
* configure.ac (AC_MSG_CHECKING(what linker to use)):
in_tree_ld_is_elf should be true for LynxOS.
- * configure: Regenerate.
+ * configure: Regenerate.
2004-09-10 Adam Nemet <anemet@lnxw.com>
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index b322755..bf332f4 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -1905,7 +1905,6 @@ eliminate (void)
static void
init_pre (void)
{
- size_t tsize;
basic_block bb;
connect_infinite_loops_to_exit ();
@@ -1937,13 +1936,12 @@ init_pre (void)
sizeof (struct value_set_node), 30);
calculate_dominance_info (CDI_POST_DOMINATORS);
calculate_dominance_info (CDI_DOMINATORS);
- tsize = tree_size (build (PLUS_EXPR, void_type_node, NULL_TREE, NULL_TREE));
- binary_node_pool = create_alloc_pool ("Binary tree nodes", tsize, 30);
- tsize = tree_size (build1 (NEGATE_EXPR, void_type_node, NULL_TREE));
- unary_node_pool = create_alloc_pool ("Unary tree nodes", tsize, 30);
- tsize = tree_size (build (COMPONENT_REF, void_type_node, NULL_TREE,
- NULL_TREE, NULL_TREE));
- reference_node_pool = create_alloc_pool ("Reference tree nodes", tsize, 30);
+ binary_node_pool = create_alloc_pool ("Binary tree nodes",
+ tree_code_size (PLUS_EXPR), 30);
+ unary_node_pool = create_alloc_pool ("Unary tree nodes",
+ tree_code_size (NEGATE_EXPR), 30);
+ reference_node_pool = create_alloc_pool ("Reference tree nodes",
+ tree_code_size (COMPONENT_REF), 30);
FOR_ALL_BB (bb)
{
EXP_GEN (bb) = set_new (true);
diff --git a/gcc/tree.c b/gcc/tree.c
index c7031e1..9ef5a62 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -142,12 +142,16 @@ decl_assembler_name (tree decl)
return DECL_CHECK (decl)->decl.assembler_name;
}
-/* Compute the number of bytes occupied by 'node'. This routine only
- looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH. */
+/* Compute the number of bytes occupied by a tree with code CODE. This
+ function cannot be used for TREE_VEC or PHI_NODE codes, which are of
+ variable length. */
size_t
-tree_size (tree node)
+tree_code_size (enum tree_code code)
{
- enum tree_code code = TREE_CODE (node);
+ /* We can't state the size of a TREE_VEC or PHI_NODE
+ without knowing how many elements it will have. */
+ gcc_assert (code != TREE_VEC);
+ gcc_assert (code != PHI_NODE);
switch (TREE_CODE_CLASS (code))
{
@@ -164,7 +168,7 @@ tree_size (tree node)
case '1': /* a unary arithmetic expression */
case '2': /* a binary arithmetic expression */
return (sizeof (struct tree_exp)
- + TREE_CODE_LENGTH (code) * sizeof (char *) - sizeof (char *));
+ + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
case 'c': /* a constant */
switch (code)
@@ -183,16 +187,11 @@ tree_size (tree node)
{
case IDENTIFIER_NODE: return lang_hooks.identifier_size;
case TREE_LIST: return sizeof (struct tree_list);
- case TREE_VEC: return (sizeof (struct tree_vec)
- + TREE_VEC_LENGTH(node) * sizeof(char *)
- - sizeof (char *));
case ERROR_MARK:
case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
- case PHI_NODE: return (sizeof (struct tree_phi_node)
- + (PHI_ARG_CAPACITY (node) - 1) *
- sizeof (struct phi_arg_d));
+ case PHI_NODE:
case SSA_NAME: return sizeof (struct tree_ssa_name);
@@ -209,9 +208,31 @@ tree_size (tree node)
}
}
-/* Return a newly allocated node of code CODE.
- For decl and type nodes, some other fields are initialized.
- The rest of the node is initialized to zero.
+/* Compute the number of bytes occupied by NODE. This routine only
+ looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
+size_t
+tree_size (tree node)
+{
+ enum tree_code code = TREE_CODE (node);
+ switch (code)
+ {
+ case PHI_NODE:
+ return (sizeof (struct tree_phi_node)
+ + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
+
+ case TREE_VEC:
+ return (sizeof (struct tree_vec)
+ + (TREE_VEC_LENGTH (node) - 1) * sizeof(char *));
+
+ default:
+ return tree_code_size (code);
+ }
+}
+
+/* Return a newly allocated node of code CODE. For decl and type
+ nodes, some other fields are initialized. The rest of the node is
+ initialized to zero. This function cannot be used for PHI_NODE or
+ TREE_VEC nodes, which is enforced by asserts in tree_code_size.
Achoo! I got a code in the node. */
@@ -220,21 +241,10 @@ make_node_stat (enum tree_code code MEM_STAT_DECL)
{
tree t;
int type = TREE_CODE_CLASS (code);
- size_t length;
+ size_t length = tree_code_size (code);
#ifdef GATHER_STATISTICS
tree_node_kind kind;
-#endif
- struct tree_common ttmp;
- /* We can't allocate a TREE_VEC, PHI_NODE, or STRING_CST
- without knowing how many elements it will have. */
- gcc_assert (code != TREE_VEC);
- gcc_assert (code != PHI_NODE);
-
- TREE_SET_CODE ((tree)&ttmp, code);
- length = tree_size ((tree)&ttmp);
-
-#ifdef GATHER_STATISTICS
switch (type)
{
case 'd': /* A decl node */
diff --git a/gcc/tree.h b/gcc/tree.h
index bdd95aa..0dd7eac 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2650,6 +2650,11 @@ extern tree decl_assembler_name (tree);
extern size_t tree_size (tree);
+/* Compute the number of bytes occupied by a tree with code CODE. This
+ function cannot be used for TREE_VEC or PHI_NODE codes, which are of
+ variable length. */
+extern size_t tree_code_size (enum tree_code);
+
/* Lowest level primitive for allocating a node.
The TREE_CODE is the only argument. Contents are initialized
to zero except for a few of the common fields. */