OSDN Git Service

bcb5b114238d1febca9a4863396bf6353ea2b235
[pf3gnuchains/gcc-fork.git] / gcc / varasm.c
1 /* Output variables, constants and external declarations, for GNU compiler.
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4    2010  Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
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 "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "real.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "hashtab.h"
45 #include "ggc.h"
46 #include "langhooks.h"
47 #include "tm_p.h"
48 #include "debug.h"
49 #include "target.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
52 #include "cgraph.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
56
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h"           /* Needed for external data
59                                    declarations for e.g. AIX 4.x.  */
60 #endif
61
62 /* The (assembler) name of the first globally-visible object output.  */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
65
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
68
69 struct addr_const;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
72
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
74
75 /* Number for making the label on the next
76    constant that is stored in memory.  */
77
78 static GTY(()) int const_labelno;
79
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81    to ASM_FINISH_DECLARE_OBJECT.  */
82
83 int size_directive_output;
84
85 /* The last decl for which assemble_variable was called,
86    if it did ASM_DECLARE_OBJECT_NAME.
87    If the last call to assemble_variable didn't do that,
88    this holds 0.  */
89
90 tree last_assemble_variable_decl;
91
92 /* The following global variable indicates if the first basic block
93    in a function belongs to the cold partition or not.  */
94
95 bool first_function_block_is_cold;
96
97 /* We give all constants their own alias set.  Perhaps redundant with
98    MEM_READONLY_P, but pre-dates it.  */
99
100 static alias_set_type const_alias_set;
101
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
106 #endif
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121                             unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
122 #endif
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125                                     unsigned HOST_WIDE_INT, int)
126      ATTRIBUTE_UNUSED;
127 #endif
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
131 \f
132 /* Well-known sections, each one associated with some sort of *_ASM_OP.  */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
141
142 /* Various forms of common section.  All are guaranteed to be nonnull.  */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
146
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148    May be null.  */
149 section *bss_noswitch_section;
150
151 /* The section that holds the main exception table, when known.  The section
152    is set either by the target's init_sections hook or by the first call to
153    switch_to_exception_section.  */
154 section *exception_section;
155
156 /* The section that holds the DWARF2 frame unwind information, when known.
157    The section is set either by the target's init_sections hook or by the
158    first call to switch_to_eh_frame_section.  */
159 section *eh_frame_section;
160
161 /* asm_out_file's current section.  This is NULL if no section has yet
162    been selected or if we lose track of what the current section is.  */
163 section *in_section;
164
165 /* True if code for the current function is currently being directed
166    at the cold section.  */
167 bool in_cold_section_p;
168
169 /* A linked list of all the unnamed sections.  */
170 static GTY(()) section *unnamed_sections;
171
172 /* Return a nonzero value if DECL has a section attribute.  */
173 #define IN_NAMED_SECTION(DECL) \
174   ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175    && DECL_SECTION_NAME (DECL) != NULL_TREE)
176
177 /* Hash table of named sections.  */
178 static GTY((param_is (section))) htab_t section_htab;
179
180 /* A table of object_blocks, indexed by section.  */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
182
183 /* The next number to use for internal anchor labels.  */
184 static GTY(()) int anchor_labelno;
185
186 /* A pool of constants that can be shared between functions.  */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
188
189 /* TLS emulation.  */
190
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
192      htab_t emutls_htab;
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED.  This
195    macro can be used on them to distinguish the control variable from
196    the initialization template.  */
197 #define DECL_EMUTLS_VAR_P(D)  (TREE_TYPE (D) == emutls_object_type)
198
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR       "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR       "$"
203 #else
204 # define EMUTLS_SEPARATOR       "_"
205 #endif
206
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208    IDENTIFIER_NODE NAME's name.  */
209
210 static tree
211 prefix_name (const char *prefix, tree name)
212 {
213   unsigned plen = strlen (prefix);
214   unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215   char *toname = (char *) alloca (plen + nlen + 1);
216
217   memcpy (toname, prefix, plen);
218   memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
219
220   return get_identifier (toname);
221 }
222
223 /* Create an identifier for the struct __emutls_object, given an identifier
224    of the DECL_ASSEMBLY_NAME of the original object.  */
225
226 static tree
227 get_emutls_object_name (tree name)
228 {
229   const char *prefix = (targetm.emutls.var_prefix
230                         ? targetm.emutls.var_prefix
231                         : "__emutls_v" EMUTLS_SEPARATOR);
232   return prefix_name (prefix, name);
233 }
234
235 tree
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
237 {
238   tree word_type_node, field, next_field;
239
240   field = build_decl (UNKNOWN_LOCATION,
241                       FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242   DECL_CONTEXT (field) = type;
243   next_field = field;
244
245   field = build_decl (UNKNOWN_LOCATION,
246                       FIELD_DECL, get_identifier ("__offset"),
247                       ptr_type_node);
248   DECL_CONTEXT (field) = type;
249   TREE_CHAIN (field) = next_field;
250   next_field = field;
251
252   word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253   field = build_decl (UNKNOWN_LOCATION,
254                       FIELD_DECL, get_identifier ("__align"),
255                       word_type_node);
256   DECL_CONTEXT (field) = type;
257   TREE_CHAIN (field) = next_field;
258   next_field = field;
259
260   field = build_decl (UNKNOWN_LOCATION,
261                       FIELD_DECL, get_identifier ("__size"), word_type_node);
262   DECL_CONTEXT (field) = type;
263   TREE_CHAIN (field) = next_field;
264
265   return field;
266 }
267
268 /* Create the structure for struct __emutls_object.  This should match the
269    structure at the top of emutls.c, modulo the union there.  */
270
271 static tree
272 get_emutls_object_type (void)
273 {
274   tree type, type_name, field;
275
276   type = emutls_object_type;
277   if (type)
278     return type;
279
280   emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
281   type_name = NULL;
282   field = targetm.emutls.var_fields (type, &type_name);
283   if (!type_name)
284     type_name = get_identifier ("__emutls_object");
285   type_name = build_decl (UNKNOWN_LOCATION,
286                           TYPE_DECL, type_name, type);
287   TYPE_NAME (type) = type_name;
288   TYPE_FIELDS (type) = field;
289   layout_type (type);
290
291   return type;
292 }
293
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295    This will be used for initializing the emulated tls data area.  */
296
297 static tree
298 get_emutls_init_templ_addr (tree decl)
299 {
300   tree name, to;
301
302   if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303       && !DECL_SECTION_NAME (decl))
304     return null_pointer_node;
305
306   name = DECL_ASSEMBLER_NAME (decl);
307   if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
308     {
309       const char *prefix = (targetm.emutls.tmpl_prefix
310                             ? targetm.emutls.tmpl_prefix
311                             : "__emutls_t" EMUTLS_SEPARATOR);
312       name = prefix_name (prefix, name);
313     }
314
315   to = build_decl (DECL_SOURCE_LOCATION (decl),
316                    VAR_DECL, name, TREE_TYPE (decl));
317   SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
318   DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
319   DECL_ARTIFICIAL (to) = 1;
320   TREE_USED (to) = TREE_USED (decl);
321   TREE_READONLY (to) = 1;
322   DECL_IGNORED_P (to) = 1;
323   DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324   DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
325
326   DECL_WEAK (to) = DECL_WEAK (decl);
327   if (DECL_ONE_ONLY (decl))
328     {
329       make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
330       TREE_STATIC (to) = TREE_STATIC (decl);
331       TREE_PUBLIC (to) = TREE_PUBLIC (decl);
332       DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
333     }
334   else
335     TREE_STATIC (to) = 1;
336
337   DECL_INITIAL (to) = DECL_INITIAL (decl);
338   DECL_INITIAL (decl) = NULL;
339
340   varpool_finalize_decl (to);
341   return build_fold_addr_expr (to);
342 }
343
344 /* When emulating tls, we use a control structure for use by the runtime.
345    Create and return this structure.  */
346
347 tree
348 emutls_decl (tree decl)
349 {
350   tree name, to;
351   struct tree_map *h, in;
352   void **loc;
353
354   if (targetm.have_tls || decl == NULL || decl == error_mark_node
355       || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
356     return decl;
357
358   /* Look up the object in the hash; return the control structure if
359      it has already been created.  */
360   if (! emutls_htab)
361     emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
362
363   name = DECL_ASSEMBLER_NAME (decl);
364
365   /* Note that we use the hash of the decl's name, rather than a hash
366      of the decl's pointer.  In emutls_finish we iterate through the
367      hash table, and we want this traversal to be predictable.  */
368   in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
369   in.base.from = decl;
370   loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
371   h = (struct tree_map *) *loc;
372   if (h != NULL)
373     to = h->to;
374   else
375     {
376       to = build_decl (DECL_SOURCE_LOCATION (decl),
377                        VAR_DECL, get_emutls_object_name (name),
378                        get_emutls_object_type ());
379
380       h = GGC_NEW (struct tree_map);
381       h->hash = in.hash;
382       h->base.from = decl;
383       h->to = to;
384       *(struct tree_map **) loc = h;
385
386       DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
387       DECL_ARTIFICIAL (to) = 1;
388       DECL_IGNORED_P (to) = 1;
389       TREE_READONLY (to) = 0;
390       SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
391       if (DECL_ONE_ONLY (decl))
392         make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
393       DECL_CONTEXT (to) = DECL_CONTEXT (decl);
394       if (targetm.emutls.var_align_fixed)
395         /* If we're not allowed to change the proxy object's
396            alignment, pretend it's been set by the user.  */
397         DECL_USER_ALIGN (to) = 1;
398     }
399
400   /* Note that these fields may need to be updated from time to time from
401      the original decl.  Consider:
402         extern __thread int i;
403         int foo() { return i; }
404         __thread int i = 1;
405      in which I goes from external to locally defined and initialized.  */
406
407   TREE_STATIC (to) = TREE_STATIC (decl);
408   TREE_USED (to) = TREE_USED (decl);
409   TREE_PUBLIC (to) = TREE_PUBLIC (decl);
410   DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
411   DECL_COMMON (to) = DECL_COMMON (decl);
412   DECL_WEAK (to) = DECL_WEAK (decl);
413   DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
414
415   return to;
416 }
417
418 static int
419 emutls_common_1 (void **loc, void *xstmts)
420 {
421   struct tree_map *h = *(struct tree_map **) loc;
422   tree args, x, *pstmts = (tree *) xstmts;
423   tree word_type_node;
424
425   if (! DECL_COMMON (h->base.from)
426       || (DECL_INITIAL (h->base.from)
427           && DECL_INITIAL (h->base.from) != error_mark_node))
428     return 1;
429
430   word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
431
432   /* The idea was to call get_emutls_init_templ_addr here, but if we
433      do this and there is an initializer, -fanchor_section loses,
434      because it would be too late to ensure the template is
435      output.  */
436   x = null_pointer_node;
437   args = tree_cons (NULL, x, NULL);
438   x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
439   args = tree_cons (NULL, x, args);
440   x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
441   args = tree_cons (NULL, x, args);
442   x = build_fold_addr_expr (h->to);
443   args = tree_cons (NULL, x, args);
444
445   x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
446   x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
447
448   append_to_statement_list (x, pstmts);
449   return 1;
450 }
451
452 void
453 emutls_finish (void)
454 {
455   if (targetm.emutls.register_common)
456     {
457       tree body = NULL_TREE;
458
459       if (emutls_htab == NULL)
460         return;
461
462       htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
463       if (body == NULL_TREE)
464         return;
465
466       cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
467     }
468 }
469
470 /* Helper routines for maintaining section_htab.  */
471
472 static int
473 section_entry_eq (const void *p1, const void *p2)
474 {
475   const section *old = (const section *) p1;
476   const char *new_name = (const char *) p2;
477
478   return strcmp (old->named.name, new_name) == 0;
479 }
480
481 static hashval_t
482 section_entry_hash (const void *p)
483 {
484   const section *old = (const section *) p;
485   return htab_hash_string (old->named.name);
486 }
487
488 /* Return a hash value for section SECT.  */
489
490 static hashval_t
491 hash_section (section *sect)
492 {
493   if (sect->common.flags & SECTION_NAMED)
494     return htab_hash_string (sect->named.name);
495   return sect->common.flags;
496 }
497
498 /* Helper routines for maintaining object_block_htab.  */
499
500 static int
501 object_block_entry_eq (const void *p1, const void *p2)
502 {
503   const struct object_block *old = (const struct object_block *) p1;
504   const section *new_section = (const section *) p2;
505
506   return old->sect == new_section;
507 }
508
509 static hashval_t
510 object_block_entry_hash (const void *p)
511 {
512   const struct object_block *old = (const struct object_block *) p;
513   return hash_section (old->sect);
514 }
515
516 /* Return a new unnamed section with the given fields.  */
517
518 section *
519 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
520                      const void *data)
521 {
522   section *sect;
523
524   sect = GGC_NEW (section);
525   sect->unnamed.common.flags = flags | SECTION_UNNAMED;
526   sect->unnamed.callback = callback;
527   sect->unnamed.data = data;
528   sect->unnamed.next = unnamed_sections;
529
530   unnamed_sections = sect;
531   return sect;
532 }
533
534 /* Return a SECTION_NOSWITCH section with the given fields.  */
535
536 static section *
537 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
538 {
539   section *sect;
540
541   sect = GGC_NEW (section);
542   sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
543   sect->noswitch.callback = callback;
544
545   return sect;
546 }
547
548 /* Return the named section structure associated with NAME.  Create
549    a new section with the given fields if no such structure exists.  */
550
551 section *
552 get_section (const char *name, unsigned int flags, tree decl)
553 {
554   section *sect, **slot;
555
556   slot = (section **)
557     htab_find_slot_with_hash (section_htab, name,
558                               htab_hash_string (name), INSERT);
559   flags |= SECTION_NAMED;
560   if (*slot == NULL)
561     {
562       sect = GGC_NEW (section);
563       sect->named.common.flags = flags;
564       sect->named.name = ggc_strdup (name);
565       sect->named.decl = decl;
566       *slot = sect;
567     }
568   else
569     {
570       sect = *slot;
571       if ((sect->common.flags & ~SECTION_DECLARED) != flags
572           && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
573         {
574           /* Sanity check user variables for flag changes.  */
575           if (decl == 0)
576             decl = sect->named.decl;
577           gcc_assert (decl);
578           error ("%+D causes a section type conflict", decl);
579         }
580     }
581   return sect;
582 }
583
584 /* Return true if the current compilation mode benefits from having
585    objects grouped into blocks.  */
586
587 static bool
588 use_object_blocks_p (void)
589 {
590   return flag_section_anchors;
591 }
592
593 /* Return the object_block structure for section SECT.  Create a new
594    structure if we haven't created one already.  Return null if SECT
595    itself is null.  */
596
597 static struct object_block *
598 get_block_for_section (section *sect)
599 {
600   struct object_block *block;
601   void **slot;
602
603   if (sect == NULL)
604     return NULL;
605
606   slot = htab_find_slot_with_hash (object_block_htab, sect,
607                                    hash_section (sect), INSERT);
608   block = (struct object_block *) *slot;
609   if (block == NULL)
610     {
611       block = (struct object_block *)
612         ggc_alloc_cleared (sizeof (struct object_block));
613       block->sect = sect;
614       *slot = block;
615     }
616   return block;
617 }
618
619 /* Create a symbol with label LABEL and place it at byte offset
620    OFFSET in BLOCK.  OFFSET can be negative if the symbol's offset
621    is not yet known.  LABEL must be a garbage-collected string.  */
622
623 static rtx
624 create_block_symbol (const char *label, struct object_block *block,
625                      HOST_WIDE_INT offset)
626 {
627   rtx symbol;
628   unsigned int size;
629
630   /* Create the extended SYMBOL_REF.  */
631   size = RTX_HDR_SIZE + sizeof (struct block_symbol);
632   symbol = (rtx) ggc_alloc_zone (size, &rtl_zone);
633
634   /* Initialize the normal SYMBOL_REF fields.  */
635   memset (symbol, 0, size);
636   PUT_CODE (symbol, SYMBOL_REF);
637   PUT_MODE (symbol, Pmode);
638   XSTR (symbol, 0) = label;
639   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
640
641   /* Initialize the block_symbol stuff.  */
642   SYMBOL_REF_BLOCK (symbol) = block;
643   SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
644
645   return symbol;
646 }
647
648 static void
649 initialize_cold_section_name (void)
650 {
651   const char *stripped_name;
652   char *name, *buffer;
653   tree dsn;
654
655   gcc_assert (cfun && current_function_decl);
656   if (crtl->subsections.unlikely_text_section_name)
657     return;
658
659   dsn = DECL_SECTION_NAME (current_function_decl);
660   if (flag_function_sections && dsn)
661     {
662       name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
663       memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
664
665       stripped_name = targetm.strip_name_encoding (name);
666
667       buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
668       crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
669     }
670   else
671     crtl->subsections.unlikely_text_section_name =  UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
672 }
673
674 /* Tell assembler to switch to unlikely-to-be-executed text section.  */
675
676 section *
677 unlikely_text_section (void)
678 {
679   if (cfun)
680     {
681       if (!crtl->subsections.unlikely_text_section_name)
682         initialize_cold_section_name ();
683
684       return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
685     }
686   else
687     return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
688 }
689
690 /* When called within a function context, return true if the function
691    has been assigned a cold text section and if SECT is that section.
692    When called outside a function context, return true if SECT is the
693    default cold section.  */
694
695 bool
696 unlikely_text_section_p (section *sect)
697 {
698   const char *name;
699
700   if (cfun)
701     name = crtl->subsections.unlikely_text_section_name;
702   else
703     name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
704
705   return (name
706           && sect
707           && SECTION_STYLE (sect) == SECTION_NAMED
708           && strcmp (name, sect->named.name) == 0);
709 }
710
711 /* Return a section with a particular name and with whatever SECTION_*
712    flags section_type_flags deems appropriate.  The name of the section
713    is taken from NAME if nonnull, otherwise it is taken from DECL's
714    DECL_SECTION_NAME.  DECL is the decl associated with the section
715    (see the section comment for details) and RELOC is as for
716    section_type_flags.  */
717
718 section *
719 get_named_section (tree decl, const char *name, int reloc)
720 {
721   unsigned int flags;
722
723   gcc_assert (!decl || DECL_P (decl));
724   if (name == NULL)
725     name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
726
727   flags = targetm.section_type_flags (decl, name, reloc);
728
729   return get_section (name, flags, decl);
730 }
731
732 /* If required, set DECL_SECTION_NAME to a unique name.  */
733
734 void
735 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
736                         int flag_function_or_data_sections)
737 {
738   if (DECL_SECTION_NAME (decl) == NULL_TREE
739       && targetm.have_named_sections
740       && (flag_function_or_data_sections
741           || DECL_ONE_ONLY (decl)))
742     targetm.asm_out.unique_section (decl, reloc);
743 }
744
745 #ifdef BSS_SECTION_ASM_OP
746
747 #ifdef ASM_OUTPUT_BSS
748
749 /* Utility function for ASM_OUTPUT_BSS for targets to use if
750    they don't support alignments in .bss.
751    ??? It is believed that this function will work in most cases so such
752    support is localized here.  */
753
754 static void
755 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
756                 const char *name,
757                 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
758                 unsigned HOST_WIDE_INT rounded)
759 {
760   gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
761   targetm.asm_out.globalize_decl_name (file, decl);
762   switch_to_section (bss_section);
763 #ifdef ASM_DECLARE_OBJECT_NAME
764   last_assemble_variable_decl = decl;
765   ASM_DECLARE_OBJECT_NAME (file, name, decl);
766 #else
767   /* Standard thing is just output label for the object.  */
768   ASM_OUTPUT_LABEL (file, name);
769 #endif /* ASM_DECLARE_OBJECT_NAME */
770   ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
771 }
772
773 #endif
774
775 #ifdef ASM_OUTPUT_ALIGNED_BSS
776
777 /* Utility function for targets to use in implementing
778    ASM_OUTPUT_ALIGNED_BSS.
779    ??? It is believed that this function will work in most cases so such
780    support is localized here.  */
781
782 static void
783 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
784                         const char *name, unsigned HOST_WIDE_INT size,
785                         int align)
786 {
787   switch_to_section (bss_section);
788   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
789 #ifdef ASM_DECLARE_OBJECT_NAME
790   last_assemble_variable_decl = decl;
791   ASM_DECLARE_OBJECT_NAME (file, name, decl);
792 #else
793   /* Standard thing is just output label for the object.  */
794   ASM_OUTPUT_LABEL (file, name);
795 #endif /* ASM_DECLARE_OBJECT_NAME */
796   ASM_OUTPUT_SKIP (file, size ? size : 1);
797 }
798
799 #endif
800
801 #endif /* BSS_SECTION_ASM_OP */
802
803 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
804 /* Return the hot section for function DECL.  Return text_section for
805    null DECLs.  */
806
807 static section *
808 hot_function_section (tree decl)
809 {
810   if (decl != NULL_TREE
811       && DECL_SECTION_NAME (decl) != NULL_TREE
812       && targetm.have_named_sections)
813     return get_named_section (decl, NULL, 0);
814   else
815     return text_section;
816 }
817 #endif
818
819 /* Return the section for function DECL.
820
821    If DECL is NULL_TREE, return the text section.  We can be passed
822    NULL_TREE under some circumstances by dbxout.c at least.  */
823
824 section *
825 function_section (tree decl)
826 {
827   int reloc = 0;
828
829   if (first_function_block_is_cold)
830     reloc = 1;
831
832 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
833   if (decl != NULL_TREE
834       && DECL_SECTION_NAME (decl) != NULL_TREE)
835     return reloc ? unlikely_text_section ()
836                  : get_named_section (decl, NULL, 0);
837   else
838     return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
839 #else
840   return reloc ? unlikely_text_section () : hot_function_section (decl);
841 #endif
842 }
843
844 section *
845 current_function_section (void)
846 {
847 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
848   if (current_function_decl != NULL_TREE
849       && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
850     return in_cold_section_p ? unlikely_text_section ()
851                              : get_named_section (current_function_decl,
852                                                   NULL, 0);
853   else
854     return targetm.asm_out.select_section (current_function_decl,
855                                            in_cold_section_p,
856                                            DECL_ALIGN (current_function_decl));
857 #else
858   return (in_cold_section_p
859           ? unlikely_text_section ()
860           : hot_function_section (current_function_decl));
861 #endif
862 }
863
864 /* Return the read-only data section associated with function DECL.  */
865
866 section *
867 default_function_rodata_section (tree decl)
868 {
869   if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
870     {
871       const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
872
873       if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
874         {
875           const char *dot;
876           size_t len;
877           char* rname;
878
879           dot = strchr (name + 1, '.');
880           if (!dot)
881             dot = name;
882           len = strlen (dot) + 8;
883           rname = (char *) alloca (len);
884
885           strcpy (rname, ".rodata");
886           strcat (rname, dot);
887           return get_section (rname, SECTION_LINKONCE, decl);
888         }
889       /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo.  */
890       else if (DECL_ONE_ONLY (decl)
891                && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
892         {
893           size_t len = strlen (name) + 1;
894           char *rname = (char *) alloca (len);
895
896           memcpy (rname, name, len);
897           rname[14] = 'r';
898           return get_section (rname, SECTION_LINKONCE, decl);
899         }
900       /* For .text.foo we want to use .rodata.foo.  */
901       else if (flag_function_sections && flag_data_sections
902                && strncmp (name, ".text.", 6) == 0)
903         {
904           size_t len = strlen (name) + 1;
905           char *rname = (char *) alloca (len + 2);
906
907           memcpy (rname, ".rodata", 7);
908           memcpy (rname + 7, name + 5, len - 5);
909           return get_section (rname, 0, decl);
910         }
911     }
912
913   return readonly_data_section;
914 }
915
916 /* Return the read-only data section associated with function DECL
917    for targets where that section should be always the single
918    readonly data section.  */
919
920 section *
921 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
922 {
923   return readonly_data_section;
924 }
925
926 /* Return the section to use for string merging.  */
927
928 static section *
929 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
930                           unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
931                           unsigned int flags ATTRIBUTE_UNUSED)
932 {
933   HOST_WIDE_INT len;
934
935   if (HAVE_GAS_SHF_MERGE && flag_merge_constants
936       && TREE_CODE (decl) == STRING_CST
937       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
938       && align <= 256
939       && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
940       && TREE_STRING_LENGTH (decl) >= len)
941     {
942       enum machine_mode mode;
943       unsigned int modesize;
944       const char *str;
945       HOST_WIDE_INT i;
946       int j, unit;
947       char name[30];
948
949       mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
950       modesize = GET_MODE_BITSIZE (mode);
951       if (modesize >= 8 && modesize <= 256
952           && (modesize & (modesize - 1)) == 0)
953         {
954           if (align < modesize)
955             align = modesize;
956
957           str = TREE_STRING_POINTER (decl);
958           unit = GET_MODE_SIZE (mode);
959
960           /* Check for embedded NUL characters.  */
961           for (i = 0; i < len; i += unit)
962             {
963               for (j = 0; j < unit; j++)
964                 if (str[i + j] != '\0')
965                   break;
966               if (j == unit)
967                 break;
968             }
969           if (i == len - unit)
970             {
971               sprintf (name, ".rodata.str%d.%d", modesize / 8,
972                        (int) (align / 8));
973               flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
974               return get_section (name, flags, NULL);
975             }
976         }
977     }
978
979   return readonly_data_section;
980 }
981
982 /* Return the section to use for constant merging.  */
983
984 section *
985 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
986                             unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
987                             unsigned int flags ATTRIBUTE_UNUSED)
988 {
989   unsigned int modesize = GET_MODE_BITSIZE (mode);
990
991   if (HAVE_GAS_SHF_MERGE && flag_merge_constants
992       && mode != VOIDmode
993       && mode != BLKmode
994       && modesize <= align
995       && align >= 8
996       && align <= 256
997       && (align & (align - 1)) == 0)
998     {
999       char name[24];
1000
1001       sprintf (name, ".rodata.cst%d", (int) (align / 8));
1002       flags |= (align / 8) | SECTION_MERGE;
1003       return get_section (name, flags, NULL);
1004     }
1005   return readonly_data_section;
1006 }
1007 \f
1008 /* Given NAME, a putative register name, discard any customary prefixes.  */
1009
1010 static const char *
1011 strip_reg_name (const char *name)
1012 {
1013 #ifdef REGISTER_PREFIX
1014   if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1015     name += strlen (REGISTER_PREFIX);
1016 #endif
1017   if (name[0] == '%' || name[0] == '#')
1018     name++;
1019   return name;
1020 }
1021 \f
1022 /* The user has asked for a DECL to have a particular name.  Set (or
1023    change) it in such a way that we don't prefix an underscore to
1024    it.  */
1025 void
1026 set_user_assembler_name (tree decl, const char *name)
1027 {
1028   char *starred = (char *) alloca (strlen (name) + 2);
1029   starred[0] = '*';
1030   strcpy (starred + 1, name);
1031   change_decl_assembler_name (decl, get_identifier (starred));
1032   SET_DECL_RTL (decl, NULL_RTX);
1033 }
1034 \f
1035 /* Decode an `asm' spec for a declaration as a register name.
1036    Return the register number, or -1 if nothing specified,
1037    or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1038    or -3 if ASMSPEC is `cc' and is not recognized,
1039    or -4 if ASMSPEC is `memory' and is not recognized.
1040    Accept an exact spelling or a decimal number.
1041    Prefixes such as % are optional.  */
1042
1043 int
1044 decode_reg_name (const char *asmspec)
1045 {
1046   if (asmspec != 0)
1047     {
1048       int i;
1049
1050       /* Get rid of confusing prefixes.  */
1051       asmspec = strip_reg_name (asmspec);
1052
1053       /* Allow a decimal number as a "register name".  */
1054       for (i = strlen (asmspec) - 1; i >= 0; i--)
1055         if (! ISDIGIT (asmspec[i]))
1056           break;
1057       if (asmspec[0] != 0 && i < 0)
1058         {
1059           i = atoi (asmspec);
1060           if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1061             return i;
1062           else
1063             return -2;
1064         }
1065
1066       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1067         if (reg_names[i][0]
1068             && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1069           return i;
1070
1071 #ifdef ADDITIONAL_REGISTER_NAMES
1072       {
1073         static const struct { const char *const name; const int number; } table[]
1074           = ADDITIONAL_REGISTER_NAMES;
1075
1076         for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1077           if (table[i].name[0]
1078               && ! strcmp (asmspec, table[i].name))
1079             return table[i].number;
1080       }
1081 #endif /* ADDITIONAL_REGISTER_NAMES */
1082
1083       if (!strcmp (asmspec, "memory"))
1084         return -4;
1085
1086       if (!strcmp (asmspec, "cc"))
1087         return -3;
1088
1089       return -2;
1090     }
1091
1092   return -1;
1093 }
1094 \f
1095 /* Return true if DECL's initializer is suitable for a BSS section.  */
1096
1097 static bool
1098 bss_initializer_p (const_tree decl)
1099 {
1100   return (DECL_INITIAL (decl) == NULL
1101           || DECL_INITIAL (decl) == error_mark_node
1102           || (flag_zero_initialized_in_bss
1103               /* Leave constant zeroes in .rodata so they
1104                  can be shared.  */
1105               && !TREE_READONLY (decl)
1106               && initializer_zerop (DECL_INITIAL (decl))));
1107 }
1108
1109 /* Compute the alignment of variable specified by DECL.
1110    DONT_OUTPUT_DATA is from assemble_variable.  */
1111
1112 void
1113 align_variable (tree decl, bool dont_output_data)
1114 {
1115   unsigned int align = DECL_ALIGN (decl);
1116
1117   /* In the case for initialing an array whose length isn't specified,
1118      where we have not yet been able to do the layout,
1119      figure out the proper alignment now.  */
1120   if (dont_output_data && DECL_SIZE (decl) == 0
1121       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1122     align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1123
1124   /* Some object file formats have a maximum alignment which they support.
1125      In particular, a.out format supports a maximum alignment of 4.  */
1126   if (align > MAX_OFILE_ALIGNMENT)
1127     {
1128       warning (0, "alignment of %q+D is greater than maximum object "
1129                "file alignment.  Using %d", decl,
1130                MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1131       align = MAX_OFILE_ALIGNMENT;
1132     }
1133
1134   /* On some machines, it is good to increase alignment sometimes.  */
1135   if (! DECL_USER_ALIGN (decl))
1136     {
1137 #ifdef DATA_ALIGNMENT
1138       unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1139       /* Don't increase alignment too much for TLS variables - TLS space
1140          is too precious.  */
1141       if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1142         align = data_align;
1143 #endif
1144 #ifdef CONSTANT_ALIGNMENT
1145       if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1146         {
1147           unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1148                                                          align);
1149           /* Don't increase alignment too much for TLS variables - TLS space
1150              is too precious.  */
1151           if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1152             align = const_align;
1153         }
1154 #endif
1155     }
1156
1157   /* Reset the alignment in case we have made it tighter, so we can benefit
1158      from it in get_pointer_alignment.  */
1159   DECL_ALIGN (decl) = align;
1160 }
1161
1162 /* Return the section into which the given VAR_DECL or CONST_DECL
1163    should be placed.  PREFER_NOSWITCH_P is true if a noswitch
1164    section should be used wherever possible.  */
1165
1166 static section *
1167 get_variable_section (tree decl, bool prefer_noswitch_p)
1168 {
1169   addr_space_t as = ADDR_SPACE_GENERIC;
1170   int reloc;
1171
1172   if (TREE_TYPE (decl) != error_mark_node)
1173     as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1174
1175   if (DECL_COMMON (decl))
1176     {
1177       /* If the decl has been given an explicit section name, or it resides
1178          in a non-generic address space, then it isn't common, and shouldn't
1179          be handled as such.  */
1180       gcc_assert (DECL_SECTION_NAME (decl) == NULL
1181                   && ADDR_SPACE_GENERIC_P (as));
1182       if (DECL_THREAD_LOCAL_P (decl))
1183         return tls_comm_section;
1184       /* This cannot be common bss for an emulated TLS object without
1185          a register_common hook.  */
1186       else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1187                && !targetm.emutls.register_common)
1188         ;
1189       else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1190         return comm_section;
1191     }
1192
1193   if (DECL_INITIAL (decl) == error_mark_node)
1194     reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1195   else if (DECL_INITIAL (decl))
1196     reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1197   else
1198     reloc = 0;
1199
1200   resolve_unique_section (decl, reloc, flag_data_sections);
1201   if (IN_NAMED_SECTION (decl))
1202     return get_named_section (decl, NULL, reloc);
1203
1204   if (ADDR_SPACE_GENERIC_P (as)
1205       && !DECL_THREAD_LOCAL_P (decl)
1206       && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1207       && bss_initializer_p (decl))
1208     {
1209       if (!TREE_PUBLIC (decl))
1210         return lcomm_section;
1211       if (bss_noswitch_section)
1212         return bss_noswitch_section;
1213     }
1214
1215   return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1216 }
1217
1218 /* Return the block into which object_block DECL should be placed.  */
1219
1220 static struct object_block *
1221 get_block_for_decl (tree decl)
1222 {
1223   section *sect;
1224
1225   if (TREE_CODE (decl) == VAR_DECL)
1226     {
1227       /* The object must be defined in this translation unit.  */
1228       if (DECL_EXTERNAL (decl))
1229         return NULL;
1230
1231       /* There's no point using object blocks for something that is
1232          isolated by definition.  */
1233       if (DECL_ONE_ONLY (decl))
1234         return NULL;
1235     }
1236
1237   /* We can only calculate block offsets if the decl has a known
1238      constant size.  */
1239   if (DECL_SIZE_UNIT (decl) == NULL)
1240     return NULL;
1241   if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1242     return NULL;
1243
1244   /* Find out which section should contain DECL.  We cannot put it into
1245      an object block if it requires a standalone definition.  */
1246   if (TREE_CODE (decl) == VAR_DECL)
1247       align_variable (decl, 0);
1248   sect = get_variable_section (decl, true);
1249   if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1250     return NULL;
1251
1252   return get_block_for_section (sect);
1253 }
1254
1255 /* Make sure block symbol SYMBOL is in block BLOCK.  */
1256
1257 static void
1258 change_symbol_block (rtx symbol, struct object_block *block)
1259 {
1260   if (block != SYMBOL_REF_BLOCK (symbol))
1261     {
1262       gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1263       SYMBOL_REF_BLOCK (symbol) = block;
1264     }
1265 }
1266
1267 /* Return true if it is possible to put DECL in an object_block.  */
1268
1269 static bool
1270 use_blocks_for_decl_p (tree decl)
1271 {
1272   /* Only data DECLs can be placed into object blocks.  */
1273   if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1274     return false;
1275
1276   /* Detect decls created by dw2_force_const_mem.  Such decls are
1277      special because DECL_INITIAL doesn't specify the decl's true value.
1278      dw2_output_indirect_constants will instead call assemble_variable
1279      with dont_output_data set to 1 and then print the contents itself.  */
1280   if (DECL_INITIAL (decl) == decl)
1281     return false;
1282
1283   /* If this decl is an alias, then we don't want to emit a definition.  */
1284   if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1285     return false;
1286
1287   return true;
1288 }
1289
1290 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL.  DECL should
1291    have static storage duration.  In other words, it should not be an
1292    automatic variable, including PARM_DECLs.
1293
1294    There is, however, one exception: this function handles variables
1295    explicitly placed in a particular register by the user.
1296
1297    This is never called for PARM_DECL nodes.  */
1298
1299 void
1300 make_decl_rtl (tree decl)
1301 {
1302   const char *name = 0;
1303   int reg_number;
1304   rtx x;
1305
1306   /* Check that we are not being given an automatic variable.  */
1307   gcc_assert (TREE_CODE (decl) != PARM_DECL
1308               && TREE_CODE (decl) != RESULT_DECL);
1309
1310   /* A weak alias has TREE_PUBLIC set but not the other bits.  */
1311   gcc_assert (TREE_CODE (decl) != VAR_DECL
1312               || TREE_STATIC (decl)
1313               || TREE_PUBLIC (decl)
1314               || DECL_EXTERNAL (decl)
1315               || DECL_REGISTER (decl));
1316
1317   /* And that we were not given a type or a label.  */
1318   gcc_assert (TREE_CODE (decl) != TYPE_DECL
1319               && TREE_CODE (decl) != LABEL_DECL);
1320
1321   /* For a duplicate declaration, we can be called twice on the
1322      same DECL node.  Don't discard the RTL already made.  */
1323   if (DECL_RTL_SET_P (decl))
1324     {
1325       /* If the old RTL had the wrong mode, fix the mode.  */
1326       x = DECL_RTL (decl);
1327       if (GET_MODE (x) != DECL_MODE (decl))
1328         SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1329
1330       if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1331         return;
1332
1333       /* ??? Another way to do this would be to maintain a hashed
1334          table of such critters.  Instead of adding stuff to a DECL
1335          to give certain attributes to it, we could use an external
1336          hash map from DECL to set of attributes.  */
1337
1338       /* Let the target reassign the RTL if it wants.
1339          This is necessary, for example, when one machine specific
1340          decl attribute overrides another.  */
1341       targetm.encode_section_info (decl, DECL_RTL (decl), false);
1342
1343       /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1344          on the new decl information.  */
1345       if (MEM_P (x)
1346           && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1347           && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1348         change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1349
1350       /* Make this function static known to the mudflap runtime.  */
1351       if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1352         mudflap_enqueue_decl (decl);
1353
1354       return;
1355     }
1356
1357   /* If this variable belongs to the global constant pool, retrieve the
1358      pre-computed RTL or recompute it in LTO mode.  */
1359   if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1360     {
1361       SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1362       return;
1363     }
1364
1365   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1366
1367   if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1368       && DECL_REGISTER (decl))
1369     {
1370       error ("register name not specified for %q+D", decl);
1371     }
1372   else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1373     {
1374       const char *asmspec = name+1;
1375       reg_number = decode_reg_name (asmspec);
1376       /* First detect errors in declaring global registers.  */
1377       if (reg_number == -1)
1378         error ("register name not specified for %q+D", decl);
1379       else if (reg_number < 0)
1380         error ("invalid register name for %q+D", decl);
1381       else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1382         error ("data type of %q+D isn%'t suitable for a register",
1383                decl);
1384       else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1385         error ("register specified for %q+D isn%'t suitable for data type",
1386                decl);
1387       /* Now handle properly declared static register variables.  */
1388       else
1389         {
1390           int nregs;
1391
1392           if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1393             {
1394               DECL_INITIAL (decl) = 0;
1395               error ("global register variable has initial value");
1396             }
1397           if (TREE_THIS_VOLATILE (decl))
1398             warning (OPT_Wvolatile_register_var,
1399                      "optimization may eliminate reads and/or "
1400                      "writes to register variables");
1401
1402           /* If the user specified one of the eliminables registers here,
1403              e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1404              confused with that register and be eliminated.  This usage is
1405              somewhat suspect...  */
1406
1407           SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1408           ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1409           REG_USERVAR_P (DECL_RTL (decl)) = 1;
1410
1411           if (TREE_STATIC (decl))
1412             {
1413               /* Make this register global, so not usable for anything
1414                  else.  */
1415 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1416               name = IDENTIFIER_POINTER (DECL_NAME (decl));
1417               ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1418 #endif
1419               nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1420               while (nregs > 0)
1421                 globalize_reg (reg_number + --nregs);
1422             }
1423
1424           /* As a register variable, it has no section.  */
1425           return;
1426         }
1427     }
1428   /* Now handle ordinary static variables and functions (in memory).
1429      Also handle vars declared register invalidly.  */
1430   else if (name[0] == '*')
1431   {
1432 #ifdef REGISTER_PREFIX
1433     if (strlen (REGISTER_PREFIX) != 0)
1434       {
1435         reg_number = decode_reg_name (name);
1436         if (reg_number >= 0 || reg_number == -3)
1437           error ("register name given for non-register variable %q+D", decl);
1438       }
1439 #endif
1440   }
1441
1442   /* Specifying a section attribute on a variable forces it into a
1443      non-.bss section, and thus it cannot be common.  */
1444   /* FIXME: In general this code should not be necessary because
1445      visibility pass is doing the same work.  But notice_global_symbol
1446      is called early and it needs to make DECL_RTL to get the name.
1447      we take care of recomputing the DECL_RTL after visibility is changed.  */
1448   if (TREE_CODE (decl) == VAR_DECL
1449       && DECL_SECTION_NAME (decl) != NULL_TREE
1450       && DECL_INITIAL (decl) == NULL_TREE
1451       && DECL_COMMON (decl))
1452     DECL_COMMON (decl) = 0;
1453
1454   /* Variables can't be both common and weak.  */
1455   if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1456     DECL_COMMON (decl) = 0;
1457
1458   if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1459     x = create_block_symbol (name, get_block_for_decl (decl), -1);
1460   else
1461     {
1462       enum machine_mode address_mode = Pmode;
1463       if (TREE_TYPE (decl) != error_mark_node)
1464         {
1465           addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1466           address_mode = targetm.addr_space.address_mode (as);
1467         }
1468       x = gen_rtx_SYMBOL_REF (address_mode, name);
1469     }
1470   SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1471   SET_SYMBOL_REF_DECL (x, decl);
1472
1473   x = gen_rtx_MEM (DECL_MODE (decl), x);
1474   if (TREE_CODE (decl) != FUNCTION_DECL)
1475     set_mem_attributes (x, decl, 1);
1476   SET_DECL_RTL (decl, x);
1477
1478   /* Optionally set flags or add text to the name to record information
1479      such as that it is a function name.
1480      If the name is changed, the macro ASM_OUTPUT_LABELREF
1481      will have to know how to strip this information.  */
1482   targetm.encode_section_info (decl, DECL_RTL (decl), true);
1483
1484   /* Make this function static known to the mudflap runtime.  */
1485   if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1486     mudflap_enqueue_decl (decl);
1487 }
1488
1489 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1490    calling make_decl_rtl.  Also, reset DECL_RTL before returning the
1491    rtl.  */
1492
1493 rtx
1494 make_decl_rtl_for_debug (tree decl)
1495 {
1496   unsigned int save_aliasing_flag, save_mudflap_flag;
1497   rtx rtl;
1498
1499   if (DECL_RTL_SET_P (decl))
1500     return DECL_RTL (decl);
1501
1502   /* Kludge alert!  Somewhere down the call chain, make_decl_rtl will
1503      call new_alias_set.  If running with -fcompare-debug, sometimes
1504      we do not want to create alias sets that will throw the alias
1505      numbers off in the comparison dumps.  So... clearing
1506      flag_strict_aliasing will keep new_alias_set() from creating a
1507      new set.  It is undesirable to register decl with mudflap
1508      in this case as well.  */
1509   save_aliasing_flag = flag_strict_aliasing;
1510   flag_strict_aliasing = 0;
1511   save_mudflap_flag = flag_mudflap;
1512   flag_mudflap = 0;
1513
1514   rtl = DECL_RTL (decl);
1515   /* Reset DECL_RTL back, as various parts of the compiler expects
1516      DECL_RTL set meaning it is actually going to be output.  */
1517   SET_DECL_RTL (decl, NULL);
1518
1519   flag_strict_aliasing = save_aliasing_flag;
1520   flag_mudflap = save_mudflap_flag;
1521
1522   return rtl;
1523 }
1524 \f
1525 /* Output a string of literal assembler code
1526    for an `asm' keyword used between functions.  */
1527
1528 void
1529 assemble_asm (tree string)
1530 {
1531   app_enable ();
1532
1533   if (TREE_CODE (string) == ADDR_EXPR)
1534     string = TREE_OPERAND (string, 0);
1535
1536   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1537 }
1538
1539 /* Record an element in the table of global destructors.  SYMBOL is
1540    a SYMBOL_REF of the function to be called; PRIORITY is a number
1541    between 0 and MAX_INIT_PRIORITY.  */
1542
1543 void
1544 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1545                                   int priority ATTRIBUTE_UNUSED)
1546 {
1547 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1548   /* Tell GNU LD that this is part of the static destructor set.
1549      This will work for any system that uses stabs, most usefully
1550      aout systems.  */
1551   dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1552   dbxout_stab_value_label (XSTR (symbol, 0));
1553 #else
1554   sorry ("global destructors not supported on this target");
1555 #endif
1556 }
1557
1558 /* Write the address of the entity given by SYMBOL to SEC.  */
1559 void
1560 assemble_addr_to_section (rtx symbol, section *sec)
1561 {
1562   switch_to_section (sec);
1563   assemble_align (POINTER_SIZE);
1564   assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1565 }
1566
1567 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1568    not) section for PRIORITY.  */
1569 section *
1570 get_cdtor_priority_section (int priority, bool constructor_p)
1571 {
1572   char buf[16];
1573
1574   /* ??? This only works reliably with the GNU linker.  */
1575   sprintf (buf, "%s.%.5u",
1576            constructor_p ? ".ctors" : ".dtors",
1577            /* Invert the numbering so the linker puts us in the proper
1578               order; constructors are run from right to left, and the
1579               linker sorts in increasing order.  */
1580            MAX_INIT_PRIORITY - priority);
1581   return get_section (buf, SECTION_WRITE, NULL);
1582 }
1583
1584 void
1585 default_named_section_asm_out_destructor (rtx symbol, int priority)
1586 {
1587   section *sec;
1588
1589   if (priority != DEFAULT_INIT_PRIORITY)
1590     sec = get_cdtor_priority_section (priority,
1591                                       /*constructor_p=*/false);
1592   else
1593     sec = get_section (".dtors", SECTION_WRITE, NULL);
1594
1595   assemble_addr_to_section (symbol, sec);
1596 }
1597
1598 #ifdef DTORS_SECTION_ASM_OP
1599 void
1600 default_dtor_section_asm_out_destructor (rtx symbol,
1601                                          int priority ATTRIBUTE_UNUSED)
1602 {
1603   assemble_addr_to_section (symbol, dtors_section);
1604 }
1605 #endif
1606
1607 /* Likewise for global constructors.  */
1608
1609 void
1610 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1611                                    int priority ATTRIBUTE_UNUSED)
1612 {
1613 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1614   /* Tell GNU LD that this is part of the static destructor set.
1615      This will work for any system that uses stabs, most usefully
1616      aout systems.  */
1617   dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1618   dbxout_stab_value_label (XSTR (symbol, 0));
1619 #else
1620   sorry ("global constructors not supported on this target");
1621 #endif
1622 }
1623
1624 void
1625 default_named_section_asm_out_constructor (rtx symbol, int priority)
1626 {
1627   section *sec;
1628
1629   if (priority != DEFAULT_INIT_PRIORITY)
1630     sec = get_cdtor_priority_section (priority,
1631                                       /*constructor_p=*/true);
1632   else
1633     sec = get_section (".ctors", SECTION_WRITE, NULL);
1634
1635   assemble_addr_to_section (symbol, sec);
1636 }
1637
1638 #ifdef CTORS_SECTION_ASM_OP
1639 void
1640 default_ctor_section_asm_out_constructor (rtx symbol,
1641                                           int priority ATTRIBUTE_UNUSED)
1642 {
1643   assemble_addr_to_section (symbol, ctors_section);
1644 }
1645 #endif
1646 \f
1647 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1648    a nonzero value if the constant pool should be output before the
1649    start of the function, or a zero value if the pool should output
1650    after the end of the function.  The default is to put it before the
1651    start.  */
1652
1653 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1654 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1655 #endif
1656
1657 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1658    to be output to assembler.
1659    Set first_global_object_name and weak_global_object_name as appropriate.  */
1660
1661 void
1662 notice_global_symbol (tree decl)
1663 {
1664   const char **type = &first_global_object_name;
1665
1666   if (first_global_object_name
1667       || !TREE_PUBLIC (decl)
1668       || DECL_EXTERNAL (decl)
1669       || !DECL_NAME (decl)
1670       || (TREE_CODE (decl) != FUNCTION_DECL
1671           && (TREE_CODE (decl) != VAR_DECL
1672               || (DECL_COMMON (decl)
1673                   && (DECL_INITIAL (decl) == 0
1674                       || DECL_INITIAL (decl) == error_mark_node))))
1675       || !MEM_P (DECL_RTL (decl)))
1676     return;
1677
1678   /* We win when global object is found, but it is useful to know about weak
1679      symbol as well so we can produce nicer unique names.  */
1680   if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1681     type = &weak_global_object_name;
1682
1683   if (!*type)
1684     {
1685       const char *p;
1686       const char *name;
1687       rtx decl_rtl = DECL_RTL (decl);
1688
1689       p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1690       name = ggc_strdup (p);
1691
1692       *type = name;
1693     }
1694 }
1695
1696 /* Output assembler code for the constant pool of a function and associated
1697    with defining the name of the function.  DECL describes the function.
1698    NAME is the function's name.  For the constant pool, we use the current
1699    constant pool data.  */
1700
1701 void
1702 assemble_start_function (tree decl, const char *fnname)
1703 {
1704   int align;
1705   char tmp_label[100];
1706   bool hot_label_written = false;
1707
1708   crtl->subsections.unlikely_text_section_name = NULL;
1709
1710   first_function_block_is_cold = false;
1711   if (flag_reorder_blocks_and_partition)
1712     {
1713       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1714       crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1715       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1716       crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1717       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1718       crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1719       ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1720       crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1721       const_labelno++;
1722     }
1723   else
1724     {
1725       crtl->subsections.hot_section_label = NULL;
1726       crtl->subsections.cold_section_label = NULL;
1727       crtl->subsections.hot_section_end_label = NULL;
1728       crtl->subsections.cold_section_end_label = NULL;
1729     }
1730
1731   /* The following code does not need preprocessing in the assembler.  */
1732
1733   app_disable ();
1734
1735   if (CONSTANT_POOL_BEFORE_FUNCTION)
1736     output_constant_pool (fnname, decl);
1737
1738   resolve_unique_section (decl, 0, flag_function_sections);
1739
1740   /* Make sure the not and cold text (code) sections are properly
1741      aligned.  This is necessary here in the case where the function
1742      has both hot and cold sections, because we don't want to re-set
1743      the alignment when the section switch happens mid-function.  */
1744
1745   if (flag_reorder_blocks_and_partition)
1746     {
1747       switch_to_section (unlikely_text_section ());
1748       assemble_align (DECL_ALIGN (decl));
1749       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1750
1751       /* When the function starts with a cold section, we need to explicitly
1752          align the hot section and write out the hot section label.
1753          But if the current function is a thunk, we do not have a CFG.  */
1754       if (!cfun->is_thunk
1755           && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1756         {
1757           switch_to_section (text_section);
1758           assemble_align (DECL_ALIGN (decl));
1759           ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1760           hot_label_written = true;
1761           first_function_block_is_cold = true;
1762         }
1763     }
1764   else if (DECL_SECTION_NAME (decl))
1765     {
1766       /* Calls to function_section rely on first_function_block_is_cold
1767          being accurate.  The first block may be cold even if we aren't
1768          doing partitioning, if the entire function was decided by
1769          choose_function_section (predict.c) to be cold.  */
1770
1771       initialize_cold_section_name ();
1772
1773       if (crtl->subsections.unlikely_text_section_name
1774           && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1775                      crtl->subsections.unlikely_text_section_name) == 0)
1776         first_function_block_is_cold = true;
1777     }
1778
1779   in_cold_section_p = first_function_block_is_cold;
1780
1781   /* Switch to the correct text section for the start of the function.  */
1782
1783   switch_to_section (function_section (decl));
1784   if (flag_reorder_blocks_and_partition
1785       && !hot_label_written)
1786     ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1787
1788   /* Tell assembler to move to target machine's alignment for functions.  */
1789   align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1790   if (align > 0)
1791     {
1792       ASM_OUTPUT_ALIGN (asm_out_file, align);
1793     }
1794
1795   /* Handle a user-specified function alignment.
1796      Note that we still need to align to DECL_ALIGN, as above,
1797      because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all.  */
1798   if (! DECL_USER_ALIGN (decl)
1799       && align_functions_log > align
1800       && optimize_function_for_speed_p (cfun))
1801     {
1802 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1803       ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1804                                  align_functions_log, align_functions - 1);
1805 #else
1806       ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1807 #endif
1808     }
1809
1810 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1811   ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1812 #endif
1813
1814   if (!DECL_IGNORED_P (decl))
1815     (*debug_hooks->begin_function) (decl);
1816
1817   /* Make function name accessible from other files, if appropriate.  */
1818
1819   if (TREE_PUBLIC (decl))
1820     {
1821       notice_global_symbol (decl);
1822
1823       globalize_decl (decl);
1824
1825       maybe_assemble_visibility (decl);
1826     }
1827
1828   if (DECL_PRESERVE_P (decl))
1829     targetm.asm_out.mark_decl_preserved (fnname);
1830
1831   /* Do any machine/system dependent processing of the function name.  */
1832 #ifdef ASM_DECLARE_FUNCTION_NAME
1833   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1834 #else
1835   /* Standard thing is just output label for the function.  */
1836   ASM_OUTPUT_LABEL (asm_out_file, fnname);
1837 #endif /* ASM_DECLARE_FUNCTION_NAME */
1838 }
1839
1840 /* Output assembler code associated with defining the size of the
1841    function.  DECL describes the function.  NAME is the function's name.  */
1842
1843 void
1844 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1845 {
1846 #ifdef ASM_DECLARE_FUNCTION_SIZE
1847   /* We could have switched section in the middle of the function.  */
1848   if (flag_reorder_blocks_and_partition)
1849     switch_to_section (function_section (decl));
1850   ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1851 #endif
1852   if (! CONSTANT_POOL_BEFORE_FUNCTION)
1853     {
1854       output_constant_pool (fnname, decl);
1855       switch_to_section (function_section (decl)); /* need to switch back */
1856     }
1857   /* Output labels for end of hot/cold text sections (to be used by
1858      debug info.)  */
1859   if (flag_reorder_blocks_and_partition)
1860     {
1861       section *save_text_section;
1862
1863       save_text_section = in_section;
1864       switch_to_section (unlikely_text_section ());
1865       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1866       if (first_function_block_is_cold)
1867         switch_to_section (text_section);
1868       else
1869         switch_to_section (function_section (decl));
1870       ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1871       switch_to_section (save_text_section);
1872     }
1873 }
1874 \f
1875 /* Assemble code to leave SIZE bytes of zeros.  */
1876
1877 void
1878 assemble_zeros (unsigned HOST_WIDE_INT size)
1879 {
1880   /* Do no output if -fsyntax-only.  */
1881   if (flag_syntax_only)
1882     return;
1883
1884 #ifdef ASM_NO_SKIP_IN_TEXT
1885   /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1886      so we must output 0s explicitly in the text section.  */
1887   if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1888     {
1889       unsigned HOST_WIDE_INT i;
1890       for (i = 0; i < size; i++)
1891         assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1892     }
1893   else
1894 #endif
1895     if (size > 0)
1896       ASM_OUTPUT_SKIP (asm_out_file, size);
1897 }
1898
1899 /* Assemble an alignment pseudo op for an ALIGN-bit boundary.  */
1900
1901 void
1902 assemble_align (int align)
1903 {
1904   if (align > BITS_PER_UNIT)
1905     {
1906       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1907     }
1908 }
1909
1910 /* Assemble a string constant with the specified C string as contents.  */
1911
1912 void
1913 assemble_string (const char *p, int size)
1914 {
1915   int pos = 0;
1916   int maximum = 2000;
1917
1918   /* If the string is very long, split it up.  */
1919
1920   while (pos < size)
1921     {
1922       int thissize = size - pos;
1923       if (thissize > maximum)
1924         thissize = maximum;
1925
1926       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1927
1928       pos += thissize;
1929       p += thissize;
1930     }
1931 }
1932
1933 \f
1934 /* A noswitch_section_callback for lcomm_section.  */
1935
1936 static bool
1937 emit_local (tree decl ATTRIBUTE_UNUSED,
1938             const char *name ATTRIBUTE_UNUSED,
1939             unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1940             unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1941 {
1942 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1943   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1944                                  size, DECL_ALIGN (decl));
1945   return true;
1946 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1947   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1948   return true;
1949 #else
1950   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1951   return false;
1952 #endif
1953 }
1954
1955 /* A noswitch_section_callback for bss_noswitch_section.  */
1956
1957 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1958 static bool
1959 emit_bss (tree decl ATTRIBUTE_UNUSED,
1960           const char *name ATTRIBUTE_UNUSED,
1961           unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1962           unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1963 {
1964 #if defined ASM_OUTPUT_ALIGNED_BSS
1965   ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1966   return true;
1967 #else
1968   ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1969   return false;
1970 #endif
1971 }
1972 #endif
1973
1974 /* A noswitch_section_callback for comm_section.  */
1975
1976 static bool
1977 emit_common (tree decl ATTRIBUTE_UNUSED,
1978              const char *name ATTRIBUTE_UNUSED,
1979              unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1980              unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1981 {
1982 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1983   ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1984                                   size, DECL_ALIGN (decl));
1985   return true;
1986 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1987   ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1988   return true;
1989 #else
1990   ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1991   return false;
1992 #endif
1993 }
1994
1995 /* A noswitch_section_callback for tls_comm_section.  */
1996
1997 static bool
1998 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1999                  const char *name ATTRIBUTE_UNUSED,
2000                  unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2001                  unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2002 {
2003 #ifdef ASM_OUTPUT_TLS_COMMON
2004   ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2005   return true;
2006 #else
2007   sorry ("thread-local COMMON data not implemented");
2008   return true;
2009 #endif
2010 }
2011
2012 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2013    NAME is the name of DECL's SYMBOL_REF.  */
2014
2015 static void
2016 assemble_noswitch_variable (tree decl, const char *name, section *sect)
2017 {
2018   unsigned HOST_WIDE_INT size, rounded;
2019
2020   size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
2021   rounded = size;
2022
2023   /* Don't allocate zero bytes of common,
2024      since that means "undefined external" in the linker.  */
2025   if (size == 0)
2026     rounded = 1;
2027
2028   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2029      so that each uninitialized object starts on such a boundary.  */
2030   rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2031   rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2032              * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2033
2034   if (!sect->noswitch.callback (decl, name, size, rounded)
2035       && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
2036     warning (0, "requested alignment for %q+D is greater than "
2037              "implemented alignment of %wu", decl, rounded);
2038 }
2039
2040 /* A subroutine of assemble_variable.  Output the label and contents of
2041    DECL, whose address is a SYMBOL_REF with name NAME.  DONT_OUTPUT_DATA
2042    is as for assemble_variable.  */
2043
2044 static void
2045 assemble_variable_contents (tree decl, const char *name,
2046                             bool dont_output_data)
2047 {
2048   /* Do any machine/system dependent processing of the object.  */
2049 #ifdef ASM_DECLARE_OBJECT_NAME
2050   last_assemble_variable_decl = decl;
2051   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2052 #else
2053   /* Standard thing is just output label for the object.  */
2054   ASM_OUTPUT_LABEL (asm_out_file, name);
2055 #endif /* ASM_DECLARE_OBJECT_NAME */
2056
2057   if (!dont_output_data)
2058     {
2059       if (DECL_INITIAL (decl)
2060           && DECL_INITIAL (decl) != error_mark_node
2061           && !initializer_zerop (DECL_INITIAL (decl)))
2062         /* Output the actual data.  */
2063         output_constant (DECL_INITIAL (decl),
2064                          tree_low_cst (DECL_SIZE_UNIT (decl), 1),
2065                          DECL_ALIGN (decl));
2066       else
2067         /* Leave space for it.  */
2068         assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2069     }
2070 }
2071
2072 /* Initialize emulated tls object TO, which refers to TLS variable
2073    DECL and is initialized by PROXY.  */
2074
2075 tree
2076 default_emutls_var_init (tree to, tree decl, tree proxy)
2077 {
2078   VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2079   constructor_elt *elt;
2080   tree type = TREE_TYPE (to);
2081   tree field = TYPE_FIELDS (type);
2082
2083   elt = VEC_quick_push (constructor_elt, v, NULL);
2084   elt->index = field;
2085   elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2086
2087   elt = VEC_quick_push (constructor_elt, v, NULL);
2088   field = TREE_CHAIN (field);
2089   elt->index = field;
2090   elt->value = build_int_cst (TREE_TYPE (field),
2091                               DECL_ALIGN_UNIT (decl));
2092
2093   elt = VEC_quick_push (constructor_elt, v, NULL);
2094   field = TREE_CHAIN (field);
2095   elt->index = field;
2096   elt->value = null_pointer_node;
2097
2098   elt = VEC_quick_push (constructor_elt, v, NULL);
2099   field = TREE_CHAIN (field);
2100   elt->index = field;
2101   elt->value = proxy;
2102
2103   return build_constructor (type, v);
2104 }
2105
2106 /* Assemble everything that is needed for a variable or function declaration.
2107    Not used for automatic variables, and not used for function definitions.
2108    Should not be called for variables of incomplete structure type.
2109
2110    TOP_LEVEL is nonzero if this variable has file scope.
2111    AT_END is nonzero if this is the special handling, at end of compilation,
2112    to define things that have had only tentative definitions.
2113    DONT_OUTPUT_DATA if nonzero means don't actually output the
2114    initial value (that will be done by the caller).  */
2115
2116 void
2117 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2118                    int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2119 {
2120   const char *name;
2121   rtx decl_rtl, symbol;
2122   section *sect;
2123
2124   if (! targetm.have_tls
2125       && TREE_CODE (decl) == VAR_DECL
2126       && DECL_THREAD_LOCAL_P (decl))
2127     {
2128       tree to = emutls_decl (decl);
2129
2130       /* If this variable is defined locally, then we need to initialize the
2131          control structure with size and alignment information.  We do this
2132          at the last moment because tentative definitions can take a locally
2133          defined but uninitialized variable and initialize it later, which
2134          would result in incorrect contents.  */
2135       if (! DECL_EXTERNAL (to)
2136           && (! DECL_COMMON (to)
2137               || (DECL_INITIAL (decl)
2138                   && DECL_INITIAL (decl) != error_mark_node)))
2139         {
2140           DECL_INITIAL (to) = targetm.emutls.var_init
2141             (to, decl, get_emutls_init_templ_addr (decl));
2142
2143           /* Make sure the template is marked as needed early enough.
2144              Without this, if the variable is placed in a
2145              section-anchored block, the template will only be marked
2146              when it's too late.  */
2147           record_references_in_initializer (to, false);
2148         }
2149
2150       decl = to;
2151     }
2152
2153   last_assemble_variable_decl = 0;
2154
2155   /* Normally no need to say anything here for external references,
2156      since assemble_external is called by the language-specific code
2157      when a declaration is first seen.  */
2158
2159   if (DECL_EXTERNAL (decl))
2160     return;
2161
2162   /* Output no assembler code for a function declaration.
2163      Only definitions of functions output anything.  */
2164
2165   if (TREE_CODE (decl) == FUNCTION_DECL)
2166     return;
2167
2168   /* Do nothing for global register variables.  */
2169   if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2170     {
2171       TREE_ASM_WRITTEN (decl) = 1;
2172       return;
2173     }
2174
2175   /* If type was incomplete when the variable was declared,
2176      see if it is complete now.  */
2177
2178   if (DECL_SIZE (decl) == 0)
2179     layout_decl (decl, 0);
2180
2181   /* Still incomplete => don't allocate it; treat the tentative defn
2182      (which is what it must have been) as an `extern' reference.  */
2183
2184   if (!dont_output_data && DECL_SIZE (decl) == 0)
2185     {
2186       error ("storage size of %q+D isn%'t known", decl);
2187       TREE_ASM_WRITTEN (decl) = 1;
2188       return;
2189     }
2190
2191   /* The first declaration of a variable that comes through this function
2192      decides whether it is global (in C, has external linkage)
2193      or local (in C, has internal linkage).  So do nothing more
2194      if this function has already run.  */
2195
2196   if (TREE_ASM_WRITTEN (decl))
2197     return;
2198
2199   /* Make sure targetm.encode_section_info is invoked before we set
2200      ASM_WRITTEN.  */
2201   decl_rtl = DECL_RTL (decl);
2202
2203   TREE_ASM_WRITTEN (decl) = 1;
2204
2205   /* Do no output if -fsyntax-only.  */
2206   if (flag_syntax_only)
2207     return;
2208
2209   if (! dont_output_data
2210       && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2211     {
2212       error ("size of variable %q+D is too large", decl);
2213       return;
2214     }
2215
2216   gcc_assert (MEM_P (decl_rtl));
2217   gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2218   symbol = XEXP (decl_rtl, 0);
2219
2220   /* If this symbol belongs to the tree constant pool, output the constant
2221      if it hasn't already been written.  */
2222   if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2223     {
2224       tree decl = SYMBOL_REF_DECL (symbol);
2225       if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2226         output_constant_def_contents (symbol);
2227       return;
2228     }
2229
2230   app_disable ();
2231
2232   name = XSTR (symbol, 0);
2233   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2234     notice_global_symbol (decl);
2235
2236   /* Compute the alignment of this data.  */
2237
2238   align_variable (decl, dont_output_data);
2239   set_mem_align (decl_rtl, DECL_ALIGN (decl));
2240
2241   if (TREE_PUBLIC (decl))
2242     maybe_assemble_visibility (decl);
2243
2244   if (DECL_PRESERVE_P (decl))
2245     targetm.asm_out.mark_decl_preserved (name);
2246
2247   /* First make the assembler name(s) global if appropriate.  */
2248   sect = get_variable_section (decl, false);
2249   if (TREE_PUBLIC (decl)
2250       && (sect->common.flags & SECTION_COMMON) == 0)
2251     globalize_decl (decl);
2252
2253   /* Output any data that we will need to use the address of.  */
2254   if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2255     output_addressed_constants (DECL_INITIAL (decl));
2256
2257   /* dbxout.c needs to know this.  */
2258   if (sect && (sect->common.flags & SECTION_CODE) != 0)
2259     DECL_IN_TEXT_SECTION (decl) = 1;
2260
2261   /* If the decl is part of an object_block, make sure that the decl
2262      has been positioned within its block, but do not write out its
2263      definition yet.  output_object_blocks will do that later.  */
2264   if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2265     {
2266       gcc_assert (!dont_output_data);
2267       place_block_symbol (symbol);
2268     }
2269   else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2270     assemble_noswitch_variable (decl, name, sect);
2271   else
2272     {
2273       switch_to_section (sect);
2274       if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2275         ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2276       assemble_variable_contents (decl, name, dont_output_data);
2277     }
2278 }
2279
2280 /* Return 1 if type TYPE contains any pointers.  */
2281
2282 static int
2283 contains_pointers_p (tree type)
2284 {
2285   switch (TREE_CODE (type))
2286     {
2287     case POINTER_TYPE:
2288     case REFERENCE_TYPE:
2289       /* I'm not sure whether OFFSET_TYPE needs this treatment,
2290          so I'll play safe and return 1.  */
2291     case OFFSET_TYPE:
2292       return 1;
2293
2294     case RECORD_TYPE:
2295     case UNION_TYPE:
2296     case QUAL_UNION_TYPE:
2297       {
2298         tree fields;
2299         /* For a type that has fields, see if the fields have pointers.  */
2300         for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2301           if (TREE_CODE (fields) == FIELD_DECL
2302               && contains_pointers_p (TREE_TYPE (fields)))
2303             return 1;
2304         return 0;
2305       }
2306
2307     case ARRAY_TYPE:
2308       /* An array type contains pointers if its element type does.  */
2309       return contains_pointers_p (TREE_TYPE (type));
2310
2311     default:
2312       return 0;
2313     }
2314 }
2315
2316 /* We delay assemble_external processing until
2317    the compilation unit is finalized.  This is the best we can do for
2318    right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2319    it all the way to final.  See PR 17982 for further discussion.  */
2320 static GTY(()) tree pending_assemble_externals;
2321
2322 #ifdef ASM_OUTPUT_EXTERNAL
2323 /* True if DECL is a function decl for which no out-of-line copy exists.
2324    It is assumed that DECL's assembler name has been set.  */
2325
2326 static bool
2327 incorporeal_function_p (tree decl)
2328 {
2329   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2330     {
2331       const char *name;
2332
2333       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2334           && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2335         return true;
2336
2337       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2338       if (is_builtin_name (name))
2339         return true;
2340     }
2341   return false;
2342 }
2343
2344 /* Actually do the tests to determine if this is necessary, and invoke
2345    ASM_OUTPUT_EXTERNAL.  */
2346 static void
2347 assemble_external_real (tree decl)
2348 {
2349   rtx rtl = DECL_RTL (decl);
2350
2351   if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2352       && !SYMBOL_REF_USED (XEXP (rtl, 0))
2353       && !incorporeal_function_p (decl))
2354     {
2355       /* Some systems do require some output.  */
2356       SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2357       ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2358     }
2359 }
2360 #endif
2361
2362 void
2363 process_pending_assemble_externals (void)
2364 {
2365 #ifdef ASM_OUTPUT_EXTERNAL
2366   tree list;
2367   for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2368     assemble_external_real (TREE_VALUE (list));
2369
2370   pending_assemble_externals = 0;
2371 #endif
2372 }
2373
2374 /* This TREE_LIST contains any weak symbol declarations waiting
2375    to be emitted.  */
2376 static GTY(()) tree weak_decls;
2377
2378 /* Output something to declare an external symbol to the assembler,
2379    and qualifiers such as weakness.  (Most assemblers don't need
2380    extern declaration, so we normally output nothing.)  Do nothing if
2381    DECL is not external.  */
2382
2383 void
2384 assemble_external (tree decl ATTRIBUTE_UNUSED)
2385 {
2386   /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2387      main body of this code is only rarely exercised.  To provide some
2388      testing, on all platforms, we make sure that the ASM_OUT_FILE is
2389      open.  If it's not, we should not be calling this function.  */
2390   gcc_assert (asm_out_file);
2391
2392   if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2393     return;
2394
2395   /* We want to output annotation for weak and external symbols at
2396      very last to check if they are references or not.  */
2397
2398   if (SUPPORTS_WEAK
2399       && DECL_WEAK (decl)
2400       /* TREE_STATIC is a weird and abused creature which is not
2401          generally the right test for whether an entity has been
2402          locally emitted, inlined or otherwise not-really-extern, but
2403          for declarations that can be weak, it happens to be
2404          match.  */
2405       && !TREE_STATIC (decl)
2406       && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2407       && value_member (decl, weak_decls) == NULL_TREE)
2408     weak_decls = tree_cons (NULL, decl, weak_decls);
2409
2410 #ifdef ASM_OUTPUT_EXTERNAL
2411   if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2412     pending_assemble_externals = tree_cons (NULL, decl,
2413                                             pending_assemble_externals);
2414 #endif
2415 }
2416
2417 /* Similar, for calling a library function FUN.  */
2418
2419 void
2420 assemble_external_libcall (rtx fun)
2421 {
2422   /* Declare library function name external when first used, if nec.  */
2423   if (! SYMBOL_REF_USED (fun))
2424     {
2425       SYMBOL_REF_USED (fun) = 1;
2426       targetm.asm_out.external_libcall (fun);
2427     }
2428 }
2429
2430 /* Assemble a label named NAME.  */
2431
2432 void
2433 assemble_label (const char *name)
2434 {
2435   ASM_OUTPUT_LABEL (asm_out_file, name);
2436 }
2437
2438 /* Set the symbol_referenced flag for ID.  */
2439 void
2440 mark_referenced (tree id)
2441 {
2442   TREE_SYMBOL_REFERENCED (id) = 1;
2443 }
2444
2445 /* Set the symbol_referenced flag for DECL and notify callgraph.  */
2446 void
2447 mark_decl_referenced (tree decl)
2448 {
2449   if (TREE_CODE (decl) == FUNCTION_DECL)
2450     {
2451       /* Extern inline functions don't become needed when referenced.
2452          If we know a method will be emitted in other TU and no new
2453          functions can be marked reachable, just use the external
2454          definition.  */
2455       struct cgraph_node *node = cgraph_node (decl);
2456       if (!DECL_EXTERNAL (decl)
2457           && (!node->local.vtable_method || !cgraph_global_info_ready
2458               || !node->local.finalized))
2459         cgraph_mark_needed_node (node);
2460     }
2461   else if (TREE_CODE (decl) == VAR_DECL)
2462     {
2463       struct varpool_node *node = varpool_node (decl);
2464       varpool_mark_needed_node (node);
2465       /* C++ frontend use mark_decl_references to force COMDAT variables
2466          to be output that might appear dead otherwise.  */
2467       node->force_output = true;
2468     }
2469   /* else do nothing - we can get various sorts of CST nodes here,
2470      which do not need to be marked.  */
2471 }
2472
2473
2474 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2475    until we find an identifier that is not itself a transparent alias.
2476    Modify the alias passed to it by reference (and all aliases on the
2477    way to the ultimate target), such that they do not have to be
2478    followed again, and return the ultimate target of the alias
2479    chain.  */
2480
2481 static inline tree
2482 ultimate_transparent_alias_target (tree *alias)
2483 {
2484   tree target = *alias;
2485
2486   if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2487     {
2488       gcc_assert (TREE_CHAIN (target));
2489       target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2490       gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2491                   && ! TREE_CHAIN (target));
2492       *alias = target;
2493     }
2494
2495   return target;
2496 }
2497
2498 /* Output to FILE (an assembly file) a reference to NAME.  If NAME
2499    starts with a *, the rest of NAME is output verbatim.  Otherwise
2500    NAME is transformed in a target-specific way (usually by the
2501    addition of an underscore).  */
2502
2503 void
2504 assemble_name_raw (FILE *file, const char *name)
2505 {
2506   if (name[0] == '*')
2507     fputs (&name[1], file);
2508   else
2509     ASM_OUTPUT_LABELREF (file, name);
2510 }
2511
2512 /* Like assemble_name_raw, but should be used when NAME might refer to
2513    an entity that is also represented as a tree (like a function or
2514    variable).  If NAME does refer to such an entity, that entity will
2515    be marked as referenced.  */
2516
2517 void
2518 assemble_name (FILE *file, const char *name)
2519 {
2520   const char *real_name;
2521   tree id;
2522
2523   real_name = targetm.strip_name_encoding (name);
2524
2525   id = maybe_get_identifier (real_name);
2526   if (id)
2527     {
2528       tree id_orig = id;
2529
2530       mark_referenced (id);
2531       ultimate_transparent_alias_target (&id);
2532       if (id != id_orig)
2533         name = IDENTIFIER_POINTER (id);
2534       gcc_assert (! TREE_CHAIN (id));
2535     }
2536
2537   assemble_name_raw (file, name);
2538 }
2539
2540 /* Allocate SIZE bytes writable static space with a gensym name
2541    and return an RTX to refer to its address.  */
2542
2543 rtx
2544 assemble_static_space (unsigned HOST_WIDE_INT size)
2545 {
2546   char name[12];
2547   const char *namestring;
2548   rtx x;
2549
2550   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2551   ++const_labelno;
2552   namestring = ggc_strdup (name);
2553
2554   x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2555   SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2556
2557 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2558   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2559                                  BIGGEST_ALIGNMENT);
2560 #else
2561 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2562   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2563 #else
2564   {
2565     /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2566        so that each uninitialized object starts on such a boundary.  */
2567     /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL.  */
2568     unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2569       = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2570          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2571          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2572     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2573   }
2574 #endif
2575 #endif
2576   return x;
2577 }
2578
2579 /* Assemble the static constant template for function entry trampolines.
2580    This is done at most once per compilation.
2581    Returns an RTX for the address of the template.  */
2582
2583 static GTY(()) rtx initial_trampoline;
2584
2585 rtx
2586 assemble_trampoline_template (void)
2587 {
2588   char label[256];
2589   const char *name;
2590   int align;
2591   rtx symbol;
2592
2593   gcc_assert (targetm.asm_out.trampoline_template != NULL);
2594
2595   if (initial_trampoline)
2596     return initial_trampoline;
2597
2598   /* By default, put trampoline templates in read-only data section.  */
2599
2600 #ifdef TRAMPOLINE_SECTION
2601   switch_to_section (TRAMPOLINE_SECTION);
2602 #else
2603   switch_to_section (readonly_data_section);
2604 #endif
2605
2606   /* Write the assembler code to define one.  */
2607   align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2608   if (align > 0)
2609     ASM_OUTPUT_ALIGN (asm_out_file, align);
2610
2611   targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2612   targetm.asm_out.trampoline_template (asm_out_file);
2613
2614   /* Record the rtl to refer to it.  */
2615   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2616   name = ggc_strdup (label);
2617   symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2618   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2619
2620   initial_trampoline = gen_const_mem (BLKmode, symbol);
2621   set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2622   set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2623
2624   return initial_trampoline;
2625 }
2626 \f
2627 /* A and B are either alignments or offsets.  Return the minimum alignment
2628    that may be assumed after adding the two together.  */
2629
2630 static inline unsigned
2631 min_align (unsigned int a, unsigned int b)
2632 {
2633   return (a | b) & -(a | b);
2634 }
2635
2636 /* Return the assembler directive for creating a given kind of integer
2637    object.  SIZE is the number of bytes in the object and ALIGNED_P
2638    indicates whether it is known to be aligned.  Return NULL if the
2639    assembly dialect has no such directive.
2640
2641    The returned string should be printed at the start of a new line and
2642    be followed immediately by the object's initial value.  */
2643
2644 const char *
2645 integer_asm_op (int size, int aligned_p)
2646 {
2647   struct asm_int_op *ops;
2648
2649   if (aligned_p)
2650     ops = &targetm.asm_out.aligned_op;
2651   else
2652     ops = &targetm.asm_out.unaligned_op;
2653
2654   switch (size)
2655     {
2656     case 1:
2657       return targetm.asm_out.byte_op;
2658     case 2:
2659       return ops->hi;
2660     case 4:
2661       return ops->si;
2662     case 8:
2663       return ops->di;
2664     case 16:
2665       return ops->ti;
2666     default:
2667       return NULL;
2668     }
2669 }
2670
2671 /* Use directive OP to assemble an integer object X.  Print OP at the
2672    start of the line, followed immediately by the value of X.  */
2673
2674 void
2675 assemble_integer_with_op (const char *op, rtx x)
2676 {
2677   fputs (op, asm_out_file);
2678   output_addr_const (asm_out_file, x);
2679   fputc ('\n', asm_out_file);
2680 }
2681
2682 /* The default implementation of the asm_out.integer target hook.  */
2683
2684 bool
2685 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2686                           unsigned int size ATTRIBUTE_UNUSED,
2687                           int aligned_p ATTRIBUTE_UNUSED)
2688 {
2689   const char *op = integer_asm_op (size, aligned_p);
2690   /* Avoid GAS bugs for large values.  Specifically negative values whose
2691      absolute value fits in a bfd_vma, but not in a bfd_signed_vma.  */
2692   if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2693     return false;
2694   return op && (assemble_integer_with_op (op, x), true);
2695 }
2696
2697 /* Assemble the integer constant X into an object of SIZE bytes.  ALIGN is
2698    the alignment of the integer in bits.  Return 1 if we were able to output
2699    the constant, otherwise 0.  We must be able to output the constant,
2700    if FORCE is nonzero.  */
2701
2702 bool
2703 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2704 {
2705   int aligned_p;
2706
2707   aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2708
2709   /* See if the target hook can handle this kind of object.  */
2710   if (targetm.asm_out.integer (x, size, aligned_p))
2711     return true;
2712
2713   /* If the object is a multi-byte one, try splitting it up.  Split
2714      it into words it if is multi-word, otherwise split it into bytes.  */
2715   if (size > 1)
2716     {
2717       enum machine_mode omode, imode;
2718       unsigned int subalign;
2719       unsigned int subsize, i;
2720       enum mode_class mclass;
2721
2722       subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2723       subalign = MIN (align, subsize * BITS_PER_UNIT);
2724       if (GET_CODE (x) == CONST_FIXED)
2725         mclass = GET_MODE_CLASS (GET_MODE (x));
2726       else
2727         mclass = MODE_INT;
2728
2729       omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2730       imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2731
2732       for (i = 0; i < size; i += subsize)
2733         {
2734           rtx partial = simplify_subreg (omode, x, imode, i);
2735           if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2736             break;
2737         }
2738       if (i == size)
2739         return true;
2740
2741       /* If we've printed some of it, but not all of it, there's no going
2742          back now.  */
2743       gcc_assert (!i);
2744     }
2745
2746   gcc_assert (!force);
2747
2748   return false;
2749 }
2750 \f
2751 void
2752 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2753 {
2754   long data[4] = {0, 0, 0, 0};
2755   int i;
2756   int bitsize, nelts, nunits, units_per;
2757
2758   /* This is hairy.  We have a quantity of known size.  real_to_target
2759      will put it into an array of *host* longs, 32 bits per element
2760      (even if long is more than 32 bits).  We need to determine the
2761      number of array elements that are occupied (nelts) and the number
2762      of *target* min-addressable units that will be occupied in the
2763      object file (nunits).  We cannot assume that 32 divides the
2764      mode's bitsize (size * BITS_PER_UNIT) evenly.
2765
2766      size * BITS_PER_UNIT is used here to make sure that padding bits
2767      (which might appear at either end of the value; real_to_target
2768      will include the padding bits in its output array) are included.  */
2769
2770   nunits = GET_MODE_SIZE (mode);
2771   bitsize = nunits * BITS_PER_UNIT;
2772   nelts = CEIL (bitsize, 32);
2773   units_per = 32 / BITS_PER_UNIT;
2774
2775   real_to_target (data, &d, mode);
2776
2777   /* Put out the first word with the specified alignment.  */
2778   assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2779   nunits -= units_per;
2780
2781   /* Subsequent words need only 32-bit alignment.  */
2782   align = min_align (align, 32);
2783
2784   for (i = 1; i < nelts; i++)
2785     {
2786       assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2787       nunits -= units_per;
2788     }
2789 }
2790 \f
2791 /* Given an expression EXP with a constant value,
2792    reduce it to the sum of an assembler symbol and an integer.
2793    Store them both in the structure *VALUE.
2794    EXP must be reducible.  */
2795
2796 struct GTY(()) addr_const {
2797   rtx base;
2798   HOST_WIDE_INT offset;
2799 };
2800
2801 static void
2802 decode_addr_const (tree exp, struct addr_const *value)
2803 {
2804   tree target = TREE_OPERAND (exp, 0);
2805   int offset = 0;
2806   rtx x;
2807
2808   while (1)
2809     {
2810       if (TREE_CODE (target) == COMPONENT_REF
2811           && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2812         {
2813           offset += int_byte_position (TREE_OPERAND (target, 1));
2814           target = TREE_OPERAND (target, 0);
2815         }
2816       else if (TREE_CODE (target) == ARRAY_REF
2817                || TREE_CODE (target) == ARRAY_RANGE_REF)
2818         {
2819           offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2820                      * tree_low_cst (TREE_OPERAND (target, 1), 0));
2821           target = TREE_OPERAND (target, 0);
2822         }
2823       else if (TREE_CODE (target) == INDIRECT_REF
2824                && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2825                && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2826                   == ADDR_EXPR)
2827         target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2828       else
2829         break;
2830     }
2831
2832   switch (TREE_CODE (target))
2833     {
2834     case VAR_DECL:
2835     case FUNCTION_DECL:
2836       x = DECL_RTL (target);
2837       break;
2838
2839     case LABEL_DECL:
2840       x = gen_rtx_MEM (FUNCTION_MODE,
2841                        gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2842       break;
2843
2844     case REAL_CST:
2845     case FIXED_CST:
2846     case STRING_CST:
2847     case COMPLEX_CST:
2848     case CONSTRUCTOR:
2849     case INTEGER_CST:
2850       x = output_constant_def (target, 1);
2851       break;
2852
2853     default:
2854       gcc_unreachable ();
2855     }
2856
2857   gcc_assert (MEM_P (x));
2858   x = XEXP (x, 0);
2859
2860   value->base = x;
2861   value->offset = offset;
2862 }
2863 \f
2864
2865 static GTY((param_is (struct constant_descriptor_tree)))
2866      htab_t const_desc_htab;
2867
2868 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2869
2870 /* Constant pool accessor function.  */
2871
2872 htab_t
2873 constant_pool_htab (void)
2874 {
2875   return const_desc_htab;
2876 }
2877
2878 /* Compute a hash code for a constant expression.  */
2879
2880 static hashval_t
2881 const_desc_hash (const void *ptr)
2882 {
2883   return ((const struct constant_descriptor_tree *)ptr)->hash;
2884 }
2885
2886 static hashval_t
2887 const_hash_1 (const tree exp)
2888 {
2889   const char *p;
2890   hashval_t hi;
2891   int len, i;
2892   enum tree_code code = TREE_CODE (exp);
2893
2894   /* Either set P and LEN to the address and len of something to hash and
2895      exit the switch or return a value.  */
2896
2897   switch (code)
2898     {
2899     case INTEGER_CST:
2900       p = (char *) &TREE_INT_CST (exp);
2901       len = sizeof TREE_INT_CST (exp);
2902       break;
2903
2904     case REAL_CST:
2905       return real_hash (TREE_REAL_CST_PTR (exp));
2906
2907     case FIXED_CST:
2908       return fixed_hash (TREE_FIXED_CST_PTR (exp));
2909
2910     case STRING_CST:
2911       p = TREE_STRING_POINTER (exp);
2912       len = TREE_STRING_LENGTH (exp);
2913       break;
2914
2915     case COMPLEX_CST:
2916       return (const_hash_1 (TREE_REALPART (exp)) * 5
2917               + const_hash_1 (TREE_IMAGPART (exp)));
2918
2919     case VECTOR_CST:
2920       {
2921         tree link;
2922
2923         hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2924
2925         for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2926             hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2927
2928         return hi;
2929       }
2930
2931     case CONSTRUCTOR:
2932       {
2933         unsigned HOST_WIDE_INT idx;
2934         tree value;
2935
2936         hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2937
2938         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2939           if (value)
2940             hi = hi * 603 + const_hash_1 (value);
2941
2942         return hi;
2943       }
2944
2945     case ADDR_EXPR:
2946     case FDESC_EXPR:
2947       {
2948         struct addr_const value;
2949
2950         decode_addr_const (exp, &value);
2951         switch (GET_CODE (value.base))
2952           {
2953           case SYMBOL_REF:
2954             /* Don't hash the address of the SYMBOL_REF;
2955                only use the offset and the symbol name.  */
2956             hi = value.offset;
2957             p = XSTR (value.base, 0);
2958             for (i = 0; p[i] != 0; i++)
2959               hi = ((hi * 613) + (unsigned) (p[i]));
2960             break;
2961
2962           case LABEL_REF:
2963             hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2964             break;
2965
2966           default:
2967             gcc_unreachable ();
2968           }
2969       }
2970       return hi;
2971
2972     case PLUS_EXPR:
2973     case POINTER_PLUS_EXPR:
2974     case MINUS_EXPR:
2975       return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2976               + const_hash_1 (TREE_OPERAND (exp, 1)));
2977
2978     CASE_CONVERT:
2979       return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2980
2981     default:
2982       /* A language specific constant. Just hash the code.  */
2983       return code;
2984     }
2985
2986   /* Compute hashing function.  */
2987   hi = len;
2988   for (i = 0; i < len; i++)
2989     hi = ((hi * 613) + (unsigned) (p[i]));
2990
2991   return hi;
2992 }
2993
2994 /* Wrapper of compare_constant, for the htab interface.  */
2995 static int
2996 const_desc_eq (const void *p1, const void *p2)
2997 {
2998   const struct constant_descriptor_tree *const c1
2999     = (const struct constant_descriptor_tree *) p1;
3000   const struct constant_descriptor_tree *const c2
3001     = (const struct constant_descriptor_tree *) p2;
3002   if (c1->hash != c2->hash)
3003     return 0;
3004   return compare_constant (c1->value, c2->value);
3005 }
3006
3007 /* Compare t1 and t2, and return 1 only if they are known to result in
3008    the same bit pattern on output.  */
3009
3010 static int
3011 compare_constant (const tree t1, const tree t2)
3012 {
3013   enum tree_code typecode;
3014
3015   if (t1 == NULL_TREE)
3016     return t2 == NULL_TREE;
3017   if (t2 == NULL_TREE)
3018     return 0;
3019
3020   if (TREE_CODE (t1) != TREE_CODE (t2))
3021     return 0;
3022
3023   switch (TREE_CODE (t1))
3024     {
3025     case INTEGER_CST:
3026       /* Integer constants are the same only if the same width of type.  */
3027       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3028         return 0;
3029       if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3030         return 0;
3031       return tree_int_cst_equal (t1, t2);
3032
3033     case REAL_CST:
3034       /* Real constants are the same only if the same width of type.  */
3035       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3036         return 0;
3037
3038       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3039
3040     case FIXED_CST:
3041       /* Fixed constants are the same only if the same width of type.  */
3042       if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3043         return 0;
3044
3045       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3046
3047     case STRING_CST:
3048       if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3049         return 0;
3050
3051       return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3052               && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3053                          TREE_STRING_LENGTH (t1)));
3054
3055     case COMPLEX_CST:
3056       return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3057               && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3058
3059     case VECTOR_CST:
3060       {
3061         tree link1, link2;
3062
3063         if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3064             != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3065           return 0;
3066
3067         link2 = TREE_VECTOR_CST_ELTS (t2);
3068         for (link1 = TREE_VECTOR_CST_ELTS (t1);
3069              link1;
3070              link1 = TREE_CHAIN (link1))
3071           {
3072             if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3073               return 0;
3074             link2 = TREE_CHAIN (link2);
3075           }
3076         
3077         return 1;
3078       }
3079
3080     case CONSTRUCTOR:
3081       {
3082         VEC(constructor_elt, gc) *v1, *v2;
3083         unsigned HOST_WIDE_INT idx;
3084
3085         typecode = TREE_CODE (TREE_TYPE (t1));
3086         if (typecode != TREE_CODE (TREE_TYPE (t2)))
3087           return 0;
3088
3089         if (typecode == ARRAY_TYPE)
3090           {
3091             HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3092             /* For arrays, check that the sizes all match.  */
3093             if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3094                 || size_1 == -1
3095                 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3096               return 0;
3097           }
3098         else
3099           {
3100             /* For record and union constructors, require exact type
3101                equality.  */
3102             if (TREE_TYPE (t1) != TREE_TYPE (t2))
3103               return 0;
3104           }
3105
3106         v1 = CONSTRUCTOR_ELTS (t1);
3107         v2 = CONSTRUCTOR_ELTS (t2);
3108         if (VEC_length (constructor_elt, v1)
3109             != VEC_length (constructor_elt, v2))
3110             return 0;
3111
3112         for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3113           {
3114             constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3115             constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3116
3117             /* Check that each value is the same...  */
3118             if (!compare_constant (c1->value, c2->value))
3119               return 0;
3120             /* ... and that they apply to the same fields!  */
3121             if (typecode == ARRAY_TYPE)
3122               {
3123                 if (!compare_constant (c1->index, c2->index))
3124                   return 0;
3125               }
3126             else
3127               {
3128                 if (c1->index != c2->index)
3129                   return 0;
3130               }
3131           }
3132
3133         return 1;
3134       }
3135
3136     case ADDR_EXPR:
3137     case FDESC_EXPR:
3138       {
3139         struct addr_const value1, value2;
3140         enum rtx_code code;
3141         int ret;
3142
3143         decode_addr_const (t1, &value1);
3144         decode_addr_const (t2, &value2);
3145
3146         if (value1.offset != value2.offset)
3147           return 0;
3148
3149         code = GET_CODE (value1.base);
3150         if (code != GET_CODE (value2.base))
3151           return 0;
3152
3153         switch (code)
3154           {
3155           case SYMBOL_REF:
3156             ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3157             break;
3158
3159           case LABEL_REF:
3160             ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3161                    == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3162             break;
3163
3164           default:
3165             gcc_unreachable ();
3166           }
3167         return ret;
3168       }
3169
3170     case PLUS_EXPR:
3171     case POINTER_PLUS_EXPR:
3172     case MINUS_EXPR:
3173     case RANGE_EXPR:
3174       return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3175               && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3176
3177     CASE_CONVERT:
3178     case VIEW_CONVERT_EXPR:
3179       return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3180
3181     default:
3182       return 0;
3183     }
3184
3185   gcc_unreachable ();
3186 }
3187 \f
3188 /* Make a copy of the whole tree structure for a constant.  This
3189    handles the same types of nodes that compare_constant handles.  */
3190
3191 static tree
3192 copy_constant (tree exp)
3193 {
3194   switch (TREE_CODE (exp))
3195     {
3196     case ADDR_EXPR:
3197       /* For ADDR_EXPR, we do not want to copy the decl whose address
3198          is requested.  We do want to copy constants though.  */
3199       if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3200         return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3201                        copy_constant (TREE_OPERAND (exp, 0)));
3202       else
3203         return copy_node (exp);
3204
3205     case INTEGER_CST:
3206     case REAL_CST:
3207     case FIXED_CST:
3208     case STRING_CST:
3209       return copy_node (exp);
3210
3211     case COMPLEX_CST:
3212       return build_complex (TREE_TYPE (exp),
3213                             copy_constant (TREE_REALPART (exp)),
3214                             copy_constant (TREE_IMAGPART (exp)));
3215
3216     case PLUS_EXPR:
3217     case POINTER_PLUS_EXPR:
3218     case MINUS_EXPR:
3219       return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3220                      copy_constant (TREE_OPERAND (exp, 0)),
3221                      copy_constant (TREE_OPERAND (exp, 1)));
3222
3223     CASE_CONVERT:
3224     case VIEW_CONVERT_EXPR:
3225       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3226                      copy_constant (TREE_OPERAND (exp, 0)));
3227
3228     case VECTOR_CST:
3229       return build_vector (TREE_TYPE (exp),
3230                            copy_list (TREE_VECTOR_CST_ELTS (exp)));
3231
3232     case CONSTRUCTOR:
3233       {
3234         tree copy = copy_node (exp);
3235         VEC(constructor_elt, gc) *v;
3236         unsigned HOST_WIDE_INT idx;
3237         tree purpose, value;
3238
3239         v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3240                                                       CONSTRUCTOR_ELTS (exp)));
3241         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3242           {
3243             constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3244             ce->index = purpose;
3245             ce->value = copy_constant (value);
3246           }
3247         CONSTRUCTOR_ELTS (copy) = v;
3248         return copy;
3249       }
3250
3251     default:
3252       gcc_unreachable ();
3253     }
3254 }
3255 \f
3256 /* Return the section into which constant EXP should be placed.  */
3257
3258 static section *
3259 get_constant_section (tree exp, unsigned int align)
3260 {
3261   return targetm.asm_out.select_section (exp,
3262                                          compute_reloc_for_constant (exp),
3263                                          align);
3264 }
3265
3266 /* Return the size of constant EXP in bytes.  */
3267
3268 static HOST_WIDE_INT
3269 get_constant_size (tree exp)
3270 {
3271   HOST_WIDE_INT size;
3272
3273   size = int_size_in_bytes (TREE_TYPE (exp));
3274   if (TREE_CODE (exp) == STRING_CST)
3275     size = MAX (TREE_STRING_LENGTH (exp), size);
3276   return size;
3277 }
3278
3279 /* Subroutine of output_constant_def:
3280    No constant equal to EXP is known to have been output.
3281    Make a constant descriptor to enter EXP in the hash table.
3282    Assign the label number and construct RTL to refer to the
3283    constant's location in memory.
3284    Caller is responsible for updating the hash table.  */
3285
3286 static struct constant_descriptor_tree *
3287 build_constant_desc (tree exp)
3288 {
3289   struct constant_descriptor_tree *desc;
3290   rtx symbol, rtl;
3291   char label[256];
3292   int labelno;
3293   tree decl;
3294
3295   desc = GGC_NEW (struct constant_descriptor_tree);
3296   desc->value = copy_constant (exp);
3297
3298   /* Propagate marked-ness to copied constant.  */
3299   if (flag_mudflap && mf_marked_p (exp))
3300     mf_mark (desc->value);
3301
3302   /* Create a string containing the label name, in LABEL.  */
3303   labelno = const_labelno++;
3304   ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3305
3306   /* Construct the VAR_DECL associated with the constant.  */
3307   decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3308                      TREE_TYPE (exp));
3309   DECL_ARTIFICIAL (decl) = 1;
3310   DECL_IGNORED_P (decl) = 1;
3311   TREE_READONLY (decl) = 1;
3312   TREE_STATIC (decl) = 1;
3313   TREE_ADDRESSABLE (decl) = 1;
3314   /* We don't set the RTL yet as this would cause varpool to assume that the
3315      variable is referenced.  Moreover, it would just be dropped in LTO mode.
3316      Instead we set the flag that will be recognized in make_decl_rtl.  */
3317   DECL_IN_CONSTANT_POOL (decl) = 1;
3318   DECL_INITIAL (decl) = desc->value;
3319   /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3320      architectures so use DATA_ALIGNMENT as well, except for strings.  */
3321   if (TREE_CODE (exp) == STRING_CST)
3322     {
3323 #ifdef CONSTANT_ALIGNMENT
3324       DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3325 #endif
3326     }
3327   else
3328     align_variable (decl, 0);
3329
3330   /* Now construct the SYMBOL_REF and the MEM.  */
3331   if (use_object_blocks_p ())
3332     {
3333       section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3334       symbol = create_block_symbol (ggc_strdup (label),
3335                                     get_block_for_section (sect), -1);
3336     }
3337   else
3338     symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3339   SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3340   SET_SYMBOL_REF_DECL (symbol, decl);
3341   TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3342
3343   rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3344   set_mem_attributes (rtl, exp, 1);
3345   set_mem_alias_set (rtl, 0);
3346   set_mem_alias_set (rtl, const_alias_set);
3347
3348   /* We cannot share RTX'es in pool entries.
3349      Mark this piece of RTL as required for unsharing.  */
3350   RTX_FLAG (rtl, used) = 1;
3351
3352   /* Set flags or add text to the name to record information, such as
3353      that it is a local symbol.  If the name is changed, the macro
3354      ASM_OUTPUT_LABELREF will have to know how to strip this
3355      information.  This call might invalidate our local variable
3356      SYMBOL; we can't use it afterward.  */
3357   targetm.encode_section_info (exp, rtl, true);
3358
3359   desc->rtl = rtl;
3360
3361   return desc;
3362 }
3363
3364 /* Return an rtx representing a reference to constant data in memory
3365    for the constant expression EXP.
3366
3367    If assembler code for such a constant has already been output,
3368    return an rtx to refer to it.
3369    Otherwise, output such a constant in memory
3370    and generate an rtx for it.
3371
3372    If DEFER is nonzero, this constant can be deferred and output only
3373    if referenced in the function after all optimizations.
3374
3375    `const_desc_table' records which constants already have label strings.  */
3376
3377 rtx
3378 output_constant_def (tree exp, int defer)
3379 {
3380   struct constant_descriptor_tree *desc;
3381   struct constant_descriptor_tree key;
3382   void **loc;
3383
3384   /* Look up EXP in the table of constant descriptors.  If we didn't find
3385      it, create a new one.  */
3386   key.value = exp;
3387   key.hash = const_hash_1 (exp);
3388   loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3389
3390   desc = (struct constant_descriptor_tree *) *loc;
3391   if (desc == 0)
3392     {
3393       desc = build_constant_desc (exp);
3394       desc->hash = key.hash;
3395       *loc = desc;
3396     }
3397
3398   maybe_output_constant_def_contents (desc, defer);
3399   return desc->rtl;
3400 }
3401
3402 /* Subroutine of output_constant_def: Decide whether or not we need to
3403    output the constant DESC now, and if so, do it.  */
3404 static void
3405 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3406                                     int defer)
3407 {
3408   rtx symbol = XEXP (desc->rtl, 0);
3409   tree exp = desc->value;
3410
3411   if (flag_syntax_only)
3412     return;
3413
3414   if (TREE_ASM_WRITTEN (exp))
3415     /* Already output; don't do it again.  */
3416     return;
3417
3418   /* We can always defer constants as long as the context allows
3419      doing so.  */
3420   if (defer)
3421     {
3422       /* Increment n_deferred_constants if it exists.  It needs to be at
3423          least as large as the number of constants actually referred to
3424          by the function.  If it's too small we'll stop looking too early
3425          and fail to emit constants; if it's too large we'll only look
3426          through the entire function when we could have stopped earlier.  */
3427       if (cfun)
3428         n_deferred_constants++;
3429       return;
3430     }
3431
3432   output_constant_def_contents (symbol);
3433 }
3434
3435 /* Subroutine of output_constant_def_contents.  Output the definition
3436    of constant EXP, which is pointed to by label LABEL.  ALIGN is the
3437    constant's alignment in bits.  */
3438
3439 static void
3440 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3441 {
3442   HOST_WIDE_INT size;
3443
3444   size = get_constant_size (exp);
3445
3446   /* Do any machine/system dependent processing of the constant.  */
3447 #ifdef ASM_DECLARE_CONSTANT_NAME
3448   ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3449 #else
3450   /* Standard thing is just output label for the constant.  */
3451   ASM_OUTPUT_LABEL (asm_out_file, label);
3452 #endif /* ASM_DECLARE_CONSTANT_NAME */
3453
3454   /* Output the value of EXP.  */
3455   output_constant (exp, size, align);
3456 }
3457
3458 /* We must output the constant data referred to by SYMBOL; do so.  */
3459
3460 static void
3461 output_constant_def_contents (rtx symbol)
3462 {
3463   tree decl = SYMBOL_REF_DECL (symbol);
3464   tree exp = DECL_INITIAL (decl);
3465   unsigned int align;
3466
3467   /* Make sure any other constants whose addresses appear in EXP
3468      are assigned label numbers.  */
3469   output_addressed_constants (exp);
3470
3471   /* We are no longer deferring this constant.  */
3472   TREE_ASM_WRITTEN (exp) = 1;
3473
3474   /* If the constant is part of an object block, make sure that the
3475      decl has been positioned within its block, but do not write out
3476      its definition yet.  output_object_blocks will do that later.  */
3477   if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3478     place_block_symbol (symbol);
3479   else
3480     {
3481       align = DECL_ALIGN (decl);
3482       switch_to_section (get_constant_section (exp, align));
3483       if (align > BITS_PER_UNIT)
3484         ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3485       assemble_constant_contents (exp, XSTR (symbol, 0), align);
3486     }
3487   if (flag_mudflap)
3488     mudflap_enqueue_constant (exp);
3489 }
3490
3491 /* Look up EXP in the table of constant descriptors.  Return the rtl
3492    if it has been emitted, else null.  */
3493
3494 rtx
3495 lookup_constant_def (tree exp)
3496 {
3497   struct constant_descriptor_tree *desc;
3498   struct constant_descriptor_tree key;
3499
3500   key.value = exp;
3501   key.hash = const_hash_1 (exp);
3502   desc = (struct constant_descriptor_tree *)
3503     htab_find_with_hash (const_desc_htab, &key, key.hash);
3504
3505   return (desc ? desc->rtl : NULL_RTX);
3506 }
3507
3508 /* Return a tree representing a reference to constant data in memory
3509    for the constant expression EXP.
3510
3511    This is the counterpart of output_constant_def at the Tree level.  */
3512
3513 tree
3514 tree_output_constant_def (tree exp)
3515 {
3516   struct constant_descriptor_tree *desc, key;
3517   void **loc;
3518   tree decl;
3519
3520   /* Look up EXP in the table of constant descriptors.  If we didn't find
3521      it, create a new one.  */
3522   key.value = exp;
3523   key.hash = const_hash_1 (exp);
3524   loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3525
3526   desc = (struct constant_descriptor_tree *) *loc;
3527   if (desc == 0)
3528     {
3529       desc = build_constant_desc (exp);
3530       desc->hash = key.hash;
3531       *loc = desc;
3532     }
3533
3534   decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3535   varpool_finalize_decl (decl);
3536   return decl;
3537 }
3538 \f
3539 /* Used in the hash tables to avoid outputting the same constant
3540    twice.  Unlike 'struct constant_descriptor_tree', RTX constants
3541    are output once per function, not once per file.  */
3542 /* ??? Only a few targets need per-function constant pools.  Most
3543    can use one per-file pool.  Should add a targetm bit to tell the
3544    difference.  */
3545
3546 struct GTY(()) rtx_constant_pool {
3547   /* Pointers to first and last constant in pool, as ordered by offset.  */
3548   struct constant_descriptor_rtx *first;
3549   struct constant_descriptor_rtx *last;
3550
3551   /* Hash facility for making memory-constants from constant rtl-expressions.
3552      It is used on RISC machines where immediate integer arguments and
3553      constant addresses are restricted so that such constants must be stored
3554      in memory.  */
3555   htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3556
3557   /* Current offset in constant pool (does not include any
3558      machine-specific header).  */
3559   HOST_WIDE_INT offset;
3560 };
3561
3562 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3563   struct constant_descriptor_rtx *next;
3564   rtx mem;
3565   rtx sym;
3566   rtx constant;
3567   HOST_WIDE_INT offset;
3568   hashval_t hash;
3569   enum machine_mode mode;
3570   unsigned int align;
3571   int labelno;
3572   int mark;
3573 };
3574
3575 /* Hash and compare functions for const_rtx_htab.  */
3576
3577 static hashval_t
3578 const_desc_rtx_hash (const void *ptr)
3579 {
3580   const struct constant_descriptor_rtx *const desc
3581     = (const struct constant_descriptor_rtx *) ptr;
3582   return desc->hash;
3583 }
3584
3585 static int
3586 const_desc_rtx_eq (const void *a, const void *b)
3587 {
3588   const struct constant_descriptor_rtx *const x
3589     = (const struct constant_descriptor_rtx *) a;
3590   const struct constant_descriptor_rtx *const y
3591     = (const struct constant_descriptor_rtx *) b;
3592
3593   if (x->mode != y->mode)
3594     return 0;
3595   return rtx_equal_p (x->constant, y->constant);
3596 }
3597
3598 /* This is the worker function for const_rtx_hash, called via for_each_rtx.  */
3599
3600 static int
3601 const_rtx_hash_1 (rtx *xp, void *data)
3602 {
3603   unsigned HOST_WIDE_INT hwi;
3604   enum machine_mode mode;
3605   enum rtx_code code;
3606   hashval_t h, *hp;
3607   rtx x;
3608
3609   x = *xp;
3610   code = GET_CODE (x);
3611   mode = GET_MODE (x);
3612   h = (hashval_t) code * 1048573 + mode;
3613
3614   switch (code)
3615     {
3616     case CONST_INT:
3617       hwi = INTVAL (x);
3618     fold_hwi:
3619       {
3620         int shift = sizeof (hashval_t) * CHAR_BIT;
3621         const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3622         int i;
3623
3624         h ^= (hashval_t) hwi;
3625         for (i = 1; i < n; ++i)
3626           {
3627             hwi >>= shift;
3628             h ^= (hashval_t) hwi;
3629           }
3630       }
3631       break;
3632
3633     case CONST_DOUBLE:
3634       if (mode == VOIDmode)
3635         {
3636           hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3637           goto fold_hwi;
3638         }
3639       else
3640         h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3641       break;
3642
3643     case CONST_FIXED:
3644       h ^= fixed_hash (CONST_FIXED_VALUE (x));
3645       break;
3646
3647     case CONST_VECTOR:
3648       {
3649         int i;
3650         for (i = XVECLEN (x, 0); i-- > 0; )
3651           h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3652       }
3653       break;
3654
3655     case SYMBOL_REF:
3656       h ^= htab_hash_string (XSTR (x, 0));
3657       break;
3658
3659     case LABEL_REF:
3660       h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3661       break;
3662
3663     case UNSPEC:
3664     case UNSPEC_VOLATILE:
3665       h = h * 251 + XINT (x, 1);
3666       break;
3667
3668     default:
3669       break;
3670     }
3671
3672   hp = (hashval_t *) data;
3673   *hp = *hp * 509 + h;
3674   return 0;
3675 }
3676
3677 /* Compute a hash value for X, which should be a constant.  */
3678
3679 static hashval_t
3680 const_rtx_hash (rtx x)
3681 {
3682   hashval_t h = 0;
3683   for_each_rtx (&x, const_rtx_hash_1, &h);
3684   return h;
3685 }
3686
3687 \f
3688 /* Create and return a new rtx constant pool.  */
3689
3690 static struct rtx_constant_pool *
3691 create_constant_pool (void)
3692 {
3693   struct rtx_constant_pool *pool;
3694
3695   pool = GGC_NEW (struct rtx_constant_pool);
3696   pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3697                                           const_desc_rtx_eq, NULL);
3698   pool->first = NULL;
3699   pool->last = NULL;
3700   pool->offset = 0;
3701   return pool;
3702 }
3703
3704 /* Initialize constant pool hashing for a new function.  */
3705
3706 void
3707 init_varasm_status (void)
3708 {
3709   crtl->varasm.pool = create_constant_pool ();
3710   crtl->varasm.deferred_constants = 0;
3711 }
3712 \f
3713 /* Given a MINUS expression, simplify it if both sides
3714    include the same symbol.  */
3715
3716 rtx
3717 simplify_subtraction (rtx x)
3718 {
3719   rtx r = simplify_rtx (x);
3720   return r ? r : x;
3721 }
3722 \f
3723 /* Given a constant rtx X, make (or find) a memory constant for its value
3724    and return a MEM rtx to refer to it in memory.  */
3725
3726 rtx
3727 force_const_mem (enum machine_mode mode, rtx x)
3728 {
3729   struct constant_descriptor_rtx *desc, tmp;
3730   struct rtx_constant_pool *pool;
3731   char label[256];
3732   rtx def, symbol;
3733   hashval_t hash;
3734   unsigned int align;
3735   void **slot;
3736
3737   /* If we're not allowed to drop X into the constant pool, don't.  */
3738   if (targetm.cannot_force_const_mem (x))
3739     return NULL_RTX;
3740
3741   /* Record that this function has used a constant pool entry.  */
3742   crtl->uses_const_pool = 1;
3743
3744   /* Decide which pool to use.  */
3745   pool = (targetm.use_blocks_for_constant_p (mode, x)
3746           ? shared_constant_pool
3747           : crtl->varasm.pool);
3748
3749   /* Lookup the value in the hashtable.  */
3750   tmp.constant = x;
3751   tmp.mode = mode;
3752   hash = const_rtx_hash (x);
3753   slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3754   desc = (struct constant_descriptor_rtx *) *slot;
3755
3756   /* If the constant was already present, return its memory.  */
3757   if (desc)
3758     return copy_rtx (desc->mem);
3759
3760   /* Otherwise, create a new descriptor.  */
3761   desc = GGC_NEW (struct constant_descriptor_rtx);
3762   *slot = desc;
3763
3764   /* Align the location counter as required by EXP's data type.  */
3765   align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3766 #ifdef CONSTANT_ALIGNMENT
3767   {
3768     tree type = lang_hooks.types.type_for_mode (mode, 0);
3769     if (type != NULL_TREE)
3770       align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3771   }
3772 #endif
3773
3774   pool->offset += (align / BITS_PER_UNIT) - 1;
3775   pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3776
3777   desc->next = NULL;
3778   desc->constant = tmp.constant;
3779   desc->offset = pool->offset;
3780   desc->hash = hash;
3781   desc->mode = mode;
3782   desc->align = align;
3783   desc->labelno = const_labelno;
3784   desc->mark = 0;
3785
3786   pool->offset += GET_MODE_SIZE (mode);
3787   if (pool->last)
3788     pool->last->next = desc;
3789   else
3790     pool->first = pool->last = desc;
3791   pool->last = desc;
3792
3793   /* Create a string containing the label name, in LABEL.  */
3794   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3795   ++const_labelno;
3796
3797   /* Construct the SYMBOL_REF.  Make sure to mark it as belonging to
3798      the constants pool.  */
3799   if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3800     {
3801       section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3802       symbol = create_block_symbol (ggc_strdup (label),
3803                                     get_block_for_section (sect), -1);
3804     }
3805   else
3806     symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3807   desc->sym = symbol;
3808   SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3809   CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3810   SET_SYMBOL_REF_CONSTANT (symbol, desc);
3811
3812   /* Construct the MEM.  */
3813   desc->mem = def = gen_const_mem (mode, symbol);
3814   set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3815   set_mem_align (def, align);
3816
3817   /* If we're dropping a label to the constant pool, make sure we
3818      don't delete it.  */
3819   if (GET_CODE (x) == LABEL_REF)
3820     LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3821
3822   return copy_rtx (def);
3823 }
3824 \f
3825 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3826
3827 rtx
3828 get_pool_constant (rtx addr)
3829 {
3830   return SYMBOL_REF_CONSTANT (addr)->constant;
3831 }
3832
3833 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3834    and whether it has been output or not.  */
3835
3836 rtx
3837 get_pool_constant_mark (rtx addr, bool *pmarked)
3838 {
3839   struct constant_descriptor_rtx *desc;
3840
3841   desc = SYMBOL_REF_CONSTANT (addr);
3842   *pmarked = (desc->mark != 0);
3843   return desc->constant;
3844 }
3845
3846 /* Similar, return the mode.  */
3847
3848 enum machine_mode
3849 get_pool_mode (const_rtx addr)
3850 {
3851   return SYMBOL_REF_CONSTANT (addr)->mode;
3852 }
3853
3854 /* Return the size of the constant pool.  */
3855
3856 int
3857 get_pool_size (void)
3858 {
3859   return crtl->varasm.pool->offset;
3860 }
3861 \f
3862 /* Worker function for output_constant_pool_1.  Emit assembly for X
3863    in MODE with known alignment ALIGN.  */
3864
3865 static void
3866 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3867 {
3868   switch (GET_MODE_CLASS (mode))
3869     {
3870     case MODE_FLOAT:
3871     case MODE_DECIMAL_FLOAT:
3872       {
3873         REAL_VALUE_TYPE r;
3874
3875         gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3876         REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3877         assemble_real (r, mode, align);
3878         break;
3879       }
3880
3881     case MODE_INT:
3882     case MODE_PARTIAL_INT:
3883     case MODE_FRACT:
3884     case MODE_UFRACT:
3885     case MODE_ACCUM:
3886     case MODE_UACCUM:
3887       assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3888       break;
3889
3890     case MODE_VECTOR_FLOAT:
3891     case MODE_VECTOR_INT:
3892     case MODE_VECTOR_FRACT:
3893     case MODE_VECTOR_UFRACT:
3894     case MODE_VECTOR_ACCUM:
3895     case MODE_VECTOR_UACCUM:
3896       {
3897         int i, units;
3898         enum machine_mode submode = GET_MODE_INNER (mode);
3899         unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3900
3901         gcc_assert (GET_CODE (x) == CONST_VECTOR);
3902         units = CONST_VECTOR_NUNITS (x);
3903
3904         for (i = 0; i < units; i++)
3905           {
3906             rtx elt = CONST_VECTOR_ELT (x, i);
3907             output_constant_pool_2 (submode, elt, i ? subalign : align);
3908           }
3909       }
3910       break;
3911
3912     default:
3913       gcc_unreachable ();
3914     }
3915 }
3916
3917 /* Worker function for output_constant_pool.  Emit constant DESC,
3918    giving it ALIGN bits of alignment.  */
3919
3920 static void
3921 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3922                         unsigned int align)
3923 {
3924   rtx x, tmp;
3925
3926   x = desc->constant;
3927
3928   /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3929      whose CODE_LABEL has been deleted.  This can occur if a jump table
3930      is eliminated by optimization.  If so, write a constant of zero
3931      instead.  Note that this can also happen by turning the
3932      CODE_LABEL into a NOTE.  */
3933   /* ??? This seems completely and utterly wrong.  Certainly it's
3934      not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3935      functioning even with INSN_DELETED_P and friends.  */
3936
3937   tmp = x;
3938   switch (GET_CODE (tmp))
3939     {
3940     case CONST:
3941       if (GET_CODE (XEXP (tmp, 0)) != PLUS
3942           || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3943         break;
3944       tmp = XEXP (XEXP (tmp, 0), 0);
3945       /* FALLTHRU  */
3946
3947     case LABEL_REF:
3948       tmp = XEXP (tmp, 0);
3949       gcc_assert (!INSN_DELETED_P (tmp));
3950       gcc_assert (!NOTE_P (tmp)
3951                   || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3952       break;
3953
3954     default:
3955       break;
3956     }
3957
3958 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3959   ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3960                                  align, desc->labelno, done);
3961 #endif
3962
3963   assemble_align (align);
3964
3965   /* Output the label.  */
3966   targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3967
3968   /* Output the data.  */
3969   output_constant_pool_2 (desc->mode, x, align);
3970
3971   /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3972      sections have proper size.  */
3973   if (align > GET_MODE_BITSIZE (desc->mode)
3974       && in_section
3975       && (in_section->common.flags & SECTION_MERGE))
3976     assemble_align (align);
3977
3978 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3979  done:
3980 #endif
3981   return;
3982 }
3983
3984 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3985    to as used.  Emit referenced deferred strings.  This function can
3986    be used with for_each_rtx to mark all SYMBOL_REFs in an rtx.  */
3987
3988 static int
3989 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3990 {
3991   rtx x = *current_rtx;
3992
3993   if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3994     return 0;
3995
3996   if (CONSTANT_POOL_ADDRESS_P (x))
3997     {
3998       struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3999       if (desc->mark == 0)
4000         {
4001           desc->mark = 1;
4002           for_each_rtx (&desc->constant, mark_constant, NULL);
4003         }
4004     }
4005   else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4006     {
4007       tree decl = SYMBOL_REF_DECL (x);
4008       if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4009         {
4010           n_deferred_constants--;
4011           output_constant_def_contents (x);
4012         }
4013     }
4014
4015   return -1;
4016 }
4017
4018 /* Look through appropriate parts of INSN, marking all entries in the
4019    constant pool which are actually being used.  Entries that are only
4020    referenced by other constants are also marked as used.  Emit
4021    deferred strings that are used.  */
4022
4023 static void
4024 mark_constants (rtx insn)
4025 {
4026   if (!INSN_P (insn))
4027     return;
4028
4029   /* Insns may appear inside a SEQUENCE.  Only check the patterns of
4030      insns, not any notes that may be attached.  We don't want to mark
4031      a constant just because it happens to appear in a REG_EQUIV note.  */
4032   if (GET_CODE (PATTERN (insn)) == SEQUENCE)
4033     {
4034       rtx seq = PATTERN (insn);
4035       int i, n = XVECLEN (seq, 0);
4036       for (i = 0; i < n; ++i)
4037         {
4038           rtx subinsn = XVECEXP (seq, 0, i);
4039           if (INSN_P (subinsn))
4040             for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
4041         }
4042     }
4043   else
4044     for_each_rtx (&PATTERN (insn), mark_constant, NULL);
4045 }
4046
4047 /* Look through the instructions for this function, and mark all the
4048    entries in POOL which are actually being used.  Emit deferred constants
4049    which have indeed been used.  */
4050
4051 static void
4052 mark_constant_pool (void)
4053 {
4054   rtx insn, link;
4055
4056   if (!crtl->uses_const_pool && n_deferred_constants == 0)
4057     return;
4058
4059   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4060     mark_constants (insn);
4061
4062   for (link = crtl->epilogue_delay_list;
4063        link;
4064        link = XEXP (link, 1))
4065     mark_constants (XEXP (link, 0));
4066 }
4067
4068 /* Write all the constants in POOL.  */
4069
4070 static void
4071 output_constant_pool_contents (struct rtx_constant_pool *pool)
4072 {
4073   struct constant_descriptor_rtx *desc;
4074
4075   for (desc = pool->first; desc ; desc = desc->next)
4076     if (desc->mark)
4077       {
4078         /* If the constant is part of an object_block, make sure that
4079            the constant has been positioned within its block, but do not
4080            write out its definition yet.  output_object_blocks will do
4081            that later.  */
4082         if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4083             && SYMBOL_REF_BLOCK (desc->sym))
4084           place_block_symbol (desc->sym);
4085         else
4086           {
4087             switch_to_section (targetm.asm_out.select_rtx_section
4088                                (desc->mode, desc->constant, desc->align));
4089             output_constant_pool_1 (desc, desc->align);
4090           }
4091       }
4092 }
4093
4094 /* Mark all constants that are used in the current function, then write
4095    out the function's private constant pool.  */
4096
4097 static void
4098 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4099                       tree fndecl ATTRIBUTE_UNUSED)
4100 {
4101   struct rtx_constant_pool *pool = crtl->varasm.pool;
4102
4103   /* It is possible for gcc to call force_const_mem and then to later
4104      discard the instructions which refer to the constant.  In such a
4105      case we do not need to output the constant.  */
4106   mark_constant_pool ();
4107
4108 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4109   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4110 #endif
4111
4112   output_constant_pool_contents (pool);
4113
4114 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4115   ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4116 #endif
4117 }
4118 \f
4119 /* Write the contents of the shared constant pool.  */
4120
4121 void
4122 output_shared_constant_pool (void)
4123 {
4124   output_constant_pool_contents (shared_constant_pool);
4125 }
4126 \f
4127 /* Determine what kind of relocations EXP may need.  */
4128
4129 int
4130 compute_reloc_for_constant (tree exp)
4131 {
4132   int reloc = 0, reloc2;
4133   tree tem;
4134
4135   switch (TREE_CODE (exp))
4136     {
4137     case ADDR_EXPR:
4138     case FDESC_EXPR:
4139       /* Go inside any operations that get_inner_reference can handle and see
4140          if what's inside is a constant: no need to do anything here for
4141          addresses of variables or functions.  */
4142       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4143            tem = TREE_OPERAND (tem, 0))
4144         ;
4145
4146       if (TREE_PUBLIC (tem))
4147         reloc |= 2;
4148       else
4149         reloc |= 1;
4150       break;
4151
4152     case PLUS_EXPR:
4153     case POINTER_PLUS_EXPR:
4154       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4155       reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4156       break;
4157
4158     case MINUS_EXPR:
4159       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4160       reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4161       /* The difference of two local labels is computable at link time.  */
4162       if (reloc == 1 && reloc2 == 1)
4163         reloc = 0;
4164       else
4165         reloc |= reloc2;
4166       break;
4167
4168     CASE_CONVERT:
4169     case VIEW_CONVERT_EXPR:
4170       reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4171       break;
4172
4173     case CONSTRUCTOR:
4174       {
4175         unsigned HOST_WIDE_INT idx;
4176         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4177           if (tem != 0)
4178             reloc |= compute_reloc_for_constant (tem);
4179       }
4180       break;
4181
4182     default:
4183       break;
4184     }
4185   return reloc;
4186 }
4187
4188 /* Find all the constants whose addresses are referenced inside of EXP,
4189    and make sure assembler code with a label has been output for each one.
4190    Indicate whether an ADDR_EXPR has been encountered.  */
4191
4192 static void
4193 output_addressed_constants (tree exp)
4194 {
4195   tree tem;
4196
4197   switch (TREE_CODE (exp))
4198     {
4199     case ADDR_EXPR:
4200     case FDESC_EXPR:
4201       /* Go inside any operations that get_inner_reference can handle and see
4202          if what's inside is a constant: no need to do anything here for
4203          addresses of variables or functions.  */
4204       for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4205            tem = TREE_OPERAND (tem, 0))
4206         ;
4207
4208       /* If we have an initialized CONST_DECL, retrieve the initializer.  */
4209       if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4210         tem = DECL_INITIAL (tem);
4211
4212       if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4213         output_constant_def (tem, 0);
4214       break;
4215
4216     case PLUS_EXPR:
4217     case POINTER_PLUS_EXPR:
4218     case MINUS_EXPR:
4219       output_addressed_constants (TREE_OPERAND (exp, 1));
4220       /* Fall through.  */
4221
4222     CASE_CONVERT:
4223     case VIEW_CONVERT_EXPR:
4224       output_addressed_constants (TREE_OPERAND (exp, 0));
4225       break;
4226
4227     case CONSTRUCTOR:
4228       {
4229         unsigned HOST_WIDE_INT idx;
4230         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4231           if (tem != 0)
4232             output_addressed_constants (tem);
4233       }
4234       break;
4235
4236     default:
4237       break;
4238     }
4239 }
4240 \f
4241 /* Whether a constructor CTOR is a valid static constant initializer if all
4242    its elements are.  This used to be internal to initializer_constant_valid_p
4243    and has been exposed to let other functions like categorize_ctor_elements
4244    evaluate the property while walking a constructor for other purposes.  */
4245
4246 bool
4247 constructor_static_from_elts_p (const_tree ctor)
4248 {
4249   return (TREE_CONSTANT (ctor)
4250           && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4251               || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4252           && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4253 }
4254
4255 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4256                                             tree *cache);
4257
4258 /* A subroutine of initializer_constant_valid_p.  VALUE is a MINUS_EXPR,
4259    PLUS_EXPR or POINTER_PLUS_EXPR.  This looks for cases of VALUE
4260    which are valid when ENDTYPE is an integer of any size; in
4261    particular, this does not accept a pointer minus a constant.  This
4262    returns null_pointer_node if the VALUE is an absolute constant
4263    which can be used to initialize a static variable.  Otherwise it
4264    returns NULL.  */
4265
4266 static tree
4267 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4268 {
4269   tree op0, op1;
4270
4271   if (!INTEGRAL_TYPE_P (endtype))
4272     return NULL_TREE;
4273
4274   op0 = TREE_OPERAND (value, 0);
4275   op1 = TREE_OPERAND (value, 1);
4276
4277   /* Like STRIP_NOPS except allow the operand mode to widen.  This
4278      works around a feature of fold that simplifies (int)(p1 - p2) to
4279      ((int)p1 - (int)p2) under the theory that the narrower operation
4280      is cheaper.  */
4281
4282   while (CONVERT_EXPR_P (op0)
4283          || TREE_CODE (op0) == NON_LVALUE_EXPR)
4284     {
4285       tree inner = TREE_OPERAND (op0, 0);
4286       if (inner == error_mark_node
4287           || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4288           || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4289               > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4290         break;
4291       op0 = inner;
4292     }
4293
4294   while (CONVERT_EXPR_P (op1)
4295          || TREE_CODE (op1) == NON_LVALUE_EXPR)
4296     {
4297       tree inner = TREE_OPERAND (op1, 0);
4298       if (inner == error_mark_node
4299           || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4300           || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4301               > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4302         break;
4303       op1 = inner;
4304     }
4305
4306   op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4307   if (!op0)
4308     return NULL_TREE;
4309
4310   op1 = initializer_constant_valid_p_1 (op1, endtype,
4311                                         cache ? cache + 2 : NULL);
4312   /* Both initializers must be known.  */
4313   if (op1)
4314     {
4315       if (op0 == op1
4316           && (op0 == null_pointer_node
4317               || TREE_CODE (value) == MINUS_EXPR))
4318         return null_pointer_node;
4319
4320       /* Support differences between labels.  */
4321       if (TREE_CODE (op0) == LABEL_DECL
4322           && TREE_CODE (op1) == LABEL_DECL)
4323         return null_pointer_node;
4324
4325       if (TREE_CODE (op0) == STRING_CST
4326           && TREE_CODE (op1) == STRING_CST
4327           && operand_equal_p (op0, op1, 1))
4328         return null_pointer_node;
4329     }
4330
4331   return NULL_TREE;
4332 }
4333
4334 /* Helper function of initializer_constant_valid_p.
4335    Return nonzero if VALUE is a valid constant-valued expression
4336    for use in initializing a static variable; one that can be an
4337    element of a "constant" initializer.
4338
4339    Return null_pointer_node if the value is absolute;
4340    if it is relocatable, return the variable that determines the relocation.
4341    We assume that VALUE has been folded as much as possible;
4342    therefore, we do not need to check for such things as
4343    arithmetic-combinations of integers.
4344
4345    Use CACHE (pointer to 2 tree values) for caching if non-NULL.  */
4346
4347 static tree
4348 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4349 {
4350   tree ret;
4351
4352   switch (TREE_CODE (value))
4353     {
4354     case CONSTRUCTOR:
4355       if (constructor_static_from_elts_p (value))
4356         {
4357           unsigned HOST_WIDE_INT idx;
4358           tree elt;
4359           bool absolute = true;
4360
4361           if (cache && cache[0] == value)
4362             return cache[1];
4363           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4364             {
4365               tree reloc;
4366               reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4367                                                       NULL);
4368               if (!reloc)
4369                 {
4370                   if (cache)
4371                     {
4372                       cache[0] = value;
4373                       cache[1] = NULL_TREE;
4374                     }
4375                   return NULL_TREE;
4376                 }
4377               if (reloc != null_pointer_node)
4378                 absolute = false;
4379             }
4380           /* For a non-absolute relocation, there is no single
4381              variable that can be "the variable that determines the
4382              relocation."  */
4383           if (cache)
4384             {
4385               cache[0] = value;
4386               cache[1] = absolute ? null_pointer_node : error_mark_node;
4387             }
4388           return absolute ? null_pointer_node : error_mark_node;
4389         }
4390
4391       return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4392
4393     case INTEGER_CST:
4394     case VECTOR_CST:
4395     case REAL_CST:
4396     case FIXED_CST:
4397     case STRING_CST:
4398     case COMPLEX_CST:
4399       return null_pointer_node;
4400
4401     case ADDR_EXPR:
4402     case FDESC_EXPR:
4403       {
4404         tree op0 = staticp (TREE_OPERAND (value, 0));
4405         if (op0)
4406           {
4407             /* "&(*a).f" is like unto pointer arithmetic.  If "a" turns out
4408                to be a constant, this is old-skool offsetof-like nonsense.  */
4409             if (TREE_CODE (op0) == INDIRECT_REF
4410                 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4411               return null_pointer_node;
4412             /* Taking the address of a nested function involves a trampoline,
4413                unless we don't need or want one.  */
4414             if (TREE_CODE (op0) == FUNCTION_DECL
4415                 && DECL_STATIC_CHAIN (op0)
4416                 && !TREE_NO_TRAMPOLINE (value))
4417               return NULL_TREE;
4418             /* "&{...}" requires a temporary to hold the constructed