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