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 ();
92 static int contains_pointers_p ();
94 void output_constant_pool ();
95 void assemble_name ();
96 int output_addressed_constants ();
97 void output_constant ();
98 void output_constructor ();
100 void readonly_data_section ();
101 void data_section ();
103 #ifdef EXTRA_SECTIONS
104 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
107 static enum in_section {no_section, in_text, in_data} in_section
111 /* Define functions like text_section for any extra sections. */
112 #ifdef EXTRA_SECTION_FUNCTIONS
113 EXTRA_SECTION_FUNCTIONS
116 /* Tell assembler to switch to text section. */
121 if (in_section != in_text)
123 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
124 in_section = in_text;
128 /* Tell assembler to switch to data section. */
133 if (in_section != in_data)
135 if (flag_shared_data)
137 #ifdef SHARED_SECTION_ASM_OP
138 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
140 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
144 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
146 in_section = in_data;
150 /* Tell assembler to switch to read-only data section. This is normally
154 readonly_data_section ()
156 #ifdef READONLY_DATA_SECTION
157 READONLY_DATA_SECTION (); /* Note this can call data_section. */
163 /* Determine if we're in the text section. */
168 return in_section == in_text;
171 /* Create the rtl to represent a function, for a function definition.
172 DECL is a FUNCTION_DECL node which describes which function.
173 The rtl is stored into DECL. */
176 make_function_rtl (decl)
179 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
181 /* Rename a nested function to avoid conflicts. */
182 if (decl_function_context (decl) != 0
183 && DECL_INITIAL (decl) != 0
184 && DECL_RTL (decl) == 0)
188 name = IDENTIFIER_POINTER (DECL_NAME (decl));
189 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
190 name = obstack_copy0 (saveable_obstack, label, strlen (label));
194 if (DECL_RTL (decl) == 0)
197 = gen_rtx (MEM, DECL_MODE (decl),
198 gen_rtx (SYMBOL_REF, Pmode, name));
200 /* Optionally set flags or add text to the name to record information
201 such as that it is a function name. If the name is changed, the macro
202 ASM_OUTPUT_LABELREF will have to know how to strip this information.
203 And if it finds a * at the beginning after doing so, it must handle
205 #ifdef ENCODE_SECTION_INFO
206 ENCODE_SECTION_INFO (decl);
210 /* Record at least one function has been defined. */
211 function_defined = 1;
214 /* Given NAME, a putative register name, discard any customary prefixes. */
217 strip_reg_name (name)
220 #ifdef REGISTER_PREFIX
221 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
222 name += strlen (REGISTER_PREFIX);
224 if (name[0] == '%' || name[0] == '#')
229 /* Decode an `asm' spec for a declaration as a register name.
230 Return the register number, or -1 if nothing specified,
231 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
232 or -3 if ASMSPEC is `cc' and is not recognized,
233 or -4 if ASMSPEC is `memory' and is not recognized.
234 Accept an exact spelling or a decimal number.
235 Prefixes such as % are optional. */
238 decode_reg_name (asmspec)
245 /* Get rid of confusing prefixes. */
246 asmspec = strip_reg_name (asmspec);
248 /* Allow a decimal number as a "register name". */
249 for (i = strlen (asmspec) - 1; i >= 0; i--)
250 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
252 if (asmspec[0] != 0 && i < 0)
255 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
261 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
263 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
266 #ifdef ADDITIONAL_REGISTER_NAMES
268 static struct { char *name; int number; } table[]
269 = ADDITIONAL_REGISTER_NAMES;
271 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
272 if (! strcmp (asmspec, table[i].name))
273 return table[i].number;
275 #endif /* ADDITIONAL_REGISTER_NAMES */
277 if (!strcmp (asmspec, "memory"))
280 if (!strcmp (asmspec, "cc"))
289 /* Create the DECL_RTL for a declaration for a static or external variable
290 or static or external function.
291 ASMSPEC, if not 0, is the string which the user specified
292 as the assembler symbol name.
293 TOP_LEVEL is nonzero if this is a file-scope variable.
295 This is never called for PARM_DECL nodes. */
298 make_decl_rtl (decl, asmspec, top_level)
304 int reg_number = decode_reg_name (asmspec);
306 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
307 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
309 if (reg_number == -2)
311 /* ASMSPEC is given, and not the name of a register. */
312 name = (char *) obstack_alloc (saveable_obstack,
313 strlen (asmspec) + 2);
315 strcpy (&name[1], asmspec);
318 /* For a duplicate declaration, we can be called twice on the
319 same DECL node. Don't discard the RTL already made. */
320 if (DECL_RTL (decl) == 0)
324 /* First detect errors in declaring global registers. */
325 if (DECL_REGISTER (decl) && reg_number == -1)
326 error_with_decl (decl,
327 "register name not specified for `%s'");
328 else if (DECL_REGISTER (decl) && reg_number < 0)
329 error_with_decl (decl,
330 "invalid register name for `%s'");
331 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
332 error_with_decl (decl,
333 "register name given for non-register variable `%s'");
334 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
335 error ("function declared `register'");
336 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
337 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
338 else if (DECL_REGISTER (decl)
339 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
340 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
341 /* Now handle properly declared static register variables. */
342 else if (DECL_REGISTER (decl))
345 #if 0 /* yylex should print the warning for this */
347 pedwarn ("ANSI C forbids global register variables");
349 if (DECL_INITIAL (decl) != 0 && top_level)
351 DECL_INITIAL (decl) = 0;
352 error ("global register variable has initial value");
354 if (fixed_regs[reg_number] == 0
355 && function_defined && top_level)
356 error ("global register variable follows a function definition");
357 if (TREE_THIS_VOLATILE (decl))
358 warning ("volatile register variables don't work as you might wish");
360 /* If the user specified one of the eliminables registers here,
361 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
362 confused with that register and be eliminated. Although this
363 usage is somewhat suspect, we nevertheless use the following
364 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
367 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
368 REGNO (DECL_RTL (decl)) = reg_number;
369 REG_USERVAR_P (DECL_RTL (decl)) = 1;
373 /* Make this register fixed, so not usable for anything else. */
374 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
376 global_regs[reg_number + --nregs] = 1;
381 /* Now handle ordinary static variables and functions (in memory).
382 Also handle vars declared register invalidly. */
383 if (DECL_RTL (decl) == 0)
385 /* Can't use just the variable's own name for a variable
386 whose scope is less than the whole file.
387 Concatenate a distinguishing number. */
388 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
392 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
393 name = obstack_copy0 (saveable_obstack, label, strlen (label));
397 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
398 gen_rtx (SYMBOL_REF, Pmode, name));
399 if (TREE_THIS_VOLATILE (decl)
400 || (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
401 && TREE_PUBLIC (decl)))
402 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
403 if (TREE_READONLY (decl))
404 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
405 MEM_IN_STRUCT_P (DECL_RTL (decl))
406 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
407 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
408 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
409 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
411 /* Optionally set flags or add text to the name to record information
412 such as that it is a function name.
413 If the name is changed, the macro ASM_OUTPUT_LABELREF
414 will have to know how to strip this information.
415 And if it finds a * at the beginning after doing so,
416 it must handle that too. */
417 #ifdef ENCODE_SECTION_INFO
418 ENCODE_SECTION_INFO (decl);
422 /* If the old RTL had the wrong mode, fix the mode. */
423 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
425 rtx rtl = DECL_RTL (decl);
426 PUT_MODE (rtl, DECL_MODE (decl));
430 /* Make the rtl for variable VAR be volatile.
431 Use this only for static variables. */
434 make_var_volatile (var)
437 if (GET_CODE (DECL_RTL (var)) != MEM)
440 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
443 /* Output alignment directive to align for constant expression EXP. */
446 assemble_constant_align (exp)
451 /* Align the location counter as required by EXP's data type. */
452 align = TYPE_ALIGN (TREE_TYPE (exp));
453 #ifdef CONSTANT_ALIGNMENT
454 align = CONSTANT_ALIGNMENT (exp, align);
457 if (align > BITS_PER_UNIT)
458 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
461 /* Output a string of literal assembler code
462 for an `asm' keyword used between functions. */
465 assemble_asm (string)
470 if (TREE_CODE (string) == ADDR_EXPR)
471 string = TREE_OPERAND (string, 0);
473 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
476 #if 0 /* This should no longer be needed, because
477 flag_gnu_linker should be 0 on these systems,
478 which should prevent any output
479 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
480 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
481 #ifndef ASM_OUTPUT_CONSTRUCTOR
482 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
484 #ifndef ASM_OUTPUT_DESTRUCTOR
485 #define ASM_OUTPUT_DESTRUCTOR(file, name)
490 /* Record an element in the table of global destructors.
491 How this is done depends on what sort of assembler and linker
494 NAME should be the name of a global function to be called
495 at exit time. This name is output using assemble_name. */
498 assemble_destructor (name)
501 #ifdef ASM_OUTPUT_DESTRUCTOR
502 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
506 /* Now tell GNU LD that this is part of the static destructor set. */
507 /* This code works for any machine provided you use GNU as/ld. */
508 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
509 assemble_name (asm_out_file, name);
510 fputc ('\n', asm_out_file);
515 /* Likewise for global constructors. */
518 assemble_constructor (name)
521 #ifdef ASM_OUTPUT_CONSTRUCTOR
522 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
526 /* Now tell GNU LD that this is part of the static constructor set. */
527 /* This code works for any machine provided you use GNU as/ld. */
528 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
529 assemble_name (asm_out_file, name);
530 fputc ('\n', asm_out_file);
535 /* Likewise for entries we want to record for garbage collection.
536 Garbage collection is still under development. */
539 assemble_gc_entry (name)
542 #ifdef ASM_OUTPUT_GC_ENTRY
543 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
547 /* Now tell GNU LD that this is part of the static constructor set. */
548 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
549 assemble_name (asm_out_file, name);
550 fputc ('\n', asm_out_file);
555 /* Output assembler code for the constant pool of a function and associated
556 with defining the name of the function. DECL describes the function.
557 NAME is the function's name. For the constant pool, we use the current
558 constant pool data. */
561 assemble_start_function (decl, fnname)
567 /* The following code does not need preprocessing in the assembler. */
571 output_constant_pool (fnname, decl);
576 /* Tell assembler to move to target machine's alignment for functions. */
577 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
579 ASM_OUTPUT_ALIGN (asm_out_file, align);
581 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
582 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
585 #ifdef SDB_DEBUGGING_INFO
586 /* Output SDB definition of the function. */
587 if (write_symbols == SDB_DEBUG)
588 sdbout_mark_begin_function ();
591 #ifdef DBX_DEBUGGING_INFO
592 /* Output DBX definition of the function. */
593 if (write_symbols == DBX_DEBUG)
594 dbxout_begin_function (decl);
597 /* Make function name accessible from other files, if appropriate. */
599 if (TREE_PUBLIC (decl))
601 if (!first_global_object_name)
602 STRIP_NAME_ENCODING (first_global_object_name, fnname);
603 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
606 /* Do any machine/system dependent processing of the function name */
607 #ifdef ASM_DECLARE_FUNCTION_NAME
608 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
610 /* Standard thing is just output label for the function. */
611 ASM_OUTPUT_LABEL (asm_out_file, fnname);
612 #endif /* ASM_DECLARE_FUNCTION_NAME */
615 /* Output assembler code associated with defining the size of the
616 function. DECL describes the function. NAME is the function's name. */
619 assemble_end_function (decl, fnname)
623 #ifdef ASM_DECLARE_FUNCTION_SIZE
624 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
628 /* Assemble code to leave SIZE bytes of zeros. */
631 assemble_zeros (size)
634 #ifdef ASM_NO_SKIP_IN_TEXT
635 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
636 so we must output 0s explicitly in the text section. */
637 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
641 for (i = 0; i < size - 20; i += 20)
644 fprintf (asm_out_file,
645 "%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);
647 fprintf (asm_out_file,
648 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
654 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
656 fprintf (asm_out_file, "\tbyte 0");
659 for (; i < size; i++)
660 fprintf (asm_out_file, ",0");
661 fprintf (asm_out_file, "\n");
667 ASM_OUTPUT_SKIP (asm_out_file, size);
670 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
673 assemble_align (align)
676 if (align > BITS_PER_UNIT)
677 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
680 /* Assemble a string constant with the specified C string as contents. */
683 assemble_string (p, size)
691 /* If the string is very long, split it up. */
695 int thissize = size - pos;
696 if (thissize > maximum)
699 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
706 /* Assemble everything that is needed for a variable or function declaration.
707 Not used for automatic variables, and not used for function definitions.
708 Should not be called for variables of incomplete structure type.
710 TOP_LEVEL is nonzero if this variable has file scope.
711 AT_END is nonzero if this is the special handling, at end of compilation,
712 to define things that have had only tentative definitions.
713 DONT_OUTPUT_DATA if nonzero means don't actually output the
714 initial value (that will be done by the caller). */
717 assemble_variable (decl, top_level, at_end, dont_output_data)
726 enum in_section saved_in_section;
728 if (GET_CODE (DECL_RTL (decl)) == REG)
730 /* Do output symbol info for global register variables, but do nothing
733 if (TREE_ASM_WRITTEN (decl))
735 TREE_ASM_WRITTEN (decl) = 1;
737 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
738 /* File-scope global variables are output here. */
739 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
741 dbxout_symbol (decl, 0);
743 #ifdef SDB_DEBUGGING_INFO
744 if (write_symbols == SDB_DEBUG && top_level
745 /* Leave initialized global vars for end of compilation;
746 see comment in compile_file. */
747 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
748 sdbout_symbol (decl, 0);
751 /* Don't output any DWARF debugging information for variables here.
752 In the case of local variables, the information for them is output
753 when we do our recursive traversal of the tree representation for
754 the entire containing function. In the case of file-scope variables,
755 we output information for all of them at the very end of compilation
756 while we are doing our final traversal of the chain of file-scope
762 /* Normally no need to say anything here for external references,
763 since assemble_external is called by the langauge-specific code
764 when a declaration is first seen. */
766 if (DECL_EXTERNAL (decl))
769 /* Output no assembler code for a function declaration.
770 Only definitions of functions output anything. */
772 if (TREE_CODE (decl) == FUNCTION_DECL)
775 /* If type was incomplete when the variable was declared,
776 see if it is complete now. */
778 if (DECL_SIZE (decl) == 0)
779 layout_decl (decl, 0);
781 /* Still incomplete => don't allocate it; treat the tentative defn
782 (which is what it must have been) as an `extern' reference. */
784 if (!dont_output_data && DECL_SIZE (decl) == 0)
786 error_with_file_and_line (DECL_SOURCE_FILE (decl),
787 DECL_SOURCE_LINE (decl),
788 "storage size of `%s' isn't known",
789 IDENTIFIER_POINTER (DECL_NAME (decl)));
793 /* The first declaration of a variable that comes through this function
794 decides whether it is global (in C, has external linkage)
795 or local (in C, has internal linkage). So do nothing more
796 if this function has already run. */
798 if (TREE_ASM_WRITTEN (decl))
801 TREE_ASM_WRITTEN (decl) = 1;
803 /* If storage size is erroneously variable, just continue.
804 Error message was already made. */
806 if (DECL_SIZE (decl))
808 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
813 /* This is better than explicit arithmetic, since it avoids overflow. */
814 size_tree = size_binop (CEIL_DIV_EXPR,
815 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
817 if (TREE_INT_CST_HIGH (size_tree) != 0)
819 error_with_decl (decl, "size of variable `%s' is too large");
824 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
826 /* Handle uninitialized definitions. */
828 /* ANSI specifies that a tentative definition which is not merged with
829 a non-tentative definition behaves exactly like a definition with an
830 initializer equal to zero. (Section 3.7.2)
831 -fno-common gives strict ANSI behavior. Usually you don't want it.
832 This matters only for variables with external linkage. */
833 if ((! flag_no_common || ! TREE_PUBLIC (decl))
834 && ! dont_output_data
835 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
837 int size = TREE_INT_CST_LOW (size_tree);
840 if (TREE_INT_CST_HIGH (size_tree) != 0)
841 error_with_decl (decl, "size of variable `%s' is too large");
842 /* Don't allocate zero bytes of common,
843 since that means "undefined external" in the linker. */
844 if (size == 0) rounded = 1;
845 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
846 so that each uninitialized object starts on such a boundary. */
847 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
848 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
849 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
851 #ifdef DBX_DEBUGGING_INFO
852 /* File-scope global variables are output here. */
853 if (write_symbols == DBX_DEBUG && top_level)
854 dbxout_symbol (decl, 0);
856 #ifdef SDB_DEBUGGING_INFO
857 if (write_symbols == SDB_DEBUG && top_level
858 /* Leave initialized global vars for end of compilation;
859 see comment in compile_file. */
860 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
861 sdbout_symbol (decl, 0);
864 /* Don't output any DWARF debugging information for variables here.
865 In the case of local variables, the information for them is output
866 when we do our recursive traversal of the tree representation for
867 the entire containing function. In the case of file-scope variables,
868 we output information for all of them at the very end of compilation
869 while we are doing our final traversal of the chain of file-scope
873 if (flag_shared_data)
876 if (TREE_PUBLIC (decl))
878 #ifdef ASM_OUTPUT_SHARED_COMMON
879 if (flag_shared_data)
880 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
883 #ifdef ASM_OUTPUT_ALIGNED_COMMON
884 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
887 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
892 #ifdef ASM_OUTPUT_SHARED_LOCAL
893 if (flag_shared_data)
894 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
897 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
898 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
901 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
907 /* Handle initialized definitions. */
909 /* First make the assembler name(s) global if appropriate. */
910 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
912 if (!first_global_object_name)
913 STRIP_NAME_ENCODING(first_global_object_name, name);
914 ASM_GLOBALIZE_LABEL (asm_out_file, name);
917 for (d = equivalents; d; d = TREE_CHAIN (d))
919 tree e = TREE_VALUE (d);
920 if (TREE_PUBLIC (e) && DECL_NAME (e))
921 ASM_GLOBALIZE_LABEL (asm_out_file,
922 XSTR (XEXP (DECL_RTL (e), 0), 0));
926 /* Output any data that we will need to use the address of. */
927 if (DECL_INITIAL (decl) == error_mark_node)
928 reloc = contains_pointers_p (TREE_TYPE (decl));
929 else if (DECL_INITIAL (decl))
930 reloc = output_addressed_constants (DECL_INITIAL (decl));
932 /* Switch to the proper section for this data. */
933 #ifdef SELECT_SECTION
934 SELECT_SECTION (decl, reloc);
936 if (TREE_READONLY (decl)
937 && ! TREE_THIS_VOLATILE (decl)
938 && ! (flag_pic && reloc))
939 readonly_data_section ();
944 /* Record current section so we can restore it if dbxout.c clobbers it. */
945 saved_in_section = in_section;
947 /* Output the dbx info now that we have chosen the section. */
949 #ifdef DBX_DEBUGGING_INFO
950 /* File-scope global variables are output here. */
951 if (write_symbols == DBX_DEBUG && top_level)
952 dbxout_symbol (decl, 0);
954 #ifdef SDB_DEBUGGING_INFO
955 if (write_symbols == SDB_DEBUG && top_level
956 /* Leave initialized global vars for end of compilation;
957 see comment in compile_file. */
958 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
959 sdbout_symbol (decl, 0);
962 /* Don't output any DWARF debugging information for variables here.
963 In the case of local variables, the information for them is output
964 when we do our recursive traversal of the tree representation for
965 the entire containing function. In the case of file-scope variables,
966 we output information for all of them at the very end of compilation
967 while we are doing our final traversal of the chain of file-scope
970 if (in_section != saved_in_section)
972 /* Switch to the proper section for this data. */
973 #ifdef SELECT_SECTION
974 SELECT_SECTION (decl, reloc);
976 if (TREE_READONLY (decl)
977 && ! TREE_THIS_VOLATILE (decl)
978 && ! (flag_pic && reloc))
979 readonly_data_section ();
985 /* Compute and output the alignment of this data. */
987 align = DECL_ALIGN (decl);
988 /* In the case for initialing an array whose length isn't specified,
989 where we have not yet been able to do the layout,
990 figure out the proper alignment now. */
991 if (dont_output_data && DECL_SIZE (decl) == 0
992 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
993 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
995 /* Some object file formats have a maximum alignment which they support.
996 In particular, a.out format supports a maximum alignment of 4. */
997 #ifndef MAX_OFILE_ALIGNMENT
998 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1000 if (align > MAX_OFILE_ALIGNMENT)
1002 warning_with_decl (decl,
1003 "alignment of `%s' is greater than maximum object file alignment");
1004 align = MAX_OFILE_ALIGNMENT;
1006 #ifdef DATA_ALIGNMENT
1007 /* On some machines, it is good to increase alignment sometimes. */
1008 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1010 #ifdef CONSTANT_ALIGNMENT
1011 if (DECL_INITIAL (decl))
1012 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1015 /* Reset the alignment in case we have made it tighter, so we can benefit
1016 from it in get_pointer_alignment. */
1017 DECL_ALIGN (decl) = align;
1019 if (align > BITS_PER_UNIT)
1020 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1022 /* Do any machine/system dependent processing of the object. */
1023 #ifdef ASM_DECLARE_OBJECT_NAME
1024 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1026 /* Standard thing is just output label for the object. */
1027 ASM_OUTPUT_LABEL (asm_out_file, name);
1028 #endif /* ASM_DECLARE_OBJECT_NAME */
1030 if (!dont_output_data)
1032 if (DECL_INITIAL (decl))
1033 /* Output the actual data. */
1034 output_constant (DECL_INITIAL (decl),
1035 int_size_in_bytes (TREE_TYPE (decl)));
1037 /* Leave space for it. */
1038 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1042 #ifdef XCOFF_DEBUGGING_INFO
1043 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1044 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1045 and `aa' hasn't been output yet, the assembler generates a stab entry with
1046 a value of zero, in addition to creating an unnecessary external entry
1047 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1049 /* File-scope global variables are output here. */
1050 if (write_symbols == XCOFF_DEBUG && top_level)
1051 dbxout_symbol (decl, 0);
1053 /* There must be a statement after a label. */
1058 /* Return 1 if type TYPE contains any pointers. */
1061 contains_pointers_p (type)
1064 switch (TREE_CODE (type))
1067 case REFERENCE_TYPE:
1068 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1069 so I'll play safe and return 1. */
1075 case QUAL_UNION_TYPE:
1078 /* For a type that has fields, see if the fields have pointers. */
1079 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1080 if (contains_pointers_p (TREE_TYPE (fields)))
1086 /* An array type contains pointers if its element type does. */
1087 return contains_pointers_p (TREE_TYPE (type));
1094 /* Output something to declare an external symbol to the assembler.
1095 (Most assemblers don't need this, so we normally output nothing.)
1096 Do nothing if DECL is not external. */
1099 assemble_external (decl)
1102 #ifdef ASM_OUTPUT_EXTERNAL
1103 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1104 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1106 rtx rtl = DECL_RTL (decl);
1108 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1109 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1111 /* Some systems do require some output. */
1112 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1113 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1119 /* Similar, for calling a library function FUN. */
1122 assemble_external_libcall (fun)
1125 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1126 /* Declare library function name external when first used, if nec. */
1127 if (! SYMBOL_REF_USED (fun))
1129 SYMBOL_REF_USED (fun) = 1;
1130 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1135 /* Declare the label NAME global. */
1138 assemble_global (name)
1141 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1144 /* Assemble a label named NAME. */
1147 assemble_label (name)
1150 ASM_OUTPUT_LABEL (asm_out_file, name);
1153 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1154 If NAME starts with a *, the rest of NAME is output verbatim.
1155 Otherwise NAME is transformed in an implementation-defined way
1156 (usually by the addition of an underscore).
1157 Many macros in the tm file are defined to call this function. */
1160 assemble_name (file, name)
1165 fputs (&name[1], file);
1167 ASM_OUTPUT_LABELREF (file, name);
1170 /* Allocate SIZE bytes writable static space with a gensym name
1171 and return an RTX to refer to its address. */
1174 assemble_static_space (size)
1180 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1181 so that each uninitialized object starts on such a boundary. */
1182 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1183 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1184 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1187 if (flag_shared_data)
1191 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1194 namestring = (char *) obstack_alloc (saveable_obstack,
1196 strcpy (namestring, name);
1198 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1199 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1200 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1202 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1207 /* Assemble the static constant template for function entry trampolines.
1208 This is done at most once per compilation.
1209 Returns an RTX for the address of the template. */
1212 assemble_trampoline_template ()
1218 /* By default, put trampoline templates in read-only data section. */
1220 #ifdef TRAMPOLINE_SECTION
1221 TRAMPOLINE_SECTION ();
1223 readonly_data_section ();
1226 /* Write the assembler code to define one. */
1227 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1229 ASM_OUTPUT_ALIGN (asm_out_file, align);
1231 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1232 TRAMPOLINE_TEMPLATE (asm_out_file);
1234 /* Record the rtl to refer to it. */
1235 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1237 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1238 return gen_rtx (SYMBOL_REF, Pmode, name);
1241 /* Assemble the integer constant X into an object of SIZE bytes.
1242 X must be either a CONST_INT or CONST_DOUBLE.
1244 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1245 non-zero, abort if we can't output the constant. */
1248 assemble_integer (x, size, force)
1253 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1254 ASM_OUTPUT... macros. */
1258 #ifdef ASM_OUTPUT_CHAR
1260 ASM_OUTPUT_CHAR (asm_out_file, x);
1264 #ifdef ASM_OUTPUT_SHORT
1266 ASM_OUTPUT_SHORT (asm_out_file, x);
1270 #ifdef ASM_OUTPUT_INT
1272 ASM_OUTPUT_INT (asm_out_file, x);
1276 #ifdef ASM_OUTPUT_DOUBLE_INT
1278 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1282 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1284 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1289 /* If we couldn't do it that way, there are two other possibilities: First,
1290 if the machine can output an explicit byte and this is a 1 byte constant,
1291 we can use ASM_OUTPUT_BYTE. */
1293 #ifdef ASM_OUTPUT_BYTE
1294 if (size == 1 && GET_CODE (x) == CONST_INT)
1296 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1301 /* Finally, if SIZE is larger than a single word, try to output the constant
1302 one word at a time. */
1304 if (size > UNITS_PER_WORD)
1307 enum machine_mode mode
1308 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1311 for (i = 0; i < size / UNITS_PER_WORD; i++)
1313 word = operand_subword (x, i, 0, mode);
1318 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1322 if (i == size / UNITS_PER_WORD)
1324 /* If we output at least one word and then could not finish,
1325 there is no valid way to continue. */
1336 /* Assemble the floating-point constant D into an object of size MODE. */
1339 assemble_real (d, mode)
1341 enum machine_mode mode;
1343 jmp_buf output_constant_handler;
1345 if (setjmp (output_constant_handler))
1347 error ("floating point trap outputting a constant");
1348 #ifdef REAL_IS_NOT_DOUBLE
1349 bzero (&d, sizeof d);
1356 set_float_handler (output_constant_handler);
1360 #ifdef ASM_OUTPUT_BYTE_FLOAT
1362 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1365 #ifdef ASM_OUTPUT_SHORT_FLOAT
1367 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1370 #ifdef ASM_OUTPUT_FLOAT
1372 ASM_OUTPUT_FLOAT (asm_out_file, d);
1376 #ifdef ASM_OUTPUT_DOUBLE
1378 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1382 #ifdef ASM_OUTPUT_LONG_DOUBLE
1385 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1393 set_float_handler (NULL_PTR);
1396 /* Here we combine duplicate floating constants to make
1397 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1399 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1400 They are chained through the CONST_DOUBLE_CHAIN.
1401 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1402 In that case, CONST_DOUBLE_MEM is either a MEM,
1403 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1405 (CONST_DOUBLE_MEM is used only for top-level functions.
1406 See force_const_mem for explanation.) */
1408 static rtx const_double_chain;
1410 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1411 For an integer, I0 is the low-order word and I1 is the high-order word.
1412 For a real number, I0 is the word with the low address
1413 and I1 is the word with the high address. */
1416 immed_double_const (i0, i1, mode)
1417 HOST_WIDE_INT i0, i1;
1418 enum machine_mode mode;
1421 int in_current_obstack;
1423 if (GET_MODE_CLASS (mode) == MODE_INT
1424 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1426 /* We clear out all bits that don't belong in MODE, unless they and our
1427 sign bit are all one. So we get either a reasonable negative value
1428 or a reasonable unsigned value for this mode. */
1429 int width = GET_MODE_BITSIZE (mode);
1430 if (width < HOST_BITS_PER_WIDE_INT
1431 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1432 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1433 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1434 else if (width == HOST_BITS_PER_WIDE_INT
1435 && ! (i1 == ~0 && i0 < 0))
1437 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1438 /* We cannot represent this value as a constant. */
1441 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1443 ??? Strictly speaking, this is wrong if we create a CONST_INT
1444 for a large unsigned constant with the size of MODE being
1445 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1446 wider mode. In that case we will mis-interpret it as a negative
1449 Unfortunately, the only alternative is to make a CONST_DOUBLE
1450 for any constant in any mode if it is an unsigned constant larger
1451 than the maximum signed integer in an int on the host. However,
1452 doing this will break everyone that always expects to see a CONST_INT
1453 for SImode and smaller.
1455 We have always been making CONST_INTs in this case, so nothing new
1458 if (width <= HOST_BITS_PER_WIDE_INT)
1459 i1 = (i0 < 0) ? ~0 : 0;
1461 /* If this integer fits in one word, return a CONST_INT. */
1462 if ((i1 == 0 && i0 >= 0)
1463 || (i1 == ~0 && i0 < 0))
1464 return GEN_INT (i0);
1466 /* We use VOIDmode for integers. */
1470 /* Search the chain for an existing CONST_DOUBLE with the right value.
1471 If one is found, return it. */
1473 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1474 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1475 && GET_MODE (r) == mode)
1478 /* No; make a new one and add it to the chain.
1480 We may be called by an optimizer which may be discarding any memory
1481 allocated during its processing (such as combine and loop). However,
1482 we will be leaving this constant on the chain, so we cannot tolerate
1483 freed memory. So switch to saveable_obstack for this allocation
1484 and then switch back if we were in current_obstack. */
1486 push_obstacks_nochange ();
1487 rtl_in_saveable_obstack ();
1488 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1491 /* Don't touch const_double_chain in nested function;
1492 see force_const_mem. */
1493 if (outer_function_chain == 0)
1495 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1496 const_double_chain = r;
1499 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1500 Actual use of mem-slot is only through force_const_mem. */
1502 CONST_DOUBLE_MEM (r) = const0_rtx;
1507 /* Return a CONST_DOUBLE for a specified `double' value
1508 and machine mode. */
1511 immed_real_const_1 (d, mode)
1513 enum machine_mode mode;
1515 union real_extract u;
1517 int in_current_obstack;
1519 /* Get the desired `double' value as a sequence of ints
1520 since that is how they are stored in a CONST_DOUBLE. */
1524 /* Detect special cases. */
1526 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1527 if (!bcmp (&dconst0, &d, sizeof d))
1528 return CONST0_RTX (mode);
1529 /* Check for NaN first, because some ports (specifically the i386) do not
1530 emit correct ieee-fp code by default, and thus will generate a core
1531 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1532 does a floating point comparison. */
1533 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1534 return CONST1_RTX (mode);
1536 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1537 return immed_double_const (u.i[0], u.i[1], mode);
1539 /* The rest of this function handles the case where
1540 a float value requires more than 2 ints of space.
1541 It will be deleted as dead code on machines that don't need it. */
1543 /* Search the chain for an existing CONST_DOUBLE with the right value.
1544 If one is found, return it. */
1546 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1547 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1548 && GET_MODE (r) == mode)
1551 /* No; make a new one and add it to the chain.
1553 We may be called by an optimizer which may be discarding any memory
1554 allocated during its processing (such as combine and loop). However,
1555 we will be leaving this constant on the chain, so we cannot tolerate
1556 freed memory. So switch to saveable_obstack for this allocation
1557 and then switch back if we were in current_obstack. */
1559 push_obstacks_nochange ();
1560 rtl_in_saveable_obstack ();
1561 r = rtx_alloc (CONST_DOUBLE);
1563 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1566 /* Don't touch const_double_chain in nested function;
1567 see force_const_mem. */
1568 if (outer_function_chain == 0)
1570 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1571 const_double_chain = r;
1574 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1575 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1576 is only through force_const_mem. */
1578 CONST_DOUBLE_MEM (r) = const0_rtx;
1583 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1584 which must be a REAL_CST tree node. */
1587 immed_real_const (exp)
1590 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1593 /* At the end of a function, forget the memory-constants
1594 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1595 Also clear out real_constant_chain and clear out all the chain-pointers. */
1598 clear_const_double_mem ()
1600 register rtx r, next;
1602 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1603 See force_const_mem for explanation. */
1604 if (outer_function_chain != 0)
1607 for (r = const_double_chain; r; r = next)
1609 next = CONST_DOUBLE_CHAIN (r);
1610 CONST_DOUBLE_CHAIN (r) = 0;
1611 CONST_DOUBLE_MEM (r) = cc0_rtx;
1613 const_double_chain = 0;
1616 /* Given an expression EXP with a constant value,
1617 reduce it to the sum of an assembler symbol and an integer.
1618 Store them both in the structure *VALUE.
1619 Abort if EXP does not reduce. */
1624 HOST_WIDE_INT offset;
1628 decode_addr_const (exp, value)
1630 struct addr_const *value;
1632 register tree target = TREE_OPERAND (exp, 0);
1633 register int offset = 0;
1638 if (TREE_CODE (target) == COMPONENT_REF
1639 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1642 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1643 target = TREE_OPERAND (target, 0);
1645 else if (TREE_CODE (target) == ARRAY_REF)
1647 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1648 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1650 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1651 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1653 target = TREE_OPERAND (target, 0);
1659 switch (TREE_CODE (target))
1663 x = DECL_RTL (target);
1667 x = gen_rtx (MEM, FUNCTION_MODE,
1668 gen_rtx (LABEL_REF, VOIDmode,
1669 label_rtx (TREE_OPERAND (exp, 0))));
1676 x = TREE_CST_RTL (target);
1683 if (GET_CODE (x) != MEM)
1688 value->offset = offset;
1691 /* Uniquize all constants that appear in memory.
1692 Each constant in memory thus far output is recorded
1693 in `const_hash_table' with a `struct constant_descriptor'
1694 that contains a polish representation of the value of
1697 We cannot store the trees in the hash table
1698 because the trees may be temporary. */
1700 struct constant_descriptor
1702 struct constant_descriptor *next;
1708 #define MAX_HASH_TABLE 1009
1709 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1711 /* Compute a hash code for a constant expression. */
1718 register int len, hi, i;
1719 register enum tree_code code = TREE_CODE (exp);
1721 if (code == INTEGER_CST)
1723 p = (char *) &TREE_INT_CST_LOW (exp);
1724 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1726 else if (code == REAL_CST)
1728 p = (char *) &TREE_REAL_CST (exp);
1729 len = sizeof TREE_REAL_CST (exp);
1731 else if (code == STRING_CST)
1732 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1733 else if (code == COMPLEX_CST)
1734 return const_hash (TREE_REALPART (exp)) * 5
1735 + const_hash (TREE_IMAGPART (exp));
1736 else if (code == CONSTRUCTOR)
1740 /* For record type, include the type in the hashing.
1741 We do not do so for array types
1742 because (1) the sizes of the elements are sufficient
1743 and (2) distinct array types can have the same constructor.
1744 Instead, we include the array size because the constructor could
1746 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1747 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
1750 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
1751 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
1753 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1754 if (TREE_VALUE (link))
1755 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
1759 else if (code == ADDR_EXPR)
1761 struct addr_const value;
1762 decode_addr_const (exp, &value);
1763 if (GET_CODE (value.base) == SYMBOL_REF)
1765 /* Don't hash the address of the SYMBOL_REF;
1766 only use the offset and the symbol name. */
1768 p = XSTR (value.base, 0);
1769 for (i = 0; p[i] != 0; i++)
1770 hi = ((hi * 613) + (unsigned)(p[i]));
1772 else if (GET_CODE (value.base) == LABEL_REF)
1773 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
1775 hi &= (1 << HASHBITS) - 1;
1776 hi %= MAX_HASH_TABLE;
1779 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1780 return const_hash (TREE_OPERAND (exp, 0)) * 9
1781 + const_hash (TREE_OPERAND (exp, 1));
1782 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1783 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
1785 /* Compute hashing function */
1787 for (i = 0; i < len; i++)
1788 hi = ((hi * 613) + (unsigned)(p[i]));
1790 hi &= (1 << HASHBITS) - 1;
1791 hi %= MAX_HASH_TABLE;
1795 /* Compare a constant expression EXP with a constant-descriptor DESC.
1796 Return 1 if DESC describes a constant with the same value as EXP. */
1799 compare_constant (exp, desc)
1801 struct constant_descriptor *desc;
1803 return 0 != compare_constant_1 (exp, desc->contents);
1806 /* Compare constant expression EXP with a substring P of a constant descriptor.
1807 If they match, return a pointer to the end of the substring matched.
1808 If they do not match, return 0.
1810 Since descriptors are written in polish prefix notation,
1811 this function can be used recursively to test one operand of EXP
1812 against a subdescriptor, and if it succeeds it returns the
1813 address of the subdescriptor for the next operand. */
1816 compare_constant_1 (exp, p)
1820 register char *strp;
1822 register enum tree_code code = TREE_CODE (exp);
1824 if (code != (enum tree_code) *p++)
1827 if (code == INTEGER_CST)
1829 /* Integer constants are the same only if the same width of type. */
1830 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1832 strp = (char *) &TREE_INT_CST_LOW (exp);
1833 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1835 else if (code == REAL_CST)
1837 /* Real constants are the same only if the same width of type. */
1838 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1840 strp = (char *) &TREE_REAL_CST (exp);
1841 len = sizeof TREE_REAL_CST (exp);
1843 else if (code == STRING_CST)
1845 if (flag_writable_strings)
1847 strp = TREE_STRING_POINTER (exp);
1848 len = TREE_STRING_LENGTH (exp);
1849 if (bcmp (&TREE_STRING_LENGTH (exp), p,
1850 sizeof TREE_STRING_LENGTH (exp)))
1852 p += sizeof TREE_STRING_LENGTH (exp);
1854 else if (code == COMPLEX_CST)
1856 p = compare_constant_1 (TREE_REALPART (exp), p);
1857 if (p == 0) return 0;
1858 p = compare_constant_1 (TREE_IMAGPART (exp), p);
1861 else if (code == CONSTRUCTOR)
1864 int length = list_length (CONSTRUCTOR_ELTS (exp));
1867 if (bcmp (&length, p, sizeof length))
1871 /* For record constructors, insist that the types match.
1872 For arrays, just verify both constructors are for arrays. */
1873 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1874 type = TREE_TYPE (exp);
1877 if (bcmp (&type, p, sizeof type))
1881 /* For arrays, insist that the size in bytes match. */
1882 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1884 int size = int_size_in_bytes (TREE_TYPE (exp));
1885 if (bcmp (&size, p, sizeof size))
1890 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1892 if (TREE_VALUE (link))
1894 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
1901 if (bcmp (&zero, p, sizeof zero))
1909 else if (code == ADDR_EXPR)
1911 struct addr_const value;
1912 decode_addr_const (exp, &value);
1913 strp = (char *) &value.offset;
1914 len = sizeof value.offset;
1915 /* Compare the offset. */
1917 if (*p++ != *strp++)
1919 /* Compare symbol name. */
1920 strp = XSTR (value.base, 0);
1921 len = strlen (strp) + 1;
1923 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1925 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1926 if (p == 0) return 0;
1927 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
1930 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1932 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1936 /* Compare constant contents. */
1938 if (*p++ != *strp++)
1944 /* Construct a constant descriptor for the expression EXP.
1945 It is up to the caller to enter the descriptor in the hash table. */
1947 static struct constant_descriptor *
1948 record_constant (exp)
1951 struct constant_descriptor *next = 0;
1954 /* Make a struct constant_descriptor. The first two pointers will
1955 be filled in later. Here we just leave space for them. */
1957 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
1958 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
1959 record_constant_1 (exp);
1960 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
1963 /* Add a description of constant expression EXP
1964 to the object growing in `permanent_obstack'.
1965 No need to return its address; the caller will get that
1966 from the obstack when the object is complete. */
1969 record_constant_1 (exp)
1972 register char *strp;
1974 register enum tree_code code = TREE_CODE (exp);
1976 obstack_1grow (&permanent_obstack, (unsigned int) code);
1978 if (code == INTEGER_CST)
1980 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1981 strp = (char *) &TREE_INT_CST_LOW (exp);
1982 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1984 else if (code == REAL_CST)
1986 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1987 strp = (char *) &TREE_REAL_CST (exp);
1988 len = sizeof TREE_REAL_CST (exp);
1990 else if (code == STRING_CST)
1992 if (flag_writable_strings)
1994 strp = TREE_STRING_POINTER (exp);
1995 len = TREE_STRING_LENGTH (exp);
1996 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
1997 sizeof TREE_STRING_LENGTH (exp));
1999 else if (code == COMPLEX_CST)
2001 record_constant_1 (TREE_REALPART (exp));
2002 record_constant_1 (TREE_IMAGPART (exp));
2005 else if (code == CONSTRUCTOR)
2008 int length = list_length (CONSTRUCTOR_ELTS (exp));
2011 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2013 /* For record constructors, insist that the types match.
2014 For arrays, just verify both constructors are for arrays. */
2015 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2016 type = TREE_TYPE (exp);
2019 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2021 /* For arrays, insist that the size in bytes match. */
2022 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2024 int size = int_size_in_bytes (TREE_TYPE (exp));
2025 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2028 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2030 if (TREE_VALUE (link))
2031 record_constant_1 (TREE_VALUE (link));
2036 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2042 else if (code == ADDR_EXPR)
2044 struct addr_const value;
2045 decode_addr_const (exp, &value);
2046 /* Record the offset. */
2047 obstack_grow (&permanent_obstack,
2048 (char *) &value.offset, sizeof value.offset);
2049 /* Record the symbol name. */
2050 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2051 strlen (XSTR (value.base, 0)) + 1);
2054 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2056 record_constant_1 (TREE_OPERAND (exp, 0));
2057 record_constant_1 (TREE_OPERAND (exp, 1));
2060 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2062 record_constant_1 (TREE_OPERAND (exp, 0));
2066 /* Record constant contents. */
2067 obstack_grow (&permanent_obstack, strp, len);
2070 /* Record a list of constant expressions that were passed to
2071 output_constant_def but that could not be output right away. */
2073 struct deferred_constant
2075 struct deferred_constant *next;
2081 static struct deferred_constant *deferred_constants;
2083 /* Nonzero means defer output of addressed subconstants
2084 (i.e., those for which output_constant_def is called.) */
2085 static int defer_addressed_constants_flag;
2087 /* Start deferring output of subconstants. */
2090 defer_addressed_constants ()
2092 defer_addressed_constants_flag++;
2095 /* Stop deferring output of subconstants,
2096 and output now all those that have been deferred. */
2099 output_deferred_addressed_constants ()
2101 struct deferred_constant *p, *next;
2103 defer_addressed_constants_flag--;
2105 if (defer_addressed_constants_flag > 0)
2108 for (p = deferred_constants; p; p = next)
2110 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2115 deferred_constants = 0;
2118 /* Return an rtx representing a reference to constant data in memory
2119 for the constant expression EXP.
2121 If assembler code for such a constant has already been output,
2122 return an rtx to refer to it.
2123 Otherwise, output such a constant in memory (or defer it for later)
2124 and generate an rtx for it.
2126 The TREE_CST_RTL of EXP is set up to point to that rtx.
2127 The const_hash_table records which constants already have label strings. */
2130 output_constant_def (exp)
2134 register struct constant_descriptor *desc;
2140 if (TREE_CODE (exp) == INTEGER_CST)
2141 abort (); /* No TREE_CST_RTL slot in these. */
2143 if (TREE_CST_RTL (exp))
2144 return TREE_CST_RTL (exp);
2146 /* Make sure any other constants whose addresses appear in EXP
2147 are assigned label numbers. */
2149 reloc = output_addressed_constants (exp);
2151 /* Compute hash code of EXP. Search the descriptors for that hash code
2152 to see if any of them describes EXP. If yes, the descriptor records
2153 the label number already assigned. */
2155 hash = const_hash (exp) % MAX_HASH_TABLE;
2157 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2158 if (compare_constant (exp, desc))
2160 found = desc->label;
2166 /* No constant equal to EXP is known to have been output.
2167 Make a constant descriptor to enter EXP in the hash table.
2168 Assign the label number and record it in the descriptor for
2169 future calls to this function to find. */
2171 /* Create a string containing the label name, in LABEL. */
2172 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2174 desc = record_constant (exp);
2175 desc->next = const_hash_table[hash];
2177 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2178 const_hash_table[hash] = desc;
2181 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2183 push_obstacks_nochange ();
2184 if (TREE_PERMANENT (exp))
2185 end_temporary_allocation ();
2187 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2190 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2191 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2192 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2193 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2194 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2198 /* Optionally set flags or add text to the name to record information
2199 such as that it is a function name. If the name is changed, the macro
2200 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2201 And if it finds a * at the beginning after doing so, it must handle
2203 #ifdef ENCODE_SECTION_INFO
2204 ENCODE_SECTION_INFO (exp);
2207 /* If this is the first time we've seen this particular constant,
2208 output it (or defer its output for later). */
2211 if (defer_addressed_constants_flag)
2213 struct deferred_constant *p;
2214 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2216 /* We really should copy trees in depth here,
2217 but since this case is the only one that should happen now,
2218 let's do it later. */
2219 if (TREE_CODE (exp) != STRING_CST)
2222 push_obstacks_nochange ();
2223 suspend_momentary ();
2224 p->exp = copy_node (exp);
2227 p->labelno = const_labelno++;
2228 p->next = deferred_constants;
2229 deferred_constants = p;
2232 output_constant_def_contents (exp, reloc, const_labelno++);
2235 return TREE_CST_RTL (exp);
2238 /* Now output assembler code to define the label for EXP,
2239 and follow it with the data of EXP. */
2242 output_constant_def_contents (exp, reloc, labelno)
2249 /* First switch to text section, except for writable strings. */
2250 #ifdef SELECT_SECTION
2251 SELECT_SECTION (exp, reloc);
2253 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2254 || (flag_pic && reloc))
2257 readonly_data_section ();
2260 /* Align the location counter as required by EXP's data type. */
2261 align = TYPE_ALIGN (TREE_TYPE (exp));
2262 #ifdef CONSTANT_ALIGNMENT
2263 align = CONSTANT_ALIGNMENT (exp, align);
2266 if (align > BITS_PER_UNIT)
2267 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2269 /* Output the label itself. */
2270 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2272 /* Output the value of EXP. */
2273 output_constant (exp,
2274 (TREE_CODE (exp) == STRING_CST
2275 ? TREE_STRING_LENGTH (exp)
2276 : int_size_in_bytes (TREE_TYPE (exp))));
2280 /* Similar hash facility for making memory-constants
2281 from constant rtl-expressions. It is used on RISC machines
2282 where immediate integer arguments and constant addresses are restricted
2283 so that such constants must be stored in memory.
2285 This pool of constants is reinitialized for each function
2286 so each function gets its own constants-pool that comes right before it.
2288 All structures allocated here are discarded when functions are saved for
2289 inlining, so they do not need to be allocated permanently. */
2291 #define MAX_RTX_HASH_TABLE 61
2292 static struct constant_descriptor **const_rtx_hash_table;
2294 /* Structure to represent sufficient information about a constant so that
2295 it can be output when the constant pool is output, so that function
2296 integration can be done, and to simplify handling on machines that reference
2297 constant pool as base+displacement. */
2299 struct pool_constant
2301 struct constant_descriptor *desc;
2302 struct pool_constant *next;
2303 enum machine_mode mode;
2310 /* Pointers to first and last constant in pool. */
2312 static struct pool_constant *first_pool, *last_pool;
2314 /* Current offset in constant pool (does not include any machine-specific
2317 static int pool_offset;
2319 /* Structure used to maintain hash table mapping symbols used to their
2320 corresponding constants. */
2325 struct pool_constant *pool;
2326 struct pool_sym *next;
2329 static struct pool_sym **const_rtx_sym_hash_table;
2331 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2332 The argument is XSTR (... , 0) */
2334 #define SYMHASH(LABEL) \
2335 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2337 /* Initialize constant pool hashing for next function. */
2340 init_const_rtx_hash_table ()
2342 const_rtx_hash_table
2343 = ((struct constant_descriptor **)
2344 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2345 const_rtx_sym_hash_table
2346 = ((struct pool_sym **)
2347 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2348 bzero (const_rtx_hash_table,
2349 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2350 bzero (const_rtx_sym_hash_table,
2351 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2353 first_pool = last_pool = 0;
2357 /* Save and restore it for a nested function. */
2360 save_varasm_status (p)
2363 p->const_rtx_hash_table = const_rtx_hash_table;
2364 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2365 p->first_pool = first_pool;
2366 p->last_pool = last_pool;
2367 p->pool_offset = pool_offset;
2371 restore_varasm_status (p)
2374 const_rtx_hash_table = p->const_rtx_hash_table;
2375 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2376 first_pool = p->first_pool;
2377 last_pool = p->last_pool;
2378 pool_offset = p->pool_offset;
2381 enum kind { RTX_DOUBLE, RTX_INT };
2385 #ifdef ONLY_INT_FIELDS
2386 unsigned int kind : 16;
2387 unsigned int mode : 16;
2389 enum kind kind : 16;
2390 enum machine_mode mode : 16;
2393 union real_extract du;
2394 struct addr_const addr;
2398 /* Express an rtx for a constant integer (perhaps symbolic)
2399 as the sum of a symbol or label plus an explicit integer.
2400 They are stored into VALUE. */
2403 decode_rtx_const (mode, x, value)
2404 enum machine_mode mode;
2406 struct rtx_const *value;
2408 /* Clear the whole structure, including any gaps. */
2411 int *p = (int *) value;
2412 int *end = (int *) (value + 1);
2417 value->kind = RTX_INT; /* Most usual kind. */
2420 switch (GET_CODE (x))
2423 value->kind = RTX_DOUBLE;
2424 value->mode = GET_MODE (x);
2425 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2429 value->un.addr.offset = INTVAL (x);
2435 value->un.addr.base = x;
2440 if (GET_CODE (x) == PLUS)
2442 value->un.addr.base = XEXP (x, 0);
2443 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2445 value->un.addr.offset = INTVAL (XEXP (x, 1));
2447 else if (GET_CODE (x) == MINUS)
2449 value->un.addr.base = XEXP (x, 0);
2450 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2452 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2462 if (value->kind == RTX_INT && value->un.addr.base != 0)
2463 switch (GET_CODE (value->un.addr.base))
2467 /* Use the string's address, not the SYMBOL_REF's address,
2468 for the sake of addresses of library routines.
2469 For a LABEL_REF, compare labels. */
2470 value->un.addr.base = XEXP (value->un.addr.base, 0);
2474 /* Given a MINUS expression, simplify it if both sides
2475 include the same symbol. */
2478 simplify_subtraction (x)
2481 struct rtx_const val0, val1;
2483 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2484 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2486 if (val0.un.addr.base == val1.un.addr.base)
2487 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2491 /* Compute a hash code for a constant RTL expression. */
2494 const_hash_rtx (mode, x)
2495 enum machine_mode mode;
2500 struct rtx_const value;
2501 decode_rtx_const (mode, x, &value);
2503 /* Compute hashing function */
2505 for (i = 0; i < sizeof value / sizeof (int); i++)
2506 hi += ((int *) &value)[i];
2508 hi &= (1 << HASHBITS) - 1;
2509 hi %= MAX_RTX_HASH_TABLE;
2513 /* Compare a constant rtl object X with a constant-descriptor DESC.
2514 Return 1 if DESC describes a constant with the same value as X. */
2517 compare_constant_rtx (mode, x, desc)
2518 enum machine_mode mode;
2520 struct constant_descriptor *desc;
2522 register int *p = (int *) desc->contents;
2525 struct rtx_const value;
2527 decode_rtx_const (mode, x, &value);
2528 strp = (int *) &value;
2529 len = sizeof value / sizeof (int);
2531 /* Compare constant contents. */
2533 if (*p++ != *strp++)
2539 /* Construct a constant descriptor for the rtl-expression X.
2540 It is up to the caller to enter the descriptor in the hash table. */
2542 static struct constant_descriptor *
2543 record_constant_rtx (mode, x)
2544 enum machine_mode mode;
2547 struct constant_descriptor *ptr;
2549 struct rtx_const value;
2551 decode_rtx_const (mode, x, &value);
2553 obstack_grow (current_obstack, &ptr, sizeof ptr);
2554 obstack_grow (current_obstack, &label, sizeof label);
2556 /* Record constant contents. */
2557 obstack_grow (current_obstack, &value, sizeof value);
2559 return (struct constant_descriptor *) obstack_finish (current_obstack);
2562 /* Given a constant rtx X, make (or find) a memory constant for its value
2563 and return a MEM rtx to refer to it in memory. */
2566 force_const_mem (mode, x)
2567 enum machine_mode mode;
2571 register struct constant_descriptor *desc;
2576 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2577 (this will always be true for floating CONST_DOUBLEs that have been
2578 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2579 use the previous copy. Otherwise, make a new one. Note that in
2580 the unlikely event that this same CONST_DOUBLE is used in two different
2581 modes in an alternating fashion, we will allocate a lot of different
2582 memory locations, but this should be extremely rare. */
2584 /* Don't use CONST_DOUBLE_MEM in a nested function.
2585 Nested functions have their own constant pools,
2586 so they can't share the same values in CONST_DOUBLE_MEM
2587 with the containing function. */
2588 if (outer_function_chain == 0)
2589 if (GET_CODE (x) == CONST_DOUBLE
2590 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2591 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2592 return CONST_DOUBLE_MEM (x);
2594 /* Compute hash code of X. Search the descriptors for that hash code
2595 to see if any of them describes X. If yes, the descriptor records
2596 the label number already assigned. */
2598 hash = const_hash_rtx (mode, x);
2600 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2601 if (compare_constant_rtx (mode, x, desc))
2603 found = desc->label;
2609 register struct pool_constant *pool;
2610 register struct pool_sym *sym;
2613 /* No constant equal to X is known to have been output.
2614 Make a constant descriptor to enter X in the hash table.
2615 Assign the label number and record it in the descriptor for
2616 future calls to this function to find. */
2618 desc = record_constant_rtx (mode, x);
2619 desc->next = const_rtx_hash_table[hash];
2620 const_rtx_hash_table[hash] = desc;
2622 /* Align the location counter as required by EXP's data type. */
2623 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2624 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2625 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2627 pool_offset += align - 1;
2628 pool_offset &= ~ (align - 1);
2630 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2632 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2636 pool->labelno = const_labelno;
2637 pool->align = align;
2638 pool->offset = pool_offset;
2644 last_pool->next = pool;
2647 pool_offset += GET_MODE_SIZE (mode);
2649 /* Create a string containing the label name, in LABEL. */
2650 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2655 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2657 /* Add label to symbol hash table. */
2658 hash = SYMHASH (found);
2659 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2662 sym->next = const_rtx_sym_hash_table[hash];
2663 const_rtx_sym_hash_table[hash] = sym;
2666 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2668 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2670 RTX_UNCHANGING_P (def) = 1;
2671 /* Mark the symbol_ref as belonging to this constants pool. */
2672 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2673 current_function_uses_const_pool = 1;
2675 if (outer_function_chain == 0)
2676 if (GET_CODE (x) == CONST_DOUBLE)
2678 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2680 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2681 const_double_chain = x;
2683 CONST_DOUBLE_MEM (x) = def;
2689 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2690 the corresponding pool_constant structure. */
2692 static struct pool_constant *
2693 find_pool_constant (addr)
2696 struct pool_sym *sym;
2697 char *label = XSTR (addr, 0);
2699 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2700 if (sym->label == label)
2706 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2709 get_pool_constant (addr)
2712 return (find_pool_constant (addr))->constant;
2715 /* Similar, return the mode. */
2718 get_pool_mode (addr)
2721 return (find_pool_constant (addr))->mode;
2724 /* Similar, return the offset in the constant pool. */
2727 get_pool_offset (addr)
2730 return (find_pool_constant (addr))->offset;
2733 /* Return the size of the constant pool. */
2741 /* Write all the constants in the constant pool. */
2744 output_constant_pool (fnname, fndecl)
2748 struct pool_constant *pool;
2750 union real_extract u;
2752 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2753 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
2756 for (pool = first_pool; pool; pool = pool->next)
2760 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2761 whose CODE_LABEL has been deleted. This can occur if a jump table
2762 is eliminated by optimization. If so, write a constant of zero
2763 instead. Note that this can also happen by turning the
2764 CODE_LABEL into a NOTE. */
2765 if (((GET_CODE (x) == LABEL_REF
2766 && (INSN_DELETED_P (XEXP (x, 0))
2767 || GET_CODE (XEXP (x, 0)) == NOTE)))
2768 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2769 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
2770 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
2771 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
2774 /* First switch to correct section. */
2775 #ifdef SELECT_RTX_SECTION
2776 SELECT_RTX_SECTION (pool->mode, x);
2778 readonly_data_section ();
2781 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2782 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
2783 pool->align, pool->labelno, done);
2786 if (pool->align > 1)
2787 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
2789 /* Output the label. */
2790 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
2792 /* Output the value of the constant itself. */
2793 switch (GET_MODE_CLASS (pool->mode))
2796 if (GET_CODE (x) != CONST_DOUBLE)
2799 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
2800 assemble_real (u.d, pool->mode);
2804 case MODE_PARTIAL_INT:
2805 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
2815 /* Done with this pool. */
2816 first_pool = last_pool = 0;
2819 /* Find all the constants whose addresses are referenced inside of EXP,
2820 and make sure assembler code with a label has been output for each one.
2821 Indicate whether an ADDR_EXPR has been encountered. */
2824 output_addressed_constants (exp)
2829 switch (TREE_CODE (exp))
2833 register tree constant = TREE_OPERAND (exp, 0);
2835 while (TREE_CODE (constant) == COMPONENT_REF)
2837 constant = TREE_OPERAND (constant, 0);
2840 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
2841 || TREE_CODE (constant) == CONSTRUCTOR)
2842 /* No need to do anything here
2843 for addresses of variables or functions. */
2844 output_constant_def (constant);
2851 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2852 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
2857 case NON_LVALUE_EXPR:
2858 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2864 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2865 if (TREE_VALUE (link) != 0)
2866 reloc |= output_addressed_constants (TREE_VALUE (link));
2876 /* Output assembler code for constant EXP to FILE, with no label.
2877 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2878 Assumes output_addressed_constants has been done on EXP already.
2880 Generate exactly SIZE bytes of assembler data, padding at the end
2881 with zeros if necessary. SIZE must always be specified.
2883 SIZE is important for structure constructors,
2884 since trailing members may have been omitted from the constructor.
2885 It is also important for initialization of arrays from string constants
2886 since the full length of the string constant might not be wanted.
2887 It is also needed for initialization of unions, where the initializer's
2888 type is just one member, and that may not be as long as the union.
2890 There a case in which we would fail to output exactly SIZE bytes:
2891 for a structure constructor that wants to produce more than SIZE bytes.
2892 But such constructors will never be generated for any possible input. */
2895 output_constant (exp, size)
2899 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
2905 /* Allow a constructor with no elements for any data type.
2906 This means to fill the space with zeros. */
2907 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
2909 assemble_zeros (size);
2913 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2914 That way we get the constant (we hope) inside it. */
2915 if (TREE_CODE (exp) == NOP_EXPR
2916 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
2917 exp = TREE_OPERAND (exp, 0);
2926 case REFERENCE_TYPE:
2927 /* ??? What about (int)((float)(int)&foo + 4) */
2928 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
2929 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2930 exp = TREE_OPERAND (exp, 0);
2932 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
2933 EXPAND_INITIALIZER),
2935 error ("initializer for integer value is too complicated");
2940 if (TREE_CODE (exp) != REAL_CST)
2941 error ("initializer for floating value is not a floating constant");
2943 assemble_real (TREE_REAL_CST (exp),
2944 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
2949 output_constant (TREE_REALPART (exp), size / 2);
2950 output_constant (TREE_IMAGPART (exp), size / 2);
2951 size -= (size / 2) * 2;
2955 if (TREE_CODE (exp) == CONSTRUCTOR)
2957 output_constructor (exp, size);
2960 else if (TREE_CODE (exp) == STRING_CST)
2964 if (size > TREE_STRING_LENGTH (exp))
2966 excess = size - TREE_STRING_LENGTH (exp);
2967 size = TREE_STRING_LENGTH (exp);
2970 assemble_string (TREE_STRING_POINTER (exp), size);
2979 if (TREE_CODE (exp) == CONSTRUCTOR)
2980 output_constructor (exp, size);
2987 assemble_zeros (size);
2990 /* Subroutine of output_constant, used for CONSTRUCTORs
2991 (aggregate constants).
2992 Generate at least SIZE bytes, padding if necessary. */
2995 output_constructor (exp, size)
2999 register tree link, field = 0;
3000 /* Number of bytes output or skipped so far.
3001 In other words, current position within the constructor. */
3002 int total_bytes = 0;
3003 /* Non-zero means BYTE contains part of a byte, to be output. */
3004 int byte_buffer_in_use = 0;
3007 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3010 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3011 field = TYPE_FIELDS (TREE_TYPE (exp));
3013 /* As LINK goes through the elements of the constant,
3014 FIELD goes through the structure fields, if the constant is a structure.
3015 if the constant is a union, then we override this,
3016 by getting the field from the TREE_LIST element.
3017 But the constant could also be an array. Then FIELD is zero. */
3018 for (link = CONSTRUCTOR_ELTS (exp);
3020 link = TREE_CHAIN (link),
3021 field = field ? TREE_CHAIN (field) : 0)
3023 tree val = TREE_VALUE (link);
3024 /* the element in a union constructor specifies the proper field. */
3025 if (TREE_PURPOSE (link) != 0)
3026 field = TREE_PURPOSE (link);
3028 /* Eliminate the marker that makes a cast not be an lvalue. */
3032 if (field == 0 || !DECL_BIT_FIELD (field))
3034 register int fieldsize;
3035 /* Since this structure is static,
3036 we know the positions are constant. */
3037 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3041 /* An element that is not a bit-field.
3042 Output any buffered-up bit-fields preceding it. */
3043 if (byte_buffer_in_use)
3045 ASM_OUTPUT_BYTE (asm_out_file, byte);
3047 byte_buffer_in_use = 0;
3050 /* Advance to offset of this element.
3051 Note no alignment needed in an array, since that is guaranteed
3052 if each element has the proper size. */
3053 if (field != 0 && bitpos != total_bytes)
3055 assemble_zeros (bitpos - total_bytes);
3056 total_bytes = bitpos;
3059 /* Determine size this element should occupy. */
3062 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3064 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3066 /* This avoids overflow trouble. */
3067 tree size_tree = size_binop (CEIL_DIV_EXPR,
3069 size_int (BITS_PER_UNIT));
3070 fieldsize = TREE_INT_CST_LOW (size_tree);
3074 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3075 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3079 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3081 /* Output the element's initial value. */
3083 assemble_zeros (fieldsize);
3085 output_constant (val, fieldsize);
3087 /* Count its size. */
3088 total_bytes += fieldsize;
3090 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3091 error ("invalid initial value for member `%s'",
3092 IDENTIFIER_POINTER (DECL_NAME (field)));
3095 /* Element that is a bit-field. */
3097 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3099 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3102 val = integer_zero_node;
3104 /* If this field does not start in this (or, next) byte,
3106 if (next_offset / BITS_PER_UNIT != total_bytes)
3108 /* Output remnant of any bit field in previous bytes. */
3109 if (byte_buffer_in_use)
3111 ASM_OUTPUT_BYTE (asm_out_file, byte);
3113 byte_buffer_in_use = 0;
3116 /* If still not at proper byte, advance to there. */
3117 if (next_offset / BITS_PER_UNIT != total_bytes)
3119 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3120 total_bytes = next_offset / BITS_PER_UNIT;
3124 if (! byte_buffer_in_use)
3127 /* We must split the element into pieces that fall within
3128 separate bytes, and combine each byte with previous or
3129 following bit-fields. */
3131 /* next_offset is the offset n fbits from the beginning of
3132 the structure to the next bit of this element to be processed.
3133 end_offset is the offset of the first bit past the end of
3135 while (next_offset < end_offset)
3139 int next_byte = next_offset / BITS_PER_UNIT;
3140 int next_bit = next_offset % BITS_PER_UNIT;
3142 /* Advance from byte to byte
3143 within this element when necessary. */
3144 while (next_byte != total_bytes)
3146 ASM_OUTPUT_BYTE (asm_out_file, byte);
3151 /* Number of bits we can process at once
3152 (all part of the same byte). */
3153 this_time = MIN (end_offset - next_offset,
3154 BITS_PER_UNIT - next_bit);
3155 #if BYTES_BIG_ENDIAN
3156 /* On big-endian machine, take the most significant bits
3157 first (of the bits that are significant)
3158 and put them into bytes from the most significant end. */
3159 shift = end_offset - next_offset - this_time;
3160 /* Don't try to take a bunch of bits that cross
3161 the word boundary in the INTEGER_CST. */
3162 if (shift < HOST_BITS_PER_WIDE_INT
3163 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3165 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3166 shift = HOST_BITS_PER_WIDE_INT;
3169 /* Now get the bits from the appropriate constant word. */
3170 if (shift < HOST_BITS_PER_WIDE_INT)
3172 value = TREE_INT_CST_LOW (val);
3174 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3176 value = TREE_INT_CST_HIGH (val);
3177 shift -= HOST_BITS_PER_WIDE_INT;
3181 byte |= (((value >> shift)
3182 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3183 << (BITS_PER_UNIT - this_time - next_bit));
3185 /* On little-endian machines,
3186 take first the least significant bits of the value
3187 and pack them starting at the least significant
3188 bits of the bytes. */
3189 shift = (next_offset
3190 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3191 /* Don't try to take a bunch of bits that cross
3192 the word boundary in the INTEGER_CST. */
3193 if (shift < HOST_BITS_PER_WIDE_INT
3194 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3196 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3197 shift = HOST_BITS_PER_WIDE_INT;
3200 /* Now get the bits from the appropriate constant word. */
3201 if (shift < HOST_BITS_PER_INT)
3202 value = TREE_INT_CST_LOW (val);
3203 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3205 value = TREE_INT_CST_HIGH (val);
3206 shift -= HOST_BITS_PER_WIDE_INT;
3210 byte |= ((value >> shift)
3211 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3213 next_offset += this_time;
3214 byte_buffer_in_use = 1;
3218 if (byte_buffer_in_use)
3220 ASM_OUTPUT_BYTE (asm_out_file, byte);
3223 if (total_bytes < size)
3224 assemble_zeros (size - total_bytes);