2 Copyright (C) 1987-2023 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
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
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. */
28 /* Disable rtl checking; it conflicts with the iterator handling. */
29 #undef ENABLE_RTL_CHECKING
32 #include "coretypes.h"
37 #include "gensupport.h"
39 /* One element in a singly-linked list of (integer, string) pairs. */
41 struct map_value
*next
;
46 /* Maps an iterator or attribute name to a list of (integer, string) pairs.
47 The integers are iterator values; the strings are either C conditions
48 or attribute values. */
50 /* The name of the iterator or attribute. */
53 /* The group (modes or codes) to which the iterator or attribute belongs. */
54 struct iterator_group
*group
;
56 /* The list of (integer, string) pairs. */
57 struct map_value
*values
;
59 /* For iterators, records the current value of the iterator. */
60 struct map_value
*current_value
;
63 /* A structure for abstracting the common parts of iterators. */
64 struct iterator_group
{
65 /* Tables of "mapping" structures, one for attributes and one for
67 htab_t attrs
, iterators
;
69 /* The C++ type of the iterator, such as "machine_mode" for modes. */
72 /* Treat the given string as the name of a standard mode, etc., and
73 return its integer value. */
74 HOST_WIDE_INT (*find_builtin
) (const char *);
76 /* Make the given rtx use the iterator value given by the third argument.
77 If the iterator applies to operands, the second argument gives the
78 operand index, otherwise it is ignored. */
79 void (*apply_iterator
) (rtx
, unsigned int, HOST_WIDE_INT
);
81 /* Return the C token for the given standard mode, code, etc. */
82 const char *(*get_c_token
) (int);
84 /* True if each iterator name should be treated as an attribute that
85 maps to the C token produced by get_c_token. This means that for
86 an iterator ITER, <ITER> can be used in strings to refer to the
87 current value of ITER, as a C token. */
91 /* Records one use of an iterator. */
93 /* The iterator itself. */
94 struct mapping
*iterator
;
96 /* The location of the use, as passed to the apply_iterator callback.
97 The index is the number of the operand that used the iterator
98 if applicable, otherwise it is ignored. */
103 /* Records one use of an attribute (the "<[iterator:]attribute>" syntax)
104 in a non-string rtx field. */
105 struct attribute_use
{
106 /* The group that describes the use site. */
107 struct iterator_group
*group
;
109 /* The location at which the use occurs. */
112 /* The name of the attribute, possibly with an "iterator:" prefix. */
115 /* The location of the use, as passed to GROUP's apply_iterator callback.
116 The index is the number of the operand that used the iterator
117 if applicable, otherwise it is ignored. */
122 /* This struct is used to link subst_attr named ATTR_NAME with
123 corresponding define_subst named ITER_NAME. */
124 struct subst_attr_to_iter_mapping
130 /* Hash-table to store links between subst-attributes and
132 htab_t subst_attr_to_iter_map
= NULL
;
133 /* This global stores name of subst-iterator which is currently being
135 const char *current_iterator_name
;
137 static void validate_const_int (const char *);
138 static void one_time_initialization (void);
140 /* Global singleton. */
141 rtx_reader
*rtx_reader_ptr
= NULL
;
143 /* The mode and code iterator structures. */
144 static struct iterator_group modes
, codes
, ints
, substs
;
146 /* All iterators used in the current rtx. */
147 static vec
<mapping
*> current_iterators
;
149 /* The list of all iterator uses in the current rtx. */
150 static vec
<iterator_use
> iterator_uses
;
152 /* The list of all attribute uses in the current rtx. */
153 static vec
<attribute_use
> attribute_uses
;
155 /* Provide a version of a function to read a long long if the system does
157 #if (HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG \
158 && !HAVE_DECL_ATOLL \
159 && !defined (HAVE_ATOQ))
160 HOST_WIDE_INT
atoll (const char *);
163 atoll (const char *p
)
166 HOST_WIDE_INT tmp_wide
;
178 HOST_WIDE_INT new_wide
= tmp_wide
*10 + (*p
- '0');
179 if (new_wide
< tmp_wide
)
181 /* Return INT_MAX equiv on overflow. */
182 tmp_wide
= HOST_WIDE_INT_M1U
>> 1;
190 tmp_wide
= -tmp_wide
;
195 /* Implementations of the iterator_group callbacks for modes. */
198 find_mode (const char *name
)
202 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
203 if (strcmp (GET_MODE_NAME (i
), name
) == 0)
206 fatal_with_file_and_line ("unknown mode `%s'", name
);
210 apply_mode_iterator (rtx x
, unsigned int, HOST_WIDE_INT mode
)
212 PUT_MODE (x
, (machine_mode
) mode
);
216 get_mode_token (int mode
)
218 return concat ("E_", GET_MODE_NAME (mode
), "mode", NULL
);
221 /* In compact dumps, the code of insns is prefixed with "c", giving "cinsn",
222 "cnote" etc, and CODE_LABEL is special-cased as "clabel". */
224 struct compact_insn_name
{
229 static const compact_insn_name compact_insn_names
[] = {
230 { DEBUG_INSN
, "cdebug_insn" },
232 { JUMP_INSN
, "cjump_insn" },
233 { CALL_INSN
, "ccall_insn" },
234 { JUMP_TABLE_DATA
, "cjump_table_data" },
235 { BARRIER
, "cbarrier" },
236 { CODE_LABEL
, "clabel" },
240 /* Return the rtx code for NAME, or UNKNOWN if NAME isn't a valid rtx code. */
243 maybe_find_code (const char *name
)
245 for (int i
= 0; i
< NUM_RTX_CODE
; i
++)
246 if (strcmp (GET_RTX_NAME (i
), name
) == 0)
249 for (int i
= 0; i
< (signed)ARRAY_SIZE (compact_insn_names
); i
++)
250 if (strcmp (compact_insn_names
[i
].name
, name
) == 0)
251 return compact_insn_names
[i
].code
;
256 /* Implementations of the iterator_group callbacks for codes. */
259 find_code (const char *name
)
261 rtx_code code
= maybe_find_code (name
);
263 fatal_with_file_and_line ("unknown rtx code `%s'", name
);
268 apply_code_iterator (rtx x
, unsigned int, HOST_WIDE_INT code
)
270 PUT_CODE (x
, (enum rtx_code
) code
);
274 get_code_token (int code
)
276 char *name
= xstrdup (GET_RTX_NAME (code
));
277 for (int i
= 0; name
[i
]; ++i
)
278 name
[i
] = TOUPPER (name
[i
]);
282 /* Implementations of the iterator_group callbacks for ints. */
284 /* Since GCC does not construct a table of valid constants,
285 we have to accept any int as valid. No cross-checking can
289 find_int (const char *name
)
293 struct md_constant tmp_def
;
294 tmp_def
.name
= const_cast<char *> (name
);
295 auto htab
= rtx_reader_ptr
->get_md_constants ();
296 if (auto def
= (struct md_constant
*) htab_find (htab
, &tmp_def
))
299 validate_const_int (name
);
300 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
303 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
306 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
307 But prefer not to use our hand-rolled function above either. */
308 #if HAVE_DECL_ATOLL || !defined(HAVE_ATOQ)
319 apply_int_iterator (rtx x
, unsigned int index
, HOST_WIDE_INT value
)
321 RTX_CODE code
= GET_CODE (x
);
322 const char *format_ptr
= GET_RTX_FORMAT (code
);
324 switch (format_ptr
[index
])
328 XINT (x
, index
) = value
;
331 XWINT (x
, index
) = value
;
334 gcc_assert (code
== SUBREG
);
335 SUBREG_BYTE (x
) = value
;
343 get_int_token (int value
)
345 char buffer
[HOST_BITS_PER_INT
+ 1];
346 sprintf (buffer
, "%d", value
);
347 return xstrdup (buffer
);
350 #ifdef GENERATOR_FILE
352 /* This routine adds attribute or does nothing depending on VALUE. When
353 VALUE is 1, it does nothing - the first duplicate of original
354 template is kept untouched when it's subjected to a define_subst.
355 When VALUE isn't 1, the routine modifies RTL-template RT, adding
356 attribute, named exactly as define_subst, which later will be
357 applied. If such attribute has already been added, then no the
358 routine has no effect. */
360 apply_subst_iterator (rtx rt
, unsigned int, HOST_WIDE_INT value
)
363 rtvec attrs_vec
, new_attrs_vec
;
365 /* define_split has no attributes. */
366 if (value
== 1 || GET_CODE (rt
) == DEFINE_SPLIT
)
368 gcc_assert (GET_CODE (rt
) == DEFINE_INSN
369 || GET_CODE (rt
) == DEFINE_INSN_AND_SPLIT
370 || GET_CODE (rt
) == DEFINE_INSN_AND_REWRITE
371 || GET_CODE (rt
) == DEFINE_EXPAND
);
373 int attrs
= (GET_CODE (rt
) == DEFINE_INSN_AND_SPLIT
? 7
374 : GET_CODE (rt
) == DEFINE_INSN_AND_REWRITE
? 6 : 4);
375 attrs_vec
= XVEC (rt
, attrs
);
377 /* If we've already added attribute 'current_iterator_name', then we
378 have nothing to do now. */
381 for (i
= 0; i
< GET_NUM_ELEM (attrs_vec
); i
++)
383 if (strcmp (XSTR (attrs_vec
->elem
[i
], 0), current_iterator_name
) == 0)
388 /* Add attribute with subst name - it serves as a mark for
389 define_subst which later would be applied to this pattern. */
390 new_attr
= rtx_alloc (SET_ATTR
);
391 PUT_CODE (new_attr
, SET_ATTR
);
392 XSTR (new_attr
, 0) = xstrdup (current_iterator_name
);
393 XSTR (new_attr
, 1) = xstrdup ("yes");
397 new_attrs_vec
= rtvec_alloc (1);
398 new_attrs_vec
->elem
[0] = new_attr
;
402 new_attrs_vec
= rtvec_alloc (GET_NUM_ELEM (attrs_vec
) + 1);
403 memcpy (&new_attrs_vec
->elem
[0], &attrs_vec
->elem
[0],
404 GET_NUM_ELEM (attrs_vec
) * sizeof (rtx
));
405 new_attrs_vec
->elem
[GET_NUM_ELEM (attrs_vec
)] = new_attr
;
407 XVEC (rt
, attrs
) = new_attrs_vec
;
410 /* Map subst-attribute ATTR to subst iterator ITER. */
413 bind_subst_iter_and_attr (const char *iter
, const char *attr
)
415 struct subst_attr_to_iter_mapping
*value
;
417 if (!subst_attr_to_iter_map
)
418 subst_attr_to_iter_map
=
419 htab_create (1, leading_string_hash
, leading_string_eq_p
, 0);
420 value
= XNEW (struct subst_attr_to_iter_mapping
);
421 value
->attr_name
= xstrdup (attr
);
422 value
->iter_name
= xstrdup (iter
);
423 slot
= htab_find_slot (subst_attr_to_iter_map
, value
, INSERT
);
427 #endif /* #ifdef GENERATOR_FILE */
429 /* Return name of a subst-iterator, corresponding to subst-attribute ATTR. */
432 find_subst_iter_by_attr (const char *attr
)
434 char *iter_name
= NULL
;
435 struct subst_attr_to_iter_mapping
*value
;
436 value
= (struct subst_attr_to_iter_mapping
*)
437 htab_find (subst_attr_to_iter_map
, &attr
);
439 iter_name
= value
->iter_name
;
443 /* Map attribute string P to its current value. Return null if the attribute
444 isn't known. If ITERATOR_OUT is nonnull, store the associated iterator
445 there. Report any errors against location LOC. */
447 static struct map_value
*
448 map_attr_string (file_location loc
, const char *p
, mapping
**iterator_out
= 0)
451 struct mapping
*iterator
;
455 int iterator_name_len
;
456 struct map_value
*res
= NULL
;
457 struct mapping
*prev
= NULL
;
459 /* Peel off any "iterator:" prefix. Set ATTR to the start of the
461 attr
= strchr (p
, ':');
464 iterator_name_len
= -1;
469 iterator_name_len
= attr
- p
;
473 FOR_EACH_VEC_ELT (current_iterators
, i
, iterator
)
475 /* If an iterator name was specified, check that it matches. */
476 if (iterator_name_len
>= 0
477 && (strncmp (p
, iterator
->name
, iterator_name_len
) != 0
478 || iterator
->name
[iterator_name_len
] != 0))
481 if (iterator
->group
->has_self_attr
482 && strcmp (attr
, iterator
->name
) == 0)
485 *iterator_out
= iterator
;
486 int number
= iterator
->current_value
->number
;
487 const char *string
= iterator
->group
->get_c_token (number
);
488 if (res
&& strcmp (string
, res
->string
) != 0)
490 error_at (loc
, "ambiguous attribute '%s'; could be"
491 " '%s' (via '%s:%s') or '%s' (via '%s:%s')",
492 attr
, res
->string
, prev
->name
, attr
,
493 string
, iterator
->name
, attr
);
497 res
= new map_value
{ nullptr, number
, string
};
500 /* Find the attribute specification. */
501 m
= (struct mapping
*) htab_find (iterator
->group
->attrs
, &attr
);
504 /* In contrast to code/mode/int iterators, attributes of subst
505 iterators are linked to one specific subst-iterator. So, if
506 we are dealing with subst-iterator, we should check if it's
507 the one which linked with the given attribute. */
508 if (iterator
->group
== &substs
)
510 char *iter_name
= find_subst_iter_by_attr (attr
);
511 if (strcmp (iter_name
, iterator
->name
) != 0)
514 /* Find the attribute value associated with the current
516 for (v
= m
->values
; v
; v
= v
->next
)
517 if (v
->number
== iterator
->current_value
->number
)
519 if (res
&& strcmp (v
->string
, res
->string
) != 0)
521 error_at (loc
, "ambiguous attribute '%s'; could be"
522 " '%s' (via '%s:%s') or '%s' (via '%s:%s')",
523 attr
, res
->string
, prev
->name
, attr
,
524 v
->string
, iterator
->name
, attr
);
528 *iterator_out
= iterator
;
537 /* Apply the current iterator values to STRING. Return the new string
538 if any changes were needed, otherwise return STRING itself. */
541 md_reader::apply_iterator_to_string (const char *string
)
543 char *base
, *copy
, *p
, *start
, *end
;
546 if (string
== 0 || string
[0] == 0)
549 file_location loc
= get_md_ptr_loc (string
)->loc
;
550 base
= p
= copy
= ASTRDUP (string
);
551 while ((start
= strchr (p
, '<')) && (end
= strchr (start
, '>')))
556 v
= map_attr_string (loc
, p
);
561 /* Add everything between the last copied byte and the '<',
562 then add in the attribute value. */
563 obstack_grow (&m_string_obstack
, base
, start
- base
);
564 obstack_grow (&m_string_obstack
, v
->string
, strlen (v
->string
));
569 obstack_grow (&m_string_obstack
, base
, strlen (base
) + 1);
570 copy
= XOBFINISH (&m_string_obstack
, char *);
571 copy_md_ptr_loc (copy
, string
);
577 /* Return a deep copy of X, substituting the current iterator
578 values into any strings. */
581 md_reader::copy_rtx_for_iterators (rtx original
)
583 const char *format_ptr
, *p
;
590 /* Create a shallow copy of ORIGINAL. */
591 x
= rtx_alloc (GET_CODE (original
));
592 memcpy (x
, original
, RTX_CODE_SIZE (GET_CODE (original
)));
594 /* Change each string and recursively change each rtx. */
595 format_ptr
= GET_RTX_FORMAT (GET_CODE (original
));
596 for (i
= 0; format_ptr
[i
] != 0; i
++)
597 switch (format_ptr
[i
])
600 while (XTMPL (x
, i
) != (p
= apply_iterator_to_string (XTMPL (x
, i
))))
606 while (XSTR (x
, i
) != (p
= apply_iterator_to_string (XSTR (x
, i
))))
611 XEXP (x
, i
) = copy_rtx_for_iterators (XEXP (x
, i
));
616 if (XVEC (original
, i
))
618 XVEC (x
, i
) = rtvec_alloc (XVECLEN (original
, i
));
619 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
621 = copy_rtx_for_iterators (XVECEXP (original
, i
, j
));
631 #ifdef GENERATOR_FILE
633 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
634 has the form "&& ..." (as used in define_insn_and_splits), assume that
635 EXTRA is already satisfied. Empty strings are treated like "true". */
638 add_condition_to_string (const char *original
, const char *extra
)
640 if (original
!= 0 && original
[0] == '&' && original
[1] == '&')
642 return rtx_reader_ptr
->join_c_conditions (original
, extra
);
645 /* Like add_condition, but applied to all conditions in rtx X. */
648 add_condition_to_rtx (rtx x
, const char *extra
)
650 switch (GET_CODE (x
))
655 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
659 case DEFINE_PEEPHOLE
:
660 case DEFINE_PEEPHOLE2
:
661 case DEFINE_COND_EXEC
:
662 XSTR (x
, 1) = add_condition_to_string (XSTR (x
, 1), extra
);
665 case DEFINE_INSN_AND_SPLIT
:
666 case DEFINE_INSN_AND_REWRITE
:
667 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
668 XSTR (x
, 4) = add_condition_to_string (XSTR (x
, 4), extra
);
676 /* Apply the current iterator values to all attribute_uses. */
679 apply_attribute_uses (void)
685 FOR_EACH_VEC_ELT (attribute_uses
, i
, ause
)
687 v
= map_attr_string (ause
->loc
, ause
->value
);
689 fatal_with_file_and_line ("unknown iterator value `%s'", ause
->value
);
690 ause
->group
->apply_iterator (ause
->x
, ause
->index
,
691 ause
->group
->find_builtin (v
->string
));
695 /* A htab_traverse callback for iterators. Add all used iterators
696 to current_iterators. */
699 add_current_iterators (void **slot
, void *data ATTRIBUTE_UNUSED
)
701 struct mapping
*iterator
;
703 iterator
= (struct mapping
*) *slot
;
704 if (iterator
->current_value
)
705 current_iterators
.safe_push (iterator
);
709 /* Return a hash value for overloaded_name UNCAST_ONAME. There shouldn't
710 be many instances of two overloaded_names having the same name but
711 different arguments, so hashing on the name should be good enough in
715 overloaded_name_hash (const void *uncast_oname
)
717 const overloaded_name
*oname
= (const overloaded_name
*) uncast_oname
;
718 return htab_hash_string (oname
->name
);
721 /* Return true if two overloaded_names are similar enough to share
722 the same generated functions. */
725 overloaded_name_eq_p (const void *uncast_oname1
, const void *uncast_oname2
)
727 const overloaded_name
*oname1
= (const overloaded_name
*) uncast_oname1
;
728 const overloaded_name
*oname2
= (const overloaded_name
*) uncast_oname2
;
729 if (strcmp (oname1
->name
, oname2
->name
) != 0
730 || oname1
->arg_types
.length () != oname2
->arg_types
.length ())
733 for (unsigned int i
= 0; i
< oname1
->arg_types
.length (); ++i
)
734 if (strcmp (oname1
->arg_types
[i
], oname2
->arg_types
[i
]) != 0)
740 /* Return true if X has an instruction name in XSTR (X, 0). */
745 switch (GET_CODE (x
))
749 case DEFINE_INSN_AND_SPLIT
:
750 case DEFINE_INSN_AND_REWRITE
:
758 /* Check whether ORIGINAL is a named pattern whose name starts with '@'.
759 If so, return the associated overloaded_name and add the iterator for
760 each argument to ITERATORS. Return null otherwise. */
763 md_reader::handle_overloaded_name (rtx original
, vec
<mapping
*> *iterators
)
765 /* Check for the leading '@'. */
766 if (!named_rtx_p (original
) || XSTR (original
, 0)[0] != '@')
769 /* Remove the '@', so that no other code needs to worry about it. */
770 const char *name
= XSTR (original
, 0);
771 file_location loc
= get_md_ptr_loc (name
)->loc
;
772 copy_md_ptr_loc (name
+ 1, name
);
774 XSTR (original
, 0) = name
;
776 /* Build a copy of the name without the '<...>' attribute strings.
777 Add the iterator associated with each such attribute string to ITERATORS
778 and add an associated argument to TMP_ONAME. */
779 char *copy
= ASTRDUP (name
);
780 char *base
= copy
, *start
, *end
;
781 overloaded_name tmp_oname
;
782 tmp_oname
.arg_types
.create (current_iterators
.length ());
783 bool pending_underscore_p
= false;
784 while ((start
= strchr (base
, '<')) && (end
= strchr (start
, '>')))
788 if (!map_attr_string (loc
, start
+ 1, &iterator
))
789 fatal_with_file_and_line ("unknown iterator `%s'", start
+ 1);
792 /* Remove a trailing underscore, so that we don't end a name
793 with "_" or turn "_<...>_" into "__". */
794 if (start
!= base
&& start
[-1] == '_')
797 pending_underscore_p
= true;
800 /* Add the text between either the last '>' or the start of
801 the string and this '<'. */
802 obstack_grow (&m_string_obstack
, base
, start
- base
);
805 /* If there's a character we need to keep after the '>', check
806 whether we should prefix it with a previously-dropped '_'. */
807 if (base
[0] != 0 && base
[0] != '<')
809 if (pending_underscore_p
&& base
[0] != '_')
810 obstack_1grow (&m_string_obstack
, '_');
811 pending_underscore_p
= false;
814 /* Record an argument for ITERATOR. */
815 iterators
->safe_push (iterator
);
816 tmp_oname
.arg_types
.safe_push (iterator
->group
->type
);
819 fatal_with_file_and_line ("no iterator attributes in name `%s'", name
);
821 size_t length
= obstack_object_size (&m_string_obstack
);
823 fatal_with_file_and_line ("`%s' only contains iterator attributes", name
);
825 /* Get the completed name. */
826 obstack_grow (&m_string_obstack
, base
, strlen (base
) + 1);
827 char *new_name
= XOBFINISH (&m_string_obstack
, char *);
828 tmp_oname
.name
= new_name
;
830 if (!m_overloads_htab
)
831 m_overloads_htab
= htab_create (31, overloaded_name_hash
,
832 overloaded_name_eq_p
, NULL
);
834 /* See whether another pattern had the same overload name and list
835 of argument types. Create a new permanent one if not. */
836 void **slot
= htab_find_slot (m_overloads_htab
, &tmp_oname
, INSERT
);
837 overloaded_name
*oname
= (overloaded_name
*) *slot
;
840 *slot
= oname
= new overloaded_name
;
841 oname
->name
= tmp_oname
.name
;
842 oname
->arg_types
= tmp_oname
.arg_types
;
844 oname
->first_instance
= NULL
;
845 oname
->next_instance_ptr
= &oname
->first_instance
;
847 *m_next_overload_ptr
= oname
;
848 m_next_overload_ptr
= &oname
->next
;
852 obstack_free (&m_string_obstack
, new_name
);
853 tmp_oname
.arg_types
.release ();
859 /* Add an instance of ONAME for instruction pattern X. ITERATORS[I]
860 gives the iterator associated with argument I of ONAME. */
863 add_overload_instance (overloaded_name
*oname
, const vec
<mapping
*> &iterators
, rtx x
)
865 /* Create the instance. */
866 overloaded_instance
*instance
= new overloaded_instance
;
867 instance
->next
= NULL
;
868 instance
->arg_values
.create (oname
->arg_types
.length ());
869 for (unsigned int i
= 0; i
< iterators
.length (); ++i
)
871 int value
= iterators
[i
]->current_value
->number
;
872 const char *name
= iterators
[i
]->group
->get_c_token (value
);
873 instance
->arg_values
.quick_push (name
);
875 instance
->name
= XSTR (x
, 0);
878 /* Chain it onto the end of ONAME's list. */
879 *oname
->next_instance_ptr
= instance
;
880 oname
->next_instance_ptr
= &instance
->next
;
883 /* Expand all iterators in the current rtx, which is given as ORIGINAL.
884 Build a list of expanded rtxes in the EXPR_LIST pointed to by QUEUE. */
887 apply_iterators (rtx original
, vec
<rtx
> *queue
)
890 const char *condition
;
892 struct mapping
*iterator
;
896 if (iterator_uses
.is_empty ())
898 /* Raise an error if any attributes were used. */
899 apply_attribute_uses ();
901 if (named_rtx_p (original
) && XSTR (original
, 0)[0] == '@')
902 fatal_with_file_and_line ("'@' used without iterators");
904 queue
->safe_push (original
);
908 /* Clear out the iterators from the previous run. */
909 FOR_EACH_VEC_ELT (current_iterators
, i
, iterator
)
910 iterator
->current_value
= NULL
;
911 current_iterators
.truncate (0);
913 /* Mark the iterators that we need this time. */
914 FOR_EACH_VEC_ELT (iterator_uses
, i
, iuse
)
915 iuse
->iterator
->current_value
= iuse
->iterator
->values
;
917 /* Get the list of iterators that are in use, preserving the
918 definition order within each group. */
919 htab_traverse (modes
.iterators
, add_current_iterators
, NULL
);
920 htab_traverse (codes
.iterators
, add_current_iterators
, NULL
);
921 htab_traverse (ints
.iterators
, add_current_iterators
, NULL
);
922 htab_traverse (substs
.iterators
, add_current_iterators
, NULL
);
923 gcc_assert (!current_iterators
.is_empty ());
925 /* Check whether this is a '@' overloaded pattern. */
926 auto_vec
<mapping
*, 16> iterators
;
927 overloaded_name
*oname
928 = rtx_reader_ptr
->handle_overloaded_name (original
, &iterators
);
932 /* Apply the current iterator values. Accumulate a condition to
933 say when the resulting rtx can be used. */
935 FOR_EACH_VEC_ELT (iterator_uses
, i
, iuse
)
937 if (iuse
->iterator
->group
== &substs
)
939 v
= iuse
->iterator
->current_value
;
940 iuse
->iterator
->group
->apply_iterator (iuse
->x
, iuse
->index
,
942 condition
= rtx_reader_ptr
->join_c_conditions (condition
, v
->string
);
944 apply_attribute_uses ();
945 x
= rtx_reader_ptr
->copy_rtx_for_iterators (original
);
946 add_condition_to_rtx (x
, condition
);
948 /* We apply subst iterator after RTL-template is copied, as during
949 subst-iterator processing, we could add an attribute to the
950 RTL-template, and we don't want to do it in the original one. */
951 FOR_EACH_VEC_ELT (iterator_uses
, i
, iuse
)
953 v
= iuse
->iterator
->current_value
;
954 if (iuse
->iterator
->group
== &substs
)
958 current_iterator_name
= iuse
->iterator
->name
;
959 iuse
->iterator
->group
->apply_iterator (iuse
->x
, iuse
->index
,
965 add_overload_instance (oname
, iterators
, x
);
967 /* Add the new rtx to the end of the queue. */
968 queue
->safe_push (x
);
970 /* Lexicographically increment the iterator value sequence.
971 That is, cycle through iterator values, starting from the right,
972 and stopping when one of them doesn't wrap around. */
973 i
= current_iterators
.length ();
979 iterator
= current_iterators
[i
];
980 iterator
->current_value
= iterator
->current_value
->next
;
981 if (iterator
->current_value
)
983 iterator
->current_value
= iterator
->values
;
987 #endif /* #ifdef GENERATOR_FILE */
989 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
990 of the mapping and GROUP is the group to which it belongs. */
992 static struct mapping
*
993 add_mapping (struct iterator_group
*group
, htab_t table
, const char *name
)
998 m
= XNEW (struct mapping
);
999 m
->name
= xstrdup (name
);
1002 m
->current_value
= NULL
;
1004 slot
= htab_find_slot (table
, m
, INSERT
);
1006 fatal_with_file_and_line ("`%s' already defined", name
);
1012 /* Add the pair (NUMBER, STRING) to a list of map_value structures.
1013 END_PTR points to the current null terminator for the list; return
1014 a pointer the new null terminator. */
1016 static struct map_value
**
1017 add_map_value (struct map_value
**end_ptr
, int number
, const char *string
)
1019 struct map_value
*value
;
1021 value
= XNEW (struct map_value
);
1023 value
->number
= number
;
1024 value
->string
= string
;
1027 return &value
->next
;
1030 /* Do one-time initialization of the mode and code attributes. */
1033 initialize_iterators (void)
1035 struct mapping
*lower
, *upper
;
1036 struct map_value
**lower_ptr
, **upper_ptr
;
1040 modes
.attrs
= htab_create (13, leading_string_hash
, leading_string_eq_p
, 0);
1041 modes
.iterators
= htab_create (13, leading_string_hash
,
1042 leading_string_eq_p
, 0);
1043 modes
.type
= "machine_mode";
1044 modes
.find_builtin
= find_mode
;
1045 modes
.apply_iterator
= apply_mode_iterator
;
1046 modes
.get_c_token
= get_mode_token
;
1048 codes
.attrs
= htab_create (13, leading_string_hash
, leading_string_eq_p
, 0);
1049 codes
.iterators
= htab_create (13, leading_string_hash
,
1050 leading_string_eq_p
, 0);
1051 codes
.type
= "rtx_code";
1052 codes
.find_builtin
= find_code
;
1053 codes
.apply_iterator
= apply_code_iterator
;
1054 codes
.get_c_token
= get_code_token
;
1056 ints
.attrs
= htab_create (13, leading_string_hash
, leading_string_eq_p
, 0);
1057 ints
.iterators
= htab_create (13, leading_string_hash
,
1058 leading_string_eq_p
, 0);
1060 ints
.find_builtin
= find_int
;
1061 ints
.apply_iterator
= apply_int_iterator
;
1062 ints
.get_c_token
= get_int_token
;
1063 ints
.has_self_attr
= true;
1065 substs
.attrs
= htab_create (13, leading_string_hash
, leading_string_eq_p
, 0);
1066 substs
.iterators
= htab_create (13, leading_string_hash
,
1067 leading_string_eq_p
, 0);
1068 substs
.type
= "int";
1069 substs
.find_builtin
= find_int
; /* We don't use it, anyway. */
1070 #ifdef GENERATOR_FILE
1071 substs
.apply_iterator
= apply_subst_iterator
;
1073 substs
.get_c_token
= get_int_token
;
1075 lower
= add_mapping (&modes
, modes
.attrs
, "mode");
1076 upper
= add_mapping (&modes
, modes
.attrs
, "MODE");
1077 lower_ptr
= &lower
->values
;
1078 upper_ptr
= &upper
->values
;
1079 for (i
= 0; i
< MAX_MACHINE_MODE
; i
++)
1081 copy
= xstrdup (GET_MODE_NAME (i
));
1082 for (p
= copy
; *p
!= 0; p
++)
1085 upper_ptr
= add_map_value (upper_ptr
, i
, GET_MODE_NAME (i
));
1086 lower_ptr
= add_map_value (lower_ptr
, i
, copy
);
1089 lower
= add_mapping (&codes
, codes
.attrs
, "code");
1090 upper
= add_mapping (&codes
, codes
.attrs
, "CODE");
1091 lower_ptr
= &lower
->values
;
1092 upper_ptr
= &upper
->values
;
1093 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
1095 copy
= xstrdup (GET_RTX_NAME (i
));
1096 for (p
= copy
; *p
!= 0; p
++)
1099 lower_ptr
= add_map_value (lower_ptr
, i
, GET_RTX_NAME (i
));
1100 upper_ptr
= add_map_value (upper_ptr
, i
, copy
);
1105 #ifdef GENERATOR_FILE
1106 /* Process a define_conditions directive, starting with the optional
1107 space after the "define_conditions". The directive looks like this:
1109 (define_conditions [
1115 It's not intended to appear in machine descriptions. It is
1116 generated by (the program generated by) genconditions.cc, and
1117 slipped in at the beginning of the sequence of MD files read by
1118 most of the other generators. */
1120 md_reader::read_conditions ()
1124 require_char_ws ('[');
1126 while ( (c
= read_skip_spaces ()) != ']')
1128 struct md_name name
;
1133 fatal_expected_char ('(', c
);
1136 validate_const_int (name
.string
);
1137 value
= atoi (name
.string
);
1139 require_char_ws ('"');
1140 expr
= read_quoted_string ();
1142 require_char_ws (')');
1144 add_c_test (expr
, value
);
1147 #endif /* #ifdef GENERATOR_FILE */
1150 validate_const_int (const char *string
)
1156 while (*cp
&& ISSPACE (*cp
))
1158 if (*cp
== '-' || *cp
== '+')
1163 if (! ISDIGIT (*cp
))
1169 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string
);
1173 validate_const_wide_int (const char *string
)
1179 while (*cp
&& ISSPACE (*cp
))
1181 /* Skip the leading 0x. */
1182 if (cp
[0] == '0' || cp
[1] == 'x')
1189 if (! ISXDIGIT (*cp
))
1192 fatal_with_file_and_line ("invalid hex constant \"%s\"\n", string
);
1195 /* Record that X uses iterator ITERATOR. If the use is in an operand
1196 of X, INDEX is the index of that operand, otherwise it is ignored. */
1199 record_iterator_use (struct mapping
*iterator
, rtx x
, unsigned int index
)
1201 struct iterator_use iuse
= {iterator
, x
, index
};
1202 iterator_uses
.safe_push (iuse
);
1205 /* Record that X uses attribute VALUE at location LOC, where VALUE must
1206 match a built-in value from group GROUP. If the use is in an operand
1207 of X, INDEX is the index of that operand, otherwise it is ignored. */
1210 record_attribute_use (struct iterator_group
*group
, file_location loc
, rtx x
,
1211 unsigned int index
, const char *value
)
1213 struct attribute_use ause
= {group
, loc
, value
, x
, index
};
1214 attribute_uses
.safe_push (ause
);
1217 /* Interpret NAME as either a built-in value, iterator or attribute
1218 for group GROUP. X and INDEX are the values to pass to GROUP's
1219 apply_iterator callback. LOC is the location of the use. */
1222 md_reader::record_potential_iterator_use (struct iterator_group
*group
,
1224 rtx x
, unsigned int index
,
1230 len
= strlen (name
);
1231 if (name
[0] == '<' && name
[len
- 1] == '>')
1233 /* Copy the attribute string into permanent storage, without the
1234 angle brackets around it. */
1235 obstack_grow0 (&m_string_obstack
, name
+ 1, len
- 2);
1236 record_attribute_use (group
, loc
, x
, index
,
1237 XOBFINISH (&m_string_obstack
, char *));
1241 m
= (struct mapping
*) htab_find (group
->iterators
, &name
);
1243 record_iterator_use (m
, x
, index
);
1245 group
->apply_iterator (x
, index
, group
->find_builtin (name
));
1249 #ifdef GENERATOR_FILE
1251 /* Finish reading a declaration of the form:
1253 (define... <name> [<value1> ... <valuen>])
1255 from the MD file, where each <valuei> is either a bare symbol name or a
1256 "(<name> <string>)" pair. The "(define..." part has already been read.
1258 Represent the declaration as a "mapping" structure; add it to TABLE
1259 (which belongs to GROUP) and return it. */
1262 md_reader::read_mapping (struct iterator_group
*group
, htab_t table
)
1264 struct md_name name
;
1266 struct map_value
**end_ptr
;
1270 /* Read the mapping name and create a structure for it. */
1272 m
= add_mapping (group
, table
, name
.string
);
1274 require_char_ws ('[');
1276 /* Read each value. */
1277 end_ptr
= &m
->values
;
1278 c
= read_skip_spaces ();
1283 /* A bare symbol name that is implicitly paired to an
1291 /* A "(name string)" pair. */
1293 string
= read_string (false);
1294 require_char_ws (')');
1296 number
= group
->find_builtin (name
.string
);
1297 end_ptr
= add_map_value (end_ptr
, number
, string
);
1298 c
= read_skip_spaces ();
1305 /* For iterator with name ATTR_NAME generate define_attr with values
1306 'yes' and 'no'. This attribute is used to mark templates to which
1307 define_subst ATTR_NAME should be applied. This attribute is set and
1308 defined implicitly and automatically. */
1310 add_define_attr_for_define_subst (const char *attr_name
, vec
<rtx
> *queue
)
1312 rtx const_str
, return_rtx
;
1314 return_rtx
= rtx_alloc (DEFINE_ATTR
);
1315 PUT_CODE (return_rtx
, DEFINE_ATTR
);
1317 const_str
= rtx_alloc (CONST_STRING
);
1318 PUT_CODE (const_str
, CONST_STRING
);
1319 XSTR (const_str
, 0) = xstrdup ("no");
1321 XSTR (return_rtx
, 0) = xstrdup (attr_name
);
1322 XSTR (return_rtx
, 1) = xstrdup ("no,yes");
1323 XEXP (return_rtx
, 2) = const_str
;
1325 queue
->safe_push (return_rtx
);
1328 /* This routine generates DEFINE_SUBST_ATTR expression with operands
1329 ATTR_OPERANDS and places it to QUEUE. */
1331 add_define_subst_attr (const char **attr_operands
, vec
<rtx
> *queue
)
1336 return_rtx
= rtx_alloc (DEFINE_SUBST_ATTR
);
1337 PUT_CODE (return_rtx
, DEFINE_SUBST_ATTR
);
1339 for (i
= 0; i
< 4; i
++)
1340 XSTR (return_rtx
, i
) = xstrdup (attr_operands
[i
]);
1342 queue
->safe_push (return_rtx
);
1345 /* Read define_subst_attribute construction. It has next form:
1346 (define_subst_attribute <attribute_name> <iterator_name> <value1> <value2>)
1347 Attribute is substituted with value1 when no subst is applied and with
1348 value2 in the opposite case.
1349 Attributes are added to SUBST_ATTRS_TABLE.
1350 In case the iterator is encountered for the first time, it's added to
1351 SUBST_ITERS_TABLE. Also, implicit define_attr is generated. */
1354 read_subst_mapping (htab_t subst_iters_table
, htab_t subst_attrs_table
,
1358 struct map_value
**end_ptr
;
1359 const char *attr_operands
[4];
1362 for (i
= 0; i
< 4; i
++)
1363 attr_operands
[i
] = rtx_reader_ptr
->read_string (false);
1365 add_define_subst_attr (attr_operands
, queue
);
1367 bind_subst_iter_and_attr (attr_operands
[1], attr_operands
[0]);
1369 m
= (struct mapping
*) htab_find (substs
.iterators
, &attr_operands
[1]);
1372 m
= add_mapping (&substs
, subst_iters_table
, attr_operands
[1]);
1373 end_ptr
= &m
->values
;
1374 end_ptr
= add_map_value (end_ptr
, 1, "");
1375 add_map_value (end_ptr
, 2, "");
1377 add_define_attr_for_define_subst (attr_operands
[1], queue
);
1380 m
= add_mapping (&substs
, subst_attrs_table
, attr_operands
[0]);
1381 end_ptr
= &m
->values
;
1382 end_ptr
= add_map_value (end_ptr
, 1, attr_operands
[2]);
1383 add_map_value (end_ptr
, 2, attr_operands
[3]);
1386 /* Check newly-created code iterator ITERATOR to see whether every code has the
1390 check_code_iterator (struct mapping
*iterator
)
1392 struct map_value
*v
;
1393 enum rtx_code bellwether
;
1395 bellwether
= (enum rtx_code
) iterator
->values
->number
;
1396 for (v
= iterator
->values
->next
; v
!= 0; v
= v
->next
)
1397 if (strcmp (GET_RTX_FORMAT (bellwether
), GET_RTX_FORMAT (v
->number
)) != 0)
1398 fatal_with_file_and_line ("code iterator `%s' combines "
1399 "`%s' and `%s', which have different "
1400 "rtx formats", iterator
->name
,
1401 GET_RTX_NAME (bellwether
),
1402 GET_RTX_NAME (v
->number
));
1405 /* Check that all values of attribute ATTR are rtx codes that have a
1406 consistent format. Return a representative code. */
1409 check_code_attribute (mapping
*attr
)
1411 rtx_code bellwether
= UNKNOWN
;
1412 for (map_value
*v
= attr
->values
; v
!= 0; v
= v
->next
)
1414 rtx_code code
= maybe_find_code (v
->string
);
1415 if (code
== UNKNOWN
)
1416 fatal_with_file_and_line ("code attribute `%s' contains "
1417 "unrecognized rtx code `%s'",
1418 attr
->name
, v
->string
);
1419 if (bellwether
== UNKNOWN
)
1421 else if (strcmp (GET_RTX_FORMAT (bellwether
),
1422 GET_RTX_FORMAT (code
)) != 0)
1423 fatal_with_file_and_line ("code attribute `%s' combines "
1424 "`%s' and `%s', which have different "
1425 "rtx formats", attr
->name
,
1426 GET_RTX_NAME (bellwether
),
1427 GET_RTX_NAME (code
));
1432 /* Read an rtx-related declaration from the MD file, given that it
1433 starts with directive name RTX_NAME. Return true if it expands to
1434 one or more rtxes (as defined by rtx.def). When returning true,
1435 store the list of rtxes as an EXPR_LIST in *X. */
1438 rtx_reader::read_rtx (const char *rtx_name
, vec
<rtx
> *rtxen
)
1440 /* Handle various rtx-related declarations that aren't themselves
1441 encoded as rtxes. */
1442 if (strcmp (rtx_name
, "define_conditions") == 0)
1447 if (strcmp (rtx_name
, "define_mode_attr") == 0)
1449 read_mapping (&modes
, modes
.attrs
);
1452 if (strcmp (rtx_name
, "define_mode_iterator") == 0)
1454 read_mapping (&modes
, modes
.iterators
);
1457 if (strcmp (rtx_name
, "define_code_attr") == 0)
1459 read_mapping (&codes
, codes
.attrs
);
1462 if (strcmp (rtx_name
, "define_code_iterator") == 0)
1464 check_code_iterator (read_mapping (&codes
, codes
.iterators
));
1467 if (strcmp (rtx_name
, "define_int_attr") == 0)
1469 read_mapping (&ints
, ints
.attrs
);
1472 if (strcmp (rtx_name
, "define_int_iterator") == 0)
1474 read_mapping (&ints
, ints
.iterators
);
1477 if (strcmp (rtx_name
, "define_subst_attr") == 0)
1479 read_subst_mapping (substs
.iterators
, substs
.attrs
, rtxen
);
1481 /* READ_SUBST_MAPPING could generate a new DEFINE_ATTR. Return
1482 TRUE to process it. */
1486 apply_iterators (rtx_reader_ptr
->read_rtx_code (rtx_name
), rtxen
);
1487 iterator_uses
.truncate (0);
1488 attribute_uses
.truncate (0);
1493 #endif /* #ifdef GENERATOR_FILE */
1495 /* Do one-time initialization. */
1498 one_time_initialization (void)
1500 static bool initialized
= false;
1504 initialize_iterators ();
1509 /* Consume characters until encountering a character in TERMINATOR_CHARS,
1510 consuming the terminator character if CONSUME_TERMINATOR is true.
1511 Return all characters before the terminator as an allocated buffer. */
1514 rtx_reader::read_until (const char *terminator_chars
, bool consume_terminator
)
1516 int ch
= read_skip_spaces ();
1522 if (strchr (terminator_chars
, ch
))
1524 if (!consume_terminator
)
1530 buf
.safe_push ('\0');
1531 return xstrdup (buf
.address ());
1534 /* Subroutine of read_rtx_code, for parsing zero or more flags. */
1537 read_flags (rtx return_rtx
)
1541 int ch
= read_char ();
1548 int flag_char
= read_char ();
1552 RTX_FLAG (return_rtx
, in_struct
) = 1;
1555 RTX_FLAG (return_rtx
, volatil
) = 1;
1558 RTX_FLAG (return_rtx
, unchanging
) = 1;
1561 RTX_FLAG (return_rtx
, frame_related
) = 1;
1564 RTX_FLAG (return_rtx
, jump
) = 1;
1567 RTX_FLAG (return_rtx
, call
) = 1;
1570 RTX_FLAG (return_rtx
, return_val
) = 1;
1573 fatal_with_file_and_line ("unrecognized flag: `%c'", flag_char
);
1578 /* Return the numeric value n for GET_REG_NOTE_NAME (n) for STRING,
1579 or fail if STRING isn't recognized. */
1582 parse_reg_note_name (const char *string
)
1584 for (int i
= 0; i
< REG_NOTE_MAX
; i
++)
1585 if (strcmp (string
, GET_REG_NOTE_NAME (i
)) == 0)
1587 fatal_with_file_and_line ("unrecognized REG_NOTE name: `%s'", string
);
1590 /* Allocate an rtx for code NAME. If NAME is a code iterator or code
1591 attribute, record its use for later and use one of its possible
1592 values as an interim rtx code. */
1595 rtx_reader::rtx_alloc_for_name (const char *name
)
1597 #ifdef GENERATOR_FILE
1598 size_t len
= strlen (name
);
1599 if (name
[0] == '<' && name
[len
- 1] == '>')
1601 /* Copy the attribute string into permanent storage, without the
1602 angle brackets around it. */
1603 obstack
*strings
= get_string_obstack ();
1604 obstack_grow0 (strings
, name
+ 1, len
- 2);
1605 char *deferred_name
= XOBFINISH (strings
, char *);
1607 /* Find the name of the attribute. */
1608 const char *attr
= strchr (deferred_name
, ':');
1610 attr
= deferred_name
;
1612 /* Find the attribute itself. */
1613 mapping
*m
= (mapping
*) htab_find (codes
.attrs
, &attr
);
1615 fatal_with_file_and_line ("unknown code attribute `%s'", attr
);
1617 /* Pick the first possible code for now, and record the attribute
1619 rtx x
= rtx_alloc (check_code_attribute (m
));
1620 record_attribute_use (&codes
, get_current_location (),
1621 x
, 0, deferred_name
);
1625 mapping
*iterator
= (mapping
*) htab_find (codes
.iterators
, &name
);
1628 /* Pick the first possible code for now, and record the iterator
1630 rtx x
= rtx_alloc (rtx_code (iterator
->values
->number
));
1631 record_iterator_use (iterator
, x
, 0);
1636 return rtx_alloc (rtx_code (codes
.find_builtin (name
)));
1639 /* Subroutine of read_rtx and read_nested_rtx. CODE_NAME is the name of
1640 either an rtx code or a code iterator. Parse the rest of the rtx and
1644 rtx_reader::read_rtx_code (const char *code_name
)
1647 const char *format_ptr
;
1648 struct md_name name
;
1653 /* Linked list structure for making RTXs: */
1656 struct rtx_list
*next
;
1657 rtx value
; /* Value of this node. */
1660 /* Handle reuse_rtx ids e.g. "(0|scratch:DI)". */
1661 if (ISDIGIT (code_name
[0]))
1663 reuse_id
= atoi (code_name
);
1664 while (char ch
= *code_name
++)
1669 /* Handle "reuse_rtx". */
1670 if (strcmp (code_name
, "reuse_rtx") == 0)
1673 unsigned idx
= atoi (name
.string
);
1674 /* Look it up by ID. */
1675 gcc_assert (idx
< m_reuse_rtx_by_id
.length ());
1676 return_rtx
= m_reuse_rtx_by_id
[idx
];
1680 /* Handle "const_double_zero". */
1681 if (strcmp (code_name
, "const_double_zero") == 0)
1683 code
= CONST_DOUBLE
;
1684 return_rtx
= rtx_alloc (code
);
1685 memset (return_rtx
, 0, RTX_CODE_SIZE (code
));
1686 PUT_CODE (return_rtx
, code
);
1687 c
= read_skip_spaces ();
1690 file_location loc
= read_name (&name
);
1691 record_potential_iterator_use (&modes
, loc
, return_rtx
, 0,
1699 /* If we end up with an insn expression then we free this space below. */
1700 return_rtx
= rtx_alloc_for_name (code_name
);
1701 code
= GET_CODE (return_rtx
);
1702 format_ptr
= GET_RTX_FORMAT (code
);
1703 memset (return_rtx
, 0, RTX_CODE_SIZE (code
));
1704 PUT_CODE (return_rtx
, code
);
1708 /* Store away for later reuse. */
1709 m_reuse_rtx_by_id
.safe_grow_cleared (reuse_id
+ 1, true);
1710 m_reuse_rtx_by_id
[reuse_id
] = return_rtx
;
1713 /* Check for flags. */
1714 read_flags (return_rtx
);
1716 /* Read REG_NOTE names for EXPR_LIST and INSN_LIST. */
1717 if ((GET_CODE (return_rtx
) == EXPR_LIST
1718 || GET_CODE (return_rtx
) == INSN_LIST
1719 || GET_CODE (return_rtx
) == INT_LIST
)
1720 && !m_in_call_function_usage
)
1722 char ch
= read_char ();
1726 PUT_MODE_RAW (return_rtx
,
1727 (machine_mode
)parse_reg_note_name (name
.string
));
1733 /* If what follows is `: mode ', read it and
1734 store the mode in the rtx. */
1736 c
= read_skip_spaces ();
1739 file_location loc
= read_name (&name
);
1740 record_potential_iterator_use (&modes
, loc
, return_rtx
, 0, name
.string
);
1745 if (INSN_CHAIN_CODE_P (code
))
1748 INSN_UID (return_rtx
) = atoi (name
.string
);
1751 /* Use the format_ptr to parse the various operands of this rtx. */
1752 for (int idx
= 0; format_ptr
[idx
] != 0; idx
++)
1753 return_rtx
= read_rtx_operand (return_rtx
, idx
);
1755 /* Handle any additional information that after the regular fields
1756 (e.g. when parsing function dumps). */
1757 handle_any_trailing_information (return_rtx
);
1759 if (CONST_WIDE_INT_P (return_rtx
))
1762 validate_const_wide_int (name
.string
);
1764 const char *s
= name
.string
;
1767 int gs
= HOST_BITS_PER_WIDE_INT
/4;
1769 char * buf
= XALLOCAVEC (char, gs
+ 1);
1770 unsigned HOST_WIDE_INT wi
;
1773 /* Skip the leading spaces. */
1774 while (*s
&& ISSPACE (*s
))
1777 /* Skip the leading 0x. */
1778 gcc_assert (s
[0] == '0');
1779 gcc_assert (s
[1] == 'x');
1784 wlen
= (len
+ gs
- 1) / gs
; /* Number of words needed */
1786 return_rtx
= const_wide_int_alloc (wlen
);
1790 #if HOST_BITS_PER_WIDE_INT == 64
1791 sscanf (s
+ pos
, "%16" HOST_WIDE_INT_PRINT
"x", &wi
);
1793 sscanf (s
+ pos
, "%8" HOST_WIDE_INT_PRINT
"x", &wi
);
1795 CWI_ELT (return_rtx
, index
++) = wi
;
1798 strncpy (buf
, s
, gs
- pos
);
1800 sscanf (buf
, "%" HOST_WIDE_INT_PRINT
"x", &wi
);
1801 CWI_ELT (return_rtx
, index
++) = wi
;
1802 /* TODO: After reading, do we want to canonicalize with:
1803 value = lookup_const_wide_int (value); ? */
1807 c
= read_skip_spaces ();
1808 /* Syntactic sugar for AND and IOR, allowing Lisp-like
1809 arbitrary number of arguments for them. */
1811 && (GET_CODE (return_rtx
) == AND
1812 || GET_CODE (return_rtx
) == IOR
))
1813 return read_rtx_variadic (return_rtx
);
1819 /* Subroutine of read_rtx_code. Parse operand IDX within RETURN_RTX,
1820 based on the corresponding format character within GET_RTX_FORMAT
1821 for the GET_CODE (RETURN_RTX), and return RETURN_RTX.
1822 This is a virtual function, so that function_reader can override
1823 some parsing, and potentially return a different rtx. */
1826 rtx_reader::read_rtx_operand (rtx return_rtx
, int idx
)
1828 RTX_CODE code
= GET_CODE (return_rtx
);
1829 const char *format_ptr
= GET_RTX_FORMAT (code
);
1831 struct md_name name
;
1833 switch (format_ptr
[idx
])
1835 /* 0 means a field for internal use only.
1836 Don't expect it to be present in the input. */
1839 ORIGINAL_REGNO (return_rtx
) = REGNO (return_rtx
);
1843 XEXP (return_rtx
, idx
) = read_nested_rtx ();
1847 XEXP (return_rtx
, idx
) = read_nested_rtx ();
1851 /* 'V' is an optional vector: if a closeparen follows,
1852 just store NULL for this element. */
1853 c
= read_skip_spaces ();
1857 XVEC (return_rtx
, idx
) = 0;
1860 /* Now process the vector. */
1865 /* Obstack to store scratch vector in. */
1866 struct obstack vector_stack
;
1867 int list_counter
= 0;
1868 rtvec return_vec
= NULL_RTVEC
;
1869 rtx saved_rtx
= NULL_RTX
;
1871 require_char_ws ('[');
1873 /* Add expressions to a list, while keeping a count. */
1874 obstack_init (&vector_stack
);
1875 while ((c
= read_skip_spaces ()) && c
!= ']')
1878 fatal_expected_char (']', c
);
1882 int repeat_count
= 1;
1885 /* Process "repeated xN" directive. */
1887 if (strcmp (name
.string
, "repeated"))
1888 fatal_with_file_and_line ("invalid directive \"%s\"\n",
1891 if (!sscanf (name
.string
, "x%d", &repeat_count
))
1892 fatal_with_file_and_line ("invalid repeat count \"%s\"\n",
1895 /* We already saw one of the instances. */
1900 value
= read_nested_rtx ();
1902 for (; repeat_count
> 0; repeat_count
--)
1905 obstack_ptr_grow (&vector_stack
, value
);
1909 if (list_counter
> 0)
1911 return_vec
= rtvec_alloc (list_counter
);
1912 memcpy (&return_vec
->elem
[0], obstack_finish (&vector_stack
),
1913 list_counter
* sizeof (rtx
));
1915 else if (format_ptr
[idx
] == 'E')
1916 fatal_with_file_and_line ("vector must have at least one element");
1917 XVEC (return_rtx
, idx
) = return_vec
;
1918 obstack_free (&vector_stack
, NULL
);
1919 /* close bracket gotten */
1930 c
= read_skip_spaces ();
1934 /* 'S' fields are optional and should be NULL if no string
1935 was given. Also allow normal 's' and 'T' strings to be
1936 omitted, treating them in the same way as empty strings. */
1937 XSTR (return_rtx
, idx
) = (format_ptr
[idx
] == 'S' ? NULL
: "");
1941 /* The output template slot of a DEFINE_INSN, DEFINE_INSN_AND_SPLIT,
1942 DEFINE_INSN_AND_REWRITE or DEFINE_PEEPHOLE automatically
1943 gets a star inserted as its first character, if it is
1944 written with a brace block instead of a string constant. */
1945 star_if_braced
= (format_ptr
[idx
] == 'T');
1947 stringbuf
= read_string (star_if_braced
);
1951 #ifdef GENERATOR_FILE
1952 /* For insn patterns, we want to provide a default name
1953 based on the file and line, like "*foo.md:12", if the
1954 given name is blank. These are only for define_insn and
1955 define_insn_and_split, to aid debugging. */
1956 if (*stringbuf
== '\0'
1958 && (GET_CODE (return_rtx
) == DEFINE_INSN
1959 || GET_CODE (return_rtx
) == DEFINE_INSN_AND_SPLIT
1960 || GET_CODE (return_rtx
) == DEFINE_INSN_AND_REWRITE
))
1962 const char *old_stringbuf
= stringbuf
;
1963 struct obstack
*string_obstack
= get_string_obstack ();
1965 const char *read_md_filename
= get_filename ();
1966 const char *fn
= (read_md_filename
? read_md_filename
: "rtx");
1968 for (slash
= fn
; *slash
; slash
++)
1969 if (*slash
== '/' || *slash
== '\\' || *slash
== ':')
1971 obstack_1grow (string_obstack
, '*');
1972 obstack_grow (string_obstack
, fn
, strlen (fn
));
1973 sprintf (line_name
, ":%d", get_lineno ());
1974 obstack_grow (string_obstack
, line_name
, strlen (line_name
)+1);
1975 stringbuf
= XOBFINISH (string_obstack
, char *);
1976 copy_md_ptr_loc (stringbuf
, old_stringbuf
);
1979 /* Find attr-names in the string. */
1981 char *start
, *end
, *ptr
;
1985 while ((start
= strchr (end
, '<')) && (end
= strchr (start
, '>')))
1987 if ((end
- start
- 1 > 0)
1988 && (end
- start
- 1 < (int)sizeof (tmpstr
)))
1990 strncpy (tmpstr
, start
+1, end
-start
-1);
1991 tmpstr
[end
-start
-1] = 0;
1997 = (struct mapping
*) htab_find (substs
.attrs
, &ptr
);
2000 /* Here we should find linked subst-iter. */
2001 str
= find_subst_iter_by_attr (ptr
);
2003 m
= (struct mapping
*) htab_find (substs
.iterators
, &str
);
2008 record_iterator_use (m
, return_rtx
, 0);
2010 #endif /* #ifdef GENERATOR_FILE */
2012 const char *string_ptr
= finalize_string (stringbuf
);
2015 XTMPL (return_rtx
, idx
) = string_ptr
;
2017 XSTR (return_rtx
, idx
) = string_ptr
;
2026 /* Can be an iterator or an integer constant. */
2027 file_location loc
= read_name (&name
);
2028 record_potential_iterator_use (&ints
, loc
, return_rtx
, idx
,
2035 validate_const_int (name
.string
);
2036 set_regno_raw (return_rtx
, atoi (name
.string
), 1);
2037 REG_ATTRS (return_rtx
) = NULL
;
2047 /* Read a nested rtx construct from the MD file and return it. */
2050 rtx_reader::read_nested_rtx ()
2052 struct md_name name
;
2055 /* In compact dumps, trailing "(nil)" values can be omitted.
2056 Handle such dumps. */
2057 if (peek_char () == ')')
2060 require_char_ws ('(');
2063 if (strcmp (name
.string
, "nil") == 0)
2066 return_rtx
= read_rtx_code (name
.string
);
2068 require_char_ws (')');
2070 return_rtx
= postprocess (return_rtx
);
2075 /* Mutually recursive subroutine of read_rtx which reads
2076 (thing x1 x2 x3 ...) and produces RTL as if
2077 (thing x1 (thing x2 (thing x3 ...))) had been written.
2078 When called, FORM is (thing x1 x2), and the file position
2079 is just past the leading parenthesis of x3. Only works
2080 for THINGs which are dyadic expressions, e.g. AND, IOR. */
2082 rtx_reader::read_rtx_variadic (rtx form
)
2091 q
= rtx_alloc (GET_CODE (p
));
2092 PUT_MODE (q
, GET_MODE (p
));
2094 XEXP (q
, 0) = XEXP (p
, 1);
2095 XEXP (q
, 1) = read_nested_rtx ();
2099 c
= read_skip_spaces ();
2106 /* Constructor for class rtx_reader. */
2108 rtx_reader::rtx_reader (bool compact
)
2109 : md_reader (compact
),
2110 m_in_call_function_usage (false)
2112 /* Set the global singleton pointer. */
2113 rtx_reader_ptr
= this;
2115 one_time_initialization ();
2118 /* Destructor for class rtx_reader. */
2120 rtx_reader::~rtx_reader ()
2122 /* Clear the global singleton pointer. */
2123 rtx_reader_ptr
= NULL
;