]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/genemit.c
[PATCH][AARCH64]Add csneg3_uxtw_insn pattern
[thirdparty/gcc.git] / gcc / genemit.c
CommitLineData
65963943 1/* Generate code from machine description to emit insns as rtl.
5624e564 2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
65963943 3
1322177d 4This file is part of GCC.
65963943 5
1322177d
LB
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
1322177d 9version.
65963943 10
1322177d
LB
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
65963943
RK
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
65963943
RK
19
20
4977bab6 21#include "bconfig.h"
0b93b64e 22#include "system.h"
4977bab6
ZW
23#include "coretypes.h"
24#include "tm.h"
65963943 25#include "rtl.h"
f8b6598e 26#include "errors.h"
10692477 27#include "read-md.h"
c88c0d42 28#include "gensupport.h"
65963943 29
65963943 30
65963943 31/* Data structure for recording the patterns of insns that have CLOBBERs.
3d7aafde 32 We use this to output a function that adds these CLOBBERs to a
65963943
RK
33 previously-allocated PARALLEL expression. */
34
35struct clobber_pat
36{
e5f6a288 37 struct clobber_ent *insns;
65963943
RK
38 rtx pattern;
39 int first_clobber;
40 struct clobber_pat *next;
751aa7cc 41 int has_hard_reg;
65963943
RK
42} *clobber_list;
43
e5f6a288
RK
44/* Records one insn that uses the clobber list. */
45
46struct clobber_ent
47{
48 int code_number; /* Counts only insns. */
49 struct clobber_ent *next;
50};
51
3d7aafde 52static void output_peephole2_scratches (rtx);
e009aaf3 53
65963943
RK
54\f
55static void
3d7aafde 56print_code (RTX_CODE code)
65963943 57{
b3694847 58 const char *p1;
65963943 59 for (p1 = GET_RTX_NAME (code); *p1; p1++)
c3284718 60 putchar (TOUPPER (*p1));
65963943
RK
61}
62
ede7cd44 63static void
3d7aafde 64gen_rtx_scratch (rtx x, enum rtx_code subroutine_type)
ede7cd44
RH
65{
66 if (subroutine_type == DEFINE_PEEPHOLE2)
67 {
68 printf ("operand%d", XINT (x, 0));
69 }
70 else
71 {
72 printf ("gen_rtx_SCRATCH (%smode)", GET_MODE_NAME (GET_MODE (x)));
73 }
74}
75
65963943
RK
76/* Print a C expression to construct an RTX just like X,
77 substituting any operand references appearing within. */
78
79static void
3d7aafde 80gen_exp (rtx x, enum rtx_code subroutine_type, char *used)
65963943 81{
b3694847
SS
82 RTX_CODE code;
83 int i;
84 int len;
85 const char *fmt;
f7df4a84 86 const char *sep = "";
65963943
RK
87
88 if (x == 0)
89 {
3d678dca 90 printf ("NULL_RTX");
65963943
RK
91 return;
92 }
93
94 code = GET_CODE (x);
95
96 switch (code)
97 {
98 case MATCH_OPERAND:
99 case MATCH_DUP:
ab55f58c
RH
100 if (used)
101 {
102 if (used[XINT (x, 0)])
103 {
104 printf ("copy_rtx (operand%d)", XINT (x, 0));
105 return;
106 }
107 used[XINT (x, 0)] = 1;
108 }
65963943
RK
109 printf ("operand%d", XINT (x, 0));
110 return;
111
112 case MATCH_OP_DUP:
600555f5
KH
113 printf ("gen_rtx_fmt_");
114 for (i = 0; i < XVECLEN (x, 1); i++)
115 printf ("e");
116 printf (" (GET_CODE (operand%d), ", XINT (x, 0));
4ceb7595
JC
117 if (GET_MODE (x) == VOIDmode)
118 printf ("GET_MODE (operand%d)", XINT (x, 0));
119 else
120 printf ("%smode", GET_MODE_NAME (GET_MODE (x)));
65963943
RK
121 for (i = 0; i < XVECLEN (x, 1); i++)
122 {
123 printf (",\n\t\t");
ab55f58c 124 gen_exp (XVECEXP (x, 1, i), subroutine_type, used);
65963943
RK
125 }
126 printf (")");
127 return;
128
129 case MATCH_OPERATOR:
600555f5
KH
130 printf ("gen_rtx_fmt_");
131 for (i = 0; i < XVECLEN (x, 2); i++)
132 printf ("e");
133 printf (" (GET_CODE (operand%d)", XINT (x, 0));
65963943
RK
134 printf (", %smode", GET_MODE_NAME (GET_MODE (x)));
135 for (i = 0; i < XVECLEN (x, 2); i++)
136 {
137 printf (",\n\t\t");
ab55f58c 138 gen_exp (XVECEXP (x, 2, i), subroutine_type, used);
65963943
RK
139 }
140 printf (")");
141 return;
142
143 case MATCH_PARALLEL:
8fabbfe6 144 case MATCH_PAR_DUP:
65963943
RK
145 printf ("operand%d", XINT (x, 0));
146 return;
147
148 case MATCH_SCRATCH:
ede7cd44 149 gen_rtx_scratch (x, subroutine_type);
65963943
RK
150 return;
151
65963943
RK
152 case PC:
153 printf ("pc_rtx");
154 return;
3810076b
BS
155 case RETURN:
156 printf ("ret_rtx");
157 return;
26898771
BS
158 case SIMPLE_RETURN:
159 printf ("simple_return_rtx");
160 return;
3e89ed8d
JH
161 case CLOBBER:
162 if (REG_P (XEXP (x, 0)))
163 {
164 printf ("gen_hard_reg_clobber (%smode, %i)", GET_MODE_NAME (GET_MODE (XEXP (x, 0))),
165 REGNO (XEXP (x, 0)));
166 return;
167 }
168 break;
65963943
RK
169
170 case CC0:
171 printf ("cc0_rtx");
172 return;
173
174 case CONST_INT:
175 if (INTVAL (x) == 0)
3d678dca
RS
176 printf ("const0_rtx");
177 else if (INTVAL (x) == 1)
178 printf ("const1_rtx");
179 else if (INTVAL (x) == -1)
180 printf ("constm1_rtx");
11b635fe
KH
181 else if (-MAX_SAVED_CONST_INT <= INTVAL (x)
182 && INTVAL (x) <= MAX_SAVED_CONST_INT)
183 printf ("const_int_rtx[MAX_SAVED_CONST_INT + (%d)]",
184 (int) INTVAL (x));
3d678dca
RS
185 else if (INTVAL (x) == STORE_FLAG_VALUE)
186 printf ("const_true_rtx");
187 else
76d31c63
JL
188 {
189 printf ("GEN_INT (");
bb9b3805 190 printf (HOST_WIDE_INT_PRINT_DEC_C, INTVAL (x));
76d31c63
JL
191 printf (")");
192 }
3d678dca
RS
193 return;
194
195 case CONST_DOUBLE:
091a3ac7 196 case CONST_FIXED:
807e902e 197 case CONST_WIDE_INT:
3d678dca
RS
198 /* These shouldn't be written in MD files. Instead, the appropriate
199 routines in varasm.c should be called. */
b2d59f6f 200 gcc_unreachable ();
1d300e19
KG
201
202 default:
203 break;
65963943
RK
204 }
205
3b80f6ca 206 printf ("gen_rtx_");
65963943 207 print_code (code);
f7df4a84
RS
208 printf (" (");
209 if (!always_void_p (code))
210 {
211 printf ("%smode", GET_MODE_NAME (GET_MODE (x)));
212 sep = ",\n\t";
213 }
65963943
RK
214
215 fmt = GET_RTX_FORMAT (code);
216 len = GET_RTX_LENGTH (code);
217 for (i = 0; i < len; i++)
218 {
219 if (fmt[i] == '0')
220 break;
f7df4a84 221 fputs (sep, stdout);
b2d59f6f 222 switch (fmt[i])
65963943 223 {
b2d59f6f
NS
224 case 'e': case 'u':
225 gen_exp (XEXP (x, i), subroutine_type, used);
226 break;
227
228 case 'i':
229 printf ("%u", XINT (x, i));
230 break;
231
9fccb335
RS
232 case 'r':
233 printf ("%u", REGNO (x));
234 break;
235
b2d59f6f
NS
236 case 's':
237 printf ("\"%s\"", XSTR (x, i));
238 break;
239
240 case 'E':
241 {
242 int j;
243 printf ("gen_rtvec (%d", XVECLEN (x, i));
244 for (j = 0; j < XVECLEN (x, i); j++)
245 {
246 printf (",\n\t\t");
247 gen_exp (XVECEXP (x, i, j), subroutine_type, used);
248 }
249 printf (")");
250 break;
251 }
252
253 default:
254 gcc_unreachable ();
65963943 255 }
f7df4a84 256 sep = ",\n\t";
65963943
RK
257 }
258 printf (")");
3d7aafde 259}
3beaff21
RS
260
261/* Output code to emit the instruction patterns in VEC, with each element
262 becoming a separate instruction. USED is as for gen_exp. */
263
264static void
265gen_emit_seq (rtvec vec, char *used)
266{
267 for (int i = 0, len = GET_NUM_ELEM (vec); i < len; ++i)
268 {
9d8895c9 269 bool last_p = (i == len - 1);
3beaff21 270 rtx next = RTVEC_ELT (vec, i);
9d8895c9
RS
271 if (const char *name = get_emit_function (next))
272 {
273 printf (" %s (", name);
274 gen_exp (next, DEFINE_EXPAND, used);
275 printf (");\n");
276 if (!last_p && needs_barrier_p (next))
277 printf (" emit_barrier ();");
278 }
279 else
280 {
281 printf (" emit (");
282 gen_exp (next, DEFINE_EXPAND, used);
283 printf (", %s);\n", last_p ? "false" : "true");
284 }
3beaff21
RS
285 }
286}
65963943
RK
287\f
288/* Generate the `gen_...' function for a DEFINE_INSN. */
289
290static void
5d2d3e43 291gen_insn (md_rtx_info *info)
65963943 292{
e792559a 293 struct pattern_stats stats;
b3694847 294 int i;
65963943
RK
295
296 /* See if the pattern for this insn ends with a group of CLOBBERs of (hard)
297 registers or MATCH_SCRATCHes. If so, store away the information for
0f41302f 298 later. */
65963943 299
5d2d3e43 300 rtx insn = info->def;
65963943
RK
301 if (XVEC (insn, 1))
302 {
751aa7cc
RK
303 int has_hard_reg = 0;
304
65963943 305 for (i = XVECLEN (insn, 1) - 1; i > 0; i--)
751aa7cc
RK
306 {
307 if (GET_CODE (XVECEXP (insn, 1, i)) != CLOBBER)
308 break;
309
f8cfc6aa 310 if (REG_P (XEXP (XVECEXP (insn, 1, i), 0)))
751aa7cc
RK
311 has_hard_reg = 1;
312 else if (GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != MATCH_SCRATCH)
313 break;
314 }
65963943
RK
315
316 if (i != XVECLEN (insn, 1) - 1)
317 {
b3694847 318 struct clobber_pat *p;
5ed6ace5 319 struct clobber_ent *link = XNEW (struct clobber_ent);
b3694847 320 int j;
e5f6a288 321
5d2d3e43 322 link->code_number = info->index;
e5f6a288
RK
323
324 /* See if any previous CLOBBER_LIST entry is the same as this
325 one. */
326
327 for (p = clobber_list; p; p = p->next)
328 {
329 if (p->first_clobber != i + 1
330 || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1))
331 continue;
332
333 for (j = i + 1; j < XVECLEN (insn, 1); j++)
334 {
8ad97cfc
KG
335 rtx old_rtx = XEXP (XVECEXP (p->pattern, 1, j), 0);
336 rtx new_rtx = XEXP (XVECEXP (insn, 1, j), 0);
e5f6a288 337
8ad97cfc 338 /* OLD and NEW_INSN are the same if both are to be a SCRATCH
3d7aafde 339 of the same mode,
e5f6a288 340 or if both are registers of the same mode and number. */
8ad97cfc
KG
341 if (! (GET_MODE (old_rtx) == GET_MODE (new_rtx)
342 && ((GET_CODE (old_rtx) == MATCH_SCRATCH
343 && GET_CODE (new_rtx) == MATCH_SCRATCH)
344 || (REG_P (old_rtx) && REG_P (new_rtx)
345 && REGNO (old_rtx) == REGNO (new_rtx)))))
e5f6a288
RK
346 break;
347 }
3d7aafde 348
e5f6a288
RK
349 if (j == XVECLEN (insn, 1))
350 break;
351 }
352
353 if (p == 0)
354 {
5ed6ace5 355 p = XNEW (struct clobber_pat);
3d7aafde 356
e5f6a288
RK
357 p->insns = 0;
358 p->pattern = insn;
359 p->first_clobber = i + 1;
360 p->next = clobber_list;
751aa7cc 361 p->has_hard_reg = has_hard_reg;
e5f6a288
RK
362 clobber_list = p;
363 }
364
365 link->next = p->insns;
366 p->insns = link;
65963943
RK
367 }
368 }
369
6b6ca844
RK
370 /* Don't mention instructions whose names are the null string
371 or begin with '*'. They are in the machine description just
372 to be recognized. */
373 if (XSTR (insn, 0)[0] == 0 || XSTR (insn, 0)[0] == '*')
65963943
RK
374 return;
375
5d2d3e43 376 printf ("/* %s:%d */\n", info->loc.filename, info->loc.lineno);
821e35ba 377
85a45cbb 378 /* Find out how many operands this function has. */
e792559a
RS
379 get_pattern_stats (&stats, XVEC (insn, 1));
380 if (stats.max_dup_opno > stats.max_opno)
5d2d3e43 381 fatal_at (info->loc, "match_dup operand number has no match_operand");
65963943
RK
382
383 /* Output the function name and argument declarations. */
384 printf ("rtx\ngen_%s (", XSTR (insn, 0));
e792559a
RS
385 if (stats.num_generator_args)
386 for (i = 0; i < stats.num_generator_args; i++)
6906ba40
KG
387 if (i)
388 printf (",\n\trtx operand%d ATTRIBUTE_UNUSED", i);
389 else
390 printf ("rtx operand%d ATTRIBUTE_UNUSED", i);
391 else
392 printf ("void");
65963943 393 printf (")\n");
65963943
RK
394 printf ("{\n");
395
6614fd40 396 /* Output code to construct and return the rtl for the instruction body. */
65963943 397
313d38e3
RS
398 rtx pattern = add_implicit_parallel (XVEC (insn, 1));
399 /* ??? This is the traditional behavior, but seems suspect. */
400 char *used = (XVECLEN (insn, 1) == 1
401 ? NULL
402 : XCNEWVEC (char, stats.num_generator_args));
403 printf (" return ");
404 gen_exp (pattern, DEFINE_INSN, used);
405 printf (";\n}\n\n");
406 XDELETEVEC (used);
65963943
RK
407}
408\f
409/* Generate the `gen_...' function for a DEFINE_EXPAND. */
410
411static void
5d2d3e43 412gen_expand (md_rtx_info *info)
65963943 413{
e792559a 414 struct pattern_stats stats;
b3694847 415 int i;
329b3cc3 416 char *used;
65963943 417
5d2d3e43 418 rtx expand = info->def;
65963943 419 if (strlen (XSTR (expand, 0)) == 0)
5d2d3e43 420 fatal_at (info->loc, "define_expand lacks a name");
65963943 421 if (XVEC (expand, 1) == 0)
5d2d3e43
RS
422 fatal_at (info->loc, "define_expand for %s lacks a pattern",
423 XSTR (expand, 0));
65963943 424
85a45cbb 425 /* Find out how many operands this function has. */
e792559a 426 get_pattern_stats (&stats, XVEC (expand, 1));
65963943
RK
427
428 /* Output the function name and argument declarations. */
429 printf ("rtx\ngen_%s (", XSTR (expand, 0));
e792559a
RS
430 if (stats.num_generator_args)
431 for (i = 0; i < stats.num_generator_args; i++)
6906ba40
KG
432 if (i)
433 printf (",\n\trtx operand%d", i);
434 else
435 printf ("rtx operand%d", i);
436 else
437 printf ("void");
65963943 438 printf (")\n");
65963943
RK
439 printf ("{\n");
440
441 /* If we don't have any C code to write, only one insn is being written,
442 and no MATCH_DUPs are present, we can just return the desired insn
443 like we do for a DEFINE_INSN. This saves memory. */
444 if ((XSTR (expand, 3) == 0 || *XSTR (expand, 3) == '\0')
e792559a 445 && stats.max_opno >= stats.max_dup_opno
65963943
RK
446 && XVECLEN (expand, 1) == 1)
447 {
448 printf (" return ");
ab55f58c 449 gen_exp (XVECEXP (expand, 1, 0), DEFINE_EXPAND, NULL);
65963943
RK
450 printf (";\n}\n\n");
451 return;
452 }
453
454 /* For each operand referred to only with MATCH_DUPs,
455 make a local variable. */
e792559a 456 for (i = stats.num_generator_args; i <= stats.max_dup_opno; i++)
65963943 457 printf (" rtx operand%d;\n", i);
e792559a 458 for (; i <= stats.max_scratch_opno; i++)
b3656137 459 printf (" rtx operand%d ATTRIBUTE_UNUSED;\n", i);
e67d1102 460 printf (" rtx_insn *_val = 0;\n");
65963943
RK
461 printf (" start_sequence ();\n");
462
463 /* The fourth operand of DEFINE_EXPAND is some code to be executed
464 before the actual construction.
465 This code expects to refer to `operands'
466 just as the output-code in a DEFINE_INSN does,
467 but here `operands' is an automatic array.
468 So copy the operand values there before executing it. */
469 if (XSTR (expand, 3) && *XSTR (expand, 3))
470 {
e2bef702 471 printf (" {\n");
e792559a
RS
472 if (stats.num_operand_vars > 0)
473 printf (" rtx operands[%d];\n", stats.num_operand_vars);
474
65963943 475 /* Output code to copy the arguments into `operands'. */
e792559a 476 for (i = 0; i < stats.num_generator_args; i++)
e2bef702 477 printf (" operands[%d] = operand%d;\n", i, i);
65963943
RK
478
479 /* Output the special code to be executed before the sequence
480 is generated. */
d2a3ce4e 481 print_md_ptr_loc (XSTR (expand, 3));
65963943
RK
482 printf ("%s\n", XSTR (expand, 3));
483
484 /* Output code to copy the arguments back out of `operands'
485 (unless we aren't going to use them at all). */
486 if (XVEC (expand, 1) != 0)
487 {
e792559a 488 for (i = 0; i < stats.num_operand_vars; i++)
60d3aec4
JJ
489 {
490 printf (" operand%d = operands[%d];\n", i, i);
491 printf (" (void) operand%d;\n", i);
492 }
65963943 493 }
e2bef702 494 printf (" }\n");
65963943
RK
495 }
496
e792559a 497 used = XCNEWVEC (char, stats.num_operand_vars);
3beaff21 498 gen_emit_seq (XVEC (expand, 1), used);
329b3cc3
KK
499 XDELETEVEC (used);
500
2f937369 501 /* Call `get_insns' to extract the list of all the
65963943
RK
502 insns emitted within this gen_... function. */
503
2f937369 504 printf (" _val = get_insns ();\n");
65963943
RK
505 printf (" end_sequence ();\n");
506 printf (" return _val;\n}\n\n");
507}
508
2f937369 509/* Like gen_expand, but generates insns resulting from splitting SPLIT. */
0f41302f 510
65963943 511static void
5d2d3e43 512gen_split (md_rtx_info *info)
65963943 513{
e792559a 514 struct pattern_stats stats;
b3694847 515 int i;
5d2d3e43 516 rtx split = info->def;
27c38fbe
KG
517 const char *const name =
518 ((GET_CODE (split) == DEFINE_PEEPHOLE2) ? "peephole2" : "split");
751aa7cc 519 const char *unused;
ab55f58c 520 char *used;
ede7cd44 521
65963943 522 if (XVEC (split, 0) == 0)
5d2d3e43
RS
523 fatal_at (info->loc, "%s lacks a pattern",
524 GET_RTX_NAME (GET_CODE (split)));
65963943 525 else if (XVEC (split, 2) == 0)
5d2d3e43
RS
526 fatal_at (info->loc, "%s lacks a replacement pattern",
527 GET_RTX_NAME (GET_CODE (split)));
65963943
RK
528
529 /* Find out how many operands this function has. */
530
e792559a
RS
531 get_pattern_stats (&stats, XVEC (split, 2));
532 unused = (stats.num_operand_vars == 0 ? " ATTRIBUTE_UNUSED" : "");
533 used = XCNEWVEC (char, stats.num_operand_vars);
65963943 534
ede7cd44
RH
535 /* Output the prototype, function name and argument declarations. */
536 if (GET_CODE (split) == DEFINE_PEEPHOLE2)
537 {
bb5c4956 538 printf ("extern rtx_insn *gen_%s_%d (rtx_insn *, rtx *);\n",
5d2d3e43
RS
539 name, info->index);
540 printf ("rtx_insn *\ngen_%s_%d (rtx_insn *curr_insn ATTRIBUTE_UNUSED,"
541 " rtx *operands%s)\n",
542 name, info->index, unused);
ede7cd44
RH
543 }
544 else
545 {
bb5c4956 546 printf ("extern rtx_insn *gen_split_%d (rtx_insn *, rtx *);\n",
5d2d3e43 547 info->index);
bb5c4956
MM
548 printf ("rtx_insn *\ngen_split_%d "
549 "(rtx_insn *curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
5d2d3e43 550 info->index, unused);
ede7cd44 551 }
65963943
RK
552 printf ("{\n");
553
554 /* Declare all local variables. */
e792559a 555 for (i = 0; i < stats.num_operand_vars; i++)
65963943 556 printf (" rtx operand%d;\n", i);
bb5c4956 557 printf (" rtx_insn *_val = NULL;\n");
ede7cd44
RH
558
559 if (GET_CODE (split) == DEFINE_PEEPHOLE2)
560 output_peephole2_scratches (split);
561
eddcad13
SB
562 printf (" if (dump_file)\n");
563 printf (" fprintf (dump_file, \"Splitting with gen_%s_%d\\n\");\n",
5d2d3e43 564 name, info->index);
eddcad13 565
65963943
RK
566 printf (" start_sequence ();\n");
567
568 /* The fourth operand of DEFINE_SPLIT is some code to be executed
569 before the actual construction. */
570
571 if (XSTR (split, 3))
7445392c 572 {
d2a3ce4e 573 print_md_ptr_loc (XSTR (split, 3));
7445392c
RS
574 printf ("%s\n", XSTR (split, 3));
575 }
65963943
RK
576
577 /* Output code to copy the arguments back out of `operands' */
e792559a 578 for (i = 0; i < stats.num_operand_vars; i++)
60d3aec4
JJ
579 {
580 printf (" operand%d = operands[%d];\n", i, i);
581 printf (" (void) operand%d;\n", i);
582 }
65963943 583
3beaff21 584 gen_emit_seq (XVEC (split, 2), used);
65963943 585
2f937369 586 /* Call `get_insns' to make a list of all the
65963943
RK
587 insns emitted within this gen_... function. */
588
2f937369 589 printf (" _val = get_insns ();\n");
65963943
RK
590 printf (" end_sequence ();\n");
591 printf (" return _val;\n}\n\n");
ab55f58c
RH
592
593 free (used);
65963943
RK
594}
595\f
596/* Write a function, `add_clobbers', that is given a PARALLEL of sufficient
597 size for the insn and an INSN_CODE, and inserts the required CLOBBERs at
598 the end of the vector. */
599
600static void
7e51717c 601output_add_clobbers (void)
65963943
RK
602{
603 struct clobber_pat *clobber;
e5f6a288 604 struct clobber_ent *ent;
65963943
RK
605 int i;
606
6906ba40 607 printf ("\n\nvoid\nadd_clobbers (rtx pattern ATTRIBUTE_UNUSED, int insn_code_number)\n");
65963943 608 printf ("{\n");
65963943
RK
609 printf (" switch (insn_code_number)\n");
610 printf (" {\n");
611
612 for (clobber = clobber_list; clobber; clobber = clobber->next)
613 {
e5f6a288
RK
614 for (ent = clobber->insns; ent; ent = ent->next)
615 printf (" case %d:\n", ent->code_number);
65963943
RK
616
617 for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++)
618 {
619 printf (" XVECEXP (pattern, 0, %d) = ", i);
ede7cd44 620 gen_exp (XVECEXP (clobber->pattern, 1, i),
ab55f58c 621 GET_CODE (clobber->pattern), NULL);
65963943
RK
622 printf (";\n");
623 }
624
e5f6a288 625 printf (" break;\n\n");
65963943
RK
626 }
627
628 printf (" default:\n");
b2d59f6f 629 printf (" gcc_unreachable ();\n");
65963943
RK
630 printf (" }\n");
631 printf ("}\n");
632}
633\f
6327d36a
RK
634/* Write a function, `added_clobbers_hard_reg_p' that is given an insn_code
635 number that will have clobbers added (as indicated by `recog') and returns
636 1 if those include a clobber of a hard reg or 0 if all of them just clobber
637 SCRATCH. */
751aa7cc
RK
638
639static void
3d7aafde 640output_added_clobbers_hard_reg_p (void)
751aa7cc
RK
641{
642 struct clobber_pat *clobber;
643 struct clobber_ent *ent;
a29b099d 644 int clobber_p, used;
751aa7cc 645
6906ba40 646 printf ("\n\nint\nadded_clobbers_hard_reg_p (int insn_code_number)\n");
751aa7cc
RK
647 printf ("{\n");
648 printf (" switch (insn_code_number)\n");
649 printf (" {\n");
650
651 for (clobber_p = 0; clobber_p <= 1; clobber_p++)
652 {
a29b099d 653 used = 0;
751aa7cc
RK
654 for (clobber = clobber_list; clobber; clobber = clobber->next)
655 if (clobber->has_hard_reg == clobber_p)
656 for (ent = clobber->insns; ent; ent = ent->next)
a29b099d
JJ
657 {
658 printf (" case %d:\n", ent->code_number);
659 used++;
660 }
751aa7cc 661
a29b099d
JJ
662 if (used)
663 printf (" return %d;\n\n", clobber_p);
751aa7cc
RK
664 }
665
666 printf (" default:\n");
b2d59f6f 667 printf (" gcc_unreachable ();\n");
751aa7cc
RK
668 printf (" }\n");
669 printf ("}\n");
670}
671\f
ede7cd44 672/* Generate code to invoke find_free_register () as needed for the
dc297297 673 scratch registers used by the peephole2 pattern in SPLIT. */
ede7cd44
RH
674
675static void
3d7aafde 676output_peephole2_scratches (rtx split)
ede7cd44
RH
677{
678 int i;
679 int insn_nr = 0;
f1ed99cd 680 bool first = true;
ede7cd44
RH
681
682 for (i = 0; i < XVECLEN (split, 0); i++)
683 {
684 rtx elt = XVECEXP (split, 0, i);
685 if (GET_CODE (elt) == MATCH_SCRATCH)
686 {
687 int last_insn_nr = insn_nr;
688 int cur_insn_nr = insn_nr;
689 int j;
690 for (j = i + 1; j < XVECLEN (split, 0); j++)
691 if (GET_CODE (XVECEXP (split, 0, j)) == MATCH_DUP)
692 {
693 if (XINT (XVECEXP (split, 0, j), 0) == XINT (elt, 0))
694 last_insn_nr = cur_insn_nr;
695 }
696 else if (GET_CODE (XVECEXP (split, 0, j)) != MATCH_SCRATCH)
697 cur_insn_nr++;
23280139 698
f1ed99cd
JJ
699 if (first)
700 {
701 printf (" HARD_REG_SET _regs_allocated;\n");
702 printf (" CLEAR_HARD_REG_SET (_regs_allocated);\n");
703 first = false;
704 }
705
23280139 706 printf (" if ((operands[%d] = peep2_find_free_register (%d, %d, \"%s\", %smode, &_regs_allocated)) == NULL_RTX)\n\
3d7aafde 707 return NULL;\n",
ede7cd44 708 XINT (elt, 0),
23280139 709 insn_nr, last_insn_nr,
ede7cd44
RH
710 XSTR (elt, 1),
711 GET_MODE_NAME (GET_MODE (elt)));
712
713 }
714 else if (GET_CODE (elt) != MATCH_DUP)
715 insn_nr++;
716 }
717}
65963943 718
65963943 719int
3d7aafde 720main (int argc, char **argv)
65963943 721{
f8b6598e 722 progname = "genemit";
65963943 723
600ab3fc 724 if (!init_rtx_reader_args (argc, argv))
c88c0d42 725 return (FATAL_EXIT_CODE);
65963943 726
65963943
RK
727 /* Assign sequential codes to all entries in the machine description
728 in parallel with the tables in insn-output.c. */
729
65963943
RK
730 printf ("/* Generated automatically by the program `genemit'\n\
731from the machine description file `md'. */\n\n");
732
733 printf ("#include \"config.h\"\n");
729da3f5 734 printf ("#include \"system.h\"\n");
4977bab6 735 printf ("#include \"coretypes.h\"\n");
c7131fb2 736 printf ("#include \"backend.h\"\n");
9fdcd34e 737 printf ("#include \"predict.h\"\n");
4d648807 738 printf ("#include \"tree.h\"\n");
c7131fb2
AM
739 printf ("#include \"rtl.h\"\n");
740 printf ("#include \"alias.h\"\n");
d8a2d370
DN
741 printf ("#include \"varasm.h\"\n");
742 printf ("#include \"stor-layout.h\"\n");
743 printf ("#include \"calls.h\"\n");
6baf1cc8 744 printf ("#include \"tm_p.h\"\n");
36566b39 745 printf ("#include \"flags.h\"\n");
36566b39
PK
746 printf ("#include \"insn-config.h\"\n");
747 printf ("#include \"expmed.h\"\n");
748 printf ("#include \"dojump.h\"\n");
749 printf ("#include \"explow.h\"\n");
750 printf ("#include \"emit-rtl.h\"\n");
751 printf ("#include \"stmt.h\"\n");
65963943 752 printf ("#include \"expr.h\"\n");
b0710fe1 753 printf ("#include \"insn-codes.h\"\n");
e78d8e51 754 printf ("#include \"optabs.h\"\n");
c413e1b5 755 printf ("#include \"dfp.h\"\n");
65963943 756 printf ("#include \"output.h\"\n");
23280139 757 printf ("#include \"recog.h\"\n");
c7131fb2 758 printf ("#include \"df.h\"\n");
ede7cd44 759 printf ("#include \"resource.h\"\n");
d80eb1e1 760 printf ("#include \"reload.h\"\n");
79a3f089 761 printf ("#include \"diagnostic-core.h\"\n");
5abc5de9 762 printf ("#include \"regs.h\"\n");
279bb624 763 printf ("#include \"tm-constrs.h\"\n");
5abc5de9 764 printf ("#include \"ggc.h\"\n");
eddcad13 765 printf ("#include \"dumpfile.h\"\n");
3b1552c1 766 printf ("#include \"target.h\"\n\n");
53bfe9cd 767 printf ("#define FAIL return (end_sequence (), _val)\n");
2f937369 768 printf ("#define DONE return (_val = get_insns (), end_sequence (), _val)\n\n");
65963943
RK
769
770 /* Read the machine description. */
771
5d2d3e43
RS
772 md_rtx_info info;
773 while (read_md_rtx (&info))
774 switch (GET_CODE (info.def))
775 {
776 case DEFINE_INSN:
777 gen_insn (&info);
c88c0d42 778 break;
ede7cd44 779
5d2d3e43
RS
780 case DEFINE_EXPAND:
781 printf ("/* %s:%d */\n", info.loc.filename, info.loc.lineno);
782 gen_expand (&info);
783 break;
821e35ba 784
5d2d3e43
RS
785 case DEFINE_SPLIT:
786 printf ("/* %s:%d */\n", info.loc.filename, info.loc.lineno);
787 gen_split (&info);
788 break;
821e35ba 789
5d2d3e43
RS
790 case DEFINE_PEEPHOLE2:
791 printf ("/* %s:%d */\n", info.loc.filename, info.loc.lineno);
792 gen_split (&info);
793 break;
821e35ba 794
5d2d3e43
RS
795 default:
796 break;
797 }
65963943 798
751aa7cc
RK
799 /* Write out the routines to add CLOBBERs to a pattern and say whether they
800 clobber a hard reg. */
65963943 801 output_add_clobbers ();
751aa7cc 802 output_added_clobbers_hard_reg_p ();
65963943 803
65963943 804 fflush (stdout);
c1b59dce 805 return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
65963943 806}