Move *-*-gnu* pattern below *-*-linux*.
[official-gcc.git] / gcc / varasm.c
blob944d1bb47f3faff8a355d4f05e0260c8338613be
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 "function.h"
37 #include "expr.h"
38 #include "output.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "defaults.h"
42 #include "real.h"
43 #include "toplev.h"
44 #include "dbxout.h"
45 #include "sdbout.h"
47 #include "obstack.h"
48 #include "c-pragma.h"
50 #ifdef XCOFF_DEBUGGING_INFO
51 #include "xcoffout.h"
52 #endif
54 #ifndef TRAMPOLINE_ALIGNMENT
55 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
56 #endif
58 #ifndef ASM_STABS_OP
59 #define ASM_STABS_OP ".stabs"
60 #endif
62 /* Define the prefix to use when check_memory_usage_flag is enable. */
63 #ifdef NO_DOLLAR_IN_LABEL
64 #ifdef NO_DOT_IN_LABEL
65 #define CHKR_PREFIX "chkr_prefix_"
66 #else /* !NO_DOT_IN_LABEL */
67 #define CHKR_PREFIX "chkr."
68 #endif
69 #else /* !NO_DOLLAR_IN_LABEL */
70 #define CHKR_PREFIX "chkr$"
71 #endif
72 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
74 /* File in which assembler code is being written. */
76 extern FILE *asm_out_file;
78 /* The (assembler) name of the first globally-visible object output. */
79 char *first_global_object_name;
80 char *weak_global_object_name;
82 extern struct obstack *current_obstack;
83 extern struct obstack *saveable_obstack;
84 extern struct obstack *rtl_obstack;
85 extern struct obstack permanent_obstack;
86 #define obstack_chunk_alloc xmalloc
88 /* Number for making the label on the next
89 constant that is stored in memory. */
91 int const_labelno;
93 /* Number for making the label on the next
94 static variable internal to a function. */
96 int var_labelno;
98 /* Carry information from ASM_DECLARE_OBJECT_NAME
99 to ASM_FINISH_DECLARE_OBJECT. */
101 int size_directive_output;
103 /* The last decl for which assemble_variable was called,
104 if it did ASM_DECLARE_OBJECT_NAME.
105 If the last call to assemble_variable didn't do that,
106 this holds 0. */
108 tree last_assemble_variable_decl;
110 /* Nonzero if at least one function definition has been seen. */
112 static int function_defined;
114 struct addr_const;
115 struct constant_descriptor;
116 struct rtx_const;
117 struct pool_constant;
119 static const char *strip_reg_name PROTO((const char *));
120 static int contains_pointers_p PROTO((tree));
121 static void decode_addr_const PROTO((tree, struct addr_const *));
122 static int const_hash PROTO((tree));
123 static int compare_constant PROTO((tree,
124 struct constant_descriptor *));
125 static char *compare_constant_1 PROTO((tree, char *));
126 static struct constant_descriptor *record_constant PROTO((tree));
127 static void record_constant_1 PROTO((tree));
128 static tree copy_constant PROTO((tree));
129 static void output_constant_def_contents PROTO((tree, int, int));
130 static void decode_rtx_const PROTO((enum machine_mode, rtx,
131 struct rtx_const *));
132 static int const_hash_rtx PROTO((enum machine_mode, rtx));
133 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
134 struct constant_descriptor *));
135 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
136 rtx));
137 static struct pool_constant *find_pool_constant PROTO((rtx));
138 static void mark_constant_pool PROTO((void));
139 static void mark_constants PROTO((rtx));
140 static int output_addressed_constants PROTO((tree));
141 static void output_after_function_constants PROTO((void));
142 static void output_constructor PROTO((tree, int));
143 static void remove_from_pending_weak_list PROTO ((char *));
144 #ifdef ASM_OUTPUT_BSS
145 static void asm_output_bss PROTO((FILE *, tree, char *, int, int));
146 #endif
147 #ifdef BSS_SECTION_ASM_OP
148 #ifdef ASM_OUTPUT_ALIGNED_BSS
149 static void asm_output_aligned_bss PROTO((FILE *, tree, char *, int, int));
150 #endif
151 #endif /* BSS_SECTION_ASM_OP */
153 static enum in_section { no_section, in_text, in_data, in_named
154 #ifdef BSS_SECTION_ASM_OP
155 , in_bss
156 #endif
157 #ifdef EH_FRAME_SECTION_ASM_OP
158 , in_eh_frame
159 #endif
160 #ifdef EXTRA_SECTIONS
161 , EXTRA_SECTIONS
162 #endif
163 } in_section = no_section;
165 /* Return a non-zero value if DECL has a section attribute. */
166 #define IN_NAMED_SECTION(DECL) \
167 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
168 && DECL_SECTION_NAME (DECL) != NULL_TREE)
170 /* Text of section name when in_section == in_named. */
171 static char *in_named_name;
173 /* Define functions like text_section for any extra sections. */
174 #ifdef EXTRA_SECTION_FUNCTIONS
175 EXTRA_SECTION_FUNCTIONS
176 #endif
178 /* Tell assembler to switch to text section. */
180 void
181 text_section ()
183 if (in_section != in_text)
185 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
186 in_section = in_text;
190 /* Tell assembler to switch to data section. */
192 void
193 data_section ()
195 if (in_section != in_data)
197 if (flag_shared_data)
199 #ifdef SHARED_SECTION_ASM_OP
200 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
201 #else
202 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
203 #endif
205 else
206 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
208 in_section = in_data;
211 /* Tell assembler to ALWAYS switch to data section, in case
212 it's not sure where it it. */
214 void
215 force_data_section ()
217 in_section = no_section;
218 data_section ();
221 /* Tell assembler to switch to read-only data section. This is normally
222 the text section. */
224 void
225 readonly_data_section ()
227 #ifdef READONLY_DATA_SECTION
228 READONLY_DATA_SECTION (); /* Note this can call data_section. */
229 #else
230 text_section ();
231 #endif
234 /* Determine if we're in the text section. */
237 in_text_section ()
239 return in_section == in_text;
242 /* Determine if we're in the data section. */
245 in_data_section ()
247 return in_section == in_data;
250 /* Tell assembler to change to section NAME for DECL.
251 If DECL is NULL, just switch to section NAME.
252 If NAME is NULL, get the name from DECL.
253 If RELOC is 1, the initializer for DECL contains relocs. */
255 void
256 named_section (decl, name, reloc)
257 tree decl;
258 const char *name;
259 int reloc ATTRIBUTE_UNUSED;
261 if (decl != NULL_TREE
262 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
263 abort ();
264 if (name == NULL)
265 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
267 if (in_section != in_named || strcmp (name, in_named_name))
269 #ifdef ASM_OUTPUT_SECTION_NAME
270 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
271 #else
272 /* Section attributes are not supported if this macro isn't provided -
273 some host formats don't support them at all. The front-end should
274 already have flagged this as an error. */
275 abort ();
276 #endif
278 in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1);
279 strcpy (in_named_name, name);
280 in_section = in_named;
284 #ifdef ASM_OUTPUT_SECTION_NAME
285 #ifndef UNIQUE_SECTION
286 #define UNIQUE_SECTION(DECL,RELOC) \
287 do { \
288 int len; \
289 const char *name; \
290 char *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 #ifdef ASM_DECLARE_REGISTER_GLOBAL
709 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
710 #endif
711 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
712 while (nregs > 0)
713 globalize_reg (reg_number + --nregs);
716 /* Specifying a section attribute on a variable forces it into a
717 non-.bss section, and thus it cannot be common. */
718 else if (TREE_CODE (decl) == VAR_DECL
719 && DECL_SECTION_NAME (decl) != NULL_TREE
720 && DECL_INITIAL (decl) == NULL_TREE
721 && DECL_COMMON (decl))
722 DECL_COMMON (decl) = 0;
724 /* Now handle ordinary static variables and functions (in memory).
725 Also handle vars declared register invalidly. */
726 if (DECL_RTL (decl) == 0)
728 /* Can't use just the variable's own name for a variable
729 whose scope is less than the whole file.
730 Concatenate a distinguishing number. */
731 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
733 char *label;
735 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
736 name = obstack_copy0 (saveable_obstack, label, strlen (label));
737 var_labelno++;
740 if (name == 0)
741 abort ();
743 /* When -fprefix-function-name is used, the functions
744 names are prefixed. Only nested function names are not
745 prefixed. */
746 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
748 char *new_name;
749 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE
750 + 1);
751 strcpy (new_name, CHKR_PREFIX);
752 strcpy (new_name + CHKR_PREFIX_SIZE, name);
753 name = obstack_copy0 (saveable_obstack,
754 new_name, strlen (new_name));
757 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
758 gen_rtx_SYMBOL_REF (Pmode, name));
759 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
761 /* If this variable is to be treated as volatile, show its
762 tree node has side effects. If it has side effects, either
763 because of this test or from TREE_THIS_VOLATILE also
764 being set, show the MEM is volatile. */
765 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
766 && TREE_PUBLIC (decl))
767 TREE_SIDE_EFFECTS (decl) = 1;
768 else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
769 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
770 TREE_SIDE_EFFECTS (decl) = 1;
772 if (TREE_SIDE_EFFECTS (decl))
773 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
775 if (TREE_READONLY (decl))
776 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
777 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
778 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
780 /* Optionally set flags or add text to the name to record information
781 such as that it is a function name.
782 If the name is changed, the macro ASM_OUTPUT_LABELREF
783 will have to know how to strip this information. */
784 #ifdef ENCODE_SECTION_INFO
785 ENCODE_SECTION_INFO (decl);
786 #endif
789 else
791 /* If the old RTL had the wrong mode, fix the mode. */
792 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
794 rtx rtl = DECL_RTL (decl);
795 PUT_MODE (rtl, DECL_MODE (decl));
798 /* ??? Another way to do this would be to do what halfpic.c does
799 and maintain a hashed table of such critters. */
800 /* ??? Another way to do this would be to pass a flag bit to
801 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
802 /* Let the target reassign the RTL if it wants.
803 This is necessary, for example, when one machine specific
804 decl attribute overrides another. */
805 #ifdef REDO_SECTION_INFO_P
806 if (REDO_SECTION_INFO_P (decl))
807 ENCODE_SECTION_INFO (decl);
808 #endif
812 /* Make the rtl for variable VAR be volatile.
813 Use this only for static variables. */
815 void
816 make_var_volatile (var)
817 tree var;
819 if (GET_CODE (DECL_RTL (var)) != MEM)
820 abort ();
822 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
825 /* Output alignment directive to align for constant expression EXP. */
827 void
828 assemble_constant_align (exp)
829 tree exp;
831 int align;
833 /* Align the location counter as required by EXP's data type. */
834 align = TYPE_ALIGN (TREE_TYPE (exp));
835 #ifdef CONSTANT_ALIGNMENT
836 align = CONSTANT_ALIGNMENT (exp, align);
837 #endif
839 if (align > BITS_PER_UNIT)
840 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
843 /* Output a string of literal assembler code
844 for an `asm' keyword used between functions. */
846 void
847 assemble_asm (string)
848 tree string;
850 app_enable ();
852 if (TREE_CODE (string) == ADDR_EXPR)
853 string = TREE_OPERAND (string, 0);
855 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
858 #if 0 /* This should no longer be needed, because
859 flag_gnu_linker should be 0 on these systems,
860 which should prevent any output
861 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
862 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
863 #ifndef ASM_OUTPUT_CONSTRUCTOR
864 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
865 #endif
866 #ifndef ASM_OUTPUT_DESTRUCTOR
867 #define ASM_OUTPUT_DESTRUCTOR(file, name)
868 #endif
869 #endif
870 #endif /* 0 */
872 /* Record an element in the table of global destructors.
873 How this is done depends on what sort of assembler and linker
874 are in use.
876 NAME should be the name of a global function to be called
877 at exit time. This name is output using assemble_name. */
879 void
880 assemble_destructor (name)
881 char *name;
883 #ifdef ASM_OUTPUT_DESTRUCTOR
884 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
885 #else
886 if (flag_gnu_linker)
888 /* Now tell GNU LD that this is part of the static destructor set. */
889 /* This code works for any machine provided you use GNU as/ld. */
890 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
891 assemble_name (asm_out_file, name);
892 fputc ('\n', asm_out_file);
894 #endif
897 /* Likewise for global constructors. */
899 void
900 assemble_constructor (name)
901 char *name;
903 #ifdef ASM_OUTPUT_CONSTRUCTOR
904 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
905 #else
906 if (flag_gnu_linker)
908 /* Now tell GNU LD that this is part of the static constructor set. */
909 /* This code works for any machine provided you use GNU as/ld. */
910 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
911 assemble_name (asm_out_file, name);
912 fputc ('\n', asm_out_file);
914 #endif
917 /* Likewise for entries we want to record for garbage collection.
918 Garbage collection is still under development. */
920 void
921 assemble_gc_entry (name)
922 char *name;
924 #ifdef ASM_OUTPUT_GC_ENTRY
925 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
926 #else
927 if (flag_gnu_linker)
929 /* Now tell GNU LD that this is part of the static constructor set. */
930 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
931 assemble_name (asm_out_file, name);
932 fputc ('\n', asm_out_file);
934 #endif
937 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
938 a non-zero value if the constant pool should be output before the
939 start of the function, or a zero value if the pool should output
940 after the end of the function. The default is to put it before the
941 start. */
943 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
944 #define CONSTANT_POOL_BEFORE_FUNCTION 1
945 #endif
947 /* Output assembler code for the constant pool of a function and associated
948 with defining the name of the function. DECL describes the function.
949 NAME is the function's name. For the constant pool, we use the current
950 constant pool data. */
952 void
953 assemble_start_function (decl, fnname)
954 tree decl;
955 char *fnname;
957 int align;
959 /* The following code does not need preprocessing in the assembler. */
961 app_disable ();
963 if (CONSTANT_POOL_BEFORE_FUNCTION)
964 output_constant_pool (fnname, decl);
966 #ifdef ASM_OUTPUT_SECTION_NAME
967 /* If the function is to be put in its own section and it's not in a section
968 already, indicate so. */
969 if ((flag_function_sections
970 && DECL_SECTION_NAME (decl) == NULL_TREE)
971 || UNIQUE_SECTION_P (decl))
972 UNIQUE_SECTION (decl, 0);
973 #endif
975 function_section (decl);
977 /* Tell assembler to move to target machine's alignment for functions. */
978 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
979 if (align > 0)
980 ASM_OUTPUT_ALIGN (asm_out_file, align);
982 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
983 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
984 #endif
986 #ifdef SDB_DEBUGGING_INFO
987 /* Output SDB definition of the function. */
988 if (write_symbols == SDB_DEBUG)
989 sdbout_mark_begin_function ();
990 #endif
992 #ifdef DBX_DEBUGGING_INFO
993 /* Output DBX definition of the function. */
994 if (write_symbols == DBX_DEBUG)
995 dbxout_begin_function (decl);
996 #endif
998 /* Make function name accessible from other files, if appropriate. */
1000 if (TREE_PUBLIC (decl))
1002 if (! first_global_object_name)
1004 const char *p;
1005 char **name;
1007 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1008 name = &first_global_object_name;
1009 else
1010 name = &weak_global_object_name;
1012 STRIP_NAME_ENCODING (p, fnname);
1013 *name = permalloc (strlen (p) + 1);
1014 strcpy (*name, p);
1017 #ifdef ASM_WEAKEN_LABEL
1018 if (DECL_WEAK (decl))
1020 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1021 /* Remove this function from the pending weak list so that
1022 we do not emit multiple .weak directives for it. */
1023 remove_from_pending_weak_list
1024 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1026 else
1027 #endif
1028 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1031 /* Do any machine/system dependent processing of the function name */
1032 #ifdef ASM_DECLARE_FUNCTION_NAME
1033 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1034 #else
1035 /* Standard thing is just output label for the function. */
1036 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1037 #endif /* ASM_DECLARE_FUNCTION_NAME */
1040 /* Output assembler code associated with defining the size of the
1041 function. DECL describes the function. NAME is the function's name. */
1043 void
1044 assemble_end_function (decl, fnname)
1045 tree decl;
1046 char *fnname;
1048 #ifdef ASM_DECLARE_FUNCTION_SIZE
1049 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1050 #endif
1051 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1053 output_constant_pool (fnname, decl);
1054 function_section (decl); /* need to switch back */
1057 /* Output any constants which should appear after the function. */
1058 output_after_function_constants ();
1061 /* Assemble code to leave SIZE bytes of zeros. */
1063 void
1064 assemble_zeros (size)
1065 int size;
1067 /* Do no output if -fsyntax-only. */
1068 if (flag_syntax_only)
1069 return;
1071 #ifdef ASM_NO_SKIP_IN_TEXT
1072 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1073 so we must output 0s explicitly in the text section. */
1074 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1076 int i;
1078 for (i = 0; i < size - 20; i += 20)
1080 #ifdef ASM_BYTE_OP
1081 fprintf (asm_out_file,
1082 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
1083 #else
1084 fprintf (asm_out_file,
1085 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1086 #endif
1088 if (i < size)
1090 #ifdef ASM_BYTE_OP
1091 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1092 #else
1093 fprintf (asm_out_file, "\tbyte 0");
1094 #endif
1095 i++;
1096 for (; i < size; i++)
1097 fprintf (asm_out_file, ",0");
1098 fprintf (asm_out_file, "\n");
1101 else
1102 #endif
1103 if (size > 0)
1104 ASM_OUTPUT_SKIP (asm_out_file, size);
1107 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1109 void
1110 assemble_align (align)
1111 int align;
1113 if (align > BITS_PER_UNIT)
1114 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1117 /* Assemble a string constant with the specified C string as contents. */
1119 void
1120 assemble_string (p, size)
1121 const char *p;
1122 int size;
1124 int pos = 0;
1125 int maximum = 2000;
1127 /* If the string is very long, split it up. */
1129 while (pos < size)
1131 int thissize = size - pos;
1132 if (thissize > maximum)
1133 thissize = maximum;
1135 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1137 pos += thissize;
1138 p += thissize;
1143 /* Assemble everything that is needed for a variable or function declaration.
1144 Not used for automatic variables, and not used for function definitions.
1145 Should not be called for variables of incomplete structure type.
1147 TOP_LEVEL is nonzero if this variable has file scope.
1148 AT_END is nonzero if this is the special handling, at end of compilation,
1149 to define things that have had only tentative definitions.
1150 DONT_OUTPUT_DATA if nonzero means don't actually output the
1151 initial value (that will be done by the caller). */
1153 void
1154 assemble_variable (decl, top_level, at_end, dont_output_data)
1155 tree decl;
1156 int top_level ATTRIBUTE_UNUSED;
1157 int at_end;
1158 int dont_output_data;
1160 register char *name;
1161 unsigned int align;
1162 tree size_tree = NULL_TREE;
1163 int reloc = 0;
1164 enum in_section saved_in_section;
1166 last_assemble_variable_decl = 0;
1168 if (GET_CODE (DECL_RTL (decl)) == REG)
1170 /* Do output symbol info for global register variables, but do nothing
1171 else for them. */
1173 if (TREE_ASM_WRITTEN (decl))
1174 return;
1175 TREE_ASM_WRITTEN (decl) = 1;
1177 /* Do no output if -fsyntax-only. */
1178 if (flag_syntax_only)
1179 return;
1181 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1182 /* File-scope global variables are output here. */
1183 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1184 && top_level)
1185 dbxout_symbol (decl, 0);
1186 #endif
1187 #ifdef SDB_DEBUGGING_INFO
1188 if (write_symbols == SDB_DEBUG && top_level
1189 /* Leave initialized global vars for end of compilation;
1190 see comment in compile_file. */
1191 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1192 sdbout_symbol (decl, 0);
1193 #endif
1195 /* Don't output any DWARF debugging information for variables here.
1196 In the case of local variables, the information for them is output
1197 when we do our recursive traversal of the tree representation for
1198 the entire containing function. In the case of file-scope variables,
1199 we output information for all of them at the very end of compilation
1200 while we are doing our final traversal of the chain of file-scope
1201 declarations. */
1203 return;
1206 /* Normally no need to say anything here for external references,
1207 since assemble_external is called by the language-specific code
1208 when a declaration is first seen. */
1210 if (DECL_EXTERNAL (decl))
1211 return;
1213 /* Output no assembler code for a function declaration.
1214 Only definitions of functions output anything. */
1216 if (TREE_CODE (decl) == FUNCTION_DECL)
1217 return;
1219 /* If type was incomplete when the variable was declared,
1220 see if it is complete now. */
1222 if (DECL_SIZE (decl) == 0)
1223 layout_decl (decl, 0);
1225 /* Still incomplete => don't allocate it; treat the tentative defn
1226 (which is what it must have been) as an `extern' reference. */
1228 if (!dont_output_data && DECL_SIZE (decl) == 0)
1230 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1231 DECL_SOURCE_LINE (decl),
1232 "storage size of `%s' isn't known",
1233 IDENTIFIER_POINTER (DECL_NAME (decl)));
1234 TREE_ASM_WRITTEN (decl) = 1;
1235 return;
1238 /* The first declaration of a variable that comes through this function
1239 decides whether it is global (in C, has external linkage)
1240 or local (in C, has internal linkage). So do nothing more
1241 if this function has already run. */
1243 if (TREE_ASM_WRITTEN (decl))
1244 return;
1246 TREE_ASM_WRITTEN (decl) = 1;
1248 /* Do no output if -fsyntax-only. */
1249 if (flag_syntax_only)
1250 return;
1252 app_disable ();
1254 if (! dont_output_data)
1256 int size;
1258 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1259 goto finish;
1261 /* This is better than explicit arithmetic, since it avoids overflow. */
1262 size_tree = size_binop (CEIL_DIV_EXPR,
1263 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1265 size = TREE_INT_CST_LOW (size_tree);
1266 if (TREE_INT_CST_HIGH (size_tree) != 0
1267 || size != TREE_INT_CST_LOW (size_tree))
1269 error_with_decl (decl, "size of variable `%s' is too large");
1270 goto finish;
1274 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1276 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1277 && ! first_global_object_name
1278 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1279 || DECL_INITIAL (decl) == error_mark_node))
1280 && ! DECL_WEAK (decl)
1281 && ! DECL_ONE_ONLY (decl))
1283 const char *p;
1285 STRIP_NAME_ENCODING (p, name);
1286 first_global_object_name = permalloc (strlen (p) + 1);
1287 strcpy (first_global_object_name, p);
1290 /* Compute the alignment of this data. */
1292 align = DECL_ALIGN (decl);
1294 /* In the case for initialing an array whose length isn't specified,
1295 where we have not yet been able to do the layout,
1296 figure out the proper alignment now. */
1297 if (dont_output_data && DECL_SIZE (decl) == 0
1298 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1299 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1301 /* Some object file formats have a maximum alignment which they support.
1302 In particular, a.out format supports a maximum alignment of 4. */
1303 #ifndef MAX_OFILE_ALIGNMENT
1304 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1305 #endif
1306 if (align > MAX_OFILE_ALIGNMENT)
1308 warning_with_decl (decl,
1309 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1310 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1311 align = MAX_OFILE_ALIGNMENT;
1314 /* On some machines, it is good to increase alignment sometimes. */
1315 #ifdef DATA_ALIGNMENT
1316 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1317 #endif
1318 #ifdef CONSTANT_ALIGNMENT
1319 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1320 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1321 #endif
1323 /* Reset the alignment in case we have made it tighter, so we can benefit
1324 from it in get_pointer_alignment. */
1325 DECL_ALIGN (decl) = align;
1327 /* Handle uninitialized definitions. */
1329 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1330 /* If the target can't output uninitialized but not common global data
1331 in .bss, then we have to use .data. */
1332 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1333 && DECL_COMMON (decl)
1334 #endif
1335 && DECL_SECTION_NAME (decl) == 0
1336 && ! dont_output_data)
1338 int size = TREE_INT_CST_LOW (size_tree);
1339 int rounded = size;
1341 /* Don't allocate zero bytes of common,
1342 since that means "undefined external" in the linker. */
1343 if (size == 0) rounded = 1;
1344 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1345 so that each uninitialized object starts on such a boundary. */
1346 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1347 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1348 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1350 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1351 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1352 warning_with_decl
1353 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1354 #endif
1356 #ifdef DBX_DEBUGGING_INFO
1357 /* File-scope global variables are output here. */
1358 if (write_symbols == DBX_DEBUG && top_level)
1359 dbxout_symbol (decl, 0);
1360 #endif
1361 #ifdef SDB_DEBUGGING_INFO
1362 if (write_symbols == SDB_DEBUG && top_level
1363 /* Leave initialized global vars for end of compilation;
1364 see comment in compile_file. */
1365 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1366 sdbout_symbol (decl, 0);
1367 #endif
1369 /* Don't output any DWARF debugging information for variables here.
1370 In the case of local variables, the information for them is output
1371 when we do our recursive traversal of the tree representation for
1372 the entire containing function. In the case of file-scope variables,
1373 we output information for all of them at the very end of compilation
1374 while we are doing our final traversal of the chain of file-scope
1375 declarations. */
1377 #if 0 /* ??? We should either delete this or add a comment describing what
1378 it was intended to do and why we shouldn't delete it. */
1379 if (flag_shared_data)
1380 data_section ();
1381 #endif
1383 if (TREE_PUBLIC (decl)
1384 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1385 && DECL_COMMON (decl)
1386 #endif
1389 #ifdef ASM_OUTPUT_SHARED_COMMON
1390 if (flag_shared_data)
1391 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1392 else
1393 #endif
1395 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1396 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1397 DECL_ALIGN (decl));
1398 #else
1399 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1400 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1401 DECL_ALIGN (decl));
1402 #else
1403 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1404 #endif
1405 #endif
1408 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1409 else if (TREE_PUBLIC (decl))
1411 #ifdef ASM_OUTPUT_SHARED_BSS
1412 if (flag_shared_data)
1413 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1414 else
1415 #endif
1417 #ifdef ASM_OUTPUT_ALIGNED_BSS
1418 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1419 DECL_ALIGN (decl));
1420 #else
1421 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1422 #endif
1425 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1426 else
1428 #ifdef ASM_OUTPUT_SHARED_LOCAL
1429 if (flag_shared_data)
1430 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1431 else
1432 #endif
1434 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1435 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1436 DECL_ALIGN (decl));
1437 #else
1438 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1439 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1440 DECL_ALIGN (decl));
1441 #else
1442 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1443 #endif
1444 #endif
1447 goto finish;
1450 /* Handle initialized definitions.
1451 Also handle uninitialized global definitions if -fno-common and the
1452 target doesn't support ASM_OUTPUT_BSS. */
1454 /* First make the assembler name(s) global if appropriate. */
1455 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1457 #ifdef ASM_WEAKEN_LABEL
1458 if (DECL_WEAK (decl))
1460 ASM_WEAKEN_LABEL (asm_out_file, name);
1461 /* Remove this variable from the pending weak list so that
1462 we do not emit multiple .weak directives for it. */
1463 remove_from_pending_weak_list
1464 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1466 else
1467 #endif
1468 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1470 #if 0
1471 for (d = equivalents; d; d = TREE_CHAIN (d))
1473 tree e = TREE_VALUE (d);
1474 if (TREE_PUBLIC (e) && DECL_NAME (e))
1475 ASM_GLOBALIZE_LABEL (asm_out_file,
1476 XSTR (XEXP (DECL_RTL (e), 0), 0));
1478 #endif
1480 /* Output any data that we will need to use the address of. */
1481 if (DECL_INITIAL (decl) == error_mark_node)
1482 reloc = contains_pointers_p (TREE_TYPE (decl));
1483 else if (DECL_INITIAL (decl))
1484 reloc = output_addressed_constants (DECL_INITIAL (decl));
1486 #ifdef ASM_OUTPUT_SECTION_NAME
1487 if ((flag_data_sections != 0
1488 && DECL_SECTION_NAME (decl) == NULL_TREE)
1489 || UNIQUE_SECTION_P (decl))
1490 UNIQUE_SECTION (decl, reloc);
1491 #endif
1493 /* Switch to the appropriate section. */
1494 variable_section (decl, reloc);
1496 /* dbxout.c needs to know this. */
1497 if (in_text_section ())
1498 DECL_IN_TEXT_SECTION (decl) = 1;
1500 /* Record current section so we can restore it if dbxout.c clobbers it. */
1501 saved_in_section = in_section;
1503 /* Output the dbx info now that we have chosen the section. */
1505 #ifdef DBX_DEBUGGING_INFO
1506 /* File-scope global variables are output here. */
1507 if (write_symbols == DBX_DEBUG && top_level)
1508 dbxout_symbol (decl, 0);
1509 #endif
1510 #ifdef SDB_DEBUGGING_INFO
1511 if (write_symbols == SDB_DEBUG && top_level
1512 /* Leave initialized global vars for end of compilation;
1513 see comment in compile_file. */
1514 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1515 sdbout_symbol (decl, 0);
1516 #endif
1518 /* Don't output any DWARF debugging information for variables here.
1519 In the case of local variables, the information for them is output
1520 when we do our recursive traversal of the tree representation for
1521 the entire containing function. In the case of file-scope variables,
1522 we output information for all of them at the very end of compilation
1523 while we are doing our final traversal of the chain of file-scope
1524 declarations. */
1526 /* If the debugging output changed sections, reselect the section
1527 that's supposed to be selected. */
1528 if (in_section != saved_in_section)
1529 variable_section (decl, reloc);
1531 /* Output the alignment of this data. */
1532 if (align > BITS_PER_UNIT)
1533 ASM_OUTPUT_ALIGN (asm_out_file,
1534 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1536 /* Do any machine/system dependent processing of the object. */
1537 #ifdef ASM_DECLARE_OBJECT_NAME
1538 last_assemble_variable_decl = decl;
1539 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1540 #else
1541 /* Standard thing is just output label for the object. */
1542 ASM_OUTPUT_LABEL (asm_out_file, name);
1543 #endif /* ASM_DECLARE_OBJECT_NAME */
1545 if (!dont_output_data)
1547 if (DECL_INITIAL (decl))
1548 /* Output the actual data. */
1549 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1550 else
1551 /* Leave space for it. */
1552 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1555 finish:
1556 #ifdef XCOFF_DEBUGGING_INFO
1557 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1558 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1559 and `aa' hasn't been output yet, the assembler generates a stab entry with
1560 a value of zero, in addition to creating an unnecessary external entry
1561 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1563 /* File-scope global variables are output here. */
1564 if (write_symbols == XCOFF_DEBUG && top_level)
1566 saved_in_section = in_section;
1568 dbxout_symbol (decl, 0);
1570 if (in_section != saved_in_section)
1571 variable_section (decl, reloc);
1573 #else
1574 /* There must be a statement after a label. */
1576 #endif
1579 /* Return 1 if type TYPE contains any pointers. */
1581 static int
1582 contains_pointers_p (type)
1583 tree type;
1585 switch (TREE_CODE (type))
1587 case POINTER_TYPE:
1588 case REFERENCE_TYPE:
1589 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1590 so I'll play safe and return 1. */
1591 case OFFSET_TYPE:
1592 return 1;
1594 case RECORD_TYPE:
1595 case UNION_TYPE:
1596 case QUAL_UNION_TYPE:
1598 tree fields;
1599 /* For a type that has fields, see if the fields have pointers. */
1600 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1601 if (TREE_CODE (fields) == FIELD_DECL
1602 && contains_pointers_p (TREE_TYPE (fields)))
1603 return 1;
1604 return 0;
1607 case ARRAY_TYPE:
1608 /* An array type contains pointers if its element type does. */
1609 return contains_pointers_p (TREE_TYPE (type));
1611 default:
1612 return 0;
1616 /* Output something to declare an external symbol to the assembler.
1617 (Most assemblers don't need this, so we normally output nothing.)
1618 Do nothing if DECL is not external. */
1620 void
1621 assemble_external (decl)
1622 tree decl ATTRIBUTE_UNUSED;
1624 #ifdef ASM_OUTPUT_EXTERNAL
1625 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1626 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1628 rtx rtl = DECL_RTL (decl);
1630 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1631 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1633 /* Some systems do require some output. */
1634 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1635 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1638 #endif
1641 /* Similar, for calling a library function FUN. */
1643 void
1644 assemble_external_libcall (fun)
1645 rtx fun ATTRIBUTE_UNUSED;
1647 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1648 /* Declare library function name external when first used, if nec. */
1649 if (! SYMBOL_REF_USED (fun))
1651 SYMBOL_REF_USED (fun) = 1;
1652 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1654 #endif
1657 /* Declare the label NAME global. */
1659 void
1660 assemble_global (name)
1661 char *name;
1663 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1666 /* Assemble a label named NAME. */
1668 void
1669 assemble_label (name)
1670 char *name;
1672 ASM_OUTPUT_LABEL (asm_out_file, name);
1675 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1676 If NAME starts with a *, the rest of NAME is output verbatim.
1677 Otherwise NAME is transformed in an implementation-defined way
1678 (usually by the addition of an underscore).
1679 Many macros in the tm file are defined to call this function. */
1681 void
1682 assemble_name (file, name)
1683 FILE *file;
1684 const char *name;
1686 const char *real_name;
1687 tree id;
1689 STRIP_NAME_ENCODING (real_name, name);
1690 if (flag_prefix_function_name
1691 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1692 real_name = real_name + CHKR_PREFIX_SIZE;
1694 id = maybe_get_identifier (real_name);
1695 if (id)
1696 TREE_SYMBOL_REFERENCED (id) = 1;
1698 if (name[0] == '*')
1699 fputs (&name[1], file);
1700 else
1701 ASM_OUTPUT_LABELREF (file, name);
1704 /* Allocate SIZE bytes writable static space with a gensym name
1705 and return an RTX to refer to its address. */
1708 assemble_static_space (size)
1709 int size;
1711 char name[12];
1712 char *namestring;
1713 rtx x;
1715 #if 0
1716 if (flag_shared_data)
1717 data_section ();
1718 #endif
1720 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1721 ++const_labelno;
1723 namestring = (char *) obstack_alloc (saveable_obstack,
1724 strlen (name) + 2);
1725 strcpy (namestring, name);
1727 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1729 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1730 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1731 BIGGEST_ALIGNMENT);
1732 #else
1733 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1734 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1735 #else
1737 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1738 so that each uninitialized object starts on such a boundary. */
1739 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1740 int rounded ATTRIBUTE_UNUSED
1741 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1742 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1743 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1744 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1746 #endif
1747 #endif
1748 return x;
1751 /* Assemble the static constant template for function entry trampolines.
1752 This is done at most once per compilation.
1753 Returns an RTX for the address of the template. */
1755 #ifdef TRAMPOLINE_TEMPLATE
1757 assemble_trampoline_template ()
1759 char label[256];
1760 char *name;
1761 int align;
1763 /* By default, put trampoline templates in read-only data section. */
1765 #ifdef TRAMPOLINE_SECTION
1766 TRAMPOLINE_SECTION ();
1767 #else
1768 readonly_data_section ();
1769 #endif
1771 /* Write the assembler code to define one. */
1772 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1773 if (align > 0)
1774 ASM_OUTPUT_ALIGN (asm_out_file, align);
1776 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1777 TRAMPOLINE_TEMPLATE (asm_out_file);
1779 /* Record the rtl to refer to it. */
1780 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1781 name
1782 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1783 return gen_rtx_SYMBOL_REF (Pmode, name);
1785 #endif
1787 /* Assemble the integer constant X into an object of SIZE bytes.
1788 X must be either a CONST_INT or CONST_DOUBLE.
1790 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1791 non-zero, abort if we can't output the constant. */
1794 assemble_integer (x, size, force)
1795 rtx x;
1796 int size;
1797 int force;
1799 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1800 ASM_OUTPUT... macros. */
1802 switch (size)
1804 #ifdef ASM_OUTPUT_CHAR
1805 case 1:
1806 ASM_OUTPUT_CHAR (asm_out_file, x);
1807 return 1;
1808 #endif
1810 #ifdef ASM_OUTPUT_SHORT
1811 case 2:
1812 ASM_OUTPUT_SHORT (asm_out_file, x);
1813 return 1;
1814 #endif
1816 #ifdef ASM_OUTPUT_INT
1817 case 4:
1818 ASM_OUTPUT_INT (asm_out_file, x);
1819 return 1;
1820 #endif
1822 #ifdef ASM_OUTPUT_DOUBLE_INT
1823 case 8:
1824 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1825 return 1;
1826 #endif
1828 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1829 case 16:
1830 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1831 return 1;
1832 #endif
1835 /* If we couldn't do it that way, there are two other possibilities: First,
1836 if the machine can output an explicit byte and this is a 1 byte constant,
1837 we can use ASM_OUTPUT_BYTE. */
1839 #ifdef ASM_OUTPUT_BYTE
1840 if (size == 1 && GET_CODE (x) == CONST_INT)
1842 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1843 return 1;
1845 #endif
1847 /* Finally, if SIZE is larger than a single word, try to output the constant
1848 one word at a time. */
1850 if (size > UNITS_PER_WORD)
1852 int i;
1853 enum machine_mode mode
1854 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1855 rtx word;
1857 for (i = 0; i < size / UNITS_PER_WORD; i++)
1859 word = operand_subword (x, i, 0, mode);
1861 if (word == 0)
1862 break;
1864 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1865 break;
1868 if (i == size / UNITS_PER_WORD)
1869 return 1;
1870 /* If we output at least one word and then could not finish,
1871 there is no valid way to continue. */
1872 if (i > 0)
1873 abort ();
1876 if (force)
1877 abort ();
1879 return 0;
1882 /* Assemble the floating-point constant D into an object of size MODE. */
1884 void
1885 assemble_real (d, mode)
1886 REAL_VALUE_TYPE d;
1887 enum machine_mode mode;
1889 jmp_buf output_constant_handler;
1891 if (setjmp (output_constant_handler))
1893 error ("floating point trap outputting a constant");
1894 #ifdef REAL_IS_NOT_DOUBLE
1895 bzero ((char *) &d, sizeof d);
1896 d = dconst0;
1897 #else
1898 d = 0;
1899 #endif
1902 set_float_handler (output_constant_handler);
1904 switch (mode)
1906 #ifdef ASM_OUTPUT_BYTE_FLOAT
1907 case QFmode:
1908 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1909 break;
1910 #endif
1911 #ifdef ASM_OUTPUT_SHORT_FLOAT
1912 case HFmode:
1913 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1914 break;
1915 #endif
1916 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1917 case TQFmode:
1918 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1919 break;
1920 #endif
1921 #ifdef ASM_OUTPUT_FLOAT
1922 case SFmode:
1923 ASM_OUTPUT_FLOAT (asm_out_file, d);
1924 break;
1925 #endif
1927 #ifdef ASM_OUTPUT_DOUBLE
1928 case DFmode:
1929 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1930 break;
1931 #endif
1933 #ifdef ASM_OUTPUT_LONG_DOUBLE
1934 case XFmode:
1935 case TFmode:
1936 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1937 break;
1938 #endif
1940 default:
1941 abort ();
1944 set_float_handler (NULL_PTR);
1947 /* Here we combine duplicate floating constants to make
1948 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1950 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1951 They are chained through the CONST_DOUBLE_CHAIN.
1952 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1953 In that case, CONST_DOUBLE_MEM is either a MEM,
1954 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1956 (CONST_DOUBLE_MEM is used only for top-level functions.
1957 See force_const_mem for explanation.) */
1959 static rtx const_double_chain;
1961 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1962 For an integer, I0 is the low-order word and I1 is the high-order word.
1963 For a real number, I0 is the word with the low address
1964 and I1 is the word with the high address. */
1967 immed_double_const (i0, i1, mode)
1968 HOST_WIDE_INT i0, i1;
1969 enum machine_mode mode;
1971 register rtx r;
1973 if (GET_MODE_CLASS (mode) == MODE_INT
1974 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1976 /* We clear out all bits that don't belong in MODE, unless they and our
1977 sign bit are all one. So we get either a reasonable negative value
1978 or a reasonable unsigned value for this mode. */
1979 int width = GET_MODE_BITSIZE (mode);
1980 if (width < HOST_BITS_PER_WIDE_INT
1981 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1982 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1983 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1984 else if (width == HOST_BITS_PER_WIDE_INT
1985 && ! (i1 == ~0 && i0 < 0))
1986 i1 = 0;
1987 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1988 /* We cannot represent this value as a constant. */
1989 abort ();
1991 /* If this would be an entire word for the target, but is not for
1992 the host, then sign-extend on the host so that the number will look
1993 the same way on the host that it would on the target.
1995 For example, when building a 64 bit alpha hosted 32 bit sparc
1996 targeted compiler, then we want the 32 bit unsigned value -1 to be
1997 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1998 The later confuses the sparc backend. */
2000 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2001 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2002 i0 |= ((HOST_WIDE_INT) (-1) << width);
2004 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2006 ??? Strictly speaking, this is wrong if we create a CONST_INT
2007 for a large unsigned constant with the size of MODE being
2008 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2009 wider mode. In that case we will mis-interpret it as a negative
2010 number.
2012 Unfortunately, the only alternative is to make a CONST_DOUBLE
2013 for any constant in any mode if it is an unsigned constant larger
2014 than the maximum signed integer in an int on the host. However,
2015 doing this will break everyone that always expects to see a CONST_INT
2016 for SImode and smaller.
2018 We have always been making CONST_INTs in this case, so nothing new
2019 is being broken. */
2021 if (width <= HOST_BITS_PER_WIDE_INT)
2022 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2024 /* If this integer fits in one word, return a CONST_INT. */
2025 if ((i1 == 0 && i0 >= 0)
2026 || (i1 == ~0 && i0 < 0))
2027 return GEN_INT (i0);
2029 /* We use VOIDmode for integers. */
2030 mode = VOIDmode;
2033 /* Search the chain for an existing CONST_DOUBLE with the right value.
2034 If one is found, return it. */
2036 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2037 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2038 && GET_MODE (r) == mode)
2039 return r;
2041 /* No; make a new one and add it to the chain.
2043 We may be called by an optimizer which may be discarding any memory
2044 allocated during its processing (such as combine and loop). However,
2045 we will be leaving this constant on the chain, so we cannot tolerate
2046 freed memory. So switch to saveable_obstack for this allocation
2047 and then switch back if we were in current_obstack. */
2049 push_obstacks_nochange ();
2050 rtl_in_saveable_obstack ();
2051 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2052 pop_obstacks ();
2054 /* Don't touch const_double_chain in nested function; see force_const_mem.
2055 Also, don't touch it if not inside any function. */
2056 if (outer_function_chain == 0 && current_function_decl != 0)
2058 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2059 const_double_chain = r;
2062 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2063 Actual use of mem-slot is only through force_const_mem. */
2065 CONST_DOUBLE_MEM (r) = const0_rtx;
2067 return r;
2070 /* Return a CONST_DOUBLE for a specified `double' value
2071 and machine mode. */
2074 immed_real_const_1 (d, mode)
2075 REAL_VALUE_TYPE d;
2076 enum machine_mode mode;
2078 union real_extract u;
2079 register rtx r;
2081 /* Get the desired `double' value as a sequence of ints
2082 since that is how they are stored in a CONST_DOUBLE. */
2084 u.d = d;
2086 /* Detect special cases. */
2088 if (REAL_VALUES_IDENTICAL (dconst0, d))
2089 return CONST0_RTX (mode);
2090 /* Check for NaN first, because some ports (specifically the i386) do not
2091 emit correct ieee-fp code by default, and thus will generate a core
2092 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2093 does a floating point comparison. */
2094 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2095 return CONST1_RTX (mode);
2097 if (sizeof u == sizeof (HOST_WIDE_INT))
2098 return immed_double_const (u.i[0], 0, mode);
2099 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2100 return immed_double_const (u.i[0], u.i[1], mode);
2102 /* The rest of this function handles the case where
2103 a float value requires more than 2 ints of space.
2104 It will be deleted as dead code on machines that don't need it. */
2106 /* Search the chain for an existing CONST_DOUBLE with the right value.
2107 If one is found, return it. */
2109 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2110 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2111 && GET_MODE (r) == mode)
2112 return r;
2114 /* No; make a new one and add it to the chain.
2116 We may be called by an optimizer which may be discarding any memory
2117 allocated during its processing (such as combine and loop). However,
2118 we will be leaving this constant on the chain, so we cannot tolerate
2119 freed memory. So switch to saveable_obstack for this allocation
2120 and then switch back if we were in current_obstack. */
2122 push_obstacks_nochange ();
2123 rtl_in_saveable_obstack ();
2124 r = rtx_alloc (CONST_DOUBLE);
2125 PUT_MODE (r, mode);
2126 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2127 pop_obstacks ();
2129 /* Don't touch const_double_chain in nested function; see force_const_mem.
2130 Also, don't touch it if not inside any function. */
2131 if (outer_function_chain == 0 && current_function_decl != 0)
2133 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2134 const_double_chain = r;
2137 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2138 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2139 is only through force_const_mem. */
2141 CONST_DOUBLE_MEM (r) = const0_rtx;
2143 return r;
2146 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2147 which must be a REAL_CST tree node. */
2150 immed_real_const (exp)
2151 tree exp;
2153 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2156 /* At the end of a function, forget the memory-constants
2157 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2158 Also clear out real_constant_chain and clear out all the chain-pointers. */
2160 void
2161 clear_const_double_mem ()
2163 register rtx r, next;
2165 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2166 See force_const_mem for explanation. */
2167 if (outer_function_chain != 0)
2168 return;
2170 for (r = const_double_chain; r; r = next)
2172 next = CONST_DOUBLE_CHAIN (r);
2173 CONST_DOUBLE_CHAIN (r) = 0;
2174 CONST_DOUBLE_MEM (r) = cc0_rtx;
2176 const_double_chain = 0;
2179 /* Given an expression EXP with a constant value,
2180 reduce it to the sum of an assembler symbol and an integer.
2181 Store them both in the structure *VALUE.
2182 Abort if EXP does not reduce. */
2184 struct addr_const
2186 rtx base;
2187 HOST_WIDE_INT offset;
2190 static void
2191 decode_addr_const (exp, value)
2192 tree exp;
2193 struct addr_const *value;
2195 register tree target = TREE_OPERAND (exp, 0);
2196 register int offset = 0;
2197 register rtx x;
2199 while (1)
2201 if (TREE_CODE (target) == COMPONENT_REF
2202 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2203 == INTEGER_CST))
2205 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2206 target = TREE_OPERAND (target, 0);
2208 else if (TREE_CODE (target) == ARRAY_REF)
2210 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2211 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2212 abort ();
2213 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2214 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2215 / BITS_PER_UNIT);
2216 target = TREE_OPERAND (target, 0);
2218 else
2219 break;
2222 switch (TREE_CODE (target))
2224 case VAR_DECL:
2225 case FUNCTION_DECL:
2226 x = DECL_RTL (target);
2227 break;
2229 case LABEL_DECL:
2230 x = gen_rtx_MEM (FUNCTION_MODE,
2231 gen_rtx_LABEL_REF (VOIDmode,
2232 label_rtx (TREE_OPERAND (exp, 0))));
2233 break;
2235 case REAL_CST:
2236 case STRING_CST:
2237 case COMPLEX_CST:
2238 case CONSTRUCTOR:
2239 case INTEGER_CST:
2240 x = TREE_CST_RTL (target);
2241 break;
2243 default:
2244 abort ();
2247 if (GET_CODE (x) != MEM)
2248 abort ();
2249 x = XEXP (x, 0);
2251 value->base = x;
2252 value->offset = offset;
2255 /* Uniquize all constants that appear in memory.
2256 Each constant in memory thus far output is recorded
2257 in `const_hash_table' with a `struct constant_descriptor'
2258 that contains a polish representation of the value of
2259 the constant.
2261 We cannot store the trees in the hash table
2262 because the trees may be temporary. */
2264 struct constant_descriptor
2266 struct constant_descriptor *next;
2267 char *label;
2268 char contents[1];
2271 #define HASHBITS 30
2272 #define MAX_HASH_TABLE 1009
2273 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2275 /* Compute a hash code for a constant expression. */
2277 static int
2278 const_hash (exp)
2279 tree exp;
2281 register char *p;
2282 register int len, hi, i;
2283 register enum tree_code code = TREE_CODE (exp);
2285 /* Either set P and LEN to the address and len of something to hash and
2286 exit the switch or return a value. */
2288 switch (code)
2290 case INTEGER_CST:
2291 p = (char *) &TREE_INT_CST_LOW (exp);
2292 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2293 break;
2295 case REAL_CST:
2296 p = (char *) &TREE_REAL_CST (exp);
2297 len = sizeof TREE_REAL_CST (exp);
2298 break;
2300 case STRING_CST:
2301 p = TREE_STRING_POINTER (exp);
2302 len = TREE_STRING_LENGTH (exp);
2303 break;
2305 case COMPLEX_CST:
2306 return (const_hash (TREE_REALPART (exp)) * 5
2307 + const_hash (TREE_IMAGPART (exp)));
2309 case CONSTRUCTOR:
2310 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2312 len = int_size_in_bytes (TREE_TYPE (exp));
2313 p = (char *) alloca (len);
2314 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2315 break;
2317 else
2319 register tree link;
2321 /* For record type, include the type in the hashing.
2322 We do not do so for array types
2323 because (1) the sizes of the elements are sufficient
2324 and (2) distinct array types can have the same constructor.
2325 Instead, we include the array size because the constructor could
2326 be shorter. */
2327 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2328 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2329 % MAX_HASH_TABLE;
2330 else
2331 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2332 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2334 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2335 if (TREE_VALUE (link))
2337 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2339 return hi;
2342 case ADDR_EXPR:
2344 struct addr_const value;
2346 decode_addr_const (exp, &value);
2347 if (GET_CODE (value.base) == SYMBOL_REF)
2349 /* Don't hash the address of the SYMBOL_REF;
2350 only use the offset and the symbol name. */
2351 hi = value.offset;
2352 p = XSTR (value.base, 0);
2353 for (i = 0; p[i] != 0; i++)
2354 hi = ((hi * 613) + (unsigned) (p[i]));
2356 else if (GET_CODE (value.base) == LABEL_REF)
2357 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2358 else
2359 abort();
2361 hi &= (1 << HASHBITS) - 1;
2362 hi %= MAX_HASH_TABLE;
2364 return hi;
2366 case PLUS_EXPR:
2367 case MINUS_EXPR:
2368 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2369 + const_hash (TREE_OPERAND (exp, 1)));
2371 case NOP_EXPR:
2372 case CONVERT_EXPR:
2373 case NON_LVALUE_EXPR:
2374 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2376 default:
2377 abort ();
2380 /* Compute hashing function */
2381 hi = len;
2382 for (i = 0; i < len; i++)
2383 hi = ((hi * 613) + (unsigned) (p[i]));
2385 hi &= (1 << HASHBITS) - 1;
2386 hi %= MAX_HASH_TABLE;
2387 return hi;
2390 /* Compare a constant expression EXP with a constant-descriptor DESC.
2391 Return 1 if DESC describes a constant with the same value as EXP. */
2393 static int
2394 compare_constant (exp, desc)
2395 tree exp;
2396 struct constant_descriptor *desc;
2398 return 0 != compare_constant_1 (exp, desc->contents);
2401 /* Compare constant expression EXP with a substring P of a constant descriptor.
2402 If they match, return a pointer to the end of the substring matched.
2403 If they do not match, return 0.
2405 Since descriptors are written in polish prefix notation,
2406 this function can be used recursively to test one operand of EXP
2407 against a subdescriptor, and if it succeeds it returns the
2408 address of the subdescriptor for the next operand. */
2410 static char *
2411 compare_constant_1 (exp, p)
2412 tree exp;
2413 char *p;
2415 register char *strp;
2416 register int len;
2417 register enum tree_code code = TREE_CODE (exp);
2419 if (code != (enum tree_code) *p++)
2420 return 0;
2422 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2423 switch, or return the result of the comparison. */
2425 switch (code)
2427 case INTEGER_CST:
2428 /* Integer constants are the same only if the same width of type. */
2429 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2430 return 0;
2432 strp = (char *) &TREE_INT_CST_LOW (exp);
2433 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2434 break;
2436 case REAL_CST:
2437 /* Real constants are the same only if the same width of type. */
2438 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2439 return 0;
2441 strp = (char *) &TREE_REAL_CST (exp);
2442 len = sizeof TREE_REAL_CST (exp);
2443 break;
2445 case STRING_CST:
2446 if (flag_writable_strings)
2447 return 0;
2449 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2450 return 0;
2452 strp = TREE_STRING_POINTER (exp);
2453 len = TREE_STRING_LENGTH (exp);
2454 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2455 sizeof TREE_STRING_LENGTH (exp)))
2456 return 0;
2458 p += sizeof TREE_STRING_LENGTH (exp);
2459 break;
2461 case COMPLEX_CST:
2462 p = compare_constant_1 (TREE_REALPART (exp), p);
2463 if (p == 0)
2464 return 0;
2466 return compare_constant_1 (TREE_IMAGPART (exp), p);
2468 case CONSTRUCTOR:
2469 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2471 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2473 strp = (char *) alloca (len);
2474 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2475 if (bcmp ((char *) &xlen, p, sizeof xlen))
2476 return 0;
2478 p += sizeof xlen;
2479 break;
2481 else
2483 register tree link;
2484 int length = list_length (CONSTRUCTOR_ELTS (exp));
2485 tree type;
2486 int have_purpose = 0;
2488 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2489 if (TREE_PURPOSE (link))
2490 have_purpose = 1;
2492 if (bcmp ((char *) &length, p, sizeof length))
2493 return 0;
2495 p += sizeof length;
2497 /* For record constructors, insist that the types match.
2498 For arrays, just verify both constructors are for arrays.
2499 Then insist that either both or none have any TREE_PURPOSE
2500 values. */
2501 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2502 type = TREE_TYPE (exp);
2503 else
2504 type = 0;
2506 if (bcmp ((char *) &type, p, sizeof type))
2507 return 0;
2509 p += sizeof type;
2511 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2512 return 0;
2514 p += sizeof have_purpose;
2516 /* For arrays, insist that the size in bytes match. */
2517 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2519 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2521 if (bcmp ((char *) &size, p, sizeof size))
2522 return 0;
2524 p += sizeof size;
2527 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2529 if (TREE_VALUE (link))
2531 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2532 return 0;
2534 else
2536 tree zero = 0;
2538 if (bcmp ((char *) &zero, p, sizeof zero))
2539 return 0;
2541 p += sizeof zero;
2544 if (TREE_PURPOSE (link)
2545 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2547 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2548 sizeof TREE_PURPOSE (link)))
2549 return 0;
2551 p += sizeof TREE_PURPOSE (link);
2553 else if (TREE_PURPOSE (link))
2555 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2556 return 0;
2558 else if (have_purpose)
2560 int zero = 0;
2562 if (bcmp ((char *) &zero, p, sizeof zero))
2563 return 0;
2565 p += sizeof zero;
2569 return p;
2572 case ADDR_EXPR:
2574 struct addr_const value;
2576 decode_addr_const (exp, &value);
2577 strp = (char *) &value.offset;
2578 len = sizeof value.offset;
2579 /* Compare the offset. */
2580 while (--len >= 0)
2581 if (*p++ != *strp++)
2582 return 0;
2584 /* Compare symbol name. */
2585 strp = XSTR (value.base, 0);
2586 len = strlen (strp) + 1;
2588 break;
2590 case PLUS_EXPR:
2591 case MINUS_EXPR:
2592 case RANGE_EXPR:
2593 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2594 if (p == 0)
2595 return 0;
2597 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2599 case NOP_EXPR:
2600 case CONVERT_EXPR:
2601 case NON_LVALUE_EXPR:
2602 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2604 default:
2605 abort ();
2608 /* Compare constant contents. */
2609 while (--len >= 0)
2610 if (*p++ != *strp++)
2611 return 0;
2613 return p;
2616 /* Construct a constant descriptor for the expression EXP.
2617 It is up to the caller to enter the descriptor in the hash table. */
2619 static struct constant_descriptor *
2620 record_constant (exp)
2621 tree exp;
2623 struct constant_descriptor *next = 0;
2624 char *label = 0;
2626 /* Make a struct constant_descriptor. The first two pointers will
2627 be filled in later. Here we just leave space for them. */
2629 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2630 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2631 record_constant_1 (exp);
2632 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2635 /* Add a description of constant expression EXP
2636 to the object growing in `permanent_obstack'.
2637 No need to return its address; the caller will get that
2638 from the obstack when the object is complete. */
2640 static void
2641 record_constant_1 (exp)
2642 tree exp;
2644 register char *strp;
2645 register int len;
2646 register enum tree_code code = TREE_CODE (exp);
2648 obstack_1grow (&permanent_obstack, (unsigned int) code);
2650 switch (code)
2652 case INTEGER_CST:
2653 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2654 strp = (char *) &TREE_INT_CST_LOW (exp);
2655 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2656 break;
2658 case REAL_CST:
2659 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2660 strp = (char *) &TREE_REAL_CST (exp);
2661 len = sizeof TREE_REAL_CST (exp);
2662 break;
2664 case STRING_CST:
2665 if (flag_writable_strings)
2666 return;
2668 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2669 strp = TREE_STRING_POINTER (exp);
2670 len = TREE_STRING_LENGTH (exp);
2671 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2672 sizeof TREE_STRING_LENGTH (exp));
2673 break;
2675 case COMPLEX_CST:
2676 record_constant_1 (TREE_REALPART (exp));
2677 record_constant_1 (TREE_IMAGPART (exp));
2678 return;
2680 case CONSTRUCTOR:
2681 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2683 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2684 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2685 obstack_blank (&permanent_obstack, nbytes);
2686 get_set_constructor_bytes
2687 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2688 nbytes);
2689 return;
2691 else
2693 register tree link;
2694 int length = list_length (CONSTRUCTOR_ELTS (exp));
2695 tree type;
2696 int have_purpose = 0;
2698 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2699 if (TREE_PURPOSE (link))
2700 have_purpose = 1;
2702 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2704 /* For record constructors, insist that the types match.
2705 For arrays, just verify both constructors are for arrays.
2706 Then insist that either both or none have any TREE_PURPOSE
2707 values. */
2708 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2709 type = TREE_TYPE (exp);
2710 else
2711 type = 0;
2712 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2713 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2714 sizeof have_purpose);
2716 /* For arrays, insist that the size in bytes match. */
2717 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2719 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2720 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2723 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2725 if (TREE_VALUE (link))
2726 record_constant_1 (TREE_VALUE (link));
2727 else
2729 tree zero = 0;
2731 obstack_grow (&permanent_obstack,
2732 (char *) &zero, sizeof zero);
2735 if (TREE_PURPOSE (link)
2736 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2737 obstack_grow (&permanent_obstack,
2738 (char *) &TREE_PURPOSE (link),
2739 sizeof TREE_PURPOSE (link));
2740 else if (TREE_PURPOSE (link))
2741 record_constant_1 (TREE_PURPOSE (link));
2742 else if (have_purpose)
2744 int zero = 0;
2746 obstack_grow (&permanent_obstack,
2747 (char *) &zero, sizeof zero);
2751 return;
2753 case ADDR_EXPR:
2755 struct addr_const value;
2757 decode_addr_const (exp, &value);
2758 /* Record the offset. */
2759 obstack_grow (&permanent_obstack,
2760 (char *) &value.offset, sizeof value.offset);
2761 /* Record the symbol name. */
2762 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2763 strlen (XSTR (value.base, 0)) + 1);
2765 return;
2767 case PLUS_EXPR:
2768 case MINUS_EXPR:
2769 case RANGE_EXPR:
2770 record_constant_1 (TREE_OPERAND (exp, 0));
2771 record_constant_1 (TREE_OPERAND (exp, 1));
2772 return;
2774 case NOP_EXPR:
2775 case CONVERT_EXPR:
2776 case NON_LVALUE_EXPR:
2777 record_constant_1 (TREE_OPERAND (exp, 0));
2778 return;
2780 default:
2781 abort ();
2784 /* Record constant contents. */
2785 obstack_grow (&permanent_obstack, strp, len);
2788 /* Record a list of constant expressions that were passed to
2789 output_constant_def but that could not be output right away. */
2791 struct deferred_constant
2793 struct deferred_constant *next;
2794 tree exp;
2795 int reloc;
2796 int labelno;
2799 static struct deferred_constant *deferred_constants;
2801 /* Another list of constants which should be output after the
2802 function. */
2803 static struct deferred_constant *after_function_constants;
2805 /* Nonzero means defer output of addressed subconstants
2806 (i.e., those for which output_constant_def is called.) */
2807 static int defer_addressed_constants_flag;
2809 /* Start deferring output of subconstants. */
2811 void
2812 defer_addressed_constants ()
2814 defer_addressed_constants_flag++;
2817 /* Stop deferring output of subconstants,
2818 and output now all those that have been deferred. */
2820 void
2821 output_deferred_addressed_constants ()
2823 struct deferred_constant *p, *next;
2825 defer_addressed_constants_flag--;
2827 if (defer_addressed_constants_flag > 0)
2828 return;
2830 for (p = deferred_constants; p; p = next)
2832 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2833 next = p->next;
2834 free (p);
2837 deferred_constants = 0;
2840 /* Output any constants which should appear after a function. */
2842 static void
2843 output_after_function_constants ()
2845 struct deferred_constant *p, *next;
2847 for (p = after_function_constants; p; p = next)
2849 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2850 next = p->next;
2851 free (p);
2854 after_function_constants = 0;
2857 /* Make a copy of the whole tree structure for a constant.
2858 This handles the same types of nodes that compare_constant
2859 and record_constant handle. */
2861 static tree
2862 copy_constant (exp)
2863 tree exp;
2865 switch (TREE_CODE (exp))
2867 case ADDR_EXPR:
2868 /* For ADDR_EXPR, we do not want to copy the decl whose address
2869 is requested. We do want to copy constants though. */
2870 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2871 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2872 copy_constant (TREE_OPERAND (exp, 0)));
2873 else
2874 return copy_node (exp);
2876 case INTEGER_CST:
2877 case REAL_CST:
2878 case STRING_CST:
2879 return copy_node (exp);
2881 case COMPLEX_CST:
2882 return build_complex (TREE_TYPE (exp),
2883 copy_constant (TREE_REALPART (exp)),
2884 copy_constant (TREE_IMAGPART (exp)));
2886 case PLUS_EXPR:
2887 case MINUS_EXPR:
2888 return build (TREE_CODE (exp), TREE_TYPE (exp),
2889 copy_constant (TREE_OPERAND (exp, 0)),
2890 copy_constant (TREE_OPERAND (exp, 1)));
2892 case NOP_EXPR:
2893 case CONVERT_EXPR:
2894 case NON_LVALUE_EXPR:
2895 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2896 copy_constant (TREE_OPERAND (exp, 0)));
2898 case CONSTRUCTOR:
2900 tree copy = copy_node (exp);
2901 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2902 tree tail;
2904 CONSTRUCTOR_ELTS (copy) = list;
2905 for (tail = list; tail; tail = TREE_CHAIN (tail))
2906 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2907 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2908 for (tail = list; tail; tail = TREE_CHAIN (tail))
2909 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2911 return copy;
2914 default:
2915 abort ();
2919 /* Return an rtx representing a reference to constant data in memory
2920 for the constant expression EXP.
2922 If assembler code for such a constant has already been output,
2923 return an rtx to refer to it.
2924 Otherwise, output such a constant in memory (or defer it for later)
2925 and generate an rtx for it.
2927 The TREE_CST_RTL of EXP is set up to point to that rtx.
2928 The const_hash_table records which constants already have label strings. */
2931 output_constant_def (exp)
2932 tree exp;
2934 register int hash;
2935 register struct constant_descriptor *desc;
2936 char label[256];
2937 char *found = 0;
2938 int reloc;
2939 register rtx def;
2941 if (TREE_CST_RTL (exp))
2942 return TREE_CST_RTL (exp);
2944 /* Make sure any other constants whose addresses appear in EXP
2945 are assigned label numbers. */
2947 reloc = output_addressed_constants (exp);
2949 /* Compute hash code of EXP. Search the descriptors for that hash code
2950 to see if any of them describes EXP. If yes, the descriptor records
2951 the label number already assigned. */
2953 hash = const_hash (exp) % MAX_HASH_TABLE;
2955 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2956 if (compare_constant (exp, desc))
2958 found = desc->label;
2959 break;
2962 if (found == 0)
2964 /* No constant equal to EXP is known to have been output.
2965 Make a constant descriptor to enter EXP in the hash table.
2966 Assign the label number and record it in the descriptor for
2967 future calls to this function to find. */
2969 /* Create a string containing the label name, in LABEL. */
2970 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2972 desc = record_constant (exp);
2973 desc->next = const_hash_table[hash];
2974 desc->label
2975 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2976 const_hash_table[hash] = desc;
2978 else
2980 /* Create a string containing the label name, in LABEL. */
2981 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2984 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2986 push_obstacks_nochange ();
2987 if (TREE_PERMANENT (exp))
2988 end_temporary_allocation ();
2990 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
2992 TREE_CST_RTL (exp)
2993 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
2994 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2995 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2996 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
2998 pop_obstacks ();
3000 /* Optionally set flags or add text to the name to record information
3001 such as that it is a function name. If the name is changed, the macro
3002 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3003 #ifdef ENCODE_SECTION_INFO
3004 ENCODE_SECTION_INFO (exp);
3005 #endif
3007 /* If this is the first time we've seen this particular constant,
3008 output it (or defer its output for later). */
3009 if (found == 0)
3011 int after_function = 0;
3013 #ifdef CONSTANT_AFTER_FUNCTION_P
3014 if (current_function_decl != 0
3015 && CONSTANT_AFTER_FUNCTION_P (exp))
3016 after_function = 1;
3017 #endif
3019 if (defer_addressed_constants_flag || after_function)
3021 struct deferred_constant *p;
3022 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3024 push_obstacks_nochange ();
3025 suspend_momentary ();
3026 p->exp = copy_constant (exp);
3027 pop_obstacks ();
3028 p->reloc = reloc;
3029 p->labelno = const_labelno++;
3030 if (after_function)
3032 p->next = after_function_constants;
3033 after_function_constants = p;
3035 else
3037 p->next = deferred_constants;
3038 deferred_constants = p;
3041 else
3043 /* Do no output if -fsyntax-only. */
3044 if (! flag_syntax_only)
3045 output_constant_def_contents (exp, reloc, const_labelno);
3046 ++const_labelno;
3050 return TREE_CST_RTL (exp);
3053 /* Now output assembler code to define the label for EXP,
3054 and follow it with the data of EXP. */
3056 static void
3057 output_constant_def_contents (exp, reloc, labelno)
3058 tree exp;
3059 int reloc;
3060 int labelno;
3062 int align;
3064 if (IN_NAMED_SECTION (exp))
3065 named_section (exp, NULL, reloc);
3066 else
3068 /* First switch to text section, except for writable strings. */
3069 #ifdef SELECT_SECTION
3070 SELECT_SECTION (exp, reloc);
3071 #else
3072 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3073 || (flag_pic && reloc))
3074 data_section ();
3075 else
3076 readonly_data_section ();
3077 #endif
3080 /* Align the location counter as required by EXP's data type. */
3081 align = TYPE_ALIGN (TREE_TYPE (exp));
3082 #ifdef CONSTANT_ALIGNMENT
3083 align = CONSTANT_ALIGNMENT (exp, align);
3084 #endif
3086 if (align > BITS_PER_UNIT)
3087 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3089 /* Output the label itself. */
3090 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3092 /* Output the value of EXP. */
3093 output_constant (exp,
3094 (TREE_CODE (exp) == STRING_CST
3095 ? TREE_STRING_LENGTH (exp)
3096 : int_size_in_bytes (TREE_TYPE (exp))));
3100 /* Similar hash facility for making memory-constants
3101 from constant rtl-expressions. It is used on RISC machines
3102 where immediate integer arguments and constant addresses are restricted
3103 so that such constants must be stored in memory.
3105 This pool of constants is reinitialized for each function
3106 so each function gets its own constants-pool that comes right before it.
3108 All structures allocated here are discarded when functions are saved for
3109 inlining, so they do not need to be allocated permanently. */
3111 #define MAX_RTX_HASH_TABLE 61
3112 static struct constant_descriptor **const_rtx_hash_table;
3114 /* Structure to represent sufficient information about a constant so that
3115 it can be output when the constant pool is output, so that function
3116 integration can be done, and to simplify handling on machines that reference
3117 constant pool as base+displacement. */
3119 struct pool_constant
3121 struct constant_descriptor *desc;
3122 struct pool_constant *next;
3123 enum machine_mode mode;
3124 rtx constant;
3125 int labelno;
3126 int align;
3127 int offset;
3128 int mark;
3131 /* Pointers to first and last constant in pool. */
3133 static struct pool_constant *first_pool, *last_pool;
3135 /* Current offset in constant pool (does not include any machine-specific
3136 header. */
3138 static int pool_offset;
3140 /* Structure used to maintain hash table mapping symbols used to their
3141 corresponding constants. */
3143 struct pool_sym
3145 char *label;
3146 struct pool_constant *pool;
3147 struct pool_sym *next;
3150 static struct pool_sym **const_rtx_sym_hash_table;
3152 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3153 The argument is XSTR (... , 0) */
3155 #define SYMHASH(LABEL) \
3156 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3158 /* Initialize constant pool hashing for next function. */
3160 void
3161 init_const_rtx_hash_table ()
3163 const_rtx_hash_table
3164 = ((struct constant_descriptor **)
3165 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3166 const_rtx_sym_hash_table
3167 = ((struct pool_sym **)
3168 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3169 bzero ((char *) const_rtx_hash_table,
3170 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3171 bzero ((char *) const_rtx_sym_hash_table,
3172 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3174 first_pool = last_pool = 0;
3175 pool_offset = 0;
3178 /* Save and restore status for a nested function. */
3180 void
3181 save_varasm_status (p, context)
3182 struct function *p;
3183 tree context;
3185 p->const_rtx_hash_table = const_rtx_hash_table;
3186 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3187 p->first_pool = first_pool;
3188 p->last_pool = last_pool;
3189 p->pool_offset = pool_offset;
3190 p->const_double_chain = const_double_chain;
3192 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3193 if (context == NULL_TREE)
3194 const_double_chain = 0;
3197 void
3198 restore_varasm_status (p)
3199 struct function *p;
3201 const_rtx_hash_table = p->const_rtx_hash_table;
3202 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3203 first_pool = p->first_pool;
3204 last_pool = p->last_pool;
3205 pool_offset = p->pool_offset;
3206 const_double_chain = p->const_double_chain;
3209 enum kind { RTX_DOUBLE, RTX_INT };
3211 struct rtx_const
3213 #ifdef ONLY_INT_FIELDS
3214 unsigned int kind : 16;
3215 unsigned int mode : 16;
3216 #else
3217 enum kind kind : 16;
3218 enum machine_mode mode : 16;
3219 #endif
3220 union {
3221 union real_extract du;
3222 struct addr_const addr;
3223 struct {HOST_WIDE_INT high, low;} di;
3224 } un;
3227 /* Express an rtx for a constant integer (perhaps symbolic)
3228 as the sum of a symbol or label plus an explicit integer.
3229 They are stored into VALUE. */
3231 static void
3232 decode_rtx_const (mode, x, value)
3233 enum machine_mode mode;
3234 rtx x;
3235 struct rtx_const *value;
3237 /* Clear the whole structure, including any gaps. */
3240 int *p = (int *) value;
3241 int *end = (int *) (value + 1);
3242 while (p < end)
3243 *p++ = 0;
3246 value->kind = RTX_INT; /* Most usual kind. */
3247 value->mode = mode;
3249 switch (GET_CODE (x))
3251 case CONST_DOUBLE:
3252 value->kind = RTX_DOUBLE;
3253 if (GET_MODE (x) != VOIDmode)
3255 value->mode = GET_MODE (x);
3256 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3257 (char *) &value->un.du, sizeof value->un.du);
3259 else
3261 value->un.di.low = CONST_DOUBLE_LOW (x);
3262 value->un.di.high = CONST_DOUBLE_HIGH (x);
3264 break;
3266 case CONST_INT:
3267 value->un.addr.offset = INTVAL (x);
3268 break;
3270 case SYMBOL_REF:
3271 case LABEL_REF:
3272 case PC:
3273 value->un.addr.base = x;
3274 break;
3276 case CONST:
3277 x = XEXP (x, 0);
3278 if (GET_CODE (x) == PLUS)
3280 value->un.addr.base = XEXP (x, 0);
3281 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3282 abort ();
3283 value->un.addr.offset = INTVAL (XEXP (x, 1));
3285 else if (GET_CODE (x) == MINUS)
3287 value->un.addr.base = XEXP (x, 0);
3288 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3289 abort ();
3290 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3292 else
3293 abort ();
3294 break;
3296 default:
3297 abort ();
3300 if (value->kind == RTX_INT && value->un.addr.base != 0)
3301 switch (GET_CODE (value->un.addr.base))
3303 case SYMBOL_REF:
3304 case LABEL_REF:
3305 /* Use the string's address, not the SYMBOL_REF's address,
3306 for the sake of addresses of library routines.
3307 For a LABEL_REF, compare labels. */
3308 value->un.addr.base = XEXP (value->un.addr.base, 0);
3310 default:
3311 break;
3315 /* Given a MINUS expression, simplify it if both sides
3316 include the same symbol. */
3319 simplify_subtraction (x)
3320 rtx x;
3322 struct rtx_const val0, val1;
3324 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3325 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3327 if (val0.un.addr.base == val1.un.addr.base)
3328 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3329 return x;
3332 /* Compute a hash code for a constant RTL expression. */
3334 static int
3335 const_hash_rtx (mode, x)
3336 enum machine_mode mode;
3337 rtx x;
3339 register int hi;
3340 register size_t i;
3342 struct rtx_const value;
3343 decode_rtx_const (mode, x, &value);
3345 /* Compute hashing function */
3346 hi = 0;
3347 for (i = 0; i < sizeof value / sizeof (int); i++)
3348 hi += ((int *) &value)[i];
3350 hi &= (1 << HASHBITS) - 1;
3351 hi %= MAX_RTX_HASH_TABLE;
3352 return hi;
3355 /* Compare a constant rtl object X with a constant-descriptor DESC.
3356 Return 1 if DESC describes a constant with the same value as X. */
3358 static int
3359 compare_constant_rtx (mode, x, desc)
3360 enum machine_mode mode;
3361 rtx x;
3362 struct constant_descriptor *desc;
3364 register int *p = (int *) desc->contents;
3365 register int *strp;
3366 register int len;
3367 struct rtx_const value;
3369 decode_rtx_const (mode, x, &value);
3370 strp = (int *) &value;
3371 len = sizeof value / sizeof (int);
3373 /* Compare constant contents. */
3374 while (--len >= 0)
3375 if (*p++ != *strp++)
3376 return 0;
3378 return 1;
3381 /* Construct a constant descriptor for the rtl-expression X.
3382 It is up to the caller to enter the descriptor in the hash table. */
3384 static struct constant_descriptor *
3385 record_constant_rtx (mode, x)
3386 enum machine_mode mode;
3387 rtx x;
3389 struct constant_descriptor *ptr;
3390 char *label;
3391 struct rtx_const value;
3393 decode_rtx_const (mode, x, &value);
3395 /* Put these things in the saveable obstack so we can ensure it won't
3396 be freed if we are called from combine or some other phase that discards
3397 memory allocated from function_obstack (current_obstack). */
3398 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3399 obstack_grow (saveable_obstack, &label, sizeof label);
3401 /* Record constant contents. */
3402 obstack_grow (saveable_obstack, &value, sizeof value);
3404 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3407 /* Given a constant rtx X, make (or find) a memory constant for its value
3408 and return a MEM rtx to refer to it in memory. */
3411 force_const_mem (mode, x)
3412 enum machine_mode mode;
3413 rtx x;
3415 register int hash;
3416 register struct constant_descriptor *desc;
3417 char label[256];
3418 char *found = 0;
3419 rtx def;
3421 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3422 (this will always be true for floating CONST_DOUBLEs that have been
3423 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3424 use the previous copy. Otherwise, make a new one. Note that in
3425 the unlikely event that this same CONST_DOUBLE is used in two different
3426 modes in an alternating fashion, we will allocate a lot of different
3427 memory locations, but this should be extremely rare. */
3429 /* Don't use CONST_DOUBLE_MEM in a nested function.
3430 Nested functions have their own constant pools,
3431 so they can't share the same values in CONST_DOUBLE_MEM
3432 with the containing function. */
3433 if (outer_function_chain == 0)
3434 if (GET_CODE (x) == CONST_DOUBLE
3435 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3436 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3437 return CONST_DOUBLE_MEM (x);
3439 /* Compute hash code of X. Search the descriptors for that hash code
3440 to see if any of them describes X. If yes, the descriptor records
3441 the label number already assigned. */
3443 hash = const_hash_rtx (mode, x);
3445 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3446 if (compare_constant_rtx (mode, x, desc))
3448 found = desc->label;
3449 break;
3452 if (found == 0)
3454 register struct pool_constant *pool;
3455 register struct pool_sym *sym;
3456 int align;
3458 /* No constant equal to X is known to have been output.
3459 Make a constant descriptor to enter X in the hash table.
3460 Assign the label number and record it in the descriptor for
3461 future calls to this function to find. */
3463 desc = record_constant_rtx (mode, x);
3464 desc->next = const_rtx_hash_table[hash];
3465 const_rtx_hash_table[hash] = desc;
3467 /* Align the location counter as required by EXP's data type. */
3468 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3469 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3470 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3471 #ifdef CONSTANT_ALIGNMENT
3472 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3473 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3474 #endif
3476 pool_offset += align - 1;
3477 pool_offset &= ~ (align - 1);
3479 /* If RTL is not being placed into the saveable obstack, make a
3480 copy of X that is in the saveable obstack in case we are
3481 being called from combine or some other phase that discards
3482 memory it allocates. We used to only do this if it is a
3483 CONST; however, reload can allocate a CONST_INT when
3484 eliminating registers. */
3485 if (rtl_obstack != saveable_obstack
3486 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3488 push_obstacks_nochange ();
3489 rtl_in_saveable_obstack ();
3491 if (GET_CODE (x) == CONST)
3492 x = gen_rtx_CONST (GET_MODE (x),
3493 gen_rtx_PLUS (GET_MODE (x),
3494 XEXP (XEXP (x, 0), 0),
3495 XEXP (XEXP (x, 0), 1)));
3496 else
3497 x = GEN_INT (INTVAL (x));
3499 pop_obstacks ();
3502 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3504 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3505 pool->desc = desc;
3506 pool->constant = x;
3507 pool->mode = mode;
3508 pool->labelno = const_labelno;
3509 pool->align = align;
3510 pool->offset = pool_offset;
3511 pool->mark = 1;
3512 pool->next = 0;
3514 if (last_pool == 0)
3515 first_pool = pool;
3516 else
3517 last_pool->next = pool;
3519 last_pool = pool;
3520 pool_offset += GET_MODE_SIZE (mode);
3522 /* Create a string containing the label name, in LABEL. */
3523 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3525 ++const_labelno;
3527 desc->label = found
3528 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3530 /* Add label to symbol hash table. */
3531 hash = SYMHASH (found);
3532 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3533 sym->label = found;
3534 sym->pool = pool;
3535 sym->next = const_rtx_sym_hash_table[hash];
3536 const_rtx_sym_hash_table[hash] = sym;
3539 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3541 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3543 RTX_UNCHANGING_P (def) = 1;
3544 /* Mark the symbol_ref as belonging to this constants pool. */
3545 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3546 current_function_uses_const_pool = 1;
3548 if (outer_function_chain == 0)
3549 if (GET_CODE (x) == CONST_DOUBLE)
3551 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3553 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3554 const_double_chain = x;
3556 CONST_DOUBLE_MEM (x) = def;
3559 return def;
3562 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3563 the corresponding pool_constant structure. */
3565 static struct pool_constant *
3566 find_pool_constant (addr)
3567 rtx addr;
3569 struct pool_sym *sym;
3570 char *label = XSTR (addr, 0);
3572 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3573 if (sym->label == label)
3574 return sym->pool;
3576 abort ();
3579 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3582 get_pool_constant (addr)
3583 rtx addr;
3585 return (find_pool_constant (addr))->constant;
3588 /* Similar, return the mode. */
3590 enum machine_mode
3591 get_pool_mode (addr)
3592 rtx addr;
3594 return (find_pool_constant (addr))->mode;
3597 /* Similar, return the offset in the constant pool. */
3600 get_pool_offset (addr)
3601 rtx addr;
3603 return (find_pool_constant (addr))->offset;
3606 /* Return the size of the constant pool. */
3609 get_pool_size ()
3611 return pool_offset;
3614 /* Write all the constants in the constant pool. */
3616 void
3617 output_constant_pool (fnname, fndecl)
3618 char *fnname ATTRIBUTE_UNUSED;
3619 tree fndecl ATTRIBUTE_UNUSED;
3621 struct pool_constant *pool;
3622 rtx x;
3623 union real_extract u;
3625 /* It is possible for gcc to call force_const_mem and then to later
3626 discard the instructions which refer to the constant. In such a
3627 case we do not need to output the constant. */
3628 mark_constant_pool ();
3630 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3631 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3632 #endif
3634 for (pool = first_pool; pool; pool = pool->next)
3636 x = pool->constant;
3638 if (! pool->mark)
3639 continue;
3641 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3642 whose CODE_LABEL has been deleted. This can occur if a jump table
3643 is eliminated by optimization. If so, write a constant of zero
3644 instead. Note that this can also happen by turning the
3645 CODE_LABEL into a NOTE. */
3646 if (((GET_CODE (x) == LABEL_REF
3647 && (INSN_DELETED_P (XEXP (x, 0))
3648 || GET_CODE (XEXP (x, 0)) == NOTE)))
3649 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3650 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3651 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3652 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3653 x = const0_rtx;
3655 /* First switch to correct section. */
3656 #ifdef SELECT_RTX_SECTION
3657 SELECT_RTX_SECTION (pool->mode, x);
3658 #else
3659 readonly_data_section ();
3660 #endif
3662 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3663 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3664 pool->align, pool->labelno, done);
3665 #endif
3667 if (pool->align > 1)
3668 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3670 /* Output the label. */
3671 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3673 /* Output the value of the constant itself. */
3674 switch (GET_MODE_CLASS (pool->mode))
3676 case MODE_FLOAT:
3677 if (GET_CODE (x) != CONST_DOUBLE)
3678 abort ();
3680 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3681 assemble_real (u.d, pool->mode);
3682 break;
3684 case MODE_INT:
3685 case MODE_PARTIAL_INT:
3686 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3687 break;
3689 default:
3690 abort ();
3693 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3694 done: ;
3695 #endif
3699 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3700 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3701 #endif
3703 /* Done with this pool. */
3704 first_pool = last_pool = 0;
3707 /* Look through the instructions for this function, and mark all the
3708 entries in the constant pool which are actually being used. */
3710 static void
3711 mark_constant_pool ()
3713 register rtx insn;
3714 struct pool_constant *pool;
3716 if (first_pool == 0)
3717 return;
3719 for (pool = first_pool; pool; pool = pool->next)
3720 pool->mark = 0;
3722 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3723 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3724 mark_constants (PATTERN (insn));
3726 for (insn = current_function_epilogue_delay_list;
3727 insn;
3728 insn = XEXP (insn, 1))
3729 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3730 mark_constants (PATTERN (insn));
3732 /* It's possible that the only reference to a symbol is in a symbol
3733 that's in the constant pool. This happens in Fortran under some
3734 situations. (When the constant contains the address of another
3735 constant, and only the first is used directly in an insn.)
3736 This is potentially suboptimal if there's ever a possibility of
3737 backwards (in pool order) 2'd level references. However, it's
3738 not clear that 2'd level references can happen. */
3739 for (pool = first_pool; pool; pool = pool->next)
3741 struct pool_sym *sym;
3742 char *label;
3744 /* skip unmarked entries; no insn refers to them. */
3745 if (!pool->mark)
3746 continue;
3748 /* skip CONST_DOUBLEs too - correct? */
3749 if (GET_CODE (pool->constant) == CONST_DOUBLE)
3750 continue;
3751 label = XSTR (pool->constant, 0);
3753 /* Be sure the symbol's value is marked. */
3754 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3755 sym = sym->next)
3756 if (sym->label == label)
3757 sym->pool->mark = 1;
3758 /* If we didn't find it, there's something truly wrong here, but it
3759 will be announced by the assembler. */
3763 static void
3764 mark_constants (x)
3765 register rtx x;
3767 register int i;
3768 register const char *format_ptr;
3770 if (x == 0)
3771 return;
3773 if (GET_CODE (x) == SYMBOL_REF)
3775 if (CONSTANT_POOL_ADDRESS_P (x))
3776 find_pool_constant (x)->mark = 1;
3777 return;
3779 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3780 a MEM, but does not constitute a use of that MEM. This is particularly
3781 important inside a nested function, because CONST_DOUBLE_MEM may be
3782 a reference to a MEM in the parent's constant pool. See the comment
3783 in force_const_mem. */
3784 else if (GET_CODE (x) == CONST_DOUBLE)
3785 return;
3787 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3788 insns, not any notes that may be attached. We don't want to mark
3789 a constant just because it happens to appear in a REG_EQUIV note. */
3790 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3792 mark_constants (PATTERN (x));
3793 return;
3796 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3798 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3800 switch (*format_ptr++)
3802 case 'e':
3803 mark_constants (XEXP (x, i));
3804 break;
3806 case 'E':
3807 if (XVEC (x, i) != 0)
3809 register int j;
3811 for (j = 0; j < XVECLEN (x, i); j++)
3812 mark_constants (XVECEXP (x, i, j));
3814 break;
3816 case 'S':
3817 case 's':
3818 case '0':
3819 case 'i':
3820 case 'w':
3821 case 'n':
3822 case 'u':
3823 break;
3825 default:
3826 abort ();
3831 /* Find all the constants whose addresses are referenced inside of EXP,
3832 and make sure assembler code with a label has been output for each one.
3833 Indicate whether an ADDR_EXPR has been encountered. */
3835 static int
3836 output_addressed_constants (exp)
3837 tree exp;
3839 int reloc = 0;
3841 switch (TREE_CODE (exp))
3843 case ADDR_EXPR:
3845 register tree constant = TREE_OPERAND (exp, 0);
3847 while (TREE_CODE (constant) == COMPONENT_REF)
3849 constant = TREE_OPERAND (constant, 0);
3852 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3853 || TREE_CODE (constant) == CONSTRUCTOR)
3854 /* No need to do anything here
3855 for addresses of variables or functions. */
3856 output_constant_def (constant);
3858 reloc = 1;
3859 break;
3861 case PLUS_EXPR:
3862 case MINUS_EXPR:
3863 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3864 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3865 break;
3867 case NOP_EXPR:
3868 case CONVERT_EXPR:
3869 case NON_LVALUE_EXPR:
3870 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3871 break;
3873 case CONSTRUCTOR:
3875 register tree link;
3876 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3877 if (TREE_VALUE (link) != 0)
3878 reloc |= output_addressed_constants (TREE_VALUE (link));
3880 break;
3882 default:
3883 break;
3885 return reloc;
3888 /* Output assembler code for constant EXP to FILE, with no label.
3889 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3890 Assumes output_addressed_constants has been done on EXP already.
3892 Generate exactly SIZE bytes of assembler data, padding at the end
3893 with zeros if necessary. SIZE must always be specified.
3895 SIZE is important for structure constructors,
3896 since trailing members may have been omitted from the constructor.
3897 It is also important for initialization of arrays from string constants
3898 since the full length of the string constant might not be wanted.
3899 It is also needed for initialization of unions, where the initializer's
3900 type is just one member, and that may not be as long as the union.
3902 There a case in which we would fail to output exactly SIZE bytes:
3903 for a structure constructor that wants to produce more than SIZE bytes.
3904 But such constructors will never be generated for any possible input. */
3906 void
3907 output_constant (exp, size)
3908 register tree exp;
3909 register int size;
3911 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3913 /* Some front-ends use constants other than the standard
3914 language-indepdent varieties, but which may still be output
3915 directly. Give the front-end a chance to convert EXP to a
3916 language-independent representation. */
3917 if (lang_expand_constant)
3918 exp = (*lang_expand_constant) (exp);
3920 if (size == 0 || flag_syntax_only)
3921 return;
3923 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3924 That way we get the constant (we hope) inside it. Also, strip off any
3925 NOP_EXPR that converts between two record, union, array, or set types. */
3926 while ((TREE_CODE (exp) == NOP_EXPR
3927 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3928 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3929 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3930 exp = TREE_OPERAND (exp, 0);
3932 /* Allow a constructor with no elements for any data type.
3933 This means to fill the space with zeros. */
3934 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3936 assemble_zeros (size);
3937 return;
3940 switch (code)
3942 case CHAR_TYPE:
3943 case BOOLEAN_TYPE:
3944 case INTEGER_TYPE:
3945 case ENUMERAL_TYPE:
3946 case POINTER_TYPE:
3947 case REFERENCE_TYPE:
3948 /* ??? What about (int)((float)(int)&foo + 4) */
3949 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3950 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3951 exp = TREE_OPERAND (exp, 0);
3953 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3954 EXPAND_INITIALIZER),
3955 size, 0))
3956 error ("initializer for integer value is too complicated");
3957 size = 0;
3958 break;
3960 case REAL_TYPE:
3961 if (TREE_CODE (exp) != REAL_CST)
3962 error ("initializer for floating value is not a floating constant");
3964 assemble_real (TREE_REAL_CST (exp),
3965 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3966 size = 0;
3967 break;
3969 case COMPLEX_TYPE:
3970 output_constant (TREE_REALPART (exp), size / 2);
3971 output_constant (TREE_IMAGPART (exp), size / 2);
3972 size -= (size / 2) * 2;
3973 break;
3975 case ARRAY_TYPE:
3976 if (TREE_CODE (exp) == CONSTRUCTOR)
3978 output_constructor (exp, size);
3979 return;
3981 else if (TREE_CODE (exp) == STRING_CST)
3983 int excess = 0;
3985 if (size > TREE_STRING_LENGTH (exp))
3987 excess = size - TREE_STRING_LENGTH (exp);
3988 size = TREE_STRING_LENGTH (exp);
3991 assemble_string (TREE_STRING_POINTER (exp), size);
3992 size = excess;
3994 else
3995 abort ();
3996 break;
3998 case RECORD_TYPE:
3999 case UNION_TYPE:
4000 if (TREE_CODE (exp) == CONSTRUCTOR)
4001 output_constructor (exp, size);
4002 else
4003 abort ();
4004 return;
4006 case SET_TYPE:
4007 if (TREE_CODE (exp) == INTEGER_CST)
4008 assemble_integer (expand_expr (exp, NULL_RTX,
4009 VOIDmode, EXPAND_INITIALIZER),
4010 size, 1);
4011 else if (TREE_CODE (exp) == CONSTRUCTOR)
4013 unsigned char *buffer = (unsigned char *) alloca (size);
4014 if (get_set_constructor_bytes (exp, buffer, size))
4015 abort ();
4016 assemble_string ((char *) buffer, size);
4018 else
4019 error ("unknown set constructor type");
4020 return;
4022 default:
4023 break; /* ??? */
4026 if (size > 0)
4027 assemble_zeros (size);
4031 /* Subroutine of output_constant, used for CONSTRUCTORs
4032 (aggregate constants).
4033 Generate at least SIZE bytes, padding if necessary. */
4035 static void
4036 output_constructor (exp, size)
4037 tree exp;
4038 int size;
4040 register tree link, field = 0;
4041 HOST_WIDE_INT min_index = 0;
4042 /* Number of bytes output or skipped so far.
4043 In other words, current position within the constructor. */
4044 int total_bytes = 0;
4045 /* Non-zero means BYTE contains part of a byte, to be output. */
4046 int byte_buffer_in_use = 0;
4047 register int byte;
4049 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4050 abort ();
4052 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4053 field = TYPE_FIELDS (TREE_TYPE (exp));
4055 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4056 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4057 min_index
4058 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4060 /* As LINK goes through the elements of the constant,
4061 FIELD goes through the structure fields, if the constant is a structure.
4062 if the constant is a union, then we override this,
4063 by getting the field from the TREE_LIST element.
4064 But the constant could also be an array. Then FIELD is zero.
4066 There is always a maximum of one element in the chain LINK for unions
4067 (even if the initializer in a source program incorrectly contains
4068 more one). */
4069 for (link = CONSTRUCTOR_ELTS (exp);
4070 link;
4071 link = TREE_CHAIN (link),
4072 field = field ? TREE_CHAIN (field) : 0)
4074 tree val = TREE_VALUE (link);
4075 tree index = 0;
4077 /* the element in a union constructor specifies the proper field. */
4079 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4080 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4082 /* if available, use the type given by link */
4083 if (TREE_PURPOSE (link) != 0)
4084 field = TREE_PURPOSE (link);
4087 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4088 index = TREE_PURPOSE (link);
4090 /* Eliminate the marker that makes a cast not be an lvalue. */
4091 if (val != 0)
4092 STRIP_NOPS (val);
4094 if (index && TREE_CODE (index) == RANGE_EXPR)
4096 register int fieldsize
4097 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4098 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4099 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4100 HOST_WIDE_INT index;
4101 for (index = lo_index; index <= hi_index; index++)
4103 /* Output the element's initial value. */
4104 if (val == 0)
4105 assemble_zeros (fieldsize);
4106 else
4107 output_constant (val, fieldsize);
4109 /* Count its size. */
4110 total_bytes += fieldsize;
4113 else if (field == 0 || !DECL_BIT_FIELD (field))
4115 /* An element that is not a bit-field. */
4117 register int fieldsize;
4118 /* Since this structure is static,
4119 we know the positions are constant. */
4120 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4121 / BITS_PER_UNIT)
4122 : 0);
4123 if (index != 0)
4124 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4125 / BITS_PER_UNIT
4126 * (TREE_INT_CST_LOW (index) - min_index));
4128 /* Output any buffered-up bit-fields preceding this element. */
4129 if (byte_buffer_in_use)
4131 ASM_OUTPUT_BYTE (asm_out_file, byte);
4132 total_bytes++;
4133 byte_buffer_in_use = 0;
4136 /* Advance to offset of this element.
4137 Note no alignment needed in an array, since that is guaranteed
4138 if each element has the proper size. */
4139 if ((field != 0 || index != 0) && bitpos != total_bytes)
4141 assemble_zeros (bitpos - total_bytes);
4142 total_bytes = bitpos;
4145 /* Determine size this element should occupy. */
4146 if (field)
4148 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4149 abort ();
4150 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4152 /* This avoids overflow trouble. */
4153 tree size_tree = size_binop (CEIL_DIV_EXPR,
4154 DECL_SIZE (field),
4155 size_int (BITS_PER_UNIT));
4156 fieldsize = TREE_INT_CST_LOW (size_tree);
4158 else
4160 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4161 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4164 else
4165 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4167 /* Output the element's initial value. */
4168 if (val == 0)
4169 assemble_zeros (fieldsize);
4170 else
4171 output_constant (val, fieldsize);
4173 /* Count its size. */
4174 total_bytes += fieldsize;
4176 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4177 error ("invalid initial value for member `%s'",
4178 IDENTIFIER_POINTER (DECL_NAME (field)));
4179 else
4181 /* Element that is a bit-field. */
4183 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4184 int end_offset
4185 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4187 if (val == 0)
4188 val = integer_zero_node;
4190 /* If this field does not start in this (or, next) byte,
4191 skip some bytes. */
4192 if (next_offset / BITS_PER_UNIT != total_bytes)
4194 /* Output remnant of any bit field in previous bytes. */
4195 if (byte_buffer_in_use)
4197 ASM_OUTPUT_BYTE (asm_out_file, byte);
4198 total_bytes++;
4199 byte_buffer_in_use = 0;
4202 /* If still not at proper byte, advance to there. */
4203 if (next_offset / BITS_PER_UNIT != total_bytes)
4205 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4206 total_bytes = next_offset / BITS_PER_UNIT;
4210 if (! byte_buffer_in_use)
4211 byte = 0;
4213 /* We must split the element into pieces that fall within
4214 separate bytes, and combine each byte with previous or
4215 following bit-fields. */
4217 /* next_offset is the offset n fbits from the beginning of
4218 the structure to the next bit of this element to be processed.
4219 end_offset is the offset of the first bit past the end of
4220 this element. */
4221 while (next_offset < end_offset)
4223 int this_time;
4224 int shift;
4225 HOST_WIDE_INT value;
4226 int next_byte = next_offset / BITS_PER_UNIT;
4227 int next_bit = next_offset % BITS_PER_UNIT;
4229 /* Advance from byte to byte
4230 within this element when necessary. */
4231 while (next_byte != total_bytes)
4233 ASM_OUTPUT_BYTE (asm_out_file, byte);
4234 total_bytes++;
4235 byte = 0;
4238 /* Number of bits we can process at once
4239 (all part of the same byte). */
4240 this_time = MIN (end_offset - next_offset,
4241 BITS_PER_UNIT - next_bit);
4242 if (BYTES_BIG_ENDIAN)
4244 /* On big-endian machine, take the most significant bits
4245 first (of the bits that are significant)
4246 and put them into bytes from the most significant end. */
4247 shift = end_offset - next_offset - this_time;
4248 /* Don't try to take a bunch of bits that cross
4249 the word boundary in the INTEGER_CST. */
4250 if (shift < HOST_BITS_PER_WIDE_INT
4251 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4253 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4254 shift = HOST_BITS_PER_WIDE_INT;
4257 /* Now get the bits from the appropriate constant word. */
4258 if (shift < HOST_BITS_PER_WIDE_INT)
4260 value = TREE_INT_CST_LOW (val);
4262 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4264 value = TREE_INT_CST_HIGH (val);
4265 shift -= HOST_BITS_PER_WIDE_INT;
4267 else
4268 abort ();
4269 byte |= (((value >> shift)
4270 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4271 << (BITS_PER_UNIT - this_time - next_bit));
4273 else
4275 /* On little-endian machines,
4276 take first the least significant bits of the value
4277 and pack them starting at the least significant
4278 bits of the bytes. */
4279 shift = (next_offset
4280 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4281 /* Don't try to take a bunch of bits that cross
4282 the word boundary in the INTEGER_CST. */
4283 if (shift < HOST_BITS_PER_WIDE_INT
4284 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4286 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4287 shift = HOST_BITS_PER_WIDE_INT;
4290 /* Now get the bits from the appropriate constant word. */
4291 if (shift < HOST_BITS_PER_WIDE_INT)
4292 value = TREE_INT_CST_LOW (val);
4293 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4295 value = TREE_INT_CST_HIGH (val);
4296 shift -= HOST_BITS_PER_WIDE_INT;
4298 else
4299 abort ();
4300 byte |= (((value >> shift)
4301 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4302 << next_bit);
4304 next_offset += this_time;
4305 byte_buffer_in_use = 1;
4309 if (byte_buffer_in_use)
4311 ASM_OUTPUT_BYTE (asm_out_file, byte);
4312 total_bytes++;
4314 if (total_bytes < size)
4315 assemble_zeros (size - total_bytes);
4318 #ifdef HANDLE_PRAGMA_WEAK
4319 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4320 associatd with NAME. */
4323 add_weak (name, value)
4324 char *name;
4325 char *value;
4327 struct weak_syms *weak;
4329 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4331 if (weak == NULL)
4332 return 0;
4334 weak->next = weak_decls;
4335 weak->name = name;
4336 weak->value = value;
4337 weak_decls = weak;
4339 return 1;
4341 #endif /* HANDLE_PRAGMA_WEAK */
4343 /* Declare DECL to be a weak symbol. */
4345 void
4346 declare_weak (decl)
4347 tree decl;
4349 if (! TREE_PUBLIC (decl))
4350 error_with_decl (decl, "weak declaration of `%s' must be public");
4351 else if (TREE_ASM_WRITTEN (decl))
4352 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4353 else if (SUPPORTS_WEAK)
4354 DECL_WEAK (decl) = 1;
4355 #ifdef HANDLE_PRAGMA_WEAK
4356 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4357 #endif
4360 /* Emit any pending weak declarations. */
4362 #ifdef HANDLE_PRAGMA_WEAK
4363 struct weak_syms * weak_decls;
4364 #endif
4366 void
4367 weak_finish ()
4369 #ifdef HANDLE_PRAGMA_WEAK
4370 if (HANDLE_PRAGMA_WEAK)
4372 struct weak_syms *t;
4373 for (t = weak_decls; t; t = t->next)
4375 if (t->name)
4377 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4378 if (t->value)
4379 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4383 #endif
4386 /* Remove NAME from the pending list of weak symbols. This prevents
4387 the compiler from emitting multiple .weak directives which confuses
4388 some assemblers. */
4389 static void
4390 remove_from_pending_weak_list (name)
4391 char *name ATTRIBUTE_UNUSED;
4393 #ifdef HANDLE_PRAGMA_WEAK
4394 if (HANDLE_PRAGMA_WEAK)
4396 struct weak_syms *t;
4397 for (t = weak_decls; t; t = t->next)
4399 if (t->name && strcmp (name, t->name) == 0)
4400 t->name = NULL;
4403 #endif
4406 void
4407 assemble_alias (decl, target)
4408 tree decl, target ATTRIBUTE_UNUSED;
4410 char *name;
4412 make_decl_rtl (decl, (char *) 0, 1);
4413 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4415 #ifdef ASM_OUTPUT_DEF
4416 /* Make name accessible from other files, if appropriate. */
4418 if (TREE_PUBLIC (decl))
4420 #ifdef ASM_WEAKEN_LABEL
4421 if (DECL_WEAK (decl))
4423 ASM_WEAKEN_LABEL (asm_out_file, name);
4424 /* Remove this function from the pending weak list so that
4425 we do not emit multiple .weak directives for it. */
4426 remove_from_pending_weak_list
4427 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4429 else
4430 #endif
4431 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4434 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4435 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4436 #else
4437 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4438 #endif
4439 TREE_ASM_WRITTEN (decl) = 1;
4440 #else
4441 #ifdef ASM_OUTPUT_WEAK_ALIAS
4442 if (! DECL_WEAK (decl))
4443 warning ("only weak aliases are supported in this configuration");
4445 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4446 TREE_ASM_WRITTEN (decl) = 1;
4447 #else
4448 warning ("alias definitions not supported in this configuration; ignored");
4449 #endif
4450 #endif
4453 /* This determines whether or not we support link-once semantics. */
4454 #ifndef SUPPORTS_ONE_ONLY
4455 #ifdef MAKE_DECL_ONE_ONLY
4456 #define SUPPORTS_ONE_ONLY 1
4457 #else
4458 #define SUPPORTS_ONE_ONLY 0
4459 #endif
4460 #endif
4462 /* Returns 1 if the target configuration supports defining public symbols
4463 so that one of them will be chosen at link time instead of generating a
4464 multiply-defined symbol error, whether through the use of weak symbols or
4465 a target-specific mechanism for having duplicates discarded. */
4468 supports_one_only ()
4470 if (SUPPORTS_ONE_ONLY)
4471 return 1;
4472 return SUPPORTS_WEAK;
4475 /* Set up DECL as a public symbol that can be defined in multiple
4476 translation units without generating a linker error. */
4478 void
4479 make_decl_one_only (decl)
4480 tree decl;
4482 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4483 abort ();
4485 TREE_PUBLIC (decl) = 1;
4487 if (TREE_CODE (decl) == VAR_DECL
4488 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4489 DECL_COMMON (decl) = 1;
4490 else if (SUPPORTS_ONE_ONLY)
4492 #ifdef MAKE_DECL_ONE_ONLY
4493 MAKE_DECL_ONE_ONLY (decl);
4494 #endif
4495 DECL_ONE_ONLY (decl) = 1;
4497 else if (SUPPORTS_WEAK)
4498 DECL_WEAK (decl) = 1;
4499 else
4500 abort ();