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