]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/varasm.c
(sparc_type_code): Support range types.
[thirdparty/gcc.git] / gcc / varasm.c
CommitLineData
79e68feb 1/* Output variables, constants and external declarations, for GNU compiler.
387e854a 2 Copyright (C) 1987, 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
79e68feb
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21/* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
24
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
27
28#include <stdio.h>
29#include <setjmp.h>
30/* #include <stab.h> */
31#include "config.h"
32#include "rtl.h"
33#include "tree.h"
34#include "flags.h"
57632c51 35#include "function.h"
79e68feb
RS
36#include "expr.h"
37#include "hard-reg-set.h"
38#include "regs.h"
9a631e8e 39#include "defaults.h"
24b09b50 40#include "real.h"
79e68feb
RS
41
42#include "obstack.h"
43
b4ac57ab 44#ifdef XCOFF_DEBUGGING_INFO
f246a305 45#include "xcoffout.h"
b4ac57ab
RS
46#endif
47
6baacf63
RS
48#include <ctype.h>
49
79e68feb
RS
50#ifndef ASM_STABS_OP
51#define ASM_STABS_OP ".stabs"
52#endif
53
561e6650
RS
54/* This macro gets just the user-specified name
55 out of the string in a SYMBOL_REF. On most machines,
56 we discard the * if any and that's all. */
57#ifndef STRIP_NAME_ENCODING
58#define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
59 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
60#endif
61
79e68feb
RS
62/* File in which assembler code is being written. */
63
64extern FILE *asm_out_file;
65
66/* The (assembler) name of the first globally-visible object output. */
67char *first_global_object_name;
68
69extern struct obstack *current_obstack;
70extern struct obstack *saveable_obstack;
71extern struct obstack permanent_obstack;
72#define obstack_chunk_alloc xmalloc
79e68feb
RS
73
74/* Number for making the label on the next
75 constant that is stored in memory. */
76
77int const_labelno;
78
79/* Number for making the label on the next
80 static variable internal to a function. */
81
82int var_labelno;
83
84/* Nonzero if at least one function definition has been seen. */
85static int function_defined;
86
87extern FILE *asm_out_file;
88
89static char *compare_constant_1 ();
90static void record_constant_1 ();
ff8f4401
RS
91static void output_constant_def_contents ();
92
79e68feb
RS
93void output_constant_pool ();
94void assemble_name ();
95int output_addressed_constants ();
96void output_constant ();
97void output_constructor ();
11435a40
TW
98void text_section ();
99void readonly_data_section ();
f246a305 100void data_section ();
79e68feb
RS
101\f
102#ifdef EXTRA_SECTIONS
103static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
104 = no_section;
105#else
106static enum in_section {no_section, in_text, in_data} in_section
107 = no_section;
108#endif
109
110/* Define functions like text_section for any extra sections. */
111#ifdef EXTRA_SECTION_FUNCTIONS
112EXTRA_SECTION_FUNCTIONS
113#endif
114
115/* Tell assembler to switch to text section. */
116
117void
118text_section ()
119{
120 if (in_section != in_text)
121 {
122 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
123 in_section = in_text;
124 }
125}
126
79e68feb
RS
127/* Tell assembler to switch to data section. */
128
129void
130data_section ()
131{
132 if (in_section != in_data)
133 {
134 if (flag_shared_data)
135 {
136#ifdef SHARED_SECTION_ASM_OP
137 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
138#else
139 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
140#endif
141 }
142 else
143 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
144
145 in_section = in_data;
146 }
147}
148
7c6d68c8
RS
149/* Tell assembler to switch to read-only data section. This is normally
150 the text section. */
151
152void
153readonly_data_section ()
154{
155#ifdef READONLY_DATA_SECTION
156 READONLY_DATA_SECTION (); /* Note this can call data_section. */
157#else
158 text_section ();
159#endif
160}
161
79e68feb
RS
162/* Determine if we're in the text section. */
163
164int
165in_text_section ()
166{
167 return in_section == in_text;
168}
169\f
170/* Create the rtl to represent a function, for a function definition.
171 DECL is a FUNCTION_DECL node which describes which function.
172 The rtl is stored into DECL. */
173
174void
175make_function_rtl (decl)
176 tree decl;
177{
178 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
179
180 /* Rename a nested function to avoid conflicts. */
181 if (decl_function_context (decl) != 0
182 && DECL_INITIAL (decl) != 0
183 && DECL_RTL (decl) == 0)
184 {
185 char *label;
186
187 name = IDENTIFIER_POINTER (DECL_NAME (decl));
188 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
189 name = obstack_copy0 (saveable_obstack, label, strlen (label));
190 var_labelno++;
191 }
192
193 if (DECL_RTL (decl) == 0)
194 {
195 DECL_RTL (decl)
196 = gen_rtx (MEM, DECL_MODE (decl),
197 gen_rtx (SYMBOL_REF, Pmode, name));
198
199 /* Optionally set flags or add text to the name to record information
200 such as that it is a function name. If the name is changed, the macro
201 ASM_OUTPUT_LABELREF will have to know how to strip this information.
202 And if it finds a * at the beginning after doing so, it must handle
203 that too. */
204#ifdef ENCODE_SECTION_INFO
205 ENCODE_SECTION_INFO (decl);
206#endif
207 }
208
209 /* Record at least one function has been defined. */
210 function_defined = 1;
211}
212
b4ac57ab
RS
213/* Given NAME, a putative register name, discard any customary prefixes. */
214
215static char *
216strip_reg_name (name)
217 char *name;
218{
219#ifdef REGISTER_PREFIX
220 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
221 name += strlen (REGISTER_PREFIX);
222#endif
223 if (name[0] == '%' || name[0] == '#')
224 name++;
225 return name;
226}
dcfedcd0 227\f
79e68feb
RS
228/* Decode an `asm' spec for a declaration as a register name.
229 Return the register number, or -1 if nothing specified,
c09e6498
RS
230 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
231 or -3 if ASMSPEC is `cc' and is not recognized,
232 or -4 if ASMSPEC is `memory' and is not recognized.
dcfedcd0
RK
233 Accept an exact spelling or a decimal number.
234 Prefixes such as % are optional. */
79e68feb
RS
235
236int
237decode_reg_name (asmspec)
238 char *asmspec;
239{
240 if (asmspec != 0)
241 {
242 int i;
243
b4ac57ab
RS
244 /* Get rid of confusing prefixes. */
245 asmspec = strip_reg_name (asmspec);
246
fff9e713
MT
247 /* Allow a decimal number as a "register name". */
248 for (i = strlen (asmspec) - 1; i >= 0; i--)
249 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
250 break;
251 if (asmspec[0] != 0 && i < 0)
252 {
253 i = atoi (asmspec);
254 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
255 return i;
256 else
257 return -2;
258 }
259
79e68feb 260 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
b4ac57ab
RS
261 if (reg_names[i][0]
262 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
79e68feb
RS
263 return i;
264
79e68feb
RS
265#ifdef ADDITIONAL_REGISTER_NAMES
266 {
267 static struct { char *name; int number; } table[]
268 = ADDITIONAL_REGISTER_NAMES;
269
270 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
271 if (! strcmp (asmspec, table[i].name))
272 return table[i].number;
79e68feb
RS
273 }
274#endif /* ADDITIONAL_REGISTER_NAMES */
275
c09e6498
RS
276 if (!strcmp (asmspec, "memory"))
277 return -4;
278
dcfedcd0
RK
279 if (!strcmp (asmspec, "cc"))
280 return -3;
281
79e68feb
RS
282 return -2;
283 }
284
285 return -1;
286}
287\f
288/* Create the DECL_RTL for a declaration for a static or external variable
289 or static or external function.
290 ASMSPEC, if not 0, is the string which the user specified
291 as the assembler symbol name.
292 TOP_LEVEL is nonzero if this is a file-scope variable.
293
294 This is never called for PARM_DECL nodes. */
295
296void
297make_decl_rtl (decl, asmspec, top_level)
298 tree decl;
299 char *asmspec;
300 int top_level;
301{
302 register char *name;
303 int reg_number = decode_reg_name (asmspec);
304
305 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
306 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
307
308 if (reg_number == -2)
309 {
310 /* ASMSPEC is given, and not the name of a register. */
311 name = (char *) obstack_alloc (saveable_obstack,
312 strlen (asmspec) + 2);
313 name[0] = '*';
314 strcpy (&name[1], asmspec);
315 }
316
317 /* For a duplicate declaration, we can be called twice on the
ff8f4401
RS
318 same DECL node. Don't discard the RTL already made. */
319 if (DECL_RTL (decl) == 0)
79e68feb
RS
320 {
321 DECL_RTL (decl) = 0;
322
323 /* First detect errors in declaring global registers. */
44fe2e80 324 if (DECL_REGISTER (decl) && reg_number == -1)
79e68feb
RS
325 error_with_decl (decl,
326 "register name not specified for `%s'");
44fe2e80 327 else if (DECL_REGISTER (decl) && reg_number < 0)
79e68feb
RS
328 error_with_decl (decl,
329 "invalid register name for `%s'");
44fe2e80 330 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
79e68feb
RS
331 error_with_decl (decl,
332 "register name given for non-register variable `%s'");
44fe2e80 333 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
79e68feb 334 error ("function declared `register'");
44fe2e80 335 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
79e68feb 336 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
ce2fb245
RS
337 else if (DECL_REGISTER (decl)
338 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
339 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
79e68feb 340 /* Now handle properly declared static register variables. */
44fe2e80 341 else if (DECL_REGISTER (decl))
79e68feb
RS
342 {
343 int nregs;
344#if 0 /* yylex should print the warning for this */
345 if (pedantic)
346 pedwarn ("ANSI C forbids global register variables");
347#endif
348 if (DECL_INITIAL (decl) != 0 && top_level)
349 {
350 DECL_INITIAL (decl) = 0;
351 error ("global register variable has initial value");
352 }
353 if (fixed_regs[reg_number] == 0
354 && function_defined && top_level)
355 error ("global register variable follows a function definition");
356 if (TREE_THIS_VOLATILE (decl))
357 warning ("volatile register variables don't work as you might wish");
31e4b1c0
RK
358
359 /* If the user specified one of the eliminables registers here,
360 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
361 confused with that register and be eliminated. Although this
362 usage is somewhat suspect, we nevertheless use the following
363 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
364
365 DECL_RTL (decl)
366 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
367 REGNO (DECL_RTL (decl)) = reg_number;
79e68feb
RS
368 REG_USERVAR_P (DECL_RTL (decl)) = 1;
369
370 if (top_level)
371 {
372 /* Make this register fixed, so not usable for anything else. */
373 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
374 while (nregs > 0)
375 global_regs[reg_number + --nregs] = 1;
376 init_reg_sets_1 ();
377 }
378 }
379
380 /* Now handle ordinary static variables and functions (in memory).
381 Also handle vars declared register invalidly. */
382 if (DECL_RTL (decl) == 0)
383 {
384 /* Can't use just the variable's own name for a variable
385 whose scope is less than the whole file.
386 Concatenate a distinguishing number. */
44fe2e80 387 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
79e68feb
RS
388 {
389 char *label;
390
391 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
392 name = obstack_copy0 (saveable_obstack, label, strlen (label));
393 var_labelno++;
394 }
395
396 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
397 gen_rtx (SYMBOL_REF, Pmode, name));
0f15260a
RS
398 if (TREE_THIS_VOLATILE (decl)
399 || (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
400 && TREE_PUBLIC (decl)))
79e68feb
RS
401 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
402 if (TREE_READONLY (decl))
403 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
404 MEM_IN_STRUCT_P (DECL_RTL (decl))
405 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
406 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
c1b98a95
RK
407 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
408 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
79e68feb
RS
409
410 /* Optionally set flags or add text to the name to record information
411 such as that it is a function name.
412 If the name is changed, the macro ASM_OUTPUT_LABELREF
413 will have to know how to strip this information.
414 And if it finds a * at the beginning after doing so,
415 it must handle that too. */
416#ifdef ENCODE_SECTION_INFO
417 ENCODE_SECTION_INFO (decl);
418#endif
419 }
420 }
ff8f4401
RS
421 /* If the old RTL had the wrong mode, fix the mode. */
422 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
423 {
424 rtx rtl = DECL_RTL (decl);
425 PUT_MODE (rtl, DECL_MODE (decl));
426 }
79e68feb 427}
4724d87a
RS
428
429/* Make the rtl for variable VAR be volatile.
430 Use this only for static variables. */
431
fcbaecc6 432void
4724d87a
RS
433make_var_volatile (var)
434 tree var;
435{
436 if (GET_CODE (DECL_RTL (var)) != MEM)
437 abort ();
438
439 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
440}
79e68feb 441\f
d447ec6f
RS
442/* Output alignment directive to align for constant expression EXP. */
443
444void
445assemble_constant_align (exp)
446 tree exp;
447{
448 int align;
449
450 /* Align the location counter as required by EXP's data type. */
451 align = TYPE_ALIGN (TREE_TYPE (exp));
452#ifdef CONSTANT_ALIGNMENT
453 align = CONSTANT_ALIGNMENT (exp, align);
454#endif
455
456 if (align > BITS_PER_UNIT)
457 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
458}
459
79e68feb
RS
460/* Output a string of literal assembler code
461 for an `asm' keyword used between functions. */
462
463void
464assemble_asm (string)
465 tree string;
466{
467 app_enable ();
468
469 if (TREE_CODE (string) == ADDR_EXPR)
470 string = TREE_OPERAND (string, 0);
471
472 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
473}
474
9bb2e4fe
RS
475#if 0 /* This should no longer be needed, because
476 flag_gnu_linker should be 0 on these systems,
477 which should prevent any output
478 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
79e68feb
RS
479#if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
480#ifndef ASM_OUTPUT_CONSTRUCTOR
481#define ASM_OUTPUT_CONSTRUCTOR(file, name)
482#endif
483#ifndef ASM_OUTPUT_DESTRUCTOR
484#define ASM_OUTPUT_DESTRUCTOR(file, name)
485#endif
486#endif
9bb2e4fe 487#endif /* 0 */
79e68feb
RS
488
489/* Record an element in the table of global destructors.
490 How this is done depends on what sort of assembler and linker
491 are in use.
492
493 NAME should be the name of a global function to be called
494 at exit time. This name is output using assemble_name. */
495
496void
497assemble_destructor (name)
498 char *name;
499{
500#ifdef ASM_OUTPUT_DESTRUCTOR
501 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
502#else
503 if (flag_gnu_linker)
504 {
505 /* Now tell GNU LD that this is part of the static destructor set. */
506 /* This code works for any machine provided you use GNU as/ld. */
507 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
508 assemble_name (asm_out_file, name);
509 fputc ('\n', asm_out_file);
510 }
511#endif
512}
513
514/* Likewise for global constructors. */
515
516void
517assemble_constructor (name)
518 char *name;
519{
520#ifdef ASM_OUTPUT_CONSTRUCTOR
521 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
522#else
523 if (flag_gnu_linker)
524 {
525 /* Now tell GNU LD that this is part of the static constructor set. */
526 /* This code works for any machine provided you use GNU as/ld. */
527 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
528 assemble_name (asm_out_file, name);
529 fputc ('\n', asm_out_file);
530 }
531#endif
532}
533
534/* Likewise for entries we want to record for garbage collection.
535 Garbage collection is still under development. */
536
537void
538assemble_gc_entry (name)
539 char *name;
540{
541#ifdef ASM_OUTPUT_GC_ENTRY
542 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
543#else
544 if (flag_gnu_linker)
545 {
546 /* Now tell GNU LD that this is part of the static constructor set. */
547 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
548 assemble_name (asm_out_file, name);
549 fputc ('\n', asm_out_file);
550 }
551#endif
552}
553\f
554/* Output assembler code for the constant pool of a function and associated
555 with defining the name of the function. DECL describes the function.
556 NAME is the function's name. For the constant pool, we use the current
557 constant pool data. */
558
559void
560assemble_start_function (decl, fnname)
561 tree decl;
562 char *fnname;
563{
564 int align;
565
566 /* The following code does not need preprocessing in the assembler. */
567
568 app_disable ();
569
570 output_constant_pool (fnname, decl);
571
572 text_section ();
573
574
575 /* Tell assembler to move to target machine's alignment for functions. */
576 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
577 if (align > 0)
578 ASM_OUTPUT_ALIGN (asm_out_file, align);
579
580#ifdef ASM_OUTPUT_FUNCTION_PREFIX
581 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
582#endif
583
584#ifdef SDB_DEBUGGING_INFO
585 /* Output SDB definition of the function. */
586 if (write_symbols == SDB_DEBUG)
587 sdbout_mark_begin_function ();
588#endif
589
590#ifdef DBX_DEBUGGING_INFO
e5c90c23 591 /* Output DBX definition of the function. */
79e68feb 592 if (write_symbols == DBX_DEBUG)
e5c90c23 593 dbxout_begin_function (decl);
79e68feb
RS
594#endif
595
596 /* Make function name accessible from other files, if appropriate. */
597
598 if (TREE_PUBLIC (decl))
599 {
600 if (!first_global_object_name)
561e6650 601 STRIP_NAME_ENCODING (first_global_object_name, fnname);
79e68feb
RS
602 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
603 }
604
605 /* Do any machine/system dependent processing of the function name */
606#ifdef ASM_DECLARE_FUNCTION_NAME
607 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
608#else
609 /* Standard thing is just output label for the function. */
610 ASM_OUTPUT_LABEL (asm_out_file, fnname);
611#endif /* ASM_DECLARE_FUNCTION_NAME */
612}
613
614/* Output assembler code associated with defining the size of the
615 function. DECL describes the function. NAME is the function's name. */
616
617void
618assemble_end_function (decl, fnname)
619 tree decl;
620 char *fnname;
621{
622#ifdef ASM_DECLARE_FUNCTION_SIZE
623 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
624#endif
625}
626\f
627/* Assemble code to leave SIZE bytes of zeros. */
628
629void
630assemble_zeros (size)
631 int size;
632{
633#ifdef ASM_NO_SKIP_IN_TEXT
634 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
635 so we must output 0s explicitly in the text section. */
636 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
637 {
638 int i;
639
640 for (i = 0; i < size - 20; i += 20)
641 {
642#ifdef ASM_BYTE_OP
643 fprintf (asm_out_file,
644 "%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);
645#else
646 fprintf (asm_out_file,
647 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
648#endif
649 }
650 if (i < size)
651 {
652#ifdef ASM_BYTE_OP
653 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
654#else
655 fprintf (asm_out_file, "\tbyte 0");
656#endif
657 i++;
658 for (; i < size; i++)
659 fprintf (asm_out_file, ",0");
660 fprintf (asm_out_file, "\n");
661 }
662 }
663 else
664#endif
41fe4d9e
RS
665 if (size > 0)
666 ASM_OUTPUT_SKIP (asm_out_file, size);
79e68feb
RS
667}
668
a785e67e
RS
669/* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
670
671void
672assemble_align (align)
673 int align;
674{
675 if (align > BITS_PER_UNIT)
676 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
677}
678
79e68feb
RS
679/* Assemble a string constant with the specified C string as contents. */
680
681void
682assemble_string (p, size)
fcbaecc6 683 char *p;
79e68feb
RS
684 int size;
685{
686 register int i;
687 int pos = 0;
688 int maximum = 2000;
689
690 /* If the string is very long, split it up. */
691
692 while (pos < size)
693 {
694 int thissize = size - pos;
695 if (thissize > maximum)
696 thissize = maximum;
697
79e68feb 698 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
79e68feb
RS
699
700 pos += thissize;
701 p += thissize;
702 }
703}
704\f
705/* Assemble everything that is needed for a variable or function declaration.
706 Not used for automatic variables, and not used for function definitions.
707 Should not be called for variables of incomplete structure type.
708
709 TOP_LEVEL is nonzero if this variable has file scope.
710 AT_END is nonzero if this is the special handling, at end of compilation,
ff8f4401
RS
711 to define things that have had only tentative definitions.
712 DONT_OUTPUT_DATA if nonzero means don't actually output the
713 initial value (that will be done by the caller). */
79e68feb
RS
714
715void
ff8f4401 716assemble_variable (decl, top_level, at_end, dont_output_data)
79e68feb
RS
717 tree decl;
718 int top_level;
719 int at_end;
720{
721 register char *name;
722 int align;
723 tree size_tree;
724 int reloc = 0;
edbc355b 725 enum in_section saved_in_section;
79e68feb
RS
726
727 if (GET_CODE (DECL_RTL (decl)) == REG)
728 {
729 /* Do output symbol info for global register variables, but do nothing
730 else for them. */
731
732 if (TREE_ASM_WRITTEN (decl))
733 return;
734 TREE_ASM_WRITTEN (decl) = 1;
735
b4ac57ab 736#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
79e68feb 737 /* File-scope global variables are output here. */
b4ac57ab
RS
738 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
739 && top_level)
79e68feb
RS
740 dbxout_symbol (decl, 0);
741#endif
742#ifdef SDB_DEBUGGING_INFO
743 if (write_symbols == SDB_DEBUG && top_level
744 /* Leave initialized global vars for end of compilation;
745 see comment in compile_file. */
746 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
747 sdbout_symbol (decl, 0);
748#endif
749
750 /* Don't output any DWARF debugging information for variables here.
751 In the case of local variables, the information for them is output
752 when we do our recursive traversal of the tree representation for
753 the entire containing function. In the case of file-scope variables,
754 we output information for all of them at the very end of compilation
755 while we are doing our final traversal of the chain of file-scope
756 declarations. */
757
758 return;
759 }
760
d36d70cc
RK
761 /* Normally no need to say anything here for external references,
762 since assemble_external is called by the langauge-specific code
763 when a declaration is first seen. */
79e68feb 764
44fe2e80 765 if (DECL_EXTERNAL (decl))
79e68feb
RS
766 return;
767
768 /* Output no assembler code for a function declaration.
769 Only definitions of functions output anything. */
770
771 if (TREE_CODE (decl) == FUNCTION_DECL)
772 return;
773
774 /* If type was incomplete when the variable was declared,
775 see if it is complete now. */
776
777 if (DECL_SIZE (decl) == 0)
778 layout_decl (decl, 0);
779
780 /* Still incomplete => don't allocate it; treat the tentative defn
781 (which is what it must have been) as an `extern' reference. */
782
ff8f4401 783 if (!dont_output_data && DECL_SIZE (decl) == 0)
79e68feb
RS
784 {
785 error_with_file_and_line (DECL_SOURCE_FILE (decl),
786 DECL_SOURCE_LINE (decl),
ea80ee44 787 "storage size of `%s' isn't known",
79e68feb
RS
788 IDENTIFIER_POINTER (DECL_NAME (decl)));
789 return;
790 }
791
792 /* The first declaration of a variable that comes through this function
793 decides whether it is global (in C, has external linkage)
794 or local (in C, has internal linkage). So do nothing more
795 if this function has already run. */
796
797 if (TREE_ASM_WRITTEN (decl))
798 return;
799
800 TREE_ASM_WRITTEN (decl) = 1;
801
79e68feb
RS
802 /* If storage size is erroneously variable, just continue.
803 Error message was already made. */
804
ff8f4401
RS
805 if (DECL_SIZE (decl))
806 {
807 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
808 goto finish;
79e68feb 809
ff8f4401 810 app_disable ();
79e68feb 811
ff8f4401
RS
812 /* This is better than explicit arithmetic, since it avoids overflow. */
813 size_tree = size_binop (CEIL_DIV_EXPR,
814 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
79e68feb 815
ff8f4401
RS
816 if (TREE_INT_CST_HIGH (size_tree) != 0)
817 {
818 error_with_decl (decl, "size of variable `%s' is too large");
819 goto finish;
820 }
79e68feb
RS
821 }
822
823 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
824
825 /* Handle uninitialized definitions. */
826
827 /* ANSI specifies that a tentative definition which is not merged with
828 a non-tentative definition behaves exactly like a definition with an
829 initializer equal to zero. (Section 3.7.2)
21432660
JW
830 -fno-common gives strict ANSI behavior. Usually you don't want it.
831 This matters only for variables with external linkage. */
832 if ((! flag_no_common || ! TREE_PUBLIC (decl))
ff8f4401 833 && ! dont_output_data
79e68feb
RS
834 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
835 {
836 int size = TREE_INT_CST_LOW (size_tree);
837 int rounded = size;
838
839 if (TREE_INT_CST_HIGH (size_tree) != 0)
840 error_with_decl (decl, "size of variable `%s' is too large");
841 /* Don't allocate zero bytes of common,
842 since that means "undefined external" in the linker. */
843 if (size == 0) rounded = 1;
844 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
845 so that each uninitialized object starts on such a boundary. */
846 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
847 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
848 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
edbc355b
RS
849
850#ifdef DBX_DEBUGGING_INFO
851 /* File-scope global variables are output here. */
852 if (write_symbols == DBX_DEBUG && top_level)
853 dbxout_symbol (decl, 0);
854#endif
855#ifdef SDB_DEBUGGING_INFO
856 if (write_symbols == SDB_DEBUG && top_level
857 /* Leave initialized global vars for end of compilation;
858 see comment in compile_file. */
859 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
860 sdbout_symbol (decl, 0);
861#endif
862
863 /* Don't output any DWARF debugging information for variables here.
864 In the case of local variables, the information for them is output
865 when we do our recursive traversal of the tree representation for
866 the entire containing function. In the case of file-scope variables,
867 we output information for all of them at the very end of compilation
868 while we are doing our final traversal of the chain of file-scope
869 declarations. */
870
79e68feb
RS
871#if 0
872 if (flag_shared_data)
873 data_section ();
874#endif
875 if (TREE_PUBLIC (decl))
876 {
877#ifdef ASM_OUTPUT_SHARED_COMMON
878 if (flag_shared_data)
879 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
880 else
881#endif
882#ifdef ASM_OUTPUT_ALIGNED_COMMON
883 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
884 DECL_ALIGN (decl));
885#else
886 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
887#endif
888 }
889 else
890 {
891#ifdef ASM_OUTPUT_SHARED_LOCAL
892 if (flag_shared_data)
893 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
894 else
895#endif
896#ifdef ASM_OUTPUT_ALIGNED_LOCAL
897 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
898 DECL_ALIGN (decl));
899#else
900 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
901#endif
902 }
b4ac57ab 903 goto finish;
79e68feb
RS
904 }
905
906 /* Handle initialized definitions. */
907
908 /* First make the assembler name(s) global if appropriate. */
909 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
910 {
911 if (!first_global_object_name)
561e6650 912 STRIP_NAME_ENCODING(first_global_object_name, name);
79e68feb
RS
913 ASM_GLOBALIZE_LABEL (asm_out_file, name);
914 }
915#if 0
916 for (d = equivalents; d; d = TREE_CHAIN (d))
917 {
918 tree e = TREE_VALUE (d);
919 if (TREE_PUBLIC (e) && DECL_NAME (e))
920 ASM_GLOBALIZE_LABEL (asm_out_file,
921 XSTR (XEXP (DECL_RTL (e), 0), 0));
922 }
923#endif
924
925 /* Output any data that we will need to use the address of. */
926 if (DECL_INITIAL (decl))
927 reloc = output_addressed_constants (DECL_INITIAL (decl));
928
929 /* Switch to the proper section for this data. */
930#ifdef SELECT_SECTION
931 SELECT_SECTION (decl, reloc);
932#else
933 if (TREE_READONLY (decl)
934 && ! TREE_THIS_VOLATILE (decl)
935 && ! (flag_pic && reloc))
936 readonly_data_section ();
937 else
938 data_section ();
939#endif
940
edbc355b
RS
941 /* Record current section so we can restore it if dbxout.c clobbers it. */
942 saved_in_section = in_section;
943
944 /* Output the dbx info now that we have chosen the section. */
945
946#ifdef DBX_DEBUGGING_INFO
947 /* File-scope global variables are output here. */
948 if (write_symbols == DBX_DEBUG && top_level)
949 dbxout_symbol (decl, 0);
950#endif
951#ifdef SDB_DEBUGGING_INFO
952 if (write_symbols == SDB_DEBUG && top_level
953 /* Leave initialized global vars for end of compilation;
954 see comment in compile_file. */
955 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
956 sdbout_symbol (decl, 0);
957#endif
958
959 /* Don't output any DWARF debugging information for variables here.
960 In the case of local variables, the information for them is output
961 when we do our recursive traversal of the tree representation for
962 the entire containing function. In the case of file-scope variables,
963 we output information for all of them at the very end of compilation
964 while we are doing our final traversal of the chain of file-scope
965 declarations. */
966
967 if (in_section != saved_in_section)
968 {
969 /* Switch to the proper section for this data. */
970#ifdef SELECT_SECTION
971 SELECT_SECTION (decl, reloc);
972#else
973 if (TREE_READONLY (decl)
974 && ! TREE_THIS_VOLATILE (decl)
975 && ! (flag_pic && reloc))
976 readonly_data_section ();
977 else
978 data_section ();
979#endif
980 }
981
79e68feb
RS
982 /* Compute and output the alignment of this data. */
983
984 align = DECL_ALIGN (decl);
a785e67e
RS
985 /* In the case for initialing an array whose length isn't specified,
986 where we have not yet been able to do the layout,
987 figure out the proper alignment now. */
988 if (dont_output_data && DECL_SIZE (decl) == 0
989 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
990 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
991
79e68feb
RS
992 /* Some object file formats have a maximum alignment which they support.
993 In particular, a.out format supports a maximum alignment of 4. */
994#ifndef MAX_OFILE_ALIGNMENT
995#define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
996#endif
997 if (align > MAX_OFILE_ALIGNMENT)
998 {
999 warning_with_decl (decl,
1000 "alignment of `%s' is greater than maximum object file alignment");
1001 align = MAX_OFILE_ALIGNMENT;
1002 }
1003#ifdef DATA_ALIGNMENT
1004 /* On some machines, it is good to increase alignment sometimes. */
1005 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1006#endif
1007#ifdef CONSTANT_ALIGNMENT
1008 if (DECL_INITIAL (decl))
1009 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1010#endif
1011
1012 /* Reset the alignment in case we have made it tighter, so we can benefit
1013 from it in get_pointer_alignment. */
1014 DECL_ALIGN (decl) = align;
1015
1016 if (align > BITS_PER_UNIT)
1017 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1018
1019 /* Do any machine/system dependent processing of the object. */
1020#ifdef ASM_DECLARE_OBJECT_NAME
1021 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1022#else
1023 /* Standard thing is just output label for the object. */
1024 ASM_OUTPUT_LABEL (asm_out_file, name);
1025#endif /* ASM_DECLARE_OBJECT_NAME */
1026
ff8f4401 1027 if (!dont_output_data)
79e68feb 1028 {
ff8f4401
RS
1029 if (DECL_INITIAL (decl))
1030 /* Output the actual data. */
1031 output_constant (DECL_INITIAL (decl),
1032 int_size_in_bytes (TREE_TYPE (decl)));
1033 else
1034 /* Leave space for it. */
1035 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
79e68feb 1036 }
b4ac57ab
RS
1037
1038 finish:
1039#ifdef XCOFF_DEBUGGING_INFO
1040 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1041 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1042 and `aa' hasn't been output yet, the assembler generates a stab entry with
1043 a value of zero, in addition to creating an unnecessary external entry
6dc42e49 1044 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
b4ac57ab
RS
1045
1046 /* File-scope global variables are output here. */
1047 if (write_symbols == XCOFF_DEBUG && top_level)
1048 dbxout_symbol (decl, 0);
1049#else
1050 /* There must be a statement after a label. */
1051 ;
1052#endif
79e68feb
RS
1053}
1054
1055/* Output something to declare an external symbol to the assembler.
fff9e713
MT
1056 (Most assemblers don't need this, so we normally output nothing.)
1057 Do nothing if DECL is not external. */
79e68feb
RS
1058
1059void
1060assemble_external (decl)
1061 tree decl;
1062{
79e68feb 1063#ifdef ASM_OUTPUT_EXTERNAL
fff9e713 1064 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
44fe2e80 1065 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
79e68feb 1066 {
fff9e713
MT
1067 rtx rtl = DECL_RTL (decl);
1068
1069 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1070 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1071 {
1072 /* Some systems do require some output. */
1073 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1074 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1075 }
79e68feb
RS
1076 }
1077#endif
1078}
1079
1080/* Similar, for calling a library function FUN. */
1081
1082void
1083assemble_external_libcall (fun)
1084 rtx fun;
1085{
1086#ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1087 /* Declare library function name external when first used, if nec. */
1088 if (! SYMBOL_REF_USED (fun))
1089 {
1090 SYMBOL_REF_USED (fun) = 1;
1091 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1092 }
1093#endif
1094}
1095
1096/* Declare the label NAME global. */
1097
1098void
1099assemble_global (name)
1100 char *name;
1101{
1102 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1103}
1104
1105/* Assemble a label named NAME. */
1106
1107void
1108assemble_label (name)
1109 char *name;
1110{
1111 ASM_OUTPUT_LABEL (asm_out_file, name);
1112}
1113
1114/* Output to FILE a reference to the assembler name of a C-level name NAME.
1115 If NAME starts with a *, the rest of NAME is output verbatim.
1116 Otherwise NAME is transformed in an implementation-defined way
1117 (usually by the addition of an underscore).
1118 Many macros in the tm file are defined to call this function. */
1119
1120void
1121assemble_name (file, name)
1122 FILE *file;
1123 char *name;
1124{
1125 if (name[0] == '*')
1126 fputs (&name[1], file);
1127 else
1128 ASM_OUTPUT_LABELREF (file, name);
1129}
1130
1131/* Allocate SIZE bytes writable static space with a gensym name
1132 and return an RTX to refer to its address. */
1133
1134rtx
1135assemble_static_space (size)
1136 int size;
1137{
1138 char name[12];
1139 char *namestring;
1140 rtx x;
1141 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1142 so that each uninitialized object starts on such a boundary. */
1143 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1144 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1145 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1146
1147#if 0
1148 if (flag_shared_data)
1149 data_section ();
1150#endif
1151
1152 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1153 ++const_labelno;
1154
1155 namestring = (char *) obstack_alloc (saveable_obstack,
1156 strlen (name) + 2);
1157 strcpy (namestring, name);
1158
1159 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1160#ifdef ASM_OUTPUT_ALIGNED_LOCAL
1161 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1162#else
1163 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1164#endif
1165 return x;
1166}
1167
1168/* Assemble the static constant template for function entry trampolines.
1169 This is done at most once per compilation.
1170 Returns an RTX for the address of the template. */
1171
1172rtx
1173assemble_trampoline_template ()
1174{
1175 char label[256];
1176 char *name;
1177 int align;
1178
37552631 1179 /* By default, put trampoline templates in read-only data section. */
f49acdb4 1180
37552631
RS
1181#ifdef TRAMPOLINE_SECTION
1182 TRAMPOLINE_SECTION ();
1183#else
c8c29f85 1184 readonly_data_section ();
37552631 1185#endif
f49acdb4 1186
79e68feb
RS
1187 /* Write the assembler code to define one. */
1188 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1189 if (align > 0)
1190 ASM_OUTPUT_ALIGN (asm_out_file, align);
1191
1192 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1193 TRAMPOLINE_TEMPLATE (asm_out_file);
1194
1195 /* Record the rtl to refer to it. */
1196 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1197 name
1198 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1199 return gen_rtx (SYMBOL_REF, Pmode, name);
1200}
1201\f
1202/* Assemble the integer constant X into an object of SIZE bytes.
1203 X must be either a CONST_INT or CONST_DOUBLE.
1204
1205 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1206 non-zero, abort if we can't output the constant. */
1207
1208int
1209assemble_integer (x, size, force)
1210 rtx x;
1211 int size;
1212 int force;
1213{
1214 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1215 ASM_OUTPUT... macros. */
1216
1217 switch (size)
1218 {
1219#ifdef ASM_OUTPUT_CHAR
1220 case 1:
1221 ASM_OUTPUT_CHAR (asm_out_file, x);
1222 return 1;
1223#endif
1224
1225#ifdef ASM_OUTPUT_SHORT
1226 case 2:
1227 ASM_OUTPUT_SHORT (asm_out_file, x);
1228 return 1;
1229#endif
1230
1231#ifdef ASM_OUTPUT_INT
1232 case 4:
1233 ASM_OUTPUT_INT (asm_out_file, x);
1234 return 1;
1235#endif
1236
1237#ifdef ASM_OUTPUT_DOUBLE_INT
1238 case 8:
1239 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1240 return 1;
1241#endif
1242
1243#ifdef ASM_OUTPUT_QUADRUPLE_INT
1244 case 16:
1245 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1246 return 1;
1247#endif
1248 }
1249
1250 /* If we couldn't do it that way, there are two other possibilities: First,
1251 if the machine can output an explicit byte and this is a 1 byte constant,
1252 we can use ASM_OUTPUT_BYTE. */
1253
1254#ifdef ASM_OUTPUT_BYTE
1255 if (size == 1 && GET_CODE (x) == CONST_INT)
1256 {
1257 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1258 return 1;
1259 }
1260#endif
1261
1262 /* Finally, if SIZE is larger than a single word, try to output the constant
1263 one word at a time. */
1264
1265 if (size > UNITS_PER_WORD)
1266 {
1267 int i;
1268 enum machine_mode mode
1269 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1270 rtx word;
1271
1272 for (i = 0; i < size / UNITS_PER_WORD; i++)
1273 {
1274 word = operand_subword (x, i, 0, mode);
1275
1276 if (word == 0)
1277 break;
1278
fff9e713
MT
1279 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1280 break;
79e68feb
RS
1281 }
1282
1283 if (i == size / UNITS_PER_WORD)
1284 return 1;
fff9e713
MT
1285 /* If we output at least one word and then could not finish,
1286 there is no valid way to continue. */
1287 if (i > 0)
1288 abort ();
79e68feb
RS
1289 }
1290
1291 if (force)
1292 abort ();
1293
1294 return 0;
1295}
1296\f
1297/* Assemble the floating-point constant D into an object of size MODE. */
1298
1299void
1300assemble_real (d, mode)
1301 REAL_VALUE_TYPE d;
1302 enum machine_mode mode;
1303{
1304 jmp_buf output_constant_handler;
1305
1306 if (setjmp (output_constant_handler))
1307 {
1308 error ("floating point trap outputting a constant");
1309#ifdef REAL_IS_NOT_DOUBLE
1310 bzero (&d, sizeof d);
1311 d = dconst0;
1312#else
1313 d = 0;
1314#endif
1315 }
1316
1317 set_float_handler (output_constant_handler);
1318
1319 switch (mode)
1320 {
b7526ea5
RS
1321#ifdef ASM_OUTPUT_BYTE_FLOAT
1322 case QFmode:
1323 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1324 break;
1325#endif
1326#ifdef ASM_OUTPUT_SHORT_FLOAT
1327 case HFmode:
1328 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1329 break;
1330#endif
79e68feb
RS
1331#ifdef ASM_OUTPUT_FLOAT
1332 case SFmode:
1333 ASM_OUTPUT_FLOAT (asm_out_file, d);
1334 break;
1335#endif
1336
1337#ifdef ASM_OUTPUT_DOUBLE
1338 case DFmode:
1339 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1340 break;
1341#endif
1342
1343#ifdef ASM_OUTPUT_LONG_DOUBLE
2c7ff63c 1344 case XFmode:
79e68feb
RS
1345 case TFmode:
1346 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1347 break;
1348#endif
1349
1350 default:
1351 abort ();
1352 }
1353
37366632 1354 set_float_handler (NULL_PTR);
79e68feb
RS
1355}
1356\f
1357/* Here we combine duplicate floating constants to make
1358 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1359
1360/* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1361 They are chained through the CONST_DOUBLE_CHAIN.
1362 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1363 In that case, CONST_DOUBLE_MEM is either a MEM,
57632c51
RS
1364 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1365
1366 (CONST_DOUBLE_MEM is used only for top-level functions.
1367 See force_const_mem for explanation.) */
79e68feb
RS
1368
1369static rtx const_double_chain;
1370
1371/* Return a CONST_DOUBLE for a value specified as a pair of ints.
1372 For an integer, I0 is the low-order word and I1 is the high-order word.
1373 For a real number, I0 is the word with the low address
1374 and I1 is the word with the high address. */
1375
1376rtx
1377immed_double_const (i0, i1, mode)
37366632 1378 HOST_WIDE_INT i0, i1;
79e68feb
RS
1379 enum machine_mode mode;
1380{
1381 register rtx r;
1382 int in_current_obstack;
1383
ab8ab9d0
SC
1384 if (GET_MODE_CLASS (mode) == MODE_INT
1385 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
79e68feb
RS
1386 {
1387 /* We clear out all bits that don't belong in MODE, unless they and our
1388 sign bit are all one. So we get either a reasonable negative value
1389 or a reasonable unsigned value for this mode. */
1390 int width = GET_MODE_BITSIZE (mode);
37366632
RK
1391 if (width < HOST_BITS_PER_WIDE_INT
1392 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1393 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1394 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1395 else if (width == HOST_BITS_PER_WIDE_INT
79e68feb
RS
1396 && ! (i1 == ~0 && i0 < 0))
1397 i1 = 0;
37366632 1398 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1399 /* We cannot represent this value as a constant. */
1400 abort ();
1401
37366632 1402 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
79e68feb
RS
1403
1404 ??? Strictly speaking, this is wrong if we create a CONST_INT
1405 for a large unsigned constant with the size of MODE being
37366632
RK
1406 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1407 wider mode. In that case we will mis-interpret it as a negative
1408 number.
79e68feb
RS
1409
1410 Unfortunately, the only alternative is to make a CONST_DOUBLE
1411 for any constant in any mode if it is an unsigned constant larger
1412 than the maximum signed integer in an int on the host. However,
1413 doing this will break everyone that always expects to see a CONST_INT
1414 for SImode and smaller.
1415
1416 We have always been making CONST_INTs in this case, so nothing new
1417 is being broken. */
1418
37366632 1419 if (width <= HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1420 i1 = (i0 < 0) ? ~0 : 0;
1421
1422 /* If this integer fits in one word, return a CONST_INT. */
1423 if ((i1 == 0 && i0 >= 0)
1424 || (i1 == ~0 && i0 < 0))
37366632 1425 return GEN_INT (i0);
79e68feb
RS
1426
1427 /* We use VOIDmode for integers. */
1428 mode = VOIDmode;
1429 }
1430
1431 /* Search the chain for an existing CONST_DOUBLE with the right value.
1432 If one is found, return it. */
1433
1434 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1435 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1436 && GET_MODE (r) == mode)
1437 return r;
1438
1439 /* No; make a new one and add it to the chain.
1440
1441 We may be called by an optimizer which may be discarding any memory
1442 allocated during its processing (such as combine and loop). However,
1443 we will be leaving this constant on the chain, so we cannot tolerate
1444 freed memory. So switch to saveable_obstack for this allocation
1445 and then switch back if we were in current_obstack. */
1446
2260924f
JW
1447 push_obstacks_nochange ();
1448 rtl_in_saveable_obstack ();
79e68feb 1449 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
2260924f 1450 pop_obstacks ();
79e68feb 1451
5145eda8
RS
1452 /* Don't touch const_double_chain in nested function;
1453 see force_const_mem. */
8843f6e2 1454 if (outer_function_chain == 0)
5145eda8
RS
1455 {
1456 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1457 const_double_chain = r;
1458 }
79e68feb
RS
1459
1460 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1461 Actual use of mem-slot is only through force_const_mem. */
1462
1463 CONST_DOUBLE_MEM (r) = const0_rtx;
1464
1465 return r;
1466}
1467
1468/* Return a CONST_DOUBLE for a specified `double' value
1469 and machine mode. */
1470
1471rtx
1472immed_real_const_1 (d, mode)
1473 REAL_VALUE_TYPE d;
1474 enum machine_mode mode;
1475{
1476 union real_extract u;
1477 register rtx r;
1478 int in_current_obstack;
1479
1480 /* Get the desired `double' value as a sequence of ints
1481 since that is how they are stored in a CONST_DOUBLE. */
1482
1483 u.d = d;
1484
1485 /* Detect special cases. */
1486
f246a305
RS
1487 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1488 if (!bcmp (&dconst0, &d, sizeof d))
79e68feb 1489 return CONST0_RTX (mode);
12194c38
RS
1490 /* Check for NaN first, because some ports (specifically the i386) do not
1491 emit correct ieee-fp code by default, and thus will generate a core
1492 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1493 does a floating point comparison. */
1494 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
79e68feb
RS
1495 return CONST1_RTX (mode);
1496
37366632 1497 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
79e68feb
RS
1498 return immed_double_const (u.i[0], u.i[1], mode);
1499
1500 /* The rest of this function handles the case where
1501 a float value requires more than 2 ints of space.
1502 It will be deleted as dead code on machines that don't need it. */
1503
1504 /* Search the chain for an existing CONST_DOUBLE with the right value.
1505 If one is found, return it. */
1506
1507 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1508 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1509 && GET_MODE (r) == mode)
1510 return r;
1511
1512 /* No; make a new one and add it to the chain.
1513
1514 We may be called by an optimizer which may be discarding any memory
1515 allocated during its processing (such as combine and loop). However,
1516 we will be leaving this constant on the chain, so we cannot tolerate
1517 freed memory. So switch to saveable_obstack for this allocation
1518 and then switch back if we were in current_obstack. */
1519
2260924f
JW
1520 push_obstacks_nochange ();
1521 rtl_in_saveable_obstack ();
79e68feb
RS
1522 r = rtx_alloc (CONST_DOUBLE);
1523 PUT_MODE (r, mode);
1524 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
2260924f 1525 pop_obstacks ();
79e68feb 1526
5145eda8
RS
1527 /* Don't touch const_double_chain in nested function;
1528 see force_const_mem. */
8843f6e2 1529 if (outer_function_chain == 0)
5145eda8
RS
1530 {
1531 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1532 const_double_chain = r;
1533 }
79e68feb
RS
1534
1535 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1536 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1537 is only through force_const_mem. */
1538
1539 CONST_DOUBLE_MEM (r) = const0_rtx;
1540
1541 return r;
1542}
1543
1544/* Return a CONST_DOUBLE rtx for a value specified by EXP,
1545 which must be a REAL_CST tree node. */
1546
1547rtx
1548immed_real_const (exp)
1549 tree exp;
1550{
1551 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1552}
1553
1554/* At the end of a function, forget the memory-constants
1555 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1556 Also clear out real_constant_chain and clear out all the chain-pointers. */
1557
1558void
1559clear_const_double_mem ()
1560{
1561 register rtx r, next;
1562
57632c51
RS
1563 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1564 See force_const_mem for explanation. */
1565 if (outer_function_chain != 0)
1566 return;
1567
79e68feb
RS
1568 for (r = const_double_chain; r; r = next)
1569 {
1570 next = CONST_DOUBLE_CHAIN (r);
1571 CONST_DOUBLE_CHAIN (r) = 0;
1572 CONST_DOUBLE_MEM (r) = cc0_rtx;
1573 }
1574 const_double_chain = 0;
1575}
1576\f
1577/* Given an expression EXP with a constant value,
1578 reduce it to the sum of an assembler symbol and an integer.
1579 Store them both in the structure *VALUE.
1580 Abort if EXP does not reduce. */
1581
1582struct addr_const
1583{
1584 rtx base;
fb351073 1585 HOST_WIDE_INT offset;
79e68feb
RS
1586};
1587
1588static void
1589decode_addr_const (exp, value)
1590 tree exp;
1591 struct addr_const *value;
1592{
1593 register tree target = TREE_OPERAND (exp, 0);
1594 register int offset = 0;
1595 register rtx x;
1596
1597 while (1)
1598 {
1599 if (TREE_CODE (target) == COMPONENT_REF
1600 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1601 == INTEGER_CST))
1602 {
1603 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1604 target = TREE_OPERAND (target, 0);
1605 }
1606 else if (TREE_CODE (target) == ARRAY_REF)
1607 {
1608 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1609 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1610 abort ();
1611 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1612 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1613 / BITS_PER_UNIT);
1614 target = TREE_OPERAND (target, 0);
1615 }
1616 else
1617 break;
1618 }
1619
1620 switch (TREE_CODE (target))
1621 {
1622 case VAR_DECL:
1623 case FUNCTION_DECL:
1624 x = DECL_RTL (target);
1625 break;
1626
1627 case LABEL_DECL:
1628 x = gen_rtx (MEM, FUNCTION_MODE,
1629 gen_rtx (LABEL_REF, VOIDmode,
1630 label_rtx (TREE_OPERAND (exp, 0))));
1631 break;
1632
1633 case REAL_CST:
1634 case STRING_CST:
1635 case COMPLEX_CST:
1636 case CONSTRUCTOR:
1637 x = TREE_CST_RTL (target);
1638 break;
1639
1640 default:
1641 abort ();
1642 }
1643
1644 if (GET_CODE (x) != MEM)
1645 abort ();
1646 x = XEXP (x, 0);
1647
1648 value->base = x;
1649 value->offset = offset;
1650}
1651\f
1652/* Uniquize all constants that appear in memory.
1653 Each constant in memory thus far output is recorded
1654 in `const_hash_table' with a `struct constant_descriptor'
1655 that contains a polish representation of the value of
1656 the constant.
1657
1658 We cannot store the trees in the hash table
1659 because the trees may be temporary. */
1660
1661struct constant_descriptor
1662{
1663 struct constant_descriptor *next;
1664 char *label;
1665 char contents[1];
1666};
1667
1668#define HASHBITS 30
1669#define MAX_HASH_TABLE 1009
1670static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1671
1672/* Compute a hash code for a constant expression. */
1673
1674int
1675const_hash (exp)
1676 tree exp;
1677{
1678 register char *p;
1679 register int len, hi, i;
1680 register enum tree_code code = TREE_CODE (exp);
1681
1682 if (code == INTEGER_CST)
1683 {
1684 p = (char *) &TREE_INT_CST_LOW (exp);
1685 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1686 }
1687 else if (code == REAL_CST)
1688 {
1689 p = (char *) &TREE_REAL_CST (exp);
1690 len = sizeof TREE_REAL_CST (exp);
1691 }
1692 else if (code == STRING_CST)
1693 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1694 else if (code == COMPLEX_CST)
1695 return const_hash (TREE_REALPART (exp)) * 5
1696 + const_hash (TREE_IMAGPART (exp));
1697 else if (code == CONSTRUCTOR)
1698 {
1699 register tree link;
1700
1701 /* For record type, include the type in the hashing.
1702 We do not do so for array types
1703 because (1) the sizes of the elements are sufficient
eb528802
RS
1704 and (2) distinct array types can have the same constructor.
1705 Instead, we include the array size because the constructor could
1706 be shorter. */
79e68feb 1707 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
fb351073
RK
1708 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
1709 % MAX_HASH_TABLE;
79e68feb 1710 else
eb528802
RS
1711 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
1712 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
79e68feb
RS
1713
1714 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
1715 if (TREE_VALUE (link))
1716 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
79e68feb
RS
1717
1718 return hi;
1719 }
1720 else if (code == ADDR_EXPR)
1721 {
1722 struct addr_const value;
1723 decode_addr_const (exp, &value);
1724 if (GET_CODE (value.base) == SYMBOL_REF)
1725 {
1726 /* Don't hash the address of the SYMBOL_REF;
1727 only use the offset and the symbol name. */
1728 hi = value.offset;
1729 p = XSTR (value.base, 0);
1730 for (i = 0; p[i] != 0; i++)
1731 hi = ((hi * 613) + (unsigned)(p[i]));
1732 }
1733 else if (GET_CODE (value.base) == LABEL_REF)
1734 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
1735
1736 hi &= (1 << HASHBITS) - 1;
1737 hi %= MAX_HASH_TABLE;
1738 return hi;
1739 }
1740 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1741 return const_hash (TREE_OPERAND (exp, 0)) * 9
1742 + const_hash (TREE_OPERAND (exp, 1));
1743 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1744 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
1745
1746 /* Compute hashing function */
1747 hi = len;
1748 for (i = 0; i < len; i++)
1749 hi = ((hi * 613) + (unsigned)(p[i]));
1750
1751 hi &= (1 << HASHBITS) - 1;
1752 hi %= MAX_HASH_TABLE;
1753 return hi;
1754}
1755\f
1756/* Compare a constant expression EXP with a constant-descriptor DESC.
1757 Return 1 if DESC describes a constant with the same value as EXP. */
1758
1759static int
1760compare_constant (exp, desc)
1761 tree exp;
1762 struct constant_descriptor *desc;
1763{
1764 return 0 != compare_constant_1 (exp, desc->contents);
1765}
1766
1767/* Compare constant expression EXP with a substring P of a constant descriptor.
1768 If they match, return a pointer to the end of the substring matched.
1769 If they do not match, return 0.
1770
1771 Since descriptors are written in polish prefix notation,
1772 this function can be used recursively to test one operand of EXP
1773 against a subdescriptor, and if it succeeds it returns the
1774 address of the subdescriptor for the next operand. */
1775
1776static char *
1777compare_constant_1 (exp, p)
1778 tree exp;
1779 char *p;
1780{
1781 register char *strp;
1782 register int len;
1783 register enum tree_code code = TREE_CODE (exp);
1784
1785 if (code != (enum tree_code) *p++)
1786 return 0;
1787
1788 if (code == INTEGER_CST)
1789 {
1790 /* Integer constants are the same only if the same width of type. */
1791 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1792 return 0;
1793 strp = (char *) &TREE_INT_CST_LOW (exp);
1794 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1795 }
1796 else if (code == REAL_CST)
1797 {
1798 /* Real constants are the same only if the same width of type. */
1799 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1800 return 0;
1801 strp = (char *) &TREE_REAL_CST (exp);
1802 len = sizeof TREE_REAL_CST (exp);
1803 }
1804 else if (code == STRING_CST)
1805 {
1806 if (flag_writable_strings)
1807 return 0;
1808 strp = TREE_STRING_POINTER (exp);
1809 len = TREE_STRING_LENGTH (exp);
1810 if (bcmp (&TREE_STRING_LENGTH (exp), p,
1811 sizeof TREE_STRING_LENGTH (exp)))
1812 return 0;
1813 p += sizeof TREE_STRING_LENGTH (exp);
1814 }
1815 else if (code == COMPLEX_CST)
1816 {
1817 p = compare_constant_1 (TREE_REALPART (exp), p);
1818 if (p == 0) return 0;
1819 p = compare_constant_1 (TREE_IMAGPART (exp), p);
1820 return p;
1821 }
1822 else if (code == CONSTRUCTOR)
1823 {
1824 register tree link;
1825 int length = list_length (CONSTRUCTOR_ELTS (exp));
1826 tree type;
1827
1828 if (bcmp (&length, p, sizeof length))
1829 return 0;
1830 p += sizeof length;
1831
1832 /* For record constructors, insist that the types match.
1833 For arrays, just verify both constructors are for arrays. */
1834 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1835 type = TREE_TYPE (exp);
1836 else
1837 type = 0;
1838 if (bcmp (&type, p, sizeof type))
1839 return 0;
1840 p += sizeof type;
1841
eb528802
RS
1842 /* For arrays, insist that the size in bytes match. */
1843 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1844 {
1845 int size = int_size_in_bytes (TREE_TYPE (exp));
1846 if (bcmp (&size, p, sizeof size))
1847 return 0;
1848 p += sizeof size;
1849 }
1850
79e68feb 1851 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
1852 {
1853 if (TREE_VALUE (link))
1854 {
1855 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
1856 return 0;
1857 }
1858 else
1859 {
1860 tree zero = 0;
1861
1862 if (bcmp (&zero, p, sizeof zero))
1863 return 0;
1864 p += sizeof zero;
1865 }
1866 }
1867
79e68feb
RS
1868 return p;
1869 }
1870 else if (code == ADDR_EXPR)
1871 {
1872 struct addr_const value;
1873 decode_addr_const (exp, &value);
1874 strp = (char *) &value.offset;
1875 len = sizeof value.offset;
1876 /* Compare the offset. */
1877 while (--len >= 0)
1878 if (*p++ != *strp++)
1879 return 0;
1880 /* Compare symbol name. */
1881 strp = XSTR (value.base, 0);
1882 len = strlen (strp) + 1;
1883 }
1884 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1885 {
1886 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1887 if (p == 0) return 0;
1888 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
1889 return p;
1890 }
1891 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1892 {
1893 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1894 return p;
1895 }
1896
1897 /* Compare constant contents. */
1898 while (--len >= 0)
1899 if (*p++ != *strp++)
1900 return 0;
1901
1902 return p;
1903}
1904\f
1905/* Construct a constant descriptor for the expression EXP.
1906 It is up to the caller to enter the descriptor in the hash table. */
1907
1908static struct constant_descriptor *
1909record_constant (exp)
1910 tree exp;
1911{
387e854a
RK
1912 struct constant_descriptor *next = 0;
1913 char *label = 0;
79e68feb 1914
387e854a
RK
1915 /* Make a struct constant_descriptor. The first two pointers will
1916 be filled in later. Here we just leave space for them. */
1917
1918 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
1919 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
79e68feb
RS
1920 record_constant_1 (exp);
1921 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
1922}
1923
1924/* Add a description of constant expression EXP
1925 to the object growing in `permanent_obstack'.
1926 No need to return its address; the caller will get that
1927 from the obstack when the object is complete. */
1928
1929static void
1930record_constant_1 (exp)
1931 tree exp;
1932{
1933 register char *strp;
1934 register int len;
1935 register enum tree_code code = TREE_CODE (exp);
1936
1937 obstack_1grow (&permanent_obstack, (unsigned int) code);
1938
1939 if (code == INTEGER_CST)
1940 {
1941 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1942 strp = (char *) &TREE_INT_CST_LOW (exp);
1943 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1944 }
1945 else if (code == REAL_CST)
1946 {
1947 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1948 strp = (char *) &TREE_REAL_CST (exp);
1949 len = sizeof TREE_REAL_CST (exp);
1950 }
1951 else if (code == STRING_CST)
1952 {
1953 if (flag_writable_strings)
1954 return;
1955 strp = TREE_STRING_POINTER (exp);
1956 len = TREE_STRING_LENGTH (exp);
1957 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
1958 sizeof TREE_STRING_LENGTH (exp));
1959 }
1960 else if (code == COMPLEX_CST)
1961 {
1962 record_constant_1 (TREE_REALPART (exp));
1963 record_constant_1 (TREE_IMAGPART (exp));
1964 return;
1965 }
1966 else if (code == CONSTRUCTOR)
1967 {
1968 register tree link;
1969 int length = list_length (CONSTRUCTOR_ELTS (exp));
1970 tree type;
1971
1972 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
1973
1974 /* For record constructors, insist that the types match.
1975 For arrays, just verify both constructors are for arrays. */
1976 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1977 type = TREE_TYPE (exp);
1978 else
1979 type = 0;
1980 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
1981
eb528802
RS
1982 /* For arrays, insist that the size in bytes match. */
1983 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1984 {
1985 int size = int_size_in_bytes (TREE_TYPE (exp));
1986 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
1987 }
1988
79e68feb 1989 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
1990 {
1991 if (TREE_VALUE (link))
1992 record_constant_1 (TREE_VALUE (link));
1993 else
1994 {
1995 tree zero = 0;
1996
1997 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
1998 }
1999 }
2000
79e68feb
RS
2001 return;
2002 }
2003 else if (code == ADDR_EXPR)
2004 {
2005 struct addr_const value;
2006 decode_addr_const (exp, &value);
2007 /* Record the offset. */
2008 obstack_grow (&permanent_obstack,
2009 (char *) &value.offset, sizeof value.offset);
2010 /* Record the symbol name. */
2011 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2012 strlen (XSTR (value.base, 0)) + 1);
2013 return;
2014 }
2015 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2016 {
2017 record_constant_1 (TREE_OPERAND (exp, 0));
2018 record_constant_1 (TREE_OPERAND (exp, 1));
2019 return;
2020 }
2021 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2022 {
2023 record_constant_1 (TREE_OPERAND (exp, 0));
2024 return;
2025 }
2026
2027 /* Record constant contents. */
2028 obstack_grow (&permanent_obstack, strp, len);
2029}
2030\f
ff8f4401
RS
2031/* Record a list of constant expressions that were passed to
2032 output_constant_def but that could not be output right away. */
2033
2034struct deferred_constant
2035{
2036 struct deferred_constant *next;
2037 tree exp;
2038 int reloc;
2039 int labelno;
2040};
2041
2042static struct deferred_constant *deferred_constants;
2043
2044/* Nonzero means defer output of addressed subconstants
2045 (i.e., those for which output_constant_def is called.) */
2046static int defer_addressed_constants_flag;
2047
2048/* Start deferring output of subconstants. */
2049
2050void
2051defer_addressed_constants ()
2052{
2053 defer_addressed_constants_flag++;
2054}
2055
2056/* Stop deferring output of subconstants,
2057 and output now all those that have been deferred. */
2058
2059void
2060output_deferred_addressed_constants ()
2061{
2062 struct deferred_constant *p, *next;
2063
2064 defer_addressed_constants_flag--;
2065
2066 if (defer_addressed_constants_flag > 0)
2067 return;
2068
2069 for (p = deferred_constants; p; p = next)
2070 {
2071 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2072 next = p->next;
2073 free (p);
2074 }
2075
2076 deferred_constants = 0;
2077}
2078\f
79e68feb
RS
2079/* Return an rtx representing a reference to constant data in memory
2080 for the constant expression EXP.
ff8f4401 2081
79e68feb
RS
2082 If assembler code for such a constant has already been output,
2083 return an rtx to refer to it.
ff8f4401
RS
2084 Otherwise, output such a constant in memory (or defer it for later)
2085 and generate an rtx for it.
2086
2087 The TREE_CST_RTL of EXP is set up to point to that rtx.
79e68feb
RS
2088 The const_hash_table records which constants already have label strings. */
2089
2090rtx
2091output_constant_def (exp)
2092 tree exp;
2093{
ff8f4401 2094 register int hash;
79e68feb
RS
2095 register struct constant_descriptor *desc;
2096 char label[256];
2097 char *found = 0;
2098 int reloc;
2099 register rtx def;
2100
2101 if (TREE_CODE (exp) == INTEGER_CST)
2102 abort (); /* No TREE_CST_RTL slot in these. */
2103
2104 if (TREE_CST_RTL (exp))
2105 return TREE_CST_RTL (exp);
2106
2107 /* Make sure any other constants whose addresses appear in EXP
2108 are assigned label numbers. */
2109
2110 reloc = output_addressed_constants (exp);
2111
2112 /* Compute hash code of EXP. Search the descriptors for that hash code
2113 to see if any of them describes EXP. If yes, the descriptor records
2114 the label number already assigned. */
2115
2116 hash = const_hash (exp) % MAX_HASH_TABLE;
2117
2118 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2119 if (compare_constant (exp, desc))
2120 {
2121 found = desc->label;
2122 break;
2123 }
2124
2125 if (found == 0)
2126 {
2127 /* No constant equal to EXP is known to have been output.
2128 Make a constant descriptor to enter EXP in the hash table.
2129 Assign the label number and record it in the descriptor for
2130 future calls to this function to find. */
2131
2132 /* Create a string containing the label name, in LABEL. */
2133 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2134
2135 desc = record_constant (exp);
2136 desc->next = const_hash_table[hash];
2137 desc->label
2138 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2139 const_hash_table[hash] = desc;
2140 }
2141
2142 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2143
2144 push_obstacks_nochange ();
2145 if (TREE_PERMANENT (exp))
2146 end_temporary_allocation ();
2147
2148 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2149
2150 TREE_CST_RTL (exp)
2151 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2152 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
dd43f13d
RS
2153 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2154 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2155 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
79e68feb
RS
2156
2157 pop_obstacks ();
2158
2159 /* Optionally set flags or add text to the name to record information
2160 such as that it is a function name. If the name is changed, the macro
2161 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2162 And if it finds a * at the beginning after doing so, it must handle
2163 that too. */
2164#ifdef ENCODE_SECTION_INFO
2165 ENCODE_SECTION_INFO (exp);
2166#endif
2167
ff8f4401
RS
2168 /* If this is the first time we've seen this particular constant,
2169 output it (or defer its output for later). */
79e68feb
RS
2170 if (found == 0)
2171 {
ff8f4401
RS
2172 if (defer_addressed_constants_flag)
2173 {
2174 struct deferred_constant *p;
2175 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2176
2177 /* We really should copy trees in depth here,
2178 but since this case is the only one that should happen now,
2179 let's do it later. */
2180 if (TREE_CODE (exp) != STRING_CST)
2181 abort ();
2182
2183 push_obstacks_nochange ();
2184 suspend_momentary ();
2185 p->exp = copy_node (exp);
2186 pop_obstacks ();
2187 p->reloc = reloc;
2188 p->labelno = const_labelno++;
2189 p->next = deferred_constants;
2190 deferred_constants = p;
2191 }
2192 else
2193 output_constant_def_contents (exp, reloc, const_labelno++);
2194 }
2195
2196 return TREE_CST_RTL (exp);
2197}
2198
2199/* Now output assembler code to define the label for EXP,
2200 and follow it with the data of EXP. */
79e68feb 2201
ff8f4401
RS
2202static void
2203output_constant_def_contents (exp, reloc, labelno)
2204 tree exp;
2205 int reloc;
2206 int labelno;
2207{
2208 int align;
2209
2210 /* First switch to text section, except for writable strings. */
79e68feb 2211#ifdef SELECT_SECTION
ff8f4401 2212 SELECT_SECTION (exp, reloc);
79e68feb 2213#else
ff8f4401
RS
2214 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2215 || (flag_pic && reloc))
2216 data_section ();
2217 else
2218 readonly_data_section ();
79e68feb
RS
2219#endif
2220
ff8f4401
RS
2221 /* Align the location counter as required by EXP's data type. */
2222 align = TYPE_ALIGN (TREE_TYPE (exp));
79e68feb 2223#ifdef CONSTANT_ALIGNMENT
ff8f4401 2224 align = CONSTANT_ALIGNMENT (exp, align);
79e68feb
RS
2225#endif
2226
ff8f4401
RS
2227 if (align > BITS_PER_UNIT)
2228 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
79e68feb 2229
ff8f4401
RS
2230 /* Output the label itself. */
2231 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
79e68feb 2232
ff8f4401
RS
2233 /* Output the value of EXP. */
2234 output_constant (exp,
2235 (TREE_CODE (exp) == STRING_CST
2236 ? TREE_STRING_LENGTH (exp)
2237 : int_size_in_bytes (TREE_TYPE (exp))));
79e68feb 2238
79e68feb
RS
2239}
2240\f
2241/* Similar hash facility for making memory-constants
2242 from constant rtl-expressions. It is used on RISC machines
2243 where immediate integer arguments and constant addresses are restricted
2244 so that such constants must be stored in memory.
2245
2246 This pool of constants is reinitialized for each function
2247 so each function gets its own constants-pool that comes right before it.
2248
2249 All structures allocated here are discarded when functions are saved for
2250 inlining, so they do not need to be allocated permanently. */
2251
2252#define MAX_RTX_HASH_TABLE 61
57632c51 2253static struct constant_descriptor **const_rtx_hash_table;
79e68feb
RS
2254
2255/* Structure to represent sufficient information about a constant so that
2256 it can be output when the constant pool is output, so that function
2257 integration can be done, and to simplify handling on machines that reference
2258 constant pool as base+displacement. */
2259
2260struct pool_constant
2261{
2262 struct constant_descriptor *desc;
2263 struct pool_constant *next;
2264 enum machine_mode mode;
2265 rtx constant;
2266 int labelno;
2267 int align;
2268 int offset;
2269};
2270
2271/* Pointers to first and last constant in pool. */
2272
2273static struct pool_constant *first_pool, *last_pool;
2274
2275/* Current offset in constant pool (does not include any machine-specific
2276 header. */
2277
2278static int pool_offset;
2279
2280/* Structure used to maintain hash table mapping symbols used to their
2281 corresponding constants. */
2282
2283struct pool_sym
2284{
2285 char *label;
2286 struct pool_constant *pool;
2287 struct pool_sym *next;
2288};
2289
57632c51 2290static struct pool_sym **const_rtx_sym_hash_table;
79e68feb
RS
2291
2292/* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2293 The argument is XSTR (... , 0) */
2294
2295#define SYMHASH(LABEL) \
fb351073 2296 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
79e68feb
RS
2297\f
2298/* Initialize constant pool hashing for next function. */
2299
2300void
2301init_const_rtx_hash_table ()
2302{
57632c51
RS
2303 const_rtx_hash_table
2304 = ((struct constant_descriptor **)
2305 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2306 const_rtx_sym_hash_table
2307 = ((struct pool_sym **)
2308 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2309 bzero (const_rtx_hash_table,
2310 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2311 bzero (const_rtx_sym_hash_table,
2312 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
79e68feb
RS
2313
2314 first_pool = last_pool = 0;
2315 pool_offset = 0;
2316}
2317
57632c51
RS
2318/* Save and restore it for a nested function. */
2319
2320void
2321save_varasm_status (p)
2322 struct function *p;
2323{
2324 p->const_rtx_hash_table = const_rtx_hash_table;
2325 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2326 p->first_pool = first_pool;
2327 p->last_pool = last_pool;
2328 p->pool_offset = pool_offset;
2329}
2330
2331void
2332restore_varasm_status (p)
2333 struct function *p;
2334{
2335 const_rtx_hash_table = p->const_rtx_hash_table;
2336 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2337 first_pool = p->first_pool;
2338 last_pool = p->last_pool;
2339 pool_offset = p->pool_offset;
2340}
2341\f
79e68feb
RS
2342enum kind { RTX_DOUBLE, RTX_INT };
2343
2344struct rtx_const
2345{
2346#ifdef ONLY_INT_FIELDS
2347 unsigned int kind : 16;
2348 unsigned int mode : 16;
2349#else
2350 enum kind kind : 16;
2351 enum machine_mode mode : 16;
2352#endif
2353 union {
2354 union real_extract du;
2355 struct addr_const addr;
2356 } un;
2357};
2358
2359/* Express an rtx for a constant integer (perhaps symbolic)
2360 as the sum of a symbol or label plus an explicit integer.
2361 They are stored into VALUE. */
2362
2363static void
2364decode_rtx_const (mode, x, value)
2365 enum machine_mode mode;
2366 rtx x;
2367 struct rtx_const *value;
2368{
2369 /* Clear the whole structure, including any gaps. */
2370
2371 {
2372 int *p = (int *) value;
2373 int *end = (int *) (value + 1);
2374 while (p < end)
2375 *p++ = 0;
2376 }
2377
2378 value->kind = RTX_INT; /* Most usual kind. */
2379 value->mode = mode;
2380
2381 switch (GET_CODE (x))
2382 {
2383 case CONST_DOUBLE:
2384 value->kind = RTX_DOUBLE;
2385 value->mode = GET_MODE (x);
2386 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2387 break;
2388
2389 case CONST_INT:
2390 value->un.addr.offset = INTVAL (x);
2391 break;
2392
2393 case SYMBOL_REF:
2394 case LABEL_REF:
3d037392 2395 case PC:
79e68feb
RS
2396 value->un.addr.base = x;
2397 break;
2398
2399 case CONST:
2400 x = XEXP (x, 0);
2401 if (GET_CODE (x) == PLUS)
2402 {
2403 value->un.addr.base = XEXP (x, 0);
2404 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2405 abort ();
2406 value->un.addr.offset = INTVAL (XEXP (x, 1));
2407 }
2408 else if (GET_CODE (x) == MINUS)
2409 {
2410 value->un.addr.base = XEXP (x, 0);
2411 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2412 abort ();
2413 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2414 }
2415 else
2416 abort ();
2417 break;
2418
2419 default:
2420 abort ();
2421 }
2422
2423 if (value->kind == RTX_INT && value->un.addr.base != 0)
2424 switch (GET_CODE (value->un.addr.base))
2425 {
2426 case SYMBOL_REF:
2427 case LABEL_REF:
2428 /* Use the string's address, not the SYMBOL_REF's address,
2429 for the sake of addresses of library routines.
2430 For a LABEL_REF, compare labels. */
2431 value->un.addr.base = XEXP (value->un.addr.base, 0);
2432 }
2433}
2434
57632c51
RS
2435/* Given a MINUS expression, simplify it if both sides
2436 include the same symbol. */
2437
2438rtx
2439simplify_subtraction (x)
2440 rtx x;
2441{
2442 struct rtx_const val0, val1;
2443
2444 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2445 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2446
2447 if (val0.un.addr.base == val1.un.addr.base)
2448 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2449 return x;
2450}
2451
79e68feb
RS
2452/* Compute a hash code for a constant RTL expression. */
2453
2454int
2455const_hash_rtx (mode, x)
2456 enum machine_mode mode;
2457 rtx x;
2458{
2459 register int hi, i;
2460
2461 struct rtx_const value;
2462 decode_rtx_const (mode, x, &value);
2463
2464 /* Compute hashing function */
2465 hi = 0;
2466 for (i = 0; i < sizeof value / sizeof (int); i++)
2467 hi += ((int *) &value)[i];
2468
2469 hi &= (1 << HASHBITS) - 1;
2470 hi %= MAX_RTX_HASH_TABLE;
2471 return hi;
2472}
2473
2474/* Compare a constant rtl object X with a constant-descriptor DESC.
2475 Return 1 if DESC describes a constant with the same value as X. */
2476
2477static int
2478compare_constant_rtx (mode, x, desc)
2479 enum machine_mode mode;
2480 rtx x;
2481 struct constant_descriptor *desc;
2482{
2483 register int *p = (int *) desc->contents;
2484 register int *strp;
2485 register int len;
2486 struct rtx_const value;
2487
2488 decode_rtx_const (mode, x, &value);
2489 strp = (int *) &value;
2490 len = sizeof value / sizeof (int);
2491
2492 /* Compare constant contents. */
2493 while (--len >= 0)
2494 if (*p++ != *strp++)
2495 return 0;
2496
2497 return 1;
2498}
2499
2500/* Construct a constant descriptor for the rtl-expression X.
2501 It is up to the caller to enter the descriptor in the hash table. */
2502
2503static struct constant_descriptor *
2504record_constant_rtx (mode, x)
2505 enum machine_mode mode;
2506 rtx x;
2507{
2508 struct constant_descriptor *ptr;
2509 char *label;
2510 struct rtx_const value;
2511
2512 decode_rtx_const (mode, x, &value);
2513
2514 obstack_grow (current_obstack, &ptr, sizeof ptr);
2515 obstack_grow (current_obstack, &label, sizeof label);
2516
2517 /* Record constant contents. */
2518 obstack_grow (current_obstack, &value, sizeof value);
2519
2520 return (struct constant_descriptor *) obstack_finish (current_obstack);
2521}
2522\f
2523/* Given a constant rtx X, make (or find) a memory constant for its value
2524 and return a MEM rtx to refer to it in memory. */
2525
2526rtx
2527force_const_mem (mode, x)
2528 enum machine_mode mode;
2529 rtx x;
2530{
2531 register int hash;
2532 register struct constant_descriptor *desc;
2533 char label[256];
2534 char *found = 0;
2535 rtx def;
2536
2537 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2538 (this will always be true for floating CONST_DOUBLEs that have been
2539 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2540 use the previous copy. Otherwise, make a new one. Note that in
2541 the unlikely event that this same CONST_DOUBLE is used in two different
2542 modes in an alternating fashion, we will allocate a lot of different
2543 memory locations, but this should be extremely rare. */
2544
57632c51
RS
2545 /* Don't use CONST_DOUBLE_MEM in a nested function.
2546 Nested functions have their own constant pools,
2547 so they can't share the same values in CONST_DOUBLE_MEM
2548 with the containing function. */
2549 if (outer_function_chain == 0)
2550 if (GET_CODE (x) == CONST_DOUBLE
2551 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2552 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2553 return CONST_DOUBLE_MEM (x);
79e68feb
RS
2554
2555 /* Compute hash code of X. Search the descriptors for that hash code
2556 to see if any of them describes X. If yes, the descriptor records
2557 the label number already assigned. */
2558
2559 hash = const_hash_rtx (mode, x);
2560
2561 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2562 if (compare_constant_rtx (mode, x, desc))
2563 {
2564 found = desc->label;
2565 break;
2566 }
2567
2568 if (found == 0)
2569 {
2570 register struct pool_constant *pool;
2571 register struct pool_sym *sym;
2572 int align;
2573
2574 /* No constant equal to X is known to have been output.
2575 Make a constant descriptor to enter X in the hash table.
2576 Assign the label number and record it in the descriptor for
2577 future calls to this function to find. */
2578
2579 desc = record_constant_rtx (mode, x);
2580 desc->next = const_rtx_hash_table[hash];
2581 const_rtx_hash_table[hash] = desc;
2582
2583 /* Align the location counter as required by EXP's data type. */
2584 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2585 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2586 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2587
2588 pool_offset += align - 1;
2589 pool_offset &= ~ (align - 1);
2590
2591 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2592
2593 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2594 pool->desc = desc;
2595 pool->constant = x;
2596 pool->mode = mode;
2597 pool->labelno = const_labelno;
2598 pool->align = align;
2599 pool->offset = pool_offset;
2600 pool->next = 0;
2601
2602 if (last_pool == 0)
2603 first_pool = pool;
2604 else
2605 last_pool->next = pool;
2606
2607 last_pool = pool;
2608 pool_offset += GET_MODE_SIZE (mode);
2609
2610 /* Create a string containing the label name, in LABEL. */
2611 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2612
2613 ++const_labelno;
2614
2615 desc->label = found
2616 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2617
2618 /* Add label to symbol hash table. */
2619 hash = SYMHASH (found);
2620 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2621 sym->label = found;
2622 sym->pool = pool;
2623 sym->next = const_rtx_sym_hash_table[hash];
2624 const_rtx_sym_hash_table[hash] = sym;
2625 }
2626
2627 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2628
2629 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2630
2631 RTX_UNCHANGING_P (def) = 1;
2632 /* Mark the symbol_ref as belonging to this constants pool. */
2633 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2634 current_function_uses_const_pool = 1;
2635
57632c51
RS
2636 if (outer_function_chain == 0)
2637 if (GET_CODE (x) == CONST_DOUBLE)
2638 {
2639 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2640 {
2641 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2642 const_double_chain = x;
2643 }
2644 CONST_DOUBLE_MEM (x) = def;
2645 }
79e68feb
RS
2646
2647 return def;
2648}
2649\f
2650/* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2651 the corresponding pool_constant structure. */
2652
2653static struct pool_constant *
2654find_pool_constant (addr)
2655 rtx addr;
2656{
2657 struct pool_sym *sym;
2658 char *label = XSTR (addr, 0);
2659
2660 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2661 if (sym->label == label)
2662 return sym->pool;
2663
2664 abort ();
2665}
2666
2667/* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2668
2669rtx
2670get_pool_constant (addr)
2671 rtx addr;
2672{
2673 return (find_pool_constant (addr))->constant;
2674}
2675
2676/* Similar, return the mode. */
2677
2678enum machine_mode
2679get_pool_mode (addr)
2680 rtx addr;
2681{
2682 return (find_pool_constant (addr))->mode;
2683}
2684
2685/* Similar, return the offset in the constant pool. */
2686
2687int
2688get_pool_offset (addr)
2689 rtx addr;
2690{
2691 return (find_pool_constant (addr))->offset;
2692}
2693
2694/* Return the size of the constant pool. */
2695
2696int
2697get_pool_size ()
2698{
2699 return pool_offset;
2700}
2701\f
2702/* Write all the constants in the constant pool. */
2703
2704void
2705output_constant_pool (fnname, fndecl)
2706 char *fnname;
2707 tree fndecl;
2708{
2709 struct pool_constant *pool;
2710 rtx x;
2711 union real_extract u;
2712
2713#ifdef ASM_OUTPUT_POOL_PROLOGUE
2714 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
2715#endif
2716
2717 for (pool = first_pool; pool; pool = pool->next)
2718 {
2719 x = pool->constant;
2720
2721 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2722 whose CODE_LABEL has been deleted. This can occur if a jump table
2723 is eliminated by optimization. If so, write a constant of zero
7b2b3f1f
RK
2724 instead. Note that this can also happen by turning the
2725 CODE_LABEL into a NOTE. */
2726 if (((GET_CODE (x) == LABEL_REF
2727 && (INSN_DELETED_P (XEXP (x, 0))
2728 || GET_CODE (XEXP (x, 0)) == NOTE)))
79e68feb
RS
2729 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2730 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
7b2b3f1f
RK
2731 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
2732 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
79e68feb
RS
2733 x = const0_rtx;
2734
2735 /* First switch to correct section. */
2736#ifdef SELECT_RTX_SECTION
2737 SELECT_RTX_SECTION (pool->mode, x);
2738#else
2739 readonly_data_section ();
2740#endif
2741
2742#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2743 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
2744 pool->align, pool->labelno, done);
2745#endif
2746
2747 if (pool->align > 1)
2748 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
2749
2750 /* Output the label. */
2751 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
2752
2753 /* Output the value of the constant itself. */
2754 switch (GET_MODE_CLASS (pool->mode))
2755 {
2756 case MODE_FLOAT:
2757 if (GET_CODE (x) != CONST_DOUBLE)
2758 abort ();
2759
2760 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
2761 assemble_real (u.d, pool->mode);
2762 break;
2763
2764 case MODE_INT:
ab8ab9d0 2765 case MODE_PARTIAL_INT:
79e68feb
RS
2766 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
2767 break;
2768
2769 default:
2770 abort ();
2771 }
2772
2773 done: ;
2774 }
2775
2776 /* Done with this pool. */
2777 first_pool = last_pool = 0;
2778}
2779\f
2780/* Find all the constants whose addresses are referenced inside of EXP,
2781 and make sure assembler code with a label has been output for each one.
2782 Indicate whether an ADDR_EXPR has been encountered. */
2783
2784int
2785output_addressed_constants (exp)
2786 tree exp;
2787{
2788 int reloc = 0;
2789
2790 switch (TREE_CODE (exp))
2791 {
2792 case ADDR_EXPR:
2793 {
2794 register tree constant = TREE_OPERAND (exp, 0);
2795
2796 while (TREE_CODE (constant) == COMPONENT_REF)
2797 {
2798 constant = TREE_OPERAND (constant, 0);
2799 }
2800
2801 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
2802 || TREE_CODE (constant) == CONSTRUCTOR)
2803 /* No need to do anything here
2804 for addresses of variables or functions. */
2805 output_constant_def (constant);
2806 }
2807 reloc = 1;
2808 break;
2809
2810 case PLUS_EXPR:
2811 case MINUS_EXPR:
2812 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2813 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
2814 break;
2815
2816 case NOP_EXPR:
2817 case CONVERT_EXPR:
37a52112 2818 case NON_LVALUE_EXPR:
79e68feb
RS
2819 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2820 break;
2821
2822 case CONSTRUCTOR:
2823 {
2824 register tree link;
2825 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2826 if (TREE_VALUE (link) != 0)
2827 reloc |= output_addressed_constants (TREE_VALUE (link));
2828 }
2829 break;
2830
2831 case ERROR_MARK:
2832 break;
2833 }
2834 return reloc;
2835}
2836\f
2837/* Output assembler code for constant EXP to FILE, with no label.
2838 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2839 Assumes output_addressed_constants has been done on EXP already.
2840
2841 Generate exactly SIZE bytes of assembler data, padding at the end
2842 with zeros if necessary. SIZE must always be specified.
2843
2844 SIZE is important for structure constructors,
2845 since trailing members may have been omitted from the constructor.
2846 It is also important for initialization of arrays from string constants
2847 since the full length of the string constant might not be wanted.
2848 It is also needed for initialization of unions, where the initializer's
2849 type is just one member, and that may not be as long as the union.
2850
2851 There a case in which we would fail to output exactly SIZE bytes:
2852 for a structure constructor that wants to produce more than SIZE bytes.
2853 But such constructors will never be generated for any possible input. */
2854
2855void
2856output_constant (exp, size)
2857 register tree exp;
2858 register int size;
2859{
2860 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
2861 rtx x;
2862
2863 if (size == 0)
2864 return;
2865
fff9e713
MT
2866 /* Allow a constructor with no elements for any data type.
2867 This means to fill the space with zeros. */
77fa0940 2868 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
fff9e713
MT
2869 {
2870 assemble_zeros (size);
2871 return;
2872 }
2873
79e68feb
RS
2874 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2875 That way we get the constant (we hope) inside it. */
2876 if (TREE_CODE (exp) == NOP_EXPR
2877 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
2878 exp = TREE_OPERAND (exp, 0);
2879
2880 switch (code)
2881 {
644ea577
RS
2882 case CHAR_TYPE:
2883 case BOOLEAN_TYPE:
79e68feb
RS
2884 case INTEGER_TYPE:
2885 case ENUMERAL_TYPE:
2886 case POINTER_TYPE:
2887 case REFERENCE_TYPE:
2888 /* ??? What about (int)((float)(int)&foo + 4) */
2889 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
2890 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2891 exp = TREE_OPERAND (exp, 0);
2892
37366632 2893 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
79e68feb
RS
2894 EXPAND_INITIALIZER),
2895 size, 0))
2896 error ("initializer for integer value is too complicated");
2897 size = 0;
2898 break;
2899
2900 case REAL_TYPE:
2901 if (TREE_CODE (exp) != REAL_CST)
2902 error ("initializer for floating value is not a floating constant");
2903
2904 assemble_real (TREE_REAL_CST (exp),
2905 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
2906 size = 0;
2907 break;
2908
2909 case COMPLEX_TYPE:
2910 output_constant (TREE_REALPART (exp), size / 2);
2911 output_constant (TREE_IMAGPART (exp), size / 2);
2912 size -= (size / 2) * 2;
2913 break;
2914
2915 case ARRAY_TYPE:
2916 if (TREE_CODE (exp) == CONSTRUCTOR)
2917 {
2918 output_constructor (exp, size);
2919 return;
2920 }
2921 else if (TREE_CODE (exp) == STRING_CST)
2922 {
2923 int excess = 0;
2924
2925 if (size > TREE_STRING_LENGTH (exp))
2926 {
2927 excess = size - TREE_STRING_LENGTH (exp);
2928 size = TREE_STRING_LENGTH (exp);
2929 }
2930
2931 assemble_string (TREE_STRING_POINTER (exp), size);
2932 size = excess;
2933 }
2934 else
2935 abort ();
2936 break;
2937
2938 case RECORD_TYPE:
2939 case UNION_TYPE:
2940 if (TREE_CODE (exp) == CONSTRUCTOR)
2941 output_constructor (exp, size);
2942 else
2943 abort ();
2944 return;
2945 }
2946
2947 if (size > 0)
2948 assemble_zeros (size);
2949}
2950\f
2951/* Subroutine of output_constant, used for CONSTRUCTORs
2952 (aggregate constants).
2953 Generate at least SIZE bytes, padding if necessary. */
2954
2955void
2956output_constructor (exp, size)
2957 tree exp;
2958 int size;
2959{
2960 register tree link, field = 0;
2961 /* Number of bytes output or skipped so far.
2962 In other words, current position within the constructor. */
2963 int total_bytes = 0;
2964 /* Non-zero means BYTE contains part of a byte, to be output. */
2965 int byte_buffer_in_use = 0;
2966 register int byte;
2967
37366632 2968 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
79e68feb
RS
2969 abort ();
2970
2971 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2972 field = TYPE_FIELDS (TREE_TYPE (exp));
2973
2974 /* As LINK goes through the elements of the constant,
2975 FIELD goes through the structure fields, if the constant is a structure.
2976 if the constant is a union, then we override this,
2977 by getting the field from the TREE_LIST element.
2978 But the constant could also be an array. Then FIELD is zero. */
2979 for (link = CONSTRUCTOR_ELTS (exp);
2980 link;
2981 link = TREE_CHAIN (link),
2982 field = field ? TREE_CHAIN (field) : 0)
2983 {
2984 tree val = TREE_VALUE (link);
2985 /* the element in a union constructor specifies the proper field. */
2986 if (TREE_PURPOSE (link) != 0)
2987 field = TREE_PURPOSE (link);
2988
2989 /* Eliminate the marker that makes a cast not be an lvalue. */
d964285c
CH
2990 if (val != 0)
2991 STRIP_NOPS (val);
79e68feb
RS
2992
2993 if (field == 0 || !DECL_BIT_FIELD (field))
2994 {
2995 register int fieldsize;
2996 /* Since this structure is static,
2997 we know the positions are constant. */
2998 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
2999 / BITS_PER_UNIT)
3000 : 0);
3001
3002 /* An element that is not a bit-field.
3003 Output any buffered-up bit-fields preceding it. */
3004 if (byte_buffer_in_use)
3005 {
3006 ASM_OUTPUT_BYTE (asm_out_file, byte);
3007 total_bytes++;
3008 byte_buffer_in_use = 0;
3009 }
3010
3011 /* Advance to offset of this element.
3012 Note no alignment needed in an array, since that is guaranteed
3013 if each element has the proper size. */
3014 if (field != 0 && bitpos != total_bytes)
3015 {
3016 assemble_zeros (bitpos - total_bytes);
3017 total_bytes = bitpos;
3018 }
3019
3020 /* Determine size this element should occupy. */
3021 if (field)
3022 {
3023 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3024 abort ();
3025 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3026 {
3027 /* This avoids overflow trouble. */
3028 tree size_tree = size_binop (CEIL_DIV_EXPR,
3029 DECL_SIZE (field),
3030 size_int (BITS_PER_UNIT));
3031 fieldsize = TREE_INT_CST_LOW (size_tree);
3032 }
3033 else
3034 {
3035 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3036 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3037 }
3038 }
3039 else
3040 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3041
3042 /* Output the element's initial value. */
3043 if (val == 0)
3044 assemble_zeros (fieldsize);
3045 else
3046 output_constant (val, fieldsize);
3047
3048 /* Count its size. */
3049 total_bytes += fieldsize;
3050 }
3051 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3052 error ("invalid initial value for member `%s'",
3053 IDENTIFIER_POINTER (DECL_NAME (field)));
3054 else
3055 {
3056 /* Element that is a bit-field. */
3057
3058 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3059 int end_offset
3060 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3061
3062 if (val == 0)
3063 val = integer_zero_node;
3064
3065 /* If this field does not start in this (or, next) byte,
3066 skip some bytes. */
3067 if (next_offset / BITS_PER_UNIT != total_bytes)
3068 {
3069 /* Output remnant of any bit field in previous bytes. */
3070 if (byte_buffer_in_use)
3071 {
3072 ASM_OUTPUT_BYTE (asm_out_file, byte);
3073 total_bytes++;
3074 byte_buffer_in_use = 0;
3075 }
3076
3077 /* If still not at proper byte, advance to there. */
3078 if (next_offset / BITS_PER_UNIT != total_bytes)
3079 {
3080 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3081 total_bytes = next_offset / BITS_PER_UNIT;
3082 }
3083 }
3084
3085 if (! byte_buffer_in_use)
3086 byte = 0;
3087
3088 /* We must split the element into pieces that fall within
3089 separate bytes, and combine each byte with previous or
3090 following bit-fields. */
3091
b4ac57ab 3092 /* next_offset is the offset n fbits from the beginning of
79e68feb
RS
3093 the structure to the next bit of this element to be processed.
3094 end_offset is the offset of the first bit past the end of
3095 this element. */
3096 while (next_offset < end_offset)
3097 {
3098 int this_time;
3099 int shift, value;
3100 int next_byte = next_offset / BITS_PER_UNIT;
3101 int next_bit = next_offset % BITS_PER_UNIT;
3102
3103 /* Advance from byte to byte
3104 within this element when necessary. */
3105 while (next_byte != total_bytes)
3106 {
3107 ASM_OUTPUT_BYTE (asm_out_file, byte);
3108 total_bytes++;
3109 byte = 0;
3110 }
3111
3112 /* Number of bits we can process at once
3113 (all part of the same byte). */
3114 this_time = MIN (end_offset - next_offset,
3115 BITS_PER_UNIT - next_bit);
3116#if BYTES_BIG_ENDIAN
3117 /* On big-endian machine, take the most significant bits
3118 first (of the bits that are significant)
3119 and put them into bytes from the most significant end. */
3120 shift = end_offset - next_offset - this_time;
3121 /* Don't try to take a bunch of bits that cross
3122 the word boundary in the INTEGER_CST. */
37366632
RK
3123 if (shift < HOST_BITS_PER_WIDE_INT
3124 && shift + this_time > HOST_BITS_PER_WIDE_INT)
79e68feb 3125 {
37366632
RK
3126 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3127 shift = HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3128 }
3129
3130 /* Now get the bits from the appropriate constant word. */
37366632 3131 if (shift < HOST_BITS_PER_WIDE_INT)
79e68feb
RS
3132 {
3133 value = TREE_INT_CST_LOW (val);
3134 }
37366632 3135 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
3136 {
3137 value = TREE_INT_CST_HIGH (val);
37366632 3138 shift -= HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3139 }
3140 else
3141 abort ();
37366632
RK
3142 byte |= (((value >> shift)
3143 & (((HOST_WIDE_INT) 1 << this_time) - 1))
79e68feb
RS
3144 << (BITS_PER_UNIT - this_time - next_bit));
3145#else
3146 /* On little-endian machines,
3147 take first the least significant bits of the value
3148 and pack them starting at the least significant
3149 bits of the bytes. */
3150 shift = (next_offset
3151 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3152 /* Don't try to take a bunch of bits that cross
3153 the word boundary in the INTEGER_CST. */
37366632
RK
3154 if (shift < HOST_BITS_PER_WIDE_INT
3155 && shift + this_time > HOST_BITS_PER_WIDE_INT)
79e68feb 3156 {
37366632
RK
3157 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3158 shift = HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3159 }
3160
3161 /* Now get the bits from the appropriate constant word. */
3162 if (shift < HOST_BITS_PER_INT)
3163 value = TREE_INT_CST_LOW (val);
37366632 3164 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
3165 {
3166 value = TREE_INT_CST_HIGH (val);
37366632 3167 shift -= HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3168 }
3169 else
3170 abort ();
37366632
RK
3171 byte |= ((value >> shift)
3172 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
79e68feb
RS
3173#endif
3174 next_offset += this_time;
3175 byte_buffer_in_use = 1;
3176 }
3177 }
3178 }
3179 if (byte_buffer_in_use)
3180 {
3181 ASM_OUTPUT_BYTE (asm_out_file, byte);
3182 total_bytes++;
3183 }
3184 if (total_bytes < size)
3185 assemble_zeros (size - total_bytes);
3186}