]>
Commit | Line | Data |
---|---|---|
79e68feb | 1 | /* Output variables, constants and external declarations, for GNU compiler. |
e5e809f4 | 2 | Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc. |
79e68feb RS |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
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) | |
9 | any later version. | |
10 | ||
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. | |
15 | ||
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 | |
e9fa0c7c RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
79e68feb RS |
20 | |
21 | ||
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. | |
25 | ||
26 | We also output the assembler code for constants stored in memory | |
27 | and are responsible for combining constants with the same value. */ | |
28 | ||
e9a25f70 | 29 | #include "config.h" |
670ee920 | 30 | #include "system.h" |
79e68feb RS |
31 | #include <setjmp.h> |
32 | /* #include <stab.h> */ | |
79e68feb RS |
33 | #include "rtl.h" |
34 | #include "tree.h" | |
35 | #include "flags.h" | |
6adb4e3a | 36 | #include "except.h" |
57632c51 | 37 | #include "function.h" |
79e68feb | 38 | #include "expr.h" |
5a13eaa4 | 39 | #include "output.h" |
79e68feb RS |
40 | #include "hard-reg-set.h" |
41 | #include "regs.h" | |
9a631e8e | 42 | #include "defaults.h" |
24b09b50 | 43 | #include "real.h" |
79e68feb RS |
44 | |
45 | #include "obstack.h" | |
3d6f7931 | 46 | #include "c-pragma.h" |
79e68feb | 47 | |
b4ac57ab | 48 | #ifdef XCOFF_DEBUGGING_INFO |
f246a305 | 49 | #include "xcoffout.h" |
b4ac57ab RS |
50 | #endif |
51 | ||
073b0524 RK |
52 | #ifndef TRAMPOLINE_ALIGNMENT |
53 | #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY | |
54 | #endif | |
55 | ||
79e68feb RS |
56 | #ifndef ASM_STABS_OP |
57 | #define ASM_STABS_OP ".stabs" | |
58 | #endif | |
59 | ||
7c6d4120 RK |
60 | /* Define the prefix to use when check_memory_usage_flag is enable. */ |
61 | #ifdef NO_DOLLAR_IN_LABEL | |
62 | #ifdef NO_DOT_IN_LABEL | |
63 | #define CHKR_PREFIX "chkr_prefix_" | |
64 | #else /* !NO_DOT_IN_LABEL */ | |
65 | #define CHKR_PREFIX "chkr." | |
66 | #endif | |
956d6950 | 67 | #else /* !NO_DOLLAR_IN_LABEL */ |
7c6d4120 RK |
68 | #define CHKR_PREFIX "chkr$" |
69 | #endif | |
70 | #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1) | |
71 | ||
561e6650 RS |
72 | /* This macro gets just the user-specified name |
73 | out of the string in a SYMBOL_REF. On most machines, | |
74 | we discard the * if any and that's all. */ | |
75 | #ifndef STRIP_NAME_ENCODING | |
76 | #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \ | |
77 | (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*')) | |
78 | #endif | |
79 | ||
79e68feb RS |
80 | /* File in which assembler code is being written. */ |
81 | ||
82 | extern FILE *asm_out_file; | |
83 | ||
84 | /* The (assembler) name of the first globally-visible object output. */ | |
85 | char *first_global_object_name; | |
86 | ||
87 | extern struct obstack *current_obstack; | |
88 | extern struct obstack *saveable_obstack; | |
75974726 | 89 | extern struct obstack *rtl_obstack; |
79e68feb RS |
90 | extern struct obstack permanent_obstack; |
91 | #define obstack_chunk_alloc xmalloc | |
79e68feb RS |
92 | |
93 | /* Number for making the label on the next | |
94 | constant that is stored in memory. */ | |
95 | ||
96 | int const_labelno; | |
97 | ||
98 | /* Number for making the label on the next | |
99 | static variable internal to a function. */ | |
100 | ||
101 | int var_labelno; | |
102 | ||
dcc8e5e6 RS |
103 | /* Carry information from ASM_DECLARE_OBJECT_NAME |
104 | to ASM_FINISH_DECLARE_OBJECT. */ | |
105 | ||
106 | int size_directive_output; | |
107 | ||
cbed4565 RS |
108 | /* The last decl for which assemble_variable was called, |
109 | if it did ASM_DECLARE_OBJECT_NAME. | |
110 | If the last call to assemble_variable didn't do that, | |
111 | this holds 0. */ | |
112 | ||
113 | tree last_assemble_variable_decl; | |
114 | ||
79e68feb | 115 | |
3d6f7931 | 116 | #ifdef HANDLE_PRAGMA_WEAK |
4b8af8d9 JM |
117 | /* Any weak symbol declarations waiting to be emitted. */ |
118 | ||
eb0430f0 MM |
119 | struct weak_syms |
120 | { | |
121 | struct weak_syms *next; | |
122 | char *name; | |
123 | char *value; | |
124 | }; | |
125 | ||
126 | static struct weak_syms *weak_decls; | |
127 | #endif | |
128 | ||
129 | /* Nonzero if at least one function definition has been seen. */ | |
130 | ||
131 | static int function_defined; | |
4b8af8d9 | 132 | |
5a13eaa4 RK |
133 | struct addr_const; |
134 | struct constant_descriptor; | |
135 | struct rtx_const; | |
136 | struct pool_constant; | |
137 | ||
5a13eaa4 | 138 | static char *strip_reg_name PROTO((char *)); |
5a13eaa4 RK |
139 | static int contains_pointers_p PROTO((tree)); |
140 | static void decode_addr_const PROTO((tree, struct addr_const *)); | |
141 | static int const_hash PROTO((tree)); | |
142 | static int compare_constant PROTO((tree, | |
143 | struct constant_descriptor *)); | |
144 | static char *compare_constant_1 PROTO((tree, char *)); | |
145 | static struct constant_descriptor *record_constant PROTO((tree)); | |
146 | static void record_constant_1 PROTO((tree)); | |
147 | static tree copy_constant PROTO((tree)); | |
148 | static void output_constant_def_contents PROTO((tree, int, int)); | |
149 | static void decode_rtx_const PROTO((enum machine_mode, rtx, | |
150 | struct rtx_const *)); | |
151 | static int const_hash_rtx PROTO((enum machine_mode, rtx)); | |
152 | static int compare_constant_rtx PROTO((enum machine_mode, rtx, | |
153 | struct constant_descriptor *)); | |
154 | static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode, | |
155 | rtx)); | |
156 | static struct pool_constant *find_pool_constant PROTO((rtx)); | |
91674c37 ILT |
157 | static void mark_constant_pool PROTO((void)); |
158 | static void mark_constants PROTO((rtx)); | |
5a13eaa4 | 159 | static int output_addressed_constants PROTO((tree)); |
8839fca4 | 160 | static void output_after_function_constants PROTO((void)); |
5a13eaa4 | 161 | static void output_constructor PROTO((tree, int)); |
79e68feb | 162 | \f |
e5887033 DE |
163 | static enum in_section { no_section, in_text, in_data, in_named |
164 | #ifdef BSS_SECTION_ASM_OP | |
165 | , in_bss | |
166 | #endif | |
0021b564 JM |
167 | #ifdef EH_FRAME_SECTION_ASM_OP |
168 | , in_eh_frame | |
169 | #endif | |
79e68feb | 170 | #ifdef EXTRA_SECTIONS |
e5887033 | 171 | , EXTRA_SECTIONS |
79e68feb | 172 | #endif |
e5887033 | 173 | } in_section = no_section; |
79e68feb | 174 | |
8a425a05 DE |
175 | /* Return a non-zero value if DECL has a section attribute. */ |
176 | #define IN_NAMED_SECTION(DECL) \ | |
177 | ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \ | |
178 | && DECL_SECTION_NAME (DECL) != NULL_TREE) | |
179 | ||
180 | /* Text of section name when in_section == in_named. */ | |
181 | static char *in_named_name; | |
182 | ||
79e68feb RS |
183 | /* Define functions like text_section for any extra sections. */ |
184 | #ifdef EXTRA_SECTION_FUNCTIONS | |
185 | EXTRA_SECTION_FUNCTIONS | |
186 | #endif | |
187 | ||
188 | /* Tell assembler to switch to text section. */ | |
189 | ||
190 | void | |
191 | text_section () | |
192 | { | |
193 | if (in_section != in_text) | |
194 | { | |
b93a436e | 195 | fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP); |
79e68feb RS |
196 | in_section = in_text; |
197 | } | |
198 | } | |
199 | ||
79e68feb RS |
200 | /* Tell assembler to switch to data section. */ |
201 | ||
202 | void | |
203 | data_section () | |
204 | { | |
205 | if (in_section != in_data) | |
206 | { | |
b93a436e | 207 | if (flag_shared_data) |
79e68feb RS |
208 | { |
209 | #ifdef SHARED_SECTION_ASM_OP | |
b93a436e | 210 | fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP); |
79e68feb | 211 | #else |
b93a436e | 212 | fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP); |
79e68feb RS |
213 | #endif |
214 | } | |
b93a436e JL |
215 | else |
216 | fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP); | |
79e68feb RS |
217 | |
218 | in_section = in_data; | |
219 | } | |
220 | } | |
221 | ||
7c6d68c8 RS |
222 | /* Tell assembler to switch to read-only data section. This is normally |
223 | the text section. */ | |
224 | ||
225 | void | |
226 | readonly_data_section () | |
227 | { | |
228 | #ifdef READONLY_DATA_SECTION | |
229 | READONLY_DATA_SECTION (); /* Note this can call data_section. */ | |
230 | #else | |
231 | text_section (); | |
232 | #endif | |
233 | } | |
234 | ||
0f41302f | 235 | /* Determine if we're in the text section. */ |
79e68feb RS |
236 | |
237 | int | |
238 | in_text_section () | |
239 | { | |
240 | return in_section == in_text; | |
241 | } | |
8a425a05 | 242 | |
0f41302f | 243 | /* Determine if we're in the data section. */ |
6f2f3db7 | 244 | |
274351ba RK |
245 | int |
246 | in_data_section () | |
247 | { | |
248 | return in_section == in_data; | |
249 | } | |
6f2f3db7 | 250 | |
2ffe831c DE |
251 | /* Tell assembler to change to section NAME for DECL. |
252 | If DECL is NULL, just switch to section NAME. | |
ad4ff310 JM |
253 | If NAME is NULL, get the name from DECL. |
254 | If RELOC is 1, the initializer for DECL contains relocs. */ | |
8a425a05 DE |
255 | |
256 | void | |
ad4ff310 | 257 | named_section (decl, name, reloc) |
2ffe831c | 258 | tree decl; |
8a425a05 | 259 | char *name; |
ad4ff310 | 260 | int reloc; |
8a425a05 | 261 | { |
2ffe831c | 262 | if (decl != NULL_TREE |
6f2f3db7 | 263 | && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd') |
2ffe831c DE |
264 | abort (); |
265 | if (name == NULL) | |
266 | name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
267 | ||
8a425a05 DE |
268 | if (in_section != in_named || strcmp (name, in_named_name)) |
269 | { | |
8a425a05 | 270 | #ifdef ASM_OUTPUT_SECTION_NAME |
ad4ff310 | 271 | ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc); |
8a425a05 DE |
272 | #else |
273 | /* Section attributes are not supported if this macro isn't provided - | |
274 | some host formats don't support them at all. The front-end should | |
275 | already have flagged this as an error. */ | |
276 | abort (); | |
277 | #endif | |
e9a25f70 JL |
278 | |
279 | in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1); | |
280 | strcpy (in_named_name, name); | |
281 | in_section = in_named; | |
8a425a05 DE |
282 | } |
283 | } | |
4d1065ed | 284 | |
ad4ff310 JM |
285 | #ifdef ASM_OUTPUT_SECTION_NAME |
286 | #ifndef UNIQUE_SECTION | |
287 | #define UNIQUE_SECTION(DECL,RELOC) \ | |
288 | do { \ | |
289 | int len; \ | |
290 | char *name, *string; \ | |
291 | \ | |
292 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \ | |
293 | /* Strip off any encoding in name. */ \ | |
294 | STRIP_NAME_ENCODING (name, name); \ | |
295 | \ | |
296 | len = strlen (name) + 1; \ | |
297 | string = alloca (len + 1); \ | |
298 | sprintf (string, ".%s", name); \ | |
299 | \ | |
300 | DECL_SECTION_NAME (DECL) = build_string (len, string); \ | |
301 | } while (0) | |
302 | #endif | |
303 | #ifndef UNIQUE_SECTION_P | |
304 | #define UNIQUE_SECTION_P(DECL) 0 | |
305 | #endif | |
306 | #endif | |
307 | ||
e5887033 DE |
308 | #ifdef BSS_SECTION_ASM_OP |
309 | ||
310 | /* Tell the assembler to switch to the bss section. */ | |
311 | ||
312 | void | |
da2c5447 | 313 | bss_section () |
e5887033 DE |
314 | { |
315 | if (in_section != in_bss) | |
316 | { | |
e5887033 | 317 | #ifdef SHARED_BSS_SECTION_ASM_OP |
b93a436e JL |
318 | if (flag_shared_data) |
319 | fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP); | |
320 | else | |
e5887033 | 321 | #endif |
b93a436e | 322 | fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP); |
e5887033 DE |
323 | |
324 | in_section = in_bss; | |
325 | } | |
326 | } | |
327 | ||
328 | #ifdef ASM_OUTPUT_BSS | |
329 | ||
330 | /* Utility function for ASM_OUTPUT_BSS for targets to use if | |
331 | they don't support alignments in .bss. | |
332 | ??? It is believed that this function will work in most cases so such | |
333 | support is localized here. */ | |
334 | ||
335 | static void | |
91fddd7c | 336 | asm_output_bss (file, decl, name, size, rounded) |
e5887033 | 337 | FILE *file; |
91fddd7c | 338 | tree decl; |
e5887033 DE |
339 | char *name; |
340 | int size, rounded; | |
341 | { | |
342 | ASM_GLOBALIZE_LABEL (file, name); | |
343 | bss_section (); | |
91fddd7c DE |
344 | #ifdef ASM_DECLARE_OBJECT_NAME |
345 | last_assemble_variable_decl = decl; | |
346 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
347 | #else | |
348 | /* Standard thing is just output label for the object. */ | |
e5887033 | 349 | ASM_OUTPUT_LABEL (file, name); |
91fddd7c | 350 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
e5887033 DE |
351 | ASM_OUTPUT_SKIP (file, rounded); |
352 | } | |
353 | ||
354 | #endif | |
355 | ||
356 | #ifdef ASM_OUTPUT_ALIGNED_BSS | |
357 | ||
358 | /* Utility function for targets to use in implementing | |
359 | ASM_OUTPUT_ALIGNED_BSS. | |
360 | ??? It is believed that this function will work in most cases so such | |
361 | support is localized here. */ | |
362 | ||
363 | static void | |
91fddd7c | 364 | asm_output_aligned_bss (file, decl, name, size, align) |
e5887033 | 365 | FILE *file; |
91fddd7c | 366 | tree decl; |
e5887033 DE |
367 | char *name; |
368 | int size, align; | |
369 | { | |
370 | ASM_GLOBALIZE_LABEL (file, name); | |
371 | bss_section (); | |
372 | ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT)); | |
91fddd7c DE |
373 | #ifdef ASM_DECLARE_OBJECT_NAME |
374 | last_assemble_variable_decl = decl; | |
375 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
376 | #else | |
377 | /* Standard thing is just output label for the object. */ | |
e5887033 | 378 | ASM_OUTPUT_LABEL (file, name); |
91fddd7c | 379 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
f8bc3367 | 380 | ASM_OUTPUT_SKIP (file, size ? size : 1); |
e5887033 DE |
381 | } |
382 | ||
383 | #endif | |
384 | ||
385 | #endif /* BSS_SECTION_ASM_OP */ | |
386 | ||
0021b564 JM |
387 | #ifdef EH_FRAME_SECTION_ASM_OP |
388 | void | |
389 | eh_frame_section () | |
390 | { | |
391 | if (in_section != in_eh_frame) | |
392 | { | |
393 | fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP); | |
394 | in_section = in_eh_frame; | |
395 | } | |
396 | } | |
397 | #endif | |
398 | ||
4d1065ed DE |
399 | /* Switch to the section for function DECL. |
400 | ||
401 | If DECL is NULL_TREE, switch to the text section. | |
402 | ??? It's not clear that we will ever be passed NULL_TREE, but it's | |
403 | safer to handle it. */ | |
404 | ||
405 | void | |
406 | function_section (decl) | |
407 | tree decl; | |
408 | { | |
409 | if (decl != NULL_TREE | |
410 | && DECL_SECTION_NAME (decl) != NULL_TREE) | |
ad4ff310 | 411 | named_section (decl, (char *) 0, 0); |
8b43265c JL |
412 | else |
413 | text_section (); | |
4d1065ed | 414 | } |
f9da1f35 DE |
415 | |
416 | /* Switch to section for variable DECL. | |
417 | ||
418 | RELOC is the `reloc' argument to SELECT_SECTION. */ | |
419 | ||
420 | void | |
421 | variable_section (decl, reloc) | |
422 | tree decl; | |
423 | int reloc; | |
424 | { | |
425 | if (IN_NAMED_SECTION (decl)) | |
ad4ff310 | 426 | named_section (decl, NULL, reloc); |
f9da1f35 DE |
427 | else |
428 | { | |
429 | /* C++ can have const variables that get initialized from constructors, | |
430 | and thus can not be in a readonly section. We prevent this by | |
431 | verifying that the initial value is constant for objects put in a | |
432 | readonly section. | |
433 | ||
434 | error_mark_node is used by the C front end to indicate that the | |
435 | initializer has not been seen yet. In this case, we assume that | |
e5887033 DE |
436 | the initializer must be constant. |
437 | ||
438 | C++ uses error_mark_node for variables that have complicated | |
439 | initializers, but these variables go in BSS so we won't be called | |
440 | for them. */ | |
441 | ||
f9da1f35 DE |
442 | #ifdef SELECT_SECTION |
443 | SELECT_SECTION (decl, reloc); | |
444 | #else | |
ad4ff310 | 445 | if (DECL_READONLY_SECTION (decl, reloc)) |
f9da1f35 DE |
446 | readonly_data_section (); |
447 | else | |
448 | data_section (); | |
449 | #endif | |
450 | } | |
451 | } | |
6adb4e3a MS |
452 | |
453 | /* Tell assembler to switch to the section for the exception handling | |
454 | table. */ | |
455 | ||
456 | void | |
457 | exception_section () | |
458 | { | |
0021b564 JM |
459 | #if defined (EXCEPTION_SECTION) |
460 | EXCEPTION_SECTION (); | |
461 | #else | |
6adb4e3a | 462 | #ifdef ASM_OUTPUT_SECTION_NAME |
ad4ff310 | 463 | named_section (NULL_TREE, ".gcc_except_table", 0); |
6adb4e3a MS |
464 | #else |
465 | if (flag_pic) | |
466 | data_section (); | |
467 | else | |
6adb4e3a MS |
468 | readonly_data_section (); |
469 | #endif | |
470 | #endif | |
471 | } | |
79e68feb RS |
472 | \f |
473 | /* Create the rtl to represent a function, for a function definition. | |
474 | DECL is a FUNCTION_DECL node which describes which function. | |
475 | The rtl is stored into DECL. */ | |
476 | ||
477 | void | |
478 | make_function_rtl (decl) | |
479 | tree decl; | |
480 | { | |
481 | char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
7c6d4120 | 482 | char *new_name = name; |
79e68feb RS |
483 | |
484 | /* Rename a nested function to avoid conflicts. */ | |
485 | if (decl_function_context (decl) != 0 | |
486 | && DECL_INITIAL (decl) != 0 | |
487 | && DECL_RTL (decl) == 0) | |
488 | { | |
489 | char *label; | |
490 | ||
491 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); | |
492 | ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno); | |
493 | name = obstack_copy0 (saveable_obstack, label, strlen (label)); | |
494 | var_labelno++; | |
495 | } | |
7c6d4120 RK |
496 | else |
497 | { | |
498 | /* When -fprefix-function-name is used, every function name is | |
499 | prefixed. Even static functions are prefixed because they | |
500 | could be declared latter. Note that a nested function name | |
501 | is not prefixed. */ | |
502 | if (flag_prefix_function_name) | |
503 | { | |
504 | new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE + 1); | |
505 | strcpy (new_name, CHKR_PREFIX); | |
506 | strcpy (new_name + CHKR_PREFIX_SIZE, name); | |
507 | name = obstack_copy0 (saveable_obstack, new_name, strlen (new_name)); | |
508 | } | |
509 | } | |
79e68feb RS |
510 | |
511 | if (DECL_RTL (decl) == 0) | |
512 | { | |
513 | DECL_RTL (decl) | |
38a448ca RH |
514 | = gen_rtx_MEM (DECL_MODE (decl), |
515 | gen_rtx_SYMBOL_REF (Pmode, name)); | |
79e68feb RS |
516 | |
517 | /* Optionally set flags or add text to the name to record information | |
518 | such as that it is a function name. If the name is changed, the macro | |
8a425a05 | 519 | ASM_OUTPUT_LABELREF will have to know how to strip this information. */ |
79e68feb RS |
520 | #ifdef ENCODE_SECTION_INFO |
521 | ENCODE_SECTION_INFO (decl); | |
d9525bec BK |
522 | #endif |
523 | } | |
524 | else | |
525 | { | |
526 | /* ??? Another way to do this would be to do what halfpic.c does | |
527 | and maintain a hashed table of such critters. */ | |
528 | /* ??? Another way to do this would be to pass a flag bit to | |
529 | ENCODE_SECTION_INFO saying whether this is a new decl or not. */ | |
530 | /* Let the target reassign the RTL if it wants. | |
531 | This is necessary, for example, when one machine specific | |
532 | decl attribute overrides another. */ | |
533 | #ifdef REDO_SECTION_INFO_P | |
534 | if (REDO_SECTION_INFO_P (decl)) | |
535 | ENCODE_SECTION_INFO (decl); | |
79e68feb RS |
536 | #endif |
537 | } | |
538 | ||
539 | /* Record at least one function has been defined. */ | |
540 | function_defined = 1; | |
541 | } | |
542 | ||
b4ac57ab RS |
543 | /* Given NAME, a putative register name, discard any customary prefixes. */ |
544 | ||
545 | static char * | |
546 | strip_reg_name (name) | |
547 | char *name; | |
548 | { | |
549 | #ifdef REGISTER_PREFIX | |
550 | if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX))) | |
551 | name += strlen (REGISTER_PREFIX); | |
552 | #endif | |
553 | if (name[0] == '%' || name[0] == '#') | |
554 | name++; | |
555 | return name; | |
556 | } | |
dcfedcd0 | 557 | \f |
79e68feb RS |
558 | /* Decode an `asm' spec for a declaration as a register name. |
559 | Return the register number, or -1 if nothing specified, | |
c09e6498 RS |
560 | or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized, |
561 | or -3 if ASMSPEC is `cc' and is not recognized, | |
562 | or -4 if ASMSPEC is `memory' and is not recognized. | |
dcfedcd0 RK |
563 | Accept an exact spelling or a decimal number. |
564 | Prefixes such as % are optional. */ | |
79e68feb RS |
565 | |
566 | int | |
567 | decode_reg_name (asmspec) | |
568 | char *asmspec; | |
569 | { | |
570 | if (asmspec != 0) | |
571 | { | |
572 | int i; | |
573 | ||
b4ac57ab RS |
574 | /* Get rid of confusing prefixes. */ |
575 | asmspec = strip_reg_name (asmspec); | |
576 | ||
fff9e713 MT |
577 | /* Allow a decimal number as a "register name". */ |
578 | for (i = strlen (asmspec) - 1; i >= 0; i--) | |
579 | if (! (asmspec[i] >= '0' && asmspec[i] <= '9')) | |
580 | break; | |
581 | if (asmspec[0] != 0 && i < 0) | |
582 | { | |
583 | i = atoi (asmspec); | |
584 | if (i < FIRST_PSEUDO_REGISTER && i >= 0) | |
585 | return i; | |
586 | else | |
587 | return -2; | |
588 | } | |
589 | ||
79e68feb | 590 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
b4ac57ab RS |
591 | if (reg_names[i][0] |
592 | && ! strcmp (asmspec, strip_reg_name (reg_names[i]))) | |
79e68feb RS |
593 | return i; |
594 | ||
79e68feb RS |
595 | #ifdef ADDITIONAL_REGISTER_NAMES |
596 | { | |
597 | static struct { char *name; int number; } table[] | |
598 | = ADDITIONAL_REGISTER_NAMES; | |
599 | ||
600 | for (i = 0; i < sizeof (table) / sizeof (table[0]); i++) | |
601 | if (! strcmp (asmspec, table[i].name)) | |
602 | return table[i].number; | |
79e68feb RS |
603 | } |
604 | #endif /* ADDITIONAL_REGISTER_NAMES */ | |
605 | ||
c09e6498 RS |
606 | if (!strcmp (asmspec, "memory")) |
607 | return -4; | |
608 | ||
dcfedcd0 RK |
609 | if (!strcmp (asmspec, "cc")) |
610 | return -3; | |
611 | ||
79e68feb RS |
612 | return -2; |
613 | } | |
614 | ||
615 | return -1; | |
616 | } | |
617 | \f | |
618 | /* Create the DECL_RTL for a declaration for a static or external variable | |
619 | or static or external function. | |
620 | ASMSPEC, if not 0, is the string which the user specified | |
621 | as the assembler symbol name. | |
622 | TOP_LEVEL is nonzero if this is a file-scope variable. | |
623 | ||
624 | This is never called for PARM_DECL nodes. */ | |
625 | ||
626 | void | |
627 | make_decl_rtl (decl, asmspec, top_level) | |
628 | tree decl; | |
629 | char *asmspec; | |
630 | int top_level; | |
631 | { | |
0a5152d0 | 632 | register char *name = 0; |
ca695ac9 JB |
633 | int reg_number; |
634 | ||
ca695ac9 | 635 | reg_number = decode_reg_name (asmspec); |
79e68feb RS |
636 | |
637 | if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE) | |
638 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
639 | ||
640 | if (reg_number == -2) | |
641 | { | |
642 | /* ASMSPEC is given, and not the name of a register. */ | |
643 | name = (char *) obstack_alloc (saveable_obstack, | |
644 | strlen (asmspec) + 2); | |
645 | name[0] = '*'; | |
646 | strcpy (&name[1], asmspec); | |
647 | } | |
648 | ||
649 | /* For a duplicate declaration, we can be called twice on the | |
ff8f4401 RS |
650 | same DECL node. Don't discard the RTL already made. */ |
651 | if (DECL_RTL (decl) == 0) | |
79e68feb RS |
652 | { |
653 | DECL_RTL (decl) = 0; | |
654 | ||
655 | /* First detect errors in declaring global registers. */ | |
12266a61 RK |
656 | if (TREE_CODE (decl) != FUNCTION_DECL |
657 | && DECL_REGISTER (decl) && reg_number == -1) | |
79e68feb RS |
658 | error_with_decl (decl, |
659 | "register name not specified for `%s'"); | |
12266a61 RK |
660 | else if (TREE_CODE (decl) != FUNCTION_DECL |
661 | && DECL_REGISTER (decl) && reg_number < 0) | |
79e68feb RS |
662 | error_with_decl (decl, |
663 | "invalid register name for `%s'"); | |
12266a61 RK |
664 | else if ((reg_number >= 0 || reg_number == -3) |
665 | && (TREE_CODE (decl) == FUNCTION_DECL | |
666 | && ! DECL_REGISTER (decl))) | |
79e68feb RS |
667 | error_with_decl (decl, |
668 | "register name given for non-register variable `%s'"); | |
12266a61 RK |
669 | else if (TREE_CODE (decl) != FUNCTION_DECL |
670 | && DECL_REGISTER (decl) | |
671 | && TYPE_MODE (TREE_TYPE (decl)) == BLKmode) | |
672 | error_with_decl (decl, | |
673 | "data type of `%s' isn't suitable for a register"); | |
674 | else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl) | |
675 | && ! HARD_REGNO_MODE_OK (reg_number, | |
676 | TYPE_MODE (TREE_TYPE (decl)))) | |
677 | error_with_decl (decl, | |
678 | "register number for `%s' isn't suitable for data type"); | |
79e68feb | 679 | /* Now handle properly declared static register variables. */ |
12266a61 | 680 | else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) |
79e68feb RS |
681 | { |
682 | int nregs; | |
12266a61 | 683 | |
79e68feb RS |
684 | if (DECL_INITIAL (decl) != 0 && top_level) |
685 | { | |
686 | DECL_INITIAL (decl) = 0; | |
687 | error ("global register variable has initial value"); | |
688 | } | |
689 | if (fixed_regs[reg_number] == 0 | |
690 | && function_defined && top_level) | |
691 | error ("global register variable follows a function definition"); | |
692 | if (TREE_THIS_VOLATILE (decl)) | |
693 | warning ("volatile register variables don't work as you might wish"); | |
31e4b1c0 RK |
694 | |
695 | /* If the user specified one of the eliminables registers here, | |
696 | e.g., FRAME_POINTER_REGNUM, we don't want to get this variable | |
697 | confused with that register and be eliminated. Although this | |
698 | usage is somewhat suspect, we nevertheless use the following | |
699 | kludge to avoid setting DECL_RTL to frame_pointer_rtx. */ | |
700 | ||
701 | DECL_RTL (decl) | |
38a448ca | 702 | = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER); |
31e4b1c0 | 703 | REGNO (DECL_RTL (decl)) = reg_number; |
79e68feb RS |
704 | REG_USERVAR_P (DECL_RTL (decl)) = 1; |
705 | ||
706 | if (top_level) | |
707 | { | |
ad800eb1 RK |
708 | /* Make this register global, so not usable for anything |
709 | else. */ | |
79e68feb RS |
710 | nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl)); |
711 | while (nregs > 0) | |
ad800eb1 | 712 | globalize_reg (reg_number + --nregs); |
79e68feb RS |
713 | } |
714 | } | |
0bcc6fc7 RK |
715 | /* Specifying a section attribute on a variable forces it into a |
716 | non-.bss section, and thus it cannot be common. */ | |
8a425a05 DE |
717 | else if (TREE_CODE (decl) == VAR_DECL |
718 | && DECL_SECTION_NAME (decl) != NULL_TREE | |
4580042b | 719 | && DECL_INITIAL (decl) == NULL_TREE |
d5160254 | 720 | && DECL_COMMON (decl)) |
0bcc6fc7 | 721 | DECL_COMMON (decl) = 0; |
79e68feb RS |
722 | |
723 | /* Now handle ordinary static variables and functions (in memory). | |
724 | Also handle vars declared register invalidly. */ | |
725 | if (DECL_RTL (decl) == 0) | |
726 | { | |
727 | /* Can't use just the variable's own name for a variable | |
728 | whose scope is less than the whole file. | |
729 | Concatenate a distinguishing number. */ | |
61881daa | 730 | if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0) |
79e68feb RS |
731 | { |
732 | char *label; | |
733 | ||
734 | ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno); | |
735 | name = obstack_copy0 (saveable_obstack, label, strlen (label)); | |
736 | var_labelno++; | |
c651e1e0 MM |
737 | |
738 | /* We've changed the name by which this entity is | |
739 | known. In order that we can generate | |
740 | correct references to it, we update its | |
741 | DECL_ASSEMBLER_NAME. */ | |
742 | DECL_ASSEMBLER_NAME (decl) = get_identifier (name); | |
79e68feb RS |
743 | } |
744 | ||
0a5152d0 RK |
745 | if (name == 0) |
746 | abort (); | |
747 | ||
7c6d4120 RK |
748 | /* When -fprefix-function-name is used, the functions |
749 | names are prefixed. Only nested function names are not | |
750 | prefixed. */ | |
751 | if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL) | |
752 | { | |
753 | char *new_name; | |
754 | new_name = (char *) alloca (strlen (name) + CHKR_PREFIX_SIZE | |
755 | + 1); | |
756 | strcpy (new_name, CHKR_PREFIX); | |
757 | strcpy (new_name + CHKR_PREFIX_SIZE, name); | |
758 | name = obstack_copy0 (saveable_obstack, | |
759 | new_name, strlen (new_name)); | |
760 | } | |
761 | ||
38a448ca RH |
762 | DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl), |
763 | gen_rtx_SYMBOL_REF (Pmode, name)); | |
3771b9b2 RK |
764 | |
765 | /* If this variable is to be treated as volatile, show its | |
766 | tree node has side effects. If it has side effects, either | |
767 | because of this test or from TREE_THIS_VOLATILE also | |
768 | being set, show the MEM is volatile. */ | |
769 | if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL | |
770 | && TREE_PUBLIC (decl)) | |
771 | TREE_SIDE_EFFECTS (decl) = 1; | |
772 | if (TREE_SIDE_EFFECTS (decl)) | |
79e68feb | 773 | MEM_VOLATILE_P (DECL_RTL (decl)) = 1; |
3771b9b2 | 774 | |
79e68feb RS |
775 | if (TREE_READONLY (decl)) |
776 | RTX_UNCHANGING_P (DECL_RTL (decl)) = 1; | |
777 | MEM_IN_STRUCT_P (DECL_RTL (decl)) | |
05e3bdb9 | 778 | = AGGREGATE_TYPE_P (TREE_TYPE (decl)); |
79e68feb RS |
779 | |
780 | /* Optionally set flags or add text to the name to record information | |
781 | such as that it is a function name. | |
782 | If the name is changed, the macro ASM_OUTPUT_LABELREF | |
8a425a05 | 783 | will have to know how to strip this information. */ |
79e68feb RS |
784 | #ifdef ENCODE_SECTION_INFO |
785 | ENCODE_SECTION_INFO (decl); | |
786 | #endif | |
787 | } | |
788 | } | |
d9525bec | 789 | else |
ff8f4401 | 790 | { |
d9525bec BK |
791 | /* If the old RTL had the wrong mode, fix the mode. */ |
792 | if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl)) | |
793 | { | |
794 | rtx rtl = DECL_RTL (decl); | |
795 | PUT_MODE (rtl, DECL_MODE (decl)); | |
796 | } | |
797 | ||
798 | /* ??? Another way to do this would be to do what halfpic.c does | |
799 | and maintain a hashed table of such critters. */ | |
800 | /* ??? Another way to do this would be to pass a flag bit to | |
801 | ENCODE_SECTION_INFO saying whether this is a new decl or not. */ | |
802 | /* Let the target reassign the RTL if it wants. | |
803 | This is necessary, for example, when one machine specific | |
804 | decl attribute overrides another. */ | |
805 | #ifdef REDO_SECTION_INFO_P | |
806 | if (REDO_SECTION_INFO_P (decl)) | |
807 | ENCODE_SECTION_INFO (decl); | |
808 | #endif | |
ff8f4401 | 809 | } |
79e68feb | 810 | } |
4724d87a RS |
811 | |
812 | /* Make the rtl for variable VAR be volatile. | |
813 | Use this only for static variables. */ | |
814 | ||
fcbaecc6 | 815 | void |
4724d87a RS |
816 | make_var_volatile (var) |
817 | tree var; | |
818 | { | |
819 | if (GET_CODE (DECL_RTL (var)) != MEM) | |
820 | abort (); | |
821 | ||
822 | MEM_VOLATILE_P (DECL_RTL (var)) = 1; | |
823 | } | |
79e68feb | 824 | \f |
d447ec6f RS |
825 | /* Output alignment directive to align for constant expression EXP. */ |
826 | ||
827 | void | |
828 | assemble_constant_align (exp) | |
829 | tree exp; | |
830 | { | |
831 | int align; | |
832 | ||
833 | /* Align the location counter as required by EXP's data type. */ | |
834 | align = TYPE_ALIGN (TREE_TYPE (exp)); | |
835 | #ifdef CONSTANT_ALIGNMENT | |
836 | align = CONSTANT_ALIGNMENT (exp, align); | |
837 | #endif | |
838 | ||
839 | if (align > BITS_PER_UNIT) | |
840 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
841 | } | |
842 | ||
79e68feb RS |
843 | /* Output a string of literal assembler code |
844 | for an `asm' keyword used between functions. */ | |
845 | ||
846 | void | |
847 | assemble_asm (string) | |
848 | tree string; | |
849 | { | |
850 | app_enable (); | |
851 | ||
852 | if (TREE_CODE (string) == ADDR_EXPR) | |
853 | string = TREE_OPERAND (string, 0); | |
854 | ||
855 | fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string)); | |
856 | } | |
857 | ||
9bb2e4fe RS |
858 | #if 0 /* This should no longer be needed, because |
859 | flag_gnu_linker should be 0 on these systems, | |
860 | which should prevent any output | |
861 | if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */ | |
79e68feb RS |
862 | #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER)) |
863 | #ifndef ASM_OUTPUT_CONSTRUCTOR | |
864 | #define ASM_OUTPUT_CONSTRUCTOR(file, name) | |
865 | #endif | |
866 | #ifndef ASM_OUTPUT_DESTRUCTOR | |
867 | #define ASM_OUTPUT_DESTRUCTOR(file, name) | |
868 | #endif | |
869 | #endif | |
9bb2e4fe | 870 | #endif /* 0 */ |
79e68feb RS |
871 | |
872 | /* Record an element in the table of global destructors. | |
873 | How this is done depends on what sort of assembler and linker | |
874 | are in use. | |
875 | ||
876 | NAME should be the name of a global function to be called | |
877 | at exit time. This name is output using assemble_name. */ | |
878 | ||
879 | void | |
880 | assemble_destructor (name) | |
881 | char *name; | |
882 | { | |
883 | #ifdef ASM_OUTPUT_DESTRUCTOR | |
884 | ASM_OUTPUT_DESTRUCTOR (asm_out_file, name); | |
885 | #else | |
886 | if (flag_gnu_linker) | |
887 | { | |
888 | /* Now tell GNU LD that this is part of the static destructor set. */ | |
889 | /* This code works for any machine provided you use GNU as/ld. */ | |
890 | fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP); | |
891 | assemble_name (asm_out_file, name); | |
892 | fputc ('\n', asm_out_file); | |
893 | } | |
894 | #endif | |
895 | } | |
896 | ||
897 | /* Likewise for global constructors. */ | |
898 | ||
899 | void | |
900 | assemble_constructor (name) | |
901 | char *name; | |
902 | { | |
903 | #ifdef ASM_OUTPUT_CONSTRUCTOR | |
904 | ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name); | |
905 | #else | |
906 | if (flag_gnu_linker) | |
907 | { | |
908 | /* Now tell GNU LD that this is part of the static constructor set. */ | |
909 | /* This code works for any machine provided you use GNU as/ld. */ | |
910 | fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP); | |
911 | assemble_name (asm_out_file, name); | |
912 | fputc ('\n', asm_out_file); | |
913 | } | |
914 | #endif | |
915 | } | |
916 | ||
917 | /* Likewise for entries we want to record for garbage collection. | |
918 | Garbage collection is still under development. */ | |
919 | ||
920 | void | |
921 | assemble_gc_entry (name) | |
922 | char *name; | |
923 | { | |
924 | #ifdef ASM_OUTPUT_GC_ENTRY | |
925 | ASM_OUTPUT_GC_ENTRY (asm_out_file, name); | |
926 | #else | |
927 | if (flag_gnu_linker) | |
928 | { | |
929 | /* Now tell GNU LD that this is part of the static constructor set. */ | |
930 | fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP); | |
931 | assemble_name (asm_out_file, name); | |
932 | fputc ('\n', asm_out_file); | |
933 | } | |
934 | #endif | |
935 | } | |
936 | \f | |
97adc6ed ILT |
937 | /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with |
938 | a non-zero value if the constant pool should be output before the | |
939 | start of the function, or a zero value if the pool should output | |
940 | after the end of the function. The default is to put it before the | |
941 | start. */ | |
942 | ||
943 | #ifndef CONSTANT_POOL_BEFORE_FUNCTION | |
944 | #define CONSTANT_POOL_BEFORE_FUNCTION 1 | |
945 | #endif | |
946 | ||
79e68feb RS |
947 | /* Output assembler code for the constant pool of a function and associated |
948 | with defining the name of the function. DECL describes the function. | |
949 | NAME is the function's name. For the constant pool, we use the current | |
950 | constant pool data. */ | |
951 | ||
952 | void | |
953 | assemble_start_function (decl, fnname) | |
954 | tree decl; | |
955 | char *fnname; | |
956 | { | |
957 | int align; | |
958 | ||
959 | /* The following code does not need preprocessing in the assembler. */ | |
960 | ||
961 | app_disable (); | |
962 | ||
97adc6ed ILT |
963 | if (CONSTANT_POOL_BEFORE_FUNCTION) |
964 | output_constant_pool (fnname, decl); | |
79e68feb | 965 | |
c30ac676 DE |
966 | #ifdef ASM_OUTPUT_SECTION_NAME |
967 | /* If the function is to be put in its own section and it's not in a section | |
968 | already, indicate so. */ | |
ad4ff310 JM |
969 | if ((flag_function_sections |
970 | && DECL_SECTION_NAME (decl) == NULL_TREE) | |
971 | || UNIQUE_SECTION_P (decl)) | |
972 | UNIQUE_SECTION (decl, 0); | |
c30ac676 DE |
973 | #endif |
974 | ||
4d1065ed | 975 | function_section (decl); |
79e68feb RS |
976 | |
977 | /* Tell assembler to move to target machine's alignment for functions. */ | |
978 | align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT); | |
979 | if (align > 0) | |
b93a436e | 980 | ASM_OUTPUT_ALIGN (asm_out_file, align); |
79e68feb RS |
981 | |
982 | #ifdef ASM_OUTPUT_FUNCTION_PREFIX | |
983 | ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname); | |
984 | #endif | |
985 | ||
986 | #ifdef SDB_DEBUGGING_INFO | |
987 | /* Output SDB definition of the function. */ | |
988 | if (write_symbols == SDB_DEBUG) | |
989 | sdbout_mark_begin_function (); | |
990 | #endif | |
991 | ||
992 | #ifdef DBX_DEBUGGING_INFO | |
e5c90c23 | 993 | /* Output DBX definition of the function. */ |
79e68feb | 994 | if (write_symbols == DBX_DEBUG) |
e5c90c23 | 995 | dbxout_begin_function (decl); |
79e68feb RS |
996 | #endif |
997 | ||
998 | /* Make function name accessible from other files, if appropriate. */ | |
999 | ||
1000 | if (TREE_PUBLIC (decl)) | |
1001 | { | |
f796d997 JM |
1002 | if (!first_global_object_name && ! DECL_WEAK (decl) |
1003 | && ! DECL_ONE_ONLY (decl)) | |
06bb02f7 RK |
1004 | { |
1005 | char *p; | |
1006 | ||
1007 | STRIP_NAME_ENCODING (p, fnname); | |
1008 | first_global_object_name = permalloc (strlen (p) + 1); | |
1009 | strcpy (first_global_object_name, p); | |
1010 | } | |
1011 | ||
daefd78b JM |
1012 | #ifdef ASM_WEAKEN_LABEL |
1013 | if (DECL_WEAK (decl)) | |
1014 | ASM_WEAKEN_LABEL (asm_out_file, fnname); | |
1015 | else | |
1016 | #endif | |
b93a436e | 1017 | ASM_GLOBALIZE_LABEL (asm_out_file, fnname); |
79e68feb RS |
1018 | } |
1019 | ||
1020 | /* Do any machine/system dependent processing of the function name */ | |
8bd16853 | 1021 | #ifdef ASM_DECLARE_FUNCTION_NAME |
b93a436e | 1022 | ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl); |
8bd16853 | 1023 | #else |
b93a436e JL |
1024 | /* Standard thing is just output label for the function. */ |
1025 | ASM_OUTPUT_LABEL (asm_out_file, fnname); | |
79e68feb RS |
1026 | #endif /* ASM_DECLARE_FUNCTION_NAME */ |
1027 | } | |
1028 | ||
1029 | /* Output assembler code associated with defining the size of the | |
1030 | function. DECL describes the function. NAME is the function's name. */ | |
1031 | ||
1032 | void | |
1033 | assemble_end_function (decl, fnname) | |
1034 | tree decl; | |
1035 | char *fnname; | |
1036 | { | |
1037 | #ifdef ASM_DECLARE_FUNCTION_SIZE | |
1038 | ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl); | |
1039 | #endif | |
97adc6ed | 1040 | if (! CONSTANT_POOL_BEFORE_FUNCTION) |
83488369 RK |
1041 | { |
1042 | output_constant_pool (fnname, decl); | |
1043 | function_section (decl); /* need to switch back */ | |
1044 | } | |
8839fca4 ILT |
1045 | |
1046 | /* Output any constants which should appear after the function. */ | |
1047 | output_after_function_constants (); | |
79e68feb RS |
1048 | } |
1049 | \f | |
1050 | /* Assemble code to leave SIZE bytes of zeros. */ | |
1051 | ||
1052 | void | |
1053 | assemble_zeros (size) | |
1054 | int size; | |
1055 | { | |
1056 | #ifdef ASM_NO_SKIP_IN_TEXT | |
1057 | /* The `space' pseudo in the text section outputs nop insns rather than 0s, | |
1058 | so we must output 0s explicitly in the text section. */ | |
1059 | if (ASM_NO_SKIP_IN_TEXT && in_text_section ()) | |
1060 | { | |
1061 | int i; | |
1062 | ||
1063 | for (i = 0; i < size - 20; i += 20) | |
1064 | { | |
1065 | #ifdef ASM_BYTE_OP | |
1066 | fprintf (asm_out_file, | |
1067 | "%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); | |
1068 | #else | |
1069 | fprintf (asm_out_file, | |
1070 | "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n"); | |
1071 | #endif | |
1072 | } | |
1073 | if (i < size) | |
1074 | { | |
1075 | #ifdef ASM_BYTE_OP | |
1076 | fprintf (asm_out_file, "%s 0", ASM_BYTE_OP); | |
1077 | #else | |
1078 | fprintf (asm_out_file, "\tbyte 0"); | |
1079 | #endif | |
1080 | i++; | |
1081 | for (; i < size; i++) | |
1082 | fprintf (asm_out_file, ",0"); | |
1083 | fprintf (asm_out_file, "\n"); | |
1084 | } | |
1085 | } | |
1086 | else | |
1087 | #endif | |
41fe4d9e | 1088 | if (size > 0) |
b93a436e | 1089 | ASM_OUTPUT_SKIP (asm_out_file, size); |
79e68feb RS |
1090 | } |
1091 | ||
a785e67e RS |
1092 | /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */ |
1093 | ||
1094 | void | |
1095 | assemble_align (align) | |
1096 | int align; | |
1097 | { | |
1098 | if (align > BITS_PER_UNIT) | |
1099 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
1100 | } | |
1101 | ||
79e68feb RS |
1102 | /* Assemble a string constant with the specified C string as contents. */ |
1103 | ||
1104 | void | |
1105 | assemble_string (p, size) | |
fcbaecc6 | 1106 | char *p; |
79e68feb RS |
1107 | int size; |
1108 | { | |
79e68feb RS |
1109 | int pos = 0; |
1110 | int maximum = 2000; | |
1111 | ||
1112 | /* If the string is very long, split it up. */ | |
1113 | ||
1114 | while (pos < size) | |
1115 | { | |
1116 | int thissize = size - pos; | |
1117 | if (thissize > maximum) | |
1118 | thissize = maximum; | |
1119 | ||
b93a436e | 1120 | ASM_OUTPUT_ASCII (asm_out_file, p, thissize); |
79e68feb RS |
1121 | |
1122 | pos += thissize; | |
1123 | p += thissize; | |
1124 | } | |
1125 | } | |
69249c1b | 1126 | |
79e68feb RS |
1127 | \f |
1128 | /* Assemble everything that is needed for a variable or function declaration. | |
1129 | Not used for automatic variables, and not used for function definitions. | |
1130 | Should not be called for variables of incomplete structure type. | |
1131 | ||
1132 | TOP_LEVEL is nonzero if this variable has file scope. | |
1133 | AT_END is nonzero if this is the special handling, at end of compilation, | |
ff8f4401 RS |
1134 | to define things that have had only tentative definitions. |
1135 | DONT_OUTPUT_DATA if nonzero means don't actually output the | |
1136 | initial value (that will be done by the caller). */ | |
79e68feb RS |
1137 | |
1138 | void | |
ff8f4401 | 1139 | assemble_variable (decl, top_level, at_end, dont_output_data) |
79e68feb RS |
1140 | tree decl; |
1141 | int top_level; | |
1142 | int at_end; | |
5a13eaa4 | 1143 | int dont_output_data; |
79e68feb RS |
1144 | { |
1145 | register char *name; | |
f8344bea | 1146 | unsigned int align; |
79e68feb RS |
1147 | tree size_tree; |
1148 | int reloc = 0; | |
edbc355b | 1149 | enum in_section saved_in_section; |
79e68feb | 1150 | |
cbed4565 RS |
1151 | last_assemble_variable_decl = 0; |
1152 | ||
79e68feb RS |
1153 | if (GET_CODE (DECL_RTL (decl)) == REG) |
1154 | { | |
1155 | /* Do output symbol info for global register variables, but do nothing | |
1156 | else for them. */ | |
1157 | ||
1158 | if (TREE_ASM_WRITTEN (decl)) | |
1159 | return; | |
1160 | TREE_ASM_WRITTEN (decl) = 1; | |
1161 | ||
b4ac57ab | 1162 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
b93a436e JL |
1163 | /* File-scope global variables are output here. */ |
1164 | if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) | |
1165 | && top_level) | |
1166 | dbxout_symbol (decl, 0); | |
79e68feb RS |
1167 | #endif |
1168 | #ifdef SDB_DEBUGGING_INFO | |
b93a436e JL |
1169 | if (write_symbols == SDB_DEBUG && top_level |
1170 | /* Leave initialized global vars for end of compilation; | |
1171 | see comment in compile_file. */ | |
1172 | && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0)) | |
1173 | sdbout_symbol (decl, 0); | |
79e68feb RS |
1174 | #endif |
1175 | ||
a94dbf2c JM |
1176 | /* Don't output any DWARF debugging information for variables here. |
1177 | In the case of local variables, the information for them is output | |
1178 | when we do our recursive traversal of the tree representation for | |
1179 | the entire containing function. In the case of file-scope variables, | |
1180 | we output information for all of them at the very end of compilation | |
1181 | while we are doing our final traversal of the chain of file-scope | |
1182 | declarations. */ | |
79e68feb RS |
1183 | |
1184 | return; | |
1185 | } | |
1186 | ||
d36d70cc | 1187 | /* Normally no need to say anything here for external references, |
9faa82d8 | 1188 | since assemble_external is called by the language-specific code |
d36d70cc | 1189 | when a declaration is first seen. */ |
79e68feb | 1190 | |
44fe2e80 | 1191 | if (DECL_EXTERNAL (decl)) |
79e68feb RS |
1192 | return; |
1193 | ||
1194 | /* Output no assembler code for a function declaration. | |
1195 | Only definitions of functions output anything. */ | |
1196 | ||
1197 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1198 | return; | |
1199 | ||
1200 | /* If type was incomplete when the variable was declared, | |
1201 | see if it is complete now. */ | |
1202 | ||
1203 | if (DECL_SIZE (decl) == 0) | |
1204 | layout_decl (decl, 0); | |
1205 | ||
1206 | /* Still incomplete => don't allocate it; treat the tentative defn | |
1207 | (which is what it must have been) as an `extern' reference. */ | |
1208 | ||
ff8f4401 | 1209 | if (!dont_output_data && DECL_SIZE (decl) == 0) |
79e68feb RS |
1210 | { |
1211 | error_with_file_and_line (DECL_SOURCE_FILE (decl), | |
1212 | DECL_SOURCE_LINE (decl), | |
ea80ee44 | 1213 | "storage size of `%s' isn't known", |
79e68feb | 1214 | IDENTIFIER_POINTER (DECL_NAME (decl))); |
1c1a7ba4 | 1215 | TREE_ASM_WRITTEN (decl) = 1; |
79e68feb RS |
1216 | return; |
1217 | } | |
1218 | ||
1219 | /* The first declaration of a variable that comes through this function | |
1220 | decides whether it is global (in C, has external linkage) | |
1221 | or local (in C, has internal linkage). So do nothing more | |
1222 | if this function has already run. */ | |
1223 | ||
1224 | if (TREE_ASM_WRITTEN (decl)) | |
1225 | return; | |
1226 | ||
1227 | TREE_ASM_WRITTEN (decl) = 1; | |
1228 | ||
809d6575 | 1229 | app_disable (); |
79e68feb | 1230 | |
809d6575 | 1231 | if (! dont_output_data) |
ff8f4401 | 1232 | { |
506711af RK |
1233 | int size; |
1234 | ||
ff8f4401 RS |
1235 | if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) |
1236 | goto finish; | |
79e68feb | 1237 | |
ff8f4401 RS |
1238 | /* This is better than explicit arithmetic, since it avoids overflow. */ |
1239 | size_tree = size_binop (CEIL_DIV_EXPR, | |
0189a68a | 1240 | DECL_SIZE (decl), size_int (BITS_PER_UNIT)); |
79e68feb | 1241 | |
506711af RK |
1242 | size = TREE_INT_CST_LOW (size_tree); |
1243 | if (TREE_INT_CST_HIGH (size_tree) != 0 | |
1244 | || size != TREE_INT_CST_LOW (size_tree)) | |
ff8f4401 RS |
1245 | { |
1246 | error_with_decl (decl, "size of variable `%s' is too large"); | |
1247 | goto finish; | |
1248 | } | |
79e68feb RS |
1249 | } |
1250 | ||
1251 | name = XSTR (XEXP (DECL_RTL (decl), 0), 0); | |
1252 | ||
f796d997 JM |
1253 | if (TREE_PUBLIC (decl) && DECL_NAME (decl) |
1254 | && ! first_global_object_name | |
1255 | && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0 | |
1256 | || DECL_INITIAL (decl) == error_mark_node)) | |
1257 | && ! DECL_WEAK (decl) | |
1258 | && ! DECL_ONE_ONLY (decl)) | |
1259 | { | |
1260 | char *p; | |
1261 | ||
1262 | STRIP_NAME_ENCODING (p, name); | |
1263 | first_global_object_name = permalloc (strlen (p) + 1); | |
1264 | strcpy (first_global_object_name, p); | |
1265 | } | |
1266 | ||
79e68feb RS |
1267 | /* Handle uninitialized definitions. */ |
1268 | ||
e5887033 DE |
1269 | if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node) |
1270 | /* If the target can't output uninitialized but not common global data | |
1271 | in .bss, then we have to use .data. */ | |
1272 | #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) | |
cd98bf12 | 1273 | && DECL_COMMON (decl) |
e5887033 DE |
1274 | #endif |
1275 | && ! dont_output_data) | |
79e68feb RS |
1276 | { |
1277 | int size = TREE_INT_CST_LOW (size_tree); | |
1278 | int rounded = size; | |
1279 | ||
79e68feb RS |
1280 | /* Don't allocate zero bytes of common, |
1281 | since that means "undefined external" in the linker. */ | |
1282 | if (size == 0) rounded = 1; | |
1283 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits | |
1284 | so that each uninitialized object starts on such a boundary. */ | |
1285 | rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; | |
1286 | rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
1287 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
edbc355b RS |
1288 | |
1289 | #ifdef DBX_DEBUGGING_INFO | |
1290 | /* File-scope global variables are output here. */ | |
1291 | if (write_symbols == DBX_DEBUG && top_level) | |
1292 | dbxout_symbol (decl, 0); | |
1293 | #endif | |
1294 | #ifdef SDB_DEBUGGING_INFO | |
1295 | if (write_symbols == SDB_DEBUG && top_level | |
1296 | /* Leave initialized global vars for end of compilation; | |
1297 | see comment in compile_file. */ | |
1298 | && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0)) | |
1299 | sdbout_symbol (decl, 0); | |
1300 | #endif | |
1301 | ||
a94dbf2c JM |
1302 | /* Don't output any DWARF debugging information for variables here. |
1303 | In the case of local variables, the information for them is output | |
1304 | when we do our recursive traversal of the tree representation for | |
1305 | the entire containing function. In the case of file-scope variables, | |
1306 | we output information for all of them at the very end of compilation | |
1307 | while we are doing our final traversal of the chain of file-scope | |
1308 | declarations. */ | |
edbc355b | 1309 | |
e5887033 DE |
1310 | #if 0 /* ??? We should either delete this or add a comment describing what |
1311 | it was intended to do and why we shouldn't delete it. */ | |
79e68feb RS |
1312 | if (flag_shared_data) |
1313 | data_section (); | |
1314 | #endif | |
e5887033 DE |
1315 | |
1316 | if (TREE_PUBLIC (decl) | |
1317 | #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS) | |
1318 | && DECL_COMMON (decl) | |
e5887033 DE |
1319 | #endif |
1320 | ) | |
79e68feb RS |
1321 | { |
1322 | #ifdef ASM_OUTPUT_SHARED_COMMON | |
1323 | if (flag_shared_data) | |
1324 | ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded); | |
1325 | else | |
1326 | #endif | |
ca695ac9 | 1327 | { |
e9a25f70 JL |
1328 | #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON |
1329 | ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, | |
1330 | DECL_ALIGN (decl)); | |
1331 | #else | |
79e68feb | 1332 | #ifdef ASM_OUTPUT_ALIGNED_COMMON |
ca695ac9 JB |
1333 | ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, |
1334 | DECL_ALIGN (decl)); | |
79e68feb | 1335 | #else |
ca695ac9 | 1336 | ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded); |
e9a25f70 | 1337 | #endif |
79e68feb | 1338 | #endif |
ca695ac9 | 1339 | } |
79e68feb | 1340 | } |
e5887033 DE |
1341 | #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS) |
1342 | else if (TREE_PUBLIC (decl)) | |
1343 | { | |
1344 | #ifdef ASM_OUTPUT_SHARED_BSS | |
1345 | if (flag_shared_data) | |
91fddd7c | 1346 | ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded); |
e5887033 DE |
1347 | else |
1348 | #endif | |
e5887033 DE |
1349 | { |
1350 | #ifdef ASM_OUTPUT_ALIGNED_BSS | |
91fddd7c | 1351 | ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, |
e5887033 DE |
1352 | DECL_ALIGN (decl)); |
1353 | #else | |
91fddd7c | 1354 | ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded); |
e5887033 DE |
1355 | #endif |
1356 | } | |
1357 | } | |
1358 | #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */ | |
79e68feb RS |
1359 | else |
1360 | { | |
1361 | #ifdef ASM_OUTPUT_SHARED_LOCAL | |
1362 | if (flag_shared_data) | |
1363 | ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded); | |
1364 | else | |
1365 | #endif | |
ca695ac9 | 1366 | { |
e9a25f70 JL |
1367 | #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL |
1368 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, | |
1369 | DECL_ALIGN (decl)); | |
1370 | #else | |
79e68feb | 1371 | #ifdef ASM_OUTPUT_ALIGNED_LOCAL |
ca695ac9 JB |
1372 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, |
1373 | DECL_ALIGN (decl)); | |
79e68feb | 1374 | #else |
ca695ac9 | 1375 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
e9a25f70 | 1376 | #endif |
79e68feb | 1377 | #endif |
ca695ac9 | 1378 | } |
79e68feb | 1379 | } |
b4ac57ab | 1380 | goto finish; |
79e68feb RS |
1381 | } |
1382 | ||
e5887033 DE |
1383 | /* Handle initialized definitions. |
1384 | Also handle uninitialized global definitions if -fno-common and the | |
1385 | target doesn't support ASM_OUTPUT_BSS. */ | |
79e68feb RS |
1386 | |
1387 | /* First make the assembler name(s) global if appropriate. */ | |
1388 | if (TREE_PUBLIC (decl) && DECL_NAME (decl)) | |
1389 | { | |
daefd78b JM |
1390 | #ifdef ASM_WEAKEN_LABEL |
1391 | if (DECL_WEAK (decl)) | |
1392 | ASM_WEAKEN_LABEL (asm_out_file, name); | |
1393 | else | |
1394 | #endif | |
79e68feb RS |
1395 | ASM_GLOBALIZE_LABEL (asm_out_file, name); |
1396 | } | |
1397 | #if 0 | |
1398 | for (d = equivalents; d; d = TREE_CHAIN (d)) | |
1399 | { | |
1400 | tree e = TREE_VALUE (d); | |
1401 | if (TREE_PUBLIC (e) && DECL_NAME (e)) | |
1402 | ASM_GLOBALIZE_LABEL (asm_out_file, | |
1403 | XSTR (XEXP (DECL_RTL (e), 0), 0)); | |
1404 | } | |
1405 | #endif | |
1406 | ||
1407 | /* Output any data that we will need to use the address of. */ | |
2e9effae RS |
1408 | if (DECL_INITIAL (decl) == error_mark_node) |
1409 | reloc = contains_pointers_p (TREE_TYPE (decl)); | |
1410 | else if (DECL_INITIAL (decl)) | |
79e68feb RS |
1411 | reloc = output_addressed_constants (DECL_INITIAL (decl)); |
1412 | ||
ad4ff310 JM |
1413 | #ifdef ASM_OUTPUT_SECTION_NAME |
1414 | if (UNIQUE_SECTION_P (decl)) | |
1415 | UNIQUE_SECTION (decl, reloc); | |
1416 | #endif | |
1417 | ||
f9da1f35 DE |
1418 | /* Switch to the appropriate section. */ |
1419 | variable_section (decl, reloc); | |
79e68feb | 1420 | |
a8e2f179 RS |
1421 | /* dbxout.c needs to know this. */ |
1422 | if (in_text_section ()) | |
1423 | DECL_IN_TEXT_SECTION (decl) = 1; | |
1424 | ||
edbc355b RS |
1425 | /* Record current section so we can restore it if dbxout.c clobbers it. */ |
1426 | saved_in_section = in_section; | |
1427 | ||
1428 | /* Output the dbx info now that we have chosen the section. */ | |
1429 | ||
1430 | #ifdef DBX_DEBUGGING_INFO | |
1431 | /* File-scope global variables are output here. */ | |
1432 | if (write_symbols == DBX_DEBUG && top_level) | |
1433 | dbxout_symbol (decl, 0); | |
1434 | #endif | |
1435 | #ifdef SDB_DEBUGGING_INFO | |
1436 | if (write_symbols == SDB_DEBUG && top_level | |
1437 | /* Leave initialized global vars for end of compilation; | |
1438 | see comment in compile_file. */ | |
1439 | && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0)) | |
1440 | sdbout_symbol (decl, 0); | |
1441 | #endif | |
1442 | ||
1443 | /* Don't output any DWARF debugging information for variables here. | |
1444 | In the case of local variables, the information for them is output | |
1445 | when we do our recursive traversal of the tree representation for | |
1446 | the entire containing function. In the case of file-scope variables, | |
1447 | we output information for all of them at the very end of compilation | |
1448 | while we are doing our final traversal of the chain of file-scope | |
1449 | declarations. */ | |
1450 | ||
a8e2f179 RS |
1451 | /* If the debugging output changed sections, reselect the section |
1452 | that's supposed to be selected. */ | |
edbc355b | 1453 | if (in_section != saved_in_section) |
f9da1f35 | 1454 | variable_section (decl, reloc); |
edbc355b | 1455 | |
79e68feb RS |
1456 | /* Compute and output the alignment of this data. */ |
1457 | ||
1458 | align = DECL_ALIGN (decl); | |
a785e67e RS |
1459 | /* In the case for initialing an array whose length isn't specified, |
1460 | where we have not yet been able to do the layout, | |
1461 | figure out the proper alignment now. */ | |
1462 | if (dont_output_data && DECL_SIZE (decl) == 0 | |
1463 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
1464 | align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))); | |
1465 | ||
79e68feb RS |
1466 | /* Some object file formats have a maximum alignment which they support. |
1467 | In particular, a.out format supports a maximum alignment of 4. */ | |
1468 | #ifndef MAX_OFILE_ALIGNMENT | |
1469 | #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT | |
1470 | #endif | |
1471 | if (align > MAX_OFILE_ALIGNMENT) | |
1472 | { | |
1473 | warning_with_decl (decl, | |
1474 | "alignment of `%s' is greater than maximum object file alignment"); | |
1475 | align = MAX_OFILE_ALIGNMENT; | |
1476 | } | |
1477 | #ifdef DATA_ALIGNMENT | |
1478 | /* On some machines, it is good to increase alignment sometimes. */ | |
1479 | align = DATA_ALIGNMENT (TREE_TYPE (decl), align); | |
1480 | #endif | |
1481 | #ifdef CONSTANT_ALIGNMENT | |
1482 | if (DECL_INITIAL (decl)) | |
1483 | align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align); | |
1484 | #endif | |
1485 | ||
1486 | /* Reset the alignment in case we have made it tighter, so we can benefit | |
1487 | from it in get_pointer_alignment. */ | |
1488 | DECL_ALIGN (decl) = align; | |
1489 | ||
1490 | if (align > BITS_PER_UNIT) | |
b93a436e | 1491 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); |
79e68feb RS |
1492 | |
1493 | /* Do any machine/system dependent processing of the object. */ | |
8bd16853 | 1494 | #ifdef ASM_DECLARE_OBJECT_NAME |
b93a436e JL |
1495 | last_assemble_variable_decl = decl; |
1496 | ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl); | |
8bd16853 | 1497 | #else |
b93a436e JL |
1498 | /* Standard thing is just output label for the object. */ |
1499 | ASM_OUTPUT_LABEL (asm_out_file, name); | |
79e68feb RS |
1500 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
1501 | ||
ff8f4401 | 1502 | if (!dont_output_data) |
79e68feb | 1503 | { |
ff8f4401 RS |
1504 | if (DECL_INITIAL (decl)) |
1505 | /* Output the actual data. */ | |
809d6575 | 1506 | output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree)); |
ff8f4401 RS |
1507 | else |
1508 | /* Leave space for it. */ | |
809d6575 | 1509 | assemble_zeros (TREE_INT_CST_LOW (size_tree)); |
79e68feb | 1510 | } |
b4ac57ab RS |
1511 | |
1512 | finish: | |
1513 | #ifdef XCOFF_DEBUGGING_INFO | |
1514 | /* Unfortunately, the IBM assembler cannot handle stabx before the actual | |
1515 | declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted | |
1516 | and `aa' hasn't been output yet, the assembler generates a stab entry with | |
1517 | a value of zero, in addition to creating an unnecessary external entry | |
6dc42e49 | 1518 | for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */ |
b4ac57ab RS |
1519 | |
1520 | /* File-scope global variables are output here. */ | |
1521 | if (write_symbols == XCOFF_DEBUG && top_level) | |
05be4cea JW |
1522 | { |
1523 | saved_in_section = in_section; | |
1524 | ||
1525 | dbxout_symbol (decl, 0); | |
1526 | ||
1527 | if (in_section != saved_in_section) | |
f9da1f35 | 1528 | variable_section (decl, reloc); |
05be4cea | 1529 | } |
b4ac57ab RS |
1530 | #else |
1531 | /* There must be a statement after a label. */ | |
1532 | ; | |
1533 | #endif | |
79e68feb RS |
1534 | } |
1535 | ||
2e9effae RS |
1536 | /* Return 1 if type TYPE contains any pointers. */ |
1537 | ||
1538 | static int | |
1539 | contains_pointers_p (type) | |
1540 | tree type; | |
1541 | { | |
1542 | switch (TREE_CODE (type)) | |
1543 | { | |
1544 | case POINTER_TYPE: | |
1545 | case REFERENCE_TYPE: | |
1546 | /* I'm not sure whether OFFSET_TYPE needs this treatment, | |
1547 | so I'll play safe and return 1. */ | |
1548 | case OFFSET_TYPE: | |
1549 | return 1; | |
1550 | ||
1551 | case RECORD_TYPE: | |
1552 | case UNION_TYPE: | |
1553 | case QUAL_UNION_TYPE: | |
1554 | { | |
1555 | tree fields; | |
1556 | /* For a type that has fields, see if the fields have pointers. */ | |
1557 | for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) | |
ce49ea8a JM |
1558 | if (TREE_CODE (fields) == FIELD_DECL |
1559 | && contains_pointers_p (TREE_TYPE (fields))) | |
2e9effae RS |
1560 | return 1; |
1561 | return 0; | |
1562 | } | |
1563 | ||
1564 | case ARRAY_TYPE: | |
1565 | /* An array type contains pointers if its element type does. */ | |
1566 | return contains_pointers_p (TREE_TYPE (type)); | |
1567 | ||
1568 | default: | |
1569 | return 0; | |
1570 | } | |
1571 | } | |
1572 | ||
79e68feb | 1573 | /* Output something to declare an external symbol to the assembler. |
fff9e713 MT |
1574 | (Most assemblers don't need this, so we normally output nothing.) |
1575 | Do nothing if DECL is not external. */ | |
79e68feb RS |
1576 | |
1577 | void | |
1578 | assemble_external (decl) | |
1579 | tree decl; | |
1580 | { | |
79e68feb | 1581 | #ifdef ASM_OUTPUT_EXTERNAL |
fff9e713 | 1582 | if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd' |
44fe2e80 | 1583 | && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) |
79e68feb | 1584 | { |
fff9e713 MT |
1585 | rtx rtl = DECL_RTL (decl); |
1586 | ||
1587 | if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF | |
1588 | && ! SYMBOL_REF_USED (XEXP (rtl, 0))) | |
1589 | { | |
1590 | /* Some systems do require some output. */ | |
1591 | SYMBOL_REF_USED (XEXP (rtl, 0)) = 1; | |
1592 | ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0)); | |
1593 | } | |
79e68feb RS |
1594 | } |
1595 | #endif | |
1596 | } | |
1597 | ||
1598 | /* Similar, for calling a library function FUN. */ | |
1599 | ||
1600 | void | |
1601 | assemble_external_libcall (fun) | |
1602 | rtx fun; | |
1603 | { | |
1604 | #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL | |
b93a436e JL |
1605 | /* Declare library function name external when first used, if nec. */ |
1606 | if (! SYMBOL_REF_USED (fun)) | |
79e68feb | 1607 | { |
b93a436e JL |
1608 | SYMBOL_REF_USED (fun) = 1; |
1609 | ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun); | |
79e68feb RS |
1610 | } |
1611 | #endif | |
1612 | } | |
1613 | ||
1614 | /* Declare the label NAME global. */ | |
1615 | ||
1616 | void | |
1617 | assemble_global (name) | |
1618 | char *name; | |
1619 | { | |
1620 | ASM_GLOBALIZE_LABEL (asm_out_file, name); | |
1621 | } | |
1622 | ||
1623 | /* Assemble a label named NAME. */ | |
1624 | ||
1625 | void | |
1626 | assemble_label (name) | |
1627 | char *name; | |
1628 | { | |
b93a436e | 1629 | ASM_OUTPUT_LABEL (asm_out_file, name); |
79e68feb RS |
1630 | } |
1631 | ||
1632 | /* Output to FILE a reference to the assembler name of a C-level name NAME. | |
1633 | If NAME starts with a *, the rest of NAME is output verbatim. | |
1634 | Otherwise NAME is transformed in an implementation-defined way | |
1635 | (usually by the addition of an underscore). | |
1636 | Many macros in the tm file are defined to call this function. */ | |
1637 | ||
1638 | void | |
1639 | assemble_name (file, name) | |
1640 | FILE *file; | |
1641 | char *name; | |
1642 | { | |
648fb7cf | 1643 | char *real_name; |
a94dbf2c | 1644 | tree id; |
648fb7cf RK |
1645 | |
1646 | STRIP_NAME_ENCODING (real_name, name); | |
7c6d4120 RK |
1647 | if (flag_prefix_function_name |
1648 | && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE)) | |
1649 | real_name = real_name + CHKR_PREFIX_SIZE; | |
87907387 | 1650 | |
a94dbf2c JM |
1651 | id = maybe_get_identifier (real_name); |
1652 | if (id) | |
1653 | TREE_SYMBOL_REFERENCED (id) = 1; | |
03e42132 | 1654 | |
79e68feb | 1655 | if (name[0] == '*') |
b93a436e | 1656 | fputs (&name[1], file); |
79e68feb | 1657 | else |
b93a436e | 1658 | ASM_OUTPUT_LABELREF (file, name); |
79e68feb RS |
1659 | } |
1660 | ||
1661 | /* Allocate SIZE bytes writable static space with a gensym name | |
1662 | and return an RTX to refer to its address. */ | |
1663 | ||
1664 | rtx | |
1665 | assemble_static_space (size) | |
1666 | int size; | |
1667 | { | |
1668 | char name[12]; | |
1669 | char *namestring; | |
1670 | rtx x; | |
4e1e2064 | 1671 | #ifndef ASM_OUTPUT_ALIGNED_LOCAL |
79e68feb RS |
1672 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits |
1673 | so that each uninitialized object starts on such a boundary. */ | |
1674 | int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1) | |
1675 | / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
1676 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
4e1e2064 | 1677 | #endif |
79e68feb RS |
1678 | |
1679 | #if 0 | |
1680 | if (flag_shared_data) | |
1681 | data_section (); | |
1682 | #endif | |
1683 | ||
1684 | ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno); | |
1685 | ++const_labelno; | |
1686 | ||
1687 | namestring = (char *) obstack_alloc (saveable_obstack, | |
1688 | strlen (name) + 2); | |
1689 | strcpy (namestring, name); | |
1690 | ||
b93a436e | 1691 | x = gen_rtx_SYMBOL_REF (Pmode, namestring); |
ca695ac9 | 1692 | |
e9a25f70 | 1693 | #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL |
b93a436e JL |
1694 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size, |
1695 | BIGGEST_ALIGNMENT); | |
e9a25f70 | 1696 | #else |
79e68feb | 1697 | #ifdef ASM_OUTPUT_ALIGNED_LOCAL |
b93a436e | 1698 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT); |
79e68feb | 1699 | #else |
b93a436e | 1700 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
e9a25f70 | 1701 | #endif |
79e68feb RS |
1702 | #endif |
1703 | return x; | |
1704 | } | |
1705 | ||
1706 | /* Assemble the static constant template for function entry trampolines. | |
1707 | This is done at most once per compilation. | |
1708 | Returns an RTX for the address of the template. */ | |
1709 | ||
f0e969bd | 1710 | #ifdef TRAMPOLINE_TEMPLATE |
79e68feb RS |
1711 | rtx |
1712 | assemble_trampoline_template () | |
1713 | { | |
1714 | char label[256]; | |
1715 | char *name; | |
1716 | int align; | |
1717 | ||
37552631 | 1718 | /* By default, put trampoline templates in read-only data section. */ |
f49acdb4 | 1719 | |
37552631 RS |
1720 | #ifdef TRAMPOLINE_SECTION |
1721 | TRAMPOLINE_SECTION (); | |
1722 | #else | |
c8c29f85 | 1723 | readonly_data_section (); |
37552631 | 1724 | #endif |
f49acdb4 | 1725 | |
79e68feb | 1726 | /* Write the assembler code to define one. */ |
073b0524 | 1727 | align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); |
79e68feb RS |
1728 | if (align > 0) |
1729 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
1730 | ||
1731 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0); | |
1732 | TRAMPOLINE_TEMPLATE (asm_out_file); | |
1733 | ||
1734 | /* Record the rtl to refer to it. */ | |
1735 | ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0); | |
1736 | name | |
1737 | = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label)); | |
38a448ca | 1738 | return gen_rtx_SYMBOL_REF (Pmode, name); |
79e68feb | 1739 | } |
f0e969bd | 1740 | #endif |
79e68feb RS |
1741 | \f |
1742 | /* Assemble the integer constant X into an object of SIZE bytes. | |
1743 | X must be either a CONST_INT or CONST_DOUBLE. | |
1744 | ||
1745 | Return 1 if we were able to output the constant, otherwise 0. If FORCE is | |
1746 | non-zero, abort if we can't output the constant. */ | |
1747 | ||
1748 | int | |
1749 | assemble_integer (x, size, force) | |
1750 | rtx x; | |
1751 | int size; | |
1752 | int force; | |
1753 | { | |
1754 | /* First try to use the standard 1, 2, 4, 8, and 16 byte | |
0f41302f | 1755 | ASM_OUTPUT... macros. */ |
79e68feb RS |
1756 | |
1757 | switch (size) | |
1758 | { | |
1759 | #ifdef ASM_OUTPUT_CHAR | |
1760 | case 1: | |
1761 | ASM_OUTPUT_CHAR (asm_out_file, x); | |
1762 | return 1; | |
1763 | #endif | |
1764 | ||
1765 | #ifdef ASM_OUTPUT_SHORT | |
1766 | case 2: | |
1767 | ASM_OUTPUT_SHORT (asm_out_file, x); | |
1768 | return 1; | |
1769 | #endif | |
1770 | ||
1771 | #ifdef ASM_OUTPUT_INT | |
1772 | case 4: | |
1773 | ASM_OUTPUT_INT (asm_out_file, x); | |
1774 | return 1; | |
1775 | #endif | |
1776 | ||
1777 | #ifdef ASM_OUTPUT_DOUBLE_INT | |
1778 | case 8: | |
1779 | ASM_OUTPUT_DOUBLE_INT (asm_out_file, x); | |
1780 | return 1; | |
1781 | #endif | |
1782 | ||
1783 | #ifdef ASM_OUTPUT_QUADRUPLE_INT | |
1784 | case 16: | |
1785 | ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x); | |
1786 | return 1; | |
1787 | #endif | |
1788 | } | |
1789 | ||
1790 | /* If we couldn't do it that way, there are two other possibilities: First, | |
1791 | if the machine can output an explicit byte and this is a 1 byte constant, | |
1792 | we can use ASM_OUTPUT_BYTE. */ | |
1793 | ||
1794 | #ifdef ASM_OUTPUT_BYTE | |
1795 | if (size == 1 && GET_CODE (x) == CONST_INT) | |
1796 | { | |
1797 | ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x)); | |
1798 | return 1; | |
1799 | } | |
1800 | #endif | |
1801 | ||
1802 | /* Finally, if SIZE is larger than a single word, try to output the constant | |
1803 | one word at a time. */ | |
1804 | ||
1805 | if (size > UNITS_PER_WORD) | |
1806 | { | |
1807 | int i; | |
1808 | enum machine_mode mode | |
1809 | = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); | |
1810 | rtx word; | |
1811 | ||
1812 | for (i = 0; i < size / UNITS_PER_WORD; i++) | |
1813 | { | |
1814 | word = operand_subword (x, i, 0, mode); | |
1815 | ||
1816 | if (word == 0) | |
1817 | break; | |
1818 | ||
fff9e713 MT |
1819 | if (! assemble_integer (word, UNITS_PER_WORD, 0)) |
1820 | break; | |
79e68feb RS |
1821 | } |
1822 | ||
1823 | if (i == size / UNITS_PER_WORD) | |
1824 | return 1; | |
fff9e713 MT |
1825 | /* If we output at least one word and then could not finish, |
1826 | there is no valid way to continue. */ | |
1827 | if (i > 0) | |
1828 | abort (); | |
79e68feb RS |
1829 | } |
1830 | ||
1831 | if (force) | |
1832 | abort (); | |
1833 | ||
1834 | return 0; | |
1835 | } | |
1836 | \f | |
1837 | /* Assemble the floating-point constant D into an object of size MODE. */ | |
1838 | ||
1839 | void | |
1840 | assemble_real (d, mode) | |
1841 | REAL_VALUE_TYPE d; | |
1842 | enum machine_mode mode; | |
1843 | { | |
1844 | jmp_buf output_constant_handler; | |
1845 | ||
1846 | if (setjmp (output_constant_handler)) | |
1847 | { | |
1848 | error ("floating point trap outputting a constant"); | |
1849 | #ifdef REAL_IS_NOT_DOUBLE | |
4c9a05bc | 1850 | bzero ((char *) &d, sizeof d); |
79e68feb RS |
1851 | d = dconst0; |
1852 | #else | |
1853 | d = 0; | |
1854 | #endif | |
1855 | } | |
1856 | ||
1857 | set_float_handler (output_constant_handler); | |
1858 | ||
1859 | switch (mode) | |
1860 | { | |
b7526ea5 RS |
1861 | #ifdef ASM_OUTPUT_BYTE_FLOAT |
1862 | case QFmode: | |
1863 | ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d); | |
1864 | break; | |
1865 | #endif | |
1866 | #ifdef ASM_OUTPUT_SHORT_FLOAT | |
1867 | case HFmode: | |
1868 | ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d); | |
1869 | break; | |
1870 | #endif | |
32c03bfb RK |
1871 | #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT |
1872 | case TQFmode: | |
1873 | ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d); | |
1874 | break; | |
1875 | #endif | |
79e68feb RS |
1876 | #ifdef ASM_OUTPUT_FLOAT |
1877 | case SFmode: | |
1878 | ASM_OUTPUT_FLOAT (asm_out_file, d); | |
1879 | break; | |
1880 | #endif | |
1881 | ||
1882 | #ifdef ASM_OUTPUT_DOUBLE | |
1883 | case DFmode: | |
1884 | ASM_OUTPUT_DOUBLE (asm_out_file, d); | |
1885 | break; | |
1886 | #endif | |
1887 | ||
1888 | #ifdef ASM_OUTPUT_LONG_DOUBLE | |
2c7ff63c | 1889 | case XFmode: |
79e68feb RS |
1890 | case TFmode: |
1891 | ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d); | |
1892 | break; | |
1893 | #endif | |
1894 | ||
1895 | default: | |
1896 | abort (); | |
1897 | } | |
1898 | ||
37366632 | 1899 | set_float_handler (NULL_PTR); |
79e68feb RS |
1900 | } |
1901 | \f | |
1902 | /* Here we combine duplicate floating constants to make | |
1903 | CONST_DOUBLE rtx's, and force those out to memory when necessary. */ | |
1904 | ||
1905 | /* Chain of all CONST_DOUBLE rtx's constructed for the current function. | |
1906 | They are chained through the CONST_DOUBLE_CHAIN. | |
1907 | A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain. | |
1908 | In that case, CONST_DOUBLE_MEM is either a MEM, | |
57632c51 RS |
1909 | or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. |
1910 | ||
1911 | (CONST_DOUBLE_MEM is used only for top-level functions. | |
1912 | See force_const_mem for explanation.) */ | |
79e68feb RS |
1913 | |
1914 | static rtx const_double_chain; | |
1915 | ||
4db92e9a | 1916 | /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints. |
79e68feb RS |
1917 | For an integer, I0 is the low-order word and I1 is the high-order word. |
1918 | For a real number, I0 is the word with the low address | |
1919 | and I1 is the word with the high address. */ | |
1920 | ||
1921 | rtx | |
1922 | immed_double_const (i0, i1, mode) | |
37366632 | 1923 | HOST_WIDE_INT i0, i1; |
79e68feb RS |
1924 | enum machine_mode mode; |
1925 | { | |
1926 | register rtx r; | |
79e68feb | 1927 | |
ab8ab9d0 SC |
1928 | if (GET_MODE_CLASS (mode) == MODE_INT |
1929 | || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT) | |
79e68feb RS |
1930 | { |
1931 | /* We clear out all bits that don't belong in MODE, unless they and our | |
1932 | sign bit are all one. So we get either a reasonable negative value | |
1933 | or a reasonable unsigned value for this mode. */ | |
1934 | int width = GET_MODE_BITSIZE (mode); | |
37366632 RK |
1935 | if (width < HOST_BITS_PER_WIDE_INT |
1936 | && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1))) | |
1937 | != ((HOST_WIDE_INT) (-1) << (width - 1)))) | |
1938 | i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0; | |
1939 | else if (width == HOST_BITS_PER_WIDE_INT | |
79e68feb RS |
1940 | && ! (i1 == ~0 && i0 < 0)) |
1941 | i1 = 0; | |
37366632 | 1942 | else if (width > 2 * HOST_BITS_PER_WIDE_INT) |
79e68feb RS |
1943 | /* We cannot represent this value as a constant. */ |
1944 | abort (); | |
1945 | ||
2ba3a0ec JW |
1946 | /* If this would be an entire word for the target, but is not for |
1947 | the host, then sign-extend on the host so that the number will look | |
1948 | the same way on the host that it would on the target. | |
1949 | ||
1950 | For example, when building a 64 bit alpha hosted 32 bit sparc | |
1951 | targeted compiler, then we want the 32 bit unsigned value -1 to be | |
1952 | represented as a 64 bit value -1, and not as 0x00000000ffffffff. | |
1953 | The later confuses the sparc backend. */ | |
1954 | ||
1955 | if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width | |
1956 | && (i0 & ((HOST_WIDE_INT) 1 << (width - 1)))) | |
1957 | i0 |= ((HOST_WIDE_INT) (-1) << width); | |
1958 | ||
37366632 | 1959 | /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT. |
79e68feb RS |
1960 | |
1961 | ??? Strictly speaking, this is wrong if we create a CONST_INT | |
1962 | for a large unsigned constant with the size of MODE being | |
37366632 RK |
1963 | HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a |
1964 | wider mode. In that case we will mis-interpret it as a negative | |
1965 | number. | |
79e68feb RS |
1966 | |
1967 | Unfortunately, the only alternative is to make a CONST_DOUBLE | |
1968 | for any constant in any mode if it is an unsigned constant larger | |
1969 | than the maximum signed integer in an int on the host. However, | |
1970 | doing this will break everyone that always expects to see a CONST_INT | |
1971 | for SImode and smaller. | |
1972 | ||
1973 | We have always been making CONST_INTs in this case, so nothing new | |
1974 | is being broken. */ | |
1975 | ||
37366632 | 1976 | if (width <= HOST_BITS_PER_WIDE_INT) |
7bcac048 | 1977 | i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0; |
79e68feb RS |
1978 | |
1979 | /* If this integer fits in one word, return a CONST_INT. */ | |
1980 | if ((i1 == 0 && i0 >= 0) | |
1981 | || (i1 == ~0 && i0 < 0)) | |
37366632 | 1982 | return GEN_INT (i0); |
79e68feb RS |
1983 | |
1984 | /* We use VOIDmode for integers. */ | |
1985 | mode = VOIDmode; | |
1986 | } | |
1987 | ||
1988 | /* Search the chain for an existing CONST_DOUBLE with the right value. | |
1989 | If one is found, return it. */ | |
1990 | ||
1991 | for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r)) | |
1992 | if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1 | |
1993 | && GET_MODE (r) == mode) | |
1994 | return r; | |
1995 | ||
1996 | /* No; make a new one and add it to the chain. | |
1997 | ||
1998 | We may be called by an optimizer which may be discarding any memory | |
1999 | allocated during its processing (such as combine and loop). However, | |
2000 | we will be leaving this constant on the chain, so we cannot tolerate | |
2001 | freed memory. So switch to saveable_obstack for this allocation | |
2002 | and then switch back if we were in current_obstack. */ | |
2003 | ||
2260924f JW |
2004 | push_obstacks_nochange (); |
2005 | rtl_in_saveable_obstack (); | |
38a448ca | 2006 | r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1); |
2260924f | 2007 | pop_obstacks (); |
79e68feb | 2008 | |
179bb78c JW |
2009 | /* Don't touch const_double_chain in nested function; see force_const_mem. |
2010 | Also, don't touch it if not inside any function. */ | |
2011 | if (outer_function_chain == 0 && current_function_decl != 0) | |
5145eda8 RS |
2012 | { |
2013 | CONST_DOUBLE_CHAIN (r) = const_double_chain; | |
2014 | const_double_chain = r; | |
2015 | } | |
79e68feb RS |
2016 | |
2017 | /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain. | |
2018 | Actual use of mem-slot is only through force_const_mem. */ | |
2019 | ||
2020 | CONST_DOUBLE_MEM (r) = const0_rtx; | |
2021 | ||
2022 | return r; | |
2023 | } | |
2024 | ||
2025 | /* Return a CONST_DOUBLE for a specified `double' value | |
2026 | and machine mode. */ | |
2027 | ||
2028 | rtx | |
2029 | immed_real_const_1 (d, mode) | |
2030 | REAL_VALUE_TYPE d; | |
2031 | enum machine_mode mode; | |
2032 | { | |
2033 | union real_extract u; | |
2034 | register rtx r; | |
79e68feb RS |
2035 | |
2036 | /* Get the desired `double' value as a sequence of ints | |
2037 | since that is how they are stored in a CONST_DOUBLE. */ | |
2038 | ||
2039 | u.d = d; | |
2040 | ||
2041 | /* Detect special cases. */ | |
2042 | ||
41c9120b | 2043 | if (REAL_VALUES_IDENTICAL (dconst0, d)) |
79e68feb | 2044 | return CONST0_RTX (mode); |
12194c38 RS |
2045 | /* Check for NaN first, because some ports (specifically the i386) do not |
2046 | emit correct ieee-fp code by default, and thus will generate a core | |
2047 | dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL | |
2048 | does a floating point comparison. */ | |
2049 | else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d)) | |
79e68feb RS |
2050 | return CONST1_RTX (mode); |
2051 | ||
37366632 | 2052 | if (sizeof u == 2 * sizeof (HOST_WIDE_INT)) |
79e68feb RS |
2053 | return immed_double_const (u.i[0], u.i[1], mode); |
2054 | ||
2055 | /* The rest of this function handles the case where | |
2056 | a float value requires more than 2 ints of space. | |
2057 | It will be deleted as dead code on machines that don't need it. */ | |
2058 | ||
2059 | /* Search the chain for an existing CONST_DOUBLE with the right value. | |
2060 | If one is found, return it. */ | |
2061 | ||
2062 | for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r)) | |
4c9a05bc | 2063 | if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u) |
79e68feb RS |
2064 | && GET_MODE (r) == mode) |
2065 | return r; | |
2066 | ||
2067 | /* No; make a new one and add it to the chain. | |
2068 | ||
2069 | We may be called by an optimizer which may be discarding any memory | |
2070 | allocated during its processing (such as combine and loop). However, | |
2071 | we will be leaving this constant on the chain, so we cannot tolerate | |
2072 | freed memory. So switch to saveable_obstack for this allocation | |
2073 | and then switch back if we were in current_obstack. */ | |
2074 | ||
2260924f JW |
2075 | push_obstacks_nochange (); |
2076 | rtl_in_saveable_obstack (); | |
79e68feb RS |
2077 | r = rtx_alloc (CONST_DOUBLE); |
2078 | PUT_MODE (r, mode); | |
4c9a05bc | 2079 | bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u); |
2260924f | 2080 | pop_obstacks (); |
79e68feb | 2081 | |
179bb78c JW |
2082 | /* Don't touch const_double_chain in nested function; see force_const_mem. |
2083 | Also, don't touch it if not inside any function. */ | |
2084 | if (outer_function_chain == 0 && current_function_decl != 0) | |
5145eda8 RS |
2085 | { |
2086 | CONST_DOUBLE_CHAIN (r) = const_double_chain; | |
2087 | const_double_chain = r; | |
2088 | } | |
79e68feb RS |
2089 | |
2090 | /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the | |
2091 | chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM | |
2092 | is only through force_const_mem. */ | |
2093 | ||
2094 | CONST_DOUBLE_MEM (r) = const0_rtx; | |
2095 | ||
2096 | return r; | |
2097 | } | |
2098 | ||
2099 | /* Return a CONST_DOUBLE rtx for a value specified by EXP, | |
2100 | which must be a REAL_CST tree node. */ | |
2101 | ||
2102 | rtx | |
2103 | immed_real_const (exp) | |
2104 | tree exp; | |
2105 | { | |
2106 | return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp))); | |
2107 | } | |
2108 | ||
2109 | /* At the end of a function, forget the memory-constants | |
2110 | previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain. | |
2111 | Also clear out real_constant_chain and clear out all the chain-pointers. */ | |
2112 | ||
2113 | void | |
2114 | clear_const_double_mem () | |
2115 | { | |
2116 | register rtx r, next; | |
2117 | ||
57632c51 RS |
2118 | /* Don't touch CONST_DOUBLE_MEM for nested functions. |
2119 | See force_const_mem for explanation. */ | |
2120 | if (outer_function_chain != 0) | |
2121 | return; | |
2122 | ||
79e68feb RS |
2123 | for (r = const_double_chain; r; r = next) |
2124 | { | |
2125 | next = CONST_DOUBLE_CHAIN (r); | |
2126 | CONST_DOUBLE_CHAIN (r) = 0; | |
2127 | CONST_DOUBLE_MEM (r) = cc0_rtx; | |
2128 | } | |
2129 | const_double_chain = 0; | |
2130 | } | |
2131 | \f | |
2132 | /* Given an expression EXP with a constant value, | |
2133 | reduce it to the sum of an assembler symbol and an integer. | |
2134 | Store them both in the structure *VALUE. | |
2135 | Abort if EXP does not reduce. */ | |
2136 | ||
2137 | struct addr_const | |
2138 | { | |
2139 | rtx base; | |
fb351073 | 2140 | HOST_WIDE_INT offset; |
79e68feb RS |
2141 | }; |
2142 | ||
2143 | static void | |
2144 | decode_addr_const (exp, value) | |
2145 | tree exp; | |
2146 | struct addr_const *value; | |
2147 | { | |
2148 | register tree target = TREE_OPERAND (exp, 0); | |
2149 | register int offset = 0; | |
2150 | register rtx x; | |
2151 | ||
2152 | while (1) | |
2153 | { | |
2154 | if (TREE_CODE (target) == COMPONENT_REF | |
2155 | && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) | |
2156 | == INTEGER_CST)) | |
2157 | { | |
2158 | offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT; | |
2159 | target = TREE_OPERAND (target, 0); | |
2160 | } | |
2161 | else if (TREE_CODE (target) == ARRAY_REF) | |
2162 | { | |
2163 | if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST | |
2164 | || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST) | |
2165 | abort (); | |
2166 | offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target))) | |
2167 | * TREE_INT_CST_LOW (TREE_OPERAND (target, 1))) | |
2168 | / BITS_PER_UNIT); | |
2169 | target = TREE_OPERAND (target, 0); | |
2170 | } | |
2171 | else | |
2172 | break; | |
2173 | } | |
2174 | ||
2175 | switch (TREE_CODE (target)) | |
2176 | { | |
2177 | case VAR_DECL: | |
2178 | case FUNCTION_DECL: | |
2179 | x = DECL_RTL (target); | |
2180 | break; | |
2181 | ||
2182 | case LABEL_DECL: | |
b93a436e JL |
2183 | x = gen_rtx_MEM (FUNCTION_MODE, |
2184 | gen_rtx_LABEL_REF (VOIDmode, | |
2185 | label_rtx (TREE_OPERAND (exp, 0)))); | |
79e68feb RS |
2186 | break; |
2187 | ||
2188 | case REAL_CST: | |
2189 | case STRING_CST: | |
2190 | case COMPLEX_CST: | |
2191 | case CONSTRUCTOR: | |
2cf55b55 | 2192 | case INTEGER_CST: |
79e68feb RS |
2193 | x = TREE_CST_RTL (target); |
2194 | break; | |
2195 | ||
2196 | default: | |
2197 | abort (); | |
2198 | } | |
2199 | ||
b93a436e JL |
2200 | if (GET_CODE (x) != MEM) |
2201 | abort (); | |
2202 | x = XEXP (x, 0); | |
79e68feb RS |
2203 | |
2204 | value->base = x; | |
2205 | value->offset = offset; | |
2206 | } | |
2207 | \f | |
2208 | /* Uniquize all constants that appear in memory. | |
2209 | Each constant in memory thus far output is recorded | |
2210 | in `const_hash_table' with a `struct constant_descriptor' | |
2211 | that contains a polish representation of the value of | |
2212 | the constant. | |
2213 | ||
2214 | We cannot store the trees in the hash table | |
2215 | because the trees may be temporary. */ | |
2216 | ||
2217 | struct constant_descriptor | |
2218 | { | |
2219 | struct constant_descriptor *next; | |
2220 | char *label; | |
2221 | char contents[1]; | |
2222 | }; | |
2223 | ||
2224 | #define HASHBITS 30 | |
2225 | #define MAX_HASH_TABLE 1009 | |
2226 | static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE]; | |
2227 | ||
2228 | /* Compute a hash code for a constant expression. */ | |
2229 | ||
5a13eaa4 | 2230 | static int |
79e68feb RS |
2231 | const_hash (exp) |
2232 | tree exp; | |
2233 | { | |
2234 | register char *p; | |
2235 | register int len, hi, i; | |
2236 | register enum tree_code code = TREE_CODE (exp); | |
2237 | ||
a9d07d6e RK |
2238 | /* Either set P and LEN to the address and len of something to hash and |
2239 | exit the switch or return a value. */ | |
2240 | ||
2241 | switch (code) | |
79e68feb | 2242 | { |
a9d07d6e | 2243 | case INTEGER_CST: |
79e68feb RS |
2244 | p = (char *) &TREE_INT_CST_LOW (exp); |
2245 | len = 2 * sizeof TREE_INT_CST_LOW (exp); | |
a9d07d6e RK |
2246 | break; |
2247 | ||
2248 | case REAL_CST: | |
79e68feb RS |
2249 | p = (char *) &TREE_REAL_CST (exp); |
2250 | len = sizeof TREE_REAL_CST (exp); | |
a9d07d6e | 2251 | break; |
79e68feb | 2252 | |
a9d07d6e RK |
2253 | case STRING_CST: |
2254 | p = TREE_STRING_POINTER (exp); | |
2255 | len = TREE_STRING_LENGTH (exp); | |
2256 | break; | |
79e68feb | 2257 | |
a9d07d6e RK |
2258 | case COMPLEX_CST: |
2259 | return (const_hash (TREE_REALPART (exp)) * 5 | |
2260 | + const_hash (TREE_IMAGPART (exp))); | |
2261 | ||
2262 | case CONSTRUCTOR: | |
2263 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) | |
79e68feb | 2264 | { |
a9d07d6e RK |
2265 | len = int_size_in_bytes (TREE_TYPE (exp)); |
2266 | p = (char *) alloca (len); | |
2267 | get_set_constructor_bytes (exp, (unsigned char *) p, len); | |
2268 | break; | |
2269 | } | |
2270 | else | |
2271 | { | |
2272 | register tree link; | |
2273 | ||
2274 | /* For record type, include the type in the hashing. | |
2275 | We do not do so for array types | |
2276 | because (1) the sizes of the elements are sufficient | |
2277 | and (2) distinct array types can have the same constructor. | |
2278 | Instead, we include the array size because the constructor could | |
2279 | be shorter. */ | |
2280 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) | |
7bcac048 | 2281 | hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1)) |
a9d07d6e RK |
2282 | % MAX_HASH_TABLE; |
2283 | else | |
2284 | hi = ((5 + int_size_in_bytes (TREE_TYPE (exp))) | |
2285 | & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE; | |
2286 | ||
2287 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
2288 | if (TREE_VALUE (link)) | |
2289 | hi | |
2290 | = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE; | |
2291 | ||
2292 | return hi; | |
79e68feb | 2293 | } |
79e68feb | 2294 | |
a9d07d6e RK |
2295 | case ADDR_EXPR: |
2296 | { | |
2297 | struct addr_const value; | |
2298 | ||
2299 | decode_addr_const (exp, &value); | |
2300 | if (GET_CODE (value.base) == SYMBOL_REF) | |
2301 | { | |
2302 | /* Don't hash the address of the SYMBOL_REF; | |
2303 | only use the offset and the symbol name. */ | |
2304 | hi = value.offset; | |
2305 | p = XSTR (value.base, 0); | |
2306 | for (i = 0; p[i] != 0; i++) | |
2307 | hi = ((hi * 613) + (unsigned) (p[i])); | |
2308 | } | |
2309 | else if (GET_CODE (value.base) == LABEL_REF) | |
2310 | hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13; | |
2311 | ||
2312 | hi &= (1 << HASHBITS) - 1; | |
2313 | hi %= MAX_HASH_TABLE; | |
2314 | } | |
79e68feb | 2315 | return hi; |
a9d07d6e RK |
2316 | |
2317 | case PLUS_EXPR: | |
2318 | case MINUS_EXPR: | |
2319 | return (const_hash (TREE_OPERAND (exp, 0)) * 9 | |
2320 | + const_hash (TREE_OPERAND (exp, 1))); | |
2321 | ||
2322 | case NOP_EXPR: | |
2323 | case CONVERT_EXPR: | |
2324 | case NON_LVALUE_EXPR: | |
2325 | return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2; | |
e9a25f70 JL |
2326 | |
2327 | default: | |
2328 | abort (); | |
79e68feb | 2329 | } |
79e68feb RS |
2330 | |
2331 | /* Compute hashing function */ | |
2332 | hi = len; | |
2333 | for (i = 0; i < len; i++) | |
0f41302f | 2334 | hi = ((hi * 613) + (unsigned) (p[i])); |
79e68feb RS |
2335 | |
2336 | hi &= (1 << HASHBITS) - 1; | |
2337 | hi %= MAX_HASH_TABLE; | |
2338 | return hi; | |
2339 | } | |
2340 | \f | |
2341 | /* Compare a constant expression EXP with a constant-descriptor DESC. | |
2342 | Return 1 if DESC describes a constant with the same value as EXP. */ | |
2343 | ||
2344 | static int | |
2345 | compare_constant (exp, desc) | |
2346 | tree exp; | |
2347 | struct constant_descriptor *desc; | |
2348 | { | |
2349 | return 0 != compare_constant_1 (exp, desc->contents); | |
2350 | } | |
2351 | ||
2352 | /* Compare constant expression EXP with a substring P of a constant descriptor. | |
2353 | If they match, return a pointer to the end of the substring matched. | |
2354 | If they do not match, return 0. | |
2355 | ||
2356 | Since descriptors are written in polish prefix notation, | |
2357 | this function can be used recursively to test one operand of EXP | |
2358 | against a subdescriptor, and if it succeeds it returns the | |
2359 | address of the subdescriptor for the next operand. */ | |
2360 | ||
2361 | static char * | |
2362 | compare_constant_1 (exp, p) | |
2363 | tree exp; | |
2364 | char *p; | |
2365 | { | |
2366 | register char *strp; | |
2367 | register int len; | |
2368 | register enum tree_code code = TREE_CODE (exp); | |
2369 | ||
2370 | if (code != (enum tree_code) *p++) | |
2371 | return 0; | |
2372 | ||
a9d07d6e RK |
2373 | /* Either set STRP, P and LEN to pointers and length to compare and exit the |
2374 | switch, or return the result of the comparison. */ | |
2375 | ||
2376 | switch (code) | |
79e68feb | 2377 | { |
a9d07d6e | 2378 | case INTEGER_CST: |
79e68feb RS |
2379 | /* Integer constants are the same only if the same width of type. */ |
2380 | if (*p++ != TYPE_PRECISION (TREE_TYPE (exp))) | |
2381 | return 0; | |
a9d07d6e | 2382 | |
79e68feb RS |
2383 | strp = (char *) &TREE_INT_CST_LOW (exp); |
2384 | len = 2 * sizeof TREE_INT_CST_LOW (exp); | |
a9d07d6e RK |
2385 | break; |
2386 | ||
2387 | case REAL_CST: | |
79e68feb RS |
2388 | /* Real constants are the same only if the same width of type. */ |
2389 | if (*p++ != TYPE_PRECISION (TREE_TYPE (exp))) | |
2390 | return 0; | |
a9d07d6e | 2391 | |
79e68feb RS |
2392 | strp = (char *) &TREE_REAL_CST (exp); |
2393 | len = sizeof TREE_REAL_CST (exp); | |
a9d07d6e RK |
2394 | break; |
2395 | ||
2396 | case STRING_CST: | |
79e68feb RS |
2397 | if (flag_writable_strings) |
2398 | return 0; | |
a9d07d6e | 2399 | |
f163668c RK |
2400 | if (*p++ != TYPE_MODE (TREE_TYPE (exp))) |
2401 | return 0; | |
2402 | ||
79e68feb RS |
2403 | strp = TREE_STRING_POINTER (exp); |
2404 | len = TREE_STRING_LENGTH (exp); | |
4c9a05bc | 2405 | if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p, |
79e68feb RS |
2406 | sizeof TREE_STRING_LENGTH (exp))) |
2407 | return 0; | |
a9d07d6e | 2408 | |
79e68feb | 2409 | p += sizeof TREE_STRING_LENGTH (exp); |
a9d07d6e | 2410 | break; |
79e68feb | 2411 | |
a9d07d6e RK |
2412 | case COMPLEX_CST: |
2413 | p = compare_constant_1 (TREE_REALPART (exp), p); | |
2414 | if (p == 0) | |
79e68feb | 2415 | return 0; |
79e68feb | 2416 | |
a9d07d6e | 2417 | return compare_constant_1 (TREE_IMAGPART (exp), p); |
79e68feb | 2418 | |
a9d07d6e RK |
2419 | case CONSTRUCTOR: |
2420 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) | |
eb528802 | 2421 | { |
a9d07d6e RK |
2422 | int xlen = len = int_size_in_bytes (TREE_TYPE (exp)); |
2423 | ||
2424 | strp = (char *) alloca (len); | |
2425 | get_set_constructor_bytes (exp, (unsigned char *) strp, len); | |
2426 | if (bcmp ((char *) &xlen, p, sizeof xlen)) | |
eb528802 | 2427 | return 0; |
eb528802 | 2428 | |
a9d07d6e RK |
2429 | p += sizeof xlen; |
2430 | break; | |
2431 | } | |
2432 | else | |
77fa0940 | 2433 | { |
a9d07d6e RK |
2434 | register tree link; |
2435 | int length = list_length (CONSTRUCTOR_ELTS (exp)); | |
2436 | tree type; | |
e5e809f4 JL |
2437 | int have_purpose = 0; |
2438 | ||
2439 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
2440 | if (TREE_PURPOSE (link)) | |
2441 | have_purpose = 1; | |
a9d07d6e RK |
2442 | |
2443 | if (bcmp ((char *) &length, p, sizeof length)) | |
2444 | return 0; | |
2445 | ||
2446 | p += sizeof length; | |
2447 | ||
2448 | /* For record constructors, insist that the types match. | |
e5e809f4 JL |
2449 | For arrays, just verify both constructors are for arrays. |
2450 | Then insist that either both or none have any TREE_PURPOSE | |
2451 | values. */ | |
a9d07d6e RK |
2452 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) |
2453 | type = TREE_TYPE (exp); | |
2454 | else | |
2455 | type = 0; | |
2456 | ||
2457 | if (bcmp ((char *) &type, p, sizeof type)) | |
2458 | return 0; | |
2459 | ||
2460 | p += sizeof type; | |
2461 | ||
e5e809f4 JL |
2462 | if (bcmp ((char *) &have_purpose, p, sizeof have_purpose)) |
2463 | return 0; | |
2464 | ||
2465 | p += sizeof have_purpose; | |
2466 | ||
a9d07d6e RK |
2467 | /* For arrays, insist that the size in bytes match. */ |
2468 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) | |
77fa0940 | 2469 | { |
e5e809f4 JL |
2470 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); |
2471 | ||
a9d07d6e | 2472 | if (bcmp ((char *) &size, p, sizeof size)) |
77fa0940 | 2473 | return 0; |
a9d07d6e RK |
2474 | |
2475 | p += sizeof size; | |
77fa0940 | 2476 | } |
a9d07d6e RK |
2477 | |
2478 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
77fa0940 | 2479 | { |
a9d07d6e RK |
2480 | if (TREE_VALUE (link)) |
2481 | { | |
2482 | if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0) | |
2483 | return 0; | |
2484 | } | |
2485 | else | |
2486 | { | |
2487 | tree zero = 0; | |
77fa0940 | 2488 | |
e5e809f4 JL |
2489 | if (bcmp ((char *) &zero, p, sizeof zero)) |
2490 | return 0; | |
2491 | ||
2492 | p += sizeof zero; | |
2493 | } | |
2494 | ||
2495 | if (TREE_PURPOSE (link) | |
2496 | && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL) | |
2497 | { | |
2498 | if (bcmp ((char *) &TREE_PURPOSE (link), p, | |
2499 | sizeof TREE_PURPOSE (link))) | |
2500 | return 0; | |
2501 | ||
2502 | p += sizeof TREE_PURPOSE (link); | |
2503 | } | |
2504 | else if (TREE_PURPOSE (link)) | |
2505 | { | |
2506 | if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0) | |
2507 | return 0; | |
2508 | } | |
2509 | else if (have_purpose) | |
2510 | { | |
2511 | int zero = 0; | |
2512 | ||
a9d07d6e RK |
2513 | if (bcmp ((char *) &zero, p, sizeof zero)) |
2514 | return 0; | |
2515 | ||
2516 | p += sizeof zero; | |
2517 | } | |
77fa0940 | 2518 | } |
a9d07d6e RK |
2519 | |
2520 | return p; | |
77fa0940 RK |
2521 | } |
2522 | ||
a9d07d6e RK |
2523 | case ADDR_EXPR: |
2524 | { | |
2525 | struct addr_const value; | |
2526 | ||
2527 | decode_addr_const (exp, &value); | |
2528 | strp = (char *) &value.offset; | |
2529 | len = sizeof value.offset; | |
2530 | /* Compare the offset. */ | |
2531 | while (--len >= 0) | |
2532 | if (*p++ != *strp++) | |
2533 | return 0; | |
2534 | ||
2535 | /* Compare symbol name. */ | |
2536 | strp = XSTR (value.base, 0); | |
2537 | len = strlen (strp) + 1; | |
2538 | } | |
2539 | break; | |
2540 | ||
2541 | case PLUS_EXPR: | |
2542 | case MINUS_EXPR: | |
79e68feb | 2543 | p = compare_constant_1 (TREE_OPERAND (exp, 0), p); |
a9d07d6e RK |
2544 | if (p == 0) |
2545 | return 0; | |
2546 | ||
2547 | return compare_constant_1 (TREE_OPERAND (exp, 1), p); | |
2548 | ||
2549 | case NOP_EXPR: | |
2550 | case CONVERT_EXPR: | |
2551 | case NON_LVALUE_EXPR: | |
2552 | return compare_constant_1 (TREE_OPERAND (exp, 0), p); | |
e9a25f70 JL |
2553 | |
2554 | default: | |
2555 | abort (); | |
79e68feb RS |
2556 | } |
2557 | ||
2558 | /* Compare constant contents. */ | |
2559 | while (--len >= 0) | |
2560 | if (*p++ != *strp++) | |
2561 | return 0; | |
2562 | ||
2563 | return p; | |
2564 | } | |
2565 | \f | |
2566 | /* Construct a constant descriptor for the expression EXP. | |
2567 | It is up to the caller to enter the descriptor in the hash table. */ | |
2568 | ||
2569 | static struct constant_descriptor * | |
2570 | record_constant (exp) | |
2571 | tree exp; | |
2572 | { | |
387e854a RK |
2573 | struct constant_descriptor *next = 0; |
2574 | char *label = 0; | |
79e68feb | 2575 | |
387e854a RK |
2576 | /* Make a struct constant_descriptor. The first two pointers will |
2577 | be filled in later. Here we just leave space for them. */ | |
2578 | ||
2579 | obstack_grow (&permanent_obstack, (char *) &next, sizeof next); | |
2580 | obstack_grow (&permanent_obstack, (char *) &label, sizeof label); | |
79e68feb RS |
2581 | record_constant_1 (exp); |
2582 | return (struct constant_descriptor *) obstack_finish (&permanent_obstack); | |
2583 | } | |
2584 | ||
2585 | /* Add a description of constant expression EXP | |
2586 | to the object growing in `permanent_obstack'. | |
2587 | No need to return its address; the caller will get that | |
2588 | from the obstack when the object is complete. */ | |
2589 | ||
2590 | static void | |
2591 | record_constant_1 (exp) | |
2592 | tree exp; | |
2593 | { | |
2594 | register char *strp; | |
2595 | register int len; | |
2596 | register enum tree_code code = TREE_CODE (exp); | |
2597 | ||
2598 | obstack_1grow (&permanent_obstack, (unsigned int) code); | |
2599 | ||
2871d24f | 2600 | switch (code) |
79e68feb | 2601 | { |
2871d24f | 2602 | case INTEGER_CST: |
79e68feb RS |
2603 | obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp))); |
2604 | strp = (char *) &TREE_INT_CST_LOW (exp); | |
2605 | len = 2 * sizeof TREE_INT_CST_LOW (exp); | |
2871d24f RK |
2606 | break; |
2607 | ||
2608 | case REAL_CST: | |
79e68feb RS |
2609 | obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp))); |
2610 | strp = (char *) &TREE_REAL_CST (exp); | |
2611 | len = sizeof TREE_REAL_CST (exp); | |
2871d24f RK |
2612 | break; |
2613 | ||
2614 | case STRING_CST: | |
79e68feb RS |
2615 | if (flag_writable_strings) |
2616 | return; | |
2871d24f | 2617 | |
f163668c | 2618 | obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp))); |
79e68feb RS |
2619 | strp = TREE_STRING_POINTER (exp); |
2620 | len = TREE_STRING_LENGTH (exp); | |
2621 | obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp), | |
2622 | sizeof TREE_STRING_LENGTH (exp)); | |
2871d24f RK |
2623 | break; |
2624 | ||
2625 | case COMPLEX_CST: | |
79e68feb RS |
2626 | record_constant_1 (TREE_REALPART (exp)); |
2627 | record_constant_1 (TREE_IMAGPART (exp)); | |
2628 | return; | |
79e68feb | 2629 | |
2871d24f RK |
2630 | case CONSTRUCTOR: |
2631 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) | |
eb528802 | 2632 | { |
2871d24f RK |
2633 | int nbytes = int_size_in_bytes (TREE_TYPE (exp)); |
2634 | obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes)); | |
2635 | obstack_blank (&permanent_obstack, nbytes); | |
2636 | get_set_constructor_bytes | |
2491d239 PB |
2637 | (exp, (unsigned char *) permanent_obstack.next_free-nbytes, |
2638 | nbytes); | |
2871d24f | 2639 | return; |
eb528802 | 2640 | } |
2871d24f | 2641 | else |
77fa0940 | 2642 | { |
2871d24f RK |
2643 | register tree link; |
2644 | int length = list_length (CONSTRUCTOR_ELTS (exp)); | |
2645 | tree type; | |
e5e809f4 JL |
2646 | int have_purpose = 0; |
2647 | ||
2648 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
2649 | if (TREE_PURPOSE (link)) | |
2650 | have_purpose = 1; | |
2871d24f RK |
2651 | |
2652 | obstack_grow (&permanent_obstack, (char *) &length, sizeof length); | |
2653 | ||
2654 | /* For record constructors, insist that the types match. | |
e5e809f4 JL |
2655 | For arrays, just verify both constructors are for arrays. |
2656 | Then insist that either both or none have any TREE_PURPOSE | |
2657 | values. */ | |
2871d24f RK |
2658 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) |
2659 | type = TREE_TYPE (exp); | |
77fa0940 | 2660 | else |
2871d24f RK |
2661 | type = 0; |
2662 | obstack_grow (&permanent_obstack, (char *) &type, sizeof type); | |
e5e809f4 JL |
2663 | obstack_grow (&permanent_obstack, (char *) &have_purpose, |
2664 | sizeof have_purpose); | |
2871d24f RK |
2665 | |
2666 | /* For arrays, insist that the size in bytes match. */ | |
2667 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) | |
77fa0940 | 2668 | { |
e5e809f4 | 2669 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); |
2871d24f RK |
2670 | obstack_grow (&permanent_obstack, (char *) &size, sizeof size); |
2671 | } | |
77fa0940 | 2672 | |
2871d24f RK |
2673 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) |
2674 | { | |
2675 | if (TREE_VALUE (link)) | |
2676 | record_constant_1 (TREE_VALUE (link)); | |
2677 | else | |
2678 | { | |
2679 | tree zero = 0; | |
2680 | ||
e5e809f4 JL |
2681 | obstack_grow (&permanent_obstack, |
2682 | (char *) &zero, sizeof zero); | |
2683 | } | |
2684 | ||
2685 | if (TREE_PURPOSE (link) | |
2686 | && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL) | |
2687 | obstack_grow (&permanent_obstack, | |
2688 | (char *) &TREE_PURPOSE (link), | |
2689 | sizeof TREE_PURPOSE (link)); | |
2690 | else if (TREE_PURPOSE (link)) | |
2691 | record_constant_1 (TREE_PURPOSE (link)); | |
2692 | else if (have_purpose) | |
2693 | { | |
2694 | int zero = 0; | |
2695 | ||
2871d24f RK |
2696 | obstack_grow (&permanent_obstack, |
2697 | (char *) &zero, sizeof zero); | |
2698 | } | |
77fa0940 RK |
2699 | } |
2700 | } | |
79e68feb | 2701 | return; |
2871d24f RK |
2702 | |
2703 | case ADDR_EXPR: | |
2704 | { | |
2705 | struct addr_const value; | |
2706 | ||
2707 | decode_addr_const (exp, &value); | |
2708 | /* Record the offset. */ | |
2709 | obstack_grow (&permanent_obstack, | |
2710 | (char *) &value.offset, sizeof value.offset); | |
2711 | /* Record the symbol name. */ | |
2712 | obstack_grow (&permanent_obstack, XSTR (value.base, 0), | |
2713 | strlen (XSTR (value.base, 0)) + 1); | |
2714 | } | |
79e68feb | 2715 | return; |
2871d24f RK |
2716 | |
2717 | case PLUS_EXPR: | |
2718 | case MINUS_EXPR: | |
79e68feb RS |
2719 | record_constant_1 (TREE_OPERAND (exp, 0)); |
2720 | record_constant_1 (TREE_OPERAND (exp, 1)); | |
2721 | return; | |
2871d24f RK |
2722 | |
2723 | case NOP_EXPR: | |
2724 | case CONVERT_EXPR: | |
2725 | case NON_LVALUE_EXPR: | |
79e68feb RS |
2726 | record_constant_1 (TREE_OPERAND (exp, 0)); |
2727 | return; | |
2871d24f RK |
2728 | |
2729 | default: | |
2730 | abort (); | |
79e68feb RS |
2731 | } |
2732 | ||
2733 | /* Record constant contents. */ | |
2734 | obstack_grow (&permanent_obstack, strp, len); | |
2735 | } | |
2736 | \f | |
ff8f4401 RS |
2737 | /* Record a list of constant expressions that were passed to |
2738 | output_constant_def but that could not be output right away. */ | |
2739 | ||
2740 | struct deferred_constant | |
2741 | { | |
2742 | struct deferred_constant *next; | |
2743 | tree exp; | |
2744 | int reloc; | |
2745 | int labelno; | |
2746 | }; | |
2747 | ||
2748 | static struct deferred_constant *deferred_constants; | |
2749 | ||
8839fca4 ILT |
2750 | /* Another list of constants which should be output after the |
2751 | function. */ | |
2752 | static struct deferred_constant *after_function_constants; | |
2753 | ||
ff8f4401 RS |
2754 | /* Nonzero means defer output of addressed subconstants |
2755 | (i.e., those for which output_constant_def is called.) */ | |
2756 | static int defer_addressed_constants_flag; | |
2757 | ||
2758 | /* Start deferring output of subconstants. */ | |
2759 | ||
2760 | void | |
2761 | defer_addressed_constants () | |
2762 | { | |
2763 | defer_addressed_constants_flag++; | |
2764 | } | |
2765 | ||
2766 | /* Stop deferring output of subconstants, | |
2767 | and output now all those that have been deferred. */ | |
2768 | ||
2769 | void | |
2770 | output_deferred_addressed_constants () | |
2771 | { | |
2772 | struct deferred_constant *p, *next; | |
2773 | ||
2774 | defer_addressed_constants_flag--; | |
2775 | ||
2776 | if (defer_addressed_constants_flag > 0) | |
2777 | return; | |
2778 | ||
2779 | for (p = deferred_constants; p; p = next) | |
2780 | { | |
2781 | output_constant_def_contents (p->exp, p->reloc, p->labelno); | |
2782 | next = p->next; | |
2783 | free (p); | |
2784 | } | |
2785 | ||
2786 | deferred_constants = 0; | |
2787 | } | |
d12516f1 | 2788 | |
8839fca4 ILT |
2789 | /* Output any constants which should appear after a function. */ |
2790 | ||
2791 | static void | |
2792 | output_after_function_constants () | |
2793 | { | |
2794 | struct deferred_constant *p, *next; | |
2795 | ||
2796 | for (p = after_function_constants; p; p = next) | |
2797 | { | |
2798 | output_constant_def_contents (p->exp, p->reloc, p->labelno); | |
2799 | next = p->next; | |
2800 | free (p); | |
2801 | } | |
2802 | ||
2803 | after_function_constants = 0; | |
2804 | } | |
2805 | ||
d12516f1 RS |
2806 | /* Make a copy of the whole tree structure for a constant. |
2807 | This handles the same types of nodes that compare_constant | |
2808 | and record_constant handle. */ | |
2809 | ||
2810 | static tree | |
2811 | copy_constant (exp) | |
2812 | tree exp; | |
2813 | { | |
2814 | switch (TREE_CODE (exp)) | |
2815 | { | |
310bbbf4 JW |
2816 | case ADDR_EXPR: |
2817 | /* For ADDR_EXPR, we do not want to copy the decl whose address | |
2818 | is requested. We do want to copy constants though. */ | |
2819 | if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c') | |
2820 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), | |
2821 | copy_constant (TREE_OPERAND (exp, 0))); | |
2822 | else | |
2823 | return copy_node (exp); | |
2824 | ||
d12516f1 RS |
2825 | case INTEGER_CST: |
2826 | case REAL_CST: | |
2827 | case STRING_CST: | |
d12516f1 RS |
2828 | return copy_node (exp); |
2829 | ||
2830 | case COMPLEX_CST: | |
28eb1cb8 RK |
2831 | return build_complex (TREE_TYPE (exp), |
2832 | copy_constant (TREE_REALPART (exp)), | |
d12516f1 RS |
2833 | copy_constant (TREE_IMAGPART (exp))); |
2834 | ||
2835 | case PLUS_EXPR: | |
2836 | case MINUS_EXPR: | |
2837 | return build (TREE_CODE (exp), TREE_TYPE (exp), | |
2838 | copy_constant (TREE_OPERAND (exp, 0)), | |
2839 | copy_constant (TREE_OPERAND (exp, 1))); | |
2840 | ||
2841 | case NOP_EXPR: | |
2842 | case CONVERT_EXPR: | |
a9d07d6e | 2843 | case NON_LVALUE_EXPR: |
d12516f1 RS |
2844 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), |
2845 | copy_constant (TREE_OPERAND (exp, 0))); | |
2846 | ||
2847 | case CONSTRUCTOR: | |
2848 | { | |
2849 | tree copy = copy_node (exp); | |
2850 | tree list = copy_list (CONSTRUCTOR_ELTS (exp)); | |
2851 | tree tail; | |
2852 | ||
bb31ce0a | 2853 | CONSTRUCTOR_ELTS (copy) = list; |
d12516f1 RS |
2854 | for (tail = list; tail; tail = TREE_CHAIN (tail)) |
2855 | TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail)); | |
474bda6c PB |
2856 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) |
2857 | for (tail = list; tail; tail = TREE_CHAIN (tail)) | |
2858 | TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail)); | |
d12516f1 RS |
2859 | |
2860 | return copy; | |
2861 | } | |
2862 | ||
2863 | default: | |
2864 | abort (); | |
2865 | } | |
2866 | } | |
ff8f4401 | 2867 | \f |
79e68feb RS |
2868 | /* Return an rtx representing a reference to constant data in memory |
2869 | for the constant expression EXP. | |
ff8f4401 | 2870 | |
79e68feb RS |
2871 | If assembler code for such a constant has already been output, |
2872 | return an rtx to refer to it. | |
ff8f4401 RS |
2873 | Otherwise, output such a constant in memory (or defer it for later) |
2874 | and generate an rtx for it. | |
2875 | ||
2876 | The TREE_CST_RTL of EXP is set up to point to that rtx. | |
79e68feb RS |
2877 | The const_hash_table records which constants already have label strings. */ |
2878 | ||
2879 | rtx | |
2880 | output_constant_def (exp) | |
2881 | tree exp; | |
2882 | { | |
ff8f4401 | 2883 | register int hash; |
79e68feb RS |
2884 | register struct constant_descriptor *desc; |
2885 | char label[256]; | |
2886 | char *found = 0; | |
2887 | int reloc; | |
2888 | register rtx def; | |
2889 | ||
79e68feb RS |
2890 | if (TREE_CST_RTL (exp)) |
2891 | return TREE_CST_RTL (exp); | |
2892 | ||
2893 | /* Make sure any other constants whose addresses appear in EXP | |
2894 | are assigned label numbers. */ | |
2895 | ||
2896 | reloc = output_addressed_constants (exp); | |
2897 | ||
2898 | /* Compute hash code of EXP. Search the descriptors for that hash code | |
2899 | to see if any of them describes EXP. If yes, the descriptor records | |
2900 | the label number already assigned. */ | |
2901 | ||
00f07fb9 | 2902 | hash = const_hash (exp) % MAX_HASH_TABLE; |
ca695ac9 | 2903 | |
00f07fb9 RK |
2904 | for (desc = const_hash_table[hash]; desc; desc = desc->next) |
2905 | if (compare_constant (exp, desc)) | |
2906 | { | |
2907 | found = desc->label; | |
2908 | break; | |
2909 | } | |
ca695ac9 | 2910 | |
00f07fb9 RK |
2911 | if (found == 0) |
2912 | { | |
2913 | /* No constant equal to EXP is known to have been output. | |
2914 | Make a constant descriptor to enter EXP in the hash table. | |
2915 | Assign the label number and record it in the descriptor for | |
2916 | future calls to this function to find. */ | |
ca695ac9 | 2917 | |
00f07fb9 RK |
2918 | /* Create a string containing the label name, in LABEL. */ |
2919 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
2920 | ||
2921 | desc = record_constant (exp); | |
2922 | desc->next = const_hash_table[hash]; | |
2923 | desc->label | |
2924 | = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label)); | |
2925 | const_hash_table[hash] = desc; | |
2926 | } | |
2927 | else | |
2928 | { | |
2929 | /* Create a string containing the label name, in LABEL. */ | |
2930 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
79e68feb | 2931 | } |
ca695ac9 | 2932 | |
79e68feb RS |
2933 | /* We have a symbol name; construct the SYMBOL_REF and the MEM. */ |
2934 | ||
2935 | push_obstacks_nochange (); | |
2936 | if (TREE_PERMANENT (exp)) | |
2937 | end_temporary_allocation (); | |
2938 | ||
38a448ca | 2939 | def = gen_rtx_SYMBOL_REF (Pmode, desc->label); |
ca695ac9 | 2940 | |
00f07fb9 | 2941 | TREE_CST_RTL (exp) |
38a448ca | 2942 | = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def); |
00f07fb9 | 2943 | RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1; |
05e3bdb9 | 2944 | if (AGGREGATE_TYPE_P (TREE_TYPE (exp))) |
00f07fb9 RK |
2945 | MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1; |
2946 | ||
79e68feb RS |
2947 | pop_obstacks (); |
2948 | ||
2949 | /* Optionally set flags or add text to the name to record information | |
2950 | such as that it is a function name. If the name is changed, the macro | |
8a425a05 | 2951 | ASM_OUTPUT_LABELREF will have to know how to strip this information. */ |
79e68feb RS |
2952 | #ifdef ENCODE_SECTION_INFO |
2953 | ENCODE_SECTION_INFO (exp); | |
2954 | #endif | |
2955 | ||
ff8f4401 RS |
2956 | /* If this is the first time we've seen this particular constant, |
2957 | output it (or defer its output for later). */ | |
79e68feb RS |
2958 | if (found == 0) |
2959 | { | |
8839fca4 ILT |
2960 | int after_function = 0; |
2961 | ||
2962 | #ifdef CONSTANT_AFTER_FUNCTION_P | |
2963 | if (current_function_decl != 0 | |
2964 | && CONSTANT_AFTER_FUNCTION_P (exp)) | |
2965 | after_function = 1; | |
2966 | #endif | |
2967 | ||
2968 | if (defer_addressed_constants_flag || after_function) | |
ff8f4401 RS |
2969 | { |
2970 | struct deferred_constant *p; | |
2971 | p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant)); | |
2972 | ||
ff8f4401 RS |
2973 | push_obstacks_nochange (); |
2974 | suspend_momentary (); | |
d12516f1 | 2975 | p->exp = copy_constant (exp); |
ff8f4401 RS |
2976 | pop_obstacks (); |
2977 | p->reloc = reloc; | |
2978 | p->labelno = const_labelno++; | |
8839fca4 ILT |
2979 | if (after_function) |
2980 | { | |
2981 | p->next = after_function_constants; | |
2982 | after_function_constants = p; | |
2983 | } | |
2984 | else | |
2985 | { | |
2986 | p->next = deferred_constants; | |
2987 | deferred_constants = p; | |
2988 | } | |
ff8f4401 RS |
2989 | } |
2990 | else | |
2991 | output_constant_def_contents (exp, reloc, const_labelno++); | |
2992 | } | |
2993 | ||
2994 | return TREE_CST_RTL (exp); | |
2995 | } | |
2996 | ||
2997 | /* Now output assembler code to define the label for EXP, | |
2998 | and follow it with the data of EXP. */ | |
79e68feb | 2999 | |
ff8f4401 RS |
3000 | static void |
3001 | output_constant_def_contents (exp, reloc, labelno) | |
3002 | tree exp; | |
3003 | int reloc; | |
3004 | int labelno; | |
3005 | { | |
3006 | int align; | |
3007 | ||
8a425a05 | 3008 | if (IN_NAMED_SECTION (exp)) |
ad4ff310 | 3009 | named_section (exp, NULL, reloc); |
8a425a05 DE |
3010 | else |
3011 | { | |
3012 | /* First switch to text section, except for writable strings. */ | |
79e68feb | 3013 | #ifdef SELECT_SECTION |
8a425a05 | 3014 | SELECT_SECTION (exp, reloc); |
79e68feb | 3015 | #else |
8a425a05 DE |
3016 | if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings) |
3017 | || (flag_pic && reloc)) | |
3018 | data_section (); | |
3019 | else | |
3020 | readonly_data_section (); | |
79e68feb | 3021 | #endif |
8a425a05 | 3022 | } |
79e68feb | 3023 | |
ff8f4401 RS |
3024 | /* Align the location counter as required by EXP's data type. */ |
3025 | align = TYPE_ALIGN (TREE_TYPE (exp)); | |
79e68feb | 3026 | #ifdef CONSTANT_ALIGNMENT |
ff8f4401 | 3027 | align = CONSTANT_ALIGNMENT (exp, align); |
79e68feb RS |
3028 | #endif |
3029 | ||
ff8f4401 | 3030 | if (align > BITS_PER_UNIT) |
b93a436e | 3031 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); |
79e68feb | 3032 | |
ff8f4401 RS |
3033 | /* Output the label itself. */ |
3034 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno); | |
79e68feb | 3035 | |
ff8f4401 RS |
3036 | /* Output the value of EXP. */ |
3037 | output_constant (exp, | |
3038 | (TREE_CODE (exp) == STRING_CST | |
3039 | ? TREE_STRING_LENGTH (exp) | |
3040 | : int_size_in_bytes (TREE_TYPE (exp)))); | |
79e68feb | 3041 | |
79e68feb RS |
3042 | } |
3043 | \f | |
3044 | /* Similar hash facility for making memory-constants | |
3045 | from constant rtl-expressions. It is used on RISC machines | |
3046 | where immediate integer arguments and constant addresses are restricted | |
3047 | so that such constants must be stored in memory. | |
3048 | ||
3049 | This pool of constants is reinitialized for each function | |
3050 | so each function gets its own constants-pool that comes right before it. | |
3051 | ||
3052 | All structures allocated here are discarded when functions are saved for | |
3053 | inlining, so they do not need to be allocated permanently. */ | |
3054 | ||
3055 | #define MAX_RTX_HASH_TABLE 61 | |
57632c51 | 3056 | static struct constant_descriptor **const_rtx_hash_table; |
79e68feb RS |
3057 | |
3058 | /* Structure to represent sufficient information about a constant so that | |
3059 | it can be output when the constant pool is output, so that function | |
3060 | integration can be done, and to simplify handling on machines that reference | |
3061 | constant pool as base+displacement. */ | |
3062 | ||
3063 | struct pool_constant | |
3064 | { | |
3065 | struct constant_descriptor *desc; | |
3066 | struct pool_constant *next; | |
3067 | enum machine_mode mode; | |
3068 | rtx constant; | |
3069 | int labelno; | |
3070 | int align; | |
3071 | int offset; | |
91674c37 | 3072 | int mark; |
79e68feb RS |
3073 | }; |
3074 | ||
3075 | /* Pointers to first and last constant in pool. */ | |
3076 | ||
3077 | static struct pool_constant *first_pool, *last_pool; | |
3078 | ||
3079 | /* Current offset in constant pool (does not include any machine-specific | |
3080 | header. */ | |
3081 | ||
3082 | static int pool_offset; | |
3083 | ||
3084 | /* Structure used to maintain hash table mapping symbols used to their | |
3085 | corresponding constants. */ | |
3086 | ||
3087 | struct pool_sym | |
3088 | { | |
3089 | char *label; | |
3090 | struct pool_constant *pool; | |
3091 | struct pool_sym *next; | |
3092 | }; | |
3093 | ||
57632c51 | 3094 | static struct pool_sym **const_rtx_sym_hash_table; |
79e68feb RS |
3095 | |
3096 | /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true. | |
3097 | The argument is XSTR (... , 0) */ | |
3098 | ||
3099 | #define SYMHASH(LABEL) \ | |
7bcac048 | 3100 | ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE) |
79e68feb RS |
3101 | \f |
3102 | /* Initialize constant pool hashing for next function. */ | |
3103 | ||
3104 | void | |
3105 | init_const_rtx_hash_table () | |
3106 | { | |
57632c51 RS |
3107 | const_rtx_hash_table |
3108 | = ((struct constant_descriptor **) | |
3109 | oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *))); | |
3110 | const_rtx_sym_hash_table | |
3111 | = ((struct pool_sym **) | |
3112 | oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *))); | |
4c9a05bc | 3113 | bzero ((char *) const_rtx_hash_table, |
57632c51 | 3114 | MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)); |
4c9a05bc | 3115 | bzero ((char *) const_rtx_sym_hash_table, |
57632c51 | 3116 | MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)); |
79e68feb RS |
3117 | |
3118 | first_pool = last_pool = 0; | |
3119 | pool_offset = 0; | |
3120 | } | |
3121 | ||
5a13eaa4 | 3122 | /* Save and restore status for a nested function. */ |
57632c51 RS |
3123 | |
3124 | void | |
e9a25f70 | 3125 | save_varasm_status (p, context) |
57632c51 | 3126 | struct function *p; |
e9a25f70 | 3127 | tree context; |
57632c51 RS |
3128 | { |
3129 | p->const_rtx_hash_table = const_rtx_hash_table; | |
3130 | p->const_rtx_sym_hash_table = const_rtx_sym_hash_table; | |
3131 | p->first_pool = first_pool; | |
3132 | p->last_pool = last_pool; | |
3133 | p->pool_offset = pool_offset; | |
e9a25f70 JL |
3134 | p->const_double_chain = const_double_chain; |
3135 | ||
3136 | /* If we are pushing to toplevel, we can't reuse const_double_chain. */ | |
3137 | if (context == NULL_TREE) | |
3138 | const_double_chain = 0; | |
57632c51 RS |
3139 | } |
3140 | ||
3141 | void | |
3142 | restore_varasm_status (p) | |
3143 | struct function *p; | |
3144 | { | |
3145 | const_rtx_hash_table = p->const_rtx_hash_table; | |
3146 | const_rtx_sym_hash_table = p->const_rtx_sym_hash_table; | |
3147 | first_pool = p->first_pool; | |
3148 | last_pool = p->last_pool; | |
3149 | pool_offset = p->pool_offset; | |
e9a25f70 | 3150 | const_double_chain = p->const_double_chain; |
57632c51 RS |
3151 | } |
3152 | \f | |
79e68feb RS |
3153 | enum kind { RTX_DOUBLE, RTX_INT }; |
3154 | ||
3155 | struct rtx_const | |
3156 | { | |
3157 | #ifdef ONLY_INT_FIELDS | |
3158 | unsigned int kind : 16; | |
3159 | unsigned int mode : 16; | |
3160 | #else | |
3161 | enum kind kind : 16; | |
3162 | enum machine_mode mode : 16; | |
3163 | #endif | |
3164 | union { | |
3165 | union real_extract du; | |
3166 | struct addr_const addr; | |
0b19a5b9 | 3167 | struct {HOST_WIDE_INT high, low;} di; |
79e68feb RS |
3168 | } un; |
3169 | }; | |
3170 | ||
3171 | /* Express an rtx for a constant integer (perhaps symbolic) | |
3172 | as the sum of a symbol or label plus an explicit integer. | |
3173 | They are stored into VALUE. */ | |
3174 | ||
3175 | static void | |
3176 | decode_rtx_const (mode, x, value) | |
3177 | enum machine_mode mode; | |
3178 | rtx x; | |
3179 | struct rtx_const *value; | |
3180 | { | |
3181 | /* Clear the whole structure, including any gaps. */ | |
3182 | ||
3183 | { | |
3184 | int *p = (int *) value; | |
3185 | int *end = (int *) (value + 1); | |
3186 | while (p < end) | |
3187 | *p++ = 0; | |
3188 | } | |
3189 | ||
0f41302f | 3190 | value->kind = RTX_INT; /* Most usual kind. */ |
79e68feb RS |
3191 | value->mode = mode; |
3192 | ||
3193 | switch (GET_CODE (x)) | |
3194 | { | |
3195 | case CONST_DOUBLE: | |
3196 | value->kind = RTX_DOUBLE; | |
56e2d435 | 3197 | if (GET_MODE (x) != VOIDmode) |
0b19a5b9 RK |
3198 | { |
3199 | value->mode = GET_MODE (x); | |
3200 | bcopy ((char *) &CONST_DOUBLE_LOW (x), | |
3201 | (char *) &value->un.du, sizeof value->un.du); | |
3202 | } | |
3203 | else | |
3204 | { | |
3205 | value->un.di.low = CONST_DOUBLE_LOW (x); | |
3206 | value->un.di.high = CONST_DOUBLE_HIGH (x); | |
3207 | } | |
79e68feb RS |
3208 | break; |
3209 | ||
3210 | case CONST_INT: | |
3211 | value->un.addr.offset = INTVAL (x); | |
3212 | break; | |
3213 | ||
3214 | case SYMBOL_REF: | |
3215 | case LABEL_REF: | |
3d037392 | 3216 | case PC: |
79e68feb RS |
3217 | value->un.addr.base = x; |
3218 | break; | |
3219 | ||
3220 | case CONST: | |
3221 | x = XEXP (x, 0); | |
3222 | if (GET_CODE (x) == PLUS) | |
3223 | { | |
3224 | value->un.addr.base = XEXP (x, 0); | |
3225 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
3226 | abort (); | |
3227 | value->un.addr.offset = INTVAL (XEXP (x, 1)); | |
3228 | } | |
3229 | else if (GET_CODE (x) == MINUS) | |
3230 | { | |
3231 | value->un.addr.base = XEXP (x, 0); | |
3232 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
3233 | abort (); | |
3234 | value->un.addr.offset = - INTVAL (XEXP (x, 1)); | |
3235 | } | |
3236 | else | |
3237 | abort (); | |
3238 | break; | |
3239 | ||
3240 | default: | |
3241 | abort (); | |
3242 | } | |
3243 | ||
3244 | if (value->kind == RTX_INT && value->un.addr.base != 0) | |
3245 | switch (GET_CODE (value->un.addr.base)) | |
3246 | { | |
3247 | case SYMBOL_REF: | |
3248 | case LABEL_REF: | |
3249 | /* Use the string's address, not the SYMBOL_REF's address, | |
3250 | for the sake of addresses of library routines. | |
3251 | For a LABEL_REF, compare labels. */ | |
3252 | value->un.addr.base = XEXP (value->un.addr.base, 0); | |
e9a25f70 JL |
3253 | |
3254 | default: | |
3255 | break; | |
79e68feb RS |
3256 | } |
3257 | } | |
3258 | ||
57632c51 RS |
3259 | /* Given a MINUS expression, simplify it if both sides |
3260 | include the same symbol. */ | |
3261 | ||
3262 | rtx | |
3263 | simplify_subtraction (x) | |
3264 | rtx x; | |
3265 | { | |
3266 | struct rtx_const val0, val1; | |
3267 | ||
3268 | decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0); | |
3269 | decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1); | |
3270 | ||
3271 | if (val0.un.addr.base == val1.un.addr.base) | |
3272 | return GEN_INT (val0.un.addr.offset - val1.un.addr.offset); | |
3273 | return x; | |
3274 | } | |
3275 | ||
79e68feb RS |
3276 | /* Compute a hash code for a constant RTL expression. */ |
3277 | ||
5a13eaa4 | 3278 | static int |
79e68feb RS |
3279 | const_hash_rtx (mode, x) |
3280 | enum machine_mode mode; | |
3281 | rtx x; | |
3282 | { | |
f8344bea MH |
3283 | register int hi; |
3284 | register size_t i; | |
79e68feb RS |
3285 | |
3286 | struct rtx_const value; | |
3287 | decode_rtx_const (mode, x, &value); | |
3288 | ||
3289 | /* Compute hashing function */ | |
3290 | hi = 0; | |
3291 | for (i = 0; i < sizeof value / sizeof (int); i++) | |
3292 | hi += ((int *) &value)[i]; | |
3293 | ||
3294 | hi &= (1 << HASHBITS) - 1; | |
3295 | hi %= MAX_RTX_HASH_TABLE; | |
3296 | return hi; | |
3297 | } | |
3298 | ||
3299 | /* Compare a constant rtl object X with a constant-descriptor DESC. | |
3300 | Return 1 if DESC describes a constant with the same value as X. */ | |
3301 | ||
3302 | static int | |
3303 | compare_constant_rtx (mode, x, desc) | |
3304 | enum machine_mode mode; | |
3305 | rtx x; | |
3306 | struct constant_descriptor *desc; | |
3307 | { | |
3308 | register int *p = (int *) desc->contents; | |
3309 | register int *strp; | |
3310 | register int len; | |
3311 | struct rtx_const value; | |
3312 | ||
3313 | decode_rtx_const (mode, x, &value); | |
3314 | strp = (int *) &value; | |
3315 | len = sizeof value / sizeof (int); | |
3316 | ||
3317 | /* Compare constant contents. */ | |
3318 | while (--len >= 0) | |
3319 | if (*p++ != *strp++) | |
3320 | return 0; | |
3321 | ||
3322 | return 1; | |
3323 | } | |
3324 | ||
3325 | /* Construct a constant descriptor for the rtl-expression X. | |
3326 | It is up to the caller to enter the descriptor in the hash table. */ | |
3327 | ||
3328 | static struct constant_descriptor * | |
3329 | record_constant_rtx (mode, x) | |
3330 | enum machine_mode mode; | |
3331 | rtx x; | |
3332 | { | |
3333 | struct constant_descriptor *ptr; | |
3334 | char *label; | |
3335 | struct rtx_const value; | |
3336 | ||
3337 | decode_rtx_const (mode, x, &value); | |
3338 | ||
75974726 RK |
3339 | /* Put these things in the saveable obstack so we can ensure it won't |
3340 | be freed if we are called from combine or some other phase that discards | |
3341 | memory allocated from function_obstack (current_obstack). */ | |
3342 | obstack_grow (saveable_obstack, &ptr, sizeof ptr); | |
3343 | obstack_grow (saveable_obstack, &label, sizeof label); | |
79e68feb RS |
3344 | |
3345 | /* Record constant contents. */ | |
75974726 | 3346 | obstack_grow (saveable_obstack, &value, sizeof value); |
79e68feb | 3347 | |
75974726 | 3348 | return (struct constant_descriptor *) obstack_finish (saveable_obstack); |
79e68feb RS |
3349 | } |
3350 | \f | |
3351 | /* Given a constant rtx X, make (or find) a memory constant for its value | |
3352 | and return a MEM rtx to refer to it in memory. */ | |
3353 | ||
3354 | rtx | |
3355 | force_const_mem (mode, x) | |
3356 | enum machine_mode mode; | |
3357 | rtx x; | |
3358 | { | |
3359 | register int hash; | |
3360 | register struct constant_descriptor *desc; | |
3361 | char label[256]; | |
3362 | char *found = 0; | |
3363 | rtx def; | |
3364 | ||
3365 | /* If we want this CONST_DOUBLE in the same mode as it is in memory | |
3366 | (this will always be true for floating CONST_DOUBLEs that have been | |
3367 | placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs), | |
3368 | use the previous copy. Otherwise, make a new one. Note that in | |
3369 | the unlikely event that this same CONST_DOUBLE is used in two different | |
3370 | modes in an alternating fashion, we will allocate a lot of different | |
3371 | memory locations, but this should be extremely rare. */ | |
3372 | ||
57632c51 RS |
3373 | /* Don't use CONST_DOUBLE_MEM in a nested function. |
3374 | Nested functions have their own constant pools, | |
3375 | so they can't share the same values in CONST_DOUBLE_MEM | |
3376 | with the containing function. */ | |
3377 | if (outer_function_chain == 0) | |
3378 | if (GET_CODE (x) == CONST_DOUBLE | |
3379 | && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM | |
3380 | && GET_MODE (CONST_DOUBLE_MEM (x)) == mode) | |
3381 | return CONST_DOUBLE_MEM (x); | |
79e68feb RS |
3382 | |
3383 | /* Compute hash code of X. Search the descriptors for that hash code | |
3384 | to see if any of them describes X. If yes, the descriptor records | |
3385 | the label number already assigned. */ | |
3386 | ||
3387 | hash = const_hash_rtx (mode, x); | |
3388 | ||
3389 | for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next) | |
3390 | if (compare_constant_rtx (mode, x, desc)) | |
3391 | { | |
3392 | found = desc->label; | |
3393 | break; | |
3394 | } | |
3395 | ||
3396 | if (found == 0) | |
3397 | { | |
3398 | register struct pool_constant *pool; | |
3399 | register struct pool_sym *sym; | |
3400 | int align; | |
3401 | ||
3402 | /* No constant equal to X is known to have been output. | |
3403 | Make a constant descriptor to enter X in the hash table. | |
3404 | Assign the label number and record it in the descriptor for | |
3405 | future calls to this function to find. */ | |
3406 | ||
3407 | desc = record_constant_rtx (mode, x); | |
3408 | desc->next = const_rtx_hash_table[hash]; | |
3409 | const_rtx_hash_table[hash] = desc; | |
3410 | ||
3411 | /* Align the location counter as required by EXP's data type. */ | |
3412 | align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode); | |
3413 | if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
3414 | align = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
3415 | ||
3416 | pool_offset += align - 1; | |
3417 | pool_offset &= ~ (align - 1); | |
3418 | ||
75974726 | 3419 | /* If RTL is not being placed into the saveable obstack, make a |
c0560887 ILT |
3420 | copy of X that is in the saveable obstack in case we are |
3421 | being called from combine or some other phase that discards | |
3422 | memory it allocates. We used to only do this if it is a | |
3423 | CONST; however, reload can allocate a CONST_INT when | |
3424 | eliminating registers. */ | |
75974726 | 3425 | if (rtl_obstack != saveable_obstack |
c0560887 | 3426 | && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT)) |
75974726 RK |
3427 | { |
3428 | push_obstacks_nochange (); | |
3429 | rtl_in_saveable_obstack (); | |
3430 | ||
c0560887 | 3431 | if (GET_CODE (x) == CONST) |
38a448ca RH |
3432 | x = gen_rtx_CONST (GET_MODE (x), |
3433 | gen_rtx_PLUS (GET_MODE (x), | |
3434 | XEXP (XEXP (x, 0), 0), | |
3435 | XEXP (XEXP (x, 0), 1))); | |
c0560887 ILT |
3436 | else |
3437 | x = GEN_INT (INTVAL (x)); | |
3438 | ||
75974726 RK |
3439 | pop_obstacks (); |
3440 | } | |
3441 | ||
79e68feb RS |
3442 | /* Allocate a pool constant descriptor, fill it in, and chain it in. */ |
3443 | ||
75974726 | 3444 | pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant)); |
79e68feb RS |
3445 | pool->desc = desc; |
3446 | pool->constant = x; | |
3447 | pool->mode = mode; | |
3448 | pool->labelno = const_labelno; | |
3449 | pool->align = align; | |
3450 | pool->offset = pool_offset; | |
d2ce9169 | 3451 | pool->mark = 1; |
79e68feb RS |
3452 | pool->next = 0; |
3453 | ||
3454 | if (last_pool == 0) | |
3455 | first_pool = pool; | |
3456 | else | |
3457 | last_pool->next = pool; | |
3458 | ||
3459 | last_pool = pool; | |
3460 | pool_offset += GET_MODE_SIZE (mode); | |
3461 | ||
3462 | /* Create a string containing the label name, in LABEL. */ | |
3463 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
3464 | ||
3465 | ++const_labelno; | |
3466 | ||
3467 | desc->label = found | |
3468 | = (char *) obstack_copy0 (saveable_obstack, label, strlen (label)); | |
3469 | ||
3470 | /* Add label to symbol hash table. */ | |
3471 | hash = SYMHASH (found); | |
75974726 | 3472 | sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym)); |
79e68feb RS |
3473 | sym->label = found; |
3474 | sym->pool = pool; | |
3475 | sym->next = const_rtx_sym_hash_table[hash]; | |
3476 | const_rtx_sym_hash_table[hash] = sym; | |
3477 | } | |
3478 | ||
3479 | /* We have a symbol name; construct the SYMBOL_REF and the MEM. */ | |
3480 | ||
38a448ca | 3481 | def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found)); |
79e68feb RS |
3482 | |
3483 | RTX_UNCHANGING_P (def) = 1; | |
3484 | /* Mark the symbol_ref as belonging to this constants pool. */ | |
3485 | CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1; | |
3486 | current_function_uses_const_pool = 1; | |
3487 | ||
57632c51 RS |
3488 | if (outer_function_chain == 0) |
3489 | if (GET_CODE (x) == CONST_DOUBLE) | |
3490 | { | |
3491 | if (CONST_DOUBLE_MEM (x) == cc0_rtx) | |
3492 | { | |
3493 | CONST_DOUBLE_CHAIN (x) = const_double_chain; | |
3494 | const_double_chain = x; | |
3495 | } | |
3496 | CONST_DOUBLE_MEM (x) = def; | |
3497 | } | |
79e68feb RS |
3498 | |
3499 | return def; | |
3500 | } | |
3501 | \f | |
3502 | /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to | |
3503 | the corresponding pool_constant structure. */ | |
3504 | ||
3505 | static struct pool_constant * | |
3506 | find_pool_constant (addr) | |
3507 | rtx addr; | |
3508 | { | |
3509 | struct pool_sym *sym; | |
3510 | char *label = XSTR (addr, 0); | |
3511 | ||
3512 | for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next) | |
3513 | if (sym->label == label) | |
3514 | return sym->pool; | |
3515 | ||
3516 | abort (); | |
3517 | } | |
3518 | ||
3519 | /* Given a constant pool SYMBOL_REF, return the corresponding constant. */ | |
3520 | ||
3521 | rtx | |
3522 | get_pool_constant (addr) | |
3523 | rtx addr; | |
3524 | { | |
3525 | return (find_pool_constant (addr))->constant; | |
3526 | } | |
3527 | ||
3528 | /* Similar, return the mode. */ | |
3529 | ||
3530 | enum machine_mode | |
3531 | get_pool_mode (addr) | |
3532 | rtx addr; | |
3533 | { | |
3534 | return (find_pool_constant (addr))->mode; | |
3535 | } | |
3536 | ||
3537 | /* Similar, return the offset in the constant pool. */ | |
3538 | ||
3539 | int | |
3540 | get_pool_offset (addr) | |
3541 | rtx addr; | |
3542 | { | |
3543 | return (find_pool_constant (addr))->offset; | |
3544 | } | |
3545 | ||
3546 | /* Return the size of the constant pool. */ | |
3547 | ||
3548 | int | |
3549 | get_pool_size () | |
3550 | { | |
3551 | return pool_offset; | |
3552 | } | |
3553 | \f | |
3554 | /* Write all the constants in the constant pool. */ | |
3555 | ||
3556 | void | |
3557 | output_constant_pool (fnname, fndecl) | |
3558 | char *fnname; | |
3559 | tree fndecl; | |
3560 | { | |
3561 | struct pool_constant *pool; | |
3562 | rtx x; | |
3563 | union real_extract u; | |
3564 | ||
91674c37 ILT |
3565 | /* It is possible for gcc to call force_const_mem and then to later |
3566 | discard the instructions which refer to the constant. In such a | |
3567 | case we do not need to output the constant. */ | |
d2ce9169 | 3568 | if (optimize >= 0 && flag_expensive_optimizations) |
91674c37 ILT |
3569 | mark_constant_pool (); |
3570 | ||
79e68feb RS |
3571 | #ifdef ASM_OUTPUT_POOL_PROLOGUE |
3572 | ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset); | |
3573 | #endif | |
3574 | ||
3575 | for (pool = first_pool; pool; pool = pool->next) | |
3576 | { | |
3577 | x = pool->constant; | |
3578 | ||
d2ce9169 | 3579 | if (! pool->mark) |
91674c37 ILT |
3580 | continue; |
3581 | ||
79e68feb RS |
3582 | /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF) |
3583 | whose CODE_LABEL has been deleted. This can occur if a jump table | |
3584 | is eliminated by optimization. If so, write a constant of zero | |
7b2b3f1f RK |
3585 | instead. Note that this can also happen by turning the |
3586 | CODE_LABEL into a NOTE. */ | |
3587 | if (((GET_CODE (x) == LABEL_REF | |
3588 | && (INSN_DELETED_P (XEXP (x, 0)) | |
3589 | || GET_CODE (XEXP (x, 0)) == NOTE))) | |
79e68feb RS |
3590 | || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS |
3591 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF | |
7b2b3f1f RK |
3592 | && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0)) |
3593 | || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE))) | |
79e68feb RS |
3594 | x = const0_rtx; |
3595 | ||
3596 | /* First switch to correct section. */ | |
3597 | #ifdef SELECT_RTX_SECTION | |
3598 | SELECT_RTX_SECTION (pool->mode, x); | |
3599 | #else | |
3600 | readonly_data_section (); | |
3601 | #endif | |
3602 | ||
3603 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY | |
3604 | ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode, | |
3605 | pool->align, pool->labelno, done); | |
3606 | #endif | |
3607 | ||
3608 | if (pool->align > 1) | |
3609 | ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align)); | |
3610 | ||
3611 | /* Output the label. */ | |
3612 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno); | |
3613 | ||
3614 | /* Output the value of the constant itself. */ | |
3615 | switch (GET_MODE_CLASS (pool->mode)) | |
3616 | { | |
3617 | case MODE_FLOAT: | |
3618 | if (GET_CODE (x) != CONST_DOUBLE) | |
3619 | abort (); | |
3620 | ||
4c9a05bc | 3621 | bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u); |
79e68feb RS |
3622 | assemble_real (u.d, pool->mode); |
3623 | break; | |
3624 | ||
3625 | case MODE_INT: | |
ab8ab9d0 | 3626 | case MODE_PARTIAL_INT: |
79e68feb RS |
3627 | assemble_integer (x, GET_MODE_SIZE (pool->mode), 1); |
3628 | break; | |
3629 | ||
3630 | default: | |
3631 | abort (); | |
3632 | } | |
3633 | ||
29a82058 JL |
3634 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY |
3635 | done: ; | |
3636 | #endif | |
3637 | ||
7f83c0e7 JL |
3638 | } |
3639 | ||
5c8c0abd ILT |
3640 | #ifdef ASM_OUTPUT_POOL_EPILOGUE |
3641 | ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset); | |
3642 | #endif | |
3643 | ||
79e68feb RS |
3644 | /* Done with this pool. */ |
3645 | first_pool = last_pool = 0; | |
3646 | } | |
91674c37 ILT |
3647 | |
3648 | /* Look through the instructions for this function, and mark all the | |
3649 | entries in the constant pool which are actually being used. */ | |
3650 | ||
3651 | static void | |
3652 | mark_constant_pool () | |
3653 | { | |
3654 | register rtx insn; | |
d2ce9169 | 3655 | struct pool_constant *pool; |
91674c37 ILT |
3656 | |
3657 | if (first_pool == 0) | |
3658 | return; | |
3659 | ||
d2ce9169 RK |
3660 | for (pool = first_pool; pool; pool = pool->next) |
3661 | pool->mark = 0; | |
3662 | ||
91674c37 ILT |
3663 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
3664 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') | |
3665 | mark_constants (PATTERN (insn)); | |
3666 | ||
3667 | for (insn = current_function_epilogue_delay_list; | |
3668 | insn; | |
3669 | insn = XEXP (insn, 1)) | |
3670 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') | |
3671 | mark_constants (PATTERN (insn)); | |
3672 | } | |
3673 | ||
3674 | static void | |
3675 | mark_constants (x) | |
3676 | register rtx x; | |
3677 | { | |
3678 | register int i; | |
3679 | register char *format_ptr; | |
3680 | ||
3681 | if (x == 0) | |
3682 | return; | |
3683 | ||
3684 | if (GET_CODE (x) == SYMBOL_REF) | |
3685 | { | |
3686 | if (CONSTANT_POOL_ADDRESS_P (x)) | |
3687 | find_pool_constant (x)->mark = 1; | |
3688 | return; | |
3689 | } | |
eb7b11fd JW |
3690 | /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be |
3691 | a MEM, but does not constitute a use of that MEM. This is particularly | |
3692 | important inside a nested function, because CONST_DOUBLE_MEM may be | |
3693 | a reference to a MEM in the parent's constant pool. See the comment | |
3694 | in force_const_mem. */ | |
3695 | else if (GET_CODE (x) == CONST_DOUBLE) | |
3696 | return; | |
91674c37 ILT |
3697 | |
3698 | /* Insns may appear inside a SEQUENCE. Only check the patterns of | |
3699 | insns, not any notes that may be attached. We don't want to mark | |
3700 | a constant just because it happens to appear in a REG_EQUIV note. */ | |
3701 | if (GET_RTX_CLASS (GET_CODE (x)) == 'i') | |
3702 | { | |
3703 | mark_constants (PATTERN (x)); | |
3704 | return; | |
3705 | } | |
3706 | ||
3707 | format_ptr = GET_RTX_FORMAT (GET_CODE (x)); | |
3708 | ||
3709 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++) | |
3710 | { | |
3711 | switch (*format_ptr++) | |
3712 | { | |
3713 | case 'e': | |
3714 | mark_constants (XEXP (x, i)); | |
3715 | break; | |
3716 | ||
3717 | case 'E': | |
3718 | if (XVEC (x, i) != 0) | |
3719 | { | |
3720 | register int j; | |
3721 | ||
3722 | for (j = 0; j < XVECLEN (x, i); j++) | |
3723 | mark_constants (XVECEXP (x, i, j)); | |
3724 | } | |
3725 | break; | |
3726 | ||
3727 | case 'S': | |
3728 | case 's': | |
3729 | case '0': | |
3730 | case 'i': | |
3731 | case 'w': | |
3732 | case 'n': | |
3733 | case 'u': | |
3734 | break; | |
3735 | ||
3736 | default: | |
3737 | abort (); | |
3738 | } | |
3739 | } | |
3740 | } | |
79e68feb RS |
3741 | \f |
3742 | /* Find all the constants whose addresses are referenced inside of EXP, | |
3743 | and make sure assembler code with a label has been output for each one. | |
3744 | Indicate whether an ADDR_EXPR has been encountered. */ | |
3745 | ||
5a13eaa4 | 3746 | static int |
79e68feb RS |
3747 | output_addressed_constants (exp) |
3748 | tree exp; | |
3749 | { | |
3750 | int reloc = 0; | |
3751 | ||
3752 | switch (TREE_CODE (exp)) | |
3753 | { | |
3754 | case ADDR_EXPR: | |
3755 | { | |
3756 | register tree constant = TREE_OPERAND (exp, 0); | |
3757 | ||
3758 | while (TREE_CODE (constant) == COMPONENT_REF) | |
3759 | { | |
3760 | constant = TREE_OPERAND (constant, 0); | |
3761 | } | |
3762 | ||
3763 | if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c' | |
3764 | || TREE_CODE (constant) == CONSTRUCTOR) | |
3765 | /* No need to do anything here | |
3766 | for addresses of variables or functions. */ | |
3767 | output_constant_def (constant); | |
3768 | } | |
3769 | reloc = 1; | |
3770 | break; | |
3771 | ||
3772 | case PLUS_EXPR: | |
3773 | case MINUS_EXPR: | |
3774 | reloc = output_addressed_constants (TREE_OPERAND (exp, 0)); | |
3775 | reloc |= output_addressed_constants (TREE_OPERAND (exp, 1)); | |
3776 | break; | |
3777 | ||
3778 | case NOP_EXPR: | |
3779 | case CONVERT_EXPR: | |
37a52112 | 3780 | case NON_LVALUE_EXPR: |
79e68feb RS |
3781 | reloc = output_addressed_constants (TREE_OPERAND (exp, 0)); |
3782 | break; | |
3783 | ||
3784 | case CONSTRUCTOR: | |
3785 | { | |
3786 | register tree link; | |
3787 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
3788 | if (TREE_VALUE (link) != 0) | |
3789 | reloc |= output_addressed_constants (TREE_VALUE (link)); | |
3790 | } | |
3791 | break; | |
3792 | ||
e9a25f70 | 3793 | default: |
79e68feb RS |
3794 | break; |
3795 | } | |
3796 | return reloc; | |
3797 | } | |
3798 | \f | |
3799 | /* Output assembler code for constant EXP to FILE, with no label. | |
3800 | This includes the pseudo-op such as ".int" or ".byte", and a newline. | |
3801 | Assumes output_addressed_constants has been done on EXP already. | |
3802 | ||
3803 | Generate exactly SIZE bytes of assembler data, padding at the end | |
3804 | with zeros if necessary. SIZE must always be specified. | |
3805 | ||
3806 | SIZE is important for structure constructors, | |
3807 | since trailing members may have been omitted from the constructor. | |
3808 | It is also important for initialization of arrays from string constants | |
3809 | since the full length of the string constant might not be wanted. | |
3810 | It is also needed for initialization of unions, where the initializer's | |
3811 | type is just one member, and that may not be as long as the union. | |
3812 | ||
3813 | There a case in which we would fail to output exactly SIZE bytes: | |
3814 | for a structure constructor that wants to produce more than SIZE bytes. | |
3815 | But such constructors will never be generated for any possible input. */ | |
3816 | ||
3817 | void | |
3818 | output_constant (exp, size) | |
3819 | register tree exp; | |
3820 | register int size; | |
3821 | { | |
3822 | register enum tree_code code = TREE_CODE (TREE_TYPE (exp)); | |
79e68feb RS |
3823 | |
3824 | if (size == 0) | |
3825 | return; | |
3826 | ||
be1ad04c | 3827 | /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue. |
b81cdf54 | 3828 | That way we get the constant (we hope) inside it. Also, strip off any |
4e1bf5f5 | 3829 | NOP_EXPR that converts between two record, union, array, or set types. */ |
be1ad04c RK |
3830 | while ((TREE_CODE (exp) == NOP_EXPR |
3831 | && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)) | |
4e1bf5f5 | 3832 | || AGGREGATE_TYPE_P (TREE_TYPE (exp)))) |
be1ad04c RK |
3833 | || TREE_CODE (exp) == NON_LVALUE_EXPR) |
3834 | exp = TREE_OPERAND (exp, 0); | |
3835 | ||
fff9e713 MT |
3836 | /* Allow a constructor with no elements for any data type. |
3837 | This means to fill the space with zeros. */ | |
77fa0940 | 3838 | if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0) |
fff9e713 | 3839 | { |
b93a436e | 3840 | assemble_zeros (size); |
fff9e713 MT |
3841 | return; |
3842 | } | |
3843 | ||
79e68feb RS |
3844 | switch (code) |
3845 | { | |
644ea577 RS |
3846 | case CHAR_TYPE: |
3847 | case BOOLEAN_TYPE: | |
79e68feb RS |
3848 | case INTEGER_TYPE: |
3849 | case ENUMERAL_TYPE: | |
3850 | case POINTER_TYPE: | |
3851 | case REFERENCE_TYPE: | |
3852 | /* ??? What about (int)((float)(int)&foo + 4) */ | |
3853 | while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR | |
3854 | || TREE_CODE (exp) == NON_LVALUE_EXPR) | |
3855 | exp = TREE_OPERAND (exp, 0); | |
3856 | ||
37366632 | 3857 | if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode, |
79e68feb RS |
3858 | EXPAND_INITIALIZER), |
3859 | size, 0)) | |
3860 | error ("initializer for integer value is too complicated"); | |
3861 | size = 0; | |
3862 | break; | |
3863 | ||
3864 | case REAL_TYPE: | |
3865 | if (TREE_CODE (exp) != REAL_CST) | |
3866 | error ("initializer for floating value is not a floating constant"); | |
3867 | ||
3868 | assemble_real (TREE_REAL_CST (exp), | |
3869 | mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0)); | |
3870 | size = 0; | |
3871 | break; | |
3872 | ||
3873 | case COMPLEX_TYPE: | |
3874 | output_constant (TREE_REALPART (exp), size / 2); | |
3875 | output_constant (TREE_IMAGPART (exp), size / 2); | |
3876 | size -= (size / 2) * 2; | |
3877 | break; | |
3878 | ||
3879 | case ARRAY_TYPE: | |
3880 | if (TREE_CODE (exp) == CONSTRUCTOR) | |
3881 | { | |
3882 | output_constructor (exp, size); | |
3883 | return; | |
3884 | } | |
3885 | else if (TREE_CODE (exp) == STRING_CST) | |
3886 | { | |
3887 | int excess = 0; | |
3888 | ||
3889 | if (size > TREE_STRING_LENGTH (exp)) | |
3890 | { | |
3891 | excess = size - TREE_STRING_LENGTH (exp); | |
3892 | size = TREE_STRING_LENGTH (exp); | |
3893 | } | |
3894 | ||
3895 | assemble_string (TREE_STRING_POINTER (exp), size); | |
3896 | size = excess; | |
3897 | } | |
3898 | else | |
3899 | abort (); | |
3900 | break; | |
3901 | ||
3902 | case RECORD_TYPE: | |
3903 | case UNION_TYPE: | |
3904 | if (TREE_CODE (exp) == CONSTRUCTOR) | |
3905 | output_constructor (exp, size); | |
3906 | else | |
3907 | abort (); | |
3908 | return; | |
474bda6c PB |
3909 | |
3910 | case SET_TYPE: | |
3911 | if (TREE_CODE (exp) == INTEGER_CST) | |
3912 | assemble_integer (expand_expr (exp, NULL_RTX, | |
3913 | VOIDmode, EXPAND_INITIALIZER), | |
af13b0fb | 3914 | size, 1); |
474bda6c PB |
3915 | else if (TREE_CODE (exp) == CONSTRUCTOR) |
3916 | { | |
af13b0fb DE |
3917 | unsigned char *buffer = (unsigned char *) alloca (size); |
3918 | if (get_set_constructor_bytes (exp, buffer, size)) | |
474bda6c | 3919 | abort (); |
b029f99a | 3920 | assemble_string ((char *) buffer, size); |
474bda6c PB |
3921 | } |
3922 | else | |
3923 | error ("unknown set constructor type"); | |
3924 | return; | |
e9a25f70 JL |
3925 | |
3926 | default: | |
3927 | break; /* ??? */ | |
79e68feb RS |
3928 | } |
3929 | ||
3930 | if (size > 0) | |
3931 | assemble_zeros (size); | |
3932 | } | |
ca695ac9 | 3933 | |
79e68feb RS |
3934 | \f |
3935 | /* Subroutine of output_constant, used for CONSTRUCTORs | |
3936 | (aggregate constants). | |
3937 | Generate at least SIZE bytes, padding if necessary. */ | |
3938 | ||
5a13eaa4 | 3939 | static void |
79e68feb RS |
3940 | output_constructor (exp, size) |
3941 | tree exp; | |
3942 | int size; | |
3943 | { | |
3944 | register tree link, field = 0; | |
13b457e7 | 3945 | HOST_WIDE_INT min_index = 0; |
79e68feb RS |
3946 | /* Number of bytes output or skipped so far. |
3947 | In other words, current position within the constructor. */ | |
3948 | int total_bytes = 0; | |
3949 | /* Non-zero means BYTE contains part of a byte, to be output. */ | |
3950 | int byte_buffer_in_use = 0; | |
3951 | register int byte; | |
3952 | ||
37366632 | 3953 | if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT) |
79e68feb RS |
3954 | abort (); |
3955 | ||
3956 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) | |
3957 | field = TYPE_FIELDS (TREE_TYPE (exp)); | |
3958 | ||
d12516f1 RS |
3959 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE |
3960 | && TYPE_DOMAIN (TREE_TYPE (exp)) != 0) | |
13b457e7 RK |
3961 | min_index |
3962 | = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp)))); | |
3963 | ||
79e68feb RS |
3964 | /* As LINK goes through the elements of the constant, |
3965 | FIELD goes through the structure fields, if the constant is a structure. | |
3966 | if the constant is a union, then we override this, | |
3967 | by getting the field from the TREE_LIST element. | |
3968 | But the constant could also be an array. Then FIELD is zero. */ | |
3969 | for (link = CONSTRUCTOR_ELTS (exp); | |
3970 | link; | |
3971 | link = TREE_CHAIN (link), | |
3972 | field = field ? TREE_CHAIN (field) : 0) | |
3973 | { | |
3974 | tree val = TREE_VALUE (link); | |
3181cbfd RS |
3975 | tree index = 0; |
3976 | ||
79e68feb | 3977 | /* the element in a union constructor specifies the proper field. */ |
3181cbfd RS |
3978 | |
3979 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE | |
3980 | || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE) | |
1108dc3d KKT |
3981 | { |
3982 | /* if available, use the type given by link */ | |
3983 | if (TREE_PURPOSE (link) != 0) | |
3984 | field = TREE_PURPOSE (link); | |
3985 | } | |
79e68feb | 3986 | |
3181cbfd RS |
3987 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) |
3988 | index = TREE_PURPOSE (link); | |
3989 | ||
79e68feb | 3990 | /* Eliminate the marker that makes a cast not be an lvalue. */ |
d964285c CH |
3991 | if (val != 0) |
3992 | STRIP_NOPS (val); | |
79e68feb | 3993 | |
8311a11f PB |
3994 | if (index && TREE_CODE (index) == RANGE_EXPR) |
3995 | { | |
3996 | register int fieldsize | |
3997 | = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp))); | |
3998 | HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0)); | |
3999 | HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1)); | |
4000 | HOST_WIDE_INT index; | |
4001 | for (index = lo_index; index <= hi_index; index++) | |
4002 | { | |
4003 | /* Output the element's initial value. */ | |
4004 | if (val == 0) | |
4005 | assemble_zeros (fieldsize); | |
4006 | else | |
4007 | output_constant (val, fieldsize); | |
4008 | ||
4009 | /* Count its size. */ | |
4010 | total_bytes += fieldsize; | |
4011 | } | |
4012 | } | |
4013 | else if (field == 0 || !DECL_BIT_FIELD (field)) | |
79e68feb | 4014 | { |
3181cbfd RS |
4015 | /* An element that is not a bit-field. */ |
4016 | ||
79e68feb RS |
4017 | register int fieldsize; |
4018 | /* Since this structure is static, | |
4019 | we know the positions are constant. */ | |
4020 | int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)) | |
4021 | / BITS_PER_UNIT) | |
4022 | : 0); | |
3181cbfd RS |
4023 | if (index != 0) |
4024 | bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val))) | |
4025 | / BITS_PER_UNIT | |
13b457e7 | 4026 | * (TREE_INT_CST_LOW (index) - min_index)); |
79e68feb | 4027 | |
3181cbfd | 4028 | /* Output any buffered-up bit-fields preceding this element. */ |
79e68feb RS |
4029 | if (byte_buffer_in_use) |
4030 | { | |
4031 | ASM_OUTPUT_BYTE (asm_out_file, byte); | |
4032 | total_bytes++; | |
4033 | byte_buffer_in_use = 0; | |
4034 | } | |
4035 | ||
4036 | /* Advance to offset of this element. | |
4037 | Note no alignment needed in an array, since that is guaranteed | |
4038 | if each element has the proper size. */ | |
3181cbfd | 4039 | if ((field != 0 || index != 0) && bitpos != total_bytes) |
79e68feb | 4040 | { |
b93a436e | 4041 | assemble_zeros (bitpos - total_bytes); |
79e68feb RS |
4042 | total_bytes = bitpos; |
4043 | } | |
4044 | ||
4045 | /* Determine size this element should occupy. */ | |
4046 | if (field) | |
4047 | { | |
4048 | if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST) | |
4049 | abort (); | |
4050 | if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000) | |
4051 | { | |
4052 | /* This avoids overflow trouble. */ | |
4053 | tree size_tree = size_binop (CEIL_DIV_EXPR, | |
4054 | DECL_SIZE (field), | |
4055 | size_int (BITS_PER_UNIT)); | |
4056 | fieldsize = TREE_INT_CST_LOW (size_tree); | |
4057 | } | |
4058 | else | |
4059 | { | |
4060 | fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field)); | |
4061 | fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT; | |
4062 | } | |
4063 | } | |
4064 | else | |
4065 | fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp))); | |
4066 | ||
4067 | /* Output the element's initial value. */ | |
4068 | if (val == 0) | |
4069 | assemble_zeros (fieldsize); | |
4070 | else | |
4071 | output_constant (val, fieldsize); | |
4072 | ||
4073 | /* Count its size. */ | |
4074 | total_bytes += fieldsize; | |
4075 | } | |
4076 | else if (val != 0 && TREE_CODE (val) != INTEGER_CST) | |
4077 | error ("invalid initial value for member `%s'", | |
4078 | IDENTIFIER_POINTER (DECL_NAME (field))); | |
4079 | else | |
4080 | { | |
4081 | /* Element that is a bit-field. */ | |
4082 | ||
4083 | int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)); | |
4084 | int end_offset | |
4085 | = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field))); | |
4086 | ||
4087 | if (val == 0) | |
4088 | val = integer_zero_node; | |
4089 | ||
4090 | /* If this field does not start in this (or, next) byte, | |
4091 | skip some bytes. */ | |
4092 | if (next_offset / BITS_PER_UNIT != total_bytes) | |
4093 | { | |
4094 | /* Output remnant of any bit field in previous bytes. */ | |
4095 | if (byte_buffer_in_use) | |
4096 | { | |
4097 | ASM_OUTPUT_BYTE (asm_out_file, byte); | |
4098 | total_bytes++; | |
4099 | byte_buffer_in_use = 0; | |
4100 | } | |
4101 | ||
4102 | /* If still not at proper byte, advance to there. */ | |
4103 | if (next_offset / BITS_PER_UNIT != total_bytes) | |
4104 | { | |
4105 | assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes); | |
4106 | total_bytes = next_offset / BITS_PER_UNIT; | |
4107 | } | |
4108 | } | |
4109 | ||
4110 | if (! byte_buffer_in_use) | |
4111 | byte = 0; | |
4112 | ||
4113 | /* We must split the element into pieces that fall within | |
4114 | separate bytes, and combine each byte with previous or | |
4115 | following bit-fields. */ | |
4116 | ||
b4ac57ab | 4117 | /* next_offset is the offset n fbits from the beginning of |
79e68feb RS |
4118 | the structure to the next bit of this element to be processed. |
4119 | end_offset is the offset of the first bit past the end of | |
4120 | this element. */ | |
4121 | while (next_offset < end_offset) | |
4122 | { | |
4123 | int this_time; | |
e7105755 JW |
4124 | int shift; |
4125 | HOST_WIDE_INT value; | |
79e68feb RS |
4126 | int next_byte = next_offset / BITS_PER_UNIT; |
4127 | int next_bit = next_offset % BITS_PER_UNIT; | |
4128 | ||
4129 | /* Advance from byte to byte | |
4130 | within this element when necessary. */ | |
4131 | while (next_byte != total_bytes) | |
4132 | { | |
4133 | ASM_OUTPUT_BYTE (asm_out_file, byte); | |
4134 | total_bytes++; | |
4135 | byte = 0; | |
4136 | } | |
4137 | ||
4138 | /* Number of bits we can process at once | |
4139 | (all part of the same byte). */ | |
4140 | this_time = MIN (end_offset - next_offset, | |
4141 | BITS_PER_UNIT - next_bit); | |
f76b9db2 | 4142 | if (BYTES_BIG_ENDIAN) |
79e68feb | 4143 | { |
f76b9db2 ILT |
4144 | /* On big-endian machine, take the most significant bits |
4145 | first (of the bits that are significant) | |
4146 | and put them into bytes from the most significant end. */ | |
4147 | shift = end_offset - next_offset - this_time; | |
4148 | /* Don't try to take a bunch of bits that cross | |
4149 | the word boundary in the INTEGER_CST. */ | |
4150 | if (shift < HOST_BITS_PER_WIDE_INT | |
4151 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
4152 | { | |
4153 | this_time -= (HOST_BITS_PER_WIDE_INT - shift); | |
4154 | shift = HOST_BITS_PER_WIDE_INT; | |
4155 | } | |
4156 | ||
4157 | /* Now get the bits from the appropriate constant word. */ | |
4158 | if (shift < HOST_BITS_PER_WIDE_INT) | |
4159 | { | |
4160 | value = TREE_INT_CST_LOW (val); | |
4161 | } | |
4162 | else if (shift < 2 * HOST_BITS_PER_WIDE_INT) | |
4163 | { | |
4164 | value = TREE_INT_CST_HIGH (val); | |
4165 | shift -= HOST_BITS_PER_WIDE_INT; | |
4166 | } | |
4167 | else | |
4168 | abort (); | |
4169 | byte |= (((value >> shift) | |
4170 | & (((HOST_WIDE_INT) 1 << this_time) - 1)) | |
4171 | << (BITS_PER_UNIT - this_time - next_bit)); | |
79e68feb RS |
4172 | } |
4173 | else | |
79e68feb | 4174 | { |
f76b9db2 ILT |
4175 | /* On little-endian machines, |
4176 | take first the least significant bits of the value | |
4177 | and pack them starting at the least significant | |
4178 | bits of the bytes. */ | |
4179 | shift = (next_offset | |
4180 | - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))); | |
4181 | /* Don't try to take a bunch of bits that cross | |
4182 | the word boundary in the INTEGER_CST. */ | |
4183 | if (shift < HOST_BITS_PER_WIDE_INT | |
4184 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
4185 | { | |
4186 | this_time -= (HOST_BITS_PER_WIDE_INT - shift); | |
4187 | shift = HOST_BITS_PER_WIDE_INT; | |
4188 | } | |
4189 | ||
4190 | /* Now get the bits from the appropriate constant word. */ | |
e9a25f70 | 4191 | if (shift < HOST_BITS_PER_WIDE_INT) |
f76b9db2 ILT |
4192 | value = TREE_INT_CST_LOW (val); |
4193 | else if (shift < 2 * HOST_BITS_PER_WIDE_INT) | |
4194 | { | |
4195 | value = TREE_INT_CST_HIGH (val); | |
4196 | shift -= HOST_BITS_PER_WIDE_INT; | |
4197 | } | |
4198 | else | |
4199 | abort (); | |
4200 | byte |= (((value >> shift) | |
4201 | & (((HOST_WIDE_INT) 1 << this_time) - 1)) | |
4202 | << next_bit); | |
79e68feb | 4203 | } |
79e68feb RS |
4204 | next_offset += this_time; |
4205 | byte_buffer_in_use = 1; | |
4206 | } | |
4207 | } | |
4208 | } | |
4209 | if (byte_buffer_in_use) | |
4210 | { | |
4211 | ASM_OUTPUT_BYTE (asm_out_file, byte); | |
4212 | total_bytes++; | |
4213 | } | |
4214 | if (total_bytes < size) | |
4215 | assemble_zeros (size - total_bytes); | |
4216 | } | |
ca695ac9 | 4217 | |
ca695ac9 | 4218 | /* Output asm to handle ``#pragma weak'' */ |
0f41302f | 4219 | |
ca695ac9 | 4220 | void |
3d6f7931 | 4221 | handle_pragma_weak (what, name, value) |
ca695ac9 | 4222 | enum pragma_state what; |
ca695ac9 JB |
4223 | char *name, *value; |
4224 | { | |
7198acbe | 4225 | #ifdef HANDLE_PRAGMA_WEAK |
ca695ac9 JB |
4226 | if (what == ps_name || what == ps_value) |
4227 | { | |
eb0430f0 MM |
4228 | struct weak_syms *weak = |
4229 | (struct weak_syms *)permalloc (sizeof (struct weak_syms)); | |
4230 | weak->next = weak_decls; | |
4231 | weak->name = permalloc (strlen (name) + 1); | |
4232 | strcpy (weak->name, name); | |
4233 | ||
4234 | if (what != ps_value) | |
4235 | weak->value = NULL_PTR; | |
4236 | ||
4237 | else | |
4238 | { | |
4239 | weak->value = permalloc (strlen (value) + 1); | |
4240 | strcpy (weak->value, value); | |
4241 | } | |
4242 | ||
4243 | weak_decls = weak; | |
ca695ac9 JB |
4244 | } |
4245 | else if (! (what == ps_done || what == ps_start)) | |
4246 | warning ("malformed `#pragma weak'"); | |
7198acbe | 4247 | #endif /* HANDLE_PRAGMA_WEAK */ |
ca695ac9 | 4248 | } |
c02bd5d9 | 4249 | |
4b8af8d9 JM |
4250 | /* Declare DECL to be a weak symbol. */ |
4251 | ||
4252 | void | |
4253 | declare_weak (decl) | |
4254 | tree decl; | |
4255 | { | |
4256 | if (! TREE_PUBLIC (decl)) | |
4257 | error_with_decl (decl, "weak declaration of `%s' must be public"); | |
daefd78b JM |
4258 | else if (TREE_ASM_WRITTEN (decl)) |
4259 | error_with_decl (decl, "weak declaration of `%s' must precede definition"); | |
4260 | else if (SUPPORTS_WEAK) | |
4261 | DECL_WEAK (decl) = 1; | |
4b8af8d9 JM |
4262 | } |
4263 | ||
4264 | /* Emit any pending weak declarations. */ | |
4265 | ||
4266 | void | |
4267 | weak_finish () | |
4268 | { | |
4269 | #ifdef HANDLE_PRAGMA_WEAK | |
4270 | if (HANDLE_PRAGMA_WEAK) | |
4271 | { | |
eb0430f0 MM |
4272 | struct weak_syms *t; |
4273 | for (t = weak_decls; t; t = t->next) | |
4b8af8d9 | 4274 | { |
daefd78b | 4275 | ASM_WEAKEN_LABEL (asm_out_file, t->name); |
eb0430f0 MM |
4276 | if (t->value) |
4277 | ASM_OUTPUT_DEF (asm_out_file, t->name, t->value); | |
4b8af8d9 JM |
4278 | } |
4279 | } | |
4280 | #endif | |
4281 | } | |
4282 | ||
4283 | void | |
4284 | assemble_alias (decl, target) | |
4285 | tree decl, target; | |
4286 | { | |
4b8af8d9 JM |
4287 | char *name; |
4288 | ||
0f41302f | 4289 | make_decl_rtl (decl, (char *) 0, 1); |
4b8af8d9 JM |
4290 | name = XSTR (XEXP (DECL_RTL (decl), 0), 0); |
4291 | ||
4927276d | 4292 | #ifdef ASM_OUTPUT_DEF |
4b8af8d9 JM |
4293 | /* Make name accessible from other files, if appropriate. */ |
4294 | ||
4295 | if (TREE_PUBLIC (decl)) | |
4296 | { | |
daefd78b JM |
4297 | #ifdef ASM_WEAKEN_LABEL |
4298 | if (DECL_WEAK (decl)) | |
4299 | ASM_WEAKEN_LABEL (asm_out_file, name); | |
4300 | else | |
4301 | #endif | |
4b8af8d9 JM |
4302 | ASM_GLOBALIZE_LABEL (asm_out_file, name); |
4303 | } | |
4304 | ||
4305 | ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target)); | |
daefd78b | 4306 | TREE_ASM_WRITTEN (decl) = 1; |
4b8af8d9 | 4307 | #else |
4927276d JM |
4308 | #ifdef ASM_OUTPUT_WEAK_ALIAS |
4309 | if (! DECL_WEAK (decl)) | |
4310 | warning ("only weak aliases are supported in this configuration"); | |
4311 | ||
4312 | ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target)); | |
4313 | TREE_ASM_WRITTEN (decl) = 1; | |
4314 | #else | |
4315 | warning ("alias definitions not supported in this configuration; ignored"); | |
4316 | #endif | |
4b8af8d9 JM |
4317 | #endif |
4318 | } | |
f796d997 JM |
4319 | |
4320 | /* This determines whether or not we support link-once semantics. */ | |
4321 | #ifndef SUPPORTS_ONE_ONLY | |
4322 | #ifdef MAKE_DECL_ONE_ONLY | |
4323 | #define SUPPORTS_ONE_ONLY 1 | |
4324 | #else | |
4325 | #define SUPPORTS_ONE_ONLY 0 | |
4326 | #endif | |
4327 | #endif | |
4328 | ||
4329 | /* Returns 1 if the target configuration supports defining public symbols | |
4330 | so that one of them will be chosen at link time instead of generating a | |
4331 | multiply-defined symbol error, whether through the use of weak symbols or | |
4332 | a target-specific mechanism for having duplicates discarded. */ | |
4333 | ||
4334 | int | |
4335 | supports_one_only () | |
4336 | { | |
4337 | if (SUPPORTS_ONE_ONLY) | |
4338 | return 1; | |
4339 | return SUPPORTS_WEAK; | |
4340 | } | |
4341 | ||
4342 | /* Set up DECL as a public symbol that can be defined in multiple | |
4343 | translation units without generating a linker error. */ | |
4344 | ||
4345 | void | |
4346 | make_decl_one_only (decl) | |
4347 | tree decl; | |
4348 | { | |
4349 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL) | |
4350 | abort (); | |
4351 | ||
4352 | TREE_PUBLIC (decl) = 1; | |
4353 | ||
4354 | if (TREE_CODE (decl) == VAR_DECL | |
4355 | && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)) | |
4356 | DECL_COMMON (decl) = 1; | |
4357 | else if (SUPPORTS_ONE_ONLY) | |
4358 | { | |
4359 | #ifdef MAKE_DECL_ONE_ONLY | |
4360 | MAKE_DECL_ONE_ONLY (decl); | |
4361 | #endif | |
4362 | DECL_ONE_ONLY (decl) = 1; | |
4363 | } | |
4364 | else if (SUPPORTS_WEAK) | |
4365 | DECL_WEAK (decl) = 1; | |
4366 | else | |
4367 | abort (); | |
4368 | } |