/* Generate code from machine description to compute values of attributes.
Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
This file is part of GCC.
#define ATTR_PERMANENT_P(RTX) (RTX_FLAG((RTX), integrated))
#define ATTR_EQ_ATTR_P(RTX) (RTX_FLAG((RTX), volatil))
+#if 0
+#define strcmp_check(S1, S2) ((S1) == (S2) \
+ ? 0 \
+ : (strcmp ((S1), (S2)) \
+ ? 1 \
+ : (abort (), 0)))
+#else
+#define strcmp_check(S1, S2) ((S1) != (S2))
+#endif
+
#include "bconfig.h"
#include "system.h"
#include "coretypes.h"
{
char *name; /* Name of attribute. */
struct attr_desc *next; /* Next attribute. */
+ struct attr_value *first_value; /* First value of this attribute. */
+ struct attr_value *default_val; /* Default value for this attribute. */
+ int lineno : 24; /* Line number. */
unsigned is_numeric : 1; /* Values of this attribute are numeric. */
unsigned negative_ok : 1; /* Allow negative numeric values. */
unsigned unsigned_p : 1; /* Make the output function unsigned int. */
unsigned is_const : 1; /* Attribute value constant for each run. */
unsigned is_special : 1; /* Don't call `write_attr_set'. */
- unsigned func_units_p : 1; /* this is the function_units attribute */
- unsigned blockage_p : 1; /* this is the blockage range function */
- struct attr_value *first_value; /* First value of this attribute. */
- struct attr_value *default_val; /* Default value for this attribute. */
- int lineno; /* Line number. */
+ unsigned func_units_p : 1; /* This is the function_units attribute. */
+ unsigned blockage_p : 1; /* This is the blockage range function. */
+ unsigned static_p : 1; /* Make the output function static. */
};
#define NULL_ATTR (struct attr_desc *) NULL
/* Used to reduce calls to `strcmp' */
static char *alternative_name;
+static const char *length_str;
+static const char *delay_type_str;
+static const char *delay_1_0_str;
+static const char *num_delay_slots_str;
/* Indicate that REG_DEAD notes are valid if dead_or_set_p is ever
called. */
(EXP) = (XSTR ((EXP), 1) == current_alternative_string \
? true_rtx : false_rtx);
+#define DEF_ATTR_STRING(S) (attr_string ((S), strlen (S)))
+
/* These are referenced by rtlanal.c and hence need to be defined somewhere.
They won't actually be used. */
static rtx simplify_with_current_value (rtx, struct dimension *, int);
static rtx simplify_with_current_value_aux (rtx);
static void clear_struct_flag (rtx);
-static int count_sub_rtxs (rtx, int);
static void remove_insn_ent (struct attr_value *, struct insn_ent *);
static void insert_insn_ent (struct attr_value *, struct insn_ent *);
static rtx insert_right_side (enum rtx_code, rtx, rtx, int, int);
static void write_toplevel_expr (rtx);
static void write_const_num_delay_slots (void);
static char *next_comma_elt (const char **);
-static struct attr_desc *find_attr (const char *, int);
+static struct attr_desc *find_attr (const char **, int);
static struct attr_value *find_most_used (struct attr_desc *);
static rtx find_single_value (struct attr_desc *);
static void extend_range (struct range *, int, int);
static int attr_equal_p (rtx, rtx);
static rtx attr_copy_rtx (rtx);
static int attr_rtx_cost (rtx);
+static bool attr_alt_subset_p (rtx, rtx);
+static bool attr_alt_subset_of_compl_p (rtx, rtx);
+static rtx attr_alt_intersection (rtx, rtx);
+static rtx attr_alt_union (rtx, rtx);
+static rtx attr_alt_complement (rtx);
+static bool attr_alt_bit_p (rtx, int);
+static rtx mk_attr_alt (int);
#define oballoc(size) obstack_alloc (hash_obstack, size)
{
struct attr_hash *h;
- h = (struct attr_hash *) obstack_alloc (hash_obstack,
- sizeof (struct attr_hash));
+ h = obstack_alloc (hash_obstack, sizeof (struct attr_hash));
h->hashcode = hashcode;
h->u.rtl = rtl;
h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];
{
struct attr_hash *h;
- h = (struct attr_hash *) obstack_alloc (hash_obstack,
- sizeof (struct attr_hash));
+ h = obstack_alloc (hash_obstack, sizeof (struct attr_hash));
h->hashcode = -hashcode;
h->u.str = str;
h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];
In some cases we cannot uniquify; then we return an ordinary
impermanent rtx with ATTR_PERMANENT_P clear.
- Args are like gen_rtx, but without the mode:
+ Args are as follows:
rtx attr_rtx (code, [element1, ..., elementn]) */
{
char *arg0 = va_arg (p, char *);
- if (code == SYMBOL_REF)
- arg0 = attr_string (arg0, strlen (arg0));
+ arg0 = DEF_ATTR_STRING (arg0);
hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0));
for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
vsprintf (str, fmt, p);
va_end (p);
- return attr_string (str, strlen (str));
+ return DEF_ATTR_STRING (str);
}
static rtx
attr_eq (const char *name, const char *value)
{
- return attr_rtx (EQ_ATTR, attr_string (name, strlen (name)),
- attr_string (value, strlen (value)));
+ return attr_rtx (EQ_ATTR, DEF_ATTR_STRING (name), DEF_ATTR_STRING (value));
}
static const char *
return h->u.str; /* <-- return if found. */
/* Not found; create a permanent copy and add it to the hash table. */
- new_str = (char *) obstack_alloc (hash_obstack, len + 1);
+ new_str = obstack_alloc (hash_obstack, len + 1);
memcpy (new_str, str, len);
new_str[len] = '\0';
attr_hash_add_string (hashcode, new_str);
else if (n_comma_elts (XSTR (exp, 1)) == 1)
{
- attr = find_attr (XSTR (exp, 0), 0);
+ attr = find_attr (&XSTR (exp, 0), 0);
if (attr == NULL)
{
if (! strcmp (XSTR (exp, 0), "alternative"))
- {
- XSTR (exp, 0) = alternative_name;
- /* This can't be simplified any further. */
- ATTR_IND_SIMPLIFIED_P (exp) = 1;
- return exp;
- }
+ return mk_attr_alt (1 << atoi (XSTR (exp, 1)));
else
fatal ("unknown attribute `%s' in EQ_ATTR", XSTR (exp, 0));
}
}
else
{
- /* Make an IOR tree of the possible values. */
- orexp = false_rtx;
- name_ptr = XSTR (exp, 1);
- while ((p = next_comma_elt (&name_ptr)) != NULL)
+ if (! strcmp (XSTR (exp, 0), "alternative"))
{
- newexp = attr_eq (XSTR (exp, 0), p);
- orexp = insert_right_side (IOR, orexp, newexp, -2, -2);
+ int set = 0;
+
+ name_ptr = XSTR (exp, 1);
+ while ((p = next_comma_elt (&name_ptr)) != NULL)
+ set |= 1 << atoi (p);
+
+ return mk_attr_alt (set);
}
+ else
+ {
+ /* Make an IOR tree of the possible values. */
+ orexp = false_rtx;
+ name_ptr = XSTR (exp, 1);
+ while ((p = next_comma_elt (&name_ptr)) != NULL)
+ {
+ newexp = attr_eq (XSTR (exp, 0), p);
+ orexp = insert_right_side (IOR, orexp, newexp, -2, -2);
+ }
- return check_attr_test (orexp, is_const, lineno);
+ return check_attr_test (orexp, is_const, lineno);
+ }
}
break;
have_error = 1;
break;
}
- /* FALLTHRU */
+ /* Fall through. */
case IOR:
case AND:
case ATTR:
{
- struct attr_desc *attr2 = find_attr (XSTR (exp, 0), 0);
+ struct attr_desc *attr2 = find_attr (&XSTR (exp, 0), 0);
if (attr2 == NULL)
{
message_with_line (attr ? attr->lineno : 0,
if (value == NULL_RTX)
continue;
- if ((attr = find_attr (XSTR (XEXP (value, 0), 0), 0)) == NULL)
+ if ((attr = find_attr (&XSTR (XEXP (value, 0), 0), 0)) == NULL)
{
message_with_line (id->lineno, "unknown attribute %s",
XSTR (XEXP (value, 0), 0));
fatal ("(attr_value \"*\") used in invalid context");
exp = attr->default_val->value;
}
+ else
+ XSTR (exp, 0) = DEF_ATTR_STRING (XSTR (exp, 0));
break;
if (GET_CODE (exp) == AND || GET_CODE (exp) == IOR)
return attr_rtx (GET_CODE (exp), copy_boolean (XEXP (exp, 0)),
copy_boolean (XEXP (exp, 1)));
+ if (GET_CODE (exp) == MATCH_OPERAND)
+ {
+ XSTR (exp, 1) = DEF_ATTR_STRING (XSTR (exp, 1));
+ XSTR (exp, 2) = DEF_ATTR_STRING (XSTR (exp, 2));
+ }
+ else if (GET_CODE (exp) == EQ_ATTR)
+ {
+ XSTR (exp, 0) = DEF_ATTR_STRING (XSTR (exp, 0));
+ XSTR (exp, 1) = DEF_ATTR_STRING (XSTR (exp, 1));
+ }
+
return exp;
}
|| insn_alternatives[av->first_insn->insn_code]))
return av;
- av = (struct attr_value *) oballoc (sizeof (struct attr_value));
+ av = oballoc (sizeof (struct attr_value));
av->value = value;
av->next = attr->first_value;
attr->first_value = av;
= make_numeric_value (XVECLEN (delay->def, 1) / 3);
}
- make_internal_attr ("*num_delay_slots", condexp, 0);
+ make_internal_attr (num_delay_slots_str, condexp, ATTR_NONE);
/* If more than one delay type, do the same for computing the delay type. */
if (num_delays > 1)
XVECEXP (condexp, 0, i + 1) = make_numeric_value (delay->num);
}
- make_internal_attr ("*delay_type", condexp, 1);
+ make_internal_attr (delay_type_str, condexp, ATTR_SPECIAL);
}
/* For each delay possibility and delay slot, compute an eligibility
p = attr_printf (sizeof "*delay__" + MAX_DIGITS * 2,
"*delay_%d_%d", delay->num, i / 3);
- make_internal_attr (p, newexp, 1);
+ make_internal_attr (p, newexp, ATTR_SPECIAL);
if (have_annul_true)
{
make_numeric_value (0));
p = attr_printf (sizeof "*annul_true__" + MAX_DIGITS * 2,
"*annul_true_%d_%d", delay->num, i / 3);
- make_internal_attr (p, newexp, 1);
+ make_internal_attr (p, newexp, ATTR_SPECIAL);
}
if (have_annul_false)
make_numeric_value (0));
p = attr_printf (sizeof "*annul_false__" + MAX_DIGITS * 2,
"*annul_false_%d_%d", delay->num, i / 3);
- make_internal_attr (p, newexp, 1);
+ make_internal_attr (p, newexp, ATTR_SPECIAL);
}
}
}
str = attr_printf ((strlen (unit->name) + sizeof "*_cost_"
+ MAX_DIGITS),
"*%s_cost_%d", unit->name, op->num);
- make_internal_attr (str, issue_exp, 1);
+ make_internal_attr (str, issue_exp, ATTR_SPECIAL);
}
/* Validate the condition. */
unitsmask = attr_rtx (FFS, unitsmask);
}
- make_internal_attr ("*function_units_used", unitsmask, 10);
+ make_internal_attr ("*function_units_used", unitsmask,
+ (ATTR_NEGATIVE_OK | ATTR_FUNC_UNITS));
/* Create an array of ops for each unit. Add an extra unit for the
result_ready_cost function that has the ops of all other units. */
- unit_ops = (struct function_unit_op ***)
- xmalloc ((num_units + 1) * sizeof (struct function_unit_op **));
- unit_num = (struct function_unit **)
- xmalloc ((num_units + 1) * sizeof (struct function_unit *));
+ unit_ops = xmalloc ((num_units + 1) * sizeof (struct function_unit_op **));
+ unit_num = xmalloc ((num_units + 1) * sizeof (struct function_unit *));
- unit_num[num_units] = unit = (struct function_unit *)
- xmalloc (sizeof (struct function_unit));
+ unit_num[num_units] = unit = xmalloc (sizeof (struct function_unit));
unit->num = num_units;
unit->num_opclasses = 0;
{
unit_num[num_units]->num_opclasses += unit->num_opclasses;
unit_num[unit->num] = unit;
- unit_ops[unit->num] = op_array = (struct function_unit_op **)
+ unit_ops[unit->num] = op_array =
xmalloc (unit->num_opclasses * sizeof (struct function_unit_op *));
for (op = unit->ops; op; op = op->next)
}
/* Compose the array of ops for the extra unit. */
- unit_ops[num_units] = op_array = (struct function_unit_op **)
+ unit_ops[num_units] = op_array =
xmalloc (unit_num[num_units]->num_opclasses
* sizeof (struct function_unit_op *));
str = attr_printf ((strlen (unit->name) + sizeof "*_block_"
+ MAX_DIGITS),
"*%s_block_%d", unit->name, op->num);
- make_internal_attr (str, blockage, 1);
+ make_internal_attr (str, blockage, ATTR_SPECIAL);
}
/* Record MAX (BLOCKAGE (*,*)). */
str = attr_printf ((strlen (unit->name)
+ sizeof "*_unit_blockage_range"),
"*%s_unit_blockage_range", unit->name);
- make_internal_attr (str, newexp, 20);
+ make_internal_attr (str, newexp, (ATTR_STATIC|ATTR_BLOCKAGE|ATTR_UNSIGNED));
}
str = attr_printf (strlen (unit->name) + sizeof "*_unit_ready_cost",
"*%s_unit_ready_cost", unit->name);
+ make_internal_attr (str, readycost, ATTR_STATIC);
}
else
- str = "*result_ready_cost";
-
- /* Make an attribute for the ready_cost function. Simplifying
- further with simplify_by_exploding doesn't win. */
- make_internal_attr (str, readycost, 0);
+ {
+ /* Make an attribute for the ready_cost function. Simplifying
+ further with simplify_by_exploding doesn't win. */
+ str = "*result_ready_cost";
+ make_internal_attr (str, readycost, ATTR_NONE);
+ }
}
/* For each unit that requires a conflict cost function, make an attribute
/* Simplifying caseexp with simplify_by_exploding doesn't win. */
str = attr_printf (strlen (unit->name) + sizeof "*_cases",
"*%s_cases", unit->name);
- make_internal_attr (str, caseexp, 1);
+ make_internal_attr (str, caseexp, ATTR_SPECIAL);
}
}
case PC:
case CC0:
case EQ_ATTR:
+ case EQ_ATTR_ALT:
return x;
default:
value = NULL;
if (XVEC (id->def, id->vec_idx))
for (i = 0; i < XVECLEN (id->def, id->vec_idx); i++)
- if (! strcmp (XSTR (XEXP (XVECEXP (id->def, id->vec_idx, i), 0), 0),
- attr->name))
+ if (! strcmp_check (XSTR (XEXP (XVECEXP (id->def, id->vec_idx, i), 0), 0),
+ attr->name))
value = XEXP (XVECEXP (id->def, id->vec_idx, i), 1);
if (value == NULL)
else
av = get_attr_value (value, attr, id->insn_code);
- ie = (struct insn_ent *) oballoc (sizeof (struct insn_ent));
+ ie = oballoc (sizeof (struct insn_ent));
ie->insn_code = id->insn_code;
ie->insn_index = id->insn_code;
insert_insn_ent (av, ie);
static void
make_length_attrs (void)
{
- static const char *const new_names[] = {"*insn_default_length",
- "*insn_variable_length_p",
- "*insn_current_length"};
+ static const char *new_names[] =
+ {
+ "*insn_default_length",
+ "*insn_variable_length_p",
+ "*insn_current_length"
+ };
static rtx (*const no_address_fn[]) (rtx) = {identity_fn, zero_fn, zero_fn};
static rtx (*const address_fn[]) (rtx) = {max_fn, one_fn, identity_fn};
size_t i;
/* See if length attribute is defined. If so, it must be numeric. Make
it special so we don't output anything for it. */
- length_attr = find_attr ("length", 0);
+ length_attr = find_attr (&length_str, 0);
if (length_attr == 0)
return;
make_internal_attr (new_names[i],
substitute_address (length_attr->default_val->value,
no_address_fn[i], address_fn[i]),
- 0);
- new_attr = find_attr (new_names[i], 0);
+ ATTR_NONE);
+ new_attr = find_attr (&new_names[i], 0);
for (av = length_attr->first_value; av; av = av->next)
for (ie = av->first_insn; ie; ie = ie->next)
{
no_address_fn[i],
address_fn[i]),
new_attr, ie->insn_code);
- new_ie = (struct insn_ent *) oballoc (sizeof (struct insn_ent));
+ new_ie = oballoc (sizeof (struct insn_ent));
new_ie->insn_code = ie->insn_code;
new_ie->insn_index = ie->insn_index;
insert_insn_ent (new_av, new_ie);
static void
write_length_unit_log (void)
{
- struct attr_desc *length_attr = find_attr ("length", 0);
+ struct attr_desc *length_attr = find_attr (&length_str, 0);
struct attr_value *av;
struct insn_ent *ie;
unsigned int length_unit_log, length_or;
rtx defval = XEXP (exp, 1);
rtx new_defval = XEXP (exp, 1);
int len = XVECLEN (exp, 0);
- rtx *tests = (rtx *) xmalloc (len * sizeof (rtx));
+ rtx *tests = xmalloc (len * sizeof (rtx));
int allsame = 1;
rtx ret;
/* If test is false, discard it and its value. */
for (j = i; j < len - 2; j++)
tests[j] = tests[j + 2];
+ i -= 2;
len -= 2;
}
for (j = i; j < len - 2; j++)
tests[j] = tests[j + 2];
len -= 2;
+ i -= 2;
}
else
&& XSTR (exp, 0) == alternative_name)
string = XSTR (exp, 1);
+ else if (GET_CODE (exp) == EQ_ATTR_ALT)
+ {
+ if (code == AND && XINT (exp, 1))
+ return XINT (exp, 0);
+
+ if (code == IOR && !XINT (exp, 1))
+ return XINT (exp, 0);
+
+ return 0;
+ }
else
return 0;
static rtx
make_alternative_compare (int mask)
{
- rtx newexp;
- int i;
-
- /* Find the bit. */
- for (i = 0; (mask & (1 << i)) == 0; i++)
- ;
-
- newexp = attr_rtx (EQ_ATTR, alternative_name, attr_numeral (i));
- ATTR_IND_SIMPLIFIED_P (newexp) = 1;
-
- return newexp;
+ return mk_attr_alt (mask);
}
/* If we are processing an (eq_attr "attr" "value") test, we find the value
if (GET_CODE (value) == CONST_STRING)
{
- if (! strcmp (XSTR (value, 0), XSTR (exp, 1)))
+ if (! strcmp_check (XSTR (value, 0), XSTR (exp, 1)))
newexp = true_rtx;
else
newexp = false_rtx;
newexp = attr_rtx (EQ, value,
attr_rtx (SYMBOL_REF,
- attr_string (string, strlen (string))));
+ DEF_ATTR_STRING (string)));
}
else if (GET_CODE (value) == COND)
{
right = simplify_and_tree (XEXP (exp, 1), pterm, insn_code, insn_index);
if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
{
- newexp = attr_rtx (GET_CODE (exp), left, right);
+ newexp = attr_rtx (AND, left, right);
exp = simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
{
- newexp = attr_rtx (GET_CODE (exp), left, right);
+ newexp = attr_rtx (IOR, left, right);
exp = simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
else if (GET_CODE (*pterm) == NOT && exp == XEXP (*pterm, 0))
return false_rtx;
+ else if (GET_CODE (exp) == EQ_ATTR_ALT && GET_CODE (*pterm) == EQ_ATTR_ALT)
+ {
+ if (attr_alt_subset_p (*pterm, exp))
+ return true_rtx;
+
+ if (attr_alt_subset_of_compl_p (*pterm, exp))
+ return false_rtx;
+
+ if (attr_alt_subset_p (exp, *pterm))
+ *pterm = true_rtx;
+
+ return exp;
+ }
+
else if (GET_CODE (exp) == EQ_ATTR && GET_CODE (*pterm) == EQ_ATTR)
{
if (XSTR (exp, 0) != XSTR (*pterm, 0))
return exp;
- if (! strcmp (XSTR (exp, 1), XSTR (*pterm, 1)))
+ if (! strcmp_check (XSTR (exp, 1), XSTR (*pterm, 1)))
return true_rtx;
else
return false_rtx;
if (XSTR (*pterm, 0) != XSTR (XEXP (exp, 0), 0))
return exp;
- if (! strcmp (XSTR (*pterm, 1), XSTR (XEXP (exp, 0), 1)))
+ if (! strcmp_check (XSTR (*pterm, 1), XSTR (XEXP (exp, 0), 1)))
return false_rtx;
else
return true_rtx;
if (XSTR (exp, 0) != XSTR (XEXP (*pterm, 0), 0))
return exp;
- if (! strcmp (XSTR (exp, 1), XSTR (XEXP (*pterm, 0), 1)))
+ if (! strcmp_check (XSTR (exp, 1), XSTR (XEXP (*pterm, 0), 1)))
return false_rtx;
else
*pterm = true_rtx;
return 10;
else
return 0;
+
+ case EQ_ATTR_ALT:
+ return 0;
+
case EQ_ATTR:
/* Alternatives don't result into function call. */
- if (!strcmp (XSTR (x, 0), "alternative"))
+ if (!strcmp_check (XSTR (x, 0), alternative_name))
return 0;
else
return 5;
return attr_copy_rtx (x);
}
+/* Returns true if S1 is a subset of S2. */
+
+static bool
+attr_alt_subset_p (rtx s1, rtx s2)
+{
+ switch ((XINT (s1, 1) << 1) | XINT (s2, 1))
+ {
+ case (0 << 1) | 0:
+ return !(XINT (s1, 0) &~ XINT (s2, 0));
+
+ case (0 << 1) | 1:
+ return !(XINT (s1, 0) & XINT (s2, 0));
+
+ case (1 << 1) | 0:
+ return false;
+
+ case (1 << 1) | 1:
+ return !(XINT (s2, 0) &~ XINT (s1, 0));
+
+ default:
+ abort ();
+ }
+}
+
+/* Returns true if S1 is a subset of complement of S2. */
+
+static bool attr_alt_subset_of_compl_p (rtx s1, rtx s2)
+{
+ switch ((XINT (s1, 1) << 1) | XINT (s2, 1))
+ {
+ case (0 << 1) | 0:
+ return !(XINT (s1, 0) & XINT (s2, 0));
+
+ case (0 << 1) | 1:
+ return !(XINT (s1, 0) & ~XINT (s2, 0));
+
+ case (1 << 1) | 0:
+ return !(XINT (s2, 0) &~ XINT (s1, 0));
+
+ case (1 << 1) | 1:
+ return false;
+
+ default:
+ abort ();
+ }
+}
+
+/* Return EQ_ATTR_ALT expression representing intersection of S1 and S2. */
+
+static rtx
+attr_alt_intersection (rtx s1, rtx s2)
+{
+ rtx result = rtx_alloc (EQ_ATTR_ALT);
+
+ switch ((XINT (s1, 1) << 1) | XINT (s2, 1))
+ {
+ case (0 << 1) | 0:
+ XINT (result, 0) = XINT (s1, 0) & XINT (s2, 0);
+ break;
+ case (0 << 1) | 1:
+ XINT (result, 0) = XINT (s1, 0) & ~XINT (s2, 0);
+ break;
+ case (1 << 1) | 0:
+ XINT (result, 0) = XINT (s2, 0) & ~XINT (s1, 0);
+ break;
+ case (1 << 1) | 1:
+ XINT (result, 0) = XINT (s1, 0) | XINT (s2, 0);
+ break;
+ default:
+ abort ();
+ }
+ XINT (result, 1) = XINT (s1, 1) & XINT (s2, 1);
+
+ return result;
+}
+
+/* Return EQ_ATTR_ALT expression representing union of S1 and S2. */
+
+static rtx
+attr_alt_union (rtx s1, rtx s2)
+{
+ rtx result = rtx_alloc (EQ_ATTR_ALT);
+
+ switch ((XINT (s1, 1) << 1) | XINT (s2, 1))
+ {
+ case (0 << 1) | 0:
+ XINT (result, 0) = XINT (s1, 0) | XINT (s2, 0);
+ break;
+ case (0 << 1) | 1:
+ XINT (result, 0) = XINT (s2, 0) & ~XINT (s1, 0);
+ break;
+ case (1 << 1) | 0:
+ XINT (result, 0) = XINT (s1, 0) & ~XINT (s2, 0);
+ break;
+ case (1 << 1) | 1:
+ XINT (result, 0) = XINT (s1, 0) & XINT (s2, 0);
+ break;
+ default:
+ abort ();
+ }
+
+ XINT (result, 1) = XINT (s1, 1) | XINT (s2, 1);
+ return result;
+}
+
+/* Return EQ_ATTR_ALT expression representing complement of S. */
+
+static rtx
+attr_alt_complement (rtx s)
+{
+ rtx result = rtx_alloc (EQ_ATTR_ALT);
+
+ XINT (result, 0) = XINT (s, 0);
+ XINT (result, 1) = 1 - XINT (s, 1);
+
+ return result;
+}
+
+/* Tests whether a bit B belongs to the set represented by S. */
+
+static bool
+attr_alt_bit_p (rtx s, int b)
+{
+ return XINT (s, 1) ^ ((XINT (s, 0) >> b) & 1);
+}
+
+/* Return EQ_ATTR_ALT expression representing set containing elements set
+ in E. */
+
+static rtx
+mk_attr_alt (int e)
+{
+ rtx result = rtx_alloc (EQ_ATTR_ALT);
+
+ XINT (result, 0) = e;
+ XINT (result, 1) = 0;
+
+ return result;
+}
+
/* Given an expression, see if it can be simplified for a particular insn
code based on the values of other attributes being tested. This can
eliminate nested get_attr_... calls.
struct insn_ent *ie;
int i;
rtx newexp = exp;
+ bool left_alt, right_alt;
/* Don't re-simplify something we already simplified. */
if (ATTR_IND_SIMPLIFIED_P (exp) || ATTR_CURR_SIMPLIFIED_P (exp))
if (left == false_rtx)
return false_rtx;
+ if (GET_CODE (left) == EQ_ATTR_ALT
+ && GET_CODE (right) == EQ_ATTR_ALT)
+ {
+ exp = attr_alt_intersection (left, right);
+ return simplify_test_exp (exp, insn_code, insn_index);
+ }
+
/* If either side is an IOR and we have (eq_attr "alternative" ..")
present on both sides, apply the distributive law since this will
yield simplifications. */
/* See if all or all but one of the insn's alternatives are specified
in this tree. Optimize if so. */
- else if (insn_code >= 0
- && (GET_CODE (left) == AND
- || (GET_CODE (left) == NOT
- && GET_CODE (XEXP (left, 0)) == EQ_ATTR
- && XSTR (XEXP (left, 0), 0) == alternative_name)
- || GET_CODE (right) == AND
- || (GET_CODE (right) == NOT
- && GET_CODE (XEXP (right, 0)) == EQ_ATTR
- && XSTR (XEXP (right, 0), 0) == alternative_name)))
+ if (GET_CODE (left) == NOT)
+ left_alt = (GET_CODE (XEXP (left, 0)) == EQ_ATTR
+ && XSTR (XEXP (left, 0), 0) == alternative_name);
+ else
+ left_alt = (GET_CODE (left) == EQ_ATTR_ALT
+ && XINT (left, 1));
+
+ if (GET_CODE (right) == NOT)
+ right_alt = (GET_CODE (XEXP (right, 0)) == EQ_ATTR
+ && XSTR (XEXP (right, 0), 0) == alternative_name);
+ else
+ right_alt = (GET_CODE (right) == EQ_ATTR_ALT
+ && XINT (right, 1));
+
+ if (insn_code >= 0
+ && (GET_CODE (left) == AND
+ || left_alt
+ || GET_CODE (right) == AND
+ || right_alt))
{
i = compute_alternative_mask (exp, AND);
if (i & ~insn_alternatives[insn_code])
if (right == true_rtx)
return true_rtx;
+ if (GET_CODE (left) == EQ_ATTR_ALT
+ && GET_CODE (right) == EQ_ATTR_ALT)
+ {
+ exp = attr_alt_union (left, right);
+ return simplify_test_exp (exp, insn_code, insn_index);
+ }
+
right = simplify_or_tree (right, &left, insn_code, insn_index);
if (left == XEXP (exp, 0) && right == XEXP (exp, 1))
left = simplify_or_tree (left, &right, insn_code, insn_index);
else if (insn_code >= 0
&& (GET_CODE (left) == IOR
+ || (GET_CODE (left) == EQ_ATTR_ALT
+ && !XINT (left, 1))
|| (GET_CODE (left) == EQ_ATTR
&& XSTR (left, 0) == alternative_name)
|| GET_CODE (right) == IOR
+ || (GET_CODE (right) == EQ_ATTR_ALT
+ && !XINT (right, 1))
|| (GET_CODE (right) == EQ_ATTR
&& XSTR (right, 0) == alternative_name)))
{
if (left == false_rtx)
return true_rtx;
- else if (left == true_rtx)
+ if (left == true_rtx)
return false_rtx;
+ if (GET_CODE (left) == EQ_ATTR_ALT)
+ {
+ exp = attr_alt_complement (left);
+ return simplify_test_exp (exp, insn_code, insn_index);
+ }
+
/* Try to apply De`Morgan's laws. */
- else if (GET_CODE (left) == IOR)
+ if (GET_CODE (left) == IOR)
{
newexp = attr_rtx (AND,
attr_rtx (NOT, XEXP (left, 0)),
}
break;
+ case EQ_ATTR_ALT:
+ if (current_alternative_string)
+ return attr_alt_bit_p (exp, atoi (current_alternative_string)) ? true_rtx : false_rtx;
+
+ if (!XINT (exp, 0))
+ return XINT (exp, 1) ? true_rtx : false_rtx;
+ break;
+
case EQ_ATTR:
if (current_alternative_string && XSTR (exp, 0) == alternative_name)
return (XSTR (exp, 1) == current_alternative_string
? true_rtx : false_rtx);
+ if (XSTR (exp, 0) == alternative_name)
+ {
+ newexp = mk_attr_alt (1 << atoi (XSTR (exp, 1)));
+ break;
+ }
+
/* Look at the value for this insn code in the specified attribute.
We normally can replace this comparison with the condition that
would give this insn the values being tested for. */
if (XSTR (exp, 0) != alternative_name
- && (attr = find_attr (XSTR (exp, 0), 0)) != NULL)
+ && (attr = find_attr (&XSTR (exp, 0), 0)) != NULL)
for (av = attr->first_value; av; av = av->next)
for (ie = av->first_insn; ie; ie = ie->next)
if (ie->insn_code == insn_code)
return;
/* Make 2 extra elements, for "code" values -2 and -1. */
- insn_code_values
- = (struct attr_value_list **) xmalloc ((insn_code_number + 2)
- * sizeof (struct attr_value_list *));
- memset ((char *) insn_code_values, 0,
- (insn_code_number + 2) * sizeof (struct attr_value_list *));
+ insn_code_values = xcalloc ((insn_code_number + 2),
+ sizeof (struct attr_value_list *));
/* Offset the table address so we can index by -2 or -1. */
insn_code_values += 2;
- iv = ivbuf = ((struct attr_value_list *)
- xmalloc (num_insn_ents * sizeof (struct attr_value_list)));
+ iv = ivbuf = xmalloc (num_insn_ents * sizeof (struct attr_value_list));
for (i = 0; i < MAX_ATTRS_INDEX; i++)
for (attr = attrs[i]; attr; attr = attr->next)
cover the domain of the attribute. This makes the expanded COND form
order independent. */
- space = (struct dimension *) xmalloc (ndim * sizeof (struct dimension));
+ space = xmalloc (ndim * sizeof (struct dimension));
total = 1;
for (ndim = 0; list; ndim++)
const char *name = XSTR (XEXP (list, 0), 0);
rtx *prev;
- if ((space[ndim].attr = find_attr (name, 0)) == 0
+ space[ndim].attr = find_attr (&name, 0);
+ XSTR (XEXP (list, 0), 0) = name;
+
+ if (space[ndim].attr == 0
|| space[ndim].attr->is_numeric)
{
unmark_used_attributes (list, space, ndim);
space[ndim].values = 0;
prev = &list;
for (link = list; link; link = *prev)
- if (! strcmp (XSTR (XEXP (link, 0), 0), name))
+ if (! strcmp_check (XSTR (XEXP (link, 0), 0), name))
{
space[ndim].num_values++;
*prev = XEXP (link, 1);
for (i = 0; i < ndim; i++)
space[i].current_value = space[i].values;
- condtest = (rtx *) xmalloc (total * sizeof (rtx));
- condval = (rtx *) xmalloc (total * sizeof (rtx));
+ condtest = xmalloc (total * sizeof (rtx));
+ condval = xmalloc (total * sizeof (rtx));
/* Expand the tests and values by iterating over all values in the
attribute space. */
}
}
-/* Return the number of RTX objects making up the expression X.
- But if we count more than MAX objects, stop counting. */
-
-static int
-count_sub_rtxs (rtx x, int max)
-{
- int i;
- int j;
- enum rtx_code code;
- const char *fmt;
- int total = 0;
-
- code = GET_CODE (x);
-
- switch (code)
- {
- case REG:
- case QUEUED:
- case CONST_INT:
- case CONST_DOUBLE:
- case CONST_VECTOR:
- case SYMBOL_REF:
- case CODE_LABEL:
- case PC:
- case CC0:
- case EQ_ATTR:
- case ATTR_FLAG:
- return 1;
-
- default:
- break;
- }
-
- /* Compare the elements. If any pair of corresponding elements
- fail to match, return 0 for the whole things. */
-
- fmt = GET_RTX_FORMAT (code);
- for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
- {
- if (total >= max)
- return total;
-
- switch (fmt[i])
- {
- case 'V':
- case 'E':
- for (j = 0; j < XVECLEN (x, i); j++)
- total += count_sub_rtxs (XVECEXP (x, i, j), max);
- break;
-
- case 'e':
- total += count_sub_rtxs (XEXP (x, i), max);
- break;
- }
- }
- return total;
-
-}
-
/* Create table entries for DEFINE_ATTR. */
static void
/* Make a new attribute structure. Check for duplicate by looking at
attr->default_val, since it is initialized by this routine. */
- attr = find_attr (XSTR (exp, 0), 1);
+ attr = find_attr (&XSTR (exp, 0), 1);
if (attr->default_val)
{
message_with_line (lineno, "duplicate definition for attribute %s",
name_ptr = XSTR (exp, 1);
while ((p = next_comma_elt (&name_ptr)) != NULL)
{
- av = (struct attr_value *) oballoc (sizeof (struct attr_value));
+ av = oballoc (sizeof (struct attr_value));
av->value = attr_rtx (CONST_STRING, p);
av->next = attr->first_value;
attr->first_value = av;
XEXP (exp, 2) = XEXP (XEXP (exp, 2), 0);
}
- if (! strcmp (attr->name, "length") && ! attr->is_numeric)
+ if (! strcmp_check (attr->name, length_str) && ! attr->is_numeric)
{
message_with_line (lineno,
"`length' attribute must take numeric values");
{
struct insn_def *id;
- id = (struct insn_def *) oballoc (sizeof (struct insn_def));
+ id = oballoc (sizeof (struct insn_def));
id->next = defs;
defs = id;
id->def = exp;
have_annul_false = 1;
}
- delay = (struct delay_desc *) oballoc (sizeof (struct delay_desc));
+ delay = oballoc (sizeof (struct delay_desc));
delay->def = def;
delay->num = ++num_delays;
delay->next = delays;
if (unit == 0)
{
- unit = (struct function_unit *) oballoc (sizeof (struct function_unit));
+ unit = oballoc (sizeof (struct function_unit));
unit->name = name;
unit->multiplicity = multiplicity;
unit->simultaneity = simultaneity;
unit->first_lineno = lineno;
units = unit;
}
+ else
+ XSTR (def, 0) = unit->name;
/* Make a new operation class structure entry and initialize it. */
- op = (struct function_unit_op *) oballoc (sizeof (struct function_unit_op));
+ op = oballoc (sizeof (struct function_unit_op));
op->condexp = condexp;
op->num = unit->num_opclasses++;
op->ready = ready_cost;
write_test_expr (XEXP (exp, 0), flags);
break;
+ case EQ_ATTR_ALT:
+ {
+ int set = XINT (exp, 0), bit = 0;
+
+ if (flags & 1)
+ fatal ("EQ_ATTR_ALT not valid inside comparison");
+
+ if (!set)
+ fatal ("Empty EQ_ATTR_ALT should be optimized out");
+
+ if (!(set & (set - 1)))
+ {
+ if (!(set & 0xffff))
+ {
+ bit += 16;
+ set >>= 16;
+ }
+ if (!(set & 0xff))
+ {
+ bit += 8;
+ set >>= 8;
+ }
+ if (!(set & 0xf))
+ {
+ bit += 4;
+ set >>= 4;
+ }
+ if (!(set & 0x3))
+ {
+ bit += 2;
+ set >>= 2;
+ }
+ if (!(set & 1))
+ bit++;
+
+ printf ("which_alternative %s= %d",
+ XINT (exp, 1) ? "!" : "=", bit);
+ }
+ else
+ {
+ printf ("%s((1 << which_alternative) & 0x%x)",
+ XINT (exp, 1) ? "!" : "", set);
+ }
+ }
+ break;
+
/* Comparison test of an attribute with a value. Most of these will
have been removed by optimization. Handle "alternative"
specially and give error if EQ_ATTR present inside a comparison. */
break;
}
- attr = find_attr (XSTR (exp, 0), 0);
+ attr = find_attr (&XSTR (exp, 0), 0);
if (! attr)
abort ();
must_extract = 1;
return;
+ case EQ_ATTR_ALT:
+ must_extract = must_constrain = 1;
+ break;
+
case EQ_ATTR:
if (XSTR (exp, 0) == alternative_name)
must_extract = must_constrain = 1;
- else if (strcmp (XSTR (exp, 0), "length") == 0)
+ else if (strcmp_check (XSTR (exp, 0), length_str) == 0)
length_used = 1;
return;
switch we will generate. */
common_av = find_most_used (attr);
- /* Write out prototype of function. */
- if (!attr->is_numeric)
- printf ("extern enum attr_%s ", attr->name);
- else if (attr->unsigned_p)
- printf ("extern unsigned int ");
- else
- printf ("extern int ");
- /* If the attribute name starts with a star, the remainder is the name of
- the subroutine to use, instead of `get_attr_...'. */
- if (attr->name[0] == '*')
- printf ("%s (rtx);\n", &attr->name[1]);
- else
- printf ("get_attr_%s (%s);\n", attr->name,
- (attr->is_const ? "void" : "rtx"));
-
/* Write out start of function, then all values with explicit `case' lines,
then a `default', then the value with the most uses. */
+ if (attr->static_p)
+ printf ("static ");
if (!attr->is_numeric)
printf ("enum attr_%s\n", attr->name);
else if (attr->unsigned_p)
/* If the attribute name starts with a star, the remainder is the name of
the subroutine to use, instead of `get_attr_...'. */
if (attr->name[0] == '*')
- printf ("%s (insn)\n", &attr->name[1]);
+ printf ("%s (rtx insn ATTRIBUTE_UNUSED)\n", &attr->name[1]);
else if (attr->is_const == 0)
- printf ("get_attr_%s (insn)\n", attr->name);
+ printf ("get_attr_%s (rtx insn ATTRIBUTE_UNUSED)\n", attr->name);
else
{
- printf ("get_attr_%s ()\n", attr->name);
+ printf ("get_attr_%s (void)\n", attr->name);
printf ("{\n");
for (av = attr->first_value; av; av = av->next)
return;
}
- printf (" rtx insn ATTRIBUTE_UNUSED;\n");
printf ("{\n");
if (GET_CODE (common_av->value) == FFS)
case ATTR:
{
- struct attr_desc *attr2 = find_attr (XSTR (value, 0), 0);
+ struct attr_desc *attr2 = find_attr (&XSTR (value, 0), 0);
printf ("get_attr_%s (%s)", attr2->name,
(attr2->is_const ? "" : "insn"));
}
struct delay_desc *delay;
int max_slots;
char str[50];
+ const char *pstr;
struct attr_desc *attr;
struct attr_value *av, *common_av;
int i;
/* Write function prelude. */
printf ("int\n");
- printf ("eligible_for_%s (delay_insn, slot, candidate_insn, flags)\n",
+ printf ("eligible_for_%s (rtx delay_insn ATTRIBUTE_UNUSED, int slot, rtx candidate_insn, int flags ATTRIBUTE_UNUSED)\n",
kind);
- printf (" rtx delay_insn ATTRIBUTE_UNUSED;\n");
- printf (" int slot;\n");
- printf (" rtx candidate_insn;\n");
- printf (" int flags ATTRIBUTE_UNUSED;\n");
printf ("{\n");
printf (" rtx insn;\n");
printf ("\n");
if (num_delays > 1)
{
- attr = find_attr ("*delay_type", 0);
+ attr = find_attr (&delay_type_str, 0);
if (! attr)
abort ();
common_av = find_most_used (attr);
printf (" switch (recog_memoized (insn))\n");
printf (" {\n");
- attr = find_attr ("*delay_1_0", 0);
+ attr = find_attr (&delay_1_0_str, 0);
if (! attr)
abort ();
common_av = find_most_used (attr);
printf ("\t{\n");
sprintf (str, "*%s_%d_%d", kind, delay->num, i / 3);
- attr = find_attr (str, 0);
+ pstr = str;
+ attr = find_attr (&pstr, 0);
if (! attr)
abort ();
common_av = find_most_used (attr);
struct attr_value *av, *common_av;
rtx value;
char str[256];
+ const char *pstr;
int using_case;
int i;
- printf ("static int %s_unit_%s (rtx, rtx);\n", unit->name, name);
printf ("static int\n");
- printf ("%s_unit_%s (executing_insn, candidate_insn)\n", unit->name, name);
- printf (" rtx executing_insn;\n");
- printf (" rtx candidate_insn;\n");
+ printf ("%s_unit_%s (rtx executing_insn, rtx candidate_insn)\n",
+ unit->name, name);
printf ("{\n");
printf (" rtx insn;\n");
printf (" int casenum;\n\n");
if (strlen (unit->name) + sizeof "*_cases" > 256)
abort ();
sprintf (str, "*%s_cases", unit->name);
- case_attr = find_attr (str, 0);
+ pstr = str;
+ case_attr = find_attr (&pstr, 0);
if (! case_attr)
abort ();
common_av = find_most_used (case_attr);
printf (" case %d:\n", i);
sprintf (str, "*%s_%s_%d", unit->name, connection, i);
- attr = find_attr (str, 0);
+ pstr = str;
+ attr = find_attr (&pstr, 0);
if (! attr)
abort ();
}
/* Return a `struct attr_desc' pointer for a given named attribute. If CREATE
- is nonzero, build a new attribute, if one does not exist. */
+ is nonzero, build a new attribute, if one does not exist. *NAME_P is
+ replaced by a pointer to a canonical copy of the string. */
static struct attr_desc *
-find_attr (const char *name, int create)
+find_attr (const char **name_p, int create)
{
struct attr_desc *attr;
int index;
+ const char *name = *name_p;
/* Before we resort to using `strcmp', see if the string address matches
anywhere. In most cases, it should have been canonicalized to do so. */
/* Otherwise, do it the slow way. */
for (attr = attrs[index]; attr; attr = attr->next)
if (name[0] == attr->name[0] && ! strcmp (name, attr->name))
- return attr;
+ {
+ *name_p = attr->name;
+ return attr;
+ }
if (! create)
return NULL;
- attr = (struct attr_desc *) oballoc (sizeof (struct attr_desc));
- attr->name = attr_string (name, strlen (name));
+ attr = oballoc (sizeof (struct attr_desc));
+ attr->name = DEF_ATTR_STRING (name);
attr->first_value = attr->default_val = NULL;
attr->is_numeric = attr->negative_ok = attr->is_const = attr->is_special = 0;
- attr->unsigned_p = attr->func_units_p = attr->blockage_p = 0;
+ attr->unsigned_p = attr->func_units_p = attr->blockage_p = attr->static_p = 0;
attr->next = attrs[index];
attrs[index] = attr;
+ *name_p = attr->name;
+
return attr;
}
{
struct attr_desc *attr;
- attr = find_attr (name, 1);
+ attr = find_attr (&name, 1);
if (attr->default_val)
abort ();
attr->is_numeric = 1;
attr->is_const = 0;
- attr->is_special = (special & 1) != 0;
- attr->negative_ok = (special & 2) != 0;
- attr->unsigned_p = (special & 4) != 0;
- attr->func_units_p = (special & 8) != 0;
- attr->blockage_p = (special & 16) != 0;
+ attr->is_special = (special & ATTR_SPECIAL) != 0;
+ attr->negative_ok = (special & ATTR_NEGATIVE_OK) != 0;
+ attr->unsigned_p = (special & ATTR_UNSIGNED) != 0;
+ attr->func_units_p = (special & ATTR_FUNC_UNITS) != 0;
+ attr->blockage_p = (special & ATTR_BLOCKAGE) != 0;
+ attr->static_p = (special & ATTR_STATIC) != 0;
attr->default_val = get_attr_value (value, attr, -2);
}
static void
write_const_num_delay_slots (void)
{
- struct attr_desc *attr = find_attr ("*num_delay_slots", 0);
+ struct attr_desc *attr = find_attr (&num_delay_slots_str, 0);
struct attr_value *av;
struct insn_ent *ie;
if (attr)
{
- printf ("int\nconst_num_delay_slots (insn)\n");
- printf (" rtx insn;\n");
+ printf ("int\nconst_num_delay_slots (rtx insn)\n");
printf ("{\n");
printf (" switch (recog_memoized (insn))\n");
printf (" {\n");
ATTR_IND_SIMPLIFIED_P (true_rtx) = ATTR_IND_SIMPLIFIED_P (false_rtx) = 1;
ATTR_PERMANENT_P (true_rtx) = ATTR_PERMANENT_P (false_rtx) = 1;
- alternative_name = attr_string ("alternative", strlen ("alternative"));
+ alternative_name = DEF_ATTR_STRING ("alternative");
+ length_str = DEF_ATTR_STRING ("length");
+ delay_type_str = DEF_ATTR_STRING ("*delay_type");
+ delay_1_0_str = DEF_ATTR_STRING ("*delay_1_0");
+ num_delay_slots_str = DEF_ATTR_STRING ("*num_delay_slots");
printf ("/* Generated automatically by the program `genattrtab'\n\
from the machine description file `md'. */\n\n");
printf ("#define operands recog_data.operand\n\n");
/* Make `insn_alternatives'. */
- insn_alternatives = (int *) oballoc (insn_code_number * sizeof (int));
+ insn_alternatives = oballoc (insn_code_number * sizeof (int));
for (id = defs; id; id = id->next)
if (id->insn_code >= 0)
insn_alternatives[id->insn_code] = (1 << id->num_alternatives) - 1;
/* Make `insn_n_alternatives'. */
- insn_n_alternatives = (int *) oballoc (insn_code_number * sizeof (int));
+ insn_n_alternatives = oballoc (insn_code_number * sizeof (int));
for (id = defs; id; id = id->next)
if (id->insn_code >= 0)
insn_n_alternatives[id->insn_code] = id->num_alternatives;
insn_alts_p
= (attr->name [0] == '*'
- && strcmp (&attr->name [1], INSN_ALTS_FUNC_NAME) == 0);
+ && strcmp (&attr->name[1], INSN_ALTS_FUNC_NAME) == 0);
if (insn_alts_p)
printf ("\n#if AUTOMATON_ALTS\n");
write_attr_get (attr);