1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
38 #include "hard-reg-set.h"
50 #ifdef XCOFF_DEBUGGING_INFO
54 #ifndef TRAMPOLINE_ALIGNMENT
55 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
59 #define ASM_STABS_OP ".stabs"
62 /* Define the prefix to use when check_memory_usage_flag is enable. */
63 #ifdef NO_DOLLAR_IN_LABEL
64 #ifdef NO_DOT_IN_LABEL
65 #define CHKR_PREFIX "chkr_prefix_"
66 #else /* !NO_DOT_IN_LABEL */
67 #define CHKR_PREFIX "chkr."
69 #else /* !NO_DOLLAR_IN_LABEL */
70 #define CHKR_PREFIX "chkr$"
72 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
74 /* File in which assembler code is being written. */
76 extern FILE *asm_out_file
;
78 /* The (assembler) name of the first globally-visible object output. */
79 char *first_global_object_name
;
80 char *weak_global_object_name
;
82 extern struct obstack
*current_obstack
;
83 extern struct obstack
*saveable_obstack
;
84 extern struct obstack
*rtl_obstack
;
85 extern struct obstack permanent_obstack
;
86 #define obstack_chunk_alloc xmalloc
89 struct constant_descriptor
;
93 #define MAX_RTX_HASH_TABLE 61
97 /* Hash facility for making memory-constants
98 from constant rtl-expressions. It is used on RISC machines
99 where immediate integer arguments and constant addresses are restricted
100 so that such constants must be stored in memory.
102 This pool of constants is reinitialized for each function
103 so each function gets its own constants-pool that comes right before
105 struct constant_descriptor
**x_const_rtx_hash_table
;
106 struct pool_sym
**x_const_rtx_sym_hash_table
;
108 /* Pointers to first and last constant in pool. */
109 struct pool_constant
*x_first_pool
, *x_last_pool
;
111 /* Current offset in constant pool (does not include any machine-specific
115 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
116 They are chained through the CONST_DOUBLE_CHAIN.
117 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
118 In that case, CONST_DOUBLE_MEM is either a MEM,
119 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
120 rtx x_const_double_chain
;
123 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
124 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
125 #define first_pool (cfun->varasm->x_first_pool)
126 #define last_pool (cfun->varasm->x_last_pool)
127 #define pool_offset (cfun->varasm->x_pool_offset)
128 #define const_double_chain (cfun->varasm->x_const_double_chain)
130 /* Number for making the label on the next
131 constant that is stored in memory. */
135 /* Number for making the label on the next
136 static variable internal to a function. */
140 /* Carry information from ASM_DECLARE_OBJECT_NAME
141 to ASM_FINISH_DECLARE_OBJECT. */
143 int size_directive_output
;
145 /* The last decl for which assemble_variable was called,
146 if it did ASM_DECLARE_OBJECT_NAME.
147 If the last call to assemble_variable didn't do that,
150 tree last_assemble_variable_decl
;
152 static const char *strip_reg_name
PROTO((const char *));
153 static int contains_pointers_p
PROTO((tree
));
154 static void decode_addr_const
PROTO((tree
, struct addr_const
*));
155 static int const_hash
PROTO((tree
));
156 static int compare_constant
PROTO((tree
,
157 struct constant_descriptor
*));
158 static char *compare_constant_1
PROTO((tree
, char *));
159 static struct constant_descriptor
*record_constant
PROTO((tree
));
160 static void record_constant_1
PROTO((tree
));
161 static tree copy_constant
PROTO((tree
));
162 static void output_constant_def_contents
PROTO((tree
, int, int));
163 static void decode_rtx_const
PROTO((enum machine_mode
, rtx
,
164 struct rtx_const
*));
165 static int const_hash_rtx
PROTO((enum machine_mode
, rtx
));
166 static int compare_constant_rtx
PROTO((enum machine_mode
, rtx
,
167 struct constant_descriptor
*));
168 static struct constant_descriptor
*record_constant_rtx
PROTO((enum machine_mode
,
170 static struct pool_constant
*find_pool_constant
PROTO((struct function
*, rtx
));
171 static void mark_constant_pool
PROTO((void));
172 static void mark_constants
PROTO((rtx
));
173 static int output_addressed_constants
PROTO((tree
));
174 static void output_after_function_constants
PROTO((void));
175 static void output_constructor
PROTO((tree
, int));
176 #ifdef ASM_WEAKEN_LABEL
177 static void remove_from_pending_weak_list
PROTO ((char *));
179 #ifdef ASM_OUTPUT_BSS
180 static void asm_output_bss
PROTO((FILE *, tree
, char *, int, int));
182 #ifdef BSS_SECTION_ASM_OP
183 #ifdef ASM_OUTPUT_ALIGNED_BSS
184 static void asm_output_aligned_bss
PROTO((FILE *, tree
, char *, int, int));
186 #endif /* BSS_SECTION_ASM_OP */
187 static void mark_pool_constant
PROTO((struct pool_constant
*));
188 static void mark_pool_sym_hash_table
PROTO((struct pool_sym
**));
189 static void mark_const_hash_entry
PROTO((void *));
190 static void asm_emit_uninitialised
PROTO((tree
, char *, int, int));
192 static enum in_section
{ no_section
, in_text
, in_data
, in_named
193 #ifdef BSS_SECTION_ASM_OP
196 #ifdef EH_FRAME_SECTION_ASM_OP
199 #ifdef EXTRA_SECTIONS
202 } in_section
= no_section
;
204 /* Return a non-zero value if DECL has a section attribute. */
205 #define IN_NAMED_SECTION(DECL) \
206 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
207 && DECL_SECTION_NAME (DECL) != NULL_TREE)
209 /* Text of section name when in_section == in_named. */
210 static char *in_named_name
;
212 /* Define functions like text_section for any extra sections. */
213 #ifdef EXTRA_SECTION_FUNCTIONS
214 EXTRA_SECTION_FUNCTIONS
217 /* Tell assembler to switch to text section. */
222 if (in_section
!= in_text
)
224 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
225 in_section
= in_text
;
229 /* Tell assembler to switch to data section. */
234 if (in_section
!= in_data
)
236 if (flag_shared_data
)
238 #ifdef SHARED_SECTION_ASM_OP
239 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
241 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
245 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
247 in_section
= in_data
;
250 /* Tell assembler to ALWAYS switch to data section, in case
251 it's not sure where it it. */
254 force_data_section ()
256 in_section
= no_section
;
260 /* Tell assembler to switch to read-only data section. This is normally
264 readonly_data_section ()
266 #ifdef READONLY_DATA_SECTION
267 READONLY_DATA_SECTION (); /* Note this can call data_section. */
273 /* Determine if we're in the text section. */
278 return in_section
== in_text
;
281 /* Determine if we're in the data section. */
286 return in_section
== in_data
;
289 /* Tell assembler to change to section NAME for DECL.
290 If DECL is NULL, just switch to section NAME.
291 If NAME is NULL, get the name from DECL.
292 If RELOC is 1, the initializer for DECL contains relocs. */
295 named_section (decl
, name
, reloc
)
298 int reloc ATTRIBUTE_UNUSED
;
300 if (decl
!= NULL_TREE
301 && TREE_CODE_CLASS (TREE_CODE (decl
)) != 'd')
304 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
306 if (in_section
!= in_named
|| strcmp (name
, in_named_name
))
308 #ifdef ASM_OUTPUT_SECTION_NAME
309 ASM_OUTPUT_SECTION_NAME (asm_out_file
, decl
, name
, reloc
);
311 /* Section attributes are not supported if this macro isn't provided -
312 some host formats don't support them at all. The front-end should
313 already have flagged this as an error. */
317 in_named_name
= ggc_alloc_string (name
, -1);
318 in_section
= in_named
;
322 #ifdef ASM_OUTPUT_SECTION_NAME
323 #ifndef UNIQUE_SECTION
324 #define UNIQUE_SECTION(DECL,RELOC) \
330 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
331 /* Strip off any encoding in name. */ \
332 STRIP_NAME_ENCODING (name, name); \
334 len = strlen (name) + 1; \
335 string = alloca (len + 1); \
336 sprintf (string, ".%s", name); \
338 DECL_SECTION_NAME (DECL) = build_string (len, string); \
341 #ifndef UNIQUE_SECTION_P
342 #define UNIQUE_SECTION_P(DECL) 0
346 #ifdef BSS_SECTION_ASM_OP
348 /* Tell the assembler to switch to the bss section. */
353 if (in_section
!= in_bss
)
355 #ifdef SHARED_BSS_SECTION_ASM_OP
356 if (flag_shared_data
)
357 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
360 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
366 #ifdef ASM_OUTPUT_BSS
368 /* Utility function for ASM_OUTPUT_BSS for targets to use if
369 they don't support alignments in .bss.
370 ??? It is believed that this function will work in most cases so such
371 support is localized here. */
374 asm_output_bss (file
, decl
, name
, size
, rounded
)
380 ASM_GLOBALIZE_LABEL (file
, name
);
382 #ifdef ASM_DECLARE_OBJECT_NAME
383 last_assemble_variable_decl
= decl
;
384 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
386 /* Standard thing is just output label for the object. */
387 ASM_OUTPUT_LABEL (file
, name
);
388 #endif /* ASM_DECLARE_OBJECT_NAME */
389 ASM_OUTPUT_SKIP (file
, rounded
);
394 #ifdef ASM_OUTPUT_ALIGNED_BSS
396 /* Utility function for targets to use in implementing
397 ASM_OUTPUT_ALIGNED_BSS.
398 ??? It is believed that this function will work in most cases so such
399 support is localized here. */
402 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
408 ASM_GLOBALIZE_LABEL (file
, name
);
410 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
411 #ifdef ASM_DECLARE_OBJECT_NAME
412 last_assemble_variable_decl
= decl
;
413 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
415 /* Standard thing is just output label for the object. */
416 ASM_OUTPUT_LABEL (file
, name
);
417 #endif /* ASM_DECLARE_OBJECT_NAME */
418 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
423 #endif /* BSS_SECTION_ASM_OP */
425 #ifdef EH_FRAME_SECTION_ASM_OP
429 if (in_section
!= in_eh_frame
)
431 fprintf (asm_out_file
, "%s\n", EH_FRAME_SECTION_ASM_OP
);
432 in_section
= in_eh_frame
;
437 /* Switch to the section for function DECL.
439 If DECL is NULL_TREE, switch to the text section.
440 ??? It's not clear that we will ever be passed NULL_TREE, but it's
441 safer to handle it. */
444 function_section (decl
)
447 if (decl
!= NULL_TREE
448 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
449 named_section (decl
, (char *) 0, 0);
454 /* Switch to section for variable DECL.
456 RELOC is the `reloc' argument to SELECT_SECTION. */
459 variable_section (decl
, reloc
)
463 if (IN_NAMED_SECTION (decl
))
464 named_section (decl
, NULL
, reloc
);
467 /* C++ can have const variables that get initialized from constructors,
468 and thus can not be in a readonly section. We prevent this by
469 verifying that the initial value is constant for objects put in a
472 error_mark_node is used by the C front end to indicate that the
473 initializer has not been seen yet. In this case, we assume that
474 the initializer must be constant.
476 C++ uses error_mark_node for variables that have complicated
477 initializers, but these variables go in BSS so we won't be called
480 #ifdef SELECT_SECTION
481 SELECT_SECTION (decl
, reloc
);
483 if (DECL_READONLY_SECTION (decl
, reloc
))
484 readonly_data_section ();
491 /* Tell assembler to switch to the section for the exception handling
497 #if defined (EXCEPTION_SECTION)
498 EXCEPTION_SECTION ();
500 #ifdef ASM_OUTPUT_SECTION_NAME
501 named_section (NULL_TREE
, ".gcc_except_table", 0);
506 readonly_data_section ();
511 /* Create the rtl to represent a function, for a function definition.
512 DECL is a FUNCTION_DECL node which describes which function.
513 The rtl is stored into DECL. */
516 make_function_rtl (decl
)
519 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
520 char *new_name
= name
;
522 /* Rename a nested function to avoid conflicts. */
523 if (decl_function_context (decl
) != 0
524 && DECL_INITIAL (decl
) != 0
525 && DECL_RTL (decl
) == 0)
529 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
530 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
531 name
= ggc_alloc_string (label
, -1);
536 /* When -fprefix-function-name is used, every function name is
537 prefixed. Even static functions are prefixed because they
538 could be declared latter. Note that a nested function name
540 if (flag_prefix_function_name
)
542 size_t name_len
= strlen (name
);
544 new_name
= ggc_alloc_string (NULL
, name_len
+ CHKR_PREFIX_SIZE
);
545 memcpy (new_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
);
546 memcpy (new_name
+ CHKR_PREFIX_SIZE
, name
, name_len
+ 1);
551 if (DECL_RTL (decl
) == 0)
554 = gen_rtx_MEM (DECL_MODE (decl
),
555 gen_rtx_SYMBOL_REF (Pmode
, name
));
557 /* Optionally set flags or add text to the name to record information
558 such as that it is a function name. If the name is changed, the macro
559 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
560 #ifdef ENCODE_SECTION_INFO
561 ENCODE_SECTION_INFO (decl
);
566 /* ??? Another way to do this would be to do what halfpic.c does
567 and maintain a hashed table of such critters. */
568 /* ??? Another way to do this would be to pass a flag bit to
569 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
570 /* Let the target reassign the RTL if it wants.
571 This is necessary, for example, when one machine specific
572 decl attribute overrides another. */
573 #ifdef REDO_SECTION_INFO_P
574 if (REDO_SECTION_INFO_P (decl
))
575 ENCODE_SECTION_INFO (decl
);
580 /* Given NAME, a putative register name, discard any customary prefixes. */
583 strip_reg_name (name
)
586 #ifdef REGISTER_PREFIX
587 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
588 name
+= strlen (REGISTER_PREFIX
);
590 if (name
[0] == '%' || name
[0] == '#')
595 /* Decode an `asm' spec for a declaration as a register name.
596 Return the register number, or -1 if nothing specified,
597 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
598 or -3 if ASMSPEC is `cc' and is not recognized,
599 or -4 if ASMSPEC is `memory' and is not recognized.
600 Accept an exact spelling or a decimal number.
601 Prefixes such as % are optional. */
604 decode_reg_name (asmspec
)
611 /* Get rid of confusing prefixes. */
612 asmspec
= strip_reg_name (asmspec
);
614 /* Allow a decimal number as a "register name". */
615 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
616 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
618 if (asmspec
[0] != 0 && i
< 0)
621 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
627 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
629 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
632 #ifdef ADDITIONAL_REGISTER_NAMES
634 static struct { const char *name
; int number
; } table
[]
635 = ADDITIONAL_REGISTER_NAMES
;
637 for (i
= 0; i
< (int)(sizeof (table
) / sizeof (table
[0])); i
++)
638 if (! strcmp (asmspec
, table
[i
].name
))
639 return table
[i
].number
;
641 #endif /* ADDITIONAL_REGISTER_NAMES */
643 if (!strcmp (asmspec
, "memory"))
646 if (!strcmp (asmspec
, "cc"))
655 /* Create the DECL_RTL for a declaration for a static or external variable
656 or static or external function.
657 ASMSPEC, if not 0, is the string which the user specified
658 as the assembler symbol name.
659 TOP_LEVEL is nonzero if this is a file-scope variable.
661 This is never called for PARM_DECL nodes. */
664 make_decl_rtl (decl
, asmspec
, top_level
)
669 register char *name
= 0;
672 reg_number
= decode_reg_name (asmspec
);
674 if (DECL_ASSEMBLER_NAME (decl
) != NULL_TREE
)
675 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
677 if (reg_number
== -2)
679 /* ASMSPEC is given, and not the name of a register. */
680 size_t len
= strlen (asmspec
);
682 name
= ggc_alloc_string (NULL
, len
+ 1);
684 memcpy (&name
[1], asmspec
, len
+ 1);
687 /* For a duplicate declaration, we can be called twice on the
688 same DECL node. Don't discard the RTL already made. */
689 if (DECL_RTL (decl
) == 0)
691 /* First detect errors in declaring global registers. */
692 if (TREE_CODE (decl
) != FUNCTION_DECL
693 && DECL_REGISTER (decl
) && reg_number
== -1)
694 error_with_decl (decl
,
695 "register name not specified for `%s'");
696 else if (TREE_CODE (decl
) != FUNCTION_DECL
697 && DECL_REGISTER (decl
) && reg_number
< 0)
698 error_with_decl (decl
,
699 "invalid register name for `%s'");
700 else if ((reg_number
>= 0 || reg_number
== -3)
701 && (TREE_CODE (decl
) == FUNCTION_DECL
702 && ! DECL_REGISTER (decl
)))
703 error_with_decl (decl
,
704 "register name given for non-register variable `%s'");
705 else if (TREE_CODE (decl
) != FUNCTION_DECL
706 && DECL_REGISTER (decl
)
707 && TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
708 error_with_decl (decl
,
709 "data type of `%s' isn't suitable for a register");
710 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
)
711 && ! HARD_REGNO_MODE_OK (reg_number
,
712 TYPE_MODE (TREE_TYPE (decl
))))
713 error_with_decl (decl
,
714 "register number for `%s' isn't suitable for data type");
715 /* Now handle properly declared static register variables. */
716 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
720 if (DECL_INITIAL (decl
) != 0 && top_level
)
722 DECL_INITIAL (decl
) = 0;
723 error ("global register variable has initial value");
725 if (TREE_THIS_VOLATILE (decl
))
726 warning ("volatile register variables don't work as you might wish");
728 /* If the user specified one of the eliminables registers here,
729 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
730 confused with that register and be eliminated. Although this
731 usage is somewhat suspect, we nevertheless use the following
732 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
735 = gen_rtx_REG (DECL_MODE (decl
), FIRST_PSEUDO_REGISTER
);
736 REGNO (DECL_RTL (decl
)) = reg_number
;
737 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
741 /* Make this register global, so not usable for anything
743 #ifdef ASM_DECLARE_REGISTER_GLOBAL
744 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
746 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
748 globalize_reg (reg_number
+ --nregs
);
751 /* Specifying a section attribute on a variable forces it into a
752 non-.bss section, and thus it cannot be common. */
753 else if (TREE_CODE (decl
) == VAR_DECL
754 && DECL_SECTION_NAME (decl
) != NULL_TREE
755 && DECL_INITIAL (decl
) == NULL_TREE
756 && DECL_COMMON (decl
))
757 DECL_COMMON (decl
) = 0;
759 /* Now handle ordinary static variables and functions (in memory).
760 Also handle vars declared register invalidly. */
761 if (DECL_RTL (decl
) == 0)
763 /* Can't use just the variable's own name for a variable
764 whose scope is less than the whole file.
765 Concatenate a distinguishing number. */
766 if (!top_level
&& !TREE_PUBLIC (decl
) && asmspec
== 0)
770 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
771 name
= ggc_alloc_string (label
, -1);
778 /* When -fprefix-function-name is used, the functions
779 names are prefixed. Only nested function names are not
781 if (flag_prefix_function_name
&& TREE_CODE (decl
) == FUNCTION_DECL
)
783 size_t name_len
= strlen (name
);
786 new_name
= ggc_alloc_string (NULL
, name_len
+ CHKR_PREFIX_SIZE
);
787 memcpy (new_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
);
788 memcpy (new_name
+ CHKR_PREFIX_SIZE
, name
, name_len
+ 1);
792 DECL_RTL (decl
) = gen_rtx_MEM (DECL_MODE (decl
),
793 gen_rtx_SYMBOL_REF (Pmode
, name
));
794 MEM_ALIAS_SET (DECL_RTL (decl
)) = get_alias_set (decl
);
796 /* If this variable is to be treated as volatile, show its
797 tree node has side effects. If it has side effects, either
798 because of this test or from TREE_THIS_VOLATILE also
799 being set, show the MEM is volatile. */
800 if (flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
801 && TREE_PUBLIC (decl
))
802 TREE_SIDE_EFFECTS (decl
) = 1;
803 else if (flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
804 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))
805 TREE_SIDE_EFFECTS (decl
) = 1;
807 if (TREE_SIDE_EFFECTS (decl
))
808 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
810 if (TREE_READONLY (decl
))
811 RTX_UNCHANGING_P (DECL_RTL (decl
)) = 1;
812 MEM_SET_IN_STRUCT_P (DECL_RTL (decl
),
813 AGGREGATE_TYPE_P (TREE_TYPE (decl
)));
815 /* Optionally set flags or add text to the name to record information
816 such as that it is a function name.
817 If the name is changed, the macro ASM_OUTPUT_LABELREF
818 will have to know how to strip this information. */
819 #ifdef ENCODE_SECTION_INFO
820 ENCODE_SECTION_INFO (decl
);
826 /* If the old RTL had the wrong mode, fix the mode. */
827 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
829 rtx rtl
= DECL_RTL (decl
);
830 PUT_MODE (rtl
, DECL_MODE (decl
));
833 /* ??? Another way to do this would be to do what halfpic.c does
834 and maintain a hashed table of such critters. */
835 /* ??? Another way to do this would be to pass a flag bit to
836 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
837 /* Let the target reassign the RTL if it wants.
838 This is necessary, for example, when one machine specific
839 decl attribute overrides another. */
840 #ifdef REDO_SECTION_INFO_P
841 if (REDO_SECTION_INFO_P (decl
))
842 ENCODE_SECTION_INFO (decl
);
847 /* Make the rtl for variable VAR be volatile.
848 Use this only for static variables. */
851 make_var_volatile (var
)
854 if (GET_CODE (DECL_RTL (var
)) != MEM
)
857 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
860 /* Output alignment directive to align for constant expression EXP. */
863 assemble_constant_align (exp
)
868 /* Align the location counter as required by EXP's data type. */
869 align
= TYPE_ALIGN (TREE_TYPE (exp
));
870 #ifdef CONSTANT_ALIGNMENT
871 align
= CONSTANT_ALIGNMENT (exp
, align
);
874 if (align
> BITS_PER_UNIT
)
875 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
878 /* Output a string of literal assembler code
879 for an `asm' keyword used between functions. */
882 assemble_asm (string
)
887 if (TREE_CODE (string
) == ADDR_EXPR
)
888 string
= TREE_OPERAND (string
, 0);
890 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
893 #if 0 /* This should no longer be needed, because
894 flag_gnu_linker should be 0 on these systems,
895 which should prevent any output
896 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
897 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
898 #ifndef ASM_OUTPUT_CONSTRUCTOR
899 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
901 #ifndef ASM_OUTPUT_DESTRUCTOR
902 #define ASM_OUTPUT_DESTRUCTOR(file, name)
907 /* Record an element in the table of global destructors.
908 How this is done depends on what sort of assembler and linker
911 NAME should be the name of a global function to be called
912 at exit time. This name is output using assemble_name. */
915 assemble_destructor (name
)
918 #ifdef ASM_OUTPUT_DESTRUCTOR
919 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
923 /* Now tell GNU LD that this is part of the static destructor set. */
924 /* This code works for any machine provided you use GNU as/ld. */
925 fprintf (asm_out_file
, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
926 assemble_name (asm_out_file
, name
);
927 fputc ('\n', asm_out_file
);
932 /* Likewise for global constructors. */
935 assemble_constructor (name
)
938 #ifdef ASM_OUTPUT_CONSTRUCTOR
939 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
943 /* Now tell GNU LD that this is part of the static constructor set. */
944 /* This code works for any machine provided you use GNU as/ld. */
945 fprintf (asm_out_file
, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
946 assemble_name (asm_out_file
, name
);
947 fputc ('\n', asm_out_file
);
952 /* Likewise for entries we want to record for garbage collection.
953 Garbage collection is still under development. */
956 assemble_gc_entry (name
)
959 #ifdef ASM_OUTPUT_GC_ENTRY
960 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
964 /* Now tell GNU LD that this is part of the static constructor set. */
965 fprintf (asm_out_file
, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
966 assemble_name (asm_out_file
, name
);
967 fputc ('\n', asm_out_file
);
972 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
973 a non-zero value if the constant pool should be output before the
974 start of the function, or a zero value if the pool should output
975 after the end of the function. The default is to put it before the
978 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
979 #define CONSTANT_POOL_BEFORE_FUNCTION 1
982 /* Output assembler code for the constant pool of a function and associated
983 with defining the name of the function. DECL describes the function.
984 NAME is the function's name. For the constant pool, we use the current
985 constant pool data. */
988 assemble_start_function (decl
, fnname
)
994 /* The following code does not need preprocessing in the assembler. */
998 if (CONSTANT_POOL_BEFORE_FUNCTION
)
999 output_constant_pool (fnname
, decl
);
1001 #ifdef ASM_OUTPUT_SECTION_NAME
1002 /* If the function is to be put in its own section and it's not in a section
1003 already, indicate so. */
1004 if ((flag_function_sections
1005 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1006 || UNIQUE_SECTION_P (decl
))
1007 UNIQUE_SECTION (decl
, 0);
1010 function_section (decl
);
1012 /* Tell assembler to move to target machine's alignment for functions. */
1013 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1015 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1017 /* Handle a user-specified function alignment.
1018 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1019 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1020 if (align_functions_log
> align
)
1022 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1023 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1024 align_functions_log
, align_functions
-1);
1026 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1030 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1031 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1034 #ifdef SDB_DEBUGGING_INFO
1035 /* Output SDB definition of the function. */
1036 if (write_symbols
== SDB_DEBUG
)
1037 sdbout_mark_begin_function ();
1040 #ifdef DBX_DEBUGGING_INFO
1041 /* Output DBX definition of the function. */
1042 if (write_symbols
== DBX_DEBUG
)
1043 dbxout_begin_function (decl
);
1046 /* Make function name accessible from other files, if appropriate. */
1048 if (TREE_PUBLIC (decl
))
1050 if (! first_global_object_name
)
1055 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1056 name
= &first_global_object_name
;
1058 name
= &weak_global_object_name
;
1060 STRIP_NAME_ENCODING (p
, fnname
);
1061 *name
= permalloc (strlen (p
) + 1);
1065 #ifdef ASM_WEAKEN_LABEL
1066 if (DECL_WEAK (decl
))
1068 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
1069 /* Remove this function from the pending weak list so that
1070 we do not emit multiple .weak directives for it. */
1071 remove_from_pending_weak_list
1072 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1076 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
1079 /* Do any machine/system dependent processing of the function name */
1080 #ifdef ASM_DECLARE_FUNCTION_NAME
1081 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1083 /* Standard thing is just output label for the function. */
1084 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1085 #endif /* ASM_DECLARE_FUNCTION_NAME */
1088 /* Output assembler code associated with defining the size of the
1089 function. DECL describes the function. NAME is the function's name. */
1092 assemble_end_function (decl
, fnname
)
1096 #ifdef ASM_DECLARE_FUNCTION_SIZE
1097 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1099 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1101 output_constant_pool (fnname
, decl
);
1102 function_section (decl
); /* need to switch back */
1105 /* Output any constants which should appear after the function. */
1106 output_after_function_constants ();
1109 /* Assemble code to leave SIZE bytes of zeros. */
1112 assemble_zeros (size
)
1115 /* Do no output if -fsyntax-only. */
1116 if (flag_syntax_only
)
1119 #ifdef ASM_NO_SKIP_IN_TEXT
1120 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1121 so we must output 0s explicitly in the text section. */
1122 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1126 for (i
= 0; i
< size
- 20; i
+= 20)
1129 fprintf (asm_out_file
,
1130 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP
);
1132 fprintf (asm_out_file
,
1133 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1139 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
1141 fprintf (asm_out_file
, "\tbyte 0");
1144 for (; i
< size
; i
++)
1145 fprintf (asm_out_file
, ",0");
1146 fprintf (asm_out_file
, "\n");
1152 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1155 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1158 assemble_align (align
)
1161 if (align
> BITS_PER_UNIT
)
1162 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1165 /* Assemble a string constant with the specified C string as contents. */
1168 assemble_string (p
, size
)
1175 /* If the string is very long, split it up. */
1179 int thissize
= size
- pos
;
1180 if (thissize
> maximum
)
1183 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1191 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1192 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1193 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1195 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1196 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1197 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1199 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1200 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1204 #if defined ASM_OUTPUT_ALIGNED_BSS
1205 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1206 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1208 #if defined ASM_OUTPUT_BSS
1209 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1210 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1216 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1217 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1218 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1220 #if defined ASM_OUTPUT_ALIGNED_COMMON
1221 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1222 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1224 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1225 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1230 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1234 int rounded ATTRIBUTE_UNUSED
;
1241 destination
= asm_dest_local
;
1243 if (TREE_PUBLIC (decl
))
1245 #if defined ASM_EMIT_BSS
1246 if (! DECL_COMMON (decl
))
1247 destination
= asm_dest_bss
;
1250 destination
= asm_dest_common
;
1253 if (flag_shared_data
)
1255 switch (destination
)
1257 #ifdef ASM_OUTPUT_SHARED_BSS
1259 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1262 #ifdef ASM_OUTPUT_SHARED_COMMON
1263 case asm_dest_common
:
1264 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1267 #ifdef ASM_OUTPUT_SHARED_LOCAL
1268 case asm_dest_local
:
1269 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1277 switch (destination
)
1281 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1284 case asm_dest_common
:
1285 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1287 case asm_dest_local
:
1288 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1297 /* Assemble everything that is needed for a variable or function declaration.
1298 Not used for automatic variables, and not used for function definitions.
1299 Should not be called for variables of incomplete structure type.
1301 TOP_LEVEL is nonzero if this variable has file scope.
1302 AT_END is nonzero if this is the special handling, at end of compilation,
1303 to define things that have had only tentative definitions.
1304 DONT_OUTPUT_DATA if nonzero means don't actually output the
1305 initial value (that will be done by the caller). */
1308 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1310 int top_level ATTRIBUTE_UNUSED
;
1311 int at_end ATTRIBUTE_UNUSED
;
1312 int dont_output_data
;
1314 register char *name
;
1316 tree size_tree
= NULL_TREE
;
1318 enum in_section saved_in_section
;
1320 last_assemble_variable_decl
= 0;
1322 if (GET_CODE (DECL_RTL (decl
)) == REG
)
1324 /* Do output symbol info for global register variables, but do nothing
1327 if (TREE_ASM_WRITTEN (decl
))
1329 TREE_ASM_WRITTEN (decl
) = 1;
1331 /* Do no output if -fsyntax-only. */
1332 if (flag_syntax_only
)
1335 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1336 /* File-scope global variables are output here. */
1337 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1339 dbxout_symbol (decl
, 0);
1341 #ifdef SDB_DEBUGGING_INFO
1342 if (write_symbols
== SDB_DEBUG
&& top_level
1343 /* Leave initialized global vars for end of compilation;
1344 see comment in compile_file. */
1345 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1346 sdbout_symbol (decl
, 0);
1349 /* Don't output any DWARF debugging information for variables here.
1350 In the case of local variables, the information for them is output
1351 when we do our recursive traversal of the tree representation for
1352 the entire containing function. In the case of file-scope variables,
1353 we output information for all of them at the very end of compilation
1354 while we are doing our final traversal of the chain of file-scope
1360 /* Normally no need to say anything here for external references,
1361 since assemble_external is called by the language-specific code
1362 when a declaration is first seen. */
1364 if (DECL_EXTERNAL (decl
))
1367 /* Output no assembler code for a function declaration.
1368 Only definitions of functions output anything. */
1370 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1373 /* If type was incomplete when the variable was declared,
1374 see if it is complete now. */
1376 if (DECL_SIZE (decl
) == 0)
1377 layout_decl (decl
, 0);
1379 /* Still incomplete => don't allocate it; treat the tentative defn
1380 (which is what it must have been) as an `extern' reference. */
1382 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1384 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1385 DECL_SOURCE_LINE (decl
),
1386 "storage size of `%s' isn't known",
1387 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1388 TREE_ASM_WRITTEN (decl
) = 1;
1392 /* The first declaration of a variable that comes through this function
1393 decides whether it is global (in C, has external linkage)
1394 or local (in C, has internal linkage). So do nothing more
1395 if this function has already run. */
1397 if (TREE_ASM_WRITTEN (decl
))
1400 TREE_ASM_WRITTEN (decl
) = 1;
1402 /* Do no output if -fsyntax-only. */
1403 if (flag_syntax_only
)
1408 if (! dont_output_data
)
1412 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1415 /* This is better than explicit arithmetic, since it avoids overflow. */
1416 size_tree
= size_binop (CEIL_DIV_EXPR
,
1417 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
1419 size
= TREE_INT_CST_LOW (size_tree
);
1420 if (TREE_INT_CST_HIGH (size_tree
) != 0
1421 || size
!= TREE_INT_CST_LOW (size_tree
))
1423 error_with_decl (decl
, "size of variable `%s' is too large");
1428 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1430 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1431 && ! first_global_object_name
1432 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1433 || DECL_INITIAL (decl
) == error_mark_node
))
1434 && ! DECL_WEAK (decl
)
1435 && ! DECL_ONE_ONLY (decl
))
1439 STRIP_NAME_ENCODING (p
, name
);
1440 first_global_object_name
= permalloc (strlen (p
) + 1);
1441 strcpy (first_global_object_name
, p
);
1444 /* Compute the alignment of this data. */
1446 align
= DECL_ALIGN (decl
);
1448 /* In the case for initialing an array whose length isn't specified,
1449 where we have not yet been able to do the layout,
1450 figure out the proper alignment now. */
1451 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1452 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1453 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1455 /* Some object file formats have a maximum alignment which they support.
1456 In particular, a.out format supports a maximum alignment of 4. */
1457 #ifndef MAX_OFILE_ALIGNMENT
1458 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1460 if (align
> MAX_OFILE_ALIGNMENT
)
1462 warning_with_decl (decl
,
1463 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1464 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1465 align
= MAX_OFILE_ALIGNMENT
;
1468 /* On some machines, it is good to increase alignment sometimes. */
1469 #ifdef DATA_ALIGNMENT
1470 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1472 #ifdef CONSTANT_ALIGNMENT
1473 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1474 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1477 /* Reset the alignment in case we have made it tighter, so we can benefit
1478 from it in get_pointer_alignment. */
1479 DECL_ALIGN (decl
) = align
;
1481 /* Handle uninitialized definitions. */
1483 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
)
1484 /* If the target can't output uninitialized but not common global data
1485 in .bss, then we have to use .data. */
1486 #if ! defined ASM_EMIT_BSS
1487 && DECL_COMMON (decl
)
1489 && DECL_SECTION_NAME (decl
) == 0
1490 && ! dont_output_data
)
1492 int size
= TREE_INT_CST_LOW (size_tree
);
1495 /* Don't allocate zero bytes of common,
1496 since that means "undefined external" in the linker. */
1497 if (size
== 0) rounded
= 1;
1498 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1499 so that each uninitialized object starts on such a boundary. */
1500 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1501 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1502 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1504 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1505 if ( (DECL_ALIGN (decl
) / BITS_PER_UNIT
) > rounded
)
1507 (decl
, "requested alignment for %s is greater than implemented alignment of %d.",rounded
);
1510 #ifdef DBX_DEBUGGING_INFO
1511 /* File-scope global variables are output here. */
1512 if (write_symbols
== DBX_DEBUG
&& top_level
)
1513 dbxout_symbol (decl
, 0);
1515 #ifdef SDB_DEBUGGING_INFO
1516 if (write_symbols
== SDB_DEBUG
&& top_level
1517 /* Leave initialized global vars for end of compilation;
1518 see comment in compile_file. */
1519 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1520 sdbout_symbol (decl
, 0);
1523 /* Don't output any DWARF debugging information for variables here.
1524 In the case of local variables, the information for them is output
1525 when we do our recursive traversal of the tree representation for
1526 the entire containing function. In the case of file-scope variables,
1527 we output information for all of them at the very end of compilation
1528 while we are doing our final traversal of the chain of file-scope
1531 #if 0 /* ??? We should either delete this or add a comment describing what
1532 it was intended to do and why we shouldn't delete it. */
1533 if (flag_shared_data
)
1536 asm_emit_uninitialised (decl
, name
, size
, rounded
);
1541 /* Handle initialized definitions.
1542 Also handle uninitialized global definitions if -fno-common and the
1543 target doesn't support ASM_OUTPUT_BSS. */
1545 /* First make the assembler name(s) global if appropriate. */
1546 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1548 #ifdef ASM_WEAKEN_LABEL
1549 if (DECL_WEAK (decl
))
1551 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1552 /* Remove this variable from the pending weak list so that
1553 we do not emit multiple .weak directives for it. */
1554 remove_from_pending_weak_list
1555 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1559 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1562 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
1564 tree e
= TREE_VALUE (d
);
1565 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
1566 ASM_GLOBALIZE_LABEL (asm_out_file
,
1567 XSTR (XEXP (DECL_RTL (e
), 0), 0));
1571 /* Output any data that we will need to use the address of. */
1572 if (DECL_INITIAL (decl
) == error_mark_node
)
1573 reloc
= contains_pointers_p (TREE_TYPE (decl
));
1574 else if (DECL_INITIAL (decl
))
1575 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1577 #ifdef ASM_OUTPUT_SECTION_NAME
1578 if ((flag_data_sections
!= 0
1579 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1580 || UNIQUE_SECTION_P (decl
))
1581 UNIQUE_SECTION (decl
, reloc
);
1584 /* Switch to the appropriate section. */
1585 variable_section (decl
, reloc
);
1587 /* dbxout.c needs to know this. */
1588 if (in_text_section ())
1589 DECL_IN_TEXT_SECTION (decl
) = 1;
1591 /* Record current section so we can restore it if dbxout.c clobbers it. */
1592 saved_in_section
= in_section
;
1594 /* Output the dbx info now that we have chosen the section. */
1596 #ifdef DBX_DEBUGGING_INFO
1597 /* File-scope global variables are output here. */
1598 if (write_symbols
== DBX_DEBUG
&& top_level
)
1599 dbxout_symbol (decl
, 0);
1601 #ifdef SDB_DEBUGGING_INFO
1602 if (write_symbols
== SDB_DEBUG
&& top_level
1603 /* Leave initialized global vars for end of compilation;
1604 see comment in compile_file. */
1605 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1606 sdbout_symbol (decl
, 0);
1609 /* Don't output any DWARF debugging information for variables here.
1610 In the case of local variables, the information for them is output
1611 when we do our recursive traversal of the tree representation for
1612 the entire containing function. In the case of file-scope variables,
1613 we output information for all of them at the very end of compilation
1614 while we are doing our final traversal of the chain of file-scope
1617 /* If the debugging output changed sections, reselect the section
1618 that's supposed to be selected. */
1619 if (in_section
!= saved_in_section
)
1620 variable_section (decl
, reloc
);
1622 /* Output the alignment of this data. */
1623 if (align
> BITS_PER_UNIT
)
1624 ASM_OUTPUT_ALIGN (asm_out_file
,
1625 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1627 /* Do any machine/system dependent processing of the object. */
1628 #ifdef ASM_DECLARE_OBJECT_NAME
1629 last_assemble_variable_decl
= decl
;
1630 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1632 /* Standard thing is just output label for the object. */
1633 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1634 #endif /* ASM_DECLARE_OBJECT_NAME */
1636 if (!dont_output_data
)
1638 if (DECL_INITIAL (decl
))
1639 /* Output the actual data. */
1640 output_constant (DECL_INITIAL (decl
), TREE_INT_CST_LOW (size_tree
));
1642 /* Leave space for it. */
1643 assemble_zeros (TREE_INT_CST_LOW (size_tree
));
1647 #ifdef XCOFF_DEBUGGING_INFO
1648 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1649 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1650 and `aa' hasn't been output yet, the assembler generates a stab entry with
1651 a value of zero, in addition to creating an unnecessary external entry
1652 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1654 /* File-scope global variables are output here. */
1655 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
1657 saved_in_section
= in_section
;
1659 dbxout_symbol (decl
, 0);
1661 if (in_section
!= saved_in_section
)
1662 variable_section (decl
, reloc
);
1665 /* There must be a statement after a label. */
1670 /* Return 1 if type TYPE contains any pointers. */
1673 contains_pointers_p (type
)
1676 switch (TREE_CODE (type
))
1679 case REFERENCE_TYPE
:
1680 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1681 so I'll play safe and return 1. */
1687 case QUAL_UNION_TYPE
:
1690 /* For a type that has fields, see if the fields have pointers. */
1691 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1692 if (TREE_CODE (fields
) == FIELD_DECL
1693 && contains_pointers_p (TREE_TYPE (fields
)))
1699 /* An array type contains pointers if its element type does. */
1700 return contains_pointers_p (TREE_TYPE (type
));
1707 /* Output something to declare an external symbol to the assembler.
1708 (Most assemblers don't need this, so we normally output nothing.)
1709 Do nothing if DECL is not external. */
1712 assemble_external (decl
)
1713 tree decl ATTRIBUTE_UNUSED
;
1715 #ifdef ASM_OUTPUT_EXTERNAL
1716 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
1717 && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1719 rtx rtl
= DECL_RTL (decl
);
1721 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1722 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1724 /* Some systems do require some output. */
1725 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1726 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1732 /* Similar, for calling a library function FUN. */
1735 assemble_external_libcall (fun
)
1736 rtx fun ATTRIBUTE_UNUSED
;
1738 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1739 /* Declare library function name external when first used, if nec. */
1740 if (! SYMBOL_REF_USED (fun
))
1742 SYMBOL_REF_USED (fun
) = 1;
1743 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1748 /* Declare the label NAME global. */
1751 assemble_global (name
)
1754 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1757 /* Assemble a label named NAME. */
1760 assemble_label (name
)
1763 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1766 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1767 If NAME starts with a *, the rest of NAME is output verbatim.
1768 Otherwise NAME is transformed in an implementation-defined way
1769 (usually by the addition of an underscore).
1770 Many macros in the tm file are defined to call this function. */
1773 assemble_name (file
, name
)
1777 const char *real_name
;
1780 STRIP_NAME_ENCODING (real_name
, name
);
1781 if (flag_prefix_function_name
1782 && ! bcmp (real_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
))
1783 real_name
= real_name
+ CHKR_PREFIX_SIZE
;
1785 id
= maybe_get_identifier (real_name
);
1787 TREE_SYMBOL_REFERENCED (id
) = 1;
1790 fputs (&name
[1], file
);
1792 ASM_OUTPUT_LABELREF (file
, name
);
1795 /* Allocate SIZE bytes writable static space with a gensym name
1796 and return an RTX to refer to its address. */
1799 assemble_static_space (size
)
1807 if (flag_shared_data
)
1811 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1813 namestring
= ggc_alloc_string (name
, -1);
1815 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1817 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1818 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1821 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1822 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1825 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1826 so that each uninitialized object starts on such a boundary. */
1827 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1828 int rounded ATTRIBUTE_UNUSED
1829 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1830 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1831 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1832 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1839 /* Assemble the static constant template for function entry trampolines.
1840 This is done at most once per compilation.
1841 Returns an RTX for the address of the template. */
1843 #ifdef TRAMPOLINE_TEMPLATE
1845 assemble_trampoline_template ()
1851 /* By default, put trampoline templates in read-only data section. */
1853 #ifdef TRAMPOLINE_SECTION
1854 TRAMPOLINE_SECTION ();
1856 readonly_data_section ();
1859 /* Write the assembler code to define one. */
1860 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1862 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1864 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1865 TRAMPOLINE_TEMPLATE (asm_out_file
);
1867 /* Record the rtl to refer to it. */
1868 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1869 name
= ggc_alloc_string (label
, -1);
1870 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1874 /* Assemble the integer constant X into an object of SIZE bytes.
1875 X must be either a CONST_INT or CONST_DOUBLE.
1877 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1878 non-zero, abort if we can't output the constant. */
1881 assemble_integer (x
, size
, force
)
1886 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1887 ASM_OUTPUT... macros. */
1891 #ifdef ASM_OUTPUT_CHAR
1893 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1897 #ifdef ASM_OUTPUT_SHORT
1899 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1903 #ifdef ASM_OUTPUT_INT
1905 ASM_OUTPUT_INT (asm_out_file
, x
);
1909 #ifdef ASM_OUTPUT_DOUBLE_INT
1911 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1915 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1917 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1922 /* If we couldn't do it that way, there are two other possibilities: First,
1923 if the machine can output an explicit byte and this is a 1 byte constant,
1924 we can use ASM_OUTPUT_BYTE. */
1926 #ifdef ASM_OUTPUT_BYTE
1927 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1929 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1934 /* Finally, if SIZE is larger than a single word, try to output the constant
1935 one word at a time. */
1937 if (size
> UNITS_PER_WORD
)
1940 enum machine_mode mode
1941 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1944 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1946 word
= operand_subword (x
, i
, 0, mode
);
1951 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1955 if (i
== size
/ UNITS_PER_WORD
)
1957 /* If we output at least one word and then could not finish,
1958 there is no valid way to continue. */
1969 /* Assemble the floating-point constant D into an object of size MODE. */
1972 assemble_real (d
, mode
)
1974 enum machine_mode mode
;
1976 jmp_buf output_constant_handler
;
1978 if (setjmp (output_constant_handler
))
1980 error ("floating point trap outputting a constant");
1981 #ifdef REAL_IS_NOT_DOUBLE
1982 bzero ((char *) &d
, sizeof d
);
1989 set_float_handler (output_constant_handler
);
1993 #ifdef ASM_OUTPUT_BYTE_FLOAT
1995 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, d
);
1998 #ifdef ASM_OUTPUT_SHORT_FLOAT
2000 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, d
);
2003 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2005 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, d
);
2008 #ifdef ASM_OUTPUT_FLOAT
2010 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
2014 #ifdef ASM_OUTPUT_DOUBLE
2016 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
2020 #ifdef ASM_OUTPUT_LONG_DOUBLE
2023 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
2031 set_float_handler (NULL_PTR
);
2034 /* Here we combine duplicate floating constants to make
2035 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2037 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2038 For an integer, I0 is the low-order word and I1 is the high-order word.
2039 For a real number, I0 is the word with the low address
2040 and I1 is the word with the high address. */
2043 immed_double_const (i0
, i1
, mode
)
2044 HOST_WIDE_INT i0
, i1
;
2045 enum machine_mode mode
;
2049 if (GET_MODE_CLASS (mode
) == MODE_INT
2050 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
2052 /* We clear out all bits that don't belong in MODE, unless they and our
2053 sign bit are all one. So we get either a reasonable negative value
2054 or a reasonable unsigned value for this mode. */
2055 int width
= GET_MODE_BITSIZE (mode
);
2056 if (width
< HOST_BITS_PER_WIDE_INT
2057 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
2058 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
2059 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
2060 else if (width
== HOST_BITS_PER_WIDE_INT
2061 && ! (i1
== ~0 && i0
< 0))
2063 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
2064 /* We cannot represent this value as a constant. */
2067 /* If this would be an entire word for the target, but is not for
2068 the host, then sign-extend on the host so that the number will look
2069 the same way on the host that it would on the target.
2071 For example, when building a 64 bit alpha hosted 32 bit sparc
2072 targeted compiler, then we want the 32 bit unsigned value -1 to be
2073 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2074 The later confuses the sparc backend. */
2076 if (BITS_PER_WORD
< HOST_BITS_PER_WIDE_INT
&& BITS_PER_WORD
== width
2077 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
2078 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
2080 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2082 ??? Strictly speaking, this is wrong if we create a CONST_INT
2083 for a large unsigned constant with the size of MODE being
2084 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2085 wider mode. In that case we will mis-interpret it as a negative
2088 Unfortunately, the only alternative is to make a CONST_DOUBLE
2089 for any constant in any mode if it is an unsigned constant larger
2090 than the maximum signed integer in an int on the host. However,
2091 doing this will break everyone that always expects to see a CONST_INT
2092 for SImode and smaller.
2094 We have always been making CONST_INTs in this case, so nothing new
2097 if (width
<= HOST_BITS_PER_WIDE_INT
)
2098 i1
= (i0
< 0) ? ~(HOST_WIDE_INT
) 0 : 0;
2100 /* If this integer fits in one word, return a CONST_INT. */
2101 if ((i1
== 0 && i0
>= 0)
2102 || (i1
== ~0 && i0
< 0))
2103 return GEN_INT (i0
);
2105 /* We use VOIDmode for integers. */
2109 /* Search the chain for an existing CONST_DOUBLE with the right value.
2110 If one is found, return it. */
2112 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2113 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
2114 && GET_MODE (r
) == mode
)
2117 /* No; make a new one and add it to the chain.
2119 We may be called by an optimizer which may be discarding any memory
2120 allocated during its processing (such as combine and loop). However,
2121 we will be leaving this constant on the chain, so we cannot tolerate
2122 freed memory. So switch to saveable_obstack for this allocation
2123 and then switch back if we were in current_obstack. */
2125 push_obstacks_nochange ();
2126 rtl_in_saveable_obstack ();
2127 r
= gen_rtx_CONST_DOUBLE (mode
, NULL_RTX
, i0
, i1
);
2130 /* Don't touch const_double_chain if not inside any function. */
2131 if (current_function_decl
!= 0)
2133 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2134 const_double_chain
= r
;
2137 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2138 Actual use of mem-slot is only through force_const_mem. */
2140 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2145 /* Return a CONST_DOUBLE for a specified `double' value
2146 and machine mode. */
2149 immed_real_const_1 (d
, mode
)
2151 enum machine_mode mode
;
2153 union real_extract u
;
2156 /* Get the desired `double' value as a sequence of ints
2157 since that is how they are stored in a CONST_DOUBLE. */
2161 /* Detect special cases. */
2163 if (REAL_VALUES_IDENTICAL (dconst0
, d
))
2164 return CONST0_RTX (mode
);
2165 /* Check for NaN first, because some ports (specifically the i386) do not
2166 emit correct ieee-fp code by default, and thus will generate a core
2167 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2168 does a floating point comparison. */
2169 else if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
2170 return CONST1_RTX (mode
);
2172 if (sizeof u
== sizeof (HOST_WIDE_INT
))
2173 return immed_double_const (u
.i
[0], 0, mode
);
2174 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
2175 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
2177 /* The rest of this function handles the case where
2178 a float value requires more than 2 ints of space.
2179 It will be deleted as dead code on machines that don't need it. */
2181 /* Search the chain for an existing CONST_DOUBLE with the right value.
2182 If one is found, return it. */
2184 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2185 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
2186 && GET_MODE (r
) == mode
)
2189 /* No; make a new one and add it to the chain.
2191 We may be called by an optimizer which may be discarding any memory
2192 allocated during its processing (such as combine and loop). However,
2193 we will be leaving this constant on the chain, so we cannot tolerate
2194 freed memory. So switch to saveable_obstack for this allocation
2195 and then switch back if we were in current_obstack. */
2196 push_obstacks_nochange ();
2197 rtl_in_saveable_obstack ();
2198 r
= rtx_alloc (CONST_DOUBLE
);
2201 bcopy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (r
), sizeof u
);
2203 /* Don't touch const_double_chain if not inside any function. */
2204 if (current_function_decl
!= 0)
2206 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2207 const_double_chain
= r
;
2210 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2211 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2212 is only through force_const_mem. */
2214 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2219 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2220 which must be a REAL_CST tree node. */
2223 immed_real_const (exp
)
2226 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
2229 /* At the end of a function, forget the memory-constants
2230 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2231 Also clear out real_constant_chain and clear out all the chain-pointers. */
2234 clear_const_double_mem ()
2236 register rtx r
, next
;
2238 for (r
= const_double_chain
; r
; r
= next
)
2240 next
= CONST_DOUBLE_CHAIN (r
);
2241 CONST_DOUBLE_CHAIN (r
) = 0;
2242 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
2244 const_double_chain
= 0;
2247 /* Given an expression EXP with a constant value,
2248 reduce it to the sum of an assembler symbol and an integer.
2249 Store them both in the structure *VALUE.
2250 Abort if EXP does not reduce. */
2255 HOST_WIDE_INT offset
;
2259 decode_addr_const (exp
, value
)
2261 struct addr_const
*value
;
2263 register tree target
= TREE_OPERAND (exp
, 0);
2264 register int offset
= 0;
2269 if (TREE_CODE (target
) == COMPONENT_REF
2270 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
2273 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
2274 target
= TREE_OPERAND (target
, 0);
2276 else if (TREE_CODE (target
) == ARRAY_REF
)
2278 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
2279 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
2281 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
2282 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
2284 target
= TREE_OPERAND (target
, 0);
2290 switch (TREE_CODE (target
))
2294 x
= DECL_RTL (target
);
2298 x
= gen_rtx_MEM (FUNCTION_MODE
,
2299 gen_rtx_LABEL_REF (VOIDmode
,
2300 label_rtx (TREE_OPERAND (exp
, 0))));
2308 x
= TREE_CST_RTL (target
);
2315 if (GET_CODE (x
) != MEM
)
2320 value
->offset
= offset
;
2323 /* Uniquize all constants that appear in memory.
2324 Each constant in memory thus far output is recorded
2325 in `const_hash_table' with a `struct constant_descriptor'
2326 that contains a polish representation of the value of
2329 We cannot store the trees in the hash table
2330 because the trees may be temporary. */
2332 struct constant_descriptor
2334 struct constant_descriptor
*next
;
2341 #define MAX_HASH_TABLE 1009
2342 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2344 /* Mark a const_hash_table descriptor for GC. */
2347 mark_const_hash_entry (ptr
)
2350 struct constant_descriptor
*desc
= * (struct constant_descriptor
**) ptr
;
2354 ggc_mark_string (desc
->label
);
2355 ggc_mark_rtx (desc
->rtl
);
2360 /* Compute a hash code for a constant expression. */
2367 register int len
, hi
, i
;
2368 register enum tree_code code
= TREE_CODE (exp
);
2370 /* Either set P and LEN to the address and len of something to hash and
2371 exit the switch or return a value. */
2376 p
= (char *) &TREE_INT_CST_LOW (exp
);
2377 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2381 p
= (char *) &TREE_REAL_CST (exp
);
2382 len
= sizeof TREE_REAL_CST (exp
);
2386 p
= TREE_STRING_POINTER (exp
);
2387 len
= TREE_STRING_LENGTH (exp
);
2391 return (const_hash (TREE_REALPART (exp
)) * 5
2392 + const_hash (TREE_IMAGPART (exp
)));
2395 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2397 len
= int_size_in_bytes (TREE_TYPE (exp
));
2398 p
= (char *) alloca (len
);
2399 get_set_constructor_bytes (exp
, (unsigned char *) p
, len
);
2406 /* For record type, include the type in the hashing.
2407 We do not do so for array types
2408 because (1) the sizes of the elements are sufficient
2409 and (2) distinct array types can have the same constructor.
2410 Instead, we include the array size because the constructor could
2412 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2413 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2416 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2417 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2419 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2420 if (TREE_VALUE (link
))
2422 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2429 struct addr_const value
;
2431 decode_addr_const (exp
, &value
);
2432 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2434 /* Don't hash the address of the SYMBOL_REF;
2435 only use the offset and the symbol name. */
2437 p
= XSTR (value
.base
, 0);
2438 for (i
= 0; p
[i
] != 0; i
++)
2439 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2441 else if (GET_CODE (value
.base
) == LABEL_REF
)
2442 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2446 hi
&= (1 << HASHBITS
) - 1;
2447 hi
%= MAX_HASH_TABLE
;
2453 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2454 + const_hash (TREE_OPERAND (exp
, 1)));
2458 case NON_LVALUE_EXPR
:
2459 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2465 /* Compute hashing function */
2467 for (i
= 0; i
< len
; i
++)
2468 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2470 hi
&= (1 << HASHBITS
) - 1;
2471 hi
%= MAX_HASH_TABLE
;
2475 /* Compare a constant expression EXP with a constant-descriptor DESC.
2476 Return 1 if DESC describes a constant with the same value as EXP. */
2479 compare_constant (exp
, desc
)
2481 struct constant_descriptor
*desc
;
2483 return 0 != compare_constant_1 (exp
, desc
->contents
);
2486 /* Compare constant expression EXP with a substring P of a constant descriptor.
2487 If they match, return a pointer to the end of the substring matched.
2488 If they do not match, return 0.
2490 Since descriptors are written in polish prefix notation,
2491 this function can be used recursively to test one operand of EXP
2492 against a subdescriptor, and if it succeeds it returns the
2493 address of the subdescriptor for the next operand. */
2496 compare_constant_1 (exp
, p
)
2500 register char *strp
;
2502 register enum tree_code code
= TREE_CODE (exp
);
2504 if (code
!= (enum tree_code
) *p
++)
2507 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2508 switch, or return the result of the comparison. */
2513 /* Integer constants are the same only if the same width of type. */
2514 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2517 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2518 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2522 /* Real constants are the same only if the same width of type. */
2523 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2526 strp
= (char *) &TREE_REAL_CST (exp
);
2527 len
= sizeof TREE_REAL_CST (exp
);
2531 if (flag_writable_strings
)
2534 if (*p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2537 strp
= TREE_STRING_POINTER (exp
);
2538 len
= TREE_STRING_LENGTH (exp
);
2539 if (bcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2540 sizeof TREE_STRING_LENGTH (exp
)))
2543 p
+= sizeof TREE_STRING_LENGTH (exp
);
2547 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2551 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2554 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2556 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2558 strp
= (char *) alloca (len
);
2559 get_set_constructor_bytes (exp
, (unsigned char *) strp
, len
);
2560 if (bcmp ((char *) &xlen
, p
, sizeof xlen
))
2569 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2571 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2572 int have_purpose
= 0;
2574 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2575 if (TREE_PURPOSE (link
))
2578 if (bcmp ((char *) &length
, p
, sizeof length
))
2583 /* For record constructors, insist that the types match.
2584 For arrays, just verify both constructors are for arrays.
2585 Then insist that either both or none have any TREE_PURPOSE
2587 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2588 type
= TREE_TYPE (exp
);
2592 if (bcmp ((char *) &type
, p
, sizeof type
))
2595 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2597 if (bcmp ((char *) &mode
, p
, sizeof mode
))
2605 if (bcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2608 p
+= sizeof have_purpose
;
2610 /* For arrays, insist that the size in bytes match. */
2611 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2613 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2615 if (bcmp ((char *) &size
, p
, sizeof size
))
2621 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2623 if (TREE_VALUE (link
))
2625 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2632 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2638 if (TREE_PURPOSE (link
)
2639 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2641 if (bcmp ((char *) &TREE_PURPOSE (link
), p
,
2642 sizeof TREE_PURPOSE (link
)))
2645 p
+= sizeof TREE_PURPOSE (link
);
2647 else if (TREE_PURPOSE (link
))
2649 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2652 else if (have_purpose
)
2656 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2668 struct addr_const value
;
2670 decode_addr_const (exp
, &value
);
2671 strp
= (char *) &value
.offset
;
2672 len
= sizeof value
.offset
;
2673 /* Compare the offset. */
2675 if (*p
++ != *strp
++)
2678 /* Compare symbol name. */
2679 strp
= XSTR (value
.base
, 0);
2680 len
= strlen (strp
) + 1;
2687 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2691 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2695 case NON_LVALUE_EXPR
:
2696 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2702 /* Compare constant contents. */
2704 if (*p
++ != *strp
++)
2710 /* Construct a constant descriptor for the expression EXP.
2711 It is up to the caller to enter the descriptor in the hash table. */
2713 static struct constant_descriptor
*
2714 record_constant (exp
)
2717 struct constant_descriptor
*next
= 0;
2721 /* Make a struct constant_descriptor. The first three pointers will
2722 be filled in later. Here we just leave space for them. */
2724 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2725 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2726 obstack_grow (&permanent_obstack
, (char *) &rtl
, sizeof rtl
);
2727 record_constant_1 (exp
);
2728 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2731 /* Add a description of constant expression EXP
2732 to the object growing in `permanent_obstack'.
2733 No need to return its address; the caller will get that
2734 from the obstack when the object is complete. */
2737 record_constant_1 (exp
)
2740 register char *strp
;
2742 register enum tree_code code
= TREE_CODE (exp
);
2744 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2749 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2750 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2751 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2755 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2756 strp
= (char *) &TREE_REAL_CST (exp
);
2757 len
= sizeof TREE_REAL_CST (exp
);
2761 if (flag_writable_strings
)
2764 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2765 strp
= TREE_STRING_POINTER (exp
);
2766 len
= TREE_STRING_LENGTH (exp
);
2767 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2768 sizeof TREE_STRING_LENGTH (exp
));
2772 record_constant_1 (TREE_REALPART (exp
));
2773 record_constant_1 (TREE_IMAGPART (exp
));
2777 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2779 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2780 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2781 obstack_blank (&permanent_obstack
, nbytes
);
2782 get_set_constructor_bytes
2783 (exp
, (unsigned char *) permanent_obstack
.next_free
-nbytes
,
2790 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2791 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2793 int have_purpose
= 0;
2795 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2796 if (TREE_PURPOSE (link
))
2799 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2801 /* For record constructors, insist that the types match.
2802 For arrays, just verify both constructors are for arrays
2803 of the same mode. Then insist that either both or none
2804 have any TREE_PURPOSE values. */
2805 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2806 type
= TREE_TYPE (exp
);
2810 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2811 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2812 obstack_grow (&permanent_obstack
, &mode
, sizeof mode
);
2814 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2815 sizeof have_purpose
);
2817 /* For arrays, insist that the size in bytes match. */
2818 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2820 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2821 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2824 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2826 if (TREE_VALUE (link
))
2827 record_constant_1 (TREE_VALUE (link
));
2832 obstack_grow (&permanent_obstack
,
2833 (char *) &zero
, sizeof zero
);
2836 if (TREE_PURPOSE (link
)
2837 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2838 obstack_grow (&permanent_obstack
,
2839 (char *) &TREE_PURPOSE (link
),
2840 sizeof TREE_PURPOSE (link
));
2841 else if (TREE_PURPOSE (link
))
2842 record_constant_1 (TREE_PURPOSE (link
));
2843 else if (have_purpose
)
2847 obstack_grow (&permanent_obstack
,
2848 (char *) &zero
, sizeof zero
);
2856 struct addr_const value
;
2858 decode_addr_const (exp
, &value
);
2859 /* Record the offset. */
2860 obstack_grow (&permanent_obstack
,
2861 (char *) &value
.offset
, sizeof value
.offset
);
2862 /* Record the symbol name. */
2863 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2864 strlen (XSTR (value
.base
, 0)) + 1);
2871 record_constant_1 (TREE_OPERAND (exp
, 0));
2872 record_constant_1 (TREE_OPERAND (exp
, 1));
2877 case NON_LVALUE_EXPR
:
2878 record_constant_1 (TREE_OPERAND (exp
, 0));
2885 /* Record constant contents. */
2886 obstack_grow (&permanent_obstack
, strp
, len
);
2889 /* Record a list of constant expressions that were passed to
2890 output_constant_def but that could not be output right away. */
2892 struct deferred_constant
2894 struct deferred_constant
*next
;
2900 static struct deferred_constant
*deferred_constants
;
2902 /* Another list of constants which should be output after the
2904 static struct deferred_constant
*after_function_constants
;
2906 /* Nonzero means defer output of addressed subconstants
2907 (i.e., those for which output_constant_def is called.) */
2908 static int defer_addressed_constants_flag
;
2910 /* Start deferring output of subconstants. */
2913 defer_addressed_constants ()
2915 defer_addressed_constants_flag
++;
2918 /* Stop deferring output of subconstants,
2919 and output now all those that have been deferred. */
2922 output_deferred_addressed_constants ()
2924 struct deferred_constant
*p
, *next
;
2926 defer_addressed_constants_flag
--;
2928 if (defer_addressed_constants_flag
> 0)
2931 for (p
= deferred_constants
; p
; p
= next
)
2933 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2938 deferred_constants
= 0;
2941 /* Output any constants which should appear after a function. */
2944 output_after_function_constants ()
2946 struct deferred_constant
*p
, *next
;
2948 for (p
= after_function_constants
; p
; p
= next
)
2950 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2955 after_function_constants
= 0;
2958 /* Make a copy of the whole tree structure for a constant.
2959 This handles the same types of nodes that compare_constant
2960 and record_constant handle. */
2966 switch (TREE_CODE (exp
))
2969 /* For ADDR_EXPR, we do not want to copy the decl whose address
2970 is requested. We do want to copy constants though. */
2971 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2972 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2973 copy_constant (TREE_OPERAND (exp
, 0)));
2975 return copy_node (exp
);
2980 return copy_node (exp
);
2983 return build_complex (TREE_TYPE (exp
),
2984 copy_constant (TREE_REALPART (exp
)),
2985 copy_constant (TREE_IMAGPART (exp
)));
2989 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2990 copy_constant (TREE_OPERAND (exp
, 0)),
2991 copy_constant (TREE_OPERAND (exp
, 1)));
2995 case NON_LVALUE_EXPR
:
2996 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2997 copy_constant (TREE_OPERAND (exp
, 0)));
3001 tree copy
= copy_node (exp
);
3002 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
3005 CONSTRUCTOR_ELTS (copy
) = list
;
3006 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3007 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
3008 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
3009 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3010 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
3020 /* Return an rtx representing a reference to constant data in memory
3021 for the constant expression EXP.
3023 If assembler code for such a constant has already been output,
3024 return an rtx to refer to it.
3025 Otherwise, output such a constant in memory (or defer it for later)
3026 and generate an rtx for it.
3028 The TREE_CST_RTL of EXP is set up to point to that rtx.
3029 The const_hash_table records which constants already have label strings. */
3032 output_constant_def (exp
)
3036 register struct constant_descriptor
*desc
;
3041 if (TREE_CST_RTL (exp
))
3042 return TREE_CST_RTL (exp
);
3044 /* Make sure any other constants whose addresses appear in EXP
3045 are assigned label numbers. */
3047 reloc
= output_addressed_constants (exp
);
3049 /* Compute hash code of EXP. Search the descriptors for that hash code
3050 to see if any of them describes EXP. If yes, the descriptor records
3051 the label number already assigned. */
3053 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
3055 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
3056 if (compare_constant (exp
, desc
))
3061 /* No constant equal to EXP is known to have been output.
3062 Make a constant descriptor to enter EXP in the hash table.
3063 Assign the label number and record it in the descriptor for
3064 future calls to this function to find. */
3066 /* Create a string containing the label name, in LABEL. */
3067 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3069 desc
= record_constant (exp
);
3070 desc
->next
= const_hash_table
[hash
];
3071 desc
->label
= ggc_alloc_string (label
, -1);
3072 const_hash_table
[hash
] = desc
;
3074 /* We have a symbol name; construct the SYMBOL_REF and the MEM
3075 in the permanent obstack. We could also construct this in the
3076 obstack of EXP and put it into TREE_CST_RTL, but we have no way
3077 of knowing what obstack it is (e.g., it might be in a function
3078 obstack of a function we are nested inside). */
3080 push_obstacks_nochange ();
3081 end_temporary_allocation ();
3084 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
3085 gen_rtx_SYMBOL_REF (Pmode
, desc
->label
));
3087 RTX_UNCHANGING_P (desc
->rtl
) = 1;
3088 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
)))
3089 MEM_SET_IN_STRUCT_P (desc
->rtl
, 1);
3096 TREE_CST_RTL (exp
) = desc
->rtl
;
3098 /* Optionally set flags or add text to the name to record information
3099 such as that it is a function name. If the name is changed, the macro
3100 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3101 #ifdef ENCODE_SECTION_INFO
3102 ENCODE_SECTION_INFO (exp
);
3105 /* If this is the first time we've seen this particular constant,
3106 output it (or defer its output for later). */
3109 int after_function
= 0;
3111 #ifdef CONSTANT_AFTER_FUNCTION_P
3112 if (current_function_decl
!= 0
3113 && CONSTANT_AFTER_FUNCTION_P (exp
))
3117 if (defer_addressed_constants_flag
|| after_function
)
3119 struct deferred_constant
*p
;
3120 p
= (struct deferred_constant
*) xmalloc (sizeof (struct deferred_constant
));
3122 push_obstacks_nochange ();
3123 suspend_momentary ();
3124 p
->exp
= copy_constant (exp
);
3127 p
->labelno
= const_labelno
++;
3130 p
->next
= after_function_constants
;
3131 after_function_constants
= p
;
3135 p
->next
= deferred_constants
;
3136 deferred_constants
= p
;
3141 /* Do no output if -fsyntax-only. */
3142 if (! flag_syntax_only
)
3143 output_constant_def_contents (exp
, reloc
, const_labelno
);
3148 return TREE_CST_RTL (exp
);
3151 /* Now output assembler code to define the label for EXP,
3152 and follow it with the data of EXP. */
3155 output_constant_def_contents (exp
, reloc
, labelno
)
3162 if (IN_NAMED_SECTION (exp
))
3163 named_section (exp
, NULL
, reloc
);
3166 /* First switch to text section, except for writable strings. */
3167 #ifdef SELECT_SECTION
3168 SELECT_SECTION (exp
, reloc
);
3170 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
3171 || (flag_pic
&& reloc
))
3174 readonly_data_section ();
3178 /* Align the location counter as required by EXP's data type. */
3179 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3180 #ifdef CONSTANT_ALIGNMENT
3181 align
= CONSTANT_ALIGNMENT (exp
, align
);
3184 if (align
> BITS_PER_UNIT
)
3185 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3187 /* Output the label itself. */
3188 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3190 /* Output the value of EXP. */
3191 output_constant (exp
,
3192 (TREE_CODE (exp
) == STRING_CST
3193 ? TREE_STRING_LENGTH (exp
)
3194 : int_size_in_bytes (TREE_TYPE (exp
))));
3198 /* Structure to represent sufficient information about a constant so that
3199 it can be output when the constant pool is output, so that function
3200 integration can be done, and to simplify handling on machines that reference
3201 constant pool as base+displacement. */
3203 struct pool_constant
3205 struct constant_descriptor
*desc
;
3206 struct pool_constant
*next
;
3207 enum machine_mode mode
;
3215 /* Structure used to maintain hash table mapping symbols used to their
3216 corresponding constants. */
3221 struct pool_constant
*pool
;
3222 struct pool_sym
*next
;
3225 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3226 The argument is XSTR (... , 0) */
3228 #define SYMHASH(LABEL) \
3229 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3231 /* Initialize constant pool hashing for a new function. */
3234 init_varasm_status (f
)
3237 struct varasm_status
*p
;
3238 p
= (struct varasm_status
*) xmalloc (sizeof (struct varasm_status
));
3240 p
->x_const_rtx_hash_table
3241 = ((struct constant_descriptor
**)
3242 xmalloc (MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*)));
3243 p
->x_const_rtx_sym_hash_table
3244 = ((struct pool_sym
**)
3245 xmalloc (MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*)));
3246 bzero ((char *) p
->x_const_rtx_hash_table
,
3247 MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*));
3248 bzero ((char *) p
->x_const_rtx_sym_hash_table
,
3249 MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*));
3251 p
->x_first_pool
= p
->x_last_pool
= 0;
3252 p
->x_pool_offset
= 0;
3253 p
->x_const_double_chain
= 0;
3256 /* Mark PC for GC. */
3259 mark_pool_constant (pc
)
3260 struct pool_constant
*pc
;
3264 ggc_mark_rtx (pc
->constant
);
3269 /* Mark PPS for GC. */
3272 mark_pool_sym_hash_table (pps
)
3273 struct pool_sym
**pps
;
3275 struct pool_sym
*ps
;
3278 for (i
= 0; i
< MAX_RTX_HASH_TABLE
; ++i
)
3279 for (ps
= pps
[i
]; ps
; ps
= ps
->next
)
3280 ggc_mark_string (ps
->label
);
3283 /* Mark P for GC. */
3286 mark_varasm_status (p
)
3287 struct varasm_status
*p
;
3292 mark_pool_constant (p
->x_first_pool
);
3293 mark_pool_sym_hash_table (p
->x_const_rtx_sym_hash_table
);
3294 ggc_mark_rtx (p
->x_const_double_chain
);
3297 /* Clear out all parts of the state in F that can safely be discarded
3298 after the function has been compiled, to let garbage collection
3299 reclaim the memory. */
3302 free_varasm_status (f
)
3305 struct varasm_status
*p
;
3308 free (p
->x_const_rtx_hash_table
);
3309 free (p
->x_const_rtx_sym_hash_table
);
3314 enum kind
{ RTX_DOUBLE
, RTX_INT
};
3318 #ifdef ONLY_INT_FIELDS
3319 unsigned int kind
: 16;
3320 unsigned int mode
: 16;
3322 enum kind kind
: 16;
3323 enum machine_mode mode
: 16;
3326 union real_extract du
;
3327 struct addr_const addr
;
3328 struct {HOST_WIDE_INT high
, low
;} di
;
3332 /* Express an rtx for a constant integer (perhaps symbolic)
3333 as the sum of a symbol or label plus an explicit integer.
3334 They are stored into VALUE. */
3337 decode_rtx_const (mode
, x
, value
)
3338 enum machine_mode mode
;
3340 struct rtx_const
*value
;
3342 /* Clear the whole structure, including any gaps. */
3345 int *p
= (int *) value
;
3346 int *end
= (int *) (value
+ 1);
3351 value
->kind
= RTX_INT
; /* Most usual kind. */
3354 switch (GET_CODE (x
))
3357 value
->kind
= RTX_DOUBLE
;
3358 if (GET_MODE (x
) != VOIDmode
)
3360 value
->mode
= GET_MODE (x
);
3361 bcopy ((char *) &CONST_DOUBLE_LOW (x
),
3362 (char *) &value
->un
.du
, sizeof value
->un
.du
);
3366 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3367 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3372 value
->un
.addr
.offset
= INTVAL (x
);
3378 value
->un
.addr
.base
= x
;
3383 if (GET_CODE (x
) == PLUS
)
3385 value
->un
.addr
.base
= XEXP (x
, 0);
3386 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3388 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3390 else if (GET_CODE (x
) == MINUS
)
3392 value
->un
.addr
.base
= XEXP (x
, 0);
3393 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3395 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3405 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3406 switch (GET_CODE (value
->un
.addr
.base
))
3409 /* Use the string's address, not the SYMBOL_REF's address,
3410 for the sake of addresses of library routines. */
3411 value
->un
.addr
.base
= XSTR (value
->un
.addr
.base
, 0);
3415 /* For a LABEL_REF, compare labels. */
3416 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3423 /* Given a MINUS expression, simplify it if both sides
3424 include the same symbol. */
3427 simplify_subtraction (x
)
3430 struct rtx_const val0
, val1
;
3432 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3433 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3435 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3436 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3440 /* Compute a hash code for a constant RTL expression. */
3443 const_hash_rtx (mode
, x
)
3444 enum machine_mode mode
;
3450 struct rtx_const value
;
3451 decode_rtx_const (mode
, x
, &value
);
3453 /* Compute hashing function */
3455 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3456 hi
+= ((int *) &value
)[i
];
3458 hi
&= (1 << HASHBITS
) - 1;
3459 hi
%= MAX_RTX_HASH_TABLE
;
3463 /* Compare a constant rtl object X with a constant-descriptor DESC.
3464 Return 1 if DESC describes a constant with the same value as X. */
3467 compare_constant_rtx (mode
, x
, desc
)
3468 enum machine_mode mode
;
3470 struct constant_descriptor
*desc
;
3472 register int *p
= (int *) desc
->contents
;
3475 struct rtx_const value
;
3477 decode_rtx_const (mode
, x
, &value
);
3478 strp
= (int *) &value
;
3479 len
= sizeof value
/ sizeof (int);
3481 /* Compare constant contents. */
3483 if (*p
++ != *strp
++)
3489 /* Construct a constant descriptor for the rtl-expression X.
3490 It is up to the caller to enter the descriptor in the hash table. */
3492 static struct constant_descriptor
*
3493 record_constant_rtx (mode
, x
)
3494 enum machine_mode mode
;
3497 struct constant_descriptor
*ptr
;
3500 struct rtx_const value
;
3502 decode_rtx_const (mode
, x
, &value
);
3504 /* Put these things in the saveable obstack so we can ensure it won't
3505 be freed if we are called from combine or some other phase that discards
3506 memory allocated from function_obstack (current_obstack). */
3507 obstack_grow (saveable_obstack
, &ptr
, sizeof ptr
);
3508 obstack_grow (saveable_obstack
, &label
, sizeof label
);
3509 obstack_grow (saveable_obstack
, &rtl
, sizeof rtl
);
3511 /* Record constant contents. */
3512 obstack_grow (saveable_obstack
, &value
, sizeof value
);
3514 return (struct constant_descriptor
*) obstack_finish (saveable_obstack
);
3517 /* Given a constant rtx X, make (or find) a memory constant for its value
3518 and return a MEM rtx to refer to it in memory. */
3521 force_const_mem (mode
, x
)
3522 enum machine_mode mode
;
3526 register struct constant_descriptor
*desc
;
3531 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3532 (this will always be true for floating CONST_DOUBLEs that have been
3533 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3534 use the previous copy. Otherwise, make a new one. Note that in
3535 the unlikely event that this same CONST_DOUBLE is used in two different
3536 modes in an alternating fashion, we will allocate a lot of different
3537 memory locations, but this should be extremely rare. */
3539 if (GET_CODE (x
) == CONST_DOUBLE
3540 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
3541 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
3542 return CONST_DOUBLE_MEM (x
);
3544 /* Compute hash code of X. Search the descriptors for that hash code
3545 to see if any of them describes X. If yes, the descriptor records
3546 the label number already assigned. */
3548 hash
= const_hash_rtx (mode
, x
);
3550 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3551 if (compare_constant_rtx (mode
, x
, desc
))
3553 found
= desc
->label
;
3559 register struct pool_constant
*pool
;
3560 register struct pool_sym
*sym
;
3563 /* No constant equal to X is known to have been output.
3564 Make a constant descriptor to enter X in the hash table.
3565 Assign the label number and record it in the descriptor for
3566 future calls to this function to find. */
3568 desc
= record_constant_rtx (mode
, x
);
3569 desc
->next
= const_rtx_hash_table
[hash
];
3570 const_rtx_hash_table
[hash
] = desc
;
3572 /* Align the location counter as required by EXP's data type. */
3573 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
3574 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
3575 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
3576 #ifdef CONSTANT_ALIGNMENT
3577 align
= CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode
, 0), x
),
3578 align
* BITS_PER_UNIT
) / BITS_PER_UNIT
;
3581 pool_offset
+= align
- 1;
3582 pool_offset
&= ~ (align
- 1);
3584 /* If RTL is not being placed into the saveable obstack, make a
3585 copy of X that is in the saveable obstack in case we are
3586 being called from combine or some other phase that discards
3587 memory it allocates. We used to only do this if it is a
3588 CONST; however, reload can allocate a CONST_INT when
3589 eliminating registers. */
3590 if (rtl_obstack
!= saveable_obstack
3591 && (GET_CODE (x
) == CONST
|| GET_CODE (x
) == CONST_INT
))
3593 push_obstacks_nochange ();
3594 rtl_in_saveable_obstack ();
3596 if (GET_CODE (x
) == CONST
)
3597 x
= gen_rtx_CONST (GET_MODE (x
),
3598 gen_rtx_PLUS (GET_MODE (x
),
3599 XEXP (XEXP (x
, 0), 0),
3600 XEXP (XEXP (x
, 0), 1)));
3602 x
= GEN_INT (INTVAL (x
));
3607 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3609 pool
= (struct pool_constant
*) savealloc (sizeof (struct pool_constant
));
3613 pool
->labelno
= const_labelno
;
3614 pool
->align
= align
;
3615 pool
->offset
= pool_offset
;
3622 last_pool
->next
= pool
;
3625 pool_offset
+= GET_MODE_SIZE (mode
);
3627 /* Create a string containing the label name, in LABEL. */
3628 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3632 desc
->label
= found
= ggc_alloc_string (label
, -1);
3634 /* Add label to symbol hash table. */
3635 hash
= SYMHASH (found
);
3636 sym
= (struct pool_sym
*) savealloc (sizeof (struct pool_sym
));
3639 sym
->next
= const_rtx_sym_hash_table
[hash
];
3640 const_rtx_sym_hash_table
[hash
] = sym
;
3643 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3645 def
= gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, found
));
3647 RTX_UNCHANGING_P (def
) = 1;
3648 /* Mark the symbol_ref as belonging to this constants pool. */
3649 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3650 current_function_uses_const_pool
= 1;
3652 if (GET_CODE (x
) == CONST_DOUBLE
)
3654 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
3656 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
3657 const_double_chain
= x
;
3659 CONST_DOUBLE_MEM (x
) = def
;
3665 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3666 the corresponding pool_constant structure. */
3668 static struct pool_constant
*
3669 find_pool_constant (f
, addr
)
3673 struct pool_sym
*sym
;
3674 char *label
= XSTR (addr
, 0);
3676 for (sym
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
3677 if (sym
->label
== label
)
3683 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3686 get_pool_constant (addr
)
3689 return (find_pool_constant (cfun
, addr
))->constant
;
3692 /* Likewise, but for the constant pool of a specific function. */
3695 get_pool_constant_for_function (f
, addr
)
3699 return (find_pool_constant (f
, addr
))->constant
;
3702 /* Similar, return the mode. */
3705 get_pool_mode (addr
)
3708 return (find_pool_constant (cfun
, addr
))->mode
;
3712 get_pool_mode_for_function (f
, addr
)
3716 return (find_pool_constant (f
, addr
))->mode
;
3719 /* Similar, return the offset in the constant pool. */
3722 get_pool_offset (addr
)
3725 return (find_pool_constant (cfun
, addr
))->offset
;
3728 /* Return the size of the constant pool. */
3736 /* Write all the constants in the constant pool. */
3739 output_constant_pool (fnname
, fndecl
)
3740 const char *fnname ATTRIBUTE_UNUSED
;
3741 tree fndecl ATTRIBUTE_UNUSED
;
3743 struct pool_constant
*pool
;
3745 union real_extract u
;
3747 /* It is possible for gcc to call force_const_mem and then to later
3748 discard the instructions which refer to the constant. In such a
3749 case we do not need to output the constant. */
3750 mark_constant_pool ();
3752 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3753 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3756 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3763 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3764 whose CODE_LABEL has been deleted. This can occur if a jump table
3765 is eliminated by optimization. If so, write a constant of zero
3766 instead. Note that this can also happen by turning the
3767 CODE_LABEL into a NOTE. */
3768 if (((GET_CODE (x
) == LABEL_REF
3769 && (INSN_DELETED_P (XEXP (x
, 0))
3770 || GET_CODE (XEXP (x
, 0)) == NOTE
)))
3771 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
3772 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
3773 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))
3774 || GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == NOTE
)))
3777 /* First switch to correct section. */
3778 #ifdef SELECT_RTX_SECTION
3779 SELECT_RTX_SECTION (pool
->mode
, x
);
3781 readonly_data_section ();
3784 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3785 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3786 pool
->align
, pool
->labelno
, done
);
3789 if (pool
->align
> 1)
3790 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (pool
->align
));
3792 /* Output the label. */
3793 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3795 /* Output the value of the constant itself. */
3796 switch (GET_MODE_CLASS (pool
->mode
))
3799 if (GET_CODE (x
) != CONST_DOUBLE
)
3802 bcopy ((char *) &CONST_DOUBLE_LOW (x
), (char *) &u
, sizeof u
);
3803 assemble_real (u
.d
, pool
->mode
);
3807 case MODE_PARTIAL_INT
:
3808 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
3815 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3821 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3822 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3825 /* Done with this pool. */
3826 first_pool
= last_pool
= 0;
3829 /* Look through the instructions for this function, and mark all the
3830 entries in the constant pool which are actually being used. */
3833 mark_constant_pool ()
3836 struct pool_constant
*pool
;
3838 if (first_pool
== 0)
3841 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3844 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3845 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3846 mark_constants (PATTERN (insn
));
3848 for (insn
= current_function_epilogue_delay_list
;
3850 insn
= XEXP (insn
, 1))
3851 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3852 mark_constants (PATTERN (insn
));
3854 /* It's possible that the only reference to a symbol is in a symbol
3855 that's in the constant pool. This happens in Fortran under some
3856 situations. (When the constant contains the address of another
3857 constant, and only the first is used directly in an insn.)
3858 This is potentially suboptimal if there's ever a possibility of
3859 backwards (in pool order) 2'd level references. However, it's
3860 not clear that 2'd level references can happen. */
3861 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3863 struct pool_sym
*sym
;
3866 /* skip unmarked entries; no insn refers to them. */
3870 /* Skip everything except SYMBOL_REFs. */
3871 if (GET_CODE (pool
->constant
) != SYMBOL_REF
)
3873 label
= XSTR (pool
->constant
, 0);
3875 /* Be sure the symbol's value is marked. */
3876 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
;
3878 if (sym
->label
== label
)
3879 sym
->pool
->mark
= 1;
3880 /* If we didn't find it, there's something truly wrong here, but it
3881 will be announced by the assembler. */
3890 register const char *format_ptr
;
3895 if (GET_CODE (x
) == SYMBOL_REF
)
3897 if (CONSTANT_POOL_ADDRESS_P (x
))
3898 find_pool_constant (cfun
, x
)->mark
= 1;
3901 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3902 a MEM, but does not constitute a use of that MEM. */
3903 else if (GET_CODE (x
) == CONST_DOUBLE
)
3906 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3907 insns, not any notes that may be attached. We don't want to mark
3908 a constant just because it happens to appear in a REG_EQUIV note. */
3909 if (GET_RTX_CLASS (GET_CODE (x
)) == 'i')
3911 mark_constants (PATTERN (x
));
3915 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3917 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3919 switch (*format_ptr
++)
3922 mark_constants (XEXP (x
, i
));
3926 if (XVEC (x
, i
) != 0)
3930 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3931 mark_constants (XVECEXP (x
, i
, j
));
3950 /* Find all the constants whose addresses are referenced inside of EXP,
3951 and make sure assembler code with a label has been output for each one.
3952 Indicate whether an ADDR_EXPR has been encountered. */
3955 output_addressed_constants (exp
)
3960 switch (TREE_CODE (exp
))
3964 register tree constant
= TREE_OPERAND (exp
, 0);
3966 while (TREE_CODE (constant
) == COMPONENT_REF
)
3968 constant
= TREE_OPERAND (constant
, 0);
3971 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
3972 || TREE_CODE (constant
) == CONSTRUCTOR
)
3973 /* No need to do anything here
3974 for addresses of variables or functions. */
3975 output_constant_def (constant
);
3982 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3983 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3988 case NON_LVALUE_EXPR
:
3989 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3995 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
3996 if (TREE_VALUE (link
) != 0)
3997 reloc
|= output_addressed_constants (TREE_VALUE (link
));
4007 /* Return nonzero if VALUE is a valid constant-valued expression
4008 for use in initializing a static variable; one that can be an
4009 element of a "constant" initializer.
4011 Return null_pointer_node if the value is absolute;
4012 if it is relocatable, return the variable that determines the relocation.
4013 We assume that VALUE has been folded as much as possible;
4014 therefore, we do not need to check for such things as
4015 arithmetic-combinations of integers. */
4018 initializer_constant_valid_p (value
, endtype
)
4022 switch (TREE_CODE (value
))
4025 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
4026 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
4027 && TREE_CONSTANT (value
)
4028 && CONSTRUCTOR_ELTS (value
))
4030 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
4033 return TREE_STATIC (value
) ? null_pointer_node
: 0;
4039 return null_pointer_node
;
4042 return TREE_OPERAND (value
, 0);
4044 case NON_LVALUE_EXPR
:
4045 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4049 /* Allow conversions between pointer types. */
4050 if (POINTER_TYPE_P (TREE_TYPE (value
))
4051 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4052 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4054 /* Allow conversions between real types. */
4055 if (FLOAT_TYPE_P (TREE_TYPE (value
))
4056 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4057 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4059 /* Allow length-preserving conversions between integer types. */
4060 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4061 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4062 && (TYPE_PRECISION (TREE_TYPE (value
))
4063 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4064 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4066 /* Allow conversions between other integer types only if
4068 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4069 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4071 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4073 if (inner
== null_pointer_node
)
4074 return null_pointer_node
;
4078 /* Allow (int) &foo provided int is as wide as a pointer. */
4079 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4080 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4081 && (TYPE_PRECISION (TREE_TYPE (value
))
4082 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4083 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4086 /* Likewise conversions from int to pointers, but also allow
4087 conversions from 0. */
4088 if (POINTER_TYPE_P (TREE_TYPE (value
))
4089 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4091 if (integer_zerop (TREE_OPERAND (value
, 0)))
4092 return null_pointer_node
;
4093 else if (TYPE_PRECISION (TREE_TYPE (value
))
4094 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
4095 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4099 /* Allow conversions to union types if the value inside is okay. */
4100 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4101 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4106 if (! INTEGRAL_TYPE_P (endtype
)
4107 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4109 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4111 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4113 /* If either term is absolute, use the other terms relocation. */
4114 if (valid0
== null_pointer_node
)
4116 if (valid1
== null_pointer_node
)
4122 if (! INTEGRAL_TYPE_P (endtype
)
4123 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4125 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4127 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4129 /* Win if second argument is absolute. */
4130 if (valid1
== null_pointer_node
)
4132 /* Win if both arguments have the same relocation.
4133 Then the value is absolute. */
4134 if (valid0
== valid1
&& valid0
!= 0)
4135 return null_pointer_node
;
4138 /* Support differences between labels. */
4139 if (INTEGRAL_TYPE_P (endtype
))
4142 op0
= TREE_OPERAND (value
, 0);
4143 op1
= TREE_OPERAND (value
, 1);
4147 if (TREE_CODE (op0
) == ADDR_EXPR
4148 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
4149 && TREE_CODE (op1
) == ADDR_EXPR
4150 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
4151 return null_pointer_node
;
4162 /* Output assembler code for constant EXP to FILE, with no label.
4163 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4164 Assumes output_addressed_constants has been done on EXP already.
4166 Generate exactly SIZE bytes of assembler data, padding at the end
4167 with zeros if necessary. SIZE must always be specified.
4169 SIZE is important for structure constructors,
4170 since trailing members may have been omitted from the constructor.
4171 It is also important for initialization of arrays from string constants
4172 since the full length of the string constant might not be wanted.
4173 It is also needed for initialization of unions, where the initializer's
4174 type is just one member, and that may not be as long as the union.
4176 There a case in which we would fail to output exactly SIZE bytes:
4177 for a structure constructor that wants to produce more than SIZE bytes.
4178 But such constructors will never be generated for any possible input. */
4181 output_constant (exp
, size
)
4185 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
4187 /* Some front-ends use constants other than the standard
4188 language-indepdent varieties, but which may still be output
4189 directly. Give the front-end a chance to convert EXP to a
4190 language-independent representation. */
4191 if (lang_expand_constant
)
4192 exp
= (*lang_expand_constant
) (exp
);
4194 if (size
== 0 || flag_syntax_only
)
4197 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4198 That way we get the constant (we hope) inside it. Also, strip off any
4199 NOP_EXPR that converts between two record, union, array, or set types. */
4200 while ((TREE_CODE (exp
) == NOP_EXPR
4201 && (TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0))
4202 || AGGREGATE_TYPE_P (TREE_TYPE (exp
))))
4203 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
4204 exp
= TREE_OPERAND (exp
, 0);
4206 /* Allow a constructor with no elements for any data type.
4207 This means to fill the space with zeros. */
4208 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
4210 assemble_zeros (size
);
4221 case REFERENCE_TYPE
:
4222 /* ??? What about (int)((float)(int)&foo + 4) */
4223 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
4224 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
4225 exp
= TREE_OPERAND (exp
, 0);
4227 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4228 EXPAND_INITIALIZER
),
4230 error ("initializer for integer value is too complicated");
4235 if (TREE_CODE (exp
) != REAL_CST
)
4236 error ("initializer for floating value is not a floating constant");
4238 assemble_real (TREE_REAL_CST (exp
),
4239 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
4244 output_constant (TREE_REALPART (exp
), size
/ 2);
4245 output_constant (TREE_IMAGPART (exp
), size
/ 2);
4246 size
-= (size
/ 2) * 2;
4250 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4252 output_constructor (exp
, size
);
4255 else if (TREE_CODE (exp
) == STRING_CST
)
4259 if (size
> TREE_STRING_LENGTH (exp
))
4261 excess
= size
- TREE_STRING_LENGTH (exp
);
4262 size
= TREE_STRING_LENGTH (exp
);
4265 assemble_string (TREE_STRING_POINTER (exp
), size
);
4274 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4275 output_constructor (exp
, size
);
4281 if (TREE_CODE (exp
) == INTEGER_CST
)
4282 assemble_integer (expand_expr (exp
, NULL_RTX
,
4283 VOIDmode
, EXPAND_INITIALIZER
),
4285 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4287 unsigned char *buffer
= (unsigned char *) alloca (size
);
4288 if (get_set_constructor_bytes (exp
, buffer
, size
))
4290 assemble_string ((char *) buffer
, size
);
4293 error ("unknown set constructor type");
4301 assemble_zeros (size
);
4305 /* Subroutine of output_constant, used for CONSTRUCTORs
4306 (aggregate constants).
4307 Generate at least SIZE bytes, padding if necessary. */
4310 output_constructor (exp
, size
)
4314 register tree link
, field
= 0;
4315 HOST_WIDE_INT min_index
= 0;
4316 /* Number of bytes output or skipped so far.
4317 In other words, current position within the constructor. */
4318 int total_bytes
= 0;
4319 /* Non-zero means BYTE contains part of a byte, to be output. */
4320 int byte_buffer_in_use
= 0;
4323 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4326 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
4327 field
= TYPE_FIELDS (TREE_TYPE (exp
));
4329 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
4330 && TYPE_DOMAIN (TREE_TYPE (exp
)) != 0)
4332 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp
))));
4334 /* As LINK goes through the elements of the constant,
4335 FIELD goes through the structure fields, if the constant is a structure.
4336 if the constant is a union, then we override this,
4337 by getting the field from the TREE_LIST element.
4338 But the constant could also be an array. Then FIELD is zero.
4340 There is always a maximum of one element in the chain LINK for unions
4341 (even if the initializer in a source program incorrectly contains
4343 for (link
= CONSTRUCTOR_ELTS (exp
);
4345 link
= TREE_CHAIN (link
),
4346 field
= field
? TREE_CHAIN (field
) : 0)
4348 tree val
= TREE_VALUE (link
);
4351 /* the element in a union constructor specifies the proper field. */
4353 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
4354 || TREE_CODE (TREE_TYPE (exp
)) == UNION_TYPE
)
4356 /* if available, use the type given by link */
4357 if (TREE_PURPOSE (link
) != 0)
4358 field
= TREE_PURPOSE (link
);
4361 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
4362 index
= TREE_PURPOSE (link
);
4364 /* Eliminate the marker that makes a cast not be an lvalue. */
4368 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4370 register int fieldsize
4371 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
4372 HOST_WIDE_INT lo_index
= TREE_INT_CST_LOW (TREE_OPERAND (index
, 0));
4373 HOST_WIDE_INT hi_index
= TREE_INT_CST_LOW (TREE_OPERAND (index
, 1));
4374 HOST_WIDE_INT index
;
4375 for (index
= lo_index
; index
<= hi_index
; index
++)
4377 /* Output the element's initial value. */
4379 assemble_zeros (fieldsize
);
4381 output_constant (val
, fieldsize
);
4383 /* Count its size. */
4384 total_bytes
+= fieldsize
;
4387 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4389 /* An element that is not a bit-field. */
4391 register int fieldsize
;
4392 /* Since this structure is static,
4393 we know the positions are constant. */
4394 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
4398 bitpos
= (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val
)))
4400 * (TREE_INT_CST_LOW (index
) - min_index
));
4402 /* Output any buffered-up bit-fields preceding this element. */
4403 if (byte_buffer_in_use
)
4405 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4407 byte_buffer_in_use
= 0;
4410 /* Advance to offset of this element.
4411 Note no alignment needed in an array, since that is guaranteed
4412 if each element has the proper size. */
4413 if ((field
!= 0 || index
!= 0) && bitpos
!= total_bytes
)
4415 assemble_zeros (bitpos
- total_bytes
);
4416 total_bytes
= bitpos
;
4419 /* Determine size this element should occupy. */
4422 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
4424 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
4426 /* This avoids overflow trouble. */
4427 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
4429 size_int (BITS_PER_UNIT
));
4430 fieldsize
= TREE_INT_CST_LOW (size_tree
);
4434 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
4435 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
4439 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
4441 /* Output the element's initial value. */
4443 assemble_zeros (fieldsize
);
4445 output_constant (val
, fieldsize
);
4447 /* Count its size. */
4448 total_bytes
+= fieldsize
;
4450 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4451 error ("invalid initial value for member `%s'",
4452 IDENTIFIER_POINTER (DECL_NAME (field
)));
4455 /* Element that is a bit-field. */
4457 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
4459 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
4462 val
= integer_zero_node
;
4464 /* If this field does not start in this (or, next) byte,
4466 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4468 /* Output remnant of any bit field in previous bytes. */
4469 if (byte_buffer_in_use
)
4471 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4473 byte_buffer_in_use
= 0;
4476 /* If still not at proper byte, advance to there. */
4477 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4479 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4480 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4484 if (! byte_buffer_in_use
)
4487 /* We must split the element into pieces that fall within
4488 separate bytes, and combine each byte with previous or
4489 following bit-fields. */
4491 /* next_offset is the offset n fbits from the beginning of
4492 the structure to the next bit of this element to be processed.
4493 end_offset is the offset of the first bit past the end of
4495 while (next_offset
< end_offset
)
4499 HOST_WIDE_INT value
;
4500 int next_byte
= next_offset
/ BITS_PER_UNIT
;
4501 int next_bit
= next_offset
% BITS_PER_UNIT
;
4503 /* Advance from byte to byte
4504 within this element when necessary. */
4505 while (next_byte
!= total_bytes
)
4507 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4512 /* Number of bits we can process at once
4513 (all part of the same byte). */
4514 this_time
= MIN (end_offset
- next_offset
,
4515 BITS_PER_UNIT
- next_bit
);
4516 if (BYTES_BIG_ENDIAN
)
4518 /* On big-endian machine, take the most significant bits
4519 first (of the bits that are significant)
4520 and put them into bytes from the most significant end. */
4521 shift
= end_offset
- next_offset
- this_time
;
4522 /* Don't try to take a bunch of bits that cross
4523 the word boundary in the INTEGER_CST. We can
4524 only select bits from the LOW or HIGH part
4526 if (shift
< HOST_BITS_PER_WIDE_INT
4527 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4529 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4530 shift
= HOST_BITS_PER_WIDE_INT
;
4533 /* Now get the bits from the appropriate constant word. */
4534 if (shift
< HOST_BITS_PER_WIDE_INT
)
4536 value
= TREE_INT_CST_LOW (val
);
4538 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4540 value
= TREE_INT_CST_HIGH (val
);
4541 shift
-= HOST_BITS_PER_WIDE_INT
;
4545 /* Get the result. This works only when:
4546 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4547 byte
|= (((value
>> shift
)
4548 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4549 << (BITS_PER_UNIT
- this_time
- next_bit
));
4553 /* On little-endian machines,
4554 take first the least significant bits of the value
4555 and pack them starting at the least significant
4556 bits of the bytes. */
4557 shift
= (next_offset
4558 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
4559 /* Don't try to take a bunch of bits that cross
4560 the word boundary in the INTEGER_CST. We can
4561 only select bits from the LOW or HIGH part
4563 if (shift
< HOST_BITS_PER_WIDE_INT
4564 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4566 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4569 /* Now get the bits from the appropriate constant word. */
4570 if (shift
< HOST_BITS_PER_WIDE_INT
)
4571 value
= TREE_INT_CST_LOW (val
);
4572 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4574 value
= TREE_INT_CST_HIGH (val
);
4575 shift
-= HOST_BITS_PER_WIDE_INT
;
4579 /* Get the result. This works only when:
4580 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4581 byte
|= (((value
>> shift
)
4582 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4585 next_offset
+= this_time
;
4586 byte_buffer_in_use
= 1;
4590 if (byte_buffer_in_use
)
4592 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4595 if (total_bytes
< size
)
4596 assemble_zeros (size
- total_bytes
);
4599 #ifdef HANDLE_PRAGMA_WEAK
4600 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4601 associatd with NAME. */
4604 add_weak (name
, value
)
4608 struct weak_syms
*weak
;
4610 weak
= (struct weak_syms
*) permalloc (sizeof (struct weak_syms
));
4615 weak
->next
= weak_decls
;
4617 weak
->value
= value
;
4622 #endif /* HANDLE_PRAGMA_WEAK */
4624 /* Declare DECL to be a weak symbol. */
4630 if (! TREE_PUBLIC (decl
))
4631 error_with_decl (decl
, "weak declaration of `%s' must be public");
4632 else if (TREE_ASM_WRITTEN (decl
))
4633 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4634 else if (SUPPORTS_WEAK
)
4635 DECL_WEAK (decl
) = 1;
4636 #ifdef HANDLE_PRAGMA_WEAK
4637 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), NULL
);
4641 /* Emit any pending weak declarations. */
4643 #ifdef HANDLE_PRAGMA_WEAK
4644 struct weak_syms
* weak_decls
;
4650 #ifdef HANDLE_PRAGMA_WEAK
4651 if (HANDLE_PRAGMA_WEAK
)
4653 struct weak_syms
*t
;
4654 for (t
= weak_decls
; t
; t
= t
->next
)
4658 ASM_WEAKEN_LABEL (asm_out_file
, t
->name
);
4660 ASM_OUTPUT_DEF (asm_out_file
, t
->name
, t
->value
);
4667 /* Remove NAME from the pending list of weak symbols. This prevents
4668 the compiler from emitting multiple .weak directives which confuses
4670 #ifdef ASM_WEAKEN_LABEL
4672 remove_from_pending_weak_list (name
)
4673 char *name ATTRIBUTE_UNUSED
;
4675 #ifdef HANDLE_PRAGMA_WEAK
4676 if (HANDLE_PRAGMA_WEAK
)
4678 struct weak_syms
*t
;
4679 for (t
= weak_decls
; t
; t
= t
->next
)
4681 if (t
->name
&& strcmp (name
, t
->name
) == 0)
4690 assemble_alias (decl
, target
)
4691 tree decl
, target ATTRIBUTE_UNUSED
;
4695 make_decl_rtl (decl
, (char *) 0, 1);
4696 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4698 #ifdef ASM_OUTPUT_DEF
4699 /* Make name accessible from other files, if appropriate. */
4701 if (TREE_PUBLIC (decl
))
4703 #ifdef ASM_WEAKEN_LABEL
4704 if (DECL_WEAK (decl
))
4706 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4707 /* Remove this function from the pending weak list so that
4708 we do not emit multiple .weak directives for it. */
4709 remove_from_pending_weak_list
4710 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
4714 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4717 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4718 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4720 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4722 TREE_ASM_WRITTEN (decl
) = 1;
4724 #ifdef ASM_OUTPUT_WEAK_ALIAS
4725 if (! DECL_WEAK (decl
))
4726 warning ("only weak aliases are supported in this configuration");
4728 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4729 TREE_ASM_WRITTEN (decl
) = 1;
4731 warning ("alias definitions not supported in this configuration; ignored");
4736 /* This determines whether or not we support link-once semantics. */
4737 #ifndef SUPPORTS_ONE_ONLY
4738 #ifdef MAKE_DECL_ONE_ONLY
4739 #define SUPPORTS_ONE_ONLY 1
4741 #define SUPPORTS_ONE_ONLY 0
4745 /* Returns 1 if the target configuration supports defining public symbols
4746 so that one of them will be chosen at link time instead of generating a
4747 multiply-defined symbol error, whether through the use of weak symbols or
4748 a target-specific mechanism for having duplicates discarded. */
4751 supports_one_only ()
4753 if (SUPPORTS_ONE_ONLY
)
4755 return SUPPORTS_WEAK
;
4758 /* Set up DECL as a public symbol that can be defined in multiple
4759 translation units without generating a linker error. */
4762 make_decl_one_only (decl
)
4765 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
4768 TREE_PUBLIC (decl
) = 1;
4770 if (TREE_CODE (decl
) == VAR_DECL
4771 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4772 DECL_COMMON (decl
) = 1;
4773 else if (SUPPORTS_ONE_ONLY
)
4775 #ifdef MAKE_DECL_ONE_ONLY
4776 MAKE_DECL_ONE_ONLY (decl
);
4778 DECL_ONE_ONLY (decl
) = 1;
4780 else if (SUPPORTS_WEAK
)
4781 DECL_WEAK (decl
) = 1;
4789 ggc_add_root (const_hash_table
, MAX_HASH_TABLE
, sizeof const_hash_table
[0],
4790 mark_const_hash_entry
);
4791 ggc_add_string_root (&in_named_name
, 1);