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