2001-01-23 Alexandre Petit-Bianco <apbianco@cygnus.com>
[official-gcc.git] / gcc / varasm.c
blob99c8da691d9692b001546c2321bf9154e2cb057b
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
30 #include "config.h"
31 #include "system.h"
32 #include <setjmp.h>
33 #include "rtl.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "expr.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "output.h"
42 #include "real.h"
43 #include "toplev.h"
44 #include "dbxout.h"
45 #include "sdbout.h"
46 #include "obstack.h"
47 #include "hashtab.h"
48 #include "c-pragma.h"
49 #include "ggc.h"
50 #include "tm_p.h"
52 #ifdef XCOFF_DEBUGGING_INFO
53 #include "xcoffout.h"
54 #endif
56 #ifndef TRAMPOLINE_ALIGNMENT
57 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
58 #endif
60 #ifndef ASM_STABS_OP
61 #define ASM_STABS_OP "\t.stabs\t"
62 #endif
64 /* Define the prefix to use when check_memory_usage_flag is enable. */
65 #ifdef NO_DOLLAR_IN_LABEL
66 #ifdef NO_DOT_IN_LABEL
67 #define CHKR_PREFIX "chkr_prefix_"
68 #else /* !NO_DOT_IN_LABEL */
69 #define CHKR_PREFIX "chkr."
70 #endif
71 #else /* !NO_DOLLAR_IN_LABEL */
72 #define CHKR_PREFIX "chkr$"
73 #endif
74 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
76 /* File in which assembler code is being written. */
78 extern FILE *asm_out_file;
80 /* The (assembler) name of the first globally-visible object output. */
81 const char *first_global_object_name;
82 const char *weak_global_object_name;
84 extern struct obstack permanent_obstack;
85 #define obstack_chunk_alloc xmalloc
87 struct addr_const;
88 struct constant_descriptor;
89 struct rtx_const;
90 struct pool_constant;
92 #define MAX_RTX_HASH_TABLE 61
94 struct varasm_status
96 /* Hash facility for making memory-constants
97 from constant rtl-expressions. It is used on RISC machines
98 where immediate integer arguments and constant addresses are restricted
99 so that such constants must be stored in memory.
101 This pool of constants is reinitialized for each function
102 so each function gets its own constants-pool that comes right before
103 it. */
104 struct constant_descriptor **x_const_rtx_hash_table;
105 struct pool_constant **x_const_rtx_sym_hash_table;
107 /* Pointers to first and last constant in pool. */
108 struct pool_constant *x_first_pool, *x_last_pool;
110 /* Current offset in constant pool (does not include any machine-specific
111 header). */
112 int x_pool_offset;
114 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
115 They are chained through the CONST_DOUBLE_CHAIN.
116 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
117 In that case, CONST_DOUBLE_MEM is either a MEM,
118 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
119 rtx x_const_double_chain;
122 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
123 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
124 #define first_pool (cfun->varasm->x_first_pool)
125 #define last_pool (cfun->varasm->x_last_pool)
126 #define pool_offset (cfun->varasm->x_pool_offset)
127 #define const_double_chain (cfun->varasm->x_const_double_chain)
129 /* Number for making the label on the next
130 constant that is stored in memory. */
132 int const_labelno;
134 /* Number for making the label on the next
135 static variable internal to a function. */
137 int var_labelno;
139 /* Carry information from ASM_DECLARE_OBJECT_NAME
140 to ASM_FINISH_DECLARE_OBJECT. */
142 int size_directive_output;
144 /* The last decl for which assemble_variable was called,
145 if it did ASM_DECLARE_OBJECT_NAME.
146 If the last call to assemble_variable didn't do that,
147 this holds 0. */
149 tree last_assemble_variable_decl;
151 static const char *strip_reg_name PARAMS ((const char *));
152 static int contains_pointers_p PARAMS ((tree));
153 static void decode_addr_const PARAMS ((tree, struct addr_const *));
154 static int const_hash PARAMS ((tree));
155 static int compare_constant PARAMS ((tree,
156 struct constant_descriptor *));
157 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
158 static struct constant_descriptor *record_constant PARAMS ((tree));
159 static void record_constant_1 PARAMS ((tree));
160 static tree copy_constant PARAMS ((tree));
161 static void output_constant_def_contents PARAMS ((tree, int, int));
162 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
163 struct rtx_const *));
164 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
165 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
166 struct constant_descriptor *));
167 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
168 rtx));
169 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
170 static void mark_constant_pool PARAMS ((void));
171 static void mark_constants PARAMS ((rtx));
172 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
173 static int output_addressed_constants PARAMS ((tree));
174 static void output_after_function_constants PARAMS ((void));
175 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
176 static void output_constructor PARAMS ((tree, int));
177 #ifdef ASM_WEAKEN_LABEL
178 static void remove_from_pending_weak_list PARAMS ((const char *));
179 #endif
180 #ifdef ASM_OUTPUT_BSS
181 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
182 #endif
183 #ifdef BSS_SECTION_ASM_OP
184 #ifdef ASM_OUTPUT_ALIGNED_BSS
185 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
186 int, int));
187 #endif
188 #endif /* BSS_SECTION_ASM_OP */
189 static void mark_pool_constant PARAMS ((struct pool_constant *));
190 static void mark_const_hash_entry PARAMS ((void *));
191 static int mark_const_str_htab_1 PARAMS ((void **, void *));
192 static void mark_const_str_htab PARAMS ((void *));
193 static hashval_t const_str_htab_hash PARAMS ((const void *x));
194 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
195 static void const_str_htab_del PARAMS ((void *));
196 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
198 static enum in_section { no_section, in_text, in_data, in_named
199 #ifdef BSS_SECTION_ASM_OP
200 , in_bss
201 #endif
202 #ifdef EH_FRAME_SECTION_ASM_OP
203 , in_eh_frame
204 #endif
205 #ifdef EXTRA_SECTIONS
206 , EXTRA_SECTIONS
207 #endif
208 } in_section = no_section;
210 /* Return a non-zero value if DECL has a section attribute. */
211 #ifndef IN_NAMED_SECTION
212 #define IN_NAMED_SECTION(DECL) \
213 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
214 && DECL_SECTION_NAME (DECL) != NULL_TREE)
215 #endif
217 /* Text of section name when in_section == in_named. */
218 static const char *in_named_name;
220 /* Define functions like text_section for any extra sections. */
221 #ifdef EXTRA_SECTION_FUNCTIONS
222 EXTRA_SECTION_FUNCTIONS
223 #endif
225 /* Tell assembler to switch to text section. */
227 void
228 text_section ()
230 if (in_section != in_text)
232 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
233 in_section = in_text;
237 /* Tell assembler to switch to data section. */
239 void
240 data_section ()
242 if (in_section != in_data)
244 if (flag_shared_data)
246 #ifdef SHARED_SECTION_ASM_OP
247 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
248 #else
249 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
250 #endif
252 else
253 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
255 in_section = in_data;
258 /* Tell assembler to ALWAYS switch to data section, in case
259 it's not sure where it it. */
261 void
262 force_data_section ()
264 in_section = no_section;
265 data_section ();
268 /* Tell assembler to switch to read-only data section. This is normally
269 the text section. */
271 void
272 readonly_data_section ()
274 #ifdef READONLY_DATA_SECTION
275 READONLY_DATA_SECTION (); /* Note this can call data_section. */
276 #else
277 text_section ();
278 #endif
281 /* Determine if we're in the text section. */
284 in_text_section ()
286 return in_section == in_text;
289 /* Determine if we're in the data section. */
292 in_data_section ()
294 return in_section == in_data;
297 /* Tell assembler to change to section NAME for DECL.
298 If DECL is NULL, just switch to section NAME.
299 If NAME is NULL, get the name from DECL.
300 If RELOC is 1, the initializer for DECL contains relocs. */
302 void
303 named_section (decl, name, reloc)
304 tree decl;
305 const char *name;
306 int reloc ATTRIBUTE_UNUSED;
308 if (decl != NULL_TREE && !DECL_P (decl))
309 abort ();
310 if (name == NULL)
311 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
313 if (in_section != in_named || strcmp (name, in_named_name))
315 #ifdef ASM_OUTPUT_SECTION_NAME
316 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
317 #else
318 /* Section attributes are not supported if this macro isn't provided -
319 some host formats don't support them at all. The front-end should
320 already have flagged this as an error. */
321 abort ();
322 #endif
324 in_named_name = ggc_strdup (name);
325 in_section = in_named;
329 #ifdef BSS_SECTION_ASM_OP
331 /* Tell the assembler to switch to the bss section. */
333 void
334 bss_section ()
336 if (in_section != in_bss)
338 #ifdef SHARED_BSS_SECTION_ASM_OP
339 if (flag_shared_data)
340 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
341 else
342 #endif
343 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
345 in_section = in_bss;
349 #ifdef ASM_OUTPUT_BSS
351 /* Utility function for ASM_OUTPUT_BSS for targets to use if
352 they don't support alignments in .bss.
353 ??? It is believed that this function will work in most cases so such
354 support is localized here. */
356 static void
357 asm_output_bss (file, decl, name, size, rounded)
358 FILE *file;
359 tree decl ATTRIBUTE_UNUSED;
360 const char *name;
361 int size ATTRIBUTE_UNUSED, rounded;
363 ASM_GLOBALIZE_LABEL (file, name);
364 bss_section ();
365 #ifdef ASM_DECLARE_OBJECT_NAME
366 last_assemble_variable_decl = decl;
367 ASM_DECLARE_OBJECT_NAME (file, name, decl);
368 #else
369 /* Standard thing is just output label for the object. */
370 ASM_OUTPUT_LABEL (file, name);
371 #endif /* ASM_DECLARE_OBJECT_NAME */
372 ASM_OUTPUT_SKIP (file, rounded);
375 #endif
377 #ifdef ASM_OUTPUT_ALIGNED_BSS
379 /* Utility function for targets to use in implementing
380 ASM_OUTPUT_ALIGNED_BSS.
381 ??? It is believed that this function will work in most cases so such
382 support is localized here. */
384 static void
385 asm_output_aligned_bss (file, decl, name, size, align)
386 FILE *file;
387 tree decl;
388 const char *name;
389 int size, align;
391 ASM_GLOBALIZE_LABEL (file, name);
392 bss_section ();
393 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
394 #ifdef ASM_DECLARE_OBJECT_NAME
395 last_assemble_variable_decl = decl;
396 ASM_DECLARE_OBJECT_NAME (file, name, decl);
397 #else
398 /* Standard thing is just output label for the object. */
399 ASM_OUTPUT_LABEL (file, name);
400 #endif /* ASM_DECLARE_OBJECT_NAME */
401 ASM_OUTPUT_SKIP (file, size ? size : 1);
404 #endif
406 #endif /* BSS_SECTION_ASM_OP */
408 #ifdef EH_FRAME_SECTION_ASM_OP
409 void
410 eh_frame_section ()
412 if (in_section != in_eh_frame)
414 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
415 in_section = in_eh_frame;
418 #endif
420 /* Switch to the section for function DECL.
422 If DECL is NULL_TREE, switch to the text section.
423 ??? It's not clear that we will ever be passed NULL_TREE, but it's
424 safer to handle it. */
426 void
427 function_section (decl)
428 tree decl;
430 if (decl != NULL_TREE
431 && DECL_SECTION_NAME (decl) != NULL_TREE)
432 named_section (decl, (char *) 0, 0);
433 else
434 text_section ();
437 /* Switch to section for variable DECL.
439 RELOC is the `reloc' argument to SELECT_SECTION. */
441 void
442 variable_section (decl, reloc)
443 tree decl;
444 int reloc;
446 if (IN_NAMED_SECTION (decl))
447 named_section (decl, NULL, reloc);
448 else
450 /* C++ can have const variables that get initialized from constructors,
451 and thus can not be in a readonly section. We prevent this by
452 verifying that the initial value is constant for objects put in a
453 readonly section.
455 error_mark_node is used by the C front end to indicate that the
456 initializer has not been seen yet. In this case, we assume that
457 the initializer must be constant.
459 C++ uses error_mark_node for variables that have complicated
460 initializers, but these variables go in BSS so we won't be called
461 for them. */
463 #ifdef SELECT_SECTION
464 SELECT_SECTION (decl, reloc);
465 #else
466 if (DECL_READONLY_SECTION (decl, reloc))
467 readonly_data_section ();
468 else
469 data_section ();
470 #endif
474 /* Tell assembler to switch to the section for the exception handling
475 table. */
477 void
478 exception_section ()
480 #if defined (EXCEPTION_SECTION)
481 EXCEPTION_SECTION ();
482 #else
483 #ifdef ASM_OUTPUT_SECTION_NAME
484 named_section (NULL_TREE, ".gcc_except_table", 0);
485 #else
486 if (flag_pic)
487 data_section ();
488 else
489 readonly_data_section ();
490 #endif
491 #endif
494 /* Given NAME, a putative register name, discard any customary prefixes. */
496 static const char *
497 strip_reg_name (name)
498 const char *name;
500 #ifdef REGISTER_PREFIX
501 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
502 name += strlen (REGISTER_PREFIX);
503 #endif
504 if (name[0] == '%' || name[0] == '#')
505 name++;
506 return name;
509 /* Decode an `asm' spec for a declaration as a register name.
510 Return the register number, or -1 if nothing specified,
511 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
512 or -3 if ASMSPEC is `cc' and is not recognized,
513 or -4 if ASMSPEC is `memory' and is not recognized.
514 Accept an exact spelling or a decimal number.
515 Prefixes such as % are optional. */
518 decode_reg_name (asmspec)
519 const char *asmspec;
521 if (asmspec != 0)
523 int i;
525 /* Get rid of confusing prefixes. */
526 asmspec = strip_reg_name (asmspec);
528 /* Allow a decimal number as a "register name". */
529 for (i = strlen (asmspec) - 1; i >= 0; i--)
530 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
531 break;
532 if (asmspec[0] != 0 && i < 0)
534 i = atoi (asmspec);
535 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
536 return i;
537 else
538 return -2;
541 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
542 if (reg_names[i][0]
543 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
544 return i;
546 #ifdef ADDITIONAL_REGISTER_NAMES
548 static struct { const char *name; int number; } table[]
549 = ADDITIONAL_REGISTER_NAMES;
551 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
552 if (! strcmp (asmspec, table[i].name))
553 return table[i].number;
555 #endif /* ADDITIONAL_REGISTER_NAMES */
557 if (!strcmp (asmspec, "memory"))
558 return -4;
560 if (!strcmp (asmspec, "cc"))
561 return -3;
563 return -2;
566 return -1;
569 /* Create the DECL_RTL for a declaration for a static or external variable
570 or static or external function.
571 ASMSPEC, if not 0, is the string which the user specified
572 as the assembler symbol name.
574 This is never called for PARM_DECL nodes. */
576 void
577 make_decl_rtl (decl, asmspec)
578 tree decl;
579 const char *asmspec;
581 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
582 const char *name = 0;
583 const char *new_name = 0;
584 int reg_number;
586 /* For a duplicate declaration, we can be called twice on the
587 same DECL node. Don't discard the RTL already made. */
588 if (DECL_RTL (decl) != 0)
590 /* If the old RTL had the wrong mode, fix the mode. */
591 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
593 rtx rtl = DECL_RTL (decl);
594 PUT_MODE (rtl, DECL_MODE (decl));
597 /* ??? Another way to do this would be to do what halfpic.c does
598 and maintain a hashed table of such critters. */
599 /* ??? Another way to do this would be to pass a flag bit to
600 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
601 /* Let the target reassign the RTL if it wants.
602 This is necessary, for example, when one machine specific
603 decl attribute overrides another. */
604 #ifdef REDO_SECTION_INFO_P
605 if (REDO_SECTION_INFO_P (decl))
606 ENCODE_SECTION_INFO (decl);
607 #endif
608 return;
611 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
613 reg_number = decode_reg_name (asmspec);
614 if (reg_number == -2)
616 /* ASMSPEC is given, and not the name of a register. Mark the
617 name with a star so assemble_name won't munge it. */
618 char *starred = alloca (strlen (asmspec) + 2);
619 starred[0] = '*';
620 strcpy (starred + 1, asmspec);
621 new_name = starred;
624 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
626 /* First detect errors in declaring global registers. */
627 if (reg_number == -1)
628 error_with_decl (decl, "register name not specified for `%s'");
629 else if (reg_number < 0)
630 error_with_decl (decl, "invalid register name for `%s'");
631 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
632 error_with_decl (decl,
633 "data type of `%s' isn't suitable for a register");
634 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
635 error_with_decl (decl,
636 "register specified for `%s' isn't suitable for data type");
637 /* Now handle properly declared static register variables. */
638 else
640 int nregs;
642 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
644 DECL_INITIAL (decl) = 0;
645 error ("global register variable has initial value");
647 if (TREE_THIS_VOLATILE (decl))
648 warning ("volatile register variables don't work as you might wish");
650 /* If the user specified one of the eliminables registers here,
651 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
652 confused with that register and be eliminated. Although this
653 usage is somewhat suspect, we nevertheless use the following
654 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
656 DECL_RTL (decl)
657 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
658 REGNO (DECL_RTL (decl)) = reg_number;
659 REG_USERVAR_P (DECL_RTL (decl)) = 1;
661 if (TREE_STATIC (decl))
663 /* Make this register global, so not usable for anything
664 else. */
665 #ifdef ASM_DECLARE_REGISTER_GLOBAL
666 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
667 #endif
668 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
669 while (nregs > 0)
670 globalize_reg (reg_number + --nregs);
673 /* As a register variable, it has no section. */
674 return;
678 /* Now handle ordinary static variables and functions (in memory).
679 Also handle vars declared register invalidly. */
681 if (reg_number >= 0 || reg_number == -3)
682 error_with_decl (decl,
683 "register name given for non-register variable `%s'");
685 /* Specifying a section attribute on a variable forces it into a
686 non-.bss section, and thus it cannot be common. */
687 if (TREE_CODE (decl) == VAR_DECL
688 && DECL_SECTION_NAME (decl) != NULL_TREE
689 && DECL_INITIAL (decl) == NULL_TREE
690 && DECL_COMMON (decl))
691 DECL_COMMON (decl) = 0;
693 /* Can't use just the variable's own name for a variable
694 whose scope is less than the whole file, unless it's a member
695 of a local class (which will already be unambiguous).
696 Concatenate a distinguishing number. */
697 if (!top_level && !TREE_PUBLIC (decl)
698 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
699 && asmspec == 0)
701 char *label;
702 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
703 var_labelno++;
704 new_name = label;
707 /* When -fprefix-function-name is used, the functions
708 names are prefixed. Only nested function names are not
709 prefixed. */
710 else if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
712 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
713 char *pname;
715 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
716 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
717 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
718 new_name = pname;
721 if (name != new_name)
723 DECL_ASSEMBLER_NAME (decl) = get_identifier (new_name);
724 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
727 /* If this variable is to be treated as volatile, show its
728 tree node has side effects. */
729 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
730 && TREE_PUBLIC (decl))
731 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
732 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
733 TREE_SIDE_EFFECTS (decl) = 1;
735 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
736 gen_rtx_SYMBOL_REF (Pmode, name));
737 if (TREE_CODE (decl) != FUNCTION_DECL)
738 set_mem_attributes (DECL_RTL (decl), decl, 1);
740 /* Optionally set flags or add text to the name to record information
741 such as that it is a function name.
742 If the name is changed, the macro ASM_OUTPUT_LABELREF
743 will have to know how to strip this information. */
744 #ifdef ENCODE_SECTION_INFO
745 ENCODE_SECTION_INFO (decl);
746 #endif
749 /* Make the rtl for variable VAR be volatile.
750 Use this only for static variables. */
752 void
753 make_var_volatile (var)
754 tree var;
756 if (GET_CODE (DECL_RTL (var)) != MEM)
757 abort ();
759 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
762 /* Output alignment directive to align for constant expression EXP. */
764 void
765 assemble_constant_align (exp)
766 tree exp;
768 int align;
770 /* Align the location counter as required by EXP's data type. */
771 align = TYPE_ALIGN (TREE_TYPE (exp));
772 #ifdef CONSTANT_ALIGNMENT
773 align = CONSTANT_ALIGNMENT (exp, align);
774 #endif
776 if (align > BITS_PER_UNIT)
777 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
780 /* Output a string of literal assembler code
781 for an `asm' keyword used between functions. */
783 void
784 assemble_asm (string)
785 tree string;
787 app_enable ();
789 if (TREE_CODE (string) == ADDR_EXPR)
790 string = TREE_OPERAND (string, 0);
792 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
795 #if 0 /* This should no longer be needed, because
796 flag_gnu_linker should be 0 on these systems,
797 which should prevent any output
798 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
799 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
800 #ifndef ASM_OUTPUT_CONSTRUCTOR
801 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
802 #endif
803 #ifndef ASM_OUTPUT_DESTRUCTOR
804 #define ASM_OUTPUT_DESTRUCTOR(file, name)
805 #endif
806 #endif
807 #endif /* 0 */
809 /* Record an element in the table of global destructors.
810 How this is done depends on what sort of assembler and linker
811 are in use.
813 NAME should be the name of a global function to be called
814 at exit time. This name is output using assemble_name. */
816 void
817 assemble_destructor (name)
818 const char *name;
820 #ifdef ASM_OUTPUT_DESTRUCTOR
821 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
822 #else
823 if (flag_gnu_linker)
825 /* Now tell GNU LD that this is part of the static destructor set. */
826 /* This code works for any machine provided you use GNU as/ld. */
827 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
828 assemble_name (asm_out_file, name);
829 fputc ('\n', asm_out_file);
831 #endif
834 /* Likewise for global constructors. */
836 void
837 assemble_constructor (name)
838 const char *name;
840 #ifdef ASM_OUTPUT_CONSTRUCTOR
841 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
842 #else
843 if (flag_gnu_linker)
845 /* Now tell GNU LD that this is part of the static constructor set. */
846 /* This code works for any machine provided you use GNU as/ld. */
847 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
848 assemble_name (asm_out_file, name);
849 fputc ('\n', asm_out_file);
851 #endif
854 /* Likewise for entries we want to record for garbage collection.
855 Garbage collection is still under development. */
857 void
858 assemble_gc_entry (name)
859 const char *name;
861 #ifdef ASM_OUTPUT_GC_ENTRY
862 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
863 #else
864 if (flag_gnu_linker)
866 /* Now tell GNU LD that this is part of the static constructor set. */
867 fprintf (asm_out_file, "%s\"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
868 assemble_name (asm_out_file, name);
869 fputc ('\n', asm_out_file);
871 #endif
874 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
875 a non-zero value if the constant pool should be output before the
876 start of the function, or a zero value if the pool should output
877 after the end of the function. The default is to put it before the
878 start. */
880 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
881 #define CONSTANT_POOL_BEFORE_FUNCTION 1
882 #endif
884 /* Output assembler code for the constant pool of a function and associated
885 with defining the name of the function. DECL describes the function.
886 NAME is the function's name. For the constant pool, we use the current
887 constant pool data. */
889 void
890 assemble_start_function (decl, fnname)
891 tree decl;
892 const char *fnname;
894 int align;
896 /* The following code does not need preprocessing in the assembler. */
898 app_disable ();
900 if (CONSTANT_POOL_BEFORE_FUNCTION)
901 output_constant_pool (fnname, decl);
903 #ifdef ASM_OUTPUT_SECTION_NAME
904 /* If the function is to be put in its own section and it's not in a section
905 already, indicate so. */
906 if ((flag_function_sections
907 && DECL_SECTION_NAME (decl) == NULL_TREE)
908 || UNIQUE_SECTION_P (decl))
909 UNIQUE_SECTION (decl, 0);
910 #endif
912 function_section (decl);
914 /* Tell assembler to move to target machine's alignment for functions. */
915 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
916 if (align > 0)
917 ASM_OUTPUT_ALIGN (asm_out_file, align);
919 /* Handle a user-specified function alignment.
920 Note that we still need to align to FUNCTION_BOUNDARY, as above,
921 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
922 if (align_functions_log > align)
924 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
925 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
926 align_functions_log, align_functions-1);
927 #else
928 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
929 #endif
932 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
933 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
934 #endif
936 #ifdef SDB_DEBUGGING_INFO
937 /* Output SDB definition of the function. */
938 if (write_symbols == SDB_DEBUG)
939 sdbout_mark_begin_function ();
940 #endif
942 #ifdef DBX_DEBUGGING_INFO
943 /* Output DBX definition of the function. */
944 if (write_symbols == DBX_DEBUG)
945 dbxout_begin_function (decl);
946 #endif
948 /* Make function name accessible from other files, if appropriate. */
950 if (TREE_PUBLIC (decl))
952 if (! first_global_object_name)
954 const char *p;
955 char *name;
957 STRIP_NAME_ENCODING (p, fnname);
958 name = permalloc (strlen (p) + 1);
959 strcpy (name, p);
961 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
962 first_global_object_name = name;
963 else
964 weak_global_object_name = name;
967 #ifdef ASM_WEAKEN_LABEL
968 if (DECL_WEAK (decl))
970 ASM_WEAKEN_LABEL (asm_out_file, fnname);
971 /* Remove this function from the pending weak list so that
972 we do not emit multiple .weak directives for it. */
973 remove_from_pending_weak_list
974 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
976 else
977 #endif
978 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
981 /* Do any machine/system dependent processing of the function name */
982 #ifdef ASM_DECLARE_FUNCTION_NAME
983 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
984 #else
985 /* Standard thing is just output label for the function. */
986 ASM_OUTPUT_LABEL (asm_out_file, fnname);
987 #endif /* ASM_DECLARE_FUNCTION_NAME */
990 /* Output assembler code associated with defining the size of the
991 function. DECL describes the function. NAME is the function's name. */
993 void
994 assemble_end_function (decl, fnname)
995 tree decl;
996 const char *fnname;
998 #ifdef ASM_DECLARE_FUNCTION_SIZE
999 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1000 #endif
1001 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1003 output_constant_pool (fnname, decl);
1004 function_section (decl); /* need to switch back */
1007 /* Output any constants which should appear after the function. */
1008 output_after_function_constants ();
1011 /* Assemble code to leave SIZE bytes of zeros. */
1013 void
1014 assemble_zeros (size)
1015 int size;
1017 /* Do no output if -fsyntax-only. */
1018 if (flag_syntax_only)
1019 return;
1021 #ifdef ASM_NO_SKIP_IN_TEXT
1022 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1023 so we must output 0s explicitly in the text section. */
1024 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1026 int i;
1028 for (i = 0; i < size - 20; i += 20)
1030 #ifdef ASM_BYTE_OP
1031 fprintf (asm_out_file,
1032 "%s0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
1033 #else
1034 fprintf (asm_out_file,
1035 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1036 #endif
1038 if (i < size)
1040 #ifdef ASM_BYTE_OP
1041 fprintf (asm_out_file, "%s0", ASM_BYTE_OP);
1042 #else
1043 fprintf (asm_out_file, "\tbyte 0");
1044 #endif
1045 i++;
1046 for (; i < size; i++)
1047 fprintf (asm_out_file, ",0");
1048 fprintf (asm_out_file, "\n");
1051 else
1052 #endif
1053 if (size > 0)
1054 ASM_OUTPUT_SKIP (asm_out_file, size);
1057 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1059 void
1060 assemble_align (align)
1061 int align;
1063 if (align > BITS_PER_UNIT)
1064 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1067 /* Assemble a string constant with the specified C string as contents. */
1069 void
1070 assemble_string (p, size)
1071 const char *p;
1072 int size;
1074 int pos = 0;
1075 int maximum = 2000;
1077 /* If the string is very long, split it up. */
1079 while (pos < size)
1081 int thissize = size - pos;
1082 if (thissize > maximum)
1083 thissize = maximum;
1085 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1087 pos += thissize;
1088 p += thissize;
1093 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1094 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1095 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1096 #else
1097 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1098 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1099 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1100 #else
1101 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1102 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1103 #endif
1104 #endif
1106 #if defined ASM_OUTPUT_ALIGNED_BSS
1107 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1108 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1109 #else
1110 #if defined ASM_OUTPUT_BSS
1111 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1112 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1113 #else
1114 #undef ASM_EMIT_BSS
1115 #endif
1116 #endif
1118 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1119 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1120 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1121 #else
1122 #if defined ASM_OUTPUT_ALIGNED_COMMON
1123 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1124 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1125 #else
1126 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1127 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1128 #endif
1129 #endif
1131 static void
1132 asm_emit_uninitialised (decl, name, size, rounded)
1133 tree decl;
1134 const char * name;
1135 int size ATTRIBUTE_UNUSED;
1136 int rounded ATTRIBUTE_UNUSED;
1138 enum
1140 asm_dest_common,
1141 asm_dest_bss,
1142 asm_dest_local
1144 destination = asm_dest_local;
1146 if (TREE_PUBLIC (decl))
1148 #if defined ASM_EMIT_BSS
1149 if (! DECL_COMMON (decl))
1150 destination = asm_dest_bss;
1151 else
1152 #endif
1153 destination = asm_dest_common;
1156 if (flag_shared_data)
1158 switch (destination)
1160 #ifdef ASM_OUTPUT_SHARED_BSS
1161 case asm_dest_bss:
1162 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1163 return;
1164 #endif
1165 #ifdef ASM_OUTPUT_SHARED_COMMON
1166 case asm_dest_common:
1167 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1168 return;
1169 #endif
1170 #ifdef ASM_OUTPUT_SHARED_LOCAL
1171 case asm_dest_local:
1172 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1173 return;
1174 #endif
1175 default:
1176 break;
1180 #ifdef ASM_OUTPUT_SECTION_NAME
1181 /* We already know that DECL_SECTION_NAME() == NULL. */
1182 if (flag_data_sections != 0 || UNIQUE_SECTION_P (decl))
1183 UNIQUE_SECTION (decl, 0);
1184 #endif
1186 switch (destination)
1188 #ifdef ASM_EMIT_BSS
1189 case asm_dest_bss:
1190 ASM_EMIT_BSS (decl, name, size, rounded);
1191 break;
1192 #endif
1193 case asm_dest_common:
1194 ASM_EMIT_COMMON (decl, name, size, rounded);
1195 break;
1196 case asm_dest_local:
1197 ASM_EMIT_LOCAL (decl, name, size, rounded);
1198 break;
1199 default:
1200 abort ();
1203 return;
1206 /* Assemble everything that is needed for a variable or function declaration.
1207 Not used for automatic variables, and not used for function definitions.
1208 Should not be called for variables of incomplete structure type.
1210 TOP_LEVEL is nonzero if this variable has file scope.
1211 AT_END is nonzero if this is the special handling, at end of compilation,
1212 to define things that have had only tentative definitions.
1213 DONT_OUTPUT_DATA if nonzero means don't actually output the
1214 initial value (that will be done by the caller). */
1216 void
1217 assemble_variable (decl, top_level, at_end, dont_output_data)
1218 tree decl;
1219 int top_level ATTRIBUTE_UNUSED;
1220 int at_end ATTRIBUTE_UNUSED;
1221 int dont_output_data;
1223 register const char *name;
1224 unsigned int align;
1225 int reloc = 0;
1226 enum in_section saved_in_section;
1228 last_assemble_variable_decl = 0;
1230 if (GET_CODE (DECL_RTL (decl)) == REG)
1232 /* Do output symbol info for global register variables, but do nothing
1233 else for them. */
1235 if (TREE_ASM_WRITTEN (decl))
1236 return;
1237 TREE_ASM_WRITTEN (decl) = 1;
1239 /* Do no output if -fsyntax-only. */
1240 if (flag_syntax_only)
1241 return;
1243 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1244 /* File-scope global variables are output here. */
1245 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1246 && top_level)
1247 dbxout_symbol (decl, 0);
1248 #endif
1249 #ifdef SDB_DEBUGGING_INFO
1250 if (write_symbols == SDB_DEBUG && top_level
1251 /* Leave initialized global vars for end of compilation;
1252 see comment in compile_file. */
1253 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1254 sdbout_symbol (decl, 0);
1255 #endif
1257 /* Don't output any DWARF debugging information for variables here.
1258 In the case of local variables, the information for them is output
1259 when we do our recursive traversal of the tree representation for
1260 the entire containing function. In the case of file-scope variables,
1261 we output information for all of them at the very end of compilation
1262 while we are doing our final traversal of the chain of file-scope
1263 declarations. */
1265 return;
1268 /* Normally no need to say anything here for external references,
1269 since assemble_external is called by the language-specific code
1270 when a declaration is first seen. */
1272 if (DECL_EXTERNAL (decl))
1273 return;
1275 /* Output no assembler code for a function declaration.
1276 Only definitions of functions output anything. */
1278 if (TREE_CODE (decl) == FUNCTION_DECL)
1279 return;
1281 /* If type was incomplete when the variable was declared,
1282 see if it is complete now. */
1284 if (DECL_SIZE (decl) == 0)
1285 layout_decl (decl, 0);
1287 /* Still incomplete => don't allocate it; treat the tentative defn
1288 (which is what it must have been) as an `extern' reference. */
1290 if (!dont_output_data && DECL_SIZE (decl) == 0)
1292 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1293 DECL_SOURCE_LINE (decl),
1294 "storage size of `%s' isn't known",
1295 IDENTIFIER_POINTER (DECL_NAME (decl)));
1296 TREE_ASM_WRITTEN (decl) = 1;
1297 return;
1300 /* The first declaration of a variable that comes through this function
1301 decides whether it is global (in C, has external linkage)
1302 or local (in C, has internal linkage). So do nothing more
1303 if this function has already run. */
1305 if (TREE_ASM_WRITTEN (decl))
1306 return;
1308 TREE_ASM_WRITTEN (decl) = 1;
1310 /* Do no output if -fsyntax-only. */
1311 if (flag_syntax_only)
1312 return;
1314 app_disable ();
1316 if (! dont_output_data
1317 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1319 error_with_decl (decl, "size of variable `%s' is too large");
1320 goto finish;
1323 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1324 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1325 && ! first_global_object_name
1326 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1327 || DECL_INITIAL (decl) == error_mark_node))
1328 && ! DECL_WEAK (decl)
1329 && ! DECL_ONE_ONLY (decl))
1331 const char *p;
1332 char *xname;
1334 STRIP_NAME_ENCODING (p, name);
1335 xname = permalloc (strlen (p) + 1);
1336 strcpy (xname, p);
1337 first_global_object_name = xname;
1340 /* Compute the alignment of this data. */
1342 align = DECL_ALIGN (decl);
1344 /* In the case for initialing an array whose length isn't specified,
1345 where we have not yet been able to do the layout,
1346 figure out the proper alignment now. */
1347 if (dont_output_data && DECL_SIZE (decl) == 0
1348 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1349 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1351 /* Some object file formats have a maximum alignment which they support.
1352 In particular, a.out format supports a maximum alignment of 4. */
1353 #ifndef MAX_OFILE_ALIGNMENT
1354 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1355 #endif
1356 if (align > MAX_OFILE_ALIGNMENT)
1358 warning_with_decl (decl,
1359 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1360 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1361 align = MAX_OFILE_ALIGNMENT;
1364 /* On some machines, it is good to increase alignment sometimes. */
1365 #ifdef DATA_ALIGNMENT
1366 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1367 #endif
1368 #ifdef CONSTANT_ALIGNMENT
1369 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1370 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1371 #endif
1373 /* Reset the alignment in case we have made it tighter, so we can benefit
1374 from it in get_pointer_alignment. */
1375 DECL_ALIGN (decl) = align;
1377 /* Handle uninitialized definitions. */
1379 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1380 /* If the target can't output uninitialized but not common global data
1381 in .bss, then we have to use .data. */
1382 #if ! defined ASM_EMIT_BSS
1383 && DECL_COMMON (decl)
1384 #endif
1385 && DECL_SECTION_NAME (decl) == NULL_TREE
1386 && ! dont_output_data)
1388 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1389 unsigned HOST_WIDE_INT rounded = size;
1391 /* Don't allocate zero bytes of common,
1392 since that means "undefined external" in the linker. */
1393 if (size == 0)
1394 rounded = 1;
1396 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1397 so that each uninitialized object starts on such a boundary. */
1398 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1399 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1400 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1402 /* Don't continue this line--convex cc version 4.1 would lose. */
1403 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1404 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1405 warning_with_decl
1406 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1407 #endif
1409 #ifdef DBX_DEBUGGING_INFO
1410 /* File-scope global variables are output here. */
1411 if (write_symbols == DBX_DEBUG && top_level)
1412 dbxout_symbol (decl, 0);
1413 #endif
1414 #ifdef SDB_DEBUGGING_INFO
1415 if (write_symbols == SDB_DEBUG && top_level
1416 /* Leave initialized global vars for end of compilation;
1417 see comment in compile_file. */
1418 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1419 sdbout_symbol (decl, 0);
1420 #endif
1422 /* Don't output any DWARF debugging information for variables here.
1423 In the case of local variables, the information for them is output
1424 when we do our recursive traversal of the tree representation for
1425 the entire containing function. In the case of file-scope variables,
1426 we output information for all of them at the very end of compilation
1427 while we are doing our final traversal of the chain of file-scope
1428 declarations. */
1430 #if 0 /* ??? We should either delete this or add a comment describing what
1431 it was intended to do and why we shouldn't delete it. */
1432 if (flag_shared_data)
1433 data_section ();
1434 #endif
1435 asm_emit_uninitialised (decl, name, size, rounded);
1437 goto finish;
1440 /* Handle initialized definitions.
1441 Also handle uninitialized global definitions if -fno-common and the
1442 target doesn't support ASM_OUTPUT_BSS. */
1444 /* First make the assembler name(s) global if appropriate. */
1445 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1447 #ifdef ASM_WEAKEN_LABEL
1448 if (DECL_WEAK (decl))
1450 ASM_WEAKEN_LABEL (asm_out_file, name);
1451 /* Remove this variable from the pending weak list so that
1452 we do not emit multiple .weak directives for it. */
1453 remove_from_pending_weak_list
1454 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1456 else
1457 #endif
1458 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1460 #if 0
1461 for (d = equivalents; d; d = TREE_CHAIN (d))
1463 tree e = TREE_VALUE (d);
1464 if (TREE_PUBLIC (e) && DECL_NAME (e))
1465 ASM_GLOBALIZE_LABEL (asm_out_file,
1466 XSTR (XEXP (DECL_RTL (e), 0), 0));
1468 #endif
1470 /* Output any data that we will need to use the address of. */
1471 if (DECL_INITIAL (decl) == error_mark_node)
1472 reloc = contains_pointers_p (TREE_TYPE (decl));
1473 else if (DECL_INITIAL (decl))
1474 reloc = output_addressed_constants (DECL_INITIAL (decl));
1476 #ifdef ASM_OUTPUT_SECTION_NAME
1477 if ((flag_data_sections != 0 && DECL_SECTION_NAME (decl) == NULL_TREE)
1478 || UNIQUE_SECTION_P (decl))
1479 UNIQUE_SECTION (decl, reloc);
1480 #endif
1482 /* Switch to the appropriate section. */
1483 variable_section (decl, reloc);
1485 /* dbxout.c needs to know this. */
1486 if (in_text_section ())
1487 DECL_IN_TEXT_SECTION (decl) = 1;
1489 /* Record current section so we can restore it if dbxout.c clobbers it. */
1490 saved_in_section = in_section;
1492 /* Output the dbx info now that we have chosen the section. */
1494 #ifdef DBX_DEBUGGING_INFO
1495 /* File-scope global variables are output here. */
1496 if (write_symbols == DBX_DEBUG && top_level)
1497 dbxout_symbol (decl, 0);
1498 #endif
1499 #ifdef SDB_DEBUGGING_INFO
1500 if (write_symbols == SDB_DEBUG && top_level
1501 /* Leave initialized global vars for end of compilation;
1502 see comment in compile_file. */
1503 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1504 sdbout_symbol (decl, 0);
1505 #endif
1507 /* Don't output any DWARF debugging information for variables here.
1508 In the case of local variables, the information for them is output
1509 when we do our recursive traversal of the tree representation for
1510 the entire containing function. In the case of file-scope variables,
1511 we output information for all of them at the very end of compilation
1512 while we are doing our final traversal of the chain of file-scope
1513 declarations. */
1515 /* If the debugging output changed sections, reselect the section
1516 that's supposed to be selected. */
1517 if (in_section != saved_in_section)
1518 variable_section (decl, reloc);
1520 /* Output the alignment of this data. */
1521 if (align > BITS_PER_UNIT)
1522 ASM_OUTPUT_ALIGN (asm_out_file,
1523 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1525 /* Do any machine/system dependent processing of the object. */
1526 #ifdef ASM_DECLARE_OBJECT_NAME
1527 last_assemble_variable_decl = decl;
1528 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1529 #else
1530 /* Standard thing is just output label for the object. */
1531 ASM_OUTPUT_LABEL (asm_out_file, name);
1532 #endif /* ASM_DECLARE_OBJECT_NAME */
1534 if (!dont_output_data)
1536 if (DECL_INITIAL (decl))
1537 /* Output the actual data. */
1538 output_constant (DECL_INITIAL (decl),
1539 tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1540 else
1541 /* Leave space for it. */
1542 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1545 finish:
1546 #ifdef XCOFF_DEBUGGING_INFO
1547 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1548 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1549 and `aa' hasn't been output yet, the assembler generates a stab entry with
1550 a value of zero, in addition to creating an unnecessary external entry
1551 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1553 /* File-scope global variables are output here. */
1554 if (write_symbols == XCOFF_DEBUG && top_level)
1556 saved_in_section = in_section;
1558 dbxout_symbol (decl, 0);
1560 if (in_section != saved_in_section)
1561 variable_section (decl, reloc);
1563 #else
1564 /* There must be a statement after a label. */
1566 #endif
1569 /* Return 1 if type TYPE contains any pointers. */
1571 static int
1572 contains_pointers_p (type)
1573 tree type;
1575 switch (TREE_CODE (type))
1577 case POINTER_TYPE:
1578 case REFERENCE_TYPE:
1579 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1580 so I'll play safe and return 1. */
1581 case OFFSET_TYPE:
1582 return 1;
1584 case RECORD_TYPE:
1585 case UNION_TYPE:
1586 case QUAL_UNION_TYPE:
1588 tree fields;
1589 /* For a type that has fields, see if the fields have pointers. */
1590 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1591 if (TREE_CODE (fields) == FIELD_DECL
1592 && contains_pointers_p (TREE_TYPE (fields)))
1593 return 1;
1594 return 0;
1597 case ARRAY_TYPE:
1598 /* An array type contains pointers if its element type does. */
1599 return contains_pointers_p (TREE_TYPE (type));
1601 default:
1602 return 0;
1606 /* Output something to declare an external symbol to the assembler.
1607 (Most assemblers don't need this, so we normally output nothing.)
1608 Do nothing if DECL is not external. */
1610 void
1611 assemble_external (decl)
1612 tree decl ATTRIBUTE_UNUSED;
1614 #ifdef ASM_OUTPUT_EXTERNAL
1615 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1617 rtx rtl = DECL_RTL (decl);
1619 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1620 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1622 /* Some systems do require some output. */
1623 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1624 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1627 #endif
1630 /* Similar, for calling a library function FUN. */
1632 void
1633 assemble_external_libcall (fun)
1634 rtx fun ATTRIBUTE_UNUSED;
1636 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1637 /* Declare library function name external when first used, if nec. */
1638 if (! SYMBOL_REF_USED (fun))
1640 SYMBOL_REF_USED (fun) = 1;
1641 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1643 #endif
1646 /* Declare the label NAME global. */
1648 void
1649 assemble_global (name)
1650 const char *name;
1652 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1655 /* Assemble a label named NAME. */
1657 void
1658 assemble_label (name)
1659 const char *name;
1661 ASM_OUTPUT_LABEL (asm_out_file, name);
1664 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1665 If NAME starts with a *, the rest of NAME is output verbatim.
1666 Otherwise NAME is transformed in an implementation-defined way
1667 (usually by the addition of an underscore).
1668 Many macros in the tm file are defined to call this function. */
1670 void
1671 assemble_name (file, name)
1672 FILE *file;
1673 const char *name;
1675 const char *real_name;
1676 tree id;
1678 STRIP_NAME_ENCODING (real_name, name);
1679 if (flag_prefix_function_name
1680 && ! memcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1681 real_name = real_name + CHKR_PREFIX_SIZE;
1683 id = maybe_get_identifier (real_name);
1684 if (id)
1685 TREE_SYMBOL_REFERENCED (id) = 1;
1687 if (name[0] == '*')
1688 fputs (&name[1], file);
1689 else
1690 ASM_OUTPUT_LABELREF (file, name);
1693 /* Allocate SIZE bytes writable static space with a gensym name
1694 and return an RTX to refer to its address. */
1697 assemble_static_space (size)
1698 int size;
1700 char name[12];
1701 const char *namestring;
1702 rtx x;
1704 #if 0
1705 if (flag_shared_data)
1706 data_section ();
1707 #endif
1709 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1710 ++const_labelno;
1711 namestring = ggc_strdup (name);
1713 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1715 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1716 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1717 BIGGEST_ALIGNMENT);
1718 #else
1719 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1720 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1721 #else
1723 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1724 so that each uninitialized object starts on such a boundary. */
1725 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1726 int rounded ATTRIBUTE_UNUSED
1727 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1728 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1729 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1730 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1732 #endif
1733 #endif
1734 return x;
1737 /* Assemble the static constant template for function entry trampolines.
1738 This is done at most once per compilation.
1739 Returns an RTX for the address of the template. */
1741 #ifdef TRAMPOLINE_TEMPLATE
1743 assemble_trampoline_template ()
1745 char label[256];
1746 const char *name;
1747 int align;
1749 /* By default, put trampoline templates in read-only data section. */
1751 #ifdef TRAMPOLINE_SECTION
1752 TRAMPOLINE_SECTION ();
1753 #else
1754 readonly_data_section ();
1755 #endif
1757 /* Write the assembler code to define one. */
1758 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1759 if (align > 0)
1760 ASM_OUTPUT_ALIGN (asm_out_file, align);
1762 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1763 TRAMPOLINE_TEMPLATE (asm_out_file);
1765 /* Record the rtl to refer to it. */
1766 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1767 name = ggc_strdup (label);
1768 return gen_rtx_SYMBOL_REF (Pmode, name);
1770 #endif
1772 /* Assemble the integer constant X into an object of SIZE bytes.
1773 X must be either a CONST_INT or CONST_DOUBLE.
1775 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1776 non-zero, abort if we can't output the constant. */
1779 assemble_integer (x, size, force)
1780 rtx x;
1781 int size;
1782 int force;
1784 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1785 ASM_OUTPUT... macros. */
1787 switch (size)
1789 #ifdef ASM_OUTPUT_CHAR
1790 case 1:
1791 ASM_OUTPUT_CHAR (asm_out_file, x);
1792 return 1;
1793 #endif
1795 #ifdef ASM_OUTPUT_SHORT
1796 case 2:
1797 ASM_OUTPUT_SHORT (asm_out_file, x);
1798 return 1;
1799 #endif
1801 #ifdef ASM_OUTPUT_INT
1802 case 4:
1803 ASM_OUTPUT_INT (asm_out_file, x);
1804 return 1;
1805 #endif
1807 #ifdef ASM_OUTPUT_DOUBLE_INT
1808 case 8:
1809 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1810 return 1;
1811 #endif
1813 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1814 case 16:
1815 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1816 return 1;
1817 #endif
1820 /* If we couldn't do it that way, there are two other possibilities: First,
1821 if the machine can output an explicit byte and this is a 1 byte constant,
1822 we can use ASM_OUTPUT_BYTE. */
1824 #ifdef ASM_OUTPUT_BYTE
1825 if (size == 1 && GET_CODE (x) == CONST_INT)
1827 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1828 return 1;
1830 #endif
1832 /* Finally, if SIZE is larger than a single word, try to output the constant
1833 one word at a time. */
1835 if (size > UNITS_PER_WORD)
1837 int i;
1838 enum machine_mode mode
1839 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1840 rtx word;
1842 for (i = 0; i < size / UNITS_PER_WORD; i++)
1844 word = operand_subword (x, i, 0, mode);
1846 if (word == 0)
1847 break;
1849 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1850 break;
1853 if (i == size / UNITS_PER_WORD)
1854 return 1;
1855 /* If we output at least one word and then could not finish,
1856 there is no valid way to continue. */
1857 if (i > 0)
1858 abort ();
1861 if (force)
1862 abort ();
1864 return 0;
1867 /* Assemble the floating-point constant D into an object of size MODE. */
1869 void
1870 assemble_real (d, mode)
1871 REAL_VALUE_TYPE d;
1872 enum machine_mode mode;
1874 jmp_buf output_constant_handler;
1876 if (setjmp (output_constant_handler))
1878 error ("floating point trap outputting a constant");
1879 #ifdef REAL_IS_NOT_DOUBLE
1880 memset ((char *) &d, 0, sizeof d);
1881 d = dconst0;
1882 #else
1883 d = 0;
1884 #endif
1887 set_float_handler (output_constant_handler);
1889 switch (mode)
1891 #ifdef ASM_OUTPUT_BYTE_FLOAT
1892 case QFmode:
1893 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1894 break;
1895 #endif
1896 #ifdef ASM_OUTPUT_SHORT_FLOAT
1897 case HFmode:
1898 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1899 break;
1900 #endif
1901 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1902 case TQFmode:
1903 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1904 break;
1905 #endif
1906 #ifdef ASM_OUTPUT_FLOAT
1907 case SFmode:
1908 ASM_OUTPUT_FLOAT (asm_out_file, d);
1909 break;
1910 #endif
1912 #ifdef ASM_OUTPUT_DOUBLE
1913 case DFmode:
1914 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1915 break;
1916 #endif
1918 #ifdef ASM_OUTPUT_LONG_DOUBLE
1919 case XFmode:
1920 case TFmode:
1921 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1922 break;
1923 #endif
1925 default:
1926 abort ();
1929 set_float_handler (NULL_PTR);
1932 /* Here we combine duplicate floating constants to make
1933 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1935 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1936 For an integer, I0 is the low-order word and I1 is the high-order word.
1937 For a real number, I0 is the word with the low address
1938 and I1 is the word with the high address. */
1941 immed_double_const (i0, i1, mode)
1942 HOST_WIDE_INT i0, i1;
1943 enum machine_mode mode;
1945 register rtx r;
1947 if (GET_MODE_CLASS (mode) == MODE_INT
1948 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1950 /* We clear out all bits that don't belong in MODE, unless they and our
1951 sign bit are all one. So we get either a reasonable negative value
1952 or a reasonable unsigned value for this mode. */
1953 int width = GET_MODE_BITSIZE (mode);
1954 if (width < HOST_BITS_PER_WIDE_INT
1955 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1956 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1957 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1958 else if (width == HOST_BITS_PER_WIDE_INT
1959 && ! (i1 == ~0 && i0 < 0))
1960 i1 = 0;
1961 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1962 /* We cannot represent this value as a constant. */
1963 abort ();
1965 /* If this would be an entire word for the target, but is not for
1966 the host, then sign-extend on the host so that the number will look
1967 the same way on the host that it would on the target.
1969 For example, when building a 64 bit alpha hosted 32 bit sparc
1970 targeted compiler, then we want the 32 bit unsigned value -1 to be
1971 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1972 The later confuses the sparc backend. */
1974 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1975 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1976 i0 |= ((HOST_WIDE_INT) (-1) << width);
1978 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1980 ??? Strictly speaking, this is wrong if we create a CONST_INT
1981 for a large unsigned constant with the size of MODE being
1982 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1983 wider mode. In that case we will mis-interpret it as a negative
1984 number.
1986 Unfortunately, the only alternative is to make a CONST_DOUBLE
1987 for any constant in any mode if it is an unsigned constant larger
1988 than the maximum signed integer in an int on the host. However,
1989 doing this will break everyone that always expects to see a CONST_INT
1990 for SImode and smaller.
1992 We have always been making CONST_INTs in this case, so nothing new
1993 is being broken. */
1995 if (width <= HOST_BITS_PER_WIDE_INT)
1996 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
1998 /* If this integer fits in one word, return a CONST_INT. */
1999 if ((i1 == 0 && i0 >= 0)
2000 || (i1 == ~0 && i0 < 0))
2001 return GEN_INT (i0);
2003 /* We use VOIDmode for integers. */
2004 mode = VOIDmode;
2007 /* Search the chain for an existing CONST_DOUBLE with the right value.
2008 If one is found, return it. */
2009 if (cfun != 0)
2010 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2011 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2012 && GET_MODE (r) == mode)
2013 return r;
2015 /* No; make a new one and add it to the chain. */
2016 r = gen_rtx_CONST_DOUBLE (mode, const0_rtx, i0, i1);
2018 /* Don't touch const_double_chain if not inside any function. */
2019 if (current_function_decl != 0)
2021 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2022 const_double_chain = r;
2025 return r;
2028 /* Return a CONST_DOUBLE for a specified `double' value
2029 and machine mode. */
2032 immed_real_const_1 (d, mode)
2033 REAL_VALUE_TYPE d;
2034 enum machine_mode mode;
2036 union real_extract u;
2037 register rtx r;
2039 /* Get the desired `double' value as a sequence of ints
2040 since that is how they are stored in a CONST_DOUBLE. */
2042 u.d = d;
2044 /* Detect special cases. But be careful we don't use a CONST_DOUBLE
2045 that's from a parent function since it may be in its constant pool. */
2046 if (REAL_VALUES_IDENTICAL (dconst0, d)
2047 && (cfun == 0 || decl_function_context (current_function_decl) == 0))
2048 return CONST0_RTX (mode);
2050 /* Check for NaN first, because some ports (specifically the i386) do not
2051 emit correct ieee-fp code by default, and thus will generate a core
2052 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2053 does a floating point comparison. */
2054 else if ((! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2055 && (cfun == 0
2056 || decl_function_context (current_function_decl) == 0))
2057 return CONST1_RTX (mode);
2059 if (sizeof u == sizeof (HOST_WIDE_INT))
2060 return immed_double_const (u.i[0], 0, mode);
2061 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2062 return immed_double_const (u.i[0], u.i[1], mode);
2064 /* The rest of this function handles the case where
2065 a float value requires more than 2 ints of space.
2066 It will be deleted as dead code on machines that don't need it. */
2068 /* Search the chain for an existing CONST_DOUBLE with the right value.
2069 If one is found, return it. */
2070 if (cfun != 0)
2071 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2072 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2073 && GET_MODE (r) == mode)
2074 return r;
2076 /* No; make a new one and add it to the chain.
2078 We may be called by an optimizer which may be discarding any memory
2079 allocated during its processing (such as combine and loop). However,
2080 we will be leaving this constant on the chain, so we cannot tolerate
2081 freed memory. */
2082 r = rtx_alloc (CONST_DOUBLE);
2083 PUT_MODE (r, mode);
2084 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2086 /* If we aren't inside a function, don't put r on the
2087 const_double_chain. */
2088 if (current_function_decl != 0)
2090 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2091 const_double_chain = r;
2093 else
2094 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2096 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2097 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2098 is only through force_const_mem. */
2100 CONST_DOUBLE_MEM (r) = const0_rtx;
2102 return r;
2105 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2106 which must be a REAL_CST tree node. */
2109 immed_real_const (exp)
2110 tree exp;
2112 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2115 /* At the end of a function, forget the memory-constants
2116 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2117 Also clear out real_constant_chain and clear out all the chain-pointers. */
2119 void
2120 clear_const_double_mem ()
2122 register rtx r, next;
2124 for (r = const_double_chain; r; r = next)
2126 next = CONST_DOUBLE_CHAIN (r);
2127 CONST_DOUBLE_CHAIN (r) = 0;
2128 CONST_DOUBLE_MEM (r) = cc0_rtx;
2130 const_double_chain = 0;
2133 /* Given an expression EXP with a constant value,
2134 reduce it to the sum of an assembler symbol and an integer.
2135 Store them both in the structure *VALUE.
2136 Abort if EXP does not reduce. */
2138 struct addr_const
2140 rtx base;
2141 HOST_WIDE_INT offset;
2144 static void
2145 decode_addr_const (exp, value)
2146 tree exp;
2147 struct addr_const *value;
2149 register tree target = TREE_OPERAND (exp, 0);
2150 register int offset = 0;
2151 register rtx x;
2153 while (1)
2155 if (TREE_CODE (target) == COMPONENT_REF
2156 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2159 offset += int_byte_position (TREE_OPERAND (target, 1));
2160 target = TREE_OPERAND (target, 0);
2162 else if (TREE_CODE (target) == ARRAY_REF)
2164 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2165 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2166 target = TREE_OPERAND (target, 0);
2168 else
2169 break;
2172 switch (TREE_CODE (target))
2174 case VAR_DECL:
2175 case FUNCTION_DECL:
2176 x = DECL_RTL (target);
2177 break;
2179 case LABEL_DECL:
2180 x = gen_rtx_MEM (FUNCTION_MODE,
2181 gen_rtx_LABEL_REF (VOIDmode,
2182 label_rtx (TREE_OPERAND (exp, 0))));
2183 break;
2185 case REAL_CST:
2186 case STRING_CST:
2187 case COMPLEX_CST:
2188 case CONSTRUCTOR:
2189 case INTEGER_CST:
2190 x = TREE_CST_RTL (target);
2191 break;
2193 default:
2194 abort ();
2197 if (GET_CODE (x) != MEM)
2198 abort ();
2199 x = XEXP (x, 0);
2201 value->base = x;
2202 value->offset = offset;
2205 struct rtx_const
2207 #ifdef ONLY_INT_FIELDS
2208 unsigned int kind : 16;
2209 unsigned int mode : 16;
2210 #else
2211 enum kind kind : 16;
2212 enum machine_mode mode : 16;
2213 #endif
2214 union {
2215 union real_extract du;
2216 struct addr_const addr;
2217 struct {HOST_WIDE_INT high, low;} di;
2218 } un;
2221 /* Uniquize all constants that appear in memory.
2222 Each constant in memory thus far output is recorded
2223 in `const_hash_table' with a `struct constant_descriptor'
2224 that contains a polish representation of the value of
2225 the constant.
2227 We cannot store the trees in the hash table
2228 because the trees may be temporary. */
2230 struct constant_descriptor
2232 struct constant_descriptor *next;
2233 const char *label;
2234 rtx rtl;
2235 /* Make sure the data is reasonably aligned. */
2236 union
2238 unsigned char contents[1];
2239 #ifdef HAVE_LONG_DOUBLE
2240 long double d;
2241 #else
2242 double d;
2243 #endif
2244 } u;
2247 #define HASHBITS 30
2248 #define MAX_HASH_TABLE 1009
2249 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2251 #define STRHASH(x) ((hashval_t)((long)(x) >> 3))
2253 struct deferred_string
2255 const char *label;
2256 tree exp;
2257 int labelno;
2260 static htab_t const_str_htab;
2262 /* Mark a const_hash_table descriptor for GC. */
2264 static void
2265 mark_const_hash_entry (ptr)
2266 void *ptr;
2268 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2270 while (desc)
2272 ggc_mark_rtx (desc->rtl);
2273 desc = desc->next;
2277 /* Mark the hash-table element X (which is really a pointer to an
2278 struct deferred_string *). */
2280 static int
2281 mark_const_str_htab_1 (x, data)
2282 void **x;
2283 void *data ATTRIBUTE_UNUSED;
2285 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2286 return 1;
2289 /* Mark a const_str_htab for GC. */
2291 static void
2292 mark_const_str_htab (htab)
2293 void *htab;
2295 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2298 /* Returns a hash code for X (which is a really a
2299 struct deferred_string *). */
2301 static hashval_t
2302 const_str_htab_hash (x)
2303 const void *x;
2305 return STRHASH (((const struct deferred_string *) x)->label);
2308 /* Returns non-zero if the value represented by X (which is really a
2309 struct deferred_string *) is the same as that given by Y
2310 (which is really a char *). */
2312 static int
2313 const_str_htab_eq (x, y)
2314 const void *x;
2315 const void *y;
2317 return (((const struct deferred_string *) x)->label == (const char *) y);
2320 /* Delete the hash table entry dfsp. */
2322 static void
2323 const_str_htab_del (dfsp)
2324 void *dfsp;
2326 free (dfsp);
2329 /* Compute a hash code for a constant expression. */
2331 static int
2332 const_hash (exp)
2333 tree exp;
2335 register const char *p;
2336 register int len, hi, i;
2337 register enum tree_code code = TREE_CODE (exp);
2339 /* Either set P and LEN to the address and len of something to hash and
2340 exit the switch or return a value. */
2342 switch (code)
2344 case INTEGER_CST:
2345 p = (char *) &TREE_INT_CST (exp);
2346 len = sizeof TREE_INT_CST (exp);
2347 break;
2349 case REAL_CST:
2350 p = (char *) &TREE_REAL_CST (exp);
2351 len = sizeof TREE_REAL_CST (exp);
2352 break;
2354 case STRING_CST:
2355 p = TREE_STRING_POINTER (exp);
2356 len = TREE_STRING_LENGTH (exp);
2357 break;
2359 case COMPLEX_CST:
2360 return (const_hash (TREE_REALPART (exp)) * 5
2361 + const_hash (TREE_IMAGPART (exp)));
2363 case CONSTRUCTOR:
2364 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2366 char *tmp;
2368 len = int_size_in_bytes (TREE_TYPE (exp));
2369 tmp = (char *) alloca (len);
2370 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2371 p = tmp;
2372 break;
2374 else
2376 register tree link;
2378 /* For record type, include the type in the hashing.
2379 We do not do so for array types
2380 because (1) the sizes of the elements are sufficient
2381 and (2) distinct array types can have the same constructor.
2382 Instead, we include the array size because the constructor could
2383 be shorter. */
2384 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2385 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2386 % MAX_HASH_TABLE;
2387 else
2388 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2389 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2391 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2392 if (TREE_VALUE (link))
2394 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2396 return hi;
2399 case ADDR_EXPR:
2401 struct addr_const value;
2403 decode_addr_const (exp, &value);
2404 if (GET_CODE (value.base) == SYMBOL_REF)
2406 /* Don't hash the address of the SYMBOL_REF;
2407 only use the offset and the symbol name. */
2408 hi = value.offset;
2409 p = XSTR (value.base, 0);
2410 for (i = 0; p[i] != 0; i++)
2411 hi = ((hi * 613) + (unsigned) (p[i]));
2413 else if (GET_CODE (value.base) == LABEL_REF)
2414 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2415 else
2416 abort();
2418 hi &= (1 << HASHBITS) - 1;
2419 hi %= MAX_HASH_TABLE;
2421 return hi;
2423 case PLUS_EXPR:
2424 case MINUS_EXPR:
2425 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2426 + const_hash (TREE_OPERAND (exp, 1)));
2428 case NOP_EXPR:
2429 case CONVERT_EXPR:
2430 case NON_LVALUE_EXPR:
2431 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2433 default:
2434 /* A language specific constant. Just hash the code. */
2435 return code % MAX_HASH_TABLE;
2438 /* Compute hashing function */
2439 hi = len;
2440 for (i = 0; i < len; i++)
2441 hi = ((hi * 613) + (unsigned) (p[i]));
2443 hi &= (1 << HASHBITS) - 1;
2444 hi %= MAX_HASH_TABLE;
2445 return hi;
2448 /* Compare a constant expression EXP with a constant-descriptor DESC.
2449 Return 1 if DESC describes a constant with the same value as EXP. */
2451 static int
2452 compare_constant (exp, desc)
2453 tree exp;
2454 struct constant_descriptor *desc;
2456 return 0 != compare_constant_1 (exp, desc->u.contents);
2459 /* Compare constant expression EXP with a substring P of a constant descriptor.
2460 If they match, return a pointer to the end of the substring matched.
2461 If they do not match, return 0.
2463 Since descriptors are written in polish prefix notation,
2464 this function can be used recursively to test one operand of EXP
2465 against a subdescriptor, and if it succeeds it returns the
2466 address of the subdescriptor for the next operand. */
2468 static const unsigned char *
2469 compare_constant_1 (exp, p)
2470 tree exp;
2471 const unsigned char *p;
2473 register const unsigned char *strp;
2474 register int len;
2475 register enum tree_code code = TREE_CODE (exp);
2477 if (code != (enum tree_code) *p++)
2478 return 0;
2480 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2481 switch, or return the result of the comparison. */
2483 switch (code)
2485 case INTEGER_CST:
2486 /* Integer constants are the same only if the same width of type. */
2487 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2488 return 0;
2490 strp = (unsigned char *) &TREE_INT_CST (exp);
2491 len = sizeof TREE_INT_CST (exp);
2492 break;
2494 case REAL_CST:
2495 /* Real constants are the same only if the same width of type. */
2496 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2497 return 0;
2499 strp = (unsigned char *) &TREE_REAL_CST (exp);
2500 len = sizeof TREE_REAL_CST (exp);
2501 break;
2503 case STRING_CST:
2504 if (flag_writable_strings)
2505 return 0;
2507 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2508 return 0;
2510 strp = (const unsigned char *)TREE_STRING_POINTER (exp);
2511 len = TREE_STRING_LENGTH (exp);
2512 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2513 sizeof TREE_STRING_LENGTH (exp)))
2514 return 0;
2516 p += sizeof TREE_STRING_LENGTH (exp);
2517 break;
2519 case COMPLEX_CST:
2520 p = compare_constant_1 (TREE_REALPART (exp), p);
2521 if (p == 0)
2522 return 0;
2524 return compare_constant_1 (TREE_IMAGPART (exp), p);
2526 case CONSTRUCTOR:
2527 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2529 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2530 unsigned char *tmp = (unsigned char *) alloca (len);
2532 get_set_constructor_bytes (exp, tmp, len);
2533 strp = (unsigned char *) tmp;
2534 if (memcmp ((char *) &xlen, p, sizeof xlen))
2535 return 0;
2537 p += sizeof xlen;
2538 break;
2540 else
2542 register tree link;
2543 int length = list_length (CONSTRUCTOR_ELTS (exp));
2544 tree type;
2545 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2546 int have_purpose = 0;
2548 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2549 if (TREE_PURPOSE (link))
2550 have_purpose = 1;
2552 if (memcmp ((char *) &length, p, sizeof length))
2553 return 0;
2555 p += sizeof length;
2557 /* For record constructors, insist that the types match.
2558 For arrays, just verify both constructors are for arrays.
2559 Then insist that either both or none have any TREE_PURPOSE
2560 values. */
2561 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2562 type = TREE_TYPE (exp);
2563 else
2564 type = 0;
2566 if (memcmp ((char *) &type, p, sizeof type))
2567 return 0;
2569 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2571 if (memcmp ((char *) &mode, p, sizeof mode))
2572 return 0;
2574 p += sizeof mode;
2577 p += sizeof type;
2579 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2580 return 0;
2582 p += sizeof have_purpose;
2584 /* For arrays, insist that the size in bytes match. */
2585 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2587 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2589 if (memcmp ((char *) &size, p, sizeof size))
2590 return 0;
2592 p += sizeof size;
2595 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2597 if (TREE_VALUE (link))
2599 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2600 return 0;
2602 else
2604 tree zero = 0;
2606 if (memcmp ((char *) &zero, p, sizeof zero))
2607 return 0;
2609 p += sizeof zero;
2612 if (TREE_PURPOSE (link)
2613 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2615 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2616 sizeof TREE_PURPOSE (link)))
2617 return 0;
2619 p += sizeof TREE_PURPOSE (link);
2621 else if (TREE_PURPOSE (link))
2623 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2624 return 0;
2626 else if (have_purpose)
2628 int zero = 0;
2630 if (memcmp ((char *) &zero, p, sizeof zero))
2631 return 0;
2633 p += sizeof zero;
2637 return p;
2640 case ADDR_EXPR:
2642 struct addr_const value;
2644 decode_addr_const (exp, &value);
2645 strp = (unsigned char *) &value.offset;
2646 len = sizeof value.offset;
2647 /* Compare the offset. */
2648 while (--len >= 0)
2649 if (*p++ != *strp++)
2650 return 0;
2652 /* Compare symbol name. */
2653 strp = (const unsigned char *) XSTR (value.base, 0);
2654 len = strlen ((const char *) strp) + 1;
2656 break;
2658 case PLUS_EXPR:
2659 case MINUS_EXPR:
2660 case RANGE_EXPR:
2661 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2662 if (p == 0)
2663 return 0;
2665 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2667 case NOP_EXPR:
2668 case CONVERT_EXPR:
2669 case NON_LVALUE_EXPR:
2670 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2672 default:
2673 if (lang_expand_constant)
2675 exp = (*lang_expand_constant) (exp);
2676 return compare_constant_1 (exp, p);
2678 return 0;
2681 /* Compare constant contents. */
2682 while (--len >= 0)
2683 if (*p++ != *strp++)
2684 return 0;
2686 return p;
2689 /* Construct a constant descriptor for the expression EXP.
2690 It is up to the caller to enter the descriptor in the hash table. */
2692 static struct constant_descriptor *
2693 record_constant (exp)
2694 tree exp;
2696 struct constant_descriptor *next = 0;
2697 char *label = 0;
2698 rtx rtl = 0;
2699 int pad;
2701 /* Make a struct constant_descriptor. The first three pointers will
2702 be filled in later. Here we just leave space for them. */
2704 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2705 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2706 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2708 /* Align the descriptor for the data payload. */
2709 pad = (offsetof (struct constant_descriptor, u)
2710 - offsetof(struct constant_descriptor, rtl)
2711 - sizeof(next->rtl));
2712 if (pad > 0)
2713 obstack_blank (&permanent_obstack, pad);
2715 record_constant_1 (exp);
2716 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2719 /* Add a description of constant expression EXP
2720 to the object growing in `permanent_obstack'.
2721 No need to return its address; the caller will get that
2722 from the obstack when the object is complete. */
2724 static void
2725 record_constant_1 (exp)
2726 tree exp;
2728 register const unsigned char *strp;
2729 register int len;
2730 register enum tree_code code = TREE_CODE (exp);
2732 obstack_1grow (&permanent_obstack, (unsigned int) code);
2734 switch (code)
2736 case INTEGER_CST:
2737 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2738 strp = (unsigned char *) &TREE_INT_CST (exp);
2739 len = sizeof TREE_INT_CST (exp);
2740 break;
2742 case REAL_CST:
2743 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2744 strp = (unsigned char *) &TREE_REAL_CST (exp);
2745 len = sizeof TREE_REAL_CST (exp);
2746 break;
2748 case STRING_CST:
2749 if (flag_writable_strings)
2750 return;
2752 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2753 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2754 len = TREE_STRING_LENGTH (exp);
2755 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2756 sizeof TREE_STRING_LENGTH (exp));
2757 break;
2759 case COMPLEX_CST:
2760 record_constant_1 (TREE_REALPART (exp));
2761 record_constant_1 (TREE_IMAGPART (exp));
2762 return;
2764 case CONSTRUCTOR:
2765 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2767 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2768 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2769 obstack_blank (&permanent_obstack, nbytes);
2770 get_set_constructor_bytes
2771 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2772 nbytes);
2773 return;
2775 else
2777 register tree link;
2778 int length = list_length (CONSTRUCTOR_ELTS (exp));
2779 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2780 tree type;
2781 int have_purpose = 0;
2783 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2784 if (TREE_PURPOSE (link))
2785 have_purpose = 1;
2787 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2789 /* For record constructors, insist that the types match.
2790 For arrays, just verify both constructors are for arrays
2791 of the same mode. Then insist that either both or none
2792 have any TREE_PURPOSE values. */
2793 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2794 type = TREE_TYPE (exp);
2795 else
2796 type = 0;
2798 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2799 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2800 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2802 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2803 sizeof have_purpose);
2805 /* For arrays, insist that the size in bytes match. */
2806 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2808 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2809 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2812 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2814 if (TREE_VALUE (link))
2815 record_constant_1 (TREE_VALUE (link));
2816 else
2818 tree zero = 0;
2820 obstack_grow (&permanent_obstack,
2821 (char *) &zero, sizeof zero);
2824 if (TREE_PURPOSE (link)
2825 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2826 obstack_grow (&permanent_obstack,
2827 (char *) &TREE_PURPOSE (link),
2828 sizeof TREE_PURPOSE (link));
2829 else if (TREE_PURPOSE (link))
2830 record_constant_1 (TREE_PURPOSE (link));
2831 else if (have_purpose)
2833 int zero = 0;
2835 obstack_grow (&permanent_obstack,
2836 (char *) &zero, sizeof zero);
2840 return;
2842 case ADDR_EXPR:
2844 struct addr_const value;
2846 decode_addr_const (exp, &value);
2847 /* Record the offset. */
2848 obstack_grow (&permanent_obstack,
2849 (char *) &value.offset, sizeof value.offset);
2851 switch (GET_CODE (value.base))
2853 case SYMBOL_REF:
2854 /* Record the symbol name. */
2855 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2856 strlen (XSTR (value.base, 0)) + 1);
2857 break;
2858 case LABEL_REF:
2859 /* Record the address of the CODE_LABEL. It may not have
2860 been emitted yet, so it's UID may be zero. But pointer
2861 identity is good enough. */
2862 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
2863 sizeof (rtx));
2864 break;
2865 default:
2866 abort ();
2869 return;
2871 case PLUS_EXPR:
2872 case MINUS_EXPR:
2873 case RANGE_EXPR:
2874 record_constant_1 (TREE_OPERAND (exp, 0));
2875 record_constant_1 (TREE_OPERAND (exp, 1));
2876 return;
2878 case NOP_EXPR:
2879 case CONVERT_EXPR:
2880 case NON_LVALUE_EXPR:
2881 record_constant_1 (TREE_OPERAND (exp, 0));
2882 return;
2884 default:
2885 if (lang_expand_constant)
2887 exp = (*lang_expand_constant) (exp);
2888 record_constant_1 (exp);
2890 return;
2893 /* Record constant contents. */
2894 obstack_grow (&permanent_obstack, strp, len);
2897 /* Record a list of constant expressions that were passed to
2898 output_constant_def but that could not be output right away. */
2900 struct deferred_constant
2902 struct deferred_constant *next;
2903 tree exp;
2904 int reloc;
2905 int labelno;
2908 static struct deferred_constant *deferred_constants;
2910 /* Another list of constants which should be output after the
2911 function. */
2912 static struct deferred_constant *after_function_constants;
2914 /* Nonzero means defer output of addressed subconstants
2915 (i.e., those for which output_constant_def is called.) */
2916 static int defer_addressed_constants_flag;
2918 /* Start deferring output of subconstants. */
2920 void
2921 defer_addressed_constants ()
2923 defer_addressed_constants_flag++;
2926 /* Stop deferring output of subconstants,
2927 and output now all those that have been deferred. */
2929 void
2930 output_deferred_addressed_constants ()
2932 struct deferred_constant *p, *next;
2934 defer_addressed_constants_flag--;
2936 if (defer_addressed_constants_flag > 0)
2937 return;
2939 for (p = deferred_constants; p; p = next)
2941 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2942 next = p->next;
2943 free (p);
2946 deferred_constants = 0;
2949 /* Output any constants which should appear after a function. */
2951 static void
2952 output_after_function_constants ()
2954 struct deferred_constant *p, *next;
2956 for (p = after_function_constants; p; p = next)
2958 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2959 next = p->next;
2960 free (p);
2963 after_function_constants = 0;
2966 /* Make a copy of the whole tree structure for a constant.
2967 This handles the same types of nodes that compare_constant
2968 and record_constant handle. */
2970 static tree
2971 copy_constant (exp)
2972 tree exp;
2974 switch (TREE_CODE (exp))
2976 case ADDR_EXPR:
2977 /* For ADDR_EXPR, we do not want to copy the decl whose address
2978 is requested. We do want to copy constants though. */
2979 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2980 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2981 copy_constant (TREE_OPERAND (exp, 0)));
2982 else
2983 return copy_node (exp);
2985 case INTEGER_CST:
2986 case REAL_CST:
2987 case STRING_CST:
2988 return copy_node (exp);
2990 case COMPLEX_CST:
2991 return build_complex (TREE_TYPE (exp),
2992 copy_constant (TREE_REALPART (exp)),
2993 copy_constant (TREE_IMAGPART (exp)));
2995 case PLUS_EXPR:
2996 case MINUS_EXPR:
2997 return build (TREE_CODE (exp), TREE_TYPE (exp),
2998 copy_constant (TREE_OPERAND (exp, 0)),
2999 copy_constant (TREE_OPERAND (exp, 1)));
3001 case NOP_EXPR:
3002 case CONVERT_EXPR:
3003 case NON_LVALUE_EXPR:
3004 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3005 copy_constant (TREE_OPERAND (exp, 0)));
3007 case CONSTRUCTOR:
3009 tree copy = copy_node (exp);
3010 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3011 tree tail;
3013 CONSTRUCTOR_ELTS (copy) = list;
3014 for (tail = list; tail; tail = TREE_CHAIN (tail))
3015 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3016 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3017 for (tail = list; tail; tail = TREE_CHAIN (tail))
3018 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3020 return copy;
3023 default:
3024 abort ();
3028 /* Return an rtx representing a reference to constant data in memory
3029 for the constant expression EXP.
3031 If assembler code for such a constant has already been output,
3032 return an rtx to refer to it.
3033 Otherwise, output such a constant in memory (or defer it for later)
3034 and generate an rtx for it.
3036 If DEFER is non-zero, the output of string constants can be deferred
3037 and output only if referenced in the function after all optimizations.
3039 The TREE_CST_RTL of EXP is set up to point to that rtx.
3040 The const_hash_table records which constants already have label strings. */
3043 output_constant_def (exp, defer)
3044 tree exp;
3045 int defer;
3047 register int hash;
3048 register struct constant_descriptor *desc;
3049 struct deferred_string **defstr;
3050 char label[256];
3051 int reloc;
3052 int found = 1;
3053 int after_function = 0;
3054 int labelno = -1;
3056 if (TREE_CST_RTL (exp))
3057 return TREE_CST_RTL (exp);
3059 /* Make sure any other constants whose addresses appear in EXP
3060 are assigned label numbers. */
3062 reloc = output_addressed_constants (exp);
3064 /* Compute hash code of EXP. Search the descriptors for that hash code
3065 to see if any of them describes EXP. If yes, the descriptor records
3066 the label number already assigned. */
3068 hash = const_hash (exp) % MAX_HASH_TABLE;
3070 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3071 if (compare_constant (exp, desc))
3072 break;
3074 if (desc == 0)
3076 /* No constant equal to EXP is known to have been output.
3077 Make a constant descriptor to enter EXP in the hash table.
3078 Assign the label number and record it in the descriptor for
3079 future calls to this function to find. */
3081 /* Create a string containing the label name, in LABEL. */
3082 labelno = const_labelno++;
3083 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3085 desc = record_constant (exp);
3086 desc->next = const_hash_table[hash];
3087 desc->label = ggc_strdup (label);
3088 const_hash_table[hash] = desc;
3090 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3091 desc->rtl
3092 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3093 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3095 set_mem_attributes (desc->rtl, exp, 1);
3097 found = 0;
3100 TREE_CST_RTL (exp) = desc->rtl;
3102 /* Optionally set flags or add text to the name to record information
3103 such as that it is a function name. If the name is changed, the macro
3104 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3105 #ifdef ENCODE_SECTION_INFO
3106 /* A previously-processed constant would already have section info
3107 encoded in it. */
3108 if (! found)
3110 ENCODE_SECTION_INFO (exp);
3111 desc->rtl = TREE_CST_RTL (exp);
3112 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3114 #endif
3116 #ifdef CONSTANT_AFTER_FUNCTION_P
3117 if (current_function_decl != 0
3118 && CONSTANT_AFTER_FUNCTION_P (exp))
3119 after_function = 1;
3120 #endif
3122 if (found
3123 && STRING_POOL_ADDRESS_P (XEXP (desc->rtl, 0))
3124 && (!defer || defer_addressed_constants_flag || after_function))
3126 defstr = (struct deferred_string **)
3127 htab_find_slot_with_hash (const_str_htab, desc->label,
3128 STRHASH (desc->label), NO_INSERT);
3129 if (defstr)
3131 /* If the string is currently deferred but we need to output it now,
3132 remove it from deferred string hash table. */
3133 found = 0;
3134 labelno = (*defstr)->labelno;
3135 STRING_POOL_ADDRESS_P (XEXP (desc->rtl, 0)) = 0;
3136 htab_clear_slot (const_str_htab, (void **) defstr);
3140 /* If this is the first time we've seen this particular constant,
3141 output it (or defer its output for later). */
3142 if (! found)
3144 if (defer_addressed_constants_flag || after_function)
3146 struct deferred_constant *p;
3147 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3149 p->exp = copy_constant (exp);
3150 p->reloc = reloc;
3151 p->labelno = labelno;
3152 if (after_function)
3154 p->next = after_function_constants;
3155 after_function_constants = p;
3157 else
3159 p->next = deferred_constants;
3160 deferred_constants = p;
3163 else
3165 /* Do no output if -fsyntax-only. */
3166 if (! flag_syntax_only)
3168 if (TREE_CODE (exp) != STRING_CST
3169 || !defer
3170 || flag_writable_strings
3171 || (defstr = (struct deferred_string **)
3172 htab_find_slot_with_hash (const_str_htab,
3173 desc->label,
3174 STRHASH (desc->label),
3175 INSERT)) == NULL)
3176 output_constant_def_contents (exp, reloc, labelno);
3177 else
3179 struct deferred_string *p;
3181 p = (struct deferred_string *)
3182 xmalloc (sizeof (struct deferred_string));
3184 p->exp = copy_constant (exp);
3185 p->label = desc->label;
3186 p->labelno = labelno;
3187 *defstr = p;
3188 STRING_POOL_ADDRESS_P (XEXP (desc->rtl, 0)) = 1;
3194 return TREE_CST_RTL (exp);
3197 /* Now output assembler code to define the label for EXP,
3198 and follow it with the data of EXP. */
3200 static void
3201 output_constant_def_contents (exp, reloc, labelno)
3202 tree exp;
3203 int reloc;
3204 int labelno;
3206 int align;
3208 if (IN_NAMED_SECTION (exp))
3209 named_section (exp, NULL, reloc);
3210 else
3212 /* First switch to text section, except for writable strings. */
3213 #ifdef SELECT_SECTION
3214 SELECT_SECTION (exp, reloc);
3215 #else
3216 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3217 || (flag_pic && reloc))
3218 data_section ();
3219 else
3220 readonly_data_section ();
3221 #endif
3224 /* Align the location counter as required by EXP's data type. */
3225 align = TYPE_ALIGN (TREE_TYPE (exp));
3226 #ifdef CONSTANT_ALIGNMENT
3227 align = CONSTANT_ALIGNMENT (exp, align);
3228 #endif
3230 if (align > BITS_PER_UNIT)
3231 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3233 /* Output the label itself. */
3234 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3236 /* Output the value of EXP. */
3237 output_constant (exp,
3238 (TREE_CODE (exp) == STRING_CST
3239 ? TREE_STRING_LENGTH (exp)
3240 : int_size_in_bytes (TREE_TYPE (exp))));
3244 /* Structure to represent sufficient information about a constant so that
3245 it can be output when the constant pool is output, so that function
3246 integration can be done, and to simplify handling on machines that reference
3247 constant pool as base+displacement. */
3249 struct pool_constant
3251 struct constant_descriptor *desc;
3252 struct pool_constant *next, *next_sym;
3253 const char *label;
3254 rtx constant;
3255 enum machine_mode mode;
3256 int labelno;
3257 int align;
3258 int offset;
3259 int mark;
3262 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3263 The argument is XSTR (... , 0) */
3265 #define SYMHASH(LABEL) \
3266 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3268 /* Initialize constant pool hashing for a new function. */
3270 void
3271 init_varasm_status (f)
3272 struct function *f;
3274 struct varasm_status *p;
3275 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3276 f->varasm = p;
3277 p->x_const_rtx_hash_table
3278 = ((struct constant_descriptor **)
3279 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3280 p->x_const_rtx_sym_hash_table
3281 = ((struct pool_constant **)
3282 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3284 p->x_first_pool = p->x_last_pool = 0;
3285 p->x_pool_offset = 0;
3286 p->x_const_double_chain = 0;
3289 /* Mark PC for GC. */
3291 static void
3292 mark_pool_constant (pc)
3293 struct pool_constant *pc;
3295 while (pc)
3297 ggc_mark (pc);
3298 ggc_mark_rtx (pc->constant);
3299 pc = pc->next;
3303 /* Mark P for GC. */
3305 void
3306 mark_varasm_status (p)
3307 struct varasm_status *p;
3309 if (p == NULL)
3310 return;
3312 mark_pool_constant (p->x_first_pool);
3313 ggc_mark_rtx (p->x_const_double_chain);
3316 /* Clear out all parts of the state in F that can safely be discarded
3317 after the function has been compiled, to let garbage collection
3318 reclaim the memory. */
3320 void
3321 free_varasm_status (f)
3322 struct function *f;
3324 struct varasm_status *p;
3325 int i;
3327 p = f->varasm;
3329 /* Clear out the hash tables. */
3330 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3332 struct constant_descriptor* cd;
3334 cd = p->x_const_rtx_hash_table[i];
3335 while (cd) {
3336 struct constant_descriptor* next = cd->next;
3337 free (cd);
3338 cd = next;
3342 free (p->x_const_rtx_hash_table);
3343 free (p->x_const_rtx_sym_hash_table);
3344 free (p);
3345 f->varasm = NULL;
3348 enum kind { RTX_DOUBLE, RTX_INT };
3350 /* Express an rtx for a constant integer (perhaps symbolic)
3351 as the sum of a symbol or label plus an explicit integer.
3352 They are stored into VALUE. */
3354 static void
3355 decode_rtx_const (mode, x, value)
3356 enum machine_mode mode;
3357 rtx x;
3358 struct rtx_const *value;
3360 /* Clear the whole structure, including any gaps. */
3361 memset (value, 0, sizeof (struct rtx_const));
3363 value->kind = RTX_INT; /* Most usual kind. */
3364 value->mode = mode;
3366 switch (GET_CODE (x))
3368 case CONST_DOUBLE:
3369 value->kind = RTX_DOUBLE;
3370 if (GET_MODE (x) != VOIDmode)
3372 value->mode = GET_MODE (x);
3373 memcpy ((char *) &value->un.du,
3374 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3376 else
3378 value->un.di.low = CONST_DOUBLE_LOW (x);
3379 value->un.di.high = CONST_DOUBLE_HIGH (x);
3381 break;
3383 case CONST_INT:
3384 value->un.addr.offset = INTVAL (x);
3385 break;
3387 case SYMBOL_REF:
3388 case LABEL_REF:
3389 case PC:
3390 value->un.addr.base = x;
3391 break;
3393 case CONST:
3394 x = XEXP (x, 0);
3395 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3397 value->un.addr.base = XEXP (x, 0);
3398 value->un.addr.offset = INTVAL (XEXP (x, 1));
3400 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3402 value->un.addr.base = XEXP (x, 0);
3403 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3405 else
3407 value->un.addr.base = x;
3408 value->un.addr.offset = 0;
3410 break;
3412 default:
3413 abort ();
3416 if (value->kind == RTX_INT && value->un.addr.base != 0)
3417 switch (GET_CODE (value->un.addr.base))
3419 case SYMBOL_REF:
3420 /* Use the string's address, not the SYMBOL_REF's address,
3421 for the sake of addresses of library routines. */
3422 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3423 break;
3425 case LABEL_REF:
3426 /* For a LABEL_REF, compare labels. */
3427 value->un.addr.base = XEXP (value->un.addr.base, 0);
3429 default:
3430 break;
3434 /* Given a MINUS expression, simplify it if both sides
3435 include the same symbol. */
3438 simplify_subtraction (x)
3439 rtx x;
3441 struct rtx_const val0, val1;
3443 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3444 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3446 if (val0.un.addr.base == val1.un.addr.base)
3447 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3448 return x;
3451 /* Compute a hash code for a constant RTL expression. */
3453 static int
3454 const_hash_rtx (mode, x)
3455 enum machine_mode mode;
3456 rtx x;
3458 register int hi;
3459 register size_t i;
3461 struct rtx_const value;
3462 decode_rtx_const (mode, x, &value);
3464 /* Compute hashing function */
3465 hi = 0;
3466 for (i = 0; i < sizeof value / sizeof (int); i++)
3467 hi += ((int *) &value)[i];
3469 hi &= (1 << HASHBITS) - 1;
3470 hi %= MAX_RTX_HASH_TABLE;
3471 return hi;
3474 /* Compare a constant rtl object X with a constant-descriptor DESC.
3475 Return 1 if DESC describes a constant with the same value as X. */
3477 static int
3478 compare_constant_rtx (mode, x, desc)
3479 enum machine_mode mode;
3480 rtx x;
3481 struct constant_descriptor *desc;
3483 register int *p = (int *) desc->u.contents;
3484 register int *strp;
3485 register int len;
3486 struct rtx_const value;
3488 decode_rtx_const (mode, x, &value);
3489 strp = (int *) &value;
3490 len = sizeof value / sizeof (int);
3492 /* Compare constant contents. */
3493 while (--len >= 0)
3494 if (*p++ != *strp++)
3495 return 0;
3497 return 1;
3500 /* Construct a constant descriptor for the rtl-expression X.
3501 It is up to the caller to enter the descriptor in the hash table. */
3503 static struct constant_descriptor *
3504 record_constant_rtx (mode, x)
3505 enum machine_mode mode;
3506 rtx x;
3508 struct constant_descriptor *ptr;
3510 ptr = ((struct constant_descriptor *)
3511 xcalloc (1, (offsetof (struct constant_descriptor, u)
3512 + sizeof (struct rtx_const))));
3513 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3515 return ptr;
3518 /* Given a constant rtx X, make (or find) a memory constant for its value
3519 and return a MEM rtx to refer to it in memory. */
3522 force_const_mem (mode, x)
3523 enum machine_mode mode;
3524 rtx x;
3526 register int hash;
3527 register struct constant_descriptor *desc;
3528 char label[256];
3529 const char *found = 0;
3530 rtx def;
3532 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3533 (this will always be true for floating CONST_DOUBLEs that have been
3534 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3535 use the previous copy. Otherwise, make a new one. Note that in
3536 the unlikely event that this same CONST_DOUBLE is used in two different
3537 modes in an alternating fashion, we will allocate a lot of different
3538 memory locations, but this should be extremely rare. */
3540 if (GET_CODE (x) == CONST_DOUBLE
3541 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3542 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3543 return CONST_DOUBLE_MEM (x);
3545 /* Compute hash code of X. Search the descriptors for that hash code
3546 to see if any of them describes X. If yes, the descriptor records
3547 the label number already assigned. */
3549 hash = const_hash_rtx (mode, x);
3551 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3552 if (compare_constant_rtx (mode, x, desc))
3554 found = desc->label;
3555 break;
3558 if (found == 0)
3560 register struct pool_constant *pool;
3561 int align;
3563 /* No constant equal to X is known to have been output.
3564 Make a constant descriptor to enter X in the hash table.
3565 Assign the label number and record it in the descriptor for
3566 future calls to this function to find. */
3568 desc = record_constant_rtx (mode, x);
3569 desc->next = const_rtx_hash_table[hash];
3570 const_rtx_hash_table[hash] = desc;
3572 /* Align the location counter as required by EXP's data type. */
3573 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3574 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3575 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3576 #ifdef CONSTANT_ALIGNMENT
3577 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3578 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3579 #endif
3581 pool_offset += align - 1;
3582 pool_offset &= ~ (align - 1);
3584 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3586 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3587 pool->desc = desc;
3588 pool->constant = x;
3589 pool->mode = mode;
3590 pool->labelno = const_labelno;
3591 pool->align = align;
3592 pool->offset = pool_offset;
3593 pool->mark = 1;
3594 pool->next = 0;
3596 if (last_pool == 0)
3597 first_pool = pool;
3598 else
3599 last_pool->next = pool;
3601 last_pool = pool;
3602 pool_offset += GET_MODE_SIZE (mode);
3604 /* Create a string containing the label name, in LABEL. */
3605 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3607 ++const_labelno;
3609 desc->label = found = ggc_strdup (label);
3611 /* Add label to symbol hash table. */
3612 hash = SYMHASH (found);
3613 pool->label = found;
3614 pool->next_sym = const_rtx_sym_hash_table[hash];
3615 const_rtx_sym_hash_table[hash] = pool;
3618 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3620 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3621 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3622 RTX_UNCHANGING_P (def) = 1;
3624 /* Mark the symbol_ref as belonging to this constants pool. */
3625 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3626 current_function_uses_const_pool = 1;
3628 if (GET_CODE (x) == CONST_DOUBLE)
3630 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3632 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3633 const_double_chain = x;
3635 CONST_DOUBLE_MEM (x) = def;
3638 return def;
3641 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3642 the corresponding pool_constant structure. */
3644 static struct pool_constant *
3645 find_pool_constant (f, addr)
3646 struct function *f;
3647 rtx addr;
3649 struct pool_constant *pool;
3650 const char *label = XSTR (addr, 0);
3652 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3653 pool = pool->next_sym)
3654 if (pool->label == label)
3655 return pool;
3657 abort ();
3660 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3663 get_pool_constant (addr)
3664 rtx addr;
3666 return (find_pool_constant (cfun, addr))->constant;
3669 /* Likewise, but for the constant pool of a specific function. */
3672 get_pool_constant_for_function (f, addr)
3673 struct function *f;
3674 rtx addr;
3676 return (find_pool_constant (f, addr))->constant;
3679 /* Similar, return the mode. */
3681 enum machine_mode
3682 get_pool_mode (addr)
3683 rtx addr;
3685 return (find_pool_constant (cfun, addr))->mode;
3688 enum machine_mode
3689 get_pool_mode_for_function (f, addr)
3690 struct function *f;
3691 rtx addr;
3693 return (find_pool_constant (f, addr))->mode;
3696 /* Similar, return the offset in the constant pool. */
3699 get_pool_offset (addr)
3700 rtx addr;
3702 return (find_pool_constant (cfun, addr))->offset;
3705 /* Return the size of the constant pool. */
3708 get_pool_size ()
3710 return pool_offset;
3713 /* Write all the constants in the constant pool. */
3715 void
3716 output_constant_pool (fnname, fndecl)
3717 const char *fnname ATTRIBUTE_UNUSED;
3718 tree fndecl ATTRIBUTE_UNUSED;
3720 struct pool_constant *pool;
3721 rtx x;
3722 union real_extract u;
3724 /* It is possible for gcc to call force_const_mem and then to later
3725 discard the instructions which refer to the constant. In such a
3726 case we do not need to output the constant. */
3727 mark_constant_pool ();
3729 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3730 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3731 #endif
3733 for (pool = first_pool; pool; pool = pool->next)
3735 rtx tmp;
3737 x = pool->constant;
3739 if (! pool->mark)
3740 continue;
3742 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3743 whose CODE_LABEL has been deleted. This can occur if a jump table
3744 is eliminated by optimization. If so, write a constant of zero
3745 instead. Note that this can also happen by turning the
3746 CODE_LABEL into a NOTE. */
3747 /* ??? This seems completely and utterly wrong. Certainly it's
3748 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3749 functioning even with INSN_DELETED_P and friends. */
3751 tmp = x;
3752 switch (GET_CODE (x))
3754 case CONST:
3755 if (GET_CODE (XEXP (x, 0)) != PLUS
3756 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3757 break;
3758 tmp = XEXP (XEXP (x, 0), 0);
3759 /* FALLTHRU */
3761 case LABEL_REF:
3762 tmp = XEXP (x, 0);
3763 if (INSN_DELETED_P (tmp)
3764 || (GET_CODE (tmp) == NOTE
3765 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3767 abort ();
3768 x = const0_rtx;
3770 break;
3772 default:
3773 break;
3776 /* First switch to correct section. */
3777 #ifdef SELECT_RTX_SECTION
3778 SELECT_RTX_SECTION (pool->mode, x);
3779 #else
3780 readonly_data_section ();
3781 #endif
3783 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3784 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3785 pool->align, pool->labelno, done);
3786 #endif
3788 if (pool->align > 1)
3789 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3791 /* Output the label. */
3792 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3794 /* Output the value of the constant itself. */
3795 switch (GET_MODE_CLASS (pool->mode))
3797 case MODE_FLOAT:
3798 if (GET_CODE (x) != CONST_DOUBLE)
3799 abort ();
3801 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
3802 assemble_real (u.d, pool->mode);
3803 break;
3805 case MODE_INT:
3806 case MODE_PARTIAL_INT:
3807 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3808 break;
3810 default:
3811 abort ();
3814 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3815 done: ;
3816 #endif
3820 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3821 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3822 #endif
3824 /* Done with this pool. */
3825 first_pool = last_pool = 0;
3828 /* Look through the instructions for this function, and mark all the
3829 entries in the constant pool which are actually being used.
3830 Emit used deferred strings. */
3832 static void
3833 mark_constant_pool ()
3835 register rtx insn;
3836 struct pool_constant *pool;
3838 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
3839 return;
3841 for (pool = first_pool; pool; pool = pool->next)
3842 pool->mark = 0;
3844 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3845 if (INSN_P (insn))
3846 mark_constants (PATTERN (insn));
3848 for (insn = current_function_epilogue_delay_list;
3849 insn;
3850 insn = XEXP (insn, 1))
3851 if (INSN_P (insn))
3852 mark_constants (PATTERN (insn));
3855 /* Look through appropriate parts of X, marking all entries in the
3856 constant pool which are actually being used. Entries that are only
3857 referenced by other constants are also marked as used. Emit
3858 deferred strings that are used. */
3860 static void
3861 mark_constants (x)
3862 rtx x;
3864 register int i;
3865 register const char *format_ptr;
3867 if (x == 0)
3868 return;
3870 if (GET_CODE (x) == SYMBOL_REF)
3872 mark_constant (&x, NULL);
3873 return;
3875 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3876 a MEM, but does not constitute a use of that MEM. */
3877 else if (GET_CODE (x) == CONST_DOUBLE)
3878 return;
3880 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3881 insns, not any notes that may be attached. We don't want to mark
3882 a constant just because it happens to appear in a REG_EQUIV note. */
3883 if (INSN_P (x))
3885 mark_constants (PATTERN (x));
3886 return;
3889 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3891 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3893 switch (*format_ptr++)
3895 case 'e':
3896 mark_constants (XEXP (x, i));
3897 break;
3899 case 'E':
3900 if (XVEC (x, i) != 0)
3902 register int j;
3904 for (j = 0; j < XVECLEN (x, i); j++)
3905 mark_constants (XVECEXP (x, i, j));
3907 break;
3909 case 'S':
3910 case 's':
3911 case '0':
3912 case 'i':
3913 case 'w':
3914 case 'n':
3915 case 'u':
3916 break;
3918 default:
3919 abort ();
3924 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3925 to as used. Emit referenced deferred strings. This function can
3926 be used with for_each_rtx () to mark all SYMBOL_REFs in an rtx. */
3928 static int
3929 mark_constant (current_rtx, data)
3930 rtx *current_rtx;
3931 void *data ATTRIBUTE_UNUSED;
3933 rtx x = *current_rtx;
3935 if (x == NULL_RTX)
3936 return 0;
3937 else if (GET_CODE(x) == CONST_DOUBLE)
3938 /* Never search inside a CONST_DOUBLE because CONST_DOUBLE_MEM may
3939 be a MEM but does not constitute a use of that MEM. */
3940 return -1;
3941 else if (GET_CODE (x) == SYMBOL_REF)
3943 if (CONSTANT_POOL_ADDRESS_P (x))
3945 struct pool_constant *pool = find_pool_constant (cfun, x);
3946 if (pool->mark == 0) {
3947 pool->mark = 1;
3948 for_each_rtx (&(pool->constant), &mark_constant, NULL);
3950 else
3951 return -1;
3953 else if (STRING_POOL_ADDRESS_P (x))
3955 struct deferred_string **defstr;
3957 defstr = (struct deferred_string **)
3958 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
3959 STRHASH (XSTR (x, 0)), NO_INSERT);
3960 if (defstr)
3962 struct deferred_string *p = *defstr;
3964 STRING_POOL_ADDRESS_P (x) = 0;
3965 output_constant_def_contents (p->exp, 0, p->labelno);
3966 htab_clear_slot (const_str_htab, (void **) defstr);
3970 return 0;
3973 /* Find all the constants whose addresses are referenced inside of EXP,
3974 and make sure assembler code with a label has been output for each one.
3975 Indicate whether an ADDR_EXPR has been encountered. */
3977 static int
3978 output_addressed_constants (exp)
3979 tree exp;
3981 int reloc = 0;
3983 /* Give the front-end a chance to convert VALUE to something that
3984 looks more like a constant to the back-end. */
3985 if (lang_expand_constant)
3986 exp = (*lang_expand_constant) (exp);
3988 switch (TREE_CODE (exp))
3990 case ADDR_EXPR:
3992 register tree constant = TREE_OPERAND (exp, 0);
3994 while (TREE_CODE (constant) == COMPONENT_REF)
3996 constant = TREE_OPERAND (constant, 0);
3999 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
4000 || TREE_CODE (constant) == CONSTRUCTOR)
4001 /* No need to do anything here
4002 for addresses of variables or functions. */
4003 output_constant_def (constant, 0);
4005 reloc = 1;
4006 break;
4008 case PLUS_EXPR:
4009 case MINUS_EXPR:
4010 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4011 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4012 break;
4014 case NOP_EXPR:
4015 case CONVERT_EXPR:
4016 case NON_LVALUE_EXPR:
4017 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4018 break;
4020 case CONSTRUCTOR:
4022 register tree link;
4023 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
4024 if (TREE_VALUE (link) != 0)
4025 reloc |= output_addressed_constants (TREE_VALUE (link));
4027 break;
4029 default:
4030 break;
4032 return reloc;
4035 /* Return nonzero if VALUE is a valid constant-valued expression
4036 for use in initializing a static variable; one that can be an
4037 element of a "constant" initializer.
4039 Return null_pointer_node if the value is absolute;
4040 if it is relocatable, return the variable that determines the relocation.
4041 We assume that VALUE has been folded as much as possible;
4042 therefore, we do not need to check for such things as
4043 arithmetic-combinations of integers. */
4045 tree
4046 initializer_constant_valid_p (value, endtype)
4047 tree value;
4048 tree endtype;
4050 /* Give the front-end a chance to convert VALUE to something that
4051 looks more like a constant to the back-end. */
4052 if (lang_expand_constant)
4053 value = (*lang_expand_constant) (value);
4055 switch (TREE_CODE (value))
4057 case CONSTRUCTOR:
4058 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4059 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4060 && TREE_CONSTANT (value)
4061 && CONSTRUCTOR_ELTS (value))
4062 return
4063 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4064 endtype);
4066 return TREE_STATIC (value) ? null_pointer_node : 0;
4068 case INTEGER_CST:
4069 case REAL_CST:
4070 case STRING_CST:
4071 case COMPLEX_CST:
4072 return null_pointer_node;
4074 case ADDR_EXPR:
4075 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4077 case NON_LVALUE_EXPR:
4078 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4080 case CONVERT_EXPR:
4081 case NOP_EXPR:
4082 /* Allow conversions between pointer types. */
4083 if (POINTER_TYPE_P (TREE_TYPE (value))
4084 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4085 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4087 /* Allow conversions between real types. */
4088 if (FLOAT_TYPE_P (TREE_TYPE (value))
4089 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4090 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4092 /* Allow length-preserving conversions between integer types. */
4093 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4094 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4095 && (TYPE_PRECISION (TREE_TYPE (value))
4096 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4097 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4099 /* Allow conversions between other integer types only if
4100 explicit value. */
4101 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4102 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4104 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4105 endtype);
4106 if (inner == null_pointer_node)
4107 return null_pointer_node;
4108 break;
4111 /* Allow (int) &foo provided int is as wide as a pointer. */
4112 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4113 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4114 && (TYPE_PRECISION (TREE_TYPE (value))
4115 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4116 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4117 endtype);
4119 /* Likewise conversions from int to pointers, but also allow
4120 conversions from 0. */
4121 if (POINTER_TYPE_P (TREE_TYPE (value))
4122 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4124 if (integer_zerop (TREE_OPERAND (value, 0)))
4125 return null_pointer_node;
4126 else if (TYPE_PRECISION (TREE_TYPE (value))
4127 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4128 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4129 endtype);
4132 /* Allow conversions to union types if the value inside is okay. */
4133 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4134 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4135 endtype);
4136 break;
4138 case PLUS_EXPR:
4139 if (! INTEGRAL_TYPE_P (endtype)
4140 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4142 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4143 endtype);
4144 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4145 endtype);
4146 /* If either term is absolute, use the other terms relocation. */
4147 if (valid0 == null_pointer_node)
4148 return valid1;
4149 if (valid1 == null_pointer_node)
4150 return valid0;
4152 break;
4154 case MINUS_EXPR:
4155 if (! INTEGRAL_TYPE_P (endtype)
4156 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4158 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4159 endtype);
4160 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4161 endtype);
4162 /* Win if second argument is absolute. */
4163 if (valid1 == null_pointer_node)
4164 return valid0;
4165 /* Win if both arguments have the same relocation.
4166 Then the value is absolute. */
4167 if (valid0 == valid1 && valid0 != 0)
4168 return null_pointer_node;
4170 /* Since GCC guarantees that string constants are unique in the
4171 generated code, a subtraction between two copies of the same
4172 constant string is absolute. */
4173 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4174 valid1 && TREE_CODE (valid1) == STRING_CST &&
4175 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4176 return null_pointer_node;
4179 /* Support differences between labels. */
4180 if (INTEGRAL_TYPE_P (endtype))
4182 tree op0, op1;
4183 op0 = TREE_OPERAND (value, 0);
4184 op1 = TREE_OPERAND (value, 1);
4185 STRIP_NOPS (op0);
4186 STRIP_NOPS (op1);
4188 if (TREE_CODE (op0) == ADDR_EXPR
4189 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4190 && TREE_CODE (op1) == ADDR_EXPR
4191 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4192 return null_pointer_node;
4194 break;
4196 default:
4197 break;
4200 return 0;
4203 /* Output assembler code for constant EXP to FILE, with no label.
4204 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4205 Assumes output_addressed_constants has been done on EXP already.
4207 Generate exactly SIZE bytes of assembler data, padding at the end
4208 with zeros if necessary. SIZE must always be specified.
4210 SIZE is important for structure constructors,
4211 since trailing members may have been omitted from the constructor.
4212 It is also important for initialization of arrays from string constants
4213 since the full length of the string constant might not be wanted.
4214 It is also needed for initialization of unions, where the initializer's
4215 type is just one member, and that may not be as long as the union.
4217 There a case in which we would fail to output exactly SIZE bytes:
4218 for a structure constructor that wants to produce more than SIZE bytes.
4219 But such constructors will never be generated for any possible input. */
4221 void
4222 output_constant (exp, size)
4223 register tree exp;
4224 register int size;
4226 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4228 /* Some front-ends use constants other than the standard
4229 language-indepdent varieties, but which may still be output
4230 directly. Give the front-end a chance to convert EXP to a
4231 language-independent representation. */
4232 if (lang_expand_constant)
4233 exp = (*lang_expand_constant) (exp);
4235 if (size == 0 || flag_syntax_only)
4236 return;
4238 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4239 That way we get the constant (we hope) inside it. Also, strip off any
4240 NOP_EXPR that converts between two record, union, array, or set types
4241 or a CONVERT_EXPR that converts to a union TYPE. */
4242 while ((TREE_CODE (exp) == NOP_EXPR
4243 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4244 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4245 || (TREE_CODE (exp) == CONVERT_EXPR
4246 && code == UNION_TYPE)
4247 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4249 exp = TREE_OPERAND (exp, 0);
4250 code = TREE_CODE (TREE_TYPE (exp));
4253 /* Allow a constructor with no elements for any data type.
4254 This means to fill the space with zeros. */
4255 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4257 assemble_zeros (size);
4258 return;
4261 switch (code)
4263 case CHAR_TYPE:
4264 case BOOLEAN_TYPE:
4265 case INTEGER_TYPE:
4266 case ENUMERAL_TYPE:
4267 case POINTER_TYPE:
4268 case REFERENCE_TYPE:
4269 /* ??? What about (int)((float)(int)&foo + 4) */
4270 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4271 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4272 exp = TREE_OPERAND (exp, 0);
4274 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4275 EXPAND_INITIALIZER),
4276 size, 0))
4277 error ("initializer for integer value is too complicated");
4278 size = 0;
4279 break;
4281 case REAL_TYPE:
4282 if (TREE_CODE (exp) != REAL_CST)
4283 error ("initializer for floating value is not a floating constant");
4285 assemble_real (TREE_REAL_CST (exp),
4286 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4287 size = 0;
4288 break;
4290 case COMPLEX_TYPE:
4291 output_constant (TREE_REALPART (exp), size / 2);
4292 output_constant (TREE_IMAGPART (exp), size / 2);
4293 size -= (size / 2) * 2;
4294 break;
4296 case ARRAY_TYPE:
4297 if (TREE_CODE (exp) == CONSTRUCTOR)
4299 output_constructor (exp, size);
4300 return;
4302 else if (TREE_CODE (exp) == STRING_CST)
4304 int excess = 0;
4306 if (size > TREE_STRING_LENGTH (exp))
4308 excess = size - TREE_STRING_LENGTH (exp);
4309 size = TREE_STRING_LENGTH (exp);
4312 assemble_string (TREE_STRING_POINTER (exp), size);
4313 size = excess;
4315 else
4316 abort ();
4317 break;
4319 case RECORD_TYPE:
4320 case UNION_TYPE:
4321 if (TREE_CODE (exp) == CONSTRUCTOR)
4322 output_constructor (exp, size);
4323 else
4324 abort ();
4325 return;
4327 case SET_TYPE:
4328 if (TREE_CODE (exp) == INTEGER_CST)
4329 assemble_integer (expand_expr (exp, NULL_RTX,
4330 VOIDmode, EXPAND_INITIALIZER),
4331 size, 1);
4332 else if (TREE_CODE (exp) == CONSTRUCTOR)
4334 unsigned char *buffer = (unsigned char *) alloca (size);
4335 if (get_set_constructor_bytes (exp, buffer, size))
4336 abort ();
4337 assemble_string ((char *) buffer, size);
4339 else
4340 error ("unknown set constructor type");
4341 return;
4343 default:
4344 break; /* ??? */
4347 if (size > 0)
4348 assemble_zeros (size);
4352 /* Subroutine of output_constructor, used for computing the size of
4353 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4354 type with an unspecified upper bound. */
4356 static unsigned HOST_WIDE_INT
4357 array_size_for_constructor (val)
4358 tree val;
4360 tree max_index, i;
4362 max_index = NULL_TREE;
4363 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4365 tree index = TREE_PURPOSE (i);
4367 if (TREE_CODE (index) == RANGE_EXPR)
4368 index = TREE_OPERAND (index, 1);
4369 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4370 max_index = index;
4373 if (max_index == NULL_TREE)
4374 return 0;
4376 /* Compute the total number of array elements. */
4377 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4378 convert (sizetype,
4379 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4380 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4382 /* Multiply by the array element unit size to find number of bytes. */
4383 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4385 return tree_low_cst (i, 1);
4388 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4389 Generate at least SIZE bytes, padding if necessary. */
4391 static void
4392 output_constructor (exp, size)
4393 tree exp;
4394 int size;
4396 tree type = TREE_TYPE (exp);
4397 register tree link, field = 0;
4398 tree min_index = 0;
4399 /* Number of bytes output or skipped so far.
4400 In other words, current position within the constructor. */
4401 HOST_WIDE_INT total_bytes = 0;
4402 /* Non-zero means BYTE contains part of a byte, to be output. */
4403 int byte_buffer_in_use = 0;
4404 register int byte = 0;
4406 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4407 abort ();
4409 if (TREE_CODE (type) == RECORD_TYPE)
4410 field = TYPE_FIELDS (type);
4412 if (TREE_CODE (type) == ARRAY_TYPE
4413 && TYPE_DOMAIN (type) != 0)
4414 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4416 /* As LINK goes through the elements of the constant,
4417 FIELD goes through the structure fields, if the constant is a structure.
4418 if the constant is a union, then we override this,
4419 by getting the field from the TREE_LIST element.
4420 But the constant could also be an array. Then FIELD is zero.
4422 There is always a maximum of one element in the chain LINK for unions
4423 (even if the initializer in a source program incorrectly contains
4424 more one). */
4425 for (link = CONSTRUCTOR_ELTS (exp);
4426 link;
4427 link = TREE_CHAIN (link),
4428 field = field ? TREE_CHAIN (field) : 0)
4430 tree val = TREE_VALUE (link);
4431 tree index = 0;
4433 /* The element in a union constructor specifies the proper field
4434 or index. */
4435 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4436 || TREE_CODE (type) == QUAL_UNION_TYPE)
4437 && TREE_PURPOSE (link) != 0)
4438 field = TREE_PURPOSE (link);
4440 else if (TREE_CODE (type) == ARRAY_TYPE)
4441 index = TREE_PURPOSE (link);
4443 /* Eliminate the marker that makes a cast not be an lvalue. */
4444 if (val != 0)
4445 STRIP_NOPS (val);
4447 if (index && TREE_CODE (index) == RANGE_EXPR)
4449 unsigned HOST_WIDE_INT fieldsize
4450 = int_size_in_bytes (TREE_TYPE (type));
4451 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4452 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4453 HOST_WIDE_INT index;
4455 for (index = lo_index; index <= hi_index; index++)
4457 /* Output the element's initial value. */
4458 if (val == 0)
4459 assemble_zeros (fieldsize);
4460 else
4461 output_constant (val, fieldsize);
4463 /* Count its size. */
4464 total_bytes += fieldsize;
4467 else if (field == 0 || !DECL_BIT_FIELD (field))
4469 /* An element that is not a bit-field. */
4471 unsigned HOST_WIDE_INT fieldsize;
4472 /* Since this structure is static,
4473 we know the positions are constant. */
4474 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4476 if (index != 0)
4477 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4478 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4480 /* Output any buffered-up bit-fields preceding this element. */
4481 if (byte_buffer_in_use)
4483 ASM_OUTPUT_BYTE (asm_out_file, byte);
4484 total_bytes++;
4485 byte_buffer_in_use = 0;
4488 /* Advance to offset of this element.
4489 Note no alignment needed in an array, since that is guaranteed
4490 if each element has the proper size. */
4491 if ((field != 0 || index != 0) && pos != total_bytes)
4493 assemble_zeros (pos - total_bytes);
4494 total_bytes = pos;
4497 else if (field != 0 && DECL_PACKED (field))
4498 /* Some assemblers automaticallly align a datum according to its
4499 size if no align directive is specified. The datum, however,
4500 may be declared with 'packed' attribute, so we have to disable
4501 such a feature. */
4502 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4504 /* Determine size this element should occupy. */
4505 if (field)
4507 fieldsize = 0;
4509 /* If this is an array with an unspecified upper bound,
4510 the initializer determines the size. */
4511 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4512 but we cannot do this until the deprecated support for
4513 initializing zero-length array members is removed. */
4514 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4515 && TYPE_DOMAIN (TREE_TYPE (field))
4516 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4518 fieldsize = array_size_for_constructor (val);
4519 /* Given a non-empty initialization, this field had
4520 better be last. */
4521 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4522 abort ();
4524 else if (DECL_SIZE_UNIT (field))
4526 /* ??? This can't be right. If the decl size overflows
4527 a host integer we will silently emit no data. */
4528 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4529 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4532 else
4533 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4535 /* Output the element's initial value. */
4536 if (val == 0)
4537 assemble_zeros (fieldsize);
4538 else
4539 output_constant (val, fieldsize);
4541 /* Count its size. */
4542 total_bytes += fieldsize;
4544 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4545 error ("invalid initial value for member `%s'",
4546 IDENTIFIER_POINTER (DECL_NAME (field)));
4547 else
4549 /* Element that is a bit-field. */
4551 HOST_WIDE_INT next_offset = int_bit_position (field);
4552 HOST_WIDE_INT end_offset
4553 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4555 if (val == 0)
4556 val = integer_zero_node;
4558 /* If this field does not start in this (or, next) byte,
4559 skip some bytes. */
4560 if (next_offset / BITS_PER_UNIT != total_bytes)
4562 /* Output remnant of any bit field in previous bytes. */
4563 if (byte_buffer_in_use)
4565 ASM_OUTPUT_BYTE (asm_out_file, byte);
4566 total_bytes++;
4567 byte_buffer_in_use = 0;
4570 /* If still not at proper byte, advance to there. */
4571 if (next_offset / BITS_PER_UNIT != total_bytes)
4573 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4574 total_bytes = next_offset / BITS_PER_UNIT;
4578 if (! byte_buffer_in_use)
4579 byte = 0;
4581 /* We must split the element into pieces that fall within
4582 separate bytes, and combine each byte with previous or
4583 following bit-fields. */
4585 /* next_offset is the offset n fbits from the beginning of
4586 the structure to the next bit of this element to be processed.
4587 end_offset is the offset of the first bit past the end of
4588 this element. */
4589 while (next_offset < end_offset)
4591 int this_time;
4592 int shift;
4593 HOST_WIDE_INT value;
4594 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4595 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4597 /* Advance from byte to byte
4598 within this element when necessary. */
4599 while (next_byte != total_bytes)
4601 ASM_OUTPUT_BYTE (asm_out_file, byte);
4602 total_bytes++;
4603 byte = 0;
4606 /* Number of bits we can process at once
4607 (all part of the same byte). */
4608 this_time = MIN (end_offset - next_offset,
4609 BITS_PER_UNIT - next_bit);
4610 if (BYTES_BIG_ENDIAN)
4612 /* On big-endian machine, take the most significant bits
4613 first (of the bits that are significant)
4614 and put them into bytes from the most significant end. */
4615 shift = end_offset - next_offset - this_time;
4617 /* Don't try to take a bunch of bits that cross
4618 the word boundary in the INTEGER_CST. We can
4619 only select bits from the LOW or HIGH part
4620 not from both. */
4621 if (shift < HOST_BITS_PER_WIDE_INT
4622 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4624 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4625 shift = HOST_BITS_PER_WIDE_INT;
4628 /* Now get the bits from the appropriate constant word. */
4629 if (shift < HOST_BITS_PER_WIDE_INT)
4630 value = TREE_INT_CST_LOW (val);
4631 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4633 value = TREE_INT_CST_HIGH (val);
4634 shift -= HOST_BITS_PER_WIDE_INT;
4636 else
4637 abort ();
4639 /* Get the result. This works only when:
4640 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4641 byte |= (((value >> shift)
4642 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4643 << (BITS_PER_UNIT - this_time - next_bit));
4645 else
4647 /* On little-endian machines,
4648 take first the least significant bits of the value
4649 and pack them starting at the least significant
4650 bits of the bytes. */
4651 shift = next_offset - int_bit_position (field);
4653 /* Don't try to take a bunch of bits that cross
4654 the word boundary in the INTEGER_CST. We can
4655 only select bits from the LOW or HIGH part
4656 not from both. */
4657 if (shift < HOST_BITS_PER_WIDE_INT
4658 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4659 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4661 /* Now get the bits from the appropriate constant word. */
4662 if (shift < HOST_BITS_PER_WIDE_INT)
4663 value = TREE_INT_CST_LOW (val);
4664 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4666 value = TREE_INT_CST_HIGH (val);
4667 shift -= HOST_BITS_PER_WIDE_INT;
4669 else
4670 abort ();
4672 /* Get the result. This works only when:
4673 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4674 byte |= (((value >> shift)
4675 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4676 << next_bit);
4679 next_offset += this_time;
4680 byte_buffer_in_use = 1;
4685 if (byte_buffer_in_use)
4687 ASM_OUTPUT_BYTE (asm_out_file, byte);
4688 total_bytes++;
4691 if (total_bytes < size)
4692 assemble_zeros (size - total_bytes);
4695 #ifdef HANDLE_PRAGMA_WEAK
4696 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4697 associatd with NAME. */
4700 add_weak (name, value)
4701 const char *name;
4702 const char *value;
4704 struct weak_syms *weak;
4706 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4708 if (weak == NULL)
4709 return 0;
4711 weak->next = weak_decls;
4712 weak->name = name;
4713 weak->value = value;
4714 weak_decls = weak;
4716 return 1;
4718 #endif /* HANDLE_PRAGMA_WEAK */
4720 /* Declare DECL to be a weak symbol. */
4722 void
4723 declare_weak (decl)
4724 tree decl;
4726 if (! TREE_PUBLIC (decl))
4727 error_with_decl (decl, "weak declaration of `%s' must be public");
4728 else if (TREE_ASM_WRITTEN (decl))
4729 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4730 else if (SUPPORTS_WEAK)
4731 DECL_WEAK (decl) = 1;
4732 #ifdef HANDLE_PRAGMA_WEAK
4733 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4734 #endif
4737 /* Emit any pending weak declarations. */
4739 #ifdef HANDLE_PRAGMA_WEAK
4740 struct weak_syms * weak_decls;
4741 #endif
4743 void
4744 weak_finish ()
4746 #ifdef HANDLE_PRAGMA_WEAK
4747 if (HANDLE_PRAGMA_WEAK)
4749 struct weak_syms *t;
4750 for (t = weak_decls; t; t = t->next)
4752 if (t->name)
4754 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4755 if (t->value)
4756 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4760 #endif
4763 /* Remove NAME from the pending list of weak symbols. This prevents
4764 the compiler from emitting multiple .weak directives which confuses
4765 some assemblers. */
4766 #ifdef ASM_WEAKEN_LABEL
4767 static void
4768 remove_from_pending_weak_list (name)
4769 const char *name ATTRIBUTE_UNUSED;
4771 #ifdef HANDLE_PRAGMA_WEAK
4772 if (HANDLE_PRAGMA_WEAK)
4774 struct weak_syms *t;
4775 for (t = weak_decls; t; t = t->next)
4777 if (t->name && strcmp (name, t->name) == 0)
4778 t->name = NULL;
4781 #endif
4783 #endif
4785 void
4786 assemble_alias (decl, target)
4787 tree decl, target ATTRIBUTE_UNUSED;
4789 const char *name;
4791 make_decl_rtl (decl, (char *) 0);
4792 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4794 #ifdef ASM_OUTPUT_DEF
4795 /* Make name accessible from other files, if appropriate. */
4797 if (TREE_PUBLIC (decl))
4799 #ifdef ASM_WEAKEN_LABEL
4800 if (DECL_WEAK (decl))
4802 ASM_WEAKEN_LABEL (asm_out_file, name);
4803 /* Remove this function from the pending weak list so that
4804 we do not emit multiple .weak directives for it. */
4805 remove_from_pending_weak_list
4806 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4808 else
4809 #endif
4810 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4813 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4814 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4815 #else
4816 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4817 #endif
4818 TREE_ASM_WRITTEN (decl) = 1;
4819 #else
4820 #ifdef ASM_OUTPUT_WEAK_ALIAS
4821 if (! DECL_WEAK (decl))
4822 warning ("only weak aliases are supported in this configuration");
4824 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4825 TREE_ASM_WRITTEN (decl) = 1;
4826 #else
4827 warning ("alias definitions not supported in this configuration; ignored");
4828 #endif
4829 #endif
4832 /* This determines whether or not we support link-once semantics. */
4833 #ifndef SUPPORTS_ONE_ONLY
4834 #ifdef MAKE_DECL_ONE_ONLY
4835 #define SUPPORTS_ONE_ONLY 1
4836 #else
4837 #define SUPPORTS_ONE_ONLY 0
4838 #endif
4839 #endif
4841 /* Returns 1 if the target configuration supports defining public symbols
4842 so that one of them will be chosen at link time instead of generating a
4843 multiply-defined symbol error, whether through the use of weak symbols or
4844 a target-specific mechanism for having duplicates discarded. */
4847 supports_one_only ()
4849 if (SUPPORTS_ONE_ONLY)
4850 return 1;
4851 return SUPPORTS_WEAK;
4854 /* Set up DECL as a public symbol that can be defined in multiple
4855 translation units without generating a linker error. */
4857 void
4858 make_decl_one_only (decl)
4859 tree decl;
4861 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4862 abort ();
4864 TREE_PUBLIC (decl) = 1;
4866 if (TREE_CODE (decl) == VAR_DECL
4867 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4868 DECL_COMMON (decl) = 1;
4869 else if (SUPPORTS_ONE_ONLY)
4871 #ifdef MAKE_DECL_ONE_ONLY
4872 MAKE_DECL_ONE_ONLY (decl);
4873 #endif
4874 DECL_ONE_ONLY (decl) = 1;
4876 else if (SUPPORTS_WEAK)
4877 DECL_WEAK (decl) = 1;
4878 else
4879 abort ();
4882 void
4883 init_varasm_once ()
4885 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
4886 const_str_htab_del);
4887 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
4888 mark_const_hash_entry);
4889 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
4890 mark_const_str_htab);
4893 /* Extra support for EH values. */
4894 void
4895 assemble_eh_label (name)
4896 const char *name;
4898 #ifdef ASM_OUTPUT_EH_LABEL
4899 ASM_OUTPUT_EH_LABEL (asm_out_file, name);
4900 #else
4901 assemble_label (name);
4902 #endif
4905 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
4907 void
4908 assemble_eh_align (align)
4909 int align;
4911 #ifdef ASM_OUTPUT_EH_ALIGN
4912 if (align > BITS_PER_UNIT)
4913 ASM_OUTPUT_EH_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
4914 #else
4915 assemble_align (align);
4916 #endif
4920 /* On some platforms, we may want to specify a special mechansim to
4921 output EH data when generating with a function.. */
4923 assemble_eh_integer (x, size, force)
4924 rtx x;
4925 int size;
4926 int force;
4929 switch (size)
4931 #ifdef ASM_OUTPUT_EH_CHAR
4932 case 1:
4933 ASM_OUTPUT_EH_CHAR (asm_out_file, x);
4934 return 1;
4935 #endif
4937 #ifdef ASM_OUTPUT_EH_SHORT
4938 case 2:
4939 ASM_OUTPUT_EH_SHORT (asm_out_file, x);
4940 return 1;
4941 #endif
4943 #ifdef ASM_OUTPUT_EH_INT
4944 case 4:
4945 ASM_OUTPUT_EH_INT (asm_out_file, x);
4946 return 1;
4947 #endif
4949 #ifdef ASM_OUTPUT_EH_DOUBLE_INT
4950 case 8:
4951 ASM_OUTPUT_EH_DOUBLE_INT (asm_out_file, x);
4952 return 1;
4953 #endif
4955 default:
4956 break;
4958 return (assemble_integer (x, size, force));