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