2017-05-11 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / read-rtl.c
blob2a8650b3afa266db3ea1f4c051a75b22db761fc1
1 /* RTL reader for GCC.
2 Copyright (C) 1987-2017 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 /* This file is compiled twice: once for the generator programs
21 once for the compiler. */
22 #ifdef GENERATOR_FILE
23 #include "bconfig.h"
24 #else
25 #include "config.h"
26 #endif
28 /* Disable rtl checking; it conflicts with the iterator handling. */
29 #undef ENABLE_RTL_CHECKING
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "obstack.h"
36 #include "read-md.h"
37 #include "gensupport.h"
39 #ifndef GENERATOR_FILE
40 #include "function.h"
41 #include "memmodel.h"
42 #include "emit-rtl.h"
43 #endif
45 /* One element in a singly-linked list of (integer, string) pairs. */
46 struct map_value {
47 struct map_value *next;
48 int number;
49 const char *string;
52 /* Maps an iterator or attribute name to a list of (integer, string) pairs.
53 The integers are iterator values; the strings are either C conditions
54 or attribute values. */
55 struct mapping {
56 /* The name of the iterator or attribute. */
57 const char *name;
59 /* The group (modes or codes) to which the iterator or attribute belongs. */
60 struct iterator_group *group;
62 /* The list of (integer, string) pairs. */
63 struct map_value *values;
65 /* For iterators, records the current value of the iterator. */
66 struct map_value *current_value;
69 /* A structure for abstracting the common parts of iterators. */
70 struct iterator_group {
71 /* Tables of "mapping" structures, one for attributes and one for
72 iterators. */
73 htab_t attrs, iterators;
75 /* Treat the given string as the name of a standard mode, etc., and
76 return its integer value. */
77 int (*find_builtin) (const char *);
79 /* Make the given pointer use the given iterator value. */
80 void (*apply_iterator) (void *, int);
83 /* Records one use of an iterator. */
84 struct iterator_use {
85 /* The iterator itself. */
86 struct mapping *iterator;
88 /* The location of the use, as passed to the apply_iterator callback. */
89 void *ptr;
92 /* Records one use of an attribute (the "<[iterator:]attribute>" syntax)
93 in a non-string rtx field. */
94 struct attribute_use {
95 /* The group that describes the use site. */
96 struct iterator_group *group;
98 /* The name of the attribute, possibly with an "iterator:" prefix. */
99 const char *value;
101 /* The location of the use, as passed to GROUP's apply_iterator callback. */
102 void *ptr;
105 /* This struct is used to link subst_attr named ATTR_NAME with
106 corresponding define_subst named ITER_NAME. */
107 struct subst_attr_to_iter_mapping
109 char *attr_name;
110 char *iter_name;
113 /* Hash-table to store links between subst-attributes and
114 define_substs. */
115 htab_t subst_attr_to_iter_map = NULL;
116 /* This global stores name of subst-iterator which is currently being
117 processed. */
118 const char *current_iterator_name;
120 static void validate_const_int (const char *);
121 static void one_time_initialization (void);
123 /* Global singleton. */
124 rtx_reader *rtx_reader_ptr = NULL;
126 /* The mode and code iterator structures. */
127 static struct iterator_group modes, codes, ints, substs;
129 /* All iterators used in the current rtx. */
130 static vec<mapping *> current_iterators;
132 /* The list of all iterator uses in the current rtx. */
133 static vec<iterator_use> iterator_uses;
135 /* The list of all attribute uses in the current rtx. */
136 static vec<attribute_use> attribute_uses;
138 /* Implementations of the iterator_group callbacks for modes. */
140 static int
141 find_mode (const char *name)
143 int i;
145 for (i = 0; i < NUM_MACHINE_MODES; i++)
146 if (strcmp (GET_MODE_NAME (i), name) == 0)
147 return i;
149 fatal_with_file_and_line ("unknown mode `%s'", name);
152 static void
153 apply_mode_iterator (void *loc, int mode)
155 PUT_MODE ((rtx) loc, (machine_mode) mode);
158 /* In compact dumps, the code of insns is prefixed with "c", giving "cinsn",
159 "cnote" etc, and CODE_LABEL is special-cased as "clabel". */
161 struct compact_insn_name {
162 RTX_CODE code;
163 const char *name;
166 static const compact_insn_name compact_insn_names[] = {
167 { DEBUG_INSN, "cdebug_insn" },
168 { INSN, "cinsn" },
169 { JUMP_INSN, "cjump_insn" },
170 { CALL_INSN, "ccall_insn" },
171 { JUMP_TABLE_DATA, "cjump_table_data" },
172 { BARRIER, "cbarrier" },
173 { CODE_LABEL, "clabel" },
174 { NOTE, "cnote" }
177 /* Implementations of the iterator_group callbacks for codes. */
179 static int
180 find_code (const char *name)
182 int i;
184 for (i = 0; i < NUM_RTX_CODE; i++)
185 if (strcmp (GET_RTX_NAME (i), name) == 0)
186 return i;
188 for (i = 0; i < (signed)ARRAY_SIZE (compact_insn_names); i++)
189 if (strcmp (compact_insn_names[i].name, name) == 0)
190 return compact_insn_names[i].code;
192 fatal_with_file_and_line ("unknown rtx code `%s'", name);
195 static void
196 apply_code_iterator (void *loc, int code)
198 PUT_CODE ((rtx) loc, (enum rtx_code) code);
201 /* Implementations of the iterator_group callbacks for ints. */
203 /* Since GCC does not construct a table of valid constants,
204 we have to accept any int as valid. No cross-checking can
205 be done. */
207 static int
208 find_int (const char *name)
210 validate_const_int (name);
211 return atoi (name);
214 static void
215 apply_int_iterator (void *loc, int value)
217 *(int *)loc = value;
220 #ifdef GENERATOR_FILE
222 /* This routine adds attribute or does nothing depending on VALUE. When
223 VALUE is 1, it does nothing - the first duplicate of original
224 template is kept untouched when it's subjected to a define_subst.
225 When VALUE isn't 1, the routine modifies RTL-template LOC, adding
226 attribute, named exactly as define_subst, which later will be
227 applied. If such attribute has already been added, then no the
228 routine has no effect. */
229 static void
230 apply_subst_iterator (void *loc, int value)
232 rtx rt = (rtx)loc;
233 rtx new_attr;
234 rtvec attrs_vec, new_attrs_vec;
235 int i;
236 if (value == 1)
237 return;
238 gcc_assert (GET_CODE (rt) == DEFINE_INSN
239 || GET_CODE (rt) == DEFINE_EXPAND);
241 attrs_vec = XVEC (rt, 4);
243 /* If we've already added attribute 'current_iterator_name', then we
244 have nothing to do now. */
245 if (attrs_vec)
247 for (i = 0; i < GET_NUM_ELEM (attrs_vec); i++)
249 if (strcmp (XSTR (attrs_vec->elem[i], 0), current_iterator_name) == 0)
250 return;
254 /* Add attribute with subst name - it serves as a mark for
255 define_subst which later would be applied to this pattern. */
256 new_attr = rtx_alloc (SET_ATTR);
257 PUT_CODE (new_attr, SET_ATTR);
258 XSTR (new_attr, 0) = xstrdup (current_iterator_name);
259 XSTR (new_attr, 1) = xstrdup ("yes");
261 if (!attrs_vec)
263 new_attrs_vec = rtvec_alloc (1);
264 new_attrs_vec->elem[0] = new_attr;
266 else
268 new_attrs_vec = rtvec_alloc (GET_NUM_ELEM (attrs_vec) + 1);
269 memcpy (&new_attrs_vec->elem[0], &attrs_vec->elem[0],
270 GET_NUM_ELEM (attrs_vec) * sizeof (rtx));
271 new_attrs_vec->elem[GET_NUM_ELEM (attrs_vec)] = new_attr;
273 XVEC (rt, 4) = new_attrs_vec;
276 /* Map subst-attribute ATTR to subst iterator ITER. */
278 static void
279 bind_subst_iter_and_attr (const char *iter, const char *attr)
281 struct subst_attr_to_iter_mapping *value;
282 void **slot;
283 if (!subst_attr_to_iter_map)
284 subst_attr_to_iter_map =
285 htab_create (1, leading_string_hash, leading_string_eq_p, 0);
286 value = XNEW (struct subst_attr_to_iter_mapping);
287 value->attr_name = xstrdup (attr);
288 value->iter_name = xstrdup (iter);
289 slot = htab_find_slot (subst_attr_to_iter_map, value, INSERT);
290 *slot = value;
293 #endif /* #ifdef GENERATOR_FILE */
295 /* Return name of a subst-iterator, corresponding to subst-attribute ATTR. */
297 static char*
298 find_subst_iter_by_attr (const char *attr)
300 char *iter_name = NULL;
301 struct subst_attr_to_iter_mapping *value;
302 value = (struct subst_attr_to_iter_mapping*)
303 htab_find (subst_attr_to_iter_map, &attr);
304 if (value)
305 iter_name = value->iter_name;
306 return iter_name;
309 /* Map attribute string P to its current value. Return null if the attribute
310 isn't known. */
312 static struct map_value *
313 map_attr_string (const char *p)
315 const char *attr;
316 struct mapping *iterator;
317 unsigned int i;
318 struct mapping *m;
319 struct map_value *v;
320 int iterator_name_len;
322 /* Peel off any "iterator:" prefix. Set ATTR to the start of the
323 attribute name. */
324 attr = strchr (p, ':');
325 if (attr == 0)
327 iterator_name_len = -1;
328 attr = p;
330 else
332 iterator_name_len = attr - p;
333 attr++;
336 FOR_EACH_VEC_ELT (current_iterators, i, iterator)
338 /* If an iterator name was specified, check that it matches. */
339 if (iterator_name_len >= 0
340 && (strncmp (p, iterator->name, iterator_name_len) != 0
341 || iterator->name[iterator_name_len] != 0))
342 continue;
344 /* Find the attribute specification. */
345 m = (struct mapping *) htab_find (iterator->group->attrs, &attr);
346 if (m)
348 /* In contrast to code/mode/int iterators, attributes of subst
349 iterators are linked to one specific subst-iterator. So, if
350 we are dealing with subst-iterator, we should check if it's
351 the one which linked with the given attribute. */
352 if (iterator->group == &substs)
354 char *iter_name = find_subst_iter_by_attr (attr);
355 if (strcmp (iter_name, iterator->name) != 0)
356 continue;
358 /* Find the attribute value associated with the current
359 iterator value. */
360 for (v = m->values; v; v = v->next)
361 if (v->number == iterator->current_value->number)
362 return v;
365 return NULL;
368 /* Apply the current iterator values to STRING. Return the new string
369 if any changes were needed, otherwise return STRING itself. */
371 const char *
372 md_reader::apply_iterator_to_string (const char *string)
374 char *base, *copy, *p, *start, *end;
375 struct map_value *v;
377 if (string == 0)
378 return string;
380 base = p = copy = ASTRDUP (string);
381 while ((start = strchr (p, '<')) && (end = strchr (start, '>')))
383 p = start + 1;
385 *end = 0;
386 v = map_attr_string (p);
387 *end = '>';
388 if (v == 0)
389 continue;
391 /* Add everything between the last copied byte and the '<',
392 then add in the attribute value. */
393 obstack_grow (&m_string_obstack, base, start - base);
394 obstack_grow (&m_string_obstack, v->string, strlen (v->string));
395 base = end + 1;
397 if (base != copy)
399 obstack_grow (&m_string_obstack, base, strlen (base) + 1);
400 copy = XOBFINISH (&m_string_obstack, char *);
401 copy_md_ptr_loc (copy, string);
402 return copy;
404 return string;
407 /* Return a deep copy of X, substituting the current iterator
408 values into any strings. */
411 md_reader::copy_rtx_for_iterators (rtx original)
413 const char *format_ptr, *p;
414 int i, j;
415 rtx x;
417 if (original == 0)
418 return original;
420 /* Create a shallow copy of ORIGINAL. */
421 x = rtx_alloc (GET_CODE (original));
422 memcpy (x, original, RTX_CODE_SIZE (GET_CODE (original)));
424 /* Change each string and recursively change each rtx. */
425 format_ptr = GET_RTX_FORMAT (GET_CODE (original));
426 for (i = 0; format_ptr[i] != 0; i++)
427 switch (format_ptr[i])
429 case 'T':
430 while (XTMPL (x, i) != (p = apply_iterator_to_string (XTMPL (x, i))))
431 XTMPL (x, i) = p;
432 break;
434 case 'S':
435 case 's':
436 while (XSTR (x, i) != (p = apply_iterator_to_string (XSTR (x, i))))
437 XSTR (x, i) = p;
438 break;
440 case 'e':
441 XEXP (x, i) = copy_rtx_for_iterators (XEXP (x, i));
442 break;
444 case 'V':
445 case 'E':
446 if (XVEC (original, i))
448 XVEC (x, i) = rtvec_alloc (XVECLEN (original, i));
449 for (j = 0; j < XVECLEN (x, i); j++)
450 XVECEXP (x, i, j)
451 = copy_rtx_for_iterators (XVECEXP (original, i, j));
453 break;
455 default:
456 break;
458 return x;
461 #ifdef GENERATOR_FILE
463 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
464 has the form "&& ..." (as used in define_insn_and_splits), assume that
465 EXTRA is already satisfied. Empty strings are treated like "true". */
467 static const char *
468 add_condition_to_string (const char *original, const char *extra)
470 if (original != 0 && original[0] == '&' && original[1] == '&')
471 return original;
472 return rtx_reader_ptr->join_c_conditions (original, extra);
475 /* Like add_condition, but applied to all conditions in rtx X. */
477 static void
478 add_condition_to_rtx (rtx x, const char *extra)
480 switch (GET_CODE (x))
482 case DEFINE_INSN:
483 case DEFINE_EXPAND:
484 case DEFINE_SUBST:
485 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra);
486 break;
488 case DEFINE_SPLIT:
489 case DEFINE_PEEPHOLE:
490 case DEFINE_PEEPHOLE2:
491 case DEFINE_COND_EXEC:
492 XSTR (x, 1) = add_condition_to_string (XSTR (x, 1), extra);
493 break;
495 case DEFINE_INSN_AND_SPLIT:
496 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra);
497 XSTR (x, 4) = add_condition_to_string (XSTR (x, 4), extra);
498 break;
500 default:
501 break;
505 /* Apply the current iterator values to all attribute_uses. */
507 static void
508 apply_attribute_uses (void)
510 struct map_value *v;
511 attribute_use *ause;
512 unsigned int i;
514 FOR_EACH_VEC_ELT (attribute_uses, i, ause)
516 v = map_attr_string (ause->value);
517 if (!v)
518 fatal_with_file_and_line ("unknown iterator value `%s'", ause->value);
519 ause->group->apply_iterator (ause->ptr,
520 ause->group->find_builtin (v->string));
524 /* A htab_traverse callback for iterators. Add all used iterators
525 to current_iterators. */
527 static int
528 add_current_iterators (void **slot, void *data ATTRIBUTE_UNUSED)
530 struct mapping *iterator;
532 iterator = (struct mapping *) *slot;
533 if (iterator->current_value)
534 current_iterators.safe_push (iterator);
535 return 1;
538 /* Expand all iterators in the current rtx, which is given as ORIGINAL.
539 Build a list of expanded rtxes in the EXPR_LIST pointed to by QUEUE. */
541 static void
542 apply_iterators (rtx original, vec<rtx> *queue)
544 unsigned int i;
545 const char *condition;
546 iterator_use *iuse;
547 struct mapping *iterator;
548 struct map_value *v;
549 rtx x;
551 if (iterator_uses.is_empty ())
553 /* Raise an error if any attributes were used. */
554 apply_attribute_uses ();
555 queue->safe_push (original);
556 return;
559 /* Clear out the iterators from the previous run. */
560 FOR_EACH_VEC_ELT (current_iterators, i, iterator)
561 iterator->current_value = NULL;
562 current_iterators.truncate (0);
564 /* Mark the iterators that we need this time. */
565 FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
566 iuse->iterator->current_value = iuse->iterator->values;
568 /* Get the list of iterators that are in use, preserving the
569 definition order within each group. */
570 htab_traverse (modes.iterators, add_current_iterators, NULL);
571 htab_traverse (codes.iterators, add_current_iterators, NULL);
572 htab_traverse (ints.iterators, add_current_iterators, NULL);
573 htab_traverse (substs.iterators, add_current_iterators, NULL);
574 gcc_assert (!current_iterators.is_empty ());
576 for (;;)
578 /* Apply the current iterator values. Accumulate a condition to
579 say when the resulting rtx can be used. */
580 condition = "";
581 FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
583 if (iuse->iterator->group == &substs)
584 continue;
585 v = iuse->iterator->current_value;
586 iuse->iterator->group->apply_iterator (iuse->ptr, v->number);
587 condition = rtx_reader_ptr->join_c_conditions (condition, v->string);
589 apply_attribute_uses ();
590 x = rtx_reader_ptr->copy_rtx_for_iterators (original);
591 add_condition_to_rtx (x, condition);
593 /* We apply subst iterator after RTL-template is copied, as during
594 subst-iterator processing, we could add an attribute to the
595 RTL-template, and we don't want to do it in the original one. */
596 FOR_EACH_VEC_ELT (iterator_uses, i, iuse)
598 v = iuse->iterator->current_value;
599 if (iuse->iterator->group == &substs)
601 iuse->ptr = x;
602 current_iterator_name = iuse->iterator->name;
603 iuse->iterator->group->apply_iterator (iuse->ptr, v->number);
606 /* Add the new rtx to the end of the queue. */
607 queue->safe_push (x);
609 /* Lexicographically increment the iterator value sequence.
610 That is, cycle through iterator values, starting from the right,
611 and stopping when one of them doesn't wrap around. */
612 i = current_iterators.length ();
613 for (;;)
615 if (i == 0)
616 return;
617 i--;
618 iterator = current_iterators[i];
619 iterator->current_value = iterator->current_value->next;
620 if (iterator->current_value)
621 break;
622 iterator->current_value = iterator->values;
626 #endif /* #ifdef GENERATOR_FILE */
628 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
629 of the mapping and GROUP is the group to which it belongs. */
631 static struct mapping *
632 add_mapping (struct iterator_group *group, htab_t table, const char *name)
634 struct mapping *m;
635 void **slot;
637 m = XNEW (struct mapping);
638 m->name = xstrdup (name);
639 m->group = group;
640 m->values = 0;
641 m->current_value = NULL;
643 slot = htab_find_slot (table, m, INSERT);
644 if (*slot != 0)
645 fatal_with_file_and_line ("`%s' already defined", name);
647 *slot = m;
648 return m;
651 /* Add the pair (NUMBER, STRING) to a list of map_value structures.
652 END_PTR points to the current null terminator for the list; return
653 a pointer the new null terminator. */
655 static struct map_value **
656 add_map_value (struct map_value **end_ptr, int number, const char *string)
658 struct map_value *value;
660 value = XNEW (struct map_value);
661 value->next = 0;
662 value->number = number;
663 value->string = string;
665 *end_ptr = value;
666 return &value->next;
669 /* Do one-time initialization of the mode and code attributes. */
671 static void
672 initialize_iterators (void)
674 struct mapping *lower, *upper;
675 struct map_value **lower_ptr, **upper_ptr;
676 char *copy, *p;
677 int i;
679 modes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
680 modes.iterators = htab_create (13, leading_string_hash,
681 leading_string_eq_p, 0);
682 modes.find_builtin = find_mode;
683 modes.apply_iterator = apply_mode_iterator;
685 codes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
686 codes.iterators = htab_create (13, leading_string_hash,
687 leading_string_eq_p, 0);
688 codes.find_builtin = find_code;
689 codes.apply_iterator = apply_code_iterator;
691 ints.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
692 ints.iterators = htab_create (13, leading_string_hash,
693 leading_string_eq_p, 0);
694 ints.find_builtin = find_int;
695 ints.apply_iterator = apply_int_iterator;
697 substs.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
698 substs.iterators = htab_create (13, leading_string_hash,
699 leading_string_eq_p, 0);
700 substs.find_builtin = find_int; /* We don't use it, anyway. */
701 #ifdef GENERATOR_FILE
702 substs.apply_iterator = apply_subst_iterator;
703 #endif
705 lower = add_mapping (&modes, modes.attrs, "mode");
706 upper = add_mapping (&modes, modes.attrs, "MODE");
707 lower_ptr = &lower->values;
708 upper_ptr = &upper->values;
709 for (i = 0; i < MAX_MACHINE_MODE; i++)
711 copy = xstrdup (GET_MODE_NAME (i));
712 for (p = copy; *p != 0; p++)
713 *p = TOLOWER (*p);
715 upper_ptr = add_map_value (upper_ptr, i, GET_MODE_NAME (i));
716 lower_ptr = add_map_value (lower_ptr, i, copy);
719 lower = add_mapping (&codes, codes.attrs, "code");
720 upper = add_mapping (&codes, codes.attrs, "CODE");
721 lower_ptr = &lower->values;
722 upper_ptr = &upper->values;
723 for (i = 0; i < NUM_RTX_CODE; i++)
725 copy = xstrdup (GET_RTX_NAME (i));
726 for (p = copy; *p != 0; p++)
727 *p = TOUPPER (*p);
729 lower_ptr = add_map_value (lower_ptr, i, GET_RTX_NAME (i));
730 upper_ptr = add_map_value (upper_ptr, i, copy);
734 /* Provide a version of a function to read a long long if the system does
735 not provide one. */
736 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !HAVE_DECL_ATOLL && !defined(HAVE_ATOQ)
737 HOST_WIDE_INT atoll (const char *);
739 HOST_WIDE_INT
740 atoll (const char *p)
742 int neg = 0;
743 HOST_WIDE_INT tmp_wide;
745 while (ISSPACE (*p))
746 p++;
747 if (*p == '-')
748 neg = 1, p++;
749 else if (*p == '+')
750 p++;
752 tmp_wide = 0;
753 while (ISDIGIT (*p))
755 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0');
756 if (new_wide < tmp_wide)
758 /* Return INT_MAX equiv on overflow. */
759 tmp_wide = HOST_WIDE_INT_M1U >> 1;
760 break;
762 tmp_wide = new_wide;
763 p++;
766 if (neg)
767 tmp_wide = -tmp_wide;
768 return tmp_wide;
770 #endif
773 #ifdef GENERATOR_FILE
774 /* Process a define_conditions directive, starting with the optional
775 space after the "define_conditions". The directive looks like this:
777 (define_conditions [
778 (number "string")
779 (number "string")
783 It's not intended to appear in machine descriptions. It is
784 generated by (the program generated by) genconditions.c, and
785 slipped in at the beginning of the sequence of MD files read by
786 most of the other generators. */
787 void
788 md_reader::read_conditions ()
790 int c;
792 require_char_ws ('[');
794 while ( (c = read_skip_spaces ()) != ']')
796 struct md_name name;
797 char *expr;
798 int value;
800 if (c != '(')
801 fatal_expected_char ('(', c);
803 read_name (&name);
804 validate_const_int (name.string);
805 value = atoi (name.string);
807 require_char_ws ('"');
808 expr = read_quoted_string ();
810 require_char_ws (')');
812 add_c_test (expr, value);
815 #endif /* #ifdef GENERATOR_FILE */
817 static void
818 validate_const_int (const char *string)
820 const char *cp;
821 int valid = 1;
823 cp = string;
824 while (*cp && ISSPACE (*cp))
825 cp++;
826 if (*cp == '-' || *cp == '+')
827 cp++;
828 if (*cp == 0)
829 valid = 0;
830 for (; *cp; cp++)
831 if (! ISDIGIT (*cp))
833 valid = 0;
834 break;
836 if (!valid)
837 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string);
840 static void
841 validate_const_wide_int (const char *string)
843 const char *cp;
844 int valid = 1;
846 cp = string;
847 while (*cp && ISSPACE (*cp))
848 cp++;
849 /* Skip the leading 0x. */
850 if (cp[0] == '0' || cp[1] == 'x')
851 cp += 2;
852 else
853 valid = 0;
854 if (*cp == 0)
855 valid = 0;
856 for (; *cp; cp++)
857 if (! ISXDIGIT (*cp))
858 valid = 0;
859 if (!valid)
860 fatal_with_file_and_line ("invalid hex constant \"%s\"\n", string);
863 /* Record that PTR uses iterator ITERATOR. */
865 static void
866 record_iterator_use (struct mapping *iterator, void *ptr)
868 struct iterator_use iuse = {iterator, ptr};
869 iterator_uses.safe_push (iuse);
872 /* Record that PTR uses attribute VALUE, which must match a built-in
873 value from group GROUP. */
875 static void
876 record_attribute_use (struct iterator_group *group, void *ptr,
877 const char *value)
879 struct attribute_use ause = {group, value, ptr};
880 attribute_uses.safe_push (ause);
883 /* Interpret NAME as either a built-in value, iterator or attribute
884 for group GROUP. PTR is the value to pass to GROUP's apply_iterator
885 callback. */
887 void
888 md_reader::record_potential_iterator_use (struct iterator_group *group,
889 void *ptr, const char *name)
891 struct mapping *m;
892 size_t len;
894 len = strlen (name);
895 if (name[0] == '<' && name[len - 1] == '>')
897 /* Copy the attribute string into permanent storage, without the
898 angle brackets around it. */
899 obstack_grow0 (&m_string_obstack, name + 1, len - 2);
900 record_attribute_use (group, ptr, XOBFINISH (&m_string_obstack, char *));
902 else
904 m = (struct mapping *) htab_find (group->iterators, &name);
905 if (m != 0)
906 record_iterator_use (m, ptr);
907 else
908 group->apply_iterator (ptr, group->find_builtin (name));
912 #ifdef GENERATOR_FILE
914 /* Finish reading a declaration of the form:
916 (define... <name> [<value1> ... <valuen>])
918 from the MD file, where each <valuei> is either a bare symbol name or a
919 "(<name> <string>)" pair. The "(define..." part has already been read.
921 Represent the declaration as a "mapping" structure; add it to TABLE
922 (which belongs to GROUP) and return it. */
924 struct mapping *
925 md_reader::read_mapping (struct iterator_group *group, htab_t table)
927 struct md_name name;
928 struct mapping *m;
929 struct map_value **end_ptr;
930 const char *string;
931 int number, c;
933 /* Read the mapping name and create a structure for it. */
934 read_name (&name);
935 m = add_mapping (group, table, name.string);
937 require_char_ws ('[');
939 /* Read each value. */
940 end_ptr = &m->values;
941 c = read_skip_spaces ();
944 if (c != '(')
946 /* A bare symbol name that is implicitly paired to an
947 empty string. */
948 unread_char (c);
949 read_name (&name);
950 string = "";
952 else
954 /* A "(name string)" pair. */
955 read_name (&name);
956 string = read_string (false);
957 require_char_ws (')');
959 number = group->find_builtin (name.string);
960 end_ptr = add_map_value (end_ptr, number, string);
961 c = read_skip_spaces ();
963 while (c != ']');
965 return m;
968 /* For iterator with name ATTR_NAME generate define_attr with values
969 'yes' and 'no'. This attribute is used to mark templates to which
970 define_subst ATTR_NAME should be applied. This attribute is set and
971 defined implicitly and automatically. */
972 static void
973 add_define_attr_for_define_subst (const char *attr_name, vec<rtx> *queue)
975 rtx const_str, return_rtx;
977 return_rtx = rtx_alloc (DEFINE_ATTR);
978 PUT_CODE (return_rtx, DEFINE_ATTR);
980 const_str = rtx_alloc (CONST_STRING);
981 PUT_CODE (const_str, CONST_STRING);
982 XSTR (const_str, 0) = xstrdup ("no");
984 XSTR (return_rtx, 0) = xstrdup (attr_name);
985 XSTR (return_rtx, 1) = xstrdup ("no,yes");
986 XEXP (return_rtx, 2) = const_str;
988 queue->safe_push (return_rtx);
991 /* This routine generates DEFINE_SUBST_ATTR expression with operands
992 ATTR_OPERANDS and places it to QUEUE. */
993 static void
994 add_define_subst_attr (const char **attr_operands, vec<rtx> *queue)
996 rtx return_rtx;
997 int i;
999 return_rtx = rtx_alloc (DEFINE_SUBST_ATTR);
1000 PUT_CODE (return_rtx, DEFINE_SUBST_ATTR);
1002 for (i = 0; i < 4; i++)
1003 XSTR (return_rtx, i) = xstrdup (attr_operands[i]);
1005 queue->safe_push (return_rtx);
1008 /* Read define_subst_attribute construction. It has next form:
1009 (define_subst_attribute <attribute_name> <iterator_name> <value1> <value2>)
1010 Attribute is substituted with value1 when no subst is applied and with
1011 value2 in the opposite case.
1012 Attributes are added to SUBST_ATTRS_TABLE.
1013 In case the iterator is encountered for the first time, it's added to
1014 SUBST_ITERS_TABLE. Also, implicit define_attr is generated. */
1016 static void
1017 read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table,
1018 vec<rtx> *queue)
1020 struct mapping *m;
1021 struct map_value **end_ptr;
1022 const char *attr_operands[4];
1023 int i;
1025 for (i = 0; i < 4; i++)
1026 attr_operands[i] = rtx_reader_ptr->read_string (false);
1028 add_define_subst_attr (attr_operands, queue);
1030 bind_subst_iter_and_attr (attr_operands[1], attr_operands[0]);
1032 m = (struct mapping *) htab_find (substs.iterators, &attr_operands[1]);
1033 if (!m)
1035 m = add_mapping (&substs, subst_iters_table, attr_operands[1]);
1036 end_ptr = &m->values;
1037 end_ptr = add_map_value (end_ptr, 1, "");
1038 end_ptr = add_map_value (end_ptr, 2, "");
1040 add_define_attr_for_define_subst (attr_operands[1], queue);
1043 m = add_mapping (&substs, subst_attrs_table, attr_operands[0]);
1044 end_ptr = &m->values;
1045 end_ptr = add_map_value (end_ptr, 1, attr_operands[2]);
1046 end_ptr = add_map_value (end_ptr, 2, attr_operands[3]);
1049 /* Check newly-created code iterator ITERATOR to see whether every code has the
1050 same format. */
1052 static void
1053 check_code_iterator (struct mapping *iterator)
1055 struct map_value *v;
1056 enum rtx_code bellwether;
1058 bellwether = (enum rtx_code) iterator->values->number;
1059 for (v = iterator->values->next; v != 0; v = v->next)
1060 if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0)
1061 fatal_with_file_and_line ("code iterator `%s' combines "
1062 "different rtx formats", iterator->name);
1065 /* Read an rtx-related declaration from the MD file, given that it
1066 starts with directive name RTX_NAME. Return true if it expands to
1067 one or more rtxes (as defined by rtx.def). When returning true,
1068 store the list of rtxes as an EXPR_LIST in *X. */
1070 bool
1071 rtx_reader::read_rtx (const char *rtx_name, vec<rtx> *rtxen)
1073 /* Handle various rtx-related declarations that aren't themselves
1074 encoded as rtxes. */
1075 if (strcmp (rtx_name, "define_conditions") == 0)
1077 read_conditions ();
1078 return false;
1080 if (strcmp (rtx_name, "define_mode_attr") == 0)
1082 read_mapping (&modes, modes.attrs);
1083 return false;
1085 if (strcmp (rtx_name, "define_mode_iterator") == 0)
1087 read_mapping (&modes, modes.iterators);
1088 return false;
1090 if (strcmp (rtx_name, "define_code_attr") == 0)
1092 read_mapping (&codes, codes.attrs);
1093 return false;
1095 if (strcmp (rtx_name, "define_code_iterator") == 0)
1097 check_code_iterator (read_mapping (&codes, codes.iterators));
1098 return false;
1100 if (strcmp (rtx_name, "define_int_attr") == 0)
1102 read_mapping (&ints, ints.attrs);
1103 return false;
1105 if (strcmp (rtx_name, "define_int_iterator") == 0)
1107 read_mapping (&ints, ints.iterators);
1108 return false;
1110 if (strcmp (rtx_name, "define_subst_attr") == 0)
1112 read_subst_mapping (substs.iterators, substs.attrs, rtxen);
1114 /* READ_SUBST_MAPPING could generate a new DEFINE_ATTR. Return
1115 TRUE to process it. */
1116 return true;
1119 apply_iterators (rtx_reader_ptr->read_rtx_code (rtx_name), rtxen);
1120 iterator_uses.truncate (0);
1121 attribute_uses.truncate (0);
1123 return true;
1126 #endif /* #ifdef GENERATOR_FILE */
1128 /* Do one-time initialization. */
1130 static void
1131 one_time_initialization (void)
1133 static bool initialized = false;
1135 if (!initialized)
1137 initialize_iterators ();
1138 initialized = true;
1142 /* Consume characters until encountering a character in TERMINATOR_CHARS,
1143 consuming the terminator character if CONSUME_TERMINATOR is true.
1144 Return all characters before the terminator as an allocated buffer. */
1146 char *
1147 rtx_reader::read_until (const char *terminator_chars, bool consume_terminator)
1149 int ch = read_skip_spaces ();
1150 unread_char (ch);
1151 auto_vec<char> buf;
1152 while (1)
1154 ch = read_char ();
1155 if (strchr (terminator_chars, ch))
1157 if (!consume_terminator)
1158 unread_char (ch);
1159 break;
1161 buf.safe_push (ch);
1163 buf.safe_push ('\0');
1164 return xstrdup (buf.address ());
1167 /* Subroutine of read_rtx_code, for parsing zero or more flags. */
1169 static void
1170 read_flags (rtx return_rtx)
1172 while (1)
1174 int ch = read_char ();
1175 if (ch != '/')
1177 unread_char (ch);
1178 break;
1181 int flag_char = read_char ();
1182 switch (flag_char)
1184 case 's':
1185 RTX_FLAG (return_rtx, in_struct) = 1;
1186 break;
1187 case 'v':
1188 RTX_FLAG (return_rtx, volatil) = 1;
1189 break;
1190 case 'u':
1191 RTX_FLAG (return_rtx, unchanging) = 1;
1192 break;
1193 case 'f':
1194 RTX_FLAG (return_rtx, frame_related) = 1;
1195 break;
1196 case 'j':
1197 RTX_FLAG (return_rtx, jump) = 1;
1198 break;
1199 case 'c':
1200 RTX_FLAG (return_rtx, call) = 1;
1201 break;
1202 case 'i':
1203 RTX_FLAG (return_rtx, return_val) = 1;
1204 break;
1205 default:
1206 fatal_with_file_and_line ("unrecognized flag: `%c'", flag_char);
1211 /* Return the numeric value n for GET_REG_NOTE_NAME (n) for STRING,
1212 or fail if STRING isn't recognized. */
1214 static int
1215 parse_reg_note_name (const char *string)
1217 for (int i = 0; i < REG_NOTE_MAX; i++)
1218 if (0 == strcmp (string, GET_REG_NOTE_NAME (i)))
1219 return i;
1220 fatal_with_file_and_line ("unrecognized REG_NOTE name: `%s'", string);
1223 /* Subroutine of read_rtx and read_nested_rtx. CODE_NAME is the name of
1224 either an rtx code or a code iterator. Parse the rest of the rtx and
1225 return it. */
1228 rtx_reader::read_rtx_code (const char *code_name)
1230 RTX_CODE code;
1231 struct mapping *iterator = NULL;
1232 const char *format_ptr;
1233 struct md_name name;
1234 rtx return_rtx;
1235 int c;
1236 long reuse_id = -1;
1238 /* Linked list structure for making RTXs: */
1239 struct rtx_list
1241 struct rtx_list *next;
1242 rtx value; /* Value of this node. */
1245 /* Handle reuse_rtx ids e.g. "(0|scratch:DI)". */
1246 if (ISDIGIT (code_name[0]))
1248 reuse_id = atoi (code_name);
1249 while (char ch = *code_name++)
1250 if (ch == '|')
1251 break;
1254 /* Handle "reuse_rtx". */
1255 if (strcmp (code_name, "reuse_rtx") == 0)
1257 read_name (&name);
1258 unsigned idx = atoi (name.string);
1259 /* Look it up by ID. */
1260 gcc_assert (idx < m_reuse_rtx_by_id.length ());
1261 return_rtx = m_reuse_rtx_by_id[idx];
1262 return return_rtx;
1265 /* If this code is an iterator, build the rtx using the iterator's
1266 first value. */
1267 #ifdef GENERATOR_FILE
1268 iterator = (struct mapping *) htab_find (codes.iterators, &code_name);
1269 if (iterator != 0)
1270 code = (enum rtx_code) iterator->values->number;
1271 else
1272 code = (enum rtx_code) codes.find_builtin (code_name);
1273 #else
1274 code = (enum rtx_code) codes.find_builtin (code_name);
1275 #endif
1277 /* If we end up with an insn expression then we free this space below. */
1278 return_rtx = rtx_alloc (code);
1279 format_ptr = GET_RTX_FORMAT (code);
1280 memset (return_rtx, 0, RTX_CODE_SIZE (code));
1281 PUT_CODE (return_rtx, code);
1283 if (reuse_id != -1)
1285 /* Store away for later reuse. */
1286 m_reuse_rtx_by_id.safe_grow_cleared (reuse_id + 1);
1287 m_reuse_rtx_by_id[reuse_id] = return_rtx;
1290 if (iterator)
1291 record_iterator_use (iterator, return_rtx);
1293 /* Check for flags. */
1294 read_flags (return_rtx);
1296 /* Read REG_NOTE names for EXPR_LIST and INSN_LIST. */
1297 if ((GET_CODE (return_rtx) == EXPR_LIST
1298 || GET_CODE (return_rtx) == INSN_LIST
1299 || GET_CODE (return_rtx) == INT_LIST)
1300 && !m_in_call_function_usage)
1302 char ch = read_char ();
1303 if (ch == ':')
1305 read_name (&name);
1306 PUT_MODE_RAW (return_rtx,
1307 (machine_mode)parse_reg_note_name (name.string));
1309 else
1310 unread_char (ch);
1313 /* If what follows is `: mode ', read it and
1314 store the mode in the rtx. */
1316 c = read_skip_spaces ();
1317 if (c == ':')
1319 read_name (&name);
1320 record_potential_iterator_use (&modes, return_rtx, name.string);
1322 else
1323 unread_char (c);
1325 if (INSN_CHAIN_CODE_P (code))
1327 read_name (&name);
1328 INSN_UID (return_rtx) = atoi (name.string);
1331 /* Use the format_ptr to parse the various operands of this rtx. */
1332 for (int idx = 0; format_ptr[idx] != 0; idx++)
1333 return_rtx = read_rtx_operand (return_rtx, idx);
1335 /* Handle any additional information that after the regular fields
1336 (e.g. when parsing function dumps). */
1337 handle_any_trailing_information (return_rtx);
1339 if (CONST_WIDE_INT_P (return_rtx))
1341 read_name (&name);
1342 validate_const_wide_int (name.string);
1344 const char *s = name.string;
1345 int len;
1346 int index = 0;
1347 int gs = HOST_BITS_PER_WIDE_INT/4;
1348 int pos;
1349 char * buf = XALLOCAVEC (char, gs + 1);
1350 unsigned HOST_WIDE_INT wi;
1351 int wlen;
1353 /* Skip the leading spaces. */
1354 while (*s && ISSPACE (*s))
1355 s++;
1357 /* Skip the leading 0x. */
1358 gcc_assert (s[0] == '0');
1359 gcc_assert (s[1] == 'x');
1360 s += 2;
1362 len = strlen (s);
1363 pos = len - gs;
1364 wlen = (len + gs - 1) / gs; /* Number of words needed */
1366 return_rtx = const_wide_int_alloc (wlen);
1368 while (pos > 0)
1370 #if HOST_BITS_PER_WIDE_INT == 64
1371 sscanf (s + pos, "%16" HOST_WIDE_INT_PRINT "x", &wi);
1372 #else
1373 sscanf (s + pos, "%8" HOST_WIDE_INT_PRINT "x", &wi);
1374 #endif
1375 CWI_ELT (return_rtx, index++) = wi;
1376 pos -= gs;
1378 strncpy (buf, s, gs - pos);
1379 buf [gs - pos] = 0;
1380 sscanf (buf, "%" HOST_WIDE_INT_PRINT "x", &wi);
1381 CWI_ELT (return_rtx, index++) = wi;
1382 /* TODO: After reading, do we want to canonicalize with:
1383 value = lookup_const_wide_int (value); ? */
1387 c = read_skip_spaces ();
1388 /* Syntactic sugar for AND and IOR, allowing Lisp-like
1389 arbitrary number of arguments for them. */
1390 if (c == '('
1391 && (GET_CODE (return_rtx) == AND
1392 || GET_CODE (return_rtx) == IOR))
1393 return read_rtx_variadic (return_rtx);
1395 unread_char (c);
1396 return return_rtx;
1399 /* Subroutine of read_rtx_code. Parse operand IDX within RETURN_RTX,
1400 based on the corresponding format character within GET_RTX_FORMAT
1401 for the GET_CODE (RETURN_RTX), and return RETURN_RTX.
1402 This is a virtual function, so that function_reader can override
1403 some parsing, and potentially return a different rtx. */
1406 rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
1408 RTX_CODE code = GET_CODE (return_rtx);
1409 const char *format_ptr = GET_RTX_FORMAT (code);
1410 int c;
1411 struct md_name name;
1413 switch (format_ptr[idx])
1415 /* 0 means a field for internal use only.
1416 Don't expect it to be present in the input. */
1417 case '0':
1418 if (code == REG)
1419 ORIGINAL_REGNO (return_rtx) = REGNO (return_rtx);
1420 break;
1422 case 'e':
1423 XEXP (return_rtx, idx) = read_nested_rtx ();
1424 break;
1426 case 'u':
1427 XEXP (return_rtx, idx) = read_nested_rtx ();
1428 break;
1430 case 'V':
1431 /* 'V' is an optional vector: if a closeparen follows,
1432 just store NULL for this element. */
1433 c = read_skip_spaces ();
1434 unread_char (c);
1435 if (c == ')')
1437 XVEC (return_rtx, idx) = 0;
1438 break;
1440 /* Now process the vector. */
1441 /* FALLTHRU */
1443 case 'E':
1445 /* Obstack to store scratch vector in. */
1446 struct obstack vector_stack;
1447 int list_counter = 0;
1448 rtvec return_vec = NULL_RTVEC;
1450 require_char_ws ('[');
1452 /* Add expressions to a list, while keeping a count. */
1453 obstack_init (&vector_stack);
1454 while ((c = read_skip_spaces ()) && c != ']')
1456 if (c == EOF)
1457 fatal_expected_char (']', c);
1458 unread_char (c);
1459 list_counter++;
1460 obstack_ptr_grow (&vector_stack, read_nested_rtx ());
1462 if (list_counter > 0)
1464 return_vec = rtvec_alloc (list_counter);
1465 memcpy (&return_vec->elem[0], obstack_finish (&vector_stack),
1466 list_counter * sizeof (rtx));
1468 else if (format_ptr[idx] == 'E')
1469 fatal_with_file_and_line ("vector must have at least one element");
1470 XVEC (return_rtx, idx) = return_vec;
1471 obstack_free (&vector_stack, NULL);
1472 /* close bracket gotten */
1474 break;
1476 case 'S':
1477 case 'T':
1478 case 's':
1480 char *stringbuf;
1481 int star_if_braced;
1483 c = read_skip_spaces ();
1484 unread_char (c);
1485 if (c == ')')
1487 /* 'S' fields are optional and should be NULL if no string
1488 was given. Also allow normal 's' and 'T' strings to be
1489 omitted, treating them in the same way as empty strings. */
1490 XSTR (return_rtx, idx) = (format_ptr[idx] == 'S' ? NULL : "");
1491 break;
1494 /* The output template slot of a DEFINE_INSN,
1495 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
1496 gets a star inserted as its first character, if it is
1497 written with a brace block instead of a string constant. */
1498 star_if_braced = (format_ptr[idx] == 'T');
1500 stringbuf = read_string (star_if_braced);
1501 if (!stringbuf)
1502 break;
1504 #ifdef GENERATOR_FILE
1505 /* For insn patterns, we want to provide a default name
1506 based on the file and line, like "*foo.md:12", if the
1507 given name is blank. These are only for define_insn and
1508 define_insn_and_split, to aid debugging. */
1509 if (*stringbuf == '\0'
1510 && idx == 0
1511 && (GET_CODE (return_rtx) == DEFINE_INSN
1512 || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT))
1514 struct obstack *string_obstack = get_string_obstack ();
1515 char line_name[20];
1516 const char *read_md_filename = get_filename ();
1517 const char *fn = (read_md_filename ? read_md_filename : "rtx");
1518 const char *slash;
1519 for (slash = fn; *slash; slash ++)
1520 if (*slash == '/' || *slash == '\\' || *slash == ':')
1521 fn = slash + 1;
1522 obstack_1grow (string_obstack, '*');
1523 obstack_grow (string_obstack, fn, strlen (fn));
1524 sprintf (line_name, ":%d", get_lineno ());
1525 obstack_grow (string_obstack, line_name, strlen (line_name)+1);
1526 stringbuf = XOBFINISH (string_obstack, char *);
1529 /* Find attr-names in the string. */
1530 char *str;
1531 char *start, *end, *ptr;
1532 char tmpstr[256];
1533 ptr = &tmpstr[0];
1534 end = stringbuf;
1535 while ((start = strchr (end, '<')) && (end = strchr (start, '>')))
1537 if ((end - start - 1 > 0)
1538 && (end - start - 1 < (int)sizeof (tmpstr)))
1540 strncpy (tmpstr, start+1, end-start-1);
1541 tmpstr[end-start-1] = 0;
1542 end++;
1544 else
1545 break;
1546 struct mapping *m
1547 = (struct mapping *) htab_find (substs.attrs, &ptr);
1548 if (m != 0)
1550 /* Here we should find linked subst-iter. */
1551 str = find_subst_iter_by_attr (ptr);
1552 if (str)
1553 m = (struct mapping *) htab_find (substs.iterators, &str);
1554 else
1555 m = 0;
1557 if (m != 0)
1558 record_iterator_use (m, return_rtx);
1560 #endif /* #ifdef GENERATOR_FILE */
1562 const char *string_ptr = finalize_string (stringbuf);
1564 if (star_if_braced)
1565 XTMPL (return_rtx, idx) = string_ptr;
1566 else
1567 XSTR (return_rtx, idx) = string_ptr;
1569 break;
1571 case 'w':
1573 HOST_WIDE_INT tmp_wide;
1574 read_name (&name);
1575 validate_const_int (name.string);
1576 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1577 tmp_wide = atoi (name.string);
1578 #else
1579 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1580 tmp_wide = atol (name.string);
1581 #else
1582 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
1583 But prefer not to use our hand-rolled function above either. */
1584 #if HAVE_DECL_ATOLL || !defined(HAVE_ATOQ)
1585 tmp_wide = atoll (name.string);
1586 #else
1587 tmp_wide = atoq (name.string);
1588 #endif
1589 #endif
1590 #endif
1591 XWINT (return_rtx, idx) = tmp_wide;
1593 break;
1595 case 'i':
1596 case 'n':
1597 /* Can be an iterator or an integer constant. */
1598 read_name (&name);
1599 record_potential_iterator_use (&ints, &XINT (return_rtx, idx),
1600 name.string);
1601 break;
1603 case 'r':
1604 read_name (&name);
1605 validate_const_int (name.string);
1606 set_regno_raw (return_rtx, atoi (name.string), 1);
1607 REG_ATTRS (return_rtx) = NULL;
1608 break;
1610 default:
1611 gcc_unreachable ();
1614 return return_rtx;
1617 /* Read a nested rtx construct from the MD file and return it. */
1620 rtx_reader::read_nested_rtx ()
1622 struct md_name name;
1623 rtx return_rtx;
1625 /* In compact dumps, trailing "(nil)" values can be omitted.
1626 Handle such dumps. */
1627 if (peek_char () == ')')
1628 return NULL_RTX;
1630 require_char_ws ('(');
1632 read_name (&name);
1633 if (strcmp (name.string, "nil") == 0)
1634 return_rtx = NULL;
1635 else
1636 return_rtx = read_rtx_code (name.string);
1638 require_char_ws (')');
1640 return_rtx = postprocess (return_rtx);
1642 return return_rtx;
1645 /* Mutually recursive subroutine of read_rtx which reads
1646 (thing x1 x2 x3 ...) and produces RTL as if
1647 (thing x1 (thing x2 (thing x3 ...))) had been written.
1648 When called, FORM is (thing x1 x2), and the file position
1649 is just past the leading parenthesis of x3. Only works
1650 for THINGs which are dyadic expressions, e.g. AND, IOR. */
1652 rtx_reader::read_rtx_variadic (rtx form)
1654 char c = '(';
1655 rtx p = form, q;
1659 unread_char (c);
1661 q = rtx_alloc (GET_CODE (p));
1662 PUT_MODE (q, GET_MODE (p));
1664 XEXP (q, 0) = XEXP (p, 1);
1665 XEXP (q, 1) = read_nested_rtx ();
1667 XEXP (p, 1) = q;
1668 p = q;
1669 c = read_skip_spaces ();
1671 while (c == '(');
1672 unread_char (c);
1673 return form;
1676 /* Constructor for class rtx_reader. */
1678 rtx_reader::rtx_reader (bool compact)
1679 : md_reader (compact),
1680 m_in_call_function_usage (false)
1682 /* Set the global singleton pointer. */
1683 rtx_reader_ptr = this;
1685 one_time_initialization ();
1688 /* Destructor for class rtx_reader. */
1690 rtx_reader::~rtx_reader ()
1692 /* Clear the global singleton pointer. */
1693 rtx_reader_ptr = NULL;