OSDN Git Service

* config/xtensa/xtensa.md: Remove unused type attributes.
[pf3gnuchains/gcc-fork.git] / gcc / varasm.c
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, 2002 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22
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.
26
27    We also output the assembler code for constants stored in memory
28    and are responsible for combining constants with the same value.  */
29
30 #include "config.h"
31 #include "system.h"
32 #include "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "hard-reg-set.h"
38 #include "regs.h"
39 #include "output.h"
40 #include "real.h"
41 #include "toplev.h"
42 #include "obstack.h"
43 #include "hashtab.h"
44 #include "c-pragma.h"
45 #include "c-tree.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
51
52 #ifdef XCOFF_DEBUGGING_INFO
53 #include "xcoffout.h"           /* Needed for external data
54                                    declarations for e.g. AIX 4.x.  */
55 #endif
56
57 #ifndef TRAMPOLINE_ALIGNMENT
58 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
59 #endif
60
61 #ifndef ASM_STABS_OP
62 #define ASM_STABS_OP "\t.stabs\t"
63 #endif
64
65 /* The (assembler) name of the first globally-visible object output.  */
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
68
69 extern struct obstack permanent_obstack;
70 #define obstack_chunk_alloc xmalloc
71
72 struct addr_const;
73 struct constant_descriptor;
74 struct rtx_const;
75 struct pool_constant;
76
77 #define MAX_RTX_HASH_TABLE 61
78
79 struct varasm_status
80 {
81   /* Hash facility for making memory-constants
82      from constant rtl-expressions.  It is used on RISC machines
83      where immediate integer arguments and constant addresses are restricted
84      so that such constants must be stored in memory.
85
86      This pool of constants is reinitialized for each function
87      so each function gets its own constants-pool that comes right before
88      it.  */
89   struct constant_descriptor **x_const_rtx_hash_table;
90   struct pool_constant **x_const_rtx_sym_hash_table;
91
92   /* Pointers to first and last constant in pool.  */
93   struct pool_constant *x_first_pool, *x_last_pool;
94
95   /* Current offset in constant pool (does not include any machine-specific
96      header).  */
97   HOST_WIDE_INT x_pool_offset;
98
99   /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
100      They are chained through the CONST_DOUBLE_CHAIN.  */
101   rtx x_const_double_chain;
102 };
103
104 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
105 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
106 #define first_pool (cfun->varasm->x_first_pool)
107 #define last_pool (cfun->varasm->x_last_pool)
108 #define pool_offset (cfun->varasm->x_pool_offset)
109 #define const_double_chain (cfun->varasm->x_const_double_chain)
110
111 /* Number for making the label on the next
112    constant that is stored in memory.  */
113
114 int const_labelno;
115
116 /* Number for making the label on the next
117    static variable internal to a function.  */
118
119 int var_labelno;
120
121 /* Carry information from ASM_DECLARE_OBJECT_NAME
122    to ASM_FINISH_DECLARE_OBJECT.  */
123
124 int size_directive_output;
125
126 /* The last decl for which assemble_variable was called,
127    if it did ASM_DECLARE_OBJECT_NAME.
128    If the last call to assemble_variable didn't do that,
129    this holds 0.  */
130
131 tree last_assemble_variable_decl;
132
133 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
134    So giving constant the alias set for the type will allow such
135    initializations to appear to conflict with the load of the constant.  We
136    avoid this by giving all constants an alias set for just constants.
137    Since there will be no stores to that alias set, nothing will ever
138    conflict with them.  */
139
140 static HOST_WIDE_INT const_alias_set;
141
142 static const char *strip_reg_name       PARAMS ((const char *));
143 static int contains_pointers_p          PARAMS ((tree));
144 static void decode_addr_const           PARAMS ((tree, struct addr_const *));
145 static int const_hash                   PARAMS ((tree));
146 static int compare_constant             PARAMS ((tree,
147                                                struct constant_descriptor *));
148 static const unsigned char *compare_constant_1  PARAMS ((tree, const unsigned char *));
149 static struct constant_descriptor *record_constant PARAMS ((tree));
150 static void record_constant_1           PARAMS ((tree));
151 static tree copy_constant               PARAMS ((tree));
152 static void output_constant_def_contents  PARAMS ((tree, int, int));
153 static void decode_rtx_const            PARAMS ((enum machine_mode, rtx,
154                                                struct rtx_const *));
155 static int const_hash_rtx               PARAMS ((enum machine_mode, rtx));
156 static int compare_constant_rtx         PARAMS ((enum machine_mode, rtx,
157                                                struct constant_descriptor *));
158 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
159                                                               rtx));
160 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
161 static void mark_constant_pool          PARAMS ((void));
162 static void mark_constants              PARAMS ((rtx));
163 static int mark_constant                PARAMS ((rtx *current_rtx, void *data));
164 static int output_addressed_constants   PARAMS ((tree));
165 static void output_after_function_constants PARAMS ((void));
166 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
167 static unsigned min_align               PARAMS ((unsigned, unsigned));
168 static void output_constructor          PARAMS ((tree, HOST_WIDE_INT,
169                                                  unsigned int));
170 static void globalize_decl              PARAMS ((tree));
171 static void maybe_assemble_visibility   PARAMS ((tree));
172 static int in_named_entry_eq            PARAMS ((const PTR, const PTR));
173 static hashval_t in_named_entry_hash    PARAMS ((const PTR));
174 #ifdef ASM_OUTPUT_BSS
175 static void asm_output_bss              PARAMS ((FILE *, tree, const char *, int, int));
176 #endif
177 #ifdef BSS_SECTION_ASM_OP
178 #ifdef ASM_OUTPUT_ALIGNED_BSS
179 static void asm_output_aligned_bss      PARAMS ((FILE *, tree, const char *,
180                                                  int, int));
181 #endif
182 #endif /* BSS_SECTION_ASM_OP */
183 static void mark_pool_constant          PARAMS ((struct pool_constant *));
184 static void mark_const_hash_entry       PARAMS ((void *));
185 static int mark_const_str_htab_1        PARAMS ((void **, void *));
186 static void mark_const_str_htab         PARAMS ((void *));
187 static hashval_t const_str_htab_hash    PARAMS ((const void *x));
188 static int const_str_htab_eq            PARAMS ((const void *x, const void *y));
189 static void const_str_htab_del          PARAMS ((void *));
190 static void asm_emit_uninitialised      PARAMS ((tree, const char*, int, int));
191 static void resolve_unique_section      PARAMS ((tree, int));
192 \f
193 static enum in_section { no_section, in_text, in_data, in_named
194 #ifdef BSS_SECTION_ASM_OP
195   , in_bss
196 #endif
197 #ifdef CTORS_SECTION_ASM_OP
198   , in_ctors
199 #endif
200 #ifdef DTORS_SECTION_ASM_OP
201   , in_dtors
202 #endif
203 #ifdef EXTRA_SECTIONS
204   , EXTRA_SECTIONS
205 #endif
206 } in_section = no_section;
207
208 /* Return a non-zero value if DECL has a section attribute.  */
209 #ifndef IN_NAMED_SECTION
210 #define IN_NAMED_SECTION(DECL) \
211   ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
212    && DECL_SECTION_NAME (DECL) != NULL_TREE)
213 #endif
214
215 /* Text of section name when in_section == in_named.  */
216 static const char *in_named_name;
217
218 /* Hash table of flags that have been used for a particular named section.  */
219
220 struct in_named_entry
221 {
222   const char *name;
223   unsigned int flags;
224   bool declared;
225 };
226
227 static htab_t in_named_htab;
228
229 /* Define functions like text_section for any extra sections.  */
230 #ifdef EXTRA_SECTION_FUNCTIONS
231 EXTRA_SECTION_FUNCTIONS
232 #endif
233
234 /* Tell assembler to switch to text section.  */
235
236 void
237 text_section ()
238 {
239   if (in_section != in_text)
240     {
241 #ifdef TEXT_SECTION
242       TEXT_SECTION ();
243 #else
244       fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
245 #endif
246       in_section = in_text;
247     }
248 }
249
250 /* Tell assembler to switch to data section.  */
251
252 void
253 data_section ()
254 {
255   if (in_section != in_data)
256     {
257       if (flag_shared_data)
258         {
259 #ifdef SHARED_SECTION_ASM_OP
260           fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
261 #else
262           fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
263 #endif
264         }
265       else
266         fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
267
268       in_section = in_data;
269     }
270 }
271 /* Tell assembler to ALWAYS switch to data section, in case
272    it's not sure where it is.  */
273
274 void
275 force_data_section ()
276 {
277   in_section = no_section;
278   data_section ();
279 }
280
281 /* Tell assembler to switch to read-only data section.  This is normally
282    the text section.  */
283
284 void
285 readonly_data_section ()
286 {
287 #ifdef READONLY_DATA_SECTION
288   READONLY_DATA_SECTION ();  /* Note this can call data_section.  */
289 #else
290   text_section ();
291 #endif
292 }
293
294 /* Determine if we're in the text section.  */
295
296 int
297 in_text_section ()
298 {
299   return in_section == in_text;
300 }
301
302 /* Determine if we're in the data section.  */
303
304 int
305 in_data_section ()
306 {
307   return in_section == in_data;
308 }
309
310 /* Helper routines for maintaining in_named_htab.  */
311
312 static int
313 in_named_entry_eq (p1, p2)
314      const PTR p1;
315      const PTR p2;
316 {
317   const struct in_named_entry *old = p1;
318   const char *new = p2;
319
320   return strcmp (old->name, new) == 0;
321 }
322
323 static hashval_t
324 in_named_entry_hash (p)
325      const PTR p;
326 {
327   const struct in_named_entry *old = p;
328   return htab_hash_string (old->name);
329 }
330
331 /* If SECTION has been seen before as a named section, return the flags
332    that were used.  Otherwise, return 0.  Note, that 0 is a perfectly valid
333    set of flags for a section to have, so 0 does not mean that the section
334    has not been seen.  */
335
336 unsigned int
337 get_named_section_flags (section)
338      const char *section;
339 {
340   struct in_named_entry **slot;
341
342   slot = (struct in_named_entry**)
343     htab_find_slot_with_hash (in_named_htab, section,
344                               htab_hash_string (section), NO_INSERT);
345
346   return slot ? (*slot)->flags : 0;
347 }
348
349 /* Returns true if the section has been declared before.   Sets internal
350    flag on this section in in_named_hash so subsequent calls on this 
351    section will return false.  */
352
353 bool
354 named_section_first_declaration (name)
355      const char *name;
356 {
357   struct in_named_entry **slot;
358
359   slot = (struct in_named_entry**)
360     htab_find_slot_with_hash (in_named_htab, name, 
361                               htab_hash_string (name), NO_INSERT);
362   if (! (*slot)->declared)
363     {
364       (*slot)->declared = true;
365       return true;
366     }
367   else 
368     {
369       return false;
370     }
371 }
372
373
374 /* Record FLAGS for SECTION.  If SECTION was previously recorded with a
375    different set of flags, return false.  */
376
377 bool
378 set_named_section_flags (section, flags)
379      const char *section;
380      unsigned int flags;
381 {
382   struct in_named_entry **slot, *entry;
383
384   slot = (struct in_named_entry**)
385     htab_find_slot_with_hash (in_named_htab, section,
386                               htab_hash_string (section), INSERT);
387   entry = *slot;
388
389   if (!entry)
390     {
391       entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
392       *slot = entry;
393       entry->name = ggc_strdup (section);
394       entry->flags = flags;
395       entry->declared = false;
396     }
397   else if (entry->flags != flags)
398     return false;
399
400   return true;
401 }
402
403 /* Tell assembler to change to section NAME with attributes FLAGS.  */
404
405 void
406 named_section_flags (name, flags)
407      const char *name;
408      unsigned int flags;
409 {
410   if (in_section != in_named || strcmp (name, in_named_name) != 0)
411     {
412       if (! set_named_section_flags (name, flags))
413         abort ();
414
415       (* targetm.asm_out.named_section) (name, flags);
416
417       if (flags & SECTION_FORGET)
418         in_section = no_section;
419       else
420         {
421           in_named_name = ggc_strdup (name);
422           in_section = in_named;
423         }
424     }
425 }
426
427 /* Tell assembler to change to section NAME for DECL.
428    If DECL is NULL, just switch to section NAME.
429    If NAME is NULL, get the name from DECL.
430    If RELOC is 1, the initializer for DECL contains relocs.  */
431
432 void
433 named_section (decl, name, reloc)
434      tree decl;
435      const char *name;
436      int reloc;
437 {
438   unsigned int flags;
439
440   if (decl != NULL_TREE && !DECL_P (decl))
441     abort ();
442   if (name == NULL)
443     name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
444
445   flags = (* targetm.section_type_flags) (decl, name, reloc);
446
447   /* Sanity check user variables for flag changes.  Non-user
448      section flag changes will abort in named_section_flags.
449      However, don't complain if SECTION_OVERRIDE is set.
450      We trust that the setter knows that it is safe to ignore
451      the default flags for this decl.  */
452   if (decl && ! set_named_section_flags (name, flags))
453     {
454       flags = get_named_section_flags (name);
455       if ((flags & SECTION_OVERRIDE) == 0)
456         error_with_decl (decl, "%s causes a section type conflict");
457     }
458
459   named_section_flags (name, flags);
460 }
461
462 /* If required, set DECL_SECTION_NAME to a unique name.  */
463
464 static void
465 resolve_unique_section (decl, reloc)
466      tree decl;
467      int reloc ATTRIBUTE_UNUSED;
468 {
469   if (DECL_SECTION_NAME (decl) == NULL_TREE
470       && (flag_function_sections
471           || (targetm.have_named_sections
472               && DECL_ONE_ONLY (decl))))
473     UNIQUE_SECTION (decl, reloc);
474 }
475
476 #ifdef BSS_SECTION_ASM_OP
477
478 /* Tell the assembler to switch to the bss section.  */
479
480 void
481 bss_section ()
482 {
483   if (in_section != in_bss)
484     {
485 #ifdef SHARED_BSS_SECTION_ASM_OP
486       if (flag_shared_data)
487         fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
488       else
489 #endif
490         fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
491
492       in_section = in_bss;
493     }
494 }
495
496 #ifdef ASM_OUTPUT_BSS
497
498 /* Utility function for ASM_OUTPUT_BSS for targets to use if
499    they don't support alignments in .bss.
500    ??? It is believed that this function will work in most cases so such
501    support is localized here.  */
502
503 static void
504 asm_output_bss (file, decl, name, size, rounded)
505      FILE *file;
506      tree decl ATTRIBUTE_UNUSED;
507      const char *name;
508      int size ATTRIBUTE_UNUSED, rounded;
509 {
510   ASM_GLOBALIZE_LABEL (file, name);
511   bss_section ();
512 #ifdef ASM_DECLARE_OBJECT_NAME
513   last_assemble_variable_decl = decl;
514   ASM_DECLARE_OBJECT_NAME (file, name, decl);
515 #else
516   /* Standard thing is just output label for the object.  */
517   ASM_OUTPUT_LABEL (file, name);
518 #endif /* ASM_DECLARE_OBJECT_NAME */
519   ASM_OUTPUT_SKIP (file, rounded);
520 }
521
522 #endif
523
524 #ifdef ASM_OUTPUT_ALIGNED_BSS
525
526 /* Utility function for targets to use in implementing
527    ASM_OUTPUT_ALIGNED_BSS.
528    ??? It is believed that this function will work in most cases so such
529    support is localized here.  */
530
531 static void
532 asm_output_aligned_bss (file, decl, name, size, align)
533      FILE *file;
534      tree decl ATTRIBUTE_UNUSED;
535      const char *name;
536      int size, align;
537 {
538   ASM_GLOBALIZE_LABEL (file, name);
539   bss_section ();
540   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
541 #ifdef ASM_DECLARE_OBJECT_NAME
542   last_assemble_variable_decl = decl;
543   ASM_DECLARE_OBJECT_NAME (file, name, decl);
544 #else
545   /* Standard thing is just output label for the object.  */
546   ASM_OUTPUT_LABEL (file, name);
547 #endif /* ASM_DECLARE_OBJECT_NAME */
548   ASM_OUTPUT_SKIP (file, size ? size : 1);
549 }
550
551 #endif
552
553 #endif /* BSS_SECTION_ASM_OP */
554
555 /* Switch to the section for function DECL.
556
557    If DECL is NULL_TREE, switch to the text section.
558    ??? It's not clear that we will ever be passed NULL_TREE, but it's
559    safer to handle it.  */
560
561 void
562 function_section (decl)
563      tree decl;
564 {
565   if (decl != NULL_TREE
566       && DECL_SECTION_NAME (decl) != NULL_TREE)
567     named_section (decl, (char *) 0, 0);
568   else
569     text_section ();
570 }
571
572 /* Switch to section for variable DECL.
573
574    RELOC is the `reloc' argument to SELECT_SECTION.  */
575
576 void
577 variable_section (decl, reloc)
578      tree decl;
579      int reloc;
580 {
581   if (IN_NAMED_SECTION (decl))
582     named_section (decl, NULL, reloc);
583   else
584     {
585       /* C++ can have const variables that get initialized from constructors,
586          and thus can not be in a readonly section.  We prevent this by
587          verifying that the initial value is constant for objects put in a
588          readonly section.
589
590          error_mark_node is used by the C front end to indicate that the
591          initializer has not been seen yet.  In this case, we assume that
592          the initializer must be constant.
593
594          C++ uses error_mark_node for variables that have complicated
595          initializers, but these variables go in BSS so we won't be called
596          for them.  */
597
598 #ifdef SELECT_SECTION
599       SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
600 #else
601       if (DECL_READONLY_SECTION (decl, reloc))
602         readonly_data_section ();
603       else
604         data_section ();
605 #endif
606     }
607 }
608
609 /* Tell assembler to switch to the section for the exception handling
610    table.  */
611
612 void
613 default_exception_section ()
614 {
615   if (targetm.have_named_sections)
616     named_section (NULL_TREE, ".gcc_except_table", 0);
617   else if (flag_pic)
618     data_section ();
619   else
620     readonly_data_section ();
621 }
622
623 /* Tell assembler to switch to the section for string merging.  */
624
625 void
626 mergeable_string_section (decl, align, flags)
627   tree decl ATTRIBUTE_UNUSED;
628   unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
629   unsigned int flags ATTRIBUTE_UNUSED;
630 {
631 #ifdef HAVE_GAS_SHF_MERGE
632   if (flag_merge_constants
633       && TREE_CODE (decl) == STRING_CST
634       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
635       && align <= 256
636       && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
637     {
638       enum machine_mode mode;
639       unsigned int modesize;
640       const char *str;
641       int i, j, len, unit;
642       char name[30];
643
644       mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
645       modesize = GET_MODE_BITSIZE (mode);
646       if (modesize >= 8 && modesize <= 256
647           && (modesize & (modesize - 1)) == 0)
648         {
649           if (align < modesize)
650             align = modesize;
651
652           str = TREE_STRING_POINTER (decl);
653           len = TREE_STRING_LENGTH (decl);
654           unit = GET_MODE_SIZE (mode);
655
656           /* Check for embedded NUL characters.  */
657           for (i = 0; i < len; i += unit)
658             {
659               for (j = 0; j < unit; j++)
660                 if (str [i + j] != '\0')
661                   break;
662               if (j == unit)
663                 break;
664             }
665           if (i == len - unit)
666             {
667               sprintf (name, ".rodata.str%d.%d", modesize / 8,
668                        (int) (align / 8));
669               flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
670               if (!i && modesize < align)
671                 {
672                   /* A "" string with requested alignment greater than
673                      character size might cause a problem:
674                      if some other string required even bigger
675                      alignment than "", then linker might think the
676                      "" is just part of padding after some other string
677                      and not put it into the hash table initially.
678                      But this means "" could have smaller alignment
679                      than requested.  */
680 #ifdef ASM_OUTPUT_SECTION_START
681                   named_section_flags (name, flags);
682                   ASM_OUTPUT_SECTION_START (asm_out_file);
683 #else
684                   readonly_data_section ();
685 #endif
686                   return;
687                 }
688
689               named_section_flags (name, flags);
690               return;
691             }
692         }
693     }
694 #endif
695   readonly_data_section ();
696 }  
697
698 /* Tell assembler to switch to the section for constant merging.  */
699
700 void
701 mergeable_constant_section (mode, align, flags)
702   enum machine_mode mode ATTRIBUTE_UNUSED;
703   unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
704   unsigned int flags ATTRIBUTE_UNUSED;
705 {
706 #ifdef HAVE_GAS_SHF_MERGE
707   unsigned int modesize = GET_MODE_BITSIZE (mode);
708
709   if (flag_merge_constants
710       && mode != VOIDmode
711       && mode != BLKmode
712       && modesize <= align
713       && align >= 8
714       && align <= 256
715       && (align & (align - 1)) == 0)
716     {
717       char name[24];
718
719       sprintf (name, ".rodata.cst%d", (int) (align / 8));
720       flags |= (align / 8) | SECTION_MERGE;
721       named_section_flags (name, flags);
722       return;
723     }            
724 #endif
725   readonly_data_section ();
726 }
727 \f
728 /* Given NAME, a putative register name, discard any customary prefixes.  */
729
730 static const char *
731 strip_reg_name (name)
732   const char *name;
733 {
734 #ifdef REGISTER_PREFIX
735   if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
736     name += strlen (REGISTER_PREFIX);
737 #endif
738   if (name[0] == '%' || name[0] == '#')
739     name++;
740   return name;
741 }
742 \f
743 /* Decode an `asm' spec for a declaration as a register name.
744    Return the register number, or -1 if nothing specified,
745    or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
746    or -3 if ASMSPEC is `cc' and is not recognized,
747    or -4 if ASMSPEC is `memory' and is not recognized.
748    Accept an exact spelling or a decimal number.
749    Prefixes such as % are optional.  */
750
751 int
752 decode_reg_name (asmspec)
753   const char *asmspec;
754 {
755   if (asmspec != 0)
756     {
757       int i;
758
759       /* Get rid of confusing prefixes.  */
760       asmspec = strip_reg_name (asmspec);
761
762       /* Allow a decimal number as a "register name".  */
763       for (i = strlen (asmspec) - 1; i >= 0; i--)
764         if (! ISDIGIT (asmspec[i]))
765           break;
766       if (asmspec[0] != 0 && i < 0)
767         {
768           i = atoi (asmspec);
769           if (i < FIRST_PSEUDO_REGISTER && i >= 0)
770             return i;
771           else
772             return -2;
773         }
774
775       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
776         if (reg_names[i][0]
777             && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
778           return i;
779
780 #ifdef ADDITIONAL_REGISTER_NAMES
781       {
782         static const struct { const char *const name; const int number; } table[]
783           = ADDITIONAL_REGISTER_NAMES;
784
785         for (i = 0; i < (int) ARRAY_SIZE (table); i++)
786           if (! strcmp (asmspec, table[i].name))
787             return table[i].number;
788       }
789 #endif /* ADDITIONAL_REGISTER_NAMES */
790
791       if (!strcmp (asmspec, "memory"))
792         return -4;
793
794       if (!strcmp (asmspec, "cc"))
795         return -3;
796
797       return -2;
798     }
799
800   return -1;
801 }
802 \f
803 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL.  DECL should
804    have static storage duration.  In other words, it should not be an
805    automatic variable, including PARM_DECLs.
806
807    There is, however, one exception: this function handles variables
808    explicitly placed in a particular register by the user.
809
810    ASMSPEC, if not 0, is the string which the user specified as the
811    assembler symbol name.
812
813    This is never called for PARM_DECL nodes.  */
814
815 void
816 make_decl_rtl (decl, asmspec)
817      tree decl;
818      const char *asmspec;
819 {
820   int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
821   const char *name = 0;
822   const char *new_name = 0;
823   int reg_number;
824   rtx x;
825
826   /* Check that we are not being given an automatic variable.  */
827   /* A weak alias has TREE_PUBLIC set but not the other bits.  */
828   if (TREE_CODE (decl) == PARM_DECL
829       || TREE_CODE (decl) == RESULT_DECL
830       || (TREE_CODE (decl) == VAR_DECL
831           && !TREE_STATIC (decl)
832           && !TREE_PUBLIC (decl)
833           && !DECL_EXTERNAL (decl)
834           && !DECL_REGISTER (decl)))
835     abort ();
836   /* And that we were not given a type or a label.  */
837   else if (TREE_CODE (decl) == TYPE_DECL
838            || TREE_CODE (decl) == LABEL_DECL)
839     abort ();
840
841   /* For a duplicate declaration, we can be called twice on the
842      same DECL node.  Don't discard the RTL already made.  */
843   if (DECL_RTL_SET_P (decl))
844     {
845       /* If the old RTL had the wrong mode, fix the mode.  */
846       if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
847         SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
848                                                DECL_MODE (decl), 0));
849
850       /* ??? Another way to do this would be to do what halfpic.c does
851          and maintain a hashed table of such critters.  */
852       /* Let the target reassign the RTL if it wants.
853          This is necessary, for example, when one machine specific
854          decl attribute overrides another.  */
855 #ifdef ENCODE_SECTION_INFO
856       ENCODE_SECTION_INFO (decl, false);
857 #endif
858       return;
859     }
860
861   new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
862
863   reg_number = decode_reg_name (asmspec);
864   if (reg_number == -2)
865     {
866       /* ASMSPEC is given, and not the name of a register.  Mark the
867          name with a star so assemble_name won't munge it.  */
868       char *starred = alloca (strlen (asmspec) + 2);
869       starred[0] = '*';
870       strcpy (starred + 1, asmspec);
871       new_name = starred;
872     }
873
874   if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
875     {
876       /* First detect errors in declaring global registers.  */
877       if (reg_number == -1)
878         error_with_decl (decl, "register name not specified for `%s'");
879       else if (reg_number < 0)
880         error_with_decl (decl, "invalid register name for `%s'");
881       else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
882         error_with_decl (decl,
883                          "data type of `%s' isn't suitable for a register");
884       else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
885         error_with_decl (decl,
886                          "register specified for `%s' isn't suitable for data type");
887       /* Now handle properly declared static register variables.  */
888       else
889         {
890           int nregs;
891
892           if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
893             {
894               DECL_INITIAL (decl) = 0;
895               error ("global register variable has initial value");
896             }
897           if (TREE_THIS_VOLATILE (decl))
898             warning ("volatile register variables don't work as you might wish");
899
900           /* If the user specified one of the eliminables registers here,
901              e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
902              confused with that register and be eliminated.  This usage is
903              somewhat suspect...  */
904
905           SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
906           ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
907           REG_USERVAR_P (DECL_RTL (decl)) = 1;
908
909           if (TREE_STATIC (decl))
910             {
911               /* Make this register global, so not usable for anything
912                  else.  */
913 #ifdef ASM_DECLARE_REGISTER_GLOBAL
914               ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
915 #endif
916               nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
917               while (nregs > 0)
918                 globalize_reg (reg_number + --nregs);
919             }
920
921           /* As a register variable, it has no section.  */
922           return;
923         }
924     }
925
926   /* Now handle ordinary static variables and functions (in memory).
927      Also handle vars declared register invalidly.  */
928
929   if (reg_number >= 0 || reg_number == -3)
930     error_with_decl (decl,
931                      "register name given for non-register variable `%s'");
932
933   /* Specifying a section attribute on a variable forces it into a
934      non-.bss section, and thus it cannot be common.  */
935   if (TREE_CODE (decl) == VAR_DECL
936       && DECL_SECTION_NAME (decl) != NULL_TREE
937       && DECL_INITIAL (decl) == NULL_TREE
938       && DECL_COMMON (decl))
939     DECL_COMMON (decl) = 0;
940
941   /* Can't use just the variable's own name for a variable
942      whose scope is less than the whole file, unless it's a member
943      of a local class (which will already be unambiguous).
944      Concatenate a distinguishing number.  */
945   if (!top_level && !TREE_PUBLIC (decl)
946       && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
947       && asmspec == 0
948       && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
949     {
950       char *label;
951
952       ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
953       var_labelno++;
954       new_name = label;
955     }
956
957   if (name != new_name)
958     {
959       SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
960       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
961     }
962
963   /* If this variable is to be treated as volatile, show its
964      tree node has side effects.  */
965   if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
966        && TREE_PUBLIC (decl))
967       || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
968            && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
969     TREE_SIDE_EFFECTS (decl) = 1;
970
971   x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
972   SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
973   if (TREE_CODE (decl) != FUNCTION_DECL)
974     set_mem_attributes (x, decl, 1);
975   SET_DECL_RTL (decl, x);
976
977   /* Optionally set flags or add text to the name to record information
978      such as that it is a function name.
979      If the name is changed, the macro ASM_OUTPUT_LABELREF
980      will have to know how to strip this information.  */
981 #ifdef ENCODE_SECTION_INFO
982   ENCODE_SECTION_INFO (decl, true);
983 #endif
984 }
985
986 /* Make the rtl for variable VAR be volatile.
987    Use this only for static variables.  */
988
989 void
990 make_var_volatile (var)
991      tree var;
992 {
993   if (GET_CODE (DECL_RTL (var)) != MEM)
994     abort ();
995
996   MEM_VOLATILE_P (DECL_RTL (var)) = 1;
997 }
998 \f
999 /* Output alignment directive to align for constant expression EXP.  */
1000
1001 void
1002 assemble_constant_align (exp)
1003      tree exp;
1004 {
1005   int align;
1006
1007   /* Align the location counter as required by EXP's data type.  */
1008   align = TYPE_ALIGN (TREE_TYPE (exp));
1009 #ifdef CONSTANT_ALIGNMENT
1010   align = CONSTANT_ALIGNMENT (exp, align);
1011 #endif
1012
1013   if (align > BITS_PER_UNIT)
1014     {
1015       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1016     }
1017 }
1018
1019 /* Output a string of literal assembler code
1020    for an `asm' keyword used between functions.  */
1021
1022 void
1023 assemble_asm (string)
1024      tree string;
1025 {
1026   app_enable ();
1027
1028   if (TREE_CODE (string) == ADDR_EXPR)
1029     string = TREE_OPERAND (string, 0);
1030
1031   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1032 }
1033
1034 /* Record an element in the table of global destructors.  SYMBOL is
1035    a SYMBOL_REF of the function to be called; PRIORITY is a number
1036    between 0 and MAX_INIT_PRIORITY.  */
1037
1038 void
1039 default_stabs_asm_out_destructor (symbol, priority)
1040      rtx symbol;
1041      int priority ATTRIBUTE_UNUSED;
1042 {
1043   /* Tell GNU LD that this is part of the static destructor set.
1044      This will work for any system that uses stabs, most usefully
1045      aout systems.  */
1046   fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1047   assemble_name (asm_out_file, XSTR (symbol, 0));
1048   fputc ('\n', asm_out_file);
1049 }
1050
1051 void
1052 default_named_section_asm_out_destructor (symbol, priority)
1053      rtx symbol;
1054      int priority;
1055 {
1056   const char *section = ".dtors";
1057   char buf[16];
1058
1059   /* ??? This only works reliably with the GNU linker.  */
1060   if (priority != DEFAULT_INIT_PRIORITY)
1061     {
1062       sprintf (buf, ".dtors.%.5u",
1063                /* Invert the numbering so the linker puts us in the proper
1064                   order; constructors are run from right to left, and the
1065                   linker sorts in increasing order.  */
1066                MAX_INIT_PRIORITY - priority);
1067       section = buf;
1068     }
1069
1070   named_section_flags (section, SECTION_WRITE);
1071   assemble_align (POINTER_SIZE);
1072   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1073 }
1074
1075 #ifdef DTORS_SECTION_ASM_OP
1076 void
1077 dtors_section ()
1078 {
1079   if (in_section != in_dtors)
1080     {
1081       in_section = in_dtors;
1082       fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1083       fputc ('\n', asm_out_file);
1084     }
1085 }
1086
1087 void
1088 default_dtor_section_asm_out_destructor (symbol, priority)
1089      rtx symbol;
1090      int priority ATTRIBUTE_UNUSED;
1091 {
1092   dtors_section ();
1093   assemble_align (POINTER_SIZE);
1094   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1095 }
1096 #endif
1097
1098 /* Likewise for global constructors.  */
1099
1100 void
1101 default_stabs_asm_out_constructor (symbol, priority)
1102      rtx symbol;
1103      int priority ATTRIBUTE_UNUSED;
1104 {
1105   /* Tell GNU LD that this is part of the static destructor set.
1106      This will work for any system that uses stabs, most usefully
1107      aout systems.  */
1108   fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1109   assemble_name (asm_out_file, XSTR (symbol, 0));
1110   fputc ('\n', asm_out_file);
1111 }
1112
1113 void
1114 default_named_section_asm_out_constructor (symbol, priority)
1115      rtx symbol;
1116      int priority;
1117 {
1118   const char *section = ".ctors";
1119   char buf[16];
1120
1121   /* ??? This only works reliably with the GNU linker.  */
1122   if (priority != DEFAULT_INIT_PRIORITY)
1123     {
1124       sprintf (buf, ".ctors.%.5u",
1125                /* Invert the numbering so the linker puts us in the proper
1126                   order; constructors are run from right to left, and the
1127                   linker sorts in increasing order.  */
1128                MAX_INIT_PRIORITY - priority);
1129       section = buf;
1130     }
1131
1132   named_section_flags (section, SECTION_WRITE);
1133   assemble_align (POINTER_SIZE);
1134   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1135 }
1136
1137 #ifdef CTORS_SECTION_ASM_OP
1138 void
1139 ctors_section ()
1140 {
1141   if (in_section != in_ctors)
1142     {
1143       in_section = in_ctors;
1144       fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1145       fputc ('\n', asm_out_file);
1146     }
1147 }
1148
1149 void
1150 default_ctor_section_asm_out_constructor (symbol, priority)
1151      rtx symbol;
1152      int priority ATTRIBUTE_UNUSED;
1153 {
1154   ctors_section ();
1155   assemble_align (POINTER_SIZE);
1156   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1157 }
1158 #endif
1159 \f
1160 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1161    a non-zero value if the constant pool should be output before the
1162    start of the function, or a zero value if the pool should output
1163    after the end of the function.  The default is to put it before the
1164    start.  */
1165
1166 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1167 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1168 #endif
1169
1170 /* Output assembler code for the constant pool of a function and associated
1171    with defining the name of the function.  DECL describes the function.
1172    NAME is the function's name.  For the constant pool, we use the current
1173    constant pool data.  */
1174
1175 void
1176 assemble_start_function (decl, fnname)
1177      tree decl;
1178      const char *fnname;
1179 {
1180   int align;
1181
1182   /* The following code does not need preprocessing in the assembler.  */
1183
1184   app_disable ();
1185
1186   if (CONSTANT_POOL_BEFORE_FUNCTION)
1187     output_constant_pool (fnname, decl);
1188
1189   resolve_unique_section (decl, 0);
1190   function_section (decl);
1191
1192   /* Tell assembler to move to target machine's alignment for functions.  */
1193   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1194   if (align > 0)
1195     {
1196       ASM_OUTPUT_ALIGN (asm_out_file, align);
1197     }
1198
1199   /* Handle a user-specified function alignment.
1200      Note that we still need to align to FUNCTION_BOUNDARY, as above,
1201      because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all.  */
1202   if (align_functions_log > align)
1203     {
1204 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1205       ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1206                                  align_functions_log, align_functions-1);
1207 #else
1208       ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1209 #endif
1210     }
1211
1212 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1213   ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1214 #endif
1215
1216   (*debug_hooks->begin_function) (decl);
1217
1218   /* Make function name accessible from other files, if appropriate.  */
1219
1220   if (TREE_PUBLIC (decl))
1221     {
1222       if (! first_global_object_name)
1223         {
1224           const char *p;
1225           char *name;
1226
1227           STRIP_NAME_ENCODING (p, fnname);
1228           name = permalloc (strlen (p) + 1);
1229           strcpy (name, p);
1230
1231           if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1232             first_global_object_name = name;
1233           else
1234             weak_global_object_name = name;
1235         }
1236
1237       globalize_decl (decl);
1238
1239       maybe_assemble_visibility (decl);
1240     }
1241
1242   /* Do any machine/system dependent processing of the function name */
1243 #ifdef ASM_DECLARE_FUNCTION_NAME
1244   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1245 #else
1246   /* Standard thing is just output label for the function.  */
1247   ASM_OUTPUT_LABEL (asm_out_file, fnname);
1248 #endif /* ASM_DECLARE_FUNCTION_NAME */
1249 }
1250
1251 /* Output assembler code associated with defining the size of the
1252    function.  DECL describes the function.  NAME is the function's name.  */
1253
1254 void
1255 assemble_end_function (decl, fnname)
1256      tree decl;
1257      const char *fnname;
1258 {
1259 #ifdef ASM_DECLARE_FUNCTION_SIZE
1260   ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1261 #endif
1262   if (! CONSTANT_POOL_BEFORE_FUNCTION)
1263     {
1264       output_constant_pool (fnname, decl);
1265       function_section (decl);  /* need to switch back */
1266     }
1267
1268   /* Output any constants which should appear after the function.  */
1269   output_after_function_constants ();
1270 }
1271 \f
1272 /* Assemble code to leave SIZE bytes of zeros.  */
1273
1274 void
1275 assemble_zeros (size)
1276      int size;
1277 {
1278   /* Do no output if -fsyntax-only.  */
1279   if (flag_syntax_only)
1280     return;
1281
1282 #ifdef ASM_NO_SKIP_IN_TEXT
1283   /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1284      so we must output 0s explicitly in the text section.  */
1285   if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1286     {
1287       int i;
1288       for (i = 0; i < size; i++)
1289         assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1290     }
1291   else
1292 #endif
1293     if (size > 0)
1294       ASM_OUTPUT_SKIP (asm_out_file, size);
1295 }
1296
1297 /* Assemble an alignment pseudo op for an ALIGN-bit boundary.  */
1298
1299 void
1300 assemble_align (align)
1301      int align;
1302 {
1303   if (align > BITS_PER_UNIT)
1304     {
1305       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1306     }
1307 }
1308
1309 /* Assemble a string constant with the specified C string as contents.  */
1310
1311 void
1312 assemble_string (p, size)
1313      const char *p;
1314      int size;
1315 {
1316   int pos = 0;
1317   int maximum = 2000;
1318
1319   /* If the string is very long, split it up.  */
1320
1321   while (pos < size)
1322     {
1323       int thissize = size - pos;
1324       if (thissize > maximum)
1325         thissize = maximum;
1326
1327       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1328
1329       pos += thissize;
1330       p += thissize;
1331     }
1332 }
1333
1334 \f
1335 #if defined  ASM_OUTPUT_ALIGNED_DECL_LOCAL
1336 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1337   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1338 #else
1339 #if defined  ASM_OUTPUT_ALIGNED_LOCAL
1340 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1341   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1342 #else
1343 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1344   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1345 #endif
1346 #endif
1347
1348 #if defined ASM_OUTPUT_ALIGNED_BSS
1349 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1350   ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1351 #else
1352 #if defined ASM_OUTPUT_BSS
1353 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1354   ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1355 #else
1356 #undef  ASM_EMIT_BSS
1357 #endif
1358 #endif
1359
1360 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1361 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1362   ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1363 #else
1364 #if defined ASM_OUTPUT_ALIGNED_COMMON
1365 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1366   ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1367 #else
1368 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1369   ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1370 #endif
1371 #endif
1372
1373 static void
1374 asm_emit_uninitialised (decl, name, size, rounded)
1375      tree decl;
1376      const char * name;
1377      int size ATTRIBUTE_UNUSED;
1378      int rounded ATTRIBUTE_UNUSED;
1379 {
1380   enum
1381   {
1382     asm_dest_common,
1383     asm_dest_bss,
1384     asm_dest_local
1385   }
1386   destination = asm_dest_local;
1387
1388   if (TREE_PUBLIC (decl))
1389     {
1390 #if defined ASM_EMIT_BSS
1391       if (! DECL_COMMON (decl))
1392         destination = asm_dest_bss;
1393       else
1394 #endif
1395         destination = asm_dest_common;
1396     }
1397
1398   switch (destination)
1399     {
1400     case asm_dest_common:
1401       if (! DECL_WEAK (decl))
1402         break;
1403     case asm_dest_bss:
1404       globalize_decl (decl);
1405     default:
1406       break;
1407     }
1408
1409   if (flag_shared_data)
1410     {
1411       switch (destination)
1412         {
1413 #ifdef ASM_OUTPUT_SHARED_BSS
1414         case asm_dest_bss:
1415           ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1416           return;
1417 #endif
1418 #ifdef ASM_OUTPUT_SHARED_COMMON
1419         case asm_dest_common:
1420           ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1421           return;
1422 #endif
1423 #ifdef ASM_OUTPUT_SHARED_LOCAL
1424         case asm_dest_local:
1425           ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1426           return;
1427 #endif
1428         default:
1429           break;
1430         }
1431     }
1432
1433   resolve_unique_section (decl, 0);
1434
1435   switch (destination)
1436     {
1437 #ifdef ASM_EMIT_BSS
1438     case asm_dest_bss:
1439       ASM_EMIT_BSS (decl, name, size, rounded);
1440       break;
1441 #endif
1442     case asm_dest_common:
1443       ASM_EMIT_COMMON (decl, name, size, rounded);
1444       break;
1445     case asm_dest_local:
1446       ASM_EMIT_LOCAL (decl, name, size, rounded);
1447       break;
1448     default:
1449       abort ();
1450     }
1451
1452   return;
1453 }
1454
1455 /* Assemble everything that is needed for a variable or function declaration.
1456    Not used for automatic variables, and not used for function definitions.
1457    Should not be called for variables of incomplete structure type.
1458
1459    TOP_LEVEL is nonzero if this variable has file scope.
1460    AT_END is nonzero if this is the special handling, at end of compilation,
1461    to define things that have had only tentative definitions.
1462    DONT_OUTPUT_DATA if nonzero means don't actually output the
1463    initial value (that will be done by the caller).  */
1464
1465 void
1466 assemble_variable (decl, top_level, at_end, dont_output_data)
1467      tree decl;
1468      int top_level ATTRIBUTE_UNUSED;
1469      int at_end ATTRIBUTE_UNUSED;
1470      int dont_output_data;
1471 {
1472   const char *name;
1473   unsigned int align;
1474   int reloc = 0;
1475   rtx decl_rtl;
1476
1477   last_assemble_variable_decl = 0;
1478
1479   /* Normally no need to say anything here for external references,
1480      since assemble_external is called by the language-specific code
1481      when a declaration is first seen.  */
1482
1483   if (DECL_EXTERNAL (decl))
1484     return;
1485
1486   /* Output no assembler code for a function declaration.
1487      Only definitions of functions output anything.  */
1488
1489   if (TREE_CODE (decl) == FUNCTION_DECL)
1490     return;
1491
1492   /* Do nothing for global register variables.  */
1493   if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1494     {
1495       TREE_ASM_WRITTEN (decl) = 1;
1496       return;
1497     }
1498
1499   /* If type was incomplete when the variable was declared,
1500      see if it is complete now.  */
1501
1502   if (DECL_SIZE (decl) == 0)
1503     layout_decl (decl, 0);
1504
1505   /* Still incomplete => don't allocate it; treat the tentative defn
1506      (which is what it must have been) as an `extern' reference.  */
1507
1508   if (!dont_output_data && DECL_SIZE (decl) == 0)
1509     {
1510       error_with_file_and_line (DECL_SOURCE_FILE (decl),
1511                                 DECL_SOURCE_LINE (decl),
1512                                 "storage size of `%s' isn't known",
1513                                 IDENTIFIER_POINTER (DECL_NAME (decl)));
1514       TREE_ASM_WRITTEN (decl) = 1;
1515       return;
1516     }
1517
1518   /* The first declaration of a variable that comes through this function
1519      decides whether it is global (in C, has external linkage)
1520      or local (in C, has internal linkage).  So do nothing more
1521      if this function has already run.  */
1522
1523   if (TREE_ASM_WRITTEN (decl))
1524     return;
1525
1526   /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN.  */
1527   decl_rtl = DECL_RTL (decl);
1528
1529   TREE_ASM_WRITTEN (decl) = 1;
1530
1531   /* Do no output if -fsyntax-only.  */
1532   if (flag_syntax_only)
1533     return;
1534
1535   app_disable ();
1536
1537   if (! dont_output_data
1538       && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1539     {
1540       error_with_decl (decl, "size of variable `%s' is too large");
1541       return;
1542     }
1543
1544   name = XSTR (XEXP (decl_rtl, 0), 0);
1545   if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1546       && ! first_global_object_name
1547       && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1548                                    || DECL_INITIAL (decl) == error_mark_node))
1549       && ! DECL_WEAK (decl)
1550       && ! DECL_ONE_ONLY (decl))
1551     {
1552       const char *p;
1553       char *xname;
1554
1555       STRIP_NAME_ENCODING (p, name);
1556       xname = permalloc (strlen (p) + 1);
1557       strcpy (xname, p);
1558       first_global_object_name = xname;
1559     }
1560
1561   /* Compute the alignment of this data.  */
1562
1563   align = DECL_ALIGN (decl);
1564
1565   /* In the case for initialing an array whose length isn't specified,
1566      where we have not yet been able to do the layout,
1567      figure out the proper alignment now.  */
1568   if (dont_output_data && DECL_SIZE (decl) == 0
1569       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1570     align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1571
1572   /* Some object file formats have a maximum alignment which they support.
1573      In particular, a.out format supports a maximum alignment of 4.  */
1574 #ifndef MAX_OFILE_ALIGNMENT
1575 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1576 #endif
1577   if (align > MAX_OFILE_ALIGNMENT)
1578     {
1579       warning_with_decl (decl,
1580         "alignment of `%s' is greater than maximum object file alignment. Using %d",
1581                     MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1582       align = MAX_OFILE_ALIGNMENT;
1583     }
1584
1585   /* On some machines, it is good to increase alignment sometimes.  */
1586   if (! DECL_USER_ALIGN (decl))
1587     {
1588 #ifdef DATA_ALIGNMENT
1589       align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1590 #endif
1591 #ifdef CONSTANT_ALIGNMENT
1592       if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1593         align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1594 #endif
1595     }
1596
1597   /* Reset the alignment in case we have made it tighter, so we can benefit
1598      from it in get_pointer_alignment.  */
1599   DECL_ALIGN (decl) = align;
1600   set_mem_align (decl_rtl, align);
1601
1602   if (TREE_PUBLIC (decl))
1603     maybe_assemble_visibility (decl);
1604
1605   /* Output any data that we will need to use the address of.  */
1606   if (DECL_INITIAL (decl) == error_mark_node)
1607     reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1608   else if (DECL_INITIAL (decl))
1609     reloc = output_addressed_constants (DECL_INITIAL (decl));
1610   resolve_unique_section (decl, reloc);
1611
1612   /* Handle uninitialized definitions.  */
1613
1614   if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node
1615 #if defined ASM_EMIT_BSS
1616        || (flag_zero_initialized_in_bss
1617            && initializer_zerop (DECL_INITIAL (decl)))
1618 #endif
1619        )
1620       /* If the target can't output uninitialized but not common global data
1621          in .bss, then we have to use .data.  */
1622 #if ! defined ASM_EMIT_BSS
1623       && DECL_COMMON (decl)
1624 #endif
1625       && DECL_SECTION_NAME (decl) == NULL_TREE
1626       && ! dont_output_data)
1627     {
1628       unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1629       unsigned HOST_WIDE_INT rounded = size;
1630
1631       /* Don't allocate zero bytes of common,
1632          since that means "undefined external" in the linker.  */
1633       if (size == 0)
1634         rounded = 1;
1635
1636       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1637          so that each uninitialized object starts on such a boundary.  */
1638       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1639       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1640                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1641
1642 /* Don't continue this line--convex cc version 4.1 would lose.  */
1643 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1644       if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1645          warning_with_decl
1646            (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1647 #endif
1648
1649       asm_emit_uninitialised (decl, name, size, rounded);
1650
1651       return;
1652     }
1653
1654   /* Handle initialized definitions.
1655      Also handle uninitialized global definitions if -fno-common and the
1656      target doesn't support ASM_OUTPUT_BSS.  */
1657
1658   /* First make the assembler name(s) global if appropriate.  */
1659   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1660     globalize_decl (decl);
1661
1662   /* Switch to the appropriate section.  */
1663   variable_section (decl, reloc);
1664
1665   /* dbxout.c needs to know this.  */
1666   if (in_text_section ())
1667     DECL_IN_TEXT_SECTION (decl) = 1;
1668
1669   /* Output the alignment of this data.  */
1670   if (align > BITS_PER_UNIT)
1671     {
1672       ASM_OUTPUT_ALIGN (asm_out_file,
1673                         floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1674     }
1675
1676   /* Do any machine/system dependent processing of the object.  */
1677 #ifdef ASM_DECLARE_OBJECT_NAME
1678   last_assemble_variable_decl = decl;
1679   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1680 #else
1681   /* Standard thing is just output label for the object.  */
1682   ASM_OUTPUT_LABEL (asm_out_file, name);
1683 #endif /* ASM_DECLARE_OBJECT_NAME */
1684
1685   if (!dont_output_data)
1686     {
1687       if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1688         /* Output the actual data.  */
1689         output_constant (DECL_INITIAL (decl),
1690                          tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1691                          align);
1692       else
1693         /* Leave space for it.  */
1694         assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1695     }
1696 }
1697
1698 /* Return 1 if type TYPE contains any pointers.  */
1699
1700 static int
1701 contains_pointers_p (type)
1702      tree type;
1703 {
1704   switch (TREE_CODE (type))
1705     {
1706     case POINTER_TYPE:
1707     case REFERENCE_TYPE:
1708       /* I'm not sure whether OFFSET_TYPE needs this treatment,
1709          so I'll play safe and return 1.  */
1710     case OFFSET_TYPE:
1711       return 1;
1712
1713     case RECORD_TYPE:
1714     case UNION_TYPE:
1715     case QUAL_UNION_TYPE:
1716       {
1717         tree fields;
1718         /* For a type that has fields, see if the fields have pointers.  */
1719         for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1720           if (TREE_CODE (fields) == FIELD_DECL
1721               && contains_pointers_p (TREE_TYPE (fields)))
1722             return 1;
1723         return 0;
1724       }
1725
1726     case ARRAY_TYPE:
1727       /* An array type contains pointers if its element type does.  */
1728       return contains_pointers_p (TREE_TYPE (type));
1729
1730     default:
1731       return 0;
1732     }
1733 }
1734
1735 /* Output something to declare an external symbol to the assembler.
1736    (Most assemblers don't need this, so we normally output nothing.)
1737    Do nothing if DECL is not external.  */
1738
1739 void
1740 assemble_external (decl)
1741      tree decl ATTRIBUTE_UNUSED;
1742 {
1743   /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1744      main body of this code is only rarely exercised.  To provide some
1745      testing, on all platforms, we make sure that the ASM_OUT_FILE is
1746      open.  If it's not, we should not be calling this function.  */
1747   if (!asm_out_file)
1748     abort ();
1749
1750 #ifdef ASM_OUTPUT_EXTERNAL
1751   if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1752     {
1753       rtx rtl = DECL_RTL (decl);
1754
1755       if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1756           && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1757         {
1758           /* Some systems do require some output.  */
1759           SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1760           ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1761         }
1762     }
1763 #endif
1764 }
1765
1766 /* Similar, for calling a library function FUN.  */
1767
1768 void
1769 assemble_external_libcall (fun)
1770      rtx fun ATTRIBUTE_UNUSED;
1771 {
1772 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1773   /* Declare library function name external when first used, if nec.  */
1774   if (! SYMBOL_REF_USED (fun))
1775     {
1776       SYMBOL_REF_USED (fun) = 1;
1777       ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1778     }
1779 #endif
1780 }
1781
1782 /* Declare the label NAME global.  */
1783
1784 void
1785 assemble_global (name)
1786      const char *name ATTRIBUTE_UNUSED;
1787 {
1788   ASM_GLOBALIZE_LABEL (asm_out_file, name);
1789 }
1790
1791 /* Assemble a label named NAME.  */
1792
1793 void
1794 assemble_label (name)
1795      const char *name;
1796 {
1797   ASM_OUTPUT_LABEL (asm_out_file, name);
1798 }
1799
1800 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1801    If NAME starts with a *, the rest of NAME is output verbatim.
1802    Otherwise NAME is transformed in an implementation-defined way
1803    (usually by the addition of an underscore).
1804    Many macros in the tm file are defined to call this function.  */
1805
1806 void
1807 assemble_name (file, name)
1808      FILE *file;
1809      const char *name;
1810 {
1811   const char *real_name;
1812   tree id;
1813
1814   STRIP_NAME_ENCODING (real_name, name);
1815
1816   id = maybe_get_identifier (real_name);
1817   if (id)
1818     TREE_SYMBOL_REFERENCED (id) = 1;
1819
1820   if (name[0] == '*')
1821     fputs (&name[1], file);
1822   else
1823     ASM_OUTPUT_LABELREF (file, name);
1824 }
1825
1826 /* Allocate SIZE bytes writable static space with a gensym name
1827    and return an RTX to refer to its address.  */
1828
1829 rtx
1830 assemble_static_space (size)
1831      int size;
1832 {
1833   char name[12];
1834   const char *namestring;
1835   rtx x;
1836
1837 #if 0
1838   if (flag_shared_data)
1839     data_section ();
1840 #endif
1841
1842   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1843   ++const_labelno;
1844   namestring = ggc_strdup (name);
1845
1846   x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1847
1848 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1849   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1850                                  BIGGEST_ALIGNMENT);
1851 #else
1852 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1853   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1854 #else
1855   {
1856     /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1857        so that each uninitialized object starts on such a boundary.  */
1858     /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL.  */
1859     int rounded ATTRIBUTE_UNUSED
1860       = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1861          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1862          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1863     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1864   }
1865 #endif
1866 #endif
1867   return x;
1868 }
1869
1870 /* Assemble the static constant template for function entry trampolines.
1871    This is done at most once per compilation.
1872    Returns an RTX for the address of the template.  */
1873
1874 #ifdef TRAMPOLINE_TEMPLATE
1875 rtx
1876 assemble_trampoline_template ()
1877 {
1878   char label[256];
1879   const char *name;
1880   int align;
1881
1882   /* By default, put trampoline templates in read-only data section.  */
1883
1884 #ifdef TRAMPOLINE_SECTION
1885   TRAMPOLINE_SECTION ();
1886 #else
1887   readonly_data_section ();
1888 #endif
1889
1890   /* Write the assembler code to define one.  */
1891   align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1892   if (align > 0)
1893     {
1894       ASM_OUTPUT_ALIGN (asm_out_file, align);
1895     }
1896
1897   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1898   TRAMPOLINE_TEMPLATE (asm_out_file);
1899
1900   /* Record the rtl to refer to it.  */
1901   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1902   name = ggc_strdup (label);
1903   return gen_rtx_SYMBOL_REF (Pmode, name);
1904 }
1905 #endif
1906 \f
1907 /* A and B are either alignments or offsets.  Return the minimum alignment
1908    that may be assumed after adding the two together.  */
1909
1910 static inline unsigned
1911 min_align (a, b)
1912      unsigned int a, b;
1913 {
1914   return (a | b) & -(a | b);
1915 }
1916
1917 /* Return the assembler directive for creating a given kind of integer
1918    object.  SIZE is the number of bytes in the object and ALIGNED_P
1919    indicates whether it is known to be aligned.  Return NULL if the
1920    assembly dialect has no such directive.
1921
1922    The returned string should be printed at the start of a new line and
1923    be followed immediately by the object's initial value.  */
1924
1925 const char *
1926 integer_asm_op (size, aligned_p)
1927      int size;
1928      int aligned_p;
1929 {
1930   struct asm_int_op *ops;
1931
1932   if (aligned_p)
1933     ops = &targetm.asm_out.aligned_op;
1934   else
1935     ops = &targetm.asm_out.unaligned_op;
1936
1937   switch (size)
1938     {
1939     case 1:
1940       return targetm.asm_out.byte_op;
1941     case 2:
1942       return ops->hi;
1943     case 4:
1944       return ops->si;
1945     case 8:
1946       return ops->di;
1947     case 16:
1948       return ops->ti;
1949     default:
1950       return NULL;
1951     }
1952 }
1953
1954 /* Use directive OP to assemble an integer object X.  Print OP at the
1955    start of the line, followed immediately by the value of X.  */
1956
1957 void
1958 assemble_integer_with_op (op, x)
1959      const char *op;
1960      rtx x;
1961 {
1962   fputs (op, asm_out_file);
1963   output_addr_const (asm_out_file, x);
1964   fputc ('\n', asm_out_file);
1965 }
1966
1967 /* The default implementation of the asm_out.integer target hook.  */
1968
1969 bool
1970 default_assemble_integer (x, size, aligned_p)
1971      rtx x ATTRIBUTE_UNUSED;
1972      unsigned int size ATTRIBUTE_UNUSED;
1973      int aligned_p ATTRIBUTE_UNUSED;
1974 {
1975   const char *op = integer_asm_op (size, aligned_p);
1976   return op && (assemble_integer_with_op (op, x), true);
1977 }
1978
1979 /* Assemble the integer constant X into an object of SIZE bytes.  ALIGN is
1980    the alignment of the integer in bits.  Return 1 if we were able to output
1981    the constant, otherwise 0.  If FORCE is non-zero, abort if we can't output
1982    the constant.  */
1983
1984 bool
1985 assemble_integer (x, size, align, force)
1986      rtx x;
1987      unsigned int size;
1988      unsigned int align;
1989      int force;
1990 {
1991   int aligned_p;
1992
1993   aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1994
1995   /* See if the target hook can handle this kind of object.  */
1996   if ((*targetm.asm_out.integer) (x, size, aligned_p))
1997     return true;
1998
1999   /* If the object is a multi-byte one, try splitting it up.  Split
2000      it into words it if is multi-word, otherwise split it into bytes.  */
2001   if (size > 1)
2002     {
2003       enum machine_mode omode, imode;
2004       unsigned int subalign;
2005       unsigned int subsize, i;
2006
2007       subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2008       subalign = MIN (align, subsize * BITS_PER_UNIT);
2009       omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2010       imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2011
2012       for (i = 0; i < size; i += subsize)
2013         {
2014           rtx partial = simplify_subreg (omode, x, imode, i);
2015           if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2016             break;
2017         }
2018       if (i == size)
2019         return true;
2020
2021       /* If we've printed some of it, but not all of it, there's no going
2022          back now.  */
2023       if (i > 0)
2024         abort ();
2025     }
2026
2027   if (force)
2028     abort ();
2029
2030   return false;
2031 }
2032 \f
2033 void
2034 assemble_real (d, mode, align)
2035      REAL_VALUE_TYPE d;
2036      enum machine_mode mode;
2037      unsigned int align;
2038 {
2039   long data[4];
2040   long l;
2041   unsigned int nalign = min_align (align, 32);
2042
2043   switch (BITS_PER_UNIT)
2044     {
2045     case 8:
2046       switch (mode)
2047         {
2048         case SFmode:
2049           REAL_VALUE_TO_TARGET_SINGLE (d, l);
2050           assemble_integer (GEN_INT (l), 4, align, 1);
2051           break;
2052         case DFmode:
2053           REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2054           assemble_integer (GEN_INT (data[0]), 4, align, 1);
2055           assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2056           break;
2057         case XFmode:
2058           REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2059           assemble_integer (GEN_INT (data[0]), 4, align, 1);
2060           assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2061           assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2062           break;
2063         case TFmode:
2064           REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2065           assemble_integer (GEN_INT (data[0]), 4, align, 1);
2066           assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2067           assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2068           assemble_integer (GEN_INT (data[3]), 4, nalign, 1);
2069           break;
2070         default:
2071           abort ();
2072         }
2073       break;
2074
2075     case 16:
2076       switch (mode)
2077         {
2078         case HFmode:
2079           REAL_VALUE_TO_TARGET_SINGLE (d, l);
2080           assemble_integer (GEN_INT (l), 2, align, 1);
2081           break;
2082         case TQFmode:
2083           REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2084           assemble_integer (GEN_INT (data[0]), 2, align, 1);
2085           assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2086           break;
2087         default:
2088           abort ();
2089         }
2090       break;
2091
2092     case 32:
2093       switch (mode)
2094         {
2095         case QFmode:
2096           REAL_VALUE_TO_TARGET_SINGLE (d, l);
2097           assemble_integer (GEN_INT (l), 1, align, 1);
2098           break;
2099         case HFmode:
2100           REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2101           assemble_integer (GEN_INT (data[0]), 1, align, 1);
2102           assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2103           break;
2104         default:
2105           abort ();
2106         }
2107       break;
2108
2109     default:
2110       abort ();
2111     }
2112 }
2113 \f
2114 /* Here we combine duplicate floating constants to make
2115    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
2116
2117 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2118    For an integer, I0 is the low-order word and I1 is the high-order word.
2119    For a real number, I0 is the word with the low address
2120    and I1 is the word with the high address.  */
2121
2122 rtx
2123 immed_double_const (i0, i1, mode)
2124      HOST_WIDE_INT i0, i1;
2125      enum machine_mode mode;
2126 {
2127   rtx r;
2128
2129   if (GET_MODE_CLASS (mode) == MODE_INT
2130       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2131     {
2132       /* We clear out all bits that don't belong in MODE, unless they and our
2133          sign bit are all one.  So we get either a reasonable negative value
2134          or a reasonable unsigned value for this mode.  */
2135       int width = GET_MODE_BITSIZE (mode);
2136       if (width < HOST_BITS_PER_WIDE_INT
2137           && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2138               != ((HOST_WIDE_INT) (-1) << (width - 1))))
2139         i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2140       else if (width == HOST_BITS_PER_WIDE_INT
2141                && ! (i1 == ~0 && i0 < 0))
2142         i1 = 0;
2143       else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2144         /* We cannot represent this value as a constant.  */
2145         abort ();
2146
2147       /* If this would be an entire word for the target, but is not for
2148          the host, then sign-extend on the host so that the number will look
2149          the same way on the host that it would on the target.
2150
2151          For example, when building a 64 bit alpha hosted 32 bit sparc
2152          targeted compiler, then we want the 32 bit unsigned value -1 to be
2153          represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2154          The later confuses the sparc backend.  */
2155
2156       if (width < HOST_BITS_PER_WIDE_INT
2157           && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2158         i0 |= ((HOST_WIDE_INT) (-1) << width);
2159
2160       /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2161
2162          ??? Strictly speaking, this is wrong if we create a CONST_INT
2163          for a large unsigned constant with the size of MODE being
2164          HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2165          wider mode.  In that case we will mis-interpret it as a negative
2166          number.
2167
2168          Unfortunately, the only alternative is to make a CONST_DOUBLE
2169          for any constant in any mode if it is an unsigned constant larger
2170          than the maximum signed integer in an int on the host.  However,
2171          doing this will break everyone that always expects to see a CONST_INT
2172          for SImode and smaller.
2173
2174          We have always been making CONST_INTs in this case, so nothing new
2175          is being broken.  */
2176
2177       if (width <= HOST_BITS_PER_WIDE_INT)
2178         i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2179
2180       /* If this integer fits in one word, return a CONST_INT.  */
2181       if ((i1 == 0 && i0 >= 0)
2182           || (i1 == ~0 && i0 < 0))
2183         return GEN_INT (i0);
2184
2185       /* We use VOIDmode for integers.  */
2186       mode = VOIDmode;
2187     }
2188
2189   /* Search the chain for an existing CONST_DOUBLE with the right value.
2190      If one is found, return it.  */
2191   if (cfun != 0)
2192     for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2193       if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2194           && GET_MODE (r) == mode)
2195         return r;
2196
2197   /* No; make a new one and add it to the chain.  */
2198   r = gen_rtx_CONST_DOUBLE (mode, i0, i1);
2199
2200   /* Don't touch const_double_chain if not inside any function.  */
2201   if (current_function_decl != 0)
2202     {
2203       CONST_DOUBLE_CHAIN (r) = const_double_chain;
2204       const_double_chain = r;
2205     }
2206
2207   return r;
2208 }
2209
2210 /* Return a CONST_DOUBLE for a specified `double' value
2211    and machine mode.  */
2212
2213 rtx
2214 immed_real_const_1 (d, mode)
2215      REAL_VALUE_TYPE d;
2216      enum machine_mode mode;
2217 {
2218   union real_extract u;
2219   rtx r;
2220
2221   /* Get the desired `double' value as a sequence of ints
2222      since that is how they are stored in a CONST_DOUBLE.  */
2223
2224   u.d = d;
2225
2226   /* Detect special cases.  Check for NaN first, because some ports
2227      (specifically the i386) do not emit correct ieee-fp code by default, and
2228      thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2229      and if REAL_VALUES_EQUAL does a floating point comparison.  */
2230   if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_IDENTICAL (dconst0, d))
2231     return CONST0_RTX (mode);
2232   else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2233     return CONST1_RTX (mode);
2234   else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst2, d))
2235     return CONST2_RTX (mode);
2236
2237   if (sizeof u == sizeof (HOST_WIDE_INT))
2238     return immed_double_const (u.i[0], 0, mode);
2239   if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2240     return immed_double_const (u.i[0], u.i[1], mode);
2241
2242   /* The rest of this function handles the case where
2243      a float value requires more than 2 ints of space.
2244      It will be deleted as dead code on machines that don't need it.  */
2245
2246   /* Search the chain for an existing CONST_DOUBLE with the right value.
2247      If one is found, return it.  */
2248   if (cfun != 0)
2249     for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2250       if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2251           && GET_MODE (r) == mode)
2252         return r;
2253
2254   /* No; make a new one and add it to the chain.
2255
2256      We may be called by an optimizer which may be discarding any memory
2257      allocated during its processing (such as combine and loop).  However,
2258      we will be leaving this constant on the chain, so we cannot tolerate
2259      freed memory.  */
2260   r = rtx_alloc (CONST_DOUBLE);
2261   PUT_MODE (r, mode);
2262   memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2263
2264   /* If we aren't inside a function, don't put r on the
2265      const_double_chain.  */
2266   if (current_function_decl != 0)
2267     {
2268       CONST_DOUBLE_CHAIN (r) = const_double_chain;
2269       const_double_chain = r;
2270     }
2271   else
2272     CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2273
2274   return r;
2275 }
2276
2277 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2278    which must be a REAL_CST tree node.  */
2279
2280 rtx
2281 immed_real_const (exp)
2282      tree exp;
2283 {
2284   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2285 }
2286
2287 /* At the end of a function, forget the memory-constants
2288    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
2289    Also clear out real_constant_chain and clear out all the chain-pointers.  */
2290
2291 void
2292 clear_const_double_mem ()
2293 {
2294   rtx r, next;
2295
2296   for (r = const_double_chain; r; r = next)
2297     {
2298       next = CONST_DOUBLE_CHAIN (r);
2299       CONST_DOUBLE_CHAIN (r) = 0;
2300     }
2301   const_double_chain = 0;
2302 }
2303 \f
2304 /* Given an expression EXP with a constant value,
2305    reduce it to the sum of an assembler symbol and an integer.
2306    Store them both in the structure *VALUE.
2307    Abort if EXP does not reduce.  */
2308
2309 struct addr_const
2310 {
2311   rtx base;
2312   HOST_WIDE_INT offset;
2313 };
2314
2315 static void
2316 decode_addr_const (exp, value)
2317      tree exp;
2318      struct addr_const *value;
2319 {
2320   tree target = TREE_OPERAND (exp, 0);
2321   int offset = 0;
2322   rtx x;
2323
2324   while (1)
2325     {
2326       if (TREE_CODE (target) == COMPONENT_REF
2327           && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2328
2329         {
2330           offset += int_byte_position (TREE_OPERAND (target, 1));
2331           target = TREE_OPERAND (target, 0);
2332         }
2333       else if (TREE_CODE (target) == ARRAY_REF
2334                || TREE_CODE (target) == ARRAY_RANGE_REF)
2335         {
2336           offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2337                      * tree_low_cst (TREE_OPERAND (target, 1), 0));
2338           target = TREE_OPERAND (target, 0);
2339         }
2340       else
2341         break;
2342     }
2343
2344   switch (TREE_CODE (target))
2345     {
2346     case VAR_DECL:
2347     case FUNCTION_DECL:
2348       x = DECL_RTL (target);
2349       break;
2350
2351     case LABEL_DECL:
2352       x = gen_rtx_MEM (FUNCTION_MODE,
2353                        gen_rtx_LABEL_REF (VOIDmode,
2354                                           label_rtx (TREE_OPERAND (exp, 0))));
2355       break;
2356
2357     case REAL_CST:
2358     case STRING_CST:
2359     case COMPLEX_CST:
2360     case CONSTRUCTOR:
2361     case INTEGER_CST:
2362       /* This constant should have been output already, but we can't simply
2363          use TREE_CST_RTL since INTEGER_CST doesn't have one.  */
2364       x = output_constant_def (target, 1);
2365       break;
2366
2367     default:
2368       abort ();
2369     }
2370
2371   if (GET_CODE (x) != MEM)
2372     abort ();
2373   x = XEXP (x, 0);
2374
2375   value->base = x;
2376   value->offset = offset;
2377 }
2378 \f
2379 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC.  */
2380 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_INT, RTX_VECTOR, RTX_UNSPEC };
2381 struct rtx_const
2382 {
2383   ENUM_BITFIELD(kind) kind : 16;
2384   ENUM_BITFIELD(machine_mode) mode : 16;
2385   union {
2386     union real_extract du;
2387     struct addr_const addr;
2388     struct {HOST_WIDE_INT high, low;} di;
2389
2390     /* The max vector size we have is 8 wide.  This should be enough.  */
2391     HOST_WIDE_INT veclo[16];
2392     HOST_WIDE_INT vechi[16];
2393   } un;
2394 };
2395
2396 /* Uniquize all constants that appear in memory.
2397    Each constant in memory thus far output is recorded
2398    in `const_hash_table' with a `struct constant_descriptor'
2399    that contains a polish representation of the value of
2400    the constant.
2401
2402    We cannot store the trees in the hash table
2403    because the trees may be temporary.  */
2404
2405 struct constant_descriptor
2406 {
2407   struct constant_descriptor *next;
2408   const char *label;
2409   rtx rtl;
2410   /* Make sure the data is reasonably aligned.  */
2411   union
2412   {
2413     unsigned char contents[1];
2414 #ifdef HAVE_LONG_DOUBLE
2415     long double d;
2416 #else
2417     double d;
2418 #endif
2419   } u;
2420 };
2421
2422 #define HASHBITS 30
2423 #define MAX_HASH_TABLE 1009
2424 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2425
2426 /* We maintain a hash table of STRING_CST values.  Unless we are asked to force
2427    out a string constant, we defer output of the constants until we know
2428    they are actually used.  This will be if something takes its address or if
2429    there is a usage of the string in the RTL of a function.  */
2430
2431 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2432
2433 struct deferred_string
2434 {
2435   const char *label;
2436   tree exp;
2437   int labelno;
2438 };
2439
2440 static htab_t const_str_htab;
2441
2442 /* Mark a const_hash_table descriptor for GC.  */
2443
2444 static void
2445 mark_const_hash_entry (ptr)
2446      void *ptr;
2447 {
2448   struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2449
2450   while (desc)
2451     {
2452       ggc_mark_rtx (desc->rtl);
2453       desc = desc->next;
2454     }
2455 }
2456
2457 /* Mark the hash-table element X (which is really a pointer to an
2458    struct deferred_string *).  */
2459
2460 static int
2461 mark_const_str_htab_1 (x, data)
2462      void **x;
2463      void *data ATTRIBUTE_UNUSED;
2464 {
2465   ggc_mark_tree (((struct deferred_string *) *x)->exp);
2466   return 1;
2467 }
2468
2469 /* Mark a const_str_htab for GC.  */
2470
2471 static void
2472 mark_const_str_htab (htab)
2473      void *htab;
2474 {
2475   htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2476 }
2477
2478 /* Returns a hash code for X (which is a really a
2479    struct deferred_string *).  */
2480
2481 static hashval_t
2482 const_str_htab_hash (x)
2483      const void *x;
2484 {
2485   return STRHASH (((const struct deferred_string *) x)->label);
2486 }
2487
2488 /* Returns non-zero if the value represented by X (which is really a
2489    struct deferred_string *) is the same as that given by Y
2490    (which is really a char *).  */
2491
2492 static int
2493 const_str_htab_eq (x, y)
2494      const void *x;
2495      const void *y;
2496 {
2497   return (((const struct deferred_string *) x)->label == (const char *) y);
2498 }
2499
2500 /* Delete the hash table entry dfsp.  */
2501
2502 static void
2503 const_str_htab_del (dfsp)
2504     void *dfsp;
2505 {
2506   free (dfsp);
2507 }
2508
2509 /* Compute a hash code for a constant expression.  */
2510
2511 static int
2512 const_hash (exp)
2513      tree exp;
2514 {
2515   const char *p;
2516   int len, hi, i;
2517   enum tree_code code = TREE_CODE (exp);
2518
2519   /* Either set P and LEN to the address and len of something to hash and
2520      exit the switch or return a value.  */
2521
2522   switch (code)
2523     {
2524     case INTEGER_CST:
2525       p = (char *) &TREE_INT_CST (exp);
2526       len = sizeof TREE_INT_CST (exp);
2527       break;
2528
2529     case REAL_CST:
2530       p = (char *) &TREE_REAL_CST (exp);
2531       len = sizeof TREE_REAL_CST (exp);
2532       break;
2533
2534     case STRING_CST:
2535       p = TREE_STRING_POINTER (exp);
2536       len = TREE_STRING_LENGTH (exp);
2537       break;
2538
2539     case COMPLEX_CST:
2540       return (const_hash (TREE_REALPART (exp)) * 5
2541               + const_hash (TREE_IMAGPART (exp)));
2542
2543     case CONSTRUCTOR:
2544       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2545         {
2546           char *tmp;
2547
2548           len = int_size_in_bytes (TREE_TYPE (exp));
2549           tmp = (char *) alloca (len);
2550           get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2551           p = tmp;
2552           break;
2553         }
2554       else
2555         {
2556           tree link;
2557
2558           /* For record type, include the type in the hashing.
2559              We do not do so for array types
2560              because (1) the sizes of the elements are sufficient
2561              and (2) distinct array types can have the same constructor.
2562              Instead, we include the array size because the constructor could
2563              be shorter.  */
2564           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2565             hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2566               % MAX_HASH_TABLE;
2567           else
2568             hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2569                   & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2570
2571           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2572             if (TREE_VALUE (link))
2573               hi
2574                 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2575
2576           return hi;
2577         }
2578
2579     case ADDR_EXPR:
2580       {
2581         struct addr_const value;
2582
2583         decode_addr_const (exp, &value);
2584         if (GET_CODE (value.base) == SYMBOL_REF)
2585           {
2586             /* Don't hash the address of the SYMBOL_REF;
2587                only use the offset and the symbol name.  */
2588             hi = value.offset;
2589             p = XSTR (value.base, 0);
2590             for (i = 0; p[i] != 0; i++)
2591               hi = ((hi * 613) + (unsigned) (p[i]));
2592           }
2593         else if (GET_CODE (value.base) == LABEL_REF)
2594           hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2595         else
2596           abort ();
2597
2598         hi &= (1 << HASHBITS) - 1;
2599         hi %= MAX_HASH_TABLE;
2600       }
2601       return hi;
2602
2603     case PLUS_EXPR:
2604     case MINUS_EXPR:
2605       return (const_hash (TREE_OPERAND (exp, 0)) * 9
2606               + const_hash (TREE_OPERAND (exp, 1)));
2607
2608     case NOP_EXPR:
2609     case CONVERT_EXPR:
2610     case NON_LVALUE_EXPR:
2611       return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2612
2613     default:
2614       /* A language specific constant. Just hash the code.  */
2615       return (int) code % MAX_HASH_TABLE;
2616     }
2617
2618   /* Compute hashing function */
2619   hi = len;
2620   for (i = 0; i < len; i++)
2621     hi = ((hi * 613) + (unsigned) (p[i]));
2622
2623   hi &= (1 << HASHBITS) - 1;
2624   hi %= MAX_HASH_TABLE;
2625   return hi;
2626 }
2627 \f
2628 /* Compare a constant expression EXP with a constant-descriptor DESC.
2629    Return 1 if DESC describes a constant with the same value as EXP.  */
2630
2631 static int
2632 compare_constant (exp, desc)
2633      tree exp;
2634      struct constant_descriptor *desc;
2635 {
2636   return 0 != compare_constant_1 (exp, desc->u.contents);
2637 }
2638
2639 /* Compare constant expression EXP with a substring P of a constant descriptor.
2640    If they match, return a pointer to the end of the substring matched.
2641    If they do not match, return 0.
2642
2643    Since descriptors are written in polish prefix notation,
2644    this function can be used recursively to test one operand of EXP
2645    against a subdescriptor, and if it succeeds it returns the
2646    address of the subdescriptor for the next operand.  */
2647
2648 static const unsigned char *
2649 compare_constant_1 (exp, p)
2650      tree exp;
2651      const unsigned char *p;
2652 {
2653   const unsigned char *strp;
2654   int len;
2655   enum tree_code code = TREE_CODE (exp);
2656
2657   if (code != (enum tree_code) *p++)
2658     return 0;
2659
2660   /* Either set STRP, P and LEN to pointers and length to compare and exit the
2661      switch, or return the result of the comparison.  */
2662
2663   switch (code)
2664     {
2665     case INTEGER_CST:
2666       /* Integer constants are the same only if the same width of type.  */
2667       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2668         return 0;
2669
2670       strp = (unsigned char *) &TREE_INT_CST (exp);
2671       len = sizeof TREE_INT_CST (exp);
2672       break;
2673
2674     case REAL_CST:
2675       /* Real constants are the same only if the same width of type.  */
2676       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2677         return 0;
2678
2679       strp = (unsigned char *) &TREE_REAL_CST (exp);
2680       len = sizeof TREE_REAL_CST (exp);
2681       break;
2682
2683     case STRING_CST:
2684       if (flag_writable_strings)
2685         return 0;
2686
2687       if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2688         return 0;
2689
2690       strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2691       len = TREE_STRING_LENGTH (exp);
2692       if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2693                   sizeof TREE_STRING_LENGTH (exp)))
2694         return 0;
2695
2696       p += sizeof TREE_STRING_LENGTH (exp);
2697       break;
2698
2699     case COMPLEX_CST:
2700       p = compare_constant_1 (TREE_REALPART (exp), p);
2701       if (p == 0)
2702         return 0;
2703
2704       return compare_constant_1 (TREE_IMAGPART (exp), p);
2705
2706     case CONSTRUCTOR:
2707       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2708         {
2709           int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2710           unsigned char *tmp = (unsigned char *) alloca (len);
2711
2712           get_set_constructor_bytes (exp, tmp, len);
2713           strp = (unsigned char *) tmp;
2714           if (memcmp ((char *) &xlen, p, sizeof xlen))
2715             return 0;
2716
2717           p += sizeof xlen;
2718           break;
2719         }
2720       else
2721         {
2722           tree link;
2723           int length = list_length (CONSTRUCTOR_ELTS (exp));
2724           tree type;
2725           enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2726           int have_purpose = 0;
2727
2728           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2729             if (TREE_PURPOSE (link))
2730               have_purpose = 1;
2731
2732           if (memcmp ((char *) &length, p, sizeof length))
2733             return 0;
2734
2735           p += sizeof length;
2736
2737           /* For record constructors, insist that the types match.
2738              For arrays, just verify both constructors are for arrays.
2739              Then insist that either both or none have any TREE_PURPOSE
2740              values.  */
2741           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2742             type = TREE_TYPE (exp);
2743           else
2744             type = 0;
2745
2746           if (memcmp ((char *) &type, p, sizeof type))
2747             return 0;
2748
2749           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2750             {
2751               if (memcmp ((char *) &mode, p, sizeof mode))
2752                 return 0;
2753
2754               p += sizeof mode;
2755             }
2756
2757           p += sizeof type;
2758
2759           if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2760             return 0;
2761
2762           p += sizeof have_purpose;
2763
2764           /* For arrays, insist that the size in bytes match.  */
2765           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2766             {
2767               HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2768
2769               if (memcmp ((char *) &size, p, sizeof size))
2770                 return 0;
2771
2772               p += sizeof size;
2773             }
2774
2775           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2776             {
2777               if (TREE_VALUE (link))
2778                 {
2779                   if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2780                     return 0;
2781                 }
2782               else
2783                 {
2784                   tree zero = 0;
2785
2786                   if (memcmp ((char *) &zero, p, sizeof zero))
2787                     return 0;
2788
2789                   p += sizeof zero;
2790                 }
2791
2792               if (TREE_PURPOSE (link)
2793                   && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2794                 {
2795                   if (memcmp ((char *) &TREE_PURPOSE (link), p,
2796                             sizeof TREE_PURPOSE (link)))
2797                     return 0;
2798
2799                   p += sizeof TREE_PURPOSE (link);
2800                 }
2801               else if (TREE_PURPOSE (link))
2802                 {
2803                   if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2804                     return 0;
2805                 }
2806               else if (have_purpose)
2807                 {
2808                   int zero = 0;
2809
2810                   if (memcmp ((char *) &zero, p, sizeof zero))
2811                     return 0;
2812
2813                   p += sizeof zero;
2814                 }
2815             }
2816
2817           return p;
2818         }
2819
2820     case ADDR_EXPR:
2821       {
2822         struct addr_const value;
2823
2824         decode_addr_const (exp, &value);
2825         strp = (unsigned char *) &value.offset;
2826         len = sizeof value.offset;
2827         /* Compare the offset.  */
2828         while (--len >= 0)
2829           if (*p++ != *strp++)
2830             return 0;
2831
2832         /* Compare symbol name.  */
2833         strp = (const unsigned char *) XSTR (value.base, 0);
2834         len = strlen ((const char *) strp) + 1;
2835       }
2836       break;
2837
2838     case PLUS_EXPR:
2839     case MINUS_EXPR:
2840     case RANGE_EXPR:
2841       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2842       if (p == 0)
2843         return 0;
2844
2845       return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2846
2847     case NOP_EXPR:
2848     case CONVERT_EXPR:
2849     case NON_LVALUE_EXPR:
2850       return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2851
2852     default:
2853       {
2854         tree new = (*lang_hooks.expand_constant) (exp);
2855
2856         if (new != exp)
2857           return compare_constant_1 (new, p);
2858         else
2859           return 0;
2860       }
2861     }
2862
2863   /* Compare constant contents.  */
2864   while (--len >= 0)
2865     if (*p++ != *strp++)
2866       return 0;
2867
2868   return p;
2869 }
2870 \f
2871 /* Construct a constant descriptor for the expression EXP.
2872    It is up to the caller to enter the descriptor in the hash table.  */
2873
2874 static struct constant_descriptor *
2875 record_constant (exp)
2876      tree exp;
2877 {
2878   struct constant_descriptor *next = 0;
2879   char *label = 0;
2880   rtx rtl = 0;
2881   int pad;
2882
2883   /* Make a struct constant_descriptor.  The first three pointers will
2884      be filled in later.  Here we just leave space for them.  */
2885
2886   obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2887   obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2888   obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2889
2890   /* Align the descriptor for the data payload.  */
2891   pad = (offsetof (struct constant_descriptor, u)
2892          - offsetof(struct constant_descriptor, rtl)
2893          - sizeof(next->rtl));
2894   if (pad > 0)
2895     obstack_blank (&permanent_obstack, pad);
2896
2897   record_constant_1 (exp);
2898   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2899 }
2900
2901 /* Add a description of constant expression EXP
2902    to the object growing in `permanent_obstack'.
2903    No need to return its address; the caller will get that
2904    from the obstack when the object is complete.  */
2905
2906 static void
2907 record_constant_1 (exp)
2908      tree exp;
2909 {
2910   const unsigned char *strp;
2911   int len;
2912   enum tree_code code = TREE_CODE (exp);
2913
2914   obstack_1grow (&permanent_obstack, (unsigned int) code);
2915
2916   switch (code)
2917     {
2918     case INTEGER_CST:
2919       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2920       strp = (unsigned char *) &TREE_INT_CST (exp);
2921       len = sizeof TREE_INT_CST (exp);
2922       break;
2923
2924     case REAL_CST:
2925       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2926       strp = (unsigned char *) &TREE_REAL_CST (exp);
2927       len = sizeof TREE_REAL_CST (exp);
2928       break;
2929
2930     case STRING_CST:
2931       if (flag_writable_strings)
2932         return;
2933
2934       obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2935       strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2936       len = TREE_STRING_LENGTH (exp);
2937       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2938                     sizeof TREE_STRING_LENGTH (exp));
2939       break;
2940
2941     case COMPLEX_CST:
2942       record_constant_1 (TREE_REALPART (exp));
2943       record_constant_1 (TREE_IMAGPART (exp));
2944       return;
2945
2946     case CONSTRUCTOR:
2947       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2948         {
2949           int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2950           obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2951           obstack_blank (&permanent_obstack, nbytes);
2952           get_set_constructor_bytes
2953             (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2954              nbytes);
2955           return;
2956         }
2957       else
2958         {
2959           tree link;
2960           int length = list_length (CONSTRUCTOR_ELTS (exp));
2961           enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2962           tree type;
2963           int have_purpose = 0;
2964
2965           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2966             if (TREE_PURPOSE (link))
2967               have_purpose = 1;
2968
2969           obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2970
2971           /* For record constructors, insist that the types match.
2972              For arrays, just verify both constructors are for arrays
2973              of the same mode.  Then insist that either both or none
2974              have any TREE_PURPOSE values.  */
2975           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2976             type = TREE_TYPE (exp);
2977           else
2978             type = 0;
2979
2980           obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2981           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2982             obstack_grow (&permanent_obstack, &mode, sizeof mode);
2983
2984           obstack_grow (&permanent_obstack, (char *) &have_purpose,
2985                         sizeof have_purpose);
2986
2987           /* For arrays, insist that the size in bytes match.  */
2988           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2989             {
2990               HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2991               obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2992             }
2993
2994           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2995             {
2996               if (TREE_VALUE (link))
2997                 record_constant_1 (TREE_VALUE (link));
2998               else
2999                 {
3000                   tree zero = 0;
3001
3002                   obstack_grow (&permanent_obstack,
3003                                 (char *) &zero, sizeof zero);
3004                 }
3005
3006               if (TREE_PURPOSE (link)
3007                   && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
3008                 obstack_grow (&permanent_obstack,
3009                               (char *) &TREE_PURPOSE (link),
3010                               sizeof TREE_PURPOSE (link));
3011               else if (TREE_PURPOSE (link))
3012                 record_constant_1 (TREE_PURPOSE (link));
3013               else if (have_purpose)
3014                 {
3015                   int zero = 0;
3016
3017                   obstack_grow (&permanent_obstack,
3018                                 (char *) &zero, sizeof zero);
3019                 }
3020             }
3021         }
3022       return;
3023
3024     case ADDR_EXPR:
3025       {
3026         struct addr_const value;
3027
3028         decode_addr_const (exp, &value);
3029         /* Record the offset.  */
3030         obstack_grow (&permanent_obstack,
3031                       (char *) &value.offset, sizeof value.offset);
3032
3033         switch (GET_CODE (value.base))
3034           {
3035           case SYMBOL_REF:
3036             /* Record the symbol name.  */
3037             obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3038                           strlen (XSTR (value.base, 0)) + 1);
3039             break;
3040           case LABEL_REF:
3041             /* Record the address of the CODE_LABEL.  It may not have
3042                been emitted yet, so it's UID may be zero.  But pointer
3043                identity is good enough.  */
3044             obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3045                           sizeof (rtx));
3046             break;
3047           default:
3048             abort ();
3049           }
3050       }
3051       return;
3052
3053     case PLUS_EXPR:
3054     case MINUS_EXPR:
3055     case RANGE_EXPR:
3056       record_constant_1 (TREE_OPERAND (exp, 0));
3057       record_constant_1 (TREE_OPERAND (exp, 1));
3058       return;
3059
3060     case NOP_EXPR:
3061     case CONVERT_EXPR:
3062     case NON_LVALUE_EXPR:
3063       record_constant_1 (TREE_OPERAND (exp, 0));
3064       return;
3065
3066     default:
3067       {
3068         tree new = (*lang_hooks.expand_constant) (exp);
3069
3070         if (new != exp)
3071           record_constant_1 (new);
3072         return;
3073       }
3074     }
3075
3076   /* Record constant contents.  */
3077   obstack_grow (&permanent_obstack, strp, len);
3078 }
3079 \f
3080 /* Record a list of constant expressions that were passed to
3081    output_constant_def but that could not be output right away.  */
3082
3083 struct deferred_constant
3084 {
3085   struct deferred_constant *next;
3086   tree exp;
3087   int reloc;
3088   int labelno;
3089 };
3090
3091 static struct deferred_constant *deferred_constants;
3092
3093 /* Another list of constants which should be output after the
3094    function.  */
3095 static struct deferred_constant *after_function_constants;
3096
3097 /* Nonzero means defer output of addressed subconstants
3098    (i.e., those for which output_constant_def is called.)  */
3099 static int defer_addressed_constants_flag;
3100
3101 /* Start deferring output of subconstants.  */
3102
3103 void
3104 defer_addressed_constants ()
3105 {
3106   defer_addressed_constants_flag++;
3107 }
3108
3109 /* Stop deferring output of subconstants,
3110    and output now all those that have been deferred.  */
3111
3112 void
3113 output_deferred_addressed_constants ()
3114 {
3115   struct deferred_constant *p, *next;
3116
3117   defer_addressed_constants_flag--;
3118
3119   if (defer_addressed_constants_flag > 0)
3120     return;
3121
3122   for (p = deferred_constants; p; p = next)
3123     {
3124       output_constant_def_contents (p->exp, p->reloc, p->labelno);
3125       next = p->next;
3126       free (p);
3127     }
3128
3129   deferred_constants = 0;
3130 }
3131
3132 /* Output any constants which should appear after a function.  */
3133
3134 static void
3135 output_after_function_constants ()
3136 {
3137   struct deferred_constant *p, *next;
3138
3139   for (p = after_function_constants; p; p = next)
3140     {
3141       output_constant_def_contents (p->exp, p->reloc, p->labelno);
3142       next = p->next;
3143       free (p);
3144     }
3145
3146   after_function_constants = 0;
3147 }
3148
3149 /* Make a copy of the whole tree structure for a constant.
3150    This handles the same types of nodes that compare_constant
3151    and record_constant handle.  */
3152
3153 static tree
3154 copy_constant (exp)
3155      tree exp;
3156 {
3157   switch (TREE_CODE (exp))
3158     {
3159     case ADDR_EXPR:
3160       /* For ADDR_EXPR, we do not want to copy the decl whose address
3161          is requested.  We do want to copy constants though.  */
3162       if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3163         return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3164                        copy_constant (TREE_OPERAND (exp, 0)));
3165       else
3166         return copy_node (exp);
3167
3168     case INTEGER_CST:
3169     case REAL_CST:
3170     case STRING_CST:
3171       return copy_node (exp);
3172
3173     case COMPLEX_CST:
3174       return build_complex (TREE_TYPE (exp),
3175                             copy_constant (TREE_REALPART (exp)),
3176                             copy_constant (TREE_IMAGPART (exp)));
3177
3178     case PLUS_EXPR:
3179     case MINUS_EXPR:
3180       return build (TREE_CODE (exp), TREE_TYPE (exp),
3181                     copy_constant (TREE_OPERAND (exp, 0)),
3182                     copy_constant (TREE_OPERAND (exp, 1)));
3183
3184     case NOP_EXPR:
3185     case CONVERT_EXPR:
3186     case NON_LVALUE_EXPR:
3187       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3188                      copy_constant (TREE_OPERAND (exp, 0)));
3189
3190     case CONSTRUCTOR:
3191       {
3192         tree copy = copy_node (exp);
3193         tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3194         tree tail;
3195
3196         CONSTRUCTOR_ELTS (copy) = list;
3197         for (tail = list; tail; tail = TREE_CHAIN (tail))
3198           TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3199         if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3200           for (tail = list; tail; tail = TREE_CHAIN (tail))
3201             TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3202
3203         return copy;
3204       }
3205
3206     default:
3207       abort ();
3208     }
3209 }
3210 \f
3211 /* Return an rtx representing a reference to constant data in memory
3212    for the constant expression EXP.
3213
3214    If assembler code for such a constant has already been output,
3215    return an rtx to refer to it.
3216    Otherwise, output such a constant in memory (or defer it for later)
3217    and generate an rtx for it.
3218
3219    If DEFER is non-zero, the output of string constants can be deferred
3220    and output only if referenced in the function after all optimizations.
3221
3222    The TREE_CST_RTL of EXP is set up to point to that rtx.
3223    The const_hash_table records which constants already have label strings.  */
3224
3225 rtx
3226 output_constant_def (exp, defer)
3227      tree exp;
3228      int defer;
3229 {
3230   int hash;
3231   struct constant_descriptor *desc;
3232   struct deferred_string **defstr;
3233   char label[256];
3234   int reloc;
3235   int found = 1;
3236   int after_function = 0;
3237   int labelno = -1;
3238   rtx rtl;
3239
3240   /* We can't just use the saved RTL if this is a defererred string constant
3241      and we are not to defer anymode.  */
3242   if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3243       && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3244     return TREE_CST_RTL (exp);
3245
3246   /* Make sure any other constants whose addresses appear in EXP
3247      are assigned label numbers.  */
3248
3249   reloc = output_addressed_constants (exp);
3250
3251   /* Compute hash code of EXP.  Search the descriptors for that hash code
3252      to see if any of them describes EXP.  If yes, the descriptor records
3253      the label number already assigned.  */
3254
3255   hash = const_hash (exp) % MAX_HASH_TABLE;
3256
3257   for (desc = const_hash_table[hash]; desc; desc = desc->next)
3258     if (compare_constant (exp, desc))
3259       break;
3260
3261   if (desc == 0)
3262     {
3263       /* No constant equal to EXP is known to have been output.
3264          Make a constant descriptor to enter EXP in the hash table.
3265          Assign the label number and record it in the descriptor for
3266          future calls to this function to find.  */
3267
3268       /* Create a string containing the label name, in LABEL.  */
3269       labelno = const_labelno++;
3270       ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3271
3272       desc = record_constant (exp);
3273       desc->next = const_hash_table[hash];
3274       desc->label = ggc_strdup (label);
3275       const_hash_table[hash] = desc;
3276
3277       /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
3278       rtl = desc->rtl
3279         = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3280                        gen_rtx_SYMBOL_REF (Pmode, desc->label));
3281
3282       set_mem_attributes (rtl, exp, 1);
3283       set_mem_alias_set (rtl, 0);
3284       set_mem_alias_set (rtl, const_alias_set);
3285
3286       found = 0;
3287     }
3288   else
3289     rtl = desc->rtl;
3290
3291   if (TREE_CODE (exp) != INTEGER_CST)
3292     TREE_CST_RTL (exp) = rtl;
3293
3294   /* Optionally set flags or add text to the name to record information
3295      such as that it is a function name.  If the name is changed, the macro
3296      ASM_OUTPUT_LABELREF will have to know how to strip this information.  */
3297 #ifdef ENCODE_SECTION_INFO
3298   /* A previously-processed constant would already have section info
3299      encoded in it.  */
3300   if (! found)
3301     {
3302       if (TREE_CODE (exp) == INTEGER_CST)
3303         ENCODE_SECTION_INFO (exp, true);
3304
3305       desc->rtl = rtl;
3306       desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3307     }
3308 #endif
3309
3310 #ifdef CONSTANT_AFTER_FUNCTION_P
3311   if (current_function_decl != 0
3312       && CONSTANT_AFTER_FUNCTION_P (exp))
3313     after_function = 1;
3314 #endif
3315
3316   if (found
3317       && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3318       && (!defer || defer_addressed_constants_flag || after_function))
3319     {
3320       defstr = (struct deferred_string **)
3321         htab_find_slot_with_hash (const_str_htab, desc->label,
3322                                   STRHASH (desc->label), NO_INSERT);
3323       if (defstr)
3324         {
3325           /* If the string is currently deferred but we need to output it now,
3326              remove it from deferred string hash table.  */
3327           found = 0;
3328           labelno = (*defstr)->labelno;
3329           STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3330           htab_clear_slot (const_str_htab, (void **) defstr);
3331         }
3332     }
3333
3334   /* If this is the first time we've seen this particular constant,
3335      output it (or defer its output for later).  */
3336   if (! found)
3337     {
3338       if (defer_addressed_constants_flag || after_function)
3339         {
3340           struct deferred_constant *p
3341             = (struct deferred_constant *)
3342               xmalloc (sizeof (struct deferred_constant));
3343
3344           p->exp = copy_constant (exp);
3345           p->reloc = reloc;
3346           p->labelno = labelno;
3347           if (after_function)
3348             {
3349               p->next = after_function_constants;
3350               after_function_constants = p;
3351             }
3352           else
3353             {
3354               p->next = deferred_constants;
3355               deferred_constants = p;
3356             }
3357         }
3358       else
3359         {
3360           /* Do no output if -fsyntax-only.  */
3361           if (! flag_syntax_only)
3362             {
3363               if (TREE_CODE (exp) != STRING_CST
3364                   || !defer
3365                   || flag_writable_strings
3366                   || (defstr = (struct deferred_string **)
3367                                htab_find_slot_with_hash (const_str_htab,
3368                                                          desc->label,
3369                                                          STRHASH (desc->label),
3370                                                          INSERT)) == NULL)
3371                 output_constant_def_contents (exp, reloc, labelno);
3372               else
3373                 {
3374                   struct deferred_string *p;
3375
3376                   p = (struct deferred_string *)
3377                       xmalloc (sizeof (struct deferred_string));
3378
3379                   p->exp = copy_constant (exp);
3380                   p->label = desc->label;
3381                   p->labelno = labelno;
3382                   *defstr = p;
3383                   STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3384                 }
3385             }
3386         }
3387     }
3388
3389   return rtl;
3390 }
3391
3392 /* Now output assembler code to define the label for EXP,
3393    and follow it with the data of EXP.  */
3394
3395 static void
3396 output_constant_def_contents (exp, reloc, labelno)
3397      tree exp;
3398      int reloc;
3399      int labelno;
3400 {
3401   int align;
3402
3403   /* Align the location counter as required by EXP's data type.  */
3404   align = TYPE_ALIGN (TREE_TYPE (exp));
3405 #ifdef CONSTANT_ALIGNMENT
3406   align = CONSTANT_ALIGNMENT (exp, align);
3407 #endif
3408
3409   if (IN_NAMED_SECTION (exp))
3410     named_section (exp, NULL, reloc);
3411   else
3412     {
3413       /* First switch to text section, except for writable strings.  */
3414 #ifdef SELECT_SECTION
3415       SELECT_SECTION (exp, reloc, align);
3416 #else
3417       if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3418           || (flag_pic && reloc))
3419         data_section ();
3420       else
3421         readonly_data_section ();
3422 #endif
3423     }
3424
3425   if (align > BITS_PER_UNIT)
3426     {
3427       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3428     }
3429
3430   /* Output the label itself.  */
3431   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3432
3433   /* Output the value of EXP.  */
3434   output_constant (exp,
3435                    (TREE_CODE (exp) == STRING_CST
3436                     ? MAX (TREE_STRING_LENGTH (exp),
3437                            int_size_in_bytes (TREE_TYPE (exp)))
3438                     : int_size_in_bytes (TREE_TYPE (exp))),
3439                    align);
3440
3441 }
3442 \f
3443 /* Structure to represent sufficient information about a constant so that
3444    it can be output when the constant pool is output, so that function
3445    integration can be done, and to simplify handling on machines that reference
3446    constant pool as base+displacement.  */
3447
3448 struct pool_constant
3449 {
3450   struct constant_descriptor *desc;
3451   struct pool_constant *next, *next_sym;
3452   rtx constant;
3453   enum machine_mode mode;
3454   int labelno;
3455   unsigned int align;
3456   HOST_WIDE_INT offset;
3457   int mark;
3458 };
3459
3460 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3461    The argument is XSTR (... , 0)  */
3462
3463 #define SYMHASH(LABEL)  \
3464   ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1))  % MAX_RTX_HASH_TABLE)
3465 \f
3466 /* Initialize constant pool hashing for a new function.  */
3467
3468 void
3469 init_varasm_status (f)
3470      struct function *f;
3471 {
3472   struct varasm_status *p;
3473   p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3474   f->varasm = p;
3475   p->x_const_rtx_hash_table
3476     = ((struct constant_descriptor **)
3477        xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3478   p->x_const_rtx_sym_hash_table
3479     = ((struct pool_constant **)
3480        xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3481
3482   p->x_first_pool = p->x_last_pool = 0;
3483   p->x_pool_offset = 0;
3484   p->x_const_double_chain = 0;
3485 }
3486
3487 /* Mark PC for GC.  */
3488
3489 static void
3490 mark_pool_constant (pc)
3491      struct pool_constant *pc;
3492 {
3493   while (pc)
3494     {
3495       ggc_mark (pc);
3496       ggc_mark_rtx (pc->constant);
3497       ggc_mark_rtx (pc->desc->rtl);
3498       pc = pc->next;
3499     }
3500 }
3501
3502 /* Mark P for GC.  */
3503
3504 void
3505 mark_varasm_status (p)
3506      struct varasm_status *p;
3507 {
3508   if (p == NULL)
3509     return;
3510
3511   mark_pool_constant (p->x_first_pool);
3512   ggc_mark_rtx (p->x_const_double_chain);
3513 }
3514
3515 /* Clear out all parts of the state in F that can safely be discarded
3516    after the function has been compiled, to let garbage collection
3517    reclaim the memory.  */
3518
3519 void
3520 free_varasm_status (f)
3521      struct function *f;
3522 {
3523   struct varasm_status *p;
3524   int i;
3525
3526   p = f->varasm;
3527
3528   /* Clear out the hash tables.  */
3529   for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3530     {
3531       struct constant_descriptor *cd;
3532
3533       cd = p->x_const_rtx_hash_table[i];
3534       while (cd)
3535         {
3536           struct constant_descriptor *next = cd->next;
3537
3538           free (cd);
3539           cd = next;
3540         }
3541     }
3542
3543   free (p->x_const_rtx_hash_table);
3544   free (p->x_const_rtx_sym_hash_table);
3545   free (p);
3546
3547   f->varasm = NULL;
3548 }
3549 \f
3550
3551 /* Express an rtx for a constant integer (perhaps symbolic)
3552    as the sum of a symbol or label plus an explicit integer.
3553    They are stored into VALUE.  */
3554
3555 static void
3556 decode_rtx_const (mode, x, value)
3557      enum machine_mode mode;
3558      rtx x;
3559      struct rtx_const *value;
3560 {
3561   /* Clear the whole structure, including any gaps.  */
3562   memset (value, 0, sizeof (struct rtx_const));
3563
3564   value->kind = RTX_INT;        /* Most usual kind.  */
3565   value->mode = mode;
3566
3567   switch (GET_CODE (x))
3568     {
3569     case CONST_DOUBLE:
3570       value->kind = RTX_DOUBLE;
3571       if (GET_MODE (x) != VOIDmode)
3572         {
3573           value->mode = GET_MODE (x);
3574           memcpy ((char *) &value->un.du,
3575                   (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3576         }
3577       else
3578         {
3579           value->un.di.low = CONST_DOUBLE_LOW (x);
3580           value->un.di.high = CONST_DOUBLE_HIGH (x);
3581         }
3582       break;
3583
3584     case CONST_VECTOR:
3585       {
3586         int units, i;
3587         rtx elt;
3588
3589         units = CONST_VECTOR_NUNITS (x);
3590         value->kind = RTX_VECTOR;
3591         value->mode = mode;
3592
3593         for (i = 0; i < units; ++i)
3594           {
3595             elt = CONST_VECTOR_ELT (x, i);
3596             if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
3597               {
3598                 value->un.veclo[i] = (HOST_WIDE_INT) INTVAL (elt);
3599                 value->un.vechi[i] = 0;
3600               }
3601             else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3602               {
3603                 value->un.veclo[i] = (HOST_WIDE_INT) CONST_DOUBLE_LOW (elt);
3604                 value->un.vechi[i] = (HOST_WIDE_INT) CONST_DOUBLE_HIGH (elt);
3605               }
3606             else
3607               abort ();
3608           }
3609       }
3610       break;
3611
3612     case CONST_INT:
3613       value->un.addr.offset = INTVAL (x);
3614       break;
3615
3616     case SYMBOL_REF:
3617     case LABEL_REF:
3618     case PC:
3619       value->un.addr.base = x;
3620       break;
3621
3622     case CONST:
3623       x = XEXP (x, 0);
3624       if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3625         {
3626           value->un.addr.base = XEXP (x, 0);
3627           value->un.addr.offset = INTVAL (XEXP (x, 1));
3628         }
3629       else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3630         {
3631           value->un.addr.base = XEXP (x, 0);
3632           value->un.addr.offset = - INTVAL (XEXP (x, 1));
3633         }
3634       else
3635         {
3636           value->un.addr.base = x;
3637           value->un.addr.offset = 0;
3638         }
3639       break;
3640
3641     default:
3642       value->kind = RTX_UNKNOWN;
3643       break;
3644     }
3645
3646   if (value->kind == RTX_INT && value->un.addr.base != 0
3647       && GET_CODE (value->un.addr.base) == UNSPEC)
3648     {      
3649       /* For a simple UNSPEC, the base is set to the
3650          operand, the kind field is set to the index of
3651          the unspec expression. 
3652          Together with the code below, in case that
3653          the operand is a SYMBOL_REF or LABEL_REF, 
3654          the address of the string or the code_label 
3655          is taken as base.  */
3656       if (XVECLEN (value->un.addr.base, 0) == 1)
3657         {
3658           value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
3659           value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
3660         }
3661     }
3662
3663   if (value->kind > RTX_DOUBLE && value->un.addr.base != 0)
3664     switch (GET_CODE (value->un.addr.base))
3665       {
3666       case SYMBOL_REF:
3667         /* Use the string's address, not the SYMBOL_REF's address,
3668            for the sake of addresses of library routines.  */
3669         value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3670         break;
3671
3672       case LABEL_REF:
3673         /* For a LABEL_REF, compare labels.  */
3674         value->un.addr.base = XEXP (value->un.addr.base, 0);
3675
3676       default:
3677         break;
3678       }
3679 }
3680
3681 /* Given a MINUS expression, simplify it if both sides
3682    include the same symbol.  */
3683
3684 rtx
3685 simplify_subtraction (x)
3686      rtx x;
3687 {
3688   struct rtx_const val0, val1;
3689
3690   decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3691   decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3692
3693   if (val0.kind > RTX_DOUBLE
3694       && val0.kind == val1.kind
3695       && val0.un.addr.base == val1.un.addr.base)
3696     return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3697
3698   return x;
3699 }
3700
3701 /* Compute a hash code for a constant RTL expression.  */
3702
3703 static int
3704 const_hash_rtx (mode, x)
3705      enum machine_mode mode;
3706      rtx x;
3707 {
3708   int hi;
3709   size_t i;
3710
3711   struct rtx_const value;
3712   decode_rtx_const (mode, x, &value);
3713
3714   /* Compute hashing function */
3715   hi = 0;
3716   for (i = 0; i < sizeof value / sizeof (int); i++)
3717     hi += ((int *) &value)[i];
3718
3719   hi &= (1 << HASHBITS) - 1;
3720   hi %= MAX_RTX_HASH_TABLE;
3721   return hi;
3722 }
3723
3724 /* Compare a constant rtl object X with a constant-descriptor DESC.
3725    Return 1 if DESC describes a constant with the same value as X.  */
3726
3727 static int
3728 compare_constant_rtx (mode, x, desc)
3729      enum machine_mode mode;
3730      rtx x;
3731      struct constant_descriptor *desc;
3732 {
3733   int *p = (int *) desc->u.contents;
3734   int *strp;
3735   int len;
3736   struct rtx_const value;
3737
3738   decode_rtx_const (mode, x, &value);
3739   strp = (int *) &value;
3740   len = sizeof value / sizeof (int);
3741
3742   /* Compare constant contents.  */
3743   while (--len >= 0)
3744     if (*p++ != *strp++)
3745       return 0;
3746
3747   return 1;
3748 }
3749
3750 /* Construct a constant descriptor for the rtl-expression X.
3751    It is up to the caller to enter the descriptor in the hash table.  */
3752
3753 static struct constant_descriptor *
3754 record_constant_rtx (mode, x)
3755      enum machine_mode mode;
3756      rtx x;
3757 {
3758   struct constant_descriptor *ptr;
3759
3760   ptr = ((struct constant_descriptor *)
3761          xcalloc (1, (offsetof (struct constant_descriptor, u)
3762                       + sizeof (struct rtx_const))));
3763   decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3764
3765   return ptr;
3766 }
3767 \f
3768 /* Given a constant rtx X, return a MEM for the location in memory at which
3769    this constant has been placed.  Return 0 if it not has been placed yet.  */
3770
3771 rtx
3772 mem_for_const_double (x)
3773      rtx x;
3774 {
3775   enum machine_mode mode = GET_MODE (x);
3776   struct constant_descriptor *desc;
3777
3778   for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3779        desc = desc->next)
3780     if (compare_constant_rtx (mode, x, desc))
3781       return desc->rtl;
3782
3783   return 0;
3784 }
3785   
3786 /* Given a constant rtx X, make (or find) a memory constant for its value
3787    and return a MEM rtx to refer to it in memory.  */
3788
3789 rtx
3790 force_const_mem (mode, x)
3791      enum machine_mode mode;
3792      rtx x;
3793 {
3794   int hash;
3795   struct constant_descriptor *desc;
3796   char label[256];
3797   rtx def;
3798   struct pool_constant *pool;
3799   unsigned int align;
3800
3801   /* Compute hash code of X.  Search the descriptors for that hash code
3802      to see if any of them describes X.  If yes, we have an rtx to use.  */
3803   hash = const_hash_rtx (mode, x);
3804   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3805     if (compare_constant_rtx (mode, x, desc))
3806       return desc->rtl;
3807
3808   /* No constant equal to X is known to have been output.
3809      Make a constant descriptor to enter X in the hash table
3810      and make a MEM for it.  */
3811   desc = record_constant_rtx (mode, x);
3812   desc->next = const_rtx_hash_table[hash];
3813   const_rtx_hash_table[hash] = desc;
3814   
3815   /* Align the location counter as required by EXP's data type.  */
3816   align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3817 #ifdef CONSTANT_ALIGNMENT
3818   align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x), align);
3819 #endif
3820
3821   pool_offset += (align / BITS_PER_UNIT) - 1;
3822   pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3823
3824   if (GET_CODE (x) == LABEL_REF)
3825     LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3826
3827   /* Allocate a pool constant descriptor, fill it in, and chain it in.  */
3828   pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3829   pool->desc = desc;
3830   pool->constant = x;
3831   pool->mode = mode;
3832   pool->labelno = const_labelno;
3833   pool->align = align;
3834   pool->offset = pool_offset;
3835   pool->mark = 1;
3836   pool->next = 0;
3837
3838   if (last_pool == 0)
3839     first_pool = pool;
3840   else
3841     last_pool->next = pool;
3842   
3843   last_pool = pool;
3844   pool_offset += GET_MODE_SIZE (mode);
3845
3846   /* Create a string containing the label name, in LABEL.  */
3847   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3848
3849   ++const_labelno;
3850
3851   /* Construct the SYMBOL_REF and the MEM.  */
3852
3853   pool->desc->rtl = def
3854     = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3855   set_mem_alias_set (def, const_alias_set);
3856   set_mem_attributes (def, type_for_mode (mode, 0), 1);
3857   RTX_UNCHANGING_P (def) = 1;
3858
3859   /* Add label to symbol hash table.  */
3860   hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3861   pool->next_sym = const_rtx_sym_hash_table[hash];
3862   const_rtx_sym_hash_table[hash] = pool;
3863
3864   /* Mark the symbol_ref as belonging to this constants pool.  */
3865   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3866   current_function_uses_const_pool = 1;
3867
3868   return def;
3869 }
3870 \f
3871 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3872    the corresponding pool_constant structure.  */
3873
3874 static struct pool_constant *
3875 find_pool_constant (f, addr)
3876      struct function *f;
3877      rtx addr;
3878 {
3879   struct pool_constant *pool;
3880   const char *label = XSTR (addr, 0);
3881
3882   for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3883        pool = pool->next_sym)
3884     if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3885       return pool;
3886
3887   abort ();
3888 }
3889
3890 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3891
3892 rtx
3893 get_pool_constant (addr)
3894      rtx addr;
3895 {
3896   return (find_pool_constant (cfun, addr))->constant;
3897 }
3898
3899 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3900    and whether it has been output or not.  */
3901
3902 rtx
3903 get_pool_constant_mark (addr, pmarked)
3904      rtx addr;
3905      bool *pmarked;
3906 {
3907   struct pool_constant *pool = find_pool_constant (cfun, addr);
3908   *pmarked = (pool->mark != 0);
3909   return pool->constant;
3910 }
3911
3912 /* Likewise, but for the constant pool of a specific function.  */
3913
3914 rtx
3915 get_pool_constant_for_function (f, addr)
3916      struct function *f;
3917      rtx addr;
3918 {
3919   return (find_pool_constant (f, addr))->constant;
3920 }
3921
3922 /* Similar, return the mode.  */
3923
3924 enum machine_mode
3925 get_pool_mode (addr)
3926      rtx addr;
3927 {
3928   return (find_pool_constant (cfun, addr))->mode;
3929 }
3930
3931 enum machine_mode
3932 get_pool_mode_for_function (f, addr)
3933      struct function *f;
3934      rtx addr;
3935 {
3936   return (find_pool_constant (f, addr))->mode;
3937 }
3938
3939 /* Similar, return the offset in the constant pool.  */
3940
3941 int
3942 get_pool_offset (addr)
3943      rtx addr;
3944 {
3945   return (find_pool_constant (cfun, addr))->offset;
3946 }
3947
3948 /* Return the size of the constant pool.  */
3949
3950 int
3951 get_pool_size ()
3952 {
3953   return pool_offset;
3954 }
3955 \f
3956 /* Write all the constants in the constant pool.  */
3957
3958 void
3959 output_constant_pool (fnname, fndecl)
3960   const char *fnname ATTRIBUTE_UNUSED;
3961   tree fndecl ATTRIBUTE_UNUSED;
3962 {
3963   struct pool_constant *pool;
3964   rtx x;
3965   union real_extract u;
3966
3967   /* It is possible for gcc to call force_const_mem and then to later
3968      discard the instructions which refer to the constant.  In such a
3969      case we do not need to output the constant.  */
3970   mark_constant_pool ();
3971
3972 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3973   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3974 #endif
3975
3976   for (pool = first_pool; pool; pool = pool->next)
3977     {
3978       rtx tmp;
3979
3980       x = pool->constant;
3981
3982       if (! pool->mark)
3983         continue;
3984
3985       /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3986          whose CODE_LABEL has been deleted.  This can occur if a jump table
3987          is eliminated by optimization.  If so, write a constant of zero
3988          instead.  Note that this can also happen by turning the
3989          CODE_LABEL into a NOTE.  */
3990       /* ??? This seems completely and utterly wrong.  Certainly it's
3991          not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3992          functioning even with INSN_DELETED_P and friends.  */
3993
3994       tmp = x;
3995       switch (GET_CODE (x))
3996         {
3997         case CONST:
3998           if (GET_CODE (XEXP (x, 0)) != PLUS
3999               || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
4000             break;
4001           tmp = XEXP (XEXP (x, 0), 0);
4002           /* FALLTHRU */
4003
4004         case LABEL_REF:
4005           tmp = XEXP (x, 0);
4006           if (INSN_DELETED_P (tmp)
4007               || (GET_CODE (tmp) == NOTE
4008                   && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
4009             {
4010               abort ();
4011               x = const0_rtx;
4012             }
4013           break;
4014
4015         default:
4016           break;
4017         }
4018
4019       /* First switch to correct section.  */
4020 #ifdef SELECT_RTX_SECTION
4021       SELECT_RTX_SECTION (pool->mode, x, pool->align);
4022 #else
4023       readonly_data_section ();
4024 #endif
4025
4026 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4027       ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4028                                      pool->align, pool->labelno, done);
4029 #endif
4030
4031       assemble_align (pool->align);
4032
4033       /* Output the label.  */
4034       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4035
4036       /* Output the value of the constant itself.  */
4037       switch (GET_MODE_CLASS (pool->mode))
4038         {
4039         case MODE_FLOAT:
4040           if (GET_CODE (x) != CONST_DOUBLE)
4041             abort ();
4042
4043           memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4044           assemble_real (u.d, pool->mode, pool->align);
4045           break;
4046
4047         case MODE_INT:
4048         case MODE_PARTIAL_INT:
4049           assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4050           break;
4051
4052         case MODE_VECTOR_FLOAT:
4053           {
4054             int i, units;
4055             rtx elt;
4056
4057             if (GET_CODE (x) != CONST_VECTOR)
4058               abort ();
4059
4060             units = CONST_VECTOR_NUNITS (x);
4061
4062             for (i = 0; i < units; i++)
4063               {
4064                 elt = CONST_VECTOR_ELT (x, i);
4065                 memcpy ((char *) &u,
4066                         (char *) &CONST_DOUBLE_LOW (elt),
4067                         sizeof u);
4068                 assemble_real (u.d, GET_MODE_INNER (pool->mode), pool->align);
4069               }
4070           }
4071           break;
4072
4073         case MODE_VECTOR_INT:
4074           {
4075             int i, units;
4076             rtx elt;
4077
4078             if (GET_CODE (x) != CONST_VECTOR)
4079               abort ();
4080
4081             units = CONST_VECTOR_NUNITS (x);
4082
4083             for (i = 0; i < units; i++)
4084               {
4085                 elt = CONST_VECTOR_ELT (x, i);
4086                 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
4087                                   pool->align, 1);
4088               }
4089           }
4090           break;
4091
4092         default:
4093           abort ();
4094         }
4095
4096 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4097     done: ;
4098 #endif
4099     }
4100
4101 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4102   ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4103 #endif
4104
4105   /* Done with this pool.  */
4106   first_pool = last_pool = 0;
4107 }
4108
4109 /* Look through the instructions for this function, and mark all the
4110    entries in the constant pool which are actually being used.
4111    Emit used deferred strings.  */
4112
4113 static void
4114 mark_constant_pool ()
4115 {
4116   rtx insn;
4117   struct pool_constant *pool;
4118
4119   if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4120     return;
4121
4122   for (pool = first_pool; pool; pool = pool->next)
4123     pool->mark = 0;
4124
4125   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4126     if (INSN_P (insn))
4127       mark_constants (PATTERN (insn));
4128
4129   for (insn = current_function_epilogue_delay_list;
4130        insn;
4131        insn = XEXP (insn, 1))
4132     if (INSN_P (insn))
4133       mark_constants (PATTERN (insn));
4134 }
4135
4136 /* Look through appropriate parts of X, marking all entries in the
4137    constant pool which are actually being used.  Entries that are only
4138    referenced by other constants are also marked as used.  Emit
4139    deferred strings that are used.  */
4140
4141 static void
4142 mark_constants (x)
4143      rtx x;
4144 {
4145   int i;
4146   const char *format_ptr;
4147
4148   if (x == 0)
4149     return;
4150
4151   if (GET_CODE (x) == SYMBOL_REF)
4152     {
4153       mark_constant (&x, NULL);
4154       return;
4155     }
4156
4157   /* Insns may appear inside a SEQUENCE.  Only check the patterns of
4158      insns, not any notes that may be attached.  We don't want to mark
4159      a constant just because it happens to appear in a REG_EQUIV note.  */
4160   if (INSN_P (x))
4161     {
4162       mark_constants (PATTERN (x));
4163       return;
4164     }
4165
4166   format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4167
4168   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4169     {
4170       switch (*format_ptr++)
4171         {
4172         case 'e':
4173           mark_constants (XEXP (x, i));
4174           break;
4175
4176         case 'E':
4177           if (XVEC (x, i) != 0)
4178             {
4179               int j;
4180
4181               for (j = 0; j < XVECLEN (x, i); j++)
4182                 mark_constants (XVECEXP (x, i, j));
4183             }
4184           break;
4185
4186         case 'S':
4187         case 's':
4188         case '0':
4189         case 'i':
4190         case 'w':
4191         case 'n':
4192         case 'u':
4193           break;
4194
4195         default:
4196           abort ();
4197         }
4198     }
4199 }
4200
4201 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4202    to as used.  Emit referenced deferred strings.  This function can
4203    be used with for_each_rtx to mark all SYMBOL_REFs in an rtx.  */
4204
4205 static int
4206 mark_constant (current_rtx, data)
4207      rtx *current_rtx;
4208      void *data ATTRIBUTE_UNUSED;
4209 {
4210   rtx x = *current_rtx;
4211
4212   if (x == NULL_RTX)
4213     return 0;
4214
4215   else if (GET_CODE (x) == SYMBOL_REF)
4216     {
4217       if (CONSTANT_POOL_ADDRESS_P (x))
4218         {
4219           struct pool_constant *pool = find_pool_constant (cfun, x);
4220           if (pool->mark == 0) {
4221             pool->mark = 1;
4222             for_each_rtx (&(pool->constant), &mark_constant, NULL);
4223           }
4224           else
4225             return -1;
4226         }
4227       else if (STRING_POOL_ADDRESS_P (x))
4228         {
4229           struct deferred_string **defstr;
4230
4231           defstr = (struct deferred_string **)
4232             htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4233                                       STRHASH (XSTR (x, 0)), NO_INSERT);
4234           if (defstr)
4235             {
4236               struct deferred_string *p = *defstr;
4237
4238               STRING_POOL_ADDRESS_P (x) = 0;
4239               output_constant_def_contents (p->exp, 0, p->labelno);
4240               htab_clear_slot (const_str_htab, (void **) defstr);
4241             }
4242         }
4243     }
4244   return 0;
4245 }
4246 \f
4247 /* Find all the constants whose addresses are referenced inside of EXP,
4248    and make sure assembler code with a label has been output for each one.
4249    Indicate whether an ADDR_EXPR has been encountered.  */
4250
4251 static int
4252 output_addressed_constants (exp)
4253      tree exp;
4254 {
4255   int reloc = 0;
4256   tree tem;
4257
4258   /* Give the front-end a chance to convert VALUE to something that
4259      looks more like a constant to the back-end.  */
4260   exp = (*lang_hooks.expand_constant) (exp);
4261
4262   switch (TREE_CODE (exp))
4263     {
4264     case ADDR_EXPR:
4265       /* Go inside any operations that get_inner_reference can handle and see
4266          if what's inside is a constant: no need to do anything here for
4267          addresses of variables or functions.  */
4268       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4269            tem = TREE_OPERAND (tem, 0))
4270         ;
4271
4272       if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4273             || TREE_CODE (tem) == CONSTRUCTOR)
4274           output_constant_def (tem, 0);
4275
4276       if (TREE_PUBLIC (tem))
4277         reloc |= 2;
4278       else
4279         reloc |= 1;
4280       break;
4281
4282     case PLUS_EXPR:
4283     case MINUS_EXPR:
4284       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4285       reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4286       break;
4287
4288     case NOP_EXPR:
4289     case CONVERT_EXPR:
4290     case NON_LVALUE_EXPR:
4291       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4292       break;
4293
4294     case CONSTRUCTOR:
4295       for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4296         if (TREE_VALUE (tem) != 0)
4297             reloc |= output_addressed_constants (TREE_VALUE (tem));
4298
4299       break;
4300
4301     default:
4302       break;
4303     }
4304   return reloc;
4305 }
4306 \f
4307 /* Return nonzero if VALUE is a valid constant-valued expression
4308    for use in initializing a static variable; one that can be an
4309    element of a "constant" initializer.
4310
4311    Return null_pointer_node if the value is absolute;
4312    if it is relocatable, return the variable that determines the relocation.
4313    We assume that VALUE has been folded as much as possible;
4314    therefore, we do not need to check for such things as
4315    arithmetic-combinations of integers.  */
4316
4317 tree
4318 initializer_constant_valid_p (value, endtype)
4319      tree value;
4320      tree endtype;
4321 {
4322   /* Give the front-end a chance to convert VALUE to something that
4323      looks more like a constant to the back-end.  */
4324   value = (*lang_hooks.expand_constant) (value);
4325
4326   switch (TREE_CODE (value))
4327     {
4328     case CONSTRUCTOR:
4329       if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4330            || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4331           && TREE_CONSTANT (value)
4332           && CONSTRUCTOR_ELTS (value))
4333         return
4334           initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4335                                         endtype);
4336
4337       return TREE_STATIC (value) ? null_pointer_node : 0;
4338
4339     case INTEGER_CST:
4340     case VECTOR_CST:
4341     case REAL_CST:
4342     case STRING_CST:
4343     case COMPLEX_CST:
4344       return null_pointer_node;
4345
4346     case ADDR_EXPR:
4347     case FDESC_EXPR:
4348       return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4349
4350     case VIEW_CONVERT_EXPR:
4351     case NON_LVALUE_EXPR:
4352       return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4353
4354     case CONVERT_EXPR:
4355     case NOP_EXPR:
4356       /* Allow conversions between pointer types.  */
4357       if (POINTER_TYPE_P (TREE_TYPE (value))
4358           && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4359         return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4360
4361       /* Allow conversions between real types.  */
4362       if (FLOAT_TYPE_P (TREE_TYPE (value))
4363           && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4364         return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4365
4366       /* Allow length-preserving conversions between integer types.  */
4367       if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4368           && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4369           && (TYPE_PRECISION (TREE_TYPE (value))
4370               == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4371         return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4372
4373       /* Allow conversions between other integer types only if
4374          explicit value.  */
4375       if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4376           && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4377         {
4378           tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4379                                                      endtype);
4380           if (inner == null_pointer_node)
4381             return null_pointer_node;
4382           break;
4383         }
4384
4385       /* Allow (int) &foo provided int is as wide as a pointer.  */
4386       if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4387           && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4388           && (TYPE_PRECISION (TREE_TYPE (value))
4389               >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4390         return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4391                                              endtype);
4392
4393       /* Likewise conversions from int to pointers, but also allow
4394          conversions from 0.  */
4395       if (POINTER_TYPE_P (TREE_TYPE (value))
4396           && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4397         {
4398           if (integer_zerop (TREE_OPERAND (value, 0)))
4399             return null_pointer_node;
4400           else if (TYPE_PRECISION (TREE_TYPE (value))
4401                    <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4402             return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4403                                                  endtype);
4404         }
4405
4406       /* Allow conversions to union types if the value inside is okay.  */
4407       if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4408         return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4409                                              endtype);
4410       break;
4411
4412     case PLUS_EXPR:
4413       if (! INTEGRAL_TYPE_P (endtype)
4414           || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4415         {
4416           tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4417                                                       endtype);
4418           tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4419                                                       endtype);
4420           /* If either term is absolute, use the other terms relocation.  */
4421           if (valid0 == null_pointer_node)
4422             return valid1;
4423           if (valid1 == null_pointer_node)
4424             return valid0;
4425         }
4426       break;
4427
4428     case MINUS_EXPR:
4429       if (! INTEGRAL_TYPE_P (endtype)
4430           || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4431         {
4432           tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4433                                                       endtype);
4434           tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4435                                                       endtype);
4436           /* Win if second argument is absolute.  */
4437           if (valid1 == null_pointer_node)
4438             return valid0;
4439           /* Win if both arguments have the same relocation.
4440              Then the value is absolute.  */
4441           if (valid0 == valid1 && valid0 != 0)
4442             return null_pointer_node;
4443
4444           /* Since GCC guarantees that string constants are unique in the
4445              generated code, a subtraction between two copies of the same
4446              constant string is absolute.  */
4447           if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4448               valid1 && TREE_CODE (valid1) == STRING_CST &&
4449               TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4450             return null_pointer_node;
4451         }
4452
4453       /* Support differences between labels.  */
4454       if (INTEGRAL_TYPE_P (endtype))
4455         {
4456           tree op0, op1;
4457           op0 = TREE_OPERAND (value, 0);
4458           op1 = TREE_OPERAND (value, 1);
4459
4460           /* Like STRIP_NOPS except allow the operand mode to widen.
4461              This works around a feature of fold that simplfies
4462              (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4463              that the narrower operation is cheaper.  */
4464
4465           while (TREE_CODE (op0) == NOP_EXPR
4466                  || TREE_CODE (op0) == CONVERT_EXPR
4467                  || TREE_CODE (op0) == NON_LVALUE_EXPR)
4468             {
4469               tree inner = TREE_OPERAND (op0, 0);
4470               if (inner == error_mark_node
4471                   || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4472                   || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4473                       > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4474                 break;
4475               op0 = inner;
4476             }
4477
4478           while (TREE_CODE (op1) == NOP_EXPR
4479                  || TREE_CODE (op1) == CONVERT_EXPR
4480                  || TREE_CODE (op1) == NON_LVALUE_EXPR)
4481             {
4482               tree inner = TREE_OPERAND (op1, 0);
4483               if (inner == error_mark_node
4484                   || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4485                   || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4486                       > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4487                 break;
4488               op1 = inner;
4489             }
4490
4491           if (TREE_CODE (op0) == ADDR_EXPR
4492               && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4493               && TREE_CODE (op1) == ADDR_EXPR
4494               && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4495             return null_pointer_node;
4496         }
4497       break;
4498
4499     default:
4500       break;
4501     }
4502
4503   return 0;
4504 }
4505 \f
4506 /* Output assembler code for constant EXP to FILE, with no label.
4507    This includes the pseudo-op such as ".int" or ".byte", and a newline.
4508    Assumes output_addressed_constants has been done on EXP already.
4509
4510    Generate exactly SIZE bytes of assembler data, padding at the end
4511    with zeros if necessary.  SIZE must always be specified.
4512
4513    SIZE is important for structure constructors,
4514    since trailing members may have been omitted from the constructor.
4515    It is also important for initialization of arrays from string constants
4516    since the full length of the string constant might not be wanted.
4517    It is also needed for initialization of unions, where the initializer's
4518    type is just one member, and that may not be as long as the union.
4519
4520    There a case in which we would fail to output exactly SIZE bytes:
4521    for a structure constructor that wants to produce more than SIZE bytes.
4522    But such constructors will never be generated for any possible input.
4523
4524    ALIGN is the alignment of the data in bits.  */
4525
4526 void
4527 output_constant (exp, size, align)
4528      tree exp;
4529      HOST_WIDE_INT size;
4530      unsigned int align;
4531 {
4532   enum tree_code code;
4533   HOST_WIDE_INT thissize;
4534
4535   /* Some front-ends use constants other than the standard language-indepdent
4536      varieties, but which may still be output directly.  Give the front-end a
4537      chance to convert EXP to a language-independent representation.  */
4538   exp = (*lang_hooks.expand_constant) (exp);
4539
4540   if (size == 0 || flag_syntax_only)
4541     return;
4542
4543   /* Eliminate any conversions since we'll be outputting the underlying
4544      constant.  */
4545   while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4546          || TREE_CODE (exp) == NON_LVALUE_EXPR
4547          || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4548     exp = TREE_OPERAND (exp, 0);
4549
4550   code = TREE_CODE (TREE_TYPE (exp));
4551   thissize = int_size_in_bytes (TREE_TYPE (exp));
4552
4553   /* Allow a constructor with no elements for any data type.
4554      This means to fill the space with zeros.  */
4555   if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4556     {
4557       assemble_zeros (size);
4558       return;
4559     }
4560
4561   if (TREE_CODE (exp) == FDESC_EXPR)
4562     {
4563 #ifdef ASM_OUTPUT_FDESC
4564       HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4565       tree decl = TREE_OPERAND (exp, 0);
4566       ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4567 #else
4568       abort ();
4569 #endif
4570       return;
4571     }
4572
4573   /* Now output the underlying data.  If we've handling the padding, return.
4574      Otherwise, break and ensure THISSIZE is the size written.  */
4575   switch (code)
4576     {
4577     case CHAR_TYPE:
4578     case BOOLEAN_TYPE:
4579     case INTEGER_TYPE:
4580     case ENUMERAL_TYPE:
4581     case POINTER_TYPE:
4582     case REFERENCE_TYPE:
4583       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4584                                            EXPAND_INITIALIZER),
4585                               size, align, 0))
4586         error ("initializer for integer value is too complicated");
4587       break;
4588
4589     case REAL_TYPE:
4590       if (TREE_CODE (exp) != REAL_CST)
4591         error ("initializer for floating value is not a floating constant");
4592
4593       assemble_real (TREE_REAL_CST (exp),
4594                      mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4595                      align);
4596       break;
4597
4598     case COMPLEX_TYPE:
4599       output_constant (TREE_REALPART (exp), thissize / 2, align);
4600       output_constant (TREE_IMAGPART (exp), thissize / 2,
4601                        min_align (align, BITS_PER_UNIT * (thissize / 2)));
4602       break;
4603
4604     case ARRAY_TYPE:
4605     case VECTOR_TYPE:
4606       if (TREE_CODE (exp) == CONSTRUCTOR)
4607         {
4608           output_constructor (exp, size, align);
4609           return;
4610         }
4611       else if (TREE_CODE (exp) == STRING_CST)
4612         {
4613           thissize = MIN (TREE_STRING_LENGTH (exp), size);
4614           assemble_string (TREE_STRING_POINTER (exp), thissize);
4615         }
4616       else
4617         abort ();
4618       break;
4619
4620     case RECORD_TYPE:
4621     case UNION_TYPE:
4622       if (TREE_CODE (exp) == CONSTRUCTOR)
4623         output_constructor (exp, size, align);
4624       else
4625         abort ();
4626       return;
4627
4628     case SET_TYPE:
4629       if (TREE_CODE (exp) == INTEGER_CST)
4630         assemble_integer (expand_expr (exp, NULL_RTX,
4631                                        VOIDmode, EXPAND_INITIALIZER),
4632                          thissize, align, 1);
4633       else if (TREE_CODE (exp) == CONSTRUCTOR)
4634         {
4635           unsigned char *buffer = (unsigned char *) alloca (thissize);
4636           if (get_set_constructor_bytes (exp, buffer, thissize))
4637             abort ();
4638           assemble_string ((char *) buffer, thissize);
4639         }
4640       else
4641         error ("unknown set constructor type");
4642       return;
4643
4644     case ERROR_MARK:
4645       return;
4646
4647     default:
4648       abort ();
4649     }
4650
4651   size -= thissize;
4652   if (size > 0)
4653     assemble_zeros (size);
4654 }
4655
4656 \f
4657 /* Subroutine of output_constructor, used for computing the size of
4658    arrays of unspecified length.  VAL must be a CONSTRUCTOR of an array
4659    type with an unspecified upper bound.  */
4660
4661 static unsigned HOST_WIDE_INT
4662 array_size_for_constructor (val)
4663      tree val;
4664 {
4665   tree max_index, i;
4666
4667   /* This code used to attempt to handle string constants that are not
4668      arrays of single-bytes, but nothing else does, so there's no point in
4669      doing it here.  */
4670   if (TREE_CODE (val) == STRING_CST)
4671     return TREE_STRING_LENGTH (val);
4672
4673   max_index = NULL_TREE;
4674   for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4675     {
4676       tree index = TREE_PURPOSE (i);
4677
4678       if (TREE_CODE (index) == RANGE_EXPR)
4679         index = TREE_OPERAND (index, 1);
4680       if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4681         max_index = index;
4682     }
4683
4684   if (max_index == NULL_TREE)
4685     return 0;
4686
4687   /* Compute the total number of array elements.  */
4688   i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4689                   convert (sizetype,
4690                            TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4691   i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4692
4693   /* Multiply by the array element unit size to find number of bytes.  */
4694   i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4695
4696   return tree_low_cst (i, 1);
4697 }
4698
4699 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4700    Generate at least SIZE bytes, padding if necessary.  */
4701
4702 static void
4703 output_constructor (exp, size, align)
4704      tree exp;
4705      HOST_WIDE_INT size;
4706      unsigned int align;
4707 {
4708   tree type = TREE_TYPE (exp);
4709   tree link, field = 0;
4710   tree min_index = 0;
4711   /* Number of bytes output or skipped so far.
4712      In other words, current position within the constructor.  */
4713   HOST_WIDE_INT total_bytes = 0;
4714   /* Non-zero means BYTE contains part of a byte, to be output.  */
4715   int byte_buffer_in_use = 0;
4716   int byte = 0;
4717
4718   if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4719     abort ();
4720
4721   if (TREE_CODE (type) == RECORD_TYPE)
4722     field = TYPE_FIELDS (type);
4723
4724   if (TREE_CODE (type) == ARRAY_TYPE
4725       && TYPE_DOMAIN (type) != 0)
4726     min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4727
4728   /* As LINK goes through the elements of the constant,
4729      FIELD goes through the structure fields, if the constant is a structure.
4730      if the constant is a union, then we override this,
4731      by getting the field from the TREE_LIST element.
4732      But the constant could also be an array.  Then FIELD is zero.
4733
4734      There is always a maximum of one element in the chain LINK for unions
4735      (even if the initializer in a source program incorrectly contains
4736      more one).  */
4737   for (link = CONSTRUCTOR_ELTS (exp);
4738        link;
4739        link = TREE_CHAIN (link),
4740        field = field ? TREE_CHAIN (field) : 0)
4741     {
4742       tree val = TREE_VALUE (link);
4743       tree index = 0;
4744
4745       /* The element in a union constructor specifies the proper field
4746          or index.  */
4747       if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4748            || TREE_CODE (type) == QUAL_UNION_TYPE)
4749           && TREE_PURPOSE (link) != 0)
4750         field = TREE_PURPOSE (link);
4751
4752       else if (TREE_CODE (type) == ARRAY_TYPE)
4753         index = TREE_PURPOSE (link);
4754
4755       /* Eliminate the marker that makes a cast not be an lvalue.  */
4756       if (val != 0)
4757         STRIP_NOPS (val);
4758
4759       if (index && TREE_CODE (index) == RANGE_EXPR)
4760         {
4761           unsigned HOST_WIDE_INT fieldsize
4762             = int_size_in_bytes (TREE_TYPE (type));
4763           HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4764           HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4765           HOST_WIDE_INT index;
4766           unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4767
4768           for (index = lo_index; index <= hi_index; index++)
4769             {
4770               /* Output the element's initial value.  */
4771               if (val == 0)
4772                 assemble_zeros (fieldsize);
4773               else
4774                 output_constant (val, fieldsize, align2);
4775
4776               /* Count its size.  */
4777               total_bytes += fieldsize;
4778             }
4779         }
4780       else if (field == 0 || !DECL_BIT_FIELD (field))
4781         {
4782           /* An element that is not a bit-field.  */
4783
4784           unsigned HOST_WIDE_INT fieldsize;
4785           /* Since this structure is static,
4786              we know the positions are constant.  */
4787           HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4788           unsigned int align2;
4789
4790           if (index != 0)
4791             pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4792                    * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4793
4794           /* Output any buffered-up bit-fields preceding this element.  */
4795           if (byte_buffer_in_use)
4796             {
4797               assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4798               total_bytes++;
4799               byte_buffer_in_use = 0;
4800             }
4801
4802           /* Advance to offset of this element.
4803              Note no alignment needed in an array, since that is guaranteed
4804              if each element has the proper size.  */
4805           if ((field != 0 || index != 0) && pos != total_bytes)
4806             {
4807               assemble_zeros (pos - total_bytes);
4808               total_bytes = pos;
4809             }
4810
4811           /* Find the alignment of this element.  */
4812           align2 = min_align (align, BITS_PER_UNIT * pos);
4813
4814           /* Determine size this element should occupy.  */
4815           if (field)
4816             {
4817               fieldsize = 0;
4818
4819               /* If this is an array with an unspecified upper bound,
4820                  the initializer determines the size.  */
4821               /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4822                  but we cannot do this until the deprecated support for
4823                  initializing zero-length array members is removed.  */
4824               if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4825                   && TYPE_DOMAIN (TREE_TYPE (field))
4826                   && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4827                 {
4828                   fieldsize = array_size_for_constructor (val);
4829                   /* Given a non-empty initialization, this field had
4830                      better be last.  */
4831                   if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4832                     abort ();
4833                 }
4834               else if (DECL_SIZE_UNIT (field))
4835                 {
4836                   /* ??? This can't be right.  If the decl size overflows
4837                      a host integer we will silently emit no data.  */
4838                   if (host_integerp (DECL_SIZE_UNIT (field), 1))
4839                     fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4840                 }
4841             }
4842           else
4843             fieldsize = int_size_in_bytes (TREE_TYPE (type));
4844
4845           /* Output the element's initial value.  */
4846           if (val == 0)
4847             assemble_zeros (fieldsize);
4848           else
4849             output_constant (val, fieldsize, align2);
4850
4851           /* Count its size.  */
4852           total_bytes += fieldsize;
4853         }
4854       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4855         error ("invalid initial value for member `%s'",
4856                IDENTIFIER_POINTER (DECL_NAME (field)));
4857       else
4858         {
4859           /* Element that is a bit-field.  */
4860
4861           HOST_WIDE_INT next_offset = int_bit_position (field);
4862           HOST_WIDE_INT end_offset
4863             = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4864
4865           if (val == 0)
4866             val = integer_zero_node;
4867
4868           /* If this field does not start in this (or, next) byte,
4869              skip some bytes.  */
4870           if (next_offset / BITS_PER_UNIT != total_bytes)
4871             {
4872               /* Output remnant of any bit field in previous bytes.  */
4873               if (byte_buffer_in_use)
4874                 {
4875                   assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4876                   total_bytes++;
4877                   byte_buffer_in_use = 0;
4878                 }
4879
4880               /* If still not at proper byte, advance to there.  */
4881               if (next_offset / BITS_PER_UNIT != total_bytes)
4882                 {
4883                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4884                   total_bytes = next_offset / BITS_PER_UNIT;
4885                 }
4886             }
4887
4888           if (! byte_buffer_in_use)
4889             byte = 0;
4890
4891           /* We must split the element into pieces that fall within
4892              separate bytes, and combine each byte with previous or
4893              following bit-fields.  */
4894
4895           /* next_offset is the offset n fbits from the beginning of
4896              the structure to the next bit of this element to be processed.
4897              end_offset is the offset of the first bit past the end of
4898              this element.  */
4899           while (next_offset < end_offset)
4900             {
4901               int this_time;
4902               int shift;
4903               HOST_WIDE_INT value;
4904               HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4905               HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4906
4907               /* Advance from byte to byte
4908                  within this element when necessary.  */
4909               while (next_byte != total_bytes)
4910                 {
4911                   assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4912                   total_bytes++;
4913                   byte = 0;
4914                 }
4915
4916               /* Number of bits we can process at once
4917                  (all part of the same byte).  */
4918               this_time = MIN (end_offset - next_offset,
4919                                BITS_PER_UNIT - next_bit);
4920               if (BYTES_BIG_ENDIAN)
4921                 {
4922                   /* On big-endian machine, take the most significant bits
4923                      first (of the bits that are significant)
4924                      and put them into bytes from the most significant end.  */
4925                   shift = end_offset - next_offset - this_time;
4926
4927                   /* Don't try to take a bunch of bits that cross
4928                      the word boundary in the INTEGER_CST. We can
4929                      only select bits from the LOW or HIGH part
4930                      not from both.  */
4931                   if (shift < HOST_BITS_PER_WIDE_INT
4932                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4933                     {
4934                       this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4935                       shift = HOST_BITS_PER_WIDE_INT;
4936                     }
4937
4938                   /* Now get the bits from the appropriate constant word.  */
4939                   if (shift < HOST_BITS_PER_WIDE_INT)
4940                     value = TREE_INT_CST_LOW (val);
4941                   else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4942                     {
4943                       value = TREE_INT_CST_HIGH (val);
4944                       shift -= HOST_BITS_PER_WIDE_INT;
4945                     }
4946                   else
4947                     abort ();
4948
4949                   /* Get the result. This works only when:
4950                      1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
4951                   byte |= (((value >> shift)
4952                             & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4953                            << (BITS_PER_UNIT - this_time - next_bit));
4954                 }
4955               else
4956                 {
4957                   /* On little-endian machines,
4958                      take first the least significant bits of the value
4959                      and pack them starting at the least significant
4960                      bits of the bytes.  */
4961                   shift = next_offset - int_bit_position (field);
4962
4963                   /* Don't try to take a bunch of bits that cross
4964                      the word boundary in the INTEGER_CST. We can
4965                      only select bits from the LOW or HIGH part
4966                      not from both.  */
4967                   if (shift < HOST_BITS_PER_WIDE_INT
4968                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4969                     this_time = (HOST_BITS_PER_WIDE_INT - shift);
4970
4971                   /* Now get the bits from the appropriate constant word.  */
4972                   if (shift < HOST_BITS_PER_WIDE_INT)
4973                     value = TREE_INT_CST_LOW (val);
4974                   else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4975                     {
4976                       value = TREE_INT_CST_HIGH (val);
4977                       shift -= HOST_BITS_PER_WIDE_INT;
4978                     }
4979                   else
4980                     abort ();
4981
4982                   /* Get the result. This works only when:
4983                      1 <= this_time <= HOST_BITS_PER_WIDE_INT.  */
4984                   byte |= (((value >> shift)
4985                             & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4986                            << next_bit);
4987                 }
4988
4989               next_offset += this_time;
4990               byte_buffer_in_use = 1;
4991             }
4992         }
4993     }
4994
4995   if (byte_buffer_in_use)
4996     {
4997       assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4998       total_bytes++;
4999     }
5000
5001   if (total_bytes < size)
5002     assemble_zeros (size - total_bytes);
5003 }
5004
5005 /* This TREE_LIST contains any weak symbol declarations waiting
5006    to be emitted.  */
5007 static tree weak_decls;
5008
5009 /* Declare DECL to be a weak symbol.  */
5010
5011 void
5012 declare_weak (decl)
5013      tree decl;
5014 {
5015   if (! TREE_PUBLIC (decl))
5016     error_with_decl (decl, "weak declaration of `%s' must be public");
5017   else if (TREE_ASM_WRITTEN (decl))
5018     error_with_decl (decl, "weak declaration of `%s' must precede definition");
5019   else if (SUPPORTS_WEAK)
5020     {
5021       if (! DECL_WEAK (decl))
5022         weak_decls = tree_cons (NULL, decl, weak_decls);
5023     }
5024   else
5025     warning_with_decl (decl, "weak declaration of `%s' not supported");
5026
5027   DECL_WEAK (decl) = 1;
5028 }
5029
5030 /* Emit any pending weak declarations.  */
5031
5032 void
5033 weak_finish ()
5034 {
5035   tree t;
5036
5037   for (t = weak_decls; t ; t = TREE_CHAIN (t))
5038     {
5039       tree decl = TREE_VALUE (t);
5040       const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5041
5042       if (! TREE_USED (decl))
5043         continue;
5044
5045 #ifdef ASM_WEAKEN_DECL
5046       ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5047 #else
5048 #ifdef ASM_WEAKEN_LABEL
5049       ASM_WEAKEN_LABEL (asm_out_file, name);
5050 #else
5051 #ifdef ASM_OUTPUT_WEAK_ALIAS
5052       warning ("only weak aliases are supported in this configuration");
5053       return;
5054 #endif
5055 #endif
5056 #endif
5057     }
5058 }
5059
5060 /* Emit the assembly bits to indicate that DECL is globally visible.  */
5061
5062 static void
5063 globalize_decl (decl)
5064      tree decl;
5065 {
5066   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5067
5068 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5069   if (DECL_WEAK (decl))
5070     {
5071       tree *p, t;
5072
5073 #ifdef ASM_WEAKEN_DECL
5074       ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5075 #else
5076       ASM_WEAKEN_LABEL (asm_out_file, name);
5077 #endif
5078
5079       /* Remove this function from the pending weak list so that
5080          we do not emit multiple .weak directives for it.  */
5081       for (p = &weak_decls; (t = *p) ; p = &TREE_CHAIN (t))
5082         if (TREE_VALUE (t) == decl)
5083           {
5084             *p = TREE_CHAIN (t);
5085             break;
5086           }
5087       return;
5088     }
5089 #endif
5090
5091   ASM_GLOBALIZE_LABEL (asm_out_file, name);
5092 }
5093
5094 /* Emit an assembler directive to make the symbol for DECL an alias to
5095    the symbol for TARGET.  */
5096
5097 void
5098 assemble_alias (decl, target)
5099      tree decl, target ATTRIBUTE_UNUSED;
5100 {
5101   const char *name;
5102
5103   /* We must force creation of DECL_RTL for debug info generation, even though
5104      we don't use it here.  */
5105   make_decl_rtl (decl, NULL);
5106
5107   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5108
5109 #ifdef ASM_OUTPUT_DEF
5110   /* Make name accessible from other files, if appropriate.  */
5111
5112   if (TREE_PUBLIC (decl))
5113     {
5114       globalize_decl (decl);
5115       maybe_assemble_visibility (decl);
5116     }
5117
5118 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5119   ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5120 #else
5121   ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5122 #endif
5123   TREE_ASM_WRITTEN (decl) = 1;
5124 #else /* !ASM_OUTPUT_DEF */
5125 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5126   if (! DECL_WEAK (decl))
5127     warning ("only weak aliases are supported in this configuration");
5128
5129 #ifdef ASM_WEAKEN_DECL
5130   ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5131 #else
5132   ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5133 #endif
5134   TREE_ASM_WRITTEN (decl) = 1;
5135 #else
5136   warning ("alias definitions not supported in this configuration; ignored");
5137 #endif
5138 #endif
5139 }
5140
5141 /* Emit an assembler directive to set symbol for DECL visibility to
5142    VISIBILITY_TYPE.  */
5143
5144 void
5145 assemble_visibility (decl, visibility_type)
5146      tree decl;
5147      const char *visibility_type ATTRIBUTE_UNUSED;
5148 {
5149   const char *name;
5150
5151   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5152
5153 #ifdef HAVE_GAS_HIDDEN
5154   fprintf (asm_out_file, "\t.%s\t%s\n", visibility_type, name);
5155 #else
5156   warning ("visibility attribute not supported in this configuration; ignored");
5157 #endif
5158 }
5159
5160 /* A helper function to call assemble_visibility when needed for a decl.  */
5161
5162 static void
5163 maybe_assemble_visibility (decl)
5164      tree decl;
5165 {
5166   tree visibility = lookup_attribute ("visibility", DECL_ATTRIBUTES (decl));
5167   if (visibility)
5168     {
5169       const char *type
5170         = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility)));
5171       assemble_visibility (decl, type);
5172     }
5173 }
5174
5175 /* Returns 1 if the target configuration supports defining public symbols
5176    so that one of them will be chosen at link time instead of generating a
5177    multiply-defined symbol error, whether through the use of weak symbols or
5178    a target-specific mechanism for having duplicates discarded.  */
5179
5180 int
5181 supports_one_only ()
5182 {
5183   if (SUPPORTS_ONE_ONLY)
5184     return 1;
5185   return SUPPORTS_WEAK;
5186 }
5187
5188 /* Set up DECL as a public symbol that can be defined in multiple
5189    translation units without generating a linker error.  */
5190
5191 void
5192 make_decl_one_only (decl)
5193      tree decl;
5194 {
5195   if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5196     abort ();
5197
5198   TREE_PUBLIC (decl) = 1;
5199
5200   if (TREE_CODE (decl) == VAR_DECL
5201       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5202     DECL_COMMON (decl) = 1;
5203   else if (SUPPORTS_ONE_ONLY)
5204     {
5205 #ifdef MAKE_DECL_ONE_ONLY
5206       MAKE_DECL_ONE_ONLY (decl);
5207 #endif
5208       DECL_ONE_ONLY (decl) = 1;
5209     }
5210   else if (SUPPORTS_WEAK)
5211     DECL_WEAK (decl) = 1;
5212   else
5213     abort ();
5214 }
5215
5216 void
5217 init_varasm_once ()
5218 {
5219   const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5220                                 const_str_htab_del);
5221   in_named_htab = htab_create (31, in_named_entry_hash,
5222                                in_named_entry_eq, NULL);
5223
5224   ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5225                 mark_const_hash_entry);
5226   ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5227                 mark_const_str_htab);
5228   ggc_add_tree_root (&weak_decls, 1);
5229
5230   const_alias_set = new_alias_set ();
5231 }
5232
5233 /* Select a set of attributes for section NAME based on the properties
5234    of DECL and whether or not RELOC indicates that DECL's initializer
5235    might contain runtime relocations.
5236
5237    We make the section read-only and executable for a function decl,
5238    read-only for a const data decl, and writable for a non-const data decl.  */
5239
5240 unsigned int
5241 default_section_type_flags (decl, name, reloc)
5242      tree decl;
5243      const char *name;
5244      int reloc;
5245 {
5246   unsigned int flags;
5247
5248   if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5249     flags = SECTION_CODE;
5250   else if (decl && DECL_READONLY_SECTION (decl, reloc))
5251     flags = 0;
5252   else
5253     flags = SECTION_WRITE;
5254
5255   if (decl && DECL_ONE_ONLY (decl))
5256     flags |= SECTION_LINKONCE;
5257
5258   if (strcmp (name, ".bss") == 0
5259       || strncmp (name, ".bss.", 5) == 0
5260       || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5261       || strcmp (name, ".sbss") == 0
5262       || strncmp (name, ".sbss.", 6) == 0
5263       || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5264     flags |= SECTION_BSS;
5265
5266   return flags;
5267 }
5268
5269 /* Output assembly to switch to section NAME with attribute FLAGS.
5270    Four variants for common object file formats.  */
5271
5272 void
5273 default_no_named_section (name, flags)
5274      const char *name ATTRIBUTE_UNUSED;
5275      unsigned int flags ATTRIBUTE_UNUSED;
5276 {
5277   /* Some object formats don't support named sections at all.  The
5278      front-end should already have flagged this as an error.  */
5279   abort ();
5280 }
5281
5282 void
5283 default_elf_asm_named_section (name, flags)
5284      const char *name;
5285      unsigned int flags;
5286 {
5287   char flagchars[10], *f = flagchars;
5288   const char *type;
5289
5290   if (! named_section_first_declaration (name))
5291     {
5292       fprintf (asm_out_file, "\t.section\t%s\n", name);
5293       return;
5294     }
5295
5296   if (!(flags & SECTION_DEBUG))
5297     *f++ = 'a';
5298   if (flags & SECTION_WRITE)
5299     *f++ = 'w';
5300   if (flags & SECTION_CODE)
5301     *f++ = 'x';
5302   if (flags & SECTION_SMALL)
5303     *f++ = 's';
5304   if (flags & SECTION_MERGE)
5305     *f++ = 'M';
5306   if (flags & SECTION_STRINGS)
5307     *f++ = 'S';
5308   *f = '\0';
5309
5310   if (flags & SECTION_BSS)
5311     type = "nobits";
5312   else
5313     type = "progbits";
5314
5315   if (flags & SECTION_ENTSIZE)
5316     fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5317              name, flagchars, type, flags & SECTION_ENTSIZE);
5318   else
5319     fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5320              name, flagchars, type);
5321 }
5322
5323 void
5324 default_coff_asm_named_section (name, flags)
5325      const char *name;
5326      unsigned int flags;
5327 {
5328   char flagchars[8], *f = flagchars;
5329
5330   if (flags & SECTION_WRITE)
5331     *f++ = 'w';
5332   if (flags & SECTION_CODE)
5333     *f++ = 'x';
5334   *f = '\0';
5335
5336   fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5337 }
5338
5339 void
5340 default_pe_asm_named_section (name, flags)
5341      const char *name;
5342      unsigned int flags;
5343 {
5344   default_coff_asm_named_section (name, flags);
5345
5346   if (flags & SECTION_LINKONCE)
5347     {
5348       /* Functions may have been compiled at various levels of
5349          optimization so we can't use `same_size' here.
5350          Instead, have the linker pick one.  */
5351       fprintf (asm_out_file, "\t.linkonce %s\n",
5352                (flags & SECTION_CODE ? "discard" : "same_size"));
5353     }
5354 }
5355 \f
5356 /* Used for vtable gc in GNU binutils.  Record that the pointer at OFFSET
5357    from SYMBOL is used in all classes derived from SYMBOL.  */
5358
5359 void
5360 assemble_vtable_entry (symbol, offset)
5361      rtx symbol;
5362      HOST_WIDE_INT offset;
5363 {
5364   fputs ("\t.vtable_entry ", asm_out_file);
5365   output_addr_const (asm_out_file, symbol);
5366   fputs (", ", asm_out_file);
5367   fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5368   fputc ('\n', asm_out_file);
5369 }
5370
5371 /* Used for vtable gc in GNU binutils.  Record the class hierarchy by noting
5372    that the vtable symbol CHILD is derived from the vtable symbol PARENT.  */
5373
5374 void
5375 assemble_vtable_inherit (child, parent)
5376      rtx child, parent;
5377 {
5378   fputs ("\t.vtable_inherit ", asm_out_file);
5379   output_addr_const (asm_out_file, child);
5380   fputs (", ", asm_out_file);
5381   output_addr_const (asm_out_file, parent);
5382   fputc ('\n', asm_out_file);
5383 }