1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
38 #include "hard-reg-set.h"
51 #ifdef XCOFF_DEBUGGING_INFO
55 #ifndef TRAMPOLINE_ALIGNMENT
56 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
60 #define ASM_STABS_OP "\t.stabs\t"
63 /* Define the prefix to use when check_memory_usage_flag is enable. */
64 #ifdef NO_DOLLAR_IN_LABEL
65 #ifdef NO_DOT_IN_LABEL
66 #define CHKR_PREFIX "chkr_prefix_"
67 #else /* !NO_DOT_IN_LABEL */
68 #define CHKR_PREFIX "chkr."
70 #else /* !NO_DOLLAR_IN_LABEL */
71 #define CHKR_PREFIX "chkr$"
73 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
75 /* File in which assembler code is being written. */
77 extern FILE *asm_out_file
;
79 /* The (assembler) name of the first globally-visible object output. */
80 const char *first_global_object_name
;
81 const char *weak_global_object_name
;
83 extern struct obstack permanent_obstack
;
84 #define obstack_chunk_alloc xmalloc
87 struct constant_descriptor
;
91 #define MAX_RTX_HASH_TABLE 61
95 /* Hash facility for making memory-constants
96 from constant rtl-expressions. It is used on RISC machines
97 where immediate integer arguments and constant addresses are restricted
98 so that such constants must be stored in memory.
100 This pool of constants is reinitialized for each function
101 so each function gets its own constants-pool that comes right before
103 struct constant_descriptor
**x_const_rtx_hash_table
;
104 struct pool_constant
**x_const_rtx_sym_hash_table
;
106 /* Pointers to first and last constant in pool. */
107 struct pool_constant
*x_first_pool
, *x_last_pool
;
109 /* Current offset in constant pool (does not include any machine-specific
113 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
114 They are chained through the CONST_DOUBLE_CHAIN.
115 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
116 In that case, CONST_DOUBLE_MEM is either a MEM,
117 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
118 rtx x_const_double_chain
;
121 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
122 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
123 #define first_pool (cfun->varasm->x_first_pool)
124 #define last_pool (cfun->varasm->x_last_pool)
125 #define pool_offset (cfun->varasm->x_pool_offset)
126 #define const_double_chain (cfun->varasm->x_const_double_chain)
128 /* Number for making the label on the next
129 constant that is stored in memory. */
133 /* Number for making the label on the next
134 static variable internal to a function. */
138 /* Carry information from ASM_DECLARE_OBJECT_NAME
139 to ASM_FINISH_DECLARE_OBJECT. */
141 int size_directive_output
;
143 /* The last decl for which assemble_variable was called,
144 if it did ASM_DECLARE_OBJECT_NAME.
145 If the last call to assemble_variable didn't do that,
148 tree last_assemble_variable_decl
;
150 static const char *strip_reg_name
PARAMS ((const char *));
151 static int contains_pointers_p
PARAMS ((tree
));
152 static void decode_addr_const
PARAMS ((tree
, struct addr_const
*));
153 static int const_hash
PARAMS ((tree
));
154 static int compare_constant
PARAMS ((tree
,
155 struct constant_descriptor
*));
156 static const unsigned char *compare_constant_1
PARAMS ((tree
, const unsigned char *));
157 static struct constant_descriptor
*record_constant
PARAMS ((tree
));
158 static void record_constant_1
PARAMS ((tree
));
159 static tree copy_constant
PARAMS ((tree
));
160 static void output_constant_def_contents
PARAMS ((tree
, int, int));
161 static void decode_rtx_const
PARAMS ((enum machine_mode
, rtx
,
162 struct rtx_const
*));
163 static int const_hash_rtx
PARAMS ((enum machine_mode
, rtx
));
164 static int compare_constant_rtx
PARAMS ((enum machine_mode
, rtx
,
165 struct constant_descriptor
*));
166 static struct constant_descriptor
*record_constant_rtx
PARAMS ((enum machine_mode
,
168 static struct pool_constant
*find_pool_constant
PARAMS ((struct function
*, rtx
));
169 static void mark_constant_pool
PARAMS ((void));
170 static void mark_constants
PARAMS ((rtx
));
171 static int output_addressed_constants
PARAMS ((tree
));
172 static void output_after_function_constants
PARAMS ((void));
173 static void output_constructor
PARAMS ((tree
, int));
174 #ifdef ASM_WEAKEN_LABEL
175 static void remove_from_pending_weak_list
PARAMS ((const char *));
177 #ifdef ASM_OUTPUT_BSS
178 static void asm_output_bss
PARAMS ((FILE *, tree
, const char *, int, int));
180 #ifdef BSS_SECTION_ASM_OP
181 #ifdef ASM_OUTPUT_ALIGNED_BSS
182 static void asm_output_aligned_bss
PARAMS ((FILE *, tree
, const char *,
185 #endif /* BSS_SECTION_ASM_OP */
186 static void mark_pool_constant
PARAMS ((struct pool_constant
*));
187 static void mark_const_hash_entry
PARAMS ((void *));
188 static void asm_emit_uninitialised
PARAMS ((tree
, const char*, int, int));
190 static enum in_section
{ no_section
, in_text
, in_data
, in_named
191 #ifdef BSS_SECTION_ASM_OP
194 #ifdef EH_FRAME_SECTION_ASM_OP
197 #ifdef EXTRA_SECTIONS
200 } in_section
= no_section
;
202 /* Return a non-zero value if DECL has a section attribute. */
203 #ifndef IN_NAMED_SECTION
204 #define IN_NAMED_SECTION(DECL) \
205 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
206 && DECL_SECTION_NAME (DECL) != NULL_TREE)
209 /* Text of section name when in_section == in_named. */
210 static char *in_named_name
;
212 /* Define functions like text_section for any extra sections. */
213 #ifdef EXTRA_SECTION_FUNCTIONS
214 EXTRA_SECTION_FUNCTIONS
217 /* Tell assembler to switch to text section. */
222 if (in_section
!= in_text
)
224 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
225 in_section
= in_text
;
229 /* Tell assembler to switch to data section. */
234 if (in_section
!= in_data
)
236 if (flag_shared_data
)
238 #ifdef SHARED_SECTION_ASM_OP
239 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
241 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
245 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
247 in_section
= in_data
;
250 /* Tell assembler to ALWAYS switch to data section, in case
251 it's not sure where it it. */
254 force_data_section ()
256 in_section
= no_section
;
260 /* Tell assembler to switch to read-only data section. This is normally
264 readonly_data_section ()
266 #ifdef READONLY_DATA_SECTION
267 READONLY_DATA_SECTION (); /* Note this can call data_section. */
273 /* Determine if we're in the text section. */
278 return in_section
== in_text
;
281 /* Determine if we're in the data section. */
286 return in_section
== in_data
;
289 /* Tell assembler to change to section NAME for DECL.
290 If DECL is NULL, just switch to section NAME.
291 If NAME is NULL, get the name from DECL.
292 If RELOC is 1, the initializer for DECL contains relocs. */
295 named_section (decl
, name
, reloc
)
298 int reloc ATTRIBUTE_UNUSED
;
300 if (decl
!= NULL_TREE
&& !DECL_P (decl
))
303 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
305 if (in_section
!= in_named
|| strcmp (name
, in_named_name
))
307 #ifdef ASM_OUTPUT_SECTION_NAME
308 ASM_OUTPUT_SECTION_NAME (asm_out_file
, decl
, name
, reloc
);
310 /* Section attributes are not supported if this macro isn't provided -
311 some host formats don't support them at all. The front-end should
312 already have flagged this as an error. */
316 in_named_name
= ggc_alloc_string (name
, -1);
317 in_section
= in_named
;
321 #ifdef ASM_OUTPUT_SECTION_NAME
322 #ifndef UNIQUE_SECTION
323 #define UNIQUE_SECTION(DECL,RELOC) \
329 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
330 /* Strip off any encoding in name. */ \
331 STRIP_NAME_ENCODING (name, name); \
333 len = strlen (name) + 1; \
334 string = alloca (len + 1); \
335 sprintf (string, ".%s", name); \
337 DECL_SECTION_NAME (DECL) = build_string (len, string); \
340 #ifndef UNIQUE_SECTION_P
341 #define UNIQUE_SECTION_P(DECL) 0
345 #ifdef BSS_SECTION_ASM_OP
347 /* Tell the assembler to switch to the bss section. */
352 if (in_section
!= in_bss
)
354 #ifdef SHARED_BSS_SECTION_ASM_OP
355 if (flag_shared_data
)
356 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
359 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
365 #ifdef ASM_OUTPUT_BSS
367 /* Utility function for ASM_OUTPUT_BSS for targets to use if
368 they don't support alignments in .bss.
369 ??? It is believed that this function will work in most cases so such
370 support is localized here. */
373 asm_output_bss (file
, decl
, name
, size
, rounded
)
375 tree decl ATTRIBUTE_UNUSED
;
377 int size ATTRIBUTE_UNUSED
, rounded
;
379 ASM_GLOBALIZE_LABEL (file
, name
);
381 #ifdef ASM_DECLARE_OBJECT_NAME
382 last_assemble_variable_decl
= decl
;
383 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
385 /* Standard thing is just output label for the object. */
386 ASM_OUTPUT_LABEL (file
, name
);
387 #endif /* ASM_DECLARE_OBJECT_NAME */
388 ASM_OUTPUT_SKIP (file
, rounded
);
393 #ifdef ASM_OUTPUT_ALIGNED_BSS
395 /* Utility function for targets to use in implementing
396 ASM_OUTPUT_ALIGNED_BSS.
397 ??? It is believed that this function will work in most cases so such
398 support is localized here. */
401 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
407 ASM_GLOBALIZE_LABEL (file
, name
);
409 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
410 #ifdef ASM_DECLARE_OBJECT_NAME
411 last_assemble_variable_decl
= decl
;
412 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
414 /* Standard thing is just output label for the object. */
415 ASM_OUTPUT_LABEL (file
, name
);
416 #endif /* ASM_DECLARE_OBJECT_NAME */
417 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
422 #endif /* BSS_SECTION_ASM_OP */
424 #ifdef EH_FRAME_SECTION_ASM_OP
428 if (in_section
!= in_eh_frame
)
430 fprintf (asm_out_file
, "%s\n", EH_FRAME_SECTION_ASM_OP
);
431 in_section
= in_eh_frame
;
436 /* Switch to the section for function DECL.
438 If DECL is NULL_TREE, switch to the text section.
439 ??? It's not clear that we will ever be passed NULL_TREE, but it's
440 safer to handle it. */
443 function_section (decl
)
446 if (decl
!= NULL_TREE
447 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
448 named_section (decl
, (char *) 0, 0);
453 /* Switch to section for variable DECL.
455 RELOC is the `reloc' argument to SELECT_SECTION. */
458 variable_section (decl
, reloc
)
462 if (IN_NAMED_SECTION (decl
))
463 named_section (decl
, NULL
, reloc
);
466 /* C++ can have const variables that get initialized from constructors,
467 and thus can not be in a readonly section. We prevent this by
468 verifying that the initial value is constant for objects put in a
471 error_mark_node is used by the C front end to indicate that the
472 initializer has not been seen yet. In this case, we assume that
473 the initializer must be constant.
475 C++ uses error_mark_node for variables that have complicated
476 initializers, but these variables go in BSS so we won't be called
479 #ifdef SELECT_SECTION
480 SELECT_SECTION (decl
, reloc
);
482 if (DECL_READONLY_SECTION (decl
, reloc
))
483 readonly_data_section ();
490 /* Tell assembler to switch to the section for the exception handling
496 #if defined (EXCEPTION_SECTION)
497 EXCEPTION_SECTION ();
499 #ifdef ASM_OUTPUT_SECTION_NAME
500 named_section (NULL_TREE
, ".gcc_except_table", 0);
505 readonly_data_section ();
510 /* Create the rtl to represent a function, for a function definition.
511 DECL is a FUNCTION_DECL node which describes which function.
512 The rtl is stored into DECL. */
515 make_function_rtl (decl
)
519 const char *new_name
;
521 if (DECL_RTL (decl
) != 0)
523 /* ??? Another way to do this would be to do what halfpic.c does
524 and maintain a hashed table of such critters. */
525 /* ??? Another way to do this would be to pass a flag bit to
526 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
527 /* Let the target reassign the RTL if it wants.
528 This is necessary, for example, when one machine specific
529 decl attribute overrides another. */
530 #ifdef REDO_SECTION_INFO_P
531 if (REDO_SECTION_INFO_P (decl
))
532 ENCODE_SECTION_INFO (decl
);
537 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
540 /* Rename a nested function to avoid conflicts, unless it's a member of
541 a local class, in which case the class name is already unique. */
542 if (decl_function_context (decl
) != 0
543 && ! TYPE_P (DECL_CONTEXT (decl
))
544 && DECL_INITIAL (decl
) != 0
545 && DECL_RTL (decl
) == 0)
548 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
552 /* When -fprefix-function-name is used, every function name is
553 prefixed. Even static functions are prefixed because they
554 could be declared latter. Note that a nested function name
556 else if (flag_prefix_function_name
)
558 size_t name_len
= IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl
));
561 pname
= alloca (name_len
+ CHKR_PREFIX_SIZE
+ 1);
562 memcpy (pname
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
);
563 memcpy (pname
+ CHKR_PREFIX_SIZE
, name
, name_len
+ 1);
567 if (name
!= new_name
)
569 DECL_ASSEMBLER_NAME (decl
) = get_identifier (new_name
);
570 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
574 = gen_rtx_MEM (DECL_MODE (decl
),
575 gen_rtx_SYMBOL_REF (Pmode
, name
));
577 /* Optionally set flags or add text to the name to record
578 information such as that it is a function name. If the name
579 is changed, the macro ASM_OUTPUT_LABELREF will have to know
580 how to strip this information. */
581 #ifdef ENCODE_SECTION_INFO
582 ENCODE_SECTION_INFO (decl
);
587 /* Given NAME, a putative register name, discard any customary prefixes. */
590 strip_reg_name (name
)
593 #ifdef REGISTER_PREFIX
594 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
595 name
+= strlen (REGISTER_PREFIX
);
597 if (name
[0] == '%' || name
[0] == '#')
602 /* Decode an `asm' spec for a declaration as a register name.
603 Return the register number, or -1 if nothing specified,
604 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
605 or -3 if ASMSPEC is `cc' and is not recognized,
606 or -4 if ASMSPEC is `memory' and is not recognized.
607 Accept an exact spelling or a decimal number.
608 Prefixes such as % are optional. */
611 decode_reg_name (asmspec
)
618 /* Get rid of confusing prefixes. */
619 asmspec
= strip_reg_name (asmspec
);
621 /* Allow a decimal number as a "register name". */
622 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
623 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
625 if (asmspec
[0] != 0 && i
< 0)
628 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
634 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
636 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
639 #ifdef ADDITIONAL_REGISTER_NAMES
641 static struct { const char *name
; int number
; } table
[]
642 = ADDITIONAL_REGISTER_NAMES
;
644 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
645 if (! strcmp (asmspec
, table
[i
].name
))
646 return table
[i
].number
;
648 #endif /* ADDITIONAL_REGISTER_NAMES */
650 if (!strcmp (asmspec
, "memory"))
653 if (!strcmp (asmspec
, "cc"))
662 /* Create the DECL_RTL for a declaration for a static or external variable
663 or static or external function.
664 ASMSPEC, if not 0, is the string which the user specified
665 as the assembler symbol name.
666 TOP_LEVEL is nonzero if this is a file-scope variable.
668 This is never called for PARM_DECL nodes. */
671 make_decl_rtl (decl
, asmspec
, top_level
)
676 const char *name
= 0;
677 const char *new_name
= 0;
680 /* For a duplicate declaration, we can be called twice on the
681 same DECL node. Don't discard the RTL already made. */
682 if (DECL_RTL (decl
) != 0)
684 /* If the old RTL had the wrong mode, fix the mode. */
685 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
687 rtx rtl
= DECL_RTL (decl
);
688 PUT_MODE (rtl
, DECL_MODE (decl
));
691 /* ??? Another way to do this would be to do what halfpic.c does
692 and maintain a hashed table of such critters. */
693 /* ??? Another way to do this would be to pass a flag bit to
694 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
695 /* Let the target reassign the RTL if it wants.
696 This is necessary, for example, when one machine specific
697 decl attribute overrides another. */
698 #ifdef REDO_SECTION_INFO_P
699 if (REDO_SECTION_INFO_P (decl
))
700 ENCODE_SECTION_INFO (decl
);
705 new_name
= name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
707 reg_number
= decode_reg_name (asmspec
);
708 if (reg_number
== -2)
710 /* ASMSPEC is given, and not the name of a register. Mark the
711 name with a star so assemble_name won't munge it. */
712 char *starred
= alloca (strlen (asmspec
) + 2);
714 strcpy (starred
+ 1, asmspec
);
718 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
720 /* First detect errors in declaring global registers. */
721 if (reg_number
== -1)
722 error_with_decl (decl
, "register name not specified for `%s'");
723 else if (reg_number
< 0)
724 error_with_decl (decl
, "invalid register name for `%s'");
725 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
726 error_with_decl (decl
,
727 "data type of `%s' isn't suitable for a register");
728 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
729 error_with_decl (decl
,
730 "register specified for `%s' isn't suitable for data type");
731 /* Now handle properly declared static register variables. */
736 if (DECL_INITIAL (decl
) != 0 && top_level
)
738 DECL_INITIAL (decl
) = 0;
739 error ("global register variable has initial value");
741 if (TREE_THIS_VOLATILE (decl
))
742 warning ("volatile register variables don't work as you might wish");
744 /* If the user specified one of the eliminables registers here,
745 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
746 confused with that register and be eliminated. Although this
747 usage is somewhat suspect, we nevertheless use the following
748 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
751 = gen_rtx_REG (DECL_MODE (decl
), FIRST_PSEUDO_REGISTER
);
752 REGNO (DECL_RTL (decl
)) = reg_number
;
753 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
757 /* Make this register global, so not usable for anything
759 #ifdef ASM_DECLARE_REGISTER_GLOBAL
760 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
762 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
764 globalize_reg (reg_number
+ --nregs
);
767 /* As a register variable, it has no section. */
772 /* Now handle ordinary static variables and functions (in memory).
773 Also handle vars declared register invalidly. */
775 if (reg_number
>= 0 || reg_number
== -3)
776 error_with_decl (decl
,
777 "register name given for non-register variable `%s'");
779 /* Specifying a section attribute on a variable forces it into a
780 non-.bss section, and thus it cannot be common. */
781 if (TREE_CODE (decl
) == VAR_DECL
782 && DECL_SECTION_NAME (decl
) != NULL_TREE
783 && DECL_INITIAL (decl
) == NULL_TREE
784 && DECL_COMMON (decl
))
785 DECL_COMMON (decl
) = 0;
787 /* Can't use just the variable's own name for a variable
788 whose scope is less than the whole file, unless it's a member
789 of a local class (which will already be unambiguous).
790 Concatenate a distinguishing number. */
791 if (!top_level
&& !TREE_PUBLIC (decl
)
792 && ! (DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
)))
796 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
801 /* When -fprefix-function-name is used, the functions
802 names are prefixed. Only nested function names are not
804 else if (flag_prefix_function_name
&& TREE_CODE (decl
) == FUNCTION_DECL
)
806 size_t name_len
= IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl
));
809 pname
= alloca (name_len
+ CHKR_PREFIX_SIZE
+ 1);
810 memcpy (pname
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
);
811 memcpy (pname
+ CHKR_PREFIX_SIZE
, name
, name_len
+ 1);
815 if (name
!= new_name
)
817 DECL_ASSEMBLER_NAME (decl
) = get_identifier (new_name
);
818 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
821 /* If this variable is to be treated as volatile, show its
822 tree node has side effects. */
823 if ((flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
824 && TREE_PUBLIC (decl
))
825 || ((flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
826 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))))
827 TREE_SIDE_EFFECTS (decl
) = 1;
829 DECL_RTL (decl
) = gen_rtx_MEM (DECL_MODE (decl
),
830 gen_rtx_SYMBOL_REF (Pmode
, name
));
831 if (TREE_CODE (decl
) != FUNCTION_DECL
)
832 set_mem_attributes (DECL_RTL (decl
), decl
, 1);
834 /* Optionally set flags or add text to the name to record information
835 such as that it is a function name.
836 If the name is changed, the macro ASM_OUTPUT_LABELREF
837 will have to know how to strip this information. */
838 #ifdef ENCODE_SECTION_INFO
839 ENCODE_SECTION_INFO (decl
);
843 /* Make the rtl for variable VAR be volatile.
844 Use this only for static variables. */
847 make_var_volatile (var
)
850 if (GET_CODE (DECL_RTL (var
)) != MEM
)
853 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
856 /* Output alignment directive to align for constant expression EXP. */
859 assemble_constant_align (exp
)
864 /* Align the location counter as required by EXP's data type. */
865 align
= TYPE_ALIGN (TREE_TYPE (exp
));
866 #ifdef CONSTANT_ALIGNMENT
867 align
= CONSTANT_ALIGNMENT (exp
, align
);
870 if (align
> BITS_PER_UNIT
)
871 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
874 /* Output a string of literal assembler code
875 for an `asm' keyword used between functions. */
878 assemble_asm (string
)
883 if (TREE_CODE (string
) == ADDR_EXPR
)
884 string
= TREE_OPERAND (string
, 0);
886 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
889 #if 0 /* This should no longer be needed, because
890 flag_gnu_linker should be 0 on these systems,
891 which should prevent any output
892 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
893 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
894 #ifndef ASM_OUTPUT_CONSTRUCTOR
895 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
897 #ifndef ASM_OUTPUT_DESTRUCTOR
898 #define ASM_OUTPUT_DESTRUCTOR(file, name)
903 /* Record an element in the table of global destructors.
904 How this is done depends on what sort of assembler and linker
907 NAME should be the name of a global function to be called
908 at exit time. This name is output using assemble_name. */
911 assemble_destructor (name
)
914 #ifdef ASM_OUTPUT_DESTRUCTOR
915 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
919 /* Now tell GNU LD that this is part of the static destructor set. */
920 /* This code works for any machine provided you use GNU as/ld. */
921 fprintf (asm_out_file
, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
922 assemble_name (asm_out_file
, name
);
923 fputc ('\n', asm_out_file
);
928 /* Likewise for global constructors. */
931 assemble_constructor (name
)
934 #ifdef ASM_OUTPUT_CONSTRUCTOR
935 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
939 /* Now tell GNU LD that this is part of the static constructor set. */
940 /* This code works for any machine provided you use GNU as/ld. */
941 fprintf (asm_out_file
, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
942 assemble_name (asm_out_file
, name
);
943 fputc ('\n', asm_out_file
);
948 /* Likewise for entries we want to record for garbage collection.
949 Garbage collection is still under development. */
952 assemble_gc_entry (name
)
955 #ifdef ASM_OUTPUT_GC_ENTRY
956 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
960 /* Now tell GNU LD that this is part of the static constructor set. */
961 fprintf (asm_out_file
, "%s\"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
962 assemble_name (asm_out_file
, name
);
963 fputc ('\n', asm_out_file
);
968 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
969 a non-zero value if the constant pool should be output before the
970 start of the function, or a zero value if the pool should output
971 after the end of the function. The default is to put it before the
974 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
975 #define CONSTANT_POOL_BEFORE_FUNCTION 1
978 /* Output assembler code for the constant pool of a function and associated
979 with defining the name of the function. DECL describes the function.
980 NAME is the function's name. For the constant pool, we use the current
981 constant pool data. */
984 assemble_start_function (decl
, fnname
)
990 /* The following code does not need preprocessing in the assembler. */
994 if (CONSTANT_POOL_BEFORE_FUNCTION
)
995 output_constant_pool (fnname
, decl
);
997 #ifdef ASM_OUTPUT_SECTION_NAME
998 /* If the function is to be put in its own section and it's not in a section
999 already, indicate so. */
1000 if ((flag_function_sections
1001 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1002 || UNIQUE_SECTION_P (decl
))
1003 UNIQUE_SECTION (decl
, 0);
1006 function_section (decl
);
1008 /* Tell assembler to move to target machine's alignment for functions. */
1009 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1011 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1013 /* Handle a user-specified function alignment.
1014 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1015 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1016 if (align_functions_log
> align
)
1018 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1019 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1020 align_functions_log
, align_functions
-1);
1022 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1026 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1027 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1030 #ifdef SDB_DEBUGGING_INFO
1031 /* Output SDB definition of the function. */
1032 if (write_symbols
== SDB_DEBUG
)
1033 sdbout_mark_begin_function ();
1036 #ifdef DBX_DEBUGGING_INFO
1037 /* Output DBX definition of the function. */
1038 if (write_symbols
== DBX_DEBUG
)
1039 dbxout_begin_function (decl
);
1042 /* Make function name accessible from other files, if appropriate. */
1044 if (TREE_PUBLIC (decl
))
1046 if (! first_global_object_name
)
1051 STRIP_NAME_ENCODING (p
, fnname
);
1052 name
= permalloc (strlen (p
) + 1);
1055 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1056 first_global_object_name
= name
;
1058 weak_global_object_name
= name
;
1061 #ifdef ASM_WEAKEN_LABEL
1062 if (DECL_WEAK (decl
))
1064 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
1065 /* Remove this function from the pending weak list so that
1066 we do not emit multiple .weak directives for it. */
1067 remove_from_pending_weak_list
1068 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1072 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
1075 /* Do any machine/system dependent processing of the function name */
1076 #ifdef ASM_DECLARE_FUNCTION_NAME
1077 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1079 /* Standard thing is just output label for the function. */
1080 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1081 #endif /* ASM_DECLARE_FUNCTION_NAME */
1084 /* Output assembler code associated with defining the size of the
1085 function. DECL describes the function. NAME is the function's name. */
1088 assemble_end_function (decl
, fnname
)
1092 #ifdef ASM_DECLARE_FUNCTION_SIZE
1093 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1095 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1097 output_constant_pool (fnname
, decl
);
1098 function_section (decl
); /* need to switch back */
1101 /* Output any constants which should appear after the function. */
1102 output_after_function_constants ();
1105 /* Assemble code to leave SIZE bytes of zeros. */
1108 assemble_zeros (size
)
1111 /* Do no output if -fsyntax-only. */
1112 if (flag_syntax_only
)
1115 #ifdef ASM_NO_SKIP_IN_TEXT
1116 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1117 so we must output 0s explicitly in the text section. */
1118 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1122 for (i
= 0; i
< size
- 20; i
+= 20)
1125 fprintf (asm_out_file
,
1126 "%s0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP
);
1128 fprintf (asm_out_file
,
1129 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1135 fprintf (asm_out_file
, "%s0", ASM_BYTE_OP
);
1137 fprintf (asm_out_file
, "\tbyte 0");
1140 for (; i
< size
; i
++)
1141 fprintf (asm_out_file
, ",0");
1142 fprintf (asm_out_file
, "\n");
1148 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1151 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1154 assemble_align (align
)
1157 if (align
> BITS_PER_UNIT
)
1158 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1161 /* Assemble a string constant with the specified C string as contents. */
1164 assemble_string (p
, size
)
1171 /* If the string is very long, split it up. */
1175 int thissize
= size
- pos
;
1176 if (thissize
> maximum
)
1179 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1187 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1188 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1189 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1191 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1192 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1193 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1195 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1196 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1200 #if defined ASM_OUTPUT_ALIGNED_BSS
1201 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1202 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1204 #if defined ASM_OUTPUT_BSS
1205 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1206 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1212 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1213 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1214 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1216 #if defined ASM_OUTPUT_ALIGNED_COMMON
1217 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1218 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1220 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1221 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1226 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1229 int size ATTRIBUTE_UNUSED
;
1230 int rounded ATTRIBUTE_UNUSED
;
1238 destination
= asm_dest_local
;
1240 if (TREE_PUBLIC (decl
))
1242 #if defined ASM_EMIT_BSS
1243 if (! DECL_COMMON (decl
))
1244 destination
= asm_dest_bss
;
1247 destination
= asm_dest_common
;
1250 if (flag_shared_data
)
1252 switch (destination
)
1254 #ifdef ASM_OUTPUT_SHARED_BSS
1256 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1259 #ifdef ASM_OUTPUT_SHARED_COMMON
1260 case asm_dest_common
:
1261 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1264 #ifdef ASM_OUTPUT_SHARED_LOCAL
1265 case asm_dest_local
:
1266 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1274 #ifdef ASM_OUTPUT_SECTION_NAME
1275 /* We already know that DECL_SECTION_NAME() == NULL. */
1276 if (flag_data_sections
!= 0 || UNIQUE_SECTION_P (decl
))
1277 UNIQUE_SECTION (decl
, 0);
1280 switch (destination
)
1284 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1287 case asm_dest_common
:
1288 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1290 case asm_dest_local
:
1291 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1300 /* Assemble everything that is needed for a variable or function declaration.
1301 Not used for automatic variables, and not used for function definitions.
1302 Should not be called for variables of incomplete structure type.
1304 TOP_LEVEL is nonzero if this variable has file scope.
1305 AT_END is nonzero if this is the special handling, at end of compilation,
1306 to define things that have had only tentative definitions.
1307 DONT_OUTPUT_DATA if nonzero means don't actually output the
1308 initial value (that will be done by the caller). */
1311 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1313 int top_level ATTRIBUTE_UNUSED
;
1314 int at_end ATTRIBUTE_UNUSED
;
1315 int dont_output_data
;
1317 register const char *name
;
1320 enum in_section saved_in_section
;
1322 last_assemble_variable_decl
= 0;
1324 if (GET_CODE (DECL_RTL (decl
)) == REG
)
1326 /* Do output symbol info for global register variables, but do nothing
1329 if (TREE_ASM_WRITTEN (decl
))
1331 TREE_ASM_WRITTEN (decl
) = 1;
1333 /* Do no output if -fsyntax-only. */
1334 if (flag_syntax_only
)
1337 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1338 /* File-scope global variables are output here. */
1339 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1341 dbxout_symbol (decl
, 0);
1343 #ifdef SDB_DEBUGGING_INFO
1344 if (write_symbols
== SDB_DEBUG
&& top_level
1345 /* Leave initialized global vars for end of compilation;
1346 see comment in compile_file. */
1347 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1348 sdbout_symbol (decl
, 0);
1351 /* Don't output any DWARF debugging information for variables here.
1352 In the case of local variables, the information for them is output
1353 when we do our recursive traversal of the tree representation for
1354 the entire containing function. In the case of file-scope variables,
1355 we output information for all of them at the very end of compilation
1356 while we are doing our final traversal of the chain of file-scope
1362 /* Normally no need to say anything here for external references,
1363 since assemble_external is called by the language-specific code
1364 when a declaration is first seen. */
1366 if (DECL_EXTERNAL (decl
))
1369 /* Output no assembler code for a function declaration.
1370 Only definitions of functions output anything. */
1372 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1375 /* If type was incomplete when the variable was declared,
1376 see if it is complete now. */
1378 if (DECL_SIZE (decl
) == 0)
1379 layout_decl (decl
, 0);
1381 /* Still incomplete => don't allocate it; treat the tentative defn
1382 (which is what it must have been) as an `extern' reference. */
1384 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1386 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1387 DECL_SOURCE_LINE (decl
),
1388 "storage size of `%s' isn't known",
1389 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1390 TREE_ASM_WRITTEN (decl
) = 1;
1394 /* The first declaration of a variable that comes through this function
1395 decides whether it is global (in C, has external linkage)
1396 or local (in C, has internal linkage). So do nothing more
1397 if this function has already run. */
1399 if (TREE_ASM_WRITTEN (decl
))
1402 TREE_ASM_WRITTEN (decl
) = 1;
1404 /* Do no output if -fsyntax-only. */
1405 if (flag_syntax_only
)
1410 if (! dont_output_data
1411 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1413 error_with_decl (decl
, "size of variable `%s' is too large");
1417 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1418 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1419 && ! first_global_object_name
1420 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1421 || DECL_INITIAL (decl
) == error_mark_node
))
1422 && ! DECL_WEAK (decl
)
1423 && ! DECL_ONE_ONLY (decl
))
1428 STRIP_NAME_ENCODING (p
, name
);
1429 xname
= permalloc (strlen (p
) + 1);
1431 first_global_object_name
= xname
;
1434 /* Compute the alignment of this data. */
1436 align
= DECL_ALIGN (decl
);
1438 /* In the case for initialing an array whose length isn't specified,
1439 where we have not yet been able to do the layout,
1440 figure out the proper alignment now. */
1441 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1442 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1443 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1445 /* Some object file formats have a maximum alignment which they support.
1446 In particular, a.out format supports a maximum alignment of 4. */
1447 #ifndef MAX_OFILE_ALIGNMENT
1448 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1450 if (align
> MAX_OFILE_ALIGNMENT
)
1452 warning_with_decl (decl
,
1453 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1454 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1455 align
= MAX_OFILE_ALIGNMENT
;
1458 /* On some machines, it is good to increase alignment sometimes. */
1459 #ifdef DATA_ALIGNMENT
1460 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1462 #ifdef CONSTANT_ALIGNMENT
1463 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1464 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1467 /* Reset the alignment in case we have made it tighter, so we can benefit
1468 from it in get_pointer_alignment. */
1469 DECL_ALIGN (decl
) = align
;
1471 /* Handle uninitialized definitions. */
1473 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
)
1474 /* If the target can't output uninitialized but not common global data
1475 in .bss, then we have to use .data. */
1476 #if ! defined ASM_EMIT_BSS
1477 && DECL_COMMON (decl
)
1479 && DECL_SECTION_NAME (decl
) == NULL_TREE
1480 && ! dont_output_data
)
1482 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1483 unsigned HOST_WIDE_INT rounded
= size
;
1485 /* Don't allocate zero bytes of common,
1486 since that means "undefined external" in the linker. */
1490 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1491 so that each uninitialized object starts on such a boundary. */
1492 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1493 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1494 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1496 /* Don't continue this line--convex cc version 4.1 would lose. */
1497 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1498 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN (decl
) / BITS_PER_UNIT
> rounded
)
1500 (decl
, "requested alignment for %s is greater than implemented alignment of %d.",rounded
);
1503 #ifdef DBX_DEBUGGING_INFO
1504 /* File-scope global variables are output here. */
1505 if (write_symbols
== DBX_DEBUG
&& top_level
)
1506 dbxout_symbol (decl
, 0);
1508 #ifdef SDB_DEBUGGING_INFO
1509 if (write_symbols
== SDB_DEBUG
&& top_level
1510 /* Leave initialized global vars for end of compilation;
1511 see comment in compile_file. */
1512 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1513 sdbout_symbol (decl
, 0);
1516 /* Don't output any DWARF debugging information for variables here.
1517 In the case of local variables, the information for them is output
1518 when we do our recursive traversal of the tree representation for
1519 the entire containing function. In the case of file-scope variables,
1520 we output information for all of them at the very end of compilation
1521 while we are doing our final traversal of the chain of file-scope
1524 #if 0 /* ??? We should either delete this or add a comment describing what
1525 it was intended to do and why we shouldn't delete it. */
1526 if (flag_shared_data
)
1529 asm_emit_uninitialised (decl
, name
, size
, rounded
);
1534 /* Handle initialized definitions.
1535 Also handle uninitialized global definitions if -fno-common and the
1536 target doesn't support ASM_OUTPUT_BSS. */
1538 /* First make the assembler name(s) global if appropriate. */
1539 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1541 #ifdef ASM_WEAKEN_LABEL
1542 if (DECL_WEAK (decl
))
1544 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1545 /* Remove this variable from the pending weak list so that
1546 we do not emit multiple .weak directives for it. */
1547 remove_from_pending_weak_list
1548 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1552 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1555 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
1557 tree e
= TREE_VALUE (d
);
1558 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
1559 ASM_GLOBALIZE_LABEL (asm_out_file
,
1560 XSTR (XEXP (DECL_RTL (e
), 0), 0));
1564 /* Output any data that we will need to use the address of. */
1565 if (DECL_INITIAL (decl
) == error_mark_node
)
1566 reloc
= contains_pointers_p (TREE_TYPE (decl
));
1567 else if (DECL_INITIAL (decl
))
1568 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1570 #ifdef ASM_OUTPUT_SECTION_NAME
1571 if ((flag_data_sections
!= 0 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1572 || UNIQUE_SECTION_P (decl
))
1573 UNIQUE_SECTION (decl
, reloc
);
1576 /* Switch to the appropriate section. */
1577 variable_section (decl
, reloc
);
1579 /* dbxout.c needs to know this. */
1580 if (in_text_section ())
1581 DECL_IN_TEXT_SECTION (decl
) = 1;
1583 /* Record current section so we can restore it if dbxout.c clobbers it. */
1584 saved_in_section
= in_section
;
1586 /* Output the dbx info now that we have chosen the section. */
1588 #ifdef DBX_DEBUGGING_INFO
1589 /* File-scope global variables are output here. */
1590 if (write_symbols
== DBX_DEBUG
&& top_level
)
1591 dbxout_symbol (decl
, 0);
1593 #ifdef SDB_DEBUGGING_INFO
1594 if (write_symbols
== SDB_DEBUG
&& top_level
1595 /* Leave initialized global vars for end of compilation;
1596 see comment in compile_file. */
1597 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1598 sdbout_symbol (decl
, 0);
1601 /* Don't output any DWARF debugging information for variables here.
1602 In the case of local variables, the information for them is output
1603 when we do our recursive traversal of the tree representation for
1604 the entire containing function. In the case of file-scope variables,
1605 we output information for all of them at the very end of compilation
1606 while we are doing our final traversal of the chain of file-scope
1609 /* If the debugging output changed sections, reselect the section
1610 that's supposed to be selected. */
1611 if (in_section
!= saved_in_section
)
1612 variable_section (decl
, reloc
);
1614 /* Output the alignment of this data. */
1615 if (align
> BITS_PER_UNIT
)
1616 ASM_OUTPUT_ALIGN (asm_out_file
,
1617 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1619 /* Do any machine/system dependent processing of the object. */
1620 #ifdef ASM_DECLARE_OBJECT_NAME
1621 last_assemble_variable_decl
= decl
;
1622 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1624 /* Standard thing is just output label for the object. */
1625 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1626 #endif /* ASM_DECLARE_OBJECT_NAME */
1628 if (!dont_output_data
)
1630 if (DECL_INITIAL (decl
))
1631 /* Output the actual data. */
1632 output_constant (DECL_INITIAL (decl
),
1633 tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1635 /* Leave space for it. */
1636 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1640 #ifdef XCOFF_DEBUGGING_INFO
1641 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1642 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1643 and `aa' hasn't been output yet, the assembler generates a stab entry with
1644 a value of zero, in addition to creating an unnecessary external entry
1645 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1647 /* File-scope global variables are output here. */
1648 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
1650 saved_in_section
= in_section
;
1652 dbxout_symbol (decl
, 0);
1654 if (in_section
!= saved_in_section
)
1655 variable_section (decl
, reloc
);
1658 /* There must be a statement after a label. */
1663 /* Return 1 if type TYPE contains any pointers. */
1666 contains_pointers_p (type
)
1669 switch (TREE_CODE (type
))
1672 case REFERENCE_TYPE
:
1673 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1674 so I'll play safe and return 1. */
1680 case QUAL_UNION_TYPE
:
1683 /* For a type that has fields, see if the fields have pointers. */
1684 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1685 if (TREE_CODE (fields
) == FIELD_DECL
1686 && contains_pointers_p (TREE_TYPE (fields
)))
1692 /* An array type contains pointers if its element type does. */
1693 return contains_pointers_p (TREE_TYPE (type
));
1700 /* Output something to declare an external symbol to the assembler.
1701 (Most assemblers don't need this, so we normally output nothing.)
1702 Do nothing if DECL is not external. */
1705 assemble_external (decl
)
1706 tree decl ATTRIBUTE_UNUSED
;
1708 #ifdef ASM_OUTPUT_EXTERNAL
1709 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1711 rtx rtl
= DECL_RTL (decl
);
1713 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1714 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1716 /* Some systems do require some output. */
1717 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1718 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1724 /* Similar, for calling a library function FUN. */
1727 assemble_external_libcall (fun
)
1728 rtx fun ATTRIBUTE_UNUSED
;
1730 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1731 /* Declare library function name external when first used, if nec. */
1732 if (! SYMBOL_REF_USED (fun
))
1734 SYMBOL_REF_USED (fun
) = 1;
1735 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1740 /* Declare the label NAME global. */
1743 assemble_global (name
)
1746 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1749 /* Assemble a label named NAME. */
1752 assemble_label (name
)
1755 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1758 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1759 If NAME starts with a *, the rest of NAME is output verbatim.
1760 Otherwise NAME is transformed in an implementation-defined way
1761 (usually by the addition of an underscore).
1762 Many macros in the tm file are defined to call this function. */
1765 assemble_name (file
, name
)
1769 const char *real_name
;
1772 STRIP_NAME_ENCODING (real_name
, name
);
1773 if (flag_prefix_function_name
1774 && ! memcmp (real_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
))
1775 real_name
= real_name
+ CHKR_PREFIX_SIZE
;
1777 id
= maybe_get_identifier (real_name
);
1779 TREE_SYMBOL_REFERENCED (id
) = 1;
1782 fputs (&name
[1], file
);
1784 ASM_OUTPUT_LABELREF (file
, name
);
1787 /* Allocate SIZE bytes writable static space with a gensym name
1788 and return an RTX to refer to its address. */
1791 assemble_static_space (size
)
1799 if (flag_shared_data
)
1803 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1805 namestring
= ggc_alloc_string (name
, -1);
1807 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1809 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1810 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1813 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1814 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1817 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1818 so that each uninitialized object starts on such a boundary. */
1819 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1820 int rounded ATTRIBUTE_UNUSED
1821 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1822 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1823 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1824 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1831 /* Assemble the static constant template for function entry trampolines.
1832 This is done at most once per compilation.
1833 Returns an RTX for the address of the template. */
1835 #ifdef TRAMPOLINE_TEMPLATE
1837 assemble_trampoline_template ()
1843 /* By default, put trampoline templates in read-only data section. */
1845 #ifdef TRAMPOLINE_SECTION
1846 TRAMPOLINE_SECTION ();
1848 readonly_data_section ();
1851 /* Write the assembler code to define one. */
1852 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1854 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1856 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1857 TRAMPOLINE_TEMPLATE (asm_out_file
);
1859 /* Record the rtl to refer to it. */
1860 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1861 name
= ggc_alloc_string (label
, -1);
1862 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1866 /* Assemble the integer constant X into an object of SIZE bytes.
1867 X must be either a CONST_INT or CONST_DOUBLE.
1869 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1870 non-zero, abort if we can't output the constant. */
1873 assemble_integer (x
, size
, force
)
1878 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1879 ASM_OUTPUT... macros. */
1883 #ifdef ASM_OUTPUT_CHAR
1885 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1889 #ifdef ASM_OUTPUT_SHORT
1891 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1895 #ifdef ASM_OUTPUT_INT
1897 ASM_OUTPUT_INT (asm_out_file
, x
);
1901 #ifdef ASM_OUTPUT_DOUBLE_INT
1903 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1907 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1909 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1914 /* If we couldn't do it that way, there are two other possibilities: First,
1915 if the machine can output an explicit byte and this is a 1 byte constant,
1916 we can use ASM_OUTPUT_BYTE. */
1918 #ifdef ASM_OUTPUT_BYTE
1919 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1921 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1926 /* Finally, if SIZE is larger than a single word, try to output the constant
1927 one word at a time. */
1929 if (size
> UNITS_PER_WORD
)
1932 enum machine_mode mode
1933 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1936 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1938 word
= operand_subword (x
, i
, 0, mode
);
1943 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1947 if (i
== size
/ UNITS_PER_WORD
)
1949 /* If we output at least one word and then could not finish,
1950 there is no valid way to continue. */
1961 /* Assemble the floating-point constant D into an object of size MODE. */
1964 assemble_real (d
, mode
)
1966 enum machine_mode mode
;
1968 jmp_buf output_constant_handler
;
1970 if (setjmp (output_constant_handler
))
1972 error ("floating point trap outputting a constant");
1973 #ifdef REAL_IS_NOT_DOUBLE
1974 memset ((char *) &d
, 0, sizeof d
);
1981 set_float_handler (output_constant_handler
);
1985 #ifdef ASM_OUTPUT_BYTE_FLOAT
1987 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, d
);
1990 #ifdef ASM_OUTPUT_SHORT_FLOAT
1992 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, d
);
1995 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1997 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, d
);
2000 #ifdef ASM_OUTPUT_FLOAT
2002 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
2006 #ifdef ASM_OUTPUT_DOUBLE
2008 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
2012 #ifdef ASM_OUTPUT_LONG_DOUBLE
2015 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
2023 set_float_handler (NULL_PTR
);
2026 /* Here we combine duplicate floating constants to make
2027 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2029 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2030 For an integer, I0 is the low-order word and I1 is the high-order word.
2031 For a real number, I0 is the word with the low address
2032 and I1 is the word with the high address. */
2035 immed_double_const (i0
, i1
, mode
)
2036 HOST_WIDE_INT i0
, i1
;
2037 enum machine_mode mode
;
2041 if (GET_MODE_CLASS (mode
) == MODE_INT
2042 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
2044 /* We clear out all bits that don't belong in MODE, unless they and our
2045 sign bit are all one. So we get either a reasonable negative value
2046 or a reasonable unsigned value for this mode. */
2047 int width
= GET_MODE_BITSIZE (mode
);
2048 if (width
< HOST_BITS_PER_WIDE_INT
2049 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
2050 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
2051 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
2052 else if (width
== HOST_BITS_PER_WIDE_INT
2053 && ! (i1
== ~0 && i0
< 0))
2055 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
2056 /* We cannot represent this value as a constant. */
2059 /* If this would be an entire word for the target, but is not for
2060 the host, then sign-extend on the host so that the number will look
2061 the same way on the host that it would on the target.
2063 For example, when building a 64 bit alpha hosted 32 bit sparc
2064 targeted compiler, then we want the 32 bit unsigned value -1 to be
2065 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2066 The later confuses the sparc backend. */
2068 if (BITS_PER_WORD
< HOST_BITS_PER_WIDE_INT
&& BITS_PER_WORD
== width
2069 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
2070 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
2072 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2074 ??? Strictly speaking, this is wrong if we create a CONST_INT
2075 for a large unsigned constant with the size of MODE being
2076 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2077 wider mode. In that case we will mis-interpret it as a negative
2080 Unfortunately, the only alternative is to make a CONST_DOUBLE
2081 for any constant in any mode if it is an unsigned constant larger
2082 than the maximum signed integer in an int on the host. However,
2083 doing this will break everyone that always expects to see a CONST_INT
2084 for SImode and smaller.
2086 We have always been making CONST_INTs in this case, so nothing new
2089 if (width
<= HOST_BITS_PER_WIDE_INT
)
2090 i1
= (i0
< 0) ? ~(HOST_WIDE_INT
) 0 : 0;
2092 /* If this integer fits in one word, return a CONST_INT. */
2093 if ((i1
== 0 && i0
>= 0)
2094 || (i1
== ~0 && i0
< 0))
2095 return GEN_INT (i0
);
2097 /* We use VOIDmode for integers. */
2101 /* Search the chain for an existing CONST_DOUBLE with the right value.
2102 If one is found, return it. */
2104 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2105 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
2106 && GET_MODE (r
) == mode
)
2109 /* No; make a new one and add it to the chain. */
2110 r
= gen_rtx_CONST_DOUBLE (mode
, const0_rtx
, i0
, i1
);
2112 /* Don't touch const_double_chain if not inside any function. */
2113 if (current_function_decl
!= 0)
2115 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2116 const_double_chain
= r
;
2122 /* Return a CONST_DOUBLE for a specified `double' value
2123 and machine mode. */
2126 immed_real_const_1 (d
, mode
)
2128 enum machine_mode mode
;
2130 union real_extract u
;
2133 /* Get the desired `double' value as a sequence of ints
2134 since that is how they are stored in a CONST_DOUBLE. */
2138 /* Detect special cases. But be careful we don't use a CONST_DOUBLE
2139 that's from a parent function since it may be in its constant pool. */
2140 if (REAL_VALUES_IDENTICAL (dconst0
, d
)
2141 && (cfun
== 0 || decl_function_context (current_function_decl
) == 0))
2142 return CONST0_RTX (mode
);
2144 /* Check for NaN first, because some ports (specifically the i386) do not
2145 emit correct ieee-fp code by default, and thus will generate a core
2146 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2147 does a floating point comparison. */
2148 else if ((! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
2150 || decl_function_context (current_function_decl
) == 0))
2151 return CONST1_RTX (mode
);
2153 if (sizeof u
== sizeof (HOST_WIDE_INT
))
2154 return immed_double_const (u
.i
[0], 0, mode
);
2155 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
2156 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
2158 /* The rest of this function handles the case where
2159 a float value requires more than 2 ints of space.
2160 It will be deleted as dead code on machines that don't need it. */
2162 /* Search the chain for an existing CONST_DOUBLE with the right value.
2163 If one is found, return it. */
2165 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
2166 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
2167 && GET_MODE (r
) == mode
)
2170 /* No; make a new one and add it to the chain.
2172 We may be called by an optimizer which may be discarding any memory
2173 allocated during its processing (such as combine and loop). However,
2174 we will be leaving this constant on the chain, so we cannot tolerate
2176 r
= rtx_alloc (CONST_DOUBLE
);
2178 memcpy ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
);
2180 /* If we aren't inside a function, don't put r on the
2181 const_double_chain. */
2182 if (current_function_decl
!= 0)
2184 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2185 const_double_chain
= r
;
2188 CONST_DOUBLE_CHAIN (r
) = NULL_RTX
;
2190 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2191 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2192 is only through force_const_mem. */
2194 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2199 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2200 which must be a REAL_CST tree node. */
2203 immed_real_const (exp
)
2206 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
2209 /* At the end of a function, forget the memory-constants
2210 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2211 Also clear out real_constant_chain and clear out all the chain-pointers. */
2214 clear_const_double_mem ()
2216 register rtx r
, next
;
2218 for (r
= const_double_chain
; r
; r
= next
)
2220 next
= CONST_DOUBLE_CHAIN (r
);
2221 CONST_DOUBLE_CHAIN (r
) = 0;
2222 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
2224 const_double_chain
= 0;
2227 /* Given an expression EXP with a constant value,
2228 reduce it to the sum of an assembler symbol and an integer.
2229 Store them both in the structure *VALUE.
2230 Abort if EXP does not reduce. */
2235 HOST_WIDE_INT offset
;
2239 decode_addr_const (exp
, value
)
2241 struct addr_const
*value
;
2243 register tree target
= TREE_OPERAND (exp
, 0);
2244 register int offset
= 0;
2249 if (TREE_CODE (target
) == COMPONENT_REF
2250 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2253 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2254 target
= TREE_OPERAND (target
, 0);
2256 else if (TREE_CODE (target
) == ARRAY_REF
)
2258 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2259 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2260 target
= TREE_OPERAND (target
, 0);
2266 switch (TREE_CODE (target
))
2270 x
= DECL_RTL (target
);
2274 x
= gen_rtx_MEM (FUNCTION_MODE
,
2275 gen_rtx_LABEL_REF (VOIDmode
,
2276 label_rtx (TREE_OPERAND (exp
, 0))));
2284 x
= TREE_CST_RTL (target
);
2291 if (GET_CODE (x
) != MEM
)
2296 value
->offset
= offset
;
2301 #ifdef ONLY_INT_FIELDS
2302 unsigned int kind
: 16;
2303 unsigned int mode
: 16;
2305 enum kind kind
: 16;
2306 enum machine_mode mode
: 16;
2309 union real_extract du
;
2310 struct addr_const addr
;
2311 struct {HOST_WIDE_INT high
, low
;} di
;
2315 /* Uniquize all constants that appear in memory.
2316 Each constant in memory thus far output is recorded
2317 in `const_hash_table' with a `struct constant_descriptor'
2318 that contains a polish representation of the value of
2321 We cannot store the trees in the hash table
2322 because the trees may be temporary. */
2324 struct constant_descriptor
2326 struct constant_descriptor
*next
;
2329 /* Make sure the data is reasonably aligned. */
2332 unsigned char contents
[1];
2333 #ifdef HAVE_LONG_DOUBLE
2342 #define MAX_HASH_TABLE 1009
2343 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2345 /* Mark a const_hash_table descriptor for GC. */
2348 mark_const_hash_entry (ptr
)
2351 struct constant_descriptor
*desc
= * (struct constant_descriptor
**) ptr
;
2355 ggc_mark_string ((const char *)desc
->label
);
2356 ggc_mark_rtx (desc
->rtl
);
2361 /* Compute a hash code for a constant expression. */
2367 register const char *p
;
2368 register int len
, hi
, i
;
2369 register enum tree_code code
= TREE_CODE (exp
);
2371 /* Either set P and LEN to the address and len of something to hash and
2372 exit the switch or return a value. */
2377 p
= (char *) &TREE_INT_CST (exp
);
2378 len
= sizeof TREE_INT_CST (exp
);
2382 p
= (char *) &TREE_REAL_CST (exp
);
2383 len
= sizeof TREE_REAL_CST (exp
);
2387 p
= TREE_STRING_POINTER (exp
);
2388 len
= TREE_STRING_LENGTH (exp
);
2392 return (const_hash (TREE_REALPART (exp
)) * 5
2393 + const_hash (TREE_IMAGPART (exp
)));
2396 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2400 len
= int_size_in_bytes (TREE_TYPE (exp
));
2401 tmp
= (char *) alloca (len
);
2402 get_set_constructor_bytes (exp
, (unsigned char *) tmp
, len
);
2410 /* For record type, include the type in the hashing.
2411 We do not do so for array types
2412 because (1) the sizes of the elements are sufficient
2413 and (2) distinct array types can have the same constructor.
2414 Instead, we include the array size because the constructor could
2416 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2417 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2420 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2421 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2423 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2424 if (TREE_VALUE (link
))
2426 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2433 struct addr_const value
;
2435 decode_addr_const (exp
, &value
);
2436 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2438 /* Don't hash the address of the SYMBOL_REF;
2439 only use the offset and the symbol name. */
2441 p
= XSTR (value
.base
, 0);
2442 for (i
= 0; p
[i
] != 0; i
++)
2443 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2445 else if (GET_CODE (value
.base
) == LABEL_REF
)
2446 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2450 hi
&= (1 << HASHBITS
) - 1;
2451 hi
%= MAX_HASH_TABLE
;
2457 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2458 + const_hash (TREE_OPERAND (exp
, 1)));
2462 case NON_LVALUE_EXPR
:
2463 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2466 /* A language specific constant. Just hash the code. */
2467 return code
% MAX_HASH_TABLE
;
2470 /* Compute hashing function */
2472 for (i
= 0; i
< len
; i
++)
2473 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2475 hi
&= (1 << HASHBITS
) - 1;
2476 hi
%= MAX_HASH_TABLE
;
2480 /* Compare a constant expression EXP with a constant-descriptor DESC.
2481 Return 1 if DESC describes a constant with the same value as EXP. */
2484 compare_constant (exp
, desc
)
2486 struct constant_descriptor
*desc
;
2488 return 0 != compare_constant_1 (exp
, desc
->u
.contents
);
2491 /* Compare constant expression EXP with a substring P of a constant descriptor.
2492 If they match, return a pointer to the end of the substring matched.
2493 If they do not match, return 0.
2495 Since descriptors are written in polish prefix notation,
2496 this function can be used recursively to test one operand of EXP
2497 against a subdescriptor, and if it succeeds it returns the
2498 address of the subdescriptor for the next operand. */
2500 static const unsigned char *
2501 compare_constant_1 (exp
, p
)
2503 const unsigned char *p
;
2505 register const unsigned char *strp
;
2507 register enum tree_code code
= TREE_CODE (exp
);
2509 if (code
!= (enum tree_code
) *p
++)
2512 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2513 switch, or return the result of the comparison. */
2518 /* Integer constants are the same only if the same width of type. */
2519 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2522 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2523 len
= sizeof TREE_INT_CST (exp
);
2527 /* Real constants are the same only if the same width of type. */
2528 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2531 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2532 len
= sizeof TREE_REAL_CST (exp
);
2536 if (flag_writable_strings
)
2539 if ((enum machine_mode
) *p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2542 strp
= (unsigned char *)TREE_STRING_POINTER (exp
);
2543 len
= TREE_STRING_LENGTH (exp
);
2544 if (memcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2545 sizeof TREE_STRING_LENGTH (exp
)))
2548 p
+= sizeof TREE_STRING_LENGTH (exp
);
2552 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2556 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2559 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2561 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2562 unsigned char *tmp
= (unsigned char *) alloca (len
);
2564 get_set_constructor_bytes (exp
, tmp
, len
);
2565 strp
= (unsigned char *) tmp
;
2566 if (memcmp ((char *) &xlen
, p
, sizeof xlen
))
2575 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2577 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2578 int have_purpose
= 0;
2580 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2581 if (TREE_PURPOSE (link
))
2584 if (memcmp ((char *) &length
, p
, sizeof length
))
2589 /* For record constructors, insist that the types match.
2590 For arrays, just verify both constructors are for arrays.
2591 Then insist that either both or none have any TREE_PURPOSE
2593 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2594 type
= TREE_TYPE (exp
);
2598 if (memcmp ((char *) &type
, p
, sizeof type
))
2601 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2603 if (memcmp ((char *) &mode
, p
, sizeof mode
))
2611 if (memcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2614 p
+= sizeof have_purpose
;
2616 /* For arrays, insist that the size in bytes match. */
2617 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2619 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2621 if (memcmp ((char *) &size
, p
, sizeof size
))
2627 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2629 if (TREE_VALUE (link
))
2631 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2638 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2644 if (TREE_PURPOSE (link
)
2645 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2647 if (memcmp ((char *) &TREE_PURPOSE (link
), p
,
2648 sizeof TREE_PURPOSE (link
)))
2651 p
+= sizeof TREE_PURPOSE (link
);
2653 else if (TREE_PURPOSE (link
))
2655 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2658 else if (have_purpose
)
2662 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2674 struct addr_const value
;
2676 decode_addr_const (exp
, &value
);
2677 strp
= (unsigned char *) &value
.offset
;
2678 len
= sizeof value
.offset
;
2679 /* Compare the offset. */
2681 if (*p
++ != *strp
++)
2684 /* Compare symbol name. */
2685 strp
= (unsigned char *) XSTR (value
.base
, 0);
2686 len
= strlen ((char *) strp
) + 1;
2693 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2697 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2701 case NON_LVALUE_EXPR
:
2702 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2705 if (lang_expand_constant
)
2707 exp
= (*lang_expand_constant
) (exp
);
2708 return compare_constant_1 (exp
, p
);
2713 /* Compare constant contents. */
2715 if (*p
++ != *strp
++)
2721 /* Construct a constant descriptor for the expression EXP.
2722 It is up to the caller to enter the descriptor in the hash table. */
2724 static struct constant_descriptor
*
2725 record_constant (exp
)
2728 struct constant_descriptor
*next
= 0;
2732 /* Make a struct constant_descriptor. The first three pointers will
2733 be filled in later. Here we just leave space for them. */
2735 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2736 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2737 obstack_grow (&permanent_obstack
, (char *) &rtl
, sizeof rtl
);
2738 record_constant_1 (exp
);
2739 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2742 /* Add a description of constant expression EXP
2743 to the object growing in `permanent_obstack'.
2744 No need to return its address; the caller will get that
2745 from the obstack when the object is complete. */
2748 record_constant_1 (exp
)
2751 register unsigned char *strp
;
2753 register enum tree_code code
= TREE_CODE (exp
);
2755 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2760 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2761 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2762 len
= sizeof TREE_INT_CST (exp
);
2766 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2767 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2768 len
= sizeof TREE_REAL_CST (exp
);
2772 if (flag_writable_strings
)
2775 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2776 strp
= (unsigned char *) TREE_STRING_POINTER (exp
);
2777 len
= TREE_STRING_LENGTH (exp
);
2778 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2779 sizeof TREE_STRING_LENGTH (exp
));
2783 record_constant_1 (TREE_REALPART (exp
));
2784 record_constant_1 (TREE_IMAGPART (exp
));
2788 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2790 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2791 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2792 obstack_blank (&permanent_obstack
, nbytes
);
2793 get_set_constructor_bytes
2794 (exp
, (unsigned char *) permanent_obstack
.next_free
-nbytes
,
2801 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2802 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2804 int have_purpose
= 0;
2806 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2807 if (TREE_PURPOSE (link
))
2810 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2812 /* For record constructors, insist that the types match.
2813 For arrays, just verify both constructors are for arrays
2814 of the same mode. Then insist that either both or none
2815 have any TREE_PURPOSE values. */
2816 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2817 type
= TREE_TYPE (exp
);
2821 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2822 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2823 obstack_grow (&permanent_obstack
, &mode
, sizeof mode
);
2825 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2826 sizeof have_purpose
);
2828 /* For arrays, insist that the size in bytes match. */
2829 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2831 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2832 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2835 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2837 if (TREE_VALUE (link
))
2838 record_constant_1 (TREE_VALUE (link
));
2843 obstack_grow (&permanent_obstack
,
2844 (char *) &zero
, sizeof zero
);
2847 if (TREE_PURPOSE (link
)
2848 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2849 obstack_grow (&permanent_obstack
,
2850 (char *) &TREE_PURPOSE (link
),
2851 sizeof TREE_PURPOSE (link
));
2852 else if (TREE_PURPOSE (link
))
2853 record_constant_1 (TREE_PURPOSE (link
));
2854 else if (have_purpose
)
2858 obstack_grow (&permanent_obstack
,
2859 (char *) &zero
, sizeof zero
);
2867 struct addr_const value
;
2869 decode_addr_const (exp
, &value
);
2870 /* Record the offset. */
2871 obstack_grow (&permanent_obstack
,
2872 (char *) &value
.offset
, sizeof value
.offset
);
2874 switch (GET_CODE (value
.base
))
2877 /* Record the symbol name. */
2878 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2879 strlen (XSTR (value
.base
, 0)) + 1);
2882 /* Record the address of the CODE_LABEL. It may not have
2883 been emitted yet, so it's UID may be zero. But pointer
2884 identity is good enough. */
2885 obstack_grow (&permanent_obstack
, &XEXP (value
.base
, 0),
2897 record_constant_1 (TREE_OPERAND (exp
, 0));
2898 record_constant_1 (TREE_OPERAND (exp
, 1));
2903 case NON_LVALUE_EXPR
:
2904 record_constant_1 (TREE_OPERAND (exp
, 0));
2908 if (lang_expand_constant
)
2910 exp
= (*lang_expand_constant
) (exp
);
2911 record_constant_1 (exp
);
2916 /* Record constant contents. */
2917 obstack_grow (&permanent_obstack
, strp
, len
);
2920 /* Record a list of constant expressions that were passed to
2921 output_constant_def but that could not be output right away. */
2923 struct deferred_constant
2925 struct deferred_constant
*next
;
2931 static struct deferred_constant
*deferred_constants
;
2933 /* Another list of constants which should be output after the
2935 static struct deferred_constant
*after_function_constants
;
2937 /* Nonzero means defer output of addressed subconstants
2938 (i.e., those for which output_constant_def is called.) */
2939 static int defer_addressed_constants_flag
;
2941 /* Start deferring output of subconstants. */
2944 defer_addressed_constants ()
2946 defer_addressed_constants_flag
++;
2949 /* Stop deferring output of subconstants,
2950 and output now all those that have been deferred. */
2953 output_deferred_addressed_constants ()
2955 struct deferred_constant
*p
, *next
;
2957 defer_addressed_constants_flag
--;
2959 if (defer_addressed_constants_flag
> 0)
2962 for (p
= deferred_constants
; p
; p
= next
)
2964 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2969 deferred_constants
= 0;
2972 /* Output any constants which should appear after a function. */
2975 output_after_function_constants ()
2977 struct deferred_constant
*p
, *next
;
2979 for (p
= after_function_constants
; p
; p
= next
)
2981 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2986 after_function_constants
= 0;
2989 /* Make a copy of the whole tree structure for a constant.
2990 This handles the same types of nodes that compare_constant
2991 and record_constant handle. */
2997 switch (TREE_CODE (exp
))
3000 /* For ADDR_EXPR, we do not want to copy the decl whose address
3001 is requested. We do want to copy constants though. */
3002 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
3003 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3004 copy_constant (TREE_OPERAND (exp
, 0)));
3006 return copy_node (exp
);
3011 return copy_node (exp
);
3014 return build_complex (TREE_TYPE (exp
),
3015 copy_constant (TREE_REALPART (exp
)),
3016 copy_constant (TREE_IMAGPART (exp
)));
3020 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
3021 copy_constant (TREE_OPERAND (exp
, 0)),
3022 copy_constant (TREE_OPERAND (exp
, 1)));
3026 case NON_LVALUE_EXPR
:
3027 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3028 copy_constant (TREE_OPERAND (exp
, 0)));
3032 tree copy
= copy_node (exp
);
3033 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
3036 CONSTRUCTOR_ELTS (copy
) = list
;
3037 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3038 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
3039 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
3040 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3041 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
3051 /* Return an rtx representing a reference to constant data in memory
3052 for the constant expression EXP.
3054 If assembler code for such a constant has already been output,
3055 return an rtx to refer to it.
3056 Otherwise, output such a constant in memory (or defer it for later)
3057 and generate an rtx for it.
3059 The TREE_CST_RTL of EXP is set up to point to that rtx.
3060 The const_hash_table records which constants already have label strings. */
3063 output_constant_def (exp
)
3067 register struct constant_descriptor
*desc
;
3072 if (TREE_CST_RTL (exp
))
3073 return TREE_CST_RTL (exp
);
3075 /* Make sure any other constants whose addresses appear in EXP
3076 are assigned label numbers. */
3078 reloc
= output_addressed_constants (exp
);
3080 /* Compute hash code of EXP. Search the descriptors for that hash code
3081 to see if any of them describes EXP. If yes, the descriptor records
3082 the label number already assigned. */
3084 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
3086 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
3087 if (compare_constant (exp
, desc
))
3092 /* No constant equal to EXP is known to have been output.
3093 Make a constant descriptor to enter EXP in the hash table.
3094 Assign the label number and record it in the descriptor for
3095 future calls to this function to find. */
3097 /* Create a string containing the label name, in LABEL. */
3098 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3100 desc
= record_constant (exp
);
3101 desc
->next
= const_hash_table
[hash
];
3102 desc
->label
= ggc_alloc_string (label
, -1);
3103 const_hash_table
[hash
] = desc
;
3105 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3107 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
3108 gen_rtx_SYMBOL_REF (Pmode
, desc
->label
));
3110 set_mem_attributes (desc
->rtl
, exp
, 1);
3115 TREE_CST_RTL (exp
) = desc
->rtl
;
3117 /* Optionally set flags or add text to the name to record information
3118 such as that it is a function name. If the name is changed, the macro
3119 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3120 #ifdef ENCODE_SECTION_INFO
3121 ENCODE_SECTION_INFO (exp
);
3124 /* If this is the first time we've seen this particular constant,
3125 output it (or defer its output for later). */
3128 int after_function
= 0;
3130 #ifdef CONSTANT_AFTER_FUNCTION_P
3131 if (current_function_decl
!= 0
3132 && CONSTANT_AFTER_FUNCTION_P (exp
))
3136 if (defer_addressed_constants_flag
|| after_function
)
3138 struct deferred_constant
*p
;
3139 p
= (struct deferred_constant
*) xmalloc (sizeof (struct deferred_constant
));
3141 p
->exp
= copy_constant (exp
);
3143 p
->labelno
= const_labelno
++;
3146 p
->next
= after_function_constants
;
3147 after_function_constants
= p
;
3151 p
->next
= deferred_constants
;
3152 deferred_constants
= p
;
3157 /* Do no output if -fsyntax-only. */
3158 if (! flag_syntax_only
)
3159 output_constant_def_contents (exp
, reloc
, const_labelno
);
3164 return TREE_CST_RTL (exp
);
3167 /* Now output assembler code to define the label for EXP,
3168 and follow it with the data of EXP. */
3171 output_constant_def_contents (exp
, reloc
, labelno
)
3178 if (IN_NAMED_SECTION (exp
))
3179 named_section (exp
, NULL
, reloc
);
3182 /* First switch to text section, except for writable strings. */
3183 #ifdef SELECT_SECTION
3184 SELECT_SECTION (exp
, reloc
);
3186 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
3187 || (flag_pic
&& reloc
))
3190 readonly_data_section ();
3194 /* Align the location counter as required by EXP's data type. */
3195 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3196 #ifdef CONSTANT_ALIGNMENT
3197 align
= CONSTANT_ALIGNMENT (exp
, align
);
3200 if (align
> BITS_PER_UNIT
)
3201 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3203 /* Output the label itself. */
3204 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3206 /* Output the value of EXP. */
3207 output_constant (exp
,
3208 (TREE_CODE (exp
) == STRING_CST
3209 ? TREE_STRING_LENGTH (exp
)
3210 : int_size_in_bytes (TREE_TYPE (exp
))));
3214 /* Structure to represent sufficient information about a constant so that
3215 it can be output when the constant pool is output, so that function
3216 integration can be done, and to simplify handling on machines that reference
3217 constant pool as base+displacement. */
3219 struct pool_constant
3221 struct constant_descriptor
*desc
;
3222 struct pool_constant
*next
, *next_sym
;
3225 enum machine_mode mode
;
3232 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3233 The argument is XSTR (... , 0) */
3235 #define SYMHASH(LABEL) \
3236 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3238 /* Initialize constant pool hashing for a new function. */
3241 init_varasm_status (f
)
3244 struct varasm_status
*p
;
3245 p
= (struct varasm_status
*) xmalloc (sizeof (struct varasm_status
));
3247 p
->x_const_rtx_hash_table
3248 = ((struct constant_descriptor
**)
3249 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct constant_descriptor
*)));
3250 p
->x_const_rtx_sym_hash_table
3251 = ((struct pool_constant
**)
3252 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct pool_constant
*)));
3254 p
->x_first_pool
= p
->x_last_pool
= 0;
3255 p
->x_pool_offset
= 0;
3256 p
->x_const_double_chain
= 0;
3259 /* Mark PC for GC. */
3262 mark_pool_constant (pc
)
3263 struct pool_constant
*pc
;
3268 ggc_mark_rtx (pc
->constant
);
3269 ggc_mark_string (pc
->label
);
3274 /* Mark P for GC. */
3277 mark_varasm_status (p
)
3278 struct varasm_status
*p
;
3283 mark_pool_constant (p
->x_first_pool
);
3284 ggc_mark_rtx (p
->x_const_double_chain
);
3287 /* Clear out all parts of the state in F that can safely be discarded
3288 after the function has been compiled, to let garbage collection
3289 reclaim the memory. */
3292 free_varasm_status (f
)
3295 struct varasm_status
*p
;
3300 /* Clear out the hash tables. */
3301 for (i
= 0; i
< MAX_RTX_HASH_TABLE
; ++i
)
3303 struct constant_descriptor
* cd
;
3305 cd
= p
->x_const_rtx_hash_table
[i
];
3307 struct constant_descriptor
* next
= cd
->next
;
3313 free (p
->x_const_rtx_hash_table
);
3314 free (p
->x_const_rtx_sym_hash_table
);
3319 enum kind
{ RTX_DOUBLE
, RTX_INT
};
3321 /* Express an rtx for a constant integer (perhaps symbolic)
3322 as the sum of a symbol or label plus an explicit integer.
3323 They are stored into VALUE. */
3326 decode_rtx_const (mode
, x
, value
)
3327 enum machine_mode mode
;
3329 struct rtx_const
*value
;
3331 /* Clear the whole structure, including any gaps. */
3332 memset (value
, 0, sizeof (struct rtx_const
));
3334 value
->kind
= RTX_INT
; /* Most usual kind. */
3337 switch (GET_CODE (x
))
3340 value
->kind
= RTX_DOUBLE
;
3341 if (GET_MODE (x
) != VOIDmode
)
3343 value
->mode
= GET_MODE (x
);
3344 memcpy ((char *) &value
->un
.du
,
3345 (char *) &CONST_DOUBLE_LOW (x
), sizeof value
->un
.du
);
3349 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3350 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3355 value
->un
.addr
.offset
= INTVAL (x
);
3361 value
->un
.addr
.base
= x
;
3366 if (GET_CODE (x
) == PLUS
)
3368 value
->un
.addr
.base
= XEXP (x
, 0);
3369 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3371 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3373 else if (GET_CODE (x
) == MINUS
)
3375 value
->un
.addr
.base
= XEXP (x
, 0);
3376 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3378 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3388 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3389 switch (GET_CODE (value
->un
.addr
.base
))
3392 /* Use the string's address, not the SYMBOL_REF's address,
3393 for the sake of addresses of library routines. */
3394 value
->un
.addr
.base
= (rtx
) XSTR (value
->un
.addr
.base
, 0);
3398 /* For a LABEL_REF, compare labels. */
3399 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3406 /* Given a MINUS expression, simplify it if both sides
3407 include the same symbol. */
3410 simplify_subtraction (x
)
3413 struct rtx_const val0
, val1
;
3415 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3416 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3418 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3419 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3423 /* Compute a hash code for a constant RTL expression. */
3426 const_hash_rtx (mode
, x
)
3427 enum machine_mode mode
;
3433 struct rtx_const value
;
3434 decode_rtx_const (mode
, x
, &value
);
3436 /* Compute hashing function */
3438 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3439 hi
+= ((int *) &value
)[i
];
3441 hi
&= (1 << HASHBITS
) - 1;
3442 hi
%= MAX_RTX_HASH_TABLE
;
3446 /* Compare a constant rtl object X with a constant-descriptor DESC.
3447 Return 1 if DESC describes a constant with the same value as X. */
3450 compare_constant_rtx (mode
, x
, desc
)
3451 enum machine_mode mode
;
3453 struct constant_descriptor
*desc
;
3455 register int *p
= (int *) desc
->u
.contents
;
3458 struct rtx_const value
;
3460 decode_rtx_const (mode
, x
, &value
);
3461 strp
= (int *) &value
;
3462 len
= sizeof value
/ sizeof (int);
3464 /* Compare constant contents. */
3466 if (*p
++ != *strp
++)
3472 /* Construct a constant descriptor for the rtl-expression X.
3473 It is up to the caller to enter the descriptor in the hash table. */
3475 static struct constant_descriptor
*
3476 record_constant_rtx (mode
, x
)
3477 enum machine_mode mode
;
3480 struct constant_descriptor
*ptr
;
3482 ptr
= ((struct constant_descriptor
*)
3483 xcalloc (1, (offsetof (struct constant_descriptor
, u
)
3484 + sizeof (struct rtx_const
))));
3485 decode_rtx_const (mode
, x
, (struct rtx_const
*) ptr
->u
.contents
);
3490 /* Given a constant rtx X, make (or find) a memory constant for its value
3491 and return a MEM rtx to refer to it in memory. */
3494 force_const_mem (mode
, x
)
3495 enum machine_mode mode
;
3499 register struct constant_descriptor
*desc
;
3504 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3505 (this will always be true for floating CONST_DOUBLEs that have been
3506 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3507 use the previous copy. Otherwise, make a new one. Note that in
3508 the unlikely event that this same CONST_DOUBLE is used in two different
3509 modes in an alternating fashion, we will allocate a lot of different
3510 memory locations, but this should be extremely rare. */
3512 if (GET_CODE (x
) == CONST_DOUBLE
3513 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
3514 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
3515 return CONST_DOUBLE_MEM (x
);
3517 /* Compute hash code of X. Search the descriptors for that hash code
3518 to see if any of them describes X. If yes, the descriptor records
3519 the label number already assigned. */
3521 hash
= const_hash_rtx (mode
, x
);
3523 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3524 if (compare_constant_rtx (mode
, x
, desc
))
3526 found
= desc
->label
;
3532 register struct pool_constant
*pool
;
3535 /* No constant equal to X is known to have been output.
3536 Make a constant descriptor to enter X in the hash table.
3537 Assign the label number and record it in the descriptor for
3538 future calls to this function to find. */
3540 desc
= record_constant_rtx (mode
, x
);
3541 desc
->next
= const_rtx_hash_table
[hash
];
3542 const_rtx_hash_table
[hash
] = desc
;
3544 /* Align the location counter as required by EXP's data type. */
3545 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
3546 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
3547 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
3548 #ifdef CONSTANT_ALIGNMENT
3549 align
= CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode
, 0), x
),
3550 align
* BITS_PER_UNIT
) / BITS_PER_UNIT
;
3553 pool_offset
+= align
- 1;
3554 pool_offset
&= ~ (align
- 1);
3556 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3558 pool
= (struct pool_constant
*) ggc_alloc (sizeof (struct pool_constant
));
3562 pool
->labelno
= const_labelno
;
3563 pool
->align
= align
;
3564 pool
->offset
= pool_offset
;
3571 last_pool
->next
= pool
;
3574 pool_offset
+= GET_MODE_SIZE (mode
);
3576 /* Create a string containing the label name, in LABEL. */
3577 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3581 desc
->label
= found
= ggc_alloc_string (label
, -1);
3583 /* Add label to symbol hash table. */
3584 hash
= SYMHASH (found
);
3585 pool
->label
= found
;
3586 pool
->next_sym
= const_rtx_sym_hash_table
[hash
];
3587 const_rtx_sym_hash_table
[hash
] = pool
;
3590 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3592 def
= gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, found
));
3593 set_mem_attributes (def
, type_for_mode (mode
, 0), 1);
3594 RTX_UNCHANGING_P (def
) = 1;
3596 /* Mark the symbol_ref as belonging to this constants pool. */
3597 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3598 current_function_uses_const_pool
= 1;
3600 if (GET_CODE (x
) == CONST_DOUBLE
)
3602 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
3604 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
3605 const_double_chain
= x
;
3607 CONST_DOUBLE_MEM (x
) = def
;
3613 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3614 the corresponding pool_constant structure. */
3616 static struct pool_constant
*
3617 find_pool_constant (f
, addr
)
3621 struct pool_constant
*pool
;
3622 const char *label
= XSTR (addr
, 0);
3624 for (pool
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; pool
;
3625 pool
= pool
->next_sym
)
3626 if (pool
->label
== label
)
3632 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3635 get_pool_constant (addr
)
3638 return (find_pool_constant (cfun
, addr
))->constant
;
3641 /* Likewise, but for the constant pool of a specific function. */
3644 get_pool_constant_for_function (f
, addr
)
3648 return (find_pool_constant (f
, addr
))->constant
;
3651 /* Similar, return the mode. */
3654 get_pool_mode (addr
)
3657 return (find_pool_constant (cfun
, addr
))->mode
;
3661 get_pool_mode_for_function (f
, addr
)
3665 return (find_pool_constant (f
, addr
))->mode
;
3668 /* Similar, return the offset in the constant pool. */
3671 get_pool_offset (addr
)
3674 return (find_pool_constant (cfun
, addr
))->offset
;
3677 /* Return the size of the constant pool. */
3685 /* Write all the constants in the constant pool. */
3688 output_constant_pool (fnname
, fndecl
)
3689 const char *fnname ATTRIBUTE_UNUSED
;
3690 tree fndecl ATTRIBUTE_UNUSED
;
3692 struct pool_constant
*pool
;
3694 union real_extract u
;
3696 /* It is possible for gcc to call force_const_mem and then to later
3697 discard the instructions which refer to the constant. In such a
3698 case we do not need to output the constant. */
3699 mark_constant_pool ();
3701 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3702 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3705 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3714 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3715 whose CODE_LABEL has been deleted. This can occur if a jump table
3716 is eliminated by optimization. If so, write a constant of zero
3717 instead. Note that this can also happen by turning the
3718 CODE_LABEL into a NOTE. */
3719 /* ??? This seems completely and utterly wrong. Certainly it's
3720 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3721 functioning even with INSN_DELETED_P and friends. */
3724 switch (GET_CODE (x
))
3727 if (GET_CODE (XEXP (x
, 0)) != PLUS
3728 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3730 tmp
= XEXP (XEXP (x
, 0), 0);
3735 if (INSN_DELETED_P (tmp
)
3736 || (GET_CODE (tmp
) == NOTE
3737 && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_DELETED
))
3748 /* First switch to correct section. */
3749 #ifdef SELECT_RTX_SECTION
3750 SELECT_RTX_SECTION (pool
->mode
, x
);
3752 readonly_data_section ();
3755 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3756 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3757 pool
->align
, pool
->labelno
, done
);
3760 if (pool
->align
> 1)
3761 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (pool
->align
));
3763 /* Output the label. */
3764 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3766 /* Output the value of the constant itself. */
3767 switch (GET_MODE_CLASS (pool
->mode
))
3770 if (GET_CODE (x
) != CONST_DOUBLE
)
3773 memcpy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (x
), sizeof u
);
3774 assemble_real (u
.d
, pool
->mode
);
3778 case MODE_PARTIAL_INT
:
3779 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
3786 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3792 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3793 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3796 /* Done with this pool. */
3797 first_pool
= last_pool
= 0;
3800 /* Look through the instructions for this function, and mark all the
3801 entries in the constant pool which are actually being used. */
3804 mark_constant_pool ()
3807 struct pool_constant
*pool
;
3809 if (first_pool
== 0)
3812 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3815 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3817 mark_constants (PATTERN (insn
));
3819 for (insn
= current_function_epilogue_delay_list
;
3821 insn
= XEXP (insn
, 1))
3823 mark_constants (PATTERN (insn
));
3825 /* It's possible that the only reference to a symbol is in a symbol
3826 that's in the constant pool. This happens in Fortran under some
3827 situations. (When the constant contains the address of another
3828 constant, and only the first is used directly in an insn.)
3829 This is potentially suboptimal if there's ever a possibility of
3830 backwards (in pool order) 2'd level references. However, it's
3831 not clear that 2'd level references can happen. */
3832 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3834 struct pool_constant
*tem
;
3837 /* skip unmarked entries; no insn refers to them. */
3841 /* Skip everything except SYMBOL_REFs. */
3842 if (GET_CODE (pool
->constant
) != SYMBOL_REF
)
3844 label
= XSTR (pool
->constant
, 0);
3846 /* Be sure the symbol's value is marked. */
3847 for (tem
= const_rtx_sym_hash_table
[SYMHASH (label
)]; tem
;
3849 if (tem
->label
== label
)
3851 /* If we didn't find it, there's something truly wrong here, but it
3852 will be announced by the assembler. */
3861 register const char *format_ptr
;
3866 if (GET_CODE (x
) == SYMBOL_REF
)
3868 if (CONSTANT_POOL_ADDRESS_P (x
))
3869 find_pool_constant (cfun
, x
)->mark
= 1;
3872 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3873 a MEM, but does not constitute a use of that MEM. */
3874 else if (GET_CODE (x
) == CONST_DOUBLE
)
3877 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3878 insns, not any notes that may be attached. We don't want to mark
3879 a constant just because it happens to appear in a REG_EQUIV note. */
3882 mark_constants (PATTERN (x
));
3886 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3888 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3890 switch (*format_ptr
++)
3893 mark_constants (XEXP (x
, i
));
3897 if (XVEC (x
, i
) != 0)
3901 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3902 mark_constants (XVECEXP (x
, i
, j
));
3921 /* Find all the constants whose addresses are referenced inside of EXP,
3922 and make sure assembler code with a label has been output for each one.
3923 Indicate whether an ADDR_EXPR has been encountered. */
3926 output_addressed_constants (exp
)
3931 switch (TREE_CODE (exp
))
3935 register tree constant
= TREE_OPERAND (exp
, 0);
3937 while (TREE_CODE (constant
) == COMPONENT_REF
)
3939 constant
= TREE_OPERAND (constant
, 0);
3942 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
3943 || TREE_CODE (constant
) == CONSTRUCTOR
)
3944 /* No need to do anything here
3945 for addresses of variables or functions. */
3946 output_constant_def (constant
);
3953 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3954 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3959 case NON_LVALUE_EXPR
:
3960 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3966 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
3967 if (TREE_VALUE (link
) != 0)
3968 reloc
|= output_addressed_constants (TREE_VALUE (link
));
3978 /* Return nonzero if VALUE is a valid constant-valued expression
3979 for use in initializing a static variable; one that can be an
3980 element of a "constant" initializer.
3982 Return null_pointer_node if the value is absolute;
3983 if it is relocatable, return the variable that determines the relocation.
3984 We assume that VALUE has been folded as much as possible;
3985 therefore, we do not need to check for such things as
3986 arithmetic-combinations of integers. */
3989 initializer_constant_valid_p (value
, endtype
)
3993 /* Give the front-end a chance to convert VALUE to something that
3994 looks more like a constant to the back-end. */
3995 if (lang_expand_constant
)
3996 value
= (*lang_expand_constant
) (value
);
3998 switch (TREE_CODE (value
))
4001 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
4002 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
4003 && TREE_CONSTANT (value
)
4004 && CONSTRUCTOR_ELTS (value
))
4006 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
4009 return TREE_STATIC (value
) ? null_pointer_node
: 0;
4015 return null_pointer_node
;
4018 return staticp (TREE_OPERAND (value
, 0)) ? TREE_OPERAND (value
, 0) : 0;
4020 case NON_LVALUE_EXPR
:
4021 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4025 /* Allow conversions between pointer types. */
4026 if (POINTER_TYPE_P (TREE_TYPE (value
))
4027 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4028 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4030 /* Allow conversions between real types. */
4031 if (FLOAT_TYPE_P (TREE_TYPE (value
))
4032 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4033 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4035 /* Allow length-preserving conversions between integer types. */
4036 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4037 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4038 && (TYPE_PRECISION (TREE_TYPE (value
))
4039 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4040 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4042 /* Allow conversions between other integer types only if
4044 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4045 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4047 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4049 if (inner
== null_pointer_node
)
4050 return null_pointer_node
;
4054 /* Allow (int) &foo provided int is as wide as a pointer. */
4055 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4056 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4057 && (TYPE_PRECISION (TREE_TYPE (value
))
4058 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4059 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4062 /* Likewise conversions from int to pointers, but also allow
4063 conversions from 0. */
4064 if (POINTER_TYPE_P (TREE_TYPE (value
))
4065 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4067 if (integer_zerop (TREE_OPERAND (value
, 0)))
4068 return null_pointer_node
;
4069 else if (TYPE_PRECISION (TREE_TYPE (value
))
4070 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
4071 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4075 /* Allow conversions to union types if the value inside is okay. */
4076 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4077 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4082 if (! INTEGRAL_TYPE_P (endtype
)
4083 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4085 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4087 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4089 /* If either term is absolute, use the other terms relocation. */
4090 if (valid0
== null_pointer_node
)
4092 if (valid1
== null_pointer_node
)
4098 if (! INTEGRAL_TYPE_P (endtype
)
4099 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4101 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4103 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4105 /* Win if second argument is absolute. */
4106 if (valid1
== null_pointer_node
)
4108 /* Win if both arguments have the same relocation.
4109 Then the value is absolute. */
4110 if (valid0
== valid1
&& valid0
!= 0)
4111 return null_pointer_node
;
4114 /* Support differences between labels. */
4115 if (INTEGRAL_TYPE_P (endtype
))
4118 op0
= TREE_OPERAND (value
, 0);
4119 op1
= TREE_OPERAND (value
, 1);
4123 if (TREE_CODE (op0
) == ADDR_EXPR
4124 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
4125 && TREE_CODE (op1
) == ADDR_EXPR
4126 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
4127 return null_pointer_node
;
4138 /* Output assembler code for constant EXP to FILE, with no label.
4139 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4140 Assumes output_addressed_constants has been done on EXP already.
4142 Generate exactly SIZE bytes of assembler data, padding at the end
4143 with zeros if necessary. SIZE must always be specified.
4145 SIZE is important for structure constructors,
4146 since trailing members may have been omitted from the constructor.
4147 It is also important for initialization of arrays from string constants
4148 since the full length of the string constant might not be wanted.
4149 It is also needed for initialization of unions, where the initializer's
4150 type is just one member, and that may not be as long as the union.
4152 There a case in which we would fail to output exactly SIZE bytes:
4153 for a structure constructor that wants to produce more than SIZE bytes.
4154 But such constructors will never be generated for any possible input. */
4157 output_constant (exp
, size
)
4161 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
4163 /* Some front-ends use constants other than the standard
4164 language-indepdent varieties, but which may still be output
4165 directly. Give the front-end a chance to convert EXP to a
4166 language-independent representation. */
4167 if (lang_expand_constant
)
4168 exp
= (*lang_expand_constant
) (exp
);
4170 if (size
== 0 || flag_syntax_only
)
4173 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4174 That way we get the constant (we hope) inside it. Also, strip off any
4175 NOP_EXPR that converts between two record, union, array, or set types
4176 or a CONVERT_EXPR that converts to a union TYPE. */
4177 while ((TREE_CODE (exp
) == NOP_EXPR
4178 && (TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0))
4179 || AGGREGATE_TYPE_P (TREE_TYPE (exp
))))
4180 || (TREE_CODE (exp
) == CONVERT_EXPR
4181 && code
== UNION_TYPE
)
4182 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
4184 exp
= TREE_OPERAND (exp
, 0);
4185 code
= TREE_CODE (TREE_TYPE (exp
));
4188 /* Allow a constructor with no elements for any data type.
4189 This means to fill the space with zeros. */
4190 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
4192 assemble_zeros (size
);
4203 case REFERENCE_TYPE
:
4204 /* ??? What about (int)((float)(int)&foo + 4) */
4205 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
4206 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
4207 exp
= TREE_OPERAND (exp
, 0);
4209 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4210 EXPAND_INITIALIZER
),
4212 error ("initializer for integer value is too complicated");
4217 if (TREE_CODE (exp
) != REAL_CST
)
4218 error ("initializer for floating value is not a floating constant");
4220 assemble_real (TREE_REAL_CST (exp
),
4221 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
4226 output_constant (TREE_REALPART (exp
), size
/ 2);
4227 output_constant (TREE_IMAGPART (exp
), size
/ 2);
4228 size
-= (size
/ 2) * 2;
4232 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4234 output_constructor (exp
, size
);
4237 else if (TREE_CODE (exp
) == STRING_CST
)
4241 if (size
> TREE_STRING_LENGTH (exp
))
4243 excess
= size
- TREE_STRING_LENGTH (exp
);
4244 size
= TREE_STRING_LENGTH (exp
);
4247 assemble_string (TREE_STRING_POINTER (exp
), size
);
4256 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4257 output_constructor (exp
, size
);
4263 if (TREE_CODE (exp
) == INTEGER_CST
)
4264 assemble_integer (expand_expr (exp
, NULL_RTX
,
4265 VOIDmode
, EXPAND_INITIALIZER
),
4267 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4269 unsigned char *buffer
= (unsigned char *) alloca (size
);
4270 if (get_set_constructor_bytes (exp
, buffer
, size
))
4272 assemble_string ((char *) buffer
, size
);
4275 error ("unknown set constructor type");
4283 assemble_zeros (size
);
4287 /* Subroutine of output_constant, used for CONSTRUCTORs
4288 (aggregate constants).
4289 Generate at least SIZE bytes, padding if necessary. */
4292 output_constructor (exp
, size
)
4296 tree type
= TREE_TYPE (exp
);
4297 register tree link
, field
= 0;
4299 /* Number of bytes output or skipped so far.
4300 In other words, current position within the constructor. */
4301 HOST_WIDE_INT total_bytes
= 0;
4302 /* Non-zero means BYTE contains part of a byte, to be output. */
4303 int byte_buffer_in_use
= 0;
4304 register int byte
= 0;
4306 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4309 if (TREE_CODE (type
) == RECORD_TYPE
)
4310 field
= TYPE_FIELDS (type
);
4312 if (TREE_CODE (type
) == ARRAY_TYPE
4313 && TYPE_DOMAIN (type
) != 0)
4314 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
4316 /* As LINK goes through the elements of the constant,
4317 FIELD goes through the structure fields, if the constant is a structure.
4318 if the constant is a union, then we override this,
4319 by getting the field from the TREE_LIST element.
4320 But the constant could also be an array. Then FIELD is zero.
4322 There is always a maximum of one element in the chain LINK for unions
4323 (even if the initializer in a source program incorrectly contains
4325 for (link
= CONSTRUCTOR_ELTS (exp
);
4327 link
= TREE_CHAIN (link
),
4328 field
= field
? TREE_CHAIN (field
) : 0)
4330 tree val
= TREE_VALUE (link
);
4333 /* The element in a union constructor specifies the proper field
4335 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
4336 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4337 && TREE_PURPOSE (link
) != 0)
4338 field
= TREE_PURPOSE (link
);
4340 else if (TREE_CODE (type
) == ARRAY_TYPE
)
4341 index
= TREE_PURPOSE (link
);
4343 /* Eliminate the marker that makes a cast not be an lvalue. */
4347 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4349 register int fieldsize
4350 = int_size_in_bytes (TREE_TYPE (type
));
4351 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
4352 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
4353 HOST_WIDE_INT index
;
4355 for (index
= lo_index
; index
<= hi_index
; index
++)
4357 /* Output the element's initial value. */
4359 assemble_zeros (fieldsize
);
4361 output_constant (val
, fieldsize
);
4363 /* Count its size. */
4364 total_bytes
+= fieldsize
;
4367 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4369 /* An element that is not a bit-field. */
4371 register int fieldsize
;
4372 /* Since this structure is static,
4373 we know the positions are constant. */
4374 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4377 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4378 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4380 /* Output any buffered-up bit-fields preceding this element. */
4381 if (byte_buffer_in_use
)
4383 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4385 byte_buffer_in_use
= 0;
4388 /* Advance to offset of this element.
4389 Note no alignment needed in an array, since that is guaranteed
4390 if each element has the proper size. */
4391 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4393 assemble_zeros (pos
- total_bytes
);
4397 else if (field
!= 0 && DECL_PACKED (field
))
4398 /* Some assemblers automaticallly align a datum according to its
4399 size if no align directive is specified. The datum, however,
4400 may be declared with 'packed' attribute, so we have to disable
4402 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
4404 /* Determine size this element should occupy. */
4406 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4408 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4410 /* Output the element's initial value. */
4412 assemble_zeros (fieldsize
);
4414 output_constant (val
, fieldsize
);
4416 /* Count its size. */
4417 total_bytes
+= fieldsize
;
4419 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4420 error ("invalid initial value for member `%s'",
4421 IDENTIFIER_POINTER (DECL_NAME (field
)));
4424 /* Element that is a bit-field. */
4426 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4427 HOST_WIDE_INT end_offset
4428 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4431 val
= integer_zero_node
;
4433 /* If this field does not start in this (or, next) byte,
4435 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4437 /* Output remnant of any bit field in previous bytes. */
4438 if (byte_buffer_in_use
)
4440 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4442 byte_buffer_in_use
= 0;
4445 /* If still not at proper byte, advance to there. */
4446 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4448 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4449 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4453 if (! byte_buffer_in_use
)
4456 /* We must split the element into pieces that fall within
4457 separate bytes, and combine each byte with previous or
4458 following bit-fields. */
4460 /* next_offset is the offset n fbits from the beginning of
4461 the structure to the next bit of this element to be processed.
4462 end_offset is the offset of the first bit past the end of
4464 while (next_offset
< end_offset
)
4468 HOST_WIDE_INT value
;
4469 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4470 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4472 /* Advance from byte to byte
4473 within this element when necessary. */
4474 while (next_byte
!= total_bytes
)
4476 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4481 /* Number of bits we can process at once
4482 (all part of the same byte). */
4483 this_time
= MIN (end_offset
- next_offset
,
4484 BITS_PER_UNIT
- next_bit
);
4485 if (BYTES_BIG_ENDIAN
)
4487 /* On big-endian machine, take the most significant bits
4488 first (of the bits that are significant)
4489 and put them into bytes from the most significant end. */
4490 shift
= end_offset
- next_offset
- this_time
;
4492 /* Don't try to take a bunch of bits that cross
4493 the word boundary in the INTEGER_CST. We can
4494 only select bits from the LOW or HIGH part
4496 if (shift
< HOST_BITS_PER_WIDE_INT
4497 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4499 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4500 shift
= HOST_BITS_PER_WIDE_INT
;
4503 /* Now get the bits from the appropriate constant word. */
4504 if (shift
< HOST_BITS_PER_WIDE_INT
)
4505 value
= TREE_INT_CST_LOW (val
);
4506 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4508 value
= TREE_INT_CST_HIGH (val
);
4509 shift
-= HOST_BITS_PER_WIDE_INT
;
4514 /* Get the result. This works only when:
4515 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4516 byte
|= (((value
>> shift
)
4517 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4518 << (BITS_PER_UNIT
- this_time
- next_bit
));
4522 /* On little-endian machines,
4523 take first the least significant bits of the value
4524 and pack them starting at the least significant
4525 bits of the bytes. */
4526 shift
= next_offset
- int_bit_position (field
);
4528 /* Don't try to take a bunch of bits that cross
4529 the word boundary in the INTEGER_CST. We can
4530 only select bits from the LOW or HIGH part
4532 if (shift
< HOST_BITS_PER_WIDE_INT
4533 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4534 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4536 /* Now get the bits from the appropriate constant word. */
4537 if (shift
< HOST_BITS_PER_WIDE_INT
)
4538 value
= TREE_INT_CST_LOW (val
);
4539 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4541 value
= TREE_INT_CST_HIGH (val
);
4542 shift
-= HOST_BITS_PER_WIDE_INT
;
4547 /* Get the result. This works only when:
4548 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4549 byte
|= (((value
>> shift
)
4550 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4554 next_offset
+= this_time
;
4555 byte_buffer_in_use
= 1;
4560 if (byte_buffer_in_use
)
4562 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4566 if (total_bytes
< size
)
4567 assemble_zeros (size
- total_bytes
);
4570 #ifdef HANDLE_PRAGMA_WEAK
4571 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4572 associatd with NAME. */
4575 add_weak (name
, value
)
4579 struct weak_syms
*weak
;
4581 weak
= (struct weak_syms
*) permalloc (sizeof (struct weak_syms
));
4586 weak
->next
= weak_decls
;
4588 weak
->value
= value
;
4593 #endif /* HANDLE_PRAGMA_WEAK */
4595 /* Declare DECL to be a weak symbol. */
4601 if (! TREE_PUBLIC (decl
))
4602 error_with_decl (decl
, "weak declaration of `%s' must be public");
4603 else if (TREE_ASM_WRITTEN (decl
))
4604 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4605 else if (SUPPORTS_WEAK
)
4606 DECL_WEAK (decl
) = 1;
4607 #ifdef HANDLE_PRAGMA_WEAK
4608 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), NULL
);
4612 /* Emit any pending weak declarations. */
4614 #ifdef HANDLE_PRAGMA_WEAK
4615 struct weak_syms
* weak_decls
;
4621 #ifdef HANDLE_PRAGMA_WEAK
4622 if (HANDLE_PRAGMA_WEAK
)
4624 struct weak_syms
*t
;
4625 for (t
= weak_decls
; t
; t
= t
->next
)
4629 ASM_WEAKEN_LABEL (asm_out_file
, t
->name
);
4631 ASM_OUTPUT_DEF (asm_out_file
, t
->name
, t
->value
);
4638 /* Remove NAME from the pending list of weak symbols. This prevents
4639 the compiler from emitting multiple .weak directives which confuses
4641 #ifdef ASM_WEAKEN_LABEL
4643 remove_from_pending_weak_list (name
)
4644 const char *name ATTRIBUTE_UNUSED
;
4646 #ifdef HANDLE_PRAGMA_WEAK
4647 if (HANDLE_PRAGMA_WEAK
)
4649 struct weak_syms
*t
;
4650 for (t
= weak_decls
; t
; t
= t
->next
)
4652 if (t
->name
&& strcmp (name
, t
->name
) == 0)
4661 assemble_alias (decl
, target
)
4662 tree decl
, target ATTRIBUTE_UNUSED
;
4666 make_decl_rtl (decl
, (char *) 0, 1);
4667 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4669 #ifdef ASM_OUTPUT_DEF
4670 /* Make name accessible from other files, if appropriate. */
4672 if (TREE_PUBLIC (decl
))
4674 #ifdef ASM_WEAKEN_LABEL
4675 if (DECL_WEAK (decl
))
4677 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4678 /* Remove this function from the pending weak list so that
4679 we do not emit multiple .weak directives for it. */
4680 remove_from_pending_weak_list
4681 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
4685 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4688 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4689 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4691 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4693 TREE_ASM_WRITTEN (decl
) = 1;
4695 #ifdef ASM_OUTPUT_WEAK_ALIAS
4696 if (! DECL_WEAK (decl
))
4697 warning ("only weak aliases are supported in this configuration");
4699 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4700 TREE_ASM_WRITTEN (decl
) = 1;
4702 warning ("alias definitions not supported in this configuration; ignored");
4707 /* This determines whether or not we support link-once semantics. */
4708 #ifndef SUPPORTS_ONE_ONLY
4709 #ifdef MAKE_DECL_ONE_ONLY
4710 #define SUPPORTS_ONE_ONLY 1
4712 #define SUPPORTS_ONE_ONLY 0
4716 /* Returns 1 if the target configuration supports defining public symbols
4717 so that one of them will be chosen at link time instead of generating a
4718 multiply-defined symbol error, whether through the use of weak symbols or
4719 a target-specific mechanism for having duplicates discarded. */
4722 supports_one_only ()
4724 if (SUPPORTS_ONE_ONLY
)
4726 return SUPPORTS_WEAK
;
4729 /* Set up DECL as a public symbol that can be defined in multiple
4730 translation units without generating a linker error. */
4733 make_decl_one_only (decl
)
4736 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
4739 TREE_PUBLIC (decl
) = 1;
4741 if (TREE_CODE (decl
) == VAR_DECL
4742 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4743 DECL_COMMON (decl
) = 1;
4744 else if (SUPPORTS_ONE_ONLY
)
4746 #ifdef MAKE_DECL_ONE_ONLY
4747 MAKE_DECL_ONE_ONLY (decl
);
4749 DECL_ONE_ONLY (decl
) = 1;
4751 else if (SUPPORTS_WEAK
)
4752 DECL_WEAK (decl
) = 1;
4760 ggc_add_root (const_hash_table
, MAX_HASH_TABLE
, sizeof const_hash_table
[0],
4761 mark_const_hash_entry
);
4762 ggc_add_string_root (&in_named_name
, 1);
4765 /* Extra support for EH values. */
4767 assemble_eh_label (name
)
4770 #ifdef ASM_OUTPUT_EH_LABEL
4771 ASM_OUTPUT_EH_LABEL (asm_out_file
, name
);
4773 assemble_label (name
);
4777 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
4780 assemble_eh_align (align
)
4783 #ifdef ASM_OUTPUT_EH_ALIGN
4784 if (align
> BITS_PER_UNIT
)
4785 ASM_OUTPUT_EH_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
4787 assemble_align (align
);
4792 /* On some platforms, we may want to specify a special mechansim to
4793 output EH data when generating with a function.. */
4795 assemble_eh_integer (x
, size
, force
)
4803 #ifdef ASM_OUTPUT_EH_CHAR
4805 ASM_OUTPUT_EH_CHAR (asm_out_file
, x
);
4809 #ifdef ASM_OUTPUT_EH_SHORT
4811 ASM_OUTPUT_EH_SHORT (asm_out_file
, x
);
4815 #ifdef ASM_OUTPUT_EH_INT
4817 ASM_OUTPUT_EH_INT (asm_out_file
, x
);
4821 #ifdef ASM_OUTPUT_EH_DOUBLE_INT
4823 ASM_OUTPUT_EH_DOUBLE_INT (asm_out_file
, x
);
4830 return (assemble_integer (x
, size
, force
));