* decl.c (initialize_local_var): Handle static variables here.
[official-gcc.git] / gcc / varasm.c
blob0f9d36ae705999507396f3101e73df650f0799f0
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 "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "output.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "real.h"
42 #include "toplev.h"
43 #include "dbxout.h"
44 #include "sdbout.h"
45 #include "obstack.h"
46 #include "c-pragma.h"
47 #include "ggc.h"
48 #include "tm_p.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 struct addr_const;
89 struct constant_descriptor;
90 struct rtx_const;
91 struct pool_constant;
93 #define MAX_RTX_HASH_TABLE 61
95 struct varasm_status
97 /* Hash facility for making memory-constants
98 from constant rtl-expressions. It is used on RISC machines
99 where immediate integer arguments and constant addresses are restricted
100 so that such constants must be stored in memory.
102 This pool of constants is reinitialized for each function
103 so each function gets its own constants-pool that comes right before
104 it. */
105 struct constant_descriptor **x_const_rtx_hash_table;
106 struct pool_sym **x_const_rtx_sym_hash_table;
108 /* Pointers to first and last constant in pool. */
109 struct pool_constant *x_first_pool, *x_last_pool;
111 /* Current offset in constant pool (does not include any machine-specific
112 header. */
113 int x_pool_offset;
115 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
116 They are chained through the CONST_DOUBLE_CHAIN.
117 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
118 In that case, CONST_DOUBLE_MEM is either a MEM,
119 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
120 rtx x_const_double_chain;
123 #define const_rtx_hash_table (current_function->varasm->x_const_rtx_hash_table)
124 #define const_rtx_sym_hash_table (current_function->varasm->x_const_rtx_sym_hash_table)
125 #define first_pool (current_function->varasm->x_first_pool)
126 #define last_pool (current_function->varasm->x_last_pool)
127 #define pool_offset (current_function->varasm->x_pool_offset)
128 #define const_double_chain (current_function->varasm->x_const_double_chain)
130 /* Number for making the label on the next
131 constant that is stored in memory. */
133 int const_labelno;
135 /* Number for making the label on the next
136 static variable internal to a function. */
138 int var_labelno;
140 /* Carry information from ASM_DECLARE_OBJECT_NAME
141 to ASM_FINISH_DECLARE_OBJECT. */
143 int size_directive_output;
145 /* The last decl for which assemble_variable was called,
146 if it did ASM_DECLARE_OBJECT_NAME.
147 If the last call to assemble_variable didn't do that,
148 this holds 0. */
150 tree last_assemble_variable_decl;
152 /* Nonzero if at least one function definition has been seen. */
154 static int function_defined;
156 static const char *strip_reg_name PROTO((const char *));
157 static int contains_pointers_p PROTO((tree));
158 static void decode_addr_const PROTO((tree, struct addr_const *));
159 static int const_hash PROTO((tree));
160 static int compare_constant PROTO((tree,
161 struct constant_descriptor *));
162 static char *compare_constant_1 PROTO((tree, char *));
163 static struct constant_descriptor *record_constant PROTO((tree));
164 static void record_constant_1 PROTO((tree));
165 static tree copy_constant PROTO((tree));
166 static void output_constant_def_contents PROTO((tree, int, int));
167 static void decode_rtx_const PROTO((enum machine_mode, rtx,
168 struct rtx_const *));
169 static int const_hash_rtx PROTO((enum machine_mode, rtx));
170 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
171 struct constant_descriptor *));
172 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
173 rtx));
174 static struct pool_constant *find_pool_constant PROTO((struct function *, rtx));
175 static void mark_constant_pool PROTO((void));
176 static void mark_constants PROTO((rtx));
177 static int output_addressed_constants PROTO((tree));
178 static void output_after_function_constants PROTO((void));
179 static void output_constructor PROTO((tree, int));
180 #ifdef ASM_WEAKEN_LABEL
181 static void remove_from_pending_weak_list PROTO ((char *));
182 #endif
183 #ifdef ASM_OUTPUT_BSS
184 static void asm_output_bss PROTO((FILE *, tree, char *, int, int));
185 #endif
186 #ifdef BSS_SECTION_ASM_OP
187 #ifdef ASM_OUTPUT_ALIGNED_BSS
188 static void asm_output_aligned_bss PROTO((FILE *, tree, char *, int, int));
189 #endif
190 #endif /* BSS_SECTION_ASM_OP */
191 static void mark_pool_constant PROTO((struct pool_constant *));
192 static void mark_pool_sym_hash_table PROTO((struct pool_sym **));
193 static void mark_const_hash_entry PROTO((void *));
195 static enum in_section { no_section, in_text, in_data, in_named
196 #ifdef BSS_SECTION_ASM_OP
197 , in_bss
198 #endif
199 #ifdef EH_FRAME_SECTION_ASM_OP
200 , in_eh_frame
201 #endif
202 #ifdef EXTRA_SECTIONS
203 , EXTRA_SECTIONS
204 #endif
205 } in_section = no_section;
207 /* Return a non-zero value if DECL has a section attribute. */
208 #define IN_NAMED_SECTION(DECL) \
209 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
210 && DECL_SECTION_NAME (DECL) != NULL_TREE)
212 /* Text of section name when in_section == in_named. */
213 static char *in_named_name;
215 /* Define functions like text_section for any extra sections. */
216 #ifdef EXTRA_SECTION_FUNCTIONS
217 EXTRA_SECTION_FUNCTIONS
218 #endif
220 /* Tell assembler to switch to text section. */
222 void
223 text_section ()
225 if (in_section != in_text)
227 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
228 in_section = in_text;
232 /* Tell assembler to switch to data section. */
234 void
235 data_section ()
237 if (in_section != in_data)
239 if (flag_shared_data)
241 #ifdef SHARED_SECTION_ASM_OP
242 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
243 #else
244 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
245 #endif
247 else
248 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
250 in_section = in_data;
253 /* Tell assembler to ALWAYS switch to data section, in case
254 it's not sure where it it. */
256 void
257 force_data_section ()
259 in_section = no_section;
260 data_section ();
263 /* Tell assembler to switch to read-only data section. This is normally
264 the text section. */
266 void
267 readonly_data_section ()
269 #ifdef READONLY_DATA_SECTION
270 READONLY_DATA_SECTION (); /* Note this can call data_section. */
271 #else
272 text_section ();
273 #endif
276 /* Determine if we're in the text section. */
279 in_text_section ()
281 return in_section == in_text;
284 /* Determine if we're in the data section. */
287 in_data_section ()
289 return in_section == in_data;
292 /* Tell assembler to change to section NAME for DECL.
293 If DECL is NULL, just switch to section NAME.
294 If NAME is NULL, get the name from DECL.
295 If RELOC is 1, the initializer for DECL contains relocs. */
297 void
298 named_section (decl, name, reloc)
299 tree decl;
300 const char *name;
301 int reloc ATTRIBUTE_UNUSED;
303 if (decl != NULL_TREE
304 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
305 abort ();
306 if (name == NULL)
307 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
309 if (in_section != in_named || strcmp (name, in_named_name))
311 #ifdef ASM_OUTPUT_SECTION_NAME
312 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
313 #else
314 /* Section attributes are not supported if this macro isn't provided -
315 some host formats don't support them at all. The front-end should
316 already have flagged this as an error. */
317 abort ();
318 #endif
320 in_named_name = ggc_alloc_string (name, -1);
321 in_section = in_named;
325 #ifdef ASM_OUTPUT_SECTION_NAME
326 #ifndef UNIQUE_SECTION
327 #define UNIQUE_SECTION(DECL,RELOC) \
328 do { \
329 int len; \
330 const char *name; \
331 char *string; \
333 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
334 /* Strip off any encoding in name. */ \
335 STRIP_NAME_ENCODING (name, name); \
337 len = strlen (name) + 1; \
338 string = alloca (len + 1); \
339 sprintf (string, ".%s", name); \
341 DECL_SECTION_NAME (DECL) = build_string (len, string); \
342 } while (0)
343 #endif
344 #ifndef UNIQUE_SECTION_P
345 #define UNIQUE_SECTION_P(DECL) 0
346 #endif
347 #endif
349 #ifdef BSS_SECTION_ASM_OP
351 /* Tell the assembler to switch to the bss section. */
353 void
354 bss_section ()
356 if (in_section != in_bss)
358 #ifdef SHARED_BSS_SECTION_ASM_OP
359 if (flag_shared_data)
360 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
361 else
362 #endif
363 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
365 in_section = in_bss;
369 #ifdef ASM_OUTPUT_BSS
371 /* Utility function for ASM_OUTPUT_BSS for targets to use if
372 they don't support alignments in .bss.
373 ??? It is believed that this function will work in most cases so such
374 support is localized here. */
376 static void
377 asm_output_bss (file, decl, name, size, rounded)
378 FILE *file;
379 tree decl;
380 char *name;
381 int size, rounded;
383 ASM_GLOBALIZE_LABEL (file, name);
384 bss_section ();
385 #ifdef ASM_DECLARE_OBJECT_NAME
386 last_assemble_variable_decl = decl;
387 ASM_DECLARE_OBJECT_NAME (file, name, decl);
388 #else
389 /* Standard thing is just output label for the object. */
390 ASM_OUTPUT_LABEL (file, name);
391 #endif /* ASM_DECLARE_OBJECT_NAME */
392 ASM_OUTPUT_SKIP (file, rounded);
395 #endif
397 #ifdef ASM_OUTPUT_ALIGNED_BSS
399 /* Utility function for targets to use in implementing
400 ASM_OUTPUT_ALIGNED_BSS.
401 ??? It is believed that this function will work in most cases so such
402 support is localized here. */
404 static void
405 asm_output_aligned_bss (file, decl, name, size, align)
406 FILE *file;
407 tree decl;
408 char *name;
409 int size, align;
411 ASM_GLOBALIZE_LABEL (file, name);
412 bss_section ();
413 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
414 #ifdef ASM_DECLARE_OBJECT_NAME
415 last_assemble_variable_decl = decl;
416 ASM_DECLARE_OBJECT_NAME (file, name, decl);
417 #else
418 /* Standard thing is just output label for the object. */
419 ASM_OUTPUT_LABEL (file, name);
420 #endif /* ASM_DECLARE_OBJECT_NAME */
421 ASM_OUTPUT_SKIP (file, size ? size : 1);
424 #endif
426 #endif /* BSS_SECTION_ASM_OP */
428 #ifdef EH_FRAME_SECTION_ASM_OP
429 void
430 eh_frame_section ()
432 if (in_section != in_eh_frame)
434 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
435 in_section = in_eh_frame;
438 #endif
440 /* Switch to the section for function DECL.
442 If DECL is NULL_TREE, switch to the text section.
443 ??? It's not clear that we will ever be passed NULL_TREE, but it's
444 safer to handle it. */
446 void
447 function_section (decl)
448 tree decl;
450 if (decl != NULL_TREE
451 && DECL_SECTION_NAME (decl) != NULL_TREE)
452 named_section (decl, (char *) 0, 0);
453 else
454 text_section ();
457 /* Switch to section for variable DECL.
459 RELOC is the `reloc' argument to SELECT_SECTION. */
461 void
462 variable_section (decl, reloc)
463 tree decl;
464 int reloc;
466 if (IN_NAMED_SECTION (decl))
467 named_section (decl, NULL, reloc);
468 else
470 /* C++ can have const variables that get initialized from constructors,
471 and thus can not be in a readonly section. We prevent this by
472 verifying that the initial value is constant for objects put in a
473 readonly section.
475 error_mark_node is used by the C front end to indicate that the
476 initializer has not been seen yet. In this case, we assume that
477 the initializer must be constant.
479 C++ uses error_mark_node for variables that have complicated
480 initializers, but these variables go in BSS so we won't be called
481 for them. */
483 #ifdef SELECT_SECTION
484 SELECT_SECTION (decl, reloc);
485 #else
486 if (DECL_READONLY_SECTION (decl, reloc))
487 readonly_data_section ();
488 else
489 data_section ();
490 #endif
494 /* Tell assembler to switch to the section for the exception handling
495 table. */
497 void
498 exception_section ()
500 #if defined (EXCEPTION_SECTION)
501 EXCEPTION_SECTION ();
502 #else
503 #ifdef ASM_OUTPUT_SECTION_NAME
504 named_section (NULL_TREE, ".gcc_except_table", 0);
505 #else
506 if (flag_pic)
507 data_section ();
508 else
509 readonly_data_section ();
510 #endif
511 #endif
514 /* Create the rtl to represent a function, for a function definition.
515 DECL is a FUNCTION_DECL node which describes which function.
516 The rtl is stored into DECL. */
518 void
519 make_function_rtl (decl)
520 tree decl;
522 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
523 char *new_name = name;
525 /* Rename a nested function to avoid conflicts. */
526 if (decl_function_context (decl) != 0
527 && DECL_INITIAL (decl) != 0
528 && DECL_RTL (decl) == 0)
530 char *label;
532 name = IDENTIFIER_POINTER (DECL_NAME (decl));
533 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
534 name = ggc_alloc_string (label, -1);
535 var_labelno++;
537 else
539 /* When -fprefix-function-name is used, every function name is
540 prefixed. Even static functions are prefixed because they
541 could be declared latter. Note that a nested function name
542 is not prefixed. */
543 if (flag_prefix_function_name)
545 size_t name_len = strlen (name);
547 new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
548 memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
549 memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
550 name = new_name;
554 if (DECL_RTL (decl) == 0)
556 DECL_RTL (decl)
557 = gen_rtx_MEM (DECL_MODE (decl),
558 gen_rtx_SYMBOL_REF (Pmode, name));
560 /* Optionally set flags or add text to the name to record information
561 such as that it is a function name. If the name is changed, the macro
562 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
563 #ifdef ENCODE_SECTION_INFO
564 ENCODE_SECTION_INFO (decl);
565 #endif
567 else
569 /* ??? Another way to do this would be to do what halfpic.c does
570 and maintain a hashed table of such critters. */
571 /* ??? Another way to do this would be to pass a flag bit to
572 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
573 /* Let the target reassign the RTL if it wants.
574 This is necessary, for example, when one machine specific
575 decl attribute overrides another. */
576 #ifdef REDO_SECTION_INFO_P
577 if (REDO_SECTION_INFO_P (decl))
578 ENCODE_SECTION_INFO (decl);
579 #endif
582 /* Record at least one function has been defined. */
583 function_defined = 1;
586 /* Given NAME, a putative register name, discard any customary prefixes. */
588 static const char *
589 strip_reg_name (name)
590 const char *name;
592 #ifdef REGISTER_PREFIX
593 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
594 name += strlen (REGISTER_PREFIX);
595 #endif
596 if (name[0] == '%' || name[0] == '#')
597 name++;
598 return name;
601 /* Decode an `asm' spec for a declaration as a register name.
602 Return the register number, or -1 if nothing specified,
603 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
604 or -3 if ASMSPEC is `cc' and is not recognized,
605 or -4 if ASMSPEC is `memory' and is not recognized.
606 Accept an exact spelling or a decimal number.
607 Prefixes such as % are optional. */
610 decode_reg_name (asmspec)
611 const char *asmspec;
613 if (asmspec != 0)
615 int i;
617 /* Get rid of confusing prefixes. */
618 asmspec = strip_reg_name (asmspec);
620 /* Allow a decimal number as a "register name". */
621 for (i = strlen (asmspec) - 1; i >= 0; i--)
622 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
623 break;
624 if (asmspec[0] != 0 && i < 0)
626 i = atoi (asmspec);
627 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
628 return i;
629 else
630 return -2;
633 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
634 if (reg_names[i][0]
635 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
636 return i;
638 #ifdef ADDITIONAL_REGISTER_NAMES
640 static struct { const char *name; int number; } table[]
641 = ADDITIONAL_REGISTER_NAMES;
643 for (i = 0; i < (int)(sizeof (table) / sizeof (table[0])); i++)
644 if (! strcmp (asmspec, table[i].name))
645 return table[i].number;
647 #endif /* ADDITIONAL_REGISTER_NAMES */
649 if (!strcmp (asmspec, "memory"))
650 return -4;
652 if (!strcmp (asmspec, "cc"))
653 return -3;
655 return -2;
658 return -1;
661 /* Create the DECL_RTL for a declaration for a static or external variable
662 or static or external function.
663 ASMSPEC, if not 0, is the string which the user specified
664 as the assembler symbol name.
665 TOP_LEVEL is nonzero if this is a file-scope variable.
667 This is never called for PARM_DECL nodes. */
669 void
670 make_decl_rtl (decl, asmspec, top_level)
671 tree decl;
672 const char *asmspec;
673 int top_level;
675 register char *name = 0;
676 int reg_number;
678 reg_number = decode_reg_name (asmspec);
680 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
681 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
683 if (reg_number == -2)
685 /* ASMSPEC is given, and not the name of a register. */
686 size_t len = strlen (asmspec);
688 name = ggc_alloc_string (NULL, len + 1);
689 name[0] = '*';
690 memcpy (&name[1], asmspec, len + 1);
693 /* For a duplicate declaration, we can be called twice on the
694 same DECL node. Don't discard the RTL already made. */
695 if (DECL_RTL (decl) == 0)
697 /* First detect errors in declaring global registers. */
698 if (TREE_CODE (decl) != FUNCTION_DECL
699 && DECL_REGISTER (decl) && reg_number == -1)
700 error_with_decl (decl,
701 "register name not specified for `%s'");
702 else if (TREE_CODE (decl) != FUNCTION_DECL
703 && DECL_REGISTER (decl) && reg_number < 0)
704 error_with_decl (decl,
705 "invalid register name for `%s'");
706 else if ((reg_number >= 0 || reg_number == -3)
707 && (TREE_CODE (decl) == FUNCTION_DECL
708 && ! DECL_REGISTER (decl)))
709 error_with_decl (decl,
710 "register name given for non-register variable `%s'");
711 else if (TREE_CODE (decl) != FUNCTION_DECL
712 && DECL_REGISTER (decl)
713 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
714 error_with_decl (decl,
715 "data type of `%s' isn't suitable for a register");
716 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
717 && ! HARD_REGNO_MODE_OK (reg_number,
718 TYPE_MODE (TREE_TYPE (decl))))
719 error_with_decl (decl,
720 "register number for `%s' isn't suitable for data type");
721 /* Now handle properly declared static register variables. */
722 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
724 int nregs;
726 if (DECL_INITIAL (decl) != 0 && top_level)
728 DECL_INITIAL (decl) = 0;
729 error ("global register variable has initial value");
731 if (fixed_regs[reg_number] == 0
732 && function_defined && top_level)
733 error ("global register variable follows a function definition");
734 if (TREE_THIS_VOLATILE (decl))
735 warning ("volatile register variables don't work as you might wish");
737 /* If the user specified one of the eliminables registers here,
738 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
739 confused with that register and be eliminated. Although this
740 usage is somewhat suspect, we nevertheless use the following
741 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
743 DECL_RTL (decl)
744 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
745 REGNO (DECL_RTL (decl)) = reg_number;
746 REG_USERVAR_P (DECL_RTL (decl)) = 1;
748 if (top_level)
750 /* Make this register global, so not usable for anything
751 else. */
752 #ifdef ASM_DECLARE_REGISTER_GLOBAL
753 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
754 #endif
755 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
756 while (nregs > 0)
757 globalize_reg (reg_number + --nregs);
760 /* Specifying a section attribute on a variable forces it into a
761 non-.bss section, and thus it cannot be common. */
762 else if (TREE_CODE (decl) == VAR_DECL
763 && DECL_SECTION_NAME (decl) != NULL_TREE
764 && DECL_INITIAL (decl) == NULL_TREE
765 && DECL_COMMON (decl))
766 DECL_COMMON (decl) = 0;
768 /* Now handle ordinary static variables and functions (in memory).
769 Also handle vars declared register invalidly. */
770 if (DECL_RTL (decl) == 0)
772 /* Can't use just the variable's own name for a variable
773 whose scope is less than the whole file.
774 Concatenate a distinguishing number. */
775 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
777 char *label;
779 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
780 name = ggc_alloc_string (label, -1);
781 var_labelno++;
784 if (name == 0)
785 abort ();
787 /* When -fprefix-function-name is used, the functions
788 names are prefixed. Only nested function names are not
789 prefixed. */
790 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
792 size_t name_len = strlen (name);
793 char *new_name;
795 new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
796 memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
797 memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
798 name = new_name;
801 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
802 gen_rtx_SYMBOL_REF (Pmode, name));
803 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
805 /* If this variable is to be treated as volatile, show its
806 tree node has side effects. If it has side effects, either
807 because of this test or from TREE_THIS_VOLATILE also
808 being set, show the MEM is volatile. */
809 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
810 && TREE_PUBLIC (decl))
811 TREE_SIDE_EFFECTS (decl) = 1;
812 else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
813 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
814 TREE_SIDE_EFFECTS (decl) = 1;
816 if (TREE_SIDE_EFFECTS (decl))
817 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
819 if (TREE_READONLY (decl))
820 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
821 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
822 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
824 /* Optionally set flags or add text to the name to record information
825 such as that it is a function name.
826 If the name is changed, the macro ASM_OUTPUT_LABELREF
827 will have to know how to strip this information. */
828 #ifdef ENCODE_SECTION_INFO
829 ENCODE_SECTION_INFO (decl);
830 #endif
833 else
835 /* If the old RTL had the wrong mode, fix the mode. */
836 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
838 rtx rtl = DECL_RTL (decl);
839 PUT_MODE (rtl, DECL_MODE (decl));
842 /* ??? Another way to do this would be to do what halfpic.c does
843 and maintain a hashed table of such critters. */
844 /* ??? Another way to do this would be to pass a flag bit to
845 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
846 /* Let the target reassign the RTL if it wants.
847 This is necessary, for example, when one machine specific
848 decl attribute overrides another. */
849 #ifdef REDO_SECTION_INFO_P
850 if (REDO_SECTION_INFO_P (decl))
851 ENCODE_SECTION_INFO (decl);
852 #endif
856 /* Make the rtl for variable VAR be volatile.
857 Use this only for static variables. */
859 void
860 make_var_volatile (var)
861 tree var;
863 if (GET_CODE (DECL_RTL (var)) != MEM)
864 abort ();
866 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
869 /* Output alignment directive to align for constant expression EXP. */
871 void
872 assemble_constant_align (exp)
873 tree exp;
875 int align;
877 /* Align the location counter as required by EXP's data type. */
878 align = TYPE_ALIGN (TREE_TYPE (exp));
879 #ifdef CONSTANT_ALIGNMENT
880 align = CONSTANT_ALIGNMENT (exp, align);
881 #endif
883 if (align > BITS_PER_UNIT)
884 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
887 /* Output a string of literal assembler code
888 for an `asm' keyword used between functions. */
890 void
891 assemble_asm (string)
892 tree string;
894 app_enable ();
896 if (TREE_CODE (string) == ADDR_EXPR)
897 string = TREE_OPERAND (string, 0);
899 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
902 #if 0 /* This should no longer be needed, because
903 flag_gnu_linker should be 0 on these systems,
904 which should prevent any output
905 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
906 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
907 #ifndef ASM_OUTPUT_CONSTRUCTOR
908 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
909 #endif
910 #ifndef ASM_OUTPUT_DESTRUCTOR
911 #define ASM_OUTPUT_DESTRUCTOR(file, name)
912 #endif
913 #endif
914 #endif /* 0 */
916 /* Record an element in the table of global destructors.
917 How this is done depends on what sort of assembler and linker
918 are in use.
920 NAME should be the name of a global function to be called
921 at exit time. This name is output using assemble_name. */
923 void
924 assemble_destructor (name)
925 char *name;
927 #ifdef ASM_OUTPUT_DESTRUCTOR
928 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
929 #else
930 if (flag_gnu_linker)
932 /* Now tell GNU LD that this is part of the static destructor set. */
933 /* This code works for any machine provided you use GNU as/ld. */
934 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
935 assemble_name (asm_out_file, name);
936 fputc ('\n', asm_out_file);
938 #endif
941 /* Likewise for global constructors. */
943 void
944 assemble_constructor (name)
945 char *name;
947 #ifdef ASM_OUTPUT_CONSTRUCTOR
948 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
949 #else
950 if (flag_gnu_linker)
952 /* Now tell GNU LD that this is part of the static constructor set. */
953 /* This code works for any machine provided you use GNU as/ld. */
954 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
955 assemble_name (asm_out_file, name);
956 fputc ('\n', asm_out_file);
958 #endif
961 /* Likewise for entries we want to record for garbage collection.
962 Garbage collection is still under development. */
964 void
965 assemble_gc_entry (name)
966 char *name;
968 #ifdef ASM_OUTPUT_GC_ENTRY
969 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
970 #else
971 if (flag_gnu_linker)
973 /* Now tell GNU LD that this is part of the static constructor set. */
974 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
975 assemble_name (asm_out_file, name);
976 fputc ('\n', asm_out_file);
978 #endif
981 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
982 a non-zero value if the constant pool should be output before the
983 start of the function, or a zero value if the pool should output
984 after the end of the function. The default is to put it before the
985 start. */
987 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
988 #define CONSTANT_POOL_BEFORE_FUNCTION 1
989 #endif
991 /* Output assembler code for the constant pool of a function and associated
992 with defining the name of the function. DECL describes the function.
993 NAME is the function's name. For the constant pool, we use the current
994 constant pool data. */
996 void
997 assemble_start_function (decl, fnname)
998 tree decl;
999 char *fnname;
1001 int align;
1003 /* The following code does not need preprocessing in the assembler. */
1005 app_disable ();
1007 if (CONSTANT_POOL_BEFORE_FUNCTION)
1008 output_constant_pool (fnname, decl);
1010 #ifdef ASM_OUTPUT_SECTION_NAME
1011 /* If the function is to be put in its own section and it's not in a section
1012 already, indicate so. */
1013 if ((flag_function_sections
1014 && DECL_SECTION_NAME (decl) == NULL_TREE)
1015 || UNIQUE_SECTION_P (decl))
1016 UNIQUE_SECTION (decl, 0);
1017 #endif
1019 function_section (decl);
1021 /* Tell assembler to move to target machine's alignment for functions. */
1022 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1023 if (align > 0)
1024 ASM_OUTPUT_ALIGN (asm_out_file, align);
1026 /* Handle a user-specified function alignment.
1027 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1028 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1029 if (align_functions_log > align)
1031 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1032 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1033 align_functions_log, align_functions-1);
1034 #else
1035 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1036 #endif
1039 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1040 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1041 #endif
1043 #ifdef SDB_DEBUGGING_INFO
1044 /* Output SDB definition of the function. */
1045 if (write_symbols == SDB_DEBUG)
1046 sdbout_mark_begin_function ();
1047 #endif
1049 #ifdef DBX_DEBUGGING_INFO
1050 /* Output DBX definition of the function. */
1051 if (write_symbols == DBX_DEBUG)
1052 dbxout_begin_function (decl);
1053 #endif
1055 /* Make function name accessible from other files, if appropriate. */
1057 if (TREE_PUBLIC (decl))
1059 if (! first_global_object_name)
1061 const char *p;
1062 char **name;
1064 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1065 name = &first_global_object_name;
1066 else
1067 name = &weak_global_object_name;
1069 STRIP_NAME_ENCODING (p, fnname);
1070 *name = permalloc (strlen (p) + 1);
1071 strcpy (*name, p);
1074 #ifdef ASM_WEAKEN_LABEL
1075 if (DECL_WEAK (decl))
1077 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1078 /* Remove this function from the pending weak list so that
1079 we do not emit multiple .weak directives for it. */
1080 remove_from_pending_weak_list
1081 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1083 else
1084 #endif
1085 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1088 /* Do any machine/system dependent processing of the function name */
1089 #ifdef ASM_DECLARE_FUNCTION_NAME
1090 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1091 #else
1092 /* Standard thing is just output label for the function. */
1093 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1094 #endif /* ASM_DECLARE_FUNCTION_NAME */
1097 /* Output assembler code associated with defining the size of the
1098 function. DECL describes the function. NAME is the function's name. */
1100 void
1101 assemble_end_function (decl, fnname)
1102 tree decl;
1103 char *fnname;
1105 #ifdef ASM_DECLARE_FUNCTION_SIZE
1106 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1107 #endif
1108 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1110 output_constant_pool (fnname, decl);
1111 function_section (decl); /* need to switch back */
1114 /* Output any constants which should appear after the function. */
1115 output_after_function_constants ();
1118 /* Assemble code to leave SIZE bytes of zeros. */
1120 void
1121 assemble_zeros (size)
1122 int size;
1124 /* Do no output if -fsyntax-only. */
1125 if (flag_syntax_only)
1126 return;
1128 #ifdef ASM_NO_SKIP_IN_TEXT
1129 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1130 so we must output 0s explicitly in the text section. */
1131 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1133 int i;
1135 for (i = 0; i < size - 20; i += 20)
1137 #ifdef ASM_BYTE_OP
1138 fprintf (asm_out_file,
1139 "%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);
1140 #else
1141 fprintf (asm_out_file,
1142 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1143 #endif
1145 if (i < size)
1147 #ifdef ASM_BYTE_OP
1148 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1149 #else
1150 fprintf (asm_out_file, "\tbyte 0");
1151 #endif
1152 i++;
1153 for (; i < size; i++)
1154 fprintf (asm_out_file, ",0");
1155 fprintf (asm_out_file, "\n");
1158 else
1159 #endif
1160 if (size > 0)
1161 ASM_OUTPUT_SKIP (asm_out_file, size);
1164 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1166 void
1167 assemble_align (align)
1168 int align;
1170 if (align > BITS_PER_UNIT)
1171 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1174 /* Assemble a string constant with the specified C string as contents. */
1176 void
1177 assemble_string (p, size)
1178 const char *p;
1179 int size;
1181 int pos = 0;
1182 int maximum = 2000;
1184 /* If the string is very long, split it up. */
1186 while (pos < size)
1188 int thissize = size - pos;
1189 if (thissize > maximum)
1190 thissize = maximum;
1192 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1194 pos += thissize;
1195 p += thissize;
1200 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1201 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1202 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1203 #else
1204 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1205 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1206 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1207 #else
1208 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1209 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1210 #endif
1211 #endif
1213 #if defined ASM_OUTPUT_ALIGNED_BSS
1214 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1215 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1216 #else
1217 #if defined ASM_OUTPUT_BSS
1218 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1219 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1220 #else
1221 #undef ASM_EMIT_BSS
1222 #endif
1223 #endif
1225 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1226 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1227 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1228 #else
1229 #if defined ASM_OUTPUT_ALIGNED_COMMON
1230 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1231 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1232 #else
1233 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1234 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1235 #endif
1236 #endif
1238 static void
1239 asm_emit_uninitialised (decl, name, size, rounded)
1240 tree decl;
1241 char * name;
1242 int size;
1243 int rounded;
1245 enum {
1246 asm_dest_common,
1247 asm_dest_bss,
1248 asm_dest_local
1250 destination = asm_dest_local;
1252 if (TREE_PUBLIC (decl))
1254 #if defined ASM_EMIT_BSS
1255 if (! DECL_COMMON (decl))
1256 destination = asm_dest_bss;
1257 else
1258 #endif
1259 destination = asm_dest_common;
1262 if (flag_shared_data)
1264 switch (destination)
1266 #ifdef ASM_OUTPUT_SHARED_BSS
1267 case asm_dest_bss:
1268 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1269 return;
1270 #endif
1271 #ifdef ASM_OUTPUT_SHARED_COMMON
1272 case asm_dest_common:
1273 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1274 return;
1275 #endif
1276 #ifdef ASM_OUTPUT_SHARED_LOCAL
1277 case asm_dest_local:
1278 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1279 return;
1280 #endif
1281 default:
1282 break;
1286 switch (destination)
1288 #ifdef ASM_EMIT_BSS
1289 case asm_dest_bss:
1290 ASM_EMIT_BSS (decl, name, size, rounded);
1291 break;
1292 #endif
1293 case asm_dest_common:
1294 ASM_EMIT_COMMON (decl, name, size, rounded);
1295 break;
1296 case asm_dest_local:
1297 ASM_EMIT_LOCAL (decl, name, size, rounded);
1298 break;
1299 default:
1300 abort ();
1303 return;
1306 /* Assemble everything that is needed for a variable or function declaration.
1307 Not used for automatic variables, and not used for function definitions.
1308 Should not be called for variables of incomplete structure type.
1310 TOP_LEVEL is nonzero if this variable has file scope.
1311 AT_END is nonzero if this is the special handling, at end of compilation,
1312 to define things that have had only tentative definitions.
1313 DONT_OUTPUT_DATA if nonzero means don't actually output the
1314 initial value (that will be done by the caller). */
1316 void
1317 assemble_variable (decl, top_level, at_end, dont_output_data)
1318 tree decl;
1319 int top_level ATTRIBUTE_UNUSED;
1320 int at_end;
1321 int dont_output_data;
1323 register char *name;
1324 unsigned int align;
1325 tree size_tree = NULL_TREE;
1326 int reloc = 0;
1327 enum in_section saved_in_section;
1329 last_assemble_variable_decl = 0;
1331 if (GET_CODE (DECL_RTL (decl)) == REG)
1333 /* Do output symbol info for global register variables, but do nothing
1334 else for them. */
1336 if (TREE_ASM_WRITTEN (decl))
1337 return;
1338 TREE_ASM_WRITTEN (decl) = 1;
1340 /* Do no output if -fsyntax-only. */
1341 if (flag_syntax_only)
1342 return;
1344 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1345 /* File-scope global variables are output here. */
1346 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1347 && top_level)
1348 dbxout_symbol (decl, 0);
1349 #endif
1350 #ifdef SDB_DEBUGGING_INFO
1351 if (write_symbols == SDB_DEBUG && top_level
1352 /* Leave initialized global vars for end of compilation;
1353 see comment in compile_file. */
1354 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1355 sdbout_symbol (decl, 0);
1356 #endif
1358 /* Don't output any DWARF debugging information for variables here.
1359 In the case of local variables, the information for them is output
1360 when we do our recursive traversal of the tree representation for
1361 the entire containing function. In the case of file-scope variables,
1362 we output information for all of them at the very end of compilation
1363 while we are doing our final traversal of the chain of file-scope
1364 declarations. */
1366 return;
1369 /* Normally no need to say anything here for external references,
1370 since assemble_external is called by the language-specific code
1371 when a declaration is first seen. */
1373 if (DECL_EXTERNAL (decl))
1374 return;
1376 /* Output no assembler code for a function declaration.
1377 Only definitions of functions output anything. */
1379 if (TREE_CODE (decl) == FUNCTION_DECL)
1380 return;
1382 /* If type was incomplete when the variable was declared,
1383 see if it is complete now. */
1385 if (DECL_SIZE (decl) == 0)
1386 layout_decl (decl, 0);
1388 /* Still incomplete => don't allocate it; treat the tentative defn
1389 (which is what it must have been) as an `extern' reference. */
1391 if (!dont_output_data && DECL_SIZE (decl) == 0)
1393 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1394 DECL_SOURCE_LINE (decl),
1395 "storage size of `%s' isn't known",
1396 IDENTIFIER_POINTER (DECL_NAME (decl)));
1397 TREE_ASM_WRITTEN (decl) = 1;
1398 return;
1401 /* The first declaration of a variable that comes through this function
1402 decides whether it is global (in C, has external linkage)
1403 or local (in C, has internal linkage). So do nothing more
1404 if this function has already run. */
1406 if (TREE_ASM_WRITTEN (decl))
1407 return;
1409 TREE_ASM_WRITTEN (decl) = 1;
1411 /* Do no output if -fsyntax-only. */
1412 if (flag_syntax_only)
1413 return;
1415 app_disable ();
1417 if (! dont_output_data)
1419 int size;
1421 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1422 goto finish;
1424 /* This is better than explicit arithmetic, since it avoids overflow. */
1425 size_tree = size_binop (CEIL_DIV_EXPR,
1426 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1428 size = TREE_INT_CST_LOW (size_tree);
1429 if (TREE_INT_CST_HIGH (size_tree) != 0
1430 || size != TREE_INT_CST_LOW (size_tree))
1432 error_with_decl (decl, "size of variable `%s' is too large");
1433 goto finish;
1437 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1439 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1440 && ! first_global_object_name
1441 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1442 || DECL_INITIAL (decl) == error_mark_node))
1443 && ! DECL_WEAK (decl)
1444 && ! DECL_ONE_ONLY (decl))
1446 const char *p;
1448 STRIP_NAME_ENCODING (p, name);
1449 first_global_object_name = permalloc (strlen (p) + 1);
1450 strcpy (first_global_object_name, p);
1453 /* Compute the alignment of this data. */
1455 align = DECL_ALIGN (decl);
1457 /* In the case for initialing an array whose length isn't specified,
1458 where we have not yet been able to do the layout,
1459 figure out the proper alignment now. */
1460 if (dont_output_data && DECL_SIZE (decl) == 0
1461 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1462 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1464 /* Some object file formats have a maximum alignment which they support.
1465 In particular, a.out format supports a maximum alignment of 4. */
1466 #ifndef MAX_OFILE_ALIGNMENT
1467 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1468 #endif
1469 if (align > MAX_OFILE_ALIGNMENT)
1471 warning_with_decl (decl,
1472 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1473 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1474 align = MAX_OFILE_ALIGNMENT;
1477 /* On some machines, it is good to increase alignment sometimes. */
1478 #ifdef DATA_ALIGNMENT
1479 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1480 #endif
1481 #ifdef CONSTANT_ALIGNMENT
1482 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1483 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1484 #endif
1486 /* Reset the alignment in case we have made it tighter, so we can benefit
1487 from it in get_pointer_alignment. */
1488 DECL_ALIGN (decl) = align;
1490 /* Handle uninitialized definitions. */
1492 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1493 /* If the target can't output uninitialized but not common global data
1494 in .bss, then we have to use .data. */
1495 #if ! defined ASM_EMIT_BSS
1496 && DECL_COMMON (decl)
1497 #endif
1498 && DECL_SECTION_NAME (decl) == 0
1499 && ! dont_output_data)
1501 int size = TREE_INT_CST_LOW (size_tree);
1502 int rounded = size;
1504 /* Don't allocate zero bytes of common,
1505 since that means "undefined external" in the linker. */
1506 if (size == 0) rounded = 1;
1507 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1508 so that each uninitialized object starts on such a boundary. */
1509 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1510 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1511 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1513 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1514 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1515 warning_with_decl
1516 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1517 #endif
1519 #ifdef DBX_DEBUGGING_INFO
1520 /* File-scope global variables are output here. */
1521 if (write_symbols == DBX_DEBUG && top_level)
1522 dbxout_symbol (decl, 0);
1523 #endif
1524 #ifdef SDB_DEBUGGING_INFO
1525 if (write_symbols == SDB_DEBUG && top_level
1526 /* Leave initialized global vars for end of compilation;
1527 see comment in compile_file. */
1528 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1529 sdbout_symbol (decl, 0);
1530 #endif
1532 /* Don't output any DWARF debugging information for variables here.
1533 In the case of local variables, the information for them is output
1534 when we do our recursive traversal of the tree representation for
1535 the entire containing function. In the case of file-scope variables,
1536 we output information for all of them at the very end of compilation
1537 while we are doing our final traversal of the chain of file-scope
1538 declarations. */
1540 #if 0 /* ??? We should either delete this or add a comment describing what
1541 it was intended to do and why we shouldn't delete it. */
1542 if (flag_shared_data)
1543 data_section ();
1544 #endif
1545 asm_emit_uninitialised (decl, name, size, rounded);
1547 goto finish;
1550 /* Handle initialized definitions.
1551 Also handle uninitialized global definitions if -fno-common and the
1552 target doesn't support ASM_OUTPUT_BSS. */
1554 /* First make the assembler name(s) global if appropriate. */
1555 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1557 #ifdef ASM_WEAKEN_LABEL
1558 if (DECL_WEAK (decl))
1560 ASM_WEAKEN_LABEL (asm_out_file, name);
1561 /* Remove this variable from the pending weak list so that
1562 we do not emit multiple .weak directives for it. */
1563 remove_from_pending_weak_list
1564 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1566 else
1567 #endif
1568 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1570 #if 0
1571 for (d = equivalents; d; d = TREE_CHAIN (d))
1573 tree e = TREE_VALUE (d);
1574 if (TREE_PUBLIC (e) && DECL_NAME (e))
1575 ASM_GLOBALIZE_LABEL (asm_out_file,
1576 XSTR (XEXP (DECL_RTL (e), 0), 0));
1578 #endif
1580 /* Output any data that we will need to use the address of. */
1581 if (DECL_INITIAL (decl) == error_mark_node)
1582 reloc = contains_pointers_p (TREE_TYPE (decl));
1583 else if (DECL_INITIAL (decl))
1584 reloc = output_addressed_constants (DECL_INITIAL (decl));
1586 #ifdef ASM_OUTPUT_SECTION_NAME
1587 if ((flag_data_sections != 0
1588 && DECL_SECTION_NAME (decl) == NULL_TREE)
1589 || UNIQUE_SECTION_P (decl))
1590 UNIQUE_SECTION (decl, reloc);
1591 #endif
1593 /* Switch to the appropriate section. */
1594 variable_section (decl, reloc);
1596 /* dbxout.c needs to know this. */
1597 if (in_text_section ())
1598 DECL_IN_TEXT_SECTION (decl) = 1;
1600 /* Record current section so we can restore it if dbxout.c clobbers it. */
1601 saved_in_section = in_section;
1603 /* Output the dbx info now that we have chosen the section. */
1605 #ifdef DBX_DEBUGGING_INFO
1606 /* File-scope global variables are output here. */
1607 if (write_symbols == DBX_DEBUG && top_level)
1608 dbxout_symbol (decl, 0);
1609 #endif
1610 #ifdef SDB_DEBUGGING_INFO
1611 if (write_symbols == SDB_DEBUG && top_level
1612 /* Leave initialized global vars for end of compilation;
1613 see comment in compile_file. */
1614 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1615 sdbout_symbol (decl, 0);
1616 #endif
1618 /* Don't output any DWARF debugging information for variables here.
1619 In the case of local variables, the information for them is output
1620 when we do our recursive traversal of the tree representation for
1621 the entire containing function. In the case of file-scope variables,
1622 we output information for all of them at the very end of compilation
1623 while we are doing our final traversal of the chain of file-scope
1624 declarations. */
1626 /* If the debugging output changed sections, reselect the section
1627 that's supposed to be selected. */
1628 if (in_section != saved_in_section)
1629 variable_section (decl, reloc);
1631 /* Output the alignment of this data. */
1632 if (align > BITS_PER_UNIT)
1633 ASM_OUTPUT_ALIGN (asm_out_file,
1634 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1636 /* Do any machine/system dependent processing of the object. */
1637 #ifdef ASM_DECLARE_OBJECT_NAME
1638 last_assemble_variable_decl = decl;
1639 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1640 #else
1641 /* Standard thing is just output label for the object. */
1642 ASM_OUTPUT_LABEL (asm_out_file, name);
1643 #endif /* ASM_DECLARE_OBJECT_NAME */
1645 if (!dont_output_data)
1647 if (DECL_INITIAL (decl))
1648 /* Output the actual data. */
1649 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1650 else
1651 /* Leave space for it. */
1652 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1655 finish:
1656 #ifdef XCOFF_DEBUGGING_INFO
1657 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1658 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1659 and `aa' hasn't been output yet, the assembler generates a stab entry with
1660 a value of zero, in addition to creating an unnecessary external entry
1661 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1663 /* File-scope global variables are output here. */
1664 if (write_symbols == XCOFF_DEBUG && top_level)
1666 saved_in_section = in_section;
1668 dbxout_symbol (decl, 0);
1670 if (in_section != saved_in_section)
1671 variable_section (decl, reloc);
1673 #else
1674 /* There must be a statement after a label. */
1676 #endif
1679 /* Return 1 if type TYPE contains any pointers. */
1681 static int
1682 contains_pointers_p (type)
1683 tree type;
1685 switch (TREE_CODE (type))
1687 case POINTER_TYPE:
1688 case REFERENCE_TYPE:
1689 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1690 so I'll play safe and return 1. */
1691 case OFFSET_TYPE:
1692 return 1;
1694 case RECORD_TYPE:
1695 case UNION_TYPE:
1696 case QUAL_UNION_TYPE:
1698 tree fields;
1699 /* For a type that has fields, see if the fields have pointers. */
1700 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1701 if (TREE_CODE (fields) == FIELD_DECL
1702 && contains_pointers_p (TREE_TYPE (fields)))
1703 return 1;
1704 return 0;
1707 case ARRAY_TYPE:
1708 /* An array type contains pointers if its element type does. */
1709 return contains_pointers_p (TREE_TYPE (type));
1711 default:
1712 return 0;
1716 /* Output something to declare an external symbol to the assembler.
1717 (Most assemblers don't need this, so we normally output nothing.)
1718 Do nothing if DECL is not external. */
1720 void
1721 assemble_external (decl)
1722 tree decl ATTRIBUTE_UNUSED;
1724 #ifdef ASM_OUTPUT_EXTERNAL
1725 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1726 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1728 rtx rtl = DECL_RTL (decl);
1730 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1731 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1733 /* Some systems do require some output. */
1734 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1735 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1738 #endif
1741 /* Similar, for calling a library function FUN. */
1743 void
1744 assemble_external_libcall (fun)
1745 rtx fun ATTRIBUTE_UNUSED;
1747 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1748 /* Declare library function name external when first used, if nec. */
1749 if (! SYMBOL_REF_USED (fun))
1751 SYMBOL_REF_USED (fun) = 1;
1752 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1754 #endif
1757 /* Declare the label NAME global. */
1759 void
1760 assemble_global (name)
1761 char *name;
1763 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1766 /* Assemble a label named NAME. */
1768 void
1769 assemble_label (name)
1770 char *name;
1772 ASM_OUTPUT_LABEL (asm_out_file, name);
1775 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1776 If NAME starts with a *, the rest of NAME is output verbatim.
1777 Otherwise NAME is transformed in an implementation-defined way
1778 (usually by the addition of an underscore).
1779 Many macros in the tm file are defined to call this function. */
1781 void
1782 assemble_name (file, name)
1783 FILE *file;
1784 const char *name;
1786 const char *real_name;
1787 tree id;
1789 STRIP_NAME_ENCODING (real_name, name);
1790 if (flag_prefix_function_name
1791 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1792 real_name = real_name + CHKR_PREFIX_SIZE;
1794 id = maybe_get_identifier (real_name);
1795 if (id)
1796 TREE_SYMBOL_REFERENCED (id) = 1;
1798 if (name[0] == '*')
1799 fputs (&name[1], file);
1800 else
1801 ASM_OUTPUT_LABELREF (file, name);
1804 /* Allocate SIZE bytes writable static space with a gensym name
1805 and return an RTX to refer to its address. */
1808 assemble_static_space (size)
1809 int size;
1811 char name[12];
1812 char *namestring;
1813 rtx x;
1815 #if 0
1816 if (flag_shared_data)
1817 data_section ();
1818 #endif
1820 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1821 ++const_labelno;
1822 namestring = ggc_alloc_string (name, -1);
1824 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1826 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1827 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1828 BIGGEST_ALIGNMENT);
1829 #else
1830 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1831 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1832 #else
1834 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1835 so that each uninitialized object starts on such a boundary. */
1836 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1837 int rounded ATTRIBUTE_UNUSED
1838 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1839 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1840 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1841 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1843 #endif
1844 #endif
1845 return x;
1848 /* Assemble the static constant template for function entry trampolines.
1849 This is done at most once per compilation.
1850 Returns an RTX for the address of the template. */
1852 #ifdef TRAMPOLINE_TEMPLATE
1854 assemble_trampoline_template ()
1856 char label[256];
1857 char *name;
1858 int align;
1860 /* By default, put trampoline templates in read-only data section. */
1862 #ifdef TRAMPOLINE_SECTION
1863 TRAMPOLINE_SECTION ();
1864 #else
1865 readonly_data_section ();
1866 #endif
1868 /* Write the assembler code to define one. */
1869 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1870 if (align > 0)
1871 ASM_OUTPUT_ALIGN (asm_out_file, align);
1873 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1874 TRAMPOLINE_TEMPLATE (asm_out_file);
1876 /* Record the rtl to refer to it. */
1877 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1878 name = ggc_alloc_string (label, -1);
1879 return gen_rtx_SYMBOL_REF (Pmode, name);
1881 #endif
1883 /* Assemble the integer constant X into an object of SIZE bytes.
1884 X must be either a CONST_INT or CONST_DOUBLE.
1886 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1887 non-zero, abort if we can't output the constant. */
1890 assemble_integer (x, size, force)
1891 rtx x;
1892 int size;
1893 int force;
1895 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1896 ASM_OUTPUT... macros. */
1898 switch (size)
1900 #ifdef ASM_OUTPUT_CHAR
1901 case 1:
1902 ASM_OUTPUT_CHAR (asm_out_file, x);
1903 return 1;
1904 #endif
1906 #ifdef ASM_OUTPUT_SHORT
1907 case 2:
1908 ASM_OUTPUT_SHORT (asm_out_file, x);
1909 return 1;
1910 #endif
1912 #ifdef ASM_OUTPUT_INT
1913 case 4:
1914 ASM_OUTPUT_INT (asm_out_file, x);
1915 return 1;
1916 #endif
1918 #ifdef ASM_OUTPUT_DOUBLE_INT
1919 case 8:
1920 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1921 return 1;
1922 #endif
1924 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1925 case 16:
1926 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1927 return 1;
1928 #endif
1931 /* If we couldn't do it that way, there are two other possibilities: First,
1932 if the machine can output an explicit byte and this is a 1 byte constant,
1933 we can use ASM_OUTPUT_BYTE. */
1935 #ifdef ASM_OUTPUT_BYTE
1936 if (size == 1 && GET_CODE (x) == CONST_INT)
1938 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1939 return 1;
1941 #endif
1943 /* Finally, if SIZE is larger than a single word, try to output the constant
1944 one word at a time. */
1946 if (size > UNITS_PER_WORD)
1948 int i;
1949 enum machine_mode mode
1950 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1951 rtx word;
1953 for (i = 0; i < size / UNITS_PER_WORD; i++)
1955 word = operand_subword (x, i, 0, mode);
1957 if (word == 0)
1958 break;
1960 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1961 break;
1964 if (i == size / UNITS_PER_WORD)
1965 return 1;
1966 /* If we output at least one word and then could not finish,
1967 there is no valid way to continue. */
1968 if (i > 0)
1969 abort ();
1972 if (force)
1973 abort ();
1975 return 0;
1978 /* Assemble the floating-point constant D into an object of size MODE. */
1980 void
1981 assemble_real (d, mode)
1982 REAL_VALUE_TYPE d;
1983 enum machine_mode mode;
1985 jmp_buf output_constant_handler;
1987 if (setjmp (output_constant_handler))
1989 error ("floating point trap outputting a constant");
1990 #ifdef REAL_IS_NOT_DOUBLE
1991 bzero ((char *) &d, sizeof d);
1992 d = dconst0;
1993 #else
1994 d = 0;
1995 #endif
1998 set_float_handler (output_constant_handler);
2000 switch (mode)
2002 #ifdef ASM_OUTPUT_BYTE_FLOAT
2003 case QFmode:
2004 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
2005 break;
2006 #endif
2007 #ifdef ASM_OUTPUT_SHORT_FLOAT
2008 case HFmode:
2009 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
2010 break;
2011 #endif
2012 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2013 case TQFmode:
2014 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
2015 break;
2016 #endif
2017 #ifdef ASM_OUTPUT_FLOAT
2018 case SFmode:
2019 ASM_OUTPUT_FLOAT (asm_out_file, d);
2020 break;
2021 #endif
2023 #ifdef ASM_OUTPUT_DOUBLE
2024 case DFmode:
2025 ASM_OUTPUT_DOUBLE (asm_out_file, d);
2026 break;
2027 #endif
2029 #ifdef ASM_OUTPUT_LONG_DOUBLE
2030 case XFmode:
2031 case TFmode:
2032 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
2033 break;
2034 #endif
2036 default:
2037 abort ();
2040 set_float_handler (NULL_PTR);
2043 /* Here we combine duplicate floating constants to make
2044 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2046 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2047 For an integer, I0 is the low-order word and I1 is the high-order word.
2048 For a real number, I0 is the word with the low address
2049 and I1 is the word with the high address. */
2052 immed_double_const (i0, i1, mode)
2053 HOST_WIDE_INT i0, i1;
2054 enum machine_mode mode;
2056 register rtx r;
2058 if (GET_MODE_CLASS (mode) == MODE_INT
2059 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2061 /* We clear out all bits that don't belong in MODE, unless they and our
2062 sign bit are all one. So we get either a reasonable negative value
2063 or a reasonable unsigned value for this mode. */
2064 int width = GET_MODE_BITSIZE (mode);
2065 if (width < HOST_BITS_PER_WIDE_INT
2066 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2067 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2068 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2069 else if (width == HOST_BITS_PER_WIDE_INT
2070 && ! (i1 == ~0 && i0 < 0))
2071 i1 = 0;
2072 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2073 /* We cannot represent this value as a constant. */
2074 abort ();
2076 /* If this would be an entire word for the target, but is not for
2077 the host, then sign-extend on the host so that the number will look
2078 the same way on the host that it would on the target.
2080 For example, when building a 64 bit alpha hosted 32 bit sparc
2081 targeted compiler, then we want the 32 bit unsigned value -1 to be
2082 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2083 The later confuses the sparc backend. */
2085 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2086 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2087 i0 |= ((HOST_WIDE_INT) (-1) << width);
2089 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2091 ??? Strictly speaking, this is wrong if we create a CONST_INT
2092 for a large unsigned constant with the size of MODE being
2093 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2094 wider mode. In that case we will mis-interpret it as a negative
2095 number.
2097 Unfortunately, the only alternative is to make a CONST_DOUBLE
2098 for any constant in any mode if it is an unsigned constant larger
2099 than the maximum signed integer in an int on the host. However,
2100 doing this will break everyone that always expects to see a CONST_INT
2101 for SImode and smaller.
2103 We have always been making CONST_INTs in this case, so nothing new
2104 is being broken. */
2106 if (width <= HOST_BITS_PER_WIDE_INT)
2107 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2109 /* If this integer fits in one word, return a CONST_INT. */
2110 if ((i1 == 0 && i0 >= 0)
2111 || (i1 == ~0 && i0 < 0))
2112 return GEN_INT (i0);
2114 /* We use VOIDmode for integers. */
2115 mode = VOIDmode;
2118 /* Search the chain for an existing CONST_DOUBLE with the right value.
2119 If one is found, return it. */
2120 if (current_function != 0)
2121 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2122 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2123 && GET_MODE (r) == mode)
2124 return r;
2126 /* No; make a new one and add it to the chain.
2128 We may be called by an optimizer which may be discarding any memory
2129 allocated during its processing (such as combine and loop). However,
2130 we will be leaving this constant on the chain, so we cannot tolerate
2131 freed memory. So switch to saveable_obstack for this allocation
2132 and then switch back if we were in current_obstack. */
2134 push_obstacks_nochange ();
2135 rtl_in_saveable_obstack ();
2136 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2137 pop_obstacks ();
2139 /* Don't touch const_double_chain if not inside any function. */
2140 if (current_function_decl != 0)
2142 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2143 const_double_chain = r;
2146 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2147 Actual use of mem-slot is only through force_const_mem. */
2149 CONST_DOUBLE_MEM (r) = const0_rtx;
2151 return r;
2154 /* Return a CONST_DOUBLE for a specified `double' value
2155 and machine mode. */
2158 immed_real_const_1 (d, mode)
2159 REAL_VALUE_TYPE d;
2160 enum machine_mode mode;
2162 union real_extract u;
2163 register rtx r;
2165 /* Get the desired `double' value as a sequence of ints
2166 since that is how they are stored in a CONST_DOUBLE. */
2168 u.d = d;
2170 /* Detect special cases. */
2172 if (REAL_VALUES_IDENTICAL (dconst0, d))
2173 return CONST0_RTX (mode);
2174 /* Check for NaN first, because some ports (specifically the i386) do not
2175 emit correct ieee-fp code by default, and thus will generate a core
2176 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2177 does a floating point comparison. */
2178 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2179 return CONST1_RTX (mode);
2181 if (sizeof u == sizeof (HOST_WIDE_INT))
2182 return immed_double_const (u.i[0], 0, mode);
2183 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2184 return immed_double_const (u.i[0], u.i[1], mode);
2186 /* The rest of this function handles the case where
2187 a float value requires more than 2 ints of space.
2188 It will be deleted as dead code on machines that don't need it. */
2190 /* Search the chain for an existing CONST_DOUBLE with the right value.
2191 If one is found, return it. */
2192 if (current_function != 0)
2193 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2194 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2195 && GET_MODE (r) == mode)
2196 return r;
2198 /* No; make a new one and add it to the chain.
2200 We may be called by an optimizer which may be discarding any memory
2201 allocated during its processing (such as combine and loop). However,
2202 we will be leaving this constant on the chain, so we cannot tolerate
2203 freed memory. So switch to saveable_obstack for this allocation
2204 and then switch back if we were in current_obstack. */
2205 push_obstacks_nochange ();
2206 rtl_in_saveable_obstack ();
2207 r = rtx_alloc (CONST_DOUBLE);
2208 pop_obstacks ();
2209 PUT_MODE (r, mode);
2210 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2212 /* Don't touch const_double_chain if not inside any function. */
2213 if (current_function_decl != 0)
2215 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2216 const_double_chain = r;
2219 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2220 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2221 is only through force_const_mem. */
2223 CONST_DOUBLE_MEM (r) = const0_rtx;
2225 return r;
2228 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2229 which must be a REAL_CST tree node. */
2232 immed_real_const (exp)
2233 tree exp;
2235 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2238 /* At the end of a function, forget the memory-constants
2239 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2240 Also clear out real_constant_chain and clear out all the chain-pointers. */
2242 void
2243 clear_const_double_mem ()
2245 register rtx r, next;
2247 for (r = const_double_chain; r; r = next)
2249 next = CONST_DOUBLE_CHAIN (r);
2250 CONST_DOUBLE_CHAIN (r) = 0;
2251 CONST_DOUBLE_MEM (r) = cc0_rtx;
2253 const_double_chain = 0;
2256 /* Given an expression EXP with a constant value,
2257 reduce it to the sum of an assembler symbol and an integer.
2258 Store them both in the structure *VALUE.
2259 Abort if EXP does not reduce. */
2261 struct addr_const
2263 rtx base;
2264 HOST_WIDE_INT offset;
2267 static void
2268 decode_addr_const (exp, value)
2269 tree exp;
2270 struct addr_const *value;
2272 register tree target = TREE_OPERAND (exp, 0);
2273 register int offset = 0;
2274 register rtx x;
2276 while (1)
2278 if (TREE_CODE (target) == COMPONENT_REF
2279 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2280 == INTEGER_CST))
2282 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2283 target = TREE_OPERAND (target, 0);
2285 else if (TREE_CODE (target) == ARRAY_REF)
2287 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2288 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2289 abort ();
2290 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2291 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2292 / BITS_PER_UNIT);
2293 target = TREE_OPERAND (target, 0);
2295 else
2296 break;
2299 switch (TREE_CODE (target))
2301 case VAR_DECL:
2302 case FUNCTION_DECL:
2303 x = DECL_RTL (target);
2304 break;
2306 case LABEL_DECL:
2307 x = gen_rtx_MEM (FUNCTION_MODE,
2308 gen_rtx_LABEL_REF (VOIDmode,
2309 label_rtx (TREE_OPERAND (exp, 0))));
2310 break;
2312 case REAL_CST:
2313 case STRING_CST:
2314 case COMPLEX_CST:
2315 case CONSTRUCTOR:
2316 case INTEGER_CST:
2317 x = TREE_CST_RTL (target);
2318 break;
2320 default:
2321 abort ();
2324 if (GET_CODE (x) != MEM)
2325 abort ();
2326 x = XEXP (x, 0);
2328 value->base = x;
2329 value->offset = offset;
2332 /* Uniquize all constants that appear in memory.
2333 Each constant in memory thus far output is recorded
2334 in `const_hash_table' with a `struct constant_descriptor'
2335 that contains a polish representation of the value of
2336 the constant.
2338 We cannot store the trees in the hash table
2339 because the trees may be temporary. */
2341 struct constant_descriptor
2343 struct constant_descriptor *next;
2344 char *label;
2345 char contents[1];
2348 #define HASHBITS 30
2349 #define MAX_HASH_TABLE 1009
2350 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2352 /* Mark a const_hash_table descriptor for GC. */
2354 static void
2355 mark_const_hash_entry (ptr)
2356 void *ptr;
2358 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2360 while (desc)
2362 ggc_mark_string (desc->label);
2363 desc = desc->next;
2367 /* Compute a hash code for a constant expression. */
2369 static int
2370 const_hash (exp)
2371 tree exp;
2373 register char *p;
2374 register int len, hi, i;
2375 register enum tree_code code = TREE_CODE (exp);
2377 /* Either set P and LEN to the address and len of something to hash and
2378 exit the switch or return a value. */
2380 switch (code)
2382 case INTEGER_CST:
2383 p = (char *) &TREE_INT_CST_LOW (exp);
2384 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2385 break;
2387 case REAL_CST:
2388 p = (char *) &TREE_REAL_CST (exp);
2389 len = sizeof TREE_REAL_CST (exp);
2390 break;
2392 case STRING_CST:
2393 p = TREE_STRING_POINTER (exp);
2394 len = TREE_STRING_LENGTH (exp);
2395 break;
2397 case COMPLEX_CST:
2398 return (const_hash (TREE_REALPART (exp)) * 5
2399 + const_hash (TREE_IMAGPART (exp)));
2401 case CONSTRUCTOR:
2402 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2404 len = int_size_in_bytes (TREE_TYPE (exp));
2405 p = (char *) alloca (len);
2406 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2407 break;
2409 else
2411 register tree link;
2413 /* For record type, include the type in the hashing.
2414 We do not do so for array types
2415 because (1) the sizes of the elements are sufficient
2416 and (2) distinct array types can have the same constructor.
2417 Instead, we include the array size because the constructor could
2418 be shorter. */
2419 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2420 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2421 % MAX_HASH_TABLE;
2422 else
2423 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2424 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2426 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2427 if (TREE_VALUE (link))
2429 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2431 return hi;
2434 case ADDR_EXPR:
2436 struct addr_const value;
2438 decode_addr_const (exp, &value);
2439 if (GET_CODE (value.base) == SYMBOL_REF)
2441 /* Don't hash the address of the SYMBOL_REF;
2442 only use the offset and the symbol name. */
2443 hi = value.offset;
2444 p = XSTR (value.base, 0);
2445 for (i = 0; p[i] != 0; i++)
2446 hi = ((hi * 613) + (unsigned) (p[i]));
2448 else if (GET_CODE (value.base) == LABEL_REF)
2449 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2450 else
2451 abort();
2453 hi &= (1 << HASHBITS) - 1;
2454 hi %= MAX_HASH_TABLE;
2456 return hi;
2458 case PLUS_EXPR:
2459 case MINUS_EXPR:
2460 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2461 + const_hash (TREE_OPERAND (exp, 1)));
2463 case NOP_EXPR:
2464 case CONVERT_EXPR:
2465 case NON_LVALUE_EXPR:
2466 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2468 default:
2469 abort ();
2472 /* Compute hashing function */
2473 hi = len;
2474 for (i = 0; i < len; i++)
2475 hi = ((hi * 613) + (unsigned) (p[i]));
2477 hi &= (1 << HASHBITS) - 1;
2478 hi %= MAX_HASH_TABLE;
2479 return hi;
2482 /* Compare a constant expression EXP with a constant-descriptor DESC.
2483 Return 1 if DESC describes a constant with the same value as EXP. */
2485 static int
2486 compare_constant (exp, desc)
2487 tree exp;
2488 struct constant_descriptor *desc;
2490 return 0 != compare_constant_1 (exp, desc->contents);
2493 /* Compare constant expression EXP with a substring P of a constant descriptor.
2494 If they match, return a pointer to the end of the substring matched.
2495 If they do not match, return 0.
2497 Since descriptors are written in polish prefix notation,
2498 this function can be used recursively to test one operand of EXP
2499 against a subdescriptor, and if it succeeds it returns the
2500 address of the subdescriptor for the next operand. */
2502 static char *
2503 compare_constant_1 (exp, p)
2504 tree exp;
2505 char *p;
2507 register char *strp;
2508 register int len;
2509 register enum tree_code code = TREE_CODE (exp);
2511 if (code != (enum tree_code) *p++)
2512 return 0;
2514 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2515 switch, or return the result of the comparison. */
2517 switch (code)
2519 case INTEGER_CST:
2520 /* Integer constants are the same only if the same width of type. */
2521 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2522 return 0;
2524 strp = (char *) &TREE_INT_CST_LOW (exp);
2525 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2526 break;
2528 case REAL_CST:
2529 /* Real constants are the same only if the same width of type. */
2530 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2531 return 0;
2533 strp = (char *) &TREE_REAL_CST (exp);
2534 len = sizeof TREE_REAL_CST (exp);
2535 break;
2537 case STRING_CST:
2538 if (flag_writable_strings)
2539 return 0;
2541 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2542 return 0;
2544 strp = TREE_STRING_POINTER (exp);
2545 len = TREE_STRING_LENGTH (exp);
2546 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2547 sizeof TREE_STRING_LENGTH (exp)))
2548 return 0;
2550 p += sizeof TREE_STRING_LENGTH (exp);
2551 break;
2553 case COMPLEX_CST:
2554 p = compare_constant_1 (TREE_REALPART (exp), p);
2555 if (p == 0)
2556 return 0;
2558 return compare_constant_1 (TREE_IMAGPART (exp), p);
2560 case CONSTRUCTOR:
2561 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2563 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2565 strp = (char *) alloca (len);
2566 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2567 if (bcmp ((char *) &xlen, p, sizeof xlen))
2568 return 0;
2570 p += sizeof xlen;
2571 break;
2573 else
2575 register tree link;
2576 int length = list_length (CONSTRUCTOR_ELTS (exp));
2577 tree type;
2578 int have_purpose = 0;
2580 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2581 if (TREE_PURPOSE (link))
2582 have_purpose = 1;
2584 if (bcmp ((char *) &length, p, sizeof length))
2585 return 0;
2587 p += sizeof length;
2589 /* For record constructors, insist that the types match.
2590 For arrays, just verify both constructors are for arrays.
2591 Then insist that either both or none have any TREE_PURPOSE
2592 values. */
2593 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2594 type = TREE_TYPE (exp);
2595 else
2596 type = 0;
2598 if (bcmp ((char *) &type, p, sizeof type))
2599 return 0;
2601 p += sizeof type;
2603 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2604 return 0;
2606 p += sizeof have_purpose;
2608 /* For arrays, insist that the size in bytes match. */
2609 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2611 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2613 if (bcmp ((char *) &size, p, sizeof size))
2614 return 0;
2616 p += sizeof size;
2619 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2621 if (TREE_VALUE (link))
2623 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2624 return 0;
2626 else
2628 tree zero = 0;
2630 if (bcmp ((char *) &zero, p, sizeof zero))
2631 return 0;
2633 p += sizeof zero;
2636 if (TREE_PURPOSE (link)
2637 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2639 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2640 sizeof TREE_PURPOSE (link)))
2641 return 0;
2643 p += sizeof TREE_PURPOSE (link);
2645 else if (TREE_PURPOSE (link))
2647 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2648 return 0;
2650 else if (have_purpose)
2652 int zero = 0;
2654 if (bcmp ((char *) &zero, p, sizeof zero))
2655 return 0;
2657 p += sizeof zero;
2661 return p;
2664 case ADDR_EXPR:
2666 struct addr_const value;
2668 decode_addr_const (exp, &value);
2669 strp = (char *) &value.offset;
2670 len = sizeof value.offset;
2671 /* Compare the offset. */
2672 while (--len >= 0)
2673 if (*p++ != *strp++)
2674 return 0;
2676 /* Compare symbol name. */
2677 strp = XSTR (value.base, 0);
2678 len = strlen (strp) + 1;
2680 break;
2682 case PLUS_EXPR:
2683 case MINUS_EXPR:
2684 case RANGE_EXPR:
2685 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2686 if (p == 0)
2687 return 0;
2689 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2691 case NOP_EXPR:
2692 case CONVERT_EXPR:
2693 case NON_LVALUE_EXPR:
2694 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2696 default:
2697 abort ();
2700 /* Compare constant contents. */
2701 while (--len >= 0)
2702 if (*p++ != *strp++)
2703 return 0;
2705 return p;
2708 /* Construct a constant descriptor for the expression EXP.
2709 It is up to the caller to enter the descriptor in the hash table. */
2711 static struct constant_descriptor *
2712 record_constant (exp)
2713 tree exp;
2715 struct constant_descriptor *next = 0;
2716 char *label = 0;
2718 /* Make a struct constant_descriptor. The first two pointers will
2719 be filled in later. Here we just leave space for them. */
2721 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2722 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2723 record_constant_1 (exp);
2724 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2727 /* Add a description of constant expression EXP
2728 to the object growing in `permanent_obstack'.
2729 No need to return its address; the caller will get that
2730 from the obstack when the object is complete. */
2732 static void
2733 record_constant_1 (exp)
2734 tree exp;
2736 register char *strp;
2737 register int len;
2738 register enum tree_code code = TREE_CODE (exp);
2740 obstack_1grow (&permanent_obstack, (unsigned int) code);
2742 switch (code)
2744 case INTEGER_CST:
2745 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2746 strp = (char *) &TREE_INT_CST_LOW (exp);
2747 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2748 break;
2750 case REAL_CST:
2751 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2752 strp = (char *) &TREE_REAL_CST (exp);
2753 len = sizeof TREE_REAL_CST (exp);
2754 break;
2756 case STRING_CST:
2757 if (flag_writable_strings)
2758 return;
2760 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2761 strp = TREE_STRING_POINTER (exp);
2762 len = TREE_STRING_LENGTH (exp);
2763 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2764 sizeof TREE_STRING_LENGTH (exp));
2765 break;
2767 case COMPLEX_CST:
2768 record_constant_1 (TREE_REALPART (exp));
2769 record_constant_1 (TREE_IMAGPART (exp));
2770 return;
2772 case CONSTRUCTOR:
2773 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2775 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2776 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2777 obstack_blank (&permanent_obstack, nbytes);
2778 get_set_constructor_bytes
2779 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2780 nbytes);
2781 return;
2783 else
2785 register tree link;
2786 int length = list_length (CONSTRUCTOR_ELTS (exp));
2787 tree type;
2788 int have_purpose = 0;
2790 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2791 if (TREE_PURPOSE (link))
2792 have_purpose = 1;
2794 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2796 /* For record constructors, insist that the types match.
2797 For arrays, just verify both constructors are for arrays.
2798 Then insist that either both or none have any TREE_PURPOSE
2799 values. */
2800 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2801 type = TREE_TYPE (exp);
2802 else
2803 type = 0;
2804 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2805 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2806 sizeof have_purpose);
2808 /* For arrays, insist that the size in bytes match. */
2809 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2811 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2812 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2815 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2817 if (TREE_VALUE (link))
2818 record_constant_1 (TREE_VALUE (link));
2819 else
2821 tree zero = 0;
2823 obstack_grow (&permanent_obstack,
2824 (char *) &zero, sizeof zero);
2827 if (TREE_PURPOSE (link)
2828 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2829 obstack_grow (&permanent_obstack,
2830 (char *) &TREE_PURPOSE (link),
2831 sizeof TREE_PURPOSE (link));
2832 else if (TREE_PURPOSE (link))
2833 record_constant_1 (TREE_PURPOSE (link));
2834 else if (have_purpose)
2836 int zero = 0;
2838 obstack_grow (&permanent_obstack,
2839 (char *) &zero, sizeof zero);
2843 return;
2845 case ADDR_EXPR:
2847 struct addr_const value;
2849 decode_addr_const (exp, &value);
2850 /* Record the offset. */
2851 obstack_grow (&permanent_obstack,
2852 (char *) &value.offset, sizeof value.offset);
2853 /* Record the symbol name. */
2854 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2855 strlen (XSTR (value.base, 0)) + 1);
2857 return;
2859 case PLUS_EXPR:
2860 case MINUS_EXPR:
2861 case RANGE_EXPR:
2862 record_constant_1 (TREE_OPERAND (exp, 0));
2863 record_constant_1 (TREE_OPERAND (exp, 1));
2864 return;
2866 case NOP_EXPR:
2867 case CONVERT_EXPR:
2868 case NON_LVALUE_EXPR:
2869 record_constant_1 (TREE_OPERAND (exp, 0));
2870 return;
2872 default:
2873 abort ();
2876 /* Record constant contents. */
2877 obstack_grow (&permanent_obstack, strp, len);
2880 /* Record a list of constant expressions that were passed to
2881 output_constant_def but that could not be output right away. */
2883 struct deferred_constant
2885 struct deferred_constant *next;
2886 tree exp;
2887 int reloc;
2888 int labelno;
2891 static struct deferred_constant *deferred_constants;
2893 /* Another list of constants which should be output after the
2894 function. */
2895 static struct deferred_constant *after_function_constants;
2897 /* Nonzero means defer output of addressed subconstants
2898 (i.e., those for which output_constant_def is called.) */
2899 static int defer_addressed_constants_flag;
2901 /* Start deferring output of subconstants. */
2903 void
2904 defer_addressed_constants ()
2906 defer_addressed_constants_flag++;
2909 /* Stop deferring output of subconstants,
2910 and output now all those that have been deferred. */
2912 void
2913 output_deferred_addressed_constants ()
2915 struct deferred_constant *p, *next;
2917 defer_addressed_constants_flag--;
2919 if (defer_addressed_constants_flag > 0)
2920 return;
2922 for (p = deferred_constants; p; p = next)
2924 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2925 next = p->next;
2926 free (p);
2929 deferred_constants = 0;
2932 /* Output any constants which should appear after a function. */
2934 static void
2935 output_after_function_constants ()
2937 struct deferred_constant *p, *next;
2939 for (p = after_function_constants; p; p = next)
2941 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2942 next = p->next;
2943 free (p);
2946 after_function_constants = 0;
2949 /* Make a copy of the whole tree structure for a constant.
2950 This handles the same types of nodes that compare_constant
2951 and record_constant handle. */
2953 static tree
2954 copy_constant (exp)
2955 tree exp;
2957 switch (TREE_CODE (exp))
2959 case ADDR_EXPR:
2960 /* For ADDR_EXPR, we do not want to copy the decl whose address
2961 is requested. We do want to copy constants though. */
2962 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2963 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2964 copy_constant (TREE_OPERAND (exp, 0)));
2965 else
2966 return copy_node (exp);
2968 case INTEGER_CST:
2969 case REAL_CST:
2970 case STRING_CST:
2971 return copy_node (exp);
2973 case COMPLEX_CST:
2974 return build_complex (TREE_TYPE (exp),
2975 copy_constant (TREE_REALPART (exp)),
2976 copy_constant (TREE_IMAGPART (exp)));
2978 case PLUS_EXPR:
2979 case MINUS_EXPR:
2980 return build (TREE_CODE (exp), TREE_TYPE (exp),
2981 copy_constant (TREE_OPERAND (exp, 0)),
2982 copy_constant (TREE_OPERAND (exp, 1)));
2984 case NOP_EXPR:
2985 case CONVERT_EXPR:
2986 case NON_LVALUE_EXPR:
2987 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2988 copy_constant (TREE_OPERAND (exp, 0)));
2990 case CONSTRUCTOR:
2992 tree copy = copy_node (exp);
2993 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2994 tree tail;
2996 CONSTRUCTOR_ELTS (copy) = list;
2997 for (tail = list; tail; tail = TREE_CHAIN (tail))
2998 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2999 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3000 for (tail = list; tail; tail = TREE_CHAIN (tail))
3001 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3003 return copy;
3006 default:
3007 abort ();
3011 /* Return an rtx representing a reference to constant data in memory
3012 for the constant expression EXP.
3014 If assembler code for such a constant has already been output,
3015 return an rtx to refer to it.
3016 Otherwise, output such a constant in memory (or defer it for later)
3017 and generate an rtx for it.
3019 The TREE_CST_RTL of EXP is set up to point to that rtx.
3020 The const_hash_table records which constants already have label strings. */
3023 output_constant_def (exp)
3024 tree exp;
3026 register int hash;
3027 register struct constant_descriptor *desc;
3028 char label[256];
3029 char *found = 0;
3030 int reloc;
3031 register rtx def;
3033 if (TREE_CST_RTL (exp))
3034 return TREE_CST_RTL (exp);
3036 /* Make sure any other constants whose addresses appear in EXP
3037 are assigned label numbers. */
3039 reloc = output_addressed_constants (exp);
3041 /* Compute hash code of EXP. Search the descriptors for that hash code
3042 to see if any of them describes EXP. If yes, the descriptor records
3043 the label number already assigned. */
3045 hash = const_hash (exp) % MAX_HASH_TABLE;
3047 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3048 if (compare_constant (exp, desc))
3050 found = desc->label;
3051 break;
3054 if (found == 0)
3056 /* No constant equal to EXP is known to have been output.
3057 Make a constant descriptor to enter EXP in the hash table.
3058 Assign the label number and record it in the descriptor for
3059 future calls to this function to find. */
3061 /* Create a string containing the label name, in LABEL. */
3062 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3064 desc = record_constant (exp);
3065 desc->next = const_hash_table[hash];
3066 desc->label = ggc_alloc_string (label, -1);
3067 const_hash_table[hash] = desc;
3070 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3072 push_obstacks_nochange ();
3073 if (TREE_PERMANENT (exp))
3074 end_temporary_allocation ();
3076 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
3078 TREE_CST_RTL (exp)
3079 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
3080 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
3081 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
3082 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
3084 pop_obstacks ();
3086 /* Optionally set flags or add text to the name to record information
3087 such as that it is a function name. If the name is changed, the macro
3088 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3089 #ifdef ENCODE_SECTION_INFO
3090 ENCODE_SECTION_INFO (exp);
3091 #endif
3093 /* If this is the first time we've seen this particular constant,
3094 output it (or defer its output for later). */
3095 if (found == 0)
3097 int after_function = 0;
3099 #ifdef CONSTANT_AFTER_FUNCTION_P
3100 if (current_function_decl != 0
3101 && CONSTANT_AFTER_FUNCTION_P (exp))
3102 after_function = 1;
3103 #endif
3105 if (defer_addressed_constants_flag || after_function)
3107 struct deferred_constant *p;
3108 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3110 push_obstacks_nochange ();
3111 suspend_momentary ();
3112 p->exp = copy_constant (exp);
3113 pop_obstacks ();
3114 p->reloc = reloc;
3115 p->labelno = const_labelno++;
3116 if (after_function)
3118 p->next = after_function_constants;
3119 after_function_constants = p;
3121 else
3123 p->next = deferred_constants;
3124 deferred_constants = p;
3127 else
3129 /* Do no output if -fsyntax-only. */
3130 if (! flag_syntax_only)
3131 output_constant_def_contents (exp, reloc, const_labelno);
3132 ++const_labelno;
3136 return TREE_CST_RTL (exp);
3139 /* Now output assembler code to define the label for EXP,
3140 and follow it with the data of EXP. */
3142 static void
3143 output_constant_def_contents (exp, reloc, labelno)
3144 tree exp;
3145 int reloc;
3146 int labelno;
3148 int align;
3150 if (IN_NAMED_SECTION (exp))
3151 named_section (exp, NULL, reloc);
3152 else
3154 /* First switch to text section, except for writable strings. */
3155 #ifdef SELECT_SECTION
3156 SELECT_SECTION (exp, reloc);
3157 #else
3158 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3159 || (flag_pic && reloc))
3160 data_section ();
3161 else
3162 readonly_data_section ();
3163 #endif
3166 /* Align the location counter as required by EXP's data type. */
3167 align = TYPE_ALIGN (TREE_TYPE (exp));
3168 #ifdef CONSTANT_ALIGNMENT
3169 align = CONSTANT_ALIGNMENT (exp, align);
3170 #endif
3172 if (align > BITS_PER_UNIT)
3173 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3175 /* Output the label itself. */
3176 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3178 /* Output the value of EXP. */
3179 output_constant (exp,
3180 (TREE_CODE (exp) == STRING_CST
3181 ? TREE_STRING_LENGTH (exp)
3182 : int_size_in_bytes (TREE_TYPE (exp))));
3186 /* Structure to represent sufficient information about a constant so that
3187 it can be output when the constant pool is output, so that function
3188 integration can be done, and to simplify handling on machines that reference
3189 constant pool as base+displacement. */
3191 struct pool_constant
3193 struct constant_descriptor *desc;
3194 struct pool_constant *next;
3195 enum machine_mode mode;
3196 rtx constant;
3197 int labelno;
3198 int align;
3199 int offset;
3200 int mark;
3203 /* Structure used to maintain hash table mapping symbols used to their
3204 corresponding constants. */
3206 struct pool_sym
3208 char *label;
3209 struct pool_constant *pool;
3210 struct pool_sym *next;
3213 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3214 The argument is XSTR (... , 0) */
3216 #define SYMHASH(LABEL) \
3217 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3219 /* Initialize constant pool hashing for a new function. */
3221 void
3222 init_varasm_status (f)
3223 struct function *f;
3225 struct varasm_status *p;
3226 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3227 f->varasm = p;
3228 p->x_const_rtx_hash_table
3229 = ((struct constant_descriptor **)
3230 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3231 p->x_const_rtx_sym_hash_table
3232 = ((struct pool_sym **)
3233 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3234 bzero ((char *) p->x_const_rtx_hash_table,
3235 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3236 bzero ((char *) p->x_const_rtx_sym_hash_table,
3237 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3239 p->x_first_pool = p->x_last_pool = 0;
3240 p->x_pool_offset = 0;
3241 p->x_const_double_chain = 0;
3244 /* Mark PC for GC. */
3246 static void
3247 mark_pool_constant (pc)
3248 struct pool_constant *pc;
3250 while (pc)
3252 ggc_mark_rtx (pc->constant);
3253 pc = pc->next;
3257 /* Mark PPS for GC. */
3259 static void
3260 mark_pool_sym_hash_table (pps)
3261 struct pool_sym **pps;
3263 struct pool_sym *ps;
3264 int i;
3266 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3267 for (ps = pps[i]; ps ; ps = ps->next)
3268 ggc_mark_string (ps->label);
3271 /* Mark P for GC. */
3273 void
3274 mark_varasm_status (p)
3275 struct varasm_status *p;
3277 if (p == NULL)
3278 return;
3280 mark_pool_constant (p->x_first_pool);
3281 mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
3282 ggc_mark_rtx (p->x_const_double_chain);
3285 /* Clear out all parts of the state in F that can safely be discarded
3286 after the function has been compiled, to let garbage collection
3287 reclaim the memory. */
3289 void
3290 free_varasm_status (f)
3291 struct function *f;
3293 struct varasm_status *p;
3295 p = f->varasm;
3296 free (p->x_const_rtx_hash_table);
3297 free (p->x_const_rtx_sym_hash_table);
3298 free (p);
3299 f->varasm = NULL;
3302 enum kind { RTX_DOUBLE, RTX_INT };
3304 struct rtx_const
3306 #ifdef ONLY_INT_FIELDS
3307 unsigned int kind : 16;
3308 unsigned int mode : 16;
3309 #else
3310 enum kind kind : 16;
3311 enum machine_mode mode : 16;
3312 #endif
3313 union {
3314 union real_extract du;
3315 struct addr_const addr;
3316 struct {HOST_WIDE_INT high, low;} di;
3317 } un;
3320 /* Express an rtx for a constant integer (perhaps symbolic)
3321 as the sum of a symbol or label plus an explicit integer.
3322 They are stored into VALUE. */
3324 static void
3325 decode_rtx_const (mode, x, value)
3326 enum machine_mode mode;
3327 rtx x;
3328 struct rtx_const *value;
3330 /* Clear the whole structure, including any gaps. */
3333 int *p = (int *) value;
3334 int *end = (int *) (value + 1);
3335 while (p < end)
3336 *p++ = 0;
3339 value->kind = RTX_INT; /* Most usual kind. */
3340 value->mode = mode;
3342 switch (GET_CODE (x))
3344 case CONST_DOUBLE:
3345 value->kind = RTX_DOUBLE;
3346 if (GET_MODE (x) != VOIDmode)
3348 value->mode = GET_MODE (x);
3349 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3350 (char *) &value->un.du, sizeof value->un.du);
3352 else
3354 value->un.di.low = CONST_DOUBLE_LOW (x);
3355 value->un.di.high = CONST_DOUBLE_HIGH (x);
3357 break;
3359 case CONST_INT:
3360 value->un.addr.offset = INTVAL (x);
3361 break;
3363 case SYMBOL_REF:
3364 case LABEL_REF:
3365 case PC:
3366 value->un.addr.base = x;
3367 break;
3369 case CONST:
3370 x = XEXP (x, 0);
3371 if (GET_CODE (x) == PLUS)
3373 value->un.addr.base = XEXP (x, 0);
3374 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3375 abort ();
3376 value->un.addr.offset = INTVAL (XEXP (x, 1));
3378 else if (GET_CODE (x) == MINUS)
3380 value->un.addr.base = XEXP (x, 0);
3381 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3382 abort ();
3383 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3385 else
3386 abort ();
3387 break;
3389 default:
3390 abort ();
3393 if (value->kind == RTX_INT && value->un.addr.base != 0)
3394 switch (GET_CODE (value->un.addr.base))
3396 case SYMBOL_REF:
3397 case LABEL_REF:
3398 /* Use the string's address, not the SYMBOL_REF's address,
3399 for the sake of addresses of library routines.
3400 For a LABEL_REF, compare labels. */
3401 value->un.addr.base = XEXP (value->un.addr.base, 0);
3403 default:
3404 break;
3408 /* Given a MINUS expression, simplify it if both sides
3409 include the same symbol. */
3412 simplify_subtraction (x)
3413 rtx x;
3415 struct rtx_const val0, val1;
3417 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3418 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3420 if (val0.un.addr.base == val1.un.addr.base)
3421 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3422 return x;
3425 /* Compute a hash code for a constant RTL expression. */
3427 static int
3428 const_hash_rtx (mode, x)
3429 enum machine_mode mode;
3430 rtx x;
3432 register int hi;
3433 register size_t i;
3435 struct rtx_const value;
3436 decode_rtx_const (mode, x, &value);
3438 /* Compute hashing function */
3439 hi = 0;
3440 for (i = 0; i < sizeof value / sizeof (int); i++)
3441 hi += ((int *) &value)[i];
3443 hi &= (1 << HASHBITS) - 1;
3444 hi %= MAX_RTX_HASH_TABLE;
3445 return hi;
3448 /* Compare a constant rtl object X with a constant-descriptor DESC.
3449 Return 1 if DESC describes a constant with the same value as X. */
3451 static int
3452 compare_constant_rtx (mode, x, desc)
3453 enum machine_mode mode;
3454 rtx x;
3455 struct constant_descriptor *desc;
3457 register int *p = (int *) desc->contents;
3458 register int *strp;
3459 register int len;
3460 struct rtx_const value;
3462 decode_rtx_const (mode, x, &value);
3463 strp = (int *) &value;
3464 len = sizeof value / sizeof (int);
3466 /* Compare constant contents. */
3467 while (--len >= 0)
3468 if (*p++ != *strp++)
3469 return 0;
3471 return 1;
3474 /* Construct a constant descriptor for the rtl-expression X.
3475 It is up to the caller to enter the descriptor in the hash table. */
3477 static struct constant_descriptor *
3478 record_constant_rtx (mode, x)
3479 enum machine_mode mode;
3480 rtx x;
3482 struct constant_descriptor *ptr;
3483 char *label;
3484 struct rtx_const value;
3486 decode_rtx_const (mode, x, &value);
3488 /* Put these things in the saveable obstack so we can ensure it won't
3489 be freed if we are called from combine or some other phase that discards
3490 memory allocated from function_obstack (current_obstack). */
3491 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3492 obstack_grow (saveable_obstack, &label, sizeof label);
3494 /* Record constant contents. */
3495 obstack_grow (saveable_obstack, &value, sizeof value);
3497 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3500 /* Given a constant rtx X, make (or find) a memory constant for its value
3501 and return a MEM rtx to refer to it in memory. */
3504 force_const_mem (mode, x)
3505 enum machine_mode mode;
3506 rtx x;
3508 register int hash;
3509 register struct constant_descriptor *desc;
3510 char label[256];
3511 char *found = 0;
3512 rtx def;
3514 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3515 (this will always be true for floating CONST_DOUBLEs that have been
3516 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3517 use the previous copy. Otherwise, make a new one. Note that in
3518 the unlikely event that this same CONST_DOUBLE is used in two different
3519 modes in an alternating fashion, we will allocate a lot of different
3520 memory locations, but this should be extremely rare. */
3522 if (GET_CODE (x) == CONST_DOUBLE
3523 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3524 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3525 return CONST_DOUBLE_MEM (x);
3527 /* Compute hash code of X. Search the descriptors for that hash code
3528 to see if any of them describes X. If yes, the descriptor records
3529 the label number already assigned. */
3531 hash = const_hash_rtx (mode, x);
3533 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3534 if (compare_constant_rtx (mode, x, desc))
3536 found = desc->label;
3537 break;
3540 if (found == 0)
3542 register struct pool_constant *pool;
3543 register struct pool_sym *sym;
3544 int align;
3546 /* No constant equal to X is known to have been output.
3547 Make a constant descriptor to enter X in the hash table.
3548 Assign the label number and record it in the descriptor for
3549 future calls to this function to find. */
3551 desc = record_constant_rtx (mode, x);
3552 desc->next = const_rtx_hash_table[hash];
3553 const_rtx_hash_table[hash] = desc;
3555 /* Align the location counter as required by EXP's data type. */
3556 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3557 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3558 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3559 #ifdef CONSTANT_ALIGNMENT
3560 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3561 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3562 #endif
3564 pool_offset += align - 1;
3565 pool_offset &= ~ (align - 1);
3567 /* If RTL is not being placed into the saveable obstack, make a
3568 copy of X that is in the saveable obstack in case we are
3569 being called from combine or some other phase that discards
3570 memory it allocates. We used to only do this if it is a
3571 CONST; however, reload can allocate a CONST_INT when
3572 eliminating registers. */
3573 if (rtl_obstack != saveable_obstack
3574 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3576 push_obstacks_nochange ();
3577 rtl_in_saveable_obstack ();
3579 if (GET_CODE (x) == CONST)
3580 x = gen_rtx_CONST (GET_MODE (x),
3581 gen_rtx_PLUS (GET_MODE (x),
3582 XEXP (XEXP (x, 0), 0),
3583 XEXP (XEXP (x, 0), 1)));
3584 else
3585 x = GEN_INT (INTVAL (x));
3587 pop_obstacks ();
3590 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3592 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3593 pool->desc = desc;
3594 pool->constant = x;
3595 pool->mode = mode;
3596 pool->labelno = const_labelno;
3597 pool->align = align;
3598 pool->offset = pool_offset;
3599 pool->mark = 1;
3600 pool->next = 0;
3602 if (last_pool == 0)
3603 first_pool = pool;
3604 else
3605 last_pool->next = pool;
3607 last_pool = pool;
3608 pool_offset += GET_MODE_SIZE (mode);
3610 /* Create a string containing the label name, in LABEL. */
3611 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3613 ++const_labelno;
3615 desc->label = found = ggc_alloc_string (label, -1);
3617 /* Add label to symbol hash table. */
3618 hash = SYMHASH (found);
3619 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3620 sym->label = found;
3621 sym->pool = pool;
3622 sym->next = const_rtx_sym_hash_table[hash];
3623 const_rtx_sym_hash_table[hash] = sym;
3626 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3628 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3630 RTX_UNCHANGING_P (def) = 1;
3631 /* Mark the symbol_ref as belonging to this constants pool. */
3632 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3633 current_function_uses_const_pool = 1;
3635 if (GET_CODE (x) == CONST_DOUBLE)
3637 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3639 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3640 const_double_chain = x;
3642 CONST_DOUBLE_MEM (x) = def;
3645 return def;
3648 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3649 the corresponding pool_constant structure. */
3651 static struct pool_constant *
3652 find_pool_constant (f, addr)
3653 struct function *f;
3654 rtx addr;
3656 struct pool_sym *sym;
3657 char *label = XSTR (addr, 0);
3659 for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3660 if (sym->label == label)
3661 return sym->pool;
3663 abort ();
3666 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3669 get_pool_constant (addr)
3670 rtx addr;
3672 return (find_pool_constant (current_function, addr))->constant;
3675 /* Likewise, but for the constant pool of a specific function. */
3678 get_pool_constant_for_function (f, addr)
3679 struct function *f;
3680 rtx addr;
3682 return (find_pool_constant (f, addr))->constant;
3685 /* Similar, return the mode. */
3687 enum machine_mode
3688 get_pool_mode (addr)
3689 rtx addr;
3691 return (find_pool_constant (current_function, addr))->mode;
3694 enum machine_mode
3695 get_pool_mode_for_function (f, addr)
3696 struct function *f;
3697 rtx addr;
3699 return (find_pool_constant (f, addr))->mode;
3702 /* Similar, return the offset in the constant pool. */
3705 get_pool_offset (addr)
3706 rtx addr;
3708 return (find_pool_constant (current_function, addr))->offset;
3711 /* Return the size of the constant pool. */
3714 get_pool_size ()
3716 return pool_offset;
3719 /* Write all the constants in the constant pool. */
3721 void
3722 output_constant_pool (fnname, fndecl)
3723 char *fnname ATTRIBUTE_UNUSED;
3724 tree fndecl ATTRIBUTE_UNUSED;
3726 struct pool_constant *pool;
3727 rtx x;
3728 union real_extract u;
3730 /* It is possible for gcc to call force_const_mem and then to later
3731 discard the instructions which refer to the constant. In such a
3732 case we do not need to output the constant. */
3733 mark_constant_pool ();
3735 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3736 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3737 #endif
3739 for (pool = first_pool; pool; pool = pool->next)
3741 x = pool->constant;
3743 if (! pool->mark)
3744 continue;
3746 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3747 whose CODE_LABEL has been deleted. This can occur if a jump table
3748 is eliminated by optimization. If so, write a constant of zero
3749 instead. Note that this can also happen by turning the
3750 CODE_LABEL into a NOTE. */
3751 if (((GET_CODE (x) == LABEL_REF
3752 && (INSN_DELETED_P (XEXP (x, 0))
3753 || GET_CODE (XEXP (x, 0)) == NOTE)))
3754 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3755 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3756 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3757 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3758 x = const0_rtx;
3760 /* First switch to correct section. */
3761 #ifdef SELECT_RTX_SECTION
3762 SELECT_RTX_SECTION (pool->mode, x);
3763 #else
3764 readonly_data_section ();
3765 #endif
3767 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3768 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3769 pool->align, pool->labelno, done);
3770 #endif
3772 if (pool->align > 1)
3773 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3775 /* Output the label. */
3776 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3778 /* Output the value of the constant itself. */
3779 switch (GET_MODE_CLASS (pool->mode))
3781 case MODE_FLOAT:
3782 if (GET_CODE (x) != CONST_DOUBLE)
3783 abort ();
3785 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3786 assemble_real (u.d, pool->mode);
3787 break;
3789 case MODE_INT:
3790 case MODE_PARTIAL_INT:
3791 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3792 break;
3794 default:
3795 abort ();
3798 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3799 done: ;
3800 #endif
3804 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3805 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3806 #endif
3808 /* Done with this pool. */
3809 first_pool = last_pool = 0;
3812 /* Look through the instructions for this function, and mark all the
3813 entries in the constant pool which are actually being used. */
3815 static void
3816 mark_constant_pool ()
3818 register rtx insn;
3819 struct pool_constant *pool;
3821 if (first_pool == 0)
3822 return;
3824 for (pool = first_pool; pool; pool = pool->next)
3825 pool->mark = 0;
3827 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3828 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3829 mark_constants (PATTERN (insn));
3831 for (insn = current_function_epilogue_delay_list;
3832 insn;
3833 insn = XEXP (insn, 1))
3834 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3835 mark_constants (PATTERN (insn));
3837 /* It's possible that the only reference to a symbol is in a symbol
3838 that's in the constant pool. This happens in Fortran under some
3839 situations. (When the constant contains the address of another
3840 constant, and only the first is used directly in an insn.)
3841 This is potentially suboptimal if there's ever a possibility of
3842 backwards (in pool order) 2'd level references. However, it's
3843 not clear that 2'd level references can happen. */
3844 for (pool = first_pool; pool; pool = pool->next)
3846 struct pool_sym *sym;
3847 char *label;
3849 /* skip unmarked entries; no insn refers to them. */
3850 if (!pool->mark)
3851 continue;
3853 /* Skip everything except SYMBOL_REFs. */
3854 if (GET_CODE (pool->constant) != SYMBOL_REF)
3855 continue;
3856 label = XSTR (pool->constant, 0);
3858 /* Be sure the symbol's value is marked. */
3859 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3860 sym = sym->next)
3861 if (sym->label == label)
3862 sym->pool->mark = 1;
3863 /* If we didn't find it, there's something truly wrong here, but it
3864 will be announced by the assembler. */
3868 static void
3869 mark_constants (x)
3870 register rtx x;
3872 register int i;
3873 register const char *format_ptr;
3875 if (x == 0)
3876 return;
3878 if (GET_CODE (x) == SYMBOL_REF)
3880 if (CONSTANT_POOL_ADDRESS_P (x))
3881 find_pool_constant (current_function, x)->mark = 1;
3882 return;
3884 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3885 a MEM, but does not constitute a use of that MEM. */
3886 else if (GET_CODE (x) == CONST_DOUBLE)
3887 return;
3889 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3890 insns, not any notes that may be attached. We don't want to mark
3891 a constant just because it happens to appear in a REG_EQUIV note. */
3892 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3894 mark_constants (PATTERN (x));
3895 return;
3898 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3900 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3902 switch (*format_ptr++)
3904 case 'e':
3905 mark_constants (XEXP (x, i));
3906 break;
3908 case 'E':
3909 if (XVEC (x, i) != 0)
3911 register int j;
3913 for (j = 0; j < XVECLEN (x, i); j++)
3914 mark_constants (XVECEXP (x, i, j));
3916 break;
3918 case 'S':
3919 case 's':
3920 case '0':
3921 case 'i':
3922 case 'w':
3923 case 'n':
3924 case 'u':
3925 break;
3927 default:
3928 abort ();
3933 /* Find all the constants whose addresses are referenced inside of EXP,
3934 and make sure assembler code with a label has been output for each one.
3935 Indicate whether an ADDR_EXPR has been encountered. */
3937 static int
3938 output_addressed_constants (exp)
3939 tree exp;
3941 int reloc = 0;
3943 switch (TREE_CODE (exp))
3945 case ADDR_EXPR:
3947 register tree constant = TREE_OPERAND (exp, 0);
3949 while (TREE_CODE (constant) == COMPONENT_REF)
3951 constant = TREE_OPERAND (constant, 0);
3954 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3955 || TREE_CODE (constant) == CONSTRUCTOR)
3956 /* No need to do anything here
3957 for addresses of variables or functions. */
3958 output_constant_def (constant);
3960 reloc = 1;
3961 break;
3963 case PLUS_EXPR:
3964 case MINUS_EXPR:
3965 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3966 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3967 break;
3969 case NOP_EXPR:
3970 case CONVERT_EXPR:
3971 case NON_LVALUE_EXPR:
3972 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3973 break;
3975 case CONSTRUCTOR:
3977 register tree link;
3978 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3979 if (TREE_VALUE (link) != 0)
3980 reloc |= output_addressed_constants (TREE_VALUE (link));
3982 break;
3984 default:
3985 break;
3987 return reloc;
3990 /* Output assembler code for constant EXP to FILE, with no label.
3991 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3992 Assumes output_addressed_constants has been done on EXP already.
3994 Generate exactly SIZE bytes of assembler data, padding at the end
3995 with zeros if necessary. SIZE must always be specified.
3997 SIZE is important for structure constructors,
3998 since trailing members may have been omitted from the constructor.
3999 It is also important for initialization of arrays from string constants
4000 since the full length of the string constant might not be wanted.
4001 It is also needed for initialization of unions, where the initializer's
4002 type is just one member, and that may not be as long as the union.
4004 There a case in which we would fail to output exactly SIZE bytes:
4005 for a structure constructor that wants to produce more than SIZE bytes.
4006 But such constructors will never be generated for any possible input. */
4008 void
4009 output_constant (exp, size)
4010 register tree exp;
4011 register int size;
4013 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4015 /* Some front-ends use constants other than the standard
4016 language-indepdent varieties, but which may still be output
4017 directly. Give the front-end a chance to convert EXP to a
4018 language-independent representation. */
4019 if (lang_expand_constant)
4020 exp = (*lang_expand_constant) (exp);
4022 if (size == 0 || flag_syntax_only)
4023 return;
4025 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4026 That way we get the constant (we hope) inside it. Also, strip off any
4027 NOP_EXPR that converts between two record, union, array, or set types. */
4028 while ((TREE_CODE (exp) == NOP_EXPR
4029 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4030 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4031 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4032 exp = TREE_OPERAND (exp, 0);
4034 /* Allow a constructor with no elements for any data type.
4035 This means to fill the space with zeros. */
4036 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4038 assemble_zeros (size);
4039 return;
4042 switch (code)
4044 case CHAR_TYPE:
4045 case BOOLEAN_TYPE:
4046 case INTEGER_TYPE:
4047 case ENUMERAL_TYPE:
4048 case POINTER_TYPE:
4049 case REFERENCE_TYPE:
4050 /* ??? What about (int)((float)(int)&foo + 4) */
4051 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4052 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4053 exp = TREE_OPERAND (exp, 0);
4055 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4056 EXPAND_INITIALIZER),
4057 size, 0))
4058 error ("initializer for integer value is too complicated");
4059 size = 0;
4060 break;
4062 case REAL_TYPE:
4063 if (TREE_CODE (exp) != REAL_CST)
4064 error ("initializer for floating value is not a floating constant");
4066 assemble_real (TREE_REAL_CST (exp),
4067 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4068 size = 0;
4069 break;
4071 case COMPLEX_TYPE:
4072 output_constant (TREE_REALPART (exp), size / 2);
4073 output_constant (TREE_IMAGPART (exp), size / 2);
4074 size -= (size / 2) * 2;
4075 break;
4077 case ARRAY_TYPE:
4078 if (TREE_CODE (exp) == CONSTRUCTOR)
4080 output_constructor (exp, size);
4081 return;
4083 else if (TREE_CODE (exp) == STRING_CST)
4085 int excess = 0;
4087 if (size > TREE_STRING_LENGTH (exp))
4089 excess = size - TREE_STRING_LENGTH (exp);
4090 size = TREE_STRING_LENGTH (exp);
4093 assemble_string (TREE_STRING_POINTER (exp), size);
4094 size = excess;
4096 else
4097 abort ();
4098 break;
4100 case RECORD_TYPE:
4101 case UNION_TYPE:
4102 if (TREE_CODE (exp) == CONSTRUCTOR)
4103 output_constructor (exp, size);
4104 else
4105 abort ();
4106 return;
4108 case SET_TYPE:
4109 if (TREE_CODE (exp) == INTEGER_CST)
4110 assemble_integer (expand_expr (exp, NULL_RTX,
4111 VOIDmode, EXPAND_INITIALIZER),
4112 size, 1);
4113 else if (TREE_CODE (exp) == CONSTRUCTOR)
4115 unsigned char *buffer = (unsigned char *) alloca (size);
4116 if (get_set_constructor_bytes (exp, buffer, size))
4117 abort ();
4118 assemble_string ((char *) buffer, size);
4120 else
4121 error ("unknown set constructor type");
4122 return;
4124 default:
4125 break; /* ??? */
4128 if (size > 0)
4129 assemble_zeros (size);
4133 /* Subroutine of output_constant, used for CONSTRUCTORs
4134 (aggregate constants).
4135 Generate at least SIZE bytes, padding if necessary. */
4137 static void
4138 output_constructor (exp, size)
4139 tree exp;
4140 int size;
4142 register tree link, field = 0;
4143 HOST_WIDE_INT min_index = 0;
4144 /* Number of bytes output or skipped so far.
4145 In other words, current position within the constructor. */
4146 int total_bytes = 0;
4147 /* Non-zero means BYTE contains part of a byte, to be output. */
4148 int byte_buffer_in_use = 0;
4149 register int byte;
4151 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4152 abort ();
4154 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4155 field = TYPE_FIELDS (TREE_TYPE (exp));
4157 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4158 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4159 min_index
4160 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4162 /* As LINK goes through the elements of the constant,
4163 FIELD goes through the structure fields, if the constant is a structure.
4164 if the constant is a union, then we override this,
4165 by getting the field from the TREE_LIST element.
4166 But the constant could also be an array. Then FIELD is zero.
4168 There is always a maximum of one element in the chain LINK for unions
4169 (even if the initializer in a source program incorrectly contains
4170 more one). */
4171 for (link = CONSTRUCTOR_ELTS (exp);
4172 link;
4173 link = TREE_CHAIN (link),
4174 field = field ? TREE_CHAIN (field) : 0)
4176 tree val = TREE_VALUE (link);
4177 tree index = 0;
4179 /* the element in a union constructor specifies the proper field. */
4181 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4182 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4184 /* if available, use the type given by link */
4185 if (TREE_PURPOSE (link) != 0)
4186 field = TREE_PURPOSE (link);
4189 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4190 index = TREE_PURPOSE (link);
4192 /* Eliminate the marker that makes a cast not be an lvalue. */
4193 if (val != 0)
4194 STRIP_NOPS (val);
4196 if (index && TREE_CODE (index) == RANGE_EXPR)
4198 register int fieldsize
4199 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4200 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4201 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4202 HOST_WIDE_INT index;
4203 for (index = lo_index; index <= hi_index; index++)
4205 /* Output the element's initial value. */
4206 if (val == 0)
4207 assemble_zeros (fieldsize);
4208 else
4209 output_constant (val, fieldsize);
4211 /* Count its size. */
4212 total_bytes += fieldsize;
4215 else if (field == 0 || !DECL_BIT_FIELD (field))
4217 /* An element that is not a bit-field. */
4219 register int fieldsize;
4220 /* Since this structure is static,
4221 we know the positions are constant. */
4222 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4223 / BITS_PER_UNIT)
4224 : 0);
4225 if (index != 0)
4226 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4227 / BITS_PER_UNIT
4228 * (TREE_INT_CST_LOW (index) - min_index));
4230 /* Output any buffered-up bit-fields preceding this element. */
4231 if (byte_buffer_in_use)
4233 ASM_OUTPUT_BYTE (asm_out_file, byte);
4234 total_bytes++;
4235 byte_buffer_in_use = 0;
4238 /* Advance to offset of this element.
4239 Note no alignment needed in an array, since that is guaranteed
4240 if each element has the proper size. */
4241 if ((field != 0 || index != 0) && bitpos != total_bytes)
4243 assemble_zeros (bitpos - total_bytes);
4244 total_bytes = bitpos;
4247 /* Determine size this element should occupy. */
4248 if (field)
4250 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4251 abort ();
4252 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4254 /* This avoids overflow trouble. */
4255 tree size_tree = size_binop (CEIL_DIV_EXPR,
4256 DECL_SIZE (field),
4257 size_int (BITS_PER_UNIT));
4258 fieldsize = TREE_INT_CST_LOW (size_tree);
4260 else
4262 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4263 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4266 else
4267 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4269 /* Output the element's initial value. */
4270 if (val == 0)
4271 assemble_zeros (fieldsize);
4272 else
4273 output_constant (val, fieldsize);
4275 /* Count its size. */
4276 total_bytes += fieldsize;
4278 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4279 error ("invalid initial value for member `%s'",
4280 IDENTIFIER_POINTER (DECL_NAME (field)));
4281 else
4283 /* Element that is a bit-field. */
4285 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4286 int end_offset
4287 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4289 if (val == 0)
4290 val = integer_zero_node;
4292 /* If this field does not start in this (or, next) byte,
4293 skip some bytes. */
4294 if (next_offset / BITS_PER_UNIT != total_bytes)
4296 /* Output remnant of any bit field in previous bytes. */
4297 if (byte_buffer_in_use)
4299 ASM_OUTPUT_BYTE (asm_out_file, byte);
4300 total_bytes++;
4301 byte_buffer_in_use = 0;
4304 /* If still not at proper byte, advance to there. */
4305 if (next_offset / BITS_PER_UNIT != total_bytes)
4307 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4308 total_bytes = next_offset / BITS_PER_UNIT;
4312 if (! byte_buffer_in_use)
4313 byte = 0;
4315 /* We must split the element into pieces that fall within
4316 separate bytes, and combine each byte with previous or
4317 following bit-fields. */
4319 /* next_offset is the offset n fbits from the beginning of
4320 the structure to the next bit of this element to be processed.
4321 end_offset is the offset of the first bit past the end of
4322 this element. */
4323 while (next_offset < end_offset)
4325 int this_time;
4326 int shift;
4327 HOST_WIDE_INT value;
4328 int next_byte = next_offset / BITS_PER_UNIT;
4329 int next_bit = next_offset % BITS_PER_UNIT;
4331 /* Advance from byte to byte
4332 within this element when necessary. */
4333 while (next_byte != total_bytes)
4335 ASM_OUTPUT_BYTE (asm_out_file, byte);
4336 total_bytes++;
4337 byte = 0;
4340 /* Number of bits we can process at once
4341 (all part of the same byte). */
4342 this_time = MIN (end_offset - next_offset,
4343 BITS_PER_UNIT - next_bit);
4344 if (BYTES_BIG_ENDIAN)
4346 /* On big-endian machine, take the most significant bits
4347 first (of the bits that are significant)
4348 and put them into bytes from the most significant end. */
4349 shift = end_offset - next_offset - this_time;
4350 /* Don't try to take a bunch of bits that cross
4351 the word boundary in the INTEGER_CST. */
4352 if (shift < HOST_BITS_PER_WIDE_INT
4353 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4355 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4356 shift = HOST_BITS_PER_WIDE_INT;
4359 /* Now get the bits from the appropriate constant word. */
4360 if (shift < HOST_BITS_PER_WIDE_INT)
4362 value = TREE_INT_CST_LOW (val);
4364 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4366 value = TREE_INT_CST_HIGH (val);
4367 shift -= HOST_BITS_PER_WIDE_INT;
4369 else
4370 abort ();
4371 byte |= (((value >> shift)
4372 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4373 << (BITS_PER_UNIT - this_time - next_bit));
4375 else
4377 /* On little-endian machines,
4378 take first the least significant bits of the value
4379 and pack them starting at the least significant
4380 bits of the bytes. */
4381 shift = (next_offset
4382 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4383 /* Don't try to take a bunch of bits that cross
4384 the word boundary in the INTEGER_CST. */
4385 if (shift < HOST_BITS_PER_WIDE_INT
4386 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4388 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4389 shift = HOST_BITS_PER_WIDE_INT;
4392 /* Now get the bits from the appropriate constant word. */
4393 if (shift < HOST_BITS_PER_WIDE_INT)
4394 value = TREE_INT_CST_LOW (val);
4395 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4397 value = TREE_INT_CST_HIGH (val);
4398 shift -= HOST_BITS_PER_WIDE_INT;
4400 else
4401 abort ();
4402 byte |= (((value >> shift)
4403 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4404 << next_bit);
4406 next_offset += this_time;
4407 byte_buffer_in_use = 1;
4411 if (byte_buffer_in_use)
4413 ASM_OUTPUT_BYTE (asm_out_file, byte);
4414 total_bytes++;
4416 if (total_bytes < size)
4417 assemble_zeros (size - total_bytes);
4420 #ifdef HANDLE_PRAGMA_WEAK
4421 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4422 associatd with NAME. */
4425 add_weak (name, value)
4426 char *name;
4427 char *value;
4429 struct weak_syms *weak;
4431 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4433 if (weak == NULL)
4434 return 0;
4436 weak->next = weak_decls;
4437 weak->name = name;
4438 weak->value = value;
4439 weak_decls = weak;
4441 return 1;
4443 #endif /* HANDLE_PRAGMA_WEAK */
4445 /* Declare DECL to be a weak symbol. */
4447 void
4448 declare_weak (decl)
4449 tree decl;
4451 if (! TREE_PUBLIC (decl))
4452 error_with_decl (decl, "weak declaration of `%s' must be public");
4453 else if (TREE_ASM_WRITTEN (decl))
4454 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4455 else if (SUPPORTS_WEAK)
4456 DECL_WEAK (decl) = 1;
4457 #ifdef HANDLE_PRAGMA_WEAK
4458 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4459 #endif
4462 /* Emit any pending weak declarations. */
4464 #ifdef HANDLE_PRAGMA_WEAK
4465 struct weak_syms * weak_decls;
4466 #endif
4468 void
4469 weak_finish ()
4471 #ifdef HANDLE_PRAGMA_WEAK
4472 if (HANDLE_PRAGMA_WEAK)
4474 struct weak_syms *t;
4475 for (t = weak_decls; t; t = t->next)
4477 if (t->name)
4479 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4480 if (t->value)
4481 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4485 #endif
4488 /* Remove NAME from the pending list of weak symbols. This prevents
4489 the compiler from emitting multiple .weak directives which confuses
4490 some assemblers. */
4491 #ifdef ASM_WEAKEN_LABEL
4492 static void
4493 remove_from_pending_weak_list (name)
4494 char *name ATTRIBUTE_UNUSED;
4496 #ifdef HANDLE_PRAGMA_WEAK
4497 if (HANDLE_PRAGMA_WEAK)
4499 struct weak_syms *t;
4500 for (t = weak_decls; t; t = t->next)
4502 if (t->name && strcmp (name, t->name) == 0)
4503 t->name = NULL;
4506 #endif
4508 #endif
4510 void
4511 assemble_alias (decl, target)
4512 tree decl, target ATTRIBUTE_UNUSED;
4514 char *name;
4516 make_decl_rtl (decl, (char *) 0, 1);
4517 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4519 #ifdef ASM_OUTPUT_DEF
4520 /* Make name accessible from other files, if appropriate. */
4522 if (TREE_PUBLIC (decl))
4524 #ifdef ASM_WEAKEN_LABEL
4525 if (DECL_WEAK (decl))
4527 ASM_WEAKEN_LABEL (asm_out_file, name);
4528 /* Remove this function from the pending weak list so that
4529 we do not emit multiple .weak directives for it. */
4530 remove_from_pending_weak_list
4531 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4533 else
4534 #endif
4535 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4538 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4539 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4540 #else
4541 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4542 #endif
4543 TREE_ASM_WRITTEN (decl) = 1;
4544 #else
4545 #ifdef ASM_OUTPUT_WEAK_ALIAS
4546 if (! DECL_WEAK (decl))
4547 warning ("only weak aliases are supported in this configuration");
4549 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4550 TREE_ASM_WRITTEN (decl) = 1;
4551 #else
4552 warning ("alias definitions not supported in this configuration; ignored");
4553 #endif
4554 #endif
4557 /* This determines whether or not we support link-once semantics. */
4558 #ifndef SUPPORTS_ONE_ONLY
4559 #ifdef MAKE_DECL_ONE_ONLY
4560 #define SUPPORTS_ONE_ONLY 1
4561 #else
4562 #define SUPPORTS_ONE_ONLY 0
4563 #endif
4564 #endif
4566 /* Returns 1 if the target configuration supports defining public symbols
4567 so that one of them will be chosen at link time instead of generating a
4568 multiply-defined symbol error, whether through the use of weak symbols or
4569 a target-specific mechanism for having duplicates discarded. */
4572 supports_one_only ()
4574 if (SUPPORTS_ONE_ONLY)
4575 return 1;
4576 return SUPPORTS_WEAK;
4579 /* Set up DECL as a public symbol that can be defined in multiple
4580 translation units without generating a linker error. */
4582 void
4583 make_decl_one_only (decl)
4584 tree decl;
4586 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4587 abort ();
4589 TREE_PUBLIC (decl) = 1;
4591 if (TREE_CODE (decl) == VAR_DECL
4592 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4593 DECL_COMMON (decl) = 1;
4594 else if (SUPPORTS_ONE_ONLY)
4596 #ifdef MAKE_DECL_ONE_ONLY
4597 MAKE_DECL_ONE_ONLY (decl);
4598 #endif
4599 DECL_ONE_ONLY (decl) = 1;
4601 else if (SUPPORTS_WEAK)
4602 DECL_WEAK (decl) = 1;
4603 else
4604 abort ();
4607 void
4608 init_varasm_once ()
4610 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof(const_hash_table[0]),
4611 mark_const_hash_entry);
4612 ggc_add_string_root (&in_named_name, 1);