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