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 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
983 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
986 #ifdef SDB_DEBUGGING_INFO
987 /* Output SDB definition of the function. */
988 if (write_symbols
== SDB_DEBUG
)
989 sdbout_mark_begin_function ();
992 #ifdef DBX_DEBUGGING_INFO
993 /* Output DBX definition of the function. */
994 if (write_symbols
== DBX_DEBUG
)
995 dbxout_begin_function (decl
);
998 /* Make function name accessible from other files, if appropriate. */
1000 if (TREE_PUBLIC (decl
))
1002 if (! first_global_object_name
)
1007 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1008 name
= &first_global_object_name
;
1010 name
= &weak_global_object_name
;
1012 STRIP_NAME_ENCODING (p
, fnname
);
1013 *name
= permalloc (strlen (p
) + 1);
1017 #ifdef ASM_WEAKEN_LABEL
1018 if (DECL_WEAK (decl
))
1020 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
1021 /* Remove this function from the pending weak list so that
1022 we do not emit multiple .weak directives for it. */
1023 remove_from_pending_weak_list
1024 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1028 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
1031 /* Do any machine/system dependent processing of the function name */
1032 #ifdef ASM_DECLARE_FUNCTION_NAME
1033 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1035 /* Standard thing is just output label for the function. */
1036 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1037 #endif /* ASM_DECLARE_FUNCTION_NAME */
1040 /* Output assembler code associated with defining the size of the
1041 function. DECL describes the function. NAME is the function's name. */
1044 assemble_end_function (decl
, fnname
)
1048 #ifdef ASM_DECLARE_FUNCTION_SIZE
1049 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1051 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1053 output_constant_pool (fnname
, decl
);
1054 function_section (decl
); /* need to switch back */
1057 /* Output any constants which should appear after the function. */
1058 output_after_function_constants ();
1061 /* Assemble code to leave SIZE bytes of zeros. */
1064 assemble_zeros (size
)
1067 /* Do no output if -fsyntax-only. */
1068 if (flag_syntax_only
)
1071 #ifdef ASM_NO_SKIP_IN_TEXT
1072 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1073 so we must output 0s explicitly in the text section. */
1074 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1078 for (i
= 0; i
< size
- 20; i
+= 20)
1081 fprintf (asm_out_file
,
1082 "%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
);
1084 fprintf (asm_out_file
,
1085 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1091 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
1093 fprintf (asm_out_file
, "\tbyte 0");
1096 for (; i
< size
; i
++)
1097 fprintf (asm_out_file
, ",0");
1098 fprintf (asm_out_file
, "\n");
1104 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1107 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1110 assemble_align (align
)
1113 if (align
> BITS_PER_UNIT
)
1114 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1117 /* Assemble a string constant with the specified C string as contents. */
1120 assemble_string (p
, size
)
1127 /* If the string is very long, split it up. */
1131 int thissize
= size
- pos
;
1132 if (thissize
> maximum
)
1135 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1143 /* Assemble everything that is needed for a variable or function declaration.
1144 Not used for automatic variables, and not used for function definitions.
1145 Should not be called for variables of incomplete structure type.
1147 TOP_LEVEL is nonzero if this variable has file scope.
1148 AT_END is nonzero if this is the special handling, at end of compilation,
1149 to define things that have had only tentative definitions.
1150 DONT_OUTPUT_DATA if nonzero means don't actually output the
1151 initial value (that will be done by the caller). */
1154 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1156 int top_level ATTRIBUTE_UNUSED
;
1158 int dont_output_data
;
1160 register char *name
;
1162 tree size_tree
= NULL_TREE
;
1164 enum in_section saved_in_section
;
1166 last_assemble_variable_decl
= 0;
1168 if (GET_CODE (DECL_RTL (decl
)) == REG
)
1170 /* Do output symbol info for global register variables, but do nothing
1173 if (TREE_ASM_WRITTEN (decl
))
1175 TREE_ASM_WRITTEN (decl
) = 1;
1177 /* Do no output if -fsyntax-only. */
1178 if (flag_syntax_only
)
1181 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1182 /* File-scope global variables are output here. */
1183 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1185 dbxout_symbol (decl
, 0);
1187 #ifdef SDB_DEBUGGING_INFO
1188 if (write_symbols
== SDB_DEBUG
&& top_level
1189 /* Leave initialized global vars for end of compilation;
1190 see comment in compile_file. */
1191 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1192 sdbout_symbol (decl
, 0);
1195 /* Don't output any DWARF debugging information for variables here.
1196 In the case of local variables, the information for them is output
1197 when we do our recursive traversal of the tree representation for
1198 the entire containing function. In the case of file-scope variables,
1199 we output information for all of them at the very end of compilation
1200 while we are doing our final traversal of the chain of file-scope
1206 /* Normally no need to say anything here for external references,
1207 since assemble_external is called by the language-specific code
1208 when a declaration is first seen. */
1210 if (DECL_EXTERNAL (decl
))
1213 /* Output no assembler code for a function declaration.
1214 Only definitions of functions output anything. */
1216 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1219 /* If type was incomplete when the variable was declared,
1220 see if it is complete now. */
1222 if (DECL_SIZE (decl
) == 0)
1223 layout_decl (decl
, 0);
1225 /* Still incomplete => don't allocate it; treat the tentative defn
1226 (which is what it must have been) as an `extern' reference. */
1228 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1230 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1231 DECL_SOURCE_LINE (decl
),
1232 "storage size of `%s' isn't known",
1233 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1234 TREE_ASM_WRITTEN (decl
) = 1;
1238 /* The first declaration of a variable that comes through this function
1239 decides whether it is global (in C, has external linkage)
1240 or local (in C, has internal linkage). So do nothing more
1241 if this function has already run. */
1243 if (TREE_ASM_WRITTEN (decl
))
1246 TREE_ASM_WRITTEN (decl
) = 1;
1248 /* Do no output if -fsyntax-only. */
1249 if (flag_syntax_only
)
1254 if (! dont_output_data
)
1258 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1261 /* This is better than explicit arithmetic, since it avoids overflow. */
1262 size_tree
= size_binop (CEIL_DIV_EXPR
,
1263 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
1265 size
= TREE_INT_CST_LOW (size_tree
);
1266 if (TREE_INT_CST_HIGH (size_tree
) != 0
1267 || size
!= TREE_INT_CST_LOW (size_tree
))
1269 error_with_decl (decl
, "size of variable `%s' is too large");
1274 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1276 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1277 && ! first_global_object_name
1278 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1279 || DECL_INITIAL (decl
) == error_mark_node
))
1280 && ! DECL_WEAK (decl
)
1281 && ! DECL_ONE_ONLY (decl
))
1285 STRIP_NAME_ENCODING (p
, name
);
1286 first_global_object_name
= permalloc (strlen (p
) + 1);
1287 strcpy (first_global_object_name
, p
);
1290 /* Compute the alignment of this data. */
1292 align
= DECL_ALIGN (decl
);
1294 /* In the case for initialing an array whose length isn't specified,
1295 where we have not yet been able to do the layout,
1296 figure out the proper alignment now. */
1297 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1298 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1299 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1301 /* Some object file formats have a maximum alignment which they support.
1302 In particular, a.out format supports a maximum alignment of 4. */
1303 #ifndef MAX_OFILE_ALIGNMENT
1304 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1306 if (align
> MAX_OFILE_ALIGNMENT
)
1308 warning_with_decl (decl
,
1309 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1310 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1311 align
= MAX_OFILE_ALIGNMENT
;
1314 /* On some machines, it is good to increase alignment sometimes. */
1315 #ifdef DATA_ALIGNMENT
1316 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1318 #ifdef CONSTANT_ALIGNMENT
1319 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1320 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1323 /* Reset the alignment in case we have made it tighter, so we can benefit
1324 from it in get_pointer_alignment. */
1325 DECL_ALIGN (decl
) = align
;
1327 /* Handle uninitialized definitions. */
1329 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
)
1330 /* If the target can't output uninitialized but not common global data
1331 in .bss, then we have to use .data. */
1332 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1333 && DECL_COMMON (decl
)
1335 && DECL_SECTION_NAME (decl
) == 0
1336 && ! dont_output_data
)
1338 int size
= TREE_INT_CST_LOW (size_tree
);
1341 /* Don't allocate zero bytes of common,
1342 since that means "undefined external" in the linker. */
1343 if (size
== 0) rounded
= 1;
1344 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1345 so that each uninitialized object starts on such a boundary. */
1346 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1347 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1348 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1350 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1351 if ( (DECL_ALIGN (decl
) / BITS_PER_UNIT
) > rounded
)
1353 (decl
, "requested alignment for %s is greater than implemented alignment of %d.",rounded
);
1356 #ifdef DBX_DEBUGGING_INFO
1357 /* File-scope global variables are output here. */
1358 if (write_symbols
== DBX_DEBUG
&& top_level
)
1359 dbxout_symbol (decl
, 0);
1361 #ifdef SDB_DEBUGGING_INFO
1362 if (write_symbols
== SDB_DEBUG
&& top_level
1363 /* Leave initialized global vars for end of compilation;
1364 see comment in compile_file. */
1365 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1366 sdbout_symbol (decl
, 0);
1369 /* Don't output any DWARF debugging information for variables here.
1370 In the case of local variables, the information for them is output
1371 when we do our recursive traversal of the tree representation for
1372 the entire containing function. In the case of file-scope variables,
1373 we output information for all of them at the very end of compilation
1374 while we are doing our final traversal of the chain of file-scope
1377 #if 0 /* ??? We should either delete this or add a comment describing what
1378 it was intended to do and why we shouldn't delete it. */
1379 if (flag_shared_data
)
1383 if (TREE_PUBLIC (decl
)
1384 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1385 && DECL_COMMON (decl
)
1389 #ifdef ASM_OUTPUT_SHARED_COMMON
1390 if (flag_shared_data
)
1391 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1395 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1396 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
, size
,
1399 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1400 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
1403 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1408 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1409 else if (TREE_PUBLIC (decl
))
1411 #ifdef ASM_OUTPUT_SHARED_BSS
1412 if (flag_shared_data
)
1413 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1417 #ifdef ASM_OUTPUT_ALIGNED_BSS
1418 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
,
1421 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1425 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1428 #ifdef ASM_OUTPUT_SHARED_LOCAL
1429 if (flag_shared_data
)
1430 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1434 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1435 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
, size
,
1438 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1439 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
1442 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1450 /* Handle initialized definitions.
1451 Also handle uninitialized global definitions if -fno-common and the
1452 target doesn't support ASM_OUTPUT_BSS. */
1454 /* First make the assembler name(s) global if appropriate. */
1455 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1457 #ifdef ASM_WEAKEN_LABEL
1458 if (DECL_WEAK (decl
))
1460 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1461 /* Remove this variable from the pending weak list so that
1462 we do not emit multiple .weak directives for it. */
1463 remove_from_pending_weak_list
1464 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1468 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1471 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
1473 tree e
= TREE_VALUE (d
);
1474 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
1475 ASM_GLOBALIZE_LABEL (asm_out_file
,
1476 XSTR (XEXP (DECL_RTL (e
), 0), 0));
1480 /* Output any data that we will need to use the address of. */
1481 if (DECL_INITIAL (decl
) == error_mark_node
)
1482 reloc
= contains_pointers_p (TREE_TYPE (decl
));
1483 else if (DECL_INITIAL (decl
))
1484 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1486 #ifdef ASM_OUTPUT_SECTION_NAME
1487 if ((flag_data_sections
!= 0
1488 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1489 || UNIQUE_SECTION_P (decl
))
1490 UNIQUE_SECTION (decl
, reloc
);
1493 /* Switch to the appropriate section. */
1494 variable_section (decl
, reloc
);
1496 /* dbxout.c needs to know this. */
1497 if (in_text_section ())
1498 DECL_IN_TEXT_SECTION (decl
) = 1;
1500 /* Record current section so we can restore it if dbxout.c clobbers it. */
1501 saved_in_section
= in_section
;
1503 /* Output the dbx info now that we have chosen the section. */
1505 #ifdef DBX_DEBUGGING_INFO
1506 /* File-scope global variables are output here. */
1507 if (write_symbols
== DBX_DEBUG
&& top_level
)
1508 dbxout_symbol (decl
, 0);
1510 #ifdef SDB_DEBUGGING_INFO
1511 if (write_symbols
== SDB_DEBUG
&& top_level
1512 /* Leave initialized global vars for end of compilation;
1513 see comment in compile_file. */
1514 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1515 sdbout_symbol (decl
, 0);
1518 /* Don't output any DWARF debugging information for variables here.
1519 In the case of local variables, the information for them is output
1520 when we do our recursive traversal of the tree representation for
1521 the entire containing function. In the case of file-scope variables,
1522 we output information for all of them at the very end of compilation
1523 while we are doing our final traversal of the chain of file-scope
1526 /* If the debugging output changed sections, reselect the section
1527 that's supposed to be selected. */
1528 if (in_section
!= saved_in_section
)
1529 variable_section (decl
, reloc
);
1531 /* Output the alignment of this data. */
1532 if (align
> BITS_PER_UNIT
)
1533 ASM_OUTPUT_ALIGN (asm_out_file
,
1534 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1536 /* Do any machine/system dependent processing of the object. */
1537 #ifdef ASM_DECLARE_OBJECT_NAME
1538 last_assemble_variable_decl
= decl
;
1539 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1541 /* Standard thing is just output label for the object. */
1542 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1543 #endif /* ASM_DECLARE_OBJECT_NAME */
1545 if (!dont_output_data
)
1547 if (DECL_INITIAL (decl
))
1548 /* Output the actual data. */
1549 output_constant (DECL_INITIAL (decl
), TREE_INT_CST_LOW (size_tree
));
1551 /* Leave space for it. */
1552 assemble_zeros (TREE_INT_CST_LOW (size_tree
));
1556 #ifdef XCOFF_DEBUGGING_INFO
1557 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1558 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1559 and `aa' hasn't been output yet, the assembler generates a stab entry with
1560 a value of zero, in addition to creating an unnecessary external entry
1561 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1563 /* File-scope global variables are output here. */
1564 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
1566 saved_in_section
= in_section
;
1568 dbxout_symbol (decl
, 0);
1570 if (in_section
!= saved_in_section
)
1571 variable_section (decl
, reloc
);
1574 /* There must be a statement after a label. */
1579 /* Return 1 if type TYPE contains any pointers. */
1582 contains_pointers_p (type
)
1585 switch (TREE_CODE (type
))
1588 case REFERENCE_TYPE
:
1589 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1590 so I'll play safe and return 1. */
1596 case QUAL_UNION_TYPE
:
1599 /* For a type that has fields, see if the fields have pointers. */
1600 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1601 if (TREE_CODE (fields
) == FIELD_DECL
1602 && contains_pointers_p (TREE_TYPE (fields
)))
1608 /* An array type contains pointers if its element type does. */
1609 return contains_pointers_p (TREE_TYPE (type
));
1616 /* Output something to declare an external symbol to the assembler.
1617 (Most assemblers don't need this, so we normally output nothing.)
1618 Do nothing if DECL is not external. */
1621 assemble_external (decl
)
1622 tree decl ATTRIBUTE_UNUSED
;
1624 #ifdef ASM_OUTPUT_EXTERNAL
1625 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
1626 && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1628 rtx rtl
= DECL_RTL (decl
);
1630 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1631 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1633 /* Some systems do require some output. */
1634 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1635 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1641 /* Similar, for calling a library function FUN. */
1644 assemble_external_libcall (fun
)
1645 rtx fun ATTRIBUTE_UNUSED
;
1647 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1648 /* Declare library function name external when first used, if nec. */
1649 if (! SYMBOL_REF_USED (fun
))
1651 SYMBOL_REF_USED (fun
) = 1;
1652 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1657 /* Declare the label NAME global. */
1660 assemble_global (name
)
1663 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1666 /* Assemble a label named NAME. */
1669 assemble_label (name
)
1672 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1675 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1676 If NAME starts with a *, the rest of NAME is output verbatim.
1677 Otherwise NAME is transformed in an implementation-defined way
1678 (usually by the addition of an underscore).
1679 Many macros in the tm file are defined to call this function. */
1682 assemble_name (file
, name
)
1686 const char *real_name
;
1689 STRIP_NAME_ENCODING (real_name
, name
);
1690 if (flag_prefix_function_name
1691 && ! bcmp (real_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
))
1692 real_name
= real_name
+ CHKR_PREFIX_SIZE
;
1694 id
= maybe_get_identifier (real_name
);
1696 TREE_SYMBOL_REFERENCED (id
) = 1;
1699 fputs (&name
[1], file
);
1701 ASM_OUTPUT_LABELREF (file
, name
);
1704 /* Allocate SIZE bytes writable static space with a gensym name
1705 and return an RTX to refer to its address. */
1708 assemble_static_space (size
)
1716 if (flag_shared_data
)
1720 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1723 namestring
= (char *) obstack_alloc (saveable_obstack
,
1725 strcpy (namestring
, name
);
1727 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1729 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1730 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1733 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1734 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1737 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1738 so that each uninitialized object starts on such a boundary. */
1739 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1740 int rounded ATTRIBUTE_UNUSED
1741 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1742 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1743 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1744 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1751 /* Assemble the static constant template for function entry trampolines.
1752 This is done at most once per compilation.
1753 Returns an RTX for the address of the template. */
1755 #ifdef TRAMPOLINE_TEMPLATE
1757 assemble_trampoline_template ()
1763 /* By default, put trampoline templates in read-only data section. */
1765 #ifdef TRAMPOLINE_SECTION
1766 TRAMPOLINE_SECTION ();
1768 readonly_data_section ();
1771 /* Write the assembler code to define one. */
1772 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1774 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1776 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1777 TRAMPOLINE_TEMPLATE (asm_out_file
);
1779 /* Record the rtl to refer to it. */
1780 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1782 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1783 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1787 /* Assemble the integer constant X into an object of SIZE bytes.
1788 X must be either a CONST_INT or CONST_DOUBLE.
1790 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1791 non-zero, abort if we can't output the constant. */
1794 assemble_integer (x
, size
, force
)
1799 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1800 ASM_OUTPUT... macros. */
1804 #ifdef ASM_OUTPUT_CHAR
1806 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1810 #ifdef ASM_OUTPUT_SHORT
1812 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1816 #ifdef ASM_OUTPUT_INT
1818 ASM_OUTPUT_INT (asm_out_file
, x
);
1822 #ifdef ASM_OUTPUT_DOUBLE_INT
1824 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1828 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1830 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1835 /* If we couldn't do it that way, there are two other possibilities: First,
1836 if the machine can output an explicit byte and this is a 1 byte constant,
1837 we can use ASM_OUTPUT_BYTE. */
1839 #ifdef ASM_OUTPUT_BYTE
1840 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1842 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1847 /* Finally, if SIZE is larger than a single word, try to output the constant
1848 one word at a time. */
1850 if (size
> UNITS_PER_WORD
)
1853 enum machine_mode mode
1854 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1857 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1859 word
= operand_subword (x
, i
, 0, mode
);
1864 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1868 if (i
== size
/ UNITS_PER_WORD
)
1870 /* If we output at least one word and then could not finish,
1871 there is no valid way to continue. */
1882 /* Assemble the floating-point constant D into an object of size MODE. */
1885 assemble_real (d
, mode
)
1887 enum machine_mode mode
;
1889 jmp_buf output_constant_handler
;
1891 if (setjmp (output_constant_handler
))
1893 error ("floating point trap outputting a constant");
1894 #ifdef REAL_IS_NOT_DOUBLE
1895 bzero ((char *) &d
, sizeof d
);
1902 set_float_handler (output_constant_handler
);
1906 #ifdef ASM_OUTPUT_BYTE_FLOAT
1908 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, d
);
1911 #ifdef ASM_OUTPUT_SHORT_FLOAT
1913 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, d
);
1916 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1918 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, d
);
1921 #ifdef ASM_OUTPUT_FLOAT
1923 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1927 #ifdef ASM_OUTPUT_DOUBLE
1929 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1933 #ifdef ASM_OUTPUT_LONG_DOUBLE
1936 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1944 set_float_handler (NULL_PTR
);
1947 /* Here we combine duplicate floating constants to make
1948 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1950 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1951 They are chained through the CONST_DOUBLE_CHAIN.
1952 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1953 In that case, CONST_DOUBLE_MEM is either a MEM,
1954 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1956 (CONST_DOUBLE_MEM is used only for top-level functions.
1957 See force_const_mem for explanation.) */
1959 static rtx const_double_chain
;
1961 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1962 For an integer, I0 is the low-order word and I1 is the high-order word.
1963 For a real number, I0 is the word with the low address
1964 and I1 is the word with the high address. */
1967 immed_double_const (i0
, i1
, mode
)
1968 HOST_WIDE_INT i0
, i1
;
1969 enum machine_mode mode
;
1973 if (GET_MODE_CLASS (mode
) == MODE_INT
1974 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
1976 /* We clear out all bits that don't belong in MODE, unless they and our
1977 sign bit are all one. So we get either a reasonable negative value
1978 or a reasonable unsigned value for this mode. */
1979 int width
= GET_MODE_BITSIZE (mode
);
1980 if (width
< HOST_BITS_PER_WIDE_INT
1981 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
1982 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
1983 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
1984 else if (width
== HOST_BITS_PER_WIDE_INT
1985 && ! (i1
== ~0 && i0
< 0))
1987 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
1988 /* We cannot represent this value as a constant. */
1991 /* If this would be an entire word for the target, but is not for
1992 the host, then sign-extend on the host so that the number will look
1993 the same way on the host that it would on the target.
1995 For example, when building a 64 bit alpha hosted 32 bit sparc
1996 targeted compiler, then we want the 32 bit unsigned value -1 to be
1997 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1998 The later confuses the sparc backend. */
2000 if (BITS_PER_WORD
< HOST_BITS_PER_WIDE_INT
&& BITS_PER_WORD
== width
2001 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
2002 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
2004 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2006 ??? Strictly speaking, this is wrong if we create a CONST_INT
2007 for a large unsigned constant with the size of MODE being
2008 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2009 wider mode. In that case we will mis-interpret it as a negative
2012 Unfortunately, the only alternative is to make a CONST_DOUBLE
2013 for any constant in any mode if it is an unsigned constant larger
2014 than the maximum signed integer in an int on the host. However,
2015 doing this will break everyone that always expects to see a CONST_INT
2016 for SImode and smaller.
2018 We have always been making CONST_INTs in this case, so nothing new
2021 if (width
<= HOST_BITS_PER_WIDE_INT
)
2022 i1
= (i0
< 0) ? ~(HOST_WIDE_INT
) 0 : 0;
2024 /* If this integer fits in one word, return a CONST_INT. */
2025 if ((i1
== 0 && i0
>= 0)
2026 || (i1
== ~0 && i0
< 0))
2027 return GEN_INT (i0
);
2029 /* We use VOIDmode for integers. */
2033 /* Search the chain for an existing CONST_DOUBLE with the right value.
2034 If one is found, return it. */
2036 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2037 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
2038 && GET_MODE (r
) == mode
)
2041 /* No; make a new one and add it to the chain.
2043 We may be called by an optimizer which may be discarding any memory
2044 allocated during its processing (such as combine and loop). However,
2045 we will be leaving this constant on the chain, so we cannot tolerate
2046 freed memory. So switch to saveable_obstack for this allocation
2047 and then switch back if we were in current_obstack. */
2049 push_obstacks_nochange ();
2050 rtl_in_saveable_obstack ();
2051 r
= gen_rtx_CONST_DOUBLE (mode
, NULL_RTX
, i0
, i1
);
2054 /* Don't touch const_double_chain in nested function; see force_const_mem.
2055 Also, don't touch it if not inside any function. */
2056 if (outer_function_chain
== 0 && current_function_decl
!= 0)
2058 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2059 const_double_chain
= r
;
2062 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2063 Actual use of mem-slot is only through force_const_mem. */
2065 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2070 /* Return a CONST_DOUBLE for a specified `double' value
2071 and machine mode. */
2074 immed_real_const_1 (d
, mode
)
2076 enum machine_mode mode
;
2078 union real_extract u
;
2081 /* Get the desired `double' value as a sequence of ints
2082 since that is how they are stored in a CONST_DOUBLE. */
2086 /* Detect special cases. */
2088 if (REAL_VALUES_IDENTICAL (dconst0
, d
))
2089 return CONST0_RTX (mode
);
2090 /* Check for NaN first, because some ports (specifically the i386) do not
2091 emit correct ieee-fp code by default, and thus will generate a core
2092 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2093 does a floating point comparison. */
2094 else if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
2095 return CONST1_RTX (mode
);
2097 if (sizeof u
== sizeof (HOST_WIDE_INT
))
2098 return immed_double_const (u
.i
[0], 0, mode
);
2099 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
2100 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
2102 /* The rest of this function handles the case where
2103 a float value requires more than 2 ints of space.
2104 It will be deleted as dead code on machines that don't need it. */
2106 /* Search the chain for an existing CONST_DOUBLE with the right value.
2107 If one is found, return it. */
2109 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2110 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
2111 && GET_MODE (r
) == mode
)
2114 /* No; make a new one and add it to the chain.
2116 We may be called by an optimizer which may be discarding any memory
2117 allocated during its processing (such as combine and loop). However,
2118 we will be leaving this constant on the chain, so we cannot tolerate
2119 freed memory. So switch to saveable_obstack for this allocation
2120 and then switch back if we were in current_obstack. */
2122 push_obstacks_nochange ();
2123 rtl_in_saveable_obstack ();
2124 r
= rtx_alloc (CONST_DOUBLE
);
2126 bcopy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (r
), sizeof u
);
2129 /* Don't touch const_double_chain in nested function; see force_const_mem.
2130 Also, don't touch it if not inside any function. */
2131 if (outer_function_chain
== 0 && current_function_decl
!= 0)
2133 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2134 const_double_chain
= r
;
2137 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2138 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2139 is only through force_const_mem. */
2141 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2146 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2147 which must be a REAL_CST tree node. */
2150 immed_real_const (exp
)
2153 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
2156 /* At the end of a function, forget the memory-constants
2157 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2158 Also clear out real_constant_chain and clear out all the chain-pointers. */
2161 clear_const_double_mem ()
2163 register rtx r
, next
;
2165 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2166 See force_const_mem for explanation. */
2167 if (outer_function_chain
!= 0)
2170 for (r
= const_double_chain
; r
; r
= next
)
2172 next
= CONST_DOUBLE_CHAIN (r
);
2173 CONST_DOUBLE_CHAIN (r
) = 0;
2174 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
2176 const_double_chain
= 0;
2179 /* Given an expression EXP with a constant value,
2180 reduce it to the sum of an assembler symbol and an integer.
2181 Store them both in the structure *VALUE.
2182 Abort if EXP does not reduce. */
2187 HOST_WIDE_INT offset
;
2191 decode_addr_const (exp
, value
)
2193 struct addr_const
*value
;
2195 register tree target
= TREE_OPERAND (exp
, 0);
2196 register int offset
= 0;
2201 if (TREE_CODE (target
) == COMPONENT_REF
2202 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
2205 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
2206 target
= TREE_OPERAND (target
, 0);
2208 else if (TREE_CODE (target
) == ARRAY_REF
)
2210 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
2211 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
2213 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
2214 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
2216 target
= TREE_OPERAND (target
, 0);
2222 switch (TREE_CODE (target
))
2226 x
= DECL_RTL (target
);
2230 x
= gen_rtx_MEM (FUNCTION_MODE
,
2231 gen_rtx_LABEL_REF (VOIDmode
,
2232 label_rtx (TREE_OPERAND (exp
, 0))));
2240 x
= TREE_CST_RTL (target
);
2247 if (GET_CODE (x
) != MEM
)
2252 value
->offset
= offset
;
2255 /* Uniquize all constants that appear in memory.
2256 Each constant in memory thus far output is recorded
2257 in `const_hash_table' with a `struct constant_descriptor'
2258 that contains a polish representation of the value of
2261 We cannot store the trees in the hash table
2262 because the trees may be temporary. */
2264 struct constant_descriptor
2266 struct constant_descriptor
*next
;
2272 #define MAX_HASH_TABLE 1009
2273 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2275 /* Compute a hash code for a constant expression. */
2282 register int len
, hi
, i
;
2283 register enum tree_code code
= TREE_CODE (exp
);
2285 /* Either set P and LEN to the address and len of something to hash and
2286 exit the switch or return a value. */
2291 p
= (char *) &TREE_INT_CST_LOW (exp
);
2292 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2296 p
= (char *) &TREE_REAL_CST (exp
);
2297 len
= sizeof TREE_REAL_CST (exp
);
2301 p
= TREE_STRING_POINTER (exp
);
2302 len
= TREE_STRING_LENGTH (exp
);
2306 return (const_hash (TREE_REALPART (exp
)) * 5
2307 + const_hash (TREE_IMAGPART (exp
)));
2310 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2312 len
= int_size_in_bytes (TREE_TYPE (exp
));
2313 p
= (char *) alloca (len
);
2314 get_set_constructor_bytes (exp
, (unsigned char *) p
, len
);
2321 /* For record type, include the type in the hashing.
2322 We do not do so for array types
2323 because (1) the sizes of the elements are sufficient
2324 and (2) distinct array types can have the same constructor.
2325 Instead, we include the array size because the constructor could
2327 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2328 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2331 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2332 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2334 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2335 if (TREE_VALUE (link
))
2337 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2344 struct addr_const value
;
2346 decode_addr_const (exp
, &value
);
2347 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2349 /* Don't hash the address of the SYMBOL_REF;
2350 only use the offset and the symbol name. */
2352 p
= XSTR (value
.base
, 0);
2353 for (i
= 0; p
[i
] != 0; i
++)
2354 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2356 else if (GET_CODE (value
.base
) == LABEL_REF
)
2357 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2361 hi
&= (1 << HASHBITS
) - 1;
2362 hi
%= MAX_HASH_TABLE
;
2368 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2369 + const_hash (TREE_OPERAND (exp
, 1)));
2373 case NON_LVALUE_EXPR
:
2374 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2380 /* Compute hashing function */
2382 for (i
= 0; i
< len
; i
++)
2383 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2385 hi
&= (1 << HASHBITS
) - 1;
2386 hi
%= MAX_HASH_TABLE
;
2390 /* Compare a constant expression EXP with a constant-descriptor DESC.
2391 Return 1 if DESC describes a constant with the same value as EXP. */
2394 compare_constant (exp
, desc
)
2396 struct constant_descriptor
*desc
;
2398 return 0 != compare_constant_1 (exp
, desc
->contents
);
2401 /* Compare constant expression EXP with a substring P of a constant descriptor.
2402 If they match, return a pointer to the end of the substring matched.
2403 If they do not match, return 0.
2405 Since descriptors are written in polish prefix notation,
2406 this function can be used recursively to test one operand of EXP
2407 against a subdescriptor, and if it succeeds it returns the
2408 address of the subdescriptor for the next operand. */
2411 compare_constant_1 (exp
, p
)
2415 register char *strp
;
2417 register enum tree_code code
= TREE_CODE (exp
);
2419 if (code
!= (enum tree_code
) *p
++)
2422 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2423 switch, or return the result of the comparison. */
2428 /* Integer constants are the same only if the same width of type. */
2429 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2432 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2433 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2437 /* Real constants are the same only if the same width of type. */
2438 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2441 strp
= (char *) &TREE_REAL_CST (exp
);
2442 len
= sizeof TREE_REAL_CST (exp
);
2446 if (flag_writable_strings
)
2449 if (*p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2452 strp
= TREE_STRING_POINTER (exp
);
2453 len
= TREE_STRING_LENGTH (exp
);
2454 if (bcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2455 sizeof TREE_STRING_LENGTH (exp
)))
2458 p
+= sizeof TREE_STRING_LENGTH (exp
);
2462 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2466 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2469 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2471 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2473 strp
= (char *) alloca (len
);
2474 get_set_constructor_bytes (exp
, (unsigned char *) strp
, len
);
2475 if (bcmp ((char *) &xlen
, p
, sizeof xlen
))
2484 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2486 int have_purpose
= 0;
2488 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2489 if (TREE_PURPOSE (link
))
2492 if (bcmp ((char *) &length
, p
, sizeof length
))
2497 /* For record constructors, insist that the types match.
2498 For arrays, just verify both constructors are for arrays.
2499 Then insist that either both or none have any TREE_PURPOSE
2501 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2502 type
= TREE_TYPE (exp
);
2506 if (bcmp ((char *) &type
, p
, sizeof type
))
2511 if (bcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2514 p
+= sizeof have_purpose
;
2516 /* For arrays, insist that the size in bytes match. */
2517 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2519 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2521 if (bcmp ((char *) &size
, p
, sizeof size
))
2527 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2529 if (TREE_VALUE (link
))
2531 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2538 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2544 if (TREE_PURPOSE (link
)
2545 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2547 if (bcmp ((char *) &TREE_PURPOSE (link
), p
,
2548 sizeof TREE_PURPOSE (link
)))
2551 p
+= sizeof TREE_PURPOSE (link
);
2553 else if (TREE_PURPOSE (link
))
2555 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2558 else if (have_purpose
)
2562 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2574 struct addr_const value
;
2576 decode_addr_const (exp
, &value
);
2577 strp
= (char *) &value
.offset
;
2578 len
= sizeof value
.offset
;
2579 /* Compare the offset. */
2581 if (*p
++ != *strp
++)
2584 /* Compare symbol name. */
2585 strp
= XSTR (value
.base
, 0);
2586 len
= strlen (strp
) + 1;
2593 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2597 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2601 case NON_LVALUE_EXPR
:
2602 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2608 /* Compare constant contents. */
2610 if (*p
++ != *strp
++)
2616 /* Construct a constant descriptor for the expression EXP.
2617 It is up to the caller to enter the descriptor in the hash table. */
2619 static struct constant_descriptor
*
2620 record_constant (exp
)
2623 struct constant_descriptor
*next
= 0;
2626 /* Make a struct constant_descriptor. The first two pointers will
2627 be filled in later. Here we just leave space for them. */
2629 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2630 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2631 record_constant_1 (exp
);
2632 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2635 /* Add a description of constant expression EXP
2636 to the object growing in `permanent_obstack'.
2637 No need to return its address; the caller will get that
2638 from the obstack when the object is complete. */
2641 record_constant_1 (exp
)
2644 register char *strp
;
2646 register enum tree_code code
= TREE_CODE (exp
);
2648 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2653 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2654 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2655 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2659 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2660 strp
= (char *) &TREE_REAL_CST (exp
);
2661 len
= sizeof TREE_REAL_CST (exp
);
2665 if (flag_writable_strings
)
2668 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2669 strp
= TREE_STRING_POINTER (exp
);
2670 len
= TREE_STRING_LENGTH (exp
);
2671 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2672 sizeof TREE_STRING_LENGTH (exp
));
2676 record_constant_1 (TREE_REALPART (exp
));
2677 record_constant_1 (TREE_IMAGPART (exp
));
2681 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2683 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2684 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2685 obstack_blank (&permanent_obstack
, nbytes
);
2686 get_set_constructor_bytes
2687 (exp
, (unsigned char *) permanent_obstack
.next_free
-nbytes
,
2694 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2696 int have_purpose
= 0;
2698 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2699 if (TREE_PURPOSE (link
))
2702 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2704 /* For record constructors, insist that the types match.
2705 For arrays, just verify both constructors are for arrays.
2706 Then insist that either both or none have any TREE_PURPOSE
2708 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2709 type
= TREE_TYPE (exp
);
2712 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2713 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2714 sizeof have_purpose
);
2716 /* For arrays, insist that the size in bytes match. */
2717 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2719 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2720 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2723 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2725 if (TREE_VALUE (link
))
2726 record_constant_1 (TREE_VALUE (link
));
2731 obstack_grow (&permanent_obstack
,
2732 (char *) &zero
, sizeof zero
);
2735 if (TREE_PURPOSE (link
)
2736 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2737 obstack_grow (&permanent_obstack
,
2738 (char *) &TREE_PURPOSE (link
),
2739 sizeof TREE_PURPOSE (link
));
2740 else if (TREE_PURPOSE (link
))
2741 record_constant_1 (TREE_PURPOSE (link
));
2742 else if (have_purpose
)
2746 obstack_grow (&permanent_obstack
,
2747 (char *) &zero
, sizeof zero
);
2755 struct addr_const value
;
2757 decode_addr_const (exp
, &value
);
2758 /* Record the offset. */
2759 obstack_grow (&permanent_obstack
,
2760 (char *) &value
.offset
, sizeof value
.offset
);
2761 /* Record the symbol name. */
2762 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2763 strlen (XSTR (value
.base
, 0)) + 1);
2770 record_constant_1 (TREE_OPERAND (exp
, 0));
2771 record_constant_1 (TREE_OPERAND (exp
, 1));
2776 case NON_LVALUE_EXPR
:
2777 record_constant_1 (TREE_OPERAND (exp
, 0));
2784 /* Record constant contents. */
2785 obstack_grow (&permanent_obstack
, strp
, len
);
2788 /* Record a list of constant expressions that were passed to
2789 output_constant_def but that could not be output right away. */
2791 struct deferred_constant
2793 struct deferred_constant
*next
;
2799 static struct deferred_constant
*deferred_constants
;
2801 /* Another list of constants which should be output after the
2803 static struct deferred_constant
*after_function_constants
;
2805 /* Nonzero means defer output of addressed subconstants
2806 (i.e., those for which output_constant_def is called.) */
2807 static int defer_addressed_constants_flag
;
2809 /* Start deferring output of subconstants. */
2812 defer_addressed_constants ()
2814 defer_addressed_constants_flag
++;
2817 /* Stop deferring output of subconstants,
2818 and output now all those that have been deferred. */
2821 output_deferred_addressed_constants ()
2823 struct deferred_constant
*p
, *next
;
2825 defer_addressed_constants_flag
--;
2827 if (defer_addressed_constants_flag
> 0)
2830 for (p
= deferred_constants
; p
; p
= next
)
2832 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2837 deferred_constants
= 0;
2840 /* Output any constants which should appear after a function. */
2843 output_after_function_constants ()
2845 struct deferred_constant
*p
, *next
;
2847 for (p
= after_function_constants
; p
; p
= next
)
2849 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2854 after_function_constants
= 0;
2857 /* Make a copy of the whole tree structure for a constant.
2858 This handles the same types of nodes that compare_constant
2859 and record_constant handle. */
2865 switch (TREE_CODE (exp
))
2868 /* For ADDR_EXPR, we do not want to copy the decl whose address
2869 is requested. We do want to copy constants though. */
2870 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2871 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2872 copy_constant (TREE_OPERAND (exp
, 0)));
2874 return copy_node (exp
);
2879 return copy_node (exp
);
2882 return build_complex (TREE_TYPE (exp
),
2883 copy_constant (TREE_REALPART (exp
)),
2884 copy_constant (TREE_IMAGPART (exp
)));
2888 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2889 copy_constant (TREE_OPERAND (exp
, 0)),
2890 copy_constant (TREE_OPERAND (exp
, 1)));
2894 case NON_LVALUE_EXPR
:
2895 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2896 copy_constant (TREE_OPERAND (exp
, 0)));
2900 tree copy
= copy_node (exp
);
2901 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2904 CONSTRUCTOR_ELTS (copy
) = list
;
2905 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2906 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2907 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2908 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2909 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
2919 /* Return an rtx representing a reference to constant data in memory
2920 for the constant expression EXP.
2922 If assembler code for such a constant has already been output,
2923 return an rtx to refer to it.
2924 Otherwise, output such a constant in memory (or defer it for later)
2925 and generate an rtx for it.
2927 The TREE_CST_RTL of EXP is set up to point to that rtx.
2928 The const_hash_table records which constants already have label strings. */
2931 output_constant_def (exp
)
2935 register struct constant_descriptor
*desc
;
2941 if (TREE_CST_RTL (exp
))
2942 return TREE_CST_RTL (exp
);
2944 /* Make sure any other constants whose addresses appear in EXP
2945 are assigned label numbers. */
2947 reloc
= output_addressed_constants (exp
);
2949 /* Compute hash code of EXP. Search the descriptors for that hash code
2950 to see if any of them describes EXP. If yes, the descriptor records
2951 the label number already assigned. */
2953 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
2955 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
2956 if (compare_constant (exp
, desc
))
2958 found
= desc
->label
;
2964 /* No constant equal to EXP is known to have been output.
2965 Make a constant descriptor to enter EXP in the hash table.
2966 Assign the label number and record it in the descriptor for
2967 future calls to this function to find. */
2969 /* Create a string containing the label name, in LABEL. */
2970 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2972 desc
= record_constant (exp
);
2973 desc
->next
= const_hash_table
[hash
];
2975 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
2976 const_hash_table
[hash
] = desc
;
2980 /* Create a string containing the label name, in LABEL. */
2981 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2984 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2986 push_obstacks_nochange ();
2987 if (TREE_PERMANENT (exp
))
2988 end_temporary_allocation ();
2990 def
= gen_rtx_SYMBOL_REF (Pmode
, desc
->label
);
2993 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), def
);
2994 RTX_UNCHANGING_P (TREE_CST_RTL (exp
)) = 1;
2995 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
)))
2996 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp
), 1);
3000 /* Optionally set flags or add text to the name to record information
3001 such as that it is a function name. If the name is changed, the macro
3002 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3003 #ifdef ENCODE_SECTION_INFO
3004 ENCODE_SECTION_INFO (exp
);
3007 /* If this is the first time we've seen this particular constant,
3008 output it (or defer its output for later). */
3011 int after_function
= 0;
3013 #ifdef CONSTANT_AFTER_FUNCTION_P
3014 if (current_function_decl
!= 0
3015 && CONSTANT_AFTER_FUNCTION_P (exp
))
3019 if (defer_addressed_constants_flag
|| after_function
)
3021 struct deferred_constant
*p
;
3022 p
= (struct deferred_constant
*) xmalloc (sizeof (struct deferred_constant
));
3024 push_obstacks_nochange ();
3025 suspend_momentary ();
3026 p
->exp
= copy_constant (exp
);
3029 p
->labelno
= const_labelno
++;
3032 p
->next
= after_function_constants
;
3033 after_function_constants
= p
;
3037 p
->next
= deferred_constants
;
3038 deferred_constants
= p
;
3043 /* Do no output if -fsyntax-only. */
3044 if (! flag_syntax_only
)
3045 output_constant_def_contents (exp
, reloc
, const_labelno
);
3050 return TREE_CST_RTL (exp
);
3053 /* Now output assembler code to define the label for EXP,
3054 and follow it with the data of EXP. */
3057 output_constant_def_contents (exp
, reloc
, labelno
)
3064 if (IN_NAMED_SECTION (exp
))
3065 named_section (exp
, NULL
, reloc
);
3068 /* First switch to text section, except for writable strings. */
3069 #ifdef SELECT_SECTION
3070 SELECT_SECTION (exp
, reloc
);
3072 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
3073 || (flag_pic
&& reloc
))
3076 readonly_data_section ();
3080 /* Align the location counter as required by EXP's data type. */
3081 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3082 #ifdef CONSTANT_ALIGNMENT
3083 align
= CONSTANT_ALIGNMENT (exp
, align
);
3086 if (align
> BITS_PER_UNIT
)
3087 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3089 /* Output the label itself. */
3090 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3092 /* Output the value of EXP. */
3093 output_constant (exp
,
3094 (TREE_CODE (exp
) == STRING_CST
3095 ? TREE_STRING_LENGTH (exp
)
3096 : int_size_in_bytes (TREE_TYPE (exp
))));
3100 /* Similar hash facility for making memory-constants
3101 from constant rtl-expressions. It is used on RISC machines
3102 where immediate integer arguments and constant addresses are restricted
3103 so that such constants must be stored in memory.
3105 This pool of constants is reinitialized for each function
3106 so each function gets its own constants-pool that comes right before it.
3108 All structures allocated here are discarded when functions are saved for
3109 inlining, so they do not need to be allocated permanently. */
3111 #define MAX_RTX_HASH_TABLE 61
3112 static struct constant_descriptor
**const_rtx_hash_table
;
3114 /* Structure to represent sufficient information about a constant so that
3115 it can be output when the constant pool is output, so that function
3116 integration can be done, and to simplify handling on machines that reference
3117 constant pool as base+displacement. */
3119 struct pool_constant
3121 struct constant_descriptor
*desc
;
3122 struct pool_constant
*next
;
3123 enum machine_mode mode
;
3131 /* Pointers to first and last constant in pool. */
3133 static struct pool_constant
*first_pool
, *last_pool
;
3135 /* Current offset in constant pool (does not include any machine-specific
3138 static int pool_offset
;
3140 /* Structure used to maintain hash table mapping symbols used to their
3141 corresponding constants. */
3146 struct pool_constant
*pool
;
3147 struct pool_sym
*next
;
3150 static struct pool_sym
**const_rtx_sym_hash_table
;
3152 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3153 The argument is XSTR (... , 0) */
3155 #define SYMHASH(LABEL) \
3156 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3158 /* Initialize constant pool hashing for next function. */
3161 init_const_rtx_hash_table ()
3163 const_rtx_hash_table
3164 = ((struct constant_descriptor
**)
3165 oballoc (MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*)));
3166 const_rtx_sym_hash_table
3167 = ((struct pool_sym
**)
3168 oballoc (MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*)));
3169 bzero ((char *) const_rtx_hash_table
,
3170 MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*));
3171 bzero ((char *) const_rtx_sym_hash_table
,
3172 MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*));
3174 first_pool
= last_pool
= 0;
3178 /* Save and restore status for a nested function. */
3181 save_varasm_status (p
, context
)
3185 p
->const_rtx_hash_table
= const_rtx_hash_table
;
3186 p
->const_rtx_sym_hash_table
= const_rtx_sym_hash_table
;
3187 p
->first_pool
= first_pool
;
3188 p
->last_pool
= last_pool
;
3189 p
->pool_offset
= pool_offset
;
3190 p
->const_double_chain
= const_double_chain
;
3192 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3193 if (context
== NULL_TREE
)
3194 const_double_chain
= 0;
3198 restore_varasm_status (p
)
3201 const_rtx_hash_table
= p
->const_rtx_hash_table
;
3202 const_rtx_sym_hash_table
= p
->const_rtx_sym_hash_table
;
3203 first_pool
= p
->first_pool
;
3204 last_pool
= p
->last_pool
;
3205 pool_offset
= p
->pool_offset
;
3206 const_double_chain
= p
->const_double_chain
;
3209 enum kind
{ RTX_DOUBLE
, RTX_INT
};
3213 #ifdef ONLY_INT_FIELDS
3214 unsigned int kind
: 16;
3215 unsigned int mode
: 16;
3217 enum kind kind
: 16;
3218 enum machine_mode mode
: 16;
3221 union real_extract du
;
3222 struct addr_const addr
;
3223 struct {HOST_WIDE_INT high
, low
;} di
;
3227 /* Express an rtx for a constant integer (perhaps symbolic)
3228 as the sum of a symbol or label plus an explicit integer.
3229 They are stored into VALUE. */
3232 decode_rtx_const (mode
, x
, value
)
3233 enum machine_mode mode
;
3235 struct rtx_const
*value
;
3237 /* Clear the whole structure, including any gaps. */
3240 int *p
= (int *) value
;
3241 int *end
= (int *) (value
+ 1);
3246 value
->kind
= RTX_INT
; /* Most usual kind. */
3249 switch (GET_CODE (x
))
3252 value
->kind
= RTX_DOUBLE
;
3253 if (GET_MODE (x
) != VOIDmode
)
3255 value
->mode
= GET_MODE (x
);
3256 bcopy ((char *) &CONST_DOUBLE_LOW (x
),
3257 (char *) &value
->un
.du
, sizeof value
->un
.du
);
3261 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3262 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3267 value
->un
.addr
.offset
= INTVAL (x
);
3273 value
->un
.addr
.base
= x
;
3278 if (GET_CODE (x
) == PLUS
)
3280 value
->un
.addr
.base
= XEXP (x
, 0);
3281 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3283 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3285 else if (GET_CODE (x
) == MINUS
)
3287 value
->un
.addr
.base
= XEXP (x
, 0);
3288 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3290 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3300 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3301 switch (GET_CODE (value
->un
.addr
.base
))
3305 /* Use the string's address, not the SYMBOL_REF's address,
3306 for the sake of addresses of library routines.
3307 For a LABEL_REF, compare labels. */
3308 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3315 /* Given a MINUS expression, simplify it if both sides
3316 include the same symbol. */
3319 simplify_subtraction (x
)
3322 struct rtx_const val0
, val1
;
3324 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3325 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3327 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3328 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3332 /* Compute a hash code for a constant RTL expression. */
3335 const_hash_rtx (mode
, x
)
3336 enum machine_mode mode
;
3342 struct rtx_const value
;
3343 decode_rtx_const (mode
, x
, &value
);
3345 /* Compute hashing function */
3347 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3348 hi
+= ((int *) &value
)[i
];
3350 hi
&= (1 << HASHBITS
) - 1;
3351 hi
%= MAX_RTX_HASH_TABLE
;
3355 /* Compare a constant rtl object X with a constant-descriptor DESC.
3356 Return 1 if DESC describes a constant with the same value as X. */
3359 compare_constant_rtx (mode
, x
, desc
)
3360 enum machine_mode mode
;
3362 struct constant_descriptor
*desc
;
3364 register int *p
= (int *) desc
->contents
;
3367 struct rtx_const value
;
3369 decode_rtx_const (mode
, x
, &value
);
3370 strp
= (int *) &value
;
3371 len
= sizeof value
/ sizeof (int);
3373 /* Compare constant contents. */
3375 if (*p
++ != *strp
++)
3381 /* Construct a constant descriptor for the rtl-expression X.
3382 It is up to the caller to enter the descriptor in the hash table. */
3384 static struct constant_descriptor
*
3385 record_constant_rtx (mode
, x
)
3386 enum machine_mode mode
;
3389 struct constant_descriptor
*ptr
;
3391 struct rtx_const value
;
3393 decode_rtx_const (mode
, x
, &value
);
3395 /* Put these things in the saveable obstack so we can ensure it won't
3396 be freed if we are called from combine or some other phase that discards
3397 memory allocated from function_obstack (current_obstack). */
3398 obstack_grow (saveable_obstack
, &ptr
, sizeof ptr
);
3399 obstack_grow (saveable_obstack
, &label
, sizeof label
);
3401 /* Record constant contents. */
3402 obstack_grow (saveable_obstack
, &value
, sizeof value
);
3404 return (struct constant_descriptor
*) obstack_finish (saveable_obstack
);
3407 /* Given a constant rtx X, make (or find) a memory constant for its value
3408 and return a MEM rtx to refer to it in memory. */
3411 force_const_mem (mode
, x
)
3412 enum machine_mode mode
;
3416 register struct constant_descriptor
*desc
;
3421 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3422 (this will always be true for floating CONST_DOUBLEs that have been
3423 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3424 use the previous copy. Otherwise, make a new one. Note that in
3425 the unlikely event that this same CONST_DOUBLE is used in two different
3426 modes in an alternating fashion, we will allocate a lot of different
3427 memory locations, but this should be extremely rare. */
3429 /* Don't use CONST_DOUBLE_MEM in a nested function.
3430 Nested functions have their own constant pools,
3431 so they can't share the same values in CONST_DOUBLE_MEM
3432 with the containing function. */
3433 if (outer_function_chain
== 0)
3434 if (GET_CODE (x
) == CONST_DOUBLE
3435 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
3436 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
3437 return CONST_DOUBLE_MEM (x
);
3439 /* Compute hash code of X. Search the descriptors for that hash code
3440 to see if any of them describes X. If yes, the descriptor records
3441 the label number already assigned. */
3443 hash
= const_hash_rtx (mode
, x
);
3445 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3446 if (compare_constant_rtx (mode
, x
, desc
))
3448 found
= desc
->label
;
3454 register struct pool_constant
*pool
;
3455 register struct pool_sym
*sym
;
3458 /* No constant equal to X is known to have been output.
3459 Make a constant descriptor to enter X in the hash table.
3460 Assign the label number and record it in the descriptor for
3461 future calls to this function to find. */
3463 desc
= record_constant_rtx (mode
, x
);
3464 desc
->next
= const_rtx_hash_table
[hash
];
3465 const_rtx_hash_table
[hash
] = desc
;
3467 /* Align the location counter as required by EXP's data type. */
3468 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
3469 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
3470 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
3471 #ifdef CONSTANT_ALIGNMENT
3472 align
= CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode
, 0), x
),
3473 align
* BITS_PER_UNIT
) / BITS_PER_UNIT
;
3476 pool_offset
+= align
- 1;
3477 pool_offset
&= ~ (align
- 1);
3479 /* If RTL is not being placed into the saveable obstack, make a
3480 copy of X that is in the saveable obstack in case we are
3481 being called from combine or some other phase that discards
3482 memory it allocates. We used to only do this if it is a
3483 CONST; however, reload can allocate a CONST_INT when
3484 eliminating registers. */
3485 if (rtl_obstack
!= saveable_obstack
3486 && (GET_CODE (x
) == CONST
|| GET_CODE (x
) == CONST_INT
))
3488 push_obstacks_nochange ();
3489 rtl_in_saveable_obstack ();
3491 if (GET_CODE (x
) == CONST
)
3492 x
= gen_rtx_CONST (GET_MODE (x
),
3493 gen_rtx_PLUS (GET_MODE (x
),
3494 XEXP (XEXP (x
, 0), 0),
3495 XEXP (XEXP (x
, 0), 1)));
3497 x
= GEN_INT (INTVAL (x
));
3502 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3504 pool
= (struct pool_constant
*) savealloc (sizeof (struct pool_constant
));
3508 pool
->labelno
= const_labelno
;
3509 pool
->align
= align
;
3510 pool
->offset
= pool_offset
;
3517 last_pool
->next
= pool
;
3520 pool_offset
+= GET_MODE_SIZE (mode
);
3522 /* Create a string containing the label name, in LABEL. */
3523 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3528 = (char *) obstack_copy0 (saveable_obstack
, label
, strlen (label
));
3530 /* Add label to symbol hash table. */
3531 hash
= SYMHASH (found
);
3532 sym
= (struct pool_sym
*) savealloc (sizeof (struct pool_sym
));
3535 sym
->next
= const_rtx_sym_hash_table
[hash
];
3536 const_rtx_sym_hash_table
[hash
] = sym
;
3539 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3541 def
= gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, found
));
3543 RTX_UNCHANGING_P (def
) = 1;
3544 /* Mark the symbol_ref as belonging to this constants pool. */
3545 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3546 current_function_uses_const_pool
= 1;
3548 if (outer_function_chain
== 0)
3549 if (GET_CODE (x
) == CONST_DOUBLE
)
3551 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
3553 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
3554 const_double_chain
= x
;
3556 CONST_DOUBLE_MEM (x
) = def
;
3562 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3563 the corresponding pool_constant structure. */
3565 static struct pool_constant
*
3566 find_pool_constant (addr
)
3569 struct pool_sym
*sym
;
3570 char *label
= XSTR (addr
, 0);
3572 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
3573 if (sym
->label
== label
)
3579 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3582 get_pool_constant (addr
)
3585 return (find_pool_constant (addr
))->constant
;
3588 /* Similar, return the mode. */
3591 get_pool_mode (addr
)
3594 return (find_pool_constant (addr
))->mode
;
3597 /* Similar, return the offset in the constant pool. */
3600 get_pool_offset (addr
)
3603 return (find_pool_constant (addr
))->offset
;
3606 /* Return the size of the constant pool. */
3614 /* Write all the constants in the constant pool. */
3617 output_constant_pool (fnname
, fndecl
)
3618 char *fnname ATTRIBUTE_UNUSED
;
3619 tree fndecl ATTRIBUTE_UNUSED
;
3621 struct pool_constant
*pool
;
3623 union real_extract u
;
3625 /* It is possible for gcc to call force_const_mem and then to later
3626 discard the instructions which refer to the constant. In such a
3627 case we do not need to output the constant. */
3628 mark_constant_pool ();
3630 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3631 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3634 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3641 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3642 whose CODE_LABEL has been deleted. This can occur if a jump table
3643 is eliminated by optimization. If so, write a constant of zero
3644 instead. Note that this can also happen by turning the
3645 CODE_LABEL into a NOTE. */
3646 if (((GET_CODE (x
) == LABEL_REF
3647 && (INSN_DELETED_P (XEXP (x
, 0))
3648 || GET_CODE (XEXP (x
, 0)) == NOTE
)))
3649 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
3650 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
3651 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))
3652 || GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == NOTE
)))
3655 /* First switch to correct section. */
3656 #ifdef SELECT_RTX_SECTION
3657 SELECT_RTX_SECTION (pool
->mode
, x
);
3659 readonly_data_section ();
3662 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3663 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3664 pool
->align
, pool
->labelno
, done
);
3667 if (pool
->align
> 1)
3668 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (pool
->align
));
3670 /* Output the label. */
3671 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3673 /* Output the value of the constant itself. */
3674 switch (GET_MODE_CLASS (pool
->mode
))
3677 if (GET_CODE (x
) != CONST_DOUBLE
)
3680 bcopy ((char *) &CONST_DOUBLE_LOW (x
), (char *) &u
, sizeof u
);
3681 assemble_real (u
.d
, pool
->mode
);
3685 case MODE_PARTIAL_INT
:
3686 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
3693 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3699 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3700 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3703 /* Done with this pool. */
3704 first_pool
= last_pool
= 0;
3707 /* Look through the instructions for this function, and mark all the
3708 entries in the constant pool which are actually being used. */
3711 mark_constant_pool ()
3714 struct pool_constant
*pool
;
3716 if (first_pool
== 0)
3719 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3722 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3723 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3724 mark_constants (PATTERN (insn
));
3726 for (insn
= current_function_epilogue_delay_list
;
3728 insn
= XEXP (insn
, 1))
3729 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3730 mark_constants (PATTERN (insn
));
3732 /* It's possible that the only reference to a symbol is in a symbol
3733 that's in the constant pool. This happens in Fortran under some
3734 situations. (When the constant contains the address of another
3735 constant, and only the first is used directly in an insn.)
3736 This is potentially suboptimal if there's ever a possibility of
3737 backwards (in pool order) 2'd level references. However, it's
3738 not clear that 2'd level references can happen. */
3739 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3741 struct pool_sym
*sym
;
3744 /* skip unmarked entries; no insn refers to them. */
3748 label
= XSTR (pool
->constant
, 0);
3750 /* Be sure the symbol's value is marked. */
3751 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
;
3753 if (sym
->label
== label
)
3754 sym
->pool
->mark
= 1;
3755 /* If we didn't find it, there's something truly wrong here, but it
3756 will be announced by the assembler. */
3765 register const char *format_ptr
;
3770 if (GET_CODE (x
) == SYMBOL_REF
)
3772 if (CONSTANT_POOL_ADDRESS_P (x
))
3773 find_pool_constant (x
)->mark
= 1;
3776 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3777 a MEM, but does not constitute a use of that MEM. This is particularly
3778 important inside a nested function, because CONST_DOUBLE_MEM may be
3779 a reference to a MEM in the parent's constant pool. See the comment
3780 in force_const_mem. */
3781 else if (GET_CODE (x
) == CONST_DOUBLE
)
3784 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3785 insns, not any notes that may be attached. We don't want to mark
3786 a constant just because it happens to appear in a REG_EQUIV note. */
3787 if (GET_RTX_CLASS (GET_CODE (x
)) == 'i')
3789 mark_constants (PATTERN (x
));
3793 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3795 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3797 switch (*format_ptr
++)
3800 mark_constants (XEXP (x
, i
));
3804 if (XVEC (x
, i
) != 0)
3808 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3809 mark_constants (XVECEXP (x
, i
, j
));
3828 /* Find all the constants whose addresses are referenced inside of EXP,
3829 and make sure assembler code with a label has been output for each one.
3830 Indicate whether an ADDR_EXPR has been encountered. */
3833 output_addressed_constants (exp
)
3838 switch (TREE_CODE (exp
))
3842 register tree constant
= TREE_OPERAND (exp
, 0);
3844 while (TREE_CODE (constant
) == COMPONENT_REF
)
3846 constant
= TREE_OPERAND (constant
, 0);
3849 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
3850 || TREE_CODE (constant
) == CONSTRUCTOR
)
3851 /* No need to do anything here
3852 for addresses of variables or functions. */
3853 output_constant_def (constant
);
3860 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3861 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3866 case NON_LVALUE_EXPR
:
3867 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3873 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
3874 if (TREE_VALUE (link
) != 0)
3875 reloc
|= output_addressed_constants (TREE_VALUE (link
));
3885 /* Output assembler code for constant EXP to FILE, with no label.
3886 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3887 Assumes output_addressed_constants has been done on EXP already.
3889 Generate exactly SIZE bytes of assembler data, padding at the end
3890 with zeros if necessary. SIZE must always be specified.
3892 SIZE is important for structure constructors,
3893 since trailing members may have been omitted from the constructor.
3894 It is also important for initialization of arrays from string constants
3895 since the full length of the string constant might not be wanted.
3896 It is also needed for initialization of unions, where the initializer's
3897 type is just one member, and that may not be as long as the union.
3899 There a case in which we would fail to output exactly SIZE bytes:
3900 for a structure constructor that wants to produce more than SIZE bytes.
3901 But such constructors will never be generated for any possible input. */
3904 output_constant (exp
, size
)
3908 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
3910 /* Some front-ends use constants other than the standard
3911 language-indepdent varieties, but which may still be output
3912 directly. Give the front-end a chance to convert EXP to a
3913 language-independent representation. */
3914 if (lang_expand_constant
)
3915 exp
= (*lang_expand_constant
) (exp
);
3917 if (size
== 0 || flag_syntax_only
)
3920 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3921 That way we get the constant (we hope) inside it. Also, strip off any
3922 NOP_EXPR that converts between two record, union, array, or set types. */
3923 while ((TREE_CODE (exp
) == NOP_EXPR
3924 && (TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0))
3925 || AGGREGATE_TYPE_P (TREE_TYPE (exp
))))
3926 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3927 exp
= TREE_OPERAND (exp
, 0);
3929 /* Allow a constructor with no elements for any data type.
3930 This means to fill the space with zeros. */
3931 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
3933 assemble_zeros (size
);
3944 case REFERENCE_TYPE
:
3945 /* ??? What about (int)((float)(int)&foo + 4) */
3946 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3947 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3948 exp
= TREE_OPERAND (exp
, 0);
3950 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3951 EXPAND_INITIALIZER
),
3953 error ("initializer for integer value is too complicated");
3958 if (TREE_CODE (exp
) != REAL_CST
)
3959 error ("initializer for floating value is not a floating constant");
3961 assemble_real (TREE_REAL_CST (exp
),
3962 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
3967 output_constant (TREE_REALPART (exp
), size
/ 2);
3968 output_constant (TREE_IMAGPART (exp
), size
/ 2);
3969 size
-= (size
/ 2) * 2;
3973 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3975 output_constructor (exp
, size
);
3978 else if (TREE_CODE (exp
) == STRING_CST
)
3982 if (size
> TREE_STRING_LENGTH (exp
))
3984 excess
= size
- TREE_STRING_LENGTH (exp
);
3985 size
= TREE_STRING_LENGTH (exp
);
3988 assemble_string (TREE_STRING_POINTER (exp
), size
);
3997 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3998 output_constructor (exp
, size
);
4004 if (TREE_CODE (exp
) == INTEGER_CST
)
4005 assemble_integer (expand_expr (exp
, NULL_RTX
,
4006 VOIDmode
, EXPAND_INITIALIZER
),
4008 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4010 unsigned char *buffer
= (unsigned char *) alloca (size
);
4011 if (get_set_constructor_bytes (exp
, buffer
, size
))
4013 assemble_string ((char *) buffer
, size
);
4016 error ("unknown set constructor type");
4024 assemble_zeros (size
);
4028 /* Subroutine of output_constant, used for CONSTRUCTORs
4029 (aggregate constants).
4030 Generate at least SIZE bytes, padding if necessary. */
4033 output_constructor (exp
, size
)
4037 register tree link
, field
= 0;
4038 HOST_WIDE_INT min_index
= 0;
4039 /* Number of bytes output or skipped so far.
4040 In other words, current position within the constructor. */
4041 int total_bytes
= 0;
4042 /* Non-zero means BYTE contains part of a byte, to be output. */
4043 int byte_buffer_in_use
= 0;
4046 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4049 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
4050 field
= TYPE_FIELDS (TREE_TYPE (exp
));
4052 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
4053 && TYPE_DOMAIN (TREE_TYPE (exp
)) != 0)
4055 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp
))));
4057 /* As LINK goes through the elements of the constant,
4058 FIELD goes through the structure fields, if the constant is a structure.
4059 if the constant is a union, then we override this,
4060 by getting the field from the TREE_LIST element.
4061 But the constant could also be an array. Then FIELD is zero.
4063 There is always a maximum of one element in the chain LINK for unions
4064 (even if the initializer in a source program incorrectly contains
4066 for (link
= CONSTRUCTOR_ELTS (exp
);
4068 link
= TREE_CHAIN (link
),
4069 field
= field
? TREE_CHAIN (field
) : 0)
4071 tree val
= TREE_VALUE (link
);
4074 /* the element in a union constructor specifies the proper field. */
4076 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
4077 || TREE_CODE (TREE_TYPE (exp
)) == UNION_TYPE
)
4079 /* if available, use the type given by link */
4080 if (TREE_PURPOSE (link
) != 0)
4081 field
= TREE_PURPOSE (link
);
4084 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
4085 index
= TREE_PURPOSE (link
);
4087 /* Eliminate the marker that makes a cast not be an lvalue. */
4091 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4093 register int fieldsize
4094 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
4095 HOST_WIDE_INT lo_index
= TREE_INT_CST_LOW (TREE_OPERAND (index
, 0));
4096 HOST_WIDE_INT hi_index
= TREE_INT_CST_LOW (TREE_OPERAND (index
, 1));
4097 HOST_WIDE_INT index
;
4098 for (index
= lo_index
; index
<= hi_index
; index
++)
4100 /* Output the element's initial value. */
4102 assemble_zeros (fieldsize
);
4104 output_constant (val
, fieldsize
);
4106 /* Count its size. */
4107 total_bytes
+= fieldsize
;
4110 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4112 /* An element that is not a bit-field. */
4114 register int fieldsize
;
4115 /* Since this structure is static,
4116 we know the positions are constant. */
4117 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
4121 bitpos
= (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val
)))
4123 * (TREE_INT_CST_LOW (index
) - min_index
));
4125 /* Output any buffered-up bit-fields preceding this element. */
4126 if (byte_buffer_in_use
)
4128 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4130 byte_buffer_in_use
= 0;
4133 /* Advance to offset of this element.
4134 Note no alignment needed in an array, since that is guaranteed
4135 if each element has the proper size. */
4136 if ((field
!= 0 || index
!= 0) && bitpos
!= total_bytes
)
4138 assemble_zeros (bitpos
- total_bytes
);
4139 total_bytes
= bitpos
;
4142 /* Determine size this element should occupy. */
4145 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
4147 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
4149 /* This avoids overflow trouble. */
4150 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
4152 size_int (BITS_PER_UNIT
));
4153 fieldsize
= TREE_INT_CST_LOW (size_tree
);
4157 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
4158 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
4162 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
4164 /* Output the element's initial value. */
4166 assemble_zeros (fieldsize
);
4168 output_constant (val
, fieldsize
);
4170 /* Count its size. */
4171 total_bytes
+= fieldsize
;
4173 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4174 error ("invalid initial value for member `%s'",
4175 IDENTIFIER_POINTER (DECL_NAME (field
)));
4178 /* Element that is a bit-field. */
4180 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
4182 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
4185 val
= integer_zero_node
;
4187 /* If this field does not start in this (or, next) byte,
4189 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4191 /* Output remnant of any bit field in previous bytes. */
4192 if (byte_buffer_in_use
)
4194 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4196 byte_buffer_in_use
= 0;
4199 /* If still not at proper byte, advance to there. */
4200 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4202 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4203 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4207 if (! byte_buffer_in_use
)
4210 /* We must split the element into pieces that fall within
4211 separate bytes, and combine each byte with previous or
4212 following bit-fields. */
4214 /* next_offset is the offset n fbits from the beginning of
4215 the structure to the next bit of this element to be processed.
4216 end_offset is the offset of the first bit past the end of
4218 while (next_offset
< end_offset
)
4222 HOST_WIDE_INT value
;
4223 int next_byte
= next_offset
/ BITS_PER_UNIT
;
4224 int next_bit
= next_offset
% BITS_PER_UNIT
;
4226 /* Advance from byte to byte
4227 within this element when necessary. */
4228 while (next_byte
!= total_bytes
)
4230 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4235 /* Number of bits we can process at once
4236 (all part of the same byte). */
4237 this_time
= MIN (end_offset
- next_offset
,
4238 BITS_PER_UNIT
- next_bit
);
4239 if (BYTES_BIG_ENDIAN
)
4241 /* On big-endian machine, take the most significant bits
4242 first (of the bits that are significant)
4243 and put them into bytes from the most significant end. */
4244 shift
= end_offset
- next_offset
- this_time
;
4245 /* Don't try to take a bunch of bits that cross
4246 the word boundary in the INTEGER_CST. */
4247 if (shift
< HOST_BITS_PER_WIDE_INT
4248 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4250 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
4251 shift
= HOST_BITS_PER_WIDE_INT
;
4254 /* Now get the bits from the appropriate constant word. */
4255 if (shift
< HOST_BITS_PER_WIDE_INT
)
4257 value
= TREE_INT_CST_LOW (val
);
4259 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4261 value
= TREE_INT_CST_HIGH (val
);
4262 shift
-= HOST_BITS_PER_WIDE_INT
;
4266 byte
|= (((value
>> shift
)
4267 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
4268 << (BITS_PER_UNIT
- this_time
- next_bit
));
4272 /* On little-endian machines,
4273 take first the least significant bits of the value
4274 and pack them starting at the least significant
4275 bits of the bytes. */
4276 shift
= (next_offset
4277 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
4278 /* Don't try to take a bunch of bits that cross
4279 the word boundary in the INTEGER_CST. */
4280 if (shift
< HOST_BITS_PER_WIDE_INT
4281 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4283 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
4284 shift
= HOST_BITS_PER_WIDE_INT
;
4287 /* Now get the bits from the appropriate constant word. */
4288 if (shift
< HOST_BITS_PER_WIDE_INT
)
4289 value
= TREE_INT_CST_LOW (val
);
4290 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4292 value
= TREE_INT_CST_HIGH (val
);
4293 shift
-= HOST_BITS_PER_WIDE_INT
;
4297 byte
|= (((value
>> shift
)
4298 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
4301 next_offset
+= this_time
;
4302 byte_buffer_in_use
= 1;
4306 if (byte_buffer_in_use
)
4308 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4311 if (total_bytes
< size
)
4312 assemble_zeros (size
- total_bytes
);
4315 #ifdef HANDLE_PRAGMA_WEAK
4316 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4317 associatd with NAME. */
4320 add_weak (name
, value
)
4324 struct weak_syms
*weak
;
4326 weak
= (struct weak_syms
*) permalloc (sizeof (struct weak_syms
));
4331 weak
->next
= weak_decls
;
4333 weak
->value
= value
;
4338 #endif /* HANDLE_PRAGMA_WEAK */
4340 /* Declare DECL to be a weak symbol. */
4346 if (! TREE_PUBLIC (decl
))
4347 error_with_decl (decl
, "weak declaration of `%s' must be public");
4348 else if (TREE_ASM_WRITTEN (decl
))
4349 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4350 else if (SUPPORTS_WEAK
)
4351 DECL_WEAK (decl
) = 1;
4352 #ifdef HANDLE_PRAGMA_WEAK
4353 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), NULL
);
4357 /* Emit any pending weak declarations. */
4359 #ifdef HANDLE_PRAGMA_WEAK
4360 struct weak_syms
* weak_decls
;
4366 #ifdef HANDLE_PRAGMA_WEAK
4367 if (HANDLE_PRAGMA_WEAK
)
4369 struct weak_syms
*t
;
4370 for (t
= weak_decls
; t
; t
= t
->next
)
4374 ASM_WEAKEN_LABEL (asm_out_file
, t
->name
);
4376 ASM_OUTPUT_DEF (asm_out_file
, t
->name
, t
->value
);
4383 /* Remove NAME from the pending list of weak symbols. This prevents
4384 the compiler from emitting multiple .weak directives which confuses
4387 remove_from_pending_weak_list (name
)
4388 char *name ATTRIBUTE_UNUSED
;
4390 #ifdef HANDLE_PRAGMA_WEAK
4391 if (HANDLE_PRAGMA_WEAK
)
4393 struct weak_syms
*t
;
4394 for (t
= weak_decls
; t
; t
= t
->next
)
4396 if (t
->name
&& strcmp (name
, t
->name
) == 0)
4404 assemble_alias (decl
, target
)
4405 tree decl
, target ATTRIBUTE_UNUSED
;
4409 make_decl_rtl (decl
, (char *) 0, 1);
4410 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4412 #ifdef ASM_OUTPUT_DEF
4413 /* Make name accessible from other files, if appropriate. */
4415 if (TREE_PUBLIC (decl
))
4417 #ifdef ASM_WEAKEN_LABEL
4418 if (DECL_WEAK (decl
))
4420 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4421 /* Remove this function from the pending weak list so that
4422 we do not emit multiple .weak directives for it. */
4423 remove_from_pending_weak_list
4424 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
4428 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4431 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4432 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4434 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4436 TREE_ASM_WRITTEN (decl
) = 1;
4438 #ifdef ASM_OUTPUT_WEAK_ALIAS
4439 if (! DECL_WEAK (decl
))
4440 warning ("only weak aliases are supported in this configuration");
4442 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4443 TREE_ASM_WRITTEN (decl
) = 1;
4445 warning ("alias definitions not supported in this configuration; ignored");
4450 /* This determines whether or not we support link-once semantics. */
4451 #ifndef SUPPORTS_ONE_ONLY
4452 #ifdef MAKE_DECL_ONE_ONLY
4453 #define SUPPORTS_ONE_ONLY 1
4455 #define SUPPORTS_ONE_ONLY 0
4459 /* Returns 1 if the target configuration supports defining public symbols
4460 so that one of them will be chosen at link time instead of generating a
4461 multiply-defined symbol error, whether through the use of weak symbols or
4462 a target-specific mechanism for having duplicates discarded. */
4465 supports_one_only ()
4467 if (SUPPORTS_ONE_ONLY
)
4469 return SUPPORTS_WEAK
;
4472 /* Set up DECL as a public symbol that can be defined in multiple
4473 translation units without generating a linker error. */
4476 make_decl_one_only (decl
)
4479 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
4482 TREE_PUBLIC (decl
) = 1;
4484 if (TREE_CODE (decl
) == VAR_DECL
4485 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4486 DECL_COMMON (decl
) = 1;
4487 else if (SUPPORTS_ONE_ONLY
)
4489 #ifdef MAKE_DECL_ONE_ONLY
4490 MAKE_DECL_ONE_ONLY (decl
);
4492 DECL_ONE_ONLY (decl
) = 1;
4494 else if (SUPPORTS_WEAK
)
4495 DECL_WEAK (decl
) = 1;