diff options
author | Jason Merrill <jason@redhat.com> | 2003-05-27 18:53:01 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2003-05-27 18:53:01 -0400 |
commit | 066f50a9e770684a2cca6c0e1062aaf1cc318472 (patch) | |
tree | 0854be3944c723522290b358ba36543e20a49806 /gcc | |
parent | f85716e06e7fdf16123e5db3101dfc81b71afe09 (diff) | |
download | gcc-066f50a9e770684a2cca6c0e1062aaf1cc318472.zip gcc-066f50a9e770684a2cca6c0e1062aaf1cc318472.tar.gz gcc-066f50a9e770684a2cca6c0e1062aaf1cc318472.tar.bz2 |
tree.c (expr_first, [...]): New fns.
* tree.c (expr_first, expr_length): New fns.
* tree.h: Declare them.
* tree.c (iterative_hash_expr): Hash commutative expressions
consistently.
From-SVN: r67201
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/tree.c | 55 | ||||
-rw-r--r-- | gcc/tree.h | 2 |
3 files changed, 60 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d56b572..08805e7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2003-05-27 Jason Merrill <jason@redhat.com> + + * tree.c (expr_first, expr_length): New fns. + * tree.h: Declare them. + + * tree.c (iterative_hash_expr): Hash commutative expressions + consistently. + 2003-05027 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> * tree.h (contains_placeholder_p): Now returns bool. @@ -1123,11 +1123,22 @@ tree_cons (purpose, value, chain) return node; } +/* Return the first expression in a sequence of COMPOUND_EXPRs. */ + +tree +expr_first (tree expr) +{ + if (expr == NULL_TREE) + return expr; + while (TREE_CODE (expr) == COMPOUND_EXPR) + expr = TREE_OPERAND (expr, 0); + return expr; +} + /* Return the last expression in a sequence of COMPOUND_EXPRs. */ tree -expr_last (expr) - tree expr; +expr_last (tree expr) { if (expr == NULL_TREE) return expr; @@ -1135,6 +1146,21 @@ expr_last (expr) expr = TREE_OPERAND (expr, 1); return expr; } + +/* Return the number of subexpressions in a sequence of COMPOUND_EXPRs. */ + +int +expr_length (tree expr) +{ + int len = 0; + + if (expr == NULL_TREE) + return 0; + for (; TREE_CODE (expr) == COMPOUND_EXPR; expr = TREE_OPERAND (expr, 1)) + len += expr_length (TREE_OPERAND (expr, 0)); + ++len; + return len; +} /* Return the size nominally occupied by an object of type TYPE when it resides in memory. The value is measured in units of bytes, @@ -3653,9 +3679,28 @@ iterative_hash_expr (tree t, hashval_t val) if (code == NOP_EXPR || code == CONVERT_EXPR || code == NON_LVALUE_EXPR) val = iterative_hash_object (TREE_TYPE (t), val); - - for (i = first_rtl_op (code) - 1; i >= 0; --i) - val = iterative_hash_expr (TREE_OPERAND (t, i), val); + + if (code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR + || code == MAX_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR + || code == BIT_AND_EXPR || code == NE_EXPR || code == EQ_EXPR) + { + /* It's a commutative expression. We want to hash it the same + however it appears. We do this by first hashing both operands + and then rehashing based on the order of their independent + hashes. */ + hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0); + hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0); + hashval_t t; + + if (one > two) + t = one, one = two, two = t; + + val = iterative_hash_object (one, val); + val = iterative_hash_object (two, val); + } + else + for (i = first_rtl_op (code) - 1; i >= 0; --i) + val = iterative_hash_expr (TREE_OPERAND (t, i), val); } else if (code == TREE_LIST) { @@ -2349,7 +2349,9 @@ extern tree pedantic_non_lvalue PARAMS ((tree)); extern tree convert PARAMS ((tree, tree)); extern unsigned int expr_align PARAMS ((tree)); +extern tree expr_first PARAMS ((tree)); extern tree expr_last PARAMS ((tree)); +extern int expr_length PARAMS ((tree)); extern tree size_in_bytes PARAMS ((tree)); extern HOST_WIDE_INT int_size_in_bytes PARAMS ((tree)); extern tree bit_position PARAMS ((tree)); |