]>
Commit | Line | Data |
---|---|---|
6f29feb1 | 1 | /* Allocate and read RTL for GNU C Compiler. |
f6e3c1bb | 2 | Copyright (C) 1987, 1988, 1991, 1994, 1997 Free Software Foundation, Inc. |
6f29feb1 JW |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
e99215a3 RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
6f29feb1 JW |
20 | |
21 | ||
22 | #include "config.h" | |
670ee920 | 23 | #include "system.h" |
6f29feb1 | 24 | #include "rtl.h" |
a19a1b5d | 25 | #include "real.h" |
0dfa1860 | 26 | #include "bitmap.h" |
6f29feb1 JW |
27 | |
28 | #include "obstack.h" | |
29 | #define obstack_chunk_alloc xmalloc | |
30 | #define obstack_chunk_free free | |
6f29feb1 JW |
31 | |
32 | /* Obstack used for allocating RTL objects. | |
33 | Between functions, this is the permanent_obstack. | |
34 | While parsing and expanding a function, this is maybepermanent_obstack | |
35 | so we can save it if it is an inline function. | |
36 | During optimization and output, this is function_obstack. */ | |
37 | ||
38 | extern struct obstack *rtl_obstack; | |
6f29feb1 JW |
39 | \f |
40 | /* Indexed by rtx code, gives number of operands for an rtx with that code. | |
41 | Does NOT include rtx header data (code and links). | |
42 | This array is initialized in init_rtl. */ | |
43 | ||
44 | int rtx_length[NUM_RTX_CODE + 1]; | |
45 | ||
46 | /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */ | |
47 | ||
48 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME , | |
49 | ||
50 | char *rtx_name[] = { | |
51 | #include "rtl.def" /* rtl expressions are documented here */ | |
52 | }; | |
53 | ||
54 | #undef DEF_RTL_EXPR | |
55 | ||
56 | /* Indexed by machine mode, gives the name of that machine mode. | |
57 | This name does not include the letters "mode". */ | |
58 | ||
59 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) NAME, | |
60 | ||
913f68c1 | 61 | char *mode_name[(int) MAX_MACHINE_MODE + 1] = { |
6f29feb1 JW |
62 | #include "machmode.def" |
63 | ||
64 | #ifdef EXTRA_CC_MODES | |
913f68c1 | 65 | EXTRA_CC_NAMES, |
6f29feb1 | 66 | #endif |
913f68c1 JC |
67 | /* Add an extra field to avoid a core dump if someone tries to convert |
68 | MAX_MACHINE_MODE to a string. */ | |
69 | "" | |
6f29feb1 JW |
70 | }; |
71 | ||
72 | #undef DEF_MACHMODE | |
73 | ||
74 | /* Indexed by machine mode, gives the length of the mode, in bytes. | |
75 | GET_MODE_CLASS uses this. */ | |
76 | ||
77 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) CLASS, | |
78 | ||
79 | enum mode_class mode_class[(int) MAX_MACHINE_MODE] = { | |
80 | #include "machmode.def" | |
81 | }; | |
82 | ||
83 | #undef DEF_MACHMODE | |
84 | ||
85 | /* Indexed by machine mode, gives the length of the mode, in bytes. | |
86 | GET_MODE_SIZE uses this. */ | |
87 | ||
88 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) SIZE, | |
89 | ||
90 | int mode_size[(int) MAX_MACHINE_MODE] = { | |
91 | #include "machmode.def" | |
92 | }; | |
93 | ||
94 | #undef DEF_MACHMODE | |
95 | ||
96 | /* Indexed by machine mode, gives the length of the mode's subunit. | |
97 | GET_MODE_UNIT_SIZE uses this. */ | |
98 | ||
99 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) UNIT, | |
100 | ||
101 | int mode_unit_size[(int) MAX_MACHINE_MODE] = { | |
102 | #include "machmode.def" /* machine modes are documented here */ | |
103 | }; | |
104 | ||
105 | #undef DEF_MACHMODE | |
106 | ||
107 | /* Indexed by machine mode, gives next wider natural mode | |
108 | (QI -> HI -> SI -> DI, etc.) Widening multiply instructions | |
109 | use this. */ | |
110 | ||
111 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \ | |
913f68c1 | 112 | (unsigned char) WIDER, |
6f29feb1 | 113 | |
913f68c1 | 114 | unsigned char mode_wider_mode[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
115 | #include "machmode.def" /* machine modes are documented here */ |
116 | }; | |
117 | ||
118 | #undef DEF_MACHMODE | |
119 | ||
913f68c1 JC |
120 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \ |
121 | ((SIZE) * BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT) ? ~(unsigned HOST_WIDE_INT)0 : ((unsigned HOST_WIDE_INT) 1 << (SIZE) * BITS_PER_UNIT) - 1, | |
122 | ||
123 | /* Indexed by machine mode, gives mask of significant bits in mode. */ | |
124 | ||
abef8789 | 125 | unsigned HOST_WIDE_INT mode_mask_array[(int) MAX_MACHINE_MODE] = { |
913f68c1 JC |
126 | #include "machmode.def" |
127 | }; | |
128 | ||
4a39a918 RK |
129 | /* Indexed by mode class, gives the narrowest mode for each class. */ |
130 | ||
131 | enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS]; | |
132 | ||
6f29feb1 JW |
133 | /* Indexed by rtx code, gives a sequence of operand-types for |
134 | rtx's of that code. The sequence is a C string in which | |
6dc42e49 | 135 | each character describes one operand. */ |
6f29feb1 JW |
136 | |
137 | char *rtx_format[] = { | |
138 | /* "*" undefined. | |
139 | can cause a warning message | |
140 | "0" field is unused (or used in a phase-dependent manner) | |
141 | prints nothing | |
142 | "i" an integer | |
143 | prints the integer | |
144 | "n" like "i", but prints entries from `note_insn_name' | |
c166a311 CH |
145 | "w" an integer of width HOST_BITS_PER_WIDE_INT |
146 | prints the integer | |
6f29feb1 JW |
147 | "s" a pointer to a string |
148 | prints the string | |
149 | "S" like "s", but optional: | |
150 | the containing rtx may end before this operand | |
151 | "e" a pointer to an rtl expression | |
152 | prints the expression | |
153 | "E" a pointer to a vector that points to a number of rtl expressions | |
154 | prints a list of the rtl expressions | |
155 | "V" like "E", but optional: | |
156 | the containing rtx may end before this operand | |
157 | "u" a pointer to another insn | |
0dfa1860 MM |
158 | prints the uid of the insn. |
159 | "b" is a pointer to a bitmap header. | |
160 | "t" is a tree pointer. */ | |
6f29feb1 JW |
161 | |
162 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT , | |
163 | #include "rtl.def" /* rtl expressions are defined here */ | |
164 | #undef DEF_RTL_EXPR | |
165 | }; | |
166 | ||
167 | /* Indexed by rtx code, gives a character representing the "class" of | |
168 | that rtx code. See rtl.def for documentation on the defined classes. */ | |
169 | ||
170 | char rtx_class[] = { | |
171 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS, | |
172 | #include "rtl.def" /* rtl expressions are defined here */ | |
173 | #undef DEF_RTL_EXPR | |
174 | }; | |
175 | ||
176 | /* Names for kinds of NOTEs and REG_NOTEs. */ | |
177 | ||
a31efb86 | 178 | char *note_insn_name[] = { 0 , "NOTE_INSN_DELETED", |
6f29feb1 JW |
179 | "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END", |
180 | "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END", | |
181 | "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP", | |
bdac5f58 | 182 | "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP", |
196cedd0 | 183 | "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG", |
3d195391 | 184 | "NOTE_INSN_DELETED_LABEL", "NOTE_INSN_FUNCTION_BEG", |
f6e3c1bb | 185 | "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END", |
0dfa1860 MM |
186 | "NOTE_REPEATED_LINE_NUMBER", "NOTE_INSN_RANGE_START", |
187 | "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE" }; | |
6f29feb1 JW |
188 | |
189 | char *reg_note_name[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0", | |
190 | "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL", | |
191 | "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED", | |
192 | "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL", | |
f6e3c1bb | 193 | "REG_DEP_ANTI", "REG_DEP_OUTPUT", "REG_BR_PROB", |
c107334d | 194 | "REG_EXEC_COUNT", "REG_NOALIAS", "REG_SAVE_AREA", |
07ebc930 RH |
195 | "REG_BR_PRED", "REG_EH_CONTEXT", |
196 | "REG_FRAME_RELATED_EXPR" }; | |
6f29feb1 | 197 | |
bf94d1ec | 198 | static void dump_and_abort PROTO((int, int, FILE *)) ATTRIBUTE_NORETURN; |
956d6950 JL |
199 | static void read_name PROTO((char *, FILE *)); |
200 | \f | |
6f29feb1 JW |
201 | /* Allocate an rtx vector of N elements. |
202 | Store the length, and initialize all elements to zero. */ | |
203 | ||
204 | rtvec | |
205 | rtvec_alloc (n) | |
206 | int n; | |
207 | { | |
208 | rtvec rt; | |
209 | int i; | |
210 | ||
211 | rt = (rtvec) obstack_alloc (rtl_obstack, | |
212 | sizeof (struct rtvec_def) | |
213 | + (( n - 1) * sizeof (rtunion))); | |
214 | ||
215 | /* clear out the vector */ | |
395d53bb RK |
216 | PUT_NUM_ELEM (rt, n); |
217 | ||
218 | for (i = 0; i < n; i++) | |
219 | rt->elem[i].rtwint = 0; | |
6f29feb1 JW |
220 | |
221 | return rt; | |
222 | } | |
223 | ||
224 | /* Allocate an rtx of code CODE. The CODE is stored in the rtx; | |
225 | all the rest is initialized to zero. */ | |
226 | ||
227 | rtx | |
228 | rtx_alloc (code) | |
229 | RTX_CODE code; | |
230 | { | |
231 | rtx rt; | |
232 | register struct obstack *ob = rtl_obstack; | |
233 | register int nelts = GET_RTX_LENGTH (code); | |
234 | register int length = sizeof (struct rtx_def) | |
235 | + (nelts - 1) * sizeof (rtunion); | |
236 | ||
237 | /* This function is called more than any other in GCC, | |
238 | so we manipulate the obstack directly. | |
239 | ||
240 | Even though rtx objects are word aligned, we may be sharing an obstack | |
241 | with tree nodes, which may have to be double-word aligned. So align | |
242 | our length to the alignment mask in the obstack. */ | |
243 | ||
244 | length = (length + ob->alignment_mask) & ~ ob->alignment_mask; | |
245 | ||
246 | if (ob->chunk_limit - ob->next_free < length) | |
247 | _obstack_newchunk (ob, length); | |
248 | rt = (rtx)ob->object_base; | |
249 | ob->next_free += length; | |
250 | ob->object_base = ob->next_free; | |
251 | ||
2151a093 RK |
252 | /* We want to clear everything up to the FLD array. Normally, this is |
253 | one int, but we don't want to assume that and it isn't very portable | |
254 | anyway; this is. */ | |
255 | ||
256 | length = (sizeof (struct rtx_def) - sizeof (rtunion) - 1) / sizeof (int); | |
257 | for (; length >= 0; length--) | |
258 | ((int *) rt)[length] = 0; | |
259 | ||
6f29feb1 JW |
260 | PUT_CODE (rt, code); |
261 | ||
262 | return rt; | |
263 | } | |
9b404774 RS |
264 | |
265 | /* Free the rtx X and all RTL allocated since X. */ | |
266 | ||
267 | void | |
268 | rtx_free (x) | |
269 | rtx x; | |
270 | { | |
271 | obstack_free (rtl_obstack, x); | |
272 | } | |
6f29feb1 JW |
273 | \f |
274 | /* Create a new copy of an rtx. | |
275 | Recursively copies the operands of the rtx, | |
276 | except for those few rtx codes that are sharable. */ | |
277 | ||
278 | rtx | |
279 | copy_rtx (orig) | |
280 | register rtx orig; | |
281 | { | |
282 | register rtx copy; | |
283 | register int i, j; | |
284 | register RTX_CODE code; | |
285 | register char *format_ptr; | |
286 | ||
287 | code = GET_CODE (orig); | |
288 | ||
289 | switch (code) | |
290 | { | |
291 | case REG: | |
292 | case QUEUED: | |
293 | case CONST_INT: | |
294 | case CONST_DOUBLE: | |
295 | case SYMBOL_REF: | |
296 | case CODE_LABEL: | |
297 | case PC: | |
298 | case CC0: | |
cf526dcc | 299 | case SCRATCH: |
0f41302f | 300 | /* SCRATCH must be shared because they represent distinct values. */ |
e9a25f70 | 301 | case ADDRESSOF: |
6f29feb1 | 302 | return orig; |
cf526dcc RK |
303 | |
304 | case CONST: | |
305 | /* CONST can be shared if it contains a SYMBOL_REF. If it contains | |
306 | a LABEL_REF, it isn't sharable. */ | |
307 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
308 | && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF | |
309 | && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT) | |
310 | return orig; | |
311 | break; | |
312 | ||
cc81e625 JW |
313 | /* A MEM with a constant address is not sharable. The problem is that |
314 | the constant address may need to be reloaded. If the mem is shared, | |
315 | then reloading one copy of this mem will cause all copies to appear | |
316 | to have been reloaded. */ | |
e9a25f70 JL |
317 | |
318 | default: | |
319 | break; | |
6f29feb1 JW |
320 | } |
321 | ||
322 | copy = rtx_alloc (code); | |
323 | PUT_MODE (copy, GET_MODE (orig)); | |
324 | copy->in_struct = orig->in_struct; | |
325 | copy->volatil = orig->volatil; | |
326 | copy->unchanging = orig->unchanging; | |
327 | copy->integrated = orig->integrated; | |
328 | ||
329 | format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); | |
330 | ||
331 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) | |
332 | { | |
333 | switch (*format_ptr++) | |
334 | { | |
335 | case 'e': | |
336 | XEXP (copy, i) = XEXP (orig, i); | |
337 | if (XEXP (orig, i) != NULL) | |
338 | XEXP (copy, i) = copy_rtx (XEXP (orig, i)); | |
339 | break; | |
340 | ||
c166a311 | 341 | case '0': |
f1027406 RK |
342 | case 'u': |
343 | XEXP (copy, i) = XEXP (orig, i); | |
344 | break; | |
345 | ||
6f29feb1 JW |
346 | case 'E': |
347 | case 'V': | |
348 | XVEC (copy, i) = XVEC (orig, i); | |
349 | if (XVEC (orig, i) != NULL) | |
350 | { | |
351 | XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); | |
352 | for (j = 0; j < XVECLEN (copy, i); j++) | |
353 | XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j)); | |
354 | } | |
355 | break; | |
356 | ||
0dfa1860 MM |
357 | case 'b': |
358 | { | |
359 | bitmap new_bits = BITMAP_OBSTACK_ALLOC (rtl_obstack); | |
360 | bitmap_copy (new_bits, XBITMAP (orig, i)); | |
361 | XBITMAP (copy, i) = new_bits; | |
362 | break; | |
363 | } | |
364 | ||
365 | case 't': | |
366 | XTREE (copy, i) = XTREE (orig, i); | |
367 | break; | |
368 | ||
c166a311 CH |
369 | case 'w': |
370 | XWINT (copy, i) = XWINT (orig, i); | |
371 | break; | |
372 | ||
373 | case 'i': | |
6f29feb1 JW |
374 | XINT (copy, i) = XINT (orig, i); |
375 | break; | |
c166a311 CH |
376 | |
377 | case 's': | |
378 | case 'S': | |
379 | XSTR (copy, i) = XSTR (orig, i); | |
380 | break; | |
381 | ||
382 | default: | |
383 | abort (); | |
6f29feb1 JW |
384 | } |
385 | } | |
386 | return copy; | |
387 | } | |
388 | ||
389 | /* Similar to `copy_rtx' except that if MAY_SHARE is present, it is | |
390 | placed in the result directly, rather than being copied. */ | |
391 | ||
392 | rtx | |
393 | copy_most_rtx (orig, may_share) | |
394 | register rtx orig; | |
395 | register rtx may_share; | |
396 | { | |
397 | register rtx copy; | |
398 | register int i, j; | |
399 | register RTX_CODE code; | |
400 | register char *format_ptr; | |
401 | ||
402 | if (orig == may_share) | |
403 | return orig; | |
404 | ||
405 | code = GET_CODE (orig); | |
406 | ||
407 | switch (code) | |
408 | { | |
409 | case REG: | |
410 | case QUEUED: | |
411 | case CONST_INT: | |
412 | case CONST_DOUBLE: | |
413 | case SYMBOL_REF: | |
414 | case CODE_LABEL: | |
415 | case PC: | |
416 | case CC0: | |
417 | return orig; | |
e9a25f70 JL |
418 | default: |
419 | break; | |
6f29feb1 JW |
420 | } |
421 | ||
422 | copy = rtx_alloc (code); | |
423 | PUT_MODE (copy, GET_MODE (orig)); | |
424 | copy->in_struct = orig->in_struct; | |
425 | copy->volatil = orig->volatil; | |
426 | copy->unchanging = orig->unchanging; | |
427 | copy->integrated = orig->integrated; | |
428 | ||
429 | format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); | |
430 | ||
431 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) | |
432 | { | |
433 | switch (*format_ptr++) | |
434 | { | |
435 | case 'e': | |
436 | XEXP (copy, i) = XEXP (orig, i); | |
437 | if (XEXP (orig, i) != NULL && XEXP (orig, i) != may_share) | |
438 | XEXP (copy, i) = copy_most_rtx (XEXP (orig, i), may_share); | |
439 | break; | |
f1027406 | 440 | |
c166a311 | 441 | case '0': |
f1027406 RK |
442 | case 'u': |
443 | XEXP (copy, i) = XEXP (orig, i); | |
444 | break; | |
6f29feb1 JW |
445 | |
446 | case 'E': | |
447 | case 'V': | |
448 | XVEC (copy, i) = XVEC (orig, i); | |
449 | if (XVEC (orig, i) != NULL) | |
450 | { | |
451 | XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); | |
452 | for (j = 0; j < XVECLEN (copy, i); j++) | |
453 | XVECEXP (copy, i, j) | |
454 | = copy_most_rtx (XVECEXP (orig, i, j), may_share); | |
455 | } | |
456 | break; | |
457 | ||
c166a311 CH |
458 | case 'w': |
459 | XWINT (copy, i) = XWINT (orig, i); | |
460 | break; | |
461 | ||
462 | case 'n': | |
463 | case 'i': | |
6f29feb1 JW |
464 | XINT (copy, i) = XINT (orig, i); |
465 | break; | |
c166a311 CH |
466 | |
467 | case 's': | |
468 | case 'S': | |
469 | XSTR (copy, i) = XSTR (orig, i); | |
470 | break; | |
471 | ||
472 | default: | |
473 | abort (); | |
6f29feb1 JW |
474 | } |
475 | } | |
476 | return copy; | |
477 | } | |
478 | \f | |
6f29feb1 JW |
479 | /* Subroutines of read_rtx. */ |
480 | ||
481 | /* Dump code after printing a message. Used when read_rtx finds | |
482 | invalid data. */ | |
483 | ||
484 | static void | |
485 | dump_and_abort (expected_c, actual_c, infile) | |
486 | int expected_c, actual_c; | |
487 | FILE *infile; | |
488 | { | |
489 | int c, i; | |
490 | ||
491 | if (expected_c >= 0) | |
492 | fprintf (stderr, | |
493 | "Expected character %c. Found character %c.", | |
494 | expected_c, actual_c); | |
495 | fprintf (stderr, " At file position: %ld\n", ftell (infile)); | |
496 | fprintf (stderr, "Following characters are:\n\t"); | |
497 | for (i = 0; i < 200; i++) | |
498 | { | |
499 | c = getc (infile); | |
500 | if (EOF == c) break; | |
501 | putc (c, stderr); | |
502 | } | |
503 | fprintf (stderr, "Aborting.\n"); | |
504 | abort (); | |
505 | } | |
506 | ||
507 | /* Read chars from INFILE until a non-whitespace char | |
508 | and return that. Comments, both Lisp style and C style, | |
509 | are treated as whitespace. | |
510 | Tools such as genflags use this function. */ | |
511 | ||
512 | int | |
513 | read_skip_spaces (infile) | |
514 | FILE *infile; | |
515 | { | |
516 | register int c; | |
1d300e19 | 517 | while ((c = getc (infile))) |
6f29feb1 JW |
518 | { |
519 | if (c == ' ' || c == '\n' || c == '\t' || c == '\f') | |
520 | ; | |
521 | else if (c == ';') | |
522 | { | |
29cb1e1f NC |
523 | while ((c = getc (infile)) && c != '\n' && c != EOF) |
524 | ; | |
6f29feb1 JW |
525 | } |
526 | else if (c == '/') | |
527 | { | |
528 | register int prevc; | |
529 | c = getc (infile); | |
530 | if (c != '*') | |
531 | dump_and_abort ('*', c, infile); | |
532 | ||
533 | prevc = 0; | |
29cb1e1f | 534 | while ((c = getc (infile)) && c != EOF) |
6f29feb1 JW |
535 | { |
536 | if (prevc == '*' && c == '/') | |
537 | break; | |
538 | prevc = c; | |
539 | } | |
540 | } | |
541 | else break; | |
542 | } | |
543 | return c; | |
544 | } | |
545 | ||
546 | /* Read an rtx code name into the buffer STR[]. | |
547 | It is terminated by any of the punctuation chars of rtx printed syntax. */ | |
548 | ||
549 | static void | |
550 | read_name (str, infile) | |
551 | char *str; | |
552 | FILE *infile; | |
553 | { | |
554 | register char *p; | |
555 | register int c; | |
556 | ||
557 | c = read_skip_spaces(infile); | |
558 | ||
559 | p = str; | |
560 | while (1) | |
561 | { | |
562 | if (c == ' ' || c == '\n' || c == '\t' || c == '\f') | |
563 | break; | |
564 | if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/' | |
565 | || c == '(' || c == '[') | |
566 | { | |
567 | ungetc (c, infile); | |
568 | break; | |
569 | } | |
570 | *p++ = c; | |
571 | c = getc (infile); | |
572 | } | |
573 | if (p == str) | |
574 | { | |
575 | fprintf (stderr, "missing name or number"); | |
576 | dump_and_abort (-1, -1, infile); | |
577 | } | |
578 | ||
579 | *p = 0; | |
580 | } | |
581 | \f | |
cbe36725 RH |
582 | /* Provide a version of a function to read a long long if the system does |
583 | not provide one. */ | |
584 | #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ) | |
585 | HOST_WIDE_INT | |
586 | atoll(p) | |
587 | const char *p; | |
588 | { | |
589 | int neg = 0; | |
590 | HOST_WIDE_INT tmp_wide; | |
591 | ||
e9a780ec | 592 | while (ISSPACE(*p)) |
cbe36725 RH |
593 | p++; |
594 | if (*p == '-') | |
595 | neg = 1, p++; | |
596 | else if (*p == '+') | |
597 | p++; | |
598 | ||
599 | tmp_wide = 0; | |
e9a780ec | 600 | while (ISDIGIT(*p)) |
cbe36725 RH |
601 | { |
602 | HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0'); | |
603 | if (new_wide < tmp_wide) | |
604 | { | |
605 | /* Return INT_MAX equiv on overflow. */ | |
606 | tmp_wide = (~(unsigned HOST_WIDE_INT)0) >> 1; | |
607 | break; | |
608 | } | |
609 | tmp_wide = new_wide; | |
610 | p++; | |
611 | } | |
612 | ||
613 | if (neg) | |
614 | tmp_wide = -tmp_wide; | |
615 | return tmp_wide; | |
616 | } | |
617 | #endif | |
618 | ||
6f29feb1 JW |
619 | /* Read an rtx in printed representation from INFILE |
620 | and return an actual rtx in core constructed accordingly. | |
621 | read_rtx is not used in the compiler proper, but rather in | |
622 | the utilities gen*.c that construct C code from machine descriptions. */ | |
623 | ||
624 | rtx | |
625 | read_rtx (infile) | |
626 | FILE *infile; | |
627 | { | |
628 | register int i, j, list_counter; | |
629 | RTX_CODE tmp_code; | |
630 | register char *format_ptr; | |
631 | /* tmp_char is a buffer used for reading decimal integers | |
632 | and names of rtx types and machine modes. | |
633 | Therefore, 256 must be enough. */ | |
634 | char tmp_char[256]; | |
635 | rtx return_rtx; | |
636 | register int c; | |
637 | int tmp_int; | |
c166a311 | 638 | HOST_WIDE_INT tmp_wide; |
6f29feb1 JW |
639 | |
640 | /* Linked list structure for making RTXs: */ | |
641 | struct rtx_list | |
642 | { | |
643 | struct rtx_list *next; | |
644 | rtx value; /* Value of this node... */ | |
645 | }; | |
646 | ||
647 | c = read_skip_spaces (infile); /* Should be open paren. */ | |
648 | if (c != '(') | |
649 | dump_and_abort ('(', c, infile); | |
650 | ||
651 | read_name (tmp_char, infile); | |
652 | ||
653 | tmp_code = UNKNOWN; | |
654 | ||
655 | for (i=0; i < NUM_RTX_CODE; i++) /* @@ might speed this search up */ | |
656 | { | |
657 | if (!(strcmp (tmp_char, GET_RTX_NAME (i)))) | |
658 | { | |
659 | tmp_code = (RTX_CODE) i; /* get value for name */ | |
660 | break; | |
661 | } | |
662 | } | |
663 | if (tmp_code == UNKNOWN) | |
664 | { | |
665 | fprintf (stderr, | |
666 | "Unknown rtx read in rtl.read_rtx(). Code name was %s .", | |
667 | tmp_char); | |
668 | } | |
669 | /* (NIL) stands for an expression that isn't there. */ | |
670 | if (tmp_code == NIL) | |
671 | { | |
672 | /* Discard the closeparen. */ | |
673 | while ((c = getc (infile)) && c != ')'); | |
674 | return 0; | |
675 | } | |
676 | ||
677 | return_rtx = rtx_alloc (tmp_code); /* if we end up with an insn expression | |
678 | then we free this space below. */ | |
679 | format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx)); | |
680 | ||
681 | /* If what follows is `: mode ', read it and | |
682 | store the mode in the rtx. */ | |
683 | ||
684 | i = read_skip_spaces (infile); | |
685 | if (i == ':') | |
686 | { | |
687 | register int k; | |
688 | read_name (tmp_char, infile); | |
689 | for (k = 0; k < NUM_MACHINE_MODES; k++) | |
690 | if (!strcmp (GET_MODE_NAME (k), tmp_char)) | |
691 | break; | |
692 | ||
693 | PUT_MODE (return_rtx, (enum machine_mode) k ); | |
694 | } | |
695 | else | |
696 | ungetc (i, infile); | |
697 | ||
698 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++) | |
699 | switch (*format_ptr++) | |
700 | { | |
701 | /* 0 means a field for internal use only. | |
702 | Don't expect it to be present in the input. */ | |
703 | case '0': | |
704 | break; | |
705 | ||
706 | case 'e': | |
707 | case 'u': | |
708 | XEXP (return_rtx, i) = read_rtx (infile); | |
709 | break; | |
710 | ||
711 | case 'V': | |
712 | /* 'V' is an optional vector: if a closeparen follows, | |
713 | just store NULL for this element. */ | |
714 | c = read_skip_spaces (infile); | |
715 | ungetc (c, infile); | |
716 | if (c == ')') | |
717 | { | |
718 | XVEC (return_rtx, i) = 0; | |
719 | break; | |
720 | } | |
721 | /* Now process the vector. */ | |
722 | ||
723 | case 'E': | |
724 | { | |
725 | register struct rtx_list *next_rtx, *rtx_list_link; | |
4399e7a3 | 726 | struct rtx_list *list_rtx = NULL; |
6f29feb1 JW |
727 | |
728 | c = read_skip_spaces (infile); | |
729 | if (c != '[') | |
730 | dump_and_abort ('[', c, infile); | |
731 | ||
732 | /* add expressions to a list, while keeping a count */ | |
733 | next_rtx = NULL; | |
734 | list_counter = 0; | |
735 | while ((c = read_skip_spaces (infile)) && c != ']') | |
736 | { | |
737 | ungetc (c, infile); | |
738 | list_counter++; | |
739 | rtx_list_link = (struct rtx_list *) | |
740 | alloca (sizeof (struct rtx_list)); | |
741 | rtx_list_link->value = read_rtx (infile); | |
742 | if (next_rtx == 0) | |
743 | list_rtx = rtx_list_link; | |
744 | else | |
745 | next_rtx->next = rtx_list_link; | |
746 | next_rtx = rtx_list_link; | |
747 | rtx_list_link->next = 0; | |
748 | } | |
749 | /* get vector length and allocate it */ | |
750 | XVEC (return_rtx, i) = (list_counter | |
c166a311 | 751 | ? rtvec_alloc (list_counter) : NULL_RTVEC); |
6f29feb1 JW |
752 | if (list_counter > 0) |
753 | { | |
754 | next_rtx = list_rtx; | |
755 | for (j = 0; j < list_counter; j++, | |
756 | next_rtx = next_rtx->next) | |
757 | XVECEXP (return_rtx, i, j) = next_rtx->value; | |
758 | } | |
759 | /* close bracket gotten */ | |
760 | } | |
761 | break; | |
762 | ||
763 | case 'S': | |
764 | /* 'S' is an optional string: if a closeparen follows, | |
765 | just store NULL for this element. */ | |
766 | c = read_skip_spaces (infile); | |
767 | ungetc (c, infile); | |
768 | if (c == ')') | |
769 | { | |
770 | XSTR (return_rtx, i) = 0; | |
771 | break; | |
772 | } | |
773 | ||
774 | case 's': | |
775 | { | |
776 | int saw_paren = 0; | |
777 | register char *stringbuf; | |
6f29feb1 JW |
778 | |
779 | c = read_skip_spaces (infile); | |
780 | if (c == '(') | |
781 | { | |
782 | saw_paren = 1; | |
783 | c = read_skip_spaces (infile); | |
784 | } | |
785 | if (c != '"') | |
786 | dump_and_abort ('"', c, infile); | |
6f29feb1 JW |
787 | |
788 | while (1) | |
789 | { | |
2dcb563f RS |
790 | c = getc (infile); /* Read the string */ |
791 | if (c == '\\') | |
6f29feb1 | 792 | { |
2dcb563f | 793 | c = getc (infile); /* Read the string */ |
6f29feb1 JW |
794 | /* \; makes stuff for a C string constant containing |
795 | newline and tab. */ | |
2dcb563f | 796 | if (c == ';') |
81dd58a6 RS |
797 | { |
798 | obstack_grow (rtl_obstack, "\\n\\t", 4); | |
799 | continue; | |
800 | } | |
6f29feb1 | 801 | } |
2dcb563f | 802 | else if (c == '"') |
6f29feb1 | 803 | break; |
2dcb563f RS |
804 | |
805 | obstack_1grow (rtl_obstack, c); | |
6f29feb1 JW |
806 | } |
807 | ||
2dcb563f RS |
808 | obstack_1grow (rtl_obstack, 0); |
809 | stringbuf = (char *) obstack_finish (rtl_obstack); | |
6f29feb1 JW |
810 | |
811 | if (saw_paren) | |
812 | { | |
813 | c = read_skip_spaces (infile); | |
814 | if (c != ')') | |
815 | dump_and_abort (')', c, infile); | |
816 | } | |
817 | XSTR (return_rtx, i) = stringbuf; | |
818 | } | |
819 | break; | |
820 | ||
c166a311 CH |
821 | case 'w': |
822 | read_name (tmp_char, infile); | |
823 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
824 | tmp_wide = atoi (tmp_char); | |
825 | #else | |
76d31c63 | 826 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG |
c166a311 | 827 | tmp_wide = atol (tmp_char); |
76d31c63 | 828 | #else |
cbe36725 RH |
829 | /* Prefer atoll over atoq, since the former is in the ISO C9X draft. |
830 | But prefer not to use our hand-rolled function above either. */ | |
831 | #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ) | |
c5afbb49 JL |
832 | tmp_wide = atoll (tmp_char); |
833 | #else | |
76d31c63 JL |
834 | tmp_wide = atoq (tmp_char); |
835 | #endif | |
c5afbb49 | 836 | #endif |
c166a311 CH |
837 | #endif |
838 | XWINT (return_rtx, i) = tmp_wide; | |
839 | break; | |
840 | ||
6f29feb1 JW |
841 | case 'i': |
842 | case 'n': | |
843 | read_name (tmp_char, infile); | |
844 | tmp_int = atoi (tmp_char); | |
845 | XINT (return_rtx, i) = tmp_int; | |
846 | break; | |
847 | ||
848 | default: | |
849 | fprintf (stderr, | |
850 | "switch format wrong in rtl.read_rtx(). format was: %c.\n", | |
851 | format_ptr[-1]); | |
852 | fprintf (stderr, "\tfile position: %ld\n", ftell (infile)); | |
853 | abort (); | |
854 | } | |
855 | ||
856 | c = read_skip_spaces (infile); | |
857 | if (c != ')') | |
858 | dump_and_abort (')', c, infile); | |
859 | ||
860 | return return_rtx; | |
861 | } | |
862 | \f | |
863 | /* This is called once per compilation, before any rtx's are constructed. | |
4a39a918 RK |
864 | It initializes the vector `rtx_length', the extra CC modes, if any, |
865 | and computes certain commonly-used modes. */ | |
6f29feb1 JW |
866 | |
867 | void | |
868 | init_rtl () | |
869 | { | |
4a39a918 RK |
870 | int min_class_size[(int) MAX_MODE_CLASS]; |
871 | enum machine_mode mode; | |
6f29feb1 JW |
872 | int i; |
873 | ||
874 | for (i = 0; i < NUM_RTX_CODE; i++) | |
875 | rtx_length[i] = strlen (rtx_format[i]); | |
876 | ||
877 | /* Make CONST_DOUBLE bigger, if real values are bigger than | |
878 | it normally expects to have room for. | |
879 | Note that REAL_VALUE_TYPE is not defined by default, | |
880 | since tree.h is not included. But the default dfn as `double' | |
881 | would do no harm. */ | |
882 | #ifdef REAL_VALUE_TYPE | |
883 | i = sizeof (REAL_VALUE_TYPE) / sizeof (rtunion) + 2; | |
884 | if (rtx_length[(int) CONST_DOUBLE] < i) | |
885 | { | |
886 | char *s = (char *) xmalloc (i + 1); | |
887 | rtx_length[(int) CONST_DOUBLE] = i; | |
888 | rtx_format[(int) CONST_DOUBLE] = s; | |
889 | *s++ = 'e'; | |
890 | *s++ = '0'; | |
891 | /* Set the GET_RTX_FORMAT of CONST_DOUBLE to a string | |
262555e2 RS |
892 | of as many `w's as we now have elements. Subtract two from |
893 | the size to account for the 'e' and the '0'. */ | |
894 | for (i = 2; i < rtx_length[(int) CONST_DOUBLE]; i++) | |
c166a311 | 895 | *s++ = 'w'; |
6f29feb1 JW |
896 | *s++ = 0; |
897 | } | |
898 | #endif | |
899 | ||
900 | #ifdef EXTRA_CC_MODES | |
901 | for (i = (int) CCmode + 1; i < (int) MAX_MACHINE_MODE; i++) | |
902 | { | |
903 | mode_class[i] = MODE_CC; | |
abef8789 | 904 | mode_mask_array[i] = mode_mask_array[(int) CCmode]; |
6f29feb1 JW |
905 | mode_size[i] = mode_size[(int) CCmode]; |
906 | mode_unit_size[i] = mode_unit_size[(int) CCmode]; | |
913f68c1 JC |
907 | mode_wider_mode[i - 1] = i; |
908 | mode_wider_mode[i] = (unsigned char)VOIDmode; | |
6f29feb1 JW |
909 | } |
910 | #endif | |
4a39a918 | 911 | |
d3d63026 | 912 | /* Find the narrowest mode for each class. */ |
4a39a918 RK |
913 | |
914 | for (i = 0; i < (int) MAX_MODE_CLASS; i++) | |
915 | min_class_size[i] = 1000; | |
916 | ||
917 | for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE; | |
918 | mode = (enum machine_mode) ((int) mode + 1)) | |
919 | { | |
920 | if (GET_MODE_SIZE (mode) < min_class_size[(int) GET_MODE_CLASS (mode)]) | |
921 | { | |
922 | class_narrowest_mode[(int) GET_MODE_CLASS (mode)] = mode; | |
923 | min_class_size[(int) GET_MODE_CLASS (mode)] = GET_MODE_SIZE (mode); | |
924 | } | |
4a39a918 | 925 | } |
6f29feb1 | 926 | } |