1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
37 #include "hard-reg-set.h"
46 #include "langhooks.h"
51 #ifdef XCOFF_DEBUGGING_INFO
52 #include "xcoffout.h" /* Needed for external data
53 declarations for e.g. AIX 4.x. */
56 #ifndef TRAMPOLINE_ALIGNMENT
57 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
61 #define ASM_STABS_OP "\t.stabs\t"
64 /* The (assembler) name of the first globally-visible object output. */
65 const char *first_global_object_name
;
66 const char *weak_global_object_name
;
68 extern struct obstack permanent_obstack
;
69 #define obstack_chunk_alloc xmalloc
72 struct constant_descriptor
;
76 #define MAX_RTX_HASH_TABLE 61
80 /* Hash facility for making memory-constants
81 from constant rtl-expressions. It is used on RISC machines
82 where immediate integer arguments and constant addresses are restricted
83 so that such constants must be stored in memory.
85 This pool of constants is reinitialized for each function
86 so each function gets its own constants-pool that comes right before
88 struct constant_descriptor
**x_const_rtx_hash_table
;
89 struct pool_constant
**x_const_rtx_sym_hash_table
;
91 /* Pointers to first and last constant in pool. */
92 struct pool_constant
*x_first_pool
, *x_last_pool
;
94 /* Current offset in constant pool (does not include any machine-specific
96 HOST_WIDE_INT x_pool_offset
;
98 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
99 They are chained through the CONST_DOUBLE_CHAIN. */
100 rtx x_const_double_chain
;
103 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
104 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
105 #define first_pool (cfun->varasm->x_first_pool)
106 #define last_pool (cfun->varasm->x_last_pool)
107 #define pool_offset (cfun->varasm->x_pool_offset)
108 #define const_double_chain (cfun->varasm->x_const_double_chain)
110 /* Number for making the label on the next
111 constant that is stored in memory. */
115 /* Number for making the label on the next
116 static variable internal to a function. */
120 /* Carry information from ASM_DECLARE_OBJECT_NAME
121 to ASM_FINISH_DECLARE_OBJECT. */
123 int size_directive_output
;
125 /* The last decl for which assemble_variable was called,
126 if it did ASM_DECLARE_OBJECT_NAME.
127 If the last call to assemble_variable didn't do that,
130 tree last_assemble_variable_decl
;
132 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
133 So giving constant the alias set for the type will allow such
134 initializations to appear to conflict with the load of the constant. We
135 avoid this by giving all constants an alias set for just constants.
136 Since there will be no stores to that a alias set, nothing will ever
137 conflict with them. */
139 static HOST_WIDE_INT const_alias_set
;
141 static const char *strip_reg_name
PARAMS ((const char *));
142 static int contains_pointers_p
PARAMS ((tree
));
143 static void assemble_real_1
PARAMS ((PTR
));
144 static void decode_addr_const
PARAMS ((tree
, struct addr_const
*));
145 static int const_hash
PARAMS ((tree
));
146 static int compare_constant
PARAMS ((tree
,
147 struct constant_descriptor
*));
148 static const unsigned char *compare_constant_1
PARAMS ((tree
, const unsigned char *));
149 static struct constant_descriptor
*record_constant
PARAMS ((tree
));
150 static void record_constant_1
PARAMS ((tree
));
151 static tree copy_constant
PARAMS ((tree
));
152 static void output_constant_def_contents
PARAMS ((tree
, int, int));
153 static void decode_rtx_const
PARAMS ((enum machine_mode
, rtx
,
154 struct rtx_const
*));
155 static int const_hash_rtx
PARAMS ((enum machine_mode
, rtx
));
156 static int compare_constant_rtx
PARAMS ((enum machine_mode
, rtx
,
157 struct constant_descriptor
*));
158 static struct constant_descriptor
*record_constant_rtx
PARAMS ((enum machine_mode
,
160 static struct pool_constant
*find_pool_constant
PARAMS ((struct function
*, rtx
));
161 static void mark_constant_pool
PARAMS ((void));
162 static void mark_constants
PARAMS ((rtx
));
163 static int mark_constant
PARAMS ((rtx
*current_rtx
, void *data
));
164 static int output_addressed_constants
PARAMS ((tree
));
165 static void output_after_function_constants
PARAMS ((void));
166 static unsigned HOST_WIDE_INT array_size_for_constructor
PARAMS ((tree
));
167 static unsigned min_align
PARAMS ((unsigned, unsigned));
168 static void output_constructor
PARAMS ((tree
, HOST_WIDE_INT
,
170 #ifdef ASM_WEAKEN_LABEL
171 static void remove_from_pending_weak_list
PARAMS ((const char *));
173 static int in_named_entry_eq
PARAMS ((const PTR
, const PTR
));
174 static hashval_t in_named_entry_hash
PARAMS ((const PTR
));
175 #ifdef ASM_OUTPUT_BSS
176 static void asm_output_bss
PARAMS ((FILE *, tree
, const char *, int, int));
178 #ifdef BSS_SECTION_ASM_OP
179 #ifdef ASM_OUTPUT_ALIGNED_BSS
180 static void asm_output_aligned_bss
PARAMS ((FILE *, tree
, const char *,
183 #endif /* BSS_SECTION_ASM_OP */
184 static void mark_pool_constant
PARAMS ((struct pool_constant
*));
185 static void mark_const_hash_entry
PARAMS ((void *));
186 static int mark_const_str_htab_1
PARAMS ((void **, void *));
187 static void mark_const_str_htab
PARAMS ((void *));
188 static hashval_t const_str_htab_hash
PARAMS ((const void *x
));
189 static int const_str_htab_eq
PARAMS ((const void *x
, const void *y
));
190 static void const_str_htab_del
PARAMS ((void *));
191 static void asm_emit_uninitialised
PARAMS ((tree
, const char*, int, int));
192 static void resolve_unique_section
PARAMS ((tree
, int));
194 static enum in_section
{ no_section
, in_text
, in_data
, in_named
195 #ifdef BSS_SECTION_ASM_OP
198 #ifdef CTORS_SECTION_ASM_OP
201 #ifdef DTORS_SECTION_ASM_OP
204 #ifdef EXTRA_SECTIONS
207 } in_section
= no_section
;
209 /* Return a non-zero value if DECL has a section attribute. */
210 #ifndef IN_NAMED_SECTION
211 #define IN_NAMED_SECTION(DECL) \
212 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
213 && DECL_SECTION_NAME (DECL) != NULL_TREE)
216 /* Text of section name when in_section == in_named. */
217 static const char *in_named_name
;
219 /* Hash table of flags that have been used for a particular named section. */
221 struct in_named_entry
228 static htab_t in_named_htab
;
230 /* Define functions like text_section for any extra sections. */
231 #ifdef EXTRA_SECTION_FUNCTIONS
232 EXTRA_SECTION_FUNCTIONS
235 /* Tell assembler to switch to text section. */
240 if (in_section
!= in_text
)
245 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
247 in_section
= in_text
;
251 /* Tell assembler to switch to data section. */
256 if (in_section
!= in_data
)
258 if (flag_shared_data
)
260 #ifdef SHARED_SECTION_ASM_OP
261 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
263 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
267 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
269 in_section
= in_data
;
272 /* Tell assembler to ALWAYS switch to data section, in case
273 it's not sure where it is. */
276 force_data_section ()
278 in_section
= no_section
;
282 /* Tell assembler to switch to read-only data section. This is normally
286 readonly_data_section ()
288 #ifdef READONLY_DATA_SECTION
289 READONLY_DATA_SECTION (); /* Note this can call data_section. */
295 /* Determine if we're in the text section. */
300 return in_section
== in_text
;
303 /* Determine if we're in the data section. */
308 return in_section
== in_data
;
311 /* Helper routines for maintaining in_named_htab. */
314 in_named_entry_eq (p1
, p2
)
318 const struct in_named_entry
*old
= p1
;
319 const char *new = p2
;
321 return strcmp (old
->name
, new) == 0;
325 in_named_entry_hash (p
)
328 const struct in_named_entry
*old
= p
;
329 return htab_hash_string (old
->name
);
332 /* If SECTION has been seen before as a named section, return the flags
333 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
334 set of flags for a section to have, so 0 does not mean that the section
335 has not been seen. */
338 get_named_section_flags (section
)
341 struct in_named_entry
**slot
;
343 slot
= (struct in_named_entry
**)
344 htab_find_slot_with_hash (in_named_htab
, section
,
345 htab_hash_string (section
), NO_INSERT
);
347 return slot
? (*slot
)->flags
: 0;
350 /* Returns true if the section has been declared before. Sets internal
351 flag on this section in in_named_hash so subsequent calls on this
352 section will return false. */
355 named_section_first_declaration (name
)
358 struct in_named_entry
**slot
;
360 slot
= (struct in_named_entry
**)
361 htab_find_slot_with_hash (in_named_htab
, name
,
362 htab_hash_string (name
), NO_INSERT
);
363 if (! (*slot
)->declared
)
365 (*slot
)->declared
= true;
375 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
376 different set of flags, return false. */
379 set_named_section_flags (section
, flags
)
383 struct in_named_entry
**slot
, *entry
;
385 slot
= (struct in_named_entry
**)
386 htab_find_slot_with_hash (in_named_htab
, section
,
387 htab_hash_string (section
), INSERT
);
392 entry
= (struct in_named_entry
*) xmalloc (sizeof (*entry
));
394 entry
->name
= ggc_strdup (section
);
395 entry
->flags
= flags
;
396 entry
->declared
= false;
398 else if (entry
->flags
!= flags
)
404 /* Tell assembler to change to section NAME with attributes FLAGS. */
407 named_section_flags (name
, flags
)
411 if (in_section
!= in_named
|| strcmp (name
, in_named_name
) != 0)
413 if (! set_named_section_flags (name
, flags
))
416 (* targetm
.asm_out
.named_section
) (name
, flags
);
418 if (flags
& SECTION_FORGET
)
419 in_section
= no_section
;
422 in_named_name
= ggc_strdup (name
);
423 in_section
= in_named
;
428 /* Tell assembler to change to section NAME for DECL.
429 If DECL is NULL, just switch to section NAME.
430 If NAME is NULL, get the name from DECL.
431 If RELOC is 1, the initializer for DECL contains relocs. */
434 named_section (decl
, name
, reloc
)
441 if (decl
!= NULL_TREE
&& !DECL_P (decl
))
444 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
446 flags
= (* targetm
.section_type_flags
) (decl
, name
, reloc
);
448 /* Sanity check user variables for flag changes. Non-user
449 section flag changes will abort in named_section_flags. */
450 if (decl
&& ! set_named_section_flags (name
, flags
))
452 error_with_decl (decl
, "%s causes a section type conflict");
453 flags
= get_named_section_flags (name
);
456 named_section_flags (name
, flags
);
459 /* If required, set DECL_SECTION_NAME to a unique name. */
462 resolve_unique_section (decl
, reloc
)
464 int reloc ATTRIBUTE_UNUSED
;
466 if (DECL_SECTION_NAME (decl
) == NULL_TREE
467 && (flag_function_sections
468 || (targetm
.have_named_sections
469 && DECL_ONE_ONLY (decl
))))
470 UNIQUE_SECTION (decl
, reloc
);
473 #ifdef BSS_SECTION_ASM_OP
475 /* Tell the assembler to switch to the bss section. */
480 if (in_section
!= in_bss
)
482 #ifdef SHARED_BSS_SECTION_ASM_OP
483 if (flag_shared_data
)
484 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
487 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
493 #ifdef ASM_OUTPUT_BSS
495 /* Utility function for ASM_OUTPUT_BSS for targets to use if
496 they don't support alignments in .bss.
497 ??? It is believed that this function will work in most cases so such
498 support is localized here. */
501 asm_output_bss (file
, decl
, name
, size
, rounded
)
503 tree decl ATTRIBUTE_UNUSED
;
505 int size ATTRIBUTE_UNUSED
, rounded
;
507 ASM_GLOBALIZE_LABEL (file
, name
);
509 #ifdef ASM_DECLARE_OBJECT_NAME
510 last_assemble_variable_decl
= decl
;
511 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
513 /* Standard thing is just output label for the object. */
514 ASM_OUTPUT_LABEL (file
, name
);
515 #endif /* ASM_DECLARE_OBJECT_NAME */
516 ASM_OUTPUT_SKIP (file
, rounded
);
521 #ifdef ASM_OUTPUT_ALIGNED_BSS
523 /* Utility function for targets to use in implementing
524 ASM_OUTPUT_ALIGNED_BSS.
525 ??? It is believed that this function will work in most cases so such
526 support is localized here. */
529 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
531 tree decl ATTRIBUTE_UNUSED
;
535 ASM_GLOBALIZE_LABEL (file
, name
);
537 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
538 #ifdef ASM_DECLARE_OBJECT_NAME
539 last_assemble_variable_decl
= decl
;
540 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
542 /* Standard thing is just output label for the object. */
543 ASM_OUTPUT_LABEL (file
, name
);
544 #endif /* ASM_DECLARE_OBJECT_NAME */
545 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
550 #endif /* BSS_SECTION_ASM_OP */
552 /* Switch to the section for function DECL.
554 If DECL is NULL_TREE, switch to the text section.
555 ??? It's not clear that we will ever be passed NULL_TREE, but it's
556 safer to handle it. */
559 function_section (decl
)
562 if (decl
!= NULL_TREE
563 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
564 named_section (decl
, (char *) 0, 0);
569 /* Switch to section for variable DECL.
571 RELOC is the `reloc' argument to SELECT_SECTION. */
574 variable_section (decl
, reloc
)
578 if (IN_NAMED_SECTION (decl
))
579 named_section (decl
, NULL
, reloc
);
582 /* C++ can have const variables that get initialized from constructors,
583 and thus can not be in a readonly section. We prevent this by
584 verifying that the initial value is constant for objects put in a
587 error_mark_node is used by the C front end to indicate that the
588 initializer has not been seen yet. In this case, we assume that
589 the initializer must be constant.
591 C++ uses error_mark_node for variables that have complicated
592 initializers, but these variables go in BSS so we won't be called
595 #ifdef SELECT_SECTION
596 SELECT_SECTION (decl
, reloc
, DECL_ALIGN (decl
));
598 if (DECL_READONLY_SECTION (decl
, reloc
))
599 readonly_data_section ();
606 /* Tell assembler to switch to the section for the exception handling
610 default_exception_section ()
612 if (targetm
.have_named_sections
)
613 named_section (NULL_TREE
, ".gcc_except_table", 0);
617 readonly_data_section ();
620 /* Tell assembler to switch to the section for string merging. */
623 mergeable_string_section (decl
, align
, flags
)
624 tree decl ATTRIBUTE_UNUSED
;
625 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
626 unsigned int flags ATTRIBUTE_UNUSED
;
628 #ifdef HAVE_GAS_SHF_MERGE
629 if (flag_merge_constants
630 && TREE_CODE (decl
) == STRING_CST
631 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
633 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
635 enum machine_mode mode
;
636 unsigned int modesize
;
641 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
642 modesize
= GET_MODE_BITSIZE (mode
);
643 if (modesize
>= 8 && modesize
<= 256
644 && (modesize
& (modesize
- 1)) == 0)
646 if (align
< modesize
)
649 str
= TREE_STRING_POINTER (decl
);
650 len
= TREE_STRING_LENGTH (decl
);
651 unit
= GET_MODE_SIZE (mode
);
653 /* Check for embedded NUL characters. */
654 for (i
= 0; i
< len
; i
+= unit
)
656 for (j
= 0; j
< unit
; j
++)
657 if (str
[i
+ j
] != '\0')
664 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
666 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
667 if (!i
&& modesize
< align
)
669 /* A "" string with requested alignment greater than
670 character size might cause a problem:
671 if some other string required even bigger
672 alignment than "", then linker might think the
673 "" is just part of padding after some other string
674 and not put it into the hash table initially.
675 But this means "" could have smaller alignment
677 #ifdef ASM_OUTPUT_SECTION_START
678 named_section_flags (name
, flags
);
679 ASM_OUTPUT_SECTION_START (asm_out_file
);
681 readonly_data_section ();
686 named_section_flags (name
, flags
);
692 readonly_data_section ();
695 /* Tell assembler to switch to the section for constant merging. */
698 mergeable_constant_section (mode
, align
, flags
)
699 enum machine_mode mode ATTRIBUTE_UNUSED
;
700 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
701 unsigned int flags ATTRIBUTE_UNUSED
;
703 #ifdef HAVE_GAS_SHF_MERGE
704 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
706 if (flag_merge_constants
712 && (align
& (align
- 1)) == 0)
716 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
717 flags
|= (align
/ 8) | SECTION_MERGE
;
718 named_section_flags (name
, flags
);
722 readonly_data_section ();
725 /* Given NAME, a putative register name, discard any customary prefixes. */
728 strip_reg_name (name
)
731 #ifdef REGISTER_PREFIX
732 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
733 name
+= strlen (REGISTER_PREFIX
);
735 if (name
[0] == '%' || name
[0] == '#')
740 /* Decode an `asm' spec for a declaration as a register name.
741 Return the register number, or -1 if nothing specified,
742 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
743 or -3 if ASMSPEC is `cc' and is not recognized,
744 or -4 if ASMSPEC is `memory' and is not recognized.
745 Accept an exact spelling or a decimal number.
746 Prefixes such as % are optional. */
749 decode_reg_name (asmspec
)
756 /* Get rid of confusing prefixes. */
757 asmspec
= strip_reg_name (asmspec
);
759 /* Allow a decimal number as a "register name". */
760 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
761 if (! ISDIGIT (asmspec
[i
]))
763 if (asmspec
[0] != 0 && i
< 0)
766 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
772 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
774 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
777 #ifdef ADDITIONAL_REGISTER_NAMES
779 static const struct { const char *const name
; const int number
; } table
[]
780 = ADDITIONAL_REGISTER_NAMES
;
782 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
783 if (! strcmp (asmspec
, table
[i
].name
))
784 return table
[i
].number
;
786 #endif /* ADDITIONAL_REGISTER_NAMES */
788 if (!strcmp (asmspec
, "memory"))
791 if (!strcmp (asmspec
, "cc"))
800 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
801 have static storage duration. In other words, it should not be an
802 automatic variable, including PARM_DECLs.
804 There is, however, one exception: this function handles variables
805 explicitly placed in a particular register by the user.
807 ASMSPEC, if not 0, is the string which the user specified as the
808 assembler symbol name.
810 This is never called for PARM_DECL nodes. */
813 make_decl_rtl (decl
, asmspec
)
817 int top_level
= (DECL_CONTEXT (decl
) == NULL_TREE
);
818 const char *name
= 0;
819 const char *new_name
= 0;
823 /* Check that we are not being given an automatic variable. */
824 /* A weak alias has TREE_PUBLIC set but not the other bits. */
825 if (TREE_CODE (decl
) == PARM_DECL
826 || TREE_CODE (decl
) == RESULT_DECL
827 || (TREE_CODE (decl
) == VAR_DECL
828 && !TREE_STATIC (decl
)
829 && !TREE_PUBLIC (decl
)
830 && !DECL_EXTERNAL (decl
)
831 && !DECL_REGISTER (decl
)))
833 /* And that we were not given a type or a label. */
834 else if (TREE_CODE (decl
) == TYPE_DECL
835 || TREE_CODE (decl
) == LABEL_DECL
)
838 /* For a duplicate declaration, we can be called twice on the
839 same DECL node. Don't discard the RTL already made. */
840 if (DECL_RTL_SET_P (decl
))
842 /* If the old RTL had the wrong mode, fix the mode. */
843 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
845 rtx rtl
= DECL_RTL (decl
);
846 PUT_MODE (rtl
, DECL_MODE (decl
));
849 /* ??? Another way to do this would be to do what halfpic.c does
850 and maintain a hashed table of such critters. */
851 /* ??? Another way to do this would be to pass a flag bit to
852 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
853 /* Let the target reassign the RTL if it wants.
854 This is necessary, for example, when one machine specific
855 decl attribute overrides another. */
856 #ifdef REDO_SECTION_INFO_P
857 if (REDO_SECTION_INFO_P (decl
))
858 ENCODE_SECTION_INFO (decl
);
863 new_name
= name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
865 reg_number
= decode_reg_name (asmspec
);
866 if (reg_number
== -2)
868 /* ASMSPEC is given, and not the name of a register. Mark the
869 name with a star so assemble_name won't munge it. */
870 char *starred
= alloca (strlen (asmspec
) + 2);
872 strcpy (starred
+ 1, asmspec
);
876 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
878 /* First detect errors in declaring global registers. */
879 if (reg_number
== -1)
880 error_with_decl (decl
, "register name not specified for `%s'");
881 else if (reg_number
< 0)
882 error_with_decl (decl
, "invalid register name for `%s'");
883 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
884 error_with_decl (decl
,
885 "data type of `%s' isn't suitable for a register");
886 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
887 error_with_decl (decl
,
888 "register specified for `%s' isn't suitable for data type");
889 /* Now handle properly declared static register variables. */
894 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
896 DECL_INITIAL (decl
) = 0;
897 error ("global register variable has initial value");
899 if (TREE_THIS_VOLATILE (decl
))
900 warning ("volatile register variables don't work as you might wish");
902 /* If the user specified one of the eliminables registers here,
903 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
904 confused with that register and be eliminated. Although this
905 usage is somewhat suspect, we nevertheless use the following
906 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
909 gen_rtx_REG (DECL_MODE (decl
),
910 FIRST_PSEUDO_REGISTER
));
911 REGNO (DECL_RTL (decl
)) = reg_number
;
912 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
914 if (TREE_STATIC (decl
))
916 /* Make this register global, so not usable for anything
918 #ifdef ASM_DECLARE_REGISTER_GLOBAL
919 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
921 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
923 globalize_reg (reg_number
+ --nregs
);
926 /* As a register variable, it has no section. */
931 /* Now handle ordinary static variables and functions (in memory).
932 Also handle vars declared register invalidly. */
934 if (reg_number
>= 0 || reg_number
== -3)
935 error_with_decl (decl
,
936 "register name given for non-register variable `%s'");
938 /* Specifying a section attribute on a variable forces it into a
939 non-.bss section, and thus it cannot be common. */
940 if (TREE_CODE (decl
) == VAR_DECL
941 && DECL_SECTION_NAME (decl
) != NULL_TREE
942 && DECL_INITIAL (decl
) == NULL_TREE
943 && DECL_COMMON (decl
))
944 DECL_COMMON (decl
) = 0;
946 /* Can't use just the variable's own name for a variable
947 whose scope is less than the whole file, unless it's a member
948 of a local class (which will already be unambiguous).
949 Concatenate a distinguishing number. */
950 if (!top_level
&& !TREE_PUBLIC (decl
)
951 && ! (DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
)))
953 && name
== IDENTIFIER_POINTER (DECL_NAME (decl
)))
957 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
962 if (name
!= new_name
)
964 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (new_name
));
965 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
968 /* If this variable is to be treated as volatile, show its
969 tree node has side effects. */
970 if ((flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
971 && TREE_PUBLIC (decl
))
972 || ((flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
973 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))))
974 TREE_SIDE_EFFECTS (decl
) = 1;
976 x
= gen_rtx_MEM (DECL_MODE (decl
), gen_rtx_SYMBOL_REF (Pmode
, name
));
977 SYMBOL_REF_WEAK (XEXP (x
, 0)) = DECL_WEAK (decl
);
978 if (TREE_CODE (decl
) != FUNCTION_DECL
)
979 set_mem_attributes (x
, decl
, 1);
980 SET_DECL_RTL (decl
, x
);
982 /* Optionally set flags or add text to the name to record information
983 such as that it is a function name.
984 If the name is changed, the macro ASM_OUTPUT_LABELREF
985 will have to know how to strip this information. */
986 #ifdef ENCODE_SECTION_INFO
987 ENCODE_SECTION_INFO (decl
);
991 /* Make the rtl for variable VAR be volatile.
992 Use this only for static variables. */
995 make_var_volatile (var
)
998 if (GET_CODE (DECL_RTL (var
)) != MEM
)
1001 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
1004 /* Output alignment directive to align for constant expression EXP. */
1007 assemble_constant_align (exp
)
1012 /* Align the location counter as required by EXP's data type. */
1013 align
= TYPE_ALIGN (TREE_TYPE (exp
));
1014 #ifdef CONSTANT_ALIGNMENT
1015 align
= CONSTANT_ALIGNMENT (exp
, align
);
1018 if (align
> BITS_PER_UNIT
)
1020 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1024 /* Output a string of literal assembler code
1025 for an `asm' keyword used between functions. */
1028 assemble_asm (string
)
1033 if (TREE_CODE (string
) == ADDR_EXPR
)
1034 string
= TREE_OPERAND (string
, 0);
1036 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1039 /* Record an element in the table of global destructors. SYMBOL is
1040 a SYMBOL_REF of the function to be called; PRIORITY is a number
1041 between 0 and MAX_INIT_PRIORITY. */
1044 default_stabs_asm_out_destructor (symbol
, priority
)
1046 int priority ATTRIBUTE_UNUSED
;
1048 /* Tell GNU LD that this is part of the static destructor set.
1049 This will work for any system that uses stabs, most usefully
1051 fprintf (asm_out_file
, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1052 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1053 fputc ('\n', asm_out_file
);
1057 default_named_section_asm_out_destructor (symbol
, priority
)
1061 const char *section
= ".dtors";
1064 /* ??? This only works reliably with the GNU linker. */
1065 if (priority
!= DEFAULT_INIT_PRIORITY
)
1067 sprintf (buf
, ".dtors.%.5u",
1068 /* Invert the numbering so the linker puts us in the proper
1069 order; constructors are run from right to left, and the
1070 linker sorts in increasing order. */
1071 MAX_INIT_PRIORITY
- priority
);
1075 named_section_flags (section
, SECTION_WRITE
);
1076 assemble_align (POINTER_SIZE
);
1077 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1080 #ifdef DTORS_SECTION_ASM_OP
1084 if (in_section
!= in_dtors
)
1086 in_section
= in_dtors
;
1087 fputs (DTORS_SECTION_ASM_OP
, asm_out_file
);
1088 fputc ('\n', asm_out_file
);
1093 default_dtor_section_asm_out_destructor (symbol
, priority
)
1095 int priority ATTRIBUTE_UNUSED
;
1098 assemble_align (POINTER_SIZE
);
1099 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1103 /* Likewise for global constructors. */
1106 default_stabs_asm_out_constructor (symbol
, priority
)
1108 int priority ATTRIBUTE_UNUSED
;
1110 /* Tell GNU LD that this is part of the static destructor set.
1111 This will work for any system that uses stabs, most usefully
1113 fprintf (asm_out_file
, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1114 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1115 fputc ('\n', asm_out_file
);
1119 default_named_section_asm_out_constructor (symbol
, priority
)
1123 const char *section
= ".ctors";
1126 /* ??? This only works reliably with the GNU linker. */
1127 if (priority
!= DEFAULT_INIT_PRIORITY
)
1129 sprintf (buf
, ".ctors.%.5u",
1130 /* Invert the numbering so the linker puts us in the proper
1131 order; constructors are run from right to left, and the
1132 linker sorts in increasing order. */
1133 MAX_INIT_PRIORITY
- priority
);
1137 named_section_flags (section
, SECTION_WRITE
);
1138 assemble_align (POINTER_SIZE
);
1139 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1142 #ifdef CTORS_SECTION_ASM_OP
1146 if (in_section
!= in_ctors
)
1148 in_section
= in_ctors
;
1149 fputs (CTORS_SECTION_ASM_OP
, asm_out_file
);
1150 fputc ('\n', asm_out_file
);
1155 default_ctor_section_asm_out_constructor (symbol
, priority
)
1157 int priority ATTRIBUTE_UNUSED
;
1160 assemble_align (POINTER_SIZE
);
1161 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1165 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1166 a non-zero value if the constant pool should be output before the
1167 start of the function, or a zero value if the pool should output
1168 after the end of the function. The default is to put it before the
1171 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1172 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1175 /* Output assembler code for the constant pool of a function and associated
1176 with defining the name of the function. DECL describes the function.
1177 NAME is the function's name. For the constant pool, we use the current
1178 constant pool data. */
1181 assemble_start_function (decl
, fnname
)
1187 /* The following code does not need preprocessing in the assembler. */
1191 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1192 output_constant_pool (fnname
, decl
);
1194 resolve_unique_section (decl
, 0);
1195 function_section (decl
);
1197 /* Tell assembler to move to target machine's alignment for functions. */
1198 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1201 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1204 /* Handle a user-specified function alignment.
1205 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1206 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1207 if (align_functions_log
> align
)
1209 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1210 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1211 align_functions_log
, align_functions
-1);
1213 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1217 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1218 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1221 (*debug_hooks
->begin_function
) (decl
);
1223 /* Make function name accessible from other files, if appropriate. */
1225 if (TREE_PUBLIC (decl
))
1227 if (! first_global_object_name
)
1232 STRIP_NAME_ENCODING (p
, fnname
);
1233 name
= permalloc (strlen (p
) + 1);
1236 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1237 first_global_object_name
= name
;
1239 weak_global_object_name
= name
;
1242 #ifdef ASM_WEAKEN_LABEL
1243 if (DECL_WEAK (decl
))
1245 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
1246 /* Remove this function from the pending weak list so that
1247 we do not emit multiple .weak directives for it. */
1248 remove_from_pending_weak_list
1249 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1253 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
1256 /* Do any machine/system dependent processing of the function name */
1257 #ifdef ASM_DECLARE_FUNCTION_NAME
1258 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1260 /* Standard thing is just output label for the function. */
1261 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1262 #endif /* ASM_DECLARE_FUNCTION_NAME */
1265 /* Output assembler code associated with defining the size of the
1266 function. DECL describes the function. NAME is the function's name. */
1269 assemble_end_function (decl
, fnname
)
1273 #ifdef ASM_DECLARE_FUNCTION_SIZE
1274 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1276 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1278 output_constant_pool (fnname
, decl
);
1279 function_section (decl
); /* need to switch back */
1282 /* Output any constants which should appear after the function. */
1283 output_after_function_constants ();
1286 /* Assemble code to leave SIZE bytes of zeros. */
1289 assemble_zeros (size
)
1292 /* Do no output if -fsyntax-only. */
1293 if (flag_syntax_only
)
1296 #ifdef ASM_NO_SKIP_IN_TEXT
1297 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1298 so we must output 0s explicitly in the text section. */
1299 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1302 for (i
= 0; i
< size
; i
++)
1303 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1308 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1311 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1314 assemble_align (align
)
1317 if (align
> BITS_PER_UNIT
)
1319 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1323 /* Assemble a string constant with the specified C string as contents. */
1326 assemble_string (p
, size
)
1333 /* If the string is very long, split it up. */
1337 int thissize
= size
- pos
;
1338 if (thissize
> maximum
)
1341 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1349 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1350 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1351 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1353 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1354 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1355 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1357 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1358 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1362 #if defined ASM_OUTPUT_ALIGNED_BSS
1363 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1364 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1366 #if defined ASM_OUTPUT_BSS
1367 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1368 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1374 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1375 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1376 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1378 #if defined ASM_OUTPUT_ALIGNED_COMMON
1379 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1380 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1382 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1383 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1388 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1391 int size ATTRIBUTE_UNUSED
;
1392 int rounded ATTRIBUTE_UNUSED
;
1400 destination
= asm_dest_local
;
1402 if (TREE_PUBLIC (decl
))
1404 #if defined ASM_EMIT_BSS
1405 if (! DECL_COMMON (decl
))
1406 destination
= asm_dest_bss
;
1409 destination
= asm_dest_common
;
1412 if (flag_shared_data
)
1414 switch (destination
)
1416 #ifdef ASM_OUTPUT_SHARED_BSS
1418 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1421 #ifdef ASM_OUTPUT_SHARED_COMMON
1422 case asm_dest_common
:
1423 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1426 #ifdef ASM_OUTPUT_SHARED_LOCAL
1427 case asm_dest_local
:
1428 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1436 resolve_unique_section (decl
, 0);
1438 switch (destination
)
1442 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1445 case asm_dest_common
:
1446 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1448 case asm_dest_local
:
1449 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1458 /* Assemble everything that is needed for a variable or function declaration.
1459 Not used for automatic variables, and not used for function definitions.
1460 Should not be called for variables of incomplete structure type.
1462 TOP_LEVEL is nonzero if this variable has file scope.
1463 AT_END is nonzero if this is the special handling, at end of compilation,
1464 to define things that have had only tentative definitions.
1465 DONT_OUTPUT_DATA if nonzero means don't actually output the
1466 initial value (that will be done by the caller). */
1469 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1471 int top_level ATTRIBUTE_UNUSED
;
1472 int at_end ATTRIBUTE_UNUSED
;
1473 int dont_output_data
;
1480 last_assemble_variable_decl
= 0;
1482 /* Normally no need to say anything here for external references,
1483 since assemble_external is called by the language-specific code
1484 when a declaration is first seen. */
1486 if (DECL_EXTERNAL (decl
))
1489 /* Output no assembler code for a function declaration.
1490 Only definitions of functions output anything. */
1492 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1495 /* Do nothing for global register variables. */
1496 if (DECL_RTL_SET_P (decl
) && GET_CODE (DECL_RTL (decl
)) == REG
)
1498 TREE_ASM_WRITTEN (decl
) = 1;
1502 /* If type was incomplete when the variable was declared,
1503 see if it is complete now. */
1505 if (DECL_SIZE (decl
) == 0)
1506 layout_decl (decl
, 0);
1508 /* Still incomplete => don't allocate it; treat the tentative defn
1509 (which is what it must have been) as an `extern' reference. */
1511 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1513 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1514 DECL_SOURCE_LINE (decl
),
1515 "storage size of `%s' isn't known",
1516 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1517 TREE_ASM_WRITTEN (decl
) = 1;
1521 /* The first declaration of a variable that comes through this function
1522 decides whether it is global (in C, has external linkage)
1523 or local (in C, has internal linkage). So do nothing more
1524 if this function has already run. */
1526 if (TREE_ASM_WRITTEN (decl
))
1529 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1530 decl_rtl
= DECL_RTL (decl
);
1532 TREE_ASM_WRITTEN (decl
) = 1;
1534 /* Do no output if -fsyntax-only. */
1535 if (flag_syntax_only
)
1540 if (! dont_output_data
1541 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1543 error_with_decl (decl
, "size of variable `%s' is too large");
1547 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1548 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1549 && ! first_global_object_name
1550 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1551 || DECL_INITIAL (decl
) == error_mark_node
))
1552 && ! DECL_WEAK (decl
)
1553 && ! DECL_ONE_ONLY (decl
))
1558 STRIP_NAME_ENCODING (p
, name
);
1559 xname
= permalloc (strlen (p
) + 1);
1561 first_global_object_name
= xname
;
1564 /* Compute the alignment of this data. */
1566 align
= DECL_ALIGN (decl
);
1568 /* In the case for initialing an array whose length isn't specified,
1569 where we have not yet been able to do the layout,
1570 figure out the proper alignment now. */
1571 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1572 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1573 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1575 /* Some object file formats have a maximum alignment which they support.
1576 In particular, a.out format supports a maximum alignment of 4. */
1577 #ifndef MAX_OFILE_ALIGNMENT
1578 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1580 if (align
> MAX_OFILE_ALIGNMENT
)
1582 warning_with_decl (decl
,
1583 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1584 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1585 align
= MAX_OFILE_ALIGNMENT
;
1588 /* On some machines, it is good to increase alignment sometimes. */
1589 if (! DECL_USER_ALIGN (decl
))
1591 #ifdef DATA_ALIGNMENT
1592 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1594 #ifdef CONSTANT_ALIGNMENT
1595 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1596 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1600 /* Reset the alignment in case we have made it tighter, so we can benefit
1601 from it in get_pointer_alignment. */
1602 DECL_ALIGN (decl
) = align
;
1603 set_mem_align (decl_rtl
, align
);
1605 /* Handle uninitialized definitions. */
1607 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
)
1608 /* If the target can't output uninitialized but not common global data
1609 in .bss, then we have to use .data. */
1610 #if ! defined ASM_EMIT_BSS
1611 && DECL_COMMON (decl
)
1613 && DECL_SECTION_NAME (decl
) == NULL_TREE
1614 && ! dont_output_data
)
1616 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1617 unsigned HOST_WIDE_INT rounded
= size
;
1619 /* Don't allocate zero bytes of common,
1620 since that means "undefined external" in the linker. */
1624 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1625 so that each uninitialized object starts on such a boundary. */
1626 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1627 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1628 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1630 /* Don't continue this line--convex cc version 4.1 would lose. */
1631 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1632 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN (decl
) / BITS_PER_UNIT
> rounded
)
1634 (decl
, "requested alignment for %s is greater than implemented alignment of %d",rounded
);
1637 asm_emit_uninitialised (decl
, name
, size
, rounded
);
1642 /* Handle initialized definitions.
1643 Also handle uninitialized global definitions if -fno-common and the
1644 target doesn't support ASM_OUTPUT_BSS. */
1646 /* First make the assembler name(s) global if appropriate. */
1647 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1649 #ifdef ASM_WEAKEN_LABEL
1650 if (DECL_WEAK (decl
))
1652 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1653 /* Remove this variable from the pending weak list so that
1654 we do not emit multiple .weak directives for it. */
1655 remove_from_pending_weak_list
1656 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1660 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1663 /* Output any data that we will need to use the address of. */
1664 if (DECL_INITIAL (decl
) == error_mark_node
)
1665 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1666 else if (DECL_INITIAL (decl
))
1667 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1669 /* Switch to the appropriate section. */
1670 resolve_unique_section (decl
, reloc
);
1671 variable_section (decl
, reloc
);
1673 /* dbxout.c needs to know this. */
1674 if (in_text_section ())
1675 DECL_IN_TEXT_SECTION (decl
) = 1;
1677 /* Output the alignment of this data. */
1678 if (align
> BITS_PER_UNIT
)
1680 ASM_OUTPUT_ALIGN (asm_out_file
,
1681 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1684 /* Do any machine/system dependent processing of the object. */
1685 #ifdef ASM_DECLARE_OBJECT_NAME
1686 last_assemble_variable_decl
= decl
;
1687 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1689 /* Standard thing is just output label for the object. */
1690 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1691 #endif /* ASM_DECLARE_OBJECT_NAME */
1693 if (!dont_output_data
)
1695 if (DECL_INITIAL (decl
))
1696 /* Output the actual data. */
1697 output_constant (DECL_INITIAL (decl
),
1698 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1701 /* Leave space for it. */
1702 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1706 /* Return 1 if type TYPE contains any pointers. */
1709 contains_pointers_p (type
)
1712 switch (TREE_CODE (type
))
1715 case REFERENCE_TYPE
:
1716 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1717 so I'll play safe and return 1. */
1723 case QUAL_UNION_TYPE
:
1726 /* For a type that has fields, see if the fields have pointers. */
1727 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1728 if (TREE_CODE (fields
) == FIELD_DECL
1729 && contains_pointers_p (TREE_TYPE (fields
)))
1735 /* An array type contains pointers if its element type does. */
1736 return contains_pointers_p (TREE_TYPE (type
));
1743 /* Output something to declare an external symbol to the assembler.
1744 (Most assemblers don't need this, so we normally output nothing.)
1745 Do nothing if DECL is not external. */
1748 assemble_external (decl
)
1749 tree decl ATTRIBUTE_UNUSED
;
1751 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1752 main body of this code is only rarely exercised. To provide some
1753 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1754 open. If it's not, we should not be calling this function. */
1758 #ifdef ASM_OUTPUT_EXTERNAL
1759 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1761 rtx rtl
= DECL_RTL (decl
);
1763 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1764 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1766 /* Some systems do require some output. */
1767 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1768 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1774 /* Similar, for calling a library function FUN. */
1777 assemble_external_libcall (fun
)
1778 rtx fun ATTRIBUTE_UNUSED
;
1780 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1781 /* Declare library function name external when first used, if nec. */
1782 if (! SYMBOL_REF_USED (fun
))
1784 SYMBOL_REF_USED (fun
) = 1;
1785 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1790 /* Declare the label NAME global. */
1793 assemble_global (name
)
1794 const char *name ATTRIBUTE_UNUSED
;
1796 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1799 /* Assemble a label named NAME. */
1802 assemble_label (name
)
1805 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1808 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1809 If NAME starts with a *, the rest of NAME is output verbatim.
1810 Otherwise NAME is transformed in an implementation-defined way
1811 (usually by the addition of an underscore).
1812 Many macros in the tm file are defined to call this function. */
1815 assemble_name (file
, name
)
1819 const char *real_name
;
1822 STRIP_NAME_ENCODING (real_name
, name
);
1824 id
= maybe_get_identifier (real_name
);
1826 TREE_SYMBOL_REFERENCED (id
) = 1;
1829 fputs (&name
[1], file
);
1831 ASM_OUTPUT_LABELREF (file
, name
);
1834 /* Allocate SIZE bytes writable static space with a gensym name
1835 and return an RTX to refer to its address. */
1838 assemble_static_space (size
)
1842 const char *namestring
;
1846 if (flag_shared_data
)
1850 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1852 namestring
= ggc_strdup (name
);
1854 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1856 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1857 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1860 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1861 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1864 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1865 so that each uninitialized object starts on such a boundary. */
1866 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1867 int rounded ATTRIBUTE_UNUSED
1868 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1869 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1870 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1871 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1878 /* Assemble the static constant template for function entry trampolines.
1879 This is done at most once per compilation.
1880 Returns an RTX for the address of the template. */
1882 #ifdef TRAMPOLINE_TEMPLATE
1884 assemble_trampoline_template ()
1890 /* By default, put trampoline templates in read-only data section. */
1892 #ifdef TRAMPOLINE_SECTION
1893 TRAMPOLINE_SECTION ();
1895 readonly_data_section ();
1898 /* Write the assembler code to define one. */
1899 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1902 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1905 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1906 TRAMPOLINE_TEMPLATE (asm_out_file
);
1908 /* Record the rtl to refer to it. */
1909 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1910 name
= ggc_strdup (label
);
1911 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1915 /* A and B are either alignments or offsets. Return the minimum alignment
1916 that may be assumed after adding the two together. */
1918 static inline unsigned
1922 return (a
| b
) & -(a
| b
);
1925 /* Return the assembler directive for creating a given kind of integer
1926 object. SIZE is the number of bytes in the object and ALIGNED_P
1927 indicates whether it is known to be aligned. Return NULL if the
1928 assembly dialect has no such directive.
1930 The returned string should be printed at the start of a new line and
1931 be followed immediately by the object's initial value. */
1934 integer_asm_op (size
, aligned_p
)
1938 struct asm_int_op
*ops
;
1941 ops
= &targetm
.asm_out
.aligned_op
;
1943 ops
= &targetm
.asm_out
.unaligned_op
;
1948 return targetm
.asm_out
.byte_op
;
1962 /* Use directive OP to assemble an integer object X. Print OP at the
1963 start of the line, followed immediately by the value of X. */
1966 assemble_integer_with_op (op
, x
)
1970 fputs (op
, asm_out_file
);
1971 output_addr_const (asm_out_file
, x
);
1972 fputc ('\n', asm_out_file
);
1975 /* The default implementation of the asm_out.integer target hook. */
1978 default_assemble_integer (x
, size
, aligned_p
)
1979 rtx x ATTRIBUTE_UNUSED
;
1980 unsigned int size ATTRIBUTE_UNUSED
;
1981 int aligned_p ATTRIBUTE_UNUSED
;
1983 const char *op
= integer_asm_op (size
, aligned_p
);
1984 return op
&& (assemble_integer_with_op (op
, x
), true);
1987 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1988 the alignment of the integer in bits. Return 1 if we were able to output
1989 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1993 assemble_integer (x
, size
, align
, force
)
2001 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2003 /* See if the target hook can handle this kind of object. */
2004 if ((*targetm
.asm_out
.integer
) (x
, size
, aligned_p
))
2007 /* If the object is a multi-byte one, try splitting it up. Split
2008 it into words it if is multi-word, otherwise split it into bytes. */
2011 enum machine_mode omode
, imode
;
2012 unsigned int subalign
;
2013 unsigned int subsize
, i
;
2015 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2016 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2017 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
2018 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2020 for (i
= 0; i
< size
; i
+= subsize
)
2022 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2023 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2029 /* If we've printed some of it, but not all of it, there's no going
2041 /* Assemble the floating-point constant D into an object of size MODE. */
2042 struct assemble_real_args
2045 enum machine_mode mode
;
2052 struct assemble_real_args
*args
= (struct assemble_real_args
*) p
;
2053 REAL_VALUE_TYPE
*d
= args
->d
;
2054 enum machine_mode mode
= args
->mode
;
2058 #ifdef ASM_OUTPUT_BYTE_FLOAT
2060 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, *d
);
2063 #ifdef ASM_OUTPUT_SHORT_FLOAT
2065 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, *d
);
2068 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2070 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, *d
);
2073 #ifdef ASM_OUTPUT_FLOAT
2075 ASM_OUTPUT_FLOAT (asm_out_file
, *d
);
2079 #ifdef ASM_OUTPUT_DOUBLE
2081 ASM_OUTPUT_DOUBLE (asm_out_file
, *d
);
2085 #ifdef ASM_OUTPUT_LONG_DOUBLE
2088 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, *d
);
2098 assemble_real (d
, mode
, align
)
2100 enum machine_mode mode
;
2103 struct assemble_real_args args
;
2107 /* We cannot emit unaligned floating point constants. This is slightly
2108 complicated in that we don't know what "unaligned" means exactly. */
2109 #ifdef BIGGEST_FIELD_ALIGNMENT
2110 if (align
>= BIGGEST_FIELD_ALIGNMENT
)
2114 if (align
< GET_MODE_ALIGNMENT (mode
))
2117 if (do_float_handler (assemble_real_1
, (PTR
) &args
))
2120 internal_error ("floating point trap outputting a constant");
2123 /* Here we combine duplicate floating constants to make
2124 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2126 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2127 For an integer, I0 is the low-order word and I1 is the high-order word.
2128 For a real number, I0 is the word with the low address
2129 and I1 is the word with the high address. */
2132 immed_double_const (i0
, i1
, mode
)
2133 HOST_WIDE_INT i0
, i1
;
2134 enum machine_mode mode
;
2138 if (GET_MODE_CLASS (mode
) == MODE_INT
2139 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
2141 /* We clear out all bits that don't belong in MODE, unless they and our
2142 sign bit are all one. So we get either a reasonable negative value
2143 or a reasonable unsigned value for this mode. */
2144 int width
= GET_MODE_BITSIZE (mode
);
2145 if (width
< HOST_BITS_PER_WIDE_INT
2146 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
2147 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
2148 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
2149 else if (width
== HOST_BITS_PER_WIDE_INT
2150 && ! (i1
== ~0 && i0
< 0))
2152 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
2153 /* We cannot represent this value as a constant. */
2156 /* If this would be an entire word for the target, but is not for
2157 the host, then sign-extend on the host so that the number will look
2158 the same way on the host that it would on the target.
2160 For example, when building a 64 bit alpha hosted 32 bit sparc
2161 targeted compiler, then we want the 32 bit unsigned value -1 to be
2162 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2163 The later confuses the sparc backend. */
2165 if (width
< HOST_BITS_PER_WIDE_INT
2166 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
2167 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
2169 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2171 ??? Strictly speaking, this is wrong if we create a CONST_INT
2172 for a large unsigned constant with the size of MODE being
2173 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2174 wider mode. In that case we will mis-interpret it as a negative
2177 Unfortunately, the only alternative is to make a CONST_DOUBLE
2178 for any constant in any mode if it is an unsigned constant larger
2179 than the maximum signed integer in an int on the host. However,
2180 doing this will break everyone that always expects to see a CONST_INT
2181 for SImode and smaller.
2183 We have always been making CONST_INTs in this case, so nothing new
2186 if (width
<= HOST_BITS_PER_WIDE_INT
)
2187 i1
= (i0
< 0) ? ~(HOST_WIDE_INT
) 0 : 0;
2189 /* If this integer fits in one word, return a CONST_INT. */
2190 if ((i1
== 0 && i0
>= 0)
2191 || (i1
== ~0 && i0
< 0))
2192 return GEN_INT (i0
);
2194 /* We use VOIDmode for integers. */
2198 /* Search the chain for an existing CONST_DOUBLE with the right value.
2199 If one is found, return it. */
2201 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2202 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
2203 && GET_MODE (r
) == mode
)
2206 /* No; make a new one and add it to the chain. */
2207 r
= gen_rtx_CONST_DOUBLE (mode
, i0
, i1
);
2209 /* Don't touch const_double_chain if not inside any function. */
2210 if (current_function_decl
!= 0)
2212 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2213 const_double_chain
= r
;
2219 /* Return a CONST_DOUBLE for a specified `double' value
2220 and machine mode. */
2223 immed_real_const_1 (d
, mode
)
2225 enum machine_mode mode
;
2227 union real_extract u
;
2230 /* Get the desired `double' value as a sequence of ints
2231 since that is how they are stored in a CONST_DOUBLE. */
2235 /* Detect special cases. Check for NaN first, because some ports
2236 (specifically the i386) do not emit correct ieee-fp code by default, and
2237 thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2238 and if REAL_VALUES_EQUAL does a floating point comparison. */
2239 if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_IDENTICAL (dconst0
, d
))
2240 return CONST0_RTX (mode
);
2241 else if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
2242 return CONST1_RTX (mode
);
2243 else if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst2
, d
))
2244 return CONST2_RTX (mode
);
2246 if (sizeof u
== sizeof (HOST_WIDE_INT
))
2247 return immed_double_const (u
.i
[0], 0, mode
);
2248 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
2249 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
2251 /* The rest of this function handles the case where
2252 a float value requires more than 2 ints of space.
2253 It will be deleted as dead code on machines that don't need it. */
2255 /* Search the chain for an existing CONST_DOUBLE with the right value.
2256 If one is found, return it. */
2258 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2259 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
2260 && GET_MODE (r
) == mode
)
2263 /* No; make a new one and add it to the chain.
2265 We may be called by an optimizer which may be discarding any memory
2266 allocated during its processing (such as combine and loop). However,
2267 we will be leaving this constant on the chain, so we cannot tolerate
2269 r
= rtx_alloc (CONST_DOUBLE
);
2271 memcpy ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
);
2273 /* If we aren't inside a function, don't put r on the
2274 const_double_chain. */
2275 if (current_function_decl
!= 0)
2277 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2278 const_double_chain
= r
;
2281 CONST_DOUBLE_CHAIN (r
) = NULL_RTX
;
2286 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2287 which must be a REAL_CST tree node. */
2290 immed_real_const (exp
)
2293 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
2296 /* At the end of a function, forget the memory-constants
2297 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2298 Also clear out real_constant_chain and clear out all the chain-pointers. */
2301 clear_const_double_mem ()
2305 for (r
= const_double_chain
; r
; r
= next
)
2307 next
= CONST_DOUBLE_CHAIN (r
);
2308 CONST_DOUBLE_CHAIN (r
) = 0;
2310 const_double_chain
= 0;
2313 /* Given an expression EXP with a constant value,
2314 reduce it to the sum of an assembler symbol and an integer.
2315 Store them both in the structure *VALUE.
2316 Abort if EXP does not reduce. */
2321 HOST_WIDE_INT offset
;
2325 decode_addr_const (exp
, value
)
2327 struct addr_const
*value
;
2329 tree target
= TREE_OPERAND (exp
, 0);
2335 if (TREE_CODE (target
) == COMPONENT_REF
2336 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2339 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2340 target
= TREE_OPERAND (target
, 0);
2342 else if (TREE_CODE (target
) == ARRAY_REF
2343 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2345 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2346 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2347 target
= TREE_OPERAND (target
, 0);
2353 switch (TREE_CODE (target
))
2357 x
= DECL_RTL (target
);
2361 x
= gen_rtx_MEM (FUNCTION_MODE
,
2362 gen_rtx_LABEL_REF (VOIDmode
,
2363 label_rtx (TREE_OPERAND (exp
, 0))));
2371 x
= TREE_CST_RTL (target
);
2378 if (GET_CODE (x
) != MEM
)
2383 value
->offset
= offset
;
2386 enum kind
{ RTX_DOUBLE
, RTX_INT
};
2389 ENUM_BITFIELD(kind
) kind
: 16;
2390 ENUM_BITFIELD(machine_mode
) mode
: 16;
2392 union real_extract du
;
2393 struct addr_const addr
;
2394 struct {HOST_WIDE_INT high
, low
;} di
;
2398 /* Uniquize all constants that appear in memory.
2399 Each constant in memory thus far output is recorded
2400 in `const_hash_table' with a `struct constant_descriptor'
2401 that contains a polish representation of the value of
2404 We cannot store the trees in the hash table
2405 because the trees may be temporary. */
2407 struct constant_descriptor
2409 struct constant_descriptor
*next
;
2412 /* Make sure the data is reasonably aligned. */
2415 unsigned char contents
[1];
2416 #ifdef HAVE_LONG_DOUBLE
2425 #define MAX_HASH_TABLE 1009
2426 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2428 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2429 out a string constant, we defer output of the constants until we know
2430 they are actually used. This will be if something takes its address or if
2431 there is a usage of the string in the RTL of a function. */
2433 #define STRHASH(x) ((hashval_t)((long)(x) >> 3))
2435 struct deferred_string
2442 static htab_t const_str_htab
;
2444 /* Mark a const_hash_table descriptor for GC. */
2447 mark_const_hash_entry (ptr
)
2450 struct constant_descriptor
*desc
= * (struct constant_descriptor
**) ptr
;
2454 ggc_mark_rtx (desc
->rtl
);
2459 /* Mark the hash-table element X (which is really a pointer to an
2460 struct deferred_string *). */
2463 mark_const_str_htab_1 (x
, data
)
2465 void *data ATTRIBUTE_UNUSED
;
2467 ggc_mark_tree (((struct deferred_string
*) *x
)->exp
);
2471 /* Mark a const_str_htab for GC. */
2474 mark_const_str_htab (htab
)
2477 htab_traverse (*((htab_t
*) htab
), mark_const_str_htab_1
, NULL
);
2480 /* Returns a hash code for X (which is a really a
2481 struct deferred_string *). */
2484 const_str_htab_hash (x
)
2487 return STRHASH (((const struct deferred_string
*) x
)->label
);
2490 /* Returns non-zero if the value represented by X (which is really a
2491 struct deferred_string *) is the same as that given by Y
2492 (which is really a char *). */
2495 const_str_htab_eq (x
, y
)
2499 return (((const struct deferred_string
*) x
)->label
== (const char *) y
);
2502 /* Delete the hash table entry dfsp. */
2505 const_str_htab_del (dfsp
)
2511 /* Compute a hash code for a constant expression. */
2519 enum tree_code code
= TREE_CODE (exp
);
2521 /* Either set P and LEN to the address and len of something to hash and
2522 exit the switch or return a value. */
2527 p
= (char *) &TREE_INT_CST (exp
);
2528 len
= sizeof TREE_INT_CST (exp
);
2532 p
= (char *) &TREE_REAL_CST (exp
);
2533 len
= sizeof TREE_REAL_CST (exp
);
2537 p
= TREE_STRING_POINTER (exp
);
2538 len
= TREE_STRING_LENGTH (exp
);
2542 return (const_hash (TREE_REALPART (exp
)) * 5
2543 + const_hash (TREE_IMAGPART (exp
)));
2546 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2550 len
= int_size_in_bytes (TREE_TYPE (exp
));
2551 tmp
= (char *) alloca (len
);
2552 get_set_constructor_bytes (exp
, (unsigned char *) tmp
, len
);
2560 /* For record type, include the type in the hashing.
2561 We do not do so for array types
2562 because (1) the sizes of the elements are sufficient
2563 and (2) distinct array types can have the same constructor.
2564 Instead, we include the array size because the constructor could
2566 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2567 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2570 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2571 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2573 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2574 if (TREE_VALUE (link
))
2576 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2583 struct addr_const value
;
2585 decode_addr_const (exp
, &value
);
2586 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2588 /* Don't hash the address of the SYMBOL_REF;
2589 only use the offset and the symbol name. */
2591 p
= XSTR (value
.base
, 0);
2592 for (i
= 0; p
[i
] != 0; i
++)
2593 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2595 else if (GET_CODE (value
.base
) == LABEL_REF
)
2596 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2600 hi
&= (1 << HASHBITS
) - 1;
2601 hi
%= MAX_HASH_TABLE
;
2607 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2608 + const_hash (TREE_OPERAND (exp
, 1)));
2612 case NON_LVALUE_EXPR
:
2613 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2616 /* A language specific constant. Just hash the code. */
2617 return (int) code
% MAX_HASH_TABLE
;
2620 /* Compute hashing function */
2622 for (i
= 0; i
< len
; i
++)
2623 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2625 hi
&= (1 << HASHBITS
) - 1;
2626 hi
%= MAX_HASH_TABLE
;
2630 /* Compare a constant expression EXP with a constant-descriptor DESC.
2631 Return 1 if DESC describes a constant with the same value as EXP. */
2634 compare_constant (exp
, desc
)
2636 struct constant_descriptor
*desc
;
2638 return 0 != compare_constant_1 (exp
, desc
->u
.contents
);
2641 /* Compare constant expression EXP with a substring P of a constant descriptor.
2642 If they match, return a pointer to the end of the substring matched.
2643 If they do not match, return 0.
2645 Since descriptors are written in polish prefix notation,
2646 this function can be used recursively to test one operand of EXP
2647 against a subdescriptor, and if it succeeds it returns the
2648 address of the subdescriptor for the next operand. */
2650 static const unsigned char *
2651 compare_constant_1 (exp
, p
)
2653 const unsigned char *p
;
2655 const unsigned char *strp
;
2657 enum tree_code code
= TREE_CODE (exp
);
2659 if (code
!= (enum tree_code
) *p
++)
2662 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2663 switch, or return the result of the comparison. */
2668 /* Integer constants are the same only if the same width of type. */
2669 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2672 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2673 len
= sizeof TREE_INT_CST (exp
);
2677 /* Real constants are the same only if the same width of type. */
2678 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2681 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2682 len
= sizeof TREE_REAL_CST (exp
);
2686 if (flag_writable_strings
)
2689 if ((enum machine_mode
) *p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2692 strp
= (const unsigned char *)TREE_STRING_POINTER (exp
);
2693 len
= TREE_STRING_LENGTH (exp
);
2694 if (memcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2695 sizeof TREE_STRING_LENGTH (exp
)))
2698 p
+= sizeof TREE_STRING_LENGTH (exp
);
2702 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2706 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2709 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2711 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2712 unsigned char *tmp
= (unsigned char *) alloca (len
);
2714 get_set_constructor_bytes (exp
, tmp
, len
);
2715 strp
= (unsigned char *) tmp
;
2716 if (memcmp ((char *) &xlen
, p
, sizeof xlen
))
2725 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2727 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2728 int have_purpose
= 0;
2730 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2731 if (TREE_PURPOSE (link
))
2734 if (memcmp ((char *) &length
, p
, sizeof length
))
2739 /* For record constructors, insist that the types match.
2740 For arrays, just verify both constructors are for arrays.
2741 Then insist that either both or none have any TREE_PURPOSE
2743 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2744 type
= TREE_TYPE (exp
);
2748 if (memcmp ((char *) &type
, p
, sizeof type
))
2751 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2753 if (memcmp ((char *) &mode
, p
, sizeof mode
))
2761 if (memcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2764 p
+= sizeof have_purpose
;
2766 /* For arrays, insist that the size in bytes match. */
2767 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2769 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2771 if (memcmp ((char *) &size
, p
, sizeof size
))
2777 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2779 if (TREE_VALUE (link
))
2781 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2788 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2794 if (TREE_PURPOSE (link
)
2795 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2797 if (memcmp ((char *) &TREE_PURPOSE (link
), p
,
2798 sizeof TREE_PURPOSE (link
)))
2801 p
+= sizeof TREE_PURPOSE (link
);
2803 else if (TREE_PURPOSE (link
))
2805 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2808 else if (have_purpose
)
2812 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2824 struct addr_const value
;
2826 decode_addr_const (exp
, &value
);
2827 strp
= (unsigned char *) &value
.offset
;
2828 len
= sizeof value
.offset
;
2829 /* Compare the offset. */
2831 if (*p
++ != *strp
++)
2834 /* Compare symbol name. */
2835 strp
= (const unsigned char *) XSTR (value
.base
, 0);
2836 len
= strlen ((const char *) strp
) + 1;
2843 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2847 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2851 case NON_LVALUE_EXPR
:
2852 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2856 tree
new = (*lang_hooks
.expand_constant
) (exp
);
2859 return compare_constant_1 (new, p
);
2865 /* Compare constant contents. */
2867 if (*p
++ != *strp
++)
2873 /* Construct a constant descriptor for the expression EXP.
2874 It is up to the caller to enter the descriptor in the hash table. */
2876 static struct constant_descriptor
*
2877 record_constant (exp
)
2880 struct constant_descriptor
*next
= 0;
2885 /* Make a struct constant_descriptor. The first three pointers will
2886 be filled in later. Here we just leave space for them. */
2888 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2889 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2890 obstack_grow (&permanent_obstack
, (char *) &rtl
, sizeof rtl
);
2892 /* Align the descriptor for the data payload. */
2893 pad
= (offsetof (struct constant_descriptor
, u
)
2894 - offsetof(struct constant_descriptor
, rtl
)
2895 - sizeof(next
->rtl
));
2897 obstack_blank (&permanent_obstack
, pad
);
2899 record_constant_1 (exp
);
2900 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2903 /* Add a description of constant expression EXP
2904 to the object growing in `permanent_obstack'.
2905 No need to return its address; the caller will get that
2906 from the obstack when the object is complete. */
2909 record_constant_1 (exp
)
2912 const unsigned char *strp
;
2914 enum tree_code code
= TREE_CODE (exp
);
2916 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2921 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2922 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2923 len
= sizeof TREE_INT_CST (exp
);
2927 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2928 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2929 len
= sizeof TREE_REAL_CST (exp
);
2933 if (flag_writable_strings
)
2936 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2937 strp
= (const unsigned char *) TREE_STRING_POINTER (exp
);
2938 len
= TREE_STRING_LENGTH (exp
);
2939 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2940 sizeof TREE_STRING_LENGTH (exp
));
2944 record_constant_1 (TREE_REALPART (exp
));
2945 record_constant_1 (TREE_IMAGPART (exp
));
2949 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2951 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2952 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2953 obstack_blank (&permanent_obstack
, nbytes
);
2954 get_set_constructor_bytes
2955 (exp
, (unsigned char *) permanent_obstack
.next_free
-nbytes
,
2962 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2963 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2965 int have_purpose
= 0;
2967 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2968 if (TREE_PURPOSE (link
))
2971 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2973 /* For record constructors, insist that the types match.
2974 For arrays, just verify both constructors are for arrays
2975 of the same mode. Then insist that either both or none
2976 have any TREE_PURPOSE values. */
2977 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2978 type
= TREE_TYPE (exp
);
2982 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2983 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2984 obstack_grow (&permanent_obstack
, &mode
, sizeof mode
);
2986 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2987 sizeof have_purpose
);
2989 /* For arrays, insist that the size in bytes match. */
2990 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2992 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2993 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2996 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2998 if (TREE_VALUE (link
))
2999 record_constant_1 (TREE_VALUE (link
));
3004 obstack_grow (&permanent_obstack
,
3005 (char *) &zero
, sizeof zero
);
3008 if (TREE_PURPOSE (link
)
3009 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
3010 obstack_grow (&permanent_obstack
,
3011 (char *) &TREE_PURPOSE (link
),
3012 sizeof TREE_PURPOSE (link
));
3013 else if (TREE_PURPOSE (link
))
3014 record_constant_1 (TREE_PURPOSE (link
));
3015 else if (have_purpose
)
3019 obstack_grow (&permanent_obstack
,
3020 (char *) &zero
, sizeof zero
);
3028 struct addr_const value
;
3030 decode_addr_const (exp
, &value
);
3031 /* Record the offset. */
3032 obstack_grow (&permanent_obstack
,
3033 (char *) &value
.offset
, sizeof value
.offset
);
3035 switch (GET_CODE (value
.base
))
3038 /* Record the symbol name. */
3039 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
3040 strlen (XSTR (value
.base
, 0)) + 1);
3043 /* Record the address of the CODE_LABEL. It may not have
3044 been emitted yet, so it's UID may be zero. But pointer
3045 identity is good enough. */
3046 obstack_grow (&permanent_obstack
, &XEXP (value
.base
, 0),
3058 record_constant_1 (TREE_OPERAND (exp
, 0));
3059 record_constant_1 (TREE_OPERAND (exp
, 1));
3064 case NON_LVALUE_EXPR
:
3065 record_constant_1 (TREE_OPERAND (exp
, 0));
3070 tree
new = (*lang_hooks
.expand_constant
) (exp
);
3073 record_constant_1 (exp
);
3078 /* Record constant contents. */
3079 obstack_grow (&permanent_obstack
, strp
, len
);
3082 /* Record a list of constant expressions that were passed to
3083 output_constant_def but that could not be output right away. */
3085 struct deferred_constant
3087 struct deferred_constant
*next
;
3093 static struct deferred_constant
*deferred_constants
;
3095 /* Another list of constants which should be output after the
3097 static struct deferred_constant
*after_function_constants
;
3099 /* Nonzero means defer output of addressed subconstants
3100 (i.e., those for which output_constant_def is called.) */
3101 static int defer_addressed_constants_flag
;
3103 /* Start deferring output of subconstants. */
3106 defer_addressed_constants ()
3108 defer_addressed_constants_flag
++;
3111 /* Stop deferring output of subconstants,
3112 and output now all those that have been deferred. */
3115 output_deferred_addressed_constants ()
3117 struct deferred_constant
*p
, *next
;
3119 defer_addressed_constants_flag
--;
3121 if (defer_addressed_constants_flag
> 0)
3124 for (p
= deferred_constants
; p
; p
= next
)
3126 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
3131 deferred_constants
= 0;
3134 /* Output any constants which should appear after a function. */
3137 output_after_function_constants ()
3139 struct deferred_constant
*p
, *next
;
3141 for (p
= after_function_constants
; p
; p
= next
)
3143 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
3148 after_function_constants
= 0;
3151 /* Make a copy of the whole tree structure for a constant.
3152 This handles the same types of nodes that compare_constant
3153 and record_constant handle. */
3159 switch (TREE_CODE (exp
))
3162 /* For ADDR_EXPR, we do not want to copy the decl whose address
3163 is requested. We do want to copy constants though. */
3164 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
3165 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3166 copy_constant (TREE_OPERAND (exp
, 0)));
3168 return copy_node (exp
);
3173 return copy_node (exp
);
3176 return build_complex (TREE_TYPE (exp
),
3177 copy_constant (TREE_REALPART (exp
)),
3178 copy_constant (TREE_IMAGPART (exp
)));
3182 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
3183 copy_constant (TREE_OPERAND (exp
, 0)),
3184 copy_constant (TREE_OPERAND (exp
, 1)));
3188 case NON_LVALUE_EXPR
:
3189 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3190 copy_constant (TREE_OPERAND (exp
, 0)));
3194 tree copy
= copy_node (exp
);
3195 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
3198 CONSTRUCTOR_ELTS (copy
) = list
;
3199 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3200 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
3201 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
3202 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3203 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
3213 /* Return an rtx representing a reference to constant data in memory
3214 for the constant expression EXP.
3216 If assembler code for such a constant has already been output,
3217 return an rtx to refer to it.
3218 Otherwise, output such a constant in memory (or defer it for later)
3219 and generate an rtx for it.
3221 If DEFER is non-zero, the output of string constants can be deferred
3222 and output only if referenced in the function after all optimizations.
3224 The TREE_CST_RTL of EXP is set up to point to that rtx.
3225 The const_hash_table records which constants already have label strings. */
3228 output_constant_def (exp
, defer
)
3233 struct constant_descriptor
*desc
;
3234 struct deferred_string
**defstr
;
3238 int after_function
= 0;
3242 /* We can't just use the saved RTL if this is a defererred string constant
3243 and we are not to defer anymode. */
3244 if (TREE_CODE (exp
) != INTEGER_CST
&& TREE_CST_RTL (exp
)
3245 && (defer
|| !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp
), 0))))
3246 return TREE_CST_RTL (exp
);
3248 /* Make sure any other constants whose addresses appear in EXP
3249 are assigned label numbers. */
3251 reloc
= output_addressed_constants (exp
);
3253 /* Compute hash code of EXP. Search the descriptors for that hash code
3254 to see if any of them describes EXP. If yes, the descriptor records
3255 the label number already assigned. */
3257 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
3259 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
3260 if (compare_constant (exp
, desc
))
3265 /* No constant equal to EXP is known to have been output.
3266 Make a constant descriptor to enter EXP in the hash table.
3267 Assign the label number and record it in the descriptor for
3268 future calls to this function to find. */
3270 /* Create a string containing the label name, in LABEL. */
3271 labelno
= const_labelno
++;
3272 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3274 desc
= record_constant (exp
);
3275 desc
->next
= const_hash_table
[hash
];
3276 desc
->label
= ggc_strdup (label
);
3277 const_hash_table
[hash
] = desc
;
3279 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3281 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
3282 gen_rtx_SYMBOL_REF (Pmode
, desc
->label
));
3284 set_mem_attributes (rtl
, exp
, 1);
3285 set_mem_alias_set (rtl
, 0);
3286 set_mem_alias_set (rtl
, const_alias_set
);
3293 if (TREE_CODE (exp
) != INTEGER_CST
)
3294 TREE_CST_RTL (exp
) = rtl
;
3296 /* Optionally set flags or add text to the name to record information
3297 such as that it is a function name. If the name is changed, the macro
3298 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3299 #ifdef ENCODE_SECTION_INFO
3300 /* A previously-processed constant would already have section info
3304 ENCODE_SECTION_INFO (exp
);
3306 desc
->label
= XSTR (XEXP (desc
->rtl
, 0), 0);
3310 #ifdef CONSTANT_AFTER_FUNCTION_P
3311 if (current_function_decl
!= 0
3312 && CONSTANT_AFTER_FUNCTION_P (exp
))
3317 && STRING_POOL_ADDRESS_P (XEXP (rtl
, 0))
3318 && (!defer
|| defer_addressed_constants_flag
|| after_function
))
3320 defstr
= (struct deferred_string
**)
3321 htab_find_slot_with_hash (const_str_htab
, desc
->label
,
3322 STRHASH (desc
->label
), NO_INSERT
);
3325 /* If the string is currently deferred but we need to output it now,
3326 remove it from deferred string hash table. */
3328 labelno
= (*defstr
)->labelno
;
3329 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 0;
3330 htab_clear_slot (const_str_htab
, (void **) defstr
);
3334 /* If this is the first time we've seen this particular constant,
3335 output it (or defer its output for later). */
3338 if (defer_addressed_constants_flag
|| after_function
)
3340 struct deferred_constant
*p
3341 = (struct deferred_constant
*)
3342 xmalloc (sizeof (struct deferred_constant
));
3344 p
->exp
= copy_constant (exp
);
3346 p
->labelno
= labelno
;
3349 p
->next
= after_function_constants
;
3350 after_function_constants
= p
;
3354 p
->next
= deferred_constants
;
3355 deferred_constants
= p
;
3360 /* Do no output if -fsyntax-only. */
3361 if (! flag_syntax_only
)
3363 if (TREE_CODE (exp
) != STRING_CST
3365 || flag_writable_strings
3366 || (defstr
= (struct deferred_string
**)
3367 htab_find_slot_with_hash (const_str_htab
,
3369 STRHASH (desc
->label
),
3371 output_constant_def_contents (exp
, reloc
, labelno
);
3374 struct deferred_string
*p
;
3376 p
= (struct deferred_string
*)
3377 xmalloc (sizeof (struct deferred_string
));
3379 p
->exp
= copy_constant (exp
);
3380 p
->label
= desc
->label
;
3381 p
->labelno
= labelno
;
3383 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 1;
3392 /* Now output assembler code to define the label for EXP,
3393 and follow it with the data of EXP. */
3396 output_constant_def_contents (exp
, reloc
, labelno
)
3403 /* Align the location counter as required by EXP's data type. */
3404 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3405 #ifdef CONSTANT_ALIGNMENT
3406 align
= CONSTANT_ALIGNMENT (exp
, align
);
3409 if (IN_NAMED_SECTION (exp
))
3410 named_section (exp
, NULL
, reloc
);
3413 /* First switch to text section, except for writable strings. */
3414 #ifdef SELECT_SECTION
3415 SELECT_SECTION (exp
, reloc
, align
);
3417 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
3418 || (flag_pic
&& reloc
))
3421 readonly_data_section ();
3425 if (align
> BITS_PER_UNIT
)
3427 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3430 /* Output the label itself. */
3431 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3433 /* Output the value of EXP. */
3434 output_constant (exp
,
3435 (TREE_CODE (exp
) == STRING_CST
3436 ? MAX (TREE_STRING_LENGTH (exp
),
3437 int_size_in_bytes (TREE_TYPE (exp
)))
3438 : int_size_in_bytes (TREE_TYPE (exp
))),
3443 /* Structure to represent sufficient information about a constant so that
3444 it can be output when the constant pool is output, so that function
3445 integration can be done, and to simplify handling on machines that reference
3446 constant pool as base+displacement. */
3448 struct pool_constant
3450 struct constant_descriptor
*desc
;
3451 struct pool_constant
*next
, *next_sym
;
3453 enum machine_mode mode
;
3456 HOST_WIDE_INT offset
;
3460 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3461 The argument is XSTR (... , 0) */
3463 #define SYMHASH(LABEL) \
3464 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3466 /* Initialize constant pool hashing for a new function. */
3469 init_varasm_status (f
)
3472 struct varasm_status
*p
;
3473 p
= (struct varasm_status
*) xmalloc (sizeof (struct varasm_status
));
3475 p
->x_const_rtx_hash_table
3476 = ((struct constant_descriptor
**)
3477 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct constant_descriptor
*)));
3478 p
->x_const_rtx_sym_hash_table
3479 = ((struct pool_constant
**)
3480 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct pool_constant
*)));
3482 p
->x_first_pool
= p
->x_last_pool
= 0;
3483 p
->x_pool_offset
= 0;
3484 p
->x_const_double_chain
= 0;
3487 /* Mark PC for GC. */
3490 mark_pool_constant (pc
)
3491 struct pool_constant
*pc
;
3496 ggc_mark_rtx (pc
->constant
);
3497 ggc_mark_rtx (pc
->desc
->rtl
);
3502 /* Mark P for GC. */
3505 mark_varasm_status (p
)
3506 struct varasm_status
*p
;
3511 mark_pool_constant (p
->x_first_pool
);
3512 ggc_mark_rtx (p
->x_const_double_chain
);
3515 /* Clear out all parts of the state in F that can safely be discarded
3516 after the function has been compiled, to let garbage collection
3517 reclaim the memory. */
3520 free_varasm_status (f
)
3523 struct varasm_status
*p
;
3528 /* Clear out the hash tables. */
3529 for (i
= 0; i
< MAX_RTX_HASH_TABLE
; ++i
)
3531 struct constant_descriptor
*cd
;
3533 cd
= p
->x_const_rtx_hash_table
[i
];
3536 struct constant_descriptor
*next
= cd
->next
;
3543 free (p
->x_const_rtx_hash_table
);
3544 free (p
->x_const_rtx_sym_hash_table
);
3551 /* Express an rtx for a constant integer (perhaps symbolic)
3552 as the sum of a symbol or label plus an explicit integer.
3553 They are stored into VALUE. */
3556 decode_rtx_const (mode
, x
, value
)
3557 enum machine_mode mode
;
3559 struct rtx_const
*value
;
3561 /* Clear the whole structure, including any gaps. */
3562 memset (value
, 0, sizeof (struct rtx_const
));
3564 value
->kind
= RTX_INT
; /* Most usual kind. */
3567 switch (GET_CODE (x
))
3570 value
->kind
= RTX_DOUBLE
;
3571 if (GET_MODE (x
) != VOIDmode
)
3573 value
->mode
= GET_MODE (x
);
3574 memcpy ((char *) &value
->un
.du
,
3575 (char *) &CONST_DOUBLE_LOW (x
), sizeof value
->un
.du
);
3579 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3580 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3585 value
->un
.addr
.offset
= INTVAL (x
);
3591 value
->un
.addr
.base
= x
;
3596 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3598 value
->un
.addr
.base
= XEXP (x
, 0);
3599 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3601 else if (GET_CODE (x
) == MINUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3603 value
->un
.addr
.base
= XEXP (x
, 0);
3604 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3608 value
->un
.addr
.base
= x
;
3609 value
->un
.addr
.offset
= 0;
3617 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3618 switch (GET_CODE (value
->un
.addr
.base
))
3621 /* Use the string's address, not the SYMBOL_REF's address,
3622 for the sake of addresses of library routines. */
3623 value
->un
.addr
.base
= (rtx
) XSTR (value
->un
.addr
.base
, 0);
3627 /* For a LABEL_REF, compare labels. */
3628 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3635 /* Given a MINUS expression, simplify it if both sides
3636 include the same symbol. */
3639 simplify_subtraction (x
)
3642 struct rtx_const val0
, val1
;
3644 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3645 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3647 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3648 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3652 /* Compute a hash code for a constant RTL expression. */
3655 const_hash_rtx (mode
, x
)
3656 enum machine_mode mode
;
3662 struct rtx_const value
;
3663 decode_rtx_const (mode
, x
, &value
);
3665 /* Compute hashing function */
3667 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3668 hi
+= ((int *) &value
)[i
];
3670 hi
&= (1 << HASHBITS
) - 1;
3671 hi
%= MAX_RTX_HASH_TABLE
;
3675 /* Compare a constant rtl object X with a constant-descriptor DESC.
3676 Return 1 if DESC describes a constant with the same value as X. */
3679 compare_constant_rtx (mode
, x
, desc
)
3680 enum machine_mode mode
;
3682 struct constant_descriptor
*desc
;
3684 int *p
= (int *) desc
->u
.contents
;
3687 struct rtx_const value
;
3689 decode_rtx_const (mode
, x
, &value
);
3690 strp
= (int *) &value
;
3691 len
= sizeof value
/ sizeof (int);
3693 /* Compare constant contents. */
3695 if (*p
++ != *strp
++)
3701 /* Construct a constant descriptor for the rtl-expression X.
3702 It is up to the caller to enter the descriptor in the hash table. */
3704 static struct constant_descriptor
*
3705 record_constant_rtx (mode
, x
)
3706 enum machine_mode mode
;
3709 struct constant_descriptor
*ptr
;
3711 ptr
= ((struct constant_descriptor
*)
3712 xcalloc (1, (offsetof (struct constant_descriptor
, u
)
3713 + sizeof (struct rtx_const
))));
3714 decode_rtx_const (mode
, x
, (struct rtx_const
*) ptr
->u
.contents
);
3719 /* Given a constant rtx X, return a MEM for the location in memory at which
3720 this constant has been placed. Return 0 if it not has been placed yet. */
3723 mem_for_const_double (x
)
3726 enum machine_mode mode
= GET_MODE (x
);
3727 struct constant_descriptor
*desc
;
3729 for (desc
= const_rtx_hash_table
[const_hash_rtx (mode
, x
)]; desc
;
3731 if (compare_constant_rtx (mode
, x
, desc
))
3737 /* Given a constant rtx X, make (or find) a memory constant for its value
3738 and return a MEM rtx to refer to it in memory. */
3741 force_const_mem (mode
, x
)
3742 enum machine_mode mode
;
3746 struct constant_descriptor
*desc
;
3749 struct pool_constant
*pool
;
3752 /* Compute hash code of X. Search the descriptors for that hash code
3753 to see if any of them describes X. If yes, we have an rtx to use. */
3754 hash
= const_hash_rtx (mode
, x
);
3755 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3756 if (compare_constant_rtx (mode
, x
, desc
))
3759 /* No constant equal to X is known to have been output.
3760 Make a constant descriptor to enter X in the hash table
3761 and make a MEM for it. */
3762 desc
= record_constant_rtx (mode
, x
);
3763 desc
->next
= const_rtx_hash_table
[hash
];
3764 const_rtx_hash_table
[hash
] = desc
;
3766 /* Align the location counter as required by EXP's data type. */
3767 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3768 #ifdef CONSTANT_ALIGNMENT
3769 align
= CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode
, 0), x
), align
);
3772 pool_offset
+= (align
/ BITS_PER_UNIT
) - 1;
3773 pool_offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3775 if (GET_CODE (x
) == LABEL_REF
)
3776 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3778 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3779 pool
= (struct pool_constant
*) ggc_alloc (sizeof (struct pool_constant
));
3783 pool
->labelno
= const_labelno
;
3784 pool
->align
= align
;
3785 pool
->offset
= pool_offset
;
3792 last_pool
->next
= pool
;
3795 pool_offset
+= GET_MODE_SIZE (mode
);
3797 /* Create a string containing the label name, in LABEL. */
3798 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3802 /* Construct the SYMBOL_REF and the MEM. */
3804 pool
->desc
->rtl
= def
3805 = gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
)));
3806 set_mem_alias_set (def
, const_alias_set
);
3807 set_mem_attributes (def
, type_for_mode (mode
, 0), 1);
3808 RTX_UNCHANGING_P (def
) = 1;
3810 /* Add label to symbol hash table. */
3811 hash
= SYMHASH (XSTR (XEXP (def
, 0), 0));
3812 pool
->next_sym
= const_rtx_sym_hash_table
[hash
];
3813 const_rtx_sym_hash_table
[hash
] = pool
;
3815 /* Mark the symbol_ref as belonging to this constants pool. */
3816 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3817 current_function_uses_const_pool
= 1;
3822 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3823 the corresponding pool_constant structure. */
3825 static struct pool_constant
*
3826 find_pool_constant (f
, addr
)
3830 struct pool_constant
*pool
;
3831 const char *label
= XSTR (addr
, 0);
3833 for (pool
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; pool
;
3834 pool
= pool
->next_sym
)
3835 if (XSTR (XEXP (pool
->desc
->rtl
, 0), 0) == label
)
3841 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3844 get_pool_constant (addr
)
3847 return (find_pool_constant (cfun
, addr
))->constant
;
3850 /* Likewise, but for the constant pool of a specific function. */
3853 get_pool_constant_for_function (f
, addr
)
3857 return (find_pool_constant (f
, addr
))->constant
;
3860 /* Similar, return the mode. */
3863 get_pool_mode (addr
)
3866 return (find_pool_constant (cfun
, addr
))->mode
;
3870 get_pool_mode_for_function (f
, addr
)
3874 return (find_pool_constant (f
, addr
))->mode
;
3877 /* Similar, return the offset in the constant pool. */
3880 get_pool_offset (addr
)
3883 return (find_pool_constant (cfun
, addr
))->offset
;
3886 /* Return the size of the constant pool. */
3894 /* Write all the constants in the constant pool. */
3897 output_constant_pool (fnname
, fndecl
)
3898 const char *fnname ATTRIBUTE_UNUSED
;
3899 tree fndecl ATTRIBUTE_UNUSED
;
3901 struct pool_constant
*pool
;
3903 union real_extract u
;
3905 /* It is possible for gcc to call force_const_mem and then to later
3906 discard the instructions which refer to the constant. In such a
3907 case we do not need to output the constant. */
3908 mark_constant_pool ();
3910 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3911 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3914 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3923 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3924 whose CODE_LABEL has been deleted. This can occur if a jump table
3925 is eliminated by optimization. If so, write a constant of zero
3926 instead. Note that this can also happen by turning the
3927 CODE_LABEL into a NOTE. */
3928 /* ??? This seems completely and utterly wrong. Certainly it's
3929 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3930 functioning even with INSN_DELETED_P and friends. */
3933 switch (GET_CODE (x
))
3936 if (GET_CODE (XEXP (x
, 0)) != PLUS
3937 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3939 tmp
= XEXP (XEXP (x
, 0), 0);
3944 if (INSN_DELETED_P (tmp
)
3945 || (GET_CODE (tmp
) == NOTE
3946 && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_DELETED
))
3957 /* First switch to correct section. */
3958 #ifdef SELECT_RTX_SECTION
3959 SELECT_RTX_SECTION (pool
->mode
, x
, pool
->align
);
3961 readonly_data_section ();
3964 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3965 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3966 pool
->align
, pool
->labelno
, done
);
3969 assemble_align (pool
->align
);
3971 /* Output the label. */
3972 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3974 /* Output the value of the constant itself. */
3975 switch (GET_MODE_CLASS (pool
->mode
))
3978 if (GET_CODE (x
) != CONST_DOUBLE
)
3981 memcpy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (x
), sizeof u
);
3982 assemble_real (u
.d
, pool
->mode
, pool
->align
);
3986 case MODE_PARTIAL_INT
:
3987 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), pool
->align
, 1);
3994 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3999 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4000 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
4003 /* Done with this pool. */
4004 first_pool
= last_pool
= 0;
4007 /* Look through the instructions for this function, and mark all the
4008 entries in the constant pool which are actually being used.
4009 Emit used deferred strings. */
4012 mark_constant_pool ()
4015 struct pool_constant
*pool
;
4017 if (first_pool
== 0 && htab_elements (const_str_htab
) == 0)
4020 for (pool
= first_pool
; pool
; pool
= pool
->next
)
4023 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4025 mark_constants (PATTERN (insn
));
4027 for (insn
= current_function_epilogue_delay_list
;
4029 insn
= XEXP (insn
, 1))
4031 mark_constants (PATTERN (insn
));
4034 /* Look through appropriate parts of X, marking all entries in the
4035 constant pool which are actually being used. Entries that are only
4036 referenced by other constants are also marked as used. Emit
4037 deferred strings that are used. */
4044 const char *format_ptr
;
4049 if (GET_CODE (x
) == SYMBOL_REF
)
4051 mark_constant (&x
, NULL
);
4055 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4056 insns, not any notes that may be attached. We don't want to mark
4057 a constant just because it happens to appear in a REG_EQUIV note. */
4060 mark_constants (PATTERN (x
));
4064 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
4066 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
4068 switch (*format_ptr
++)
4071 mark_constants (XEXP (x
, i
));
4075 if (XVEC (x
, i
) != 0)
4079 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4080 mark_constants (XVECEXP (x
, i
, j
));
4099 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4100 to as used. Emit referenced deferred strings. This function can
4101 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4104 mark_constant (current_rtx
, data
)
4106 void *data ATTRIBUTE_UNUSED
;
4108 rtx x
= *current_rtx
;
4113 else if (GET_CODE (x
) == SYMBOL_REF
)
4115 if (CONSTANT_POOL_ADDRESS_P (x
))
4117 struct pool_constant
*pool
= find_pool_constant (cfun
, x
);
4118 if (pool
->mark
== 0) {
4120 for_each_rtx (&(pool
->constant
), &mark_constant
, NULL
);
4125 else if (STRING_POOL_ADDRESS_P (x
))
4127 struct deferred_string
**defstr
;
4129 defstr
= (struct deferred_string
**)
4130 htab_find_slot_with_hash (const_str_htab
, XSTR (x
, 0),
4131 STRHASH (XSTR (x
, 0)), NO_INSERT
);
4134 struct deferred_string
*p
= *defstr
;
4136 STRING_POOL_ADDRESS_P (x
) = 0;
4137 output_constant_def_contents (p
->exp
, 0, p
->labelno
);
4138 htab_clear_slot (const_str_htab
, (void **) defstr
);
4145 /* Find all the constants whose addresses are referenced inside of EXP,
4146 and make sure assembler code with a label has been output for each one.
4147 Indicate whether an ADDR_EXPR has been encountered. */
4150 output_addressed_constants (exp
)
4156 /* Give the front-end a chance to convert VALUE to something that
4157 looks more like a constant to the back-end. */
4158 exp
= (*lang_hooks
.expand_constant
) (exp
);
4160 switch (TREE_CODE (exp
))
4163 /* Go inside any operations that get_inner_reference can handle and see
4164 if what's inside is a constant: no need to do anything here for
4165 addresses of variables or functions. */
4166 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4167 tem
= TREE_OPERAND (tem
, 0))
4170 if (TREE_CODE_CLASS (TREE_CODE (tem
)) == 'c'
4171 || TREE_CODE (tem
) == CONSTRUCTOR
)
4172 output_constant_def (tem
, 0);
4174 if (TREE_PUBLIC (tem
))
4182 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
4183 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
4188 case NON_LVALUE_EXPR
:
4189 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
4193 for (tem
= CONSTRUCTOR_ELTS (exp
); tem
; tem
= TREE_CHAIN (tem
))
4194 if (TREE_VALUE (tem
) != 0)
4195 reloc
|= output_addressed_constants (TREE_VALUE (tem
));
4205 /* Return nonzero if VALUE is a valid constant-valued expression
4206 for use in initializing a static variable; one that can be an
4207 element of a "constant" initializer.
4209 Return null_pointer_node if the value is absolute;
4210 if it is relocatable, return the variable that determines the relocation.
4211 We assume that VALUE has been folded as much as possible;
4212 therefore, we do not need to check for such things as
4213 arithmetic-combinations of integers. */
4216 initializer_constant_valid_p (value
, endtype
)
4220 /* Give the front-end a chance to convert VALUE to something that
4221 looks more like a constant to the back-end. */
4222 value
= (*lang_hooks
.expand_constant
) (value
);
4224 switch (TREE_CODE (value
))
4227 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
4228 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
4229 && TREE_CONSTANT (value
)
4230 && CONSTRUCTOR_ELTS (value
))
4232 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
4235 return TREE_STATIC (value
) ? null_pointer_node
: 0;
4241 return null_pointer_node
;
4245 return staticp (TREE_OPERAND (value
, 0)) ? TREE_OPERAND (value
, 0) : 0;
4247 case VIEW_CONVERT_EXPR
:
4248 case NON_LVALUE_EXPR
:
4249 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4253 /* Allow conversions between pointer types. */
4254 if (POINTER_TYPE_P (TREE_TYPE (value
))
4255 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4256 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4258 /* Allow conversions between real types. */
4259 if (FLOAT_TYPE_P (TREE_TYPE (value
))
4260 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4261 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4263 /* Allow length-preserving conversions between integer types. */
4264 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4265 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4266 && (TYPE_PRECISION (TREE_TYPE (value
))
4267 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4268 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4270 /* Allow conversions between other integer types only if
4272 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4273 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4275 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4277 if (inner
== null_pointer_node
)
4278 return null_pointer_node
;
4282 /* Allow (int) &foo provided int is as wide as a pointer. */
4283 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4284 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4285 && (TYPE_PRECISION (TREE_TYPE (value
))
4286 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4287 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4290 /* Likewise conversions from int to pointers, but also allow
4291 conversions from 0. */
4292 if (POINTER_TYPE_P (TREE_TYPE (value
))
4293 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4295 if (integer_zerop (TREE_OPERAND (value
, 0)))
4296 return null_pointer_node
;
4297 else if (TYPE_PRECISION (TREE_TYPE (value
))
4298 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
4299 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4303 /* Allow conversions to union types if the value inside is okay. */
4304 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4305 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4310 if (! INTEGRAL_TYPE_P (endtype
)
4311 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4313 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4315 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4317 /* If either term is absolute, use the other terms relocation. */
4318 if (valid0
== null_pointer_node
)
4320 if (valid1
== null_pointer_node
)
4326 if (! INTEGRAL_TYPE_P (endtype
)
4327 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4329 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4331 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4333 /* Win if second argument is absolute. */
4334 if (valid1
== null_pointer_node
)
4336 /* Win if both arguments have the same relocation.
4337 Then the value is absolute. */
4338 if (valid0
== valid1
&& valid0
!= 0)
4339 return null_pointer_node
;
4341 /* Since GCC guarantees that string constants are unique in the
4342 generated code, a subtraction between two copies of the same
4343 constant string is absolute. */
4344 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
&&
4345 valid1
&& TREE_CODE (valid1
) == STRING_CST
&&
4346 TREE_STRING_POINTER (valid0
) == TREE_STRING_POINTER (valid1
))
4347 return null_pointer_node
;
4350 /* Support differences between labels. */
4351 if (INTEGRAL_TYPE_P (endtype
))
4354 op0
= TREE_OPERAND (value
, 0);
4355 op1
= TREE_OPERAND (value
, 1);
4359 if (TREE_CODE (op0
) == ADDR_EXPR
4360 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
4361 && TREE_CODE (op1
) == ADDR_EXPR
4362 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
4363 return null_pointer_node
;
4374 /* Output assembler code for constant EXP to FILE, with no label.
4375 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4376 Assumes output_addressed_constants has been done on EXP already.
4378 Generate exactly SIZE bytes of assembler data, padding at the end
4379 with zeros if necessary. SIZE must always be specified.
4381 SIZE is important for structure constructors,
4382 since trailing members may have been omitted from the constructor.
4383 It is also important for initialization of arrays from string constants
4384 since the full length of the string constant might not be wanted.
4385 It is also needed for initialization of unions, where the initializer's
4386 type is just one member, and that may not be as long as the union.
4388 There a case in which we would fail to output exactly SIZE bytes:
4389 for a structure constructor that wants to produce more than SIZE bytes.
4390 But such constructors will never be generated for any possible input.
4392 ALIGN is the alignment of the data in bits. */
4395 output_constant (exp
, size
, align
)
4400 enum tree_code code
;
4401 HOST_WIDE_INT thissize
;
4403 /* Some front-ends use constants other than the standard language-indepdent
4404 varieties, but which may still be output directly. Give the front-end a
4405 chance to convert EXP to a language-independent representation. */
4406 exp
= (*lang_hooks
.expand_constant
) (exp
);
4408 if (size
== 0 || flag_syntax_only
)
4411 /* Eliminate any conversions since we'll be outputting the underlying
4413 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
4414 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4415 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4416 exp
= TREE_OPERAND (exp
, 0);
4418 code
= TREE_CODE (TREE_TYPE (exp
));
4419 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4421 /* Allow a constructor with no elements for any data type.
4422 This means to fill the space with zeros. */
4423 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
4425 assemble_zeros (size
);
4429 if (TREE_CODE (exp
) == FDESC_EXPR
)
4431 #ifdef ASM_OUTPUT_FDESC
4432 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4433 tree decl
= TREE_OPERAND (exp
, 0);
4434 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4441 /* Now output the underlying data. If we've handling the padding, return.
4442 Otherwise, break and ensure THISSIZE is the size written. */
4450 case REFERENCE_TYPE
:
4451 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4452 EXPAND_INITIALIZER
),
4454 error ("initializer for integer value is too complicated");
4458 if (TREE_CODE (exp
) != REAL_CST
)
4459 error ("initializer for floating value is not a floating constant");
4461 assemble_real (TREE_REAL_CST (exp
),
4462 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0),
4467 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4468 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4469 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4473 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4475 output_constructor (exp
, size
, align
);
4478 else if (TREE_CODE (exp
) == STRING_CST
)
4480 thissize
= MIN (TREE_STRING_LENGTH (exp
), size
);
4481 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4489 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4490 output_constructor (exp
, size
, align
);
4496 if (TREE_CODE (exp
) == INTEGER_CST
)
4497 assemble_integer (expand_expr (exp
, NULL_RTX
,
4498 VOIDmode
, EXPAND_INITIALIZER
),
4499 thissize
, align
, 1);
4500 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4502 unsigned char *buffer
= (unsigned char *) alloca (thissize
);
4503 if (get_set_constructor_bytes (exp
, buffer
, thissize
))
4505 assemble_string ((char *) buffer
, thissize
);
4508 error ("unknown set constructor type");
4520 assemble_zeros (size
);
4524 /* Subroutine of output_constructor, used for computing the size of
4525 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4526 type with an unspecified upper bound. */
4528 static unsigned HOST_WIDE_INT
4529 array_size_for_constructor (val
)
4534 /* This code used to attempt to handle string constants that are not
4535 arrays of single-bytes, but nothing else does, so there's no point in
4537 if (TREE_CODE (val
) == STRING_CST
)
4538 return TREE_STRING_LENGTH (val
);
4540 max_index
= NULL_TREE
;
4541 for (i
= CONSTRUCTOR_ELTS (val
); i
; i
= TREE_CHAIN (i
))
4543 tree index
= TREE_PURPOSE (i
);
4545 if (TREE_CODE (index
) == RANGE_EXPR
)
4546 index
= TREE_OPERAND (index
, 1);
4547 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4551 if (max_index
== NULL_TREE
)
4554 /* Compute the total number of array elements. */
4555 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
4557 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
4558 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
4560 /* Multiply by the array element unit size to find number of bytes. */
4561 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4563 return tree_low_cst (i
, 1);
4566 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4567 Generate at least SIZE bytes, padding if necessary. */
4570 output_constructor (exp
, size
, align
)
4575 tree type
= TREE_TYPE (exp
);
4576 tree link
, field
= 0;
4578 /* Number of bytes output or skipped so far.
4579 In other words, current position within the constructor. */
4580 HOST_WIDE_INT total_bytes
= 0;
4581 /* Non-zero means BYTE contains part of a byte, to be output. */
4582 int byte_buffer_in_use
= 0;
4585 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4588 if (TREE_CODE (type
) == RECORD_TYPE
)
4589 field
= TYPE_FIELDS (type
);
4591 if (TREE_CODE (type
) == ARRAY_TYPE
4592 && TYPE_DOMAIN (type
) != 0)
4593 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
4595 /* As LINK goes through the elements of the constant,
4596 FIELD goes through the structure fields, if the constant is a structure.
4597 if the constant is a union, then we override this,
4598 by getting the field from the TREE_LIST element.
4599 But the constant could also be an array. Then FIELD is zero.
4601 There is always a maximum of one element in the chain LINK for unions
4602 (even if the initializer in a source program incorrectly contains
4604 for (link
= CONSTRUCTOR_ELTS (exp
);
4606 link
= TREE_CHAIN (link
),
4607 field
= field
? TREE_CHAIN (field
) : 0)
4609 tree val
= TREE_VALUE (link
);
4612 /* The element in a union constructor specifies the proper field
4614 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
4615 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4616 && TREE_PURPOSE (link
) != 0)
4617 field
= TREE_PURPOSE (link
);
4619 else if (TREE_CODE (type
) == ARRAY_TYPE
)
4620 index
= TREE_PURPOSE (link
);
4622 /* Eliminate the marker that makes a cast not be an lvalue. */
4626 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4628 unsigned HOST_WIDE_INT fieldsize
4629 = int_size_in_bytes (TREE_TYPE (type
));
4630 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
4631 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
4632 HOST_WIDE_INT index
;
4633 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
4635 for (index
= lo_index
; index
<= hi_index
; index
++)
4637 /* Output the element's initial value. */
4639 assemble_zeros (fieldsize
);
4641 output_constant (val
, fieldsize
, align2
);
4643 /* Count its size. */
4644 total_bytes
+= fieldsize
;
4647 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4649 /* An element that is not a bit-field. */
4651 unsigned HOST_WIDE_INT fieldsize
;
4652 /* Since this structure is static,
4653 we know the positions are constant. */
4654 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4655 unsigned int align2
;
4658 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4659 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4661 /* Output any buffered-up bit-fields preceding this element. */
4662 if (byte_buffer_in_use
)
4664 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4666 byte_buffer_in_use
= 0;
4669 /* Advance to offset of this element.
4670 Note no alignment needed in an array, since that is guaranteed
4671 if each element has the proper size. */
4672 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4674 assemble_zeros (pos
- total_bytes
);
4678 /* Find the alignment of this element. */
4679 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4681 /* Determine size this element should occupy. */
4686 /* If this is an array with an unspecified upper bound,
4687 the initializer determines the size. */
4688 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4689 but we cannot do this until the deprecated support for
4690 initializing zero-length array members is removed. */
4691 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4692 && TYPE_DOMAIN (TREE_TYPE (field
))
4693 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4695 fieldsize
= array_size_for_constructor (val
);
4696 /* Given a non-empty initialization, this field had
4698 if (fieldsize
!= 0 && TREE_CHAIN (field
) != NULL_TREE
)
4701 else if (DECL_SIZE_UNIT (field
))
4703 /* ??? This can't be right. If the decl size overflows
4704 a host integer we will silently emit no data. */
4705 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4706 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4710 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4712 /* Output the element's initial value. */
4714 assemble_zeros (fieldsize
);
4716 output_constant (val
, fieldsize
, align2
);
4718 /* Count its size. */
4719 total_bytes
+= fieldsize
;
4721 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4722 error ("invalid initial value for member `%s'",
4723 IDENTIFIER_POINTER (DECL_NAME (field
)));
4726 /* Element that is a bit-field. */
4728 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4729 HOST_WIDE_INT end_offset
4730 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4733 val
= integer_zero_node
;
4735 /* If this field does not start in this (or, next) byte,
4737 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4739 /* Output remnant of any bit field in previous bytes. */
4740 if (byte_buffer_in_use
)
4742 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4744 byte_buffer_in_use
= 0;
4747 /* If still not at proper byte, advance to there. */
4748 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4750 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4751 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4755 if (! byte_buffer_in_use
)
4758 /* We must split the element into pieces that fall within
4759 separate bytes, and combine each byte with previous or
4760 following bit-fields. */
4762 /* next_offset is the offset n fbits from the beginning of
4763 the structure to the next bit of this element to be processed.
4764 end_offset is the offset of the first bit past the end of
4766 while (next_offset
< end_offset
)
4770 HOST_WIDE_INT value
;
4771 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4772 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4774 /* Advance from byte to byte
4775 within this element when necessary. */
4776 while (next_byte
!= total_bytes
)
4778 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4783 /* Number of bits we can process at once
4784 (all part of the same byte). */
4785 this_time
= MIN (end_offset
- next_offset
,
4786 BITS_PER_UNIT
- next_bit
);
4787 if (BYTES_BIG_ENDIAN
)
4789 /* On big-endian machine, take the most significant bits
4790 first (of the bits that are significant)
4791 and put them into bytes from the most significant end. */
4792 shift
= end_offset
- next_offset
- this_time
;
4794 /* Don't try to take a bunch of bits that cross
4795 the word boundary in the INTEGER_CST. We can
4796 only select bits from the LOW or HIGH part
4798 if (shift
< HOST_BITS_PER_WIDE_INT
4799 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4801 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4802 shift
= HOST_BITS_PER_WIDE_INT
;
4805 /* Now get the bits from the appropriate constant word. */
4806 if (shift
< HOST_BITS_PER_WIDE_INT
)
4807 value
= TREE_INT_CST_LOW (val
);
4808 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4810 value
= TREE_INT_CST_HIGH (val
);
4811 shift
-= HOST_BITS_PER_WIDE_INT
;
4816 /* Get the result. This works only when:
4817 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4818 byte
|= (((value
>> shift
)
4819 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4820 << (BITS_PER_UNIT
- this_time
- next_bit
));
4824 /* On little-endian machines,
4825 take first the least significant bits of the value
4826 and pack them starting at the least significant
4827 bits of the bytes. */
4828 shift
= next_offset
- int_bit_position (field
);
4830 /* Don't try to take a bunch of bits that cross
4831 the word boundary in the INTEGER_CST. We can
4832 only select bits from the LOW or HIGH part
4834 if (shift
< HOST_BITS_PER_WIDE_INT
4835 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4836 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4838 /* Now get the bits from the appropriate constant word. */
4839 if (shift
< HOST_BITS_PER_WIDE_INT
)
4840 value
= TREE_INT_CST_LOW (val
);
4841 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4843 value
= TREE_INT_CST_HIGH (val
);
4844 shift
-= HOST_BITS_PER_WIDE_INT
;
4849 /* Get the result. This works only when:
4850 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4851 byte
|= (((value
>> shift
)
4852 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4856 next_offset
+= this_time
;
4857 byte_buffer_in_use
= 1;
4862 if (byte_buffer_in_use
)
4864 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4868 if (total_bytes
< size
)
4869 assemble_zeros (size
- total_bytes
);
4873 /* This structure contains any weak symbol declarations waiting
4877 struct weak_syms
* next
;
4882 static struct weak_syms
* weak_decls
;
4884 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4885 associated with NAME. */
4888 add_weak (name
, value
)
4892 struct weak_syms
*weak
;
4894 weak
= (struct weak_syms
*) xmalloc (sizeof (struct weak_syms
));
4899 weak
->next
= weak_decls
;
4901 weak
->value
= value
;
4907 /* Declare DECL to be a weak symbol. */
4913 if (! TREE_PUBLIC (decl
))
4914 error_with_decl (decl
, "weak declaration of `%s' must be public");
4915 else if (TREE_ASM_WRITTEN (decl
))
4916 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4917 else if (SUPPORTS_WEAK
)
4918 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), NULL
);
4920 warning_with_decl (decl
, "weak declaration of `%s' not supported");
4922 DECL_WEAK (decl
) = 1;
4925 /* Emit any pending weak declarations. */
4932 struct weak_syms
*t
;
4933 for (t
= weak_decls
; t
; t
= t
->next
)
4935 #ifdef ASM_OUTPUT_WEAK_ALIAS
4936 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, t
->name
, t
->value
);
4938 #ifdef ASM_WEAKEN_LABEL
4941 ASM_WEAKEN_LABEL (asm_out_file
, t
->name
);
4948 /* Remove NAME from the pending list of weak symbols. This prevents
4949 the compiler from emitting multiple .weak directives which confuses
4951 #ifdef ASM_WEAKEN_LABEL
4953 remove_from_pending_weak_list (name
)
4956 struct weak_syms
*t
;
4957 struct weak_syms
**p
;
4959 for (p
= &weak_decls
; *p
; )
4962 if (strcmp (name
, t
->name
) == 0)
4971 #endif /* ASM_WEAKEN_LABEL */
4973 /* Emit an assembler directive to make the symbol for DECL an alias to
4974 the symbol for TARGET. */
4977 assemble_alias (decl
, target
)
4978 tree decl
, target ATTRIBUTE_UNUSED
;
4982 /* We must force creation of DECL_RTL for debug info generation, even though
4983 we don't use it here. */
4984 make_decl_rtl (decl
, NULL
);
4986 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4988 #ifdef ASM_OUTPUT_DEF
4989 /* Make name accessible from other files, if appropriate. */
4991 if (TREE_PUBLIC (decl
))
4993 #ifdef ASM_WEAKEN_LABEL
4994 if (DECL_WEAK (decl
))
4996 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4997 /* Remove this function from the pending weak list so that
4998 we do not emit multiple .weak directives for it. */
4999 remove_from_pending_weak_list
5000 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
5004 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
5007 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5008 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5010 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5012 TREE_ASM_WRITTEN (decl
) = 1;
5014 #ifdef ASM_OUTPUT_WEAK_ALIAS
5015 if (! DECL_WEAK (decl
))
5016 warning ("only weak aliases are supported in this configuration");
5018 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5019 TREE_ASM_WRITTEN (decl
) = 1;
5021 warning ("alias definitions not supported in this configuration; ignored");
5026 /* Returns 1 if the target configuration supports defining public symbols
5027 so that one of them will be chosen at link time instead of generating a
5028 multiply-defined symbol error, whether through the use of weak symbols or
5029 a target-specific mechanism for having duplicates discarded. */
5032 supports_one_only ()
5034 if (SUPPORTS_ONE_ONLY
)
5036 return SUPPORTS_WEAK
;
5039 /* Set up DECL as a public symbol that can be defined in multiple
5040 translation units without generating a linker error. */
5043 make_decl_one_only (decl
)
5046 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
5049 TREE_PUBLIC (decl
) = 1;
5051 if (TREE_CODE (decl
) == VAR_DECL
5052 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5053 DECL_COMMON (decl
) = 1;
5054 else if (SUPPORTS_ONE_ONLY
)
5056 #ifdef MAKE_DECL_ONE_ONLY
5057 MAKE_DECL_ONE_ONLY (decl
);
5059 DECL_ONE_ONLY (decl
) = 1;
5061 else if (SUPPORTS_WEAK
)
5062 DECL_WEAK (decl
) = 1;
5070 const_str_htab
= htab_create (128, const_str_htab_hash
, const_str_htab_eq
,
5071 const_str_htab_del
);
5072 in_named_htab
= htab_create (31, in_named_entry_hash
,
5073 in_named_entry_eq
, NULL
);
5075 ggc_add_root (const_hash_table
, MAX_HASH_TABLE
, sizeof const_hash_table
[0],
5076 mark_const_hash_entry
);
5077 ggc_add_root (&const_str_htab
, 1, sizeof const_str_htab
,
5078 mark_const_str_htab
);
5080 const_alias_set
= new_alias_set ();
5083 /* Select a set of attributes for section NAME based on the properties
5084 of DECL and whether or not RELOC indicates that DECL's initializer
5085 might contain runtime relocations.
5087 We make the section read-only and executable for a function decl,
5088 read-only for a const data decl, and writable for a non-const data decl. */
5091 default_section_type_flags (decl
, name
, reloc
)
5098 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5099 flags
= SECTION_CODE
;
5100 else if (decl
&& DECL_READONLY_SECTION (decl
, reloc
))
5103 flags
= SECTION_WRITE
;
5105 if (decl
&& DECL_ONE_ONLY (decl
))
5106 flags
|= SECTION_LINKONCE
;
5108 if (strcmp (name
, ".bss") == 0
5109 || strncmp (name
, ".bss.", 5) == 0
5110 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5111 || strcmp (name
, ".sbss") == 0
5112 || strncmp (name
, ".sbss.", 6) == 0
5113 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
5114 flags
|= SECTION_BSS
;
5119 /* Output assembly to switch to section NAME with attribute FLAGS.
5120 Four variants for common object file formats. */
5123 default_no_named_section (name
, flags
)
5124 const char *name ATTRIBUTE_UNUSED
;
5125 unsigned int flags ATTRIBUTE_UNUSED
;
5127 /* Some object formats don't support named sections at all. The
5128 front-end should already have flagged this as an error. */
5133 default_elf_asm_named_section (name
, flags
)
5137 char flagchars
[10], *f
= flagchars
;
5140 if (! named_section_first_declaration (name
))
5142 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5146 if (!(flags
& SECTION_DEBUG
))
5148 if (flags
& SECTION_WRITE
)
5150 if (flags
& SECTION_CODE
)
5152 if (flags
& SECTION_SMALL
)
5154 if (flags
& SECTION_MERGE
)
5156 if (flags
& SECTION_STRINGS
)
5160 if (flags
& SECTION_BSS
)
5165 if (flags
& SECTION_ENTSIZE
)
5166 fprintf (asm_out_file
, "\t.section\t%s,\"%s\",@%s,%d\n",
5167 name
, flagchars
, type
, flags
& SECTION_ENTSIZE
);
5169 fprintf (asm_out_file
, "\t.section\t%s,\"%s\",@%s\n",
5170 name
, flagchars
, type
);
5174 default_coff_asm_named_section (name
, flags
)
5178 char flagchars
[8], *f
= flagchars
;
5180 if (flags
& SECTION_WRITE
)
5182 if (flags
& SECTION_CODE
)
5186 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5190 default_pe_asm_named_section (name
, flags
)
5194 default_coff_asm_named_section (name
, flags
);
5196 if (flags
& SECTION_LINKONCE
)
5198 /* Functions may have been compiled at various levels of
5199 optimization so we can't use `same_size' here.
5200 Instead, have the linker pick one. */
5201 fprintf (asm_out_file
, "\t.linkonce %s\n",
5202 (flags
& SECTION_CODE
? "discard" : "same_size"));
5206 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5207 from SYMBOL is used in all classes derived from SYMBOL. */
5210 assemble_vtable_entry (symbol
, offset
)
5212 HOST_WIDE_INT offset
;
5214 fputs ("\t.vtable_entry ", asm_out_file
);
5215 output_addr_const (asm_out_file
, symbol
);
5216 fputs (", ", asm_out_file
);
5217 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_DEC
, offset
);
5218 fputc ('\n', asm_out_file
);
5221 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5222 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5225 assemble_vtable_inherit (child
, parent
)
5228 fputs ("\t.vtable_inherit ", asm_out_file
);
5229 output_addr_const (asm_out_file
, child
);
5230 fputs (", ", asm_out_file
);
5231 output_addr_const (asm_out_file
, parent
);
5232 fputc ('\n', asm_out_file
);