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