comparison gcc/read-rtl.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* RTL reader for GCC. 1 /* RTL reader for GCC.
2 Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
3 2003, 2004, 2005, 2007, 2008, 2010
4 Free Software Foundation, Inc.
5 3
6 This file is part of GCC. 4 This file is part of GCC.
7 5
8 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
17 15
18 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see 17 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */ 18 <http://www.gnu.org/licenses/>. */
21 19
20 /* This file is compiled twice: once for the generator programs
21 once for the compiler. */
22 #ifdef GENERATOR_FILE
22 #include "bconfig.h" 23 #include "bconfig.h"
24 #else
25 #include "config.h"
26 #endif
23 27
24 /* Disable rtl checking; it conflicts with the iterator handling. */ 28 /* Disable rtl checking; it conflicts with the iterator handling. */
25 #undef ENABLE_RTL_CHECKING 29 #undef ENABLE_RTL_CHECKING
26 30
27 #include "system.h" 31 #include "system.h"
28 #include "coretypes.h" 32 #include "coretypes.h"
29 #include "tm.h" 33 #include "tm.h"
30 #include "rtl.h" 34 #include "rtl.h"
31 #include "obstack.h" 35 #include "obstack.h"
32 #include "hashtab.h"
33 #include "read-md.h" 36 #include "read-md.h"
34 #include "gensupport.h" 37 #include "gensupport.h"
38
39 #ifndef GENERATOR_FILE
40 #include "function.h"
41 #include "memmodel.h"
42 #include "emit-rtl.h"
43 #endif
35 44
36 /* One element in a singly-linked list of (integer, string) pairs. */ 45 /* One element in a singly-linked list of (integer, string) pairs. */
37 struct map_value { 46 struct map_value {
38 struct map_value *next; 47 struct map_value *next;
39 int number; 48 int number;
40 const char *string; 49 const char *string;
41 }; 50 };
42 51
43 /* Maps an iterator or attribute name to a list of (integer, string) pairs. 52 /* Maps an iterator or attribute name to a list of (integer, string) pairs.
44 The integers are mode or code values; the strings are either C conditions 53 The integers are iterator values; the strings are either C conditions
45 or attribute values. */ 54 or attribute values. */
46 struct mapping { 55 struct mapping {
47 /* The name of the iterator or attribute. */ 56 /* The name of the iterator or attribute. */
48 const char *name; 57 const char *name;
49 58
50 /* The group (modes or codes) to which the iterator or attribute belongs. */ 59 /* The group (modes or codes) to which the iterator or attribute belongs. */
51 struct iterator_group *group; 60 struct iterator_group *group;
52 61
53 /* Gives a unique number to the attribute or iterator. Numbers are
54 allocated consecutively, starting at 0. */
55 int index;
56
57 /* The list of (integer, string) pairs. */ 62 /* The list of (integer, string) pairs. */
58 struct map_value *values; 63 struct map_value *values;
64
65 /* For iterators, records the current value of the iterator. */
66 struct map_value *current_value;
59 }; 67 };
60 68
61 /* A structure for abstracting the common parts of code and mode iterators. */ 69 /* A structure for abstracting the common parts of iterators. */
62 struct iterator_group { 70 struct iterator_group {
63 /* Tables of "mapping" structures, one for attributes and one for iterators. */ 71 /* Tables of "mapping" structures, one for attributes and one for
72 iterators. */
64 htab_t attrs, iterators; 73 htab_t attrs, iterators;
65 74
66 /* The number of "real" modes or codes (and by extension, the first 75 /* Treat the given string as the name of a standard mode, etc., and
67 number available for use as an iterator placeholder). */
68 int num_builtins;
69
70 /* Treat the given string as the name of a standard mode or code and
71 return its integer value. */ 76 return its integer value. */
72 int (*find_builtin) (const char *); 77 int (*find_builtin) (const char *);
73 78
74 /* Return true if the given rtx uses the given mode or code. */ 79 /* Make the given rtx use the iterator value given by the third argument.
75 bool (*uses_iterator_p) (rtx, int); 80 If the iterator applies to operands, the second argument gives the
76 81 operand index, otherwise it is ignored. */
77 /* Make the given rtx use the given mode or code. */ 82 void (*apply_iterator) (rtx, unsigned int, int);
78 void (*apply_iterator) (rtx, int);
79 }; 83 };
80 84
81 /* A structure used to pass data from read_rtx to apply_iterator_traverse 85 /* Records one use of an iterator. */
82 via htab_traverse. */ 86 struct iterator_use {
83 struct iterator_traverse_data { 87 /* The iterator itself. */
84 /* Instruction queue. */ 88 struct mapping *iterator;
85 rtx queue; 89
86 /* Attributes seen for modes. */ 90 /* The location of the use, as passed to the apply_iterator callback.
87 struct map_value *mode_maps; 91 The index is the number of the operand that used the iterator
88 /* The last unknown attribute used as a mode. */ 92 if applicable, otherwise it is ignored. */
89 const char *unknown_mode_attr; 93 rtx x;
94 unsigned int index;
90 }; 95 };
91 96
92 /* If CODE is the number of a code iterator, return a real rtx code that 97 /* Records one use of an attribute (the "<[iterator:]attribute>" syntax)
93 has the same format. Return CODE otherwise. */ 98 in a non-string rtx field. */
94 #define BELLWETHER_CODE(CODE) \ 99 struct attribute_use {
95 ((CODE) < NUM_RTX_CODE ? CODE : bellwether_codes[CODE - NUM_RTX_CODE]) 100 /* The group that describes the use site. */
96 101 struct iterator_group *group;
97 static int find_mode (const char *); 102
98 static bool uses_mode_iterator_p (rtx, int); 103 /* The name of the attribute, possibly with an "iterator:" prefix. */
99 static void apply_mode_iterator (rtx, int); 104 const char *value;
100 static int find_code (const char *); 105
101 static bool uses_code_iterator_p (rtx, int); 106 /* The location of the use, as passed to GROUP's apply_iterator callback.
102 static void apply_code_iterator (rtx, int); 107 The index is the number of the operand that used the iterator
103 static const char *apply_iterator_to_string (const char *, struct mapping *, int); 108 if applicable, otherwise it is ignored. */
104 static rtx apply_iterator_to_rtx (rtx, struct mapping *, int, 109 rtx x;
105 struct map_value *, const char **); 110 unsigned int index;
106 static bool uses_iterator_p (rtx, struct mapping *); 111 };
107 static const char *add_condition_to_string (const char *, const char *); 112
108 static void add_condition_to_rtx (rtx, const char *); 113 /* This struct is used to link subst_attr named ATTR_NAME with
109 static int apply_iterator_traverse (void **, void *); 114 corresponding define_subst named ITER_NAME. */
110 static struct mapping *add_mapping (struct iterator_group *, htab_t t, 115 struct subst_attr_to_iter_mapping
111 const char *); 116 {
112 static struct map_value **add_map_value (struct map_value **, 117 char *attr_name;
113 int, const char *); 118 char *iter_name;
114 static void initialize_iterators (void); 119 };
115 static void read_conditions (void); 120
121 /* Hash-table to store links between subst-attributes and
122 define_substs. */
123 htab_t subst_attr_to_iter_map = NULL;
124 /* This global stores name of subst-iterator which is currently being
125 processed. */
126 const char *current_iterator_name;
127
116 static void validate_const_int (const char *); 128 static void validate_const_int (const char *);
117 static int find_iterator (struct iterator_group *, const char *); 129 static void one_time_initialization (void);
118 static struct mapping *read_mapping (struct iterator_group *, htab_t); 130
119 static void check_code_iterator (struct mapping *); 131 /* Global singleton. */
120 static rtx read_rtx_code (const char *, struct map_value **); 132 rtx_reader *rtx_reader_ptr = NULL;
121 static rtx read_nested_rtx (struct map_value **);
122 static rtx read_rtx_variadic (struct map_value **, rtx);
123 133
124 /* The mode and code iterator structures. */ 134 /* The mode and code iterator structures. */
125 static struct iterator_group modes, codes; 135 static struct iterator_group modes, codes, ints, substs;
126 136
127 /* Index I is the value of BELLWETHER_CODE (I + NUM_RTX_CODE). */ 137 /* All iterators used in the current rtx. */
128 static enum rtx_code *bellwether_codes; 138 static vec<mapping *> current_iterators;
139
140 /* The list of all iterator uses in the current rtx. */
141 static vec<iterator_use> iterator_uses;
142
143 /* The list of all attribute uses in the current rtx. */
144 static vec<attribute_use> attribute_uses;
129 145
130 /* Implementations of the iterator_group callbacks for modes. */ 146 /* Implementations of the iterator_group callbacks for modes. */
131 147
132 static int 148 static int
133 find_mode (const char *name) 149 find_mode (const char *name)
139 return i; 155 return i;
140 156
141 fatal_with_file_and_line ("unknown mode `%s'", name); 157 fatal_with_file_and_line ("unknown mode `%s'", name);
142 } 158 }
143 159
144 static bool 160 static void
145 uses_mode_iterator_p (rtx x, int mode) 161 apply_mode_iterator (rtx x, unsigned int, int mode)
146 { 162 {
147 return (int) GET_MODE (x) == mode; 163 PUT_MODE (x, (machine_mode) mode);
148 } 164 }
149 165
150 static void 166 /* In compact dumps, the code of insns is prefixed with "c", giving "cinsn",
151 apply_mode_iterator (rtx x, int mode) 167 "cnote" etc, and CODE_LABEL is special-cased as "clabel". */
152 { 168
153 PUT_MODE (x, (enum machine_mode) mode); 169 struct compact_insn_name {
154 } 170 RTX_CODE code;
171 const char *name;
172 };
173
174 static const compact_insn_name compact_insn_names[] = {
175 { DEBUG_INSN, "cdebug_insn" },
176 { INSN, "cinsn" },
177 { JUMP_INSN, "cjump_insn" },
178 { CALL_INSN, "ccall_insn" },
179 { JUMP_TABLE_DATA, "cjump_table_data" },
180 { BARRIER, "cbarrier" },
181 { CODE_LABEL, "clabel" },
182 { NOTE, "cnote" }
183 };
155 184
156 /* Implementations of the iterator_group callbacks for codes. */ 185 /* Implementations of the iterator_group callbacks for codes. */
157 186
158 static int 187 static int
159 find_code (const char *name) 188 find_code (const char *name)
162 191
163 for (i = 0; i < NUM_RTX_CODE; i++) 192 for (i = 0; i < NUM_RTX_CODE; i++)
164 if (strcmp (GET_RTX_NAME (i), name) == 0) 193 if (strcmp (GET_RTX_NAME (i), name) == 0)
165 return i; 194 return i;
166 195
196 for (i = 0; i < (signed)ARRAY_SIZE (compact_insn_names); i++)
197 if (strcmp (compact_insn_names[i].name, name) == 0)
198 return compact_insn_names[i].code;
199
167 fatal_with_file_and_line ("unknown rtx code `%s'", name); 200 fatal_with_file_and_line ("unknown rtx code `%s'", name);
168 } 201 }
169 202
170 static bool 203 static void
171 uses_code_iterator_p (rtx x, int code) 204 apply_code_iterator (rtx x, unsigned int, int code)
172 {
173 return (int) GET_CODE (x) == code;
174 }
175
176 static void
177 apply_code_iterator (rtx x, int code)
178 { 205 {
179 PUT_CODE (x, (enum rtx_code) code); 206 PUT_CODE (x, (enum rtx_code) code);
180 } 207 }
181 208
182 /* Map a code or mode attribute string P to the underlying string for 209 /* Implementations of the iterator_group callbacks for ints. */
183 ITERATOR and VALUE. */ 210
211 /* Since GCC does not construct a table of valid constants,
212 we have to accept any int as valid. No cross-checking can
213 be done. */
214
215 static int
216 find_int (const char *name)
217 {
218 validate_const_int (name);
219 return atoi (name);
220 }
221
222 static void
223 apply_int_iterator (rtx x, unsigned int index, int value)
224 {
225 XINT (x, index) = value;
226 }
227
228 #ifdef GENERATOR_FILE
229
230 /* This routine adds attribute or does nothing depending on VALUE. When
231 VALUE is 1, it does nothing - the first duplicate of original
232 template is kept untouched when it's subjected to a define_subst.
233 When VALUE isn't 1, the routine modifies RTL-template RT, adding
234 attribute, named exactly as define_subst, which later will be
235 applied. If such attribute has already been added, then no the
236 routine has no effect. */
237 static void
238 apply_subst_iterator (rtx rt, unsigned int, int value)
239 {
240 rtx new_attr;
241 rtvec attrs_vec, new_attrs_vec;
242 int i;
243 if (value == 1)
244 return;
245 gcc_assert (GET_CODE (rt) == DEFINE_INSN
246 || GET_CODE (rt) == DEFINE_EXPAND);
247
248 attrs_vec = XVEC (rt, 4);
249
250 /* If we've already added attribute 'current_iterator_name', then we
251 have nothing to do now. */
252 if (attrs_vec)
253 {
254 for (i = 0; i < GET_NUM_ELEM (attrs_vec); i++)
255 {
256 if (strcmp (XSTR (attrs_vec->elem[i], 0), current_iterator_name) == 0)
257 return;
258 }
259 }
260
261 /* Add attribute with subst name - it serves as a mark for
262 define_subst which later would be applied to this pattern. */
263 new_attr = rtx_alloc (SET_ATTR);
264 PUT_CODE (new_attr, SET_ATTR);
265 XSTR (new_attr, 0) = xstrdup (current_iterator_name);
266 XSTR (new_attr, 1) = xstrdup ("yes");
267
268 if (!attrs_vec)
269 {
270 new_attrs_vec = rtvec_alloc (1);
271 new_attrs_vec->elem[0] = new_attr;
272 }
273 else
274 {
275 new_attrs_vec = rtvec_alloc (GET_NUM_ELEM (attrs_vec) + 1);
276 memcpy (&new_attrs_vec->elem[0], &attrs_vec->elem[0],
277 GET_NUM_ELEM (attrs_vec) * sizeof (rtx));
278 new_attrs_vec->elem[GET_NUM_ELEM (attrs_vec)] = new_attr;
279 }
280 XVEC (rt, 4) = new_attrs_vec;
281 }
282
283 /* Map subst-attribute ATTR to subst iterator ITER. */
284
285 static void
286 bind_subst_iter_and_attr (const char *iter, const char *attr)
287 {
288 struct subst_attr_to_iter_mapping *value;
289 void **slot;
290 if (!subst_attr_to_iter_map)
291 subst_attr_to_iter_map =
292 htab_create (1, leading_string_hash, leading_string_eq_p, 0);
293 value = XNEW (struct subst_attr_to_iter_mapping);
294 value->attr_name = xstrdup (attr);
295 value->iter_name = xstrdup (iter);
296 slot = htab_find_slot (subst_attr_to_iter_map, value, INSERT);
297 *slot = value;
298 }
299
300 #endif /* #ifdef GENERATOR_FILE */
301
302 /* Return name of a subst-iterator, corresponding to subst-attribute ATTR. */
303
304 static char*
305 find_subst_iter_by_attr (const char *attr)
306 {
307 char *iter_name = NULL;
308 struct subst_attr_to_iter_mapping *value;
309 value = (struct subst_attr_to_iter_mapping*)
310 htab_find (subst_attr_to_iter_map, &attr);
311 if (value)
312 iter_name = value->iter_name;
313 return iter_name;
314 }
315
316 /* Map attribute string P to its current value. Return null if the attribute
317 isn't known. */
184 318
185 static struct map_value * 319 static struct map_value *
186 map_attr_string (const char *p, struct mapping *iterator, int value) 320 map_attr_string (const char *p)
187 { 321 {
188 const char *attr; 322 const char *attr;
323 struct mapping *iterator;
324 unsigned int i;
189 struct mapping *m; 325 struct mapping *m;
190 struct map_value *v; 326 struct map_value *v;
191 327 int iterator_name_len;
192 /* If there's a "iterator:" prefix, check whether the iterator name matches. 328
193 Set ATTR to the start of the attribute name. */ 329 /* Peel off any "iterator:" prefix. Set ATTR to the start of the
330 attribute name. */
194 attr = strchr (p, ':'); 331 attr = strchr (p, ':');
195 if (attr == 0) 332 if (attr == 0)
196 attr = p; 333 {
334 iterator_name_len = -1;
335 attr = p;
336 }
197 else 337 else
198 { 338 {
199 if (strncmp (p, iterator->name, attr - p) != 0 339 iterator_name_len = attr - p;
200 || iterator->name[attr - p] != 0)
201 return 0;
202 attr++; 340 attr++;
203 } 341 }
204 342
205 /* Find the attribute specification. */ 343 FOR_EACH_VEC_ELT (current_iterators, i, iterator)
206 m = (struct mapping *) htab_find (iterator->group->attrs, &attr); 344 {
207 if (m == 0) 345 /* If an iterator name was specified, check that it matches. */
208 return 0; 346 if (iterator_name_len >= 0
209 347 && (strncmp (p, iterator->name, iterator_name_len) != 0
210 /* Find the attribute value for VALUE. */ 348 || iterator->name[iterator_name_len] != 0))
211 for (v = m->values; v != 0; v = v->next) 349 continue;
212 if (v->number == value) 350
213 break; 351 /* Find the attribute specification. */
214 352 m = (struct mapping *) htab_find (iterator->group->attrs, &attr);
215 return v; 353 if (m)
216 }
217
218 /* Given an attribute string used as a machine mode, return an index
219 to store in the machine mode to be translated by
220 apply_iterator_to_rtx. */
221
222 static unsigned int
223 mode_attr_index (struct map_value **mode_maps, const char *string)
224 {
225 char *p;
226 struct map_value *mv;
227
228 /* Copy the attribute string into permanent storage, without the
229 angle brackets around it. */
230 obstack_grow0 (&string_obstack, string + 1, strlen (string) - 2);
231 p = XOBFINISH (&string_obstack, char *);
232
233 mv = XNEW (struct map_value);
234 mv->number = *mode_maps == 0 ? 0 : (*mode_maps)->number + 1;
235 mv->string = p;
236 mv->next = *mode_maps;
237 *mode_maps = mv;
238
239 /* We return a code which we can map back into this string: the
240 number of machine modes + the number of mode iterators + the index
241 we just used. */
242 return MAX_MACHINE_MODE + htab_elements (modes.iterators) + mv->number;
243 }
244
245 /* Apply MODE_MAPS to the top level of X, expanding cases where an
246 attribute is used for a mode. ITERATOR is the current iterator we are
247 expanding, and VALUE is the value to which we are expanding it.
248 This sets *UNKNOWN to true if we find a mode attribute which has not
249 yet been defined, and does not change it otherwise. */
250
251 static void
252 apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *iterator,
253 int value, const char **unknown)
254 {
255 unsigned int offset;
256 int indx;
257 struct map_value *pm;
258
259 offset = MAX_MACHINE_MODE + htab_elements (modes.iterators);
260 if (GET_MODE (x) < offset)
261 return;
262
263 indx = GET_MODE (x) - offset;
264 for (pm = mode_maps; pm; pm = pm->next)
265 {
266 if (pm->number == indx)
267 { 354 {
268 struct map_value *v; 355 /* In contrast to code/mode/int iterators, attributes of subst
269 356 iterators are linked to one specific subst-iterator. So, if
270 v = map_attr_string (pm->string, iterator, value); 357 we are dealing with subst-iterator, we should check if it's
271 if (v) 358 the one which linked with the given attribute. */
272 PUT_MODE (x, (enum machine_mode) find_mode (v->string)); 359 if (iterator->group == &substs)
273 else 360 {
274 *unknown = pm->string; 361 char *iter_name = find_subst_iter_by_attr (attr);
275 return; 362 if (strcmp (iter_name, iterator->name) != 0)
363 continue;
364 }
365 /* Find the attribute value associated with the current
366 iterator value. */
367 for (v = m->values; v; v = v->next)
368 if (v->number == iterator->current_value->number)
369 return v;
276 } 370 }
277 } 371 }
278 } 372 return NULL;
279 373 }
280 /* Given that ITERATOR is being expanded as VALUE, apply the appropriate 374
281 string substitutions to STRING. Return the new string if any changes 375 /* Apply the current iterator values to STRING. Return the new string
282 were needed, otherwise return STRING itself. */ 376 if any changes were needed, otherwise return STRING itself. */
283 377
284 static const char * 378 const char *
285 apply_iterator_to_string (const char *string, struct mapping *iterator, int value) 379 md_reader::apply_iterator_to_string (const char *string)
286 { 380 {
287 char *base, *copy, *p, *start, *end; 381 char *base, *copy, *p, *start, *end;
288 struct map_value *v; 382 struct map_value *v;
289 383
290 if (string == 0) 384 if (string == 0)
294 while ((start = strchr (p, '<')) && (end = strchr (start, '>'))) 388 while ((start = strchr (p, '<')) && (end = strchr (start, '>')))
295 { 389 {
296 p = start + 1; 390 p = start + 1;
297 391
298 *end = 0; 392 *end = 0;
299 v = map_attr_string (p, iterator, value); 393 v = map_attr_string (p);
300 *end = '>'; 394 *end = '>';
301 if (v == 0) 395 if (v == 0)
302 continue; 396 continue;
303 397
304 /* Add everything between the last copied byte and the '<', 398 /* Add everything between the last copied byte and the '<',
305 then add in the attribute value. */ 399 then add in the attribute value. */
306 obstack_grow (&string_obstack, base, start - base); 400 obstack_grow (&m_string_obstack, base, start - base);
307 obstack_grow (&string_obstack, v->string, strlen (v->string)); 401 obstack_grow (&m_string_obstack, v->string, strlen (v->string));
308 base = end + 1; 402 base = end + 1;
309 } 403 }
310 if (base != copy) 404 if (base != copy)
311 { 405 {
312 obstack_grow (&string_obstack, base, strlen (base) + 1); 406 obstack_grow (&m_string_obstack, base, strlen (base) + 1);
313 copy = XOBFINISH (&string_obstack, char *); 407 copy = XOBFINISH (&m_string_obstack, char *);
314 copy_md_ptr_loc (copy, string); 408 copy_md_ptr_loc (copy, string);
315 return copy; 409 return copy;
316 } 410 }
317 return string; 411 return string;
318 } 412 }
319 413
320 /* Return a copy of ORIGINAL in which all uses of ITERATOR have been 414 /* Return a deep copy of X, substituting the current iterator
321 replaced by VALUE. MODE_MAPS holds information about attribute 415 values into any strings. */
322 strings used for modes. This sets *UNKNOWN_MODE_ATTR to the value of 416
323 an unknown mode attribute, and does not change it otherwise. */ 417 rtx
324 418 md_reader::copy_rtx_for_iterators (rtx original)
325 static rtx 419 {
326 apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value, 420 const char *format_ptr, *p;
327 struct map_value *mode_maps,
328 const char **unknown_mode_attr)
329 {
330 struct iterator_group *group;
331 const char *format_ptr;
332 int i, j; 421 int i, j;
333 rtx x; 422 rtx x;
334 enum rtx_code bellwether_code;
335 423
336 if (original == 0) 424 if (original == 0)
337 return original; 425 return original;
338 426
339 /* Create a shallow copy of ORIGINAL. */ 427 /* Create a shallow copy of ORIGINAL. */
340 bellwether_code = BELLWETHER_CODE (GET_CODE (original)); 428 x = rtx_alloc (GET_CODE (original));
341 x = rtx_alloc (bellwether_code); 429 memcpy (x, original, RTX_CODE_SIZE (GET_CODE (original)));
342 memcpy (x, original, RTX_CODE_SIZE (bellwether_code));
343
344 /* Change the mode or code itself. */
345 group = iterator->group;
346 if (group->uses_iterator_p (x, iterator->index + group->num_builtins))
347 group->apply_iterator (x, value);
348
349 if (mode_maps)
350 apply_mode_maps (x, mode_maps, iterator, value, unknown_mode_attr);
351 430
352 /* Change each string and recursively change each rtx. */ 431 /* Change each string and recursively change each rtx. */
353 format_ptr = GET_RTX_FORMAT (bellwether_code); 432 format_ptr = GET_RTX_FORMAT (GET_CODE (original));
354 for (i = 0; format_ptr[i] != 0; i++) 433 for (i = 0; format_ptr[i] != 0; i++)
355 switch (format_ptr[i]) 434 switch (format_ptr[i])
356 { 435 {
357 case 'T': 436 case 'T':
358 XTMPL (x, i) = apply_iterator_to_string (XTMPL (x, i), iterator, value); 437 while (XTMPL (x, i) != (p = apply_iterator_to_string (XTMPL (x, i))))
438 XTMPL (x, i) = p;
359 break; 439 break;
360 440
361 case 'S': 441 case 'S':
362 case 's': 442 case 's':
363 XSTR (x, i) = apply_iterator_to_string (XSTR (x, i), iterator, value); 443 while (XSTR (x, i) != (p = apply_iterator_to_string (XSTR (x, i))))
444 XSTR (x, i) = p;
364 break; 445 break;
365 446
366 case 'e': 447 case 'e':
367 XEXP (x, i) = apply_iterator_to_rtx (XEXP (x, i), iterator, value, 448 XEXP (x, i) = copy_rtx_for_iterators (XEXP (x, i));
368 mode_maps, unknown_mode_attr);
369 break; 449 break;
370 450
371 case 'V': 451 case 'V':
372 case 'E': 452 case 'E':
373 if (XVEC (original, i)) 453 if (XVEC (original, i))
374 { 454 {
375 XVEC (x, i) = rtvec_alloc (XVECLEN (original, i)); 455 XVEC (x, i) = rtvec_alloc (XVECLEN (original, i));
376 for (j = 0; j < XVECLEN (x, i); j++) 456 for (j = 0; j < XVECLEN (x, i); j++)
377 XVECEXP (x, i, j) = apply_iterator_to_rtx (XVECEXP (original, i, j), 457 XVECEXP (x, i, j)
378 iterator, value, mode_maps, 458 = copy_rtx_for_iterators (XVECEXP (original, i, j));
379 unknown_mode_attr);
380 } 459 }
381 break; 460 break;
382 461
383 default: 462 default:
384 break; 463 break;
385 } 464 }
386 return x; 465 return x;
387 } 466 }
388 467
389 /* Return true if X (or some subexpression of X) uses iterator ITERATOR. */ 468 #ifdef GENERATOR_FILE
390
391 static bool
392 uses_iterator_p (rtx x, struct mapping *iterator)
393 {
394 struct iterator_group *group;
395 const char *format_ptr;
396 int i, j;
397
398 if (x == 0)
399 return false;
400
401 group = iterator->group;
402 if (group->uses_iterator_p (x, iterator->index + group->num_builtins))
403 return true;
404
405 format_ptr = GET_RTX_FORMAT (BELLWETHER_CODE (GET_CODE (x)));
406 for (i = 0; format_ptr[i] != 0; i++)
407 switch (format_ptr[i])
408 {
409 case 'e':
410 if (uses_iterator_p (XEXP (x, i), iterator))
411 return true;
412 break;
413
414 case 'V':
415 case 'E':
416 if (XVEC (x, i))
417 for (j = 0; j < XVECLEN (x, i); j++)
418 if (uses_iterator_p (XVECEXP (x, i, j), iterator))
419 return true;
420 break;
421
422 default:
423 break;
424 }
425 return false;
426 }
427 469
428 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL 470 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
429 has the form "&& ..." (as used in define_insn_and_splits), assume that 471 has the form "&& ..." (as used in define_insn_and_splits), assume that
430 EXTRA is already satisfied. Empty strings are treated like "true". */ 472 EXTRA is already satisfied. Empty strings are treated like "true". */
431 473
432 static const char * 474 static const char *
433 add_condition_to_string (const char *original, const char *extra) 475 add_condition_to_string (const char *original, const char *extra)
434 { 476 {
435 if (original != 0 && original[0] == '&' && original[1] == '&') 477 if (original != 0 && original[0] == '&' && original[1] == '&')
436 return original; 478 return original;
437 return join_c_conditions (original, extra); 479 return rtx_reader_ptr->join_c_conditions (original, extra);
438 } 480 }
439 481
440 /* Like add_condition, but applied to all conditions in rtx X. */ 482 /* Like add_condition, but applied to all conditions in rtx X. */
441 483
442 static void 484 static void
444 { 486 {
445 switch (GET_CODE (x)) 487 switch (GET_CODE (x))
446 { 488 {
447 case DEFINE_INSN: 489 case DEFINE_INSN:
448 case DEFINE_EXPAND: 490 case DEFINE_EXPAND:
491 case DEFINE_SUBST:
449 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra); 492 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra);
450 break; 493 break;
451 494
452 case DEFINE_SPLIT: 495 case DEFINE_SPLIT:
453 case DEFINE_PEEPHOLE: 496 case DEFINE_PEEPHOLE:
464 default: 507 default:
465 break; 508 break;
466 } 509 }
467 } 510 }
468 511
469 /* A htab_traverse callback. Search the EXPR_LIST given by DATA 512 /* Apply the current iterator values to all attribute_uses. */
470 for rtxes that use the iterator in *SLOT. Replace each such rtx 513
471 with a list of expansions. */ 514 static void
515 apply_attribute_uses (void)
516 {
517 struct map_value *v;
518 attribute_use *ause;
519 unsigned int i;
520
521 FOR_EACH_VEC_ELT (attribute_uses, i, ause)
522 {
523 v = map_attr_string (ause->value);
524 if (!v)
525 fatal_with_file_and_line ("unknown iterator value `%s'", ause->value);
526 ause->group->apply_iterator (ause->x, ause->index,
527 ause->group->find_builtin (v->string));
528 }
529 }
530
531 /* A htab_traverse callback for iterators. Add all used iterators
532 to current_iterators. */
472 533
473 static int 534 static int
474 apply_iterator_traverse (void **slot, void *data) 535 add_current_iterators (void **slot, void *data ATTRIBUTE_UNUSED)
475 { 536 {
476 struct iterator_traverse_data *mtd = (struct iterator_traverse_data *) data; 537 struct mapping *iterator;
538
539 iterator = (struct mapping *) *slot;
540 if (iterator->current_value)
541 current_iterators.safe_push (iterator);
542 return 1;
543 }
544
545 /* Expand all iterators in the current rtx, which is given as ORIGINAL.
546 Build a list of expanded rtxes in the EXPR_LIST pointed to by QUEUE. */
547
548 static void
549 apply_iterators (rtx original, vec<rtx> *queue)
550 {
551 unsigned int i;
552 const char *condition;
553 iterator_use *iuse;
477 struct mapping *iterator; 554 struct mapping *iterator;
478 struct map_value *v; 555 struct map_value *v;
479 rtx elem, new_elem, original, x; 556 rtx x;
480 557
481 iterator = (struct mapping *) *slot; 558 if (iterator_uses.is_empty ())
482 for (elem = mtd->queue; elem != 0; elem = XEXP (elem, 1)) 559 {
483 if (uses_iterator_p (XEXP (elem, 0), iterator)) 560 /* Raise an error if any attributes were used. */
484 { 561 apply_attribute_uses ();
485 /* For each iterator we expand, we set UNKNOWN_MODE_ATTR to NULL. 562 queue->safe_push (original);
486 If apply_iterator_rtx finds an unknown attribute for a mode, 563 return;
487 it will set it to the attribute. We want to know whether 564 }
488 the attribute is unknown after we have expanded all 565
489 possible iterators, so setting it to NULL here gives us the 566 /* Clear out the iterators from the previous run. */
490 right result when the hash table traversal is complete. */ 567 FOR_EACH_VEC_ELT (current_iterators, i, iterator)
491 mtd->unknown_mode_attr = NULL; 568 iterator->current_value = NULL;
492 569 current_iterators.truncate (0);
493 original = XEXP (elem, 0); 570
494 for (v = iterator->values; v != 0; v = v->next) 571 /* Mark the iterators that we need this time. */
495 { 572 FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
496 x = apply_iterator_to_rtx (original, iterator, v->number, 573 iuse->iterator->current_value = iuse->iterator->values;
497 mtd->mode_maps, 574
498 &mtd->unknown_mode_attr); 575 /* Get the list of iterators that are in use, preserving the
499 add_condition_to_rtx (x, v->string); 576 definition order within each group. */
500 if (v != iterator->values) 577 htab_traverse (modes.iterators, add_current_iterators, NULL);
501 { 578 htab_traverse (codes.iterators, add_current_iterators, NULL);
502 /* Insert a new EXPR_LIST node after ELEM and put the 579 htab_traverse (ints.iterators, add_current_iterators, NULL);
503 new expansion there. */ 580 htab_traverse (substs.iterators, add_current_iterators, NULL);
504 new_elem = rtx_alloc (EXPR_LIST); 581 gcc_assert (!current_iterators.is_empty ());
505 XEXP (new_elem, 1) = XEXP (elem, 1); 582
506 XEXP (elem, 1) = new_elem; 583 for (;;)
507 elem = new_elem; 584 {
508 } 585 /* Apply the current iterator values. Accumulate a condition to
509 XEXP (elem, 0) = x; 586 say when the resulting rtx can be used. */
510 } 587 condition = "";
511 } 588 FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
512 return 1; 589 {
513 } 590 if (iuse->iterator->group == &substs)
591 continue;
592 v = iuse->iterator->current_value;
593 iuse->iterator->group->apply_iterator (iuse->x, iuse->index,
594 v->number);
595 condition = rtx_reader_ptr->join_c_conditions (condition, v->string);
596 }
597 apply_attribute_uses ();
598 x = rtx_reader_ptr->copy_rtx_for_iterators (original);
599 add_condition_to_rtx (x, condition);
600
601 /* We apply subst iterator after RTL-template is copied, as during
602 subst-iterator processing, we could add an attribute to the
603 RTL-template, and we don't want to do it in the original one. */
604 FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
605 {
606 v = iuse->iterator->current_value;
607 if (iuse->iterator->group == &substs)
608 {
609 iuse->x = x;
610 iuse->index = 0;
611 current_iterator_name = iuse->iterator->name;
612 iuse->iterator->group->apply_iterator (iuse->x, iuse->index,
613 v->number);
614 }
615 }
616 /* Add the new rtx to the end of the queue. */
617 queue->safe_push (x);
618
619 /* Lexicographically increment the iterator value sequence.
620 That is, cycle through iterator values, starting from the right,
621 and stopping when one of them doesn't wrap around. */
622 i = current_iterators.length ();
623 for (;;)
624 {
625 if (i == 0)
626 return;
627 i--;
628 iterator = current_iterators[i];
629 iterator->current_value = iterator->current_value->next;
630 if (iterator->current_value)
631 break;
632 iterator->current_value = iterator->values;
633 }
634 }
635 }
636 #endif /* #ifdef GENERATOR_FILE */
514 637
515 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name 638 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
516 of the mapping and GROUP is the group to which it belongs. */ 639 of the mapping and GROUP is the group to which it belongs. */
517 640
518 static struct mapping * 641 static struct mapping *
522 void **slot; 645 void **slot;
523 646
524 m = XNEW (struct mapping); 647 m = XNEW (struct mapping);
525 m->name = xstrdup (name); 648 m->name = xstrdup (name);
526 m->group = group; 649 m->group = group;
527 m->index = htab_elements (table);
528 m->values = 0; 650 m->values = 0;
651 m->current_value = NULL;
529 652
530 slot = htab_find_slot (table, m, INSERT); 653 slot = htab_find_slot (table, m, INSERT);
531 if (*slot != 0) 654 if (*slot != 0)
532 fatal_with_file_and_line ("`%s' already defined", name); 655 fatal_with_file_and_line ("`%s' already defined", name);
533 656
564 int i; 687 int i;
565 688
566 modes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); 689 modes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
567 modes.iterators = htab_create (13, leading_string_hash, 690 modes.iterators = htab_create (13, leading_string_hash,
568 leading_string_eq_p, 0); 691 leading_string_eq_p, 0);
569 modes.num_builtins = MAX_MACHINE_MODE;
570 modes.find_builtin = find_mode; 692 modes.find_builtin = find_mode;
571 modes.uses_iterator_p = uses_mode_iterator_p;
572 modes.apply_iterator = apply_mode_iterator; 693 modes.apply_iterator = apply_mode_iterator;
573 694
574 codes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); 695 codes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
575 codes.iterators = htab_create (13, leading_string_hash, 696 codes.iterators = htab_create (13, leading_string_hash,
576 leading_string_eq_p, 0); 697 leading_string_eq_p, 0);
577 codes.num_builtins = NUM_RTX_CODE;
578 codes.find_builtin = find_code; 698 codes.find_builtin = find_code;
579 codes.uses_iterator_p = uses_code_iterator_p;
580 codes.apply_iterator = apply_code_iterator; 699 codes.apply_iterator = apply_code_iterator;
700
701 ints.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
702 ints.iterators = htab_create (13, leading_string_hash,
703 leading_string_eq_p, 0);
704 ints.find_builtin = find_int;
705 ints.apply_iterator = apply_int_iterator;
706
707 substs.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
708 substs.iterators = htab_create (13, leading_string_hash,
709 leading_string_eq_p, 0);
710 substs.find_builtin = find_int; /* We don't use it, anyway. */
711 #ifdef GENERATOR_FILE
712 substs.apply_iterator = apply_subst_iterator;
713 #endif
581 714
582 lower = add_mapping (&modes, modes.attrs, "mode"); 715 lower = add_mapping (&modes, modes.attrs, "mode");
583 upper = add_mapping (&modes, modes.attrs, "MODE"); 716 upper = add_mapping (&modes, modes.attrs, "MODE");
584 lower_ptr = &lower->values; 717 lower_ptr = &lower->values;
585 upper_ptr = &upper->values; 718 upper_ptr = &upper->values;
608 } 741 }
609 } 742 }
610 743
611 /* Provide a version of a function to read a long long if the system does 744 /* Provide a version of a function to read a long long if the system does
612 not provide one. */ 745 not provide one. */
613 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ) 746 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !HAVE_DECL_ATOLL && !defined(HAVE_ATOQ)
614 HOST_WIDE_INT atoll (const char *); 747 HOST_WIDE_INT atoll (const char *);
615 748
616 HOST_WIDE_INT 749 HOST_WIDE_INT
617 atoll (const char *p) 750 atoll (const char *p)
618 { 751 {
631 { 764 {
632 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0'); 765 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0');
633 if (new_wide < tmp_wide) 766 if (new_wide < tmp_wide)
634 { 767 {
635 /* Return INT_MAX equiv on overflow. */ 768 /* Return INT_MAX equiv on overflow. */
636 tmp_wide = (~(unsigned HOST_WIDE_INT) 0) >> 1; 769 tmp_wide = HOST_WIDE_INT_M1U >> 1;
637 break; 770 break;
638 } 771 }
639 tmp_wide = new_wide; 772 tmp_wide = new_wide;
640 p++; 773 p++;
641 } 774 }
644 tmp_wide = -tmp_wide; 777 tmp_wide = -tmp_wide;
645 return tmp_wide; 778 return tmp_wide;
646 } 779 }
647 #endif 780 #endif
648 781
782
783 #ifdef GENERATOR_FILE
649 /* Process a define_conditions directive, starting with the optional 784 /* Process a define_conditions directive, starting with the optional
650 space after the "define_conditions". The directive looks like this: 785 space after the "define_conditions". The directive looks like this:
651 786
652 (define_conditions [ 787 (define_conditions [
653 (number "string") 788 (number "string")
657 792
658 It's not intended to appear in machine descriptions. It is 793 It's not intended to appear in machine descriptions. It is
659 generated by (the program generated by) genconditions.c, and 794 generated by (the program generated by) genconditions.c, and
660 slipped in at the beginning of the sequence of MD files read by 795 slipped in at the beginning of the sequence of MD files read by
661 most of the other generators. */ 796 most of the other generators. */
662 static void 797 void
663 read_conditions (void) 798 md_reader::read_conditions ()
664 { 799 {
665 int c; 800 int c;
666 801
667 c = read_skip_spaces (); 802 require_char_ws ('[');
668 if (c != '[')
669 fatal_expected_char ('[', c);
670 803
671 while ( (c = read_skip_spaces ()) != ']') 804 while ( (c = read_skip_spaces ()) != ']')
672 { 805 {
673 struct md_name name; 806 struct md_name name;
674 char *expr; 807 char *expr;
679 812
680 read_name (&name); 813 read_name (&name);
681 validate_const_int (name.string); 814 validate_const_int (name.string);
682 value = atoi (name.string); 815 value = atoi (name.string);
683 816
684 c = read_skip_spaces (); 817 require_char_ws ('"');
685 if (c != '"')
686 fatal_expected_char ('"', c);
687 expr = read_quoted_string (); 818 expr = read_quoted_string ();
688 819
689 c = read_skip_spaces (); 820 require_char_ws (')');
690 if (c != ')')
691 fatal_expected_char (')', c);
692 821
693 add_c_test (expr, value); 822 add_c_test (expr, value);
694 } 823 }
695 } 824 }
825 #endif /* #ifdef GENERATOR_FILE */
696 826
697 static void 827 static void
698 validate_const_int (const char *string) 828 validate_const_int (const char *string)
699 { 829 {
700 const char *cp; 830 const char *cp;
707 cp++; 837 cp++;
708 if (*cp == 0) 838 if (*cp == 0)
709 valid = 0; 839 valid = 0;
710 for (; *cp; cp++) 840 for (; *cp; cp++)
711 if (! ISDIGIT (*cp)) 841 if (! ISDIGIT (*cp))
842 {
843 valid = 0;
844 break;
845 }
846 if (!valid)
847 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string);
848 }
849
850 static void
851 validate_const_wide_int (const char *string)
852 {
853 const char *cp;
854 int valid = 1;
855
856 cp = string;
857 while (*cp && ISSPACE (*cp))
858 cp++;
859 /* Skip the leading 0x. */
860 if (cp[0] == '0' || cp[1] == 'x')
861 cp += 2;
862 else
863 valid = 0;
864 if (*cp == 0)
865 valid = 0;
866 for (; *cp; cp++)
867 if (! ISXDIGIT (*cp))
712 valid = 0; 868 valid = 0;
713 if (!valid) 869 if (!valid)
714 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string); 870 fatal_with_file_and_line ("invalid hex constant \"%s\"\n", string);
715 } 871 }
716 872
717 /* Search GROUP for a mode or code called NAME and return its numerical 873 /* Record that X uses iterator ITERATOR. If the use is in an operand
718 identifier. */ 874 of X, INDEX is the index of that operand, otherwise it is ignored. */
719 875
720 static int 876 static void
721 find_iterator (struct iterator_group *group, const char *name) 877 record_iterator_use (struct mapping *iterator, rtx x, unsigned int index)
878 {
879 struct iterator_use iuse = {iterator, x, index};
880 iterator_uses.safe_push (iuse);
881 }
882
883 /* Record that X uses attribute VALUE, which must match a built-in
884 value from group GROUP. If the use is in an operand of X, INDEX
885 is the index of that operand, otherwise it is ignored. */
886
887 static void
888 record_attribute_use (struct iterator_group *group, rtx x,
889 unsigned int index, const char *value)
890 {
891 struct attribute_use ause = {group, value, x, index};
892 attribute_uses.safe_push (ause);
893 }
894
895 /* Interpret NAME as either a built-in value, iterator or attribute
896 for group GROUP. X and INDEX are the values to pass to GROUP's
897 apply_iterator callback. */
898
899 void
900 md_reader::record_potential_iterator_use (struct iterator_group *group,
901 rtx x, unsigned int index,
902 const char *name)
722 { 903 {
723 struct mapping *m; 904 struct mapping *m;
724 905 size_t len;
725 m = (struct mapping *) htab_find (group->iterators, &name); 906
726 if (m != 0) 907 len = strlen (name);
727 return m->index + group->num_builtins; 908 if (name[0] == '<' && name[len - 1] == '>')
728 return group->find_builtin (name); 909 {
729 } 910 /* Copy the attribute string into permanent storage, without the
911 angle brackets around it. */
912 obstack_grow0 (&m_string_obstack, name + 1, len - 2);
913 record_attribute_use (group, x, index,
914 XOBFINISH (&m_string_obstack, char *));
915 }
916 else
917 {
918 m = (struct mapping *) htab_find (group->iterators, &name);
919 if (m != 0)
920 record_iterator_use (m, x, index);
921 else
922 group->apply_iterator (x, index, group->find_builtin (name));
923 }
924 }
925
926 #ifdef GENERATOR_FILE
730 927
731 /* Finish reading a declaration of the form: 928 /* Finish reading a declaration of the form:
732 929
733 (define... <name> [<value1> ... <valuen>]) 930 (define... <name> [<value1> ... <valuen>])
734 931
736 "(<name> <string>)" pair. The "(define..." part has already been read. 933 "(<name> <string>)" pair. The "(define..." part has already been read.
737 934
738 Represent the declaration as a "mapping" structure; add it to TABLE 935 Represent the declaration as a "mapping" structure; add it to TABLE
739 (which belongs to GROUP) and return it. */ 936 (which belongs to GROUP) and return it. */
740 937
741 static struct mapping * 938 struct mapping *
742 read_mapping (struct iterator_group *group, htab_t table) 939 md_reader::read_mapping (struct iterator_group *group, htab_t table)
743 { 940 {
744 struct md_name name; 941 struct md_name name;
745 struct mapping *m; 942 struct mapping *m;
746 struct map_value **end_ptr; 943 struct map_value **end_ptr;
747 const char *string; 944 const char *string;
749 946
750 /* Read the mapping name and create a structure for it. */ 947 /* Read the mapping name and create a structure for it. */
751 read_name (&name); 948 read_name (&name);
752 m = add_mapping (group, table, name.string); 949 m = add_mapping (group, table, name.string);
753 950
754 c = read_skip_spaces (); 951 require_char_ws ('[');
755 if (c != '[')
756 fatal_expected_char ('[', c);
757 952
758 /* Read each value. */ 953 /* Read each value. */
759 end_ptr = &m->values; 954 end_ptr = &m->values;
760 c = read_skip_spaces (); 955 c = read_skip_spaces ();
761 do 956 do
771 else 966 else
772 { 967 {
773 /* A "(name string)" pair. */ 968 /* A "(name string)" pair. */
774 read_name (&name); 969 read_name (&name);
775 string = read_string (false); 970 string = read_string (false);
776 c = read_skip_spaces (); 971 require_char_ws (')');
777 if (c != ')')
778 fatal_expected_char (')', c);
779 } 972 }
780 number = group->find_builtin (name.string); 973 number = group->find_builtin (name.string);
781 end_ptr = add_map_value (end_ptr, number, string); 974 end_ptr = add_map_value (end_ptr, number, string);
782 c = read_skip_spaces (); 975 c = read_skip_spaces ();
783 } 976 }
784 while (c != ']'); 977 while (c != ']');
785 978
786 return m; 979 return m;
787 } 980 }
788 981
982 /* For iterator with name ATTR_NAME generate define_attr with values
983 'yes' and 'no'. This attribute is used to mark templates to which
984 define_subst ATTR_NAME should be applied. This attribute is set and
985 defined implicitly and automatically. */
986 static void
987 add_define_attr_for_define_subst (const char *attr_name, vec<rtx> *queue)
988 {
989 rtx const_str, return_rtx;
990
991 return_rtx = rtx_alloc (DEFINE_ATTR);
992 PUT_CODE (return_rtx, DEFINE_ATTR);
993
994 const_str = rtx_alloc (CONST_STRING);
995 PUT_CODE (const_str, CONST_STRING);
996 XSTR (const_str, 0) = xstrdup ("no");
997
998 XSTR (return_rtx, 0) = xstrdup (attr_name);
999 XSTR (return_rtx, 1) = xstrdup ("no,yes");
1000 XEXP (return_rtx, 2) = const_str;
1001
1002 queue->safe_push (return_rtx);
1003 }
1004
1005 /* This routine generates DEFINE_SUBST_ATTR expression with operands
1006 ATTR_OPERANDS and places it to QUEUE. */
1007 static void
1008 add_define_subst_attr (const char **attr_operands, vec<rtx> *queue)
1009 {
1010 rtx return_rtx;
1011 int i;
1012
1013 return_rtx = rtx_alloc (DEFINE_SUBST_ATTR);
1014 PUT_CODE (return_rtx, DEFINE_SUBST_ATTR);
1015
1016 for (i = 0; i < 4; i++)
1017 XSTR (return_rtx, i) = xstrdup (attr_operands[i]);
1018
1019 queue->safe_push (return_rtx);
1020 }
1021
1022 /* Read define_subst_attribute construction. It has next form:
1023 (define_subst_attribute <attribute_name> <iterator_name> <value1> <value2>)
1024 Attribute is substituted with value1 when no subst is applied and with
1025 value2 in the opposite case.
1026 Attributes are added to SUBST_ATTRS_TABLE.
1027 In case the iterator is encountered for the first time, it's added to
1028 SUBST_ITERS_TABLE. Also, implicit define_attr is generated. */
1029
1030 static void
1031 read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table,
1032 vec<rtx> *queue)
1033 {
1034 struct mapping *m;
1035 struct map_value **end_ptr;
1036 const char *attr_operands[4];
1037 int i;
1038
1039 for (i = 0; i < 4; i++)
1040 attr_operands[i] = rtx_reader_ptr->read_string (false);
1041
1042 add_define_subst_attr (attr_operands, queue);
1043
1044 bind_subst_iter_and_attr (attr_operands[1], attr_operands[0]);
1045
1046 m = (struct mapping *) htab_find (substs.iterators, &attr_operands[1]);
1047 if (!m)
1048 {
1049 m = add_mapping (&substs, subst_iters_table, attr_operands[1]);
1050 end_ptr = &m->values;
1051 end_ptr = add_map_value (end_ptr, 1, "");
1052 end_ptr = add_map_value (end_ptr, 2, "");
1053
1054 add_define_attr_for_define_subst (attr_operands[1], queue);
1055 }
1056
1057 m = add_mapping (&substs, subst_attrs_table, attr_operands[0]);
1058 end_ptr = &m->values;
1059 end_ptr = add_map_value (end_ptr, 1, attr_operands[2]);
1060 end_ptr = add_map_value (end_ptr, 2, attr_operands[3]);
1061 }
1062
789 /* Check newly-created code iterator ITERATOR to see whether every code has the 1063 /* Check newly-created code iterator ITERATOR to see whether every code has the
790 same format. Initialize the iterator's entry in bellwether_codes. */ 1064 same format. */
791 1065
792 static void 1066 static void
793 check_code_iterator (struct mapping *iterator) 1067 check_code_iterator (struct mapping *iterator)
794 { 1068 {
795 struct map_value *v; 1069 struct map_value *v;
798 bellwether = (enum rtx_code) iterator->values->number; 1072 bellwether = (enum rtx_code) iterator->values->number;
799 for (v = iterator->values->next; v != 0; v = v->next) 1073 for (v = iterator->values->next; v != 0; v = v->next)
800 if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0) 1074 if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0)
801 fatal_with_file_and_line ("code iterator `%s' combines " 1075 fatal_with_file_and_line ("code iterator `%s' combines "
802 "different rtx formats", iterator->name); 1076 "different rtx formats", iterator->name);
803
804 bellwether_codes = XRESIZEVEC (enum rtx_code, bellwether_codes,
805 iterator->index + 1);
806 bellwether_codes[iterator->index] = bellwether;
807 } 1077 }
808 1078
809 /* Read an rtx-related declaration from the MD file, given that it 1079 /* Read an rtx-related declaration from the MD file, given that it
810 starts with directive name RTX_NAME. Return true if it expands to 1080 starts with directive name RTX_NAME. Return true if it expands to
811 one or more rtxes (as defined by rtx.def). When returning true, 1081 one or more rtxes (as defined by rtx.def). When returning true,
812 store the list of rtxes as an EXPR_LIST in *X. */ 1082 store the list of rtxes as an EXPR_LIST in *X. */
813 1083
814 bool 1084 bool
815 read_rtx (const char *rtx_name, rtx *x) 1085 rtx_reader::read_rtx (const char *rtx_name, vec<rtx> *rtxen)
816 { 1086 {
817 static rtx queue_head;
818 struct map_value *mode_maps;
819 struct iterator_traverse_data mtd;
820
821 /* Do one-time initialization. */
822 if (queue_head == 0)
823 {
824 initialize_iterators ();
825 queue_head = rtx_alloc (EXPR_LIST);
826 }
827
828 /* Handle various rtx-related declarations that aren't themselves 1087 /* Handle various rtx-related declarations that aren't themselves
829 encoded as rtxes. */ 1088 encoded as rtxes. */
830 if (strcmp (rtx_name, "define_conditions") == 0) 1089 if (strcmp (rtx_name, "define_conditions") == 0)
831 { 1090 {
832 read_conditions (); 1091 read_conditions ();
850 if (strcmp (rtx_name, "define_code_iterator") == 0) 1109 if (strcmp (rtx_name, "define_code_iterator") == 0)
851 { 1110 {
852 check_code_iterator (read_mapping (&codes, codes.iterators)); 1111 check_code_iterator (read_mapping (&codes, codes.iterators));
853 return false; 1112 return false;
854 } 1113 }
855 1114 if (strcmp (rtx_name, "define_int_attr") == 0)
856 mode_maps = 0; 1115 {
857 XEXP (queue_head, 0) = read_rtx_code (rtx_name, &mode_maps); 1116 read_mapping (&ints, ints.attrs);
858 XEXP (queue_head, 1) = 0; 1117 return false;
859 1118 }
860 mtd.queue = queue_head; 1119 if (strcmp (rtx_name, "define_int_iterator") == 0)
861 mtd.mode_maps = mode_maps; 1120 {
862 mtd.unknown_mode_attr = mode_maps ? mode_maps->string : NULL; 1121 read_mapping (&ints, ints.iterators);
863 htab_traverse (modes.iterators, apply_iterator_traverse, &mtd); 1122 return false;
864 htab_traverse (codes.iterators, apply_iterator_traverse, &mtd); 1123 }
865 if (mtd.unknown_mode_attr) 1124 if (strcmp (rtx_name, "define_subst_attr") == 0)
866 fatal_with_file_and_line ("undefined attribute '%s' used for mode", 1125 {
867 mtd.unknown_mode_attr); 1126 read_subst_mapping (substs.iterators, substs.attrs, rtxen);
868 1127
869 *x = queue_head; 1128 /* READ_SUBST_MAPPING could generate a new DEFINE_ATTR. Return
1129 TRUE to process it. */
1130 return true;
1131 }
1132
1133 apply_iterators (rtx_reader_ptr->read_rtx_code (rtx_name), rtxen);
1134 iterator_uses.truncate (0);
1135 attribute_uses.truncate (0);
1136
870 return true; 1137 return true;
1138 }
1139
1140 #endif /* #ifdef GENERATOR_FILE */
1141
1142 /* Do one-time initialization. */
1143
1144 static void
1145 one_time_initialization (void)
1146 {
1147 static bool initialized = false;
1148
1149 if (!initialized)
1150 {
1151 initialize_iterators ();
1152 initialized = true;
1153 }
1154 }
1155
1156 /* Consume characters until encountering a character in TERMINATOR_CHARS,
1157 consuming the terminator character if CONSUME_TERMINATOR is true.
1158 Return all characters before the terminator as an allocated buffer. */
1159
1160 char *
1161 rtx_reader::read_until (const char *terminator_chars, bool consume_terminator)
1162 {
1163 int ch = read_skip_spaces ();
1164 unread_char (ch);
1165 auto_vec<char> buf;
1166 while (1)
1167 {
1168 ch = read_char ();
1169 if (strchr (terminator_chars, ch))
1170 {
1171 if (!consume_terminator)
1172 unread_char (ch);
1173 break;
1174 }
1175 buf.safe_push (ch);
1176 }
1177 buf.safe_push ('\0');
1178 return xstrdup (buf.address ());
1179 }
1180
1181 /* Subroutine of read_rtx_code, for parsing zero or more flags. */
1182
1183 static void
1184 read_flags (rtx return_rtx)
1185 {
1186 while (1)
1187 {
1188 int ch = read_char ();
1189 if (ch != '/')
1190 {
1191 unread_char (ch);
1192 break;
1193 }
1194
1195 int flag_char = read_char ();
1196 switch (flag_char)
1197 {
1198 case 's':
1199 RTX_FLAG (return_rtx, in_struct) = 1;
1200 break;
1201 case 'v':
1202 RTX_FLAG (return_rtx, volatil) = 1;
1203 break;
1204 case 'u':
1205 RTX_FLAG (return_rtx, unchanging) = 1;
1206 break;
1207 case 'f':
1208 RTX_FLAG (return_rtx, frame_related) = 1;
1209 break;
1210 case 'j':
1211 RTX_FLAG (return_rtx, jump) = 1;
1212 break;
1213 case 'c':
1214 RTX_FLAG (return_rtx, call) = 1;
1215 break;
1216 case 'i':
1217 RTX_FLAG (return_rtx, return_val) = 1;
1218 break;
1219 default:
1220 fatal_with_file_and_line ("unrecognized flag: `%c'", flag_char);
1221 }
1222 }
1223 }
1224
1225 /* Return the numeric value n for GET_REG_NOTE_NAME (n) for STRING,
1226 or fail if STRING isn't recognized. */
1227
1228 static int
1229 parse_reg_note_name (const char *string)
1230 {
1231 for (int i = 0; i < REG_NOTE_MAX; i++)
1232 if (0 == strcmp (string, GET_REG_NOTE_NAME (i)))
1233 return i;
1234 fatal_with_file_and_line ("unrecognized REG_NOTE name: `%s'", string);
871 } 1235 }
872 1236
873 /* Subroutine of read_rtx and read_nested_rtx. CODE_NAME is the name of 1237 /* Subroutine of read_rtx and read_nested_rtx. CODE_NAME is the name of
874 either an rtx code or a code iterator. Parse the rest of the rtx and 1238 either an rtx code or a code iterator. Parse the rest of the rtx and
875 return it. MODE_MAPS is as for iterator_traverse_data. */ 1239 return it. */
876 1240
877 static rtx 1241 rtx
878 read_rtx_code (const char *code_name, struct map_value **mode_maps) 1242 rtx_reader::read_rtx_code (const char *code_name)
879 { 1243 {
880 int i; 1244 RTX_CODE code;
881 RTX_CODE real_code, bellwether_code; 1245 struct mapping *iterator = NULL;
882 const char *format_ptr; 1246 const char *format_ptr;
883 struct md_name name; 1247 struct md_name name;
884 rtx return_rtx; 1248 rtx return_rtx;
885 int c; 1249 int c;
886 int tmp_int; 1250 long reuse_id = -1;
887 HOST_WIDE_INT tmp_wide;
888 1251
889 /* Linked list structure for making RTXs: */ 1252 /* Linked list structure for making RTXs: */
890 struct rtx_list 1253 struct rtx_list
891 { 1254 {
892 struct rtx_list *next; 1255 struct rtx_list *next;
893 rtx value; /* Value of this node. */ 1256 rtx value; /* Value of this node. */
894 }; 1257 };
895 1258
896 real_code = (enum rtx_code) find_iterator (&codes, code_name); 1259 /* Handle reuse_rtx ids e.g. "(0|scratch:DI)". */
897 bellwether_code = BELLWETHER_CODE (real_code); 1260 if (ISDIGIT (code_name[0]))
1261 {
1262 reuse_id = atoi (code_name);
1263 while (char ch = *code_name++)
1264 if (ch == '|')
1265 break;
1266 }
1267
1268 /* Handle "reuse_rtx". */
1269 if (strcmp (code_name, "reuse_rtx") == 0)
1270 {
1271 read_name (&name);
1272 unsigned idx = atoi (name.string);
1273 /* Look it up by ID. */
1274 gcc_assert (idx < m_reuse_rtx_by_id.length ());
1275 return_rtx = m_reuse_rtx_by_id[idx];
1276 return return_rtx;
1277 }
1278
1279 /* If this code is an iterator, build the rtx using the iterator's
1280 first value. */
1281 #ifdef GENERATOR_FILE
1282 iterator = (struct mapping *) htab_find (codes.iterators, &code_name);
1283 if (iterator != 0)
1284 code = (enum rtx_code) iterator->values->number;
1285 else
1286 code = (enum rtx_code) codes.find_builtin (code_name);
1287 #else
1288 code = (enum rtx_code) codes.find_builtin (code_name);
1289 #endif
898 1290
899 /* If we end up with an insn expression then we free this space below. */ 1291 /* If we end up with an insn expression then we free this space below. */
900 return_rtx = rtx_alloc (bellwether_code); 1292 return_rtx = rtx_alloc (code);
901 format_ptr = GET_RTX_FORMAT (bellwether_code); 1293 format_ptr = GET_RTX_FORMAT (code);
902 PUT_CODE (return_rtx, real_code); 1294 memset (return_rtx, 0, RTX_CODE_SIZE (code));
1295 PUT_CODE (return_rtx, code);
1296
1297 if (reuse_id != -1)
1298 {
1299 /* Store away for later reuse. */
1300 m_reuse_rtx_by_id.safe_grow_cleared (reuse_id + 1);
1301 m_reuse_rtx_by_id[reuse_id] = return_rtx;
1302 }
1303
1304 if (iterator)
1305 record_iterator_use (iterator, return_rtx, 0);
1306
1307 /* Check for flags. */
1308 read_flags (return_rtx);
1309
1310 /* Read REG_NOTE names for EXPR_LIST and INSN_LIST. */
1311 if ((GET_CODE (return_rtx) == EXPR_LIST
1312 || GET_CODE (return_rtx) == INSN_LIST
1313 || GET_CODE (return_rtx) == INT_LIST)
1314 && !m_in_call_function_usage)
1315 {
1316 char ch = read_char ();
1317 if (ch == ':')
1318 {
1319 read_name (&name);
1320 PUT_MODE_RAW (return_rtx,
1321 (machine_mode)parse_reg_note_name (name.string));
1322 }
1323 else
1324 unread_char (ch);
1325 }
903 1326
904 /* If what follows is `: mode ', read it and 1327 /* If what follows is `: mode ', read it and
905 store the mode in the rtx. */ 1328 store the mode in the rtx. */
906 1329
907 i = read_skip_spaces (); 1330 c = read_skip_spaces ();
908 if (i == ':') 1331 if (c == ':')
909 { 1332 {
910 unsigned int mode;
911
912 read_name (&name); 1333 read_name (&name);
913 if (name.string[0] != '<' || name.string[strlen (name.string) - 1] != '>') 1334 record_potential_iterator_use (&modes, return_rtx, 0, name.string);
914 mode = find_iterator (&modes, name.string);
915 else
916 mode = mode_attr_index (mode_maps, name.string);
917 PUT_MODE (return_rtx, (enum machine_mode) mode);
918 if (GET_MODE (return_rtx) != mode)
919 fatal_with_file_and_line ("mode too large");
920 } 1335 }
921 else 1336 else
922 unread_char (i); 1337 unread_char (c);
923 1338
924 for (i = 0; format_ptr[i] != 0; i++) 1339 if (INSN_CHAIN_CODE_P (code))
925 switch (format_ptr[i]) 1340 {
1341 read_name (&name);
1342 INSN_UID (return_rtx) = atoi (name.string);
1343 }
1344
1345 /* Use the format_ptr to parse the various operands of this rtx. */
1346 for (int idx = 0; format_ptr[idx] != 0; idx++)
1347 return_rtx = read_rtx_operand (return_rtx, idx);
1348
1349 /* Handle any additional information that after the regular fields
1350 (e.g. when parsing function dumps). */
1351 handle_any_trailing_information (return_rtx);
1352
1353 if (CONST_WIDE_INT_P (return_rtx))
1354 {
1355 read_name (&name);
1356 validate_const_wide_int (name.string);
926 { 1357 {
927 /* 0 means a field for internal use only. 1358 const char *s = name.string;
928 Don't expect it to be present in the input. */ 1359 int len;
929 case '0': 1360 int index = 0;
930 break; 1361 int gs = HOST_BITS_PER_WIDE_INT/4;
931 1362 int pos;
932 case 'e': 1363 char * buf = XALLOCAVEC (char, gs + 1);
933 case 'u': 1364 unsigned HOST_WIDE_INT wi;
934 XEXP (return_rtx, i) = read_nested_rtx (mode_maps); 1365 int wlen;
935 break; 1366
936 1367 /* Skip the leading spaces. */
937 case 'V': 1368 while (*s && ISSPACE (*s))
938 /* 'V' is an optional vector: if a closeparen follows, 1369 s++;
939 just store NULL for this element. */ 1370
1371 /* Skip the leading 0x. */
1372 gcc_assert (s[0] == '0');
1373 gcc_assert (s[1] == 'x');
1374 s += 2;
1375
1376 len = strlen (s);
1377 pos = len - gs;
1378 wlen = (len + gs - 1) / gs; /* Number of words needed */
1379
1380 return_rtx = const_wide_int_alloc (wlen);
1381
1382 while (pos > 0)
1383 {
1384 #if HOST_BITS_PER_WIDE_INT == 64
1385 sscanf (s + pos, "%16" HOST_WIDE_INT_PRINT "x", &wi);
1386 #else
1387 sscanf (s + pos, "%8" HOST_WIDE_INT_PRINT "x", &wi);
1388 #endif
1389 CWI_ELT (return_rtx, index++) = wi;
1390 pos -= gs;
1391 }
1392 strncpy (buf, s, gs - pos);
1393 buf [gs - pos] = 0;
1394 sscanf (buf, "%" HOST_WIDE_INT_PRINT "x", &wi);
1395 CWI_ELT (return_rtx, index++) = wi;
1396 /* TODO: After reading, do we want to canonicalize with:
1397 value = lookup_const_wide_int (value); ? */
1398 }
1399 }
1400
1401 c = read_skip_spaces ();
1402 /* Syntactic sugar for AND and IOR, allowing Lisp-like
1403 arbitrary number of arguments for them. */
1404 if (c == '('
1405 && (GET_CODE (return_rtx) == AND
1406 || GET_CODE (return_rtx) == IOR))
1407 return read_rtx_variadic (return_rtx);
1408
1409 unread_char (c);
1410 return return_rtx;
1411 }
1412
1413 /* Subroutine of read_rtx_code. Parse operand IDX within RETURN_RTX,
1414 based on the corresponding format character within GET_RTX_FORMAT
1415 for the GET_CODE (RETURN_RTX), and return RETURN_RTX.
1416 This is a virtual function, so that function_reader can override
1417 some parsing, and potentially return a different rtx. */
1418
1419 rtx
1420 rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
1421 {
1422 RTX_CODE code = GET_CODE (return_rtx);
1423 const char *format_ptr = GET_RTX_FORMAT (code);
1424 int c;
1425 struct md_name name;
1426
1427 switch (format_ptr[idx])
1428 {
1429 /* 0 means a field for internal use only.
1430 Don't expect it to be present in the input. */
1431 case '0':
1432 if (code == REG)
1433 ORIGINAL_REGNO (return_rtx) = REGNO (return_rtx);
1434 break;
1435
1436 case 'e':
1437 XEXP (return_rtx, idx) = read_nested_rtx ();
1438 break;
1439
1440 case 'u':
1441 XEXP (return_rtx, idx) = read_nested_rtx ();
1442 break;
1443
1444 case 'V':
1445 /* 'V' is an optional vector: if a closeparen follows,
1446 just store NULL for this element. */
1447 c = read_skip_spaces ();
1448 unread_char (c);
1449 if (c == ')')
1450 {
1451 XVEC (return_rtx, idx) = 0;
1452 break;
1453 }
1454 /* Now process the vector. */
1455 /* FALLTHRU */
1456
1457 case 'E':
1458 {
1459 /* Obstack to store scratch vector in. */
1460 struct obstack vector_stack;
1461 int list_counter = 0;
1462 rtvec return_vec = NULL_RTVEC;
1463
1464 require_char_ws ('[');
1465
1466 /* Add expressions to a list, while keeping a count. */
1467 obstack_init (&vector_stack);
1468 while ((c = read_skip_spaces ()) && c != ']')
1469 {
1470 if (c == EOF)
1471 fatal_expected_char (']', c);
1472 unread_char (c);
1473 list_counter++;
1474 obstack_ptr_grow (&vector_stack, read_nested_rtx ());
1475 }
1476 if (list_counter > 0)
1477 {
1478 return_vec = rtvec_alloc (list_counter);
1479 memcpy (&return_vec->elem[0], obstack_finish (&vector_stack),
1480 list_counter * sizeof (rtx));
1481 }
1482 else if (format_ptr[idx] == 'E')
1483 fatal_with_file_and_line ("vector must have at least one element");
1484 XVEC (return_rtx, idx) = return_vec;
1485 obstack_free (&vector_stack, NULL);
1486 /* close bracket gotten */
1487 }
1488 break;
1489
1490 case 'S':
1491 case 'T':
1492 case 's':
1493 {
1494 char *stringbuf;
1495 int star_if_braced;
1496
940 c = read_skip_spaces (); 1497 c = read_skip_spaces ();
941 unread_char (c); 1498 unread_char (c);
942 if (c == ')') 1499 if (c == ')')
943 { 1500 {
944 XVEC (return_rtx, i) = 0; 1501 /* 'S' fields are optional and should be NULL if no string
1502 was given. Also allow normal 's' and 'T' strings to be
1503 omitted, treating them in the same way as empty strings. */
1504 XSTR (return_rtx, idx) = (format_ptr[idx] == 'S' ? NULL : "");
945 break; 1505 break;
946 } 1506 }
947 /* Now process the vector. */ 1507
948 1508 /* The output template slot of a DEFINE_INSN,
949 case 'E': 1509 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
950 { 1510 gets a star inserted as its first character, if it is
951 /* Obstack to store scratch vector in. */ 1511 written with a brace block instead of a string constant. */
952 struct obstack vector_stack; 1512 star_if_braced = (format_ptr[idx] == 'T');
953 int list_counter = 0; 1513
954 rtvec return_vec = NULL_RTVEC; 1514 stringbuf = read_string (star_if_braced);
955 1515 if (!stringbuf)
956 c = read_skip_spaces (); 1516 break;
957 if (c != '[') 1517
958 fatal_expected_char ('[', c); 1518 #ifdef GENERATOR_FILE
959 1519 /* For insn patterns, we want to provide a default name
960 /* Add expressions to a list, while keeping a count. */ 1520 based on the file and line, like "*foo.md:12", if the
961 obstack_init (&vector_stack); 1521 given name is blank. These are only for define_insn and
962 while ((c = read_skip_spaces ()) && c != ']') 1522 define_insn_and_split, to aid debugging. */
963 { 1523 if (*stringbuf == '\0'
964 if (c == EOF) 1524 && idx == 0
965 fatal_expected_char (']', c); 1525 && (GET_CODE (return_rtx) == DEFINE_INSN
966 unread_char (c); 1526 || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT))
967 list_counter++; 1527 {
968 obstack_ptr_grow (&vector_stack, read_nested_rtx (mode_maps)); 1528 struct obstack *string_obstack = get_string_obstack ();
969 } 1529 char line_name[20];
970 if (list_counter > 0) 1530 const char *read_md_filename = get_filename ();
971 { 1531 const char *fn = (read_md_filename ? read_md_filename : "rtx");
972 return_vec = rtvec_alloc (list_counter); 1532 const char *slash;
973 memcpy (&return_vec->elem[0], obstack_finish (&vector_stack), 1533 for (slash = fn; *slash; slash ++)
974 list_counter * sizeof (rtx)); 1534 if (*slash == '/' || *slash == '\\' || *slash == ':')
975 } 1535 fn = slash + 1;
976 else if (format_ptr[i] == 'E') 1536 obstack_1grow (string_obstack, '*');
977 fatal_with_file_and_line ("vector must have at least one element"); 1537 obstack_grow (string_obstack, fn, strlen (fn));
978 XVEC (return_rtx, i) = return_vec; 1538 sprintf (line_name, ":%d", get_lineno ());
979 obstack_free (&vector_stack, NULL); 1539 obstack_grow (string_obstack, line_name, strlen (line_name)+1);
980 /* close bracket gotten */ 1540 stringbuf = XOBFINISH (string_obstack, char *);
981 } 1541 }
982 break; 1542
983 1543 /* Find attr-names in the string. */
984 case 'S': 1544 char *str;
985 case 'T': 1545 char *start, *end, *ptr;
986 case 's': 1546 char tmpstr[256];
987 { 1547 ptr = &tmpstr[0];
988 char *stringbuf; 1548 end = stringbuf;
989 int star_if_braced; 1549 while ((start = strchr (end, '<')) && (end = strchr (start, '>')))
990 1550 {
991 c = read_skip_spaces (); 1551 if ((end - start - 1 > 0)
992 unread_char (c); 1552 && (end - start - 1 < (int)sizeof (tmpstr)))
993 if (c == ')') 1553 {
994 { 1554 strncpy (tmpstr, start+1, end-start-1);
995 /* 'S' fields are optional and should be NULL if no string 1555 tmpstr[end-start-1] = 0;
996 was given. Also allow normal 's' and 'T' strings to be 1556 end++;
997 omitted, treating them in the same way as empty strings. */ 1557 }
998 XSTR (return_rtx, i) = (format_ptr[i] == 'S' ? NULL : ""); 1558 else
999 break; 1559 break;
1000 } 1560 struct mapping *m
1001 1561 = (struct mapping *) htab_find (substs.attrs, &ptr);
1002 /* The output template slot of a DEFINE_INSN, 1562 if (m != 0)
1003 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically 1563 {
1004 gets a star inserted as its first character, if it is 1564 /* Here we should find linked subst-iter. */
1005 written with a brace block instead of a string constant. */ 1565 str = find_subst_iter_by_attr (ptr);
1006 star_if_braced = (format_ptr[i] == 'T'); 1566 if (str)
1007 1567 m = (struct mapping *) htab_find (substs.iterators, &str);
1008 stringbuf = read_string (star_if_braced); 1568 else
1009 1569 m = 0;
1010 /* For insn patterns, we want to provide a default name 1570 }
1011 based on the file and line, like "*foo.md:12", if the 1571 if (m != 0)
1012 given name is blank. These are only for define_insn and 1572 record_iterator_use (m, return_rtx, 0);
1013 define_insn_and_split, to aid debugging. */ 1573 }
1014 if (*stringbuf == '\0' 1574 #endif /* #ifdef GENERATOR_FILE */
1015 && i == 0 1575
1016 && (GET_CODE (return_rtx) == DEFINE_INSN 1576 const char *string_ptr = finalize_string (stringbuf);
1017 || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT)) 1577
1018 { 1578 if (star_if_braced)
1019 char line_name[20]; 1579 XTMPL (return_rtx, idx) = string_ptr;
1020 const char *fn = (read_md_filename ? read_md_filename : "rtx"); 1580 else
1021 const char *slash; 1581 XSTR (return_rtx, idx) = string_ptr;
1022 for (slash = fn; *slash; slash ++) 1582 }
1023 if (*slash == '/' || *slash == '\\' || *slash == ':') 1583 break;
1024 fn = slash + 1; 1584
1025 obstack_1grow (&string_obstack, '*'); 1585 case 'w':
1026 obstack_grow (&string_obstack, fn, strlen (fn)); 1586 {
1027 sprintf (line_name, ":%d", read_md_lineno); 1587 HOST_WIDE_INT tmp_wide;
1028 obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
1029 stringbuf = XOBFINISH (&string_obstack, char *);
1030 }
1031
1032 if (star_if_braced)
1033 XTMPL (return_rtx, i) = stringbuf;
1034 else
1035 XSTR (return_rtx, i) = stringbuf;
1036 }
1037 break;
1038
1039 case 'w':
1040 read_name (&name); 1588 read_name (&name);
1041 validate_const_int (name.string); 1589 validate_const_int (name.string);
1042 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT 1590 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1043 tmp_wide = atoi (name.string); 1591 tmp_wide = atoi (name.string);
1044 #else 1592 #else
1045 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG 1593 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1046 tmp_wide = atol (name.string); 1594 tmp_wide = atol (name.string);
1047 #else 1595 #else
1048 /* Prefer atoll over atoq, since the former is in the ISO C99 standard. 1596 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
1049 But prefer not to use our hand-rolled function above either. */ 1597 But prefer not to use our hand-rolled function above either. */
1050 #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ) 1598 #if HAVE_DECL_ATOLL || !defined(HAVE_ATOQ)
1051 tmp_wide = atoll (name.string); 1599 tmp_wide = atoll (name.string);
1052 #else 1600 #else
1053 tmp_wide = atoq (name.string); 1601 tmp_wide = atoq (name.string);
1054 #endif 1602 #endif
1055 #endif 1603 #endif
1056 #endif 1604 #endif
1057 XWINT (return_rtx, i) = tmp_wide; 1605 XWINT (return_rtx, idx) = tmp_wide;
1058 break;
1059
1060 case 'i':
1061 case 'n':
1062 read_name (&name);
1063 validate_const_int (name.string);
1064 tmp_int = atoi (name.string);
1065 XINT (return_rtx, i) = tmp_int;
1066 break;
1067
1068 default:
1069 gcc_unreachable ();
1070 } 1606 }
1071 1607 break;
1072 c = read_skip_spaces (); 1608
1073 /* Syntactic sugar for AND and IOR, allowing Lisp-like 1609 case 'i':
1074 arbitrary number of arguments for them. */ 1610 case 'n':
1075 if (c == '(' 1611 /* Can be an iterator or an integer constant. */
1076 && (GET_CODE (return_rtx) == AND 1612 read_name (&name);
1077 || GET_CODE (return_rtx) == IOR)) 1613 record_potential_iterator_use (&ints, return_rtx, idx, name.string);
1078 return read_rtx_variadic (mode_maps, return_rtx); 1614 break;
1079 1615
1080 unread_char (c); 1616 case 'r':
1617 read_name (&name);
1618 validate_const_int (name.string);
1619 set_regno_raw (return_rtx, atoi (name.string), 1);
1620 REG_ATTRS (return_rtx) = NULL;
1621 break;
1622
1623 default:
1624 gcc_unreachable ();
1625 }
1626
1081 return return_rtx; 1627 return return_rtx;
1082 } 1628 }
1083 1629
1084 /* Read a nested rtx construct from the MD file and return it. 1630 /* Read a nested rtx construct from the MD file and return it. */
1085 MODE_MAPS is as for iterator_traverse_data. */ 1631
1086 1632 rtx
1087 static rtx 1633 rtx_reader::read_nested_rtx ()
1088 read_nested_rtx (struct map_value **mode_maps)
1089 { 1634 {
1090 struct md_name name; 1635 struct md_name name;
1091 int c;
1092 rtx return_rtx; 1636 rtx return_rtx;
1093 1637
1094 c = read_skip_spaces (); 1638 /* In compact dumps, trailing "(nil)" values can be omitted.
1095 if (c != '(') 1639 Handle such dumps. */
1096 fatal_expected_char ('(', c); 1640 if (peek_char () == ')')
1641 return NULL_RTX;
1642
1643 require_char_ws ('(');
1097 1644
1098 read_name (&name); 1645 read_name (&name);
1099 if (strcmp (name.string, "nil") == 0) 1646 if (strcmp (name.string, "nil") == 0)
1100 return_rtx = NULL; 1647 return_rtx = NULL;
1101 else 1648 else
1102 return_rtx = read_rtx_code (name.string, mode_maps); 1649 return_rtx = read_rtx_code (name.string);
1103 1650
1104 c = read_skip_spaces (); 1651 require_char_ws (')');
1105 if (c != ')') 1652
1106 fatal_expected_char (')', c); 1653 return_rtx = postprocess (return_rtx);
1107 1654
1108 return return_rtx; 1655 return return_rtx;
1109 } 1656 }
1110 1657
1111 /* Mutually recursive subroutine of read_rtx which reads 1658 /* Mutually recursive subroutine of read_rtx which reads
1112 (thing x1 x2 x3 ...) and produces RTL as if 1659 (thing x1 x2 x3 ...) and produces RTL as if
1113 (thing x1 (thing x2 (thing x3 ...))) had been written. 1660 (thing x1 (thing x2 (thing x3 ...))) had been written.
1114 When called, FORM is (thing x1 x2), and the file position 1661 When called, FORM is (thing x1 x2), and the file position
1115 is just past the leading parenthesis of x3. Only works 1662 is just past the leading parenthesis of x3. Only works
1116 for THINGs which are dyadic expressions, e.g. AND, IOR. */ 1663 for THINGs which are dyadic expressions, e.g. AND, IOR. */
1117 static rtx 1664 rtx
1118 read_rtx_variadic (struct map_value **mode_maps, rtx form) 1665 rtx_reader::read_rtx_variadic (rtx form)
1119 { 1666 {
1120 char c = '('; 1667 char c = '(';
1121 rtx p = form, q; 1668 rtx p = form, q;
1122 1669
1123 do 1670 do
1126 1673
1127 q = rtx_alloc (GET_CODE (p)); 1674 q = rtx_alloc (GET_CODE (p));
1128 PUT_MODE (q, GET_MODE (p)); 1675 PUT_MODE (q, GET_MODE (p));
1129 1676
1130 XEXP (q, 0) = XEXP (p, 1); 1677 XEXP (q, 0) = XEXP (p, 1);
1131 XEXP (q, 1) = read_nested_rtx (mode_maps); 1678 XEXP (q, 1) = read_nested_rtx ();
1132 1679
1133 XEXP (p, 1) = q; 1680 XEXP (p, 1) = q;
1134 p = q; 1681 p = q;
1135 c = read_skip_spaces (); 1682 c = read_skip_spaces ();
1136 } 1683 }
1137 while (c == '('); 1684 while (c == '(');
1138 unread_char (c); 1685 unread_char (c);
1139 return form; 1686 return form;
1140 } 1687 }
1688
1689 /* Constructor for class rtx_reader. */
1690
1691 rtx_reader::rtx_reader (bool compact)
1692 : md_reader (compact),
1693 m_in_call_function_usage (false)
1694 {
1695 /* Set the global singleton pointer. */
1696 rtx_reader_ptr = this;
1697
1698 one_time_initialization ();
1699 }
1700
1701 /* Destructor for class rtx_reader. */
1702
1703 rtx_reader::~rtx_reader ()
1704 {
1705 /* Clear the global singleton pointer. */
1706 rtx_reader_ptr = NULL;
1707 }