* config/i386/i386.md (mmx_pinsrw): Output operands in correct
[official-gcc.git] / gcc / varasm.c
blobc4229037ed1a08fa8317b0fba43fe7cb914f3eab
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
30 #include "config.h"
31 #include "system.h"
32 #include <setjmp.h>
33 #include "rtl.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "expr.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "output.h"
42 #include "real.h"
43 #include "toplev.h"
44 #include "dbxout.h"
45 #include "sdbout.h"
46 #include "obstack.h"
47 #include "c-pragma.h"
48 #include "ggc.h"
49 #include "tm_p.h"
51 #ifdef XCOFF_DEBUGGING_INFO
52 #include "xcoffout.h"
53 #endif
55 #ifndef TRAMPOLINE_ALIGNMENT
56 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
57 #endif
59 #ifndef ASM_STABS_OP
60 #define ASM_STABS_OP "\t.stabs\t"
61 #endif
63 /* Define the prefix to use when check_memory_usage_flag is enable. */
64 #ifdef NO_DOLLAR_IN_LABEL
65 #ifdef NO_DOT_IN_LABEL
66 #define CHKR_PREFIX "chkr_prefix_"
67 #else /* !NO_DOT_IN_LABEL */
68 #define CHKR_PREFIX "chkr."
69 #endif
70 #else /* !NO_DOLLAR_IN_LABEL */
71 #define CHKR_PREFIX "chkr$"
72 #endif
73 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
75 /* File in which assembler code is being written. */
77 extern FILE *asm_out_file;
79 /* The (assembler) name of the first globally-visible object output. */
80 const char *first_global_object_name;
81 const char *weak_global_object_name;
83 extern struct obstack permanent_obstack;
84 #define obstack_chunk_alloc xmalloc
86 struct addr_const;
87 struct constant_descriptor;
88 struct rtx_const;
89 struct pool_constant;
91 #define MAX_RTX_HASH_TABLE 61
93 struct varasm_status
95 /* Hash facility for making memory-constants
96 from constant rtl-expressions. It is used on RISC machines
97 where immediate integer arguments and constant addresses are restricted
98 so that such constants must be stored in memory.
100 This pool of constants is reinitialized for each function
101 so each function gets its own constants-pool that comes right before
102 it. */
103 struct constant_descriptor **x_const_rtx_hash_table;
104 struct pool_sym **x_const_rtx_sym_hash_table;
106 /* Pointers to first and last constant in pool. */
107 struct pool_constant *x_first_pool, *x_last_pool;
109 /* Current offset in constant pool (does not include any machine-specific
110 header. */
111 int x_pool_offset;
113 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
114 They are chained through the CONST_DOUBLE_CHAIN.
115 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
116 In that case, CONST_DOUBLE_MEM is either a MEM,
117 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
118 rtx x_const_double_chain;
121 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
122 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
123 #define first_pool (cfun->varasm->x_first_pool)
124 #define last_pool (cfun->varasm->x_last_pool)
125 #define pool_offset (cfun->varasm->x_pool_offset)
126 #define const_double_chain (cfun->varasm->x_const_double_chain)
128 /* Number for making the label on the next
129 constant that is stored in memory. */
131 int const_labelno;
133 /* Number for making the label on the next
134 static variable internal to a function. */
136 int var_labelno;
138 /* Carry information from ASM_DECLARE_OBJECT_NAME
139 to ASM_FINISH_DECLARE_OBJECT. */
141 int size_directive_output;
143 /* The last decl for which assemble_variable was called,
144 if it did ASM_DECLARE_OBJECT_NAME.
145 If the last call to assemble_variable didn't do that,
146 this holds 0. */
148 tree last_assemble_variable_decl;
150 static const char *strip_reg_name PARAMS ((const char *));
151 static int contains_pointers_p PARAMS ((tree));
152 static void decode_addr_const PARAMS ((tree, struct addr_const *));
153 static int const_hash PARAMS ((tree));
154 static int compare_constant PARAMS ((tree,
155 struct constant_descriptor *));
156 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
157 static struct constant_descriptor *record_constant PARAMS ((tree));
158 static void record_constant_1 PARAMS ((tree));
159 static tree copy_constant PARAMS ((tree));
160 static void output_constant_def_contents PARAMS ((tree, int, int));
161 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
162 struct rtx_const *));
163 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
164 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
165 struct constant_descriptor *));
166 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
167 rtx));
168 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
169 static void mark_constant_pool PARAMS ((void));
170 static void mark_constants PARAMS ((rtx));
171 static int output_addressed_constants PARAMS ((tree));
172 static void output_after_function_constants PARAMS ((void));
173 static void output_constructor PARAMS ((tree, int));
174 #ifdef ASM_WEAKEN_LABEL
175 static void remove_from_pending_weak_list PARAMS ((const char *));
176 #endif
177 #ifdef ASM_OUTPUT_BSS
178 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
179 #endif
180 #ifdef BSS_SECTION_ASM_OP
181 #ifdef ASM_OUTPUT_ALIGNED_BSS
182 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
183 int, int));
184 #endif
185 #endif /* BSS_SECTION_ASM_OP */
186 static void mark_pool_constant PARAMS ((struct pool_constant *));
187 static void mark_pool_sym_hash_table PARAMS ((struct pool_sym **));
188 static void mark_const_hash_entry PARAMS ((void *));
189 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
191 static enum in_section { no_section, in_text, in_data, in_named
192 #ifdef BSS_SECTION_ASM_OP
193 , in_bss
194 #endif
195 #ifdef EH_FRAME_SECTION_ASM_OP
196 , in_eh_frame
197 #endif
198 #ifdef EXTRA_SECTIONS
199 , EXTRA_SECTIONS
200 #endif
201 } in_section = no_section;
203 /* Return a non-zero value if DECL has a section attribute. */
204 #ifndef IN_NAMED_SECTION
205 #define IN_NAMED_SECTION(DECL) \
206 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
207 && DECL_SECTION_NAME (DECL) != NULL_TREE)
208 #endif
210 /* Text of section name when in_section == in_named. */
211 static char *in_named_name;
213 /* Define functions like text_section for any extra sections. */
214 #ifdef EXTRA_SECTION_FUNCTIONS
215 EXTRA_SECTION_FUNCTIONS
216 #endif
218 /* Tell assembler to switch to text section. */
220 void
221 text_section ()
223 if (in_section != in_text)
225 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
226 in_section = in_text;
230 /* Tell assembler to switch to data section. */
232 void
233 data_section ()
235 if (in_section != in_data)
237 if (flag_shared_data)
239 #ifdef SHARED_SECTION_ASM_OP
240 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
241 #else
242 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
243 #endif
245 else
246 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
248 in_section = in_data;
251 /* Tell assembler to ALWAYS switch to data section, in case
252 it's not sure where it it. */
254 void
255 force_data_section ()
257 in_section = no_section;
258 data_section ();
261 /* Tell assembler to switch to read-only data section. This is normally
262 the text section. */
264 void
265 readonly_data_section ()
267 #ifdef READONLY_DATA_SECTION
268 READONLY_DATA_SECTION (); /* Note this can call data_section. */
269 #else
270 text_section ();
271 #endif
274 /* Determine if we're in the text section. */
277 in_text_section ()
279 return in_section == in_text;
282 /* Determine if we're in the data section. */
285 in_data_section ()
287 return in_section == in_data;
290 /* Tell assembler to change to section NAME for DECL.
291 If DECL is NULL, just switch to section NAME.
292 If NAME is NULL, get the name from DECL.
293 If RELOC is 1, the initializer for DECL contains relocs. */
295 void
296 named_section (decl, name, reloc)
297 tree decl;
298 const char *name;
299 int reloc ATTRIBUTE_UNUSED;
301 if (decl != NULL_TREE && !DECL_P (decl))
302 abort ();
303 if (name == NULL)
304 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
306 if (in_section != in_named || strcmp (name, in_named_name))
308 #ifdef ASM_OUTPUT_SECTION_NAME
309 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
310 #else
311 /* Section attributes are not supported if this macro isn't provided -
312 some host formats don't support them at all. The front-end should
313 already have flagged this as an error. */
314 abort ();
315 #endif
317 in_named_name = ggc_alloc_string (name, -1);
318 in_section = in_named;
322 #ifdef ASM_OUTPUT_SECTION_NAME
323 #ifndef UNIQUE_SECTION
324 #define UNIQUE_SECTION(DECL,RELOC) \
325 do { \
326 int len; \
327 const char *name; \
328 char *string; \
330 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
331 /* Strip off any encoding in name. */ \
332 STRIP_NAME_ENCODING (name, name); \
334 len = strlen (name) + 1; \
335 string = alloca (len + 1); \
336 sprintf (string, ".%s", name); \
338 DECL_SECTION_NAME (DECL) = build_string (len, string); \
339 } while (0)
340 #endif
341 #ifndef UNIQUE_SECTION_P
342 #define UNIQUE_SECTION_P(DECL) 0
343 #endif
344 #endif
346 #ifdef BSS_SECTION_ASM_OP
348 /* Tell the assembler to switch to the bss section. */
350 void
351 bss_section ()
353 if (in_section != in_bss)
355 #ifdef SHARED_BSS_SECTION_ASM_OP
356 if (flag_shared_data)
357 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
358 else
359 #endif
360 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
362 in_section = in_bss;
366 #ifdef ASM_OUTPUT_BSS
368 /* Utility function for ASM_OUTPUT_BSS for targets to use if
369 they don't support alignments in .bss.
370 ??? It is believed that this function will work in most cases so such
371 support is localized here. */
373 static void
374 asm_output_bss (file, decl, name, size, rounded)
375 FILE *file;
376 tree decl ATTRIBUTE_UNUSED;
377 const char *name;
378 int size ATTRIBUTE_UNUSED, rounded;
380 ASM_GLOBALIZE_LABEL (file, name);
381 bss_section ();
382 #ifdef ASM_DECLARE_OBJECT_NAME
383 last_assemble_variable_decl = decl;
384 ASM_DECLARE_OBJECT_NAME (file, name, decl);
385 #else
386 /* Standard thing is just output label for the object. */
387 ASM_OUTPUT_LABEL (file, name);
388 #endif /* ASM_DECLARE_OBJECT_NAME */
389 ASM_OUTPUT_SKIP (file, rounded);
392 #endif
394 #ifdef ASM_OUTPUT_ALIGNED_BSS
396 /* Utility function for targets to use in implementing
397 ASM_OUTPUT_ALIGNED_BSS.
398 ??? It is believed that this function will work in most cases so such
399 support is localized here. */
401 static void
402 asm_output_aligned_bss (file, decl, name, size, align)
403 FILE *file;
404 tree decl;
405 const char *name;
406 int size, align;
408 ASM_GLOBALIZE_LABEL (file, name);
409 bss_section ();
410 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
411 #ifdef ASM_DECLARE_OBJECT_NAME
412 last_assemble_variable_decl = decl;
413 ASM_DECLARE_OBJECT_NAME (file, name, decl);
414 #else
415 /* Standard thing is just output label for the object. */
416 ASM_OUTPUT_LABEL (file, name);
417 #endif /* ASM_DECLARE_OBJECT_NAME */
418 ASM_OUTPUT_SKIP (file, size ? size : 1);
421 #endif
423 #endif /* BSS_SECTION_ASM_OP */
425 #ifdef EH_FRAME_SECTION_ASM_OP
426 void
427 eh_frame_section ()
429 if (in_section != in_eh_frame)
431 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
432 in_section = in_eh_frame;
435 #endif
437 /* Switch to the section for function DECL.
439 If DECL is NULL_TREE, switch to the text section.
440 ??? It's not clear that we will ever be passed NULL_TREE, but it's
441 safer to handle it. */
443 void
444 function_section (decl)
445 tree decl;
447 if (decl != NULL_TREE
448 && DECL_SECTION_NAME (decl) != NULL_TREE)
449 named_section (decl, (char *) 0, 0);
450 else
451 text_section ();
454 /* Switch to section for variable DECL.
456 RELOC is the `reloc' argument to SELECT_SECTION. */
458 void
459 variable_section (decl, reloc)
460 tree decl;
461 int reloc;
463 if (IN_NAMED_SECTION (decl))
464 named_section (decl, NULL, reloc);
465 else
467 /* C++ can have const variables that get initialized from constructors,
468 and thus can not be in a readonly section. We prevent this by
469 verifying that the initial value is constant for objects put in a
470 readonly section.
472 error_mark_node is used by the C front end to indicate that the
473 initializer has not been seen yet. In this case, we assume that
474 the initializer must be constant.
476 C++ uses error_mark_node for variables that have complicated
477 initializers, but these variables go in BSS so we won't be called
478 for them. */
480 #ifdef SELECT_SECTION
481 SELECT_SECTION (decl, reloc);
482 #else
483 if (DECL_READONLY_SECTION (decl, reloc))
484 readonly_data_section ();
485 else
486 data_section ();
487 #endif
491 /* Tell assembler to switch to the section for the exception handling
492 table. */
494 void
495 exception_section ()
497 #if defined (EXCEPTION_SECTION)
498 EXCEPTION_SECTION ();
499 #else
500 #ifdef ASM_OUTPUT_SECTION_NAME
501 named_section (NULL_TREE, ".gcc_except_table", 0);
502 #else
503 if (flag_pic)
504 data_section ();
505 else
506 readonly_data_section ();
507 #endif
508 #endif
511 /* Create the rtl to represent a function, for a function definition.
512 DECL is a FUNCTION_DECL node which describes which function.
513 The rtl is stored into DECL. */
515 void
516 make_function_rtl (decl)
517 tree decl;
519 const char *name;
520 const char *new_name;
522 if (DECL_RTL (decl) != 0)
524 /* ??? Another way to do this would be to do what halfpic.c does
525 and maintain a hashed table of such critters. */
526 /* ??? Another way to do this would be to pass a flag bit to
527 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
528 /* Let the target reassign the RTL if it wants.
529 This is necessary, for example, when one machine specific
530 decl attribute overrides another. */
531 #ifdef REDO_SECTION_INFO_P
532 if (REDO_SECTION_INFO_P (decl))
533 ENCODE_SECTION_INFO (decl);
534 #endif
535 return;
538 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
539 new_name = name;
541 /* Rename a nested function to avoid conflicts, unless it's a member of
542 a local class, in which case the class name is already unique. */
543 if (decl_function_context (decl) != 0
544 && ! TYPE_P (DECL_CONTEXT (decl))
545 && DECL_INITIAL (decl) != 0
546 && DECL_RTL (decl) == 0)
548 char *label;
549 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
550 var_labelno++;
551 new_name = label;
553 /* When -fprefix-function-name is used, every function name is
554 prefixed. Even static functions are prefixed because they
555 could be declared latter. Note that a nested function name
556 is not prefixed. */
557 else if (flag_prefix_function_name)
559 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
560 char *pname;
562 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
563 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
564 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
565 new_name = pname;
568 if (name != new_name)
570 DECL_ASSEMBLER_NAME (decl) = get_identifier (new_name);
571 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
574 DECL_RTL (decl)
575 = gen_rtx_MEM (DECL_MODE (decl),
576 gen_rtx_SYMBOL_REF (Pmode, name));
578 /* Optionally set flags or add text to the name to record
579 information such as that it is a function name. If the name
580 is changed, the macro ASM_OUTPUT_LABELREF will have to know
581 how to strip this information. */
582 #ifdef ENCODE_SECTION_INFO
583 ENCODE_SECTION_INFO (decl);
584 #endif
588 /* Given NAME, a putative register name, discard any customary prefixes. */
590 static const char *
591 strip_reg_name (name)
592 const char *name;
594 #ifdef REGISTER_PREFIX
595 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
596 name += strlen (REGISTER_PREFIX);
597 #endif
598 if (name[0] == '%' || name[0] == '#')
599 name++;
600 return name;
603 /* Decode an `asm' spec for a declaration as a register name.
604 Return the register number, or -1 if nothing specified,
605 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
606 or -3 if ASMSPEC is `cc' and is not recognized,
607 or -4 if ASMSPEC is `memory' and is not recognized.
608 Accept an exact spelling or a decimal number.
609 Prefixes such as % are optional. */
612 decode_reg_name (asmspec)
613 const char *asmspec;
615 if (asmspec != 0)
617 int i;
619 /* Get rid of confusing prefixes. */
620 asmspec = strip_reg_name (asmspec);
622 /* Allow a decimal number as a "register name". */
623 for (i = strlen (asmspec) - 1; i >= 0; i--)
624 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
625 break;
626 if (asmspec[0] != 0 && i < 0)
628 i = atoi (asmspec);
629 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
630 return i;
631 else
632 return -2;
635 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
636 if (reg_names[i][0]
637 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
638 return i;
640 #ifdef ADDITIONAL_REGISTER_NAMES
642 static struct { const char *name; int number; } table[]
643 = ADDITIONAL_REGISTER_NAMES;
645 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
646 if (! strcmp (asmspec, table[i].name))
647 return table[i].number;
649 #endif /* ADDITIONAL_REGISTER_NAMES */
651 if (!strcmp (asmspec, "memory"))
652 return -4;
654 if (!strcmp (asmspec, "cc"))
655 return -3;
657 return -2;
660 return -1;
663 /* Create the DECL_RTL for a declaration for a static or external variable
664 or static or external function.
665 ASMSPEC, if not 0, is the string which the user specified
666 as the assembler symbol name.
667 TOP_LEVEL is nonzero if this is a file-scope variable.
669 This is never called for PARM_DECL nodes. */
671 void
672 make_decl_rtl (decl, asmspec, top_level)
673 tree decl;
674 const char *asmspec;
675 int top_level;
677 const char *name = 0;
678 const char *new_name = 0;
679 int reg_number;
681 /* For a duplicate declaration, we can be called twice on the
682 same DECL node. Don't discard the RTL already made. */
683 if (DECL_RTL (decl) != 0)
685 /* If the old RTL had the wrong mode, fix the mode. */
686 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
688 rtx rtl = DECL_RTL (decl);
689 PUT_MODE (rtl, DECL_MODE (decl));
692 /* ??? Another way to do this would be to do what halfpic.c does
693 and maintain a hashed table of such critters. */
694 /* ??? Another way to do this would be to pass a flag bit to
695 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
696 /* Let the target reassign the RTL if it wants.
697 This is necessary, for example, when one machine specific
698 decl attribute overrides another. */
699 #ifdef REDO_SECTION_INFO_P
700 if (REDO_SECTION_INFO_P (decl))
701 ENCODE_SECTION_INFO (decl);
702 #endif
703 return;
706 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
708 reg_number = decode_reg_name (asmspec);
709 if (reg_number == -2)
711 /* ASMSPEC is given, and not the name of a register. Mark the
712 name with a star so assemble_name won't munge it. */
713 char *starred = alloca (strlen (asmspec) + 2);
714 starred[0] = '*';
715 strcpy (starred + 1, asmspec);
716 new_name = starred;
719 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
721 /* First detect errors in declaring global registers. */
722 if (reg_number == -1)
723 error_with_decl (decl, "register name not specified for `%s'");
724 else if (reg_number < 0)
725 error_with_decl (decl, "invalid register name for `%s'");
726 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
727 error_with_decl (decl,
728 "data type of `%s' isn't suitable for a register");
729 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
730 error_with_decl (decl,
731 "register specified for `%s' isn't suitable for data type");
732 /* Now handle properly declared static register variables. */
733 else
735 int nregs;
737 if (DECL_INITIAL (decl) != 0 && top_level)
739 DECL_INITIAL (decl) = 0;
740 error ("global register variable has initial value");
742 if (TREE_THIS_VOLATILE (decl))
743 warning ("volatile register variables don't work as you might wish");
745 /* If the user specified one of the eliminables registers here,
746 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
747 confused with that register and be eliminated. Although this
748 usage is somewhat suspect, we nevertheless use the following
749 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
751 DECL_RTL (decl)
752 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
753 REGNO (DECL_RTL (decl)) = reg_number;
754 REG_USERVAR_P (DECL_RTL (decl)) = 1;
756 if (top_level)
758 /* Make this register global, so not usable for anything
759 else. */
760 #ifdef ASM_DECLARE_REGISTER_GLOBAL
761 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
762 #endif
763 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
764 while (nregs > 0)
765 globalize_reg (reg_number + --nregs);
768 /* As a register variable, it has no section. */
769 return;
773 /* Now handle ordinary static variables and functions (in memory).
774 Also handle vars declared register invalidly. */
776 if (reg_number >= 0 || reg_number == -3)
777 error_with_decl (decl,
778 "register name given for non-register variable `%s'");
780 /* Specifying a section attribute on a variable forces it into a
781 non-.bss section, and thus it cannot be common. */
782 if (TREE_CODE (decl) == VAR_DECL
783 && DECL_SECTION_NAME (decl) != NULL_TREE
784 && DECL_INITIAL (decl) == NULL_TREE
785 && DECL_COMMON (decl))
786 DECL_COMMON (decl) = 0;
788 /* Can't use just the variable's own name for a variable
789 whose scope is less than the whole file, unless it's a member
790 of a local class (which will already be unambiguous).
791 Concatenate a distinguishing number. */
792 if (!top_level && !TREE_PUBLIC (decl)
793 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
794 && asmspec == 0)
796 char *label;
797 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
798 var_labelno++;
799 new_name = label;
802 /* When -fprefix-function-name is used, the functions
803 names are prefixed. Only nested function names are not
804 prefixed. */
805 else if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
807 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
808 char *pname;
810 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
811 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
812 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
813 new_name = pname;
816 if (name != new_name)
818 DECL_ASSEMBLER_NAME (decl) = get_identifier (new_name);
819 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
822 /* If this variable is to be treated as volatile, show its
823 tree node has side effects. */
824 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
825 && TREE_PUBLIC (decl))
826 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
827 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
828 TREE_SIDE_EFFECTS (decl) = 1;
830 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
831 gen_rtx_SYMBOL_REF (Pmode, name));
832 if (TREE_CODE (decl) != FUNCTION_DECL)
833 set_mem_attributes (DECL_RTL (decl), decl, 1);
835 /* Optionally set flags or add text to the name to record information
836 such as that it is a function name.
837 If the name is changed, the macro ASM_OUTPUT_LABELREF
838 will have to know how to strip this information. */
839 #ifdef ENCODE_SECTION_INFO
840 ENCODE_SECTION_INFO (decl);
841 #endif
844 /* Make the rtl for variable VAR be volatile.
845 Use this only for static variables. */
847 void
848 make_var_volatile (var)
849 tree var;
851 if (GET_CODE (DECL_RTL (var)) != MEM)
852 abort ();
854 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
857 /* Output alignment directive to align for constant expression EXP. */
859 void
860 assemble_constant_align (exp)
861 tree exp;
863 int align;
865 /* Align the location counter as required by EXP's data type. */
866 align = TYPE_ALIGN (TREE_TYPE (exp));
867 #ifdef CONSTANT_ALIGNMENT
868 align = CONSTANT_ALIGNMENT (exp, align);
869 #endif
871 if (align > BITS_PER_UNIT)
872 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
875 /* Output a string of literal assembler code
876 for an `asm' keyword used between functions. */
878 void
879 assemble_asm (string)
880 tree string;
882 app_enable ();
884 if (TREE_CODE (string) == ADDR_EXPR)
885 string = TREE_OPERAND (string, 0);
887 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
890 #if 0 /* This should no longer be needed, because
891 flag_gnu_linker should be 0 on these systems,
892 which should prevent any output
893 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
894 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
895 #ifndef ASM_OUTPUT_CONSTRUCTOR
896 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
897 #endif
898 #ifndef ASM_OUTPUT_DESTRUCTOR
899 #define ASM_OUTPUT_DESTRUCTOR(file, name)
900 #endif
901 #endif
902 #endif /* 0 */
904 /* Record an element in the table of global destructors.
905 How this is done depends on what sort of assembler and linker
906 are in use.
908 NAME should be the name of a global function to be called
909 at exit time. This name is output using assemble_name. */
911 void
912 assemble_destructor (name)
913 const char *name;
915 #ifdef ASM_OUTPUT_DESTRUCTOR
916 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
917 #else
918 if (flag_gnu_linker)
920 /* Now tell GNU LD that this is part of the static destructor set. */
921 /* This code works for any machine provided you use GNU as/ld. */
922 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
923 assemble_name (asm_out_file, name);
924 fputc ('\n', asm_out_file);
926 #endif
929 /* Likewise for global constructors. */
931 void
932 assemble_constructor (name)
933 const char *name;
935 #ifdef ASM_OUTPUT_CONSTRUCTOR
936 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
937 #else
938 if (flag_gnu_linker)
940 /* Now tell GNU LD that this is part of the static constructor set. */
941 /* This code works for any machine provided you use GNU as/ld. */
942 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
943 assemble_name (asm_out_file, name);
944 fputc ('\n', asm_out_file);
946 #endif
949 /* Likewise for entries we want to record for garbage collection.
950 Garbage collection is still under development. */
952 void
953 assemble_gc_entry (name)
954 const char *name;
956 #ifdef ASM_OUTPUT_GC_ENTRY
957 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
958 #else
959 if (flag_gnu_linker)
961 /* Now tell GNU LD that this is part of the static constructor set. */
962 fprintf (asm_out_file, "%s\"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
963 assemble_name (asm_out_file, name);
964 fputc ('\n', asm_out_file);
966 #endif
969 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
970 a non-zero value if the constant pool should be output before the
971 start of the function, or a zero value if the pool should output
972 after the end of the function. The default is to put it before the
973 start. */
975 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
976 #define CONSTANT_POOL_BEFORE_FUNCTION 1
977 #endif
979 /* Output assembler code for the constant pool of a function and associated
980 with defining the name of the function. DECL describes the function.
981 NAME is the function's name. For the constant pool, we use the current
982 constant pool data. */
984 void
985 assemble_start_function (decl, fnname)
986 tree decl;
987 const char *fnname;
989 int align;
991 /* The following code does not need preprocessing in the assembler. */
993 app_disable ();
995 if (CONSTANT_POOL_BEFORE_FUNCTION)
996 output_constant_pool (fnname, decl);
998 #ifdef ASM_OUTPUT_SECTION_NAME
999 /* If the function is to be put in its own section and it's not in a section
1000 already, indicate so. */
1001 if ((flag_function_sections
1002 && DECL_SECTION_NAME (decl) == NULL_TREE)
1003 || UNIQUE_SECTION_P (decl))
1004 UNIQUE_SECTION (decl, 0);
1005 #endif
1007 function_section (decl);
1009 /* Tell assembler to move to target machine's alignment for functions. */
1010 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1011 if (align > 0)
1012 ASM_OUTPUT_ALIGN (asm_out_file, align);
1014 /* Handle a user-specified function alignment.
1015 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1016 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1017 if (align_functions_log > align)
1019 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1020 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1021 align_functions_log, align_functions-1);
1022 #else
1023 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1024 #endif
1027 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1028 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1029 #endif
1031 #ifdef SDB_DEBUGGING_INFO
1032 /* Output SDB definition of the function. */
1033 if (write_symbols == SDB_DEBUG)
1034 sdbout_mark_begin_function ();
1035 #endif
1037 #ifdef DBX_DEBUGGING_INFO
1038 /* Output DBX definition of the function. */
1039 if (write_symbols == DBX_DEBUG)
1040 dbxout_begin_function (decl);
1041 #endif
1043 /* Make function name accessible from other files, if appropriate. */
1045 if (TREE_PUBLIC (decl))
1047 if (! first_global_object_name)
1049 const char *p;
1050 char *name;
1052 STRIP_NAME_ENCODING (p, fnname);
1053 name = permalloc (strlen (p) + 1);
1054 strcpy (name, p);
1056 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1057 first_global_object_name = name;
1058 else
1059 weak_global_object_name = name;
1062 #ifdef ASM_WEAKEN_LABEL
1063 if (DECL_WEAK (decl))
1065 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1066 /* Remove this function from the pending weak list so that
1067 we do not emit multiple .weak directives for it. */
1068 remove_from_pending_weak_list
1069 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1071 else
1072 #endif
1073 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1076 /* Do any machine/system dependent processing of the function name */
1077 #ifdef ASM_DECLARE_FUNCTION_NAME
1078 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1079 #else
1080 /* Standard thing is just output label for the function. */
1081 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1082 #endif /* ASM_DECLARE_FUNCTION_NAME */
1085 /* Output assembler code associated with defining the size of the
1086 function. DECL describes the function. NAME is the function's name. */
1088 void
1089 assemble_end_function (decl, fnname)
1090 tree decl;
1091 const char *fnname;
1093 #ifdef ASM_DECLARE_FUNCTION_SIZE
1094 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1095 #endif
1096 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1098 output_constant_pool (fnname, decl);
1099 function_section (decl); /* need to switch back */
1102 /* Output any constants which should appear after the function. */
1103 output_after_function_constants ();
1106 /* Assemble code to leave SIZE bytes of zeros. */
1108 void
1109 assemble_zeros (size)
1110 int size;
1112 /* Do no output if -fsyntax-only. */
1113 if (flag_syntax_only)
1114 return;
1116 #ifdef ASM_NO_SKIP_IN_TEXT
1117 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1118 so we must output 0s explicitly in the text section. */
1119 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1121 int i;
1123 for (i = 0; i < size - 20; i += 20)
1125 #ifdef ASM_BYTE_OP
1126 fprintf (asm_out_file,
1127 "%s0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
1128 #else
1129 fprintf (asm_out_file,
1130 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1131 #endif
1133 if (i < size)
1135 #ifdef ASM_BYTE_OP
1136 fprintf (asm_out_file, "%s0", ASM_BYTE_OP);
1137 #else
1138 fprintf (asm_out_file, "\tbyte 0");
1139 #endif
1140 i++;
1141 for (; i < size; i++)
1142 fprintf (asm_out_file, ",0");
1143 fprintf (asm_out_file, "\n");
1146 else
1147 #endif
1148 if (size > 0)
1149 ASM_OUTPUT_SKIP (asm_out_file, size);
1152 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1154 void
1155 assemble_align (align)
1156 int align;
1158 if (align > BITS_PER_UNIT)
1159 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1162 /* Assemble a string constant with the specified C string as contents. */
1164 void
1165 assemble_string (p, size)
1166 const char *p;
1167 int size;
1169 int pos = 0;
1170 int maximum = 2000;
1172 /* If the string is very long, split it up. */
1174 while (pos < size)
1176 int thissize = size - pos;
1177 if (thissize > maximum)
1178 thissize = maximum;
1180 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1182 pos += thissize;
1183 p += thissize;
1188 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1189 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1190 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1191 #else
1192 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1193 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1194 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1195 #else
1196 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1197 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1198 #endif
1199 #endif
1201 #if defined ASM_OUTPUT_ALIGNED_BSS
1202 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1203 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1204 #else
1205 #if defined ASM_OUTPUT_BSS
1206 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1207 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1208 #else
1209 #undef ASM_EMIT_BSS
1210 #endif
1211 #endif
1213 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1214 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1215 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1216 #else
1217 #if defined ASM_OUTPUT_ALIGNED_COMMON
1218 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1219 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1220 #else
1221 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1222 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1223 #endif
1224 #endif
1226 static void
1227 asm_emit_uninitialised (decl, name, size, rounded)
1228 tree decl;
1229 const char * name;
1230 int size ATTRIBUTE_UNUSED;
1231 int rounded ATTRIBUTE_UNUSED;
1233 enum
1235 asm_dest_common,
1236 asm_dest_bss,
1237 asm_dest_local
1239 destination = asm_dest_local;
1241 if (TREE_PUBLIC (decl))
1243 #if defined ASM_EMIT_BSS
1244 if (! DECL_COMMON (decl))
1245 destination = asm_dest_bss;
1246 else
1247 #endif
1248 destination = asm_dest_common;
1251 if (flag_shared_data)
1253 switch (destination)
1255 #ifdef ASM_OUTPUT_SHARED_BSS
1256 case asm_dest_bss:
1257 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1258 return;
1259 #endif
1260 #ifdef ASM_OUTPUT_SHARED_COMMON
1261 case asm_dest_common:
1262 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1263 return;
1264 #endif
1265 #ifdef ASM_OUTPUT_SHARED_LOCAL
1266 case asm_dest_local:
1267 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1268 return;
1269 #endif
1270 default:
1271 break;
1275 #ifdef ASM_OUTPUT_SECTION_NAME
1276 /* We already know that DECL_SECTION_NAME() == NULL. */
1277 if (flag_data_sections != 0 || UNIQUE_SECTION_P (decl))
1278 UNIQUE_SECTION (decl, 0);
1279 #endif
1281 switch (destination)
1283 #ifdef ASM_EMIT_BSS
1284 case asm_dest_bss:
1285 ASM_EMIT_BSS (decl, name, size, rounded);
1286 break;
1287 #endif
1288 case asm_dest_common:
1289 ASM_EMIT_COMMON (decl, name, size, rounded);
1290 break;
1291 case asm_dest_local:
1292 ASM_EMIT_LOCAL (decl, name, size, rounded);
1293 break;
1294 default:
1295 abort ();
1298 return;
1301 /* Assemble everything that is needed for a variable or function declaration.
1302 Not used for automatic variables, and not used for function definitions.
1303 Should not be called for variables of incomplete structure type.
1305 TOP_LEVEL is nonzero if this variable has file scope.
1306 AT_END is nonzero if this is the special handling, at end of compilation,
1307 to define things that have had only tentative definitions.
1308 DONT_OUTPUT_DATA if nonzero means don't actually output the
1309 initial value (that will be done by the caller). */
1311 void
1312 assemble_variable (decl, top_level, at_end, dont_output_data)
1313 tree decl;
1314 int top_level ATTRIBUTE_UNUSED;
1315 int at_end ATTRIBUTE_UNUSED;
1316 int dont_output_data;
1318 register const char *name;
1319 unsigned int align;
1320 int reloc = 0;
1321 enum in_section saved_in_section;
1323 last_assemble_variable_decl = 0;
1325 if (GET_CODE (DECL_RTL (decl)) == REG)
1327 /* Do output symbol info for global register variables, but do nothing
1328 else for them. */
1330 if (TREE_ASM_WRITTEN (decl))
1331 return;
1332 TREE_ASM_WRITTEN (decl) = 1;
1334 /* Do no output if -fsyntax-only. */
1335 if (flag_syntax_only)
1336 return;
1338 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1339 /* File-scope global variables are output here. */
1340 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1341 && top_level)
1342 dbxout_symbol (decl, 0);
1343 #endif
1344 #ifdef SDB_DEBUGGING_INFO
1345 if (write_symbols == SDB_DEBUG && top_level
1346 /* Leave initialized global vars for end of compilation;
1347 see comment in compile_file. */
1348 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1349 sdbout_symbol (decl, 0);
1350 #endif
1352 /* Don't output any DWARF debugging information for variables here.
1353 In the case of local variables, the information for them is output
1354 when we do our recursive traversal of the tree representation for
1355 the entire containing function. In the case of file-scope variables,
1356 we output information for all of them at the very end of compilation
1357 while we are doing our final traversal of the chain of file-scope
1358 declarations. */
1360 return;
1363 /* Normally no need to say anything here for external references,
1364 since assemble_external is called by the language-specific code
1365 when a declaration is first seen. */
1367 if (DECL_EXTERNAL (decl))
1368 return;
1370 /* Output no assembler code for a function declaration.
1371 Only definitions of functions output anything. */
1373 if (TREE_CODE (decl) == FUNCTION_DECL)
1374 return;
1376 /* If type was incomplete when the variable was declared,
1377 see if it is complete now. */
1379 if (DECL_SIZE (decl) == 0)
1380 layout_decl (decl, 0);
1382 /* Still incomplete => don't allocate it; treat the tentative defn
1383 (which is what it must have been) as an `extern' reference. */
1385 if (!dont_output_data && DECL_SIZE (decl) == 0)
1387 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1388 DECL_SOURCE_LINE (decl),
1389 "storage size of `%s' isn't known",
1390 IDENTIFIER_POINTER (DECL_NAME (decl)));
1391 TREE_ASM_WRITTEN (decl) = 1;
1392 return;
1395 /* The first declaration of a variable that comes through this function
1396 decides whether it is global (in C, has external linkage)
1397 or local (in C, has internal linkage). So do nothing more
1398 if this function has already run. */
1400 if (TREE_ASM_WRITTEN (decl))
1401 return;
1403 TREE_ASM_WRITTEN (decl) = 1;
1405 /* Do no output if -fsyntax-only. */
1406 if (flag_syntax_only)
1407 return;
1409 app_disable ();
1411 if (! dont_output_data
1412 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1414 error_with_decl (decl, "size of variable `%s' is too large");
1415 goto finish;
1418 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1419 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1420 && ! first_global_object_name
1421 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1422 || DECL_INITIAL (decl) == error_mark_node))
1423 && ! DECL_WEAK (decl)
1424 && ! DECL_ONE_ONLY (decl))
1426 const char *p;
1427 char *xname;
1429 STRIP_NAME_ENCODING (p, name);
1430 xname = permalloc (strlen (p) + 1);
1431 strcpy (xname, p);
1432 first_global_object_name = xname;
1435 /* Compute the alignment of this data. */
1437 align = DECL_ALIGN (decl);
1439 /* In the case for initialing an array whose length isn't specified,
1440 where we have not yet been able to do the layout,
1441 figure out the proper alignment now. */
1442 if (dont_output_data && DECL_SIZE (decl) == 0
1443 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1444 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1446 /* Some object file formats have a maximum alignment which they support.
1447 In particular, a.out format supports a maximum alignment of 4. */
1448 #ifndef MAX_OFILE_ALIGNMENT
1449 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1450 #endif
1451 if (align > MAX_OFILE_ALIGNMENT)
1453 warning_with_decl (decl,
1454 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1455 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1456 align = MAX_OFILE_ALIGNMENT;
1459 /* On some machines, it is good to increase alignment sometimes. */
1460 #ifdef DATA_ALIGNMENT
1461 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1462 #endif
1463 #ifdef CONSTANT_ALIGNMENT
1464 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1465 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1466 #endif
1468 /* Reset the alignment in case we have made it tighter, so we can benefit
1469 from it in get_pointer_alignment. */
1470 DECL_ALIGN (decl) = align;
1472 /* Handle uninitialized definitions. */
1474 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1475 /* If the target can't output uninitialized but not common global data
1476 in .bss, then we have to use .data. */
1477 #if ! defined ASM_EMIT_BSS
1478 && DECL_COMMON (decl)
1479 #endif
1480 && DECL_SECTION_NAME (decl) == NULL_TREE
1481 && ! dont_output_data)
1483 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1484 unsigned HOST_WIDE_INT rounded = size;
1486 /* Don't allocate zero bytes of common,
1487 since that means "undefined external" in the linker. */
1488 if (size == 0)
1489 rounded = 1;
1491 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1492 so that each uninitialized object starts on such a boundary. */
1493 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1494 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1495 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1497 /* Don't continue this line--convex cc version 4.1 would lose. */
1498 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1499 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1500 warning_with_decl
1501 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1502 #endif
1504 #ifdef DBX_DEBUGGING_INFO
1505 /* File-scope global variables are output here. */
1506 if (write_symbols == DBX_DEBUG && top_level)
1507 dbxout_symbol (decl, 0);
1508 #endif
1509 #ifdef SDB_DEBUGGING_INFO
1510 if (write_symbols == SDB_DEBUG && top_level
1511 /* Leave initialized global vars for end of compilation;
1512 see comment in compile_file. */
1513 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1514 sdbout_symbol (decl, 0);
1515 #endif
1517 /* Don't output any DWARF debugging information for variables here.
1518 In the case of local variables, the information for them is output
1519 when we do our recursive traversal of the tree representation for
1520 the entire containing function. In the case of file-scope variables,
1521 we output information for all of them at the very end of compilation
1522 while we are doing our final traversal of the chain of file-scope
1523 declarations. */
1525 #if 0 /* ??? We should either delete this or add a comment describing what
1526 it was intended to do and why we shouldn't delete it. */
1527 if (flag_shared_data)
1528 data_section ();
1529 #endif
1530 asm_emit_uninitialised (decl, name, size, rounded);
1532 goto finish;
1535 /* Handle initialized definitions.
1536 Also handle uninitialized global definitions if -fno-common and the
1537 target doesn't support ASM_OUTPUT_BSS. */
1539 /* First make the assembler name(s) global if appropriate. */
1540 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1542 #ifdef ASM_WEAKEN_LABEL
1543 if (DECL_WEAK (decl))
1545 ASM_WEAKEN_LABEL (asm_out_file, name);
1546 /* Remove this variable from the pending weak list so that
1547 we do not emit multiple .weak directives for it. */
1548 remove_from_pending_weak_list
1549 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1551 else
1552 #endif
1553 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1555 #if 0
1556 for (d = equivalents; d; d = TREE_CHAIN (d))
1558 tree e = TREE_VALUE (d);
1559 if (TREE_PUBLIC (e) && DECL_NAME (e))
1560 ASM_GLOBALIZE_LABEL (asm_out_file,
1561 XSTR (XEXP (DECL_RTL (e), 0), 0));
1563 #endif
1565 /* Output any data that we will need to use the address of. */
1566 if (DECL_INITIAL (decl) == error_mark_node)
1567 reloc = contains_pointers_p (TREE_TYPE (decl));
1568 else if (DECL_INITIAL (decl))
1569 reloc = output_addressed_constants (DECL_INITIAL (decl));
1571 #ifdef ASM_OUTPUT_SECTION_NAME
1572 if ((flag_data_sections != 0 && DECL_SECTION_NAME (decl) == NULL_TREE)
1573 || UNIQUE_SECTION_P (decl))
1574 UNIQUE_SECTION (decl, reloc);
1575 #endif
1577 /* Switch to the appropriate section. */
1578 variable_section (decl, reloc);
1580 /* dbxout.c needs to know this. */
1581 if (in_text_section ())
1582 DECL_IN_TEXT_SECTION (decl) = 1;
1584 /* Record current section so we can restore it if dbxout.c clobbers it. */
1585 saved_in_section = in_section;
1587 /* Output the dbx info now that we have chosen the section. */
1589 #ifdef DBX_DEBUGGING_INFO
1590 /* File-scope global variables are output here. */
1591 if (write_symbols == DBX_DEBUG && top_level)
1592 dbxout_symbol (decl, 0);
1593 #endif
1594 #ifdef SDB_DEBUGGING_INFO
1595 if (write_symbols == SDB_DEBUG && top_level
1596 /* Leave initialized global vars for end of compilation;
1597 see comment in compile_file. */
1598 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1599 sdbout_symbol (decl, 0);
1600 #endif
1602 /* Don't output any DWARF debugging information for variables here.
1603 In the case of local variables, the information for them is output
1604 when we do our recursive traversal of the tree representation for
1605 the entire containing function. In the case of file-scope variables,
1606 we output information for all of them at the very end of compilation
1607 while we are doing our final traversal of the chain of file-scope
1608 declarations. */
1610 /* If the debugging output changed sections, reselect the section
1611 that's supposed to be selected. */
1612 if (in_section != saved_in_section)
1613 variable_section (decl, reloc);
1615 /* Output the alignment of this data. */
1616 if (align > BITS_PER_UNIT)
1617 ASM_OUTPUT_ALIGN (asm_out_file,
1618 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1620 /* Do any machine/system dependent processing of the object. */
1621 #ifdef ASM_DECLARE_OBJECT_NAME
1622 last_assemble_variable_decl = decl;
1623 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1624 #else
1625 /* Standard thing is just output label for the object. */
1626 ASM_OUTPUT_LABEL (asm_out_file, name);
1627 #endif /* ASM_DECLARE_OBJECT_NAME */
1629 if (!dont_output_data)
1631 if (DECL_INITIAL (decl))
1632 /* Output the actual data. */
1633 output_constant (DECL_INITIAL (decl),
1634 tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1635 else
1636 /* Leave space for it. */
1637 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1640 finish:
1641 #ifdef XCOFF_DEBUGGING_INFO
1642 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1643 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1644 and `aa' hasn't been output yet, the assembler generates a stab entry with
1645 a value of zero, in addition to creating an unnecessary external entry
1646 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1648 /* File-scope global variables are output here. */
1649 if (write_symbols == XCOFF_DEBUG && top_level)
1651 saved_in_section = in_section;
1653 dbxout_symbol (decl, 0);
1655 if (in_section != saved_in_section)
1656 variable_section (decl, reloc);
1658 #else
1659 /* There must be a statement after a label. */
1661 #endif
1664 /* Return 1 if type TYPE contains any pointers. */
1666 static int
1667 contains_pointers_p (type)
1668 tree type;
1670 switch (TREE_CODE (type))
1672 case POINTER_TYPE:
1673 case REFERENCE_TYPE:
1674 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1675 so I'll play safe and return 1. */
1676 case OFFSET_TYPE:
1677 return 1;
1679 case RECORD_TYPE:
1680 case UNION_TYPE:
1681 case QUAL_UNION_TYPE:
1683 tree fields;
1684 /* For a type that has fields, see if the fields have pointers. */
1685 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1686 if (TREE_CODE (fields) == FIELD_DECL
1687 && contains_pointers_p (TREE_TYPE (fields)))
1688 return 1;
1689 return 0;
1692 case ARRAY_TYPE:
1693 /* An array type contains pointers if its element type does. */
1694 return contains_pointers_p (TREE_TYPE (type));
1696 default:
1697 return 0;
1701 /* Output something to declare an external symbol to the assembler.
1702 (Most assemblers don't need this, so we normally output nothing.)
1703 Do nothing if DECL is not external. */
1705 void
1706 assemble_external (decl)
1707 tree decl ATTRIBUTE_UNUSED;
1709 #ifdef ASM_OUTPUT_EXTERNAL
1710 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1712 rtx rtl = DECL_RTL (decl);
1714 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1715 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1717 /* Some systems do require some output. */
1718 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1719 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1722 #endif
1725 /* Similar, for calling a library function FUN. */
1727 void
1728 assemble_external_libcall (fun)
1729 rtx fun ATTRIBUTE_UNUSED;
1731 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1732 /* Declare library function name external when first used, if nec. */
1733 if (! SYMBOL_REF_USED (fun))
1735 SYMBOL_REF_USED (fun) = 1;
1736 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1738 #endif
1741 /* Declare the label NAME global. */
1743 void
1744 assemble_global (name)
1745 const char *name;
1747 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1750 /* Assemble a label named NAME. */
1752 void
1753 assemble_label (name)
1754 const char *name;
1756 ASM_OUTPUT_LABEL (asm_out_file, name);
1759 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1760 If NAME starts with a *, the rest of NAME is output verbatim.
1761 Otherwise NAME is transformed in an implementation-defined way
1762 (usually by the addition of an underscore).
1763 Many macros in the tm file are defined to call this function. */
1765 void
1766 assemble_name (file, name)
1767 FILE *file;
1768 const char *name;
1770 const char *real_name;
1771 tree id;
1773 STRIP_NAME_ENCODING (real_name, name);
1774 if (flag_prefix_function_name
1775 && ! memcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1776 real_name = real_name + CHKR_PREFIX_SIZE;
1778 id = maybe_get_identifier (real_name);
1779 if (id)
1780 TREE_SYMBOL_REFERENCED (id) = 1;
1782 if (name[0] == '*')
1783 fputs (&name[1], file);
1784 else
1785 ASM_OUTPUT_LABELREF (file, name);
1788 /* Allocate SIZE bytes writable static space with a gensym name
1789 and return an RTX to refer to its address. */
1792 assemble_static_space (size)
1793 int size;
1795 char name[12];
1796 char *namestring;
1797 rtx x;
1799 #if 0
1800 if (flag_shared_data)
1801 data_section ();
1802 #endif
1804 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1805 ++const_labelno;
1806 namestring = ggc_alloc_string (name, -1);
1808 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1810 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1811 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1812 BIGGEST_ALIGNMENT);
1813 #else
1814 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1815 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1816 #else
1818 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1819 so that each uninitialized object starts on such a boundary. */
1820 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1821 int rounded ATTRIBUTE_UNUSED
1822 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1823 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1824 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1825 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1827 #endif
1828 #endif
1829 return x;
1832 /* Assemble the static constant template for function entry trampolines.
1833 This is done at most once per compilation.
1834 Returns an RTX for the address of the template. */
1836 #ifdef TRAMPOLINE_TEMPLATE
1838 assemble_trampoline_template ()
1840 char label[256];
1841 char *name;
1842 int align;
1844 /* By default, put trampoline templates in read-only data section. */
1846 #ifdef TRAMPOLINE_SECTION
1847 TRAMPOLINE_SECTION ();
1848 #else
1849 readonly_data_section ();
1850 #endif
1852 /* Write the assembler code to define one. */
1853 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1854 if (align > 0)
1855 ASM_OUTPUT_ALIGN (asm_out_file, align);
1857 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1858 TRAMPOLINE_TEMPLATE (asm_out_file);
1860 /* Record the rtl to refer to it. */
1861 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1862 name = ggc_alloc_string (label, -1);
1863 return gen_rtx_SYMBOL_REF (Pmode, name);
1865 #endif
1867 /* Assemble the integer constant X into an object of SIZE bytes.
1868 X must be either a CONST_INT or CONST_DOUBLE.
1870 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1871 non-zero, abort if we can't output the constant. */
1874 assemble_integer (x, size, force)
1875 rtx x;
1876 int size;
1877 int force;
1879 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1880 ASM_OUTPUT... macros. */
1882 switch (size)
1884 #ifdef ASM_OUTPUT_CHAR
1885 case 1:
1886 ASM_OUTPUT_CHAR (asm_out_file, x);
1887 return 1;
1888 #endif
1890 #ifdef ASM_OUTPUT_SHORT
1891 case 2:
1892 ASM_OUTPUT_SHORT (asm_out_file, x);
1893 return 1;
1894 #endif
1896 #ifdef ASM_OUTPUT_INT
1897 case 4:
1898 ASM_OUTPUT_INT (asm_out_file, x);
1899 return 1;
1900 #endif
1902 #ifdef ASM_OUTPUT_DOUBLE_INT
1903 case 8:
1904 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1905 return 1;
1906 #endif
1908 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1909 case 16:
1910 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1911 return 1;
1912 #endif
1915 /* If we couldn't do it that way, there are two other possibilities: First,
1916 if the machine can output an explicit byte and this is a 1 byte constant,
1917 we can use ASM_OUTPUT_BYTE. */
1919 #ifdef ASM_OUTPUT_BYTE
1920 if (size == 1 && GET_CODE (x) == CONST_INT)
1922 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1923 return 1;
1925 #endif
1927 /* Finally, if SIZE is larger than a single word, try to output the constant
1928 one word at a time. */
1930 if (size > UNITS_PER_WORD)
1932 int i;
1933 enum machine_mode mode
1934 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1935 rtx word;
1937 for (i = 0; i < size / UNITS_PER_WORD; i++)
1939 word = operand_subword (x, i, 0, mode);
1941 if (word == 0)
1942 break;
1944 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1945 break;
1948 if (i == size / UNITS_PER_WORD)
1949 return 1;
1950 /* If we output at least one word and then could not finish,
1951 there is no valid way to continue. */
1952 if (i > 0)
1953 abort ();
1956 if (force)
1957 abort ();
1959 return 0;
1962 /* Assemble the floating-point constant D into an object of size MODE. */
1964 void
1965 assemble_real (d, mode)
1966 REAL_VALUE_TYPE d;
1967 enum machine_mode mode;
1969 jmp_buf output_constant_handler;
1971 if (setjmp (output_constant_handler))
1973 error ("floating point trap outputting a constant");
1974 #ifdef REAL_IS_NOT_DOUBLE
1975 memset ((char *) &d, 0, sizeof d);
1976 d = dconst0;
1977 #else
1978 d = 0;
1979 #endif
1982 set_float_handler (output_constant_handler);
1984 switch (mode)
1986 #ifdef ASM_OUTPUT_BYTE_FLOAT
1987 case QFmode:
1988 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1989 break;
1990 #endif
1991 #ifdef ASM_OUTPUT_SHORT_FLOAT
1992 case HFmode:
1993 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1994 break;
1995 #endif
1996 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1997 case TQFmode:
1998 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1999 break;
2000 #endif
2001 #ifdef ASM_OUTPUT_FLOAT
2002 case SFmode:
2003 ASM_OUTPUT_FLOAT (asm_out_file, d);
2004 break;
2005 #endif
2007 #ifdef ASM_OUTPUT_DOUBLE
2008 case DFmode:
2009 ASM_OUTPUT_DOUBLE (asm_out_file, d);
2010 break;
2011 #endif
2013 #ifdef ASM_OUTPUT_LONG_DOUBLE
2014 case XFmode:
2015 case TFmode:
2016 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
2017 break;
2018 #endif
2020 default:
2021 abort ();
2024 set_float_handler (NULL_PTR);
2027 /* Here we combine duplicate floating constants to make
2028 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2030 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2031 For an integer, I0 is the low-order word and I1 is the high-order word.
2032 For a real number, I0 is the word with the low address
2033 and I1 is the word with the high address. */
2036 immed_double_const (i0, i1, mode)
2037 HOST_WIDE_INT i0, i1;
2038 enum machine_mode mode;
2040 register rtx r;
2042 if (GET_MODE_CLASS (mode) == MODE_INT
2043 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2045 /* We clear out all bits that don't belong in MODE, unless they and our
2046 sign bit are all one. So we get either a reasonable negative value
2047 or a reasonable unsigned value for this mode. */
2048 int width = GET_MODE_BITSIZE (mode);
2049 if (width < HOST_BITS_PER_WIDE_INT
2050 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2051 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2052 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2053 else if (width == HOST_BITS_PER_WIDE_INT
2054 && ! (i1 == ~0 && i0 < 0))
2055 i1 = 0;
2056 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2057 /* We cannot represent this value as a constant. */
2058 abort ();
2060 /* If this would be an entire word for the target, but is not for
2061 the host, then sign-extend on the host so that the number will look
2062 the same way on the host that it would on the target.
2064 For example, when building a 64 bit alpha hosted 32 bit sparc
2065 targeted compiler, then we want the 32 bit unsigned value -1 to be
2066 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2067 The later confuses the sparc backend. */
2069 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2070 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2071 i0 |= ((HOST_WIDE_INT) (-1) << width);
2073 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2075 ??? Strictly speaking, this is wrong if we create a CONST_INT
2076 for a large unsigned constant with the size of MODE being
2077 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2078 wider mode. In that case we will mis-interpret it as a negative
2079 number.
2081 Unfortunately, the only alternative is to make a CONST_DOUBLE
2082 for any constant in any mode if it is an unsigned constant larger
2083 than the maximum signed integer in an int on the host. However,
2084 doing this will break everyone that always expects to see a CONST_INT
2085 for SImode and smaller.
2087 We have always been making CONST_INTs in this case, so nothing new
2088 is being broken. */
2090 if (width <= HOST_BITS_PER_WIDE_INT)
2091 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2093 /* If this integer fits in one word, return a CONST_INT. */
2094 if ((i1 == 0 && i0 >= 0)
2095 || (i1 == ~0 && i0 < 0))
2096 return GEN_INT (i0);
2098 /* We use VOIDmode for integers. */
2099 mode = VOIDmode;
2102 /* Search the chain for an existing CONST_DOUBLE with the right value.
2103 If one is found, return it. */
2104 if (cfun != 0)
2105 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2106 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2107 && GET_MODE (r) == mode)
2108 return r;
2110 /* No; make a new one and add it to the chain. */
2111 r = gen_rtx_CONST_DOUBLE (mode, const0_rtx, i0, i1);
2113 /* Don't touch const_double_chain if not inside any function. */
2114 if (current_function_decl != 0)
2116 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2117 const_double_chain = r;
2120 return r;
2123 /* Return a CONST_DOUBLE for a specified `double' value
2124 and machine mode. */
2127 immed_real_const_1 (d, mode)
2128 REAL_VALUE_TYPE d;
2129 enum machine_mode mode;
2131 union real_extract u;
2132 register rtx r;
2134 /* Get the desired `double' value as a sequence of ints
2135 since that is how they are stored in a CONST_DOUBLE. */
2137 u.d = d;
2139 /* Detect special cases. But be careful we don't use a CONST_DOUBLE
2140 that's from a parent function since it may be in its constant pool. */
2141 if (REAL_VALUES_IDENTICAL (dconst0, d)
2142 && (cfun == 0 || decl_function_context (current_function_decl) == 0))
2143 return CONST0_RTX (mode);
2145 /* Check for NaN first, because some ports (specifically the i386) do not
2146 emit correct ieee-fp code by default, and thus will generate a core
2147 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2148 does a floating point comparison. */
2149 else if ((! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2150 && (cfun == 0
2151 || decl_function_context (current_function_decl) == 0))
2152 return CONST1_RTX (mode);
2154 if (sizeof u == sizeof (HOST_WIDE_INT))
2155 return immed_double_const (u.i[0], 0, mode);
2156 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2157 return immed_double_const (u.i[0], u.i[1], mode);
2159 /* The rest of this function handles the case where
2160 a float value requires more than 2 ints of space.
2161 It will be deleted as dead code on machines that don't need it. */
2163 /* Search the chain for an existing CONST_DOUBLE with the right value.
2164 If one is found, return it. */
2165 if (cfun != 0)
2166 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2167 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2168 && GET_MODE (r) == mode)
2169 return r;
2171 /* No; make a new one and add it to the chain.
2173 We may be called by an optimizer which may be discarding any memory
2174 allocated during its processing (such as combine and loop). However,
2175 we will be leaving this constant on the chain, so we cannot tolerate
2176 freed memory. */
2177 r = rtx_alloc (CONST_DOUBLE);
2178 PUT_MODE (r, mode);
2179 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2181 /* If we aren't inside a function, don't put r on the
2182 const_double_chain. */
2183 if (current_function_decl != 0)
2185 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2186 const_double_chain = r;
2188 else
2189 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2191 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2192 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2193 is only through force_const_mem. */
2195 CONST_DOUBLE_MEM (r) = const0_rtx;
2197 return r;
2200 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2201 which must be a REAL_CST tree node. */
2204 immed_real_const (exp)
2205 tree exp;
2207 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2210 /* At the end of a function, forget the memory-constants
2211 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2212 Also clear out real_constant_chain and clear out all the chain-pointers. */
2214 void
2215 clear_const_double_mem ()
2217 register rtx r, next;
2219 for (r = const_double_chain; r; r = next)
2221 next = CONST_DOUBLE_CHAIN (r);
2222 CONST_DOUBLE_CHAIN (r) = 0;
2223 CONST_DOUBLE_MEM (r) = cc0_rtx;
2225 const_double_chain = 0;
2228 /* Given an expression EXP with a constant value,
2229 reduce it to the sum of an assembler symbol and an integer.
2230 Store them both in the structure *VALUE.
2231 Abort if EXP does not reduce. */
2233 struct addr_const
2235 rtx base;
2236 HOST_WIDE_INT offset;
2239 static void
2240 decode_addr_const (exp, value)
2241 tree exp;
2242 struct addr_const *value;
2244 register tree target = TREE_OPERAND (exp, 0);
2245 register int offset = 0;
2246 register rtx x;
2248 while (1)
2250 if (TREE_CODE (target) == COMPONENT_REF
2251 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2254 offset += int_byte_position (TREE_OPERAND (target, 1));
2255 target = TREE_OPERAND (target, 0);
2257 else if (TREE_CODE (target) == ARRAY_REF)
2259 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2260 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2261 target = TREE_OPERAND (target, 0);
2263 else
2264 break;
2267 switch (TREE_CODE (target))
2269 case VAR_DECL:
2270 case FUNCTION_DECL:
2271 x = DECL_RTL (target);
2272 break;
2274 case LABEL_DECL:
2275 x = gen_rtx_MEM (FUNCTION_MODE,
2276 gen_rtx_LABEL_REF (VOIDmode,
2277 label_rtx (TREE_OPERAND (exp, 0))));
2278 break;
2280 case REAL_CST:
2281 case STRING_CST:
2282 case COMPLEX_CST:
2283 case CONSTRUCTOR:
2284 case INTEGER_CST:
2285 x = TREE_CST_RTL (target);
2286 break;
2288 default:
2289 abort ();
2292 if (GET_CODE (x) != MEM)
2293 abort ();
2294 x = XEXP (x, 0);
2296 value->base = x;
2297 value->offset = offset;
2300 struct rtx_const
2302 #ifdef ONLY_INT_FIELDS
2303 unsigned int kind : 16;
2304 unsigned int mode : 16;
2305 #else
2306 enum kind kind : 16;
2307 enum machine_mode mode : 16;
2308 #endif
2309 union {
2310 union real_extract du;
2311 struct addr_const addr;
2312 struct {HOST_WIDE_INT high, low;} di;
2313 } un;
2316 /* Uniquize all constants that appear in memory.
2317 Each constant in memory thus far output is recorded
2318 in `const_hash_table' with a `struct constant_descriptor'
2319 that contains a polish representation of the value of
2320 the constant.
2322 We cannot store the trees in the hash table
2323 because the trees may be temporary. */
2325 struct constant_descriptor
2327 struct constant_descriptor *next;
2328 char *label;
2329 rtx rtl;
2330 unsigned char contents[1];
2333 #define HASHBITS 30
2334 #define MAX_HASH_TABLE 1009
2335 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2337 /* Mark a const_hash_table descriptor for GC. */
2339 static void
2340 mark_const_hash_entry (ptr)
2341 void *ptr;
2343 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2345 while (desc)
2347 ggc_mark_string ((const char *)desc->label);
2348 ggc_mark_rtx (desc->rtl);
2349 desc = desc->next;
2353 /* Compute a hash code for a constant expression. */
2355 static int
2356 const_hash (exp)
2357 tree exp;
2359 register const char *p;
2360 register int len, hi, i;
2361 register enum tree_code code = TREE_CODE (exp);
2363 /* Either set P and LEN to the address and len of something to hash and
2364 exit the switch or return a value. */
2366 switch (code)
2368 case INTEGER_CST:
2369 p = (char *) &TREE_INT_CST (exp);
2370 len = sizeof TREE_INT_CST (exp);
2371 break;
2373 case REAL_CST:
2374 p = (char *) &TREE_REAL_CST (exp);
2375 len = sizeof TREE_REAL_CST (exp);
2376 break;
2378 case STRING_CST:
2379 p = TREE_STRING_POINTER (exp);
2380 len = TREE_STRING_LENGTH (exp);
2381 break;
2383 case COMPLEX_CST:
2384 return (const_hash (TREE_REALPART (exp)) * 5
2385 + const_hash (TREE_IMAGPART (exp)));
2387 case CONSTRUCTOR:
2388 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2390 char *tmp;
2392 len = int_size_in_bytes (TREE_TYPE (exp));
2393 tmp = (char *) alloca (len);
2394 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2395 p = tmp;
2396 break;
2398 else
2400 register tree link;
2402 /* For record type, include the type in the hashing.
2403 We do not do so for array types
2404 because (1) the sizes of the elements are sufficient
2405 and (2) distinct array types can have the same constructor.
2406 Instead, we include the array size because the constructor could
2407 be shorter. */
2408 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2409 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2410 % MAX_HASH_TABLE;
2411 else
2412 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2413 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2415 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2416 if (TREE_VALUE (link))
2418 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2420 return hi;
2423 case ADDR_EXPR:
2425 struct addr_const value;
2427 decode_addr_const (exp, &value);
2428 if (GET_CODE (value.base) == SYMBOL_REF)
2430 /* Don't hash the address of the SYMBOL_REF;
2431 only use the offset and the symbol name. */
2432 hi = value.offset;
2433 p = XSTR (value.base, 0);
2434 for (i = 0; p[i] != 0; i++)
2435 hi = ((hi * 613) + (unsigned) (p[i]));
2437 else if (GET_CODE (value.base) == LABEL_REF)
2438 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2439 else
2440 abort();
2442 hi &= (1 << HASHBITS) - 1;
2443 hi %= MAX_HASH_TABLE;
2445 return hi;
2447 case PLUS_EXPR:
2448 case MINUS_EXPR:
2449 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2450 + const_hash (TREE_OPERAND (exp, 1)));
2452 case NOP_EXPR:
2453 case CONVERT_EXPR:
2454 case NON_LVALUE_EXPR:
2455 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2457 default:
2458 /* A language specific constant. Just hash the code. */
2459 return code % MAX_HASH_TABLE;
2462 /* Compute hashing function */
2463 hi = len;
2464 for (i = 0; i < len; i++)
2465 hi = ((hi * 613) + (unsigned) (p[i]));
2467 hi &= (1 << HASHBITS) - 1;
2468 hi %= MAX_HASH_TABLE;
2469 return hi;
2472 /* Compare a constant expression EXP with a constant-descriptor DESC.
2473 Return 1 if DESC describes a constant with the same value as EXP. */
2475 static int
2476 compare_constant (exp, desc)
2477 tree exp;
2478 struct constant_descriptor *desc;
2480 return 0 != compare_constant_1 (exp, desc->contents);
2483 /* Compare constant expression EXP with a substring P of a constant descriptor.
2484 If they match, return a pointer to the end of the substring matched.
2485 If they do not match, return 0.
2487 Since descriptors are written in polish prefix notation,
2488 this function can be used recursively to test one operand of EXP
2489 against a subdescriptor, and if it succeeds it returns the
2490 address of the subdescriptor for the next operand. */
2492 static const unsigned char *
2493 compare_constant_1 (exp, p)
2494 tree exp;
2495 const unsigned char *p;
2497 register const unsigned char *strp;
2498 register int len;
2499 register enum tree_code code = TREE_CODE (exp);
2501 if (code != (enum tree_code) *p++)
2502 return 0;
2504 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2505 switch, or return the result of the comparison. */
2507 switch (code)
2509 case INTEGER_CST:
2510 /* Integer constants are the same only if the same width of type. */
2511 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2512 return 0;
2514 strp = (unsigned char *) &TREE_INT_CST (exp);
2515 len = sizeof TREE_INT_CST (exp);
2516 break;
2518 case REAL_CST:
2519 /* Real constants are the same only if the same width of type. */
2520 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2521 return 0;
2523 strp = (unsigned char *) &TREE_REAL_CST (exp);
2524 len = sizeof TREE_REAL_CST (exp);
2525 break;
2527 case STRING_CST:
2528 if (flag_writable_strings)
2529 return 0;
2531 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2532 return 0;
2534 strp = (unsigned char *)TREE_STRING_POINTER (exp);
2535 len = TREE_STRING_LENGTH (exp);
2536 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2537 sizeof TREE_STRING_LENGTH (exp)))
2538 return 0;
2540 p += sizeof TREE_STRING_LENGTH (exp);
2541 break;
2543 case COMPLEX_CST:
2544 p = compare_constant_1 (TREE_REALPART (exp), p);
2545 if (p == 0)
2546 return 0;
2548 return compare_constant_1 (TREE_IMAGPART (exp), p);
2550 case CONSTRUCTOR:
2551 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2553 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2554 unsigned char *tmp = (unsigned char *) alloca (len);
2556 get_set_constructor_bytes (exp, tmp, len);
2557 strp = (unsigned char *) tmp;
2558 if (memcmp ((char *) &xlen, p, sizeof xlen))
2559 return 0;
2561 p += sizeof xlen;
2562 break;
2564 else
2566 register tree link;
2567 int length = list_length (CONSTRUCTOR_ELTS (exp));
2568 tree type;
2569 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2570 int have_purpose = 0;
2572 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2573 if (TREE_PURPOSE (link))
2574 have_purpose = 1;
2576 if (memcmp ((char *) &length, p, sizeof length))
2577 return 0;
2579 p += sizeof length;
2581 /* For record constructors, insist that the types match.
2582 For arrays, just verify both constructors are for arrays.
2583 Then insist that either both or none have any TREE_PURPOSE
2584 values. */
2585 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2586 type = TREE_TYPE (exp);
2587 else
2588 type = 0;
2590 if (memcmp ((char *) &type, p, sizeof type))
2591 return 0;
2593 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2595 if (memcmp ((char *) &mode, p, sizeof mode))
2596 return 0;
2598 p += sizeof mode;
2601 p += sizeof type;
2603 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2604 return 0;
2606 p += sizeof have_purpose;
2608 /* For arrays, insist that the size in bytes match. */
2609 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2611 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2613 if (memcmp ((char *) &size, p, sizeof size))
2614 return 0;
2616 p += sizeof size;
2619 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2621 if (TREE_VALUE (link))
2623 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2624 return 0;
2626 else
2628 tree zero = 0;
2630 if (memcmp ((char *) &zero, p, sizeof zero))
2631 return 0;
2633 p += sizeof zero;
2636 if (TREE_PURPOSE (link)
2637 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2639 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2640 sizeof TREE_PURPOSE (link)))
2641 return 0;
2643 p += sizeof TREE_PURPOSE (link);
2645 else if (TREE_PURPOSE (link))
2647 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2648 return 0;
2650 else if (have_purpose)
2652 int zero = 0;
2654 if (memcmp ((char *) &zero, p, sizeof zero))
2655 return 0;
2657 p += sizeof zero;
2661 return p;
2664 case ADDR_EXPR:
2666 struct addr_const value;
2668 decode_addr_const (exp, &value);
2669 strp = (unsigned char *) &value.offset;
2670 len = sizeof value.offset;
2671 /* Compare the offset. */
2672 while (--len >= 0)
2673 if (*p++ != *strp++)
2674 return 0;
2676 /* Compare symbol name. */
2677 strp = (unsigned char *) XSTR (value.base, 0);
2678 len = strlen ((char *) strp) + 1;
2680 break;
2682 case PLUS_EXPR:
2683 case MINUS_EXPR:
2684 case RANGE_EXPR:
2685 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2686 if (p == 0)
2687 return 0;
2689 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2691 case NOP_EXPR:
2692 case CONVERT_EXPR:
2693 case NON_LVALUE_EXPR:
2694 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2696 default:
2697 if (lang_expand_constant)
2699 exp = (*lang_expand_constant) (exp);
2700 return compare_constant_1 (exp, p);
2702 return 0;
2705 /* Compare constant contents. */
2706 while (--len >= 0)
2707 if (*p++ != *strp++)
2708 return 0;
2710 return p;
2713 /* Construct a constant descriptor for the expression EXP.
2714 It is up to the caller to enter the descriptor in the hash table. */
2716 static struct constant_descriptor *
2717 record_constant (exp)
2718 tree exp;
2720 struct constant_descriptor *next = 0;
2721 char *label = 0;
2722 rtx rtl = 0;
2724 /* Make a struct constant_descriptor. The first three pointers will
2725 be filled in later. Here we just leave space for them. */
2727 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2728 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2729 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2730 record_constant_1 (exp);
2731 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2734 /* Add a description of constant expression EXP
2735 to the object growing in `permanent_obstack'.
2736 No need to return its address; the caller will get that
2737 from the obstack when the object is complete. */
2739 static void
2740 record_constant_1 (exp)
2741 tree exp;
2743 register unsigned char *strp;
2744 register int len;
2745 register enum tree_code code = TREE_CODE (exp);
2747 obstack_1grow (&permanent_obstack, (unsigned int) code);
2749 switch (code)
2751 case INTEGER_CST:
2752 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2753 strp = (unsigned char *) &TREE_INT_CST (exp);
2754 len = sizeof TREE_INT_CST (exp);
2755 break;
2757 case REAL_CST:
2758 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2759 strp = (unsigned char *) &TREE_REAL_CST (exp);
2760 len = sizeof TREE_REAL_CST (exp);
2761 break;
2763 case STRING_CST:
2764 if (flag_writable_strings)
2765 return;
2767 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2768 strp = (unsigned char *) TREE_STRING_POINTER (exp);
2769 len = TREE_STRING_LENGTH (exp);
2770 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2771 sizeof TREE_STRING_LENGTH (exp));
2772 break;
2774 case COMPLEX_CST:
2775 record_constant_1 (TREE_REALPART (exp));
2776 record_constant_1 (TREE_IMAGPART (exp));
2777 return;
2779 case CONSTRUCTOR:
2780 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2782 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2783 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2784 obstack_blank (&permanent_obstack, nbytes);
2785 get_set_constructor_bytes
2786 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2787 nbytes);
2788 return;
2790 else
2792 register tree link;
2793 int length = list_length (CONSTRUCTOR_ELTS (exp));
2794 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2795 tree type;
2796 int have_purpose = 0;
2798 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2799 if (TREE_PURPOSE (link))
2800 have_purpose = 1;
2802 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2804 /* For record constructors, insist that the types match.
2805 For arrays, just verify both constructors are for arrays
2806 of the same mode. Then insist that either both or none
2807 have any TREE_PURPOSE values. */
2808 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2809 type = TREE_TYPE (exp);
2810 else
2811 type = 0;
2813 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2814 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2815 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2817 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2818 sizeof have_purpose);
2820 /* For arrays, insist that the size in bytes match. */
2821 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2823 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2824 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2827 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2829 if (TREE_VALUE (link))
2830 record_constant_1 (TREE_VALUE (link));
2831 else
2833 tree zero = 0;
2835 obstack_grow (&permanent_obstack,
2836 (char *) &zero, sizeof zero);
2839 if (TREE_PURPOSE (link)
2840 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2841 obstack_grow (&permanent_obstack,
2842 (char *) &TREE_PURPOSE (link),
2843 sizeof TREE_PURPOSE (link));
2844 else if (TREE_PURPOSE (link))
2845 record_constant_1 (TREE_PURPOSE (link));
2846 else if (have_purpose)
2848 int zero = 0;
2850 obstack_grow (&permanent_obstack,
2851 (char *) &zero, sizeof zero);
2855 return;
2857 case ADDR_EXPR:
2859 struct addr_const value;
2861 decode_addr_const (exp, &value);
2862 /* Record the offset. */
2863 obstack_grow (&permanent_obstack,
2864 (char *) &value.offset, sizeof value.offset);
2866 switch (GET_CODE (value.base))
2868 case SYMBOL_REF:
2869 /* Record the symbol name. */
2870 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2871 strlen (XSTR (value.base, 0)) + 1);
2872 break;
2873 case LABEL_REF:
2874 /* Record the address of the CODE_LABEL. It may not have
2875 been emitted yet, so it's UID may be zero. But pointer
2876 identity is good enough. */
2877 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
2878 sizeof (rtx));
2879 break;
2880 default:
2881 abort ();
2884 return;
2886 case PLUS_EXPR:
2887 case MINUS_EXPR:
2888 case RANGE_EXPR:
2889 record_constant_1 (TREE_OPERAND (exp, 0));
2890 record_constant_1 (TREE_OPERAND (exp, 1));
2891 return;
2893 case NOP_EXPR:
2894 case CONVERT_EXPR:
2895 case NON_LVALUE_EXPR:
2896 record_constant_1 (TREE_OPERAND (exp, 0));
2897 return;
2899 default:
2900 if (lang_expand_constant)
2902 exp = (*lang_expand_constant) (exp);
2903 record_constant_1 (exp);
2905 return;
2908 /* Record constant contents. */
2909 obstack_grow (&permanent_obstack, strp, len);
2912 /* Record a list of constant expressions that were passed to
2913 output_constant_def but that could not be output right away. */
2915 struct deferred_constant
2917 struct deferred_constant *next;
2918 tree exp;
2919 int reloc;
2920 int labelno;
2923 static struct deferred_constant *deferred_constants;
2925 /* Another list of constants which should be output after the
2926 function. */
2927 static struct deferred_constant *after_function_constants;
2929 /* Nonzero means defer output of addressed subconstants
2930 (i.e., those for which output_constant_def is called.) */
2931 static int defer_addressed_constants_flag;
2933 /* Start deferring output of subconstants. */
2935 void
2936 defer_addressed_constants ()
2938 defer_addressed_constants_flag++;
2941 /* Stop deferring output of subconstants,
2942 and output now all those that have been deferred. */
2944 void
2945 output_deferred_addressed_constants ()
2947 struct deferred_constant *p, *next;
2949 defer_addressed_constants_flag--;
2951 if (defer_addressed_constants_flag > 0)
2952 return;
2954 for (p = deferred_constants; p; p = next)
2956 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2957 next = p->next;
2958 free (p);
2961 deferred_constants = 0;
2964 /* Output any constants which should appear after a function. */
2966 static void
2967 output_after_function_constants ()
2969 struct deferred_constant *p, *next;
2971 for (p = after_function_constants; p; p = next)
2973 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2974 next = p->next;
2975 free (p);
2978 after_function_constants = 0;
2981 /* Make a copy of the whole tree structure for a constant.
2982 This handles the same types of nodes that compare_constant
2983 and record_constant handle. */
2985 static tree
2986 copy_constant (exp)
2987 tree exp;
2989 switch (TREE_CODE (exp))
2991 case ADDR_EXPR:
2992 /* For ADDR_EXPR, we do not want to copy the decl whose address
2993 is requested. We do want to copy constants though. */
2994 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2995 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2996 copy_constant (TREE_OPERAND (exp, 0)));
2997 else
2998 return copy_node (exp);
3000 case INTEGER_CST:
3001 case REAL_CST:
3002 case STRING_CST:
3003 return copy_node (exp);
3005 case COMPLEX_CST:
3006 return build_complex (TREE_TYPE (exp),
3007 copy_constant (TREE_REALPART (exp)),
3008 copy_constant (TREE_IMAGPART (exp)));
3010 case PLUS_EXPR:
3011 case MINUS_EXPR:
3012 return build (TREE_CODE (exp), TREE_TYPE (exp),
3013 copy_constant (TREE_OPERAND (exp, 0)),
3014 copy_constant (TREE_OPERAND (exp, 1)));
3016 case NOP_EXPR:
3017 case CONVERT_EXPR:
3018 case NON_LVALUE_EXPR:
3019 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3020 copy_constant (TREE_OPERAND (exp, 0)));
3022 case CONSTRUCTOR:
3024 tree copy = copy_node (exp);
3025 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3026 tree tail;
3028 CONSTRUCTOR_ELTS (copy) = list;
3029 for (tail = list; tail; tail = TREE_CHAIN (tail))
3030 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3031 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3032 for (tail = list; tail; tail = TREE_CHAIN (tail))
3033 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3035 return copy;
3038 default:
3039 abort ();
3043 /* Return an rtx representing a reference to constant data in memory
3044 for the constant expression EXP.
3046 If assembler code for such a constant has already been output,
3047 return an rtx to refer to it.
3048 Otherwise, output such a constant in memory (or defer it for later)
3049 and generate an rtx for it.
3051 The TREE_CST_RTL of EXP is set up to point to that rtx.
3052 The const_hash_table records which constants already have label strings. */
3055 output_constant_def (exp)
3056 tree exp;
3058 register int hash;
3059 register struct constant_descriptor *desc;
3060 char label[256];
3061 int reloc;
3062 int found = 1;
3064 if (TREE_CST_RTL (exp))
3065 return TREE_CST_RTL (exp);
3067 /* Make sure any other constants whose addresses appear in EXP
3068 are assigned label numbers. */
3070 reloc = output_addressed_constants (exp);
3072 /* Compute hash code of EXP. Search the descriptors for that hash code
3073 to see if any of them describes EXP. If yes, the descriptor records
3074 the label number already assigned. */
3076 hash = const_hash (exp) % MAX_HASH_TABLE;
3078 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3079 if (compare_constant (exp, desc))
3080 break;
3082 if (desc == 0)
3084 /* No constant equal to EXP is known to have been output.
3085 Make a constant descriptor to enter EXP in the hash table.
3086 Assign the label number and record it in the descriptor for
3087 future calls to this function to find. */
3089 /* Create a string containing the label name, in LABEL. */
3090 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3092 desc = record_constant (exp);
3093 desc->next = const_hash_table[hash];
3094 desc->label = ggc_alloc_string (label, -1);
3095 const_hash_table[hash] = desc;
3097 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3098 desc->rtl
3099 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3100 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3102 set_mem_attributes (desc->rtl, exp, 1);
3104 found = 0;
3107 TREE_CST_RTL (exp) = desc->rtl;
3109 /* Optionally set flags or add text to the name to record information
3110 such as that it is a function name. If the name is changed, the macro
3111 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3112 #ifdef ENCODE_SECTION_INFO
3113 ENCODE_SECTION_INFO (exp);
3114 #endif
3116 /* If this is the first time we've seen this particular constant,
3117 output it (or defer its output for later). */
3118 if (! found)
3120 int after_function = 0;
3122 #ifdef CONSTANT_AFTER_FUNCTION_P
3123 if (current_function_decl != 0
3124 && CONSTANT_AFTER_FUNCTION_P (exp))
3125 after_function = 1;
3126 #endif
3128 if (defer_addressed_constants_flag || after_function)
3130 struct deferred_constant *p;
3131 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3133 p->exp = copy_constant (exp);
3134 p->reloc = reloc;
3135 p->labelno = const_labelno++;
3136 if (after_function)
3138 p->next = after_function_constants;
3139 after_function_constants = p;
3141 else
3143 p->next = deferred_constants;
3144 deferred_constants = p;
3147 else
3149 /* Do no output if -fsyntax-only. */
3150 if (! flag_syntax_only)
3151 output_constant_def_contents (exp, reloc, const_labelno);
3152 ++const_labelno;
3156 return TREE_CST_RTL (exp);
3159 /* Now output assembler code to define the label for EXP,
3160 and follow it with the data of EXP. */
3162 static void
3163 output_constant_def_contents (exp, reloc, labelno)
3164 tree exp;
3165 int reloc;
3166 int labelno;
3168 int align;
3170 if (IN_NAMED_SECTION (exp))
3171 named_section (exp, NULL, reloc);
3172 else
3174 /* First switch to text section, except for writable strings. */
3175 #ifdef SELECT_SECTION
3176 SELECT_SECTION (exp, reloc);
3177 #else
3178 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3179 || (flag_pic && reloc))
3180 data_section ();
3181 else
3182 readonly_data_section ();
3183 #endif
3186 /* Align the location counter as required by EXP's data type. */
3187 align = TYPE_ALIGN (TREE_TYPE (exp));
3188 #ifdef CONSTANT_ALIGNMENT
3189 align = CONSTANT_ALIGNMENT (exp, align);
3190 #endif
3192 if (align > BITS_PER_UNIT)
3193 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3195 /* Output the label itself. */
3196 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3198 /* Output the value of EXP. */
3199 output_constant (exp,
3200 (TREE_CODE (exp) == STRING_CST
3201 ? TREE_STRING_LENGTH (exp)
3202 : int_size_in_bytes (TREE_TYPE (exp))));
3206 /* Structure to represent sufficient information about a constant so that
3207 it can be output when the constant pool is output, so that function
3208 integration can be done, and to simplify handling on machines that reference
3209 constant pool as base+displacement. */
3211 struct pool_constant
3213 struct constant_descriptor *desc;
3214 struct pool_constant *next;
3215 enum machine_mode mode;
3216 rtx constant;
3217 int labelno;
3218 int align;
3219 int offset;
3220 int mark;
3223 /* Structure used to maintain hash table mapping symbols used to their
3224 corresponding constants. */
3226 struct pool_sym
3228 char *label;
3229 struct pool_constant *pool;
3230 struct pool_sym *next;
3233 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3234 The argument is XSTR (... , 0) */
3236 #define SYMHASH(LABEL) \
3237 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3239 /* Initialize constant pool hashing for a new function. */
3241 void
3242 init_varasm_status (f)
3243 struct function *f;
3245 struct varasm_status *p;
3246 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3247 f->varasm = p;
3248 p->x_const_rtx_hash_table
3249 = ((struct constant_descriptor **)
3250 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3251 p->x_const_rtx_sym_hash_table
3252 = ((struct pool_sym **)
3253 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_sym *)));
3255 p->x_first_pool = p->x_last_pool = 0;
3256 p->x_pool_offset = 0;
3257 p->x_const_double_chain = 0;
3260 /* Mark PC for GC. */
3262 static void
3263 mark_pool_constant (pc)
3264 struct pool_constant *pc;
3266 while (pc)
3268 ggc_mark (pc);
3269 ggc_mark_rtx (pc->constant);
3270 pc = pc->next;
3274 /* Mark PPS for GC. */
3276 static void
3277 mark_pool_sym_hash_table (pps)
3278 struct pool_sym **pps;
3280 struct pool_sym *ps;
3281 int i;
3283 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3284 for (ps = pps[i]; ps ; ps = ps->next)
3285 ggc_mark_string (ps->label);
3288 /* Mark P for GC. */
3290 void
3291 mark_varasm_status (p)
3292 struct varasm_status *p;
3294 if (p == NULL)
3295 return;
3297 mark_pool_constant (p->x_first_pool);
3298 mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
3299 ggc_mark_rtx (p->x_const_double_chain);
3302 /* Clear out all parts of the state in F that can safely be discarded
3303 after the function has been compiled, to let garbage collection
3304 reclaim the memory. */
3306 void
3307 free_varasm_status (f)
3308 struct function *f;
3310 struct varasm_status *p;
3311 int i;
3313 p = f->varasm;
3315 /* Clear out the hash tables. */
3316 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3318 struct constant_descriptor* cd;
3319 struct pool_sym *ps;
3321 cd = p->x_const_rtx_hash_table[i];
3322 while (cd) {
3323 struct constant_descriptor* next = cd->next;
3324 free (cd);
3325 cd = next;
3328 ps = p->x_const_rtx_sym_hash_table[i];
3329 while (ps) {
3330 struct pool_sym *next = ps->next;
3331 free (ps);
3332 ps = next;
3336 free (p->x_const_rtx_hash_table);
3337 free (p->x_const_rtx_sym_hash_table);
3338 free (p);
3339 f->varasm = NULL;
3342 enum kind { RTX_DOUBLE, RTX_INT };
3344 /* Express an rtx for a constant integer (perhaps symbolic)
3345 as the sum of a symbol or label plus an explicit integer.
3346 They are stored into VALUE. */
3348 static void
3349 decode_rtx_const (mode, x, value)
3350 enum machine_mode mode;
3351 rtx x;
3352 struct rtx_const *value;
3354 /* Clear the whole structure, including any gaps. */
3355 memset (value, 0, sizeof (struct rtx_const));
3357 value->kind = RTX_INT; /* Most usual kind. */
3358 value->mode = mode;
3360 switch (GET_CODE (x))
3362 case CONST_DOUBLE:
3363 value->kind = RTX_DOUBLE;
3364 if (GET_MODE (x) != VOIDmode)
3366 value->mode = GET_MODE (x);
3367 memcpy ((char *) &value->un.du,
3368 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3370 else
3372 value->un.di.low = CONST_DOUBLE_LOW (x);
3373 value->un.di.high = CONST_DOUBLE_HIGH (x);
3375 break;
3377 case CONST_INT:
3378 value->un.addr.offset = INTVAL (x);
3379 break;
3381 case SYMBOL_REF:
3382 case LABEL_REF:
3383 case PC:
3384 value->un.addr.base = x;
3385 break;
3387 case CONST:
3388 x = XEXP (x, 0);
3389 if (GET_CODE (x) == PLUS)
3391 value->un.addr.base = XEXP (x, 0);
3392 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3393 abort ();
3394 value->un.addr.offset = INTVAL (XEXP (x, 1));
3396 else if (GET_CODE (x) == MINUS)
3398 value->un.addr.base = XEXP (x, 0);
3399 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3400 abort ();
3401 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3403 else
3404 abort ();
3405 break;
3407 default:
3408 abort ();
3411 if (value->kind == RTX_INT && value->un.addr.base != 0)
3412 switch (GET_CODE (value->un.addr.base))
3414 case SYMBOL_REF:
3415 /* Use the string's address, not the SYMBOL_REF's address,
3416 for the sake of addresses of library routines. */
3417 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3418 break;
3420 case LABEL_REF:
3421 /* For a LABEL_REF, compare labels. */
3422 value->un.addr.base = XEXP (value->un.addr.base, 0);
3424 default:
3425 break;
3429 /* Given a MINUS expression, simplify it if both sides
3430 include the same symbol. */
3433 simplify_subtraction (x)
3434 rtx x;
3436 struct rtx_const val0, val1;
3438 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3439 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3441 if (val0.un.addr.base == val1.un.addr.base)
3442 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3443 return x;
3446 /* Compute a hash code for a constant RTL expression. */
3448 static int
3449 const_hash_rtx (mode, x)
3450 enum machine_mode mode;
3451 rtx x;
3453 register int hi;
3454 register size_t i;
3456 struct rtx_const value;
3457 decode_rtx_const (mode, x, &value);
3459 /* Compute hashing function */
3460 hi = 0;
3461 for (i = 0; i < sizeof value / sizeof (int); i++)
3462 hi += ((int *) &value)[i];
3464 hi &= (1 << HASHBITS) - 1;
3465 hi %= MAX_RTX_HASH_TABLE;
3466 return hi;
3469 /* Compare a constant rtl object X with a constant-descriptor DESC.
3470 Return 1 if DESC describes a constant with the same value as X. */
3472 static int
3473 compare_constant_rtx (mode, x, desc)
3474 enum machine_mode mode;
3475 rtx x;
3476 struct constant_descriptor *desc;
3478 register int *p = (int *) desc->contents;
3479 register int *strp;
3480 register int len;
3481 struct rtx_const value;
3483 decode_rtx_const (mode, x, &value);
3484 strp = (int *) &value;
3485 len = sizeof value / sizeof (int);
3487 /* Compare constant contents. */
3488 while (--len >= 0)
3489 if (*p++ != *strp++)
3490 return 0;
3492 return 1;
3495 /* Construct a constant descriptor for the rtl-expression X.
3496 It is up to the caller to enter the descriptor in the hash table. */
3498 static struct constant_descriptor *
3499 record_constant_rtx (mode, x)
3500 enum machine_mode mode;
3501 rtx x;
3503 struct constant_descriptor *ptr;
3505 ptr = ((struct constant_descriptor *)
3506 xcalloc (1,
3507 (sizeof (struct constant_descriptor)
3508 + sizeof (struct rtx_const) - 1)));
3509 decode_rtx_const (mode, x, (struct rtx_const *) ptr->contents);
3511 return ptr;
3514 /* Given a constant rtx X, make (or find) a memory constant for its value
3515 and return a MEM rtx to refer to it in memory. */
3518 force_const_mem (mode, x)
3519 enum machine_mode mode;
3520 rtx x;
3522 register int hash;
3523 register struct constant_descriptor *desc;
3524 char label[256];
3525 char *found = 0;
3526 rtx def;
3528 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3529 (this will always be true for floating CONST_DOUBLEs that have been
3530 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3531 use the previous copy. Otherwise, make a new one. Note that in
3532 the unlikely event that this same CONST_DOUBLE is used in two different
3533 modes in an alternating fashion, we will allocate a lot of different
3534 memory locations, but this should be extremely rare. */
3536 if (GET_CODE (x) == CONST_DOUBLE
3537 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3538 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3539 return CONST_DOUBLE_MEM (x);
3541 /* Compute hash code of X. Search the descriptors for that hash code
3542 to see if any of them describes X. If yes, the descriptor records
3543 the label number already assigned. */
3545 hash = const_hash_rtx (mode, x);
3547 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3548 if (compare_constant_rtx (mode, x, desc))
3550 found = desc->label;
3551 break;
3554 if (found == 0)
3556 register struct pool_constant *pool;
3557 register struct pool_sym *sym;
3558 int align;
3560 /* No constant equal to X is known to have been output.
3561 Make a constant descriptor to enter X in the hash table.
3562 Assign the label number and record it in the descriptor for
3563 future calls to this function to find. */
3565 desc = record_constant_rtx (mode, x);
3566 desc->next = const_rtx_hash_table[hash];
3567 const_rtx_hash_table[hash] = desc;
3569 /* Align the location counter as required by EXP's data type. */
3570 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3571 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3572 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3573 #ifdef CONSTANT_ALIGNMENT
3574 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3575 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3576 #endif
3578 pool_offset += align - 1;
3579 pool_offset &= ~ (align - 1);
3581 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3583 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3584 pool->desc = desc;
3585 pool->constant = x;
3586 pool->mode = mode;
3587 pool->labelno = const_labelno;
3588 pool->align = align;
3589 pool->offset = pool_offset;
3590 pool->mark = 1;
3591 pool->next = 0;
3593 if (last_pool == 0)
3594 first_pool = pool;
3595 else
3596 last_pool->next = pool;
3598 last_pool = pool;
3599 pool_offset += GET_MODE_SIZE (mode);
3601 /* Create a string containing the label name, in LABEL. */
3602 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3604 ++const_labelno;
3606 desc->label = found = ggc_alloc_string (label, -1);
3608 /* Add label to symbol hash table. */
3609 hash = SYMHASH (found);
3610 sym = (struct pool_sym *) xmalloc (sizeof (struct pool_sym));
3611 sym->label = found;
3612 sym->pool = pool;
3613 sym->next = const_rtx_sym_hash_table[hash];
3614 const_rtx_sym_hash_table[hash] = sym;
3617 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3619 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3620 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3621 RTX_UNCHANGING_P (def) = 1;
3623 /* Mark the symbol_ref as belonging to this constants pool. */
3624 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3625 current_function_uses_const_pool = 1;
3627 if (GET_CODE (x) == CONST_DOUBLE)
3629 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3631 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3632 const_double_chain = x;
3634 CONST_DOUBLE_MEM (x) = def;
3637 return def;
3640 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3641 the corresponding pool_constant structure. */
3643 static struct pool_constant *
3644 find_pool_constant (f, addr)
3645 struct function *f;
3646 rtx addr;
3648 struct pool_sym *sym;
3649 const char *label = XSTR (addr, 0);
3651 for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3652 sym = sym->next)
3653 if (sym->label == label)
3654 return sym->pool;
3656 abort ();
3659 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3662 get_pool_constant (addr)
3663 rtx addr;
3665 return (find_pool_constant (cfun, addr))->constant;
3668 /* Likewise, but for the constant pool of a specific function. */
3671 get_pool_constant_for_function (f, addr)
3672 struct function *f;
3673 rtx addr;
3675 return (find_pool_constant (f, addr))->constant;
3678 /* Similar, return the mode. */
3680 enum machine_mode
3681 get_pool_mode (addr)
3682 rtx addr;
3684 return (find_pool_constant (cfun, addr))->mode;
3687 enum machine_mode
3688 get_pool_mode_for_function (f, addr)
3689 struct function *f;
3690 rtx addr;
3692 return (find_pool_constant (f, addr))->mode;
3695 /* Similar, return the offset in the constant pool. */
3698 get_pool_offset (addr)
3699 rtx addr;
3701 return (find_pool_constant (cfun, addr))->offset;
3704 /* Return the size of the constant pool. */
3707 get_pool_size ()
3709 return pool_offset;
3712 /* Write all the constants in the constant pool. */
3714 void
3715 output_constant_pool (fnname, fndecl)
3716 const char *fnname ATTRIBUTE_UNUSED;
3717 tree fndecl ATTRIBUTE_UNUSED;
3719 struct pool_constant *pool;
3720 rtx x;
3721 union real_extract u;
3723 /* It is possible for gcc to call force_const_mem and then to later
3724 discard the instructions which refer to the constant. In such a
3725 case we do not need to output the constant. */
3726 mark_constant_pool ();
3728 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3729 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3730 #endif
3732 for (pool = first_pool; pool; pool = pool->next)
3734 rtx tmp;
3736 x = pool->constant;
3738 if (! pool->mark)
3739 continue;
3741 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3742 whose CODE_LABEL has been deleted. This can occur if a jump table
3743 is eliminated by optimization. If so, write a constant of zero
3744 instead. Note that this can also happen by turning the
3745 CODE_LABEL into a NOTE. */
3746 /* ??? This seems completely and utterly wrong. Certainly it's
3747 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3748 functioning even with INSN_DELETED_P and friends. */
3750 tmp = x;
3751 switch (GET_CODE (x))
3753 case CONST:
3754 if (GET_CODE (XEXP (x, 0)) != PLUS
3755 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3756 break;
3757 tmp = XEXP (XEXP (x, 0), 0);
3758 /* FALLTHRU */
3760 case LABEL_REF:
3761 tmp = XEXP (x, 0);
3762 if (INSN_DELETED_P (tmp)
3763 || (GET_CODE (tmp) == NOTE
3764 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3766 abort ();
3767 x = const0_rtx;
3769 break;
3771 default:
3772 break;
3775 /* First switch to correct section. */
3776 #ifdef SELECT_RTX_SECTION
3777 SELECT_RTX_SECTION (pool->mode, x);
3778 #else
3779 readonly_data_section ();
3780 #endif
3782 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3783 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3784 pool->align, pool->labelno, done);
3785 #endif
3787 if (pool->align > 1)
3788 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3790 /* Output the label. */
3791 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3793 /* Output the value of the constant itself. */
3794 switch (GET_MODE_CLASS (pool->mode))
3796 case MODE_FLOAT:
3797 if (GET_CODE (x) != CONST_DOUBLE)
3798 abort ();
3800 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
3801 assemble_real (u.d, pool->mode);
3802 break;
3804 case MODE_INT:
3805 case MODE_PARTIAL_INT:
3806 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3807 break;
3809 default:
3810 abort ();
3813 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3814 done: ;
3815 #endif
3819 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3820 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3821 #endif
3823 /* Done with this pool. */
3824 first_pool = last_pool = 0;
3827 /* Look through the instructions for this function, and mark all the
3828 entries in the constant pool which are actually being used. */
3830 static void
3831 mark_constant_pool ()
3833 register rtx insn;
3834 struct pool_constant *pool;
3836 if (first_pool == 0)
3837 return;
3839 for (pool = first_pool; pool; pool = pool->next)
3840 pool->mark = 0;
3842 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3843 if (INSN_P (insn))
3844 mark_constants (PATTERN (insn));
3846 for (insn = current_function_epilogue_delay_list;
3847 insn;
3848 insn = XEXP (insn, 1))
3849 if (INSN_P (insn))
3850 mark_constants (PATTERN (insn));
3852 /* It's possible that the only reference to a symbol is in a symbol
3853 that's in the constant pool. This happens in Fortran under some
3854 situations. (When the constant contains the address of another
3855 constant, and only the first is used directly in an insn.)
3856 This is potentially suboptimal if there's ever a possibility of
3857 backwards (in pool order) 2'd level references. However, it's
3858 not clear that 2'd level references can happen. */
3859 for (pool = first_pool; pool; pool = pool->next)
3861 struct pool_sym *sym;
3862 const char *label;
3864 /* skip unmarked entries; no insn refers to them. */
3865 if (!pool->mark)
3866 continue;
3868 /* Skip everything except SYMBOL_REFs. */
3869 if (GET_CODE (pool->constant) != SYMBOL_REF)
3870 continue;
3871 label = XSTR (pool->constant, 0);
3873 /* Be sure the symbol's value is marked. */
3874 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3875 sym = sym->next)
3876 if (sym->label == label)
3877 sym->pool->mark = 1;
3878 /* If we didn't find it, there's something truly wrong here, but it
3879 will be announced by the assembler. */
3883 static void
3884 mark_constants (x)
3885 register rtx x;
3887 register int i;
3888 register const char *format_ptr;
3890 if (x == 0)
3891 return;
3893 if (GET_CODE (x) == SYMBOL_REF)
3895 if (CONSTANT_POOL_ADDRESS_P (x))
3896 find_pool_constant (cfun, x)->mark = 1;
3897 return;
3899 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3900 a MEM, but does not constitute a use of that MEM. */
3901 else if (GET_CODE (x) == CONST_DOUBLE)
3902 return;
3904 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3905 insns, not any notes that may be attached. We don't want to mark
3906 a constant just because it happens to appear in a REG_EQUIV note. */
3907 if (INSN_P (x))
3909 mark_constants (PATTERN (x));
3910 return;
3913 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3915 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3917 switch (*format_ptr++)
3919 case 'e':
3920 mark_constants (XEXP (x, i));
3921 break;
3923 case 'E':
3924 if (XVEC (x, i) != 0)
3926 register int j;
3928 for (j = 0; j < XVECLEN (x, i); j++)
3929 mark_constants (XVECEXP (x, i, j));
3931 break;
3933 case 'S':
3934 case 's':
3935 case '0':
3936 case 'i':
3937 case 'w':
3938 case 'n':
3939 case 'u':
3940 break;
3942 default:
3943 abort ();
3948 /* Find all the constants whose addresses are referenced inside of EXP,
3949 and make sure assembler code with a label has been output for each one.
3950 Indicate whether an ADDR_EXPR has been encountered. */
3952 static int
3953 output_addressed_constants (exp)
3954 tree exp;
3956 int reloc = 0;
3958 switch (TREE_CODE (exp))
3960 case ADDR_EXPR:
3962 register tree constant = TREE_OPERAND (exp, 0);
3964 while (TREE_CODE (constant) == COMPONENT_REF)
3966 constant = TREE_OPERAND (constant, 0);
3969 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3970 || TREE_CODE (constant) == CONSTRUCTOR)
3971 /* No need to do anything here
3972 for addresses of variables or functions. */
3973 output_constant_def (constant);
3975 reloc = 1;
3976 break;
3978 case PLUS_EXPR:
3979 case MINUS_EXPR:
3980 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3981 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3982 break;
3984 case NOP_EXPR:
3985 case CONVERT_EXPR:
3986 case NON_LVALUE_EXPR:
3987 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3988 break;
3990 case CONSTRUCTOR:
3992 register tree link;
3993 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3994 if (TREE_VALUE (link) != 0)
3995 reloc |= output_addressed_constants (TREE_VALUE (link));
3997 break;
3999 default:
4000 break;
4002 return reloc;
4005 /* Return nonzero if VALUE is a valid constant-valued expression
4006 for use in initializing a static variable; one that can be an
4007 element of a "constant" initializer.
4009 Return null_pointer_node if the value is absolute;
4010 if it is relocatable, return the variable that determines the relocation.
4011 We assume that VALUE has been folded as much as possible;
4012 therefore, we do not need to check for such things as
4013 arithmetic-combinations of integers. */
4015 tree
4016 initializer_constant_valid_p (value, endtype)
4017 tree value;
4018 tree endtype;
4020 /* Give the front-end a chance to convert VALUE to something that
4021 looks more like a constant to the back-end. */
4022 if (lang_expand_constant)
4023 value = (*lang_expand_constant) (value);
4025 switch (TREE_CODE (value))
4027 case CONSTRUCTOR:
4028 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4029 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4030 && TREE_CONSTANT (value)
4031 && CONSTRUCTOR_ELTS (value))
4032 return
4033 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4034 endtype);
4036 return TREE_STATIC (value) ? null_pointer_node : 0;
4038 case INTEGER_CST:
4039 case REAL_CST:
4040 case STRING_CST:
4041 case COMPLEX_CST:
4042 return null_pointer_node;
4044 case ADDR_EXPR:
4045 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4047 case NON_LVALUE_EXPR:
4048 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4050 case CONVERT_EXPR:
4051 case NOP_EXPR:
4052 /* Allow conversions between pointer types. */
4053 if (POINTER_TYPE_P (TREE_TYPE (value))
4054 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4055 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4057 /* Allow conversions between real types. */
4058 if (FLOAT_TYPE_P (TREE_TYPE (value))
4059 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4060 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4062 /* Allow length-preserving conversions between integer types. */
4063 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4064 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4065 && (TYPE_PRECISION (TREE_TYPE (value))
4066 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4067 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4069 /* Allow conversions between other integer types only if
4070 explicit value. */
4071 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4072 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4074 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4075 endtype);
4076 if (inner == null_pointer_node)
4077 return null_pointer_node;
4078 break;
4081 /* Allow (int) &foo provided int is as wide as a pointer. */
4082 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4083 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4084 && (TYPE_PRECISION (TREE_TYPE (value))
4085 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4086 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4087 endtype);
4089 /* Likewise conversions from int to pointers, but also allow
4090 conversions from 0. */
4091 if (POINTER_TYPE_P (TREE_TYPE (value))
4092 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4094 if (integer_zerop (TREE_OPERAND (value, 0)))
4095 return null_pointer_node;
4096 else if (TYPE_PRECISION (TREE_TYPE (value))
4097 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4098 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4099 endtype);
4102 /* Allow conversions to union types if the value inside is okay. */
4103 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4104 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4105 endtype);
4106 break;
4108 case PLUS_EXPR:
4109 if (! INTEGRAL_TYPE_P (endtype)
4110 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4112 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4113 endtype);
4114 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4115 endtype);
4116 /* If either term is absolute, use the other terms relocation. */
4117 if (valid0 == null_pointer_node)
4118 return valid1;
4119 if (valid1 == null_pointer_node)
4120 return valid0;
4122 break;
4124 case MINUS_EXPR:
4125 if (! INTEGRAL_TYPE_P (endtype)
4126 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4128 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4129 endtype);
4130 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4131 endtype);
4132 /* Win if second argument is absolute. */
4133 if (valid1 == null_pointer_node)
4134 return valid0;
4135 /* Win if both arguments have the same relocation.
4136 Then the value is absolute. */
4137 if (valid0 == valid1 && valid0 != 0)
4138 return null_pointer_node;
4141 /* Support differences between labels. */
4142 if (INTEGRAL_TYPE_P (endtype))
4144 tree op0, op1;
4145 op0 = TREE_OPERAND (value, 0);
4146 op1 = TREE_OPERAND (value, 1);
4147 STRIP_NOPS (op0);
4148 STRIP_NOPS (op1);
4150 if (TREE_CODE (op0) == ADDR_EXPR
4151 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4152 && TREE_CODE (op1) == ADDR_EXPR
4153 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4154 return null_pointer_node;
4156 break;
4158 default:
4159 break;
4162 return 0;
4165 /* Output assembler code for constant EXP to FILE, with no label.
4166 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4167 Assumes output_addressed_constants has been done on EXP already.
4169 Generate exactly SIZE bytes of assembler data, padding at the end
4170 with zeros if necessary. SIZE must always be specified.
4172 SIZE is important for structure constructors,
4173 since trailing members may have been omitted from the constructor.
4174 It is also important for initialization of arrays from string constants
4175 since the full length of the string constant might not be wanted.
4176 It is also needed for initialization of unions, where the initializer's
4177 type is just one member, and that may not be as long as the union.
4179 There a case in which we would fail to output exactly SIZE bytes:
4180 for a structure constructor that wants to produce more than SIZE bytes.
4181 But such constructors will never be generated for any possible input. */
4183 void
4184 output_constant (exp, size)
4185 register tree exp;
4186 register int size;
4188 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4190 /* Some front-ends use constants other than the standard
4191 language-indepdent varieties, but which may still be output
4192 directly. Give the front-end a chance to convert EXP to a
4193 language-independent representation. */
4194 if (lang_expand_constant)
4195 exp = (*lang_expand_constant) (exp);
4197 if (size == 0 || flag_syntax_only)
4198 return;
4200 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4201 That way we get the constant (we hope) inside it. Also, strip off any
4202 NOP_EXPR that converts between two record, union, array, or set types
4203 or a CONVERT_EXPR that converts to a union TYPE. */
4204 while ((TREE_CODE (exp) == NOP_EXPR
4205 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4206 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4207 || (TREE_CODE (exp) == CONVERT_EXPR
4208 && code == UNION_TYPE)
4209 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4211 exp = TREE_OPERAND (exp, 0);
4212 code = TREE_CODE (TREE_TYPE (exp));
4215 /* Allow a constructor with no elements for any data type.
4216 This means to fill the space with zeros. */
4217 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4219 assemble_zeros (size);
4220 return;
4223 switch (code)
4225 case CHAR_TYPE:
4226 case BOOLEAN_TYPE:
4227 case INTEGER_TYPE:
4228 case ENUMERAL_TYPE:
4229 case POINTER_TYPE:
4230 case REFERENCE_TYPE:
4231 /* ??? What about (int)((float)(int)&foo + 4) */
4232 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4233 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4234 exp = TREE_OPERAND (exp, 0);
4236 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4237 EXPAND_INITIALIZER),
4238 size, 0))
4239 error ("initializer for integer value is too complicated");
4240 size = 0;
4241 break;
4243 case REAL_TYPE:
4244 if (TREE_CODE (exp) != REAL_CST)
4245 error ("initializer for floating value is not a floating constant");
4247 assemble_real (TREE_REAL_CST (exp),
4248 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4249 size = 0;
4250 break;
4252 case COMPLEX_TYPE:
4253 output_constant (TREE_REALPART (exp), size / 2);
4254 output_constant (TREE_IMAGPART (exp), size / 2);
4255 size -= (size / 2) * 2;
4256 break;
4258 case ARRAY_TYPE:
4259 if (TREE_CODE (exp) == CONSTRUCTOR)
4261 output_constructor (exp, size);
4262 return;
4264 else if (TREE_CODE (exp) == STRING_CST)
4266 int excess = 0;
4268 if (size > TREE_STRING_LENGTH (exp))
4270 excess = size - TREE_STRING_LENGTH (exp);
4271 size = TREE_STRING_LENGTH (exp);
4274 assemble_string (TREE_STRING_POINTER (exp), size);
4275 size = excess;
4277 else
4278 abort ();
4279 break;
4281 case RECORD_TYPE:
4282 case UNION_TYPE:
4283 if (TREE_CODE (exp) == CONSTRUCTOR)
4284 output_constructor (exp, size);
4285 else
4286 abort ();
4287 return;
4289 case SET_TYPE:
4290 if (TREE_CODE (exp) == INTEGER_CST)
4291 assemble_integer (expand_expr (exp, NULL_RTX,
4292 VOIDmode, EXPAND_INITIALIZER),
4293 size, 1);
4294 else if (TREE_CODE (exp) == CONSTRUCTOR)
4296 unsigned char *buffer = (unsigned char *) alloca (size);
4297 if (get_set_constructor_bytes (exp, buffer, size))
4298 abort ();
4299 assemble_string ((char *) buffer, size);
4301 else
4302 error ("unknown set constructor type");
4303 return;
4305 default:
4306 break; /* ??? */
4309 if (size > 0)
4310 assemble_zeros (size);
4314 /* Subroutine of output_constant, used for CONSTRUCTORs
4315 (aggregate constants).
4316 Generate at least SIZE bytes, padding if necessary. */
4318 static void
4319 output_constructor (exp, size)
4320 tree exp;
4321 int size;
4323 tree type = TREE_TYPE (exp);
4324 register tree link, field = 0;
4325 tree min_index = 0;
4326 /* Number of bytes output or skipped so far.
4327 In other words, current position within the constructor. */
4328 HOST_WIDE_INT total_bytes = 0;
4329 /* Non-zero means BYTE contains part of a byte, to be output. */
4330 int byte_buffer_in_use = 0;
4331 register int byte = 0;
4333 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4334 abort ();
4336 if (TREE_CODE (type) == RECORD_TYPE)
4337 field = TYPE_FIELDS (type);
4339 if (TREE_CODE (type) == ARRAY_TYPE
4340 && TYPE_DOMAIN (type) != 0)
4341 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4343 /* As LINK goes through the elements of the constant,
4344 FIELD goes through the structure fields, if the constant is a structure.
4345 if the constant is a union, then we override this,
4346 by getting the field from the TREE_LIST element.
4347 But the constant could also be an array. Then FIELD is zero.
4349 There is always a maximum of one element in the chain LINK for unions
4350 (even if the initializer in a source program incorrectly contains
4351 more one). */
4352 for (link = CONSTRUCTOR_ELTS (exp);
4353 link;
4354 link = TREE_CHAIN (link),
4355 field = field ? TREE_CHAIN (field) : 0)
4357 tree val = TREE_VALUE (link);
4358 tree index = 0;
4360 /* The element in a union constructor specifies the proper field
4361 or index. */
4362 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4363 || TREE_CODE (type) == QUAL_UNION_TYPE)
4364 && TREE_PURPOSE (link) != 0)
4365 field = TREE_PURPOSE (link);
4367 else if (TREE_CODE (type) == ARRAY_TYPE)
4368 index = TREE_PURPOSE (link);
4370 /* Eliminate the marker that makes a cast not be an lvalue. */
4371 if (val != 0)
4372 STRIP_NOPS (val);
4374 if (index && TREE_CODE (index) == RANGE_EXPR)
4376 register int fieldsize
4377 = int_size_in_bytes (TREE_TYPE (type));
4378 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4379 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4380 HOST_WIDE_INT index;
4382 for (index = lo_index; index <= hi_index; index++)
4384 /* Output the element's initial value. */
4385 if (val == 0)
4386 assemble_zeros (fieldsize);
4387 else
4388 output_constant (val, fieldsize);
4390 /* Count its size. */
4391 total_bytes += fieldsize;
4394 else if (field == 0 || !DECL_BIT_FIELD (field))
4396 /* An element that is not a bit-field. */
4398 register int fieldsize;
4399 /* Since this structure is static,
4400 we know the positions are constant. */
4401 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4403 if (index != 0)
4404 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4405 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4407 /* Output any buffered-up bit-fields preceding this element. */
4408 if (byte_buffer_in_use)
4410 ASM_OUTPUT_BYTE (asm_out_file, byte);
4411 total_bytes++;
4412 byte_buffer_in_use = 0;
4415 /* Advance to offset of this element.
4416 Note no alignment needed in an array, since that is guaranteed
4417 if each element has the proper size. */
4418 if ((field != 0 || index != 0) && pos != total_bytes)
4420 assemble_zeros (pos - total_bytes);
4421 total_bytes = pos;
4424 else if (field != 0 && DECL_PACKED (field))
4425 /* Some assemblers automaticallly align a datum according to its
4426 size if no align directive is specified. The datum, however,
4427 may be declared with 'packed' attribute, so we have to disable
4428 such a feature. */
4429 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4431 /* Determine size this element should occupy. */
4432 if (field)
4433 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4434 else
4435 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4437 /* Output the element's initial value. */
4438 if (val == 0)
4439 assemble_zeros (fieldsize);
4440 else
4441 output_constant (val, fieldsize);
4443 /* Count its size. */
4444 total_bytes += fieldsize;
4446 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4447 error ("invalid initial value for member `%s'",
4448 IDENTIFIER_POINTER (DECL_NAME (field)));
4449 else
4451 /* Element that is a bit-field. */
4453 HOST_WIDE_INT next_offset = int_bit_position (field);
4454 HOST_WIDE_INT end_offset
4455 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4457 if (val == 0)
4458 val = integer_zero_node;
4460 /* If this field does not start in this (or, next) byte,
4461 skip some bytes. */
4462 if (next_offset / BITS_PER_UNIT != total_bytes)
4464 /* Output remnant of any bit field in previous bytes. */
4465 if (byte_buffer_in_use)
4467 ASM_OUTPUT_BYTE (asm_out_file, byte);
4468 total_bytes++;
4469 byte_buffer_in_use = 0;
4472 /* If still not at proper byte, advance to there. */
4473 if (next_offset / BITS_PER_UNIT != total_bytes)
4475 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4476 total_bytes = next_offset / BITS_PER_UNIT;
4480 if (! byte_buffer_in_use)
4481 byte = 0;
4483 /* We must split the element into pieces that fall within
4484 separate bytes, and combine each byte with previous or
4485 following bit-fields. */
4487 /* next_offset is the offset n fbits from the beginning of
4488 the structure to the next bit of this element to be processed.
4489 end_offset is the offset of the first bit past the end of
4490 this element. */
4491 while (next_offset < end_offset)
4493 int this_time;
4494 int shift;
4495 HOST_WIDE_INT value;
4496 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4497 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4499 /* Advance from byte to byte
4500 within this element when necessary. */
4501 while (next_byte != total_bytes)
4503 ASM_OUTPUT_BYTE (asm_out_file, byte);
4504 total_bytes++;
4505 byte = 0;
4508 /* Number of bits we can process at once
4509 (all part of the same byte). */
4510 this_time = MIN (end_offset - next_offset,
4511 BITS_PER_UNIT - next_bit);
4512 if (BYTES_BIG_ENDIAN)
4514 /* On big-endian machine, take the most significant bits
4515 first (of the bits that are significant)
4516 and put them into bytes from the most significant end. */
4517 shift = end_offset - next_offset - this_time;
4519 /* Don't try to take a bunch of bits that cross
4520 the word boundary in the INTEGER_CST. We can
4521 only select bits from the LOW or HIGH part
4522 not from both. */
4523 if (shift < HOST_BITS_PER_WIDE_INT
4524 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4526 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4527 shift = HOST_BITS_PER_WIDE_INT;
4530 /* Now get the bits from the appropriate constant word. */
4531 if (shift < HOST_BITS_PER_WIDE_INT)
4532 value = TREE_INT_CST_LOW (val);
4533 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4535 value = TREE_INT_CST_HIGH (val);
4536 shift -= HOST_BITS_PER_WIDE_INT;
4538 else
4539 abort ();
4541 /* Get the result. This works only when:
4542 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4543 byte |= (((value >> shift)
4544 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4545 << (BITS_PER_UNIT - this_time - next_bit));
4547 else
4549 /* On little-endian machines,
4550 take first the least significant bits of the value
4551 and pack them starting at the least significant
4552 bits of the bytes. */
4553 shift = next_offset - int_bit_position (field);
4555 /* Don't try to take a bunch of bits that cross
4556 the word boundary in the INTEGER_CST. We can
4557 only select bits from the LOW or HIGH part
4558 not from both. */
4559 if (shift < HOST_BITS_PER_WIDE_INT
4560 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4561 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4563 /* Now get the bits from the appropriate constant word. */
4564 if (shift < HOST_BITS_PER_WIDE_INT)
4565 value = TREE_INT_CST_LOW (val);
4566 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4568 value = TREE_INT_CST_HIGH (val);
4569 shift -= HOST_BITS_PER_WIDE_INT;
4571 else
4572 abort ();
4574 /* Get the result. This works only when:
4575 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4576 byte |= (((value >> shift)
4577 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4578 << next_bit);
4581 next_offset += this_time;
4582 byte_buffer_in_use = 1;
4587 if (byte_buffer_in_use)
4589 ASM_OUTPUT_BYTE (asm_out_file, byte);
4590 total_bytes++;
4593 if (total_bytes < size)
4594 assemble_zeros (size - total_bytes);
4597 #ifdef HANDLE_PRAGMA_WEAK
4598 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4599 associatd with NAME. */
4602 add_weak (name, value)
4603 const char *name;
4604 const char *value;
4606 struct weak_syms *weak;
4608 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4610 if (weak == NULL)
4611 return 0;
4613 weak->next = weak_decls;
4614 weak->name = name;
4615 weak->value = value;
4616 weak_decls = weak;
4618 return 1;
4620 #endif /* HANDLE_PRAGMA_WEAK */
4622 /* Declare DECL to be a weak symbol. */
4624 void
4625 declare_weak (decl)
4626 tree decl;
4628 if (! TREE_PUBLIC (decl))
4629 error_with_decl (decl, "weak declaration of `%s' must be public");
4630 else if (TREE_ASM_WRITTEN (decl))
4631 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4632 else if (SUPPORTS_WEAK)
4633 DECL_WEAK (decl) = 1;
4634 #ifdef HANDLE_PRAGMA_WEAK
4635 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4636 #endif
4639 /* Emit any pending weak declarations. */
4641 #ifdef HANDLE_PRAGMA_WEAK
4642 struct weak_syms * weak_decls;
4643 #endif
4645 void
4646 weak_finish ()
4648 #ifdef HANDLE_PRAGMA_WEAK
4649 if (HANDLE_PRAGMA_WEAK)
4651 struct weak_syms *t;
4652 for (t = weak_decls; t; t = t->next)
4654 if (t->name)
4656 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4657 if (t->value)
4658 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4662 #endif
4665 /* Remove NAME from the pending list of weak symbols. This prevents
4666 the compiler from emitting multiple .weak directives which confuses
4667 some assemblers. */
4668 #ifdef ASM_WEAKEN_LABEL
4669 static void
4670 remove_from_pending_weak_list (name)
4671 const char *name ATTRIBUTE_UNUSED;
4673 #ifdef HANDLE_PRAGMA_WEAK
4674 if (HANDLE_PRAGMA_WEAK)
4676 struct weak_syms *t;
4677 for (t = weak_decls; t; t = t->next)
4679 if (t->name && strcmp (name, t->name) == 0)
4680 t->name = NULL;
4683 #endif
4685 #endif
4687 void
4688 assemble_alias (decl, target)
4689 tree decl, target ATTRIBUTE_UNUSED;
4691 const char *name;
4693 make_decl_rtl (decl, (char *) 0, 1);
4694 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4696 #ifdef ASM_OUTPUT_DEF
4697 /* Make name accessible from other files, if appropriate. */
4699 if (TREE_PUBLIC (decl))
4701 #ifdef ASM_WEAKEN_LABEL
4702 if (DECL_WEAK (decl))
4704 ASM_WEAKEN_LABEL (asm_out_file, name);
4705 /* Remove this function from the pending weak list so that
4706 we do not emit multiple .weak directives for it. */
4707 remove_from_pending_weak_list
4708 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4710 else
4711 #endif
4712 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4715 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4716 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4717 #else
4718 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4719 #endif
4720 TREE_ASM_WRITTEN (decl) = 1;
4721 #else
4722 #ifdef ASM_OUTPUT_WEAK_ALIAS
4723 if (! DECL_WEAK (decl))
4724 warning ("only weak aliases are supported in this configuration");
4726 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4727 TREE_ASM_WRITTEN (decl) = 1;
4728 #else
4729 warning ("alias definitions not supported in this configuration; ignored");
4730 #endif
4731 #endif
4734 /* This determines whether or not we support link-once semantics. */
4735 #ifndef SUPPORTS_ONE_ONLY
4736 #ifdef MAKE_DECL_ONE_ONLY
4737 #define SUPPORTS_ONE_ONLY 1
4738 #else
4739 #define SUPPORTS_ONE_ONLY 0
4740 #endif
4741 #endif
4743 /* Returns 1 if the target configuration supports defining public symbols
4744 so that one of them will be chosen at link time instead of generating a
4745 multiply-defined symbol error, whether through the use of weak symbols or
4746 a target-specific mechanism for having duplicates discarded. */
4749 supports_one_only ()
4751 if (SUPPORTS_ONE_ONLY)
4752 return 1;
4753 return SUPPORTS_WEAK;
4756 /* Set up DECL as a public symbol that can be defined in multiple
4757 translation units without generating a linker error. */
4759 void
4760 make_decl_one_only (decl)
4761 tree decl;
4763 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4764 abort ();
4766 TREE_PUBLIC (decl) = 1;
4768 if (TREE_CODE (decl) == VAR_DECL
4769 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4770 DECL_COMMON (decl) = 1;
4771 else if (SUPPORTS_ONE_ONLY)
4773 #ifdef MAKE_DECL_ONE_ONLY
4774 MAKE_DECL_ONE_ONLY (decl);
4775 #endif
4776 DECL_ONE_ONLY (decl) = 1;
4778 else if (SUPPORTS_WEAK)
4779 DECL_WEAK (decl) = 1;
4780 else
4781 abort ();
4784 void
4785 init_varasm_once ()
4787 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
4788 mark_const_hash_entry);
4789 ggc_add_string_root (&in_named_name, 1);
4792 /* Extra support for EH values. */
4793 void
4794 assemble_eh_label (name)
4795 const char *name;
4797 #ifdef ASM_OUTPUT_EH_LABEL
4798 ASM_OUTPUT_EH_LABEL (asm_out_file, name);
4799 #else
4800 assemble_label (name);
4801 #endif
4804 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
4806 void
4807 assemble_eh_align (align)
4808 int align;
4810 #ifdef ASM_OUTPUT_EH_ALIGN
4811 if (align > BITS_PER_UNIT)
4812 ASM_OUTPUT_EH_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
4813 #else
4814 assemble_align (align);
4815 #endif
4819 /* On some platforms, we may want to specify a special mechansim to
4820 output EH data when generating with a function.. */
4822 assemble_eh_integer (x, size, force)
4823 rtx x;
4824 int size;
4825 int force;
4828 switch (size)
4830 #ifdef ASM_OUTPUT_EH_CHAR
4831 case 1:
4832 ASM_OUTPUT_EH_CHAR (asm_out_file, x);
4833 return 1;
4834 #endif
4836 #ifdef ASM_OUTPUT_EH_SHORT
4837 case 2:
4838 ASM_OUTPUT_EH_SHORT (asm_out_file, x);
4839 return 1;
4840 #endif
4842 #ifdef ASM_OUTPUT_EH_INT
4843 case 4:
4844 ASM_OUTPUT_EH_INT (asm_out_file, x);
4845 return 1;
4846 #endif
4848 #ifdef ASM_OUTPUT_EH_DOUBLE_INT
4849 case 8:
4850 ASM_OUTPUT_EH_DOUBLE_INT (asm_out_file, x);
4851 return 1;
4852 #endif
4854 default:
4855 break;
4857 return (assemble_integer (x, size, force));