]>
Commit | Line | Data |
---|---|---|
79e68feb | 1 | /* Output variables, constants and external declarations, for GNU compiler. |
06ceef4e | 2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, |
a8154559 | 3 | 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
79e68feb | 4 | |
1322177d | 5 | This file is part of GCC. |
79e68feb | 6 | |
1322177d LB |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 2, or (at your option) any later | |
10 | version. | |
79e68feb | 11 | |
1322177d LB |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
79e68feb RS |
16 | |
17 | You should have received a copy of the GNU General Public License | |
1322177d LB |
18 | along with GCC; see the file COPYING. If not, write to the Free |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
79e68feb RS |
21 | |
22 | ||
23 | /* This file handles generation of all the assembler code | |
24 | *except* the instructions of a function. | |
25 | This includes declarations of variables and their initial values. | |
26 | ||
27 | We also output the assembler code for constants stored in memory | |
28 | and are responsible for combining constants with the same value. */ | |
29 | ||
e9a25f70 | 30 | #include "config.h" |
670ee920 | 31 | #include "system.h" |
79e68feb RS |
32 | #include "rtl.h" |
33 | #include "tree.h" | |
34 | #include "flags.h" | |
57632c51 | 35 | #include "function.h" |
79e68feb RS |
36 | #include "expr.h" |
37 | #include "hard-reg-set.h" | |
38 | #include "regs.h" | |
fbd40359 | 39 | #include "output.h" |
24b09b50 | 40 | #include "real.h" |
10f0ad3d | 41 | #include "toplev.h" |
79e68feb | 42 | #include "obstack.h" |
bd7cf17e | 43 | #include "hashtab.h" |
3d6f7931 | 44 | #include "c-pragma.h" |
79c4e63f | 45 | #include "c-tree.h" |
87ff9c8e | 46 | #include "ggc.h" |
ac79cd5a | 47 | #include "langhooks.h" |
aa388f29 | 48 | #include "tm_p.h" |
653e276c | 49 | #include "debug.h" |
7c262518 | 50 | #include "target.h" |
79e68feb | 51 | |
440aabf8 NB |
52 | #ifdef XCOFF_DEBUGGING_INFO |
53 | #include "xcoffout.h" /* Needed for external data | |
54 | declarations for e.g. AIX 4.x. */ | |
55 | #endif | |
56 | ||
073b0524 RK |
57 | #ifndef TRAMPOLINE_ALIGNMENT |
58 | #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY | |
59 | #endif | |
60 | ||
79e68feb | 61 | #ifndef ASM_STABS_OP |
0a3e1f45 | 62 | #define ASM_STABS_OP "\t.stabs\t" |
79e68feb RS |
63 | #endif |
64 | ||
79e68feb | 65 | /* The (assembler) name of the first globally-visible object output. */ |
3b304f5b ZW |
66 | const char *first_global_object_name; |
67 | const char *weak_global_object_name; | |
79e68feb | 68 | |
79e68feb RS |
69 | extern struct obstack permanent_obstack; |
70 | #define obstack_chunk_alloc xmalloc | |
79e68feb | 71 | |
36edd3cc BS |
72 | struct addr_const; |
73 | struct constant_descriptor; | |
74 | struct rtx_const; | |
75 | struct pool_constant; | |
76 | ||
77 | #define MAX_RTX_HASH_TABLE 61 | |
78 | ||
79 | struct varasm_status | |
80 | { | |
81 | /* Hash facility for making memory-constants | |
82 | from constant rtl-expressions. It is used on RISC machines | |
83 | where immediate integer arguments and constant addresses are restricted | |
84 | so that such constants must be stored in memory. | |
85 | ||
86 | This pool of constants is reinitialized for each function | |
87 | so each function gets its own constants-pool that comes right before | |
88 | it. */ | |
89 | struct constant_descriptor **x_const_rtx_hash_table; | |
94b01be3 | 90 | struct pool_constant **x_const_rtx_sym_hash_table; |
36edd3cc BS |
91 | |
92 | /* Pointers to first and last constant in pool. */ | |
93 | struct pool_constant *x_first_pool, *x_last_pool; | |
94 | ||
95 | /* Current offset in constant pool (does not include any machine-specific | |
ffc5c6a9 | 96 | header). */ |
a79e3a45 | 97 | HOST_WIDE_INT x_pool_offset; |
36edd3cc BS |
98 | }; |
99 | ||
01d939e8 BS |
100 | #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table) |
101 | #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table) | |
102 | #define first_pool (cfun->varasm->x_first_pool) | |
103 | #define last_pool (cfun->varasm->x_last_pool) | |
104 | #define pool_offset (cfun->varasm->x_pool_offset) | |
36edd3cc | 105 | |
79e68feb RS |
106 | /* Number for making the label on the next |
107 | constant that is stored in memory. */ | |
108 | ||
109 | int const_labelno; | |
110 | ||
111 | /* Number for making the label on the next | |
112 | static variable internal to a function. */ | |
113 | ||
114 | int var_labelno; | |
115 | ||
dcc8e5e6 RS |
116 | /* Carry information from ASM_DECLARE_OBJECT_NAME |
117 | to ASM_FINISH_DECLARE_OBJECT. */ | |
118 | ||
119 | int size_directive_output; | |
120 | ||
cbed4565 RS |
121 | /* The last decl for which assemble_variable was called, |
122 | if it did ASM_DECLARE_OBJECT_NAME. | |
123 | If the last call to assemble_variable didn't do that, | |
124 | this holds 0. */ | |
125 | ||
126 | tree last_assemble_variable_decl; | |
127 | ||
a79e3a45 RK |
128 | /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization. |
129 | So giving constant the alias set for the type will allow such | |
130 | initializations to appear to conflict with the load of the constant. We | |
131 | avoid this by giving all constants an alias set for just constants. | |
a8154559 | 132 | Since there will be no stores to that alias set, nothing will ever |
a79e3a45 RK |
133 | conflict with them. */ |
134 | ||
135 | static HOST_WIDE_INT const_alias_set; | |
136 | ||
58782098 KG |
137 | static const char *strip_reg_name PARAMS ((const char *)); |
138 | static int contains_pointers_p PARAMS ((tree)); | |
139 | static void decode_addr_const PARAMS ((tree, struct addr_const *)); | |
140 | static int const_hash PARAMS ((tree)); | |
141 | static int compare_constant PARAMS ((tree, | |
5a13eaa4 | 142 | struct constant_descriptor *)); |
990e8954 | 143 | static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *)); |
58782098 KG |
144 | static struct constant_descriptor *record_constant PARAMS ((tree)); |
145 | static void record_constant_1 PARAMS ((tree)); | |
146 | static tree copy_constant PARAMS ((tree)); | |
147 | static void output_constant_def_contents PARAMS ((tree, int, int)); | |
148 | static void decode_rtx_const PARAMS ((enum machine_mode, rtx, | |
5a13eaa4 | 149 | struct rtx_const *)); |
58782098 KG |
150 | static int const_hash_rtx PARAMS ((enum machine_mode, rtx)); |
151 | static int compare_constant_rtx PARAMS ((enum machine_mode, rtx, | |
5a13eaa4 | 152 | struct constant_descriptor *)); |
58782098 | 153 | static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode, |
5a13eaa4 | 154 | rtx)); |
58782098 KG |
155 | static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx)); |
156 | static void mark_constant_pool PARAMS ((void)); | |
157 | static void mark_constants PARAMS ((rtx)); | |
fcbd8ef2 | 158 | static int mark_constant PARAMS ((rtx *current_rtx, void *data)); |
58782098 KG |
159 | static int output_addressed_constants PARAMS ((tree)); |
160 | static void output_after_function_constants PARAMS ((void)); | |
ffc5c6a9 | 161 | static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree)); |
c8af3574 | 162 | static unsigned min_align PARAMS ((unsigned, unsigned)); |
ac79cd5a RK |
163 | static void output_constructor PARAMS ((tree, HOST_WIDE_INT, |
164 | unsigned int)); | |
19c5b1cf | 165 | static void globalize_decl PARAMS ((tree)); |
b14707c3 | 166 | static void maybe_assemble_visibility PARAMS ((tree)); |
715bdd29 RH |
167 | static int in_named_entry_eq PARAMS ((const PTR, const PTR)); |
168 | static hashval_t in_named_entry_hash PARAMS ((const PTR)); | |
0e05e8ea | 169 | #ifdef ASM_OUTPUT_BSS |
3cce094d | 170 | static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int)); |
0e05e8ea | 171 | #endif |
cab634f2 | 172 | #ifdef BSS_SECTION_ASM_OP |
0e05e8ea | 173 | #ifdef ASM_OUTPUT_ALIGNED_BSS |
3cce094d KG |
174 | static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *, |
175 | int, int)); | |
0e05e8ea | 176 | #endif |
cab634f2 | 177 | #endif /* BSS_SECTION_ASM_OP */ |
58782098 | 178 | static void mark_pool_constant PARAMS ((struct pool_constant *)); |
58782098 | 179 | static void mark_const_hash_entry PARAMS ((void *)); |
bd7cf17e JJ |
180 | static int mark_const_str_htab_1 PARAMS ((void **, void *)); |
181 | static void mark_const_str_htab PARAMS ((void *)); | |
182 | static hashval_t const_str_htab_hash PARAMS ((const void *x)); | |
183 | static int const_str_htab_eq PARAMS ((const void *x, const void *y)); | |
184 | static void const_str_htab_del PARAMS ((void *)); | |
3cce094d | 185 | static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int)); |
1b18fc2c | 186 | static void resolve_unique_section PARAMS ((tree, int, int)); |
f90bf7ca | 187 | static void mark_weak PARAMS ((tree)); |
79e68feb | 188 | \f |
e5887033 DE |
189 | static enum in_section { no_section, in_text, in_data, in_named |
190 | #ifdef BSS_SECTION_ASM_OP | |
191 | , in_bss | |
192 | #endif | |
2cc07db4 RH |
193 | #ifdef CTORS_SECTION_ASM_OP |
194 | , in_ctors | |
195 | #endif | |
196 | #ifdef DTORS_SECTION_ASM_OP | |
197 | , in_dtors | |
198 | #endif | |
79e68feb | 199 | #ifdef EXTRA_SECTIONS |
e5887033 | 200 | , EXTRA_SECTIONS |
79e68feb | 201 | #endif |
e5887033 | 202 | } in_section = no_section; |
79e68feb | 203 | |
8a425a05 | 204 | /* Return a non-zero value if DECL has a section attribute. */ |
a56e7c08 | 205 | #ifndef IN_NAMED_SECTION |
8a425a05 DE |
206 | #define IN_NAMED_SECTION(DECL) \ |
207 | ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \ | |
208 | && DECL_SECTION_NAME (DECL) != NULL_TREE) | |
a56e7c08 | 209 | #endif |
46f9491e | 210 | |
8a425a05 | 211 | /* Text of section name when in_section == in_named. */ |
520a57c8 | 212 | static const char *in_named_name; |
8a425a05 | 213 | |
715bdd29 RH |
214 | /* Hash table of flags that have been used for a particular named section. */ |
215 | ||
216 | struct in_named_entry | |
217 | { | |
218 | const char *name; | |
219 | unsigned int flags; | |
a8c01a59 | 220 | bool declared; |
715bdd29 RH |
221 | }; |
222 | ||
223 | static htab_t in_named_htab; | |
224 | ||
79e68feb RS |
225 | /* Define functions like text_section for any extra sections. */ |
226 | #ifdef EXTRA_SECTION_FUNCTIONS | |
227 | EXTRA_SECTION_FUNCTIONS | |
228 | #endif | |
229 | ||
230 | /* Tell assembler to switch to text section. */ | |
231 | ||
232 | void | |
233 | text_section () | |
234 | { | |
235 | if (in_section != in_text) | |
236 | { | |
f99ffb60 RH |
237 | #ifdef TEXT_SECTION |
238 | TEXT_SECTION (); | |
239 | #else | |
b93a436e | 240 | fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP); |
f99ffb60 | 241 | #endif |
79e68feb RS |
242 | in_section = in_text; |
243 | } | |
244 | } | |
245 | ||
79e68feb RS |
246 | /* Tell assembler to switch to data section. */ |
247 | ||
248 | void | |
249 | data_section () | |
250 | { | |
251 | if (in_section != in_data) | |
252 | { | |
b93a436e | 253 | if (flag_shared_data) |
79e68feb RS |
254 | { |
255 | #ifdef SHARED_SECTION_ASM_OP | |
b93a436e | 256 | fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP); |
79e68feb | 257 | #else |
b93a436e | 258 | fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP); |
79e68feb RS |
259 | #endif |
260 | } | |
b93a436e JL |
261 | else |
262 | fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP); | |
79e68feb RS |
263 | |
264 | in_section = in_data; | |
265 | } | |
266 | } | |
c26fbbca | 267 | |
3167de5b | 268 | /* Tell assembler to ALWAYS switch to data section, in case |
dd49a9ec | 269 | it's not sure where it is. */ |
3167de5b AM |
270 | |
271 | void | |
272 | force_data_section () | |
273 | { | |
274 | in_section = no_section; | |
275 | data_section (); | |
276 | } | |
79e68feb | 277 | |
7c6d68c8 RS |
278 | /* Tell assembler to switch to read-only data section. This is normally |
279 | the text section. */ | |
280 | ||
281 | void | |
282 | readonly_data_section () | |
283 | { | |
284 | #ifdef READONLY_DATA_SECTION | |
285 | READONLY_DATA_SECTION (); /* Note this can call data_section. */ | |
286 | #else | |
287 | text_section (); | |
288 | #endif | |
289 | } | |
290 | ||
0f41302f | 291 | /* Determine if we're in the text section. */ |
79e68feb RS |
292 | |
293 | int | |
294 | in_text_section () | |
295 | { | |
296 | return in_section == in_text; | |
297 | } | |
8a425a05 | 298 | |
0f41302f | 299 | /* Determine if we're in the data section. */ |
6f2f3db7 | 300 | |
274351ba RK |
301 | int |
302 | in_data_section () | |
303 | { | |
304 | return in_section == in_data; | |
305 | } | |
6f2f3db7 | 306 | |
715bdd29 RH |
307 | /* Helper routines for maintaining in_named_htab. */ |
308 | ||
309 | static int | |
310 | in_named_entry_eq (p1, p2) | |
311 | const PTR p1; | |
312 | const PTR p2; | |
313 | { | |
314 | const struct in_named_entry *old = p1; | |
315 | const char *new = p2; | |
316 | ||
317 | return strcmp (old->name, new) == 0; | |
318 | } | |
319 | ||
320 | static hashval_t | |
321 | in_named_entry_hash (p) | |
322 | const PTR p; | |
323 | { | |
324 | const struct in_named_entry *old = p; | |
325 | return htab_hash_string (old->name); | |
326 | } | |
327 | ||
328 | /* If SECTION has been seen before as a named section, return the flags | |
329 | that were used. Otherwise, return 0. Note, that 0 is a perfectly valid | |
330 | set of flags for a section to have, so 0 does not mean that the section | |
331 | has not been seen. */ | |
332 | ||
333 | unsigned int | |
334 | get_named_section_flags (section) | |
335 | const char *section; | |
336 | { | |
337 | struct in_named_entry **slot; | |
338 | ||
c26fbbca | 339 | slot = (struct in_named_entry **) |
715bdd29 RH |
340 | htab_find_slot_with_hash (in_named_htab, section, |
341 | htab_hash_string (section), NO_INSERT); | |
342 | ||
343 | return slot ? (*slot)->flags : 0; | |
344 | } | |
345 | ||
a8c01a59 | 346 | /* Returns true if the section has been declared before. Sets internal |
c26fbbca | 347 | flag on this section in in_named_hash so subsequent calls on this |
2ba84f36 | 348 | section will return false. */ |
a8c01a59 RL |
349 | |
350 | bool | |
351 | named_section_first_declaration (name) | |
352 | const char *name; | |
353 | { | |
354 | struct in_named_entry **slot; | |
355 | ||
c26fbbca KH |
356 | slot = (struct in_named_entry **) |
357 | htab_find_slot_with_hash (in_named_htab, name, | |
a8c01a59 RL |
358 | htab_hash_string (name), NO_INSERT); |
359 | if (! (*slot)->declared) | |
360 | { | |
361 | (*slot)->declared = true; | |
362 | return true; | |
363 | } | |
c26fbbca | 364 | else |
a8c01a59 RL |
365 | { |
366 | return false; | |
367 | } | |
368 | } | |
369 | ||
370 | ||
715bdd29 RH |
371 | /* Record FLAGS for SECTION. If SECTION was previously recorded with a |
372 | different set of flags, return false. */ | |
373 | ||
374 | bool | |
375 | set_named_section_flags (section, flags) | |
376 | const char *section; | |
377 | unsigned int flags; | |
378 | { | |
379 | struct in_named_entry **slot, *entry; | |
380 | ||
c26fbbca | 381 | slot = (struct in_named_entry **) |
715bdd29 RH |
382 | htab_find_slot_with_hash (in_named_htab, section, |
383 | htab_hash_string (section), INSERT); | |
384 | entry = *slot; | |
385 | ||
386 | if (!entry) | |
387 | { | |
388 | entry = (struct in_named_entry *) xmalloc (sizeof (*entry)); | |
389 | *slot = entry; | |
390 | entry->name = ggc_strdup (section); | |
391 | entry->flags = flags; | |
8d2134aa | 392 | entry->declared = false; |
715bdd29 RH |
393 | } |
394 | else if (entry->flags != flags) | |
395 | return false; | |
396 | ||
397 | return true; | |
398 | } | |
399 | ||
7c262518 RH |
400 | /* Tell assembler to change to section NAME with attributes FLAGS. */ |
401 | ||
402 | void | |
715bdd29 | 403 | named_section_flags (name, flags) |
7c262518 RH |
404 | const char *name; |
405 | unsigned int flags; | |
7c262518 | 406 | { |
715bdd29 | 407 | if (in_section != in_named || strcmp (name, in_named_name) != 0) |
7c262518 | 408 | { |
715bdd29 RH |
409 | if (! set_named_section_flags (name, flags)) |
410 | abort (); | |
411 | ||
c26fbbca | 412 | (*targetm.asm_out.named_section) (name, flags); |
7c262518 RH |
413 | |
414 | if (flags & SECTION_FORGET) | |
415 | in_section = no_section; | |
416 | else | |
417 | { | |
418 | in_named_name = ggc_strdup (name); | |
419 | in_section = in_named; | |
420 | } | |
421 | } | |
422 | } | |
423 | ||
2ffe831c DE |
424 | /* Tell assembler to change to section NAME for DECL. |
425 | If DECL is NULL, just switch to section NAME. | |
ad4ff310 JM |
426 | If NAME is NULL, get the name from DECL. |
427 | If RELOC is 1, the initializer for DECL contains relocs. */ | |
8a425a05 DE |
428 | |
429 | void | |
ad4ff310 | 430 | named_section (decl, name, reloc) |
2ffe831c | 431 | tree decl; |
87e11268 | 432 | const char *name; |
7c262518 | 433 | int reloc; |
8a425a05 | 434 | { |
7c262518 RH |
435 | unsigned int flags; |
436 | ||
2f939d94 | 437 | if (decl != NULL_TREE && !DECL_P (decl)) |
2ffe831c DE |
438 | abort (); |
439 | if (name == NULL) | |
440 | name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
441 | ||
7c262518 | 442 | flags = (* targetm.section_type_flags) (decl, name, reloc); |
715bdd29 RH |
443 | |
444 | /* Sanity check user variables for flag changes. Non-user | |
10c45943 AG |
445 | section flag changes will abort in named_section_flags. |
446 | However, don't complain if SECTION_OVERRIDE is set. | |
447 | We trust that the setter knows that it is safe to ignore | |
448 | the default flags for this decl. */ | |
715bdd29 RH |
449 | if (decl && ! set_named_section_flags (name, flags)) |
450 | { | |
715bdd29 | 451 | flags = get_named_section_flags (name); |
10c45943 AG |
452 | if ((flags & SECTION_OVERRIDE) == 0) |
453 | error_with_decl (decl, "%s causes a section type conflict"); | |
715bdd29 RH |
454 | } |
455 | ||
456 | named_section_flags (name, flags); | |
7c262518 | 457 | } |
e9a25f70 | 458 | |
7c262518 RH |
459 | /* If required, set DECL_SECTION_NAME to a unique name. */ |
460 | ||
461 | static void | |
1b18fc2c | 462 | resolve_unique_section (decl, reloc, flag_function_or_data_sections) |
7c262518 | 463 | tree decl; |
715bdd29 | 464 | int reloc ATTRIBUTE_UNUSED; |
1b18fc2c | 465 | int flag_function_or_data_sections; |
7c262518 RH |
466 | { |
467 | if (DECL_SECTION_NAME (decl) == NULL_TREE | |
1b18fc2c | 468 | && (flag_function_or_data_sections |
7c262518 RH |
469 | || (targetm.have_named_sections |
470 | && DECL_ONE_ONLY (decl)))) | |
471 | UNIQUE_SECTION (decl, reloc); | |
8a425a05 | 472 | } |
4d1065ed | 473 | |
e5887033 DE |
474 | #ifdef BSS_SECTION_ASM_OP |
475 | ||
476 | /* Tell the assembler to switch to the bss section. */ | |
477 | ||
478 | void | |
da2c5447 | 479 | bss_section () |
e5887033 DE |
480 | { |
481 | if (in_section != in_bss) | |
482 | { | |
e5887033 | 483 | #ifdef SHARED_BSS_SECTION_ASM_OP |
b93a436e JL |
484 | if (flag_shared_data) |
485 | fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP); | |
486 | else | |
e5887033 | 487 | #endif |
b93a436e | 488 | fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP); |
e5887033 DE |
489 | |
490 | in_section = in_bss; | |
491 | } | |
492 | } | |
493 | ||
494 | #ifdef ASM_OUTPUT_BSS | |
495 | ||
496 | /* Utility function for ASM_OUTPUT_BSS for targets to use if | |
497 | they don't support alignments in .bss. | |
498 | ??? It is believed that this function will work in most cases so such | |
499 | support is localized here. */ | |
500 | ||
501 | static void | |
91fddd7c | 502 | asm_output_bss (file, decl, name, size, rounded) |
e5887033 | 503 | FILE *file; |
05b13f59 | 504 | tree decl ATTRIBUTE_UNUSED; |
3cce094d | 505 | const char *name; |
05b13f59 | 506 | int size ATTRIBUTE_UNUSED, rounded; |
e5887033 DE |
507 | { |
508 | ASM_GLOBALIZE_LABEL (file, name); | |
509 | bss_section (); | |
91fddd7c DE |
510 | #ifdef ASM_DECLARE_OBJECT_NAME |
511 | last_assemble_variable_decl = decl; | |
512 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
513 | #else | |
514 | /* Standard thing is just output label for the object. */ | |
e5887033 | 515 | ASM_OUTPUT_LABEL (file, name); |
91fddd7c | 516 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
e5887033 DE |
517 | ASM_OUTPUT_SKIP (file, rounded); |
518 | } | |
519 | ||
520 | #endif | |
521 | ||
522 | #ifdef ASM_OUTPUT_ALIGNED_BSS | |
523 | ||
524 | /* Utility function for targets to use in implementing | |
525 | ASM_OUTPUT_ALIGNED_BSS. | |
526 | ??? It is believed that this function will work in most cases so such | |
527 | support is localized here. */ | |
528 | ||
529 | static void | |
91fddd7c | 530 | asm_output_aligned_bss (file, decl, name, size, align) |
e5887033 | 531 | FILE *file; |
91ea4f8d | 532 | tree decl ATTRIBUTE_UNUSED; |
3cce094d | 533 | const char *name; |
e5887033 DE |
534 | int size, align; |
535 | { | |
536 | ASM_GLOBALIZE_LABEL (file, name); | |
537 | bss_section (); | |
538 | ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT)); | |
91fddd7c DE |
539 | #ifdef ASM_DECLARE_OBJECT_NAME |
540 | last_assemble_variable_decl = decl; | |
541 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
542 | #else | |
543 | /* Standard thing is just output label for the object. */ | |
e5887033 | 544 | ASM_OUTPUT_LABEL (file, name); |
91fddd7c | 545 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
f8bc3367 | 546 | ASM_OUTPUT_SKIP (file, size ? size : 1); |
e5887033 DE |
547 | } |
548 | ||
549 | #endif | |
550 | ||
551 | #endif /* BSS_SECTION_ASM_OP */ | |
552 | ||
4d1065ed DE |
553 | /* Switch to the section for function DECL. |
554 | ||
555 | If DECL is NULL_TREE, switch to the text section. | |
556 | ??? It's not clear that we will ever be passed NULL_TREE, but it's | |
557 | safer to handle it. */ | |
558 | ||
559 | void | |
560 | function_section (decl) | |
561 | tree decl; | |
562 | { | |
563 | if (decl != NULL_TREE | |
564 | && DECL_SECTION_NAME (decl) != NULL_TREE) | |
ad4ff310 | 565 | named_section (decl, (char *) 0, 0); |
8b43265c JL |
566 | else |
567 | text_section (); | |
4d1065ed | 568 | } |
f9da1f35 DE |
569 | |
570 | /* Switch to section for variable DECL. | |
571 | ||
572 | RELOC is the `reloc' argument to SELECT_SECTION. */ | |
573 | ||
574 | void | |
575 | variable_section (decl, reloc) | |
576 | tree decl; | |
577 | int reloc; | |
578 | { | |
579 | if (IN_NAMED_SECTION (decl)) | |
ad4ff310 | 580 | named_section (decl, NULL, reloc); |
f9da1f35 DE |
581 | else |
582 | { | |
583 | /* C++ can have const variables that get initialized from constructors, | |
584 | and thus can not be in a readonly section. We prevent this by | |
585 | verifying that the initial value is constant for objects put in a | |
586 | readonly section. | |
587 | ||
588 | error_mark_node is used by the C front end to indicate that the | |
589 | initializer has not been seen yet. In this case, we assume that | |
e5887033 DE |
590 | the initializer must be constant. |
591 | ||
592 | C++ uses error_mark_node for variables that have complicated | |
593 | initializers, but these variables go in BSS so we won't be called | |
594 | for them. */ | |
595 | ||
f9da1f35 | 596 | #ifdef SELECT_SECTION |
201556f0 | 597 | SELECT_SECTION (decl, reloc, DECL_ALIGN (decl)); |
f9da1f35 | 598 | #else |
ad4ff310 | 599 | if (DECL_READONLY_SECTION (decl, reloc)) |
f9da1f35 DE |
600 | readonly_data_section (); |
601 | else | |
602 | data_section (); | |
603 | #endif | |
604 | } | |
605 | } | |
6adb4e3a MS |
606 | |
607 | /* Tell assembler to switch to the section for the exception handling | |
608 | table. */ | |
609 | ||
610 | void | |
07c9d2eb | 611 | default_exception_section () |
6adb4e3a | 612 | { |
7c262518 RH |
613 | if (targetm.have_named_sections) |
614 | named_section (NULL_TREE, ".gcc_except_table", 0); | |
615 | else if (flag_pic) | |
6adb4e3a MS |
616 | data_section (); |
617 | else | |
6adb4e3a | 618 | readonly_data_section (); |
6adb4e3a | 619 | } |
201556f0 JJ |
620 | |
621 | /* Tell assembler to switch to the section for string merging. */ | |
622 | ||
623 | void | |
624 | mergeable_string_section (decl, align, flags) | |
c26fbbca KH |
625 | tree decl ATTRIBUTE_UNUSED; |
626 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED; | |
627 | unsigned int flags ATTRIBUTE_UNUSED; | |
201556f0 JJ |
628 | { |
629 | #ifdef HAVE_GAS_SHF_MERGE | |
630 | if (flag_merge_constants | |
631 | && TREE_CODE (decl) == STRING_CST | |
632 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
633 | && align <= 256 | |
634 | && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl))) | |
635 | { | |
636 | enum machine_mode mode; | |
637 | unsigned int modesize; | |
638 | const char *str; | |
639 | int i, j, len, unit; | |
640 | char name[30]; | |
641 | ||
642 | mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl))); | |
643 | modesize = GET_MODE_BITSIZE (mode); | |
644 | if (modesize >= 8 && modesize <= 256 | |
645 | && (modesize & (modesize - 1)) == 0) | |
646 | { | |
647 | if (align < modesize) | |
648 | align = modesize; | |
649 | ||
650 | str = TREE_STRING_POINTER (decl); | |
651 | len = TREE_STRING_LENGTH (decl); | |
652 | unit = GET_MODE_SIZE (mode); | |
653 | ||
654 | /* Check for embedded NUL characters. */ | |
655 | for (i = 0; i < len; i += unit) | |
656 | { | |
657 | for (j = 0; j < unit; j++) | |
c26fbbca | 658 | if (str[i + j] != '\0') |
201556f0 JJ |
659 | break; |
660 | if (j == unit) | |
661 | break; | |
662 | } | |
663 | if (i == len - unit) | |
664 | { | |
665 | sprintf (name, ".rodata.str%d.%d", modesize / 8, | |
666 | (int) (align / 8)); | |
667 | flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS; | |
668 | if (!i && modesize < align) | |
669 | { | |
670 | /* A "" string with requested alignment greater than | |
671 | character size might cause a problem: | |
672 | if some other string required even bigger | |
673 | alignment than "", then linker might think the | |
674 | "" is just part of padding after some other string | |
675 | and not put it into the hash table initially. | |
676 | But this means "" could have smaller alignment | |
677 | than requested. */ | |
678 | #ifdef ASM_OUTPUT_SECTION_START | |
679 | named_section_flags (name, flags); | |
680 | ASM_OUTPUT_SECTION_START (asm_out_file); | |
681 | #else | |
682 | readonly_data_section (); | |
683 | #endif | |
684 | return; | |
685 | } | |
686 | ||
687 | named_section_flags (name, flags); | |
688 | return; | |
689 | } | |
690 | } | |
691 | } | |
692 | #endif | |
693 | readonly_data_section (); | |
c26fbbca | 694 | } |
201556f0 JJ |
695 | |
696 | /* Tell assembler to switch to the section for constant merging. */ | |
697 | ||
698 | void | |
699 | mergeable_constant_section (mode, align, flags) | |
c26fbbca KH |
700 | enum machine_mode mode ATTRIBUTE_UNUSED; |
701 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED; | |
702 | unsigned int flags ATTRIBUTE_UNUSED; | |
201556f0 JJ |
703 | { |
704 | #ifdef HAVE_GAS_SHF_MERGE | |
705 | unsigned int modesize = GET_MODE_BITSIZE (mode); | |
706 | ||
707 | if (flag_merge_constants | |
708 | && mode != VOIDmode | |
709 | && mode != BLKmode | |
710 | && modesize <= align | |
711 | && align >= 8 | |
712 | && align <= 256 | |
713 | && (align & (align - 1)) == 0) | |
714 | { | |
715 | char name[24]; | |
716 | ||
717 | sprintf (name, ".rodata.cst%d", (int) (align / 8)); | |
718 | flags |= (align / 8) | SECTION_MERGE; | |
719 | named_section_flags (name, flags); | |
720 | return; | |
c26fbbca | 721 | } |
201556f0 JJ |
722 | #endif |
723 | readonly_data_section (); | |
724 | } | |
79e68feb | 725 | \f |
b4ac57ab RS |
726 | /* Given NAME, a putative register name, discard any customary prefixes. */ |
727 | ||
87e11268 | 728 | static const char * |
b4ac57ab | 729 | strip_reg_name (name) |
c26fbbca | 730 | const char *name; |
b4ac57ab RS |
731 | { |
732 | #ifdef REGISTER_PREFIX | |
733 | if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX))) | |
734 | name += strlen (REGISTER_PREFIX); | |
735 | #endif | |
736 | if (name[0] == '%' || name[0] == '#') | |
737 | name++; | |
738 | return name; | |
739 | } | |
dcfedcd0 | 740 | \f |
79e68feb RS |
741 | /* Decode an `asm' spec for a declaration as a register name. |
742 | Return the register number, or -1 if nothing specified, | |
c09e6498 RS |
743 | or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized, |
744 | or -3 if ASMSPEC is `cc' and is not recognized, | |
745 | or -4 if ASMSPEC is `memory' and is not recognized. | |
dcfedcd0 RK |
746 | Accept an exact spelling or a decimal number. |
747 | Prefixes such as % are optional. */ | |
79e68feb RS |
748 | |
749 | int | |
750 | decode_reg_name (asmspec) | |
c26fbbca | 751 | const char *asmspec; |
79e68feb RS |
752 | { |
753 | if (asmspec != 0) | |
754 | { | |
755 | int i; | |
756 | ||
b4ac57ab RS |
757 | /* Get rid of confusing prefixes. */ |
758 | asmspec = strip_reg_name (asmspec); | |
46f9491e | 759 | |
fff9e713 MT |
760 | /* Allow a decimal number as a "register name". */ |
761 | for (i = strlen (asmspec) - 1; i >= 0; i--) | |
0df6c2c7 | 762 | if (! ISDIGIT (asmspec[i])) |
fff9e713 MT |
763 | break; |
764 | if (asmspec[0] != 0 && i < 0) | |
765 | { | |
766 | i = atoi (asmspec); | |
767 | if (i < FIRST_PSEUDO_REGISTER && i >= 0) | |
768 | return i; | |
769 | else | |
770 | return -2; | |
771 | } | |
772 | ||
79e68feb | 773 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
b4ac57ab RS |
774 | if (reg_names[i][0] |
775 | && ! strcmp (asmspec, strip_reg_name (reg_names[i]))) | |
79e68feb RS |
776 | return i; |
777 | ||
79e68feb RS |
778 | #ifdef ADDITIONAL_REGISTER_NAMES |
779 | { | |
83182544 | 780 | static const struct { const char *const name; const int number; } table[] |
79e68feb RS |
781 | = ADDITIONAL_REGISTER_NAMES; |
782 | ||
b6a1cbae | 783 | for (i = 0; i < (int) ARRAY_SIZE (table); i++) |
79e68feb RS |
784 | if (! strcmp (asmspec, table[i].name)) |
785 | return table[i].number; | |
79e68feb RS |
786 | } |
787 | #endif /* ADDITIONAL_REGISTER_NAMES */ | |
788 | ||
c09e6498 RS |
789 | if (!strcmp (asmspec, "memory")) |
790 | return -4; | |
791 | ||
dcfedcd0 RK |
792 | if (!strcmp (asmspec, "cc")) |
793 | return -3; | |
794 | ||
79e68feb RS |
795 | return -2; |
796 | } | |
797 | ||
798 | return -1; | |
799 | } | |
800 | \f | |
19e7881c MM |
801 | /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should |
802 | have static storage duration. In other words, it should not be an | |
803 | automatic variable, including PARM_DECLs. | |
804 | ||
805 | There is, however, one exception: this function handles variables | |
806 | explicitly placed in a particular register by the user. | |
807 | ||
808 | ASMSPEC, if not 0, is the string which the user specified as the | |
809 | assembler symbol name. | |
79e68feb RS |
810 | |
811 | This is never called for PARM_DECL nodes. */ | |
812 | ||
813 | void | |
6c418184 | 814 | make_decl_rtl (decl, asmspec) |
79e68feb | 815 | tree decl; |
87e11268 | 816 | const char *asmspec; |
79e68feb | 817 | { |
6c418184 | 818 | int top_level = (DECL_CONTEXT (decl) == NULL_TREE); |
63ad61ed ZW |
819 | const char *name = 0; |
820 | const char *new_name = 0; | |
ca695ac9 | 821 | int reg_number; |
abde42f7 | 822 | rtx x; |
ca695ac9 | 823 | |
19e7881c | 824 | /* Check that we are not being given an automatic variable. */ |
9ea07fd0 | 825 | /* A weak alias has TREE_PUBLIC set but not the other bits. */ |
19e7881c MM |
826 | if (TREE_CODE (decl) == PARM_DECL |
827 | || TREE_CODE (decl) == RESULT_DECL | |
828 | || (TREE_CODE (decl) == VAR_DECL | |
829 | && !TREE_STATIC (decl) | |
9ea07fd0 | 830 | && !TREE_PUBLIC (decl) |
19e7881c MM |
831 | && !DECL_EXTERNAL (decl) |
832 | && !DECL_REGISTER (decl))) | |
833 | abort (); | |
834 | /* And that we were not given a type or a label. */ | |
46f9491e | 835 | else if (TREE_CODE (decl) == TYPE_DECL |
19e7881c MM |
836 | || TREE_CODE (decl) == LABEL_DECL) |
837 | abort (); | |
838 | ||
63ad61ed ZW |
839 | /* For a duplicate declaration, we can be called twice on the |
840 | same DECL node. Don't discard the RTL already made. */ | |
19e7881c | 841 | if (DECL_RTL_SET_P (decl)) |
79e68feb | 842 | { |
63ad61ed ZW |
843 | /* If the old RTL had the wrong mode, fix the mode. */ |
844 | if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl)) | |
c4e59f51 RK |
845 | SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl), |
846 | DECL_MODE (decl), 0)); | |
76095e2f | 847 | |
63ad61ed ZW |
848 | /* ??? Another way to do this would be to do what halfpic.c does |
849 | and maintain a hashed table of such critters. */ | |
63ad61ed ZW |
850 | /* Let the target reassign the RTL if it wants. |
851 | This is necessary, for example, when one machine specific | |
852 | decl attribute overrides another. */ | |
b2003250 RH |
853 | #ifdef ENCODE_SECTION_INFO |
854 | ENCODE_SECTION_INFO (decl, false); | |
63ad61ed ZW |
855 | #endif |
856 | return; | |
79e68feb RS |
857 | } |
858 | ||
63ad61ed ZW |
859 | new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
860 | ||
861 | reg_number = decode_reg_name (asmspec); | |
862 | if (reg_number == -2) | |
8f820299 ZW |
863 | { |
864 | /* ASMSPEC is given, and not the name of a register. Mark the | |
865 | name with a star so assemble_name won't munge it. */ | |
866 | char *starred = alloca (strlen (asmspec) + 2); | |
867 | starred[0] = '*'; | |
868 | strcpy (starred + 1, asmspec); | |
869 | new_name = starred; | |
870 | } | |
63ad61ed ZW |
871 | |
872 | if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) | |
79e68feb | 873 | { |
79e68feb | 874 | /* First detect errors in declaring global registers. */ |
63ad61ed ZW |
875 | if (reg_number == -1) |
876 | error_with_decl (decl, "register name not specified for `%s'"); | |
877 | else if (reg_number < 0) | |
878 | error_with_decl (decl, "invalid register name for `%s'"); | |
879 | else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode) | |
12266a61 RK |
880 | error_with_decl (decl, |
881 | "data type of `%s' isn't suitable for a register"); | |
63ad61ed | 882 | else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl)))) |
12266a61 | 883 | error_with_decl (decl, |
63ad61ed | 884 | "register specified for `%s' isn't suitable for data type"); |
79e68feb | 885 | /* Now handle properly declared static register variables. */ |
63ad61ed | 886 | else |
79e68feb RS |
887 | { |
888 | int nregs; | |
12266a61 | 889 | |
e3406b2a | 890 | if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl)) |
79e68feb RS |
891 | { |
892 | DECL_INITIAL (decl) = 0; | |
893 | error ("global register variable has initial value"); | |
894 | } | |
79e68feb RS |
895 | if (TREE_THIS_VOLATILE (decl)) |
896 | warning ("volatile register variables don't work as you might wish"); | |
31e4b1c0 RK |
897 | |
898 | /* If the user specified one of the eliminables registers here, | |
899 | e.g., FRAME_POINTER_REGNUM, we don't want to get this variable | |
3ada20ee RH |
900 | confused with that register and be eliminated. This usage is |
901 | somewhat suspect... */ | |
902 | ||
903 | SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number)); | |
904 | ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number; | |
79e68feb RS |
905 | REG_USERVAR_P (DECL_RTL (decl)) = 1; |
906 | ||
6c418184 | 907 | if (TREE_STATIC (decl)) |
79e68feb | 908 | { |
ad800eb1 RK |
909 | /* Make this register global, so not usable for anything |
910 | else. */ | |
1cb36a98 RH |
911 | #ifdef ASM_DECLARE_REGISTER_GLOBAL |
912 | ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name); | |
913 | #endif | |
79e68feb RS |
914 | nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl)); |
915 | while (nregs > 0) | |
ad800eb1 | 916 | globalize_reg (reg_number + --nregs); |
79e68feb | 917 | } |
79e68feb | 918 | |
63ad61ed ZW |
919 | /* As a register variable, it has no section. */ |
920 | return; | |
921 | } | |
922 | } | |
0a5152d0 | 923 | |
63ad61ed ZW |
924 | /* Now handle ordinary static variables and functions (in memory). |
925 | Also handle vars declared register invalidly. */ | |
926 | ||
927 | if (reg_number >= 0 || reg_number == -3) | |
928 | error_with_decl (decl, | |
929 | "register name given for non-register variable `%s'"); | |
930 | ||
931 | /* Specifying a section attribute on a variable forces it into a | |
2d76cb1a | 932 | non-.bss section, and thus it cannot be common. */ |
63ad61ed ZW |
933 | if (TREE_CODE (decl) == VAR_DECL |
934 | && DECL_SECTION_NAME (decl) != NULL_TREE | |
935 | && DECL_INITIAL (decl) == NULL_TREE | |
936 | && DECL_COMMON (decl)) | |
937 | DECL_COMMON (decl) = 0; | |
938 | ||
939 | /* Can't use just the variable's own name for a variable | |
940 | whose scope is less than the whole file, unless it's a member | |
941 | of a local class (which will already be unambiguous). | |
942 | Concatenate a distinguishing number. */ | |
943 | if (!top_level && !TREE_PUBLIC (decl) | |
944 | && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))) | |
60080880 JJ |
945 | && asmspec == 0 |
946 | && name == IDENTIFIER_POINTER (DECL_NAME (decl))) | |
63ad61ed ZW |
947 | { |
948 | char *label; | |
37a08a29 | 949 | |
63ad61ed ZW |
950 | ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno); |
951 | var_labelno++; | |
952 | new_name = label; | |
953 | } | |
76095e2f | 954 | |
63ad61ed | 955 | if (name != new_name) |
ff8f4401 | 956 | { |
92643fea | 957 | SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name)); |
63ad61ed ZW |
958 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
959 | } | |
d9525bec | 960 | |
63ad61ed | 961 | /* If this variable is to be treated as volatile, show its |
6d2f8887 | 962 | tree node has side effects. */ |
63ad61ed ZW |
963 | if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL |
964 | && TREE_PUBLIC (decl)) | |
965 | || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL | |
966 | && (TREE_PUBLIC (decl) || TREE_STATIC (decl))))) | |
967 | TREE_SIDE_EFFECTS (decl) = 1; | |
968 | ||
abde42f7 JH |
969 | x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name)); |
970 | SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl); | |
63ad61ed | 971 | if (TREE_CODE (decl) != FUNCTION_DECL) |
abde42f7 JH |
972 | set_mem_attributes (x, decl, 1); |
973 | SET_DECL_RTL (decl, x); | |
63ad61ed ZW |
974 | |
975 | /* Optionally set flags or add text to the name to record information | |
976 | such as that it is a function name. | |
977 | If the name is changed, the macro ASM_OUTPUT_LABELREF | |
978 | will have to know how to strip this information. */ | |
979 | #ifdef ENCODE_SECTION_INFO | |
b2003250 | 980 | ENCODE_SECTION_INFO (decl, true); |
d9525bec | 981 | #endif |
79e68feb | 982 | } |
4724d87a RS |
983 | |
984 | /* Make the rtl for variable VAR be volatile. | |
985 | Use this only for static variables. */ | |
986 | ||
fcbaecc6 | 987 | void |
4724d87a RS |
988 | make_var_volatile (var) |
989 | tree var; | |
990 | { | |
991 | if (GET_CODE (DECL_RTL (var)) != MEM) | |
992 | abort (); | |
993 | ||
994 | MEM_VOLATILE_P (DECL_RTL (var)) = 1; | |
995 | } | |
79e68feb | 996 | \f |
d447ec6f RS |
997 | /* Output alignment directive to align for constant expression EXP. */ |
998 | ||
999 | void | |
1000 | assemble_constant_align (exp) | |
1001 | tree exp; | |
1002 | { | |
1003 | int align; | |
1004 | ||
1005 | /* Align the location counter as required by EXP's data type. */ | |
1006 | align = TYPE_ALIGN (TREE_TYPE (exp)); | |
1007 | #ifdef CONSTANT_ALIGNMENT | |
1008 | align = CONSTANT_ALIGNMENT (exp, align); | |
1009 | #endif | |
1010 | ||
1011 | if (align > BITS_PER_UNIT) | |
91ea4f8d KG |
1012 | { |
1013 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
1014 | } | |
d447ec6f RS |
1015 | } |
1016 | ||
79e68feb RS |
1017 | /* Output a string of literal assembler code |
1018 | for an `asm' keyword used between functions. */ | |
1019 | ||
1020 | void | |
1021 | assemble_asm (string) | |
1022 | tree string; | |
1023 | { | |
1024 | app_enable (); | |
1025 | ||
1026 | if (TREE_CODE (string) == ADDR_EXPR) | |
1027 | string = TREE_OPERAND (string, 0); | |
1028 | ||
1029 | fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string)); | |
1030 | } | |
1031 | ||
2cc07db4 RH |
1032 | /* Record an element in the table of global destructors. SYMBOL is |
1033 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
1034 | between 0 and MAX_INIT_PRIORITY. */ | |
79e68feb RS |
1035 | |
1036 | void | |
2cc07db4 | 1037 | default_stabs_asm_out_destructor (symbol, priority) |
47907859 | 1038 | rtx symbol; |
2cc07db4 | 1039 | int priority ATTRIBUTE_UNUSED; |
79e68feb | 1040 | { |
2cc07db4 RH |
1041 | /* Tell GNU LD that this is part of the static destructor set. |
1042 | This will work for any system that uses stabs, most usefully | |
1043 | aout systems. */ | |
1044 | fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP); | |
1045 | assemble_name (asm_out_file, XSTR (symbol, 0)); | |
1046 | fputc ('\n', asm_out_file); | |
1047 | } | |
47907859 | 1048 | |
2cc07db4 RH |
1049 | void |
1050 | default_named_section_asm_out_destructor (symbol, priority) | |
1051 | rtx symbol; | |
1052 | int priority; | |
1053 | { | |
1054 | const char *section = ".dtors"; | |
1055 | char buf[16]; | |
47907859 | 1056 | |
6d2f8887 | 1057 | /* ??? This only works reliably with the GNU linker. */ |
2cc07db4 | 1058 | if (priority != DEFAULT_INIT_PRIORITY) |
47907859 | 1059 | { |
47907859 RH |
1060 | sprintf (buf, ".dtors.%.5u", |
1061 | /* Invert the numbering so the linker puts us in the proper | |
1062 | order; constructors are run from right to left, and the | |
1063 | linker sorts in increasing order. */ | |
1064 | MAX_INIT_PRIORITY - priority); | |
2cc07db4 | 1065 | section = buf; |
47907859 RH |
1066 | } |
1067 | ||
715bdd29 RH |
1068 | named_section_flags (section, SECTION_WRITE); |
1069 | assemble_align (POINTER_SIZE); | |
c8af3574 | 1070 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
2cc07db4 RH |
1071 | } |
1072 | ||
1073 | #ifdef DTORS_SECTION_ASM_OP | |
1074 | void | |
1075 | dtors_section () | |
1076 | { | |
1077 | if (in_section != in_dtors) | |
79e68feb | 1078 | { |
2cc07db4 RH |
1079 | in_section = in_dtors; |
1080 | fputs (DTORS_SECTION_ASM_OP, asm_out_file); | |
79e68feb RS |
1081 | fputc ('\n', asm_out_file); |
1082 | } | |
79e68feb RS |
1083 | } |
1084 | ||
2cc07db4 RH |
1085 | void |
1086 | default_dtor_section_asm_out_destructor (symbol, priority) | |
1087 | rtx symbol; | |
1088 | int priority ATTRIBUTE_UNUSED; | |
1089 | { | |
1090 | dtors_section (); | |
c8af3574 RH |
1091 | assemble_align (POINTER_SIZE); |
1092 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
2cc07db4 RH |
1093 | } |
1094 | #endif | |
1095 | ||
79e68feb RS |
1096 | /* Likewise for global constructors. */ |
1097 | ||
1098 | void | |
2cc07db4 | 1099 | default_stabs_asm_out_constructor (symbol, priority) |
47907859 | 1100 | rtx symbol; |
2cc07db4 | 1101 | int priority ATTRIBUTE_UNUSED; |
79e68feb | 1102 | { |
2cc07db4 RH |
1103 | /* Tell GNU LD that this is part of the static destructor set. |
1104 | This will work for any system that uses stabs, most usefully | |
1105 | aout systems. */ | |
1106 | fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP); | |
1107 | assemble_name (asm_out_file, XSTR (symbol, 0)); | |
1108 | fputc ('\n', asm_out_file); | |
1109 | } | |
47907859 | 1110 | |
2cc07db4 RH |
1111 | void |
1112 | default_named_section_asm_out_constructor (symbol, priority) | |
1113 | rtx symbol; | |
1114 | int priority; | |
1115 | { | |
1116 | const char *section = ".ctors"; | |
1117 | char buf[16]; | |
47907859 | 1118 | |
6d2f8887 | 1119 | /* ??? This only works reliably with the GNU linker. */ |
2cc07db4 | 1120 | if (priority != DEFAULT_INIT_PRIORITY) |
47907859 | 1121 | { |
47907859 RH |
1122 | sprintf (buf, ".ctors.%.5u", |
1123 | /* Invert the numbering so the linker puts us in the proper | |
1124 | order; constructors are run from right to left, and the | |
1125 | linker sorts in increasing order. */ | |
1126 | MAX_INIT_PRIORITY - priority); | |
2cc07db4 | 1127 | section = buf; |
47907859 RH |
1128 | } |
1129 | ||
715bdd29 | 1130 | named_section_flags (section, SECTION_WRITE); |
c8af3574 RH |
1131 | assemble_align (POINTER_SIZE); |
1132 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
2cc07db4 RH |
1133 | } |
1134 | ||
1135 | #ifdef CTORS_SECTION_ASM_OP | |
1136 | void | |
1137 | ctors_section () | |
1138 | { | |
1139 | if (in_section != in_ctors) | |
79e68feb | 1140 | { |
2cc07db4 RH |
1141 | in_section = in_ctors; |
1142 | fputs (CTORS_SECTION_ASM_OP, asm_out_file); | |
79e68feb RS |
1143 | fputc ('\n', asm_out_file); |
1144 | } | |
79e68feb | 1145 | } |
2cc07db4 RH |
1146 | |
1147 | void | |
1148 | default_ctor_section_asm_out_constructor (symbol, priority) | |
1149 | rtx symbol; | |
1150 | int priority ATTRIBUTE_UNUSED; | |
1151 | { | |
1152 | ctors_section (); | |
c8af3574 RH |
1153 | assemble_align (POINTER_SIZE); |
1154 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
2cc07db4 RH |
1155 | } |
1156 | #endif | |
79e68feb | 1157 | \f |
97adc6ed ILT |
1158 | /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with |
1159 | a non-zero value if the constant pool should be output before the | |
1160 | start of the function, or a zero value if the pool should output | |
1161 | after the end of the function. The default is to put it before the | |
1162 | start. */ | |
1163 | ||
1164 | #ifndef CONSTANT_POOL_BEFORE_FUNCTION | |
1165 | #define CONSTANT_POOL_BEFORE_FUNCTION 1 | |
1166 | #endif | |
1167 | ||
79e68feb RS |
1168 | /* Output assembler code for the constant pool of a function and associated |
1169 | with defining the name of the function. DECL describes the function. | |
1170 | NAME is the function's name. For the constant pool, we use the current | |
1171 | constant pool data. */ | |
1172 | ||
1173 | void | |
1174 | assemble_start_function (decl, fnname) | |
1175 | tree decl; | |
3cce094d | 1176 | const char *fnname; |
79e68feb RS |
1177 | { |
1178 | int align; | |
1179 | ||
1180 | /* The following code does not need preprocessing in the assembler. */ | |
1181 | ||
1182 | app_disable (); | |
1183 | ||
97adc6ed ILT |
1184 | if (CONSTANT_POOL_BEFORE_FUNCTION) |
1185 | output_constant_pool (fnname, decl); | |
79e68feb | 1186 | |
1b18fc2c | 1187 | resolve_unique_section (decl, 0, flag_function_sections); |
4d1065ed | 1188 | function_section (decl); |
79e68feb RS |
1189 | |
1190 | /* Tell assembler to move to target machine's alignment for functions. */ | |
1191 | align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT); | |
1192 | if (align > 0) | |
91ea4f8d KG |
1193 | { |
1194 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
1195 | } | |
79e68feb | 1196 | |
efa3896a GK |
1197 | /* Handle a user-specified function alignment. |
1198 | Note that we still need to align to FUNCTION_BOUNDARY, as above, | |
1199 | because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */ | |
194734e9 JH |
1200 | if (align_functions_log > align |
1201 | && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED) | |
efa3896a GK |
1202 | { |
1203 | #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN | |
46f9491e | 1204 | ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, |
c26fbbca | 1205 | align_functions_log, align_functions - 1); |
efa3896a GK |
1206 | #else |
1207 | ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log); | |
1208 | #endif | |
1209 | } | |
1210 | ||
79e68feb RS |
1211 | #ifdef ASM_OUTPUT_FUNCTION_PREFIX |
1212 | ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname); | |
1213 | #endif | |
1214 | ||
653e276c | 1215 | (*debug_hooks->begin_function) (decl); |
79e68feb RS |
1216 | |
1217 | /* Make function name accessible from other files, if appropriate. */ | |
1218 | ||
1219 | if (TREE_PUBLIC (decl)) | |
1220 | { | |
ee830309 | 1221 | if (! first_global_object_name) |
06bb02f7 | 1222 | { |
ec940faa | 1223 | const char *p; |
3b304f5b ZW |
1224 | char *name; |
1225 | ||
1226 | STRIP_NAME_ENCODING (p, fnname); | |
1227 | name = permalloc (strlen (p) + 1); | |
1228 | strcpy (name, p); | |
ee830309 JM |
1229 | |
1230 | if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl)) | |
3b304f5b | 1231 | first_global_object_name = name; |
ee830309 | 1232 | else |
3b304f5b | 1233 | weak_global_object_name = name; |
06bb02f7 RK |
1234 | } |
1235 | ||
19c5b1cf | 1236 | globalize_decl (decl); |
b14707c3 RH |
1237 | |
1238 | maybe_assemble_visibility (decl); | |
79e68feb RS |
1239 | } |
1240 | ||
1241 | /* Do any machine/system dependent processing of the function name */ | |
8bd16853 | 1242 | #ifdef ASM_DECLARE_FUNCTION_NAME |
b93a436e | 1243 | ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl); |
8bd16853 | 1244 | #else |
b93a436e JL |
1245 | /* Standard thing is just output label for the function. */ |
1246 | ASM_OUTPUT_LABEL (asm_out_file, fnname); | |
79e68feb RS |
1247 | #endif /* ASM_DECLARE_FUNCTION_NAME */ |
1248 | } | |
1249 | ||
1250 | /* Output assembler code associated with defining the size of the | |
1251 | function. DECL describes the function. NAME is the function's name. */ | |
1252 | ||
1253 | void | |
1254 | assemble_end_function (decl, fnname) | |
1255 | tree decl; | |
d9bba9c3 | 1256 | const char *fnname; |
79e68feb RS |
1257 | { |
1258 | #ifdef ASM_DECLARE_FUNCTION_SIZE | |
1259 | ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl); | |
1260 | #endif | |
97adc6ed | 1261 | if (! CONSTANT_POOL_BEFORE_FUNCTION) |
83488369 RK |
1262 | { |
1263 | output_constant_pool (fnname, decl); | |
1264 | function_section (decl); /* need to switch back */ | |
1265 | } | |
8839fca4 ILT |
1266 | |
1267 | /* Output any constants which should appear after the function. */ | |
1268 | output_after_function_constants (); | |
79e68feb RS |
1269 | } |
1270 | \f | |
1271 | /* Assemble code to leave SIZE bytes of zeros. */ | |
1272 | ||
1273 | void | |
1274 | assemble_zeros (size) | |
1275 | int size; | |
1276 | { | |
3c350eb3 CB |
1277 | /* Do no output if -fsyntax-only. */ |
1278 | if (flag_syntax_only) | |
1279 | return; | |
1280 | ||
79e68feb RS |
1281 | #ifdef ASM_NO_SKIP_IN_TEXT |
1282 | /* The `space' pseudo in the text section outputs nop insns rather than 0s, | |
1283 | so we must output 0s explicitly in the text section. */ | |
1284 | if (ASM_NO_SKIP_IN_TEXT && in_text_section ()) | |
1285 | { | |
1286 | int i; | |
c8af3574 RH |
1287 | for (i = 0; i < size; i++) |
1288 | assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1); | |
79e68feb RS |
1289 | } |
1290 | else | |
1291 | #endif | |
41fe4d9e | 1292 | if (size > 0) |
b93a436e | 1293 | ASM_OUTPUT_SKIP (asm_out_file, size); |
79e68feb RS |
1294 | } |
1295 | ||
a785e67e RS |
1296 | /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */ |
1297 | ||
1298 | void | |
1299 | assemble_align (align) | |
1300 | int align; | |
1301 | { | |
1302 | if (align > BITS_PER_UNIT) | |
91ea4f8d KG |
1303 | { |
1304 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
1305 | } | |
a785e67e RS |
1306 | } |
1307 | ||
79e68feb RS |
1308 | /* Assemble a string constant with the specified C string as contents. */ |
1309 | ||
1310 | void | |
1311 | assemble_string (p, size) | |
9b3142b3 | 1312 | const char *p; |
79e68feb RS |
1313 | int size; |
1314 | { | |
79e68feb RS |
1315 | int pos = 0; |
1316 | int maximum = 2000; | |
1317 | ||
1318 | /* If the string is very long, split it up. */ | |
1319 | ||
1320 | while (pos < size) | |
1321 | { | |
1322 | int thissize = size - pos; | |
1323 | if (thissize > maximum) | |
1324 | thissize = maximum; | |
1325 | ||
b93a436e | 1326 | ASM_OUTPUT_ASCII (asm_out_file, p, thissize); |
79e68feb RS |
1327 | |
1328 | pos += thissize; | |
1329 | p += thissize; | |
1330 | } | |
1331 | } | |
69249c1b | 1332 | |
79e68feb | 1333 | \f |
b8694195 NC |
1334 | #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL |
1335 | #define ASM_EMIT_LOCAL(decl, name, size, rounded) \ | |
1336 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl)) | |
1337 | #else | |
1338 | #if defined ASM_OUTPUT_ALIGNED_LOCAL | |
1339 | #define ASM_EMIT_LOCAL(decl, name, size, rounded) \ | |
1340 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl)) | |
1341 | #else | |
1342 | #define ASM_EMIT_LOCAL(decl, name, size, rounded) \ | |
1343 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded) | |
1344 | #endif | |
1345 | #endif | |
1346 | ||
1347 | #if defined ASM_OUTPUT_ALIGNED_BSS | |
1348 | #define ASM_EMIT_BSS(decl, name, size, rounded) \ | |
1349 | ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl)) | |
1350 | #else | |
1351 | #if defined ASM_OUTPUT_BSS | |
1352 | #define ASM_EMIT_BSS(decl, name, size, rounded) \ | |
1353 | ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded) | |
1354 | #else | |
1355 | #undef ASM_EMIT_BSS | |
1356 | #endif | |
1357 | #endif | |
1358 | ||
1359 | #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON | |
1360 | #define ASM_EMIT_COMMON(decl, name, size, rounded) \ | |
1361 | ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl)) | |
1362 | #else | |
1363 | #if defined ASM_OUTPUT_ALIGNED_COMMON | |
1364 | #define ASM_EMIT_COMMON(decl, name, size, rounded) \ | |
1365 | ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl)) | |
1366 | #else | |
1367 | #define ASM_EMIT_COMMON(decl, name, size, rounded) \ | |
1368 | ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded) | |
1369 | #endif | |
1370 | #endif | |
1371 | ||
1372 | static void | |
1373 | asm_emit_uninitialised (decl, name, size, rounded) | |
1374 | tree decl; | |
c26fbbca | 1375 | const char *name; |
05b13f59 | 1376 | int size ATTRIBUTE_UNUSED; |
95d75019 | 1377 | int rounded ATTRIBUTE_UNUSED; |
b8694195 | 1378 | { |
a56e7c08 NC |
1379 | enum |
1380 | { | |
b8694195 NC |
1381 | asm_dest_common, |
1382 | asm_dest_bss, | |
1383 | asm_dest_local | |
1384 | } | |
1385 | destination = asm_dest_local; | |
46f9491e | 1386 | |
b8694195 NC |
1387 | if (TREE_PUBLIC (decl)) |
1388 | { | |
1389 | #if defined ASM_EMIT_BSS | |
1390 | if (! DECL_COMMON (decl)) | |
1391 | destination = asm_dest_bss; | |
1392 | else | |
46f9491e | 1393 | #endif |
b8694195 NC |
1394 | destination = asm_dest_common; |
1395 | } | |
1396 | ||
1bd6476f RH |
1397 | if (destination == asm_dest_bss) |
1398 | globalize_decl (decl); | |
1b18fc2c | 1399 | resolve_unique_section (decl, 0, flag_data_sections); |
ecb0eece | 1400 | |
b8694195 NC |
1401 | if (flag_shared_data) |
1402 | { | |
1403 | switch (destination) | |
1404 | { | |
1405 | #ifdef ASM_OUTPUT_SHARED_BSS | |
1406 | case asm_dest_bss: | |
1407 | ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded); | |
1408 | return; | |
1409 | #endif | |
1410 | #ifdef ASM_OUTPUT_SHARED_COMMON | |
1411 | case asm_dest_common: | |
1412 | ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded); | |
1413 | return; | |
1414 | #endif | |
1415 | #ifdef ASM_OUTPUT_SHARED_LOCAL | |
1416 | case asm_dest_local: | |
1417 | ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded); | |
1418 | return; | |
1419 | #endif | |
1420 | default: | |
1421 | break; | |
1422 | } | |
1423 | } | |
1424 | ||
1425 | switch (destination) | |
1426 | { | |
1427 | #ifdef ASM_EMIT_BSS | |
1428 | case asm_dest_bss: | |
1429 | ASM_EMIT_BSS (decl, name, size, rounded); | |
1430 | break; | |
1431 | #endif | |
1432 | case asm_dest_common: | |
1433 | ASM_EMIT_COMMON (decl, name, size, rounded); | |
1434 | break; | |
1435 | case asm_dest_local: | |
1436 | ASM_EMIT_LOCAL (decl, name, size, rounded); | |
1437 | break; | |
1438 | default: | |
1439 | abort (); | |
1440 | } | |
1441 | ||
1442 | return; | |
1443 | } | |
1444 | ||
79e68feb RS |
1445 | /* Assemble everything that is needed for a variable or function declaration. |
1446 | Not used for automatic variables, and not used for function definitions. | |
1447 | Should not be called for variables of incomplete structure type. | |
1448 | ||
1449 | TOP_LEVEL is nonzero if this variable has file scope. | |
1450 | AT_END is nonzero if this is the special handling, at end of compilation, | |
ff8f4401 RS |
1451 | to define things that have had only tentative definitions. |
1452 | DONT_OUTPUT_DATA if nonzero means don't actually output the | |
1453 | initial value (that will be done by the caller). */ | |
79e68feb RS |
1454 | |
1455 | void | |
ff8f4401 | 1456 | assemble_variable (decl, top_level, at_end, dont_output_data) |
79e68feb | 1457 | tree decl; |
c84e2712 | 1458 | int top_level ATTRIBUTE_UNUSED; |
95d75019 | 1459 | int at_end ATTRIBUTE_UNUSED; |
5a13eaa4 | 1460 | int dont_output_data; |
79e68feb | 1461 | { |
b3694847 | 1462 | const char *name; |
f8344bea | 1463 | unsigned int align; |
79e68feb | 1464 | int reloc = 0; |
17eee61c | 1465 | rtx decl_rtl; |
79e68feb | 1466 | |
cbed4565 RS |
1467 | last_assemble_variable_decl = 0; |
1468 | ||
d36d70cc | 1469 | /* Normally no need to say anything here for external references, |
9faa82d8 | 1470 | since assemble_external is called by the language-specific code |
d36d70cc | 1471 | when a declaration is first seen. */ |
79e68feb | 1472 | |
44fe2e80 | 1473 | if (DECL_EXTERNAL (decl)) |
79e68feb RS |
1474 | return; |
1475 | ||
1476 | /* Output no assembler code for a function declaration. | |
1477 | Only definitions of functions output anything. */ | |
1478 | ||
1479 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1480 | return; | |
1481 | ||
3914abb4 NB |
1482 | /* Do nothing for global register variables. */ |
1483 | if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG) | |
1484 | { | |
1485 | TREE_ASM_WRITTEN (decl) = 1; | |
1486 | return; | |
1487 | } | |
1488 | ||
79e68feb RS |
1489 | /* If type was incomplete when the variable was declared, |
1490 | see if it is complete now. */ | |
1491 | ||
1492 | if (DECL_SIZE (decl) == 0) | |
1493 | layout_decl (decl, 0); | |
1494 | ||
1495 | /* Still incomplete => don't allocate it; treat the tentative defn | |
1496 | (which is what it must have been) as an `extern' reference. */ | |
1497 | ||
ff8f4401 | 1498 | if (!dont_output_data && DECL_SIZE (decl) == 0) |
79e68feb RS |
1499 | { |
1500 | error_with_file_and_line (DECL_SOURCE_FILE (decl), | |
1501 | DECL_SOURCE_LINE (decl), | |
ea80ee44 | 1502 | "storage size of `%s' isn't known", |
79e68feb | 1503 | IDENTIFIER_POINTER (DECL_NAME (decl))); |
1c1a7ba4 | 1504 | TREE_ASM_WRITTEN (decl) = 1; |
79e68feb RS |
1505 | return; |
1506 | } | |
1507 | ||
1508 | /* The first declaration of a variable that comes through this function | |
1509 | decides whether it is global (in C, has external linkage) | |
1510 | or local (in C, has internal linkage). So do nothing more | |
1511 | if this function has already run. */ | |
1512 | ||
1513 | if (TREE_ASM_WRITTEN (decl)) | |
1514 | return; | |
1515 | ||
17eee61c RH |
1516 | /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */ |
1517 | decl_rtl = DECL_RTL (decl); | |
46f9491e | 1518 | |
79e68feb RS |
1519 | TREE_ASM_WRITTEN (decl) = 1; |
1520 | ||
3c350eb3 CB |
1521 | /* Do no output if -fsyntax-only. */ |
1522 | if (flag_syntax_only) | |
1523 | return; | |
1524 | ||
809d6575 | 1525 | app_disable (); |
79e68feb | 1526 | |
770ae6cc RK |
1527 | if (! dont_output_data |
1528 | && ! host_integerp (DECL_SIZE_UNIT (decl), 1)) | |
ff8f4401 | 1529 | { |
770ae6cc | 1530 | error_with_decl (decl, "size of variable `%s' is too large"); |
544f03b4 | 1531 | return; |
79e68feb RS |
1532 | } |
1533 | ||
17eee61c | 1534 | name = XSTR (XEXP (decl_rtl, 0), 0); |
f796d997 JM |
1535 | if (TREE_PUBLIC (decl) && DECL_NAME (decl) |
1536 | && ! first_global_object_name | |
1537 | && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0 | |
1538 | || DECL_INITIAL (decl) == error_mark_node)) | |
1539 | && ! DECL_WEAK (decl) | |
1540 | && ! DECL_ONE_ONLY (decl)) | |
1541 | { | |
ec940faa | 1542 | const char *p; |
3b304f5b | 1543 | char *xname; |
f796d997 JM |
1544 | |
1545 | STRIP_NAME_ENCODING (p, name); | |
3b304f5b ZW |
1546 | xname = permalloc (strlen (p) + 1); |
1547 | strcpy (xname, p); | |
1548 | first_global_object_name = xname; | |
f796d997 JM |
1549 | } |
1550 | ||
8a198bd2 JW |
1551 | /* Compute the alignment of this data. */ |
1552 | ||
1553 | align = DECL_ALIGN (decl); | |
1554 | ||
1555 | /* In the case for initialing an array whose length isn't specified, | |
1556 | where we have not yet been able to do the layout, | |
1557 | figure out the proper alignment now. */ | |
1558 | if (dont_output_data && DECL_SIZE (decl) == 0 | |
1559 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
1560 | align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))); | |
1561 | ||
1562 | /* Some object file formats have a maximum alignment which they support. | |
1563 | In particular, a.out format supports a maximum alignment of 4. */ | |
1564 | #ifndef MAX_OFILE_ALIGNMENT | |
1565 | #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT | |
1566 | #endif | |
1567 | if (align > MAX_OFILE_ALIGNMENT) | |
1568 | { | |
1569 | warning_with_decl (decl, | |
357351e5 | 1570 | "alignment of `%s' is greater than maximum object file alignment. Using %d", |
44ec7e59 | 1571 | MAX_OFILE_ALIGNMENT/BITS_PER_UNIT); |
8a198bd2 JW |
1572 | align = MAX_OFILE_ALIGNMENT; |
1573 | } | |
1574 | ||
1575 | /* On some machines, it is good to increase alignment sometimes. */ | |
51084e13 RH |
1576 | if (! DECL_USER_ALIGN (decl)) |
1577 | { | |
8a198bd2 | 1578 | #ifdef DATA_ALIGNMENT |
51084e13 | 1579 | align = DATA_ALIGNMENT (TREE_TYPE (decl), align); |
8a198bd2 JW |
1580 | #endif |
1581 | #ifdef CONSTANT_ALIGNMENT | |
51084e13 RH |
1582 | if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node) |
1583 | align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align); | |
8a198bd2 | 1584 | #endif |
51084e13 | 1585 | } |
8a198bd2 JW |
1586 | |
1587 | /* Reset the alignment in case we have made it tighter, so we can benefit | |
1588 | from it in get_pointer_alignment. */ | |
1589 | DECL_ALIGN (decl) = align; | |
c952ff4b | 1590 | set_mem_align (decl_rtl, align); |
8a198bd2 | 1591 | |
b14707c3 RH |
1592 | if (TREE_PUBLIC (decl)) |
1593 | maybe_assemble_visibility (decl); | |
1594 | ||
15409448 JM |
1595 | /* Output any data that we will need to use the address of. */ |
1596 | if (DECL_INITIAL (decl) == error_mark_node) | |
1597 | reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0; | |
1598 | else if (DECL_INITIAL (decl)) | |
1599 | reloc = output_addressed_constants (DECL_INITIAL (decl)); | |
d88a8ff5 | 1600 | resolve_unique_section (decl, reloc, flag_data_sections); |
15409448 | 1601 | |
79e68feb RS |
1602 | /* Handle uninitialized definitions. */ |
1603 | ||
27b41650 KG |
1604 | if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node |
1605 | #if defined ASM_EMIT_BSS | |
1606 | || (flag_zero_initialized_in_bss | |
1607 | && initializer_zerop (DECL_INITIAL (decl))) | |
1608 | #endif | |
1609 | ) | |
e5887033 DE |
1610 | /* If the target can't output uninitialized but not common global data |
1611 | in .bss, then we have to use .data. */ | |
b8694195 | 1612 | #if ! defined ASM_EMIT_BSS |
cd98bf12 | 1613 | && DECL_COMMON (decl) |
e5887033 | 1614 | #endif |
a56e7c08 | 1615 | && DECL_SECTION_NAME (decl) == NULL_TREE |
e5887033 | 1616 | && ! dont_output_data) |
79e68feb | 1617 | { |
770ae6cc RK |
1618 | unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); |
1619 | unsigned HOST_WIDE_INT rounded = size; | |
79e68feb | 1620 | |
79e68feb RS |
1621 | /* Don't allocate zero bytes of common, |
1622 | since that means "undefined external" in the linker. */ | |
770ae6cc RK |
1623 | if (size == 0) |
1624 | rounded = 1; | |
1625 | ||
79e68feb RS |
1626 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits |
1627 | so that each uninitialized object starts on such a boundary. */ | |
1628 | rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; | |
1629 | rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
1630 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
46f9491e | 1631 | |
ec1bff50 HPN |
1632 | /* Don't continue this line--convex cc version 4.1 would lose. */ |
1633 | #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS) | |
4cf7705a | 1634 | if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded) |
46f9491e | 1635 | warning_with_decl |
357351e5 | 1636 | (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded); |
4bcfa7a8 | 1637 | #endif |
46f9491e | 1638 | |
b8694195 | 1639 | asm_emit_uninitialised (decl, name, size, rounded); |
e5887033 | 1640 | |
544f03b4 | 1641 | return; |
79e68feb RS |
1642 | } |
1643 | ||
e5887033 DE |
1644 | /* Handle initialized definitions. |
1645 | Also handle uninitialized global definitions if -fno-common and the | |
1646 | target doesn't support ASM_OUTPUT_BSS. */ | |
79e68feb RS |
1647 | |
1648 | /* First make the assembler name(s) global if appropriate. */ | |
1649 | if (TREE_PUBLIC (decl) && DECL_NAME (decl)) | |
19c5b1cf | 1650 | globalize_decl (decl); |
79e68feb | 1651 | |
f9da1f35 DE |
1652 | /* Switch to the appropriate section. */ |
1653 | variable_section (decl, reloc); | |
79e68feb | 1654 | |
a8e2f179 RS |
1655 | /* dbxout.c needs to know this. */ |
1656 | if (in_text_section ()) | |
1657 | DECL_IN_TEXT_SECTION (decl) = 1; | |
1658 | ||
8a198bd2 | 1659 | /* Output the alignment of this data. */ |
79e68feb | 1660 | if (align > BITS_PER_UNIT) |
91ea4f8d KG |
1661 | { |
1662 | ASM_OUTPUT_ALIGN (asm_out_file, | |
1663 | floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT)); | |
1664 | } | |
79e68feb RS |
1665 | |
1666 | /* Do any machine/system dependent processing of the object. */ | |
8bd16853 | 1667 | #ifdef ASM_DECLARE_OBJECT_NAME |
b93a436e JL |
1668 | last_assemble_variable_decl = decl; |
1669 | ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl); | |
8bd16853 | 1670 | #else |
b93a436e JL |
1671 | /* Standard thing is just output label for the object. */ |
1672 | ASM_OUTPUT_LABEL (asm_out_file, name); | |
79e68feb RS |
1673 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
1674 | ||
ff8f4401 | 1675 | if (!dont_output_data) |
79e68feb | 1676 | { |
15409448 | 1677 | if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node) |
ff8f4401 | 1678 | /* Output the actual data. */ |
770ae6cc | 1679 | output_constant (DECL_INITIAL (decl), |
c8af3574 RH |
1680 | tree_low_cst (DECL_SIZE_UNIT (decl), 1), |
1681 | align); | |
ff8f4401 RS |
1682 | else |
1683 | /* Leave space for it. */ | |
770ae6cc | 1684 | assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1)); |
79e68feb | 1685 | } |
79e68feb RS |
1686 | } |
1687 | ||
2e9effae RS |
1688 | /* Return 1 if type TYPE contains any pointers. */ |
1689 | ||
1690 | static int | |
1691 | contains_pointers_p (type) | |
1692 | tree type; | |
1693 | { | |
1694 | switch (TREE_CODE (type)) | |
1695 | { | |
1696 | case POINTER_TYPE: | |
1697 | case REFERENCE_TYPE: | |
1698 | /* I'm not sure whether OFFSET_TYPE needs this treatment, | |
1699 | so I'll play safe and return 1. */ | |
1700 | case OFFSET_TYPE: | |
1701 | return 1; | |
1702 | ||
1703 | case RECORD_TYPE: | |
1704 | case UNION_TYPE: | |
1705 | case QUAL_UNION_TYPE: | |
1706 | { | |
1707 | tree fields; | |
1708 | /* For a type that has fields, see if the fields have pointers. */ | |
1709 | for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) | |
ce49ea8a JM |
1710 | if (TREE_CODE (fields) == FIELD_DECL |
1711 | && contains_pointers_p (TREE_TYPE (fields))) | |
2e9effae RS |
1712 | return 1; |
1713 | return 0; | |
1714 | } | |
1715 | ||
1716 | case ARRAY_TYPE: | |
1717 | /* An array type contains pointers if its element type does. */ | |
1718 | return contains_pointers_p (TREE_TYPE (type)); | |
1719 | ||
1720 | default: | |
1721 | return 0; | |
1722 | } | |
1723 | } | |
1724 | ||
79e68feb | 1725 | /* Output something to declare an external symbol to the assembler. |
fff9e713 MT |
1726 | (Most assemblers don't need this, so we normally output nothing.) |
1727 | Do nothing if DECL is not external. */ | |
79e68feb RS |
1728 | |
1729 | void | |
1730 | assemble_external (decl) | |
91813b28 | 1731 | tree decl ATTRIBUTE_UNUSED; |
79e68feb | 1732 | { |
e6855a2d MM |
1733 | /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the |
1734 | main body of this code is only rarely exercised. To provide some | |
1735 | testing, on all platforms, we make sure that the ASM_OUT_FILE is | |
1736 | open. If it's not, we should not be calling this function. */ | |
1737 | if (!asm_out_file) | |
1738 | abort (); | |
1739 | ||
79e68feb | 1740 | #ifdef ASM_OUTPUT_EXTERNAL |
2f939d94 | 1741 | if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) |
79e68feb | 1742 | { |
fff9e713 MT |
1743 | rtx rtl = DECL_RTL (decl); |
1744 | ||
1745 | if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF | |
1746 | && ! SYMBOL_REF_USED (XEXP (rtl, 0))) | |
1747 | { | |
1748 | /* Some systems do require some output. */ | |
1749 | SYMBOL_REF_USED (XEXP (rtl, 0)) = 1; | |
1750 | ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0)); | |
1751 | } | |
79e68feb RS |
1752 | } |
1753 | #endif | |
1754 | } | |
1755 | ||
1756 | /* Similar, for calling a library function FUN. */ | |
1757 | ||
1758 | void | |
1759 | assemble_external_libcall (fun) | |
c84e2712 | 1760 | rtx fun ATTRIBUTE_UNUSED; |
79e68feb RS |
1761 | { |
1762 | #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL | |
b93a436e JL |
1763 | /* Declare library function name external when first used, if nec. */ |
1764 | if (! SYMBOL_REF_USED (fun)) | |
79e68feb | 1765 | { |
b93a436e JL |
1766 | SYMBOL_REF_USED (fun) = 1; |
1767 | ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun); | |
79e68feb RS |
1768 | } |
1769 | #endif | |
1770 | } | |
1771 | ||
1772 | /* Declare the label NAME global. */ | |
1773 | ||
1774 | void | |
1775 | assemble_global (name) | |
e59f7d3d | 1776 | const char *name ATTRIBUTE_UNUSED; |
79e68feb RS |
1777 | { |
1778 | ASM_GLOBALIZE_LABEL (asm_out_file, name); | |
1779 | } | |
1780 | ||
1781 | /* Assemble a label named NAME. */ | |
1782 | ||
1783 | void | |
1784 | assemble_label (name) | |
d9bba9c3 | 1785 | const char *name; |
79e68feb | 1786 | { |
b93a436e | 1787 | ASM_OUTPUT_LABEL (asm_out_file, name); |
79e68feb RS |
1788 | } |
1789 | ||
1790 | /* Output to FILE a reference to the assembler name of a C-level name NAME. | |
1791 | If NAME starts with a *, the rest of NAME is output verbatim. | |
1792 | Otherwise NAME is transformed in an implementation-defined way | |
1793 | (usually by the addition of an underscore). | |
1794 | Many macros in the tm file are defined to call this function. */ | |
1795 | ||
1796 | void | |
1797 | assemble_name (file, name) | |
1798 | FILE *file; | |
ec940faa | 1799 | const char *name; |
79e68feb | 1800 | { |
ec940faa | 1801 | const char *real_name; |
a94dbf2c | 1802 | tree id; |
648fb7cf RK |
1803 | |
1804 | STRIP_NAME_ENCODING (real_name, name); | |
87907387 | 1805 | |
a94dbf2c JM |
1806 | id = maybe_get_identifier (real_name); |
1807 | if (id) | |
1808 | TREE_SYMBOL_REFERENCED (id) = 1; | |
03e42132 | 1809 | |
79e68feb | 1810 | if (name[0] == '*') |
b93a436e | 1811 | fputs (&name[1], file); |
79e68feb | 1812 | else |
86aff125 | 1813 | ASM_OUTPUT_LABELREF (file, name); |
79e68feb RS |
1814 | } |
1815 | ||
1816 | /* Allocate SIZE bytes writable static space with a gensym name | |
1817 | and return an RTX to refer to its address. */ | |
1818 | ||
1819 | rtx | |
1820 | assemble_static_space (size) | |
1821 | int size; | |
1822 | { | |
1823 | char name[12]; | |
520a57c8 | 1824 | const char *namestring; |
79e68feb | 1825 | rtx x; |
79e68feb RS |
1826 | |
1827 | #if 0 | |
1828 | if (flag_shared_data) | |
1829 | data_section (); | |
1830 | #endif | |
1831 | ||
1832 | ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno); | |
1833 | ++const_labelno; | |
a8a05998 | 1834 | namestring = ggc_strdup (name); |
79e68feb | 1835 | |
b93a436e | 1836 | x = gen_rtx_SYMBOL_REF (Pmode, namestring); |
ca695ac9 | 1837 | |
e9a25f70 | 1838 | #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL |
b93a436e JL |
1839 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size, |
1840 | BIGGEST_ALIGNMENT); | |
e9a25f70 | 1841 | #else |
79e68feb | 1842 | #ifdef ASM_OUTPUT_ALIGNED_LOCAL |
b93a436e | 1843 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT); |
79e68feb | 1844 | #else |
e016950d KG |
1845 | { |
1846 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits | |
1847 | so that each uninitialized object starts on such a boundary. */ | |
2d76cb1a | 1848 | /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */ |
47c3ed98 KG |
1849 | int rounded ATTRIBUTE_UNUSED |
1850 | = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1) | |
1851 | / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
1852 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
e016950d KG |
1853 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
1854 | } | |
e9a25f70 | 1855 | #endif |
79e68feb RS |
1856 | #endif |
1857 | return x; | |
1858 | } | |
1859 | ||
1860 | /* Assemble the static constant template for function entry trampolines. | |
1861 | This is done at most once per compilation. | |
1862 | Returns an RTX for the address of the template. */ | |
1863 | ||
f0e969bd | 1864 | #ifdef TRAMPOLINE_TEMPLATE |
79e68feb RS |
1865 | rtx |
1866 | assemble_trampoline_template () | |
1867 | { | |
1868 | char label[256]; | |
fc608b03 | 1869 | const char *name; |
79e68feb RS |
1870 | int align; |
1871 | ||
37552631 | 1872 | /* By default, put trampoline templates in read-only data section. */ |
f49acdb4 | 1873 | |
37552631 RS |
1874 | #ifdef TRAMPOLINE_SECTION |
1875 | TRAMPOLINE_SECTION (); | |
1876 | #else | |
c8c29f85 | 1877 | readonly_data_section (); |
37552631 | 1878 | #endif |
f49acdb4 | 1879 | |
79e68feb | 1880 | /* Write the assembler code to define one. */ |
073b0524 | 1881 | align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); |
79e68feb | 1882 | if (align > 0) |
91ea4f8d KG |
1883 | { |
1884 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
1885 | } | |
79e68feb RS |
1886 | |
1887 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0); | |
1888 | TRAMPOLINE_TEMPLATE (asm_out_file); | |
1889 | ||
1890 | /* Record the rtl to refer to it. */ | |
1891 | ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0); | |
a8a05998 | 1892 | name = ggc_strdup (label); |
38a448ca | 1893 | return gen_rtx_SYMBOL_REF (Pmode, name); |
79e68feb | 1894 | } |
f0e969bd | 1895 | #endif |
79e68feb | 1896 | \f |
c8af3574 RH |
1897 | /* A and B are either alignments or offsets. Return the minimum alignment |
1898 | that may be assumed after adding the two together. */ | |
1899 | ||
1900 | static inline unsigned | |
1901 | min_align (a, b) | |
1902 | unsigned int a, b; | |
1903 | { | |
1904 | return (a | b) & -(a | b); | |
1905 | } | |
79e68feb | 1906 | |
301d03af RS |
1907 | /* Return the assembler directive for creating a given kind of integer |
1908 | object. SIZE is the number of bytes in the object and ALIGNED_P | |
1909 | indicates whether it is known to be aligned. Return NULL if the | |
1910 | assembly dialect has no such directive. | |
79e68feb | 1911 | |
301d03af RS |
1912 | The returned string should be printed at the start of a new line and |
1913 | be followed immediately by the object's initial value. */ | |
1914 | ||
1915 | const char * | |
1916 | integer_asm_op (size, aligned_p) | |
1917 | int size; | |
1918 | int aligned_p; | |
79e68feb | 1919 | { |
301d03af | 1920 | struct asm_int_op *ops; |
79e68feb | 1921 | |
301d03af RS |
1922 | if (aligned_p) |
1923 | ops = &targetm.asm_out.aligned_op; | |
c8af3574 | 1924 | else |
301d03af RS |
1925 | ops = &targetm.asm_out.unaligned_op; |
1926 | ||
1927 | switch (size) | |
c8af3574 | 1928 | { |
301d03af RS |
1929 | case 1: |
1930 | return targetm.asm_out.byte_op; | |
1931 | case 2: | |
1932 | return ops->hi; | |
1933 | case 4: | |
1934 | return ops->si; | |
1935 | case 8: | |
1936 | return ops->di; | |
1937 | case 16: | |
1938 | return ops->ti; | |
1939 | default: | |
1940 | return NULL; | |
1941 | } | |
1942 | } | |
c8af3574 | 1943 | |
301d03af RS |
1944 | /* Use directive OP to assemble an integer object X. Print OP at the |
1945 | start of the line, followed immediately by the value of X. */ | |
c8af3574 | 1946 | |
301d03af RS |
1947 | void |
1948 | assemble_integer_with_op (op, x) | |
1949 | const char *op; | |
1950 | rtx x; | |
1951 | { | |
1952 | fputs (op, asm_out_file); | |
1953 | output_addr_const (asm_out_file, x); | |
1954 | fputc ('\n', asm_out_file); | |
1955 | } | |
79e68feb | 1956 | |
301d03af | 1957 | /* The default implementation of the asm_out.integer target hook. */ |
79e68feb | 1958 | |
301d03af RS |
1959 | bool |
1960 | default_assemble_integer (x, size, aligned_p) | |
1961 | rtx x ATTRIBUTE_UNUSED; | |
1962 | unsigned int size ATTRIBUTE_UNUSED; | |
1963 | int aligned_p ATTRIBUTE_UNUSED; | |
1964 | { | |
1965 | const char *op = integer_asm_op (size, aligned_p); | |
1966 | return op && (assemble_integer_with_op (op, x), true); | |
1967 | } | |
79e68feb | 1968 | |
301d03af RS |
1969 | /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is |
1970 | the alignment of the integer in bits. Return 1 if we were able to output | |
1971 | the constant, otherwise 0. If FORCE is non-zero, abort if we can't output | |
1972 | the constant. */ | |
79e68feb | 1973 | |
301d03af RS |
1974 | bool |
1975 | assemble_integer (x, size, align, force) | |
1976 | rtx x; | |
1977 | unsigned int size; | |
1978 | unsigned int align; | |
1979 | int force; | |
1980 | { | |
1981 | int aligned_p; | |
79e68feb | 1982 | |
301d03af | 1983 | aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT)); |
79e68feb | 1984 | |
301d03af RS |
1985 | /* See if the target hook can handle this kind of object. */ |
1986 | if ((*targetm.asm_out.integer) (x, size, aligned_p)) | |
1987 | return true; | |
79e68feb | 1988 | |
301d03af RS |
1989 | /* If the object is a multi-byte one, try splitting it up. Split |
1990 | it into words it if is multi-word, otherwise split it into bytes. */ | |
1991 | if (size > 1) | |
c8af3574 RH |
1992 | { |
1993 | enum machine_mode omode, imode; | |
301d03af RS |
1994 | unsigned int subalign; |
1995 | unsigned int subsize, i; | |
46f9491e | 1996 | |
301d03af RS |
1997 | subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1; |
1998 | subalign = MIN (align, subsize * BITS_PER_UNIT); | |
1999 | omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0); | |
c8af3574 RH |
2000 | imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); |
2001 | ||
301d03af | 2002 | for (i = 0; i < size; i += subsize) |
c8af3574 | 2003 | { |
301d03af RS |
2004 | rtx partial = simplify_subreg (omode, x, imode, i); |
2005 | if (!partial || !assemble_integer (partial, subsize, subalign, 0)) | |
c8af3574 RH |
2006 | break; |
2007 | } | |
c8af3574 | 2008 | if (i == size) |
301d03af RS |
2009 | return true; |
2010 | ||
2011 | /* If we've printed some of it, but not all of it, there's no going | |
2012 | back now. */ | |
c8af3574 RH |
2013 | if (i > 0) |
2014 | abort (); | |
2015 | } | |
2016 | ||
79e68feb RS |
2017 | if (force) |
2018 | abort (); | |
2019 | ||
301d03af | 2020 | return false; |
79e68feb RS |
2021 | } |
2022 | \f | |
82af613f RH |
2023 | void |
2024 | assemble_real (d, mode, align) | |
2025 | REAL_VALUE_TYPE d; | |
2026 | enum machine_mode mode; | |
2027 | unsigned int align; | |
94aca342 | 2028 | { |
82af613f RH |
2029 | long data[4]; |
2030 | long l; | |
2031 | unsigned int nalign = min_align (align, 32); | |
79e68feb | 2032 | |
82af613f | 2033 | switch (BITS_PER_UNIT) |
79e68feb | 2034 | { |
82af613f RH |
2035 | case 8: |
2036 | switch (mode) | |
2037 | { | |
2038 | case SFmode: | |
2039 | REAL_VALUE_TO_TARGET_SINGLE (d, l); | |
2040 | assemble_integer (GEN_INT (l), 4, align, 1); | |
2041 | break; | |
2042 | case DFmode: | |
2043 | REAL_VALUE_TO_TARGET_DOUBLE (d, data); | |
2044 | assemble_integer (GEN_INT (data[0]), 4, align, 1); | |
2045 | assemble_integer (GEN_INT (data[1]), 4, nalign, 1); | |
2046 | break; | |
2047 | case XFmode: | |
2048 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data); | |
2049 | assemble_integer (GEN_INT (data[0]), 4, align, 1); | |
2050 | assemble_integer (GEN_INT (data[1]), 4, nalign, 1); | |
2051 | assemble_integer (GEN_INT (data[2]), 4, nalign, 1); | |
2052 | break; | |
2053 | case TFmode: | |
2054 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data); | |
2055 | assemble_integer (GEN_INT (data[0]), 4, align, 1); | |
2056 | assemble_integer (GEN_INT (data[1]), 4, nalign, 1); | |
2057 | assemble_integer (GEN_INT (data[2]), 4, nalign, 1); | |
2058 | assemble_integer (GEN_INT (data[3]), 4, nalign, 1); | |
2059 | break; | |
2060 | default: | |
2061 | abort (); | |
2062 | } | |
79e68feb | 2063 | break; |
79e68feb | 2064 | |
82af613f RH |
2065 | case 16: |
2066 | switch (mode) | |
2067 | { | |
2068 | case HFmode: | |
2069 | REAL_VALUE_TO_TARGET_SINGLE (d, l); | |
2070 | assemble_integer (GEN_INT (l), 2, align, 1); | |
2071 | break; | |
2072 | case TQFmode: | |
2073 | REAL_VALUE_TO_TARGET_DOUBLE (d, data); | |
2074 | assemble_integer (GEN_INT (data[0]), 2, align, 1); | |
2075 | assemble_integer (GEN_INT (data[1]), 1, nalign, 1); | |
2076 | break; | |
2077 | default: | |
2078 | abort (); | |
2079 | } | |
79e68feb | 2080 | break; |
79e68feb | 2081 | |
82af613f RH |
2082 | case 32: |
2083 | switch (mode) | |
2084 | { | |
2085 | case QFmode: | |
2086 | REAL_VALUE_TO_TARGET_SINGLE (d, l); | |
2087 | assemble_integer (GEN_INT (l), 1, align, 1); | |
2088 | break; | |
2089 | case HFmode: | |
2090 | REAL_VALUE_TO_TARGET_DOUBLE (d, data); | |
2091 | assemble_integer (GEN_INT (data[0]), 1, align, 1); | |
2092 | assemble_integer (GEN_INT (data[1]), 1, nalign, 1); | |
2093 | break; | |
2094 | default: | |
2095 | abort (); | |
2096 | } | |
79e68feb | 2097 | break; |
79e68feb RS |
2098 | |
2099 | default: | |
2100 | abort (); | |
2101 | } | |
94aca342 | 2102 | } |
79e68feb | 2103 | \f |
79e68feb RS |
2104 | /* Given an expression EXP with a constant value, |
2105 | reduce it to the sum of an assembler symbol and an integer. | |
2106 | Store them both in the structure *VALUE. | |
2107 | Abort if EXP does not reduce. */ | |
2108 | ||
2109 | struct addr_const | |
2110 | { | |
2111 | rtx base; | |
fb351073 | 2112 | HOST_WIDE_INT offset; |
79e68feb RS |
2113 | }; |
2114 | ||
2115 | static void | |
2116 | decode_addr_const (exp, value) | |
2117 | tree exp; | |
2118 | struct addr_const *value; | |
2119 | { | |
b3694847 SS |
2120 | tree target = TREE_OPERAND (exp, 0); |
2121 | int offset = 0; | |
2122 | rtx x; | |
79e68feb RS |
2123 | |
2124 | while (1) | |
2125 | { | |
2126 | if (TREE_CODE (target) == COMPONENT_REF | |
770ae6cc | 2127 | && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0)) |
665f2503 | 2128 | |
79e68feb | 2129 | { |
770ae6cc | 2130 | offset += int_byte_position (TREE_OPERAND (target, 1)); |
79e68feb RS |
2131 | target = TREE_OPERAND (target, 0); |
2132 | } | |
b4e3fabb RK |
2133 | else if (TREE_CODE (target) == ARRAY_REF |
2134 | || TREE_CODE (target) == ARRAY_RANGE_REF) | |
79e68feb | 2135 | { |
770ae6cc RK |
2136 | offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1) |
2137 | * tree_low_cst (TREE_OPERAND (target, 1), 0)); | |
79e68feb RS |
2138 | target = TREE_OPERAND (target, 0); |
2139 | } | |
2140 | else | |
2141 | break; | |
2142 | } | |
2143 | ||
2144 | switch (TREE_CODE (target)) | |
2145 | { | |
2146 | case VAR_DECL: | |
2147 | case FUNCTION_DECL: | |
2148 | x = DECL_RTL (target); | |
2149 | break; | |
2150 | ||
2151 | case LABEL_DECL: | |
b93a436e JL |
2152 | x = gen_rtx_MEM (FUNCTION_MODE, |
2153 | gen_rtx_LABEL_REF (VOIDmode, | |
2154 | label_rtx (TREE_OPERAND (exp, 0)))); | |
79e68feb RS |
2155 | break; |
2156 | ||
2157 | case REAL_CST: | |
2158 | case STRING_CST: | |
2159 | case COMPLEX_CST: | |
2160 | case CONSTRUCTOR: | |
2cf55b55 | 2161 | case INTEGER_CST: |
44e3910a RK |
2162 | /* This constant should have been output already, but we can't simply |
2163 | use TREE_CST_RTL since INTEGER_CST doesn't have one. */ | |
2164 | x = output_constant_def (target, 1); | |
79e68feb RS |
2165 | break; |
2166 | ||
2167 | default: | |
2168 | abort (); | |
2169 | } | |
2170 | ||
b93a436e JL |
2171 | if (GET_CODE (x) != MEM) |
2172 | abort (); | |
2173 | x = XEXP (x, 0); | |
79e68feb RS |
2174 | |
2175 | value->base = x; | |
2176 | value->offset = offset; | |
2177 | } | |
2178 | \f | |
69ef87e2 AH |
2179 | /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */ |
2180 | enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_INT, RTX_VECTOR, RTX_UNSPEC }; | |
1f8f4a0b MM |
2181 | struct rtx_const |
2182 | { | |
9612ab65 ZW |
2183 | ENUM_BITFIELD(kind) kind : 16; |
2184 | ENUM_BITFIELD(machine_mode) mode : 16; | |
1f8f4a0b | 2185 | union { |
b216cd4a | 2186 | REAL_VALUE_TYPE du; |
1f8f4a0b MM |
2187 | struct addr_const addr; |
2188 | struct {HOST_WIDE_INT high, low;} di; | |
69ef87e2 AH |
2189 | |
2190 | /* The max vector size we have is 8 wide. This should be enough. */ | |
2191 | HOST_WIDE_INT veclo[16]; | |
2192 | HOST_WIDE_INT vechi[16]; | |
1f8f4a0b MM |
2193 | } un; |
2194 | }; | |
2195 | ||
79e68feb RS |
2196 | /* Uniquize all constants that appear in memory. |
2197 | Each constant in memory thus far output is recorded | |
2198 | in `const_hash_table' with a `struct constant_descriptor' | |
2199 | that contains a polish representation of the value of | |
2200 | the constant. | |
2201 | ||
2202 | We cannot store the trees in the hash table | |
2203 | because the trees may be temporary. */ | |
2204 | ||
2205 | struct constant_descriptor | |
2206 | { | |
2207 | struct constant_descriptor *next; | |
520a57c8 | 2208 | const char *label; |
14a774a9 | 2209 | rtx rtl; |
37357796 | 2210 | /* Make sure the data is reasonably aligned. */ |
46f9491e | 2211 | union |
37357796 RE |
2212 | { |
2213 | unsigned char contents[1]; | |
2214 | #ifdef HAVE_LONG_DOUBLE | |
2215 | long double d; | |
2216 | #else | |
2217 | double d; | |
2218 | #endif | |
2219 | } u; | |
79e68feb RS |
2220 | }; |
2221 | ||
2222 | #define HASHBITS 30 | |
2223 | #define MAX_HASH_TABLE 1009 | |
2224 | static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE]; | |
2225 | ||
ac79cd5a RK |
2226 | /* We maintain a hash table of STRING_CST values. Unless we are asked to force |
2227 | out a string constant, we defer output of the constants until we know | |
2228 | they are actually used. This will be if something takes its address or if | |
2229 | there is a usage of the string in the RTL of a function. */ | |
2230 | ||
c203e7fe | 2231 | #define STRHASH(x) ((hashval_t) ((long) (x) >> 3)) |
bd7cf17e JJ |
2232 | |
2233 | struct deferred_string | |
2234 | { | |
520a57c8 | 2235 | const char *label; |
bd7cf17e JJ |
2236 | tree exp; |
2237 | int labelno; | |
2238 | }; | |
2239 | ||
2240 | static htab_t const_str_htab; | |
2241 | ||
76095e2f RH |
2242 | /* Mark a const_hash_table descriptor for GC. */ |
2243 | ||
46f9491e | 2244 | static void |
76095e2f RH |
2245 | mark_const_hash_entry (ptr) |
2246 | void *ptr; | |
2247 | { | |
2248 | struct constant_descriptor *desc = * (struct constant_descriptor **) ptr; | |
2249 | ||
2250 | while (desc) | |
2251 | { | |
14a774a9 | 2252 | ggc_mark_rtx (desc->rtl); |
76095e2f RH |
2253 | desc = desc->next; |
2254 | } | |
2255 | } | |
2256 | ||
bd7cf17e JJ |
2257 | /* Mark the hash-table element X (which is really a pointer to an |
2258 | struct deferred_string *). */ | |
46f9491e | 2259 | |
bd7cf17e JJ |
2260 | static int |
2261 | mark_const_str_htab_1 (x, data) | |
2262 | void **x; | |
2263 | void *data ATTRIBUTE_UNUSED; | |
2264 | { | |
2265 | ggc_mark_tree (((struct deferred_string *) *x)->exp); | |
2266 | return 1; | |
2267 | } | |
2268 | ||
2269 | /* Mark a const_str_htab for GC. */ | |
2270 | ||
46f9491e | 2271 | static void |
bd7cf17e JJ |
2272 | mark_const_str_htab (htab) |
2273 | void *htab; | |
2274 | { | |
2275 | htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL); | |
2276 | } | |
2277 | ||
2278 | /* Returns a hash code for X (which is a really a | |
2279 | struct deferred_string *). */ | |
2280 | ||
2281 | static hashval_t | |
2282 | const_str_htab_hash (x) | |
2283 | const void *x; | |
2284 | { | |
ce1cc601 | 2285 | return STRHASH (((const struct deferred_string *) x)->label); |
bd7cf17e JJ |
2286 | } |
2287 | ||
2288 | /* Returns non-zero if the value represented by X (which is really a | |
2289 | struct deferred_string *) is the same as that given by Y | |
2290 | (which is really a char *). */ | |
2291 | ||
2292 | static int | |
2293 | const_str_htab_eq (x, y) | |
2294 | const void *x; | |
2295 | const void *y; | |
2296 | { | |
ce1cc601 | 2297 | return (((const struct deferred_string *) x)->label == (const char *) y); |
bd7cf17e JJ |
2298 | } |
2299 | ||
2300 | /* Delete the hash table entry dfsp. */ | |
2301 | ||
2302 | static void | |
2303 | const_str_htab_del (dfsp) | |
c26fbbca | 2304 | void *dfsp; |
bd7cf17e JJ |
2305 | { |
2306 | free (dfsp); | |
2307 | } | |
2308 | ||
79e68feb RS |
2309 | /* Compute a hash code for a constant expression. */ |
2310 | ||
5a13eaa4 | 2311 | static int |
79e68feb RS |
2312 | const_hash (exp) |
2313 | tree exp; | |
2314 | { | |
b3694847 SS |
2315 | const char *p; |
2316 | int len, hi, i; | |
2317 | enum tree_code code = TREE_CODE (exp); | |
79e68feb | 2318 | |
a9d07d6e RK |
2319 | /* Either set P and LEN to the address and len of something to hash and |
2320 | exit the switch or return a value. */ | |
2321 | ||
2322 | switch (code) | |
79e68feb | 2323 | { |
a9d07d6e | 2324 | case INTEGER_CST: |
2afaa41c GM |
2325 | p = (char *) &TREE_INT_CST (exp); |
2326 | len = sizeof TREE_INT_CST (exp); | |
a9d07d6e RK |
2327 | break; |
2328 | ||
2329 | case REAL_CST: | |
79e68feb RS |
2330 | p = (char *) &TREE_REAL_CST (exp); |
2331 | len = sizeof TREE_REAL_CST (exp); | |
a9d07d6e | 2332 | break; |
79e68feb | 2333 | |
a9d07d6e RK |
2334 | case STRING_CST: |
2335 | p = TREE_STRING_POINTER (exp); | |
2336 | len = TREE_STRING_LENGTH (exp); | |
2337 | break; | |
79e68feb | 2338 | |
a9d07d6e RK |
2339 | case COMPLEX_CST: |
2340 | return (const_hash (TREE_REALPART (exp)) * 5 | |
2341 | + const_hash (TREE_IMAGPART (exp))); | |
2342 | ||
2343 | case CONSTRUCTOR: | |
2344 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) | |
79e68feb | 2345 | { |
3cce094d KG |
2346 | char *tmp; |
2347 | ||
a9d07d6e | 2348 | len = int_size_in_bytes (TREE_TYPE (exp)); |
3cce094d KG |
2349 | tmp = (char *) alloca (len); |
2350 | get_set_constructor_bytes (exp, (unsigned char *) tmp, len); | |
2351 | p = tmp; | |
a9d07d6e RK |
2352 | break; |
2353 | } | |
2354 | else | |
2355 | { | |
b3694847 | 2356 | tree link; |
a9d07d6e RK |
2357 | |
2358 | /* For record type, include the type in the hashing. | |
2359 | We do not do so for array types | |
2360 | because (1) the sizes of the elements are sufficient | |
2361 | and (2) distinct array types can have the same constructor. | |
2362 | Instead, we include the array size because the constructor could | |
2363 | be shorter. */ | |
2364 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) | |
7bcac048 | 2365 | hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1)) |
a9d07d6e RK |
2366 | % MAX_HASH_TABLE; |
2367 | else | |
2368 | hi = ((5 + int_size_in_bytes (TREE_TYPE (exp))) | |
2369 | & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE; | |
2370 | ||
2371 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
2372 | if (TREE_VALUE (link)) | |
2373 | hi | |
2374 | = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE; | |
2375 | ||
2376 | return hi; | |
79e68feb | 2377 | } |
79e68feb | 2378 | |
a9d07d6e RK |
2379 | case ADDR_EXPR: |
2380 | { | |
2381 | struct addr_const value; | |
2382 | ||
2383 | decode_addr_const (exp, &value); | |
2384 | if (GET_CODE (value.base) == SYMBOL_REF) | |
2385 | { | |
2386 | /* Don't hash the address of the SYMBOL_REF; | |
2387 | only use the offset and the symbol name. */ | |
2388 | hi = value.offset; | |
2389 | p = XSTR (value.base, 0); | |
2390 | for (i = 0; p[i] != 0; i++) | |
2391 | hi = ((hi * 613) + (unsigned) (p[i])); | |
2392 | } | |
2393 | else if (GET_CODE (value.base) == LABEL_REF) | |
2394 | hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13; | |
6a651371 | 2395 | else |
c203e7fe | 2396 | abort (); |
a9d07d6e RK |
2397 | |
2398 | hi &= (1 << HASHBITS) - 1; | |
2399 | hi %= MAX_HASH_TABLE; | |
2400 | } | |
79e68feb | 2401 | return hi; |
a9d07d6e RK |
2402 | |
2403 | case PLUS_EXPR: | |
2404 | case MINUS_EXPR: | |
2405 | return (const_hash (TREE_OPERAND (exp, 0)) * 9 | |
2406 | + const_hash (TREE_OPERAND (exp, 1))); | |
2407 | ||
2408 | case NOP_EXPR: | |
2409 | case CONVERT_EXPR: | |
2410 | case NON_LVALUE_EXPR: | |
2411 | return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2; | |
46f9491e | 2412 | |
e9a25f70 | 2413 | default: |
2d76cb1a | 2414 | /* A language specific constant. Just hash the code. */ |
dbbbbf3b | 2415 | return (int) code % MAX_HASH_TABLE; |
79e68feb | 2416 | } |
79e68feb RS |
2417 | |
2418 | /* Compute hashing function */ | |
2419 | hi = len; | |
2420 | for (i = 0; i < len; i++) | |
0f41302f | 2421 | hi = ((hi * 613) + (unsigned) (p[i])); |
79e68feb RS |
2422 | |
2423 | hi &= (1 << HASHBITS) - 1; | |
2424 | hi %= MAX_HASH_TABLE; | |
2425 | return hi; | |
2426 | } | |
2427 | \f | |
2428 | /* Compare a constant expression EXP with a constant-descriptor DESC. | |
2429 | Return 1 if DESC describes a constant with the same value as EXP. */ | |
2430 | ||
2431 | static int | |
2432 | compare_constant (exp, desc) | |
2433 | tree exp; | |
2434 | struct constant_descriptor *desc; | |
2435 | { | |
37357796 | 2436 | return 0 != compare_constant_1 (exp, desc->u.contents); |
79e68feb RS |
2437 | } |
2438 | ||
2439 | /* Compare constant expression EXP with a substring P of a constant descriptor. | |
2440 | If they match, return a pointer to the end of the substring matched. | |
2441 | If they do not match, return 0. | |
2442 | ||
2443 | Since descriptors are written in polish prefix notation, | |
2444 | this function can be used recursively to test one operand of EXP | |
2445 | against a subdescriptor, and if it succeeds it returns the | |
2446 | address of the subdescriptor for the next operand. */ | |
2447 | ||
990e8954 | 2448 | static const unsigned char * |
79e68feb RS |
2449 | compare_constant_1 (exp, p) |
2450 | tree exp; | |
990e8954 | 2451 | const unsigned char *p; |
79e68feb | 2452 | { |
b3694847 SS |
2453 | const unsigned char *strp; |
2454 | int len; | |
2455 | enum tree_code code = TREE_CODE (exp); | |
79e68feb RS |
2456 | |
2457 | if (code != (enum tree_code) *p++) | |
2458 | return 0; | |
2459 | ||
a9d07d6e RK |
2460 | /* Either set STRP, P and LEN to pointers and length to compare and exit the |
2461 | switch, or return the result of the comparison. */ | |
2462 | ||
2463 | switch (code) | |
79e68feb | 2464 | { |
a9d07d6e | 2465 | case INTEGER_CST: |
79e68feb RS |
2466 | /* Integer constants are the same only if the same width of type. */ |
2467 | if (*p++ != TYPE_PRECISION (TREE_TYPE (exp))) | |
2468 | return 0; | |
a9d07d6e | 2469 | |
2afaa41c GM |
2470 | strp = (unsigned char *) &TREE_INT_CST (exp); |
2471 | len = sizeof TREE_INT_CST (exp); | |
a9d07d6e RK |
2472 | break; |
2473 | ||
2474 | case REAL_CST: | |
79e68feb RS |
2475 | /* Real constants are the same only if the same width of type. */ |
2476 | if (*p++ != TYPE_PRECISION (TREE_TYPE (exp))) | |
2477 | return 0; | |
a9d07d6e | 2478 | |
990e8954 | 2479 | strp = (unsigned char *) &TREE_REAL_CST (exp); |
79e68feb | 2480 | len = sizeof TREE_REAL_CST (exp); |
a9d07d6e RK |
2481 | break; |
2482 | ||
2483 | case STRING_CST: | |
79e68feb RS |
2484 | if (flag_writable_strings) |
2485 | return 0; | |
a9d07d6e | 2486 | |
c8d8ed65 | 2487 | if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp))) |
f163668c RK |
2488 | return 0; |
2489 | ||
e9d1b155 | 2490 | strp = (const unsigned char *) TREE_STRING_POINTER (exp); |
79e68feb | 2491 | len = TREE_STRING_LENGTH (exp); |
da61dec9 | 2492 | if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p, |
ac79cd5a | 2493 | sizeof TREE_STRING_LENGTH (exp))) |
79e68feb | 2494 | return 0; |
a9d07d6e | 2495 | |
79e68feb | 2496 | p += sizeof TREE_STRING_LENGTH (exp); |
a9d07d6e | 2497 | break; |
79e68feb | 2498 | |
a9d07d6e RK |
2499 | case COMPLEX_CST: |
2500 | p = compare_constant_1 (TREE_REALPART (exp), p); | |
2501 | if (p == 0) | |
79e68feb | 2502 | return 0; |
79e68feb | 2503 | |
a9d07d6e | 2504 | return compare_constant_1 (TREE_IMAGPART (exp), p); |
79e68feb | 2505 | |
a9d07d6e RK |
2506 | case CONSTRUCTOR: |
2507 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) | |
eb528802 | 2508 | { |
a9d07d6e | 2509 | int xlen = len = int_size_in_bytes (TREE_TYPE (exp)); |
3cce094d | 2510 | unsigned char *tmp = (unsigned char *) alloca (len); |
a9d07d6e | 2511 | |
f9e158c3 | 2512 | get_set_constructor_bytes (exp, tmp, len); |
990e8954 | 2513 | strp = (unsigned char *) tmp; |
da61dec9 | 2514 | if (memcmp ((char *) &xlen, p, sizeof xlen)) |
eb528802 | 2515 | return 0; |
eb528802 | 2516 | |
a9d07d6e RK |
2517 | p += sizeof xlen; |
2518 | break; | |
2519 | } | |
2520 | else | |
77fa0940 | 2521 | { |
b3694847 | 2522 | tree link; |
a9d07d6e RK |
2523 | int length = list_length (CONSTRUCTOR_ELTS (exp)); |
2524 | tree type; | |
14a774a9 | 2525 | enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); |
e5e809f4 JL |
2526 | int have_purpose = 0; |
2527 | ||
2528 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
2529 | if (TREE_PURPOSE (link)) | |
2530 | have_purpose = 1; | |
a9d07d6e | 2531 | |
da61dec9 | 2532 | if (memcmp ((char *) &length, p, sizeof length)) |
a9d07d6e RK |
2533 | return 0; |
2534 | ||
2535 | p += sizeof length; | |
2536 | ||
2537 | /* For record constructors, insist that the types match. | |
46f9491e | 2538 | For arrays, just verify both constructors are for arrays. |
e5e809f4 JL |
2539 | Then insist that either both or none have any TREE_PURPOSE |
2540 | values. */ | |
a9d07d6e RK |
2541 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) |
2542 | type = TREE_TYPE (exp); | |
2543 | else | |
2544 | type = 0; | |
2545 | ||
da61dec9 | 2546 | if (memcmp ((char *) &type, p, sizeof type)) |
a9d07d6e RK |
2547 | return 0; |
2548 | ||
14a774a9 RK |
2549 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) |
2550 | { | |
da61dec9 | 2551 | if (memcmp ((char *) &mode, p, sizeof mode)) |
14a774a9 RK |
2552 | return 0; |
2553 | ||
2554 | p += sizeof mode; | |
2555 | } | |
2556 | ||
a9d07d6e RK |
2557 | p += sizeof type; |
2558 | ||
da61dec9 | 2559 | if (memcmp ((char *) &have_purpose, p, sizeof have_purpose)) |
e5e809f4 JL |
2560 | return 0; |
2561 | ||
2562 | p += sizeof have_purpose; | |
2563 | ||
a9d07d6e RK |
2564 | /* For arrays, insist that the size in bytes match. */ |
2565 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) | |
77fa0940 | 2566 | { |
e5e809f4 JL |
2567 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); |
2568 | ||
da61dec9 | 2569 | if (memcmp ((char *) &size, p, sizeof size)) |
77fa0940 | 2570 | return 0; |
a9d07d6e RK |
2571 | |
2572 | p += sizeof size; | |
77fa0940 | 2573 | } |
a9d07d6e RK |
2574 | |
2575 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
77fa0940 | 2576 | { |
a9d07d6e RK |
2577 | if (TREE_VALUE (link)) |
2578 | { | |
2579 | if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0) | |
2580 | return 0; | |
2581 | } | |
2582 | else | |
2583 | { | |
2584 | tree zero = 0; | |
77fa0940 | 2585 | |
da61dec9 | 2586 | if (memcmp ((char *) &zero, p, sizeof zero)) |
e5e809f4 JL |
2587 | return 0; |
2588 | ||
2589 | p += sizeof zero; | |
2590 | } | |
2591 | ||
2592 | if (TREE_PURPOSE (link) | |
2593 | && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL) | |
2594 | { | |
da61dec9 | 2595 | if (memcmp ((char *) &TREE_PURPOSE (link), p, |
c26fbbca | 2596 | sizeof TREE_PURPOSE (link))) |
e5e809f4 JL |
2597 | return 0; |
2598 | ||
2599 | p += sizeof TREE_PURPOSE (link); | |
2600 | } | |
2601 | else if (TREE_PURPOSE (link)) | |
2602 | { | |
2603 | if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0) | |
2604 | return 0; | |
2605 | } | |
2606 | else if (have_purpose) | |
2607 | { | |
2608 | int zero = 0; | |
2609 | ||
da61dec9 | 2610 | if (memcmp ((char *) &zero, p, sizeof zero)) |
a9d07d6e RK |
2611 | return 0; |
2612 | ||
2613 | p += sizeof zero; | |
2614 | } | |
77fa0940 | 2615 | } |
a9d07d6e RK |
2616 | |
2617 | return p; | |
77fa0940 RK |
2618 | } |
2619 | ||
a9d07d6e RK |
2620 | case ADDR_EXPR: |
2621 | { | |
2622 | struct addr_const value; | |
2623 | ||
2624 | decode_addr_const (exp, &value); | |
990e8954 | 2625 | strp = (unsigned char *) &value.offset; |
a9d07d6e RK |
2626 | len = sizeof value.offset; |
2627 | /* Compare the offset. */ | |
2628 | while (--len >= 0) | |
2629 | if (*p++ != *strp++) | |
2630 | return 0; | |
2631 | ||
2632 | /* Compare symbol name. */ | |
ce1cc601 KG |
2633 | strp = (const unsigned char *) XSTR (value.base, 0); |
2634 | len = strlen ((const char *) strp) + 1; | |
a9d07d6e RK |
2635 | } |
2636 | break; | |
2637 | ||
2638 | case PLUS_EXPR: | |
2639 | case MINUS_EXPR: | |
fa212801 | 2640 | case RANGE_EXPR: |
79e68feb | 2641 | p = compare_constant_1 (TREE_OPERAND (exp, 0), p); |
a9d07d6e RK |
2642 | if (p == 0) |
2643 | return 0; | |
2644 | ||
2645 | return compare_constant_1 (TREE_OPERAND (exp, 1), p); | |
2646 | ||
2647 | case NOP_EXPR: | |
2648 | case CONVERT_EXPR: | |
2649 | case NON_LVALUE_EXPR: | |
2650 | return compare_constant_1 (TREE_OPERAND (exp, 0), p); | |
e9a25f70 JL |
2651 | |
2652 | default: | |
ac79cd5a RK |
2653 | { |
2654 | tree new = (*lang_hooks.expand_constant) (exp); | |
2655 | ||
2656 | if (new != exp) | |
c26fbbca | 2657 | return compare_constant_1 (new, p); |
ac79cd5a RK |
2658 | else |
2659 | return 0; | |
2660 | } | |
79e68feb RS |
2661 | } |
2662 | ||
2663 | /* Compare constant contents. */ | |
2664 | while (--len >= 0) | |
2665 | if (*p++ != *strp++) | |
2666 | return 0; | |
2667 | ||
2668 | return p; | |
2669 | } | |
2670 | \f | |
2671 | /* Construct a constant descriptor for the expression EXP. | |
2672 | It is up to the caller to enter the descriptor in the hash table. */ | |
2673 | ||
2674 | static struct constant_descriptor * | |
2675 | record_constant (exp) | |
2676 | tree exp; | |
2677 | { | |
387e854a RK |
2678 | struct constant_descriptor *next = 0; |
2679 | char *label = 0; | |
14a774a9 | 2680 | rtx rtl = 0; |
cac16ef9 | 2681 | int pad; |
79e68feb | 2682 | |
14a774a9 | 2683 | /* Make a struct constant_descriptor. The first three pointers will |
387e854a RK |
2684 | be filled in later. Here we just leave space for them. */ |
2685 | ||
2686 | obstack_grow (&permanent_obstack, (char *) &next, sizeof next); | |
2687 | obstack_grow (&permanent_obstack, (char *) &label, sizeof label); | |
14a774a9 | 2688 | obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl); |
cac16ef9 RH |
2689 | |
2690 | /* Align the descriptor for the data payload. */ | |
2691 | pad = (offsetof (struct constant_descriptor, u) | |
2692 | - offsetof(struct constant_descriptor, rtl) | |
2693 | - sizeof(next->rtl)); | |
2694 | if (pad > 0) | |
2695 | obstack_blank (&permanent_obstack, pad); | |
2696 | ||
79e68feb RS |
2697 | record_constant_1 (exp); |
2698 | return (struct constant_descriptor *) obstack_finish (&permanent_obstack); | |
2699 | } | |
2700 | ||
2701 | /* Add a description of constant expression EXP | |
2702 | to the object growing in `permanent_obstack'. | |
2703 | No need to return its address; the caller will get that | |
2704 | from the obstack when the object is complete. */ | |
2705 | ||
2706 | static void | |
2707 | record_constant_1 (exp) | |
2708 | tree exp; | |
2709 | { | |
b3694847 SS |
2710 | const unsigned char *strp; |
2711 | int len; | |
2712 | enum tree_code code = TREE_CODE (exp); | |
79e68feb RS |
2713 | |
2714 | obstack_1grow (&permanent_obstack, (unsigned int) code); | |
2715 | ||
2871d24f | 2716 | switch (code) |
79e68feb | 2717 | { |
2871d24f | 2718 | case INTEGER_CST: |
79e68feb | 2719 | obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp))); |
2afaa41c GM |
2720 | strp = (unsigned char *) &TREE_INT_CST (exp); |
2721 | len = sizeof TREE_INT_CST (exp); | |
2871d24f RK |
2722 | break; |
2723 | ||
2724 | case REAL_CST: | |
79e68feb | 2725 | obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp))); |
990e8954 | 2726 | strp = (unsigned char *) &TREE_REAL_CST (exp); |
79e68feb | 2727 | len = sizeof TREE_REAL_CST (exp); |
2871d24f RK |
2728 | break; |
2729 | ||
2730 | case STRING_CST: | |
79e68feb RS |
2731 | if (flag_writable_strings) |
2732 | return; | |
2871d24f | 2733 | |
f163668c | 2734 | obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp))); |
ce1cc601 | 2735 | strp = (const unsigned char *) TREE_STRING_POINTER (exp); |
79e68feb RS |
2736 | len = TREE_STRING_LENGTH (exp); |
2737 | obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp), | |
2738 | sizeof TREE_STRING_LENGTH (exp)); | |
2871d24f RK |
2739 | break; |
2740 | ||
2741 | case COMPLEX_CST: | |
79e68feb RS |
2742 | record_constant_1 (TREE_REALPART (exp)); |
2743 | record_constant_1 (TREE_IMAGPART (exp)); | |
2744 | return; | |
79e68feb | 2745 | |
2871d24f RK |
2746 | case CONSTRUCTOR: |
2747 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) | |
eb528802 | 2748 | { |
2871d24f RK |
2749 | int nbytes = int_size_in_bytes (TREE_TYPE (exp)); |
2750 | obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes)); | |
2751 | obstack_blank (&permanent_obstack, nbytes); | |
2752 | get_set_constructor_bytes | |
c26fbbca | 2753 | (exp, (unsigned char *) permanent_obstack.next_free - nbytes, |
2491d239 | 2754 | nbytes); |
2871d24f | 2755 | return; |
eb528802 | 2756 | } |
2871d24f | 2757 | else |
77fa0940 | 2758 | { |
b3694847 | 2759 | tree link; |
2871d24f | 2760 | int length = list_length (CONSTRUCTOR_ELTS (exp)); |
14a774a9 | 2761 | enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); |
2871d24f | 2762 | tree type; |
e5e809f4 JL |
2763 | int have_purpose = 0; |
2764 | ||
2765 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) | |
2766 | if (TREE_PURPOSE (link)) | |
2767 | have_purpose = 1; | |
2871d24f RK |
2768 | |
2769 | obstack_grow (&permanent_obstack, (char *) &length, sizeof length); | |
2770 | ||
2771 | /* For record constructors, insist that the types match. | |
14a774a9 RK |
2772 | For arrays, just verify both constructors are for arrays |
2773 | of the same mode. Then insist that either both or none | |
2774 | have any TREE_PURPOSE values. */ | |
2871d24f RK |
2775 | if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE) |
2776 | type = TREE_TYPE (exp); | |
77fa0940 | 2777 | else |
2871d24f | 2778 | type = 0; |
14a774a9 | 2779 | |
2871d24f | 2780 | obstack_grow (&permanent_obstack, (char *) &type, sizeof type); |
14a774a9 RK |
2781 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) |
2782 | obstack_grow (&permanent_obstack, &mode, sizeof mode); | |
46f9491e | 2783 | |
e5e809f4 JL |
2784 | obstack_grow (&permanent_obstack, (char *) &have_purpose, |
2785 | sizeof have_purpose); | |
2871d24f RK |
2786 | |
2787 | /* For arrays, insist that the size in bytes match. */ | |
2788 | if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) | |
77fa0940 | 2789 | { |
e5e809f4 | 2790 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); |
2871d24f RK |
2791 | obstack_grow (&permanent_obstack, (char *) &size, sizeof size); |
2792 | } | |
77fa0940 | 2793 | |
2871d24f RK |
2794 | for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) |
2795 | { | |
2796 | if (TREE_VALUE (link)) | |
2797 | record_constant_1 (TREE_VALUE (link)); | |
2798 | else | |
2799 | { | |
2800 | tree zero = 0; | |
2801 | ||
e5e809f4 JL |
2802 | obstack_grow (&permanent_obstack, |
2803 | (char *) &zero, sizeof zero); | |
2804 | } | |
2805 | ||
2806 | if (TREE_PURPOSE (link) | |
2807 | && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL) | |
2808 | obstack_grow (&permanent_obstack, | |
2809 | (char *) &TREE_PURPOSE (link), | |
2810 | sizeof TREE_PURPOSE (link)); | |
2811 | else if (TREE_PURPOSE (link)) | |
2812 | record_constant_1 (TREE_PURPOSE (link)); | |
2813 | else if (have_purpose) | |
2814 | { | |
2815 | int zero = 0; | |
2816 | ||
2871d24f RK |
2817 | obstack_grow (&permanent_obstack, |
2818 | (char *) &zero, sizeof zero); | |
2819 | } | |
77fa0940 RK |
2820 | } |
2821 | } | |
79e68feb | 2822 | return; |
2871d24f RK |
2823 | |
2824 | case ADDR_EXPR: | |
2825 | { | |
2826 | struct addr_const value; | |
2827 | ||
2828 | decode_addr_const (exp, &value); | |
2829 | /* Record the offset. */ | |
2830 | obstack_grow (&permanent_obstack, | |
2831 | (char *) &value.offset, sizeof value.offset); | |
e67cd9f8 RH |
2832 | |
2833 | switch (GET_CODE (value.base)) | |
2834 | { | |
2835 | case SYMBOL_REF: | |
2836 | /* Record the symbol name. */ | |
2837 | obstack_grow (&permanent_obstack, XSTR (value.base, 0), | |
2838 | strlen (XSTR (value.base, 0)) + 1); | |
2839 | break; | |
2840 | case LABEL_REF: | |
2841 | /* Record the address of the CODE_LABEL. It may not have | |
2842 | been emitted yet, so it's UID may be zero. But pointer | |
2843 | identity is good enough. */ | |
2844 | obstack_grow (&permanent_obstack, &XEXP (value.base, 0), | |
2845 | sizeof (rtx)); | |
2846 | break; | |
2847 | default: | |
2848 | abort (); | |
2849 | } | |
2871d24f | 2850 | } |
79e68feb | 2851 | return; |
2871d24f RK |
2852 | |
2853 | case PLUS_EXPR: | |
2854 | case MINUS_EXPR: | |
fa212801 | 2855 | case RANGE_EXPR: |
79e68feb RS |
2856 | record_constant_1 (TREE_OPERAND (exp, 0)); |
2857 | record_constant_1 (TREE_OPERAND (exp, 1)); | |
2858 | return; | |
2871d24f RK |
2859 | |
2860 | case NOP_EXPR: | |
2861 | case CONVERT_EXPR: | |
2862 | case NON_LVALUE_EXPR: | |
79e68feb RS |
2863 | record_constant_1 (TREE_OPERAND (exp, 0)); |
2864 | return; | |
2871d24f RK |
2865 | |
2866 | default: | |
ac79cd5a RK |
2867 | { |
2868 | tree new = (*lang_hooks.expand_constant) (exp); | |
2869 | ||
2870 | if (new != exp) | |
c26fbbca | 2871 | record_constant_1 (new); |
ac79cd5a RK |
2872 | return; |
2873 | } | |
79e68feb RS |
2874 | } |
2875 | ||
2876 | /* Record constant contents. */ | |
2877 | obstack_grow (&permanent_obstack, strp, len); | |
2878 | } | |
2879 | \f | |
ff8f4401 RS |
2880 | /* Record a list of constant expressions that were passed to |
2881 | output_constant_def but that could not be output right away. */ | |
2882 | ||
2883 | struct deferred_constant | |
2884 | { | |
2885 | struct deferred_constant *next; | |
2886 | tree exp; | |
2887 | int reloc; | |
2888 | int labelno; | |
2889 | }; | |
2890 | ||
2891 | static struct deferred_constant *deferred_constants; | |
2892 | ||
8839fca4 ILT |
2893 | /* Another list of constants which should be output after the |
2894 | function. */ | |
2895 | static struct deferred_constant *after_function_constants; | |
2896 | ||
ff8f4401 RS |
2897 | /* Nonzero means defer output of addressed subconstants |
2898 | (i.e., those for which output_constant_def is called.) */ | |
2899 | static int defer_addressed_constants_flag; | |
2900 | ||
2901 | /* Start deferring output of subconstants. */ | |
2902 | ||
2903 | void | |
2904 | defer_addressed_constants () | |
2905 | { | |
2906 | defer_addressed_constants_flag++; | |
2907 | } | |
2908 | ||
2909 | /* Stop deferring output of subconstants, | |
2910 | and output now all those that have been deferred. */ | |
2911 | ||
2912 | void | |
2913 | output_deferred_addressed_constants () | |
2914 | { | |
2915 | struct deferred_constant *p, *next; | |
2916 | ||
2917 | defer_addressed_constants_flag--; | |
2918 | ||
2919 | if (defer_addressed_constants_flag > 0) | |
2920 | return; | |
2921 | ||
2922 | for (p = deferred_constants; p; p = next) | |
2923 | { | |
2924 | output_constant_def_contents (p->exp, p->reloc, p->labelno); | |
2925 | next = p->next; | |
2926 | free (p); | |
2927 | } | |
2928 | ||
2929 | deferred_constants = 0; | |
2930 | } | |
d12516f1 | 2931 | |
8839fca4 ILT |
2932 | /* Output any constants which should appear after a function. */ |
2933 | ||
2934 | static void | |
2935 | output_after_function_constants () | |
2936 | { | |
2937 | struct deferred_constant *p, *next; | |
2938 | ||
2939 | for (p = after_function_constants; p; p = next) | |
2940 | { | |
2941 | output_constant_def_contents (p->exp, p->reloc, p->labelno); | |
2942 | next = p->next; | |
2943 | free (p); | |
2944 | } | |
2945 | ||
2946 | after_function_constants = 0; | |
2947 | } | |
2948 | ||
d12516f1 RS |
2949 | /* Make a copy of the whole tree structure for a constant. |
2950 | This handles the same types of nodes that compare_constant | |
2951 | and record_constant handle. */ | |
2952 | ||
2953 | static tree | |
2954 | copy_constant (exp) | |
2955 | tree exp; | |
2956 | { | |
2957 | switch (TREE_CODE (exp)) | |
2958 | { | |
310bbbf4 JW |
2959 | case ADDR_EXPR: |
2960 | /* For ADDR_EXPR, we do not want to copy the decl whose address | |
2961 | is requested. We do want to copy constants though. */ | |
2962 | if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c') | |
2963 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), | |
2964 | copy_constant (TREE_OPERAND (exp, 0))); | |
2965 | else | |
2966 | return copy_node (exp); | |
2967 | ||
d12516f1 RS |
2968 | case INTEGER_CST: |
2969 | case REAL_CST: | |
2970 | case STRING_CST: | |
d12516f1 RS |
2971 | return copy_node (exp); |
2972 | ||
2973 | case COMPLEX_CST: | |
28eb1cb8 RK |
2974 | return build_complex (TREE_TYPE (exp), |
2975 | copy_constant (TREE_REALPART (exp)), | |
d12516f1 RS |
2976 | copy_constant (TREE_IMAGPART (exp))); |
2977 | ||
2978 | case PLUS_EXPR: | |
2979 | case MINUS_EXPR: | |
2980 | return build (TREE_CODE (exp), TREE_TYPE (exp), | |
2981 | copy_constant (TREE_OPERAND (exp, 0)), | |
2982 | copy_constant (TREE_OPERAND (exp, 1))); | |
2983 | ||
2984 | case NOP_EXPR: | |
2985 | case CONVERT_EXPR: | |
a9d07d6e | 2986 | case NON_LVALUE_EXPR: |
d12516f1 RS |
2987 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), |
2988 | copy_constant (TREE_OPERAND (exp, 0))); | |
2989 | ||
2990 | case CONSTRUCTOR: | |
2991 | { | |
2992 | tree copy = copy_node (exp); | |
2993 | tree list = copy_list (CONSTRUCTOR_ELTS (exp)); | |
2994 | tree tail; | |
2995 | ||
bb31ce0a | 2996 | CONSTRUCTOR_ELTS (copy) = list; |
d12516f1 RS |
2997 | for (tail = list; tail; tail = TREE_CHAIN (tail)) |
2998 | TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail)); | |
474bda6c PB |
2999 | if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE) |
3000 | for (tail = list; tail; tail = TREE_CHAIN (tail)) | |
3001 | TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail)); | |
d12516f1 RS |
3002 | |
3003 | return copy; | |
3004 | } | |
3005 | ||
3006 | default: | |
3007 | abort (); | |
3008 | } | |
3009 | } | |
ff8f4401 | 3010 | \f |
79e68feb RS |
3011 | /* Return an rtx representing a reference to constant data in memory |
3012 | for the constant expression EXP. | |
ff8f4401 | 3013 | |
79e68feb RS |
3014 | If assembler code for such a constant has already been output, |
3015 | return an rtx to refer to it. | |
ff8f4401 RS |
3016 | Otherwise, output such a constant in memory (or defer it for later) |
3017 | and generate an rtx for it. | |
3018 | ||
bd7cf17e JJ |
3019 | If DEFER is non-zero, the output of string constants can be deferred |
3020 | and output only if referenced in the function after all optimizations. | |
3021 | ||
ff8f4401 | 3022 | The TREE_CST_RTL of EXP is set up to point to that rtx. |
79e68feb RS |
3023 | The const_hash_table records which constants already have label strings. */ |
3024 | ||
3025 | rtx | |
bd7cf17e | 3026 | output_constant_def (exp, defer) |
79e68feb | 3027 | tree exp; |
bd7cf17e | 3028 | int defer; |
79e68feb | 3029 | { |
b3694847 SS |
3030 | int hash; |
3031 | struct constant_descriptor *desc; | |
bd7cf17e | 3032 | struct deferred_string **defstr; |
79e68feb | 3033 | char label[256]; |
79e68feb | 3034 | int reloc; |
14a774a9 | 3035 | int found = 1; |
bd7cf17e JJ |
3036 | int after_function = 0; |
3037 | int labelno = -1; | |
a79e3a45 | 3038 | rtx rtl; |
79e68feb | 3039 | |
ac79cd5a RK |
3040 | /* We can't just use the saved RTL if this is a defererred string constant |
3041 | and we are not to defer anymode. */ | |
3042 | if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp) | |
3043 | && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0)))) | |
79e68feb RS |
3044 | return TREE_CST_RTL (exp); |
3045 | ||
3046 | /* Make sure any other constants whose addresses appear in EXP | |
3047 | are assigned label numbers. */ | |
3048 | ||
3049 | reloc = output_addressed_constants (exp); | |
3050 | ||
3051 | /* Compute hash code of EXP. Search the descriptors for that hash code | |
3052 | to see if any of them describes EXP. If yes, the descriptor records | |
3053 | the label number already assigned. */ | |
3054 | ||
00f07fb9 | 3055 | hash = const_hash (exp) % MAX_HASH_TABLE; |
46f9491e | 3056 | |
00f07fb9 RK |
3057 | for (desc = const_hash_table[hash]; desc; desc = desc->next) |
3058 | if (compare_constant (exp, desc)) | |
14a774a9 | 3059 | break; |
46f9491e | 3060 | |
14a774a9 | 3061 | if (desc == 0) |
00f07fb9 RK |
3062 | { |
3063 | /* No constant equal to EXP is known to have been output. | |
3064 | Make a constant descriptor to enter EXP in the hash table. | |
3065 | Assign the label number and record it in the descriptor for | |
3066 | future calls to this function to find. */ | |
46f9491e | 3067 | |
00f07fb9 | 3068 | /* Create a string containing the label name, in LABEL. */ |
bd7cf17e JJ |
3069 | labelno = const_labelno++; |
3070 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno); | |
00f07fb9 RK |
3071 | |
3072 | desc = record_constant (exp); | |
3073 | desc->next = const_hash_table[hash]; | |
a8a05998 | 3074 | desc->label = ggc_strdup (label); |
00f07fb9 | 3075 | const_hash_table[hash] = desc; |
46f9491e | 3076 | |
1f8f4a0b | 3077 | /* We have a symbol name; construct the SYMBOL_REF and the MEM. */ |
a79e3a45 | 3078 | rtl = desc->rtl |
14a774a9 RK |
3079 | = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), |
3080 | gen_rtx_SYMBOL_REF (Pmode, desc->label)); | |
00f07fb9 | 3081 | |
a79e3a45 RK |
3082 | set_mem_attributes (rtl, exp, 1); |
3083 | set_mem_alias_set (rtl, 0); | |
3084 | set_mem_alias_set (rtl, const_alias_set); | |
14a774a9 RK |
3085 | |
3086 | found = 0; | |
3087 | } | |
a79e3a45 RK |
3088 | else |
3089 | rtl = desc->rtl; | |
14a774a9 | 3090 | |
a79e3a45 RK |
3091 | if (TREE_CODE (exp) != INTEGER_CST) |
3092 | TREE_CST_RTL (exp) = rtl; | |
79e68feb RS |
3093 | |
3094 | /* Optionally set flags or add text to the name to record information | |
3095 | such as that it is a function name. If the name is changed, the macro | |
8a425a05 | 3096 | ASM_OUTPUT_LABELREF will have to know how to strip this information. */ |
79e68feb | 3097 | #ifdef ENCODE_SECTION_INFO |
e1b4533c AO |
3098 | /* A previously-processed constant would already have section info |
3099 | encoded in it. */ | |
3100 | if (! found) | |
3101 | { | |
ec493bcb HPN |
3102 | /* Take care not to invoke ENCODE_SECTION_INFO for constants |
3103 | which don't have a TREE_CST_RTL. */ | |
3104 | if (TREE_CODE (exp) != INTEGER_CST) | |
ed4fbfa0 OH |
3105 | ENCODE_SECTION_INFO (exp, true); |
3106 | ||
a79e3a45 | 3107 | desc->rtl = rtl; |
e1b4533c AO |
3108 | desc->label = XSTR (XEXP (desc->rtl, 0), 0); |
3109 | } | |
79e68feb RS |
3110 | #endif |
3111 | ||
bd7cf17e JJ |
3112 | #ifdef CONSTANT_AFTER_FUNCTION_P |
3113 | if (current_function_decl != 0 | |
3114 | && CONSTANT_AFTER_FUNCTION_P (exp)) | |
3115 | after_function = 1; | |
3116 | #endif | |
3117 | ||
3118 | if (found | |
a79e3a45 | 3119 | && STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) |
bd7cf17e JJ |
3120 | && (!defer || defer_addressed_constants_flag || after_function)) |
3121 | { | |
3122 | defstr = (struct deferred_string **) | |
3123 | htab_find_slot_with_hash (const_str_htab, desc->label, | |
3124 | STRHASH (desc->label), NO_INSERT); | |
3125 | if (defstr) | |
3126 | { | |
3127 | /* If the string is currently deferred but we need to output it now, | |
3128 | remove it from deferred string hash table. */ | |
3129 | found = 0; | |
3130 | labelno = (*defstr)->labelno; | |
a79e3a45 | 3131 | STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0; |
bd7cf17e JJ |
3132 | htab_clear_slot (const_str_htab, (void **) defstr); |
3133 | } | |
3134 | } | |
3135 | ||
ff8f4401 RS |
3136 | /* If this is the first time we've seen this particular constant, |
3137 | output it (or defer its output for later). */ | |
14a774a9 | 3138 | if (! found) |
79e68feb | 3139 | { |
8839fca4 | 3140 | if (defer_addressed_constants_flag || after_function) |
ff8f4401 | 3141 | { |
a79e3a45 RK |
3142 | struct deferred_constant *p |
3143 | = (struct deferred_constant *) | |
3144 | xmalloc (sizeof (struct deferred_constant)); | |
ff8f4401 | 3145 | |
d12516f1 | 3146 | p->exp = copy_constant (exp); |
ff8f4401 | 3147 | p->reloc = reloc; |
bd7cf17e | 3148 | p->labelno = labelno; |
8839fca4 ILT |
3149 | if (after_function) |
3150 | { | |
3151 | p->next = after_function_constants; | |
3152 | after_function_constants = p; | |
3153 | } | |
3154 | else | |
3155 | { | |
3156 | p->next = deferred_constants; | |
3157 | deferred_constants = p; | |
3158 | } | |
ff8f4401 RS |
3159 | } |
3160 | else | |
3c350eb3 CB |
3161 | { |
3162 | /* Do no output if -fsyntax-only. */ | |
3163 | if (! flag_syntax_only) | |
bd7cf17e JJ |
3164 | { |
3165 | if (TREE_CODE (exp) != STRING_CST | |
3166 | || !defer | |
3167 | || flag_writable_strings | |
3168 | || (defstr = (struct deferred_string **) | |
3169 | htab_find_slot_with_hash (const_str_htab, | |
3170 | desc->label, | |
3171 | STRHASH (desc->label), | |
3172 | INSERT)) == NULL) | |
3173 | output_constant_def_contents (exp, reloc, labelno); | |
3174 | else | |
3175 | { | |
3176 | struct deferred_string *p; | |
3177 | ||
3178 | p = (struct deferred_string *) | |
3179 | xmalloc (sizeof (struct deferred_string)); | |
3180 | ||
3181 | p->exp = copy_constant (exp); | |
3182 | p->label = desc->label; | |
3183 | p->labelno = labelno; | |
3184 | *defstr = p; | |
a79e3a45 | 3185 | STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1; |
bd7cf17e JJ |
3186 | } |
3187 | } | |
3c350eb3 | 3188 | } |
ff8f4401 RS |
3189 | } |
3190 | ||
a79e3a45 | 3191 | return rtl; |
ff8f4401 RS |
3192 | } |
3193 | ||
3194 | /* Now output assembler code to define the label for EXP, | |
3195 | and follow it with the data of EXP. */ | |
79e68feb | 3196 | |
ff8f4401 RS |
3197 | static void |
3198 | output_constant_def_contents (exp, reloc, labelno) | |
3199 | tree exp; | |
3200 | int reloc; | |
3201 | int labelno; | |
3202 | { | |
3203 | int align; | |
3204 | ||
201556f0 JJ |
3205 | /* Align the location counter as required by EXP's data type. */ |
3206 | align = TYPE_ALIGN (TREE_TYPE (exp)); | |
3207 | #ifdef CONSTANT_ALIGNMENT | |
3208 | align = CONSTANT_ALIGNMENT (exp, align); | |
3209 | #endif | |
3210 | ||
8a425a05 | 3211 | if (IN_NAMED_SECTION (exp)) |
ad4ff310 | 3212 | named_section (exp, NULL, reloc); |
8a425a05 DE |
3213 | else |
3214 | { | |
3215 | /* First switch to text section, except for writable strings. */ | |
79e68feb | 3216 | #ifdef SELECT_SECTION |
201556f0 | 3217 | SELECT_SECTION (exp, reloc, align); |
79e68feb | 3218 | #else |
8a425a05 DE |
3219 | if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings) |
3220 | || (flag_pic && reloc)) | |
3221 | data_section (); | |
3222 | else | |
3223 | readonly_data_section (); | |
79e68feb | 3224 | #endif |
8a425a05 | 3225 | } |
79e68feb | 3226 | |
ff8f4401 | 3227 | if (align > BITS_PER_UNIT) |
91ea4f8d KG |
3228 | { |
3229 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
3230 | } | |
79e68feb | 3231 | |
ff8f4401 RS |
3232 | /* Output the label itself. */ |
3233 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno); | |
79e68feb | 3234 | |
ff8f4401 RS |
3235 | /* Output the value of EXP. */ |
3236 | output_constant (exp, | |
3237 | (TREE_CODE (exp) == STRING_CST | |
c6b74046 JDA |
3238 | ? MAX (TREE_STRING_LENGTH (exp), |
3239 | int_size_in_bytes (TREE_TYPE (exp))) | |
c8af3574 RH |
3240 | : int_size_in_bytes (TREE_TYPE (exp))), |
3241 | align); | |
79e68feb | 3242 | |
79e68feb RS |
3243 | } |
3244 | \f | |
79e68feb RS |
3245 | /* Structure to represent sufficient information about a constant so that |
3246 | it can be output when the constant pool is output, so that function | |
3247 | integration can be done, and to simplify handling on machines that reference | |
3248 | constant pool as base+displacement. */ | |
3249 | ||
3250 | struct pool_constant | |
3251 | { | |
3252 | struct constant_descriptor *desc; | |
94b01be3 | 3253 | struct pool_constant *next, *next_sym; |
79e68feb | 3254 | rtx constant; |
94b01be3 | 3255 | enum machine_mode mode; |
79e68feb | 3256 | int labelno; |
a79e3a45 RK |
3257 | unsigned int align; |
3258 | HOST_WIDE_INT offset; | |
91674c37 | 3259 | int mark; |
79e68feb RS |
3260 | }; |
3261 | ||
79e68feb RS |
3262 | /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true. |
3263 | The argument is XSTR (... , 0) */ | |
3264 | ||
3265 | #define SYMHASH(LABEL) \ | |
7bcac048 | 3266 | ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE) |
79e68feb | 3267 | \f |
36edd3cc | 3268 | /* Initialize constant pool hashing for a new function. */ |
79e68feb RS |
3269 | |
3270 | void | |
36edd3cc BS |
3271 | init_varasm_status (f) |
3272 | struct function *f; | |
79e68feb | 3273 | { |
36edd3cc BS |
3274 | struct varasm_status *p; |
3275 | p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status)); | |
3276 | f->varasm = p; | |
3277 | p->x_const_rtx_hash_table | |
57632c51 | 3278 | = ((struct constant_descriptor **) |
1f8f4a0b | 3279 | xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *))); |
36edd3cc | 3280 | p->x_const_rtx_sym_hash_table |
94b01be3 JJ |
3281 | = ((struct pool_constant **) |
3282 | xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *))); | |
79e68feb | 3283 | |
36edd3cc BS |
3284 | p->x_first_pool = p->x_last_pool = 0; |
3285 | p->x_pool_offset = 0; | |
57632c51 | 3286 | } |
e2ecd91c | 3287 | |
87ff9c8e RH |
3288 | /* Mark PC for GC. */ |
3289 | ||
46f9491e | 3290 | static void |
87ff9c8e RH |
3291 | mark_pool_constant (pc) |
3292 | struct pool_constant *pc; | |
3293 | { | |
3294 | while (pc) | |
3295 | { | |
1f8f4a0b | 3296 | ggc_mark (pc); |
87ff9c8e | 3297 | ggc_mark_rtx (pc->constant); |
a79e3a45 | 3298 | ggc_mark_rtx (pc->desc->rtl); |
87ff9c8e RH |
3299 | pc = pc->next; |
3300 | } | |
3301 | } | |
3302 | ||
3303 | /* Mark P for GC. */ | |
3304 | ||
3305 | void | |
fa51b01b RH |
3306 | mark_varasm_status (p) |
3307 | struct varasm_status *p; | |
87ff9c8e | 3308 | { |
fa51b01b RH |
3309 | if (p == NULL) |
3310 | return; | |
3311 | ||
87ff9c8e | 3312 | mark_pool_constant (p->x_first_pool); |
87ff9c8e RH |
3313 | } |
3314 | ||
21cd906e MM |
3315 | /* Clear out all parts of the state in F that can safely be discarded |
3316 | after the function has been compiled, to let garbage collection | |
0a8a198c | 3317 | reclaim the memory. */ |
21cd906e | 3318 | |
e2ecd91c | 3319 | void |
0a8a198c | 3320 | free_varasm_status (f) |
e2ecd91c BS |
3321 | struct function *f; |
3322 | { | |
21cd906e | 3323 | struct varasm_status *p; |
1f8f4a0b | 3324 | int i; |
21cd906e | 3325 | |
21cd906e | 3326 | p = f->varasm; |
1f8f4a0b MM |
3327 | |
3328 | /* Clear out the hash tables. */ | |
3329 | for (i = 0; i < MAX_RTX_HASH_TABLE; ++i) | |
3330 | { | |
a79e3a45 | 3331 | struct constant_descriptor *cd; |
1f8f4a0b MM |
3332 | |
3333 | cd = p->x_const_rtx_hash_table[i]; | |
a79e3a45 RK |
3334 | while (cd) |
3335 | { | |
3336 | struct constant_descriptor *next = cd->next; | |
3337 | ||
3338 | free (cd); | |
3339 | cd = next; | |
3340 | } | |
1f8f4a0b MM |
3341 | } |
3342 | ||
e2ecd91c BS |
3343 | free (p->x_const_rtx_hash_table); |
3344 | free (p->x_const_rtx_sym_hash_table); | |
fa51b01b | 3345 | free (p); |
a79e3a45 | 3346 | |
fa51b01b | 3347 | f->varasm = NULL; |
e2ecd91c | 3348 | } |
57632c51 | 3349 | \f |
79e68feb | 3350 | |
79e68feb RS |
3351 | /* Express an rtx for a constant integer (perhaps symbolic) |
3352 | as the sum of a symbol or label plus an explicit integer. | |
3353 | They are stored into VALUE. */ | |
3354 | ||
3355 | static void | |
3356 | decode_rtx_const (mode, x, value) | |
3357 | enum machine_mode mode; | |
3358 | rtx x; | |
3359 | struct rtx_const *value; | |
3360 | { | |
3361 | /* Clear the whole structure, including any gaps. */ | |
da61dec9 | 3362 | memset (value, 0, sizeof (struct rtx_const)); |
79e68feb | 3363 | |
0f41302f | 3364 | value->kind = RTX_INT; /* Most usual kind. */ |
79e68feb RS |
3365 | value->mode = mode; |
3366 | ||
3367 | switch (GET_CODE (x)) | |
3368 | { | |
3369 | case CONST_DOUBLE: | |
3370 | value->kind = RTX_DOUBLE; | |
56e2d435 | 3371 | if (GET_MODE (x) != VOIDmode) |
0b19a5b9 RK |
3372 | { |
3373 | value->mode = GET_MODE (x); | |
b216cd4a | 3374 | REAL_VALUE_FROM_CONST_DOUBLE (value->un.du, x); |
0b19a5b9 RK |
3375 | } |
3376 | else | |
3377 | { | |
3378 | value->un.di.low = CONST_DOUBLE_LOW (x); | |
3379 | value->un.di.high = CONST_DOUBLE_HIGH (x); | |
3380 | } | |
79e68feb RS |
3381 | break; |
3382 | ||
69ef87e2 AH |
3383 | case CONST_VECTOR: |
3384 | { | |
3385 | int units, i; | |
3386 | rtx elt; | |
3387 | ||
3388 | units = CONST_VECTOR_NUNITS (x); | |
3389 | value->kind = RTX_VECTOR; | |
3390 | value->mode = mode; | |
3391 | ||
3392 | for (i = 0; i < units; ++i) | |
3393 | { | |
3394 | elt = CONST_VECTOR_ELT (x, i); | |
3395 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) | |
3396 | { | |
3397 | value->un.veclo[i] = (HOST_WIDE_INT) INTVAL (elt); | |
3398 | value->un.vechi[i] = 0; | |
3399 | } | |
3400 | else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
3401 | { | |
3402 | value->un.veclo[i] = (HOST_WIDE_INT) CONST_DOUBLE_LOW (elt); | |
3403 | value->un.vechi[i] = (HOST_WIDE_INT) CONST_DOUBLE_HIGH (elt); | |
3404 | } | |
3405 | else | |
3406 | abort (); | |
3407 | } | |
3408 | } | |
3409 | break; | |
3410 | ||
79e68feb RS |
3411 | case CONST_INT: |
3412 | value->un.addr.offset = INTVAL (x); | |
3413 | break; | |
3414 | ||
3415 | case SYMBOL_REF: | |
3416 | case LABEL_REF: | |
3d037392 | 3417 | case PC: |
79e68feb RS |
3418 | value->un.addr.base = x; |
3419 | break; | |
3420 | ||
3421 | case CONST: | |
3422 | x = XEXP (x, 0); | |
422be3c3 | 3423 | if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) |
79e68feb RS |
3424 | { |
3425 | value->un.addr.base = XEXP (x, 0); | |
79e68feb RS |
3426 | value->un.addr.offset = INTVAL (XEXP (x, 1)); |
3427 | } | |
422be3c3 | 3428 | else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT) |
79e68feb RS |
3429 | { |
3430 | value->un.addr.base = XEXP (x, 0); | |
79e68feb RS |
3431 | value->un.addr.offset = - INTVAL (XEXP (x, 1)); |
3432 | } | |
3433 | else | |
422be3c3 AO |
3434 | { |
3435 | value->un.addr.base = x; | |
3436 | value->un.addr.offset = 0; | |
3437 | } | |
79e68feb RS |
3438 | break; |
3439 | ||
3440 | default: | |
fdf473ae RH |
3441 | value->kind = RTX_UNKNOWN; |
3442 | break; | |
79e68feb RS |
3443 | } |
3444 | ||
fecaac37 HP |
3445 | if (value->kind == RTX_INT && value->un.addr.base != 0 |
3446 | && GET_CODE (value->un.addr.base) == UNSPEC) | |
c26fbbca | 3447 | { |
fecaac37 HP |
3448 | /* For a simple UNSPEC, the base is set to the |
3449 | operand, the kind field is set to the index of | |
c26fbbca | 3450 | the unspec expression. |
fecaac37 | 3451 | Together with the code below, in case that |
c26fbbca KH |
3452 | the operand is a SYMBOL_REF or LABEL_REF, |
3453 | the address of the string or the code_label | |
fecaac37 HP |
3454 | is taken as base. */ |
3455 | if (XVECLEN (value->un.addr.base, 0) == 1) | |
c26fbbca | 3456 | { |
fecaac37 HP |
3457 | value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1); |
3458 | value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0); | |
3459 | } | |
3460 | } | |
3461 | ||
fdf473ae | 3462 | if (value->kind > RTX_DOUBLE && value->un.addr.base != 0) |
79e68feb RS |
3463 | switch (GET_CODE (value->un.addr.base)) |
3464 | { | |
3465 | case SYMBOL_REF: | |
79e68feb | 3466 | /* Use the string's address, not the SYMBOL_REF's address, |
241a1bcc | 3467 | for the sake of addresses of library routines. */ |
dd1bd863 | 3468 | value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0); |
241a1bcc FS |
3469 | break; |
3470 | ||
3471 | case LABEL_REF: | |
3472 | /* For a LABEL_REF, compare labels. */ | |
79e68feb | 3473 | value->un.addr.base = XEXP (value->un.addr.base, 0); |
46f9491e | 3474 | |
e9a25f70 JL |
3475 | default: |
3476 | break; | |
79e68feb RS |
3477 | } |
3478 | } | |
3479 | ||
57632c51 RS |
3480 | /* Given a MINUS expression, simplify it if both sides |
3481 | include the same symbol. */ | |
3482 | ||
3483 | rtx | |
3484 | simplify_subtraction (x) | |
3485 | rtx x; | |
3486 | { | |
3487 | struct rtx_const val0, val1; | |
3488 | ||
3489 | decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0); | |
3490 | decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1); | |
3491 | ||
fdf473ae RH |
3492 | if (val0.kind > RTX_DOUBLE |
3493 | && val0.kind == val1.kind | |
fecaac37 | 3494 | && val0.un.addr.base == val1.un.addr.base) |
57632c51 | 3495 | return GEN_INT (val0.un.addr.offset - val1.un.addr.offset); |
fdf473ae | 3496 | |
57632c51 RS |
3497 | return x; |
3498 | } | |
3499 | ||
79e68feb RS |
3500 | /* Compute a hash code for a constant RTL expression. */ |
3501 | ||
5a13eaa4 | 3502 | static int |
79e68feb RS |
3503 | const_hash_rtx (mode, x) |
3504 | enum machine_mode mode; | |
3505 | rtx x; | |
3506 | { | |
b3694847 SS |
3507 | int hi; |
3508 | size_t i; | |
79e68feb RS |
3509 | |
3510 | struct rtx_const value; | |
3511 | decode_rtx_const (mode, x, &value); | |
3512 | ||
3513 | /* Compute hashing function */ | |
3514 | hi = 0; | |
3515 | for (i = 0; i < sizeof value / sizeof (int); i++) | |
3516 | hi += ((int *) &value)[i]; | |
3517 | ||
3518 | hi &= (1 << HASHBITS) - 1; | |
3519 | hi %= MAX_RTX_HASH_TABLE; | |
3520 | return hi; | |
3521 | } | |
3522 | ||
3523 | /* Compare a constant rtl object X with a constant-descriptor DESC. | |
3524 | Return 1 if DESC describes a constant with the same value as X. */ | |
3525 | ||
3526 | static int | |
3527 | compare_constant_rtx (mode, x, desc) | |
3528 | enum machine_mode mode; | |
3529 | rtx x; | |
3530 | struct constant_descriptor *desc; | |
3531 | { | |
b3694847 SS |
3532 | int *p = (int *) desc->u.contents; |
3533 | int *strp; | |
3534 | int len; | |
79e68feb RS |
3535 | struct rtx_const value; |
3536 | ||
3537 | decode_rtx_const (mode, x, &value); | |
3538 | strp = (int *) &value; | |
3539 | len = sizeof value / sizeof (int); | |
3540 | ||
3541 | /* Compare constant contents. */ | |
3542 | while (--len >= 0) | |
3543 | if (*p++ != *strp++) | |
3544 | return 0; | |
3545 | ||
3546 | return 1; | |
3547 | } | |
3548 | ||
3549 | /* Construct a constant descriptor for the rtl-expression X. | |
3550 | It is up to the caller to enter the descriptor in the hash table. */ | |
3551 | ||
3552 | static struct constant_descriptor * | |
3553 | record_constant_rtx (mode, x) | |
3554 | enum machine_mode mode; | |
3555 | rtx x; | |
3556 | { | |
3557 | struct constant_descriptor *ptr; | |
79e68feb | 3558 | |
46f9491e | 3559 | ptr = ((struct constant_descriptor *) |
37357796 RE |
3560 | xcalloc (1, (offsetof (struct constant_descriptor, u) |
3561 | + sizeof (struct rtx_const)))); | |
3562 | decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents); | |
79e68feb | 3563 | |
1f8f4a0b | 3564 | return ptr; |
79e68feb RS |
3565 | } |
3566 | \f | |
03f54026 RK |
3567 | /* Given a constant rtx X, return a MEM for the location in memory at which |
3568 | this constant has been placed. Return 0 if it not has been placed yet. */ | |
3569 | ||
3570 | rtx | |
3571 | mem_for_const_double (x) | |
3572 | rtx x; | |
3573 | { | |
3574 | enum machine_mode mode = GET_MODE (x); | |
3575 | struct constant_descriptor *desc; | |
3576 | ||
3577 | for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc; | |
3578 | desc = desc->next) | |
3579 | if (compare_constant_rtx (mode, x, desc)) | |
3580 | return desc->rtl; | |
3581 | ||
3582 | return 0; | |
3583 | } | |
c26fbbca | 3584 | |
79e68feb RS |
3585 | /* Given a constant rtx X, make (or find) a memory constant for its value |
3586 | and return a MEM rtx to refer to it in memory. */ | |
3587 | ||
3588 | rtx | |
3589 | force_const_mem (mode, x) | |
3590 | enum machine_mode mode; | |
3591 | rtx x; | |
3592 | { | |
b3694847 SS |
3593 | int hash; |
3594 | struct constant_descriptor *desc; | |
79e68feb | 3595 | char label[256]; |
79e68feb | 3596 | rtx def; |
a79e3a45 RK |
3597 | struct pool_constant *pool; |
3598 | unsigned int align; | |
79e68feb RS |
3599 | |
3600 | /* Compute hash code of X. Search the descriptors for that hash code | |
a79e3a45 | 3601 | to see if any of them describes X. If yes, we have an rtx to use. */ |
79e68feb | 3602 | hash = const_hash_rtx (mode, x); |
79e68feb RS |
3603 | for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next) |
3604 | if (compare_constant_rtx (mode, x, desc)) | |
a79e3a45 RK |
3605 | return desc->rtl; |
3606 | ||
3607 | /* No constant equal to X is known to have been output. | |
3608 | Make a constant descriptor to enter X in the hash table | |
3609 | and make a MEM for it. */ | |
3610 | desc = record_constant_rtx (mode, x); | |
3611 | desc->next = const_rtx_hash_table[hash]; | |
3612 | const_rtx_hash_table[hash] = desc; | |
c26fbbca | 3613 | |
a79e3a45 RK |
3614 | /* Align the location counter as required by EXP's data type. */ |
3615 | align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode); | |
e5e8a8bf | 3616 | #ifdef CONSTANT_ALIGNMENT |
b0c48229 NB |
3617 | align = CONSTANT_ALIGNMENT (make_tree ((*lang_hooks.types.type_for_mode) |
3618 | (mode, 0), x), align); | |
e5e8a8bf | 3619 | #endif |
79e68feb | 3620 | |
a79e3a45 RK |
3621 | pool_offset += (align / BITS_PER_UNIT) - 1; |
3622 | pool_offset &= ~ ((align / BITS_PER_UNIT) - 1); | |
3623 | ||
3624 | if (GET_CODE (x) == LABEL_REF) | |
3625 | LABEL_PRESERVE_P (XEXP (x, 0)) = 1; | |
3626 | ||
3627 | /* Allocate a pool constant descriptor, fill it in, and chain it in. */ | |
3628 | pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant)); | |
3629 | pool->desc = desc; | |
3630 | pool->constant = x; | |
3631 | pool->mode = mode; | |
3632 | pool->labelno = const_labelno; | |
3633 | pool->align = align; | |
3634 | pool->offset = pool_offset; | |
3635 | pool->mark = 1; | |
3636 | pool->next = 0; | |
3637 | ||
3638 | if (last_pool == 0) | |
3639 | first_pool = pool; | |
3640 | else | |
3641 | last_pool->next = pool; | |
c26fbbca | 3642 | |
a79e3a45 RK |
3643 | last_pool = pool; |
3644 | pool_offset += GET_MODE_SIZE (mode); | |
79e68feb | 3645 | |
a79e3a45 RK |
3646 | /* Create a string containing the label name, in LABEL. */ |
3647 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
79e68feb | 3648 | |
a79e3a45 | 3649 | ++const_labelno; |
79e68feb | 3650 | |
a79e3a45 | 3651 | /* Construct the SYMBOL_REF and the MEM. */ |
79e68feb | 3652 | |
a79e3a45 RK |
3653 | pool->desc->rtl = def |
3654 | = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label))); | |
3655 | set_mem_alias_set (def, const_alias_set); | |
b0c48229 | 3656 | set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1); |
79e68feb | 3657 | RTX_UNCHANGING_P (def) = 1; |
289c5b45 | 3658 | |
a79e3a45 RK |
3659 | /* Add label to symbol hash table. */ |
3660 | hash = SYMHASH (XSTR (XEXP (def, 0), 0)); | |
3661 | pool->next_sym = const_rtx_sym_hash_table[hash]; | |
3662 | const_rtx_sym_hash_table[hash] = pool; | |
3663 | ||
79e68feb RS |
3664 | /* Mark the symbol_ref as belonging to this constants pool. */ |
3665 | CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1; | |
3666 | current_function_uses_const_pool = 1; | |
3667 | ||
79e68feb RS |
3668 | return def; |
3669 | } | |
3670 | \f | |
3671 | /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to | |
3672 | the corresponding pool_constant structure. */ | |
3673 | ||
3674 | static struct pool_constant * | |
36edd3cc BS |
3675 | find_pool_constant (f, addr) |
3676 | struct function *f; | |
79e68feb RS |
3677 | rtx addr; |
3678 | { | |
94b01be3 | 3679 | struct pool_constant *pool; |
3cce094d | 3680 | const char *label = XSTR (addr, 0); |
79e68feb | 3681 | |
94b01be3 JJ |
3682 | for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool; |
3683 | pool = pool->next_sym) | |
a79e3a45 | 3684 | if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label) |
94b01be3 | 3685 | return pool; |
79e68feb RS |
3686 | |
3687 | abort (); | |
3688 | } | |
3689 | ||
3690 | /* Given a constant pool SYMBOL_REF, return the corresponding constant. */ | |
3691 | ||
3692 | rtx | |
3693 | get_pool_constant (addr) | |
3694 | rtx addr; | |
3695 | { | |
01d939e8 | 3696 | return (find_pool_constant (cfun, addr))->constant; |
36edd3cc BS |
3697 | } |
3698 | ||
149d6f9e JJ |
3699 | /* Given a constant pool SYMBOL_REF, return the corresponding constant |
3700 | and whether it has been output or not. */ | |
3701 | ||
3702 | rtx | |
3703 | get_pool_constant_mark (addr, pmarked) | |
3704 | rtx addr; | |
3705 | bool *pmarked; | |
3706 | { | |
3707 | struct pool_constant *pool = find_pool_constant (cfun, addr); | |
3708 | *pmarked = (pool->mark != 0); | |
3709 | return pool->constant; | |
3710 | } | |
3711 | ||
36edd3cc BS |
3712 | /* Likewise, but for the constant pool of a specific function. */ |
3713 | ||
3714 | rtx | |
3715 | get_pool_constant_for_function (f, addr) | |
3716 | struct function *f; | |
3717 | rtx addr; | |
3718 | { | |
3719 | return (find_pool_constant (f, addr))->constant; | |
79e68feb RS |
3720 | } |
3721 | ||
3722 | /* Similar, return the mode. */ | |
3723 | ||
3724 | enum machine_mode | |
3725 | get_pool_mode (addr) | |
3726 | rtx addr; | |
3727 | { | |
01d939e8 | 3728 | return (find_pool_constant (cfun, addr))->mode; |
36edd3cc BS |
3729 | } |
3730 | ||
3731 | enum machine_mode | |
3732 | get_pool_mode_for_function (f, addr) | |
3733 | struct function *f; | |
3734 | rtx addr; | |
3735 | { | |
3736 | return (find_pool_constant (f, addr))->mode; | |
79e68feb RS |
3737 | } |
3738 | ||
3739 | /* Similar, return the offset in the constant pool. */ | |
3740 | ||
3741 | int | |
3742 | get_pool_offset (addr) | |
3743 | rtx addr; | |
3744 | { | |
01d939e8 | 3745 | return (find_pool_constant (cfun, addr))->offset; |
79e68feb RS |
3746 | } |
3747 | ||
3748 | /* Return the size of the constant pool. */ | |
3749 | ||
3750 | int | |
3751 | get_pool_size () | |
3752 | { | |
3753 | return pool_offset; | |
3754 | } | |
3755 | \f | |
3756 | /* Write all the constants in the constant pool. */ | |
3757 | ||
3758 | void | |
3759 | output_constant_pool (fnname, fndecl) | |
c26fbbca KH |
3760 | const char *fnname ATTRIBUTE_UNUSED; |
3761 | tree fndecl ATTRIBUTE_UNUSED; | |
79e68feb RS |
3762 | { |
3763 | struct pool_constant *pool; | |
3764 | rtx x; | |
b216cd4a | 3765 | REAL_VALUE_TYPE r; |
79e68feb | 3766 | |
91674c37 ILT |
3767 | /* It is possible for gcc to call force_const_mem and then to later |
3768 | discard the instructions which refer to the constant. In such a | |
3769 | case we do not need to output the constant. */ | |
8f0e7be4 | 3770 | mark_constant_pool (); |
91674c37 | 3771 | |
79e68feb RS |
3772 | #ifdef ASM_OUTPUT_POOL_PROLOGUE |
3773 | ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset); | |
3774 | #endif | |
3775 | ||
3776 | for (pool = first_pool; pool; pool = pool->next) | |
3777 | { | |
085ce8c6 RH |
3778 | rtx tmp; |
3779 | ||
79e68feb RS |
3780 | x = pool->constant; |
3781 | ||
d2ce9169 | 3782 | if (! pool->mark) |
91674c37 ILT |
3783 | continue; |
3784 | ||
79e68feb RS |
3785 | /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF) |
3786 | whose CODE_LABEL has been deleted. This can occur if a jump table | |
3787 | is eliminated by optimization. If so, write a constant of zero | |
7b2b3f1f RK |
3788 | instead. Note that this can also happen by turning the |
3789 | CODE_LABEL into a NOTE. */ | |
085ce8c6 RH |
3790 | /* ??? This seems completely and utterly wrong. Certainly it's |
3791 | not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper | |
3792 | functioning even with INSN_DELETED_P and friends. */ | |
3793 | ||
3794 | tmp = x; | |
3795 | switch (GET_CODE (x)) | |
3796 | { | |
3797 | case CONST: | |
3798 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
3799 | || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
3800 | break; | |
3801 | tmp = XEXP (XEXP (x, 0), 0); | |
3802 | /* FALLTHRU */ | |
3803 | ||
3804 | case LABEL_REF: | |
3805 | tmp = XEXP (x, 0); | |
3806 | if (INSN_DELETED_P (tmp) | |
3807 | || (GET_CODE (tmp) == NOTE | |
3808 | && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED)) | |
3809 | { | |
3810 | abort (); | |
3811 | x = const0_rtx; | |
3812 | } | |
3813 | break; | |
46f9491e | 3814 | |
085ce8c6 RH |
3815 | default: |
3816 | break; | |
3817 | } | |
79e68feb RS |
3818 | |
3819 | /* First switch to correct section. */ | |
3820 | #ifdef SELECT_RTX_SECTION | |
201556f0 | 3821 | SELECT_RTX_SECTION (pool->mode, x, pool->align); |
79e68feb RS |
3822 | #else |
3823 | readonly_data_section (); | |
3824 | #endif | |
3825 | ||
3826 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY | |
3827 | ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode, | |
3828 | pool->align, pool->labelno, done); | |
3829 | #endif | |
3830 | ||
09e07be6 | 3831 | assemble_align (pool->align); |
79e68feb RS |
3832 | |
3833 | /* Output the label. */ | |
3834 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno); | |
3835 | ||
3836 | /* Output the value of the constant itself. */ | |
3837 | switch (GET_MODE_CLASS (pool->mode)) | |
3838 | { | |
3839 | case MODE_FLOAT: | |
3840 | if (GET_CODE (x) != CONST_DOUBLE) | |
3841 | abort (); | |
3842 | ||
b216cd4a ZW |
3843 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
3844 | assemble_real (r, pool->mode, pool->align); | |
79e68feb RS |
3845 | break; |
3846 | ||
3847 | case MODE_INT: | |
ab8ab9d0 | 3848 | case MODE_PARTIAL_INT: |
c8af3574 | 3849 | assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1); |
79e68feb RS |
3850 | break; |
3851 | ||
69ef87e2 AH |
3852 | case MODE_VECTOR_FLOAT: |
3853 | { | |
3854 | int i, units; | |
3855 | rtx elt; | |
3856 | ||
3857 | if (GET_CODE (x) != CONST_VECTOR) | |
3858 | abort (); | |
3859 | ||
3860 | units = CONST_VECTOR_NUNITS (x); | |
3861 | ||
3862 | for (i = 0; i < units; i++) | |
3863 | { | |
3864 | elt = CONST_VECTOR_ELT (x, i); | |
b216cd4a ZW |
3865 | REAL_VALUE_FROM_CONST_DOUBLE (r, elt); |
3866 | assemble_real (r, GET_MODE_INNER (pool->mode), pool->align); | |
69ef87e2 AH |
3867 | } |
3868 | } | |
3869 | break; | |
3870 | ||
c26fbbca | 3871 | case MODE_VECTOR_INT: |
69ef87e2 AH |
3872 | { |
3873 | int i, units; | |
3874 | rtx elt; | |
3875 | ||
3876 | if (GET_CODE (x) != CONST_VECTOR) | |
3877 | abort (); | |
3878 | ||
3879 | units = CONST_VECTOR_NUNITS (x); | |
3880 | ||
3881 | for (i = 0; i < units; i++) | |
3882 | { | |
3883 | elt = CONST_VECTOR_ELT (x, i); | |
3884 | assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode), | |
3885 | pool->align, 1); | |
3886 | } | |
3887 | } | |
3888 | break; | |
3889 | ||
79e68feb RS |
3890 | default: |
3891 | abort (); | |
3892 | } | |
3893 | ||
29a82058 JL |
3894 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY |
3895 | done: ; | |
3896 | #endif | |
7f83c0e7 JL |
3897 | } |
3898 | ||
5c8c0abd ILT |
3899 | #ifdef ASM_OUTPUT_POOL_EPILOGUE |
3900 | ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset); | |
3901 | #endif | |
3902 | ||
79e68feb RS |
3903 | /* Done with this pool. */ |
3904 | first_pool = last_pool = 0; | |
3905 | } | |
91674c37 ILT |
3906 | |
3907 | /* Look through the instructions for this function, and mark all the | |
fcbd8ef2 JO |
3908 | entries in the constant pool which are actually being used. |
3909 | Emit used deferred strings. */ | |
91674c37 ILT |
3910 | |
3911 | static void | |
3912 | mark_constant_pool () | |
3913 | { | |
b3694847 | 3914 | rtx insn; |
d2ce9169 | 3915 | struct pool_constant *pool; |
91674c37 | 3916 | |
bd7cf17e | 3917 | if (first_pool == 0 && htab_elements (const_str_htab) == 0) |
91674c37 ILT |
3918 | return; |
3919 | ||
d2ce9169 RK |
3920 | for (pool = first_pool; pool; pool = pool->next) |
3921 | pool->mark = 0; | |
3922 | ||
91674c37 | 3923 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
2c3c49de | 3924 | if (INSN_P (insn)) |
91674c37 ILT |
3925 | mark_constants (PATTERN (insn)); |
3926 | ||
3927 | for (insn = current_function_epilogue_delay_list; | |
3928 | insn; | |
3929 | insn = XEXP (insn, 1)) | |
2c3c49de | 3930 | if (INSN_P (insn)) |
91674c37 ILT |
3931 | mark_constants (PATTERN (insn)); |
3932 | } | |
3933 | ||
fcbd8ef2 JO |
3934 | /* Look through appropriate parts of X, marking all entries in the |
3935 | constant pool which are actually being used. Entries that are only | |
3936 | referenced by other constants are also marked as used. Emit | |
3937 | deferred strings that are used. */ | |
3938 | ||
91674c37 ILT |
3939 | static void |
3940 | mark_constants (x) | |
fcbd8ef2 | 3941 | rtx x; |
91674c37 | 3942 | { |
b3694847 SS |
3943 | int i; |
3944 | const char *format_ptr; | |
91674c37 ILT |
3945 | |
3946 | if (x == 0) | |
3947 | return; | |
3948 | ||
3949 | if (GET_CODE (x) == SYMBOL_REF) | |
3950 | { | |
fcbd8ef2 | 3951 | mark_constant (&x, NULL); |
91674c37 ILT |
3952 | return; |
3953 | } | |
3954 | ||
3955 | /* Insns may appear inside a SEQUENCE. Only check the patterns of | |
3956 | insns, not any notes that may be attached. We don't want to mark | |
3957 | a constant just because it happens to appear in a REG_EQUIV note. */ | |
2c3c49de | 3958 | if (INSN_P (x)) |
91674c37 ILT |
3959 | { |
3960 | mark_constants (PATTERN (x)); | |
3961 | return; | |
3962 | } | |
3963 | ||
3964 | format_ptr = GET_RTX_FORMAT (GET_CODE (x)); | |
3965 | ||
3966 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++) | |
3967 | { | |
3968 | switch (*format_ptr++) | |
3969 | { | |
3970 | case 'e': | |
3971 | mark_constants (XEXP (x, i)); | |
3972 | break; | |
3973 | ||
3974 | case 'E': | |
3975 | if (XVEC (x, i) != 0) | |
3976 | { | |
b3694847 | 3977 | int j; |
91674c37 ILT |
3978 | |
3979 | for (j = 0; j < XVECLEN (x, i); j++) | |
3980 | mark_constants (XVECEXP (x, i, j)); | |
3981 | } | |
3982 | break; | |
3983 | ||
3984 | case 'S': | |
3985 | case 's': | |
3986 | case '0': | |
3987 | case 'i': | |
3988 | case 'w': | |
3989 | case 'n': | |
3990 | case 'u': | |
3991 | break; | |
3992 | ||
3993 | default: | |
3994 | abort (); | |
3995 | } | |
3996 | } | |
3997 | } | |
fcbd8ef2 JO |
3998 | |
3999 | /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers | |
4000 | to as used. Emit referenced deferred strings. This function can | |
a79e3a45 | 4001 | be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */ |
fcbd8ef2 JO |
4002 | |
4003 | static int | |
4004 | mark_constant (current_rtx, data) | |
4005 | rtx *current_rtx; | |
4006 | void *data ATTRIBUTE_UNUSED; | |
4007 | { | |
4008 | rtx x = *current_rtx; | |
4009 | ||
4010 | if (x == NULL_RTX) | |
4011 | return 0; | |
a79e3a45 | 4012 | |
fcbd8ef2 JO |
4013 | else if (GET_CODE (x) == SYMBOL_REF) |
4014 | { | |
4015 | if (CONSTANT_POOL_ADDRESS_P (x)) | |
4016 | { | |
4017 | struct pool_constant *pool = find_pool_constant (cfun, x); | |
c26fbbca KH |
4018 | if (pool->mark == 0) |
4019 | { | |
4020 | pool->mark = 1; | |
4021 | for_each_rtx (&(pool->constant), &mark_constant, NULL); | |
4022 | } | |
fcbd8ef2 JO |
4023 | else |
4024 | return -1; | |
4025 | } | |
4026 | else if (STRING_POOL_ADDRESS_P (x)) | |
4027 | { | |
4028 | struct deferred_string **defstr; | |
4029 | ||
4030 | defstr = (struct deferred_string **) | |
4031 | htab_find_slot_with_hash (const_str_htab, XSTR (x, 0), | |
4032 | STRHASH (XSTR (x, 0)), NO_INSERT); | |
4033 | if (defstr) | |
4034 | { | |
4035 | struct deferred_string *p = *defstr; | |
4036 | ||
4037 | STRING_POOL_ADDRESS_P (x) = 0; | |
4038 | output_constant_def_contents (p->exp, 0, p->labelno); | |
4039 | htab_clear_slot (const_str_htab, (void **) defstr); | |
4040 | } | |
4041 | } | |
4042 | } | |
4043 | return 0; | |
4044 | } | |
79e68feb RS |
4045 | \f |
4046 | /* Find all the constants whose addresses are referenced inside of EXP, | |
4047 | and make sure assembler code with a label has been output for each one. | |
4048 | Indicate whether an ADDR_EXPR has been encountered. */ | |
4049 | ||
5a13eaa4 | 4050 | static int |
79e68feb RS |
4051 | output_addressed_constants (exp) |
4052 | tree exp; | |
4053 | { | |
4054 | int reloc = 0; | |
ac79cd5a | 4055 | tree tem; |
79e68feb | 4056 | |
c165f94f CC |
4057 | /* Give the front-end a chance to convert VALUE to something that |
4058 | looks more like a constant to the back-end. */ | |
ac79cd5a | 4059 | exp = (*lang_hooks.expand_constant) (exp); |
c165f94f | 4060 | |
79e68feb RS |
4061 | switch (TREE_CODE (exp)) |
4062 | { | |
4063 | case ADDR_EXPR: | |
ac79cd5a RK |
4064 | /* Go inside any operations that get_inner_reference can handle and see |
4065 | if what's inside is a constant: no need to do anything here for | |
4066 | addresses of variables or functions. */ | |
4067 | for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem); | |
4068 | tem = TREE_OPERAND (tem, 0)) | |
4069 | ; | |
79e68feb | 4070 | |
ac79cd5a RK |
4071 | if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c' |
4072 | || TREE_CODE (tem) == CONSTRUCTOR) | |
4073 | output_constant_def (tem, 0); | |
79e68feb | 4074 | |
d2c35e67 JH |
4075 | if (TREE_PUBLIC (tem)) |
4076 | reloc |= 2; | |
4077 | else | |
4078 | reloc |= 1; | |
79e68feb RS |
4079 | break; |
4080 | ||
4081 | case PLUS_EXPR: | |
4082 | case MINUS_EXPR: | |
4083 | reloc = output_addressed_constants (TREE_OPERAND (exp, 0)); | |
4084 | reloc |= output_addressed_constants (TREE_OPERAND (exp, 1)); | |
4085 | break; | |
4086 | ||
4087 | case NOP_EXPR: | |
4088 | case CONVERT_EXPR: | |
37a52112 | 4089 | case NON_LVALUE_EXPR: |
79e68feb RS |
4090 | reloc = output_addressed_constants (TREE_OPERAND (exp, 0)); |
4091 | break; | |
4092 | ||
4093 | case CONSTRUCTOR: | |
ac79cd5a RK |
4094 | for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem)) |
4095 | if (TREE_VALUE (tem) != 0) | |
c26fbbca | 4096 | reloc |= output_addressed_constants (TREE_VALUE (tem)); |
ac79cd5a | 4097 | |
79e68feb RS |
4098 | break; |
4099 | ||
e9a25f70 | 4100 | default: |
79e68feb RS |
4101 | break; |
4102 | } | |
4103 | return reloc; | |
4104 | } | |
4105 | \f | |
14a774a9 RK |
4106 | /* Return nonzero if VALUE is a valid constant-valued expression |
4107 | for use in initializing a static variable; one that can be an | |
4108 | element of a "constant" initializer. | |
4109 | ||
4110 | Return null_pointer_node if the value is absolute; | |
4111 | if it is relocatable, return the variable that determines the relocation. | |
4112 | We assume that VALUE has been folded as much as possible; | |
4113 | therefore, we do not need to check for such things as | |
4114 | arithmetic-combinations of integers. */ | |
4115 | ||
4116 | tree | |
4117 | initializer_constant_valid_p (value, endtype) | |
4118 | tree value; | |
4119 | tree endtype; | |
4120 | { | |
99740276 MM |
4121 | /* Give the front-end a chance to convert VALUE to something that |
4122 | looks more like a constant to the back-end. */ | |
ac79cd5a | 4123 | value = (*lang_hooks.expand_constant) (value); |
99740276 | 4124 | |
14a774a9 RK |
4125 | switch (TREE_CODE (value)) |
4126 | { | |
4127 | case CONSTRUCTOR: | |
4128 | if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE | |
4129 | || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE) | |
4130 | && TREE_CONSTANT (value) | |
4131 | && CONSTRUCTOR_ELTS (value)) | |
4132 | return | |
4133 | initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)), | |
4134 | endtype); | |
46f9491e | 4135 | |
14a774a9 RK |
4136 | return TREE_STATIC (value) ? null_pointer_node : 0; |
4137 | ||
4138 | case INTEGER_CST: | |
69ef87e2 | 4139 | case VECTOR_CST: |
14a774a9 RK |
4140 | case REAL_CST: |
4141 | case STRING_CST: | |
4142 | case COMPLEX_CST: | |
4143 | return null_pointer_node; | |
4144 | ||
4145 | case ADDR_EXPR: | |
67231816 | 4146 | case FDESC_EXPR: |
8c8de5fc | 4147 | return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0; |
14a774a9 | 4148 | |
ed239f5a | 4149 | case VIEW_CONVERT_EXPR: |
14a774a9 RK |
4150 | case NON_LVALUE_EXPR: |
4151 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); | |
4152 | ||
4153 | case CONVERT_EXPR: | |
4154 | case NOP_EXPR: | |
4155 | /* Allow conversions between pointer types. */ | |
4156 | if (POINTER_TYPE_P (TREE_TYPE (value)) | |
4157 | && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) | |
4158 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); | |
4159 | ||
4160 | /* Allow conversions between real types. */ | |
4161 | if (FLOAT_TYPE_P (TREE_TYPE (value)) | |
4162 | && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) | |
4163 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); | |
4164 | ||
4165 | /* Allow length-preserving conversions between integer types. */ | |
4166 | if (INTEGRAL_TYPE_P (TREE_TYPE (value)) | |
4167 | && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))) | |
4168 | && (TYPE_PRECISION (TREE_TYPE (value)) | |
4169 | == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) | |
4170 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); | |
4171 | ||
4172 | /* Allow conversions between other integer types only if | |
4173 | explicit value. */ | |
4174 | if (INTEGRAL_TYPE_P (TREE_TYPE (value)) | |
4175 | && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) | |
4176 | { | |
4177 | tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
4178 | endtype); | |
4179 | if (inner == null_pointer_node) | |
4180 | return null_pointer_node; | |
4181 | break; | |
4182 | } | |
4183 | ||
4184 | /* Allow (int) &foo provided int is as wide as a pointer. */ | |
4185 | if (INTEGRAL_TYPE_P (TREE_TYPE (value)) | |
4186 | && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))) | |
4187 | && (TYPE_PRECISION (TREE_TYPE (value)) | |
4188 | >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) | |
4189 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
4190 | endtype); | |
4191 | ||
4192 | /* Likewise conversions from int to pointers, but also allow | |
4193 | conversions from 0. */ | |
4194 | if (POINTER_TYPE_P (TREE_TYPE (value)) | |
4195 | && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))) | |
4196 | { | |
4197 | if (integer_zerop (TREE_OPERAND (value, 0))) | |
4198 | return null_pointer_node; | |
4199 | else if (TYPE_PRECISION (TREE_TYPE (value)) | |
4200 | <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))) | |
4201 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
4202 | endtype); | |
4203 | } | |
4204 | ||
4205 | /* Allow conversions to union types if the value inside is okay. */ | |
4206 | if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE) | |
4207 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
4208 | endtype); | |
4209 | break; | |
4210 | ||
4211 | case PLUS_EXPR: | |
4212 | if (! INTEGRAL_TYPE_P (endtype) | |
4213 | || TYPE_PRECISION (endtype) >= POINTER_SIZE) | |
c26fbbca | 4214 | { |
14a774a9 RK |
4215 | tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), |
4216 | endtype); | |
4217 | tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), | |
4218 | endtype); | |
4219 | /* If either term is absolute, use the other terms relocation. */ | |
4220 | if (valid0 == null_pointer_node) | |
4221 | return valid1; | |
4222 | if (valid1 == null_pointer_node) | |
4223 | return valid0; | |
c26fbbca | 4224 | } |
14a774a9 RK |
4225 | break; |
4226 | ||
4227 | case MINUS_EXPR: | |
4228 | if (! INTEGRAL_TYPE_P (endtype) | |
4229 | || TYPE_PRECISION (endtype) >= POINTER_SIZE) | |
4230 | { | |
4231 | tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
4232 | endtype); | |
4233 | tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), | |
4234 | endtype); | |
4235 | /* Win if second argument is absolute. */ | |
4236 | if (valid1 == null_pointer_node) | |
4237 | return valid0; | |
4238 | /* Win if both arguments have the same relocation. | |
4239 | Then the value is absolute. */ | |
4240 | if (valid0 == valid1 && valid0 != 0) | |
4241 | return null_pointer_node; | |
212addfa JO |
4242 | |
4243 | /* Since GCC guarantees that string constants are unique in the | |
4244 | generated code, a subtraction between two copies of the same | |
4245 | constant string is absolute. */ | |
4246 | if (valid0 && TREE_CODE (valid0) == STRING_CST && | |
4247 | valid1 && TREE_CODE (valid1) == STRING_CST && | |
4248 | TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1)) | |
4249 | return null_pointer_node; | |
14a774a9 RK |
4250 | } |
4251 | ||
4252 | /* Support differences between labels. */ | |
4253 | if (INTEGRAL_TYPE_P (endtype)) | |
4254 | { | |
4255 | tree op0, op1; | |
4256 | op0 = TREE_OPERAND (value, 0); | |
4257 | op1 = TREE_OPERAND (value, 1); | |
fdf473ae RH |
4258 | |
4259 | /* Like STRIP_NOPS except allow the operand mode to widen. | |
4260 | This works around a feature of fold that simplfies | |
4261 | (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory | |
4262 | that the narrower operation is cheaper. */ | |
4263 | ||
4264 | while (TREE_CODE (op0) == NOP_EXPR | |
4265 | || TREE_CODE (op0) == CONVERT_EXPR | |
4266 | || TREE_CODE (op0) == NON_LVALUE_EXPR) | |
4267 | { | |
4268 | tree inner = TREE_OPERAND (op0, 0); | |
4269 | if (inner == error_mark_node | |
4270 | || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) | |
4271 | || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))) | |
4272 | > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) | |
4273 | break; | |
4274 | op0 = inner; | |
4275 | } | |
4276 | ||
4277 | while (TREE_CODE (op1) == NOP_EXPR | |
4278 | || TREE_CODE (op1) == CONVERT_EXPR | |
4279 | || TREE_CODE (op1) == NON_LVALUE_EXPR) | |
4280 | { | |
4281 | tree inner = TREE_OPERAND (op1, 0); | |
4282 | if (inner == error_mark_node | |
4283 | || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) | |
4284 | || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1))) | |
4285 | > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) | |
4286 | break; | |
4287 | op1 = inner; | |
4288 | } | |
14a774a9 RK |
4289 | |
4290 | if (TREE_CODE (op0) == ADDR_EXPR | |
4291 | && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL | |
4292 | && TREE_CODE (op1) == ADDR_EXPR | |
4293 | && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL) | |
4294 | return null_pointer_node; | |
4295 | } | |
4296 | break; | |
4297 | ||
4298 | default: | |
4299 | break; | |
4300 | } | |
4301 | ||
4302 | return 0; | |
4303 | } | |
4304 | \f | |
79e68feb RS |
4305 | /* Output assembler code for constant EXP to FILE, with no label. |
4306 | This includes the pseudo-op such as ".int" or ".byte", and a newline. | |
4307 | Assumes output_addressed_constants has been done on EXP already. | |
4308 | ||
4309 | Generate exactly SIZE bytes of assembler data, padding at the end | |
4310 | with zeros if necessary. SIZE must always be specified. | |
4311 | ||
4312 | SIZE is important for structure constructors, | |
4313 | since trailing members may have been omitted from the constructor. | |
4314 | It is also important for initialization of arrays from string constants | |
4315 | since the full length of the string constant might not be wanted. | |
4316 | It is also needed for initialization of unions, where the initializer's | |
4317 | type is just one member, and that may not be as long as the union. | |
4318 | ||
4319 | There a case in which we would fail to output exactly SIZE bytes: | |
4320 | for a structure constructor that wants to produce more than SIZE bytes. | |
c8af3574 RH |
4321 | But such constructors will never be generated for any possible input. |
4322 | ||
4323 | ALIGN is the alignment of the data in bits. */ | |
79e68feb RS |
4324 | |
4325 | void | |
c8af3574 RH |
4326 | output_constant (exp, size, align) |
4327 | tree exp; | |
ac79cd5a | 4328 | HOST_WIDE_INT size; |
c8af3574 | 4329 | unsigned int align; |
79e68feb | 4330 | { |
ac79cd5a RK |
4331 | enum tree_code code; |
4332 | HOST_WIDE_INT thissize; | |
79e68feb | 4333 | |
ed239f5a RK |
4334 | /* Some front-ends use constants other than the standard language-indepdent |
4335 | varieties, but which may still be output directly. Give the front-end a | |
4336 | chance to convert EXP to a language-independent representation. */ | |
ac79cd5a | 4337 | exp = (*lang_hooks.expand_constant) (exp); |
e697e20a | 4338 | |
e9996db7 | 4339 | if (size == 0 || flag_syntax_only) |
79e68feb RS |
4340 | return; |
4341 | ||
ac79cd5a RK |
4342 | /* Eliminate any conversions since we'll be outputting the underlying |
4343 | constant. */ | |
4344 | while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR | |
ed239f5a RK |
4345 | || TREE_CODE (exp) == NON_LVALUE_EXPR |
4346 | || TREE_CODE (exp) == VIEW_CONVERT_EXPR) | |
ac79cd5a RK |
4347 | exp = TREE_OPERAND (exp, 0); |
4348 | ||
4349 | code = TREE_CODE (TREE_TYPE (exp)); | |
4350 | thissize = int_size_in_bytes (TREE_TYPE (exp)); | |
be1ad04c | 4351 | |
fff9e713 MT |
4352 | /* Allow a constructor with no elements for any data type. |
4353 | This means to fill the space with zeros. */ | |
77fa0940 | 4354 | if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0) |
fff9e713 | 4355 | { |
b93a436e | 4356 | assemble_zeros (size); |
fff9e713 MT |
4357 | return; |
4358 | } | |
4359 | ||
67231816 RH |
4360 | if (TREE_CODE (exp) == FDESC_EXPR) |
4361 | { | |
f42f3c2d | 4362 | #ifdef ASM_OUTPUT_FDESC |
67231816 RH |
4363 | HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0); |
4364 | tree decl = TREE_OPERAND (exp, 0); | |
67231816 RH |
4365 | ASM_OUTPUT_FDESC (asm_out_file, decl, part); |
4366 | #else | |
4367 | abort (); | |
4368 | #endif | |
4369 | return; | |
4370 | } | |
4371 | ||
ac79cd5a RK |
4372 | /* Now output the underlying data. If we've handling the padding, return. |
4373 | Otherwise, break and ensure THISSIZE is the size written. */ | |
79e68feb RS |
4374 | switch (code) |
4375 | { | |
644ea577 RS |
4376 | case CHAR_TYPE: |
4377 | case BOOLEAN_TYPE: | |
79e68feb RS |
4378 | case INTEGER_TYPE: |
4379 | case ENUMERAL_TYPE: | |
4380 | case POINTER_TYPE: | |
4381 | case REFERENCE_TYPE: | |
37366632 | 4382 | if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode, |
79e68feb | 4383 | EXPAND_INITIALIZER), |
c8af3574 | 4384 | size, align, 0)) |
79e68feb | 4385 | error ("initializer for integer value is too complicated"); |
79e68feb RS |
4386 | break; |
4387 | ||
4388 | case REAL_TYPE: | |
4389 | if (TREE_CODE (exp) != REAL_CST) | |
4390 | error ("initializer for floating value is not a floating constant"); | |
4391 | ||
4392 | assemble_real (TREE_REAL_CST (exp), | |
c8af3574 RH |
4393 | mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0), |
4394 | align); | |
79e68feb RS |
4395 | break; |
4396 | ||
4397 | case COMPLEX_TYPE: | |
ac79cd5a RK |
4398 | output_constant (TREE_REALPART (exp), thissize / 2, align); |
4399 | output_constant (TREE_IMAGPART (exp), thissize / 2, | |
4400 | min_align (align, BITS_PER_UNIT * (thissize / 2))); | |
79e68feb RS |
4401 | break; |
4402 | ||
4403 | case ARRAY_TYPE: | |
e6834654 | 4404 | case VECTOR_TYPE: |
79e68feb RS |
4405 | if (TREE_CODE (exp) == CONSTRUCTOR) |
4406 | { | |
c8af3574 | 4407 | output_constructor (exp, size, align); |
79e68feb RS |
4408 | return; |
4409 | } | |
4410 | else if (TREE_CODE (exp) == STRING_CST) | |
4411 | { | |
ac79cd5a RK |
4412 | thissize = MIN (TREE_STRING_LENGTH (exp), size); |
4413 | assemble_string (TREE_STRING_POINTER (exp), thissize); | |
79e68feb RS |
4414 | } |
4415 | else | |
4416 | abort (); | |
4417 | break; | |
4418 | ||
4419 | case RECORD_TYPE: | |
4420 | case UNION_TYPE: | |
4421 | if (TREE_CODE (exp) == CONSTRUCTOR) | |
c8af3574 | 4422 | output_constructor (exp, size, align); |
79e68feb RS |
4423 | else |
4424 | abort (); | |
4425 | return; | |
474bda6c PB |
4426 | |
4427 | case SET_TYPE: | |
4428 | if (TREE_CODE (exp) == INTEGER_CST) | |
4429 | assemble_integer (expand_expr (exp, NULL_RTX, | |
4430 | VOIDmode, EXPAND_INITIALIZER), | |
c26fbbca | 4431 | thissize, align, 1); |
474bda6c PB |
4432 | else if (TREE_CODE (exp) == CONSTRUCTOR) |
4433 | { | |
ac79cd5a RK |
4434 | unsigned char *buffer = (unsigned char *) alloca (thissize); |
4435 | if (get_set_constructor_bytes (exp, buffer, thissize)) | |
474bda6c | 4436 | abort (); |
ac79cd5a | 4437 | assemble_string ((char *) buffer, thissize); |
474bda6c PB |
4438 | } |
4439 | else | |
4440 | error ("unknown set constructor type"); | |
4441 | return; | |
e9a25f70 | 4442 | |
0974a3b8 RK |
4443 | case ERROR_MARK: |
4444 | return; | |
4445 | ||
e9a25f70 | 4446 | default: |
ac79cd5a | 4447 | abort (); |
79e68feb RS |
4448 | } |
4449 | ||
ac79cd5a | 4450 | size -= thissize; |
79e68feb RS |
4451 | if (size > 0) |
4452 | assemble_zeros (size); | |
4453 | } | |
ca695ac9 | 4454 | |
79e68feb | 4455 | \f |
a25f1211 RH |
4456 | /* Subroutine of output_constructor, used for computing the size of |
4457 | arrays of unspecified length. VAL must be a CONSTRUCTOR of an array | |
4458 | type with an unspecified upper bound. */ | |
4459 | ||
ffc5c6a9 | 4460 | static unsigned HOST_WIDE_INT |
a25f1211 RH |
4461 | array_size_for_constructor (val) |
4462 | tree val; | |
4463 | { | |
4464 | tree max_index, i; | |
4465 | ||
ac79cd5a RK |
4466 | /* This code used to attempt to handle string constants that are not |
4467 | arrays of single-bytes, but nothing else does, so there's no point in | |
4468 | doing it here. */ | |
b6fc7110 | 4469 | if (TREE_CODE (val) == STRING_CST) |
ac79cd5a RK |
4470 | return TREE_STRING_LENGTH (val); |
4471 | ||
a25f1211 | 4472 | max_index = NULL_TREE; |
c26fbbca | 4473 | for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i)) |
a25f1211 RH |
4474 | { |
4475 | tree index = TREE_PURPOSE (i); | |
4476 | ||
4477 | if (TREE_CODE (index) == RANGE_EXPR) | |
4478 | index = TREE_OPERAND (index, 1); | |
4479 | if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index)) | |
4480 | max_index = index; | |
4481 | } | |
4482 | ||
a25f1211 | 4483 | if (max_index == NULL_TREE) |
ffc5c6a9 | 4484 | return 0; |
a25f1211 RH |
4485 | |
4486 | /* Compute the total number of array elements. */ | |
46f9491e | 4487 | i = size_binop (MINUS_EXPR, convert (sizetype, max_index), |
ffc5c6a9 RH |
4488 | convert (sizetype, |
4489 | TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val))))); | |
4490 | i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node)); | |
a25f1211 RH |
4491 | |
4492 | /* Multiply by the array element unit size to find number of bytes. */ | |
ffc5c6a9 | 4493 | i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val)))); |
a25f1211 RH |
4494 | |
4495 | return tree_low_cst (i, 1); | |
4496 | } | |
4497 | ||
4498 | /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants). | |
79e68feb RS |
4499 | Generate at least SIZE bytes, padding if necessary. */ |
4500 | ||
5a13eaa4 | 4501 | static void |
c8af3574 | 4502 | output_constructor (exp, size, align) |
79e68feb | 4503 | tree exp; |
ac79cd5a | 4504 | HOST_WIDE_INT size; |
c8af3574 | 4505 | unsigned int align; |
79e68feb | 4506 | { |
85f3d674 | 4507 | tree type = TREE_TYPE (exp); |
b3694847 | 4508 | tree link, field = 0; |
85f3d674 | 4509 | tree min_index = 0; |
79e68feb RS |
4510 | /* Number of bytes output or skipped so far. |
4511 | In other words, current position within the constructor. */ | |
85f3d674 | 4512 | HOST_WIDE_INT total_bytes = 0; |
79e68feb RS |
4513 | /* Non-zero means BYTE contains part of a byte, to be output. */ |
4514 | int byte_buffer_in_use = 0; | |
b3694847 | 4515 | int byte = 0; |
79e68feb | 4516 | |
37366632 | 4517 | if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT) |
79e68feb RS |
4518 | abort (); |
4519 | ||
85f3d674 RK |
4520 | if (TREE_CODE (type) == RECORD_TYPE) |
4521 | field = TYPE_FIELDS (type); | |
79e68feb | 4522 | |
85f3d674 RK |
4523 | if (TREE_CODE (type) == ARRAY_TYPE |
4524 | && TYPE_DOMAIN (type) != 0) | |
4525 | min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type)); | |
13b457e7 | 4526 | |
79e68feb RS |
4527 | /* As LINK goes through the elements of the constant, |
4528 | FIELD goes through the structure fields, if the constant is a structure. | |
4529 | if the constant is a union, then we override this, | |
4530 | by getting the field from the TREE_LIST element. | |
43f7bed5 VM |
4531 | But the constant could also be an array. Then FIELD is zero. |
4532 | ||
4533 | There is always a maximum of one element in the chain LINK for unions | |
4534 | (even if the initializer in a source program incorrectly contains | |
2d76cb1a | 4535 | more one). */ |
79e68feb RS |
4536 | for (link = CONSTRUCTOR_ELTS (exp); |
4537 | link; | |
4538 | link = TREE_CHAIN (link), | |
4539 | field = field ? TREE_CHAIN (field) : 0) | |
4540 | { | |
4541 | tree val = TREE_VALUE (link); | |
3181cbfd RS |
4542 | tree index = 0; |
4543 | ||
85f3d674 RK |
4544 | /* The element in a union constructor specifies the proper field |
4545 | or index. */ | |
4546 | if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE | |
4547 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
4548 | && TREE_PURPOSE (link) != 0) | |
4549 | field = TREE_PURPOSE (link); | |
3181cbfd | 4550 | |
85f3d674 | 4551 | else if (TREE_CODE (type) == ARRAY_TYPE) |
3181cbfd RS |
4552 | index = TREE_PURPOSE (link); |
4553 | ||
79e68feb | 4554 | /* Eliminate the marker that makes a cast not be an lvalue. */ |
d964285c CH |
4555 | if (val != 0) |
4556 | STRIP_NOPS (val); | |
79e68feb | 4557 | |
8311a11f PB |
4558 | if (index && TREE_CODE (index) == RANGE_EXPR) |
4559 | { | |
bf1aaf0a | 4560 | unsigned HOST_WIDE_INT fieldsize |
85f3d674 RK |
4561 | = int_size_in_bytes (TREE_TYPE (type)); |
4562 | HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0); | |
4563 | HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0); | |
8311a11f | 4564 | HOST_WIDE_INT index; |
c8af3574 | 4565 | unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT); |
85f3d674 | 4566 | |
8311a11f PB |
4567 | for (index = lo_index; index <= hi_index; index++) |
4568 | { | |
4569 | /* Output the element's initial value. */ | |
4570 | if (val == 0) | |
4571 | assemble_zeros (fieldsize); | |
4572 | else | |
c8af3574 | 4573 | output_constant (val, fieldsize, align2); |
8311a11f PB |
4574 | |
4575 | /* Count its size. */ | |
4576 | total_bytes += fieldsize; | |
4577 | } | |
4578 | } | |
4579 | else if (field == 0 || !DECL_BIT_FIELD (field)) | |
79e68feb | 4580 | { |
3181cbfd RS |
4581 | /* An element that is not a bit-field. */ |
4582 | ||
bf1aaf0a | 4583 | unsigned HOST_WIDE_INT fieldsize; |
79e68feb RS |
4584 | /* Since this structure is static, |
4585 | we know the positions are constant. */ | |
85f3d674 | 4586 | HOST_WIDE_INT pos = field ? int_byte_position (field) : 0; |
c8af3574 | 4587 | unsigned int align2; |
770ae6cc | 4588 | |
3181cbfd | 4589 | if (index != 0) |
85f3d674 RK |
4590 | pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1) |
4591 | * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0))); | |
79e68feb | 4592 | |
3181cbfd | 4593 | /* Output any buffered-up bit-fields preceding this element. */ |
79e68feb RS |
4594 | if (byte_buffer_in_use) |
4595 | { | |
eac50d7a | 4596 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4597 | total_bytes++; |
4598 | byte_buffer_in_use = 0; | |
4599 | } | |
4600 | ||
4601 | /* Advance to offset of this element. | |
4602 | Note no alignment needed in an array, since that is guaranteed | |
4603 | if each element has the proper size. */ | |
85f3d674 | 4604 | if ((field != 0 || index != 0) && pos != total_bytes) |
79e68feb | 4605 | { |
85f3d674 RK |
4606 | assemble_zeros (pos - total_bytes); |
4607 | total_bytes = pos; | |
79e68feb | 4608 | } |
ca2eed21 | 4609 | |
c8af3574 RH |
4610 | /* Find the alignment of this element. */ |
4611 | align2 = min_align (align, BITS_PER_UNIT * pos); | |
46f9491e | 4612 | |
79e68feb RS |
4613 | /* Determine size this element should occupy. */ |
4614 | if (field) | |
a25f1211 | 4615 | { |
ffc5c6a9 RH |
4616 | fieldsize = 0; |
4617 | ||
4618 | /* If this is an array with an unspecified upper bound, | |
4619 | the initializer determines the size. */ | |
4620 | /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL, | |
4621 | but we cannot do this until the deprecated support for | |
4622 | initializing zero-length array members is removed. */ | |
4623 | if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE | |
4624 | && TYPE_DOMAIN (TREE_TYPE (field)) | |
4625 | && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field)))) | |
4626 | { | |
a25f1211 | 4627 | fieldsize = array_size_for_constructor (val); |
ffc5c6a9 RH |
4628 | /* Given a non-empty initialization, this field had |
4629 | better be last. */ | |
4630 | if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE) | |
4631 | abort (); | |
4632 | } | |
4633 | else if (DECL_SIZE_UNIT (field)) | |
4634 | { | |
4635 | /* ??? This can't be right. If the decl size overflows | |
4636 | a host integer we will silently emit no data. */ | |
4637 | if (host_integerp (DECL_SIZE_UNIT (field), 1)) | |
4638 | fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1); | |
4639 | } | |
a25f1211 | 4640 | } |
79e68feb | 4641 | else |
85f3d674 | 4642 | fieldsize = int_size_in_bytes (TREE_TYPE (type)); |
79e68feb RS |
4643 | |
4644 | /* Output the element's initial value. */ | |
4645 | if (val == 0) | |
4646 | assemble_zeros (fieldsize); | |
4647 | else | |
c8af3574 | 4648 | output_constant (val, fieldsize, align2); |
79e68feb RS |
4649 | |
4650 | /* Count its size. */ | |
4651 | total_bytes += fieldsize; | |
4652 | } | |
4653 | else if (val != 0 && TREE_CODE (val) != INTEGER_CST) | |
4654 | error ("invalid initial value for member `%s'", | |
4655 | IDENTIFIER_POINTER (DECL_NAME (field))); | |
4656 | else | |
4657 | { | |
4658 | /* Element that is a bit-field. */ | |
4659 | ||
770ae6cc RK |
4660 | HOST_WIDE_INT next_offset = int_bit_position (field); |
4661 | HOST_WIDE_INT end_offset | |
4662 | = (next_offset + tree_low_cst (DECL_SIZE (field), 1)); | |
79e68feb RS |
4663 | |
4664 | if (val == 0) | |
4665 | val = integer_zero_node; | |
4666 | ||
4667 | /* If this field does not start in this (or, next) byte, | |
4668 | skip some bytes. */ | |
4669 | if (next_offset / BITS_PER_UNIT != total_bytes) | |
4670 | { | |
4671 | /* Output remnant of any bit field in previous bytes. */ | |
4672 | if (byte_buffer_in_use) | |
4673 | { | |
eac50d7a | 4674 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4675 | total_bytes++; |
4676 | byte_buffer_in_use = 0; | |
4677 | } | |
4678 | ||
4679 | /* If still not at proper byte, advance to there. */ | |
4680 | if (next_offset / BITS_PER_UNIT != total_bytes) | |
4681 | { | |
4682 | assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes); | |
4683 | total_bytes = next_offset / BITS_PER_UNIT; | |
4684 | } | |
4685 | } | |
4686 | ||
4687 | if (! byte_buffer_in_use) | |
4688 | byte = 0; | |
4689 | ||
4690 | /* We must split the element into pieces that fall within | |
4691 | separate bytes, and combine each byte with previous or | |
4692 | following bit-fields. */ | |
4693 | ||
b4ac57ab | 4694 | /* next_offset is the offset n fbits from the beginning of |
79e68feb RS |
4695 | the structure to the next bit of this element to be processed. |
4696 | end_offset is the offset of the first bit past the end of | |
4697 | this element. */ | |
4698 | while (next_offset < end_offset) | |
4699 | { | |
4700 | int this_time; | |
e7105755 JW |
4701 | int shift; |
4702 | HOST_WIDE_INT value; | |
85f3d674 RK |
4703 | HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT; |
4704 | HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT; | |
79e68feb RS |
4705 | |
4706 | /* Advance from byte to byte | |
4707 | within this element when necessary. */ | |
4708 | while (next_byte != total_bytes) | |
4709 | { | |
eac50d7a | 4710 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4711 | total_bytes++; |
4712 | byte = 0; | |
4713 | } | |
4714 | ||
4715 | /* Number of bits we can process at once | |
4716 | (all part of the same byte). */ | |
4717 | this_time = MIN (end_offset - next_offset, | |
4718 | BITS_PER_UNIT - next_bit); | |
f76b9db2 | 4719 | if (BYTES_BIG_ENDIAN) |
79e68feb | 4720 | { |
f76b9db2 ILT |
4721 | /* On big-endian machine, take the most significant bits |
4722 | first (of the bits that are significant) | |
4723 | and put them into bytes from the most significant end. */ | |
4724 | shift = end_offset - next_offset - this_time; | |
85f3d674 | 4725 | |
f76b9db2 | 4726 | /* Don't try to take a bunch of bits that cross |
dfb2c079 HB |
4727 | the word boundary in the INTEGER_CST. We can |
4728 | only select bits from the LOW or HIGH part | |
4729 | not from both. */ | |
f76b9db2 ILT |
4730 | if (shift < HOST_BITS_PER_WIDE_INT |
4731 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
4732 | { | |
8b1cb95b GK |
4733 | this_time = shift + this_time - HOST_BITS_PER_WIDE_INT; |
4734 | shift = HOST_BITS_PER_WIDE_INT; | |
f76b9db2 ILT |
4735 | } |
4736 | ||
4737 | /* Now get the bits from the appropriate constant word. */ | |
4738 | if (shift < HOST_BITS_PER_WIDE_INT) | |
85f3d674 | 4739 | value = TREE_INT_CST_LOW (val); |
f76b9db2 ILT |
4740 | else if (shift < 2 * HOST_BITS_PER_WIDE_INT) |
4741 | { | |
4742 | value = TREE_INT_CST_HIGH (val); | |
4743 | shift -= HOST_BITS_PER_WIDE_INT; | |
4744 | } | |
4745 | else | |
4746 | abort (); | |
85f3d674 | 4747 | |
dfb2c079 HB |
4748 | /* Get the result. This works only when: |
4749 | 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ | |
f76b9db2 | 4750 | byte |= (((value >> shift) |
dfb2c079 | 4751 | & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) |
f76b9db2 | 4752 | << (BITS_PER_UNIT - this_time - next_bit)); |
79e68feb RS |
4753 | } |
4754 | else | |
79e68feb | 4755 | { |
f76b9db2 ILT |
4756 | /* On little-endian machines, |
4757 | take first the least significant bits of the value | |
4758 | and pack them starting at the least significant | |
4759 | bits of the bytes. */ | |
770ae6cc RK |
4760 | shift = next_offset - int_bit_position (field); |
4761 | ||
f76b9db2 | 4762 | /* Don't try to take a bunch of bits that cross |
dfb2c079 HB |
4763 | the word boundary in the INTEGER_CST. We can |
4764 | only select bits from the LOW or HIGH part | |
4765 | not from both. */ | |
f76b9db2 ILT |
4766 | if (shift < HOST_BITS_PER_WIDE_INT |
4767 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
770ae6cc | 4768 | this_time = (HOST_BITS_PER_WIDE_INT - shift); |
f76b9db2 ILT |
4769 | |
4770 | /* Now get the bits from the appropriate constant word. */ | |
e9a25f70 | 4771 | if (shift < HOST_BITS_PER_WIDE_INT) |
f76b9db2 ILT |
4772 | value = TREE_INT_CST_LOW (val); |
4773 | else if (shift < 2 * HOST_BITS_PER_WIDE_INT) | |
4774 | { | |
4775 | value = TREE_INT_CST_HIGH (val); | |
4776 | shift -= HOST_BITS_PER_WIDE_INT; | |
4777 | } | |
4778 | else | |
4779 | abort (); | |
770ae6cc | 4780 | |
dfb2c079 HB |
4781 | /* Get the result. This works only when: |
4782 | 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ | |
f76b9db2 | 4783 | byte |= (((value >> shift) |
dfb2c079 | 4784 | & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) |
f76b9db2 | 4785 | << next_bit); |
79e68feb | 4786 | } |
85f3d674 | 4787 | |
79e68feb RS |
4788 | next_offset += this_time; |
4789 | byte_buffer_in_use = 1; | |
4790 | } | |
4791 | } | |
4792 | } | |
85f3d674 | 4793 | |
79e68feb RS |
4794 | if (byte_buffer_in_use) |
4795 | { | |
eac50d7a | 4796 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4797 | total_bytes++; |
4798 | } | |
85f3d674 | 4799 | |
79e68feb RS |
4800 | if (total_bytes < size) |
4801 | assemble_zeros (size - total_bytes); | |
4802 | } | |
ca695ac9 | 4803 | |
ecb0eece | 4804 | /* This TREE_LIST contains any weak symbol declarations waiting |
46f9491e | 4805 | to be emitted. */ |
ecb0eece | 4806 | static tree weak_decls; |
0e9264a2 | 4807 | |
f90bf7ca MM |
4808 | /* Mark DECL as weak. */ |
4809 | ||
4810 | static void | |
4811 | mark_weak (decl) | |
4812 | tree decl; | |
4813 | { | |
4814 | DECL_WEAK (decl) = 1; | |
4815 | ||
4816 | if (DECL_RTL_SET_P (decl) | |
4817 | && GET_CODE (DECL_RTL (decl)) == MEM | |
4818 | && XEXP (DECL_RTL (decl), 0) | |
4819 | && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF) | |
4820 | SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1; | |
4821 | } | |
4822 | ||
45806a3f FS |
4823 | /* Merge weak status between NEWDECL and OLDDECL. */ |
4824 | ||
4825 | void | |
4826 | merge_weak (newdecl, olddecl) | |
4827 | tree newdecl; | |
4828 | tree olddecl; | |
4829 | { | |
45806a3f FS |
4830 | if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl)) |
4831 | return; | |
4832 | ||
f90bf7ca MM |
4833 | if (DECL_WEAK (newdecl)) |
4834 | { | |
4835 | tree wd; | |
4836 | ||
4837 | /* NEWDECL is weak, but OLDDECL is not. */ | |
4838 | ||
4839 | /* If we already output the OLDDECL, we're in trouble; we can't | |
4840 | go back and make it weak. This error cannot caught in | |
4841 | declare_weak because the NEWDECL and OLDDECL was not yet | |
4842 | been merged; therefore, TREE_ASM_WRITTEN was not set. */ | |
14285ace | 4843 | if (TREE_ASM_WRITTEN (olddecl)) |
f90bf7ca MM |
4844 | error_with_decl (newdecl, |
4845 | "weak declaration of `%s' must precede definition"); | |
14285ace RH |
4846 | |
4847 | /* If we've already generated rtl referencing OLDDECL, we may | |
4848 | have done so in a way that will not function properly with | |
4849 | a weak symbol. */ | |
4850 | else if (TREE_USED (olddecl) | |
34fb9ba5 | 4851 | && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl))) |
14285ace RH |
4852 | warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior"); |
4853 | ||
f90bf7ca MM |
4854 | if (SUPPORTS_WEAK) |
4855 | { | |
4856 | /* We put the NEWDECL on the weak_decls list at some point. | |
4857 | Replace it with the OLDDECL. */ | |
4858 | for (wd = weak_decls; wd; wd = TREE_CHAIN (wd)) | |
4859 | if (TREE_VALUE (wd) == newdecl) | |
4860 | { | |
4861 | TREE_VALUE (wd) = olddecl; | |
4862 | break; | |
4863 | } | |
4864 | /* We may not find the entry on the list. If NEWDECL is a | |
4865 | weak alias, then we will have already called | |
4866 | globalize_decl to remove the entry; in that case, we do | |
4867 | not need to do anything. */ | |
4868 | } | |
45806a3f | 4869 | |
f90bf7ca MM |
4870 | /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */ |
4871 | mark_weak (olddecl); | |
4872 | } | |
4873 | else | |
4874 | /* OLDDECL was weak, but NEWDECL was not explicitly marked as | |
4875 | weak. Just update NEWDECL to indicate that it's weak too. */ | |
4876 | mark_weak (newdecl); | |
45806a3f FS |
4877 | } |
4878 | ||
4b8af8d9 JM |
4879 | /* Declare DECL to be a weak symbol. */ |
4880 | ||
4881 | void | |
4882 | declare_weak (decl) | |
4883 | tree decl; | |
4884 | { | |
4885 | if (! TREE_PUBLIC (decl)) | |
4886 | error_with_decl (decl, "weak declaration of `%s' must be public"); | |
45806a3f | 4887 | else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) |
daefd78b JM |
4888 | error_with_decl (decl, "weak declaration of `%s' must precede definition"); |
4889 | else if (SUPPORTS_WEAK) | |
ecb0eece RH |
4890 | { |
4891 | if (! DECL_WEAK (decl)) | |
4892 | weak_decls = tree_cons (NULL, decl, weak_decls); | |
4893 | } | |
4ae08f95 JM |
4894 | else |
4895 | warning_with_decl (decl, "weak declaration of `%s' not supported"); | |
4896 | ||
f90bf7ca | 4897 | mark_weak (decl); |
4b8af8d9 JM |
4898 | } |
4899 | ||
4900 | /* Emit any pending weak declarations. */ | |
4901 | ||
4902 | void | |
4903 | weak_finish () | |
4904 | { | |
ecb0eece RH |
4905 | tree t; |
4906 | ||
c26fbbca | 4907 | for (t = weak_decls; t; t = TREE_CHAIN (t)) |
4b8af8d9 | 4908 | { |
ecb0eece RH |
4909 | tree decl = TREE_VALUE (t); |
4910 | const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
4911 | ||
4912 | if (! TREE_USED (decl)) | |
4913 | continue; | |
4914 | ||
79c4e63f | 4915 | #ifdef ASM_WEAKEN_DECL |
ecb0eece | 4916 | ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL); |
4ae08f95 JM |
4917 | #else |
4918 | #ifdef ASM_WEAKEN_LABEL | |
ecb0eece RH |
4919 | ASM_WEAKEN_LABEL (asm_out_file, name); |
4920 | #else | |
4921 | #ifdef ASM_OUTPUT_WEAK_ALIAS | |
4922 | warning ("only weak aliases are supported in this configuration"); | |
4923 | return; | |
4ae08f95 | 4924 | #endif |
79c4e63f | 4925 | #endif |
4ae08f95 | 4926 | #endif |
4b8af8d9 | 4927 | } |
4b8af8d9 | 4928 | } |
4ae08f95 | 4929 | |
19c5b1cf JM |
4930 | /* Emit the assembly bits to indicate that DECL is globally visible. */ |
4931 | ||
4932 | static void | |
4933 | globalize_decl (decl) | |
4934 | tree decl; | |
4935 | { | |
f9d09ae5 | 4936 | const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); |
19c5b1cf JM |
4937 | |
4938 | #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL) | |
4939 | if (DECL_WEAK (decl)) | |
4940 | { | |
ecb0eece RH |
4941 | tree *p, t; |
4942 | ||
19c5b1cf JM |
4943 | #ifdef ASM_WEAKEN_DECL |
4944 | ASM_WEAKEN_DECL (asm_out_file, decl, name, 0); | |
4945 | #else | |
4946 | ASM_WEAKEN_LABEL (asm_out_file, name); | |
4947 | #endif | |
ecb0eece | 4948 | |
19c5b1cf JM |
4949 | /* Remove this function from the pending weak list so that |
4950 | we do not emit multiple .weak directives for it. */ | |
a81eed10 FS |
4951 | for (p = &weak_decls; (t = *p) ; ) |
4952 | { | |
4953 | if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))) | |
ecb0eece | 4954 | *p = TREE_CHAIN (t); |
a81eed10 FS |
4955 | else |
4956 | p = &TREE_CHAIN (t); | |
4957 | } | |
19c5b1cf JM |
4958 | return; |
4959 | } | |
19c5b1cf | 4960 | #endif |
ecb0eece | 4961 | |
19c5b1cf JM |
4962 | ASM_GLOBALIZE_LABEL (asm_out_file, name); |
4963 | } | |
4964 | ||
4ae08f95 JM |
4965 | /* Emit an assembler directive to make the symbol for DECL an alias to |
4966 | the symbol for TARGET. */ | |
4b8af8d9 JM |
4967 | |
4968 | void | |
4969 | assemble_alias (decl, target) | |
91813b28 | 4970 | tree decl, target ATTRIBUTE_UNUSED; |
4b8af8d9 | 4971 | { |
3cce094d | 4972 | const char *name; |
4b8af8d9 | 4973 | |
9ea07fd0 JW |
4974 | /* We must force creation of DECL_RTL for debug info generation, even though |
4975 | we don't use it here. */ | |
6496a589 | 4976 | make_decl_rtl (decl, NULL); |
9ea07fd0 | 4977 | |
19e7881c | 4978 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
4b8af8d9 | 4979 | |
4927276d | 4980 | #ifdef ASM_OUTPUT_DEF |
4b8af8d9 JM |
4981 | /* Make name accessible from other files, if appropriate. */ |
4982 | ||
4983 | if (TREE_PUBLIC (decl)) | |
4984 | { | |
19c5b1cf | 4985 | globalize_decl (decl); |
b14707c3 | 4986 | maybe_assemble_visibility (decl); |
4b8af8d9 JM |
4987 | } |
4988 | ||
e4faf1eb NC |
4989 | #ifdef ASM_OUTPUT_DEF_FROM_DECLS |
4990 | ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target); | |
4991 | #else | |
4b8af8d9 | 4992 | ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target)); |
e4faf1eb | 4993 | #endif |
79c4e63f AM |
4994 | #else /* !ASM_OUTPUT_DEF */ |
4995 | #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL) | |
4927276d JM |
4996 | if (! DECL_WEAK (decl)) |
4997 | warning ("only weak aliases are supported in this configuration"); | |
4998 | ||
79c4e63f AM |
4999 | #ifdef ASM_WEAKEN_DECL |
5000 | ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target)); | |
5001 | #else | |
4927276d | 5002 | ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target)); |
79c4e63f | 5003 | #endif |
4927276d JM |
5004 | #else |
5005 | warning ("alias definitions not supported in this configuration; ignored"); | |
5006 | #endif | |
4b8af8d9 | 5007 | #endif |
14285ace RH |
5008 | |
5009 | TREE_USED (decl) = 1; | |
5010 | TREE_ASM_WRITTEN (decl) = 1; | |
5011 | TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1; | |
4b8af8d9 | 5012 | } |
f796d997 | 5013 | |
47bd70b5 JJ |
5014 | /* Emit an assembler directive to set symbol for DECL visibility to |
5015 | VISIBILITY_TYPE. */ | |
5016 | ||
5017 | void | |
5018 | assemble_visibility (decl, visibility_type) | |
5019 | tree decl; | |
5020 | const char *visibility_type ATTRIBUTE_UNUSED; | |
5021 | { | |
5022 | const char *name; | |
5023 | ||
5024 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
5025 | ||
5026 | #ifdef HAVE_GAS_HIDDEN | |
5027 | fprintf (asm_out_file, "\t.%s\t%s\n", visibility_type, name); | |
5028 | #else | |
5029 | warning ("visibility attribute not supported in this configuration; ignored"); | |
5030 | #endif | |
5031 | } | |
5032 | ||
b14707c3 RH |
5033 | /* A helper function to call assemble_visibility when needed for a decl. */ |
5034 | ||
5035 | static void | |
5036 | maybe_assemble_visibility (decl) | |
5037 | tree decl; | |
5038 | { | |
5039 | tree visibility = lookup_attribute ("visibility", DECL_ATTRIBUTES (decl)); | |
5040 | if (visibility) | |
5041 | { | |
5042 | const char *type | |
5043 | = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility))); | |
5044 | assemble_visibility (decl, type); | |
5045 | } | |
5046 | } | |
5047 | ||
f796d997 JM |
5048 | /* Returns 1 if the target configuration supports defining public symbols |
5049 | so that one of them will be chosen at link time instead of generating a | |
5050 | multiply-defined symbol error, whether through the use of weak symbols or | |
5051 | a target-specific mechanism for having duplicates discarded. */ | |
5052 | ||
5053 | int | |
5054 | supports_one_only () | |
5055 | { | |
5056 | if (SUPPORTS_ONE_ONLY) | |
5057 | return 1; | |
5058 | return SUPPORTS_WEAK; | |
5059 | } | |
5060 | ||
5061 | /* Set up DECL as a public symbol that can be defined in multiple | |
5062 | translation units without generating a linker error. */ | |
5063 | ||
5064 | void | |
5065 | make_decl_one_only (decl) | |
5066 | tree decl; | |
5067 | { | |
5068 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL) | |
5069 | abort (); | |
5070 | ||
5071 | TREE_PUBLIC (decl) = 1; | |
5072 | ||
5073 | if (TREE_CODE (decl) == VAR_DECL | |
5074 | && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)) | |
5075 | DECL_COMMON (decl) = 1; | |
5076 | else if (SUPPORTS_ONE_ONLY) | |
5077 | { | |
5078 | #ifdef MAKE_DECL_ONE_ONLY | |
5079 | MAKE_DECL_ONE_ONLY (decl); | |
5080 | #endif | |
5081 | DECL_ONE_ONLY (decl) = 1; | |
5082 | } | |
5083 | else if (SUPPORTS_WEAK) | |
5084 | DECL_WEAK (decl) = 1; | |
5085 | else | |
5086 | abort (); | |
5087 | } | |
76095e2f RH |
5088 | |
5089 | void | |
5090 | init_varasm_once () | |
5091 | { | |
bd7cf17e | 5092 | const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq, |
c26fbbca | 5093 | const_str_htab_del); |
715bdd29 RH |
5094 | in_named_htab = htab_create (31, in_named_entry_hash, |
5095 | in_named_entry_eq, NULL); | |
5096 | ||
14a774a9 | 5097 | ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0], |
76095e2f | 5098 | mark_const_hash_entry); |
bd7cf17e JJ |
5099 | ggc_add_root (&const_str_htab, 1, sizeof const_str_htab, |
5100 | mark_const_str_htab); | |
ecb0eece | 5101 | ggc_add_tree_root (&weak_decls, 1); |
a79e3a45 RK |
5102 | |
5103 | const_alias_set = new_alias_set (); | |
76095e2f | 5104 | } |
7c262518 RH |
5105 | |
5106 | /* Select a set of attributes for section NAME based on the properties | |
5107 | of DECL and whether or not RELOC indicates that DECL's initializer | |
5108 | might contain runtime relocations. | |
5109 | ||
5110 | We make the section read-only and executable for a function decl, | |
715bdd29 | 5111 | read-only for a const data decl, and writable for a non-const data decl. */ |
7c262518 RH |
5112 | |
5113 | unsigned int | |
5114 | default_section_type_flags (decl, name, reloc) | |
5115 | tree decl; | |
5116 | const char *name; | |
5117 | int reloc; | |
5118 | { | |
7c262518 | 5119 | unsigned int flags; |
7c262518 RH |
5120 | |
5121 | if (decl && TREE_CODE (decl) == FUNCTION_DECL) | |
5122 | flags = SECTION_CODE; | |
5123 | else if (decl && DECL_READONLY_SECTION (decl, reloc)) | |
5124 | flags = 0; | |
5125 | else | |
5126 | flags = SECTION_WRITE; | |
5127 | ||
5128 | if (decl && DECL_ONE_ONLY (decl)) | |
5129 | flags |= SECTION_LINKONCE; | |
5130 | ||
5131 | if (strcmp (name, ".bss") == 0 | |
5132 | || strncmp (name, ".bss.", 5) == 0 | |
5133 | || strncmp (name, ".gnu.linkonce.b.", 16) == 0 | |
5134 | || strcmp (name, ".sbss") == 0 | |
5135 | || strncmp (name, ".sbss.", 6) == 0 | |
5136 | || strncmp (name, ".gnu.linkonce.sb.", 17) == 0) | |
5137 | flags |= SECTION_BSS; | |
5138 | ||
7c262518 RH |
5139 | return flags; |
5140 | } | |
5141 | ||
5142 | /* Output assembly to switch to section NAME with attribute FLAGS. | |
5143 | Four variants for common object file formats. */ | |
5144 | ||
5145 | void | |
715bdd29 | 5146 | default_no_named_section (name, flags) |
7c262518 RH |
5147 | const char *name ATTRIBUTE_UNUSED; |
5148 | unsigned int flags ATTRIBUTE_UNUSED; | |
7c262518 RH |
5149 | { |
5150 | /* Some object formats don't support named sections at all. The | |
5151 | front-end should already have flagged this as an error. */ | |
5152 | abort (); | |
5153 | } | |
5154 | ||
5155 | void | |
715bdd29 | 5156 | default_elf_asm_named_section (name, flags) |
7c262518 RH |
5157 | const char *name; |
5158 | unsigned int flags; | |
7c262518 | 5159 | { |
201556f0 | 5160 | char flagchars[10], *f = flagchars; |
7c262518 RH |
5161 | const char *type; |
5162 | ||
a8c01a59 RL |
5163 | if (! named_section_first_declaration (name)) |
5164 | { | |
5165 | fprintf (asm_out_file, "\t.section\t%s\n", name); | |
5166 | return; | |
5167 | } | |
5168 | ||
7c262518 RH |
5169 | if (!(flags & SECTION_DEBUG)) |
5170 | *f++ = 'a'; | |
5171 | if (flags & SECTION_WRITE) | |
5172 | *f++ = 'w'; | |
5173 | if (flags & SECTION_CODE) | |
5174 | *f++ = 'x'; | |
5175 | if (flags & SECTION_SMALL) | |
5176 | *f++ = 's'; | |
201556f0 JJ |
5177 | if (flags & SECTION_MERGE) |
5178 | *f++ = 'M'; | |
5179 | if (flags & SECTION_STRINGS) | |
5180 | *f++ = 'S'; | |
7c262518 RH |
5181 | *f = '\0'; |
5182 | ||
5183 | if (flags & SECTION_BSS) | |
5184 | type = "nobits"; | |
5185 | else | |
5186 | type = "progbits"; | |
5187 | ||
201556f0 JJ |
5188 | if (flags & SECTION_ENTSIZE) |
5189 | fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n", | |
5190 | name, flagchars, type, flags & SECTION_ENTSIZE); | |
5191 | else | |
5192 | fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n", | |
5193 | name, flagchars, type); | |
7c262518 RH |
5194 | } |
5195 | ||
5196 | void | |
715bdd29 | 5197 | default_coff_asm_named_section (name, flags) |
7c262518 RH |
5198 | const char *name; |
5199 | unsigned int flags; | |
7c262518 RH |
5200 | { |
5201 | char flagchars[8], *f = flagchars; | |
5202 | ||
5203 | if (flags & SECTION_WRITE) | |
5204 | *f++ = 'w'; | |
5205 | if (flags & SECTION_CODE) | |
5206 | *f++ = 'x'; | |
5207 | *f = '\0'; | |
5208 | ||
5209 | fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars); | |
5210 | } | |
5211 | ||
5212 | void | |
715bdd29 | 5213 | default_pe_asm_named_section (name, flags) |
7c262518 RH |
5214 | const char *name; |
5215 | unsigned int flags; | |
7c262518 | 5216 | { |
715bdd29 | 5217 | default_coff_asm_named_section (name, flags); |
7c262518 RH |
5218 | |
5219 | if (flags & SECTION_LINKONCE) | |
5220 | { | |
5221 | /* Functions may have been compiled at various levels of | |
5222 | optimization so we can't use `same_size' here. | |
5223 | Instead, have the linker pick one. */ | |
5224 | fprintf (asm_out_file, "\t.linkonce %s\n", | |
5225 | (flags & SECTION_CODE ? "discard" : "same_size")); | |
5226 | } | |
5227 | } | |
4a8d0c9c RH |
5228 | \f |
5229 | /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET | |
5230 | from SYMBOL is used in all classes derived from SYMBOL. */ | |
5231 | ||
5232 | void | |
5233 | assemble_vtable_entry (symbol, offset) | |
5234 | rtx symbol; | |
5235 | HOST_WIDE_INT offset; | |
5236 | { | |
5237 | fputs ("\t.vtable_entry ", asm_out_file); | |
5238 | output_addr_const (asm_out_file, symbol); | |
5239 | fputs (", ", asm_out_file); | |
5240 | fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset); | |
5241 | fputc ('\n', asm_out_file); | |
5242 | } | |
5243 | ||
684d9f3b | 5244 | /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting |
4a8d0c9c RH |
5245 | that the vtable symbol CHILD is derived from the vtable symbol PARENT. */ |
5246 | ||
5247 | void | |
5248 | assemble_vtable_inherit (child, parent) | |
5249 | rtx child, parent; | |
5250 | { | |
5251 | fputs ("\t.vtable_inherit ", asm_out_file); | |
5252 | output_addr_const (asm_out_file, child); | |
5253 | fputs (", ", asm_out_file); | |
5254 | output_addr_const (asm_out_file, parent); | |
5255 | fputc ('\n', asm_out_file); | |
5256 | } |