* flags.h: New variables align_loops, align_loops_log,
[official-gcc.git] / gcc / varasm.c
blob7110a2e6f2a3fa5745bfe1be463a1465fd182d15
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 /* Handle a user-specified function alignment.
983 Note that we still need to align to FUNCTION_BOUNDARY, as above,
984 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
985 if (align_functions_log > align)
987 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
988 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
989 align_functions_log, align_functions-1);
990 #else
991 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
992 #endif
995 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
996 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
997 #endif
999 #ifdef SDB_DEBUGGING_INFO
1000 /* Output SDB definition of the function. */
1001 if (write_symbols == SDB_DEBUG)
1002 sdbout_mark_begin_function ();
1003 #endif
1005 #ifdef DBX_DEBUGGING_INFO
1006 /* Output DBX definition of the function. */
1007 if (write_symbols == DBX_DEBUG)
1008 dbxout_begin_function (decl);
1009 #endif
1011 /* Make function name accessible from other files, if appropriate. */
1013 if (TREE_PUBLIC (decl))
1015 if (! first_global_object_name)
1017 const char *p;
1018 char **name;
1020 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1021 name = &first_global_object_name;
1022 else
1023 name = &weak_global_object_name;
1025 STRIP_NAME_ENCODING (p, fnname);
1026 *name = permalloc (strlen (p) + 1);
1027 strcpy (*name, p);
1030 #ifdef ASM_WEAKEN_LABEL
1031 if (DECL_WEAK (decl))
1033 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1034 /* Remove this function from the pending weak list so that
1035 we do not emit multiple .weak directives for it. */
1036 remove_from_pending_weak_list
1037 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1039 else
1040 #endif
1041 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1044 /* Do any machine/system dependent processing of the function name */
1045 #ifdef ASM_DECLARE_FUNCTION_NAME
1046 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1047 #else
1048 /* Standard thing is just output label for the function. */
1049 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1050 #endif /* ASM_DECLARE_FUNCTION_NAME */
1053 /* Output assembler code associated with defining the size of the
1054 function. DECL describes the function. NAME is the function's name. */
1056 void
1057 assemble_end_function (decl, fnname)
1058 tree decl;
1059 char *fnname;
1061 #ifdef ASM_DECLARE_FUNCTION_SIZE
1062 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1063 #endif
1064 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1066 output_constant_pool (fnname, decl);
1067 function_section (decl); /* need to switch back */
1070 /* Output any constants which should appear after the function. */
1071 output_after_function_constants ();
1074 /* Assemble code to leave SIZE bytes of zeros. */
1076 void
1077 assemble_zeros (size)
1078 int size;
1080 /* Do no output if -fsyntax-only. */
1081 if (flag_syntax_only)
1082 return;
1084 #ifdef ASM_NO_SKIP_IN_TEXT
1085 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1086 so we must output 0s explicitly in the text section. */
1087 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1089 int i;
1091 for (i = 0; i < size - 20; i += 20)
1093 #ifdef ASM_BYTE_OP
1094 fprintf (asm_out_file,
1095 "%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);
1096 #else
1097 fprintf (asm_out_file,
1098 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1099 #endif
1101 if (i < size)
1103 #ifdef ASM_BYTE_OP
1104 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1105 #else
1106 fprintf (asm_out_file, "\tbyte 0");
1107 #endif
1108 i++;
1109 for (; i < size; i++)
1110 fprintf (asm_out_file, ",0");
1111 fprintf (asm_out_file, "\n");
1114 else
1115 #endif
1116 if (size > 0)
1117 ASM_OUTPUT_SKIP (asm_out_file, size);
1120 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1122 void
1123 assemble_align (align)
1124 int align;
1126 if (align > BITS_PER_UNIT)
1127 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1130 /* Assemble a string constant with the specified C string as contents. */
1132 void
1133 assemble_string (p, size)
1134 const char *p;
1135 int size;
1137 int pos = 0;
1138 int maximum = 2000;
1140 /* If the string is very long, split it up. */
1142 while (pos < size)
1144 int thissize = size - pos;
1145 if (thissize > maximum)
1146 thissize = maximum;
1148 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1150 pos += thissize;
1151 p += thissize;
1156 /* Assemble everything that is needed for a variable or function declaration.
1157 Not used for automatic variables, and not used for function definitions.
1158 Should not be called for variables of incomplete structure type.
1160 TOP_LEVEL is nonzero if this variable has file scope.
1161 AT_END is nonzero if this is the special handling, at end of compilation,
1162 to define things that have had only tentative definitions.
1163 DONT_OUTPUT_DATA if nonzero means don't actually output the
1164 initial value (that will be done by the caller). */
1166 void
1167 assemble_variable (decl, top_level, at_end, dont_output_data)
1168 tree decl;
1169 int top_level ATTRIBUTE_UNUSED;
1170 int at_end;
1171 int dont_output_data;
1173 register char *name;
1174 unsigned int align;
1175 tree size_tree = NULL_TREE;
1176 int reloc = 0;
1177 enum in_section saved_in_section;
1179 last_assemble_variable_decl = 0;
1181 if (GET_CODE (DECL_RTL (decl)) == REG)
1183 /* Do output symbol info for global register variables, but do nothing
1184 else for them. */
1186 if (TREE_ASM_WRITTEN (decl))
1187 return;
1188 TREE_ASM_WRITTEN (decl) = 1;
1190 /* Do no output if -fsyntax-only. */
1191 if (flag_syntax_only)
1192 return;
1194 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1195 /* File-scope global variables are output here. */
1196 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1197 && top_level)
1198 dbxout_symbol (decl, 0);
1199 #endif
1200 #ifdef SDB_DEBUGGING_INFO
1201 if (write_symbols == SDB_DEBUG && top_level
1202 /* Leave initialized global vars for end of compilation;
1203 see comment in compile_file. */
1204 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1205 sdbout_symbol (decl, 0);
1206 #endif
1208 /* Don't output any DWARF debugging information for variables here.
1209 In the case of local variables, the information for them is output
1210 when we do our recursive traversal of the tree representation for
1211 the entire containing function. In the case of file-scope variables,
1212 we output information for all of them at the very end of compilation
1213 while we are doing our final traversal of the chain of file-scope
1214 declarations. */
1216 return;
1219 /* Normally no need to say anything here for external references,
1220 since assemble_external is called by the language-specific code
1221 when a declaration is first seen. */
1223 if (DECL_EXTERNAL (decl))
1224 return;
1226 /* Output no assembler code for a function declaration.
1227 Only definitions of functions output anything. */
1229 if (TREE_CODE (decl) == FUNCTION_DECL)
1230 return;
1232 /* If type was incomplete when the variable was declared,
1233 see if it is complete now. */
1235 if (DECL_SIZE (decl) == 0)
1236 layout_decl (decl, 0);
1238 /* Still incomplete => don't allocate it; treat the tentative defn
1239 (which is what it must have been) as an `extern' reference. */
1241 if (!dont_output_data && DECL_SIZE (decl) == 0)
1243 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1244 DECL_SOURCE_LINE (decl),
1245 "storage size of `%s' isn't known",
1246 IDENTIFIER_POINTER (DECL_NAME (decl)));
1247 TREE_ASM_WRITTEN (decl) = 1;
1248 return;
1251 /* The first declaration of a variable that comes through this function
1252 decides whether it is global (in C, has external linkage)
1253 or local (in C, has internal linkage). So do nothing more
1254 if this function has already run. */
1256 if (TREE_ASM_WRITTEN (decl))
1257 return;
1259 TREE_ASM_WRITTEN (decl) = 1;
1261 /* Do no output if -fsyntax-only. */
1262 if (flag_syntax_only)
1263 return;
1265 app_disable ();
1267 if (! dont_output_data)
1269 int size;
1271 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1272 goto finish;
1274 /* This is better than explicit arithmetic, since it avoids overflow. */
1275 size_tree = size_binop (CEIL_DIV_EXPR,
1276 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1278 size = TREE_INT_CST_LOW (size_tree);
1279 if (TREE_INT_CST_HIGH (size_tree) != 0
1280 || size != TREE_INT_CST_LOW (size_tree))
1282 error_with_decl (decl, "size of variable `%s' is too large");
1283 goto finish;
1287 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1289 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1290 && ! first_global_object_name
1291 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1292 || DECL_INITIAL (decl) == error_mark_node))
1293 && ! DECL_WEAK (decl)
1294 && ! DECL_ONE_ONLY (decl))
1296 const char *p;
1298 STRIP_NAME_ENCODING (p, name);
1299 first_global_object_name = permalloc (strlen (p) + 1);
1300 strcpy (first_global_object_name, p);
1303 /* Compute the alignment of this data. */
1305 align = DECL_ALIGN (decl);
1307 /* In the case for initialing an array whose length isn't specified,
1308 where we have not yet been able to do the layout,
1309 figure out the proper alignment now. */
1310 if (dont_output_data && DECL_SIZE (decl) == 0
1311 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1312 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1314 /* Some object file formats have a maximum alignment which they support.
1315 In particular, a.out format supports a maximum alignment of 4. */
1316 #ifndef MAX_OFILE_ALIGNMENT
1317 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1318 #endif
1319 if (align > MAX_OFILE_ALIGNMENT)
1321 warning_with_decl (decl,
1322 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1323 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1324 align = MAX_OFILE_ALIGNMENT;
1327 /* On some machines, it is good to increase alignment sometimes. */
1328 #ifdef DATA_ALIGNMENT
1329 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1330 #endif
1331 #ifdef CONSTANT_ALIGNMENT
1332 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1333 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1334 #endif
1336 /* Reset the alignment in case we have made it tighter, so we can benefit
1337 from it in get_pointer_alignment. */
1338 DECL_ALIGN (decl) = align;
1340 /* Handle uninitialized definitions. */
1342 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1343 /* If the target can't output uninitialized but not common global data
1344 in .bss, then we have to use .data. */
1345 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1346 && DECL_COMMON (decl)
1347 #endif
1348 && DECL_SECTION_NAME (decl) == 0
1349 && ! dont_output_data)
1351 int size = TREE_INT_CST_LOW (size_tree);
1352 int rounded = size;
1354 /* Don't allocate zero bytes of common,
1355 since that means "undefined external" in the linker. */
1356 if (size == 0) rounded = 1;
1357 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1358 so that each uninitialized object starts on such a boundary. */
1359 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1360 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1361 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1363 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1364 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1365 warning_with_decl
1366 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1367 #endif
1369 #ifdef DBX_DEBUGGING_INFO
1370 /* File-scope global variables are output here. */
1371 if (write_symbols == DBX_DEBUG && top_level)
1372 dbxout_symbol (decl, 0);
1373 #endif
1374 #ifdef SDB_DEBUGGING_INFO
1375 if (write_symbols == SDB_DEBUG && top_level
1376 /* Leave initialized global vars for end of compilation;
1377 see comment in compile_file. */
1378 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1379 sdbout_symbol (decl, 0);
1380 #endif
1382 /* Don't output any DWARF debugging information for variables here.
1383 In the case of local variables, the information for them is output
1384 when we do our recursive traversal of the tree representation for
1385 the entire containing function. In the case of file-scope variables,
1386 we output information for all of them at the very end of compilation
1387 while we are doing our final traversal of the chain of file-scope
1388 declarations. */
1390 #if 0 /* ??? We should either delete this or add a comment describing what
1391 it was intended to do and why we shouldn't delete it. */
1392 if (flag_shared_data)
1393 data_section ();
1394 #endif
1396 if (TREE_PUBLIC (decl)
1397 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1398 && DECL_COMMON (decl)
1399 #endif
1402 #ifdef ASM_OUTPUT_SHARED_COMMON
1403 if (flag_shared_data)
1404 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1405 else
1406 #endif
1408 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1409 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1410 DECL_ALIGN (decl));
1411 #else
1412 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1413 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1414 DECL_ALIGN (decl));
1415 #else
1416 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1417 #endif
1418 #endif
1421 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1422 else if (TREE_PUBLIC (decl))
1424 #ifdef ASM_OUTPUT_SHARED_BSS
1425 if (flag_shared_data)
1426 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1427 else
1428 #endif
1430 #ifdef ASM_OUTPUT_ALIGNED_BSS
1431 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1432 DECL_ALIGN (decl));
1433 #else
1434 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1435 #endif
1438 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1439 else
1441 #ifdef ASM_OUTPUT_SHARED_LOCAL
1442 if (flag_shared_data)
1443 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1444 else
1445 #endif
1447 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1448 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1449 DECL_ALIGN (decl));
1450 #else
1451 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1452 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1453 DECL_ALIGN (decl));
1454 #else
1455 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1456 #endif
1457 #endif
1460 goto finish;
1463 /* Handle initialized definitions.
1464 Also handle uninitialized global definitions if -fno-common and the
1465 target doesn't support ASM_OUTPUT_BSS. */
1467 /* First make the assembler name(s) global if appropriate. */
1468 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1470 #ifdef ASM_WEAKEN_LABEL
1471 if (DECL_WEAK (decl))
1473 ASM_WEAKEN_LABEL (asm_out_file, name);
1474 /* Remove this variable from the pending weak list so that
1475 we do not emit multiple .weak directives for it. */
1476 remove_from_pending_weak_list
1477 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1479 else
1480 #endif
1481 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1483 #if 0
1484 for (d = equivalents; d; d = TREE_CHAIN (d))
1486 tree e = TREE_VALUE (d);
1487 if (TREE_PUBLIC (e) && DECL_NAME (e))
1488 ASM_GLOBALIZE_LABEL (asm_out_file,
1489 XSTR (XEXP (DECL_RTL (e), 0), 0));
1491 #endif
1493 /* Output any data that we will need to use the address of. */
1494 if (DECL_INITIAL (decl) == error_mark_node)
1495 reloc = contains_pointers_p (TREE_TYPE (decl));
1496 else if (DECL_INITIAL (decl))
1497 reloc = output_addressed_constants (DECL_INITIAL (decl));
1499 #ifdef ASM_OUTPUT_SECTION_NAME
1500 if ((flag_data_sections != 0
1501 && DECL_SECTION_NAME (decl) == NULL_TREE)
1502 || UNIQUE_SECTION_P (decl))
1503 UNIQUE_SECTION (decl, reloc);
1504 #endif
1506 /* Switch to the appropriate section. */
1507 variable_section (decl, reloc);
1509 /* dbxout.c needs to know this. */
1510 if (in_text_section ())
1511 DECL_IN_TEXT_SECTION (decl) = 1;
1513 /* Record current section so we can restore it if dbxout.c clobbers it. */
1514 saved_in_section = in_section;
1516 /* Output the dbx info now that we have chosen the section. */
1518 #ifdef DBX_DEBUGGING_INFO
1519 /* File-scope global variables are output here. */
1520 if (write_symbols == DBX_DEBUG && top_level)
1521 dbxout_symbol (decl, 0);
1522 #endif
1523 #ifdef SDB_DEBUGGING_INFO
1524 if (write_symbols == SDB_DEBUG && top_level
1525 /* Leave initialized global vars for end of compilation;
1526 see comment in compile_file. */
1527 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1528 sdbout_symbol (decl, 0);
1529 #endif
1531 /* Don't output any DWARF debugging information for variables here.
1532 In the case of local variables, the information for them is output
1533 when we do our recursive traversal of the tree representation for
1534 the entire containing function. In the case of file-scope variables,
1535 we output information for all of them at the very end of compilation
1536 while we are doing our final traversal of the chain of file-scope
1537 declarations. */
1539 /* If the debugging output changed sections, reselect the section
1540 that's supposed to be selected. */
1541 if (in_section != saved_in_section)
1542 variable_section (decl, reloc);
1544 /* Output the alignment of this data. */
1545 if (align > BITS_PER_UNIT)
1546 ASM_OUTPUT_ALIGN (asm_out_file,
1547 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1549 /* Do any machine/system dependent processing of the object. */
1550 #ifdef ASM_DECLARE_OBJECT_NAME
1551 last_assemble_variable_decl = decl;
1552 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1553 #else
1554 /* Standard thing is just output label for the object. */
1555 ASM_OUTPUT_LABEL (asm_out_file, name);
1556 #endif /* ASM_DECLARE_OBJECT_NAME */
1558 if (!dont_output_data)
1560 if (DECL_INITIAL (decl))
1561 /* Output the actual data. */
1562 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1563 else
1564 /* Leave space for it. */
1565 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1568 finish:
1569 #ifdef XCOFF_DEBUGGING_INFO
1570 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1571 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1572 and `aa' hasn't been output yet, the assembler generates a stab entry with
1573 a value of zero, in addition to creating an unnecessary external entry
1574 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1576 /* File-scope global variables are output here. */
1577 if (write_symbols == XCOFF_DEBUG && top_level)
1579 saved_in_section = in_section;
1581 dbxout_symbol (decl, 0);
1583 if (in_section != saved_in_section)
1584 variable_section (decl, reloc);
1586 #else
1587 /* There must be a statement after a label. */
1589 #endif
1592 /* Return 1 if type TYPE contains any pointers. */
1594 static int
1595 contains_pointers_p (type)
1596 tree type;
1598 switch (TREE_CODE (type))
1600 case POINTER_TYPE:
1601 case REFERENCE_TYPE:
1602 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1603 so I'll play safe and return 1. */
1604 case OFFSET_TYPE:
1605 return 1;
1607 case RECORD_TYPE:
1608 case UNION_TYPE:
1609 case QUAL_UNION_TYPE:
1611 tree fields;
1612 /* For a type that has fields, see if the fields have pointers. */
1613 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1614 if (TREE_CODE (fields) == FIELD_DECL
1615 && contains_pointers_p (TREE_TYPE (fields)))
1616 return 1;
1617 return 0;
1620 case ARRAY_TYPE:
1621 /* An array type contains pointers if its element type does. */
1622 return contains_pointers_p (TREE_TYPE (type));
1624 default:
1625 return 0;
1629 /* Output something to declare an external symbol to the assembler.
1630 (Most assemblers don't need this, so we normally output nothing.)
1631 Do nothing if DECL is not external. */
1633 void
1634 assemble_external (decl)
1635 tree decl ATTRIBUTE_UNUSED;
1637 #ifdef ASM_OUTPUT_EXTERNAL
1638 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1639 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1641 rtx rtl = DECL_RTL (decl);
1643 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1644 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1646 /* Some systems do require some output. */
1647 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1648 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1651 #endif
1654 /* Similar, for calling a library function FUN. */
1656 void
1657 assemble_external_libcall (fun)
1658 rtx fun ATTRIBUTE_UNUSED;
1660 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1661 /* Declare library function name external when first used, if nec. */
1662 if (! SYMBOL_REF_USED (fun))
1664 SYMBOL_REF_USED (fun) = 1;
1665 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1667 #endif
1670 /* Declare the label NAME global. */
1672 void
1673 assemble_global (name)
1674 char *name;
1676 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1679 /* Assemble a label named NAME. */
1681 void
1682 assemble_label (name)
1683 char *name;
1685 ASM_OUTPUT_LABEL (asm_out_file, name);
1688 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1689 If NAME starts with a *, the rest of NAME is output verbatim.
1690 Otherwise NAME is transformed in an implementation-defined way
1691 (usually by the addition of an underscore).
1692 Many macros in the tm file are defined to call this function. */
1694 void
1695 assemble_name (file, name)
1696 FILE *file;
1697 const char *name;
1699 const char *real_name;
1700 tree id;
1702 STRIP_NAME_ENCODING (real_name, name);
1703 if (flag_prefix_function_name
1704 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1705 real_name = real_name + CHKR_PREFIX_SIZE;
1707 id = maybe_get_identifier (real_name);
1708 if (id)
1709 TREE_SYMBOL_REFERENCED (id) = 1;
1711 if (name[0] == '*')
1712 fputs (&name[1], file);
1713 else
1714 ASM_OUTPUT_LABELREF (file, name);
1717 /* Allocate SIZE bytes writable static space with a gensym name
1718 and return an RTX to refer to its address. */
1721 assemble_static_space (size)
1722 int size;
1724 char name[12];
1725 char *namestring;
1726 rtx x;
1728 #if 0
1729 if (flag_shared_data)
1730 data_section ();
1731 #endif
1733 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1734 ++const_labelno;
1736 namestring = (char *) obstack_alloc (saveable_obstack,
1737 strlen (name) + 2);
1738 strcpy (namestring, name);
1740 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1742 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1743 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1744 BIGGEST_ALIGNMENT);
1745 #else
1746 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1747 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1748 #else
1750 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1751 so that each uninitialized object starts on such a boundary. */
1752 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1753 int rounded ATTRIBUTE_UNUSED
1754 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1755 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1756 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1757 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1759 #endif
1760 #endif
1761 return x;
1764 /* Assemble the static constant template for function entry trampolines.
1765 This is done at most once per compilation.
1766 Returns an RTX for the address of the template. */
1768 #ifdef TRAMPOLINE_TEMPLATE
1770 assemble_trampoline_template ()
1772 char label[256];
1773 char *name;
1774 int align;
1776 /* By default, put trampoline templates in read-only data section. */
1778 #ifdef TRAMPOLINE_SECTION
1779 TRAMPOLINE_SECTION ();
1780 #else
1781 readonly_data_section ();
1782 #endif
1784 /* Write the assembler code to define one. */
1785 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1786 if (align > 0)
1787 ASM_OUTPUT_ALIGN (asm_out_file, align);
1789 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1790 TRAMPOLINE_TEMPLATE (asm_out_file);
1792 /* Record the rtl to refer to it. */
1793 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1794 name
1795 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1796 return gen_rtx_SYMBOL_REF (Pmode, name);
1798 #endif
1800 /* Assemble the integer constant X into an object of SIZE bytes.
1801 X must be either a CONST_INT or CONST_DOUBLE.
1803 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1804 non-zero, abort if we can't output the constant. */
1807 assemble_integer (x, size, force)
1808 rtx x;
1809 int size;
1810 int force;
1812 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1813 ASM_OUTPUT... macros. */
1815 switch (size)
1817 #ifdef ASM_OUTPUT_CHAR
1818 case 1:
1819 ASM_OUTPUT_CHAR (asm_out_file, x);
1820 return 1;
1821 #endif
1823 #ifdef ASM_OUTPUT_SHORT
1824 case 2:
1825 ASM_OUTPUT_SHORT (asm_out_file, x);
1826 return 1;
1827 #endif
1829 #ifdef ASM_OUTPUT_INT
1830 case 4:
1831 ASM_OUTPUT_INT (asm_out_file, x);
1832 return 1;
1833 #endif
1835 #ifdef ASM_OUTPUT_DOUBLE_INT
1836 case 8:
1837 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1838 return 1;
1839 #endif
1841 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1842 case 16:
1843 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1844 return 1;
1845 #endif
1848 /* If we couldn't do it that way, there are two other possibilities: First,
1849 if the machine can output an explicit byte and this is a 1 byte constant,
1850 we can use ASM_OUTPUT_BYTE. */
1852 #ifdef ASM_OUTPUT_BYTE
1853 if (size == 1 && GET_CODE (x) == CONST_INT)
1855 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1856 return 1;
1858 #endif
1860 /* Finally, if SIZE is larger than a single word, try to output the constant
1861 one word at a time. */
1863 if (size > UNITS_PER_WORD)
1865 int i;
1866 enum machine_mode mode
1867 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1868 rtx word;
1870 for (i = 0; i < size / UNITS_PER_WORD; i++)
1872 word = operand_subword (x, i, 0, mode);
1874 if (word == 0)
1875 break;
1877 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1878 break;
1881 if (i == size / UNITS_PER_WORD)
1882 return 1;
1883 /* If we output at least one word and then could not finish,
1884 there is no valid way to continue. */
1885 if (i > 0)
1886 abort ();
1889 if (force)
1890 abort ();
1892 return 0;
1895 /* Assemble the floating-point constant D into an object of size MODE. */
1897 void
1898 assemble_real (d, mode)
1899 REAL_VALUE_TYPE d;
1900 enum machine_mode mode;
1902 jmp_buf output_constant_handler;
1904 if (setjmp (output_constant_handler))
1906 error ("floating point trap outputting a constant");
1907 #ifdef REAL_IS_NOT_DOUBLE
1908 bzero ((char *) &d, sizeof d);
1909 d = dconst0;
1910 #else
1911 d = 0;
1912 #endif
1915 set_float_handler (output_constant_handler);
1917 switch (mode)
1919 #ifdef ASM_OUTPUT_BYTE_FLOAT
1920 case QFmode:
1921 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1922 break;
1923 #endif
1924 #ifdef ASM_OUTPUT_SHORT_FLOAT
1925 case HFmode:
1926 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1927 break;
1928 #endif
1929 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1930 case TQFmode:
1931 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1932 break;
1933 #endif
1934 #ifdef ASM_OUTPUT_FLOAT
1935 case SFmode:
1936 ASM_OUTPUT_FLOAT (asm_out_file, d);
1937 break;
1938 #endif
1940 #ifdef ASM_OUTPUT_DOUBLE
1941 case DFmode:
1942 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1943 break;
1944 #endif
1946 #ifdef ASM_OUTPUT_LONG_DOUBLE
1947 case XFmode:
1948 case TFmode:
1949 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1950 break;
1951 #endif
1953 default:
1954 abort ();
1957 set_float_handler (NULL_PTR);
1960 /* Here we combine duplicate floating constants to make
1961 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1963 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1964 They are chained through the CONST_DOUBLE_CHAIN.
1965 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1966 In that case, CONST_DOUBLE_MEM is either a MEM,
1967 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1969 (CONST_DOUBLE_MEM is used only for top-level functions.
1970 See force_const_mem for explanation.) */
1972 static rtx const_double_chain;
1974 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1975 For an integer, I0 is the low-order word and I1 is the high-order word.
1976 For a real number, I0 is the word with the low address
1977 and I1 is the word with the high address. */
1980 immed_double_const (i0, i1, mode)
1981 HOST_WIDE_INT i0, i1;
1982 enum machine_mode mode;
1984 register rtx r;
1986 if (GET_MODE_CLASS (mode) == MODE_INT
1987 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1989 /* We clear out all bits that don't belong in MODE, unless they and our
1990 sign bit are all one. So we get either a reasonable negative value
1991 or a reasonable unsigned value for this mode. */
1992 int width = GET_MODE_BITSIZE (mode);
1993 if (width < HOST_BITS_PER_WIDE_INT
1994 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1995 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1996 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1997 else if (width == HOST_BITS_PER_WIDE_INT
1998 && ! (i1 == ~0 && i0 < 0))
1999 i1 = 0;
2000 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2001 /* We cannot represent this value as a constant. */
2002 abort ();
2004 /* If this would be an entire word for the target, but is not for
2005 the host, then sign-extend on the host so that the number will look
2006 the same way on the host that it would on the target.
2008 For example, when building a 64 bit alpha hosted 32 bit sparc
2009 targeted compiler, then we want the 32 bit unsigned value -1 to be
2010 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2011 The later confuses the sparc backend. */
2013 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2014 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2015 i0 |= ((HOST_WIDE_INT) (-1) << width);
2017 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2019 ??? Strictly speaking, this is wrong if we create a CONST_INT
2020 for a large unsigned constant with the size of MODE being
2021 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2022 wider mode. In that case we will mis-interpret it as a negative
2023 number.
2025 Unfortunately, the only alternative is to make a CONST_DOUBLE
2026 for any constant in any mode if it is an unsigned constant larger
2027 than the maximum signed integer in an int on the host. However,
2028 doing this will break everyone that always expects to see a CONST_INT
2029 for SImode and smaller.
2031 We have always been making CONST_INTs in this case, so nothing new
2032 is being broken. */
2034 if (width <= HOST_BITS_PER_WIDE_INT)
2035 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2037 /* If this integer fits in one word, return a CONST_INT. */
2038 if ((i1 == 0 && i0 >= 0)
2039 || (i1 == ~0 && i0 < 0))
2040 return GEN_INT (i0);
2042 /* We use VOIDmode for integers. */
2043 mode = VOIDmode;
2046 /* Search the chain for an existing CONST_DOUBLE with the right value.
2047 If one is found, return it. */
2049 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2050 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2051 && GET_MODE (r) == mode)
2052 return r;
2054 /* No; make a new one and add it to the chain.
2056 We may be called by an optimizer which may be discarding any memory
2057 allocated during its processing (such as combine and loop). However,
2058 we will be leaving this constant on the chain, so we cannot tolerate
2059 freed memory. So switch to saveable_obstack for this allocation
2060 and then switch back if we were in current_obstack. */
2062 push_obstacks_nochange ();
2063 rtl_in_saveable_obstack ();
2064 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2065 pop_obstacks ();
2067 /* Don't touch const_double_chain in nested function; see force_const_mem.
2068 Also, don't touch it if not inside any function. */
2069 if (outer_function_chain == 0 && current_function_decl != 0)
2071 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2072 const_double_chain = r;
2075 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2076 Actual use of mem-slot is only through force_const_mem. */
2078 CONST_DOUBLE_MEM (r) = const0_rtx;
2080 return r;
2083 /* Return a CONST_DOUBLE for a specified `double' value
2084 and machine mode. */
2087 immed_real_const_1 (d, mode)
2088 REAL_VALUE_TYPE d;
2089 enum machine_mode mode;
2091 union real_extract u;
2092 register rtx r;
2094 /* Get the desired `double' value as a sequence of ints
2095 since that is how they are stored in a CONST_DOUBLE. */
2097 u.d = d;
2099 /* Detect special cases. */
2101 if (REAL_VALUES_IDENTICAL (dconst0, d))
2102 return CONST0_RTX (mode);
2103 /* Check for NaN first, because some ports (specifically the i386) do not
2104 emit correct ieee-fp code by default, and thus will generate a core
2105 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2106 does a floating point comparison. */
2107 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2108 return CONST1_RTX (mode);
2110 if (sizeof u == sizeof (HOST_WIDE_INT))
2111 return immed_double_const (u.i[0], 0, mode);
2112 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2113 return immed_double_const (u.i[0], u.i[1], mode);
2115 /* The rest of this function handles the case where
2116 a float value requires more than 2 ints of space.
2117 It will be deleted as dead code on machines that don't need it. */
2119 /* Search the chain for an existing CONST_DOUBLE with the right value.
2120 If one is found, return it. */
2122 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2123 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2124 && GET_MODE (r) == mode)
2125 return r;
2127 /* No; make a new one and add it to the chain.
2129 We may be called by an optimizer which may be discarding any memory
2130 allocated during its processing (such as combine and loop). However,
2131 we will be leaving this constant on the chain, so we cannot tolerate
2132 freed memory. So switch to saveable_obstack for this allocation
2133 and then switch back if we were in current_obstack. */
2135 push_obstacks_nochange ();
2136 rtl_in_saveable_obstack ();
2137 r = rtx_alloc (CONST_DOUBLE);
2138 PUT_MODE (r, mode);
2139 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2140 pop_obstacks ();
2142 /* Don't touch const_double_chain in nested function; see force_const_mem.
2143 Also, don't touch it if not inside any function. */
2144 if (outer_function_chain == 0 && current_function_decl != 0)
2146 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2147 const_double_chain = r;
2150 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2151 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2152 is only through force_const_mem. */
2154 CONST_DOUBLE_MEM (r) = const0_rtx;
2156 return r;
2159 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2160 which must be a REAL_CST tree node. */
2163 immed_real_const (exp)
2164 tree exp;
2166 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2169 /* At the end of a function, forget the memory-constants
2170 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2171 Also clear out real_constant_chain and clear out all the chain-pointers. */
2173 void
2174 clear_const_double_mem ()
2176 register rtx r, next;
2178 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2179 See force_const_mem for explanation. */
2180 if (outer_function_chain != 0)
2181 return;
2183 for (r = const_double_chain; r; r = next)
2185 next = CONST_DOUBLE_CHAIN (r);
2186 CONST_DOUBLE_CHAIN (r) = 0;
2187 CONST_DOUBLE_MEM (r) = cc0_rtx;
2189 const_double_chain = 0;
2192 /* Given an expression EXP with a constant value,
2193 reduce it to the sum of an assembler symbol and an integer.
2194 Store them both in the structure *VALUE.
2195 Abort if EXP does not reduce. */
2197 struct addr_const
2199 rtx base;
2200 HOST_WIDE_INT offset;
2203 static void
2204 decode_addr_const (exp, value)
2205 tree exp;
2206 struct addr_const *value;
2208 register tree target = TREE_OPERAND (exp, 0);
2209 register int offset = 0;
2210 register rtx x;
2212 while (1)
2214 if (TREE_CODE (target) == COMPONENT_REF
2215 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2216 == INTEGER_CST))
2218 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2219 target = TREE_OPERAND (target, 0);
2221 else if (TREE_CODE (target) == ARRAY_REF)
2223 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2224 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2225 abort ();
2226 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2227 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2228 / BITS_PER_UNIT);
2229 target = TREE_OPERAND (target, 0);
2231 else
2232 break;
2235 switch (TREE_CODE (target))
2237 case VAR_DECL:
2238 case FUNCTION_DECL:
2239 x = DECL_RTL (target);
2240 break;
2242 case LABEL_DECL:
2243 x = gen_rtx_MEM (FUNCTION_MODE,
2244 gen_rtx_LABEL_REF (VOIDmode,
2245 label_rtx (TREE_OPERAND (exp, 0))));
2246 break;
2248 case REAL_CST:
2249 case STRING_CST:
2250 case COMPLEX_CST:
2251 case CONSTRUCTOR:
2252 case INTEGER_CST:
2253 x = TREE_CST_RTL (target);
2254 break;
2256 default:
2257 abort ();
2260 if (GET_CODE (x) != MEM)
2261 abort ();
2262 x = XEXP (x, 0);
2264 value->base = x;
2265 value->offset = offset;
2268 /* Uniquize all constants that appear in memory.
2269 Each constant in memory thus far output is recorded
2270 in `const_hash_table' with a `struct constant_descriptor'
2271 that contains a polish representation of the value of
2272 the constant.
2274 We cannot store the trees in the hash table
2275 because the trees may be temporary. */
2277 struct constant_descriptor
2279 struct constant_descriptor *next;
2280 char *label;
2281 char contents[1];
2284 #define HASHBITS 30
2285 #define MAX_HASH_TABLE 1009
2286 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2288 /* Compute a hash code for a constant expression. */
2290 static int
2291 const_hash (exp)
2292 tree exp;
2294 register char *p;
2295 register int len, hi, i;
2296 register enum tree_code code = TREE_CODE (exp);
2298 /* Either set P and LEN to the address and len of something to hash and
2299 exit the switch or return a value. */
2301 switch (code)
2303 case INTEGER_CST:
2304 p = (char *) &TREE_INT_CST_LOW (exp);
2305 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2306 break;
2308 case REAL_CST:
2309 p = (char *) &TREE_REAL_CST (exp);
2310 len = sizeof TREE_REAL_CST (exp);
2311 break;
2313 case STRING_CST:
2314 p = TREE_STRING_POINTER (exp);
2315 len = TREE_STRING_LENGTH (exp);
2316 break;
2318 case COMPLEX_CST:
2319 return (const_hash (TREE_REALPART (exp)) * 5
2320 + const_hash (TREE_IMAGPART (exp)));
2322 case CONSTRUCTOR:
2323 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2325 len = int_size_in_bytes (TREE_TYPE (exp));
2326 p = (char *) alloca (len);
2327 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2328 break;
2330 else
2332 register tree link;
2334 /* For record type, include the type in the hashing.
2335 We do not do so for array types
2336 because (1) the sizes of the elements are sufficient
2337 and (2) distinct array types can have the same constructor.
2338 Instead, we include the array size because the constructor could
2339 be shorter. */
2340 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2341 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2342 % MAX_HASH_TABLE;
2343 else
2344 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2345 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2347 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2348 if (TREE_VALUE (link))
2350 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2352 return hi;
2355 case ADDR_EXPR:
2357 struct addr_const value;
2359 decode_addr_const (exp, &value);
2360 if (GET_CODE (value.base) == SYMBOL_REF)
2362 /* Don't hash the address of the SYMBOL_REF;
2363 only use the offset and the symbol name. */
2364 hi = value.offset;
2365 p = XSTR (value.base, 0);
2366 for (i = 0; p[i] != 0; i++)
2367 hi = ((hi * 613) + (unsigned) (p[i]));
2369 else if (GET_CODE (value.base) == LABEL_REF)
2370 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2371 else
2372 abort();
2374 hi &= (1 << HASHBITS) - 1;
2375 hi %= MAX_HASH_TABLE;
2377 return hi;
2379 case PLUS_EXPR:
2380 case MINUS_EXPR:
2381 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2382 + const_hash (TREE_OPERAND (exp, 1)));
2384 case NOP_EXPR:
2385 case CONVERT_EXPR:
2386 case NON_LVALUE_EXPR:
2387 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2389 default:
2390 abort ();
2393 /* Compute hashing function */
2394 hi = len;
2395 for (i = 0; i < len; i++)
2396 hi = ((hi * 613) + (unsigned) (p[i]));
2398 hi &= (1 << HASHBITS) - 1;
2399 hi %= MAX_HASH_TABLE;
2400 return hi;
2403 /* Compare a constant expression EXP with a constant-descriptor DESC.
2404 Return 1 if DESC describes a constant with the same value as EXP. */
2406 static int
2407 compare_constant (exp, desc)
2408 tree exp;
2409 struct constant_descriptor *desc;
2411 return 0 != compare_constant_1 (exp, desc->contents);
2414 /* Compare constant expression EXP with a substring P of a constant descriptor.
2415 If they match, return a pointer to the end of the substring matched.
2416 If they do not match, return 0.
2418 Since descriptors are written in polish prefix notation,
2419 this function can be used recursively to test one operand of EXP
2420 against a subdescriptor, and if it succeeds it returns the
2421 address of the subdescriptor for the next operand. */
2423 static char *
2424 compare_constant_1 (exp, p)
2425 tree exp;
2426 char *p;
2428 register char *strp;
2429 register int len;
2430 register enum tree_code code = TREE_CODE (exp);
2432 if (code != (enum tree_code) *p++)
2433 return 0;
2435 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2436 switch, or return the result of the comparison. */
2438 switch (code)
2440 case INTEGER_CST:
2441 /* Integer constants are the same only if the same width of type. */
2442 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2443 return 0;
2445 strp = (char *) &TREE_INT_CST_LOW (exp);
2446 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2447 break;
2449 case REAL_CST:
2450 /* Real constants are the same only if the same width of type. */
2451 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2452 return 0;
2454 strp = (char *) &TREE_REAL_CST (exp);
2455 len = sizeof TREE_REAL_CST (exp);
2456 break;
2458 case STRING_CST:
2459 if (flag_writable_strings)
2460 return 0;
2462 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2463 return 0;
2465 strp = TREE_STRING_POINTER (exp);
2466 len = TREE_STRING_LENGTH (exp);
2467 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2468 sizeof TREE_STRING_LENGTH (exp)))
2469 return 0;
2471 p += sizeof TREE_STRING_LENGTH (exp);
2472 break;
2474 case COMPLEX_CST:
2475 p = compare_constant_1 (TREE_REALPART (exp), p);
2476 if (p == 0)
2477 return 0;
2479 return compare_constant_1 (TREE_IMAGPART (exp), p);
2481 case CONSTRUCTOR:
2482 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2484 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2486 strp = (char *) alloca (len);
2487 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2488 if (bcmp ((char *) &xlen, p, sizeof xlen))
2489 return 0;
2491 p += sizeof xlen;
2492 break;
2494 else
2496 register tree link;
2497 int length = list_length (CONSTRUCTOR_ELTS (exp));
2498 tree type;
2499 int have_purpose = 0;
2501 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2502 if (TREE_PURPOSE (link))
2503 have_purpose = 1;
2505 if (bcmp ((char *) &length, p, sizeof length))
2506 return 0;
2508 p += sizeof length;
2510 /* For record constructors, insist that the types match.
2511 For arrays, just verify both constructors are for arrays.
2512 Then insist that either both or none have any TREE_PURPOSE
2513 values. */
2514 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2515 type = TREE_TYPE (exp);
2516 else
2517 type = 0;
2519 if (bcmp ((char *) &type, p, sizeof type))
2520 return 0;
2522 p += sizeof type;
2524 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2525 return 0;
2527 p += sizeof have_purpose;
2529 /* For arrays, insist that the size in bytes match. */
2530 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2532 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2534 if (bcmp ((char *) &size, p, sizeof size))
2535 return 0;
2537 p += sizeof size;
2540 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2542 if (TREE_VALUE (link))
2544 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2545 return 0;
2547 else
2549 tree zero = 0;
2551 if (bcmp ((char *) &zero, p, sizeof zero))
2552 return 0;
2554 p += sizeof zero;
2557 if (TREE_PURPOSE (link)
2558 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2560 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2561 sizeof TREE_PURPOSE (link)))
2562 return 0;
2564 p += sizeof TREE_PURPOSE (link);
2566 else if (TREE_PURPOSE (link))
2568 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2569 return 0;
2571 else if (have_purpose)
2573 int zero = 0;
2575 if (bcmp ((char *) &zero, p, sizeof zero))
2576 return 0;
2578 p += sizeof zero;
2582 return p;
2585 case ADDR_EXPR:
2587 struct addr_const value;
2589 decode_addr_const (exp, &value);
2590 strp = (char *) &value.offset;
2591 len = sizeof value.offset;
2592 /* Compare the offset. */
2593 while (--len >= 0)
2594 if (*p++ != *strp++)
2595 return 0;
2597 /* Compare symbol name. */
2598 strp = XSTR (value.base, 0);
2599 len = strlen (strp) + 1;
2601 break;
2603 case PLUS_EXPR:
2604 case MINUS_EXPR:
2605 case RANGE_EXPR:
2606 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2607 if (p == 0)
2608 return 0;
2610 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2612 case NOP_EXPR:
2613 case CONVERT_EXPR:
2614 case NON_LVALUE_EXPR:
2615 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2617 default:
2618 abort ();
2621 /* Compare constant contents. */
2622 while (--len >= 0)
2623 if (*p++ != *strp++)
2624 return 0;
2626 return p;
2629 /* Construct a constant descriptor for the expression EXP.
2630 It is up to the caller to enter the descriptor in the hash table. */
2632 static struct constant_descriptor *
2633 record_constant (exp)
2634 tree exp;
2636 struct constant_descriptor *next = 0;
2637 char *label = 0;
2639 /* Make a struct constant_descriptor. The first two pointers will
2640 be filled in later. Here we just leave space for them. */
2642 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2643 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2644 record_constant_1 (exp);
2645 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2648 /* Add a description of constant expression EXP
2649 to the object growing in `permanent_obstack'.
2650 No need to return its address; the caller will get that
2651 from the obstack when the object is complete. */
2653 static void
2654 record_constant_1 (exp)
2655 tree exp;
2657 register char *strp;
2658 register int len;
2659 register enum tree_code code = TREE_CODE (exp);
2661 obstack_1grow (&permanent_obstack, (unsigned int) code);
2663 switch (code)
2665 case INTEGER_CST:
2666 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2667 strp = (char *) &TREE_INT_CST_LOW (exp);
2668 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2669 break;
2671 case REAL_CST:
2672 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2673 strp = (char *) &TREE_REAL_CST (exp);
2674 len = sizeof TREE_REAL_CST (exp);
2675 break;
2677 case STRING_CST:
2678 if (flag_writable_strings)
2679 return;
2681 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2682 strp = TREE_STRING_POINTER (exp);
2683 len = TREE_STRING_LENGTH (exp);
2684 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2685 sizeof TREE_STRING_LENGTH (exp));
2686 break;
2688 case COMPLEX_CST:
2689 record_constant_1 (TREE_REALPART (exp));
2690 record_constant_1 (TREE_IMAGPART (exp));
2691 return;
2693 case CONSTRUCTOR:
2694 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2696 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2697 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2698 obstack_blank (&permanent_obstack, nbytes);
2699 get_set_constructor_bytes
2700 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2701 nbytes);
2702 return;
2704 else
2706 register tree link;
2707 int length = list_length (CONSTRUCTOR_ELTS (exp));
2708 tree type;
2709 int have_purpose = 0;
2711 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2712 if (TREE_PURPOSE (link))
2713 have_purpose = 1;
2715 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2717 /* For record constructors, insist that the types match.
2718 For arrays, just verify both constructors are for arrays.
2719 Then insist that either both or none have any TREE_PURPOSE
2720 values. */
2721 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2722 type = TREE_TYPE (exp);
2723 else
2724 type = 0;
2725 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2726 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2727 sizeof have_purpose);
2729 /* For arrays, insist that the size in bytes match. */
2730 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2732 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2733 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2736 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2738 if (TREE_VALUE (link))
2739 record_constant_1 (TREE_VALUE (link));
2740 else
2742 tree zero = 0;
2744 obstack_grow (&permanent_obstack,
2745 (char *) &zero, sizeof zero);
2748 if (TREE_PURPOSE (link)
2749 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2750 obstack_grow (&permanent_obstack,
2751 (char *) &TREE_PURPOSE (link),
2752 sizeof TREE_PURPOSE (link));
2753 else if (TREE_PURPOSE (link))
2754 record_constant_1 (TREE_PURPOSE (link));
2755 else if (have_purpose)
2757 int zero = 0;
2759 obstack_grow (&permanent_obstack,
2760 (char *) &zero, sizeof zero);
2764 return;
2766 case ADDR_EXPR:
2768 struct addr_const value;
2770 decode_addr_const (exp, &value);
2771 /* Record the offset. */
2772 obstack_grow (&permanent_obstack,
2773 (char *) &value.offset, sizeof value.offset);
2774 /* Record the symbol name. */
2775 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2776 strlen (XSTR (value.base, 0)) + 1);
2778 return;
2780 case PLUS_EXPR:
2781 case MINUS_EXPR:
2782 case RANGE_EXPR:
2783 record_constant_1 (TREE_OPERAND (exp, 0));
2784 record_constant_1 (TREE_OPERAND (exp, 1));
2785 return;
2787 case NOP_EXPR:
2788 case CONVERT_EXPR:
2789 case NON_LVALUE_EXPR:
2790 record_constant_1 (TREE_OPERAND (exp, 0));
2791 return;
2793 default:
2794 abort ();
2797 /* Record constant contents. */
2798 obstack_grow (&permanent_obstack, strp, len);
2801 /* Record a list of constant expressions that were passed to
2802 output_constant_def but that could not be output right away. */
2804 struct deferred_constant
2806 struct deferred_constant *next;
2807 tree exp;
2808 int reloc;
2809 int labelno;
2812 static struct deferred_constant *deferred_constants;
2814 /* Another list of constants which should be output after the
2815 function. */
2816 static struct deferred_constant *after_function_constants;
2818 /* Nonzero means defer output of addressed subconstants
2819 (i.e., those for which output_constant_def is called.) */
2820 static int defer_addressed_constants_flag;
2822 /* Start deferring output of subconstants. */
2824 void
2825 defer_addressed_constants ()
2827 defer_addressed_constants_flag++;
2830 /* Stop deferring output of subconstants,
2831 and output now all those that have been deferred. */
2833 void
2834 output_deferred_addressed_constants ()
2836 struct deferred_constant *p, *next;
2838 defer_addressed_constants_flag--;
2840 if (defer_addressed_constants_flag > 0)
2841 return;
2843 for (p = deferred_constants; p; p = next)
2845 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2846 next = p->next;
2847 free (p);
2850 deferred_constants = 0;
2853 /* Output any constants which should appear after a function. */
2855 static void
2856 output_after_function_constants ()
2858 struct deferred_constant *p, *next;
2860 for (p = after_function_constants; p; p = next)
2862 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2863 next = p->next;
2864 free (p);
2867 after_function_constants = 0;
2870 /* Make a copy of the whole tree structure for a constant.
2871 This handles the same types of nodes that compare_constant
2872 and record_constant handle. */
2874 static tree
2875 copy_constant (exp)
2876 tree exp;
2878 switch (TREE_CODE (exp))
2880 case ADDR_EXPR:
2881 /* For ADDR_EXPR, we do not want to copy the decl whose address
2882 is requested. We do want to copy constants though. */
2883 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2884 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2885 copy_constant (TREE_OPERAND (exp, 0)));
2886 else
2887 return copy_node (exp);
2889 case INTEGER_CST:
2890 case REAL_CST:
2891 case STRING_CST:
2892 return copy_node (exp);
2894 case COMPLEX_CST:
2895 return build_complex (TREE_TYPE (exp),
2896 copy_constant (TREE_REALPART (exp)),
2897 copy_constant (TREE_IMAGPART (exp)));
2899 case PLUS_EXPR:
2900 case MINUS_EXPR:
2901 return build (TREE_CODE (exp), TREE_TYPE (exp),
2902 copy_constant (TREE_OPERAND (exp, 0)),
2903 copy_constant (TREE_OPERAND (exp, 1)));
2905 case NOP_EXPR:
2906 case CONVERT_EXPR:
2907 case NON_LVALUE_EXPR:
2908 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2909 copy_constant (TREE_OPERAND (exp, 0)));
2911 case CONSTRUCTOR:
2913 tree copy = copy_node (exp);
2914 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2915 tree tail;
2917 CONSTRUCTOR_ELTS (copy) = list;
2918 for (tail = list; tail; tail = TREE_CHAIN (tail))
2919 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2920 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2921 for (tail = list; tail; tail = TREE_CHAIN (tail))
2922 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2924 return copy;
2927 default:
2928 abort ();
2932 /* Return an rtx representing a reference to constant data in memory
2933 for the constant expression EXP.
2935 If assembler code for such a constant has already been output,
2936 return an rtx to refer to it.
2937 Otherwise, output such a constant in memory (or defer it for later)
2938 and generate an rtx for it.
2940 The TREE_CST_RTL of EXP is set up to point to that rtx.
2941 The const_hash_table records which constants already have label strings. */
2944 output_constant_def (exp)
2945 tree exp;
2947 register int hash;
2948 register struct constant_descriptor *desc;
2949 char label[256];
2950 char *found = 0;
2951 int reloc;
2952 register rtx def;
2954 if (TREE_CST_RTL (exp))
2955 return TREE_CST_RTL (exp);
2957 /* Make sure any other constants whose addresses appear in EXP
2958 are assigned label numbers. */
2960 reloc = output_addressed_constants (exp);
2962 /* Compute hash code of EXP. Search the descriptors for that hash code
2963 to see if any of them describes EXP. If yes, the descriptor records
2964 the label number already assigned. */
2966 hash = const_hash (exp) % MAX_HASH_TABLE;
2968 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2969 if (compare_constant (exp, desc))
2971 found = desc->label;
2972 break;
2975 if (found == 0)
2977 /* No constant equal to EXP is known to have been output.
2978 Make a constant descriptor to enter EXP in the hash table.
2979 Assign the label number and record it in the descriptor for
2980 future calls to this function to find. */
2982 /* Create a string containing the label name, in LABEL. */
2983 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2985 desc = record_constant (exp);
2986 desc->next = const_hash_table[hash];
2987 desc->label
2988 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2989 const_hash_table[hash] = desc;
2991 else
2993 /* Create a string containing the label name, in LABEL. */
2994 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2997 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2999 push_obstacks_nochange ();
3000 if (TREE_PERMANENT (exp))
3001 end_temporary_allocation ();
3003 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
3005 TREE_CST_RTL (exp)
3006 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
3007 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
3008 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
3009 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
3011 pop_obstacks ();
3013 /* Optionally set flags or add text to the name to record information
3014 such as that it is a function name. If the name is changed, the macro
3015 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3016 #ifdef ENCODE_SECTION_INFO
3017 ENCODE_SECTION_INFO (exp);
3018 #endif
3020 /* If this is the first time we've seen this particular constant,
3021 output it (or defer its output for later). */
3022 if (found == 0)
3024 int after_function = 0;
3026 #ifdef CONSTANT_AFTER_FUNCTION_P
3027 if (current_function_decl != 0
3028 && CONSTANT_AFTER_FUNCTION_P (exp))
3029 after_function = 1;
3030 #endif
3032 if (defer_addressed_constants_flag || after_function)
3034 struct deferred_constant *p;
3035 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3037 push_obstacks_nochange ();
3038 suspend_momentary ();
3039 p->exp = copy_constant (exp);
3040 pop_obstacks ();
3041 p->reloc = reloc;
3042 p->labelno = const_labelno++;
3043 if (after_function)
3045 p->next = after_function_constants;
3046 after_function_constants = p;
3048 else
3050 p->next = deferred_constants;
3051 deferred_constants = p;
3054 else
3056 /* Do no output if -fsyntax-only. */
3057 if (! flag_syntax_only)
3058 output_constant_def_contents (exp, reloc, const_labelno);
3059 ++const_labelno;
3063 return TREE_CST_RTL (exp);
3066 /* Now output assembler code to define the label for EXP,
3067 and follow it with the data of EXP. */
3069 static void
3070 output_constant_def_contents (exp, reloc, labelno)
3071 tree exp;
3072 int reloc;
3073 int labelno;
3075 int align;
3077 if (IN_NAMED_SECTION (exp))
3078 named_section (exp, NULL, reloc);
3079 else
3081 /* First switch to text section, except for writable strings. */
3082 #ifdef SELECT_SECTION
3083 SELECT_SECTION (exp, reloc);
3084 #else
3085 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3086 || (flag_pic && reloc))
3087 data_section ();
3088 else
3089 readonly_data_section ();
3090 #endif
3093 /* Align the location counter as required by EXP's data type. */
3094 align = TYPE_ALIGN (TREE_TYPE (exp));
3095 #ifdef CONSTANT_ALIGNMENT
3096 align = CONSTANT_ALIGNMENT (exp, align);
3097 #endif
3099 if (align > BITS_PER_UNIT)
3100 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3102 /* Output the label itself. */
3103 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3105 /* Output the value of EXP. */
3106 output_constant (exp,
3107 (TREE_CODE (exp) == STRING_CST
3108 ? TREE_STRING_LENGTH (exp)
3109 : int_size_in_bytes (TREE_TYPE (exp))));
3113 /* Similar hash facility for making memory-constants
3114 from constant rtl-expressions. It is used on RISC machines
3115 where immediate integer arguments and constant addresses are restricted
3116 so that such constants must be stored in memory.
3118 This pool of constants is reinitialized for each function
3119 so each function gets its own constants-pool that comes right before it.
3121 All structures allocated here are discarded when functions are saved for
3122 inlining, so they do not need to be allocated permanently. */
3124 #define MAX_RTX_HASH_TABLE 61
3125 static struct constant_descriptor **const_rtx_hash_table;
3127 /* Structure to represent sufficient information about a constant so that
3128 it can be output when the constant pool is output, so that function
3129 integration can be done, and to simplify handling on machines that reference
3130 constant pool as base+displacement. */
3132 struct pool_constant
3134 struct constant_descriptor *desc;
3135 struct pool_constant *next;
3136 enum machine_mode mode;
3137 rtx constant;
3138 int labelno;
3139 int align;
3140 int offset;
3141 int mark;
3144 /* Pointers to first and last constant in pool. */
3146 static struct pool_constant *first_pool, *last_pool;
3148 /* Current offset in constant pool (does not include any machine-specific
3149 header. */
3151 static int pool_offset;
3153 /* Structure used to maintain hash table mapping symbols used to their
3154 corresponding constants. */
3156 struct pool_sym
3158 char *label;
3159 struct pool_constant *pool;
3160 struct pool_sym *next;
3163 static struct pool_sym **const_rtx_sym_hash_table;
3165 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3166 The argument is XSTR (... , 0) */
3168 #define SYMHASH(LABEL) \
3169 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3171 /* Initialize constant pool hashing for next function. */
3173 void
3174 init_const_rtx_hash_table ()
3176 const_rtx_hash_table
3177 = ((struct constant_descriptor **)
3178 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3179 const_rtx_sym_hash_table
3180 = ((struct pool_sym **)
3181 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3182 bzero ((char *) const_rtx_hash_table,
3183 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3184 bzero ((char *) const_rtx_sym_hash_table,
3185 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3187 first_pool = last_pool = 0;
3188 pool_offset = 0;
3191 /* Save and restore status for a nested function. */
3193 void
3194 save_varasm_status (p, context)
3195 struct function *p;
3196 tree context;
3198 p->const_rtx_hash_table = const_rtx_hash_table;
3199 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3200 p->first_pool = first_pool;
3201 p->last_pool = last_pool;
3202 p->pool_offset = pool_offset;
3203 p->const_double_chain = const_double_chain;
3205 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3206 if (context == NULL_TREE)
3207 const_double_chain = 0;
3210 void
3211 restore_varasm_status (p)
3212 struct function *p;
3214 const_rtx_hash_table = p->const_rtx_hash_table;
3215 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3216 first_pool = p->first_pool;
3217 last_pool = p->last_pool;
3218 pool_offset = p->pool_offset;
3219 const_double_chain = p->const_double_chain;
3222 enum kind { RTX_DOUBLE, RTX_INT };
3224 struct rtx_const
3226 #ifdef ONLY_INT_FIELDS
3227 unsigned int kind : 16;
3228 unsigned int mode : 16;
3229 #else
3230 enum kind kind : 16;
3231 enum machine_mode mode : 16;
3232 #endif
3233 union {
3234 union real_extract du;
3235 struct addr_const addr;
3236 struct {HOST_WIDE_INT high, low;} di;
3237 } un;
3240 /* Express an rtx for a constant integer (perhaps symbolic)
3241 as the sum of a symbol or label plus an explicit integer.
3242 They are stored into VALUE. */
3244 static void
3245 decode_rtx_const (mode, x, value)
3246 enum machine_mode mode;
3247 rtx x;
3248 struct rtx_const *value;
3250 /* Clear the whole structure, including any gaps. */
3253 int *p = (int *) value;
3254 int *end = (int *) (value + 1);
3255 while (p < end)
3256 *p++ = 0;
3259 value->kind = RTX_INT; /* Most usual kind. */
3260 value->mode = mode;
3262 switch (GET_CODE (x))
3264 case CONST_DOUBLE:
3265 value->kind = RTX_DOUBLE;
3266 if (GET_MODE (x) != VOIDmode)
3268 value->mode = GET_MODE (x);
3269 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3270 (char *) &value->un.du, sizeof value->un.du);
3272 else
3274 value->un.di.low = CONST_DOUBLE_LOW (x);
3275 value->un.di.high = CONST_DOUBLE_HIGH (x);
3277 break;
3279 case CONST_INT:
3280 value->un.addr.offset = INTVAL (x);
3281 break;
3283 case SYMBOL_REF:
3284 case LABEL_REF:
3285 case PC:
3286 value->un.addr.base = x;
3287 break;
3289 case CONST:
3290 x = XEXP (x, 0);
3291 if (GET_CODE (x) == PLUS)
3293 value->un.addr.base = XEXP (x, 0);
3294 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3295 abort ();
3296 value->un.addr.offset = INTVAL (XEXP (x, 1));
3298 else if (GET_CODE (x) == MINUS)
3300 value->un.addr.base = XEXP (x, 0);
3301 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3302 abort ();
3303 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3305 else
3306 abort ();
3307 break;
3309 default:
3310 abort ();
3313 if (value->kind == RTX_INT && value->un.addr.base != 0)
3314 switch (GET_CODE (value->un.addr.base))
3316 case SYMBOL_REF:
3317 case LABEL_REF:
3318 /* Use the string's address, not the SYMBOL_REF's address,
3319 for the sake of addresses of library routines.
3320 For a LABEL_REF, compare labels. */
3321 value->un.addr.base = XEXP (value->un.addr.base, 0);
3323 default:
3324 break;
3328 /* Given a MINUS expression, simplify it if both sides
3329 include the same symbol. */
3332 simplify_subtraction (x)
3333 rtx x;
3335 struct rtx_const val0, val1;
3337 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3338 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3340 if (val0.un.addr.base == val1.un.addr.base)
3341 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3342 return x;
3345 /* Compute a hash code for a constant RTL expression. */
3347 static int
3348 const_hash_rtx (mode, x)
3349 enum machine_mode mode;
3350 rtx x;
3352 register int hi;
3353 register size_t i;
3355 struct rtx_const value;
3356 decode_rtx_const (mode, x, &value);
3358 /* Compute hashing function */
3359 hi = 0;
3360 for (i = 0; i < sizeof value / sizeof (int); i++)
3361 hi += ((int *) &value)[i];
3363 hi &= (1 << HASHBITS) - 1;
3364 hi %= MAX_RTX_HASH_TABLE;
3365 return hi;
3368 /* Compare a constant rtl object X with a constant-descriptor DESC.
3369 Return 1 if DESC describes a constant with the same value as X. */
3371 static int
3372 compare_constant_rtx (mode, x, desc)
3373 enum machine_mode mode;
3374 rtx x;
3375 struct constant_descriptor *desc;
3377 register int *p = (int *) desc->contents;
3378 register int *strp;
3379 register int len;
3380 struct rtx_const value;
3382 decode_rtx_const (mode, x, &value);
3383 strp = (int *) &value;
3384 len = sizeof value / sizeof (int);
3386 /* Compare constant contents. */
3387 while (--len >= 0)
3388 if (*p++ != *strp++)
3389 return 0;
3391 return 1;
3394 /* Construct a constant descriptor for the rtl-expression X.
3395 It is up to the caller to enter the descriptor in the hash table. */
3397 static struct constant_descriptor *
3398 record_constant_rtx (mode, x)
3399 enum machine_mode mode;
3400 rtx x;
3402 struct constant_descriptor *ptr;
3403 char *label;
3404 struct rtx_const value;
3406 decode_rtx_const (mode, x, &value);
3408 /* Put these things in the saveable obstack so we can ensure it won't
3409 be freed if we are called from combine or some other phase that discards
3410 memory allocated from function_obstack (current_obstack). */
3411 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3412 obstack_grow (saveable_obstack, &label, sizeof label);
3414 /* Record constant contents. */
3415 obstack_grow (saveable_obstack, &value, sizeof value);
3417 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3420 /* Given a constant rtx X, make (or find) a memory constant for its value
3421 and return a MEM rtx to refer to it in memory. */
3424 force_const_mem (mode, x)
3425 enum machine_mode mode;
3426 rtx x;
3428 register int hash;
3429 register struct constant_descriptor *desc;
3430 char label[256];
3431 char *found = 0;
3432 rtx def;
3434 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3435 (this will always be true for floating CONST_DOUBLEs that have been
3436 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3437 use the previous copy. Otherwise, make a new one. Note that in
3438 the unlikely event that this same CONST_DOUBLE is used in two different
3439 modes in an alternating fashion, we will allocate a lot of different
3440 memory locations, but this should be extremely rare. */
3442 /* Don't use CONST_DOUBLE_MEM in a nested function.
3443 Nested functions have their own constant pools,
3444 so they can't share the same values in CONST_DOUBLE_MEM
3445 with the containing function. */
3446 if (outer_function_chain == 0)
3447 if (GET_CODE (x) == CONST_DOUBLE
3448 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3449 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3450 return CONST_DOUBLE_MEM (x);
3452 /* Compute hash code of X. Search the descriptors for that hash code
3453 to see if any of them describes X. If yes, the descriptor records
3454 the label number already assigned. */
3456 hash = const_hash_rtx (mode, x);
3458 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3459 if (compare_constant_rtx (mode, x, desc))
3461 found = desc->label;
3462 break;
3465 if (found == 0)
3467 register struct pool_constant *pool;
3468 register struct pool_sym *sym;
3469 int align;
3471 /* No constant equal to X is known to have been output.
3472 Make a constant descriptor to enter X in the hash table.
3473 Assign the label number and record it in the descriptor for
3474 future calls to this function to find. */
3476 desc = record_constant_rtx (mode, x);
3477 desc->next = const_rtx_hash_table[hash];
3478 const_rtx_hash_table[hash] = desc;
3480 /* Align the location counter as required by EXP's data type. */
3481 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3482 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3483 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3484 #ifdef CONSTANT_ALIGNMENT
3485 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3486 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3487 #endif
3489 pool_offset += align - 1;
3490 pool_offset &= ~ (align - 1);
3492 /* If RTL is not being placed into the saveable obstack, make a
3493 copy of X that is in the saveable obstack in case we are
3494 being called from combine or some other phase that discards
3495 memory it allocates. We used to only do this if it is a
3496 CONST; however, reload can allocate a CONST_INT when
3497 eliminating registers. */
3498 if (rtl_obstack != saveable_obstack
3499 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3501 push_obstacks_nochange ();
3502 rtl_in_saveable_obstack ();
3504 if (GET_CODE (x) == CONST)
3505 x = gen_rtx_CONST (GET_MODE (x),
3506 gen_rtx_PLUS (GET_MODE (x),
3507 XEXP (XEXP (x, 0), 0),
3508 XEXP (XEXP (x, 0), 1)));
3509 else
3510 x = GEN_INT (INTVAL (x));
3512 pop_obstacks ();
3515 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3517 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3518 pool->desc = desc;
3519 pool->constant = x;
3520 pool->mode = mode;
3521 pool->labelno = const_labelno;
3522 pool->align = align;
3523 pool->offset = pool_offset;
3524 pool->mark = 1;
3525 pool->next = 0;
3527 if (last_pool == 0)
3528 first_pool = pool;
3529 else
3530 last_pool->next = pool;
3532 last_pool = pool;
3533 pool_offset += GET_MODE_SIZE (mode);
3535 /* Create a string containing the label name, in LABEL. */
3536 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3538 ++const_labelno;
3540 desc->label = found
3541 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3543 /* Add label to symbol hash table. */
3544 hash = SYMHASH (found);
3545 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3546 sym->label = found;
3547 sym->pool = pool;
3548 sym->next = const_rtx_sym_hash_table[hash];
3549 const_rtx_sym_hash_table[hash] = sym;
3552 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3554 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3556 RTX_UNCHANGING_P (def) = 1;
3557 /* Mark the symbol_ref as belonging to this constants pool. */
3558 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3559 current_function_uses_const_pool = 1;
3561 if (outer_function_chain == 0)
3562 if (GET_CODE (x) == CONST_DOUBLE)
3564 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3566 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3567 const_double_chain = x;
3569 CONST_DOUBLE_MEM (x) = def;
3572 return def;
3575 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3576 the corresponding pool_constant structure. */
3578 static struct pool_constant *
3579 find_pool_constant (addr)
3580 rtx addr;
3582 struct pool_sym *sym;
3583 char *label = XSTR (addr, 0);
3585 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3586 if (sym->label == label)
3587 return sym->pool;
3589 abort ();
3592 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3595 get_pool_constant (addr)
3596 rtx addr;
3598 return (find_pool_constant (addr))->constant;
3601 /* Similar, return the mode. */
3603 enum machine_mode
3604 get_pool_mode (addr)
3605 rtx addr;
3607 return (find_pool_constant (addr))->mode;
3610 /* Similar, return the offset in the constant pool. */
3613 get_pool_offset (addr)
3614 rtx addr;
3616 return (find_pool_constant (addr))->offset;
3619 /* Return the size of the constant pool. */
3622 get_pool_size ()
3624 return pool_offset;
3627 /* Write all the constants in the constant pool. */
3629 void
3630 output_constant_pool (fnname, fndecl)
3631 char *fnname ATTRIBUTE_UNUSED;
3632 tree fndecl ATTRIBUTE_UNUSED;
3634 struct pool_constant *pool;
3635 rtx x;
3636 union real_extract u;
3638 /* It is possible for gcc to call force_const_mem and then to later
3639 discard the instructions which refer to the constant. In such a
3640 case we do not need to output the constant. */
3641 mark_constant_pool ();
3643 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3644 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3645 #endif
3647 for (pool = first_pool; pool; pool = pool->next)
3649 x = pool->constant;
3651 if (! pool->mark)
3652 continue;
3654 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3655 whose CODE_LABEL has been deleted. This can occur if a jump table
3656 is eliminated by optimization. If so, write a constant of zero
3657 instead. Note that this can also happen by turning the
3658 CODE_LABEL into a NOTE. */
3659 if (((GET_CODE (x) == LABEL_REF
3660 && (INSN_DELETED_P (XEXP (x, 0))
3661 || GET_CODE (XEXP (x, 0)) == NOTE)))
3662 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3663 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3664 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3665 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3666 x = const0_rtx;
3668 /* First switch to correct section. */
3669 #ifdef SELECT_RTX_SECTION
3670 SELECT_RTX_SECTION (pool->mode, x);
3671 #else
3672 readonly_data_section ();
3673 #endif
3675 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3676 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3677 pool->align, pool->labelno, done);
3678 #endif
3680 if (pool->align > 1)
3681 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3683 /* Output the label. */
3684 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3686 /* Output the value of the constant itself. */
3687 switch (GET_MODE_CLASS (pool->mode))
3689 case MODE_FLOAT:
3690 if (GET_CODE (x) != CONST_DOUBLE)
3691 abort ();
3693 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3694 assemble_real (u.d, pool->mode);
3695 break;
3697 case MODE_INT:
3698 case MODE_PARTIAL_INT:
3699 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3700 break;
3702 default:
3703 abort ();
3706 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3707 done: ;
3708 #endif
3712 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3713 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3714 #endif
3716 /* Done with this pool. */
3717 first_pool = last_pool = 0;
3720 /* Look through the instructions for this function, and mark all the
3721 entries in the constant pool which are actually being used. */
3723 static void
3724 mark_constant_pool ()
3726 register rtx insn;
3727 struct pool_constant *pool;
3729 if (first_pool == 0)
3730 return;
3732 for (pool = first_pool; pool; pool = pool->next)
3733 pool->mark = 0;
3735 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3736 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3737 mark_constants (PATTERN (insn));
3739 for (insn = current_function_epilogue_delay_list;
3740 insn;
3741 insn = XEXP (insn, 1))
3742 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3743 mark_constants (PATTERN (insn));
3745 /* It's possible that the only reference to a symbol is in a symbol
3746 that's in the constant pool. This happens in Fortran under some
3747 situations. (When the constant contains the address of another
3748 constant, and only the first is used directly in an insn.)
3749 This is potentially suboptimal if there's ever a possibility of
3750 backwards (in pool order) 2'd level references. However, it's
3751 not clear that 2'd level references can happen. */
3752 for (pool = first_pool; pool; pool = pool->next)
3754 struct pool_sym *sym;
3755 char *label;
3757 /* skip unmarked entries; no insn refers to them. */
3758 if (!pool->mark)
3759 continue;
3761 /* skip CONST_DOUBLEs too - correct? */
3762 if (GET_CODE (pool->constant) == CONST_DOUBLE)
3763 continue;
3764 label = XSTR (pool->constant, 0);
3766 /* Be sure the symbol's value is marked. */
3767 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3768 sym = sym->next)
3769 if (sym->label == label)
3770 sym->pool->mark = 1;
3771 /* If we didn't find it, there's something truly wrong here, but it
3772 will be announced by the assembler. */
3776 static void
3777 mark_constants (x)
3778 register rtx x;
3780 register int i;
3781 register const char *format_ptr;
3783 if (x == 0)
3784 return;
3786 if (GET_CODE (x) == SYMBOL_REF)
3788 if (CONSTANT_POOL_ADDRESS_P (x))
3789 find_pool_constant (x)->mark = 1;
3790 return;
3792 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3793 a MEM, but does not constitute a use of that MEM. This is particularly
3794 important inside a nested function, because CONST_DOUBLE_MEM may be
3795 a reference to a MEM in the parent's constant pool. See the comment
3796 in force_const_mem. */
3797 else if (GET_CODE (x) == CONST_DOUBLE)
3798 return;
3800 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3801 insns, not any notes that may be attached. We don't want to mark
3802 a constant just because it happens to appear in a REG_EQUIV note. */
3803 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3805 mark_constants (PATTERN (x));
3806 return;
3809 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3811 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3813 switch (*format_ptr++)
3815 case 'e':
3816 mark_constants (XEXP (x, i));
3817 break;
3819 case 'E':
3820 if (XVEC (x, i) != 0)
3822 register int j;
3824 for (j = 0; j < XVECLEN (x, i); j++)
3825 mark_constants (XVECEXP (x, i, j));
3827 break;
3829 case 'S':
3830 case 's':
3831 case '0':
3832 case 'i':
3833 case 'w':
3834 case 'n':
3835 case 'u':
3836 break;
3838 default:
3839 abort ();
3844 /* Find all the constants whose addresses are referenced inside of EXP,
3845 and make sure assembler code with a label has been output for each one.
3846 Indicate whether an ADDR_EXPR has been encountered. */
3848 static int
3849 output_addressed_constants (exp)
3850 tree exp;
3852 int reloc = 0;
3854 switch (TREE_CODE (exp))
3856 case ADDR_EXPR:
3858 register tree constant = TREE_OPERAND (exp, 0);
3860 while (TREE_CODE (constant) == COMPONENT_REF)
3862 constant = TREE_OPERAND (constant, 0);
3865 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3866 || TREE_CODE (constant) == CONSTRUCTOR)
3867 /* No need to do anything here
3868 for addresses of variables or functions. */
3869 output_constant_def (constant);
3871 reloc = 1;
3872 break;
3874 case PLUS_EXPR:
3875 case MINUS_EXPR:
3876 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3877 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3878 break;
3880 case NOP_EXPR:
3881 case CONVERT_EXPR:
3882 case NON_LVALUE_EXPR:
3883 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3884 break;
3886 case CONSTRUCTOR:
3888 register tree link;
3889 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3890 if (TREE_VALUE (link) != 0)
3891 reloc |= output_addressed_constants (TREE_VALUE (link));
3893 break;
3895 default:
3896 break;
3898 return reloc;
3901 /* Output assembler code for constant EXP to FILE, with no label.
3902 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3903 Assumes output_addressed_constants has been done on EXP already.
3905 Generate exactly SIZE bytes of assembler data, padding at the end
3906 with zeros if necessary. SIZE must always be specified.
3908 SIZE is important for structure constructors,
3909 since trailing members may have been omitted from the constructor.
3910 It is also important for initialization of arrays from string constants
3911 since the full length of the string constant might not be wanted.
3912 It is also needed for initialization of unions, where the initializer's
3913 type is just one member, and that may not be as long as the union.
3915 There a case in which we would fail to output exactly SIZE bytes:
3916 for a structure constructor that wants to produce more than SIZE bytes.
3917 But such constructors will never be generated for any possible input. */
3919 void
3920 output_constant (exp, size)
3921 register tree exp;
3922 register int size;
3924 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3926 /* Some front-ends use constants other than the standard
3927 language-indepdent varieties, but which may still be output
3928 directly. Give the front-end a chance to convert EXP to a
3929 language-independent representation. */
3930 if (lang_expand_constant)
3931 exp = (*lang_expand_constant) (exp);
3933 if (size == 0 || flag_syntax_only)
3934 return;
3936 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3937 That way we get the constant (we hope) inside it. Also, strip off any
3938 NOP_EXPR that converts between two record, union, array, or set types. */
3939 while ((TREE_CODE (exp) == NOP_EXPR
3940 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3941 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3942 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3943 exp = TREE_OPERAND (exp, 0);
3945 /* Allow a constructor with no elements for any data type.
3946 This means to fill the space with zeros. */
3947 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3949 assemble_zeros (size);
3950 return;
3953 switch (code)
3955 case CHAR_TYPE:
3956 case BOOLEAN_TYPE:
3957 case INTEGER_TYPE:
3958 case ENUMERAL_TYPE:
3959 case POINTER_TYPE:
3960 case REFERENCE_TYPE:
3961 /* ??? What about (int)((float)(int)&foo + 4) */
3962 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3963 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3964 exp = TREE_OPERAND (exp, 0);
3966 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3967 EXPAND_INITIALIZER),
3968 size, 0))
3969 error ("initializer for integer value is too complicated");
3970 size = 0;
3971 break;
3973 case REAL_TYPE:
3974 if (TREE_CODE (exp) != REAL_CST)
3975 error ("initializer for floating value is not a floating constant");
3977 assemble_real (TREE_REAL_CST (exp),
3978 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3979 size = 0;
3980 break;
3982 case COMPLEX_TYPE:
3983 output_constant (TREE_REALPART (exp), size / 2);
3984 output_constant (TREE_IMAGPART (exp), size / 2);
3985 size -= (size / 2) * 2;
3986 break;
3988 case ARRAY_TYPE:
3989 if (TREE_CODE (exp) == CONSTRUCTOR)
3991 output_constructor (exp, size);
3992 return;
3994 else if (TREE_CODE (exp) == STRING_CST)
3996 int excess = 0;
3998 if (size > TREE_STRING_LENGTH (exp))
4000 excess = size - TREE_STRING_LENGTH (exp);
4001 size = TREE_STRING_LENGTH (exp);
4004 assemble_string (TREE_STRING_POINTER (exp), size);
4005 size = excess;
4007 else
4008 abort ();
4009 break;
4011 case RECORD_TYPE:
4012 case UNION_TYPE:
4013 if (TREE_CODE (exp) == CONSTRUCTOR)
4014 output_constructor (exp, size);
4015 else
4016 abort ();
4017 return;
4019 case SET_TYPE:
4020 if (TREE_CODE (exp) == INTEGER_CST)
4021 assemble_integer (expand_expr (exp, NULL_RTX,
4022 VOIDmode, EXPAND_INITIALIZER),
4023 size, 1);
4024 else if (TREE_CODE (exp) == CONSTRUCTOR)
4026 unsigned char *buffer = (unsigned char *) alloca (size);
4027 if (get_set_constructor_bytes (exp, buffer, size))
4028 abort ();
4029 assemble_string ((char *) buffer, size);
4031 else
4032 error ("unknown set constructor type");
4033 return;
4035 default:
4036 break; /* ??? */
4039 if (size > 0)
4040 assemble_zeros (size);
4044 /* Subroutine of output_constant, used for CONSTRUCTORs
4045 (aggregate constants).
4046 Generate at least SIZE bytes, padding if necessary. */
4048 static void
4049 output_constructor (exp, size)
4050 tree exp;
4051 int size;
4053 register tree link, field = 0;
4054 HOST_WIDE_INT min_index = 0;
4055 /* Number of bytes output or skipped so far.
4056 In other words, current position within the constructor. */
4057 int total_bytes = 0;
4058 /* Non-zero means BYTE contains part of a byte, to be output. */
4059 int byte_buffer_in_use = 0;
4060 register int byte;
4062 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4063 abort ();
4065 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4066 field = TYPE_FIELDS (TREE_TYPE (exp));
4068 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4069 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4070 min_index
4071 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4073 /* As LINK goes through the elements of the constant,
4074 FIELD goes through the structure fields, if the constant is a structure.
4075 if the constant is a union, then we override this,
4076 by getting the field from the TREE_LIST element.
4077 But the constant could also be an array. Then FIELD is zero.
4079 There is always a maximum of one element in the chain LINK for unions
4080 (even if the initializer in a source program incorrectly contains
4081 more one). */
4082 for (link = CONSTRUCTOR_ELTS (exp);
4083 link;
4084 link = TREE_CHAIN (link),
4085 field = field ? TREE_CHAIN (field) : 0)
4087 tree val = TREE_VALUE (link);
4088 tree index = 0;
4090 /* the element in a union constructor specifies the proper field. */
4092 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4093 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4095 /* if available, use the type given by link */
4096 if (TREE_PURPOSE (link) != 0)
4097 field = TREE_PURPOSE (link);
4100 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4101 index = TREE_PURPOSE (link);
4103 /* Eliminate the marker that makes a cast not be an lvalue. */
4104 if (val != 0)
4105 STRIP_NOPS (val);
4107 if (index && TREE_CODE (index) == RANGE_EXPR)
4109 register int fieldsize
4110 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4111 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4112 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4113 HOST_WIDE_INT index;
4114 for (index = lo_index; index <= hi_index; index++)
4116 /* Output the element's initial value. */
4117 if (val == 0)
4118 assemble_zeros (fieldsize);
4119 else
4120 output_constant (val, fieldsize);
4122 /* Count its size. */
4123 total_bytes += fieldsize;
4126 else if (field == 0 || !DECL_BIT_FIELD (field))
4128 /* An element that is not a bit-field. */
4130 register int fieldsize;
4131 /* Since this structure is static,
4132 we know the positions are constant. */
4133 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4134 / BITS_PER_UNIT)
4135 : 0);
4136 if (index != 0)
4137 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4138 / BITS_PER_UNIT
4139 * (TREE_INT_CST_LOW (index) - min_index));
4141 /* Output any buffered-up bit-fields preceding this element. */
4142 if (byte_buffer_in_use)
4144 ASM_OUTPUT_BYTE (asm_out_file, byte);
4145 total_bytes++;
4146 byte_buffer_in_use = 0;
4149 /* Advance to offset of this element.
4150 Note no alignment needed in an array, since that is guaranteed
4151 if each element has the proper size. */
4152 if ((field != 0 || index != 0) && bitpos != total_bytes)
4154 assemble_zeros (bitpos - total_bytes);
4155 total_bytes = bitpos;
4158 /* Determine size this element should occupy. */
4159 if (field)
4161 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4162 abort ();
4163 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4165 /* This avoids overflow trouble. */
4166 tree size_tree = size_binop (CEIL_DIV_EXPR,
4167 DECL_SIZE (field),
4168 size_int (BITS_PER_UNIT));
4169 fieldsize = TREE_INT_CST_LOW (size_tree);
4171 else
4173 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4174 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4177 else
4178 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4180 /* Output the element's initial value. */
4181 if (val == 0)
4182 assemble_zeros (fieldsize);
4183 else
4184 output_constant (val, fieldsize);
4186 /* Count its size. */
4187 total_bytes += fieldsize;
4189 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4190 error ("invalid initial value for member `%s'",
4191 IDENTIFIER_POINTER (DECL_NAME (field)));
4192 else
4194 /* Element that is a bit-field. */
4196 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4197 int end_offset
4198 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4200 if (val == 0)
4201 val = integer_zero_node;
4203 /* If this field does not start in this (or, next) byte,
4204 skip some bytes. */
4205 if (next_offset / BITS_PER_UNIT != total_bytes)
4207 /* Output remnant of any bit field in previous bytes. */
4208 if (byte_buffer_in_use)
4210 ASM_OUTPUT_BYTE (asm_out_file, byte);
4211 total_bytes++;
4212 byte_buffer_in_use = 0;
4215 /* If still not at proper byte, advance to there. */
4216 if (next_offset / BITS_PER_UNIT != total_bytes)
4218 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4219 total_bytes = next_offset / BITS_PER_UNIT;
4223 if (! byte_buffer_in_use)
4224 byte = 0;
4226 /* We must split the element into pieces that fall within
4227 separate bytes, and combine each byte with previous or
4228 following bit-fields. */
4230 /* next_offset is the offset n fbits from the beginning of
4231 the structure to the next bit of this element to be processed.
4232 end_offset is the offset of the first bit past the end of
4233 this element. */
4234 while (next_offset < end_offset)
4236 int this_time;
4237 int shift;
4238 HOST_WIDE_INT value;
4239 int next_byte = next_offset / BITS_PER_UNIT;
4240 int next_bit = next_offset % BITS_PER_UNIT;
4242 /* Advance from byte to byte
4243 within this element when necessary. */
4244 while (next_byte != total_bytes)
4246 ASM_OUTPUT_BYTE (asm_out_file, byte);
4247 total_bytes++;
4248 byte = 0;
4251 /* Number of bits we can process at once
4252 (all part of the same byte). */
4253 this_time = MIN (end_offset - next_offset,
4254 BITS_PER_UNIT - next_bit);
4255 if (BYTES_BIG_ENDIAN)
4257 /* On big-endian machine, take the most significant bits
4258 first (of the bits that are significant)
4259 and put them into bytes from the most significant end. */
4260 shift = end_offset - next_offset - this_time;
4261 /* Don't try to take a bunch of bits that cross
4262 the word boundary in the INTEGER_CST. */
4263 if (shift < HOST_BITS_PER_WIDE_INT
4264 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4266 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4267 shift = HOST_BITS_PER_WIDE_INT;
4270 /* Now get the bits from the appropriate constant word. */
4271 if (shift < HOST_BITS_PER_WIDE_INT)
4273 value = TREE_INT_CST_LOW (val);
4275 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4277 value = TREE_INT_CST_HIGH (val);
4278 shift -= HOST_BITS_PER_WIDE_INT;
4280 else
4281 abort ();
4282 byte |= (((value >> shift)
4283 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4284 << (BITS_PER_UNIT - this_time - next_bit));
4286 else
4288 /* On little-endian machines,
4289 take first the least significant bits of the value
4290 and pack them starting at the least significant
4291 bits of the bytes. */
4292 shift = (next_offset
4293 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4294 /* Don't try to take a bunch of bits that cross
4295 the word boundary in the INTEGER_CST. */
4296 if (shift < HOST_BITS_PER_WIDE_INT
4297 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4299 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4300 shift = HOST_BITS_PER_WIDE_INT;
4303 /* Now get the bits from the appropriate constant word. */
4304 if (shift < HOST_BITS_PER_WIDE_INT)
4305 value = TREE_INT_CST_LOW (val);
4306 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4308 value = TREE_INT_CST_HIGH (val);
4309 shift -= HOST_BITS_PER_WIDE_INT;
4311 else
4312 abort ();
4313 byte |= (((value >> shift)
4314 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4315 << next_bit);
4317 next_offset += this_time;
4318 byte_buffer_in_use = 1;
4322 if (byte_buffer_in_use)
4324 ASM_OUTPUT_BYTE (asm_out_file, byte);
4325 total_bytes++;
4327 if (total_bytes < size)
4328 assemble_zeros (size - total_bytes);
4331 #ifdef HANDLE_PRAGMA_WEAK
4332 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4333 associatd with NAME. */
4336 add_weak (name, value)
4337 char *name;
4338 char *value;
4340 struct weak_syms *weak;
4342 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4344 if (weak == NULL)
4345 return 0;
4347 weak->next = weak_decls;
4348 weak->name = name;
4349 weak->value = value;
4350 weak_decls = weak;
4352 return 1;
4354 #endif /* HANDLE_PRAGMA_WEAK */
4356 /* Declare DECL to be a weak symbol. */
4358 void
4359 declare_weak (decl)
4360 tree decl;
4362 if (! TREE_PUBLIC (decl))
4363 error_with_decl (decl, "weak declaration of `%s' must be public");
4364 else if (TREE_ASM_WRITTEN (decl))
4365 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4366 else if (SUPPORTS_WEAK)
4367 DECL_WEAK (decl) = 1;
4368 #ifdef HANDLE_PRAGMA_WEAK
4369 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4370 #endif
4373 /* Emit any pending weak declarations. */
4375 #ifdef HANDLE_PRAGMA_WEAK
4376 struct weak_syms * weak_decls;
4377 #endif
4379 void
4380 weak_finish ()
4382 #ifdef HANDLE_PRAGMA_WEAK
4383 if (HANDLE_PRAGMA_WEAK)
4385 struct weak_syms *t;
4386 for (t = weak_decls; t; t = t->next)
4388 if (t->name)
4390 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4391 if (t->value)
4392 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4396 #endif
4399 /* Remove NAME from the pending list of weak symbols. This prevents
4400 the compiler from emitting multiple .weak directives which confuses
4401 some assemblers. */
4402 static void
4403 remove_from_pending_weak_list (name)
4404 char *name ATTRIBUTE_UNUSED;
4406 #ifdef HANDLE_PRAGMA_WEAK
4407 if (HANDLE_PRAGMA_WEAK)
4409 struct weak_syms *t;
4410 for (t = weak_decls; t; t = t->next)
4412 if (t->name && strcmp (name, t->name) == 0)
4413 t->name = NULL;
4416 #endif
4419 void
4420 assemble_alias (decl, target)
4421 tree decl, target ATTRIBUTE_UNUSED;
4423 char *name;
4425 make_decl_rtl (decl, (char *) 0, 1);
4426 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4428 #ifdef ASM_OUTPUT_DEF
4429 /* Make name accessible from other files, if appropriate. */
4431 if (TREE_PUBLIC (decl))
4433 #ifdef ASM_WEAKEN_LABEL
4434 if (DECL_WEAK (decl))
4436 ASM_WEAKEN_LABEL (asm_out_file, name);
4437 /* Remove this function from the pending weak list so that
4438 we do not emit multiple .weak directives for it. */
4439 remove_from_pending_weak_list
4440 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4442 else
4443 #endif
4444 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4447 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4448 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4449 #else
4450 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4451 #endif
4452 TREE_ASM_WRITTEN (decl) = 1;
4453 #else
4454 #ifdef ASM_OUTPUT_WEAK_ALIAS
4455 if (! DECL_WEAK (decl))
4456 warning ("only weak aliases are supported in this configuration");
4458 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4459 TREE_ASM_WRITTEN (decl) = 1;
4460 #else
4461 warning ("alias definitions not supported in this configuration; ignored");
4462 #endif
4463 #endif
4466 /* This determines whether or not we support link-once semantics. */
4467 #ifndef SUPPORTS_ONE_ONLY
4468 #ifdef MAKE_DECL_ONE_ONLY
4469 #define SUPPORTS_ONE_ONLY 1
4470 #else
4471 #define SUPPORTS_ONE_ONLY 0
4472 #endif
4473 #endif
4475 /* Returns 1 if the target configuration supports defining public symbols
4476 so that one of them will be chosen at link time instead of generating a
4477 multiply-defined symbol error, whether through the use of weak symbols or
4478 a target-specific mechanism for having duplicates discarded. */
4481 supports_one_only ()
4483 if (SUPPORTS_ONE_ONLY)
4484 return 1;
4485 return SUPPORTS_WEAK;
4488 /* Set up DECL as a public symbol that can be defined in multiple
4489 translation units without generating a linker error. */
4491 void
4492 make_decl_one_only (decl)
4493 tree decl;
4495 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4496 abort ();
4498 TREE_PUBLIC (decl) = 1;
4500 if (TREE_CODE (decl) == VAR_DECL
4501 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4502 DECL_COMMON (decl) = 1;
4503 else if (SUPPORTS_ONE_ONLY)
4505 #ifdef MAKE_DECL_ONE_ONLY
4506 MAKE_DECL_ONE_ONLY (decl);
4507 #endif
4508 DECL_ONE_ONLY (decl) = 1;
4510 else if (SUPPORTS_WEAK)
4511 DECL_WEAK (decl) = 1;
4512 else
4513 abort ();