1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992 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
49 #define ASM_STABS_OP ".stabs"
52 /* This macro gets just the user-specified name
53 out of the string in a SYMBOL_REF. On most machines,
54 we discard the * if any and that's all. */
55 #ifndef STRIP_NAME_ENCODING
56 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
57 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
60 /* File in which assembler code is being written. */
62 extern FILE *asm_out_file;
64 /* The (assembler) name of the first globally-visible object output. */
65 char *first_global_object_name;
67 extern struct obstack *current_obstack;
68 extern struct obstack *saveable_obstack;
69 extern struct obstack permanent_obstack;
70 #define obstack_chunk_alloc xmalloc
72 /* Number for making the label on the next
73 constant that is stored in memory. */
77 /* Number for making the label on the next
78 static variable internal to a function. */
82 /* Nonzero if at least one function definition has been seen. */
83 static int function_defined;
85 extern FILE *asm_out_file;
87 static char *compare_constant_1 ();
88 static void record_constant_1 ();
89 void output_constant_pool ();
90 void assemble_name ();
91 int output_addressed_constants ();
92 void output_constant ();
93 void output_constructor ();
95 void readonly_data_section ();
99 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
102 static enum in_section {no_section, in_text, in_data} in_section
106 /* Define functions like text_section for any extra sections. */
107 #ifdef EXTRA_SECTION_FUNCTIONS
108 EXTRA_SECTION_FUNCTIONS
111 /* Tell assembler to switch to text section. */
116 if (in_section != in_text)
118 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
119 in_section = in_text;
123 /* Tell assembler to switch to data section. */
128 if (in_section != in_data)
130 if (flag_shared_data)
132 #ifdef SHARED_SECTION_ASM_OP
133 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
135 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
139 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
141 in_section = in_data;
145 /* Tell assembler to switch to read-only data section. This is normally
149 readonly_data_section ()
151 #ifdef READONLY_DATA_SECTION
152 READONLY_DATA_SECTION (); /* Note this can call data_section. */
158 /* Determine if we're in the text section. */
163 return in_section == in_text;
166 /* Create the rtl to represent a function, for a function definition.
167 DECL is a FUNCTION_DECL node which describes which function.
168 The rtl is stored into DECL. */
171 make_function_rtl (decl)
174 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
176 /* Rename a nested function to avoid conflicts. */
177 if (decl_function_context (decl) != 0
178 && DECL_INITIAL (decl) != 0
179 && DECL_RTL (decl) == 0)
183 name = IDENTIFIER_POINTER (DECL_NAME (decl));
184 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
185 name = obstack_copy0 (saveable_obstack, label, strlen (label));
189 if (DECL_RTL (decl) == 0)
192 = gen_rtx (MEM, DECL_MODE (decl),
193 gen_rtx (SYMBOL_REF, Pmode, name));
195 /* Optionally set flags or add text to the name to record information
196 such as that it is a function name. If the name is changed, the macro
197 ASM_OUTPUT_LABELREF will have to know how to strip this information.
198 And if it finds a * at the beginning after doing so, it must handle
200 #ifdef ENCODE_SECTION_INFO
201 ENCODE_SECTION_INFO (decl);
205 /* Record at least one function has been defined. */
206 function_defined = 1;
209 /* Given NAME, a putative register name, discard any customary prefixes. */
212 strip_reg_name (name)
215 #ifdef REGISTER_PREFIX
216 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
217 name += strlen (REGISTER_PREFIX);
219 if (name[0] == '%' || name[0] == '#')
224 /* Decode an `asm' spec for a declaration as a register name.
225 Return the register number, or -1 if nothing specified,
226 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
227 or -3 if ASMSPEC is `cc' and is not recognized,
228 or -4 if ASMSPEC is `memory' and is not recognized.
229 Accept an exact spelling or a decimal number.
230 Prefixes such as % are optional. */
233 decode_reg_name (asmspec)
240 /* Get rid of confusing prefixes. */
241 asmspec = strip_reg_name (asmspec);
243 /* Allow a decimal number as a "register name". */
244 for (i = strlen (asmspec) - 1; i >= 0; i--)
245 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
247 if (asmspec[0] != 0 && i < 0)
250 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
256 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
258 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
261 #ifdef ADDITIONAL_REGISTER_NAMES
263 static struct { char *name; int number; } table[]
264 = ADDITIONAL_REGISTER_NAMES;
266 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
267 if (! strcmp (asmspec, table[i].name))
268 return table[i].number;
270 #endif /* ADDITIONAL_REGISTER_NAMES */
272 if (!strcmp (asmspec, "memory"))
275 if (!strcmp (asmspec, "cc"))
284 /* Create the DECL_RTL for a declaration for a static or external variable
285 or static or external function.
286 ASMSPEC, if not 0, is the string which the user specified
287 as the assembler symbol name.
288 TOP_LEVEL is nonzero if this is a file-scope variable.
290 This is never called for PARM_DECL nodes. */
293 make_decl_rtl (decl, asmspec, top_level)
299 int reg_number = decode_reg_name (asmspec);
301 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
302 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
304 if (reg_number == -2)
306 /* ASMSPEC is given, and not the name of a register. */
307 name = (char *) obstack_alloc (saveable_obstack,
308 strlen (asmspec) + 2);
310 strcpy (&name[1], asmspec);
313 /* For a duplicate declaration, we can be called twice on the
314 same DECL node. Don't alter the RTL already made
315 unless the old mode is wrong (which can happen when
316 the previous rtl was made when the type was incomplete). */
317 if (DECL_RTL (decl) == 0
318 || GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
322 /* First detect errors in declaring global registers. */
323 if (DECL_REGISTER (decl) && reg_number == -1)
324 error_with_decl (decl,
325 "register name not specified for `%s'");
326 else if (DECL_REGISTER (decl) && reg_number < 0)
327 error_with_decl (decl,
328 "invalid register name for `%s'");
329 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
330 error_with_decl (decl,
331 "register name given for non-register variable `%s'");
332 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
333 error ("function declared `register'");
334 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
335 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
336 /* Now handle properly declared static register variables. */
337 else if (DECL_REGISTER (decl))
340 #if 0 /* yylex should print the warning for this */
342 pedwarn ("ANSI C forbids global register variables");
344 if (DECL_INITIAL (decl) != 0 && top_level)
346 DECL_INITIAL (decl) = 0;
347 error ("global register variable has initial value");
349 if (fixed_regs[reg_number] == 0
350 && function_defined && top_level)
351 error ("global register variable follows a function definition");
352 if (TREE_THIS_VOLATILE (decl))
353 warning ("volatile register variables don't work as you might wish");
354 DECL_RTL (decl) = gen_rtx (REG, DECL_MODE (decl), reg_number);
355 REG_USERVAR_P (DECL_RTL (decl)) = 1;
359 /* Make this register fixed, so not usable for anything else. */
360 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
362 global_regs[reg_number + --nregs] = 1;
367 /* Now handle ordinary static variables and functions (in memory).
368 Also handle vars declared register invalidly. */
369 if (DECL_RTL (decl) == 0)
371 /* Can't use just the variable's own name for a variable
372 whose scope is less than the whole file.
373 Concatenate a distinguishing number. */
374 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
378 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
379 name = obstack_copy0 (saveable_obstack, label, strlen (label));
383 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
384 gen_rtx (SYMBOL_REF, Pmode, name));
385 if (TREE_THIS_VOLATILE (decl))
386 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
387 if (TREE_READONLY (decl))
388 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
389 MEM_IN_STRUCT_P (DECL_RTL (decl))
390 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
391 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
392 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
394 /* Optionally set flags or add text to the name to record information
395 such as that it is a function name.
396 If the name is changed, the macro ASM_OUTPUT_LABELREF
397 will have to know how to strip this information.
398 And if it finds a * at the beginning after doing so,
399 it must handle that too. */
400 #ifdef ENCODE_SECTION_INFO
401 ENCODE_SECTION_INFO (decl);
407 /* Make the rtl for variable VAR be volatile.
408 Use this only for static variables. */
410 make_var_volatile (var)
413 if (GET_CODE (DECL_RTL (var)) != MEM)
416 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
419 /* Output a string of literal assembler code
420 for an `asm' keyword used between functions. */
423 assemble_asm (string)
428 if (TREE_CODE (string) == ADDR_EXPR)
429 string = TREE_OPERAND (string, 0);
431 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
434 #if 0 /* This should no longer be needed, because
435 flag_gnu_linker should be 0 on these systems,
436 which should prevent any output
437 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
438 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
439 #ifndef ASM_OUTPUT_CONSTRUCTOR
440 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
442 #ifndef ASM_OUTPUT_DESTRUCTOR
443 #define ASM_OUTPUT_DESTRUCTOR(file, name)
448 /* Record an element in the table of global destructors.
449 How this is done depends on what sort of assembler and linker
452 NAME should be the name of a global function to be called
453 at exit time. This name is output using assemble_name. */
456 assemble_destructor (name)
459 #ifdef ASM_OUTPUT_DESTRUCTOR
460 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
464 /* Now tell GNU LD that this is part of the static destructor set. */
465 /* This code works for any machine provided you use GNU as/ld. */
466 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
467 assemble_name (asm_out_file, name);
468 fputc ('\n', asm_out_file);
473 /* Likewise for global constructors. */
476 assemble_constructor (name)
479 #ifdef ASM_OUTPUT_CONSTRUCTOR
480 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
484 /* Now tell GNU LD that this is part of the static constructor set. */
485 /* This code works for any machine provided you use GNU as/ld. */
486 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
487 assemble_name (asm_out_file, name);
488 fputc ('\n', asm_out_file);
493 /* Likewise for entries we want to record for garbage collection.
494 Garbage collection is still under development. */
497 assemble_gc_entry (name)
500 #ifdef ASM_OUTPUT_GC_ENTRY
501 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
505 /* Now tell GNU LD that this is part of the static constructor set. */
506 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
507 assemble_name (asm_out_file, name);
508 fputc ('\n', asm_out_file);
513 /* Output assembler code for the constant pool of a function and associated
514 with defining the name of the function. DECL describes the function.
515 NAME is the function's name. For the constant pool, we use the current
516 constant pool data. */
519 assemble_start_function (decl, fnname)
525 /* The following code does not need preprocessing in the assembler. */
529 output_constant_pool (fnname, decl);
534 /* Tell assembler to move to target machine's alignment for functions. */
535 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
537 ASM_OUTPUT_ALIGN (asm_out_file, align);
539 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
540 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
543 #ifdef SDB_DEBUGGING_INFO
544 /* Output SDB definition of the function. */
545 if (write_symbols == SDB_DEBUG)
546 sdbout_mark_begin_function ();
549 #ifdef DBX_DEBUGGING_INFO
550 /* Output DBX definition of the function. */
551 if (write_symbols == DBX_DEBUG)
552 dbxout_begin_function (decl);
555 /* Make function name accessible from other files, if appropriate. */
557 if (TREE_PUBLIC (decl))
559 if (!first_global_object_name)
560 STRIP_NAME_ENCODING (first_global_object_name, fnname);
561 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
564 /* Do any machine/system dependent processing of the function name */
565 #ifdef ASM_DECLARE_FUNCTION_NAME
566 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
568 /* Standard thing is just output label for the function. */
569 ASM_OUTPUT_LABEL (asm_out_file, fnname);
570 #endif /* ASM_DECLARE_FUNCTION_NAME */
573 /* Output assembler code associated with defining the size of the
574 function. DECL describes the function. NAME is the function's name. */
577 assemble_end_function (decl, fnname)
581 #ifdef ASM_DECLARE_FUNCTION_SIZE
582 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
586 /* Assemble code to leave SIZE bytes of zeros. */
589 assemble_zeros (size)
592 #ifdef ASM_NO_SKIP_IN_TEXT
593 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
594 so we must output 0s explicitly in the text section. */
595 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
599 for (i = 0; i < size - 20; i += 20)
602 fprintf (asm_out_file,
603 "%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);
605 fprintf (asm_out_file,
606 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
612 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
614 fprintf (asm_out_file, "\tbyte 0");
617 for (; i < size; i++)
618 fprintf (asm_out_file, ",0");
619 fprintf (asm_out_file, "\n");
624 ASM_OUTPUT_SKIP (asm_out_file, size);
627 /* Assemble a string constant with the specified C string as contents. */
630 assemble_string (p, size)
638 /* If the string is very long, split it up. */
642 int thissize = size - pos;
643 if (thissize > maximum)
646 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
653 /* Assemble everything that is needed for a variable or function declaration.
654 Not used for automatic variables, and not used for function definitions.
655 Should not be called for variables of incomplete structure type.
657 TOP_LEVEL is nonzero if this variable has file scope.
658 AT_END is nonzero if this is the special handling, at end of compilation,
659 to define things that have had only tentative definitions. */
662 assemble_variable (decl, top_level, at_end)
672 if (GET_CODE (DECL_RTL (decl)) == REG)
674 /* Do output symbol info for global register variables, but do nothing
677 if (TREE_ASM_WRITTEN (decl))
679 TREE_ASM_WRITTEN (decl) = 1;
681 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
682 /* File-scope global variables are output here. */
683 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
685 dbxout_symbol (decl, 0);
687 #ifdef SDB_DEBUGGING_INFO
688 if (write_symbols == SDB_DEBUG && top_level
689 /* Leave initialized global vars for end of compilation;
690 see comment in compile_file. */
691 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
692 sdbout_symbol (decl, 0);
695 /* Don't output any DWARF debugging information for variables here.
696 In the case of local variables, the information for them is output
697 when we do our recursive traversal of the tree representation for
698 the entire containing function. In the case of file-scope variables,
699 we output information for all of them at the very end of compilation
700 while we are doing our final traversal of the chain of file-scope
706 /* Normally no need to say anything for external references,
707 since assembler considers all undefined symbols external. */
709 if (DECL_EXTERNAL (decl))
712 /* Output no assembler code for a function declaration.
713 Only definitions of functions output anything. */
715 if (TREE_CODE (decl) == FUNCTION_DECL)
718 /* If type was incomplete when the variable was declared,
719 see if it is complete now. */
721 if (DECL_SIZE (decl) == 0)
722 layout_decl (decl, 0);
724 /* Still incomplete => don't allocate it; treat the tentative defn
725 (which is what it must have been) as an `extern' reference. */
727 if (DECL_SIZE (decl) == 0)
729 error_with_file_and_line (DECL_SOURCE_FILE (decl),
730 DECL_SOURCE_LINE (decl),
731 "storage size of `%s' isn't known",
732 IDENTIFIER_POINTER (DECL_NAME (decl)));
736 /* The first declaration of a variable that comes through this function
737 decides whether it is global (in C, has external linkage)
738 or local (in C, has internal linkage). So do nothing more
739 if this function has already run. */
741 if (TREE_ASM_WRITTEN (decl))
744 TREE_ASM_WRITTEN (decl) = 1;
746 #ifdef DBX_DEBUGGING_INFO
747 /* File-scope global variables are output here. */
748 if (write_symbols == DBX_DEBUG && top_level)
749 dbxout_symbol (decl, 0);
751 #ifdef SDB_DEBUGGING_INFO
752 if (write_symbols == SDB_DEBUG && top_level
753 /* Leave initialized global vars for end of compilation;
754 see comment in compile_file. */
755 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
756 sdbout_symbol (decl, 0);
759 /* Don't output any DWARF debugging information for variables here.
760 In the case of local variables, the information for them is output
761 when we do our recursive traversal of the tree representation for
762 the entire containing function. In the case of file-scope variables,
763 we output information for all of them at the very end of compilation
764 while we are doing our final traversal of the chain of file-scope
767 /* If storage size is erroneously variable, just continue.
768 Error message was already made. */
770 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
775 /* This is better than explicit arithmetic, since it avoids overflow. */
776 size_tree = size_binop (CEIL_DIV_EXPR,
777 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
779 if (TREE_INT_CST_HIGH (size_tree) != 0)
781 error_with_decl (decl, "size of variable `%s' is too large");
785 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
787 /* Handle uninitialized definitions. */
789 /* ANSI specifies that a tentative definition which is not merged with
790 a non-tentative definition behaves exactly like a definition with an
791 initializer equal to zero. (Section 3.7.2)
792 -fno-common gives strict ANSI behavior. Usually you don't want it. */
794 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
796 int size = TREE_INT_CST_LOW (size_tree);
799 if (TREE_INT_CST_HIGH (size_tree) != 0)
800 error_with_decl (decl, "size of variable `%s' is too large");
801 /* Don't allocate zero bytes of common,
802 since that means "undefined external" in the linker. */
803 if (size == 0) rounded = 1;
804 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
805 so that each uninitialized object starts on such a boundary. */
806 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
807 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
808 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
810 if (flag_shared_data)
813 if (TREE_PUBLIC (decl))
815 #ifdef ASM_OUTPUT_SHARED_COMMON
816 if (flag_shared_data)
817 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
820 #ifdef ASM_OUTPUT_ALIGNED_COMMON
821 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
824 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
829 #ifdef ASM_OUTPUT_SHARED_LOCAL
830 if (flag_shared_data)
831 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
834 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
835 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
838 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
844 /* Handle initialized definitions. */
846 /* First make the assembler name(s) global if appropriate. */
847 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
849 if (!first_global_object_name)
850 STRIP_NAME_ENCODING(first_global_object_name, name);
851 ASM_GLOBALIZE_LABEL (asm_out_file, name);
854 for (d = equivalents; d; d = TREE_CHAIN (d))
856 tree e = TREE_VALUE (d);
857 if (TREE_PUBLIC (e) && DECL_NAME (e))
858 ASM_GLOBALIZE_LABEL (asm_out_file,
859 XSTR (XEXP (DECL_RTL (e), 0), 0));
863 /* Output any data that we will need to use the address of. */
864 if (DECL_INITIAL (decl))
865 reloc = output_addressed_constants (DECL_INITIAL (decl));
867 /* Switch to the proper section for this data. */
868 #ifdef SELECT_SECTION
869 SELECT_SECTION (decl, reloc);
871 if (TREE_READONLY (decl)
872 && ! TREE_THIS_VOLATILE (decl)
873 && ! (flag_pic && reloc))
874 readonly_data_section ();
879 /* Compute and output the alignment of this data. */
881 align = DECL_ALIGN (decl);
882 /* Some object file formats have a maximum alignment which they support.
883 In particular, a.out format supports a maximum alignment of 4. */
884 #ifndef MAX_OFILE_ALIGNMENT
885 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
887 if (align > MAX_OFILE_ALIGNMENT)
889 warning_with_decl (decl,
890 "alignment of `%s' is greater than maximum object file alignment");
891 align = MAX_OFILE_ALIGNMENT;
893 #ifdef DATA_ALIGNMENT
894 /* On some machines, it is good to increase alignment sometimes. */
895 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
897 #ifdef CONSTANT_ALIGNMENT
898 if (DECL_INITIAL (decl))
899 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
902 /* Reset the alignment in case we have made it tighter, so we can benefit
903 from it in get_pointer_alignment. */
904 DECL_ALIGN (decl) = align;
906 if (align > BITS_PER_UNIT)
907 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
909 /* Do any machine/system dependent processing of the object. */
910 #ifdef ASM_DECLARE_OBJECT_NAME
911 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
913 /* Standard thing is just output label for the object. */
914 ASM_OUTPUT_LABEL (asm_out_file, name);
915 #endif /* ASM_DECLARE_OBJECT_NAME */
918 for (d = equivalents; d; d = TREE_CHAIN (d))
920 tree e = TREE_VALUE (d);
921 ASM_OUTPUT_LABEL (asm_out_file, XSTR (XEXP (DECL_RTL (e), 0), 0));
925 if (DECL_INITIAL (decl))
926 /* Output the actual data. */
927 output_constant (DECL_INITIAL (decl),
928 int_size_in_bytes (TREE_TYPE (decl)));
930 /* Leave space for it. */
931 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
934 #ifdef XCOFF_DEBUGGING_INFO
935 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
936 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
937 and `aa' hasn't been output yet, the assembler generates a stab entry with
938 a value of zero, in addition to creating an unnecessary external entry
939 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
941 /* File-scope global variables are output here. */
942 if (write_symbols == XCOFF_DEBUG && top_level)
943 dbxout_symbol (decl, 0);
945 /* There must be a statement after a label. */
950 /* Output something to declare an external symbol to the assembler.
951 (Most assemblers don't need this, so we normally output nothing.)
952 Do nothing if DECL is not external. */
955 assemble_external (decl)
958 #ifdef ASM_OUTPUT_EXTERNAL
959 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
960 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
962 rtx rtl = DECL_RTL (decl);
964 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
965 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
967 /* Some systems do require some output. */
968 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
969 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
975 /* Similar, for calling a library function FUN. */
978 assemble_external_libcall (fun)
981 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
982 /* Declare library function name external when first used, if nec. */
983 if (! SYMBOL_REF_USED (fun))
985 SYMBOL_REF_USED (fun) = 1;
986 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
991 /* Declare the label NAME global. */
994 assemble_global (name)
997 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1000 /* Assemble a label named NAME. */
1003 assemble_label (name)
1006 ASM_OUTPUT_LABEL (asm_out_file, name);
1009 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1010 If NAME starts with a *, the rest of NAME is output verbatim.
1011 Otherwise NAME is transformed in an implementation-defined way
1012 (usually by the addition of an underscore).
1013 Many macros in the tm file are defined to call this function. */
1016 assemble_name (file, name)
1021 fputs (&name[1], file);
1023 ASM_OUTPUT_LABELREF (file, name);
1026 /* Allocate SIZE bytes writable static space with a gensym name
1027 and return an RTX to refer to its address. */
1030 assemble_static_space (size)
1036 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1037 so that each uninitialized object starts on such a boundary. */
1038 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1039 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1040 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1043 if (flag_shared_data)
1047 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1050 namestring = (char *) obstack_alloc (saveable_obstack,
1052 strcpy (namestring, name);
1054 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1055 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1056 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1058 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1063 /* Assemble the static constant template for function entry trampolines.
1064 This is done at most once per compilation.
1065 Returns an RTX for the address of the template. */
1068 assemble_trampoline_template ()
1074 /* By default, put trampoline templates in read-only data section. */
1076 #ifdef TRAMPOLINE_SECTION
1077 TRAMPOLINE_SECTION ();
1079 readonly_data_section ();
1082 /* Write the assembler code to define one. */
1083 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1085 ASM_OUTPUT_ALIGN (asm_out_file, align);
1087 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1088 TRAMPOLINE_TEMPLATE (asm_out_file);
1090 /* Record the rtl to refer to it. */
1091 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1093 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1094 return gen_rtx (SYMBOL_REF, Pmode, name);
1097 /* Assemble the integer constant X into an object of SIZE bytes.
1098 X must be either a CONST_INT or CONST_DOUBLE.
1100 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1101 non-zero, abort if we can't output the constant. */
1104 assemble_integer (x, size, force)
1109 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1110 ASM_OUTPUT... macros. */
1114 #ifdef ASM_OUTPUT_CHAR
1116 ASM_OUTPUT_CHAR (asm_out_file, x);
1120 #ifdef ASM_OUTPUT_SHORT
1122 ASM_OUTPUT_SHORT (asm_out_file, x);
1126 #ifdef ASM_OUTPUT_INT
1128 ASM_OUTPUT_INT (asm_out_file, x);
1132 #ifdef ASM_OUTPUT_DOUBLE_INT
1134 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1138 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1140 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1145 /* If we couldn't do it that way, there are two other possibilities: First,
1146 if the machine can output an explicit byte and this is a 1 byte constant,
1147 we can use ASM_OUTPUT_BYTE. */
1149 #ifdef ASM_OUTPUT_BYTE
1150 if (size == 1 && GET_CODE (x) == CONST_INT)
1152 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1157 /* Finally, if SIZE is larger than a single word, try to output the constant
1158 one word at a time. */
1160 if (size > UNITS_PER_WORD)
1163 enum machine_mode mode
1164 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1167 for (i = 0; i < size / UNITS_PER_WORD; i++)
1169 word = operand_subword (x, i, 0, mode);
1174 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1178 if (i == size / UNITS_PER_WORD)
1180 /* If we output at least one word and then could not finish,
1181 there is no valid way to continue. */
1192 /* Assemble the floating-point constant D into an object of size MODE. */
1195 assemble_real (d, mode)
1197 enum machine_mode mode;
1199 jmp_buf output_constant_handler;
1201 if (setjmp (output_constant_handler))
1203 error ("floating point trap outputting a constant");
1204 #ifdef REAL_IS_NOT_DOUBLE
1205 bzero (&d, sizeof d);
1212 set_float_handler (output_constant_handler);
1216 #ifdef ASM_OUTPUT_BYTE_FLOAT
1218 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1221 #ifdef ASM_OUTPUT_SHORT_FLOAT
1223 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1226 #ifdef ASM_OUTPUT_FLOAT
1228 ASM_OUTPUT_FLOAT (asm_out_file, d);
1232 #ifdef ASM_OUTPUT_DOUBLE
1234 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1238 #ifdef ASM_OUTPUT_LONG_DOUBLE
1240 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1248 set_float_handler (NULL_PTR);
1251 /* Here we combine duplicate floating constants to make
1252 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1254 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1255 They are chained through the CONST_DOUBLE_CHAIN.
1256 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1257 In that case, CONST_DOUBLE_MEM is either a MEM,
1258 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1260 (CONST_DOUBLE_MEM is used only for top-level functions.
1261 See force_const_mem for explanation.) */
1263 static rtx const_double_chain;
1265 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1266 For an integer, I0 is the low-order word and I1 is the high-order word.
1267 For a real number, I0 is the word with the low address
1268 and I1 is the word with the high address. */
1271 immed_double_const (i0, i1, mode)
1272 HOST_WIDE_INT i0, i1;
1273 enum machine_mode mode;
1276 int in_current_obstack;
1278 if (GET_MODE_CLASS (mode) == MODE_INT)
1280 /* We clear out all bits that don't belong in MODE, unless they and our
1281 sign bit are all one. So we get either a reasonable negative value
1282 or a reasonable unsigned value for this mode. */
1283 int width = GET_MODE_BITSIZE (mode);
1284 if (width < HOST_BITS_PER_WIDE_INT
1285 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1286 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1287 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1288 else if (width == HOST_BITS_PER_WIDE_INT
1289 && ! (i1 == ~0 && i0 < 0))
1291 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1292 /* We cannot represent this value as a constant. */
1295 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1297 ??? Strictly speaking, this is wrong if we create a CONST_INT
1298 for a large unsigned constant with the size of MODE being
1299 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1300 wider mode. In that case we will mis-interpret it as a negative
1303 Unfortunately, the only alternative is to make a CONST_DOUBLE
1304 for any constant in any mode if it is an unsigned constant larger
1305 than the maximum signed integer in an int on the host. However,
1306 doing this will break everyone that always expects to see a CONST_INT
1307 for SImode and smaller.
1309 We have always been making CONST_INTs in this case, so nothing new
1312 if (width <= HOST_BITS_PER_WIDE_INT)
1313 i1 = (i0 < 0) ? ~0 : 0;
1315 /* If this integer fits in one word, return a CONST_INT. */
1316 if ((i1 == 0 && i0 >= 0)
1317 || (i1 == ~0 && i0 < 0))
1318 return GEN_INT (i0);
1320 /* We use VOIDmode for integers. */
1324 /* Search the chain for an existing CONST_DOUBLE with the right value.
1325 If one is found, return it. */
1327 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1328 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1329 && GET_MODE (r) == mode)
1332 /* No; make a new one and add it to the chain.
1334 We may be called by an optimizer which may be discarding any memory
1335 allocated during its processing (such as combine and loop). However,
1336 we will be leaving this constant on the chain, so we cannot tolerate
1337 freed memory. So switch to saveable_obstack for this allocation
1338 and then switch back if we were in current_obstack. */
1340 in_current_obstack = rtl_in_saveable_obstack ();
1341 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1342 if (in_current_obstack)
1343 rtl_in_current_obstack ();
1345 /* Don't touch const_double_chain in nested function;
1346 see force_const_mem. */
1347 if (outer_function_chain == 0)
1349 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1350 const_double_chain = r;
1353 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1354 Actual use of mem-slot is only through force_const_mem. */
1356 CONST_DOUBLE_MEM (r) = const0_rtx;
1361 /* Return a CONST_DOUBLE for a specified `double' value
1362 and machine mode. */
1365 immed_real_const_1 (d, mode)
1367 enum machine_mode mode;
1369 union real_extract u;
1371 int in_current_obstack;
1373 /* Get the desired `double' value as a sequence of ints
1374 since that is how they are stored in a CONST_DOUBLE. */
1378 /* Detect special cases. */
1380 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1381 if (!bcmp (&dconst0, &d, sizeof d))
1382 return CONST0_RTX (mode);
1383 else if (REAL_VALUES_EQUAL (dconst1, d))
1384 return CONST1_RTX (mode);
1386 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1387 return immed_double_const (u.i[0], u.i[1], mode);
1389 /* The rest of this function handles the case where
1390 a float value requires more than 2 ints of space.
1391 It will be deleted as dead code on machines that don't need it. */
1393 /* Search the chain for an existing CONST_DOUBLE with the right value.
1394 If one is found, return it. */
1396 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1397 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1398 && GET_MODE (r) == mode)
1401 /* No; make a new one and add it to the chain.
1403 We may be called by an optimizer which may be discarding any memory
1404 allocated during its processing (such as combine and loop). However,
1405 we will be leaving this constant on the chain, so we cannot tolerate
1406 freed memory. So switch to saveable_obstack for this allocation
1407 and then switch back if we were in current_obstack. */
1409 in_current_obstack = rtl_in_saveable_obstack ();
1410 r = rtx_alloc (CONST_DOUBLE);
1412 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1413 if (in_current_obstack)
1414 rtl_in_current_obstack ();
1416 /* Don't touch const_double_chain in nested function;
1417 see force_const_mem. */
1418 if (outer_function_chain == 0)
1420 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1421 const_double_chain = r;
1424 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1425 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1426 is only through force_const_mem. */
1428 CONST_DOUBLE_MEM (r) = const0_rtx;
1433 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1434 which must be a REAL_CST tree node. */
1437 immed_real_const (exp)
1440 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1443 /* At the end of a function, forget the memory-constants
1444 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1445 Also clear out real_constant_chain and clear out all the chain-pointers. */
1448 clear_const_double_mem ()
1450 register rtx r, next;
1452 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1453 See force_const_mem for explanation. */
1454 if (outer_function_chain != 0)
1457 for (r = const_double_chain; r; r = next)
1459 next = CONST_DOUBLE_CHAIN (r);
1460 CONST_DOUBLE_CHAIN (r) = 0;
1461 CONST_DOUBLE_MEM (r) = cc0_rtx;
1463 const_double_chain = 0;
1466 /* Given an expression EXP with a constant value,
1467 reduce it to the sum of an assembler symbol and an integer.
1468 Store them both in the structure *VALUE.
1469 Abort if EXP does not reduce. */
1474 HOST_WIDE_INT offset;
1478 decode_addr_const (exp, value)
1480 struct addr_const *value;
1482 register tree target = TREE_OPERAND (exp, 0);
1483 register int offset = 0;
1488 if (TREE_CODE (target) == COMPONENT_REF
1489 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1492 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1493 target = TREE_OPERAND (target, 0);
1495 else if (TREE_CODE (target) == ARRAY_REF)
1497 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1498 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1500 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1501 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1503 target = TREE_OPERAND (target, 0);
1509 switch (TREE_CODE (target))
1513 x = DECL_RTL (target);
1517 x = gen_rtx (MEM, FUNCTION_MODE,
1518 gen_rtx (LABEL_REF, VOIDmode,
1519 label_rtx (TREE_OPERAND (exp, 0))));
1526 x = TREE_CST_RTL (target);
1533 if (GET_CODE (x) != MEM)
1538 value->offset = offset;
1541 /* Uniquize all constants that appear in memory.
1542 Each constant in memory thus far output is recorded
1543 in `const_hash_table' with a `struct constant_descriptor'
1544 that contains a polish representation of the value of
1547 We cannot store the trees in the hash table
1548 because the trees may be temporary. */
1550 struct constant_descriptor
1552 struct constant_descriptor *next;
1558 #define MAX_HASH_TABLE 1009
1559 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1561 /* Compute a hash code for a constant expression. */
1568 register int len, hi, i;
1569 register enum tree_code code = TREE_CODE (exp);
1571 if (code == INTEGER_CST)
1573 p = (char *) &TREE_INT_CST_LOW (exp);
1574 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1576 else if (code == REAL_CST)
1578 p = (char *) &TREE_REAL_CST (exp);
1579 len = sizeof TREE_REAL_CST (exp);
1581 else if (code == STRING_CST)
1582 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1583 else if (code == COMPLEX_CST)
1584 return const_hash (TREE_REALPART (exp)) * 5
1585 + const_hash (TREE_IMAGPART (exp));
1586 else if (code == CONSTRUCTOR)
1590 /* For record type, include the type in the hashing.
1591 We do not do so for array types
1592 because (1) the sizes of the elements are sufficient
1593 and (2) distinct array types can have the same constructor.
1594 Instead, we include the array size because the constructor could
1596 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1597 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
1600 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
1601 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
1603 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1604 if (TREE_VALUE (link))
1605 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
1609 else if (code == ADDR_EXPR)
1611 struct addr_const value;
1612 decode_addr_const (exp, &value);
1613 if (GET_CODE (value.base) == SYMBOL_REF)
1615 /* Don't hash the address of the SYMBOL_REF;
1616 only use the offset and the symbol name. */
1618 p = XSTR (value.base, 0);
1619 for (i = 0; p[i] != 0; i++)
1620 hi = ((hi * 613) + (unsigned)(p[i]));
1622 else if (GET_CODE (value.base) == LABEL_REF)
1623 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
1625 hi &= (1 << HASHBITS) - 1;
1626 hi %= MAX_HASH_TABLE;
1629 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1630 return const_hash (TREE_OPERAND (exp, 0)) * 9
1631 + const_hash (TREE_OPERAND (exp, 1));
1632 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1633 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
1635 /* Compute hashing function */
1637 for (i = 0; i < len; i++)
1638 hi = ((hi * 613) + (unsigned)(p[i]));
1640 hi &= (1 << HASHBITS) - 1;
1641 hi %= MAX_HASH_TABLE;
1645 /* Compare a constant expression EXP with a constant-descriptor DESC.
1646 Return 1 if DESC describes a constant with the same value as EXP. */
1649 compare_constant (exp, desc)
1651 struct constant_descriptor *desc;
1653 return 0 != compare_constant_1 (exp, desc->contents);
1656 /* Compare constant expression EXP with a substring P of a constant descriptor.
1657 If they match, return a pointer to the end of the substring matched.
1658 If they do not match, return 0.
1660 Since descriptors are written in polish prefix notation,
1661 this function can be used recursively to test one operand of EXP
1662 against a subdescriptor, and if it succeeds it returns the
1663 address of the subdescriptor for the next operand. */
1666 compare_constant_1 (exp, p)
1670 register char *strp;
1672 register enum tree_code code = TREE_CODE (exp);
1674 if (code != (enum tree_code) *p++)
1677 if (code == INTEGER_CST)
1679 /* Integer constants are the same only if the same width of type. */
1680 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1682 strp = (char *) &TREE_INT_CST_LOW (exp);
1683 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1685 else if (code == REAL_CST)
1687 /* Real constants are the same only if the same width of type. */
1688 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1690 strp = (char *) &TREE_REAL_CST (exp);
1691 len = sizeof TREE_REAL_CST (exp);
1693 else if (code == STRING_CST)
1695 if (flag_writable_strings)
1697 strp = TREE_STRING_POINTER (exp);
1698 len = TREE_STRING_LENGTH (exp);
1699 if (bcmp (&TREE_STRING_LENGTH (exp), p,
1700 sizeof TREE_STRING_LENGTH (exp)))
1702 p += sizeof TREE_STRING_LENGTH (exp);
1704 else if (code == COMPLEX_CST)
1706 p = compare_constant_1 (TREE_REALPART (exp), p);
1707 if (p == 0) return 0;
1708 p = compare_constant_1 (TREE_IMAGPART (exp), p);
1711 else if (code == CONSTRUCTOR)
1714 int length = list_length (CONSTRUCTOR_ELTS (exp));
1717 if (bcmp (&length, p, sizeof length))
1721 /* For record constructors, insist that the types match.
1722 For arrays, just verify both constructors are for arrays. */
1723 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1724 type = TREE_TYPE (exp);
1727 if (bcmp (&type, p, sizeof type))
1731 /* For arrays, insist that the size in bytes match. */
1732 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1734 int size = int_size_in_bytes (TREE_TYPE (exp));
1735 if (bcmp (&size, p, sizeof size))
1740 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1742 if (TREE_VALUE (link))
1744 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
1751 if (bcmp (&zero, p, sizeof zero))
1759 else if (code == ADDR_EXPR)
1761 struct addr_const value;
1762 decode_addr_const (exp, &value);
1763 strp = (char *) &value.offset;
1764 len = sizeof value.offset;
1765 /* Compare the offset. */
1767 if (*p++ != *strp++)
1769 /* Compare symbol name. */
1770 strp = XSTR (value.base, 0);
1771 len = strlen (strp) + 1;
1773 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1775 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1776 if (p == 0) return 0;
1777 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
1780 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1782 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1786 /* Compare constant contents. */
1788 if (*p++ != *strp++)
1794 /* Construct a constant descriptor for the expression EXP.
1795 It is up to the caller to enter the descriptor in the hash table. */
1797 static struct constant_descriptor *
1798 record_constant (exp)
1801 struct constant_descriptor *ptr = 0;
1804 obstack_grow (&permanent_obstack, &ptr, sizeof ptr);
1805 obstack_grow (&permanent_obstack, &buf, sizeof buf);
1806 record_constant_1 (exp);
1807 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
1810 /* Add a description of constant expression EXP
1811 to the object growing in `permanent_obstack'.
1812 No need to return its address; the caller will get that
1813 from the obstack when the object is complete. */
1816 record_constant_1 (exp)
1819 register char *strp;
1821 register enum tree_code code = TREE_CODE (exp);
1823 obstack_1grow (&permanent_obstack, (unsigned int) code);
1825 if (code == INTEGER_CST)
1827 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1828 strp = (char *) &TREE_INT_CST_LOW (exp);
1829 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1831 else if (code == REAL_CST)
1833 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1834 strp = (char *) &TREE_REAL_CST (exp);
1835 len = sizeof TREE_REAL_CST (exp);
1837 else if (code == STRING_CST)
1839 if (flag_writable_strings)
1841 strp = TREE_STRING_POINTER (exp);
1842 len = TREE_STRING_LENGTH (exp);
1843 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
1844 sizeof TREE_STRING_LENGTH (exp));
1846 else if (code == COMPLEX_CST)
1848 record_constant_1 (TREE_REALPART (exp));
1849 record_constant_1 (TREE_IMAGPART (exp));
1852 else if (code == CONSTRUCTOR)
1855 int length = list_length (CONSTRUCTOR_ELTS (exp));
1858 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
1860 /* For record constructors, insist that the types match.
1861 For arrays, just verify both constructors are for arrays. */
1862 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1863 type = TREE_TYPE (exp);
1866 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
1868 /* For arrays, insist that the size in bytes match. */
1869 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1871 int size = int_size_in_bytes (TREE_TYPE (exp));
1872 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
1875 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1877 if (TREE_VALUE (link))
1878 record_constant_1 (TREE_VALUE (link));
1883 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
1889 else if (code == ADDR_EXPR)
1891 struct addr_const value;
1892 decode_addr_const (exp, &value);
1893 /* Record the offset. */
1894 obstack_grow (&permanent_obstack,
1895 (char *) &value.offset, sizeof value.offset);
1896 /* Record the symbol name. */
1897 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
1898 strlen (XSTR (value.base, 0)) + 1);
1901 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1903 record_constant_1 (TREE_OPERAND (exp, 0));
1904 record_constant_1 (TREE_OPERAND (exp, 1));
1907 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1909 record_constant_1 (TREE_OPERAND (exp, 0));
1913 /* Record constant contents. */
1914 obstack_grow (&permanent_obstack, strp, len);
1917 /* Return an rtx representing a reference to constant data in memory
1918 for the constant expression EXP.
1919 If assembler code for such a constant has already been output,
1920 return an rtx to refer to it.
1921 Otherwise, output such a constant in memory and generate
1922 an rtx for it. The TREE_CST_RTL of EXP is set up to point to that rtx.
1923 The const_hash_table records which constants already have label strings. */
1926 output_constant_def (exp)
1929 register int hash, align;
1930 register struct constant_descriptor *desc;
1936 if (TREE_CODE (exp) == INTEGER_CST)
1937 abort (); /* No TREE_CST_RTL slot in these. */
1939 if (TREE_CST_RTL (exp))
1940 return TREE_CST_RTL (exp);
1942 /* Make sure any other constants whose addresses appear in EXP
1943 are assigned label numbers. */
1945 reloc = output_addressed_constants (exp);
1947 /* Compute hash code of EXP. Search the descriptors for that hash code
1948 to see if any of them describes EXP. If yes, the descriptor records
1949 the label number already assigned. */
1951 hash = const_hash (exp) % MAX_HASH_TABLE;
1953 for (desc = const_hash_table[hash]; desc; desc = desc->next)
1954 if (compare_constant (exp, desc))
1956 found = desc->label;
1962 /* No constant equal to EXP is known to have been output.
1963 Make a constant descriptor to enter EXP in the hash table.
1964 Assign the label number and record it in the descriptor for
1965 future calls to this function to find. */
1967 /* Create a string containing the label name, in LABEL. */
1968 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
1970 desc = record_constant (exp);
1971 desc->next = const_hash_table[hash];
1973 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1974 const_hash_table[hash] = desc;
1977 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
1979 push_obstacks_nochange ();
1980 if (TREE_PERMANENT (exp))
1981 end_temporary_allocation ();
1983 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
1986 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
1987 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
1988 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1989 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1990 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
1994 /* Optionally set flags or add text to the name to record information
1995 such as that it is a function name. If the name is changed, the macro
1996 ASM_OUTPUT_LABELREF will have to know how to strip this information.
1997 And if it finds a * at the beginning after doing so, it must handle
1999 #ifdef ENCODE_SECTION_INFO
2000 ENCODE_SECTION_INFO (exp);
2005 /* Now output assembler code to define that label
2006 and follow it with the data of EXP. */
2008 /* First switch to text section, except for writable strings. */
2009 #ifdef SELECT_SECTION
2010 SELECT_SECTION (exp, reloc);
2012 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2013 || (flag_pic && reloc))
2016 readonly_data_section ();
2019 /* Align the location counter as required by EXP's data type. */
2020 align = TYPE_ALIGN (TREE_TYPE (exp));
2021 #ifdef CONSTANT_ALIGNMENT
2022 align = CONSTANT_ALIGNMENT (exp, align);
2025 if (align > BITS_PER_UNIT)
2026 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2028 /* Output the label itself. */
2029 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
2031 /* Output the value of EXP. */
2032 output_constant (exp,
2033 (TREE_CODE (exp) == STRING_CST
2034 ? TREE_STRING_LENGTH (exp)
2035 : int_size_in_bytes (TREE_TYPE (exp))));
2040 return TREE_CST_RTL (exp);
2043 /* Similar hash facility for making memory-constants
2044 from constant rtl-expressions. It is used on RISC machines
2045 where immediate integer arguments and constant addresses are restricted
2046 so that such constants must be stored in memory.
2048 This pool of constants is reinitialized for each function
2049 so each function gets its own constants-pool that comes right before it.
2051 All structures allocated here are discarded when functions are saved for
2052 inlining, so they do not need to be allocated permanently. */
2054 #define MAX_RTX_HASH_TABLE 61
2055 static struct constant_descriptor **const_rtx_hash_table;
2057 /* Structure to represent sufficient information about a constant so that
2058 it can be output when the constant pool is output, so that function
2059 integration can be done, and to simplify handling on machines that reference
2060 constant pool as base+displacement. */
2062 struct pool_constant
2064 struct constant_descriptor *desc;
2065 struct pool_constant *next;
2066 enum machine_mode mode;
2073 /* Pointers to first and last constant in pool. */
2075 static struct pool_constant *first_pool, *last_pool;
2077 /* Current offset in constant pool (does not include any machine-specific
2080 static int pool_offset;
2082 /* Structure used to maintain hash table mapping symbols used to their
2083 corresponding constants. */
2088 struct pool_constant *pool;
2089 struct pool_sym *next;
2092 static struct pool_sym **const_rtx_sym_hash_table;
2094 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2095 The argument is XSTR (... , 0) */
2097 #define SYMHASH(LABEL) \
2098 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2100 /* Initialize constant pool hashing for next function. */
2103 init_const_rtx_hash_table ()
2105 const_rtx_hash_table
2106 = ((struct constant_descriptor **)
2107 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2108 const_rtx_sym_hash_table
2109 = ((struct pool_sym **)
2110 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2111 bzero (const_rtx_hash_table,
2112 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2113 bzero (const_rtx_sym_hash_table,
2114 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2116 first_pool = last_pool = 0;
2120 /* Save and restore it for a nested function. */
2123 save_varasm_status (p)
2126 p->const_rtx_hash_table = const_rtx_hash_table;
2127 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2128 p->first_pool = first_pool;
2129 p->last_pool = last_pool;
2130 p->pool_offset = pool_offset;
2134 restore_varasm_status (p)
2137 const_rtx_hash_table = p->const_rtx_hash_table;
2138 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2139 first_pool = p->first_pool;
2140 last_pool = p->last_pool;
2141 pool_offset = p->pool_offset;
2144 enum kind { RTX_DOUBLE, RTX_INT };
2148 #ifdef ONLY_INT_FIELDS
2149 unsigned int kind : 16;
2150 unsigned int mode : 16;
2152 enum kind kind : 16;
2153 enum machine_mode mode : 16;
2156 union real_extract du;
2157 struct addr_const addr;
2161 /* Express an rtx for a constant integer (perhaps symbolic)
2162 as the sum of a symbol or label plus an explicit integer.
2163 They are stored into VALUE. */
2166 decode_rtx_const (mode, x, value)
2167 enum machine_mode mode;
2169 struct rtx_const *value;
2171 /* Clear the whole structure, including any gaps. */
2174 int *p = (int *) value;
2175 int *end = (int *) (value + 1);
2180 value->kind = RTX_INT; /* Most usual kind. */
2183 switch (GET_CODE (x))
2186 value->kind = RTX_DOUBLE;
2187 value->mode = GET_MODE (x);
2188 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2192 value->un.addr.offset = INTVAL (x);
2198 value->un.addr.base = x;
2203 if (GET_CODE (x) == PLUS)
2205 value->un.addr.base = XEXP (x, 0);
2206 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2208 value->un.addr.offset = INTVAL (XEXP (x, 1));
2210 else if (GET_CODE (x) == MINUS)
2212 value->un.addr.base = XEXP (x, 0);
2213 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2215 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2225 if (value->kind == RTX_INT && value->un.addr.base != 0)
2226 switch (GET_CODE (value->un.addr.base))
2230 /* Use the string's address, not the SYMBOL_REF's address,
2231 for the sake of addresses of library routines.
2232 For a LABEL_REF, compare labels. */
2233 value->un.addr.base = XEXP (value->un.addr.base, 0);
2237 /* Given a MINUS expression, simplify it if both sides
2238 include the same symbol. */
2241 simplify_subtraction (x)
2244 struct rtx_const val0, val1;
2246 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2247 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2249 if (val0.un.addr.base == val1.un.addr.base)
2250 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2254 /* Compute a hash code for a constant RTL expression. */
2257 const_hash_rtx (mode, x)
2258 enum machine_mode mode;
2263 struct rtx_const value;
2264 decode_rtx_const (mode, x, &value);
2266 /* Compute hashing function */
2268 for (i = 0; i < sizeof value / sizeof (int); i++)
2269 hi += ((int *) &value)[i];
2271 hi &= (1 << HASHBITS) - 1;
2272 hi %= MAX_RTX_HASH_TABLE;
2276 /* Compare a constant rtl object X with a constant-descriptor DESC.
2277 Return 1 if DESC describes a constant with the same value as X. */
2280 compare_constant_rtx (mode, x, desc)
2281 enum machine_mode mode;
2283 struct constant_descriptor *desc;
2285 register int *p = (int *) desc->contents;
2288 struct rtx_const value;
2290 decode_rtx_const (mode, x, &value);
2291 strp = (int *) &value;
2292 len = sizeof value / sizeof (int);
2294 /* Compare constant contents. */
2296 if (*p++ != *strp++)
2302 /* Construct a constant descriptor for the rtl-expression X.
2303 It is up to the caller to enter the descriptor in the hash table. */
2305 static struct constant_descriptor *
2306 record_constant_rtx (mode, x)
2307 enum machine_mode mode;
2310 struct constant_descriptor *ptr;
2312 struct rtx_const value;
2314 decode_rtx_const (mode, x, &value);
2316 obstack_grow (current_obstack, &ptr, sizeof ptr);
2317 obstack_grow (current_obstack, &label, sizeof label);
2319 /* Record constant contents. */
2320 obstack_grow (current_obstack, &value, sizeof value);
2322 return (struct constant_descriptor *) obstack_finish (current_obstack);
2325 /* Given a constant rtx X, make (or find) a memory constant for its value
2326 and return a MEM rtx to refer to it in memory. */
2329 force_const_mem (mode, x)
2330 enum machine_mode mode;
2334 register struct constant_descriptor *desc;
2339 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2340 (this will always be true for floating CONST_DOUBLEs that have been
2341 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2342 use the previous copy. Otherwise, make a new one. Note that in
2343 the unlikely event that this same CONST_DOUBLE is used in two different
2344 modes in an alternating fashion, we will allocate a lot of different
2345 memory locations, but this should be extremely rare. */
2347 /* Don't use CONST_DOUBLE_MEM in a nested function.
2348 Nested functions have their own constant pools,
2349 so they can't share the same values in CONST_DOUBLE_MEM
2350 with the containing function. */
2351 if (outer_function_chain == 0)
2352 if (GET_CODE (x) == CONST_DOUBLE
2353 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2354 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2355 return CONST_DOUBLE_MEM (x);
2357 /* Compute hash code of X. Search the descriptors for that hash code
2358 to see if any of them describes X. If yes, the descriptor records
2359 the label number already assigned. */
2361 hash = const_hash_rtx (mode, x);
2363 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2364 if (compare_constant_rtx (mode, x, desc))
2366 found = desc->label;
2372 register struct pool_constant *pool;
2373 register struct pool_sym *sym;
2376 /* No constant equal to X is known to have been output.
2377 Make a constant descriptor to enter X in the hash table.
2378 Assign the label number and record it in the descriptor for
2379 future calls to this function to find. */
2381 desc = record_constant_rtx (mode, x);
2382 desc->next = const_rtx_hash_table[hash];
2383 const_rtx_hash_table[hash] = desc;
2385 /* Align the location counter as required by EXP's data type. */
2386 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2387 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2388 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2390 pool_offset += align - 1;
2391 pool_offset &= ~ (align - 1);
2393 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2395 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2399 pool->labelno = const_labelno;
2400 pool->align = align;
2401 pool->offset = pool_offset;
2407 last_pool->next = pool;
2410 pool_offset += GET_MODE_SIZE (mode);
2412 /* Create a string containing the label name, in LABEL. */
2413 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2418 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2420 /* Add label to symbol hash table. */
2421 hash = SYMHASH (found);
2422 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2425 sym->next = const_rtx_sym_hash_table[hash];
2426 const_rtx_sym_hash_table[hash] = sym;
2429 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2431 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2433 RTX_UNCHANGING_P (def) = 1;
2434 /* Mark the symbol_ref as belonging to this constants pool. */
2435 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2436 current_function_uses_const_pool = 1;
2438 if (outer_function_chain == 0)
2439 if (GET_CODE (x) == CONST_DOUBLE)
2441 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2443 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2444 const_double_chain = x;
2446 CONST_DOUBLE_MEM (x) = def;
2452 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2453 the corresponding pool_constant structure. */
2455 static struct pool_constant *
2456 find_pool_constant (addr)
2459 struct pool_sym *sym;
2460 char *label = XSTR (addr, 0);
2462 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2463 if (sym->label == label)
2469 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2472 get_pool_constant (addr)
2475 return (find_pool_constant (addr))->constant;
2478 /* Similar, return the mode. */
2481 get_pool_mode (addr)
2484 return (find_pool_constant (addr))->mode;
2487 /* Similar, return the offset in the constant pool. */
2490 get_pool_offset (addr)
2493 return (find_pool_constant (addr))->offset;
2496 /* Return the size of the constant pool. */
2504 /* Write all the constants in the constant pool. */
2507 output_constant_pool (fnname, fndecl)
2511 struct pool_constant *pool;
2513 union real_extract u;
2515 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2516 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
2519 for (pool = first_pool; pool; pool = pool->next)
2523 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2524 whose CODE_LABEL has been deleted. This can occur if a jump table
2525 is eliminated by optimization. If so, write a constant of zero
2526 instead. Note that this can also happen by turning the
2527 CODE_LABEL into a NOTE. */
2528 if (((GET_CODE (x) == LABEL_REF
2529 && (INSN_DELETED_P (XEXP (x, 0))
2530 || GET_CODE (XEXP (x, 0)) == NOTE)))
2531 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2532 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
2533 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
2534 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
2537 /* First switch to correct section. */
2538 #ifdef SELECT_RTX_SECTION
2539 SELECT_RTX_SECTION (pool->mode, x);
2541 readonly_data_section ();
2544 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2545 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
2546 pool->align, pool->labelno, done);
2549 if (pool->align > 1)
2550 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
2552 /* Output the label. */
2553 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
2555 /* Output the value of the constant itself. */
2556 switch (GET_MODE_CLASS (pool->mode))
2559 if (GET_CODE (x) != CONST_DOUBLE)
2562 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
2563 assemble_real (u.d, pool->mode);
2567 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
2577 /* Done with this pool. */
2578 first_pool = last_pool = 0;
2581 /* Find all the constants whose addresses are referenced inside of EXP,
2582 and make sure assembler code with a label has been output for each one.
2583 Indicate whether an ADDR_EXPR has been encountered. */
2586 output_addressed_constants (exp)
2591 switch (TREE_CODE (exp))
2595 register tree constant = TREE_OPERAND (exp, 0);
2597 while (TREE_CODE (constant) == COMPONENT_REF)
2599 constant = TREE_OPERAND (constant, 0);
2602 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
2603 || TREE_CODE (constant) == CONSTRUCTOR)
2604 /* No need to do anything here
2605 for addresses of variables or functions. */
2606 output_constant_def (constant);
2613 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2614 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
2619 case NON_LVALUE_EXPR:
2620 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2626 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2627 if (TREE_VALUE (link) != 0)
2628 reloc |= output_addressed_constants (TREE_VALUE (link));
2638 /* Output assembler code for constant EXP to FILE, with no label.
2639 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2640 Assumes output_addressed_constants has been done on EXP already.
2642 Generate exactly SIZE bytes of assembler data, padding at the end
2643 with zeros if necessary. SIZE must always be specified.
2645 SIZE is important for structure constructors,
2646 since trailing members may have been omitted from the constructor.
2647 It is also important for initialization of arrays from string constants
2648 since the full length of the string constant might not be wanted.
2649 It is also needed for initialization of unions, where the initializer's
2650 type is just one member, and that may not be as long as the union.
2652 There a case in which we would fail to output exactly SIZE bytes:
2653 for a structure constructor that wants to produce more than SIZE bytes.
2654 But such constructors will never be generated for any possible input. */
2657 output_constant (exp, size)
2661 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
2667 /* Allow a constructor with no elements for any data type.
2668 This means to fill the space with zeros. */
2669 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
2671 assemble_zeros (size);
2675 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2676 That way we get the constant (we hope) inside it. */
2677 if (TREE_CODE (exp) == NOP_EXPR
2678 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
2679 exp = TREE_OPERAND (exp, 0);
2688 case REFERENCE_TYPE:
2689 /* ??? What about (int)((float)(int)&foo + 4) */
2690 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
2691 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2692 exp = TREE_OPERAND (exp, 0);
2694 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
2695 EXPAND_INITIALIZER),
2697 error ("initializer for integer value is too complicated");
2702 if (TREE_CODE (exp) != REAL_CST)
2703 error ("initializer for floating value is not a floating constant");
2705 assemble_real (TREE_REAL_CST (exp),
2706 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
2711 output_constant (TREE_REALPART (exp), size / 2);
2712 output_constant (TREE_IMAGPART (exp), size / 2);
2713 size -= (size / 2) * 2;
2717 if (TREE_CODE (exp) == CONSTRUCTOR)
2719 output_constructor (exp, size);
2722 else if (TREE_CODE (exp) == STRING_CST)
2726 if (size > TREE_STRING_LENGTH (exp))
2728 excess = size - TREE_STRING_LENGTH (exp);
2729 size = TREE_STRING_LENGTH (exp);
2732 assemble_string (TREE_STRING_POINTER (exp), size);
2741 if (TREE_CODE (exp) == CONSTRUCTOR)
2742 output_constructor (exp, size);
2749 assemble_zeros (size);
2752 /* Subroutine of output_constant, used for CONSTRUCTORs
2753 (aggregate constants).
2754 Generate at least SIZE bytes, padding if necessary. */
2757 output_constructor (exp, size)
2761 register tree link, field = 0;
2762 /* Number of bytes output or skipped so far.
2763 In other words, current position within the constructor. */
2764 int total_bytes = 0;
2765 /* Non-zero means BYTE contains part of a byte, to be output. */
2766 int byte_buffer_in_use = 0;
2769 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
2772 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2773 field = TYPE_FIELDS (TREE_TYPE (exp));
2775 /* As LINK goes through the elements of the constant,
2776 FIELD goes through the structure fields, if the constant is a structure.
2777 if the constant is a union, then we override this,
2778 by getting the field from the TREE_LIST element.
2779 But the constant could also be an array. Then FIELD is zero. */
2780 for (link = CONSTRUCTOR_ELTS (exp);
2782 link = TREE_CHAIN (link),
2783 field = field ? TREE_CHAIN (field) : 0)
2785 tree val = TREE_VALUE (link);
2786 /* the element in a union constructor specifies the proper field. */
2787 if (TREE_PURPOSE (link) != 0)
2788 field = TREE_PURPOSE (link);
2790 /* Eliminate the marker that makes a cast not be an lvalue. */
2794 if (field == 0 || !DECL_BIT_FIELD (field))
2796 register int fieldsize;
2797 /* Since this structure is static,
2798 we know the positions are constant. */
2799 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
2803 /* An element that is not a bit-field.
2804 Output any buffered-up bit-fields preceding it. */
2805 if (byte_buffer_in_use)
2807 ASM_OUTPUT_BYTE (asm_out_file, byte);
2809 byte_buffer_in_use = 0;
2812 /* Advance to offset of this element.
2813 Note no alignment needed in an array, since that is guaranteed
2814 if each element has the proper size. */
2815 if (field != 0 && bitpos != total_bytes)
2817 assemble_zeros (bitpos - total_bytes);
2818 total_bytes = bitpos;
2821 /* Determine size this element should occupy. */
2824 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
2826 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
2828 /* This avoids overflow trouble. */
2829 tree size_tree = size_binop (CEIL_DIV_EXPR,
2831 size_int (BITS_PER_UNIT));
2832 fieldsize = TREE_INT_CST_LOW (size_tree);
2836 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
2837 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
2841 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
2843 /* Output the element's initial value. */
2845 assemble_zeros (fieldsize);
2847 output_constant (val, fieldsize);
2849 /* Count its size. */
2850 total_bytes += fieldsize;
2852 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
2853 error ("invalid initial value for member `%s'",
2854 IDENTIFIER_POINTER (DECL_NAME (field)));
2857 /* Element that is a bit-field. */
2859 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
2861 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
2864 val = integer_zero_node;
2866 /* If this field does not start in this (or, next) byte,
2868 if (next_offset / BITS_PER_UNIT != total_bytes)
2870 /* Output remnant of any bit field in previous bytes. */
2871 if (byte_buffer_in_use)
2873 ASM_OUTPUT_BYTE (asm_out_file, byte);
2875 byte_buffer_in_use = 0;
2878 /* If still not at proper byte, advance to there. */
2879 if (next_offset / BITS_PER_UNIT != total_bytes)
2881 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
2882 total_bytes = next_offset / BITS_PER_UNIT;
2886 if (! byte_buffer_in_use)
2889 /* We must split the element into pieces that fall within
2890 separate bytes, and combine each byte with previous or
2891 following bit-fields. */
2893 /* next_offset is the offset n fbits from the beginning of
2894 the structure to the next bit of this element to be processed.
2895 end_offset is the offset of the first bit past the end of
2897 while (next_offset < end_offset)
2901 int next_byte = next_offset / BITS_PER_UNIT;
2902 int next_bit = next_offset % BITS_PER_UNIT;
2904 /* Advance from byte to byte
2905 within this element when necessary. */
2906 while (next_byte != total_bytes)
2908 ASM_OUTPUT_BYTE (asm_out_file, byte);
2913 /* Number of bits we can process at once
2914 (all part of the same byte). */
2915 this_time = MIN (end_offset - next_offset,
2916 BITS_PER_UNIT - next_bit);
2917 #if BYTES_BIG_ENDIAN
2918 /* On big-endian machine, take the most significant bits
2919 first (of the bits that are significant)
2920 and put them into bytes from the most significant end. */
2921 shift = end_offset - next_offset - this_time;
2922 /* Don't try to take a bunch of bits that cross
2923 the word boundary in the INTEGER_CST. */
2924 if (shift < HOST_BITS_PER_WIDE_INT
2925 && shift + this_time > HOST_BITS_PER_WIDE_INT)
2927 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
2928 shift = HOST_BITS_PER_WIDE_INT;
2931 /* Now get the bits from the appropriate constant word. */
2932 if (shift < HOST_BITS_PER_WIDE_INT)
2934 value = TREE_INT_CST_LOW (val);
2936 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
2938 value = TREE_INT_CST_HIGH (val);
2939 shift -= HOST_BITS_PER_WIDE_INT;
2943 byte |= (((value >> shift)
2944 & (((HOST_WIDE_INT) 1 << this_time) - 1))
2945 << (BITS_PER_UNIT - this_time - next_bit));
2947 /* On little-endian machines,
2948 take first the least significant bits of the value
2949 and pack them starting at the least significant
2950 bits of the bytes. */
2951 shift = (next_offset
2952 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
2953 /* Don't try to take a bunch of bits that cross
2954 the word boundary in the INTEGER_CST. */
2955 if (shift < HOST_BITS_PER_WIDE_INT
2956 && shift + this_time > HOST_BITS_PER_WIDE_INT)
2958 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
2959 shift = HOST_BITS_PER_WIDE_INT;
2962 /* Now get the bits from the appropriate constant word. */
2963 if (shift < HOST_BITS_PER_INT)
2964 value = TREE_INT_CST_LOW (val);
2965 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
2967 value = TREE_INT_CST_HIGH (val);
2968 shift -= HOST_BITS_PER_WIDE_INT;
2972 byte |= ((value >> shift)
2973 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
2975 next_offset += this_time;
2976 byte_buffer_in_use = 1;
2980 if (byte_buffer_in_use)
2982 ASM_OUTPUT_BYTE (asm_out_file, byte);
2985 if (total_bytes < size)
2986 assemble_zeros (size - total_bytes);