1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993 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. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 /* #include <stab.h> */
37 #include "hard-reg-set.h"
44 #ifdef XCOFF_DEBUGGING_INFO
51 #define ASM_STABS_OP ".stabs"
54 /* This macro gets just the user-specified name
55 out of the string in a SYMBOL_REF. On most machines,
56 we discard the * if any and that's all. */
57 #ifndef STRIP_NAME_ENCODING
58 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
59 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
62 /* File in which assembler code is being written. */
64 extern FILE *asm_out_file;
66 /* The (assembler) name of the first globally-visible object output. */
67 char *first_global_object_name;
69 extern struct obstack *current_obstack;
70 extern struct obstack *saveable_obstack;
71 extern struct obstack permanent_obstack;
72 #define obstack_chunk_alloc xmalloc
74 /* Number for making the label on the next
75 constant that is stored in memory. */
79 /* Number for making the label on the next
80 static variable internal to a function. */
84 /* Nonzero if at least one function definition has been seen. */
85 static int function_defined;
87 extern FILE *asm_out_file;
89 static char *compare_constant_1 ();
90 static void record_constant_1 ();
91 static void output_constant_def_contents ();
93 void output_constant_pool ();
94 void assemble_name ();
95 int output_addressed_constants ();
96 void output_constant ();
97 void output_constructor ();
99 void readonly_data_section ();
100 void data_section ();
102 #ifdef EXTRA_SECTIONS
103 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
106 static enum in_section {no_section, in_text, in_data} in_section
110 /* Define functions like text_section for any extra sections. */
111 #ifdef EXTRA_SECTION_FUNCTIONS
112 EXTRA_SECTION_FUNCTIONS
115 /* Tell assembler to switch to text section. */
120 if (in_section != in_text)
122 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
123 in_section = in_text;
127 /* Tell assembler to switch to data section. */
132 if (in_section != in_data)
134 if (flag_shared_data)
136 #ifdef SHARED_SECTION_ASM_OP
137 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
139 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
143 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
145 in_section = in_data;
149 /* Tell assembler to switch to read-only data section. This is normally
153 readonly_data_section ()
155 #ifdef READONLY_DATA_SECTION
156 READONLY_DATA_SECTION (); /* Note this can call data_section. */
162 /* Determine if we're in the text section. */
167 return in_section == in_text;
170 /* Create the rtl to represent a function, for a function definition.
171 DECL is a FUNCTION_DECL node which describes which function.
172 The rtl is stored into DECL. */
175 make_function_rtl (decl)
178 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
180 /* Rename a nested function to avoid conflicts. */
181 if (decl_function_context (decl) != 0
182 && DECL_INITIAL (decl) != 0
183 && DECL_RTL (decl) == 0)
187 name = IDENTIFIER_POINTER (DECL_NAME (decl));
188 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
189 name = obstack_copy0 (saveable_obstack, label, strlen (label));
193 if (DECL_RTL (decl) == 0)
196 = gen_rtx (MEM, DECL_MODE (decl),
197 gen_rtx (SYMBOL_REF, Pmode, name));
199 /* Optionally set flags or add text to the name to record information
200 such as that it is a function name. If the name is changed, the macro
201 ASM_OUTPUT_LABELREF will have to know how to strip this information.
202 And if it finds a * at the beginning after doing so, it must handle
204 #ifdef ENCODE_SECTION_INFO
205 ENCODE_SECTION_INFO (decl);
209 /* Record at least one function has been defined. */
210 function_defined = 1;
213 /* Given NAME, a putative register name, discard any customary prefixes. */
216 strip_reg_name (name)
219 #ifdef REGISTER_PREFIX
220 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
221 name += strlen (REGISTER_PREFIX);
223 if (name[0] == '%' || name[0] == '#')
228 /* Decode an `asm' spec for a declaration as a register name.
229 Return the register number, or -1 if nothing specified,
230 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
231 or -3 if ASMSPEC is `cc' and is not recognized,
232 or -4 if ASMSPEC is `memory' and is not recognized.
233 Accept an exact spelling or a decimal number.
234 Prefixes such as % are optional. */
237 decode_reg_name (asmspec)
244 /* Get rid of confusing prefixes. */
245 asmspec = strip_reg_name (asmspec);
247 /* Allow a decimal number as a "register name". */
248 for (i = strlen (asmspec) - 1; i >= 0; i--)
249 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
251 if (asmspec[0] != 0 && i < 0)
254 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
260 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
262 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
265 #ifdef ADDITIONAL_REGISTER_NAMES
267 static struct { char *name; int number; } table[]
268 = ADDITIONAL_REGISTER_NAMES;
270 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
271 if (! strcmp (asmspec, table[i].name))
272 return table[i].number;
274 #endif /* ADDITIONAL_REGISTER_NAMES */
276 if (!strcmp (asmspec, "memory"))
279 if (!strcmp (asmspec, "cc"))
288 /* Create the DECL_RTL for a declaration for a static or external variable
289 or static or external function.
290 ASMSPEC, if not 0, is the string which the user specified
291 as the assembler symbol name.
292 TOP_LEVEL is nonzero if this is a file-scope variable.
294 This is never called for PARM_DECL nodes. */
297 make_decl_rtl (decl, asmspec, top_level)
303 int reg_number = decode_reg_name (asmspec);
305 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
306 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
308 if (reg_number == -2)
310 /* ASMSPEC is given, and not the name of a register. */
311 name = (char *) obstack_alloc (saveable_obstack,
312 strlen (asmspec) + 2);
314 strcpy (&name[1], asmspec);
317 /* For a duplicate declaration, we can be called twice on the
318 same DECL node. Don't discard the RTL already made. */
319 if (DECL_RTL (decl) == 0)
323 /* First detect errors in declaring global registers. */
324 if (DECL_REGISTER (decl) && reg_number == -1)
325 error_with_decl (decl,
326 "register name not specified for `%s'");
327 else if (DECL_REGISTER (decl) && reg_number < 0)
328 error_with_decl (decl,
329 "invalid register name for `%s'");
330 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
331 error_with_decl (decl,
332 "register name given for non-register variable `%s'");
333 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
334 error ("function declared `register'");
335 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
336 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
337 else if (DECL_REGISTER (decl)
338 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
339 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
340 /* Now handle properly declared static register variables. */
341 else if (DECL_REGISTER (decl))
344 #if 0 /* yylex should print the warning for this */
346 pedwarn ("ANSI C forbids global register variables");
348 if (DECL_INITIAL (decl) != 0 && top_level)
350 DECL_INITIAL (decl) = 0;
351 error ("global register variable has initial value");
353 if (fixed_regs[reg_number] == 0
354 && function_defined && top_level)
355 error ("global register variable follows a function definition");
356 if (TREE_THIS_VOLATILE (decl))
357 warning ("volatile register variables don't work as you might wish");
359 /* If the user specified one of the eliminables registers here,
360 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
361 confused with that register and be eliminated. Although this
362 usage is somewhat suspect, we nevertheless use the following
363 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
366 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
367 REGNO (DECL_RTL (decl)) = reg_number;
368 REG_USERVAR_P (DECL_RTL (decl)) = 1;
372 /* Make this register fixed, so not usable for anything else. */
373 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
375 global_regs[reg_number + --nregs] = 1;
380 /* Now handle ordinary static variables and functions (in memory).
381 Also handle vars declared register invalidly. */
382 if (DECL_RTL (decl) == 0)
384 /* Can't use just the variable's own name for a variable
385 whose scope is less than the whole file.
386 Concatenate a distinguishing number. */
387 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
391 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
392 name = obstack_copy0 (saveable_obstack, label, strlen (label));
396 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
397 gen_rtx (SYMBOL_REF, Pmode, name));
398 if (TREE_THIS_VOLATILE (decl)
399 || (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
400 && TREE_PUBLIC (decl)))
401 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
402 if (TREE_READONLY (decl))
403 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
404 MEM_IN_STRUCT_P (DECL_RTL (decl))
405 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
406 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
407 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
408 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
410 /* Optionally set flags or add text to the name to record information
411 such as that it is a function name.
412 If the name is changed, the macro ASM_OUTPUT_LABELREF
413 will have to know how to strip this information.
414 And if it finds a * at the beginning after doing so,
415 it must handle that too. */
416 #ifdef ENCODE_SECTION_INFO
417 ENCODE_SECTION_INFO (decl);
421 /* If the old RTL had the wrong mode, fix the mode. */
422 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
424 rtx rtl = DECL_RTL (decl);
425 PUT_MODE (rtl, DECL_MODE (decl));
429 /* Make the rtl for variable VAR be volatile.
430 Use this only for static variables. */
433 make_var_volatile (var)
436 if (GET_CODE (DECL_RTL (var)) != MEM)
439 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
442 /* Output alignment directive to align for constant expression EXP. */
445 assemble_constant_align (exp)
450 /* Align the location counter as required by EXP's data type. */
451 align = TYPE_ALIGN (TREE_TYPE (exp));
452 #ifdef CONSTANT_ALIGNMENT
453 align = CONSTANT_ALIGNMENT (exp, align);
456 if (align > BITS_PER_UNIT)
457 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
460 /* Output a string of literal assembler code
461 for an `asm' keyword used between functions. */
464 assemble_asm (string)
469 if (TREE_CODE (string) == ADDR_EXPR)
470 string = TREE_OPERAND (string, 0);
472 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
475 #if 0 /* This should no longer be needed, because
476 flag_gnu_linker should be 0 on these systems,
477 which should prevent any output
478 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
479 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
480 #ifndef ASM_OUTPUT_CONSTRUCTOR
481 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
483 #ifndef ASM_OUTPUT_DESTRUCTOR
484 #define ASM_OUTPUT_DESTRUCTOR(file, name)
489 /* Record an element in the table of global destructors.
490 How this is done depends on what sort of assembler and linker
493 NAME should be the name of a global function to be called
494 at exit time. This name is output using assemble_name. */
497 assemble_destructor (name)
500 #ifdef ASM_OUTPUT_DESTRUCTOR
501 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
505 /* Now tell GNU LD that this is part of the static destructor set. */
506 /* This code works for any machine provided you use GNU as/ld. */
507 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
508 assemble_name (asm_out_file, name);
509 fputc ('\n', asm_out_file);
514 /* Likewise for global constructors. */
517 assemble_constructor (name)
520 #ifdef ASM_OUTPUT_CONSTRUCTOR
521 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
525 /* Now tell GNU LD that this is part of the static constructor set. */
526 /* This code works for any machine provided you use GNU as/ld. */
527 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
528 assemble_name (asm_out_file, name);
529 fputc ('\n', asm_out_file);
534 /* Likewise for entries we want to record for garbage collection.
535 Garbage collection is still under development. */
538 assemble_gc_entry (name)
541 #ifdef ASM_OUTPUT_GC_ENTRY
542 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
546 /* Now tell GNU LD that this is part of the static constructor set. */
547 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
548 assemble_name (asm_out_file, name);
549 fputc ('\n', asm_out_file);
554 /* Output assembler code for the constant pool of a function and associated
555 with defining the name of the function. DECL describes the function.
556 NAME is the function's name. For the constant pool, we use the current
557 constant pool data. */
560 assemble_start_function (decl, fnname)
566 /* The following code does not need preprocessing in the assembler. */
570 output_constant_pool (fnname, decl);
575 /* Tell assembler to move to target machine's alignment for functions. */
576 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
578 ASM_OUTPUT_ALIGN (asm_out_file, align);
580 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
581 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
584 #ifdef SDB_DEBUGGING_INFO
585 /* Output SDB definition of the function. */
586 if (write_symbols == SDB_DEBUG)
587 sdbout_mark_begin_function ();
590 #ifdef DBX_DEBUGGING_INFO
591 /* Output DBX definition of the function. */
592 if (write_symbols == DBX_DEBUG)
593 dbxout_begin_function (decl);
596 /* Make function name accessible from other files, if appropriate. */
598 if (TREE_PUBLIC (decl))
600 if (!first_global_object_name)
601 STRIP_NAME_ENCODING (first_global_object_name, fnname);
602 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
605 /* Do any machine/system dependent processing of the function name */
606 #ifdef ASM_DECLARE_FUNCTION_NAME
607 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
609 /* Standard thing is just output label for the function. */
610 ASM_OUTPUT_LABEL (asm_out_file, fnname);
611 #endif /* ASM_DECLARE_FUNCTION_NAME */
614 /* Output assembler code associated with defining the size of the
615 function. DECL describes the function. NAME is the function's name. */
618 assemble_end_function (decl, fnname)
622 #ifdef ASM_DECLARE_FUNCTION_SIZE
623 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
627 /* Assemble code to leave SIZE bytes of zeros. */
630 assemble_zeros (size)
633 #ifdef ASM_NO_SKIP_IN_TEXT
634 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
635 so we must output 0s explicitly in the text section. */
636 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
640 for (i = 0; i < size - 20; i += 20)
643 fprintf (asm_out_file,
644 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
646 fprintf (asm_out_file,
647 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
653 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
655 fprintf (asm_out_file, "\tbyte 0");
658 for (; i < size; i++)
659 fprintf (asm_out_file, ",0");
660 fprintf (asm_out_file, "\n");
666 ASM_OUTPUT_SKIP (asm_out_file, size);
669 /* Assemble a string constant with the specified C string as contents. */
672 assemble_string (p, size)
680 /* If the string is very long, split it up. */
684 int thissize = size - pos;
685 if (thissize > maximum)
688 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
695 /* Assemble everything that is needed for a variable or function declaration.
696 Not used for automatic variables, and not used for function definitions.
697 Should not be called for variables of incomplete structure type.
699 TOP_LEVEL is nonzero if this variable has file scope.
700 AT_END is nonzero if this is the special handling, at end of compilation,
701 to define things that have had only tentative definitions.
702 DONT_OUTPUT_DATA if nonzero means don't actually output the
703 initial value (that will be done by the caller). */
706 assemble_variable (decl, top_level, at_end, dont_output_data)
715 enum in_section saved_in_section;
717 if (GET_CODE (DECL_RTL (decl)) == REG)
719 /* Do output symbol info for global register variables, but do nothing
722 if (TREE_ASM_WRITTEN (decl))
724 TREE_ASM_WRITTEN (decl) = 1;
726 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
727 /* File-scope global variables are output here. */
728 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
730 dbxout_symbol (decl, 0);
732 #ifdef SDB_DEBUGGING_INFO
733 if (write_symbols == SDB_DEBUG && top_level
734 /* Leave initialized global vars for end of compilation;
735 see comment in compile_file. */
736 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
737 sdbout_symbol (decl, 0);
740 /* Don't output any DWARF debugging information for variables here.
741 In the case of local variables, the information for them is output
742 when we do our recursive traversal of the tree representation for
743 the entire containing function. In the case of file-scope variables,
744 we output information for all of them at the very end of compilation
745 while we are doing our final traversal of the chain of file-scope
751 /* Normally no need to say anything here for external references,
752 since assemble_external is called by the langauge-specific code
753 when a declaration is first seen. */
755 if (DECL_EXTERNAL (decl))
758 /* Output no assembler code for a function declaration.
759 Only definitions of functions output anything. */
761 if (TREE_CODE (decl) == FUNCTION_DECL)
764 /* If type was incomplete when the variable was declared,
765 see if it is complete now. */
767 if (DECL_SIZE (decl) == 0)
768 layout_decl (decl, 0);
770 /* Still incomplete => don't allocate it; treat the tentative defn
771 (which is what it must have been) as an `extern' reference. */
773 if (!dont_output_data && DECL_SIZE (decl) == 0)
775 error_with_file_and_line (DECL_SOURCE_FILE (decl),
776 DECL_SOURCE_LINE (decl),
777 "storage size of `%s' isn't known",
778 IDENTIFIER_POINTER (DECL_NAME (decl)));
782 /* The first declaration of a variable that comes through this function
783 decides whether it is global (in C, has external linkage)
784 or local (in C, has internal linkage). So do nothing more
785 if this function has already run. */
787 if (TREE_ASM_WRITTEN (decl))
790 TREE_ASM_WRITTEN (decl) = 1;
792 /* If storage size is erroneously variable, just continue.
793 Error message was already made. */
795 if (DECL_SIZE (decl))
797 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
802 /* This is better than explicit arithmetic, since it avoids overflow. */
803 size_tree = size_binop (CEIL_DIV_EXPR,
804 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
806 if (TREE_INT_CST_HIGH (size_tree) != 0)
808 error_with_decl (decl, "size of variable `%s' is too large");
813 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
815 /* Handle uninitialized definitions. */
817 /* ANSI specifies that a tentative definition which is not merged with
818 a non-tentative definition behaves exactly like a definition with an
819 initializer equal to zero. (Section 3.7.2)
820 -fno-common gives strict ANSI behavior. Usually you don't want it. */
822 && ! dont_output_data
823 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
825 int size = TREE_INT_CST_LOW (size_tree);
828 if (TREE_INT_CST_HIGH (size_tree) != 0)
829 error_with_decl (decl, "size of variable `%s' is too large");
830 /* Don't allocate zero bytes of common,
831 since that means "undefined external" in the linker. */
832 if (size == 0) rounded = 1;
833 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
834 so that each uninitialized object starts on such a boundary. */
835 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
836 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
837 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
839 #ifdef DBX_DEBUGGING_INFO
840 /* File-scope global variables are output here. */
841 if (write_symbols == DBX_DEBUG && top_level)
842 dbxout_symbol (decl, 0);
844 #ifdef SDB_DEBUGGING_INFO
845 if (write_symbols == SDB_DEBUG && top_level
846 /* Leave initialized global vars for end of compilation;
847 see comment in compile_file. */
848 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
849 sdbout_symbol (decl, 0);
852 /* Don't output any DWARF debugging information for variables here.
853 In the case of local variables, the information for them is output
854 when we do our recursive traversal of the tree representation for
855 the entire containing function. In the case of file-scope variables,
856 we output information for all of them at the very end of compilation
857 while we are doing our final traversal of the chain of file-scope
861 if (flag_shared_data)
864 if (TREE_PUBLIC (decl))
866 #ifdef ASM_OUTPUT_SHARED_COMMON
867 if (flag_shared_data)
868 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
871 #ifdef ASM_OUTPUT_ALIGNED_COMMON
872 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
875 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
880 #ifdef ASM_OUTPUT_SHARED_LOCAL
881 if (flag_shared_data)
882 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
885 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
886 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
889 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
895 /* Handle initialized definitions. */
897 /* First make the assembler name(s) global if appropriate. */
898 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
900 if (!first_global_object_name)
901 STRIP_NAME_ENCODING(first_global_object_name, name);
902 ASM_GLOBALIZE_LABEL (asm_out_file, name);
905 for (d = equivalents; d; d = TREE_CHAIN (d))
907 tree e = TREE_VALUE (d);
908 if (TREE_PUBLIC (e) && DECL_NAME (e))
909 ASM_GLOBALIZE_LABEL (asm_out_file,
910 XSTR (XEXP (DECL_RTL (e), 0), 0));
914 /* Output any data that we will need to use the address of. */
915 if (DECL_INITIAL (decl))
916 reloc = output_addressed_constants (DECL_INITIAL (decl));
918 /* Switch to the proper section for this data. */
919 #ifdef SELECT_SECTION
920 SELECT_SECTION (decl, reloc);
922 if (TREE_READONLY (decl)
923 && ! TREE_THIS_VOLATILE (decl)
924 && ! (flag_pic && reloc))
925 readonly_data_section ();
930 /* Record current section so we can restore it if dbxout.c clobbers it. */
931 saved_in_section = in_section;
933 /* Output the dbx info now that we have chosen the section. */
935 #ifdef DBX_DEBUGGING_INFO
936 /* File-scope global variables are output here. */
937 if (write_symbols == DBX_DEBUG && top_level)
938 dbxout_symbol (decl, 0);
940 #ifdef SDB_DEBUGGING_INFO
941 if (write_symbols == SDB_DEBUG && top_level
942 /* Leave initialized global vars for end of compilation;
943 see comment in compile_file. */
944 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
945 sdbout_symbol (decl, 0);
948 /* Don't output any DWARF debugging information for variables here.
949 In the case of local variables, the information for them is output
950 when we do our recursive traversal of the tree representation for
951 the entire containing function. In the case of file-scope variables,
952 we output information for all of them at the very end of compilation
953 while we are doing our final traversal of the chain of file-scope
956 if (in_section != saved_in_section)
958 /* Switch to the proper section for this data. */
959 #ifdef SELECT_SECTION
960 SELECT_SECTION (decl, reloc);
962 if (TREE_READONLY (decl)
963 && ! TREE_THIS_VOLATILE (decl)
964 && ! (flag_pic && reloc))
965 readonly_data_section ();
971 /* Compute and output the alignment of this data. */
973 align = DECL_ALIGN (decl);
974 /* Some object file formats have a maximum alignment which they support.
975 In particular, a.out format supports a maximum alignment of 4. */
976 #ifndef MAX_OFILE_ALIGNMENT
977 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
979 if (align > MAX_OFILE_ALIGNMENT)
981 warning_with_decl (decl,
982 "alignment of `%s' is greater than maximum object file alignment");
983 align = MAX_OFILE_ALIGNMENT;
985 #ifdef DATA_ALIGNMENT
986 /* On some machines, it is good to increase alignment sometimes. */
987 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
989 #ifdef CONSTANT_ALIGNMENT
990 if (DECL_INITIAL (decl))
991 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
994 /* Reset the alignment in case we have made it tighter, so we can benefit
995 from it in get_pointer_alignment. */
996 DECL_ALIGN (decl) = align;
998 if (align > BITS_PER_UNIT)
999 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1001 /* Do any machine/system dependent processing of the object. */
1002 #ifdef ASM_DECLARE_OBJECT_NAME
1003 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1005 /* Standard thing is just output label for the object. */
1006 ASM_OUTPUT_LABEL (asm_out_file, name);
1007 #endif /* ASM_DECLARE_OBJECT_NAME */
1009 if (!dont_output_data)
1011 if (DECL_INITIAL (decl))
1012 /* Output the actual data. */
1013 output_constant (DECL_INITIAL (decl),
1014 int_size_in_bytes (TREE_TYPE (decl)));
1016 /* Leave space for it. */
1017 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1021 #ifdef XCOFF_DEBUGGING_INFO
1022 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1023 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1024 and `aa' hasn't been output yet, the assembler generates a stab entry with
1025 a value of zero, in addition to creating an unnecessary external entry
1026 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1028 /* File-scope global variables are output here. */
1029 if (write_symbols == XCOFF_DEBUG && top_level)
1030 dbxout_symbol (decl, 0);
1032 /* There must be a statement after a label. */
1037 /* Output something to declare an external symbol to the assembler.
1038 (Most assemblers don't need this, so we normally output nothing.)
1039 Do nothing if DECL is not external. */
1042 assemble_external (decl)
1045 #ifdef ASM_OUTPUT_EXTERNAL
1046 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1047 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1049 rtx rtl = DECL_RTL (decl);
1051 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1052 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1054 /* Some systems do require some output. */
1055 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1056 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1062 /* Similar, for calling a library function FUN. */
1065 assemble_external_libcall (fun)
1068 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1069 /* Declare library function name external when first used, if nec. */
1070 if (! SYMBOL_REF_USED (fun))
1072 SYMBOL_REF_USED (fun) = 1;
1073 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1078 /* Declare the label NAME global. */
1081 assemble_global (name)
1084 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1087 /* Assemble a label named NAME. */
1090 assemble_label (name)
1093 ASM_OUTPUT_LABEL (asm_out_file, name);
1096 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1097 If NAME starts with a *, the rest of NAME is output verbatim.
1098 Otherwise NAME is transformed in an implementation-defined way
1099 (usually by the addition of an underscore).
1100 Many macros in the tm file are defined to call this function. */
1103 assemble_name (file, name)
1108 fputs (&name[1], file);
1110 ASM_OUTPUT_LABELREF (file, name);
1113 /* Allocate SIZE bytes writable static space with a gensym name
1114 and return an RTX to refer to its address. */
1117 assemble_static_space (size)
1123 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1124 so that each uninitialized object starts on such a boundary. */
1125 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1126 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1127 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1130 if (flag_shared_data)
1134 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1137 namestring = (char *) obstack_alloc (saveable_obstack,
1139 strcpy (namestring, name);
1141 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1142 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1143 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1145 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1150 /* Assemble the static constant template for function entry trampolines.
1151 This is done at most once per compilation.
1152 Returns an RTX for the address of the template. */
1155 assemble_trampoline_template ()
1161 /* By default, put trampoline templates in read-only data section. */
1163 #ifdef TRAMPOLINE_SECTION
1164 TRAMPOLINE_SECTION ();
1166 readonly_data_section ();
1169 /* Write the assembler code to define one. */
1170 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1172 ASM_OUTPUT_ALIGN (asm_out_file, align);
1174 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1175 TRAMPOLINE_TEMPLATE (asm_out_file);
1177 /* Record the rtl to refer to it. */
1178 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1180 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1181 return gen_rtx (SYMBOL_REF, Pmode, name);
1184 /* Assemble the integer constant X into an object of SIZE bytes.
1185 X must be either a CONST_INT or CONST_DOUBLE.
1187 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1188 non-zero, abort if we can't output the constant. */
1191 assemble_integer (x, size, force)
1196 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1197 ASM_OUTPUT... macros. */
1201 #ifdef ASM_OUTPUT_CHAR
1203 ASM_OUTPUT_CHAR (asm_out_file, x);
1207 #ifdef ASM_OUTPUT_SHORT
1209 ASM_OUTPUT_SHORT (asm_out_file, x);
1213 #ifdef ASM_OUTPUT_INT
1215 ASM_OUTPUT_INT (asm_out_file, x);
1219 #ifdef ASM_OUTPUT_DOUBLE_INT
1221 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1225 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1227 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1232 /* If we couldn't do it that way, there are two other possibilities: First,
1233 if the machine can output an explicit byte and this is a 1 byte constant,
1234 we can use ASM_OUTPUT_BYTE. */
1236 #ifdef ASM_OUTPUT_BYTE
1237 if (size == 1 && GET_CODE (x) == CONST_INT)
1239 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1244 /* Finally, if SIZE is larger than a single word, try to output the constant
1245 one word at a time. */
1247 if (size > UNITS_PER_WORD)
1250 enum machine_mode mode
1251 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1254 for (i = 0; i < size / UNITS_PER_WORD; i++)
1256 word = operand_subword (x, i, 0, mode);
1261 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1265 if (i == size / UNITS_PER_WORD)
1267 /* If we output at least one word and then could not finish,
1268 there is no valid way to continue. */
1279 /* Assemble the floating-point constant D into an object of size MODE. */
1282 assemble_real (d, mode)
1284 enum machine_mode mode;
1286 jmp_buf output_constant_handler;
1288 if (setjmp (output_constant_handler))
1290 error ("floating point trap outputting a constant");
1291 #ifdef REAL_IS_NOT_DOUBLE
1292 bzero (&d, sizeof d);
1299 set_float_handler (output_constant_handler);
1303 #ifdef ASM_OUTPUT_BYTE_FLOAT
1305 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1308 #ifdef ASM_OUTPUT_SHORT_FLOAT
1310 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1313 #ifdef ASM_OUTPUT_FLOAT
1315 ASM_OUTPUT_FLOAT (asm_out_file, d);
1319 #ifdef ASM_OUTPUT_DOUBLE
1321 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1325 #ifdef ASM_OUTPUT_LONG_DOUBLE
1328 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1336 set_float_handler (NULL_PTR);
1339 /* Here we combine duplicate floating constants to make
1340 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1342 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1343 They are chained through the CONST_DOUBLE_CHAIN.
1344 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1345 In that case, CONST_DOUBLE_MEM is either a MEM,
1346 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1348 (CONST_DOUBLE_MEM is used only for top-level functions.
1349 See force_const_mem for explanation.) */
1351 static rtx const_double_chain;
1353 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1354 For an integer, I0 is the low-order word and I1 is the high-order word.
1355 For a real number, I0 is the word with the low address
1356 and I1 is the word with the high address. */
1359 immed_double_const (i0, i1, mode)
1360 HOST_WIDE_INT i0, i1;
1361 enum machine_mode mode;
1364 int in_current_obstack;
1366 if (GET_MODE_CLASS (mode) == MODE_INT
1367 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1369 /* We clear out all bits that don't belong in MODE, unless they and our
1370 sign bit are all one. So we get either a reasonable negative value
1371 or a reasonable unsigned value for this mode. */
1372 int width = GET_MODE_BITSIZE (mode);
1373 if (width < HOST_BITS_PER_WIDE_INT
1374 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1375 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1376 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1377 else if (width == HOST_BITS_PER_WIDE_INT
1378 && ! (i1 == ~0 && i0 < 0))
1380 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1381 /* We cannot represent this value as a constant. */
1384 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1386 ??? Strictly speaking, this is wrong if we create a CONST_INT
1387 for a large unsigned constant with the size of MODE being
1388 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1389 wider mode. In that case we will mis-interpret it as a negative
1392 Unfortunately, the only alternative is to make a CONST_DOUBLE
1393 for any constant in any mode if it is an unsigned constant larger
1394 than the maximum signed integer in an int on the host. However,
1395 doing this will break everyone that always expects to see a CONST_INT
1396 for SImode and smaller.
1398 We have always been making CONST_INTs in this case, so nothing new
1401 if (width <= HOST_BITS_PER_WIDE_INT)
1402 i1 = (i0 < 0) ? ~0 : 0;
1404 /* If this integer fits in one word, return a CONST_INT. */
1405 if ((i1 == 0 && i0 >= 0)
1406 || (i1 == ~0 && i0 < 0))
1407 return GEN_INT (i0);
1409 /* We use VOIDmode for integers. */
1413 /* Search the chain for an existing CONST_DOUBLE with the right value.
1414 If one is found, return it. */
1416 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1417 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1418 && GET_MODE (r) == mode)
1421 /* No; make a new one and add it to the chain.
1423 We may be called by an optimizer which may be discarding any memory
1424 allocated during its processing (such as combine and loop). However,
1425 we will be leaving this constant on the chain, so we cannot tolerate
1426 freed memory. So switch to saveable_obstack for this allocation
1427 and then switch back if we were in current_obstack. */
1429 push_obstacks_nochange ();
1430 rtl_in_saveable_obstack ();
1431 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1434 /* Don't touch const_double_chain in nested function;
1435 see force_const_mem. */
1436 if (outer_function_chain == 0)
1438 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1439 const_double_chain = r;
1442 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1443 Actual use of mem-slot is only through force_const_mem. */
1445 CONST_DOUBLE_MEM (r) = const0_rtx;
1450 /* Return a CONST_DOUBLE for a specified `double' value
1451 and machine mode. */
1454 immed_real_const_1 (d, mode)
1456 enum machine_mode mode;
1458 union real_extract u;
1460 int in_current_obstack;
1462 /* Get the desired `double' value as a sequence of ints
1463 since that is how they are stored in a CONST_DOUBLE. */
1467 /* Detect special cases. */
1469 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1470 if (!bcmp (&dconst0, &d, sizeof d))
1471 return CONST0_RTX (mode);
1472 /* Check for NaN first, because some ports (specifically the i386) do not
1473 emit correct ieee-fp code by default, and thus will generate a core
1474 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1475 does a floating point comparison. */
1476 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1477 return CONST1_RTX (mode);
1479 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1480 return immed_double_const (u.i[0], u.i[1], mode);
1482 /* The rest of this function handles the case where
1483 a float value requires more than 2 ints of space.
1484 It will be deleted as dead code on machines that don't need it. */
1486 /* Search the chain for an existing CONST_DOUBLE with the right value.
1487 If one is found, return it. */
1489 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1490 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1491 && GET_MODE (r) == mode)
1494 /* No; make a new one and add it to the chain.
1496 We may be called by an optimizer which may be discarding any memory
1497 allocated during its processing (such as combine and loop). However,
1498 we will be leaving this constant on the chain, so we cannot tolerate
1499 freed memory. So switch to saveable_obstack for this allocation
1500 and then switch back if we were in current_obstack. */
1502 push_obstacks_nochange ();
1503 rtl_in_saveable_obstack ();
1504 r = rtx_alloc (CONST_DOUBLE);
1506 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1509 /* Don't touch const_double_chain in nested function;
1510 see force_const_mem. */
1511 if (outer_function_chain == 0)
1513 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1514 const_double_chain = r;
1517 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1518 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1519 is only through force_const_mem. */
1521 CONST_DOUBLE_MEM (r) = const0_rtx;
1526 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1527 which must be a REAL_CST tree node. */
1530 immed_real_const (exp)
1533 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1536 /* At the end of a function, forget the memory-constants
1537 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1538 Also clear out real_constant_chain and clear out all the chain-pointers. */
1541 clear_const_double_mem ()
1543 register rtx r, next;
1545 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1546 See force_const_mem for explanation. */
1547 if (outer_function_chain != 0)
1550 for (r = const_double_chain; r; r = next)
1552 next = CONST_DOUBLE_CHAIN (r);
1553 CONST_DOUBLE_CHAIN (r) = 0;
1554 CONST_DOUBLE_MEM (r) = cc0_rtx;
1556 const_double_chain = 0;
1559 /* Given an expression EXP with a constant value,
1560 reduce it to the sum of an assembler symbol and an integer.
1561 Store them both in the structure *VALUE.
1562 Abort if EXP does not reduce. */
1567 HOST_WIDE_INT offset;
1571 decode_addr_const (exp, value)
1573 struct addr_const *value;
1575 register tree target = TREE_OPERAND (exp, 0);
1576 register int offset = 0;
1581 if (TREE_CODE (target) == COMPONENT_REF
1582 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1585 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1586 target = TREE_OPERAND (target, 0);
1588 else if (TREE_CODE (target) == ARRAY_REF)
1590 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1591 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1593 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1594 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1596 target = TREE_OPERAND (target, 0);
1602 switch (TREE_CODE (target))
1606 x = DECL_RTL (target);
1610 x = gen_rtx (MEM, FUNCTION_MODE,
1611 gen_rtx (LABEL_REF, VOIDmode,
1612 label_rtx (TREE_OPERAND (exp, 0))));
1619 x = TREE_CST_RTL (target);
1626 if (GET_CODE (x) != MEM)
1631 value->offset = offset;
1634 /* Uniquize all constants that appear in memory.
1635 Each constant in memory thus far output is recorded
1636 in `const_hash_table' with a `struct constant_descriptor'
1637 that contains a polish representation of the value of
1640 We cannot store the trees in the hash table
1641 because the trees may be temporary. */
1643 struct constant_descriptor
1645 struct constant_descriptor *next;
1651 #define MAX_HASH_TABLE 1009
1652 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1654 /* Compute a hash code for a constant expression. */
1661 register int len, hi, i;
1662 register enum tree_code code = TREE_CODE (exp);
1664 if (code == INTEGER_CST)
1666 p = (char *) &TREE_INT_CST_LOW (exp);
1667 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1669 else if (code == REAL_CST)
1671 p = (char *) &TREE_REAL_CST (exp);
1672 len = sizeof TREE_REAL_CST (exp);
1674 else if (code == STRING_CST)
1675 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1676 else if (code == COMPLEX_CST)
1677 return const_hash (TREE_REALPART (exp)) * 5
1678 + const_hash (TREE_IMAGPART (exp));
1679 else if (code == CONSTRUCTOR)
1683 /* For record type, include the type in the hashing.
1684 We do not do so for array types
1685 because (1) the sizes of the elements are sufficient
1686 and (2) distinct array types can have the same constructor.
1687 Instead, we include the array size because the constructor could
1689 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1690 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
1693 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
1694 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
1696 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1697 if (TREE_VALUE (link))
1698 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
1702 else if (code == ADDR_EXPR)
1704 struct addr_const value;
1705 decode_addr_const (exp, &value);
1706 if (GET_CODE (value.base) == SYMBOL_REF)
1708 /* Don't hash the address of the SYMBOL_REF;
1709 only use the offset and the symbol name. */
1711 p = XSTR (value.base, 0);
1712 for (i = 0; p[i] != 0; i++)
1713 hi = ((hi * 613) + (unsigned)(p[i]));
1715 else if (GET_CODE (value.base) == LABEL_REF)
1716 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
1718 hi &= (1 << HASHBITS) - 1;
1719 hi %= MAX_HASH_TABLE;
1722 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1723 return const_hash (TREE_OPERAND (exp, 0)) * 9
1724 + const_hash (TREE_OPERAND (exp, 1));
1725 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1726 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
1728 /* Compute hashing function */
1730 for (i = 0; i < len; i++)
1731 hi = ((hi * 613) + (unsigned)(p[i]));
1733 hi &= (1 << HASHBITS) - 1;
1734 hi %= MAX_HASH_TABLE;
1738 /* Compare a constant expression EXP with a constant-descriptor DESC.
1739 Return 1 if DESC describes a constant with the same value as EXP. */
1742 compare_constant (exp, desc)
1744 struct constant_descriptor *desc;
1746 return 0 != compare_constant_1 (exp, desc->contents);
1749 /* Compare constant expression EXP with a substring P of a constant descriptor.
1750 If they match, return a pointer to the end of the substring matched.
1751 If they do not match, return 0.
1753 Since descriptors are written in polish prefix notation,
1754 this function can be used recursively to test one operand of EXP
1755 against a subdescriptor, and if it succeeds it returns the
1756 address of the subdescriptor for the next operand. */
1759 compare_constant_1 (exp, p)
1763 register char *strp;
1765 register enum tree_code code = TREE_CODE (exp);
1767 if (code != (enum tree_code) *p++)
1770 if (code == INTEGER_CST)
1772 /* Integer constants are the same only if the same width of type. */
1773 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1775 strp = (char *) &TREE_INT_CST_LOW (exp);
1776 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1778 else if (code == REAL_CST)
1780 /* Real constants are the same only if the same width of type. */
1781 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1783 strp = (char *) &TREE_REAL_CST (exp);
1784 len = sizeof TREE_REAL_CST (exp);
1786 else if (code == STRING_CST)
1788 if (flag_writable_strings)
1790 strp = TREE_STRING_POINTER (exp);
1791 len = TREE_STRING_LENGTH (exp);
1792 if (bcmp (&TREE_STRING_LENGTH (exp), p,
1793 sizeof TREE_STRING_LENGTH (exp)))
1795 p += sizeof TREE_STRING_LENGTH (exp);
1797 else if (code == COMPLEX_CST)
1799 p = compare_constant_1 (TREE_REALPART (exp), p);
1800 if (p == 0) return 0;
1801 p = compare_constant_1 (TREE_IMAGPART (exp), p);
1804 else if (code == CONSTRUCTOR)
1807 int length = list_length (CONSTRUCTOR_ELTS (exp));
1810 if (bcmp (&length, p, sizeof length))
1814 /* For record constructors, insist that the types match.
1815 For arrays, just verify both constructors are for arrays. */
1816 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1817 type = TREE_TYPE (exp);
1820 if (bcmp (&type, p, sizeof type))
1824 /* For arrays, insist that the size in bytes match. */
1825 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1827 int size = int_size_in_bytes (TREE_TYPE (exp));
1828 if (bcmp (&size, p, sizeof size))
1833 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1835 if (TREE_VALUE (link))
1837 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
1844 if (bcmp (&zero, p, sizeof zero))
1852 else if (code == ADDR_EXPR)
1854 struct addr_const value;
1855 decode_addr_const (exp, &value);
1856 strp = (char *) &value.offset;
1857 len = sizeof value.offset;
1858 /* Compare the offset. */
1860 if (*p++ != *strp++)
1862 /* Compare symbol name. */
1863 strp = XSTR (value.base, 0);
1864 len = strlen (strp) + 1;
1866 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1868 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1869 if (p == 0) return 0;
1870 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
1873 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1875 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1879 /* Compare constant contents. */
1881 if (*p++ != *strp++)
1887 /* Construct a constant descriptor for the expression EXP.
1888 It is up to the caller to enter the descriptor in the hash table. */
1890 static struct constant_descriptor *
1891 record_constant (exp)
1894 struct constant_descriptor *next = 0;
1897 /* Make a struct constant_descriptor. The first two pointers will
1898 be filled in later. Here we just leave space for them. */
1900 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
1901 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
1902 record_constant_1 (exp);
1903 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
1906 /* Add a description of constant expression EXP
1907 to the object growing in `permanent_obstack'.
1908 No need to return its address; the caller will get that
1909 from the obstack when the object is complete. */
1912 record_constant_1 (exp)
1915 register char *strp;
1917 register enum tree_code code = TREE_CODE (exp);
1919 obstack_1grow (&permanent_obstack, (unsigned int) code);
1921 if (code == INTEGER_CST)
1923 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1924 strp = (char *) &TREE_INT_CST_LOW (exp);
1925 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1927 else if (code == REAL_CST)
1929 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1930 strp = (char *) &TREE_REAL_CST (exp);
1931 len = sizeof TREE_REAL_CST (exp);
1933 else if (code == STRING_CST)
1935 if (flag_writable_strings)
1937 strp = TREE_STRING_POINTER (exp);
1938 len = TREE_STRING_LENGTH (exp);
1939 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
1940 sizeof TREE_STRING_LENGTH (exp));
1942 else if (code == COMPLEX_CST)
1944 record_constant_1 (TREE_REALPART (exp));
1945 record_constant_1 (TREE_IMAGPART (exp));
1948 else if (code == CONSTRUCTOR)
1951 int length = list_length (CONSTRUCTOR_ELTS (exp));
1954 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
1956 /* For record constructors, insist that the types match.
1957 For arrays, just verify both constructors are for arrays. */
1958 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1959 type = TREE_TYPE (exp);
1962 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
1964 /* For arrays, insist that the size in bytes match. */
1965 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1967 int size = int_size_in_bytes (TREE_TYPE (exp));
1968 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
1971 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1973 if (TREE_VALUE (link))
1974 record_constant_1 (TREE_VALUE (link));
1979 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
1985 else if (code == ADDR_EXPR)
1987 struct addr_const value;
1988 decode_addr_const (exp, &value);
1989 /* Record the offset. */
1990 obstack_grow (&permanent_obstack,
1991 (char *) &value.offset, sizeof value.offset);
1992 /* Record the symbol name. */
1993 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
1994 strlen (XSTR (value.base, 0)) + 1);
1997 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1999 record_constant_1 (TREE_OPERAND (exp, 0));
2000 record_constant_1 (TREE_OPERAND (exp, 1));
2003 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2005 record_constant_1 (TREE_OPERAND (exp, 0));
2009 /* Record constant contents. */
2010 obstack_grow (&permanent_obstack, strp, len);
2013 /* Record a list of constant expressions that were passed to
2014 output_constant_def but that could not be output right away. */
2016 struct deferred_constant
2018 struct deferred_constant *next;
2024 static struct deferred_constant *deferred_constants;
2026 /* Nonzero means defer output of addressed subconstants
2027 (i.e., those for which output_constant_def is called.) */
2028 static int defer_addressed_constants_flag;
2030 /* Start deferring output of subconstants. */
2033 defer_addressed_constants ()
2035 defer_addressed_constants_flag++;
2038 /* Stop deferring output of subconstants,
2039 and output now all those that have been deferred. */
2042 output_deferred_addressed_constants ()
2044 struct deferred_constant *p, *next;
2046 defer_addressed_constants_flag--;
2048 if (defer_addressed_constants_flag > 0)
2051 for (p = deferred_constants; p; p = next)
2053 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2058 deferred_constants = 0;
2061 /* Return an rtx representing a reference to constant data in memory
2062 for the constant expression EXP.
2064 If assembler code for such a constant has already been output,
2065 return an rtx to refer to it.
2066 Otherwise, output such a constant in memory (or defer it for later)
2067 and generate an rtx for it.
2069 The TREE_CST_RTL of EXP is set up to point to that rtx.
2070 The const_hash_table records which constants already have label strings. */
2073 output_constant_def (exp)
2077 register struct constant_descriptor *desc;
2083 if (TREE_CODE (exp) == INTEGER_CST)
2084 abort (); /* No TREE_CST_RTL slot in these. */
2086 if (TREE_CST_RTL (exp))
2087 return TREE_CST_RTL (exp);
2089 /* Make sure any other constants whose addresses appear in EXP
2090 are assigned label numbers. */
2092 reloc = output_addressed_constants (exp);
2094 /* Compute hash code of EXP. Search the descriptors for that hash code
2095 to see if any of them describes EXP. If yes, the descriptor records
2096 the label number already assigned. */
2098 hash = const_hash (exp) % MAX_HASH_TABLE;
2100 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2101 if (compare_constant (exp, desc))
2103 found = desc->label;
2109 /* No constant equal to EXP is known to have been output.
2110 Make a constant descriptor to enter EXP in the hash table.
2111 Assign the label number and record it in the descriptor for
2112 future calls to this function to find. */
2114 /* Create a string containing the label name, in LABEL. */
2115 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2117 desc = record_constant (exp);
2118 desc->next = const_hash_table[hash];
2120 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2121 const_hash_table[hash] = desc;
2124 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2126 push_obstacks_nochange ();
2127 if (TREE_PERMANENT (exp))
2128 end_temporary_allocation ();
2130 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2133 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2134 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2135 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2136 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2137 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2141 /* Optionally set flags or add text to the name to record information
2142 such as that it is a function name. If the name is changed, the macro
2143 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2144 And if it finds a * at the beginning after doing so, it must handle
2146 #ifdef ENCODE_SECTION_INFO
2147 ENCODE_SECTION_INFO (exp);
2150 /* If this is the first time we've seen this particular constant,
2151 output it (or defer its output for later). */
2154 if (defer_addressed_constants_flag)
2156 struct deferred_constant *p;
2157 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2159 /* We really should copy trees in depth here,
2160 but since this case is the only one that should happen now,
2161 let's do it later. */
2162 if (TREE_CODE (exp) != STRING_CST)
2165 push_obstacks_nochange ();
2166 suspend_momentary ();
2167 p->exp = copy_node (exp);
2170 p->labelno = const_labelno++;
2171 p->next = deferred_constants;
2172 deferred_constants = p;
2175 output_constant_def_contents (exp, reloc, const_labelno++);
2178 return TREE_CST_RTL (exp);
2181 /* Now output assembler code to define the label for EXP,
2182 and follow it with the data of EXP. */
2185 output_constant_def_contents (exp, reloc, labelno)
2192 /* First switch to text section, except for writable strings. */
2193 #ifdef SELECT_SECTION
2194 SELECT_SECTION (exp, reloc);
2196 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2197 || (flag_pic && reloc))
2200 readonly_data_section ();
2203 /* Align the location counter as required by EXP's data type. */
2204 align = TYPE_ALIGN (TREE_TYPE (exp));
2205 #ifdef CONSTANT_ALIGNMENT
2206 align = CONSTANT_ALIGNMENT (exp, align);
2209 if (align > BITS_PER_UNIT)
2210 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2212 /* Output the label itself. */
2213 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2215 /* Output the value of EXP. */
2216 output_constant (exp,
2217 (TREE_CODE (exp) == STRING_CST
2218 ? TREE_STRING_LENGTH (exp)
2219 : int_size_in_bytes (TREE_TYPE (exp))));
2223 /* Similar hash facility for making memory-constants
2224 from constant rtl-expressions. It is used on RISC machines
2225 where immediate integer arguments and constant addresses are restricted
2226 so that such constants must be stored in memory.
2228 This pool of constants is reinitialized for each function
2229 so each function gets its own constants-pool that comes right before it.
2231 All structures allocated here are discarded when functions are saved for
2232 inlining, so they do not need to be allocated permanently. */
2234 #define MAX_RTX_HASH_TABLE 61
2235 static struct constant_descriptor **const_rtx_hash_table;
2237 /* Structure to represent sufficient information about a constant so that
2238 it can be output when the constant pool is output, so that function
2239 integration can be done, and to simplify handling on machines that reference
2240 constant pool as base+displacement. */
2242 struct pool_constant
2244 struct constant_descriptor *desc;
2245 struct pool_constant *next;
2246 enum machine_mode mode;
2253 /* Pointers to first and last constant in pool. */
2255 static struct pool_constant *first_pool, *last_pool;
2257 /* Current offset in constant pool (does not include any machine-specific
2260 static int pool_offset;
2262 /* Structure used to maintain hash table mapping symbols used to their
2263 corresponding constants. */
2268 struct pool_constant *pool;
2269 struct pool_sym *next;
2272 static struct pool_sym **const_rtx_sym_hash_table;
2274 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2275 The argument is XSTR (... , 0) */
2277 #define SYMHASH(LABEL) \
2278 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2280 /* Initialize constant pool hashing for next function. */
2283 init_const_rtx_hash_table ()
2285 const_rtx_hash_table
2286 = ((struct constant_descriptor **)
2287 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2288 const_rtx_sym_hash_table
2289 = ((struct pool_sym **)
2290 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2291 bzero (const_rtx_hash_table,
2292 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2293 bzero (const_rtx_sym_hash_table,
2294 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2296 first_pool = last_pool = 0;
2300 /* Save and restore it for a nested function. */
2303 save_varasm_status (p)
2306 p->const_rtx_hash_table = const_rtx_hash_table;
2307 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2308 p->first_pool = first_pool;
2309 p->last_pool = last_pool;
2310 p->pool_offset = pool_offset;
2314 restore_varasm_status (p)
2317 const_rtx_hash_table = p->const_rtx_hash_table;
2318 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2319 first_pool = p->first_pool;
2320 last_pool = p->last_pool;
2321 pool_offset = p->pool_offset;
2324 enum kind { RTX_DOUBLE, RTX_INT };
2328 #ifdef ONLY_INT_FIELDS
2329 unsigned int kind : 16;
2330 unsigned int mode : 16;
2332 enum kind kind : 16;
2333 enum machine_mode mode : 16;
2336 union real_extract du;
2337 struct addr_const addr;
2341 /* Express an rtx for a constant integer (perhaps symbolic)
2342 as the sum of a symbol or label plus an explicit integer.
2343 They are stored into VALUE. */
2346 decode_rtx_const (mode, x, value)
2347 enum machine_mode mode;
2349 struct rtx_const *value;
2351 /* Clear the whole structure, including any gaps. */
2354 int *p = (int *) value;
2355 int *end = (int *) (value + 1);
2360 value->kind = RTX_INT; /* Most usual kind. */
2363 switch (GET_CODE (x))
2366 value->kind = RTX_DOUBLE;
2367 value->mode = GET_MODE (x);
2368 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2372 value->un.addr.offset = INTVAL (x);
2378 value->un.addr.base = x;
2383 if (GET_CODE (x) == PLUS)
2385 value->un.addr.base = XEXP (x, 0);
2386 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2388 value->un.addr.offset = INTVAL (XEXP (x, 1));
2390 else if (GET_CODE (x) == MINUS)
2392 value->un.addr.base = XEXP (x, 0);
2393 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2395 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2405 if (value->kind == RTX_INT && value->un.addr.base != 0)
2406 switch (GET_CODE (value->un.addr.base))
2410 /* Use the string's address, not the SYMBOL_REF's address,
2411 for the sake of addresses of library routines.
2412 For a LABEL_REF, compare labels. */
2413 value->un.addr.base = XEXP (value->un.addr.base, 0);
2417 /* Given a MINUS expression, simplify it if both sides
2418 include the same symbol. */
2421 simplify_subtraction (x)
2424 struct rtx_const val0, val1;
2426 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2427 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2429 if (val0.un.addr.base == val1.un.addr.base)
2430 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2434 /* Compute a hash code for a constant RTL expression. */
2437 const_hash_rtx (mode, x)
2438 enum machine_mode mode;
2443 struct rtx_const value;
2444 decode_rtx_const (mode, x, &value);
2446 /* Compute hashing function */
2448 for (i = 0; i < sizeof value / sizeof (int); i++)
2449 hi += ((int *) &value)[i];
2451 hi &= (1 << HASHBITS) - 1;
2452 hi %= MAX_RTX_HASH_TABLE;
2456 /* Compare a constant rtl object X with a constant-descriptor DESC.
2457 Return 1 if DESC describes a constant with the same value as X. */
2460 compare_constant_rtx (mode, x, desc)
2461 enum machine_mode mode;
2463 struct constant_descriptor *desc;
2465 register int *p = (int *) desc->contents;
2468 struct rtx_const value;
2470 decode_rtx_const (mode, x, &value);
2471 strp = (int *) &value;
2472 len = sizeof value / sizeof (int);
2474 /* Compare constant contents. */
2476 if (*p++ != *strp++)
2482 /* Construct a constant descriptor for the rtl-expression X.
2483 It is up to the caller to enter the descriptor in the hash table. */
2485 static struct constant_descriptor *
2486 record_constant_rtx (mode, x)
2487 enum machine_mode mode;
2490 struct constant_descriptor *ptr;
2492 struct rtx_const value;
2494 decode_rtx_const (mode, x, &value);
2496 obstack_grow (current_obstack, &ptr, sizeof ptr);
2497 obstack_grow (current_obstack, &label, sizeof label);
2499 /* Record constant contents. */
2500 obstack_grow (current_obstack, &value, sizeof value);
2502 return (struct constant_descriptor *) obstack_finish (current_obstack);
2505 /* Given a constant rtx X, make (or find) a memory constant for its value
2506 and return a MEM rtx to refer to it in memory. */
2509 force_const_mem (mode, x)
2510 enum machine_mode mode;
2514 register struct constant_descriptor *desc;
2519 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2520 (this will always be true for floating CONST_DOUBLEs that have been
2521 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2522 use the previous copy. Otherwise, make a new one. Note that in
2523 the unlikely event that this same CONST_DOUBLE is used in two different
2524 modes in an alternating fashion, we will allocate a lot of different
2525 memory locations, but this should be extremely rare. */
2527 /* Don't use CONST_DOUBLE_MEM in a nested function.
2528 Nested functions have their own constant pools,
2529 so they can't share the same values in CONST_DOUBLE_MEM
2530 with the containing function. */
2531 if (outer_function_chain == 0)
2532 if (GET_CODE (x) == CONST_DOUBLE
2533 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2534 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2535 return CONST_DOUBLE_MEM (x);
2537 /* Compute hash code of X. Search the descriptors for that hash code
2538 to see if any of them describes X. If yes, the descriptor records
2539 the label number already assigned. */
2541 hash = const_hash_rtx (mode, x);
2543 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2544 if (compare_constant_rtx (mode, x, desc))
2546 found = desc->label;
2552 register struct pool_constant *pool;
2553 register struct pool_sym *sym;
2556 /* No constant equal to X is known to have been output.
2557 Make a constant descriptor to enter X in the hash table.
2558 Assign the label number and record it in the descriptor for
2559 future calls to this function to find. */
2561 desc = record_constant_rtx (mode, x);
2562 desc->next = const_rtx_hash_table[hash];
2563 const_rtx_hash_table[hash] = desc;
2565 /* Align the location counter as required by EXP's data type. */
2566 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2567 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2568 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2570 pool_offset += align - 1;
2571 pool_offset &= ~ (align - 1);
2573 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2575 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2579 pool->labelno = const_labelno;
2580 pool->align = align;
2581 pool->offset = pool_offset;
2587 last_pool->next = pool;
2590 pool_offset += GET_MODE_SIZE (mode);
2592 /* Create a string containing the label name, in LABEL. */
2593 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2598 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2600 /* Add label to symbol hash table. */
2601 hash = SYMHASH (found);
2602 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2605 sym->next = const_rtx_sym_hash_table[hash];
2606 const_rtx_sym_hash_table[hash] = sym;
2609 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2611 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2613 RTX_UNCHANGING_P (def) = 1;
2614 /* Mark the symbol_ref as belonging to this constants pool. */
2615 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2616 current_function_uses_const_pool = 1;
2618 if (outer_function_chain == 0)
2619 if (GET_CODE (x) == CONST_DOUBLE)
2621 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2623 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2624 const_double_chain = x;
2626 CONST_DOUBLE_MEM (x) = def;
2632 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2633 the corresponding pool_constant structure. */
2635 static struct pool_constant *
2636 find_pool_constant (addr)
2639 struct pool_sym *sym;
2640 char *label = XSTR (addr, 0);
2642 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2643 if (sym->label == label)
2649 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2652 get_pool_constant (addr)
2655 return (find_pool_constant (addr))->constant;
2658 /* Similar, return the mode. */
2661 get_pool_mode (addr)
2664 return (find_pool_constant (addr))->mode;
2667 /* Similar, return the offset in the constant pool. */
2670 get_pool_offset (addr)
2673 return (find_pool_constant (addr))->offset;
2676 /* Return the size of the constant pool. */
2684 /* Write all the constants in the constant pool. */
2687 output_constant_pool (fnname, fndecl)
2691 struct pool_constant *pool;
2693 union real_extract u;
2695 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2696 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
2699 for (pool = first_pool; pool; pool = pool->next)
2703 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2704 whose CODE_LABEL has been deleted. This can occur if a jump table
2705 is eliminated by optimization. If so, write a constant of zero
2706 instead. Note that this can also happen by turning the
2707 CODE_LABEL into a NOTE. */
2708 if (((GET_CODE (x) == LABEL_REF
2709 && (INSN_DELETED_P (XEXP (x, 0))
2710 || GET_CODE (XEXP (x, 0)) == NOTE)))
2711 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2712 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
2713 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
2714 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
2717 /* First switch to correct section. */
2718 #ifdef SELECT_RTX_SECTION
2719 SELECT_RTX_SECTION (pool->mode, x);
2721 readonly_data_section ();
2724 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2725 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
2726 pool->align, pool->labelno, done);
2729 if (pool->align > 1)
2730 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
2732 /* Output the label. */
2733 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
2735 /* Output the value of the constant itself. */
2736 switch (GET_MODE_CLASS (pool->mode))
2739 if (GET_CODE (x) != CONST_DOUBLE)
2742 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
2743 assemble_real (u.d, pool->mode);
2747 case MODE_PARTIAL_INT:
2748 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
2758 /* Done with this pool. */
2759 first_pool = last_pool = 0;
2762 /* Find all the constants whose addresses are referenced inside of EXP,
2763 and make sure assembler code with a label has been output for each one.
2764 Indicate whether an ADDR_EXPR has been encountered. */
2767 output_addressed_constants (exp)
2772 switch (TREE_CODE (exp))
2776 register tree constant = TREE_OPERAND (exp, 0);
2778 while (TREE_CODE (constant) == COMPONENT_REF)
2780 constant = TREE_OPERAND (constant, 0);
2783 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
2784 || TREE_CODE (constant) == CONSTRUCTOR)
2785 /* No need to do anything here
2786 for addresses of variables or functions. */
2787 output_constant_def (constant);
2794 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2795 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
2800 case NON_LVALUE_EXPR:
2801 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2807 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2808 if (TREE_VALUE (link) != 0)
2809 reloc |= output_addressed_constants (TREE_VALUE (link));
2819 /* Output assembler code for constant EXP to FILE, with no label.
2820 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2821 Assumes output_addressed_constants has been done on EXP already.
2823 Generate exactly SIZE bytes of assembler data, padding at the end
2824 with zeros if necessary. SIZE must always be specified.
2826 SIZE is important for structure constructors,
2827 since trailing members may have been omitted from the constructor.
2828 It is also important for initialization of arrays from string constants
2829 since the full length of the string constant might not be wanted.
2830 It is also needed for initialization of unions, where the initializer's
2831 type is just one member, and that may not be as long as the union.
2833 There a case in which we would fail to output exactly SIZE bytes:
2834 for a structure constructor that wants to produce more than SIZE bytes.
2835 But such constructors will never be generated for any possible input. */
2838 output_constant (exp, size)
2842 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
2848 /* Allow a constructor with no elements for any data type.
2849 This means to fill the space with zeros. */
2850 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
2852 assemble_zeros (size);
2856 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2857 That way we get the constant (we hope) inside it. */
2858 if (TREE_CODE (exp) == NOP_EXPR
2859 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
2860 exp = TREE_OPERAND (exp, 0);
2869 case REFERENCE_TYPE:
2870 /* ??? What about (int)((float)(int)&foo + 4) */
2871 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
2872 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2873 exp = TREE_OPERAND (exp, 0);
2875 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
2876 EXPAND_INITIALIZER),
2878 error ("initializer for integer value is too complicated");
2883 if (TREE_CODE (exp) != REAL_CST)
2884 error ("initializer for floating value is not a floating constant");
2886 assemble_real (TREE_REAL_CST (exp),
2887 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
2892 output_constant (TREE_REALPART (exp), size / 2);
2893 output_constant (TREE_IMAGPART (exp), size / 2);
2894 size -= (size / 2) * 2;
2898 if (TREE_CODE (exp) == CONSTRUCTOR)
2900 output_constructor (exp, size);
2903 else if (TREE_CODE (exp) == STRING_CST)
2907 if (size > TREE_STRING_LENGTH (exp))
2909 excess = size - TREE_STRING_LENGTH (exp);
2910 size = TREE_STRING_LENGTH (exp);
2913 assemble_string (TREE_STRING_POINTER (exp), size);
2922 if (TREE_CODE (exp) == CONSTRUCTOR)
2923 output_constructor (exp, size);
2930 assemble_zeros (size);
2933 /* Subroutine of output_constant, used for CONSTRUCTORs
2934 (aggregate constants).
2935 Generate at least SIZE bytes, padding if necessary. */
2938 output_constructor (exp, size)
2942 register tree link, field = 0;
2943 /* Number of bytes output or skipped so far.
2944 In other words, current position within the constructor. */
2945 int total_bytes = 0;
2946 /* Non-zero means BYTE contains part of a byte, to be output. */
2947 int byte_buffer_in_use = 0;
2950 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
2953 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2954 field = TYPE_FIELDS (TREE_TYPE (exp));
2956 /* As LINK goes through the elements of the constant,
2957 FIELD goes through the structure fields, if the constant is a structure.
2958 if the constant is a union, then we override this,
2959 by getting the field from the TREE_LIST element.
2960 But the constant could also be an array. Then FIELD is zero. */
2961 for (link = CONSTRUCTOR_ELTS (exp);
2963 link = TREE_CHAIN (link),
2964 field = field ? TREE_CHAIN (field) : 0)
2966 tree val = TREE_VALUE (link);
2967 /* the element in a union constructor specifies the proper field. */
2968 if (TREE_PURPOSE (link) != 0)
2969 field = TREE_PURPOSE (link);
2971 /* Eliminate the marker that makes a cast not be an lvalue. */
2975 if (field == 0 || !DECL_BIT_FIELD (field))
2977 register int fieldsize;
2978 /* Since this structure is static,
2979 we know the positions are constant. */
2980 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
2984 /* An element that is not a bit-field.
2985 Output any buffered-up bit-fields preceding it. */
2986 if (byte_buffer_in_use)
2988 ASM_OUTPUT_BYTE (asm_out_file, byte);
2990 byte_buffer_in_use = 0;
2993 /* Advance to offset of this element.
2994 Note no alignment needed in an array, since that is guaranteed
2995 if each element has the proper size. */
2996 if (field != 0 && bitpos != total_bytes)
2998 assemble_zeros (bitpos - total_bytes);
2999 total_bytes = bitpos;
3002 /* Determine size this element should occupy. */
3005 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3007 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3009 /* This avoids overflow trouble. */
3010 tree size_tree = size_binop (CEIL_DIV_EXPR,
3012 size_int (BITS_PER_UNIT));
3013 fieldsize = TREE_INT_CST_LOW (size_tree);
3017 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3018 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3022 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3024 /* Output the element's initial value. */
3026 assemble_zeros (fieldsize);
3028 output_constant (val, fieldsize);
3030 /* Count its size. */
3031 total_bytes += fieldsize;
3033 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3034 error ("invalid initial value for member `%s'",
3035 IDENTIFIER_POINTER (DECL_NAME (field)));
3038 /* Element that is a bit-field. */
3040 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3042 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3045 val = integer_zero_node;
3047 /* If this field does not start in this (or, next) byte,
3049 if (next_offset / BITS_PER_UNIT != total_bytes)
3051 /* Output remnant of any bit field in previous bytes. */
3052 if (byte_buffer_in_use)
3054 ASM_OUTPUT_BYTE (asm_out_file, byte);
3056 byte_buffer_in_use = 0;
3059 /* If still not at proper byte, advance to there. */
3060 if (next_offset / BITS_PER_UNIT != total_bytes)
3062 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3063 total_bytes = next_offset / BITS_PER_UNIT;
3067 if (! byte_buffer_in_use)
3070 /* We must split the element into pieces that fall within
3071 separate bytes, and combine each byte with previous or
3072 following bit-fields. */
3074 /* next_offset is the offset n fbits from the beginning of
3075 the structure to the next bit of this element to be processed.
3076 end_offset is the offset of the first bit past the end of
3078 while (next_offset < end_offset)
3082 int next_byte = next_offset / BITS_PER_UNIT;
3083 int next_bit = next_offset % BITS_PER_UNIT;
3085 /* Advance from byte to byte
3086 within this element when necessary. */
3087 while (next_byte != total_bytes)
3089 ASM_OUTPUT_BYTE (asm_out_file, byte);
3094 /* Number of bits we can process at once
3095 (all part of the same byte). */
3096 this_time = MIN (end_offset - next_offset,
3097 BITS_PER_UNIT - next_bit);
3098 #if BYTES_BIG_ENDIAN
3099 /* On big-endian machine, take the most significant bits
3100 first (of the bits that are significant)
3101 and put them into bytes from the most significant end. */
3102 shift = end_offset - next_offset - this_time;
3103 /* Don't try to take a bunch of bits that cross
3104 the word boundary in the INTEGER_CST. */
3105 if (shift < HOST_BITS_PER_WIDE_INT
3106 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3108 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3109 shift = HOST_BITS_PER_WIDE_INT;
3112 /* Now get the bits from the appropriate constant word. */
3113 if (shift < HOST_BITS_PER_WIDE_INT)
3115 value = TREE_INT_CST_LOW (val);
3117 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3119 value = TREE_INT_CST_HIGH (val);
3120 shift -= HOST_BITS_PER_WIDE_INT;
3124 byte |= (((value >> shift)
3125 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3126 << (BITS_PER_UNIT - this_time - next_bit));
3128 /* On little-endian machines,
3129 take first the least significant bits of the value
3130 and pack them starting at the least significant
3131 bits of the bytes. */
3132 shift = (next_offset
3133 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3134 /* Don't try to take a bunch of bits that cross
3135 the word boundary in the INTEGER_CST. */
3136 if (shift < HOST_BITS_PER_WIDE_INT
3137 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3139 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3140 shift = HOST_BITS_PER_WIDE_INT;
3143 /* Now get the bits from the appropriate constant word. */
3144 if (shift < HOST_BITS_PER_INT)
3145 value = TREE_INT_CST_LOW (val);
3146 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3148 value = TREE_INT_CST_HIGH (val);
3149 shift -= HOST_BITS_PER_WIDE_INT;
3153 byte |= ((value >> shift)
3154 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3156 next_offset += this_time;
3157 byte_buffer_in_use = 1;
3161 if (byte_buffer_in_use)
3163 ASM_OUTPUT_BYTE (asm_out_file, byte);
3166 if (total_bytes < size)
3167 assemble_zeros (size - total_bytes);