gcc/ChangeLog
[official-gcc.git] / gcc / recog.h
blob71e801edb2ded297bfe27962c59b6918e8049378
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);
259 typedef rtx (*insn_gen_fn) (rtx, ...);
261 struct insn_operand_data
263 const insn_operand_predicate_fn predicate;
265 const char *const constraint;
267 ENUM_BITFIELD(machine_mode) const mode : 16;
269 const char strict_low;
271 const char is_operator;
273 const char eliminable;
275 const char allows_mem;
278 /* Legal values for insn_data.output_format. Indicate what type of data
279 is stored in insn_data.output. */
280 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
281 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
282 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
283 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
285 struct insn_data_d
287 const char *const name;
288 #if HAVE_DESIGNATED_UNION_INITIALIZERS
289 union {
290 const char *single;
291 const char *const *multi;
292 insn_output_fn function;
293 } output;
294 #else
295 struct {
296 const char *single;
297 const char *const *multi;
298 insn_output_fn function;
299 } output;
300 #endif
301 const insn_gen_fn genfun;
302 const struct insn_operand_data *const operand;
304 const char n_generator_args;
305 const char n_operands;
306 const char n_dups;
307 const char n_alternatives;
308 const char output_format;
311 extern const struct insn_data_d insn_data[];
312 extern int peep2_current_count;
314 #endif /* GCC_RECOG_H */