From 8d5e6e2527f07e6cfda3b62f1fd826006931d551 Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Sat, 27 May 2000 15:21:17 +0000 Subject: [PATCH] tree.h (TREE_CODE_LENGTH): New macro. * tree.h (TREE_CODE_LENGTH): New macro. * c-common.c (c_find_base_decl): Use it. * expr.c (safe_from_p): Likewise. * print-tree.c (print_node): Likewise. * tree.c (make_node, copy_node, get_identifier): Likewie. (first_rtl_op, contains_placeholder_p, substitute_in_expr): Likewise. (build, build_nt, build_parse_node, simple_cst_equal): Likewise. * fold-const.c (make_range): Likewise. (fold): Likewise; also use first_rtl_op. * c-iterate.c (collect_iterators): Use first_rtl_op. * calls.c (calls_function_1): Likewise; also rename TYPE to CLASS. Use IS_EXPR_CODE_CLASS. (preexpand_calls): Likewise. * ggc-common.c (ggc_mark_trees): Rework to use first_rtl_op and TREE_CODE_LENGTH. * stmt.c (warn_if_unused_value): If no operands, no unused value. * ch/lang.c (deep_const_expr): Use first_rtl_op. * ch/satisfy.c (satisfy): Use TREE_CODE_LENGTH. * cp/method.c (mangle_expression): Use TREE_CODE_LENGTH. * cp/tree.c (break_out_calls, build_min_nt): Use TREE_CODE_LENGTH. (built_min, cp_tree_equal): Likewise. From-SVN: r34203 --- gcc/ChangeLog | 19 +++++++++++++++++++ gcc/c-common.c | 2 +- gcc/c-iterate.c | 20 +------------------- gcc/calls.c | 42 ++++++++++++++---------------------------- gcc/ch/ChangeLog | 5 +++++ gcc/ch/lang.c | 9 +++++---- gcc/ch/satisfy.c | 3 ++- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/method.c | 2 +- gcc/cp/tree.c | 10 +++++----- gcc/expr.c | 15 +++++++-------- gcc/ggc-common.c | 31 +++++++++++-------------------- gcc/print-tree.c | 4 +++- gcc/stmt.c | 8 ++++++++ gcc/tree.c | 32 ++++++++++++++++---------------- gcc/tree.h | 5 +++-- 16 files changed, 107 insertions(+), 106 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a643cd2d3c8..886a7e26fbf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,22 @@ +Sat May 27 11:01:27 2000 Richard Kenner + + * tree.h (TREE_CODE_LENGTH): New macro. + * c-common.c (c_find_base_decl): Use it. + * expr.c (safe_from_p): Likewise. + * print-tree.c (print_node): Likewise. + * tree.c (make_node, copy_node, get_identifier): Likewie. + (first_rtl_op, contains_placeholder_p, substitute_in_expr): Likewise. + (build, build_nt, build_parse_node, simple_cst_equal): Likewise. + * fold-const.c (make_range): Likewise. + (fold): Likewise; also use first_rtl_op. + * c-iterate.c (collect_iterators): Use first_rtl_op. + * calls.c (calls_function_1): Likewise; also rename TYPE to CLASS. + Use IS_EXPR_CODE_CLASS. + (preexpand_calls): Likewise. + * ggc-common.c (ggc_mark_trees): Rework to use first_rtl_op + and TREE_CODE_LENGTH. + * stmt.c (warn_if_unused_value): If no operands, no unused value. + 2000-05-26 Geoffrey Keating * config/rs6000/rs6000.md (movsi_internal1): Use '%a1' rather diff --git a/gcc/c-common.c b/gcc/c-common.c index 4631417b90d..6989d4016de 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -3297,7 +3297,7 @@ c_find_base_decl (t) case '1': case '2': case '3': - for (i = tree_code_length [(int) TREE_CODE (t)]; --i >= 0;) + for (i = TREE_CODE_LENGTH (TREE_CODE (t)); --i >= 0;) { tree d = c_find_base_decl (TREE_OPERAND (t, i)); if (d) diff --git a/gcc/c-iterate.c b/gcc/c-iterate.c index 1692d2a4bf0..0e545d80d9d 100644 --- a/gcc/c-iterate.c +++ b/gcc/c-iterate.c @@ -241,27 +241,9 @@ collect_iterators (exp, list) case 'e': case 'r': { - int num_args = tree_code_length[(int) TREE_CODE (exp)]; + int num_args = first_rtl_op (TREE_CODE (exp)); int i; - /* Some tree codes have RTL, not trees, as operands. */ - switch (TREE_CODE (exp)) - { - case CALL_EXPR: - num_args = 2; - break; - case METHOD_CALL_EXPR: - num_args = 3; - break; - case WITH_CLEANUP_EXPR: - num_args = 1; - break; - case RTL_EXPR: - return list; - default: - break; - } - for (i = 0; i < num_args; i++) list = collect_iterators (TREE_OPERAND (exp, i), list); return list; diff --git a/gcc/calls.c b/gcc/calls.c index 1c2c2eacec2..08ab00d9f9e 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -238,12 +238,15 @@ calls_function (exp, which) int which; { int val; + calls_function_save_exprs = 0; val = calls_function_1 (exp, which); calls_function_save_exprs = 0; return val; } +/* Recursive function to do the work of above function. */ + static int calls_function_1 (exp, which) tree exp; @@ -251,8 +254,8 @@ calls_function_1 (exp, which) { register int i; enum tree_code code = TREE_CODE (exp); - int type = TREE_CODE_CLASS (code); - int length = tree_code_length[(int) code]; + int class = TREE_CODE_CLASS (code); + int length = first_rtl_op (code); /* If this code is language-specific, we don't know what it will do. */ if ((int) code >= NUM_TREE_CODES) @@ -265,16 +268,12 @@ calls_function_1 (exp, which) return 1; else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) - == FUNCTION_DECL)) - { - tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); - int flags = special_function_p (fndecl, 0); - if (flags & ECF_MAY_BE_ALLOCA) - return 1; - } + == FUNCTION_DECL) + && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0), + 0) + & ECF_MAY_BE_ALLOCA)) + return 1; - /* Third operand is RTL. */ - length = 2; break; case SAVE_EXPR: @@ -290,14 +289,12 @@ calls_function_1 (exp, which) case BLOCK: { register tree local; + register tree subblock; for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local)) if (DECL_INITIAL (local) != 0 && calls_function_1 (DECL_INITIAL (local), which)) return 1; - } - { - register tree subblock; for (subblock = BLOCK_SUBBLOCKS (exp); subblock; @@ -306,30 +303,19 @@ calls_function_1 (exp, which) return 1; } return 0; + case TREE_LIST: for (; exp != 0; exp = TREE_CHAIN (exp)) if (calls_function_1 (TREE_VALUE (exp), which)) return 1; return 0; - case METHOD_CALL_EXPR: - length = 3; - break; - - case WITH_CLEANUP_EXPR: - length = 1; - break; - - case RTL_EXPR: - return 0; - default: break; } - /* Only expressions and references can contain calls. */ - if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r' - && type != 'b') + /* Only expressions, references, and blocks can contain calls. */ + if (! IS_EXPR_CODE_CLASS (class) && class != 'r' && class != 'b') return 0; for (i = 0; i < length; i++) diff --git a/gcc/ch/ChangeLog b/gcc/ch/ChangeLog index 24991a04bc5..30c39a24058 100644 --- a/gcc/ch/ChangeLog +++ b/gcc/ch/ChangeLog @@ -1,3 +1,8 @@ +Sat May 27 11:24:26 2000 Richard Kenner + + * lang.c (deep_const_expr): Use first_rtl_op. + * satisfy.c (satisfy): Use TREE_CODE_LENGTH. + 2000-05-18 Chris Demetriou * Makefile.in (hash.h): Delete a redundant use of gawk and sed. diff --git a/gcc/ch/lang.c b/gcc/ch/lang.c index 9a2f822fc1a..985eea7bffc 100644 --- a/gcc/ch/lang.c +++ b/gcc/ch/lang.c @@ -53,8 +53,9 @@ extern FILE* finput; static int deep_const_expr PARAMS ((tree)); static void chill_print_error_function PARAMS ((const char *)); -/* return 1 if the expression tree given has all - constant nodes as its leaves; return 0 otherwise. */ +/* Return 1 if the expression tree given has all + constant nodes as its leaves,otherwise. */ + static int deep_const_expr (exp) tree exp; @@ -67,13 +68,13 @@ deep_const_expr (exp) return 0; code = TREE_CODE (exp); - length = tree_code_length[(int) code]; + length = first_rtl_op (TREE_CODE (exp)); /* constant leaf? return TRUE */ if (TREE_CODE_CLASS (code) == 'c') return 1; - /* recursively check next level down */ + /* Recursively check next level down. */ for (i = 0; i < length; i++) if (! deep_const_expr (TREE_OPERAND (exp, i))) return 0; diff --git a/gcc/ch/satisfy.c b/gcc/ch/satisfy.c index 8fa46de3966..a15d9e20a31 100644 --- a/gcc/ch/satisfy.c +++ b/gcc/ch/satisfy.c @@ -371,7 +371,8 @@ satisfy (exp, chain) default: ; } - arg_length = tree_code_length[TREE_CODE (exp)]; + + arg_length = TREE_CODE_LENGTH (TREE_CODE (exp)); for (i = 0; i < arg_length; i++) SATISFY (TREE_OPERAND (exp, i)); return exp; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1acde7b16b7..895babc9cf0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +Sat May 27 11:25:46 2000 Richard Kenner + + * method.c (mangle_expression): Use TREE_CODE_LENGTH. + * tree.c (break_out_calls, build_min_nt): Use TREE_CODE_LENGTH. + (built_min, cp_tree_equal): Likewise. + 2000-05-26 Mark Mitchell * class.c (layout_nonempty_base_or_field): Replace diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 6d34795fe9a..1f595e05015 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -519,7 +519,7 @@ mangle_expression (value) if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value)))) { int i; - int operands = tree_code_length[(int) TREE_CODE (value)]; + int operands = TREE_CODE_LENGTH (TREE_CODE (value)); tree id; const char *name; diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 646a892fe79..b62fc611625 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -405,7 +405,7 @@ break_out_calls (exp) case 'e': /* an expression */ case 'r': /* a reference */ case 's': /* an expression with side effects */ - for (i = tree_code_length[(int) code] - 1; i >= 0; i--) + for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; i--) { t1 = break_out_calls (TREE_OPERAND (exp, i)); if (t1 != TREE_OPERAND (exp, i)) @@ -427,7 +427,7 @@ break_out_calls (exp) changed = 1; if (changed) { - if (tree_code_length[(int) code] == 1) + if (TREE_CODE_LENGTH (code) == 1) return build1 (code, TREE_TYPE (exp), t1); else return build (code, TREE_TYPE (exp), t1, t2); @@ -1659,7 +1659,7 @@ build_min_nt VPARAMS ((enum tree_code code, ...)) #endif t = make_node (code); - length = tree_code_length[(int) code]; + length = TREE_CODE_LENGTH (code); TREE_COMPLEXITY (t) = lineno; for (i = 0; i < length; i++) @@ -1695,7 +1695,7 @@ build_min VPARAMS ((enum tree_code code, tree tt, ...)) #endif t = make_node (code); - length = tree_code_length[(int) code]; + length = TREE_CODE_LENGTH (code); TREE_TYPE (t) = tt; TREE_COMPLEXITY (t) = lineno; @@ -1944,7 +1944,7 @@ cp_tree_equal (t1, t2) case 'r': case 's': cmp = 1; - for (i=0; i= 0) ggc_mark_tree (TREE_VEC_ELT (t, i)); continue; } - case SAVE_EXPR: - ggc_mark_tree (TREE_OPERAND (t, 0)); - ggc_mark_tree (SAVE_EXPR_CONTEXT (t)); - ggc_mark_rtx (SAVE_EXPR_RTL (t)); - continue; - - case RTL_EXPR: - ggc_mark_rtx (RTL_EXPR_SEQUENCE (t)); - ggc_mark_rtx (RTL_EXPR_RTL (t)); - continue; - - case CALL_EXPR: - ggc_mark_tree (TREE_OPERAND (t, 0)); - ggc_mark_tree (TREE_OPERAND (t, 1)); - ggc_mark_rtx (CALL_EXPR_RTL (t)); - continue; - case COMPLEX_CST: ggc_mark_tree (TREE_REALPART (t)); ggc_mark_tree (TREE_IMAGPART (t)); @@ -450,10 +434,17 @@ ggc_mark_trees () case 'r': case '<': case '1': case '2': case 'e': case 's': /* Expressions. */ { - int i = tree_code_length[TREE_CODE (t)]; + int i = TREE_CODE_LENGTH (TREE_CODE (t)); + int first_rtl = first_rtl_op (TREE_CODE (t)); + while (--i >= 0) - ggc_mark_tree (TREE_OPERAND (t, i)); - break; + { + if (i >= first_rtl) + ggc_mark_rtx ((rtx) TREE_OPERAND (t, i)); + else + ggc_mark_tree (TREE_OPERAND (t, i)); + } + break; } case 'x': diff --git a/gcc/print-tree.c b/gcc/print-tree.c index e86a51cf974..ae409e54610 100644 --- a/gcc/print-tree.c +++ b/gcc/print-tree.c @@ -580,10 +580,12 @@ print_node (file, prefix, node, indent) break; } - len = tree_code_length[(int) TREE_CODE (node)]; + len = TREE_CODE_LENGTH (TREE_CODE (node)); + /* Some nodes contain rtx's, not trees, after a certain point. Print the rtx's as rtx's. */ first_rtl = first_rtl_op (TREE_CODE (node)); + for (i = 0; i < len; i++) { if (i >= first_rtl) diff --git a/gcc/stmt.c b/gcc/stmt.c index 76dcdc364ef..a1beb46ca9a 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -2004,6 +2004,14 @@ warn_if_unused_value (exp) || TREE_CODE_CLASS (TREE_CODE (exp)) == 'r') && TREE_THIS_VOLATILE (exp)) return 0; + + /* If this is an expression which has no operands, there is no value + to be unused. There are no such language-independent codes, + but front ends may define such. */ + if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'e' + && TREE_CODE_LENGTH (TREE_CODE (exp)) == 0) + return 0; + warn: warning_with_file_and_line (emit_filename, emit_lineno, "value computed is not used"); diff --git a/gcc/tree.c b/gcc/tree.c index a62e1308304..c2bfab8baa4 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -996,7 +996,7 @@ make_node (code) if (code == BIND_EXPR && obstack != &permanent_obstack) obstack = saveable_obstack; length = sizeof (struct tree_exp) - + (tree_code_length[(int) code] - 1) * sizeof (char *); + + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *); break; case 'c': /* a constant */ @@ -1005,7 +1005,7 @@ make_node (code) #endif obstack = expression_obstack; - /* We can't use tree_code_length for INTEGER_CST, since the number of + /* We can't use TREE_CODE_LENGTH for INTEGER_CST, since the number of words is machine-dependent due to varying length of HOST_WIDE_INT, which might be wider than a pointer (e.g., long long). Similarly for REAL_CST, since the number of words is machine-dependent due @@ -1017,7 +1017,7 @@ make_node (code) length = sizeof (struct tree_real_cst); else length = sizeof (struct tree_common) - + tree_code_length[(int) code] * sizeof (char *); + + TREE_CODE_LENGTH (code) * sizeof (char *); break; case 'x': /* something random, like an identifier. */ @@ -1032,7 +1032,7 @@ make_node (code) kind = x_kind; #endif length = sizeof (struct tree_common) - + tree_code_length[(int) code] * sizeof (char *); + + TREE_CODE_LENGTH (code) * sizeof (char *); /* Identifier nodes are always permanent since they are unique in a compiler run. */ if (code == IDENTIFIER_NODE) obstack = &permanent_obstack; @@ -1171,11 +1171,11 @@ copy_node (node) case '1': /* a unary arithmetic expression */ case '2': /* a binary arithmetic expression */ length = sizeof (struct tree_exp) - + (tree_code_length[(int) code] - 1) * sizeof (char *); + + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *); break; case 'c': /* a constant */ - /* We can't use tree_code_length for INTEGER_CST, since the number of + /* We can't use TREE_CODE_LENGTH for INTEGER_CST, since the number of words is machine-dependent due to varying length of HOST_WIDE_INT, which might be wider than a pointer (e.g., long long). Similarly for REAL_CST, since the number of words is machine-dependent due @@ -1186,12 +1186,12 @@ copy_node (node) length = sizeof (struct tree_real_cst); else length = (sizeof (struct tree_common) - + tree_code_length[(int) code] * sizeof (char *)); + + TREE_CODE_LENGTH (code) * sizeof (char *)); break; case 'x': /* something random, like an identifier. */ length = sizeof (struct tree_common) - + tree_code_length[(int) code] * sizeof (char *); + + TREE_CODE_LENGTH (code) * sizeof (char *); if (code == TREE_VEC) length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *); } @@ -1298,7 +1298,7 @@ get_identifier (text) break; } - if (tree_code_length[(int) IDENTIFIER_NODE] < 0) + if (TREE_CODE_LENGTH (IDENTIFIER_NODE) < 0) abort (); /* set_identifier_size hasn't been called. */ /* Not found, create one, add to chain */ @@ -2590,7 +2590,7 @@ first_rtl_op (code) case METHOD_CALL_EXPR: return 3; default: - return tree_code_length [(int) code]; + return TREE_CODE_LENGTH (code); } } @@ -2862,7 +2862,7 @@ contains_placeholder_p (exp) break; } - switch (tree_code_length[(int) code]) + switch (TREE_CODE_LENGTH (code)) { case 1: return contains_placeholder_p (TREE_OPERAND (exp, 0)); @@ -2981,7 +2981,7 @@ substitute_in_expr (exp, f, r) case '2': case '<': case 'e': - switch (tree_code_length[(int) code]) + switch (TREE_CODE_LENGTH (code)) { case 1: op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); @@ -3301,7 +3301,7 @@ build VPARAMS ((enum tree_code code, tree tt, ...)) #endif t = make_node (code); - length = tree_code_length[(int) code]; + length = TREE_CODE_LENGTH (code); TREE_TYPE (t) = tt; /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_RAISED for @@ -3451,7 +3451,7 @@ build_nt VPARAMS ((enum tree_code code, ...)) #endif t = make_node (code); - length = tree_code_length[(int) code]; + length = TREE_CODE_LENGTH (code); for (i = 0; i < length; i++) TREE_OPERAND (t, i) = va_arg (p, tree); @@ -3484,7 +3484,7 @@ build_parse_node VPARAMS ((enum tree_code code, ...)) expression_obstack = &temp_decl_obstack; t = make_node (code); - length = tree_code_length[(int) code]; + length = TREE_CODE_LENGTH (code); for (i = 0; i < length; i++) TREE_OPERAND (t, i) = va_arg (p, tree); @@ -4529,7 +4529,7 @@ simple_cst_equal (t1, t2) case 'r': case 's': cmp = 1; - for (i = 0; i < tree_code_length[(int) code1]; i++) + for (i = 0; i < TREE_CODE_LENGTH (code1); i++) { cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); if (cmp <= 0) diff --git a/gcc/tree.h b/gcc/tree.h index f4733d29fba..13d079a7624 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -39,8 +39,8 @@ enum tree_code { #undef DEFTREECODE -/* Number of tree codes. */ -#define NUM_TREE_CODES ((int)LAST_AND_UNUSED_TREE_CODE) +/* Number of language-independent tree codes. */ +#define NUM_TREE_CODES ((int) LAST_AND_UNUSED_TREE_CODE) /* Indexed by enum tree_code, contains a character which is `<' for a comparison expression, `1', for a unary arithmetic @@ -62,6 +62,7 @@ extern char tree_code_type[MAX_TREE_CODES]; /* Number of argument-words in each kind of tree-node. */ extern int tree_code_length[MAX_TREE_CODES]; +#define TREE_CODE_LENGTH(CODE) tree_code_length[(int) (CODE)] /* Names of tree components. */