recog.h revision 169689
11817Sdg/* Declarations for interface to insn recognizer and insn-output.c.
21817Sdg   Copyright (C) 1987, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
31817Sdg   Free Software Foundation, Inc.
41817Sdg
51817SdgThis file is part of GCC.
61817Sdg
71817SdgGCC is free software; you can redistribute it and/or modify it under
81817Sdgthe terms of the GNU General Public License as published by the Free
91817SdgSoftware Foundation; either version 2, or (at your option) any later
101817Sdgversion.
111817Sdg
121817SdgGCC is distributed in the hope that it will be useful, but WITHOUT ANY
131817SdgWARRANTY; without even the implied warranty of MERCHANTABILITY or
141817SdgFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
151817Sdgfor more details.
161817Sdg
171817SdgYou should have received a copy of the GNU General Public License
181817Sdgalong with GCC; see the file COPYING.  If not, write to the Free
191817SdgSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
201817Sdg02110-1301, USA.  */
211817Sdg
221817Sdg/* Random number that should be large enough for all purposes.  */
231817Sdg#define MAX_RECOG_ALTERNATIVES 30
241817Sdg
251817Sdg/* Types of operands.  */
261817Sdgenum op_type {
271817Sdg  OP_IN,
281817Sdg  OP_OUT,
2950477Speter  OP_INOUT
301817Sdg};
311817Sdg
322579Sbdestruct operand_alternative
332579Sbde{
342123Sjkh  /* Pointer to the beginning of the constraint string for this alternative,
3516029Speter     for easier access by alternative number.  */
362579Sbde  const char *constraint;
3718961Sbde
3813107Sbde  /* The register class valid for this alternative (possibly NO_REGS).  */
3925083Sjdp  enum reg_class cl;
40163726Sbde
4125083Sjdp  /* "Badness" of this alternative, computed from number of '?' and '!'
4225083Sjdp     characters in the constraint string.  */
43163726Sbde  unsigned int reject;
4425083Sjdp
4525083Sjdp  /* -1 if no matching constraint was found, or an operand number.  */
4625083Sjdp  int matches;
47114349Speter  /* The same information, but reversed: -1 if this operand is not
4822636Sbde     matched by any other, or the operand number of the operand that
4925083Sjdp     matches this one.  */
5022636Sbde  int matched;
51114349Speter
5222636Sbde  /* Nonzero if '&' was found in the constraint string.  */
5325083Sjdp  unsigned int earlyclobber:1;
54757Sdg  /* Nonzero if 'm' was found in the constraint string.  */
5525083Sjdp  unsigned int memory_ok:1;
5646548Sbde  /* Nonzero if 'o' was found in the constraint string.  */
5713107Sbde  unsigned int offmem_ok:1;
5818961Sbde  /* Nonzero if 'V' was found in the constraint string.  */
59757Sdg  unsigned int nonoffmem_ok:1;
60171914Sjkoshy  /* Nonzero if '<' was found in the constraint string.  */
61171914Sjkoshy  unsigned int decmem_ok:1;
62757Sdg  /* Nonzero if '>' was found in the constraint string.  */
63757Sdg  unsigned int incmem_ok:1;
6446548Sbde  /* Nonzero if 'p' was found in the constraint string.  */
6513107Sbde  unsigned int is_address:1;
6613107Sbde  /* Nonzero if 'X' was found in the constraint string, or if the constraint
6713107Sbde     string for this alternative was empty.  */
6813107Sbde  unsigned int anything_ok:1;
6913107Sbde};
7013107Sbde
7113107Sbde
7213107Sbdeextern void init_recog (void);
7346548Sbdeextern void init_recog_no_volatile (void);
7418961Sbdeextern int check_asm_operands (rtx);
7518961Sbdeextern int asm_operand_ok (rtx, const char *);
7646548Sbdeextern int validate_change (rtx, rtx *, rtx, int);
7718961Sbdeextern int insn_invalid_p (rtx);
7818961Sbdeextern int verify_changes (int);
7913107Sbdeextern void confirm_change_group (void);
8046548Sbdeextern int apply_change_group (void);
8146548Sbdeextern int num_validated_changes (void);
8213107Sbdeextern void cancel_changes (int);
8318961Sbdeextern int constrain_operands (int);
8446548Sbdeextern int constrain_operands_cached (int);
8546548Sbdeextern int memory_address_p (enum machine_mode, rtx);
8618961Sbdeextern int strict_memory_address_p (enum machine_mode, rtx);
8718961Sbdeextern int validate_replace_rtx (rtx, rtx, rtx);
8813107Sbdeextern void validate_replace_rtx_group (rtx, rtx, rtx);
8913107Sbdeextern void validate_replace_src_group (rtx, rtx, rtx);
9013107Sbdeextern bool validate_simplify_insn (rtx insn);
9113107Sbdeextern int num_changes_pending (void);
9213107Sbde#ifdef HAVE_cc0
9313107Sbdeextern int next_insn_tests_no_inequality (rtx);
9413107Sbde#endif
9513107Sbdeextern int reg_fits_class_p (rtx, enum reg_class, int, enum machine_mode);
9613107Sbdeextern rtx *find_single_use (rtx, rtx, rtx *);
9718961Sbde
9818961Sbdeextern int offsettable_memref_p (rtx);
9918961Sbdeextern int offsettable_nonstrict_memref_p (rtx);
10018961Sbdeextern int offsettable_address_p (int, enum machine_mode, rtx);
101757Sdgextern int mode_dependent_address_p (rtx);
10213107Sbde
10318961Sbdeextern int recog (rtx, rtx, int *);
10418961Sbde#ifndef GENERATOR_FILE
10518961Sbdestatic inline int recog_memoized (rtx insn);
10618961Sbde#endif
10713107Sbdeextern void add_clobbers (rtx, int);
108122940Speterextern int added_clobbers_hard_reg_p (int);
10913107Sbdeextern void insn_extract (rtx);
11013107Sbdeextern void extract_insn (rtx);
111163722Sbdeextern void extract_constrain_insn_cached (rtx);
112163726Sbdeextern void extract_insn_cached (rtx);
11318961Sbdeextern void preprocess_constraints (void);
114163722Sbdeextern rtx peep2_next_insn (int);
115163722Sbdeextern int peep2_regno_dead_p (int, int);
116163722Sbdeextern int peep2_reg_dead_p (int, rtx);
11718961Sbde#ifdef CLEAR_HARD_REG_SET
11818961Sbdeextern rtx peep2_find_free_register (int, int, const char *,
119757Sdg				     enum machine_mode, HARD_REG_SET *);
120757Sdg#endif
121757Sdgextern rtx peephole2_insns (rtx, rtx, int *);
12213107Sbde
12313107Sbdeextern int store_data_bypass_p (rtx, rtx);
124757Sdgextern int if_test_bypass_p (rtx, rtx);
12513107Sbde
12618961Sbde#ifndef GENERATOR_FILE
12718961Sbde/* Try recognizing the instruction INSN,
12813107Sbde   and return the code number that results.
12913107Sbde   Remember the code so that repeated calls do not
1301321Sdg   need to spend the time for actual rerecognition.
13113107Sbde
13213107Sbde   This function is the normal interface to instruction recognition.
13313107Sbde   The automatically-generated function `recog' is normally called
134757Sdg   through this one.  */
135122849Speter
136122849Speterstatic inline int
137156699Speterrecog_memoized (rtx insn)
138122849Speter{
139122849Speter  if (INSN_CODE (insn) < 0)
140122849Speter    INSN_CODE (insn) = recog (PATTERN (insn), insn, 0);
141122849Speter  return INSN_CODE (insn);
142153241Sjhb}
143153241Sjhb#endif
144153241Sjhb
145153241Sjhb/* Nonzero means volatile operands are recognized.  */
146153241Sjhbextern int volatile_ok;
147153241Sjhb
148153241Sjhb/* Set by constrain_operands to the number of the alternative that
149153241Sjhb   matched.  */
150153241Sjhbextern int which_alternative;
151153241Sjhb
152153241Sjhb/* The following vectors hold the results from insn_extract.  */
153153241Sjhb
154153241Sjhbstruct recog_data
155153241Sjhb{
156153241Sjhb  /* It is very tempting to make the 5 operand related arrays into a
157153241Sjhb     structure and index on that.  However, to be source compatible
158153241Sjhb     with all of the existing md file insn constraints and output
159153241Sjhb     templates, we need `operand' as a flat array.  Without that
160153241Sjhb     member, making an array for the rest seems pointless.  */
161153241Sjhb
162153241Sjhb  /* Gives value of operand N.  */
163153241Sjhb  rtx operand[MAX_RECOG_OPERANDS];
164153241Sjhb
165153241Sjhb  /* Gives location where operand N was found.  */
166153241Sjhb  rtx *operand_loc[MAX_RECOG_OPERANDS];
167153241Sjhb
168153241Sjhb  /* Gives the constraint string for operand N.  */
169153241Sjhb  const char *constraints[MAX_RECOG_OPERANDS];
170153241Sjhb
171153241Sjhb  /* Gives the mode of operand N.  */
172153241Sjhb  enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
173153241Sjhb
174153241Sjhb  /* Gives the type (in, out, inout) for operand N.  */
175153241Sjhb  enum op_type operand_type[MAX_RECOG_OPERANDS];
176153241Sjhb
177153241Sjhb  /* Gives location where the Nth duplicate-appearance of an operand
178153241Sjhb     was found.  This is something that matched MATCH_DUP.  */
179153241Sjhb  rtx *dup_loc[MAX_DUP_OPERANDS];
180153241Sjhb
181153241Sjhb  /* Gives the operand number that was duplicated in the Nth
182153241Sjhb     duplicate-appearance of an operand.  */
183153241Sjhb  char dup_num[MAX_DUP_OPERANDS];
184153241Sjhb
185153241Sjhb  /* ??? Note that these are `char' instead of `unsigned char' to (try to)
186153241Sjhb     avoid certain lossage from K&R C, wherein `unsigned char' default
187153241Sjhb     promotes to `unsigned int' instead of `int' as in ISO C.  As of 1999,
188153241Sjhb     the most common places to bootstrap from K&R C are SunOS and HPUX,
189153241Sjhb     both of which have signed characters by default.  The only other
190153241Sjhb     supported natives that have both K&R C and unsigned characters are
191153241Sjhb     ROMP and Irix 3, and neither have been seen for a while, but do
192153241Sjhb     continue to consider unsignedness when performing arithmetic inside
193153241Sjhb     a comparison.  */
194153241Sjhb
195153241Sjhb  /* The number of operands of the insn.  */
196122849Speter  char n_operands;
197122849Speter
1982579Sbde  /* The number of MATCH_DUPs in the insn.  */
199  char n_dups;
200
201  /* The number of alternatives in the constraints for the insn.  */
202  char n_alternatives;
203
204  /* In case we are caching, hold insn data was generated for.  */
205  rtx insn;
206};
207
208extern struct recog_data recog_data;
209
210/* Contains a vector of operand_alternative structures for every operand.
211   Set up by preprocess_constraints.  */
212extern struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
213
214/* A table defined in insn-output.c that give information about
215   each insn-code value.  */
216
217typedef int (*insn_operand_predicate_fn) (rtx, enum machine_mode);
218typedef const char * (*insn_output_fn) (rtx *, rtx);
219typedef rtx (*insn_gen_fn) (rtx, ...);
220
221struct insn_operand_data
222{
223  const insn_operand_predicate_fn predicate;
224
225  const char *const constraint;
226
227  ENUM_BITFIELD(machine_mode) const mode : 16;
228
229  const char strict_low;
230
231  const char eliminable;
232};
233
234/* Legal values for insn_data.output_format.  Indicate what type of data
235   is stored in insn_data.output.  */
236#define INSN_OUTPUT_FORMAT_NONE		0	/* abort */
237#define INSN_OUTPUT_FORMAT_SINGLE	1	/* const char * */
238#define INSN_OUTPUT_FORMAT_MULTI	2	/* const char * const * */
239#define INSN_OUTPUT_FORMAT_FUNCTION	3	/* const char * (*)(...) */
240
241struct insn_data
242{
243  const char *const name;
244#if HAVE_DESIGNATED_INITIALIZERS
245  union {
246    const char *single;
247    const char *const *multi;
248    insn_output_fn function;
249  } output;
250#else
251  struct {
252    const char *single;
253    const char *const *multi;
254    insn_output_fn function;
255  } output;
256#endif
257  const insn_gen_fn genfun;
258  const struct insn_operand_data *const operand;
259
260  const char n_operands;
261  const char n_dups;
262  const char n_alternatives;
263  const char output_format;
264};
265
266extern const struct insn_data insn_data[];
267extern int peep2_current_count;
268