]> gcc.gnu.org Git - gcc.git/blame - gcc/genflags.cc
OpenACC: Fix reduction tree-sharing issue [PR106982]
[gcc.git] / gcc / genflags.cc
CommitLineData
41299f41 1/* Generate from machine description:
41299f41
TW
2 - some flags HAVE_... saying which simple standard instructions are
3 available for this machine.
7adcbafe 4 Copyright (C) 1987-2022 Free Software Foundation, Inc.
41299f41 5
1322177d 6This file is part of GCC.
41299f41 7
1322177d
LB
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
9dcd6f09 10Software Foundation; either version 3, or (at your option) any later
1322177d 11version.
41299f41 12
1322177d
LB
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
41299f41
TW
17
18You should have received a copy of the GNU General Public License
9dcd6f09
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
41299f41
TW
21
22
4977bab6 23#include "bconfig.h"
0b93b64e 24#include "system.h"
4977bab6
ZW
25#include "coretypes.h"
26#include "tm.h"
41299f41
TW
27#include "rtl.h"
28#include "obstack.h"
f8b6598e 29#include "errors.h"
10692477 30#include "read-md.h"
c88c0d42 31#include "gensupport.h"
41299f41 32
f45c9d95
ZW
33/* Obstack to remember insns with. */
34static struct obstack obstack;
f837a861
MM
35
36/* Max size of names encountered. */
37static int max_id_len;
38
706b0f60
ZW
39/* Max operand encountered in a scan over some insn. */
40static int max_opno;
56c0e996 41
3d7aafde
AJ
42static void max_operand_1 (rtx);
43static int num_operands (rtx);
44static void gen_proto (rtx);
56c0e996 45
f837a861 46/* Count the number of match_operand's found. */
0f41302f 47
706b0f60 48static void
3d7aafde 49max_operand_1 (rtx x)
f837a861 50{
b3694847
SS
51 RTX_CODE code;
52 int i;
53 int len;
54 const char *fmt;
f837a861 55
706b0f60
ZW
56 if (x == 0)
57 return;
f837a861 58
706b0f60 59 code = GET_CODE (x);
f837a861 60
706b0f60
ZW
61 if (code == MATCH_OPERAND || code == MATCH_OPERATOR
62 || code == MATCH_PARALLEL)
63 max_opno = MAX (max_opno, XINT (x, 0));
64
65 fmt = GET_RTX_FORMAT (code);
66 len = GET_RTX_LENGTH (code);
67 for (i = 0; i < len; i++)
f837a861 68 {
706b0f60
ZW
69 if (fmt[i] == 'e' || fmt[i] == 'u')
70 max_operand_1 (XEXP (x, i));
71 else if (fmt[i] == 'E')
f837a861 72 {
706b0f60
ZW
73 int j;
74 for (j = 0; j < XVECLEN (x, i); j++)
75 max_operand_1 (XVECEXP (x, i, j));
f837a861
MM
76 }
77 }
706b0f60 78}
f837a861 79
706b0f60 80static int
3d7aafde 81num_operands (rtx insn)
706b0f60 82{
b3694847
SS
83 int len = XVECLEN (insn, 1);
84 int i;
706b0f60
ZW
85
86 max_opno = -1;
87
88 for (i = 0; i < len; i++)
89 max_operand_1 (XVECEXP (insn, 1, i));
90
91 return max_opno + 1;
f837a861
MM
92}
93
2199e5fa
ZW
94/* Print out prototype information for a generator function. If the
95 insn pattern has been elided, print out a dummy generator that
96 does nothing. */
0f41302f 97
f837a861 98static void
3d7aafde 99gen_proto (rtx insn)
f837a861
MM
100{
101 int num = num_operands (insn);
2199e5fa 102 int i;
f45c9d95 103 const char *name = XSTR (insn, 0);
2199e5fa 104 int truth = maybe_eval_c_test (XSTR (insn, 2));
f45c9d95 105
2199e5fa 106 if (truth != 0)
3d7aafde 107 printf ("extern rtx gen_%-*s (", max_id_len, name);
2199e5fa 108 else
3d7aafde 109 printf ("static inline rtx gen_%-*s (", max_id_len, name);
f837a861
MM
110
111 if (num == 0)
2199e5fa 112 fputs ("void", stdout);
f837a861
MM
113 else
114 {
2199e5fa
ZW
115 for (i = 1; i < num; i++)
116 fputs ("rtx, ", stdout);
3d7aafde 117
2199e5fa 118 fputs ("rtx", stdout);
f837a861
MM
119 }
120
3d7aafde 121 puts (");");
2199e5fa
ZW
122
123 /* Some back ends want to take the address of generator functions,
124 so we cannot simply use #define for these dummy definitions. */
125 if (truth == 0)
126 {
127 printf ("static inline rtx\ngen_%s", name);
128 if (num > 0)
129 {
130 putchar ('(');
131 for (i = 0; i < num-1; i++)
e18476eb
BI
132 printf ("rtx ARG_UNUSED (%c), ", 'a' + i);
133 printf ("rtx ARG_UNUSED (%c))\n", 'a' + i);
2199e5fa
ZW
134 }
135 else
5671bf27 136 puts ("(void)");
2199e5fa
ZW
137 puts ("{\n return 0;\n}");
138 }
f837a861 139
f837a861
MM
140}
141
41299f41 142static void
5d2d3e43 143gen_insn (md_rtx_info *info)
41299f41 144{
5d2d3e43 145 rtx insn = info->def;
3cce094d
KG
146 const char *name = XSTR (insn, 0);
147 const char *p;
7ddf71e3 148 const char *lt, *gt;
f837a861 149 int len;
2199e5fa 150 int truth = maybe_eval_c_test (XSTR (insn, 2));
41299f41 151
b8698a0f 152 lt = strchr (name, '<');
7ddf71e3
PB
153 if (lt && strchr (lt + 1, '>'))
154 {
74fe10ae 155 error_at (info->loc, "unresolved iterator in %s", name);
7ddf71e3
PB
156 return;
157 }
158
b8698a0f 159 gt = strchr (name, '>');
7ddf71e3
PB
160 if (lt || gt)
161 {
5d2d3e43 162 error_at (info->loc, "unmatched angle brackets, likely "
74fe10ae 163 "an error in iterator syntax in %s", name);
7ddf71e3
PB
164 return;
165 }
166
6b6ca844
RK
167 /* Don't mention instructions whose names are the null string
168 or begin with '*'. They are in the machine description just
169 to be recognized. */
170 if (name[0] == 0 || name[0] == '*')
41299f41
TW
171 return;
172
6b6ca844
RK
173 len = strlen (name);
174
f837a861
MM
175 if (len > max_id_len)
176 max_id_len = len;
177
2199e5fa 178 if (truth == 0)
e0a21ab9 179 /* Emit nothing. */;
2199e5fa
ZW
180 else if (truth == 1)
181 printf ("#define HAVE_%s 1\n", name);
41299f41
TW
182 else
183 {
184 /* Write the macro definition, putting \'s at the end of each line,
185 if more than one. */
2199e5fa 186 printf ("#define HAVE_%s (", name);
41299f41
TW
187 for (p = XSTR (insn, 2); *p; p++)
188 {
6b8b9d7b 189 if (IS_VSPACE (*p))
2199e5fa 190 fputs (" \\\n", stdout);
41299f41 191 else
2199e5fa 192 putchar (*p);
41299f41 193 }
2199e5fa 194 fputs (")\n", stdout);
41299f41 195 }
6610a1b0 196
f45c9d95 197 obstack_grow (&obstack, &insn, sizeof (rtx));
41299f41 198}
41299f41 199
41299f41 200int
66b0fe8f 201main (int argc, const char **argv)
41299f41 202{
f837a861 203 rtx dummy;
f45c9d95 204 rtx *insns;
f837a861 205 rtx *insn_ptr;
41299f41 206
f8b6598e 207 progname = "genflags";
f45c9d95 208 obstack_init (&obstack);
41299f41 209
2199e5fa
ZW
210 /* We need to see all the possibilities. Elided insns may have
211 direct calls to their generators in C code. */
212 insn_elision = 0;
213
600ab3fc 214 if (!init_rtx_reader_args (argc, argv))
c88c0d42 215 return (FATAL_EXIT_CODE);
3d7aafde 216
0313e85b
ZW
217 puts ("/* Generated automatically by the program `genflags'");
218 puts (" from the machine description file `md'. */\n");
219 puts ("#ifndef GCC_INSN_FLAGS_H");
220 puts ("#define GCC_INSN_FLAGS_H\n");
41299f41
TW
221
222 /* Read the machine description. */
223
5d2d3e43
RS
224 md_rtx_info info;
225 while (read_md_rtx (&info))
226 switch (GET_CODE (info.def))
227 {
228 case DEFINE_INSN:
229 case DEFINE_EXPAND:
230 gen_insn (&info);
231 break;
41299f41 232
5d2d3e43 233 default:
c88c0d42 234 break;
5d2d3e43 235 }
41299f41 236
f837a861 237 /* Print out the prototypes now. */
0f41302f 238 dummy = (rtx) 0;
f45c9d95 239 obstack_grow (&obstack, &dummy, sizeof (rtx));
7973fd2a 240 insns = XOBFINISH (&obstack, rtx *);
f837a861 241
f45c9d95 242 for (insn_ptr = insns; *insn_ptr; insn_ptr++)
f837a861
MM
243 gen_proto (*insn_ptr);
244
c3284718 245 puts ("\n#endif /* GCC_INSN_FLAGS_H */");
0313e85b 246
7ddf71e3 247 if (have_error || ferror (stdout) || fflush (stdout) || fclose (stdout))
0313e85b
ZW
248 return FATAL_EXIT_CODE;
249
250 return SUCCESS_EXIT_CODE;
41299f41 251}
This page took 8.98941 seconds and 5 git commands to generate.