]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/varasm.c
Daily bump.
[thirdparty/gcc.git] / gcc / varasm.c
CommitLineData
79e68feb 1/* Output variables, constants and external declarations, for GNU compiler.
47c3ed98 2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
79e68feb
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
79e68feb
RS
20
21
22/* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
25
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
28
e9a25f70 29#include "config.h"
670ee920 30#include "system.h"
79e68feb
RS
31#include <setjmp.h>
32/* #include <stab.h> */
79e68feb
RS
33#include "rtl.h"
34#include "tree.h"
35#include "flags.h"
6adb4e3a 36#include "except.h"
57632c51 37#include "function.h"
79e68feb 38#include "expr.h"
5a13eaa4 39#include "output.h"
79e68feb
RS
40#include "hard-reg-set.h"
41#include "regs.h"
9a631e8e 42#include "defaults.h"
24b09b50 43#include "real.h"
10f0ad3d 44#include "toplev.h"
50b2596f 45#include "dbxout.h"
e016950d 46#include "sdbout.h"
79e68feb
RS
47
48#include "obstack.h"
3d6f7931 49#include "c-pragma.h"
79e68feb 50
b4ac57ab 51#ifdef XCOFF_DEBUGGING_INFO
f246a305 52#include "xcoffout.h"
b4ac57ab
RS
53#endif
54
073b0524
RK
55#ifndef TRAMPOLINE_ALIGNMENT
56#define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
57#endif
58
79e68feb
RS
59#ifndef ASM_STABS_OP
60#define ASM_STABS_OP ".stabs"
61#endif
62
7c6d4120
RK
63/* Define the prefix to use when check_memory_usage_flag is enable. */
64#ifdef NO_DOLLAR_IN_LABEL
65#ifdef NO_DOT_IN_LABEL
66#define CHKR_PREFIX "chkr_prefix_"
67#else /* !NO_DOT_IN_LABEL */
68#define CHKR_PREFIX "chkr."
69#endif
956d6950 70#else /* !NO_DOLLAR_IN_LABEL */
7c6d4120
RK
71#define CHKR_PREFIX "chkr$"
72#endif
73#define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
74
79e68feb
RS
75/* File in which assembler code is being written. */
76
77extern FILE *asm_out_file;
78
79/* The (assembler) name of the first globally-visible object output. */
80char *first_global_object_name;
ee830309 81char *weak_global_object_name;
79e68feb
RS
82
83extern struct obstack *current_obstack;
84extern struct obstack *saveable_obstack;
75974726 85extern struct obstack *rtl_obstack;
79e68feb
RS
86extern struct obstack permanent_obstack;
87#define obstack_chunk_alloc xmalloc
79e68feb
RS
88
89/* Number for making the label on the next
90 constant that is stored in memory. */
91
92int const_labelno;
93
94/* Number for making the label on the next
95 static variable internal to a function. */
96
97int var_labelno;
98
dcc8e5e6
RS
99/* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
101
102int size_directive_output;
103
cbed4565
RS
104/* The last decl for which assemble_variable was called,
105 if it did ASM_DECLARE_OBJECT_NAME.
106 If the last call to assemble_variable didn't do that,
107 this holds 0. */
108
109tree last_assemble_variable_decl;
110
eb0430f0
MM
111/* Nonzero if at least one function definition has been seen. */
112
113static int function_defined;
4b8af8d9 114
5a13eaa4
RK
115struct addr_const;
116struct constant_descriptor;
117struct rtx_const;
118struct pool_constant;
119
87e11268 120static const char *strip_reg_name PROTO((const char *));
5a13eaa4
RK
121static int contains_pointers_p PROTO((tree));
122static void decode_addr_const PROTO((tree, struct addr_const *));
123static int const_hash PROTO((tree));
124static int compare_constant PROTO((tree,
125 struct constant_descriptor *));
126static char *compare_constant_1 PROTO((tree, char *));
127static struct constant_descriptor *record_constant PROTO((tree));
128static void record_constant_1 PROTO((tree));
129static tree copy_constant PROTO((tree));
130static void output_constant_def_contents PROTO((tree, int, int));
131static void decode_rtx_const PROTO((enum machine_mode, rtx,
132 struct rtx_const *));
133static int const_hash_rtx PROTO((enum machine_mode, rtx));
134static int compare_constant_rtx PROTO((enum machine_mode, rtx,
135 struct constant_descriptor *));
136static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
137 rtx));
138static struct pool_constant *find_pool_constant PROTO((rtx));
91674c37
ILT
139static void mark_constant_pool PROTO((void));
140static void mark_constants PROTO((rtx));
5a13eaa4 141static int output_addressed_constants PROTO((tree));
8839fca4 142static void output_after_function_constants PROTO((void));
5a13eaa4 143static void output_constructor PROTO((tree, int));
ec99e58f 144static void remove_from_pending_weak_list PROTO ((char *));
0e05e8ea
JL
145#ifdef ASM_OUTPUT_BSS
146static void asm_output_bss PROTO((FILE *, tree, char *, int, int));
147#endif
cab634f2 148#ifdef BSS_SECTION_ASM_OP
0e05e8ea
JL
149#ifdef ASM_OUTPUT_ALIGNED_BSS
150static void asm_output_aligned_bss PROTO((FILE *, tree, char *, int, int));
151#endif
cab634f2 152#endif /* BSS_SECTION_ASM_OP */
79e68feb 153\f
e5887033
DE
154static enum in_section { no_section, in_text, in_data, in_named
155#ifdef BSS_SECTION_ASM_OP
156 , in_bss
157#endif
0021b564
JM
158#ifdef EH_FRAME_SECTION_ASM_OP
159 , in_eh_frame
160#endif
79e68feb 161#ifdef EXTRA_SECTIONS
e5887033 162 , EXTRA_SECTIONS
79e68feb 163#endif
e5887033 164} in_section = no_section;
79e68feb 165
8a425a05
DE
166/* Return a non-zero value if DECL has a section attribute. */
167#define IN_NAMED_SECTION(DECL) \
168 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
169 && DECL_SECTION_NAME (DECL) != NULL_TREE)
170
171/* Text of section name when in_section == in_named. */
172static char *in_named_name;
173
79e68feb
RS
174/* Define functions like text_section for any extra sections. */
175#ifdef EXTRA_SECTION_FUNCTIONS
176EXTRA_SECTION_FUNCTIONS
177#endif
178
179/* Tell assembler to switch to text section. */
180
181void
182text_section ()
183{
184 if (in_section != in_text)
185 {
b93a436e 186 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
79e68feb
RS
187 in_section = in_text;
188 }
189}
190
79e68feb
RS
191/* Tell assembler to switch to data section. */
192
193void
194data_section ()
195{
196 if (in_section != in_data)
197 {
b93a436e 198 if (flag_shared_data)
79e68feb
RS
199 {
200#ifdef SHARED_SECTION_ASM_OP
b93a436e 201 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
79e68feb 202#else
b93a436e 203 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
79e68feb
RS
204#endif
205 }
b93a436e
JL
206 else
207 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
79e68feb
RS
208
209 in_section = in_data;
210 }
211}
3167de5b
AM
212/* Tell assembler to ALWAYS switch to data section, in case
213 it's not sure where it it. */
214
215void
216force_data_section ()
217{
218 in_section = no_section;
219 data_section ();
220}
79e68feb 221
7c6d68c8
RS
222/* Tell assembler to switch to read-only data section. This is normally
223 the text section. */
224
225void
226readonly_data_section ()
227{
228#ifdef READONLY_DATA_SECTION
229 READONLY_DATA_SECTION (); /* Note this can call data_section. */
230#else
231 text_section ();
232#endif
233}
234
0f41302f 235/* Determine if we're in the text section. */
79e68feb
RS
236
237int
238in_text_section ()
239{
240 return in_section == in_text;
241}
8a425a05 242
0f41302f 243/* Determine if we're in the data section. */
6f2f3db7 244
274351ba
RK
245int
246in_data_section ()
247{
248 return in_section == in_data;
249}
6f2f3db7 250
2ffe831c
DE
251/* Tell assembler to change to section NAME for DECL.
252 If DECL is NULL, just switch to section NAME.
ad4ff310
JM
253 If NAME is NULL, get the name from DECL.
254 If RELOC is 1, the initializer for DECL contains relocs. */
8a425a05
DE
255
256void
ad4ff310 257named_section (decl, name, reloc)
2ffe831c 258 tree decl;
87e11268 259 const char *name;
91813b28 260 int reloc ATTRIBUTE_UNUSED;
8a425a05 261{
2ffe831c 262 if (decl != NULL_TREE
6f2f3db7 263 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
2ffe831c
DE
264 abort ();
265 if (name == NULL)
266 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
267
8a425a05
DE
268 if (in_section != in_named || strcmp (name, in_named_name))
269 {
8a425a05 270#ifdef ASM_OUTPUT_SECTION_NAME
ad4ff310 271 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
8a425a05
DE
272#else
273 /* Section attributes are not supported if this macro isn't provided -
274 some host formats don't support them at all. The front-end should
275 already have flagged this as an error. */
276 abort ();
277#endif
e9a25f70
JL
278
279 in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1);
280 strcpy (in_named_name, name);
281 in_section = in_named;
8a425a05
DE
282 }
283}
4d1065ed 284
ad4ff310
JM
285#ifdef ASM_OUTPUT_SECTION_NAME
286#ifndef UNIQUE_SECTION
287#define UNIQUE_SECTION(DECL,RELOC) \
288do { \
289 int len; \
290 char *name, *string; \
291 \
292 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
293 /* Strip off any encoding in name. */ \
294 STRIP_NAME_ENCODING (name, name); \
295 \
296 len = strlen (name) + 1; \
297 string = alloca (len + 1); \
298 sprintf (string, ".%s", name); \
299 \
300 DECL_SECTION_NAME (DECL) = build_string (len, string); \
301} while (0)
302#endif
303#ifndef UNIQUE_SECTION_P
304#define UNIQUE_SECTION_P(DECL) 0
305#endif
306#endif
307
e5887033
DE
308#ifdef BSS_SECTION_ASM_OP
309
310/* Tell the assembler to switch to the bss section. */
311
312void
da2c5447 313bss_section ()
e5887033
DE
314{
315 if (in_section != in_bss)
316 {
e5887033 317#ifdef SHARED_BSS_SECTION_ASM_OP
b93a436e
JL
318 if (flag_shared_data)
319 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
320 else
e5887033 321#endif
b93a436e 322 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
e5887033
DE
323
324 in_section = in_bss;
325 }
326}
327
328#ifdef ASM_OUTPUT_BSS
329
330/* Utility function for ASM_OUTPUT_BSS for targets to use if
331 they don't support alignments in .bss.
332 ??? It is believed that this function will work in most cases so such
333 support is localized here. */
334
335static void
91fddd7c 336asm_output_bss (file, decl, name, size, rounded)
e5887033 337 FILE *file;
91fddd7c 338 tree decl;
e5887033
DE
339 char *name;
340 int size, rounded;
341{
342 ASM_GLOBALIZE_LABEL (file, name);
343 bss_section ();
91fddd7c
DE
344#ifdef ASM_DECLARE_OBJECT_NAME
345 last_assemble_variable_decl = decl;
346 ASM_DECLARE_OBJECT_NAME (file, name, decl);
347#else
348 /* Standard thing is just output label for the object. */
e5887033 349 ASM_OUTPUT_LABEL (file, name);
91fddd7c 350#endif /* ASM_DECLARE_OBJECT_NAME */
e5887033
DE
351 ASM_OUTPUT_SKIP (file, rounded);
352}
353
354#endif
355
356#ifdef ASM_OUTPUT_ALIGNED_BSS
357
358/* Utility function for targets to use in implementing
359 ASM_OUTPUT_ALIGNED_BSS.
360 ??? It is believed that this function will work in most cases so such
361 support is localized here. */
362
363static void
91fddd7c 364asm_output_aligned_bss (file, decl, name, size, align)
e5887033 365 FILE *file;
91fddd7c 366 tree decl;
e5887033
DE
367 char *name;
368 int size, align;
369{
370 ASM_GLOBALIZE_LABEL (file, name);
371 bss_section ();
372 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
91fddd7c
DE
373#ifdef ASM_DECLARE_OBJECT_NAME
374 last_assemble_variable_decl = decl;
375 ASM_DECLARE_OBJECT_NAME (file, name, decl);
376#else
377 /* Standard thing is just output label for the object. */
e5887033 378 ASM_OUTPUT_LABEL (file, name);
91fddd7c 379#endif /* ASM_DECLARE_OBJECT_NAME */
f8bc3367 380 ASM_OUTPUT_SKIP (file, size ? size : 1);
e5887033
DE
381}
382
383#endif
384
385#endif /* BSS_SECTION_ASM_OP */
386
0021b564
JM
387#ifdef EH_FRAME_SECTION_ASM_OP
388void
389eh_frame_section ()
390{
391 if (in_section != in_eh_frame)
392 {
393 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
394 in_section = in_eh_frame;
395 }
396}
397#endif
398
4d1065ed
DE
399/* Switch to the section for function DECL.
400
401 If DECL is NULL_TREE, switch to the text section.
402 ??? It's not clear that we will ever be passed NULL_TREE, but it's
403 safer to handle it. */
404
405void
406function_section (decl)
407 tree decl;
408{
409 if (decl != NULL_TREE
410 && DECL_SECTION_NAME (decl) != NULL_TREE)
ad4ff310 411 named_section (decl, (char *) 0, 0);
8b43265c
JL
412 else
413 text_section ();
4d1065ed 414}
f9da1f35
DE
415
416/* Switch to section for variable DECL.
417
418 RELOC is the `reloc' argument to SELECT_SECTION. */
419
420void
421variable_section (decl, reloc)
422 tree decl;
423 int reloc;
424{
425 if (IN_NAMED_SECTION (decl))
ad4ff310 426 named_section (decl, NULL, reloc);
f9da1f35
DE
427 else
428 {
429 /* C++ can have const variables that get initialized from constructors,
430 and thus can not be in a readonly section. We prevent this by
431 verifying that the initial value is constant for objects put in a
432 readonly section.
433
434 error_mark_node is used by the C front end to indicate that the
435 initializer has not been seen yet. In this case, we assume that
e5887033
DE
436 the initializer must be constant.
437
438 C++ uses error_mark_node for variables that have complicated
439 initializers, but these variables go in BSS so we won't be called
440 for them. */
441
f9da1f35
DE
442#ifdef SELECT_SECTION
443 SELECT_SECTION (decl, reloc);
444#else
ad4ff310 445 if (DECL_READONLY_SECTION (decl, reloc))
f9da1f35
DE
446 readonly_data_section ();
447 else
448 data_section ();
449#endif
450 }
451}
6adb4e3a
MS
452
453/* Tell assembler to switch to the section for the exception handling
454 table. */
455
456void
457exception_section ()
458{
0021b564
JM
459#if defined (EXCEPTION_SECTION)
460 EXCEPTION_SECTION ();
461#else
6adb4e3a 462#ifdef ASM_OUTPUT_SECTION_NAME
ad4ff310 463 named_section (NULL_TREE, ".gcc_except_table", 0);
6adb4e3a
MS
464#else
465 if (flag_pic)
466 data_section ();
467 else
6adb4e3a
MS
468 readonly_data_section ();
469#endif
470#endif
471}
79e68feb
RS
472\f
473/* Create the rtl to represent a function, for a function definition.
474 DECL is a FUNCTION_DECL node which describes which function.
475 The rtl is stored into DECL. */
476
477void
478make_function_rtl (decl)
479 tree decl;
480{
481 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
7c6d4120 482 char *new_name = name;
79e68feb
RS
483
484 /* Rename a nested function to avoid conflicts. */
485 if (decl_function_context (decl) != 0
486 && DECL_INITIAL (decl) != 0
487 && DECL_RTL (decl) == 0)
488 {
489 char *label;
490
491 name = IDENTIFIER_POINTER (DECL_NAME (decl));
492 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
493 name = obstack_copy0 (saveable_obstack, label, strlen (label));
494 var_labelno++;
495 }
7c6d4120
RK
496 else
497 {
498 /* When -fprefix-function-name is used, every function name is
499 prefixed. Even static functions are prefixed because they
500 could be declared latter. Note that a nested function name
501 is not prefixed. */
502 if (flag_prefix_function_name)
503 {
504 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE + 1);
505 strcpy (new_name, CHKR_PREFIX);
506 strcpy (new_name + CHKR_PREFIX_SIZE, name);
507 name = obstack_copy0 (saveable_obstack, new_name, strlen (new_name));
508 }
509 }
79e68feb
RS
510
511 if (DECL_RTL (decl) == 0)
512 {
513 DECL_RTL (decl)
38a448ca
RH
514 = gen_rtx_MEM (DECL_MODE (decl),
515 gen_rtx_SYMBOL_REF (Pmode, name));
79e68feb
RS
516
517 /* Optionally set flags or add text to the name to record information
518 such as that it is a function name. If the name is changed, the macro
8a425a05 519 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
79e68feb
RS
520#ifdef ENCODE_SECTION_INFO
521 ENCODE_SECTION_INFO (decl);
d9525bec
BK
522#endif
523 }
524 else
525 {
526 /* ??? Another way to do this would be to do what halfpic.c does
527 and maintain a hashed table of such critters. */
528 /* ??? Another way to do this would be to pass a flag bit to
529 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
530 /* Let the target reassign the RTL if it wants.
531 This is necessary, for example, when one machine specific
532 decl attribute overrides another. */
533#ifdef REDO_SECTION_INFO_P
534 if (REDO_SECTION_INFO_P (decl))
535 ENCODE_SECTION_INFO (decl);
79e68feb
RS
536#endif
537 }
538
539 /* Record at least one function has been defined. */
540 function_defined = 1;
541}
542
b4ac57ab
RS
543/* Given NAME, a putative register name, discard any customary prefixes. */
544
87e11268 545static const char *
b4ac57ab 546strip_reg_name (name)
87e11268 547 const char *name;
b4ac57ab
RS
548{
549#ifdef REGISTER_PREFIX
550 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
551 name += strlen (REGISTER_PREFIX);
552#endif
553 if (name[0] == '%' || name[0] == '#')
554 name++;
555 return name;
556}
dcfedcd0 557\f
79e68feb
RS
558/* Decode an `asm' spec for a declaration as a register name.
559 Return the register number, or -1 if nothing specified,
c09e6498
RS
560 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
561 or -3 if ASMSPEC is `cc' and is not recognized,
562 or -4 if ASMSPEC is `memory' and is not recognized.
dcfedcd0
RK
563 Accept an exact spelling or a decimal number.
564 Prefixes such as % are optional. */
79e68feb
RS
565
566int
567decode_reg_name (asmspec)
87e11268 568 const char *asmspec;
79e68feb
RS
569{
570 if (asmspec != 0)
571 {
572 int i;
573
b4ac57ab
RS
574 /* Get rid of confusing prefixes. */
575 asmspec = strip_reg_name (asmspec);
576
fff9e713
MT
577 /* Allow a decimal number as a "register name". */
578 for (i = strlen (asmspec) - 1; i >= 0; i--)
579 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
580 break;
581 if (asmspec[0] != 0 && i < 0)
582 {
583 i = atoi (asmspec);
584 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
585 return i;
586 else
587 return -2;
588 }
589
79e68feb 590 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
b4ac57ab
RS
591 if (reg_names[i][0]
592 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
79e68feb
RS
593 return i;
594
79e68feb
RS
595#ifdef ADDITIONAL_REGISTER_NAMES
596 {
87e11268 597 static struct { const char *name; int number; } table[]
79e68feb
RS
598 = ADDITIONAL_REGISTER_NAMES;
599
c84e2712 600 for (i = 0; i < (int)(sizeof (table) / sizeof (table[0])); i++)
79e68feb
RS
601 if (! strcmp (asmspec, table[i].name))
602 return table[i].number;
79e68feb
RS
603 }
604#endif /* ADDITIONAL_REGISTER_NAMES */
605
c09e6498
RS
606 if (!strcmp (asmspec, "memory"))
607 return -4;
608
dcfedcd0
RK
609 if (!strcmp (asmspec, "cc"))
610 return -3;
611
79e68feb
RS
612 return -2;
613 }
614
615 return -1;
616}
617\f
618/* Create the DECL_RTL for a declaration for a static or external variable
619 or static or external function.
620 ASMSPEC, if not 0, is the string which the user specified
621 as the assembler symbol name.
622 TOP_LEVEL is nonzero if this is a file-scope variable.
623
624 This is never called for PARM_DECL nodes. */
625
626void
627make_decl_rtl (decl, asmspec, top_level)
628 tree decl;
87e11268 629 const char *asmspec;
79e68feb
RS
630 int top_level;
631{
0a5152d0 632 register char *name = 0;
ca695ac9
JB
633 int reg_number;
634
ca695ac9 635 reg_number = decode_reg_name (asmspec);
79e68feb
RS
636
637 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
638 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
639
640 if (reg_number == -2)
641 {
642 /* ASMSPEC is given, and not the name of a register. */
643 name = (char *) obstack_alloc (saveable_obstack,
644 strlen (asmspec) + 2);
645 name[0] = '*';
646 strcpy (&name[1], asmspec);
647 }
648
649 /* For a duplicate declaration, we can be called twice on the
ff8f4401
RS
650 same DECL node. Don't discard the RTL already made. */
651 if (DECL_RTL (decl) == 0)
79e68feb 652 {
79e68feb 653 /* First detect errors in declaring global registers. */
12266a61
RK
654 if (TREE_CODE (decl) != FUNCTION_DECL
655 && DECL_REGISTER (decl) && reg_number == -1)
79e68feb
RS
656 error_with_decl (decl,
657 "register name not specified for `%s'");
12266a61
RK
658 else if (TREE_CODE (decl) != FUNCTION_DECL
659 && DECL_REGISTER (decl) && reg_number < 0)
79e68feb
RS
660 error_with_decl (decl,
661 "invalid register name for `%s'");
12266a61
RK
662 else if ((reg_number >= 0 || reg_number == -3)
663 && (TREE_CODE (decl) == FUNCTION_DECL
664 && ! DECL_REGISTER (decl)))
79e68feb
RS
665 error_with_decl (decl,
666 "register name given for non-register variable `%s'");
12266a61
RK
667 else if (TREE_CODE (decl) != FUNCTION_DECL
668 && DECL_REGISTER (decl)
669 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
670 error_with_decl (decl,
671 "data type of `%s' isn't suitable for a register");
672 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
673 && ! HARD_REGNO_MODE_OK (reg_number,
674 TYPE_MODE (TREE_TYPE (decl))))
675 error_with_decl (decl,
676 "register number for `%s' isn't suitable for data type");
79e68feb 677 /* Now handle properly declared static register variables. */
12266a61 678 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
79e68feb
RS
679 {
680 int nregs;
12266a61 681
79e68feb
RS
682 if (DECL_INITIAL (decl) != 0 && top_level)
683 {
684 DECL_INITIAL (decl) = 0;
685 error ("global register variable has initial value");
686 }
687 if (fixed_regs[reg_number] == 0
688 && function_defined && top_level)
689 error ("global register variable follows a function definition");
690 if (TREE_THIS_VOLATILE (decl))
691 warning ("volatile register variables don't work as you might wish");
31e4b1c0
RK
692
693 /* If the user specified one of the eliminables registers here,
694 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
695 confused with that register and be eliminated. Although this
696 usage is somewhat suspect, we nevertheless use the following
697 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
698
699 DECL_RTL (decl)
38a448ca 700 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
31e4b1c0 701 REGNO (DECL_RTL (decl)) = reg_number;
79e68feb
RS
702 REG_USERVAR_P (DECL_RTL (decl)) = 1;
703
704 if (top_level)
705 {
ad800eb1
RK
706 /* Make this register global, so not usable for anything
707 else. */
79e68feb
RS
708 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
709 while (nregs > 0)
ad800eb1 710 globalize_reg (reg_number + --nregs);
79e68feb
RS
711 }
712 }
0bcc6fc7
RK
713 /* Specifying a section attribute on a variable forces it into a
714 non-.bss section, and thus it cannot be common. */
8a425a05
DE
715 else if (TREE_CODE (decl) == VAR_DECL
716 && DECL_SECTION_NAME (decl) != NULL_TREE
4580042b 717 && DECL_INITIAL (decl) == NULL_TREE
d5160254 718 && DECL_COMMON (decl))
0bcc6fc7 719 DECL_COMMON (decl) = 0;
79e68feb
RS
720
721 /* Now handle ordinary static variables and functions (in memory).
722 Also handle vars declared register invalidly. */
723 if (DECL_RTL (decl) == 0)
724 {
725 /* Can't use just the variable's own name for a variable
726 whose scope is less than the whole file.
727 Concatenate a distinguishing number. */
61881daa 728 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
79e68feb
RS
729 {
730 char *label;
731
732 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
733 name = obstack_copy0 (saveable_obstack, label, strlen (label));
734 var_labelno++;
735 }
736
0a5152d0
RK
737 if (name == 0)
738 abort ();
739
7c6d4120
RK
740 /* When -fprefix-function-name is used, the functions
741 names are prefixed. Only nested function names are not
742 prefixed. */
743 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
744 {
745 char *new_name;
746 new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE
747 + 1);
748 strcpy (new_name, CHKR_PREFIX);
749 strcpy (new_name + CHKR_PREFIX_SIZE, name);
750 name = obstack_copy0 (saveable_obstack,
751 new_name, strlen (new_name));
752 }
753
38a448ca
RH
754 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
755 gen_rtx_SYMBOL_REF (Pmode, name));
41472af8
MM
756 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
757
3771b9b2
RK
758 /* If this variable is to be treated as volatile, show its
759 tree node has side effects. If it has side effects, either
760 because of this test or from TREE_THIS_VOLATILE also
761 being set, show the MEM is volatile. */
762 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
763 && TREE_PUBLIC (decl))
764 TREE_SIDE_EFFECTS (decl) = 1;
ab87f8c8
JL
765 else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
766 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
767 TREE_SIDE_EFFECTS (decl) = 1;
768
3771b9b2 769 if (TREE_SIDE_EFFECTS (decl))
79e68feb 770 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3771b9b2 771
79e68feb
RS
772 if (TREE_READONLY (decl))
773 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
c6df88cb
MM
774 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
775 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
79e68feb
RS
776
777 /* Optionally set flags or add text to the name to record information
778 such as that it is a function name.
779 If the name is changed, the macro ASM_OUTPUT_LABELREF
8a425a05 780 will have to know how to strip this information. */
79e68feb
RS
781#ifdef ENCODE_SECTION_INFO
782 ENCODE_SECTION_INFO (decl);
783#endif
784 }
785 }
d9525bec 786 else
ff8f4401 787 {
d9525bec
BK
788 /* If the old RTL had the wrong mode, fix the mode. */
789 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
790 {
791 rtx rtl = DECL_RTL (decl);
792 PUT_MODE (rtl, DECL_MODE (decl));
793 }
794
795 /* ??? Another way to do this would be to do what halfpic.c does
796 and maintain a hashed table of such critters. */
797 /* ??? Another way to do this would be to pass a flag bit to
798 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
799 /* Let the target reassign the RTL if it wants.
800 This is necessary, for example, when one machine specific
801 decl attribute overrides another. */
802#ifdef REDO_SECTION_INFO_P
803 if (REDO_SECTION_INFO_P (decl))
804 ENCODE_SECTION_INFO (decl);
805#endif
ff8f4401 806 }
79e68feb 807}
4724d87a
RS
808
809/* Make the rtl for variable VAR be volatile.
810 Use this only for static variables. */
811
fcbaecc6 812void
4724d87a
RS
813make_var_volatile (var)
814 tree var;
815{
816 if (GET_CODE (DECL_RTL (var)) != MEM)
817 abort ();
818
819 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
820}
79e68feb 821\f
d447ec6f
RS
822/* Output alignment directive to align for constant expression EXP. */
823
824void
825assemble_constant_align (exp)
826 tree exp;
827{
828 int align;
829
830 /* Align the location counter as required by EXP's data type. */
831 align = TYPE_ALIGN (TREE_TYPE (exp));
832#ifdef CONSTANT_ALIGNMENT
833 align = CONSTANT_ALIGNMENT (exp, align);
834#endif
835
836 if (align > BITS_PER_UNIT)
837 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
838}
839
79e68feb
RS
840/* Output a string of literal assembler code
841 for an `asm' keyword used between functions. */
842
843void
844assemble_asm (string)
845 tree string;
846{
847 app_enable ();
848
849 if (TREE_CODE (string) == ADDR_EXPR)
850 string = TREE_OPERAND (string, 0);
851
852 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
853}
854
9bb2e4fe
RS
855#if 0 /* This should no longer be needed, because
856 flag_gnu_linker should be 0 on these systems,
857 which should prevent any output
858 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
79e68feb
RS
859#if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
860#ifndef ASM_OUTPUT_CONSTRUCTOR
861#define ASM_OUTPUT_CONSTRUCTOR(file, name)
862#endif
863#ifndef ASM_OUTPUT_DESTRUCTOR
864#define ASM_OUTPUT_DESTRUCTOR(file, name)
865#endif
866#endif
9bb2e4fe 867#endif /* 0 */
79e68feb
RS
868
869/* Record an element in the table of global destructors.
870 How this is done depends on what sort of assembler and linker
871 are in use.
872
873 NAME should be the name of a global function to be called
874 at exit time. This name is output using assemble_name. */
875
876void
877assemble_destructor (name)
878 char *name;
879{
880#ifdef ASM_OUTPUT_DESTRUCTOR
881 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
882#else
883 if (flag_gnu_linker)
884 {
885 /* Now tell GNU LD that this is part of the static destructor set. */
886 /* This code works for any machine provided you use GNU as/ld. */
887 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
888 assemble_name (asm_out_file, name);
889 fputc ('\n', asm_out_file);
890 }
891#endif
892}
893
894/* Likewise for global constructors. */
895
896void
897assemble_constructor (name)
898 char *name;
899{
900#ifdef ASM_OUTPUT_CONSTRUCTOR
901 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
902#else
903 if (flag_gnu_linker)
904 {
905 /* Now tell GNU LD that this is part of the static constructor set. */
906 /* This code works for any machine provided you use GNU as/ld. */
907 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
908 assemble_name (asm_out_file, name);
909 fputc ('\n', asm_out_file);
910 }
911#endif
912}
913
914/* Likewise for entries we want to record for garbage collection.
915 Garbage collection is still under development. */
916
917void
918assemble_gc_entry (name)
919 char *name;
920{
921#ifdef ASM_OUTPUT_GC_ENTRY
922 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
923#else
924 if (flag_gnu_linker)
925 {
926 /* Now tell GNU LD that this is part of the static constructor set. */
927 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
928 assemble_name (asm_out_file, name);
929 fputc ('\n', asm_out_file);
930 }
931#endif
932}
933\f
97adc6ed
ILT
934/* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
935 a non-zero value if the constant pool should be output before the
936 start of the function, or a zero value if the pool should output
937 after the end of the function. The default is to put it before the
938 start. */
939
940#ifndef CONSTANT_POOL_BEFORE_FUNCTION
941#define CONSTANT_POOL_BEFORE_FUNCTION 1
942#endif
943
79e68feb
RS
944/* Output assembler code for the constant pool of a function and associated
945 with defining the name of the function. DECL describes the function.
946 NAME is the function's name. For the constant pool, we use the current
947 constant pool data. */
948
949void
950assemble_start_function (decl, fnname)
951 tree decl;
952 char *fnname;
953{
954 int align;
955
956 /* The following code does not need preprocessing in the assembler. */
957
958 app_disable ();
959
97adc6ed
ILT
960 if (CONSTANT_POOL_BEFORE_FUNCTION)
961 output_constant_pool (fnname, decl);
79e68feb 962
c30ac676
DE
963#ifdef ASM_OUTPUT_SECTION_NAME
964 /* If the function is to be put in its own section and it's not in a section
965 already, indicate so. */
ad4ff310
JM
966 if ((flag_function_sections
967 && DECL_SECTION_NAME (decl) == NULL_TREE)
968 || UNIQUE_SECTION_P (decl))
969 UNIQUE_SECTION (decl, 0);
c30ac676
DE
970#endif
971
4d1065ed 972 function_section (decl);
79e68feb
RS
973
974 /* Tell assembler to move to target machine's alignment for functions. */
975 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
976 if (align > 0)
b93a436e 977 ASM_OUTPUT_ALIGN (asm_out_file, align);
79e68feb
RS
978
979#ifdef ASM_OUTPUT_FUNCTION_PREFIX
980 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
981#endif
982
983#ifdef SDB_DEBUGGING_INFO
984 /* Output SDB definition of the function. */
985 if (write_symbols == SDB_DEBUG)
986 sdbout_mark_begin_function ();
987#endif
988
989#ifdef DBX_DEBUGGING_INFO
e5c90c23 990 /* Output DBX definition of the function. */
79e68feb 991 if (write_symbols == DBX_DEBUG)
e5c90c23 992 dbxout_begin_function (decl);
79e68feb
RS
993#endif
994
995 /* Make function name accessible from other files, if appropriate. */
996
997 if (TREE_PUBLIC (decl))
998 {
ee830309 999 if (! first_global_object_name)
06bb02f7
RK
1000 {
1001 char *p;
ee830309
JM
1002 char **name;
1003
1004 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1005 name = &first_global_object_name;
1006 else
1007 name = &weak_global_object_name;
06bb02f7
RK
1008
1009 STRIP_NAME_ENCODING (p, fnname);
ee830309
JM
1010 *name = permalloc (strlen (p) + 1);
1011 strcpy (*name, p);
06bb02f7
RK
1012 }
1013
daefd78b
JM
1014#ifdef ASM_WEAKEN_LABEL
1015 if (DECL_WEAK (decl))
ec99e58f
RL
1016 {
1017 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1018 /* Remove this function from the pending weak list so that
1019 we do not emit multiple .weak directives for it. */
1020 remove_from_pending_weak_list
1021 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1022 }
48ad5afd 1023 else
daefd78b 1024#endif
48ad5afd 1025 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
79e68feb
RS
1026 }
1027
1028 /* Do any machine/system dependent processing of the function name */
8bd16853 1029#ifdef ASM_DECLARE_FUNCTION_NAME
b93a436e 1030 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
8bd16853 1031#else
b93a436e
JL
1032 /* Standard thing is just output label for the function. */
1033 ASM_OUTPUT_LABEL (asm_out_file, fnname);
79e68feb
RS
1034#endif /* ASM_DECLARE_FUNCTION_NAME */
1035}
1036
1037/* Output assembler code associated with defining the size of the
1038 function. DECL describes the function. NAME is the function's name. */
1039
1040void
1041assemble_end_function (decl, fnname)
1042 tree decl;
1043 char *fnname;
1044{
1045#ifdef ASM_DECLARE_FUNCTION_SIZE
1046 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1047#endif
97adc6ed 1048 if (! CONSTANT_POOL_BEFORE_FUNCTION)
83488369
RK
1049 {
1050 output_constant_pool (fnname, decl);
1051 function_section (decl); /* need to switch back */
1052 }
8839fca4
ILT
1053
1054 /* Output any constants which should appear after the function. */
1055 output_after_function_constants ();
79e68feb
RS
1056}
1057\f
1058/* Assemble code to leave SIZE bytes of zeros. */
1059
1060void
1061assemble_zeros (size)
1062 int size;
1063{
3c350eb3
CB
1064 /* Do no output if -fsyntax-only. */
1065 if (flag_syntax_only)
1066 return;
1067
79e68feb
RS
1068#ifdef ASM_NO_SKIP_IN_TEXT
1069 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1070 so we must output 0s explicitly in the text section. */
1071 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1072 {
1073 int i;
1074
1075 for (i = 0; i < size - 20; i += 20)
1076 {
1077#ifdef ASM_BYTE_OP
1078 fprintf (asm_out_file,
1079 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
1080#else
1081 fprintf (asm_out_file,
1082 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1083#endif
1084 }
1085 if (i < size)
1086 {
1087#ifdef ASM_BYTE_OP
1088 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1089#else
1090 fprintf (asm_out_file, "\tbyte 0");
1091#endif
1092 i++;
1093 for (; i < size; i++)
1094 fprintf (asm_out_file, ",0");
1095 fprintf (asm_out_file, "\n");
1096 }
1097 }
1098 else
1099#endif
41fe4d9e 1100 if (size > 0)
b93a436e 1101 ASM_OUTPUT_SKIP (asm_out_file, size);
79e68feb
RS
1102}
1103
a785e67e
RS
1104/* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1105
1106void
1107assemble_align (align)
1108 int align;
1109{
1110 if (align > BITS_PER_UNIT)
1111 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1112}
1113
79e68feb
RS
1114/* Assemble a string constant with the specified C string as contents. */
1115
1116void
1117assemble_string (p, size)
9b3142b3 1118 const char *p;
79e68feb
RS
1119 int size;
1120{
79e68feb
RS
1121 int pos = 0;
1122 int maximum = 2000;
1123
1124 /* If the string is very long, split it up. */
1125
1126 while (pos < size)
1127 {
1128 int thissize = size - pos;
1129 if (thissize > maximum)
1130 thissize = maximum;
1131
b93a436e 1132 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
79e68feb
RS
1133
1134 pos += thissize;
1135 p += thissize;
1136 }
1137}
69249c1b 1138
79e68feb
RS
1139\f
1140/* Assemble everything that is needed for a variable or function declaration.
1141 Not used for automatic variables, and not used for function definitions.
1142 Should not be called for variables of incomplete structure type.
1143
1144 TOP_LEVEL is nonzero if this variable has file scope.
1145 AT_END is nonzero if this is the special handling, at end of compilation,
ff8f4401
RS
1146 to define things that have had only tentative definitions.
1147 DONT_OUTPUT_DATA if nonzero means don't actually output the
1148 initial value (that will be done by the caller). */
79e68feb
RS
1149
1150void
ff8f4401 1151assemble_variable (decl, top_level, at_end, dont_output_data)
79e68feb 1152 tree decl;
c84e2712 1153 int top_level ATTRIBUTE_UNUSED;
79e68feb 1154 int at_end;
5a13eaa4 1155 int dont_output_data;
79e68feb
RS
1156{
1157 register char *name;
f8344bea 1158 unsigned int align;
79e68feb
RS
1159 tree size_tree;
1160 int reloc = 0;
edbc355b 1161 enum in_section saved_in_section;
79e68feb 1162
cbed4565
RS
1163 last_assemble_variable_decl = 0;
1164
79e68feb
RS
1165 if (GET_CODE (DECL_RTL (decl)) == REG)
1166 {
1167 /* Do output symbol info for global register variables, but do nothing
1168 else for them. */
1169
1170 if (TREE_ASM_WRITTEN (decl))
1171 return;
1172 TREE_ASM_WRITTEN (decl) = 1;
1173
3c350eb3
CB
1174 /* Do no output if -fsyntax-only. */
1175 if (flag_syntax_only)
1176 return;
1177
b4ac57ab 1178#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
b93a436e
JL
1179 /* File-scope global variables are output here. */
1180 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1181 && top_level)
1182 dbxout_symbol (decl, 0);
79e68feb
RS
1183#endif
1184#ifdef SDB_DEBUGGING_INFO
b93a436e
JL
1185 if (write_symbols == SDB_DEBUG && top_level
1186 /* Leave initialized global vars for end of compilation;
1187 see comment in compile_file. */
1188 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1189 sdbout_symbol (decl, 0);
79e68feb
RS
1190#endif
1191
a94dbf2c
JM
1192 /* Don't output any DWARF debugging information for variables here.
1193 In the case of local variables, the information for them is output
1194 when we do our recursive traversal of the tree representation for
1195 the entire containing function. In the case of file-scope variables,
1196 we output information for all of them at the very end of compilation
1197 while we are doing our final traversal of the chain of file-scope
1198 declarations. */
79e68feb
RS
1199
1200 return;
1201 }
1202
d36d70cc 1203 /* Normally no need to say anything here for external references,
9faa82d8 1204 since assemble_external is called by the language-specific code
d36d70cc 1205 when a declaration is first seen. */
79e68feb 1206
44fe2e80 1207 if (DECL_EXTERNAL (decl))
79e68feb
RS
1208 return;
1209
1210 /* Output no assembler code for a function declaration.
1211 Only definitions of functions output anything. */
1212
1213 if (TREE_CODE (decl) == FUNCTION_DECL)
1214 return;
1215
1216 /* If type was incomplete when the variable was declared,
1217 see if it is complete now. */
1218
1219 if (DECL_SIZE (decl) == 0)
1220 layout_decl (decl, 0);
1221
1222 /* Still incomplete => don't allocate it; treat the tentative defn
1223 (which is what it must have been) as an `extern' reference. */
1224
ff8f4401 1225 if (!dont_output_data && DECL_SIZE (decl) == 0)
79e68feb
RS
1226 {
1227 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1228 DECL_SOURCE_LINE (decl),
ea80ee44 1229 "storage size of `%s' isn't known",
79e68feb 1230 IDENTIFIER_POINTER (DECL_NAME (decl)));
1c1a7ba4 1231 TREE_ASM_WRITTEN (decl) = 1;
79e68feb
RS
1232 return;
1233 }
1234
1235 /* The first declaration of a variable that comes through this function
1236 decides whether it is global (in C, has external linkage)
1237 or local (in C, has internal linkage). So do nothing more
1238 if this function has already run. */
1239
1240 if (TREE_ASM_WRITTEN (decl))
1241 return;
1242
1243 TREE_ASM_WRITTEN (decl) = 1;
1244
3c350eb3
CB
1245 /* Do no output if -fsyntax-only. */
1246 if (flag_syntax_only)
1247 return;
1248
809d6575 1249 app_disable ();
79e68feb 1250
809d6575 1251 if (! dont_output_data)
ff8f4401 1252 {
506711af
RK
1253 int size;
1254
ff8f4401
RS
1255 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1256 goto finish;
79e68feb 1257
ff8f4401
RS
1258 /* This is better than explicit arithmetic, since it avoids overflow. */
1259 size_tree = size_binop (CEIL_DIV_EXPR,
0189a68a 1260 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
79e68feb 1261
506711af
RK
1262 size = TREE_INT_CST_LOW (size_tree);
1263 if (TREE_INT_CST_HIGH (size_tree) != 0
1264 || size != TREE_INT_CST_LOW (size_tree))
ff8f4401
RS
1265 {
1266 error_with_decl (decl, "size of variable `%s' is too large");
1267 goto finish;
1268 }
79e68feb
RS
1269 }
1270
1271 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1272
f796d997
JM
1273 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1274 && ! first_global_object_name
1275 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1276 || DECL_INITIAL (decl) == error_mark_node))
1277 && ! DECL_WEAK (decl)
1278 && ! DECL_ONE_ONLY (decl))
1279 {
1280 char *p;
1281
1282 STRIP_NAME_ENCODING (p, name);
1283 first_global_object_name = permalloc (strlen (p) + 1);
1284 strcpy (first_global_object_name, p);
1285 }
1286
8a198bd2
JW
1287 /* Compute the alignment of this data. */
1288
1289 align = DECL_ALIGN (decl);
1290
1291 /* In the case for initialing an array whose length isn't specified,
1292 where we have not yet been able to do the layout,
1293 figure out the proper alignment now. */
1294 if (dont_output_data && DECL_SIZE (decl) == 0
1295 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1296 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1297
1298 /* Some object file formats have a maximum alignment which they support.
1299 In particular, a.out format supports a maximum alignment of 4. */
1300#ifndef MAX_OFILE_ALIGNMENT
1301#define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1302#endif
1303 if (align > MAX_OFILE_ALIGNMENT)
1304 {
1305 warning_with_decl (decl,
44ec7e59
CM
1306 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1307 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
8a198bd2
JW
1308 align = MAX_OFILE_ALIGNMENT;
1309 }
1310
1311 /* On some machines, it is good to increase alignment sometimes. */
1312#ifdef DATA_ALIGNMENT
1313 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1314#endif
1315#ifdef CONSTANT_ALIGNMENT
1316 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1317 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1318#endif
1319
1320 /* Reset the alignment in case we have made it tighter, so we can benefit
1321 from it in get_pointer_alignment. */
1322 DECL_ALIGN (decl) = align;
1323
79e68feb
RS
1324 /* Handle uninitialized definitions. */
1325
e5887033
DE
1326 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1327 /* If the target can't output uninitialized but not common global data
1328 in .bss, then we have to use .data. */
1329#if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
cd98bf12 1330 && DECL_COMMON (decl)
e5887033 1331#endif
ab87f8c8 1332 && DECL_SECTION_NAME (decl) == 0
e5887033 1333 && ! dont_output_data)
79e68feb
RS
1334 {
1335 int size = TREE_INT_CST_LOW (size_tree);
1336 int rounded = size;
1337
79e68feb
RS
1338 /* Don't allocate zero bytes of common,
1339 since that means "undefined external" in the linker. */
1340 if (size == 0) rounded = 1;
1341 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1342 so that each uninitialized object starts on such a boundary. */
1343 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1344 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1345 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
4bcfa7a8
CM
1346
1347#if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
83de03df 1348 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
4bcfa7a8
CM
1349 warning_with_decl
1350 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1351#endif
1352
edbc355b
RS
1353#ifdef DBX_DEBUGGING_INFO
1354 /* File-scope global variables are output here. */
1355 if (write_symbols == DBX_DEBUG && top_level)
1356 dbxout_symbol (decl, 0);
1357#endif
1358#ifdef SDB_DEBUGGING_INFO
1359 if (write_symbols == SDB_DEBUG && top_level
1360 /* Leave initialized global vars for end of compilation;
1361 see comment in compile_file. */
1362 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1363 sdbout_symbol (decl, 0);
1364#endif
1365
a94dbf2c
JM
1366 /* Don't output any DWARF debugging information for variables here.
1367 In the case of local variables, the information for them is output
1368 when we do our recursive traversal of the tree representation for
1369 the entire containing function. In the case of file-scope variables,
1370 we output information for all of them at the very end of compilation
1371 while we are doing our final traversal of the chain of file-scope
1372 declarations. */
edbc355b 1373
e5887033
DE
1374#if 0 /* ??? We should either delete this or add a comment describing what
1375 it was intended to do and why we shouldn't delete it. */
79e68feb
RS
1376 if (flag_shared_data)
1377 data_section ();
1378#endif
e5887033
DE
1379
1380 if (TREE_PUBLIC (decl)
1381#if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1382 && DECL_COMMON (decl)
e5887033
DE
1383#endif
1384 )
79e68feb
RS
1385 {
1386#ifdef ASM_OUTPUT_SHARED_COMMON
1387 if (flag_shared_data)
1388 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1389 else
1390#endif
ca695ac9 1391 {
e9a25f70
JL
1392#ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1393 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1394 DECL_ALIGN (decl));
1395#else
79e68feb 1396#ifdef ASM_OUTPUT_ALIGNED_COMMON
ca695ac9
JB
1397 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1398 DECL_ALIGN (decl));
79e68feb 1399#else
ca695ac9 1400 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
e9a25f70 1401#endif
79e68feb 1402#endif
ca695ac9 1403 }
79e68feb 1404 }
e5887033
DE
1405#if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1406 else if (TREE_PUBLIC (decl))
1407 {
1408#ifdef ASM_OUTPUT_SHARED_BSS
1409 if (flag_shared_data)
91fddd7c 1410 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
e5887033
DE
1411 else
1412#endif
e5887033
DE
1413 {
1414#ifdef ASM_OUTPUT_ALIGNED_BSS
91fddd7c 1415 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
e5887033
DE
1416 DECL_ALIGN (decl));
1417#else
91fddd7c 1418 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
e5887033
DE
1419#endif
1420 }
1421 }
1422#endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
79e68feb
RS
1423 else
1424 {
1425#ifdef ASM_OUTPUT_SHARED_LOCAL
1426 if (flag_shared_data)
1427 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1428 else
1429#endif
ca695ac9 1430 {
e9a25f70
JL
1431#ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1432 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1433 DECL_ALIGN (decl));
1434#else
79e68feb 1435#ifdef ASM_OUTPUT_ALIGNED_LOCAL
ca695ac9
JB
1436 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1437 DECL_ALIGN (decl));
79e68feb 1438#else
ca695ac9 1439 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
e9a25f70 1440#endif
79e68feb 1441#endif
ca695ac9 1442 }
79e68feb 1443 }
b4ac57ab 1444 goto finish;
79e68feb
RS
1445 }
1446
e5887033
DE
1447 /* Handle initialized definitions.
1448 Also handle uninitialized global definitions if -fno-common and the
1449 target doesn't support ASM_OUTPUT_BSS. */
79e68feb
RS
1450
1451 /* First make the assembler name(s) global if appropriate. */
1452 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1453 {
daefd78b 1454#ifdef ASM_WEAKEN_LABEL
ec99e58f
RL
1455 if (DECL_WEAK (decl))
1456 {
1457 ASM_WEAKEN_LABEL (asm_out_file, name);
1458 /* Remove this variable from the pending weak list so that
1459 we do not emit multiple .weak directives for it. */
1460 remove_from_pending_weak_list
1461 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1462 }
48ad5afd 1463 else
daefd78b 1464#endif
48ad5afd 1465 ASM_GLOBALIZE_LABEL (asm_out_file, name);
79e68feb
RS
1466 }
1467#if 0
1468 for (d = equivalents; d; d = TREE_CHAIN (d))
1469 {
1470 tree e = TREE_VALUE (d);
1471 if (TREE_PUBLIC (e) && DECL_NAME (e))
1472 ASM_GLOBALIZE_LABEL (asm_out_file,
1473 XSTR (XEXP (DECL_RTL (e), 0), 0));
1474 }
1475#endif
1476
1477 /* Output any data that we will need to use the address of. */
2e9effae
RS
1478 if (DECL_INITIAL (decl) == error_mark_node)
1479 reloc = contains_pointers_p (TREE_TYPE (decl));
1480 else if (DECL_INITIAL (decl))
79e68feb
RS
1481 reloc = output_addressed_constants (DECL_INITIAL (decl));
1482
ad4ff310 1483#ifdef ASM_OUTPUT_SECTION_NAME
7d0756fb
CM
1484 if ((flag_data_sections != 0
1485 && DECL_SECTION_NAME (decl) == NULL_TREE)
1486 || UNIQUE_SECTION_P (decl))
ad4ff310
JM
1487 UNIQUE_SECTION (decl, reloc);
1488#endif
1489
f9da1f35
DE
1490 /* Switch to the appropriate section. */
1491 variable_section (decl, reloc);
79e68feb 1492
a8e2f179
RS
1493 /* dbxout.c needs to know this. */
1494 if (in_text_section ())
1495 DECL_IN_TEXT_SECTION (decl) = 1;
1496
edbc355b
RS
1497 /* Record current section so we can restore it if dbxout.c clobbers it. */
1498 saved_in_section = in_section;
1499
1500 /* Output the dbx info now that we have chosen the section. */
1501
1502#ifdef DBX_DEBUGGING_INFO
1503 /* File-scope global variables are output here. */
1504 if (write_symbols == DBX_DEBUG && top_level)
1505 dbxout_symbol (decl, 0);
1506#endif
1507#ifdef SDB_DEBUGGING_INFO
1508 if (write_symbols == SDB_DEBUG && top_level
1509 /* Leave initialized global vars for end of compilation;
1510 see comment in compile_file. */
1511 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1512 sdbout_symbol (decl, 0);
1513#endif
1514
1515 /* Don't output any DWARF debugging information for variables here.
1516 In the case of local variables, the information for them is output
1517 when we do our recursive traversal of the tree representation for
1518 the entire containing function. In the case of file-scope variables,
1519 we output information for all of them at the very end of compilation
1520 while we are doing our final traversal of the chain of file-scope
1521 declarations. */
1522
a8e2f179
RS
1523 /* If the debugging output changed sections, reselect the section
1524 that's supposed to be selected. */
edbc355b 1525 if (in_section != saved_in_section)
f9da1f35 1526 variable_section (decl, reloc);
edbc355b 1527
8a198bd2 1528 /* Output the alignment of this data. */
79e68feb 1529 if (align > BITS_PER_UNIT)
8a198bd2
JW
1530 ASM_OUTPUT_ALIGN (asm_out_file,
1531 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
79e68feb
RS
1532
1533 /* Do any machine/system dependent processing of the object. */
8bd16853 1534#ifdef ASM_DECLARE_OBJECT_NAME
b93a436e
JL
1535 last_assemble_variable_decl = decl;
1536 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
8bd16853 1537#else
b93a436e
JL
1538 /* Standard thing is just output label for the object. */
1539 ASM_OUTPUT_LABEL (asm_out_file, name);
79e68feb
RS
1540#endif /* ASM_DECLARE_OBJECT_NAME */
1541
ff8f4401 1542 if (!dont_output_data)
79e68feb 1543 {
ff8f4401
RS
1544 if (DECL_INITIAL (decl))
1545 /* Output the actual data. */
809d6575 1546 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
ff8f4401
RS
1547 else
1548 /* Leave space for it. */
809d6575 1549 assemble_zeros (TREE_INT_CST_LOW (size_tree));
79e68feb 1550 }
b4ac57ab
RS
1551
1552 finish:
1553#ifdef XCOFF_DEBUGGING_INFO
1554 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1555 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1556 and `aa' hasn't been output yet, the assembler generates a stab entry with
1557 a value of zero, in addition to creating an unnecessary external entry
6dc42e49 1558 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
b4ac57ab
RS
1559
1560 /* File-scope global variables are output here. */
1561 if (write_symbols == XCOFF_DEBUG && top_level)
05be4cea
JW
1562 {
1563 saved_in_section = in_section;
1564
1565 dbxout_symbol (decl, 0);
1566
1567 if (in_section != saved_in_section)
f9da1f35 1568 variable_section (decl, reloc);
05be4cea 1569 }
b4ac57ab
RS
1570#else
1571 /* There must be a statement after a label. */
1572 ;
1573#endif
79e68feb
RS
1574}
1575
2e9effae
RS
1576/* Return 1 if type TYPE contains any pointers. */
1577
1578static int
1579contains_pointers_p (type)
1580 tree type;
1581{
1582 switch (TREE_CODE (type))
1583 {
1584 case POINTER_TYPE:
1585 case REFERENCE_TYPE:
1586 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1587 so I'll play safe and return 1. */
1588 case OFFSET_TYPE:
1589 return 1;
1590
1591 case RECORD_TYPE:
1592 case UNION_TYPE:
1593 case QUAL_UNION_TYPE:
1594 {
1595 tree fields;
1596 /* For a type that has fields, see if the fields have pointers. */
1597 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
ce49ea8a
JM
1598 if (TREE_CODE (fields) == FIELD_DECL
1599 && contains_pointers_p (TREE_TYPE (fields)))
2e9effae
RS
1600 return 1;
1601 return 0;
1602 }
1603
1604 case ARRAY_TYPE:
1605 /* An array type contains pointers if its element type does. */
1606 return contains_pointers_p (TREE_TYPE (type));
1607
1608 default:
1609 return 0;
1610 }
1611}
1612
79e68feb 1613/* Output something to declare an external symbol to the assembler.
fff9e713
MT
1614 (Most assemblers don't need this, so we normally output nothing.)
1615 Do nothing if DECL is not external. */
79e68feb
RS
1616
1617void
1618assemble_external (decl)
91813b28 1619 tree decl ATTRIBUTE_UNUSED;
79e68feb 1620{
79e68feb 1621#ifdef ASM_OUTPUT_EXTERNAL
fff9e713 1622 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
44fe2e80 1623 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
79e68feb 1624 {
fff9e713
MT
1625 rtx rtl = DECL_RTL (decl);
1626
1627 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1628 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1629 {
1630 /* Some systems do require some output. */
1631 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1632 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1633 }
79e68feb
RS
1634 }
1635#endif
1636}
1637
1638/* Similar, for calling a library function FUN. */
1639
1640void
1641assemble_external_libcall (fun)
c84e2712 1642 rtx fun ATTRIBUTE_UNUSED;
79e68feb
RS
1643{
1644#ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
b93a436e
JL
1645 /* Declare library function name external when first used, if nec. */
1646 if (! SYMBOL_REF_USED (fun))
79e68feb 1647 {
b93a436e
JL
1648 SYMBOL_REF_USED (fun) = 1;
1649 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
79e68feb
RS
1650 }
1651#endif
1652}
1653
1654/* Declare the label NAME global. */
1655
1656void
1657assemble_global (name)
1658 char *name;
1659{
1660 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1661}
1662
1663/* Assemble a label named NAME. */
1664
1665void
1666assemble_label (name)
1667 char *name;
1668{
b93a436e 1669 ASM_OUTPUT_LABEL (asm_out_file, name);
79e68feb
RS
1670}
1671
1672/* Output to FILE a reference to the assembler name of a C-level name NAME.
1673 If NAME starts with a *, the rest of NAME is output verbatim.
1674 Otherwise NAME is transformed in an implementation-defined way
1675 (usually by the addition of an underscore).
1676 Many macros in the tm file are defined to call this function. */
1677
1678void
1679assemble_name (file, name)
1680 FILE *file;
1681 char *name;
1682{
648fb7cf 1683 char *real_name;
a94dbf2c 1684 tree id;
648fb7cf
RK
1685
1686 STRIP_NAME_ENCODING (real_name, name);
7c6d4120
RK
1687 if (flag_prefix_function_name
1688 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1689 real_name = real_name + CHKR_PREFIX_SIZE;
87907387 1690
a94dbf2c
JM
1691 id = maybe_get_identifier (real_name);
1692 if (id)
1693 TREE_SYMBOL_REFERENCED (id) = 1;
03e42132 1694
79e68feb 1695 if (name[0] == '*')
b93a436e 1696 fputs (&name[1], file);
79e68feb 1697 else
b93a436e 1698 ASM_OUTPUT_LABELREF (file, name);
79e68feb
RS
1699}
1700
1701/* Allocate SIZE bytes writable static space with a gensym name
1702 and return an RTX to refer to its address. */
1703
1704rtx
1705assemble_static_space (size)
1706 int size;
1707{
1708 char name[12];
1709 char *namestring;
1710 rtx x;
79e68feb
RS
1711
1712#if 0
1713 if (flag_shared_data)
1714 data_section ();
1715#endif
1716
1717 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1718 ++const_labelno;
1719
1720 namestring = (char *) obstack_alloc (saveable_obstack,
1721 strlen (name) + 2);
1722 strcpy (namestring, name);
1723
b93a436e 1724 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
ca695ac9 1725
e9a25f70 1726#ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
b93a436e
JL
1727 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1728 BIGGEST_ALIGNMENT);
e9a25f70 1729#else
79e68feb 1730#ifdef ASM_OUTPUT_ALIGNED_LOCAL
b93a436e 1731 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
79e68feb 1732#else
e016950d
KG
1733 {
1734 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1735 so that each uninitialized object starts on such a boundary. */
47c3ed98
KG
1736 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1737 int rounded ATTRIBUTE_UNUSED
1738 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1739 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1740 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
e016950d
KG
1741 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1742 }
e9a25f70 1743#endif
79e68feb
RS
1744#endif
1745 return x;
1746}
1747
1748/* Assemble the static constant template for function entry trampolines.
1749 This is done at most once per compilation.
1750 Returns an RTX for the address of the template. */
1751
f0e969bd 1752#ifdef TRAMPOLINE_TEMPLATE
79e68feb
RS
1753rtx
1754assemble_trampoline_template ()
1755{
1756 char label[256];
1757 char *name;
1758 int align;
1759
37552631 1760 /* By default, put trampoline templates in read-only data section. */
f49acdb4 1761
37552631
RS
1762#ifdef TRAMPOLINE_SECTION
1763 TRAMPOLINE_SECTION ();
1764#else
c8c29f85 1765 readonly_data_section ();
37552631 1766#endif
f49acdb4 1767
79e68feb 1768 /* Write the assembler code to define one. */
073b0524 1769 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
79e68feb
RS
1770 if (align > 0)
1771 ASM_OUTPUT_ALIGN (asm_out_file, align);
1772
1773 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1774 TRAMPOLINE_TEMPLATE (asm_out_file);
1775
1776 /* Record the rtl to refer to it. */
1777 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1778 name
1779 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
38a448ca 1780 return gen_rtx_SYMBOL_REF (Pmode, name);
79e68feb 1781}
f0e969bd 1782#endif
79e68feb
RS
1783\f
1784/* Assemble the integer constant X into an object of SIZE bytes.
1785 X must be either a CONST_INT or CONST_DOUBLE.
1786
1787 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1788 non-zero, abort if we can't output the constant. */
1789
1790int
1791assemble_integer (x, size, force)
1792 rtx x;
1793 int size;
1794 int force;
1795{
1796 /* First try to use the standard 1, 2, 4, 8, and 16 byte
0f41302f 1797 ASM_OUTPUT... macros. */
79e68feb
RS
1798
1799 switch (size)
1800 {
1801#ifdef ASM_OUTPUT_CHAR
1802 case 1:
1803 ASM_OUTPUT_CHAR (asm_out_file, x);
1804 return 1;
1805#endif
1806
1807#ifdef ASM_OUTPUT_SHORT
1808 case 2:
1809 ASM_OUTPUT_SHORT (asm_out_file, x);
1810 return 1;
1811#endif
1812
1813#ifdef ASM_OUTPUT_INT
1814 case 4:
1815 ASM_OUTPUT_INT (asm_out_file, x);
1816 return 1;
1817#endif
1818
1819#ifdef ASM_OUTPUT_DOUBLE_INT
1820 case 8:
1821 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1822 return 1;
1823#endif
1824
1825#ifdef ASM_OUTPUT_QUADRUPLE_INT
1826 case 16:
1827 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1828 return 1;
1829#endif
1830 }
1831
1832 /* If we couldn't do it that way, there are two other possibilities: First,
1833 if the machine can output an explicit byte and this is a 1 byte constant,
1834 we can use ASM_OUTPUT_BYTE. */
1835
1836#ifdef ASM_OUTPUT_BYTE
1837 if (size == 1 && GET_CODE (x) == CONST_INT)
1838 {
1839 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1840 return 1;
1841 }
1842#endif
1843
1844 /* Finally, if SIZE is larger than a single word, try to output the constant
1845 one word at a time. */
1846
1847 if (size > UNITS_PER_WORD)
1848 {
1849 int i;
1850 enum machine_mode mode
1851 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1852 rtx word;
1853
1854 for (i = 0; i < size / UNITS_PER_WORD; i++)
1855 {
1856 word = operand_subword (x, i, 0, mode);
1857
1858 if (word == 0)
1859 break;
1860
fff9e713
MT
1861 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1862 break;
79e68feb
RS
1863 }
1864
1865 if (i == size / UNITS_PER_WORD)
1866 return 1;
fff9e713
MT
1867 /* If we output at least one word and then could not finish,
1868 there is no valid way to continue. */
1869 if (i > 0)
1870 abort ();
79e68feb
RS
1871 }
1872
1873 if (force)
1874 abort ();
1875
1876 return 0;
1877}
1878\f
1879/* Assemble the floating-point constant D into an object of size MODE. */
1880
1881void
1882assemble_real (d, mode)
1883 REAL_VALUE_TYPE d;
1884 enum machine_mode mode;
1885{
1886 jmp_buf output_constant_handler;
1887
1888 if (setjmp (output_constant_handler))
1889 {
1890 error ("floating point trap outputting a constant");
1891#ifdef REAL_IS_NOT_DOUBLE
4c9a05bc 1892 bzero ((char *) &d, sizeof d);
79e68feb
RS
1893 d = dconst0;
1894#else
1895 d = 0;
1896#endif
1897 }
1898
1899 set_float_handler (output_constant_handler);
1900
1901 switch (mode)
1902 {
b7526ea5
RS
1903#ifdef ASM_OUTPUT_BYTE_FLOAT
1904 case QFmode:
1905 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1906 break;
1907#endif
1908#ifdef ASM_OUTPUT_SHORT_FLOAT
1909 case HFmode:
1910 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1911 break;
1912#endif
32c03bfb
RK
1913#ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1914 case TQFmode:
1915 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1916 break;
1917#endif
79e68feb
RS
1918#ifdef ASM_OUTPUT_FLOAT
1919 case SFmode:
1920 ASM_OUTPUT_FLOAT (asm_out_file, d);
1921 break;
1922#endif
1923
1924#ifdef ASM_OUTPUT_DOUBLE
1925 case DFmode:
1926 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1927 break;
1928#endif
1929
1930#ifdef ASM_OUTPUT_LONG_DOUBLE
2c7ff63c 1931 case XFmode:
79e68feb
RS
1932 case TFmode:
1933 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1934 break;
1935#endif
1936
1937 default:
1938 abort ();
1939 }
1940
37366632 1941 set_float_handler (NULL_PTR);
79e68feb
RS
1942}
1943\f
1944/* Here we combine duplicate floating constants to make
1945 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1946
1947/* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1948 They are chained through the CONST_DOUBLE_CHAIN.
1949 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1950 In that case, CONST_DOUBLE_MEM is either a MEM,
57632c51
RS
1951 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1952
1953 (CONST_DOUBLE_MEM is used only for top-level functions.
1954 See force_const_mem for explanation.) */
79e68feb
RS
1955
1956static rtx const_double_chain;
1957
4db92e9a 1958/* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
79e68feb
RS
1959 For an integer, I0 is the low-order word and I1 is the high-order word.
1960 For a real number, I0 is the word with the low address
1961 and I1 is the word with the high address. */
1962
1963rtx
1964immed_double_const (i0, i1, mode)
37366632 1965 HOST_WIDE_INT i0, i1;
79e68feb
RS
1966 enum machine_mode mode;
1967{
1968 register rtx r;
79e68feb 1969
ab8ab9d0
SC
1970 if (GET_MODE_CLASS (mode) == MODE_INT
1971 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
79e68feb
RS
1972 {
1973 /* We clear out all bits that don't belong in MODE, unless they and our
1974 sign bit are all one. So we get either a reasonable negative value
1975 or a reasonable unsigned value for this mode. */
1976 int width = GET_MODE_BITSIZE (mode);
37366632
RK
1977 if (width < HOST_BITS_PER_WIDE_INT
1978 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1979 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1980 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1981 else if (width == HOST_BITS_PER_WIDE_INT
79e68feb
RS
1982 && ! (i1 == ~0 && i0 < 0))
1983 i1 = 0;
37366632 1984 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1985 /* We cannot represent this value as a constant. */
1986 abort ();
1987
2ba3a0ec
JW
1988 /* If this would be an entire word for the target, but is not for
1989 the host, then sign-extend on the host so that the number will look
1990 the same way on the host that it would on the target.
1991
1992 For example, when building a 64 bit alpha hosted 32 bit sparc
1993 targeted compiler, then we want the 32 bit unsigned value -1 to be
1994 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1995 The later confuses the sparc backend. */
1996
1997 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1998 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1999 i0 |= ((HOST_WIDE_INT) (-1) << width);
2000
37366632 2001 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
79e68feb
RS
2002
2003 ??? Strictly speaking, this is wrong if we create a CONST_INT
2004 for a large unsigned constant with the size of MODE being
37366632
RK
2005 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2006 wider mode. In that case we will mis-interpret it as a negative
2007 number.
79e68feb
RS
2008
2009 Unfortunately, the only alternative is to make a CONST_DOUBLE
2010 for any constant in any mode if it is an unsigned constant larger
2011 than the maximum signed integer in an int on the host. However,
2012 doing this will break everyone that always expects to see a CONST_INT
2013 for SImode and smaller.
2014
2015 We have always been making CONST_INTs in this case, so nothing new
2016 is being broken. */
2017
37366632 2018 if (width <= HOST_BITS_PER_WIDE_INT)
7bcac048 2019 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
79e68feb
RS
2020
2021 /* If this integer fits in one word, return a CONST_INT. */
2022 if ((i1 == 0 && i0 >= 0)
2023 || (i1 == ~0 && i0 < 0))
37366632 2024 return GEN_INT (i0);
79e68feb
RS
2025
2026 /* We use VOIDmode for integers. */
2027 mode = VOIDmode;
2028 }
2029
2030 /* Search the chain for an existing CONST_DOUBLE with the right value.
2031 If one is found, return it. */
2032
2033 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2034 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2035 && GET_MODE (r) == mode)
2036 return r;
2037
2038 /* No; make a new one and add it to the chain.
2039
2040 We may be called by an optimizer which may be discarding any memory
2041 allocated during its processing (such as combine and loop). However,
2042 we will be leaving this constant on the chain, so we cannot tolerate
2043 freed memory. So switch to saveable_obstack for this allocation
2044 and then switch back if we were in current_obstack. */
2045
2260924f
JW
2046 push_obstacks_nochange ();
2047 rtl_in_saveable_obstack ();
38a448ca 2048 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2260924f 2049 pop_obstacks ();
79e68feb 2050
179bb78c
JW
2051 /* Don't touch const_double_chain in nested function; see force_const_mem.
2052 Also, don't touch it if not inside any function. */
2053 if (outer_function_chain == 0 && current_function_decl != 0)
5145eda8
RS
2054 {
2055 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2056 const_double_chain = r;
2057 }
79e68feb
RS
2058
2059 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2060 Actual use of mem-slot is only through force_const_mem. */
2061
2062 CONST_DOUBLE_MEM (r) = const0_rtx;
2063
2064 return r;
2065}
2066
2067/* Return a CONST_DOUBLE for a specified `double' value
2068 and machine mode. */
2069
2070rtx
2071immed_real_const_1 (d, mode)
2072 REAL_VALUE_TYPE d;
2073 enum machine_mode mode;
2074{
2075 union real_extract u;
2076 register rtx r;
79e68feb
RS
2077
2078 /* Get the desired `double' value as a sequence of ints
2079 since that is how they are stored in a CONST_DOUBLE. */
2080
2081 u.d = d;
2082
2083 /* Detect special cases. */
2084
41c9120b 2085 if (REAL_VALUES_IDENTICAL (dconst0, d))
79e68feb 2086 return CONST0_RTX (mode);
12194c38
RS
2087 /* Check for NaN first, because some ports (specifically the i386) do not
2088 emit correct ieee-fp code by default, and thus will generate a core
2089 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2090 does a floating point comparison. */
2091 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
79e68feb
RS
2092 return CONST1_RTX (mode);
2093
800d5c9e
RH
2094 if (sizeof u == sizeof (HOST_WIDE_INT))
2095 return immed_double_const (u.i[0], 0, mode);
37366632 2096 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
79e68feb
RS
2097 return immed_double_const (u.i[0], u.i[1], mode);
2098
2099 /* The rest of this function handles the case where
2100 a float value requires more than 2 ints of space.
2101 It will be deleted as dead code on machines that don't need it. */
2102
2103 /* Search the chain for an existing CONST_DOUBLE with the right value.
2104 If one is found, return it. */
2105
2106 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
4c9a05bc 2107 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
79e68feb
RS
2108 && GET_MODE (r) == mode)
2109 return r;
2110
2111 /* No; make a new one and add it to the chain.
2112
2113 We may be called by an optimizer which may be discarding any memory
2114 allocated during its processing (such as combine and loop). However,
2115 we will be leaving this constant on the chain, so we cannot tolerate
2116 freed memory. So switch to saveable_obstack for this allocation
2117 and then switch back if we were in current_obstack. */
2118
2260924f
JW
2119 push_obstacks_nochange ();
2120 rtl_in_saveable_obstack ();
79e68feb
RS
2121 r = rtx_alloc (CONST_DOUBLE);
2122 PUT_MODE (r, mode);
4c9a05bc 2123 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2260924f 2124 pop_obstacks ();
79e68feb 2125
179bb78c
JW
2126 /* Don't touch const_double_chain in nested function; see force_const_mem.
2127 Also, don't touch it if not inside any function. */
2128 if (outer_function_chain == 0 && current_function_decl != 0)
5145eda8
RS
2129 {
2130 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2131 const_double_chain = r;
2132 }
79e68feb
RS
2133
2134 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2135 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2136 is only through force_const_mem. */
2137
2138 CONST_DOUBLE_MEM (r) = const0_rtx;
2139
2140 return r;
2141}
2142
2143/* Return a CONST_DOUBLE rtx for a value specified by EXP,
2144 which must be a REAL_CST tree node. */
2145
2146rtx
2147immed_real_const (exp)
2148 tree exp;
2149{
2150 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2151}
2152
2153/* At the end of a function, forget the memory-constants
2154 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2155 Also clear out real_constant_chain and clear out all the chain-pointers. */
2156
2157void
2158clear_const_double_mem ()
2159{
2160 register rtx r, next;
2161
57632c51
RS
2162 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2163 See force_const_mem for explanation. */
2164 if (outer_function_chain != 0)
2165 return;
2166
79e68feb
RS
2167 for (r = const_double_chain; r; r = next)
2168 {
2169 next = CONST_DOUBLE_CHAIN (r);
2170 CONST_DOUBLE_CHAIN (r) = 0;
2171 CONST_DOUBLE_MEM (r) = cc0_rtx;
2172 }
2173 const_double_chain = 0;
2174}
2175\f
2176/* Given an expression EXP with a constant value,
2177 reduce it to the sum of an assembler symbol and an integer.
2178 Store them both in the structure *VALUE.
2179 Abort if EXP does not reduce. */
2180
2181struct addr_const
2182{
2183 rtx base;
fb351073 2184 HOST_WIDE_INT offset;
79e68feb
RS
2185};
2186
2187static void
2188decode_addr_const (exp, value)
2189 tree exp;
2190 struct addr_const *value;
2191{
2192 register tree target = TREE_OPERAND (exp, 0);
2193 register int offset = 0;
2194 register rtx x;
2195
2196 while (1)
2197 {
2198 if (TREE_CODE (target) == COMPONENT_REF
2199 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2200 == INTEGER_CST))
2201 {
2202 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2203 target = TREE_OPERAND (target, 0);
2204 }
2205 else if (TREE_CODE (target) == ARRAY_REF)
2206 {
2207 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2208 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2209 abort ();
2210 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2211 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2212 / BITS_PER_UNIT);
2213 target = TREE_OPERAND (target, 0);
2214 }
2215 else
2216 break;
2217 }
2218
2219 switch (TREE_CODE (target))
2220 {
2221 case VAR_DECL:
2222 case FUNCTION_DECL:
2223 x = DECL_RTL (target);
2224 break;
2225
2226 case LABEL_DECL:
b93a436e
JL
2227 x = gen_rtx_MEM (FUNCTION_MODE,
2228 gen_rtx_LABEL_REF (VOIDmode,
2229 label_rtx (TREE_OPERAND (exp, 0))));
79e68feb
RS
2230 break;
2231
2232 case REAL_CST:
2233 case STRING_CST:
2234 case COMPLEX_CST:
2235 case CONSTRUCTOR:
2cf55b55 2236 case INTEGER_CST:
79e68feb
RS
2237 x = TREE_CST_RTL (target);
2238 break;
2239
2240 default:
2241 abort ();
2242 }
2243
b93a436e
JL
2244 if (GET_CODE (x) != MEM)
2245 abort ();
2246 x = XEXP (x, 0);
79e68feb
RS
2247
2248 value->base = x;
2249 value->offset = offset;
2250}
2251\f
2252/* Uniquize all constants that appear in memory.
2253 Each constant in memory thus far output is recorded
2254 in `const_hash_table' with a `struct constant_descriptor'
2255 that contains a polish representation of the value of
2256 the constant.
2257
2258 We cannot store the trees in the hash table
2259 because the trees may be temporary. */
2260
2261struct constant_descriptor
2262{
2263 struct constant_descriptor *next;
2264 char *label;
2265 char contents[1];
2266};
2267
2268#define HASHBITS 30
2269#define MAX_HASH_TABLE 1009
2270static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2271
2272/* Compute a hash code for a constant expression. */
2273
5a13eaa4 2274static int
79e68feb
RS
2275const_hash (exp)
2276 tree exp;
2277{
2278 register char *p;
2279 register int len, hi, i;
2280 register enum tree_code code = TREE_CODE (exp);
2281
a9d07d6e
RK
2282 /* Either set P and LEN to the address and len of something to hash and
2283 exit the switch or return a value. */
2284
2285 switch (code)
79e68feb 2286 {
a9d07d6e 2287 case INTEGER_CST:
79e68feb
RS
2288 p = (char *) &TREE_INT_CST_LOW (exp);
2289 len = 2 * sizeof TREE_INT_CST_LOW (exp);
a9d07d6e
RK
2290 break;
2291
2292 case REAL_CST:
79e68feb
RS
2293 p = (char *) &TREE_REAL_CST (exp);
2294 len = sizeof TREE_REAL_CST (exp);
a9d07d6e 2295 break;
79e68feb 2296
a9d07d6e
RK
2297 case STRING_CST:
2298 p = TREE_STRING_POINTER (exp);
2299 len = TREE_STRING_LENGTH (exp);
2300 break;
79e68feb 2301
a9d07d6e
RK
2302 case COMPLEX_CST:
2303 return (const_hash (TREE_REALPART (exp)) * 5
2304 + const_hash (TREE_IMAGPART (exp)));
2305
2306 case CONSTRUCTOR:
2307 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
79e68feb 2308 {
a9d07d6e
RK
2309 len = int_size_in_bytes (TREE_TYPE (exp));
2310 p = (char *) alloca (len);
2311 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2312 break;
2313 }
2314 else
2315 {
2316 register tree link;
2317
2318 /* For record type, include the type in the hashing.
2319 We do not do so for array types
2320 because (1) the sizes of the elements are sufficient
2321 and (2) distinct array types can have the same constructor.
2322 Instead, we include the array size because the constructor could
2323 be shorter. */
2324 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
7bcac048 2325 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
a9d07d6e
RK
2326 % MAX_HASH_TABLE;
2327 else
2328 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2329 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2330
2331 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2332 if (TREE_VALUE (link))
2333 hi
2334 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2335
2336 return hi;
79e68feb 2337 }
79e68feb 2338
a9d07d6e
RK
2339 case ADDR_EXPR:
2340 {
2341 struct addr_const value;
2342
2343 decode_addr_const (exp, &value);
2344 if (GET_CODE (value.base) == SYMBOL_REF)
2345 {
2346 /* Don't hash the address of the SYMBOL_REF;
2347 only use the offset and the symbol name. */
2348 hi = value.offset;
2349 p = XSTR (value.base, 0);
2350 for (i = 0; p[i] != 0; i++)
2351 hi = ((hi * 613) + (unsigned) (p[i]));
2352 }
2353 else if (GET_CODE (value.base) == LABEL_REF)
2354 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2355
2356 hi &= (1 << HASHBITS) - 1;
2357 hi %= MAX_HASH_TABLE;
2358 }
79e68feb 2359 return hi;
a9d07d6e
RK
2360
2361 case PLUS_EXPR:
2362 case MINUS_EXPR:
2363 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2364 + const_hash (TREE_OPERAND (exp, 1)));
2365
2366 case NOP_EXPR:
2367 case CONVERT_EXPR:
2368 case NON_LVALUE_EXPR:
2369 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
e9a25f70
JL
2370
2371 default:
2372 abort ();
79e68feb 2373 }
79e68feb
RS
2374
2375 /* Compute hashing function */
2376 hi = len;
2377 for (i = 0; i < len; i++)
0f41302f 2378 hi = ((hi * 613) + (unsigned) (p[i]));
79e68feb
RS
2379
2380 hi &= (1 << HASHBITS) - 1;
2381 hi %= MAX_HASH_TABLE;
2382 return hi;
2383}
2384\f
2385/* Compare a constant expression EXP with a constant-descriptor DESC.
2386 Return 1 if DESC describes a constant with the same value as EXP. */
2387
2388static int
2389compare_constant (exp, desc)
2390 tree exp;
2391 struct constant_descriptor *desc;
2392{
2393 return 0 != compare_constant_1 (exp, desc->contents);
2394}
2395
2396/* Compare constant expression EXP with a substring P of a constant descriptor.
2397 If they match, return a pointer to the end of the substring matched.
2398 If they do not match, return 0.
2399
2400 Since descriptors are written in polish prefix notation,
2401 this function can be used recursively to test one operand of EXP
2402 against a subdescriptor, and if it succeeds it returns the
2403 address of the subdescriptor for the next operand. */
2404
2405static char *
2406compare_constant_1 (exp, p)
2407 tree exp;
2408 char *p;
2409{
2410 register char *strp;
2411 register int len;
2412 register enum tree_code code = TREE_CODE (exp);
2413
2414 if (code != (enum tree_code) *p++)
2415 return 0;
2416
a9d07d6e
RK
2417 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2418 switch, or return the result of the comparison. */
2419
2420 switch (code)
79e68feb 2421 {
a9d07d6e 2422 case INTEGER_CST:
79e68feb
RS
2423 /* Integer constants are the same only if the same width of type. */
2424 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2425 return 0;
a9d07d6e 2426
79e68feb
RS
2427 strp = (char *) &TREE_INT_CST_LOW (exp);
2428 len = 2 * sizeof TREE_INT_CST_LOW (exp);
a9d07d6e
RK
2429 break;
2430
2431 case REAL_CST:
79e68feb
RS
2432 /* Real constants are the same only if the same width of type. */
2433 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2434 return 0;
a9d07d6e 2435
79e68feb
RS
2436 strp = (char *) &TREE_REAL_CST (exp);
2437 len = sizeof TREE_REAL_CST (exp);
a9d07d6e
RK
2438 break;
2439
2440 case STRING_CST:
79e68feb
RS
2441 if (flag_writable_strings)
2442 return 0;
a9d07d6e 2443
f163668c
RK
2444 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2445 return 0;
2446
79e68feb
RS
2447 strp = TREE_STRING_POINTER (exp);
2448 len = TREE_STRING_LENGTH (exp);
4c9a05bc 2449 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
79e68feb
RS
2450 sizeof TREE_STRING_LENGTH (exp)))
2451 return 0;
a9d07d6e 2452
79e68feb 2453 p += sizeof TREE_STRING_LENGTH (exp);
a9d07d6e 2454 break;
79e68feb 2455
a9d07d6e
RK
2456 case COMPLEX_CST:
2457 p = compare_constant_1 (TREE_REALPART (exp), p);
2458 if (p == 0)
79e68feb 2459 return 0;
79e68feb 2460
a9d07d6e 2461 return compare_constant_1 (TREE_IMAGPART (exp), p);
79e68feb 2462
a9d07d6e
RK
2463 case CONSTRUCTOR:
2464 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
eb528802 2465 {
a9d07d6e
RK
2466 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2467
2468 strp = (char *) alloca (len);
2469 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2470 if (bcmp ((char *) &xlen, p, sizeof xlen))
eb528802 2471 return 0;
eb528802 2472
a9d07d6e
RK
2473 p += sizeof xlen;
2474 break;
2475 }
2476 else
77fa0940 2477 {
a9d07d6e
RK
2478 register tree link;
2479 int length = list_length (CONSTRUCTOR_ELTS (exp));
2480 tree type;
e5e809f4
JL
2481 int have_purpose = 0;
2482
2483 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2484 if (TREE_PURPOSE (link))
2485 have_purpose = 1;
a9d07d6e
RK
2486
2487 if (bcmp ((char *) &length, p, sizeof length))
2488 return 0;
2489
2490 p += sizeof length;
2491
2492 /* For record constructors, insist that the types match.
e5e809f4
JL
2493 For arrays, just verify both constructors are for arrays.
2494 Then insist that either both or none have any TREE_PURPOSE
2495 values. */
a9d07d6e
RK
2496 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2497 type = TREE_TYPE (exp);
2498 else
2499 type = 0;
2500
2501 if (bcmp ((char *) &type, p, sizeof type))
2502 return 0;
2503
2504 p += sizeof type;
2505
e5e809f4
JL
2506 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2507 return 0;
2508
2509 p += sizeof have_purpose;
2510
a9d07d6e
RK
2511 /* For arrays, insist that the size in bytes match. */
2512 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
77fa0940 2513 {
e5e809f4
JL
2514 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2515
a9d07d6e 2516 if (bcmp ((char *) &size, p, sizeof size))
77fa0940 2517 return 0;
a9d07d6e
RK
2518
2519 p += sizeof size;
77fa0940 2520 }
a9d07d6e
RK
2521
2522 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940 2523 {
a9d07d6e
RK
2524 if (TREE_VALUE (link))
2525 {
2526 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2527 return 0;
2528 }
2529 else
2530 {
2531 tree zero = 0;
77fa0940 2532
e5e809f4
JL
2533 if (bcmp ((char *) &zero, p, sizeof zero))
2534 return 0;
2535
2536 p += sizeof zero;
2537 }
2538
2539 if (TREE_PURPOSE (link)
2540 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2541 {
2542 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2543 sizeof TREE_PURPOSE (link)))
2544 return 0;
2545
2546 p += sizeof TREE_PURPOSE (link);
2547 }
2548 else if (TREE_PURPOSE (link))
2549 {
2550 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2551 return 0;
2552 }
2553 else if (have_purpose)
2554 {
2555 int zero = 0;
2556
a9d07d6e
RK
2557 if (bcmp ((char *) &zero, p, sizeof zero))
2558 return 0;
2559
2560 p += sizeof zero;
2561 }
77fa0940 2562 }
a9d07d6e
RK
2563
2564 return p;
77fa0940
RK
2565 }
2566
a9d07d6e
RK
2567 case ADDR_EXPR:
2568 {
2569 struct addr_const value;
2570
2571 decode_addr_const (exp, &value);
2572 strp = (char *) &value.offset;
2573 len = sizeof value.offset;
2574 /* Compare the offset. */
2575 while (--len >= 0)
2576 if (*p++ != *strp++)
2577 return 0;
2578
2579 /* Compare symbol name. */
2580 strp = XSTR (value.base, 0);
2581 len = strlen (strp) + 1;
2582 }
2583 break;
2584
2585 case PLUS_EXPR:
2586 case MINUS_EXPR:
fa212801 2587 case RANGE_EXPR:
79e68feb 2588 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
a9d07d6e
RK
2589 if (p == 0)
2590 return 0;
2591
2592 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2593
2594 case NOP_EXPR:
2595 case CONVERT_EXPR:
2596 case NON_LVALUE_EXPR:
2597 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
e9a25f70
JL
2598
2599 default:
2600 abort ();
79e68feb
RS
2601 }
2602
2603 /* Compare constant contents. */
2604 while (--len >= 0)
2605 if (*p++ != *strp++)
2606 return 0;
2607
2608 return p;
2609}
2610\f
2611/* Construct a constant descriptor for the expression EXP.
2612 It is up to the caller to enter the descriptor in the hash table. */
2613
2614static struct constant_descriptor *
2615record_constant (exp)
2616 tree exp;
2617{
387e854a
RK
2618 struct constant_descriptor *next = 0;
2619 char *label = 0;
79e68feb 2620
387e854a
RK
2621 /* Make a struct constant_descriptor. The first two pointers will
2622 be filled in later. Here we just leave space for them. */
2623
2624 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2625 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
79e68feb
RS
2626 record_constant_1 (exp);
2627 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2628}
2629
2630/* Add a description of constant expression EXP
2631 to the object growing in `permanent_obstack'.
2632 No need to return its address; the caller will get that
2633 from the obstack when the object is complete. */
2634
2635static void
2636record_constant_1 (exp)
2637 tree exp;
2638{
2639 register char *strp;
2640 register int len;
2641 register enum tree_code code = TREE_CODE (exp);
2642
2643 obstack_1grow (&permanent_obstack, (unsigned int) code);
2644
2871d24f 2645 switch (code)
79e68feb 2646 {
2871d24f 2647 case INTEGER_CST:
79e68feb
RS
2648 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2649 strp = (char *) &TREE_INT_CST_LOW (exp);
2650 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2871d24f
RK
2651 break;
2652
2653 case REAL_CST:
79e68feb
RS
2654 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2655 strp = (char *) &TREE_REAL_CST (exp);
2656 len = sizeof TREE_REAL_CST (exp);
2871d24f
RK
2657 break;
2658
2659 case STRING_CST:
79e68feb
RS
2660 if (flag_writable_strings)
2661 return;
2871d24f 2662
f163668c 2663 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
79e68feb
RS
2664 strp = TREE_STRING_POINTER (exp);
2665 len = TREE_STRING_LENGTH (exp);
2666 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2667 sizeof TREE_STRING_LENGTH (exp));
2871d24f
RK
2668 break;
2669
2670 case COMPLEX_CST:
79e68feb
RS
2671 record_constant_1 (TREE_REALPART (exp));
2672 record_constant_1 (TREE_IMAGPART (exp));
2673 return;
79e68feb 2674
2871d24f
RK
2675 case CONSTRUCTOR:
2676 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
eb528802 2677 {
2871d24f
RK
2678 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2679 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2680 obstack_blank (&permanent_obstack, nbytes);
2681 get_set_constructor_bytes
2491d239
PB
2682 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2683 nbytes);
2871d24f 2684 return;
eb528802 2685 }
2871d24f 2686 else
77fa0940 2687 {
2871d24f
RK
2688 register tree link;
2689 int length = list_length (CONSTRUCTOR_ELTS (exp));
2690 tree type;
e5e809f4
JL
2691 int have_purpose = 0;
2692
2693 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2694 if (TREE_PURPOSE (link))
2695 have_purpose = 1;
2871d24f
RK
2696
2697 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2698
2699 /* For record constructors, insist that the types match.
e5e809f4
JL
2700 For arrays, just verify both constructors are for arrays.
2701 Then insist that either both or none have any TREE_PURPOSE
2702 values. */
2871d24f
RK
2703 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2704 type = TREE_TYPE (exp);
77fa0940 2705 else
2871d24f
RK
2706 type = 0;
2707 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
e5e809f4
JL
2708 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2709 sizeof have_purpose);
2871d24f
RK
2710
2711 /* For arrays, insist that the size in bytes match. */
2712 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
77fa0940 2713 {
e5e809f4 2714 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2871d24f
RK
2715 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2716 }
77fa0940 2717
2871d24f
RK
2718 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2719 {
2720 if (TREE_VALUE (link))
2721 record_constant_1 (TREE_VALUE (link));
2722 else
2723 {
2724 tree zero = 0;
2725
e5e809f4
JL
2726 obstack_grow (&permanent_obstack,
2727 (char *) &zero, sizeof zero);
2728 }
2729
2730 if (TREE_PURPOSE (link)
2731 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2732 obstack_grow (&permanent_obstack,
2733 (char *) &TREE_PURPOSE (link),
2734 sizeof TREE_PURPOSE (link));
2735 else if (TREE_PURPOSE (link))
2736 record_constant_1 (TREE_PURPOSE (link));
2737 else if (have_purpose)
2738 {
2739 int zero = 0;
2740
2871d24f
RK
2741 obstack_grow (&permanent_obstack,
2742 (char *) &zero, sizeof zero);
2743 }
77fa0940
RK
2744 }
2745 }
79e68feb 2746 return;
2871d24f
RK
2747
2748 case ADDR_EXPR:
2749 {
2750 struct addr_const value;
2751
2752 decode_addr_const (exp, &value);
2753 /* Record the offset. */
2754 obstack_grow (&permanent_obstack,
2755 (char *) &value.offset, sizeof value.offset);
2756 /* Record the symbol name. */
2757 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2758 strlen (XSTR (value.base, 0)) + 1);
2759 }
79e68feb 2760 return;
2871d24f
RK
2761
2762 case PLUS_EXPR:
2763 case MINUS_EXPR:
fa212801 2764 case RANGE_EXPR:
79e68feb
RS
2765 record_constant_1 (TREE_OPERAND (exp, 0));
2766 record_constant_1 (TREE_OPERAND (exp, 1));
2767 return;
2871d24f
RK
2768
2769 case NOP_EXPR:
2770 case CONVERT_EXPR:
2771 case NON_LVALUE_EXPR:
79e68feb
RS
2772 record_constant_1 (TREE_OPERAND (exp, 0));
2773 return;
2871d24f
RK
2774
2775 default:
2776 abort ();
79e68feb
RS
2777 }
2778
2779 /* Record constant contents. */
2780 obstack_grow (&permanent_obstack, strp, len);
2781}
2782\f
ff8f4401
RS
2783/* Record a list of constant expressions that were passed to
2784 output_constant_def but that could not be output right away. */
2785
2786struct deferred_constant
2787{
2788 struct deferred_constant *next;
2789 tree exp;
2790 int reloc;
2791 int labelno;
2792};
2793
2794static struct deferred_constant *deferred_constants;
2795
8839fca4
ILT
2796/* Another list of constants which should be output after the
2797 function. */
2798static struct deferred_constant *after_function_constants;
2799
ff8f4401
RS
2800/* Nonzero means defer output of addressed subconstants
2801 (i.e., those for which output_constant_def is called.) */
2802static int defer_addressed_constants_flag;
2803
2804/* Start deferring output of subconstants. */
2805
2806void
2807defer_addressed_constants ()
2808{
2809 defer_addressed_constants_flag++;
2810}
2811
2812/* Stop deferring output of subconstants,
2813 and output now all those that have been deferred. */
2814
2815void
2816output_deferred_addressed_constants ()
2817{
2818 struct deferred_constant *p, *next;
2819
2820 defer_addressed_constants_flag--;
2821
2822 if (defer_addressed_constants_flag > 0)
2823 return;
2824
2825 for (p = deferred_constants; p; p = next)
2826 {
2827 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2828 next = p->next;
2829 free (p);
2830 }
2831
2832 deferred_constants = 0;
2833}
d12516f1 2834
8839fca4
ILT
2835/* Output any constants which should appear after a function. */
2836
2837static void
2838output_after_function_constants ()
2839{
2840 struct deferred_constant *p, *next;
2841
2842 for (p = after_function_constants; p; p = next)
2843 {
2844 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2845 next = p->next;
2846 free (p);
2847 }
2848
2849 after_function_constants = 0;
2850}
2851
d12516f1
RS
2852/* Make a copy of the whole tree structure for a constant.
2853 This handles the same types of nodes that compare_constant
2854 and record_constant handle. */
2855
2856static tree
2857copy_constant (exp)
2858 tree exp;
2859{
2860 switch (TREE_CODE (exp))
2861 {
310bbbf4
JW
2862 case ADDR_EXPR:
2863 /* For ADDR_EXPR, we do not want to copy the decl whose address
2864 is requested. We do want to copy constants though. */
2865 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2866 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2867 copy_constant (TREE_OPERAND (exp, 0)));
2868 else
2869 return copy_node (exp);
2870
d12516f1
RS
2871 case INTEGER_CST:
2872 case REAL_CST:
2873 case STRING_CST:
d12516f1
RS
2874 return copy_node (exp);
2875
2876 case COMPLEX_CST:
28eb1cb8
RK
2877 return build_complex (TREE_TYPE (exp),
2878 copy_constant (TREE_REALPART (exp)),
d12516f1
RS
2879 copy_constant (TREE_IMAGPART (exp)));
2880
2881 case PLUS_EXPR:
2882 case MINUS_EXPR:
2883 return build (TREE_CODE (exp), TREE_TYPE (exp),
2884 copy_constant (TREE_OPERAND (exp, 0)),
2885 copy_constant (TREE_OPERAND (exp, 1)));
2886
2887 case NOP_EXPR:
2888 case CONVERT_EXPR:
a9d07d6e 2889 case NON_LVALUE_EXPR:
d12516f1
RS
2890 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2891 copy_constant (TREE_OPERAND (exp, 0)));
2892
2893 case CONSTRUCTOR:
2894 {
2895 tree copy = copy_node (exp);
2896 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2897 tree tail;
2898
bb31ce0a 2899 CONSTRUCTOR_ELTS (copy) = list;
d12516f1
RS
2900 for (tail = list; tail; tail = TREE_CHAIN (tail))
2901 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
474bda6c
PB
2902 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2903 for (tail = list; tail; tail = TREE_CHAIN (tail))
2904 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
d12516f1
RS
2905
2906 return copy;
2907 }
2908
2909 default:
2910 abort ();
2911 }
2912}
ff8f4401 2913\f
79e68feb
RS
2914/* Return an rtx representing a reference to constant data in memory
2915 for the constant expression EXP.
ff8f4401 2916
79e68feb
RS
2917 If assembler code for such a constant has already been output,
2918 return an rtx to refer to it.
ff8f4401
RS
2919 Otherwise, output such a constant in memory (or defer it for later)
2920 and generate an rtx for it.
2921
2922 The TREE_CST_RTL of EXP is set up to point to that rtx.
79e68feb
RS
2923 The const_hash_table records which constants already have label strings. */
2924
2925rtx
2926output_constant_def (exp)
2927 tree exp;
2928{
ff8f4401 2929 register int hash;
79e68feb
RS
2930 register struct constant_descriptor *desc;
2931 char label[256];
2932 char *found = 0;
2933 int reloc;
2934 register rtx def;
2935
79e68feb
RS
2936 if (TREE_CST_RTL (exp))
2937 return TREE_CST_RTL (exp);
2938
2939 /* Make sure any other constants whose addresses appear in EXP
2940 are assigned label numbers. */
2941
2942 reloc = output_addressed_constants (exp);
2943
2944 /* Compute hash code of EXP. Search the descriptors for that hash code
2945 to see if any of them describes EXP. If yes, the descriptor records
2946 the label number already assigned. */
2947
00f07fb9 2948 hash = const_hash (exp) % MAX_HASH_TABLE;
ca695ac9 2949
00f07fb9
RK
2950 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2951 if (compare_constant (exp, desc))
2952 {
2953 found = desc->label;
2954 break;
2955 }
ca695ac9 2956
00f07fb9
RK
2957 if (found == 0)
2958 {
2959 /* No constant equal to EXP is known to have been output.
2960 Make a constant descriptor to enter EXP in the hash table.
2961 Assign the label number and record it in the descriptor for
2962 future calls to this function to find. */
ca695ac9 2963
00f07fb9
RK
2964 /* Create a string containing the label name, in LABEL. */
2965 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2966
2967 desc = record_constant (exp);
2968 desc->next = const_hash_table[hash];
2969 desc->label
2970 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2971 const_hash_table[hash] = desc;
2972 }
2973 else
2974 {
2975 /* Create a string containing the label name, in LABEL. */
2976 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
79e68feb 2977 }
ca695ac9 2978
79e68feb
RS
2979 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2980
2981 push_obstacks_nochange ();
2982 if (TREE_PERMANENT (exp))
2983 end_temporary_allocation ();
2984
38a448ca 2985 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
ca695ac9 2986
00f07fb9 2987 TREE_CST_RTL (exp)
38a448ca 2988 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
00f07fb9 2989 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
05e3bdb9 2990 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
c6df88cb 2991 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
00f07fb9 2992
79e68feb
RS
2993 pop_obstacks ();
2994
2995 /* Optionally set flags or add text to the name to record information
2996 such as that it is a function name. If the name is changed, the macro
8a425a05 2997 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
79e68feb
RS
2998#ifdef ENCODE_SECTION_INFO
2999 ENCODE_SECTION_INFO (exp);
3000#endif
3001
ff8f4401
RS
3002 /* If this is the first time we've seen this particular constant,
3003 output it (or defer its output for later). */
79e68feb
RS
3004 if (found == 0)
3005 {
8839fca4
ILT
3006 int after_function = 0;
3007
3008#ifdef CONSTANT_AFTER_FUNCTION_P
3009 if (current_function_decl != 0
3010 && CONSTANT_AFTER_FUNCTION_P (exp))
3011 after_function = 1;
3012#endif
3013
3014 if (defer_addressed_constants_flag || after_function)
ff8f4401
RS
3015 {
3016 struct deferred_constant *p;
3017 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3018
ff8f4401
RS
3019 push_obstacks_nochange ();
3020 suspend_momentary ();
d12516f1 3021 p->exp = copy_constant (exp);
ff8f4401
RS
3022 pop_obstacks ();
3023 p->reloc = reloc;
3024 p->labelno = const_labelno++;
8839fca4
ILT
3025 if (after_function)
3026 {
3027 p->next = after_function_constants;
3028 after_function_constants = p;
3029 }
3030 else
3031 {
3032 p->next = deferred_constants;
3033 deferred_constants = p;
3034 }
ff8f4401
RS
3035 }
3036 else
3c350eb3
CB
3037 {
3038 /* Do no output if -fsyntax-only. */
3039 if (! flag_syntax_only)
3040 output_constant_def_contents (exp, reloc, const_labelno);
3041 ++const_labelno;
3042 }
ff8f4401
RS
3043 }
3044
3045 return TREE_CST_RTL (exp);
3046}
3047
3048/* Now output assembler code to define the label for EXP,
3049 and follow it with the data of EXP. */
79e68feb 3050
ff8f4401
RS
3051static void
3052output_constant_def_contents (exp, reloc, labelno)
3053 tree exp;
3054 int reloc;
3055 int labelno;
3056{
3057 int align;
3058
8a425a05 3059 if (IN_NAMED_SECTION (exp))
ad4ff310 3060 named_section (exp, NULL, reloc);
8a425a05
DE
3061 else
3062 {
3063 /* First switch to text section, except for writable strings. */
79e68feb 3064#ifdef SELECT_SECTION
8a425a05 3065 SELECT_SECTION (exp, reloc);
79e68feb 3066#else
8a425a05
DE
3067 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3068 || (flag_pic && reloc))
3069 data_section ();
3070 else
3071 readonly_data_section ();
79e68feb 3072#endif
8a425a05 3073 }
79e68feb 3074
ff8f4401
RS
3075 /* Align the location counter as required by EXP's data type. */
3076 align = TYPE_ALIGN (TREE_TYPE (exp));
79e68feb 3077#ifdef CONSTANT_ALIGNMENT
ff8f4401 3078 align = CONSTANT_ALIGNMENT (exp, align);
79e68feb
RS
3079#endif
3080
ff8f4401 3081 if (align > BITS_PER_UNIT)
b93a436e 3082 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
79e68feb 3083
ff8f4401
RS
3084 /* Output the label itself. */
3085 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
79e68feb 3086
ff8f4401
RS
3087 /* Output the value of EXP. */
3088 output_constant (exp,
3089 (TREE_CODE (exp) == STRING_CST
3090 ? TREE_STRING_LENGTH (exp)
3091 : int_size_in_bytes (TREE_TYPE (exp))));
79e68feb 3092
79e68feb
RS
3093}
3094\f
3095/* Similar hash facility for making memory-constants
3096 from constant rtl-expressions. It is used on RISC machines
3097 where immediate integer arguments and constant addresses are restricted
3098 so that such constants must be stored in memory.
3099
3100 This pool of constants is reinitialized for each function
3101 so each function gets its own constants-pool that comes right before it.
3102
3103 All structures allocated here are discarded when functions are saved for
3104 inlining, so they do not need to be allocated permanently. */
3105
3106#define MAX_RTX_HASH_TABLE 61
57632c51 3107static struct constant_descriptor **const_rtx_hash_table;
79e68feb
RS
3108
3109/* Structure to represent sufficient information about a constant so that
3110 it can be output when the constant pool is output, so that function
3111 integration can be done, and to simplify handling on machines that reference
3112 constant pool as base+displacement. */
3113
3114struct pool_constant
3115{
3116 struct constant_descriptor *desc;
3117 struct pool_constant *next;
3118 enum machine_mode mode;
3119 rtx constant;
3120 int labelno;
3121 int align;
3122 int offset;
91674c37 3123 int mark;
79e68feb
RS
3124};
3125
3126/* Pointers to first and last constant in pool. */
3127
3128static struct pool_constant *first_pool, *last_pool;
3129
3130/* Current offset in constant pool (does not include any machine-specific
3131 header. */
3132
3133static int pool_offset;
3134
3135/* Structure used to maintain hash table mapping symbols used to their
3136 corresponding constants. */
3137
3138struct pool_sym
3139{
3140 char *label;
3141 struct pool_constant *pool;
3142 struct pool_sym *next;
3143};
3144
57632c51 3145static struct pool_sym **const_rtx_sym_hash_table;
79e68feb
RS
3146
3147/* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3148 The argument is XSTR (... , 0) */
3149
3150#define SYMHASH(LABEL) \
7bcac048 3151 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
79e68feb
RS
3152\f
3153/* Initialize constant pool hashing for next function. */
3154
3155void
3156init_const_rtx_hash_table ()
3157{
57632c51
RS
3158 const_rtx_hash_table
3159 = ((struct constant_descriptor **)
3160 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3161 const_rtx_sym_hash_table
3162 = ((struct pool_sym **)
3163 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
4c9a05bc 3164 bzero ((char *) const_rtx_hash_table,
57632c51 3165 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
4c9a05bc 3166 bzero ((char *) const_rtx_sym_hash_table,
57632c51 3167 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
79e68feb
RS
3168
3169 first_pool = last_pool = 0;
3170 pool_offset = 0;
3171}
3172
5a13eaa4 3173/* Save and restore status for a nested function. */
57632c51
RS
3174
3175void
e9a25f70 3176save_varasm_status (p, context)
57632c51 3177 struct function *p;
e9a25f70 3178 tree context;
57632c51
RS
3179{
3180 p->const_rtx_hash_table = const_rtx_hash_table;
3181 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3182 p->first_pool = first_pool;
3183 p->last_pool = last_pool;
3184 p->pool_offset = pool_offset;
e9a25f70
JL
3185 p->const_double_chain = const_double_chain;
3186
3187 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3188 if (context == NULL_TREE)
3189 const_double_chain = 0;
57632c51
RS
3190}
3191
3192void
3193restore_varasm_status (p)
3194 struct function *p;
3195{
3196 const_rtx_hash_table = p->const_rtx_hash_table;
3197 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3198 first_pool = p->first_pool;
3199 last_pool = p->last_pool;
3200 pool_offset = p->pool_offset;
e9a25f70 3201 const_double_chain = p->const_double_chain;
57632c51
RS
3202}
3203\f
79e68feb
RS
3204enum kind { RTX_DOUBLE, RTX_INT };
3205
3206struct rtx_const
3207{
3208#ifdef ONLY_INT_FIELDS
3209 unsigned int kind : 16;
3210 unsigned int mode : 16;
3211#else
3212 enum kind kind : 16;
3213 enum machine_mode mode : 16;
3214#endif
3215 union {
3216 union real_extract du;
3217 struct addr_const addr;
0b19a5b9 3218 struct {HOST_WIDE_INT high, low;} di;
79e68feb
RS
3219 } un;
3220};
3221
3222/* Express an rtx for a constant integer (perhaps symbolic)
3223 as the sum of a symbol or label plus an explicit integer.
3224 They are stored into VALUE. */
3225
3226static void
3227decode_rtx_const (mode, x, value)
3228 enum machine_mode mode;
3229 rtx x;
3230 struct rtx_const *value;
3231{
3232 /* Clear the whole structure, including any gaps. */
3233
3234 {
3235 int *p = (int *) value;
3236 int *end = (int *) (value + 1);
3237 while (p < end)
3238 *p++ = 0;
3239 }
3240
0f41302f 3241 value->kind = RTX_INT; /* Most usual kind. */
79e68feb
RS
3242 value->mode = mode;
3243
3244 switch (GET_CODE (x))
3245 {
3246 case CONST_DOUBLE:
3247 value->kind = RTX_DOUBLE;
56e2d435 3248 if (GET_MODE (x) != VOIDmode)
0b19a5b9
RK
3249 {
3250 value->mode = GET_MODE (x);
3251 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3252 (char *) &value->un.du, sizeof value->un.du);
3253 }
3254 else
3255 {
3256 value->un.di.low = CONST_DOUBLE_LOW (x);
3257 value->un.di.high = CONST_DOUBLE_HIGH (x);
3258 }
79e68feb
RS
3259 break;
3260
3261 case CONST_INT:
3262 value->un.addr.offset = INTVAL (x);
3263 break;
3264
3265 case SYMBOL_REF:
3266 case LABEL_REF:
3d037392 3267 case PC:
79e68feb
RS
3268 value->un.addr.base = x;
3269 break;
3270
3271 case CONST:
3272 x = XEXP (x, 0);
3273 if (GET_CODE (x) == PLUS)
3274 {
3275 value->un.addr.base = XEXP (x, 0);
3276 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3277 abort ();
3278 value->un.addr.offset = INTVAL (XEXP (x, 1));
3279 }
3280 else if (GET_CODE (x) == MINUS)
3281 {
3282 value->un.addr.base = XEXP (x, 0);
3283 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3284 abort ();
3285 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3286 }
3287 else
3288 abort ();
3289 break;
3290
3291 default:
3292 abort ();
3293 }
3294
3295 if (value->kind == RTX_INT && value->un.addr.base != 0)
3296 switch (GET_CODE (value->un.addr.base))
3297 {
3298 case SYMBOL_REF:
3299 case LABEL_REF:
3300 /* Use the string's address, not the SYMBOL_REF's address,
3301 for the sake of addresses of library routines.
3302 For a LABEL_REF, compare labels. */
3303 value->un.addr.base = XEXP (value->un.addr.base, 0);
e9a25f70
JL
3304
3305 default:
3306 break;
79e68feb
RS
3307 }
3308}
3309
57632c51
RS
3310/* Given a MINUS expression, simplify it if both sides
3311 include the same symbol. */
3312
3313rtx
3314simplify_subtraction (x)
3315 rtx x;
3316{
3317 struct rtx_const val0, val1;
3318
3319 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3320 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3321
3322 if (val0.un.addr.base == val1.un.addr.base)
3323 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3324 return x;
3325}
3326
79e68feb
RS
3327/* Compute a hash code for a constant RTL expression. */
3328
5a13eaa4 3329static int
79e68feb
RS
3330const_hash_rtx (mode, x)
3331 enum machine_mode mode;
3332 rtx x;
3333{
f8344bea
MH
3334 register int hi;
3335 register size_t i;
79e68feb
RS
3336
3337 struct rtx_const value;
3338 decode_rtx_const (mode, x, &value);
3339
3340 /* Compute hashing function */
3341 hi = 0;
3342 for (i = 0; i < sizeof value / sizeof (int); i++)
3343 hi += ((int *) &value)[i];
3344
3345 hi &= (1 << HASHBITS) - 1;
3346 hi %= MAX_RTX_HASH_TABLE;
3347 return hi;
3348}
3349
3350/* Compare a constant rtl object X with a constant-descriptor DESC.
3351 Return 1 if DESC describes a constant with the same value as X. */
3352
3353static int
3354compare_constant_rtx (mode, x, desc)
3355 enum machine_mode mode;
3356 rtx x;
3357 struct constant_descriptor *desc;
3358{
3359 register int *p = (int *) desc->contents;
3360 register int *strp;
3361 register int len;
3362 struct rtx_const value;
3363
3364 decode_rtx_const (mode, x, &value);
3365 strp = (int *) &value;
3366 len = sizeof value / sizeof (int);
3367
3368 /* Compare constant contents. */
3369 while (--len >= 0)
3370 if (*p++ != *strp++)
3371 return 0;
3372
3373 return 1;
3374}
3375
3376/* Construct a constant descriptor for the rtl-expression X.
3377 It is up to the caller to enter the descriptor in the hash table. */
3378
3379static struct constant_descriptor *
3380record_constant_rtx (mode, x)
3381 enum machine_mode mode;
3382 rtx x;
3383{
3384 struct constant_descriptor *ptr;
3385 char *label;
3386 struct rtx_const value;
3387
3388 decode_rtx_const (mode, x, &value);
3389
75974726
RK
3390 /* Put these things in the saveable obstack so we can ensure it won't
3391 be freed if we are called from combine or some other phase that discards
3392 memory allocated from function_obstack (current_obstack). */
3393 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3394 obstack_grow (saveable_obstack, &label, sizeof label);
79e68feb
RS
3395
3396 /* Record constant contents. */
75974726 3397 obstack_grow (saveable_obstack, &value, sizeof value);
79e68feb 3398
75974726 3399 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
79e68feb
RS
3400}
3401\f
3402/* Given a constant rtx X, make (or find) a memory constant for its value
3403 and return a MEM rtx to refer to it in memory. */
3404
3405rtx
3406force_const_mem (mode, x)
3407 enum machine_mode mode;
3408 rtx x;
3409{
3410 register int hash;
3411 register struct constant_descriptor *desc;
3412 char label[256];
3413 char *found = 0;
3414 rtx def;
3415
3416 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3417 (this will always be true for floating CONST_DOUBLEs that have been
3418 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3419 use the previous copy. Otherwise, make a new one. Note that in
3420 the unlikely event that this same CONST_DOUBLE is used in two different
3421 modes in an alternating fashion, we will allocate a lot of different
3422 memory locations, but this should be extremely rare. */
3423
57632c51
RS
3424 /* Don't use CONST_DOUBLE_MEM in a nested function.
3425 Nested functions have their own constant pools,
3426 so they can't share the same values in CONST_DOUBLE_MEM
3427 with the containing function. */
3428 if (outer_function_chain == 0)
3429 if (GET_CODE (x) == CONST_DOUBLE
3430 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3431 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3432 return CONST_DOUBLE_MEM (x);
79e68feb
RS
3433
3434 /* Compute hash code of X. Search the descriptors for that hash code
3435 to see if any of them describes X. If yes, the descriptor records
3436 the label number already assigned. */
3437
3438 hash = const_hash_rtx (mode, x);
3439
3440 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3441 if (compare_constant_rtx (mode, x, desc))
3442 {
3443 found = desc->label;
3444 break;
3445 }
3446
3447 if (found == 0)
3448 {
3449 register struct pool_constant *pool;
3450 register struct pool_sym *sym;
3451 int align;
3452
3453 /* No constant equal to X is known to have been output.
3454 Make a constant descriptor to enter X in the hash table.
3455 Assign the label number and record it in the descriptor for
3456 future calls to this function to find. */
3457
3458 desc = record_constant_rtx (mode, x);
3459 desc->next = const_rtx_hash_table[hash];
3460 const_rtx_hash_table[hash] = desc;
3461
3462 /* Align the location counter as required by EXP's data type. */
3463 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3464 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3465 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
e5e8a8bf
JW
3466#ifdef CONSTANT_ALIGNMENT
3467 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3468 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3469#endif
79e68feb
RS
3470
3471 pool_offset += align - 1;
3472 pool_offset &= ~ (align - 1);
3473
75974726 3474 /* If RTL is not being placed into the saveable obstack, make a
c0560887
ILT
3475 copy of X that is in the saveable obstack in case we are
3476 being called from combine or some other phase that discards
3477 memory it allocates. We used to only do this if it is a
3478 CONST; however, reload can allocate a CONST_INT when
3479 eliminating registers. */
75974726 3480 if (rtl_obstack != saveable_obstack
c0560887 3481 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
75974726
RK
3482 {
3483 push_obstacks_nochange ();
3484 rtl_in_saveable_obstack ();
3485
c0560887 3486 if (GET_CODE (x) == CONST)
38a448ca
RH
3487 x = gen_rtx_CONST (GET_MODE (x),
3488 gen_rtx_PLUS (GET_MODE (x),
3489 XEXP (XEXP (x, 0), 0),
3490 XEXP (XEXP (x, 0), 1)));
c0560887
ILT
3491 else
3492 x = GEN_INT (INTVAL (x));
3493
75974726
RK
3494 pop_obstacks ();
3495 }
3496
79e68feb
RS
3497 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3498
75974726 3499 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
79e68feb
RS
3500 pool->desc = desc;
3501 pool->constant = x;
3502 pool->mode = mode;
3503 pool->labelno = const_labelno;
3504 pool->align = align;
3505 pool->offset = pool_offset;
d2ce9169 3506 pool->mark = 1;
79e68feb
RS
3507 pool->next = 0;
3508
3509 if (last_pool == 0)
3510 first_pool = pool;
3511 else
3512 last_pool->next = pool;
3513
3514 last_pool = pool;
3515 pool_offset += GET_MODE_SIZE (mode);
3516
3517 /* Create a string containing the label name, in LABEL. */
3518 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3519
3520 ++const_labelno;
3521
3522 desc->label = found
3523 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3524
3525 /* Add label to symbol hash table. */
3526 hash = SYMHASH (found);
75974726 3527 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
79e68feb
RS
3528 sym->label = found;
3529 sym->pool = pool;
3530 sym->next = const_rtx_sym_hash_table[hash];
3531 const_rtx_sym_hash_table[hash] = sym;
3532 }
3533
3534 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3535
38a448ca 3536 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
79e68feb
RS
3537
3538 RTX_UNCHANGING_P (def) = 1;
3539 /* Mark the symbol_ref as belonging to this constants pool. */
3540 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3541 current_function_uses_const_pool = 1;
3542
57632c51
RS
3543 if (outer_function_chain == 0)
3544 if (GET_CODE (x) == CONST_DOUBLE)
3545 {
3546 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3547 {
3548 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3549 const_double_chain = x;
3550 }
3551 CONST_DOUBLE_MEM (x) = def;
3552 }
79e68feb
RS
3553
3554 return def;
3555}
3556\f
3557/* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3558 the corresponding pool_constant structure. */
3559
3560static struct pool_constant *
3561find_pool_constant (addr)
3562 rtx addr;
3563{
3564 struct pool_sym *sym;
3565 char *label = XSTR (addr, 0);
3566
3567 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3568 if (sym->label == label)
3569 return sym->pool;
3570
3571 abort ();
3572}
3573
3574/* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3575
3576rtx
3577get_pool_constant (addr)
3578 rtx addr;
3579{
3580 return (find_pool_constant (addr))->constant;
3581}
3582
3583/* Similar, return the mode. */
3584
3585enum machine_mode
3586get_pool_mode (addr)
3587 rtx addr;
3588{
3589 return (find_pool_constant (addr))->mode;
3590}
3591
3592/* Similar, return the offset in the constant pool. */
3593
3594int
3595get_pool_offset (addr)
3596 rtx addr;
3597{
3598 return (find_pool_constant (addr))->offset;
3599}
3600
3601/* Return the size of the constant pool. */
3602
3603int
3604get_pool_size ()
3605{
3606 return pool_offset;
3607}
3608\f
3609/* Write all the constants in the constant pool. */
3610
3611void
3612output_constant_pool (fnname, fndecl)
c84e2712
KG
3613 char *fnname ATTRIBUTE_UNUSED;
3614 tree fndecl ATTRIBUTE_UNUSED;
79e68feb
RS
3615{
3616 struct pool_constant *pool;
3617 rtx x;
3618 union real_extract u;
3619
91674c37
ILT
3620 /* It is possible for gcc to call force_const_mem and then to later
3621 discard the instructions which refer to the constant. In such a
3622 case we do not need to output the constant. */
8f0e7be4 3623 mark_constant_pool ();
91674c37 3624
79e68feb
RS
3625#ifdef ASM_OUTPUT_POOL_PROLOGUE
3626 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3627#endif
3628
3629 for (pool = first_pool; pool; pool = pool->next)
3630 {
3631 x = pool->constant;
3632
d2ce9169 3633 if (! pool->mark)
91674c37
ILT
3634 continue;
3635
79e68feb
RS
3636 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3637 whose CODE_LABEL has been deleted. This can occur if a jump table
3638 is eliminated by optimization. If so, write a constant of zero
7b2b3f1f
RK
3639 instead. Note that this can also happen by turning the
3640 CODE_LABEL into a NOTE. */
3641 if (((GET_CODE (x) == LABEL_REF
3642 && (INSN_DELETED_P (XEXP (x, 0))
3643 || GET_CODE (XEXP (x, 0)) == NOTE)))
79e68feb
RS
3644 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3645 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
7b2b3f1f
RK
3646 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3647 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
79e68feb
RS
3648 x = const0_rtx;
3649
3650 /* First switch to correct section. */
3651#ifdef SELECT_RTX_SECTION
3652 SELECT_RTX_SECTION (pool->mode, x);
3653#else
3654 readonly_data_section ();
3655#endif
3656
3657#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3658 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3659 pool->align, pool->labelno, done);
3660#endif
3661
3662 if (pool->align > 1)
0003feb2 3663 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
79e68feb
RS
3664
3665 /* Output the label. */
3666 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3667
3668 /* Output the value of the constant itself. */
3669 switch (GET_MODE_CLASS (pool->mode))
3670 {
3671 case MODE_FLOAT:
3672 if (GET_CODE (x) != CONST_DOUBLE)
3673 abort ();
3674
4c9a05bc 3675 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
79e68feb
RS
3676 assemble_real (u.d, pool->mode);
3677 break;
3678
3679 case MODE_INT:
ab8ab9d0 3680 case MODE_PARTIAL_INT:
79e68feb
RS
3681 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3682 break;
3683
3684 default:
3685 abort ();
3686 }
3687
29a82058
JL
3688#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3689 done: ;
3690#endif
3691
7f83c0e7
JL
3692 }
3693
5c8c0abd
ILT
3694#ifdef ASM_OUTPUT_POOL_EPILOGUE
3695 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3696#endif
3697
79e68feb
RS
3698 /* Done with this pool. */
3699 first_pool = last_pool = 0;
3700}
91674c37
ILT
3701
3702/* Look through the instructions for this function, and mark all the
3703 entries in the constant pool which are actually being used. */
3704
3705static void
3706mark_constant_pool ()
3707{
3708 register rtx insn;
d2ce9169 3709 struct pool_constant *pool;
91674c37
ILT
3710
3711 if (first_pool == 0)
3712 return;
3713
d2ce9169
RK
3714 for (pool = first_pool; pool; pool = pool->next)
3715 pool->mark = 0;
3716
91674c37
ILT
3717 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3718 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3719 mark_constants (PATTERN (insn));
3720
3721 for (insn = current_function_epilogue_delay_list;
3722 insn;
3723 insn = XEXP (insn, 1))
3724 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3725 mark_constants (PATTERN (insn));
0e3df013
CB
3726
3727 /* It's possible that the only reference to a symbol is in a symbol
3728 that's in the constant pool. This happens in Fortran under some
3729 situations. (When the constant contains the address of another
3730 constant, and only the first is used directly in an insn.)
3731 This is potentially suboptimal if there's ever a possibility of
3732 backwards (in pool order) 2'd level references. However, it's
3733 not clear that 2'd level references can happen. */
3734 for (pool = first_pool; pool; pool = pool->next)
3735 {
3736 struct pool_sym *sym;
3737 char *label;
3738
3739 /* skip unmarked entries; no insn refers to them. */
3740 if (!pool->mark)
3741 continue;
3742
3743 label = XSTR (pool->constant, 0);
3744
3745 /* Be sure the symbol's value is marked. */
3746 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3747 sym = sym->next)
3748 if (sym->label == label)
3749 sym->pool->mark = 1;
3750 /* If we didn't find it, there's something truly wrong here, but it
3751 will be announced by the assembler. */
3752 }
91674c37
ILT
3753}
3754
3755static void
3756mark_constants (x)
3757 register rtx x;
3758{
3759 register int i;
3760 register char *format_ptr;
3761
3762 if (x == 0)
3763 return;
3764
3765 if (GET_CODE (x) == SYMBOL_REF)
3766 {
3767 if (CONSTANT_POOL_ADDRESS_P (x))
3768 find_pool_constant (x)->mark = 1;
3769 return;
3770 }
eb7b11fd
JW
3771 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3772 a MEM, but does not constitute a use of that MEM. This is particularly
3773 important inside a nested function, because CONST_DOUBLE_MEM may be
3774 a reference to a MEM in the parent's constant pool. See the comment
3775 in force_const_mem. */
3776 else if (GET_CODE (x) == CONST_DOUBLE)
3777 return;
91674c37
ILT
3778
3779 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3780 insns, not any notes that may be attached. We don't want to mark
3781 a constant just because it happens to appear in a REG_EQUIV note. */
3782 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3783 {
3784 mark_constants (PATTERN (x));
3785 return;
3786 }
3787
3788 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3789
3790 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3791 {
3792 switch (*format_ptr++)
3793 {
3794 case 'e':
3795 mark_constants (XEXP (x, i));
3796 break;
3797
3798 case 'E':
3799 if (XVEC (x, i) != 0)
3800 {
3801 register int j;
3802
3803 for (j = 0; j < XVECLEN (x, i); j++)
3804 mark_constants (XVECEXP (x, i, j));
3805 }
3806 break;
3807
3808 case 'S':
3809 case 's':
3810 case '0':
3811 case 'i':
3812 case 'w':
3813 case 'n':
3814 case 'u':
3815 break;
3816
3817 default:
3818 abort ();
3819 }
3820 }
3821}
79e68feb
RS
3822\f
3823/* Find all the constants whose addresses are referenced inside of EXP,
3824 and make sure assembler code with a label has been output for each one.
3825 Indicate whether an ADDR_EXPR has been encountered. */
3826
5a13eaa4 3827static int
79e68feb
RS
3828output_addressed_constants (exp)
3829 tree exp;
3830{
3831 int reloc = 0;
3832
3833 switch (TREE_CODE (exp))
3834 {
3835 case ADDR_EXPR:
3836 {
3837 register tree constant = TREE_OPERAND (exp, 0);
3838
3839 while (TREE_CODE (constant) == COMPONENT_REF)
3840 {
3841 constant = TREE_OPERAND (constant, 0);
3842 }
3843
3844 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3845 || TREE_CODE (constant) == CONSTRUCTOR)
3846 /* No need to do anything here
3847 for addresses of variables or functions. */
3848 output_constant_def (constant);
3849 }
3850 reloc = 1;
3851 break;
3852
3853 case PLUS_EXPR:
3854 case MINUS_EXPR:
3855 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3856 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3857 break;
3858
3859 case NOP_EXPR:
3860 case CONVERT_EXPR:
37a52112 3861 case NON_LVALUE_EXPR:
79e68feb
RS
3862 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3863 break;
3864
3865 case CONSTRUCTOR:
3866 {
3867 register tree link;
3868 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3869 if (TREE_VALUE (link) != 0)
3870 reloc |= output_addressed_constants (TREE_VALUE (link));
3871 }
3872 break;
3873
e9a25f70 3874 default:
79e68feb
RS
3875 break;
3876 }
3877 return reloc;
3878}
3879\f
3880/* Output assembler code for constant EXP to FILE, with no label.
3881 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3882 Assumes output_addressed_constants has been done on EXP already.
3883
3884 Generate exactly SIZE bytes of assembler data, padding at the end
3885 with zeros if necessary. SIZE must always be specified.
3886
3887 SIZE is important for structure constructors,
3888 since trailing members may have been omitted from the constructor.
3889 It is also important for initialization of arrays from string constants
3890 since the full length of the string constant might not be wanted.
3891 It is also needed for initialization of unions, where the initializer's
3892 type is just one member, and that may not be as long as the union.
3893
3894 There a case in which we would fail to output exactly SIZE bytes:
3895 for a structure constructor that wants to produce more than SIZE bytes.
3896 But such constructors will never be generated for any possible input. */
3897
3898void
3899output_constant (exp, size)
3900 register tree exp;
3901 register int size;
3902{
3903 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
79e68feb 3904
e697e20a
MM
3905 /* Some front-ends use constants other than the standard
3906 language-indepdent varieties, but which may still be output
3907 directly. Give the front-end a chance to convert EXP to a
3908 language-independent representation. */
3909 if (lang_expand_constant)
3910 exp = (*lang_expand_constant) (exp);
3911
e9996db7 3912 if (size == 0 || flag_syntax_only)
79e68feb
RS
3913 return;
3914
be1ad04c 3915 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
b81cdf54 3916 That way we get the constant (we hope) inside it. Also, strip off any
4e1bf5f5 3917 NOP_EXPR that converts between two record, union, array, or set types. */
be1ad04c
RK
3918 while ((TREE_CODE (exp) == NOP_EXPR
3919 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4e1bf5f5 3920 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
be1ad04c
RK
3921 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3922 exp = TREE_OPERAND (exp, 0);
3923
fff9e713
MT
3924 /* Allow a constructor with no elements for any data type.
3925 This means to fill the space with zeros. */
77fa0940 3926 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
fff9e713 3927 {
b93a436e 3928 assemble_zeros (size);
fff9e713
MT
3929 return;
3930 }
3931
79e68feb
RS
3932 switch (code)
3933 {
644ea577
RS
3934 case CHAR_TYPE:
3935 case BOOLEAN_TYPE:
79e68feb
RS
3936 case INTEGER_TYPE:
3937 case ENUMERAL_TYPE:
3938 case POINTER_TYPE:
3939 case REFERENCE_TYPE:
3940 /* ??? What about (int)((float)(int)&foo + 4) */
3941 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3942 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3943 exp = TREE_OPERAND (exp, 0);
3944
37366632 3945 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
79e68feb
RS
3946 EXPAND_INITIALIZER),
3947 size, 0))
3948 error ("initializer for integer value is too complicated");
3949 size = 0;
3950 break;
3951
3952 case REAL_TYPE:
3953 if (TREE_CODE (exp) != REAL_CST)
3954 error ("initializer for floating value is not a floating constant");
3955
3956 assemble_real (TREE_REAL_CST (exp),
3957 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3958 size = 0;
3959 break;
3960
3961 case COMPLEX_TYPE:
3962 output_constant (TREE_REALPART (exp), size / 2);
3963 output_constant (TREE_IMAGPART (exp), size / 2);
3964 size -= (size / 2) * 2;
3965 break;
3966
3967 case ARRAY_TYPE:
3968 if (TREE_CODE (exp) == CONSTRUCTOR)
3969 {
3970 output_constructor (exp, size);
3971 return;
3972 }
3973 else if (TREE_CODE (exp) == STRING_CST)
3974 {
3975 int excess = 0;
3976
3977 if (size > TREE_STRING_LENGTH (exp))
3978 {
3979 excess = size - TREE_STRING_LENGTH (exp);
3980 size = TREE_STRING_LENGTH (exp);
3981 }
3982
3983 assemble_string (TREE_STRING_POINTER (exp), size);
3984 size = excess;
3985 }
3986 else
3987 abort ();
3988 break;
3989
3990 case RECORD_TYPE:
3991 case UNION_TYPE:
3992 if (TREE_CODE (exp) == CONSTRUCTOR)
3993 output_constructor (exp, size);
3994 else
3995 abort ();
3996 return;
474bda6c
PB
3997
3998 case SET_TYPE:
3999 if (TREE_CODE (exp) == INTEGER_CST)
4000 assemble_integer (expand_expr (exp, NULL_RTX,
4001 VOIDmode, EXPAND_INITIALIZER),
af13b0fb 4002 size, 1);
474bda6c
PB
4003 else if (TREE_CODE (exp) == CONSTRUCTOR)
4004 {
af13b0fb
DE
4005 unsigned char *buffer = (unsigned char *) alloca (size);
4006 if (get_set_constructor_bytes (exp, buffer, size))
474bda6c 4007 abort ();
b029f99a 4008 assemble_string ((char *) buffer, size);
474bda6c
PB
4009 }
4010 else
4011 error ("unknown set constructor type");
4012 return;
e9a25f70
JL
4013
4014 default:
4015 break; /* ??? */
79e68feb
RS
4016 }
4017
4018 if (size > 0)
4019 assemble_zeros (size);
4020}
ca695ac9 4021
79e68feb
RS
4022\f
4023/* Subroutine of output_constant, used for CONSTRUCTORs
4024 (aggregate constants).
4025 Generate at least SIZE bytes, padding if necessary. */
4026
5a13eaa4 4027static void
79e68feb
RS
4028output_constructor (exp, size)
4029 tree exp;
4030 int size;
4031{
4032 register tree link, field = 0;
13b457e7 4033 HOST_WIDE_INT min_index = 0;
79e68feb
RS
4034 /* Number of bytes output or skipped so far.
4035 In other words, current position within the constructor. */
4036 int total_bytes = 0;
4037 /* Non-zero means BYTE contains part of a byte, to be output. */
4038 int byte_buffer_in_use = 0;
4039 register int byte;
4040
37366632 4041 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
79e68feb
RS
4042 abort ();
4043
4044 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4045 field = TYPE_FIELDS (TREE_TYPE (exp));
4046
d12516f1
RS
4047 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4048 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
13b457e7
RK
4049 min_index
4050 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4051
79e68feb
RS
4052 /* As LINK goes through the elements of the constant,
4053 FIELD goes through the structure fields, if the constant is a structure.
4054 if the constant is a union, then we override this,
4055 by getting the field from the TREE_LIST element.
43f7bed5
VM
4056 But the constant could also be an array. Then FIELD is zero.
4057
4058 There is always a maximum of one element in the chain LINK for unions
4059 (even if the initializer in a source program incorrectly contains
4060 more one). */
79e68feb
RS
4061 for (link = CONSTRUCTOR_ELTS (exp);
4062 link;
4063 link = TREE_CHAIN (link),
4064 field = field ? TREE_CHAIN (field) : 0)
4065 {
4066 tree val = TREE_VALUE (link);
3181cbfd
RS
4067 tree index = 0;
4068
79e68feb 4069 /* the element in a union constructor specifies the proper field. */
3181cbfd
RS
4070
4071 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4072 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
1108dc3d
KKT
4073 {
4074 /* if available, use the type given by link */
4075 if (TREE_PURPOSE (link) != 0)
4076 field = TREE_PURPOSE (link);
4077 }
79e68feb 4078
3181cbfd
RS
4079 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4080 index = TREE_PURPOSE (link);
4081
79e68feb 4082 /* Eliminate the marker that makes a cast not be an lvalue. */
d964285c
CH
4083 if (val != 0)
4084 STRIP_NOPS (val);
79e68feb 4085
8311a11f
PB
4086 if (index && TREE_CODE (index) == RANGE_EXPR)
4087 {
4088 register int fieldsize
4089 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4090 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4091 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4092 HOST_WIDE_INT index;
4093 for (index = lo_index; index <= hi_index; index++)
4094 {
4095 /* Output the element's initial value. */
4096 if (val == 0)
4097 assemble_zeros (fieldsize);
4098 else
4099 output_constant (val, fieldsize);
4100
4101 /* Count its size. */
4102 total_bytes += fieldsize;
4103 }
4104 }
4105 else if (field == 0 || !DECL_BIT_FIELD (field))
79e68feb 4106 {
3181cbfd
RS
4107 /* An element that is not a bit-field. */
4108
79e68feb
RS
4109 register int fieldsize;
4110 /* Since this structure is static,
4111 we know the positions are constant. */
4112 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4113 / BITS_PER_UNIT)
4114 : 0);
3181cbfd
RS
4115 if (index != 0)
4116 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4117 / BITS_PER_UNIT
13b457e7 4118 * (TREE_INT_CST_LOW (index) - min_index));
79e68feb 4119
3181cbfd 4120 /* Output any buffered-up bit-fields preceding this element. */
79e68feb
RS
4121 if (byte_buffer_in_use)
4122 {
4123 ASM_OUTPUT_BYTE (asm_out_file, byte);
4124 total_bytes++;
4125 byte_buffer_in_use = 0;
4126 }
4127
4128 /* Advance to offset of this element.
4129 Note no alignment needed in an array, since that is guaranteed
4130 if each element has the proper size. */
3181cbfd 4131 if ((field != 0 || index != 0) && bitpos != total_bytes)
79e68feb 4132 {
b93a436e 4133 assemble_zeros (bitpos - total_bytes);
79e68feb
RS
4134 total_bytes = bitpos;
4135 }
4136
4137 /* Determine size this element should occupy. */
4138 if (field)
4139 {
4140 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4141 abort ();
4142 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4143 {
4144 /* This avoids overflow trouble. */
4145 tree size_tree = size_binop (CEIL_DIV_EXPR,
4146 DECL_SIZE (field),
4147 size_int (BITS_PER_UNIT));
4148 fieldsize = TREE_INT_CST_LOW (size_tree);
4149 }
4150 else
4151 {
4152 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4153 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4154 }
4155 }
4156 else
4157 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4158
4159 /* Output the element's initial value. */
4160 if (val == 0)
4161 assemble_zeros (fieldsize);
4162 else
4163 output_constant (val, fieldsize);
4164
4165 /* Count its size. */
4166 total_bytes += fieldsize;
4167 }
4168 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4169 error ("invalid initial value for member `%s'",
4170 IDENTIFIER_POINTER (DECL_NAME (field)));
4171 else
4172 {
4173 /* Element that is a bit-field. */
4174
4175 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4176 int end_offset
4177 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4178
4179 if (val == 0)
4180 val = integer_zero_node;
4181
4182 /* If this field does not start in this (or, next) byte,
4183 skip some bytes. */
4184 if (next_offset / BITS_PER_UNIT != total_bytes)
4185 {
4186 /* Output remnant of any bit field in previous bytes. */
4187 if (byte_buffer_in_use)
4188 {
4189 ASM_OUTPUT_BYTE (asm_out_file, byte);
4190 total_bytes++;
4191 byte_buffer_in_use = 0;
4192 }
4193
4194 /* If still not at proper byte, advance to there. */
4195 if (next_offset / BITS_PER_UNIT != total_bytes)
4196 {
4197 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4198 total_bytes = next_offset / BITS_PER_UNIT;
4199 }
4200 }
4201
4202 if (! byte_buffer_in_use)
4203 byte = 0;
4204
4205 /* We must split the element into pieces that fall within
4206 separate bytes, and combine each byte with previous or
4207 following bit-fields. */
4208
b4ac57ab 4209 /* next_offset is the offset n fbits from the beginning of
79e68feb
RS
4210 the structure to the next bit of this element to be processed.
4211 end_offset is the offset of the first bit past the end of
4212 this element. */
4213 while (next_offset < end_offset)
4214 {
4215 int this_time;
e7105755
JW
4216 int shift;
4217 HOST_WIDE_INT value;
79e68feb
RS
4218 int next_byte = next_offset / BITS_PER_UNIT;
4219 int next_bit = next_offset % BITS_PER_UNIT;
4220
4221 /* Advance from byte to byte
4222 within this element when necessary. */
4223 while (next_byte != total_bytes)
4224 {
4225 ASM_OUTPUT_BYTE (asm_out_file, byte);
4226 total_bytes++;
4227 byte = 0;
4228 }
4229
4230 /* Number of bits we can process at once
4231 (all part of the same byte). */
4232 this_time = MIN (end_offset - next_offset,
4233 BITS_PER_UNIT - next_bit);
f76b9db2 4234 if (BYTES_BIG_ENDIAN)
79e68feb 4235 {
f76b9db2
ILT
4236 /* On big-endian machine, take the most significant bits
4237 first (of the bits that are significant)
4238 and put them into bytes from the most significant end. */
4239 shift = end_offset - next_offset - this_time;
4240 /* Don't try to take a bunch of bits that cross
4241 the word boundary in the INTEGER_CST. */
4242 if (shift < HOST_BITS_PER_WIDE_INT
4243 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4244 {
4245 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4246 shift = HOST_BITS_PER_WIDE_INT;
4247 }
4248
4249 /* Now get the bits from the appropriate constant word. */
4250 if (shift < HOST_BITS_PER_WIDE_INT)
4251 {
4252 value = TREE_INT_CST_LOW (val);
4253 }
4254 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4255 {
4256 value = TREE_INT_CST_HIGH (val);
4257 shift -= HOST_BITS_PER_WIDE_INT;
4258 }
4259 else
4260 abort ();
4261 byte |= (((value >> shift)
4262 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4263 << (BITS_PER_UNIT - this_time - next_bit));
79e68feb
RS
4264 }
4265 else
79e68feb 4266 {
f76b9db2
ILT
4267 /* On little-endian machines,
4268 take first the least significant bits of the value
4269 and pack them starting at the least significant
4270 bits of the bytes. */
4271 shift = (next_offset
4272 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4273 /* Don't try to take a bunch of bits that cross
4274 the word boundary in the INTEGER_CST. */
4275 if (shift < HOST_BITS_PER_WIDE_INT
4276 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4277 {
4278 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4279 shift = HOST_BITS_PER_WIDE_INT;
4280 }
4281
4282 /* Now get the bits from the appropriate constant word. */
e9a25f70 4283 if (shift < HOST_BITS_PER_WIDE_INT)
f76b9db2
ILT
4284 value = TREE_INT_CST_LOW (val);
4285 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4286 {
4287 value = TREE_INT_CST_HIGH (val);
4288 shift -= HOST_BITS_PER_WIDE_INT;
4289 }
4290 else
4291 abort ();
4292 byte |= (((value >> shift)
4293 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4294 << next_bit);
79e68feb 4295 }
79e68feb
RS
4296 next_offset += this_time;
4297 byte_buffer_in_use = 1;
4298 }
4299 }
4300 }
4301 if (byte_buffer_in_use)
4302 {
4303 ASM_OUTPUT_BYTE (asm_out_file, byte);
4304 total_bytes++;
4305 }
4306 if (total_bytes < size)
4307 assemble_zeros (size - total_bytes);
4308}
ca695ac9 4309
0e9264a2
JL
4310#ifdef HANDLE_PRAGMA_WEAK
4311/* Add function NAME to the weak symbols list. VALUE is a weak alias
4312 associatd with NAME. */
4313
4314int
4315add_weak (name, value)
4316 char *name;
4317 char *value;
4318{
4319 struct weak_syms *weak;
4320
4321 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4322
4323 if (weak == NULL)
4324 return 0;
4325
4326 weak->next = weak_decls;
4327 weak->name = name;
4328 weak->value = value;
4329 weak_decls = weak;
4330
4331 return 1;
4332}
4333#endif /* HANDLE_PRAGMA_WEAK */
4334
4b8af8d9
JM
4335/* Declare DECL to be a weak symbol. */
4336
4337void
4338declare_weak (decl)
4339 tree decl;
4340{
4341 if (! TREE_PUBLIC (decl))
4342 error_with_decl (decl, "weak declaration of `%s' must be public");
daefd78b
JM
4343 else if (TREE_ASM_WRITTEN (decl))
4344 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4345 else if (SUPPORTS_WEAK)
4346 DECL_WEAK (decl) = 1;
0e9264a2
JL
4347#ifdef HANDLE_PRAGMA_WEAK
4348 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4349#endif
4b8af8d9
JM
4350}
4351
4352/* Emit any pending weak declarations. */
4353
e2af664c
NC
4354#ifdef HANDLE_PRAGMA_WEAK
4355struct weak_syms * weak_decls;
4356#endif
4357
4b8af8d9
JM
4358void
4359weak_finish ()
4360{
4361#ifdef HANDLE_PRAGMA_WEAK
4362 if (HANDLE_PRAGMA_WEAK)
4363 {
eb0430f0
MM
4364 struct weak_syms *t;
4365 for (t = weak_decls; t; t = t->next)
4b8af8d9 4366 {
ec99e58f
RL
4367 if (t->name)
4368 {
4369 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4370 if (t->value)
4371 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4372 }
4373 }
4374 }
4375#endif
4376}
4377
4378/* Remove NAME from the pending list of weak symbols. This prevents
4379 the compiler from emitting multiple .weak directives which confuses
4380 some assemblers. */
4381static void
4382remove_from_pending_weak_list (name)
4383 char *name;
4384{
4385#ifdef HANDLE_PRAGMA_WEAK
4386 if (HANDLE_PRAGMA_WEAK)
4387 {
4388 struct weak_syms *t;
4389 for (t = weak_decls; t; t = t->next)
4390 {
548191a4 4391 if (t->name && strcmp (name, t->name) == 0)
ec99e58f 4392 t->name = NULL;
4b8af8d9
JM
4393 }
4394 }
4395#endif
4396}
4397
4398void
4399assemble_alias (decl, target)
91813b28 4400 tree decl, target ATTRIBUTE_UNUSED;
4b8af8d9 4401{
4b8af8d9
JM
4402 char *name;
4403
0f41302f 4404 make_decl_rtl (decl, (char *) 0, 1);
4b8af8d9
JM
4405 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4406
4927276d 4407#ifdef ASM_OUTPUT_DEF
4b8af8d9
JM
4408 /* Make name accessible from other files, if appropriate. */
4409
4410 if (TREE_PUBLIC (decl))
4411 {
daefd78b
JM
4412#ifdef ASM_WEAKEN_LABEL
4413 if (DECL_WEAK (decl))
ec99e58f
RL
4414 {
4415 ASM_WEAKEN_LABEL (asm_out_file, name);
4416 /* Remove this function from the pending weak list so that
4417 we do not emit multiple .weak directives for it. */
4418 remove_from_pending_weak_list
4419 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4420 }
48ad5afd 4421 else
daefd78b 4422#endif
48ad5afd 4423 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4b8af8d9
JM
4424 }
4425
4426 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
daefd78b 4427 TREE_ASM_WRITTEN (decl) = 1;
4b8af8d9 4428#else
4927276d
JM
4429#ifdef ASM_OUTPUT_WEAK_ALIAS
4430 if (! DECL_WEAK (decl))
4431 warning ("only weak aliases are supported in this configuration");
4432
4433 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4434 TREE_ASM_WRITTEN (decl) = 1;
4435#else
4436 warning ("alias definitions not supported in this configuration; ignored");
4437#endif
4b8af8d9
JM
4438#endif
4439}
f796d997
JM
4440
4441/* This determines whether or not we support link-once semantics. */
4442#ifndef SUPPORTS_ONE_ONLY
4443#ifdef MAKE_DECL_ONE_ONLY
4444#define SUPPORTS_ONE_ONLY 1
4445#else
4446#define SUPPORTS_ONE_ONLY 0
4447#endif
4448#endif
4449
4450/* Returns 1 if the target configuration supports defining public symbols
4451 so that one of them will be chosen at link time instead of generating a
4452 multiply-defined symbol error, whether through the use of weak symbols or
4453 a target-specific mechanism for having duplicates discarded. */
4454
4455int
4456supports_one_only ()
4457{
4458 if (SUPPORTS_ONE_ONLY)
4459 return 1;
4460 return SUPPORTS_WEAK;
4461}
4462
4463/* Set up DECL as a public symbol that can be defined in multiple
4464 translation units without generating a linker error. */
4465
4466void
4467make_decl_one_only (decl)
4468 tree decl;
4469{
4470 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4471 abort ();
4472
4473 TREE_PUBLIC (decl) = 1;
4474
4475 if (TREE_CODE (decl) == VAR_DECL
4476 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4477 DECL_COMMON (decl) = 1;
4478 else if (SUPPORTS_ONE_ONLY)
4479 {
4480#ifdef MAKE_DECL_ONE_ONLY
4481 MAKE_DECL_ONE_ONLY (decl);
4482#endif
4483 DECL_ONE_ONLY (decl) = 1;
4484 }
4485 else if (SUPPORTS_WEAK)
4486 DECL_WEAK (decl) = 1;
4487 else
4488 abort ();
4489}