tree.c (tree_code_size): New function, bulk of code from tree_size.

* 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.

From-SVN: r87371
This commit is contained in:
Zack Weinberg 2004-09-11 21:14:39 +00:00
parent 68a97276d6
commit a38b644be6
4 changed files with 56 additions and 36 deletions

View File

@ -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> 2004-09-11 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
* tree-cfg.c (set_bb_for_stmt): Use PHI_BB. * tree-cfg.c (set_bb_for_stmt): Use PHI_BB.

View File

@ -1905,7 +1905,6 @@ eliminate (void)
static void static void
init_pre (void) init_pre (void)
{ {
size_t tsize;
basic_block bb; basic_block bb;
connect_infinite_loops_to_exit (); connect_infinite_loops_to_exit ();
@ -1937,13 +1936,12 @@ init_pre (void)
sizeof (struct value_set_node), 30); sizeof (struct value_set_node), 30);
calculate_dominance_info (CDI_POST_DOMINATORS); calculate_dominance_info (CDI_POST_DOMINATORS);
calculate_dominance_info (CDI_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",
binary_node_pool = create_alloc_pool ("Binary tree nodes", tsize, 30); tree_code_size (PLUS_EXPR), 30);
tsize = tree_size (build1 (NEGATE_EXPR, void_type_node, NULL_TREE)); unary_node_pool = create_alloc_pool ("Unary tree nodes",
unary_node_pool = create_alloc_pool ("Unary tree nodes", tsize, 30); tree_code_size (NEGATE_EXPR), 30);
tsize = tree_size (build (COMPONENT_REF, void_type_node, NULL_TREE, reference_node_pool = create_alloc_pool ("Reference tree nodes",
NULL_TREE, NULL_TREE)); tree_code_size (COMPONENT_REF), 30);
reference_node_pool = create_alloc_pool ("Reference tree nodes", tsize, 30);
FOR_ALL_BB (bb) FOR_ALL_BB (bb)
{ {
EXP_GEN (bb) = set_new (true); EXP_GEN (bb) = set_new (true);

View File

@ -142,12 +142,16 @@ decl_assembler_name (tree decl)
return DECL_CHECK (decl)->decl.assembler_name; return DECL_CHECK (decl)->decl.assembler_name;
} }
/* Compute the number of bytes occupied by 'node'. This routine only /* Compute the number of bytes occupied by a tree with code CODE. This
looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH. */ function cannot be used for TREE_VEC or PHI_NODE codes, which are of
variable length. */
size_t 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)) switch (TREE_CODE_CLASS (code))
{ {
@ -164,7 +168,7 @@ tree_size (tree node)
case '1': /* a unary arithmetic expression */ case '1': /* a unary arithmetic expression */
case '2': /* a binary arithmetic expression */ case '2': /* a binary arithmetic expression */
return (sizeof (struct tree_exp) return (sizeof (struct tree_exp)
+ TREE_CODE_LENGTH (code) * sizeof (char *) - sizeof (char *)); + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
case 'c': /* a constant */ case 'c': /* a constant */
switch (code) switch (code)
@ -183,16 +187,11 @@ tree_size (tree node)
{ {
case IDENTIFIER_NODE: return lang_hooks.identifier_size; case IDENTIFIER_NODE: return lang_hooks.identifier_size;
case TREE_LIST: return sizeof (struct tree_list); 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 ERROR_MARK:
case PLACEHOLDER_EXPR: return sizeof (struct tree_common); case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
case PHI_NODE: return (sizeof (struct tree_phi_node) case PHI_NODE:
+ (PHI_ARG_CAPACITY (node) - 1) *
sizeof (struct phi_arg_d));
case SSA_NAME: return sizeof (struct tree_ssa_name); 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. /* Compute the number of bytes occupied by NODE. This routine only
For decl and type nodes, some other fields are initialized. looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
The rest of the node is initialized to zero. 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. */ Achoo! I got a code in the node. */
@ -220,21 +241,10 @@ make_node_stat (enum tree_code code MEM_STAT_DECL)
{ {
tree t; tree t;
int type = TREE_CODE_CLASS (code); int type = TREE_CODE_CLASS (code);
size_t length; size_t length = tree_code_size (code);
#ifdef GATHER_STATISTICS #ifdef GATHER_STATISTICS
tree_node_kind kind; 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) switch (type)
{ {
case 'd': /* A decl node */ case 'd': /* A decl node */

View File

@ -2650,6 +2650,11 @@ extern tree decl_assembler_name (tree);
extern size_t tree_size (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. /* Lowest level primitive for allocating a node.
The TREE_CODE is the only argument. Contents are initialized The TREE_CODE is the only argument. Contents are initialized
to zero except for a few of the common fields. */ to zero except for a few of the common fields. */