PR libstdc++/54562
[official-gcc.git] / gcc / recog.h
blob550a21745787684120042917006c594ad2ecb0b9
1 /* Declarations for interface to insn recognizer and insn-output.c.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_RECOG_H
21 #define GCC_RECOG_H
23 /* Random number that should be large enough for all purposes. */
24 #define MAX_RECOG_ALTERNATIVES 30
26 /* Types of operands. */
27 enum op_type {
28 OP_IN,
29 OP_OUT,
30 OP_INOUT
33 struct operand_alternative
35 /* Pointer to the beginning of the constraint string for this alternative,
36 for easier access by alternative number. */
37 const char *constraint;
39 /* The register class valid for this alternative (possibly NO_REGS). */
40 enum reg_class cl;
42 /* "Badness" of this alternative, computed from number of '?' and '!'
43 characters in the constraint string. */
44 unsigned int reject;
46 /* -1 if no matching constraint was found, or an operand number. */
47 int matches;
48 /* The same information, but reversed: -1 if this operand is not
49 matched by any other, or the operand number of the operand that
50 matches this one. */
51 int matched;
53 /* Nonzero if '&' was found in the constraint string. */
54 unsigned int earlyclobber:1;
55 /* Nonzero if TARGET_MEM_CONSTRAINT was found in the constraint
56 string. */
57 unsigned int memory_ok:1;
58 /* Nonzero if 'o' was found in the constraint string. */
59 unsigned int offmem_ok:1;
60 /* Nonzero if 'V' was found in the constraint string. */
61 unsigned int nonoffmem_ok:1;
62 /* Nonzero if '<' was found in the constraint string. */
63 unsigned int decmem_ok:1;
64 /* Nonzero if '>' was found in the constraint string. */
65 unsigned int incmem_ok:1;
66 /* Nonzero if 'p' was found in the constraint string. */
67 unsigned int is_address:1;
68 /* Nonzero if 'X' was found in the constraint string, or if the constraint
69 string for this alternative was empty. */
70 unsigned int anything_ok:1;
74 extern void init_recog (void);
75 extern void init_recog_no_volatile (void);
76 extern int check_asm_operands (rtx);
77 extern int asm_operand_ok (rtx, const char *, const char **);
78 extern bool validate_change (rtx, rtx *, rtx, bool);
79 extern bool validate_unshare_change (rtx, rtx *, rtx, bool);
80 extern bool canonicalize_change_group (rtx insn, rtx x);
81 extern int insn_invalid_p (rtx, bool);
82 extern int verify_changes (int);
83 extern void confirm_change_group (void);
84 extern int apply_change_group (void);
85 extern int num_validated_changes (void);
86 extern void cancel_changes (int);
87 extern int constrain_operands (int);
88 extern int constrain_operands_cached (int);
89 extern int memory_address_addr_space_p (enum machine_mode, rtx, addr_space_t);
90 #define memory_address_p(mode,addr) \
91 memory_address_addr_space_p ((mode), (addr), ADDR_SPACE_GENERIC)
92 extern int strict_memory_address_addr_space_p (enum machine_mode, rtx,
93 addr_space_t);
94 #define strict_memory_address_p(mode,addr) \
95 strict_memory_address_addr_space_p ((mode), (addr), ADDR_SPACE_GENERIC)
96 extern int validate_replace_rtx_subexp (rtx, rtx, rtx, rtx *);
97 extern int validate_replace_rtx (rtx, rtx, rtx);
98 extern int validate_replace_rtx_part (rtx, rtx, rtx *, rtx);
99 extern int validate_replace_rtx_part_nosimplify (rtx, rtx, rtx *, rtx);
100 extern void validate_replace_rtx_group (rtx, rtx, rtx);
101 extern void validate_replace_src_group (rtx, rtx, rtx);
102 extern bool validate_simplify_insn (rtx insn);
103 extern int num_changes_pending (void);
104 #ifdef HAVE_cc0
105 extern int next_insn_tests_no_inequality (rtx);
106 #endif
107 extern bool reg_fits_class_p (const_rtx, reg_class_t, int, enum machine_mode);
109 extern int offsettable_memref_p (rtx);
110 extern int offsettable_nonstrict_memref_p (rtx);
111 extern int offsettable_address_addr_space_p (int, enum machine_mode, rtx,
112 addr_space_t);
113 #define offsettable_address_p(strict,mode,addr) \
114 offsettable_address_addr_space_p ((strict), (mode), (addr), \
115 ADDR_SPACE_GENERIC)
116 extern bool mode_dependent_address_p (rtx, addr_space_t);
118 extern int recog (rtx, rtx, int *);
119 #ifndef GENERATOR_FILE
120 static inline int recog_memoized (rtx insn);
121 #endif
122 extern void add_clobbers (rtx, int);
123 extern int added_clobbers_hard_reg_p (int);
124 extern void insn_extract (rtx);
125 extern void extract_insn (rtx);
126 extern void extract_constrain_insn_cached (rtx);
127 extern void extract_insn_cached (rtx);
128 extern void preprocess_constraints (void);
129 extern rtx peep2_next_insn (int);
130 extern int peep2_regno_dead_p (int, int);
131 extern int peep2_reg_dead_p (int, rtx);
132 #ifdef CLEAR_HARD_REG_SET
133 extern rtx peep2_find_free_register (int, int, const char *,
134 enum machine_mode, HARD_REG_SET *);
135 #endif
136 extern rtx peephole2_insns (rtx, rtx, int *);
138 extern int store_data_bypass_p (rtx, rtx);
139 extern int if_test_bypass_p (rtx, rtx);
141 #ifndef GENERATOR_FILE
142 /* Try recognizing the instruction INSN,
143 and return the code number that results.
144 Remember the code so that repeated calls do not
145 need to spend the time for actual rerecognition.
147 This function is the normal interface to instruction recognition.
148 The automatically-generated function `recog' is normally called
149 through this one. */
151 static inline int
152 recog_memoized (rtx insn)
154 if (INSN_CODE (insn) < 0)
155 INSN_CODE (insn) = recog (PATTERN (insn), insn, 0);
156 return INSN_CODE (insn);
158 #endif
160 /* Skip chars until the next ',' or the end of the string. This is
161 useful to skip alternatives in a constraint string. */
162 static inline const char *
163 skip_alternative (const char *p)
165 const char *r = p;
166 while (*r != '\0' && *r != ',')
167 r++;
168 if (*r == ',')
169 r++;
170 return r;
173 /* Nonzero means volatile operands are recognized. */
174 extern int volatile_ok;
176 /* Set by constrain_operands to the number of the alternative that
177 matched. */
178 extern int which_alternative;
180 /* The following vectors hold the results from insn_extract. */
182 struct recog_data_d
184 /* It is very tempting to make the 5 operand related arrays into a
185 structure and index on that. However, to be source compatible
186 with all of the existing md file insn constraints and output
187 templates, we need `operand' as a flat array. Without that
188 member, making an array for the rest seems pointless. */
190 /* Gives value of operand N. */
191 rtx operand[MAX_RECOG_OPERANDS];
193 /* Gives location where operand N was found. */
194 rtx *operand_loc[MAX_RECOG_OPERANDS];
196 /* Gives the constraint string for operand N. */
197 const char *constraints[MAX_RECOG_OPERANDS];
199 /* Nonzero if operand N is a match_operator or a match_parallel. */
200 char is_operator[MAX_RECOG_OPERANDS];
202 /* Gives the mode of operand N. */
203 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
205 /* Gives the type (in, out, inout) for operand N. */
206 enum op_type operand_type[MAX_RECOG_OPERANDS];
208 /* Gives location where the Nth duplicate-appearance of an operand
209 was found. This is something that matched MATCH_DUP. */
210 rtx *dup_loc[MAX_DUP_OPERANDS];
212 /* Gives the operand number that was duplicated in the Nth
213 duplicate-appearance of an operand. */
214 char dup_num[MAX_DUP_OPERANDS];
216 /* ??? Note that these are `char' instead of `unsigned char' to (try to)
217 avoid certain lossage from K&R C, wherein `unsigned char' default
218 promotes to `unsigned int' instead of `int' as in ISO C. As of 1999,
219 the most common places to bootstrap from K&R C are SunOS and HPUX,
220 both of which have signed characters by default. The only other
221 supported natives that have both K&R C and unsigned characters are
222 ROMP and Irix 3, and neither have been seen for a while, but do
223 continue to consider unsignedness when performing arithmetic inside
224 a comparison. */
226 /* The number of operands of the insn. */
227 char n_operands;
229 /* The number of MATCH_DUPs in the insn. */
230 char n_dups;
232 /* The number of alternatives in the constraints for the insn. */
233 char n_alternatives;
235 /* True if insn is ASM_OPERANDS. */
236 bool is_asm;
238 /* Specifies whether an insn alternative is enabled using the
239 `enabled' attribute in the insn pattern definition. For back
240 ends not using the `enabled' attribute the array fields are
241 always set to `true' in expand_insn. */
242 bool alternative_enabled_p [MAX_RECOG_ALTERNATIVES];
244 /* In case we are caching, hold insn data was generated for. */
245 rtx insn;
248 extern struct recog_data_d recog_data;
250 /* Contains a vector of operand_alternative structures for every operand.
251 Set up by preprocess_constraints. */
252 extern struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
254 /* A table defined in insn-output.c that give information about
255 each insn-code value. */
257 typedef int (*insn_operand_predicate_fn) (rtx, enum machine_mode);
258 typedef const char * (*insn_output_fn) (rtx *, rtx);
260 struct insn_gen_fn
262 typedef rtx (*f0) (void);
263 typedef rtx (*f1) (rtx);
264 typedef rtx (*f2) (rtx, rtx);
265 typedef rtx (*f3) (rtx, rtx, rtx);
266 typedef rtx (*f4) (rtx, rtx, rtx, rtx);
267 typedef rtx (*f5) (rtx, rtx, rtx, rtx, rtx);
268 typedef rtx (*f6) (rtx, rtx, rtx, rtx, rtx, rtx);
269 typedef rtx (*f7) (rtx, rtx, rtx, rtx, rtx, rtx, rtx);
270 typedef rtx (*f8) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
271 typedef rtx (*f9) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
272 typedef rtx (*f10) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
273 typedef rtx (*f11) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
274 typedef rtx (*f12) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
275 typedef rtx (*f13) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
276 typedef rtx (*f14) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
277 typedef rtx (*f15) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
278 typedef rtx (*f16) (rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx, rtx);
280 typedef f0 stored_funcptr;
282 rtx operator () (void) const { return ((f0)func) (); }
283 rtx operator () (rtx a0) const { return ((f1)func) (a0); }
284 rtx operator () (rtx a0, rtx a1) const { return ((f2)func) (a0, a1); }
285 rtx operator () (rtx a0, rtx a1, rtx a2) const { return ((f3)func) (a0, a1, a2); }
286 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3) const { return ((f4)func) (a0, a1, a2, a3); }
287 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4) const { return ((f5)func) (a0, a1, a2, a3, a4); }
288 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5) const { return ((f6)func) (a0, a1, a2, a3, a4, a5); }
289 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6) const { return ((f7)func) (a0, a1, a2, a3, a4, a5, a6); }
290 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7) const { return ((f8)func) (a0, a1, a2, a3, a4, a5, a6, a7); }
291 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8) const { return ((f9)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8); }
292 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9) const { return ((f10)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }
293 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10) const { return ((f11)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); }
294 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11) const { return ((f12)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); }
295 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12) const { return ((f13)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); }
296 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12, rtx a13) const { return ((f14)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); }
297 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12, rtx a13, rtx a14) const { return ((f15)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); }
298 rtx operator () (rtx a0, rtx a1, rtx a2, rtx a3, rtx a4, rtx a5, rtx a6, rtx a7, rtx a8, rtx a9, rtx a10, rtx a11, rtx a12, rtx a13, rtx a14, rtx a15) const { return ((f16)func) (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); }
300 // This is for compatibility of code that invokes functions like
301 // (*funcptr) (arg)
302 insn_gen_fn operator * (void) const { return *this; }
304 // The wrapped function pointer must be public and there must not be any
305 // constructors. Otherwise the insn_data_d struct initializers generated
306 // by genoutput.c will result in static initializer functions, which defeats
307 // the purpose of the generated insn_data_d array.
308 stored_funcptr func;
311 struct insn_operand_data
313 const insn_operand_predicate_fn predicate;
315 const char *const constraint;
317 ENUM_BITFIELD(machine_mode) const mode : 16;
319 const char strict_low;
321 const char is_operator;
323 const char eliminable;
325 const char allows_mem;
328 /* Legal values for insn_data.output_format. Indicate what type of data
329 is stored in insn_data.output. */
330 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
331 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
332 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
333 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
335 struct insn_data_d
337 const char *const name;
338 #if HAVE_DESIGNATED_UNION_INITIALIZERS
339 union {
340 const char *single;
341 const char *const *multi;
342 insn_output_fn function;
343 } output;
344 #else
345 struct {
346 const char *single;
347 const char *const *multi;
348 insn_output_fn function;
349 } output;
350 #endif
351 const insn_gen_fn genfun;
352 const struct insn_operand_data *const operand;
354 const char n_generator_args;
355 const char n_operands;
356 const char n_dups;
357 const char n_alternatives;
358 const char output_format;
361 extern const struct insn_data_d insn_data[];
362 extern int peep2_current_count;
364 #endif /* GCC_RECOG_H */