[official-gcc.git] / gcc / varasm.c
blobf463d847d4ad742f3d745d5bccabf6cc42c2de4a
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
29 #include "config.h"
30 #include "system.h"
31 #include <setjmp.h>
32 /* #include <stab.h> */
33 #include "rtl.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "except.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "output.h"
40 #include "hard-reg-set.h"
41 #include "regs.h"
42 #include "defaults.h"
43 #include "real.h"
44 #include "toplev.h"
45 #include "dbxout.h"
46 #include "sdbout.h"
48 #include "obstack.h"
49 #include "c-pragma.h"
51 #ifdef XCOFF_DEBUGGING_INFO
52 #include "xcoffout.h"
53 #endif
55 #ifndef TRAMPOLINE_ALIGNMENT
56 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
57 #endif
59 #ifndef ASM_STABS_OP
60 #define ASM_STABS_OP ".stabs"
61 #endif
63 /* Define the prefix to use when check_memory_usage_flag is enable. */
64 #ifdef NO_DOLLAR_IN_LABEL
65 #ifdef NO_DOT_IN_LABEL
66 #define CHKR_PREFIX "chkr_prefix_"
67 #else /* !NO_DOT_IN_LABEL */
68 #define CHKR_PREFIX "chkr."
69 #endif
70 #else /* !NO_DOLLAR_IN_LABEL */
71 #define CHKR_PREFIX "chkr$"
72 #endif
73 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
75 /* File in which assembler code is being written. */
77 extern FILE *asm_out_file;
79 /* The (assembler) name of the first globally-visible object output. */
80 char *first_global_object_name;
81 char *weak_global_object_name;
83 extern struct obstack *current_obstack;
84 extern struct obstack *saveable_obstack;
85 extern struct obstack *rtl_obstack;
86 extern struct obstack permanent_obstack;
87 #define obstack_chunk_alloc xmalloc
89 /* Number for making the label on the next
90 constant that is stored in memory. */
92 int const_labelno;
94 /* Number for making the label on the next
95 static variable internal to a function. */
97 int var_labelno;
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 int size_directive_output;
104 /* The last decl for which assemble_variable was called,
105 if it did ASM_DECLARE_OBJECT_NAME.
106 If the last call to assemble_variable didn't do that,
107 this holds 0. */
109 tree last_assemble_variable_decl;
111 /* Nonzero if at least one function definition has been seen. */
113 static int function_defined;
115 struct addr_const;
116 struct constant_descriptor;
117 struct rtx_const;
118 struct pool_constant;
120 static const char *strip_reg_name PROTO((const char *));
121 static int contains_pointers_p PROTO((tree));
122 static void decode_addr_const PROTO((tree, struct addr_const *));
123 static int const_hash PROTO((tree));
124 static int compare_constant PROTO((tree,
125 struct constant_descriptor *));
126 static char *compare_constant_1 PROTO((tree, char *));
127 static struct constant_descriptor *record_constant PROTO((tree));
128 static void record_constant_1 PROTO((tree));
129 static tree copy_constant PROTO((tree));
130 static void output_constant_def_contents PROTO((tree, int, int));
131 static void decode_rtx_const PROTO((enum machine_mode, rtx,
132 struct rtx_const *));
133 static int const_hash_rtx PROTO((enum machine_mode, rtx));
134 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
135 struct constant_descriptor *));
136 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
137 rtx));
138 static struct pool_constant *find_pool_constant PROTO((rtx));
139 static void mark_constant_pool PROTO((void));
140 static void mark_constants PROTO((rtx));
141 static int output_addressed_constants PROTO((tree));
142 static void output_after_function_constants PROTO((void));
143 static void output_constructor PROTO((tree, int));
144 static void remove_from_pending_weak_list PROTO ((char *));
145 #ifdef ASM_OUTPUT_BSS
146 static void asm_output_bss PROTO((FILE *, tree, char *, int, int));
147 #endif
148 #ifdef BSS_SECTION_ASM_OP
149 #ifdef ASM_OUTPUT_ALIGNED_BSS
150 static void asm_output_aligned_bss PROTO((FILE *, tree, char *, int, int));
151 #endif
152 #endif /* BSS_SECTION_ASM_OP */
154 static enum in_section { no_section, in_text, in_data, in_named
155 #ifdef BSS_SECTION_ASM_OP
156 , in_bss
157 #endif
158 #ifdef EH_FRAME_SECTION_ASM_OP
159 , in_eh_frame
160 #endif
161 #ifdef EXTRA_SECTIONS
162 , EXTRA_SECTIONS
163 #endif
164 } in_section = no_section;
166 /* Return a non-zero value if DECL has a section attribute. */
167 #define IN_NAMED_SECTION(DECL) \
168 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
169 && DECL_SECTION_NAME (DECL) != NULL_TREE)
171 /* Text of section name when in_section == in_named. */
172 static char *in_named_name;
174 /* Define functions like text_section for any extra sections. */
175 #ifdef EXTRA_SECTION_FUNCTIONS
176 EXTRA_SECTION_FUNCTIONS
177 #endif
179 /* Tell assembler to switch to text section. */
181 void
182 text_section ()
184 if (in_section != in_text)
186 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
187 in_section = in_text;
191 /* Tell assembler to switch to data section. */
193 void
194 data_section ()
196 if (in_section != in_data)
198 if (flag_shared_data)
200 #ifdef SHARED_SECTION_ASM_OP
201 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
202 #else
203 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
204 #endif
206 else
207 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
209 in_section = in_data;
212 /* Tell assembler to ALWAYS switch to data section, in case
213 it's not sure where it it. */
215 void
216 force_data_section ()
218 in_section = no_section;
219 data_section ();
222 /* Tell assembler to switch to read-only data section. This is normally
223 the text section. */
225 void
226 readonly_data_section ()
228 #ifdef READONLY_DATA_SECTION
229 READONLY_DATA_SECTION (); /* Note this can call data_section. */
230 #else
231 text_section ();
232 #endif
235 /* Determine if we're in the text section. */
238 in_text_section ()
240 return in_section == in_text;
243 /* Determine if we're in the data section. */
246 in_data_section ()
248 return in_section == in_data;
251 /* Tell assembler to change to section NAME for DECL.
252 If DECL is NULL, just switch to section NAME.
253 If NAME is NULL, get the name from DECL.
254 If RELOC is 1, the initializer for DECL contains relocs. */
256 void
257 named_section (decl, name, reloc)
258 tree decl;
259 const char *name;
260 int reloc ATTRIBUTE_UNUSED;
262 if (decl != NULL_TREE
263 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
264 abort ();
265 if (name == NULL)
266 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
268 if (in_section != in_named || strcmp (name, in_named_name))
270 #ifdef ASM_OUTPUT_SECTION_NAME
271 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
272 #else
273 /* Section attributes are not supported if this macro isn't provided -
274 some host formats don't support them at all. The front-end should
275 already have flagged this as an error. */
276 abort ();
277 #endif
279 in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1);
280 strcpy (in_named_name, name);
281 in_section = in_named;
285 #ifdef ASM_OUTPUT_SECTION_NAME
286 #ifndef UNIQUE_SECTION
287 #define UNIQUE_SECTION(DECL,RELOC) \
288 do { \
289 int len; \
290 char *name, *string; \
292 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
293 /* Strip off any encoding in name. */ \
294 STRIP_NAME_ENCODING (name, name); \
296 len = strlen (name) + 1; \
297 string = alloca (len + 1); \
298 sprintf (string, ".%s", name); \
300 DECL_SECTION_NAME (DECL) = build_string (len, string); \
301 } while (0)
302 #endif
303 #ifndef UNIQUE_SECTION_P
304 #define UNIQUE_SECTION_P(DECL) 0
305 #endif
306 #endif
308 #ifdef BSS_SECTION_ASM_OP
310 /* Tell the assembler to switch to the bss section. */
312 void
313 bss_section ()
315 if (in_section != in_bss)
317 #ifdef SHARED_BSS_SECTION_ASM_OP
318 if (flag_shared_data)
319 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
320 else
321 #endif
322 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
324 in_section = in_bss;
328 #ifdef ASM_OUTPUT_BSS
330 /* Utility function for ASM_OUTPUT_BSS for targets to use if
331 they don't support alignments in .bss.
332 ??? It is believed that this function will work in most cases so such
333 support is localized here. */
335 static void
336 asm_output_bss (file, decl, name, size, rounded)
337 FILE *file;
338 tree decl;
339 char *name;
340 int size, rounded;
342 ASM_GLOBALIZE_LABEL (file, name);
343 bss_section ();
344 #ifdef ASM_DECLARE_OBJECT_NAME
345 last_assemble_variable_decl = decl;
346 ASM_DECLARE_OBJECT_NAME (file, name, decl);
347 #else
348 /* Standard thing is just output label for the object. */
349 ASM_OUTPUT_LABEL (file, name);
350 #endif /* ASM_DECLARE_OBJECT_NAME */
351 ASM_OUTPUT_SKIP (file, rounded);
354 #endif
356 #ifdef ASM_OUTPUT_ALIGNED_BSS
358 /* Utility function for targets to use in implementing
359 ASM_OUTPUT_ALIGNED_BSS.
360 ??? It is believed that this function will work in most cases so such
361 support is localized here. */
363 static void
364 asm_output_aligned_bss (file, decl, name, size, align)
365 FILE *file;
366 tree decl;
367 char *name;
368 int size, align;
370 ASM_GLOBALIZE_LABEL (file, name);
371 bss_section ();
372 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
373 #ifdef ASM_DECLARE_OBJECT_NAME
374 last_assemble_variable_decl = decl;
375 ASM_DECLARE_OBJECT_NAME (file, name, decl);
376 #else
377 /* Standard thing is just output label for the object. */
378 ASM_OUTPUT_LABEL (file, name);
379 #endif /* ASM_DECLARE_OBJECT_NAME */
380 ASM_OUTPUT_SKIP (file, size ? size : 1);
383 #endif
385 #endif /* BSS_SECTION_ASM_OP */
387 #ifdef EH_FRAME_SECTION_ASM_OP
388 void
389 eh_frame_section ()
391 if (in_section != in_eh_frame)
393 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
394 in_section = in_eh_frame;
397 #endif
399 /* Switch to the section for function DECL.
401 If DECL is NULL_TREE, switch to the text section.
402 ??? It's not clear that we will ever be passed NULL_TREE, but it's
403 safer to handle it. */
405 void
406 function_section (decl)
407 tree decl;
409 if (decl != NULL_TREE
410 && DECL_SECTION_NAME (decl) != NULL_TREE)
411 named_section (decl, (char *) 0, 0);
412 else
413 text_section ();
416 /* Switch to section for variable DECL.
418 RELOC is the `reloc' argument to SELECT_SECTION. */
420 void
421 variable_section (decl, reloc)
422 tree decl;
423 int reloc;
425 if (IN_NAMED_SECTION (decl))
426 named_section (decl, NULL, reloc);
427 else
429 /* C++ can have const variables that get initialized from constructors,
430 and thus can not be in a readonly section. We prevent this by
431 verifying that the initial value is constant for objects put in a
432 readonly section.
434 error_mark_node is used by the C front end to indicate that the
435 initializer has not been seen yet. In this case, we assume that
436 the initializer must be constant.
438 C++ uses error_mark_node for variables that have complicated
439 initializers, but these variables go in BSS so we won't be called
440 for them. */
442 #ifdef SELECT_SECTION
443 SELECT_SECTION (decl, reloc);
444 #else
445 if (DECL_READONLY_SECTION (decl, reloc))
446 readonly_data_section ();
447 else
448 data_section ();
449 #endif
453 /* Tell assembler to switch to the section for the exception handling
454 table. */
456 void
457 exception_section ()
459 #if defined (EXCEPTION_SECTION)
460 EXCEPTION_SECTION ();
461 #else
462 #ifdef ASM_OUTPUT_SECTION_NAME
463 named_section (NULL_TREE, ".gcc_except_table", 0);
464 #else
465 if (flag_pic)
466 data_section ();
467 else
468 readonly_data_section ();
469 #endif
470 #endif
473 /* Create the rtl to represent a function, for a function definition.
474 DECL is a FUNCTION_DECL node which describes which function.
475 The rtl is stored into DECL. */
477 void
478 make_function_rtl (decl)
479 tree decl;
481 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
482 char *new_name = name;
484 /* Rename a nested function to avoid conflicts. */
485 if (decl_function_context (decl) != 0
486 && DECL_INITIAL (decl) != 0
487 && DECL_RTL (decl) == 0)
489 char *label;
491 name = IDENTIFIER_POINTER (DECL_NAME (decl));
492 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
493 name = obstack_copy0 (saveable_obstack, label, strlen (label));
494 var_labelno++;
496 else
498 /* When -fprefix-function-name is used, every function name is
499 prefixed. Even static functions are prefixed because they
500 could be declared latter. Note that a nested function name
501 is not prefixed. */
502 if (flag_prefix_function_name)
504 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE + 1);
505 strcpy (new_name, CHKR_PREFIX);
506 strcpy (new_name + CHKR_PREFIX_SIZE, name);
507 name = obstack_copy0 (saveable_obstack, new_name, strlen (new_name));
511 if (DECL_RTL (decl) == 0)
513 DECL_RTL (decl)
514 = gen_rtx_MEM (DECL_MODE (decl),
515 gen_rtx_SYMBOL_REF (Pmode, name));
517 /* Optionally set flags or add text to the name to record information
518 such as that it is a function name. If the name is changed, the macro
519 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
520 #ifdef ENCODE_SECTION_INFO
521 ENCODE_SECTION_INFO (decl);
522 #endif
524 else
526 /* ??? Another way to do this would be to do what halfpic.c does
527 and maintain a hashed table of such critters. */
528 /* ??? Another way to do this would be to pass a flag bit to
529 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
530 /* Let the target reassign the RTL if it wants.
531 This is necessary, for example, when one machine specific
532 decl attribute overrides another. */
533 #ifdef REDO_SECTION_INFO_P
534 if (REDO_SECTION_INFO_P (decl))
535 ENCODE_SECTION_INFO (decl);
536 #endif
539 /* Record at least one function has been defined. */
540 function_defined = 1;
543 /* Given NAME, a putative register name, discard any customary prefixes. */
545 static const char *
546 strip_reg_name (name)
547 const char *name;
549 #ifdef REGISTER_PREFIX
550 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
551 name += strlen (REGISTER_PREFIX);
552 #endif
553 if (name[0] == '%' || name[0] == '#')
554 name++;
555 return name;
558 /* Decode an `asm' spec for a declaration as a register name.
559 Return the register number, or -1 if nothing specified,
560 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
561 or -3 if ASMSPEC is `cc' and is not recognized,
562 or -4 if ASMSPEC is `memory' and is not recognized.
563 Accept an exact spelling or a decimal number.
564 Prefixes such as % are optional. */
567 decode_reg_name (asmspec)
568 const char *asmspec;
570 if (asmspec != 0)
572 int i;
574 /* Get rid of confusing prefixes. */
575 asmspec = strip_reg_name (asmspec);
577 /* Allow a decimal number as a "register name". */
578 for (i = strlen (asmspec) - 1; i >= 0; i--)
579 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
580 break;
581 if (asmspec[0] != 0 && i < 0)
583 i = atoi (asmspec);
584 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
585 return i;
586 else
587 return -2;
590 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
591 if (reg_names[i][0]
592 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
593 return i;
595 #ifdef ADDITIONAL_REGISTER_NAMES
597 static struct { const char *name; int number; } table[]
598 = ADDITIONAL_REGISTER_NAMES;
600 for (i = 0; i < (int)(sizeof (table) / sizeof (table[0])); i++)
601 if (! strcmp (asmspec, table[i].name))
602 return table[i].number;
604 #endif /* ADDITIONAL_REGISTER_NAMES */
606 if (!strcmp (asmspec, "memory"))
607 return -4;
609 if (!strcmp (asmspec, "cc"))
610 return -3;
612 return -2;
615 return -1;
618 /* Create the DECL_RTL for a declaration for a static or external variable
619 or static or external function.
620 ASMSPEC, if not 0, is the string which the user specified
621 as the assembler symbol name.
622 TOP_LEVEL is nonzero if this is a file-scope variable.
624 This is never called for PARM_DECL nodes. */
626 void
627 make_decl_rtl (decl, asmspec, top_level)
628 tree decl;
629 const char *asmspec;
630 int top_level;
632 register char *name = 0;
633 int reg_number;
635 reg_number = decode_reg_name (asmspec);
637 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
638 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
640 if (reg_number == -2)
642 /* ASMSPEC is given, and not the name of a register. */
643 name = (char *) obstack_alloc (saveable_obstack,
644 strlen (asmspec) + 2);
645 name[0] = '*';
646 strcpy (&name[1], asmspec);
649 /* For a duplicate declaration, we can be called twice on the
650 same DECL node. Don't discard the RTL already made. */
651 if (DECL_RTL (decl) == 0)
653 /* First detect errors in declaring global registers. */
654 if (TREE_CODE (decl) != FUNCTION_DECL
655 && DECL_REGISTER (decl) && reg_number == -1)
656 error_with_decl (decl,
657 "register name not specified for `%s'");
658 else if (TREE_CODE (decl) != FUNCTION_DECL
659 && DECL_REGISTER (decl) && reg_number < 0)
660 error_with_decl (decl,
661 "invalid register name for `%s'");
662 else if ((reg_number >= 0 || reg_number == -3)
663 && (TREE_CODE (decl) == FUNCTION_DECL
664 && ! DECL_REGISTER (decl)))
665 error_with_decl (decl,
666 "register name given for non-register variable `%s'");
667 else if (TREE_CODE (decl) != FUNCTION_DECL
668 && DECL_REGISTER (decl)
669 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
670 error_with_decl (decl,
671 "data type of `%s' isn't suitable for a register");
672 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
673 && ! HARD_REGNO_MODE_OK (reg_number,
674 TYPE_MODE (TREE_TYPE (decl))))
675 error_with_decl (decl,
676 "register number for `%s' isn't suitable for data type");
677 /* Now handle properly declared static register variables. */
678 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
680 int nregs;
682 if (DECL_INITIAL (decl) != 0 && top_level)
684 DECL_INITIAL (decl) = 0;
685 error ("global register variable has initial value");
687 if (fixed_regs[reg_number] == 0
688 && function_defined && top_level)
689 error ("global register variable follows a function definition");
690 if (TREE_THIS_VOLATILE (decl))
691 warning ("volatile register variables don't work as you might wish");
693 /* If the user specified one of the eliminables registers here,
694 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
695 confused with that register and be eliminated. Although this
696 usage is somewhat suspect, we nevertheless use the following
697 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
699 DECL_RTL (decl)
700 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
701 REGNO (DECL_RTL (decl)) = reg_number;
702 REG_USERVAR_P (DECL_RTL (decl)) = 1;
704 if (top_level)
706 /* Make this register global, so not usable for anything
707 else. */
708 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
709 while (nregs > 0)
710 globalize_reg (reg_number + --nregs);
713 /* Specifying a section attribute on a variable forces it into a
714 non-.bss section, and thus it cannot be common. */
715 else if (TREE_CODE (decl) == VAR_DECL
716 && DECL_SECTION_NAME (decl) != NULL_TREE
717 && DECL_INITIAL (decl) == NULL_TREE
718 && DECL_COMMON (decl))
719 DECL_COMMON (decl) = 0;
721 /* Now handle ordinary static variables and functions (in memory).
722 Also handle vars declared register invalidly. */
723 if (DECL_RTL (decl) == 0)
725 /* Can't use just the variable's own name for a variable
726 whose scope is less than the whole file.
727 Concatenate a distinguishing number. */
728 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
730 char *label;
732 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
733 name = obstack_copy0 (saveable_obstack, label, strlen (label));
734 var_labelno++;
737 if (name == 0)
738 abort ();
740 /* When -fprefix-function-name is used, the functions
741 names are prefixed. Only nested function names are not
742 prefixed. */
743 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
745 char *new_name;
746 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE
747 + 1);
748 strcpy (new_name, CHKR_PREFIX);
749 strcpy (new_name + CHKR_PREFIX_SIZE, name);
750 name = obstack_copy0 (saveable_obstack,
751 new_name, strlen (new_name));
754 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
755 gen_rtx_SYMBOL_REF (Pmode, name));
756 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
758 /* If this variable is to be treated as volatile, show its
759 tree node has side effects. If it has side effects, either
760 because of this test or from TREE_THIS_VOLATILE also
761 being set, show the MEM is volatile. */
762 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
763 && TREE_PUBLIC (decl))
764 TREE_SIDE_EFFECTS (decl) = 1;
765 else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
766 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
767 TREE_SIDE_EFFECTS (decl) = 1;
769 if (TREE_SIDE_EFFECTS (decl))
770 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
772 if (TREE_READONLY (decl))
773 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
774 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
775 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
777 /* Optionally set flags or add text to the name to record information
778 such as that it is a function name.
779 If the name is changed, the macro ASM_OUTPUT_LABELREF
780 will have to know how to strip this information. */
781 #ifdef ENCODE_SECTION_INFO
782 ENCODE_SECTION_INFO (decl);
783 #endif
786 else
788 /* If the old RTL had the wrong mode, fix the mode. */
789 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
791 rtx rtl = DECL_RTL (decl);
792 PUT_MODE (rtl, DECL_MODE (decl));
795 /* ??? Another way to do this would be to do what halfpic.c does
796 and maintain a hashed table of such critters. */
797 /* ??? Another way to do this would be to pass a flag bit to
798 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
799 /* Let the target reassign the RTL if it wants.
800 This is necessary, for example, when one machine specific
801 decl attribute overrides another. */
802 #ifdef REDO_SECTION_INFO_P
803 if (REDO_SECTION_INFO_P (decl))
804 ENCODE_SECTION_INFO (decl);
805 #endif
809 /* Make the rtl for variable VAR be volatile.
810 Use this only for static variables. */
812 void
813 make_var_volatile (var)
814 tree var;
816 if (GET_CODE (DECL_RTL (var)) != MEM)
817 abort ();
819 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
822 /* Output alignment directive to align for constant expression EXP. */
824 void
825 assemble_constant_align (exp)
826 tree exp;
828 int align;
830 /* Align the location counter as required by EXP's data type. */
831 align = TYPE_ALIGN (TREE_TYPE (exp));
832 #ifdef CONSTANT_ALIGNMENT
833 align = CONSTANT_ALIGNMENT (exp, align);
834 #endif
836 if (align > BITS_PER_UNIT)
837 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
840 /* Output a string of literal assembler code
841 for an `asm' keyword used between functions. */
843 void
844 assemble_asm (string)
845 tree string;
847 app_enable ();
849 if (TREE_CODE (string) == ADDR_EXPR)
850 string = TREE_OPERAND (string, 0);
852 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
855 #if 0 /* This should no longer be needed, because
856 flag_gnu_linker should be 0 on these systems,
857 which should prevent any output
858 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
859 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
860 #ifndef ASM_OUTPUT_CONSTRUCTOR
861 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
862 #endif
863 #ifndef ASM_OUTPUT_DESTRUCTOR
864 #define ASM_OUTPUT_DESTRUCTOR(file, name)
865 #endif
866 #endif
867 #endif /* 0 */
869 /* Record an element in the table of global destructors.
870 How this is done depends on what sort of assembler and linker
871 are in use.
873 NAME should be the name of a global function to be called
874 at exit time. This name is output using assemble_name. */
876 void
877 assemble_destructor (name)
878 char *name;
880 #ifdef ASM_OUTPUT_DESTRUCTOR
881 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
882 #else
883 if (flag_gnu_linker)
885 /* Now tell GNU LD that this is part of the static destructor set. */
886 /* This code works for any machine provided you use GNU as/ld. */
887 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
888 assemble_name (asm_out_file, name);
889 fputc ('\n', asm_out_file);
891 #endif
894 /* Likewise for global constructors. */
896 void
897 assemble_constructor (name)
898 char *name;
900 #ifdef ASM_OUTPUT_CONSTRUCTOR
901 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
902 #else
903 if (flag_gnu_linker)
905 /* Now tell GNU LD that this is part of the static constructor set. */
906 /* This code works for any machine provided you use GNU as/ld. */
907 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
908 assemble_name (asm_out_file, name);
909 fputc ('\n', asm_out_file);
911 #endif
914 /* Likewise for entries we want to record for garbage collection.
915 Garbage collection is still under development. */
917 void
918 assemble_gc_entry (name)
919 char *name;
921 #ifdef ASM_OUTPUT_GC_ENTRY
922 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
923 #else
924 if (flag_gnu_linker)
926 /* Now tell GNU LD that this is part of the static constructor set. */
927 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
928 assemble_name (asm_out_file, name);
929 fputc ('\n', asm_out_file);
931 #endif
934 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
935 a non-zero value if the constant pool should be output before the
936 start of the function, or a zero value if the pool should output
937 after the end of the function. The default is to put it before the
938 start. */
940 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
941 #define CONSTANT_POOL_BEFORE_FUNCTION 1
942 #endif
944 /* Output assembler code for the constant pool of a function and associated
945 with defining the name of the function. DECL describes the function.
946 NAME is the function's name. For the constant pool, we use the current
947 constant pool data. */
949 void
950 assemble_start_function (decl, fnname)
951 tree decl;
952 char *fnname;
954 int align;
956 /* The following code does not need preprocessing in the assembler. */
958 app_disable ();
960 if (CONSTANT_POOL_BEFORE_FUNCTION)
961 output_constant_pool (fnname, decl);
963 #ifdef ASM_OUTPUT_SECTION_NAME
964 /* If the function is to be put in its own section and it's not in a section
965 already, indicate so. */
966 if ((flag_function_sections
967 && DECL_SECTION_NAME (decl) == NULL_TREE)
968 || UNIQUE_SECTION_P (decl))
969 UNIQUE_SECTION (decl, 0);
970 #endif
972 function_section (decl);
974 /* Tell assembler to move to target machine's alignment for functions. */
975 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
976 if (align > 0)
977 ASM_OUTPUT_ALIGN (asm_out_file, align);
979 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
980 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
981 #endif
983 #ifdef SDB_DEBUGGING_INFO
984 /* Output SDB definition of the function. */
985 if (write_symbols == SDB_DEBUG)
986 sdbout_mark_begin_function ();
987 #endif
989 #ifdef DBX_DEBUGGING_INFO
990 /* Output DBX definition of the function. */
991 if (write_symbols == DBX_DEBUG)
992 dbxout_begin_function (decl);
993 #endif
995 /* Make function name accessible from other files, if appropriate. */
997 if (TREE_PUBLIC (decl))
999 if (! first_global_object_name)
1001 char *p;
1002 char **name;
1004 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1005 name = &first_global_object_name;
1006 else
1007 name = &weak_global_object_name;
1009 STRIP_NAME_ENCODING (p, fnname);
1010 *name = permalloc (strlen (p) + 1);
1011 strcpy (*name, p);
1014 #ifdef ASM_WEAKEN_LABEL
1015 if (DECL_WEAK (decl))
1017 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1018 /* Remove this function from the pending weak list so that
1019 we do not emit multiple .weak directives for it. */
1020 remove_from_pending_weak_list
1021 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1023 else
1024 #endif
1025 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1028 /* Do any machine/system dependent processing of the function name */
1029 #ifdef ASM_DECLARE_FUNCTION_NAME
1030 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1031 #else
1032 /* Standard thing is just output label for the function. */
1033 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1034 #endif /* ASM_DECLARE_FUNCTION_NAME */
1037 /* Output assembler code associated with defining the size of the
1038 function. DECL describes the function. NAME is the function's name. */
1040 void
1041 assemble_end_function (decl, fnname)
1042 tree decl;
1043 char *fnname;
1045 #ifdef ASM_DECLARE_FUNCTION_SIZE
1046 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1047 #endif
1048 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1050 output_constant_pool (fnname, decl);
1051 function_section (decl); /* need to switch back */
1054 /* Output any constants which should appear after the function. */
1055 output_after_function_constants ();
1058 /* Assemble code to leave SIZE bytes of zeros. */
1060 void
1061 assemble_zeros (size)
1062 int size;
1064 /* Do no output if -fsyntax-only. */
1065 if (flag_syntax_only)
1066 return;
1068 #ifdef ASM_NO_SKIP_IN_TEXT
1069 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1070 so we must output 0s explicitly in the text section. */
1071 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1073 int i;
1075 for (i = 0; i < size - 20; i += 20)
1077 #ifdef ASM_BYTE_OP
1078 fprintf (asm_out_file,
1079 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
1080 #else
1081 fprintf (asm_out_file,
1082 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1083 #endif
1085 if (i < size)
1087 #ifdef ASM_BYTE_OP
1088 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1089 #else
1090 fprintf (asm_out_file, "\tbyte 0");
1091 #endif
1092 i++;
1093 for (; i < size; i++)
1094 fprintf (asm_out_file, ",0");
1095 fprintf (asm_out_file, "\n");
1098 else
1099 #endif
1100 if (size > 0)
1101 ASM_OUTPUT_SKIP (asm_out_file, size);
1104 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1106 void
1107 assemble_align (align)
1108 int align;
1110 if (align > BITS_PER_UNIT)
1111 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1114 /* Assemble a string constant with the specified C string as contents. */
1116 void
1117 assemble_string (p, size)
1118 const char *p;
1119 int size;
1121 int pos = 0;
1122 int maximum = 2000;
1124 /* If the string is very long, split it up. */
1126 while (pos < size)
1128 int thissize = size - pos;
1129 if (thissize > maximum)
1130 thissize = maximum;
1132 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1134 pos += thissize;
1135 p += thissize;
1140 /* Assemble everything that is needed for a variable or function declaration.
1141 Not used for automatic variables, and not used for function definitions.
1142 Should not be called for variables of incomplete structure type.
1144 TOP_LEVEL is nonzero if this variable has file scope.
1145 AT_END is nonzero if this is the special handling, at end of compilation,
1146 to define things that have had only tentative definitions.
1147 DONT_OUTPUT_DATA if nonzero means don't actually output the
1148 initial value (that will be done by the caller). */
1150 void
1151 assemble_variable (decl, top_level, at_end, dont_output_data)
1152 tree decl;
1153 int top_level ATTRIBUTE_UNUSED;
1154 int at_end;
1155 int dont_output_data;
1157 register char *name;
1158 unsigned int align;
1159 tree size_tree;
1160 int reloc = 0;
1161 enum in_section saved_in_section;
1163 last_assemble_variable_decl = 0;
1165 if (GET_CODE (DECL_RTL (decl)) == REG)
1167 /* Do output symbol info for global register variables, but do nothing
1168 else for them. */
1170 if (TREE_ASM_WRITTEN (decl))
1171 return;
1172 TREE_ASM_WRITTEN (decl) = 1;
1174 /* Do no output if -fsyntax-only. */
1175 if (flag_syntax_only)
1176 return;
1178 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1179 /* File-scope global variables are output here. */
1180 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1181 && top_level)
1182 dbxout_symbol (decl, 0);
1183 #endif
1184 #ifdef SDB_DEBUGGING_INFO
1185 if (write_symbols == SDB_DEBUG && top_level
1186 /* Leave initialized global vars for end of compilation;
1187 see comment in compile_file. */
1188 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1189 sdbout_symbol (decl, 0);
1190 #endif
1192 /* Don't output any DWARF debugging information for variables here.
1193 In the case of local variables, the information for them is output
1194 when we do our recursive traversal of the tree representation for
1195 the entire containing function. In the case of file-scope variables,
1196 we output information for all of them at the very end of compilation
1197 while we are doing our final traversal of the chain of file-scope
1198 declarations. */
1200 return;
1203 /* Normally no need to say anything here for external references,
1204 since assemble_external is called by the language-specific code
1205 when a declaration is first seen. */
1207 if (DECL_EXTERNAL (decl))
1208 return;
1210 /* Output no assembler code for a function declaration.
1211 Only definitions of functions output anything. */
1213 if (TREE_CODE (decl) == FUNCTION_DECL)
1214 return;
1216 /* If type was incomplete when the variable was declared,
1217 see if it is complete now. */
1219 if (DECL_SIZE (decl) == 0)
1220 layout_decl (decl, 0);
1222 /* Still incomplete => don't allocate it; treat the tentative defn
1223 (which is what it must have been) as an `extern' reference. */
1225 if (!dont_output_data && DECL_SIZE (decl) == 0)
1227 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1228 DECL_SOURCE_LINE (decl),
1229 "storage size of `%s' isn't known",
1230 IDENTIFIER_POINTER (DECL_NAME (decl)));
1231 TREE_ASM_WRITTEN (decl) = 1;
1232 return;
1235 /* The first declaration of a variable that comes through this function
1236 decides whether it is global (in C, has external linkage)
1237 or local (in C, has internal linkage). So do nothing more
1238 if this function has already run. */
1240 if (TREE_ASM_WRITTEN (decl))
1241 return;
1243 TREE_ASM_WRITTEN (decl) = 1;
1245 /* Do no output if -fsyntax-only. */
1246 if (flag_syntax_only)
1247 return;
1249 app_disable ();
1251 if (! dont_output_data)
1253 int size;
1255 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1256 goto finish;
1258 /* This is better than explicit arithmetic, since it avoids overflow. */
1259 size_tree = size_binop (CEIL_DIV_EXPR,
1260 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1262 size = TREE_INT_CST_LOW (size_tree);
1263 if (TREE_INT_CST_HIGH (size_tree) != 0
1264 || size != TREE_INT_CST_LOW (size_tree))
1266 error_with_decl (decl, "size of variable `%s' is too large");
1267 goto finish;
1271 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))
1280 char *p;
1282 STRIP_NAME_ENCODING (p, name);
1283 first_global_object_name = permalloc (strlen (p) + 1);
1284 strcpy (first_global_object_name, p);
1287 /* Compute the alignment of this data. */
1289 align = DECL_ALIGN (decl);
1291 /* In the case for initialing an array whose length isn't specified,
1292 where we have not yet been able to do the layout,
1293 figure out the proper alignment now. */
1294 if (dont_output_data && DECL_SIZE (decl) == 0
1295 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1296 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1298 /* Some object file formats have a maximum alignment which they support.
1299 In particular, a.out format supports a maximum alignment of 4. */
1300 #ifndef MAX_OFILE_ALIGNMENT
1301 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1302 #endif
1303 if (align > MAX_OFILE_ALIGNMENT)
1305 warning_with_decl (decl,
1306 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1307 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1308 align = MAX_OFILE_ALIGNMENT;
1311 /* On some machines, it is good to increase alignment sometimes. */
1312 #ifdef DATA_ALIGNMENT
1313 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1314 #endif
1315 #ifdef CONSTANT_ALIGNMENT
1316 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1317 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1318 #endif
1320 /* Reset the alignment in case we have made it tighter, so we can benefit
1321 from it in get_pointer_alignment. */
1322 DECL_ALIGN (decl) = align;
1324 /* Handle uninitialized definitions. */
1326 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1327 /* If the target can't output uninitialized but not common global data
1328 in .bss, then we have to use .data. */
1329 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1330 && DECL_COMMON (decl)
1331 #endif
1332 && DECL_SECTION_NAME (decl) == 0
1333 && ! dont_output_data)
1335 int size = TREE_INT_CST_LOW (size_tree);
1336 int rounded = size;
1338 /* Don't allocate zero bytes of common,
1339 since that means "undefined external" in the linker. */
1340 if (size == 0) rounded = 1;
1341 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1342 so that each uninitialized object starts on such a boundary. */
1343 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1344 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1345 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1347 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1348 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1349 warning_with_decl
1350 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1351 #endif
1353 #ifdef DBX_DEBUGGING_INFO
1354 /* File-scope global variables are output here. */
1355 if (write_symbols == DBX_DEBUG && top_level)
1356 dbxout_symbol (decl, 0);
1357 #endif
1358 #ifdef SDB_DEBUGGING_INFO
1359 if (write_symbols == SDB_DEBUG && top_level
1360 /* Leave initialized global vars for end of compilation;
1361 see comment in compile_file. */
1362 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1363 sdbout_symbol (decl, 0);
1364 #endif
1366 /* Don't output any DWARF debugging information for variables here.
1367 In the case of local variables, the information for them is output
1368 when we do our recursive traversal of the tree representation for
1369 the entire containing function. In the case of file-scope variables,
1370 we output information for all of them at the very end of compilation
1371 while we are doing our final traversal of the chain of file-scope
1372 declarations. */
1374 #if 0 /* ??? We should either delete this or add a comment describing what
1375 it was intended to do and why we shouldn't delete it. */
1376 if (flag_shared_data)
1377 data_section ();
1378 #endif
1380 if (TREE_PUBLIC (decl)
1381 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1382 && DECL_COMMON (decl)
1383 #endif
1386 #ifdef ASM_OUTPUT_SHARED_COMMON
1387 if (flag_shared_data)
1388 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1389 else
1390 #endif
1392 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1393 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1394 DECL_ALIGN (decl));
1395 #else
1396 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1397 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1398 DECL_ALIGN (decl));
1399 #else
1400 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1401 #endif
1402 #endif
1405 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1406 else if (TREE_PUBLIC (decl))
1408 #ifdef ASM_OUTPUT_SHARED_BSS
1409 if (flag_shared_data)
1410 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1411 else
1412 #endif
1414 #ifdef ASM_OUTPUT_ALIGNED_BSS
1415 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1416 DECL_ALIGN (decl));
1417 #else
1418 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1419 #endif
1422 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1423 else
1425 #ifdef ASM_OUTPUT_SHARED_LOCAL
1426 if (flag_shared_data)
1427 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1428 else
1429 #endif
1431 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1432 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1433 DECL_ALIGN (decl));
1434 #else
1435 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1436 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1437 DECL_ALIGN (decl));
1438 #else
1439 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1440 #endif
1441 #endif
1444 goto finish;
1447 /* Handle initialized definitions.
1448 Also handle uninitialized global definitions if -fno-common and the
1449 target doesn't support ASM_OUTPUT_BSS. */
1451 /* First make the assembler name(s) global if appropriate. */
1452 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1454 #ifdef ASM_WEAKEN_LABEL
1455 if (DECL_WEAK (decl))
1457 ASM_WEAKEN_LABEL (asm_out_file, name);
1458 /* Remove this variable from the pending weak list so that
1459 we do not emit multiple .weak directives for it. */
1460 remove_from_pending_weak_list
1461 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1463 else
1464 #endif
1465 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1467 #if 0
1468 for (d = equivalents; d; d = TREE_CHAIN (d))
1470 tree e = TREE_VALUE (d);
1471 if (TREE_PUBLIC (e) && DECL_NAME (e))
1472 ASM_GLOBALIZE_LABEL (asm_out_file,
1473 XSTR (XEXP (DECL_RTL (e), 0), 0));
1475 #endif
1477 /* Output any data that we will need to use the address of. */
1478 if (DECL_INITIAL (decl) == error_mark_node)
1479 reloc = contains_pointers_p (TREE_TYPE (decl));
1480 else if (DECL_INITIAL (decl))
1481 reloc = output_addressed_constants (DECL_INITIAL (decl));
1483 #ifdef ASM_OUTPUT_SECTION_NAME
1484 if ((flag_data_sections != 0
1485 && DECL_SECTION_NAME (decl) == NULL_TREE)
1486 || UNIQUE_SECTION_P (decl))
1487 UNIQUE_SECTION (decl, reloc);
1488 #endif
1490 /* Switch to the appropriate section. */
1491 variable_section (decl, reloc);
1493 /* dbxout.c needs to know this. */
1494 if (in_text_section ())
1495 DECL_IN_TEXT_SECTION (decl) = 1;
1497 /* Record current section so we can restore it if dbxout.c clobbers it. */
1498 saved_in_section = in_section;
1500 /* Output the dbx info now that we have chosen the section. */
1502 #ifdef DBX_DEBUGGING_INFO
1503 /* File-scope global variables are output here. */
1504 if (write_symbols == DBX_DEBUG && top_level)
1505 dbxout_symbol (decl, 0);
1506 #endif
1507 #ifdef SDB_DEBUGGING_INFO
1508 if (write_symbols == SDB_DEBUG && top_level
1509 /* Leave initialized global vars for end of compilation;
1510 see comment in compile_file. */
1511 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1512 sdbout_symbol (decl, 0);
1513 #endif
1515 /* Don't output any DWARF debugging information for variables here.
1516 In the case of local variables, the information for them is output
1517 when we do our recursive traversal of the tree representation for
1518 the entire containing function. In the case of file-scope variables,
1519 we output information for all of them at the very end of compilation
1520 while we are doing our final traversal of the chain of file-scope
1521 declarations. */
1523 /* If the debugging output changed sections, reselect the section
1524 that's supposed to be selected. */
1525 if (in_section != saved_in_section)
1526 variable_section (decl, reloc);
1528 /* Output the alignment of this data. */
1529 if (align > BITS_PER_UNIT)
1530 ASM_OUTPUT_ALIGN (asm_out_file,
1531 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1533 /* Do any machine/system dependent processing of the object. */
1534 #ifdef ASM_DECLARE_OBJECT_NAME
1535 last_assemble_variable_decl = decl;
1536 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1537 #else
1538 /* Standard thing is just output label for the object. */
1539 ASM_OUTPUT_LABEL (asm_out_file, name);
1540 #endif /* ASM_DECLARE_OBJECT_NAME */
1542 if (!dont_output_data)
1544 if (DECL_INITIAL (decl))
1545 /* Output the actual data. */
1546 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1547 else
1548 /* Leave space for it. */
1549 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1552 finish:
1553 #ifdef XCOFF_DEBUGGING_INFO
1554 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1555 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1556 and `aa' hasn't been output yet, the assembler generates a stab entry with
1557 a value of zero, in addition to creating an unnecessary external entry
1558 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1560 /* File-scope global variables are output here. */
1561 if (write_symbols == XCOFF_DEBUG && top_level)
1563 saved_in_section = in_section;
1565 dbxout_symbol (decl, 0);
1567 if (in_section != saved_in_section)
1568 variable_section (decl, reloc);
1570 #else
1571 /* There must be a statement after a label. */
1573 #endif
1576 /* Return 1 if type TYPE contains any pointers. */
1578 static int
1579 contains_pointers_p (type)
1580 tree type;
1582 switch (TREE_CODE (type))
1584 case POINTER_TYPE:
1585 case REFERENCE_TYPE:
1586 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1587 so I'll play safe and return 1. */
1588 case OFFSET_TYPE:
1589 return 1;
1591 case RECORD_TYPE:
1592 case UNION_TYPE:
1593 case QUAL_UNION_TYPE:
1595 tree fields;
1596 /* For a type that has fields, see if the fields have pointers. */
1597 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1598 if (TREE_CODE (fields) == FIELD_DECL
1599 && contains_pointers_p (TREE_TYPE (fields)))
1600 return 1;
1601 return 0;
1604 case ARRAY_TYPE:
1605 /* An array type contains pointers if its element type does. */
1606 return contains_pointers_p (TREE_TYPE (type));
1608 default:
1609 return 0;
1613 /* Output something to declare an external symbol to the assembler.
1614 (Most assemblers don't need this, so we normally output nothing.)
1615 Do nothing if DECL is not external. */
1617 void
1618 assemble_external (decl)
1619 tree decl ATTRIBUTE_UNUSED;
1621 #ifdef ASM_OUTPUT_EXTERNAL
1622 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1623 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1625 rtx rtl = DECL_RTL (decl);
1627 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1628 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1630 /* Some systems do require some output. */
1631 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1632 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1635 #endif
1638 /* Similar, for calling a library function FUN. */
1640 void
1641 assemble_external_libcall (fun)
1642 rtx fun ATTRIBUTE_UNUSED;
1644 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1645 /* Declare library function name external when first used, if nec. */
1646 if (! SYMBOL_REF_USED (fun))
1648 SYMBOL_REF_USED (fun) = 1;
1649 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1651 #endif
1654 /* Declare the label NAME global. */
1656 void
1657 assemble_global (name)
1658 char *name;
1660 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1663 /* Assemble a label named NAME. */
1665 void
1666 assemble_label (name)
1667 char *name;
1669 ASM_OUTPUT_LABEL (asm_out_file, name);
1672 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1673 If NAME starts with a *, the rest of NAME is output verbatim.
1674 Otherwise NAME is transformed in an implementation-defined way
1675 (usually by the addition of an underscore).
1676 Many macros in the tm file are defined to call this function. */
1678 void
1679 assemble_name (file, name)
1680 FILE *file;
1681 char *name;
1683 char *real_name;
1684 tree id;
1686 STRIP_NAME_ENCODING (real_name, name);
1687 if (flag_prefix_function_name
1688 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1689 real_name = real_name + CHKR_PREFIX_SIZE;
1691 id = maybe_get_identifier (real_name);
1692 if (id)
1693 TREE_SYMBOL_REFERENCED (id) = 1;
1695 if (name[0] == '*')
1696 fputs (&name[1], file);
1697 else
1698 ASM_OUTPUT_LABELREF (file, name);
1701 /* Allocate SIZE bytes writable static space with a gensym name
1702 and return an RTX to refer to its address. */
1705 assemble_static_space (size)
1706 int size;
1708 char name[12];
1709 char *namestring;
1710 rtx x;
1712 #if 0
1713 if (flag_shared_data)
1714 data_section ();
1715 #endif
1717 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1718 ++const_labelno;
1720 namestring = (char *) obstack_alloc (saveable_obstack,
1721 strlen (name) + 2);
1722 strcpy (namestring, name);
1724 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1726 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1727 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1728 BIGGEST_ALIGNMENT);
1729 #else
1730 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1731 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1732 #else
1734 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1735 so that each uninitialized object starts on such a boundary. */
1736 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1737 int rounded ATTRIBUTE_UNUSED
1738 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1739 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1740 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1741 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1743 #endif
1744 #endif
1745 return x;
1748 /* Assemble the static constant template for function entry trampolines.
1749 This is done at most once per compilation.
1750 Returns an RTX for the address of the template. */
1752 #ifdef TRAMPOLINE_TEMPLATE
1754 assemble_trampoline_template ()
1756 char label[256];
1757 char *name;
1758 int align;
1760 /* By default, put trampoline templates in read-only data section. */
1762 #ifdef TRAMPOLINE_SECTION
1763 TRAMPOLINE_SECTION ();
1764 #else
1765 readonly_data_section ();
1766 #endif
1768 /* Write the assembler code to define one. */
1769 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1770 if (align > 0)
1771 ASM_OUTPUT_ALIGN (asm_out_file, align);
1773 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1774 TRAMPOLINE_TEMPLATE (asm_out_file);
1776 /* Record the rtl to refer to it. */
1777 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1778 name
1779 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1780 return gen_rtx_SYMBOL_REF (Pmode, name);
1782 #endif
1784 /* Assemble the integer constant X into an object of SIZE bytes.
1785 X must be either a CONST_INT or CONST_DOUBLE.
1787 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1788 non-zero, abort if we can't output the constant. */
1791 assemble_integer (x, size, force)
1792 rtx x;
1793 int size;
1794 int force;
1796 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1797 ASM_OUTPUT... macros. */
1799 switch (size)
1801 #ifdef ASM_OUTPUT_CHAR
1802 case 1:
1803 ASM_OUTPUT_CHAR (asm_out_file, x);
1804 return 1;
1805 #endif
1807 #ifdef ASM_OUTPUT_SHORT
1808 case 2:
1809 ASM_OUTPUT_SHORT (asm_out_file, x);
1810 return 1;
1811 #endif
1813 #ifdef ASM_OUTPUT_INT
1814 case 4:
1815 ASM_OUTPUT_INT (asm_out_file, x);
1816 return 1;
1817 #endif
1819 #ifdef ASM_OUTPUT_DOUBLE_INT
1820 case 8:
1821 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1822 return 1;
1823 #endif
1825 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1826 case 16:
1827 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1828 return 1;
1829 #endif
1832 /* If we couldn't do it that way, there are two other possibilities: First,
1833 if the machine can output an explicit byte and this is a 1 byte constant,
1834 we can use ASM_OUTPUT_BYTE. */
1836 #ifdef ASM_OUTPUT_BYTE
1837 if (size == 1 && GET_CODE (x) == CONST_INT)
1839 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1840 return 1;
1842 #endif
1844 /* Finally, if SIZE is larger than a single word, try to output the constant
1845 one word at a time. */
1847 if (size > UNITS_PER_WORD)
1849 int i;
1850 enum machine_mode mode
1851 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1852 rtx word;
1854 for (i = 0; i < size / UNITS_PER_WORD; i++)
1856 word = operand_subword (x, i, 0, mode);
1858 if (word == 0)
1859 break;
1861 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1862 break;
1865 if (i == size / UNITS_PER_WORD)
1866 return 1;
1867 /* If we output at least one word and then could not finish,
1868 there is no valid way to continue. */
1869 if (i > 0)
1870 abort ();
1873 if (force)
1874 abort ();
1876 return 0;
1879 /* Assemble the floating-point constant D into an object of size MODE. */
1881 void
1882 assemble_real (d, mode)
1883 REAL_VALUE_TYPE d;
1884 enum machine_mode mode;
1886 jmp_buf output_constant_handler;
1888 if (setjmp (output_constant_handler))
1890 error ("floating point trap outputting a constant");
1891 #ifdef REAL_IS_NOT_DOUBLE
1892 bzero ((char *) &d, sizeof d);
1893 d = dconst0;
1894 #else
1895 d = 0;
1896 #endif
1899 set_float_handler (output_constant_handler);
1901 switch (mode)
1903 #ifdef ASM_OUTPUT_BYTE_FLOAT
1904 case QFmode:
1905 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1906 break;
1907 #endif
1908 #ifdef ASM_OUTPUT_SHORT_FLOAT
1909 case HFmode:
1910 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1911 break;
1912 #endif
1913 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1914 case TQFmode:
1915 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1916 break;
1917 #endif
1918 #ifdef ASM_OUTPUT_FLOAT
1919 case SFmode:
1920 ASM_OUTPUT_FLOAT (asm_out_file, d);
1921 break;
1922 #endif
1924 #ifdef ASM_OUTPUT_DOUBLE
1925 case DFmode:
1926 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1927 break;
1928 #endif
1930 #ifdef ASM_OUTPUT_LONG_DOUBLE
1931 case XFmode:
1932 case TFmode:
1933 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1934 break;
1935 #endif
1937 default:
1938 abort ();
1941 set_float_handler (NULL_PTR);
1944 /* Here we combine duplicate floating constants to make
1945 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1947 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1948 They are chained through the CONST_DOUBLE_CHAIN.
1949 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1950 In that case, CONST_DOUBLE_MEM is either a MEM,
1951 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1953 (CONST_DOUBLE_MEM is used only for top-level functions.
1954 See force_const_mem for explanation.) */
1956 static rtx const_double_chain;
1958 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1959 For an integer, I0 is the low-order word and I1 is the high-order word.
1960 For a real number, I0 is the word with the low address
1961 and I1 is the word with the high address. */
1964 immed_double_const (i0, i1, mode)
1965 HOST_WIDE_INT i0, i1;
1966 enum machine_mode mode;
1968 register rtx r;
1970 if (GET_MODE_CLASS (mode) == MODE_INT
1971 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1973 /* We clear out all bits that don't belong in MODE, unless they and our
1974 sign bit are all one. So we get either a reasonable negative value
1975 or a reasonable unsigned value for this mode. */
1976 int width = GET_MODE_BITSIZE (mode);
1977 if (width < HOST_BITS_PER_WIDE_INT
1978 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1979 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1980 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1981 else if (width == HOST_BITS_PER_WIDE_INT
1982 && ! (i1 == ~0 && i0 < 0))
1983 i1 = 0;
1984 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1985 /* We cannot represent this value as a constant. */
1986 abort ();
1988 /* If this would be an entire word for the target, but is not for
1989 the host, then sign-extend on the host so that the number will look
1990 the same way on the host that it would on the target.
1992 For example, when building a 64 bit alpha hosted 32 bit sparc
1993 targeted compiler, then we want the 32 bit unsigned value -1 to be
1994 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1995 The later confuses the sparc backend. */
1997 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1998 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1999 i0 |= ((HOST_WIDE_INT) (-1) << width);
2001 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2003 ??? Strictly speaking, this is wrong if we create a CONST_INT
2004 for a large unsigned constant with the size of MODE being
2005 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2006 wider mode. In that case we will mis-interpret it as a negative
2007 number.
2009 Unfortunately, the only alternative is to make a CONST_DOUBLE
2010 for any constant in any mode if it is an unsigned constant larger
2011 than the maximum signed integer in an int on the host. However,
2012 doing this will break everyone that always expects to see a CONST_INT
2013 for SImode and smaller.
2015 We have always been making CONST_INTs in this case, so nothing new
2016 is being broken. */
2018 if (width <= HOST_BITS_PER_WIDE_INT)
2019 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2021 /* If this integer fits in one word, return a CONST_INT. */
2022 if ((i1 == 0 && i0 >= 0)
2023 || (i1 == ~0 && i0 < 0))
2024 return GEN_INT (i0);
2026 /* We use VOIDmode for integers. */
2027 mode = VOIDmode;
2030 /* Search the chain for an existing CONST_DOUBLE with the right value.
2031 If one is found, return it. */
2033 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2034 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2035 && GET_MODE (r) == mode)
2036 return r;
2038 /* No; make a new one and add it to the chain.
2040 We may be called by an optimizer which may be discarding any memory
2041 allocated during its processing (such as combine and loop). However,
2042 we will be leaving this constant on the chain, so we cannot tolerate
2043 freed memory. So switch to saveable_obstack for this allocation
2044 and then switch back if we were in current_obstack. */
2046 push_obstacks_nochange ();
2047 rtl_in_saveable_obstack ();
2048 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2049 pop_obstacks ();
2051 /* Don't touch const_double_chain in nested function; see force_const_mem.
2052 Also, don't touch it if not inside any function. */
2053 if (outer_function_chain == 0 && current_function_decl != 0)
2055 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2056 const_double_chain = r;
2059 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2060 Actual use of mem-slot is only through force_const_mem. */
2062 CONST_DOUBLE_MEM (r) = const0_rtx;
2064 return r;
2067 /* Return a CONST_DOUBLE for a specified `double' value
2068 and machine mode. */
2071 immed_real_const_1 (d, mode)
2072 REAL_VALUE_TYPE d;
2073 enum machine_mode mode;
2075 union real_extract u;
2076 register rtx r;
2078 /* Get the desired `double' value as a sequence of ints
2079 since that is how they are stored in a CONST_DOUBLE. */
2081 u.d = d;
2083 /* Detect special cases. */
2085 if (REAL_VALUES_IDENTICAL (dconst0, d))
2086 return CONST0_RTX (mode);
2087 /* Check for NaN first, because some ports (specifically the i386) do not
2088 emit correct ieee-fp code by default, and thus will generate a core
2089 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2090 does a floating point comparison. */
2091 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2092 return CONST1_RTX (mode);
2094 if (sizeof u == sizeof (HOST_WIDE_INT))
2095 return immed_double_const (u.i[0], 0, mode);
2096 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2097 return immed_double_const (u.i[0], u.i[1], mode);
2099 /* The rest of this function handles the case where
2100 a float value requires more than 2 ints of space.
2101 It will be deleted as dead code on machines that don't need it. */
2103 /* Search the chain for an existing CONST_DOUBLE with the right value.
2104 If one is found, return it. */
2106 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2107 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2108 && GET_MODE (r) == mode)
2109 return r;
2111 /* No; make a new one and add it to the chain.
2113 We may be called by an optimizer which may be discarding any memory
2114 allocated during its processing (such as combine and loop). However,
2115 we will be leaving this constant on the chain, so we cannot tolerate
2116 freed memory. So switch to saveable_obstack for this allocation
2117 and then switch back if we were in current_obstack. */
2119 push_obstacks_nochange ();
2120 rtl_in_saveable_obstack ();
2121 r = rtx_alloc (CONST_DOUBLE);
2122 PUT_MODE (r, mode);
2123 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2124 pop_obstacks ();
2126 /* Don't touch const_double_chain in nested function; see force_const_mem.
2127 Also, don't touch it if not inside any function. */
2128 if (outer_function_chain == 0 && current_function_decl != 0)
2130 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2131 const_double_chain = r;
2134 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2135 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2136 is only through force_const_mem. */
2138 CONST_DOUBLE_MEM (r) = const0_rtx;
2140 return r;
2143 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2144 which must be a REAL_CST tree node. */
2147 immed_real_const (exp)
2148 tree exp;
2150 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2153 /* At the end of a function, forget the memory-constants
2154 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2155 Also clear out real_constant_chain and clear out all the chain-pointers. */
2157 void
2158 clear_const_double_mem ()
2160 register rtx r, next;
2162 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2163 See force_const_mem for explanation. */
2164 if (outer_function_chain != 0)
2165 return;
2167 for (r = const_double_chain; r; r = next)
2169 next = CONST_DOUBLE_CHAIN (r);
2170 CONST_DOUBLE_CHAIN (r) = 0;
2171 CONST_DOUBLE_MEM (r) = cc0_rtx;
2173 const_double_chain = 0;
2176 /* Given an expression EXP with a constant value,
2177 reduce it to the sum of an assembler symbol and an integer.
2178 Store them both in the structure *VALUE.
2179 Abort if EXP does not reduce. */
2181 struct addr_const
2183 rtx base;
2184 HOST_WIDE_INT offset;
2187 static void
2188 decode_addr_const (exp, value)
2189 tree exp;
2190 struct addr_const *value;
2192 register tree target = TREE_OPERAND (exp, 0);
2193 register int offset = 0;
2194 register rtx x;
2196 while (1)
2198 if (TREE_CODE (target) == COMPONENT_REF
2199 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2200 == INTEGER_CST))
2202 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2203 target = TREE_OPERAND (target, 0);
2205 else if (TREE_CODE (target) == ARRAY_REF)
2207 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2208 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2209 abort ();
2210 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2211 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2212 / BITS_PER_UNIT);
2213 target = TREE_OPERAND (target, 0);
2215 else
2216 break;
2219 switch (TREE_CODE (target))
2221 case VAR_DECL:
2222 case FUNCTION_DECL:
2223 x = DECL_RTL (target);
2224 break;
2226 case LABEL_DECL:
2227 x = gen_rtx_MEM (FUNCTION_MODE,
2228 gen_rtx_LABEL_REF (VOIDmode,
2229 label_rtx (TREE_OPERAND (exp, 0))));
2230 break;
2232 case REAL_CST:
2233 case STRING_CST:
2234 case COMPLEX_CST:
2235 case CONSTRUCTOR:
2236 case INTEGER_CST:
2237 x = TREE_CST_RTL (target);
2238 break;
2240 default:
2241 abort ();
2244 if (GET_CODE (x) != MEM)
2245 abort ();
2246 x = XEXP (x, 0);
2248 value->base = x;
2249 value->offset = offset;
2252 /* Uniquize all constants that appear in memory.
2253 Each constant in memory thus far output is recorded
2254 in `const_hash_table' with a `struct constant_descriptor'
2255 that contains a polish representation of the value of
2256 the constant.
2258 We cannot store the trees in the hash table
2259 because the trees may be temporary. */
2261 struct constant_descriptor
2263 struct constant_descriptor *next;
2264 char *label;
2265 char contents[1];
2268 #define HASHBITS 30
2269 #define MAX_HASH_TABLE 1009
2270 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2272 /* Compute a hash code for a constant expression. */
2274 static int
2275 const_hash (exp)
2276 tree exp;
2278 register char *p;
2279 register int len, hi, i;
2280 register enum tree_code code = TREE_CODE (exp);
2282 /* Either set P and LEN to the address and len of something to hash and
2283 exit the switch or return a value. */
2285 switch (code)
2287 case INTEGER_CST:
2288 p = (char *) &TREE_INT_CST_LOW (exp);
2289 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2290 break;
2292 case REAL_CST:
2293 p = (char *) &TREE_REAL_CST (exp);
2294 len = sizeof TREE_REAL_CST (exp);
2295 break;
2297 case STRING_CST:
2298 p = TREE_STRING_POINTER (exp);
2299 len = TREE_STRING_LENGTH (exp);
2300 break;
2302 case COMPLEX_CST:
2303 return (const_hash (TREE_REALPART (exp)) * 5
2304 + const_hash (TREE_IMAGPART (exp)));
2306 case CONSTRUCTOR:
2307 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2309 len = int_size_in_bytes (TREE_TYPE (exp));
2310 p = (char *) alloca (len);
2311 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2312 break;
2314 else
2316 register tree link;
2318 /* For record type, include the type in the hashing.
2319 We do not do so for array types
2320 because (1) the sizes of the elements are sufficient
2321 and (2) distinct array types can have the same constructor.
2322 Instead, we include the array size because the constructor could
2323 be shorter. */
2324 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2325 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2326 % MAX_HASH_TABLE;
2327 else
2328 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2329 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2331 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2332 if (TREE_VALUE (link))
2334 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2336 return hi;
2339 case ADDR_EXPR:
2341 struct addr_const value;
2343 decode_addr_const (exp, &value);
2344 if (GET_CODE (value.base) == SYMBOL_REF)
2346 /* Don't hash the address of the SYMBOL_REF;
2347 only use the offset and the symbol name. */
2348 hi = value.offset;
2349 p = XSTR (value.base, 0);
2350 for (i = 0; p[i] != 0; i++)
2351 hi = ((hi * 613) + (unsigned) (p[i]));
2353 else if (GET_CODE (value.base) == LABEL_REF)
2354 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2356 hi &= (1 << HASHBITS) - 1;
2357 hi %= MAX_HASH_TABLE;
2359 return hi;
2361 case PLUS_EXPR:
2362 case MINUS_EXPR:
2363 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2364 + const_hash (TREE_OPERAND (exp, 1)));
2366 case NOP_EXPR:
2367 case CONVERT_EXPR:
2368 case NON_LVALUE_EXPR:
2369 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2371 default:
2372 abort ();
2375 /* Compute hashing function */
2376 hi = len;
2377 for (i = 0; i < len; i++)
2378 hi = ((hi * 613) + (unsigned) (p[i]));
2380 hi &= (1 << HASHBITS) - 1;
2381 hi %= MAX_HASH_TABLE;
2382 return hi;
2385 /* Compare a constant expression EXP with a constant-descriptor DESC.
2386 Return 1 if DESC describes a constant with the same value as EXP. */
2388 static int
2389 compare_constant (exp, desc)
2390 tree exp;
2391 struct constant_descriptor *desc;
2393 return 0 != compare_constant_1 (exp, desc->contents);
2396 /* Compare constant expression EXP with a substring P of a constant descriptor.
2397 If they match, return a pointer to the end of the substring matched.
2398 If they do not match, return 0.
2400 Since descriptors are written in polish prefix notation,
2401 this function can be used recursively to test one operand of EXP
2402 against a subdescriptor, and if it succeeds it returns the
2403 address of the subdescriptor for the next operand. */
2405 static char *
2406 compare_constant_1 (exp, p)
2407 tree exp;
2408 char *p;
2410 register char *strp;
2411 register int len;
2412 register enum tree_code code = TREE_CODE (exp);
2414 if (code != (enum tree_code) *p++)
2415 return 0;
2417 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2418 switch, or return the result of the comparison. */
2420 switch (code)
2422 case INTEGER_CST:
2423 /* Integer constants are the same only if the same width of type. */
2424 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2425 return 0;
2427 strp = (char *) &TREE_INT_CST_LOW (exp);
2428 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2429 break;
2431 case REAL_CST:
2432 /* Real constants are the same only if the same width of type. */
2433 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2434 return 0;
2436 strp = (char *) &TREE_REAL_CST (exp);
2437 len = sizeof TREE_REAL_CST (exp);
2438 break;
2440 case STRING_CST:
2441 if (flag_writable_strings)
2442 return 0;
2444 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2445 return 0;
2447 strp = TREE_STRING_POINTER (exp);
2448 len = TREE_STRING_LENGTH (exp);
2449 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2450 sizeof TREE_STRING_LENGTH (exp)))
2451 return 0;
2453 p += sizeof TREE_STRING_LENGTH (exp);
2454 break;
2456 case COMPLEX_CST:
2457 p = compare_constant_1 (TREE_REALPART (exp), p);
2458 if (p == 0)
2459 return 0;
2461 return compare_constant_1 (TREE_IMAGPART (exp), p);
2463 case CONSTRUCTOR:
2464 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2466 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2468 strp = (char *) alloca (len);
2469 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2470 if (bcmp ((char *) &xlen, p, sizeof xlen))
2471 return 0;
2473 p += sizeof xlen;
2474 break;
2476 else
2478 register tree link;
2479 int length = list_length (CONSTRUCTOR_ELTS (exp));
2480 tree type;
2481 int have_purpose = 0;
2483 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2484 if (TREE_PURPOSE (link))
2485 have_purpose = 1;
2487 if (bcmp ((char *) &length, p, sizeof length))
2488 return 0;
2490 p += sizeof length;
2492 /* For record constructors, insist that the types match.
2493 For arrays, just verify both constructors are for arrays.
2494 Then insist that either both or none have any TREE_PURPOSE
2495 values. */
2496 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2497 type = TREE_TYPE (exp);
2498 else
2499 type = 0;
2501 if (bcmp ((char *) &type, p, sizeof type))
2502 return 0;
2504 p += sizeof type;
2506 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2507 return 0;
2509 p += sizeof have_purpose;
2511 /* For arrays, insist that the size in bytes match. */
2512 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2514 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2516 if (bcmp ((char *) &size, p, sizeof size))
2517 return 0;
2519 p += sizeof size;
2522 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2524 if (TREE_VALUE (link))
2526 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2527 return 0;
2529 else
2531 tree zero = 0;
2533 if (bcmp ((char *) &zero, p, sizeof zero))
2534 return 0;
2536 p += sizeof zero;
2539 if (TREE_PURPOSE (link)
2540 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2542 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2543 sizeof TREE_PURPOSE (link)))
2544 return 0;
2546 p += sizeof TREE_PURPOSE (link);
2548 else if (TREE_PURPOSE (link))
2550 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2551 return 0;
2553 else if (have_purpose)
2555 int zero = 0;
2557 if (bcmp ((char *) &zero, p, sizeof zero))
2558 return 0;
2560 p += sizeof zero;
2564 return p;
2567 case ADDR_EXPR:
2569 struct addr_const value;
2571 decode_addr_const (exp, &value);
2572 strp = (char *) &value.offset;
2573 len = sizeof value.offset;
2574 /* Compare the offset. */
2575 while (--len >= 0)
2576 if (*p++ != *strp++)
2577 return 0;
2579 /* Compare symbol name. */
2580 strp = XSTR (value.base, 0);
2581 len = strlen (strp) + 1;
2583 break;
2585 case PLUS_EXPR:
2586 case MINUS_EXPR:
2587 case RANGE_EXPR:
2588 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2589 if (p == 0)
2590 return 0;
2592 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2594 case NOP_EXPR:
2595 case CONVERT_EXPR:
2596 case NON_LVALUE_EXPR:
2597 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2599 default:
2600 abort ();
2603 /* Compare constant contents. */
2604 while (--len >= 0)
2605 if (*p++ != *strp++)
2606 return 0;
2608 return p;
2611 /* Construct a constant descriptor for the expression EXP.
2612 It is up to the caller to enter the descriptor in the hash table. */
2614 static struct constant_descriptor *
2615 record_constant (exp)
2616 tree exp;
2618 struct constant_descriptor *next = 0;
2619 char *label = 0;
2621 /* Make a struct constant_descriptor. The first two pointers will
2622 be filled in later. Here we just leave space for them. */
2624 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2625 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2626 record_constant_1 (exp);
2627 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2630 /* Add a description of constant expression EXP
2631 to the object growing in `permanent_obstack'.
2632 No need to return its address; the caller will get that
2633 from the obstack when the object is complete. */
2635 static void
2636 record_constant_1 (exp)
2637 tree exp;
2639 register char *strp;
2640 register int len;
2641 register enum tree_code code = TREE_CODE (exp);
2643 obstack_1grow (&permanent_obstack, (unsigned int) code);
2645 switch (code)
2647 case INTEGER_CST:
2648 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2649 strp = (char *) &TREE_INT_CST_LOW (exp);
2650 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2651 break;
2653 case REAL_CST:
2654 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2655 strp = (char *) &TREE_REAL_CST (exp);
2656 len = sizeof TREE_REAL_CST (exp);
2657 break;
2659 case STRING_CST:
2660 if (flag_writable_strings)
2661 return;
2663 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2664 strp = TREE_STRING_POINTER (exp);
2665 len = TREE_STRING_LENGTH (exp);
2666 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2667 sizeof TREE_STRING_LENGTH (exp));
2668 break;
2670 case COMPLEX_CST:
2671 record_constant_1 (TREE_REALPART (exp));
2672 record_constant_1 (TREE_IMAGPART (exp));
2673 return;
2675 case CONSTRUCTOR:
2676 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2678 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2679 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2680 obstack_blank (&permanent_obstack, nbytes);
2681 get_set_constructor_bytes
2682 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2683 nbytes);
2684 return;
2686 else
2688 register tree link;
2689 int length = list_length (CONSTRUCTOR_ELTS (exp));
2690 tree type;
2691 int have_purpose = 0;
2693 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2694 if (TREE_PURPOSE (link))
2695 have_purpose = 1;
2697 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2699 /* For record constructors, insist that the types match.
2700 For arrays, just verify both constructors are for arrays.
2701 Then insist that either both or none have any TREE_PURPOSE
2702 values. */
2703 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2704 type = TREE_TYPE (exp);
2705 else
2706 type = 0;
2707 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2708 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2709 sizeof have_purpose);
2711 /* For arrays, insist that the size in bytes match. */
2712 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2714 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2715 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2718 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2720 if (TREE_VALUE (link))
2721 record_constant_1 (TREE_VALUE (link));
2722 else
2724 tree zero = 0;
2726 obstack_grow (&permanent_obstack,
2727 (char *) &zero, sizeof zero);
2730 if (TREE_PURPOSE (link)
2731 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2732 obstack_grow (&permanent_obstack,
2733 (char *) &TREE_PURPOSE (link),
2734 sizeof TREE_PURPOSE (link));
2735 else if (TREE_PURPOSE (link))
2736 record_constant_1 (TREE_PURPOSE (link));
2737 else if (have_purpose)
2739 int zero = 0;
2741 obstack_grow (&permanent_obstack,
2742 (char *) &zero, sizeof zero);
2746 return;
2748 case ADDR_EXPR:
2750 struct addr_const value;
2752 decode_addr_const (exp, &value);
2753 /* Record the offset. */
2754 obstack_grow (&permanent_obstack,
2755 (char *) &value.offset, sizeof value.offset);
2756 /* Record the symbol name. */
2757 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2758 strlen (XSTR (value.base, 0)) + 1);
2760 return;
2762 case PLUS_EXPR:
2763 case MINUS_EXPR:
2764 case RANGE_EXPR:
2765 record_constant_1 (TREE_OPERAND (exp, 0));
2766 record_constant_1 (TREE_OPERAND (exp, 1));
2767 return;
2769 case NOP_EXPR:
2770 case CONVERT_EXPR:
2771 case NON_LVALUE_EXPR:
2772 record_constant_1 (TREE_OPERAND (exp, 0));
2773 return;
2775 default:
2776 abort ();
2779 /* Record constant contents. */
2780 obstack_grow (&permanent_obstack, strp, len);
2783 /* Record a list of constant expressions that were passed to
2784 output_constant_def but that could not be output right away. */
2786 struct deferred_constant
2788 struct deferred_constant *next;
2789 tree exp;
2790 int reloc;
2791 int labelno;
2794 static struct deferred_constant *deferred_constants;
2796 /* Another list of constants which should be output after the
2797 function. */
2798 static struct deferred_constant *after_function_constants;
2800 /* Nonzero means defer output of addressed subconstants
2801 (i.e., those for which output_constant_def is called.) */
2802 static int defer_addressed_constants_flag;
2804 /* Start deferring output of subconstants. */
2806 void
2807 defer_addressed_constants ()
2809 defer_addressed_constants_flag++;
2812 /* Stop deferring output of subconstants,
2813 and output now all those that have been deferred. */
2815 void
2816 output_deferred_addressed_constants ()
2818 struct deferred_constant *p, *next;
2820 defer_addressed_constants_flag--;
2822 if (defer_addressed_constants_flag > 0)
2823 return;
2825 for (p = deferred_constants; p; p = next)
2827 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2828 next = p->next;
2829 free (p);
2832 deferred_constants = 0;
2835 /* Output any constants which should appear after a function. */
2837 static void
2838 output_after_function_constants ()
2840 struct deferred_constant *p, *next;
2842 for (p = after_function_constants; p; p = next)
2844 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2845 next = p->next;
2846 free (p);
2849 after_function_constants = 0;
2852 /* Make a copy of the whole tree structure for a constant.
2853 This handles the same types of nodes that compare_constant
2854 and record_constant handle. */
2856 static tree
2857 copy_constant (exp)
2858 tree exp;
2860 switch (TREE_CODE (exp))
2862 case ADDR_EXPR:
2863 /* For ADDR_EXPR, we do not want to copy the decl whose address
2864 is requested. We do want to copy constants though. */
2865 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2866 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2867 copy_constant (TREE_OPERAND (exp, 0)));
2868 else
2869 return copy_node (exp);
2871 case INTEGER_CST:
2872 case REAL_CST:
2873 case STRING_CST:
2874 return copy_node (exp);
2876 case COMPLEX_CST:
2877 return build_complex (TREE_TYPE (exp),
2878 copy_constant (TREE_REALPART (exp)),
2879 copy_constant (TREE_IMAGPART (exp)));
2881 case PLUS_EXPR:
2882 case MINUS_EXPR:
2883 return build (TREE_CODE (exp), TREE_TYPE (exp),
2884 copy_constant (TREE_OPERAND (exp, 0)),
2885 copy_constant (TREE_OPERAND (exp, 1)));
2887 case NOP_EXPR:
2888 case CONVERT_EXPR:
2889 case NON_LVALUE_EXPR:
2890 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2891 copy_constant (TREE_OPERAND (exp, 0)));
2893 case CONSTRUCTOR:
2895 tree copy = copy_node (exp);
2896 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2897 tree tail;
2899 CONSTRUCTOR_ELTS (copy) = list;
2900 for (tail = list; tail; tail = TREE_CHAIN (tail))
2901 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2902 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2903 for (tail = list; tail; tail = TREE_CHAIN (tail))
2904 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2906 return copy;
2909 default:
2910 abort ();
2914 /* Return an rtx representing a reference to constant data in memory
2915 for the constant expression EXP.
2917 If assembler code for such a constant has already been output,
2918 return an rtx to refer to it.
2919 Otherwise, output such a constant in memory (or defer it for later)
2920 and generate an rtx for it.
2922 The TREE_CST_RTL of EXP is set up to point to that rtx.
2923 The const_hash_table records which constants already have label strings. */
2926 output_constant_def (exp)
2927 tree exp;
2929 register int hash;
2930 register struct constant_descriptor *desc;
2931 char label[256];
2932 char *found = 0;
2933 int reloc;
2934 register rtx def;
2936 if (TREE_CST_RTL (exp))
2937 return TREE_CST_RTL (exp);
2939 /* Make sure any other constants whose addresses appear in EXP
2940 are assigned label numbers. */
2942 reloc = output_addressed_constants (exp);
2944 /* Compute hash code of EXP. Search the descriptors for that hash code
2945 to see if any of them describes EXP. If yes, the descriptor records
2946 the label number already assigned. */
2948 hash = const_hash (exp) % MAX_HASH_TABLE;
2950 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2951 if (compare_constant (exp, desc))
2953 found = desc->label;
2954 break;
2957 if (found == 0)
2959 /* No constant equal to EXP is known to have been output.
2960 Make a constant descriptor to enter EXP in the hash table.
2961 Assign the label number and record it in the descriptor for
2962 future calls to this function to find. */
2964 /* Create a string containing the label name, in LABEL. */
2965 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2967 desc = record_constant (exp);
2968 desc->next = const_hash_table[hash];
2969 desc->label
2970 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2971 const_hash_table[hash] = desc;
2973 else
2975 /* Create a string containing the label name, in LABEL. */
2976 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2979 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2981 push_obstacks_nochange ();
2982 if (TREE_PERMANENT (exp))
2983 end_temporary_allocation ();
2985 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
2987 TREE_CST_RTL (exp)
2988 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
2989 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2990 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2991 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
2993 pop_obstacks ();
2995 /* Optionally set flags or add text to the name to record information
2996 such as that it is a function name. If the name is changed, the macro
2997 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2998 #ifdef ENCODE_SECTION_INFO
2999 ENCODE_SECTION_INFO (exp);
3000 #endif
3002 /* If this is the first time we've seen this particular constant,
3003 output it (or defer its output for later). */
3004 if (found == 0)
3006 int after_function = 0;
3008 #ifdef CONSTANT_AFTER_FUNCTION_P
3009 if (current_function_decl != 0
3010 && CONSTANT_AFTER_FUNCTION_P (exp))
3011 after_function = 1;
3012 #endif
3014 if (defer_addressed_constants_flag || after_function)
3016 struct deferred_constant *p;
3017 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3019 push_obstacks_nochange ();
3020 suspend_momentary ();
3021 p->exp = copy_constant (exp);
3022 pop_obstacks ();
3023 p->reloc = reloc;
3024 p->labelno = const_labelno++;
3025 if (after_function)
3027 p->next = after_function_constants;
3028 after_function_constants = p;
3030 else
3032 p->next = deferred_constants;
3033 deferred_constants = p;
3036 else
3038 /* Do no output if -fsyntax-only. */
3039 if (! flag_syntax_only)
3040 output_constant_def_contents (exp, reloc, const_labelno);
3041 ++const_labelno;
3045 return TREE_CST_RTL (exp);
3048 /* Now output assembler code to define the label for EXP,
3049 and follow it with the data of EXP. */
3051 static void
3052 output_constant_def_contents (exp, reloc, labelno)
3053 tree exp;
3054 int reloc;
3055 int labelno;
3057 int align;
3059 if (IN_NAMED_SECTION (exp))
3060 named_section (exp, NULL, reloc);
3061 else
3063 /* First switch to text section, except for writable strings. */
3064 #ifdef SELECT_SECTION
3065 SELECT_SECTION (exp, reloc);
3066 #else
3067 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3068 || (flag_pic && reloc))
3069 data_section ();
3070 else
3071 readonly_data_section ();
3072 #endif
3075 /* Align the location counter as required by EXP's data type. */
3076 align = TYPE_ALIGN (TREE_TYPE (exp));
3077 #ifdef CONSTANT_ALIGNMENT
3078 align = CONSTANT_ALIGNMENT (exp, align);
3079 #endif
3081 if (align > BITS_PER_UNIT)
3082 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3084 /* Output the label itself. */
3085 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3087 /* Output the value of EXP. */
3088 output_constant (exp,
3089 (TREE_CODE (exp) == STRING_CST
3090 ? TREE_STRING_LENGTH (exp)
3091 : int_size_in_bytes (TREE_TYPE (exp))));
3095 /* Similar hash facility for making memory-constants
3096 from constant rtl-expressions. It is used on RISC machines
3097 where immediate integer arguments and constant addresses are restricted
3098 so that such constants must be stored in memory.
3100 This pool of constants is reinitialized for each function
3101 so each function gets its own constants-pool that comes right before it.
3103 All structures allocated here are discarded when functions are saved for
3104 inlining, so they do not need to be allocated permanently. */
3106 #define MAX_RTX_HASH_TABLE 61
3107 static struct constant_descriptor **const_rtx_hash_table;
3109 /* Structure to represent sufficient information about a constant so that
3110 it can be output when the constant pool is output, so that function
3111 integration can be done, and to simplify handling on machines that reference
3112 constant pool as base+displacement. */
3114 struct pool_constant
3116 struct constant_descriptor *desc;
3117 struct pool_constant *next;
3118 enum machine_mode mode;
3119 rtx constant;
3120 int labelno;
3121 int align;
3122 int offset;
3123 int mark;
3126 /* Pointers to first and last constant in pool. */
3128 static struct pool_constant *first_pool, *last_pool;
3130 /* Current offset in constant pool (does not include any machine-specific
3131 header. */
3133 static int pool_offset;
3135 /* Structure used to maintain hash table mapping symbols used to their
3136 corresponding constants. */
3138 struct pool_sym
3140 char *label;
3141 struct pool_constant *pool;
3142 struct pool_sym *next;
3145 static struct pool_sym **const_rtx_sym_hash_table;
3147 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3148 The argument is XSTR (... , 0) */
3150 #define SYMHASH(LABEL) \
3151 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3153 /* Initialize constant pool hashing for next function. */
3155 void
3156 init_const_rtx_hash_table ()
3158 const_rtx_hash_table
3159 = ((struct constant_descriptor **)
3160 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3161 const_rtx_sym_hash_table
3162 = ((struct pool_sym **)
3163 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3164 bzero ((char *) const_rtx_hash_table,
3165 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3166 bzero ((char *) const_rtx_sym_hash_table,
3167 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3169 first_pool = last_pool = 0;
3170 pool_offset = 0;
3173 /* Save and restore status for a nested function. */
3175 void
3176 save_varasm_status (p, context)
3177 struct function *p;
3178 tree context;
3180 p->const_rtx_hash_table = const_rtx_hash_table;
3181 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3182 p->first_pool = first_pool;
3183 p->last_pool = last_pool;
3184 p->pool_offset = pool_offset;
3185 p->const_double_chain = const_double_chain;
3187 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3188 if (context == NULL_TREE)
3189 const_double_chain = 0;
3192 void
3193 restore_varasm_status (p)
3194 struct function *p;
3196 const_rtx_hash_table = p->const_rtx_hash_table;
3197 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3198 first_pool = p->first_pool;
3199 last_pool = p->last_pool;
3200 pool_offset = p->pool_offset;
3201 const_double_chain = p->const_double_chain;
3204 enum kind { RTX_DOUBLE, RTX_INT };
3206 struct rtx_const
3208 #ifdef ONLY_INT_FIELDS
3209 unsigned int kind : 16;
3210 unsigned int mode : 16;
3211 #else
3212 enum kind kind : 16;
3213 enum machine_mode mode : 16;
3214 #endif
3215 union {
3216 union real_extract du;
3217 struct addr_const addr;
3218 struct {HOST_WIDE_INT high, low;} di;
3219 } un;
3222 /* Express an rtx for a constant integer (perhaps symbolic)
3223 as the sum of a symbol or label plus an explicit integer.
3224 They are stored into VALUE. */
3226 static void
3227 decode_rtx_const (mode, x, value)
3228 enum machine_mode mode;
3229 rtx x;
3230 struct rtx_const *value;
3232 /* Clear the whole structure, including any gaps. */
3235 int *p = (int *) value;
3236 int *end = (int *) (value + 1);
3237 while (p < end)
3238 *p++ = 0;
3241 value->kind = RTX_INT; /* Most usual kind. */
3242 value->mode = mode;
3244 switch (GET_CODE (x))
3246 case CONST_DOUBLE:
3247 value->kind = RTX_DOUBLE;
3248 if (GET_MODE (x) != VOIDmode)
3250 value->mode = GET_MODE (x);
3251 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3252 (char *) &value->un.du, sizeof value->un.du);
3254 else
3256 value->un.di.low = CONST_DOUBLE_LOW (x);
3257 value->un.di.high = CONST_DOUBLE_HIGH (x);
3259 break;
3261 case CONST_INT:
3262 value->un.addr.offset = INTVAL (x);
3263 break;
3265 case SYMBOL_REF:
3266 case LABEL_REF:
3267 case PC:
3268 value->un.addr.base = x;
3269 break;
3271 case CONST:
3272 x = XEXP (x, 0);
3273 if (GET_CODE (x) == PLUS)
3275 value->un.addr.base = XEXP (x, 0);
3276 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3277 abort ();
3278 value->un.addr.offset = INTVAL (XEXP (x, 1));
3280 else if (GET_CODE (x) == MINUS)
3282 value->un.addr.base = XEXP (x, 0);
3283 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3284 abort ();
3285 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3287 else
3288 abort ();
3289 break;
3291 default:
3292 abort ();
3295 if (value->kind == RTX_INT && value->un.addr.base != 0)
3296 switch (GET_CODE (value->un.addr.base))
3298 case SYMBOL_REF:
3299 case LABEL_REF:
3300 /* Use the string's address, not the SYMBOL_REF's address,
3301 for the sake of addresses of library routines.
3302 For a LABEL_REF, compare labels. */
3303 value->un.addr.base = XEXP (value->un.addr.base, 0);
3305 default:
3306 break;
3310 /* Given a MINUS expression, simplify it if both sides
3311 include the same symbol. */
3314 simplify_subtraction (x)
3315 rtx x;
3317 struct rtx_const val0, val1;
3319 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3320 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3322 if (val0.un.addr.base == val1.un.addr.base)
3323 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3324 return x;
3327 /* Compute a hash code for a constant RTL expression. */
3329 static int
3330 const_hash_rtx (mode, x)
3331 enum machine_mode mode;
3332 rtx x;
3334 register int hi;
3335 register size_t i;
3337 struct rtx_const value;
3338 decode_rtx_const (mode, x, &value);
3340 /* Compute hashing function */
3341 hi = 0;
3342 for (i = 0; i < sizeof value / sizeof (int); i++)
3343 hi += ((int *) &value)[i];
3345 hi &= (1 << HASHBITS) - 1;
3346 hi %= MAX_RTX_HASH_TABLE;
3347 return hi;
3350 /* Compare a constant rtl object X with a constant-descriptor DESC.
3351 Return 1 if DESC describes a constant with the same value as X. */
3353 static int
3354 compare_constant_rtx (mode, x, desc)
3355 enum machine_mode mode;
3356 rtx x;
3357 struct constant_descriptor *desc;
3359 register int *p = (int *) desc->contents;
3360 register int *strp;
3361 register int len;
3362 struct rtx_const value;
3364 decode_rtx_const (mode, x, &value);
3365 strp = (int *) &value;
3366 len = sizeof value / sizeof (int);
3368 /* Compare constant contents. */
3369 while (--len >= 0)
3370 if (*p++ != *strp++)
3371 return 0;
3373 return 1;
3376 /* Construct a constant descriptor for the rtl-expression X.
3377 It is up to the caller to enter the descriptor in the hash table. */
3379 static struct constant_descriptor *
3380 record_constant_rtx (mode, x)
3381 enum machine_mode mode;
3382 rtx x;
3384 struct constant_descriptor *ptr;
3385 char *label;
3386 struct rtx_const value;
3388 decode_rtx_const (mode, x, &value);
3390 /* Put these things in the saveable obstack so we can ensure it won't
3391 be freed if we are called from combine or some other phase that discards
3392 memory allocated from function_obstack (current_obstack). */
3393 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3394 obstack_grow (saveable_obstack, &label, sizeof label);
3396 /* Record constant contents. */
3397 obstack_grow (saveable_obstack, &value, sizeof value);
3399 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3402 /* Given a constant rtx X, make (or find) a memory constant for its value
3403 and return a MEM rtx to refer to it in memory. */
3406 force_const_mem (mode, x)
3407 enum machine_mode mode;
3408 rtx x;
3410 register int hash;
3411 register struct constant_descriptor *desc;
3412 char label[256];
3413 char *found = 0;
3414 rtx def;
3416 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3417 (this will always be true for floating CONST_DOUBLEs that have been
3418 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3419 use the previous copy. Otherwise, make a new one. Note that in
3420 the unlikely event that this same CONST_DOUBLE is used in two different
3421 modes in an alternating fashion, we will allocate a lot of different
3422 memory locations, but this should be extremely rare. */
3424 /* Don't use CONST_DOUBLE_MEM in a nested function.
3425 Nested functions have their own constant pools,
3426 so they can't share the same values in CONST_DOUBLE_MEM
3427 with the containing function. */
3428 if (outer_function_chain == 0)
3429 if (GET_CODE (x) == CONST_DOUBLE
3430 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3431 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3432 return CONST_DOUBLE_MEM (x);
3434 /* Compute hash code of X. Search the descriptors for that hash code
3435 to see if any of them describes X. If yes, the descriptor records
3436 the label number already assigned. */
3438 hash = const_hash_rtx (mode, x);
3440 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3441 if (compare_constant_rtx (mode, x, desc))
3443 found = desc->label;
3444 break;
3447 if (found == 0)
3449 register struct pool_constant *pool;
3450 register struct pool_sym *sym;
3451 int align;
3453 /* No constant equal to X is known to have been output.
3454 Make a constant descriptor to enter X in the hash table.
3455 Assign the label number and record it in the descriptor for
3456 future calls to this function to find. */
3458 desc = record_constant_rtx (mode, x);
3459 desc->next = const_rtx_hash_table[hash];
3460 const_rtx_hash_table[hash] = desc;
3462 /* Align the location counter as required by EXP's data type. */
3463 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3464 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3465 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3466 #ifdef CONSTANT_ALIGNMENT
3467 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3468 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3469 #endif
3471 pool_offset += align - 1;
3472 pool_offset &= ~ (align - 1);
3474 /* If RTL is not being placed into the saveable obstack, make a
3475 copy of X that is in the saveable obstack in case we are
3476 being called from combine or some other phase that discards
3477 memory it allocates. We used to only do this if it is a
3478 CONST; however, reload can allocate a CONST_INT when
3479 eliminating registers. */
3480 if (rtl_obstack != saveable_obstack
3481 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3483 push_obstacks_nochange ();
3484 rtl_in_saveable_obstack ();
3486 if (GET_CODE (x) == CONST)
3487 x = gen_rtx_CONST (GET_MODE (x),
3488 gen_rtx_PLUS (GET_MODE (x),
3489 XEXP (XEXP (x, 0), 0),
3490 XEXP (XEXP (x, 0), 1)));
3491 else
3492 x = GEN_INT (INTVAL (x));
3494 pop_obstacks ();
3497 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3499 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3500 pool->desc = desc;
3501 pool->constant = x;
3502 pool->mode = mode;
3503 pool->labelno = const_labelno;
3504 pool->align = align;
3505 pool->offset = pool_offset;
3506 pool->mark = 1;
3507 pool->next = 0;
3509 if (last_pool == 0)
3510 first_pool = pool;
3511 else
3512 last_pool->next = pool;
3514 last_pool = pool;
3515 pool_offset += GET_MODE_SIZE (mode);
3517 /* Create a string containing the label name, in LABEL. */
3518 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3520 ++const_labelno;
3522 desc->label = found
3523 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3525 /* Add label to symbol hash table. */
3526 hash = SYMHASH (found);
3527 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3528 sym->label = found;
3529 sym->pool = pool;
3530 sym->next = const_rtx_sym_hash_table[hash];
3531 const_rtx_sym_hash_table[hash] = sym;
3534 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3536 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3538 RTX_UNCHANGING_P (def) = 1;
3539 /* Mark the symbol_ref as belonging to this constants pool. */
3540 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3541 current_function_uses_const_pool = 1;
3543 if (outer_function_chain == 0)
3544 if (GET_CODE (x) == CONST_DOUBLE)
3546 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3548 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3549 const_double_chain = x;
3551 CONST_DOUBLE_MEM (x) = def;
3554 return def;
3557 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3558 the corresponding pool_constant structure. */
3560 static struct pool_constant *
3561 find_pool_constant (addr)
3562 rtx addr;
3564 struct pool_sym *sym;
3565 char *label = XSTR (addr, 0);
3567 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3568 if (sym->label == label)
3569 return sym->pool;
3571 abort ();
3574 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3577 get_pool_constant (addr)
3578 rtx addr;
3580 return (find_pool_constant (addr))->constant;
3583 /* Similar, return the mode. */
3585 enum machine_mode
3586 get_pool_mode (addr)
3587 rtx addr;
3589 return (find_pool_constant (addr))->mode;
3592 /* Similar, return the offset in the constant pool. */
3595 get_pool_offset (addr)
3596 rtx addr;
3598 return (find_pool_constant (addr))->offset;
3601 /* Return the size of the constant pool. */
3604 get_pool_size ()
3606 return pool_offset;
3609 /* Write all the constants in the constant pool. */
3611 void
3612 output_constant_pool (fnname, fndecl)
3613 char *fnname ATTRIBUTE_UNUSED;
3614 tree fndecl ATTRIBUTE_UNUSED;
3616 struct pool_constant *pool;
3617 rtx x;
3618 union real_extract u;
3620 /* It is possible for gcc to call force_const_mem and then to later
3621 discard the instructions which refer to the constant. In such a
3622 case we do not need to output the constant. */
3623 mark_constant_pool ();
3625 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3626 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3627 #endif
3629 for (pool = first_pool; pool; pool = pool->next)
3631 x = pool->constant;
3633 if (! pool->mark)
3634 continue;
3636 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3637 whose CODE_LABEL has been deleted. This can occur if a jump table
3638 is eliminated by optimization. If so, write a constant of zero
3639 instead. Note that this can also happen by turning the
3640 CODE_LABEL into a NOTE. */
3641 if (((GET_CODE (x) == LABEL_REF
3642 && (INSN_DELETED_P (XEXP (x, 0))
3643 || GET_CODE (XEXP (x, 0)) == NOTE)))
3644 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3645 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3646 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3647 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3648 x = const0_rtx;
3650 /* First switch to correct section. */
3651 #ifdef SELECT_RTX_SECTION
3652 SELECT_RTX_SECTION (pool->mode, x);
3653 #else
3654 readonly_data_section ();
3655 #endif
3657 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3658 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3659 pool->align, pool->labelno, done);
3660 #endif
3662 if (pool->align > 1)
3663 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3665 /* Output the label. */
3666 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3668 /* Output the value of the constant itself. */
3669 switch (GET_MODE_CLASS (pool->mode))
3671 case MODE_FLOAT:
3672 if (GET_CODE (x) != CONST_DOUBLE)
3673 abort ();
3675 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3676 assemble_real (u.d, pool->mode);
3677 break;
3679 case MODE_INT:
3680 case MODE_PARTIAL_INT:
3681 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3682 break;
3684 default:
3685 abort ();
3688 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3689 done: ;
3690 #endif
3694 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3695 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3696 #endif
3698 /* Done with this pool. */
3699 first_pool = last_pool = 0;
3702 /* Look through the instructions for this function, and mark all the
3703 entries in the constant pool which are actually being used. */
3705 static void
3706 mark_constant_pool ()
3708 register rtx insn;
3709 struct pool_constant *pool;
3711 if (first_pool == 0)
3712 return;
3714 for (pool = first_pool; pool; pool = pool->next)
3715 pool->mark = 0;
3717 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3718 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3719 mark_constants (PATTERN (insn));
3721 for (insn = current_function_epilogue_delay_list;
3722 insn;
3723 insn = XEXP (insn, 1))
3724 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3725 mark_constants (PATTERN (insn));
3727 /* It's possible that the only reference to a symbol is in a symbol
3728 that's in the constant pool. This happens in Fortran under some
3729 situations. (When the constant contains the address of another
3730 constant, and only the first is used directly in an insn.)
3731 This is potentially suboptimal if there's ever a possibility of
3732 backwards (in pool order) 2'd level references. However, it's
3733 not clear that 2'd level references can happen. */
3734 for (pool = first_pool; pool; pool = pool->next)
3736 struct pool_sym *sym;
3737 char *label;
3739 /* skip unmarked entries; no insn refers to them. */
3740 if (!pool->mark)
3741 continue;
3743 label = XSTR (pool->constant, 0);
3745 /* Be sure the symbol's value is marked. */
3746 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3747 sym = sym->next)
3748 if (sym->label == label)
3749 sym->pool->mark = 1;
3750 /* If we didn't find it, there's something truly wrong here, but it
3751 will be announced by the assembler. */
3755 static void
3756 mark_constants (x)
3757 register rtx x;
3759 register int i;
3760 register char *format_ptr;
3762 if (x == 0)
3763 return;
3765 if (GET_CODE (x) == SYMBOL_REF)
3767 if (CONSTANT_POOL_ADDRESS_P (x))
3768 find_pool_constant (x)->mark = 1;
3769 return;
3771 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3772 a MEM, but does not constitute a use of that MEM. This is particularly
3773 important inside a nested function, because CONST_DOUBLE_MEM may be
3774 a reference to a MEM in the parent's constant pool. See the comment
3775 in force_const_mem. */
3776 else if (GET_CODE (x) == CONST_DOUBLE)
3777 return;
3779 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3780 insns, not any notes that may be attached. We don't want to mark
3781 a constant just because it happens to appear in a REG_EQUIV note. */
3782 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3784 mark_constants (PATTERN (x));
3785 return;
3788 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3790 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3792 switch (*format_ptr++)
3794 case 'e':
3795 mark_constants (XEXP (x, i));
3796 break;
3798 case 'E':
3799 if (XVEC (x, i) != 0)
3801 register int j;
3803 for (j = 0; j < XVECLEN (x, i); j++)
3804 mark_constants (XVECEXP (x, i, j));
3806 break;
3808 case 'S':
3809 case 's':
3810 case '0':
3811 case 'i':
3812 case 'w':
3813 case 'n':
3814 case 'u':
3815 break;
3817 default:
3818 abort ();
3823 /* Find all the constants whose addresses are referenced inside of EXP,
3824 and make sure assembler code with a label has been output for each one.
3825 Indicate whether an ADDR_EXPR has been encountered. */
3827 static int
3828 output_addressed_constants (exp)
3829 tree exp;
3831 int reloc = 0;
3833 switch (TREE_CODE (exp))
3835 case ADDR_EXPR:
3837 register tree constant = TREE_OPERAND (exp, 0);
3839 while (TREE_CODE (constant) == COMPONENT_REF)
3841 constant = TREE_OPERAND (constant, 0);
3844 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3845 || TREE_CODE (constant) == CONSTRUCTOR)
3846 /* No need to do anything here
3847 for addresses of variables or functions. */
3848 output_constant_def (constant);
3850 reloc = 1;
3851 break;
3853 case PLUS_EXPR:
3854 case MINUS_EXPR:
3855 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3856 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3857 break;
3859 case NOP_EXPR:
3860 case CONVERT_EXPR:
3861 case NON_LVALUE_EXPR:
3862 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3863 break;
3865 case CONSTRUCTOR:
3867 register tree link;
3868 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3869 if (TREE_VALUE (link) != 0)
3870 reloc |= output_addressed_constants (TREE_VALUE (link));
3872 break;
3874 default:
3875 break;
3877 return reloc;
3880 /* Output assembler code for constant EXP to FILE, with no label.
3881 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3882 Assumes output_addressed_constants has been done on EXP already.
3884 Generate exactly SIZE bytes of assembler data, padding at the end
3885 with zeros if necessary. SIZE must always be specified.
3887 SIZE is important for structure constructors,
3888 since trailing members may have been omitted from the constructor.
3889 It is also important for initialization of arrays from string constants
3890 since the full length of the string constant might not be wanted.
3891 It is also needed for initialization of unions, where the initializer's
3892 type is just one member, and that may not be as long as the union.
3894 There a case in which we would fail to output exactly SIZE bytes:
3895 for a structure constructor that wants to produce more than SIZE bytes.
3896 But such constructors will never be generated for any possible input. */
3898 void
3899 output_constant (exp, size)
3900 register tree exp;
3901 register int size;
3903 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3905 /* Some front-ends use constants other than the standard
3906 language-indepdent varieties, but which may still be output
3907 directly. Give the front-end a chance to convert EXP to a
3908 language-independent representation. */
3909 if (lang_expand_constant)
3910 exp = (*lang_expand_constant) (exp);
3912 if (size == 0 || flag_syntax_only)
3913 return;
3915 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3916 That way we get the constant (we hope) inside it. Also, strip off any
3917 NOP_EXPR that converts between two record, union, array, or set types. */
3918 while ((TREE_CODE (exp) == NOP_EXPR
3919 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3920 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3921 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3922 exp = TREE_OPERAND (exp, 0);
3924 /* Allow a constructor with no elements for any data type.
3925 This means to fill the space with zeros. */
3926 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3928 assemble_zeros (size);
3929 return;
3932 switch (code)
3934 case CHAR_TYPE:
3935 case BOOLEAN_TYPE:
3936 case INTEGER_TYPE:
3937 case ENUMERAL_TYPE:
3938 case POINTER_TYPE:
3939 case REFERENCE_TYPE:
3940 /* ??? What about (int)((float)(int)&foo + 4) */
3941 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3942 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3943 exp = TREE_OPERAND (exp, 0);
3945 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3946 EXPAND_INITIALIZER),
3947 size, 0))
3948 error ("initializer for integer value is too complicated");
3949 size = 0;
3950 break;
3952 case REAL_TYPE:
3953 if (TREE_CODE (exp) != REAL_CST)
3954 error ("initializer for floating value is not a floating constant");
3956 assemble_real (TREE_REAL_CST (exp),
3957 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3958 size = 0;
3959 break;
3961 case COMPLEX_TYPE:
3962 output_constant (TREE_REALPART (exp), size / 2);
3963 output_constant (TREE_IMAGPART (exp), size / 2);
3964 size -= (size / 2) * 2;
3965 break;
3967 case ARRAY_TYPE:
3968 if (TREE_CODE (exp) == CONSTRUCTOR)
3970 output_constructor (exp, size);
3971 return;
3973 else if (TREE_CODE (exp) == STRING_CST)
3975 int excess = 0;
3977 if (size > TREE_STRING_LENGTH (exp))
3979 excess = size - TREE_STRING_LENGTH (exp);
3980 size = TREE_STRING_LENGTH (exp);
3983 assemble_string (TREE_STRING_POINTER (exp), size);
3984 size = excess;
3986 else
3987 abort ();
3988 break;
3990 case RECORD_TYPE:
3991 case UNION_TYPE:
3992 if (TREE_CODE (exp) == CONSTRUCTOR)
3993 output_constructor (exp, size);
3994 else
3995 abort ();
3996 return;
3998 case SET_TYPE:
3999 if (TREE_CODE (exp) == INTEGER_CST)
4000 assemble_integer (expand_expr (exp, NULL_RTX,
4001 VOIDmode, EXPAND_INITIALIZER),
4002 size, 1);
4003 else if (TREE_CODE (exp) == CONSTRUCTOR)
4005 unsigned char *buffer = (unsigned char *) alloca (size);
4006 if (get_set_constructor_bytes (exp, buffer, size))
4007 abort ();
4008 assemble_string ((char *) buffer, size);
4010 else
4011 error ("unknown set constructor type");
4012 return;
4014 default:
4015 break; /* ??? */
4018 if (size > 0)
4019 assemble_zeros (size);
4023 /* Subroutine of output_constant, used for CONSTRUCTORs
4024 (aggregate constants).
4025 Generate at least SIZE bytes, padding if necessary. */
4027 static void
4028 output_constructor (exp, size)
4029 tree exp;
4030 int size;
4032 register tree link, field = 0;
4033 HOST_WIDE_INT min_index = 0;
4034 /* Number of bytes output or skipped so far.
4035 In other words, current position within the constructor. */
4036 int total_bytes = 0;
4037 /* Non-zero means BYTE contains part of a byte, to be output. */
4038 int byte_buffer_in_use = 0;
4039 register int byte;
4041 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4042 abort ();
4044 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4045 field = TYPE_FIELDS (TREE_TYPE (exp));
4047 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4048 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4049 min_index
4050 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4052 /* As LINK goes through the elements of the constant,
4053 FIELD goes through the structure fields, if the constant is a structure.
4054 if the constant is a union, then we override this,
4055 by getting the field from the TREE_LIST element.
4056 But the constant could also be an array. Then FIELD is zero.
4058 There is always a maximum of one element in the chain LINK for unions
4059 (even if the initializer in a source program incorrectly contains
4060 more one). */
4061 for (link = CONSTRUCTOR_ELTS (exp);
4062 link;
4063 link = TREE_CHAIN (link),
4064 field = field ? TREE_CHAIN (field) : 0)
4066 tree val = TREE_VALUE (link);
4067 tree index = 0;
4069 /* the element in a union constructor specifies the proper field. */
4071 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4072 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4074 /* if available, use the type given by link */
4075 if (TREE_PURPOSE (link) != 0)
4076 field = TREE_PURPOSE (link);
4079 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4080 index = TREE_PURPOSE (link);
4082 /* Eliminate the marker that makes a cast not be an lvalue. */
4083 if (val != 0)
4084 STRIP_NOPS (val);
4086 if (index && TREE_CODE (index) == RANGE_EXPR)
4088 register int fieldsize
4089 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4090 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4091 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4092 HOST_WIDE_INT index;
4093 for (index = lo_index; index <= hi_index; index++)
4095 /* Output the element's initial value. */
4096 if (val == 0)
4097 assemble_zeros (fieldsize);
4098 else
4099 output_constant (val, fieldsize);
4101 /* Count its size. */
4102 total_bytes += fieldsize;
4105 else if (field == 0 || !DECL_BIT_FIELD (field))
4107 /* An element that is not a bit-field. */
4109 register int fieldsize;
4110 /* Since this structure is static,
4111 we know the positions are constant. */
4112 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4113 / BITS_PER_UNIT)
4114 : 0);
4115 if (index != 0)
4116 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4117 / BITS_PER_UNIT
4118 * (TREE_INT_CST_LOW (index) - min_index));
4120 /* Output any buffered-up bit-fields preceding this element. */
4121 if (byte_buffer_in_use)
4123 ASM_OUTPUT_BYTE (asm_out_file, byte);
4124 total_bytes++;
4125 byte_buffer_in_use = 0;
4128 /* Advance to offset of this element.
4129 Note no alignment needed in an array, since that is guaranteed
4130 if each element has the proper size. */
4131 if ((field != 0 || index != 0) && bitpos != total_bytes)
4133 assemble_zeros (bitpos - total_bytes);
4134 total_bytes = bitpos;
4137 /* Determine size this element should occupy. */
4138 if (field)
4140 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4141 abort ();
4142 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4144 /* This avoids overflow trouble. */
4145 tree size_tree = size_binop (CEIL_DIV_EXPR,
4146 DECL_SIZE (field),
4147 size_int (BITS_PER_UNIT));
4148 fieldsize = TREE_INT_CST_LOW (size_tree);
4150 else
4152 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4153 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4156 else
4157 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4159 /* Output the element's initial value. */
4160 if (val == 0)
4161 assemble_zeros (fieldsize);
4162 else
4163 output_constant (val, fieldsize);
4165 /* Count its size. */
4166 total_bytes += fieldsize;
4168 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4169 error ("invalid initial value for member `%s'",
4170 IDENTIFIER_POINTER (DECL_NAME (field)));
4171 else
4173 /* Element that is a bit-field. */
4175 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4176 int end_offset
4177 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4179 if (val == 0)
4180 val = integer_zero_node;
4182 /* If this field does not start in this (or, next) byte,
4183 skip some bytes. */
4184 if (next_offset / BITS_PER_UNIT != total_bytes)
4186 /* Output remnant of any bit field in previous bytes. */
4187 if (byte_buffer_in_use)
4189 ASM_OUTPUT_BYTE (asm_out_file, byte);
4190 total_bytes++;
4191 byte_buffer_in_use = 0;
4194 /* If still not at proper byte, advance to there. */
4195 if (next_offset / BITS_PER_UNIT != total_bytes)
4197 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4198 total_bytes = next_offset / BITS_PER_UNIT;
4202 if (! byte_buffer_in_use)
4203 byte = 0;
4205 /* We must split the element into pieces that fall within
4206 separate bytes, and combine each byte with previous or
4207 following bit-fields. */
4209 /* next_offset is the offset n fbits from the beginning of
4210 the structure to the next bit of this element to be processed.
4211 end_offset is the offset of the first bit past the end of
4212 this element. */
4213 while (next_offset < end_offset)
4215 int this_time;
4216 int shift;
4217 HOST_WIDE_INT value;
4218 int next_byte = next_offset / BITS_PER_UNIT;
4219 int next_bit = next_offset % BITS_PER_UNIT;
4221 /* Advance from byte to byte
4222 within this element when necessary. */
4223 while (next_byte != total_bytes)
4225 ASM_OUTPUT_BYTE (asm_out_file, byte);
4226 total_bytes++;
4227 byte = 0;
4230 /* Number of bits we can process at once
4231 (all part of the same byte). */
4232 this_time = MIN (end_offset - next_offset,
4233 BITS_PER_UNIT - next_bit);
4234 if (BYTES_BIG_ENDIAN)
4236 /* On big-endian machine, take the most significant bits
4237 first (of the bits that are significant)
4238 and put them into bytes from the most significant end. */
4239 shift = end_offset - next_offset - this_time;
4240 /* Don't try to take a bunch of bits that cross
4241 the word boundary in the INTEGER_CST. */
4242 if (shift < HOST_BITS_PER_WIDE_INT
4243 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4245 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4246 shift = HOST_BITS_PER_WIDE_INT;
4249 /* Now get the bits from the appropriate constant word. */
4250 if (shift < HOST_BITS_PER_WIDE_INT)
4252 value = TREE_INT_CST_LOW (val);
4254 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4256 value = TREE_INT_CST_HIGH (val);
4257 shift -= HOST_BITS_PER_WIDE_INT;
4259 else
4260 abort ();
4261 byte |= (((value >> shift)
4262 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4263 << (BITS_PER_UNIT - this_time - next_bit));
4265 else
4267 /* On little-endian machines,
4268 take first the least significant bits of the value
4269 and pack them starting at the least significant
4270 bits of the bytes. */
4271 shift = (next_offset
4272 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4273 /* Don't try to take a bunch of bits that cross
4274 the word boundary in the INTEGER_CST. */
4275 if (shift < HOST_BITS_PER_WIDE_INT
4276 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4278 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4279 shift = HOST_BITS_PER_WIDE_INT;
4282 /* Now get the bits from the appropriate constant word. */
4283 if (shift < HOST_BITS_PER_WIDE_INT)
4284 value = TREE_INT_CST_LOW (val);
4285 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4287 value = TREE_INT_CST_HIGH (val);
4288 shift -= HOST_BITS_PER_WIDE_INT;
4290 else
4291 abort ();
4292 byte |= (((value >> shift)
4293 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4294 << next_bit);
4296 next_offset += this_time;
4297 byte_buffer_in_use = 1;
4301 if (byte_buffer_in_use)
4303 ASM_OUTPUT_BYTE (asm_out_file, byte);
4304 total_bytes++;
4306 if (total_bytes < size)
4307 assemble_zeros (size - total_bytes);
4310 #ifdef HANDLE_PRAGMA_WEAK
4311 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4312 associatd with NAME. */
4315 add_weak (name, value)
4316 char *name;
4317 char *value;
4319 struct weak_syms *weak;
4321 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4323 if (weak == NULL)
4324 return 0;
4326 weak->next = weak_decls;
4327 weak->name = name;
4328 weak->value = value;
4329 weak_decls = weak;
4331 return 1;
4333 #endif /* HANDLE_PRAGMA_WEAK */
4335 /* Declare DECL to be a weak symbol. */
4337 void
4338 declare_weak (decl)
4339 tree decl;
4341 if (! TREE_PUBLIC (decl))
4342 error_with_decl (decl, "weak declaration of `%s' must be public");
4343 else if (TREE_ASM_WRITTEN (decl))
4344 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4345 else if (SUPPORTS_WEAK)
4346 DECL_WEAK (decl) = 1;
4347 #ifdef HANDLE_PRAGMA_WEAK
4348 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4349 #endif
4352 /* Emit any pending weak declarations. */
4354 #ifdef HANDLE_PRAGMA_WEAK
4355 struct weak_syms * weak_decls;
4356 #endif
4358 void
4359 weak_finish ()
4361 #ifdef HANDLE_PRAGMA_WEAK
4362 if (HANDLE_PRAGMA_WEAK)
4364 struct weak_syms *t;
4365 for (t = weak_decls; t; t = t->next)
4367 if (t->name)
4369 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4370 if (t->value)
4371 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4375 #endif
4378 /* Remove NAME from the pending list of weak symbols. This prevents
4379 the compiler from emitting multiple .weak directives which confuses
4380 some assemblers. */
4381 static void
4382 remove_from_pending_weak_list (name)
4383 char *name;
4385 #ifdef HANDLE_PRAGMA_WEAK
4386 if (HANDLE_PRAGMA_WEAK)
4388 struct weak_syms *t;
4389 for (t = weak_decls; t; t = t->next)
4391 if (t->name && strcmp (name, t->name) == 0)
4392 t->name = NULL;
4395 #endif
4398 void
4399 assemble_alias (decl, target)
4400 tree decl, target ATTRIBUTE_UNUSED;
4402 char *name;
4404 make_decl_rtl (decl, (char *) 0, 1);
4405 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4407 #ifdef ASM_OUTPUT_DEF
4408 /* Make name accessible from other files, if appropriate. */
4410 if (TREE_PUBLIC (decl))
4412 #ifdef ASM_WEAKEN_LABEL
4413 if (DECL_WEAK (decl))
4415 ASM_WEAKEN_LABEL (asm_out_file, name);
4416 /* Remove this function from the pending weak list so that
4417 we do not emit multiple .weak directives for it. */
4418 remove_from_pending_weak_list
4419 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4421 else
4422 #endif
4423 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4426 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4427 TREE_ASM_WRITTEN (decl) = 1;
4428 #else
4429 #ifdef ASM_OUTPUT_WEAK_ALIAS
4430 if (! DECL_WEAK (decl))
4431 warning ("only weak aliases are supported in this configuration");
4433 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4434 TREE_ASM_WRITTEN (decl) = 1;
4435 #else
4436 warning ("alias definitions not supported in this configuration; ignored");
4437 #endif
4438 #endif
4441 /* This determines whether or not we support link-once semantics. */
4442 #ifndef SUPPORTS_ONE_ONLY
4443 #ifdef MAKE_DECL_ONE_ONLY
4444 #define SUPPORTS_ONE_ONLY 1
4445 #else
4446 #define SUPPORTS_ONE_ONLY 0
4447 #endif
4448 #endif
4450 /* Returns 1 if the target configuration supports defining public symbols
4451 so that one of them will be chosen at link time instead of generating a
4452 multiply-defined symbol error, whether through the use of weak symbols or
4453 a target-specific mechanism for having duplicates discarded. */
4456 supports_one_only ()
4458 if (SUPPORTS_ONE_ONLY)
4459 return 1;
4460 return SUPPORTS_WEAK;
4463 /* Set up DECL as a public symbol that can be defined in multiple
4464 translation units without generating a linker error. */
4466 void
4467 make_decl_one_only (decl)
4468 tree decl;
4470 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4471 abort ();
4473 TREE_PUBLIC (decl) = 1;
4475 if (TREE_CODE (decl) == VAR_DECL
4476 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4477 DECL_COMMON (decl) = 1;
4478 else if (SUPPORTS_ONE_ONLY)
4480 #ifdef MAKE_DECL_ONE_ONLY
4481 MAKE_DECL_ONE_ONLY (decl);
4482 #endif
4483 DECL_ONE_ONLY (decl) = 1;
4485 else if (SUPPORTS_WEAK)
4486 DECL_WEAK (decl) = 1;
4487 else
4488 abort ();