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
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 ();
85 void readonly_data_section ();
89 static enum in_section
{no_section
, in_text
, in_data
, EXTRA_SECTIONS
} in_section
92 static enum in_section
{no_section
, in_text
, in_data
} in_section
96 /* Define functions like text_section for any extra sections. */
97 #ifdef EXTRA_SECTION_FUNCTIONS
98 EXTRA_SECTION_FUNCTIONS
101 /* Tell assembler to switch to text section. */
106 if (in_section
!= in_text
)
108 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
109 in_section
= in_text
;
113 /* Tell assembler to switch to data section. */
118 if (in_section
!= in_data
)
120 if (flag_shared_data
)
122 #ifdef SHARED_SECTION_ASM_OP
123 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
125 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
129 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
131 in_section
= in_data
;
135 /* Tell assembler to switch to read-only data section. This is normally
139 readonly_data_section ()
141 #ifdef READONLY_DATA_SECTION
142 READONLY_DATA_SECTION (); /* Note this can call data_section. */
148 /* Determine if we're in the text section. */
153 return in_section
== in_text
;
156 /* Create the rtl to represent a function, for a function definition.
157 DECL is a FUNCTION_DECL node which describes which function.
158 The rtl is stored into DECL. */
161 make_function_rtl (decl
)
164 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
166 /* Rename a nested function to avoid conflicts. */
167 if (decl_function_context (decl
) != 0
168 && DECL_INITIAL (decl
) != 0
169 && DECL_RTL (decl
) == 0)
173 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
174 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
175 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
179 if (DECL_RTL (decl
) == 0)
182 = gen_rtx (MEM
, DECL_MODE (decl
),
183 gen_rtx (SYMBOL_REF
, Pmode
, name
));
185 /* Optionally set flags or add text to the name to record information
186 such as that it is a function name. If the name is changed, the macro
187 ASM_OUTPUT_LABELREF will have to know how to strip this information.
188 And if it finds a * at the beginning after doing so, it must handle
190 #ifdef ENCODE_SECTION_INFO
191 ENCODE_SECTION_INFO (decl
);
195 /* Record at least one function has been defined. */
196 function_defined
= 1;
199 /* Given NAME, a putative register name, discard any customary prefixes. */
202 strip_reg_name (name
)
205 #ifdef REGISTER_PREFIX
206 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
207 name
+= strlen (REGISTER_PREFIX
);
209 if (name
[0] == '%' || name
[0] == '#')
214 /* Decode an `asm' spec for a declaration as a register name.
215 Return the register number, or -1 if nothing specified,
216 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
217 or -3 if ASMSPEC is `cc' and is not recognized,
218 or -4 if ASMSPEC is `memory' and is not recognized.
219 Accept an exact spelling or a decimal number.
220 Prefixes such as % are optional. */
223 decode_reg_name (asmspec
)
230 /* Get rid of confusing prefixes. */
231 asmspec
= strip_reg_name (asmspec
);
233 /* Allow a decimal number as a "register name". */
234 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
235 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
237 if (asmspec
[0] != 0 && i
< 0)
240 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
246 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
248 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
251 #ifdef ADDITIONAL_REGISTER_NAMES
253 static struct { char *name
; int number
; } table
[]
254 = ADDITIONAL_REGISTER_NAMES
;
256 for (i
= 0; i
< sizeof (table
) / sizeof (table
[0]); i
++)
257 if (! strcmp (asmspec
, table
[i
].name
))
258 return table
[i
].number
;
260 #endif /* ADDITIONAL_REGISTER_NAMES */
262 if (!strcmp (asmspec
, "memory"))
265 if (!strcmp (asmspec
, "cc"))
274 /* Create the DECL_RTL for a declaration for a static or external variable
275 or static or external function.
276 ASMSPEC, if not 0, is the string which the user specified
277 as the assembler symbol name.
278 TOP_LEVEL is nonzero if this is a file-scope variable.
280 This is never called for PARM_DECL nodes. */
283 make_decl_rtl (decl
, asmspec
, top_level
)
289 int reg_number
= decode_reg_name (asmspec
);
291 if (DECL_ASSEMBLER_NAME (decl
) != NULL_TREE
)
292 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
294 if (reg_number
== -2)
296 /* ASMSPEC is given, and not the name of a register. */
297 name
= (char *) obstack_alloc (saveable_obstack
,
298 strlen (asmspec
) + 2);
300 strcpy (&name
[1], asmspec
);
303 /* For a duplicate declaration, we can be called twice on the
304 same DECL node. Don't alter the RTL already made
305 unless the old mode is wrong (which can happen when
306 the previous rtl was made when the type was incomplete). */
307 if (DECL_RTL (decl
) == 0
308 || GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
312 /* First detect errors in declaring global registers. */
313 if (DECL_REGISTER (decl
) && reg_number
== -1)
314 error_with_decl (decl
,
315 "register name not specified for `%s'");
316 else if (DECL_REGISTER (decl
) && reg_number
< 0)
317 error_with_decl (decl
,
318 "invalid register name for `%s'");
319 else if ((reg_number
>= 0 || reg_number
== -3) && ! DECL_REGISTER (decl
))
320 error_with_decl (decl
,
321 "register name given for non-register variable `%s'");
322 else if (DECL_REGISTER (decl
) && TREE_CODE (decl
) == FUNCTION_DECL
)
323 error ("function declared `register'");
324 else if (DECL_REGISTER (decl
) && TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
325 error_with_decl (decl
, "data type of `%s' isn't suitable for a register");
326 /* Now handle properly declared static register variables. */
327 else if (DECL_REGISTER (decl
))
330 #if 0 /* yylex should print the warning for this */
332 pedwarn ("ANSI C forbids global register variables");
334 if (DECL_INITIAL (decl
) != 0 && top_level
)
336 DECL_INITIAL (decl
) = 0;
337 error ("global register variable has initial value");
339 if (fixed_regs
[reg_number
] == 0
340 && function_defined
&& top_level
)
341 error ("global register variable follows a function definition");
342 if (TREE_THIS_VOLATILE (decl
))
343 warning ("volatile register variables don't work as you might wish");
344 DECL_RTL (decl
) = gen_rtx (REG
, DECL_MODE (decl
), reg_number
);
345 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
349 /* Make this register fixed, so not usable for anything else. */
350 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
352 global_regs
[reg_number
+ --nregs
] = 1;
357 /* Now handle ordinary static variables and functions (in memory).
358 Also handle vars declared register invalidly. */
359 if (DECL_RTL (decl
) == 0)
361 /* Can't use just the variable's own name for a variable
362 whose scope is less than the whole file.
363 Concatenate a distinguishing number. */
364 if (!top_level
&& !DECL_EXTERNAL (decl
) && asmspec
== 0)
368 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
369 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
373 DECL_RTL (decl
) = gen_rtx (MEM
, DECL_MODE (decl
),
374 gen_rtx (SYMBOL_REF
, Pmode
, name
));
375 if (TREE_THIS_VOLATILE (decl
))
376 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
377 if (TREE_READONLY (decl
))
378 RTX_UNCHANGING_P (DECL_RTL (decl
)) = 1;
379 MEM_IN_STRUCT_P (DECL_RTL (decl
))
380 = (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
381 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
382 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
);
384 /* Optionally set flags or add text to the name to record information
385 such as that it is a function name.
386 If the name is changed, the macro ASM_OUTPUT_LABELREF
387 will have to know how to strip this information.
388 And if it finds a * at the beginning after doing so,
389 it must handle that too. */
390 #ifdef ENCODE_SECTION_INFO
391 ENCODE_SECTION_INFO (decl
);
397 /* Make the rtl for variable VAR be volatile.
398 Use this only for static variables. */
400 make_var_volatile (var
)
403 if (GET_CODE (DECL_RTL (var
)) != MEM
)
406 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
409 /* Output a string of literal assembler code
410 for an `asm' keyword used between functions. */
413 assemble_asm (string
)
418 if (TREE_CODE (string
) == ADDR_EXPR
)
419 string
= TREE_OPERAND (string
, 0);
421 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
424 #if 0 /* This should no longer be needed, because
425 flag_gnu_linker should be 0 on these systems,
426 which should prevent any output
427 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
428 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
429 #ifndef ASM_OUTPUT_CONSTRUCTOR
430 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
432 #ifndef ASM_OUTPUT_DESTRUCTOR
433 #define ASM_OUTPUT_DESTRUCTOR(file, name)
438 /* Record an element in the table of global destructors.
439 How this is done depends on what sort of assembler and linker
442 NAME should be the name of a global function to be called
443 at exit time. This name is output using assemble_name. */
446 assemble_destructor (name
)
449 #ifdef ASM_OUTPUT_DESTRUCTOR
450 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
454 /* Now tell GNU LD that this is part of the static destructor set. */
455 /* This code works for any machine provided you use GNU as/ld. */
456 fprintf (asm_out_file
, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
457 assemble_name (asm_out_file
, name
);
458 fputc ('\n', asm_out_file
);
463 /* Likewise for global constructors. */
466 assemble_constructor (name
)
469 #ifdef ASM_OUTPUT_CONSTRUCTOR
470 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
474 /* Now tell GNU LD that this is part of the static constructor set. */
475 /* This code works for any machine provided you use GNU as/ld. */
476 fprintf (asm_out_file
, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
477 assemble_name (asm_out_file
, name
);
478 fputc ('\n', asm_out_file
);
483 /* Likewise for entries we want to record for garbage collection.
484 Garbage collection is still under development. */
487 assemble_gc_entry (name
)
490 #ifdef ASM_OUTPUT_GC_ENTRY
491 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
495 /* Now tell GNU LD that this is part of the static constructor set. */
496 fprintf (asm_out_file
, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
497 assemble_name (asm_out_file
, name
);
498 fputc ('\n', asm_out_file
);
503 /* Output assembler code for the constant pool of a function and associated
504 with defining the name of the function. DECL describes the function.
505 NAME is the function's name. For the constant pool, we use the current
506 constant pool data. */
509 assemble_start_function (decl
, fnname
)
515 /* The following code does not need preprocessing in the assembler. */
519 output_constant_pool (fnname
, decl
);
524 /* Tell assembler to move to target machine's alignment for functions. */
525 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
527 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
529 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
530 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
533 #ifdef SDB_DEBUGGING_INFO
534 /* Output SDB definition of the function. */
535 if (write_symbols
== SDB_DEBUG
)
536 sdbout_mark_begin_function ();
539 #ifdef DBX_DEBUGGING_INFO
540 /* Output DBX definition of the function. */
541 if (write_symbols
== DBX_DEBUG
)
542 dbxout_begin_function (decl
);
545 /* Make function name accessible from other files, if appropriate. */
547 if (TREE_PUBLIC (decl
))
549 if (!first_global_object_name
)
550 first_global_object_name
= fnname
+ (fnname
[0] == '*');
551 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
554 /* Do any machine/system dependent processing of the function name */
555 #ifdef ASM_DECLARE_FUNCTION_NAME
556 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
558 /* Standard thing is just output label for the function. */
559 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
560 #endif /* ASM_DECLARE_FUNCTION_NAME */
563 /* Output assembler code associated with defining the size of the
564 function. DECL describes the function. NAME is the function's name. */
567 assemble_end_function (decl
, fnname
)
571 #ifdef ASM_DECLARE_FUNCTION_SIZE
572 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
576 /* Assemble code to leave SIZE bytes of zeros. */
579 assemble_zeros (size
)
582 #ifdef ASM_NO_SKIP_IN_TEXT
583 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
584 so we must output 0s explicitly in the text section. */
585 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
589 for (i
= 0; i
< size
- 20; i
+= 20)
592 fprintf (asm_out_file
,
593 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP
);
595 fprintf (asm_out_file
,
596 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
602 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
604 fprintf (asm_out_file
, "\tbyte 0");
607 for (; i
< size
; i
++)
608 fprintf (asm_out_file
, ",0");
609 fprintf (asm_out_file
, "\n");
614 ASM_OUTPUT_SKIP (asm_out_file
, size
);
617 /* Assemble a string constant with the specified C string as contents. */
620 assemble_string (p
, size
)
628 /* If the string is very long, split it up. */
632 int thissize
= size
- pos
;
633 if (thissize
> maximum
)
636 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
643 /* Assemble everything that is needed for a variable or function declaration.
644 Not used for automatic variables, and not used for function definitions.
645 Should not be called for variables of incomplete structure type.
647 TOP_LEVEL is nonzero if this variable has file scope.
648 AT_END is nonzero if this is the special handling, at end of compilation,
649 to define things that have had only tentative definitions. */
652 assemble_variable (decl
, top_level
, at_end
)
662 if (GET_CODE (DECL_RTL (decl
)) == REG
)
664 /* Do output symbol info for global register variables, but do nothing
667 if (TREE_ASM_WRITTEN (decl
))
669 TREE_ASM_WRITTEN (decl
) = 1;
671 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
672 /* File-scope global variables are output here. */
673 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
675 dbxout_symbol (decl
, 0);
677 #ifdef SDB_DEBUGGING_INFO
678 if (write_symbols
== SDB_DEBUG
&& top_level
679 /* Leave initialized global vars for end of compilation;
680 see comment in compile_file. */
681 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
682 sdbout_symbol (decl
, 0);
685 /* Don't output any DWARF debugging information for variables here.
686 In the case of local variables, the information for them is output
687 when we do our recursive traversal of the tree representation for
688 the entire containing function. In the case of file-scope variables,
689 we output information for all of them at the very end of compilation
690 while we are doing our final traversal of the chain of file-scope
696 /* Normally no need to say anything for external references,
697 since assembler considers all undefined symbols external. */
699 if (DECL_EXTERNAL (decl
))
702 /* Output no assembler code for a function declaration.
703 Only definitions of functions output anything. */
705 if (TREE_CODE (decl
) == FUNCTION_DECL
)
708 /* If type was incomplete when the variable was declared,
709 see if it is complete now. */
711 if (DECL_SIZE (decl
) == 0)
712 layout_decl (decl
, 0);
714 /* Still incomplete => don't allocate it; treat the tentative defn
715 (which is what it must have been) as an `extern' reference. */
717 if (DECL_SIZE (decl
) == 0)
719 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
720 DECL_SOURCE_LINE (decl
),
721 "storage size of static var `%s' isn't known",
722 IDENTIFIER_POINTER (DECL_NAME (decl
)));
726 /* The first declaration of a variable that comes through this function
727 decides whether it is global (in C, has external linkage)
728 or local (in C, has internal linkage). So do nothing more
729 if this function has already run. */
731 if (TREE_ASM_WRITTEN (decl
))
734 TREE_ASM_WRITTEN (decl
) = 1;
736 #ifdef DBX_DEBUGGING_INFO
737 /* File-scope global variables are output here. */
738 if (write_symbols
== DBX_DEBUG
&& top_level
)
739 dbxout_symbol (decl
, 0);
741 #ifdef SDB_DEBUGGING_INFO
742 if (write_symbols
== SDB_DEBUG
&& top_level
743 /* Leave initialized global vars for end of compilation;
744 see comment in compile_file. */
745 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
746 sdbout_symbol (decl
, 0);
749 /* Don't output any DWARF debugging information for variables here.
750 In the case of local variables, the information for them is output
751 when we do our recursive traversal of the tree representation for
752 the entire containing function. In the case of file-scope variables,
753 we output information for all of them at the very end of compilation
754 while we are doing our final traversal of the chain of file-scope
757 /* If storage size is erroneously variable, just continue.
758 Error message was already made. */
760 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
765 /* This is better than explicit arithmetic, since it avoids overflow. */
766 size_tree
= size_binop (CEIL_DIV_EXPR
,
767 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
769 if (TREE_INT_CST_HIGH (size_tree
) != 0)
771 error_with_decl (decl
, "size of variable `%s' is too large");
775 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
777 /* Handle uninitialized definitions. */
779 /* ANSI specifies that a tentative definition which is not merged with
780 a non-tentative definition behaves exactly like a definition with an
781 initializer equal to zero. (Section 3.7.2)
782 -fno-common gives strict ANSI behavior. Usually you don't want it. */
784 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
786 int size
= TREE_INT_CST_LOW (size_tree
);
789 if (TREE_INT_CST_HIGH (size_tree
) != 0)
790 error_with_decl (decl
, "size of variable `%s' is too large");
791 /* Don't allocate zero bytes of common,
792 since that means "undefined external" in the linker. */
793 if (size
== 0) rounded
= 1;
794 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
795 so that each uninitialized object starts on such a boundary. */
796 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
797 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
798 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
800 if (flag_shared_data
)
803 if (TREE_PUBLIC (decl
))
805 #ifdef ASM_OUTPUT_SHARED_COMMON
806 if (flag_shared_data
)
807 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
810 #ifdef ASM_OUTPUT_ALIGNED_COMMON
811 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
814 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
819 #ifdef ASM_OUTPUT_SHARED_LOCAL
820 if (flag_shared_data
)
821 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
824 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
825 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
828 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
834 /* Handle initialized definitions. */
836 /* First make the assembler name(s) global if appropriate. */
837 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
839 if (!first_global_object_name
)
840 first_global_object_name
= name
+ (name
[0] == '*');
841 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
844 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
846 tree e
= TREE_VALUE (d
);
847 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
848 ASM_GLOBALIZE_LABEL (asm_out_file
,
849 XSTR (XEXP (DECL_RTL (e
), 0), 0));
853 /* Output any data that we will need to use the address of. */
854 if (DECL_INITIAL (decl
))
855 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
857 /* Switch to the proper section for this data. */
858 #ifdef SELECT_SECTION
859 SELECT_SECTION (decl
, reloc
);
861 if (TREE_READONLY (decl
)
862 && ! TREE_THIS_VOLATILE (decl
)
863 && ! (flag_pic
&& reloc
))
864 readonly_data_section ();
869 /* Compute and output the alignment of this data. */
871 align
= DECL_ALIGN (decl
);
872 /* Some object file formats have a maximum alignment which they support.
873 In particular, a.out format supports a maximum alignment of 4. */
874 #ifndef MAX_OFILE_ALIGNMENT
875 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
877 if (align
> MAX_OFILE_ALIGNMENT
)
879 warning_with_decl (decl
,
880 "alignment of `%s' is greater than maximum object file alignment");
881 align
= MAX_OFILE_ALIGNMENT
;
883 #ifdef DATA_ALIGNMENT
884 /* On some machines, it is good to increase alignment sometimes. */
885 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
887 #ifdef CONSTANT_ALIGNMENT
888 if (DECL_INITIAL (decl
))
889 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
892 /* Reset the alignment in case we have made it tighter, so we can benefit
893 from it in get_pointer_alignment. */
894 DECL_ALIGN (decl
) = align
;
896 if (align
> BITS_PER_UNIT
)
897 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
899 /* Do any machine/system dependent processing of the object. */
900 #ifdef ASM_DECLARE_OBJECT_NAME
901 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
903 /* Standard thing is just output label for the object. */
904 ASM_OUTPUT_LABEL (asm_out_file
, name
);
905 #endif /* ASM_DECLARE_OBJECT_NAME */
908 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
910 tree e
= TREE_VALUE (d
);
911 ASM_OUTPUT_LABEL (asm_out_file
, XSTR (XEXP (DECL_RTL (e
), 0), 0));
915 if (DECL_INITIAL (decl
))
916 /* Output the actual data. */
917 output_constant (DECL_INITIAL (decl
),
918 int_size_in_bytes (TREE_TYPE (decl
)));
920 /* Leave space for it. */
921 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl
)));
924 #ifdef XCOFF_DEBUGGING_INFO
925 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
926 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
927 and `aa' hasn't been output yet, the assembler generates a stab entry with
928 a value of zero, in addition to creating an unnecessary external entry
929 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
931 /* File-scope global variables are output here. */
932 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
933 dbxout_symbol (decl
, 0);
935 /* There must be a statement after a label. */
940 /* Output something to declare an external symbol to the assembler.
941 (Most assemblers don't need this, so we normally output nothing.)
942 Do nothing if DECL is not external. */
945 assemble_external (decl
)
948 #ifdef ASM_OUTPUT_EXTERNAL
949 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
950 && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
952 rtx rtl
= DECL_RTL (decl
);
954 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
955 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
957 /* Some systems do require some output. */
958 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
959 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
965 /* Similar, for calling a library function FUN. */
968 assemble_external_libcall (fun
)
971 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
972 /* Declare library function name external when first used, if nec. */
973 if (! SYMBOL_REF_USED (fun
))
975 SYMBOL_REF_USED (fun
) = 1;
976 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
981 /* Declare the label NAME global. */
984 assemble_global (name
)
987 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
990 /* Assemble a label named NAME. */
993 assemble_label (name
)
996 ASM_OUTPUT_LABEL (asm_out_file
, name
);
999 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1000 If NAME starts with a *, the rest of NAME is output verbatim.
1001 Otherwise NAME is transformed in an implementation-defined way
1002 (usually by the addition of an underscore).
1003 Many macros in the tm file are defined to call this function. */
1006 assemble_name (file
, name
)
1011 fputs (&name
[1], file
);
1013 ASM_OUTPUT_LABELREF (file
, name
);
1016 /* Allocate SIZE bytes writable static space with a gensym name
1017 and return an RTX to refer to its address. */
1020 assemble_static_space (size
)
1026 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1027 so that each uninitialized object starts on such a boundary. */
1028 int rounded
= ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1029 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1030 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1033 if (flag_shared_data
)
1037 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1040 namestring
= (char *) obstack_alloc (saveable_obstack
,
1042 strcpy (namestring
, name
);
1044 x
= gen_rtx (SYMBOL_REF
, Pmode
, namestring
);
1045 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1046 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1048 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1053 /* Assemble the static constant template for function entry trampolines.
1054 This is done at most once per compilation.
1055 Returns an RTX for the address of the template. */
1058 assemble_trampoline_template ()
1064 /* Write the assembler code to define one. */
1065 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1067 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1069 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1070 TRAMPOLINE_TEMPLATE (asm_out_file
);
1072 /* Record the rtl to refer to it. */
1073 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1075 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1076 return gen_rtx (SYMBOL_REF
, Pmode
, name
);
1079 /* Assemble the integer constant X into an object of SIZE bytes.
1080 X must be either a CONST_INT or CONST_DOUBLE.
1082 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1083 non-zero, abort if we can't output the constant. */
1086 assemble_integer (x
, size
, force
)
1091 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1092 ASM_OUTPUT... macros. */
1096 #ifdef ASM_OUTPUT_CHAR
1098 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1102 #ifdef ASM_OUTPUT_SHORT
1104 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1108 #ifdef ASM_OUTPUT_INT
1110 ASM_OUTPUT_INT (asm_out_file
, x
);
1114 #ifdef ASM_OUTPUT_DOUBLE_INT
1116 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1120 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1122 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1127 /* If we couldn't do it that way, there are two other possibilities: First,
1128 if the machine can output an explicit byte and this is a 1 byte constant,
1129 we can use ASM_OUTPUT_BYTE. */
1131 #ifdef ASM_OUTPUT_BYTE
1132 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1134 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1139 /* Finally, if SIZE is larger than a single word, try to output the constant
1140 one word at a time. */
1142 if (size
> UNITS_PER_WORD
)
1145 enum machine_mode mode
1146 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1149 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1151 word
= operand_subword (x
, i
, 0, mode
);
1156 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1160 if (i
== size
/ UNITS_PER_WORD
)
1162 /* If we output at least one word and then could not finish,
1163 there is no valid way to continue. */
1174 /* Assemble the floating-point constant D into an object of size MODE. */
1177 assemble_real (d
, mode
)
1179 enum machine_mode mode
;
1181 jmp_buf output_constant_handler
;
1183 if (setjmp (output_constant_handler
))
1185 error ("floating point trap outputting a constant");
1186 #ifdef REAL_IS_NOT_DOUBLE
1187 bzero (&d
, sizeof d
);
1194 set_float_handler (output_constant_handler
);
1198 #ifdef ASM_OUTPUT_FLOAT
1200 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1204 #ifdef ASM_OUTPUT_DOUBLE
1206 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1210 #ifdef ASM_OUTPUT_LONG_DOUBLE
1212 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1220 set_float_handler (NULL_PTR
);
1223 /* Here we combine duplicate floating constants to make
1224 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1226 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1227 They are chained through the CONST_DOUBLE_CHAIN.
1228 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1229 In that case, CONST_DOUBLE_MEM is either a MEM,
1230 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
1232 static rtx const_double_chain
;
1234 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1235 For an integer, I0 is the low-order word and I1 is the high-order word.
1236 For a real number, I0 is the word with the low address
1237 and I1 is the word with the high address. */
1240 immed_double_const (i0
, i1
, mode
)
1241 HOST_WIDE_INT i0
, i1
;
1242 enum machine_mode mode
;
1245 int in_current_obstack
;
1247 if (GET_MODE_CLASS (mode
) == MODE_INT
)
1249 /* We clear out all bits that don't belong in MODE, unless they and our
1250 sign bit are all one. So we get either a reasonable negative value
1251 or a reasonable unsigned value for this mode. */
1252 int width
= GET_MODE_BITSIZE (mode
);
1253 if (width
< HOST_BITS_PER_WIDE_INT
1254 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
1255 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
1256 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
1257 else if (width
== HOST_BITS_PER_WIDE_INT
1258 && ! (i1
== ~0 && i0
< 0))
1260 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
1261 /* We cannot represent this value as a constant. */
1264 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1266 ??? Strictly speaking, this is wrong if we create a CONST_INT
1267 for a large unsigned constant with the size of MODE being
1268 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1269 wider mode. In that case we will mis-interpret it as a negative
1272 Unfortunately, the only alternative is to make a CONST_DOUBLE
1273 for any constant in any mode if it is an unsigned constant larger
1274 than the maximum signed integer in an int on the host. However,
1275 doing this will break everyone that always expects to see a CONST_INT
1276 for SImode and smaller.
1278 We have always been making CONST_INTs in this case, so nothing new
1281 if (width
<= HOST_BITS_PER_WIDE_INT
)
1282 i1
= (i0
< 0) ? ~0 : 0;
1284 /* If this integer fits in one word, return a CONST_INT. */
1285 if ((i1
== 0 && i0
>= 0)
1286 || (i1
== ~0 && i0
< 0))
1287 return GEN_INT (i0
);
1289 /* We use VOIDmode for integers. */
1293 /* Search the chain for an existing CONST_DOUBLE with the right value.
1294 If one is found, return it. */
1296 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1297 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
1298 && GET_MODE (r
) == mode
)
1301 /* No; make a new one and add it to the chain.
1303 We may be called by an optimizer which may be discarding any memory
1304 allocated during its processing (such as combine and loop). However,
1305 we will be leaving this constant on the chain, so we cannot tolerate
1306 freed memory. So switch to saveable_obstack for this allocation
1307 and then switch back if we were in current_obstack. */
1309 in_current_obstack
= rtl_in_saveable_obstack ();
1310 r
= gen_rtx (CONST_DOUBLE
, mode
, 0, i0
, i1
);
1311 if (in_current_obstack
)
1312 rtl_in_current_obstack ();
1314 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1315 const_double_chain
= r
;
1317 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1318 Actual use of mem-slot is only through force_const_mem. */
1320 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1325 /* Return a CONST_DOUBLE for a specified `double' value
1326 and machine mode. */
1329 immed_real_const_1 (d
, mode
)
1331 enum machine_mode mode
;
1333 union real_extract u
;
1335 int in_current_obstack
;
1337 /* Get the desired `double' value as a sequence of ints
1338 since that is how they are stored in a CONST_DOUBLE. */
1342 /* Detect special cases. */
1344 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1345 if (!bcmp (&dconst0
, &d
, sizeof d
))
1346 return CONST0_RTX (mode
);
1347 else if (REAL_VALUES_EQUAL (dconst1
, d
))
1348 return CONST1_RTX (mode
);
1350 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
1351 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
1353 /* The rest of this function handles the case where
1354 a float value requires more than 2 ints of space.
1355 It will be deleted as dead code on machines that don't need it. */
1357 /* Search the chain for an existing CONST_DOUBLE with the right value.
1358 If one is found, return it. */
1360 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1361 if (! bcmp (&CONST_DOUBLE_LOW (r
), &u
, sizeof u
)
1362 && GET_MODE (r
) == mode
)
1365 /* No; make a new one and add it to the chain.
1367 We may be called by an optimizer which may be discarding any memory
1368 allocated during its processing (such as combine and loop). However,
1369 we will be leaving this constant on the chain, so we cannot tolerate
1370 freed memory. So switch to saveable_obstack for this allocation
1371 and then switch back if we were in current_obstack. */
1373 in_current_obstack
= rtl_in_saveable_obstack ();
1374 r
= rtx_alloc (CONST_DOUBLE
);
1376 bcopy (&u
, &CONST_DOUBLE_LOW (r
), sizeof u
);
1377 if (in_current_obstack
)
1378 rtl_in_current_obstack ();
1380 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1381 const_double_chain
= r
;
1383 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1384 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1385 is only through force_const_mem. */
1387 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1392 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1393 which must be a REAL_CST tree node. */
1396 immed_real_const (exp
)
1399 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
1402 /* At the end of a function, forget the memory-constants
1403 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1404 Also clear out real_constant_chain and clear out all the chain-pointers. */
1407 clear_const_double_mem ()
1409 register rtx r
, next
;
1411 for (r
= const_double_chain
; r
; r
= next
)
1413 next
= CONST_DOUBLE_CHAIN (r
);
1414 CONST_DOUBLE_CHAIN (r
) = 0;
1415 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
1417 const_double_chain
= 0;
1420 /* Given an expression EXP with a constant value,
1421 reduce it to the sum of an assembler symbol and an integer.
1422 Store them both in the structure *VALUE.
1423 Abort if EXP does not reduce. */
1432 decode_addr_const (exp
, value
)
1434 struct addr_const
*value
;
1436 register tree target
= TREE_OPERAND (exp
, 0);
1437 register int offset
= 0;
1442 if (TREE_CODE (target
) == COMPONENT_REF
1443 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
1446 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
1447 target
= TREE_OPERAND (target
, 0);
1449 else if (TREE_CODE (target
) == ARRAY_REF
)
1451 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
1452 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
1454 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
1455 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
1457 target
= TREE_OPERAND (target
, 0);
1463 switch (TREE_CODE (target
))
1467 x
= DECL_RTL (target
);
1471 x
= gen_rtx (MEM
, FUNCTION_MODE
,
1472 gen_rtx (LABEL_REF
, VOIDmode
,
1473 label_rtx (TREE_OPERAND (exp
, 0))));
1480 x
= TREE_CST_RTL (target
);
1487 if (GET_CODE (x
) != MEM
)
1492 value
->offset
= offset
;
1495 /* Uniquize all constants that appear in memory.
1496 Each constant in memory thus far output is recorded
1497 in `const_hash_table' with a `struct constant_descriptor'
1498 that contains a polish representation of the value of
1501 We cannot store the trees in the hash table
1502 because the trees may be temporary. */
1504 struct constant_descriptor
1506 struct constant_descriptor
*next
;
1512 #define MAX_HASH_TABLE 1009
1513 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
1515 /* Compute a hash code for a constant expression. */
1522 register int len
, hi
, i
;
1523 register enum tree_code code
= TREE_CODE (exp
);
1525 if (code
== INTEGER_CST
)
1527 p
= (char *) &TREE_INT_CST_LOW (exp
);
1528 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1530 else if (code
== REAL_CST
)
1532 p
= (char *) &TREE_REAL_CST (exp
);
1533 len
= sizeof TREE_REAL_CST (exp
);
1535 else if (code
== STRING_CST
)
1536 p
= TREE_STRING_POINTER (exp
), len
= TREE_STRING_LENGTH (exp
);
1537 else if (code
== COMPLEX_CST
)
1538 return const_hash (TREE_REALPART (exp
)) * 5
1539 + const_hash (TREE_IMAGPART (exp
));
1540 else if (code
== CONSTRUCTOR
)
1544 /* For record type, include the type in the hashing.
1545 We do not do so for array types
1546 because (1) the sizes of the elements are sufficient
1547 and (2) distinct array types can have the same constructor.
1548 Instead, we include the array size because the constructor could
1550 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1551 hi
= ((int) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
1553 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
1554 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
1556 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1557 if (TREE_VALUE (link
))
1558 hi
= (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
1562 else if (code
== ADDR_EXPR
)
1564 struct addr_const value
;
1565 decode_addr_const (exp
, &value
);
1566 if (GET_CODE (value
.base
) == SYMBOL_REF
)
1568 /* Don't hash the address of the SYMBOL_REF;
1569 only use the offset and the symbol name. */
1571 p
= XSTR (value
.base
, 0);
1572 for (i
= 0; p
[i
] != 0; i
++)
1573 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
1575 else if (GET_CODE (value
.base
) == LABEL_REF
)
1576 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
1578 hi
&= (1 << HASHBITS
) - 1;
1579 hi
%= MAX_HASH_TABLE
;
1582 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1583 return const_hash (TREE_OPERAND (exp
, 0)) * 9
1584 + const_hash (TREE_OPERAND (exp
, 1));
1585 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1586 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
1588 /* Compute hashing function */
1590 for (i
= 0; i
< len
; i
++)
1591 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
1593 hi
&= (1 << HASHBITS
) - 1;
1594 hi
%= MAX_HASH_TABLE
;
1598 /* Compare a constant expression EXP with a constant-descriptor DESC.
1599 Return 1 if DESC describes a constant with the same value as EXP. */
1602 compare_constant (exp
, desc
)
1604 struct constant_descriptor
*desc
;
1606 return 0 != compare_constant_1 (exp
, desc
->contents
);
1609 /* Compare constant expression EXP with a substring P of a constant descriptor.
1610 If they match, return a pointer to the end of the substring matched.
1611 If they do not match, return 0.
1613 Since descriptors are written in polish prefix notation,
1614 this function can be used recursively to test one operand of EXP
1615 against a subdescriptor, and if it succeeds it returns the
1616 address of the subdescriptor for the next operand. */
1619 compare_constant_1 (exp
, p
)
1623 register char *strp
;
1625 register enum tree_code code
= TREE_CODE (exp
);
1627 if (code
!= (enum tree_code
) *p
++)
1630 if (code
== INTEGER_CST
)
1632 /* Integer constants are the same only if the same width of type. */
1633 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
1635 strp
= (char *) &TREE_INT_CST_LOW (exp
);
1636 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1638 else if (code
== REAL_CST
)
1640 /* Real constants are the same only if the same width of type. */
1641 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
1643 strp
= (char *) &TREE_REAL_CST (exp
);
1644 len
= sizeof TREE_REAL_CST (exp
);
1646 else if (code
== STRING_CST
)
1648 if (flag_writable_strings
)
1650 strp
= TREE_STRING_POINTER (exp
);
1651 len
= TREE_STRING_LENGTH (exp
);
1652 if (bcmp (&TREE_STRING_LENGTH (exp
), p
,
1653 sizeof TREE_STRING_LENGTH (exp
)))
1655 p
+= sizeof TREE_STRING_LENGTH (exp
);
1657 else if (code
== COMPLEX_CST
)
1659 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
1660 if (p
== 0) return 0;
1661 p
= compare_constant_1 (TREE_IMAGPART (exp
), p
);
1664 else if (code
== CONSTRUCTOR
)
1667 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
1670 if (bcmp (&length
, p
, sizeof length
))
1674 /* For record constructors, insist that the types match.
1675 For arrays, just verify both constructors are for arrays. */
1676 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1677 type
= TREE_TYPE (exp
);
1680 if (bcmp (&type
, p
, sizeof type
))
1684 /* For arrays, insist that the size in bytes match. */
1685 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1687 int size
= int_size_in_bytes (TREE_TYPE (exp
));
1688 if (bcmp (&size
, p
, sizeof size
))
1693 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1695 if (TREE_VALUE (link
))
1697 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
1704 if (bcmp (&zero
, p
, sizeof zero
))
1712 else if (code
== ADDR_EXPR
)
1714 struct addr_const value
;
1715 decode_addr_const (exp
, &value
);
1716 strp
= (char *) &value
.offset
;
1717 len
= sizeof value
.offset
;
1718 /* Compare the offset. */
1720 if (*p
++ != *strp
++)
1722 /* Compare symbol name. */
1723 strp
= XSTR (value
.base
, 0);
1724 len
= strlen (strp
) + 1;
1726 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1728 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
1729 if (p
== 0) return 0;
1730 p
= compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
1733 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1735 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
1739 /* Compare constant contents. */
1741 if (*p
++ != *strp
++)
1747 /* Construct a constant descriptor for the expression EXP.
1748 It is up to the caller to enter the descriptor in the hash table. */
1750 static struct constant_descriptor
*
1751 record_constant (exp
)
1754 struct constant_descriptor
*ptr
= 0;
1757 obstack_grow (&permanent_obstack
, &ptr
, sizeof ptr
);
1758 obstack_grow (&permanent_obstack
, &buf
, sizeof buf
);
1759 record_constant_1 (exp
);
1760 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
1763 /* Add a description of constant expression EXP
1764 to the object growing in `permanent_obstack'.
1765 No need to return its address; the caller will get that
1766 from the obstack when the object is complete. */
1769 record_constant_1 (exp
)
1772 register char *strp
;
1774 register enum tree_code code
= TREE_CODE (exp
);
1776 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
1778 if (code
== INTEGER_CST
)
1780 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
1781 strp
= (char *) &TREE_INT_CST_LOW (exp
);
1782 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
1784 else if (code
== REAL_CST
)
1786 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
1787 strp
= (char *) &TREE_REAL_CST (exp
);
1788 len
= sizeof TREE_REAL_CST (exp
);
1790 else if (code
== STRING_CST
)
1792 if (flag_writable_strings
)
1794 strp
= TREE_STRING_POINTER (exp
);
1795 len
= TREE_STRING_LENGTH (exp
);
1796 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
1797 sizeof TREE_STRING_LENGTH (exp
));
1799 else if (code
== COMPLEX_CST
)
1801 record_constant_1 (TREE_REALPART (exp
));
1802 record_constant_1 (TREE_IMAGPART (exp
));
1805 else if (code
== CONSTRUCTOR
)
1808 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
1811 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
1813 /* For record constructors, insist that the types match.
1814 For arrays, just verify both constructors are for arrays. */
1815 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
1816 type
= TREE_TYPE (exp
);
1819 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
1821 /* For arrays, insist that the size in bytes match. */
1822 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1824 int size
= int_size_in_bytes (TREE_TYPE (exp
));
1825 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
1828 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
1830 if (TREE_VALUE (link
))
1831 record_constant_1 (TREE_VALUE (link
));
1836 obstack_grow (&permanent_obstack
, (char *) &zero
, sizeof zero
);
1842 else if (code
== ADDR_EXPR
)
1844 struct addr_const value
;
1845 decode_addr_const (exp
, &value
);
1846 /* Record the offset. */
1847 obstack_grow (&permanent_obstack
,
1848 (char *) &value
.offset
, sizeof value
.offset
);
1849 /* Record the symbol name. */
1850 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
1851 strlen (XSTR (value
.base
, 0)) + 1);
1854 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
1856 record_constant_1 (TREE_OPERAND (exp
, 0));
1857 record_constant_1 (TREE_OPERAND (exp
, 1));
1860 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
1862 record_constant_1 (TREE_OPERAND (exp
, 0));
1866 /* Record constant contents. */
1867 obstack_grow (&permanent_obstack
, strp
, len
);
1870 /* Return an rtx representing a reference to constant data in memory
1871 for the constant expression EXP.
1872 If assembler code for such a constant has already been output,
1873 return an rtx to refer to it.
1874 Otherwise, output such a constant in memory and generate
1875 an rtx for it. The TREE_CST_RTL of EXP is set up to point to that rtx.
1876 The const_hash_table records which constants already have label strings. */
1879 output_constant_def (exp
)
1882 register int hash
, align
;
1883 register struct constant_descriptor
*desc
;
1889 if (TREE_CODE (exp
) == INTEGER_CST
)
1890 abort (); /* No TREE_CST_RTL slot in these. */
1892 if (TREE_CST_RTL (exp
))
1893 return TREE_CST_RTL (exp
);
1895 /* Make sure any other constants whose addresses appear in EXP
1896 are assigned label numbers. */
1898 reloc
= output_addressed_constants (exp
);
1900 /* Compute hash code of EXP. Search the descriptors for that hash code
1901 to see if any of them describes EXP. If yes, the descriptor records
1902 the label number already assigned. */
1904 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
1906 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
1907 if (compare_constant (exp
, desc
))
1909 found
= desc
->label
;
1915 /* No constant equal to EXP is known to have been output.
1916 Make a constant descriptor to enter EXP in the hash table.
1917 Assign the label number and record it in the descriptor for
1918 future calls to this function to find. */
1920 /* Create a string containing the label name, in LABEL. */
1921 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
1923 desc
= record_constant (exp
);
1924 desc
->next
= const_hash_table
[hash
];
1926 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1927 const_hash_table
[hash
] = desc
;
1930 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
1932 push_obstacks_nochange ();
1933 if (TREE_PERMANENT (exp
))
1934 end_temporary_allocation ();
1936 def
= gen_rtx (SYMBOL_REF
, Pmode
, desc
->label
);
1939 = gen_rtx (MEM
, TYPE_MODE (TREE_TYPE (exp
)), def
);
1940 RTX_UNCHANGING_P (TREE_CST_RTL (exp
)) = 1;
1941 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
1942 || TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
1943 MEM_IN_STRUCT_P (TREE_CST_RTL (exp
)) = 1;
1947 /* Optionally set flags or add text to the name to record information
1948 such as that it is a function name. If the name is changed, the macro
1949 ASM_OUTPUT_LABELREF will have to know how to strip this information.
1950 And if it finds a * at the beginning after doing so, it must handle
1952 #ifdef ENCODE_SECTION_INFO
1953 ENCODE_SECTION_INFO (exp
);
1958 /* Now output assembler code to define that label
1959 and follow it with the data of EXP. */
1961 /* First switch to text section, except for writable strings. */
1962 #ifdef SELECT_SECTION
1963 SELECT_SECTION (exp
, reloc
);
1965 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
1966 || (flag_pic
&& reloc
))
1969 readonly_data_section ();
1972 /* Align the location counter as required by EXP's data type. */
1973 align
= TYPE_ALIGN (TREE_TYPE (exp
));
1974 #ifdef CONSTANT_ALIGNMENT
1975 align
= CONSTANT_ALIGNMENT (exp
, align
);
1978 if (align
> BITS_PER_UNIT
)
1979 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1981 /* Output the label itself. */
1982 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", const_labelno
);
1984 /* Output the value of EXP. */
1985 output_constant (exp
,
1986 (TREE_CODE (exp
) == STRING_CST
1987 ? TREE_STRING_LENGTH (exp
)
1988 : int_size_in_bytes (TREE_TYPE (exp
))));
1993 return TREE_CST_RTL (exp
);
1996 /* Similar hash facility for making memory-constants
1997 from constant rtl-expressions. It is used on RISC machines
1998 where immediate integer arguments and constant addresses are restricted
1999 so that such constants must be stored in memory.
2001 This pool of constants is reinitialized for each function
2002 so each function gets its own constants-pool that comes right before it.
2004 All structures allocated here are discarded when functions are saved for
2005 inlining, so they do not need to be allocated permanently. */
2007 #define MAX_RTX_HASH_TABLE 61
2008 static struct constant_descriptor
*const_rtx_hash_table
[MAX_RTX_HASH_TABLE
];
2010 /* Structure to represent sufficient information about a constant so that
2011 it can be output when the constant pool is output, so that function
2012 integration can be done, and to simplify handling on machines that reference
2013 constant pool as base+displacement. */
2015 struct pool_constant
2017 struct constant_descriptor
*desc
;
2018 struct pool_constant
*next
;
2019 enum machine_mode mode
;
2026 /* Pointers to first and last constant in pool. */
2028 static struct pool_constant
*first_pool
, *last_pool
;
2030 /* Current offset in constant pool (does not include any machine-specific
2033 static int pool_offset
;
2035 /* Structure used to maintain hash table mapping symbols used to their
2036 corresponding constants. */
2041 struct pool_constant
*pool
;
2042 struct pool_sym
*next
;
2045 static struct pool_sym
*const_rtx_sym_hash_table
[MAX_RTX_HASH_TABLE
];
2047 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2048 The argument is XSTR (... , 0) */
2050 #define SYMHASH(LABEL) \
2051 ((((int) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2053 /* Initialize constant pool hashing for next function. */
2056 init_const_rtx_hash_table ()
2058 bzero (const_rtx_hash_table
, sizeof const_rtx_hash_table
);
2059 bzero (const_rtx_sym_hash_table
, sizeof const_rtx_sym_hash_table
);
2061 first_pool
= last_pool
= 0;
2065 enum kind
{ RTX_DOUBLE
, RTX_INT
};
2069 #ifdef ONLY_INT_FIELDS
2070 unsigned int kind
: 16;
2071 unsigned int mode
: 16;
2073 enum kind kind
: 16;
2074 enum machine_mode mode
: 16;
2077 union real_extract du
;
2078 struct addr_const addr
;
2082 /* Express an rtx for a constant integer (perhaps symbolic)
2083 as the sum of a symbol or label plus an explicit integer.
2084 They are stored into VALUE. */
2087 decode_rtx_const (mode
, x
, value
)
2088 enum machine_mode mode
;
2090 struct rtx_const
*value
;
2092 /* Clear the whole structure, including any gaps. */
2095 int *p
= (int *) value
;
2096 int *end
= (int *) (value
+ 1);
2101 value
->kind
= RTX_INT
; /* Most usual kind. */
2104 switch (GET_CODE (x
))
2107 value
->kind
= RTX_DOUBLE
;
2108 value
->mode
= GET_MODE (x
);
2109 bcopy (&CONST_DOUBLE_LOW (x
), &value
->un
.du
, sizeof value
->un
.du
);
2113 value
->un
.addr
.offset
= INTVAL (x
);
2118 value
->un
.addr
.base
= x
;
2123 if (GET_CODE (x
) == PLUS
)
2125 value
->un
.addr
.base
= XEXP (x
, 0);
2126 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
2128 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
2130 else if (GET_CODE (x
) == MINUS
)
2132 value
->un
.addr
.base
= XEXP (x
, 0);
2133 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
2135 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
2145 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
2146 switch (GET_CODE (value
->un
.addr
.base
))
2150 /* Use the string's address, not the SYMBOL_REF's address,
2151 for the sake of addresses of library routines.
2152 For a LABEL_REF, compare labels. */
2153 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
2157 /* Compute a hash code for a constant RTL expression. */
2160 const_hash_rtx (mode
, x
)
2161 enum machine_mode mode
;
2166 struct rtx_const value
;
2167 decode_rtx_const (mode
, x
, &value
);
2169 /* Compute hashing function */
2171 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
2172 hi
+= ((int *) &value
)[i
];
2174 hi
&= (1 << HASHBITS
) - 1;
2175 hi
%= MAX_RTX_HASH_TABLE
;
2179 /* Compare a constant rtl object X with a constant-descriptor DESC.
2180 Return 1 if DESC describes a constant with the same value as X. */
2183 compare_constant_rtx (mode
, x
, desc
)
2184 enum machine_mode mode
;
2186 struct constant_descriptor
*desc
;
2188 register int *p
= (int *) desc
->contents
;
2191 struct rtx_const value
;
2193 decode_rtx_const (mode
, x
, &value
);
2194 strp
= (int *) &value
;
2195 len
= sizeof value
/ sizeof (int);
2197 /* Compare constant contents. */
2199 if (*p
++ != *strp
++)
2205 /* Construct a constant descriptor for the rtl-expression X.
2206 It is up to the caller to enter the descriptor in the hash table. */
2208 static struct constant_descriptor
*
2209 record_constant_rtx (mode
, x
)
2210 enum machine_mode mode
;
2213 struct constant_descriptor
*ptr
;
2215 struct rtx_const value
;
2217 decode_rtx_const (mode
, x
, &value
);
2219 obstack_grow (current_obstack
, &ptr
, sizeof ptr
);
2220 obstack_grow (current_obstack
, &label
, sizeof label
);
2222 /* Record constant contents. */
2223 obstack_grow (current_obstack
, &value
, sizeof value
);
2225 return (struct constant_descriptor
*) obstack_finish (current_obstack
);
2228 /* Given a constant rtx X, make (or find) a memory constant for its value
2229 and return a MEM rtx to refer to it in memory. */
2232 force_const_mem (mode
, x
)
2233 enum machine_mode mode
;
2237 register struct constant_descriptor
*desc
;
2242 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2243 (this will always be true for floating CONST_DOUBLEs that have been
2244 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2245 use the previous copy. Otherwise, make a new one. Note that in
2246 the unlikely event that this same CONST_DOUBLE is used in two different
2247 modes in an alternating fashion, we will allocate a lot of different
2248 memory locations, but this should be extremely rare. */
2250 if (GET_CODE (x
) == CONST_DOUBLE
2251 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
2252 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
2253 return CONST_DOUBLE_MEM (x
);
2255 /* Compute hash code of X. Search the descriptors for that hash code
2256 to see if any of them describes X. If yes, the descriptor records
2257 the label number already assigned. */
2259 hash
= const_hash_rtx (mode
, x
);
2261 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
2262 if (compare_constant_rtx (mode
, x
, desc
))
2264 found
= desc
->label
;
2270 register struct pool_constant
*pool
;
2271 register struct pool_sym
*sym
;
2274 /* No constant equal to X is known to have been output.
2275 Make a constant descriptor to enter X in the hash table.
2276 Assign the label number and record it in the descriptor for
2277 future calls to this function to find. */
2279 desc
= record_constant_rtx (mode
, x
);
2280 desc
->next
= const_rtx_hash_table
[hash
];
2281 const_rtx_hash_table
[hash
] = desc
;
2283 /* Align the location counter as required by EXP's data type. */
2284 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
2285 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2286 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
2288 pool_offset
+= align
- 1;
2289 pool_offset
&= ~ (align
- 1);
2291 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2293 pool
= (struct pool_constant
*) oballoc (sizeof (struct pool_constant
));
2297 pool
->labelno
= const_labelno
;
2298 pool
->align
= align
;
2299 pool
->offset
= pool_offset
;
2305 last_pool
->next
= pool
;
2308 pool_offset
+= GET_MODE_SIZE (mode
);
2310 /* Create a string containing the label name, in LABEL. */
2311 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2316 = (char *) obstack_copy0 (saveable_obstack
, label
, strlen (label
));
2318 /* Add label to symbol hash table. */
2319 hash
= SYMHASH (found
);
2320 sym
= (struct pool_sym
*) oballoc (sizeof (struct pool_sym
));
2323 sym
->next
= const_rtx_sym_hash_table
[hash
];
2324 const_rtx_sym_hash_table
[hash
] = sym
;
2327 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2329 def
= gen_rtx (MEM
, mode
, gen_rtx (SYMBOL_REF
, Pmode
, found
));
2331 RTX_UNCHANGING_P (def
) = 1;
2332 /* Mark the symbol_ref as belonging to this constants pool. */
2333 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
2334 current_function_uses_const_pool
= 1;
2336 if (GET_CODE (x
) == CONST_DOUBLE
)
2338 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
2340 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
2341 const_double_chain
= x
;
2343 CONST_DOUBLE_MEM (x
) = def
;
2349 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2350 the corresponding pool_constant structure. */
2352 static struct pool_constant
*
2353 find_pool_constant (addr
)
2356 struct pool_sym
*sym
;
2357 char *label
= XSTR (addr
, 0);
2359 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
2360 if (sym
->label
== label
)
2366 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2369 get_pool_constant (addr
)
2372 return (find_pool_constant (addr
))->constant
;
2375 /* Similar, return the mode. */
2378 get_pool_mode (addr
)
2381 return (find_pool_constant (addr
))->mode
;
2384 /* Similar, return the offset in the constant pool. */
2387 get_pool_offset (addr
)
2390 return (find_pool_constant (addr
))->offset
;
2393 /* Return the size of the constant pool. */
2401 /* Write all the constants in the constant pool. */
2404 output_constant_pool (fnname
, fndecl
)
2408 struct pool_constant
*pool
;
2410 union real_extract u
;
2412 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2413 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
2416 for (pool
= first_pool
; pool
; pool
= pool
->next
)
2420 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2421 whose CODE_LABEL has been deleted. This can occur if a jump table
2422 is eliminated by optimization. If so, write a constant of zero
2424 if ((GET_CODE (x
) == LABEL_REF
&& INSN_DELETED_P (XEXP (x
, 0)))
2425 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
2426 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
2427 && INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))))
2430 /* First switch to correct section. */
2431 #ifdef SELECT_RTX_SECTION
2432 SELECT_RTX_SECTION (pool
->mode
, x
);
2434 readonly_data_section ();
2437 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2438 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
2439 pool
->align
, pool
->labelno
, done
);
2442 if (pool
->align
> 1)
2443 ASM_OUTPUT_ALIGN (asm_out_file
, exact_log2 (pool
->align
));
2445 /* Output the label. */
2446 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
2448 /* Output the value of the constant itself. */
2449 switch (GET_MODE_CLASS (pool
->mode
))
2452 if (GET_CODE (x
) != CONST_DOUBLE
)
2455 bcopy (&CONST_DOUBLE_LOW (x
), &u
, sizeof u
);
2456 assemble_real (u
.d
, pool
->mode
);
2460 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
2470 /* Done with this pool. */
2471 first_pool
= last_pool
= 0;
2474 /* Find all the constants whose addresses are referenced inside of EXP,
2475 and make sure assembler code with a label has been output for each one.
2476 Indicate whether an ADDR_EXPR has been encountered. */
2479 output_addressed_constants (exp
)
2484 switch (TREE_CODE (exp
))
2488 register tree constant
= TREE_OPERAND (exp
, 0);
2490 while (TREE_CODE (constant
) == COMPONENT_REF
)
2492 constant
= TREE_OPERAND (constant
, 0);
2495 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
2496 || TREE_CODE (constant
) == CONSTRUCTOR
)
2497 /* No need to do anything here
2498 for addresses of variables or functions. */
2499 output_constant_def (constant
);
2506 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
2507 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
2512 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
2518 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2519 if (TREE_VALUE (link
) != 0)
2520 reloc
|= output_addressed_constants (TREE_VALUE (link
));
2530 /* Output assembler code for constant EXP to FILE, with no label.
2531 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2532 Assumes output_addressed_constants has been done on EXP already.
2534 Generate exactly SIZE bytes of assembler data, padding at the end
2535 with zeros if necessary. SIZE must always be specified.
2537 SIZE is important for structure constructors,
2538 since trailing members may have been omitted from the constructor.
2539 It is also important for initialization of arrays from string constants
2540 since the full length of the string constant might not be wanted.
2541 It is also needed for initialization of unions, where the initializer's
2542 type is just one member, and that may not be as long as the union.
2544 There a case in which we would fail to output exactly SIZE bytes:
2545 for a structure constructor that wants to produce more than SIZE bytes.
2546 But such constructors will never be generated for any possible input. */
2549 output_constant (exp
, size
)
2553 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
2559 /* Allow a constructor with no elements for any data type.
2560 This means to fill the space with zeros. */
2561 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
2563 assemble_zeros (size
);
2567 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2568 That way we get the constant (we hope) inside it. */
2569 if (TREE_CODE (exp
) == NOP_EXPR
2570 && TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0)))
2571 exp
= TREE_OPERAND (exp
, 0);
2578 case REFERENCE_TYPE
:
2579 /* ??? What about (int)((float)(int)&foo + 4) */
2580 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
2581 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2582 exp
= TREE_OPERAND (exp
, 0);
2584 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
2585 EXPAND_INITIALIZER
),
2587 error ("initializer for integer value is too complicated");
2592 if (TREE_CODE (exp
) != REAL_CST
)
2593 error ("initializer for floating value is not a floating constant");
2595 assemble_real (TREE_REAL_CST (exp
),
2596 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
2601 output_constant (TREE_REALPART (exp
), size
/ 2);
2602 output_constant (TREE_IMAGPART (exp
), size
/ 2);
2603 size
-= (size
/ 2) * 2;
2607 if (TREE_CODE (exp
) == CONSTRUCTOR
)
2609 output_constructor (exp
, size
);
2612 else if (TREE_CODE (exp
) == STRING_CST
)
2616 if (size
> TREE_STRING_LENGTH (exp
))
2618 excess
= size
- TREE_STRING_LENGTH (exp
);
2619 size
= TREE_STRING_LENGTH (exp
);
2622 assemble_string (TREE_STRING_POINTER (exp
), size
);
2631 if (TREE_CODE (exp
) == CONSTRUCTOR
)
2632 output_constructor (exp
, size
);
2639 assemble_zeros (size
);
2642 /* Subroutine of output_constant, used for CONSTRUCTORs
2643 (aggregate constants).
2644 Generate at least SIZE bytes, padding if necessary. */
2647 output_constructor (exp
, size
)
2651 register tree link
, field
= 0;
2652 /* Number of bytes output or skipped so far.
2653 In other words, current position within the constructor. */
2654 int total_bytes
= 0;
2655 /* Non-zero means BYTE contains part of a byte, to be output. */
2656 int byte_buffer_in_use
= 0;
2659 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
2662 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2663 field
= TYPE_FIELDS (TREE_TYPE (exp
));
2665 /* As LINK goes through the elements of the constant,
2666 FIELD goes through the structure fields, if the constant is a structure.
2667 if the constant is a union, then we override this,
2668 by getting the field from the TREE_LIST element.
2669 But the constant could also be an array. Then FIELD is zero. */
2670 for (link
= CONSTRUCTOR_ELTS (exp
);
2672 link
= TREE_CHAIN (link
),
2673 field
= field
? TREE_CHAIN (field
) : 0)
2675 tree val
= TREE_VALUE (link
);
2676 /* the element in a union constructor specifies the proper field. */
2677 if (TREE_PURPOSE (link
) != 0)
2678 field
= TREE_PURPOSE (link
);
2680 /* Eliminate the marker that makes a cast not be an lvalue. */
2684 if (field
== 0 || !DECL_BIT_FIELD (field
))
2686 register int fieldsize
;
2687 /* Since this structure is static,
2688 we know the positions are constant. */
2689 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
2693 /* An element that is not a bit-field.
2694 Output any buffered-up bit-fields preceding it. */
2695 if (byte_buffer_in_use
)
2697 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2699 byte_buffer_in_use
= 0;
2702 /* Advance to offset of this element.
2703 Note no alignment needed in an array, since that is guaranteed
2704 if each element has the proper size. */
2705 if (field
!= 0 && bitpos
!= total_bytes
)
2707 assemble_zeros (bitpos
- total_bytes
);
2708 total_bytes
= bitpos
;
2711 /* Determine size this element should occupy. */
2714 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
2716 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
2718 /* This avoids overflow trouble. */
2719 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
2721 size_int (BITS_PER_UNIT
));
2722 fieldsize
= TREE_INT_CST_LOW (size_tree
);
2726 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
2727 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
2731 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
2733 /* Output the element's initial value. */
2735 assemble_zeros (fieldsize
);
2737 output_constant (val
, fieldsize
);
2739 /* Count its size. */
2740 total_bytes
+= fieldsize
;
2742 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
2743 error ("invalid initial value for member `%s'",
2744 IDENTIFIER_POINTER (DECL_NAME (field
)));
2747 /* Element that is a bit-field. */
2749 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
2751 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
2754 val
= integer_zero_node
;
2756 /* If this field does not start in this (or, next) byte,
2758 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
2760 /* Output remnant of any bit field in previous bytes. */
2761 if (byte_buffer_in_use
)
2763 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2765 byte_buffer_in_use
= 0;
2768 /* If still not at proper byte, advance to there. */
2769 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
2771 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
2772 total_bytes
= next_offset
/ BITS_PER_UNIT
;
2776 if (! byte_buffer_in_use
)
2779 /* We must split the element into pieces that fall within
2780 separate bytes, and combine each byte with previous or
2781 following bit-fields. */
2783 /* next_offset is the offset n fbits from the beginning of
2784 the structure to the next bit of this element to be processed.
2785 end_offset is the offset of the first bit past the end of
2787 while (next_offset
< end_offset
)
2791 int next_byte
= next_offset
/ BITS_PER_UNIT
;
2792 int next_bit
= next_offset
% BITS_PER_UNIT
;
2794 /* Advance from byte to byte
2795 within this element when necessary. */
2796 while (next_byte
!= total_bytes
)
2798 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2803 /* Number of bits we can process at once
2804 (all part of the same byte). */
2805 this_time
= MIN (end_offset
- next_offset
,
2806 BITS_PER_UNIT
- next_bit
);
2807 #if BYTES_BIG_ENDIAN
2808 /* On big-endian machine, take the most significant bits
2809 first (of the bits that are significant)
2810 and put them into bytes from the most significant end. */
2811 shift
= end_offset
- next_offset
- this_time
;
2812 /* Don't try to take a bunch of bits that cross
2813 the word boundary in the INTEGER_CST. */
2814 if (shift
< HOST_BITS_PER_WIDE_INT
2815 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
2817 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
2818 shift
= HOST_BITS_PER_WIDE_INT
;
2821 /* Now get the bits from the appropriate constant word. */
2822 if (shift
< HOST_BITS_PER_WIDE_INT
)
2824 value
= TREE_INT_CST_LOW (val
);
2826 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
2828 value
= TREE_INT_CST_HIGH (val
);
2829 shift
-= HOST_BITS_PER_WIDE_INT
;
2833 byte
|= (((value
>> shift
)
2834 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
2835 << (BITS_PER_UNIT
- this_time
- next_bit
));
2837 /* On little-endian machines,
2838 take first the least significant bits of the value
2839 and pack them starting at the least significant
2840 bits of the bytes. */
2841 shift
= (next_offset
2842 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
2843 /* Don't try to take a bunch of bits that cross
2844 the word boundary in the INTEGER_CST. */
2845 if (shift
< HOST_BITS_PER_WIDE_INT
2846 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
2848 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
2849 shift
= HOST_BITS_PER_WIDE_INT
;
2852 /* Now get the bits from the appropriate constant word. */
2853 if (shift
< HOST_BITS_PER_INT
)
2854 value
= TREE_INT_CST_LOW (val
);
2855 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
2857 value
= TREE_INT_CST_HIGH (val
);
2858 shift
-= HOST_BITS_PER_WIDE_INT
;
2862 byte
|= ((value
>> shift
)
2863 & (((HOST_WIDE_INT
) 1 << this_time
) - 1)) << next_bit
;
2865 next_offset
+= this_time
;
2866 byte_buffer_in_use
= 1;
2870 if (byte_buffer_in_use
)
2872 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
2875 if (total_bytes
< size
)
2876 assemble_zeros (size
- total_bytes
);