1/* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2023 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
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
8Software Foundation; either version 3, or (at your option) any later
9version.
10
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.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#include "bconfig.h"
21#include "system.h"
22#include "errors.h"
23
24/* enum mode_class is normally defined by machmode.h but we can't
25 include that header here. */
26#include "mode-classes.def"
27
28#define DEF_MODE_CLASS(M) M
29enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
30#undef DEF_MODE_CLASS
31
32/* Text names of mode classes, for output. */
33#define DEF_MODE_CLASS(M) #M
34static const char *const mode_class_names[MAX_MODE_CLASS] =
35{
36 MODE_CLASSES
37};
38#undef DEF_MODE_CLASS
39#undef MODE_CLASSES
40
41#ifdef EXTRA_MODES_FILE
42# define HAVE_EXTRA_MODES 1
43#else
44# define HAVE_EXTRA_MODES 0
45# define EXTRA_MODES_FILE ""
46#endif
47
48/* Data structure for building up what we know about a mode.
49 They're clustered by mode class. */
50struct mode_data
51{
52 struct mode_data *next; /* next this class - arbitrary order */
53
54 const char *name; /* printable mode name -- SI, not SImode */
55 enum mode_class cl; /* this mode class */
56 unsigned int order; /* top-level sorting order */
57 unsigned int precision; /* size in bits, equiv to TYPE_PRECISION */
58 unsigned int bytesize; /* storage size in addressable units */
59 unsigned int ncomponents; /* number of subunits */
60 unsigned int alignment; /* mode alignment */
61 const char *format; /* floating point format - float modes only */
62
63 struct mode_data *component; /* mode of components */
64 struct mode_data *wider; /* next wider mode */
65
66 struct mode_data *contained; /* Pointer to list of modes that have
67 this mode as a component. */
68 struct mode_data *next_cont; /* Next mode in that list. */
69
70 struct mode_data *complex; /* complex type with mode as component. */
71 const char *file; /* file and line of definition, */
72 unsigned int line; /* for error reporting */
73 unsigned int counter; /* Rank ordering of modes */
74 unsigned int ibit; /* the number of integral bits */
75 unsigned int fbit; /* the number of fractional bits */
76 bool need_nunits_adj; /* true if this mode needs dynamic nunits
77 adjustment */
78 bool need_bytesize_adj; /* true if this mode needs dynamic size
79 adjustment */
80 unsigned int int_n; /* If nonzero, then __int<INT_N> will be defined */
81 bool boolean;
82};
83
84static struct mode_data *modes[MAX_MODE_CLASS];
85static unsigned int n_modes[MAX_MODE_CLASS];
86static struct mode_data *void_mode;
87
88static const struct mode_data blank_mode = {
89 .next: 0, .name: "<unknown>", .cl: MAX_MODE_CLASS,
90 .order: 0, .precision: -1U, .bytesize: -1U, .ncomponents: -1U, .alignment: -1U,
91 .format: 0, .component: 0, .wider: 0, .contained: 0, .next_cont: 0, .complex: 0,
92 .file: "<unknown>", .line: 0, .counter: 0, .ibit: 0, .fbit: 0, .need_nunits_adj: false, .need_bytesize_adj: false, .int_n: 0,
93 .boolean: false
94};
95
96static htab_t modes_by_name;
97
98/* Data structure for recording target-specified runtime adjustments
99 to a particular mode. We support varying the byte size, the
100 alignment, and the floating point format. */
101struct mode_adjust
102{
103 struct mode_adjust *next;
104 struct mode_data *mode;
105 const char *adjustment;
106
107 const char *file;
108 unsigned int line;
109};
110
111static struct mode_adjust *adj_nunits;
112static struct mode_adjust *adj_bytesize;
113static struct mode_adjust *adj_alignment;
114static struct mode_adjust *adj_format;
115static struct mode_adjust *adj_ibit;
116static struct mode_adjust *adj_fbit;
117static struct mode_adjust *adj_precision;
118
119/* Mode class operations. */
120static enum mode_class
121complex_class (enum mode_class c)
122{
123 switch (c)
124 {
125 case MODE_INT: return MODE_COMPLEX_INT;
126 case MODE_PARTIAL_INT: return MODE_COMPLEX_INT;
127 case MODE_FLOAT: return MODE_COMPLEX_FLOAT;
128 default:
129 error ("no complex class for class %s", mode_class_names[c]);
130 return MODE_RANDOM;
131 }
132}
133
134static enum mode_class
135vector_class (enum mode_class cl)
136{
137 switch (cl)
138 {
139 case MODE_INT: return MODE_VECTOR_INT;
140 case MODE_FLOAT: return MODE_VECTOR_FLOAT;
141 case MODE_FRACT: return MODE_VECTOR_FRACT;
142 case MODE_UFRACT: return MODE_VECTOR_UFRACT;
143 case MODE_ACCUM: return MODE_VECTOR_ACCUM;
144 case MODE_UACCUM: return MODE_VECTOR_UACCUM;
145 default:
146 error ("no vector class for class %s", mode_class_names[cl]);
147 return MODE_RANDOM;
148 }
149}
150
151/* Utility routines. */
152static inline struct mode_data *
153find_mode (const char *name)
154{
155 struct mode_data key;
156
157 key.name = name;
158 return (struct mode_data *) htab_find (modes_by_name, &key);
159}
160
161static struct mode_data *
162new_mode (enum mode_class cl, const char *name,
163 const char *file, unsigned int line)
164{
165 struct mode_data *m;
166 static unsigned int count = 0;
167
168 m = find_mode (name);
169 if (m)
170 {
171 error ("%s:%d: duplicate definition of mode \"%s\"",
172 trim_filename (file), line, name);
173 error ("%s:%d: previous definition here", m->file, m->line);
174 return m;
175 }
176
177 m = XNEW (struct mode_data);
178 memcpy (dest: m, src: &blank_mode, n: sizeof (struct mode_data));
179 m->cl = cl;
180 m->name = name;
181 if (file)
182 m->file = trim_filename (file);
183 m->line = line;
184 m->counter = count++;
185
186 m->next = modes[cl];
187 modes[cl] = m;
188 n_modes[cl]++;
189
190 *htab_find_slot (modes_by_name, m, INSERT) = m;
191
192 return m;
193}
194
195static hashval_t
196hash_mode (const void *p)
197{
198 const struct mode_data *m = (const struct mode_data *)p;
199 return htab_hash_string (m->name);
200}
201
202static int
203eq_mode (const void *p, const void *q)
204{
205 const struct mode_data *a = (const struct mode_data *)p;
206 const struct mode_data *b = (const struct mode_data *)q;
207
208 return !strcmp (s1: a->name, s2: b->name);
209}
210
211#define for_all_modes(C, M) \
212 for (C = 0; C < MAX_MODE_CLASS; C++) \
213 for (M = modes[C]; M; M = M->next)
214
215static void ATTRIBUTE_UNUSED
216new_adjust (const char *name,
217 struct mode_adjust **category, const char *catname,
218 const char *adjustment,
219 enum mode_class required_class_from,
220 enum mode_class required_class_to,
221 const char *file, unsigned int line)
222{
223 struct mode_data *mode = find_mode (name);
224 struct mode_adjust *a;
225
226 file = trim_filename (file);
227
228 if (!mode)
229 {
230 error ("%s:%d: no mode \"%s\"", file, line, name);
231 return;
232 }
233
234 if (required_class_from != MODE_RANDOM
235 && (mode->cl < required_class_from || mode->cl > required_class_to))
236 {
237 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
238 file, line, name, mode_class_names[required_class_from] + 5,
239 mode_class_names[required_class_to] + 5);
240 return;
241 }
242
243 for (a = *category; a; a = a->next)
244 if (a->mode == mode)
245 {
246 error ("%s:%d: mode \"%s\" already has a %s adjustment",
247 file, line, name, catname);
248 error ("%s:%d: previous adjustment here", a->file, a->line);
249 return;
250 }
251
252 a = XNEW (struct mode_adjust);
253 a->mode = mode;
254 a->adjustment = adjustment;
255 a->file = file;
256 a->line = line;
257
258 a->next = *category;
259 *category = a;
260}
261
262/* Diagnose failure to meet expectations in a partially filled out
263 mode structure. */
264enum requirement { SET, UNSET, OPTIONAL };
265
266#define validate_field_(mname, fname, req, val, unset, file, line) do { \
267 switch (req) \
268 { \
269 case SET: \
270 if (val == unset) \
271 error ("%s:%d: (%s) field %s must be set", \
272 file, line, mname, fname); \
273 break; \
274 case UNSET: \
275 if (val != unset) \
276 error ("%s:%d: (%s) field %s must not be set", \
277 file, line, mname, fname); \
278 case OPTIONAL: \
279 break; \
280 } \
281} while (0)
282
283#define validate_field(M, F) \
284 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
285
286static void
287validate_mode (struct mode_data *m,
288 enum requirement r_precision,
289 enum requirement r_bytesize,
290 enum requirement r_component,
291 enum requirement r_ncomponents,
292 enum requirement r_format)
293{
294 validate_field (m, precision);
295 validate_field (m, bytesize);
296 validate_field (m, component);
297 validate_field (m, ncomponents);
298 validate_field (m, format);
299}
300#undef validate_field
301#undef validate_field_
302
303/* Given a partially-filled-out mode structure, figure out what we can
304 and fill the rest of it in; die if it isn't enough. */
305static void
306complete_mode (struct mode_data *m)
307{
308 unsigned int alignment;
309
310 if (!m->name)
311 {
312 error ("%s:%d: mode with no name", m->file, m->line);
313 return;
314 }
315 if (m->cl == MAX_MODE_CLASS)
316 {
317 error ("%s:%d: %smode has no mode class", m->file, m->line, m->name);
318 return;
319 }
320
321 switch (m->cl)
322 {
323 case MODE_RANDOM:
324 /* Nothing more need be said. */
325 if (!strcmp (s1: m->name, s2: "VOID"))
326 void_mode = m;
327
328 validate_mode (m, r_precision: UNSET, r_bytesize: UNSET, r_component: UNSET, r_ncomponents: UNSET, r_format: UNSET);
329
330 m->precision = 0;
331 m->bytesize = 0;
332 m->ncomponents = 0;
333 m->component = 0;
334 break;
335
336 case MODE_CC:
337 /* Again, nothing more need be said. For historical reasons,
338 the size of a CC mode is four units. */
339 validate_mode (m, r_precision: UNSET, r_bytesize: UNSET, r_component: UNSET, r_ncomponents: UNSET, r_format: UNSET);
340
341 m->bytesize = 4;
342 m->ncomponents = 1;
343 m->component = 0;
344 break;
345
346 case MODE_INT:
347 case MODE_FLOAT:
348 case MODE_DECIMAL_FLOAT:
349 case MODE_FRACT:
350 case MODE_UFRACT:
351 case MODE_ACCUM:
352 case MODE_UACCUM:
353 /* A scalar mode must have a byte size, may have a bit size,
354 and must not have components. A float mode must have a
355 format. */
356 validate_mode (m, r_precision: OPTIONAL, r_bytesize: SET, r_component: UNSET, r_ncomponents: UNSET,
357 r_format: (m->cl == MODE_FLOAT || m->cl == MODE_DECIMAL_FLOAT)
358 ? SET : UNSET);
359
360 m->ncomponents = 1;
361 m->component = 0;
362 break;
363
364 case MODE_OPAQUE:
365 /* Opaque modes have size and precision. */
366 validate_mode (m, r_precision: OPTIONAL, r_bytesize: SET, r_component: UNSET, r_ncomponents: UNSET, r_format: UNSET);
367
368 m->ncomponents = 1;
369 m->component = 0;
370 break;
371
372 case MODE_PARTIAL_INT:
373 /* A partial integer mode uses ->component to say what the
374 corresponding full-size integer mode is, and may also
375 specify a bit size. */
376 validate_mode (m, r_precision: OPTIONAL, r_bytesize: UNSET, r_component: SET, r_ncomponents: UNSET, r_format: UNSET);
377
378 m->bytesize = m->component->bytesize;
379
380 m->ncomponents = 1;
381 break;
382
383 case MODE_COMPLEX_INT:
384 case MODE_COMPLEX_FLOAT:
385 /* Complex modes should have a component indicated, but no more. */
386 validate_mode (m, r_precision: UNSET, r_bytesize: UNSET, r_component: SET, r_ncomponents: UNSET, r_format: UNSET);
387 m->ncomponents = 2;
388 if (m->component->precision != (unsigned int)-1)
389 m->precision = 2 * m->component->precision;
390 m->bytesize = 2 * m->component->bytesize;
391 break;
392
393 case MODE_VECTOR_BOOL:
394 validate_mode (m, r_precision: UNSET, r_bytesize: SET, r_component: SET, r_ncomponents: SET, r_format: UNSET);
395 break;
396
397 case MODE_VECTOR_INT:
398 case MODE_VECTOR_FLOAT:
399 case MODE_VECTOR_FRACT:
400 case MODE_VECTOR_UFRACT:
401 case MODE_VECTOR_ACCUM:
402 case MODE_VECTOR_UACCUM:
403 /* Vector modes should have a component and a number of components. */
404 validate_mode (m, r_precision: UNSET, r_bytesize: UNSET, r_component: SET, r_ncomponents: SET, r_format: UNSET);
405 if (m->component->precision != (unsigned int)-1)
406 m->precision = m->ncomponents * m->component->precision;
407 m->bytesize = m->ncomponents * m->component->bytesize;
408 break;
409
410 default:
411 gcc_unreachable ();
412 }
413
414 /* If not already specified, the mode alignment defaults to the largest
415 power of two that divides the size of the object. Complex types are
416 not more aligned than their contents. */
417 if (m->cl == MODE_COMPLEX_INT || m->cl == MODE_COMPLEX_FLOAT)
418 alignment = m->component->bytesize;
419 else
420 alignment = m->bytesize;
421
422 m->alignment = alignment & (~alignment + 1);
423
424 /* If this mode has components, make the component mode point back
425 to this mode, for the sake of adjustments. */
426 if (m->component)
427 {
428 m->next_cont = m->component->contained;
429 m->component->contained = m;
430 }
431}
432
433static void
434complete_all_modes (void)
435{
436 struct mode_data *m;
437 int cl;
438
439 for_all_modes (cl, m)
440 complete_mode (m);
441}
442
443/* For each mode in class CLASS, construct a corresponding complex mode. */
444#define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
445static void
446make_complex_modes (enum mode_class cl,
447 const char *file, unsigned int line)
448{
449 struct mode_data *m;
450 struct mode_data *c;
451 enum mode_class cclass = complex_class (c: cl);
452
453 if (cclass == MODE_RANDOM)
454 return;
455
456 for (m = modes[cl]; m; m = m->next)
457 {
458 char *p, *buf;
459 size_t m_len;
460
461 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
462 if (m->boolean)
463 continue;
464
465 m_len = strlen (s: m->name);
466 /* The leading "1 +" is in case we prepend a "C" below. */
467 buf = (char *) xmalloc (1 + m_len + 1);
468
469 /* Float complex modes are named SCmode, etc.
470 Int complex modes are named CSImode, etc.
471 This inconsistency should be eliminated. */
472 p = 0;
473 if (cl == MODE_FLOAT)
474 {
475 memcpy (dest: buf, src: m->name, n: m_len + 1);
476 p = strchr (s: buf, c: 'F');
477 if (p == 0 && strchr (s: buf, c: 'D') == 0)
478 {
479 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
480 m->file, m->line, m->name);
481 free (ptr: buf);
482 continue;
483 }
484 }
485 if (p != 0)
486 *p = 'C';
487 else
488 {
489 buf[0] = 'C';
490 memcpy (dest: buf + 1, src: m->name, n: m_len + 1);
491 }
492
493 c = new_mode (cl: cclass, name: buf, file, line);
494 c->component = m;
495 m->complex = c;
496 }
497}
498
499/* For all modes in class CL, construct vector modes of width WIDTH,
500 having as many components as necessary. ORDER is the sorting order
501 of the mode, with smaller numbers indicating a higher priority. */
502#define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \
503 make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__)
504#define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0)
505static void ATTRIBUTE_UNUSED
506make_vector_modes (enum mode_class cl, const char *prefix, unsigned int width,
507 unsigned int order, const char *file, unsigned int line)
508{
509 struct mode_data *m;
510 struct mode_data *v;
511 /* Big enough for a 32-bit UINT_MAX plus the text. */
512 char buf[12];
513 unsigned int ncomponents;
514 enum mode_class vclass = vector_class (cl);
515
516 if (vclass == MODE_RANDOM)
517 return;
518
519 for (m = modes[cl]; m; m = m->next)
520 {
521 /* Do not construct vector modes with only one element, or
522 vector modes where the element size doesn't divide the full
523 size evenly. */
524 ncomponents = width / m->bytesize;
525 if (ncomponents < 2)
526 continue;
527 if (width % m->bytesize)
528 continue;
529
530 /* Skip QFmode and BImode. FIXME: this special case should
531 not be necessary. */
532 if (cl == MODE_FLOAT && m->bytesize == 1)
533 continue;
534 if (m->boolean)
535 continue;
536
537 if ((size_t) snprintf (s: buf, maxlen: sizeof buf, format: "%s%u%s", prefix,
538 ncomponents, m->name) >= sizeof buf)
539 {
540 error ("%s:%d: mode name \"%s\" is too long",
541 m->file, m->line, m->name);
542 continue;
543 }
544
545 v = new_mode (cl: vclass, name: xstrdup (buf), file, line);
546 v->order = order;
547 v->component = m;
548 v->ncomponents = ncomponents;
549 }
550}
551
552/* Create a vector of booleans called NAME with COUNT elements and
553 BYTESIZE bytes in total. */
554#define VECTOR_BOOL_MODE(NAME, COUNT, COMPONENT, BYTESIZE) \
555 make_vector_bool_mode (#NAME, COUNT, #COMPONENT, BYTESIZE, \
556 __FILE__, __LINE__)
557static void ATTRIBUTE_UNUSED
558make_vector_bool_mode (const char *name, unsigned int count,
559 const char *component, unsigned int bytesize,
560 const char *file, unsigned int line)
561{
562 struct mode_data *m = find_mode (name: component);
563 if (!m)
564 {
565 error ("%s:%d: no mode \"%s\"", file, line, component);
566 return;
567 }
568
569 struct mode_data *v = new_mode (cl: MODE_VECTOR_BOOL, name, file, line);
570 v->component = m;
571 v->ncomponents = count;
572 v->bytesize = bytesize;
573}
574
575/* Input. */
576
577#define _SPECIAL_MODE(C, N) \
578 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
579#define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
580#define CC_MODE(N) _SPECIAL_MODE (CC, N)
581
582static void
583make_special_mode (enum mode_class cl, const char *name,
584 const char *file, unsigned int line)
585{
586 new_mode (cl, name, file, line);
587}
588
589#define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
590#define FRACTIONAL_INT_MODE(N, B, Y) \
591 make_int_mode (#N, B, Y, __FILE__, __LINE__)
592
593static void
594make_int_mode (const char *name,
595 unsigned int precision, unsigned int bytesize,
596 const char *file, unsigned int line)
597{
598 struct mode_data *m = new_mode (cl: MODE_INT, name, file, line);
599 m->bytesize = bytesize;
600 m->precision = precision;
601}
602
603#define BOOL_MODE(N, B, Y) \
604 make_bool_mode (#N, B, Y, __FILE__, __LINE__)
605
606static void
607make_bool_mode (const char *name,
608 unsigned int precision, unsigned int bytesize,
609 const char *file, unsigned int line)
610{
611 struct mode_data *m = new_mode (cl: MODE_INT, name, file, line);
612 m->bytesize = bytesize;
613 m->precision = precision;
614 m->boolean = true;
615}
616
617#define OPAQUE_MODE(N, B) \
618 make_opaque_mode (#N, -1U, B, __FILE__, __LINE__)
619
620static void ATTRIBUTE_UNUSED
621make_opaque_mode (const char *name,
622 unsigned int precision,
623 unsigned int bytesize,
624 const char *file, unsigned int line)
625{
626 struct mode_data *m = new_mode (cl: MODE_OPAQUE, name, file, line);
627 m->bytesize = bytesize;
628 m->precision = precision;
629}
630
631#define FRACT_MODE(N, Y, F) \
632 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
633
634#define UFRACT_MODE(N, Y, F) \
635 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
636
637#define ACCUM_MODE(N, Y, I, F) \
638 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
639
640#define UACCUM_MODE(N, Y, I, F) \
641 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
642
643/* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
644 FILE, and LINE. */
645
646static void
647make_fixed_point_mode (enum mode_class cl,
648 const char *name,
649 unsigned int bytesize,
650 unsigned int ibit,
651 unsigned int fbit,
652 const char *file, unsigned int line)
653{
654 struct mode_data *m = new_mode (cl, name, file, line);
655 m->bytesize = bytesize;
656 m->ibit = ibit;
657 m->fbit = fbit;
658}
659
660#define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
661#define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
662 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
663
664static void
665make_float_mode (const char *name,
666 unsigned int precision, unsigned int bytesize,
667 const char *format,
668 const char *file, unsigned int line)
669{
670 struct mode_data *m = new_mode (cl: MODE_FLOAT, name, file, line);
671 m->bytesize = bytesize;
672 m->precision = precision;
673 m->format = format;
674}
675
676#define DECIMAL_FLOAT_MODE(N, Y, F) \
677 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
678#define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
679 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
680
681static void
682make_decimal_float_mode (const char *name,
683 unsigned int precision, unsigned int bytesize,
684 const char *format,
685 const char *file, unsigned int line)
686{
687 struct mode_data *m = new_mode (cl: MODE_DECIMAL_FLOAT, name, file, line);
688 m->bytesize = bytesize;
689 m->precision = precision;
690 m->format = format;
691}
692
693#define RESET_FLOAT_FORMAT(N, F) \
694 reset_float_format (#N, #F, __FILE__, __LINE__)
695static void ATTRIBUTE_UNUSED
696reset_float_format (const char *name, const char *format,
697 const char *file, unsigned int line)
698{
699 struct mode_data *m = find_mode (name);
700 if (!m)
701 {
702 error ("%s:%d: no mode \"%s\"", file, line, name);
703 return;
704 }
705 if (m->cl != MODE_FLOAT && m->cl != MODE_DECIMAL_FLOAT)
706 {
707 error ("%s:%d: mode \"%s\" is not a FLOAT class", file, line, name);
708 return;
709 }
710 m->format = format;
711}
712
713/* __intN support. */
714#define INT_N(M,PREC) \
715 make_int_n (#M, PREC, __FILE__, __LINE__)
716static void ATTRIBUTE_UNUSED
717make_int_n (const char *m, int bitsize,
718 const char *file, unsigned int line)
719{
720 struct mode_data *component = find_mode (name: m);
721 if (!component)
722 {
723 error ("%s:%d: no mode \"%s\"", file, line, m);
724 return;
725 }
726 if (component->cl != MODE_INT
727 && component->cl != MODE_PARTIAL_INT)
728 {
729 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file, line, m);
730 return;
731 }
732 if (component->int_n != 0)
733 {
734 error ("%s:%d: mode \"%s\" already has an intN", file, line, m);
735 return;
736 }
737
738 component->int_n = bitsize;
739}
740
741/* Partial integer modes are specified by relation to a full integer
742 mode. */
743#define PARTIAL_INT_MODE(M,PREC,NAME) \
744 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
745static void ATTRIBUTE_UNUSED
746make_partial_integer_mode (const char *base, const char *name,
747 unsigned int precision,
748 const char *file, unsigned int line)
749{
750 struct mode_data *m;
751 struct mode_data *component = find_mode (name: base);
752 if (!component)
753 {
754 error ("%s:%d: no mode \"%s\"", file, line, name);
755 return;
756 }
757 if (component->cl != MODE_INT)
758 {
759 error ("%s:%d: mode \"%s\" is not class INT", file, line, name);
760 return;
761 }
762
763 m = new_mode (cl: MODE_PARTIAL_INT, name, file, line);
764 m->precision = precision;
765 m->component = component;
766}
767
768/* A single vector mode can be specified by naming its component
769 mode and the number of components. */
770#define VECTOR_MODE_WITH_PREFIX(PREFIX, C, M, N, ORDER) \
771 make_vector_mode (MODE_##C, #PREFIX, #M, N, ORDER, __FILE__, __LINE__);
772#define VECTOR_MODE(C, M, N) VECTOR_MODE_WITH_PREFIX(V, C, M, N, 0);
773static void ATTRIBUTE_UNUSED
774make_vector_mode (enum mode_class bclass,
775 const char *prefix,
776 const char *base,
777 unsigned int ncomponents,
778 unsigned int order,
779 const char *file, unsigned int line)
780{
781 struct mode_data *v;
782 enum mode_class vclass = vector_class (cl: bclass);
783 struct mode_data *component = find_mode (name: base);
784 char namebuf[16];
785
786 if (vclass == MODE_RANDOM)
787 return;
788 if (component == 0)
789 {
790 error ("%s:%d: no mode \"%s\"", file, line, base);
791 return;
792 }
793 if (component->cl != bclass
794 && (component->cl != MODE_PARTIAL_INT
795 || bclass != MODE_INT))
796 {
797 error ("%s:%d: mode \"%s\" is not class %s",
798 file, line, base, mode_class_names[bclass] + 5);
799 return;
800 }
801
802 if ((size_t)snprintf (s: namebuf, maxlen: sizeof namebuf, format: "%s%u%s", prefix,
803 ncomponents, base) >= sizeof namebuf)
804 {
805 error ("%s:%d: mode name \"%s\" is too long",
806 file, line, base);
807 return;
808 }
809
810 v = new_mode (cl: vclass, name: xstrdup (namebuf), file, line);
811 v->order = order;
812 v->ncomponents = ncomponents;
813 v->component = component;
814}
815
816/* Adjustability. */
817#define _ADD_ADJUST(A, M, X, C1, C2) \
818 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
819
820#define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
821#define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
822#define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
823#define ADJUST_PRECISION(M, X) _ADD_ADJUST (precision, M, X, RANDOM, RANDOM)
824#define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
825#define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
826#define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
827
828static int bits_per_unit;
829static int max_bitsize_mode_any_int;
830static int max_bitsize_mode_any_mode;
831
832static void
833create_modes (void)
834{
835#include "machmode.def"
836
837 /* So put the default value unless the target needs a non standard
838 value. */
839#ifdef BITS_PER_UNIT
840 bits_per_unit = BITS_PER_UNIT;
841#else
842 bits_per_unit = 8;
843#endif
844
845#ifdef MAX_BITSIZE_MODE_ANY_INT
846 max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT;
847#else
848 max_bitsize_mode_any_int = 0;
849#endif
850
851#ifdef MAX_BITSIZE_MODE_ANY_MODE
852 max_bitsize_mode_any_mode = MAX_BITSIZE_MODE_ANY_MODE;
853#else
854 max_bitsize_mode_any_mode = 0;
855#endif
856}
857
858#ifndef NUM_POLY_INT_COEFFS
859#define NUM_POLY_INT_COEFFS 1
860#endif
861
862/* Processing. */
863
864/* Sort a list of modes into the order needed for the WIDER field:
865 major sort by precision, minor sort by component precision.
866
867 For instance:
868 QI < HI < SI < DI < TI
869 V4QI < V2HI < V8QI < V4HI < V2SI.
870
871 If the precision is not set, sort by the bytesize. A mode with
872 precision set gets sorted before a mode without precision set, if
873 they have the same bytesize; this is the right thing because
874 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
875 We don't have to do anything special to get this done -- an unset
876 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
877static int
878cmp_modes (const void *a, const void *b)
879{
880 const struct mode_data *const m = *(const struct mode_data *const*)a;
881 const struct mode_data *const n = *(const struct mode_data *const*)b;
882
883 if (m->order > n->order)
884 return 1;
885 else if (m->order < n->order)
886 return -1;
887
888 if (m->bytesize > n->bytesize)
889 return 1;
890 else if (m->bytesize < n->bytesize)
891 return -1;
892
893 if (m->precision > n->precision)
894 return 1;
895 else if (m->precision < n->precision)
896 return -1;
897
898 if (!m->component && !n->component)
899 {
900 if (m->counter < n->counter)
901 return -1;
902 else
903 return 1;
904 }
905
906 if (m->component->bytesize > n->component->bytesize)
907 return 1;
908 else if (m->component->bytesize < n->component->bytesize)
909 return -1;
910
911 if (m->component->precision > n->component->precision)
912 return 1;
913 else if (m->component->precision < n->component->precision)
914 return -1;
915
916 if (m->counter < n->counter)
917 return -1;
918 else
919 return 1;
920}
921
922static void
923calc_wider_mode (void)
924{
925 int c;
926 struct mode_data *m;
927 struct mode_data **sortbuf;
928 unsigned int max_n_modes = 0;
929 unsigned int i, j;
930
931 for (c = 0; c < MAX_MODE_CLASS; c++)
932 max_n_modes = MAX (max_n_modes, n_modes[c]);
933
934 /* Allocate max_n_modes + 1 entries to leave room for the extra null
935 pointer assigned after the qsort call below. */
936 sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1);
937
938 for (c = 0; c < MAX_MODE_CLASS; c++)
939 {
940 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
941 However, we want these in textual order, and we have
942 precisely the reverse. */
943 if (c == MODE_RANDOM || c == MODE_CC)
944 {
945 struct mode_data *prev, *next;
946
947 for (prev = 0, m = modes[c]; m; m = next)
948 {
949 m->wider = void_mode;
950
951 /* this is nreverse */
952 next = m->next;
953 m->next = prev;
954 prev = m;
955 }
956 modes[c] = prev;
957 }
958 else
959 {
960 if (!modes[c])
961 continue;
962
963 for (i = 0, m = modes[c]; m; i++, m = m->next)
964 sortbuf[i] = m;
965
966 (qsort) (base: sortbuf, nmemb: i, size: sizeof (struct mode_data *), compar: cmp_modes);
967
968 sortbuf[i] = 0;
969 for (j = 0; j < i; j++)
970 {
971 sortbuf[j]->next = sortbuf[j + 1];
972 if (c == MODE_PARTIAL_INT)
973 sortbuf[j]->wider = sortbuf[j]->component;
974 else
975 sortbuf[j]->wider = sortbuf[j]->next;
976 }
977
978 modes[c] = sortbuf[0];
979 }
980 }
981}
982
983/* Text to add to the constant part of a poly_int initializer in
984 order to fill out te whole structure. */
985#if NUM_POLY_INT_COEFFS == 1
986#define ZERO_COEFFS ""
987#elif NUM_POLY_INT_COEFFS == 2
988#define ZERO_COEFFS ", 0"
989#else
990#error "Unknown value of NUM_POLY_INT_COEFFS"
991#endif
992
993/* Output routines. */
994
995#define tagged_printf(FMT, ARG, TAG) do { \
996 int count_ = printf (" " FMT ",", ARG); \
997 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
998} while (0)
999
1000#define print_decl(TYPE, NAME, ASIZE) \
1001 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
1002
1003#define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
1004 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
1005 NEEDS_ADJ ? "" : "const ")
1006
1007#define print_closer() puts ("};")
1008
1009/* Compute the max bitsize of some of the classes of integers. It may
1010 be that there are needs for the other integer classes, and this
1011 code is easy to extend. */
1012static void
1013emit_max_int (void)
1014{
1015 unsigned int max, mmax;
1016 struct mode_data *i;
1017 int j;
1018
1019 puts (s: "");
1020
1021 printf (format: "#define BITS_PER_UNIT (%d)\n", bits_per_unit);
1022
1023 if (max_bitsize_mode_any_int == 0)
1024 {
1025 for (max = 1, i = modes[MODE_INT]; i; i = i->next)
1026 if (max < i->bytesize)
1027 max = i->bytesize;
1028 mmax = max;
1029 for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next)
1030 if (max < i->bytesize)
1031 max = i->bytesize;
1032 if (max > mmax)
1033 mmax = max;
1034 printf (format: "#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax);
1035 }
1036 else
1037 printf (format: "#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int);
1038
1039 if (max_bitsize_mode_any_mode == 0)
1040 {
1041 mmax = 0;
1042 for (j = 0; j < MAX_MODE_CLASS; j++)
1043 for (i = modes[j]; i; i = i->next)
1044 if (mmax < i->bytesize)
1045 mmax = i->bytesize;
1046 printf (format: "#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax);
1047 }
1048 else
1049 printf (format: "#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1050 max_bitsize_mode_any_mode);
1051}
1052
1053/* Emit mode_size_inline routine into insn-modes.h header. */
1054static void
1055emit_mode_size_inline (void)
1056{
1057 int c;
1058 struct mode_adjust *a;
1059 struct mode_data *m;
1060
1061 /* Size adjustments must be propagated to all containing modes. */
1062 for (a = adj_bytesize; a; a = a->next)
1063 {
1064 a->mode->need_bytesize_adj = true;
1065 for (m = a->mode->contained; m; m = m->next_cont)
1066 m->need_bytesize_adj = true;
1067 }
1068
1069 /* Changing the number of units by a factor of X also changes the size
1070 by a factor of X. */
1071 for (mode_adjust *a = adj_nunits; a; a = a->next)
1072 a->mode->need_bytesize_adj = true;
1073
1074 printf (format: "\
1075#ifdef __cplusplus\n\
1076inline __attribute__((__always_inline__))\n\
1077#else\n\
1078extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1079#endif\n\
1080poly_uint16\n\
1081mode_size_inline (machine_mode mode)\n\
1082{\n\
1083 extern %spoly_uint16 mode_size[NUM_MACHINE_MODES];\n\
1084 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1085 switch (mode)\n\
1086 {\n", adj_nunits || adj_bytesize ? "" : "const ");
1087
1088 for_all_modes (c, m)
1089 if (!m->need_bytesize_adj)
1090 printf (format: " case E_%smode: return %u;\n", m->name, m->bytesize);
1091
1092 puts (s: "\
1093 default: return mode_size[mode];\n\
1094 }\n\
1095}\n");
1096}
1097
1098/* Emit mode_nunits_inline routine into insn-modes.h header. */
1099static void
1100emit_mode_nunits_inline (void)
1101{
1102 int c;
1103 struct mode_data *m;
1104
1105 for (mode_adjust *a = adj_nunits; a; a = a->next)
1106 a->mode->need_nunits_adj = true;
1107
1108 printf (format: "\
1109#ifdef __cplusplus\n\
1110inline __attribute__((__always_inline__))\n\
1111#else\n\
1112extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1113#endif\n\
1114poly_uint16\n\
1115mode_nunits_inline (machine_mode mode)\n\
1116{\n\
1117 extern %spoly_uint16 mode_nunits[NUM_MACHINE_MODES];\n\
1118 switch (mode)\n\
1119 {\n", adj_nunits ? "" : "const ");
1120
1121 for_all_modes (c, m)
1122 if (!m->need_nunits_adj)
1123 printf (format: " case E_%smode: return %u;\n", m->name, m->ncomponents);
1124
1125 puts (s: "\
1126 default: return mode_nunits[mode];\n\
1127 }\n\
1128}\n");
1129}
1130
1131/* Emit mode_inner_inline routine into insn-modes.h header. */
1132static void
1133emit_mode_inner_inline (void)
1134{
1135 int c;
1136 struct mode_data *m;
1137
1138 puts (s: "\
1139#ifdef __cplusplus\n\
1140inline __attribute__((__always_inline__))\n\
1141#else\n\
1142extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1143#endif\n\
1144unsigned short\n\
1145mode_inner_inline (machine_mode mode)\n\
1146{\n\
1147 extern const unsigned short mode_inner[NUM_MACHINE_MODES];\n\
1148 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1149 switch (mode)\n\
1150 {");
1151
1152 for_all_modes (c, m)
1153 printf (format: " case E_%smode: return E_%smode;\n", m->name,
1154 c != MODE_PARTIAL_INT && m->component
1155 ? m->component->name : m->name);
1156
1157 puts (s: "\
1158 default: return mode_inner[mode];\n\
1159 }\n\
1160}\n");
1161}
1162
1163/* Emit mode_unit_size_inline routine into insn-modes.h header. */
1164static void
1165emit_mode_unit_size_inline (void)
1166{
1167 int c;
1168 struct mode_data *m;
1169
1170 puts (s: "\
1171#ifdef __cplusplus\n\
1172inline __attribute__((__always_inline__))\n\
1173#else\n\
1174extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1175#endif\n\
1176unsigned char\n\
1177mode_unit_size_inline (machine_mode mode)\n\
1178{\n\
1179 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1180\n\
1181 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1182 switch (mode)\n\
1183 {");
1184
1185 for_all_modes (c, m)
1186 {
1187 const char *name = m->name;
1188 struct mode_data *m2 = m;
1189 if (c != MODE_PARTIAL_INT && m2->component)
1190 m2 = m2->component;
1191 if (!m2->need_bytesize_adj)
1192 printf (format: " case E_%smode: return %u;\n", name, m2->bytesize);
1193 }
1194
1195 puts (s: "\
1196 default: return mode_unit_size[mode];\n\
1197 }\n\
1198}\n");
1199}
1200
1201/* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1202static void
1203emit_mode_unit_precision_inline (void)
1204{
1205 int c;
1206 struct mode_data *m;
1207
1208 puts (s: "\
1209#ifdef __cplusplus\n\
1210inline __attribute__((__always_inline__))\n\
1211#else\n\
1212extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1213#endif\n\
1214unsigned short\n\
1215mode_unit_precision_inline (machine_mode mode)\n\
1216{\n\
1217 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1218 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1219 switch (mode)\n\
1220 {");
1221
1222 for_all_modes (c, m)
1223 {
1224 struct mode_data *m2
1225 = (c != MODE_PARTIAL_INT && m->component) ? m->component : m;
1226 if (m2->precision != (unsigned int)-1)
1227 printf (format: " case E_%smode: return %u;\n", m->name, m2->precision);
1228 else
1229 printf (format: " case E_%smode: return %u*BITS_PER_UNIT;\n",
1230 m->name, m2->bytesize);
1231 }
1232
1233 puts (s: "\
1234 default: return mode_unit_precision[mode];\n\
1235 }\n\
1236}\n");
1237}
1238
1239/* Return the best machine mode class for MODE, or null if machine_mode
1240 should be used. */
1241
1242static const char *
1243get_mode_class (struct mode_data *mode)
1244{
1245 switch (mode->cl)
1246 {
1247 case MODE_INT:
1248 case MODE_PARTIAL_INT:
1249 return "scalar_int_mode";
1250
1251 case MODE_FRACT:
1252 case MODE_UFRACT:
1253 case MODE_ACCUM:
1254 case MODE_UACCUM:
1255 return "scalar_mode";
1256
1257 case MODE_FLOAT:
1258 case MODE_DECIMAL_FLOAT:
1259 return "scalar_float_mode";
1260
1261 case MODE_COMPLEX_INT:
1262 case MODE_COMPLEX_FLOAT:
1263 return "complex_mode";
1264
1265 default:
1266 return NULL;
1267 }
1268}
1269
1270static void
1271emit_insn_modes_h (void)
1272{
1273 int c;
1274 struct mode_data *m, *first, *last;
1275 int n_int_n_ents = 0;
1276
1277 printf (format: "/* Generated automatically from machmode.def%s%s\n",
1278 HAVE_EXTRA_MODES ? " and " : "",
1279 EXTRA_MODES_FILE);
1280
1281 puts (s: "\
1282 by genmodes. */\n\
1283\n\
1284#ifndef GCC_INSN_MODES_H\n\
1285#define GCC_INSN_MODES_H\n\
1286\n\
1287enum machine_mode\n{");
1288
1289 for (c = 0; c < MAX_MODE_CLASS; c++)
1290 for (m = modes[c]; m; m = m->next)
1291 {
1292 int count_ = printf (format: " E_%smode,", m->name);
1293 printf (format: "%*s/* %s:%d */\n", 27 - count_, "",
1294 trim_filename (m->file), m->line);
1295 printf (format: "#define HAVE_%smode\n", m->name);
1296 printf (format: "#ifdef USE_ENUM_MODES\n");
1297 printf (format: "#define %smode E_%smode\n", m->name, m->name);
1298 printf (format: "#else\n");
1299 if (const char *mode_class = get_mode_class (mode: m))
1300 printf (format: "#define %smode (%s ((%s::from_int) E_%smode))\n",
1301 m->name, mode_class, mode_class, m->name);
1302 else
1303 printf (format: "#define %smode ((void) 0, E_%smode)\n",
1304 m->name, m->name);
1305 printf (format: "#endif\n");
1306 }
1307
1308 puts (s: " MAX_MACHINE_MODE,\n");
1309
1310 for (c = 0; c < MAX_MODE_CLASS; c++)
1311 {
1312 first = modes[c];
1313 last = 0;
1314 for (m = first; m; last = m, m = m->next)
1315 ;
1316
1317 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1318 end will try to use it for bitfields in structures and the
1319 like, which we do not want. Only the target md file should
1320 generate BImode widgets. Since some targets such as ARM/MVE
1321 define boolean modes with multiple bits, handle those too. */
1322 if (first && first->boolean)
1323 {
1324 struct mode_data *last_bool = first;
1325 printf (format: " MIN_MODE_BOOL = E_%smode,\n", first->name);
1326
1327 while (first && first->boolean)
1328 {
1329 last_bool = first;
1330 first = first->next;
1331 }
1332
1333 printf (format: " MAX_MODE_BOOL = E_%smode,\n\n", last_bool->name);
1334 }
1335
1336 if (first && last)
1337 printf (format: " MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1338 mode_class_names[c], first->name,
1339 mode_class_names[c], last->name);
1340 else
1341 printf (format: " MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1342 mode_class_names[c], void_mode->name,
1343 mode_class_names[c], void_mode->name);
1344 }
1345
1346 puts (s: "\
1347 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1348};\n");
1349
1350 /* Define a NUM_* macro for each mode class, giving the number of modes
1351 in the class. */
1352 for (c = 0; c < MAX_MODE_CLASS; c++)
1353 {
1354 printf (format: "#define NUM_%s ", mode_class_names[c]);
1355 if (modes[c])
1356 printf (format: "(MAX_%s - MIN_%s + 1)\n", mode_class_names[c],
1357 mode_class_names[c]);
1358 else
1359 printf (format: "0\n");
1360 }
1361 printf (format: "\n");
1362
1363 /* I can't think of a better idea, can you? */
1364 printf (format: "#define CONST_MODE_NUNITS%s\n", adj_nunits ? "" : " const");
1365 printf (format: "#define CONST_MODE_PRECISION%s\n", adj_nunits ? "" : " const");
1366 printf (format: "#define CONST_MODE_SIZE%s\n",
1367 adj_bytesize || adj_nunits ? "" : " const");
1368 printf (format: "#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const");
1369 printf (format: "#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const");
1370#if 0 /* disabled for backward compatibility, temporary */
1371 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const");
1372#endif
1373 printf (format: "#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const");
1374 printf (format: "#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const");
1375 printf (format: "#define CONST_MODE_MASK%s\n", adj_nunits ? "" : " const");
1376 emit_max_int ();
1377
1378 for_all_modes (c, m)
1379 if (m->int_n)
1380 n_int_n_ents ++;
1381
1382 printf (format: "#define NUM_INT_N_ENTS %d\n", n_int_n_ents);
1383
1384 printf (format: "#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS);
1385
1386 puts (s: "\
1387\n\
1388#endif /* insn-modes.h */");
1389}
1390
1391static void
1392emit_insn_modes_inline_h (void)
1393{
1394 printf (format: "/* Generated automatically from machmode.def%s%s\n",
1395 HAVE_EXTRA_MODES ? " and " : "",
1396 EXTRA_MODES_FILE);
1397
1398 puts (s: "\
1399 by genmodes. */\n\
1400\n\
1401#ifndef GCC_INSN_MODES_INLINE_H\n\
1402#define GCC_INSN_MODES_INLINE_H");
1403
1404 puts (s: "\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1405 emit_mode_size_inline ();
1406 emit_mode_nunits_inline ();
1407 emit_mode_inner_inline ();
1408 emit_mode_unit_size_inline ();
1409 emit_mode_unit_precision_inline ();
1410 puts (s: "#endif /* GCC_VERSION >= 4001 */");
1411
1412 puts (s: "\
1413\n\
1414#endif /* insn-modes-inline.h */");
1415}
1416
1417static void
1418emit_insn_modes_c_header (void)
1419{
1420 printf (format: "/* Generated automatically from machmode.def%s%s\n",
1421 HAVE_EXTRA_MODES ? " and " : "",
1422 EXTRA_MODES_FILE);
1423
1424 puts (s: "\
1425 by genmodes. */\n\
1426\n\
1427#include \"config.h\"\n\
1428#include \"system.h\"\n\
1429#include \"coretypes.h\"\n\
1430#include \"tm.h\"\n\
1431#include \"real.h\"");
1432}
1433
1434static void
1435emit_min_insn_modes_c_header (void)
1436{
1437 printf (format: "/* Generated automatically from machmode.def%s%s\n",
1438 HAVE_EXTRA_MODES ? " and " : "",
1439 EXTRA_MODES_FILE);
1440
1441 puts (s: "\
1442 by genmodes. */\n\
1443\n\
1444#include \"bconfig.h\"\n\
1445#include \"system.h\"\n\
1446#include \"coretypes.h\"");
1447}
1448
1449static void
1450emit_mode_name (void)
1451{
1452 int c;
1453 struct mode_data *m;
1454
1455 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1456
1457 for_all_modes (c, m)
1458 printf (format: " \"%s\",\n", m->name);
1459
1460 print_closer ();
1461}
1462
1463static void
1464emit_mode_class (void)
1465{
1466 int c;
1467 struct mode_data *m;
1468
1469 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1470
1471 for_all_modes (c, m)
1472 tagged_printf ("%s", mode_class_names[m->cl], m->name);
1473
1474 print_closer ();
1475}
1476
1477static void
1478emit_mode_precision (void)
1479{
1480 int c;
1481 struct mode_data *m;
1482
1483 print_maybe_const_decl ("%spoly_uint16", "mode_precision",
1484 "NUM_MACHINE_MODES", adj_nunits);
1485
1486 for_all_modes (c, m)
1487 if (m->precision != (unsigned int)-1)
1488 tagged_printf ("{ %u" ZERO_COEFFS " }", m->precision, m->name);
1489 else
1490 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS " }",
1491 m->bytesize, m->name);
1492
1493 print_closer ();
1494}
1495
1496static void
1497emit_mode_size (void)
1498{
1499 int c;
1500 struct mode_data *m;
1501
1502 print_maybe_const_decl ("%spoly_uint16", "mode_size",
1503 "NUM_MACHINE_MODES", adj_nunits || adj_bytesize);
1504
1505 for_all_modes (c, m)
1506 tagged_printf ("{ %u" ZERO_COEFFS " }", m->bytesize, m->name);
1507
1508 print_closer ();
1509}
1510
1511static void
1512emit_mode_nunits (void)
1513{
1514 int c;
1515 struct mode_data *m;
1516
1517 print_maybe_const_decl ("%spoly_uint16", "mode_nunits",
1518 "NUM_MACHINE_MODES", adj_nunits);
1519
1520 for_all_modes (c, m)
1521 tagged_printf ("{ %u" ZERO_COEFFS " }", m->ncomponents, m->name);
1522
1523 print_closer ();
1524}
1525
1526static void
1527emit_mode_wider (void)
1528{
1529 int c;
1530 struct mode_data *m;
1531
1532 print_decl ("unsigned short", "mode_next", "NUM_MACHINE_MODES");
1533
1534 for_all_modes (c, m)
1535 tagged_printf ("E_%smode",
1536 m->wider ? m->wider->name : void_mode->name,
1537 m->name);
1538
1539 print_closer ();
1540 print_decl ("unsigned short", "mode_wider", "NUM_MACHINE_MODES");
1541
1542 for_all_modes (c, m)
1543 {
1544 struct mode_data *m2 = 0;
1545
1546 if (m->cl == MODE_INT
1547 || m->cl == MODE_PARTIAL_INT
1548 || m->cl == MODE_FLOAT
1549 || m->cl == MODE_DECIMAL_FLOAT
1550 || m->cl == MODE_COMPLEX_FLOAT
1551 || m->cl == MODE_FRACT
1552 || m->cl == MODE_UFRACT
1553 || m->cl == MODE_ACCUM
1554 || m->cl == MODE_UACCUM)
1555 for (m2 = m->wider; m2 && m2 != void_mode; m2 = m2->wider)
1556 {
1557 if (m2->bytesize == m->bytesize
1558 && m2->precision == m->precision)
1559 continue;
1560 break;
1561 }
1562
1563 if (m2 == void_mode)
1564 m2 = 0;
1565 tagged_printf ("E_%smode",
1566 m2 ? m2->name : void_mode->name,
1567 m->name);
1568 }
1569
1570 print_closer ();
1571 print_decl ("unsigned short", "mode_2xwider", "NUM_MACHINE_MODES");
1572
1573 for_all_modes (c, m)
1574 {
1575 struct mode_data * m2;
1576
1577 for (m2 = m;
1578 m2 && m2 != void_mode;
1579 m2 = m2->wider)
1580 {
1581 if (m2->bytesize < 2 * m->bytesize)
1582 continue;
1583 if (m->precision != (unsigned int) -1)
1584 {
1585 if (m2->precision != 2 * m->precision)
1586 continue;
1587 }
1588 else
1589 {
1590 if (m2->precision != (unsigned int) -1)
1591 continue;
1592 }
1593
1594 /* For vectors we want twice the number of components,
1595 with the same element type. */
1596 if (m->cl == MODE_VECTOR_BOOL
1597 || m->cl == MODE_VECTOR_INT
1598 || m->cl == MODE_VECTOR_FLOAT
1599 || m->cl == MODE_VECTOR_FRACT
1600 || m->cl == MODE_VECTOR_UFRACT
1601 || m->cl == MODE_VECTOR_ACCUM
1602 || m->cl == MODE_VECTOR_UACCUM)
1603 {
1604 if (m2->ncomponents != 2 * m->ncomponents)
1605 continue;
1606 if (m->component != m2->component)
1607 continue;
1608 }
1609
1610 break;
1611 }
1612 if (m2 == void_mode)
1613 m2 = 0;
1614 tagged_printf ("E_%smode",
1615 m2 ? m2->name : void_mode->name,
1616 m->name);
1617 }
1618
1619 print_closer ();
1620}
1621
1622static void
1623emit_mode_complex (void)
1624{
1625 int c;
1626 struct mode_data *m;
1627
1628 print_decl ("unsigned short", "mode_complex", "NUM_MACHINE_MODES");
1629
1630 for_all_modes (c, m)
1631 tagged_printf ("E_%smode",
1632 m->complex ? m->complex->name : void_mode->name,
1633 m->name);
1634
1635 print_closer ();
1636}
1637
1638static void
1639emit_mode_mask (void)
1640{
1641 int c;
1642 struct mode_data *m;
1643
1644 print_maybe_const_decl ("%sunsigned HOST_WIDE_INT", "mode_mask_array",
1645 "NUM_MACHINE_MODES", adj_nunits);
1646 puts (s: "\
1647#define MODE_MASK(m) \\\n\
1648 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1649 ? HOST_WIDE_INT_M1U \\\n\
1650 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1651
1652 for_all_modes (c, m)
1653 if (m->precision != (unsigned int)-1)
1654 tagged_printf ("MODE_MASK (%u)", m->precision, m->name);
1655 else
1656 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m->bytesize, m->name);
1657
1658 puts (s: "#undef MODE_MASK");
1659 print_closer ();
1660}
1661
1662static void
1663emit_mode_inner (void)
1664{
1665 int c;
1666 struct mode_data *m;
1667
1668 print_decl ("unsigned short", "mode_inner", "NUM_MACHINE_MODES");
1669
1670 for_all_modes (c, m)
1671 tagged_printf ("E_%smode",
1672 c != MODE_PARTIAL_INT && m->component
1673 ? m->component->name : m->name,
1674 m->name);
1675
1676 print_closer ();
1677}
1678
1679/* Emit mode_unit_size array into insn-modes.cc file. */
1680static void
1681emit_mode_unit_size (void)
1682{
1683 int c;
1684 struct mode_data *m;
1685
1686 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1687 "NUM_MACHINE_MODES", adj_bytesize);
1688
1689 for_all_modes (c, m)
1690 tagged_printf ("%u",
1691 c != MODE_PARTIAL_INT && m->component
1692 ? m->component->bytesize : m->bytesize, m->name);
1693
1694 print_closer ();
1695}
1696
1697/* Emit mode_unit_precision array into insn-modes.cc file. */
1698static void
1699emit_mode_unit_precision (void)
1700{
1701 int c;
1702 struct mode_data *m;
1703
1704 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1705
1706 for_all_modes (c, m)
1707 {
1708 struct mode_data *m2 = (c != MODE_PARTIAL_INT && m->component) ?
1709 m->component : m;
1710 if (m2->precision != (unsigned int)-1)
1711 tagged_printf ("%u", m2->precision, m->name);
1712 else
1713 tagged_printf ("%u*BITS_PER_UNIT", m2->bytesize, m->name);
1714 }
1715
1716 print_closer ();
1717}
1718
1719
1720static void
1721emit_mode_base_align (void)
1722{
1723 int c;
1724 struct mode_data *m;
1725
1726 print_maybe_const_decl ("%sunsigned short",
1727 "mode_base_align", "NUM_MACHINE_MODES",
1728 adj_alignment);
1729
1730 for_all_modes (c, m)
1731 tagged_printf ("%u", m->alignment, m->name);
1732
1733 print_closer ();
1734}
1735
1736static void
1737emit_class_narrowest_mode (void)
1738{
1739 int c;
1740
1741 print_decl ("unsigned short", "class_narrowest_mode", "MAX_MODE_CLASS");
1742
1743 for (c = 0; c < MAX_MODE_CLASS; c++)
1744 {
1745 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1746 struct mode_data *m = modes[c];
1747 while (m && m->boolean)
1748 m = m->next;
1749 const char *comment_name = (m ? m : void_mode)->name;
1750
1751 tagged_printf ("MIN_%s", mode_class_names[c], comment_name);
1752 }
1753
1754 print_closer ();
1755}
1756
1757static void
1758emit_real_format_for_mode (void)
1759{
1760 struct mode_data *m;
1761
1762 /* The entities pointed to by this table are constant, whether
1763 or not the table itself is constant.
1764
1765 For backward compatibility this table is always writable
1766 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1767 convert all said targets to use ADJUST_FORMAT instead. */
1768#if 0
1769 print_maybe_const_decl ("const struct real_format *%s",
1770 "real_format_for_mode",
1771 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1772 format);
1773#else
1774 print_decl ("struct real_format *\n", "real_format_for_mode",
1775 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1776 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1777#endif
1778
1779 /* The beginning of the table is entries for float modes. */
1780 for (m = modes[MODE_FLOAT]; m; m = m->next)
1781 if (!strcmp (s1: m->format, s2: "0"))
1782 tagged_printf ("%s", m->format, m->name);
1783 else
1784 tagged_printf ("&%s", m->format, m->name);
1785
1786 /* The end of the table is entries for decimal float modes. */
1787 for (m = modes[MODE_DECIMAL_FLOAT]; m; m = m->next)
1788 if (!strcmp (s1: m->format, s2: "0"))
1789 tagged_printf ("%s", m->format, m->name);
1790 else
1791 tagged_printf ("&%s", m->format, m->name);
1792
1793 print_closer ();
1794}
1795
1796static void
1797emit_mode_adjustments (void)
1798{
1799 int c;
1800 struct mode_adjust *a;
1801 struct mode_data *m;
1802
1803 if (adj_nunits)
1804 printf (format: "\n"
1805 "void\n"
1806 "adjust_mode_mask (machine_mode mode)\n"
1807 "{\n"
1808 " unsigned int precision;\n"
1809 " if (GET_MODE_PRECISION (mode).is_constant (&precision)\n"
1810 " && precision < HOST_BITS_PER_WIDE_INT)\n"
1811 " mode_mask_array[mode] = (HOST_WIDE_INT_1U << precision) - 1;"
1812 "\n"
1813 " else\n"
1814 " mode_mask_array[mode] = HOST_WIDE_INT_M1U;\n"
1815 "}\n");
1816
1817 puts (s: "\
1818\nvoid\
1819\ninit_adjust_machine_modes (void)\
1820\n{\
1821\n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1822 size_t s ATTRIBUTE_UNUSED;");
1823
1824 for (a = adj_nunits; a; a = a->next)
1825 {
1826 m = a->mode;
1827 printf (format: "\n"
1828 " {\n"
1829 " /* %s:%d */\n ps = %s;\n",
1830 a->file, a->line, a->adjustment);
1831 printf (format: " int old_factor = vector_element_size"
1832 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1833 m->name, m->name);
1834 printf (format: " mode_precision[E_%smode] = ps * old_factor;\n", m->name);
1835 printf (format: " if (!multiple_p (mode_precision[E_%smode],"
1836 " BITS_PER_UNIT, &mode_size[E_%smode]))\n", m->name, m->name);
1837 printf (format: " mode_size[E_%smode] = -1;\n", m->name);
1838 printf (format: " mode_nunits[E_%smode] = ps;\n", m->name);
1839 printf (format: " adjust_mode_mask (E_%smode);\n", m->name);
1840 printf (format: " }\n");
1841 }
1842
1843 /* Size adjustments must be propagated to all containing modes.
1844 A size adjustment forces us to recalculate the alignment too. */
1845 for (a = adj_bytesize; a; a = a->next)
1846 {
1847 printf (format: "\n /* %s:%d */\n", a->file, a->line);
1848 switch (a->mode->cl)
1849 {
1850 case MODE_VECTOR_BOOL:
1851 case MODE_VECTOR_INT:
1852 case MODE_VECTOR_FLOAT:
1853 case MODE_VECTOR_FRACT:
1854 case MODE_VECTOR_UFRACT:
1855 case MODE_VECTOR_ACCUM:
1856 case MODE_VECTOR_UACCUM:
1857 printf (format: " ps = %s;\n", a->adjustment);
1858 printf (format: " s = mode_unit_size[E_%smode];\n", a->mode->name);
1859 break;
1860
1861 default:
1862 printf (format: " ps = s = %s;\n", a->adjustment);
1863 printf (format: " mode_unit_size[E_%smode] = s;\n", a->mode->name);
1864 break;
1865 }
1866 printf (format: " mode_size[E_%smode] = ps;\n", a->mode->name);
1867 printf (format: " mode_base_align[E_%smode] = known_alignment (ps);\n",
1868 a->mode->name);
1869
1870 for (m = a->mode->contained; m; m = m->next_cont)
1871 {
1872 switch (m->cl)
1873 {
1874 case MODE_COMPLEX_INT:
1875 case MODE_COMPLEX_FLOAT:
1876 printf (format: " mode_size[E_%smode] = 2*s;\n", m->name);
1877 printf (format: " mode_unit_size[E_%smode] = s;\n", m->name);
1878 printf (format: " mode_base_align[E_%smode] = s & (~s + 1);\n",
1879 m->name);
1880 break;
1881
1882 case MODE_VECTOR_BOOL:
1883 /* Changes to BImode should not affect vector booleans. */
1884 break;
1885
1886 case MODE_VECTOR_INT:
1887 case MODE_VECTOR_FLOAT:
1888 case MODE_VECTOR_FRACT:
1889 case MODE_VECTOR_UFRACT:
1890 case MODE_VECTOR_ACCUM:
1891 case MODE_VECTOR_UACCUM:
1892 printf (format: " mode_size[E_%smode] = %d * ps;\n",
1893 m->name, m->ncomponents);
1894 printf (format: " mode_unit_size[E_%smode] = s;\n", m->name);
1895 printf (format: " mode_base_align[E_%smode]"
1896 " = known_alignment (%d * ps);\n",
1897 m->name, m->ncomponents);
1898 break;
1899
1900 default:
1901 internal_error (
1902 "mode %s is neither vector nor complex but contains %s",
1903 m->name, a->mode->name);
1904 /* NOTREACHED */
1905 }
1906 }
1907 }
1908
1909 /* Alignment adjustments propagate too.
1910 ??? This may not be the right thing for vector modes. */
1911 for (a = adj_alignment; a; a = a->next)
1912 {
1913 printf (format: "\n /* %s:%d */\n s = %s;\n",
1914 a->file, a->line, a->adjustment);
1915 printf (format: " mode_base_align[E_%smode] = s;\n", a->mode->name);
1916
1917 for (m = a->mode->contained; m; m = m->next_cont)
1918 {
1919 switch (m->cl)
1920 {
1921 case MODE_COMPLEX_INT:
1922 case MODE_COMPLEX_FLOAT:
1923 printf (format: " mode_base_align[E_%smode] = s;\n", m->name);
1924 break;
1925
1926 case MODE_VECTOR_BOOL:
1927 /* Changes to BImode should not affect vector booleans. */
1928 break;
1929
1930 case MODE_VECTOR_INT:
1931 case MODE_VECTOR_FLOAT:
1932 case MODE_VECTOR_FRACT:
1933 case MODE_VECTOR_UFRACT:
1934 case MODE_VECTOR_ACCUM:
1935 case MODE_VECTOR_UACCUM:
1936 printf (format: " mode_base_align[E_%smode] = %d*s;\n",
1937 m->name, m->ncomponents);
1938 break;
1939
1940 default:
1941 internal_error (
1942 "mode %s is neither vector nor complex but contains %s",
1943 m->name, a->mode->name);
1944 /* NOTREACHED */
1945 }
1946 }
1947 }
1948
1949 /* Ibit adjustments don't have to propagate. */
1950 for (a = adj_ibit; a; a = a->next)
1951 {
1952 printf (format: "\n /* %s:%d */\n s = %s;\n",
1953 a->file, a->line, a->adjustment);
1954 printf (format: " mode_ibit[E_%smode] = s;\n", a->mode->name);
1955 }
1956
1957 /* Fbit adjustments don't have to propagate. */
1958 for (a = adj_fbit; a; a = a->next)
1959 {
1960 printf (format: "\n /* %s:%d */\n s = %s;\n",
1961 a->file, a->line, a->adjustment);
1962 printf (format: " mode_fbit[E_%smode] = s;\n", a->mode->name);
1963 }
1964
1965 /* Real mode formats don't have to propagate anywhere. */
1966 for (a = adj_format; a; a = a->next)
1967 printf (format: "\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1968 a->file, a->line, a->mode->name, a->adjustment);
1969
1970 /* Adjust precision to the actual bits size. */
1971 for (a = adj_precision; a; a = a->next)
1972 switch (a->mode->cl)
1973 {
1974 case MODE_VECTOR_BOOL:
1975 printf (format: "\n /* %s:%d. */\n ps = %s;\n", a->file, a->line,
1976 a->adjustment);
1977 printf (format: " mode_precision[E_%smode] = ps;\n", a->mode->name);
1978 break;
1979 default:
1980 internal_error ("invalid use of ADJUST_PRECISION for mode %s",
1981 a->mode->name);
1982 /* NOTREACHED. */
1983 }
1984
1985 /* Ensure there is no mode size equals -1. */
1986 for_all_modes (c, m)
1987 printf (format: "\n gcc_assert (maybe_ne (mode_size[E_%smode], -1));\n",
1988 m->name);
1989
1990 puts (s: "}");
1991}
1992
1993/* Emit ibit for all modes. */
1994
1995static void
1996emit_mode_ibit (void)
1997{
1998 int c;
1999 struct mode_data *m;
2000
2001 print_maybe_const_decl ("%sunsigned char",
2002 "mode_ibit", "NUM_MACHINE_MODES",
2003 adj_ibit);
2004
2005 for_all_modes (c, m)
2006 tagged_printf ("%u", m->ibit, m->name);
2007
2008 print_closer ();
2009}
2010
2011/* Emit fbit for all modes. */
2012
2013static void
2014emit_mode_fbit (void)
2015{
2016 int c;
2017 struct mode_data *m;
2018
2019 print_maybe_const_decl ("%sunsigned char",
2020 "mode_fbit", "NUM_MACHINE_MODES",
2021 adj_fbit);
2022
2023 for_all_modes (c, m)
2024 tagged_printf ("%u", m->fbit, m->name);
2025
2026 print_closer ();
2027}
2028
2029/* Emit __intN for all modes. */
2030
2031static void
2032emit_mode_int_n (void)
2033{
2034 int c;
2035 struct mode_data *m;
2036 struct mode_data **mode_sort;
2037 int n_modes = 0;
2038 int i, j;
2039
2040 print_decl ("int_n_data_t", "int_n_data", "");
2041
2042 n_modes = 0;
2043 for_all_modes (c, m)
2044 if (m->int_n)
2045 n_modes ++;
2046 mode_sort = XALLOCAVEC (struct mode_data *, n_modes);
2047
2048 n_modes = 0;
2049 for_all_modes (c, m)
2050 if (m->int_n)
2051 mode_sort[n_modes++] = m;
2052
2053 /* Yes, this is a bubblesort, but there are at most four (and
2054 usually only 1-2) entries to sort. */
2055 for (i = 0; i<n_modes - 1; i++)
2056 for (j = i + 1; j < n_modes; j++)
2057 if (mode_sort[i]->int_n > mode_sort[j]->int_n)
2058 std::swap (a&: mode_sort[i], b&: mode_sort[j]);
2059
2060 for (i = 0; i < n_modes; i ++)
2061 {
2062 m = mode_sort[i];
2063 printf(format: " {\n");
2064 tagged_printf ("%u", m->int_n, m->name);
2065 printf (format: "{ E_%smode },", m->name);
2066 printf(format: " },\n");
2067 }
2068
2069 print_closer ();
2070}
2071
2072
2073static void
2074emit_insn_modes_c (void)
2075{
2076 emit_insn_modes_c_header ();
2077 emit_mode_name ();
2078 emit_mode_class ();
2079 emit_mode_precision ();
2080 emit_mode_size ();
2081 emit_mode_nunits ();
2082 emit_mode_wider ();
2083 emit_mode_complex ();
2084 emit_mode_mask ();
2085 emit_mode_inner ();
2086 emit_mode_unit_size ();
2087 emit_mode_unit_precision ();
2088 emit_mode_base_align ();
2089 emit_class_narrowest_mode ();
2090 emit_real_format_for_mode ();
2091 emit_mode_adjustments ();
2092 emit_mode_ibit ();
2093 emit_mode_fbit ();
2094 emit_mode_int_n ();
2095}
2096
2097static void
2098emit_min_insn_modes_c (void)
2099{
2100 emit_min_insn_modes_c_header ();
2101 emit_mode_name ();
2102 emit_mode_class ();
2103 emit_mode_nunits ();
2104 emit_mode_wider ();
2105 emit_mode_inner ();
2106 emit_class_narrowest_mode ();
2107}
2108
2109/* Master control. */
2110int
2111main (int argc, char **argv)
2112{
2113 bool gen_header = false, gen_inlines = false, gen_min = false;
2114 progname = argv[0];
2115
2116 if (argc == 1)
2117 ;
2118 else if (argc == 2 && !strcmp (s1: argv[1], s2: "-h"))
2119 gen_header = true;
2120 else if (argc == 2 && !strcmp (s1: argv[1], s2: "-i"))
2121 gen_inlines = true;
2122 else if (argc == 2 && !strcmp (s1: argv[1], s2: "-m"))
2123 gen_min = true;
2124 else
2125 {
2126 error ("usage: %s [-h|-i|-m] > file", progname);
2127 return FATAL_EXIT_CODE;
2128 }
2129
2130 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free);
2131
2132 create_modes ();
2133 complete_all_modes ();
2134
2135 if (have_error)
2136 return FATAL_EXIT_CODE;
2137
2138 calc_wider_mode ();
2139
2140 if (gen_header)
2141 emit_insn_modes_h ();
2142 else if (gen_inlines)
2143 emit_insn_modes_inline_h ();
2144 else if (gen_min)
2145 emit_min_insn_modes_c ();
2146 else
2147 emit_insn_modes_c ();
2148
2149 if (fflush (stdout) || fclose (stdout))
2150 return FATAL_EXIT_CODE;
2151 return SUCCESS_EXIT_CODE;
2152}
2153

source code of gcc/genmodes.cc