1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
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.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 /* #include <stab.h> */
36 #include "hard-reg-set.h"
42 #ifdef XCOFF_DEBUGGING_INFO
47 #define ASM_STABS_OP ".stabs"
50 /* File in which assembler code is being written. */
52 extern FILE *asm_out_file
;
54 /* The (assembler) name of the first globally-visible object output. */
55 char *first_global_object_name
;
57 extern struct obstack
*current_obstack
;
58 extern struct obstack
*saveable_obstack
;
59 extern struct obstack permanent_obstack
;
60 #define obstack_chunk_alloc xmalloc
61 extern int xmalloc ();
63 /* Number for making the label on the next
64 constant that is stored in memory. */
68 /* Number for making the label on the next
69 static variable internal to a function. */
73 /* Nonzero if at least one function definition has been seen. */
74 static int function_defined
;
76 extern FILE *asm_out_file
;
78 static char *compare_constant_1 ();
79 static void record_constant_1 ();
80 void output_constant_pool ();
81 void assemble_name ();
82 int output_addressed_constants ();
83 void output_constant ();
84 void output_constructor ();
86 void readonly_data_section ();
90 static enum in_section
{no_section
, in_text
, in_data
, EXTRA_SECTIONS
} in_section
93 static enum in_section
{no_section
, in_text
, in_data
} in_section
97 /* Define functions like text_section for any extra sections. */
98 #ifdef EXTRA_SECTION_FUNCTIONS
99 EXTRA_SECTION_FUNCTIONS
102 /* Tell assembler to switch to text section. */
107 if (in_section
!= in_text
)
109 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
110 in_section
= in_text
;
114 /* Tell assembler to switch to data section. */
119 if (in_section
!= in_data
)
121 if (flag_shared_data
)
123 #ifdef SHARED_SECTION_ASM_OP
124 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
126 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
130 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
132 in_section
= in_data
;
136 /* Tell assembler to switch to read-only data section. This is normally
140 readonly_data_section ()
142 #ifdef READONLY_DATA_SECTION
143 READONLY_DATA_SECTION (); /* Note this can call data_section. */
149 /* Determine if we're in the text section. */
154 return in_section
== in_text
;
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. */
162 make_function_rtl (decl
)
165 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
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)
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
));
180 if (DECL_RTL (decl
) == 0)
183 = gen_rtx (MEM
, DECL_MODE (decl
),
184 gen_rtx (SYMBOL_REF
, Pmode
, name
));
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
191 #ifdef ENCODE_SECTION_INFO
192 ENCODE_SECTION_INFO (decl
);
196 /* Record at least one function has been defined. */
197 function_defined
= 1;
200 /* Given NAME, a putative register name, discard any customary prefixes. */
203 strip_reg_name (name
)
206 #ifdef REGISTER_PREFIX
207 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
208 name
+= strlen (REGISTER_PREFIX
);
210 if (name
[0] == '%' || name
[0] == '#')
215 /* Decode an `asm' spec for a declaration as a register name.
216 Return the register number, or -1 if nothing specified,
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.
220 Accept an exact spelling or a decimal number.
221 Prefixes such as % are optional. */
224 decode_reg_name (asmspec
)
231 /* Get rid of confusing prefixes. */
232 asmspec
= strip_reg_name (asmspec
);
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'))
238 if (asmspec
[0] != 0 && i
< 0)
241 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
247 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
249 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
252 #ifdef ADDITIONAL_REGISTER_NAMES
254 static struct { char *name
; int number
; } table
[]
255 = ADDITIONAL_REGISTER_NAMES
;
257 for (i
= 0; i
< sizeof (table
) / sizeof (table
[0]); i
++)
258 if (! strcmp (asmspec
, table
[i
].name
))
259 return table
[i
].number
;
261 #endif /* ADDITIONAL_REGISTER_NAMES */
263 if (!strcmp (asmspec
, "memory"))
266 if (!strcmp (asmspec
, "cc"))
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.
281 This is never called for PARM_DECL nodes. */
284 make_decl_rtl (decl
, asmspec
, top_level
)
290 int reg_number
= decode_reg_name (asmspec
);
292 if (DECL_ASSEMBLER_NAME (decl
) != NULL_TREE
)
293 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
295 if (reg_number
== -2)
297 /* ASMSPEC is given, and not the name of a register. */
298 name
= (char *) obstack_alloc (saveable_obstack
,
299 strlen (asmspec
) + 2);
301 strcpy (&name
[1], asmspec
);
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
))
313 /* First detect errors in declaring global registers. */
314 if (TREE_REGDECL (decl
) && reg_number
== -1)
315 error_with_decl (decl
,
316 "register name not specified for `%s'");
317 else if (TREE_REGDECL (decl
) && reg_number
< 0)
318 error_with_decl (decl
,
319 "invalid register name for `%s'");
320 else if ((reg_number
>= 0 || reg_number
== -3) && ! TREE_REGDECL (decl
))
321 error_with_decl (decl
,
322 "register name given for non-register variable `%s'");
323 else if (TREE_REGDECL (decl
) && TREE_CODE (decl
) == FUNCTION_DECL
)
324 error ("function declared `register'");
325 else if (TREE_REGDECL (decl
) && TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
326 error_with_decl (decl
, "data type of `%s' isn't suitable for a register");
327 /* Now handle properly declared static register variables. */
328 else if (TREE_REGDECL (decl
))
331 #if 0 /* yylex should print the warning for this */
333 pedwarn ("ANSI C forbids global register variables");
335 if (DECL_INITIAL (decl
) != 0 && top_level
)
337 DECL_INITIAL (decl
) = 0;
338 error ("global register variable has initial value");
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;
350 /* Make this register fixed, so not usable for anything else. */
351 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
353 global_regs
[reg_number
+ --nregs
] = 1;
358 /* Now handle ordinary static variables and functions (in memory).
359 Also handle vars declared register invalidly. */
360 if (DECL_RTL (decl
) == 0)
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. */
365 if (!top_level
&& !TREE_EXTERNAL (decl
) && asmspec
== 0)
369 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
370 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
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
);
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
);
398 /* Output a string of literal assembler code
399 for an `asm' keyword used between functions. */
402 assemble_asm (string
)
407 if (TREE_CODE (string
) == ADDR_EXPR
)
408 string
= TREE_OPERAND (string
, 0);
410 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
413 /* Tiemann: please get rid of this conditional and put appropriate
414 definitions in each of the files that should have them.
415 The type of debugging format is not the right parameter to
416 control how some other aspect of assembler output is done. */
418 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
419 #ifndef ASM_OUTPUT_CONSTRUCTOR
420 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
422 #ifndef ASM_OUTPUT_DESTRUCTOR
423 #define ASM_OUTPUT_DESTRUCTOR(file, name)
427 /* Record an element in the table of global destructors.
428 How this is done depends on what sort of assembler and linker
431 NAME should be the name of a global function to be called
432 at exit time. This name is output using assemble_name. */
435 assemble_destructor (name
)
438 #ifdef ASM_OUTPUT_DESTRUCTOR
439 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
443 /* Now tell GNU LD that this is part of the static destructor set. */
444 /* This code works for any machine provided you use GNU as/ld. */
445 fprintf (asm_out_file
, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
446 assemble_name (asm_out_file
, name
);
447 fputc ('\n', asm_out_file
);
452 /* Likewise for global constructors. */
455 assemble_constructor (name
)
458 #ifdef ASM_OUTPUT_CONSTRUCTOR
459 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
463 /* Now tell GNU LD that this is part of the static constructor set. */
464 /* This code works for any machine provided you use GNU as/ld. */
465 fprintf (asm_out_file
, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
466 assemble_name (asm_out_file
, name
);
467 fputc ('\n', asm_out_file
);
472 /* Likewise for entries we want to record for garbage collection.
473 Garbage collection is still under development. */
476 assemble_gc_entry (name
)
479 #ifdef ASM_OUTPUT_GC_ENTRY
480 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
484 /* Now tell GNU LD that this is part of the static constructor set. */
485 fprintf (asm_out_file
, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
486 assemble_name (asm_out_file
, name
);
487 fputc ('\n', asm_out_file
);
492 /* Output assembler code for the constant pool of a function and associated
493 with defining the name of the function. DECL describes the function.
494 NAME is the function's name. For the constant pool, we use the current
495 constant pool data. */
498 assemble_start_function (decl
, fnname
)
504 /* The following code does not need preprocessing in the assembler. */
508 output_constant_pool (fnname
, decl
);
513 /* Tell assembler to move to target machine's alignment for functions. */
514 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
516 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
518 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
519 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
522 #ifdef SDB_DEBUGGING_INFO
523 /* Output SDB definition of the function. */
524 if (write_symbols
== SDB_DEBUG
)
525 sdbout_mark_begin_function ();
528 #ifdef DBX_DEBUGGING_INFO
529 /* Output DBX definition of the function. */
530 if (write_symbols
== DBX_DEBUG
)
531 dbxout_begin_function (decl
);
534 /* Make function name accessible from other files, if appropriate. */
536 if (TREE_PUBLIC (decl
))
538 if (!first_global_object_name
)
539 first_global_object_name
= fnname
+ (fnname
[0] == '*');
540 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
543 /* Do any machine/system dependent processing of the function name */
544 #ifdef ASM_DECLARE_FUNCTION_NAME
545 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
547 /* Standard thing is just output label for the function. */
548 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
549 #endif /* ASM_DECLARE_FUNCTION_NAME */
552 /* Output assembler code associated with defining the size of the
553 function. DECL describes the function. NAME is the function's name. */
556 assemble_end_function (decl
, fnname
)
560 #ifdef ASM_DECLARE_FUNCTION_SIZE
561 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
565 /* Assemble code to leave SIZE bytes of zeros. */
568 assemble_zeros (size
)
571 #ifdef ASM_NO_SKIP_IN_TEXT
572 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
573 so we must output 0s explicitly in the text section. */
574 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
578 for (i
= 0; i
< size
- 20; i
+= 20)
581 fprintf (asm_out_file
,
582 "%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
);
584 fprintf (asm_out_file
,
585 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
591 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
593 fprintf (asm_out_file
, "\tbyte 0");
596 for (; i
< size
; i
++)
597 fprintf (asm_out_file
, ",0");
598 fprintf (asm_out_file
, "\n");
603 ASM_OUTPUT_SKIP (asm_out_file
, size
);
606 /* Assemble a string constant with the specified C string as contents. */
609 assemble_string (p
, size
)
617 /* If the string is very long, split it up. */
621 int thissize
= size
- pos
;
622 if (thissize
> maximum
)
625 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
632 /* Assemble everything that is needed for a variable or function declaration.
633 Not used for automatic variables, and not used for function definitions.
634 Should not be called for variables of incomplete structure type.
636 TOP_LEVEL is nonzero if this variable has file scope.
637 AT_END is nonzero if this is the special handling, at end of compilation,
638 to define things that have had only tentative definitions. */
641 assemble_variable (decl
, top_level
, at_end
)
651 if (GET_CODE (DECL_RTL (decl
)) == REG
)
653 /* Do output symbol info for global register variables, but do nothing
656 if (TREE_ASM_WRITTEN (decl
))
658 TREE_ASM_WRITTEN (decl
) = 1;
660 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
661 /* File-scope global variables are output here. */
662 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
664 dbxout_symbol (decl
, 0);
666 #ifdef SDB_DEBUGGING_INFO
667 if (write_symbols
== SDB_DEBUG
&& top_level
668 /* Leave initialized global vars for end of compilation;
669 see comment in compile_file. */
670 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
671 sdbout_symbol (decl
, 0);
674 /* Don't output any DWARF debugging information for variables here.
675 In the case of local variables, the information for them is output
676 when we do our recursive traversal of the tree representation for
677 the entire containing function. In the case of file-scope variables,
678 we output information for all of them at the very end of compilation
679 while we are doing our final traversal of the chain of file-scope
685 /* Normally no need to say anything for external references,
686 since assembler considers all undefined symbols external. */
688 if (TREE_EXTERNAL (decl
))
691 /* Output no assembler code for a function declaration.
692 Only definitions of functions output anything. */
694 if (TREE_CODE (decl
) == FUNCTION_DECL
)
697 /* If type was incomplete when the variable was declared,
698 see if it is complete now. */
700 if (DECL_SIZE (decl
) == 0)
701 layout_decl (decl
, 0);
703 /* Still incomplete => don't allocate it; treat the tentative defn
704 (which is what it must have been) as an `extern' reference. */
706 if (DECL_SIZE (decl
) == 0)
708 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
709 DECL_SOURCE_LINE (decl
),
710 "storage size of static var `%s' isn't known",
711 IDENTIFIER_POINTER (DECL_NAME (decl
)));
715 /* The first declaration of a variable that comes through this function
716 decides whether it is global (in C, has external linkage)
717 or local (in C, has internal linkage). So do nothing more
718 if this function has already run. */
720 if (TREE_ASM_WRITTEN (decl
))
723 TREE_ASM_WRITTEN (decl
) = 1;
725 #ifdef DBX_DEBUGGING_INFO
726 /* File-scope global variables are output here. */
727 if (write_symbols
== DBX_DEBUG
&& top_level
)
728 dbxout_symbol (decl
, 0);
730 #ifdef SDB_DEBUGGING_INFO
731 if (write_symbols
== SDB_DEBUG
&& top_level
732 /* Leave initialized global vars for end of compilation;
733 see comment in compile_file. */
734 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
735 sdbout_symbol (decl
, 0);
738 /* Don't output any DWARF debugging information for variables here.
739 In the case of local variables, the information for them is output
740 when we do our recursive traversal of the tree representation for
741 the entire containing function. In the case of file-scope variables,
742 we output information for all of them at the very end of compilation
743 while we are doing our final traversal of the chain of file-scope
746 /* If storage size is erroneously variable, just continue.
747 Error message was already made. */
749 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
754 /* This is better than explicit arithmetic, since it avoids overflow. */
755 size_tree
= size_binop (CEIL_DIV_EXPR
,
756 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
758 if (TREE_INT_CST_HIGH (size_tree
) != 0)
760 error_with_decl (decl
, "size of variable `%s' is too large");
764 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
766 /* Handle uninitialized definitions. */
768 /* ANSI specifies that a tentative definition which is not merged with
769 a non-tentative definition behaves exactly like a definition with an
770 initializer equal to zero. (Section 3.7.2)
771 -fno-common gives strict ANSI behavior. Usually you don't want it. */
773 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
775 int size
= TREE_INT_CST_LOW (size_tree
);
778 if (TREE_INT_CST_HIGH (size_tree
) != 0)
779 error_with_decl (decl
, "size of variable `%s' is too large");
780 /* Don't allocate zero bytes of common,
781 since that means "undefined external" in the linker. */
782 if (size
== 0) rounded
= 1;
783 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
784 so that each uninitialized object starts on such a boundary. */
785 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
786 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
787 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
789 if (flag_shared_data
)
792 if (TREE_PUBLIC (decl
))
794 #ifdef ASM_OUTPUT_SHARED_COMMON
795 if (flag_shared_data
)
796 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
799 #ifdef ASM_OUTPUT_ALIGNED_COMMON
800 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
803 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
808 #ifdef ASM_OUTPUT_SHARED_LOCAL
809 if (flag_shared_data
)
810 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
813 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
814 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
817 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
823 /* Handle initialized definitions. */
825 /* First make the assembler name(s) global if appropriate. */
826 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
828 if (!first_global_object_name
)
829 first_global_object_name
= name
+ (name
[0] == '*');
830 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
833 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
835 tree e
= TREE_VALUE (d
);
836 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
837 ASM_GLOBALIZE_LABEL (asm_out_file
,
838 XSTR (XEXP (DECL_RTL (e
), 0), 0));
842 /* Output any data that we will need to use the address of. */
843 if (DECL_INITIAL (decl
))
844 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
846 /* Switch to the proper section for this data. */
847 #ifdef SELECT_SECTION
848 SELECT_SECTION (decl
, reloc
);
850 if (TREE_READONLY (decl
)
851 && ! TREE_THIS_VOLATILE (decl
)
852 && ! (flag_pic
&& reloc
))
853 readonly_data_section ();
858 /* Compute and output the alignment of this data. */
860 align
= DECL_ALIGN (decl
);
861 /* Some object file formats have a maximum alignment which they support.
862 In particular, a.out format supports a maximum alignment of 4. */
863 #ifndef MAX_OFILE_ALIGNMENT
864 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
866 if (align
> MAX_OFILE_ALIGNMENT
)
868 warning_with_decl (decl
,
869 "alignment of `%s' is greater than maximum object file alignment");
870 align
= MAX_OFILE_ALIGNMENT
;
872 #ifdef DATA_ALIGNMENT
873 /* On some machines, it is good to increase alignment sometimes. */
874 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
876 #ifdef CONSTANT_ALIGNMENT
877 if (DECL_INITIAL (decl
))
878 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
881 /* Reset the alignment in case we have made it tighter, so we can benefit
882 from it in get_pointer_alignment. */
883 DECL_ALIGN (decl
) = align
;
885 if (align
> BITS_PER_UNIT
)
886 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
888 /* Do any machine/system dependent processing of the object. */
889 #ifdef ASM_DECLARE_OBJECT_NAME
890 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
892 /* Standard thing is just output label for the object. */
893 ASM_OUTPUT_LABEL (asm_out_file
, name
);
894 #endif /* ASM_DECLARE_OBJECT_NAME */
897 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
899 tree e
= TREE_VALUE (d
);
900 ASM_OUTPUT_LABEL (asm_out_file
, XSTR (XEXP (DECL_RTL (e
), 0), 0));
904 if (DECL_INITIAL (decl
))
905 /* Output the actual data. */
906 output_constant (DECL_INITIAL (decl
),
907 int_size_in_bytes (TREE_TYPE (decl
)));
909 /* Leave space for it. */
910 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl
)));
913 #ifdef XCOFF_DEBUGGING_INFO
914 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
915 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
916 and `aa' hasn't been output yet, the assembler generates a stab entry with
917 a value of zero, in addition to creating an unnecessary external entry
918 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
920 /* File-scope global variables are output here. */
921 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
922 dbxout_symbol (decl
, 0);
924 /* There must be a statement after a label. */
929 /* Output something to declare an external symbol to the assembler.
930 (Most assemblers don't need this, so we normally output nothing.)
931 Do nothing if DECL is not external. */
934 assemble_external (decl
)
937 #ifdef ASM_OUTPUT_EXTERNAL
938 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
939 && TREE_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
941 rtx rtl
= DECL_RTL (decl
);
943 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
944 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
946 /* Some systems do require some output. */
947 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
948 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
954 /* Similar, for calling a library function FUN. */
957 assemble_external_libcall (fun
)
960 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
961 /* Declare library function name external when first used, if nec. */
962 if (! SYMBOL_REF_USED (fun
))
964 SYMBOL_REF_USED (fun
) = 1;
965 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
970 /* Declare the label NAME global. */
973 assemble_global (name
)
976 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
979 /* Assemble a label named NAME. */
982 assemble_label (name
)
985 ASM_OUTPUT_LABEL (asm_out_file
, name
);
988 /* Output to FILE a reference to the assembler name of a C-level name NAME.
989 If NAME starts with a *, the rest of NAME is output verbatim.
990 Otherwise NAME is transformed in an implementation-defined way
991 (usually by the addition of an underscore).
992 Many macros in the tm file are defined to call this function. */
995 assemble_name (file
, name
)
1000 fputs (&name
[1], file
);
1002 ASM_OUTPUT_LABELREF (file
, name
);
1005 /* Allocate SIZE bytes writable static space with a gensym name
1006 and return an RTX to refer to its address. */
1009 assemble_static_space (size
)
1015 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1016 so that each uninitialized object starts on such a boundary. */
1017 int rounded
= ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1018 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1019 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1022 if (flag_shared_data
)
1026 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1029 namestring
= (char *) obstack_alloc (saveable_obstack
,
1031 strcpy (namestring
, name
);
1033 x
= gen_rtx (SYMBOL_REF
, Pmode
, namestring
);
1034 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1035 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1037 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1042 /* Assemble the static constant template for function entry trampolines.
1043 This is done at most once per compilation.
1044 Returns an RTX for the address of the template. */
1047 assemble_trampoline_template ()
1053 /* Write the assembler code to define one. */
1054 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1056 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1058 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1059 TRAMPOLINE_TEMPLATE (asm_out_file
);
1061 /* Record the rtl to refer to it. */
1062 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1064 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1065 return gen_rtx (SYMBOL_REF
, Pmode
, name
);
1068 /* Assemble the integer constant X into an object of SIZE bytes.
1069 X must be either a CONST_INT or CONST_DOUBLE.
1071 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1072 non-zero, abort if we can't output the constant. */
1075 assemble_integer (x
, size
, force
)
1080 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1081 ASM_OUTPUT... macros. */
1085 #ifdef ASM_OUTPUT_CHAR
1087 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1091 #ifdef ASM_OUTPUT_SHORT
1093 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1097 #ifdef ASM_OUTPUT_INT
1099 ASM_OUTPUT_INT (asm_out_file
, x
);
1103 #ifdef ASM_OUTPUT_DOUBLE_INT
1105 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1109 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1111 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1116 /* If we couldn't do it that way, there are two other possibilities: First,
1117 if the machine can output an explicit byte and this is a 1 byte constant,
1118 we can use ASM_OUTPUT_BYTE. */
1120 #ifdef ASM_OUTPUT_BYTE
1121 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1123 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1128 /* Finally, if SIZE is larger than a single word, try to output the constant
1129 one word at a time. */
1131 if (size
> UNITS_PER_WORD
)
1134 enum machine_mode mode
1135 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1138 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1140 word
= operand_subword (x
, i
, 0, mode
);
1145 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1149 if (i
== size
/ UNITS_PER_WORD
)
1151 /* If we output at least one word and then could not finish,
1152 there is no valid way to continue. */
1163 /* Assemble the floating-point constant D into an object of size MODE. */
1166 assemble_real (d
, mode
)
1168 enum machine_mode mode
;
1170 jmp_buf output_constant_handler
;
1172 if (setjmp (output_constant_handler
))
1174 error ("floating point trap outputting a constant");
1175 #ifdef REAL_IS_NOT_DOUBLE
1176 bzero (&d
, sizeof d
);
1183 set_float_handler (output_constant_handler
);
1187 #ifdef ASM_OUTPUT_FLOAT
1189 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1193 #ifdef ASM_OUTPUT_DOUBLE
1195 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1199 #ifdef ASM_OUTPUT_LONG_DOUBLE
1201 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1209 set_float_handler (0);
1212 /* Here we combine duplicate floating constants to make
1213 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1215 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1216 They are chained through the CONST_DOUBLE_CHAIN.
1217 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1218 In that case, CONST_DOUBLE_MEM is either a MEM,
1219 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
1221 static rtx const_double_chain
;
1223 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1224 For an integer, I0 is the low-order word and I1 is the high-order word.
1225 For a real number, I0 is the word with the low address
1226 and I1 is the word with the high address. */
1229 immed_double_const (i0
, i1
, mode
)
1231 enum machine_mode mode
;
1234 int in_current_obstack
;
1236 if (GET_MODE_CLASS (mode
) == MODE_INT
)
1238 /* We clear out all bits that don't belong in MODE, unless they and our
1239 sign bit are all one. So we get either a reasonable negative value
1240 or a reasonable unsigned value for this mode. */
1241 int width
= GET_MODE_BITSIZE (mode
);
1242 if (width
< HOST_BITS_PER_INT
1243 && ((i0
& ((-1) << (width
- 1))) != ((-1) << (width
- 1))))
1244 i0
&= (1 << width
) - 1, i1
= 0;
1245 else if (width
== HOST_BITS_PER_INT
1246 && ! (i1
== ~0 && i0
< 0))
1248 else if (width
> 2 * HOST_BITS_PER_INT
)
1249 /* We cannot represent this value as a constant. */
1252 /* If MODE fits within HOST_BITS_PER_INT, always use a CONST_INT.
1254 ??? Strictly speaking, this is wrong if we create a CONST_INT
1255 for a large unsigned constant with the size of MODE being
1256 HOST_BITS_PER_INT and later try to interpret that constant in a wider
1257 mode. In that case we will mis-interpret it as a negative number.
1259 Unfortunately, the only alternative is to make a CONST_DOUBLE
1260 for any constant in any mode if it is an unsigned constant larger
1261 than the maximum signed integer in an int on the host. However,
1262 doing this will break everyone that always expects to see a CONST_INT
1263 for SImode and smaller.
1265 We have always been making CONST_INTs in this case, so nothing new
1268 if (width
<= HOST_BITS_PER_INT
)
1269 i1
= (i0
< 0) ? ~0 : 0;
1271 /* If this integer fits in one word, return a CONST_INT. */
1272 if ((i1
== 0 && i0
>= 0)
1273 || (i1
== ~0 && i0
< 0))
1274 return gen_rtx (CONST_INT
, VOIDmode
, i0
);
1276 /* We use VOIDmode for integers. */
1280 /* Search the chain for an existing CONST_DOUBLE with the right value.
1281 If one is found, return it. */
1283 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1284 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
1285 && GET_MODE (r
) == mode
)
1288 /* No; make a new one and add it to the chain.
1290 We may be called by an optimizer which may be discarding any memory
1291 allocated during its processing (such as combine and loop). However,
1292 we will be leaving this constant on the chain, so we cannot tolerate
1293 freed memory. So switch to saveable_obstack for this allocation
1294 and then switch back if we were in current_obstack. */
1296 in_current_obstack
= rtl_in_saveable_obstack ();
1297 r
= gen_rtx (CONST_DOUBLE
, mode
, 0, i0
, i1
);
1298 if (in_current_obstack
)
1299 rtl_in_current_obstack ();
1301 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1302 const_double_chain
= r
;
1304 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1305 Actual use of mem-slot is only through force_const_mem. */
1307 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1312 /* Return a CONST_DOUBLE for a specified `double' value
1313 and machine mode. */
1316 immed_real_const_1 (d
, mode
)
1318 enum machine_mode mode
;
1320 union real_extract u
;
1322 int in_current_obstack
;
1324 /* Get the desired `double' value as a sequence of ints
1325 since that is how they are stored in a CONST_DOUBLE. */
1329 /* Detect special cases. */
1331 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1332 if (!bcmp (&dconst0
, &d
, sizeof d
))
1333 return CONST0_RTX (mode
);
1334 else if (REAL_VALUES_EQUAL (dconst1
, d
))
1335 return CONST1_RTX (mode
);
1337 if (sizeof u
== 2 * sizeof (int))
1338 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
1340 /* The rest of this function handles the case where
1341 a float value requires more than 2 ints of space.
1342 It will be deleted as dead code on machines that don't need it. */
1344 /* Search the chain for an existing CONST_DOUBLE with the right value.
1345 If one is found, return it. */
1347 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1348 if (! bcmp (&CONST_DOUBLE_LOW (r
), &u
, sizeof u
)
1349 && GET_MODE (r
) == mode
)
1352 /* No; make a new one and add it to the chain.
1354 We may be called by an optimizer which may be discarding any memory
1355 allocated during its processing (such as combine and loop). However,
1356 we will be leaving this constant on the chain, so we cannot tolerate
1357 freed memory. So switch to saveable_obstack for this allocation
1358 and then switch back if we were in current_obstack. */
1360 in_current_obstack
= rtl_in_saveable_obstack ();
1361 r
= rtx_alloc (CONST_DOUBLE
);
1363 bcopy (&u
, &CONST_DOUBLE_LOW (r
), sizeof u
);
1364 if (in_current_obstack
)
1365 rtl_in_current_obstack ();
1367 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1368 const_double_chain
= r
;
1370 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1371 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1372 is only through force_const_mem. */
1374 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1379 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1380 which must be a REAL_CST tree node. */
1383 immed_real_const (exp
)
1386 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
1389 /* At the end of a function, forget the memory-constants
1390 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1391 Also clear out real_constant_chain and clear out all the chain-pointers. */
1394 clear_const_double_mem ()
1396 register rtx r
, next
;
1398 for (r
= const_double_chain
; r
; r
= next
)
1400 next
= CONST_DOUBLE_CHAIN (r
);
1401 CONST_DOUBLE_CHAIN (r
) = 0;
1402 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
1404 const_double_chain
= 0;
1407 /* Given an expression EXP with a constant value,
1408 reduce it to the sum of an assembler symbol and an integer.
1409 Store them both in the structure *VALUE.
1410 Abort if EXP does not reduce. */
1419 decode_addr_const (exp
, value
)
1421 struct addr_const
*value
;
1423 register tree target
= TREE_OPERAND (exp
, 0);
1424 register int offset
= 0;
1429 if (TREE_CODE (target
) == COMPONENT_REF
1430 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
1433 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
1434 target
= TREE_OPERAND (target
, 0);
1436 else if (TREE_CODE (target
) == ARRAY_REF
)
1438 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
1439 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
1441 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
1442 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
1444 target
= TREE_OPERAND (target
, 0);
1450 switch (TREE_CODE (target
))
1454 x
= DECL_RTL (target
);
1458 x
= gen_rtx (MEM
, FUNCTION_MODE
,
1459 gen_rtx (LABEL_REF
, VOIDmode
,
1460 label_rtx (TREE_OPERAND (exp
, 0))));
1467 x
= TREE_CST_RTL (target
);
1474 if (GET_CODE (x
) != MEM
)
1479 value
->offset
= offset
;
1482 /* Uniquize all constants that appear in memory.
1483 Each constant in memory thus far output is recorded
1484 in `const_hash_table' with a `struct constant_descriptor'
1485 that contains a polish representation of the value of
1488 We cannot store the trees in the hash table
1489 because the trees may be temporary. */
1491 struct constant_descriptor
1493 struct constant_descriptor
*next
;
1499 #define MAX_HASH_TABLE 1009
1500 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
1502 /* Compute a hash code for a constant expression. */
1509 register int len
, hi
, i
;
1510 register enum tree_code code
= TREE_CODE (exp
);
1512 if (code
== INTEGER_CST
)
1514 p
= (char *) &TREE_INT_CST_LOW (exp
);
1515 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1517 else if (code
== REAL_CST
)
1519 p
= (char *) &TREE_REAL_CST (exp
);
1520 len
= sizeof TREE_REAL_CST (exp
);
1522 else if (code
== STRING_CST
)
1523 p
= TREE_STRING_POINTER (exp
), len
= TREE_STRING_LENGTH (exp
);
1524 else if (code
== COMPLEX_CST
)
1525 return const_hash (TREE_REALPART (exp
)) * 5
1526 + const_hash (TREE_IMAGPART (exp
));
1527 else if (code
== CONSTRUCTOR
)
1531 /* For record type, include the type in the hashing.
1532 We do not do so for array types
1533 because (1) the sizes of the elements are sufficient
1534 and (2) distinct array types can have the same constructor.
1535 Instead, we include the array size because the constructor could
1537 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1538 hi
= ((int) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
1540 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
1541 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
1543 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1544 hi
= (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
1548 else if (code
== ADDR_EXPR
)
1550 struct addr_const value
;
1551 decode_addr_const (exp
, &value
);
1552 if (GET_CODE (value
.base
) == SYMBOL_REF
)
1554 /* Don't hash the address of the SYMBOL_REF;
1555 only use the offset and the symbol name. */
1557 p
= XSTR (value
.base
, 0);
1558 for (i
= 0; p
[i
] != 0; i
++)
1559 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
1561 else if (GET_CODE (value
.base
) == LABEL_REF
)
1562 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
1564 hi
&= (1 << HASHBITS
) - 1;
1565 hi
%= MAX_HASH_TABLE
;
1568 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1569 return const_hash (TREE_OPERAND (exp
, 0)) * 9
1570 + const_hash (TREE_OPERAND (exp
, 1));
1571 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1572 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
1574 /* Compute hashing function */
1576 for (i
= 0; i
< len
; i
++)
1577 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
1579 hi
&= (1 << HASHBITS
) - 1;
1580 hi
%= MAX_HASH_TABLE
;
1584 /* Compare a constant expression EXP with a constant-descriptor DESC.
1585 Return 1 if DESC describes a constant with the same value as EXP. */
1588 compare_constant (exp
, desc
)
1590 struct constant_descriptor
*desc
;
1592 return 0 != compare_constant_1 (exp
, desc
->contents
);
1595 /* Compare constant expression EXP with a substring P of a constant descriptor.
1596 If they match, return a pointer to the end of the substring matched.
1597 If they do not match, return 0.
1599 Since descriptors are written in polish prefix notation,
1600 this function can be used recursively to test one operand of EXP
1601 against a subdescriptor, and if it succeeds it returns the
1602 address of the subdescriptor for the next operand. */
1605 compare_constant_1 (exp
, p
)
1609 register char *strp
;
1611 register enum tree_code code
= TREE_CODE (exp
);
1613 if (code
!= (enum tree_code
) *p
++)
1616 if (code
== INTEGER_CST
)
1618 /* Integer constants are the same only if the same width of type. */
1619 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
1621 strp
= (char *) &TREE_INT_CST_LOW (exp
);
1622 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1624 else if (code
== REAL_CST
)
1626 /* Real constants are the same only if the same width of type. */
1627 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
1629 strp
= (char *) &TREE_REAL_CST (exp
);
1630 len
= sizeof TREE_REAL_CST (exp
);
1632 else if (code
== STRING_CST
)
1634 if (flag_writable_strings
)
1636 strp
= TREE_STRING_POINTER (exp
);
1637 len
= TREE_STRING_LENGTH (exp
);
1638 if (bcmp (&TREE_STRING_LENGTH (exp
), p
,
1639 sizeof TREE_STRING_LENGTH (exp
)))
1641 p
+= sizeof TREE_STRING_LENGTH (exp
);
1643 else if (code
== COMPLEX_CST
)
1645 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
1646 if (p
== 0) return 0;
1647 p
= compare_constant_1 (TREE_IMAGPART (exp
), p
);
1650 else if (code
== CONSTRUCTOR
)
1653 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
1656 if (bcmp (&length
, p
, sizeof length
))
1660 /* For record constructors, insist that the types match.
1661 For arrays, just verify both constructors are for arrays. */
1662 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1663 type
= TREE_TYPE (exp
);
1666 if (bcmp (&type
, p
, sizeof type
))
1670 /* For arrays, insist that the size in bytes match. */
1671 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1673 int size
= int_size_in_bytes (TREE_TYPE (exp
));
1674 if (bcmp (&size
, p
, sizeof size
))
1679 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1680 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
1684 else if (code
== ADDR_EXPR
)
1686 struct addr_const value
;
1687 decode_addr_const (exp
, &value
);
1688 strp
= (char *) &value
.offset
;
1689 len
= sizeof value
.offset
;
1690 /* Compare the offset. */
1692 if (*p
++ != *strp
++)
1694 /* Compare symbol name. */
1695 strp
= XSTR (value
.base
, 0);
1696 len
= strlen (strp
) + 1;
1698 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1700 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
1701 if (p
== 0) return 0;
1702 p
= compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
1705 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1707 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
1711 /* Compare constant contents. */
1713 if (*p
++ != *strp
++)
1719 /* Construct a constant descriptor for the expression EXP.
1720 It is up to the caller to enter the descriptor in the hash table. */
1722 static struct constant_descriptor
*
1723 record_constant (exp
)
1726 struct constant_descriptor
*ptr
= 0;
1729 obstack_grow (&permanent_obstack
, &ptr
, sizeof ptr
);
1730 obstack_grow (&permanent_obstack
, &buf
, sizeof buf
);
1731 record_constant_1 (exp
);
1732 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
1735 /* Add a description of constant expression EXP
1736 to the object growing in `permanent_obstack'.
1737 No need to return its address; the caller will get that
1738 from the obstack when the object is complete. */
1741 record_constant_1 (exp
)
1744 register char *strp
;
1746 register enum tree_code code
= TREE_CODE (exp
);
1748 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
1750 if (code
== INTEGER_CST
)
1752 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
1753 strp
= (char *) &TREE_INT_CST_LOW (exp
);
1754 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1756 else if (code
== REAL_CST
)
1758 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
1759 strp
= (char *) &TREE_REAL_CST (exp
);
1760 len
= sizeof TREE_REAL_CST (exp
);
1762 else if (code
== STRING_CST
)
1764 if (flag_writable_strings
)
1766 strp
= TREE_STRING_POINTER (exp
);
1767 len
= TREE_STRING_LENGTH (exp
);
1768 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
1769 sizeof TREE_STRING_LENGTH (exp
));
1771 else if (code
== COMPLEX_CST
)
1773 record_constant_1 (TREE_REALPART (exp
));
1774 record_constant_1 (TREE_IMAGPART (exp
));
1777 else if (code
== CONSTRUCTOR
)
1780 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
1783 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
1785 /* For record constructors, insist that the types match.
1786 For arrays, just verify both constructors are for arrays. */
1787 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1788 type
= TREE_TYPE (exp
);
1791 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
1793 /* For arrays, insist that the size in bytes match. */
1794 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1796 int size
= int_size_in_bytes (TREE_TYPE (exp
));
1797 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
1800 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1801 record_constant_1 (TREE_VALUE (link
));
1804 else if (code
== ADDR_EXPR
)
1806 struct addr_const value
;
1807 decode_addr_const (exp
, &value
);
1808 /* Record the offset. */
1809 obstack_grow (&permanent_obstack
,
1810 (char *) &value
.offset
, sizeof value
.offset
);
1811 /* Record the symbol name. */
1812 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
1813 strlen (XSTR (value
.base
, 0)) + 1);
1816 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1818 record_constant_1 (TREE_OPERAND (exp
, 0));
1819 record_constant_1 (TREE_OPERAND (exp
, 1));
1822 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1824 record_constant_1 (TREE_OPERAND (exp
, 0));
1828 /* Record constant contents. */
1829 obstack_grow (&permanent_obstack
, strp
, len
);
1832 /* Return an rtx representing a reference to constant data in memory
1833 for the constant expression EXP.
1834 If assembler code for such a constant has already been output,
1835 return an rtx to refer to it.
1836 Otherwise, output such a constant in memory and generate
1837 an rtx for it. The TREE_CST_RTL of EXP is set up to point to that rtx.
1838 The const_hash_table records which constants already have label strings. */
1841 output_constant_def (exp
)
1844 register int hash
, align
;
1845 register struct constant_descriptor
*desc
;
1851 if (TREE_CODE (exp
) == INTEGER_CST
)
1852 abort (); /* No TREE_CST_RTL slot in these. */
1854 if (TREE_CST_RTL (exp
))
1855 return TREE_CST_RTL (exp
);
1857 /* Make sure any other constants whose addresses appear in EXP
1858 are assigned label numbers. */
1860 reloc
= output_addressed_constants (exp
);
1862 /* Compute hash code of EXP. Search the descriptors for that hash code
1863 to see if any of them describes EXP. If yes, the descriptor records
1864 the label number already assigned. */
1866 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
1868 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
1869 if (compare_constant (exp
, desc
))
1871 found
= desc
->label
;
1877 /* No constant equal to EXP is known to have been output.
1878 Make a constant descriptor to enter EXP in the hash table.
1879 Assign the label number and record it in the descriptor for
1880 future calls to this function to find. */
1882 /* Create a string containing the label name, in LABEL. */
1883 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
1885 desc
= record_constant (exp
);
1886 desc
->next
= const_hash_table
[hash
];
1888 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1889 const_hash_table
[hash
] = desc
;
1892 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
1894 push_obstacks_nochange ();
1895 if (TREE_PERMANENT (exp
))
1896 end_temporary_allocation ();
1898 def
= gen_rtx (SYMBOL_REF
, Pmode
, desc
->label
);
1901 = gen_rtx (MEM
, TYPE_MODE (TREE_TYPE (exp
)), def
);
1902 RTX_UNCHANGING_P (TREE_CST_RTL (exp
)) = 1;
1903 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
1904 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1905 MEM_IN_STRUCT_P (TREE_CST_RTL (exp
)) = 1;
1909 /* Optionally set flags or add text to the name to record information
1910 such as that it is a function name. If the name is changed, the macro
1911 ASM_OUTPUT_LABELREF will have to know how to strip this information.
1912 And if it finds a * at the beginning after doing so, it must handle
1914 #ifdef ENCODE_SECTION_INFO
1915 ENCODE_SECTION_INFO (exp
);
1920 /* Now output assembler code to define that label
1921 and follow it with the data of EXP. */
1923 /* First switch to text section, except for writable strings. */
1924 #ifdef SELECT_SECTION
1925 SELECT_SECTION (exp
, reloc
);
1927 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
1928 || (flag_pic
&& reloc
))
1931 readonly_data_section ();
1934 /* Align the location counter as required by EXP's data type. */
1935 align
= TYPE_ALIGN (TREE_TYPE (exp
));
1936 #ifdef CONSTANT_ALIGNMENT
1937 align
= CONSTANT_ALIGNMENT (exp
, align
);
1940 if (align
> BITS_PER_UNIT
)
1941 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1943 /* Output the label itself. */
1944 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", const_labelno
);
1946 /* Output the value of EXP. */
1947 output_constant (exp
,
1948 (TREE_CODE (exp
) == STRING_CST
1949 ? TREE_STRING_LENGTH (exp
)
1950 : int_size_in_bytes (TREE_TYPE (exp
))));
1955 return TREE_CST_RTL (exp
);
1958 /* Similar hash facility for making memory-constants
1959 from constant rtl-expressions. It is used on RISC machines
1960 where immediate integer arguments and constant addresses are restricted
1961 so that such constants must be stored in memory.
1963 This pool of constants is reinitialized for each function
1964 so each function gets its own constants-pool that comes right before it.
1966 All structures allocated here are discarded when functions are saved for
1967 inlining, so they do not need to be allocated permanently. */
1969 #define MAX_RTX_HASH_TABLE 61
1970 static struct constant_descriptor
*const_rtx_hash_table
[MAX_RTX_HASH_TABLE
];
1972 /* Structure to represent sufficient information about a constant so that
1973 it can be output when the constant pool is output, so that function
1974 integration can be done, and to simplify handling on machines that reference
1975 constant pool as base+displacement. */
1977 struct pool_constant
1979 struct constant_descriptor
*desc
;
1980 struct pool_constant
*next
;
1981 enum machine_mode mode
;
1988 /* Pointers to first and last constant in pool. */
1990 static struct pool_constant
*first_pool
, *last_pool
;
1992 /* Current offset in constant pool (does not include any machine-specific
1995 static int pool_offset
;
1997 /* Structure used to maintain hash table mapping symbols used to their
1998 corresponding constants. */
2003 struct pool_constant
*pool
;
2004 struct pool_sym
*next
;
2007 static struct pool_sym
*const_rtx_sym_hash_table
[MAX_RTX_HASH_TABLE
];
2009 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2010 The argument is XSTR (... , 0) */
2012 #define SYMHASH(LABEL) \
2013 ((((int) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2015 /* Initialize constant pool hashing for next function. */
2018 init_const_rtx_hash_table ()
2020 bzero (const_rtx_hash_table
, sizeof const_rtx_hash_table
);
2021 bzero (const_rtx_sym_hash_table
, sizeof const_rtx_sym_hash_table
);
2023 first_pool
= last_pool
= 0;
2027 enum kind
{ RTX_DOUBLE
, RTX_INT
};
2031 #ifdef ONLY_INT_FIELDS
2032 unsigned int kind
: 16;
2033 unsigned int mode
: 16;
2035 enum kind kind
: 16;
2036 enum machine_mode mode
: 16;
2039 union real_extract du
;
2040 struct addr_const addr
;
2044 /* Express an rtx for a constant integer (perhaps symbolic)
2045 as the sum of a symbol or label plus an explicit integer.
2046 They are stored into VALUE. */
2049 decode_rtx_const (mode
, x
, value
)
2050 enum machine_mode mode
;
2052 struct rtx_const
*value
;
2054 /* Clear the whole structure, including any gaps. */
2057 int *p
= (int *) value
;
2058 int *end
= (int *) (value
+ 1);
2063 value
->kind
= RTX_INT
; /* Most usual kind. */
2066 switch (GET_CODE (x
))
2069 value
->kind
= RTX_DOUBLE
;
2070 value
->mode
= GET_MODE (x
);
2071 bcopy (&CONST_DOUBLE_LOW (x
), &value
->un
.du
, sizeof value
->un
.du
);
2075 value
->un
.addr
.offset
= INTVAL (x
);
2080 value
->un
.addr
.base
= x
;
2085 if (GET_CODE (x
) == PLUS
)
2087 value
->un
.addr
.base
= XEXP (x
, 0);
2088 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
2090 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
2092 else if (GET_CODE (x
) == MINUS
)
2094 value
->un
.addr
.base
= XEXP (x
, 0);
2095 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
2097 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
2107 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
2108 switch (GET_CODE (value
->un
.addr
.base
))
2112 /* Use the string's address, not the SYMBOL_REF's address,
2113 for the sake of addresses of library routines.
2114 For a LABEL_REF, compare labels. */
2115 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
2119 /* Compute a hash code for a constant RTL expression. */
2122 const_hash_rtx (mode
, x
)
2123 enum machine_mode mode
;
2128 struct rtx_const value
;
2129 decode_rtx_const (mode
, x
, &value
);
2131 /* Compute hashing function */
2133 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
2134 hi
+= ((int *) &value
)[i
];
2136 hi
&= (1 << HASHBITS
) - 1;
2137 hi
%= MAX_RTX_HASH_TABLE
;
2141 /* Compare a constant rtl object X with a constant-descriptor DESC.
2142 Return 1 if DESC describes a constant with the same value as X. */
2145 compare_constant_rtx (mode
, x
, desc
)
2146 enum machine_mode mode
;
2148 struct constant_descriptor
*desc
;
2150 register int *p
= (int *) desc
->contents
;
2153 struct rtx_const value
;
2155 decode_rtx_const (mode
, x
, &value
);
2156 strp
= (int *) &value
;
2157 len
= sizeof value
/ sizeof (int);
2159 /* Compare constant contents. */
2161 if (*p
++ != *strp
++)
2167 /* Construct a constant descriptor for the rtl-expression X.
2168 It is up to the caller to enter the descriptor in the hash table. */
2170 static struct constant_descriptor
*
2171 record_constant_rtx (mode
, x
)
2172 enum machine_mode mode
;
2175 struct constant_descriptor
*ptr
;
2177 struct rtx_const value
;
2179 decode_rtx_const (mode
, x
, &value
);
2181 obstack_grow (current_obstack
, &ptr
, sizeof ptr
);
2182 obstack_grow (current_obstack
, &label
, sizeof label
);
2184 /* Record constant contents. */
2185 obstack_grow (current_obstack
, &value
, sizeof value
);
2187 return (struct constant_descriptor
*) obstack_finish (current_obstack
);
2190 /* Given a constant rtx X, make (or find) a memory constant for its value
2191 and return a MEM rtx to refer to it in memory. */
2194 force_const_mem (mode
, x
)
2195 enum machine_mode mode
;
2199 register struct constant_descriptor
*desc
;
2204 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2205 (this will always be true for floating CONST_DOUBLEs that have been
2206 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2207 use the previous copy. Otherwise, make a new one. Note that in
2208 the unlikely event that this same CONST_DOUBLE is used in two different
2209 modes in an alternating fashion, we will allocate a lot of different
2210 memory locations, but this should be extremely rare. */
2212 if (GET_CODE (x
) == CONST_DOUBLE
2213 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
2214 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
2215 return CONST_DOUBLE_MEM (x
);
2217 /* Compute hash code of X. Search the descriptors for that hash code
2218 to see if any of them describes X. If yes, the descriptor records
2219 the label number already assigned. */
2221 hash
= const_hash_rtx (mode
, x
);
2223 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
2224 if (compare_constant_rtx (mode
, x
, desc
))
2226 found
= desc
->label
;
2232 register struct pool_constant
*pool
;
2233 register struct pool_sym
*sym
;
2236 /* No constant equal to X is known to have been output.
2237 Make a constant descriptor to enter X in the hash table.
2238 Assign the label number and record it in the descriptor for
2239 future calls to this function to find. */
2241 desc
= record_constant_rtx (mode
, x
);
2242 desc
->next
= const_rtx_hash_table
[hash
];
2243 const_rtx_hash_table
[hash
] = desc
;
2245 /* Align the location counter as required by EXP's data type. */
2246 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
2247 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2248 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
2250 pool_offset
+= align
- 1;
2251 pool_offset
&= ~ (align
- 1);
2253 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2255 pool
= (struct pool_constant
*) oballoc (sizeof (struct pool_constant
));
2259 pool
->labelno
= const_labelno
;
2260 pool
->align
= align
;
2261 pool
->offset
= pool_offset
;
2267 last_pool
->next
= pool
;
2270 pool_offset
+= GET_MODE_SIZE (mode
);
2272 /* Create a string containing the label name, in LABEL. */
2273 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2278 = (char *) obstack_copy0 (saveable_obstack
, label
, strlen (label
));
2280 /* Add label to symbol hash table. */
2281 hash
= SYMHASH (found
);
2282 sym
= (struct pool_sym
*) oballoc (sizeof (struct pool_sym
));
2285 sym
->next
= const_rtx_sym_hash_table
[hash
];
2286 const_rtx_sym_hash_table
[hash
] = sym
;
2289 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2291 def
= gen_rtx (MEM
, mode
, gen_rtx (SYMBOL_REF
, Pmode
, found
));
2293 RTX_UNCHANGING_P (def
) = 1;
2294 /* Mark the symbol_ref as belonging to this constants pool. */
2295 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
2296 current_function_uses_const_pool
= 1;
2298 if (GET_CODE (x
) == CONST_DOUBLE
)
2300 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
2302 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
2303 const_double_chain
= x
;
2305 CONST_DOUBLE_MEM (x
) = def
;
2311 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2312 the corresponding pool_constant structure. */
2314 static struct pool_constant
*
2315 find_pool_constant (addr
)
2318 struct pool_sym
*sym
;
2319 char *label
= XSTR (addr
, 0);
2321 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
2322 if (sym
->label
== label
)
2328 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2331 get_pool_constant (addr
)
2334 return (find_pool_constant (addr
))->constant
;
2337 /* Similar, return the mode. */
2340 get_pool_mode (addr
)
2343 return (find_pool_constant (addr
))->mode
;
2346 /* Similar, return the offset in the constant pool. */
2349 get_pool_offset (addr
)
2352 return (find_pool_constant (addr
))->offset
;
2355 /* Return the size of the constant pool. */
2363 /* Write all the constants in the constant pool. */
2366 output_constant_pool (fnname
, fndecl
)
2370 struct pool_constant
*pool
;
2372 union real_extract u
;
2374 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2375 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
2378 for (pool
= first_pool
; pool
; pool
= pool
->next
)
2382 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2383 whose CODE_LABEL has been deleted. This can occur if a jump table
2384 is eliminated by optimization. If so, write a constant of zero
2386 if ((GET_CODE (x
) == LABEL_REF
&& INSN_DELETED_P (XEXP (x
, 0)))
2387 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
2388 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
2389 && INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))))
2392 /* First switch to correct section. */
2393 #ifdef SELECT_RTX_SECTION
2394 SELECT_RTX_SECTION (pool
->mode
, x
);
2396 readonly_data_section ();
2399 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2400 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
2401 pool
->align
, pool
->labelno
, done
);
2404 if (pool
->align
> 1)
2405 ASM_OUTPUT_ALIGN (asm_out_file
, exact_log2 (pool
->align
));
2407 /* Output the label. */
2408 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
2410 /* Output the value of the constant itself. */
2411 switch (GET_MODE_CLASS (pool
->mode
))
2414 if (GET_CODE (x
) != CONST_DOUBLE
)
2417 bcopy (&CONST_DOUBLE_LOW (x
), &u
, sizeof u
);
2418 assemble_real (u
.d
, pool
->mode
);
2422 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
2432 /* Done with this pool. */
2433 first_pool
= last_pool
= 0;
2436 /* Find all the constants whose addresses are referenced inside of EXP,
2437 and make sure assembler code with a label has been output for each one.
2438 Indicate whether an ADDR_EXPR has been encountered. */
2441 output_addressed_constants (exp
)
2446 switch (TREE_CODE (exp
))
2450 register tree constant
= TREE_OPERAND (exp
, 0);
2452 while (TREE_CODE (constant
) == COMPONENT_REF
)
2454 constant
= TREE_OPERAND (constant
, 0);
2457 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
2458 || TREE_CODE (constant
) == CONSTRUCTOR
)
2459 /* No need to do anything here
2460 for addresses of variables or functions. */
2461 output_constant_def (constant
);
2468 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
2469 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
2474 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
2480 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2481 if (TREE_VALUE (link
) != 0)
2482 reloc
|= output_addressed_constants (TREE_VALUE (link
));
2492 /* Output assembler code for constant EXP to FILE, with no label.
2493 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2494 Assumes output_addressed_constants has been done on EXP already.
2496 Generate exactly SIZE bytes of assembler data, padding at the end
2497 with zeros if necessary. SIZE must always be specified.
2499 SIZE is important for structure constructors,
2500 since trailing members may have been omitted from the constructor.
2501 It is also important for initialization of arrays from string constants
2502 since the full length of the string constant might not be wanted.
2503 It is also needed for initialization of unions, where the initializer's
2504 type is just one member, and that may not be as long as the union.
2506 There a case in which we would fail to output exactly SIZE bytes:
2507 for a structure constructor that wants to produce more than SIZE bytes.
2508 But such constructors will never be generated for any possible input. */
2511 output_constant (exp
, size
)
2515 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
2521 /* Allow a constructor with no elements for any data type.
2522 This means to fill the space with zeros. */
2523 if (TREE_CODE (exp
) == CONSTRUCTOR
2524 && TREE_OPERAND (exp
, 1) == 0)
2526 assemble_zeros (size
);
2530 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2531 That way we get the constant (we hope) inside it. */
2532 if (TREE_CODE (exp
) == NOP_EXPR
2533 && TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0)))
2534 exp
= TREE_OPERAND (exp
, 0);
2541 case REFERENCE_TYPE
:
2542 /* ??? What about (int)((float)(int)&foo + 4) */
2543 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
2544 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2545 exp
= TREE_OPERAND (exp
, 0);
2547 if (! assemble_integer (expand_expr (exp
, 0, VOIDmode
,
2548 EXPAND_INITIALIZER
),
2550 error ("initializer for integer value is too complicated");
2555 if (TREE_CODE (exp
) != REAL_CST
)
2556 error ("initializer for floating value is not a floating constant");
2558 assemble_real (TREE_REAL_CST (exp
),
2559 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
2564 output_constant (TREE_REALPART (exp
), size
/ 2);
2565 output_constant (TREE_IMAGPART (exp
), size
/ 2);
2566 size
-= (size
/ 2) * 2;
2570 if (TREE_CODE (exp
) == CONSTRUCTOR
)
2572 output_constructor (exp
, size
);
2575 else if (TREE_CODE (exp
) == STRING_CST
)
2579 if (size
> TREE_STRING_LENGTH (exp
))
2581 excess
= size
- TREE_STRING_LENGTH (exp
);
2582 size
= TREE_STRING_LENGTH (exp
);
2585 assemble_string (TREE_STRING_POINTER (exp
), size
);
2594 if (TREE_CODE (exp
) == CONSTRUCTOR
)
2595 output_constructor (exp
, size
);
2602 assemble_zeros (size
);
2605 /* Subroutine of output_constant, used for CONSTRUCTORs
2606 (aggregate constants).
2607 Generate at least SIZE bytes, padding if necessary. */
2610 output_constructor (exp
, size
)
2614 register tree link
, field
= 0;
2615 /* Number of bytes output or skipped so far.
2616 In other words, current position within the constructor. */
2617 int total_bytes
= 0;
2618 /* Non-zero means BYTE contains part of a byte, to be output. */
2619 int byte_buffer_in_use
= 0;
2622 if (HOST_BITS_PER_INT
< BITS_PER_UNIT
)
2625 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2626 field
= TYPE_FIELDS (TREE_TYPE (exp
));
2628 /* As LINK goes through the elements of the constant,
2629 FIELD goes through the structure fields, if the constant is a structure.
2630 if the constant is a union, then we override this,
2631 by getting the field from the TREE_LIST element.
2632 But the constant could also be an array. Then FIELD is zero. */
2633 for (link
= CONSTRUCTOR_ELTS (exp
);
2635 link
= TREE_CHAIN (link
),
2636 field
= field
? TREE_CHAIN (field
) : 0)
2638 tree val
= TREE_VALUE (link
);
2639 /* the element in a union constructor specifies the proper field. */
2640 if (TREE_PURPOSE (link
) != 0)
2641 field
= TREE_PURPOSE (link
);
2643 /* Eliminate the marker that makes a cast not be an lvalue. */
2644 if (val
!= 0 && TREE_CODE (val
) == NON_LVALUE_EXPR
)
2645 val
= TREE_OPERAND (val
, 0);
2647 if (field
== 0 || !DECL_BIT_FIELD (field
))
2649 register int fieldsize
;
2650 /* Since this structure is static,
2651 we know the positions are constant. */
2652 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
2656 /* An element that is not a bit-field.
2657 Output any buffered-up bit-fields preceding it. */
2658 if (byte_buffer_in_use
)
2660 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2662 byte_buffer_in_use
= 0;
2665 /* Advance to offset of this element.
2666 Note no alignment needed in an array, since that is guaranteed
2667 if each element has the proper size. */
2668 if (field
!= 0 && bitpos
!= total_bytes
)
2670 assemble_zeros (bitpos
- total_bytes
);
2671 total_bytes
= bitpos
;
2674 /* Determine size this element should occupy. */
2677 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
2679 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
2681 /* This avoids overflow trouble. */
2682 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
2684 size_int (BITS_PER_UNIT
));
2685 fieldsize
= TREE_INT_CST_LOW (size_tree
);
2689 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
2690 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
2694 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
2696 /* Output the element's initial value. */
2698 assemble_zeros (fieldsize
);
2700 output_constant (val
, fieldsize
);
2702 /* Count its size. */
2703 total_bytes
+= fieldsize
;
2705 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
2706 error ("invalid initial value for member `%s'",
2707 IDENTIFIER_POINTER (DECL_NAME (field
)));
2710 /* Element that is a bit-field. */
2712 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
2714 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
2717 val
= integer_zero_node
;
2719 /* If this field does not start in this (or, next) byte,
2721 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
2723 /* Output remnant of any bit field in previous bytes. */
2724 if (byte_buffer_in_use
)
2726 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2728 byte_buffer_in_use
= 0;
2731 /* If still not at proper byte, advance to there. */
2732 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
2734 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
2735 total_bytes
= next_offset
/ BITS_PER_UNIT
;
2739 if (! byte_buffer_in_use
)
2742 /* We must split the element into pieces that fall within
2743 separate bytes, and combine each byte with previous or
2744 following bit-fields. */
2746 /* next_offset is the offset n fbits from the beginning of
2747 the structure to the next bit of this element to be processed.
2748 end_offset is the offset of the first bit past the end of
2750 while (next_offset
< end_offset
)
2754 int next_byte
= next_offset
/ BITS_PER_UNIT
;
2755 int next_bit
= next_offset
% BITS_PER_UNIT
;
2757 /* Advance from byte to byte
2758 within this element when necessary. */
2759 while (next_byte
!= total_bytes
)
2761 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2766 /* Number of bits we can process at once
2767 (all part of the same byte). */
2768 this_time
= MIN (end_offset
- next_offset
,
2769 BITS_PER_UNIT
- next_bit
);
2770 #if BYTES_BIG_ENDIAN
2771 /* On big-endian machine, take the most significant bits
2772 first (of the bits that are significant)
2773 and put them into bytes from the most significant end. */
2774 shift
= end_offset
- next_offset
- this_time
;
2775 /* Don't try to take a bunch of bits that cross
2776 the word boundary in the INTEGER_CST. */
2777 if (shift
< HOST_BITS_PER_INT
2778 && shift
+ this_time
> HOST_BITS_PER_INT
)
2780 this_time
-= (HOST_BITS_PER_INT
- shift
);
2781 shift
= HOST_BITS_PER_INT
;
2784 /* Now get the bits from the appropriate constant word. */
2785 if (shift
< HOST_BITS_PER_INT
)
2787 value
= TREE_INT_CST_LOW (val
);
2789 else if (shift
< 2 * HOST_BITS_PER_INT
)
2791 value
= TREE_INT_CST_HIGH (val
);
2792 shift
-= HOST_BITS_PER_INT
;
2796 byte
|= (((value
>> shift
) & ((1 << this_time
) - 1))
2797 << (BITS_PER_UNIT
- this_time
- next_bit
));
2799 /* On little-endian machines,
2800 take first the least significant bits of the value
2801 and pack them starting at the least significant
2802 bits of the bytes. */
2803 shift
= (next_offset
2804 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
2805 /* Don't try to take a bunch of bits that cross
2806 the word boundary in the INTEGER_CST. */
2807 if (shift
< HOST_BITS_PER_INT
2808 && shift
+ this_time
> HOST_BITS_PER_INT
)
2810 this_time
-= (HOST_BITS_PER_INT
- shift
);
2811 shift
= HOST_BITS_PER_INT
;
2814 /* Now get the bits from the appropriate constant word. */
2815 if (shift
< HOST_BITS_PER_INT
)
2816 value
= TREE_INT_CST_LOW (val
);
2817 else if (shift
< 2 * HOST_BITS_PER_INT
)
2819 value
= TREE_INT_CST_HIGH (val
);
2820 shift
-= HOST_BITS_PER_INT
;
2824 byte
|= ((value
>> shift
) & ((1 << this_time
) - 1)) << next_bit
;
2826 next_offset
+= this_time
;
2827 byte_buffer_in_use
= 1;
2831 if (byte_buffer_in_use
)
2833 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2836 if (total_bytes
< size
)
2837 assemble_zeros (size
- total_bytes
);