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-2013 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 /* Given a predicate expression EXP, from form NAME at line LINENO,
34 verify that it does not contain any RTL constructs which are not
35 valid in predicate definitions. Returns true if EXP is
36 INvalid; issues error messages, caller need not. */
38 validate_exp (rtx exp
, const char *name
, int lineno
)
42 message_with_line (lineno
, "%s: must give a predicate expression", name
);
46 switch (GET_CODE (exp
))
48 /* Ternary, binary, unary expressions: recurse into subexpressions. */
50 if (validate_exp (XEXP (exp
, 2), name
, lineno
))
52 /* else fall through */
55 if (validate_exp (XEXP (exp
, 1), name
, lineno
))
57 /* else fall through */
59 return validate_exp (XEXP (exp
, 0), name
, lineno
);
61 /* MATCH_CODE might have a syntax error in its path expression. */
65 for (p
= XSTR (exp
, 1); *p
; p
++)
67 if (!ISDIGIT (*p
) && !ISLOWER (*p
))
69 error_with_line (lineno
, "%s: invalid character in path "
70 "string '%s'", name
, XSTR (exp
, 1));
77 /* These need no special checking. */
83 error_with_line (lineno
,
84 "%s: cannot use '%s' in a predicate expression",
85 name
, GET_RTX_NAME (GET_CODE (exp
)));
90 /* Predicates are defined with (define_predicate) or
91 (define_special_predicate) expressions in the machine description. */
93 process_define_predicate (rtx defn
, int lineno
)
95 validate_exp (XEXP (defn
, 1), XSTR (defn
, 0), lineno
);
98 /* Given a predicate, if it has an embedded C block, write the block
99 out as a static inline subroutine, and augment the RTL test with a
100 match_test that calls that subroutine. For instance,
102 (define_predicate "basereg_operand"
103 (match_operand 0 "register_operand")
105 if (GET_CODE (op) == SUBREG)
106 op = SUBREG_REG (op);
107 return REG_POINTER (op);
112 static inline int basereg_operand_1(rtx op, enum machine_mode mode)
114 if (GET_CODE (op) == SUBREG)
115 op = SUBREG_REG (op);
116 return REG_POINTER (op);
119 (define_predicate "basereg_operand"
120 (and (match_operand 0 "register_operand")
121 (match_test "basereg_operand_1 (op, mode)")))
123 The only wart is that there's no way to insist on a { } string in
124 an RTL template, so we have to handle "" strings. */
128 write_predicate_subfunction (struct pred_data
*p
)
130 const char *match_test_str
;
131 rtx match_test_exp
, and_exp
;
133 if (p
->c_block
[0] == '\0')
136 /* Construct the function-call expression. */
137 obstack_grow (rtl_obstack
, p
->name
, strlen (p
->name
));
138 obstack_grow (rtl_obstack
, "_1 (op, mode)",
139 sizeof "_1 (op, mode)");
140 match_test_str
= XOBFINISH (rtl_obstack
, const char *);
142 /* Add the function-call expression to the complete expression to be
144 match_test_exp
= rtx_alloc (MATCH_TEST
);
145 XSTR (match_test_exp
, 0) = match_test_str
;
147 and_exp
= rtx_alloc (AND
);
148 XEXP (and_exp
, 0) = p
->exp
;
149 XEXP (and_exp
, 1) = match_test_exp
;
153 printf ("static inline int\n"
154 "%s_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)\n",
156 print_md_ptr_loc (p
->c_block
);
157 if (p
->c_block
[0] == '{')
158 fputs (p
->c_block
, stdout
);
160 printf ("{\n %s\n}", p
->c_block
);
161 fputs ("\n\n", stdout
);
164 /* Given a predicate expression EXP, from form NAME, determine whether
165 it refers to the variable given as VAR. */
167 needs_variable (rtx exp
, const char *var
)
169 switch (GET_CODE (exp
))
171 /* Ternary, binary, unary expressions need a variable if
172 any of their subexpressions do. */
174 if (needs_variable (XEXP (exp
, 2), var
))
176 /* else fall through */
179 if (needs_variable (XEXP (exp
, 1), var
))
181 /* else fall through */
183 return needs_variable (XEXP (exp
, 0), var
);
185 /* MATCH_CODE uses "op", but nothing else. */
187 return !strcmp (var
, "op");
189 /* MATCH_OPERAND uses "op" and may use "mode". */
191 if (!strcmp (var
, "op"))
193 if (!strcmp (var
, "mode") && GET_MODE (exp
) == VOIDmode
)
197 /* MATCH_TEST uses var if XSTR (exp, 0) =~ /\b${var}\b/o; */
200 const char *p
= XSTR (exp
, 0);
201 const char *q
= strstr (p
, var
);
204 if (q
!= p
&& (ISALNUM (q
[-1]) || q
[-1] == '_'))
207 if (ISALNUM (q
[0]) || q
[0] == '_')
217 /* Given an RTL expression EXP, find all subexpressions which we may
218 assume to perform mode tests. Normal MATCH_OPERAND does;
219 MATCH_CODE does if it applies to the whole expression and accepts
220 CONST_INT or CONST_DOUBLE; and we have to assume that MATCH_TEST
221 does not. These combine in almost-boolean fashion - the only
222 exception is that (not X) must be assumed not to perform a mode
223 test, whether or not X does.
225 The mark is the RTL /v flag, which is true for subexpressions which
226 do *not* perform mode tests.
228 #define NO_MODE_TEST(EXP) RTX_FLAG (EXP, volatil)
230 mark_mode_tests (rtx exp
)
232 switch (GET_CODE (exp
))
236 struct pred_data
*p
= lookup_predicate (XSTR (exp
, 1));
238 error ("reference to undefined predicate '%s'", XSTR (exp
, 1));
239 else if (p
->special
|| GET_MODE (exp
) != VOIDmode
)
240 NO_MODE_TEST (exp
) = 1;
245 if (XSTR (exp
, 1)[0] != '\0'
246 || (!strstr (XSTR (exp
, 0), "const_int")
247 && !strstr (XSTR (exp
, 0), "const_double")))
248 NO_MODE_TEST (exp
) = 1;
253 NO_MODE_TEST (exp
) = 1;
257 mark_mode_tests (XEXP (exp
, 0));
258 mark_mode_tests (XEXP (exp
, 1));
260 NO_MODE_TEST (exp
) = (NO_MODE_TEST (XEXP (exp
, 0))
261 && NO_MODE_TEST (XEXP (exp
, 1)));
265 mark_mode_tests (XEXP (exp
, 0));
266 mark_mode_tests (XEXP (exp
, 1));
268 NO_MODE_TEST (exp
) = (NO_MODE_TEST (XEXP (exp
, 0))
269 || NO_MODE_TEST (XEXP (exp
, 1)));
273 /* A ? B : C does a mode test if (one of A and B) does a mode
274 test, and C does too. */
275 mark_mode_tests (XEXP (exp
, 0));
276 mark_mode_tests (XEXP (exp
, 1));
277 mark_mode_tests (XEXP (exp
, 2));
279 NO_MODE_TEST (exp
) = ((NO_MODE_TEST (XEXP (exp
, 0))
280 && NO_MODE_TEST (XEXP (exp
, 1)))
281 || NO_MODE_TEST (XEXP (exp
, 2)));
289 /* Determine whether the expression EXP is a MATCH_CODE that should
290 be written as a switch statement. */
292 generate_switch_p (rtx exp
)
294 return GET_CODE (exp
) == MATCH_CODE
295 && strchr (XSTR (exp
, 0), ',');
298 /* Given a predicate, work out where in its RTL expression to add
299 tests for proper modes. Special predicates do not get any such
300 tests. We try to avoid adding tests when we don't have to; in
301 particular, other normal predicates can be counted on to do it for
305 add_mode_tests (struct pred_data
*p
)
307 rtx match_test_exp
, and_exp
;
310 /* Don't touch special predicates. */
314 mark_mode_tests (p
->exp
);
316 /* If the whole expression already tests the mode, we're done. */
317 if (!NO_MODE_TEST (p
->exp
))
320 match_test_exp
= rtx_alloc (MATCH_TEST
);
321 XSTR (match_test_exp
, 0) = "mode == VOIDmode || GET_MODE (op) == mode";
322 and_exp
= rtx_alloc (AND
);
323 XEXP (and_exp
, 1) = match_test_exp
;
325 /* It is always correct to rewrite p->exp as
327 (and (...) (match_test "mode == VOIDmode || GET_MODE (op) == mode"))
329 but there are a couple forms where we can do better. If the
330 top-level pattern is an IOR, and one of the two branches does test
331 the mode, we can wrap just the branch that doesn't. Likewise, if
332 we have an IF_THEN_ELSE, and one side of it tests the mode, we can
333 wrap just the side that doesn't. And, of course, we can repeat this
334 descent as many times as it works. */
341 switch (GET_CODE (subexp
))
344 /* The switch code generation in write_predicate_stmts prefers
345 rtx code tests to be at the top of the expression tree. So
346 push this AND down into the second operand of an existing
348 if (generate_switch_p (XEXP (subexp
, 0)))
349 pos
= &XEXP (subexp
, 1);
354 int test0
= NO_MODE_TEST (XEXP (subexp
, 0));
355 int test1
= NO_MODE_TEST (XEXP (subexp
, 1));
357 gcc_assert (test0
|| test1
);
361 pos
= test0
? &XEXP (subexp
, 0) : &XEXP (subexp
, 1);
367 int test0
= NO_MODE_TEST (XEXP (subexp
, 0));
368 int test1
= NO_MODE_TEST (XEXP (subexp
, 1));
369 int test2
= NO_MODE_TEST (XEXP (subexp
, 2));
371 gcc_assert ((test0
&& test1
) || test2
);
373 if (test0
&& test1
&& test2
)
376 /* Must put it on the dependent clause, not the
377 controlling expression, or we change the meaning of
379 pos
= &XEXP (subexp
, 1);
381 pos
= &XEXP (subexp
, 2);
390 XEXP (and_exp
, 0) = *pos
;
394 /* PATH is a string describing a path from the root of an RTL
395 expression to an inner subexpression to be tested. Output
396 code which computes the subexpression from the variable
397 holding the root of the expression. */
399 write_extract_subexp (const char *path
)
401 int len
= strlen (path
);
404 /* We first write out the operations (XEXP or XVECEXP) in reverse
405 order, then write "op", then the indices in forward order. */
406 for (i
= len
- 1; i
>= 0; i
--)
408 if (ISLOWER (path
[i
]))
409 fputs ("XVECEXP (", stdout
);
410 else if (ISDIGIT (path
[i
]))
411 fputs ("XEXP (", stdout
);
416 fputs ("op", stdout
);
418 for (i
= 0; i
< len
; i
++)
420 if (ISLOWER (path
[i
]))
421 printf (", 0, %d)", path
[i
] - 'a');
422 else if (ISDIGIT (path
[i
]))
423 printf (", %d)", path
[i
] - '0');
429 /* CODES is a list of RTX codes. Write out an expression which
430 determines whether the operand has one of those codes. */
432 write_match_code (const char *path
, const char *codes
)
436 while ((code
= scan_comma_elt (&codes
)) != 0)
438 fputs ("GET_CODE (", stdout
);
439 write_extract_subexp (path
);
440 fputs (") == ", stdout
);
443 putchar (TOUPPER (*code
));
448 fputs (" || ", stdout
);
452 /* EXP is an RTL (sub)expression for a predicate. Recursively
453 descend the expression and write out an equivalent C expression. */
455 write_predicate_expr (rtx exp
)
457 switch (GET_CODE (exp
))
461 write_predicate_expr (XEXP (exp
, 0));
462 fputs (") && (", stdout
);
463 write_predicate_expr (XEXP (exp
, 1));
469 write_predicate_expr (XEXP (exp
, 0));
470 fputs (") || (", stdout
);
471 write_predicate_expr (XEXP (exp
, 1));
476 fputs ("!(", stdout
);
477 write_predicate_expr (XEXP (exp
, 0));
483 write_predicate_expr (XEXP (exp
, 0));
484 fputs (") ? (", stdout
);
485 write_predicate_expr (XEXP (exp
, 1));
486 fputs (") : (", stdout
);
487 write_predicate_expr (XEXP (exp
, 2));
492 if (GET_MODE (exp
) == VOIDmode
)
493 printf ("%s (op, mode)", XSTR (exp
, 1));
495 printf ("%s (op, %smode)", XSTR (exp
, 1), mode_name
[GET_MODE (exp
)]);
499 write_match_code (XSTR (exp
, 1), XSTR (exp
, 0));
503 print_c_condition (XSTR (exp
, 0));
511 /* Write the MATCH_CODE expression EXP as a switch statement. */
514 write_match_code_switch (rtx exp
)
516 const char *codes
= XSTR (exp
, 0);
517 const char *path
= XSTR (exp
, 1);
520 fputs (" switch (GET_CODE (", stdout
);
521 write_extract_subexp (path
);
522 fputs ("))\n {\n", stdout
);
524 while ((code
= scan_comma_elt (&codes
)) != 0)
526 fputs (" case ", stdout
);
529 putchar (TOUPPER (*code
));
532 fputs (":\n", stdout
);
536 /* Given a predicate expression EXP, write out a sequence of stmts
537 to evaluate it. This is similar to write_predicate_expr but can
538 generate efficient switch statements. */
541 write_predicate_stmts (rtx exp
)
543 switch (GET_CODE (exp
))
546 if (generate_switch_p (exp
))
548 write_match_code_switch (exp
);
549 puts (" return true;\n"
559 if (generate_switch_p (XEXP (exp
, 0)))
561 write_match_code_switch (XEXP (exp
, 0));
571 if (generate_switch_p (XEXP (exp
, 0)))
573 write_match_code_switch (XEXP (exp
, 0));
574 puts (" return true;\n"
583 if (generate_switch_p (XEXP (exp
, 0)))
585 write_match_code_switch (XEXP (exp
, 0));
586 puts (" return false;\n"
599 fputs (" return ",stdout
);
600 write_predicate_expr (exp
);
601 fputs (";\n", stdout
);
604 /* Given a predicate, write out a complete C function to compute it. */
606 write_one_predicate_function (struct pred_data
*p
)
611 write_predicate_subfunction (p
);
614 /* A normal predicate can legitimately not look at enum machine_mode
615 if it accepts only CONST_INTs and/or CONST_WIDE_INT and/or CONST_DOUBLEs. */
616 printf ("int\n%s (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)\n{\n",
618 write_predicate_stmts (p
->exp
);
619 fputs ("}\n\n", stdout
);
622 /* Constraints fall into two categories: register constraints
623 (define_register_constraint), and others (define_constraint,
624 define_memory_constraint, define_address_constraint). We
625 work out automatically which of the various old-style macros
626 they correspond to, and produce appropriate code. They all
627 go in the same hash table so we can verify that there are no
630 /* All data from one constraint definition. */
631 struct constraint_data
633 struct constraint_data
*next_this_letter
;
634 struct constraint_data
*next_textual
;
636 const char *c_name
; /* same as .name unless mangling is necessary */
638 const char *regclass
; /* for register constraints */
639 rtx exp
; /* for other constraints */
640 unsigned int lineno
; /* line of definition */
641 unsigned int is_register
: 1;
642 unsigned int is_const_int
: 1;
643 unsigned int is_const_dbl
: 1;
644 unsigned int is_extra
: 1;
645 unsigned int is_memory
: 1;
646 unsigned int is_address
: 1;
649 /* Overview of all constraints beginning with a given letter. */
651 static struct constraint_data
*
652 constraints_by_letter_table
[1<<CHAR_BIT
];
654 /* For looking up all the constraints in the order that they appeared
655 in the machine description. */
656 static struct constraint_data
*first_constraint
;
657 static struct constraint_data
**last_constraint_ptr
= &first_constraint
;
659 #define FOR_ALL_CONSTRAINTS(iter_) \
660 for (iter_ = first_constraint; iter_; iter_ = iter_->next_textual)
662 /* These letters, and all names beginning with them, are reserved for
664 The 'm' constraint is not mentioned here since that constraint
665 letter can be overridden by the back end by defining the
666 TARGET_MEM_CONSTRAINT macro. */
667 static const char generic_constraint_letters
[] = "EFVXginoprs";
669 /* Machine-independent code expects that constraints with these
670 (initial) letters will allow only (a subset of all) CONST_INTs. */
672 static const char const_int_constraints
[] = "IJKLMNOP";
674 /* Machine-independent code expects that constraints with these
675 (initial) letters will allow only (a subset of all) CONST_DOUBLEs. */
677 static const char const_dbl_constraints
[] = "GH";
679 /* Summary data used to decide whether to output various functions and
680 macro definitions. */
681 static unsigned int constraint_max_namelen
;
682 static bool have_register_constraints
;
683 static bool have_memory_constraints
;
684 static bool have_address_constraints
;
685 static bool have_extra_constraints
;
686 static bool have_const_int_constraints
;
687 static bool have_const_dbl_constraints
;
689 /* Convert NAME, which contains angle brackets and/or underscores, to
690 a string that can be used as part of a C identifier. The string
691 comes from the rtl_obstack. */
693 mangle (const char *name
)
695 for (; *name
; name
++)
698 case '_': obstack_grow (rtl_obstack
, "__", 2); break;
699 case '<': obstack_grow (rtl_obstack
, "_l", 2); break;
700 case '>': obstack_grow (rtl_obstack
, "_g", 2); break;
701 default: obstack_1grow (rtl_obstack
, *name
); break;
704 obstack_1grow (rtl_obstack
, '\0');
705 return XOBFINISH (rtl_obstack
, const char *);
708 /* Add one constraint, of any sort, to the tables. NAME is its name;
709 REGCLASS is the register class, if any; EXP is the expression to
710 test, if any; IS_MEMORY and IS_ADDRESS indicate memory and address
711 constraints, respectively; LINENO is the line number from the MD reader.
712 Not all combinations of arguments are valid; most importantly, REGCLASS
713 is mutually exclusive with EXP, and IS_MEMORY/IS_ADDRESS are only
714 meaningful for constraints with EXP.
716 This function enforces all syntactic and semantic rules about what
717 constraints can be defined. */
720 add_constraint (const char *name
, const char *regclass
,
721 rtx exp
, bool is_memory
, bool is_address
,
724 struct constraint_data
*c
, **iter
, **slot
;
726 bool need_mangled_name
= false;
731 if (exp
&& validate_exp (exp
, name
, lineno
))
734 if (!ISALPHA (name
[0]) && name
[0] != '_')
737 error_with_line (lineno
, "constraint name '%s' is not "
738 "a letter or underscore", name
);
740 error_with_line (lineno
, "constraint name '%s' does not begin "
741 "with a letter or underscore", name
);
744 for (p
= name
; *p
; p
++)
747 if (*p
== '<' || *p
== '>' || *p
== '_')
748 need_mangled_name
= true;
751 error_with_line (lineno
,
752 "constraint name '%s' must be composed of "
753 "letters, digits, underscores, and "
754 "angle brackets", name
);
759 if (strchr (generic_constraint_letters
, name
[0]))
762 error_with_line (lineno
, "constraint letter '%s' cannot be "
763 "redefined by the machine description", name
);
765 error_with_line (lineno
, "constraint name '%s' cannot be defined by "
766 "the machine description, as it begins with '%c'",
772 namelen
= strlen (name
);
773 slot
= &constraints_by_letter_table
[(unsigned int)name
[0]];
774 for (iter
= slot
; *iter
; iter
= &(*iter
)->next_this_letter
)
776 /* This causes slot to end up pointing to the
777 next_this_letter field of the last constraint with a name
778 of equal or greater length than the new constraint; hence
779 the new constraint will be inserted after all previous
780 constraints with names of the same length. */
781 if ((*iter
)->namelen
>= namelen
)
784 if (!strcmp ((*iter
)->name
, name
))
786 error_with_line (lineno
, "redefinition of constraint '%s'", name
);
787 message_with_line ((*iter
)->lineno
, "previous definition is here");
790 else if (!strncmp ((*iter
)->name
, name
, (*iter
)->namelen
))
792 error_with_line (lineno
, "defining constraint '%s' here", name
);
793 message_with_line ((*iter
)->lineno
, "renders constraint '%s' "
794 "(defined here) a prefix", (*iter
)->name
);
797 else if (!strncmp ((*iter
)->name
, name
, namelen
))
799 error_with_line (lineno
, "constraint '%s' is a prefix", name
);
800 message_with_line ((*iter
)->lineno
, "of constraint '%s' "
801 "(defined here)", (*iter
)->name
);
806 is_const_int
= strchr (const_int_constraints
, name
[0]) != 0;
807 is_const_dbl
= strchr (const_dbl_constraints
, name
[0]) != 0;
809 if (is_const_int
|| is_const_dbl
)
811 enum rtx_code appropriate_code
812 = is_const_int
? CONST_INT
: CONST_DOUBLE
;
813 /* Consider relaxing this requirement in the future. */
815 || GET_CODE (exp
) != AND
816 || GET_CODE (XEXP (exp
, 0)) != MATCH_CODE
817 || strcmp (XSTR (XEXP (exp
, 0), 0),
818 GET_RTX_NAME (appropriate_code
)))
821 error_with_line (lineno
, "constraint letter '%c' is reserved "
822 "for %s constraints",
823 name
[0], GET_RTX_NAME (appropriate_code
));
825 error_with_line (lineno
, "constraint names beginning with '%c' "
826 "(%s) are reserved for %s constraints",
827 name
[0], name
, GET_RTX_NAME (appropriate_code
));
834 error_with_line (lineno
, "constraint letter '%c' cannot be a "
835 "memory constraint", name
[0]);
837 error_with_line (lineno
, "constraint name '%s' begins with '%c', "
838 "and therefore cannot be a memory constraint",
845 error_with_line (lineno
, "constraint letter '%c' cannot be a "
846 "memory constraint", name
[0]);
848 error_with_line (lineno
, "constraint name '%s' begins with '%c', "
849 "and therefore cannot be a memory constraint",
856 c
= XOBNEW (rtl_obstack
, struct constraint_data
);
858 c
->c_name
= need_mangled_name
? mangle (name
) : name
;
860 c
->namelen
= namelen
;
861 c
->regclass
= regclass
;
863 c
->is_register
= regclass
!= 0;
864 c
->is_const_int
= is_const_int
;
865 c
->is_const_dbl
= is_const_dbl
;
866 c
->is_extra
= !(regclass
|| is_const_int
|| is_const_dbl
);
867 c
->is_memory
= is_memory
;
868 c
->is_address
= is_address
;
870 c
->next_this_letter
= *slot
;
873 /* Insert this constraint in the list of all constraints in textual
876 *last_constraint_ptr
= c
;
877 last_constraint_ptr
= &c
->next_textual
;
879 constraint_max_namelen
= MAX (constraint_max_namelen
, strlen (name
));
880 have_register_constraints
|= c
->is_register
;
881 have_const_int_constraints
|= c
->is_const_int
;
882 have_const_dbl_constraints
|= c
->is_const_dbl
;
883 have_extra_constraints
|= c
->is_extra
;
884 have_memory_constraints
|= c
->is_memory
;
885 have_address_constraints
|= c
->is_address
;
888 /* Process a DEFINE_CONSTRAINT, DEFINE_MEMORY_CONSTRAINT, or
889 DEFINE_ADDRESS_CONSTRAINT expression, C. */
891 process_define_constraint (rtx c
, int lineno
)
893 add_constraint (XSTR (c
, 0), 0, XEXP (c
, 2),
894 GET_CODE (c
) == DEFINE_MEMORY_CONSTRAINT
,
895 GET_CODE (c
) == DEFINE_ADDRESS_CONSTRAINT
,
899 /* Process a DEFINE_REGISTER_CONSTRAINT expression, C. */
901 process_define_register_constraint (rtx c
, int lineno
)
903 add_constraint (XSTR (c
, 0), XSTR (c
, 1), 0, false, false, lineno
);
906 /* Write out an enumeration with one entry per machine-specific
909 write_enum_constraint_num (void)
911 struct constraint_data
*c
;
913 fputs ("#define CONSTRAINT_NUM_DEFINED_P 1\n", stdout
);
914 fputs ("enum constraint_num\n"
916 " CONSTRAINT__UNKNOWN = 0", stdout
);
917 FOR_ALL_CONSTRAINTS (c
)
918 printf (",\n CONSTRAINT_%s", c
->c_name
);
919 puts (",\n CONSTRAINT__LIMIT\n};\n");
922 /* Write out a function which looks at a string and determines what
923 constraint name, if any, it begins with. */
925 write_lookup_constraint (void)
928 puts ("enum constraint_num\n"
929 "lookup_constraint (const char *str)\n"
934 for (i
= 0; i
< ARRAY_SIZE (constraints_by_letter_table
); i
++)
936 struct constraint_data
*c
= constraints_by_letter_table
[i
];
940 printf (" case '%c':\n", i
);
942 printf (" return CONSTRAINT_%s;\n", c
->c_name
);
947 printf (" if (!strncmp (str + 1, \"%s\", %lu))\n"
948 " return CONSTRAINT_%s;\n",
949 c
->name
+ 1, (unsigned long int) c
->namelen
- 1,
951 c
= c
->next_this_letter
;
958 puts (" default: break;\n"
960 " return CONSTRAINT__UNKNOWN;\n"
964 /* Write out a function which looks at a string and determines what
965 the constraint name length is. */
967 write_insn_constraint_len (void)
971 puts ("static inline size_t\n"
972 "insn_constraint_len (char fc, const char *str ATTRIBUTE_UNUSED)\n"
977 for (i
= 0; i
< ARRAY_SIZE (constraints_by_letter_table
); i
++)
979 struct constraint_data
*c
= constraints_by_letter_table
[i
];
985 /* Constraints with multiple characters should have the same
988 struct constraint_data
*c2
= c
->next_this_letter
;
989 size_t len
= c
->namelen
;
992 if (c2
->namelen
!= len
)
993 error ("Multi-letter constraints with first letter '%c' "
994 "should have same length", i
);
995 c2
= c2
->next_this_letter
;
999 printf (" case '%c': return %lu;\n",
1000 i
, (unsigned long int) c
->namelen
);
1003 puts (" default: break;\n"
1009 /* Write out the function which computes the register class corresponding
1010 to a register constraint. */
1012 write_regclass_for_constraint (void)
1014 struct constraint_data
*c
;
1016 puts ("enum reg_class\n"
1017 "regclass_for_constraint (enum constraint_num c)\n"
1022 FOR_ALL_CONSTRAINTS (c
)
1024 printf (" case CONSTRAINT_%s: return %s;\n", c
->c_name
, c
->regclass
);
1026 puts (" default: break;\n"
1028 " return NO_REGS;\n"
1032 /* Write out the functions which compute whether a given value matches
1033 a given non-register constraint. */
1035 write_tm_constrs_h (void)
1037 struct constraint_data
*c
;
1040 /* Generated automatically by the program '%s'\n\
1041 from the machine description file '%s'. */\n\n", progname
, in_fname
);
1044 #ifndef GCC_TM_CONSTRS_H\n\
1045 #define GCC_TM_CONSTRS_H\n");
1047 FOR_ALL_CONSTRAINTS (c
)
1048 if (!c
->is_register
)
1050 bool needs_ival
= needs_variable (c
->exp
, "ival");
1051 bool needs_hval
= needs_variable (c
->exp
, "hval");
1052 bool needs_lval
= needs_variable (c
->exp
, "lval");
1053 bool needs_rval
= needs_variable (c
->exp
, "rval");
1054 bool needs_mode
= (needs_variable (c
->exp
, "mode")
1055 || needs_hval
|| needs_lval
|| needs_rval
);
1056 bool needs_op
= (needs_variable (c
->exp
, "op")
1057 || needs_ival
|| needs_mode
);
1059 printf ("static inline bool\n"
1060 "satisfies_constraint_%s (rtx %s)\n"
1062 needs_op
? "op" : "ARG_UNUSED (op)");
1064 puts (" enum machine_mode mode = GET_MODE (op);");
1066 puts (" HOST_WIDE_INT ival = 0;");
1068 puts (" HOST_WIDE_INT hval = 0;");
1070 puts (" unsigned HOST_WIDE_INT lval = 0;");
1072 puts (" const REAL_VALUE_TYPE *rval = 0;");
1075 puts (" if (CONST_INT_P (op))\n"
1076 " ival = INTVAL (op);");
1077 #if TARGET_SUPPORTS_WIDE_INT
1078 if (needs_lval
|| needs_hval
)
1079 error ("you can't use lval or hval");
1082 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1083 " hval = CONST_DOUBLE_HIGH (op);");
1085 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1086 " lval = CONST_DOUBLE_LOW (op);");
1089 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode != VOIDmode)"
1090 " rval = CONST_DOUBLE_REAL_VALUE (op);");
1092 write_predicate_stmts (c
->exp
);
1093 fputs ("}\n", stdout
);
1095 puts ("#endif /* tm-constrs.h */");
1098 /* Write out the wrapper function, constraint_satisfied_p, that maps
1099 a CONSTRAINT_xxx constant to one of the predicate functions generated
1102 write_constraint_satisfied_p (void)
1104 struct constraint_data
*c
;
1107 "constraint_satisfied_p (rtx op, enum constraint_num c)\n"
1112 FOR_ALL_CONSTRAINTS (c
)
1113 if (!c
->is_register
)
1114 printf (" case CONSTRAINT_%s: "
1115 "return satisfies_constraint_%s (op);\n",
1116 c
->c_name
, c
->c_name
);
1118 puts (" default: break;\n"
1124 /* Write out the function which computes whether a given value matches
1125 a given CONST_INT constraint. This doesn't just forward to
1126 constraint_satisfied_p because caller passes the INTVAL, not the RTX. */
1128 write_insn_const_int_ok_for_constraint (void)
1130 struct constraint_data
*c
;
1133 "insn_const_int_ok_for_constraint (HOST_WIDE_INT ival, "
1134 "enum constraint_num c)\n"
1139 FOR_ALL_CONSTRAINTS (c
)
1140 if (c
->is_const_int
)
1142 printf (" case CONSTRAINT_%s:\n return ", c
->c_name
);
1143 /* c->exp is guaranteed to be (and (match_code "const_int") (...));
1144 we know at this point that we have a const_int, so we need not
1145 bother with that part of the test. */
1146 write_predicate_expr (XEXP (c
->exp
, 1));
1147 fputs (";\n\n", stdout
);
1150 puts (" default: break;\n"
1157 /* Write out the function which computes whether a given constraint is
1158 a memory constraint. */
1160 write_insn_extra_memory_constraint (void)
1162 struct constraint_data
*c
;
1165 "insn_extra_memory_constraint (enum constraint_num c)\n"
1170 FOR_ALL_CONSTRAINTS (c
)
1172 printf (" case CONSTRAINT_%s:\n return true;\n\n", c
->c_name
);
1174 puts (" default: break;\n"
1180 /* Write out the function which computes whether a given constraint is
1181 an address constraint. */
1183 write_insn_extra_address_constraint (void)
1185 struct constraint_data
*c
;
1188 "insn_extra_address_constraint (enum constraint_num c)\n"
1193 FOR_ALL_CONSTRAINTS (c
)
1195 printf (" case CONSTRAINT_%s:\n return true;\n\n", c
->c_name
);
1197 puts (" default: break;\n"
1204 /* Write tm-preds.h. Unfortunately, it is impossible to forward-declare
1205 an enumeration in portable C, so we have to condition all these
1206 prototypes on HAVE_MACHINE_MODES. */
1208 write_tm_preds_h (void)
1210 struct pred_data
*p
;
1213 /* Generated automatically by the program '%s'\n\
1214 from the machine description file '%s'. */\n\n", progname
, in_fname
);
1217 #ifndef GCC_TM_PREDS_H\n\
1218 #define GCC_TM_PREDS_H\n\
1220 #ifdef HAVE_MACHINE_MODES");
1222 FOR_ALL_PREDICATES (p
)
1223 printf ("extern int %s (rtx, enum machine_mode);\n", p
->name
);
1225 puts ("#endif /* HAVE_MACHINE_MODES */\n");
1227 if (constraint_max_namelen
> 0)
1229 write_enum_constraint_num ();
1230 puts ("extern enum constraint_num lookup_constraint (const char *);\n"
1231 "extern bool constraint_satisfied_p (rtx, enum constraint_num);\n");
1233 if (constraint_max_namelen
> 1)
1235 write_insn_constraint_len ();
1236 puts ("#define CONSTRAINT_LEN(c_,s_) "
1237 "insn_constraint_len (c_,s_)\n");
1240 puts ("#define CONSTRAINT_LEN(c_,s_) 1\n");
1241 if (have_register_constraints
)
1242 puts ("extern enum reg_class regclass_for_constraint "
1243 "(enum constraint_num);\n"
1244 "#define REG_CLASS_FROM_CONSTRAINT(c_,s_) \\\n"
1245 " regclass_for_constraint (lookup_constraint (s_))\n"
1246 "#define REG_CLASS_FOR_CONSTRAINT(x_) \\\n"
1247 " regclass_for_constraint (x_)\n");
1249 puts ("#define REG_CLASS_FROM_CONSTRAINT(c_,s_) NO_REGS\n"
1250 "#define REG_CLASS_FOR_CONSTRAINT(x_) \\\n"
1252 if (have_const_int_constraints
)
1253 puts ("extern bool insn_const_int_ok_for_constraint "
1254 "(HOST_WIDE_INT, enum constraint_num);\n"
1255 "#define CONST_OK_FOR_CONSTRAINT_P(v_,c_,s_) \\\n"
1256 " insn_const_int_ok_for_constraint (v_, "
1257 "lookup_constraint (s_))\n");
1258 if (have_const_dbl_constraints
)
1259 puts ("#define CONST_DOUBLE_OK_FOR_CONSTRAINT_P(v_,c_,s_) \\\n"
1260 " constraint_satisfied_p (v_, lookup_constraint (s_))\n");
1262 puts ("#define CONST_DOUBLE_OK_FOR_CONSTRAINT_P(v_,c_,s_) 0\n");
1263 if (have_extra_constraints
)
1264 puts ("#define EXTRA_CONSTRAINT_STR(v_,c_,s_) \\\n"
1265 " constraint_satisfied_p (v_, lookup_constraint (s_))\n");
1266 if (have_memory_constraints
)
1267 puts ("extern bool "
1268 "insn_extra_memory_constraint (enum constraint_num);\n"
1269 "#define EXTRA_MEMORY_CONSTRAINT(c_,s_) "
1270 "insn_extra_memory_constraint (lookup_constraint (s_))\n");
1272 puts ("#define EXTRA_MEMORY_CONSTRAINT(c_,s_) false\n");
1273 if (have_address_constraints
)
1274 puts ("extern bool "
1275 "insn_extra_address_constraint (enum constraint_num);\n"
1276 "#define EXTRA_ADDRESS_CONSTRAINT(c_,s_) "
1277 "insn_extra_address_constraint (lookup_constraint (s_))\n");
1279 puts ("#define EXTRA_ADDRESS_CONSTRAINT(c_,s_) false\n");
1282 puts ("#endif /* tm-preds.h */");
1285 /* Write insn-preds.c.
1286 N.B. the list of headers to include was copied from genrecog; it
1289 FUTURE: Write #line markers referring back to the machine
1290 description. (Can't practically do this now since we don't know
1291 the line number of the C block - just the line number of the enclosing
1294 write_insn_preds_c (void)
1296 struct pred_data
*p
;
1299 /* Generated automatically by the program '%s'\n\
1300 from the machine description file '%s'. */\n\n", progname
, in_fname
);
1303 #include \"config.h\"\n\
1304 #include \"system.h\"\n\
1305 #include \"coretypes.h\"\n\
1306 #include \"tm.h\"\n\
1307 #include \"rtl.h\"\n\
1308 #include \"tree.h\"\n\
1309 #include \"varasm.h\"\n\
1310 #include \"stor-layout.h\"\n\
1311 #include \"calls.h\"\n\
1312 #include \"tm_p.h\"\n\
1313 #include \"function.h\"\n\
1314 #include \"insn-config.h\"\n\
1315 #include \"recog.h\"\n\
1316 #include \"output.h\"\n\
1317 #include \"flags.h\"\n\
1318 #include \"hard-reg-set.h\"\n\
1319 #include \"resource.h\"\n\
1320 #include \"diagnostic-core.h\"\n\
1321 #include \"reload.h\"\n\
1322 #include \"regs.h\"\n\
1323 #include \"tm-constrs.h\"\n");
1325 FOR_ALL_PREDICATES (p
)
1326 write_one_predicate_function (p
);
1328 if (constraint_max_namelen
> 0)
1330 write_lookup_constraint ();
1331 if (have_register_constraints
)
1332 write_regclass_for_constraint ();
1333 write_constraint_satisfied_p ();
1335 if (have_const_int_constraints
)
1336 write_insn_const_int_ok_for_constraint ();
1338 if (have_memory_constraints
)
1339 write_insn_extra_memory_constraint ();
1340 if (have_address_constraints
)
1341 write_insn_extra_address_constraint ();
1345 /* Argument parsing. */
1346 static bool gen_header
;
1347 static bool gen_constrs
;
1350 parse_option (const char *opt
)
1352 if (!strcmp (opt
, "-h"))
1357 else if (!strcmp (opt
, "-c"))
1366 /* Master control. */
1368 main (int argc
, char **argv
)
1371 int pattern_lineno
, next_insn_code
= 0;
1375 fatal ("no input file name");
1376 if (!init_rtx_reader_args_cb (argc
, argv
, parse_option
))
1377 return FATAL_EXIT_CODE
;
1379 while ((defn
= read_md_rtx (&pattern_lineno
, &next_insn_code
)) != 0)
1380 switch (GET_CODE (defn
))
1382 case DEFINE_PREDICATE
:
1383 case DEFINE_SPECIAL_PREDICATE
:
1384 process_define_predicate (defn
, pattern_lineno
);
1387 case DEFINE_CONSTRAINT
:
1388 case DEFINE_MEMORY_CONSTRAINT
:
1389 case DEFINE_ADDRESS_CONSTRAINT
:
1390 process_define_constraint (defn
, pattern_lineno
);
1393 case DEFINE_REGISTER_CONSTRAINT
:
1394 process_define_register_constraint (defn
, pattern_lineno
);
1402 write_tm_preds_h ();
1403 else if (gen_constrs
)
1404 write_tm_constrs_h ();
1406 write_insn_preds_c ();
1408 if (have_error
|| ferror (stdout
) || fflush (stdout
) || fclose (stdout
))
1409 return FATAL_EXIT_CODE
;
1411 return SUCCESS_EXIT_CODE
;