1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-5, 1996 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
31 /* #include <stab.h> */
39 #include "hard-reg-set.h"
48 #ifdef XCOFF_DEBUGGING_INFO
55 #define ASM_STABS_OP ".stabs"
58 /* This macro gets just the user-specified name
59 out of the string in a SYMBOL_REF. On most machines,
60 we discard the * if any and that's all. */
61 #ifndef STRIP_NAME_ENCODING
62 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
63 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
66 /* File in which assembler code is being written. */
68 extern FILE *asm_out_file
;
70 /* The (assembler) name of the first globally-visible object output. */
71 char *first_global_object_name
;
73 extern struct obstack
*current_obstack
;
74 extern struct obstack
*saveable_obstack
;
75 extern struct obstack
*rtl_obstack
;
76 extern struct obstack permanent_obstack
;
77 #define obstack_chunk_alloc xmalloc
79 /* Number for making the label on the next
80 constant that is stored in memory. */
84 /* Number for making the label on the next
85 static variable internal to a function. */
89 /* Carry information from ASM_DECLARE_OBJECT_NAME
90 to ASM_FINISH_DECLARE_OBJECT. */
92 int size_directive_output
;
94 /* The last decl for which assemble_variable was called,
95 if it did ASM_DECLARE_OBJECT_NAME.
96 If the last call to assemble_variable didn't do that,
99 tree last_assemble_variable_decl
;
102 #ifdef HANDLE_PRAGMA_WEAK
103 /* Any weak symbol declarations waiting to be emitted. */
107 struct weak_syms
*next
;
112 static struct weak_syms
*weak_decls
;
115 /* Nonzero if at least one function definition has been seen. */
117 static int function_defined
;
120 struct constant_descriptor
;
122 struct pool_constant
;
124 static void bc_make_decl_rtl
PROTO((tree
, char *, int));
125 static char *strip_reg_name
PROTO((char *));
126 static void bc_output_ascii
PROTO((FILE *, char *, int));
127 static int contains_pointers_p
PROTO((tree
));
128 static void decode_addr_const
PROTO((tree
, struct addr_const
*));
129 static int const_hash
PROTO((tree
));
130 static int compare_constant
PROTO((tree
,
131 struct constant_descriptor
*));
132 static char *compare_constant_1
PROTO((tree
, char *));
133 static struct constant_descriptor
*record_constant
PROTO((tree
));
134 static void record_constant_1
PROTO((tree
));
135 static tree copy_constant
PROTO((tree
));
136 static void output_constant_def_contents
PROTO((tree
, int, int));
137 static void decode_rtx_const
PROTO((enum machine_mode
, rtx
,
138 struct rtx_const
*));
139 static int const_hash_rtx
PROTO((enum machine_mode
, rtx
));
140 static int compare_constant_rtx
PROTO((enum machine_mode
, rtx
,
141 struct constant_descriptor
*));
142 static struct constant_descriptor
*record_constant_rtx
PROTO((enum machine_mode
,
144 static struct pool_constant
*find_pool_constant
PROTO((rtx
));
145 static int output_addressed_constants
PROTO((tree
));
146 static void bc_assemble_integer
PROTO((tree
, int));
147 static void output_constructor
PROTO((tree
, int));
149 #ifdef EXTRA_SECTIONS
150 static enum in_section
{no_section
, in_text
, in_data
, in_named
, EXTRA_SECTIONS
} in_section
153 static enum in_section
{no_section
, in_text
, in_data
, in_named
} in_section
157 /* Return a non-zero value if DECL has a section attribute. */
158 #define IN_NAMED_SECTION(DECL) \
159 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
160 && DECL_SECTION_NAME (DECL) != NULL_TREE)
162 /* Text of section name when in_section == in_named. */
163 static char *in_named_name
;
165 /* Define functions like text_section for any extra sections. */
166 #ifdef EXTRA_SECTION_FUNCTIONS
167 EXTRA_SECTION_FUNCTIONS
170 /* Tell assembler to switch to text section. */
175 if (in_section
!= in_text
)
180 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
182 in_section
= in_text
;
186 /* Tell assembler to switch to data section. */
191 if (in_section
!= in_data
)
197 if (flag_shared_data
)
199 #ifdef SHARED_SECTION_ASM_OP
200 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
202 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
206 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
209 in_section
= in_data
;
213 /* Tell assembler to switch to read-only data section. This is normally
217 readonly_data_section ()
219 #ifdef READONLY_DATA_SECTION
220 READONLY_DATA_SECTION (); /* Note this can call data_section. */
226 /* Determine if we're in the text section. */
231 return in_section
== in_text
;
234 /* Determine if we're in the data section. */
238 return in_section
== in_data
;
240 /* Tell assembler to change to section NAME for DECL.
241 If DECL is NULL, just switch to section NAME.
242 If NAME is NULL, get the name from DECL. */
245 named_section (decl
, name
)
249 if (decl
!= NULL_TREE
250 && (TREE_CODE (decl
) != FUNCTION_DECL
&& TREE_CODE (decl
) != VAR_DECL
))
253 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
255 if (in_section
!= in_named
|| strcmp (name
, in_named_name
))
257 in_named_name
= name
;
258 in_section
= in_named
;
260 #ifdef ASM_OUTPUT_SECTION_NAME
261 ASM_OUTPUT_SECTION_NAME (asm_out_file
, decl
, name
);
263 /* Section attributes are not supported if this macro isn't provided -
264 some host formats don't support them at all. The front-end should
265 already have flagged this as an error. */
271 /* Switch to the section for function DECL.
273 If DECL is NULL_TREE, switch to the text section.
274 ??? It's not clear that we will ever be passed NULL_TREE, but it's
275 safer to handle it. */
278 function_section (decl
)
281 if (decl
!= NULL_TREE
282 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
283 named_section (decl
, (char *) 0);
288 /* Switch to section for variable DECL.
290 RELOC is the `reloc' argument to SELECT_SECTION. */
293 variable_section (decl
, reloc
)
297 if (IN_NAMED_SECTION (decl
))
298 named_section (decl
, NULL
);
301 /* C++ can have const variables that get initialized from constructors,
302 and thus can not be in a readonly section. We prevent this by
303 verifying that the initial value is constant for objects put in a
306 error_mark_node is used by the C front end to indicate that the
307 initializer has not been seen yet. In this case, we assume that
308 the initializer must be constant. */
309 #ifdef SELECT_SECTION
310 SELECT_SECTION (decl
, reloc
);
312 if (TREE_READONLY (decl
)
313 && ! TREE_THIS_VOLATILE (decl
)
314 && DECL_INITIAL (decl
)
315 && (DECL_INITIAL (decl
) == error_mark_node
316 || TREE_CONSTANT (DECL_INITIAL (decl
)))
317 && ! (flag_pic
&& reloc
))
318 readonly_data_section ();
325 /* Create the rtl to represent a function, for a function definition.
326 DECL is a FUNCTION_DECL node which describes which function.
327 The rtl is stored into DECL. */
330 make_function_rtl (decl
)
333 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
337 if (DECL_RTL (decl
) == 0)
338 DECL_RTL (decl
) = bc_gen_rtx (name
, 0, (struct bc_label
*) 0);
340 /* Record that at least one function has been defined. */
341 function_defined
= 1;
345 /* Rename a nested function to avoid conflicts. */
346 if (decl_function_context (decl
) != 0
347 && DECL_INITIAL (decl
) != 0
348 && DECL_RTL (decl
) == 0)
352 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
353 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
354 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
358 if (DECL_RTL (decl
) == 0)
361 = gen_rtx (MEM
, DECL_MODE (decl
),
362 gen_rtx (SYMBOL_REF
, Pmode
, name
));
364 /* Optionally set flags or add text to the name to record information
365 such as that it is a function name. If the name is changed, the macro
366 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
367 #ifdef ENCODE_SECTION_INFO
368 ENCODE_SECTION_INFO (decl
);
372 /* Record at least one function has been defined. */
373 function_defined
= 1;
376 /* Create the DECL_RTL for a declaration for a static or external
377 variable or static or external function.
378 ASMSPEC, if not 0, is the string which the user specified
379 as the assembler symbol name.
380 TOP_LEVEL is nonzero if this is a file-scope variable.
381 This is never called for PARM_DECLs. */
384 bc_make_decl_rtl (decl
, asmspec
, top_level
)
389 register char *name
= TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl
));
391 if (DECL_RTL (decl
) == 0)
393 /* Print an error message for register variables. */
394 if (DECL_REGISTER (decl
))
395 error ("global register variables not supported in the interpreter");
397 /* Handle ordinary static variables and functions. */
398 if (DECL_RTL (decl
) == 0)
400 /* Can't use just the variable's own name for a variable
401 whose scope is less than the whole file.
402 Concatenate a distinguishing number. */
403 if (!top_level
&& !DECL_EXTERNAL (decl
) && asmspec
== 0)
407 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
408 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
412 DECL_RTL (decl
) = bc_gen_rtx (name
, 0, (struct bc_label
*) 0);
417 /* Given NAME, a putative register name, discard any customary prefixes. */
420 strip_reg_name (name
)
423 #ifdef REGISTER_PREFIX
424 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
425 name
+= strlen (REGISTER_PREFIX
);
427 if (name
[0] == '%' || name
[0] == '#')
432 /* Decode an `asm' spec for a declaration as a register name.
433 Return the register number, or -1 if nothing specified,
434 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
435 or -3 if ASMSPEC is `cc' and is not recognized,
436 or -4 if ASMSPEC is `memory' and is not recognized.
437 Accept an exact spelling or a decimal number.
438 Prefixes such as % are optional. */
441 decode_reg_name (asmspec
)
448 /* Get rid of confusing prefixes. */
449 asmspec
= strip_reg_name (asmspec
);
451 /* Allow a decimal number as a "register name". */
452 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
453 if (! (asmspec
[i
] >= '0' && asmspec
[i
] <= '9'))
455 if (asmspec
[0] != 0 && i
< 0)
458 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
464 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
466 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
469 #ifdef ADDITIONAL_REGISTER_NAMES
471 static struct { char *name
; int number
; } table
[]
472 = ADDITIONAL_REGISTER_NAMES
;
474 for (i
= 0; i
< sizeof (table
) / sizeof (table
[0]); i
++)
475 if (! strcmp (asmspec
, table
[i
].name
))
476 return table
[i
].number
;
478 #endif /* ADDITIONAL_REGISTER_NAMES */
480 if (!strcmp (asmspec
, "memory"))
483 if (!strcmp (asmspec
, "cc"))
492 /* Create the DECL_RTL for a declaration for a static or external variable
493 or static or external function.
494 ASMSPEC, if not 0, is the string which the user specified
495 as the assembler symbol name.
496 TOP_LEVEL is nonzero if this is a file-scope variable.
498 This is never called for PARM_DECL nodes. */
501 make_decl_rtl (decl
, asmspec
, top_level
)
506 register char *name
= 0;
511 bc_make_decl_rtl (decl
, asmspec
, top_level
);
515 reg_number
= decode_reg_name (asmspec
);
517 if (DECL_ASSEMBLER_NAME (decl
) != NULL_TREE
)
518 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
520 if (reg_number
== -2)
522 /* ASMSPEC is given, and not the name of a register. */
523 name
= (char *) obstack_alloc (saveable_obstack
,
524 strlen (asmspec
) + 2);
526 strcpy (&name
[1], asmspec
);
529 /* For a duplicate declaration, we can be called twice on the
530 same DECL node. Don't discard the RTL already made. */
531 if (DECL_RTL (decl
) == 0)
535 /* First detect errors in declaring global registers. */
536 if (TREE_CODE (decl
) != FUNCTION_DECL
537 && DECL_REGISTER (decl
) && reg_number
== -1)
538 error_with_decl (decl
,
539 "register name not specified for `%s'");
540 else if (TREE_CODE (decl
) != FUNCTION_DECL
541 && DECL_REGISTER (decl
) && reg_number
< 0)
542 error_with_decl (decl
,
543 "invalid register name for `%s'");
544 else if ((reg_number
>= 0 || reg_number
== -3)
545 && (TREE_CODE (decl
) == FUNCTION_DECL
546 && ! DECL_REGISTER (decl
)))
547 error_with_decl (decl
,
548 "register name given for non-register variable `%s'");
549 else if (TREE_CODE (decl
) != FUNCTION_DECL
550 && DECL_REGISTER (decl
)
551 && TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
552 error_with_decl (decl
,
553 "data type of `%s' isn't suitable for a register");
554 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
)
555 && ! HARD_REGNO_MODE_OK (reg_number
,
556 TYPE_MODE (TREE_TYPE (decl
))))
557 error_with_decl (decl
,
558 "register number for `%s' isn't suitable for data type");
559 /* Now handle properly declared static register variables. */
560 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
564 if (DECL_INITIAL (decl
) != 0 && top_level
)
566 DECL_INITIAL (decl
) = 0;
567 error ("global register variable has initial value");
569 if (fixed_regs
[reg_number
] == 0
570 && function_defined
&& top_level
)
571 error ("global register variable follows a function definition");
572 if (TREE_THIS_VOLATILE (decl
))
573 warning ("volatile register variables don't work as you might wish");
575 /* If the user specified one of the eliminables registers here,
576 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
577 confused with that register and be eliminated. Although this
578 usage is somewhat suspect, we nevertheless use the following
579 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
582 = gen_rtx (REG
, DECL_MODE (decl
), FIRST_PSEUDO_REGISTER
);
583 REGNO (DECL_RTL (decl
)) = reg_number
;
584 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
588 /* Make this register global, so not usable for anything
590 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
592 globalize_reg (reg_number
+ --nregs
);
595 /* Specifying a section attribute on an uninitialized variable does not
596 (and cannot) cause it to be put in the given section. The linker
597 can only put initialized objects in specific sections, everything
598 else goes in bss for the linker to sort out later (otherwise the
599 linker would give a duplicate definition error for each compilation
600 unit that behaved thusly). So warn the user. */
601 else if (TREE_CODE (decl
) == VAR_DECL
602 && DECL_SECTION_NAME (decl
) != NULL_TREE
603 && DECL_INITIAL (decl
) == NULL_TREE
604 && DECL_COMMON (decl
)
607 warning_with_decl (decl
,
608 "section attribute ignored for uninitialized variable `%s'");
609 /* Remove the section name so subsequent declarations won't see it.
610 We are ignoring it, remember. */
611 DECL_SECTION_NAME (decl
) = NULL_TREE
;
614 /* Now handle ordinary static variables and functions (in memory).
615 Also handle vars declared register invalidly. */
616 if (DECL_RTL (decl
) == 0)
618 /* Can't use just the variable's own name for a variable
619 whose scope is less than the whole file.
620 Concatenate a distinguishing number. */
621 if (!top_level
&& !DECL_EXTERNAL (decl
) && asmspec
== 0)
625 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
626 name
= obstack_copy0 (saveable_obstack
, label
, strlen (label
));
633 DECL_RTL (decl
) = gen_rtx (MEM
, DECL_MODE (decl
),
634 gen_rtx (SYMBOL_REF
, Pmode
, name
));
636 /* If this variable is to be treated as volatile, show its
637 tree node has side effects. If it has side effects, either
638 because of this test or from TREE_THIS_VOLATILE also
639 being set, show the MEM is volatile. */
640 if (flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
641 && TREE_PUBLIC (decl
))
642 TREE_SIDE_EFFECTS (decl
) = 1;
643 if (TREE_SIDE_EFFECTS (decl
))
644 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
646 if (TREE_READONLY (decl
))
647 RTX_UNCHANGING_P (DECL_RTL (decl
)) = 1;
648 MEM_IN_STRUCT_P (DECL_RTL (decl
))
649 = AGGREGATE_TYPE_P (TREE_TYPE (decl
));
651 /* Optionally set flags or add text to the name to record information
652 such as that it is a function name.
653 If the name is changed, the macro ASM_OUTPUT_LABELREF
654 will have to know how to strip this information. */
655 #ifdef ENCODE_SECTION_INFO
656 ENCODE_SECTION_INFO (decl
);
660 /* If the old RTL had the wrong mode, fix the mode. */
661 else if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
663 rtx rtl
= DECL_RTL (decl
);
664 PUT_MODE (rtl
, DECL_MODE (decl
));
668 /* Make the rtl for variable VAR be volatile.
669 Use this only for static variables. */
672 make_var_volatile (var
)
675 if (GET_CODE (DECL_RTL (var
)) != MEM
)
678 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
681 /* Output alignment directive to align for constant expression EXP. */
684 assemble_constant_align (exp
)
689 /* Align the location counter as required by EXP's data type. */
690 align
= TYPE_ALIGN (TREE_TYPE (exp
));
691 #ifdef CONSTANT_ALIGNMENT
692 align
= CONSTANT_ALIGNMENT (exp
, align
);
695 if (align
> BITS_PER_UNIT
)
696 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
699 /* Output a string of literal assembler code
700 for an `asm' keyword used between functions. */
703 assemble_asm (string
)
708 error ("asm statements not allowed in interpreter");
714 if (TREE_CODE (string
) == ADDR_EXPR
)
715 string
= TREE_OPERAND (string
, 0);
717 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
720 #if 0 /* This should no longer be needed, because
721 flag_gnu_linker should be 0 on these systems,
722 which should prevent any output
723 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
724 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
725 #ifndef ASM_OUTPUT_CONSTRUCTOR
726 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
728 #ifndef ASM_OUTPUT_DESTRUCTOR
729 #define ASM_OUTPUT_DESTRUCTOR(file, name)
734 /* Record an element in the table of global destructors.
735 How this is done depends on what sort of assembler and linker
738 NAME should be the name of a global function to be called
739 at exit time. This name is output using assemble_name. */
742 assemble_destructor (name
)
745 #ifdef ASM_OUTPUT_DESTRUCTOR
746 ASM_OUTPUT_DESTRUCTOR (asm_out_file
, name
);
750 /* Now tell GNU LD that this is part of the static destructor set. */
751 /* This code works for any machine provided you use GNU as/ld. */
752 fprintf (asm_out_file
, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
753 assemble_name (asm_out_file
, name
);
754 fputc ('\n', asm_out_file
);
759 /* Likewise for global constructors. */
762 assemble_constructor (name
)
765 #ifdef ASM_OUTPUT_CONSTRUCTOR
766 ASM_OUTPUT_CONSTRUCTOR (asm_out_file
, name
);
770 /* Now tell GNU LD that this is part of the static constructor set. */
771 /* This code works for any machine provided you use GNU as/ld. */
772 fprintf (asm_out_file
, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
773 assemble_name (asm_out_file
, name
);
774 fputc ('\n', asm_out_file
);
779 /* Likewise for entries we want to record for garbage collection.
780 Garbage collection is still under development. */
783 assemble_gc_entry (name
)
786 #ifdef ASM_OUTPUT_GC_ENTRY
787 ASM_OUTPUT_GC_ENTRY (asm_out_file
, name
);
791 /* Now tell GNU LD that this is part of the static constructor set. */
792 fprintf (asm_out_file
, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP
);
793 assemble_name (asm_out_file
, name
);
794 fputc ('\n', asm_out_file
);
799 /* Output assembler code for the constant pool of a function and associated
800 with defining the name of the function. DECL describes the function.
801 NAME is the function's name. For the constant pool, we use the current
802 constant pool data. */
805 assemble_start_function (decl
, fnname
)
811 /* The following code does not need preprocessing in the assembler. */
815 output_constant_pool (fnname
, decl
);
817 function_section (decl
);
819 /* Tell assembler to move to target machine's alignment for functions. */
820 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
824 BC_OUTPUT_ALIGN (asm_out_file
, align
);
826 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
829 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
830 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
833 #ifdef SDB_DEBUGGING_INFO
834 /* Output SDB definition of the function. */
835 if (write_symbols
== SDB_DEBUG
)
836 sdbout_mark_begin_function ();
839 #ifdef DBX_DEBUGGING_INFO
840 /* Output DBX definition of the function. */
841 if (write_symbols
== DBX_DEBUG
)
842 dbxout_begin_function (decl
);
845 /* Make function name accessible from other files, if appropriate. */
847 if (TREE_PUBLIC (decl
))
849 if (!first_global_object_name
)
853 STRIP_NAME_ENCODING (p
, fnname
);
854 first_global_object_name
= permalloc (strlen (p
) + 1);
855 strcpy (first_global_object_name
, p
);
858 #ifdef ASM_WEAKEN_LABEL
859 if (DECL_WEAK (decl
))
860 ASM_WEAKEN_LABEL (asm_out_file
, fnname
);
864 BC_GLOBALIZE_LABEL (asm_out_file
, fnname
);
866 ASM_GLOBALIZE_LABEL (asm_out_file
, fnname
);
869 /* Do any machine/system dependent processing of the function name */
870 #ifdef ASM_DECLARE_FUNCTION_NAME
871 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
873 /* Standard thing is just output label for the function. */
875 BC_OUTPUT_LABEL (asm_out_file
, fnname
);
877 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
878 #endif /* ASM_DECLARE_FUNCTION_NAME */
881 /* Output assembler code associated with defining the size of the
882 function. DECL describes the function. NAME is the function's name. */
885 assemble_end_function (decl
, fnname
)
889 #ifdef ASM_DECLARE_FUNCTION_SIZE
890 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
894 /* Assemble code to leave SIZE bytes of zeros. */
897 assemble_zeros (size
)
902 bc_emit_const_skip (size
);
906 #ifdef ASM_NO_SKIP_IN_TEXT
907 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
908 so we must output 0s explicitly in the text section. */
909 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
913 for (i
= 0; i
< size
- 20; i
+= 20)
916 fprintf (asm_out_file
,
917 "%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
);
919 fprintf (asm_out_file
,
920 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
926 fprintf (asm_out_file
, "%s 0", ASM_BYTE_OP
);
928 fprintf (asm_out_file
, "\tbyte 0");
931 for (; i
< size
; i
++)
932 fprintf (asm_out_file
, ",0");
933 fprintf (asm_out_file
, "\n");
941 BC_OUTPUT_SKIP (asm_out_file
, size
);
943 ASM_OUTPUT_SKIP (asm_out_file
, size
);
947 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
950 assemble_align (align
)
953 if (align
> BITS_PER_UNIT
)
954 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
957 /* Assemble a string constant with the specified C string as contents. */
960 assemble_string (p
, size
)
974 /* If the string is very long, split it up. */
978 int thissize
= size
- pos
;
979 if (thissize
> maximum
)
983 bc_output_ascii (asm_out_file
, p
, thissize
);
986 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
995 bc_output_ascii (file
, p
, size
)
1000 BC_OUTPUT_ASCII (file
, p
, size
);
1003 /* Assemble everything that is needed for a variable or function declaration.
1004 Not used for automatic variables, and not used for function definitions.
1005 Should not be called for variables of incomplete structure type.
1007 TOP_LEVEL is nonzero if this variable has file scope.
1008 AT_END is nonzero if this is the special handling, at end of compilation,
1009 to define things that have had only tentative definitions.
1010 DONT_OUTPUT_DATA if nonzero means don't actually output the
1011 initial value (that will be done by the caller). */
1014 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1018 int dont_output_data
;
1020 register char *name
;
1024 enum in_section saved_in_section
;
1026 last_assemble_variable_decl
= 0;
1028 if (output_bytecode
)
1031 if (GET_CODE (DECL_RTL (decl
)) == REG
)
1033 /* Do output symbol info for global register variables, but do nothing
1036 if (TREE_ASM_WRITTEN (decl
))
1038 TREE_ASM_WRITTEN (decl
) = 1;
1040 if (!output_bytecode
)
1042 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1043 /* File-scope global variables are output here. */
1044 if ((write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1046 dbxout_symbol (decl
, 0);
1048 #ifdef SDB_DEBUGGING_INFO
1049 if (write_symbols
== SDB_DEBUG
&& top_level
1050 /* Leave initialized global vars for end of compilation;
1051 see comment in compile_file. */
1052 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1053 sdbout_symbol (decl
, 0);
1057 /* Don't output any DWARF debugging information for variables here.
1058 In the case of local variables, the information for them is output
1059 when we do our recursive traversal of the tree representation for
1060 the entire containing function. In the case of file-scope variables,
1061 we output information for all of them at the very end of compilation
1062 while we are doing our final traversal of the chain of file-scope
1068 /* Normally no need to say anything here for external references,
1069 since assemble_external is called by the language-specific code
1070 when a declaration is first seen. */
1072 if (DECL_EXTERNAL (decl
))
1075 /* Output no assembler code for a function declaration.
1076 Only definitions of functions output anything. */
1078 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1081 /* If type was incomplete when the variable was declared,
1082 see if it is complete now. */
1084 if (DECL_SIZE (decl
) == 0)
1085 layout_decl (decl
, 0);
1087 /* Still incomplete => don't allocate it; treat the tentative defn
1088 (which is what it must have been) as an `extern' reference. */
1090 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1092 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1093 DECL_SOURCE_LINE (decl
),
1094 "storage size of `%s' isn't known",
1095 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1096 TREE_ASM_WRITTEN (decl
) = 1;
1100 /* The first declaration of a variable that comes through this function
1101 decides whether it is global (in C, has external linkage)
1102 or local (in C, has internal linkage). So do nothing more
1103 if this function has already run. */
1105 if (TREE_ASM_WRITTEN (decl
))
1108 TREE_ASM_WRITTEN (decl
) = 1;
1112 if (! dont_output_data
)
1114 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1117 /* This is better than explicit arithmetic, since it avoids overflow. */
1118 size_tree
= size_binop (CEIL_DIV_EXPR
,
1119 DECL_SIZE (decl
), size_int (BITS_PER_UNIT
));
1121 if (TREE_INT_CST_HIGH (size_tree
) != 0)
1123 error_with_decl (decl
, "size of variable `%s' is too large");
1128 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1130 /* Handle uninitialized definitions. */
1132 /* ANSI specifies that a tentative definition which is not merged with
1133 a non-tentative definition behaves exactly like a definition with an
1134 initializer equal to zero. (Section 3.7.2)
1135 -fno-common gives strict ANSI behavior. Usually you don't want it.
1136 This matters only for variables with external linkage. */
1137 if ((! flag_no_common
|| ! TREE_PUBLIC (decl
))
1138 && DECL_COMMON (decl
)
1139 && ! dont_output_data
1140 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
1142 int size
= TREE_INT_CST_LOW (size_tree
);
1145 if (TREE_INT_CST_HIGH (size_tree
) != 0)
1146 error_with_decl (decl
, "size of variable `%s' is too large");
1147 /* Don't allocate zero bytes of common,
1148 since that means "undefined external" in the linker. */
1149 if (size
== 0) rounded
= 1;
1150 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1151 so that each uninitialized object starts on such a boundary. */
1152 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1153 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1154 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1156 #ifdef DBX_DEBUGGING_INFO
1157 /* File-scope global variables are output here. */
1158 if (write_symbols
== DBX_DEBUG
&& top_level
)
1159 dbxout_symbol (decl
, 0);
1161 #ifdef SDB_DEBUGGING_INFO
1162 if (write_symbols
== SDB_DEBUG
&& top_level
1163 /* Leave initialized global vars for end of compilation;
1164 see comment in compile_file. */
1165 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1166 sdbout_symbol (decl
, 0);
1169 /* Don't output any DWARF debugging information for variables here.
1170 In the case of local variables, the information for them is output
1171 when we do our recursive traversal of the tree representation for
1172 the entire containing function. In the case of file-scope variables,
1173 we output information for all of them at the very end of compilation
1174 while we are doing our final traversal of the chain of file-scope
1178 if (flag_shared_data
)
1181 if (TREE_PUBLIC (decl
))
1183 #ifdef ASM_OUTPUT_SHARED_COMMON
1184 if (flag_shared_data
)
1185 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1188 if (output_bytecode
)
1190 BC_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1194 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1195 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
,
1198 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1204 #ifdef ASM_OUTPUT_SHARED_LOCAL
1205 if (flag_shared_data
)
1206 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1209 if (output_bytecode
)
1211 BC_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1215 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1216 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
1219 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1226 /* Handle initialized definitions. */
1228 /* First make the assembler name(s) global if appropriate. */
1229 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1231 if (!first_global_object_name
)
1235 STRIP_NAME_ENCODING (p
, name
);
1236 first_global_object_name
= permalloc (strlen (p
) + 1);
1237 strcpy (first_global_object_name
, p
);
1240 #ifdef ASM_WEAKEN_LABEL
1241 if (DECL_WEAK (decl
))
1242 ASM_WEAKEN_LABEL (asm_out_file
, name
);
1245 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1248 for (d
= equivalents
; d
; d
= TREE_CHAIN (d
))
1250 tree e
= TREE_VALUE (d
);
1251 if (TREE_PUBLIC (e
) && DECL_NAME (e
))
1252 ASM_GLOBALIZE_LABEL (asm_out_file
,
1253 XSTR (XEXP (DECL_RTL (e
), 0), 0));
1257 /* Output any data that we will need to use the address of. */
1258 if (DECL_INITIAL (decl
) == error_mark_node
)
1259 reloc
= contains_pointers_p (TREE_TYPE (decl
));
1260 else if (DECL_INITIAL (decl
))
1261 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1263 /* Switch to the appropriate section. */
1264 variable_section (decl
, reloc
);
1266 /* dbxout.c needs to know this. */
1267 if (in_text_section ())
1268 DECL_IN_TEXT_SECTION (decl
) = 1;
1270 /* Record current section so we can restore it if dbxout.c clobbers it. */
1271 saved_in_section
= in_section
;
1273 /* Output the dbx info now that we have chosen the section. */
1275 #ifdef DBX_DEBUGGING_INFO
1276 /* File-scope global variables are output here. */
1277 if (write_symbols
== DBX_DEBUG
&& top_level
)
1278 dbxout_symbol (decl
, 0);
1280 #ifdef SDB_DEBUGGING_INFO
1281 if (write_symbols
== SDB_DEBUG
&& top_level
1282 /* Leave initialized global vars for end of compilation;
1283 see comment in compile_file. */
1284 && (TREE_PUBLIC (decl
) == 0 || DECL_INITIAL (decl
) == 0))
1285 sdbout_symbol (decl
, 0);
1288 /* Don't output any DWARF debugging information for variables here.
1289 In the case of local variables, the information for them is output
1290 when we do our recursive traversal of the tree representation for
1291 the entire containing function. In the case of file-scope variables,
1292 we output information for all of them at the very end of compilation
1293 while we are doing our final traversal of the chain of file-scope
1296 /* If the debugging output changed sections, reselect the section
1297 that's supposed to be selected. */
1298 if (in_section
!= saved_in_section
)
1299 variable_section (decl
, reloc
);
1301 /* Compute and output the alignment of this data. */
1303 align
= DECL_ALIGN (decl
);
1304 /* In the case for initialing an array whose length isn't specified,
1305 where we have not yet been able to do the layout,
1306 figure out the proper alignment now. */
1307 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1308 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1309 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1311 /* Some object file formats have a maximum alignment which they support.
1312 In particular, a.out format supports a maximum alignment of 4. */
1313 #ifndef MAX_OFILE_ALIGNMENT
1314 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1316 if (align
> MAX_OFILE_ALIGNMENT
)
1318 warning_with_decl (decl
,
1319 "alignment of `%s' is greater than maximum object file alignment");
1320 align
= MAX_OFILE_ALIGNMENT
;
1322 #ifdef DATA_ALIGNMENT
1323 /* On some machines, it is good to increase alignment sometimes. */
1324 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1326 #ifdef CONSTANT_ALIGNMENT
1327 if (DECL_INITIAL (decl
))
1328 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1331 /* Reset the alignment in case we have made it tighter, so we can benefit
1332 from it in get_pointer_alignment. */
1333 DECL_ALIGN (decl
) = align
;
1335 if (align
> BITS_PER_UNIT
)
1337 if (output_bytecode
)
1338 BC_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1340 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1343 /* Do any machine/system dependent processing of the object. */
1344 #ifdef ASM_DECLARE_OBJECT_NAME
1345 last_assemble_variable_decl
= decl
;
1346 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1348 /* Standard thing is just output label for the object. */
1349 if (output_bytecode
)
1350 BC_OUTPUT_LABEL (asm_out_file
, name
);
1352 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1353 #endif /* ASM_DECLARE_OBJECT_NAME */
1355 if (!dont_output_data
)
1357 if (DECL_INITIAL (decl
))
1358 /* Output the actual data. */
1359 output_constant (DECL_INITIAL (decl
), TREE_INT_CST_LOW (size_tree
));
1361 /* Leave space for it. */
1362 assemble_zeros (TREE_INT_CST_LOW (size_tree
));
1366 #ifdef XCOFF_DEBUGGING_INFO
1367 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1368 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1369 and `aa' hasn't been output yet, the assembler generates a stab entry with
1370 a value of zero, in addition to creating an unnecessary external entry
1371 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1373 /* File-scope global variables are output here. */
1374 if (write_symbols
== XCOFF_DEBUG
&& top_level
)
1376 saved_in_section
= in_section
;
1378 dbxout_symbol (decl
, 0);
1380 if (in_section
!= saved_in_section
)
1381 variable_section (decl
, reloc
);
1384 /* There must be a statement after a label. */
1389 /* Return 1 if type TYPE contains any pointers. */
1392 contains_pointers_p (type
)
1395 switch (TREE_CODE (type
))
1398 case REFERENCE_TYPE
:
1399 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1400 so I'll play safe and return 1. */
1406 case QUAL_UNION_TYPE
:
1409 /* For a type that has fields, see if the fields have pointers. */
1410 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1411 if (TREE_CODE (fields
) == FIELD_DECL
1412 && contains_pointers_p (TREE_TYPE (fields
)))
1418 /* An array type contains pointers if its element type does. */
1419 return contains_pointers_p (TREE_TYPE (type
));
1426 /* Output text storage for constructor CONSTR. */
1429 bc_output_constructor (constr
, size
)
1435 /* Must always be a literal; non-literal constructors are handled
1438 if (!TREE_CONSTANT (constr
))
1445 for (i
= 0; TYPE_ALIGN (constr
) >= BITS_PER_UNIT
<< (i
+ 1); i
++)
1449 BC_OUTPUT_ALIGN (asm_out_file
, i
);
1452 output_constant (constr
, size
);
1455 /* Create storage for constructor CONSTR. */
1458 bc_output_data_constructor (constr
)
1463 /* Put in data section */
1467 for (i
= 0; TYPE_ALIGN (constr
) >= BITS_PER_UNIT
<< (i
+ 1); i
++);
1469 BC_OUTPUT_ALIGN (asm_out_file
, i
);
1471 /* The constructor is filled in at runtime. */
1472 BC_OUTPUT_SKIP (asm_out_file
, int_size_in_bytes (TREE_TYPE (constr
)));
1475 /* Output something to declare an external symbol to the assembler.
1476 (Most assemblers don't need this, so we normally output nothing.)
1477 Do nothing if DECL is not external. */
1480 assemble_external (decl
)
1483 if (output_bytecode
)
1486 #ifdef ASM_OUTPUT_EXTERNAL
1487 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
1488 && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1490 rtx rtl
= DECL_RTL (decl
);
1492 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1493 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1495 /* Some systems do require some output. */
1496 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1497 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1503 /* Similar, for calling a library function FUN. */
1506 assemble_external_libcall (fun
)
1509 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1510 if (!output_bytecode
)
1512 /* Declare library function name external when first used, if nec. */
1513 if (! SYMBOL_REF_USED (fun
))
1515 SYMBOL_REF_USED (fun
) = 1;
1516 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1522 /* Declare the label NAME global. */
1525 assemble_global (name
)
1528 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1531 /* Assemble a label named NAME. */
1534 assemble_label (name
)
1537 if (output_bytecode
)
1538 BC_OUTPUT_LABEL (asm_out_file
, name
);
1540 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1543 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1544 If NAME starts with a *, the rest of NAME is output verbatim.
1545 Otherwise NAME is transformed in an implementation-defined way
1546 (usually by the addition of an underscore).
1547 Many macros in the tm file are defined to call this function. */
1550 assemble_name (file
, name
)
1555 int save_warn_id_clash
= warn_id_clash
;
1557 STRIP_NAME_ENCODING (real_name
, name
);
1559 /* Don't warn about an identifier name length clash on this name, since
1560 it can be a user symbol suffixed by a number. */
1562 TREE_SYMBOL_REFERENCED (get_identifier (real_name
)) = 1;
1563 warn_id_clash
= save_warn_id_clash
;
1567 if (output_bytecode
)
1568 bc_emit_labelref (name
, 0);
1570 fputs (&name
[1], file
);
1574 if (output_bytecode
)
1575 BC_OUTPUT_LABELREF (file
, name
);
1577 ASM_OUTPUT_LABELREF (file
, name
);
1581 /* Allocate SIZE bytes writable static space with a gensym name
1582 and return an RTX to refer to its address. */
1585 assemble_static_space (size
)
1591 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1592 so that each uninitialized object starts on such a boundary. */
1593 int rounded
= ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1594 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1595 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1598 if (flag_shared_data
)
1602 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1605 namestring
= (char *) obstack_alloc (saveable_obstack
,
1607 strcpy (namestring
, name
);
1609 if (output_bytecode
)
1610 x
= bc_gen_rtx (namestring
, 0, (struct bc_label
*) 0);
1612 x
= gen_rtx (SYMBOL_REF
, Pmode
, namestring
);
1614 if (output_bytecode
)
1616 BC_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1620 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1621 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1623 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1629 /* Assemble the static constant template for function entry trampolines.
1630 This is done at most once per compilation.
1631 Returns an RTX for the address of the template. */
1634 assemble_trampoline_template ()
1640 /* Shouldn't get here */
1641 if (output_bytecode
)
1644 /* By default, put trampoline templates in read-only data section. */
1646 #ifdef TRAMPOLINE_SECTION
1647 TRAMPOLINE_SECTION ();
1649 readonly_data_section ();
1652 /* Write the assembler code to define one. */
1653 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1655 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1657 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1658 TRAMPOLINE_TEMPLATE (asm_out_file
);
1660 /* Record the rtl to refer to it. */
1661 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1663 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
1664 return gen_rtx (SYMBOL_REF
, Pmode
, name
);
1667 /* Assemble the integer constant X into an object of SIZE bytes.
1668 X must be either a CONST_INT or CONST_DOUBLE.
1670 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1671 non-zero, abort if we can't output the constant. */
1674 assemble_integer (x
, size
, force
)
1679 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1680 ASM_OUTPUT... macros. */
1684 #ifdef ASM_OUTPUT_CHAR
1686 ASM_OUTPUT_CHAR (asm_out_file
, x
);
1690 #ifdef ASM_OUTPUT_SHORT
1692 ASM_OUTPUT_SHORT (asm_out_file
, x
);
1696 #ifdef ASM_OUTPUT_INT
1698 ASM_OUTPUT_INT (asm_out_file
, x
);
1702 #ifdef ASM_OUTPUT_DOUBLE_INT
1704 ASM_OUTPUT_DOUBLE_INT (asm_out_file
, x
);
1708 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1710 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file
, x
);
1715 /* If we couldn't do it that way, there are two other possibilities: First,
1716 if the machine can output an explicit byte and this is a 1 byte constant,
1717 we can use ASM_OUTPUT_BYTE. */
1719 #ifdef ASM_OUTPUT_BYTE
1720 if (size
== 1 && GET_CODE (x
) == CONST_INT
)
1722 ASM_OUTPUT_BYTE (asm_out_file
, INTVAL (x
));
1727 /* Finally, if SIZE is larger than a single word, try to output the constant
1728 one word at a time. */
1730 if (size
> UNITS_PER_WORD
)
1733 enum machine_mode mode
1734 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1737 for (i
= 0; i
< size
/ UNITS_PER_WORD
; i
++)
1739 word
= operand_subword (x
, i
, 0, mode
);
1744 if (! assemble_integer (word
, UNITS_PER_WORD
, 0))
1748 if (i
== size
/ UNITS_PER_WORD
)
1750 /* If we output at least one word and then could not finish,
1751 there is no valid way to continue. */
1762 /* Assemble the floating-point constant D into an object of size MODE. */
1765 assemble_real (d
, mode
)
1767 enum machine_mode mode
;
1769 jmp_buf output_constant_handler
;
1771 if (setjmp (output_constant_handler
))
1773 error ("floating point trap outputting a constant");
1774 #ifdef REAL_IS_NOT_DOUBLE
1775 bzero ((char *) &d
, sizeof d
);
1782 set_float_handler (output_constant_handler
);
1786 #ifdef ASM_OUTPUT_BYTE_FLOAT
1788 ASM_OUTPUT_BYTE_FLOAT (asm_out_file
, d
);
1791 #ifdef ASM_OUTPUT_SHORT_FLOAT
1793 ASM_OUTPUT_SHORT_FLOAT (asm_out_file
, d
);
1796 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1798 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file
, d
);
1801 #ifdef ASM_OUTPUT_FLOAT
1803 ASM_OUTPUT_FLOAT (asm_out_file
, d
);
1807 #ifdef ASM_OUTPUT_DOUBLE
1809 ASM_OUTPUT_DOUBLE (asm_out_file
, d
);
1813 #ifdef ASM_OUTPUT_LONG_DOUBLE
1816 ASM_OUTPUT_LONG_DOUBLE (asm_out_file
, d
);
1824 set_float_handler (NULL_PTR
);
1827 /* Here we combine duplicate floating constants to make
1828 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1830 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1831 They are chained through the CONST_DOUBLE_CHAIN.
1832 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1833 In that case, CONST_DOUBLE_MEM is either a MEM,
1834 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1836 (CONST_DOUBLE_MEM is used only for top-level functions.
1837 See force_const_mem for explanation.) */
1839 static rtx const_double_chain
;
1841 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1842 For an integer, I0 is the low-order word and I1 is the high-order word.
1843 For a real number, I0 is the word with the low address
1844 and I1 is the word with the high address. */
1847 immed_double_const (i0
, i1
, mode
)
1848 HOST_WIDE_INT i0
, i1
;
1849 enum machine_mode mode
;
1852 int in_current_obstack
;
1854 if (GET_MODE_CLASS (mode
) == MODE_INT
1855 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
1857 /* We clear out all bits that don't belong in MODE, unless they and our
1858 sign bit are all one. So we get either a reasonable negative value
1859 or a reasonable unsigned value for this mode. */
1860 int width
= GET_MODE_BITSIZE (mode
);
1861 if (width
< HOST_BITS_PER_WIDE_INT
1862 && ((i0
& ((HOST_WIDE_INT
) (-1) << (width
- 1)))
1863 != ((HOST_WIDE_INT
) (-1) << (width
- 1))))
1864 i0
&= ((HOST_WIDE_INT
) 1 << width
) - 1, i1
= 0;
1865 else if (width
== HOST_BITS_PER_WIDE_INT
1866 && ! (i1
== ~0 && i0
< 0))
1868 else if (width
> 2 * HOST_BITS_PER_WIDE_INT
)
1869 /* We cannot represent this value as a constant. */
1872 /* If this would be an entire word for the target, but is not for
1873 the host, then sign-extend on the host so that the number will look
1874 the same way on the host that it would on the target.
1876 For example, when building a 64 bit alpha hosted 32 bit sparc
1877 targeted compiler, then we want the 32 bit unsigned value -1 to be
1878 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1879 The later confuses the sparc backend. */
1881 if (BITS_PER_WORD
< HOST_BITS_PER_WIDE_INT
&& BITS_PER_WORD
== width
1882 && (i0
& ((HOST_WIDE_INT
) 1 << (width
- 1))))
1883 i0
|= ((HOST_WIDE_INT
) (-1) << width
);
1885 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1887 ??? Strictly speaking, this is wrong if we create a CONST_INT
1888 for a large unsigned constant with the size of MODE being
1889 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1890 wider mode. In that case we will mis-interpret it as a negative
1893 Unfortunately, the only alternative is to make a CONST_DOUBLE
1894 for any constant in any mode if it is an unsigned constant larger
1895 than the maximum signed integer in an int on the host. However,
1896 doing this will break everyone that always expects to see a CONST_INT
1897 for SImode and smaller.
1899 We have always been making CONST_INTs in this case, so nothing new
1902 if (width
<= HOST_BITS_PER_WIDE_INT
)
1903 i1
= (i0
< 0) ? ~0 : 0;
1905 /* If this integer fits in one word, return a CONST_INT. */
1906 if ((i1
== 0 && i0
>= 0)
1907 || (i1
== ~0 && i0
< 0))
1908 return GEN_INT (i0
);
1910 /* We use VOIDmode for integers. */
1914 /* Search the chain for an existing CONST_DOUBLE with the right value.
1915 If one is found, return it. */
1917 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1918 if (CONST_DOUBLE_LOW (r
) == i0
&& CONST_DOUBLE_HIGH (r
) == i1
1919 && GET_MODE (r
) == mode
)
1922 /* No; make a new one and add it to the chain.
1924 We may be called by an optimizer which may be discarding any memory
1925 allocated during its processing (such as combine and loop). However,
1926 we will be leaving this constant on the chain, so we cannot tolerate
1927 freed memory. So switch to saveable_obstack for this allocation
1928 and then switch back if we were in current_obstack. */
1930 push_obstacks_nochange ();
1931 rtl_in_saveable_obstack ();
1932 r
= gen_rtx (CONST_DOUBLE
, mode
, 0, i0
, i1
);
1935 /* Don't touch const_double_chain in nested function; see force_const_mem.
1936 Also, don't touch it if not inside any function. */
1937 if (outer_function_chain
== 0 && current_function_decl
!= 0)
1939 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
1940 const_double_chain
= r
;
1943 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1944 Actual use of mem-slot is only through force_const_mem. */
1946 CONST_DOUBLE_MEM (r
) = const0_rtx
;
1951 /* Return a CONST_DOUBLE for a specified `double' value
1952 and machine mode. */
1955 immed_real_const_1 (d
, mode
)
1957 enum machine_mode mode
;
1959 union real_extract u
;
1961 int in_current_obstack
;
1963 /* Get the desired `double' value as a sequence of ints
1964 since that is how they are stored in a CONST_DOUBLE. */
1968 /* Detect special cases. */
1970 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1971 if (!bcmp ((char *) &dconst0
, (char *) &d
, sizeof d
))
1972 return CONST0_RTX (mode
);
1973 /* Check for NaN first, because some ports (specifically the i386) do not
1974 emit correct ieee-fp code by default, and thus will generate a core
1975 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1976 does a floating point comparison. */
1977 else if (! REAL_VALUE_ISNAN (d
) && REAL_VALUES_EQUAL (dconst1
, d
))
1978 return CONST1_RTX (mode
);
1980 if (sizeof u
== 2 * sizeof (HOST_WIDE_INT
))
1981 return immed_double_const (u
.i
[0], u
.i
[1], mode
);
1983 /* The rest of this function handles the case where
1984 a float value requires more than 2 ints of space.
1985 It will be deleted as dead code on machines that don't need it. */
1987 /* Search the chain for an existing CONST_DOUBLE with the right value.
1988 If one is found, return it. */
1990 for (r
= const_double_chain
; r
; r
= CONST_DOUBLE_CHAIN (r
))
1991 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r
), (char *) &u
, sizeof u
)
1992 && GET_MODE (r
) == mode
)
1995 /* No; make a new one and add it to the chain.
1997 We may be called by an optimizer which may be discarding any memory
1998 allocated during its processing (such as combine and loop). However,
1999 we will be leaving this constant on the chain, so we cannot tolerate
2000 freed memory. So switch to saveable_obstack for this allocation
2001 and then switch back if we were in current_obstack. */
2003 push_obstacks_nochange ();
2004 rtl_in_saveable_obstack ();
2005 r
= rtx_alloc (CONST_DOUBLE
);
2007 bcopy ((char *) &u
, (char *) &CONST_DOUBLE_LOW (r
), sizeof u
);
2010 /* Don't touch const_double_chain in nested function; see force_const_mem.
2011 Also, don't touch it if not inside any function. */
2012 if (outer_function_chain
== 0 && current_function_decl
!= 0)
2014 CONST_DOUBLE_CHAIN (r
) = const_double_chain
;
2015 const_double_chain
= r
;
2018 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2019 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2020 is only through force_const_mem. */
2022 CONST_DOUBLE_MEM (r
) = const0_rtx
;
2027 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2028 which must be a REAL_CST tree node. */
2031 immed_real_const (exp
)
2034 return immed_real_const_1 (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)));
2037 /* At the end of a function, forget the memory-constants
2038 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2039 Also clear out real_constant_chain and clear out all the chain-pointers. */
2042 clear_const_double_mem ()
2044 register rtx r
, next
;
2046 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2047 See force_const_mem for explanation. */
2048 if (outer_function_chain
!= 0)
2051 for (r
= const_double_chain
; r
; r
= next
)
2053 next
= CONST_DOUBLE_CHAIN (r
);
2054 CONST_DOUBLE_CHAIN (r
) = 0;
2055 CONST_DOUBLE_MEM (r
) = cc0_rtx
;
2057 const_double_chain
= 0;
2060 /* Given an expression EXP with a constant value,
2061 reduce it to the sum of an assembler symbol and an integer.
2062 Store them both in the structure *VALUE.
2063 Abort if EXP does not reduce. */
2068 HOST_WIDE_INT offset
;
2072 decode_addr_const (exp
, value
)
2074 struct addr_const
*value
;
2076 register tree target
= TREE_OPERAND (exp
, 0);
2077 register int offset
= 0;
2082 if (TREE_CODE (target
) == COMPONENT_REF
2083 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1)))
2086 offset
+= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target
, 1))) / BITS_PER_UNIT
;
2087 target
= TREE_OPERAND (target
, 0);
2089 else if (TREE_CODE (target
) == ARRAY_REF
)
2091 if (TREE_CODE (TREE_OPERAND (target
, 1)) != INTEGER_CST
2092 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target
))) != INTEGER_CST
)
2094 offset
+= ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target
)))
2095 * TREE_INT_CST_LOW (TREE_OPERAND (target
, 1)))
2097 target
= TREE_OPERAND (target
, 0);
2103 switch (TREE_CODE (target
))
2107 x
= DECL_RTL (target
);
2111 if (output_bytecode
)
2112 /* FIXME: this may not be correct, check it */
2113 x
= bc_gen_rtx (TREE_STRING_POINTER (target
), 0, (struct bc_label
*) 0);
2115 x
= gen_rtx (MEM
, FUNCTION_MODE
,
2116 gen_rtx (LABEL_REF
, VOIDmode
,
2117 label_rtx (TREE_OPERAND (exp
, 0))));
2124 x
= TREE_CST_RTL (target
);
2131 if (!output_bytecode
)
2133 if (GET_CODE (x
) != MEM
)
2139 value
->offset
= offset
;
2142 /* Uniquize all constants that appear in memory.
2143 Each constant in memory thus far output is recorded
2144 in `const_hash_table' with a `struct constant_descriptor'
2145 that contains a polish representation of the value of
2148 We cannot store the trees in the hash table
2149 because the trees may be temporary. */
2151 struct constant_descriptor
2153 struct constant_descriptor
*next
;
2159 #define MAX_HASH_TABLE 1009
2160 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2162 /* Compute a hash code for a constant expression. */
2169 register int len
, hi
, i
;
2170 register enum tree_code code
= TREE_CODE (exp
);
2172 if (code
== INTEGER_CST
)
2174 p
= (char *) &TREE_INT_CST_LOW (exp
);
2175 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2177 else if (code
== REAL_CST
)
2179 p
= (char *) &TREE_REAL_CST (exp
);
2180 len
= sizeof TREE_REAL_CST (exp
);
2182 else if (code
== STRING_CST
)
2183 p
= TREE_STRING_POINTER (exp
), len
= TREE_STRING_LENGTH (exp
);
2184 else if (code
== COMPLEX_CST
)
2185 return const_hash (TREE_REALPART (exp
)) * 5
2186 + const_hash (TREE_IMAGPART (exp
));
2187 else if (code
== CONSTRUCTOR
&& TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2189 len
= int_size_in_bytes (TREE_TYPE (exp
));
2190 p
= (char*) alloca (len
);
2191 get_set_constructor_bytes (exp
, (unsigned char *) p
, len
);
2193 else if (code
== CONSTRUCTOR
)
2197 /* For record type, include the type in the hashing.
2198 We do not do so for array types
2199 because (1) the sizes of the elements are sufficient
2200 and (2) distinct array types can have the same constructor.
2201 Instead, we include the array size because the constructor could
2203 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2204 hi
= ((HOST_WIDE_INT
) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2207 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2208 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2210 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2211 if (TREE_VALUE (link
))
2212 hi
= (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2216 else if (code
== ADDR_EXPR
)
2218 struct addr_const value
;
2219 decode_addr_const (exp
, &value
);
2220 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2222 /* Don't hash the address of the SYMBOL_REF;
2223 only use the offset and the symbol name. */
2225 p
= XSTR (value
.base
, 0);
2226 for (i
= 0; p
[i
] != 0; i
++)
2227 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
2229 else if (GET_CODE (value
.base
) == LABEL_REF
)
2230 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2232 hi
&= (1 << HASHBITS
) - 1;
2233 hi
%= MAX_HASH_TABLE
;
2236 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
2237 return const_hash (TREE_OPERAND (exp
, 0)) * 9
2238 + const_hash (TREE_OPERAND (exp
, 1));
2239 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
2240 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2242 /* Compute hashing function */
2244 for (i
= 0; i
< len
; i
++)
2245 hi
= ((hi
* 613) + (unsigned)(p
[i
]));
2247 hi
&= (1 << HASHBITS
) - 1;
2248 hi
%= MAX_HASH_TABLE
;
2252 /* Compare a constant expression EXP with a constant-descriptor DESC.
2253 Return 1 if DESC describes a constant with the same value as EXP. */
2256 compare_constant (exp
, desc
)
2258 struct constant_descriptor
*desc
;
2260 return 0 != compare_constant_1 (exp
, desc
->contents
);
2263 /* Compare constant expression EXP with a substring P of a constant descriptor.
2264 If they match, return a pointer to the end of the substring matched.
2265 If they do not match, return 0.
2267 Since descriptors are written in polish prefix notation,
2268 this function can be used recursively to test one operand of EXP
2269 against a subdescriptor, and if it succeeds it returns the
2270 address of the subdescriptor for the next operand. */
2273 compare_constant_1 (exp
, p
)
2277 register char *strp
;
2279 register enum tree_code code
= TREE_CODE (exp
);
2281 if (code
!= (enum tree_code
) *p
++)
2284 if (code
== INTEGER_CST
)
2286 /* Integer constants are the same only if the same width of type. */
2287 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2289 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2290 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2292 else if (code
== REAL_CST
)
2294 /* Real constants are the same only if the same width of type. */
2295 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2297 strp
= (char *) &TREE_REAL_CST (exp
);
2298 len
= sizeof TREE_REAL_CST (exp
);
2300 else if (code
== STRING_CST
)
2302 if (flag_writable_strings
)
2304 strp
= TREE_STRING_POINTER (exp
);
2305 len
= TREE_STRING_LENGTH (exp
);
2306 if (bcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2307 sizeof TREE_STRING_LENGTH (exp
)))
2309 p
+= sizeof TREE_STRING_LENGTH (exp
);
2311 else if (code
== COMPLEX_CST
)
2313 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2314 if (p
== 0) return 0;
2315 p
= compare_constant_1 (TREE_IMAGPART (exp
), p
);
2318 else if (code
== CONSTRUCTOR
&& TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2320 len
= int_size_in_bytes (TREE_TYPE (exp
));
2321 strp
= (char*) alloca (len
);
2322 get_set_constructor_bytes (exp
, (unsigned char *) strp
, len
);
2324 else if (code
== CONSTRUCTOR
)
2327 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2330 if (bcmp ((char *) &length
, p
, sizeof length
))
2334 /* For record constructors, insist that the types match.
2335 For arrays, just verify both constructors are for arrays. */
2336 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2337 type
= TREE_TYPE (exp
);
2340 if (bcmp ((char *) &type
, p
, sizeof type
))
2344 /* For arrays, insist that the size in bytes match. */
2345 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2347 int size
= int_size_in_bytes (TREE_TYPE (exp
));
2348 if (bcmp ((char *) &size
, p
, sizeof size
))
2353 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2355 if (TREE_VALUE (link
))
2357 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2364 if (bcmp ((char *) &zero
, p
, sizeof zero
))
2372 else if (code
== ADDR_EXPR
)
2374 struct addr_const value
;
2375 decode_addr_const (exp
, &value
);
2376 strp
= (char *) &value
.offset
;
2377 len
= sizeof value
.offset
;
2378 /* Compare the offset. */
2380 if (*p
++ != *strp
++)
2382 /* Compare symbol name. */
2383 strp
= XSTR (value
.base
, 0);
2384 len
= strlen (strp
) + 1;
2386 else if (code
== PLUS_EXPR
|| code
== MINUS_EXPR
)
2388 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2389 if (p
== 0) return 0;
2390 p
= compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2393 else if (code
== NOP_EXPR
|| code
== CONVERT_EXPR
)
2395 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2399 /* Compare constant contents. */
2401 if (*p
++ != *strp
++)
2407 /* Construct a constant descriptor for the expression EXP.
2408 It is up to the caller to enter the descriptor in the hash table. */
2410 static struct constant_descriptor
*
2411 record_constant (exp
)
2414 struct constant_descriptor
*next
= 0;
2417 /* Make a struct constant_descriptor. The first two pointers will
2418 be filled in later. Here we just leave space for them. */
2420 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2421 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2422 record_constant_1 (exp
);
2423 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2426 /* Add a description of constant expression EXP
2427 to the object growing in `permanent_obstack'.
2428 No need to return its address; the caller will get that
2429 from the obstack when the object is complete. */
2432 record_constant_1 (exp
)
2435 register char *strp
;
2437 register enum tree_code code
= TREE_CODE (exp
);
2439 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2444 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2445 strp
= (char *) &TREE_INT_CST_LOW (exp
);
2446 len
= 2 * sizeof TREE_INT_CST_LOW (exp
);
2450 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2451 strp
= (char *) &TREE_REAL_CST (exp
);
2452 len
= sizeof TREE_REAL_CST (exp
);
2456 if (flag_writable_strings
)
2459 strp
= TREE_STRING_POINTER (exp
);
2460 len
= TREE_STRING_LENGTH (exp
);
2461 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2462 sizeof TREE_STRING_LENGTH (exp
));
2466 record_constant_1 (TREE_REALPART (exp
));
2467 record_constant_1 (TREE_IMAGPART (exp
));
2471 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2473 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2474 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2475 obstack_blank (&permanent_obstack
, nbytes
);
2476 get_set_constructor_bytes
2477 (exp
, (unsigned char *) permanent_obstack
.next_free
, nbytes
);
2483 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2486 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2488 /* For record constructors, insist that the types match.
2489 For arrays, just verify both constructors are for arrays. */
2490 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2491 type
= TREE_TYPE (exp
);
2494 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2496 /* For arrays, insist that the size in bytes match. */
2497 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2499 int size
= int_size_in_bytes (TREE_TYPE (exp
));
2500 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2503 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2505 if (TREE_VALUE (link
))
2506 record_constant_1 (TREE_VALUE (link
));
2511 obstack_grow (&permanent_obstack
,
2512 (char *) &zero
, sizeof zero
);
2520 struct addr_const value
;
2522 decode_addr_const (exp
, &value
);
2523 /* Record the offset. */
2524 obstack_grow (&permanent_obstack
,
2525 (char *) &value
.offset
, sizeof value
.offset
);
2526 /* Record the symbol name. */
2527 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2528 strlen (XSTR (value
.base
, 0)) + 1);
2534 record_constant_1 (TREE_OPERAND (exp
, 0));
2535 record_constant_1 (TREE_OPERAND (exp
, 1));
2540 case NON_LVALUE_EXPR
:
2541 record_constant_1 (TREE_OPERAND (exp
, 0));
2548 /* Record constant contents. */
2549 obstack_grow (&permanent_obstack
, strp
, len
);
2552 /* Record a list of constant expressions that were passed to
2553 output_constant_def but that could not be output right away. */
2555 struct deferred_constant
2557 struct deferred_constant
*next
;
2563 static struct deferred_constant
*deferred_constants
;
2565 /* Nonzero means defer output of addressed subconstants
2566 (i.e., those for which output_constant_def is called.) */
2567 static int defer_addressed_constants_flag
;
2569 /* Start deferring output of subconstants. */
2572 defer_addressed_constants ()
2574 defer_addressed_constants_flag
++;
2577 /* Stop deferring output of subconstants,
2578 and output now all those that have been deferred. */
2581 output_deferred_addressed_constants ()
2583 struct deferred_constant
*p
, *next
;
2585 defer_addressed_constants_flag
--;
2587 if (defer_addressed_constants_flag
> 0)
2590 for (p
= deferred_constants
; p
; p
= next
)
2592 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2597 deferred_constants
= 0;
2600 /* Make a copy of the whole tree structure for a constant.
2601 This handles the same types of nodes that compare_constant
2602 and record_constant handle. */
2608 switch (TREE_CODE (exp
))
2611 /* For ADDR_EXPR, we do not want to copy the decl whose address
2612 is requested. We do want to copy constants though. */
2613 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2614 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2615 copy_constant (TREE_OPERAND (exp
, 0)));
2617 return copy_node (exp
);
2622 return copy_node (exp
);
2625 return build_complex (copy_constant (TREE_REALPART (exp
)),
2626 copy_constant (TREE_IMAGPART (exp
)));
2630 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2631 copy_constant (TREE_OPERAND (exp
, 0)),
2632 copy_constant (TREE_OPERAND (exp
, 1)));
2636 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2637 copy_constant (TREE_OPERAND (exp
, 0)));
2641 tree copy
= copy_node (exp
);
2642 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2645 CONSTRUCTOR_ELTS (copy
) = list
;
2646 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2647 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2648 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2649 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2650 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
2660 /* Return an rtx representing a reference to constant data in memory
2661 for the constant expression EXP.
2663 If assembler code for such a constant has already been output,
2664 return an rtx to refer to it.
2665 Otherwise, output such a constant in memory (or defer it for later)
2666 and generate an rtx for it.
2668 The TREE_CST_RTL of EXP is set up to point to that rtx.
2669 The const_hash_table records which constants already have label strings. */
2672 output_constant_def (exp
)
2676 register struct constant_descriptor
*desc
;
2682 if (TREE_CODE (exp
) == INTEGER_CST
)
2683 abort (); /* No TREE_CST_RTL slot in these. */
2685 if (TREE_CST_RTL (exp
))
2686 return TREE_CST_RTL (exp
);
2688 /* Make sure any other constants whose addresses appear in EXP
2689 are assigned label numbers. */
2691 reloc
= output_addressed_constants (exp
);
2693 /* Compute hash code of EXP. Search the descriptors for that hash code
2694 to see if any of them describes EXP. If yes, the descriptor records
2695 the label number already assigned. */
2697 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
2699 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
2700 if (compare_constant (exp
, desc
))
2702 found
= desc
->label
;
2708 /* No constant equal to EXP is known to have been output.
2709 Make a constant descriptor to enter EXP in the hash table.
2710 Assign the label number and record it in the descriptor for
2711 future calls to this function to find. */
2713 /* Create a string containing the label name, in LABEL. */
2714 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2716 desc
= record_constant (exp
);
2717 desc
->next
= const_hash_table
[hash
];
2719 = (char *) obstack_copy0 (&permanent_obstack
, label
, strlen (label
));
2720 const_hash_table
[hash
] = desc
;
2724 /* Create a string containing the label name, in LABEL. */
2725 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
2728 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2730 push_obstacks_nochange ();
2731 if (TREE_PERMANENT (exp
))
2732 end_temporary_allocation ();
2734 def
= gen_rtx (SYMBOL_REF
, Pmode
, desc
->label
);
2737 = gen_rtx (MEM
, TYPE_MODE (TREE_TYPE (exp
)), def
);
2738 RTX_UNCHANGING_P (TREE_CST_RTL (exp
)) = 1;
2739 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
)))
2740 MEM_IN_STRUCT_P (TREE_CST_RTL (exp
)) = 1;
2744 /* Optionally set flags or add text to the name to record information
2745 such as that it is a function name. If the name is changed, the macro
2746 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2747 #ifdef ENCODE_SECTION_INFO
2748 ENCODE_SECTION_INFO (exp
);
2751 /* If this is the first time we've seen this particular constant,
2752 output it (or defer its output for later). */
2755 if (defer_addressed_constants_flag
)
2757 struct deferred_constant
*p
;
2758 p
= (struct deferred_constant
*) xmalloc (sizeof (struct deferred_constant
));
2760 push_obstacks_nochange ();
2761 suspend_momentary ();
2762 p
->exp
= copy_constant (exp
);
2765 p
->labelno
= const_labelno
++;
2766 p
->next
= deferred_constants
;
2767 deferred_constants
= p
;
2770 output_constant_def_contents (exp
, reloc
, const_labelno
++);
2773 return TREE_CST_RTL (exp
);
2776 /* Now output assembler code to define the label for EXP,
2777 and follow it with the data of EXP. */
2780 output_constant_def_contents (exp
, reloc
, labelno
)
2787 if (IN_NAMED_SECTION (exp
))
2788 named_section (exp
, NULL
);
2791 /* First switch to text section, except for writable strings. */
2792 #ifdef SELECT_SECTION
2793 SELECT_SECTION (exp
, reloc
);
2795 if (((TREE_CODE (exp
) == STRING_CST
) && flag_writable_strings
)
2796 || (flag_pic
&& reloc
))
2799 readonly_data_section ();
2803 /* Align the location counter as required by EXP's data type. */
2804 align
= TYPE_ALIGN (TREE_TYPE (exp
));
2805 #ifdef CONSTANT_ALIGNMENT
2806 align
= CONSTANT_ALIGNMENT (exp
, align
);
2809 if (align
> BITS_PER_UNIT
)
2811 if (!output_bytecode
)
2813 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2817 BC_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2821 /* Output the label itself. */
2822 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
2824 /* Output the value of EXP. */
2825 output_constant (exp
,
2826 (TREE_CODE (exp
) == STRING_CST
2827 ? TREE_STRING_LENGTH (exp
)
2828 : int_size_in_bytes (TREE_TYPE (exp
))));
2832 /* Similar hash facility for making memory-constants
2833 from constant rtl-expressions. It is used on RISC machines
2834 where immediate integer arguments and constant addresses are restricted
2835 so that such constants must be stored in memory.
2837 This pool of constants is reinitialized for each function
2838 so each function gets its own constants-pool that comes right before it.
2840 All structures allocated here are discarded when functions are saved for
2841 inlining, so they do not need to be allocated permanently. */
2843 #define MAX_RTX_HASH_TABLE 61
2844 static struct constant_descriptor
**const_rtx_hash_table
;
2846 /* Structure to represent sufficient information about a constant so that
2847 it can be output when the constant pool is output, so that function
2848 integration can be done, and to simplify handling on machines that reference
2849 constant pool as base+displacement. */
2851 struct pool_constant
2853 struct constant_descriptor
*desc
;
2854 struct pool_constant
*next
;
2855 enum machine_mode mode
;
2862 /* Pointers to first and last constant in pool. */
2864 static struct pool_constant
*first_pool
, *last_pool
;
2866 /* Current offset in constant pool (does not include any machine-specific
2869 static int pool_offset
;
2871 /* Structure used to maintain hash table mapping symbols used to their
2872 corresponding constants. */
2877 struct pool_constant
*pool
;
2878 struct pool_sym
*next
;
2881 static struct pool_sym
**const_rtx_sym_hash_table
;
2883 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2884 The argument is XSTR (... , 0) */
2886 #define SYMHASH(LABEL) \
2887 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2889 /* Initialize constant pool hashing for next function. */
2892 init_const_rtx_hash_table ()
2894 const_rtx_hash_table
2895 = ((struct constant_descriptor
**)
2896 oballoc (MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*)));
2897 const_rtx_sym_hash_table
2898 = ((struct pool_sym
**)
2899 oballoc (MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*)));
2900 bzero ((char *) const_rtx_hash_table
,
2901 MAX_RTX_HASH_TABLE
* sizeof (struct constant_descriptor
*));
2902 bzero ((char *) const_rtx_sym_hash_table
,
2903 MAX_RTX_HASH_TABLE
* sizeof (struct pool_sym
*));
2905 first_pool
= last_pool
= 0;
2909 /* Save and restore status for a nested function. */
2912 save_varasm_status (p
)
2915 p
->const_rtx_hash_table
= const_rtx_hash_table
;
2916 p
->const_rtx_sym_hash_table
= const_rtx_sym_hash_table
;
2917 p
->first_pool
= first_pool
;
2918 p
->last_pool
= last_pool
;
2919 p
->pool_offset
= pool_offset
;
2923 restore_varasm_status (p
)
2926 const_rtx_hash_table
= p
->const_rtx_hash_table
;
2927 const_rtx_sym_hash_table
= p
->const_rtx_sym_hash_table
;
2928 first_pool
= p
->first_pool
;
2929 last_pool
= p
->last_pool
;
2930 pool_offset
= p
->pool_offset
;
2933 enum kind
{ RTX_DOUBLE
, RTX_INT
};
2937 #ifdef ONLY_INT_FIELDS
2938 unsigned int kind
: 16;
2939 unsigned int mode
: 16;
2941 enum kind kind
: 16;
2942 enum machine_mode mode
: 16;
2945 union real_extract du
;
2946 struct addr_const addr
;
2947 struct {HOST_WIDE_INT high
, low
;} di
;
2951 /* Express an rtx for a constant integer (perhaps symbolic)
2952 as the sum of a symbol or label plus an explicit integer.
2953 They are stored into VALUE. */
2956 decode_rtx_const (mode
, x
, value
)
2957 enum machine_mode mode
;
2959 struct rtx_const
*value
;
2961 /* Clear the whole structure, including any gaps. */
2964 int *p
= (int *) value
;
2965 int *end
= (int *) (value
+ 1);
2970 value
->kind
= RTX_INT
; /* Most usual kind. */
2973 switch (GET_CODE (x
))
2976 value
->kind
= RTX_DOUBLE
;
2977 if (GET_MODE (x
) != VOIDmode
)
2979 value
->mode
= GET_MODE (x
);
2980 bcopy ((char *) &CONST_DOUBLE_LOW (x
),
2981 (char *) &value
->un
.du
, sizeof value
->un
.du
);
2985 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
2986 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
2991 value
->un
.addr
.offset
= INTVAL (x
);
2997 value
->un
.addr
.base
= x
;
3002 if (GET_CODE (x
) == PLUS
)
3004 value
->un
.addr
.base
= XEXP (x
, 0);
3005 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3007 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3009 else if (GET_CODE (x
) == MINUS
)
3011 value
->un
.addr
.base
= XEXP (x
, 0);
3012 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
3014 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3024 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0)
3025 switch (GET_CODE (value
->un
.addr
.base
))
3029 /* Use the string's address, not the SYMBOL_REF's address,
3030 for the sake of addresses of library routines.
3031 For a LABEL_REF, compare labels. */
3032 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3036 /* Given a MINUS expression, simplify it if both sides
3037 include the same symbol. */
3040 simplify_subtraction (x
)
3043 struct rtx_const val0
, val1
;
3045 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3046 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3048 if (val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3049 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3053 /* Compute a hash code for a constant RTL expression. */
3056 const_hash_rtx (mode
, x
)
3057 enum machine_mode mode
;
3062 struct rtx_const value
;
3063 decode_rtx_const (mode
, x
, &value
);
3065 /* Compute hashing function */
3067 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3068 hi
+= ((int *) &value
)[i
];
3070 hi
&= (1 << HASHBITS
) - 1;
3071 hi
%= MAX_RTX_HASH_TABLE
;
3075 /* Compare a constant rtl object X with a constant-descriptor DESC.
3076 Return 1 if DESC describes a constant with the same value as X. */
3079 compare_constant_rtx (mode
, x
, desc
)
3080 enum machine_mode mode
;
3082 struct constant_descriptor
*desc
;
3084 register int *p
= (int *) desc
->contents
;
3087 struct rtx_const value
;
3089 decode_rtx_const (mode
, x
, &value
);
3090 strp
= (int *) &value
;
3091 len
= sizeof value
/ sizeof (int);
3093 /* Compare constant contents. */
3095 if (*p
++ != *strp
++)
3101 /* Construct a constant descriptor for the rtl-expression X.
3102 It is up to the caller to enter the descriptor in the hash table. */
3104 static struct constant_descriptor
*
3105 record_constant_rtx (mode
, x
)
3106 enum machine_mode mode
;
3109 struct constant_descriptor
*ptr
;
3111 struct rtx_const value
;
3113 decode_rtx_const (mode
, x
, &value
);
3115 /* Put these things in the saveable obstack so we can ensure it won't
3116 be freed if we are called from combine or some other phase that discards
3117 memory allocated from function_obstack (current_obstack). */
3118 obstack_grow (saveable_obstack
, &ptr
, sizeof ptr
);
3119 obstack_grow (saveable_obstack
, &label
, sizeof label
);
3121 /* Record constant contents. */
3122 obstack_grow (saveable_obstack
, &value
, sizeof value
);
3124 return (struct constant_descriptor
*) obstack_finish (saveable_obstack
);
3127 /* Given a constant rtx X, make (or find) a memory constant for its value
3128 and return a MEM rtx to refer to it in memory. */
3131 force_const_mem (mode
, x
)
3132 enum machine_mode mode
;
3136 register struct constant_descriptor
*desc
;
3141 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3142 (this will always be true for floating CONST_DOUBLEs that have been
3143 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3144 use the previous copy. Otherwise, make a new one. Note that in
3145 the unlikely event that this same CONST_DOUBLE is used in two different
3146 modes in an alternating fashion, we will allocate a lot of different
3147 memory locations, but this should be extremely rare. */
3149 /* Don't use CONST_DOUBLE_MEM in a nested function.
3150 Nested functions have their own constant pools,
3151 so they can't share the same values in CONST_DOUBLE_MEM
3152 with the containing function. */
3153 if (outer_function_chain
== 0)
3154 if (GET_CODE (x
) == CONST_DOUBLE
3155 && GET_CODE (CONST_DOUBLE_MEM (x
)) == MEM
3156 && GET_MODE (CONST_DOUBLE_MEM (x
)) == mode
)
3157 return CONST_DOUBLE_MEM (x
);
3159 /* Compute hash code of X. Search the descriptors for that hash code
3160 to see if any of them describes X. If yes, the descriptor records
3161 the label number already assigned. */
3163 hash
= const_hash_rtx (mode
, x
);
3165 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3166 if (compare_constant_rtx (mode
, x
, desc
))
3168 found
= desc
->label
;
3174 register struct pool_constant
*pool
;
3175 register struct pool_sym
*sym
;
3178 /* No constant equal to X is known to have been output.
3179 Make a constant descriptor to enter X in the hash table.
3180 Assign the label number and record it in the descriptor for
3181 future calls to this function to find. */
3183 desc
= record_constant_rtx (mode
, x
);
3184 desc
->next
= const_rtx_hash_table
[hash
];
3185 const_rtx_hash_table
[hash
] = desc
;
3187 /* Align the location counter as required by EXP's data type. */
3188 align
= (mode
== VOIDmode
) ? UNITS_PER_WORD
: GET_MODE_SIZE (mode
);
3189 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
3190 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
3192 pool_offset
+= align
- 1;
3193 pool_offset
&= ~ (align
- 1);
3195 /* If RTL is not being placed into the saveable obstack, make a
3196 copy of X that is in the saveable obstack in case we are being
3197 called from combine or some other phase that discards memory
3198 it allocates. We need only do this if it is a CONST, since
3199 no other RTX should be allocated in this situation. */
3200 if (rtl_obstack
!= saveable_obstack
3201 && GET_CODE (x
) == CONST
)
3203 push_obstacks_nochange ();
3204 rtl_in_saveable_obstack ();
3206 x
= gen_rtx (CONST
, GET_MODE (x
),
3207 gen_rtx (PLUS
, GET_MODE (x
),
3208 XEXP (XEXP (x
, 0), 0), XEXP (XEXP (x
, 0), 1)));
3212 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3214 pool
= (struct pool_constant
*) savealloc (sizeof (struct pool_constant
));
3218 pool
->labelno
= const_labelno
;
3219 pool
->align
= align
;
3220 pool
->offset
= pool_offset
;
3226 last_pool
->next
= pool
;
3229 pool_offset
+= GET_MODE_SIZE (mode
);
3231 /* Create a string containing the label name, in LABEL. */
3232 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3237 = (char *) obstack_copy0 (saveable_obstack
, label
, strlen (label
));
3239 /* Add label to symbol hash table. */
3240 hash
= SYMHASH (found
);
3241 sym
= (struct pool_sym
*) savealloc (sizeof (struct pool_sym
));
3244 sym
->next
= const_rtx_sym_hash_table
[hash
];
3245 const_rtx_sym_hash_table
[hash
] = sym
;
3248 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3250 def
= gen_rtx (MEM
, mode
, gen_rtx (SYMBOL_REF
, Pmode
, found
));
3252 RTX_UNCHANGING_P (def
) = 1;
3253 /* Mark the symbol_ref as belonging to this constants pool. */
3254 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3255 current_function_uses_const_pool
= 1;
3257 if (outer_function_chain
== 0)
3258 if (GET_CODE (x
) == CONST_DOUBLE
)
3260 if (CONST_DOUBLE_MEM (x
) == cc0_rtx
)
3262 CONST_DOUBLE_CHAIN (x
) = const_double_chain
;
3263 const_double_chain
= x
;
3265 CONST_DOUBLE_MEM (x
) = def
;
3271 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3272 the corresponding pool_constant structure. */
3274 static struct pool_constant
*
3275 find_pool_constant (addr
)
3278 struct pool_sym
*sym
;
3279 char *label
= XSTR (addr
, 0);
3281 for (sym
= const_rtx_sym_hash_table
[SYMHASH (label
)]; sym
; sym
= sym
->next
)
3282 if (sym
->label
== label
)
3288 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3291 get_pool_constant (addr
)
3294 return (find_pool_constant (addr
))->constant
;
3297 /* Similar, return the mode. */
3300 get_pool_mode (addr
)
3303 return (find_pool_constant (addr
))->mode
;
3306 /* Similar, return the offset in the constant pool. */
3309 get_pool_offset (addr
)
3312 return (find_pool_constant (addr
))->offset
;
3315 /* Return the size of the constant pool. */
3323 /* Write all the constants in the constant pool. */
3326 output_constant_pool (fnname
, fndecl
)
3330 struct pool_constant
*pool
;
3332 union real_extract u
;
3334 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3335 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3338 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3342 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3343 whose CODE_LABEL has been deleted. This can occur if a jump table
3344 is eliminated by optimization. If so, write a constant of zero
3345 instead. Note that this can also happen by turning the
3346 CODE_LABEL into a NOTE. */
3347 if (((GET_CODE (x
) == LABEL_REF
3348 && (INSN_DELETED_P (XEXP (x
, 0))
3349 || GET_CODE (XEXP (x
, 0)) == NOTE
)))
3350 || (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
3351 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
3352 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x
, 0), 0), 0))
3353 || GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == NOTE
)))
3356 /* First switch to correct section. */
3357 #ifdef SELECT_RTX_SECTION
3358 SELECT_RTX_SECTION (pool
->mode
, x
);
3360 readonly_data_section ();
3363 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3364 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3365 pool
->align
, pool
->labelno
, done
);
3368 if (pool
->align
> 1)
3369 ASM_OUTPUT_ALIGN (asm_out_file
, exact_log2 (pool
->align
));
3371 /* Output the label. */
3372 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3374 /* Output the value of the constant itself. */
3375 switch (GET_MODE_CLASS (pool
->mode
))
3378 if (GET_CODE (x
) != CONST_DOUBLE
)
3381 bcopy ((char *) &CONST_DOUBLE_LOW (x
), (char *) &u
, sizeof u
);
3382 assemble_real (u
.d
, pool
->mode
);
3386 case MODE_PARTIAL_INT
:
3387 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), 1);
3397 /* Done with this pool. */
3398 first_pool
= last_pool
= 0;
3401 /* Find all the constants whose addresses are referenced inside of EXP,
3402 and make sure assembler code with a label has been output for each one.
3403 Indicate whether an ADDR_EXPR has been encountered. */
3406 output_addressed_constants (exp
)
3411 switch (TREE_CODE (exp
))
3415 register tree constant
= TREE_OPERAND (exp
, 0);
3417 while (TREE_CODE (constant
) == COMPONENT_REF
)
3419 constant
= TREE_OPERAND (constant
, 0);
3422 if (TREE_CODE_CLASS (TREE_CODE (constant
)) == 'c'
3423 || TREE_CODE (constant
) == CONSTRUCTOR
)
3424 /* No need to do anything here
3425 for addresses of variables or functions. */
3426 output_constant_def (constant
);
3433 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3434 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3439 case NON_LVALUE_EXPR
:
3440 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3446 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
3447 if (TREE_VALUE (link
) != 0)
3448 reloc
|= output_addressed_constants (TREE_VALUE (link
));
3458 /* Output assembler code for constant EXP to FILE, with no label.
3459 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3460 Assumes output_addressed_constants has been done on EXP already.
3462 Generate exactly SIZE bytes of assembler data, padding at the end
3463 with zeros if necessary. SIZE must always be specified.
3465 SIZE is important for structure constructors,
3466 since trailing members may have been omitted from the constructor.
3467 It is also important for initialization of arrays from string constants
3468 since the full length of the string constant might not be wanted.
3469 It is also needed for initialization of unions, where the initializer's
3470 type is just one member, and that may not be as long as the union.
3472 There a case in which we would fail to output exactly SIZE bytes:
3473 for a structure constructor that wants to produce more than SIZE bytes.
3474 But such constructors will never be generated for any possible input. */
3477 output_constant (exp
, size
)
3481 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
3487 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3488 That way we get the constant (we hope) inside it. Also, strip off any
3489 NOP_EXPR that converts between two record, union, array, or set types. */
3490 while ((TREE_CODE (exp
) == NOP_EXPR
3491 && (TREE_TYPE (exp
) == TREE_TYPE (TREE_OPERAND (exp
, 0))
3492 || AGGREGATE_TYPE_P (TREE_TYPE (exp
))))
3493 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3494 exp
= TREE_OPERAND (exp
, 0);
3496 /* Allow a constructor with no elements for any data type.
3497 This means to fill the space with zeros. */
3498 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
3500 if (output_bytecode
)
3501 bc_emit_const_skip (size
);
3503 assemble_zeros (size
);
3514 case REFERENCE_TYPE
:
3515 /* ??? What about (int)((float)(int)&foo + 4) */
3516 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3517 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
3518 exp
= TREE_OPERAND (exp
, 0);
3520 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3521 EXPAND_INITIALIZER
),
3523 error ("initializer for integer value is too complicated");
3528 if (TREE_CODE (exp
) != REAL_CST
)
3529 error ("initializer for floating value is not a floating constant");
3531 assemble_real (TREE_REAL_CST (exp
),
3532 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0));
3537 output_constant (TREE_REALPART (exp
), size
/ 2);
3538 output_constant (TREE_IMAGPART (exp
), size
/ 2);
3539 size
-= (size
/ 2) * 2;
3543 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3545 output_constructor (exp
, size
);
3548 else if (TREE_CODE (exp
) == STRING_CST
)
3552 if (size
> TREE_STRING_LENGTH (exp
))
3554 excess
= size
- TREE_STRING_LENGTH (exp
);
3555 size
= TREE_STRING_LENGTH (exp
);
3558 assemble_string (TREE_STRING_POINTER (exp
), size
);
3567 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3568 output_constructor (exp
, size
);
3574 if (TREE_CODE (exp
) == INTEGER_CST
)
3575 assemble_integer (expand_expr (exp
, NULL_RTX
,
3576 VOIDmode
, EXPAND_INITIALIZER
),
3578 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
3580 unsigned char *buffer
= (unsigned char *) alloca (size
);
3581 if (get_set_constructor_bytes (exp
, buffer
, size
))
3583 assemble_string ((char *) buffer
, size
);
3586 error ("unknown set constructor type");
3591 assemble_zeros (size
);
3594 /* Bytecode specific code to output assembler for integer. */
3597 bc_assemble_integer (exp
, size
)
3605 /* FIXME: is this fold() business going to be as good as the
3606 expand_expr() using EXPAND_SUM above in the RTL case? I
3608 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3612 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
)
3613 exp
= TREE_OPERAND (exp
, 0);
3614 if (TREE_CODE (exp
) == INTEGER_CST
)
3619 else if (TREE_CODE (exp
) == PLUS_EXPR
)
3621 const_part
= TREE_OPERAND (exp
, 0);
3622 while (TREE_CODE (const_part
) == NOP_EXPR
3623 || TREE_CODE (const_part
) == CONVERT_EXPR
)
3624 const_part
= TREE_OPERAND (const_part
, 0);
3625 addr_part
= TREE_OPERAND (exp
, 1);
3626 while (TREE_CODE (addr_part
) == NOP_EXPR
3627 || TREE_CODE (addr_part
) == CONVERT_EXPR
)
3628 addr_part
= TREE_OPERAND (addr_part
, 0);
3629 if (TREE_CODE (const_part
) != INTEGER_CST
)
3630 tmp
= const_part
, const_part
= addr_part
, addr_part
= tmp
;
3631 if (TREE_CODE (const_part
) != INTEGER_CST
3632 || TREE_CODE (addr_part
) != ADDR_EXPR
)
3633 abort (); /* FIXME: we really haven't considered
3634 all the possible cases here. */
3636 else if (TREE_CODE (exp
) == ADDR_EXPR
)
3638 const_part
= integer_zero_node
;
3642 abort (); /* FIXME: ditto previous. */
3648 char c
= TREE_INT_CST_LOW (const_part
);
3654 short s
= TREE_INT_CST_LOW (const_part
);
3655 bc_emit ((char *) &s
, 2);
3660 int i
= TREE_INT_CST_LOW (const_part
);
3661 bc_emit ((char *) &i
, 4);
3666 if (WORDS_BIG_ENDIAN
)
3668 int i
= TREE_INT_CST_HIGH (const_part
);
3669 bc_emit ((char *) &i
, 4);
3670 i
= TREE_INT_CST_LOW (const_part
);
3671 bc_emit ((char *) &i
, 4);
3675 int i
= TREE_INT_CST_LOW (const_part
);
3676 bc_emit ((char *) &i
, 4);
3677 i
= TREE_INT_CST_HIGH (const_part
);
3678 bc_emit ((char *) &i
, 4);
3685 && TREE_CODE (TREE_OPERAND (addr_part
, 0)) == VAR_DECL
)
3686 bc_emit_labelref (IDENTIFIER_POINTER
3687 (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part
, 0))),
3688 TREE_INT_CST_LOW (const_part
));
3690 abort (); /* FIXME: there may be more cases. */
3693 /* Subroutine of output_constant, used for CONSTRUCTORs
3694 (aggregate constants).
3695 Generate at least SIZE bytes, padding if necessary. */
3698 output_constructor (exp
, size
)
3702 register tree link
, field
= 0;
3703 HOST_WIDE_INT min_index
= 0;
3704 /* Number of bytes output or skipped so far.
3705 In other words, current position within the constructor. */
3706 int total_bytes
= 0;
3707 /* Non-zero means BYTE contains part of a byte, to be output. */
3708 int byte_buffer_in_use
= 0;
3711 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
3714 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
3715 field
= TYPE_FIELDS (TREE_TYPE (exp
));
3717 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
3718 && TYPE_DOMAIN (TREE_TYPE (exp
)) != 0)
3720 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp
))));
3722 /* As LINK goes through the elements of the constant,
3723 FIELD goes through the structure fields, if the constant is a structure.
3724 if the constant is a union, then we override this,
3725 by getting the field from the TREE_LIST element.
3726 But the constant could also be an array. Then FIELD is zero. */
3727 for (link
= CONSTRUCTOR_ELTS (exp
);
3729 link
= TREE_CHAIN (link
),
3730 field
= field
? TREE_CHAIN (field
) : 0)
3732 tree val
= TREE_VALUE (link
);
3735 /* the element in a union constructor specifies the proper field. */
3737 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
3738 || TREE_CODE (TREE_TYPE (exp
)) == UNION_TYPE
)
3740 /* if available, use the type given by link */
3741 if (TREE_PURPOSE (link
) != 0)
3742 field
= TREE_PURPOSE (link
);
3745 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
3746 index
= TREE_PURPOSE (link
);
3748 /* Eliminate the marker that makes a cast not be an lvalue. */
3752 if (field
== 0 || !DECL_BIT_FIELD (field
))
3754 /* An element that is not a bit-field. */
3756 register int fieldsize
;
3757 /* Since this structure is static,
3758 we know the positions are constant. */
3759 int bitpos
= (field
? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
))
3763 bitpos
= (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val
)))
3765 * (TREE_INT_CST_LOW (index
) - min_index
));
3767 /* Output any buffered-up bit-fields preceding this element. */
3768 if (byte_buffer_in_use
)
3770 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
3772 byte_buffer_in_use
= 0;
3775 /* Advance to offset of this element.
3776 Note no alignment needed in an array, since that is guaranteed
3777 if each element has the proper size. */
3778 if ((field
!= 0 || index
!= 0) && bitpos
!= total_bytes
)
3780 if (!output_bytecode
)
3781 assemble_zeros (bitpos
- total_bytes
);
3783 bc_emit_const_skip (bitpos
- total_bytes
);
3784 total_bytes
= bitpos
;
3787 /* Determine size this element should occupy. */
3790 if (TREE_CODE (DECL_SIZE (field
)) != INTEGER_CST
)
3792 if (TREE_INT_CST_LOW (DECL_SIZE (field
)) > 100000)
3794 /* This avoids overflow trouble. */
3795 tree size_tree
= size_binop (CEIL_DIV_EXPR
,
3797 size_int (BITS_PER_UNIT
));
3798 fieldsize
= TREE_INT_CST_LOW (size_tree
);
3802 fieldsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
3803 fieldsize
= (fieldsize
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
3807 fieldsize
= int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp
)));
3809 /* Output the element's initial value. */
3811 assemble_zeros (fieldsize
);
3813 output_constant (val
, fieldsize
);
3815 /* Count its size. */
3816 total_bytes
+= fieldsize
;
3818 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
3819 error ("invalid initial value for member `%s'",
3820 IDENTIFIER_POINTER (DECL_NAME (field
)));
3823 /* Element that is a bit-field. */
3825 int next_offset
= TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
));
3827 = (next_offset
+ TREE_INT_CST_LOW (DECL_SIZE (field
)));
3830 val
= integer_zero_node
;
3832 /* If this field does not start in this (or, next) byte,
3834 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
3836 /* Output remnant of any bit field in previous bytes. */
3837 if (byte_buffer_in_use
)
3839 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
3841 byte_buffer_in_use
= 0;
3844 /* If still not at proper byte, advance to there. */
3845 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
3847 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
3848 total_bytes
= next_offset
/ BITS_PER_UNIT
;
3852 if (! byte_buffer_in_use
)
3855 /* We must split the element into pieces that fall within
3856 separate bytes, and combine each byte with previous or
3857 following bit-fields. */
3859 /* next_offset is the offset n fbits from the beginning of
3860 the structure to the next bit of this element to be processed.
3861 end_offset is the offset of the first bit past the end of
3863 while (next_offset
< end_offset
)
3867 HOST_WIDE_INT value
;
3868 int next_byte
= next_offset
/ BITS_PER_UNIT
;
3869 int next_bit
= next_offset
% BITS_PER_UNIT
;
3871 /* Advance from byte to byte
3872 within this element when necessary. */
3873 while (next_byte
!= total_bytes
)
3875 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
3880 /* Number of bits we can process at once
3881 (all part of the same byte). */
3882 this_time
= MIN (end_offset
- next_offset
,
3883 BITS_PER_UNIT
- next_bit
);
3884 if (BYTES_BIG_ENDIAN
)
3886 /* On big-endian machine, take the most significant bits
3887 first (of the bits that are significant)
3888 and put them into bytes from the most significant end. */
3889 shift
= end_offset
- next_offset
- this_time
;
3890 /* Don't try to take a bunch of bits that cross
3891 the word boundary in the INTEGER_CST. */
3892 if (shift
< HOST_BITS_PER_WIDE_INT
3893 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
3895 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
3896 shift
= HOST_BITS_PER_WIDE_INT
;
3899 /* Now get the bits from the appropriate constant word. */
3900 if (shift
< HOST_BITS_PER_WIDE_INT
)
3902 value
= TREE_INT_CST_LOW (val
);
3904 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
3906 value
= TREE_INT_CST_HIGH (val
);
3907 shift
-= HOST_BITS_PER_WIDE_INT
;
3911 byte
|= (((value
>> shift
)
3912 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
3913 << (BITS_PER_UNIT
- this_time
- next_bit
));
3917 /* On little-endian machines,
3918 take first the least significant bits of the value
3919 and pack them starting at the least significant
3920 bits of the bytes. */
3921 shift
= (next_offset
3922 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field
)));
3923 /* Don't try to take a bunch of bits that cross
3924 the word boundary in the INTEGER_CST. */
3925 if (shift
< HOST_BITS_PER_WIDE_INT
3926 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
3928 this_time
-= (HOST_BITS_PER_WIDE_INT
- shift
);
3929 shift
= HOST_BITS_PER_WIDE_INT
;
3932 /* Now get the bits from the appropriate constant word. */
3933 if (shift
< HOST_BITS_PER_INT
)
3934 value
= TREE_INT_CST_LOW (val
);
3935 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
3937 value
= TREE_INT_CST_HIGH (val
);
3938 shift
-= HOST_BITS_PER_WIDE_INT
;
3942 byte
|= (((value
>> shift
)
3943 & (((HOST_WIDE_INT
) 1 << this_time
) - 1))
3946 next_offset
+= this_time
;
3947 byte_buffer_in_use
= 1;
3951 if (byte_buffer_in_use
)
3953 ASM_OUTPUT_BYTE (asm_out_file
, byte
);
3956 if (total_bytes
< size
)
3957 assemble_zeros (size
- total_bytes
);
3960 /* Output asm to handle ``#pragma weak'' */
3962 handle_pragma_weak (what
, name
, value
)
3963 enum pragma_state what
;
3966 #ifdef HANDLE_PRAGMA_WEAK
3967 if (what
== ps_name
|| what
== ps_value
)
3969 struct weak_syms
*weak
=
3970 (struct weak_syms
*)permalloc (sizeof (struct weak_syms
));
3971 weak
->next
= weak_decls
;
3972 weak
->name
= permalloc (strlen (name
) + 1);
3973 strcpy (weak
->name
, name
);
3975 if (what
!= ps_value
)
3976 weak
->value
= NULL_PTR
;
3980 weak
->value
= permalloc (strlen (value
) + 1);
3981 strcpy (weak
->value
, value
);
3986 else if (! (what
== ps_done
|| what
== ps_start
))
3987 warning ("malformed `#pragma weak'");
3988 #endif /* HANDLE_PRAGMA_WEAK */
3991 /* Declare DECL to be a weak symbol. */
3997 if (! TREE_PUBLIC (decl
))
3998 error_with_decl (decl
, "weak declaration of `%s' must be public");
3999 else if (TREE_ASM_WRITTEN (decl
))
4000 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4001 else if (SUPPORTS_WEAK
)
4002 DECL_WEAK (decl
) = 1;
4005 /* Emit any pending weak declarations. */
4010 #ifdef HANDLE_PRAGMA_WEAK
4011 if (HANDLE_PRAGMA_WEAK
)
4013 struct weak_syms
*t
;
4014 for (t
= weak_decls
; t
; t
= t
->next
)
4016 ASM_WEAKEN_LABEL (asm_out_file
, t
->name
);
4018 ASM_OUTPUT_DEF (asm_out_file
, t
->name
, t
->value
);
4025 assemble_alias (decl
, target
)
4028 #ifdef ASM_OUTPUT_DEF
4031 make_decl_rtl (decl
, (char*)0, 1);
4032 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4034 /* Make name accessible from other files, if appropriate. */
4036 if (TREE_PUBLIC (decl
))
4038 #ifdef ASM_WEAKEN_LABEL
4039 if (DECL_WEAK (decl
))
4040 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4043 if (output_bytecode
)
4044 BC_GLOBALIZE_LABEL (asm_out_file
, name
);
4046 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4049 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4050 TREE_ASM_WRITTEN (decl
) = 1;
4052 warning ("alias definitions not supported in this configuration");