1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of 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"
50 #ifndef TRAMPOLINE_ALIGNMENT
51 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
55 #define ASM_STABS_OP "\t.stabs\t"
58 /* Define the prefix to use when check_memory_usage_flag is enable. */
59 #define CHKR_PREFIX "_CHKR_"
60 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
62 /* The (assembler) name of the first globally-visible object output. */
63 const char *first_global_object_name
;
64 const char *weak_global_object_name
;
66 extern struct obstack permanent_obstack
;
67 #define obstack_chunk_alloc xmalloc
70 struct constant_descriptor
;
74 #define MAX_RTX_HASH_TABLE 61
78 /* Hash facility for making memory-constants
79 from constant rtl-expressions. It is used on RISC machines
80 where immediate integer arguments and constant addresses are restricted
81 so that such constants must be stored in memory.
83 This pool of constants is reinitialized for each function
84 so each function gets its own constants-pool that comes right before
86 struct constant_descriptor
**x_const_rtx_hash_table
;
87 struct pool_constant
**x_const_rtx_sym_hash_table
;
89 /* Pointers to first and last constant in pool. */
90 struct pool_constant
*x_first_pool
, *x_last_pool
;
92 /* Current offset in constant pool (does not include any machine-specific
96 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
97 They are chained through the CONST_DOUBLE_CHAIN.
98 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
99 In that case, CONST_DOUBLE_MEM is either a MEM,
100 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
101 rtx x_const_double_chain
;
104 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
105 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
106 #define first_pool (cfun->varasm->x_first_pool)
107 #define last_pool (cfun->varasm->x_last_pool)
108 #define pool_offset (cfun->varasm->x_pool_offset)
109 #define const_double_chain (cfun->varasm->x_const_double_chain)
111 /* Number for making the label on the next
112 constant that is stored in memory. */
116 /* Number for making the label on the next
117 static variable internal to a function. */
121 /* Carry information from ASM_DECLARE_OBJECT_NAME
122 to ASM_FINISH_DECLARE_OBJECT. */
124 int size_directive_output
;
126 /* The last decl for which assemble_variable was called,
127 if it did ASM_DECLARE_OBJECT_NAME.
128 If the last call to assemble_variable didn't do that,
131 tree last_assemble_variable_decl
;
133 static const char *strip_reg_name
PARAMS ((const char *));
134 static int contains_pointers_p
PARAMS ((tree
));
135 static void decode_addr_const
PARAMS ((tree
, struct addr_const
*));
136 static int const_hash
PARAMS ((tree
));
137 static int compare_constant
PARAMS ((tree
,
138 struct constant_descriptor
*));
139 static const unsigned char *compare_constant_1
PARAMS ((tree
, const unsigned char *));
140 static struct constant_descriptor
*record_constant
PARAMS ((tree
));
141 static void record_constant_1
PARAMS ((tree
));
142 static tree copy_constant
PARAMS ((tree
));
143 static void output_constant_def_contents
PARAMS ((tree
, int, int));
144 static void decode_rtx_const
PARAMS ((enum machine_mode
, rtx
,
145 struct rtx_const
*));
146 static int const_hash_rtx
PARAMS ((enum machine_mode
, rtx
));
147 static int compare_constant_rtx
PARAMS ((enum machine_mode
, rtx
,
148 struct constant_descriptor
*));
149 static struct constant_descriptor
*record_constant_rtx
PARAMS ((enum machine_mode
,
151 static struct pool_constant
*find_pool_constant
PARAMS ((struct function
*, rtx
));
152 static void mark_constant_pool
PARAMS ((void));
153 static void mark_constants
PARAMS ((rtx
));
154 static int mark_constant
PARAMS ((rtx
*current_rtx
, void *data
));
155 static int output_addressed_constants
PARAMS ((tree
));
156 static void output_after_function_constants
PARAMS ((void));
157 static unsigned HOST_WIDE_INT array_size_for_constructor
PARAMS ((tree
));
158 static void output_constructor
PARAMS ((tree
, int));
159 #ifdef ASM_WEAKEN_LABEL
160 static void remove_from_pending_weak_list
PARAMS ((const char *));
162 #ifdef ASM_OUTPUT_BSS
163 static void asm_output_bss
PARAMS ((FILE *, tree
, const char *, int, int));
165 #ifdef BSS_SECTION_ASM_OP
166 #ifdef ASM_OUTPUT_ALIGNED_BSS
167 static void asm_output_aligned_bss
PARAMS ((FILE *, tree
, const char *,
170 #endif /* BSS_SECTION_ASM_OP */
171 static void mark_pool_constant
PARAMS ((struct pool_constant
*));
172 static void mark_const_hash_entry
PARAMS ((void *));
173 static int mark_const_str_htab_1
PARAMS ((void **, void *));
174 static void mark_const_str_htab
PARAMS ((void *));
175 static hashval_t const_str_htab_hash
PARAMS ((const void *x
));
176 static int const_str_htab_eq
PARAMS ((const void *x
, const void *y
));
177 static void const_str_htab_del
PARAMS ((void *));
178 static void asm_emit_uninitialised
PARAMS ((tree
, const char*, int, int));
180 static enum in_section
{ no_section
, in_text
, in_data
, in_named
181 #ifdef BSS_SECTION_ASM_OP
184 #ifdef EH_FRAME_SECTION_ASM_OP
187 #ifdef EXTRA_SECTIONS
190 } in_section
= no_section
;
192 /* Return a non-zero value if DECL has a section attribute. */
193 #ifndef IN_NAMED_SECTION
194 #define IN_NAMED_SECTION(DECL) \
195 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
196 && DECL_SECTION_NAME (DECL) != NULL_TREE)
199 /* Text of section name when in_section == in_named. */
200 static const char *in_named_name
;
202 /* Define functions like text_section for any extra sections. */
203 #ifdef EXTRA_SECTION_FUNCTIONS
204 EXTRA_SECTION_FUNCTIONS
207 /* Tell assembler to switch to text section. */
212 if (in_section
!= in_text
)
214 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
215 in_section
= in_text
;
219 /* Tell assembler to switch to data section. */
224 if (in_section
!= in_data
)
226 if (flag_shared_data
)
228 #ifdef SHARED_SECTION_ASM_OP
229 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
231 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
235 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
237 in_section
= in_data
;
240 /* Tell assembler to ALWAYS switch to data section, in case
241 it's not sure where it it. */
244 force_data_section ()
246 in_section
= no_section
;
250 /* Tell assembler to switch to read-only data section. This is normally
254 readonly_data_section ()
256 #ifdef READONLY_DATA_SECTION
257 READONLY_DATA_SECTION (); /* Note this can call data_section. */
263 /* Determine if we're in the text section. */
268 return in_section
== in_text
;
271 /* Determine if we're in the data section. */
276 return in_section
== in_data
;
279 /* Tell assembler to change to section NAME for DECL.
280 If DECL is NULL, just switch to section NAME.
281 If NAME is NULL, get the name from DECL.
282 If RELOC is 1, the initializer for DECL contains relocs. */
285 named_section (decl
, name
, reloc
)
288 int reloc ATTRIBUTE_UNUSED
;
290 if (decl
!= NULL_TREE
&& !DECL_P (decl
))
293 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
295 if (in_section
!= in_named
|| strcmp (name
, in_named_name
))
297 #ifdef ASM_OUTPUT_SECTION_NAME
298 ASM_OUTPUT_SECTION_NAME (asm_out_file
, decl
, name
, reloc
);
300 /* Section attributes are not supported if this macro isn't provided -
301 some host formats don't support them at all. The front-end should
302 already have flagged this as an error. */
306 in_named_name
= ggc_strdup (name
);
307 in_section
= in_named
;
311 #ifdef BSS_SECTION_ASM_OP
313 /* Tell the assembler to switch to the bss section. */
318 if (in_section
!= in_bss
)
320 #ifdef SHARED_BSS_SECTION_ASM_OP
321 if (flag_shared_data
)
322 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
325 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
331 #ifdef ASM_OUTPUT_BSS
333 /* Utility function for ASM_OUTPUT_BSS for targets to use if
334 they don't support alignments in .bss.
335 ??? It is believed that this function will work in most cases so such
336 support is localized here. */
339 asm_output_bss (file
, decl
, name
, size
, rounded
)
341 tree decl ATTRIBUTE_UNUSED
;
343 int size ATTRIBUTE_UNUSED
, rounded
;
345 ASM_GLOBALIZE_LABEL (file
, name
);
347 #ifdef ASM_DECLARE_OBJECT_NAME
348 last_assemble_variable_decl
= decl
;
349 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
351 /* Standard thing is just output label for the object. */
352 ASM_OUTPUT_LABEL (file
, name
);
353 #endif /* ASM_DECLARE_OBJECT_NAME */
354 ASM_OUTPUT_SKIP (file
, rounded
);
359 #ifdef ASM_OUTPUT_ALIGNED_BSS
361 /* Utility function for targets to use in implementing
362 ASM_OUTPUT_ALIGNED_BSS.
363 ??? It is believed that this function will work in most cases so such
364 support is localized here. */
367 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
373 ASM_GLOBALIZE_LABEL (file
, name
);
375 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
376 #ifdef ASM_DECLARE_OBJECT_NAME
377 last_assemble_variable_decl
= decl
;
378 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
380 /* Standard thing is just output label for the object. */
381 ASM_OUTPUT_LABEL (file
, name
);
382 #endif /* ASM_DECLARE_OBJECT_NAME */
383 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
388 #endif /* BSS_SECTION_ASM_OP */
390 #ifdef EH_FRAME_SECTION_ASM_OP
394 if (in_section
!= in_eh_frame
)
396 fprintf (asm_out_file
, "%s\n", EH_FRAME_SECTION_ASM_OP
);
397 in_section
= in_eh_frame
;
402 /* Switch to the section for function DECL.
404 If DECL is NULL_TREE, switch to the text section.
405 ??? It's not clear that we will ever be passed NULL_TREE, but it's
406 safer to handle it. */
409 function_section (decl
)
412 if (decl
!= NULL_TREE
413 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
414 named_section (decl
, (char *) 0, 0);
419 /* Switch to section for variable DECL.
421 RELOC is the `reloc' argument to SELECT_SECTION. */
424 variable_section (decl
, reloc
)
428 if (IN_NAMED_SECTION (decl
))
429 named_section (decl
, NULL
, reloc
);
432 /* C++ can have const variables that get initialized from constructors,
433 and thus can not be in a readonly section. We prevent this by
434 verifying that the initial value is constant for objects put in a
437 error_mark_node is used by the C front end to indicate that the
438 initializer has not been seen yet. In this case, we assume that
439 the initializer must be constant.
441 C++ uses error_mark_node for variables that have complicated
442 initializers, but these variables go in BSS so we won't be called
445 #ifdef SELECT_SECTION
446 SELECT_SECTION (decl
, reloc
);
448 if (DECL_READONLY_SECTION (decl
, reloc
))
449 readonly_data_section ();
456 /* Tell assembler to switch to the section for the exception handling
462 #if defined (EXCEPTION_SECTION)
463 EXCEPTION_SECTION ();
465 #ifdef ASM_OUTPUT_SECTION_NAME
466 named_section (NULL_TREE
, ".gcc_except_table", 0);
471 readonly_data_section ();
476 /* Given NAME, a putative register name, discard any customary prefixes. */
479 strip_reg_name (name
)
482 #ifdef REGISTER_PREFIX
483 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
484 name
+= strlen (REGISTER_PREFIX
);
486 if (name
[0] == '%' || name
[0] == '#')
491 /* Decode an `asm' spec for a declaration as a register name.
492 Return the register number, or -1 if nothing specified,
493 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
494 or -3 if ASMSPEC is `cc' and is not recognized,
495 or -4 if ASMSPEC is `memory' and is not recognized.
496 Accept an exact spelling or a decimal number.
497 Prefixes such as % are optional. */
500 decode_reg_name (asmspec
)
507 /* Get rid of confusing prefixes. */
508 asmspec
= strip_reg_name (asmspec
);
510 /* Allow a decimal number as a "register name". */
511 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
512 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
514 if (asmspec
[0] != 0 && i
< 0)
517 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
523 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
525 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
528 #ifdef ADDITIONAL_REGISTER_NAMES
530 static struct { const char *name
; int number
; } table
[]
531 = ADDITIONAL_REGISTER_NAMES
;
533 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
534 if (! strcmp (asmspec
, table
[i
].name
))
535 return table
[i
].number
;
537 #endif /* ADDITIONAL_REGISTER_NAMES */
539 if (!strcmp (asmspec
, "memory"))
542 if (!strcmp (asmspec
, "cc"))
551 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
552 have static storage duration. In other words, it should not be an
553 automatic variable, including PARM_DECLs.
555 There is, however, one exception: this function handles variables
556 explicitly placed in a particular register by the user.
558 ASMSPEC, if not 0, is the string which the user specified as the
559 assembler symbol name.
561 This is never called for PARM_DECL nodes. */
564 make_decl_rtl (decl
, asmspec
)
568 int top_level
= (DECL_CONTEXT (decl
) == NULL_TREE
);
569 const char *name
= 0;
570 const char *new_name
= 0;
573 /* Check that we are not being given an automatic variable. */
574 /* A weak alias has TREE_PUBLIC set but not the other bits. */
575 if (TREE_CODE (decl
) == PARM_DECL
576 || TREE_CODE (decl
) == RESULT_DECL
577 || (TREE_CODE (decl
) == VAR_DECL
578 && !TREE_STATIC (decl
)
579 && !TREE_PUBLIC (decl
)
580 && !DECL_EXTERNAL (decl
)
581 && !DECL_REGISTER (decl
)))
583 /* And that we were not given a type or a label. */
584 else if (TREE_CODE (decl
) == TYPE_DECL
585 || TREE_CODE (decl
) == LABEL_DECL
)
588 /* For a duplicate declaration, we can be called twice on the
589 same DECL node. Don't discard the RTL already made. */
590 if (DECL_RTL_SET_P (decl
))
592 /* If the old RTL had the wrong mode, fix the mode. */
593 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
595 rtx rtl
= DECL_RTL (decl
);
596 PUT_MODE (rtl
, DECL_MODE (decl
));
599 /* ??? Another way to do this would be to do what halfpic.c does
600 and maintain a hashed table of such critters. */
601 /* ??? Another way to do this would be to pass a flag bit to
602 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
603 /* Let the target reassign the RTL if it wants.
604 This is necessary, for example, when one machine specific
605 decl attribute overrides another. */
606 #ifdef REDO_SECTION_INFO_P
607 if (REDO_SECTION_INFO_P (decl
))
608 ENCODE_SECTION_INFO (decl
);
613 new_name
= name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
615 reg_number
= decode_reg_name (asmspec
);
616 if (reg_number
== -2)
618 /* ASMSPEC is given, and not the name of a register. Mark the
619 name with a star so assemble_name won't munge it. */
620 char *starred
= alloca (strlen (asmspec
) + 2);
622 strcpy (starred
+ 1, asmspec
);
626 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
628 /* First detect errors in declaring global registers. */
629 if (reg_number
== -1)
630 error_with_decl (decl
, "register name not specified for `%s'");
631 else if (reg_number
< 0)
632 error_with_decl (decl
, "invalid register name for `%s'");
633 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
634 error_with_decl (decl
,
635 "data type of `%s' isn't suitable for a register");
636 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
637 error_with_decl (decl
,
638 "register specified for `%s' isn't suitable for data type");
639 /* Now handle properly declared static register variables. */
644 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
646 DECL_INITIAL (decl
) = 0;
647 error ("global register variable has initial value");
649 if (TREE_THIS_VOLATILE (decl
))
650 warning ("volatile register variables don't work as you might wish");
652 /* If the user specified one of the eliminables registers here,
653 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
654 confused with that register and be eliminated. Although this
655 usage is somewhat suspect, we nevertheless use the following
656 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
659 gen_rtx_REG (DECL_MODE (decl
),
660 FIRST_PSEUDO_REGISTER
));
661 REGNO (DECL_RTL (decl
)) = reg_number
;
662 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
664 if (TREE_STATIC (decl
))
666 /* Make this register global, so not usable for anything
668 #ifdef ASM_DECLARE_REGISTER_GLOBAL
669 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
671 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
673 globalize_reg (reg_number
+ --nregs
);
676 /* As a register variable, it has no section. */
681 /* Now handle ordinary static variables and functions (in memory).
682 Also handle vars declared register invalidly. */
684 if (reg_number
>= 0 || reg_number
== -3)
685 error_with_decl (decl
,
686 "register name given for non-register variable `%s'");
688 /* Specifying a section attribute on a variable forces it into a
689 non-.bss section, and thus it cannot be common. */
690 if (TREE_CODE (decl
) == VAR_DECL
691 && DECL_SECTION_NAME (decl
) != NULL_TREE
692 && DECL_INITIAL (decl
) == NULL_TREE
693 && DECL_COMMON (decl
))
694 DECL_COMMON (decl
) = 0;
696 /* Can't use just the variable's own name for a variable
697 whose scope is less than the whole file, unless it's a member
698 of a local class (which will already be unambiguous).
699 Concatenate a distinguishing number. */
700 if (!top_level
&& !TREE_PUBLIC (decl
)
701 && ! (DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
)))
703 && name
== IDENTIFIER_POINTER (DECL_NAME (decl
)))
706 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
711 /* When -fprefix-function-name is used, the functions
712 names are prefixed. Only nested function names are not
714 else if (flag_prefix_function_name
&& TREE_CODE (decl
) == FUNCTION_DECL
)
716 size_t name_len
= IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl
));
719 pname
= alloca (name_len
+ CHKR_PREFIX_SIZE
+ 1);
720 memcpy (pname
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
);
721 memcpy (pname
+ CHKR_PREFIX_SIZE
, name
, name_len
+ 1);
725 if (name
!= new_name
)
727 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (new_name
));
728 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
731 /* If this variable is to be treated as volatile, show its
732 tree node has side effects. */
733 if ((flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
734 && TREE_PUBLIC (decl
))
735 || ((flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
736 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))))
737 TREE_SIDE_EFFECTS (decl
) = 1;
739 SET_DECL_RTL (decl
, gen_rtx_MEM (DECL_MODE (decl
),
740 gen_rtx_SYMBOL_REF (Pmode
, name
)));
741 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = DECL_WEAK (decl
);
742 if (TREE_CODE (decl
) != FUNCTION_DECL
)
743 set_mem_attributes (DECL_RTL (decl
), decl
, 1);
745 /* Optionally set flags or add text to the name to record information
746 such as that it is a function name.
747 If the name is changed, the macro ASM_OUTPUT_LABELREF
748 will have to know how to strip this information. */
749 #ifdef ENCODE_SECTION_INFO
750 ENCODE_SECTION_INFO (decl
);
754 /* Make the rtl for variable VAR be volatile.
755 Use this only for static variables. */
758 make_var_volatile (var
)
761 if (GET_CODE (DECL_RTL (var
)) != MEM
)
764 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
767 /* Output alignment directive to align for constant expression EXP. */
770 assemble_constant_align (exp
)
775 /* Align the location counter as required by EXP's data type. */
776 align
= TYPE_ALIGN (TREE_TYPE (exp
));
777 #ifdef CONSTANT_ALIGNMENT
778 align
= CONSTANT_ALIGNMENT (exp
, align
);
781 if (align
> BITS_PER_UNIT
)
782 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
785 /* Output a string of literal assembler code
786 for an `asm' keyword used between functions. */
789 assemble_asm (string
)
794 if (TREE_CODE (string
) == ADDR_EXPR
)
795 string
= TREE_OPERAND (string
, 0);
797 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
800 /* Record an element in the table of global destructors.
801 How this is done depends on what sort of assembler and linker
804 NAME should be the name of a global function to be called
805 at exit time. This name is output using assemble_name. */
808 assemble_destructor (name
)
811 #ifdef ASM_OUTPUT_DESTRUCTOR
812 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
816 /* Now tell GNU LD that this is part of the static destructor set. */
817 /* This code works for any machine provided you use GNU as/ld. */
818 fprintf (asm_out_file
, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
819 assemble_name (asm_out_file
, name
);
820 fputc ('\n', asm_out_file
);
825 /* Likewise for global constructors. */
828 assemble_constructor (name
)
831 #ifdef ASM_OUTPUT_CONSTRUCTOR
832 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
836 /* Now tell GNU LD that this is part of the static constructor set. */
837 /* This code works for any machine provided you use GNU as/ld. */
838 fprintf (asm_out_file
, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
839 assemble_name (asm_out_file
, name
);
840 fputc ('\n', asm_out_file
);
845 /* Likewise for entries we want to record for garbage collection.
846 Garbage collection is still under development. */
849 assemble_gc_entry (name
)
852 #ifdef ASM_OUTPUT_GC_ENTRY
853 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
857 /* Now tell GNU LD that this is part of the static constructor set. */
858 fprintf (asm_out_file
, "%s\"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
859 assemble_name (asm_out_file
, name
);
860 fputc ('\n', asm_out_file
);
865 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
866 a non-zero value if the constant pool should be output before the
867 start of the function, or a zero value if the pool should output
868 after the end of the function. The default is to put it before the
871 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
872 #define CONSTANT_POOL_BEFORE_FUNCTION 1
875 /* Output assembler code for the constant pool of a function and associated
876 with defining the name of the function. DECL describes the function.
877 NAME is the function's name. For the constant pool, we use the current
878 constant pool data. */
881 assemble_start_function (decl
, fnname
)
887 /* The following code does not need preprocessing in the assembler. */
891 if (CONSTANT_POOL_BEFORE_FUNCTION
)
892 output_constant_pool (fnname
, decl
);
894 #ifdef ASM_OUTPUT_SECTION_NAME
895 /* If the function is to be put in its own section and it's not in a section
896 already, indicate so. */
897 if ((flag_function_sections
898 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
899 || UNIQUE_SECTION_P (decl
))
900 UNIQUE_SECTION (decl
, 0);
903 function_section (decl
);
905 /* Tell assembler to move to target machine's alignment for functions. */
906 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
908 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
910 /* Handle a user-specified function alignment.
911 Note that we still need to align to FUNCTION_BOUNDARY, as above,
912 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
913 if (align_functions_log
> align
)
915 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
916 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
917 align_functions_log
, align_functions
-1);
919 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
923 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
924 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
927 (*debug_hooks
->begin_function
) (decl
);
929 /* Make function name accessible from other files, if appropriate. */
931 if (TREE_PUBLIC (decl
))
933 if (! first_global_object_name
)
938 STRIP_NAME_ENCODING (p
, fnname
);
939 name
= permalloc (strlen (p
) + 1);
942 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
943 first_global_object_name
= name
;
945 weak_global_object_name
= name
;
948 #ifdef ASM_WEAKEN_LABEL
949 if (DECL_WEAK (decl
))
951 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
952 /* Remove this function from the pending weak list so that
953 we do not emit multiple .weak directives for it. */
954 remove_from_pending_weak_list
955 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
959 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
962 /* Do any machine/system dependent processing of the function name */
963 #ifdef ASM_DECLARE_FUNCTION_NAME
964 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
966 /* Standard thing is just output label for the function. */
967 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
968 #endif /* ASM_DECLARE_FUNCTION_NAME */
971 /* Output assembler code associated with defining the size of the
972 function. DECL describes the function. NAME is the function's name. */
975 assemble_end_function (decl
, fnname
)
979 #ifdef ASM_DECLARE_FUNCTION_SIZE
980 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
982 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
984 output_constant_pool (fnname
, decl
);
985 function_section (decl
); /* need to switch back */
988 /* Output any constants which should appear after the function. */
989 output_after_function_constants ();
992 /* Assemble code to leave SIZE bytes of zeros. */
995 assemble_zeros (size
)
998 /* Do no output if -fsyntax-only. */
999 if (flag_syntax_only
)
1002 #ifdef ASM_NO_SKIP_IN_TEXT
1003 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1004 so we must output 0s explicitly in the text section. */
1005 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1009 for (i
= 0; i
< size
- 20; i
+= 20)
1012 fprintf (asm_out_file
,
1013 "%s0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP
);
1015 fprintf (asm_out_file
,
1016 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1022 fprintf (asm_out_file
, "%s0", ASM_BYTE_OP
);
1024 fprintf (asm_out_file
, "\tbyte 0");
1027 for (; i
< size
; i
++)
1028 fprintf (asm_out_file
, ",0");
1029 fprintf (asm_out_file
, "\n");
1035 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1038 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1041 assemble_align (align
)
1044 if (align
> BITS_PER_UNIT
)
1045 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1048 /* Assemble a string constant with the specified C string as contents. */
1051 assemble_string (p
, size
)
1058 /* If the string is very long, split it up. */
1062 int thissize
= size
- pos
;
1063 if (thissize
> maximum
)
1066 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1074 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1075 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1076 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1078 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1079 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1080 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1082 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1083 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1087 #if defined ASM_OUTPUT_ALIGNED_BSS
1088 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1089 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1091 #if defined ASM_OUTPUT_BSS
1092 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1093 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1099 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1100 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1101 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1103 #if defined ASM_OUTPUT_ALIGNED_COMMON
1104 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1105 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1107 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1108 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1113 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1116 int size ATTRIBUTE_UNUSED
;
1117 int rounded ATTRIBUTE_UNUSED
;
1125 destination
= asm_dest_local
;
1127 if (TREE_PUBLIC (decl
))
1129 #if defined ASM_EMIT_BSS
1130 if (! DECL_COMMON (decl
))
1131 destination
= asm_dest_bss
;
1134 destination
= asm_dest_common
;
1137 if (flag_shared_data
)
1139 switch (destination
)
1141 #ifdef ASM_OUTPUT_SHARED_BSS
1143 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1146 #ifdef ASM_OUTPUT_SHARED_COMMON
1147 case asm_dest_common
:
1148 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1151 #ifdef ASM_OUTPUT_SHARED_LOCAL
1152 case asm_dest_local
:
1153 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1161 #ifdef ASM_OUTPUT_SECTION_NAME
1162 /* We already know that DECL_SECTION_NAME() == NULL. */
1163 if (flag_data_sections
!= 0 || UNIQUE_SECTION_P (decl
))
1164 UNIQUE_SECTION (decl
, 0);
1167 switch (destination
)
1171 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1174 case asm_dest_common
:
1175 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1177 case asm_dest_local
:
1178 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1187 /* Assemble everything that is needed for a variable or function declaration.
1188 Not used for automatic variables, and not used for function definitions.
1189 Should not be called for variables of incomplete structure type.
1191 TOP_LEVEL is nonzero if this variable has file scope.
1192 AT_END is nonzero if this is the special handling, at end of compilation,
1193 to define things that have had only tentative definitions.
1194 DONT_OUTPUT_DATA if nonzero means don't actually output the
1195 initial value (that will be done by the caller). */
1198 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1200 int top_level ATTRIBUTE_UNUSED
;
1201 int at_end ATTRIBUTE_UNUSED
;
1202 int dont_output_data
;
1204 register const char *name
;
1208 last_assemble_variable_decl
= 0;
1210 /* Normally no need to say anything here for external references,
1211 since assemble_external is called by the language-specific code
1212 when a declaration is first seen. */
1214 if (DECL_EXTERNAL (decl
))
1217 /* Output no assembler code for a function declaration.
1218 Only definitions of functions output anything. */
1220 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1223 /* Do nothing for global register variables. */
1224 if (DECL_RTL_SET_P (decl
) && GET_CODE (DECL_RTL (decl
)) == REG
)
1226 TREE_ASM_WRITTEN (decl
) = 1;
1230 /* If type was incomplete when the variable was declared,
1231 see if it is complete now. */
1233 if (DECL_SIZE (decl
) == 0)
1234 layout_decl (decl
, 0);
1236 /* Still incomplete => don't allocate it; treat the tentative defn
1237 (which is what it must have been) as an `extern' reference. */
1239 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1241 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1242 DECL_SOURCE_LINE (decl
),
1243 "storage size of `%s' isn't known",
1244 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1245 TREE_ASM_WRITTEN (decl
) = 1;
1249 /* The first declaration of a variable that comes through this function
1250 decides whether it is global (in C, has external linkage)
1251 or local (in C, has internal linkage). So do nothing more
1252 if this function has already run. */
1254 if (TREE_ASM_WRITTEN (decl
))
1257 TREE_ASM_WRITTEN (decl
) = 1;
1259 /* Do no output if -fsyntax-only. */
1260 if (flag_syntax_only
)
1265 if (! dont_output_data
1266 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1268 error_with_decl (decl
, "size of variable `%s' is too large");
1272 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1273 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1274 && ! first_global_object_name
1275 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1276 || DECL_INITIAL (decl
) == error_mark_node
))
1277 && ! DECL_WEAK (decl
)
1278 && ! DECL_ONE_ONLY (decl
))
1283 STRIP_NAME_ENCODING (p
, name
);
1284 xname
= permalloc (strlen (p
) + 1);
1286 first_global_object_name
= xname
;
1289 /* Compute the alignment of this data. */
1291 align
= DECL_ALIGN (decl
);
1293 /* In the case for initialing an array whose length isn't specified,
1294 where we have not yet been able to do the layout,
1295 figure out the proper alignment now. */
1296 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1297 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1298 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1300 /* Some object file formats have a maximum alignment which they support.
1301 In particular, a.out format supports a maximum alignment of 4. */
1302 #ifndef MAX_OFILE_ALIGNMENT
1303 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1305 if (align
> MAX_OFILE_ALIGNMENT
)
1307 warning_with_decl (decl
,
1308 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1309 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1310 align
= MAX_OFILE_ALIGNMENT
;
1313 /* On some machines, it is good to increase alignment sometimes. */
1314 #ifdef DATA_ALIGNMENT
1315 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1317 #ifdef CONSTANT_ALIGNMENT
1318 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1319 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1322 /* Reset the alignment in case we have made it tighter, so we can benefit
1323 from it in get_pointer_alignment. */
1324 DECL_ALIGN (decl
) = align
;
1326 /* Handle uninitialized definitions. */
1328 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
)
1329 /* If the target can't output uninitialized but not common global data
1330 in .bss, then we have to use .data. */
1331 #if ! defined ASM_EMIT_BSS
1332 && DECL_COMMON (decl
)
1334 && DECL_SECTION_NAME (decl
) == NULL_TREE
1335 && ! dont_output_data
)
1337 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1338 unsigned HOST_WIDE_INT rounded
= size
;
1340 /* Don't allocate zero bytes of common,
1341 since that means "undefined external" in the linker. */
1345 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1346 so that each uninitialized object starts on such a boundary. */
1347 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1348 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1349 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1351 /* Don't continue this line--convex cc version 4.1 would lose. */
1352 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1353 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN (decl
) / BITS_PER_UNIT
> rounded
)
1355 (decl
, "requested alignment for %s is greater than implemented alignment of %d.",rounded
);
1358 asm_emit_uninitialised (decl
, name
, size
, rounded
);
1363 /* Handle initialized definitions.
1364 Also handle uninitialized global definitions if -fno-common and the
1365 target doesn't support ASM_OUTPUT_BSS. */
1367 /* First make the assembler name(s) global if appropriate. */
1368 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1370 #ifdef ASM_WEAKEN_LABEL
1371 if (DECL_WEAK (decl
))
1373 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1374 /* Remove this variable from the pending weak list so that
1375 we do not emit multiple .weak directives for it. */
1376 remove_from_pending_weak_list
1377 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
1381 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1384 /* Output any data that we will need to use the address of. */
1385 if (DECL_INITIAL (decl
) == error_mark_node
)
1386 reloc
= contains_pointers_p (TREE_TYPE (decl
));
1387 else if (DECL_INITIAL (decl
))
1388 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1390 #ifdef ASM_OUTPUT_SECTION_NAME
1391 if ((flag_data_sections
!= 0 && DECL_SECTION_NAME (decl
) == NULL_TREE
)
1392 || UNIQUE_SECTION_P (decl
))
1393 UNIQUE_SECTION (decl
, reloc
);
1396 /* Switch to the appropriate section. */
1397 variable_section (decl
, reloc
);
1399 /* dbxout.c needs to know this. */
1400 if (in_text_section ())
1401 DECL_IN_TEXT_SECTION (decl
) = 1;
1403 /* Output the alignment of this data. */
1404 if (align
> BITS_PER_UNIT
)
1405 ASM_OUTPUT_ALIGN (asm_out_file
,
1406 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1408 /* Do any machine/system dependent processing of the object. */
1409 #ifdef ASM_DECLARE_OBJECT_NAME
1410 last_assemble_variable_decl
= decl
;
1411 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1413 /* Standard thing is just output label for the object. */
1414 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1415 #endif /* ASM_DECLARE_OBJECT_NAME */
1417 if (!dont_output_data
)
1419 if (DECL_INITIAL (decl
))
1420 /* Output the actual data. */
1421 output_constant (DECL_INITIAL (decl
),
1422 tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1424 /* Leave space for it. */
1425 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1429 /* Return 1 if type TYPE contains any pointers. */
1432 contains_pointers_p (type
)
1435 switch (TREE_CODE (type
))
1438 case REFERENCE_TYPE
:
1439 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1440 so I'll play safe and return 1. */
1446 case QUAL_UNION_TYPE
:
1449 /* For a type that has fields, see if the fields have pointers. */
1450 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1451 if (TREE_CODE (fields
) == FIELD_DECL
1452 && contains_pointers_p (TREE_TYPE (fields
)))
1458 /* An array type contains pointers if its element type does. */
1459 return contains_pointers_p (TREE_TYPE (type
));
1466 /* Output something to declare an external symbol to the assembler.
1467 (Most assemblers don't need this, so we normally output nothing.)
1468 Do nothing if DECL is not external. */
1471 assemble_external (decl
)
1472 tree decl ATTRIBUTE_UNUSED
;
1474 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1475 main body of this code is only rarely exercised. To provide some
1476 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1477 open. If it's not, we should not be calling this function. */
1481 #ifdef ASM_OUTPUT_EXTERNAL
1482 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1484 rtx rtl
= DECL_RTL (decl
);
1486 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1487 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1489 /* Some systems do require some output. */
1490 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1491 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1497 /* Similar, for calling a library function FUN. */
1500 assemble_external_libcall (fun
)
1501 rtx fun ATTRIBUTE_UNUSED
;
1503 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1504 /* Declare library function name external when first used, if nec. */
1505 if (! SYMBOL_REF_USED (fun
))
1507 SYMBOL_REF_USED (fun
) = 1;
1508 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1513 /* Declare the label NAME global. */
1516 assemble_global (name
)
1519 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1522 /* Assemble a label named NAME. */
1525 assemble_label (name
)
1528 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1531 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1532 If NAME starts with a *, the rest of NAME is output verbatim.
1533 Otherwise NAME is transformed in an implementation-defined way
1534 (usually by the addition of an underscore).
1535 Many macros in the tm file are defined to call this function. */
1538 assemble_name (file
, name
)
1542 const char *real_name
;
1545 STRIP_NAME_ENCODING (real_name
, name
);
1546 if (flag_prefix_function_name
1547 && ! memcmp (real_name
, CHKR_PREFIX
, CHKR_PREFIX_SIZE
))
1548 real_name
= real_name
+ CHKR_PREFIX_SIZE
;
1550 id
= maybe_get_identifier (real_name
);
1552 TREE_SYMBOL_REFERENCED (id
) = 1;
1555 fputs (&name
[1], file
);
1557 ASM_OUTPUT_LABELREF (file
, name
);
1560 /* Allocate SIZE bytes writable static space with a gensym name
1561 and return an RTX to refer to its address. */
1564 assemble_static_space (size
)
1568 const char *namestring
;
1572 if (flag_shared_data
)
1576 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1578 namestring
= ggc_strdup (name
);
1580 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1582 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1583 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1586 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1587 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1590 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1591 so that each uninitialized object starts on such a boundary. */
1592 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1593 int rounded ATTRIBUTE_UNUSED
1594 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1595 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1596 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1597 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1604 /* Assemble the static constant template for function entry trampolines.
1605 This is done at most once per compilation.
1606 Returns an RTX for the address of the template. */
1608 #ifdef TRAMPOLINE_TEMPLATE
1610 assemble_trampoline_template ()
1616 /* By default, put trampoline templates in read-only data section. */
1618 #ifdef TRAMPOLINE_SECTION
1619 TRAMPOLINE_SECTION ();
1621 readonly_data_section ();
1624 /* Write the assembler code to define one. */
1625 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1627 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1629 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1630 TRAMPOLINE_TEMPLATE (asm_out_file
);
1632 /* Record the rtl to refer to it. */
1633 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1634 name
= ggc_strdup (label
);
1635 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1639 /* Assemble the integer constant X into an object of SIZE bytes.
1640 X must be either a CONST_INT or CONST_DOUBLE.
1642 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1643 non-zero, abort if we can't output the constant. */
1646 assemble_integer (x
, size
, force
)
1651 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1652 ASM_OUTPUT... macros. */
1656 #ifdef ASM_OUTPUT_CHAR
1658 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1662 #ifdef ASM_OUTPUT_SHORT
1664 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1668 #ifdef ASM_OUTPUT_INT
1670 ASM_OUTPUT_INT (asm_out_file
, x
);
1674 #ifdef ASM_OUTPUT_DOUBLE_INT
1676 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1680 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1682 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1687 /* If we couldn't do it that way, there are two other possibilities: First,
1688 if the machine can output an explicit byte and this is a 1 byte constant,
1689 we can use ASM_OUTPUT_BYTE. */
1691 #ifdef ASM_OUTPUT_BYTE
1692 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1694 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1699 /* Finally, if SIZE is larger than a single word, try to output the constant
1700 one word at a time. */
1702 if (size
> UNITS_PER_WORD
)
1705 enum machine_mode mode
1706 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1709 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1711 word
= operand_subword (x
, i
, 0, mode
);
1716 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1720 if (i
== size
/ UNITS_PER_WORD
)
1722 /* If we output at least one word and then could not finish,
1723 there is no valid way to continue. */
1734 /* Assemble the floating-point constant D into an object of size MODE. */
1737 assemble_real (d
, mode
)
1739 enum machine_mode mode
;
1741 jmp_buf output_constant_handler
;
1743 if (setjmp (output_constant_handler
))
1745 error ("floating point trap outputting a constant");
1746 #ifdef REAL_IS_NOT_DOUBLE
1747 memset ((char *) &d
, 0, sizeof d
);
1754 set_float_handler (output_constant_handler
);
1758 #ifdef ASM_OUTPUT_BYTE_FLOAT
1760 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, d
);
1763 #ifdef ASM_OUTPUT_SHORT_FLOAT
1765 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, d
);
1768 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1770 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, d
);
1773 #ifdef ASM_OUTPUT_FLOAT
1775 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1779 #ifdef ASM_OUTPUT_DOUBLE
1781 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1785 #ifdef ASM_OUTPUT_LONG_DOUBLE
1788 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1796 set_float_handler (NULL
);
1799 /* Here we combine duplicate floating constants to make
1800 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1802 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1803 For an integer, I0 is the low-order word and I1 is the high-order word.
1804 For a real number, I0 is the word with the low address
1805 and I1 is the word with the high address. */
1808 immed_double_const (i0
, i1
, mode
)
1809 HOST_WIDE_INT i0
, i1
;
1810 enum machine_mode mode
;
1814 if (GET_MODE_CLASS (mode
) == MODE_INT
1815 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
1817 /* We clear out all bits that don't belong in MODE, unless they and our
1818 sign bit are all one. So we get either a reasonable negative value
1819 or a reasonable unsigned value for this mode. */
1820 int width
= GET_MODE_BITSIZE (mode
);
1821 if (width
< HOST_BITS_PER_WIDE_INT
1822 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
1823 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
1824 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
1825 else if (width
== HOST_BITS_PER_WIDE_INT
1826 && ! (i1
== ~0 && i0
< 0))
1828 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
1829 /* We cannot represent this value as a constant. */
1832 /* If this would be an entire word for the target, but is not for
1833 the host, then sign-extend on the host so that the number will look
1834 the same way on the host that it would on the target.
1836 For example, when building a 64 bit alpha hosted 32 bit sparc
1837 targeted compiler, then we want the 32 bit unsigned value -1 to be
1838 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1839 The later confuses the sparc backend. */
1841 if (width
< HOST_BITS_PER_WIDE_INT
1842 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
1843 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
1845 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1847 ??? Strictly speaking, this is wrong if we create a CONST_INT
1848 for a large unsigned constant with the size of MODE being
1849 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1850 wider mode. In that case we will mis-interpret it as a negative
1853 Unfortunately, the only alternative is to make a CONST_DOUBLE
1854 for any constant in any mode if it is an unsigned constant larger
1855 than the maximum signed integer in an int on the host. However,
1856 doing this will break everyone that always expects to see a CONST_INT
1857 for SImode and smaller.
1859 We have always been making CONST_INTs in this case, so nothing new
1862 if (width
<= HOST_BITS_PER_WIDE_INT
)
1863 i1
= (i0
< 0) ? ~(HOST_WIDE_INT
) 0 : 0;
1865 /* If this integer fits in one word, return a CONST_INT. */
1866 if ((i1
== 0 && i0
>= 0)
1867 || (i1
== ~0 && i0
< 0))
1868 return GEN_INT (i0
);
1870 /* We use VOIDmode for integers. */
1874 /* Search the chain for an existing CONST_DOUBLE with the right value.
1875 If one is found, return it. */
1877 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1878 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
1879 && GET_MODE (r
) == mode
)
1882 /* No; make a new one and add it to the chain. */
1883 r
= gen_rtx_CONST_DOUBLE (mode
, const0_rtx
, i0
, i1
);
1885 /* Don't touch const_double_chain if not inside any function. */
1886 if (current_function_decl
!= 0)
1888 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1889 const_double_chain
= r
;
1895 /* Return a CONST_DOUBLE for a specified `double' value
1896 and machine mode. */
1899 immed_real_const_1 (d
, mode
)
1901 enum machine_mode mode
;
1903 union real_extract u
;
1906 /* Get the desired `double' value as a sequence of ints
1907 since that is how they are stored in a CONST_DOUBLE. */
1911 /* Detect special cases. But be careful we don't use a CONST_DOUBLE
1912 that's from a parent function since it may be in its constant pool. */
1913 if (REAL_VALUES_IDENTICAL (dconst0
, d
)
1914 && (cfun
== 0 || decl_function_context (current_function_decl
) == 0))
1915 return CONST0_RTX (mode
);
1917 /* Check for NaN first, because some ports (specifically the i386) do not
1918 emit correct ieee-fp code by default, and thus will generate a core
1919 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1920 does a floating point comparison. */
1921 else if ((! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
1923 || decl_function_context (current_function_decl
) == 0))
1924 return CONST1_RTX (mode
);
1926 if (sizeof u
== sizeof (HOST_WIDE_INT
))
1927 return immed_double_const (u
.i
[0], 0, mode
);
1928 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
1929 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
1931 /* The rest of this function handles the case where
1932 a float value requires more than 2 ints of space.
1933 It will be deleted as dead code on machines that don't need it. */
1935 /* Search the chain for an existing CONST_DOUBLE with the right value.
1936 If one is found, return it. */
1938 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1939 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
1940 && GET_MODE (r
) == mode
)
1943 /* No; make a new one and add it to the chain.
1945 We may be called by an optimizer which may be discarding any memory
1946 allocated during its processing (such as combine and loop). However,
1947 we will be leaving this constant on the chain, so we cannot tolerate
1949 r
= rtx_alloc (CONST_DOUBLE
);
1951 memcpy ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
);
1953 /* If we aren't inside a function, don't put r on the
1954 const_double_chain. */
1955 if (current_function_decl
!= 0)
1957 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1958 const_double_chain
= r
;
1961 CONST_DOUBLE_CHAIN (r
) = NULL_RTX
;
1963 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1964 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1965 is only through force_const_mem. */
1967 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1972 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1973 which must be a REAL_CST tree node. */
1976 immed_real_const (exp
)
1979 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
1982 /* At the end of a function, forget the memory-constants
1983 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1984 Also clear out real_constant_chain and clear out all the chain-pointers. */
1987 clear_const_double_mem ()
1989 register rtx r
, next
;
1991 for (r
= const_double_chain
; r
; r
= next
)
1993 next
= CONST_DOUBLE_CHAIN (r
);
1994 CONST_DOUBLE_CHAIN (r
) = 0;
1995 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
1997 const_double_chain
= 0;
2000 /* Given an expression EXP with a constant value,
2001 reduce it to the sum of an assembler symbol and an integer.
2002 Store them both in the structure *VALUE.
2003 Abort if EXP does not reduce. */
2008 HOST_WIDE_INT offset
;
2012 decode_addr_const (exp
, value
)
2014 struct addr_const
*value
;
2016 register tree target
= TREE_OPERAND (exp
, 0);
2017 register int offset
= 0;
2022 if (TREE_CODE (target
) == COMPONENT_REF
2023 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2026 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2027 target
= TREE_OPERAND (target
, 0);
2029 else if (TREE_CODE (target
) == ARRAY_REF
2030 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2032 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2033 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2034 target
= TREE_OPERAND (target
, 0);
2040 switch (TREE_CODE (target
))
2044 x
= DECL_RTL (target
);
2048 x
= gen_rtx_MEM (FUNCTION_MODE
,
2049 gen_rtx_LABEL_REF (VOIDmode
,
2050 label_rtx (TREE_OPERAND (exp
, 0))));
2058 x
= TREE_CST_RTL (target
);
2065 if (GET_CODE (x
) != MEM
)
2070 value
->offset
= offset
;
2073 enum kind
{ RTX_DOUBLE
, RTX_INT
};
2076 ENUM_BITFIELD(kind
) kind
: 16;
2077 ENUM_BITFIELD(machine_mode
) mode
: 16;
2079 union real_extract du
;
2080 struct addr_const addr
;
2081 struct {HOST_WIDE_INT high
, low
;} di
;
2085 /* Uniquize all constants that appear in memory.
2086 Each constant in memory thus far output is recorded
2087 in `const_hash_table' with a `struct constant_descriptor'
2088 that contains a polish representation of the value of
2091 We cannot store the trees in the hash table
2092 because the trees may be temporary. */
2094 struct constant_descriptor
2096 struct constant_descriptor
*next
;
2099 /* Make sure the data is reasonably aligned. */
2102 unsigned char contents
[1];
2103 #ifdef HAVE_LONG_DOUBLE
2112 #define MAX_HASH_TABLE 1009
2113 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2115 #define STRHASH(x) ((hashval_t)((long)(x) >> 3))
2117 struct deferred_string
2124 static htab_t const_str_htab
;
2126 /* Mark a const_hash_table descriptor for GC. */
2129 mark_const_hash_entry (ptr
)
2132 struct constant_descriptor
*desc
= * (struct constant_descriptor
**) ptr
;
2136 ggc_mark_rtx (desc
->rtl
);
2141 /* Mark the hash-table element X (which is really a pointer to an
2142 struct deferred_string *). */
2145 mark_const_str_htab_1 (x
, data
)
2147 void *data ATTRIBUTE_UNUSED
;
2149 ggc_mark_tree (((struct deferred_string
*) *x
)->exp
);
2153 /* Mark a const_str_htab for GC. */
2156 mark_const_str_htab (htab
)
2159 htab_traverse (*((htab_t
*) htab
), mark_const_str_htab_1
, NULL
);
2162 /* Returns a hash code for X (which is a really a
2163 struct deferred_string *). */
2166 const_str_htab_hash (x
)
2169 return STRHASH (((const struct deferred_string
*) x
)->label
);
2172 /* Returns non-zero if the value represented by X (which is really a
2173 struct deferred_string *) is the same as that given by Y
2174 (which is really a char *). */
2177 const_str_htab_eq (x
, y
)
2181 return (((const struct deferred_string
*) x
)->label
== (const char *) y
);
2184 /* Delete the hash table entry dfsp. */
2187 const_str_htab_del (dfsp
)
2193 /* Compute a hash code for a constant expression. */
2199 register const char *p
;
2200 register int len
, hi
, i
;
2201 register enum tree_code code
= TREE_CODE (exp
);
2203 /* Either set P and LEN to the address and len of something to hash and
2204 exit the switch or return a value. */
2209 p
= (char *) &TREE_INT_CST (exp
);
2210 len
= sizeof TREE_INT_CST (exp
);
2214 p
= (char *) &TREE_REAL_CST (exp
);
2215 len
= sizeof TREE_REAL_CST (exp
);
2219 p
= TREE_STRING_POINTER (exp
);
2220 len
= TREE_STRING_LENGTH (exp
);
2224 return (const_hash (TREE_REALPART (exp
)) * 5
2225 + const_hash (TREE_IMAGPART (exp
)));
2228 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2232 len
= int_size_in_bytes (TREE_TYPE (exp
));
2233 tmp
= (char *) alloca (len
);
2234 get_set_constructor_bytes (exp
, (unsigned char *) tmp
, len
);
2242 /* For record type, include the type in the hashing.
2243 We do not do so for array types
2244 because (1) the sizes of the elements are sufficient
2245 and (2) distinct array types can have the same constructor.
2246 Instead, we include the array size because the constructor could
2248 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2249 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2252 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2253 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2255 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2256 if (TREE_VALUE (link
))
2258 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2265 struct addr_const value
;
2267 decode_addr_const (exp
, &value
);
2268 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2270 /* Don't hash the address of the SYMBOL_REF;
2271 only use the offset and the symbol name. */
2273 p
= XSTR (value
.base
, 0);
2274 for (i
= 0; p
[i
] != 0; i
++)
2275 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2277 else if (GET_CODE (value
.base
) == LABEL_REF
)
2278 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2282 hi
&= (1 << HASHBITS
) - 1;
2283 hi
%= MAX_HASH_TABLE
;
2289 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2290 + const_hash (TREE_OPERAND (exp
, 1)));
2294 case NON_LVALUE_EXPR
:
2295 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2298 /* A language specific constant. Just hash the code. */
2299 return (int) code
% MAX_HASH_TABLE
;
2302 /* Compute hashing function */
2304 for (i
= 0; i
< len
; i
++)
2305 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2307 hi
&= (1 << HASHBITS
) - 1;
2308 hi
%= MAX_HASH_TABLE
;
2312 /* Compare a constant expression EXP with a constant-descriptor DESC.
2313 Return 1 if DESC describes a constant with the same value as EXP. */
2316 compare_constant (exp
, desc
)
2318 struct constant_descriptor
*desc
;
2320 return 0 != compare_constant_1 (exp
, desc
->u
.contents
);
2323 /* Compare constant expression EXP with a substring P of a constant descriptor.
2324 If they match, return a pointer to the end of the substring matched.
2325 If they do not match, return 0.
2327 Since descriptors are written in polish prefix notation,
2328 this function can be used recursively to test one operand of EXP
2329 against a subdescriptor, and if it succeeds it returns the
2330 address of the subdescriptor for the next operand. */
2332 static const unsigned char *
2333 compare_constant_1 (exp
, p
)
2335 const unsigned char *p
;
2337 register const unsigned char *strp
;
2339 register enum tree_code code
= TREE_CODE (exp
);
2341 if (code
!= (enum tree_code
) *p
++)
2344 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2345 switch, or return the result of the comparison. */
2350 /* Integer constants are the same only if the same width of type. */
2351 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2354 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2355 len
= sizeof TREE_INT_CST (exp
);
2359 /* Real constants are the same only if the same width of type. */
2360 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2363 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2364 len
= sizeof TREE_REAL_CST (exp
);
2368 if (flag_writable_strings
)
2371 if ((enum machine_mode
) *p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2374 strp
= (const unsigned char *)TREE_STRING_POINTER (exp
);
2375 len
= TREE_STRING_LENGTH (exp
);
2376 if (memcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2377 sizeof TREE_STRING_LENGTH (exp
)))
2380 p
+= sizeof TREE_STRING_LENGTH (exp
);
2384 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2388 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2391 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2393 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2394 unsigned char *tmp
= (unsigned char *) alloca (len
);
2396 get_set_constructor_bytes (exp
, tmp
, len
);
2397 strp
= (unsigned char *) tmp
;
2398 if (memcmp ((char *) &xlen
, p
, sizeof xlen
))
2407 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2409 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2410 int have_purpose
= 0;
2412 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2413 if (TREE_PURPOSE (link
))
2416 if (memcmp ((char *) &length
, p
, sizeof length
))
2421 /* For record constructors, insist that the types match.
2422 For arrays, just verify both constructors are for arrays.
2423 Then insist that either both or none have any TREE_PURPOSE
2425 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2426 type
= TREE_TYPE (exp
);
2430 if (memcmp ((char *) &type
, p
, sizeof type
))
2433 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2435 if (memcmp ((char *) &mode
, p
, sizeof mode
))
2443 if (memcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2446 p
+= sizeof have_purpose
;
2448 /* For arrays, insist that the size in bytes match. */
2449 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2451 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2453 if (memcmp ((char *) &size
, p
, sizeof size
))
2459 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2461 if (TREE_VALUE (link
))
2463 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2470 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2476 if (TREE_PURPOSE (link
)
2477 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2479 if (memcmp ((char *) &TREE_PURPOSE (link
), p
,
2480 sizeof TREE_PURPOSE (link
)))
2483 p
+= sizeof TREE_PURPOSE (link
);
2485 else if (TREE_PURPOSE (link
))
2487 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2490 else if (have_purpose
)
2494 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2506 struct addr_const value
;
2508 decode_addr_const (exp
, &value
);
2509 strp
= (unsigned char *) &value
.offset
;
2510 len
= sizeof value
.offset
;
2511 /* Compare the offset. */
2513 if (*p
++ != *strp
++)
2516 /* Compare symbol name. */
2517 strp
= (const unsigned char *) XSTR (value
.base
, 0);
2518 len
= strlen ((const char *) strp
) + 1;
2525 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2529 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2533 case NON_LVALUE_EXPR
:
2534 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2537 if (lang_expand_constant
)
2539 exp
= (*lang_expand_constant
) (exp
);
2540 return compare_constant_1 (exp
, p
);
2545 /* Compare constant contents. */
2547 if (*p
++ != *strp
++)
2553 /* Construct a constant descriptor for the expression EXP.
2554 It is up to the caller to enter the descriptor in the hash table. */
2556 static struct constant_descriptor
*
2557 record_constant (exp
)
2560 struct constant_descriptor
*next
= 0;
2565 /* Make a struct constant_descriptor. The first three pointers will
2566 be filled in later. Here we just leave space for them. */
2568 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2569 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2570 obstack_grow (&permanent_obstack
, (char *) &rtl
, sizeof rtl
);
2572 /* Align the descriptor for the data payload. */
2573 pad
= (offsetof (struct constant_descriptor
, u
)
2574 - offsetof(struct constant_descriptor
, rtl
)
2575 - sizeof(next
->rtl
));
2577 obstack_blank (&permanent_obstack
, pad
);
2579 record_constant_1 (exp
);
2580 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2583 /* Add a description of constant expression EXP
2584 to the object growing in `permanent_obstack'.
2585 No need to return its address; the caller will get that
2586 from the obstack when the object is complete. */
2589 record_constant_1 (exp
)
2592 register const unsigned char *strp
;
2594 register enum tree_code code
= TREE_CODE (exp
);
2596 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2601 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2602 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2603 len
= sizeof TREE_INT_CST (exp
);
2607 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2608 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2609 len
= sizeof TREE_REAL_CST (exp
);
2613 if (flag_writable_strings
)
2616 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2617 strp
= (const unsigned char *) TREE_STRING_POINTER (exp
);
2618 len
= TREE_STRING_LENGTH (exp
);
2619 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2620 sizeof TREE_STRING_LENGTH (exp
));
2624 record_constant_1 (TREE_REALPART (exp
));
2625 record_constant_1 (TREE_IMAGPART (exp
));
2629 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2631 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2632 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2633 obstack_blank (&permanent_obstack
, nbytes
);
2634 get_set_constructor_bytes
2635 (exp
, (unsigned char *) permanent_obstack
.next_free
-nbytes
,
2642 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2643 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2645 int have_purpose
= 0;
2647 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2648 if (TREE_PURPOSE (link
))
2651 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2653 /* For record constructors, insist that the types match.
2654 For arrays, just verify both constructors are for arrays
2655 of the same mode. Then insist that either both or none
2656 have any TREE_PURPOSE values. */
2657 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2658 type
= TREE_TYPE (exp
);
2662 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2663 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2664 obstack_grow (&permanent_obstack
, &mode
, sizeof mode
);
2666 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2667 sizeof have_purpose
);
2669 /* For arrays, insist that the size in bytes match. */
2670 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2672 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2673 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2676 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2678 if (TREE_VALUE (link
))
2679 record_constant_1 (TREE_VALUE (link
));
2684 obstack_grow (&permanent_obstack
,
2685 (char *) &zero
, sizeof zero
);
2688 if (TREE_PURPOSE (link
)
2689 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2690 obstack_grow (&permanent_obstack
,
2691 (char *) &TREE_PURPOSE (link
),
2692 sizeof TREE_PURPOSE (link
));
2693 else if (TREE_PURPOSE (link
))
2694 record_constant_1 (TREE_PURPOSE (link
));
2695 else if (have_purpose
)
2699 obstack_grow (&permanent_obstack
,
2700 (char *) &zero
, sizeof zero
);
2708 struct addr_const value
;
2710 decode_addr_const (exp
, &value
);
2711 /* Record the offset. */
2712 obstack_grow (&permanent_obstack
,
2713 (char *) &value
.offset
, sizeof value
.offset
);
2715 switch (GET_CODE (value
.base
))
2718 /* Record the symbol name. */
2719 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2720 strlen (XSTR (value
.base
, 0)) + 1);
2723 /* Record the address of the CODE_LABEL. It may not have
2724 been emitted yet, so it's UID may be zero. But pointer
2725 identity is good enough. */
2726 obstack_grow (&permanent_obstack
, &XEXP (value
.base
, 0),
2738 record_constant_1 (TREE_OPERAND (exp
, 0));
2739 record_constant_1 (TREE_OPERAND (exp
, 1));
2744 case NON_LVALUE_EXPR
:
2745 record_constant_1 (TREE_OPERAND (exp
, 0));
2749 if (lang_expand_constant
)
2751 exp
= (*lang_expand_constant
) (exp
);
2752 record_constant_1 (exp
);
2757 /* Record constant contents. */
2758 obstack_grow (&permanent_obstack
, strp
, len
);
2761 /* Record a list of constant expressions that were passed to
2762 output_constant_def but that could not be output right away. */
2764 struct deferred_constant
2766 struct deferred_constant
*next
;
2772 static struct deferred_constant
*deferred_constants
;
2774 /* Another list of constants which should be output after the
2776 static struct deferred_constant
*after_function_constants
;
2778 /* Nonzero means defer output of addressed subconstants
2779 (i.e., those for which output_constant_def is called.) */
2780 static int defer_addressed_constants_flag
;
2782 /* Start deferring output of subconstants. */
2785 defer_addressed_constants ()
2787 defer_addressed_constants_flag
++;
2790 /* Stop deferring output of subconstants,
2791 and output now all those that have been deferred. */
2794 output_deferred_addressed_constants ()
2796 struct deferred_constant
*p
, *next
;
2798 defer_addressed_constants_flag
--;
2800 if (defer_addressed_constants_flag
> 0)
2803 for (p
= deferred_constants
; p
; p
= next
)
2805 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2810 deferred_constants
= 0;
2813 /* Output any constants which should appear after a function. */
2816 output_after_function_constants ()
2818 struct deferred_constant
*p
, *next
;
2820 for (p
= after_function_constants
; p
; p
= next
)
2822 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2827 after_function_constants
= 0;
2830 /* Make a copy of the whole tree structure for a constant.
2831 This handles the same types of nodes that compare_constant
2832 and record_constant handle. */
2838 switch (TREE_CODE (exp
))
2841 /* For ADDR_EXPR, we do not want to copy the decl whose address
2842 is requested. We do want to copy constants though. */
2843 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2844 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2845 copy_constant (TREE_OPERAND (exp
, 0)));
2847 return copy_node (exp
);
2852 return copy_node (exp
);
2855 return build_complex (TREE_TYPE (exp
),
2856 copy_constant (TREE_REALPART (exp
)),
2857 copy_constant (TREE_IMAGPART (exp
)));
2861 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2862 copy_constant (TREE_OPERAND (exp
, 0)),
2863 copy_constant (TREE_OPERAND (exp
, 1)));
2867 case NON_LVALUE_EXPR
:
2868 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2869 copy_constant (TREE_OPERAND (exp
, 0)));
2873 tree copy
= copy_node (exp
);
2874 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2877 CONSTRUCTOR_ELTS (copy
) = list
;
2878 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2879 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2880 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2881 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2882 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
2892 /* Return an rtx representing a reference to constant data in memory
2893 for the constant expression EXP.
2895 If assembler code for such a constant has already been output,
2896 return an rtx to refer to it.
2897 Otherwise, output such a constant in memory (or defer it for later)
2898 and generate an rtx for it.
2900 If DEFER is non-zero, the output of string constants can be deferred
2901 and output only if referenced in the function after all optimizations.
2903 The TREE_CST_RTL of EXP is set up to point to that rtx.
2904 The const_hash_table records which constants already have label strings. */
2907 output_constant_def (exp
, defer
)
2912 register struct constant_descriptor
*desc
;
2913 struct deferred_string
**defstr
;
2917 int after_function
= 0;
2920 if (TREE_CST_RTL (exp
))
2921 return TREE_CST_RTL (exp
);
2923 /* Make sure any other constants whose addresses appear in EXP
2924 are assigned label numbers. */
2926 reloc
= output_addressed_constants (exp
);
2928 /* Compute hash code of EXP. Search the descriptors for that hash code
2929 to see if any of them describes EXP. If yes, the descriptor records
2930 the label number already assigned. */
2932 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
2934 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
2935 if (compare_constant (exp
, desc
))
2940 /* No constant equal to EXP is known to have been output.
2941 Make a constant descriptor to enter EXP in the hash table.
2942 Assign the label number and record it in the descriptor for
2943 future calls to this function to find. */
2945 /* Create a string containing the label name, in LABEL. */
2946 labelno
= const_labelno
++;
2947 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2949 desc
= record_constant (exp
);
2950 desc
->next
= const_hash_table
[hash
];
2951 desc
->label
= ggc_strdup (label
);
2952 const_hash_table
[hash
] = desc
;
2954 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2956 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
2957 gen_rtx_SYMBOL_REF (Pmode
, desc
->label
));
2959 set_mem_attributes (desc
->rtl
, exp
, 1);
2964 TREE_CST_RTL (exp
) = desc
->rtl
;
2966 /* Optionally set flags or add text to the name to record information
2967 such as that it is a function name. If the name is changed, the macro
2968 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2969 #ifdef ENCODE_SECTION_INFO
2970 /* A previously-processed constant would already have section info
2974 ENCODE_SECTION_INFO (exp
);
2975 desc
->rtl
= TREE_CST_RTL (exp
);
2976 desc
->label
= XSTR (XEXP (desc
->rtl
, 0), 0);
2980 #ifdef CONSTANT_AFTER_FUNCTION_P
2981 if (current_function_decl
!= 0
2982 && CONSTANT_AFTER_FUNCTION_P (exp
))
2987 && STRING_POOL_ADDRESS_P (XEXP (desc
->rtl
, 0))
2988 && (!defer
|| defer_addressed_constants_flag
|| after_function
))
2990 defstr
= (struct deferred_string
**)
2991 htab_find_slot_with_hash (const_str_htab
, desc
->label
,
2992 STRHASH (desc
->label
), NO_INSERT
);
2995 /* If the string is currently deferred but we need to output it now,
2996 remove it from deferred string hash table. */
2998 labelno
= (*defstr
)->labelno
;
2999 STRING_POOL_ADDRESS_P (XEXP (desc
->rtl
, 0)) = 0;
3000 htab_clear_slot (const_str_htab
, (void **) defstr
);
3004 /* If this is the first time we've seen this particular constant,
3005 output it (or defer its output for later). */
3008 if (defer_addressed_constants_flag
|| after_function
)
3010 struct deferred_constant
*p
;
3011 p
= (struct deferred_constant
*) xmalloc (sizeof (struct deferred_constant
));
3013 p
->exp
= copy_constant (exp
);
3015 p
->labelno
= labelno
;
3018 p
->next
= after_function_constants
;
3019 after_function_constants
= p
;
3023 p
->next
= deferred_constants
;
3024 deferred_constants
= p
;
3029 /* Do no output if -fsyntax-only. */
3030 if (! flag_syntax_only
)
3032 if (TREE_CODE (exp
) != STRING_CST
3034 || flag_writable_strings
3035 || (defstr
= (struct deferred_string
**)
3036 htab_find_slot_with_hash (const_str_htab
,
3038 STRHASH (desc
->label
),
3040 output_constant_def_contents (exp
, reloc
, labelno
);
3043 struct deferred_string
*p
;
3045 p
= (struct deferred_string
*)
3046 xmalloc (sizeof (struct deferred_string
));
3048 p
->exp
= copy_constant (exp
);
3049 p
->label
= desc
->label
;
3050 p
->labelno
= labelno
;
3052 STRING_POOL_ADDRESS_P (XEXP (desc
->rtl
, 0)) = 1;
3058 return TREE_CST_RTL (exp
);
3061 /* Now output assembler code to define the label for EXP,
3062 and follow it with the data of EXP. */
3065 output_constant_def_contents (exp
, reloc
, labelno
)
3072 if (IN_NAMED_SECTION (exp
))
3073 named_section (exp
, NULL
, reloc
);
3076 /* First switch to text section, except for writable strings. */
3077 #ifdef SELECT_SECTION
3078 SELECT_SECTION (exp
, reloc
);
3080 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
3081 || (flag_pic
&& reloc
))
3084 readonly_data_section ();
3088 /* Align the location counter as required by EXP's data type. */
3089 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3090 #ifdef CONSTANT_ALIGNMENT
3091 align
= CONSTANT_ALIGNMENT (exp
, align
);
3094 if (align
> BITS_PER_UNIT
)
3095 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3097 /* Output the label itself. */
3098 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3100 /* Output the value of EXP. */
3101 output_constant (exp
,
3102 (TREE_CODE (exp
) == STRING_CST
3103 ? TREE_STRING_LENGTH (exp
)
3104 : int_size_in_bytes (TREE_TYPE (exp
))));
3108 /* Structure to represent sufficient information about a constant so that
3109 it can be output when the constant pool is output, so that function
3110 integration can be done, and to simplify handling on machines that reference
3111 constant pool as base+displacement. */
3113 struct pool_constant
3115 struct constant_descriptor
*desc
;
3116 struct pool_constant
*next
, *next_sym
;
3119 enum machine_mode mode
;
3126 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3127 The argument is XSTR (... , 0) */
3129 #define SYMHASH(LABEL) \
3130 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3132 /* Initialize constant pool hashing for a new function. */
3135 init_varasm_status (f
)
3138 struct varasm_status
*p
;
3139 p
= (struct varasm_status
*) xmalloc (sizeof (struct varasm_status
));
3141 p
->x_const_rtx_hash_table
3142 = ((struct constant_descriptor
**)
3143 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct constant_descriptor
*)));
3144 p
->x_const_rtx_sym_hash_table
3145 = ((struct pool_constant
**)
3146 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct pool_constant
*)));
3148 p
->x_first_pool
= p
->x_last_pool
= 0;
3149 p
->x_pool_offset
= 0;
3150 p
->x_const_double_chain
= 0;
3153 /* Mark PC for GC. */
3156 mark_pool_constant (pc
)
3157 struct pool_constant
*pc
;
3162 ggc_mark_rtx (pc
->constant
);
3167 /* Mark P for GC. */
3170 mark_varasm_status (p
)
3171 struct varasm_status
*p
;
3176 mark_pool_constant (p
->x_first_pool
);
3177 ggc_mark_rtx (p
->x_const_double_chain
);
3180 /* Clear out all parts of the state in F that can safely be discarded
3181 after the function has been compiled, to let garbage collection
3182 reclaim the memory. */
3185 free_varasm_status (f
)
3188 struct varasm_status
*p
;
3193 /* Clear out the hash tables. */
3194 for (i
= 0; i
< MAX_RTX_HASH_TABLE
; ++i
)
3196 struct constant_descriptor
* cd
;
3198 cd
= p
->x_const_rtx_hash_table
[i
];
3200 struct constant_descriptor
* next
= cd
->next
;
3206 free (p
->x_const_rtx_hash_table
);
3207 free (p
->x_const_rtx_sym_hash_table
);
3213 /* Express an rtx for a constant integer (perhaps symbolic)
3214 as the sum of a symbol or label plus an explicit integer.
3215 They are stored into VALUE. */
3218 decode_rtx_const (mode
, x
, value
)
3219 enum machine_mode mode
;
3221 struct rtx_const
*value
;
3223 /* Clear the whole structure, including any gaps. */
3224 memset (value
, 0, sizeof (struct rtx_const
));
3226 value
->kind
= RTX_INT
; /* Most usual kind. */
3229 switch (GET_CODE (x
))
3232 value
->kind
= RTX_DOUBLE
;
3233 if (GET_MODE (x
) != VOIDmode
)
3235 value
->mode
= GET_MODE (x
);
3236 memcpy ((char *) &value
->un
.du
,
3237 (char *) &CONST_DOUBLE_LOW (x
), sizeof value
->un
.du
);
3241 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3242 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3247 value
->un
.addr
.offset
= INTVAL (x
);
3253 value
->un
.addr
.base
= x
;
3258 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3260 value
->un
.addr
.base
= XEXP (x
, 0);
3261 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3263 else if (GET_CODE (x
) == MINUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3265 value
->un
.addr
.base
= XEXP (x
, 0);
3266 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3270 value
->un
.addr
.base
= x
;
3271 value
->un
.addr
.offset
= 0;
3279 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3280 switch (GET_CODE (value
->un
.addr
.base
))
3283 /* Use the string's address, not the SYMBOL_REF's address,
3284 for the sake of addresses of library routines. */
3285 value
->un
.addr
.base
= (rtx
) XSTR (value
->un
.addr
.base
, 0);
3289 /* For a LABEL_REF, compare labels. */
3290 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3297 /* Given a MINUS expression, simplify it if both sides
3298 include the same symbol. */
3301 simplify_subtraction (x
)
3304 struct rtx_const val0
, val1
;
3306 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3307 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3309 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3310 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3314 /* Compute a hash code for a constant RTL expression. */
3317 const_hash_rtx (mode
, x
)
3318 enum machine_mode mode
;
3324 struct rtx_const value
;
3325 decode_rtx_const (mode
, x
, &value
);
3327 /* Compute hashing function */
3329 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3330 hi
+= ((int *) &value
)[i
];
3332 hi
&= (1 << HASHBITS
) - 1;
3333 hi
%= MAX_RTX_HASH_TABLE
;
3337 /* Compare a constant rtl object X with a constant-descriptor DESC.
3338 Return 1 if DESC describes a constant with the same value as X. */
3341 compare_constant_rtx (mode
, x
, desc
)
3342 enum machine_mode mode
;
3344 struct constant_descriptor
*desc
;
3346 register int *p
= (int *) desc
->u
.contents
;
3349 struct rtx_const value
;
3351 decode_rtx_const (mode
, x
, &value
);
3352 strp
= (int *) &value
;
3353 len
= sizeof value
/ sizeof (int);
3355 /* Compare constant contents. */
3357 if (*p
++ != *strp
++)
3363 /* Construct a constant descriptor for the rtl-expression X.
3364 It is up to the caller to enter the descriptor in the hash table. */
3366 static struct constant_descriptor
*
3367 record_constant_rtx (mode
, x
)
3368 enum machine_mode mode
;
3371 struct constant_descriptor
*ptr
;
3373 ptr
= ((struct constant_descriptor
*)
3374 xcalloc (1, (offsetof (struct constant_descriptor
, u
)
3375 + sizeof (struct rtx_const
))));
3376 decode_rtx_const (mode
, x
, (struct rtx_const
*) ptr
->u
.contents
);
3381 /* Given a constant rtx X, make (or find) a memory constant for its value
3382 and return a MEM rtx to refer to it in memory. */
3385 force_const_mem (mode
, x
)
3386 enum machine_mode mode
;
3390 register struct constant_descriptor
*desc
;
3392 const char *found
= 0;
3395 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3396 (this will always be true for floating CONST_DOUBLEs that have been
3397 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3398 use the previous copy. Otherwise, make a new one. Note that in
3399 the unlikely event that this same CONST_DOUBLE is used in two different
3400 modes in an alternating fashion, we will allocate a lot of different
3401 memory locations, but this should be extremely rare. */
3403 if (GET_CODE (x
) == CONST_DOUBLE
3404 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
3405 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
3406 return CONST_DOUBLE_MEM (x
);
3408 /* Compute hash code of X. Search the descriptors for that hash code
3409 to see if any of them describes X. If yes, the descriptor records
3410 the label number already assigned. */
3412 hash
= const_hash_rtx (mode
, x
);
3414 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3415 if (compare_constant_rtx (mode
, x
, desc
))
3417 found
= desc
->label
;
3423 register struct pool_constant
*pool
;
3426 /* No constant equal to X is known to have been output.
3427 Make a constant descriptor to enter X in the hash table.
3428 Assign the label number and record it in the descriptor for
3429 future calls to this function to find. */
3431 desc
= record_constant_rtx (mode
, x
);
3432 desc
->next
= const_rtx_hash_table
[hash
];
3433 const_rtx_hash_table
[hash
] = desc
;
3435 /* Align the location counter as required by EXP's data type. */
3436 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
3437 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
3438 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
3439 #ifdef CONSTANT_ALIGNMENT
3440 align
= CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode
, 0), x
),
3441 align
* BITS_PER_UNIT
) / BITS_PER_UNIT
;
3444 pool_offset
+= align
- 1;
3445 pool_offset
&= ~ (align
- 1);
3447 if (GET_CODE (x
) == LABEL_REF
)
3448 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3450 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3452 pool
= (struct pool_constant
*) ggc_alloc (sizeof (struct pool_constant
));
3456 pool
->labelno
= const_labelno
;
3457 pool
->align
= align
;
3458 pool
->offset
= pool_offset
;
3465 last_pool
->next
= pool
;
3468 pool_offset
+= GET_MODE_SIZE (mode
);
3470 /* Create a string containing the label name, in LABEL. */
3471 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3475 desc
->label
= found
= ggc_strdup (label
);
3477 /* Add label to symbol hash table. */
3478 hash
= SYMHASH (found
);
3479 pool
->label
= found
;
3480 pool
->next_sym
= const_rtx_sym_hash_table
[hash
];
3481 const_rtx_sym_hash_table
[hash
] = pool
;
3484 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3486 def
= gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, found
));
3487 set_mem_attributes (def
, type_for_mode (mode
, 0), 1);
3488 RTX_UNCHANGING_P (def
) = 1;
3490 /* Mark the symbol_ref as belonging to this constants pool. */
3491 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3492 current_function_uses_const_pool
= 1;
3494 if (GET_CODE (x
) == CONST_DOUBLE
)
3496 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
3498 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
3499 const_double_chain
= x
;
3501 CONST_DOUBLE_MEM (x
) = def
;
3507 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3508 the corresponding pool_constant structure. */
3510 static struct pool_constant
*
3511 find_pool_constant (f
, addr
)
3515 struct pool_constant
*pool
;
3516 const char *label
= XSTR (addr
, 0);
3518 for (pool
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; pool
;
3519 pool
= pool
->next_sym
)
3520 if (pool
->label
== label
)
3526 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3529 get_pool_constant (addr
)
3532 return (find_pool_constant (cfun
, addr
))->constant
;
3535 /* Likewise, but for the constant pool of a specific function. */
3538 get_pool_constant_for_function (f
, addr
)
3542 return (find_pool_constant (f
, addr
))->constant
;
3545 /* Similar, return the mode. */
3548 get_pool_mode (addr
)
3551 return (find_pool_constant (cfun
, addr
))->mode
;
3555 get_pool_mode_for_function (f
, addr
)
3559 return (find_pool_constant (f
, addr
))->mode
;
3562 /* Similar, return the offset in the constant pool. */
3565 get_pool_offset (addr
)
3568 return (find_pool_constant (cfun
, addr
))->offset
;
3571 /* Return the size of the constant pool. */
3579 /* Write all the constants in the constant pool. */
3582 output_constant_pool (fnname
, fndecl
)
3583 const char *fnname ATTRIBUTE_UNUSED
;
3584 tree fndecl ATTRIBUTE_UNUSED
;
3586 struct pool_constant
*pool
;
3588 union real_extract u
;
3590 /* It is possible for gcc to call force_const_mem and then to later
3591 discard the instructions which refer to the constant. In such a
3592 case we do not need to output the constant. */
3593 mark_constant_pool ();
3595 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3596 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3599 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3608 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3609 whose CODE_LABEL has been deleted. This can occur if a jump table
3610 is eliminated by optimization. If so, write a constant of zero
3611 instead. Note that this can also happen by turning the
3612 CODE_LABEL into a NOTE. */
3613 /* ??? This seems completely and utterly wrong. Certainly it's
3614 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3615 functioning even with INSN_DELETED_P and friends. */
3618 switch (GET_CODE (x
))
3621 if (GET_CODE (XEXP (x
, 0)) != PLUS
3622 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3624 tmp
= XEXP (XEXP (x
, 0), 0);
3629 if (INSN_DELETED_P (tmp
)
3630 || (GET_CODE (tmp
) == NOTE
3631 && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_DELETED
))
3642 /* First switch to correct section. */
3643 #ifdef SELECT_RTX_SECTION
3644 SELECT_RTX_SECTION (pool
->mode
, x
);
3646 readonly_data_section ();
3649 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3650 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3651 pool
->align
, pool
->labelno
, done
);
3654 if (pool
->align
> 1)
3655 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (pool
->align
));
3657 /* Output the label. */
3658 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3660 /* Output the value of the constant itself. */
3661 switch (GET_MODE_CLASS (pool
->mode
))
3664 if (GET_CODE (x
) != CONST_DOUBLE
)
3667 memcpy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (x
), sizeof u
);
3668 assemble_real (u
.d
, pool
->mode
);
3672 case MODE_PARTIAL_INT
:
3673 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
3680 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3686 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3687 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3690 /* Done with this pool. */
3691 first_pool
= last_pool
= 0;
3694 /* Look through the instructions for this function, and mark all the
3695 entries in the constant pool which are actually being used.
3696 Emit used deferred strings. */
3699 mark_constant_pool ()
3702 struct pool_constant
*pool
;
3704 if (first_pool
== 0 && htab_elements (const_str_htab
) == 0)
3707 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3710 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3712 mark_constants (PATTERN (insn
));
3714 for (insn
= current_function_epilogue_delay_list
;
3716 insn
= XEXP (insn
, 1))
3718 mark_constants (PATTERN (insn
));
3721 /* Look through appropriate parts of X, marking all entries in the
3722 constant pool which are actually being used. Entries that are only
3723 referenced by other constants are also marked as used. Emit
3724 deferred strings that are used. */
3731 register const char *format_ptr
;
3736 if (GET_CODE (x
) == SYMBOL_REF
)
3738 mark_constant (&x
, NULL
);
3741 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3742 a MEM, but does not constitute a use of that MEM. */
3743 else if (GET_CODE (x
) == CONST_DOUBLE
)
3746 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3747 insns, not any notes that may be attached. We don't want to mark
3748 a constant just because it happens to appear in a REG_EQUIV note. */
3751 mark_constants (PATTERN (x
));
3755 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3757 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3759 switch (*format_ptr
++)
3762 mark_constants (XEXP (x
, i
));
3766 if (XVEC (x
, i
) != 0)
3770 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3771 mark_constants (XVECEXP (x
, i
, j
));
3790 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3791 to as used. Emit referenced deferred strings. This function can
3792 be used with for_each_rtx () to mark all SYMBOL_REFs in an rtx. */
3795 mark_constant (current_rtx
, data
)
3797 void *data ATTRIBUTE_UNUSED
;
3799 rtx x
= *current_rtx
;
3803 else if (GET_CODE(x
) == CONST_DOUBLE
)
3804 /* Never search inside a CONST_DOUBLE because CONST_DOUBLE_MEM may
3805 be a MEM but does not constitute a use of that MEM. */
3807 else if (GET_CODE (x
) == SYMBOL_REF
)
3809 if (CONSTANT_POOL_ADDRESS_P (x
))
3811 struct pool_constant
*pool
= find_pool_constant (cfun
, x
);
3812 if (pool
->mark
== 0) {
3814 for_each_rtx (&(pool
->constant
), &mark_constant
, NULL
);
3819 else if (STRING_POOL_ADDRESS_P (x
))
3821 struct deferred_string
**defstr
;
3823 defstr
= (struct deferred_string
**)
3824 htab_find_slot_with_hash (const_str_htab
, XSTR (x
, 0),
3825 STRHASH (XSTR (x
, 0)), NO_INSERT
);
3828 struct deferred_string
*p
= *defstr
;
3830 STRING_POOL_ADDRESS_P (x
) = 0;
3831 output_constant_def_contents (p
->exp
, 0, p
->labelno
);
3832 htab_clear_slot (const_str_htab
, (void **) defstr
);
3839 /* Find all the constants whose addresses are referenced inside of EXP,
3840 and make sure assembler code with a label has been output for each one.
3841 Indicate whether an ADDR_EXPR has been encountered. */
3844 output_addressed_constants (exp
)
3849 /* Give the front-end a chance to convert VALUE to something that
3850 looks more like a constant to the back-end. */
3851 if (lang_expand_constant
)
3852 exp
= (*lang_expand_constant
) (exp
);
3854 switch (TREE_CODE (exp
))
3858 register tree constant
= TREE_OPERAND (exp
, 0);
3860 while (TREE_CODE (constant
) == COMPONENT_REF
)
3862 constant
= TREE_OPERAND (constant
, 0);
3865 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
3866 || TREE_CODE (constant
) == CONSTRUCTOR
)
3867 /* No need to do anything here
3868 for addresses of variables or functions. */
3869 output_constant_def (constant
, 0);
3876 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3877 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3882 case NON_LVALUE_EXPR
:
3883 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3889 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
3890 if (TREE_VALUE (link
) != 0)
3891 reloc
|= output_addressed_constants (TREE_VALUE (link
));
3901 /* Return nonzero if VALUE is a valid constant-valued expression
3902 for use in initializing a static variable; one that can be an
3903 element of a "constant" initializer.
3905 Return null_pointer_node if the value is absolute;
3906 if it is relocatable, return the variable that determines the relocation.
3907 We assume that VALUE has been folded as much as possible;
3908 therefore, we do not need to check for such things as
3909 arithmetic-combinations of integers. */
3912 initializer_constant_valid_p (value
, endtype
)
3916 /* Give the front-end a chance to convert VALUE to something that
3917 looks more like a constant to the back-end. */
3918 if (lang_expand_constant
)
3919 value
= (*lang_expand_constant
) (value
);
3921 switch (TREE_CODE (value
))
3924 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
3925 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
3926 && TREE_CONSTANT (value
)
3927 && CONSTRUCTOR_ELTS (value
))
3929 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
3932 return TREE_STATIC (value
) ? null_pointer_node
: 0;
3938 return null_pointer_node
;
3941 return staticp (TREE_OPERAND (value
, 0)) ? TREE_OPERAND (value
, 0) : 0;
3943 case NON_LVALUE_EXPR
:
3944 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3948 /* Allow conversions between pointer types. */
3949 if (POINTER_TYPE_P (TREE_TYPE (value
))
3950 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3951 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3953 /* Allow conversions between real types. */
3954 if (FLOAT_TYPE_P (TREE_TYPE (value
))
3955 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3956 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3958 /* Allow length-preserving conversions between integer types. */
3959 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3960 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
3961 && (TYPE_PRECISION (TREE_TYPE (value
))
3962 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
3963 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3965 /* Allow conversions between other integer types only if
3967 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3968 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3970 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3972 if (inner
== null_pointer_node
)
3973 return null_pointer_node
;
3977 /* Allow (int) &foo provided int is as wide as a pointer. */
3978 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3979 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
3980 && (TYPE_PRECISION (TREE_TYPE (value
))
3981 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
3982 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3985 /* Likewise conversions from int to pointers, but also allow
3986 conversions from 0. */
3987 if (POINTER_TYPE_P (TREE_TYPE (value
))
3988 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3990 if (integer_zerop (TREE_OPERAND (value
, 0)))
3991 return null_pointer_node
;
3992 else if (TYPE_PRECISION (TREE_TYPE (value
))
3993 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
3994 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3998 /* Allow conversions to union types if the value inside is okay. */
3999 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4000 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4005 if (! INTEGRAL_TYPE_P (endtype
)
4006 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4008 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4010 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4012 /* If either term is absolute, use the other terms relocation. */
4013 if (valid0
== null_pointer_node
)
4015 if (valid1
== null_pointer_node
)
4021 if (! INTEGRAL_TYPE_P (endtype
)
4022 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4024 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4026 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4028 /* Win if second argument is absolute. */
4029 if (valid1
== null_pointer_node
)
4031 /* Win if both arguments have the same relocation.
4032 Then the value is absolute. */
4033 if (valid0
== valid1
&& valid0
!= 0)
4034 return null_pointer_node
;
4036 /* Since GCC guarantees that string constants are unique in the
4037 generated code, a subtraction between two copies of the same
4038 constant string is absolute. */
4039 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
&&
4040 valid1
&& TREE_CODE (valid1
) == STRING_CST
&&
4041 TREE_STRING_POINTER (valid0
) == TREE_STRING_POINTER (valid1
))
4042 return null_pointer_node
;
4045 /* Support differences between labels. */
4046 if (INTEGRAL_TYPE_P (endtype
))
4049 op0
= TREE_OPERAND (value
, 0);
4050 op1
= TREE_OPERAND (value
, 1);
4054 if (TREE_CODE (op0
) == ADDR_EXPR
4055 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
4056 && TREE_CODE (op1
) == ADDR_EXPR
4057 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
4058 return null_pointer_node
;
4069 /* Output assembler code for constant EXP to FILE, with no label.
4070 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4071 Assumes output_addressed_constants has been done on EXP already.
4073 Generate exactly SIZE bytes of assembler data, padding at the end
4074 with zeros if necessary. SIZE must always be specified.
4076 SIZE is important for structure constructors,
4077 since trailing members may have been omitted from the constructor.
4078 It is also important for initialization of arrays from string constants
4079 since the full length of the string constant might not be wanted.
4080 It is also needed for initialization of unions, where the initializer's
4081 type is just one member, and that may not be as long as the union.
4083 There a case in which we would fail to output exactly SIZE bytes:
4084 for a structure constructor that wants to produce more than SIZE bytes.
4085 But such constructors will never be generated for any possible input. */
4088 output_constant (exp
, size
)
4092 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
4094 /* Some front-ends use constants other than the standard
4095 language-indepdent varieties, but which may still be output
4096 directly. Give the front-end a chance to convert EXP to a
4097 language-independent representation. */
4098 if (lang_expand_constant
)
4100 exp
= (*lang_expand_constant
) (exp
);
4101 code
= TREE_CODE (TREE_TYPE (exp
));
4104 if (size
== 0 || flag_syntax_only
)
4107 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4108 That way we get the constant (we hope) inside it. Also, strip off any
4109 NOP_EXPR that converts between two record, union, array, or set types
4110 or a CONVERT_EXPR that converts to a union TYPE. */
4111 while ((TREE_CODE (exp
) == NOP_EXPR
4112 && (TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0))
4113 || AGGREGATE_TYPE_P (TREE_TYPE (exp
))))
4114 || (TREE_CODE (exp
) == CONVERT_EXPR
4115 && code
== UNION_TYPE
)
4116 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
4118 exp
= TREE_OPERAND (exp
, 0);
4119 code
= TREE_CODE (TREE_TYPE (exp
));
4122 /* Allow a constructor with no elements for any data type.
4123 This means to fill the space with zeros. */
4124 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
4126 assemble_zeros (size
);
4137 case REFERENCE_TYPE
:
4138 /* ??? What about (int)((float)(int)&foo + 4) */
4139 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
4140 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
4141 exp
= TREE_OPERAND (exp
, 0);
4143 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4144 EXPAND_INITIALIZER
),
4146 error ("initializer for integer value is too complicated");
4151 if (TREE_CODE (exp
) != REAL_CST
)
4152 error ("initializer for floating value is not a floating constant");
4154 assemble_real (TREE_REAL_CST (exp
),
4155 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
4160 output_constant (TREE_REALPART (exp
), size
/ 2);
4161 output_constant (TREE_IMAGPART (exp
), size
/ 2);
4162 size
-= (size
/ 2) * 2;
4166 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4168 output_constructor (exp
, size
);
4171 else if (TREE_CODE (exp
) == STRING_CST
)
4175 if (size
> TREE_STRING_LENGTH (exp
))
4177 excess
= size
- TREE_STRING_LENGTH (exp
);
4178 size
= TREE_STRING_LENGTH (exp
);
4181 assemble_string (TREE_STRING_POINTER (exp
), size
);
4190 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4191 output_constructor (exp
, size
);
4197 if (TREE_CODE (exp
) == INTEGER_CST
)
4198 assemble_integer (expand_expr (exp
, NULL_RTX
,
4199 VOIDmode
, EXPAND_INITIALIZER
),
4201 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4203 unsigned char *buffer
= (unsigned char *) alloca (size
);
4204 if (get_set_constructor_bytes (exp
, buffer
, size
))
4206 assemble_string ((char *) buffer
, size
);
4209 error ("unknown set constructor type");
4217 assemble_zeros (size
);
4221 /* Subroutine of output_constructor, used for computing the size of
4222 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4223 type with an unspecified upper bound. */
4225 static unsigned HOST_WIDE_INT
4226 array_size_for_constructor (val
)
4231 max_index
= NULL_TREE
;
4232 for (i
= CONSTRUCTOR_ELTS (val
); i
; i
= TREE_CHAIN (i
))
4234 tree index
= TREE_PURPOSE (i
);
4236 if (TREE_CODE (index
) == RANGE_EXPR
)
4237 index
= TREE_OPERAND (index
, 1);
4238 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4242 if (max_index
== NULL_TREE
)
4245 /* Compute the total number of array elements. */
4246 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
4248 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
4249 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
4251 /* Multiply by the array element unit size to find number of bytes. */
4252 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4254 return tree_low_cst (i
, 1);
4257 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4258 Generate at least SIZE bytes, padding if necessary. */
4261 output_constructor (exp
, size
)
4265 tree type
= TREE_TYPE (exp
);
4266 register tree link
, field
= 0;
4268 /* Number of bytes output or skipped so far.
4269 In other words, current position within the constructor. */
4270 HOST_WIDE_INT total_bytes
= 0;
4271 /* Non-zero means BYTE contains part of a byte, to be output. */
4272 int byte_buffer_in_use
= 0;
4273 register int byte
= 0;
4275 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4278 if (TREE_CODE (type
) == RECORD_TYPE
)
4279 field
= TYPE_FIELDS (type
);
4281 if (TREE_CODE (type
) == ARRAY_TYPE
4282 && TYPE_DOMAIN (type
) != 0)
4283 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
4285 /* As LINK goes through the elements of the constant,
4286 FIELD goes through the structure fields, if the constant is a structure.
4287 if the constant is a union, then we override this,
4288 by getting the field from the TREE_LIST element.
4289 But the constant could also be an array. Then FIELD is zero.
4291 There is always a maximum of one element in the chain LINK for unions
4292 (even if the initializer in a source program incorrectly contains
4294 for (link
= CONSTRUCTOR_ELTS (exp
);
4296 link
= TREE_CHAIN (link
),
4297 field
= field
? TREE_CHAIN (field
) : 0)
4299 tree val
= TREE_VALUE (link
);
4302 /* The element in a union constructor specifies the proper field
4304 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
4305 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4306 && TREE_PURPOSE (link
) != 0)
4307 field
= TREE_PURPOSE (link
);
4309 else if (TREE_CODE (type
) == ARRAY_TYPE
)
4310 index
= TREE_PURPOSE (link
);
4312 /* Eliminate the marker that makes a cast not be an lvalue. */
4316 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4318 unsigned HOST_WIDE_INT fieldsize
4319 = int_size_in_bytes (TREE_TYPE (type
));
4320 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
4321 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
4322 HOST_WIDE_INT index
;
4324 for (index
= lo_index
; index
<= hi_index
; index
++)
4326 /* Output the element's initial value. */
4328 assemble_zeros (fieldsize
);
4330 output_constant (val
, fieldsize
);
4332 /* Count its size. */
4333 total_bytes
+= fieldsize
;
4336 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4338 /* An element that is not a bit-field. */
4340 unsigned HOST_WIDE_INT fieldsize
;
4341 /* Since this structure is static,
4342 we know the positions are constant. */
4343 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4346 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4347 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4349 /* Output any buffered-up bit-fields preceding this element. */
4350 if (byte_buffer_in_use
)
4352 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4354 byte_buffer_in_use
= 0;
4357 /* Advance to offset of this element.
4358 Note no alignment needed in an array, since that is guaranteed
4359 if each element has the proper size. */
4360 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4362 assemble_zeros (pos
- total_bytes
);
4366 else if (field
!= 0 && DECL_PACKED (field
))
4367 /* Some assemblers automaticallly align a datum according to its
4368 size if no align directive is specified. The datum, however,
4369 may be declared with 'packed' attribute, so we have to disable
4371 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
4373 /* Determine size this element should occupy. */
4378 /* If this is an array with an unspecified upper bound,
4379 the initializer determines the size. */
4380 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4381 but we cannot do this until the deprecated support for
4382 initializing zero-length array members is removed. */
4383 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4384 && TYPE_DOMAIN (TREE_TYPE (field
))
4385 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4387 fieldsize
= array_size_for_constructor (val
);
4388 /* Given a non-empty initialization, this field had
4390 if (fieldsize
!= 0 && TREE_CHAIN (field
) != NULL_TREE
)
4393 else if (DECL_SIZE_UNIT (field
))
4395 /* ??? This can't be right. If the decl size overflows
4396 a host integer we will silently emit no data. */
4397 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4398 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4402 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4404 /* Output the element's initial value. */
4406 assemble_zeros (fieldsize
);
4408 output_constant (val
, fieldsize
);
4410 /* Count its size. */
4411 total_bytes
+= fieldsize
;
4413 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4414 error ("invalid initial value for member `%s'",
4415 IDENTIFIER_POINTER (DECL_NAME (field
)));
4418 /* Element that is a bit-field. */
4420 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4421 HOST_WIDE_INT end_offset
4422 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4425 val
= integer_zero_node
;
4427 /* If this field does not start in this (or, next) byte,
4429 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4431 /* Output remnant of any bit field in previous bytes. */
4432 if (byte_buffer_in_use
)
4434 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4436 byte_buffer_in_use
= 0;
4439 /* If still not at proper byte, advance to there. */
4440 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4442 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4443 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4447 if (! byte_buffer_in_use
)
4450 /* We must split the element into pieces that fall within
4451 separate bytes, and combine each byte with previous or
4452 following bit-fields. */
4454 /* next_offset is the offset n fbits from the beginning of
4455 the structure to the next bit of this element to be processed.
4456 end_offset is the offset of the first bit past the end of
4458 while (next_offset
< end_offset
)
4462 HOST_WIDE_INT value
;
4463 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4464 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4466 /* Advance from byte to byte
4467 within this element when necessary. */
4468 while (next_byte
!= total_bytes
)
4470 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4475 /* Number of bits we can process at once
4476 (all part of the same byte). */
4477 this_time
= MIN (end_offset
- next_offset
,
4478 BITS_PER_UNIT
- next_bit
);
4479 if (BYTES_BIG_ENDIAN
)
4481 /* On big-endian machine, take the most significant bits
4482 first (of the bits that are significant)
4483 and put them into bytes from the most significant end. */
4484 shift
= end_offset
- next_offset
- this_time
;
4486 /* Don't try to take a bunch of bits that cross
4487 the word boundary in the INTEGER_CST. We can
4488 only select bits from the LOW or HIGH part
4490 if (shift
< HOST_BITS_PER_WIDE_INT
4491 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4493 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4494 shift
= HOST_BITS_PER_WIDE_INT
;
4497 /* Now get the bits from the appropriate constant word. */
4498 if (shift
< HOST_BITS_PER_WIDE_INT
)
4499 value
= TREE_INT_CST_LOW (val
);
4500 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4502 value
= TREE_INT_CST_HIGH (val
);
4503 shift
-= HOST_BITS_PER_WIDE_INT
;
4508 /* Get the result. This works only when:
4509 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4510 byte
|= (((value
>> shift
)
4511 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4512 << (BITS_PER_UNIT
- this_time
- next_bit
));
4516 /* On little-endian machines,
4517 take first the least significant bits of the value
4518 and pack them starting at the least significant
4519 bits of the bytes. */
4520 shift
= next_offset
- int_bit_position (field
);
4522 /* Don't try to take a bunch of bits that cross
4523 the word boundary in the INTEGER_CST. We can
4524 only select bits from the LOW or HIGH part
4526 if (shift
< HOST_BITS_PER_WIDE_INT
4527 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4528 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4530 /* Now get the bits from the appropriate constant word. */
4531 if (shift
< HOST_BITS_PER_WIDE_INT
)
4532 value
= TREE_INT_CST_LOW (val
);
4533 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4535 value
= TREE_INT_CST_HIGH (val
);
4536 shift
-= HOST_BITS_PER_WIDE_INT
;
4541 /* Get the result. This works only when:
4542 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4543 byte
|= (((value
>> shift
)
4544 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4548 next_offset
+= this_time
;
4549 byte_buffer_in_use
= 1;
4554 if (byte_buffer_in_use
)
4556 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
4560 if (total_bytes
< size
)
4561 assemble_zeros (size
- total_bytes
);
4564 #ifdef HANDLE_PRAGMA_WEAK
4565 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4566 associatd with NAME. */
4569 add_weak (name
, value
)
4573 struct weak_syms
*weak
;
4575 weak
= (struct weak_syms
*) permalloc (sizeof (struct weak_syms
));
4580 weak
->next
= weak_decls
;
4582 weak
->value
= value
;
4587 #endif /* HANDLE_PRAGMA_WEAK */
4589 /* Declare DECL to be a weak symbol. */
4595 if (! TREE_PUBLIC (decl
))
4596 error_with_decl (decl
, "weak declaration of `%s' must be public");
4597 else if (TREE_ASM_WRITTEN (decl
))
4598 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4599 else if (SUPPORTS_WEAK
)
4600 DECL_WEAK (decl
) = 1;
4601 #ifdef HANDLE_PRAGMA_WEAK
4602 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), NULL
);
4606 /* Emit any pending weak declarations. */
4608 #ifdef HANDLE_PRAGMA_WEAK
4609 struct weak_syms
* weak_decls
;
4615 #ifdef HANDLE_PRAGMA_WEAK
4616 if (HANDLE_PRAGMA_WEAK
)
4618 struct weak_syms
*t
;
4619 for (t
= weak_decls
; t
; t
= t
->next
)
4622 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, t
->name
, t
->value
);
4628 /* Remove NAME from the pending list of weak symbols. This prevents
4629 the compiler from emitting multiple .weak directives which confuses
4631 #ifdef ASM_WEAKEN_LABEL
4633 remove_from_pending_weak_list (name
)
4634 const char *name ATTRIBUTE_UNUSED
;
4636 #ifdef HANDLE_PRAGMA_WEAK
4637 if (HANDLE_PRAGMA_WEAK
)
4639 struct weak_syms
*t
;
4640 for (t
= weak_decls
; t
; t
= t
->next
)
4642 if (t
->name
&& strcmp (name
, t
->name
) == 0)
4651 assemble_alias (decl
, target
)
4652 tree decl
, target ATTRIBUTE_UNUSED
;
4656 /* We must force creation of DECL_RTL for debug info generation, even though
4657 we don't use it here. */
4658 make_decl_rtl (decl
, NULL
);
4660 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4662 #ifdef ASM_OUTPUT_DEF
4663 /* Make name accessible from other files, if appropriate. */
4665 if (TREE_PUBLIC (decl
))
4667 #ifdef ASM_WEAKEN_LABEL
4668 if (DECL_WEAK (decl
))
4670 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4671 /* Remove this function from the pending weak list so that
4672 we do not emit multiple .weak directives for it. */
4673 remove_from_pending_weak_list
4674 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
4678 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4681 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4682 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4684 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4686 TREE_ASM_WRITTEN (decl
) = 1;
4688 #ifdef ASM_OUTPUT_WEAK_ALIAS
4689 if (! DECL_WEAK (decl
))
4690 warning ("only weak aliases are supported in this configuration");
4692 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4693 TREE_ASM_WRITTEN (decl
) = 1;
4695 warning ("alias definitions not supported in this configuration; ignored");
4700 /* Returns 1 if the target configuration supports defining public symbols
4701 so that one of them will be chosen at link time instead of generating a
4702 multiply-defined symbol error, whether through the use of weak symbols or
4703 a target-specific mechanism for having duplicates discarded. */
4706 supports_one_only ()
4708 if (SUPPORTS_ONE_ONLY
)
4710 return SUPPORTS_WEAK
;
4713 /* Set up DECL as a public symbol that can be defined in multiple
4714 translation units without generating a linker error. */
4717 make_decl_one_only (decl
)
4720 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
4723 TREE_PUBLIC (decl
) = 1;
4725 if (TREE_CODE (decl
) == VAR_DECL
4726 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4727 DECL_COMMON (decl
) = 1;
4728 else if (SUPPORTS_ONE_ONLY
)
4730 #ifdef MAKE_DECL_ONE_ONLY
4731 MAKE_DECL_ONE_ONLY (decl
);
4733 DECL_ONE_ONLY (decl
) = 1;
4735 else if (SUPPORTS_WEAK
)
4736 DECL_WEAK (decl
) = 1;
4744 const_str_htab
= htab_create (128, const_str_htab_hash
, const_str_htab_eq
,
4745 const_str_htab_del
);
4746 ggc_add_root (const_hash_table
, MAX_HASH_TABLE
, sizeof const_hash_table
[0],
4747 mark_const_hash_entry
);
4748 ggc_add_root (&const_str_htab
, 1, sizeof const_str_htab
,
4749 mark_const_str_htab
);
4752 /* Extra support for EH values. */
4754 assemble_eh_label (name
)
4757 #ifdef ASM_OUTPUT_EH_LABEL
4758 ASM_OUTPUT_EH_LABEL (asm_out_file
, name
);
4760 assemble_label (name
);
4764 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
4767 assemble_eh_align (align
)
4770 #ifdef ASM_OUTPUT_EH_ALIGN
4771 if (align
> BITS_PER_UNIT
)
4772 ASM_OUTPUT_EH_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
4774 assemble_align (align
);
4779 /* On some platforms, we may want to specify a special mechansim to
4780 output EH data when generating with a function.. */
4782 assemble_eh_integer (x
, size
, force
)
4790 #ifdef ASM_OUTPUT_EH_CHAR
4792 ASM_OUTPUT_EH_CHAR (asm_out_file
, x
);
4796 #ifdef ASM_OUTPUT_EH_SHORT
4798 ASM_OUTPUT_EH_SHORT (asm_out_file
, x
);
4802 #ifdef ASM_OUTPUT_EH_INT
4804 ASM_OUTPUT_EH_INT (asm_out_file
, x
);
4808 #ifdef ASM_OUTPUT_EH_DOUBLE_INT
4810 ASM_OUTPUT_EH_DOUBLE_INT (asm_out_file
, x
);
4817 return (assemble_integer (x
, size
, force
));