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