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. */
32 /* #include <stab.h> */
39 #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
88 /* Number for making the label on the next
89 constant that is stored in memory. */
93 /* Number for making the label on the next
94 static variable internal to a function. */
98 /* Carry information from ASM_DECLARE_OBJECT_NAME
99 to ASM_FINISH_DECLARE_OBJECT. */
101 int size_directive_output
;
103 /* The last decl for which assemble_variable was called,
104 if it did ASM_DECLARE_OBJECT_NAME.
105 If the last call to assemble_variable didn't do that,
108 tree last_assemble_variable_decl
;
110 /* Nonzero if at least one function definition has been seen. */
112 static int function_defined
;
115 struct constant_descriptor
;
117 struct pool_constant
;
119 static const char *strip_reg_name
PROTO((const char *));
120 static int contains_pointers_p
PROTO((tree
));
121 static void decode_addr_const
PROTO((tree
, struct addr_const
*));
122 static int const_hash
PROTO((tree
));
123 static int compare_constant
PROTO((tree
,
124 struct constant_descriptor
*));
125 static char *compare_constant_1
PROTO((tree
, char *));
126 static struct constant_descriptor
*record_constant
PROTO((tree
));
127 static void record_constant_1
PROTO((tree
));
128 static tree copy_constant
PROTO((tree
));
129 static void output_constant_def_contents
PROTO((tree
, int, int));
130 static void decode_rtx_const
PROTO((enum machine_mode
, rtx
,
131 struct rtx_const
*));
132 static int const_hash_rtx
PROTO((enum machine_mode
, rtx
));
133 static int compare_constant_rtx
PROTO((enum machine_mode
, rtx
,
134 struct constant_descriptor
*));
135 static struct constant_descriptor
*record_constant_rtx
PROTO((enum machine_mode
,
137 static struct pool_constant
*find_pool_constant
PROTO((rtx
));
138 static void mark_constant_pool
PROTO((void));
139 static void mark_constants
PROTO((rtx
));
140 static int output_addressed_constants
PROTO((tree
));
141 static void output_after_function_constants
PROTO((void));
142 static void output_constructor
PROTO((tree
, int));
143 static void remove_from_pending_weak_list
PROTO ((char *));
144 #ifdef ASM_OUTPUT_BSS
145 static void asm_output_bss
PROTO((FILE *, tree
, char *, int, int));
147 #ifdef BSS_SECTION_ASM_OP
148 #ifdef ASM_OUTPUT_ALIGNED_BSS
149 static void asm_output_aligned_bss
PROTO((FILE *, tree
, char *, int, int));
151 #endif /* BSS_SECTION_ASM_OP */
153 static enum in_section
{ no_section
, in_text
, in_data
, in_named
154 #ifdef BSS_SECTION_ASM_OP
157 #ifdef EH_FRAME_SECTION_ASM_OP
160 #ifdef EXTRA_SECTIONS
163 } in_section
= no_section
;
165 /* Return a non-zero value if DECL has a section attribute. */
166 #define IN_NAMED_SECTION(DECL) \
167 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
168 && DECL_SECTION_NAME (DECL) != NULL_TREE)
170 /* Text of section name when in_section == in_named. */
171 static char *in_named_name
;
173 /* Define functions like text_section for any extra sections. */
174 #ifdef EXTRA_SECTION_FUNCTIONS
175 EXTRA_SECTION_FUNCTIONS
178 /* Tell assembler to switch to text section. */
183 if (in_section
!= in_text
)
185 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
186 in_section
= in_text
;
190 /* Tell assembler to switch to data section. */
195 if (in_section
!= in_data
)
197 if (flag_shared_data
)
199 #ifdef SHARED_SECTION_ASM_OP
200 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
202 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
206 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
208 in_section
= in_data
;
211 /* Tell assembler to ALWAYS switch to data section, in case
212 it's not sure where it it. */
215 force_data_section ()
217 in_section
= no_section
;
221 /* Tell assembler to switch to read-only data section. This is normally
225 readonly_data_section ()
227 #ifdef READONLY_DATA_SECTION
228 READONLY_DATA_SECTION (); /* Note this can call data_section. */
234 /* Determine if we're in the text section. */
239 return in_section
== in_text
;
242 /* Determine if we're in the data section. */
247 return in_section
== in_data
;
250 /* Tell assembler to change to section NAME for DECL.
251 If DECL is NULL, just switch to section NAME.
252 If NAME is NULL, get the name from DECL.
253 If RELOC is 1, the initializer for DECL contains relocs. */
256 named_section (decl
, name
, reloc
)
259 int reloc ATTRIBUTE_UNUSED
;
261 if (decl
!= NULL_TREE
262 && TREE_CODE_CLASS (TREE_CODE (decl
)) != 'd')
265 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
267 if (in_section
!= in_named
|| strcmp (name
, in_named_name
))
269 #ifdef ASM_OUTPUT_SECTION_NAME
270 ASM_OUTPUT_SECTION_NAME (asm_out_file
, decl
, name
, reloc
);
272 /* Section attributes are not supported if this macro isn't provided -
273 some host formats don't support them at all. The front-end should
274 already have flagged this as an error. */
278 in_named_name
= obstack_alloc (&permanent_obstack
, strlen (name
) + 1);
279 strcpy (in_named_name
, name
);
280 in_section
= in_named
;
284 #ifdef ASM_OUTPUT_SECTION_NAME
285 #ifndef UNIQUE_SECTION
286 #define UNIQUE_SECTION(DECL,RELOC) \
292 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
293 /* Strip off any encoding in name. */ \
294 STRIP_NAME_ENCODING (name, name); \
296 len = strlen (name) + 1; \
297 string = alloca (len + 1); \
298 sprintf (string, ".%s", name); \
300 DECL_SECTION_NAME (DECL) = build_string (len, string); \
303 #ifndef UNIQUE_SECTION_P
304 #define UNIQUE_SECTION_P(DECL) 0
308 #ifdef BSS_SECTION_ASM_OP
310 /* Tell the assembler to switch to the bss section. */
315 if (in_section
!= in_bss
)
317 #ifdef SHARED_BSS_SECTION_ASM_OP
318 if (flag_shared_data
)
319 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
322 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
328 #ifdef ASM_OUTPUT_BSS
330 /* Utility function for ASM_OUTPUT_BSS for targets to use if
331 they don't support alignments in .bss.
332 ??? It is believed that this function will work in most cases so such
333 support is localized here. */
336 asm_output_bss (file
, decl
, name
, size
, rounded
)
342 ASM_GLOBALIZE_LABEL (file
, name
);
344 #ifdef ASM_DECLARE_OBJECT_NAME
345 last_assemble_variable_decl
= decl
;
346 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
348 /* Standard thing is just output label for the object. */
349 ASM_OUTPUT_LABEL (file
, name
);
350 #endif /* ASM_DECLARE_OBJECT_NAME */
351 ASM_OUTPUT_SKIP (file
, rounded
);
356 #ifdef ASM_OUTPUT_ALIGNED_BSS
358 /* Utility function for targets to use in implementing
359 ASM_OUTPUT_ALIGNED_BSS.
360 ??? It is believed that this function will work in most cases so such
361 support is localized here. */
364 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
370 ASM_GLOBALIZE_LABEL (file
, name
);
372 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
373 #ifdef ASM_DECLARE_OBJECT_NAME
374 last_assemble_variable_decl
= decl
;
375 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
377 /* Standard thing is just output label for the object. */
378 ASM_OUTPUT_LABEL (file
, name
);
379 #endif /* ASM_DECLARE_OBJECT_NAME */
380 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
385 #endif /* BSS_SECTION_ASM_OP */
387 #ifdef EH_FRAME_SECTION_ASM_OP
391 if (in_section
!= in_eh_frame
)
393 fprintf (asm_out_file
, "%s\n", EH_FRAME_SECTION_ASM_OP
);
394 in_section
= in_eh_frame
;
399 /* Switch to the section for function DECL.
401 If DECL is NULL_TREE, switch to the text section.
402 ??? It's not clear that we will ever be passed NULL_TREE, but it's
403 safer to handle it. */
406 function_section (decl
)
409 if (decl
!= NULL_TREE
410 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
411 named_section (decl
, (char *) 0, 0);
416 /* Switch to section for variable DECL.
418 RELOC is the `reloc' argument to SELECT_SECTION. */
421 variable_section (decl
, reloc
)
425 if (IN_NAMED_SECTION (decl
))
426 named_section (decl
, NULL
, reloc
);
429 /* C++ can have const variables that get initialized from constructors,
430 and thus can not be in a readonly section. We prevent this by
431 verifying that the initial value is constant for objects put in a
434 error_mark_node is used by the C front end to indicate that the
435 initializer has not been seen yet. In this case, we assume that
436 the initializer must be constant.
438 C++ uses error_mark_node for variables that have complicated
439 initializers, but these variables go in BSS so we won't be called
442 #ifdef SELECT_SECTION
443 SELECT_SECTION (decl
, reloc
);
445 if (DECL_READONLY_SECTION (decl
, reloc
))
446 readonly_data_section ();
453 /* Tell assembler to switch to the section for the exception handling
459 #if defined (EXCEPTION_SECTION)
460 EXCEPTION_SECTION ();
462 #ifdef ASM_OUTPUT_SECTION_NAME
463 named_section (NULL_TREE
, ".gcc_except_table", 0);
468 readonly_data_section ();
473 /* Create the rtl to represent a function, for a function definition.
474 DECL is a FUNCTION_DECL node which describes which function.
475 The rtl is stored into DECL. */
478 make_function_rtl (decl
)
481 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
482 char *new_name
= name
;
484 /* Rename a nested function to avoid conflicts. */
485 if (decl_function_context (decl
) != 0
486 && DECL_INITIAL (decl
) != 0
487 && DECL_RTL (decl
) == 0)
491 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
492 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
493 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
498 /* When -fprefix-function-name is used, every function name is
499 prefixed. Even static functions are prefixed because they
500 could be declared latter. Note that a nested function name
502 if (flag_prefix_function_name
)
504 new_name
= (char *) alloca (strlen (name
) + CHKR_PREFIX_SIZE
+ 1);
505 strcpy (new_name
, CHKR_PREFIX
);
506 strcpy (new_name
+ CHKR_PREFIX_SIZE
, name
);
507 name
= obstack_copy0 (saveable_obstack
, new_name
, strlen (new_name
));
511 if (DECL_RTL (decl
) == 0)
514 = gen_rtx_MEM (DECL_MODE (decl
),
515 gen_rtx_SYMBOL_REF (Pmode
, name
));
517 /* Optionally set flags or add text to the name to record information
518 such as that it is a function name. If the name is changed, the macro
519 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
520 #ifdef ENCODE_SECTION_INFO
521 ENCODE_SECTION_INFO (decl
);
526 /* ??? Another way to do this would be to do what halfpic.c does
527 and maintain a hashed table of such critters. */
528 /* ??? Another way to do this would be to pass a flag bit to
529 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
530 /* Let the target reassign the RTL if it wants.
531 This is necessary, for example, when one machine specific
532 decl attribute overrides another. */
533 #ifdef REDO_SECTION_INFO_P
534 if (REDO_SECTION_INFO_P (decl
))
535 ENCODE_SECTION_INFO (decl
);
539 /* Record at least one function has been defined. */
540 function_defined
= 1;
543 /* Given NAME, a putative register name, discard any customary prefixes. */
546 strip_reg_name (name
)
549 #ifdef REGISTER_PREFIX
550 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
551 name
+= strlen (REGISTER_PREFIX
);
553 if (name
[0] == '%' || name
[0] == '#')
558 /* Decode an `asm' spec for a declaration as a register name.
559 Return the register number, or -1 if nothing specified,
560 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
561 or -3 if ASMSPEC is `cc' and is not recognized,
562 or -4 if ASMSPEC is `memory' and is not recognized.
563 Accept an exact spelling or a decimal number.
564 Prefixes such as % are optional. */
567 decode_reg_name (asmspec
)
574 /* Get rid of confusing prefixes. */
575 asmspec
= strip_reg_name (asmspec
);
577 /* Allow a decimal number as a "register name". */
578 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
579 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
581 if (asmspec
[0] != 0 && i
< 0)
584 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
590 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
592 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
595 #ifdef ADDITIONAL_REGISTER_NAMES
597 static struct { const char *name
; int number
; } table
[]
598 = ADDITIONAL_REGISTER_NAMES
;
600 for (i
= 0; i
< (int)(sizeof (table
) / sizeof (table
[0])); i
++)
601 if (! strcmp (asmspec
, table
[i
].name
))
602 return table
[i
].number
;
604 #endif /* ADDITIONAL_REGISTER_NAMES */
606 if (!strcmp (asmspec
, "memory"))
609 if (!strcmp (asmspec
, "cc"))
618 /* Create the DECL_RTL for a declaration for a static or external variable
619 or static or external function.
620 ASMSPEC, if not 0, is the string which the user specified
621 as the assembler symbol name.
622 TOP_LEVEL is nonzero if this is a file-scope variable.
624 This is never called for PARM_DECL nodes. */
627 make_decl_rtl (decl
, asmspec
, top_level
)
632 register char *name
= 0;
635 reg_number
= decode_reg_name (asmspec
);
637 if (DECL_ASSEMBLER_NAME (decl
) != NULL_TREE
)
638 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
640 if (reg_number
== -2)
642 /* ASMSPEC is given, and not the name of a register. */
643 name
= (char *) obstack_alloc (saveable_obstack
,
644 strlen (asmspec
) + 2);
646 strcpy (&name
[1], asmspec
);
649 /* For a duplicate declaration, we can be called twice on the
650 same DECL node. Don't discard the RTL already made. */
651 if (DECL_RTL (decl
) == 0)
653 /* First detect errors in declaring global registers. */
654 if (TREE_CODE (decl
) != FUNCTION_DECL
655 && DECL_REGISTER (decl
) && reg_number
== -1)
656 error_with_decl (decl
,
657 "register name not specified for `%s'");
658 else if (TREE_CODE (decl
) != FUNCTION_DECL
659 && DECL_REGISTER (decl
) && reg_number
< 0)
660 error_with_decl (decl
,
661 "invalid register name for `%s'");
662 else if ((reg_number
>= 0 || reg_number
== -3)
663 && (TREE_CODE (decl
) == FUNCTION_DECL
664 && ! DECL_REGISTER (decl
)))
665 error_with_decl (decl
,
666 "register name given for non-register variable `%s'");
667 else if (TREE_CODE (decl
) != FUNCTION_DECL
668 && DECL_REGISTER (decl
)
669 && TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
670 error_with_decl (decl
,
671 "data type of `%s' isn't suitable for a register");
672 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
)
673 && ! HARD_REGNO_MODE_OK (reg_number
,
674 TYPE_MODE (TREE_TYPE (decl
))))
675 error_with_decl (decl
,
676 "register number for `%s' isn't suitable for data type");
677 /* Now handle properly declared static register variables. */
678 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
682 if (DECL_INITIAL (decl
) != 0 && top_level
)
684 DECL_INITIAL (decl
) = 0;
685 error ("global register variable has initial value");
687 if (fixed_regs
[reg_number
] == 0
688 && function_defined
&& top_level
)
689 error ("global register variable follows a function definition");
690 if (TREE_THIS_VOLATILE (decl
))
691 warning ("volatile register variables don't work as you might wish");
693 /* If the user specified one of the eliminables registers here,
694 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
695 confused with that register and be eliminated. Although this
696 usage is somewhat suspect, we nevertheless use the following
697 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
700 = gen_rtx_REG (DECL_MODE (decl
), FIRST_PSEUDO_REGISTER
);
701 REGNO (DECL_RTL (decl
)) = reg_number
;
702 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
706 /* Make this register global, so not usable for anything
708 #ifdef ASM_DECLARE_REGISTER_GLOBAL
709 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
711 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
713 globalize_reg (reg_number
+ --nregs
);
716 /* Specifying a section attribute on a variable forces it into a
717 non-.bss section, and thus it cannot be common. */
718 else if (TREE_CODE (decl
) == VAR_DECL
719 && DECL_SECTION_NAME (decl
) != NULL_TREE
720 && DECL_INITIAL (decl
) == NULL_TREE
721 && DECL_COMMON (decl
))
722 DECL_COMMON (decl
) = 0;
724 /* Now handle ordinary static variables and functions (in memory).
725 Also handle vars declared register invalidly. */
726 if (DECL_RTL (decl
) == 0)
728 /* Can't use just the variable's own name for a variable
729 whose scope is less than the whole file.
730 Concatenate a distinguishing number. */
731 if (!top_level
&& !TREE_PUBLIC (decl
) && asmspec
== 0)
735 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
736 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
743 /* When -fprefix-function-name is used, the functions
744 names are prefixed. Only nested function names are not
746 if (flag_prefix_function_name
&& TREE_CODE (decl
) == FUNCTION_DECL
)
749 new_name
= (char *) alloca (strlen (name
) + CHKR_PREFIX_SIZE
751 strcpy (new_name
, CHKR_PREFIX
);
752 strcpy (new_name
+ CHKR_PREFIX_SIZE
, name
);
753 name
= obstack_copy0 (saveable_obstack
,
754 new_name
, strlen (new_name
));
757 DECL_RTL (decl
) = gen_rtx_MEM (DECL_MODE (decl
),
758 gen_rtx_SYMBOL_REF (Pmode
, name
));
759 MEM_ALIAS_SET (DECL_RTL (decl
)) = get_alias_set (decl
);
761 /* If this variable is to be treated as volatile, show its
762 tree node has side effects. If it has side effects, either
763 because of this test or from TREE_THIS_VOLATILE also
764 being set, show the MEM is volatile. */
765 if (flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
766 && TREE_PUBLIC (decl
))
767 TREE_SIDE_EFFECTS (decl
) = 1;
768 else if (flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
769 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))
770 TREE_SIDE_EFFECTS (decl
) = 1;
772 if (TREE_SIDE_EFFECTS (decl
))
773 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
775 if (TREE_READONLY (decl
))
776 RTX_UNCHANGING_P (DECL_RTL (decl
)) = 1;
777 MEM_SET_IN_STRUCT_P (DECL_RTL (decl
),
778 AGGREGATE_TYPE_P (TREE_TYPE (decl
)));
780 /* Optionally set flags or add text to the name to record information
781 such as that it is a function name.
782 If the name is changed, the macro ASM_OUTPUT_LABELREF
783 will have to know how to strip this information. */
784 #ifdef ENCODE_SECTION_INFO
785 ENCODE_SECTION_INFO (decl
);
791 /* If the old RTL had the wrong mode, fix the mode. */
792 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
794 rtx rtl
= DECL_RTL (decl
);
795 PUT_MODE (rtl
, DECL_MODE (decl
));
798 /* ??? Another way to do this would be to do what halfpic.c does
799 and maintain a hashed table of such critters. */
800 /* ??? Another way to do this would be to pass a flag bit to
801 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
802 /* Let the target reassign the RTL if it wants.
803 This is necessary, for example, when one machine specific
804 decl attribute overrides another. */
805 #ifdef REDO_SECTION_INFO_P
806 if (REDO_SECTION_INFO_P (decl
))
807 ENCODE_SECTION_INFO (decl
);
812 /* Make the rtl for variable VAR be volatile.
813 Use this only for static variables. */
816 make_var_volatile (var
)
819 if (GET_CODE (DECL_RTL (var
)) != MEM
)
822 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
825 /* Output alignment directive to align for constant expression EXP. */
828 assemble_constant_align (exp
)
833 /* Align the location counter as required by EXP's data type. */
834 align
= TYPE_ALIGN (TREE_TYPE (exp
));
835 #ifdef CONSTANT_ALIGNMENT
836 align
= CONSTANT_ALIGNMENT (exp
, align
);
839 if (align
> BITS_PER_UNIT
)
840 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
843 /* Output a string of literal assembler code
844 for an `asm' keyword used between functions. */
847 assemble_asm (string
)
852 if (TREE_CODE (string
) == ADDR_EXPR
)
853 string
= TREE_OPERAND (string
, 0);
855 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
858 #if 0 /* This should no longer be needed, because
859 flag_gnu_linker should be 0 on these systems,
860 which should prevent any output
861 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
862 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
863 #ifndef ASM_OUTPUT_CONSTRUCTOR
864 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
866 #ifndef ASM_OUTPUT_DESTRUCTOR
867 #define ASM_OUTPUT_DESTRUCTOR(file, name)
872 /* Record an element in the table of global destructors.
873 How this is done depends on what sort of assembler and linker
876 NAME should be the name of a global function to be called
877 at exit time. This name is output using assemble_name. */
880 assemble_destructor (name
)
883 #ifdef ASM_OUTPUT_DESTRUCTOR
884 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
888 /* Now tell GNU LD that this is part of the static destructor set. */
889 /* This code works for any machine provided you use GNU as/ld. */
890 fprintf (asm_out_file
, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
891 assemble_name (asm_out_file
, name
);
892 fputc ('\n', asm_out_file
);
897 /* Likewise for global constructors. */
900 assemble_constructor (name
)
903 #ifdef ASM_OUTPUT_CONSTRUCTOR
904 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
908 /* Now tell GNU LD that this is part of the static constructor set. */
909 /* This code works for any machine provided you use GNU as/ld. */
910 fprintf (asm_out_file
, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
911 assemble_name (asm_out_file
, name
);
912 fputc ('\n', asm_out_file
);
917 /* Likewise for entries we want to record for garbage collection.
918 Garbage collection is still under development. */
921 assemble_gc_entry (name
)
924 #ifdef ASM_OUTPUT_GC_ENTRY
925 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
929 /* Now tell GNU LD that this is part of the static constructor set. */
930 fprintf (asm_out_file
, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
931 assemble_name (asm_out_file
, name
);
932 fputc ('\n', asm_out_file
);
937 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
938 a non-zero value if the constant pool should be output before the
939 start of the function, or a zero value if the pool should output
940 after the end of the function. The default is to put it before the
943 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
944 #define CONSTANT_POOL_BEFORE_FUNCTION 1
947 /* Output assembler code for the constant pool of a function and associated
948 with defining the name of the function. DECL describes the function.
949 NAME is the function's name. For the constant pool, we use the current
950 constant pool data. */
953 assemble_start_function (decl
, fnname
)
959 /* The following code does not need preprocessing in the assembler. */
963 if (CONSTANT_POOL_BEFORE_FUNCTION
)
964 output_constant_pool (fnname
, decl
);
966 #ifdef ASM_OUTPUT_SECTION_NAME
967 /* If the function is to be put in its own section and it's not in a section
968 already, indicate so. */
969 if ((flag_function_sections
970 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
971 || UNIQUE_SECTION_P (decl
))
972 UNIQUE_SECTION (decl
, 0);
975 function_section (decl
);
977 /* Tell assembler to move to target machine's alignment for functions. */
978 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
980 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
982 /* Handle a user-specified function alignment.
983 Note that we still need to align to FUNCTION_BOUNDARY, as above,
984 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
985 if (align_functions_log
> align
)
987 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
988 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
989 align_functions_log
, align_functions
-1);
991 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
995 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
996 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
999 #ifdef SDB_DEBUGGING_INFO
1000 /* Output SDB definition of the function. */
1001 if (write_symbols
== SDB_DEBUG
)
1002 sdbout_mark_begin_function ();
1005 #ifdef DBX_DEBUGGING_INFO
1006 /* Output DBX definition of the function. */
1007 if (write_symbols
== DBX_DEBUG
)
1008 dbxout_begin_function (decl
);
1011 /* Make function name accessible from other files, if appropriate. */
1013 if (TREE_PUBLIC (decl
))
1015 if (! first_global_object_name
)
1020 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1021 name
= &first_global_object_name
;
1023 name
= &weak_global_object_name
;
1025 STRIP_NAME_ENCODING (p
, fnname
);
1026 *name
= permalloc (strlen (p
) + 1);
1030 #ifdef ASM_WEAKEN_LABEL
1031 if (DECL_WEAK (decl
))
1033 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
1034 /* Remove this function from the pending weak list so that
1035 we do not emit multiple .weak directives for it. */
1036 remove_from_pending_weak_list
1037 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1041 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
1044 /* Do any machine/system dependent processing of the function name */
1045 #ifdef ASM_DECLARE_FUNCTION_NAME
1046 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1048 /* Standard thing is just output label for the function. */
1049 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1050 #endif /* ASM_DECLARE_FUNCTION_NAME */
1053 /* Output assembler code associated with defining the size of the
1054 function. DECL describes the function. NAME is the function's name. */
1057 assemble_end_function (decl
, fnname
)
1061 #ifdef ASM_DECLARE_FUNCTION_SIZE
1062 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1064 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1066 output_constant_pool (fnname
, decl
);
1067 function_section (decl
); /* need to switch back */
1070 /* Output any constants which should appear after the function. */
1071 output_after_function_constants ();
1074 /* Assemble code to leave SIZE bytes of zeros. */
1077 assemble_zeros (size
)
1080 /* Do no output if -fsyntax-only. */
1081 if (flag_syntax_only
)
1084 #ifdef ASM_NO_SKIP_IN_TEXT
1085 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1086 so we must output 0s explicitly in the text section. */
1087 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1091 for (i
= 0; i
< size
- 20; i
+= 20)
1094 fprintf (asm_out_file
,
1095 "%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
);
1097 fprintf (asm_out_file
,
1098 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1104 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
1106 fprintf (asm_out_file
, "\tbyte 0");
1109 for (; i
< size
; i
++)
1110 fprintf (asm_out_file
, ",0");
1111 fprintf (asm_out_file
, "\n");
1117 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1120 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1123 assemble_align (align
)
1126 if (align
> BITS_PER_UNIT
)
1127 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1130 /* Assemble a string constant with the specified C string as contents. */
1133 assemble_string (p
, size
)
1140 /* If the string is very long, split it up. */
1144 int thissize
= size
- pos
;
1145 if (thissize
> maximum
)
1148 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1156 /* Assemble everything that is needed for a variable or function declaration.
1157 Not used for automatic variables, and not used for function definitions.
1158 Should not be called for variables of incomplete structure type.
1160 TOP_LEVEL is nonzero if this variable has file scope.
1161 AT_END is nonzero if this is the special handling, at end of compilation,
1162 to define things that have had only tentative definitions.
1163 DONT_OUTPUT_DATA if nonzero means don't actually output the
1164 initial value (that will be done by the caller). */
1167 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1169 int top_level ATTRIBUTE_UNUSED
;
1171 int dont_output_data
;
1173 register char *name
;
1175 tree size_tree
= NULL_TREE
;
1177 enum in_section saved_in_section
;
1179 last_assemble_variable_decl
= 0;
1181 if (GET_CODE (DECL_RTL (decl
)) == REG
)
1183 /* Do output symbol info for global register variables, but do nothing
1186 if (TREE_ASM_WRITTEN (decl
))
1188 TREE_ASM_WRITTEN (decl
) = 1;
1190 /* Do no output if -fsyntax-only. */
1191 if (flag_syntax_only
)
1194 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1195 /* File-scope global variables are output here. */
1196 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1198 dbxout_symbol (decl
, 0);
1200 #ifdef SDB_DEBUGGING_INFO
1201 if (write_symbols
== SDB_DEBUG
&& top_level
1202 /* Leave initialized global vars for end of compilation;
1203 see comment in compile_file. */
1204 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1205 sdbout_symbol (decl
, 0);
1208 /* Don't output any DWARF debugging information for variables here.
1209 In the case of local variables, the information for them is output
1210 when we do our recursive traversal of the tree representation for
1211 the entire containing function. In the case of file-scope variables,
1212 we output information for all of them at the very end of compilation
1213 while we are doing our final traversal of the chain of file-scope
1219 /* Normally no need to say anything here for external references,
1220 since assemble_external is called by the language-specific code
1221 when a declaration is first seen. */
1223 if (DECL_EXTERNAL (decl
))
1226 /* Output no assembler code for a function declaration.
1227 Only definitions of functions output anything. */
1229 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1232 /* If type was incomplete when the variable was declared,
1233 see if it is complete now. */
1235 if (DECL_SIZE (decl
) == 0)
1236 layout_decl (decl
, 0);
1238 /* Still incomplete => don't allocate it; treat the tentative defn
1239 (which is what it must have been) as an `extern' reference. */
1241 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1243 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1244 DECL_SOURCE_LINE (decl
),
1245 "storage size of `%s' isn't known",
1246 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1247 TREE_ASM_WRITTEN (decl
) = 1;
1251 /* The first declaration of a variable that comes through this function
1252 decides whether it is global (in C, has external linkage)
1253 or local (in C, has internal linkage). So do nothing more
1254 if this function has already run. */
1256 if (TREE_ASM_WRITTEN (decl
))
1259 TREE_ASM_WRITTEN (decl
) = 1;
1261 /* Do no output if -fsyntax-only. */
1262 if (flag_syntax_only
)
1267 if (! dont_output_data
)
1271 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1274 /* This is better than explicit arithmetic, since it avoids overflow. */
1275 size_tree
= size_binop (CEIL_DIV_EXPR
,
1276 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
1278 size
= TREE_INT_CST_LOW (size_tree
);
1279 if (TREE_INT_CST_HIGH (size_tree
) != 0
1280 || size
!= TREE_INT_CST_LOW (size_tree
))
1282 error_with_decl (decl
, "size of variable `%s' is too large");
1287 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1289 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1290 && ! first_global_object_name
1291 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1292 || DECL_INITIAL (decl
) == error_mark_node
))
1293 && ! DECL_WEAK (decl
)
1294 && ! DECL_ONE_ONLY (decl
))
1298 STRIP_NAME_ENCODING (p
, name
);
1299 first_global_object_name
= permalloc (strlen (p
) + 1);
1300 strcpy (first_global_object_name
, p
);
1303 /* Compute the alignment of this data. */
1305 align
= DECL_ALIGN (decl
);
1307 /* In the case for initialing an array whose length isn't specified,
1308 where we have not yet been able to do the layout,
1309 figure out the proper alignment now. */
1310 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1311 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1312 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1314 /* Some object file formats have a maximum alignment which they support.
1315 In particular, a.out format supports a maximum alignment of 4. */
1316 #ifndef MAX_OFILE_ALIGNMENT
1317 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1319 if (align
> MAX_OFILE_ALIGNMENT
)
1321 warning_with_decl (decl
,
1322 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1323 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1324 align
= MAX_OFILE_ALIGNMENT
;
1327 /* On some machines, it is good to increase alignment sometimes. */
1328 #ifdef DATA_ALIGNMENT
1329 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1331 #ifdef CONSTANT_ALIGNMENT
1332 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1333 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1336 /* Reset the alignment in case we have made it tighter, so we can benefit
1337 from it in get_pointer_alignment. */
1338 DECL_ALIGN (decl
) = align
;
1340 /* Handle uninitialized definitions. */
1342 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
)
1343 /* If the target can't output uninitialized but not common global data
1344 in .bss, then we have to use .data. */
1345 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1346 && DECL_COMMON (decl
)
1348 && DECL_SECTION_NAME (decl
) == 0
1349 && ! dont_output_data
)
1351 int size
= TREE_INT_CST_LOW (size_tree
);
1354 /* Don't allocate zero bytes of common,
1355 since that means "undefined external" in the linker. */
1356 if (size
== 0) rounded
= 1;
1357 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1358 so that each uninitialized object starts on such a boundary. */
1359 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1360 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1361 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1363 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1364 if ( (DECL_ALIGN (decl
) / BITS_PER_UNIT
) > rounded
)
1366 (decl
, "requested alignment for %s is greater than implemented alignment of %d.",rounded
);
1369 #ifdef DBX_DEBUGGING_INFO
1370 /* File-scope global variables are output here. */
1371 if (write_symbols
== DBX_DEBUG
&& top_level
)
1372 dbxout_symbol (decl
, 0);
1374 #ifdef SDB_DEBUGGING_INFO
1375 if (write_symbols
== SDB_DEBUG
&& top_level
1376 /* Leave initialized global vars for end of compilation;
1377 see comment in compile_file. */
1378 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1379 sdbout_symbol (decl
, 0);
1382 /* Don't output any DWARF debugging information for variables here.
1383 In the case of local variables, the information for them is output
1384 when we do our recursive traversal of the tree representation for
1385 the entire containing function. In the case of file-scope variables,
1386 we output information for all of them at the very end of compilation
1387 while we are doing our final traversal of the chain of file-scope
1390 #if 0 /* ??? We should either delete this or add a comment describing what
1391 it was intended to do and why we shouldn't delete it. */
1392 if (flag_shared_data
)
1396 if (TREE_PUBLIC (decl
)
1397 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1398 && DECL_COMMON (decl
)
1402 #ifdef ASM_OUTPUT_SHARED_COMMON
1403 if (flag_shared_data
)
1404 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1408 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1409 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
, size
,
1412 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1413 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
1416 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1421 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1422 else if (TREE_PUBLIC (decl
))
1424 #ifdef ASM_OUTPUT_SHARED_BSS
1425 if (flag_shared_data
)
1426 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1430 #ifdef ASM_OUTPUT_ALIGNED_BSS
1431 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
1434 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1438 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1441 #ifdef ASM_OUTPUT_SHARED_LOCAL
1442 if (flag_shared_data
)
1443 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1447 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1448 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
, size
,
1451 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1452 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
1455 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1463 /* Handle initialized definitions.
1464 Also handle uninitialized global definitions if -fno-common and the
1465 target doesn't support ASM_OUTPUT_BSS. */
1467 /* First make the assembler name(s) global if appropriate. */
1468 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1470 #ifdef ASM_WEAKEN_LABEL
1471 if (DECL_WEAK (decl
))
1473 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1474 /* Remove this variable from the pending weak list so that
1475 we do not emit multiple .weak directives for it. */
1476 remove_from_pending_weak_list
1477 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1481 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1484 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
1486 tree e
= TREE_VALUE (d
);
1487 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
1488 ASM_GLOBALIZE_LABEL (asm_out_file
,
1489 XSTR (XEXP (DECL_RTL (e
), 0), 0));
1493 /* Output any data that we will need to use the address of. */
1494 if (DECL_INITIAL (decl
) == error_mark_node
)
1495 reloc
= contains_pointers_p (TREE_TYPE (decl
));
1496 else if (DECL_INITIAL (decl
))
1497 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1499 #ifdef ASM_OUTPUT_SECTION_NAME
1500 if ((flag_data_sections
!= 0
1501 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1502 || UNIQUE_SECTION_P (decl
))
1503 UNIQUE_SECTION (decl
, reloc
);
1506 /* Switch to the appropriate section. */
1507 variable_section (decl
, reloc
);
1509 /* dbxout.c needs to know this. */
1510 if (in_text_section ())
1511 DECL_IN_TEXT_SECTION (decl
) = 1;
1513 /* Record current section so we can restore it if dbxout.c clobbers it. */
1514 saved_in_section
= in_section
;
1516 /* Output the dbx info now that we have chosen the section. */
1518 #ifdef DBX_DEBUGGING_INFO
1519 /* File-scope global variables are output here. */
1520 if (write_symbols
== DBX_DEBUG
&& top_level
)
1521 dbxout_symbol (decl
, 0);
1523 #ifdef SDB_DEBUGGING_INFO
1524 if (write_symbols
== SDB_DEBUG
&& top_level
1525 /* Leave initialized global vars for end of compilation;
1526 see comment in compile_file. */
1527 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1528 sdbout_symbol (decl
, 0);
1531 /* Don't output any DWARF debugging information for variables here.
1532 In the case of local variables, the information for them is output
1533 when we do our recursive traversal of the tree representation for
1534 the entire containing function. In the case of file-scope variables,
1535 we output information for all of them at the very end of compilation
1536 while we are doing our final traversal of the chain of file-scope
1539 /* If the debugging output changed sections, reselect the section
1540 that's supposed to be selected. */
1541 if (in_section
!= saved_in_section
)
1542 variable_section (decl
, reloc
);
1544 /* Output the alignment of this data. */
1545 if (align
> BITS_PER_UNIT
)
1546 ASM_OUTPUT_ALIGN (asm_out_file
,
1547 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1549 /* Do any machine/system dependent processing of the object. */
1550 #ifdef ASM_DECLARE_OBJECT_NAME
1551 last_assemble_variable_decl
= decl
;
1552 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1554 /* Standard thing is just output label for the object. */
1555 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1556 #endif /* ASM_DECLARE_OBJECT_NAME */
1558 if (!dont_output_data
)
1560 if (DECL_INITIAL (decl
))
1561 /* Output the actual data. */
1562 output_constant (DECL_INITIAL (decl
), TREE_INT_CST_LOW (size_tree
));
1564 /* Leave space for it. */
1565 assemble_zeros (TREE_INT_CST_LOW (size_tree
));
1569 #ifdef XCOFF_DEBUGGING_INFO
1570 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1571 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1572 and `aa' hasn't been output yet, the assembler generates a stab entry with
1573 a value of zero, in addition to creating an unnecessary external entry
1574 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1576 /* File-scope global variables are output here. */
1577 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
1579 saved_in_section
= in_section
;
1581 dbxout_symbol (decl
, 0);
1583 if (in_section
!= saved_in_section
)
1584 variable_section (decl
, reloc
);
1587 /* There must be a statement after a label. */
1592 /* Return 1 if type TYPE contains any pointers. */
1595 contains_pointers_p (type
)
1598 switch (TREE_CODE (type
))
1601 case REFERENCE_TYPE
:
1602 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1603 so I'll play safe and return 1. */
1609 case QUAL_UNION_TYPE
:
1612 /* For a type that has fields, see if the fields have pointers. */
1613 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1614 if (TREE_CODE (fields
) == FIELD_DECL
1615 && contains_pointers_p (TREE_TYPE (fields
)))
1621 /* An array type contains pointers if its element type does. */
1622 return contains_pointers_p (TREE_TYPE (type
));
1629 /* Output something to declare an external symbol to the assembler.
1630 (Most assemblers don't need this, so we normally output nothing.)
1631 Do nothing if DECL is not external. */
1634 assemble_external (decl
)
1635 tree decl ATTRIBUTE_UNUSED
;
1637 #ifdef ASM_OUTPUT_EXTERNAL
1638 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
1639 && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1641 rtx rtl
= DECL_RTL (decl
);
1643 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1644 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1646 /* Some systems do require some output. */
1647 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1648 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1654 /* Similar, for calling a library function FUN. */
1657 assemble_external_libcall (fun
)
1658 rtx fun ATTRIBUTE_UNUSED
;
1660 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1661 /* Declare library function name external when first used, if nec. */
1662 if (! SYMBOL_REF_USED (fun
))
1664 SYMBOL_REF_USED (fun
) = 1;
1665 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1670 /* Declare the label NAME global. */
1673 assemble_global (name
)
1676 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1679 /* Assemble a label named NAME. */
1682 assemble_label (name
)
1685 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1688 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1689 If NAME starts with a *, the rest of NAME is output verbatim.
1690 Otherwise NAME is transformed in an implementation-defined way
1691 (usually by the addition of an underscore).
1692 Many macros in the tm file are defined to call this function. */
1695 assemble_name (file
, name
)
1699 const char *real_name
;
1702 STRIP_NAME_ENCODING (real_name
, name
);
1703 if (flag_prefix_function_name
1704 && ! bcmp (real_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
))
1705 real_name
= real_name
+ CHKR_PREFIX_SIZE
;
1707 id
= maybe_get_identifier (real_name
);
1709 TREE_SYMBOL_REFERENCED (id
) = 1;
1712 fputs (&name
[1], file
);
1714 ASM_OUTPUT_LABELREF (file
, name
);
1717 /* Allocate SIZE bytes writable static space with a gensym name
1718 and return an RTX to refer to its address. */
1721 assemble_static_space (size
)
1729 if (flag_shared_data
)
1733 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1736 namestring
= (char *) obstack_alloc (saveable_obstack
,
1738 strcpy (namestring
, name
);
1740 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1742 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1743 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1746 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1747 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1750 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1751 so that each uninitialized object starts on such a boundary. */
1752 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1753 int rounded ATTRIBUTE_UNUSED
1754 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1755 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1756 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1757 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1764 /* Assemble the static constant template for function entry trampolines.
1765 This is done at most once per compilation.
1766 Returns an RTX for the address of the template. */
1768 #ifdef TRAMPOLINE_TEMPLATE
1770 assemble_trampoline_template ()
1776 /* By default, put trampoline templates in read-only data section. */
1778 #ifdef TRAMPOLINE_SECTION
1779 TRAMPOLINE_SECTION ();
1781 readonly_data_section ();
1784 /* Write the assembler code to define one. */
1785 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1787 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1789 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1790 TRAMPOLINE_TEMPLATE (asm_out_file
);
1792 /* Record the rtl to refer to it. */
1793 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1795 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1796 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1800 /* Assemble the integer constant X into an object of SIZE bytes.
1801 X must be either a CONST_INT or CONST_DOUBLE.
1803 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1804 non-zero, abort if we can't output the constant. */
1807 assemble_integer (x
, size
, force
)
1812 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1813 ASM_OUTPUT... macros. */
1817 #ifdef ASM_OUTPUT_CHAR
1819 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1823 #ifdef ASM_OUTPUT_SHORT
1825 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1829 #ifdef ASM_OUTPUT_INT
1831 ASM_OUTPUT_INT (asm_out_file
, x
);
1835 #ifdef ASM_OUTPUT_DOUBLE_INT
1837 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1841 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1843 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1848 /* If we couldn't do it that way, there are two other possibilities: First,
1849 if the machine can output an explicit byte and this is a 1 byte constant,
1850 we can use ASM_OUTPUT_BYTE. */
1852 #ifdef ASM_OUTPUT_BYTE
1853 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1855 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1860 /* Finally, if SIZE is larger than a single word, try to output the constant
1861 one word at a time. */
1863 if (size
> UNITS_PER_WORD
)
1866 enum machine_mode mode
1867 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1870 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1872 word
= operand_subword (x
, i
, 0, mode
);
1877 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1881 if (i
== size
/ UNITS_PER_WORD
)
1883 /* If we output at least one word and then could not finish,
1884 there is no valid way to continue. */
1895 /* Assemble the floating-point constant D into an object of size MODE. */
1898 assemble_real (d
, mode
)
1900 enum machine_mode mode
;
1902 jmp_buf output_constant_handler
;
1904 if (setjmp (output_constant_handler
))
1906 error ("floating point trap outputting a constant");
1907 #ifdef REAL_IS_NOT_DOUBLE
1908 bzero ((char *) &d
, sizeof d
);
1915 set_float_handler (output_constant_handler
);
1919 #ifdef ASM_OUTPUT_BYTE_FLOAT
1921 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, d
);
1924 #ifdef ASM_OUTPUT_SHORT_FLOAT
1926 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, d
);
1929 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1931 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, d
);
1934 #ifdef ASM_OUTPUT_FLOAT
1936 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1940 #ifdef ASM_OUTPUT_DOUBLE
1942 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1946 #ifdef ASM_OUTPUT_LONG_DOUBLE
1949 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1957 set_float_handler (NULL_PTR
);
1960 /* Here we combine duplicate floating constants to make
1961 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1963 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1964 They are chained through the CONST_DOUBLE_CHAIN.
1965 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1966 In that case, CONST_DOUBLE_MEM is either a MEM,
1967 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1969 (CONST_DOUBLE_MEM is used only for top-level functions.
1970 See force_const_mem for explanation.) */
1972 static rtx const_double_chain
;
1974 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1975 For an integer, I0 is the low-order word and I1 is the high-order word.
1976 For a real number, I0 is the word with the low address
1977 and I1 is the word with the high address. */
1980 immed_double_const (i0
, i1
, mode
)
1981 HOST_WIDE_INT i0
, i1
;
1982 enum machine_mode mode
;
1986 if (GET_MODE_CLASS (mode
) == MODE_INT
1987 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
1989 /* We clear out all bits that don't belong in MODE, unless they and our
1990 sign bit are all one. So we get either a reasonable negative value
1991 or a reasonable unsigned value for this mode. */
1992 int width
= GET_MODE_BITSIZE (mode
);
1993 if (width
< HOST_BITS_PER_WIDE_INT
1994 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
1995 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
1996 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
1997 else if (width
== HOST_BITS_PER_WIDE_INT
1998 && ! (i1
== ~0 && i0
< 0))
2000 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
2001 /* We cannot represent this value as a constant. */
2004 /* If this would be an entire word for the target, but is not for
2005 the host, then sign-extend on the host so that the number will look
2006 the same way on the host that it would on the target.
2008 For example, when building a 64 bit alpha hosted 32 bit sparc
2009 targeted compiler, then we want the 32 bit unsigned value -1 to be
2010 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2011 The later confuses the sparc backend. */
2013 if (BITS_PER_WORD
< HOST_BITS_PER_WIDE_INT
&& BITS_PER_WORD
== width
2014 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
2015 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
2017 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2019 ??? Strictly speaking, this is wrong if we create a CONST_INT
2020 for a large unsigned constant with the size of MODE being
2021 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2022 wider mode. In that case we will mis-interpret it as a negative
2025 Unfortunately, the only alternative is to make a CONST_DOUBLE
2026 for any constant in any mode if it is an unsigned constant larger
2027 than the maximum signed integer in an int on the host. However,
2028 doing this will break everyone that always expects to see a CONST_INT
2029 for SImode and smaller.
2031 We have always been making CONST_INTs in this case, so nothing new
2034 if (width
<= HOST_BITS_PER_WIDE_INT
)
2035 i1
= (i0
< 0) ? ~(HOST_WIDE_INT
) 0 : 0;
2037 /* If this integer fits in one word, return a CONST_INT. */
2038 if ((i1
== 0 && i0
>= 0)
2039 || (i1
== ~0 && i0
< 0))
2040 return GEN_INT (i0
);
2042 /* We use VOIDmode for integers. */
2046 /* Search the chain for an existing CONST_DOUBLE with the right value.
2047 If one is found, return it. */
2049 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2050 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
2051 && GET_MODE (r
) == mode
)
2054 /* No; make a new one and add it to the chain.
2056 We may be called by an optimizer which may be discarding any memory
2057 allocated during its processing (such as combine and loop). However,
2058 we will be leaving this constant on the chain, so we cannot tolerate
2059 freed memory. So switch to saveable_obstack for this allocation
2060 and then switch back if we were in current_obstack. */
2062 push_obstacks_nochange ();
2063 rtl_in_saveable_obstack ();
2064 r
= gen_rtx_CONST_DOUBLE (mode
, NULL_RTX
, i0
, i1
);
2067 /* Don't touch const_double_chain in nested function; see force_const_mem.
2068 Also, don't touch it if not inside any function. */
2069 if (outer_function_chain
== 0 && current_function_decl
!= 0)
2071 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2072 const_double_chain
= r
;
2075 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2076 Actual use of mem-slot is only through force_const_mem. */
2078 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2083 /* Return a CONST_DOUBLE for a specified `double' value
2084 and machine mode. */
2087 immed_real_const_1 (d
, mode
)
2089 enum machine_mode mode
;
2091 union real_extract u
;
2094 /* Get the desired `double' value as a sequence of ints
2095 since that is how they are stored in a CONST_DOUBLE. */
2099 /* Detect special cases. */
2101 if (REAL_VALUES_IDENTICAL (dconst0
, d
))
2102 return CONST0_RTX (mode
);
2103 /* Check for NaN first, because some ports (specifically the i386) do not
2104 emit correct ieee-fp code by default, and thus will generate a core
2105 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2106 does a floating point comparison. */
2107 else if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
2108 return CONST1_RTX (mode
);
2110 if (sizeof u
== sizeof (HOST_WIDE_INT
))
2111 return immed_double_const (u
.i
[0], 0, mode
);
2112 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
2113 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
2115 /* The rest of this function handles the case where
2116 a float value requires more than 2 ints of space.
2117 It will be deleted as dead code on machines that don't need it. */
2119 /* Search the chain for an existing CONST_DOUBLE with the right value.
2120 If one is found, return it. */
2122 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2123 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
2124 && GET_MODE (r
) == mode
)
2127 /* No; make a new one and add it to the chain.
2129 We may be called by an optimizer which may be discarding any memory
2130 allocated during its processing (such as combine and loop). However,
2131 we will be leaving this constant on the chain, so we cannot tolerate
2132 freed memory. So switch to saveable_obstack for this allocation
2133 and then switch back if we were in current_obstack. */
2135 push_obstacks_nochange ();
2136 rtl_in_saveable_obstack ();
2137 r
= rtx_alloc (CONST_DOUBLE
);
2139 bcopy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (r
), sizeof u
);
2142 /* Don't touch const_double_chain in nested function; see force_const_mem.
2143 Also, don't touch it if not inside any function. */
2144 if (outer_function_chain
== 0 && current_function_decl
!= 0)
2146 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2147 const_double_chain
= r
;
2150 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2151 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2152 is only through force_const_mem. */
2154 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2159 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2160 which must be a REAL_CST tree node. */
2163 immed_real_const (exp
)
2166 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
2169 /* At the end of a function, forget the memory-constants
2170 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2171 Also clear out real_constant_chain and clear out all the chain-pointers. */
2174 clear_const_double_mem ()
2176 register rtx r
, next
;
2178 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2179 See force_const_mem for explanation. */
2180 if (outer_function_chain
!= 0)
2183 for (r
= const_double_chain
; r
; r
= next
)
2185 next
= CONST_DOUBLE_CHAIN (r
);
2186 CONST_DOUBLE_CHAIN (r
) = 0;
2187 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
2189 const_double_chain
= 0;
2192 /* Given an expression EXP with a constant value,
2193 reduce it to the sum of an assembler symbol and an integer.
2194 Store them both in the structure *VALUE.
2195 Abort if EXP does not reduce. */
2200 HOST_WIDE_INT offset
;
2204 decode_addr_const (exp
, value
)
2206 struct addr_const
*value
;
2208 register tree target
= TREE_OPERAND (exp
, 0);
2209 register int offset
= 0;
2214 if (TREE_CODE (target
) == COMPONENT_REF
2215 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
2218 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
2219 target
= TREE_OPERAND (target
, 0);
2221 else if (TREE_CODE (target
) == ARRAY_REF
)
2223 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
2224 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
2226 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
2227 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
2229 target
= TREE_OPERAND (target
, 0);
2235 switch (TREE_CODE (target
))
2239 x
= DECL_RTL (target
);
2243 x
= gen_rtx_MEM (FUNCTION_MODE
,
2244 gen_rtx_LABEL_REF (VOIDmode
,
2245 label_rtx (TREE_OPERAND (exp
, 0))));
2253 x
= TREE_CST_RTL (target
);
2260 if (GET_CODE (x
) != MEM
)
2265 value
->offset
= offset
;
2268 /* Uniquize all constants that appear in memory.
2269 Each constant in memory thus far output is recorded
2270 in `const_hash_table' with a `struct constant_descriptor'
2271 that contains a polish representation of the value of
2274 We cannot store the trees in the hash table
2275 because the trees may be temporary. */
2277 struct constant_descriptor
2279 struct constant_descriptor
*next
;
2285 #define MAX_HASH_TABLE 1009
2286 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2288 /* Compute a hash code for a constant expression. */
2295 register int len
, hi
, i
;
2296 register enum tree_code code
= TREE_CODE (exp
);
2298 /* Either set P and LEN to the address and len of something to hash and
2299 exit the switch or return a value. */
2304 p
= (char *) &TREE_INT_CST_LOW (exp
);
2305 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2309 p
= (char *) &TREE_REAL_CST (exp
);
2310 len
= sizeof TREE_REAL_CST (exp
);
2314 p
= TREE_STRING_POINTER (exp
);
2315 len
= TREE_STRING_LENGTH (exp
);
2319 return (const_hash (TREE_REALPART (exp
)) * 5
2320 + const_hash (TREE_IMAGPART (exp
)));
2323 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2325 len
= int_size_in_bytes (TREE_TYPE (exp
));
2326 p
= (char *) alloca (len
);
2327 get_set_constructor_bytes (exp
, (unsigned char *) p
, len
);
2334 /* For record type, include the type in the hashing.
2335 We do not do so for array types
2336 because (1) the sizes of the elements are sufficient
2337 and (2) distinct array types can have the same constructor.
2338 Instead, we include the array size because the constructor could
2340 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2341 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2344 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2345 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2347 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2348 if (TREE_VALUE (link
))
2350 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2357 struct addr_const value
;
2359 decode_addr_const (exp
, &value
);
2360 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2362 /* Don't hash the address of the SYMBOL_REF;
2363 only use the offset and the symbol name. */
2365 p
= XSTR (value
.base
, 0);
2366 for (i
= 0; p
[i
] != 0; i
++)
2367 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2369 else if (GET_CODE (value
.base
) == LABEL_REF
)
2370 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2374 hi
&= (1 << HASHBITS
) - 1;
2375 hi
%= MAX_HASH_TABLE
;
2381 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2382 + const_hash (TREE_OPERAND (exp
, 1)));
2386 case NON_LVALUE_EXPR
:
2387 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2393 /* Compute hashing function */
2395 for (i
= 0; i
< len
; i
++)
2396 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2398 hi
&= (1 << HASHBITS
) - 1;
2399 hi
%= MAX_HASH_TABLE
;
2403 /* Compare a constant expression EXP with a constant-descriptor DESC.
2404 Return 1 if DESC describes a constant with the same value as EXP. */
2407 compare_constant (exp
, desc
)
2409 struct constant_descriptor
*desc
;
2411 return 0 != compare_constant_1 (exp
, desc
->contents
);
2414 /* Compare constant expression EXP with a substring P of a constant descriptor.
2415 If they match, return a pointer to the end of the substring matched.
2416 If they do not match, return 0.
2418 Since descriptors are written in polish prefix notation,
2419 this function can be used recursively to test one operand of EXP
2420 against a subdescriptor, and if it succeeds it returns the
2421 address of the subdescriptor for the next operand. */
2424 compare_constant_1 (exp
, p
)
2428 register char *strp
;
2430 register enum tree_code code
= TREE_CODE (exp
);
2432 if (code
!= (enum tree_code
) *p
++)
2435 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2436 switch, or return the result of the comparison. */
2441 /* Integer constants are the same only if the same width of type. */
2442 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2445 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2446 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2450 /* Real constants are the same only if the same width of type. */
2451 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2454 strp
= (char *) &TREE_REAL_CST (exp
);
2455 len
= sizeof TREE_REAL_CST (exp
);
2459 if (flag_writable_strings
)
2462 if (*p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2465 strp
= TREE_STRING_POINTER (exp
);
2466 len
= TREE_STRING_LENGTH (exp
);
2467 if (bcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2468 sizeof TREE_STRING_LENGTH (exp
)))
2471 p
+= sizeof TREE_STRING_LENGTH (exp
);
2475 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2479 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2482 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2484 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2486 strp
= (char *) alloca (len
);
2487 get_set_constructor_bytes (exp
, (unsigned char *) strp
, len
);
2488 if (bcmp ((char *) &xlen
, p
, sizeof xlen
))
2497 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2499 int have_purpose
= 0;
2501 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2502 if (TREE_PURPOSE (link
))
2505 if (bcmp ((char *) &length
, p
, sizeof length
))
2510 /* For record constructors, insist that the types match.
2511 For arrays, just verify both constructors are for arrays.
2512 Then insist that either both or none have any TREE_PURPOSE
2514 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2515 type
= TREE_TYPE (exp
);
2519 if (bcmp ((char *) &type
, p
, sizeof type
))
2524 if (bcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2527 p
+= sizeof have_purpose
;
2529 /* For arrays, insist that the size in bytes match. */
2530 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2532 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2534 if (bcmp ((char *) &size
, p
, sizeof size
))
2540 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2542 if (TREE_VALUE (link
))
2544 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2551 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2557 if (TREE_PURPOSE (link
)
2558 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2560 if (bcmp ((char *) &TREE_PURPOSE (link
), p
,
2561 sizeof TREE_PURPOSE (link
)))
2564 p
+= sizeof TREE_PURPOSE (link
);
2566 else if (TREE_PURPOSE (link
))
2568 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2571 else if (have_purpose
)
2575 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2587 struct addr_const value
;
2589 decode_addr_const (exp
, &value
);
2590 strp
= (char *) &value
.offset
;
2591 len
= sizeof value
.offset
;
2592 /* Compare the offset. */
2594 if (*p
++ != *strp
++)
2597 /* Compare symbol name. */
2598 strp
= XSTR (value
.base
, 0);
2599 len
= strlen (strp
) + 1;
2606 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2610 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2614 case NON_LVALUE_EXPR
:
2615 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2621 /* Compare constant contents. */
2623 if (*p
++ != *strp
++)
2629 /* Construct a constant descriptor for the expression EXP.
2630 It is up to the caller to enter the descriptor in the hash table. */
2632 static struct constant_descriptor
*
2633 record_constant (exp
)
2636 struct constant_descriptor
*next
= 0;
2639 /* Make a struct constant_descriptor. The first two pointers will
2640 be filled in later. Here we just leave space for them. */
2642 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2643 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2644 record_constant_1 (exp
);
2645 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2648 /* Add a description of constant expression EXP
2649 to the object growing in `permanent_obstack'.
2650 No need to return its address; the caller will get that
2651 from the obstack when the object is complete. */
2654 record_constant_1 (exp
)
2657 register char *strp
;
2659 register enum tree_code code
= TREE_CODE (exp
);
2661 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2666 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2667 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2668 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2672 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2673 strp
= (char *) &TREE_REAL_CST (exp
);
2674 len
= sizeof TREE_REAL_CST (exp
);
2678 if (flag_writable_strings
)
2681 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2682 strp
= TREE_STRING_POINTER (exp
);
2683 len
= TREE_STRING_LENGTH (exp
);
2684 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2685 sizeof TREE_STRING_LENGTH (exp
));
2689 record_constant_1 (TREE_REALPART (exp
));
2690 record_constant_1 (TREE_IMAGPART (exp
));
2694 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2696 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2697 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2698 obstack_blank (&permanent_obstack
, nbytes
);
2699 get_set_constructor_bytes
2700 (exp
, (unsigned char *) permanent_obstack
.next_free
-nbytes
,
2707 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2709 int have_purpose
= 0;
2711 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2712 if (TREE_PURPOSE (link
))
2715 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2717 /* For record constructors, insist that the types match.
2718 For arrays, just verify both constructors are for arrays.
2719 Then insist that either both or none have any TREE_PURPOSE
2721 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2722 type
= TREE_TYPE (exp
);
2725 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2726 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2727 sizeof have_purpose
);
2729 /* For arrays, insist that the size in bytes match. */
2730 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2732 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2733 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2736 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2738 if (TREE_VALUE (link
))
2739 record_constant_1 (TREE_VALUE (link
));
2744 obstack_grow (&permanent_obstack
,
2745 (char *) &zero
, sizeof zero
);
2748 if (TREE_PURPOSE (link
)
2749 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2750 obstack_grow (&permanent_obstack
,
2751 (char *) &TREE_PURPOSE (link
),
2752 sizeof TREE_PURPOSE (link
));
2753 else if (TREE_PURPOSE (link
))
2754 record_constant_1 (TREE_PURPOSE (link
));
2755 else if (have_purpose
)
2759 obstack_grow (&permanent_obstack
,
2760 (char *) &zero
, sizeof zero
);
2768 struct addr_const value
;
2770 decode_addr_const (exp
, &value
);
2771 /* Record the offset. */
2772 obstack_grow (&permanent_obstack
,
2773 (char *) &value
.offset
, sizeof value
.offset
);
2774 /* Record the symbol name. */
2775 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2776 strlen (XSTR (value
.base
, 0)) + 1);
2783 record_constant_1 (TREE_OPERAND (exp
, 0));
2784 record_constant_1 (TREE_OPERAND (exp
, 1));
2789 case NON_LVALUE_EXPR
:
2790 record_constant_1 (TREE_OPERAND (exp
, 0));
2797 /* Record constant contents. */
2798 obstack_grow (&permanent_obstack
, strp
, len
);
2801 /* Record a list of constant expressions that were passed to
2802 output_constant_def but that could not be output right away. */
2804 struct deferred_constant
2806 struct deferred_constant
*next
;
2812 static struct deferred_constant
*deferred_constants
;
2814 /* Another list of constants which should be output after the
2816 static struct deferred_constant
*after_function_constants
;
2818 /* Nonzero means defer output of addressed subconstants
2819 (i.e., those for which output_constant_def is called.) */
2820 static int defer_addressed_constants_flag
;
2822 /* Start deferring output of subconstants. */
2825 defer_addressed_constants ()
2827 defer_addressed_constants_flag
++;
2830 /* Stop deferring output of subconstants,
2831 and output now all those that have been deferred. */
2834 output_deferred_addressed_constants ()
2836 struct deferred_constant
*p
, *next
;
2838 defer_addressed_constants_flag
--;
2840 if (defer_addressed_constants_flag
> 0)
2843 for (p
= deferred_constants
; p
; p
= next
)
2845 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2850 deferred_constants
= 0;
2853 /* Output any constants which should appear after a function. */
2856 output_after_function_constants ()
2858 struct deferred_constant
*p
, *next
;
2860 for (p
= after_function_constants
; p
; p
= next
)
2862 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2867 after_function_constants
= 0;
2870 /* Make a copy of the whole tree structure for a constant.
2871 This handles the same types of nodes that compare_constant
2872 and record_constant handle. */
2878 switch (TREE_CODE (exp
))
2881 /* For ADDR_EXPR, we do not want to copy the decl whose address
2882 is requested. We do want to copy constants though. */
2883 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2884 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2885 copy_constant (TREE_OPERAND (exp
, 0)));
2887 return copy_node (exp
);
2892 return copy_node (exp
);
2895 return build_complex (TREE_TYPE (exp
),
2896 copy_constant (TREE_REALPART (exp
)),
2897 copy_constant (TREE_IMAGPART (exp
)));
2901 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2902 copy_constant (TREE_OPERAND (exp
, 0)),
2903 copy_constant (TREE_OPERAND (exp
, 1)));
2907 case NON_LVALUE_EXPR
:
2908 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2909 copy_constant (TREE_OPERAND (exp
, 0)));
2913 tree copy
= copy_node (exp
);
2914 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2917 CONSTRUCTOR_ELTS (copy
) = list
;
2918 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2919 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2920 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2921 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2922 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
2932 /* Return an rtx representing a reference to constant data in memory
2933 for the constant expression EXP.
2935 If assembler code for such a constant has already been output,
2936 return an rtx to refer to it.
2937 Otherwise, output such a constant in memory (or defer it for later)
2938 and generate an rtx for it.
2940 The TREE_CST_RTL of EXP is set up to point to that rtx.
2941 The const_hash_table records which constants already have label strings. */
2944 output_constant_def (exp
)
2948 register struct constant_descriptor
*desc
;
2954 if (TREE_CST_RTL (exp
))
2955 return TREE_CST_RTL (exp
);
2957 /* Make sure any other constants whose addresses appear in EXP
2958 are assigned label numbers. */
2960 reloc
= output_addressed_constants (exp
);
2962 /* Compute hash code of EXP. Search the descriptors for that hash code
2963 to see if any of them describes EXP. If yes, the descriptor records
2964 the label number already assigned. */
2966 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
2968 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
2969 if (compare_constant (exp
, desc
))
2971 found
= desc
->label
;
2977 /* No constant equal to EXP is known to have been output.
2978 Make a constant descriptor to enter EXP in the hash table.
2979 Assign the label number and record it in the descriptor for
2980 future calls to this function to find. */
2982 /* Create a string containing the label name, in LABEL. */
2983 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2985 desc
= record_constant (exp
);
2986 desc
->next
= const_hash_table
[hash
];
2988 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
2989 const_hash_table
[hash
] = desc
;
2993 /* Create a string containing the label name, in LABEL. */
2994 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2997 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2999 push_obstacks_nochange ();
3000 if (TREE_PERMANENT (exp
))
3001 end_temporary_allocation ();
3003 def
= gen_rtx_SYMBOL_REF (Pmode
, desc
->label
);
3006 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), def
);
3007 RTX_UNCHANGING_P (TREE_CST_RTL (exp
)) = 1;
3008 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
)))
3009 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp
), 1);
3013 /* Optionally set flags or add text to the name to record information
3014 such as that it is a function name. If the name is changed, the macro
3015 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3016 #ifdef ENCODE_SECTION_INFO
3017 ENCODE_SECTION_INFO (exp
);
3020 /* If this is the first time we've seen this particular constant,
3021 output it (or defer its output for later). */
3024 int after_function
= 0;
3026 #ifdef CONSTANT_AFTER_FUNCTION_P
3027 if (current_function_decl
!= 0
3028 && CONSTANT_AFTER_FUNCTION_P (exp
))
3032 if (defer_addressed_constants_flag
|| after_function
)
3034 struct deferred_constant
*p
;
3035 p
= (struct deferred_constant
*) xmalloc (sizeof (struct deferred_constant
));
3037 push_obstacks_nochange ();
3038 suspend_momentary ();
3039 p
->exp
= copy_constant (exp
);
3042 p
->labelno
= const_labelno
++;
3045 p
->next
= after_function_constants
;
3046 after_function_constants
= p
;
3050 p
->next
= deferred_constants
;
3051 deferred_constants
= p
;
3056 /* Do no output if -fsyntax-only. */
3057 if (! flag_syntax_only
)
3058 output_constant_def_contents (exp
, reloc
, const_labelno
);
3063 return TREE_CST_RTL (exp
);
3066 /* Now output assembler code to define the label for EXP,
3067 and follow it with the data of EXP. */
3070 output_constant_def_contents (exp
, reloc
, labelno
)
3077 if (IN_NAMED_SECTION (exp
))
3078 named_section (exp
, NULL
, reloc
);
3081 /* First switch to text section, except for writable strings. */
3082 #ifdef SELECT_SECTION
3083 SELECT_SECTION (exp
, reloc
);
3085 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
3086 || (flag_pic
&& reloc
))
3089 readonly_data_section ();
3093 /* Align the location counter as required by EXP's data type. */
3094 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3095 #ifdef CONSTANT_ALIGNMENT
3096 align
= CONSTANT_ALIGNMENT (exp
, align
);
3099 if (align
> BITS_PER_UNIT
)
3100 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3102 /* Output the label itself. */
3103 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3105 /* Output the value of EXP. */
3106 output_constant (exp
,
3107 (TREE_CODE (exp
) == STRING_CST
3108 ? TREE_STRING_LENGTH (exp
)
3109 : int_size_in_bytes (TREE_TYPE (exp
))));
3113 /* Similar hash facility for making memory-constants
3114 from constant rtl-expressions. It is used on RISC machines
3115 where immediate integer arguments and constant addresses are restricted
3116 so that such constants must be stored in memory.
3118 This pool of constants is reinitialized for each function
3119 so each function gets its own constants-pool that comes right before it.
3121 All structures allocated here are discarded when functions are saved for
3122 inlining, so they do not need to be allocated permanently. */
3124 #define MAX_RTX_HASH_TABLE 61
3125 static struct constant_descriptor
**const_rtx_hash_table
;
3127 /* Structure to represent sufficient information about a constant so that
3128 it can be output when the constant pool is output, so that function
3129 integration can be done, and to simplify handling on machines that reference
3130 constant pool as base+displacement. */
3132 struct pool_constant
3134 struct constant_descriptor
*desc
;
3135 struct pool_constant
*next
;
3136 enum machine_mode mode
;
3144 /* Pointers to first and last constant in pool. */
3146 static struct pool_constant
*first_pool
, *last_pool
;
3148 /* Current offset in constant pool (does not include any machine-specific
3151 static int pool_offset
;
3153 /* Structure used to maintain hash table mapping symbols used to their
3154 corresponding constants. */
3159 struct pool_constant
*pool
;
3160 struct pool_sym
*next
;
3163 static struct pool_sym
**const_rtx_sym_hash_table
;
3165 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3166 The argument is XSTR (... , 0) */
3168 #define SYMHASH(LABEL) \
3169 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3171 /* Initialize constant pool hashing for next function. */
3174 init_const_rtx_hash_table ()
3176 const_rtx_hash_table
3177 = ((struct constant_descriptor
**)
3178 oballoc (MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*)));
3179 const_rtx_sym_hash_table
3180 = ((struct pool_sym
**)
3181 oballoc (MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*)));
3182 bzero ((char *) const_rtx_hash_table
,
3183 MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*));
3184 bzero ((char *) const_rtx_sym_hash_table
,
3185 MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*));
3187 first_pool
= last_pool
= 0;
3191 /* Save and restore status for a nested function. */
3194 save_varasm_status (p
, context
)
3198 p
->const_rtx_hash_table
= const_rtx_hash_table
;
3199 p
->const_rtx_sym_hash_table
= const_rtx_sym_hash_table
;
3200 p
->first_pool
= first_pool
;
3201 p
->last_pool
= last_pool
;
3202 p
->pool_offset
= pool_offset
;
3203 p
->const_double_chain
= const_double_chain
;
3205 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3206 if (context
== NULL_TREE
)
3207 const_double_chain
= 0;
3211 restore_varasm_status (p
)
3214 const_rtx_hash_table
= p
->const_rtx_hash_table
;
3215 const_rtx_sym_hash_table
= p
->const_rtx_sym_hash_table
;
3216 first_pool
= p
->first_pool
;
3217 last_pool
= p
->last_pool
;
3218 pool_offset
= p
->pool_offset
;
3219 const_double_chain
= p
->const_double_chain
;
3222 enum kind
{ RTX_DOUBLE
, RTX_INT
};
3226 #ifdef ONLY_INT_FIELDS
3227 unsigned int kind
: 16;
3228 unsigned int mode
: 16;
3230 enum kind kind
: 16;
3231 enum machine_mode mode
: 16;
3234 union real_extract du
;
3235 struct addr_const addr
;
3236 struct {HOST_WIDE_INT high
, low
;} di
;
3240 /* Express an rtx for a constant integer (perhaps symbolic)
3241 as the sum of a symbol or label plus an explicit integer.
3242 They are stored into VALUE. */
3245 decode_rtx_const (mode
, x
, value
)
3246 enum machine_mode mode
;
3248 struct rtx_const
*value
;
3250 /* Clear the whole structure, including any gaps. */
3253 int *p
= (int *) value
;
3254 int *end
= (int *) (value
+ 1);
3259 value
->kind
= RTX_INT
; /* Most usual kind. */
3262 switch (GET_CODE (x
))
3265 value
->kind
= RTX_DOUBLE
;
3266 if (GET_MODE (x
) != VOIDmode
)
3268 value
->mode
= GET_MODE (x
);
3269 bcopy ((char *) &CONST_DOUBLE_LOW (x
),
3270 (char *) &value
->un
.du
, sizeof value
->un
.du
);
3274 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3275 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3280 value
->un
.addr
.offset
= INTVAL (x
);
3286 value
->un
.addr
.base
= x
;
3291 if (GET_CODE (x
) == PLUS
)
3293 value
->un
.addr
.base
= XEXP (x
, 0);
3294 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3296 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3298 else if (GET_CODE (x
) == MINUS
)
3300 value
->un
.addr
.base
= XEXP (x
, 0);
3301 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3303 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3313 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3314 switch (GET_CODE (value
->un
.addr
.base
))
3318 /* Use the string's address, not the SYMBOL_REF's address,
3319 for the sake of addresses of library routines.
3320 For a LABEL_REF, compare labels. */
3321 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3328 /* Given a MINUS expression, simplify it if both sides
3329 include the same symbol. */
3332 simplify_subtraction (x
)
3335 struct rtx_const val0
, val1
;
3337 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3338 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3340 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3341 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3345 /* Compute a hash code for a constant RTL expression. */
3348 const_hash_rtx (mode
, x
)
3349 enum machine_mode mode
;
3355 struct rtx_const value
;
3356 decode_rtx_const (mode
, x
, &value
);
3358 /* Compute hashing function */
3360 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3361 hi
+= ((int *) &value
)[i
];
3363 hi
&= (1 << HASHBITS
) - 1;
3364 hi
%= MAX_RTX_HASH_TABLE
;
3368 /* Compare a constant rtl object X with a constant-descriptor DESC.
3369 Return 1 if DESC describes a constant with the same value as X. */
3372 compare_constant_rtx (mode
, x
, desc
)
3373 enum machine_mode mode
;
3375 struct constant_descriptor
*desc
;
3377 register int *p
= (int *) desc
->contents
;
3380 struct rtx_const value
;
3382 decode_rtx_const (mode
, x
, &value
);
3383 strp
= (int *) &value
;
3384 len
= sizeof value
/ sizeof (int);
3386 /* Compare constant contents. */
3388 if (*p
++ != *strp
++)
3394 /* Construct a constant descriptor for the rtl-expression X.
3395 It is up to the caller to enter the descriptor in the hash table. */
3397 static struct constant_descriptor
*
3398 record_constant_rtx (mode
, x
)
3399 enum machine_mode mode
;
3402 struct constant_descriptor
*ptr
;
3404 struct rtx_const value
;
3406 decode_rtx_const (mode
, x
, &value
);
3408 /* Put these things in the saveable obstack so we can ensure it won't
3409 be freed if we are called from combine or some other phase that discards
3410 memory allocated from function_obstack (current_obstack). */
3411 obstack_grow (saveable_obstack
, &ptr
, sizeof ptr
);
3412 obstack_grow (saveable_obstack
, &label
, sizeof label
);
3414 /* Record constant contents. */
3415 obstack_grow (saveable_obstack
, &value
, sizeof value
);
3417 return (struct constant_descriptor
*) obstack_finish (saveable_obstack
);
3420 /* Given a constant rtx X, make (or find) a memory constant for its value
3421 and return a MEM rtx to refer to it in memory. */
3424 force_const_mem (mode
, x
)
3425 enum machine_mode mode
;
3429 register struct constant_descriptor
*desc
;
3434 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3435 (this will always be true for floating CONST_DOUBLEs that have been
3436 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3437 use the previous copy. Otherwise, make a new one. Note that in
3438 the unlikely event that this same CONST_DOUBLE is used in two different
3439 modes in an alternating fashion, we will allocate a lot of different
3440 memory locations, but this should be extremely rare. */
3442 /* Don't use CONST_DOUBLE_MEM in a nested function.
3443 Nested functions have their own constant pools,
3444 so they can't share the same values in CONST_DOUBLE_MEM
3445 with the containing function. */
3446 if (outer_function_chain
== 0)
3447 if (GET_CODE (x
) == CONST_DOUBLE
3448 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
3449 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
3450 return CONST_DOUBLE_MEM (x
);
3452 /* Compute hash code of X. Search the descriptors for that hash code
3453 to see if any of them describes X. If yes, the descriptor records
3454 the label number already assigned. */
3456 hash
= const_hash_rtx (mode
, x
);
3458 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3459 if (compare_constant_rtx (mode
, x
, desc
))
3461 found
= desc
->label
;
3467 register struct pool_constant
*pool
;
3468 register struct pool_sym
*sym
;
3471 /* No constant equal to X is known to have been output.
3472 Make a constant descriptor to enter X in the hash table.
3473 Assign the label number and record it in the descriptor for
3474 future calls to this function to find. */
3476 desc
= record_constant_rtx (mode
, x
);
3477 desc
->next
= const_rtx_hash_table
[hash
];
3478 const_rtx_hash_table
[hash
] = desc
;
3480 /* Align the location counter as required by EXP's data type. */
3481 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
3482 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
3483 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
3484 #ifdef CONSTANT_ALIGNMENT
3485 align
= CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode
, 0), x
),
3486 align
* BITS_PER_UNIT
) / BITS_PER_UNIT
;
3489 pool_offset
+= align
- 1;
3490 pool_offset
&= ~ (align
- 1);
3492 /* If RTL is not being placed into the saveable obstack, make a
3493 copy of X that is in the saveable obstack in case we are
3494 being called from combine or some other phase that discards
3495 memory it allocates. We used to only do this if it is a
3496 CONST; however, reload can allocate a CONST_INT when
3497 eliminating registers. */
3498 if (rtl_obstack
!= saveable_obstack
3499 && (GET_CODE (x
) == CONST
|| GET_CODE (x
) == CONST_INT
))
3501 push_obstacks_nochange ();
3502 rtl_in_saveable_obstack ();
3504 if (GET_CODE (x
) == CONST
)
3505 x
= gen_rtx_CONST (GET_MODE (x
),
3506 gen_rtx_PLUS (GET_MODE (x
),
3507 XEXP (XEXP (x
, 0), 0),
3508 XEXP (XEXP (x
, 0), 1)));
3510 x
= GEN_INT (INTVAL (x
));
3515 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3517 pool
= (struct pool_constant
*) savealloc (sizeof (struct pool_constant
));
3521 pool
->labelno
= const_labelno
;
3522 pool
->align
= align
;
3523 pool
->offset
= pool_offset
;
3530 last_pool
->next
= pool
;
3533 pool_offset
+= GET_MODE_SIZE (mode
);
3535 /* Create a string containing the label name, in LABEL. */
3536 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3541 = (char *) obstack_copy0 (saveable_obstack
, label
, strlen (label
));
3543 /* Add label to symbol hash table. */
3544 hash
= SYMHASH (found
);
3545 sym
= (struct pool_sym
*) savealloc (sizeof (struct pool_sym
));
3548 sym
->next
= const_rtx_sym_hash_table
[hash
];
3549 const_rtx_sym_hash_table
[hash
] = sym
;
3552 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3554 def
= gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, found
));
3556 RTX_UNCHANGING_P (def
) = 1;
3557 /* Mark the symbol_ref as belonging to this constants pool. */
3558 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3559 current_function_uses_const_pool
= 1;
3561 if (outer_function_chain
== 0)
3562 if (GET_CODE (x
) == CONST_DOUBLE
)
3564 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
3566 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
3567 const_double_chain
= x
;
3569 CONST_DOUBLE_MEM (x
) = def
;
3575 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3576 the corresponding pool_constant structure. */
3578 static struct pool_constant
*
3579 find_pool_constant (addr
)
3582 struct pool_sym
*sym
;
3583 char *label
= XSTR (addr
, 0);
3585 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
3586 if (sym
->label
== label
)
3592 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3595 get_pool_constant (addr
)
3598 return (find_pool_constant (addr
))->constant
;
3601 /* Similar, return the mode. */
3604 get_pool_mode (addr
)
3607 return (find_pool_constant (addr
))->mode
;
3610 /* Similar, return the offset in the constant pool. */
3613 get_pool_offset (addr
)
3616 return (find_pool_constant (addr
))->offset
;
3619 /* Return the size of the constant pool. */
3627 /* Write all the constants in the constant pool. */
3630 output_constant_pool (fnname
, fndecl
)
3631 char *fnname ATTRIBUTE_UNUSED
;
3632 tree fndecl ATTRIBUTE_UNUSED
;
3634 struct pool_constant
*pool
;
3636 union real_extract u
;
3638 /* It is possible for gcc to call force_const_mem and then to later
3639 discard the instructions which refer to the constant. In such a
3640 case we do not need to output the constant. */
3641 mark_constant_pool ();
3643 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3644 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3647 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3654 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3655 whose CODE_LABEL has been deleted. This can occur if a jump table
3656 is eliminated by optimization. If so, write a constant of zero
3657 instead. Note that this can also happen by turning the
3658 CODE_LABEL into a NOTE. */
3659 if (((GET_CODE (x
) == LABEL_REF
3660 && (INSN_DELETED_P (XEXP (x
, 0))
3661 || GET_CODE (XEXP (x
, 0)) == NOTE
)))
3662 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
3663 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
3664 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))
3665 || GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == NOTE
)))
3668 /* First switch to correct section. */
3669 #ifdef SELECT_RTX_SECTION
3670 SELECT_RTX_SECTION (pool
->mode
, x
);
3672 readonly_data_section ();
3675 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3676 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3677 pool
->align
, pool
->labelno
, done
);
3680 if (pool
->align
> 1)
3681 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (pool
->align
));
3683 /* Output the label. */
3684 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3686 /* Output the value of the constant itself. */
3687 switch (GET_MODE_CLASS (pool
->mode
))
3690 if (GET_CODE (x
) != CONST_DOUBLE
)
3693 bcopy ((char *) &CONST_DOUBLE_LOW (x
), (char *) &u
, sizeof u
);
3694 assemble_real (u
.d
, pool
->mode
);
3698 case MODE_PARTIAL_INT
:
3699 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
3706 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3712 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3713 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3716 /* Done with this pool. */
3717 first_pool
= last_pool
= 0;
3720 /* Look through the instructions for this function, and mark all the
3721 entries in the constant pool which are actually being used. */
3724 mark_constant_pool ()
3727 struct pool_constant
*pool
;
3729 if (first_pool
== 0)
3732 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3735 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3736 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3737 mark_constants (PATTERN (insn
));
3739 for (insn
= current_function_epilogue_delay_list
;
3741 insn
= XEXP (insn
, 1))
3742 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3743 mark_constants (PATTERN (insn
));
3745 /* It's possible that the only reference to a symbol is in a symbol
3746 that's in the constant pool. This happens in Fortran under some
3747 situations. (When the constant contains the address of another
3748 constant, and only the first is used directly in an insn.)
3749 This is potentially suboptimal if there's ever a possibility of
3750 backwards (in pool order) 2'd level references. However, it's
3751 not clear that 2'd level references can happen. */
3752 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3754 struct pool_sym
*sym
;
3757 /* skip unmarked entries; no insn refers to them. */
3761 /* skip CONST_DOUBLEs too - correct? */
3762 if (GET_CODE (pool
->constant
) == CONST_DOUBLE
)
3764 label
= XSTR (pool
->constant
, 0);
3766 /* Be sure the symbol's value is marked. */
3767 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
;
3769 if (sym
->label
== label
)
3770 sym
->pool
->mark
= 1;
3771 /* If we didn't find it, there's something truly wrong here, but it
3772 will be announced by the assembler. */
3781 register const char *format_ptr
;
3786 if (GET_CODE (x
) == SYMBOL_REF
)
3788 if (CONSTANT_POOL_ADDRESS_P (x
))
3789 find_pool_constant (x
)->mark
= 1;
3792 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3793 a MEM, but does not constitute a use of that MEM. This is particularly
3794 important inside a nested function, because CONST_DOUBLE_MEM may be
3795 a reference to a MEM in the parent's constant pool. See the comment
3796 in force_const_mem. */
3797 else if (GET_CODE (x
) == CONST_DOUBLE
)
3800 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3801 insns, not any notes that may be attached. We don't want to mark
3802 a constant just because it happens to appear in a REG_EQUIV note. */
3803 if (GET_RTX_CLASS (GET_CODE (x
)) == 'i')
3805 mark_constants (PATTERN (x
));
3809 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3811 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3813 switch (*format_ptr
++)
3816 mark_constants (XEXP (x
, i
));
3820 if (XVEC (x
, i
) != 0)
3824 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3825 mark_constants (XVECEXP (x
, i
, j
));
3844 /* Find all the constants whose addresses are referenced inside of EXP,
3845 and make sure assembler code with a label has been output for each one.
3846 Indicate whether an ADDR_EXPR has been encountered. */
3849 output_addressed_constants (exp
)
3854 switch (TREE_CODE (exp
))
3858 register tree constant
= TREE_OPERAND (exp
, 0);
3860 while (TREE_CODE (constant
) == COMPONENT_REF
)
3862 constant
= TREE_OPERAND (constant
, 0);
3865 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
3866 || TREE_CODE (constant
) == CONSTRUCTOR
)
3867 /* No need to do anything here
3868 for addresses of variables or functions. */
3869 output_constant_def (constant
);
3876 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3877 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3882 case NON_LVALUE_EXPR
:
3883 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3889 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
3890 if (TREE_VALUE (link
) != 0)
3891 reloc
|= output_addressed_constants (TREE_VALUE (link
));
3901 /* Output assembler code for constant EXP to FILE, with no label.
3902 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3903 Assumes output_addressed_constants has been done on EXP already.
3905 Generate exactly SIZE bytes of assembler data, padding at the end
3906 with zeros if necessary. SIZE must always be specified.
3908 SIZE is important for structure constructors,
3909 since trailing members may have been omitted from the constructor.
3910 It is also important for initialization of arrays from string constants
3911 since the full length of the string constant might not be wanted.
3912 It is also needed for initialization of unions, where the initializer's
3913 type is just one member, and that may not be as long as the union.
3915 There a case in which we would fail to output exactly SIZE bytes:
3916 for a structure constructor that wants to produce more than SIZE bytes.
3917 But such constructors will never be generated for any possible input. */
3920 output_constant (exp
, size
)
3924 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
3926 /* Some front-ends use constants other than the standard
3927 language-indepdent varieties, but which may still be output
3928 directly. Give the front-end a chance to convert EXP to a
3929 language-independent representation. */
3930 if (lang_expand_constant
)
3931 exp
= (*lang_expand_constant
) (exp
);
3933 if (size
== 0 || flag_syntax_only
)
3936 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3937 That way we get the constant (we hope) inside it. Also, strip off any
3938 NOP_EXPR that converts between two record, union, array, or set types. */
3939 while ((TREE_CODE (exp
) == NOP_EXPR
3940 && (TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0))
3941 || AGGREGATE_TYPE_P (TREE_TYPE (exp
))))
3942 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3943 exp
= TREE_OPERAND (exp
, 0);
3945 /* Allow a constructor with no elements for any data type.
3946 This means to fill the space with zeros. */
3947 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
3949 assemble_zeros (size
);
3960 case REFERENCE_TYPE
:
3961 /* ??? What about (int)((float)(int)&foo + 4) */
3962 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3963 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3964 exp
= TREE_OPERAND (exp
, 0);
3966 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3967 EXPAND_INITIALIZER
),
3969 error ("initializer for integer value is too complicated");
3974 if (TREE_CODE (exp
) != REAL_CST
)
3975 error ("initializer for floating value is not a floating constant");
3977 assemble_real (TREE_REAL_CST (exp
),
3978 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
3983 output_constant (TREE_REALPART (exp
), size
/ 2);
3984 output_constant (TREE_IMAGPART (exp
), size
/ 2);
3985 size
-= (size
/ 2) * 2;
3989 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3991 output_constructor (exp
, size
);
3994 else if (TREE_CODE (exp
) == STRING_CST
)
3998 if (size
> TREE_STRING_LENGTH (exp
))
4000 excess
= size
- TREE_STRING_LENGTH (exp
);
4001 size
= TREE_STRING_LENGTH (exp
);
4004 assemble_string (TREE_STRING_POINTER (exp
), size
);
4013 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4014 output_constructor (exp
, size
);
4020 if (TREE_CODE (exp
) == INTEGER_CST
)
4021 assemble_integer (expand_expr (exp
, NULL_RTX
,
4022 VOIDmode
, EXPAND_INITIALIZER
),
4024 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4026 unsigned char *buffer
= (unsigned char *) alloca (size
);
4027 if (get_set_constructor_bytes (exp
, buffer
, size
))
4029 assemble_string ((char *) buffer
, size
);
4032 error ("unknown set constructor type");
4040 assemble_zeros (size
);
4044 /* Subroutine of output_constant, used for CONSTRUCTORs
4045 (aggregate constants).
4046 Generate at least SIZE bytes, padding if necessary. */
4049 output_constructor (exp
, size
)
4053 register tree link
, field
= 0;
4054 HOST_WIDE_INT min_index
= 0;
4055 /* Number of bytes output or skipped so far.
4056 In other words, current position within the constructor. */
4057 int total_bytes
= 0;
4058 /* Non-zero means BYTE contains part of a byte, to be output. */
4059 int byte_buffer_in_use
= 0;
4062 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4065 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
4066 field
= TYPE_FIELDS (TREE_TYPE (exp
));
4068 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
4069 && TYPE_DOMAIN (TREE_TYPE (exp
)) != 0)
4071 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp
))));
4073 /* As LINK goes through the elements of the constant,
4074 FIELD goes through the structure fields, if the constant is a structure.
4075 if the constant is a union, then we override this,
4076 by getting the field from the TREE_LIST element.
4077 But the constant could also be an array. Then FIELD is zero.
4079 There is always a maximum of one element in the chain LINK for unions
4080 (even if the initializer in a source program incorrectly contains
4082 for (link
= CONSTRUCTOR_ELTS (exp
);
4084 link
= TREE_CHAIN (link
),
4085 field
= field
? TREE_CHAIN (field
) : 0)
4087 tree val
= TREE_VALUE (link
);
4090 /* the element in a union constructor specifies the proper field. */
4092 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
4093 || TREE_CODE (TREE_TYPE (exp
)) == UNION_TYPE
)
4095 /* if available, use the type given by link */
4096 if (TREE_PURPOSE (link
) != 0)
4097 field
= TREE_PURPOSE (link
);
4100 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
4101 index
= TREE_PURPOSE (link
);
4103 /* Eliminate the marker that makes a cast not be an lvalue. */
4107 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4109 register int fieldsize
4110 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
4111 HOST_WIDE_INT lo_index
= TREE_INT_CST_LOW (TREE_OPERAND (index
, 0));
4112 HOST_WIDE_INT hi_index
= TREE_INT_CST_LOW (TREE_OPERAND (index
, 1));
4113 HOST_WIDE_INT index
;
4114 for (index
= lo_index
; index
<= hi_index
; index
++)
4116 /* Output the element's initial value. */
4118 assemble_zeros (fieldsize
);
4120 output_constant (val
, fieldsize
);
4122 /* Count its size. */
4123 total_bytes
+= fieldsize
;
4126 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4128 /* An element that is not a bit-field. */
4130 register int fieldsize
;
4131 /* Since this structure is static,
4132 we know the positions are constant. */
4133 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
4137 bitpos
= (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val
)))
4139 * (TREE_INT_CST_LOW (index
) - min_index
));
4141 /* Output any buffered-up bit-fields preceding this element. */
4142 if (byte_buffer_in_use
)
4144 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4146 byte_buffer_in_use
= 0;
4149 /* Advance to offset of this element.
4150 Note no alignment needed in an array, since that is guaranteed
4151 if each element has the proper size. */
4152 if ((field
!= 0 || index
!= 0) && bitpos
!= total_bytes
)
4154 assemble_zeros (bitpos
- total_bytes
);
4155 total_bytes
= bitpos
;
4158 /* Determine size this element should occupy. */
4161 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
4163 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
4165 /* This avoids overflow trouble. */
4166 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
4168 size_int (BITS_PER_UNIT
));
4169 fieldsize
= TREE_INT_CST_LOW (size_tree
);
4173 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
4174 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
4178 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
4180 /* Output the element's initial value. */
4182 assemble_zeros (fieldsize
);
4184 output_constant (val
, fieldsize
);
4186 /* Count its size. */
4187 total_bytes
+= fieldsize
;
4189 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4190 error ("invalid initial value for member `%s'",
4191 IDENTIFIER_POINTER (DECL_NAME (field
)));
4194 /* Element that is a bit-field. */
4196 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
4198 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
4201 val
= integer_zero_node
;
4203 /* If this field does not start in this (or, next) byte,
4205 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4207 /* Output remnant of any bit field in previous bytes. */
4208 if (byte_buffer_in_use
)
4210 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4212 byte_buffer_in_use
= 0;
4215 /* If still not at proper byte, advance to there. */
4216 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4218 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4219 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4223 if (! byte_buffer_in_use
)
4226 /* We must split the element into pieces that fall within
4227 separate bytes, and combine each byte with previous or
4228 following bit-fields. */
4230 /* next_offset is the offset n fbits from the beginning of
4231 the structure to the next bit of this element to be processed.
4232 end_offset is the offset of the first bit past the end of
4234 while (next_offset
< end_offset
)
4238 HOST_WIDE_INT value
;
4239 int next_byte
= next_offset
/ BITS_PER_UNIT
;
4240 int next_bit
= next_offset
% BITS_PER_UNIT
;
4242 /* Advance from byte to byte
4243 within this element when necessary. */
4244 while (next_byte
!= total_bytes
)
4246 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4251 /* Number of bits we can process at once
4252 (all part of the same byte). */
4253 this_time
= MIN (end_offset
- next_offset
,
4254 BITS_PER_UNIT
- next_bit
);
4255 if (BYTES_BIG_ENDIAN
)
4257 /* On big-endian machine, take the most significant bits
4258 first (of the bits that are significant)
4259 and put them into bytes from the most significant end. */
4260 shift
= end_offset
- next_offset
- this_time
;
4261 /* Don't try to take a bunch of bits that cross
4262 the word boundary in the INTEGER_CST. */
4263 if (shift
< HOST_BITS_PER_WIDE_INT
4264 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4266 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
4267 shift
= HOST_BITS_PER_WIDE_INT
;
4270 /* Now get the bits from the appropriate constant word. */
4271 if (shift
< HOST_BITS_PER_WIDE_INT
)
4273 value
= TREE_INT_CST_LOW (val
);
4275 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4277 value
= TREE_INT_CST_HIGH (val
);
4278 shift
-= HOST_BITS_PER_WIDE_INT
;
4282 byte
|= (((value
>> shift
)
4283 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
4284 << (BITS_PER_UNIT
- this_time
- next_bit
));
4288 /* On little-endian machines,
4289 take first the least significant bits of the value
4290 and pack them starting at the least significant
4291 bits of the bytes. */
4292 shift
= (next_offset
4293 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
4294 /* Don't try to take a bunch of bits that cross
4295 the word boundary in the INTEGER_CST. */
4296 if (shift
< HOST_BITS_PER_WIDE_INT
4297 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4299 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
4300 shift
= HOST_BITS_PER_WIDE_INT
;
4303 /* Now get the bits from the appropriate constant word. */
4304 if (shift
< HOST_BITS_PER_WIDE_INT
)
4305 value
= TREE_INT_CST_LOW (val
);
4306 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4308 value
= TREE_INT_CST_HIGH (val
);
4309 shift
-= HOST_BITS_PER_WIDE_INT
;
4313 byte
|= (((value
>> shift
)
4314 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
4317 next_offset
+= this_time
;
4318 byte_buffer_in_use
= 1;
4322 if (byte_buffer_in_use
)
4324 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4327 if (total_bytes
< size
)
4328 assemble_zeros (size
- total_bytes
);
4331 #ifdef HANDLE_PRAGMA_WEAK
4332 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4333 associatd with NAME. */
4336 add_weak (name
, value
)
4340 struct weak_syms
*weak
;
4342 weak
= (struct weak_syms
*) permalloc (sizeof (struct weak_syms
));
4347 weak
->next
= weak_decls
;
4349 weak
->value
= value
;
4354 #endif /* HANDLE_PRAGMA_WEAK */
4356 /* Declare DECL to be a weak symbol. */
4362 if (! TREE_PUBLIC (decl
))
4363 error_with_decl (decl
, "weak declaration of `%s' must be public");
4364 else if (TREE_ASM_WRITTEN (decl
))
4365 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4366 else if (SUPPORTS_WEAK
)
4367 DECL_WEAK (decl
) = 1;
4368 #ifdef HANDLE_PRAGMA_WEAK
4369 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), NULL
);
4373 /* Emit any pending weak declarations. */
4375 #ifdef HANDLE_PRAGMA_WEAK
4376 struct weak_syms
* weak_decls
;
4382 #ifdef HANDLE_PRAGMA_WEAK
4383 if (HANDLE_PRAGMA_WEAK
)
4385 struct weak_syms
*t
;
4386 for (t
= weak_decls
; t
; t
= t
->next
)
4390 ASM_WEAKEN_LABEL (asm_out_file
, t
->name
);
4392 ASM_OUTPUT_DEF (asm_out_file
, t
->name
, t
->value
);
4399 /* Remove NAME from the pending list of weak symbols. This prevents
4400 the compiler from emitting multiple .weak directives which confuses
4403 remove_from_pending_weak_list (name
)
4404 char *name ATTRIBUTE_UNUSED
;
4406 #ifdef HANDLE_PRAGMA_WEAK
4407 if (HANDLE_PRAGMA_WEAK
)
4409 struct weak_syms
*t
;
4410 for (t
= weak_decls
; t
; t
= t
->next
)
4412 if (t
->name
&& strcmp (name
, t
->name
) == 0)
4420 assemble_alias (decl
, target
)
4421 tree decl
, target ATTRIBUTE_UNUSED
;
4425 make_decl_rtl (decl
, (char *) 0, 1);
4426 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4428 #ifdef ASM_OUTPUT_DEF
4429 /* Make name accessible from other files, if appropriate. */
4431 if (TREE_PUBLIC (decl
))
4433 #ifdef ASM_WEAKEN_LABEL
4434 if (DECL_WEAK (decl
))
4436 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4437 /* Remove this function from the pending weak list so that
4438 we do not emit multiple .weak directives for it. */
4439 remove_from_pending_weak_list
4440 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
4444 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4447 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4448 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4450 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4452 TREE_ASM_WRITTEN (decl
) = 1;
4454 #ifdef ASM_OUTPUT_WEAK_ALIAS
4455 if (! DECL_WEAK (decl
))
4456 warning ("only weak aliases are supported in this configuration");
4458 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4459 TREE_ASM_WRITTEN (decl
) = 1;
4461 warning ("alias definitions not supported in this configuration; ignored");
4466 /* This determines whether or not we support link-once semantics. */
4467 #ifndef SUPPORTS_ONE_ONLY
4468 #ifdef MAKE_DECL_ONE_ONLY
4469 #define SUPPORTS_ONE_ONLY 1
4471 #define SUPPORTS_ONE_ONLY 0
4475 /* Returns 1 if the target configuration supports defining public symbols
4476 so that one of them will be chosen at link time instead of generating a
4477 multiply-defined symbol error, whether through the use of weak symbols or
4478 a target-specific mechanism for having duplicates discarded. */
4481 supports_one_only ()
4483 if (SUPPORTS_ONE_ONLY
)
4485 return SUPPORTS_WEAK
;
4488 /* Set up DECL as a public symbol that can be defined in multiple
4489 translation units without generating a linker error. */
4492 make_decl_one_only (decl
)
4495 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
4498 TREE_PUBLIC (decl
) = 1;
4500 if (TREE_CODE (decl
) == VAR_DECL
4501 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4502 DECL_COMMON (decl
) = 1;
4503 else if (SUPPORTS_ONE_ONLY
)
4505 #ifdef MAKE_DECL_ONE_ONLY
4506 MAKE_DECL_ONE_ONLY (decl
);
4508 DECL_ONE_ONLY (decl
) = 1;
4510 else if (SUPPORTS_WEAK
)
4511 DECL_WEAK (decl
) = 1;