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)
register int len, hi, i;
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);
len = 2 * sizeof TREE_INT_CST_LOW (exp);
}
else if (code == REAL_CST)
{
break;
case REAL_CST:
p = (char *) &TREE_REAL_CST (exp);
len = sizeof TREE_REAL_CST (exp);
}
else if (code == STRING_CST)
p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
else if (code == COMPLEX_CST)
return const_hash (TREE_REALPART (exp)) * 5
+ const_hash (TREE_IMAGPART (exp));
else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
break;
case STRING_CST:
p = TREE_STRING_POINTER (exp);
len = TREE_STRING_LENGTH (exp);
break;
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));
p = (char *) alloca (len);
get_set_constructor_bytes (exp, (unsigned char *) p, len);
break;
}
else if (code == CONSTRUCTOR)
else
{
register tree link;
......@@ -2384,13 +2395,16 @@ const_hash (exp)
for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (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;
}
else if (code == ADDR_EXPR)
case ADDR_EXPR:
{
struct addr_const value;
decode_addr_const (exp, &value);
if (GET_CODE (value.base) == SYMBOL_REF)
{
......@@ -2406,13 +2420,19 @@ const_hash (exp)
hi &= (1 << HASHBITS) - 1;
hi %= MAX_HASH_TABLE;
return hi;
}
else if (code == PLUS_EXPR || code == MINUS_EXPR)
return const_hash (TREE_OPERAND (exp, 0)) * 9
+ const_hash (TREE_OPERAND (exp, 1));
else if (code == NOP_EXPR || code == CONVERT_EXPR)
return hi;
case PLUS_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;
}
/* Compute hashing function */
hi = len;
......@@ -2456,50 +2476,63 @@ compare_constant_1 (exp, p)
if (code != (enum tree_code) *p++)
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. */
if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
return 0;
strp = (char *) &TREE_INT_CST_LOW (exp);
len = 2 * sizeof TREE_INT_CST_LOW (exp);
}
else if (code == REAL_CST)
{
break;
case REAL_CST:
/* Real constants are the same only if the same width of type. */
if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
return 0;
strp = (char *) &TREE_REAL_CST (exp);
len = sizeof TREE_REAL_CST (exp);
}
else if (code == STRING_CST)
{
break;
case STRING_CST:
if (flag_writable_strings)
return 0;
strp = TREE_STRING_POINTER (exp);
len = TREE_STRING_LENGTH (exp);
if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
sizeof TREE_STRING_LENGTH (exp)))
return 0;
p += sizeof TREE_STRING_LENGTH (exp);
}
else if (code == COMPLEX_CST)
{
break;
case COMPLEX_CST:
p = compare_constant_1 (TREE_REALPART (exp), p);
if (p == 0) return 0;
p = compare_constant_1 (TREE_IMAGPART (exp), p);
return p;
}
else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
if (p == 0)
return 0;
return compare_constant_1 (TREE_IMAGPART (exp), p);
case CONSTRUCTOR:
if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
{
int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
strp = (char *) alloca (len);
get_set_constructor_bytes (exp, (unsigned char *) strp, len);
if (bcmp ((char *) &xlen, p, sizeof xlen))
return 0;
p += sizeof xlen;
break;
}
else if (code == CONSTRUCTOR)
else
{
register tree link;
int length = list_length (CONSTRUCTOR_ELTS (exp));
......@@ -2507,6 +2540,7 @@ compare_constant_1 (exp, p)
if (bcmp ((char *) &length, p, sizeof length))
return 0;
p += sizeof length;
/* For record constructors, insist that the types match.
......@@ -2515,8 +2549,10 @@ compare_constant_1 (exp, p)
type = TREE_TYPE (exp);
else
type = 0;
if (bcmp ((char *) &type, p, sizeof type))
return 0;
p += sizeof type;
/* For arrays, insist that the size in bytes match. */
......@@ -2525,6 +2561,7 @@ compare_constant_1 (exp, p)
int size = int_size_in_bytes (TREE_TYPE (exp));
if (bcmp ((char *) &size, p, sizeof size))
return 0;
p += sizeof size;
}
......@@ -2541,15 +2578,18 @@ compare_constant_1 (exp, p)
if (bcmp ((char *) &zero, p, sizeof zero))
return 0;
p += sizeof zero;
}
}
return p;
}
else if (code == ADDR_EXPR)
case ADDR_EXPR:
{
struct addr_const value;
decode_addr_const (exp, &value);
strp = (char *) &value.offset;
len = sizeof value.offset;
......@@ -2557,21 +2597,25 @@ compare_constant_1 (exp, p)
while (--len >= 0)
if (*p++ != *strp++)
return 0;
/* Compare symbol name. */
strp = XSTR (value.base, 0);
len = strlen (strp) + 1;
}
else if (code == PLUS_EXPR || code == MINUS_EXPR)
{
p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
if (p == 0) return 0;
p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
return p;
}
else if (code == NOP_EXPR || code == CONVERT_EXPR)
{
break;
case PLUS_EXPR:
case MINUS_EXPR:
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. */
......@@ -2834,6 +2878,7 @@ copy_constant (exp)
case NOP_EXPR:
case CONVERT_EXPR:
case NON_LVALUE_EXPR:
return build1 (TREE_CODE (exp), TREE_TYPE (exp),
copy_constant (TREE_OPERAND (exp, 0)));
......@@ -3833,7 +3878,8 @@ bc_assemble_integer (exp, size)
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);
if (TREE_CODE (exp) == INTEGER_CST)
{
......@@ -3844,11 +3890,13 @@ bc_assemble_integer (exp, size)
{
const_part = TREE_OPERAND (exp, 0);
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);
addr_part = TREE_OPERAND (exp, 1);
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);
if (TREE_CODE (const_part) != INTEGER_CST)
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