Commit a9d07d6e by Richard Kenner

(const_hash): Treat NON_LVALUE_EXPR like CONVERT_EXPR.

(compare_constant_1, copy_constant, bc_assemble_integer): Likewise.
(const_hash, compare_constant_1): Use switch, not if-then-else.

From-SVN: r13507
parent 19b38e04
...@@ -2344,28 +2344,39 @@ const_hash (exp) ...@@ -2344,28 +2344,39 @@ const_hash (exp)
register int len, hi, i; register int len, hi, i;
register enum tree_code code = TREE_CODE (exp); register enum tree_code code = TREE_CODE (exp);
if (code == INTEGER_CST) /* Either set P and LEN to the address and len of something to hash and
exit the switch or return a value. */
switch (code)
{ {
case INTEGER_CST:
p = (char *) &TREE_INT_CST_LOW (exp); p = (char *) &TREE_INT_CST_LOW (exp);
len = 2 * sizeof TREE_INT_CST_LOW (exp); len = 2 * sizeof TREE_INT_CST_LOW (exp);
} break;
else if (code == REAL_CST)
{ case REAL_CST:
p = (char *) &TREE_REAL_CST (exp); p = (char *) &TREE_REAL_CST (exp);
len = sizeof TREE_REAL_CST (exp); len = sizeof TREE_REAL_CST (exp);
} break;
else if (code == STRING_CST)
p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp); case STRING_CST:
else if (code == COMPLEX_CST) p = TREE_STRING_POINTER (exp);
return const_hash (TREE_REALPART (exp)) * 5 len = TREE_STRING_LENGTH (exp);
+ const_hash (TREE_IMAGPART (exp)); break;
else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
case COMPLEX_CST:
return (const_hash (TREE_REALPART (exp)) * 5
+ const_hash (TREE_IMAGPART (exp)));
case CONSTRUCTOR:
if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
{ {
len = int_size_in_bytes (TREE_TYPE (exp)); len = int_size_in_bytes (TREE_TYPE (exp));
p = (char *) alloca (len); p = (char *) alloca (len);
get_set_constructor_bytes (exp, (unsigned char *) p, len); get_set_constructor_bytes (exp, (unsigned char *) p, len);
break;
} }
else if (code == CONSTRUCTOR) else
{ {
register tree link; register tree link;
...@@ -2384,13 +2395,16 @@ const_hash (exp) ...@@ -2384,13 +2395,16 @@ const_hash (exp)
for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
if (TREE_VALUE (link)) if (TREE_VALUE (link))
hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE; hi
= (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
return hi; return hi;
} }
else if (code == ADDR_EXPR)
case ADDR_EXPR:
{ {
struct addr_const value; struct addr_const value;
decode_addr_const (exp, &value); decode_addr_const (exp, &value);
if (GET_CODE (value.base) == SYMBOL_REF) if (GET_CODE (value.base) == SYMBOL_REF)
{ {
...@@ -2406,13 +2420,19 @@ const_hash (exp) ...@@ -2406,13 +2420,19 @@ const_hash (exp)
hi &= (1 << HASHBITS) - 1; hi &= (1 << HASHBITS) - 1;
hi %= MAX_HASH_TABLE; hi %= MAX_HASH_TABLE;
return hi;
} }
else if (code == PLUS_EXPR || code == MINUS_EXPR) return hi;
return const_hash (TREE_OPERAND (exp, 0)) * 9
+ const_hash (TREE_OPERAND (exp, 1)); case PLUS_EXPR:
else if (code == NOP_EXPR || code == CONVERT_EXPR) case MINUS_EXPR:
return (const_hash (TREE_OPERAND (exp, 0)) * 9
+ const_hash (TREE_OPERAND (exp, 1)));
case NOP_EXPR:
case CONVERT_EXPR:
case NON_LVALUE_EXPR:
return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2; return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
}
/* Compute hashing function */ /* Compute hashing function */
hi = len; hi = len;
...@@ -2456,50 +2476,63 @@ compare_constant_1 (exp, p) ...@@ -2456,50 +2476,63 @@ compare_constant_1 (exp, p)
if (code != (enum tree_code) *p++) if (code != (enum tree_code) *p++)
return 0; return 0;
if (code == INTEGER_CST) /* Either set STRP, P and LEN to pointers and length to compare and exit the
switch, or return the result of the comparison. */
switch (code)
{ {
case INTEGER_CST:
/* Integer constants are the same only if the same width of type. */ /* Integer constants are the same only if the same width of type. */
if (*p++ != TYPE_PRECISION (TREE_TYPE (exp))) if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
return 0; return 0;
strp = (char *) &TREE_INT_CST_LOW (exp); strp = (char *) &TREE_INT_CST_LOW (exp);
len = 2 * sizeof TREE_INT_CST_LOW (exp); len = 2 * sizeof TREE_INT_CST_LOW (exp);
} break;
else if (code == REAL_CST)
{ case REAL_CST:
/* Real constants are the same only if the same width of type. */ /* Real constants are the same only if the same width of type. */
if (*p++ != TYPE_PRECISION (TREE_TYPE (exp))) if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
return 0; return 0;
strp = (char *) &TREE_REAL_CST (exp); strp = (char *) &TREE_REAL_CST (exp);
len = sizeof TREE_REAL_CST (exp); len = sizeof TREE_REAL_CST (exp);
} break;
else if (code == STRING_CST)
{ case STRING_CST:
if (flag_writable_strings) if (flag_writable_strings)
return 0; return 0;
strp = TREE_STRING_POINTER (exp); strp = TREE_STRING_POINTER (exp);
len = TREE_STRING_LENGTH (exp); len = TREE_STRING_LENGTH (exp);
if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p, if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
sizeof TREE_STRING_LENGTH (exp))) sizeof TREE_STRING_LENGTH (exp)))
return 0; return 0;
p += sizeof TREE_STRING_LENGTH (exp); p += sizeof TREE_STRING_LENGTH (exp);
} break;
else if (code == COMPLEX_CST)
{ case COMPLEX_CST:
p = compare_constant_1 (TREE_REALPART (exp), p); p = compare_constant_1 (TREE_REALPART (exp), p);
if (p == 0) return 0; if (p == 0)
p = compare_constant_1 (TREE_IMAGPART (exp), p); return 0;
return p;
} return compare_constant_1 (TREE_IMAGPART (exp), p);
else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
case CONSTRUCTOR:
if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
{ {
int xlen = len = int_size_in_bytes (TREE_TYPE (exp)); int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
strp = (char *) alloca (len); strp = (char *) alloca (len);
get_set_constructor_bytes (exp, (unsigned char *) strp, len); get_set_constructor_bytes (exp, (unsigned char *) strp, len);
if (bcmp ((char *) &xlen, p, sizeof xlen)) if (bcmp ((char *) &xlen, p, sizeof xlen))
return 0; return 0;
p += sizeof xlen; p += sizeof xlen;
break;
} }
else if (code == CONSTRUCTOR) else
{ {
register tree link; register tree link;
int length = list_length (CONSTRUCTOR_ELTS (exp)); int length = list_length (CONSTRUCTOR_ELTS (exp));
...@@ -2507,6 +2540,7 @@ compare_constant_1 (exp, p) ...@@ -2507,6 +2540,7 @@ compare_constant_1 (exp, p)
if (bcmp ((char *) &length, p, sizeof length)) if (bcmp ((char *) &length, p, sizeof length))
return 0; return 0;
p += sizeof length; p += sizeof length;
/* For record constructors, insist that the types match. /* For record constructors, insist that the types match.
...@@ -2515,8 +2549,10 @@ compare_constant_1 (exp, p) ...@@ -2515,8 +2549,10 @@ compare_constant_1 (exp, p)
type = TREE_TYPE (exp); type = TREE_TYPE (exp);
else else
type = 0; type = 0;
if (bcmp ((char *) &type, p, sizeof type)) if (bcmp ((char *) &type, p, sizeof type))
return 0; return 0;
p += sizeof type; p += sizeof type;
/* For arrays, insist that the size in bytes match. */ /* For arrays, insist that the size in bytes match. */
...@@ -2525,6 +2561,7 @@ compare_constant_1 (exp, p) ...@@ -2525,6 +2561,7 @@ compare_constant_1 (exp, p)
int size = int_size_in_bytes (TREE_TYPE (exp)); int size = int_size_in_bytes (TREE_TYPE (exp));
if (bcmp ((char *) &size, p, sizeof size)) if (bcmp ((char *) &size, p, sizeof size))
return 0; return 0;
p += sizeof size; p += sizeof size;
} }
...@@ -2541,15 +2578,18 @@ compare_constant_1 (exp, p) ...@@ -2541,15 +2578,18 @@ compare_constant_1 (exp, p)
if (bcmp ((char *) &zero, p, sizeof zero)) if (bcmp ((char *) &zero, p, sizeof zero))
return 0; return 0;
p += sizeof zero; p += sizeof zero;
} }
} }
return p; return p;
} }
else if (code == ADDR_EXPR)
case ADDR_EXPR:
{ {
struct addr_const value; struct addr_const value;
decode_addr_const (exp, &value); decode_addr_const (exp, &value);
strp = (char *) &value.offset; strp = (char *) &value.offset;
len = sizeof value.offset; len = sizeof value.offset;
...@@ -2557,21 +2597,25 @@ compare_constant_1 (exp, p) ...@@ -2557,21 +2597,25 @@ compare_constant_1 (exp, p)
while (--len >= 0) while (--len >= 0)
if (*p++ != *strp++) if (*p++ != *strp++)
return 0; return 0;
/* Compare symbol name. */ /* Compare symbol name. */
strp = XSTR (value.base, 0); strp = XSTR (value.base, 0);
len = strlen (strp) + 1; len = strlen (strp) + 1;
} }
else if (code == PLUS_EXPR || code == MINUS_EXPR) break;
{
p = compare_constant_1 (TREE_OPERAND (exp, 0), p); case PLUS_EXPR:
if (p == 0) return 0; case MINUS_EXPR:
p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
return p;
}
else if (code == NOP_EXPR || code == CONVERT_EXPR)
{
p = compare_constant_1 (TREE_OPERAND (exp, 0), p); p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
return p; if (p == 0)
return 0;
return compare_constant_1 (TREE_OPERAND (exp, 1), p);
case NOP_EXPR:
case CONVERT_EXPR:
case NON_LVALUE_EXPR:
return compare_constant_1 (TREE_OPERAND (exp, 0), p);
} }
/* Compare constant contents. */ /* Compare constant contents. */
...@@ -2834,6 +2878,7 @@ copy_constant (exp) ...@@ -2834,6 +2878,7 @@ copy_constant (exp)
case NOP_EXPR: case NOP_EXPR:
case CONVERT_EXPR: case CONVERT_EXPR:
case NON_LVALUE_EXPR:
return build1 (TREE_CODE (exp), TREE_TYPE (exp), return build1 (TREE_CODE (exp), TREE_TYPE (exp),
copy_constant (TREE_OPERAND (exp, 0))); copy_constant (TREE_OPERAND (exp, 0)));
...@@ -3833,7 +3878,8 @@ bc_assemble_integer (exp, size) ...@@ -3833,7 +3878,8 @@ bc_assemble_integer (exp, size)
exp = fold (exp); exp = fold (exp);
while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR) while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
|| TREE_CODE (exp) == NON_LVALUE_EXPR)
exp = TREE_OPERAND (exp, 0); exp = TREE_OPERAND (exp, 0);
if (TREE_CODE (exp) == INTEGER_CST) if (TREE_CODE (exp) == INTEGER_CST)
{ {
...@@ -3844,11 +3890,13 @@ bc_assemble_integer (exp, size) ...@@ -3844,11 +3890,13 @@ bc_assemble_integer (exp, size)
{ {
const_part = TREE_OPERAND (exp, 0); const_part = TREE_OPERAND (exp, 0);
while (TREE_CODE (const_part) == NOP_EXPR while (TREE_CODE (const_part) == NOP_EXPR
|| TREE_CODE (const_part) == CONVERT_EXPR) || TREE_CODE (const_part) == CONVERT_EXPR
|| TREE_CODE (const_part) == NON_LVALUE_EXPR)
const_part = TREE_OPERAND (const_part, 0); const_part = TREE_OPERAND (const_part, 0);
addr_part = TREE_OPERAND (exp, 1); addr_part = TREE_OPERAND (exp, 1);
while (TREE_CODE (addr_part) == NOP_EXPR while (TREE_CODE (addr_part) == NOP_EXPR
|| TREE_CODE (addr_part) == CONVERT_EXPR) || TREE_CODE (addr_part) == CONVERT_EXPR
|| TREE_CODE (addr_part) == NON_LVALUE_EXPR)
addr_part = TREE_OPERAND (addr_part, 0); addr_part = TREE_OPERAND (addr_part, 0);
if (TREE_CODE (const_part) != INTEGER_CST) if (TREE_CODE (const_part) != INTEGER_CST)
tmp = const_part, const_part = addr_part, addr_part = tmp; tmp = const_part, const_part = addr_part, addr_part = tmp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment