diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-28 03:28:18 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-28 03:28:18 +0000 |
commit | 026d38685a306238520bd2dc743b94e66ecf450f (patch) | |
tree | bfe845d7fbc0991a92a6a103f30e8889f0bd0a62 /gcc/genoutput.c | |
parent | 89ada49235886dd26d5c0d710132c9f66e1493f4 (diff) | |
download | gcc-026d38685a306238520bd2dc743b94e66ecf450f.tar.gz |
* rtl.def (define_constraint, define_register_constraint)
(define_memory_constraint, define_address_constraint): New MD forms.
* gensupport.c (process_rtx): Put define_constraint etc on the
predicate queue.
* genpreds.c (process_define_predicate): Adjust comment. Validate
the name, and call validate_exp to validate the expression.
(mark_mode_tests, write_extract_subexp): Can assume correct input.
(write_predicate_expr): Likewise. NAME argument no longer necessary;
all callers changed.
(validate_exp, needs_variable, struct constraint_data)
(constraints_by_letter_table, first_constraint, last_constraint_ptr)
(FOR_ALL_CONSTRAINTS, generic_constraint_letters, const_int_constraints)
(const_dbl_constraints, constraint_max_namelen)
(have_register_constraints, have_memory_constraints)
(have_address_constraints, have_address_constraints)
(have_extra_constraints, have_const_int_constraints)
(have_const_dbl_constraints, mangle, add_constraint)
(process_define_constraint, process_define_register_constraint)
(write_enum_constraint_num, write_lookup_constraint)
(write_insn_constraint_len, write_regclass_for_constraint)
(write_constraint_satisfied_p, write_insn_const_int_ok_for_constraint)
(write_insn_extra_memory_constraint)
(write_insn_extra_address_constraint)
(write_satisfies_constraint_fns): New.
(write_tm_preds_h): If we have new-style constraint definitions,
prototype the functions generated from them, and define the
old constraint interface (still used by generic code) in terms of
those functions.
(write_insn_preds_c): If we have new-style constraint definitions,
generate all relevant functions from those definitions.
(main): Handle define_constraint etc.
* genoutput.c (struct constraint_data, indep_constraints)
(mdep_constraint_letters, constraints_by_letter_table, note_constraint)
(mdep_constraint_len): New data structures and functions, defined
#ifdef USE_MD_CONSTRAINTS.
(check_constraint_len): Don't define #ifdef USE_MD_CONSTRAINTS.
(validate_insn_alternatives): If USE_MD_CONSTRAINTS is defined,
use new logic to validate operand constraints against constraint
definitions.
(main): Process define_constraint etc. if USE_MD_CONSTRAINTS is
defined.
* defaults.h: If none of the old-style constraint macros are
defined, define USE_MD_CONSTRAINTS; do not provide defaults for any
old-style macros; and poison REG_CLASS_FROM_LETTER,
CONST_OK_FOR_LETTER_P, CONST_DOUBLE_OK_FOR_LETTER_P, and
EXTRA_CONSTRAINT.
* recog.c (reg_fits_class_p): If cl is NO_REGS, return 0 immediately.
* doc/md.texi: Document new constraint-definition mechanism and the
C interface it provides. Remove references to old mechanism
elsewhere in the document.
(Machine Constraints): Use pathnames relative to gcc directory,
i.e. config/ARCH/FILE. Change i386 section to refer to
config/i386/predicates.md; update that section to match docstrings.
* doc/tm.texi: Move all documentation of the old constraint-
definition macros to their own section, clearly mark as obsolete.
* config/i386/predicates.md (R, q, Q, l, a, b, c, d, S, D, A, f, t)
(u, y, x, Y, I, J, K, L, M, N, O, G, C, e, Z): New constraint
definitions.
* config/i386/i386.h (REG_CLASS_FROM_LETTER, CONST_OK_FOR_LETTER_P)
(CONST_DOUBLE_OK_FOR_LETTER_P, EXTRA_CONSTRAINT): Delete.
* config/i386/i386.md (*movdf_nointeger): Remove stray 'H' from
constraint strings.
(splits and peepholes): Use satisfies_constraint_*.
* config/i386/i386.c (memory_address_length)
(ix86_attr_length_immediate_default): Use satisfies_constraint_*.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111508 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/genoutput.c')
-rw-r--r-- | gcc/genoutput.c | 187 |
1 files changed, 174 insertions, 13 deletions
diff --git a/gcc/genoutput.c b/gcc/genoutput.c index 7d1feb6fdca..4eac5818729 100644 --- a/gcc/genoutput.c +++ b/gcc/genoutput.c @@ -54,12 +54,10 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA a. `predicate', an int-valued function, is the match_operand predicate for this operand. - b. `constraint' is the constraint for this operand. This exists - only if register constraints appear in match_operand rtx's. + b. `constraint' is the constraint for this operand. c. `address_p' indicates that the operand appears within ADDRESS - rtx's. This exists only if there are *no* register constraints - in the match_operand rtx's. + rtx's. d. `mode' is the machine mode that that operand is supposed to have. @@ -189,8 +187,35 @@ static void gen_insn (rtx, int); static void gen_peephole (rtx, int); static void gen_expand (rtx, int); static void gen_split (rtx, int); + +#ifdef USE_MD_CONSTRAINTS + +struct constraint_data +{ + struct constraint_data *next_this_letter; + int lineno; + unsigned int namelen; + const char name[1]; +}; + +/* This is a complete list (unlike the one in genpreds.c) of constraint + letters and modifiers with machine-independent meaning. The only + omission is digits, as these are handled specially. */ +static const char indep_constraints[] = ",=+%*?!#&<>EFVXgimnoprs"; + +static struct constraint_data * +constraints_by_letter_table[1 << CHAR_BIT]; + +static int mdep_constraint_len (const char *, int, int); +static void note_constraint (rtx, int); + +#else /* !USE_MD_CONSTRAINTS */ + static void check_constraint_len (void); static int constraint_len (const char *, int); + +#endif /* !USE_MD_CONSTRAINTS */ + static void output_prologue (void) @@ -725,6 +750,20 @@ validate_insn_alternatives (struct data *d) for (p = d->operand[start].constraint; (c = *p); p += len) { +#ifdef USE_MD_CONSTRAINTS + if (ISSPACE (c) || strchr (indep_constraints, c)) + len = 1; + else if (ISDIGIT (c)) + { + const char *q = p; + do + q++; + while (ISDIGIT (*q)); + len = q - p; + } + else + len = mdep_constraint_len (p, d->lineno, start); +#else len = CONSTRAINT_LEN (c, p); if (len < 1 || (len > 1 && strchr (",#*+=&%!0123456789", c))) @@ -735,6 +774,7 @@ validate_insn_alternatives (struct data *d) len = 1; have_error = 1; } +#endif if (c == ',') { @@ -826,7 +866,9 @@ gen_insn (rtx insn, int lineno) d->n_operands = max_opno + 1; d->n_dups = num_dups; +#ifndef USE_MD_CONSTRAINTS check_constraint_len (); +#endif validate_insn_operands (d); validate_insn_alternatives (d); place_operands (d); @@ -983,15 +1025,37 @@ main (int argc, char **argv) if (desc == NULL) break; - if (GET_CODE (desc) == DEFINE_INSN) - gen_insn (desc, line_no); - if (GET_CODE (desc) == DEFINE_PEEPHOLE) - gen_peephole (desc, line_no); - if (GET_CODE (desc) == DEFINE_EXPAND) - gen_expand (desc, line_no); - if (GET_CODE (desc) == DEFINE_SPLIT - || GET_CODE (desc) == DEFINE_PEEPHOLE2) - gen_split (desc, line_no); + switch (GET_CODE (desc)) + { + case DEFINE_INSN: + gen_insn (desc, line_no); + break; + + case DEFINE_PEEPHOLE: + gen_peephole (desc, line_no); + break; + + case DEFINE_EXPAND: + gen_expand (desc, line_no); + break; + + case DEFINE_SPLIT: + case DEFINE_PEEPHOLE2: + gen_split (desc, line_no); + break; + +#ifdef USE_MD_CONSTRAINTS + case DEFINE_CONSTRAINT: + case DEFINE_REGISTER_CONSTRAINT: + case DEFINE_ADDRESS_CONSTRAINT: + case DEFINE_MEMORY_CONSTRAINT: + note_constraint (desc, line_no); + break; +#endif + + default: + break; + } next_index_number++; } @@ -1043,6 +1107,102 @@ strip_whitespace (const char *s) return q; } +#ifdef USE_MD_CONSTRAINTS + +/* Record just enough information about a constraint to allow checking + of operand constraint strings above, in validate_insn_alternatives. + Does not validate most properties of the constraint itself; does + enforce no duplicate names, no overlap with MI constraints, and no + prefixes. EXP is the define_*constraint form, LINENO the line number + reported by the reader. */ +static void +note_constraint (rtx exp, int lineno) +{ + const char *name = XSTR (exp, 0); + unsigned int namelen = strlen (name); + struct constraint_data **iter, **slot, *new; + + if (strchr (indep_constraints, name[0])) + { + if (name[1] == '\0') + message_with_line (lineno, "constraint letter '%s' cannot be " + "redefined by the machine description", name); + else + message_with_line (lineno, "constraint name '%s' cannot be defined by " + "the machine description, as it begins with '%c'", + name, name[0]); + have_error = 1; + return; + } + + slot = &constraints_by_letter_table[(unsigned int)name[0]]; + for (iter = slot; *iter; iter = &(*iter)->next_this_letter) + { + /* This causes slot to end up pointing to the + next_this_letter field of the last constraint with a name + of equal or greater length than the new constraint; hence + the new constraint will be inserted after all previous + constraints with names of the same length. */ + if ((*iter)->namelen >= namelen) + slot = iter; + + if (!strcmp ((*iter)->name, name)) + { + message_with_line (lineno, "redefinition of constraint '%s'", name); + message_with_line ((*iter)->lineno, "previous definition is here"); + have_error = 1; + return; + } + else if (!strncmp ((*iter)->name, name, (*iter)->namelen)) + { + message_with_line (lineno, "defining constraint '%s' here", name); + message_with_line ((*iter)->lineno, "renders constraint '%s' " + "(defined here) a prefix", (*iter)->name); + have_error = 1; + return; + } + else if (!strncmp ((*iter)->name, name, namelen)) + { + message_with_line (lineno, "constraint '%s' is a prefix", name); + message_with_line ((*iter)->lineno, "of constraint '%s' " + "(defined here)", (*iter)->name); + have_error = 1; + return; + } + } + new = xmalloc (sizeof (struct constraint_data) + namelen); + strcpy ((char *)new + offsetof(struct constraint_data, name), name); + new->namelen = namelen; + new->lineno = lineno; + new->next_this_letter = *slot; + *slot = new; +} + +/* Return the length of the constraint name beginning at position S + of an operand constraint string, or issue an error message if there + is no such constraint. Does not expect to be called for generic + constraints. */ +static int +mdep_constraint_len (const char *s, int lineno, int opno) +{ + struct constraint_data *p; + + p = constraints_by_letter_table[(unsigned int)s[0]]; + + if (p) + for (; p; p = p->next_this_letter) + if (!strncmp (s, p->name, p->namelen)) + return p->namelen; + + message_with_line (lineno, + "error: undefined machine-specific constraint " + "at this point: \"%s\"", s); + message_with_line (lineno, "note: in operand %d", opno); + have_error = 1; + return 1; /* safe */ +} + +#else /* Verify that DEFAULT_CONSTRAINT_LEN is used properly and not tampered with. This isn't bullet-proof, but it should catch most genuine mistakes. */ @@ -1076,3 +1236,4 @@ constraint_len (const char *p, int genoutput_default_constraint_len) #undef DEFAULT_CONSTRAINT_LEN #define DEFAULT_CONSTRAINT_LEN(C,STR) 1 } +#endif |