* Make-lang.in (DEMANGLER_INSTALL_NAME, DEMANGLER_CROSS_NAME): New
[official-gcc.git] / gcc / varasm.c
blob011b2341d88d8ae7c72cadef038d02f55ae3f5af
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-7, 1998 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 <stdio.h>
31 #include <setjmp.h>
32 /* #include <stab.h> */
33 #include "rtl.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "except.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "output.h"
40 #include "hard-reg-set.h"
41 #include "regs.h"
42 #include "defaults.h"
43 #include "real.h"
45 #include "obstack.h"
46 #include "c-pragma.h"
48 #ifdef XCOFF_DEBUGGING_INFO
49 #include "xcoffout.h"
50 #endif
52 #include <ctype.h>
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 /* This macro gets just the user-specified name
75 out of the string in a SYMBOL_REF. On most machines,
76 we discard the * if any and that's all. */
77 #ifndef STRIP_NAME_ENCODING
78 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
79 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
80 #endif
82 /* File in which assembler code is being written. */
84 extern FILE *asm_out_file;
86 /* The (assembler) name of the first globally-visible object output. */
87 char *first_global_object_name;
89 extern struct obstack *current_obstack;
90 extern struct obstack *saveable_obstack;
91 extern struct obstack *rtl_obstack;
92 extern struct obstack permanent_obstack;
93 #define obstack_chunk_alloc xmalloc
95 /* Number for making the label on the next
96 constant that is stored in memory. */
98 int const_labelno;
100 /* Number for making the label on the next
101 static variable internal to a function. */
103 int var_labelno;
105 /* Carry information from ASM_DECLARE_OBJECT_NAME
106 to ASM_FINISH_DECLARE_OBJECT. */
108 int size_directive_output;
110 /* The last decl for which assemble_variable was called,
111 if it did ASM_DECLARE_OBJECT_NAME.
112 If the last call to assemble_variable didn't do that,
113 this holds 0. */
115 tree last_assemble_variable_decl;
118 #ifdef HANDLE_PRAGMA_WEAK
119 /* Any weak symbol declarations waiting to be emitted. */
121 struct weak_syms
123 struct weak_syms *next;
124 char *name;
125 char *value;
128 static struct weak_syms *weak_decls;
129 #endif
131 /* Nonzero if at least one function definition has been seen. */
133 static int function_defined;
135 struct addr_const;
136 struct constant_descriptor;
137 struct rtx_const;
138 struct pool_constant;
140 static char *strip_reg_name PROTO((char *));
141 static int contains_pointers_p PROTO((tree));
142 static void decode_addr_const PROTO((tree, struct addr_const *));
143 static int const_hash PROTO((tree));
144 static int compare_constant PROTO((tree,
145 struct constant_descriptor *));
146 static char *compare_constant_1 PROTO((tree, char *));
147 static struct constant_descriptor *record_constant PROTO((tree));
148 static void record_constant_1 PROTO((tree));
149 static tree copy_constant PROTO((tree));
150 static void output_constant_def_contents PROTO((tree, int, int));
151 static void decode_rtx_const PROTO((enum machine_mode, rtx,
152 struct rtx_const *));
153 static int const_hash_rtx PROTO((enum machine_mode, rtx));
154 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
155 struct constant_descriptor *));
156 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
157 rtx));
158 static struct pool_constant *find_pool_constant PROTO((rtx));
159 static void mark_constant_pool PROTO((void));
160 static void mark_constants PROTO((rtx));
161 static int output_addressed_constants PROTO((tree));
162 static void output_after_function_constants PROTO((void));
163 static void output_constructor PROTO((tree, int));
165 static enum in_section { no_section, in_text, in_data, in_named
166 #ifdef BSS_SECTION_ASM_OP
167 , in_bss
168 #endif
169 #ifdef EH_FRAME_SECTION_ASM_OP
170 , in_eh_frame
171 #endif
172 #ifdef EXTRA_SECTIONS
173 , EXTRA_SECTIONS
174 #endif
175 } in_section = no_section;
177 /* Return a non-zero value if DECL has a section attribute. */
178 #define IN_NAMED_SECTION(DECL) \
179 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
180 && DECL_SECTION_NAME (DECL) != NULL_TREE)
182 /* Text of section name when in_section == in_named. */
183 static char *in_named_name;
185 /* Define functions like text_section for any extra sections. */
186 #ifdef EXTRA_SECTION_FUNCTIONS
187 EXTRA_SECTION_FUNCTIONS
188 #endif
190 /* Tell assembler to switch to text section. */
192 void
193 text_section ()
195 if (in_section != in_text)
197 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
198 in_section = in_text;
202 /* Tell assembler to switch to data section. */
204 void
205 data_section ()
207 if (in_section != in_data)
209 if (flag_shared_data)
211 #ifdef SHARED_SECTION_ASM_OP
212 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
213 #else
214 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
215 #endif
217 else
218 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
220 in_section = in_data;
224 /* Tell assembler to switch to read-only data section. This is normally
225 the text section. */
227 void
228 readonly_data_section ()
230 #ifdef READONLY_DATA_SECTION
231 READONLY_DATA_SECTION (); /* Note this can call data_section. */
232 #else
233 text_section ();
234 #endif
237 /* Determine if we're in the text section. */
240 in_text_section ()
242 return in_section == in_text;
245 /* Determine if we're in the data section. */
248 in_data_section ()
250 return in_section == in_data;
253 /* Tell assembler to change to section NAME for DECL.
254 If DECL is NULL, just switch to section NAME.
255 If NAME is NULL, get the name from DECL.
256 If RELOC is 1, the initializer for DECL contains relocs. */
258 void
259 named_section (decl, name, reloc)
260 tree decl;
261 char *name;
262 int reloc;
264 if (decl != NULL_TREE
265 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
266 abort ();
267 if (name == NULL)
268 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
270 if (in_section != in_named || strcmp (name, in_named_name))
272 #ifdef ASM_OUTPUT_SECTION_NAME
273 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
274 #else
275 /* Section attributes are not supported if this macro isn't provided -
276 some host formats don't support them at all. The front-end should
277 already have flagged this as an error. */
278 abort ();
279 #endif
281 in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1);
282 strcpy (in_named_name, name);
283 in_section = in_named;
287 #ifdef ASM_OUTPUT_SECTION_NAME
288 #ifndef UNIQUE_SECTION
289 #define UNIQUE_SECTION(DECL,RELOC) \
290 do { \
291 int len; \
292 char *name, *string; \
294 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
295 /* Strip off any encoding in name. */ \
296 STRIP_NAME_ENCODING (name, name); \
298 len = strlen (name) + 1; \
299 string = alloca (len + 1); \
300 sprintf (string, ".%s", name); \
302 DECL_SECTION_NAME (DECL) = build_string (len, string); \
303 } while (0)
304 #endif
305 #ifndef UNIQUE_SECTION_P
306 #define UNIQUE_SECTION_P(DECL) 0
307 #endif
308 #endif
310 #ifdef BSS_SECTION_ASM_OP
312 /* Tell the assembler to switch to the bss section. */
314 void
315 bss_section ()
317 if (in_section != in_bss)
319 #ifdef SHARED_BSS_SECTION_ASM_OP
320 if (flag_shared_data)
321 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
322 else
323 #endif
324 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
326 in_section = in_bss;
330 #ifdef ASM_OUTPUT_BSS
332 /* Utility function for ASM_OUTPUT_BSS for targets to use if
333 they don't support alignments in .bss.
334 ??? It is believed that this function will work in most cases so such
335 support is localized here. */
337 static void
338 asm_output_bss (file, decl, name, size, rounded)
339 FILE *file;
340 tree decl;
341 char *name;
342 int size, rounded;
344 ASM_GLOBALIZE_LABEL (file, name);
345 bss_section ();
346 #ifdef ASM_DECLARE_OBJECT_NAME
347 last_assemble_variable_decl = decl;
348 ASM_DECLARE_OBJECT_NAME (file, name, decl);
349 #else
350 /* Standard thing is just output label for the object. */
351 ASM_OUTPUT_LABEL (file, name);
352 #endif /* ASM_DECLARE_OBJECT_NAME */
353 ASM_OUTPUT_SKIP (file, rounded);
356 #endif
358 #ifdef ASM_OUTPUT_ALIGNED_BSS
360 /* Utility function for targets to use in implementing
361 ASM_OUTPUT_ALIGNED_BSS.
362 ??? It is believed that this function will work in most cases so such
363 support is localized here. */
365 static void
366 asm_output_aligned_bss (file, decl, name, size, align)
367 FILE *file;
368 tree decl;
369 char *name;
370 int size, align;
372 ASM_GLOBALIZE_LABEL (file, name);
373 bss_section ();
374 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
375 #ifdef ASM_DECLARE_OBJECT_NAME
376 last_assemble_variable_decl = decl;
377 ASM_DECLARE_OBJECT_NAME (file, name, decl);
378 #else
379 /* Standard thing is just output label for the object. */
380 ASM_OUTPUT_LABEL (file, name);
381 #endif /* ASM_DECLARE_OBJECT_NAME */
382 ASM_OUTPUT_SKIP (file, size ? size : 1);
385 #endif
387 #endif /* BSS_SECTION_ASM_OP */
389 #ifdef EH_FRAME_SECTION_ASM_OP
390 void
391 eh_frame_section ()
393 if (in_section != in_eh_frame)
395 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
396 in_section = in_eh_frame;
399 #endif
401 /* Switch to the section for function DECL.
403 If DECL is NULL_TREE, switch to the text section.
404 ??? It's not clear that we will ever be passed NULL_TREE, but it's
405 safer to handle it. */
407 void
408 function_section (decl)
409 tree decl;
411 if (decl != NULL_TREE
412 && DECL_SECTION_NAME (decl) != NULL_TREE)
413 named_section (decl, (char *) 0, 0);
414 else
415 text_section ();
418 /* Switch to section for variable DECL.
420 RELOC is the `reloc' argument to SELECT_SECTION. */
422 void
423 variable_section (decl, reloc)
424 tree decl;
425 int reloc;
427 if (IN_NAMED_SECTION (decl))
428 named_section (decl, NULL, reloc);
429 else
431 /* C++ can have const variables that get initialized from constructors,
432 and thus can not be in a readonly section. We prevent this by
433 verifying that the initial value is constant for objects put in a
434 readonly section.
436 error_mark_node is used by the C front end to indicate that the
437 initializer has not been seen yet. In this case, we assume that
438 the initializer must be constant.
440 C++ uses error_mark_node for variables that have complicated
441 initializers, but these variables go in BSS so we won't be called
442 for them. */
444 #ifdef SELECT_SECTION
445 SELECT_SECTION (decl, reloc);
446 #else
447 if (DECL_READONLY_SECTION (decl, reloc))
448 readonly_data_section ();
449 else
450 data_section ();
451 #endif
455 /* Tell assembler to switch to the section for the exception handling
456 table. */
458 void
459 exception_section ()
461 #if defined (EXCEPTION_SECTION)
462 EXCEPTION_SECTION ();
463 #else
464 #ifdef ASM_OUTPUT_SECTION_NAME
465 named_section (NULL_TREE, ".gcc_except_table", 0);
466 #else
467 if (flag_pic)
468 data_section ();
469 else
470 readonly_data_section ();
471 #endif
472 #endif
475 /* Create the rtl to represent a function, for a function definition.
476 DECL is a FUNCTION_DECL node which describes which function.
477 The rtl is stored into DECL. */
479 void
480 make_function_rtl (decl)
481 tree decl;
483 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
484 char *new_name = name;
486 /* Rename a nested function to avoid conflicts. */
487 if (decl_function_context (decl) != 0
488 && DECL_INITIAL (decl) != 0
489 && DECL_RTL (decl) == 0)
491 char *label;
493 name = IDENTIFIER_POINTER (DECL_NAME (decl));
494 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
495 name = obstack_copy0 (saveable_obstack, label, strlen (label));
496 var_labelno++;
498 else
500 /* When -fprefix-function-name is used, every function name is
501 prefixed. Even static functions are prefixed because they
502 could be declared latter. Note that a nested function name
503 is not prefixed. */
504 if (flag_prefix_function_name)
506 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE + 1);
507 strcpy (new_name, CHKR_PREFIX);
508 strcpy (new_name + CHKR_PREFIX_SIZE, name);
509 name = obstack_copy0 (saveable_obstack, new_name, strlen (new_name));
513 if (DECL_RTL (decl) == 0)
515 DECL_RTL (decl)
516 = gen_rtx_MEM (DECL_MODE (decl),
517 gen_rtx_SYMBOL_REF (Pmode, name));
519 /* Optionally set flags or add text to the name to record information
520 such as that it is a function name. If the name is changed, the macro
521 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
522 #ifdef ENCODE_SECTION_INFO
523 ENCODE_SECTION_INFO (decl);
524 #endif
527 /* Record at least one function has been defined. */
528 function_defined = 1;
531 /* Given NAME, a putative register name, discard any customary prefixes. */
533 static char *
534 strip_reg_name (name)
535 char *name;
537 #ifdef REGISTER_PREFIX
538 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
539 name += strlen (REGISTER_PREFIX);
540 #endif
541 if (name[0] == '%' || name[0] == '#')
542 name++;
543 return name;
546 /* Decode an `asm' spec for a declaration as a register name.
547 Return the register number, or -1 if nothing specified,
548 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
549 or -3 if ASMSPEC is `cc' and is not recognized,
550 or -4 if ASMSPEC is `memory' and is not recognized.
551 Accept an exact spelling or a decimal number.
552 Prefixes such as % are optional. */
555 decode_reg_name (asmspec)
556 char *asmspec;
558 if (asmspec != 0)
560 int i;
562 /* Get rid of confusing prefixes. */
563 asmspec = strip_reg_name (asmspec);
565 /* Allow a decimal number as a "register name". */
566 for (i = strlen (asmspec) - 1; i >= 0; i--)
567 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
568 break;
569 if (asmspec[0] != 0 && i < 0)
571 i = atoi (asmspec);
572 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
573 return i;
574 else
575 return -2;
578 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
579 if (reg_names[i][0]
580 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
581 return i;
583 #ifdef ADDITIONAL_REGISTER_NAMES
585 static struct { char *name; int number; } table[]
586 = ADDITIONAL_REGISTER_NAMES;
588 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
589 if (! strcmp (asmspec, table[i].name))
590 return table[i].number;
592 #endif /* ADDITIONAL_REGISTER_NAMES */
594 if (!strcmp (asmspec, "memory"))
595 return -4;
597 if (!strcmp (asmspec, "cc"))
598 return -3;
600 return -2;
603 return -1;
606 /* Create the DECL_RTL for a declaration for a static or external variable
607 or static or external function.
608 ASMSPEC, if not 0, is the string which the user specified
609 as the assembler symbol name.
610 TOP_LEVEL is nonzero if this is a file-scope variable.
612 This is never called for PARM_DECL nodes. */
614 void
615 make_decl_rtl (decl, asmspec, top_level)
616 tree decl;
617 char *asmspec;
618 int top_level;
620 register char *name = 0;
621 int reg_number;
623 reg_number = decode_reg_name (asmspec);
625 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
626 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
628 if (reg_number == -2)
630 /* ASMSPEC is given, and not the name of a register. */
631 name = (char *) obstack_alloc (saveable_obstack,
632 strlen (asmspec) + 2);
633 name[0] = '*';
634 strcpy (&name[1], asmspec);
637 /* For a duplicate declaration, we can be called twice on the
638 same DECL node. Don't discard the RTL already made. */
639 if (DECL_RTL (decl) == 0)
641 DECL_RTL (decl) = 0;
643 /* First detect errors in declaring global registers. */
644 if (TREE_CODE (decl) != FUNCTION_DECL
645 && DECL_REGISTER (decl) && reg_number == -1)
646 error_with_decl (decl,
647 "register name not specified for `%s'");
648 else if (TREE_CODE (decl) != FUNCTION_DECL
649 && DECL_REGISTER (decl) && reg_number < 0)
650 error_with_decl (decl,
651 "invalid register name for `%s'");
652 else if ((reg_number >= 0 || reg_number == -3)
653 && (TREE_CODE (decl) == FUNCTION_DECL
654 && ! DECL_REGISTER (decl)))
655 error_with_decl (decl,
656 "register name given for non-register variable `%s'");
657 else if (TREE_CODE (decl) != FUNCTION_DECL
658 && DECL_REGISTER (decl)
659 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
660 error_with_decl (decl,
661 "data type of `%s' isn't suitable for a register");
662 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
663 && ! HARD_REGNO_MODE_OK (reg_number,
664 TYPE_MODE (TREE_TYPE (decl))))
665 error_with_decl (decl,
666 "register number for `%s' isn't suitable for data type");
667 /* Now handle properly declared static register variables. */
668 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
670 int nregs;
672 if (DECL_INITIAL (decl) != 0 && top_level)
674 DECL_INITIAL (decl) = 0;
675 error ("global register variable has initial value");
677 if (fixed_regs[reg_number] == 0
678 && function_defined && top_level)
679 error ("global register variable follows a function definition");
680 if (TREE_THIS_VOLATILE (decl))
681 warning ("volatile register variables don't work as you might wish");
683 /* If the user specified one of the eliminables registers here,
684 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
685 confused with that register and be eliminated. Although this
686 usage is somewhat suspect, we nevertheless use the following
687 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
689 DECL_RTL (decl)
690 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
691 REGNO (DECL_RTL (decl)) = reg_number;
692 REG_USERVAR_P (DECL_RTL (decl)) = 1;
694 if (top_level)
696 /* Make this register global, so not usable for anything
697 else. */
698 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
699 while (nregs > 0)
700 globalize_reg (reg_number + --nregs);
703 /* Specifying a section attribute on a variable forces it into a
704 non-.bss section, and thus it cannot be common. */
705 else if (TREE_CODE (decl) == VAR_DECL
706 && DECL_SECTION_NAME (decl) != NULL_TREE
707 && DECL_INITIAL (decl) == NULL_TREE
708 && DECL_COMMON (decl))
709 DECL_COMMON (decl) = 0;
711 /* Now handle ordinary static variables and functions (in memory).
712 Also handle vars declared register invalidly. */
713 if (DECL_RTL (decl) == 0)
715 /* Can't use just the variable's own name for a variable
716 whose scope is less than the whole file.
717 Concatenate a distinguishing number. */
718 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
720 char *label;
722 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
723 name = obstack_copy0 (saveable_obstack, label, strlen (label));
724 var_labelno++;
727 if (name == 0)
728 abort ();
730 /* When -fprefix-function-name is used, the functions
731 names are prefixed. Only nested function names are not
732 prefixed. */
733 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
735 char *new_name;
736 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE
737 + 1);
738 strcpy (new_name, CHKR_PREFIX);
739 strcpy (new_name + CHKR_PREFIX_SIZE, name);
740 name = obstack_copy0 (saveable_obstack,
741 new_name, strlen (new_name));
744 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
745 gen_rtx_SYMBOL_REF (Pmode, name));
747 /* If this variable is to be treated as volatile, show its
748 tree node has side effects. If it has side effects, either
749 because of this test or from TREE_THIS_VOLATILE also
750 being set, show the MEM is volatile. */
751 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
752 && TREE_PUBLIC (decl))
753 TREE_SIDE_EFFECTS (decl) = 1;
754 if (TREE_SIDE_EFFECTS (decl))
755 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
757 if (TREE_READONLY (decl))
758 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
759 MEM_IN_STRUCT_P (DECL_RTL (decl))
760 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
762 /* Optionally set flags or add text to the name to record information
763 such as that it is a function name.
764 If the name is changed, the macro ASM_OUTPUT_LABELREF
765 will have to know how to strip this information. */
766 #ifdef ENCODE_SECTION_INFO
767 ENCODE_SECTION_INFO (decl);
768 #endif
771 /* If the old RTL had the wrong mode, fix the mode. */
772 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
774 rtx rtl = DECL_RTL (decl);
775 PUT_MODE (rtl, DECL_MODE (decl));
779 /* Make the rtl for variable VAR be volatile.
780 Use this only for static variables. */
782 void
783 make_var_volatile (var)
784 tree var;
786 if (GET_CODE (DECL_RTL (var)) != MEM)
787 abort ();
789 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
792 /* Output alignment directive to align for constant expression EXP. */
794 void
795 assemble_constant_align (exp)
796 tree exp;
798 int align;
800 /* Align the location counter as required by EXP's data type. */
801 align = TYPE_ALIGN (TREE_TYPE (exp));
802 #ifdef CONSTANT_ALIGNMENT
803 align = CONSTANT_ALIGNMENT (exp, align);
804 #endif
806 if (align > BITS_PER_UNIT)
807 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
810 /* Output a string of literal assembler code
811 for an `asm' keyword used between functions. */
813 void
814 assemble_asm (string)
815 tree string;
817 app_enable ();
819 if (TREE_CODE (string) == ADDR_EXPR)
820 string = TREE_OPERAND (string, 0);
822 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
825 #if 0 /* This should no longer be needed, because
826 flag_gnu_linker should be 0 on these systems,
827 which should prevent any output
828 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
829 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
830 #ifndef ASM_OUTPUT_CONSTRUCTOR
831 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
832 #endif
833 #ifndef ASM_OUTPUT_DESTRUCTOR
834 #define ASM_OUTPUT_DESTRUCTOR(file, name)
835 #endif
836 #endif
837 #endif /* 0 */
839 /* Record an element in the table of global destructors.
840 How this is done depends on what sort of assembler and linker
841 are in use.
843 NAME should be the name of a global function to be called
844 at exit time. This name is output using assemble_name. */
846 void
847 assemble_destructor (name)
848 char *name;
850 #ifdef ASM_OUTPUT_DESTRUCTOR
851 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
852 #else
853 if (flag_gnu_linker)
855 /* Now tell GNU LD that this is part of the static destructor set. */
856 /* This code works for any machine provided you use GNU as/ld. */
857 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
858 assemble_name (asm_out_file, name);
859 fputc ('\n', asm_out_file);
861 #endif
864 /* Likewise for global constructors. */
866 void
867 assemble_constructor (name)
868 char *name;
870 #ifdef ASM_OUTPUT_CONSTRUCTOR
871 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
872 #else
873 if (flag_gnu_linker)
875 /* Now tell GNU LD that this is part of the static constructor set. */
876 /* This code works for any machine provided you use GNU as/ld. */
877 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
878 assemble_name (asm_out_file, name);
879 fputc ('\n', asm_out_file);
881 #endif
884 /* Likewise for entries we want to record for garbage collection.
885 Garbage collection is still under development. */
887 void
888 assemble_gc_entry (name)
889 char *name;
891 #ifdef ASM_OUTPUT_GC_ENTRY
892 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
893 #else
894 if (flag_gnu_linker)
896 /* Now tell GNU LD that this is part of the static constructor set. */
897 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
898 assemble_name (asm_out_file, name);
899 fputc ('\n', asm_out_file);
901 #endif
904 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
905 a non-zero value if the constant pool should be output before the
906 start of the function, or a zero value if the pool should output
907 after the end of the function. The default is to put it before the
908 start. */
910 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
911 #define CONSTANT_POOL_BEFORE_FUNCTION 1
912 #endif
914 /* Output assembler code for the constant pool of a function and associated
915 with defining the name of the function. DECL describes the function.
916 NAME is the function's name. For the constant pool, we use the current
917 constant pool data. */
919 void
920 assemble_start_function (decl, fnname)
921 tree decl;
922 char *fnname;
924 int align;
926 /* The following code does not need preprocessing in the assembler. */
928 app_disable ();
930 if (CONSTANT_POOL_BEFORE_FUNCTION)
931 output_constant_pool (fnname, decl);
933 #ifdef ASM_OUTPUT_SECTION_NAME
934 /* If the function is to be put in its own section and it's not in a section
935 already, indicate so. */
936 if ((flag_function_sections
937 && DECL_SECTION_NAME (decl) == NULL_TREE)
938 || UNIQUE_SECTION_P (decl))
939 UNIQUE_SECTION (decl, 0);
940 #endif
942 function_section (decl);
944 /* Tell assembler to move to target machine's alignment for functions. */
945 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
946 if (align > 0)
947 ASM_OUTPUT_ALIGN (asm_out_file, align);
949 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
950 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
951 #endif
953 #ifdef SDB_DEBUGGING_INFO
954 /* Output SDB definition of the function. */
955 if (write_symbols == SDB_DEBUG)
956 sdbout_mark_begin_function ();
957 #endif
959 #ifdef DBX_DEBUGGING_INFO
960 /* Output DBX definition of the function. */
961 if (write_symbols == DBX_DEBUG)
962 dbxout_begin_function (decl);
963 #endif
965 /* Make function name accessible from other files, if appropriate. */
967 if (TREE_PUBLIC (decl))
969 if (!first_global_object_name && ! DECL_WEAK (decl)
970 && ! DECL_ONE_ONLY (decl))
972 char *p;
974 STRIP_NAME_ENCODING (p, fnname);
975 first_global_object_name = permalloc (strlen (p) + 1);
976 strcpy (first_global_object_name, p);
979 #ifdef ASM_WEAKEN_LABEL
980 if (DECL_WEAK (decl))
981 ASM_WEAKEN_LABEL (asm_out_file, fnname);
982 else
983 #endif
984 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
987 /* Do any machine/system dependent processing of the function name */
988 #ifdef ASM_DECLARE_FUNCTION_NAME
989 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
990 #else
991 /* Standard thing is just output label for the function. */
992 ASM_OUTPUT_LABEL (asm_out_file, fnname);
993 #endif /* ASM_DECLARE_FUNCTION_NAME */
996 /* Output assembler code associated with defining the size of the
997 function. DECL describes the function. NAME is the function's name. */
999 void
1000 assemble_end_function (decl, fnname)
1001 tree decl;
1002 char *fnname;
1004 #ifdef ASM_DECLARE_FUNCTION_SIZE
1005 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1006 #endif
1007 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1009 output_constant_pool (fnname, decl);
1010 function_section (decl); /* need to switch back */
1013 /* Output any constants which should appear after the function. */
1014 output_after_function_constants ();
1017 /* Assemble code to leave SIZE bytes of zeros. */
1019 void
1020 assemble_zeros (size)
1021 int size;
1023 #ifdef ASM_NO_SKIP_IN_TEXT
1024 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1025 so we must output 0s explicitly in the text section. */
1026 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1028 int i;
1030 for (i = 0; i < size - 20; i += 20)
1032 #ifdef ASM_BYTE_OP
1033 fprintf (asm_out_file,
1034 "%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);
1035 #else
1036 fprintf (asm_out_file,
1037 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1038 #endif
1040 if (i < size)
1042 #ifdef ASM_BYTE_OP
1043 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1044 #else
1045 fprintf (asm_out_file, "\tbyte 0");
1046 #endif
1047 i++;
1048 for (; i < size; i++)
1049 fprintf (asm_out_file, ",0");
1050 fprintf (asm_out_file, "\n");
1053 else
1054 #endif
1055 if (size > 0)
1056 ASM_OUTPUT_SKIP (asm_out_file, size);
1059 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1061 void
1062 assemble_align (align)
1063 int align;
1065 if (align > BITS_PER_UNIT)
1066 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1069 /* Assemble a string constant with the specified C string as contents. */
1071 void
1072 assemble_string (p, size)
1073 char *p;
1074 int size;
1076 int pos = 0;
1077 int maximum = 2000;
1079 /* If the string is very long, split it up. */
1081 while (pos < size)
1083 int thissize = size - pos;
1084 if (thissize > maximum)
1085 thissize = maximum;
1087 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1089 pos += thissize;
1090 p += thissize;
1095 /* Assemble everything that is needed for a variable or function declaration.
1096 Not used for automatic variables, and not used for function definitions.
1097 Should not be called for variables of incomplete structure type.
1099 TOP_LEVEL is nonzero if this variable has file scope.
1100 AT_END is nonzero if this is the special handling, at end of compilation,
1101 to define things that have had only tentative definitions.
1102 DONT_OUTPUT_DATA if nonzero means don't actually output the
1103 initial value (that will be done by the caller). */
1105 void
1106 assemble_variable (decl, top_level, at_end, dont_output_data)
1107 tree decl;
1108 int top_level;
1109 int at_end;
1110 int dont_output_data;
1112 register char *name;
1113 int align;
1114 tree size_tree;
1115 int reloc = 0;
1116 enum in_section saved_in_section;
1118 last_assemble_variable_decl = 0;
1120 if (GET_CODE (DECL_RTL (decl)) == REG)
1122 /* Do output symbol info for global register variables, but do nothing
1123 else for them. */
1125 if (TREE_ASM_WRITTEN (decl))
1126 return;
1127 TREE_ASM_WRITTEN (decl) = 1;
1129 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1130 /* File-scope global variables are output here. */
1131 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1132 && top_level)
1133 dbxout_symbol (decl, 0);
1134 #endif
1135 #ifdef SDB_DEBUGGING_INFO
1136 if (write_symbols == SDB_DEBUG && top_level
1137 /* Leave initialized global vars for end of compilation;
1138 see comment in compile_file. */
1139 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1140 sdbout_symbol (decl, 0);
1141 #endif
1143 /* Don't output any DWARF debugging information for variables here.
1144 In the case of local variables, the information for them is output
1145 when we do our recursive traversal of the tree representation for
1146 the entire containing function. In the case of file-scope variables,
1147 we output information for all of them at the very end of compilation
1148 while we are doing our final traversal of the chain of file-scope
1149 declarations. */
1151 return;
1154 /* Normally no need to say anything here for external references,
1155 since assemble_external is called by the language-specific code
1156 when a declaration is first seen. */
1158 if (DECL_EXTERNAL (decl))
1159 return;
1161 /* Output no assembler code for a function declaration.
1162 Only definitions of functions output anything. */
1164 if (TREE_CODE (decl) == FUNCTION_DECL)
1165 return;
1167 /* If type was incomplete when the variable was declared,
1168 see if it is complete now. */
1170 if (DECL_SIZE (decl) == 0)
1171 layout_decl (decl, 0);
1173 /* Still incomplete => don't allocate it; treat the tentative defn
1174 (which is what it must have been) as an `extern' reference. */
1176 if (!dont_output_data && DECL_SIZE (decl) == 0)
1178 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1179 DECL_SOURCE_LINE (decl),
1180 "storage size of `%s' isn't known",
1181 IDENTIFIER_POINTER (DECL_NAME (decl)));
1182 TREE_ASM_WRITTEN (decl) = 1;
1183 return;
1186 /* The first declaration of a variable that comes through this function
1187 decides whether it is global (in C, has external linkage)
1188 or local (in C, has internal linkage). So do nothing more
1189 if this function has already run. */
1191 if (TREE_ASM_WRITTEN (decl))
1192 return;
1194 TREE_ASM_WRITTEN (decl) = 1;
1196 app_disable ();
1198 if (! dont_output_data)
1200 int size;
1202 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1203 goto finish;
1205 /* This is better than explicit arithmetic, since it avoids overflow. */
1206 size_tree = size_binop (CEIL_DIV_EXPR,
1207 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1209 size = TREE_INT_CST_LOW (size_tree);
1210 if (TREE_INT_CST_HIGH (size_tree) != 0
1211 || size != TREE_INT_CST_LOW (size_tree))
1213 error_with_decl (decl, "size of variable `%s' is too large");
1214 goto finish;
1218 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1220 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1221 && ! first_global_object_name
1222 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1223 || DECL_INITIAL (decl) == error_mark_node))
1224 && ! DECL_WEAK (decl)
1225 && ! DECL_ONE_ONLY (decl))
1227 char *p;
1229 STRIP_NAME_ENCODING (p, name);
1230 first_global_object_name = permalloc (strlen (p) + 1);
1231 strcpy (first_global_object_name, p);
1234 /* Handle uninitialized definitions. */
1236 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1237 /* If the target can't output uninitialized but not common global data
1238 in .bss, then we have to use .data. */
1239 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1240 && DECL_COMMON (decl)
1241 #endif
1242 && ! dont_output_data)
1244 int size = TREE_INT_CST_LOW (size_tree);
1245 int rounded = size;
1247 /* Don't allocate zero bytes of common,
1248 since that means "undefined external" in the linker. */
1249 if (size == 0) rounded = 1;
1250 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1251 so that each uninitialized object starts on such a boundary. */
1252 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1253 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1254 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1256 #ifdef DBX_DEBUGGING_INFO
1257 /* File-scope global variables are output here. */
1258 if (write_symbols == DBX_DEBUG && top_level)
1259 dbxout_symbol (decl, 0);
1260 #endif
1261 #ifdef SDB_DEBUGGING_INFO
1262 if (write_symbols == SDB_DEBUG && top_level
1263 /* Leave initialized global vars for end of compilation;
1264 see comment in compile_file. */
1265 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1266 sdbout_symbol (decl, 0);
1267 #endif
1269 /* Don't output any DWARF debugging information for variables here.
1270 In the case of local variables, the information for them is output
1271 when we do our recursive traversal of the tree representation for
1272 the entire containing function. In the case of file-scope variables,
1273 we output information for all of them at the very end of compilation
1274 while we are doing our final traversal of the chain of file-scope
1275 declarations. */
1277 #if 0 /* ??? We should either delete this or add a comment describing what
1278 it was intended to do and why we shouldn't delete it. */
1279 if (flag_shared_data)
1280 data_section ();
1281 #endif
1283 if (TREE_PUBLIC (decl)
1284 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1285 && DECL_COMMON (decl)
1286 #endif
1289 #ifdef ASM_OUTPUT_SHARED_COMMON
1290 if (flag_shared_data)
1291 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1292 else
1293 #endif
1295 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1296 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1297 DECL_ALIGN (decl));
1298 #else
1299 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1300 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1301 DECL_ALIGN (decl));
1302 #else
1303 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1304 #endif
1305 #endif
1308 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1309 else if (TREE_PUBLIC (decl))
1311 #ifdef ASM_OUTPUT_SHARED_BSS
1312 if (flag_shared_data)
1313 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1314 else
1315 #endif
1317 #ifdef ASM_OUTPUT_ALIGNED_BSS
1318 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1319 DECL_ALIGN (decl));
1320 #else
1321 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1322 #endif
1325 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1326 else
1328 #ifdef ASM_OUTPUT_SHARED_LOCAL
1329 if (flag_shared_data)
1330 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1331 else
1332 #endif
1334 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1335 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1336 DECL_ALIGN (decl));
1337 #else
1338 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1339 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1340 DECL_ALIGN (decl));
1341 #else
1342 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1343 #endif
1344 #endif
1347 goto finish;
1350 /* Handle initialized definitions.
1351 Also handle uninitialized global definitions if -fno-common and the
1352 target doesn't support ASM_OUTPUT_BSS. */
1354 /* First make the assembler name(s) global if appropriate. */
1355 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1357 #ifdef ASM_WEAKEN_LABEL
1358 if (DECL_WEAK (decl))
1359 ASM_WEAKEN_LABEL (asm_out_file, name);
1360 else
1361 #endif
1362 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1364 #if 0
1365 for (d = equivalents; d; d = TREE_CHAIN (d))
1367 tree e = TREE_VALUE (d);
1368 if (TREE_PUBLIC (e) && DECL_NAME (e))
1369 ASM_GLOBALIZE_LABEL (asm_out_file,
1370 XSTR (XEXP (DECL_RTL (e), 0), 0));
1372 #endif
1374 /* Output any data that we will need to use the address of. */
1375 if (DECL_INITIAL (decl) == error_mark_node)
1376 reloc = contains_pointers_p (TREE_TYPE (decl));
1377 else if (DECL_INITIAL (decl))
1378 reloc = output_addressed_constants (DECL_INITIAL (decl));
1380 #ifdef ASM_OUTPUT_SECTION_NAME
1381 if (UNIQUE_SECTION_P (decl))
1382 UNIQUE_SECTION (decl, reloc);
1383 #endif
1385 /* Switch to the appropriate section. */
1386 variable_section (decl, reloc);
1388 /* dbxout.c needs to know this. */
1389 if (in_text_section ())
1390 DECL_IN_TEXT_SECTION (decl) = 1;
1392 /* Record current section so we can restore it if dbxout.c clobbers it. */
1393 saved_in_section = in_section;
1395 /* Output the dbx info now that we have chosen the section. */
1397 #ifdef DBX_DEBUGGING_INFO
1398 /* File-scope global variables are output here. */
1399 if (write_symbols == DBX_DEBUG && top_level)
1400 dbxout_symbol (decl, 0);
1401 #endif
1402 #ifdef SDB_DEBUGGING_INFO
1403 if (write_symbols == SDB_DEBUG && top_level
1404 /* Leave initialized global vars for end of compilation;
1405 see comment in compile_file. */
1406 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1407 sdbout_symbol (decl, 0);
1408 #endif
1410 /* Don't output any DWARF debugging information for variables here.
1411 In the case of local variables, the information for them is output
1412 when we do our recursive traversal of the tree representation for
1413 the entire containing function. In the case of file-scope variables,
1414 we output information for all of them at the very end of compilation
1415 while we are doing our final traversal of the chain of file-scope
1416 declarations. */
1418 /* If the debugging output changed sections, reselect the section
1419 that's supposed to be selected. */
1420 if (in_section != saved_in_section)
1421 variable_section (decl, reloc);
1423 /* Compute and output the alignment of this data. */
1425 align = DECL_ALIGN (decl);
1426 /* In the case for initialing an array whose length isn't specified,
1427 where we have not yet been able to do the layout,
1428 figure out the proper alignment now. */
1429 if (dont_output_data && DECL_SIZE (decl) == 0
1430 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1431 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1433 /* Some object file formats have a maximum alignment which they support.
1434 In particular, a.out format supports a maximum alignment of 4. */
1435 #ifndef MAX_OFILE_ALIGNMENT
1436 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1437 #endif
1438 if (align > MAX_OFILE_ALIGNMENT)
1440 warning_with_decl (decl,
1441 "alignment of `%s' is greater than maximum object file alignment");
1442 align = MAX_OFILE_ALIGNMENT;
1444 #ifdef DATA_ALIGNMENT
1445 /* On some machines, it is good to increase alignment sometimes. */
1446 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1447 #endif
1448 #ifdef CONSTANT_ALIGNMENT
1449 if (DECL_INITIAL (decl))
1450 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1451 #endif
1453 /* Reset the alignment in case we have made it tighter, so we can benefit
1454 from it in get_pointer_alignment. */
1455 DECL_ALIGN (decl) = align;
1457 if (align > BITS_PER_UNIT)
1458 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1460 /* Do any machine/system dependent processing of the object. */
1461 #ifdef ASM_DECLARE_OBJECT_NAME
1462 last_assemble_variable_decl = decl;
1463 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1464 #else
1465 /* Standard thing is just output label for the object. */
1466 ASM_OUTPUT_LABEL (asm_out_file, name);
1467 #endif /* ASM_DECLARE_OBJECT_NAME */
1469 if (!dont_output_data)
1471 if (DECL_INITIAL (decl))
1472 /* Output the actual data. */
1473 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1474 else
1475 /* Leave space for it. */
1476 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1479 finish:
1480 #ifdef XCOFF_DEBUGGING_INFO
1481 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1482 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1483 and `aa' hasn't been output yet, the assembler generates a stab entry with
1484 a value of zero, in addition to creating an unnecessary external entry
1485 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1487 /* File-scope global variables are output here. */
1488 if (write_symbols == XCOFF_DEBUG && top_level)
1490 saved_in_section = in_section;
1492 dbxout_symbol (decl, 0);
1494 if (in_section != saved_in_section)
1495 variable_section (decl, reloc);
1497 #else
1498 /* There must be a statement after a label. */
1500 #endif
1503 /* Return 1 if type TYPE contains any pointers. */
1505 static int
1506 contains_pointers_p (type)
1507 tree type;
1509 switch (TREE_CODE (type))
1511 case POINTER_TYPE:
1512 case REFERENCE_TYPE:
1513 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1514 so I'll play safe and return 1. */
1515 case OFFSET_TYPE:
1516 return 1;
1518 case RECORD_TYPE:
1519 case UNION_TYPE:
1520 case QUAL_UNION_TYPE:
1522 tree fields;
1523 /* For a type that has fields, see if the fields have pointers. */
1524 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1525 if (TREE_CODE (fields) == FIELD_DECL
1526 && contains_pointers_p (TREE_TYPE (fields)))
1527 return 1;
1528 return 0;
1531 case ARRAY_TYPE:
1532 /* An array type contains pointers if its element type does. */
1533 return contains_pointers_p (TREE_TYPE (type));
1535 default:
1536 return 0;
1540 /* Output something to declare an external symbol to the assembler.
1541 (Most assemblers don't need this, so we normally output nothing.)
1542 Do nothing if DECL is not external. */
1544 void
1545 assemble_external (decl)
1546 tree decl;
1548 #ifdef ASM_OUTPUT_EXTERNAL
1549 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1550 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1552 rtx rtl = DECL_RTL (decl);
1554 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1555 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1557 /* Some systems do require some output. */
1558 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1559 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1562 #endif
1565 /* Similar, for calling a library function FUN. */
1567 void
1568 assemble_external_libcall (fun)
1569 rtx fun;
1571 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1572 /* Declare library function name external when first used, if nec. */
1573 if (! SYMBOL_REF_USED (fun))
1575 SYMBOL_REF_USED (fun) = 1;
1576 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1578 #endif
1581 /* Declare the label NAME global. */
1583 void
1584 assemble_global (name)
1585 char *name;
1587 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1590 /* Assemble a label named NAME. */
1592 void
1593 assemble_label (name)
1594 char *name;
1596 ASM_OUTPUT_LABEL (asm_out_file, name);
1599 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1600 If NAME starts with a *, the rest of NAME is output verbatim.
1601 Otherwise NAME is transformed in an implementation-defined way
1602 (usually by the addition of an underscore).
1603 Many macros in the tm file are defined to call this function. */
1605 void
1606 assemble_name (file, name)
1607 FILE *file;
1608 char *name;
1610 char *real_name;
1611 tree id;
1613 STRIP_NAME_ENCODING (real_name, name);
1614 if (flag_prefix_function_name
1615 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1616 real_name = real_name + CHKR_PREFIX_SIZE;
1618 id = maybe_get_identifier (real_name);
1619 if (id)
1620 TREE_SYMBOL_REFERENCED (id) = 1;
1622 if (name[0] == '*')
1623 fputs (&name[1], file);
1624 else
1625 ASM_OUTPUT_LABELREF (file, name);
1628 /* Allocate SIZE bytes writable static space with a gensym name
1629 and return an RTX to refer to its address. */
1632 assemble_static_space (size)
1633 int size;
1635 char name[12];
1636 char *namestring;
1637 rtx x;
1638 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1639 so that each uninitialized object starts on such a boundary. */
1640 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1641 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1642 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1644 #if 0
1645 if (flag_shared_data)
1646 data_section ();
1647 #endif
1649 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1650 ++const_labelno;
1652 namestring = (char *) obstack_alloc (saveable_obstack,
1653 strlen (name) + 2);
1654 strcpy (namestring, name);
1656 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1658 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1659 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1660 BIGGEST_ALIGNMENT);
1661 #else
1662 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1663 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1664 #else
1665 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1666 #endif
1667 #endif
1668 return x;
1671 /* Assemble the static constant template for function entry trampolines.
1672 This is done at most once per compilation.
1673 Returns an RTX for the address of the template. */
1675 #ifdef TRAMPOLINE_TEMPLATE
1677 assemble_trampoline_template ()
1679 char label[256];
1680 char *name;
1681 int align;
1683 /* By default, put trampoline templates in read-only data section. */
1685 #ifdef TRAMPOLINE_SECTION
1686 TRAMPOLINE_SECTION ();
1687 #else
1688 readonly_data_section ();
1689 #endif
1691 /* Write the assembler code to define one. */
1692 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1693 if (align > 0)
1694 ASM_OUTPUT_ALIGN (asm_out_file, align);
1696 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1697 TRAMPOLINE_TEMPLATE (asm_out_file);
1699 /* Record the rtl to refer to it. */
1700 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1701 name
1702 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1703 return gen_rtx_SYMBOL_REF (Pmode, name);
1705 #endif
1707 /* Assemble the integer constant X into an object of SIZE bytes.
1708 X must be either a CONST_INT or CONST_DOUBLE.
1710 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1711 non-zero, abort if we can't output the constant. */
1714 assemble_integer (x, size, force)
1715 rtx x;
1716 int size;
1717 int force;
1719 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1720 ASM_OUTPUT... macros. */
1722 switch (size)
1724 #ifdef ASM_OUTPUT_CHAR
1725 case 1:
1726 ASM_OUTPUT_CHAR (asm_out_file, x);
1727 return 1;
1728 #endif
1730 #ifdef ASM_OUTPUT_SHORT
1731 case 2:
1732 ASM_OUTPUT_SHORT (asm_out_file, x);
1733 return 1;
1734 #endif
1736 #ifdef ASM_OUTPUT_INT
1737 case 4:
1738 ASM_OUTPUT_INT (asm_out_file, x);
1739 return 1;
1740 #endif
1742 #ifdef ASM_OUTPUT_DOUBLE_INT
1743 case 8:
1744 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1745 return 1;
1746 #endif
1748 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1749 case 16:
1750 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1751 return 1;
1752 #endif
1755 /* If we couldn't do it that way, there are two other possibilities: First,
1756 if the machine can output an explicit byte and this is a 1 byte constant,
1757 we can use ASM_OUTPUT_BYTE. */
1759 #ifdef ASM_OUTPUT_BYTE
1760 if (size == 1 && GET_CODE (x) == CONST_INT)
1762 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1763 return 1;
1765 #endif
1767 /* Finally, if SIZE is larger than a single word, try to output the constant
1768 one word at a time. */
1770 if (size > UNITS_PER_WORD)
1772 int i;
1773 enum machine_mode mode
1774 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1775 rtx word;
1777 for (i = 0; i < size / UNITS_PER_WORD; i++)
1779 word = operand_subword (x, i, 0, mode);
1781 if (word == 0)
1782 break;
1784 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1785 break;
1788 if (i == size / UNITS_PER_WORD)
1789 return 1;
1790 /* If we output at least one word and then could not finish,
1791 there is no valid way to continue. */
1792 if (i > 0)
1793 abort ();
1796 if (force)
1797 abort ();
1799 return 0;
1802 /* Assemble the floating-point constant D into an object of size MODE. */
1804 void
1805 assemble_real (d, mode)
1806 REAL_VALUE_TYPE d;
1807 enum machine_mode mode;
1809 jmp_buf output_constant_handler;
1811 if (setjmp (output_constant_handler))
1813 error ("floating point trap outputting a constant");
1814 #ifdef REAL_IS_NOT_DOUBLE
1815 bzero ((char *) &d, sizeof d);
1816 d = dconst0;
1817 #else
1818 d = 0;
1819 #endif
1822 set_float_handler (output_constant_handler);
1824 switch (mode)
1826 #ifdef ASM_OUTPUT_BYTE_FLOAT
1827 case QFmode:
1828 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1829 break;
1830 #endif
1831 #ifdef ASM_OUTPUT_SHORT_FLOAT
1832 case HFmode:
1833 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1834 break;
1835 #endif
1836 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1837 case TQFmode:
1838 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1839 break;
1840 #endif
1841 #ifdef ASM_OUTPUT_FLOAT
1842 case SFmode:
1843 ASM_OUTPUT_FLOAT (asm_out_file, d);
1844 break;
1845 #endif
1847 #ifdef ASM_OUTPUT_DOUBLE
1848 case DFmode:
1849 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1850 break;
1851 #endif
1853 #ifdef ASM_OUTPUT_LONG_DOUBLE
1854 case XFmode:
1855 case TFmode:
1856 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1857 break;
1858 #endif
1860 default:
1861 abort ();
1864 set_float_handler (NULL_PTR);
1867 /* Here we combine duplicate floating constants to make
1868 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1870 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1871 They are chained through the CONST_DOUBLE_CHAIN.
1872 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1873 In that case, CONST_DOUBLE_MEM is either a MEM,
1874 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1876 (CONST_DOUBLE_MEM is used only for top-level functions.
1877 See force_const_mem for explanation.) */
1879 static rtx const_double_chain;
1881 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1882 For an integer, I0 is the low-order word and I1 is the high-order word.
1883 For a real number, I0 is the word with the low address
1884 and I1 is the word with the high address. */
1887 immed_double_const (i0, i1, mode)
1888 HOST_WIDE_INT i0, i1;
1889 enum machine_mode mode;
1891 register rtx r;
1893 if (GET_MODE_CLASS (mode) == MODE_INT
1894 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1896 /* We clear out all bits that don't belong in MODE, unless they and our
1897 sign bit are all one. So we get either a reasonable negative value
1898 or a reasonable unsigned value for this mode. */
1899 int width = GET_MODE_BITSIZE (mode);
1900 if (width < HOST_BITS_PER_WIDE_INT
1901 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1902 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1903 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1904 else if (width == HOST_BITS_PER_WIDE_INT
1905 && ! (i1 == ~0 && i0 < 0))
1906 i1 = 0;
1907 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1908 /* We cannot represent this value as a constant. */
1909 abort ();
1911 /* If this would be an entire word for the target, but is not for
1912 the host, then sign-extend on the host so that the number will look
1913 the same way on the host that it would on the target.
1915 For example, when building a 64 bit alpha hosted 32 bit sparc
1916 targeted compiler, then we want the 32 bit unsigned value -1 to be
1917 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1918 The later confuses the sparc backend. */
1920 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1921 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1922 i0 |= ((HOST_WIDE_INT) (-1) << width);
1924 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1926 ??? Strictly speaking, this is wrong if we create a CONST_INT
1927 for a large unsigned constant with the size of MODE being
1928 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1929 wider mode. In that case we will mis-interpret it as a negative
1930 number.
1932 Unfortunately, the only alternative is to make a CONST_DOUBLE
1933 for any constant in any mode if it is an unsigned constant larger
1934 than the maximum signed integer in an int on the host. However,
1935 doing this will break everyone that always expects to see a CONST_INT
1936 for SImode and smaller.
1938 We have always been making CONST_INTs in this case, so nothing new
1939 is being broken. */
1941 if (width <= HOST_BITS_PER_WIDE_INT)
1942 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
1944 /* If this integer fits in one word, return a CONST_INT. */
1945 if ((i1 == 0 && i0 >= 0)
1946 || (i1 == ~0 && i0 < 0))
1947 return GEN_INT (i0);
1949 /* We use VOIDmode for integers. */
1950 mode = VOIDmode;
1953 /* Search the chain for an existing CONST_DOUBLE with the right value.
1954 If one is found, return it. */
1956 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1957 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1958 && GET_MODE (r) == mode)
1959 return r;
1961 /* No; make a new one and add it to the chain.
1963 We may be called by an optimizer which may be discarding any memory
1964 allocated during its processing (such as combine and loop). However,
1965 we will be leaving this constant on the chain, so we cannot tolerate
1966 freed memory. So switch to saveable_obstack for this allocation
1967 and then switch back if we were in current_obstack. */
1969 push_obstacks_nochange ();
1970 rtl_in_saveable_obstack ();
1971 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
1972 pop_obstacks ();
1974 /* Don't touch const_double_chain in nested function; see force_const_mem.
1975 Also, don't touch it if not inside any function. */
1976 if (outer_function_chain == 0 && current_function_decl != 0)
1978 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1979 const_double_chain = r;
1982 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1983 Actual use of mem-slot is only through force_const_mem. */
1985 CONST_DOUBLE_MEM (r) = const0_rtx;
1987 return r;
1990 /* Return a CONST_DOUBLE for a specified `double' value
1991 and machine mode. */
1994 immed_real_const_1 (d, mode)
1995 REAL_VALUE_TYPE d;
1996 enum machine_mode mode;
1998 union real_extract u;
1999 register rtx r;
2001 /* Get the desired `double' value as a sequence of ints
2002 since that is how they are stored in a CONST_DOUBLE. */
2004 u.d = d;
2006 /* Detect special cases. */
2008 if (REAL_VALUES_IDENTICAL (dconst0, d))
2009 return CONST0_RTX (mode);
2010 /* Check for NaN first, because some ports (specifically the i386) do not
2011 emit correct ieee-fp code by default, and thus will generate a core
2012 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2013 does a floating point comparison. */
2014 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2015 return CONST1_RTX (mode);
2017 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2018 return immed_double_const (u.i[0], u.i[1], mode);
2020 /* The rest of this function handles the case where
2021 a float value requires more than 2 ints of space.
2022 It will be deleted as dead code on machines that don't need it. */
2024 /* Search the chain for an existing CONST_DOUBLE with the right value.
2025 If one is found, return it. */
2027 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2028 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2029 && GET_MODE (r) == mode)
2030 return r;
2032 /* No; make a new one and add it to the chain.
2034 We may be called by an optimizer which may be discarding any memory
2035 allocated during its processing (such as combine and loop). However,
2036 we will be leaving this constant on the chain, so we cannot tolerate
2037 freed memory. So switch to saveable_obstack for this allocation
2038 and then switch back if we were in current_obstack. */
2040 push_obstacks_nochange ();
2041 rtl_in_saveable_obstack ();
2042 r = rtx_alloc (CONST_DOUBLE);
2043 PUT_MODE (r, mode);
2044 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2045 pop_obstacks ();
2047 /* Don't touch const_double_chain in nested function; see force_const_mem.
2048 Also, don't touch it if not inside any function. */
2049 if (outer_function_chain == 0 && current_function_decl != 0)
2051 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2052 const_double_chain = r;
2055 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2056 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2057 is only through force_const_mem. */
2059 CONST_DOUBLE_MEM (r) = const0_rtx;
2061 return r;
2064 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2065 which must be a REAL_CST tree node. */
2068 immed_real_const (exp)
2069 tree exp;
2071 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2074 /* At the end of a function, forget the memory-constants
2075 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2076 Also clear out real_constant_chain and clear out all the chain-pointers. */
2078 void
2079 clear_const_double_mem ()
2081 register rtx r, next;
2083 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2084 See force_const_mem for explanation. */
2085 if (outer_function_chain != 0)
2086 return;
2088 for (r = const_double_chain; r; r = next)
2090 next = CONST_DOUBLE_CHAIN (r);
2091 CONST_DOUBLE_CHAIN (r) = 0;
2092 CONST_DOUBLE_MEM (r) = cc0_rtx;
2094 const_double_chain = 0;
2097 /* Given an expression EXP with a constant value,
2098 reduce it to the sum of an assembler symbol and an integer.
2099 Store them both in the structure *VALUE.
2100 Abort if EXP does not reduce. */
2102 struct addr_const
2104 rtx base;
2105 HOST_WIDE_INT offset;
2108 static void
2109 decode_addr_const (exp, value)
2110 tree exp;
2111 struct addr_const *value;
2113 register tree target = TREE_OPERAND (exp, 0);
2114 register int offset = 0;
2115 register rtx x;
2117 while (1)
2119 if (TREE_CODE (target) == COMPONENT_REF
2120 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2121 == INTEGER_CST))
2123 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2124 target = TREE_OPERAND (target, 0);
2126 else if (TREE_CODE (target) == ARRAY_REF)
2128 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2129 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2130 abort ();
2131 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2132 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2133 / BITS_PER_UNIT);
2134 target = TREE_OPERAND (target, 0);
2136 else
2137 break;
2140 switch (TREE_CODE (target))
2142 case VAR_DECL:
2143 case FUNCTION_DECL:
2144 x = DECL_RTL (target);
2145 break;
2147 case LABEL_DECL:
2148 x = gen_rtx_MEM (FUNCTION_MODE,
2149 gen_rtx_LABEL_REF (VOIDmode,
2150 label_rtx (TREE_OPERAND (exp, 0))));
2151 break;
2153 case REAL_CST:
2154 case STRING_CST:
2155 case COMPLEX_CST:
2156 case CONSTRUCTOR:
2157 case INTEGER_CST:
2158 x = TREE_CST_RTL (target);
2159 break;
2161 default:
2162 abort ();
2165 if (GET_CODE (x) != MEM)
2166 abort ();
2167 x = XEXP (x, 0);
2169 value->base = x;
2170 value->offset = offset;
2173 /* Uniquize all constants that appear in memory.
2174 Each constant in memory thus far output is recorded
2175 in `const_hash_table' with a `struct constant_descriptor'
2176 that contains a polish representation of the value of
2177 the constant.
2179 We cannot store the trees in the hash table
2180 because the trees may be temporary. */
2182 struct constant_descriptor
2184 struct constant_descriptor *next;
2185 char *label;
2186 char contents[1];
2189 #define HASHBITS 30
2190 #define MAX_HASH_TABLE 1009
2191 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2193 /* Compute a hash code for a constant expression. */
2195 static int
2196 const_hash (exp)
2197 tree exp;
2199 register char *p;
2200 register int len, hi, i;
2201 register enum tree_code code = TREE_CODE (exp);
2203 /* Either set P and LEN to the address and len of something to hash and
2204 exit the switch or return a value. */
2206 switch (code)
2208 case INTEGER_CST:
2209 p = (char *) &TREE_INT_CST_LOW (exp);
2210 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2211 break;
2213 case REAL_CST:
2214 p = (char *) &TREE_REAL_CST (exp);
2215 len = sizeof TREE_REAL_CST (exp);
2216 break;
2218 case STRING_CST:
2219 p = TREE_STRING_POINTER (exp);
2220 len = TREE_STRING_LENGTH (exp);
2221 break;
2223 case COMPLEX_CST:
2224 return (const_hash (TREE_REALPART (exp)) * 5
2225 + const_hash (TREE_IMAGPART (exp)));
2227 case CONSTRUCTOR:
2228 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2230 len = int_size_in_bytes (TREE_TYPE (exp));
2231 p = (char *) alloca (len);
2232 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2233 break;
2235 else
2237 register tree link;
2239 /* For record type, include the type in the hashing.
2240 We do not do so for array types
2241 because (1) the sizes of the elements are sufficient
2242 and (2) distinct array types can have the same constructor.
2243 Instead, we include the array size because the constructor could
2244 be shorter. */
2245 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2246 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2247 % MAX_HASH_TABLE;
2248 else
2249 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2250 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2252 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2253 if (TREE_VALUE (link))
2255 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2257 return hi;
2260 case ADDR_EXPR:
2262 struct addr_const value;
2264 decode_addr_const (exp, &value);
2265 if (GET_CODE (value.base) == SYMBOL_REF)
2267 /* Don't hash the address of the SYMBOL_REF;
2268 only use the offset and the symbol name. */
2269 hi = value.offset;
2270 p = XSTR (value.base, 0);
2271 for (i = 0; p[i] != 0; i++)
2272 hi = ((hi * 613) + (unsigned) (p[i]));
2274 else if (GET_CODE (value.base) == LABEL_REF)
2275 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2277 hi &= (1 << HASHBITS) - 1;
2278 hi %= MAX_HASH_TABLE;
2280 return hi;
2282 case PLUS_EXPR:
2283 case MINUS_EXPR:
2284 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2285 + const_hash (TREE_OPERAND (exp, 1)));
2287 case NOP_EXPR:
2288 case CONVERT_EXPR:
2289 case NON_LVALUE_EXPR:
2290 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2292 default:
2293 abort ();
2296 /* Compute hashing function */
2297 hi = len;
2298 for (i = 0; i < len; i++)
2299 hi = ((hi * 613) + (unsigned) (p[i]));
2301 hi &= (1 << HASHBITS) - 1;
2302 hi %= MAX_HASH_TABLE;
2303 return hi;
2306 /* Compare a constant expression EXP with a constant-descriptor DESC.
2307 Return 1 if DESC describes a constant with the same value as EXP. */
2309 static int
2310 compare_constant (exp, desc)
2311 tree exp;
2312 struct constant_descriptor *desc;
2314 return 0 != compare_constant_1 (exp, desc->contents);
2317 /* Compare constant expression EXP with a substring P of a constant descriptor.
2318 If they match, return a pointer to the end of the substring matched.
2319 If they do not match, return 0.
2321 Since descriptors are written in polish prefix notation,
2322 this function can be used recursively to test one operand of EXP
2323 against a subdescriptor, and if it succeeds it returns the
2324 address of the subdescriptor for the next operand. */
2326 static char *
2327 compare_constant_1 (exp, p)
2328 tree exp;
2329 char *p;
2331 register char *strp;
2332 register int len;
2333 register enum tree_code code = TREE_CODE (exp);
2335 if (code != (enum tree_code) *p++)
2336 return 0;
2338 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2339 switch, or return the result of the comparison. */
2341 switch (code)
2343 case INTEGER_CST:
2344 /* Integer constants are the same only if the same width of type. */
2345 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2346 return 0;
2348 strp = (char *) &TREE_INT_CST_LOW (exp);
2349 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2350 break;
2352 case REAL_CST:
2353 /* Real constants are the same only if the same width of type. */
2354 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2355 return 0;
2357 strp = (char *) &TREE_REAL_CST (exp);
2358 len = sizeof TREE_REAL_CST (exp);
2359 break;
2361 case STRING_CST:
2362 if (flag_writable_strings)
2363 return 0;
2365 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2366 return 0;
2368 strp = TREE_STRING_POINTER (exp);
2369 len = TREE_STRING_LENGTH (exp);
2370 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2371 sizeof TREE_STRING_LENGTH (exp)))
2372 return 0;
2374 p += sizeof TREE_STRING_LENGTH (exp);
2375 break;
2377 case COMPLEX_CST:
2378 p = compare_constant_1 (TREE_REALPART (exp), p);
2379 if (p == 0)
2380 return 0;
2382 return compare_constant_1 (TREE_IMAGPART (exp), p);
2384 case CONSTRUCTOR:
2385 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2387 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2389 strp = (char *) alloca (len);
2390 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2391 if (bcmp ((char *) &xlen, p, sizeof xlen))
2392 return 0;
2394 p += sizeof xlen;
2395 break;
2397 else
2399 register tree link;
2400 int length = list_length (CONSTRUCTOR_ELTS (exp));
2401 tree type;
2403 if (bcmp ((char *) &length, p, sizeof length))
2404 return 0;
2406 p += sizeof length;
2408 /* For record constructors, insist that the types match.
2409 For arrays, just verify both constructors are for arrays. */
2410 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2411 type = TREE_TYPE (exp);
2412 else
2413 type = 0;
2415 if (bcmp ((char *) &type, p, sizeof type))
2416 return 0;
2418 p += sizeof type;
2420 /* For arrays, insist that the size in bytes match. */
2421 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2423 int size = int_size_in_bytes (TREE_TYPE (exp));
2424 if (bcmp ((char *) &size, p, sizeof size))
2425 return 0;
2427 p += sizeof size;
2430 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2432 if (TREE_VALUE (link))
2434 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2435 return 0;
2437 else
2439 tree zero = 0;
2441 if (bcmp ((char *) &zero, p, sizeof zero))
2442 return 0;
2444 p += sizeof zero;
2448 return p;
2451 case ADDR_EXPR:
2453 struct addr_const value;
2455 decode_addr_const (exp, &value);
2456 strp = (char *) &value.offset;
2457 len = sizeof value.offset;
2458 /* Compare the offset. */
2459 while (--len >= 0)
2460 if (*p++ != *strp++)
2461 return 0;
2463 /* Compare symbol name. */
2464 strp = XSTR (value.base, 0);
2465 len = strlen (strp) + 1;
2467 break;
2469 case PLUS_EXPR:
2470 case MINUS_EXPR:
2471 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2472 if (p == 0)
2473 return 0;
2475 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2477 case NOP_EXPR:
2478 case CONVERT_EXPR:
2479 case NON_LVALUE_EXPR:
2480 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2482 default:
2483 abort ();
2486 /* Compare constant contents. */
2487 while (--len >= 0)
2488 if (*p++ != *strp++)
2489 return 0;
2491 return p;
2494 /* Construct a constant descriptor for the expression EXP.
2495 It is up to the caller to enter the descriptor in the hash table. */
2497 static struct constant_descriptor *
2498 record_constant (exp)
2499 tree exp;
2501 struct constant_descriptor *next = 0;
2502 char *label = 0;
2504 /* Make a struct constant_descriptor. The first two pointers will
2505 be filled in later. Here we just leave space for them. */
2507 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2508 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2509 record_constant_1 (exp);
2510 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2513 /* Add a description of constant expression EXP
2514 to the object growing in `permanent_obstack'.
2515 No need to return its address; the caller will get that
2516 from the obstack when the object is complete. */
2518 static void
2519 record_constant_1 (exp)
2520 tree exp;
2522 register char *strp;
2523 register int len;
2524 register enum tree_code code = TREE_CODE (exp);
2526 obstack_1grow (&permanent_obstack, (unsigned int) code);
2528 switch (code)
2530 case INTEGER_CST:
2531 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2532 strp = (char *) &TREE_INT_CST_LOW (exp);
2533 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2534 break;
2536 case REAL_CST:
2537 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2538 strp = (char *) &TREE_REAL_CST (exp);
2539 len = sizeof TREE_REAL_CST (exp);
2540 break;
2542 case STRING_CST:
2543 if (flag_writable_strings)
2544 return;
2546 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2547 strp = TREE_STRING_POINTER (exp);
2548 len = TREE_STRING_LENGTH (exp);
2549 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2550 sizeof TREE_STRING_LENGTH (exp));
2551 break;
2553 case COMPLEX_CST:
2554 record_constant_1 (TREE_REALPART (exp));
2555 record_constant_1 (TREE_IMAGPART (exp));
2556 return;
2558 case CONSTRUCTOR:
2559 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2561 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2562 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2563 obstack_blank (&permanent_obstack, nbytes);
2564 get_set_constructor_bytes
2565 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2566 nbytes);
2567 return;
2569 else
2571 register tree link;
2572 int length = list_length (CONSTRUCTOR_ELTS (exp));
2573 tree type;
2575 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2577 /* For record constructors, insist that the types match.
2578 For arrays, just verify both constructors are for arrays. */
2579 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2580 type = TREE_TYPE (exp);
2581 else
2582 type = 0;
2583 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2585 /* For arrays, insist that the size in bytes match. */
2586 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2588 int size = int_size_in_bytes (TREE_TYPE (exp));
2589 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2592 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2594 if (TREE_VALUE (link))
2595 record_constant_1 (TREE_VALUE (link));
2596 else
2598 tree zero = 0;
2600 obstack_grow (&permanent_obstack,
2601 (char *) &zero, sizeof zero);
2605 return;
2607 case ADDR_EXPR:
2609 struct addr_const value;
2611 decode_addr_const (exp, &value);
2612 /* Record the offset. */
2613 obstack_grow (&permanent_obstack,
2614 (char *) &value.offset, sizeof value.offset);
2615 /* Record the symbol name. */
2616 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2617 strlen (XSTR (value.base, 0)) + 1);
2619 return;
2621 case PLUS_EXPR:
2622 case MINUS_EXPR:
2623 record_constant_1 (TREE_OPERAND (exp, 0));
2624 record_constant_1 (TREE_OPERAND (exp, 1));
2625 return;
2627 case NOP_EXPR:
2628 case CONVERT_EXPR:
2629 case NON_LVALUE_EXPR:
2630 record_constant_1 (TREE_OPERAND (exp, 0));
2631 return;
2633 default:
2634 abort ();
2637 /* Record constant contents. */
2638 obstack_grow (&permanent_obstack, strp, len);
2641 /* Record a list of constant expressions that were passed to
2642 output_constant_def but that could not be output right away. */
2644 struct deferred_constant
2646 struct deferred_constant *next;
2647 tree exp;
2648 int reloc;
2649 int labelno;
2652 static struct deferred_constant *deferred_constants;
2654 /* Another list of constants which should be output after the
2655 function. */
2656 static struct deferred_constant *after_function_constants;
2658 /* Nonzero means defer output of addressed subconstants
2659 (i.e., those for which output_constant_def is called.) */
2660 static int defer_addressed_constants_flag;
2662 /* Start deferring output of subconstants. */
2664 void
2665 defer_addressed_constants ()
2667 defer_addressed_constants_flag++;
2670 /* Stop deferring output of subconstants,
2671 and output now all those that have been deferred. */
2673 void
2674 output_deferred_addressed_constants ()
2676 struct deferred_constant *p, *next;
2678 defer_addressed_constants_flag--;
2680 if (defer_addressed_constants_flag > 0)
2681 return;
2683 for (p = deferred_constants; p; p = next)
2685 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2686 next = p->next;
2687 free (p);
2690 deferred_constants = 0;
2693 /* Output any constants which should appear after a function. */
2695 static void
2696 output_after_function_constants ()
2698 struct deferred_constant *p, *next;
2700 for (p = after_function_constants; p; p = next)
2702 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2703 next = p->next;
2704 free (p);
2707 after_function_constants = 0;
2710 /* Make a copy of the whole tree structure for a constant.
2711 This handles the same types of nodes that compare_constant
2712 and record_constant handle. */
2714 static tree
2715 copy_constant (exp)
2716 tree exp;
2718 switch (TREE_CODE (exp))
2720 case ADDR_EXPR:
2721 /* For ADDR_EXPR, we do not want to copy the decl whose address
2722 is requested. We do want to copy constants though. */
2723 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2724 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2725 copy_constant (TREE_OPERAND (exp, 0)));
2726 else
2727 return copy_node (exp);
2729 case INTEGER_CST:
2730 case REAL_CST:
2731 case STRING_CST:
2732 return copy_node (exp);
2734 case COMPLEX_CST:
2735 return build_complex (TREE_TYPE (exp),
2736 copy_constant (TREE_REALPART (exp)),
2737 copy_constant (TREE_IMAGPART (exp)));
2739 case PLUS_EXPR:
2740 case MINUS_EXPR:
2741 return build (TREE_CODE (exp), TREE_TYPE (exp),
2742 copy_constant (TREE_OPERAND (exp, 0)),
2743 copy_constant (TREE_OPERAND (exp, 1)));
2745 case NOP_EXPR:
2746 case CONVERT_EXPR:
2747 case NON_LVALUE_EXPR:
2748 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2749 copy_constant (TREE_OPERAND (exp, 0)));
2751 case CONSTRUCTOR:
2753 tree copy = copy_node (exp);
2754 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2755 tree tail;
2757 CONSTRUCTOR_ELTS (copy) = list;
2758 for (tail = list; tail; tail = TREE_CHAIN (tail))
2759 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2760 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2761 for (tail = list; tail; tail = TREE_CHAIN (tail))
2762 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2764 return copy;
2767 default:
2768 abort ();
2772 /* Return an rtx representing a reference to constant data in memory
2773 for the constant expression EXP.
2775 If assembler code for such a constant has already been output,
2776 return an rtx to refer to it.
2777 Otherwise, output such a constant in memory (or defer it for later)
2778 and generate an rtx for it.
2780 The TREE_CST_RTL of EXP is set up to point to that rtx.
2781 The const_hash_table records which constants already have label strings. */
2784 output_constant_def (exp)
2785 tree exp;
2787 register int hash;
2788 register struct constant_descriptor *desc;
2789 char label[256];
2790 char *found = 0;
2791 int reloc;
2792 register rtx def;
2794 if (TREE_CST_RTL (exp))
2795 return TREE_CST_RTL (exp);
2797 /* Make sure any other constants whose addresses appear in EXP
2798 are assigned label numbers. */
2800 reloc = output_addressed_constants (exp);
2802 /* Compute hash code of EXP. Search the descriptors for that hash code
2803 to see if any of them describes EXP. If yes, the descriptor records
2804 the label number already assigned. */
2806 hash = const_hash (exp) % MAX_HASH_TABLE;
2808 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2809 if (compare_constant (exp, desc))
2811 found = desc->label;
2812 break;
2815 if (found == 0)
2817 /* No constant equal to EXP is known to have been output.
2818 Make a constant descriptor to enter EXP in the hash table.
2819 Assign the label number and record it in the descriptor for
2820 future calls to this function to find. */
2822 /* Create a string containing the label name, in LABEL. */
2823 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2825 desc = record_constant (exp);
2826 desc->next = const_hash_table[hash];
2827 desc->label
2828 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2829 const_hash_table[hash] = desc;
2831 else
2833 /* Create a string containing the label name, in LABEL. */
2834 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2837 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2839 push_obstacks_nochange ();
2840 if (TREE_PERMANENT (exp))
2841 end_temporary_allocation ();
2843 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
2845 TREE_CST_RTL (exp)
2846 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
2847 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2848 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2849 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2851 pop_obstacks ();
2853 /* Optionally set flags or add text to the name to record information
2854 such as that it is a function name. If the name is changed, the macro
2855 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2856 #ifdef ENCODE_SECTION_INFO
2857 ENCODE_SECTION_INFO (exp);
2858 #endif
2860 /* If this is the first time we've seen this particular constant,
2861 output it (or defer its output for later). */
2862 if (found == 0)
2864 int after_function = 0;
2866 #ifdef CONSTANT_AFTER_FUNCTION_P
2867 if (current_function_decl != 0
2868 && CONSTANT_AFTER_FUNCTION_P (exp))
2869 after_function = 1;
2870 #endif
2872 if (defer_addressed_constants_flag || after_function)
2874 struct deferred_constant *p;
2875 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2877 push_obstacks_nochange ();
2878 suspend_momentary ();
2879 p->exp = copy_constant (exp);
2880 pop_obstacks ();
2881 p->reloc = reloc;
2882 p->labelno = const_labelno++;
2883 if (after_function)
2885 p->next = after_function_constants;
2886 after_function_constants = p;
2888 else
2890 p->next = deferred_constants;
2891 deferred_constants = p;
2894 else
2895 output_constant_def_contents (exp, reloc, const_labelno++);
2898 return TREE_CST_RTL (exp);
2901 /* Now output assembler code to define the label for EXP,
2902 and follow it with the data of EXP. */
2904 static void
2905 output_constant_def_contents (exp, reloc, labelno)
2906 tree exp;
2907 int reloc;
2908 int labelno;
2910 int align;
2912 if (IN_NAMED_SECTION (exp))
2913 named_section (exp, NULL, reloc);
2914 else
2916 /* First switch to text section, except for writable strings. */
2917 #ifdef SELECT_SECTION
2918 SELECT_SECTION (exp, reloc);
2919 #else
2920 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2921 || (flag_pic && reloc))
2922 data_section ();
2923 else
2924 readonly_data_section ();
2925 #endif
2928 /* Align the location counter as required by EXP's data type. */
2929 align = TYPE_ALIGN (TREE_TYPE (exp));
2930 #ifdef CONSTANT_ALIGNMENT
2931 align = CONSTANT_ALIGNMENT (exp, align);
2932 #endif
2934 if (align > BITS_PER_UNIT)
2935 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2937 /* Output the label itself. */
2938 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2940 /* Output the value of EXP. */
2941 output_constant (exp,
2942 (TREE_CODE (exp) == STRING_CST
2943 ? TREE_STRING_LENGTH (exp)
2944 : int_size_in_bytes (TREE_TYPE (exp))));
2948 /* Similar hash facility for making memory-constants
2949 from constant rtl-expressions. It is used on RISC machines
2950 where immediate integer arguments and constant addresses are restricted
2951 so that such constants must be stored in memory.
2953 This pool of constants is reinitialized for each function
2954 so each function gets its own constants-pool that comes right before it.
2956 All structures allocated here are discarded when functions are saved for
2957 inlining, so they do not need to be allocated permanently. */
2959 #define MAX_RTX_HASH_TABLE 61
2960 static struct constant_descriptor **const_rtx_hash_table;
2962 /* Structure to represent sufficient information about a constant so that
2963 it can be output when the constant pool is output, so that function
2964 integration can be done, and to simplify handling on machines that reference
2965 constant pool as base+displacement. */
2967 struct pool_constant
2969 struct constant_descriptor *desc;
2970 struct pool_constant *next;
2971 enum machine_mode mode;
2972 rtx constant;
2973 int labelno;
2974 int align;
2975 int offset;
2976 int mark;
2979 /* Pointers to first and last constant in pool. */
2981 static struct pool_constant *first_pool, *last_pool;
2983 /* Current offset in constant pool (does not include any machine-specific
2984 header. */
2986 static int pool_offset;
2988 /* Structure used to maintain hash table mapping symbols used to their
2989 corresponding constants. */
2991 struct pool_sym
2993 char *label;
2994 struct pool_constant *pool;
2995 struct pool_sym *next;
2998 static struct pool_sym **const_rtx_sym_hash_table;
3000 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3001 The argument is XSTR (... , 0) */
3003 #define SYMHASH(LABEL) \
3004 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3006 /* Initialize constant pool hashing for next function. */
3008 void
3009 init_const_rtx_hash_table ()
3011 const_rtx_hash_table
3012 = ((struct constant_descriptor **)
3013 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3014 const_rtx_sym_hash_table
3015 = ((struct pool_sym **)
3016 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3017 bzero ((char *) const_rtx_hash_table,
3018 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3019 bzero ((char *) const_rtx_sym_hash_table,
3020 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3022 first_pool = last_pool = 0;
3023 pool_offset = 0;
3026 /* Save and restore status for a nested function. */
3028 void
3029 save_varasm_status (p, context)
3030 struct function *p;
3031 tree context;
3033 p->const_rtx_hash_table = const_rtx_hash_table;
3034 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3035 p->first_pool = first_pool;
3036 p->last_pool = last_pool;
3037 p->pool_offset = pool_offset;
3038 p->const_double_chain = const_double_chain;
3040 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3041 if (context == NULL_TREE)
3042 const_double_chain = 0;
3045 void
3046 restore_varasm_status (p)
3047 struct function *p;
3049 const_rtx_hash_table = p->const_rtx_hash_table;
3050 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3051 first_pool = p->first_pool;
3052 last_pool = p->last_pool;
3053 pool_offset = p->pool_offset;
3054 const_double_chain = p->const_double_chain;
3057 enum kind { RTX_DOUBLE, RTX_INT };
3059 struct rtx_const
3061 #ifdef ONLY_INT_FIELDS
3062 unsigned int kind : 16;
3063 unsigned int mode : 16;
3064 #else
3065 enum kind kind : 16;
3066 enum machine_mode mode : 16;
3067 #endif
3068 union {
3069 union real_extract du;
3070 struct addr_const addr;
3071 struct {HOST_WIDE_INT high, low;} di;
3072 } un;
3075 /* Express an rtx for a constant integer (perhaps symbolic)
3076 as the sum of a symbol or label plus an explicit integer.
3077 They are stored into VALUE. */
3079 static void
3080 decode_rtx_const (mode, x, value)
3081 enum machine_mode mode;
3082 rtx x;
3083 struct rtx_const *value;
3085 /* Clear the whole structure, including any gaps. */
3088 int *p = (int *) value;
3089 int *end = (int *) (value + 1);
3090 while (p < end)
3091 *p++ = 0;
3094 value->kind = RTX_INT; /* Most usual kind. */
3095 value->mode = mode;
3097 switch (GET_CODE (x))
3099 case CONST_DOUBLE:
3100 value->kind = RTX_DOUBLE;
3101 if (GET_MODE (x) != VOIDmode)
3103 value->mode = GET_MODE (x);
3104 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3105 (char *) &value->un.du, sizeof value->un.du);
3107 else
3109 value->un.di.low = CONST_DOUBLE_LOW (x);
3110 value->un.di.high = CONST_DOUBLE_HIGH (x);
3112 break;
3114 case CONST_INT:
3115 value->un.addr.offset = INTVAL (x);
3116 break;
3118 case SYMBOL_REF:
3119 case LABEL_REF:
3120 case PC:
3121 value->un.addr.base = x;
3122 break;
3124 case CONST:
3125 x = XEXP (x, 0);
3126 if (GET_CODE (x) == PLUS)
3128 value->un.addr.base = XEXP (x, 0);
3129 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3130 abort ();
3131 value->un.addr.offset = INTVAL (XEXP (x, 1));
3133 else if (GET_CODE (x) == MINUS)
3135 value->un.addr.base = XEXP (x, 0);
3136 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3137 abort ();
3138 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3140 else
3141 abort ();
3142 break;
3144 default:
3145 abort ();
3148 if (value->kind == RTX_INT && value->un.addr.base != 0)
3149 switch (GET_CODE (value->un.addr.base))
3151 case SYMBOL_REF:
3152 case LABEL_REF:
3153 /* Use the string's address, not the SYMBOL_REF's address,
3154 for the sake of addresses of library routines.
3155 For a LABEL_REF, compare labels. */
3156 value->un.addr.base = XEXP (value->un.addr.base, 0);
3158 default:
3159 break;
3163 /* Given a MINUS expression, simplify it if both sides
3164 include the same symbol. */
3167 simplify_subtraction (x)
3168 rtx x;
3170 struct rtx_const val0, val1;
3172 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3173 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3175 if (val0.un.addr.base == val1.un.addr.base)
3176 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3177 return x;
3180 /* Compute a hash code for a constant RTL expression. */
3182 static int
3183 const_hash_rtx (mode, x)
3184 enum machine_mode mode;
3185 rtx x;
3187 register int hi, i;
3189 struct rtx_const value;
3190 decode_rtx_const (mode, x, &value);
3192 /* Compute hashing function */
3193 hi = 0;
3194 for (i = 0; i < sizeof value / sizeof (int); i++)
3195 hi += ((int *) &value)[i];
3197 hi &= (1 << HASHBITS) - 1;
3198 hi %= MAX_RTX_HASH_TABLE;
3199 return hi;
3202 /* Compare a constant rtl object X with a constant-descriptor DESC.
3203 Return 1 if DESC describes a constant with the same value as X. */
3205 static int
3206 compare_constant_rtx (mode, x, desc)
3207 enum machine_mode mode;
3208 rtx x;
3209 struct constant_descriptor *desc;
3211 register int *p = (int *) desc->contents;
3212 register int *strp;
3213 register int len;
3214 struct rtx_const value;
3216 decode_rtx_const (mode, x, &value);
3217 strp = (int *) &value;
3218 len = sizeof value / sizeof (int);
3220 /* Compare constant contents. */
3221 while (--len >= 0)
3222 if (*p++ != *strp++)
3223 return 0;
3225 return 1;
3228 /* Construct a constant descriptor for the rtl-expression X.
3229 It is up to the caller to enter the descriptor in the hash table. */
3231 static struct constant_descriptor *
3232 record_constant_rtx (mode, x)
3233 enum machine_mode mode;
3234 rtx x;
3236 struct constant_descriptor *ptr;
3237 char *label;
3238 struct rtx_const value;
3240 decode_rtx_const (mode, x, &value);
3242 /* Put these things in the saveable obstack so we can ensure it won't
3243 be freed if we are called from combine or some other phase that discards
3244 memory allocated from function_obstack (current_obstack). */
3245 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3246 obstack_grow (saveable_obstack, &label, sizeof label);
3248 /* Record constant contents. */
3249 obstack_grow (saveable_obstack, &value, sizeof value);
3251 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3254 /* Given a constant rtx X, make (or find) a memory constant for its value
3255 and return a MEM rtx to refer to it in memory. */
3258 force_const_mem (mode, x)
3259 enum machine_mode mode;
3260 rtx x;
3262 register int hash;
3263 register struct constant_descriptor *desc;
3264 char label[256];
3265 char *found = 0;
3266 rtx def;
3268 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3269 (this will always be true for floating CONST_DOUBLEs that have been
3270 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3271 use the previous copy. Otherwise, make a new one. Note that in
3272 the unlikely event that this same CONST_DOUBLE is used in two different
3273 modes in an alternating fashion, we will allocate a lot of different
3274 memory locations, but this should be extremely rare. */
3276 /* Don't use CONST_DOUBLE_MEM in a nested function.
3277 Nested functions have their own constant pools,
3278 so they can't share the same values in CONST_DOUBLE_MEM
3279 with the containing function. */
3280 if (outer_function_chain == 0)
3281 if (GET_CODE (x) == CONST_DOUBLE
3282 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3283 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3284 return CONST_DOUBLE_MEM (x);
3286 /* Compute hash code of X. Search the descriptors for that hash code
3287 to see if any of them describes X. If yes, the descriptor records
3288 the label number already assigned. */
3290 hash = const_hash_rtx (mode, x);
3292 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3293 if (compare_constant_rtx (mode, x, desc))
3295 found = desc->label;
3296 break;
3299 if (found == 0)
3301 register struct pool_constant *pool;
3302 register struct pool_sym *sym;
3303 int align;
3305 /* No constant equal to X is known to have been output.
3306 Make a constant descriptor to enter X in the hash table.
3307 Assign the label number and record it in the descriptor for
3308 future calls to this function to find. */
3310 desc = record_constant_rtx (mode, x);
3311 desc->next = const_rtx_hash_table[hash];
3312 const_rtx_hash_table[hash] = desc;
3314 /* Align the location counter as required by EXP's data type. */
3315 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3316 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3317 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3319 pool_offset += align - 1;
3320 pool_offset &= ~ (align - 1);
3322 /* If RTL is not being placed into the saveable obstack, make a
3323 copy of X that is in the saveable obstack in case we are
3324 being called from combine or some other phase that discards
3325 memory it allocates. We used to only do this if it is a
3326 CONST; however, reload can allocate a CONST_INT when
3327 eliminating registers. */
3328 if (rtl_obstack != saveable_obstack
3329 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3331 push_obstacks_nochange ();
3332 rtl_in_saveable_obstack ();
3334 if (GET_CODE (x) == CONST)
3335 x = gen_rtx_CONST (GET_MODE (x),
3336 gen_rtx_PLUS (GET_MODE (x),
3337 XEXP (XEXP (x, 0), 0),
3338 XEXP (XEXP (x, 0), 1)));
3339 else
3340 x = GEN_INT (INTVAL (x));
3342 pop_obstacks ();
3345 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3347 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3348 pool->desc = desc;
3349 pool->constant = x;
3350 pool->mode = mode;
3351 pool->labelno = const_labelno;
3352 pool->align = align;
3353 pool->offset = pool_offset;
3354 pool->mark = 1;
3355 pool->next = 0;
3357 if (last_pool == 0)
3358 first_pool = pool;
3359 else
3360 last_pool->next = pool;
3362 last_pool = pool;
3363 pool_offset += GET_MODE_SIZE (mode);
3365 /* Create a string containing the label name, in LABEL. */
3366 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3368 ++const_labelno;
3370 desc->label = found
3371 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3373 /* Add label to symbol hash table. */
3374 hash = SYMHASH (found);
3375 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3376 sym->label = found;
3377 sym->pool = pool;
3378 sym->next = const_rtx_sym_hash_table[hash];
3379 const_rtx_sym_hash_table[hash] = sym;
3382 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3384 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3386 RTX_UNCHANGING_P (def) = 1;
3387 /* Mark the symbol_ref as belonging to this constants pool. */
3388 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3389 current_function_uses_const_pool = 1;
3391 if (outer_function_chain == 0)
3392 if (GET_CODE (x) == CONST_DOUBLE)
3394 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3396 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3397 const_double_chain = x;
3399 CONST_DOUBLE_MEM (x) = def;
3402 return def;
3405 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3406 the corresponding pool_constant structure. */
3408 static struct pool_constant *
3409 find_pool_constant (addr)
3410 rtx addr;
3412 struct pool_sym *sym;
3413 char *label = XSTR (addr, 0);
3415 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3416 if (sym->label == label)
3417 return sym->pool;
3419 abort ();
3422 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3425 get_pool_constant (addr)
3426 rtx addr;
3428 return (find_pool_constant (addr))->constant;
3431 /* Similar, return the mode. */
3433 enum machine_mode
3434 get_pool_mode (addr)
3435 rtx addr;
3437 return (find_pool_constant (addr))->mode;
3440 /* Similar, return the offset in the constant pool. */
3443 get_pool_offset (addr)
3444 rtx addr;
3446 return (find_pool_constant (addr))->offset;
3449 /* Return the size of the constant pool. */
3452 get_pool_size ()
3454 return pool_offset;
3457 /* Write all the constants in the constant pool. */
3459 void
3460 output_constant_pool (fnname, fndecl)
3461 char *fnname;
3462 tree fndecl;
3464 struct pool_constant *pool;
3465 rtx x;
3466 union real_extract u;
3468 /* It is possible for gcc to call force_const_mem and then to later
3469 discard the instructions which refer to the constant. In such a
3470 case we do not need to output the constant. */
3471 if (optimize >= 0 && flag_expensive_optimizations)
3472 mark_constant_pool ();
3474 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3475 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3476 #endif
3478 for (pool = first_pool; pool; pool = pool->next)
3480 x = pool->constant;
3482 if (! pool->mark)
3483 continue;
3485 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3486 whose CODE_LABEL has been deleted. This can occur if a jump table
3487 is eliminated by optimization. If so, write a constant of zero
3488 instead. Note that this can also happen by turning the
3489 CODE_LABEL into a NOTE. */
3490 if (((GET_CODE (x) == LABEL_REF
3491 && (INSN_DELETED_P (XEXP (x, 0))
3492 || GET_CODE (XEXP (x, 0)) == NOTE)))
3493 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3494 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3495 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3496 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3497 x = const0_rtx;
3499 /* First switch to correct section. */
3500 #ifdef SELECT_RTX_SECTION
3501 SELECT_RTX_SECTION (pool->mode, x);
3502 #else
3503 readonly_data_section ();
3504 #endif
3506 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3507 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3508 pool->align, pool->labelno, done);
3509 #endif
3511 if (pool->align > 1)
3512 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3514 /* Output the label. */
3515 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3517 /* Output the value of the constant itself. */
3518 switch (GET_MODE_CLASS (pool->mode))
3520 case MODE_FLOAT:
3521 if (GET_CODE (x) != CONST_DOUBLE)
3522 abort ();
3524 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3525 assemble_real (u.d, pool->mode);
3526 break;
3528 case MODE_INT:
3529 case MODE_PARTIAL_INT:
3530 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3531 break;
3533 default:
3534 abort ();
3539 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3540 done: ;
3541 #endif
3543 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3544 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3545 #endif
3547 /* Done with this pool. */
3548 first_pool = last_pool = 0;
3551 /* Look through the instructions for this function, and mark all the
3552 entries in the constant pool which are actually being used. */
3554 static void
3555 mark_constant_pool ()
3557 register rtx insn;
3558 struct pool_constant *pool;
3560 if (first_pool == 0)
3561 return;
3563 for (pool = first_pool; pool; pool = pool->next)
3564 pool->mark = 0;
3566 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3567 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3568 mark_constants (PATTERN (insn));
3570 for (insn = current_function_epilogue_delay_list;
3571 insn;
3572 insn = XEXP (insn, 1))
3573 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3574 mark_constants (PATTERN (insn));
3577 static void
3578 mark_constants (x)
3579 register rtx x;
3581 register int i;
3582 register char *format_ptr;
3584 if (x == 0)
3585 return;
3587 if (GET_CODE (x) == SYMBOL_REF)
3589 if (CONSTANT_POOL_ADDRESS_P (x))
3590 find_pool_constant (x)->mark = 1;
3591 return;
3593 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3594 a MEM, but does not constitute a use of that MEM. This is particularly
3595 important inside a nested function, because CONST_DOUBLE_MEM may be
3596 a reference to a MEM in the parent's constant pool. See the comment
3597 in force_const_mem. */
3598 else if (GET_CODE (x) == CONST_DOUBLE)
3599 return;
3601 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3602 insns, not any notes that may be attached. We don't want to mark
3603 a constant just because it happens to appear in a REG_EQUIV note. */
3604 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3606 mark_constants (PATTERN (x));
3607 return;
3610 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3612 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3614 switch (*format_ptr++)
3616 case 'e':
3617 mark_constants (XEXP (x, i));
3618 break;
3620 case 'E':
3621 if (XVEC (x, i) != 0)
3623 register int j;
3625 for (j = 0; j < XVECLEN (x, i); j++)
3626 mark_constants (XVECEXP (x, i, j));
3628 break;
3630 case 'S':
3631 case 's':
3632 case '0':
3633 case 'i':
3634 case 'w':
3635 case 'n':
3636 case 'u':
3637 break;
3639 default:
3640 abort ();
3645 /* Find all the constants whose addresses are referenced inside of EXP,
3646 and make sure assembler code with a label has been output for each one.
3647 Indicate whether an ADDR_EXPR has been encountered. */
3649 static int
3650 output_addressed_constants (exp)
3651 tree exp;
3653 int reloc = 0;
3655 switch (TREE_CODE (exp))
3657 case ADDR_EXPR:
3659 register tree constant = TREE_OPERAND (exp, 0);
3661 while (TREE_CODE (constant) == COMPONENT_REF)
3663 constant = TREE_OPERAND (constant, 0);
3666 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3667 || TREE_CODE (constant) == CONSTRUCTOR)
3668 /* No need to do anything here
3669 for addresses of variables or functions. */
3670 output_constant_def (constant);
3672 reloc = 1;
3673 break;
3675 case PLUS_EXPR:
3676 case MINUS_EXPR:
3677 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3678 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3679 break;
3681 case NOP_EXPR:
3682 case CONVERT_EXPR:
3683 case NON_LVALUE_EXPR:
3684 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3685 break;
3687 case CONSTRUCTOR:
3689 register tree link;
3690 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3691 if (TREE_VALUE (link) != 0)
3692 reloc |= output_addressed_constants (TREE_VALUE (link));
3694 break;
3696 default:
3697 break;
3699 return reloc;
3702 /* Output assembler code for constant EXP to FILE, with no label.
3703 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3704 Assumes output_addressed_constants has been done on EXP already.
3706 Generate exactly SIZE bytes of assembler data, padding at the end
3707 with zeros if necessary. SIZE must always be specified.
3709 SIZE is important for structure constructors,
3710 since trailing members may have been omitted from the constructor.
3711 It is also important for initialization of arrays from string constants
3712 since the full length of the string constant might not be wanted.
3713 It is also needed for initialization of unions, where the initializer's
3714 type is just one member, and that may not be as long as the union.
3716 There a case in which we would fail to output exactly SIZE bytes:
3717 for a structure constructor that wants to produce more than SIZE bytes.
3718 But such constructors will never be generated for any possible input. */
3720 void
3721 output_constant (exp, size)
3722 register tree exp;
3723 register int size;
3725 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3727 if (size == 0)
3728 return;
3730 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3731 That way we get the constant (we hope) inside it. Also, strip off any
3732 NOP_EXPR that converts between two record, union, array, or set types. */
3733 while ((TREE_CODE (exp) == NOP_EXPR
3734 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3735 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3736 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3737 exp = TREE_OPERAND (exp, 0);
3739 /* Allow a constructor with no elements for any data type.
3740 This means to fill the space with zeros. */
3741 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3743 assemble_zeros (size);
3744 return;
3747 switch (code)
3749 case CHAR_TYPE:
3750 case BOOLEAN_TYPE:
3751 case INTEGER_TYPE:
3752 case ENUMERAL_TYPE:
3753 case POINTER_TYPE:
3754 case REFERENCE_TYPE:
3755 /* ??? What about (int)((float)(int)&foo + 4) */
3756 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3757 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3758 exp = TREE_OPERAND (exp, 0);
3760 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3761 EXPAND_INITIALIZER),
3762 size, 0))
3763 error ("initializer for integer value is too complicated");
3764 size = 0;
3765 break;
3767 case REAL_TYPE:
3768 if (TREE_CODE (exp) != REAL_CST)
3769 error ("initializer for floating value is not a floating constant");
3771 assemble_real (TREE_REAL_CST (exp),
3772 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3773 size = 0;
3774 break;
3776 case COMPLEX_TYPE:
3777 output_constant (TREE_REALPART (exp), size / 2);
3778 output_constant (TREE_IMAGPART (exp), size / 2);
3779 size -= (size / 2) * 2;
3780 break;
3782 case ARRAY_TYPE:
3783 if (TREE_CODE (exp) == CONSTRUCTOR)
3785 output_constructor (exp, size);
3786 return;
3788 else if (TREE_CODE (exp) == STRING_CST)
3790 int excess = 0;
3792 if (size > TREE_STRING_LENGTH (exp))
3794 excess = size - TREE_STRING_LENGTH (exp);
3795 size = TREE_STRING_LENGTH (exp);
3798 assemble_string (TREE_STRING_POINTER (exp), size);
3799 size = excess;
3801 else
3802 abort ();
3803 break;
3805 case RECORD_TYPE:
3806 case UNION_TYPE:
3807 if (TREE_CODE (exp) == CONSTRUCTOR)
3808 output_constructor (exp, size);
3809 else
3810 abort ();
3811 return;
3813 case SET_TYPE:
3814 if (TREE_CODE (exp) == INTEGER_CST)
3815 assemble_integer (expand_expr (exp, NULL_RTX,
3816 VOIDmode, EXPAND_INITIALIZER),
3817 size, 1);
3818 else if (TREE_CODE (exp) == CONSTRUCTOR)
3820 unsigned char *buffer = (unsigned char *) alloca (size);
3821 if (get_set_constructor_bytes (exp, buffer, size))
3822 abort ();
3823 assemble_string ((char *) buffer, size);
3825 else
3826 error ("unknown set constructor type");
3827 return;
3829 default:
3830 break; /* ??? */
3833 if (size > 0)
3834 assemble_zeros (size);
3838 /* Subroutine of output_constant, used for CONSTRUCTORs
3839 (aggregate constants).
3840 Generate at least SIZE bytes, padding if necessary. */
3842 static void
3843 output_constructor (exp, size)
3844 tree exp;
3845 int size;
3847 register tree link, field = 0;
3848 HOST_WIDE_INT min_index = 0;
3849 /* Number of bytes output or skipped so far.
3850 In other words, current position within the constructor. */
3851 int total_bytes = 0;
3852 /* Non-zero means BYTE contains part of a byte, to be output. */
3853 int byte_buffer_in_use = 0;
3854 register int byte;
3856 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3857 abort ();
3859 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3860 field = TYPE_FIELDS (TREE_TYPE (exp));
3862 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3863 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3864 min_index
3865 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3867 /* As LINK goes through the elements of the constant,
3868 FIELD goes through the structure fields, if the constant is a structure.
3869 if the constant is a union, then we override this,
3870 by getting the field from the TREE_LIST element.
3871 But the constant could also be an array. Then FIELD is zero. */
3872 for (link = CONSTRUCTOR_ELTS (exp);
3873 link;
3874 link = TREE_CHAIN (link),
3875 field = field ? TREE_CHAIN (field) : 0)
3877 tree val = TREE_VALUE (link);
3878 tree index = 0;
3880 /* the element in a union constructor specifies the proper field. */
3882 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3883 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3885 /* if available, use the type given by link */
3886 if (TREE_PURPOSE (link) != 0)
3887 field = TREE_PURPOSE (link);
3890 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3891 index = TREE_PURPOSE (link);
3893 /* Eliminate the marker that makes a cast not be an lvalue. */
3894 if (val != 0)
3895 STRIP_NOPS (val);
3897 if (index && TREE_CODE (index) == RANGE_EXPR)
3899 register int fieldsize
3900 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3901 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
3902 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
3903 HOST_WIDE_INT index;
3904 for (index = lo_index; index <= hi_index; index++)
3906 /* Output the element's initial value. */
3907 if (val == 0)
3908 assemble_zeros (fieldsize);
3909 else
3910 output_constant (val, fieldsize);
3912 /* Count its size. */
3913 total_bytes += fieldsize;
3916 else if (field == 0 || !DECL_BIT_FIELD (field))
3918 /* An element that is not a bit-field. */
3920 register int fieldsize;
3921 /* Since this structure is static,
3922 we know the positions are constant. */
3923 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3924 / BITS_PER_UNIT)
3925 : 0);
3926 if (index != 0)
3927 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3928 / BITS_PER_UNIT
3929 * (TREE_INT_CST_LOW (index) - min_index));
3931 /* Output any buffered-up bit-fields preceding this element. */
3932 if (byte_buffer_in_use)
3934 ASM_OUTPUT_BYTE (asm_out_file, byte);
3935 total_bytes++;
3936 byte_buffer_in_use = 0;
3939 /* Advance to offset of this element.
3940 Note no alignment needed in an array, since that is guaranteed
3941 if each element has the proper size. */
3942 if ((field != 0 || index != 0) && bitpos != total_bytes)
3944 assemble_zeros (bitpos - total_bytes);
3945 total_bytes = bitpos;
3948 /* Determine size this element should occupy. */
3949 if (field)
3951 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3952 abort ();
3953 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3955 /* This avoids overflow trouble. */
3956 tree size_tree = size_binop (CEIL_DIV_EXPR,
3957 DECL_SIZE (field),
3958 size_int (BITS_PER_UNIT));
3959 fieldsize = TREE_INT_CST_LOW (size_tree);
3961 else
3963 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3964 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3967 else
3968 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3970 /* Output the element's initial value. */
3971 if (val == 0)
3972 assemble_zeros (fieldsize);
3973 else
3974 output_constant (val, fieldsize);
3976 /* Count its size. */
3977 total_bytes += fieldsize;
3979 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3980 error ("invalid initial value for member `%s'",
3981 IDENTIFIER_POINTER (DECL_NAME (field)));
3982 else
3984 /* Element that is a bit-field. */
3986 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3987 int end_offset
3988 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3990 if (val == 0)
3991 val = integer_zero_node;
3993 /* If this field does not start in this (or, next) byte,
3994 skip some bytes. */
3995 if (next_offset / BITS_PER_UNIT != total_bytes)
3997 /* Output remnant of any bit field in previous bytes. */
3998 if (byte_buffer_in_use)
4000 ASM_OUTPUT_BYTE (asm_out_file, byte);
4001 total_bytes++;
4002 byte_buffer_in_use = 0;
4005 /* If still not at proper byte, advance to there. */
4006 if (next_offset / BITS_PER_UNIT != total_bytes)
4008 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4009 total_bytes = next_offset / BITS_PER_UNIT;
4013 if (! byte_buffer_in_use)
4014 byte = 0;
4016 /* We must split the element into pieces that fall within
4017 separate bytes, and combine each byte with previous or
4018 following bit-fields. */
4020 /* next_offset is the offset n fbits from the beginning of
4021 the structure to the next bit of this element to be processed.
4022 end_offset is the offset of the first bit past the end of
4023 this element. */
4024 while (next_offset < end_offset)
4026 int this_time;
4027 int shift;
4028 HOST_WIDE_INT value;
4029 int next_byte = next_offset / BITS_PER_UNIT;
4030 int next_bit = next_offset % BITS_PER_UNIT;
4032 /* Advance from byte to byte
4033 within this element when necessary. */
4034 while (next_byte != total_bytes)
4036 ASM_OUTPUT_BYTE (asm_out_file, byte);
4037 total_bytes++;
4038 byte = 0;
4041 /* Number of bits we can process at once
4042 (all part of the same byte). */
4043 this_time = MIN (end_offset - next_offset,
4044 BITS_PER_UNIT - next_bit);
4045 if (BYTES_BIG_ENDIAN)
4047 /* On big-endian machine, take the most significant bits
4048 first (of the bits that are significant)
4049 and put them into bytes from the most significant end. */
4050 shift = end_offset - next_offset - this_time;
4051 /* Don't try to take a bunch of bits that cross
4052 the word boundary in the INTEGER_CST. */
4053 if (shift < HOST_BITS_PER_WIDE_INT
4054 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4056 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4057 shift = HOST_BITS_PER_WIDE_INT;
4060 /* Now get the bits from the appropriate constant word. */
4061 if (shift < HOST_BITS_PER_WIDE_INT)
4063 value = TREE_INT_CST_LOW (val);
4065 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4067 value = TREE_INT_CST_HIGH (val);
4068 shift -= HOST_BITS_PER_WIDE_INT;
4070 else
4071 abort ();
4072 byte |= (((value >> shift)
4073 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4074 << (BITS_PER_UNIT - this_time - next_bit));
4076 else
4078 /* On little-endian machines,
4079 take first the least significant bits of the value
4080 and pack them starting at the least significant
4081 bits of the bytes. */
4082 shift = (next_offset
4083 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4084 /* Don't try to take a bunch of bits that cross
4085 the word boundary in the INTEGER_CST. */
4086 if (shift < HOST_BITS_PER_WIDE_INT
4087 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4089 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4090 shift = HOST_BITS_PER_WIDE_INT;
4093 /* Now get the bits from the appropriate constant word. */
4094 if (shift < HOST_BITS_PER_WIDE_INT)
4095 value = TREE_INT_CST_LOW (val);
4096 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4098 value = TREE_INT_CST_HIGH (val);
4099 shift -= HOST_BITS_PER_WIDE_INT;
4101 else
4102 abort ();
4103 byte |= (((value >> shift)
4104 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4105 << next_bit);
4107 next_offset += this_time;
4108 byte_buffer_in_use = 1;
4112 if (byte_buffer_in_use)
4114 ASM_OUTPUT_BYTE (asm_out_file, byte);
4115 total_bytes++;
4117 if (total_bytes < size)
4118 assemble_zeros (size - total_bytes);
4121 /* Output asm to handle ``#pragma weak'' */
4123 void
4124 handle_pragma_weak (what, name, value)
4125 enum pragma_state what;
4126 char *name, *value;
4128 #ifdef HANDLE_PRAGMA_WEAK
4129 if (what == ps_name || what == ps_value)
4131 struct weak_syms *weak =
4132 (struct weak_syms *)permalloc (sizeof (struct weak_syms));
4133 weak->next = weak_decls;
4134 weak->name = permalloc (strlen (name) + 1);
4135 strcpy (weak->name, name);
4137 if (what != ps_value)
4138 weak->value = NULL_PTR;
4140 else
4142 weak->value = permalloc (strlen (value) + 1);
4143 strcpy (weak->value, value);
4146 weak_decls = weak;
4148 else if (! (what == ps_done || what == ps_start))
4149 warning ("malformed `#pragma weak'");
4150 #endif /* HANDLE_PRAGMA_WEAK */
4153 /* Declare DECL to be a weak symbol. */
4155 void
4156 declare_weak (decl)
4157 tree decl;
4159 if (! TREE_PUBLIC (decl))
4160 error_with_decl (decl, "weak declaration of `%s' must be public");
4161 else if (TREE_ASM_WRITTEN (decl))
4162 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4163 else if (SUPPORTS_WEAK)
4164 DECL_WEAK (decl) = 1;
4167 /* Emit any pending weak declarations. */
4169 void
4170 weak_finish ()
4172 #ifdef HANDLE_PRAGMA_WEAK
4173 if (HANDLE_PRAGMA_WEAK)
4175 struct weak_syms *t;
4176 for (t = weak_decls; t; t = t->next)
4178 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4179 if (t->value)
4180 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4183 #endif
4186 void
4187 assemble_alias (decl, target)
4188 tree decl, target;
4190 char *name;
4192 make_decl_rtl (decl, (char *) 0, 1);
4193 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4195 #ifdef ASM_OUTPUT_DEF
4196 /* Make name accessible from other files, if appropriate. */
4198 if (TREE_PUBLIC (decl))
4200 #ifdef ASM_WEAKEN_LABEL
4201 if (DECL_WEAK (decl))
4202 ASM_WEAKEN_LABEL (asm_out_file, name);
4203 else
4204 #endif
4205 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4208 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4209 TREE_ASM_WRITTEN (decl) = 1;
4210 #else
4211 #ifdef ASM_OUTPUT_WEAK_ALIAS
4212 if (! DECL_WEAK (decl))
4213 warning ("only weak aliases are supported in this configuration");
4215 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4216 TREE_ASM_WRITTEN (decl) = 1;
4217 #else
4218 warning ("alias definitions not supported in this configuration; ignored");
4219 #endif
4220 #endif
4223 /* This determines whether or not we support link-once semantics. */
4224 #ifndef SUPPORTS_ONE_ONLY
4225 #ifdef MAKE_DECL_ONE_ONLY
4226 #define SUPPORTS_ONE_ONLY 1
4227 #else
4228 #define SUPPORTS_ONE_ONLY 0
4229 #endif
4230 #endif
4232 /* Returns 1 if the target configuration supports defining public symbols
4233 so that one of them will be chosen at link time instead of generating a
4234 multiply-defined symbol error, whether through the use of weak symbols or
4235 a target-specific mechanism for having duplicates discarded. */
4238 supports_one_only ()
4240 if (SUPPORTS_ONE_ONLY)
4241 return 1;
4242 return SUPPORTS_WEAK;
4245 /* Set up DECL as a public symbol that can be defined in multiple
4246 translation units without generating a linker error. */
4248 void
4249 make_decl_one_only (decl)
4250 tree decl;
4252 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4253 abort ();
4255 TREE_PUBLIC (decl) = 1;
4257 if (TREE_CODE (decl) == VAR_DECL
4258 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4259 DECL_COMMON (decl) = 1;
4260 else if (SUPPORTS_ONE_ONLY)
4262 #ifdef MAKE_DECL_ONE_ONLY
4263 MAKE_DECL_ONE_ONLY (decl);
4264 #endif
4265 DECL_ONE_ONLY (decl) = 1;
4267 else if (SUPPORTS_WEAK)
4268 DECL_WEAK (decl) = 1;
4269 else
4270 abort ();