1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-98, 1999 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
38 #include "hard-reg-set.h"
50 #ifdef XCOFF_DEBUGGING_INFO
54 #ifndef TRAMPOLINE_ALIGNMENT
55 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
59 #define ASM_STABS_OP ".stabs"
62 /* Define the prefix to use when check_memory_usage_flag is enable. */
63 #ifdef NO_DOLLAR_IN_LABEL
64 #ifdef NO_DOT_IN_LABEL
65 #define CHKR_PREFIX "chkr_prefix_"
66 #else /* !NO_DOT_IN_LABEL */
67 #define CHKR_PREFIX "chkr."
69 #else /* !NO_DOLLAR_IN_LABEL */
70 #define CHKR_PREFIX "chkr$"
72 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
74 /* File in which assembler code is being written. */
76 extern FILE *asm_out_file;
78 /* The (assembler) name of the first globally-visible object output. */
79 char *first_global_object_name;
80 char *weak_global_object_name;
82 extern struct obstack *current_obstack;
83 extern struct obstack *saveable_obstack;
84 extern struct obstack *rtl_obstack;
85 extern struct obstack permanent_obstack;
86 #define obstack_chunk_alloc xmalloc
89 struct constant_descriptor;
93 #define MAX_RTX_HASH_TABLE 61
97 /* Hash facility for making memory-constants
98 from constant rtl-expressions. It is used on RISC machines
99 where immediate integer arguments and constant addresses are restricted
100 so that such constants must be stored in memory.
102 This pool of constants is reinitialized for each function
103 so each function gets its own constants-pool that comes right before
105 struct constant_descriptor **x_const_rtx_hash_table;
106 struct pool_sym **x_const_rtx_sym_hash_table;
108 /* Pointers to first and last constant in pool. */
109 struct pool_constant *x_first_pool, *x_last_pool;
111 /* Current offset in constant pool (does not include any machine-specific
115 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
116 They are chained through the CONST_DOUBLE_CHAIN.
117 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
118 In that case, CONST_DOUBLE_MEM is either a MEM,
119 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
120 rtx x_const_double_chain;
123 #define const_rtx_hash_table (current_function->varasm->x_const_rtx_hash_table)
124 #define const_rtx_sym_hash_table (current_function->varasm->x_const_rtx_sym_hash_table)
125 #define first_pool (current_function->varasm->x_first_pool)
126 #define last_pool (current_function->varasm->x_last_pool)
127 #define pool_offset (current_function->varasm->x_pool_offset)
128 #define const_double_chain (current_function->varasm->x_const_double_chain)
130 /* Number for making the label on the next
131 constant that is stored in memory. */
135 /* Number for making the label on the next
136 static variable internal to a function. */
140 /* Carry information from ASM_DECLARE_OBJECT_NAME
141 to ASM_FINISH_DECLARE_OBJECT. */
143 int size_directive_output;
145 /* The last decl for which assemble_variable was called,
146 if it did ASM_DECLARE_OBJECT_NAME.
147 If the last call to assemble_variable didn't do that,
150 tree last_assemble_variable_decl;
152 /* Nonzero if at least one function definition has been seen. */
154 static int function_defined;
156 static const char *strip_reg_name PROTO((const char *));
157 static int contains_pointers_p PROTO((tree));
158 static void decode_addr_const PROTO((tree, struct addr_const *));
159 static int const_hash PROTO((tree));
160 static int compare_constant PROTO((tree,
161 struct constant_descriptor *));
162 static char *compare_constant_1 PROTO((tree, char *));
163 static struct constant_descriptor *record_constant PROTO((tree));
164 static void record_constant_1 PROTO((tree));
165 static tree copy_constant PROTO((tree));
166 static void output_constant_def_contents PROTO((tree, int, int));
167 static void decode_rtx_const PROTO((enum machine_mode, rtx,
168 struct rtx_const *));
169 static int const_hash_rtx PROTO((enum machine_mode, rtx));
170 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
171 struct constant_descriptor *));
172 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
174 static struct pool_constant *find_pool_constant PROTO((struct function *, rtx));
175 static void mark_constant_pool PROTO((void));
176 static void mark_constants PROTO((rtx));
177 static int output_addressed_constants PROTO((tree));
178 static void output_after_function_constants PROTO((void));
179 static void output_constructor PROTO((tree, int));
180 #ifdef ASM_WEAKEN_LABEL
181 static void remove_from_pending_weak_list PROTO ((char *));
183 #ifdef ASM_OUTPUT_BSS
184 static void asm_output_bss PROTO((FILE *, tree, char *, int, int));
186 #ifdef BSS_SECTION_ASM_OP
187 #ifdef ASM_OUTPUT_ALIGNED_BSS
188 static void asm_output_aligned_bss PROTO((FILE *, tree, char *, int, int));
190 #endif /* BSS_SECTION_ASM_OP */
191 static void mark_pool_constant PROTO((struct pool_constant *));
192 static void mark_pool_sym_hash_table PROTO((struct pool_sym **));
193 static void mark_const_hash_entry PROTO((void *));
194 static void asm_emit_uninitialised PROTO((tree, char *, int, int));
196 static enum in_section { no_section, in_text, in_data, in_named
197 #ifdef BSS_SECTION_ASM_OP
200 #ifdef EH_FRAME_SECTION_ASM_OP
203 #ifdef EXTRA_SECTIONS
206 } in_section = no_section;
208 /* Return a non-zero value if DECL has a section attribute. */
209 #define IN_NAMED_SECTION(DECL) \
210 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
211 && DECL_SECTION_NAME (DECL) != NULL_TREE)
213 /* Text of section name when in_section == in_named. */
214 static char *in_named_name;
216 /* Define functions like text_section for any extra sections. */
217 #ifdef EXTRA_SECTION_FUNCTIONS
218 EXTRA_SECTION_FUNCTIONS
221 /* Tell assembler to switch to text section. */
226 if (in_section != in_text)
228 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
229 in_section = in_text;
233 /* Tell assembler to switch to data section. */
238 if (in_section != in_data)
240 if (flag_shared_data)
242 #ifdef SHARED_SECTION_ASM_OP
243 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
245 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
249 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
251 in_section = in_data;
254 /* Tell assembler to ALWAYS switch to data section, in case
255 it's not sure where it it. */
258 force_data_section ()
260 in_section = no_section;
264 /* Tell assembler to switch to read-only data section. This is normally
268 readonly_data_section ()
270 #ifdef READONLY_DATA_SECTION
271 READONLY_DATA_SECTION (); /* Note this can call data_section. */
277 /* Determine if we're in the text section. */
282 return in_section == in_text;
285 /* Determine if we're in the data section. */
290 return in_section == in_data;
293 /* Tell assembler to change to section NAME for DECL.
294 If DECL is NULL, just switch to section NAME.
295 If NAME is NULL, get the name from DECL.
296 If RELOC is 1, the initializer for DECL contains relocs. */
299 named_section (decl, name, reloc)
302 int reloc ATTRIBUTE_UNUSED;
304 if (decl != NULL_TREE
305 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
308 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
310 if (in_section != in_named || strcmp (name, in_named_name))
312 #ifdef ASM_OUTPUT_SECTION_NAME
313 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
315 /* Section attributes are not supported if this macro isn't provided -
316 some host formats don't support them at all. The front-end should
317 already have flagged this as an error. */
321 in_named_name = ggc_alloc_string (name, -1);
322 in_section = in_named;
326 #ifdef ASM_OUTPUT_SECTION_NAME
327 #ifndef UNIQUE_SECTION
328 #define UNIQUE_SECTION(DECL,RELOC) \
334 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
335 /* Strip off any encoding in name. */ \
336 STRIP_NAME_ENCODING (name, name); \
338 len = strlen (name) + 1; \
339 string = alloca (len + 1); \
340 sprintf (string, ".%s", name); \
342 DECL_SECTION_NAME (DECL) = build_string (len, string); \
345 #ifndef UNIQUE_SECTION_P
346 #define UNIQUE_SECTION_P(DECL) 0
350 #ifdef BSS_SECTION_ASM_OP
352 /* Tell the assembler to switch to the bss section. */
357 if (in_section != in_bss)
359 #ifdef SHARED_BSS_SECTION_ASM_OP
360 if (flag_shared_data)
361 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
364 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
370 #ifdef ASM_OUTPUT_BSS
372 /* Utility function for ASM_OUTPUT_BSS for targets to use if
373 they don't support alignments in .bss.
374 ??? It is believed that this function will work in most cases so such
375 support is localized here. */
378 asm_output_bss (file, decl, name, size, rounded)
384 ASM_GLOBALIZE_LABEL (file, name);
386 #ifdef ASM_DECLARE_OBJECT_NAME
387 last_assemble_variable_decl = decl;
388 ASM_DECLARE_OBJECT_NAME (file, name, decl);
390 /* Standard thing is just output label for the object. */
391 ASM_OUTPUT_LABEL (file, name);
392 #endif /* ASM_DECLARE_OBJECT_NAME */
393 ASM_OUTPUT_SKIP (file, rounded);
398 #ifdef ASM_OUTPUT_ALIGNED_BSS
400 /* Utility function for targets to use in implementing
401 ASM_OUTPUT_ALIGNED_BSS.
402 ??? It is believed that this function will work in most cases so such
403 support is localized here. */
406 asm_output_aligned_bss (file, decl, name, size, align)
412 ASM_GLOBALIZE_LABEL (file, name);
414 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
415 #ifdef ASM_DECLARE_OBJECT_NAME
416 last_assemble_variable_decl = decl;
417 ASM_DECLARE_OBJECT_NAME (file, name, decl);
419 /* Standard thing is just output label for the object. */
420 ASM_OUTPUT_LABEL (file, name);
421 #endif /* ASM_DECLARE_OBJECT_NAME */
422 ASM_OUTPUT_SKIP (file, size ? size : 1);
427 #endif /* BSS_SECTION_ASM_OP */
429 #ifdef EH_FRAME_SECTION_ASM_OP
433 if (in_section != in_eh_frame)
435 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
436 in_section = in_eh_frame;
441 /* Switch to the section for function DECL.
443 If DECL is NULL_TREE, switch to the text section.
444 ??? It's not clear that we will ever be passed NULL_TREE, but it's
445 safer to handle it. */
448 function_section (decl)
451 if (decl != NULL_TREE
452 && DECL_SECTION_NAME (decl) != NULL_TREE)
453 named_section (decl, (char *) 0, 0);
458 /* Switch to section for variable DECL.
460 RELOC is the `reloc' argument to SELECT_SECTION. */
463 variable_section (decl, reloc)
467 if (IN_NAMED_SECTION (decl))
468 named_section (decl, NULL, reloc);
471 /* C++ can have const variables that get initialized from constructors,
472 and thus can not be in a readonly section. We prevent this by
473 verifying that the initial value is constant for objects put in a
476 error_mark_node is used by the C front end to indicate that the
477 initializer has not been seen yet. In this case, we assume that
478 the initializer must be constant.
480 C++ uses error_mark_node for variables that have complicated
481 initializers, but these variables go in BSS so we won't be called
484 #ifdef SELECT_SECTION
485 SELECT_SECTION (decl, reloc);
487 if (DECL_READONLY_SECTION (decl, reloc))
488 readonly_data_section ();
495 /* Tell assembler to switch to the section for the exception handling
501 #if defined (EXCEPTION_SECTION)
502 EXCEPTION_SECTION ();
504 #ifdef ASM_OUTPUT_SECTION_NAME
505 named_section (NULL_TREE, ".gcc_except_table", 0);
510 readonly_data_section ();
515 /* Create the rtl to represent a function, for a function definition.
516 DECL is a FUNCTION_DECL node which describes which function.
517 The rtl is stored into DECL. */
520 make_function_rtl (decl)
523 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
524 char *new_name = name;
526 /* Rename a nested function to avoid conflicts. */
527 if (decl_function_context (decl) != 0
528 && DECL_INITIAL (decl) != 0
529 && DECL_RTL (decl) == 0)
533 name = IDENTIFIER_POINTER (DECL_NAME (decl));
534 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
535 name = ggc_alloc_string (label, -1);
540 /* When -fprefix-function-name is used, every function name is
541 prefixed. Even static functions are prefixed because they
542 could be declared latter. Note that a nested function name
544 if (flag_prefix_function_name)
546 size_t name_len = strlen (name);
548 new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
549 memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
550 memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
555 if (DECL_RTL (decl) == 0)
558 = gen_rtx_MEM (DECL_MODE (decl),
559 gen_rtx_SYMBOL_REF (Pmode, name));
561 /* Optionally set flags or add text to the name to record information
562 such as that it is a function name. If the name is changed, the macro
563 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
564 #ifdef ENCODE_SECTION_INFO
565 ENCODE_SECTION_INFO (decl);
570 /* ??? Another way to do this would be to do what halfpic.c does
571 and maintain a hashed table of such critters. */
572 /* ??? Another way to do this would be to pass a flag bit to
573 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
574 /* Let the target reassign the RTL if it wants.
575 This is necessary, for example, when one machine specific
576 decl attribute overrides another. */
577 #ifdef REDO_SECTION_INFO_P
578 if (REDO_SECTION_INFO_P (decl))
579 ENCODE_SECTION_INFO (decl);
583 /* Record at least one function has been defined. */
584 function_defined = 1;
587 /* Given NAME, a putative register name, discard any customary prefixes. */
590 strip_reg_name (name)
593 #ifdef REGISTER_PREFIX
594 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
595 name += strlen (REGISTER_PREFIX);
597 if (name[0] == '%' || name[0] == '#')
602 /* Decode an `asm' spec for a declaration as a register name.
603 Return the register number, or -1 if nothing specified,
604 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
605 or -3 if ASMSPEC is `cc' and is not recognized,
606 or -4 if ASMSPEC is `memory' and is not recognized.
607 Accept an exact spelling or a decimal number.
608 Prefixes such as % are optional. */
611 decode_reg_name (asmspec)
618 /* Get rid of confusing prefixes. */
619 asmspec = strip_reg_name (asmspec);
621 /* Allow a decimal number as a "register name". */
622 for (i = strlen (asmspec) - 1; i >= 0; i--)
623 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
625 if (asmspec[0] != 0 && i < 0)
628 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
634 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
636 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
639 #ifdef ADDITIONAL_REGISTER_NAMES
641 static struct { const char *name; int number; } table[]
642 = ADDITIONAL_REGISTER_NAMES;
644 for (i = 0; i < (int)(sizeof (table) / sizeof (table[0])); i++)
645 if (! strcmp (asmspec, table[i].name))
646 return table[i].number;
648 #endif /* ADDITIONAL_REGISTER_NAMES */
650 if (!strcmp (asmspec, "memory"))
653 if (!strcmp (asmspec, "cc"))
662 /* Create the DECL_RTL for a declaration for a static or external variable
663 or static or external function.
664 ASMSPEC, if not 0, is the string which the user specified
665 as the assembler symbol name.
666 TOP_LEVEL is nonzero if this is a file-scope variable.
668 This is never called for PARM_DECL nodes. */
671 make_decl_rtl (decl, asmspec, top_level)
676 register char *name = 0;
679 reg_number = decode_reg_name (asmspec);
681 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
682 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
684 if (reg_number == -2)
686 /* ASMSPEC is given, and not the name of a register. */
687 size_t len = strlen (asmspec);
689 name = ggc_alloc_string (NULL, len + 1);
691 memcpy (&name[1], asmspec, len + 1);
694 /* For a duplicate declaration, we can be called twice on the
695 same DECL node. Don't discard the RTL already made. */
696 if (DECL_RTL (decl) == 0)
698 /* First detect errors in declaring global registers. */
699 if (TREE_CODE (decl) != FUNCTION_DECL
700 && DECL_REGISTER (decl) && reg_number == -1)
701 error_with_decl (decl,
702 "register name not specified for `%s'");
703 else if (TREE_CODE (decl) != FUNCTION_DECL
704 && DECL_REGISTER (decl) && reg_number < 0)
705 error_with_decl (decl,
706 "invalid register name for `%s'");
707 else if ((reg_number >= 0 || reg_number == -3)
708 && (TREE_CODE (decl) == FUNCTION_DECL
709 && ! DECL_REGISTER (decl)))
710 error_with_decl (decl,
711 "register name given for non-register variable `%s'");
712 else if (TREE_CODE (decl) != FUNCTION_DECL
713 && DECL_REGISTER (decl)
714 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
715 error_with_decl (decl,
716 "data type of `%s' isn't suitable for a register");
717 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
718 && ! HARD_REGNO_MODE_OK (reg_number,
719 TYPE_MODE (TREE_TYPE (decl))))
720 error_with_decl (decl,
721 "register number for `%s' isn't suitable for data type");
722 /* Now handle properly declared static register variables. */
723 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
727 if (DECL_INITIAL (decl) != 0 && top_level)
729 DECL_INITIAL (decl) = 0;
730 error ("global register variable has initial value");
732 if (fixed_regs[reg_number] == 0
733 && function_defined && top_level)
734 error ("global register variable follows a function definition");
735 if (TREE_THIS_VOLATILE (decl))
736 warning ("volatile register variables don't work as you might wish");
738 /* If the user specified one of the eliminables registers here,
739 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
740 confused with that register and be eliminated. Although this
741 usage is somewhat suspect, we nevertheless use the following
742 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
745 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
746 REGNO (DECL_RTL (decl)) = reg_number;
747 REG_USERVAR_P (DECL_RTL (decl)) = 1;
751 /* Make this register global, so not usable for anything
753 #ifdef ASM_DECLARE_REGISTER_GLOBAL
754 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
756 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
758 globalize_reg (reg_number + --nregs);
761 /* Specifying a section attribute on a variable forces it into a
762 non-.bss section, and thus it cannot be common. */
763 else if (TREE_CODE (decl) == VAR_DECL
764 && DECL_SECTION_NAME (decl) != NULL_TREE
765 && DECL_INITIAL (decl) == NULL_TREE
766 && DECL_COMMON (decl))
767 DECL_COMMON (decl) = 0;
769 /* Now handle ordinary static variables and functions (in memory).
770 Also handle vars declared register invalidly. */
771 if (DECL_RTL (decl) == 0)
773 /* Can't use just the variable's own name for a variable
774 whose scope is less than the whole file.
775 Concatenate a distinguishing number. */
776 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
780 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
781 name = ggc_alloc_string (label, -1);
788 /* When -fprefix-function-name is used, the functions
789 names are prefixed. Only nested function names are not
791 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
793 size_t name_len = strlen (name);
796 new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
797 memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
798 memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
802 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
803 gen_rtx_SYMBOL_REF (Pmode, name));
804 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
806 /* If this variable is to be treated as volatile, show its
807 tree node has side effects. If it has side effects, either
808 because of this test or from TREE_THIS_VOLATILE also
809 being set, show the MEM is volatile. */
810 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
811 && TREE_PUBLIC (decl))
812 TREE_SIDE_EFFECTS (decl) = 1;
813 else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
814 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
815 TREE_SIDE_EFFECTS (decl) = 1;
817 if (TREE_SIDE_EFFECTS (decl))
818 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
820 if (TREE_READONLY (decl))
821 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
822 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
823 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
825 /* Optionally set flags or add text to the name to record information
826 such as that it is a function name.
827 If the name is changed, the macro ASM_OUTPUT_LABELREF
828 will have to know how to strip this information. */
829 #ifdef ENCODE_SECTION_INFO
830 ENCODE_SECTION_INFO (decl);
836 /* If the old RTL had the wrong mode, fix the mode. */
837 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
839 rtx rtl = DECL_RTL (decl);
840 PUT_MODE (rtl, DECL_MODE (decl));
843 /* ??? Another way to do this would be to do what halfpic.c does
844 and maintain a hashed table of such critters. */
845 /* ??? Another way to do this would be to pass a flag bit to
846 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
847 /* Let the target reassign the RTL if it wants.
848 This is necessary, for example, when one machine specific
849 decl attribute overrides another. */
850 #ifdef REDO_SECTION_INFO_P
851 if (REDO_SECTION_INFO_P (decl))
852 ENCODE_SECTION_INFO (decl);
857 /* Make the rtl for variable VAR be volatile.
858 Use this only for static variables. */
861 make_var_volatile (var)
864 if (GET_CODE (DECL_RTL (var)) != MEM)
867 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
870 /* Output alignment directive to align for constant expression EXP. */
873 assemble_constant_align (exp)
878 /* Align the location counter as required by EXP's data type. */
879 align = TYPE_ALIGN (TREE_TYPE (exp));
880 #ifdef CONSTANT_ALIGNMENT
881 align = CONSTANT_ALIGNMENT (exp, align);
884 if (align > BITS_PER_UNIT)
885 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
888 /* Output a string of literal assembler code
889 for an `asm' keyword used between functions. */
892 assemble_asm (string)
897 if (TREE_CODE (string) == ADDR_EXPR)
898 string = TREE_OPERAND (string, 0);
900 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
903 #if 0 /* This should no longer be needed, because
904 flag_gnu_linker should be 0 on these systems,
905 which should prevent any output
906 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
907 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
908 #ifndef ASM_OUTPUT_CONSTRUCTOR
909 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
911 #ifndef ASM_OUTPUT_DESTRUCTOR
912 #define ASM_OUTPUT_DESTRUCTOR(file, name)
917 /* Record an element in the table of global destructors.
918 How this is done depends on what sort of assembler and linker
921 NAME should be the name of a global function to be called
922 at exit time. This name is output using assemble_name. */
925 assemble_destructor (name)
928 #ifdef ASM_OUTPUT_DESTRUCTOR
929 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
933 /* Now tell GNU LD that this is part of the static destructor set. */
934 /* This code works for any machine provided you use GNU as/ld. */
935 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
936 assemble_name (asm_out_file, name);
937 fputc ('\n', asm_out_file);
942 /* Likewise for global constructors. */
945 assemble_constructor (name)
948 #ifdef ASM_OUTPUT_CONSTRUCTOR
949 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
953 /* Now tell GNU LD that this is part of the static constructor set. */
954 /* This code works for any machine provided you use GNU as/ld. */
955 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
956 assemble_name (asm_out_file, name);
957 fputc ('\n', asm_out_file);
962 /* Likewise for entries we want to record for garbage collection.
963 Garbage collection is still under development. */
966 assemble_gc_entry (name)
969 #ifdef ASM_OUTPUT_GC_ENTRY
970 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
974 /* Now tell GNU LD that this is part of the static constructor set. */
975 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
976 assemble_name (asm_out_file, name);
977 fputc ('\n', asm_out_file);
982 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
983 a non-zero value if the constant pool should be output before the
984 start of the function, or a zero value if the pool should output
985 after the end of the function. The default is to put it before the
988 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
989 #define CONSTANT_POOL_BEFORE_FUNCTION 1
992 /* Output assembler code for the constant pool of a function and associated
993 with defining the name of the function. DECL describes the function.
994 NAME is the function's name. For the constant pool, we use the current
995 constant pool data. */
998 assemble_start_function (decl, fnname)
1004 /* The following code does not need preprocessing in the assembler. */
1008 if (CONSTANT_POOL_BEFORE_FUNCTION)
1009 output_constant_pool (fnname, decl);
1011 #ifdef ASM_OUTPUT_SECTION_NAME
1012 /* If the function is to be put in its own section and it's not in a section
1013 already, indicate so. */
1014 if ((flag_function_sections
1015 && DECL_SECTION_NAME (decl) == NULL_TREE)
1016 || UNIQUE_SECTION_P (decl))
1017 UNIQUE_SECTION (decl, 0);
1020 function_section (decl);
1022 /* Tell assembler to move to target machine's alignment for functions. */
1023 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1025 ASM_OUTPUT_ALIGN (asm_out_file, align);
1027 /* Handle a user-specified function alignment.
1028 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1029 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1030 if (align_functions_log > align)
1032 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1033 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1034 align_functions_log, align_functions-1);
1036 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1040 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1041 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1044 #ifdef SDB_DEBUGGING_INFO
1045 /* Output SDB definition of the function. */
1046 if (write_symbols == SDB_DEBUG)
1047 sdbout_mark_begin_function ();
1050 #ifdef DBX_DEBUGGING_INFO
1051 /* Output DBX definition of the function. */
1052 if (write_symbols == DBX_DEBUG)
1053 dbxout_begin_function (decl);
1056 /* Make function name accessible from other files, if appropriate. */
1058 if (TREE_PUBLIC (decl))
1060 if (! first_global_object_name)
1065 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1066 name = &first_global_object_name;
1068 name = &weak_global_object_name;
1070 STRIP_NAME_ENCODING (p, fnname);
1071 *name = permalloc (strlen (p) + 1);
1075 #ifdef ASM_WEAKEN_LABEL
1076 if (DECL_WEAK (decl))
1078 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1079 /* Remove this function from the pending weak list so that
1080 we do not emit multiple .weak directives for it. */
1081 remove_from_pending_weak_list
1082 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1086 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1089 /* Do any machine/system dependent processing of the function name */
1090 #ifdef ASM_DECLARE_FUNCTION_NAME
1091 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1093 /* Standard thing is just output label for the function. */
1094 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1095 #endif /* ASM_DECLARE_FUNCTION_NAME */
1098 /* Output assembler code associated with defining the size of the
1099 function. DECL describes the function. NAME is the function's name. */
1102 assemble_end_function (decl, fnname)
1106 #ifdef ASM_DECLARE_FUNCTION_SIZE
1107 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1109 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1111 output_constant_pool (fnname, decl);
1112 function_section (decl); /* need to switch back */
1115 /* Output any constants which should appear after the function. */
1116 output_after_function_constants ();
1119 /* Assemble code to leave SIZE bytes of zeros. */
1122 assemble_zeros (size)
1125 /* Do no output if -fsyntax-only. */
1126 if (flag_syntax_only)
1129 #ifdef ASM_NO_SKIP_IN_TEXT
1130 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1131 so we must output 0s explicitly in the text section. */
1132 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1136 for (i = 0; i < size - 20; i += 20)
1139 fprintf (asm_out_file,
1140 "%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);
1142 fprintf (asm_out_file,
1143 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1149 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1151 fprintf (asm_out_file, "\tbyte 0");
1154 for (; i < size; i++)
1155 fprintf (asm_out_file, ",0");
1156 fprintf (asm_out_file, "\n");
1162 ASM_OUTPUT_SKIP (asm_out_file, size);
1165 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1168 assemble_align (align)
1171 if (align > BITS_PER_UNIT)
1172 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1175 /* Assemble a string constant with the specified C string as contents. */
1178 assemble_string (p, size)
1185 /* If the string is very long, split it up. */
1189 int thissize = size - pos;
1190 if (thissize > maximum)
1193 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1201 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1202 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1203 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1205 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1206 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1207 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1209 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1210 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1214 #if defined ASM_OUTPUT_ALIGNED_BSS
1215 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1216 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1218 #if defined ASM_OUTPUT_BSS
1219 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1220 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1226 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1227 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1228 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1230 #if defined ASM_OUTPUT_ALIGNED_COMMON
1231 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1232 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1234 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1235 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1240 asm_emit_uninitialised (decl, name, size, rounded)
1244 int rounded ATTRIBUTE_UNUSED;
1251 destination = asm_dest_local;
1253 if (TREE_PUBLIC (decl))
1255 #if defined ASM_EMIT_BSS
1256 if (! DECL_COMMON (decl))
1257 destination = asm_dest_bss;
1260 destination = asm_dest_common;
1263 if (flag_shared_data)
1265 switch (destination)
1267 #ifdef ASM_OUTPUT_SHARED_BSS
1269 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1272 #ifdef ASM_OUTPUT_SHARED_COMMON
1273 case asm_dest_common:
1274 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1277 #ifdef ASM_OUTPUT_SHARED_LOCAL
1278 case asm_dest_local:
1279 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1287 switch (destination)
1291 ASM_EMIT_BSS (decl, name, size, rounded);
1294 case asm_dest_common:
1295 ASM_EMIT_COMMON (decl, name, size, rounded);
1297 case asm_dest_local:
1298 ASM_EMIT_LOCAL (decl, name, size, rounded);
1307 /* Assemble everything that is needed for a variable or function declaration.
1308 Not used for automatic variables, and not used for function definitions.
1309 Should not be called for variables of incomplete structure type.
1311 TOP_LEVEL is nonzero if this variable has file scope.
1312 AT_END is nonzero if this is the special handling, at end of compilation,
1313 to define things that have had only tentative definitions.
1314 DONT_OUTPUT_DATA if nonzero means don't actually output the
1315 initial value (that will be done by the caller). */
1318 assemble_variable (decl, top_level, at_end, dont_output_data)
1320 int top_level ATTRIBUTE_UNUSED;
1321 int at_end ATTRIBUTE_UNUSED;
1322 int dont_output_data;
1324 register char *name;
1326 tree size_tree = NULL_TREE;
1328 enum in_section saved_in_section;
1330 last_assemble_variable_decl = 0;
1332 if (GET_CODE (DECL_RTL (decl)) == REG)
1334 /* Do output symbol info for global register variables, but do nothing
1337 if (TREE_ASM_WRITTEN (decl))
1339 TREE_ASM_WRITTEN (decl) = 1;
1341 /* Do no output if -fsyntax-only. */
1342 if (flag_syntax_only)
1345 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1346 /* File-scope global variables are output here. */
1347 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1349 dbxout_symbol (decl, 0);
1351 #ifdef SDB_DEBUGGING_INFO
1352 if (write_symbols == SDB_DEBUG && top_level
1353 /* Leave initialized global vars for end of compilation;
1354 see comment in compile_file. */
1355 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1356 sdbout_symbol (decl, 0);
1359 /* Don't output any DWARF debugging information for variables here.
1360 In the case of local variables, the information for them is output
1361 when we do our recursive traversal of the tree representation for
1362 the entire containing function. In the case of file-scope variables,
1363 we output information for all of them at the very end of compilation
1364 while we are doing our final traversal of the chain of file-scope
1370 /* Normally no need to say anything here for external references,
1371 since assemble_external is called by the language-specific code
1372 when a declaration is first seen. */
1374 if (DECL_EXTERNAL (decl))
1377 /* Output no assembler code for a function declaration.
1378 Only definitions of functions output anything. */
1380 if (TREE_CODE (decl) == FUNCTION_DECL)
1383 /* If type was incomplete when the variable was declared,
1384 see if it is complete now. */
1386 if (DECL_SIZE (decl) == 0)
1387 layout_decl (decl, 0);
1389 /* Still incomplete => don't allocate it; treat the tentative defn
1390 (which is what it must have been) as an `extern' reference. */
1392 if (!dont_output_data && DECL_SIZE (decl) == 0)
1394 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1395 DECL_SOURCE_LINE (decl),
1396 "storage size of `%s' isn't known",
1397 IDENTIFIER_POINTER (DECL_NAME (decl)));
1398 TREE_ASM_WRITTEN (decl) = 1;
1402 /* The first declaration of a variable that comes through this function
1403 decides whether it is global (in C, has external linkage)
1404 or local (in C, has internal linkage). So do nothing more
1405 if this function has already run. */
1407 if (TREE_ASM_WRITTEN (decl))
1410 TREE_ASM_WRITTEN (decl) = 1;
1412 /* Do no output if -fsyntax-only. */
1413 if (flag_syntax_only)
1418 if (! dont_output_data)
1422 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1425 /* This is better than explicit arithmetic, since it avoids overflow. */
1426 size_tree = size_binop (CEIL_DIV_EXPR,
1427 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1429 size = TREE_INT_CST_LOW (size_tree);
1430 if (TREE_INT_CST_HIGH (size_tree) != 0
1431 || size != TREE_INT_CST_LOW (size_tree))
1433 error_with_decl (decl, "size of variable `%s' is too large");
1438 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1440 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1441 && ! first_global_object_name
1442 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1443 || DECL_INITIAL (decl) == error_mark_node))
1444 && ! DECL_WEAK (decl)
1445 && ! DECL_ONE_ONLY (decl))
1449 STRIP_NAME_ENCODING (p, name);
1450 first_global_object_name = permalloc (strlen (p) + 1);
1451 strcpy (first_global_object_name, p);
1454 /* Compute the alignment of this data. */
1456 align = DECL_ALIGN (decl);
1458 /* In the case for initialing an array whose length isn't specified,
1459 where we have not yet been able to do the layout,
1460 figure out the proper alignment now. */
1461 if (dont_output_data && DECL_SIZE (decl) == 0
1462 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1463 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1465 /* Some object file formats have a maximum alignment which they support.
1466 In particular, a.out format supports a maximum alignment of 4. */
1467 #ifndef MAX_OFILE_ALIGNMENT
1468 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1470 if (align > MAX_OFILE_ALIGNMENT)
1472 warning_with_decl (decl,
1473 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1474 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1475 align = MAX_OFILE_ALIGNMENT;
1478 /* On some machines, it is good to increase alignment sometimes. */
1479 #ifdef DATA_ALIGNMENT
1480 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1482 #ifdef CONSTANT_ALIGNMENT
1483 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1484 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1487 /* Reset the alignment in case we have made it tighter, so we can benefit
1488 from it in get_pointer_alignment. */
1489 DECL_ALIGN (decl) = align;
1491 /* Handle uninitialized definitions. */
1493 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1494 /* If the target can't output uninitialized but not common global data
1495 in .bss, then we have to use .data. */
1496 #if ! defined ASM_EMIT_BSS
1497 && DECL_COMMON (decl)
1499 && DECL_SECTION_NAME (decl) == 0
1500 && ! dont_output_data)
1502 int size = TREE_INT_CST_LOW (size_tree);
1505 /* Don't allocate zero bytes of common,
1506 since that means "undefined external" in the linker. */
1507 if (size == 0) rounded = 1;
1508 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1509 so that each uninitialized object starts on such a boundary. */
1510 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1511 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1512 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1514 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1515 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1517 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1520 #ifdef DBX_DEBUGGING_INFO
1521 /* File-scope global variables are output here. */
1522 if (write_symbols == DBX_DEBUG && top_level)
1523 dbxout_symbol (decl, 0);
1525 #ifdef SDB_DEBUGGING_INFO
1526 if (write_symbols == SDB_DEBUG && top_level
1527 /* Leave initialized global vars for end of compilation;
1528 see comment in compile_file. */
1529 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1530 sdbout_symbol (decl, 0);
1533 /* Don't output any DWARF debugging information for variables here.
1534 In the case of local variables, the information for them is output
1535 when we do our recursive traversal of the tree representation for
1536 the entire containing function. In the case of file-scope variables,
1537 we output information for all of them at the very end of compilation
1538 while we are doing our final traversal of the chain of file-scope
1541 #if 0 /* ??? We should either delete this or add a comment describing what
1542 it was intended to do and why we shouldn't delete it. */
1543 if (flag_shared_data)
1546 asm_emit_uninitialised (decl, name, size, rounded);
1551 /* Handle initialized definitions.
1552 Also handle uninitialized global definitions if -fno-common and the
1553 target doesn't support ASM_OUTPUT_BSS. */
1555 /* First make the assembler name(s) global if appropriate. */
1556 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1558 #ifdef ASM_WEAKEN_LABEL
1559 if (DECL_WEAK (decl))
1561 ASM_WEAKEN_LABEL (asm_out_file, name);
1562 /* Remove this variable from the pending weak list so that
1563 we do not emit multiple .weak directives for it. */
1564 remove_from_pending_weak_list
1565 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1569 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1572 for (d = equivalents; d; d = TREE_CHAIN (d))
1574 tree e = TREE_VALUE (d);
1575 if (TREE_PUBLIC (e) && DECL_NAME (e))
1576 ASM_GLOBALIZE_LABEL (asm_out_file,
1577 XSTR (XEXP (DECL_RTL (e), 0), 0));
1581 /* Output any data that we will need to use the address of. */
1582 if (DECL_INITIAL (decl) == error_mark_node)
1583 reloc = contains_pointers_p (TREE_TYPE (decl));
1584 else if (DECL_INITIAL (decl))
1585 reloc = output_addressed_constants (DECL_INITIAL (decl));
1587 #ifdef ASM_OUTPUT_SECTION_NAME
1588 if ((flag_data_sections != 0
1589 && DECL_SECTION_NAME (decl) == NULL_TREE)
1590 || UNIQUE_SECTION_P (decl))
1591 UNIQUE_SECTION (decl, reloc);
1594 /* Switch to the appropriate section. */
1595 variable_section (decl, reloc);
1597 /* dbxout.c needs to know this. */
1598 if (in_text_section ())
1599 DECL_IN_TEXT_SECTION (decl) = 1;
1601 /* Record current section so we can restore it if dbxout.c clobbers it. */
1602 saved_in_section = in_section;
1604 /* Output the dbx info now that we have chosen the section. */
1606 #ifdef DBX_DEBUGGING_INFO
1607 /* File-scope global variables are output here. */
1608 if (write_symbols == DBX_DEBUG && top_level)
1609 dbxout_symbol (decl, 0);
1611 #ifdef SDB_DEBUGGING_INFO
1612 if (write_symbols == SDB_DEBUG && top_level
1613 /* Leave initialized global vars for end of compilation;
1614 see comment in compile_file. */
1615 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1616 sdbout_symbol (decl, 0);
1619 /* Don't output any DWARF debugging information for variables here.
1620 In the case of local variables, the information for them is output
1621 when we do our recursive traversal of the tree representation for
1622 the entire containing function. In the case of file-scope variables,
1623 we output information for all of them at the very end of compilation
1624 while we are doing our final traversal of the chain of file-scope
1627 /* If the debugging output changed sections, reselect the section
1628 that's supposed to be selected. */
1629 if (in_section != saved_in_section)
1630 variable_section (decl, reloc);
1632 /* Output the alignment of this data. */
1633 if (align > BITS_PER_UNIT)
1634 ASM_OUTPUT_ALIGN (asm_out_file,
1635 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1637 /* Do any machine/system dependent processing of the object. */
1638 #ifdef ASM_DECLARE_OBJECT_NAME
1639 last_assemble_variable_decl = decl;
1640 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1642 /* Standard thing is just output label for the object. */
1643 ASM_OUTPUT_LABEL (asm_out_file, name);
1644 #endif /* ASM_DECLARE_OBJECT_NAME */
1646 if (!dont_output_data)
1648 if (DECL_INITIAL (decl))
1649 /* Output the actual data. */
1650 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1652 /* Leave space for it. */
1653 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1657 #ifdef XCOFF_DEBUGGING_INFO
1658 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1659 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1660 and `aa' hasn't been output yet, the assembler generates a stab entry with
1661 a value of zero, in addition to creating an unnecessary external entry
1662 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1664 /* File-scope global variables are output here. */
1665 if (write_symbols == XCOFF_DEBUG && top_level)
1667 saved_in_section = in_section;
1669 dbxout_symbol (decl, 0);
1671 if (in_section != saved_in_section)
1672 variable_section (decl, reloc);
1675 /* There must be a statement after a label. */
1680 /* Return 1 if type TYPE contains any pointers. */
1683 contains_pointers_p (type)
1686 switch (TREE_CODE (type))
1689 case REFERENCE_TYPE:
1690 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1691 so I'll play safe and return 1. */
1697 case QUAL_UNION_TYPE:
1700 /* For a type that has fields, see if the fields have pointers. */
1701 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1702 if (TREE_CODE (fields) == FIELD_DECL
1703 && contains_pointers_p (TREE_TYPE (fields)))
1709 /* An array type contains pointers if its element type does. */
1710 return contains_pointers_p (TREE_TYPE (type));
1717 /* Output something to declare an external symbol to the assembler.
1718 (Most assemblers don't need this, so we normally output nothing.)
1719 Do nothing if DECL is not external. */
1722 assemble_external (decl)
1723 tree decl ATTRIBUTE_UNUSED;
1725 #ifdef ASM_OUTPUT_EXTERNAL
1726 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1727 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1729 rtx rtl = DECL_RTL (decl);
1731 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1732 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1734 /* Some systems do require some output. */
1735 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1736 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1742 /* Similar, for calling a library function FUN. */
1745 assemble_external_libcall (fun)
1746 rtx fun ATTRIBUTE_UNUSED;
1748 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1749 /* Declare library function name external when first used, if nec. */
1750 if (! SYMBOL_REF_USED (fun))
1752 SYMBOL_REF_USED (fun) = 1;
1753 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1758 /* Declare the label NAME global. */
1761 assemble_global (name)
1764 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1767 /* Assemble a label named NAME. */
1770 assemble_label (name)
1773 ASM_OUTPUT_LABEL (asm_out_file, name);
1776 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1777 If NAME starts with a *, the rest of NAME is output verbatim.
1778 Otherwise NAME is transformed in an implementation-defined way
1779 (usually by the addition of an underscore).
1780 Many macros in the tm file are defined to call this function. */
1783 assemble_name (file, name)
1787 const char *real_name;
1790 STRIP_NAME_ENCODING (real_name, name);
1791 if (flag_prefix_function_name
1792 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1793 real_name = real_name + CHKR_PREFIX_SIZE;
1795 id = maybe_get_identifier (real_name);
1797 TREE_SYMBOL_REFERENCED (id) = 1;
1800 fputs (&name[1], file);
1802 ASM_OUTPUT_LABELREF (file, name);
1805 /* Allocate SIZE bytes writable static space with a gensym name
1806 and return an RTX to refer to its address. */
1809 assemble_static_space (size)
1817 if (flag_shared_data)
1821 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1823 namestring = ggc_alloc_string (name, -1);
1825 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1827 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1828 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1831 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1832 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1835 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1836 so that each uninitialized object starts on such a boundary. */
1837 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1838 int rounded ATTRIBUTE_UNUSED
1839 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1840 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1841 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1842 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1849 /* Assemble the static constant template for function entry trampolines.
1850 This is done at most once per compilation.
1851 Returns an RTX for the address of the template. */
1853 #ifdef TRAMPOLINE_TEMPLATE
1855 assemble_trampoline_template ()
1861 /* By default, put trampoline templates in read-only data section. */
1863 #ifdef TRAMPOLINE_SECTION
1864 TRAMPOLINE_SECTION ();
1866 readonly_data_section ();
1869 /* Write the assembler code to define one. */
1870 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1872 ASM_OUTPUT_ALIGN (asm_out_file, align);
1874 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1875 TRAMPOLINE_TEMPLATE (asm_out_file);
1877 /* Record the rtl to refer to it. */
1878 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1879 name = ggc_alloc_string (label, -1);
1880 return gen_rtx_SYMBOL_REF (Pmode, name);
1884 /* Assemble the integer constant X into an object of SIZE bytes.
1885 X must be either a CONST_INT or CONST_DOUBLE.
1887 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1888 non-zero, abort if we can't output the constant. */
1891 assemble_integer (x, size, force)
1896 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1897 ASM_OUTPUT... macros. */
1901 #ifdef ASM_OUTPUT_CHAR
1903 ASM_OUTPUT_CHAR (asm_out_file, x);
1907 #ifdef ASM_OUTPUT_SHORT
1909 ASM_OUTPUT_SHORT (asm_out_file, x);
1913 #ifdef ASM_OUTPUT_INT
1915 ASM_OUTPUT_INT (asm_out_file, x);
1919 #ifdef ASM_OUTPUT_DOUBLE_INT
1921 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1925 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1927 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1932 /* If we couldn't do it that way, there are two other possibilities: First,
1933 if the machine can output an explicit byte and this is a 1 byte constant,
1934 we can use ASM_OUTPUT_BYTE. */
1936 #ifdef ASM_OUTPUT_BYTE
1937 if (size == 1 && GET_CODE (x) == CONST_INT)
1939 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1944 /* Finally, if SIZE is larger than a single word, try to output the constant
1945 one word at a time. */
1947 if (size > UNITS_PER_WORD)
1950 enum machine_mode mode
1951 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1954 for (i = 0; i < size / UNITS_PER_WORD; i++)
1956 word = operand_subword (x, i, 0, mode);
1961 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1965 if (i == size / UNITS_PER_WORD)
1967 /* If we output at least one word and then could not finish,
1968 there is no valid way to continue. */
1979 /* Assemble the floating-point constant D into an object of size MODE. */
1982 assemble_real (d, mode)
1984 enum machine_mode mode;
1986 jmp_buf output_constant_handler;
1988 if (setjmp (output_constant_handler))
1990 error ("floating point trap outputting a constant");
1991 #ifdef REAL_IS_NOT_DOUBLE
1992 bzero ((char *) &d, sizeof d);
1999 set_float_handler (output_constant_handler);
2003 #ifdef ASM_OUTPUT_BYTE_FLOAT
2005 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
2008 #ifdef ASM_OUTPUT_SHORT_FLOAT
2010 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
2013 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2015 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
2018 #ifdef ASM_OUTPUT_FLOAT
2020 ASM_OUTPUT_FLOAT (asm_out_file, d);
2024 #ifdef ASM_OUTPUT_DOUBLE
2026 ASM_OUTPUT_DOUBLE (asm_out_file, d);
2030 #ifdef ASM_OUTPUT_LONG_DOUBLE
2033 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
2041 set_float_handler (NULL_PTR);
2044 /* Here we combine duplicate floating constants to make
2045 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2047 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2048 For an integer, I0 is the low-order word and I1 is the high-order word.
2049 For a real number, I0 is the word with the low address
2050 and I1 is the word with the high address. */
2053 immed_double_const (i0, i1, mode)
2054 HOST_WIDE_INT i0, i1;
2055 enum machine_mode mode;
2059 if (GET_MODE_CLASS (mode) == MODE_INT
2060 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2062 /* We clear out all bits that don't belong in MODE, unless they and our
2063 sign bit are all one. So we get either a reasonable negative value
2064 or a reasonable unsigned value for this mode. */
2065 int width = GET_MODE_BITSIZE (mode);
2066 if (width < HOST_BITS_PER_WIDE_INT
2067 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2068 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2069 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2070 else if (width == HOST_BITS_PER_WIDE_INT
2071 && ! (i1 == ~0 && i0 < 0))
2073 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2074 /* We cannot represent this value as a constant. */
2077 /* If this would be an entire word for the target, but is not for
2078 the host, then sign-extend on the host so that the number will look
2079 the same way on the host that it would on the target.
2081 For example, when building a 64 bit alpha hosted 32 bit sparc
2082 targeted compiler, then we want the 32 bit unsigned value -1 to be
2083 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2084 The later confuses the sparc backend. */
2086 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2087 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2088 i0 |= ((HOST_WIDE_INT) (-1) << width);
2090 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2092 ??? Strictly speaking, this is wrong if we create a CONST_INT
2093 for a large unsigned constant with the size of MODE being
2094 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2095 wider mode. In that case we will mis-interpret it as a negative
2098 Unfortunately, the only alternative is to make a CONST_DOUBLE
2099 for any constant in any mode if it is an unsigned constant larger
2100 than the maximum signed integer in an int on the host. However,
2101 doing this will break everyone that always expects to see a CONST_INT
2102 for SImode and smaller.
2104 We have always been making CONST_INTs in this case, so nothing new
2107 if (width <= HOST_BITS_PER_WIDE_INT)
2108 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2110 /* If this integer fits in one word, return a CONST_INT. */
2111 if ((i1 == 0 && i0 >= 0)
2112 || (i1 == ~0 && i0 < 0))
2113 return GEN_INT (i0);
2115 /* We use VOIDmode for integers. */
2119 /* Search the chain for an existing CONST_DOUBLE with the right value.
2120 If one is found, return it. */
2121 if (current_function != 0)
2122 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2123 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2124 && GET_MODE (r) == mode)
2127 /* No; make a new one and add it to the chain.
2129 We may be called by an optimizer which may be discarding any memory
2130 allocated during its processing (such as combine and loop). However,
2131 we will be leaving this constant on the chain, so we cannot tolerate
2132 freed memory. So switch to saveable_obstack for this allocation
2133 and then switch back if we were in current_obstack. */
2135 push_obstacks_nochange ();
2136 rtl_in_saveable_obstack ();
2137 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2140 /* Don't touch const_double_chain if not inside any function. */
2141 if (current_function_decl != 0)
2143 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2144 const_double_chain = r;
2147 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2148 Actual use of mem-slot is only through force_const_mem. */
2150 CONST_DOUBLE_MEM (r) = const0_rtx;
2155 /* Return a CONST_DOUBLE for a specified `double' value
2156 and machine mode. */
2159 immed_real_const_1 (d, mode)
2161 enum machine_mode mode;
2163 union real_extract u;
2166 /* Get the desired `double' value as a sequence of ints
2167 since that is how they are stored in a CONST_DOUBLE. */
2171 /* Detect special cases. */
2173 if (REAL_VALUES_IDENTICAL (dconst0, d))
2174 return CONST0_RTX (mode);
2175 /* Check for NaN first, because some ports (specifically the i386) do not
2176 emit correct ieee-fp code by default, and thus will generate a core
2177 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2178 does a floating point comparison. */
2179 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2180 return CONST1_RTX (mode);
2182 if (sizeof u == sizeof (HOST_WIDE_INT))
2183 return immed_double_const (u.i[0], 0, mode);
2184 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2185 return immed_double_const (u.i[0], u.i[1], mode);
2187 /* The rest of this function handles the case where
2188 a float value requires more than 2 ints of space.
2189 It will be deleted as dead code on machines that don't need it. */
2191 /* Search the chain for an existing CONST_DOUBLE with the right value.
2192 If one is found, return it. */
2193 if (current_function != 0)
2194 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2195 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2196 && GET_MODE (r) == mode)
2199 /* No; make a new one and add it to the chain.
2201 We may be called by an optimizer which may be discarding any memory
2202 allocated during its processing (such as combine and loop). However,
2203 we will be leaving this constant on the chain, so we cannot tolerate
2204 freed memory. So switch to saveable_obstack for this allocation
2205 and then switch back if we were in current_obstack. */
2206 push_obstacks_nochange ();
2207 rtl_in_saveable_obstack ();
2208 r = rtx_alloc (CONST_DOUBLE);
2211 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2213 /* Don't touch const_double_chain if not inside any function. */
2214 if (current_function_decl != 0)
2216 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2217 const_double_chain = r;
2220 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2221 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2222 is only through force_const_mem. */
2224 CONST_DOUBLE_MEM (r) = const0_rtx;
2229 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2230 which must be a REAL_CST tree node. */
2233 immed_real_const (exp)
2236 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2239 /* At the end of a function, forget the memory-constants
2240 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2241 Also clear out real_constant_chain and clear out all the chain-pointers. */
2244 clear_const_double_mem ()
2246 register rtx r, next;
2248 for (r = const_double_chain; r; r = next)
2250 next = CONST_DOUBLE_CHAIN (r);
2251 CONST_DOUBLE_CHAIN (r) = 0;
2252 CONST_DOUBLE_MEM (r) = cc0_rtx;
2254 const_double_chain = 0;
2257 /* Given an expression EXP with a constant value,
2258 reduce it to the sum of an assembler symbol and an integer.
2259 Store them both in the structure *VALUE.
2260 Abort if EXP does not reduce. */
2265 HOST_WIDE_INT offset;
2269 decode_addr_const (exp, value)
2271 struct addr_const *value;
2273 register tree target = TREE_OPERAND (exp, 0);
2274 register int offset = 0;
2279 if (TREE_CODE (target) == COMPONENT_REF
2280 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2283 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2284 target = TREE_OPERAND (target, 0);
2286 else if (TREE_CODE (target) == ARRAY_REF)
2288 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2289 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2291 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2292 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2294 target = TREE_OPERAND (target, 0);
2300 switch (TREE_CODE (target))
2304 x = DECL_RTL (target);
2308 x = gen_rtx_MEM (FUNCTION_MODE,
2309 gen_rtx_LABEL_REF (VOIDmode,
2310 label_rtx (TREE_OPERAND (exp, 0))));
2318 x = TREE_CST_RTL (target);
2325 if (GET_CODE (x) != MEM)
2330 value->offset = offset;
2333 /* Uniquize all constants that appear in memory.
2334 Each constant in memory thus far output is recorded
2335 in `const_hash_table' with a `struct constant_descriptor'
2336 that contains a polish representation of the value of
2339 We cannot store the trees in the hash table
2340 because the trees may be temporary. */
2342 struct constant_descriptor
2344 struct constant_descriptor *next;
2351 #define MAX_HASH_TABLE 1009
2352 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2354 /* Mark a const_hash_table descriptor for GC. */
2357 mark_const_hash_entry (ptr)
2360 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2364 ggc_mark_string (desc->label);
2365 ggc_mark_rtx (desc->rtl);
2370 /* Compute a hash code for a constant expression. */
2377 register int len, hi, i;
2378 register enum tree_code code = TREE_CODE (exp);
2380 /* Either set P and LEN to the address and len of something to hash and
2381 exit the switch or return a value. */
2386 p = (char *) &TREE_INT_CST_LOW (exp);
2387 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2391 p = (char *) &TREE_REAL_CST (exp);
2392 len = sizeof TREE_REAL_CST (exp);
2396 p = TREE_STRING_POINTER (exp);
2397 len = TREE_STRING_LENGTH (exp);
2401 return (const_hash (TREE_REALPART (exp)) * 5
2402 + const_hash (TREE_IMAGPART (exp)));
2405 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2407 len = int_size_in_bytes (TREE_TYPE (exp));
2408 p = (char *) alloca (len);
2409 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2416 /* For record type, include the type in the hashing.
2417 We do not do so for array types
2418 because (1) the sizes of the elements are sufficient
2419 and (2) distinct array types can have the same constructor.
2420 Instead, we include the array size because the constructor could
2422 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2423 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2426 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2427 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2429 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2430 if (TREE_VALUE (link))
2432 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2439 struct addr_const value;
2441 decode_addr_const (exp, &value);
2442 if (GET_CODE (value.base) == SYMBOL_REF)
2444 /* Don't hash the address of the SYMBOL_REF;
2445 only use the offset and the symbol name. */
2447 p = XSTR (value.base, 0);
2448 for (i = 0; p[i] != 0; i++)
2449 hi = ((hi * 613) + (unsigned) (p[i]));
2451 else if (GET_CODE (value.base) == LABEL_REF)
2452 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2456 hi &= (1 << HASHBITS) - 1;
2457 hi %= MAX_HASH_TABLE;
2463 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2464 + const_hash (TREE_OPERAND (exp, 1)));
2468 case NON_LVALUE_EXPR:
2469 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2475 /* Compute hashing function */
2477 for (i = 0; i < len; i++)
2478 hi = ((hi * 613) + (unsigned) (p[i]));
2480 hi &= (1 << HASHBITS) - 1;
2481 hi %= MAX_HASH_TABLE;
2485 /* Compare a constant expression EXP with a constant-descriptor DESC.
2486 Return 1 if DESC describes a constant with the same value as EXP. */
2489 compare_constant (exp, desc)
2491 struct constant_descriptor *desc;
2493 return 0 != compare_constant_1 (exp, desc->contents);
2496 /* Compare constant expression EXP with a substring P of a constant descriptor.
2497 If they match, return a pointer to the end of the substring matched.
2498 If they do not match, return 0.
2500 Since descriptors are written in polish prefix notation,
2501 this function can be used recursively to test one operand of EXP
2502 against a subdescriptor, and if it succeeds it returns the
2503 address of the subdescriptor for the next operand. */
2506 compare_constant_1 (exp, p)
2510 register char *strp;
2512 register enum tree_code code = TREE_CODE (exp);
2514 if (code != (enum tree_code) *p++)
2517 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2518 switch, or return the result of the comparison. */
2523 /* Integer constants are the same only if the same width of type. */
2524 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2527 strp = (char *) &TREE_INT_CST_LOW (exp);
2528 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2532 /* Real constants are the same only if the same width of type. */
2533 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2536 strp = (char *) &TREE_REAL_CST (exp);
2537 len = sizeof TREE_REAL_CST (exp);
2541 if (flag_writable_strings)
2544 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2547 strp = TREE_STRING_POINTER (exp);
2548 len = TREE_STRING_LENGTH (exp);
2549 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2550 sizeof TREE_STRING_LENGTH (exp)))
2553 p += sizeof TREE_STRING_LENGTH (exp);
2557 p = compare_constant_1 (TREE_REALPART (exp), p);
2561 return compare_constant_1 (TREE_IMAGPART (exp), p);
2564 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2566 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2568 strp = (char *) alloca (len);
2569 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2570 if (bcmp ((char *) &xlen, p, sizeof xlen))
2579 int length = list_length (CONSTRUCTOR_ELTS (exp));
2581 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2582 int have_purpose = 0;
2584 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2585 if (TREE_PURPOSE (link))
2588 if (bcmp ((char *) &length, p, sizeof length))
2593 /* For record constructors, insist that the types match.
2594 For arrays, just verify both constructors are for arrays.
2595 Then insist that either both or none have any TREE_PURPOSE
2597 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2598 type = TREE_TYPE (exp);
2602 if (bcmp ((char *) &type, p, sizeof type))
2605 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2607 if (bcmp ((char *) &mode, p, sizeof mode))
2615 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2618 p += sizeof have_purpose;
2620 /* For arrays, insist that the size in bytes match. */
2621 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2623 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2625 if (bcmp ((char *) &size, p, sizeof size))
2631 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2633 if (TREE_VALUE (link))
2635 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2642 if (bcmp ((char *) &zero, p, sizeof zero))
2648 if (TREE_PURPOSE (link)
2649 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2651 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2652 sizeof TREE_PURPOSE (link)))
2655 p += sizeof TREE_PURPOSE (link);
2657 else if (TREE_PURPOSE (link))
2659 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2662 else if (have_purpose)
2666 if (bcmp ((char *) &zero, p, sizeof zero))
2678 struct addr_const value;
2680 decode_addr_const (exp, &value);
2681 strp = (char *) &value.offset;
2682 len = sizeof value.offset;
2683 /* Compare the offset. */
2685 if (*p++ != *strp++)
2688 /* Compare symbol name. */
2689 strp = XSTR (value.base, 0);
2690 len = strlen (strp) + 1;
2697 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2701 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2705 case NON_LVALUE_EXPR:
2706 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2712 /* Compare constant contents. */
2714 if (*p++ != *strp++)
2720 /* Construct a constant descriptor for the expression EXP.
2721 It is up to the caller to enter the descriptor in the hash table. */
2723 static struct constant_descriptor *
2724 record_constant (exp)
2727 struct constant_descriptor *next = 0;
2731 /* Make a struct constant_descriptor. The first three pointers will
2732 be filled in later. Here we just leave space for them. */
2734 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2735 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2736 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2737 record_constant_1 (exp);
2738 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2741 /* Add a description of constant expression EXP
2742 to the object growing in `permanent_obstack'.
2743 No need to return its address; the caller will get that
2744 from the obstack when the object is complete. */
2747 record_constant_1 (exp)
2750 register char *strp;
2752 register enum tree_code code = TREE_CODE (exp);
2754 obstack_1grow (&permanent_obstack, (unsigned int) code);
2759 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2760 strp = (char *) &TREE_INT_CST_LOW (exp);
2761 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2765 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2766 strp = (char *) &TREE_REAL_CST (exp);
2767 len = sizeof TREE_REAL_CST (exp);
2771 if (flag_writable_strings)
2774 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2775 strp = TREE_STRING_POINTER (exp);
2776 len = TREE_STRING_LENGTH (exp);
2777 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2778 sizeof TREE_STRING_LENGTH (exp));
2782 record_constant_1 (TREE_REALPART (exp));
2783 record_constant_1 (TREE_IMAGPART (exp));
2787 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2789 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2790 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2791 obstack_blank (&permanent_obstack, nbytes);
2792 get_set_constructor_bytes
2793 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2800 int length = list_length (CONSTRUCTOR_ELTS (exp));
2801 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2803 int have_purpose = 0;
2805 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2806 if (TREE_PURPOSE (link))
2809 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2811 /* For record constructors, insist that the types match.
2812 For arrays, just verify both constructors are for arrays
2813 of the same mode. Then insist that either both or none
2814 have any TREE_PURPOSE values. */
2815 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2816 type = TREE_TYPE (exp);
2820 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2821 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2822 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2824 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2825 sizeof have_purpose);
2827 /* For arrays, insist that the size in bytes match. */
2828 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2830 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2831 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2834 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2836 if (TREE_VALUE (link))
2837 record_constant_1 (TREE_VALUE (link));
2842 obstack_grow (&permanent_obstack,
2843 (char *) &zero, sizeof zero);
2846 if (TREE_PURPOSE (link)
2847 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2848 obstack_grow (&permanent_obstack,
2849 (char *) &TREE_PURPOSE (link),
2850 sizeof TREE_PURPOSE (link));
2851 else if (TREE_PURPOSE (link))
2852 record_constant_1 (TREE_PURPOSE (link));
2853 else if (have_purpose)
2857 obstack_grow (&permanent_obstack,
2858 (char *) &zero, sizeof zero);
2866 struct addr_const value;
2868 decode_addr_const (exp, &value);
2869 /* Record the offset. */
2870 obstack_grow (&permanent_obstack,
2871 (char *) &value.offset, sizeof value.offset);
2872 /* Record the symbol name. */
2873 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2874 strlen (XSTR (value.base, 0)) + 1);
2881 record_constant_1 (TREE_OPERAND (exp, 0));
2882 record_constant_1 (TREE_OPERAND (exp, 1));
2887 case NON_LVALUE_EXPR:
2888 record_constant_1 (TREE_OPERAND (exp, 0));
2895 /* Record constant contents. */
2896 obstack_grow (&permanent_obstack, strp, len);
2899 /* Record a list of constant expressions that were passed to
2900 output_constant_def but that could not be output right away. */
2902 struct deferred_constant
2904 struct deferred_constant *next;
2910 static struct deferred_constant *deferred_constants;
2912 /* Another list of constants which should be output after the
2914 static struct deferred_constant *after_function_constants;
2916 /* Nonzero means defer output of addressed subconstants
2917 (i.e., those for which output_constant_def is called.) */
2918 static int defer_addressed_constants_flag;
2920 /* Start deferring output of subconstants. */
2923 defer_addressed_constants ()
2925 defer_addressed_constants_flag++;
2928 /* Stop deferring output of subconstants,
2929 and output now all those that have been deferred. */
2932 output_deferred_addressed_constants ()
2934 struct deferred_constant *p, *next;
2936 defer_addressed_constants_flag--;
2938 if (defer_addressed_constants_flag > 0)
2941 for (p = deferred_constants; p; p = next)
2943 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2948 deferred_constants = 0;
2951 /* Output any constants which should appear after a function. */
2954 output_after_function_constants ()
2956 struct deferred_constant *p, *next;
2958 for (p = after_function_constants; p; p = next)
2960 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2965 after_function_constants = 0;
2968 /* Make a copy of the whole tree structure for a constant.
2969 This handles the same types of nodes that compare_constant
2970 and record_constant handle. */
2976 switch (TREE_CODE (exp))
2979 /* For ADDR_EXPR, we do not want to copy the decl whose address
2980 is requested. We do want to copy constants though. */
2981 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2982 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2983 copy_constant (TREE_OPERAND (exp, 0)));
2985 return copy_node (exp);
2990 return copy_node (exp);
2993 return build_complex (TREE_TYPE (exp),
2994 copy_constant (TREE_REALPART (exp)),
2995 copy_constant (TREE_IMAGPART (exp)));
2999 return build (TREE_CODE (exp), TREE_TYPE (exp),
3000 copy_constant (TREE_OPERAND (exp, 0)),
3001 copy_constant (TREE_OPERAND (exp, 1)));
3005 case NON_LVALUE_EXPR:
3006 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3007 copy_constant (TREE_OPERAND (exp, 0)));
3011 tree copy = copy_node (exp);
3012 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3015 CONSTRUCTOR_ELTS (copy) = list;
3016 for (tail = list; tail; tail = TREE_CHAIN (tail))
3017 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3018 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3019 for (tail = list; tail; tail = TREE_CHAIN (tail))
3020 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3030 /* Return an rtx representing a reference to constant data in memory
3031 for the constant expression EXP.
3033 If assembler code for such a constant has already been output,
3034 return an rtx to refer to it.
3035 Otherwise, output such a constant in memory (or defer it for later)
3036 and generate an rtx for it.
3038 The TREE_CST_RTL of EXP is set up to point to that rtx.
3039 The const_hash_table records which constants already have label strings. */
3042 output_constant_def (exp)
3046 register struct constant_descriptor *desc;
3051 if (TREE_CST_RTL (exp))
3052 return TREE_CST_RTL (exp);
3054 /* Make sure any other constants whose addresses appear in EXP
3055 are assigned label numbers. */
3057 reloc = output_addressed_constants (exp);
3059 /* Compute hash code of EXP. Search the descriptors for that hash code
3060 to see if any of them describes EXP. If yes, the descriptor records
3061 the label number already assigned. */
3063 hash = const_hash (exp) % MAX_HASH_TABLE;
3065 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3066 if (compare_constant (exp, desc))
3071 /* No constant equal to EXP is known to have been output.
3072 Make a constant descriptor to enter EXP in the hash table.
3073 Assign the label number and record it in the descriptor for
3074 future calls to this function to find. */
3076 /* Create a string containing the label name, in LABEL. */
3077 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3079 desc = record_constant (exp);
3080 desc->next = const_hash_table[hash];
3081 desc->label = ggc_alloc_string (label, -1);
3082 const_hash_table[hash] = desc;
3084 /* We have a symbol name; construct the SYMBOL_REF and the MEM
3085 in the permanent obstack. We could also construct this in the
3086 obstack of EXP and put it into TREE_CST_RTL, but we have no way
3087 of knowing what obstack it is (e.g., it might be in a function
3088 obstack of a function we are nested inside). */
3090 push_obstacks_nochange ();
3091 end_temporary_allocation ();
3094 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3095 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3097 RTX_UNCHANGING_P (desc->rtl) = 1;
3098 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
3099 MEM_SET_IN_STRUCT_P (desc->rtl, 1);
3106 TREE_CST_RTL (exp) = desc->rtl;
3108 /* Optionally set flags or add text to the name to record information
3109 such as that it is a function name. If the name is changed, the macro
3110 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3111 #ifdef ENCODE_SECTION_INFO
3112 ENCODE_SECTION_INFO (exp);
3115 /* If this is the first time we've seen this particular constant,
3116 output it (or defer its output for later). */
3119 int after_function = 0;
3121 #ifdef CONSTANT_AFTER_FUNCTION_P
3122 if (current_function_decl != 0
3123 && CONSTANT_AFTER_FUNCTION_P (exp))
3127 if (defer_addressed_constants_flag || after_function)
3129 struct deferred_constant *p;
3130 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3132 push_obstacks_nochange ();
3133 suspend_momentary ();
3134 p->exp = copy_constant (exp);
3137 p->labelno = const_labelno++;
3140 p->next = after_function_constants;
3141 after_function_constants = p;
3145 p->next = deferred_constants;
3146 deferred_constants = p;
3151 /* Do no output if -fsyntax-only. */
3152 if (! flag_syntax_only)
3153 output_constant_def_contents (exp, reloc, const_labelno);
3158 return TREE_CST_RTL (exp);
3161 /* Now output assembler code to define the label for EXP,
3162 and follow it with the data of EXP. */
3165 output_constant_def_contents (exp, reloc, labelno)
3172 if (IN_NAMED_SECTION (exp))
3173 named_section (exp, NULL, reloc);
3176 /* First switch to text section, except for writable strings. */
3177 #ifdef SELECT_SECTION
3178 SELECT_SECTION (exp, reloc);
3180 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3181 || (flag_pic && reloc))
3184 readonly_data_section ();
3188 /* Align the location counter as required by EXP's data type. */
3189 align = TYPE_ALIGN (TREE_TYPE (exp));
3190 #ifdef CONSTANT_ALIGNMENT
3191 align = CONSTANT_ALIGNMENT (exp, align);
3194 if (align > BITS_PER_UNIT)
3195 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3197 /* Output the label itself. */
3198 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3200 /* Output the value of EXP. */
3201 output_constant (exp,
3202 (TREE_CODE (exp) == STRING_CST
3203 ? TREE_STRING_LENGTH (exp)
3204 : int_size_in_bytes (TREE_TYPE (exp))));
3208 /* Structure to represent sufficient information about a constant so that
3209 it can be output when the constant pool is output, so that function
3210 integration can be done, and to simplify handling on machines that reference
3211 constant pool as base+displacement. */
3213 struct pool_constant
3215 struct constant_descriptor *desc;
3216 struct pool_constant *next;
3217 enum machine_mode mode;
3225 /* Structure used to maintain hash table mapping symbols used to their
3226 corresponding constants. */
3231 struct pool_constant *pool;
3232 struct pool_sym *next;
3235 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3236 The argument is XSTR (... , 0) */
3238 #define SYMHASH(LABEL) \
3239 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3241 /* Initialize constant pool hashing for a new function. */
3244 init_varasm_status (f)
3247 struct varasm_status *p;
3248 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3250 p->x_const_rtx_hash_table
3251 = ((struct constant_descriptor **)
3252 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3253 p->x_const_rtx_sym_hash_table
3254 = ((struct pool_sym **)
3255 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3256 bzero ((char *) p->x_const_rtx_hash_table,
3257 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3258 bzero ((char *) p->x_const_rtx_sym_hash_table,
3259 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3261 p->x_first_pool = p->x_last_pool = 0;
3262 p->x_pool_offset = 0;
3263 p->x_const_double_chain = 0;
3266 /* Mark PC for GC. */
3269 mark_pool_constant (pc)
3270 struct pool_constant *pc;
3274 ggc_mark_rtx (pc->constant);
3279 /* Mark PPS for GC. */
3282 mark_pool_sym_hash_table (pps)
3283 struct pool_sym **pps;
3285 struct pool_sym *ps;
3288 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3289 for (ps = pps[i]; ps ; ps = ps->next)
3290 ggc_mark_string (ps->label);
3293 /* Mark P for GC. */
3296 mark_varasm_status (p)
3297 struct varasm_status *p;
3302 mark_pool_constant (p->x_first_pool);
3303 mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
3304 ggc_mark_rtx (p->x_const_double_chain);
3307 /* Clear out all parts of the state in F that can safely be discarded
3308 after the function has been compiled, to let garbage collection
3309 reclaim the memory. */
3312 free_varasm_status (f)
3315 struct varasm_status *p;
3318 free (p->x_const_rtx_hash_table);
3319 free (p->x_const_rtx_sym_hash_table);
3324 enum kind { RTX_DOUBLE, RTX_INT };
3328 #ifdef ONLY_INT_FIELDS
3329 unsigned int kind : 16;
3330 unsigned int mode : 16;
3332 enum kind kind : 16;
3333 enum machine_mode mode : 16;
3336 union real_extract du;
3337 struct addr_const addr;
3338 struct {HOST_WIDE_INT high, low;} di;
3342 /* Express an rtx for a constant integer (perhaps symbolic)
3343 as the sum of a symbol or label plus an explicit integer.
3344 They are stored into VALUE. */
3347 decode_rtx_const (mode, x, value)
3348 enum machine_mode mode;
3350 struct rtx_const *value;
3352 /* Clear the whole structure, including any gaps. */
3355 int *p = (int *) value;
3356 int *end = (int *) (value + 1);
3361 value->kind = RTX_INT; /* Most usual kind. */
3364 switch (GET_CODE (x))
3367 value->kind = RTX_DOUBLE;
3368 if (GET_MODE (x) != VOIDmode)
3370 value->mode = GET_MODE (x);
3371 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3372 (char *) &value->un.du, sizeof value->un.du);
3376 value->un.di.low = CONST_DOUBLE_LOW (x);
3377 value->un.di.high = CONST_DOUBLE_HIGH (x);
3382 value->un.addr.offset = INTVAL (x);
3388 value->un.addr.base = x;
3393 if (GET_CODE (x) == PLUS)
3395 value->un.addr.base = XEXP (x, 0);
3396 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3398 value->un.addr.offset = INTVAL (XEXP (x, 1));
3400 else if (GET_CODE (x) == MINUS)
3402 value->un.addr.base = XEXP (x, 0);
3403 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3405 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3415 if (value->kind == RTX_INT && value->un.addr.base != 0)
3416 switch (GET_CODE (value->un.addr.base))
3419 /* Use the string's address, not the SYMBOL_REF's address,
3420 for the sake of addresses of library routines. */
3421 value->un.addr.base = XSTR (value->un.addr.base, 0);
3425 /* For a LABEL_REF, compare labels. */
3426 value->un.addr.base = XEXP (value->un.addr.base, 0);
3433 /* Given a MINUS expression, simplify it if both sides
3434 include the same symbol. */
3437 simplify_subtraction (x)
3440 struct rtx_const val0, val1;
3442 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3443 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3445 if (val0.un.addr.base == val1.un.addr.base)
3446 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3450 /* Compute a hash code for a constant RTL expression. */
3453 const_hash_rtx (mode, x)
3454 enum machine_mode mode;
3460 struct rtx_const value;
3461 decode_rtx_const (mode, x, &value);
3463 /* Compute hashing function */
3465 for (i = 0; i < sizeof value / sizeof (int); i++)
3466 hi += ((int *) &value)[i];
3468 hi &= (1 << HASHBITS) - 1;
3469 hi %= MAX_RTX_HASH_TABLE;
3473 /* Compare a constant rtl object X with a constant-descriptor DESC.
3474 Return 1 if DESC describes a constant with the same value as X. */
3477 compare_constant_rtx (mode, x, desc)
3478 enum machine_mode mode;
3480 struct constant_descriptor *desc;
3482 register int *p = (int *) desc->contents;
3485 struct rtx_const value;
3487 decode_rtx_const (mode, x, &value);
3488 strp = (int *) &value;
3489 len = sizeof value / sizeof (int);
3491 /* Compare constant contents. */
3493 if (*p++ != *strp++)
3499 /* Construct a constant descriptor for the rtl-expression X.
3500 It is up to the caller to enter the descriptor in the hash table. */
3502 static struct constant_descriptor *
3503 record_constant_rtx (mode, x)
3504 enum machine_mode mode;
3507 struct constant_descriptor *ptr;
3510 struct rtx_const value;
3512 decode_rtx_const (mode, x, &value);
3514 /* Put these things in the saveable obstack so we can ensure it won't
3515 be freed if we are called from combine or some other phase that discards
3516 memory allocated from function_obstack (current_obstack). */
3517 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3518 obstack_grow (saveable_obstack, &label, sizeof label);
3519 obstack_grow (saveable_obstack, &rtl, sizeof rtl);
3521 /* Record constant contents. */
3522 obstack_grow (saveable_obstack, &value, sizeof value);
3524 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3527 /* Given a constant rtx X, make (or find) a memory constant for its value
3528 and return a MEM rtx to refer to it in memory. */
3531 force_const_mem (mode, x)
3532 enum machine_mode mode;
3536 register struct constant_descriptor *desc;
3541 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3542 (this will always be true for floating CONST_DOUBLEs that have been
3543 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3544 use the previous copy. Otherwise, make a new one. Note that in
3545 the unlikely event that this same CONST_DOUBLE is used in two different
3546 modes in an alternating fashion, we will allocate a lot of different
3547 memory locations, but this should be extremely rare. */
3549 if (GET_CODE (x) == CONST_DOUBLE
3550 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3551 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3552 return CONST_DOUBLE_MEM (x);
3554 /* Compute hash code of X. Search the descriptors for that hash code
3555 to see if any of them describes X. If yes, the descriptor records
3556 the label number already assigned. */
3558 hash = const_hash_rtx (mode, x);
3560 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3561 if (compare_constant_rtx (mode, x, desc))
3563 found = desc->label;
3569 register struct pool_constant *pool;
3570 register struct pool_sym *sym;
3573 /* No constant equal to X is known to have been output.
3574 Make a constant descriptor to enter X in the hash table.
3575 Assign the label number and record it in the descriptor for
3576 future calls to this function to find. */
3578 desc = record_constant_rtx (mode, x);
3579 desc->next = const_rtx_hash_table[hash];
3580 const_rtx_hash_table[hash] = desc;
3582 /* Align the location counter as required by EXP's data type. */
3583 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3584 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3585 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3586 #ifdef CONSTANT_ALIGNMENT
3587 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3588 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3591 pool_offset += align - 1;
3592 pool_offset &= ~ (align - 1);
3594 /* If RTL is not being placed into the saveable obstack, make a
3595 copy of X that is in the saveable obstack in case we are
3596 being called from combine or some other phase that discards
3597 memory it allocates. We used to only do this if it is a
3598 CONST; however, reload can allocate a CONST_INT when
3599 eliminating registers. */
3600 if (rtl_obstack != saveable_obstack
3601 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3603 push_obstacks_nochange ();
3604 rtl_in_saveable_obstack ();
3606 if (GET_CODE (x) == CONST)
3607 x = gen_rtx_CONST (GET_MODE (x),
3608 gen_rtx_PLUS (GET_MODE (x),
3609 XEXP (XEXP (x, 0), 0),
3610 XEXP (XEXP (x, 0), 1)));
3612 x = GEN_INT (INTVAL (x));
3617 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3619 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3623 pool->labelno = const_labelno;
3624 pool->align = align;
3625 pool->offset = pool_offset;
3632 last_pool->next = pool;
3635 pool_offset += GET_MODE_SIZE (mode);
3637 /* Create a string containing the label name, in LABEL. */
3638 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3642 desc->label = found = ggc_alloc_string (label, -1);
3644 /* Add label to symbol hash table. */
3645 hash = SYMHASH (found);
3646 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3649 sym->next = const_rtx_sym_hash_table[hash];
3650 const_rtx_sym_hash_table[hash] = sym;
3653 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3655 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3657 RTX_UNCHANGING_P (def) = 1;
3658 /* Mark the symbol_ref as belonging to this constants pool. */
3659 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3660 current_function_uses_const_pool = 1;
3662 if (GET_CODE (x) == CONST_DOUBLE)
3664 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3666 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3667 const_double_chain = x;
3669 CONST_DOUBLE_MEM (x) = def;
3675 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3676 the corresponding pool_constant structure. */
3678 static struct pool_constant *
3679 find_pool_constant (f, addr)
3683 struct pool_sym *sym;
3684 char *label = XSTR (addr, 0);
3686 for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3687 if (sym->label == label)
3693 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3696 get_pool_constant (addr)
3699 return (find_pool_constant (current_function, addr))->constant;
3702 /* Likewise, but for the constant pool of a specific function. */
3705 get_pool_constant_for_function (f, addr)
3709 return (find_pool_constant (f, addr))->constant;
3712 /* Similar, return the mode. */
3715 get_pool_mode (addr)
3718 return (find_pool_constant (current_function, addr))->mode;
3722 get_pool_mode_for_function (f, addr)
3726 return (find_pool_constant (f, addr))->mode;
3729 /* Similar, return the offset in the constant pool. */
3732 get_pool_offset (addr)
3735 return (find_pool_constant (current_function, addr))->offset;
3738 /* Return the size of the constant pool. */
3746 /* Write all the constants in the constant pool. */
3749 output_constant_pool (fnname, fndecl)
3750 const char *fnname ATTRIBUTE_UNUSED;
3751 tree fndecl ATTRIBUTE_UNUSED;
3753 struct pool_constant *pool;
3755 union real_extract u;
3757 /* It is possible for gcc to call force_const_mem and then to later
3758 discard the instructions which refer to the constant. In such a
3759 case we do not need to output the constant. */
3760 mark_constant_pool ();
3762 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3763 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3766 for (pool = first_pool; pool; pool = pool->next)
3773 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3774 whose CODE_LABEL has been deleted. This can occur if a jump table
3775 is eliminated by optimization. If so, write a constant of zero
3776 instead. Note that this can also happen by turning the
3777 CODE_LABEL into a NOTE. */
3778 if (((GET_CODE (x) == LABEL_REF
3779 && (INSN_DELETED_P (XEXP (x, 0))
3780 || GET_CODE (XEXP (x, 0)) == NOTE)))
3781 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3782 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3783 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3784 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3787 /* First switch to correct section. */
3788 #ifdef SELECT_RTX_SECTION
3789 SELECT_RTX_SECTION (pool->mode, x);
3791 readonly_data_section ();
3794 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3795 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3796 pool->align, pool->labelno, done);
3799 if (pool->align > 1)
3800 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3802 /* Output the label. */
3803 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3805 /* Output the value of the constant itself. */
3806 switch (GET_MODE_CLASS (pool->mode))
3809 if (GET_CODE (x) != CONST_DOUBLE)
3812 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3813 assemble_real (u.d, pool->mode);
3817 case MODE_PARTIAL_INT:
3818 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3825 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3831 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3832 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3835 /* Done with this pool. */
3836 first_pool = last_pool = 0;
3839 /* Look through the instructions for this function, and mark all the
3840 entries in the constant pool which are actually being used. */
3843 mark_constant_pool ()
3846 struct pool_constant *pool;
3848 if (first_pool == 0)
3851 for (pool = first_pool; pool; pool = pool->next)
3854 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3855 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3856 mark_constants (PATTERN (insn));
3858 for (insn = current_function_epilogue_delay_list;
3860 insn = XEXP (insn, 1))
3861 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3862 mark_constants (PATTERN (insn));
3864 /* It's possible that the only reference to a symbol is in a symbol
3865 that's in the constant pool. This happens in Fortran under some
3866 situations. (When the constant contains the address of another
3867 constant, and only the first is used directly in an insn.)
3868 This is potentially suboptimal if there's ever a possibility of
3869 backwards (in pool order) 2'd level references. However, it's
3870 not clear that 2'd level references can happen. */
3871 for (pool = first_pool; pool; pool = pool->next)
3873 struct pool_sym *sym;
3876 /* skip unmarked entries; no insn refers to them. */
3880 /* Skip everything except SYMBOL_REFs. */
3881 if (GET_CODE (pool->constant) != SYMBOL_REF)
3883 label = XSTR (pool->constant, 0);
3885 /* Be sure the symbol's value is marked. */
3886 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3888 if (sym->label == label)
3889 sym->pool->mark = 1;
3890 /* If we didn't find it, there's something truly wrong here, but it
3891 will be announced by the assembler. */
3900 register const char *format_ptr;
3905 if (GET_CODE (x) == SYMBOL_REF)
3907 if (CONSTANT_POOL_ADDRESS_P (x))
3908 find_pool_constant (current_function, x)->mark = 1;
3911 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3912 a MEM, but does not constitute a use of that MEM. */
3913 else if (GET_CODE (x) == CONST_DOUBLE)
3916 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3917 insns, not any notes that may be attached. We don't want to mark
3918 a constant just because it happens to appear in a REG_EQUIV note. */
3919 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3921 mark_constants (PATTERN (x));
3925 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3927 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3929 switch (*format_ptr++)
3932 mark_constants (XEXP (x, i));
3936 if (XVEC (x, i) != 0)
3940 for (j = 0; j < XVECLEN (x, i); j++)
3941 mark_constants (XVECEXP (x, i, j));
3960 /* Find all the constants whose addresses are referenced inside of EXP,
3961 and make sure assembler code with a label has been output for each one.
3962 Indicate whether an ADDR_EXPR has been encountered. */
3965 output_addressed_constants (exp)
3970 switch (TREE_CODE (exp))
3974 register tree constant = TREE_OPERAND (exp, 0);
3976 while (TREE_CODE (constant) == COMPONENT_REF)
3978 constant = TREE_OPERAND (constant, 0);
3981 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3982 || TREE_CODE (constant) == CONSTRUCTOR)
3983 /* No need to do anything here
3984 for addresses of variables or functions. */
3985 output_constant_def (constant);
3992 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3993 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3998 case NON_LVALUE_EXPR:
3999 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4005 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
4006 if (TREE_VALUE (link) != 0)
4007 reloc |= output_addressed_constants (TREE_VALUE (link));
4017 /* Return nonzero if VALUE is a valid constant-valued expression
4018 for use in initializing a static variable; one that can be an
4019 element of a "constant" initializer.
4021 Return null_pointer_node if the value is absolute;
4022 if it is relocatable, return the variable that determines the relocation.
4023 We assume that VALUE has been folded as much as possible;
4024 therefore, we do not need to check for such things as
4025 arithmetic-combinations of integers. */
4028 initializer_constant_valid_p (value, endtype)
4032 switch (TREE_CODE (value))
4035 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4036 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4037 && TREE_CONSTANT (value)
4038 && CONSTRUCTOR_ELTS (value))
4040 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4043 return TREE_STATIC (value) ? null_pointer_node : 0;
4049 return null_pointer_node;
4052 return TREE_OPERAND (value, 0);
4054 case NON_LVALUE_EXPR:
4055 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4059 /* Allow conversions between pointer types. */
4060 if (POINTER_TYPE_P (TREE_TYPE (value))
4061 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4062 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4064 /* Allow conversions between real types. */
4065 if (FLOAT_TYPE_P (TREE_TYPE (value))
4066 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4067 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4069 /* Allow length-preserving conversions between integer types. */
4070 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4071 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4072 && (TYPE_PRECISION (TREE_TYPE (value))
4073 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4074 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4076 /* Allow conversions between other integer types only if
4078 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4079 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4081 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4083 if (inner == null_pointer_node)
4084 return null_pointer_node;
4088 /* Allow (int) &foo provided int is as wide as a pointer. */
4089 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4090 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4091 && (TYPE_PRECISION (TREE_TYPE (value))
4092 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4093 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4096 /* Likewise conversions from int to pointers, but also allow
4097 conversions from 0. */
4098 if (POINTER_TYPE_P (TREE_TYPE (value))
4099 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4101 if (integer_zerop (TREE_OPERAND (value, 0)))
4102 return null_pointer_node;
4103 else if (TYPE_PRECISION (TREE_TYPE (value))
4104 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4105 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4109 /* Allow conversions to union types if the value inside is okay. */
4110 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4111 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4116 if (! INTEGRAL_TYPE_P (endtype)
4117 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4119 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4121 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4123 /* If either term is absolute, use the other terms relocation. */
4124 if (valid0 == null_pointer_node)
4126 if (valid1 == null_pointer_node)
4132 if (! INTEGRAL_TYPE_P (endtype)
4133 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4135 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4137 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4139 /* Win if second argument is absolute. */
4140 if (valid1 == null_pointer_node)
4142 /* Win if both arguments have the same relocation.
4143 Then the value is absolute. */
4144 if (valid0 == valid1 && valid0 != 0)
4145 return null_pointer_node;
4148 /* Support differences between labels. */
4149 if (INTEGRAL_TYPE_P (endtype))
4152 op0 = TREE_OPERAND (value, 0);
4153 op1 = TREE_OPERAND (value, 1);
4157 if (TREE_CODE (op0) == ADDR_EXPR
4158 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4159 && TREE_CODE (op1) == ADDR_EXPR
4160 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4161 return null_pointer_node;
4172 /* Output assembler code for constant EXP to FILE, with no label.
4173 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4174 Assumes output_addressed_constants has been done on EXP already.
4176 Generate exactly SIZE bytes of assembler data, padding at the end
4177 with zeros if necessary. SIZE must always be specified.
4179 SIZE is important for structure constructors,
4180 since trailing members may have been omitted from the constructor.
4181 It is also important for initialization of arrays from string constants
4182 since the full length of the string constant might not be wanted.
4183 It is also needed for initialization of unions, where the initializer's
4184 type is just one member, and that may not be as long as the union.
4186 There a case in which we would fail to output exactly SIZE bytes:
4187 for a structure constructor that wants to produce more than SIZE bytes.
4188 But such constructors will never be generated for any possible input. */
4191 output_constant (exp, size)
4195 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4197 /* Some front-ends use constants other than the standard
4198 language-indepdent varieties, but which may still be output
4199 directly. Give the front-end a chance to convert EXP to a
4200 language-independent representation. */
4201 if (lang_expand_constant)
4202 exp = (*lang_expand_constant) (exp);
4204 if (size == 0 || flag_syntax_only)
4207 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4208 That way we get the constant (we hope) inside it. Also, strip off any
4209 NOP_EXPR that converts between two record, union, array, or set types. */
4210 while ((TREE_CODE (exp) == NOP_EXPR
4211 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4212 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4213 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4214 exp = TREE_OPERAND (exp, 0);
4216 /* Allow a constructor with no elements for any data type.
4217 This means to fill the space with zeros. */
4218 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4220 assemble_zeros (size);
4231 case REFERENCE_TYPE:
4232 /* ??? What about (int)((float)(int)&foo + 4) */
4233 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4234 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4235 exp = TREE_OPERAND (exp, 0);
4237 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4238 EXPAND_INITIALIZER),
4240 error ("initializer for integer value is too complicated");
4245 if (TREE_CODE (exp) != REAL_CST)
4246 error ("initializer for floating value is not a floating constant");
4248 assemble_real (TREE_REAL_CST (exp),
4249 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4254 output_constant (TREE_REALPART (exp), size / 2);
4255 output_constant (TREE_IMAGPART (exp), size / 2);
4256 size -= (size / 2) * 2;
4260 if (TREE_CODE (exp) == CONSTRUCTOR)
4262 output_constructor (exp, size);
4265 else if (TREE_CODE (exp) == STRING_CST)
4269 if (size > TREE_STRING_LENGTH (exp))
4271 excess = size - TREE_STRING_LENGTH (exp);
4272 size = TREE_STRING_LENGTH (exp);
4275 assemble_string (TREE_STRING_POINTER (exp), size);
4284 if (TREE_CODE (exp) == CONSTRUCTOR)
4285 output_constructor (exp, size);
4291 if (TREE_CODE (exp) == INTEGER_CST)
4292 assemble_integer (expand_expr (exp, NULL_RTX,
4293 VOIDmode, EXPAND_INITIALIZER),
4295 else if (TREE_CODE (exp) == CONSTRUCTOR)
4297 unsigned char *buffer = (unsigned char *) alloca (size);
4298 if (get_set_constructor_bytes (exp, buffer, size))
4300 assemble_string ((char *) buffer, size);
4303 error ("unknown set constructor type");
4311 assemble_zeros (size);
4315 /* Subroutine of output_constant, used for CONSTRUCTORs
4316 (aggregate constants).
4317 Generate at least SIZE bytes, padding if necessary. */
4320 output_constructor (exp, size)
4324 register tree link, field = 0;
4325 HOST_WIDE_INT min_index = 0;
4326 /* Number of bytes output or skipped so far.
4327 In other words, current position within the constructor. */
4328 int total_bytes = 0;
4329 /* Non-zero means BYTE contains part of a byte, to be output. */
4330 int byte_buffer_in_use = 0;
4333 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4336 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4337 field = TYPE_FIELDS (TREE_TYPE (exp));
4339 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4340 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4342 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4344 /* As LINK goes through the elements of the constant,
4345 FIELD goes through the structure fields, if the constant is a structure.
4346 if the constant is a union, then we override this,
4347 by getting the field from the TREE_LIST element.
4348 But the constant could also be an array. Then FIELD is zero.
4350 There is always a maximum of one element in the chain LINK for unions
4351 (even if the initializer in a source program incorrectly contains
4353 for (link = CONSTRUCTOR_ELTS (exp);
4355 link = TREE_CHAIN (link),
4356 field = field ? TREE_CHAIN (field) : 0)
4358 tree val = TREE_VALUE (link);
4361 /* the element in a union constructor specifies the proper field. */
4363 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4364 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4366 /* if available, use the type given by link */
4367 if (TREE_PURPOSE (link) != 0)
4368 field = TREE_PURPOSE (link);
4371 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4372 index = TREE_PURPOSE (link);
4374 /* Eliminate the marker that makes a cast not be an lvalue. */
4378 if (index && TREE_CODE (index) == RANGE_EXPR)
4380 register int fieldsize
4381 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4382 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4383 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4384 HOST_WIDE_INT index;
4385 for (index = lo_index; index <= hi_index; index++)
4387 /* Output the element's initial value. */
4389 assemble_zeros (fieldsize);
4391 output_constant (val, fieldsize);
4393 /* Count its size. */
4394 total_bytes += fieldsize;
4397 else if (field == 0 || !DECL_BIT_FIELD (field))
4399 /* An element that is not a bit-field. */
4401 register int fieldsize;
4402 /* Since this structure is static,
4403 we know the positions are constant. */
4404 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4408 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4410 * (TREE_INT_CST_LOW (index) - min_index));
4412 /* Output any buffered-up bit-fields preceding this element. */
4413 if (byte_buffer_in_use)
4415 ASM_OUTPUT_BYTE (asm_out_file, byte);
4417 byte_buffer_in_use = 0;
4420 /* Advance to offset of this element.
4421 Note no alignment needed in an array, since that is guaranteed
4422 if each element has the proper size. */
4423 if ((field != 0 || index != 0) && bitpos != total_bytes)
4425 assemble_zeros (bitpos - total_bytes);
4426 total_bytes = bitpos;
4429 /* Determine size this element should occupy. */
4432 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4434 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4436 /* This avoids overflow trouble. */
4437 tree size_tree = size_binop (CEIL_DIV_EXPR,
4439 size_int (BITS_PER_UNIT));
4440 fieldsize = TREE_INT_CST_LOW (size_tree);
4444 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4445 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4449 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4451 /* Output the element's initial value. */
4453 assemble_zeros (fieldsize);
4455 output_constant (val, fieldsize);
4457 /* Count its size. */
4458 total_bytes += fieldsize;
4460 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4461 error ("invalid initial value for member `%s'",
4462 IDENTIFIER_POINTER (DECL_NAME (field)));
4465 /* Element that is a bit-field. */
4467 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4469 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4472 val = integer_zero_node;
4474 /* If this field does not start in this (or, next) byte,
4476 if (next_offset / BITS_PER_UNIT != total_bytes)
4478 /* Output remnant of any bit field in previous bytes. */
4479 if (byte_buffer_in_use)
4481 ASM_OUTPUT_BYTE (asm_out_file, byte);
4483 byte_buffer_in_use = 0;
4486 /* If still not at proper byte, advance to there. */
4487 if (next_offset / BITS_PER_UNIT != total_bytes)
4489 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4490 total_bytes = next_offset / BITS_PER_UNIT;
4494 if (! byte_buffer_in_use)
4497 /* We must split the element into pieces that fall within
4498 separate bytes, and combine each byte with previous or
4499 following bit-fields. */
4501 /* next_offset is the offset n fbits from the beginning of
4502 the structure to the next bit of this element to be processed.
4503 end_offset is the offset of the first bit past the end of
4505 while (next_offset < end_offset)
4509 HOST_WIDE_INT value;
4510 int next_byte = next_offset / BITS_PER_UNIT;
4511 int next_bit = next_offset % BITS_PER_UNIT;
4513 /* Advance from byte to byte
4514 within this element when necessary. */
4515 while (next_byte != total_bytes)
4517 ASM_OUTPUT_BYTE (asm_out_file, byte);
4522 /* Number of bits we can process at once
4523 (all part of the same byte). */
4524 this_time = MIN (end_offset - next_offset,
4525 BITS_PER_UNIT - next_bit);
4526 if (BYTES_BIG_ENDIAN)
4528 /* On big-endian machine, take the most significant bits
4529 first (of the bits that are significant)
4530 and put them into bytes from the most significant end. */
4531 shift = end_offset - next_offset - this_time;
4532 /* Don't try to take a bunch of bits that cross
4533 the word boundary in the INTEGER_CST. */
4534 if (shift < HOST_BITS_PER_WIDE_INT
4535 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4537 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4538 shift = HOST_BITS_PER_WIDE_INT;
4541 /* Now get the bits from the appropriate constant word. */
4542 if (shift < HOST_BITS_PER_WIDE_INT)
4544 value = TREE_INT_CST_LOW (val);
4546 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4548 value = TREE_INT_CST_HIGH (val);
4549 shift -= HOST_BITS_PER_WIDE_INT;
4553 byte |= (((value >> shift)
4554 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4555 << (BITS_PER_UNIT - this_time - next_bit));
4559 /* On little-endian machines,
4560 take first the least significant bits of the value
4561 and pack them starting at the least significant
4562 bits of the bytes. */
4563 shift = (next_offset
4564 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4565 /* Don't try to take a bunch of bits that cross
4566 the word boundary in the INTEGER_CST. */
4567 if (shift < HOST_BITS_PER_WIDE_INT
4568 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4570 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4571 shift = HOST_BITS_PER_WIDE_INT;
4574 /* Now get the bits from the appropriate constant word. */
4575 if (shift < HOST_BITS_PER_WIDE_INT)
4576 value = TREE_INT_CST_LOW (val);
4577 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4579 value = TREE_INT_CST_HIGH (val);
4580 shift -= HOST_BITS_PER_WIDE_INT;
4584 byte |= (((value >> shift)
4585 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4588 next_offset += this_time;
4589 byte_buffer_in_use = 1;
4593 if (byte_buffer_in_use)
4595 ASM_OUTPUT_BYTE (asm_out_file, byte);
4598 if (total_bytes < size)
4599 assemble_zeros (size - total_bytes);
4602 #ifdef HANDLE_PRAGMA_WEAK
4603 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4604 associatd with NAME. */
4607 add_weak (name, value)
4611 struct weak_syms *weak;
4613 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4618 weak->next = weak_decls;
4620 weak->value = value;
4625 #endif /* HANDLE_PRAGMA_WEAK */
4627 /* Declare DECL to be a weak symbol. */
4633 if (! TREE_PUBLIC (decl))
4634 error_with_decl (decl, "weak declaration of `%s' must be public");
4635 else if (TREE_ASM_WRITTEN (decl))
4636 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4637 else if (SUPPORTS_WEAK)
4638 DECL_WEAK (decl) = 1;
4639 #ifdef HANDLE_PRAGMA_WEAK
4640 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4644 /* Emit any pending weak declarations. */
4646 #ifdef HANDLE_PRAGMA_WEAK
4647 struct weak_syms * weak_decls;
4653 #ifdef HANDLE_PRAGMA_WEAK
4654 if (HANDLE_PRAGMA_WEAK)
4656 struct weak_syms *t;
4657 for (t = weak_decls; t; t = t->next)
4661 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4663 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4670 /* Remove NAME from the pending list of weak symbols. This prevents
4671 the compiler from emitting multiple .weak directives which confuses
4673 #ifdef ASM_WEAKEN_LABEL
4675 remove_from_pending_weak_list (name)
4676 char *name ATTRIBUTE_UNUSED;
4678 #ifdef HANDLE_PRAGMA_WEAK
4679 if (HANDLE_PRAGMA_WEAK)
4681 struct weak_syms *t;
4682 for (t = weak_decls; t; t = t->next)
4684 if (t->name && strcmp (name, t->name) == 0)
4693 assemble_alias (decl, target)
4694 tree decl, target ATTRIBUTE_UNUSED;
4698 make_decl_rtl (decl, (char *) 0, 1);
4699 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4701 #ifdef ASM_OUTPUT_DEF
4702 /* Make name accessible from other files, if appropriate. */
4704 if (TREE_PUBLIC (decl))
4706 #ifdef ASM_WEAKEN_LABEL
4707 if (DECL_WEAK (decl))
4709 ASM_WEAKEN_LABEL (asm_out_file, name);
4710 /* Remove this function from the pending weak list so that
4711 we do not emit multiple .weak directives for it. */
4712 remove_from_pending_weak_list
4713 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4717 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4720 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4721 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4723 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4725 TREE_ASM_WRITTEN (decl) = 1;
4727 #ifdef ASM_OUTPUT_WEAK_ALIAS
4728 if (! DECL_WEAK (decl))
4729 warning ("only weak aliases are supported in this configuration");
4731 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4732 TREE_ASM_WRITTEN (decl) = 1;
4734 warning ("alias definitions not supported in this configuration; ignored");
4739 /* This determines whether or not we support link-once semantics. */
4740 #ifndef SUPPORTS_ONE_ONLY
4741 #ifdef MAKE_DECL_ONE_ONLY
4742 #define SUPPORTS_ONE_ONLY 1
4744 #define SUPPORTS_ONE_ONLY 0
4748 /* Returns 1 if the target configuration supports defining public symbols
4749 so that one of them will be chosen at link time instead of generating a
4750 multiply-defined symbol error, whether through the use of weak symbols or
4751 a target-specific mechanism for having duplicates discarded. */
4754 supports_one_only ()
4756 if (SUPPORTS_ONE_ONLY)
4758 return SUPPORTS_WEAK;
4761 /* Set up DECL as a public symbol that can be defined in multiple
4762 translation units without generating a linker error. */
4765 make_decl_one_only (decl)
4768 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4771 TREE_PUBLIC (decl) = 1;
4773 if (TREE_CODE (decl) == VAR_DECL
4774 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4775 DECL_COMMON (decl) = 1;
4776 else if (SUPPORTS_ONE_ONLY)
4778 #ifdef MAKE_DECL_ONE_ONLY
4779 MAKE_DECL_ONE_ONLY (decl);
4781 DECL_ONE_ONLY (decl) = 1;
4783 else if (SUPPORTS_WEAK)
4784 DECL_WEAK (decl) = 1;
4792 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
4793 mark_const_hash_entry);
4794 ggc_add_string_root (&in_named_name, 1);