1 /* Allocate and read RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1991 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #define obstack_chunk_alloc xmalloc
28 #define obstack_chunk_free free
30 /* Obstack used for allocating RTL objects.
31 Between functions, this is the permanent_obstack.
32 While parsing and expanding a function, this is maybepermanent_obstack
33 so we can save it if it is an inline function.
34 During optimization and output, this is function_obstack. */
36 extern struct obstack
*rtl_obstack
;
38 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
42 /* Indexed by rtx code, gives number of operands for an rtx with that code.
43 Does NOT include rtx header data (code and links).
44 This array is initialized in init_rtl. */
46 int rtx_length
[NUM_RTX_CODE
+ 1];
48 /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */
50 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
53 #include "rtl.def" /* rtl expressions are documented here */
58 /* Indexed by machine mode, gives the name of that machine mode.
59 This name does not include the letters "mode". */
61 #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) NAME,
63 char *mode_name
[(int) MAX_MACHINE_MODE
] = {
64 #include "machmode.def"
74 /* Indexed by machine mode, gives the length of the mode, in bytes.
75 GET_MODE_CLASS uses this. */
77 #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) CLASS,
79 enum mode_class mode_class
[(int) MAX_MACHINE_MODE
] = {
80 #include "machmode.def"
85 /* Indexed by machine mode, gives the length of the mode, in bytes.
86 GET_MODE_SIZE uses this. */
88 #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) SIZE,
90 int mode_size
[(int) MAX_MACHINE_MODE
] = {
91 #include "machmode.def"
96 /* Indexed by machine mode, gives the length of the mode's subunit.
97 GET_MODE_UNIT_SIZE uses this. */
99 #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) UNIT,
101 int mode_unit_size
[(int) MAX_MACHINE_MODE
] = {
102 #include "machmode.def" /* machine modes are documented here */
107 /* Indexed by machine mode, gives next wider natural mode
108 (QI -> HI -> SI -> DI, etc.) Widening multiply instructions
111 #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \
112 (enum machine_mode) WIDER,
114 enum machine_mode mode_wider_mode
[(int) MAX_MACHINE_MODE
] = {
115 #include "machmode.def" /* machine modes are documented here */
120 /* Indexed by mode class, gives the narrowest mode for each class. */
122 enum machine_mode class_narrowest_mode
[(int) MAX_MODE_CLASS
];
124 /* Commonly used modes. */
126 enum machine_mode byte_mode
; /* Mode whose width is BITS_PER_UNIT */
127 enum machine_mode word_mode
; /* Mode whose width is BITS_PER_WORD */
129 /* Indexed by rtx code, gives a sequence of operand-types for
130 rtx's of that code. The sequence is a C string in which
131 each character describes one operand. */
133 char *rtx_format
[] = {
135 can cause a warning message
136 "0" field is unused (or used in a phase-dependent manner)
140 "n" like "i", but prints entries from `note_insn_name'
141 "w" an integer of width HOST_BITS_PER_WIDE_INT
143 "s" a pointer to a string
145 "S" like "s", but optional:
146 the containing rtx may end before this operand
147 "e" a pointer to an rtl expression
148 prints the expression
149 "E" a pointer to a vector that points to a number of rtl expressions
150 prints a list of the rtl expressions
151 "V" like "E", but optional:
152 the containing rtx may end before this operand
153 "u" a pointer to another insn
154 prints the uid of the insn. */
156 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
157 #include "rtl.def" /* rtl expressions are defined here */
161 /* Indexed by rtx code, gives a character representing the "class" of
162 that rtx code. See rtl.def for documentation on the defined classes. */
165 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS,
166 #include "rtl.def" /* rtl expressions are defined here */
170 /* Names for kinds of NOTEs and REG_NOTEs. */
172 char *note_insn_name
[] = { "NOTE_INSN_FUNCTION_BEG", "NOTE_INSN_DELETED",
173 "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END",
174 "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END",
175 "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP",
176 "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP",
177 "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG",
178 "NOTE_INSN_DELETED_LABEL"};
180 char *reg_note_name
[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0",
181 "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL",
182 "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED",
183 "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL",
184 "REG_DEP_ANTI", "REG_DEP_OUTPUT" };
186 /* Allocate an rtx vector of N elements.
187 Store the length, and initialize all elements to zero. */
196 rt
= (rtvec
) obstack_alloc (rtl_obstack
,
197 sizeof (struct rtvec_def
)
198 + (( n
- 1) * sizeof (rtunion
)));
200 /* clear out the vector */
202 for (i
=0; i
< n
; i
++)
203 rt
->elem
[i
].rtvec
= NULL
; /* @@ not portable due to rtunion */
208 /* Allocate an rtx of code CODE. The CODE is stored in the rtx;
209 all the rest is initialized to zero. */
216 register struct obstack
*ob
= rtl_obstack
;
217 register int nelts
= GET_RTX_LENGTH (code
);
218 register int length
= sizeof (struct rtx_def
)
219 + (nelts
- 1) * sizeof (rtunion
);
221 /* This function is called more than any other in GCC,
222 so we manipulate the obstack directly.
224 Even though rtx objects are word aligned, we may be sharing an obstack
225 with tree nodes, which may have to be double-word aligned. So align
226 our length to the alignment mask in the obstack. */
228 length
= (length
+ ob
->alignment_mask
) & ~ ob
->alignment_mask
;
230 if (ob
->chunk_limit
- ob
->next_free
< length
)
231 _obstack_newchunk (ob
, length
);
232 rt
= (rtx
)ob
->object_base
;
233 ob
->next_free
+= length
;
234 ob
->object_base
= ob
->next_free
;
242 /* Create a new copy of an rtx.
243 Recursively copies the operands of the rtx,
244 except for those few rtx codes that are sharable. */
252 register RTX_CODE code
;
253 register char *format_ptr
;
255 code
= GET_CODE (orig
);
270 copy
= rtx_alloc (code
);
271 PUT_MODE (copy
, GET_MODE (orig
));
272 copy
->in_struct
= orig
->in_struct
;
273 copy
->volatil
= orig
->volatil
;
274 copy
->unchanging
= orig
->unchanging
;
275 copy
->integrated
= orig
->integrated
;
277 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
279 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
281 switch (*format_ptr
++)
284 XEXP (copy
, i
) = XEXP (orig
, i
);
285 if (XEXP (orig
, i
) != NULL
)
286 XEXP (copy
, i
) = copy_rtx (XEXP (orig
, i
));
291 XEXP (copy
, i
) = XEXP (orig
, i
);
296 XVEC (copy
, i
) = XVEC (orig
, i
);
297 if (XVEC (orig
, i
) != NULL
)
299 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
300 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
301 XVECEXP (copy
, i
, j
) = copy_rtx (XVECEXP (orig
, i
, j
));
306 XWINT (copy
, i
) = XWINT (orig
, i
);
310 XINT (copy
, i
) = XINT (orig
, i
);
315 XSTR (copy
, i
) = XSTR (orig
, i
);
325 /* Similar to `copy_rtx' except that if MAY_SHARE is present, it is
326 placed in the result directly, rather than being copied. */
329 copy_most_rtx (orig
, may_share
)
331 register rtx may_share
;
335 register RTX_CODE code
;
336 register char *format_ptr
;
338 if (orig
== may_share
)
341 code
= GET_CODE (orig
);
356 copy
= rtx_alloc (code
);
357 PUT_MODE (copy
, GET_MODE (orig
));
358 copy
->in_struct
= orig
->in_struct
;
359 copy
->volatil
= orig
->volatil
;
360 copy
->unchanging
= orig
->unchanging
;
361 copy
->integrated
= orig
->integrated
;
363 format_ptr
= GET_RTX_FORMAT (GET_CODE (copy
));
365 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (copy
)); i
++)
367 switch (*format_ptr
++)
370 XEXP (copy
, i
) = XEXP (orig
, i
);
371 if (XEXP (orig
, i
) != NULL
&& XEXP (orig
, i
) != may_share
)
372 XEXP (copy
, i
) = copy_most_rtx (XEXP (orig
, i
), may_share
);
377 XEXP (copy
, i
) = XEXP (orig
, i
);
382 XVEC (copy
, i
) = XVEC (orig
, i
);
383 if (XVEC (orig
, i
) != NULL
)
385 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
386 for (j
= 0; j
< XVECLEN (copy
, i
); j
++)
388 = copy_most_rtx (XVECEXP (orig
, i
, j
), may_share
);
393 XWINT (copy
, i
) = XWINT (orig
, i
);
398 XINT (copy
, i
) = XINT (orig
, i
);
403 XSTR (copy
, i
) = XSTR (orig
, i
);
413 /* Subroutines of read_rtx. */
415 /* Dump code after printing a message. Used when read_rtx finds
419 dump_and_abort (expected_c
, actual_c
, infile
)
420 int expected_c
, actual_c
;
427 "Expected character %c. Found character %c.",
428 expected_c
, actual_c
);
429 fprintf (stderr
, " At file position: %ld\n", ftell (infile
));
430 fprintf (stderr
, "Following characters are:\n\t");
431 for (i
= 0; i
< 200; i
++)
437 fprintf (stderr
, "Aborting.\n");
441 /* Read chars from INFILE until a non-whitespace char
442 and return that. Comments, both Lisp style and C style,
443 are treated as whitespace.
444 Tools such as genflags use this function. */
447 read_skip_spaces (infile
)
451 while (c
= getc (infile
))
453 if (c
== ' ' || c
== '\n' || c
== '\t' || c
== '\f')
457 while ((c
= getc (infile
)) && c
!= '\n') ;
464 dump_and_abort ('*', c
, infile
);
467 while (c
= getc (infile
))
469 if (prevc
== '*' && c
== '/')
479 /* Read an rtx code name into the buffer STR[].
480 It is terminated by any of the punctuation chars of rtx printed syntax. */
483 read_name (str
, infile
)
490 c
= read_skip_spaces(infile
);
495 if (c
== ' ' || c
== '\n' || c
== '\t' || c
== '\f')
497 if (c
== ':' || c
== ')' || c
== ']' || c
== '"' || c
== '/'
498 || c
== '(' || c
== '[')
508 fprintf (stderr
, "missing name or number");
509 dump_and_abort (-1, -1, infile
);
515 /* Read an rtx in printed representation from INFILE
516 and return an actual rtx in core constructed accordingly.
517 read_rtx is not used in the compiler proper, but rather in
518 the utilities gen*.c that construct C code from machine descriptions. */
524 register int i
, j
, list_counter
;
526 register char *format_ptr
;
527 /* tmp_char is a buffer used for reading decimal integers
528 and names of rtx types and machine modes.
529 Therefore, 256 must be enough. */
534 HOST_WIDE_INT tmp_wide
;
536 /* Linked list structure for making RTXs: */
539 struct rtx_list
*next
;
540 rtx value
; /* Value of this node... */
543 c
= read_skip_spaces (infile
); /* Should be open paren. */
545 dump_and_abort ('(', c
, infile
);
547 read_name (tmp_char
, infile
);
551 for (i
=0; i
< NUM_RTX_CODE
; i
++) /* @@ might speed this search up */
553 if (!(strcmp (tmp_char
, GET_RTX_NAME (i
))))
555 tmp_code
= (RTX_CODE
) i
; /* get value for name */
559 if (tmp_code
== UNKNOWN
)
562 "Unknown rtx read in rtl.read_rtx(). Code name was %s .",
565 /* (NIL) stands for an expression that isn't there. */
568 /* Discard the closeparen. */
569 while ((c
= getc (infile
)) && c
!= ')');
573 return_rtx
= rtx_alloc (tmp_code
); /* if we end up with an insn expression
574 then we free this space below. */
575 format_ptr
= GET_RTX_FORMAT (GET_CODE (return_rtx
));
577 /* If what follows is `: mode ', read it and
578 store the mode in the rtx. */
580 i
= read_skip_spaces (infile
);
584 read_name (tmp_char
, infile
);
585 for (k
= 0; k
< NUM_MACHINE_MODES
; k
++)
586 if (!strcmp (GET_MODE_NAME (k
), tmp_char
))
589 PUT_MODE (return_rtx
, (enum machine_mode
) k
);
594 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (return_rtx
)); i
++)
595 switch (*format_ptr
++)
597 /* 0 means a field for internal use only.
598 Don't expect it to be present in the input. */
604 XEXP (return_rtx
, i
) = read_rtx (infile
);
608 /* 'V' is an optional vector: if a closeparen follows,
609 just store NULL for this element. */
610 c
= read_skip_spaces (infile
);
614 XVEC (return_rtx
, i
) = 0;
617 /* Now process the vector. */
621 register struct rtx_list
*next_rtx
, *rtx_list_link
;
622 struct rtx_list
*list_rtx
;
624 c
= read_skip_spaces (infile
);
626 dump_and_abort ('[', c
, infile
);
628 /* add expressions to a list, while keeping a count */
631 while ((c
= read_skip_spaces (infile
)) && c
!= ']')
635 rtx_list_link
= (struct rtx_list
*)
636 alloca (sizeof (struct rtx_list
));
637 rtx_list_link
->value
= read_rtx (infile
);
639 list_rtx
= rtx_list_link
;
641 next_rtx
->next
= rtx_list_link
;
642 next_rtx
= rtx_list_link
;
643 rtx_list_link
->next
= 0;
645 /* get vector length and allocate it */
646 XVEC (return_rtx
, i
) = (list_counter
647 ? rtvec_alloc (list_counter
) : NULL_RTVEC
);
648 if (list_counter
> 0)
651 for (j
= 0; j
< list_counter
; j
++,
652 next_rtx
= next_rtx
->next
)
653 XVECEXP (return_rtx
, i
, j
) = next_rtx
->value
;
655 /* close bracket gotten */
660 /* 'S' is an optional string: if a closeparen follows,
661 just store NULL for this element. */
662 c
= read_skip_spaces (infile
);
666 XSTR (return_rtx
, i
) = 0;
673 register char *stringbuf
;
676 c
= read_skip_spaces (infile
);
680 c
= read_skip_spaces (infile
);
683 dump_and_abort ('"', c
, infile
);
687 c
= getc (infile
); /* Read the string */
690 c
= getc (infile
); /* Read the string */
691 /* \; makes stuff for a C string constant containing
695 obstack_grow (rtl_obstack
, "\\n\\t", 4);
702 obstack_1grow (rtl_obstack
, c
);
705 obstack_1grow (rtl_obstack
, 0);
706 stringbuf
= (char *) obstack_finish (rtl_obstack
);
710 c
= read_skip_spaces (infile
);
712 dump_and_abort (')', c
, infile
);
714 XSTR (return_rtx
, i
) = stringbuf
;
719 read_name (tmp_char
, infile
);
720 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
721 tmp_wide
= atoi (tmp_char
);
723 tmp_wide
= atol (tmp_char
);
725 XWINT (return_rtx
, i
) = tmp_wide
;
730 read_name (tmp_char
, infile
);
731 tmp_int
= atoi (tmp_char
);
732 XINT (return_rtx
, i
) = tmp_int
;
737 "switch format wrong in rtl.read_rtx(). format was: %c.\n",
739 fprintf (stderr
, "\tfile position: %ld\n", ftell (infile
));
743 c
= read_skip_spaces (infile
);
745 dump_and_abort (')', c
, infile
);
750 /* This is called once per compilation, before any rtx's are constructed.
751 It initializes the vector `rtx_length', the extra CC modes, if any,
752 and computes certain commonly-used modes. */
757 int min_class_size
[(int) MAX_MODE_CLASS
];
758 enum machine_mode mode
;
761 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
762 rtx_length
[i
] = strlen (rtx_format
[i
]);
764 /* Make CONST_DOUBLE bigger, if real values are bigger than
765 it normally expects to have room for.
766 Note that REAL_VALUE_TYPE is not defined by default,
767 since tree.h is not included. But the default dfn as `double'
769 #ifdef REAL_VALUE_TYPE
770 i
= sizeof (REAL_VALUE_TYPE
) / sizeof (rtunion
) + 2;
771 if (rtx_length
[(int) CONST_DOUBLE
] < i
)
773 char *s
= (char *) xmalloc (i
+ 1);
774 rtx_length
[(int) CONST_DOUBLE
] = i
;
775 rtx_format
[(int) CONST_DOUBLE
] = s
;
778 /* Set the GET_RTX_FORMAT of CONST_DOUBLE to a string
779 of as many `i's as we now have elements. */
780 for (i
= 0; i
< rtx_length
[(int) CONST_DOUBLE
]; i
++)
786 #ifdef EXTRA_CC_MODES
787 for (i
= (int) CCmode
+ 1; i
< (int) MAX_MACHINE_MODE
; i
++)
789 mode_class
[i
] = MODE_CC
;
790 mode_size
[i
] = mode_size
[(int) CCmode
];
791 mode_unit_size
[i
] = mode_unit_size
[(int) CCmode
];
792 mode_wider_mode
[i
- 1] = (enum machine_mode
) i
;
793 mode_wider_mode
[i
] = VOIDmode
;
797 /* Find the narrowest mode for each class and compute the word and byte
800 for (i
= 0; i
< (int) MAX_MODE_CLASS
; i
++)
801 min_class_size
[i
] = 1000;
803 byte_mode
= VOIDmode
;
804 word_mode
= VOIDmode
;
806 for (mode
= VOIDmode
; (int) mode
< (int) MAX_MACHINE_MODE
;
807 mode
= (enum machine_mode
) ((int) mode
+ 1))
809 if (GET_MODE_SIZE (mode
) < min_class_size
[(int) GET_MODE_CLASS (mode
)])
811 class_narrowest_mode
[(int) GET_MODE_CLASS (mode
)] = mode
;
812 min_class_size
[(int) GET_MODE_CLASS (mode
)] = GET_MODE_SIZE (mode
);
814 if (GET_MODE_CLASS (mode
) == MODE_INT
815 && GET_MODE_BITSIZE (mode
) == BITS_PER_UNIT
816 && byte_mode
== VOIDmode
)
819 if (GET_MODE_CLASS (mode
) == MODE_INT
820 && GET_MODE_BITSIZE (mode
) == BITS_PER_WORD
821 && word_mode
== VOIDmode
)
827 gcc_memset (dest
, value
, len
)