1 /* Generate from machine description:
2 - prototype declarations for operand predicates (tm-preds.h)
3 - function definitions of operand predicates, if defined new-style
5 Copyright (C) 2001-2024 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
31 #include "gensupport.h"
33 static char general_mem
[] = { TARGET_MEM_CONSTRAINT
, 0 };
35 /* Given a predicate expression EXP, from form NAME at location LOC,
36 verify that it does not contain any RTL constructs which are not
37 valid in predicate definitions. Returns true if EXP is
38 INvalid; issues error messages, caller need not. */
40 validate_exp (rtx exp
, const char *name
, file_location loc
)
44 message_at (loc
, "%s: must give a predicate expression", name
);
48 switch (GET_CODE (exp
))
50 /* Ternary, binary, unary expressions: recurse into subexpressions. */
52 if (validate_exp (XEXP (exp
, 2), name
, loc
))
57 if (validate_exp (XEXP (exp
, 1), name
, loc
))
61 return validate_exp (XEXP (exp
, 0), name
, loc
);
63 /* MATCH_CODE might have a syntax error in its path expression. */
67 for (p
= XSTR (exp
, 1); *p
; p
++)
69 if (!ISDIGIT (*p
) && !ISLOWER (*p
))
71 error_at (loc
, "%s: invalid character in path "
72 "string '%s'", name
, XSTR (exp
, 1));
79 /* These need no special checking. */
85 error_at (loc
, "%s: cannot use '%s' in a predicate expression",
86 name
, GET_RTX_NAME (GET_CODE (exp
)));
91 /* Predicates are defined with (define_predicate) or
92 (define_special_predicate) expressions in the machine description. */
94 process_define_predicate (md_rtx_info
*info
)
96 validate_exp (XEXP (info
->def
, 1), XSTR (info
->def
, 0), info
->loc
);
99 /* Given a predicate, if it has an embedded C block, write the block
100 out as a static inline subroutine, and augment the RTL test with a
101 match_test that calls that subroutine. For instance,
103 (define_predicate "basereg_operand"
104 (match_operand 0 "register_operand")
106 if (GET_CODE (op) == SUBREG)
107 op = SUBREG_REG (op);
108 return REG_POINTER (op);
113 static inline bool basereg_operand_1(rtx op, machine_mode mode)
115 if (GET_CODE (op) == SUBREG)
116 op = SUBREG_REG (op);
117 return REG_POINTER (op);
120 (define_predicate "basereg_operand"
121 (and (match_operand 0 "register_operand")
122 (match_test "basereg_operand_1 (op, mode)")))
124 The only wart is that there's no way to insist on a { } string in
125 an RTL template, so we have to handle "" strings. */
129 write_predicate_subfunction (struct pred_data
*p
)
131 const char *match_test_str
;
132 rtx match_test_exp
, and_exp
;
134 if (p
->c_block
[0] == '\0')
137 /* Construct the function-call expression. */
138 obstack_grow (rtl_obstack
, p
->name
, strlen (p
->name
));
139 obstack_grow (rtl_obstack
, "_1 (op, mode)",
140 sizeof "_1 (op, mode)");
141 match_test_str
= XOBFINISH (rtl_obstack
, const char *);
143 /* Add the function-call expression to the complete expression to be
145 match_test_exp
= rtx_alloc (MATCH_TEST
);
146 XSTR (match_test_exp
, 0) = match_test_str
;
148 and_exp
= rtx_alloc (AND
);
149 XEXP (and_exp
, 0) = p
->exp
;
150 XEXP (and_exp
, 1) = match_test_exp
;
154 printf ("static inline bool\n"
155 "%s_1 (rtx op ATTRIBUTE_UNUSED, machine_mode mode ATTRIBUTE_UNUSED)\n",
157 rtx_reader_ptr
->print_md_ptr_loc (p
->c_block
);
158 if (p
->c_block
[0] == '{')
159 fputs (p
->c_block
, stdout
);
161 printf ("{\n %s\n}", p
->c_block
);
162 fputs ("\n\n", stdout
);
165 /* Given a predicate expression EXP, from form NAME, determine whether
166 it refers to the variable given as VAR. */
168 needs_variable (rtx exp
, const char *var
)
170 switch (GET_CODE (exp
))
172 /* Ternary, binary, unary expressions need a variable if
173 any of their subexpressions do. */
175 if (needs_variable (XEXP (exp
, 2), var
))
180 if (needs_variable (XEXP (exp
, 1), var
))
184 return needs_variable (XEXP (exp
, 0), var
);
186 /* MATCH_CODE uses "op", but nothing else. */
188 return !strcmp (var
, "op");
190 /* MATCH_OPERAND uses "op" and may use "mode". */
192 if (!strcmp (var
, "op"))
194 if (!strcmp (var
, "mode") && GET_MODE (exp
) == VOIDmode
)
198 /* MATCH_TEST uses var if XSTR (exp, 0) =~ /\b${var}\b/o; */
201 const char *p
= XSTR (exp
, 0);
202 const char *q
= strstr (p
, var
);
205 if (q
!= p
&& (ISALNUM (q
[-1]) || q
[-1] == '_'))
208 if (ISALNUM (q
[0]) || q
[0] == '_')
218 /* Given an RTL expression EXP, find all subexpressions which we may
219 assume to perform mode tests. Normal MATCH_OPERAND does;
220 MATCH_CODE doesn't as such (although certain codes always have
221 VOIDmode); and we have to assume that MATCH_TEST does not.
222 These combine in almost-boolean fashion - the only exception is
223 that (not X) must be assumed not to perform a mode test, whether
226 The mark is the RTL /v flag, which is true for subexpressions which
227 do *not* perform mode tests.
229 #define NO_MODE_TEST(EXP) RTX_FLAG (EXP, volatil)
231 mark_mode_tests (rtx exp
)
233 switch (GET_CODE (exp
))
237 struct pred_data
*p
= lookup_predicate (XSTR (exp
, 1));
239 error ("reference to undefined predicate '%s'", XSTR (exp
, 1));
240 else if (p
->special
|| GET_MODE (exp
) != VOIDmode
)
241 NO_MODE_TEST (exp
) = 1;
246 NO_MODE_TEST (exp
) = 1;
251 NO_MODE_TEST (exp
) = 1;
255 mark_mode_tests (XEXP (exp
, 0));
256 mark_mode_tests (XEXP (exp
, 1));
258 NO_MODE_TEST (exp
) = (NO_MODE_TEST (XEXP (exp
, 0))
259 && NO_MODE_TEST (XEXP (exp
, 1)));
263 mark_mode_tests (XEXP (exp
, 0));
264 mark_mode_tests (XEXP (exp
, 1));
266 NO_MODE_TEST (exp
) = (NO_MODE_TEST (XEXP (exp
, 0))
267 || NO_MODE_TEST (XEXP (exp
, 1)));
271 /* A ? B : C does a mode test if (one of A and B) does a mode
272 test, and C does too. */
273 mark_mode_tests (XEXP (exp
, 0));
274 mark_mode_tests (XEXP (exp
, 1));
275 mark_mode_tests (XEXP (exp
, 2));
277 NO_MODE_TEST (exp
) = ((NO_MODE_TEST (XEXP (exp
, 0))
278 && NO_MODE_TEST (XEXP (exp
, 1)))
279 || NO_MODE_TEST (XEXP (exp
, 2)));
287 /* Determine whether the expression EXP is a MATCH_CODE that should
288 be written as a switch statement. */
290 generate_switch_p (rtx exp
)
292 return GET_CODE (exp
) == MATCH_CODE
293 && strchr (XSTR (exp
, 0), ',');
296 /* Given a predicate, work out where in its RTL expression to add
297 tests for proper modes. Special predicates do not get any such
298 tests. We try to avoid adding tests when we don't have to; in
299 particular, other normal predicates can be counted on to do it for
303 add_mode_tests (struct pred_data
*p
)
305 rtx match_test_exp
, and_exp
;
308 /* Don't touch special predicates. */
312 /* Check whether the predicate accepts const scalar ints (which always
313 have a stored mode of VOIDmode, but logically have a real mode)
314 and whether it matches anything besides const scalar ints. */
315 bool matches_const_scalar_int_p
= false;
316 bool matches_other_p
= false;
317 for (int i
= 0; i
< NUM_RTX_CODE
; ++i
)
323 /* Special handling for (VOIDmode) LABEL_REFs. */
325 matches_const_scalar_int_p
= true;
329 if (!TARGET_SUPPORTS_WIDE_INT
)
330 matches_const_scalar_int_p
= true;
331 matches_other_p
= true;
335 matches_other_p
= true;
339 /* There's no need for a mode check if the predicate only accepts
340 constant integers. The code checks in the predicate are enough
341 to establish that the mode is VOIDmode.
343 Note that the predicate itself should check whether a scalar
344 integer is in range of the given mode. */
345 if (!matches_other_p
)
348 mark_mode_tests (p
->exp
);
350 /* If the whole expression already tests the mode, we're done. */
351 if (!NO_MODE_TEST (p
->exp
))
354 match_test_exp
= rtx_alloc (MATCH_TEST
);
355 if (matches_const_scalar_int_p
)
356 XSTR (match_test_exp
, 0) = ("mode == VOIDmode || GET_MODE (op) == mode"
357 " || GET_MODE (op) == VOIDmode");
359 XSTR (match_test_exp
, 0) = "mode == VOIDmode || GET_MODE (op) == mode";
360 and_exp
= rtx_alloc (AND
);
361 XEXP (and_exp
, 1) = match_test_exp
;
363 /* It is always correct to rewrite p->exp as
365 (and (...) (match_test "mode == VOIDmode || GET_MODE (op) == mode"))
367 but there are a couple forms where we can do better. If the
368 top-level pattern is an IOR, and one of the two branches does test
369 the mode, we can wrap just the branch that doesn't. Likewise, if
370 we have an IF_THEN_ELSE, and one side of it tests the mode, we can
371 wrap just the side that doesn't. And, of course, we can repeat this
372 descent as many times as it works. */
379 switch (GET_CODE (subexp
))
382 /* The switch code generation in write_predicate_stmts prefers
383 rtx code tests to be at the top of the expression tree. So
384 push this AND down into the second operand of an existing
386 if (generate_switch_p (XEXP (subexp
, 0)))
387 pos
= &XEXP (subexp
, 1);
392 int test0
= NO_MODE_TEST (XEXP (subexp
, 0));
393 int test1
= NO_MODE_TEST (XEXP (subexp
, 1));
395 gcc_assert (test0
|| test1
);
399 pos
= test0
? &XEXP (subexp
, 0) : &XEXP (subexp
, 1);
405 int test0
= NO_MODE_TEST (XEXP (subexp
, 0));
406 int test1
= NO_MODE_TEST (XEXP (subexp
, 1));
407 int test2
= NO_MODE_TEST (XEXP (subexp
, 2));
409 gcc_assert ((test0
&& test1
) || test2
);
411 if (test0
&& test1
&& test2
)
414 /* Must put it on the dependent clause, not the
415 controlling expression, or we change the meaning of
417 pos
= &XEXP (subexp
, 1);
419 pos
= &XEXP (subexp
, 2);
428 XEXP (and_exp
, 0) = *pos
;
432 /* PATH is a string describing a path from the root of an RTL
433 expression to an inner subexpression to be tested. Output
434 code which computes the subexpression from the variable
435 holding the root of the expression. */
437 write_extract_subexp (const char *path
)
439 int len
= strlen (path
);
442 /* We first write out the operations (XEXP or XVECEXP) in reverse
443 order, then write "op", then the indices in forward order. */
444 for (i
= len
- 1; i
>= 0; i
--)
446 if (ISLOWER (path
[i
]))
447 fputs ("XVECEXP (", stdout
);
448 else if (ISDIGIT (path
[i
]))
449 fputs ("XEXP (", stdout
);
454 fputs ("op", stdout
);
456 for (i
= 0; i
< len
; i
++)
458 if (ISLOWER (path
[i
]))
459 printf (", 0, %d)", path
[i
] - 'a');
460 else if (ISDIGIT (path
[i
]))
461 printf (", %d)", path
[i
] - '0');
467 /* CODES is a list of RTX codes. Write out an expression which
468 determines whether the operand has one of those codes. */
470 write_match_code (const char *path
, const char *codes
)
474 while ((code
= scan_comma_elt (&codes
)) != 0)
476 fputs ("GET_CODE (", stdout
);
477 write_extract_subexp (path
);
478 fputs (") == ", stdout
);
481 putchar (TOUPPER (*code
));
486 fputs (" || ", stdout
);
490 /* EXP is an RTL (sub)expression for a predicate. Recursively
491 descend the expression and write out an equivalent C expression. */
493 write_predicate_expr (rtx exp
)
495 switch (GET_CODE (exp
))
499 write_predicate_expr (XEXP (exp
, 0));
500 fputs (") && (", stdout
);
501 write_predicate_expr (XEXP (exp
, 1));
507 write_predicate_expr (XEXP (exp
, 0));
508 fputs (") || (", stdout
);
509 write_predicate_expr (XEXP (exp
, 1));
514 fputs ("!(", stdout
);
515 write_predicate_expr (XEXP (exp
, 0));
521 write_predicate_expr (XEXP (exp
, 0));
522 fputs (") ? (", stdout
);
523 write_predicate_expr (XEXP (exp
, 1));
524 fputs (") : (", stdout
);
525 write_predicate_expr (XEXP (exp
, 2));
530 if (GET_MODE (exp
) == VOIDmode
)
531 printf ("%s (op, mode)", XSTR (exp
, 1));
533 printf ("%s (op, %smode)", XSTR (exp
, 1), mode_name
[GET_MODE (exp
)]);
537 write_match_code (XSTR (exp
, 1), XSTR (exp
, 0));
541 rtx_reader_ptr
->print_c_condition (XSTR (exp
, 0));
549 /* Write the MATCH_CODE expression EXP as a switch statement. */
552 write_match_code_switch (rtx exp
)
554 const char *codes
= XSTR (exp
, 0);
555 const char *path
= XSTR (exp
, 1);
558 fputs (" switch (GET_CODE (", stdout
);
559 write_extract_subexp (path
);
560 fputs ("))\n {\n", stdout
);
562 while ((code
= scan_comma_elt (&codes
)) != 0)
564 fputs (" case ", stdout
);
567 putchar (TOUPPER (*code
));
570 fputs (":\n", stdout
);
574 /* Given a predicate expression EXP, write out a sequence of stmts
575 to evaluate it. This is similar to write_predicate_expr but can
576 generate efficient switch statements. */
579 write_predicate_stmts (rtx exp
)
581 switch (GET_CODE (exp
))
584 if (generate_switch_p (exp
))
586 write_match_code_switch (exp
);
587 puts (" return true;\n"
597 if (generate_switch_p (XEXP (exp
, 0)))
599 write_match_code_switch (XEXP (exp
, 0));
609 if (generate_switch_p (XEXP (exp
, 0)))
611 write_match_code_switch (XEXP (exp
, 0));
612 puts (" return true;\n"
621 if (generate_switch_p (XEXP (exp
, 0)))
623 write_match_code_switch (XEXP (exp
, 0));
624 puts (" return false;\n"
637 fputs (" return ",stdout
);
638 write_predicate_expr (exp
);
639 fputs (";\n", stdout
);
642 /* Given a predicate, write out a complete C function to compute it. */
644 write_one_predicate_function (struct pred_data
*p
)
649 write_predicate_subfunction (p
);
652 /* A normal predicate can legitimately not look at machine_mode
653 if it accepts only CONST_INTs and/or CONST_WIDE_INT and/or CONST_DOUBLEs. */
654 printf ("bool\n%s (rtx op, machine_mode mode ATTRIBUTE_UNUSED)\n{\n",
656 write_predicate_stmts (p
->exp
);
657 fputs ("}\n\n", stdout
);
660 /* Constraints fall into two categories: register constraints
661 (define_register_constraint), and others (define_constraint,
662 define_memory_constraint, define_special_memory_constraint,
663 define_relaxed_memory_constraint, define_address_constraint). We work out
664 automatically which of the various old-style macros they correspond to, and
665 produce appropriate code. They all go in the same hash table so we can
666 verify that there are no duplicate names. */
668 /* All data from one constraint definition. */
669 class constraint_data
672 class constraint_data
*next_this_letter
;
673 class constraint_data
*next_textual
;
675 const char *c_name
; /* same as .name unless mangling is necessary */
676 file_location loc
; /* location of definition */
678 const char *regclass
; /* for register constraints */
679 rtx exp
; /* for other constraints */
680 const char *filter
; /* the register filter condition, or null if none */
681 unsigned int is_register
: 1;
682 unsigned int is_const_int
: 1;
683 unsigned int is_const_dbl
: 1;
684 unsigned int is_extra
: 1;
685 unsigned int is_memory
: 1;
686 unsigned int is_special_memory
: 1;
687 unsigned int is_relaxed_memory
: 1;
688 unsigned int is_address
: 1;
689 unsigned int maybe_allows_reg
: 1;
690 unsigned int maybe_allows_mem
: 1;
693 /* Overview of all constraints beginning with a given letter. */
695 static class constraint_data
*
696 constraints_by_letter_table
[1<<CHAR_BIT
];
698 /* For looking up all the constraints in the order that they appeared
699 in the machine description. */
700 static class constraint_data
*first_constraint
;
701 static class constraint_data
**last_constraint_ptr
= &first_constraint
;
703 #define FOR_ALL_CONSTRAINTS(iter_) \
704 for (iter_ = first_constraint; iter_; iter_ = iter_->next_textual)
706 /* Contraint letters that have a special meaning and that cannot be used
707 in define*_constraints. */
708 static const char generic_constraint_letters
[] = "g";
710 /* Machine-independent code expects that constraints with these
711 (initial) letters will allow only (a subset of all) CONST_INTs. */
713 static const char const_int_constraints
[] = "IJKLMNOP";
715 /* Machine-independent code expects that constraints with these
716 (initial) letters will allow only (a subset of all) CONST_DOUBLEs. */
718 static const char const_dbl_constraints
[] = "GH";
720 /* Summary data used to decide whether to output various functions and
721 macro definitions. */
722 static unsigned int constraint_max_namelen
;
723 static bool have_register_constraints
;
724 static bool have_memory_constraints
;
725 static bool have_special_memory_constraints
;
726 static bool have_relaxed_memory_constraints
;
727 static bool have_address_constraints
;
728 static bool have_extra_constraints
;
729 static bool have_const_int_constraints
;
730 static unsigned int num_constraints
;
732 static const constraint_data
**enum_order
;
733 static unsigned int register_start
, register_end
;
734 static unsigned int satisfied_start
;
735 static unsigned int const_int_start
, const_int_end
;
736 static unsigned int memory_start
, memory_end
;
737 static unsigned int special_memory_start
, special_memory_end
;
738 static unsigned int relaxed_memory_start
, relaxed_memory_end
;
739 static unsigned int address_start
, address_end
;
740 static unsigned int maybe_allows_none_start
, maybe_allows_none_end
;
741 static unsigned int maybe_allows_reg_start
, maybe_allows_reg_end
;
742 static unsigned int maybe_allows_mem_start
, maybe_allows_mem_end
;
744 /* Convert NAME, which contains angle brackets and/or underscores, to
745 a string that can be used as part of a C identifier. The string
746 comes from the rtl_obstack. */
748 mangle (const char *name
)
750 for (; *name
; name
++)
753 case '_': obstack_grow (rtl_obstack
, "__", 2); break;
754 case '<': obstack_grow (rtl_obstack
, "_l", 2); break;
755 case '>': obstack_grow (rtl_obstack
, "_g", 2); break;
756 default: obstack_1grow (rtl_obstack
, *name
); break;
759 obstack_1grow (rtl_obstack
, '\0');
760 return XOBFINISH (rtl_obstack
, const char *);
763 /* Add one constraint, of any sort, to the tables. NAME is its name; REGCLASS
764 is the register class, if any; EXP is the expression to test, if any;
765 IS_MEMORY, IS_SPECIAL_MEMORY, IS_RELAXED_MEMORY and IS_ADDRESS indicate
766 memory, special memory, and address constraints, respectively; LOC is the .md
767 file location; FILTER is the filter condition for a register constraint,
770 Not all combinations of arguments are valid; most importantly, REGCLASS is
771 mutually exclusive with EXP, and
772 IS_MEMORY/IS_SPECIAL_MEMORY/IS_RELAXED_MEMORY/IS_ADDRESS are only meaningful
773 for constraints with EXP.
775 This function enforces all syntactic and semantic rules about what
776 constraints can be defined. */
779 add_constraint (const char *name
, const char *regclass
,
780 rtx exp
, bool is_memory
, bool is_special_memory
,
781 bool is_relaxed_memory
, bool is_address
, file_location loc
,
782 const char *filter
= nullptr)
784 class constraint_data
*c
, **iter
, **slot
;
786 bool need_mangled_name
= false;
791 if (strcmp (name
, "TARGET_MEM_CONSTRAINT") == 0)
794 if (exp
&& validate_exp (exp
, name
, loc
))
797 for (p
= name
; *p
; p
++)
800 if (*p
== '<' || *p
== '>' || *p
== '_')
801 need_mangled_name
= true;
804 error_at (loc
, "constraint name '%s' must be composed of letters,"
805 " digits, underscores, and angle brackets", name
);
810 if (strchr (generic_constraint_letters
, name
[0]))
813 error_at (loc
, "constraint letter '%s' cannot be "
814 "redefined by the machine description", name
);
816 error_at (loc
, "constraint name '%s' cannot be defined by the machine"
817 " description, as it begins with '%c'", name
, name
[0]);
822 namelen
= strlen (name
);
823 slot
= &constraints_by_letter_table
[(unsigned int)name
[0]];
824 for (iter
= slot
; *iter
; iter
= &(*iter
)->next_this_letter
)
826 /* This causes slot to end up pointing to the
827 next_this_letter field of the last constraint with a name
828 of equal or greater length than the new constraint; hence
829 the new constraint will be inserted after all previous
830 constraints with names of the same length. */
831 if ((*iter
)->namelen
>= namelen
)
834 if (!strcmp ((*iter
)->name
, name
))
836 error_at (loc
, "redefinition of constraint '%s'", name
);
837 message_at ((*iter
)->loc
, "previous definition is here");
840 else if (!strncmp ((*iter
)->name
, name
, (*iter
)->namelen
))
842 error_at (loc
, "defining constraint '%s' here", name
);
843 message_at ((*iter
)->loc
, "renders constraint '%s' "
844 "(defined here) a prefix", (*iter
)->name
);
847 else if (!strncmp ((*iter
)->name
, name
, namelen
))
849 error_at (loc
, "constraint '%s' is a prefix", name
);
850 message_at ((*iter
)->loc
, "of constraint '%s' (defined here)",
856 is_const_int
= strchr (const_int_constraints
, name
[0]) != 0;
857 is_const_dbl
= strchr (const_dbl_constraints
, name
[0]) != 0;
859 if (is_const_int
|| is_const_dbl
)
861 enum rtx_code appropriate_code
862 = is_const_int
? CONST_INT
: CONST_DOUBLE
;
864 /* Consider relaxing this requirement in the future. */
866 || GET_CODE (exp
) != AND
867 || GET_CODE (XEXP (exp
, 0)) != MATCH_CODE
868 || strcmp (XSTR (XEXP (exp
, 0), 0),
869 GET_RTX_NAME (appropriate_code
)))
872 error_at (loc
, "constraint letter '%c' is reserved "
873 "for %s constraints", name
[0],
874 GET_RTX_NAME (appropriate_code
));
876 error_at (loc
, "constraint names beginning with '%c' "
877 "(%s) are reserved for %s constraints",
878 name
[0], name
, GET_RTX_NAME (appropriate_code
));
882 if (is_memory
|| is_special_memory
|| is_relaxed_memory
)
885 error_at (loc
, "constraint letter '%c' cannot be a "
886 "memory constraint", name
[0]);
888 error_at (loc
, "constraint name '%s' begins with '%c', "
889 "and therefore cannot be a memory constraint",
896 error_at (loc
, "constraint letter '%c' cannot be an "
897 "address constraint", name
[0]);
899 error_at (loc
, "constraint name '%s' begins with '%c', "
900 "and therefore cannot be an address constraint",
907 c
= XOBNEW (rtl_obstack
, class constraint_data
);
909 c
->c_name
= need_mangled_name
? mangle (name
) : name
;
911 c
->namelen
= namelen
;
912 c
->regclass
= regclass
;
915 c
->is_register
= regclass
!= 0;
916 c
->is_const_int
= is_const_int
;
917 c
->is_const_dbl
= is_const_dbl
;
918 c
->is_extra
= !(regclass
|| is_const_int
|| is_const_dbl
);
919 c
->is_memory
= is_memory
;
920 c
->is_special_memory
= is_special_memory
;
921 c
->is_relaxed_memory
= is_relaxed_memory
;
922 c
->is_address
= is_address
;
923 c
->maybe_allows_reg
= true;
924 c
->maybe_allows_mem
= true;
927 char codes
[NUM_RTX_CODE
];
928 compute_test_codes (exp
, loc
, codes
);
929 if (!codes
[REG
] && !codes
[SUBREG
])
930 c
->maybe_allows_reg
= false;
932 c
->maybe_allows_mem
= false;
934 c
->next_this_letter
= *slot
;
937 /* Insert this constraint in the list of all constraints in textual
940 *last_constraint_ptr
= c
;
941 last_constraint_ptr
= &c
->next_textual
;
943 constraint_max_namelen
= MAX (constraint_max_namelen
, strlen (name
));
944 have_register_constraints
|= c
->is_register
;
945 have_const_int_constraints
|= c
->is_const_int
;
946 have_extra_constraints
|= c
->is_extra
;
947 have_memory_constraints
|= c
->is_memory
;
948 have_special_memory_constraints
|= c
->is_special_memory
;
949 have_relaxed_memory_constraints
|= c
->is_relaxed_memory
;
950 have_address_constraints
|= c
->is_address
;
951 num_constraints
+= 1;
954 /* Process a DEFINE_CONSTRAINT, DEFINE_MEMORY_CONSTRAINT,
955 DEFINE_SPECIAL_MEMORY_CONSTRAINT, DEFINE_RELAXED_MEMORY_CONSTRAINT, or
956 DEFINE_ADDRESS_CONSTRAINT expression, C. */
958 process_define_constraint (md_rtx_info
*info
)
960 add_constraint (XSTR (info
->def
, 0), 0, XEXP (info
->def
, 2),
961 GET_CODE (info
->def
) == DEFINE_MEMORY_CONSTRAINT
,
962 GET_CODE (info
->def
) == DEFINE_SPECIAL_MEMORY_CONSTRAINT
,
963 GET_CODE (info
->def
) == DEFINE_RELAXED_MEMORY_CONSTRAINT
,
964 GET_CODE (info
->def
) == DEFINE_ADDRESS_CONSTRAINT
,
968 /* Process a DEFINE_REGISTER_CONSTRAINT expression, C. */
970 process_define_register_constraint (md_rtx_info
*info
)
972 add_constraint (XSTR (info
->def
, 0), XSTR (info
->def
, 1),
973 0, false, false, false, false, info
->loc
,
974 XSTR (info
->def
, 3));
977 /* Put the constraints into enum order. We want to keep constraints
978 of the same type together so that query functions can be simple
981 choose_enum_order (void)
983 class constraint_data
*c
;
985 enum_order
= XNEWVEC (const constraint_data
*, num_constraints
);
986 unsigned int next
= 0;
988 register_start
= next
;
989 FOR_ALL_CONSTRAINTS (c
)
991 enum_order
[next
++] = c
;
994 satisfied_start
= next
;
996 const_int_start
= next
;
997 FOR_ALL_CONSTRAINTS (c
)
999 enum_order
[next
++] = c
;
1000 const_int_end
= next
;
1002 memory_start
= next
;
1003 FOR_ALL_CONSTRAINTS (c
)
1005 enum_order
[next
++] = c
;
1008 special_memory_start
= next
;
1009 FOR_ALL_CONSTRAINTS (c
)
1010 if (c
->is_special_memory
)
1011 enum_order
[next
++] = c
;
1012 special_memory_end
= next
;
1014 relaxed_memory_start
= next
;
1015 FOR_ALL_CONSTRAINTS (c
)
1016 if (c
->is_relaxed_memory
)
1017 enum_order
[next
++] = c
;
1018 relaxed_memory_end
= next
;
1020 address_start
= next
;
1021 FOR_ALL_CONSTRAINTS (c
)
1023 enum_order
[next
++] = c
;
1026 maybe_allows_none_start
= next
;
1027 FOR_ALL_CONSTRAINTS (c
)
1028 if (!c
->is_register
&& !c
->is_const_int
&& !c
->is_memory
1029 && !c
->is_special_memory
&& !c
->is_relaxed_memory
&& !c
->is_address
1030 && !c
->maybe_allows_reg
&& !c
->maybe_allows_mem
)
1031 enum_order
[next
++] = c
;
1032 maybe_allows_none_end
= next
;
1034 maybe_allows_reg_start
= next
;
1035 FOR_ALL_CONSTRAINTS (c
)
1036 if (!c
->is_register
&& !c
->is_const_int
&& !c
->is_memory
1037 && !c
->is_special_memory
&& !c
->is_relaxed_memory
&& !c
->is_address
1038 && c
->maybe_allows_reg
&& !c
->maybe_allows_mem
)
1039 enum_order
[next
++] = c
;
1040 maybe_allows_reg_end
= next
;
1042 maybe_allows_mem_start
= next
;
1043 FOR_ALL_CONSTRAINTS (c
)
1044 if (!c
->is_register
&& !c
->is_const_int
&& !c
->is_memory
1045 && !c
->is_special_memory
&& !c
->is_relaxed_memory
&& !c
->is_address
1046 && !c
->maybe_allows_reg
&& c
->maybe_allows_mem
)
1047 enum_order
[next
++] = c
;
1048 maybe_allows_mem_end
= next
;
1050 FOR_ALL_CONSTRAINTS (c
)
1051 if (!c
->is_register
&& !c
->is_const_int
&& !c
->is_memory
1052 && !c
->is_special_memory
&& !c
->is_relaxed_memory
&& !c
->is_address
1053 && c
->maybe_allows_reg
&& c
->maybe_allows_mem
)
1054 enum_order
[next
++] = c
;
1055 gcc_assert (next
== num_constraints
);
1058 /* Write out an enumeration with one entry per machine-specific
1061 write_enum_constraint_num (void)
1063 fputs ("#define CONSTRAINT_NUM_DEFINED_P 1\n", stdout
);
1064 fputs ("enum constraint_num\n"
1066 " CONSTRAINT__UNKNOWN = 0", stdout
);
1067 for (unsigned int i
= 0; i
< num_constraints
; ++i
)
1068 printf (",\n CONSTRAINT_%s", enum_order
[i
]->c_name
);
1069 puts (",\n CONSTRAINT__LIMIT\n};\n");
1072 /* Write out a function which looks at a string and determines what
1073 constraint name, if any, it begins with. */
1075 write_lookup_constraint_1 (void)
1078 puts ("enum constraint_num\n"
1079 "lookup_constraint_1 (const char *str)\n"
1081 " switch (str[0])\n"
1084 for (i
= 0; i
< ARRAY_SIZE (constraints_by_letter_table
); i
++)
1086 class constraint_data
*c
= constraints_by_letter_table
[i
];
1090 printf (" case '%c':\n", i
);
1091 if (c
->namelen
== 1)
1092 printf (" return CONSTRAINT_%s;\n", c
->c_name
);
1098 printf (" if (!strncmp (str + 1, \"%s\", %lu))\n"
1099 " return CONSTRAINT_%s;\n",
1100 c
->name
+ 1, (unsigned long int) c
->namelen
- 1,
1103 printf (" if (str[1] == '%c')\n"
1104 " return CONSTRAINT_%s;\n",
1105 c
->name
[1], c
->c_name
);
1106 c
= c
->next_this_letter
;
1113 puts (" default: break;\n"
1115 " return CONSTRAINT__UNKNOWN;\n"
1119 /* Write out an array that maps single-letter characters to their
1120 constraints (if that fits in a character) or 255 if lookup_constraint_1
1123 write_lookup_constraint_array (void)
1126 printf ("const unsigned char lookup_constraint_array[] = {\n ");
1127 for (i
= 0; i
< ARRAY_SIZE (constraints_by_letter_table
); i
++)
1131 class constraint_data
*c
= constraints_by_letter_table
[i
];
1133 printf ("CONSTRAINT__UNKNOWN");
1134 else if (c
->namelen
== 1)
1135 printf ("MIN ((int) CONSTRAINT_%s, (int) UCHAR_MAX)", c
->c_name
);
1137 printf ("UCHAR_MAX");
1139 printf ("\n};\n\n");
1142 /* Write out a function which looks at a string and determines what
1143 the constraint name length is. */
1145 write_insn_constraint_len (void)
1149 puts ("static inline size_t\n"
1150 "insn_constraint_len (char fc, const char *str ATTRIBUTE_UNUSED)\n"
1155 for (i
= 0; i
< ARRAY_SIZE (constraints_by_letter_table
); i
++)
1157 class constraint_data
*c
= constraints_by_letter_table
[i
];
1163 /* Constraints with multiple characters should have the same
1166 class constraint_data
*c2
= c
->next_this_letter
;
1167 size_t len
= c
->namelen
;
1170 if (c2
->namelen
!= len
)
1171 error ("Multi-letter constraints with first letter '%c' "
1172 "should have same length", i
);
1173 c2
= c2
->next_this_letter
;
1177 printf (" case '%c': return %lu;\n",
1178 i
, (unsigned long int) c
->namelen
);
1181 puts (" default: break;\n"
1187 /* Write out the function which computes the register class corresponding
1188 to a register constraint. */
1190 write_reg_class_for_constraint_1 (void)
1192 class constraint_data
*c
;
1194 puts ("enum reg_class\n"
1195 "reg_class_for_constraint_1 (enum constraint_num c)\n"
1200 FOR_ALL_CONSTRAINTS (c
)
1202 printf (" case CONSTRAINT_%s: return %s;\n", c
->c_name
, c
->regclass
);
1204 puts (" default: break;\n"
1206 " return NO_REGS;\n"
1210 /* Write out the functions which compute whether a given value matches
1211 a given non-register constraint. */
1213 write_tm_constrs_h (void)
1215 class constraint_data
*c
;
1218 /* Generated automatically by the program '%s'\n\
1219 from the machine description file '%s'. */\n\n", progname
,
1220 md_reader_ptr
->get_top_level_filename ());
1223 #ifndef GCC_TM_CONSTRS_H\n\
1224 #define GCC_TM_CONSTRS_H\n");
1226 FOR_ALL_CONSTRAINTS (c
)
1227 if (!c
->is_register
)
1229 bool needs_ival
= needs_variable (c
->exp
, "ival");
1230 bool needs_hval
= needs_variable (c
->exp
, "hval");
1231 bool needs_lval
= needs_variable (c
->exp
, "lval");
1232 bool needs_rval
= needs_variable (c
->exp
, "rval");
1233 bool needs_mode
= (needs_variable (c
->exp
, "mode")
1234 || needs_hval
|| needs_lval
|| needs_rval
);
1235 bool needs_op
= (needs_variable (c
->exp
, "op")
1236 || needs_ival
|| needs_mode
);
1238 printf ("static inline bool\n"
1239 "satisfies_constraint_%s (rtx %s)\n"
1241 needs_op
? "op" : "ARG_UNUSED (op)");
1243 puts (" machine_mode mode = GET_MODE (op);");
1245 puts (" HOST_WIDE_INT ival = 0;");
1247 puts (" HOST_WIDE_INT hval = 0;");
1249 puts (" unsigned HOST_WIDE_INT lval = 0;");
1251 puts (" const REAL_VALUE_TYPE *rval = 0;");
1254 puts (" if (CONST_INT_P (op))\n"
1255 " ival = INTVAL (op);");
1256 #if TARGET_SUPPORTS_WIDE_INT
1257 if (needs_lval
|| needs_hval
)
1258 error ("you can't use lval or hval");
1261 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1262 " hval = CONST_DOUBLE_HIGH (op);");
1264 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1265 " lval = CONST_DOUBLE_LOW (op);");
1268 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode != VOIDmode)"
1269 " rval = CONST_DOUBLE_REAL_VALUE (op);");
1271 write_predicate_stmts (c
->exp
);
1272 fputs ("}\n", stdout
);
1274 puts ("#endif /* tm-constrs.h */");
1277 /* Write out the wrapper function, constraint_satisfied_p, that maps
1278 a CONSTRAINT_xxx constant to one of the predicate functions generated
1281 write_constraint_satisfied_p_array (void)
1283 if (satisfied_start
== num_constraints
)
1286 printf ("bool (*constraint_satisfied_p_array[]) (rtx) = {\n ");
1287 for (unsigned int i
= satisfied_start
; i
< num_constraints
; ++i
)
1289 if (i
!= satisfied_start
)
1291 printf ("satisfies_constraint_%s", enum_order
[i
]->c_name
);
1293 printf ("\n};\n\n");
1296 /* Write out the function which computes whether a given value matches
1297 a given CONST_INT constraint. This doesn't just forward to
1298 constraint_satisfied_p because caller passes the INTVAL, not the RTX. */
1300 write_insn_const_int_ok_for_constraint (void)
1302 class constraint_data
*c
;
1305 "insn_const_int_ok_for_constraint (HOST_WIDE_INT ival, "
1306 "enum constraint_num c)\n"
1311 FOR_ALL_CONSTRAINTS (c
)
1312 if (c
->is_const_int
)
1314 printf (" case CONSTRAINT_%s:\n return ", c
->c_name
);
1315 /* c->exp is guaranteed to be (and (match_code "const_int") (...));
1316 we know at this point that we have a const_int, so we need not
1317 bother with that part of the test. */
1318 write_predicate_expr (XEXP (c
->exp
, 1));
1319 fputs (";\n\n", stdout
);
1322 puts (" default: break;\n"
1328 /* Print the init_reg_class_start_regs function, which initializes
1329 this_target_constraints->register_filters from the C conditions
1330 in the define_register_constraints. */
1332 write_init_reg_class_start_regs ()
1336 "init_reg_class_start_regs ()\n"
1338 if (!register_filters
.is_empty ())
1340 printf (" for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER;"
1343 for (unsigned int i
= 0; i
< register_filters
.length (); ++i
)
1346 rtx_reader_ptr
->print_c_condition (register_filters
[i
]);
1348 " SET_HARD_REG_BIT (%s[%d], regno);\n",
1349 "this_target_constraints->register_filters", i
);
1356 /* Write a definition for a function NAME that returns true if a given
1357 constraint_num is in the range [START, END). */
1359 write_range_function (const char *name
, unsigned int start
, unsigned int end
)
1361 printf ("static inline bool\n");
1363 printf ("%s (enum constraint_num c)\n"
1365 " return c >= CONSTRAINT_%s && c <= CONSTRAINT_%s;\n"
1367 name
, enum_order
[start
]->c_name
, enum_order
[end
- 1]->c_name
);
1369 printf ("%s (enum constraint_num)\n"
1375 /* Write a definition for insn_extra_constraint_allows_reg_mem function. */
1377 write_allows_reg_mem_function (void)
1379 printf ("static inline void\n"
1380 "insn_extra_constraint_allows_reg_mem (enum constraint_num c,\n"
1381 "\t\t\t\t bool *allows_reg, bool *allows_mem)\n"
1383 if (maybe_allows_none_start
!= maybe_allows_none_end
)
1384 printf (" if (c >= CONSTRAINT_%s && c <= CONSTRAINT_%s)\n"
1386 enum_order
[maybe_allows_none_start
]->c_name
,
1387 enum_order
[maybe_allows_none_end
- 1]->c_name
);
1388 if (maybe_allows_reg_start
!= maybe_allows_reg_end
)
1389 printf (" if (c >= CONSTRAINT_%s && c <= CONSTRAINT_%s)\n"
1391 " *allows_reg = true;\n"
1394 enum_order
[maybe_allows_reg_start
]->c_name
,
1395 enum_order
[maybe_allows_reg_end
- 1]->c_name
);
1396 if (maybe_allows_mem_start
!= maybe_allows_mem_end
)
1397 printf (" if (c >= CONSTRAINT_%s && c <= CONSTRAINT_%s)\n"
1399 " *allows_mem = true;\n"
1402 enum_order
[maybe_allows_mem_start
]->c_name
,
1403 enum_order
[maybe_allows_mem_end
- 1]->c_name
);
1404 printf (" (void) c;\n"
1405 " *allows_reg = true;\n"
1406 " *allows_mem = true;\n"
1410 /* VEC is a list of key/value pairs, with the keys being lower bounds
1411 of a range. Output a decision tree that handles the keys covered by
1412 [VEC[START], VEC[END]), returning FALLBACK for keys lower then VEC[START]'s.
1413 INDENT is the number of spaces to indent the code. */
1415 print_type_tree (const vec
<std::pair
<unsigned int, const char *> > &vec
,
1416 unsigned int start
, unsigned int end
, const char *fallback
,
1417 unsigned int indent
)
1421 unsigned int mid
= (start
+ end
) / 2;
1422 printf ("%*sif (c >= CONSTRAINT_%s)\n",
1423 indent
, "", enum_order
[vec
[mid
].first
]->c_name
);
1425 print_type_tree (vec
, mid
+ 1, end
, vec
[mid
].second
, indent
+ 2);
1428 printf ("%*s{\n", indent
+ 2, "");
1429 print_type_tree (vec
, mid
+ 1, end
, vec
[mid
].second
, indent
+ 4);
1430 printf ("%*s}\n", indent
+ 2, "");
1434 printf ("%*sreturn %s;\n", indent
, "", fallback
);
1437 /* Print the get_register_filter function, which returns a pointer
1438 to the start register filter for a given constraint, or null if none. */
1440 write_get_register_filter ()
1445 "#ifdef GCC_HARD_REG_SET_H\n"
1446 "static inline const HARD_REG_SET *\n"
1447 "get_register_filter (constraint_num%s)\n",
1448 register_filters
.is_empty () ? "" : " c");
1450 FOR_ALL_CONSTRAINTS (c
)
1451 if (c
->is_register
&& c
->filter
)
1453 printf (" if (c == CONSTRAINT_%s)\n", c
->c_name
);
1454 printf (" return &this_target_constraints->register_filters[%d];\n",
1455 get_register_filter_id (c
->filter
));
1457 printf (" return nullptr;\n"
1462 /* Print the get_register_filter_id function, which returns the index
1463 of the given constraint's register filter in
1464 this_target_constraints->register_filters, or -1 if none. */
1466 write_get_register_filter_id ()
1471 "static inline int\n"
1472 "get_register_filter_id (constraint_num%s)\n",
1473 register_filters
.is_empty () ? "" : " c");
1475 FOR_ALL_CONSTRAINTS (c
)
1476 if (c
->is_register
&& c
->filter
)
1478 printf (" if (c == CONSTRAINT_%s)\n", c
->c_name
);
1479 printf (" return %d;\n", get_register_filter_id (c
->filter
));
1481 printf (" return -1;\n"
1485 /* Write tm-preds.h. Unfortunately, it is impossible to forward-declare
1486 an enumeration in portable C, so we have to condition all these
1487 prototypes on HAVE_MACHINE_MODES. */
1489 write_tm_preds_h (void)
1491 struct pred_data
*p
;
1494 /* Generated automatically by the program '%s'\n\
1495 from the machine description file '%s'. */\n\n", progname
,
1496 md_reader_ptr
->get_top_level_filename ());
1499 #ifndef GCC_TM_PREDS_H\n\
1500 #define GCC_TM_PREDS_H\n\
1502 #ifdef HAVE_MACHINE_MODES");
1504 FOR_ALL_PREDICATES (p
)
1505 printf ("extern bool %s (rtx, machine_mode);\n", p
->name
);
1507 puts ("#endif /* HAVE_MACHINE_MODES */\n");
1509 /* Print the definition of the target_constraints structure. */
1510 printf ("#ifdef GCC_HARD_REG_SET_H\n"
1511 "struct target_constraints {\n"
1512 " HARD_REG_SET register_filters[%d];\n",
1513 MAX (register_filters
.length (), 1));
1516 "extern struct target_constraints default_target_constraints;\n"
1517 "#if SWITCHABLE_TARGET\n"
1518 "extern struct target_constraints *this_target_constraints;\n"
1520 "#define this_target_constraints (&default_target_constraints)\n"
1523 /* Print TEST_REGISTER_FILTER_BIT, which tests whether register REGNO
1524 is a valid start register for register filter ID. */
1526 "#define TEST_REGISTER_FILTER_BIT(ID, REGNO) \\\n");
1527 if (register_filters
.is_empty ())
1528 printf (" ((void) (ID), (void) (REGNO), false)\n");
1530 printf (" TEST_HARD_REG_BIT ("
1531 "this_target_constraints->register_filters[ID], REGNO)\n");
1533 /* Print test_register_filters, which tests whether register REGNO
1534 is a valid start register for the mask of register filters in MASK. */
1537 "test_register_filters (unsigned int%s, unsigned int%s)\n",
1538 register_filters
.is_empty () ? "" : " mask",
1539 register_filters
.is_empty () ? "" : " regno");
1541 if (register_filters
.is_empty ())
1542 printf (" return true;\n");
1545 printf (" for (unsigned int id = 0; id < %d; ++id)\n",
1546 register_filters
.length ());
1547 printf (" if ((mask & (1U << id))\n"
1548 "\t&& !TEST_REGISTER_FILTER_BIT (id, regno))\n"
1556 if (constraint_max_namelen
> 0)
1558 write_enum_constraint_num ();
1559 puts ("extern enum constraint_num lookup_constraint_1 (const char *);\n"
1560 "extern const unsigned char lookup_constraint_array[];\n"
1562 "/* Return the constraint at the beginning of P, or"
1563 " CONSTRAINT__UNKNOWN if it\n"
1564 " isn't recognized. */\n"
1566 "static inline enum constraint_num\n"
1567 "lookup_constraint (const char *p)\n"
1569 " unsigned int index = lookup_constraint_array"
1570 "[(unsigned char) *p];\n"
1571 " return (index == UCHAR_MAX\n"
1572 " ? lookup_constraint_1 (p)\n"
1573 " : (enum constraint_num) index);\n"
1575 if (satisfied_start
== num_constraints
)
1576 puts ("/* Return true if X satisfies constraint C. */\n"
1578 "static inline bool\n"
1579 "constraint_satisfied_p (rtx, enum constraint_num)\n"
1584 printf ("extern bool (*constraint_satisfied_p_array[]) (rtx);\n"
1586 "/* Return true if X satisfies constraint C. */\n"
1588 "static inline bool\n"
1589 "constraint_satisfied_p (rtx x, enum constraint_num c)\n"
1591 " int i = (int) c - (int) CONSTRAINT_%s;\n"
1592 " return i >= 0 && constraint_satisfied_p_array[i] (x);\n"
1595 enum_order
[satisfied_start
]->name
);
1597 write_range_function ("insn_extra_register_constraint",
1598 register_start
, register_end
);
1599 write_range_function ("insn_extra_memory_constraint",
1600 memory_start
, memory_end
);
1601 write_range_function ("insn_extra_special_memory_constraint",
1602 special_memory_start
, special_memory_end
);
1603 write_range_function ("insn_extra_relaxed_memory_constraint",
1604 relaxed_memory_start
, relaxed_memory_end
);
1605 write_range_function ("insn_extra_address_constraint",
1606 address_start
, address_end
);
1607 write_allows_reg_mem_function ();
1609 if (constraint_max_namelen
> 1)
1611 write_insn_constraint_len ();
1612 puts ("#define CONSTRAINT_LEN(c_,s_) "
1613 "insn_constraint_len (c_,s_)\n");
1616 puts ("#define CONSTRAINT_LEN(c_,s_) 1\n");
1617 if (have_register_constraints
)
1618 puts ("extern enum reg_class reg_class_for_constraint_1 "
1619 "(enum constraint_num);\n"
1621 "static inline enum reg_class\n"
1622 "reg_class_for_constraint (enum constraint_num c)\n"
1624 " if (insn_extra_register_constraint (c))\n"
1625 " return reg_class_for_constraint_1 (c);\n"
1626 " return NO_REGS;\n"
1629 puts ("static inline enum reg_class\n"
1630 "reg_class_for_constraint (enum constraint_num)\n"
1632 " return NO_REGS;\n"
1634 if (have_const_int_constraints
)
1635 puts ("extern bool insn_const_int_ok_for_constraint "
1636 "(HOST_WIDE_INT, enum constraint_num);\n"
1637 "#define CONST_OK_FOR_CONSTRAINT_P(v_,c_,s_) \\\n"
1638 " insn_const_int_ok_for_constraint (v_, "
1639 "lookup_constraint (s_))\n");
1641 puts ("static inline bool\n"
1642 "insn_const_int_ok_for_constraint (HOST_WIDE_INT,"
1643 " enum constraint_num)\n"
1648 puts ("enum constraint_type\n"
1653 " CT_SPECIAL_MEMORY,\n"
1654 " CT_RELAXED_MEMORY,\n"
1659 "static inline enum constraint_type\n"
1660 "get_constraint_type (enum constraint_num c)\n"
1662 auto_vec
<std::pair
<unsigned int, const char *>, 4> values
;
1663 if (const_int_start
!= const_int_end
)
1664 values
.safe_push (std::make_pair (const_int_start
, "CT_CONST_INT"));
1665 if (memory_start
!= memory_end
)
1666 values
.safe_push (std::make_pair (memory_start
, "CT_MEMORY"));
1667 if (special_memory_start
!= special_memory_end
)
1668 values
.safe_push (std::make_pair (special_memory_start
,
1669 "CT_SPECIAL_MEMORY"));
1670 if (relaxed_memory_start
!= relaxed_memory_end
)
1671 values
.safe_push (std::make_pair (relaxed_memory_start
,
1672 "CT_RELAXED_MEMORY"));
1673 if (address_start
!= address_end
)
1674 values
.safe_push (std::make_pair (address_start
, "CT_ADDRESS"));
1675 if (address_end
!= num_constraints
)
1676 values
.safe_push (std::make_pair (address_end
, "CT_FIXED_FORM"));
1677 print_type_tree (values
, 0, values
.length (), "CT_REGISTER", 2);
1680 write_get_register_filter ();
1681 write_get_register_filter_id ();
1684 puts ("#endif /* tm-preds.h */");
1687 /* Write insn-preds.cc.
1688 N.B. the list of headers to include was copied from genrecog; it
1691 FUTURE: Write #line markers referring back to the machine
1692 description. (Can't practically do this now since we don't know
1693 the line number of the C block - just the line number of the enclosing
1696 write_insn_preds_c (void)
1698 struct pred_data
*p
;
1701 /* Generated automatically by the program '%s'\n\
1702 from the machine description file '%s'. */\n\n", progname
,
1703 md_reader_ptr
->get_top_level_filename ());
1706 #define IN_TARGET_CODE 1\n\
1707 #include \"config.h\"\n\
1708 #include \"system.h\"\n\
1709 #include \"coretypes.h\"\n\
1710 #include \"backend.h\"\n\
1711 #include \"predict.h\"\n\
1712 #include \"tree.h\"\n\
1713 #include \"rtl.h\"\n\
1714 #include \"alias.h\"\n\
1715 #include \"varasm.h\"\n\
1716 #include \"stor-layout.h\"\n\
1717 #include \"calls.h\"\n\
1718 #include \"memmodel.h\"\n\
1719 #include \"tm_p.h\"\n\
1720 #include \"insn-config.h\"\n\
1721 #include \"recog.h\"\n\
1722 #include \"output.h\"\n\
1723 #include \"flags.h\"\n\
1724 #include \"df.h\"\n\
1725 #include \"resource.h\"\n\
1726 #include \"diagnostic-core.h\"\n\
1727 #include \"reload.h\"\n\
1728 #include \"regs.h\"\n\
1729 #include \"emit-rtl.h\"\n\
1730 #include \"tm-constrs.h\"\n\
1731 #include \"target.h\"\n");
1734 "struct target_constraints default_target_constraints;\n"
1735 "#if SWITCHABLE_TARGET\n"
1736 "struct target_constraints *this_target_constraints"
1737 " = &default_target_constraints;\n"
1740 FOR_ALL_PREDICATES (p
)
1741 write_one_predicate_function (p
);
1743 if (constraint_max_namelen
> 0)
1745 write_lookup_constraint_1 ();
1746 write_lookup_constraint_array ();
1747 if (have_register_constraints
)
1748 write_reg_class_for_constraint_1 ();
1749 write_constraint_satisfied_p_array ();
1751 if (have_const_int_constraints
)
1752 write_insn_const_int_ok_for_constraint ();
1755 write_init_reg_class_start_regs ();
1758 /* Argument parsing. */
1759 static bool gen_header
;
1760 static bool gen_constrs
;
1763 parse_option (const char *opt
)
1765 if (!strcmp (opt
, "-h"))
1770 else if (!strcmp (opt
, "-c"))
1779 /* Master control. */
1781 main (int argc
, const char **argv
)
1785 fatal ("no input file name");
1786 if (!init_rtx_reader_args_cb (argc
, argv
, parse_option
))
1787 return FATAL_EXIT_CODE
;
1790 while (read_md_rtx (&info
))
1791 switch (GET_CODE (info
.def
))
1793 case DEFINE_PREDICATE
:
1794 case DEFINE_SPECIAL_PREDICATE
:
1795 process_define_predicate (&info
);
1798 case DEFINE_CONSTRAINT
:
1799 case DEFINE_MEMORY_CONSTRAINT
:
1800 case DEFINE_SPECIAL_MEMORY_CONSTRAINT
:
1801 case DEFINE_RELAXED_MEMORY_CONSTRAINT
:
1802 case DEFINE_ADDRESS_CONSTRAINT
:
1803 process_define_constraint (&info
);
1806 case DEFINE_REGISTER_CONSTRAINT
:
1807 process_define_register_constraint (&info
);
1814 choose_enum_order ();
1817 write_tm_preds_h ();
1818 else if (gen_constrs
)
1819 write_tm_constrs_h ();
1821 write_insn_preds_c ();
1823 if (have_error
|| ferror (stdout
) || fflush (stdout
) || fclose (stdout
))
1824 return FATAL_EXIT_CODE
;
1826 return SUCCESS_EXIT_CODE
;