iris6.h (ASM_OUTPUT_WEAK_ALIAS): Call ASM_GLOBALIZE_LABEL.
[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 #ifdef ASM_WEAKEN_LABEL
1009 if (DECL_WEAK (decl))
1010 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1011 else
1012 #endif
1013 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1014 }
1015
1016 /* Do any machine/system dependent processing of the function name */
1017 #ifdef ASM_DECLARE_FUNCTION_NAME
1018 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1019 #else
1020 /* Standard thing is just output label for the function. */
1021 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1022 #endif /* ASM_DECLARE_FUNCTION_NAME */
1023 }
1024
1025 /* Output assembler code associated with defining the size of the
1026 function. DECL describes the function. NAME is the function's name. */
1027
1028 void
1029 assemble_end_function (decl, fnname)
1030 tree decl;
1031 char *fnname;
1032 {
1033 #ifdef ASM_DECLARE_FUNCTION_SIZE
1034 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1035 #endif
1036 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1037 {
1038 output_constant_pool (fnname, decl);
1039 function_section (decl); /* need to switch back */
1040 }
1041
1042 /* Output any constants which should appear after the function. */
1043 output_after_function_constants ();
1044 }
1045 \f
1046 /* Assemble code to leave SIZE bytes of zeros. */
1047
1048 void
1049 assemble_zeros (size)
1050 int size;
1051 {
1052 #ifdef ASM_NO_SKIP_IN_TEXT
1053 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1054 so we must output 0s explicitly in the text section. */
1055 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1056 {
1057 int i;
1058
1059 for (i = 0; i < size - 20; i += 20)
1060 {
1061 #ifdef ASM_BYTE_OP
1062 fprintf (asm_out_file,
1063 "%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);
1064 #else
1065 fprintf (asm_out_file,
1066 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1067 #endif
1068 }
1069 if (i < size)
1070 {
1071 #ifdef ASM_BYTE_OP
1072 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1073 #else
1074 fprintf (asm_out_file, "\tbyte 0");
1075 #endif
1076 i++;
1077 for (; i < size; i++)
1078 fprintf (asm_out_file, ",0");
1079 fprintf (asm_out_file, "\n");
1080 }
1081 }
1082 else
1083 #endif
1084 if (size > 0)
1085 ASM_OUTPUT_SKIP (asm_out_file, size);
1086 }
1087
1088 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1089
1090 void
1091 assemble_align (align)
1092 int align;
1093 {
1094 if (align > BITS_PER_UNIT)
1095 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1096 }
1097
1098 /* Assemble a string constant with the specified C string as contents. */
1099
1100 void
1101 assemble_string (p, size)
1102 char *p;
1103 int size;
1104 {
1105 int pos = 0;
1106 int maximum = 2000;
1107
1108 /* If the string is very long, split it up. */
1109
1110 while (pos < size)
1111 {
1112 int thissize = size - pos;
1113 if (thissize > maximum)
1114 thissize = maximum;
1115
1116 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1117
1118 pos += thissize;
1119 p += thissize;
1120 }
1121 }
1122
1123 \f
1124 /* Assemble everything that is needed for a variable or function declaration.
1125 Not used for automatic variables, and not used for function definitions.
1126 Should not be called for variables of incomplete structure type.
1127
1128 TOP_LEVEL is nonzero if this variable has file scope.
1129 AT_END is nonzero if this is the special handling, at end of compilation,
1130 to define things that have had only tentative definitions.
1131 DONT_OUTPUT_DATA if nonzero means don't actually output the
1132 initial value (that will be done by the caller). */
1133
1134 void
1135 assemble_variable (decl, top_level, at_end, dont_output_data)
1136 tree decl;
1137 int top_level;
1138 int at_end;
1139 int dont_output_data;
1140 {
1141 register char *name;
1142 unsigned int align;
1143 tree size_tree;
1144 int reloc = 0;
1145 enum in_section saved_in_section;
1146
1147 last_assemble_variable_decl = 0;
1148
1149 if (GET_CODE (DECL_RTL (decl)) == REG)
1150 {
1151 /* Do output symbol info for global register variables, but do nothing
1152 else for them. */
1153
1154 if (TREE_ASM_WRITTEN (decl))
1155 return;
1156 TREE_ASM_WRITTEN (decl) = 1;
1157
1158 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1159 /* File-scope global variables are output here. */
1160 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1161 && top_level)
1162 dbxout_symbol (decl, 0);
1163 #endif
1164 #ifdef SDB_DEBUGGING_INFO
1165 if (write_symbols == SDB_DEBUG && top_level
1166 /* Leave initialized global vars for end of compilation;
1167 see comment in compile_file. */
1168 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1169 sdbout_symbol (decl, 0);
1170 #endif
1171
1172 /* Don't output any DWARF debugging information for variables here.
1173 In the case of local variables, the information for them is output
1174 when we do our recursive traversal of the tree representation for
1175 the entire containing function. In the case of file-scope variables,
1176 we output information for all of them at the very end of compilation
1177 while we are doing our final traversal of the chain of file-scope
1178 declarations. */
1179
1180 return;
1181 }
1182
1183 /* Normally no need to say anything here for external references,
1184 since assemble_external is called by the language-specific code
1185 when a declaration is first seen. */
1186
1187 if (DECL_EXTERNAL (decl))
1188 return;
1189
1190 /* Output no assembler code for a function declaration.
1191 Only definitions of functions output anything. */
1192
1193 if (TREE_CODE (decl) == FUNCTION_DECL)
1194 return;
1195
1196 /* If type was incomplete when the variable was declared,
1197 see if it is complete now. */
1198
1199 if (DECL_SIZE (decl) == 0)
1200 layout_decl (decl, 0);
1201
1202 /* Still incomplete => don't allocate it; treat the tentative defn
1203 (which is what it must have been) as an `extern' reference. */
1204
1205 if (!dont_output_data && DECL_SIZE (decl) == 0)
1206 {
1207 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1208 DECL_SOURCE_LINE (decl),
1209 "storage size of `%s' isn't known",
1210 IDENTIFIER_POINTER (DECL_NAME (decl)));
1211 TREE_ASM_WRITTEN (decl) = 1;
1212 return;
1213 }
1214
1215 /* The first declaration of a variable that comes through this function
1216 decides whether it is global (in C, has external linkage)
1217 or local (in C, has internal linkage). So do nothing more
1218 if this function has already run. */
1219
1220 if (TREE_ASM_WRITTEN (decl))
1221 return;
1222
1223 TREE_ASM_WRITTEN (decl) = 1;
1224
1225 app_disable ();
1226
1227 if (! dont_output_data)
1228 {
1229 int size;
1230
1231 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1232 goto finish;
1233
1234 /* This is better than explicit arithmetic, since it avoids overflow. */
1235 size_tree = size_binop (CEIL_DIV_EXPR,
1236 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1237
1238 size = TREE_INT_CST_LOW (size_tree);
1239 if (TREE_INT_CST_HIGH (size_tree) != 0
1240 || size != TREE_INT_CST_LOW (size_tree))
1241 {
1242 error_with_decl (decl, "size of variable `%s' is too large");
1243 goto finish;
1244 }
1245 }
1246
1247 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1248
1249 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1250 && ! first_global_object_name
1251 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1252 || DECL_INITIAL (decl) == error_mark_node))
1253 && ! DECL_WEAK (decl)
1254 && ! DECL_ONE_ONLY (decl))
1255 {
1256 char *p;
1257
1258 STRIP_NAME_ENCODING (p, name);
1259 first_global_object_name = permalloc (strlen (p) + 1);
1260 strcpy (first_global_object_name, p);
1261 }
1262
1263 /* Compute the alignment of this data. */
1264
1265 align = DECL_ALIGN (decl);
1266
1267 /* In the case for initialing an array whose length isn't specified,
1268 where we have not yet been able to do the layout,
1269 figure out the proper alignment now. */
1270 if (dont_output_data && DECL_SIZE (decl) == 0
1271 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1272 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1273
1274 /* Some object file formats have a maximum alignment which they support.
1275 In particular, a.out format supports a maximum alignment of 4. */
1276 #ifndef MAX_OFILE_ALIGNMENT
1277 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1278 #endif
1279 if (align > MAX_OFILE_ALIGNMENT)
1280 {
1281 warning_with_decl (decl,
1282 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1283 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1284 align = MAX_OFILE_ALIGNMENT;
1285 }
1286
1287 /* On some machines, it is good to increase alignment sometimes. */
1288 #ifdef DATA_ALIGNMENT
1289 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1290 #endif
1291 #ifdef CONSTANT_ALIGNMENT
1292 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1293 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1294 #endif
1295
1296 /* Reset the alignment in case we have made it tighter, so we can benefit
1297 from it in get_pointer_alignment. */
1298 DECL_ALIGN (decl) = align;
1299
1300 /* Handle uninitialized definitions. */
1301
1302 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1303 /* If the target can't output uninitialized but not common global data
1304 in .bss, then we have to use .data. */
1305 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1306 && DECL_COMMON (decl)
1307 #endif
1308 && ! dont_output_data)
1309 {
1310 int size = TREE_INT_CST_LOW (size_tree);
1311 int rounded = size;
1312
1313 /* Don't allocate zero bytes of common,
1314 since that means "undefined external" in the linker. */
1315 if (size == 0) rounded = 1;
1316 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1317 so that each uninitialized object starts on such a boundary. */
1318 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1319 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1320 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1321
1322 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1323 if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1324 warning_with_decl
1325 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1326 #endif
1327
1328 #ifdef DBX_DEBUGGING_INFO
1329 /* File-scope global variables are output here. */
1330 if (write_symbols == DBX_DEBUG && top_level)
1331 dbxout_symbol (decl, 0);
1332 #endif
1333 #ifdef SDB_DEBUGGING_INFO
1334 if (write_symbols == SDB_DEBUG && top_level
1335 /* Leave initialized global vars for end of compilation;
1336 see comment in compile_file. */
1337 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1338 sdbout_symbol (decl, 0);
1339 #endif
1340
1341 /* Don't output any DWARF debugging information for variables here.
1342 In the case of local variables, the information for them is output
1343 when we do our recursive traversal of the tree representation for
1344 the entire containing function. In the case of file-scope variables,
1345 we output information for all of them at the very end of compilation
1346 while we are doing our final traversal of the chain of file-scope
1347 declarations. */
1348
1349 #if 0 /* ??? We should either delete this or add a comment describing what
1350 it was intended to do and why we shouldn't delete it. */
1351 if (flag_shared_data)
1352 data_section ();
1353 #endif
1354
1355 if (TREE_PUBLIC (decl)
1356 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1357 && DECL_COMMON (decl)
1358 #endif
1359 )
1360 {
1361 #ifdef ASM_OUTPUT_SHARED_COMMON
1362 if (flag_shared_data)
1363 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1364 else
1365 #endif
1366 {
1367 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1368 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1369 DECL_ALIGN (decl));
1370 #else
1371 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1372 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1373 DECL_ALIGN (decl));
1374 #else
1375 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1376 #endif
1377 #endif
1378 }
1379 }
1380 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1381 else if (TREE_PUBLIC (decl))
1382 {
1383 #ifdef ASM_OUTPUT_SHARED_BSS
1384 if (flag_shared_data)
1385 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1386 else
1387 #endif
1388 {
1389 #ifdef ASM_OUTPUT_ALIGNED_BSS
1390 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1391 DECL_ALIGN (decl));
1392 #else
1393 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1394 #endif
1395 }
1396 }
1397 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1398 else
1399 {
1400 #ifdef ASM_OUTPUT_SHARED_LOCAL
1401 if (flag_shared_data)
1402 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1403 else
1404 #endif
1405 {
1406 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1407 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1408 DECL_ALIGN (decl));
1409 #else
1410 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1411 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1412 DECL_ALIGN (decl));
1413 #else
1414 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1415 #endif
1416 #endif
1417 }
1418 }
1419 goto finish;
1420 }
1421
1422 /* Handle initialized definitions.
1423 Also handle uninitialized global definitions if -fno-common and the
1424 target doesn't support ASM_OUTPUT_BSS. */
1425
1426 /* First make the assembler name(s) global if appropriate. */
1427 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1428 {
1429 #ifdef ASM_WEAKEN_LABEL
1430 if (DECL_WEAK (decl))
1431 ASM_WEAKEN_LABEL (asm_out_file, name);
1432 else
1433 #endif
1434 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1435 }
1436 #if 0
1437 for (d = equivalents; d; d = TREE_CHAIN (d))
1438 {
1439 tree e = TREE_VALUE (d);
1440 if (TREE_PUBLIC (e) && DECL_NAME (e))
1441 ASM_GLOBALIZE_LABEL (asm_out_file,
1442 XSTR (XEXP (DECL_RTL (e), 0), 0));
1443 }
1444 #endif
1445
1446 /* Output any data that we will need to use the address of. */
1447 if (DECL_INITIAL (decl) == error_mark_node)
1448 reloc = contains_pointers_p (TREE_TYPE (decl));
1449 else if (DECL_INITIAL (decl))
1450 reloc = output_addressed_constants (DECL_INITIAL (decl));
1451
1452 #ifdef ASM_OUTPUT_SECTION_NAME
1453 if ((flag_data_sections != 0
1454 && DECL_SECTION_NAME (decl) == NULL_TREE)
1455 || UNIQUE_SECTION_P (decl))
1456 UNIQUE_SECTION (decl, reloc);
1457 #endif
1458
1459 /* Switch to the appropriate section. */
1460 variable_section (decl, reloc);
1461
1462 /* dbxout.c needs to know this. */
1463 if (in_text_section ())
1464 DECL_IN_TEXT_SECTION (decl) = 1;
1465
1466 /* Record current section so we can restore it if dbxout.c clobbers it. */
1467 saved_in_section = in_section;
1468
1469 /* Output the dbx info now that we have chosen the section. */
1470
1471 #ifdef DBX_DEBUGGING_INFO
1472 /* File-scope global variables are output here. */
1473 if (write_symbols == DBX_DEBUG && top_level)
1474 dbxout_symbol (decl, 0);
1475 #endif
1476 #ifdef SDB_DEBUGGING_INFO
1477 if (write_symbols == SDB_DEBUG && top_level
1478 /* Leave initialized global vars for end of compilation;
1479 see comment in compile_file. */
1480 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1481 sdbout_symbol (decl, 0);
1482 #endif
1483
1484 /* Don't output any DWARF debugging information for variables here.
1485 In the case of local variables, the information for them is output
1486 when we do our recursive traversal of the tree representation for
1487 the entire containing function. In the case of file-scope variables,
1488 we output information for all of them at the very end of compilation
1489 while we are doing our final traversal of the chain of file-scope
1490 declarations. */
1491
1492 /* If the debugging output changed sections, reselect the section
1493 that's supposed to be selected. */
1494 if (in_section != saved_in_section)
1495 variable_section (decl, reloc);
1496
1497 /* Output the alignment of this data. */
1498 if (align > BITS_PER_UNIT)
1499 ASM_OUTPUT_ALIGN (asm_out_file,
1500 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1501
1502 /* Do any machine/system dependent processing of the object. */
1503 #ifdef ASM_DECLARE_OBJECT_NAME
1504 last_assemble_variable_decl = decl;
1505 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1506 #else
1507 /* Standard thing is just output label for the object. */
1508 ASM_OUTPUT_LABEL (asm_out_file, name);
1509 #endif /* ASM_DECLARE_OBJECT_NAME */
1510
1511 if (!dont_output_data)
1512 {
1513 if (DECL_INITIAL (decl))
1514 /* Output the actual data. */
1515 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1516 else
1517 /* Leave space for it. */
1518 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1519 }
1520
1521 finish:
1522 #ifdef XCOFF_DEBUGGING_INFO
1523 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1524 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1525 and `aa' hasn't been output yet, the assembler generates a stab entry with
1526 a value of zero, in addition to creating an unnecessary external entry
1527 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1528
1529 /* File-scope global variables are output here. */
1530 if (write_symbols == XCOFF_DEBUG && top_level)
1531 {
1532 saved_in_section = in_section;
1533
1534 dbxout_symbol (decl, 0);
1535
1536 if (in_section != saved_in_section)
1537 variable_section (decl, reloc);
1538 }
1539 #else
1540 /* There must be a statement after a label. */
1541 ;
1542 #endif
1543 }
1544
1545 /* Return 1 if type TYPE contains any pointers. */
1546
1547 static int
1548 contains_pointers_p (type)
1549 tree type;
1550 {
1551 switch (TREE_CODE (type))
1552 {
1553 case POINTER_TYPE:
1554 case REFERENCE_TYPE:
1555 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1556 so I'll play safe and return 1. */
1557 case OFFSET_TYPE:
1558 return 1;
1559
1560 case RECORD_TYPE:
1561 case UNION_TYPE:
1562 case QUAL_UNION_TYPE:
1563 {
1564 tree fields;
1565 /* For a type that has fields, see if the fields have pointers. */
1566 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1567 if (TREE_CODE (fields) == FIELD_DECL
1568 && contains_pointers_p (TREE_TYPE (fields)))
1569 return 1;
1570 return 0;
1571 }
1572
1573 case ARRAY_TYPE:
1574 /* An array type contains pointers if its element type does. */
1575 return contains_pointers_p (TREE_TYPE (type));
1576
1577 default:
1578 return 0;
1579 }
1580 }
1581
1582 /* Output something to declare an external symbol to the assembler.
1583 (Most assemblers don't need this, so we normally output nothing.)
1584 Do nothing if DECL is not external. */
1585
1586 void
1587 assemble_external (decl)
1588 tree decl;
1589 {
1590 #ifdef ASM_OUTPUT_EXTERNAL
1591 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1592 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1593 {
1594 rtx rtl = DECL_RTL (decl);
1595
1596 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1597 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1598 {
1599 /* Some systems do require some output. */
1600 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1601 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1602 }
1603 }
1604 #endif
1605 }
1606
1607 /* Similar, for calling a library function FUN. */
1608
1609 void
1610 assemble_external_libcall (fun)
1611 rtx fun;
1612 {
1613 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1614 /* Declare library function name external when first used, if nec. */
1615 if (! SYMBOL_REF_USED (fun))
1616 {
1617 SYMBOL_REF_USED (fun) = 1;
1618 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1619 }
1620 #endif
1621 }
1622
1623 /* Declare the label NAME global. */
1624
1625 void
1626 assemble_global (name)
1627 char *name;
1628 {
1629 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1630 }
1631
1632 /* Assemble a label named NAME. */
1633
1634 void
1635 assemble_label (name)
1636 char *name;
1637 {
1638 ASM_OUTPUT_LABEL (asm_out_file, name);
1639 }
1640
1641 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1642 If NAME starts with a *, the rest of NAME is output verbatim.
1643 Otherwise NAME is transformed in an implementation-defined way
1644 (usually by the addition of an underscore).
1645 Many macros in the tm file are defined to call this function. */
1646
1647 void
1648 assemble_name (file, name)
1649 FILE *file;
1650 char *name;
1651 {
1652 char *real_name;
1653 tree id;
1654
1655 STRIP_NAME_ENCODING (real_name, name);
1656 if (flag_prefix_function_name
1657 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1658 real_name = real_name + CHKR_PREFIX_SIZE;
1659
1660 id = maybe_get_identifier (real_name);
1661 if (id)
1662 TREE_SYMBOL_REFERENCED (id) = 1;
1663
1664 if (name[0] == '*')
1665 fputs (&name[1], file);
1666 else
1667 ASM_OUTPUT_LABELREF (file, name);
1668 }
1669
1670 /* Allocate SIZE bytes writable static space with a gensym name
1671 and return an RTX to refer to its address. */
1672
1673 rtx
1674 assemble_static_space (size)
1675 int size;
1676 {
1677 char name[12];
1678 char *namestring;
1679 rtx x;
1680
1681 #if 0
1682 if (flag_shared_data)
1683 data_section ();
1684 #endif
1685
1686 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1687 ++const_labelno;
1688
1689 namestring = (char *) obstack_alloc (saveable_obstack,
1690 strlen (name) + 2);
1691 strcpy (namestring, name);
1692
1693 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1694
1695 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1696 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1697 BIGGEST_ALIGNMENT);
1698 #else
1699 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1700 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1701 #else
1702 {
1703 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1704 so that each uninitialized object starts on such a boundary. */
1705 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1706 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1707 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1708 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1709 }
1710 #endif
1711 #endif
1712 return x;
1713 }
1714
1715 /* Assemble the static constant template for function entry trampolines.
1716 This is done at most once per compilation.
1717 Returns an RTX for the address of the template. */
1718
1719 #ifdef TRAMPOLINE_TEMPLATE
1720 rtx
1721 assemble_trampoline_template ()
1722 {
1723 char label[256];
1724 char *name;
1725 int align;
1726
1727 /* By default, put trampoline templates in read-only data section. */
1728
1729 #ifdef TRAMPOLINE_SECTION
1730 TRAMPOLINE_SECTION ();
1731 #else
1732 readonly_data_section ();
1733 #endif
1734
1735 /* Write the assembler code to define one. */
1736 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1737 if (align > 0)
1738 ASM_OUTPUT_ALIGN (asm_out_file, align);
1739
1740 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1741 TRAMPOLINE_TEMPLATE (asm_out_file);
1742
1743 /* Record the rtl to refer to it. */
1744 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1745 name
1746 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1747 return gen_rtx_SYMBOL_REF (Pmode, name);
1748 }
1749 #endif
1750 \f
1751 /* Assemble the integer constant X into an object of SIZE bytes.
1752 X must be either a CONST_INT or CONST_DOUBLE.
1753
1754 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1755 non-zero, abort if we can't output the constant. */
1756
1757 int
1758 assemble_integer (x, size, force)
1759 rtx x;
1760 int size;
1761 int force;
1762 {
1763 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1764 ASM_OUTPUT... macros. */
1765
1766 switch (size)
1767 {
1768 #ifdef ASM_OUTPUT_CHAR
1769 case 1:
1770 ASM_OUTPUT_CHAR (asm_out_file, x);
1771 return 1;
1772 #endif
1773
1774 #ifdef ASM_OUTPUT_SHORT
1775 case 2:
1776 ASM_OUTPUT_SHORT (asm_out_file, x);
1777 return 1;
1778 #endif
1779
1780 #ifdef ASM_OUTPUT_INT
1781 case 4:
1782 ASM_OUTPUT_INT (asm_out_file, x);
1783 return 1;
1784 #endif
1785
1786 #ifdef ASM_OUTPUT_DOUBLE_INT
1787 case 8:
1788 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1789 return 1;
1790 #endif
1791
1792 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1793 case 16:
1794 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1795 return 1;
1796 #endif
1797 }
1798
1799 /* If we couldn't do it that way, there are two other possibilities: First,
1800 if the machine can output an explicit byte and this is a 1 byte constant,
1801 we can use ASM_OUTPUT_BYTE. */
1802
1803 #ifdef ASM_OUTPUT_BYTE
1804 if (size == 1 && GET_CODE (x) == CONST_INT)
1805 {
1806 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1807 return 1;
1808 }
1809 #endif
1810
1811 /* Finally, if SIZE is larger than a single word, try to output the constant
1812 one word at a time. */
1813
1814 if (size > UNITS_PER_WORD)
1815 {
1816 int i;
1817 enum machine_mode mode
1818 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1819 rtx word;
1820
1821 for (i = 0; i < size / UNITS_PER_WORD; i++)
1822 {
1823 word = operand_subword (x, i, 0, mode);
1824
1825 if (word == 0)
1826 break;
1827
1828 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1829 break;
1830 }
1831
1832 if (i == size / UNITS_PER_WORD)
1833 return 1;
1834 /* If we output at least one word and then could not finish,
1835 there is no valid way to continue. */
1836 if (i > 0)
1837 abort ();
1838 }
1839
1840 if (force)
1841 abort ();
1842
1843 return 0;
1844 }
1845 \f
1846 /* Assemble the floating-point constant D into an object of size MODE. */
1847
1848 void
1849 assemble_real (d, mode)
1850 REAL_VALUE_TYPE d;
1851 enum machine_mode mode;
1852 {
1853 jmp_buf output_constant_handler;
1854
1855 if (setjmp (output_constant_handler))
1856 {
1857 error ("floating point trap outputting a constant");
1858 #ifdef REAL_IS_NOT_DOUBLE
1859 bzero ((char *) &d, sizeof d);
1860 d = dconst0;
1861 #else
1862 d = 0;
1863 #endif
1864 }
1865
1866 set_float_handler (output_constant_handler);
1867
1868 switch (mode)
1869 {
1870 #ifdef ASM_OUTPUT_BYTE_FLOAT
1871 case QFmode:
1872 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1873 break;
1874 #endif
1875 #ifdef ASM_OUTPUT_SHORT_FLOAT
1876 case HFmode:
1877 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1878 break;
1879 #endif
1880 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1881 case TQFmode:
1882 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1883 break;
1884 #endif
1885 #ifdef ASM_OUTPUT_FLOAT
1886 case SFmode:
1887 ASM_OUTPUT_FLOAT (asm_out_file, d);
1888 break;
1889 #endif
1890
1891 #ifdef ASM_OUTPUT_DOUBLE
1892 case DFmode:
1893 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1894 break;
1895 #endif
1896
1897 #ifdef ASM_OUTPUT_LONG_DOUBLE
1898 case XFmode:
1899 case TFmode:
1900 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1901 break;
1902 #endif
1903
1904 default:
1905 abort ();
1906 }
1907
1908 set_float_handler (NULL_PTR);
1909 }
1910 \f
1911 /* Here we combine duplicate floating constants to make
1912 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1913
1914 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1915 They are chained through the CONST_DOUBLE_CHAIN.
1916 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1917 In that case, CONST_DOUBLE_MEM is either a MEM,
1918 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1919
1920 (CONST_DOUBLE_MEM is used only for top-level functions.
1921 See force_const_mem for explanation.) */
1922
1923 static rtx const_double_chain;
1924
1925 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1926 For an integer, I0 is the low-order word and I1 is the high-order word.
1927 For a real number, I0 is the word with the low address
1928 and I1 is the word with the high address. */
1929
1930 rtx
1931 immed_double_const (i0, i1, mode)
1932 HOST_WIDE_INT i0, i1;
1933 enum machine_mode mode;
1934 {
1935 register rtx r;
1936
1937 if (GET_MODE_CLASS (mode) == MODE_INT
1938 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1939 {
1940 /* We clear out all bits that don't belong in MODE, unless they and our
1941 sign bit are all one. So we get either a reasonable negative value
1942 or a reasonable unsigned value for this mode. */
1943 int width = GET_MODE_BITSIZE (mode);
1944 if (width < HOST_BITS_PER_WIDE_INT
1945 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1946 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1947 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1948 else if (width == HOST_BITS_PER_WIDE_INT
1949 && ! (i1 == ~0 && i0 < 0))
1950 i1 = 0;
1951 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1952 /* We cannot represent this value as a constant. */
1953 abort ();
1954
1955 /* If this would be an entire word for the target, but is not for
1956 the host, then sign-extend on the host so that the number will look
1957 the same way on the host that it would on the target.
1958
1959 For example, when building a 64 bit alpha hosted 32 bit sparc
1960 targeted compiler, then we want the 32 bit unsigned value -1 to be
1961 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1962 The later confuses the sparc backend. */
1963
1964 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1965 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1966 i0 |= ((HOST_WIDE_INT) (-1) << width);
1967
1968 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1969
1970 ??? Strictly speaking, this is wrong if we create a CONST_INT
1971 for a large unsigned constant with the size of MODE being
1972 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1973 wider mode. In that case we will mis-interpret it as a negative
1974 number.
1975
1976 Unfortunately, the only alternative is to make a CONST_DOUBLE
1977 for any constant in any mode if it is an unsigned constant larger
1978 than the maximum signed integer in an int on the host. However,
1979 doing this will break everyone that always expects to see a CONST_INT
1980 for SImode and smaller.
1981
1982 We have always been making CONST_INTs in this case, so nothing new
1983 is being broken. */
1984
1985 if (width <= HOST_BITS_PER_WIDE_INT)
1986 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
1987
1988 /* If this integer fits in one word, return a CONST_INT. */
1989 if ((i1 == 0 && i0 >= 0)
1990 || (i1 == ~0 && i0 < 0))
1991 return GEN_INT (i0);
1992
1993 /* We use VOIDmode for integers. */
1994 mode = VOIDmode;
1995 }
1996
1997 /* Search the chain for an existing CONST_DOUBLE with the right value.
1998 If one is found, return it. */
1999
2000 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2001 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2002 && GET_MODE (r) == mode)
2003 return r;
2004
2005 /* No; make a new one and add it to the chain.
2006
2007 We may be called by an optimizer which may be discarding any memory
2008 allocated during its processing (such as combine and loop). However,
2009 we will be leaving this constant on the chain, so we cannot tolerate
2010 freed memory. So switch to saveable_obstack for this allocation
2011 and then switch back if we were in current_obstack. */
2012
2013 push_obstacks_nochange ();
2014 rtl_in_saveable_obstack ();
2015 r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2016 pop_obstacks ();
2017
2018 /* Don't touch const_double_chain in nested function; see force_const_mem.
2019 Also, don't touch it if not inside any function. */
2020 if (outer_function_chain == 0 && current_function_decl != 0)
2021 {
2022 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2023 const_double_chain = r;
2024 }
2025
2026 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2027 Actual use of mem-slot is only through force_const_mem. */
2028
2029 CONST_DOUBLE_MEM (r) = const0_rtx;
2030
2031 return r;
2032 }
2033
2034 /* Return a CONST_DOUBLE for a specified `double' value
2035 and machine mode. */
2036
2037 rtx
2038 immed_real_const_1 (d, mode)
2039 REAL_VALUE_TYPE d;
2040 enum machine_mode mode;
2041 {
2042 union real_extract u;
2043 register rtx r;
2044
2045 /* Get the desired `double' value as a sequence of ints
2046 since that is how they are stored in a CONST_DOUBLE. */
2047
2048 u.d = d;
2049
2050 /* Detect special cases. */
2051
2052 if (REAL_VALUES_IDENTICAL (dconst0, d))
2053 return CONST0_RTX (mode);
2054 /* Check for NaN first, because some ports (specifically the i386) do not
2055 emit correct ieee-fp code by default, and thus will generate a core
2056 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2057 does a floating point comparison. */
2058 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2059 return CONST1_RTX (mode);
2060
2061 if (sizeof u == sizeof (HOST_WIDE_INT))
2062 return immed_double_const (u.i[0], 0, mode);
2063 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2064 return immed_double_const (u.i[0], u.i[1], mode);
2065
2066 /* The rest of this function handles the case where
2067 a float value requires more than 2 ints of space.
2068 It will be deleted as dead code on machines that don't need it. */
2069
2070 /* Search the chain for an existing CONST_DOUBLE with the right value.
2071 If one is found, return it. */
2072
2073 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2074 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2075 && GET_MODE (r) == mode)
2076 return r;
2077
2078 /* No; make a new one and add it to the chain.
2079
2080 We may be called by an optimizer which may be discarding any memory
2081 allocated during its processing (such as combine and loop). However,
2082 we will be leaving this constant on the chain, so we cannot tolerate
2083 freed memory. So switch to saveable_obstack for this allocation
2084 and then switch back if we were in current_obstack. */
2085
2086 push_obstacks_nochange ();
2087 rtl_in_saveable_obstack ();
2088 r = rtx_alloc (CONST_DOUBLE);
2089 PUT_MODE (r, mode);
2090 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2091 pop_obstacks ();
2092
2093 /* Don't touch const_double_chain in nested function; see force_const_mem.
2094 Also, don't touch it if not inside any function. */
2095 if (outer_function_chain == 0 && current_function_decl != 0)
2096 {
2097 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2098 const_double_chain = r;
2099 }
2100
2101 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2102 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2103 is only through force_const_mem. */
2104
2105 CONST_DOUBLE_MEM (r) = const0_rtx;
2106
2107 return r;
2108 }
2109
2110 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2111 which must be a REAL_CST tree node. */
2112
2113 rtx
2114 immed_real_const (exp)
2115 tree exp;
2116 {
2117 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2118 }
2119
2120 /* At the end of a function, forget the memory-constants
2121 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2122 Also clear out real_constant_chain and clear out all the chain-pointers. */
2123
2124 void
2125 clear_const_double_mem ()
2126 {
2127 register rtx r, next;
2128
2129 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2130 See force_const_mem for explanation. */
2131 if (outer_function_chain != 0)
2132 return;
2133
2134 for (r = const_double_chain; r; r = next)
2135 {
2136 next = CONST_DOUBLE_CHAIN (r);
2137 CONST_DOUBLE_CHAIN (r) = 0;
2138 CONST_DOUBLE_MEM (r) = cc0_rtx;
2139 }
2140 const_double_chain = 0;
2141 }
2142 \f
2143 /* Given an expression EXP with a constant value,
2144 reduce it to the sum of an assembler symbol and an integer.
2145 Store them both in the structure *VALUE.
2146 Abort if EXP does not reduce. */
2147
2148 struct addr_const
2149 {
2150 rtx base;
2151 HOST_WIDE_INT offset;
2152 };
2153
2154 static void
2155 decode_addr_const (exp, value)
2156 tree exp;
2157 struct addr_const *value;
2158 {
2159 register tree target = TREE_OPERAND (exp, 0);
2160 register int offset = 0;
2161 register rtx x;
2162
2163 while (1)
2164 {
2165 if (TREE_CODE (target) == COMPONENT_REF
2166 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2167 == INTEGER_CST))
2168 {
2169 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2170 target = TREE_OPERAND (target, 0);
2171 }
2172 else if (TREE_CODE (target) == ARRAY_REF)
2173 {
2174 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2175 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2176 abort ();
2177 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2178 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2179 / BITS_PER_UNIT);
2180 target = TREE_OPERAND (target, 0);
2181 }
2182 else
2183 break;
2184 }
2185
2186 switch (TREE_CODE (target))
2187 {
2188 case VAR_DECL:
2189 case FUNCTION_DECL:
2190 x = DECL_RTL (target);
2191 break;
2192
2193 case LABEL_DECL:
2194 x = gen_rtx_MEM (FUNCTION_MODE,
2195 gen_rtx_LABEL_REF (VOIDmode,
2196 label_rtx (TREE_OPERAND (exp, 0))));
2197 break;
2198
2199 case REAL_CST:
2200 case STRING_CST:
2201 case COMPLEX_CST:
2202 case CONSTRUCTOR:
2203 case INTEGER_CST:
2204 x = TREE_CST_RTL (target);
2205 break;
2206
2207 default:
2208 abort ();
2209 }
2210
2211 if (GET_CODE (x) != MEM)
2212 abort ();
2213 x = XEXP (x, 0);
2214
2215 value->base = x;
2216 value->offset = offset;
2217 }
2218 \f
2219 /* Uniquize all constants that appear in memory.
2220 Each constant in memory thus far output is recorded
2221 in `const_hash_table' with a `struct constant_descriptor'
2222 that contains a polish representation of the value of
2223 the constant.
2224
2225 We cannot store the trees in the hash table
2226 because the trees may be temporary. */
2227
2228 struct constant_descriptor
2229 {
2230 struct constant_descriptor *next;
2231 char *label;
2232 char contents[1];
2233 };
2234
2235 #define HASHBITS 30
2236 #define MAX_HASH_TABLE 1009
2237 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2238
2239 /* Compute a hash code for a constant expression. */
2240
2241 static int
2242 const_hash (exp)
2243 tree exp;
2244 {
2245 register char *p;
2246 register int len, hi, i;
2247 register enum tree_code code = TREE_CODE (exp);
2248
2249 /* Either set P and LEN to the address and len of something to hash and
2250 exit the switch or return a value. */
2251
2252 switch (code)
2253 {
2254 case INTEGER_CST:
2255 p = (char *) &TREE_INT_CST_LOW (exp);
2256 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2257 break;
2258
2259 case REAL_CST:
2260 p = (char *) &TREE_REAL_CST (exp);
2261 len = sizeof TREE_REAL_CST (exp);
2262 break;
2263
2264 case STRING_CST:
2265 p = TREE_STRING_POINTER (exp);
2266 len = TREE_STRING_LENGTH (exp);
2267 break;
2268
2269 case COMPLEX_CST:
2270 return (const_hash (TREE_REALPART (exp)) * 5
2271 + const_hash (TREE_IMAGPART (exp)));
2272
2273 case CONSTRUCTOR:
2274 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2275 {
2276 len = int_size_in_bytes (TREE_TYPE (exp));
2277 p = (char *) alloca (len);
2278 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2279 break;
2280 }
2281 else
2282 {
2283 register tree link;
2284
2285 /* For record type, include the type in the hashing.
2286 We do not do so for array types
2287 because (1) the sizes of the elements are sufficient
2288 and (2) distinct array types can have the same constructor.
2289 Instead, we include the array size because the constructor could
2290 be shorter. */
2291 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2292 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2293 % MAX_HASH_TABLE;
2294 else
2295 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2296 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2297
2298 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2299 if (TREE_VALUE (link))
2300 hi
2301 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2302
2303 return hi;
2304 }
2305
2306 case ADDR_EXPR:
2307 {
2308 struct addr_const value;
2309
2310 decode_addr_const (exp, &value);
2311 if (GET_CODE (value.base) == SYMBOL_REF)
2312 {
2313 /* Don't hash the address of the SYMBOL_REF;
2314 only use the offset and the symbol name. */
2315 hi = value.offset;
2316 p = XSTR (value.base, 0);
2317 for (i = 0; p[i] != 0; i++)
2318 hi = ((hi * 613) + (unsigned) (p[i]));
2319 }
2320 else if (GET_CODE (value.base) == LABEL_REF)
2321 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2322
2323 hi &= (1 << HASHBITS) - 1;
2324 hi %= MAX_HASH_TABLE;
2325 }
2326 return hi;
2327
2328 case PLUS_EXPR:
2329 case MINUS_EXPR:
2330 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2331 + const_hash (TREE_OPERAND (exp, 1)));
2332
2333 case NOP_EXPR:
2334 case CONVERT_EXPR:
2335 case NON_LVALUE_EXPR:
2336 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2337
2338 default:
2339 abort ();
2340 }
2341
2342 /* Compute hashing function */
2343 hi = len;
2344 for (i = 0; i < len; i++)
2345 hi = ((hi * 613) + (unsigned) (p[i]));
2346
2347 hi &= (1 << HASHBITS) - 1;
2348 hi %= MAX_HASH_TABLE;
2349 return hi;
2350 }
2351 \f
2352 /* Compare a constant expression EXP with a constant-descriptor DESC.
2353 Return 1 if DESC describes a constant with the same value as EXP. */
2354
2355 static int
2356 compare_constant (exp, desc)
2357 tree exp;
2358 struct constant_descriptor *desc;
2359 {
2360 return 0 != compare_constant_1 (exp, desc->contents);
2361 }
2362
2363 /* Compare constant expression EXP with a substring P of a constant descriptor.
2364 If they match, return a pointer to the end of the substring matched.
2365 If they do not match, return 0.
2366
2367 Since descriptors are written in polish prefix notation,
2368 this function can be used recursively to test one operand of EXP
2369 against a subdescriptor, and if it succeeds it returns the
2370 address of the subdescriptor for the next operand. */
2371
2372 static char *
2373 compare_constant_1 (exp, p)
2374 tree exp;
2375 char *p;
2376 {
2377 register char *strp;
2378 register int len;
2379 register enum tree_code code = TREE_CODE (exp);
2380
2381 if (code != (enum tree_code) *p++)
2382 return 0;
2383
2384 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2385 switch, or return the result of the comparison. */
2386
2387 switch (code)
2388 {
2389 case INTEGER_CST:
2390 /* Integer constants are the same only if the same width of type. */
2391 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2392 return 0;
2393
2394 strp = (char *) &TREE_INT_CST_LOW (exp);
2395 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2396 break;
2397
2398 case REAL_CST:
2399 /* Real constants are the same only if the same width of type. */
2400 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2401 return 0;
2402
2403 strp = (char *) &TREE_REAL_CST (exp);
2404 len = sizeof TREE_REAL_CST (exp);
2405 break;
2406
2407 case STRING_CST:
2408 if (flag_writable_strings)
2409 return 0;
2410
2411 if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2412 return 0;
2413
2414 strp = TREE_STRING_POINTER (exp);
2415 len = TREE_STRING_LENGTH (exp);
2416 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2417 sizeof TREE_STRING_LENGTH (exp)))
2418 return 0;
2419
2420 p += sizeof TREE_STRING_LENGTH (exp);
2421 break;
2422
2423 case COMPLEX_CST:
2424 p = compare_constant_1 (TREE_REALPART (exp), p);
2425 if (p == 0)
2426 return 0;
2427
2428 return compare_constant_1 (TREE_IMAGPART (exp), p);
2429
2430 case CONSTRUCTOR:
2431 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2432 {
2433 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2434
2435 strp = (char *) alloca (len);
2436 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2437 if (bcmp ((char *) &xlen, p, sizeof xlen))
2438 return 0;
2439
2440 p += sizeof xlen;
2441 break;
2442 }
2443 else
2444 {
2445 register tree link;
2446 int length = list_length (CONSTRUCTOR_ELTS (exp));
2447 tree type;
2448 int have_purpose = 0;
2449
2450 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2451 if (TREE_PURPOSE (link))
2452 have_purpose = 1;
2453
2454 if (bcmp ((char *) &length, p, sizeof length))
2455 return 0;
2456
2457 p += sizeof length;
2458
2459 /* For record constructors, insist that the types match.
2460 For arrays, just verify both constructors are for arrays.
2461 Then insist that either both or none have any TREE_PURPOSE
2462 values. */
2463 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2464 type = TREE_TYPE (exp);
2465 else
2466 type = 0;
2467
2468 if (bcmp ((char *) &type, p, sizeof type))
2469 return 0;
2470
2471 p += sizeof type;
2472
2473 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2474 return 0;
2475
2476 p += sizeof have_purpose;
2477
2478 /* For arrays, insist that the size in bytes match. */
2479 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2480 {
2481 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2482
2483 if (bcmp ((char *) &size, p, sizeof size))
2484 return 0;
2485
2486 p += sizeof size;
2487 }
2488
2489 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2490 {
2491 if (TREE_VALUE (link))
2492 {
2493 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2494 return 0;
2495 }
2496 else
2497 {
2498 tree zero = 0;
2499
2500 if (bcmp ((char *) &zero, p, sizeof zero))
2501 return 0;
2502
2503 p += sizeof zero;
2504 }
2505
2506 if (TREE_PURPOSE (link)
2507 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2508 {
2509 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2510 sizeof TREE_PURPOSE (link)))
2511 return 0;
2512
2513 p += sizeof TREE_PURPOSE (link);
2514 }
2515 else if (TREE_PURPOSE (link))
2516 {
2517 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2518 return 0;
2519 }
2520 else if (have_purpose)
2521 {
2522 int zero = 0;
2523
2524 if (bcmp ((char *) &zero, p, sizeof zero))
2525 return 0;
2526
2527 p += sizeof zero;
2528 }
2529 }
2530
2531 return p;
2532 }
2533
2534 case ADDR_EXPR:
2535 {
2536 struct addr_const value;
2537
2538 decode_addr_const (exp, &value);
2539 strp = (char *) &value.offset;
2540 len = sizeof value.offset;
2541 /* Compare the offset. */
2542 while (--len >= 0)
2543 if (*p++ != *strp++)
2544 return 0;
2545
2546 /* Compare symbol name. */
2547 strp = XSTR (value.base, 0);
2548 len = strlen (strp) + 1;
2549 }
2550 break;
2551
2552 case PLUS_EXPR:
2553 case MINUS_EXPR:
2554 case RANGE_EXPR:
2555 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2556 if (p == 0)
2557 return 0;
2558
2559 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2560
2561 case NOP_EXPR:
2562 case CONVERT_EXPR:
2563 case NON_LVALUE_EXPR:
2564 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2565
2566 default:
2567 abort ();
2568 }
2569
2570 /* Compare constant contents. */
2571 while (--len >= 0)
2572 if (*p++ != *strp++)
2573 return 0;
2574
2575 return p;
2576 }
2577 \f
2578 /* Construct a constant descriptor for the expression EXP.
2579 It is up to the caller to enter the descriptor in the hash table. */
2580
2581 static struct constant_descriptor *
2582 record_constant (exp)
2583 tree exp;
2584 {
2585 struct constant_descriptor *next = 0;
2586 char *label = 0;
2587
2588 /* Make a struct constant_descriptor. The first two pointers will
2589 be filled in later. Here we just leave space for them. */
2590
2591 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2592 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2593 record_constant_1 (exp);
2594 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2595 }
2596
2597 /* Add a description of constant expression EXP
2598 to the object growing in `permanent_obstack'.
2599 No need to return its address; the caller will get that
2600 from the obstack when the object is complete. */
2601
2602 static void
2603 record_constant_1 (exp)
2604 tree exp;
2605 {
2606 register char *strp;
2607 register int len;
2608 register enum tree_code code = TREE_CODE (exp);
2609
2610 obstack_1grow (&permanent_obstack, (unsigned int) code);
2611
2612 switch (code)
2613 {
2614 case INTEGER_CST:
2615 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2616 strp = (char *) &TREE_INT_CST_LOW (exp);
2617 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2618 break;
2619
2620 case REAL_CST:
2621 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2622 strp = (char *) &TREE_REAL_CST (exp);
2623 len = sizeof TREE_REAL_CST (exp);
2624 break;
2625
2626 case STRING_CST:
2627 if (flag_writable_strings)
2628 return;
2629
2630 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2631 strp = TREE_STRING_POINTER (exp);
2632 len = TREE_STRING_LENGTH (exp);
2633 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2634 sizeof TREE_STRING_LENGTH (exp));
2635 break;
2636
2637 case COMPLEX_CST:
2638 record_constant_1 (TREE_REALPART (exp));
2639 record_constant_1 (TREE_IMAGPART (exp));
2640 return;
2641
2642 case CONSTRUCTOR:
2643 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2644 {
2645 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2646 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2647 obstack_blank (&permanent_obstack, nbytes);
2648 get_set_constructor_bytes
2649 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2650 nbytes);
2651 return;
2652 }
2653 else
2654 {
2655 register tree link;
2656 int length = list_length (CONSTRUCTOR_ELTS (exp));
2657 tree type;
2658 int have_purpose = 0;
2659
2660 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2661 if (TREE_PURPOSE (link))
2662 have_purpose = 1;
2663
2664 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2665
2666 /* For record constructors, insist that the types match.
2667 For arrays, just verify both constructors are for arrays.
2668 Then insist that either both or none have any TREE_PURPOSE
2669 values. */
2670 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2671 type = TREE_TYPE (exp);
2672 else
2673 type = 0;
2674 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2675 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2676 sizeof have_purpose);
2677
2678 /* For arrays, insist that the size in bytes match. */
2679 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2680 {
2681 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2682 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2683 }
2684
2685 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2686 {
2687 if (TREE_VALUE (link))
2688 record_constant_1 (TREE_VALUE (link));
2689 else
2690 {
2691 tree zero = 0;
2692
2693 obstack_grow (&permanent_obstack,
2694 (char *) &zero, sizeof zero);
2695 }
2696
2697 if (TREE_PURPOSE (link)
2698 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2699 obstack_grow (&permanent_obstack,
2700 (char *) &TREE_PURPOSE (link),
2701 sizeof TREE_PURPOSE (link));
2702 else if (TREE_PURPOSE (link))
2703 record_constant_1 (TREE_PURPOSE (link));
2704 else if (have_purpose)
2705 {
2706 int zero = 0;
2707
2708 obstack_grow (&permanent_obstack,
2709 (char *) &zero, sizeof zero);
2710 }
2711 }
2712 }
2713 return;
2714
2715 case ADDR_EXPR:
2716 {
2717 struct addr_const value;
2718
2719 decode_addr_const (exp, &value);
2720 /* Record the offset. */
2721 obstack_grow (&permanent_obstack,
2722 (char *) &value.offset, sizeof value.offset);
2723 /* Record the symbol name. */
2724 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2725 strlen (XSTR (value.base, 0)) + 1);
2726 }
2727 return;
2728
2729 case PLUS_EXPR:
2730 case MINUS_EXPR:
2731 case RANGE_EXPR:
2732 record_constant_1 (TREE_OPERAND (exp, 0));
2733 record_constant_1 (TREE_OPERAND (exp, 1));
2734 return;
2735
2736 case NOP_EXPR:
2737 case CONVERT_EXPR:
2738 case NON_LVALUE_EXPR:
2739 record_constant_1 (TREE_OPERAND (exp, 0));
2740 return;
2741
2742 default:
2743 abort ();
2744 }
2745
2746 /* Record constant contents. */
2747 obstack_grow (&permanent_obstack, strp, len);
2748 }
2749 \f
2750 /* Record a list of constant expressions that were passed to
2751 output_constant_def but that could not be output right away. */
2752
2753 struct deferred_constant
2754 {
2755 struct deferred_constant *next;
2756 tree exp;
2757 int reloc;
2758 int labelno;
2759 };
2760
2761 static struct deferred_constant *deferred_constants;
2762
2763 /* Another list of constants which should be output after the
2764 function. */
2765 static struct deferred_constant *after_function_constants;
2766
2767 /* Nonzero means defer output of addressed subconstants
2768 (i.e., those for which output_constant_def is called.) */
2769 static int defer_addressed_constants_flag;
2770
2771 /* Start deferring output of subconstants. */
2772
2773 void
2774 defer_addressed_constants ()
2775 {
2776 defer_addressed_constants_flag++;
2777 }
2778
2779 /* Stop deferring output of subconstants,
2780 and output now all those that have been deferred. */
2781
2782 void
2783 output_deferred_addressed_constants ()
2784 {
2785 struct deferred_constant *p, *next;
2786
2787 defer_addressed_constants_flag--;
2788
2789 if (defer_addressed_constants_flag > 0)
2790 return;
2791
2792 for (p = deferred_constants; p; p = next)
2793 {
2794 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2795 next = p->next;
2796 free (p);
2797 }
2798
2799 deferred_constants = 0;
2800 }
2801
2802 /* Output any constants which should appear after a function. */
2803
2804 static void
2805 output_after_function_constants ()
2806 {
2807 struct deferred_constant *p, *next;
2808
2809 for (p = after_function_constants; p; p = next)
2810 {
2811 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2812 next = p->next;
2813 free (p);
2814 }
2815
2816 after_function_constants = 0;
2817 }
2818
2819 /* Make a copy of the whole tree structure for a constant.
2820 This handles the same types of nodes that compare_constant
2821 and record_constant handle. */
2822
2823 static tree
2824 copy_constant (exp)
2825 tree exp;
2826 {
2827 switch (TREE_CODE (exp))
2828 {
2829 case ADDR_EXPR:
2830 /* For ADDR_EXPR, we do not want to copy the decl whose address
2831 is requested. We do want to copy constants though. */
2832 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2833 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2834 copy_constant (TREE_OPERAND (exp, 0)));
2835 else
2836 return copy_node (exp);
2837
2838 case INTEGER_CST:
2839 case REAL_CST:
2840 case STRING_CST:
2841 return copy_node (exp);
2842
2843 case COMPLEX_CST:
2844 return build_complex (TREE_TYPE (exp),
2845 copy_constant (TREE_REALPART (exp)),
2846 copy_constant (TREE_IMAGPART (exp)));
2847
2848 case PLUS_EXPR:
2849 case MINUS_EXPR:
2850 return build (TREE_CODE (exp), TREE_TYPE (exp),
2851 copy_constant (TREE_OPERAND (exp, 0)),
2852 copy_constant (TREE_OPERAND (exp, 1)));
2853
2854 case NOP_EXPR:
2855 case CONVERT_EXPR:
2856 case NON_LVALUE_EXPR:
2857 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2858 copy_constant (TREE_OPERAND (exp, 0)));
2859
2860 case CONSTRUCTOR:
2861 {
2862 tree copy = copy_node (exp);
2863 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2864 tree tail;
2865
2866 CONSTRUCTOR_ELTS (copy) = list;
2867 for (tail = list; tail; tail = TREE_CHAIN (tail))
2868 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2869 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2870 for (tail = list; tail; tail = TREE_CHAIN (tail))
2871 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2872
2873 return copy;
2874 }
2875
2876 default:
2877 abort ();
2878 }
2879 }
2880 \f
2881 /* Return an rtx representing a reference to constant data in memory
2882 for the constant expression EXP.
2883
2884 If assembler code for such a constant has already been output,
2885 return an rtx to refer to it.
2886 Otherwise, output such a constant in memory (or defer it for later)
2887 and generate an rtx for it.
2888
2889 The TREE_CST_RTL of EXP is set up to point to that rtx.
2890 The const_hash_table records which constants already have label strings. */
2891
2892 rtx
2893 output_constant_def (exp)
2894 tree exp;
2895 {
2896 register int hash;
2897 register struct constant_descriptor *desc;
2898 char label[256];
2899 char *found = 0;
2900 int reloc;
2901 register rtx def;
2902
2903 if (TREE_CST_RTL (exp))
2904 return TREE_CST_RTL (exp);
2905
2906 /* Make sure any other constants whose addresses appear in EXP
2907 are assigned label numbers. */
2908
2909 reloc = output_addressed_constants (exp);
2910
2911 /* Compute hash code of EXP. Search the descriptors for that hash code
2912 to see if any of them describes EXP. If yes, the descriptor records
2913 the label number already assigned. */
2914
2915 hash = const_hash (exp) % MAX_HASH_TABLE;
2916
2917 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2918 if (compare_constant (exp, desc))
2919 {
2920 found = desc->label;
2921 break;
2922 }
2923
2924 if (found == 0)
2925 {
2926 /* No constant equal to EXP is known to have been output.
2927 Make a constant descriptor to enter EXP in the hash table.
2928 Assign the label number and record it in the descriptor for
2929 future calls to this function to find. */
2930
2931 /* Create a string containing the label name, in LABEL. */
2932 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2933
2934 desc = record_constant (exp);
2935 desc->next = const_hash_table[hash];
2936 desc->label
2937 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2938 const_hash_table[hash] = desc;
2939 }
2940 else
2941 {
2942 /* Create a string containing the label name, in LABEL. */
2943 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2944 }
2945
2946 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2947
2948 push_obstacks_nochange ();
2949 if (TREE_PERMANENT (exp))
2950 end_temporary_allocation ();
2951
2952 def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
2953
2954 TREE_CST_RTL (exp)
2955 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
2956 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2957 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2958 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2959
2960 pop_obstacks ();
2961
2962 /* Optionally set flags or add text to the name to record information
2963 such as that it is a function name. If the name is changed, the macro
2964 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2965 #ifdef ENCODE_SECTION_INFO
2966 ENCODE_SECTION_INFO (exp);
2967 #endif
2968
2969 /* If this is the first time we've seen this particular constant,
2970 output it (or defer its output for later). */
2971 if (found == 0)
2972 {
2973 int after_function = 0;
2974
2975 #ifdef CONSTANT_AFTER_FUNCTION_P
2976 if (current_function_decl != 0
2977 && CONSTANT_AFTER_FUNCTION_P (exp))
2978 after_function = 1;
2979 #endif
2980
2981 if (defer_addressed_constants_flag || after_function)
2982 {
2983 struct deferred_constant *p;
2984 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2985
2986 push_obstacks_nochange ();
2987 suspend_momentary ();
2988 p->exp = copy_constant (exp);
2989 pop_obstacks ();
2990 p->reloc = reloc;
2991 p->labelno = const_labelno++;
2992 if (after_function)
2993 {
2994 p->next = after_function_constants;
2995 after_function_constants = p;
2996 }
2997 else
2998 {
2999 p->next = deferred_constants;
3000 deferred_constants = p;
3001 }
3002 }
3003 else
3004 output_constant_def_contents (exp, reloc, const_labelno++);
3005 }
3006
3007 return TREE_CST_RTL (exp);
3008 }
3009
3010 /* Now output assembler code to define the label for EXP,
3011 and follow it with the data of EXP. */
3012
3013 static void
3014 output_constant_def_contents (exp, reloc, labelno)
3015 tree exp;
3016 int reloc;
3017 int labelno;
3018 {
3019 int align;
3020
3021 if (IN_NAMED_SECTION (exp))
3022 named_section (exp, NULL, reloc);
3023 else
3024 {
3025 /* First switch to text section, except for writable strings. */
3026 #ifdef SELECT_SECTION
3027 SELECT_SECTION (exp, reloc);
3028 #else
3029 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3030 || (flag_pic && reloc))
3031 data_section ();
3032 else
3033 readonly_data_section ();
3034 #endif
3035 }
3036
3037 /* Align the location counter as required by EXP's data type. */
3038 align = TYPE_ALIGN (TREE_TYPE (exp));
3039 #ifdef CONSTANT_ALIGNMENT
3040 align = CONSTANT_ALIGNMENT (exp, align);
3041 #endif
3042
3043 if (align > BITS_PER_UNIT)
3044 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3045
3046 /* Output the label itself. */
3047 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3048
3049 /* Output the value of EXP. */
3050 output_constant (exp,
3051 (TREE_CODE (exp) == STRING_CST
3052 ? TREE_STRING_LENGTH (exp)
3053 : int_size_in_bytes (TREE_TYPE (exp))));
3054
3055 }
3056 \f
3057 /* Similar hash facility for making memory-constants
3058 from constant rtl-expressions. It is used on RISC machines
3059 where immediate integer arguments and constant addresses are restricted
3060 so that such constants must be stored in memory.
3061
3062 This pool of constants is reinitialized for each function
3063 so each function gets its own constants-pool that comes right before it.
3064
3065 All structures allocated here are discarded when functions are saved for
3066 inlining, so they do not need to be allocated permanently. */
3067
3068 #define MAX_RTX_HASH_TABLE 61
3069 static struct constant_descriptor **const_rtx_hash_table;
3070
3071 /* Structure to represent sufficient information about a constant so that
3072 it can be output when the constant pool is output, so that function
3073 integration can be done, and to simplify handling on machines that reference
3074 constant pool as base+displacement. */
3075
3076 struct pool_constant
3077 {
3078 struct constant_descriptor *desc;
3079 struct pool_constant *next;
3080 enum machine_mode mode;
3081 rtx constant;
3082 int labelno;
3083 int align;
3084 int offset;
3085 int mark;
3086 };
3087
3088 /* Pointers to first and last constant in pool. */
3089
3090 static struct pool_constant *first_pool, *last_pool;
3091
3092 /* Current offset in constant pool (does not include any machine-specific
3093 header. */
3094
3095 static int pool_offset;
3096
3097 /* Structure used to maintain hash table mapping symbols used to their
3098 corresponding constants. */
3099
3100 struct pool_sym
3101 {
3102 char *label;
3103 struct pool_constant *pool;
3104 struct pool_sym *next;
3105 };
3106
3107 static struct pool_sym **const_rtx_sym_hash_table;
3108
3109 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3110 The argument is XSTR (... , 0) */
3111
3112 #define SYMHASH(LABEL) \
3113 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3114 \f
3115 /* Initialize constant pool hashing for next function. */
3116
3117 void
3118 init_const_rtx_hash_table ()
3119 {
3120 const_rtx_hash_table
3121 = ((struct constant_descriptor **)
3122 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3123 const_rtx_sym_hash_table
3124 = ((struct pool_sym **)
3125 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3126 bzero ((char *) const_rtx_hash_table,
3127 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3128 bzero ((char *) const_rtx_sym_hash_table,
3129 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3130
3131 first_pool = last_pool = 0;
3132 pool_offset = 0;
3133 }
3134
3135 /* Save and restore status for a nested function. */
3136
3137 void
3138 save_varasm_status (p, context)
3139 struct function *p;
3140 tree context;
3141 {
3142 p->const_rtx_hash_table = const_rtx_hash_table;
3143 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3144 p->first_pool = first_pool;
3145 p->last_pool = last_pool;
3146 p->pool_offset = pool_offset;
3147 p->const_double_chain = const_double_chain;
3148
3149 /* If we are pushing to toplevel, we can't reuse const_double_chain. */
3150 if (context == NULL_TREE)
3151 const_double_chain = 0;
3152 }
3153
3154 void
3155 restore_varasm_status (p)
3156 struct function *p;
3157 {
3158 const_rtx_hash_table = p->const_rtx_hash_table;
3159 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3160 first_pool = p->first_pool;
3161 last_pool = p->last_pool;
3162 pool_offset = p->pool_offset;
3163 const_double_chain = p->const_double_chain;
3164 }
3165 \f
3166 enum kind { RTX_DOUBLE, RTX_INT };
3167
3168 struct rtx_const
3169 {
3170 #ifdef ONLY_INT_FIELDS
3171 unsigned int kind : 16;
3172 unsigned int mode : 16;
3173 #else
3174 enum kind kind : 16;
3175 enum machine_mode mode : 16;
3176 #endif
3177 union {
3178 union real_extract du;
3179 struct addr_const addr;
3180 struct {HOST_WIDE_INT high, low;} di;
3181 } un;
3182 };
3183
3184 /* Express an rtx for a constant integer (perhaps symbolic)
3185 as the sum of a symbol or label plus an explicit integer.
3186 They are stored into VALUE. */
3187
3188 static void
3189 decode_rtx_const (mode, x, value)
3190 enum machine_mode mode;
3191 rtx x;
3192 struct rtx_const *value;
3193 {
3194 /* Clear the whole structure, including any gaps. */
3195
3196 {
3197 int *p = (int *) value;
3198 int *end = (int *) (value + 1);
3199 while (p < end)
3200 *p++ = 0;
3201 }
3202
3203 value->kind = RTX_INT; /* Most usual kind. */
3204 value->mode = mode;
3205
3206 switch (GET_CODE (x))
3207 {
3208 case CONST_DOUBLE:
3209 value->kind = RTX_DOUBLE;
3210 if (GET_MODE (x) != VOIDmode)
3211 {
3212 value->mode = GET_MODE (x);
3213 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3214 (char *) &value->un.du, sizeof value->un.du);
3215 }
3216 else
3217 {
3218 value->un.di.low = CONST_DOUBLE_LOW (x);
3219 value->un.di.high = CONST_DOUBLE_HIGH (x);
3220 }
3221 break;
3222
3223 case CONST_INT:
3224 value->un.addr.offset = INTVAL (x);
3225 break;
3226
3227 case SYMBOL_REF:
3228 case LABEL_REF:
3229 case PC:
3230 value->un.addr.base = x;
3231 break;
3232
3233 case CONST:
3234 x = XEXP (x, 0);
3235 if (GET_CODE (x) == PLUS)
3236 {
3237 value->un.addr.base = XEXP (x, 0);
3238 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3239 abort ();
3240 value->un.addr.offset = INTVAL (XEXP (x, 1));
3241 }
3242 else if (GET_CODE (x) == MINUS)
3243 {
3244 value->un.addr.base = XEXP (x, 0);
3245 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3246 abort ();
3247 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3248 }
3249 else
3250 abort ();
3251 break;
3252
3253 default:
3254 abort ();
3255 }
3256
3257 if (value->kind == RTX_INT && value->un.addr.base != 0)
3258 switch (GET_CODE (value->un.addr.base))
3259 {
3260 case SYMBOL_REF:
3261 case LABEL_REF:
3262 /* Use the string's address, not the SYMBOL_REF's address,
3263 for the sake of addresses of library routines.
3264 For a LABEL_REF, compare labels. */
3265 value->un.addr.base = XEXP (value->un.addr.base, 0);
3266
3267 default:
3268 break;
3269 }
3270 }
3271
3272 /* Given a MINUS expression, simplify it if both sides
3273 include the same symbol. */
3274
3275 rtx
3276 simplify_subtraction (x)
3277 rtx x;
3278 {
3279 struct rtx_const val0, val1;
3280
3281 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3282 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3283
3284 if (val0.un.addr.base == val1.un.addr.base)
3285 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3286 return x;
3287 }
3288
3289 /* Compute a hash code for a constant RTL expression. */
3290
3291 static int
3292 const_hash_rtx (mode, x)
3293 enum machine_mode mode;
3294 rtx x;
3295 {
3296 register int hi;
3297 register size_t i;
3298
3299 struct rtx_const value;
3300 decode_rtx_const (mode, x, &value);
3301
3302 /* Compute hashing function */
3303 hi = 0;
3304 for (i = 0; i < sizeof value / sizeof (int); i++)
3305 hi += ((int *) &value)[i];
3306
3307 hi &= (1 << HASHBITS) - 1;
3308 hi %= MAX_RTX_HASH_TABLE;
3309 return hi;
3310 }
3311
3312 /* Compare a constant rtl object X with a constant-descriptor DESC.
3313 Return 1 if DESC describes a constant with the same value as X. */
3314
3315 static int
3316 compare_constant_rtx (mode, x, desc)
3317 enum machine_mode mode;
3318 rtx x;
3319 struct constant_descriptor *desc;
3320 {
3321 register int *p = (int *) desc->contents;
3322 register int *strp;
3323 register int len;
3324 struct rtx_const value;
3325
3326 decode_rtx_const (mode, x, &value);
3327 strp = (int *) &value;
3328 len = sizeof value / sizeof (int);
3329
3330 /* Compare constant contents. */
3331 while (--len >= 0)
3332 if (*p++ != *strp++)
3333 return 0;
3334
3335 return 1;
3336 }
3337
3338 /* Construct a constant descriptor for the rtl-expression X.
3339 It is up to the caller to enter the descriptor in the hash table. */
3340
3341 static struct constant_descriptor *
3342 record_constant_rtx (mode, x)
3343 enum machine_mode mode;
3344 rtx x;
3345 {
3346 struct constant_descriptor *ptr;
3347 char *label;
3348 struct rtx_const value;
3349
3350 decode_rtx_const (mode, x, &value);
3351
3352 /* Put these things in the saveable obstack so we can ensure it won't
3353 be freed if we are called from combine or some other phase that discards
3354 memory allocated from function_obstack (current_obstack). */
3355 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3356 obstack_grow (saveable_obstack, &label, sizeof label);
3357
3358 /* Record constant contents. */
3359 obstack_grow (saveable_obstack, &value, sizeof value);
3360
3361 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3362 }
3363 \f
3364 /* Given a constant rtx X, make (or find) a memory constant for its value
3365 and return a MEM rtx to refer to it in memory. */
3366
3367 rtx
3368 force_const_mem (mode, x)
3369 enum machine_mode mode;
3370 rtx x;
3371 {
3372 register int hash;
3373 register struct constant_descriptor *desc;
3374 char label[256];
3375 char *found = 0;
3376 rtx def;
3377
3378 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3379 (this will always be true for floating CONST_DOUBLEs that have been
3380 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3381 use the previous copy. Otherwise, make a new one. Note that in
3382 the unlikely event that this same CONST_DOUBLE is used in two different
3383 modes in an alternating fashion, we will allocate a lot of different
3384 memory locations, but this should be extremely rare. */
3385
3386 /* Don't use CONST_DOUBLE_MEM in a nested function.
3387 Nested functions have their own constant pools,
3388 so they can't share the same values in CONST_DOUBLE_MEM
3389 with the containing function. */
3390 if (outer_function_chain == 0)
3391 if (GET_CODE (x) == CONST_DOUBLE
3392 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3393 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3394 return CONST_DOUBLE_MEM (x);
3395
3396 /* Compute hash code of X. Search the descriptors for that hash code
3397 to see if any of them describes X. If yes, the descriptor records
3398 the label number already assigned. */
3399
3400 hash = const_hash_rtx (mode, x);
3401
3402 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3403 if (compare_constant_rtx (mode, x, desc))
3404 {
3405 found = desc->label;
3406 break;
3407 }
3408
3409 if (found == 0)
3410 {
3411 register struct pool_constant *pool;
3412 register struct pool_sym *sym;
3413 int align;
3414
3415 /* No constant equal to X is known to have been output.
3416 Make a constant descriptor to enter X in the hash table.
3417 Assign the label number and record it in the descriptor for
3418 future calls to this function to find. */
3419
3420 desc = record_constant_rtx (mode, x);
3421 desc->next = const_rtx_hash_table[hash];
3422 const_rtx_hash_table[hash] = desc;
3423
3424 /* Align the location counter as required by EXP's data type. */
3425 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3426 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3427 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3428 #ifdef CONSTANT_ALIGNMENT
3429 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3430 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3431 #endif
3432
3433 pool_offset += align - 1;
3434 pool_offset &= ~ (align - 1);
3435
3436 /* If RTL is not being placed into the saveable obstack, make a
3437 copy of X that is in the saveable obstack in case we are
3438 being called from combine or some other phase that discards
3439 memory it allocates. We used to only do this if it is a
3440 CONST; however, reload can allocate a CONST_INT when
3441 eliminating registers. */
3442 if (rtl_obstack != saveable_obstack
3443 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3444 {
3445 push_obstacks_nochange ();
3446 rtl_in_saveable_obstack ();
3447
3448 if (GET_CODE (x) == CONST)
3449 x = gen_rtx_CONST (GET_MODE (x),
3450 gen_rtx_PLUS (GET_MODE (x),
3451 XEXP (XEXP (x, 0), 0),
3452 XEXP (XEXP (x, 0), 1)));
3453 else
3454 x = GEN_INT (INTVAL (x));
3455
3456 pop_obstacks ();
3457 }
3458
3459 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3460
3461 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3462 pool->desc = desc;
3463 pool->constant = x;
3464 pool->mode = mode;
3465 pool->labelno = const_labelno;
3466 pool->align = align;
3467 pool->offset = pool_offset;
3468 pool->mark = 1;
3469 pool->next = 0;
3470
3471 if (last_pool == 0)
3472 first_pool = pool;
3473 else
3474 last_pool->next = pool;
3475
3476 last_pool = pool;
3477 pool_offset += GET_MODE_SIZE (mode);
3478
3479 /* Create a string containing the label name, in LABEL. */
3480 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3481
3482 ++const_labelno;
3483
3484 desc->label = found
3485 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3486
3487 /* Add label to symbol hash table. */
3488 hash = SYMHASH (found);
3489 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3490 sym->label = found;
3491 sym->pool = pool;
3492 sym->next = const_rtx_sym_hash_table[hash];
3493 const_rtx_sym_hash_table[hash] = sym;
3494 }
3495
3496 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3497
3498 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3499
3500 RTX_UNCHANGING_P (def) = 1;
3501 /* Mark the symbol_ref as belonging to this constants pool. */
3502 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3503 current_function_uses_const_pool = 1;
3504
3505 if (outer_function_chain == 0)
3506 if (GET_CODE (x) == CONST_DOUBLE)
3507 {
3508 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3509 {
3510 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3511 const_double_chain = x;
3512 }
3513 CONST_DOUBLE_MEM (x) = def;
3514 }
3515
3516 return def;
3517 }
3518 \f
3519 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3520 the corresponding pool_constant structure. */
3521
3522 static struct pool_constant *
3523 find_pool_constant (addr)
3524 rtx addr;
3525 {
3526 struct pool_sym *sym;
3527 char *label = XSTR (addr, 0);
3528
3529 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3530 if (sym->label == label)
3531 return sym->pool;
3532
3533 abort ();
3534 }
3535
3536 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3537
3538 rtx
3539 get_pool_constant (addr)
3540 rtx addr;
3541 {
3542 return (find_pool_constant (addr))->constant;
3543 }
3544
3545 /* Similar, return the mode. */
3546
3547 enum machine_mode
3548 get_pool_mode (addr)
3549 rtx addr;
3550 {
3551 return (find_pool_constant (addr))->mode;
3552 }
3553
3554 /* Similar, return the offset in the constant pool. */
3555
3556 int
3557 get_pool_offset (addr)
3558 rtx addr;
3559 {
3560 return (find_pool_constant (addr))->offset;
3561 }
3562
3563 /* Return the size of the constant pool. */
3564
3565 int
3566 get_pool_size ()
3567 {
3568 return pool_offset;
3569 }
3570 \f
3571 /* Write all the constants in the constant pool. */
3572
3573 void
3574 output_constant_pool (fnname, fndecl)
3575 char *fnname;
3576 tree fndecl;
3577 {
3578 struct pool_constant *pool;
3579 rtx x;
3580 union real_extract u;
3581
3582 /* It is possible for gcc to call force_const_mem and then to later
3583 discard the instructions which refer to the constant. In such a
3584 case we do not need to output the constant. */
3585 if (optimize >= 0 && flag_expensive_optimizations)
3586 mark_constant_pool ();
3587
3588 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3589 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3590 #endif
3591
3592 for (pool = first_pool; pool; pool = pool->next)
3593 {
3594 x = pool->constant;
3595
3596 if (! pool->mark)
3597 continue;
3598
3599 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3600 whose CODE_LABEL has been deleted. This can occur if a jump table
3601 is eliminated by optimization. If so, write a constant of zero
3602 instead. Note that this can also happen by turning the
3603 CODE_LABEL into a NOTE. */
3604 if (((GET_CODE (x) == LABEL_REF
3605 && (INSN_DELETED_P (XEXP (x, 0))
3606 || GET_CODE (XEXP (x, 0)) == NOTE)))
3607 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3608 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3609 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3610 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3611 x = const0_rtx;
3612
3613 /* First switch to correct section. */
3614 #ifdef SELECT_RTX_SECTION
3615 SELECT_RTX_SECTION (pool->mode, x);
3616 #else
3617 readonly_data_section ();
3618 #endif
3619
3620 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3621 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3622 pool->align, pool->labelno, done);
3623 #endif
3624
3625 if (pool->align > 1)
3626 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3627
3628 /* Output the label. */
3629 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3630
3631 /* Output the value of the constant itself. */
3632 switch (GET_MODE_CLASS (pool->mode))
3633 {
3634 case MODE_FLOAT:
3635 if (GET_CODE (x) != CONST_DOUBLE)
3636 abort ();
3637
3638 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3639 assemble_real (u.d, pool->mode);
3640 break;
3641
3642 case MODE_INT:
3643 case MODE_PARTIAL_INT:
3644 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3645 break;
3646
3647 default:
3648 abort ();
3649 }
3650
3651 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3652 done: ;
3653 #endif
3654
3655 }
3656
3657 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3658 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3659 #endif
3660
3661 /* Done with this pool. */
3662 first_pool = last_pool = 0;
3663 }
3664
3665 /* Look through the instructions for this function, and mark all the
3666 entries in the constant pool which are actually being used. */
3667
3668 static void
3669 mark_constant_pool ()
3670 {
3671 register rtx insn;
3672 struct pool_constant *pool;
3673
3674 if (first_pool == 0)
3675 return;
3676
3677 for (pool = first_pool; pool; pool = pool->next)
3678 pool->mark = 0;
3679
3680 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3681 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3682 mark_constants (PATTERN (insn));
3683
3684 for (insn = current_function_epilogue_delay_list;
3685 insn;
3686 insn = XEXP (insn, 1))
3687 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3688 mark_constants (PATTERN (insn));
3689 }
3690
3691 static void
3692 mark_constants (x)
3693 register rtx x;
3694 {
3695 register int i;
3696 register char *format_ptr;
3697
3698 if (x == 0)
3699 return;
3700
3701 if (GET_CODE (x) == SYMBOL_REF)
3702 {
3703 if (CONSTANT_POOL_ADDRESS_P (x))
3704 find_pool_constant (x)->mark = 1;
3705 return;
3706 }
3707 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3708 a MEM, but does not constitute a use of that MEM. This is particularly
3709 important inside a nested function, because CONST_DOUBLE_MEM may be
3710 a reference to a MEM in the parent's constant pool. See the comment
3711 in force_const_mem. */
3712 else if (GET_CODE (x) == CONST_DOUBLE)
3713 return;
3714
3715 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3716 insns, not any notes that may be attached. We don't want to mark
3717 a constant just because it happens to appear in a REG_EQUIV note. */
3718 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3719 {
3720 mark_constants (PATTERN (x));
3721 return;
3722 }
3723
3724 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3725
3726 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3727 {
3728 switch (*format_ptr++)
3729 {
3730 case 'e':
3731 mark_constants (XEXP (x, i));
3732 break;
3733
3734 case 'E':
3735 if (XVEC (x, i) != 0)
3736 {
3737 register int j;
3738
3739 for (j = 0; j < XVECLEN (x, i); j++)
3740 mark_constants (XVECEXP (x, i, j));
3741 }
3742 break;
3743
3744 case 'S':
3745 case 's':
3746 case '0':
3747 case 'i':
3748 case 'w':
3749 case 'n':
3750 case 'u':
3751 break;
3752
3753 default:
3754 abort ();
3755 }
3756 }
3757 }
3758 \f
3759 /* Find all the constants whose addresses are referenced inside of EXP,
3760 and make sure assembler code with a label has been output for each one.
3761 Indicate whether an ADDR_EXPR has been encountered. */
3762
3763 static int
3764 output_addressed_constants (exp)
3765 tree exp;
3766 {
3767 int reloc = 0;
3768
3769 switch (TREE_CODE (exp))
3770 {
3771 case ADDR_EXPR:
3772 {
3773 register tree constant = TREE_OPERAND (exp, 0);
3774
3775 while (TREE_CODE (constant) == COMPONENT_REF)
3776 {
3777 constant = TREE_OPERAND (constant, 0);
3778 }
3779
3780 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3781 || TREE_CODE (constant) == CONSTRUCTOR)
3782 /* No need to do anything here
3783 for addresses of variables or functions. */
3784 output_constant_def (constant);
3785 }
3786 reloc = 1;
3787 break;
3788
3789 case PLUS_EXPR:
3790 case MINUS_EXPR:
3791 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3792 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3793 break;
3794
3795 case NOP_EXPR:
3796 case CONVERT_EXPR:
3797 case NON_LVALUE_EXPR:
3798 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3799 break;
3800
3801 case CONSTRUCTOR:
3802 {
3803 register tree link;
3804 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3805 if (TREE_VALUE (link) != 0)
3806 reloc |= output_addressed_constants (TREE_VALUE (link));
3807 }
3808 break;
3809
3810 default:
3811 break;
3812 }
3813 return reloc;
3814 }
3815 \f
3816 /* Output assembler code for constant EXP to FILE, with no label.
3817 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3818 Assumes output_addressed_constants has been done on EXP already.
3819
3820 Generate exactly SIZE bytes of assembler data, padding at the end
3821 with zeros if necessary. SIZE must always be specified.
3822
3823 SIZE is important for structure constructors,
3824 since trailing members may have been omitted from the constructor.
3825 It is also important for initialization of arrays from string constants
3826 since the full length of the string constant might not be wanted.
3827 It is also needed for initialization of unions, where the initializer's
3828 type is just one member, and that may not be as long as the union.
3829
3830 There a case in which we would fail to output exactly SIZE bytes:
3831 for a structure constructor that wants to produce more than SIZE bytes.
3832 But such constructors will never be generated for any possible input. */
3833
3834 void
3835 output_constant (exp, size)
3836 register tree exp;
3837 register int size;
3838 {
3839 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3840
3841 if (size == 0)
3842 return;
3843
3844 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3845 That way we get the constant (we hope) inside it. Also, strip off any
3846 NOP_EXPR that converts between two record, union, array, or set types. */
3847 while ((TREE_CODE (exp) == NOP_EXPR
3848 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3849 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3850 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3851 exp = TREE_OPERAND (exp, 0);
3852
3853 /* Allow a constructor with no elements for any data type.
3854 This means to fill the space with zeros. */
3855 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3856 {
3857 assemble_zeros (size);
3858 return;
3859 }
3860
3861 switch (code)
3862 {
3863 case CHAR_TYPE:
3864 case BOOLEAN_TYPE:
3865 case INTEGER_TYPE:
3866 case ENUMERAL_TYPE:
3867 case POINTER_TYPE:
3868 case REFERENCE_TYPE:
3869 /* ??? What about (int)((float)(int)&foo + 4) */
3870 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3871 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3872 exp = TREE_OPERAND (exp, 0);
3873
3874 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3875 EXPAND_INITIALIZER),
3876 size, 0))
3877 error ("initializer for integer value is too complicated");
3878 size = 0;
3879 break;
3880
3881 case REAL_TYPE:
3882 if (TREE_CODE (exp) != REAL_CST)
3883 error ("initializer for floating value is not a floating constant");
3884
3885 assemble_real (TREE_REAL_CST (exp),
3886 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3887 size = 0;
3888 break;
3889
3890 case COMPLEX_TYPE:
3891 output_constant (TREE_REALPART (exp), size / 2);
3892 output_constant (TREE_IMAGPART (exp), size / 2);
3893 size -= (size / 2) * 2;
3894 break;
3895
3896 case ARRAY_TYPE:
3897 if (TREE_CODE (exp) == CONSTRUCTOR)
3898 {
3899 output_constructor (exp, size);
3900 return;
3901 }
3902 else if (TREE_CODE (exp) == STRING_CST)
3903 {
3904 int excess = 0;
3905
3906 if (size > TREE_STRING_LENGTH (exp))
3907 {
3908 excess = size - TREE_STRING_LENGTH (exp);
3909 size = TREE_STRING_LENGTH (exp);
3910 }
3911
3912 assemble_string (TREE_STRING_POINTER (exp), size);
3913 size = excess;
3914 }
3915 else
3916 abort ();
3917 break;
3918
3919 case RECORD_TYPE:
3920 case UNION_TYPE:
3921 if (TREE_CODE (exp) == CONSTRUCTOR)
3922 output_constructor (exp, size);
3923 else
3924 abort ();
3925 return;
3926
3927 case SET_TYPE:
3928 if (TREE_CODE (exp) == INTEGER_CST)
3929 assemble_integer (expand_expr (exp, NULL_RTX,
3930 VOIDmode, EXPAND_INITIALIZER),
3931 size, 1);
3932 else if (TREE_CODE (exp) == CONSTRUCTOR)
3933 {
3934 unsigned char *buffer = (unsigned char *) alloca (size);
3935 if (get_set_constructor_bytes (exp, buffer, size))
3936 abort ();
3937 assemble_string ((char *) buffer, size);
3938 }
3939 else
3940 error ("unknown set constructor type");
3941 return;
3942
3943 default:
3944 break; /* ??? */
3945 }
3946
3947 if (size > 0)
3948 assemble_zeros (size);
3949 }
3950
3951 \f
3952 /* Subroutine of output_constant, used for CONSTRUCTORs
3953 (aggregate constants).
3954 Generate at least SIZE bytes, padding if necessary. */
3955
3956 static void
3957 output_constructor (exp, size)
3958 tree exp;
3959 int size;
3960 {
3961 register tree link, field = 0;
3962 HOST_WIDE_INT min_index = 0;
3963 /* Number of bytes output or skipped so far.
3964 In other words, current position within the constructor. */
3965 int total_bytes = 0;
3966 /* Non-zero means BYTE contains part of a byte, to be output. */
3967 int byte_buffer_in_use = 0;
3968 register int byte;
3969
3970 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3971 abort ();
3972
3973 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3974 field = TYPE_FIELDS (TREE_TYPE (exp));
3975
3976 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3977 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3978 min_index
3979 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3980
3981 /* As LINK goes through the elements of the constant,
3982 FIELD goes through the structure fields, if the constant is a structure.
3983 if the constant is a union, then we override this,
3984 by getting the field from the TREE_LIST element.
3985 But the constant could also be an array. Then FIELD is zero. */
3986 for (link = CONSTRUCTOR_ELTS (exp);
3987 link;
3988 link = TREE_CHAIN (link),
3989 field = field ? TREE_CHAIN (field) : 0)
3990 {
3991 tree val = TREE_VALUE (link);
3992 tree index = 0;
3993
3994 /* the element in a union constructor specifies the proper field. */
3995
3996 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3997 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3998 {
3999 /* if available, use the type given by link */
4000 if (TREE_PURPOSE (link) != 0)
4001 field = TREE_PURPOSE (link);
4002 }
4003
4004 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4005 index = TREE_PURPOSE (link);
4006
4007 /* Eliminate the marker that makes a cast not be an lvalue. */
4008 if (val != 0)
4009 STRIP_NOPS (val);
4010
4011 if (index && TREE_CODE (index) == RANGE_EXPR)
4012 {
4013 register int fieldsize
4014 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4015 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4016 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4017 HOST_WIDE_INT index;
4018 for (index = lo_index; index <= hi_index; index++)
4019 {
4020 /* Output the element's initial value. */
4021 if (val == 0)
4022 assemble_zeros (fieldsize);
4023 else
4024 output_constant (val, fieldsize);
4025
4026 /* Count its size. */
4027 total_bytes += fieldsize;
4028 }
4029 }
4030 else if (field == 0 || !DECL_BIT_FIELD (field))
4031 {
4032 /* An element that is not a bit-field. */
4033
4034 register int fieldsize;
4035 /* Since this structure is static,
4036 we know the positions are constant. */
4037 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4038 / BITS_PER_UNIT)
4039 : 0);
4040 if (index != 0)
4041 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4042 / BITS_PER_UNIT
4043 * (TREE_INT_CST_LOW (index) - min_index));
4044
4045 /* Output any buffered-up bit-fields preceding this element. */
4046 if (byte_buffer_in_use)
4047 {
4048 ASM_OUTPUT_BYTE (asm_out_file, byte);
4049 total_bytes++;
4050 byte_buffer_in_use = 0;
4051 }
4052
4053 /* Advance to offset of this element.
4054 Note no alignment needed in an array, since that is guaranteed
4055 if each element has the proper size. */
4056 if ((field != 0 || index != 0) && bitpos != total_bytes)
4057 {
4058 assemble_zeros (bitpos - total_bytes);
4059 total_bytes = bitpos;
4060 }
4061
4062 /* Determine size this element should occupy. */
4063 if (field)
4064 {
4065 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4066 abort ();
4067 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4068 {
4069 /* This avoids overflow trouble. */
4070 tree size_tree = size_binop (CEIL_DIV_EXPR,
4071 DECL_SIZE (field),
4072 size_int (BITS_PER_UNIT));
4073 fieldsize = TREE_INT_CST_LOW (size_tree);
4074 }
4075 else
4076 {
4077 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4078 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4079 }
4080 }
4081 else
4082 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4083
4084 /* Output the element's initial value. */
4085 if (val == 0)
4086 assemble_zeros (fieldsize);
4087 else
4088 output_constant (val, fieldsize);
4089
4090 /* Count its size. */
4091 total_bytes += fieldsize;
4092 }
4093 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4094 error ("invalid initial value for member `%s'",
4095 IDENTIFIER_POINTER (DECL_NAME (field)));
4096 else
4097 {
4098 /* Element that is a bit-field. */
4099
4100 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4101 int end_offset
4102 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4103
4104 if (val == 0)
4105 val = integer_zero_node;
4106
4107 /* If this field does not start in this (or, next) byte,
4108 skip some bytes. */
4109 if (next_offset / BITS_PER_UNIT != total_bytes)
4110 {
4111 /* Output remnant of any bit field in previous bytes. */
4112 if (byte_buffer_in_use)
4113 {
4114 ASM_OUTPUT_BYTE (asm_out_file, byte);
4115 total_bytes++;
4116 byte_buffer_in_use = 0;
4117 }
4118
4119 /* If still not at proper byte, advance to there. */
4120 if (next_offset / BITS_PER_UNIT != total_bytes)
4121 {
4122 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4123 total_bytes = next_offset / BITS_PER_UNIT;
4124 }
4125 }
4126
4127 if (! byte_buffer_in_use)
4128 byte = 0;
4129
4130 /* We must split the element into pieces that fall within
4131 separate bytes, and combine each byte with previous or
4132 following bit-fields. */
4133
4134 /* next_offset is the offset n fbits from the beginning of
4135 the structure to the next bit of this element to be processed.
4136 end_offset is the offset of the first bit past the end of
4137 this element. */
4138 while (next_offset < end_offset)
4139 {
4140 int this_time;
4141 int shift;
4142 HOST_WIDE_INT value;
4143 int next_byte = next_offset / BITS_PER_UNIT;
4144 int next_bit = next_offset % BITS_PER_UNIT;
4145
4146 /* Advance from byte to byte
4147 within this element when necessary. */
4148 while (next_byte != total_bytes)
4149 {
4150 ASM_OUTPUT_BYTE (asm_out_file, byte);
4151 total_bytes++;
4152 byte = 0;
4153 }
4154
4155 /* Number of bits we can process at once
4156 (all part of the same byte). */
4157 this_time = MIN (end_offset - next_offset,
4158 BITS_PER_UNIT - next_bit);
4159 if (BYTES_BIG_ENDIAN)
4160 {
4161 /* On big-endian machine, take the most significant bits
4162 first (of the bits that are significant)
4163 and put them into bytes from the most significant end. */
4164 shift = end_offset - next_offset - this_time;
4165 /* Don't try to take a bunch of bits that cross
4166 the word boundary in the INTEGER_CST. */
4167 if (shift < HOST_BITS_PER_WIDE_INT
4168 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4169 {
4170 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4171 shift = HOST_BITS_PER_WIDE_INT;
4172 }
4173
4174 /* Now get the bits from the appropriate constant word. */
4175 if (shift < HOST_BITS_PER_WIDE_INT)
4176 {
4177 value = TREE_INT_CST_LOW (val);
4178 }
4179 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4180 {
4181 value = TREE_INT_CST_HIGH (val);
4182 shift -= HOST_BITS_PER_WIDE_INT;
4183 }
4184 else
4185 abort ();
4186 byte |= (((value >> shift)
4187 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4188 << (BITS_PER_UNIT - this_time - next_bit));
4189 }
4190 else
4191 {
4192 /* On little-endian machines,
4193 take first the least significant bits of the value
4194 and pack them starting at the least significant
4195 bits of the bytes. */
4196 shift = (next_offset
4197 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4198 /* Don't try to take a bunch of bits that cross
4199 the word boundary in the INTEGER_CST. */
4200 if (shift < HOST_BITS_PER_WIDE_INT
4201 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4202 {
4203 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4204 shift = HOST_BITS_PER_WIDE_INT;
4205 }
4206
4207 /* Now get the bits from the appropriate constant word. */
4208 if (shift < HOST_BITS_PER_WIDE_INT)
4209 value = TREE_INT_CST_LOW (val);
4210 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4211 {
4212 value = TREE_INT_CST_HIGH (val);
4213 shift -= HOST_BITS_PER_WIDE_INT;
4214 }
4215 else
4216 abort ();
4217 byte |= (((value >> shift)
4218 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4219 << next_bit);
4220 }
4221 next_offset += this_time;
4222 byte_buffer_in_use = 1;
4223 }
4224 }
4225 }
4226 if (byte_buffer_in_use)
4227 {
4228 ASM_OUTPUT_BYTE (asm_out_file, byte);
4229 total_bytes++;
4230 }
4231 if (total_bytes < size)
4232 assemble_zeros (size - total_bytes);
4233 }
4234
4235 /* Declare DECL to be a weak symbol. */
4236
4237 void
4238 declare_weak (decl)
4239 tree decl;
4240 {
4241 if (! TREE_PUBLIC (decl))
4242 error_with_decl (decl, "weak declaration of `%s' must be public");
4243 else if (TREE_ASM_WRITTEN (decl))
4244 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4245 else if (SUPPORTS_WEAK)
4246 DECL_WEAK (decl) = 1;
4247 }
4248
4249 /* Emit any pending weak declarations. */
4250
4251 #ifdef HANDLE_PRAGMA_WEAK
4252 struct weak_syms * weak_decls;
4253 #endif
4254
4255 void
4256 weak_finish ()
4257 {
4258 #ifdef HANDLE_PRAGMA_WEAK
4259 if (HANDLE_PRAGMA_WEAK)
4260 {
4261 struct weak_syms *t;
4262 for (t = weak_decls; t; t = t->next)
4263 {
4264 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4265 if (t->value)
4266 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4267 }
4268 }
4269 #endif
4270 }
4271
4272 void
4273 assemble_alias (decl, target)
4274 tree decl, target;
4275 {
4276 char *name;
4277
4278 make_decl_rtl (decl, (char *) 0, 1);
4279 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4280
4281 #ifdef ASM_OUTPUT_DEF
4282 /* Make name accessible from other files, if appropriate. */
4283
4284 if (TREE_PUBLIC (decl))
4285 {
4286 #ifdef ASM_WEAKEN_LABEL
4287 if (DECL_WEAK (decl))
4288 ASM_WEAKEN_LABEL (asm_out_file, name);
4289 else
4290 #endif
4291 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4292 }
4293
4294 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4295 TREE_ASM_WRITTEN (decl) = 1;
4296 #else
4297 #ifdef ASM_OUTPUT_WEAK_ALIAS
4298 if (! DECL_WEAK (decl))
4299 warning ("only weak aliases are supported in this configuration");
4300
4301 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4302 TREE_ASM_WRITTEN (decl) = 1;
4303 #else
4304 warning ("alias definitions not supported in this configuration; ignored");
4305 #endif
4306 #endif
4307 }
4308
4309 /* This determines whether or not we support link-once semantics. */
4310 #ifndef SUPPORTS_ONE_ONLY
4311 #ifdef MAKE_DECL_ONE_ONLY
4312 #define SUPPORTS_ONE_ONLY 1
4313 #else
4314 #define SUPPORTS_ONE_ONLY 0
4315 #endif
4316 #endif
4317
4318 /* Returns 1 if the target configuration supports defining public symbols
4319 so that one of them will be chosen at link time instead of generating a
4320 multiply-defined symbol error, whether through the use of weak symbols or
4321 a target-specific mechanism for having duplicates discarded. */
4322
4323 int
4324 supports_one_only ()
4325 {
4326 if (SUPPORTS_ONE_ONLY)
4327 return 1;
4328 return SUPPORTS_WEAK;
4329 }
4330
4331 /* Set up DECL as a public symbol that can be defined in multiple
4332 translation units without generating a linker error. */
4333
4334 void
4335 make_decl_one_only (decl)
4336 tree decl;
4337 {
4338 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4339 abort ();
4340
4341 TREE_PUBLIC (decl) = 1;
4342
4343 if (TREE_CODE (decl) == VAR_DECL
4344 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4345 DECL_COMMON (decl) = 1;
4346 else if (SUPPORTS_ONE_ONLY)
4347 {
4348 #ifdef MAKE_DECL_ONE_ONLY
4349 MAKE_DECL_ONE_ONLY (decl);
4350 #endif
4351 DECL_ONE_ONLY (decl) = 1;
4352 }
4353 else if (SUPPORTS_WEAK)
4354 DECL_WEAK (decl) = 1;
4355 else
4356 abort ();
4357 }