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"
41 #ifdef XCOFF_DEBUGGING_INFO
46 #define ASM_STABS_OP ".stabs"
49 /* File in which assembler code is being written. */
51 extern FILE *asm_out_file
;
53 /* The (assembler) name of the first globally-visible object output. */
54 char *first_global_object_name
;
56 extern struct obstack
*current_obstack
;
57 extern struct obstack
*saveable_obstack
;
58 extern struct obstack permanent_obstack
;
59 #define obstack_chunk_alloc xmalloc
60 extern int xmalloc ();
62 /* Number for making the label on the next
63 constant that is stored in memory. */
67 /* Number for making the label on the next
68 static variable internal to a function. */
72 /* Nonzero if at least one function definition has been seen. */
73 static int function_defined
;
75 extern FILE *asm_out_file
;
77 static char *compare_constant_1 ();
78 static void record_constant_1 ();
79 void output_constant_pool ();
80 void assemble_name ();
81 int output_addressed_constants ();
82 void output_constant ();
83 void output_constructor ();
87 static enum in_section
{no_section
, in_text
, in_data
, EXTRA_SECTIONS
} in_section
90 static enum in_section
{no_section
, in_text
, in_data
} in_section
94 /* Define functions like text_section for any extra sections. */
95 #ifdef EXTRA_SECTION_FUNCTIONS
96 EXTRA_SECTION_FUNCTIONS
99 /* Tell assembler to switch to text section. */
104 if (in_section
!= in_text
)
106 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
107 in_section
= in_text
;
111 /* Tell assembler to switch to read-only data section. This is normally
115 readonly_data_section ()
117 #ifdef READONLY_DATA_SECTION
118 READONLY_DATA_SECTION ();
124 /* Tell assembler to switch to data section. */
129 if (in_section
!= in_data
)
131 if (flag_shared_data
)
133 #ifdef SHARED_SECTION_ASM_OP
134 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
136 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
140 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
142 in_section
= in_data
;
146 /* Determine if we're in the text section. */
151 return in_section
== in_text
;
154 /* Create the rtl to represent a function, for a function definition.
155 DECL is a FUNCTION_DECL node which describes which function.
156 The rtl is stored into DECL. */
159 make_function_rtl (decl
)
162 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
164 /* Rename a nested function to avoid conflicts. */
165 if (decl_function_context (decl
) != 0
166 && DECL_INITIAL (decl
) != 0
167 && DECL_RTL (decl
) == 0)
171 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
172 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
173 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
177 if (DECL_RTL (decl
) == 0)
180 = gen_rtx (MEM
, DECL_MODE (decl
),
181 gen_rtx (SYMBOL_REF
, Pmode
, name
));
183 /* Optionally set flags or add text to the name to record information
184 such as that it is a function name. If the name is changed, the macro
185 ASM_OUTPUT_LABELREF will have to know how to strip this information.
186 And if it finds a * at the beginning after doing so, it must handle
188 #ifdef ENCODE_SECTION_INFO
189 ENCODE_SECTION_INFO (decl
);
193 /* Record at least one function has been defined. */
194 function_defined
= 1;
197 /* Given NAME, a putative register name, discard any customary prefixes. */
200 strip_reg_name (name
)
203 #ifdef REGISTER_PREFIX
204 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
205 name
+= strlen (REGISTER_PREFIX
);
207 if (name
[0] == '%' || name
[0] == '#')
212 /* Decode an `asm' spec for a declaration as a register name.
213 Return the register number, or -1 if nothing specified,
214 or -2 if the ASMSPEC is not `cc' and is recognized,
215 or -3 if ASMSPEC is `cc' and is not recognized.
216 Accept an exact spelling or a decimal number.
217 Prefixes such as % are optional. */
220 decode_reg_name (asmspec
)
227 /* Get rid of confusing prefixes. */
228 asmspec
= strip_reg_name (asmspec
);
230 /* Allow a decimal number as a "register name". */
231 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
232 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
234 if (asmspec
[0] != 0 && i
< 0)
237 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
243 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
245 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
248 #ifdef ADDITIONAL_REGISTER_NAMES
250 static struct { char *name
; int number
; } table
[]
251 = ADDITIONAL_REGISTER_NAMES
;
253 for (i
= 0; i
< sizeof (table
) / sizeof (table
[0]); i
++)
254 if (! strcmp (asmspec
, table
[i
].name
))
255 return table
[i
].number
;
257 #endif /* ADDITIONAL_REGISTER_NAMES */
259 if (!strcmp (asmspec
, "cc"))
268 /* Create the DECL_RTL for a declaration for a static or external variable
269 or static or external function.
270 ASMSPEC, if not 0, is the string which the user specified
271 as the assembler symbol name.
272 TOP_LEVEL is nonzero if this is a file-scope variable.
274 This is never called for PARM_DECL nodes. */
277 make_decl_rtl (decl
, asmspec
, top_level
)
283 int reg_number
= decode_reg_name (asmspec
);
285 if (DECL_ASSEMBLER_NAME (decl
) != NULL_TREE
)
286 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
288 if (reg_number
== -2)
290 /* ASMSPEC is given, and not the name of a register. */
291 name
= (char *) obstack_alloc (saveable_obstack
,
292 strlen (asmspec
) + 2);
294 strcpy (&name
[1], asmspec
);
297 /* For a duplicate declaration, we can be called twice on the
298 same DECL node. Don't alter the RTL already made
299 unless the old mode is wrong (which can happen when
300 the previous rtl was made when the type was incomplete). */
301 if (DECL_RTL (decl
) == 0
302 || GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
306 /* First detect errors in declaring global registers. */
307 if (TREE_REGDECL (decl
) && reg_number
== -1)
308 error_with_decl (decl
,
309 "register name not specified for `%s'");
310 else if (TREE_REGDECL (decl
) && reg_number
< 0)
311 error_with_decl (decl
,
312 "invalid register name for `%s'");
313 else if ((reg_number
>= 0 || reg_number
== -3) && ! TREE_REGDECL (decl
))
314 error_with_decl (decl
,
315 "register name given for non-register variable `%s'");
316 else if (TREE_REGDECL (decl
) && TREE_CODE (decl
) == FUNCTION_DECL
)
317 error ("function declared `register'");
318 else if (TREE_REGDECL (decl
) && TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
319 error_with_decl (decl
, "data type of `%s' isn't suitable for a register");
320 /* Now handle properly declared static register variables. */
321 else if (TREE_REGDECL (decl
))
324 #if 0 /* yylex should print the warning for this */
326 pedwarn ("ANSI C forbids global register variables");
328 if (DECL_INITIAL (decl
) != 0 && top_level
)
330 DECL_INITIAL (decl
) = 0;
331 error ("global register variable has initial value");
333 if (fixed_regs
[reg_number
] == 0
334 && function_defined
&& top_level
)
335 error ("global register variable follows a function definition");
336 if (TREE_THIS_VOLATILE (decl
))
337 warning ("volatile register variables don't work as you might wish");
338 DECL_RTL (decl
) = gen_rtx (REG
, DECL_MODE (decl
), reg_number
);
339 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
343 /* Make this register fixed, so not usable for anything else. */
344 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
346 global_regs
[reg_number
+ --nregs
] = 1;
351 /* Now handle ordinary static variables and functions (in memory).
352 Also handle vars declared register invalidly. */
353 if (DECL_RTL (decl
) == 0)
355 /* Can't use just the variable's own name for a variable
356 whose scope is less than the whole file.
357 Concatenate a distinguishing number. */
358 if (!top_level
&& !TREE_EXTERNAL (decl
) && asmspec
== 0)
362 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
363 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
367 DECL_RTL (decl
) = gen_rtx (MEM
, DECL_MODE (decl
),
368 gen_rtx (SYMBOL_REF
, Pmode
, name
));
369 if (TREE_THIS_VOLATILE (decl
))
370 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
371 if (TREE_READONLY (decl
))
372 RTX_UNCHANGING_P (DECL_RTL (decl
)) = 1;
373 MEM_IN_STRUCT_P (DECL_RTL (decl
))
374 = (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
375 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
376 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
);
378 /* Optionally set flags or add text to the name to record information
379 such as that it is a function name.
380 If the name is changed, the macro ASM_OUTPUT_LABELREF
381 will have to know how to strip this information.
382 And if it finds a * at the beginning after doing so,
383 it must handle that too. */
384 #ifdef ENCODE_SECTION_INFO
385 ENCODE_SECTION_INFO (decl
);
391 /* Output a string of literal assembler code
392 for an `asm' keyword used between functions. */
395 assemble_asm (string
)
400 if (TREE_CODE (string
) == ADDR_EXPR
)
401 string
= TREE_OPERAND (string
, 0);
403 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
406 /* Tiemann: please get rid of this conditional and put appropriate
407 definitions in each of the files that should have them.
408 The type of debugging format is not the right parameter to
409 control how some other aspect of assembler output is done. */
411 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
412 #ifndef ASM_OUTPUT_CONSTRUCTOR
413 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
415 #ifndef ASM_OUTPUT_DESTRUCTOR
416 #define ASM_OUTPUT_DESTRUCTOR(file, name)
420 /* Record an element in the table of global destructors.
421 How this is done depends on what sort of assembler and linker
424 NAME should be the name of a global function to be called
425 at exit time. This name is output using assemble_name. */
428 assemble_destructor (name
)
431 #ifdef ASM_OUTPUT_DESTRUCTOR
432 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
436 /* Now tell GNU LD that this is part of the static destructor set. */
437 /* This code works for any machine provided you use GNU as/ld. */
438 fprintf (asm_out_file
, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
439 assemble_name (asm_out_file
, name
);
440 fputc ('\n', asm_out_file
);
445 /* Likewise for global constructors. */
448 assemble_constructor (name
)
451 #ifdef ASM_OUTPUT_CONSTRUCTOR
452 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
456 /* Now tell GNU LD that this is part of the static constructor set. */
457 /* This code works for any machine provided you use GNU as/ld. */
458 fprintf (asm_out_file
, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
459 assemble_name (asm_out_file
, name
);
460 fputc ('\n', asm_out_file
);
465 /* Likewise for entries we want to record for garbage collection.
466 Garbage collection is still under development. */
469 assemble_gc_entry (name
)
472 #ifdef ASM_OUTPUT_GC_ENTRY
473 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
477 /* Now tell GNU LD that this is part of the static constructor set. */
478 fprintf (asm_out_file
, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
479 assemble_name (asm_out_file
, name
);
480 fputc ('\n', asm_out_file
);
485 /* Output assembler code for the constant pool of a function and associated
486 with defining the name of the function. DECL describes the function.
487 NAME is the function's name. For the constant pool, we use the current
488 constant pool data. */
491 assemble_start_function (decl
, fnname
)
497 /* The following code does not need preprocessing in the assembler. */
501 output_constant_pool (fnname
, decl
);
506 /* Tell assembler to move to target machine's alignment for functions. */
507 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
509 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
511 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
512 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
515 #ifdef SDB_DEBUGGING_INFO
516 /* Output SDB definition of the function. */
517 if (write_symbols
== SDB_DEBUG
)
518 sdbout_mark_begin_function ();
521 #ifdef DBX_DEBUGGING_INFO
522 /* Output DBX definition of the function. */
523 if (write_symbols
== DBX_DEBUG
)
524 dbxout_begin_function (decl
);
527 /* Make function name accessible from other files, if appropriate. */
529 if (TREE_PUBLIC (decl
))
531 if (!first_global_object_name
)
532 first_global_object_name
= fnname
+ (fnname
[0] == '*');
533 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
536 /* Do any machine/system dependent processing of the function name */
537 #ifdef ASM_DECLARE_FUNCTION_NAME
538 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
540 /* Standard thing is just output label for the function. */
541 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
542 #endif /* ASM_DECLARE_FUNCTION_NAME */
545 /* Output assembler code associated with defining the size of the
546 function. DECL describes the function. NAME is the function's name. */
549 assemble_end_function (decl
, fnname
)
553 #ifdef ASM_DECLARE_FUNCTION_SIZE
554 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
558 /* Assemble code to leave SIZE bytes of zeros. */
561 assemble_zeros (size
)
564 #ifdef ASM_NO_SKIP_IN_TEXT
565 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
566 so we must output 0s explicitly in the text section. */
567 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
571 for (i
= 0; i
< size
- 20; i
+= 20)
574 fprintf (asm_out_file
,
575 "%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
);
577 fprintf (asm_out_file
,
578 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
584 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
586 fprintf (asm_out_file
, "\tbyte 0");
589 for (; i
< size
; i
++)
590 fprintf (asm_out_file
, ",0");
591 fprintf (asm_out_file
, "\n");
596 ASM_OUTPUT_SKIP (asm_out_file
, size
);
599 /* Assemble a string constant with the specified C string as contents. */
602 assemble_string (p
, size
)
610 /* If the string is very long, split it up. */
614 int thissize
= size
- pos
;
615 if (thissize
> maximum
)
618 #ifdef ASM_OUTPUT_ASCII
619 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
621 fprintf (asm_out_file
, "\t.ascii \"");
623 for (i
= 0; i
< thissize
; i
++)
625 register int c
= p
[i
];
626 if (c
== '\"' || c
== '\\')
627 putc ('\\', asm_out_file
);
628 if (c
>= ' ' && c
< 0177)
629 putc (c
, asm_out_file
);
632 fprintf (asm_out_file
, "\\%o", c
);
633 /* After an octal-escape, if a digit follows,
634 terminate one string constant and start another.
635 The Vax assembler fails to stop reading the escape
636 after three digits, so this is the only way we
637 can get it to parse the data properly. */
639 && p
[i
+ 1] >= '0' && p
[i
+ 1] <= '9')
640 fprintf (asm_out_file
, "\"\n\t.ascii \"");
643 fprintf (asm_out_file
, "\"\n");
644 #endif /* no ASM_OUTPUT_ASCII */
651 /* Assemble everything that is needed for a variable or function declaration.
652 Not used for automatic variables, and not used for function definitions.
653 Should not be called for variables of incomplete structure type.
655 TOP_LEVEL is nonzero if this variable has file scope.
656 AT_END is nonzero if this is the special handling, at end of compilation,
657 to define things that have had only tentative definitions. */
660 assemble_variable (decl
, top_level
, at_end
)
670 if (GET_CODE (DECL_RTL (decl
)) == REG
)
672 /* Do output symbol info for global register variables, but do nothing
675 if (TREE_ASM_WRITTEN (decl
))
677 TREE_ASM_WRITTEN (decl
) = 1;
679 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
680 /* File-scope global variables are output here. */
681 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
683 dbxout_symbol (decl
, 0);
685 #ifdef SDB_DEBUGGING_INFO
686 if (write_symbols
== SDB_DEBUG
&& top_level
687 /* Leave initialized global vars for end of compilation;
688 see comment in compile_file. */
689 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
690 sdbout_symbol (decl
, 0);
693 /* Don't output any DWARF debugging information for variables here.
694 In the case of local variables, the information for them is output
695 when we do our recursive traversal of the tree representation for
696 the entire containing function. In the case of file-scope variables,
697 we output information for all of them at the very end of compilation
698 while we are doing our final traversal of the chain of file-scope
704 /* Normally no need to say anything for external references,
705 since assembler considers all undefined symbols external. */
707 if (TREE_EXTERNAL (decl
))
710 /* Output no assembler code for a function declaration.
711 Only definitions of functions output anything. */
713 if (TREE_CODE (decl
) == FUNCTION_DECL
)
716 /* If type was incomplete when the variable was declared,
717 see if it is complete now. */
719 if (DECL_SIZE (decl
) == 0)
720 layout_decl (decl
, 0);
722 /* Still incomplete => don't allocate it; treat the tentative defn
723 (which is what it must have been) as an `extern' reference. */
725 if (DECL_SIZE (decl
) == 0)
727 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
728 DECL_SOURCE_LINE (decl
),
729 "storage size of static var `%s' isn't known",
730 IDENTIFIER_POINTER (DECL_NAME (decl
)));
734 /* The first declaration of a variable that comes through this function
735 decides whether it is global (in C, has external linkage)
736 or local (in C, has internal linkage). So do nothing more
737 if this function has already run. */
739 if (TREE_ASM_WRITTEN (decl
))
742 TREE_ASM_WRITTEN (decl
) = 1;
744 #ifdef DBX_DEBUGGING_INFO
745 /* File-scope global variables are output here. */
746 if (write_symbols
== DBX_DEBUG
&& top_level
)
747 dbxout_symbol (decl
, 0);
749 #ifdef SDB_DEBUGGING_INFO
750 if (write_symbols
== SDB_DEBUG
&& top_level
751 /* Leave initialized global vars for end of compilation;
752 see comment in compile_file. */
753 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
754 sdbout_symbol (decl
, 0);
757 /* Don't output any DWARF debugging information for variables here.
758 In the case of local variables, the information for them is output
759 when we do our recursive traversal of the tree representation for
760 the entire containing function. In the case of file-scope variables,
761 we output information for all of them at the very end of compilation
762 while we are doing our final traversal of the chain of file-scope
765 /* If storage size is erroneously variable, just continue.
766 Error message was already made. */
768 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
773 /* This is better than explicit arithmetic, since it avoids overflow. */
774 size_tree
= size_binop (CEIL_DIV_EXPR
,
775 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
777 if (TREE_INT_CST_HIGH (size_tree
) != 0)
779 error_with_decl (decl
, "size of variable `%s' is too large");
783 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
785 /* Handle uninitialized definitions. */
787 /* ANSI specifies that a tentative definition which is not merged with
788 a non-tentative definition behaves exactly like a definition with an
789 initializer equal to zero. (Section 3.7.2)
790 -fno-common gives strict ANSI behavior. Usually you don't want it. */
792 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
794 int size
= TREE_INT_CST_LOW (size_tree
);
797 if (TREE_INT_CST_HIGH (size_tree
) != 0)
798 error_with_decl (decl
, "size of variable `%s' is too large");
799 /* Don't allocate zero bytes of common,
800 since that means "undefined external" in the linker. */
801 if (size
== 0) rounded
= 1;
802 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
803 so that each uninitialized object starts on such a boundary. */
804 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
805 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
806 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
808 if (flag_shared_data
)
811 if (TREE_PUBLIC (decl
))
813 #ifdef ASM_OUTPUT_SHARED_COMMON
814 if (flag_shared_data
)
815 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
818 #ifdef ASM_OUTPUT_ALIGNED_COMMON
819 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
822 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
827 #ifdef ASM_OUTPUT_SHARED_LOCAL
828 if (flag_shared_data
)
829 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
832 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
833 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
836 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
842 /* Handle initialized definitions. */
844 /* First make the assembler name(s) global if appropriate. */
845 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
847 if (!first_global_object_name
)
848 first_global_object_name
= name
+ (name
[0] == '*');
849 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
852 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
854 tree e
= TREE_VALUE (d
);
855 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
856 ASM_GLOBALIZE_LABEL (asm_out_file
,
857 XSTR (XEXP (DECL_RTL (e
), 0), 0));
861 /* Output any data that we will need to use the address of. */
862 if (DECL_INITIAL (decl
))
863 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
865 /* Switch to the proper section for this data. */
866 #ifdef SELECT_SECTION
867 SELECT_SECTION (decl
, reloc
);
869 if (TREE_READONLY (decl
)
870 && ! TREE_THIS_VOLATILE (decl
)
871 && ! (flag_pic
&& reloc
))
872 readonly_data_section ();
877 /* Compute and output the alignment of this data. */
879 align
= DECL_ALIGN (decl
);
880 /* Some object file formats have a maximum alignment which they support.
881 In particular, a.out format supports a maximum alignment of 4. */
882 #ifndef MAX_OFILE_ALIGNMENT
883 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
885 if (align
> MAX_OFILE_ALIGNMENT
)
887 warning_with_decl (decl
,
888 "alignment of `%s' is greater than maximum object file alignment");
889 align
= MAX_OFILE_ALIGNMENT
;
891 #ifdef DATA_ALIGNMENT
892 /* On some machines, it is good to increase alignment sometimes. */
893 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
895 #ifdef CONSTANT_ALIGNMENT
896 if (DECL_INITIAL (decl
))
897 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
900 /* Reset the alignment in case we have made it tighter, so we can benefit
901 from it in get_pointer_alignment. */
902 DECL_ALIGN (decl
) = align
;
904 if (align
> BITS_PER_UNIT
)
905 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
907 /* Do any machine/system dependent processing of the object. */
908 #ifdef ASM_DECLARE_OBJECT_NAME
909 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
911 /* Standard thing is just output label for the object. */
912 ASM_OUTPUT_LABEL (asm_out_file
, name
);
913 #endif /* ASM_DECLARE_OBJECT_NAME */
916 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
918 tree e
= TREE_VALUE (d
);
919 ASM_OUTPUT_LABEL (asm_out_file
, XSTR (XEXP (DECL_RTL (e
), 0), 0));
923 if (DECL_INITIAL (decl
))
924 /* Output the actual data. */
925 output_constant (DECL_INITIAL (decl
),
926 int_size_in_bytes (TREE_TYPE (decl
)));
928 /* Leave space for it. */
929 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl
)));
932 #ifdef XCOFF_DEBUGGING_INFO
933 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
934 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
935 and `aa' hasn't been output yet, the assembler generates a stab entry with
936 a value of zero, in addition to creating an unnecessary external entry
937 for `aa'. Hence, we must pospone dbxout_symbol to here at the end. */
939 /* File-scope global variables are output here. */
940 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
941 dbxout_symbol (decl
, 0);
943 /* There must be a statement after a label. */
948 /* Output something to declare an external symbol to the assembler.
949 (Most assemblers don't need this, so we normally output nothing.)
950 Do nothing if DECL is not external. */
953 assemble_external (decl
)
956 #ifdef ASM_OUTPUT_EXTERNAL
957 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
958 && TREE_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
960 rtx rtl
= DECL_RTL (decl
);
962 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
963 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
965 /* Some systems do require some output. */
966 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
967 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
973 /* Similar, for calling a library function FUN. */
976 assemble_external_libcall (fun
)
979 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
980 /* Declare library function name external when first used, if nec. */
981 if (! SYMBOL_REF_USED (fun
))
983 SYMBOL_REF_USED (fun
) = 1;
984 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
989 /* Declare the label NAME global. */
992 assemble_global (name
)
995 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
998 /* Assemble a label named NAME. */
1001 assemble_label (name
)
1004 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1007 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1008 If NAME starts with a *, the rest of NAME is output verbatim.
1009 Otherwise NAME is transformed in an implementation-defined way
1010 (usually by the addition of an underscore).
1011 Many macros in the tm file are defined to call this function. */
1014 assemble_name (file
, name
)
1019 fputs (&name
[1], file
);
1021 ASM_OUTPUT_LABELREF (file
, name
);
1024 /* Allocate SIZE bytes writable static space with a gensym name
1025 and return an RTX to refer to its address. */
1028 assemble_static_space (size
)
1034 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1035 so that each uninitialized object starts on such a boundary. */
1036 int rounded
= ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1037 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1038 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1041 if (flag_shared_data
)
1045 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1048 namestring
= (char *) obstack_alloc (saveable_obstack
,
1050 strcpy (namestring
, name
);
1052 x
= gen_rtx (SYMBOL_REF
, Pmode
, namestring
);
1053 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1054 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1056 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1061 /* Assemble the static constant template for function entry trampolines.
1062 This is done at most once per compilation.
1063 Returns an RTX for the address of the template. */
1066 assemble_trampoline_template ()
1072 /* Write the assembler code to define one. */
1073 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1075 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1077 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1078 TRAMPOLINE_TEMPLATE (asm_out_file
);
1080 /* Record the rtl to refer to it. */
1081 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1083 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1084 return gen_rtx (SYMBOL_REF
, Pmode
, name
);
1087 /* Assemble the integer constant X into an object of SIZE bytes.
1088 X must be either a CONST_INT or CONST_DOUBLE.
1090 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1091 non-zero, abort if we can't output the constant. */
1094 assemble_integer (x
, size
, force
)
1099 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1100 ASM_OUTPUT... macros. */
1104 #ifdef ASM_OUTPUT_CHAR
1106 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1110 #ifdef ASM_OUTPUT_SHORT
1112 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1116 #ifdef ASM_OUTPUT_INT
1118 ASM_OUTPUT_INT (asm_out_file
, x
);
1122 #ifdef ASM_OUTPUT_DOUBLE_INT
1124 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1128 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1130 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1135 /* If we couldn't do it that way, there are two other possibilities: First,
1136 if the machine can output an explicit byte and this is a 1 byte constant,
1137 we can use ASM_OUTPUT_BYTE. */
1139 #ifdef ASM_OUTPUT_BYTE
1140 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1142 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1147 /* Finally, if SIZE is larger than a single word, try to output the constant
1148 one word at a time. */
1150 if (size
> UNITS_PER_WORD
)
1153 enum machine_mode mode
1154 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1157 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1159 word
= operand_subword (x
, i
, 0, mode
);
1164 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1168 if (i
== size
/ UNITS_PER_WORD
)
1170 /* If we output at least one word and then could not finish,
1171 there is no valid way to continue. */
1182 /* Assemble the floating-point constant D into an object of size MODE. */
1185 assemble_real (d
, mode
)
1187 enum machine_mode mode
;
1189 jmp_buf output_constant_handler
;
1191 if (setjmp (output_constant_handler
))
1193 error ("floating point trap outputting a constant");
1194 #ifdef REAL_IS_NOT_DOUBLE
1195 bzero (&d
, sizeof d
);
1202 set_float_handler (output_constant_handler
);
1206 #ifdef ASM_OUTPUT_FLOAT
1208 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1212 #ifdef ASM_OUTPUT_DOUBLE
1214 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1218 #ifdef ASM_OUTPUT_LONG_DOUBLE
1220 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1228 set_float_handler (0);
1231 /* Here we combine duplicate floating constants to make
1232 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1234 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1235 They are chained through the CONST_DOUBLE_CHAIN.
1236 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1237 In that case, CONST_DOUBLE_MEM is either a MEM,
1238 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
1240 static rtx const_double_chain
;
1242 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1243 For an integer, I0 is the low-order word and I1 is the high-order word.
1244 For a real number, I0 is the word with the low address
1245 and I1 is the word with the high address. */
1248 immed_double_const (i0
, i1
, mode
)
1250 enum machine_mode mode
;
1253 int in_current_obstack
;
1255 if (GET_MODE_CLASS (mode
) == MODE_INT
)
1257 /* We clear out all bits that don't belong in MODE, unless they and our
1258 sign bit are all one. So we get either a reasonable negative value
1259 or a reasonable unsigned value for this mode. */
1260 int width
= GET_MODE_BITSIZE (mode
);
1261 if (width
< HOST_BITS_PER_INT
1262 && ((i0
& ((-1) << (width
- 1))) != ((-1) << (width
- 1))))
1263 i0
&= (1 << width
) - 1, i1
= 0;
1264 else if (width
== HOST_BITS_PER_INT
1265 && ! (i1
== ~0 && i0
< 0))
1267 else if (width
> 2 * HOST_BITS_PER_INT
)
1268 /* We cannot represent this value as a constant. */
1271 /* If MODE fits within HOST_BITS_PER_INT, always use a CONST_INT.
1273 ??? Strictly speaking, this is wrong if we create a CONST_INT
1274 for a large unsigned constant with the size of MODE being
1275 HOST_BITS_PER_INT and later try to interpret that constant in a wider
1276 mode. In that case we will mis-interpret it as a negative number.
1278 Unfortunately, the only alternative is to make a CONST_DOUBLE
1279 for any constant in any mode if it is an unsigned constant larger
1280 than the maximum signed integer in an int on the host. However,
1281 doing this will break everyone that always expects to see a CONST_INT
1282 for SImode and smaller.
1284 We have always been making CONST_INTs in this case, so nothing new
1287 if (width
<= HOST_BITS_PER_INT
)
1288 i1
= (i0
< 0) ? ~0 : 0;
1290 /* If this integer fits in one word, return a CONST_INT. */
1291 if ((i1
== 0 && i0
>= 0)
1292 || (i1
== ~0 && i0
< 0))
1293 return gen_rtx (CONST_INT
, VOIDmode
, i0
);
1295 /* We use VOIDmode for integers. */
1299 /* Search the chain for an existing CONST_DOUBLE with the right value.
1300 If one is found, return it. */
1302 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1303 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
1304 && GET_MODE (r
) == mode
)
1307 /* No; make a new one and add it to the chain.
1309 We may be called by an optimizer which may be discarding any memory
1310 allocated during its processing (such as combine and loop). However,
1311 we will be leaving this constant on the chain, so we cannot tolerate
1312 freed memory. So switch to saveable_obstack for this allocation
1313 and then switch back if we were in current_obstack. */
1315 in_current_obstack
= rtl_in_saveable_obstack ();
1316 r
= gen_rtx (CONST_DOUBLE
, mode
, 0, i0
, i1
);
1317 if (in_current_obstack
)
1318 rtl_in_current_obstack ();
1320 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1321 const_double_chain
= r
;
1323 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1324 Actual use of mem-slot is only through force_const_mem. */
1326 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1331 /* Return a CONST_DOUBLE for a specified `double' value
1332 and machine mode. */
1335 immed_real_const_1 (d
, mode
)
1337 enum machine_mode mode
;
1339 union real_extract u
;
1341 int in_current_obstack
;
1343 /* Get the desired `double' value as a sequence of ints
1344 since that is how they are stored in a CONST_DOUBLE. */
1348 /* Detect special cases. */
1350 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1351 if (!bcmp (&dconst0
, &d
, sizeof d
))
1352 return CONST0_RTX (mode
);
1353 else if (REAL_VALUES_EQUAL (dconst1
, d
))
1354 return CONST1_RTX (mode
);
1356 if (sizeof u
== 2 * sizeof (int))
1357 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
1359 /* The rest of this function handles the case where
1360 a float value requires more than 2 ints of space.
1361 It will be deleted as dead code on machines that don't need it. */
1363 /* Search the chain for an existing CONST_DOUBLE with the right value.
1364 If one is found, return it. */
1366 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1367 if (! bcmp (&CONST_DOUBLE_LOW (r
), &u
, sizeof u
)
1368 && GET_MODE (r
) == mode
)
1371 /* No; make a new one and add it to the chain.
1373 We may be called by an optimizer which may be discarding any memory
1374 allocated during its processing (such as combine and loop). However,
1375 we will be leaving this constant on the chain, so we cannot tolerate
1376 freed memory. So switch to saveable_obstack for this allocation
1377 and then switch back if we were in current_obstack. */
1379 in_current_obstack
= rtl_in_saveable_obstack ();
1380 r
= rtx_alloc (CONST_DOUBLE
);
1382 bcopy (&u
, &CONST_DOUBLE_LOW (r
), sizeof u
);
1383 if (in_current_obstack
)
1384 rtl_in_current_obstack ();
1386 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1387 const_double_chain
= r
;
1389 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1390 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1391 is only through force_const_mem. */
1393 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1398 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1399 which must be a REAL_CST tree node. */
1402 immed_real_const (exp
)
1405 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
1408 /* At the end of a function, forget the memory-constants
1409 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1410 Also clear out real_constant_chain and clear out all the chain-pointers. */
1413 clear_const_double_mem ()
1415 register rtx r
, next
;
1417 for (r
= const_double_chain
; r
; r
= next
)
1419 next
= CONST_DOUBLE_CHAIN (r
);
1420 CONST_DOUBLE_CHAIN (r
) = 0;
1421 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
1423 const_double_chain
= 0;
1426 /* Given an expression EXP with a constant value,
1427 reduce it to the sum of an assembler symbol and an integer.
1428 Store them both in the structure *VALUE.
1429 Abort if EXP does not reduce. */
1438 decode_addr_const (exp
, value
)
1440 struct addr_const
*value
;
1442 register tree target
= TREE_OPERAND (exp
, 0);
1443 register int offset
= 0;
1448 if (TREE_CODE (target
) == COMPONENT_REF
1449 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
1452 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
1453 target
= TREE_OPERAND (target
, 0);
1455 else if (TREE_CODE (target
) == ARRAY_REF
)
1457 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
1458 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
1460 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
1461 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
1463 target
= TREE_OPERAND (target
, 0);
1469 switch (TREE_CODE (target
))
1473 x
= DECL_RTL (target
);
1477 x
= gen_rtx (MEM
, FUNCTION_MODE
,
1478 gen_rtx (LABEL_REF
, VOIDmode
,
1479 label_rtx (TREE_OPERAND (exp
, 0))));
1486 x
= TREE_CST_RTL (target
);
1493 if (GET_CODE (x
) != MEM
)
1498 value
->offset
= offset
;
1501 /* Uniquize all constants that appear in memory.
1502 Each constant in memory thus far output is recorded
1503 in `const_hash_table' with a `struct constant_descriptor'
1504 that contains a polish representation of the value of
1507 We cannot store the trees in the hash table
1508 because the trees may be temporary. */
1510 struct constant_descriptor
1512 struct constant_descriptor
*next
;
1518 #define MAX_HASH_TABLE 1009
1519 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
1521 /* Compute a hash code for a constant expression. */
1528 register int len
, hi
, i
;
1529 register enum tree_code code
= TREE_CODE (exp
);
1531 if (code
== INTEGER_CST
)
1533 p
= (char *) &TREE_INT_CST_LOW (exp
);
1534 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1536 else if (code
== REAL_CST
)
1538 p
= (char *) &TREE_REAL_CST (exp
);
1539 len
= sizeof TREE_REAL_CST (exp
);
1541 else if (code
== STRING_CST
)
1542 p
= TREE_STRING_POINTER (exp
), len
= TREE_STRING_LENGTH (exp
);
1543 else if (code
== COMPLEX_CST
)
1544 return const_hash (TREE_REALPART (exp
)) * 5
1545 + const_hash (TREE_IMAGPART (exp
));
1546 else if (code
== CONSTRUCTOR
)
1550 /* For record type, include the type in the hashing.
1551 We do not do so for array types
1552 because (1) the sizes of the elements are sufficient
1553 and (2) distinct array types can have the same constructor.
1554 Instead, we include the array size because the constructor could
1556 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1557 hi
= ((int) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
1559 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
1560 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
1562 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1563 hi
= (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
1567 else if (code
== ADDR_EXPR
)
1569 struct addr_const value
;
1570 decode_addr_const (exp
, &value
);
1571 if (GET_CODE (value
.base
) == SYMBOL_REF
)
1573 /* Don't hash the address of the SYMBOL_REF;
1574 only use the offset and the symbol name. */
1576 p
= XSTR (value
.base
, 0);
1577 for (i
= 0; p
[i
] != 0; i
++)
1578 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
1580 else if (GET_CODE (value
.base
) == LABEL_REF
)
1581 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
1583 hi
&= (1 << HASHBITS
) - 1;
1584 hi
%= MAX_HASH_TABLE
;
1587 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1588 return const_hash (TREE_OPERAND (exp
, 0)) * 9
1589 + const_hash (TREE_OPERAND (exp
, 1));
1590 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1591 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
1593 /* Compute hashing function */
1595 for (i
= 0; i
< len
; i
++)
1596 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
1598 hi
&= (1 << HASHBITS
) - 1;
1599 hi
%= MAX_HASH_TABLE
;
1603 /* Compare a constant expression EXP with a constant-descriptor DESC.
1604 Return 1 if DESC describes a constant with the same value as EXP. */
1607 compare_constant (exp
, desc
)
1609 struct constant_descriptor
*desc
;
1611 return 0 != compare_constant_1 (exp
, desc
->contents
);
1614 /* Compare constant expression EXP with a substring P of a constant descriptor.
1615 If they match, return a pointer to the end of the substring matched.
1616 If they do not match, return 0.
1618 Since descriptors are written in polish prefix notation,
1619 this function can be used recursively to test one operand of EXP
1620 against a subdescriptor, and if it succeeds it returns the
1621 address of the subdescriptor for the next operand. */
1624 compare_constant_1 (exp
, p
)
1628 register char *strp
;
1630 register enum tree_code code
= TREE_CODE (exp
);
1632 if (code
!= (enum tree_code
) *p
++)
1635 if (code
== INTEGER_CST
)
1637 /* Integer constants are the same only if the same width of type. */
1638 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
1640 strp
= (char *) &TREE_INT_CST_LOW (exp
);
1641 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1643 else if (code
== REAL_CST
)
1645 /* Real constants are the same only if the same width of type. */
1646 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
1648 strp
= (char *) &TREE_REAL_CST (exp
);
1649 len
= sizeof TREE_REAL_CST (exp
);
1651 else if (code
== STRING_CST
)
1653 if (flag_writable_strings
)
1655 strp
= TREE_STRING_POINTER (exp
);
1656 len
= TREE_STRING_LENGTH (exp
);
1657 if (bcmp (&TREE_STRING_LENGTH (exp
), p
,
1658 sizeof TREE_STRING_LENGTH (exp
)))
1660 p
+= sizeof TREE_STRING_LENGTH (exp
);
1662 else if (code
== COMPLEX_CST
)
1664 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
1665 if (p
== 0) return 0;
1666 p
= compare_constant_1 (TREE_IMAGPART (exp
), p
);
1669 else if (code
== CONSTRUCTOR
)
1672 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
1675 if (bcmp (&length
, p
, sizeof length
))
1679 /* For record constructors, insist that the types match.
1680 For arrays, just verify both constructors are for arrays. */
1681 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1682 type
= TREE_TYPE (exp
);
1685 if (bcmp (&type
, p
, sizeof type
))
1689 /* For arrays, insist that the size in bytes match. */
1690 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1692 int size
= int_size_in_bytes (TREE_TYPE (exp
));
1693 if (bcmp (&size
, p
, sizeof size
))
1698 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1699 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
1703 else if (code
== ADDR_EXPR
)
1705 struct addr_const value
;
1706 decode_addr_const (exp
, &value
);
1707 strp
= (char *) &value
.offset
;
1708 len
= sizeof value
.offset
;
1709 /* Compare the offset. */
1711 if (*p
++ != *strp
++)
1713 /* Compare symbol name. */
1714 strp
= XSTR (value
.base
, 0);
1715 len
= strlen (strp
) + 1;
1717 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1719 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
1720 if (p
== 0) return 0;
1721 p
= compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
1724 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1726 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
1730 /* Compare constant contents. */
1732 if (*p
++ != *strp
++)
1738 /* Construct a constant descriptor for the expression EXP.
1739 It is up to the caller to enter the descriptor in the hash table. */
1741 static struct constant_descriptor
*
1742 record_constant (exp
)
1745 struct constant_descriptor
*ptr
= 0;
1748 obstack_grow (&permanent_obstack
, &ptr
, sizeof ptr
);
1749 obstack_grow (&permanent_obstack
, &buf
, sizeof buf
);
1750 record_constant_1 (exp
);
1751 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
1754 /* Add a description of constant expression EXP
1755 to the object growing in `permanent_obstack'.
1756 No need to return its address; the caller will get that
1757 from the obstack when the object is complete. */
1760 record_constant_1 (exp
)
1763 register char *strp
;
1765 register enum tree_code code
= TREE_CODE (exp
);
1767 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
1769 if (code
== INTEGER_CST
)
1771 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
1772 strp
= (char *) &TREE_INT_CST_LOW (exp
);
1773 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1775 else if (code
== REAL_CST
)
1777 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
1778 strp
= (char *) &TREE_REAL_CST (exp
);
1779 len
= sizeof TREE_REAL_CST (exp
);
1781 else if (code
== STRING_CST
)
1783 if (flag_writable_strings
)
1785 strp
= TREE_STRING_POINTER (exp
);
1786 len
= TREE_STRING_LENGTH (exp
);
1787 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
1788 sizeof TREE_STRING_LENGTH (exp
));
1790 else if (code
== COMPLEX_CST
)
1792 record_constant_1 (TREE_REALPART (exp
));
1793 record_constant_1 (TREE_IMAGPART (exp
));
1796 else if (code
== CONSTRUCTOR
)
1799 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
1802 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
1804 /* For record constructors, insist that the types match.
1805 For arrays, just verify both constructors are for arrays. */
1806 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1807 type
= TREE_TYPE (exp
);
1810 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
1812 /* For arrays, insist that the size in bytes match. */
1813 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1815 int size
= int_size_in_bytes (TREE_TYPE (exp
));
1816 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
1819 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1820 record_constant_1 (TREE_VALUE (link
));
1823 else if (code
== ADDR_EXPR
)
1825 struct addr_const value
;
1826 decode_addr_const (exp
, &value
);
1827 /* Record the offset. */
1828 obstack_grow (&permanent_obstack
,
1829 (char *) &value
.offset
, sizeof value
.offset
);
1830 /* Record the symbol name. */
1831 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
1832 strlen (XSTR (value
.base
, 0)) + 1);
1835 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1837 record_constant_1 (TREE_OPERAND (exp
, 0));
1838 record_constant_1 (TREE_OPERAND (exp
, 1));
1841 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1843 record_constant_1 (TREE_OPERAND (exp
, 0));
1847 /* Record constant contents. */
1848 obstack_grow (&permanent_obstack
, strp
, len
);
1851 /* Return an rtx representing a reference to constant data in memory
1852 for the constant expression EXP.
1853 If assembler code for such a constant has already been output,
1854 return an rtx to refer to it.
1855 Otherwise, output such a constant in memory and generate
1856 an rtx for it. The TREE_CST_RTL of EXP is set up to point to that rtx.
1857 The const_hash_table records which constants already have label strings. */
1860 output_constant_def (exp
)
1863 register int hash
, align
;
1864 register struct constant_descriptor
*desc
;
1870 if (TREE_CODE (exp
) == INTEGER_CST
)
1871 abort (); /* No TREE_CST_RTL slot in these. */
1873 if (TREE_CST_RTL (exp
))
1874 return TREE_CST_RTL (exp
);
1876 /* Make sure any other constants whose addresses appear in EXP
1877 are assigned label numbers. */
1879 reloc
= output_addressed_constants (exp
);
1881 /* Compute hash code of EXP. Search the descriptors for that hash code
1882 to see if any of them describes EXP. If yes, the descriptor records
1883 the label number already assigned. */
1885 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
1887 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
1888 if (compare_constant (exp
, desc
))
1890 found
= desc
->label
;
1896 /* No constant equal to EXP is known to have been output.
1897 Make a constant descriptor to enter EXP in the hash table.
1898 Assign the label number and record it in the descriptor for
1899 future calls to this function to find. */
1901 /* Create a string containing the label name, in LABEL. */
1902 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
1904 desc
= record_constant (exp
);
1905 desc
->next
= const_hash_table
[hash
];
1907 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1908 const_hash_table
[hash
] = desc
;
1911 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
1913 push_obstacks_nochange ();
1914 if (TREE_PERMANENT (exp
))
1915 end_temporary_allocation ();
1917 def
= gen_rtx (SYMBOL_REF
, Pmode
, desc
->label
);
1920 = gen_rtx (MEM
, TYPE_MODE (TREE_TYPE (exp
)), def
);
1921 RTX_UNCHANGING_P (TREE_CST_RTL (exp
)) = 1;
1922 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
1923 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1924 MEM_IN_STRUCT_P (TREE_CST_RTL (exp
)) = 1;
1928 /* Optionally set flags or add text to the name to record information
1929 such as that it is a function name. If the name is changed, the macro
1930 ASM_OUTPUT_LABELREF will have to know how to strip this information.
1931 And if it finds a * at the beginning after doing so, it must handle
1933 #ifdef ENCODE_SECTION_INFO
1934 ENCODE_SECTION_INFO (exp
);
1939 /* Now output assembler code to define that label
1940 and follow it with the data of EXP. */
1942 /* First switch to text section, except for writable strings. */
1943 #ifdef SELECT_SECTION
1944 SELECT_SECTION (exp
, reloc
);
1946 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
1947 || (flag_pic
&& reloc
))
1950 readonly_data_section ();
1953 /* Align the location counter as required by EXP's data type. */
1954 align
= TYPE_ALIGN (TREE_TYPE (exp
));
1955 #ifdef CONSTANT_ALIGNMENT
1956 align
= CONSTANT_ALIGNMENT (exp
, align
);
1959 if (align
> BITS_PER_UNIT
)
1960 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1962 /* Output the label itself. */
1963 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", const_labelno
);
1965 /* Output the value of EXP. */
1966 output_constant (exp
,
1967 (TREE_CODE (exp
) == STRING_CST
1968 ? TREE_STRING_LENGTH (exp
)
1969 : int_size_in_bytes (TREE_TYPE (exp
))));
1974 return TREE_CST_RTL (exp
);
1977 /* Similar hash facility for making memory-constants
1978 from constant rtl-expressions. It is used on RISC machines
1979 where immediate integer arguments and constant addresses are restricted
1980 so that such constants must be stored in memory.
1982 This pool of constants is reinitialized for each function
1983 so each function gets its own constants-pool that comes right before it.
1985 All structures allocated here are discarded when functions are saved for
1986 inlining, so they do not need to be allocated permanently. */
1988 #define MAX_RTX_HASH_TABLE 61
1989 static struct constant_descriptor
*const_rtx_hash_table
[MAX_RTX_HASH_TABLE
];
1991 /* Structure to represent sufficient information about a constant so that
1992 it can be output when the constant pool is output, so that function
1993 integration can be done, and to simplify handling on machines that reference
1994 constant pool as base+displacement. */
1996 struct pool_constant
1998 struct constant_descriptor
*desc
;
1999 struct pool_constant
*next
;
2000 enum machine_mode mode
;
2007 /* Pointers to first and last constant in pool. */
2009 static struct pool_constant
*first_pool
, *last_pool
;
2011 /* Current offset in constant pool (does not include any machine-specific
2014 static int pool_offset
;
2016 /* Structure used to maintain hash table mapping symbols used to their
2017 corresponding constants. */
2022 struct pool_constant
*pool
;
2023 struct pool_sym
*next
;
2026 static struct pool_sym
*const_rtx_sym_hash_table
[MAX_RTX_HASH_TABLE
];
2028 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2029 The argument is XSTR (... , 0) */
2031 #define SYMHASH(LABEL) \
2032 ((((int) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2034 /* Initialize constant pool hashing for next function. */
2037 init_const_rtx_hash_table ()
2039 bzero (const_rtx_hash_table
, sizeof const_rtx_hash_table
);
2040 bzero (const_rtx_sym_hash_table
, sizeof const_rtx_sym_hash_table
);
2042 first_pool
= last_pool
= 0;
2046 enum kind
{ RTX_DOUBLE
, RTX_INT
};
2050 #ifdef ONLY_INT_FIELDS
2051 unsigned int kind
: 16;
2052 unsigned int mode
: 16;
2054 enum kind kind
: 16;
2055 enum machine_mode mode
: 16;
2058 union real_extract du
;
2059 struct addr_const addr
;
2063 /* Express an rtx for a constant integer (perhaps symbolic)
2064 as the sum of a symbol or label plus an explicit integer.
2065 They are stored into VALUE. */
2068 decode_rtx_const (mode
, x
, value
)
2069 enum machine_mode mode
;
2071 struct rtx_const
*value
;
2073 /* Clear the whole structure, including any gaps. */
2076 int *p
= (int *) value
;
2077 int *end
= (int *) (value
+ 1);
2082 value
->kind
= RTX_INT
; /* Most usual kind. */
2085 switch (GET_CODE (x
))
2088 value
->kind
= RTX_DOUBLE
;
2089 value
->mode
= GET_MODE (x
);
2090 bcopy (&CONST_DOUBLE_LOW (x
), &value
->un
.du
, sizeof value
->un
.du
);
2094 value
->un
.addr
.offset
= INTVAL (x
);
2099 value
->un
.addr
.base
= x
;
2104 if (GET_CODE (x
) == PLUS
)
2106 value
->un
.addr
.base
= XEXP (x
, 0);
2107 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
2109 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
2111 else if (GET_CODE (x
) == MINUS
)
2113 value
->un
.addr
.base
= XEXP (x
, 0);
2114 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
2116 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
2126 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
2127 switch (GET_CODE (value
->un
.addr
.base
))
2131 /* Use the string's address, not the SYMBOL_REF's address,
2132 for the sake of addresses of library routines.
2133 For a LABEL_REF, compare labels. */
2134 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
2138 /* Compute a hash code for a constant RTL expression. */
2141 const_hash_rtx (mode
, x
)
2142 enum machine_mode mode
;
2147 struct rtx_const value
;
2148 decode_rtx_const (mode
, x
, &value
);
2150 /* Compute hashing function */
2152 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
2153 hi
+= ((int *) &value
)[i
];
2155 hi
&= (1 << HASHBITS
) - 1;
2156 hi
%= MAX_RTX_HASH_TABLE
;
2160 /* Compare a constant rtl object X with a constant-descriptor DESC.
2161 Return 1 if DESC describes a constant with the same value as X. */
2164 compare_constant_rtx (mode
, x
, desc
)
2165 enum machine_mode mode
;
2167 struct constant_descriptor
*desc
;
2169 register int *p
= (int *) desc
->contents
;
2172 struct rtx_const value
;
2174 decode_rtx_const (mode
, x
, &value
);
2175 strp
= (int *) &value
;
2176 len
= sizeof value
/ sizeof (int);
2178 /* Compare constant contents. */
2180 if (*p
++ != *strp
++)
2186 /* Construct a constant descriptor for the rtl-expression X.
2187 It is up to the caller to enter the descriptor in the hash table. */
2189 static struct constant_descriptor
*
2190 record_constant_rtx (mode
, x
)
2191 enum machine_mode mode
;
2194 struct constant_descriptor
*ptr
;
2196 struct rtx_const value
;
2198 decode_rtx_const (mode
, x
, &value
);
2200 obstack_grow (current_obstack
, &ptr
, sizeof ptr
);
2201 obstack_grow (current_obstack
, &label
, sizeof label
);
2203 /* Record constant contents. */
2204 obstack_grow (current_obstack
, &value
, sizeof value
);
2206 return (struct constant_descriptor
*) obstack_finish (current_obstack
);
2209 /* Given a constant rtx X, make (or find) a memory constant for its value
2210 and return a MEM rtx to refer to it in memory. */
2213 force_const_mem (mode
, x
)
2214 enum machine_mode mode
;
2218 register struct constant_descriptor
*desc
;
2223 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2224 (this will always be true for floating CONST_DOUBLEs that have been
2225 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2226 use the previous copy. Otherwise, make a new one. Note that in
2227 the unlikely event that this same CONST_DOUBLE is used in two different
2228 modes in an alternating fashion, we will allocate a lot of different
2229 memory locations, but this should be extremely rare. */
2231 if (GET_CODE (x
) == CONST_DOUBLE
2232 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
2233 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
2234 return CONST_DOUBLE_MEM (x
);
2236 /* Compute hash code of X. Search the descriptors for that hash code
2237 to see if any of them describes X. If yes, the descriptor records
2238 the label number already assigned. */
2240 hash
= const_hash_rtx (mode
, x
);
2242 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
2243 if (compare_constant_rtx (mode
, x
, desc
))
2245 found
= desc
->label
;
2251 register struct pool_constant
*pool
;
2252 register struct pool_sym
*sym
;
2255 /* No constant equal to X is known to have been output.
2256 Make a constant descriptor to enter X in the hash table.
2257 Assign the label number and record it in the descriptor for
2258 future calls to this function to find. */
2260 desc
= record_constant_rtx (mode
, x
);
2261 desc
->next
= const_rtx_hash_table
[hash
];
2262 const_rtx_hash_table
[hash
] = desc
;
2264 /* Align the location counter as required by EXP's data type. */
2265 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
2266 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2267 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
2269 pool_offset
+= align
- 1;
2270 pool_offset
&= ~ (align
- 1);
2272 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2274 pool
= (struct pool_constant
*) oballoc (sizeof (struct pool_constant
));
2278 pool
->labelno
= const_labelno
;
2279 pool
->align
= align
;
2280 pool
->offset
= pool_offset
;
2286 last_pool
->next
= pool
;
2289 pool_offset
+= GET_MODE_SIZE (mode
);
2291 /* Create a string containing the label name, in LABEL. */
2292 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2297 = (char *) obstack_copy0 (saveable_obstack
, label
, strlen (label
));
2299 /* Add label to symbol hash table. */
2300 hash
= SYMHASH (found
);
2301 sym
= (struct pool_sym
*) oballoc (sizeof (struct pool_sym
));
2304 sym
->next
= const_rtx_sym_hash_table
[hash
];
2305 const_rtx_sym_hash_table
[hash
] = sym
;
2308 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2310 def
= gen_rtx (MEM
, mode
, gen_rtx (SYMBOL_REF
, Pmode
, found
));
2312 RTX_UNCHANGING_P (def
) = 1;
2313 /* Mark the symbol_ref as belonging to this constants pool. */
2314 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
2315 current_function_uses_const_pool
= 1;
2317 if (GET_CODE (x
) == CONST_DOUBLE
)
2319 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
2321 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
2322 const_double_chain
= x
;
2324 CONST_DOUBLE_MEM (x
) = def
;
2330 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2331 the corresponding pool_constant structure. */
2333 static struct pool_constant
*
2334 find_pool_constant (addr
)
2337 struct pool_sym
*sym
;
2338 char *label
= XSTR (addr
, 0);
2340 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
2341 if (sym
->label
== label
)
2347 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2350 get_pool_constant (addr
)
2353 return (find_pool_constant (addr
))->constant
;
2356 /* Similar, return the mode. */
2359 get_pool_mode (addr
)
2362 return (find_pool_constant (addr
))->mode
;
2365 /* Similar, return the offset in the constant pool. */
2368 get_pool_offset (addr
)
2371 return (find_pool_constant (addr
))->offset
;
2374 /* Return the size of the constant pool. */
2382 /* Write all the constants in the constant pool. */
2385 output_constant_pool (fnname
, fndecl
)
2389 struct pool_constant
*pool
;
2391 union real_extract u
;
2393 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2394 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
2397 for (pool
= first_pool
; pool
; pool
= pool
->next
)
2401 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2402 whose CODE_LABEL has been deleted. This can occur if a jump table
2403 is eliminated by optimization. If so, write a constant of zero
2405 if ((GET_CODE (x
) == LABEL_REF
&& INSN_DELETED_P (XEXP (x
, 0)))
2406 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
2407 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
2408 && INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))))
2411 /* First switch to correct section. */
2412 #ifdef SELECT_RTX_SECTION
2413 SELECT_RTX_SECTION (pool
->mode
, x
);
2415 readonly_data_section ();
2418 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2419 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
2420 pool
->align
, pool
->labelno
, done
);
2423 if (pool
->align
> 1)
2424 ASM_OUTPUT_ALIGN (asm_out_file
, exact_log2 (pool
->align
));
2426 /* Output the label. */
2427 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
2429 /* Output the value of the constant itself. */
2430 switch (GET_MODE_CLASS (pool
->mode
))
2433 if (GET_CODE (x
) != CONST_DOUBLE
)
2436 bcopy (&CONST_DOUBLE_LOW (x
), &u
, sizeof u
);
2437 assemble_real (u
.d
, pool
->mode
);
2441 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
2451 /* Done with this pool. */
2452 first_pool
= last_pool
= 0;
2455 /* Find all the constants whose addresses are referenced inside of EXP,
2456 and make sure assembler code with a label has been output for each one.
2457 Indicate whether an ADDR_EXPR has been encountered. */
2460 output_addressed_constants (exp
)
2465 switch (TREE_CODE (exp
))
2469 register tree constant
= TREE_OPERAND (exp
, 0);
2471 while (TREE_CODE (constant
) == COMPONENT_REF
)
2473 constant
= TREE_OPERAND (constant
, 0);
2476 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
2477 || TREE_CODE (constant
) == CONSTRUCTOR
)
2478 /* No need to do anything here
2479 for addresses of variables or functions. */
2480 output_constant_def (constant
);
2487 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
2488 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
2493 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
2499 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2500 if (TREE_VALUE (link
) != 0)
2501 reloc
|= output_addressed_constants (TREE_VALUE (link
));
2511 /* Output assembler code for constant EXP to FILE, with no label.
2512 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2513 Assumes output_addressed_constants has been done on EXP already.
2515 Generate exactly SIZE bytes of assembler data, padding at the end
2516 with zeros if necessary. SIZE must always be specified.
2518 SIZE is important for structure constructors,
2519 since trailing members may have been omitted from the constructor.
2520 It is also important for initialization of arrays from string constants
2521 since the full length of the string constant might not be wanted.
2522 It is also needed for initialization of unions, where the initializer's
2523 type is just one member, and that may not be as long as the union.
2525 There a case in which we would fail to output exactly SIZE bytes:
2526 for a structure constructor that wants to produce more than SIZE bytes.
2527 But such constructors will never be generated for any possible input. */
2530 output_constant (exp
, size
)
2534 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
2540 /* Allow a constructor with no elements for any data type.
2541 This means to fill the space with zeros. */
2542 if (TREE_CODE (exp
) == CONSTRUCTOR
2543 && TREE_OPERAND (exp
, 1) == 0)
2545 assemble_zeros (size
);
2549 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2550 That way we get the constant (we hope) inside it. */
2551 if (TREE_CODE (exp
) == NOP_EXPR
2552 && TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0)))
2553 exp
= TREE_OPERAND (exp
, 0);
2560 case REFERENCE_TYPE
:
2561 /* ??? What about (int)((float)(int)&foo + 4) */
2562 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
2563 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2564 exp
= TREE_OPERAND (exp
, 0);
2566 if (! assemble_integer (expand_expr (exp
, 0, VOIDmode
,
2567 EXPAND_INITIALIZER
),
2569 error ("initializer for integer value is too complicated");
2574 if (TREE_CODE (exp
) != REAL_CST
)
2575 error ("initializer for floating value is not a floating constant");
2577 assemble_real (TREE_REAL_CST (exp
),
2578 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
2583 output_constant (TREE_REALPART (exp
), size
/ 2);
2584 output_constant (TREE_IMAGPART (exp
), size
/ 2);
2585 size
-= (size
/ 2) * 2;
2589 if (TREE_CODE (exp
) == CONSTRUCTOR
)
2591 output_constructor (exp
, size
);
2594 else if (TREE_CODE (exp
) == STRING_CST
)
2598 if (size
> TREE_STRING_LENGTH (exp
))
2600 excess
= size
- TREE_STRING_LENGTH (exp
);
2601 size
= TREE_STRING_LENGTH (exp
);
2604 assemble_string (TREE_STRING_POINTER (exp
), size
);
2613 if (TREE_CODE (exp
) == CONSTRUCTOR
)
2614 output_constructor (exp
, size
);
2621 assemble_zeros (size
);
2624 /* Subroutine of output_constant, used for CONSTRUCTORs
2625 (aggregate constants).
2626 Generate at least SIZE bytes, padding if necessary. */
2629 output_constructor (exp
, size
)
2633 register tree link
, field
= 0;
2634 /* Number of bytes output or skipped so far.
2635 In other words, current position within the constructor. */
2636 int total_bytes
= 0;
2637 /* Non-zero means BYTE contains part of a byte, to be output. */
2638 int byte_buffer_in_use
= 0;
2641 if (HOST_BITS_PER_INT
< BITS_PER_UNIT
)
2644 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2645 field
= TYPE_FIELDS (TREE_TYPE (exp
));
2647 /* As LINK goes through the elements of the constant,
2648 FIELD goes through the structure fields, if the constant is a structure.
2649 if the constant is a union, then we override this,
2650 by getting the field from the TREE_LIST element.
2651 But the constant could also be an array. Then FIELD is zero. */
2652 for (link
= CONSTRUCTOR_ELTS (exp
);
2654 link
= TREE_CHAIN (link
),
2655 field
= field
? TREE_CHAIN (field
) : 0)
2657 tree val
= TREE_VALUE (link
);
2658 /* the element in a union constructor specifies the proper field. */
2659 if (TREE_PURPOSE (link
) != 0)
2660 field
= TREE_PURPOSE (link
);
2662 /* Eliminate the marker that makes a cast not be an lvalue. */
2663 if (val
!= 0 && TREE_CODE (val
) == NON_LVALUE_EXPR
)
2664 val
= TREE_OPERAND (val
, 0);
2666 if (field
== 0 || !DECL_BIT_FIELD (field
))
2668 register int fieldsize
;
2669 /* Since this structure is static,
2670 we know the positions are constant. */
2671 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
2675 /* An element that is not a bit-field.
2676 Output any buffered-up bit-fields preceding it. */
2677 if (byte_buffer_in_use
)
2679 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2681 byte_buffer_in_use
= 0;
2684 /* Advance to offset of this element.
2685 Note no alignment needed in an array, since that is guaranteed
2686 if each element has the proper size. */
2687 if (field
!= 0 && bitpos
!= total_bytes
)
2689 assemble_zeros (bitpos
- total_bytes
);
2690 total_bytes
= bitpos
;
2693 /* Determine size this element should occupy. */
2696 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
2698 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
2700 /* This avoids overflow trouble. */
2701 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
2703 size_int (BITS_PER_UNIT
));
2704 fieldsize
= TREE_INT_CST_LOW (size_tree
);
2708 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
2709 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
2713 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
2715 /* Output the element's initial value. */
2717 assemble_zeros (fieldsize
);
2719 output_constant (val
, fieldsize
);
2721 /* Count its size. */
2722 total_bytes
+= fieldsize
;
2724 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
2725 error ("invalid initial value for member `%s'",
2726 IDENTIFIER_POINTER (DECL_NAME (field
)));
2729 /* Element that is a bit-field. */
2731 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
2733 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
2736 val
= integer_zero_node
;
2738 /* If this field does not start in this (or, next) byte,
2740 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
2742 /* Output remnant of any bit field in previous bytes. */
2743 if (byte_buffer_in_use
)
2745 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2747 byte_buffer_in_use
= 0;
2750 /* If still not at proper byte, advance to there. */
2751 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
2753 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
2754 total_bytes
= next_offset
/ BITS_PER_UNIT
;
2758 if (! byte_buffer_in_use
)
2761 /* We must split the element into pieces that fall within
2762 separate bytes, and combine each byte with previous or
2763 following bit-fields. */
2765 /* next_offset is the offset n fbits from the beginning of
2766 the structure to the next bit of this element to be processed.
2767 end_offset is the offset of the first bit past the end of
2769 while (next_offset
< end_offset
)
2773 int next_byte
= next_offset
/ BITS_PER_UNIT
;
2774 int next_bit
= next_offset
% BITS_PER_UNIT
;
2776 /* Advance from byte to byte
2777 within this element when necessary. */
2778 while (next_byte
!= total_bytes
)
2780 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2785 /* Number of bits we can process at once
2786 (all part of the same byte). */
2787 this_time
= MIN (end_offset
- next_offset
,
2788 BITS_PER_UNIT
- next_bit
);
2789 #if BYTES_BIG_ENDIAN
2790 /* On big-endian machine, take the most significant bits
2791 first (of the bits that are significant)
2792 and put them into bytes from the most significant end. */
2793 shift
= end_offset
- next_offset
- this_time
;
2794 /* Don't try to take a bunch of bits that cross
2795 the word boundary in the INTEGER_CST. */
2796 if (shift
< HOST_BITS_PER_INT
2797 && shift
+ this_time
> HOST_BITS_PER_INT
)
2799 this_time
-= (HOST_BITS_PER_INT
- shift
);
2800 shift
= HOST_BITS_PER_INT
;
2803 /* Now get the bits from the appropriate constant word. */
2804 if (shift
< HOST_BITS_PER_INT
)
2806 value
= TREE_INT_CST_LOW (val
);
2808 else if (shift
< 2 * HOST_BITS_PER_INT
)
2810 value
= TREE_INT_CST_HIGH (val
);
2811 shift
-= HOST_BITS_PER_INT
;
2815 byte
|= (((value
>> shift
) & ((1 << this_time
) - 1))
2816 << (BITS_PER_UNIT
- this_time
- next_bit
));
2818 /* On little-endian machines,
2819 take first the least significant bits of the value
2820 and pack them starting at the least significant
2821 bits of the bytes. */
2822 shift
= (next_offset
2823 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
2824 /* Don't try to take a bunch of bits that cross
2825 the word boundary in the INTEGER_CST. */
2826 if (shift
< HOST_BITS_PER_INT
2827 && shift
+ this_time
> HOST_BITS_PER_INT
)
2829 this_time
-= (HOST_BITS_PER_INT
- shift
);
2830 shift
= HOST_BITS_PER_INT
;
2833 /* Now get the bits from the appropriate constant word. */
2834 if (shift
< HOST_BITS_PER_INT
)
2835 value
= TREE_INT_CST_LOW (val
);
2836 else if (shift
< 2 * HOST_BITS_PER_INT
)
2838 value
= TREE_INT_CST_HIGH (val
);
2839 shift
-= HOST_BITS_PER_INT
;
2843 byte
|= ((value
>> shift
) & ((1 << this_time
) - 1)) << next_bit
;
2845 next_offset
+= this_time
;
2846 byte_buffer_in_use
= 1;
2850 if (byte_buffer_in_use
)
2852 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2855 if (total_bytes
< size
)
2856 assemble_zeros (size
- total_bytes
);