Declare malloc, free, and atexit if inhibit_libc is defined.
[official-gcc.git] / gcc / varasm.c
blob9eb92bc3a0d16e9ce6f26ba793cf7695c043dd7d
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
29 #include "config.h"
30 #include "system.h"
31 #include <setjmp.h>
32 #include "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "output.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "real.h"
42 #include "toplev.h"
43 #include "dbxout.h"
44 #include "sdbout.h"
45 #include "obstack.h"
46 #include "c-pragma.h"
47 #include "ggc.h"
48 #include "tm_p.h"
50 #ifdef XCOFF_DEBUGGING_INFO
51 #include "xcoffout.h"
52 #endif
54 #ifndef TRAMPOLINE_ALIGNMENT
55 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
56 #endif
58 #ifndef ASM_STABS_OP
59 #define ASM_STABS_OP ".stabs"
60 #endif
62 /* Define the prefix to use when check_memory_usage_flag is enable. */
63 #ifdef NO_DOLLAR_IN_LABEL
64 #ifdef NO_DOT_IN_LABEL
65 #define CHKR_PREFIX "chkr_prefix_"
66 #else /* !NO_DOT_IN_LABEL */
67 #define CHKR_PREFIX "chkr."
68 #endif
69 #else /* !NO_DOLLAR_IN_LABEL */
70 #define CHKR_PREFIX "chkr$"
71 #endif
72 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
74 /* File in which assembler code is being written. */
76 extern FILE *asm_out_file;
78 /* The (assembler) name of the first globally-visible object output. */
79 char *first_global_object_name;
80 char *weak_global_object_name;
82 extern struct obstack *current_obstack;
83 extern struct obstack *saveable_obstack;
84 extern struct obstack *rtl_obstack;
85 extern struct obstack permanent_obstack;
86 #define obstack_chunk_alloc xmalloc
88 struct addr_const;
89 struct constant_descriptor;
90 struct rtx_const;
91 struct pool_constant;
93 #define MAX_RTX_HASH_TABLE 61
95 struct varasm_status
97 /* Hash facility for making memory-constants
98 from constant rtl-expressions. It is used on RISC machines
99 where immediate integer arguments and constant addresses are restricted
100 so that such constants must be stored in memory.
102 This pool of constants is reinitialized for each function
103 so each function gets its own constants-pool that comes right before
104 it. */
105 struct constant_descriptor **x_const_rtx_hash_table;
106 struct pool_sym **x_const_rtx_sym_hash_table;
108 /* Pointers to first and last constant in pool. */
109 struct pool_constant *x_first_pool, *x_last_pool;
111 /* Current offset in constant pool (does not include any machine-specific
112 header. */
113 int x_pool_offset;
115 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
116 They are chained through the CONST_DOUBLE_CHAIN.
117 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
118 In that case, CONST_DOUBLE_MEM is either a MEM,
119 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
120 rtx x_const_double_chain;
123 #define const_rtx_hash_table (current_function->varasm->x_const_rtx_hash_table)
124 #define const_rtx_sym_hash_table (current_function->varasm->x_const_rtx_sym_hash_table)
125 #define first_pool (current_function->varasm->x_first_pool)
126 #define last_pool (current_function->varasm->x_last_pool)
127 #define pool_offset (current_function->varasm->x_pool_offset)
128 #define const_double_chain (current_function->varasm->x_const_double_chain)
130 /* Number for making the label on the next
131 constant that is stored in memory. */
133 int const_labelno;
135 /* Number for making the label on the next
136 static variable internal to a function. */
138 int var_labelno;
140 /* Carry information from ASM_DECLARE_OBJECT_NAME
141 to ASM_FINISH_DECLARE_OBJECT. */
143 int size_directive_output;
145 /* The last decl for which assemble_variable was called,
146 if it did ASM_DECLARE_OBJECT_NAME.
147 If the last call to assemble_variable didn't do that,
148 this holds 0. */
150 tree last_assemble_variable_decl;
152 /* Nonzero if at least one function definition has been seen. */
154 static int function_defined;
156 static const char *strip_reg_name PROTO((const char *));
157 static int contains_pointers_p PROTO((tree));
158 static void decode_addr_const PROTO((tree, struct addr_const *));
159 static int const_hash PROTO((tree));
160 static int compare_constant PROTO((tree,
161 struct constant_descriptor *));
162 static char *compare_constant_1 PROTO((tree, char *));
163 static struct constant_descriptor *record_constant PROTO((tree));
164 static void record_constant_1 PROTO((tree));
165 static tree copy_constant PROTO((tree));
166 static void output_constant_def_contents PROTO((tree, int, int));
167 static void decode_rtx_const PROTO((enum machine_mode, rtx,
168 struct rtx_const *));
169 static int const_hash_rtx PROTO((enum machine_mode, rtx));
170 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
171 struct constant_descriptor *));
172 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
173 rtx));
174 static struct pool_constant *find_pool_constant PROTO((struct function *, rtx));
175 static void mark_constant_pool PROTO((void));
176 static void mark_constants PROTO((rtx));
177 static int output_addressed_constants PROTO((tree));
178 static void output_after_function_constants PROTO((void));
179 static void output_constructor PROTO((tree, int));
180 #ifdef ASM_WEAKEN_LABEL
181 static void remove_from_pending_weak_list PROTO ((char *));
182 #endif
183 #ifdef ASM_OUTPUT_BSS
184 static void asm_output_bss PROTO((FILE *, tree, char *, int, int));
185 #endif
186 #ifdef BSS_SECTION_ASM_OP
187 #ifdef ASM_OUTPUT_ALIGNED_BSS
188 static void asm_output_aligned_bss PROTO((FILE *, tree, char *, int, int));
189 #endif
190 #endif /* BSS_SECTION_ASM_OP */
191 static void mark_pool_constant PROTO((struct pool_constant *));
192 static void mark_pool_sym_hash_table PROTO((struct pool_sym **));
193 static void mark_const_hash_entry PROTO((void *));
194 static void asm_emit_uninitialised PROTO((tree, char *, int, int));
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;
208 /* Return a non-zero value if DECL has a section attribute. */
209 #define IN_NAMED_SECTION(DECL) \
210 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
211 && DECL_SECTION_NAME (DECL) != NULL_TREE)
213 /* Text of section name when in_section == in_named. */
214 static char *in_named_name;
216 /* Define functions like text_section for any extra sections. */
217 #ifdef EXTRA_SECTION_FUNCTIONS
218 EXTRA_SECTION_FUNCTIONS
219 #endif
221 /* Tell assembler to switch to text section. */
223 void
224 text_section ()
226 if (in_section != in_text)
228 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
229 in_section = in_text;
233 /* Tell assembler to switch to data section. */
235 void
236 data_section ()
238 if (in_section != in_data)
240 if (flag_shared_data)
242 #ifdef SHARED_SECTION_ASM_OP
243 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
244 #else
245 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
246 #endif
248 else
249 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
251 in_section = in_data;
254 /* Tell assembler to ALWAYS switch to data section, in case
255 it's not sure where it it. */
257 void
258 force_data_section ()
260 in_section = no_section;
261 data_section ();
264 /* Tell assembler to switch to read-only data section. This is normally
265 the text section. */
267 void
268 readonly_data_section ()
270 #ifdef READONLY_DATA_SECTION
271 READONLY_DATA_SECTION (); /* Note this can call data_section. */
272 #else
273 text_section ();
274 #endif
277 /* Determine if we're in the text section. */
280 in_text_section ()
282 return in_section == in_text;
285 /* Determine if we're in the data section. */
288 in_data_section ()
290 return in_section == in_data;
293 /* Tell assembler to change to section NAME for DECL.
294 If DECL is NULL, just switch to section NAME.
295 If NAME is NULL, get the name from DECL.
296 If RELOC is 1, the initializer for DECL contains relocs. */
298 void
299 named_section (decl, name, reloc)
300 tree decl;
301 const char *name;
302 int reloc ATTRIBUTE_UNUSED;
304 if (decl != NULL_TREE
305 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
306 abort ();
307 if (name == NULL)
308 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
310 if (in_section != in_named || strcmp (name, in_named_name))
312 #ifdef ASM_OUTPUT_SECTION_NAME
313 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
314 #else
315 /* Section attributes are not supported if this macro isn't provided -
316 some host formats don't support them at all. The front-end should
317 already have flagged this as an error. */
318 abort ();
319 #endif
321 in_named_name = ggc_alloc_string (name, -1);
322 in_section = in_named;
326 #ifdef ASM_OUTPUT_SECTION_NAME
327 #ifndef UNIQUE_SECTION
328 #define UNIQUE_SECTION(DECL,RELOC) \
329 do { \
330 int len; \
331 const char *name; \
332 char *string; \
334 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
335 /* Strip off any encoding in name. */ \
336 STRIP_NAME_ENCODING (name, name); \
338 len = strlen (name) + 1; \
339 string = alloca (len + 1); \
340 sprintf (string, ".%s", name); \
342 DECL_SECTION_NAME (DECL) = build_string (len, string); \
343 } while (0)
344 #endif
345 #ifndef UNIQUE_SECTION_P
346 #define UNIQUE_SECTION_P(DECL) 0
347 #endif
348 #endif
350 #ifdef BSS_SECTION_ASM_OP
352 /* Tell the assembler to switch to the bss section. */
354 void
355 bss_section ()
357 if (in_section != in_bss)
359 #ifdef SHARED_BSS_SECTION_ASM_OP
360 if (flag_shared_data)
361 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
362 else
363 #endif
364 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
366 in_section = in_bss;
370 #ifdef ASM_OUTPUT_BSS
372 /* Utility function for ASM_OUTPUT_BSS for targets to use if
373 they don't support alignments in .bss.
374 ??? It is believed that this function will work in most cases so such
375 support is localized here. */
377 static void
378 asm_output_bss (file, decl, name, size, rounded)
379 FILE *file;
380 tree decl;
381 char *name;
382 int size, rounded;
384 ASM_GLOBALIZE_LABEL (file, name);
385 bss_section ();
386 #ifdef ASM_DECLARE_OBJECT_NAME
387 last_assemble_variable_decl = decl;
388 ASM_DECLARE_OBJECT_NAME (file, name, decl);
389 #else
390 /* Standard thing is just output label for the object. */
391 ASM_OUTPUT_LABEL (file, name);
392 #endif /* ASM_DECLARE_OBJECT_NAME */
393 ASM_OUTPUT_SKIP (file, rounded);
396 #endif
398 #ifdef ASM_OUTPUT_ALIGNED_BSS
400 /* Utility function for targets to use in implementing
401 ASM_OUTPUT_ALIGNED_BSS.
402 ??? It is believed that this function will work in most cases so such
403 support is localized here. */
405 static void
406 asm_output_aligned_bss (file, decl, name, size, align)
407 FILE *file;
408 tree decl;
409 char *name;
410 int size, align;
412 ASM_GLOBALIZE_LABEL (file, name);
413 bss_section ();
414 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
415 #ifdef ASM_DECLARE_OBJECT_NAME
416 last_assemble_variable_decl = decl;
417 ASM_DECLARE_OBJECT_NAME (file, name, decl);
418 #else
419 /* Standard thing is just output label for the object. */
420 ASM_OUTPUT_LABEL (file, name);
421 #endif /* ASM_DECLARE_OBJECT_NAME */
422 ASM_OUTPUT_SKIP (file, size ? size : 1);
425 #endif
427 #endif /* BSS_SECTION_ASM_OP */
429 #ifdef EH_FRAME_SECTION_ASM_OP
430 void
431 eh_frame_section ()
433 if (in_section != in_eh_frame)
435 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
436 in_section = in_eh_frame;
439 #endif
441 /* Switch to the section for function DECL.
443 If DECL is NULL_TREE, switch to the text section.
444 ??? It's not clear that we will ever be passed NULL_TREE, but it's
445 safer to handle it. */
447 void
448 function_section (decl)
449 tree decl;
451 if (decl != NULL_TREE
452 && DECL_SECTION_NAME (decl) != NULL_TREE)
453 named_section (decl, (char *) 0, 0);
454 else
455 text_section ();
458 /* Switch to section for variable DECL.
460 RELOC is the `reloc' argument to SELECT_SECTION. */
462 void
463 variable_section (decl, reloc)
464 tree decl;
465 int reloc;
467 if (IN_NAMED_SECTION (decl))
468 named_section (decl, NULL, reloc);
469 else
471 /* C++ can have const variables that get initialized from constructors,
472 and thus can not be in a readonly section. We prevent this by
473 verifying that the initial value is constant for objects put in a
474 readonly section.
476 error_mark_node is used by the C front end to indicate that the
477 initializer has not been seen yet. In this case, we assume that
478 the initializer must be constant.
480 C++ uses error_mark_node for variables that have complicated
481 initializers, but these variables go in BSS so we won't be called
482 for them. */
484 #ifdef SELECT_SECTION
485 SELECT_SECTION (decl, reloc);
486 #else
487 if (DECL_READONLY_SECTION (decl, reloc))
488 readonly_data_section ();
489 else
490 data_section ();
491 #endif
495 /* Tell assembler to switch to the section for the exception handling
496 table. */
498 void
499 exception_section ()
501 #if defined (EXCEPTION_SECTION)
502 EXCEPTION_SECTION ();
503 #else
504 #ifdef ASM_OUTPUT_SECTION_NAME
505 named_section (NULL_TREE, ".gcc_except_table", 0);
506 #else
507 if (flag_pic)
508 data_section ();
509 else
510 readonly_data_section ();
511 #endif
512 #endif
515 /* Create the rtl to represent a function, for a function definition.
516 DECL is a FUNCTION_DECL node which describes which function.
517 The rtl is stored into DECL. */
519 void
520 make_function_rtl (decl)
521 tree decl;
523 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
524 char *new_name = name;
526 /* Rename a nested function to avoid conflicts. */
527 if (decl_function_context (decl) != 0
528 && DECL_INITIAL (decl) != 0
529 && DECL_RTL (decl) == 0)
531 char *label;
533 name = IDENTIFIER_POINTER (DECL_NAME (decl));
534 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
535 name = ggc_alloc_string (label, -1);
536 var_labelno++;
538 else
540 /* When -fprefix-function-name is used, every function name is
541 prefixed. Even static functions are prefixed because they
542 could be declared latter. Note that a nested function name
543 is not prefixed. */
544 if (flag_prefix_function_name)
546 size_t name_len = strlen (name);
548 new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
549 memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
550 memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
551 name = new_name;
555 if (DECL_RTL (decl) == 0)
557 DECL_RTL (decl)
558 = gen_rtx_MEM (DECL_MODE (decl),
559 gen_rtx_SYMBOL_REF (Pmode, name));
561 /* Optionally set flags or add text to the name to record information
562 such as that it is a function name. If the name is changed, the macro
563 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
564 #ifdef ENCODE_SECTION_INFO
565 ENCODE_SECTION_INFO (decl);
566 #endif
568 else
570 /* ??? Another way to do this would be to do what halfpic.c does
571 and maintain a hashed table of such critters. */
572 /* ??? Another way to do this would be to pass a flag bit to
573 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
574 /* Let the target reassign the RTL if it wants.
575 This is necessary, for example, when one machine specific
576 decl attribute overrides another. */
577 #ifdef REDO_SECTION_INFO_P
578 if (REDO_SECTION_INFO_P (decl))
579 ENCODE_SECTION_INFO (decl);
580 #endif
583 /* Record at least one function has been defined. */
584 function_defined = 1;
587 /* Given NAME, a putative register name, discard any customary prefixes. */
589 static const char *
590 strip_reg_name (name)
591 const char *name;
593 #ifdef REGISTER_PREFIX
594 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
595 name += strlen (REGISTER_PREFIX);
596 #endif
597 if (name[0] == '%' || name[0] == '#')
598 name++;
599 return name;
602 /* Decode an `asm' spec for a declaration as a register name.
603 Return the register number, or -1 if nothing specified,
604 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
605 or -3 if ASMSPEC is `cc' and is not recognized,
606 or -4 if ASMSPEC is `memory' and is not recognized.
607 Accept an exact spelling or a decimal number.
608 Prefixes such as % are optional. */
611 decode_reg_name (asmspec)
612 const char *asmspec;
614 if (asmspec != 0)
616 int i;
618 /* Get rid of confusing prefixes. */
619 asmspec = strip_reg_name (asmspec);
621 /* Allow a decimal number as a "register name". */
622 for (i = strlen (asmspec) - 1; i >= 0; i--)
623 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
624 break;
625 if (asmspec[0] != 0 && i < 0)
627 i = atoi (asmspec);
628 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
629 return i;
630 else
631 return -2;
634 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
635 if (reg_names[i][0]
636 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
637 return i;
639 #ifdef ADDITIONAL_REGISTER_NAMES
641 static struct { const char *name; int number; } table[]
642 = ADDITIONAL_REGISTER_NAMES;
644 for (i = 0; i < (int)(sizeof (table) / sizeof (table[0])); i++)
645 if (! strcmp (asmspec, table[i].name))
646 return table[i].number;
648 #endif /* ADDITIONAL_REGISTER_NAMES */
650 if (!strcmp (asmspec, "memory"))
651 return -4;
653 if (!strcmp (asmspec, "cc"))
654 return -3;
656 return -2;
659 return -1;
662 /* Create the DECL_RTL for a declaration for a static or external variable
663 or static or external function.
664 ASMSPEC, if not 0, is the string which the user specified
665 as the assembler symbol name.
666 TOP_LEVEL is nonzero if this is a file-scope variable.
668 This is never called for PARM_DECL nodes. */
670 void
671 make_decl_rtl (decl, asmspec, top_level)
672 tree decl;
673 const char *asmspec;
674 int top_level;
676 register char *name = 0;
677 int reg_number;
679 reg_number = decode_reg_name (asmspec);
681 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
682 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
684 if (reg_number == -2)
686 /* ASMSPEC is given, and not the name of a register. */
687 size_t len = strlen (asmspec);
689 name = ggc_alloc_string (NULL, len + 1);
690 name[0] = '*';
691 memcpy (&name[1], asmspec, len + 1);
694 /* For a duplicate declaration, we can be called twice on the
695 same DECL node. Don't discard the RTL already made. */
696 if (DECL_RTL (decl) == 0)
698 /* First detect errors in declaring global registers. */
699 if (TREE_CODE (decl) != FUNCTION_DECL
700 && DECL_REGISTER (decl) && reg_number == -1)
701 error_with_decl (decl,
702 "register name not specified for `%s'");
703 else if (TREE_CODE (decl) != FUNCTION_DECL
704 && DECL_REGISTER (decl) && reg_number < 0)
705 error_with_decl (decl,
706 "invalid register name for `%s'");
707 else if ((reg_number >= 0 || reg_number == -3)
708 && (TREE_CODE (decl) == FUNCTION_DECL
709 && ! DECL_REGISTER (decl)))
710 error_with_decl (decl,
711 "register name given for non-register variable `%s'");
712 else if (TREE_CODE (decl) != FUNCTION_DECL
713 && DECL_REGISTER (decl)
714 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
715 error_with_decl (decl,
716 "data type of `%s' isn't suitable for a register");
717 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
718 && ! HARD_REGNO_MODE_OK (reg_number,
719 TYPE_MODE (TREE_TYPE (decl))))
720 error_with_decl (decl,
721 "register number for `%s' isn't suitable for data type");
722 /* Now handle properly declared static register variables. */
723 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
725 int nregs;
727 if (DECL_INITIAL (decl) != 0 && top_level)
729 DECL_INITIAL (decl) = 0;
730 error ("global register variable has initial value");
732 if (fixed_regs[reg_number] == 0
733 && function_defined && top_level)
734 error ("global register variable follows a function definition");
735 if (TREE_THIS_VOLATILE (decl))
736 warning ("volatile register variables don't work as you might wish");
738 /* If the user specified one of the eliminables registers here,
739 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
740 confused with that register and be eliminated. Although this
741 usage is somewhat suspect, we nevertheless use the following
742 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
744 DECL_RTL (decl)
745 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
746 REGNO (DECL_RTL (decl)) = reg_number;
747 REG_USERVAR_P (DECL_RTL (decl)) = 1;
749 if (top_level)
751 /* Make this register global, so not usable for anything
752 else. */
753 #ifdef ASM_DECLARE_REGISTER_GLOBAL
754 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
755 #endif
756 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
757 while (nregs > 0)
758 globalize_reg (reg_number + --nregs);
761 /* Specifying a section attribute on a variable forces it into a
762 non-.bss section, and thus it cannot be common. */
763 else if (TREE_CODE (decl) == VAR_DECL
764 && DECL_SECTION_NAME (decl) != NULL_TREE
765 && DECL_INITIAL (decl) == NULL_TREE
766 && DECL_COMMON (decl))
767 DECL_COMMON (decl) = 0;
769 /* Now handle ordinary static variables and functions (in memory).
770 Also handle vars declared register invalidly. */
771 if (DECL_RTL (decl) == 0)
773 /* Can't use just the variable's own name for a variable
774 whose scope is less than the whole file.
775 Concatenate a distinguishing number. */
776 if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
778 char *label;
780 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
781 name = ggc_alloc_string (label, -1);
782 var_labelno++;
785 if (name == 0)
786 abort ();
788 /* When -fprefix-function-name is used, the functions
789 names are prefixed. Only nested function names are not
790 prefixed. */
791 if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
793 size_t name_len = strlen (name);
794 char *new_name;
796 new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
797 memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
798 memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
799 name = new_name;
802 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
803 gen_rtx_SYMBOL_REF (Pmode, name));
804 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
806 /* If this variable is to be treated as volatile, show its
807 tree node has side effects. If it has side effects, either
808 because of this test or from TREE_THIS_VOLATILE also
809 being set, show the MEM is volatile. */
810 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
811 && TREE_PUBLIC (decl))
812 TREE_SIDE_EFFECTS (decl) = 1;
813 else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
814 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
815 TREE_SIDE_EFFECTS (decl) = 1;
817 if (TREE_SIDE_EFFECTS (decl))
818 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
820 if (TREE_READONLY (decl))
821 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
822 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
823 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
825 /* Optionally set flags or add text to the name to record information
826 such as that it is a function name.
827 If the name is changed, the macro ASM_OUTPUT_LABELREF
828 will have to know how to strip this information. */
829 #ifdef ENCODE_SECTION_INFO
830 ENCODE_SECTION_INFO (decl);
831 #endif
834 else
836 /* If the old RTL had the wrong mode, fix the mode. */
837 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
839 rtx rtl = DECL_RTL (decl);
840 PUT_MODE (rtl, DECL_MODE (decl));
843 /* ??? Another way to do this would be to do what halfpic.c does
844 and maintain a hashed table of such critters. */
845 /* ??? Another way to do this would be to pass a flag bit to
846 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
847 /* Let the target reassign the RTL if it wants.
848 This is necessary, for example, when one machine specific
849 decl attribute overrides another. */
850 #ifdef REDO_SECTION_INFO_P
851 if (REDO_SECTION_INFO_P (decl))
852 ENCODE_SECTION_INFO (decl);
853 #endif
857 /* Make the rtl for variable VAR be volatile.
858 Use this only for static variables. */
860 void
861 make_var_volatile (var)
862 tree var;
864 if (GET_CODE (DECL_RTL (var)) != MEM)
865 abort ();
867 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
870 /* Output alignment directive to align for constant expression EXP. */
872 void
873 assemble_constant_align (exp)
874 tree exp;
876 int align;
878 /* Align the location counter as required by EXP's data type. */
879 align = TYPE_ALIGN (TREE_TYPE (exp));
880 #ifdef CONSTANT_ALIGNMENT
881 align = CONSTANT_ALIGNMENT (exp, align);
882 #endif
884 if (align > BITS_PER_UNIT)
885 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
888 /* Output a string of literal assembler code
889 for an `asm' keyword used between functions. */
891 void
892 assemble_asm (string)
893 tree string;
895 app_enable ();
897 if (TREE_CODE (string) == ADDR_EXPR)
898 string = TREE_OPERAND (string, 0);
900 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
903 #if 0 /* This should no longer be needed, because
904 flag_gnu_linker should be 0 on these systems,
905 which should prevent any output
906 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
907 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
908 #ifndef ASM_OUTPUT_CONSTRUCTOR
909 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
910 #endif
911 #ifndef ASM_OUTPUT_DESTRUCTOR
912 #define ASM_OUTPUT_DESTRUCTOR(file, name)
913 #endif
914 #endif
915 #endif /* 0 */
917 /* Record an element in the table of global destructors.
918 How this is done depends on what sort of assembler and linker
919 are in use.
921 NAME should be the name of a global function to be called
922 at exit time. This name is output using assemble_name. */
924 void
925 assemble_destructor (name)
926 char *name;
928 #ifdef ASM_OUTPUT_DESTRUCTOR
929 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
930 #else
931 if (flag_gnu_linker)
933 /* Now tell GNU LD that this is part of the static destructor set. */
934 /* This code works for any machine provided you use GNU as/ld. */
935 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
936 assemble_name (asm_out_file, name);
937 fputc ('\n', asm_out_file);
939 #endif
942 /* Likewise for global constructors. */
944 void
945 assemble_constructor (name)
946 char *name;
948 #ifdef ASM_OUTPUT_CONSTRUCTOR
949 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
950 #else
951 if (flag_gnu_linker)
953 /* Now tell GNU LD that this is part of the static constructor set. */
954 /* This code works for any machine provided you use GNU as/ld. */
955 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
956 assemble_name (asm_out_file, name);
957 fputc ('\n', asm_out_file);
959 #endif
962 /* Likewise for entries we want to record for garbage collection.
963 Garbage collection is still under development. */
965 void
966 assemble_gc_entry (name)
967 char *name;
969 #ifdef ASM_OUTPUT_GC_ENTRY
970 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
971 #else
972 if (flag_gnu_linker)
974 /* Now tell GNU LD that this is part of the static constructor set. */
975 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
976 assemble_name (asm_out_file, name);
977 fputc ('\n', asm_out_file);
979 #endif
982 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
983 a non-zero value if the constant pool should be output before the
984 start of the function, or a zero value if the pool should output
985 after the end of the function. The default is to put it before the
986 start. */
988 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
989 #define CONSTANT_POOL_BEFORE_FUNCTION 1
990 #endif
992 /* Output assembler code for the constant pool of a function and associated
993 with defining the name of the function. DECL describes the function.
994 NAME is the function's name. For the constant pool, we use the current
995 constant pool data. */
997 void
998 assemble_start_function (decl, fnname)
999 tree decl;
1000 char *fnname;
1002 int align;
1004 /* The following code does not need preprocessing in the assembler. */
1006 app_disable ();
1008 if (CONSTANT_POOL_BEFORE_FUNCTION)
1009 output_constant_pool (fnname, decl);
1011 #ifdef ASM_OUTPUT_SECTION_NAME
1012 /* If the function is to be put in its own section and it's not in a section
1013 already, indicate so. */
1014 if ((flag_function_sections
1015 && DECL_SECTION_NAME (decl) == NULL_TREE)
1016 || UNIQUE_SECTION_P (decl))
1017 UNIQUE_SECTION (decl, 0);
1018 #endif
1020 function_section (decl);
1022 /* Tell assembler to move to target machine's alignment for functions. */
1023 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1024 if (align > 0)
1025 ASM_OUTPUT_ALIGN (asm_out_file, align);
1027 /* Handle a user-specified function alignment.
1028 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1029 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1030 if (align_functions_log > align)
1032 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1033 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1034 align_functions_log, align_functions-1);
1035 #else
1036 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1037 #endif
1040 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1041 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1042 #endif
1044 #ifdef SDB_DEBUGGING_INFO
1045 /* Output SDB definition of the function. */
1046 if (write_symbols == SDB_DEBUG)
1047 sdbout_mark_begin_function ();
1048 #endif
1050 #ifdef DBX_DEBUGGING_INFO
1051 /* Output DBX definition of the function. */
1052 if (write_symbols == DBX_DEBUG)
1053 dbxout_begin_function (decl);
1054 #endif
1056 /* Make function name accessible from other files, if appropriate. */
1058 if (TREE_PUBLIC (decl))
1060 if (! first_global_object_name)
1062 const char *p;
1063 char **name;
1065 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1066 name = &first_global_object_name;
1067 else
1068 name = &weak_global_object_name;
1070 STRIP_NAME_ENCODING (p, fnname);
1071 *name = permalloc (strlen (p) + 1);
1072 strcpy (*name, p);
1075 #ifdef ASM_WEAKEN_LABEL
1076 if (DECL_WEAK (decl))
1078 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1079 /* Remove this function from the pending weak list so that
1080 we do not emit multiple .weak directives for it. */
1081 remove_from_pending_weak_list
1082 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1084 else
1085 #endif
1086 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1089 /* Do any machine/system dependent processing of the function name */
1090 #ifdef ASM_DECLARE_FUNCTION_NAME
1091 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1092 #else
1093 /* Standard thing is just output label for the function. */
1094 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1095 #endif /* ASM_DECLARE_FUNCTION_NAME */
1098 /* Output assembler code associated with defining the size of the
1099 function. DECL describes the function. NAME is the function's name. */
1101 void
1102 assemble_end_function (decl, fnname)
1103 tree decl;
1104 char *fnname;
1106 #ifdef ASM_DECLARE_FUNCTION_SIZE
1107 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1108 #endif
1109 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1111 output_constant_pool (fnname, decl);
1112 function_section (decl); /* need to switch back */
1115 /* Output any constants which should appear after the function. */
1116 output_after_function_constants ();
1119 /* Assemble code to leave SIZE bytes of zeros. */
1121 void
1122 assemble_zeros (size)
1123 int size;
1125 /* Do no output if -fsyntax-only. */
1126 if (flag_syntax_only)
1127 return;
1129 #ifdef ASM_NO_SKIP_IN_TEXT
1130 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1131 so we must output 0s explicitly in the text section. */
1132 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1134 int i;
1136 for (i = 0; i < size - 20; i += 20)
1138 #ifdef ASM_BYTE_OP
1139 fprintf (asm_out_file,
1140 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
1141 #else
1142 fprintf (asm_out_file,
1143 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1144 #endif
1146 if (i < size)
1148 #ifdef ASM_BYTE_OP
1149 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1150 #else
1151 fprintf (asm_out_file, "\tbyte 0");
1152 #endif
1153 i++;
1154 for (; i < size; i++)
1155 fprintf (asm_out_file, ",0");
1156 fprintf (asm_out_file, "\n");
1159 else
1160 #endif
1161 if (size > 0)
1162 ASM_OUTPUT_SKIP (asm_out_file, size);
1165 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1167 void
1168 assemble_align (align)
1169 int align;
1171 if (align > BITS_PER_UNIT)
1172 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1175 /* Assemble a string constant with the specified C string as contents. */
1177 void
1178 assemble_string (p, size)
1179 const char *p;
1180 int size;
1182 int pos = 0;
1183 int maximum = 2000;
1185 /* If the string is very long, split it up. */
1187 while (pos < size)
1189 int thissize = size - pos;
1190 if (thissize > maximum)
1191 thissize = maximum;
1193 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1195 pos += thissize;
1196 p += thissize;
1201 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1202 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1203 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1204 #else
1205 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1206 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1207 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1208 #else
1209 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1210 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1211 #endif
1212 #endif
1214 #if defined ASM_OUTPUT_ALIGNED_BSS
1215 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1216 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1217 #else
1218 #if defined ASM_OUTPUT_BSS
1219 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1220 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1221 #else
1222 #undef ASM_EMIT_BSS
1223 #endif
1224 #endif
1226 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1227 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1228 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1229 #else
1230 #if defined ASM_OUTPUT_ALIGNED_COMMON
1231 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1232 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1233 #else
1234 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1235 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1236 #endif
1237 #endif
1239 static void
1240 asm_emit_uninitialised (decl, name, size, rounded)
1241 tree decl;
1242 char * name;
1243 int size;
1244 int rounded ATTRIBUTE_UNUSED;
1246 enum {
1247 asm_dest_common,
1248 asm_dest_bss,
1249 asm_dest_local
1251 destination = asm_dest_local;
1253 if (TREE_PUBLIC (decl))
1255 #if defined ASM_EMIT_BSS
1256 if (! DECL_COMMON (decl))
1257 destination = asm_dest_bss;
1258 else
1259 #endif
1260 destination = asm_dest_common;
1263 if (flag_shared_data)
1265 switch (destination)
1267 #ifdef ASM_OUTPUT_SHARED_BSS
1268 case asm_dest_bss:
1269 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1270 return;
1271 #endif
1272 #ifdef ASM_OUTPUT_SHARED_COMMON
1273 case asm_dest_common:
1274 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1275 return;
1276 #endif
1277 #ifdef ASM_OUTPUT_SHARED_LOCAL
1278 case asm_dest_local:
1279 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1280 return;
1281 #endif
1282 default:
1283 break;
1287 switch (destination)
1289 #ifdef ASM_EMIT_BSS
1290 case asm_dest_bss:
1291 ASM_EMIT_BSS (decl, name, size, rounded);
1292 break;
1293 #endif
1294 case asm_dest_common:
1295 ASM_EMIT_COMMON (decl, name, size, rounded);
1296 break;
1297 case asm_dest_local:
1298 ASM_EMIT_LOCAL (decl, name, size, rounded);
1299 break;
1300 default:
1301 abort ();
1304 return;
1307 /* Assemble everything that is needed for a variable or function declaration.
1308 Not used for automatic variables, and not used for function definitions.
1309 Should not be called for variables of incomplete structure type.
1311 TOP_LEVEL is nonzero if this variable has file scope.
1312 AT_END is nonzero if this is the special handling, at end of compilation,
1313 to define things that have had only tentative definitions.
1314 DONT_OUTPUT_DATA if nonzero means don't actually output the
1315 initial value (that will be done by the caller). */
1317 void
1318 assemble_variable (decl, top_level, at_end, dont_output_data)
1319 tree decl;
1320 int top_level ATTRIBUTE_UNUSED;
1321 int at_end ATTRIBUTE_UNUSED;
1322 int dont_output_data;
1324 register char *name;
1325 unsigned int align;
1326 tree size_tree = NULL_TREE;
1327 int reloc = 0;
1328 enum in_section saved_in_section;
1330 last_assemble_variable_decl = 0;
1332 if (GET_CODE (DECL_RTL (decl)) == REG)
1334 /* Do output symbol info for global register variables, but do nothing
1335 else for them. */
1337 if (TREE_ASM_WRITTEN (decl))
1338 return;
1339 TREE_ASM_WRITTEN (decl) = 1;
1341 /* Do no output if -fsyntax-only. */
1342 if (flag_syntax_only)
1343 return;
1345 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1346 /* File-scope global variables are output here. */
1347 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1348 && top_level)
1349 dbxout_symbol (decl, 0);
1350 #endif
1351 #ifdef SDB_DEBUGGING_INFO
1352 if (write_symbols == SDB_DEBUG && top_level
1353 /* Leave initialized global vars for end of compilation;
1354 see comment in compile_file. */
1355 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1356 sdbout_symbol (decl, 0);
1357 #endif
1359 /* Don't output any DWARF debugging information for variables here.
1360 In the case of local variables, the information for them is output
1361 when we do our recursive traversal of the tree representation for
1362 the entire containing function. In the case of file-scope variables,
1363 we output information for all of them at the very end of compilation
1364 while we are doing our final traversal of the chain of file-scope
1365 declarations. */
1367 return;
1370 /* Normally no need to say anything here for external references,
1371 since assemble_external is called by the language-specific code
1372 when a declaration is first seen. */
1374 if (DECL_EXTERNAL (decl))
1375 return;
1377 /* Output no assembler code for a function declaration.
1378 Only definitions of functions output anything. */
1380 if (TREE_CODE (decl) == FUNCTION_DECL)
1381 return;
1383 /* If type was incomplete when the variable was declared,
1384 see if it is complete now. */
1386 if (DECL_SIZE (decl) == 0)
1387 layout_decl (decl, 0);
1389 /* Still incomplete => don't allocate it; treat the tentative defn
1390 (which is what it must have been) as an `extern' reference. */
1392 if (!dont_output_data && DECL_SIZE (decl) == 0)
1394 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1395 DECL_SOURCE_LINE (decl),
1396 "storage size of `%s' isn't known",
1397 IDENTIFIER_POINTER (DECL_NAME (decl)));
1398 TREE_ASM_WRITTEN (decl) = 1;
1399 return;
1402 /* The first declaration of a variable that comes through this function
1403 decides whether it is global (in C, has external linkage)
1404 or local (in C, has internal linkage). So do nothing more
1405 if this function has already run. */
1407 if (TREE_ASM_WRITTEN (decl))
1408 return;
1410 TREE_ASM_WRITTEN (decl) = 1;
1412 /* Do no output if -fsyntax-only. */
1413 if (flag_syntax_only)
1414 return;
1416 app_disable ();
1418 if (! dont_output_data)
1420 int size;
1422 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1423 goto finish;
1425 /* This is better than explicit arithmetic, since it avoids overflow. */
1426 size_tree = size_binop (CEIL_DIV_EXPR,
1427 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1429 size = TREE_INT_CST_LOW (size_tree);
1430 if (TREE_INT_CST_HIGH (size_tree) != 0
1431 || size != TREE_INT_CST_LOW (size_tree))
1433 error_with_decl (decl, "size of variable `%s' is too large");
1434 goto finish;
1438 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1440 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1441 && ! first_global_object_name
1442 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1443 || DECL_INITIAL (decl) == error_mark_node))
1444 && ! DECL_WEAK (decl)
1445 && ! DECL_ONE_ONLY (decl))
1447 const char *p;
1449 STRIP_NAME_ENCODING (p, name);
1450 first_global_object_name = permalloc (strlen (p) + 1);
1451 strcpy (first_global_object_name, p);
1454 /* Compute the alignment of this data. */
1456 align = DECL_ALIGN (decl);
1458 /* In the case for initialing an array whose length isn't specified,
1459 where we have not yet been able to do the layout,
1460 figure out the proper alignment now. */
1461 if (dont_output_data && DECL_SIZE (decl) == 0
1462 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1463 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1465 /* Some object file formats have a maximum alignment which they support.
1466 In particular, a.out format supports a maximum alignment of 4. */
1467 #ifndef MAX_OFILE_ALIGNMENT
1468 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1469 #endif
1470 if (align > MAX_OFILE_ALIGNMENT)
1472 warning_with_decl (decl,
1473 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1474 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1475 align = MAX_OFILE_ALIGNMENT;
1478 /* On some machines, it is good to increase alignment sometimes. */
1479 #ifdef DATA_ALIGNMENT
1480 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1481 #endif
1482 #ifdef CONSTANT_ALIGNMENT
1483 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1484 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1485 #endif
1487 /* Reset the alignment in case we have made it tighter, so we can benefit
1488 from it in get_pointer_alignment. */
1489 DECL_ALIGN (decl) = align;
1491 /* Handle uninitialized definitions. */
1493 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1494 /* If the target can't output uninitialized but not common global data
1495 in .bss, then we have to use .data. */
1496 #if ! defined ASM_EMIT_BSS
1497 && DECL_COMMON (decl)
1498 #endif
1499 && DECL_SECTION_NAME (decl) == 0
1500 && ! dont_output_data)
1502 int size = TREE_INT_CST_LOW (size_tree);
1503 int rounded = size;
1505 /* Don't allocate zero bytes of common,
1506 since that means "undefined external" in the linker. */
1507 if (size == 0) rounded = 1;
1508 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1509 so that each uninitialized object starts on such a boundary. */
1510 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1511 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1512 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1514 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1515 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1516 warning_with_decl
1517 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1518 #endif
1520 #ifdef DBX_DEBUGGING_INFO
1521 /* File-scope global variables are output here. */
1522 if (write_symbols == DBX_DEBUG && top_level)
1523 dbxout_symbol (decl, 0);
1524 #endif
1525 #ifdef SDB_DEBUGGING_INFO
1526 if (write_symbols == SDB_DEBUG && top_level
1527 /* Leave initialized global vars for end of compilation;
1528 see comment in compile_file. */
1529 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1530 sdbout_symbol (decl, 0);
1531 #endif
1533 /* Don't output any DWARF debugging information for variables here.
1534 In the case of local variables, the information for them is output
1535 when we do our recursive traversal of the tree representation for
1536 the entire containing function. In the case of file-scope variables,
1537 we output information for all of them at the very end of compilation
1538 while we are doing our final traversal of the chain of file-scope
1539 declarations. */
1541 #if 0 /* ??? We should either delete this or add a comment describing what
1542 it was intended to do and why we shouldn't delete it. */
1543 if (flag_shared_data)
1544 data_section ();
1545 #endif
1546 asm_emit_uninitialised (decl, name, size, rounded);
1548 goto finish;
1551 /* Handle initialized definitions.
1552 Also handle uninitialized global definitions if -fno-common and the
1553 target doesn't support ASM_OUTPUT_BSS. */
1555 /* First make the assembler name(s) global if appropriate. */
1556 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1558 #ifdef ASM_WEAKEN_LABEL
1559 if (DECL_WEAK (decl))
1561 ASM_WEAKEN_LABEL (asm_out_file, name);
1562 /* Remove this variable from the pending weak list so that
1563 we do not emit multiple .weak directives for it. */
1564 remove_from_pending_weak_list
1565 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1567 else
1568 #endif
1569 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1571 #if 0
1572 for (d = equivalents; d; d = TREE_CHAIN (d))
1574 tree e = TREE_VALUE (d);
1575 if (TREE_PUBLIC (e) && DECL_NAME (e))
1576 ASM_GLOBALIZE_LABEL (asm_out_file,
1577 XSTR (XEXP (DECL_RTL (e), 0), 0));
1579 #endif
1581 /* Output any data that we will need to use the address of. */
1582 if (DECL_INITIAL (decl) == error_mark_node)
1583 reloc = contains_pointers_p (TREE_TYPE (decl));
1584 else if (DECL_INITIAL (decl))
1585 reloc = output_addressed_constants (DECL_INITIAL (decl));
1587 #ifdef ASM_OUTPUT_SECTION_NAME
1588 if ((flag_data_sections != 0
1589 && DECL_SECTION_NAME (decl) == NULL_TREE)
1590 || UNIQUE_SECTION_P (decl))
1591 UNIQUE_SECTION (decl, reloc);
1592 #endif
1594 /* Switch to the appropriate section. */
1595 variable_section (decl, reloc);
1597 /* dbxout.c needs to know this. */
1598 if (in_text_section ())
1599 DECL_IN_TEXT_SECTION (decl) = 1;
1601 /* Record current section so we can restore it if dbxout.c clobbers it. */
1602 saved_in_section = in_section;
1604 /* Output the dbx info now that we have chosen the section. */
1606 #ifdef DBX_DEBUGGING_INFO
1607 /* File-scope global variables are output here. */
1608 if (write_symbols == DBX_DEBUG && top_level)
1609 dbxout_symbol (decl, 0);
1610 #endif
1611 #ifdef SDB_DEBUGGING_INFO
1612 if (write_symbols == SDB_DEBUG && top_level
1613 /* Leave initialized global vars for end of compilation;
1614 see comment in compile_file. */
1615 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1616 sdbout_symbol (decl, 0);
1617 #endif
1619 /* Don't output any DWARF debugging information for variables here.
1620 In the case of local variables, the information for them is output
1621 when we do our recursive traversal of the tree representation for
1622 the entire containing function. In the case of file-scope variables,
1623 we output information for all of them at the very end of compilation
1624 while we are doing our final traversal of the chain of file-scope
1625 declarations. */
1627 /* If the debugging output changed sections, reselect the section
1628 that's supposed to be selected. */
1629 if (in_section != saved_in_section)
1630 variable_section (decl, reloc);
1632 /* Output the alignment of this data. */
1633 if (align > BITS_PER_UNIT)
1634 ASM_OUTPUT_ALIGN (asm_out_file,
1635 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1637 /* Do any machine/system dependent processing of the object. */
1638 #ifdef ASM_DECLARE_OBJECT_NAME
1639 last_assemble_variable_decl = decl;
1640 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1641 #else
1642 /* Standard thing is just output label for the object. */
1643 ASM_OUTPUT_LABEL (asm_out_file, name);
1644 #endif /* ASM_DECLARE_OBJECT_NAME */
1646 if (!dont_output_data)
1648 if (DECL_INITIAL (decl))
1649 /* Output the actual data. */
1650 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1651 else
1652 /* Leave space for it. */
1653 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1656 finish:
1657 #ifdef XCOFF_DEBUGGING_INFO
1658 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1659 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1660 and `aa' hasn't been output yet, the assembler generates a stab entry with
1661 a value of zero, in addition to creating an unnecessary external entry
1662 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1664 /* File-scope global variables are output here. */
1665 if (write_symbols == XCOFF_DEBUG && top_level)
1667 saved_in_section = in_section;
1669 dbxout_symbol (decl, 0);
1671 if (in_section != saved_in_section)
1672 variable_section (decl, reloc);
1674 #else
1675 /* There must be a statement after a label. */
1677 #endif
1680 /* Return 1 if type TYPE contains any pointers. */
1682 static int
1683 contains_pointers_p (type)
1684 tree type;
1686 switch (TREE_CODE (type))
1688 case POINTER_TYPE:
1689 case REFERENCE_TYPE:
1690 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1691 so I'll play safe and return 1. */
1692 case OFFSET_TYPE:
1693 return 1;
1695 case RECORD_TYPE:
1696 case UNION_TYPE:
1697 case QUAL_UNION_TYPE:
1699 tree fields;
1700 /* For a type that has fields, see if the fields have pointers. */
1701 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1702 if (TREE_CODE (fields) == FIELD_DECL
1703 && contains_pointers_p (TREE_TYPE (fields)))
1704 return 1;
1705 return 0;
1708 case ARRAY_TYPE:
1709 /* An array type contains pointers if its element type does. */
1710 return contains_pointers_p (TREE_TYPE (type));
1712 default:
1713 return 0;
1717 /* Output something to declare an external symbol to the assembler.
1718 (Most assemblers don't need this, so we normally output nothing.)
1719 Do nothing if DECL is not external. */
1721 void
1722 assemble_external (decl)
1723 tree decl ATTRIBUTE_UNUSED;
1725 #ifdef ASM_OUTPUT_EXTERNAL
1726 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1727 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1729 rtx rtl = DECL_RTL (decl);
1731 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1732 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1734 /* Some systems do require some output. */
1735 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1736 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1739 #endif
1742 /* Similar, for calling a library function FUN. */
1744 void
1745 assemble_external_libcall (fun)
1746 rtx fun ATTRIBUTE_UNUSED;
1748 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1749 /* Declare library function name external when first used, if nec. */
1750 if (! SYMBOL_REF_USED (fun))
1752 SYMBOL_REF_USED (fun) = 1;
1753 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1755 #endif
1758 /* Declare the label NAME global. */
1760 void
1761 assemble_global (name)
1762 char *name;
1764 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1767 /* Assemble a label named NAME. */
1769 void
1770 assemble_label (name)
1771 char *name;
1773 ASM_OUTPUT_LABEL (asm_out_file, name);
1776 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1777 If NAME starts with a *, the rest of NAME is output verbatim.
1778 Otherwise NAME is transformed in an implementation-defined way
1779 (usually by the addition of an underscore).
1780 Many macros in the tm file are defined to call this function. */
1782 void
1783 assemble_name (file, name)
1784 FILE *file;
1785 const char *name;
1787 const char *real_name;
1788 tree id;
1790 STRIP_NAME_ENCODING (real_name, name);
1791 if (flag_prefix_function_name
1792 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1793 real_name = real_name + CHKR_PREFIX_SIZE;
1795 id = maybe_get_identifier (real_name);
1796 if (id)
1797 TREE_SYMBOL_REFERENCED (id) = 1;
1799 if (name[0] == '*')
1800 fputs (&name[1], file);
1801 else
1802 ASM_OUTPUT_LABELREF (file, name);
1805 /* Allocate SIZE bytes writable static space with a gensym name
1806 and return an RTX to refer to its address. */
1809 assemble_static_space (size)
1810 int size;
1812 char name[12];
1813 char *namestring;
1814 rtx x;
1816 #if 0
1817 if (flag_shared_data)
1818 data_section ();
1819 #endif
1821 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1822 ++const_labelno;
1823 namestring = ggc_alloc_string (name, -1);
1825 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1827 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1828 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1829 BIGGEST_ALIGNMENT);
1830 #else
1831 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1832 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1833 #else
1835 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1836 so that each uninitialized object starts on such a boundary. */
1837 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1838 int rounded ATTRIBUTE_UNUSED
1839 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1840 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1841 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1842 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1844 #endif
1845 #endif
1846 return x;
1849 /* Assemble the static constant template for function entry trampolines.
1850 This is done at most once per compilation.
1851 Returns an RTX for the address of the template. */
1853 #ifdef TRAMPOLINE_TEMPLATE
1855 assemble_trampoline_template ()
1857 char label[256];
1858 char *name;
1859 int align;
1861 /* By default, put trampoline templates in read-only data section. */
1863 #ifdef TRAMPOLINE_SECTION
1864 TRAMPOLINE_SECTION ();
1865 #else
1866 readonly_data_section ();
1867 #endif
1869 /* Write the assembler code to define one. */
1870 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1871 if (align > 0)
1872 ASM_OUTPUT_ALIGN (asm_out_file, align);
1874 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1875 TRAMPOLINE_TEMPLATE (asm_out_file);
1877 /* Record the rtl to refer to it. */
1878 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1879 name = ggc_alloc_string (label, -1);
1880 return gen_rtx_SYMBOL_REF (Pmode, name);
1882 #endif
1884 /* Assemble the integer constant X into an object of SIZE bytes.
1885 X must be either a CONST_INT or CONST_DOUBLE.
1887 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1888 non-zero, abort if we can't output the constant. */
1891 assemble_integer (x, size, force)
1892 rtx x;
1893 int size;
1894 int force;
1896 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1897 ASM_OUTPUT... macros. */
1899 switch (size)
1901 #ifdef ASM_OUTPUT_CHAR
1902 case 1:
1903 ASM_OUTPUT_CHAR (asm_out_file, x);
1904 return 1;
1905 #endif
1907 #ifdef ASM_OUTPUT_SHORT
1908 case 2:
1909 ASM_OUTPUT_SHORT (asm_out_file, x);
1910 return 1;
1911 #endif
1913 #ifdef ASM_OUTPUT_INT
1914 case 4:
1915 ASM_OUTPUT_INT (asm_out_file, x);
1916 return 1;
1917 #endif
1919 #ifdef ASM_OUTPUT_DOUBLE_INT
1920 case 8:
1921 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1922 return 1;
1923 #endif
1925 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1926 case 16:
1927 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1928 return 1;
1929 #endif
1932 /* If we couldn't do it that way, there are two other possibilities: First,
1933 if the machine can output an explicit byte and this is a 1 byte constant,
1934 we can use ASM_OUTPUT_BYTE. */
1936 #ifdef ASM_OUTPUT_BYTE
1937 if (size == 1 && GET_CODE (x) == CONST_INT)
1939 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1940 return 1;
1942 #endif
1944 /* Finally, if SIZE is larger than a single word, try to output the constant
1945 one word at a time. */
1947 if (size > UNITS_PER_WORD)
1949 int i;
1950 enum machine_mode mode
1951 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1952 rtx word;
1954 for (i = 0; i < size / UNITS_PER_WORD; i++)
1956 word = operand_subword (x, i, 0, mode);
1958 if (word == 0)
1959 break;
1961 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1962 break;
1965 if (i == size / UNITS_PER_WORD)
1966 return 1;
1967 /* If we output at least one word and then could not finish,
1968 there is no valid way to continue. */
1969 if (i > 0)
1970 abort ();
1973 if (force)
1974 abort ();
1976 return 0;
1979 /* Assemble the floating-point constant D into an object of size MODE. */
1981 void
1982 assemble_real (d, mode)
1983 REAL_VALUE_TYPE d;
1984 enum machine_mode mode;
1986 jmp_buf output_constant_handler;
1988 if (setjmp (output_constant_handler))
1990 error ("floating point trap outputting a constant");
1991 #ifdef REAL_IS_NOT_DOUBLE
1992 bzero ((char *) &d, sizeof d);
1993 d = dconst0;
1994 #else
1995 d = 0;
1996 #endif
1999 set_float_handler (output_constant_handler);
2001 switch (mode)
2003 #ifdef ASM_OUTPUT_BYTE_FLOAT
2004 case QFmode:
2005 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
2006 break;
2007 #endif
2008 #ifdef ASM_OUTPUT_SHORT_FLOAT
2009 case HFmode:
2010 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
2011 break;
2012 #endif
2013 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2014 case TQFmode:
2015 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
2016 break;
2017 #endif
2018 #ifdef ASM_OUTPUT_FLOAT
2019 case SFmode:
2020 ASM_OUTPUT_FLOAT (asm_out_file, d);
2021 break;
2022 #endif
2024 #ifdef ASM_OUTPUT_DOUBLE
2025 case DFmode:
2026 ASM_OUTPUT_DOUBLE (asm_out_file, d);
2027 break;
2028 #endif
2030 #ifdef ASM_OUTPUT_LONG_DOUBLE
2031 case XFmode:
2032 case TFmode:
2033 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
2034 break;
2035 #endif
2037 default:
2038 abort ();
2041 set_float_handler (NULL_PTR);
2044 /* Here we combine duplicate floating constants to make
2045 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2047 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2048 For an integer, I0 is the low-order word and I1 is the high-order word.
2049 For a real number, I0 is the word with the low address
2050 and I1 is the word with the high address. */
2053 immed_double_const (i0, i1, mode)
2054 HOST_WIDE_INT i0, i1;
2055 enum machine_mode mode;
2057 register rtx r;
2059 if (GET_MODE_CLASS (mode) == MODE_INT
2060 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2062 /* We clear out all bits that don't belong in MODE, unless they and our
2063 sign bit are all one. So we get either a reasonable negative value
2064 or a reasonable unsigned value for this mode. */
2065 int width = GET_MODE_BITSIZE (mode);
2066 if (width < HOST_BITS_PER_WIDE_INT
2067 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2068 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2069 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2070 else if (width == HOST_BITS_PER_WIDE_INT
2071 && ! (i1 == ~0 && i0 < 0))
2072 i1 = 0;
2073 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2074 /* We cannot represent this value as a constant. */
2075 abort ();
2077 /* If this would be an entire word for the target, but is not for
2078 the host, then sign-extend on the host so that the number will look
2079 the same way on the host that it would on the target.
2081 For example, when building a 64 bit alpha hosted 32 bit sparc
2082 targeted compiler, then we want the 32 bit unsigned value -1 to be
2083 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2084 The later confuses the sparc backend. */
2086 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2087 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2088 i0 |= ((HOST_WIDE_INT) (-1) << width);
2090 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2092 ??? Strictly speaking, this is wrong if we create a CONST_INT
2093 for a large unsigned constant with the size of MODE being
2094 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2095 wider mode. In that case we will mis-interpret it as a negative
2096 number.
2098 Unfortunately, the only alternative is to make a CONST_DOUBLE
2099 for any constant in any mode if it is an unsigned constant larger
2100 than the maximum signed integer in an int on the host. However,
2101 doing this will break everyone that always expects to see a CONST_INT
2102 for SImode and smaller.
2104 We have always been making CONST_INTs in this case, so nothing new
2105 is being broken. */
2107 if (width <= HOST_BITS_PER_WIDE_INT)
2108 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2110 /* If this integer fits in one word, return a CONST_INT. */
2111 if ((i1 == 0 && i0 >= 0)
2112 || (i1 == ~0 && i0 < 0))
2113 return GEN_INT (i0);
2115 /* We use VOIDmode for integers. */
2116 mode = VOIDmode;
2119 /* Search the chain for an existing CONST_DOUBLE with the right value.
2120 If one is found, return it. */
2121 if (current_function != 0)
2122 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2123 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2124 && GET_MODE (r) == mode)
2125 return r;
2127 /* No; make a new one and add it to the chain.
2129 We may be called by an optimizer which may be discarding any memory
2130 allocated during its processing (such as combine and loop). However,
2131 we will be leaving this constant on the chain, so we cannot tolerate
2132 freed memory. So switch to saveable_obstack for this allocation
2133 and then switch back if we were in current_obstack. */
2135 push_obstacks_nochange ();
2136 rtl_in_saveable_obstack ();
2137 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2138 pop_obstacks ();
2140 /* Don't touch const_double_chain if not inside any function. */
2141 if (current_function_decl != 0)
2143 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2144 const_double_chain = r;
2147 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2148 Actual use of mem-slot is only through force_const_mem. */
2150 CONST_DOUBLE_MEM (r) = const0_rtx;
2152 return r;
2155 /* Return a CONST_DOUBLE for a specified `double' value
2156 and machine mode. */
2159 immed_real_const_1 (d, mode)
2160 REAL_VALUE_TYPE d;
2161 enum machine_mode mode;
2163 union real_extract u;
2164 register rtx r;
2166 /* Get the desired `double' value as a sequence of ints
2167 since that is how they are stored in a CONST_DOUBLE. */
2169 u.d = d;
2171 /* Detect special cases. */
2173 if (REAL_VALUES_IDENTICAL (dconst0, d))
2174 return CONST0_RTX (mode);
2175 /* Check for NaN first, because some ports (specifically the i386) do not
2176 emit correct ieee-fp code by default, and thus will generate a core
2177 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2178 does a floating point comparison. */
2179 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2180 return CONST1_RTX (mode);
2182 if (sizeof u == sizeof (HOST_WIDE_INT))
2183 return immed_double_const (u.i[0], 0, mode);
2184 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2185 return immed_double_const (u.i[0], u.i[1], mode);
2187 /* The rest of this function handles the case where
2188 a float value requires more than 2 ints of space.
2189 It will be deleted as dead code on machines that don't need it. */
2191 /* Search the chain for an existing CONST_DOUBLE with the right value.
2192 If one is found, return it. */
2193 if (current_function != 0)
2194 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2195 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2196 && GET_MODE (r) == mode)
2197 return r;
2199 /* No; make a new one and add it to the chain.
2201 We may be called by an optimizer which may be discarding any memory
2202 allocated during its processing (such as combine and loop). However,
2203 we will be leaving this constant on the chain, so we cannot tolerate
2204 freed memory. So switch to saveable_obstack for this allocation
2205 and then switch back if we were in current_obstack. */
2206 push_obstacks_nochange ();
2207 rtl_in_saveable_obstack ();
2208 r = rtx_alloc (CONST_DOUBLE);
2209 pop_obstacks ();
2210 PUT_MODE (r, mode);
2211 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2213 /* Don't touch const_double_chain if not inside any function. */
2214 if (current_function_decl != 0)
2216 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2217 const_double_chain = r;
2220 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2221 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2222 is only through force_const_mem. */
2224 CONST_DOUBLE_MEM (r) = const0_rtx;
2226 return r;
2229 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2230 which must be a REAL_CST tree node. */
2233 immed_real_const (exp)
2234 tree exp;
2236 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2239 /* At the end of a function, forget the memory-constants
2240 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2241 Also clear out real_constant_chain and clear out all the chain-pointers. */
2243 void
2244 clear_const_double_mem ()
2246 register rtx r, next;
2248 for (r = const_double_chain; r; r = next)
2250 next = CONST_DOUBLE_CHAIN (r);
2251 CONST_DOUBLE_CHAIN (r) = 0;
2252 CONST_DOUBLE_MEM (r) = cc0_rtx;
2254 const_double_chain = 0;
2257 /* Given an expression EXP with a constant value,
2258 reduce it to the sum of an assembler symbol and an integer.
2259 Store them both in the structure *VALUE.
2260 Abort if EXP does not reduce. */
2262 struct addr_const
2264 rtx base;
2265 HOST_WIDE_INT offset;
2268 static void
2269 decode_addr_const (exp, value)
2270 tree exp;
2271 struct addr_const *value;
2273 register tree target = TREE_OPERAND (exp, 0);
2274 register int offset = 0;
2275 register rtx x;
2277 while (1)
2279 if (TREE_CODE (target) == COMPONENT_REF
2280 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2281 == INTEGER_CST))
2283 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2284 target = TREE_OPERAND (target, 0);
2286 else if (TREE_CODE (target) == ARRAY_REF)
2288 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2289 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2290 abort ();
2291 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2292 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2293 / BITS_PER_UNIT);
2294 target = TREE_OPERAND (target, 0);
2296 else
2297 break;
2300 switch (TREE_CODE (target))
2302 case VAR_DECL:
2303 case FUNCTION_DECL:
2304 x = DECL_RTL (target);
2305 break;
2307 case LABEL_DECL:
2308 x = gen_rtx_MEM (FUNCTION_MODE,
2309 gen_rtx_LABEL_REF (VOIDmode,
2310 label_rtx (TREE_OPERAND (exp, 0))));
2311 break;
2313 case REAL_CST:
2314 case STRING_CST:
2315 case COMPLEX_CST:
2316 case CONSTRUCTOR:
2317 case INTEGER_CST:
2318 x = TREE_CST_RTL (target);
2319 break;
2321 default:
2322 abort ();
2325 if (GET_CODE (x) != MEM)
2326 abort ();
2327 x = XEXP (x, 0);
2329 value->base = x;
2330 value->offset = offset;
2333 /* Uniquize all constants that appear in memory.
2334 Each constant in memory thus far output is recorded
2335 in `const_hash_table' with a `struct constant_descriptor'
2336 that contains a polish representation of the value of
2337 the constant.
2339 We cannot store the trees in the hash table
2340 because the trees may be temporary. */
2342 struct constant_descriptor
2344 struct constant_descriptor *next;
2345 char *label;
2346 char contents[1];
2349 #define HASHBITS 30
2350 #define MAX_HASH_TABLE 1009
2351 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2353 /* Mark a const_hash_table descriptor for GC. */
2355 static void
2356 mark_const_hash_entry (ptr)
2357 void *ptr;
2359 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2361 while (desc)
2363 ggc_mark_string (desc->label);
2364 desc = desc->next;
2368 /* Compute a hash code for a constant expression. */
2370 static int
2371 const_hash (exp)
2372 tree exp;
2374 register char *p;
2375 register int len, hi, i;
2376 register enum tree_code code = TREE_CODE (exp);
2378 /* Either set P and LEN to the address and len of something to hash and
2379 exit the switch or return a value. */
2381 switch (code)
2383 case INTEGER_CST:
2384 p = (char *) &TREE_INT_CST_LOW (exp);
2385 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2386 break;
2388 case REAL_CST:
2389 p = (char *) &TREE_REAL_CST (exp);
2390 len = sizeof TREE_REAL_CST (exp);
2391 break;
2393 case STRING_CST:
2394 p = TREE_STRING_POINTER (exp);
2395 len = TREE_STRING_LENGTH (exp);
2396 break;
2398 case COMPLEX_CST:
2399 return (const_hash (TREE_REALPART (exp)) * 5
2400 + const_hash (TREE_IMAGPART (exp)));
2402 case CONSTRUCTOR:
2403 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2405 len = int_size_in_bytes (TREE_TYPE (exp));
2406 p = (char *) alloca (len);
2407 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2408 break;
2410 else
2412 register tree link;
2414 /* For record type, include the type in the hashing.
2415 We do not do so for array types
2416 because (1) the sizes of the elements are sufficient
2417 and (2) distinct array types can have the same constructor.
2418 Instead, we include the array size because the constructor could
2419 be shorter. */
2420 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2421 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2422 % MAX_HASH_TABLE;
2423 else
2424 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2425 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2427 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2428 if (TREE_VALUE (link))
2430 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2432 return hi;
2435 case ADDR_EXPR:
2437 struct addr_const value;
2439 decode_addr_const (exp, &value);
2440 if (GET_CODE (value.base) == SYMBOL_REF)
2442 /* Don't hash the address of the SYMBOL_REF;
2443 only use the offset and the symbol name. */
2444 hi = value.offset;
2445 p = XSTR (value.base, 0);
2446 for (i = 0; p[i] != 0; i++)
2447 hi = ((hi * 613) + (unsigned) (p[i]));
2449 else if (GET_CODE (value.base) == LABEL_REF)
2450 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2451 else
2452 abort();
2454 hi &= (1 << HASHBITS) - 1;
2455 hi %= MAX_HASH_TABLE;
2457 return hi;
2459 case PLUS_EXPR:
2460 case MINUS_EXPR:
2461 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2462 + const_hash (TREE_OPERAND (exp, 1)));
2464 case NOP_EXPR:
2465 case CONVERT_EXPR:
2466 case NON_LVALUE_EXPR:
2467 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2469 default:
2470 abort ();
2473 /* Compute hashing function */
2474 hi = len;
2475 for (i = 0; i < len; i++)
2476 hi = ((hi * 613) + (unsigned) (p[i]));
2478 hi &= (1 << HASHBITS) - 1;
2479 hi %= MAX_HASH_TABLE;
2480 return hi;
2483 /* Compare a constant expression EXP with a constant-descriptor DESC.
2484 Return 1 if DESC describes a constant with the same value as EXP. */
2486 static int
2487 compare_constant (exp, desc)
2488 tree exp;
2489 struct constant_descriptor *desc;
2491 return 0 != compare_constant_1 (exp, desc->contents);
2494 /* Compare constant expression EXP with a substring P of a constant descriptor.
2495 If they match, return a pointer to the end of the substring matched.
2496 If they do not match, return 0.
2498 Since descriptors are written in polish prefix notation,
2499 this function can be used recursively to test one operand of EXP
2500 against a subdescriptor, and if it succeeds it returns the
2501 address of the subdescriptor for the next operand. */
2503 static char *
2504 compare_constant_1 (exp, p)
2505 tree exp;
2506 char *p;
2508 register char *strp;
2509 register int len;
2510 register enum tree_code code = TREE_CODE (exp);
2512 if (code != (enum tree_code) *p++)
2513 return 0;
2515 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2516 switch, or return the result of the comparison. */
2518 switch (code)
2520 case INTEGER_CST:
2521 /* Integer constants are the same only if the same width of type. */
2522 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2523 return 0;
2525 strp = (char *) &TREE_INT_CST_LOW (exp);
2526 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2527 break;
2529 case REAL_CST:
2530 /* Real constants are the same only if the same width of type. */
2531 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2532 return 0;
2534 strp = (char *) &TREE_REAL_CST (exp);
2535 len = sizeof TREE_REAL_CST (exp);
2536 break;
2538 case STRING_CST:
2539 if (flag_writable_strings)
2540 return 0;
2542 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2543 return 0;
2545 strp = TREE_STRING_POINTER (exp);
2546 len = TREE_STRING_LENGTH (exp);
2547 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2548 sizeof TREE_STRING_LENGTH (exp)))
2549 return 0;
2551 p += sizeof TREE_STRING_LENGTH (exp);
2552 break;
2554 case COMPLEX_CST:
2555 p = compare_constant_1 (TREE_REALPART (exp), p);
2556 if (p == 0)
2557 return 0;
2559 return compare_constant_1 (TREE_IMAGPART (exp), p);
2561 case CONSTRUCTOR:
2562 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2564 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2566 strp = (char *) alloca (len);
2567 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2568 if (bcmp ((char *) &xlen, p, sizeof xlen))
2569 return 0;
2571 p += sizeof xlen;
2572 break;
2574 else
2576 register tree link;
2577 int length = list_length (CONSTRUCTOR_ELTS (exp));
2578 tree type;
2579 int have_purpose = 0;
2581 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2582 if (TREE_PURPOSE (link))
2583 have_purpose = 1;
2585 if (bcmp ((char *) &length, p, sizeof length))
2586 return 0;
2588 p += sizeof length;
2590 /* For record constructors, insist that the types match.
2591 For arrays, just verify both constructors are for arrays.
2592 Then insist that either both or none have any TREE_PURPOSE
2593 values. */
2594 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2595 type = TREE_TYPE (exp);
2596 else
2597 type = 0;
2599 if (bcmp ((char *) &type, p, sizeof type))
2600 return 0;
2602 p += sizeof type;
2604 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2605 return 0;
2607 p += sizeof have_purpose;
2609 /* For arrays, insist that the size in bytes match. */
2610 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2612 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2614 if (bcmp ((char *) &size, p, sizeof size))
2615 return 0;
2617 p += sizeof size;
2620 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2622 if (TREE_VALUE (link))
2624 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2625 return 0;
2627 else
2629 tree zero = 0;
2631 if (bcmp ((char *) &zero, p, sizeof zero))
2632 return 0;
2634 p += sizeof zero;
2637 if (TREE_PURPOSE (link)
2638 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2640 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2641 sizeof TREE_PURPOSE (link)))
2642 return 0;
2644 p += sizeof TREE_PURPOSE (link);
2646 else if (TREE_PURPOSE (link))
2648 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2649 return 0;
2651 else if (have_purpose)
2653 int zero = 0;
2655 if (bcmp ((char *) &zero, p, sizeof zero))
2656 return 0;
2658 p += sizeof zero;
2662 return p;
2665 case ADDR_EXPR:
2667 struct addr_const value;
2669 decode_addr_const (exp, &value);
2670 strp = (char *) &value.offset;
2671 len = sizeof value.offset;
2672 /* Compare the offset. */
2673 while (--len >= 0)
2674 if (*p++ != *strp++)
2675 return 0;
2677 /* Compare symbol name. */
2678 strp = XSTR (value.base, 0);
2679 len = strlen (strp) + 1;
2681 break;
2683 case PLUS_EXPR:
2684 case MINUS_EXPR:
2685 case RANGE_EXPR:
2686 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2687 if (p == 0)
2688 return 0;
2690 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2692 case NOP_EXPR:
2693 case CONVERT_EXPR:
2694 case NON_LVALUE_EXPR:
2695 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2697 default:
2698 abort ();
2701 /* Compare constant contents. */
2702 while (--len >= 0)
2703 if (*p++ != *strp++)
2704 return 0;
2706 return p;
2709 /* Construct a constant descriptor for the expression EXP.
2710 It is up to the caller to enter the descriptor in the hash table. */
2712 static struct constant_descriptor *
2713 record_constant (exp)
2714 tree exp;
2716 struct constant_descriptor *next = 0;
2717 char *label = 0;
2719 /* Make a struct constant_descriptor. The first two pointers will
2720 be filled in later. Here we just leave space for them. */
2722 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2723 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2724 record_constant_1 (exp);
2725 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2728 /* Add a description of constant expression EXP
2729 to the object growing in `permanent_obstack'.
2730 No need to return its address; the caller will get that
2731 from the obstack when the object is complete. */
2733 static void
2734 record_constant_1 (exp)
2735 tree exp;
2737 register char *strp;
2738 register int len;
2739 register enum tree_code code = TREE_CODE (exp);
2741 obstack_1grow (&permanent_obstack, (unsigned int) code);
2743 switch (code)
2745 case INTEGER_CST:
2746 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2747 strp = (char *) &TREE_INT_CST_LOW (exp);
2748 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2749 break;
2751 case REAL_CST:
2752 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2753 strp = (char *) &TREE_REAL_CST (exp);
2754 len = sizeof TREE_REAL_CST (exp);
2755 break;
2757 case STRING_CST:
2758 if (flag_writable_strings)
2759 return;
2761 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2762 strp = TREE_STRING_POINTER (exp);
2763 len = TREE_STRING_LENGTH (exp);
2764 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2765 sizeof TREE_STRING_LENGTH (exp));
2766 break;
2768 case COMPLEX_CST:
2769 record_constant_1 (TREE_REALPART (exp));
2770 record_constant_1 (TREE_IMAGPART (exp));
2771 return;
2773 case CONSTRUCTOR:
2774 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2776 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2777 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2778 obstack_blank (&permanent_obstack, nbytes);
2779 get_set_constructor_bytes
2780 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2781 nbytes);
2782 return;
2784 else
2786 register tree link;
2787 int length = list_length (CONSTRUCTOR_ELTS (exp));
2788 tree type;
2789 int have_purpose = 0;
2791 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2792 if (TREE_PURPOSE (link))
2793 have_purpose = 1;
2795 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2797 /* For record constructors, insist that the types match.
2798 For arrays, just verify both constructors are for arrays.
2799 Then insist that either both or none have any TREE_PURPOSE
2800 values. */
2801 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2802 type = TREE_TYPE (exp);
2803 else
2804 type = 0;
2805 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2806 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2807 sizeof have_purpose);
2809 /* For arrays, insist that the size in bytes match. */
2810 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2812 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2813 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2816 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2818 if (TREE_VALUE (link))
2819 record_constant_1 (TREE_VALUE (link));
2820 else
2822 tree zero = 0;
2824 obstack_grow (&permanent_obstack,
2825 (char *) &zero, sizeof zero);
2828 if (TREE_PURPOSE (link)
2829 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2830 obstack_grow (&permanent_obstack,
2831 (char *) &TREE_PURPOSE (link),
2832 sizeof TREE_PURPOSE (link));
2833 else if (TREE_PURPOSE (link))
2834 record_constant_1 (TREE_PURPOSE (link));
2835 else if (have_purpose)
2837 int zero = 0;
2839 obstack_grow (&permanent_obstack,
2840 (char *) &zero, sizeof zero);
2844 return;
2846 case ADDR_EXPR:
2848 struct addr_const value;
2850 decode_addr_const (exp, &value);
2851 /* Record the offset. */
2852 obstack_grow (&permanent_obstack,
2853 (char *) &value.offset, sizeof value.offset);
2854 /* Record the symbol name. */
2855 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2856 strlen (XSTR (value.base, 0)) + 1);
2858 return;
2860 case PLUS_EXPR:
2861 case MINUS_EXPR:
2862 case RANGE_EXPR:
2863 record_constant_1 (TREE_OPERAND (exp, 0));
2864 record_constant_1 (TREE_OPERAND (exp, 1));
2865 return;
2867 case NOP_EXPR:
2868 case CONVERT_EXPR:
2869 case NON_LVALUE_EXPR:
2870 record_constant_1 (TREE_OPERAND (exp, 0));
2871 return;
2873 default:
2874 abort ();
2877 /* Record constant contents. */
2878 obstack_grow (&permanent_obstack, strp, len);
2881 /* Record a list of constant expressions that were passed to
2882 output_constant_def but that could not be output right away. */
2884 struct deferred_constant
2886 struct deferred_constant *next;
2887 tree exp;
2888 int reloc;
2889 int labelno;
2892 static struct deferred_constant *deferred_constants;
2894 /* Another list of constants which should be output after the
2895 function. */
2896 static struct deferred_constant *after_function_constants;
2898 /* Nonzero means defer output of addressed subconstants
2899 (i.e., those for which output_constant_def is called.) */
2900 static int defer_addressed_constants_flag;
2902 /* Start deferring output of subconstants. */
2904 void
2905 defer_addressed_constants ()
2907 defer_addressed_constants_flag++;
2910 /* Stop deferring output of subconstants,
2911 and output now all those that have been deferred. */
2913 void
2914 output_deferred_addressed_constants ()
2916 struct deferred_constant *p, *next;
2918 defer_addressed_constants_flag--;
2920 if (defer_addressed_constants_flag > 0)
2921 return;
2923 for (p = deferred_constants; p; p = next)
2925 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2926 next = p->next;
2927 free (p);
2930 deferred_constants = 0;
2933 /* Output any constants which should appear after a function. */
2935 static void
2936 output_after_function_constants ()
2938 struct deferred_constant *p, *next;
2940 for (p = after_function_constants; p; p = next)
2942 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2943 next = p->next;
2944 free (p);
2947 after_function_constants = 0;
2950 /* Make a copy of the whole tree structure for a constant.
2951 This handles the same types of nodes that compare_constant
2952 and record_constant handle. */
2954 static tree
2955 copy_constant (exp)
2956 tree exp;
2958 switch (TREE_CODE (exp))
2960 case ADDR_EXPR:
2961 /* For ADDR_EXPR, we do not want to copy the decl whose address
2962 is requested. We do want to copy constants though. */
2963 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2964 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2965 copy_constant (TREE_OPERAND (exp, 0)));
2966 else
2967 return copy_node (exp);
2969 case INTEGER_CST:
2970 case REAL_CST:
2971 case STRING_CST:
2972 return copy_node (exp);
2974 case COMPLEX_CST:
2975 return build_complex (TREE_TYPE (exp),
2976 copy_constant (TREE_REALPART (exp)),
2977 copy_constant (TREE_IMAGPART (exp)));
2979 case PLUS_EXPR:
2980 case MINUS_EXPR:
2981 return build (TREE_CODE (exp), TREE_TYPE (exp),
2982 copy_constant (TREE_OPERAND (exp, 0)),
2983 copy_constant (TREE_OPERAND (exp, 1)));
2985 case NOP_EXPR:
2986 case CONVERT_EXPR:
2987 case NON_LVALUE_EXPR:
2988 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2989 copy_constant (TREE_OPERAND (exp, 0)));
2991 case CONSTRUCTOR:
2993 tree copy = copy_node (exp);
2994 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2995 tree tail;
2997 CONSTRUCTOR_ELTS (copy) = list;
2998 for (tail = list; tail; tail = TREE_CHAIN (tail))
2999 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3000 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3001 for (tail = list; tail; tail = TREE_CHAIN (tail))
3002 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3004 return copy;
3007 default:
3008 abort ();
3012 /* Return an rtx representing a reference to constant data in memory
3013 for the constant expression EXP.
3015 If assembler code for such a constant has already been output,
3016 return an rtx to refer to it.
3017 Otherwise, output such a constant in memory (or defer it for later)
3018 and generate an rtx for it.
3020 The TREE_CST_RTL of EXP is set up to point to that rtx.
3021 The const_hash_table records which constants already have label strings. */
3024 output_constant_def (exp)
3025 tree exp;
3027 register int hash;
3028 register struct constant_descriptor *desc;
3029 char label[256];
3030 char *found = 0;
3031 int reloc;
3032 register rtx def;
3034 if (TREE_CST_RTL (exp))
3035 return TREE_CST_RTL (exp);
3037 /* Make sure any other constants whose addresses appear in EXP
3038 are assigned label numbers. */
3040 reloc = output_addressed_constants (exp);
3042 /* Compute hash code of EXP. Search the descriptors for that hash code
3043 to see if any of them describes EXP. If yes, the descriptor records
3044 the label number already assigned. */
3046 hash = const_hash (exp) % MAX_HASH_TABLE;
3048 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3049 if (compare_constant (exp, desc))
3051 found = desc->label;
3052 break;
3055 if (found == 0)
3057 /* No constant equal to EXP is known to have been output.
3058 Make a constant descriptor to enter EXP in the hash table.
3059 Assign the label number and record it in the descriptor for
3060 future calls to this function to find. */
3062 /* Create a string containing the label name, in LABEL. */
3063 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3065 desc = record_constant (exp);
3066 desc->next = const_hash_table[hash];
3067 desc->label = ggc_alloc_string (label, -1);
3068 const_hash_table[hash] = desc;
3071 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3073 push_obstacks_nochange ();
3074 if (TREE_PERMANENT (exp))
3075 end_temporary_allocation ();
3077 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
3079 TREE_CST_RTL (exp)
3080 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
3081 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
3082 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
3083 MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
3085 pop_obstacks ();
3087 /* Optionally set flags or add text to the name to record information
3088 such as that it is a function name. If the name is changed, the macro
3089 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3090 #ifdef ENCODE_SECTION_INFO
3091 ENCODE_SECTION_INFO (exp);
3092 #endif
3094 /* If this is the first time we've seen this particular constant,
3095 output it (or defer its output for later). */
3096 if (found == 0)
3098 int after_function = 0;
3100 #ifdef CONSTANT_AFTER_FUNCTION_P
3101 if (current_function_decl != 0
3102 && CONSTANT_AFTER_FUNCTION_P (exp))
3103 after_function = 1;
3104 #endif
3106 if (defer_addressed_constants_flag || after_function)
3108 struct deferred_constant *p;
3109 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3111 push_obstacks_nochange ();
3112 suspend_momentary ();
3113 p->exp = copy_constant (exp);
3114 pop_obstacks ();
3115 p->reloc = reloc;
3116 p->labelno = const_labelno++;
3117 if (after_function)
3119 p->next = after_function_constants;
3120 after_function_constants = p;
3122 else
3124 p->next = deferred_constants;
3125 deferred_constants = p;
3128 else
3130 /* Do no output if -fsyntax-only. */
3131 if (! flag_syntax_only)
3132 output_constant_def_contents (exp, reloc, const_labelno);
3133 ++const_labelno;
3137 return TREE_CST_RTL (exp);
3140 /* Now output assembler code to define the label for EXP,
3141 and follow it with the data of EXP. */
3143 static void
3144 output_constant_def_contents (exp, reloc, labelno)
3145 tree exp;
3146 int reloc;
3147 int labelno;
3149 int align;
3151 if (IN_NAMED_SECTION (exp))
3152 named_section (exp, NULL, reloc);
3153 else
3155 /* First switch to text section, except for writable strings. */
3156 #ifdef SELECT_SECTION
3157 SELECT_SECTION (exp, reloc);
3158 #else
3159 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3160 || (flag_pic && reloc))
3161 data_section ();
3162 else
3163 readonly_data_section ();
3164 #endif
3167 /* Align the location counter as required by EXP's data type. */
3168 align = TYPE_ALIGN (TREE_TYPE (exp));
3169 #ifdef CONSTANT_ALIGNMENT
3170 align = CONSTANT_ALIGNMENT (exp, align);
3171 #endif
3173 if (align > BITS_PER_UNIT)
3174 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3176 /* Output the label itself. */
3177 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3179 /* Output the value of EXP. */
3180 output_constant (exp,
3181 (TREE_CODE (exp) == STRING_CST
3182 ? TREE_STRING_LENGTH (exp)
3183 : int_size_in_bytes (TREE_TYPE (exp))));
3187 /* Structure to represent sufficient information about a constant so that
3188 it can be output when the constant pool is output, so that function
3189 integration can be done, and to simplify handling on machines that reference
3190 constant pool as base+displacement. */
3192 struct pool_constant
3194 struct constant_descriptor *desc;
3195 struct pool_constant *next;
3196 enum machine_mode mode;
3197 rtx constant;
3198 int labelno;
3199 int align;
3200 int offset;
3201 int mark;
3204 /* Structure used to maintain hash table mapping symbols used to their
3205 corresponding constants. */
3207 struct pool_sym
3209 char *label;
3210 struct pool_constant *pool;
3211 struct pool_sym *next;
3214 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3215 The argument is XSTR (... , 0) */
3217 #define SYMHASH(LABEL) \
3218 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3220 /* Initialize constant pool hashing for a new function. */
3222 void
3223 init_varasm_status (f)
3224 struct function *f;
3226 struct varasm_status *p;
3227 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3228 f->varasm = p;
3229 p->x_const_rtx_hash_table
3230 = ((struct constant_descriptor **)
3231 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3232 p->x_const_rtx_sym_hash_table
3233 = ((struct pool_sym **)
3234 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3235 bzero ((char *) p->x_const_rtx_hash_table,
3236 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3237 bzero ((char *) p->x_const_rtx_sym_hash_table,
3238 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3240 p->x_first_pool = p->x_last_pool = 0;
3241 p->x_pool_offset = 0;
3242 p->x_const_double_chain = 0;
3245 /* Mark PC for GC. */
3247 static void
3248 mark_pool_constant (pc)
3249 struct pool_constant *pc;
3251 while (pc)
3253 ggc_mark_rtx (pc->constant);
3254 pc = pc->next;
3258 /* Mark PPS for GC. */
3260 static void
3261 mark_pool_sym_hash_table (pps)
3262 struct pool_sym **pps;
3264 struct pool_sym *ps;
3265 int i;
3267 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3268 for (ps = pps[i]; ps ; ps = ps->next)
3269 ggc_mark_string (ps->label);
3272 /* Mark P for GC. */
3274 void
3275 mark_varasm_status (p)
3276 struct varasm_status *p;
3278 if (p == NULL)
3279 return;
3281 mark_pool_constant (p->x_first_pool);
3282 mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
3283 ggc_mark_rtx (p->x_const_double_chain);
3286 /* Clear out all parts of the state in F that can safely be discarded
3287 after the function has been compiled, to let garbage collection
3288 reclaim the memory. */
3290 void
3291 free_varasm_status (f)
3292 struct function *f;
3294 struct varasm_status *p;
3296 p = f->varasm;
3297 free (p->x_const_rtx_hash_table);
3298 free (p->x_const_rtx_sym_hash_table);
3299 free (p);
3300 f->varasm = NULL;
3303 enum kind { RTX_DOUBLE, RTX_INT };
3305 struct rtx_const
3307 #ifdef ONLY_INT_FIELDS
3308 unsigned int kind : 16;
3309 unsigned int mode : 16;
3310 #else
3311 enum kind kind : 16;
3312 enum machine_mode mode : 16;
3313 #endif
3314 union {
3315 union real_extract du;
3316 struct addr_const addr;
3317 struct {HOST_WIDE_INT high, low;} di;
3318 } un;
3321 /* Express an rtx for a constant integer (perhaps symbolic)
3322 as the sum of a symbol or label plus an explicit integer.
3323 They are stored into VALUE. */
3325 static void
3326 decode_rtx_const (mode, x, value)
3327 enum machine_mode mode;
3328 rtx x;
3329 struct rtx_const *value;
3331 /* Clear the whole structure, including any gaps. */
3334 int *p = (int *) value;
3335 int *end = (int *) (value + 1);
3336 while (p < end)
3337 *p++ = 0;
3340 value->kind = RTX_INT; /* Most usual kind. */
3341 value->mode = mode;
3343 switch (GET_CODE (x))
3345 case CONST_DOUBLE:
3346 value->kind = RTX_DOUBLE;
3347 if (GET_MODE (x) != VOIDmode)
3349 value->mode = GET_MODE (x);
3350 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3351 (char *) &value->un.du, sizeof value->un.du);
3353 else
3355 value->un.di.low = CONST_DOUBLE_LOW (x);
3356 value->un.di.high = CONST_DOUBLE_HIGH (x);
3358 break;
3360 case CONST_INT:
3361 value->un.addr.offset = INTVAL (x);
3362 break;
3364 case SYMBOL_REF:
3365 case LABEL_REF:
3366 case PC:
3367 value->un.addr.base = x;
3368 break;
3370 case CONST:
3371 x = XEXP (x, 0);
3372 if (GET_CODE (x) == PLUS)
3374 value->un.addr.base = XEXP (x, 0);
3375 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3376 abort ();
3377 value->un.addr.offset = INTVAL (XEXP (x, 1));
3379 else if (GET_CODE (x) == MINUS)
3381 value->un.addr.base = XEXP (x, 0);
3382 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3383 abort ();
3384 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3386 else
3387 abort ();
3388 break;
3390 default:
3391 abort ();
3394 if (value->kind == RTX_INT && value->un.addr.base != 0)
3395 switch (GET_CODE (value->un.addr.base))
3397 case SYMBOL_REF:
3398 case LABEL_REF:
3399 /* Use the string's address, not the SYMBOL_REF's address,
3400 for the sake of addresses of library routines.
3401 For a LABEL_REF, compare labels. */
3402 value->un.addr.base = XEXP (value->un.addr.base, 0);
3404 default:
3405 break;
3409 /* Given a MINUS expression, simplify it if both sides
3410 include the same symbol. */
3413 simplify_subtraction (x)
3414 rtx x;
3416 struct rtx_const val0, val1;
3418 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3419 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3421 if (val0.un.addr.base == val1.un.addr.base)
3422 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3423 return x;
3426 /* Compute a hash code for a constant RTL expression. */
3428 static int
3429 const_hash_rtx (mode, x)
3430 enum machine_mode mode;
3431 rtx x;
3433 register int hi;
3434 register size_t i;
3436 struct rtx_const value;
3437 decode_rtx_const (mode, x, &value);
3439 /* Compute hashing function */
3440 hi = 0;
3441 for (i = 0; i < sizeof value / sizeof (int); i++)
3442 hi += ((int *) &value)[i];
3444 hi &= (1 << HASHBITS) - 1;
3445 hi %= MAX_RTX_HASH_TABLE;
3446 return hi;
3449 /* Compare a constant rtl object X with a constant-descriptor DESC.
3450 Return 1 if DESC describes a constant with the same value as X. */
3452 static int
3453 compare_constant_rtx (mode, x, desc)
3454 enum machine_mode mode;
3455 rtx x;
3456 struct constant_descriptor *desc;
3458 register int *p = (int *) desc->contents;
3459 register int *strp;
3460 register int len;
3461 struct rtx_const value;
3463 decode_rtx_const (mode, x, &value);
3464 strp = (int *) &value;
3465 len = sizeof value / sizeof (int);
3467 /* Compare constant contents. */
3468 while (--len >= 0)
3469 if (*p++ != *strp++)
3470 return 0;
3472 return 1;
3475 /* Construct a constant descriptor for the rtl-expression X.
3476 It is up to the caller to enter the descriptor in the hash table. */
3478 static struct constant_descriptor *
3479 record_constant_rtx (mode, x)
3480 enum machine_mode mode;
3481 rtx x;
3483 struct constant_descriptor *ptr;
3484 char *label;
3485 struct rtx_const value;
3487 decode_rtx_const (mode, x, &value);
3489 /* Put these things in the saveable obstack so we can ensure it won't
3490 be freed if we are called from combine or some other phase that discards
3491 memory allocated from function_obstack (current_obstack). */
3492 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3493 obstack_grow (saveable_obstack, &label, sizeof label);
3495 /* Record constant contents. */
3496 obstack_grow (saveable_obstack, &value, sizeof value);
3498 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3501 /* Given a constant rtx X, make (or find) a memory constant for its value
3502 and return a MEM rtx to refer to it in memory. */
3505 force_const_mem (mode, x)
3506 enum machine_mode mode;
3507 rtx x;
3509 register int hash;
3510 register struct constant_descriptor *desc;
3511 char label[256];
3512 char *found = 0;
3513 rtx def;
3515 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3516 (this will always be true for floating CONST_DOUBLEs that have been
3517 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3518 use the previous copy. Otherwise, make a new one. Note that in
3519 the unlikely event that this same CONST_DOUBLE is used in two different
3520 modes in an alternating fashion, we will allocate a lot of different
3521 memory locations, but this should be extremely rare. */
3523 if (GET_CODE (x) == CONST_DOUBLE
3524 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3525 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3526 return CONST_DOUBLE_MEM (x);
3528 /* Compute hash code of X. Search the descriptors for that hash code
3529 to see if any of them describes X. If yes, the descriptor records
3530 the label number already assigned. */
3532 hash = const_hash_rtx (mode, x);
3534 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3535 if (compare_constant_rtx (mode, x, desc))
3537 found = desc->label;
3538 break;
3541 if (found == 0)
3543 register struct pool_constant *pool;
3544 register struct pool_sym *sym;
3545 int align;
3547 /* No constant equal to X is known to have been output.
3548 Make a constant descriptor to enter X in the hash table.
3549 Assign the label number and record it in the descriptor for
3550 future calls to this function to find. */
3552 desc = record_constant_rtx (mode, x);
3553 desc->next = const_rtx_hash_table[hash];
3554 const_rtx_hash_table[hash] = desc;
3556 /* Align the location counter as required by EXP's data type. */
3557 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3558 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3559 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3560 #ifdef CONSTANT_ALIGNMENT
3561 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3562 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3563 #endif
3565 pool_offset += align - 1;
3566 pool_offset &= ~ (align - 1);
3568 /* If RTL is not being placed into the saveable obstack, make a
3569 copy of X that is in the saveable obstack in case we are
3570 being called from combine or some other phase that discards
3571 memory it allocates. We used to only do this if it is a
3572 CONST; however, reload can allocate a CONST_INT when
3573 eliminating registers. */
3574 if (rtl_obstack != saveable_obstack
3575 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3577 push_obstacks_nochange ();
3578 rtl_in_saveable_obstack ();
3580 if (GET_CODE (x) == CONST)
3581 x = gen_rtx_CONST (GET_MODE (x),
3582 gen_rtx_PLUS (GET_MODE (x),
3583 XEXP (XEXP (x, 0), 0),
3584 XEXP (XEXP (x, 0), 1)));
3585 else
3586 x = GEN_INT (INTVAL (x));
3588 pop_obstacks ();
3591 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3593 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3594 pool->desc = desc;
3595 pool->constant = x;
3596 pool->mode = mode;
3597 pool->labelno = const_labelno;
3598 pool->align = align;
3599 pool->offset = pool_offset;
3600 pool->mark = 1;
3601 pool->next = 0;
3603 if (last_pool == 0)
3604 first_pool = pool;
3605 else
3606 last_pool->next = pool;
3608 last_pool = pool;
3609 pool_offset += GET_MODE_SIZE (mode);
3611 /* Create a string containing the label name, in LABEL. */
3612 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3614 ++const_labelno;
3616 desc->label = found = ggc_alloc_string (label, -1);
3618 /* Add label to symbol hash table. */
3619 hash = SYMHASH (found);
3620 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3621 sym->label = found;
3622 sym->pool = pool;
3623 sym->next = const_rtx_sym_hash_table[hash];
3624 const_rtx_sym_hash_table[hash] = sym;
3627 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3629 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3631 RTX_UNCHANGING_P (def) = 1;
3632 /* Mark the symbol_ref as belonging to this constants pool. */
3633 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3634 current_function_uses_const_pool = 1;
3636 if (GET_CODE (x) == CONST_DOUBLE)
3638 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3640 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3641 const_double_chain = x;
3643 CONST_DOUBLE_MEM (x) = def;
3646 return def;
3649 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3650 the corresponding pool_constant structure. */
3652 static struct pool_constant *
3653 find_pool_constant (f, addr)
3654 struct function *f;
3655 rtx addr;
3657 struct pool_sym *sym;
3658 char *label = XSTR (addr, 0);
3660 for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3661 if (sym->label == label)
3662 return sym->pool;
3664 abort ();
3667 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3670 get_pool_constant (addr)
3671 rtx addr;
3673 return (find_pool_constant (current_function, addr))->constant;
3676 /* Likewise, but for the constant pool of a specific function. */
3679 get_pool_constant_for_function (f, addr)
3680 struct function *f;
3681 rtx addr;
3683 return (find_pool_constant (f, addr))->constant;
3686 /* Similar, return the mode. */
3688 enum machine_mode
3689 get_pool_mode (addr)
3690 rtx addr;
3692 return (find_pool_constant (current_function, addr))->mode;
3695 enum machine_mode
3696 get_pool_mode_for_function (f, addr)
3697 struct function *f;
3698 rtx addr;
3700 return (find_pool_constant (f, addr))->mode;
3703 /* Similar, return the offset in the constant pool. */
3706 get_pool_offset (addr)
3707 rtx addr;
3709 return (find_pool_constant (current_function, addr))->offset;
3712 /* Return the size of the constant pool. */
3715 get_pool_size ()
3717 return pool_offset;
3720 /* Write all the constants in the constant pool. */
3722 void
3723 output_constant_pool (fnname, fndecl)
3724 char *fnname ATTRIBUTE_UNUSED;
3725 tree fndecl ATTRIBUTE_UNUSED;
3727 struct pool_constant *pool;
3728 rtx x;
3729 union real_extract u;
3731 /* It is possible for gcc to call force_const_mem and then to later
3732 discard the instructions which refer to the constant. In such a
3733 case we do not need to output the constant. */
3734 mark_constant_pool ();
3736 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3737 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3738 #endif
3740 for (pool = first_pool; pool; pool = pool->next)
3742 x = pool->constant;
3744 if (! pool->mark)
3745 continue;
3747 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3748 whose CODE_LABEL has been deleted. This can occur if a jump table
3749 is eliminated by optimization. If so, write a constant of zero
3750 instead. Note that this can also happen by turning the
3751 CODE_LABEL into a NOTE. */
3752 if (((GET_CODE (x) == LABEL_REF
3753 && (INSN_DELETED_P (XEXP (x, 0))
3754 || GET_CODE (XEXP (x, 0)) == NOTE)))
3755 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3756 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3757 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3758 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3759 x = const0_rtx;
3761 /* First switch to correct section. */
3762 #ifdef SELECT_RTX_SECTION
3763 SELECT_RTX_SECTION (pool->mode, x);
3764 #else
3765 readonly_data_section ();
3766 #endif
3768 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3769 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3770 pool->align, pool->labelno, done);
3771 #endif
3773 if (pool->align > 1)
3774 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3776 /* Output the label. */
3777 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3779 /* Output the value of the constant itself. */
3780 switch (GET_MODE_CLASS (pool->mode))
3782 case MODE_FLOAT:
3783 if (GET_CODE (x) != CONST_DOUBLE)
3784 abort ();
3786 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3787 assemble_real (u.d, pool->mode);
3788 break;
3790 case MODE_INT:
3791 case MODE_PARTIAL_INT:
3792 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3793 break;
3795 default:
3796 abort ();
3799 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3800 done: ;
3801 #endif
3805 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3806 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3807 #endif
3809 /* Done with this pool. */
3810 first_pool = last_pool = 0;
3813 /* Look through the instructions for this function, and mark all the
3814 entries in the constant pool which are actually being used. */
3816 static void
3817 mark_constant_pool ()
3819 register rtx insn;
3820 struct pool_constant *pool;
3822 if (first_pool == 0)
3823 return;
3825 for (pool = first_pool; pool; pool = pool->next)
3826 pool->mark = 0;
3828 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3829 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3830 mark_constants (PATTERN (insn));
3832 for (insn = current_function_epilogue_delay_list;
3833 insn;
3834 insn = XEXP (insn, 1))
3835 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3836 mark_constants (PATTERN (insn));
3838 /* It's possible that the only reference to a symbol is in a symbol
3839 that's in the constant pool. This happens in Fortran under some
3840 situations. (When the constant contains the address of another
3841 constant, and only the first is used directly in an insn.)
3842 This is potentially suboptimal if there's ever a possibility of
3843 backwards (in pool order) 2'd level references. However, it's
3844 not clear that 2'd level references can happen. */
3845 for (pool = first_pool; pool; pool = pool->next)
3847 struct pool_sym *sym;
3848 char *label;
3850 /* skip unmarked entries; no insn refers to them. */
3851 if (!pool->mark)
3852 continue;
3854 /* Skip everything except SYMBOL_REFs. */
3855 if (GET_CODE (pool->constant) != SYMBOL_REF)
3856 continue;
3857 label = XSTR (pool->constant, 0);
3859 /* Be sure the symbol's value is marked. */
3860 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3861 sym = sym->next)
3862 if (sym->label == label)
3863 sym->pool->mark = 1;
3864 /* If we didn't find it, there's something truly wrong here, but it
3865 will be announced by the assembler. */
3869 static void
3870 mark_constants (x)
3871 register rtx x;
3873 register int i;
3874 register const char *format_ptr;
3876 if (x == 0)
3877 return;
3879 if (GET_CODE (x) == SYMBOL_REF)
3881 if (CONSTANT_POOL_ADDRESS_P (x))
3882 find_pool_constant (current_function, x)->mark = 1;
3883 return;
3885 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3886 a MEM, but does not constitute a use of that MEM. */
3887 else if (GET_CODE (x) == CONST_DOUBLE)
3888 return;
3890 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3891 insns, not any notes that may be attached. We don't want to mark
3892 a constant just because it happens to appear in a REG_EQUIV note. */
3893 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3895 mark_constants (PATTERN (x));
3896 return;
3899 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3901 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3903 switch (*format_ptr++)
3905 case 'e':
3906 mark_constants (XEXP (x, i));
3907 break;
3909 case 'E':
3910 if (XVEC (x, i) != 0)
3912 register int j;
3914 for (j = 0; j < XVECLEN (x, i); j++)
3915 mark_constants (XVECEXP (x, i, j));
3917 break;
3919 case 'S':
3920 case 's':
3921 case '0':
3922 case 'i':
3923 case 'w':
3924 case 'n':
3925 case 'u':
3926 break;
3928 default:
3929 abort ();
3934 /* Find all the constants whose addresses are referenced inside of EXP,
3935 and make sure assembler code with a label has been output for each one.
3936 Indicate whether an ADDR_EXPR has been encountered. */
3938 static int
3939 output_addressed_constants (exp)
3940 tree exp;
3942 int reloc = 0;
3944 switch (TREE_CODE (exp))
3946 case ADDR_EXPR:
3948 register tree constant = TREE_OPERAND (exp, 0);
3950 while (TREE_CODE (constant) == COMPONENT_REF)
3952 constant = TREE_OPERAND (constant, 0);
3955 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3956 || TREE_CODE (constant) == CONSTRUCTOR)
3957 /* No need to do anything here
3958 for addresses of variables or functions. */
3959 output_constant_def (constant);
3961 reloc = 1;
3962 break;
3964 case PLUS_EXPR:
3965 case MINUS_EXPR:
3966 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3967 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3968 break;
3970 case NOP_EXPR:
3971 case CONVERT_EXPR:
3972 case NON_LVALUE_EXPR:
3973 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3974 break;
3976 case CONSTRUCTOR:
3978 register tree link;
3979 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3980 if (TREE_VALUE (link) != 0)
3981 reloc |= output_addressed_constants (TREE_VALUE (link));
3983 break;
3985 default:
3986 break;
3988 return reloc;
3991 /* Output assembler code for constant EXP to FILE, with no label.
3992 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3993 Assumes output_addressed_constants has been done on EXP already.
3995 Generate exactly SIZE bytes of assembler data, padding at the end
3996 with zeros if necessary. SIZE must always be specified.
3998 SIZE is important for structure constructors,
3999 since trailing members may have been omitted from the constructor.
4000 It is also important for initialization of arrays from string constants
4001 since the full length of the string constant might not be wanted.
4002 It is also needed for initialization of unions, where the initializer's
4003 type is just one member, and that may not be as long as the union.
4005 There a case in which we would fail to output exactly SIZE bytes:
4006 for a structure constructor that wants to produce more than SIZE bytes.
4007 But such constructors will never be generated for any possible input. */
4009 void
4010 output_constant (exp, size)
4011 register tree exp;
4012 register int size;
4014 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4016 /* Some front-ends use constants other than the standard
4017 language-indepdent varieties, but which may still be output
4018 directly. Give the front-end a chance to convert EXP to a
4019 language-independent representation. */
4020 if (lang_expand_constant)
4021 exp = (*lang_expand_constant) (exp);
4023 if (size == 0 || flag_syntax_only)
4024 return;
4026 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4027 That way we get the constant (we hope) inside it. Also, strip off any
4028 NOP_EXPR that converts between two record, union, array, or set types. */
4029 while ((TREE_CODE (exp) == NOP_EXPR
4030 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4031 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4032 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4033 exp = TREE_OPERAND (exp, 0);
4035 /* Allow a constructor with no elements for any data type.
4036 This means to fill the space with zeros. */
4037 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4039 assemble_zeros (size);
4040 return;
4043 switch (code)
4045 case CHAR_TYPE:
4046 case BOOLEAN_TYPE:
4047 case INTEGER_TYPE:
4048 case ENUMERAL_TYPE:
4049 case POINTER_TYPE:
4050 case REFERENCE_TYPE:
4051 /* ??? What about (int)((float)(int)&foo + 4) */
4052 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4053 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4054 exp = TREE_OPERAND (exp, 0);
4056 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4057 EXPAND_INITIALIZER),
4058 size, 0))
4059 error ("initializer for integer value is too complicated");
4060 size = 0;
4061 break;
4063 case REAL_TYPE:
4064 if (TREE_CODE (exp) != REAL_CST)
4065 error ("initializer for floating value is not a floating constant");
4067 assemble_real (TREE_REAL_CST (exp),
4068 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4069 size = 0;
4070 break;
4072 case COMPLEX_TYPE:
4073 output_constant (TREE_REALPART (exp), size / 2);
4074 output_constant (TREE_IMAGPART (exp), size / 2);
4075 size -= (size / 2) * 2;
4076 break;
4078 case ARRAY_TYPE:
4079 if (TREE_CODE (exp) == CONSTRUCTOR)
4081 output_constructor (exp, size);
4082 return;
4084 else if (TREE_CODE (exp) == STRING_CST)
4086 int excess = 0;
4088 if (size > TREE_STRING_LENGTH (exp))
4090 excess = size - TREE_STRING_LENGTH (exp);
4091 size = TREE_STRING_LENGTH (exp);
4094 assemble_string (TREE_STRING_POINTER (exp), size);
4095 size = excess;
4097 else
4098 abort ();
4099 break;
4101 case RECORD_TYPE:
4102 case UNION_TYPE:
4103 if (TREE_CODE (exp) == CONSTRUCTOR)
4104 output_constructor (exp, size);
4105 else
4106 abort ();
4107 return;
4109 case SET_TYPE:
4110 if (TREE_CODE (exp) == INTEGER_CST)
4111 assemble_integer (expand_expr (exp, NULL_RTX,
4112 VOIDmode, EXPAND_INITIALIZER),
4113 size, 1);
4114 else if (TREE_CODE (exp) == CONSTRUCTOR)
4116 unsigned char *buffer = (unsigned char *) alloca (size);
4117 if (get_set_constructor_bytes (exp, buffer, size))
4118 abort ();
4119 assemble_string ((char *) buffer, size);
4121 else
4122 error ("unknown set constructor type");
4123 return;
4125 default:
4126 break; /* ??? */
4129 if (size > 0)
4130 assemble_zeros (size);
4134 /* Subroutine of output_constant, used for CONSTRUCTORs
4135 (aggregate constants).
4136 Generate at least SIZE bytes, padding if necessary. */
4138 static void
4139 output_constructor (exp, size)
4140 tree exp;
4141 int size;
4143 register tree link, field = 0;
4144 HOST_WIDE_INT min_index = 0;
4145 /* Number of bytes output or skipped so far.
4146 In other words, current position within the constructor. */
4147 int total_bytes = 0;
4148 /* Non-zero means BYTE contains part of a byte, to be output. */
4149 int byte_buffer_in_use = 0;
4150 register int byte;
4152 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4153 abort ();
4155 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4156 field = TYPE_FIELDS (TREE_TYPE (exp));
4158 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4159 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4160 min_index
4161 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4163 /* As LINK goes through the elements of the constant,
4164 FIELD goes through the structure fields, if the constant is a structure.
4165 if the constant is a union, then we override this,
4166 by getting the field from the TREE_LIST element.
4167 But the constant could also be an array. Then FIELD is zero.
4169 There is always a maximum of one element in the chain LINK for unions
4170 (even if the initializer in a source program incorrectly contains
4171 more one). */
4172 for (link = CONSTRUCTOR_ELTS (exp);
4173 link;
4174 link = TREE_CHAIN (link),
4175 field = field ? TREE_CHAIN (field) : 0)
4177 tree val = TREE_VALUE (link);
4178 tree index = 0;
4180 /* the element in a union constructor specifies the proper field. */
4182 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4183 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4185 /* if available, use the type given by link */
4186 if (TREE_PURPOSE (link) != 0)
4187 field = TREE_PURPOSE (link);
4190 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4191 index = TREE_PURPOSE (link);
4193 /* Eliminate the marker that makes a cast not be an lvalue. */
4194 if (val != 0)
4195 STRIP_NOPS (val);
4197 if (index && TREE_CODE (index) == RANGE_EXPR)
4199 register int fieldsize
4200 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4201 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4202 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4203 HOST_WIDE_INT index;
4204 for (index = lo_index; index <= hi_index; index++)
4206 /* Output the element's initial value. */
4207 if (val == 0)
4208 assemble_zeros (fieldsize);
4209 else
4210 output_constant (val, fieldsize);
4212 /* Count its size. */
4213 total_bytes += fieldsize;
4216 else if (field == 0 || !DECL_BIT_FIELD (field))
4218 /* An element that is not a bit-field. */
4220 register int fieldsize;
4221 /* Since this structure is static,
4222 we know the positions are constant. */
4223 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4224 / BITS_PER_UNIT)
4225 : 0);
4226 if (index != 0)
4227 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4228 / BITS_PER_UNIT
4229 * (TREE_INT_CST_LOW (index) - min_index));
4231 /* Output any buffered-up bit-fields preceding this element. */
4232 if (byte_buffer_in_use)
4234 ASM_OUTPUT_BYTE (asm_out_file, byte);
4235 total_bytes++;
4236 byte_buffer_in_use = 0;
4239 /* Advance to offset of this element.
4240 Note no alignment needed in an array, since that is guaranteed
4241 if each element has the proper size. */
4242 if ((field != 0 || index != 0) && bitpos != total_bytes)
4244 assemble_zeros (bitpos - total_bytes);
4245 total_bytes = bitpos;
4248 /* Determine size this element should occupy. */
4249 if (field)
4251 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4252 abort ();
4253 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4255 /* This avoids overflow trouble. */
4256 tree size_tree = size_binop (CEIL_DIV_EXPR,
4257 DECL_SIZE (field),
4258 size_int (BITS_PER_UNIT));
4259 fieldsize = TREE_INT_CST_LOW (size_tree);
4261 else
4263 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4264 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4267 else
4268 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4270 /* Output the element's initial value. */
4271 if (val == 0)
4272 assemble_zeros (fieldsize);
4273 else
4274 output_constant (val, fieldsize);
4276 /* Count its size. */
4277 total_bytes += fieldsize;
4279 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4280 error ("invalid initial value for member `%s'",
4281 IDENTIFIER_POINTER (DECL_NAME (field)));
4282 else
4284 /* Element that is a bit-field. */
4286 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4287 int end_offset
4288 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4290 if (val == 0)
4291 val = integer_zero_node;
4293 /* If this field does not start in this (or, next) byte,
4294 skip some bytes. */
4295 if (next_offset / BITS_PER_UNIT != total_bytes)
4297 /* Output remnant of any bit field in previous bytes. */
4298 if (byte_buffer_in_use)
4300 ASM_OUTPUT_BYTE (asm_out_file, byte);
4301 total_bytes++;
4302 byte_buffer_in_use = 0;
4305 /* If still not at proper byte, advance to there. */
4306 if (next_offset / BITS_PER_UNIT != total_bytes)
4308 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4309 total_bytes = next_offset / BITS_PER_UNIT;
4313 if (! byte_buffer_in_use)
4314 byte = 0;
4316 /* We must split the element into pieces that fall within
4317 separate bytes, and combine each byte with previous or
4318 following bit-fields. */
4320 /* next_offset is the offset n fbits from the beginning of
4321 the structure to the next bit of this element to be processed.
4322 end_offset is the offset of the first bit past the end of
4323 this element. */
4324 while (next_offset < end_offset)
4326 int this_time;
4327 int shift;
4328 HOST_WIDE_INT value;
4329 int next_byte = next_offset / BITS_PER_UNIT;
4330 int next_bit = next_offset % BITS_PER_UNIT;
4332 /* Advance from byte to byte
4333 within this element when necessary. */
4334 while (next_byte != total_bytes)
4336 ASM_OUTPUT_BYTE (asm_out_file, byte);
4337 total_bytes++;
4338 byte = 0;
4341 /* Number of bits we can process at once
4342 (all part of the same byte). */
4343 this_time = MIN (end_offset - next_offset,
4344 BITS_PER_UNIT - next_bit);
4345 if (BYTES_BIG_ENDIAN)
4347 /* On big-endian machine, take the most significant bits
4348 first (of the bits that are significant)
4349 and put them into bytes from the most significant end. */
4350 shift = end_offset - next_offset - this_time;
4351 /* Don't try to take a bunch of bits that cross
4352 the word boundary in the INTEGER_CST. */
4353 if (shift < HOST_BITS_PER_WIDE_INT
4354 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4356 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4357 shift = HOST_BITS_PER_WIDE_INT;
4360 /* Now get the bits from the appropriate constant word. */
4361 if (shift < HOST_BITS_PER_WIDE_INT)
4363 value = TREE_INT_CST_LOW (val);
4365 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4367 value = TREE_INT_CST_HIGH (val);
4368 shift -= HOST_BITS_PER_WIDE_INT;
4370 else
4371 abort ();
4372 byte |= (((value >> shift)
4373 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4374 << (BITS_PER_UNIT - this_time - next_bit));
4376 else
4378 /* On little-endian machines,
4379 take first the least significant bits of the value
4380 and pack them starting at the least significant
4381 bits of the bytes. */
4382 shift = (next_offset
4383 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4384 /* Don't try to take a bunch of bits that cross
4385 the word boundary in the INTEGER_CST. */
4386 if (shift < HOST_BITS_PER_WIDE_INT
4387 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4389 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4390 shift = HOST_BITS_PER_WIDE_INT;
4393 /* Now get the bits from the appropriate constant word. */
4394 if (shift < HOST_BITS_PER_WIDE_INT)
4395 value = TREE_INT_CST_LOW (val);
4396 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4398 value = TREE_INT_CST_HIGH (val);
4399 shift -= HOST_BITS_PER_WIDE_INT;
4401 else
4402 abort ();
4403 byte |= (((value >> shift)
4404 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4405 << next_bit);
4407 next_offset += this_time;
4408 byte_buffer_in_use = 1;
4412 if (byte_buffer_in_use)
4414 ASM_OUTPUT_BYTE (asm_out_file, byte);
4415 total_bytes++;
4417 if (total_bytes < size)
4418 assemble_zeros (size - total_bytes);
4421 #ifdef HANDLE_PRAGMA_WEAK
4422 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4423 associatd with NAME. */
4426 add_weak (name, value)
4427 char *name;
4428 char *value;
4430 struct weak_syms *weak;
4432 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4434 if (weak == NULL)
4435 return 0;
4437 weak->next = weak_decls;
4438 weak->name = name;
4439 weak->value = value;
4440 weak_decls = weak;
4442 return 1;
4444 #endif /* HANDLE_PRAGMA_WEAK */
4446 /* Declare DECL to be a weak symbol. */
4448 void
4449 declare_weak (decl)
4450 tree decl;
4452 if (! TREE_PUBLIC (decl))
4453 error_with_decl (decl, "weak declaration of `%s' must be public");
4454 else if (TREE_ASM_WRITTEN (decl))
4455 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4456 else if (SUPPORTS_WEAK)
4457 DECL_WEAK (decl) = 1;
4458 #ifdef HANDLE_PRAGMA_WEAK
4459 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4460 #endif
4463 /* Emit any pending weak declarations. */
4465 #ifdef HANDLE_PRAGMA_WEAK
4466 struct weak_syms * weak_decls;
4467 #endif
4469 void
4470 weak_finish ()
4472 #ifdef HANDLE_PRAGMA_WEAK
4473 if (HANDLE_PRAGMA_WEAK)
4475 struct weak_syms *t;
4476 for (t = weak_decls; t; t = t->next)
4478 if (t->name)
4480 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4481 if (t->value)
4482 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4486 #endif
4489 /* Remove NAME from the pending list of weak symbols. This prevents
4490 the compiler from emitting multiple .weak directives which confuses
4491 some assemblers. */
4492 #ifdef ASM_WEAKEN_LABEL
4493 static void
4494 remove_from_pending_weak_list (name)
4495 char *name ATTRIBUTE_UNUSED;
4497 #ifdef HANDLE_PRAGMA_WEAK
4498 if (HANDLE_PRAGMA_WEAK)
4500 struct weak_syms *t;
4501 for (t = weak_decls; t; t = t->next)
4503 if (t->name && strcmp (name, t->name) == 0)
4504 t->name = NULL;
4507 #endif
4509 #endif
4511 void
4512 assemble_alias (decl, target)
4513 tree decl, target ATTRIBUTE_UNUSED;
4515 char *name;
4517 make_decl_rtl (decl, (char *) 0, 1);
4518 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4520 #ifdef ASM_OUTPUT_DEF
4521 /* Make name accessible from other files, if appropriate. */
4523 if (TREE_PUBLIC (decl))
4525 #ifdef ASM_WEAKEN_LABEL
4526 if (DECL_WEAK (decl))
4528 ASM_WEAKEN_LABEL (asm_out_file, name);
4529 /* Remove this function from the pending weak list so that
4530 we do not emit multiple .weak directives for it. */
4531 remove_from_pending_weak_list
4532 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4534 else
4535 #endif
4536 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4539 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4540 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4541 #else
4542 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4543 #endif
4544 TREE_ASM_WRITTEN (decl) = 1;
4545 #else
4546 #ifdef ASM_OUTPUT_WEAK_ALIAS
4547 if (! DECL_WEAK (decl))
4548 warning ("only weak aliases are supported in this configuration");
4550 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4551 TREE_ASM_WRITTEN (decl) = 1;
4552 #else
4553 warning ("alias definitions not supported in this configuration; ignored");
4554 #endif
4555 #endif
4558 /* This determines whether or not we support link-once semantics. */
4559 #ifndef SUPPORTS_ONE_ONLY
4560 #ifdef MAKE_DECL_ONE_ONLY
4561 #define SUPPORTS_ONE_ONLY 1
4562 #else
4563 #define SUPPORTS_ONE_ONLY 0
4564 #endif
4565 #endif
4567 /* Returns 1 if the target configuration supports defining public symbols
4568 so that one of them will be chosen at link time instead of generating a
4569 multiply-defined symbol error, whether through the use of weak symbols or
4570 a target-specific mechanism for having duplicates discarded. */
4573 supports_one_only ()
4575 if (SUPPORTS_ONE_ONLY)
4576 return 1;
4577 return SUPPORTS_WEAK;
4580 /* Set up DECL as a public symbol that can be defined in multiple
4581 translation units without generating a linker error. */
4583 void
4584 make_decl_one_only (decl)
4585 tree decl;
4587 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4588 abort ();
4590 TREE_PUBLIC (decl) = 1;
4592 if (TREE_CODE (decl) == VAR_DECL
4593 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4594 DECL_COMMON (decl) = 1;
4595 else if (SUPPORTS_ONE_ONLY)
4597 #ifdef MAKE_DECL_ONE_ONLY
4598 MAKE_DECL_ONE_ONLY (decl);
4599 #endif
4600 DECL_ONE_ONLY (decl) = 1;
4602 else if (SUPPORTS_WEAK)
4603 DECL_WEAK (decl) = 1;
4604 else
4605 abort ();
4608 void
4609 init_varasm_once ()
4611 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof(const_hash_table[0]),
4612 mark_const_hash_entry);
4613 ggc_add_string_root (&in_named_name, 1);