]>
Commit | Line | Data |
---|---|---|
9878760c | 1 | /* Subroutines used for code generation on IBM RS/6000. |
9ebbca7d GK |
2 | Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
3 | 2000 Free Software Foundation, Inc. | |
fab3bcc3 | 4 | Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) |
9878760c RK |
5 | |
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
c15c9075 RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
9878760c | 22 | |
956d6950 | 23 | #include "config.h" |
c4d38ccb | 24 | #include "system.h" |
9878760c RK |
25 | #include "rtl.h" |
26 | #include "regs.h" | |
27 | #include "hard-reg-set.h" | |
28 | #include "real.h" | |
29 | #include "insn-config.h" | |
30 | #include "conditions.h" | |
31 | #include "insn-flags.h" | |
9878760c RK |
32 | #include "insn-attr.h" |
33 | #include "flags.h" | |
34 | #include "recog.h" | |
9878760c | 35 | #include "obstack.h" |
9b30bae2 | 36 | #include "tree.h" |
dfafc897 | 37 | #include "expr.h" |
2a430ec1 | 38 | #include "except.h" |
a7df97e6 | 39 | #include "function.h" |
296b8152 KG |
40 | #include "output.h" |
41 | #include "toplev.h" | |
c8023011 | 42 | #include "ggc.h" |
9ebbca7d GK |
43 | #include "hashtab.h" |
44 | #include "tm_p.h" | |
9b30bae2 | 45 | |
7509c759 MM |
46 | #ifndef TARGET_NO_PROTOTYPE |
47 | #define TARGET_NO_PROTOTYPE 0 | |
48 | #endif | |
49 | ||
5248c961 | 50 | extern int profile_block_flag; |
9878760c RK |
51 | |
52 | #define min(A,B) ((A) < (B) ? (A) : (B)) | |
53 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
54 | ||
5248c961 RK |
55 | /* Target cpu type */ |
56 | ||
57 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
58 | struct rs6000_cpu_select rs6000_select[3] = |
59 | { | |
815cdc52 MM |
60 | /* switch name, tune arch */ |
61 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
62 | { (const char *)0, "-mcpu=", 1, 1 }, | |
63 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 64 | }; |
5248c961 | 65 | |
c764f757 RK |
66 | /* Set to non-zero once AIX common-mode calls have been defined. */ |
67 | static int common_mode_defined; | |
c81bebd7 | 68 | |
9878760c RK |
69 | /* Save information from a "cmpxx" operation until the branch or scc is |
70 | emitted. */ | |
9878760c RK |
71 | rtx rs6000_compare_op0, rs6000_compare_op1; |
72 | int rs6000_compare_fp_p; | |
874a0744 | 73 | |
874a0744 MM |
74 | /* Label number of label created for -mrelocatable, to call to so we can |
75 | get the address of the GOT section */ | |
76 | int rs6000_pic_labelno; | |
c81bebd7 | 77 | |
9ebbca7d | 78 | #ifdef USING_SVR4_H |
c81bebd7 | 79 | /* Which abi to adhere to */ |
815cdc52 | 80 | const char *rs6000_abi_name = RS6000_ABI_NAME; |
d9407988 MM |
81 | |
82 | /* Semantics of the small data area */ | |
83 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
84 | ||
85 | /* Which small data model to use */ | |
815cdc52 | 86 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
87 | |
88 | /* Counter for labels which are to be placed in .fixup. */ | |
89 | int fixuplabelno = 0; | |
874a0744 | 90 | #endif |
4697a36c MM |
91 | |
92 | /* Whether a System V.4 varargs area was created. */ | |
93 | int rs6000_sysv_varargs_p; | |
8f75773e | 94 | |
b6c9286a MM |
95 | /* ABI enumeration available for subtarget to use. */ |
96 | enum rs6000_abi rs6000_current_abi; | |
97 | ||
38c1f2d7 | 98 | /* Debug flags */ |
815cdc52 | 99 | const char *rs6000_debug_name; |
38c1f2d7 MM |
100 | int rs6000_debug_stack; /* debug stack applications */ |
101 | int rs6000_debug_arg; /* debug argument handling */ | |
102 | ||
103 | /* Flag to say the TOC is initialized */ | |
104 | int toc_initialized; | |
9ebbca7d | 105 | char toc_label_name[10]; |
38c1f2d7 | 106 | |
9ebbca7d GK |
107 | /* Alias set for saves and restores from the rs6000 stack. */ |
108 | static int rs6000_sr_alias_set; | |
c8023011 | 109 | |
9ebbca7d GK |
110 | static void rs6000_add_gc_roots PARAMS ((void)); |
111 | static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT)); | |
112 | static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx)); | |
39a10a29 GK |
113 | static void validate_condition_mode |
114 | PARAMS ((enum rtx_code, enum machine_mode)); | |
115 | static rtx rs6000_generate_compare PARAMS ((enum rtx_code)); | |
e50f5f3d | 116 | static void rs6000_maybe_dead PARAMS ((rtx)); |
9ebbca7d GK |
117 | static void rs6000_emit_stack_tie PARAMS ((void)); |
118 | static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx)); | |
119 | static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int)); | |
120 | static unsigned rs6000_hash_constant PARAMS ((rtx)); | |
121 | static unsigned toc_hash_function PARAMS ((const void *)); | |
122 | static int toc_hash_eq PARAMS ((const void *, const void *)); | |
2eba1afa | 123 | static int toc_hash_mark_entry PARAMS ((void **, void *)); |
9ebbca7d GK |
124 | static void toc_hash_mark_table PARAMS ((void *)); |
125 | static int constant_pool_expr_1 PARAMS ((rtx, int *, int *)); | |
c81bebd7 MM |
126 | \f |
127 | /* Default register names. */ | |
128 | char rs6000_reg_names[][8] = | |
129 | { | |
802a0058 MM |
130 | "0", "1", "2", "3", "4", "5", "6", "7", |
131 | "8", "9", "10", "11", "12", "13", "14", "15", | |
132 | "16", "17", "18", "19", "20", "21", "22", "23", | |
133 | "24", "25", "26", "27", "28", "29", "30", "31", | |
134 | "0", "1", "2", "3", "4", "5", "6", "7", | |
135 | "8", "9", "10", "11", "12", "13", "14", "15", | |
136 | "16", "17", "18", "19", "20", "21", "22", "23", | |
137 | "24", "25", "26", "27", "28", "29", "30", "31", | |
138 | "mq", "lr", "ctr","ap", | |
139 | "0", "1", "2", "3", "4", "5", "6", "7", | |
9ebbca7d | 140 | "xer" |
c81bebd7 MM |
141 | }; |
142 | ||
143 | #ifdef TARGET_REGNAMES | |
144 | static char alt_reg_names[][8] = | |
145 | { | |
802a0058 MM |
146 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
147 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
148 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
149 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
150 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
151 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
152 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
153 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
154 | "mq", "lr", "ctr", "ap", | |
155 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
9ebbca7d | 156 | "xer" |
c81bebd7 MM |
157 | }; |
158 | #endif | |
9878760c | 159 | \f |
daf11973 MM |
160 | #ifndef MASK_STRICT_ALIGN |
161 | #define MASK_STRICT_ALIGN 0 | |
162 | #endif | |
163 | ||
5248c961 RK |
164 | /* Override command line options. Mostly we process the processor |
165 | type and sometimes adjust other TARGET_ options. */ | |
166 | ||
167 | void | |
8e3f41e7 | 168 | rs6000_override_options (default_cpu) |
d330fd93 | 169 | const char *default_cpu; |
5248c961 | 170 | { |
c4d38ccb | 171 | size_t i, j; |
8e3f41e7 | 172 | struct rs6000_cpu_select *ptr; |
5248c961 | 173 | |
85638c0d RK |
174 | /* Simplify the entries below by making a mask for any POWER |
175 | variant and any PowerPC variant. */ | |
176 | ||
938937d8 | 177 | #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING) |
68c49ffa RK |
178 | #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \ |
179 | | MASK_PPC_GFXOPT | MASK_POWERPC64) | |
180 | #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT) | |
85638c0d | 181 | |
5248c961 RK |
182 | static struct ptt |
183 | { | |
d330fd93 | 184 | const char *name; /* Canonical processor name. */ |
5248c961 RK |
185 | enum processor_type processor; /* Processor type enum value. */ |
186 | int target_enable; /* Target flags to enable. */ | |
187 | int target_disable; /* Target flags to disable. */ | |
188 | } processor_target_table[] | |
cf27b467 MM |
189 | = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS, |
190 | POWER_MASKS | POWERPC_MASKS}, | |
db7f1e43 | 191 | {"power", PROCESSOR_POWER, |
938937d8 | 192 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 | 193 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
8e3f41e7 MM |
194 | {"power2", PROCESSOR_POWER, |
195 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
196 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, | |
c71791e0 DE |
197 | {"power3", PROCESSOR_PPC630, |
198 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
199 | POWER_MASKS | MASK_PPC_GPOPT}, | |
db7f1e43 RK |
200 | {"powerpc", PROCESSOR_POWERPC, |
201 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
68c49ffa | 202 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
3cb999d8 DE |
203 | {"powerpc64", PROCESSOR_POWERPC64, |
204 | MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS, | |
205 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
db7f1e43 | 206 | {"rios", PROCESSOR_RIOS1, |
938937d8 | 207 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
208 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
209 | {"rios1", PROCESSOR_RIOS1, | |
938937d8 | 210 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
211 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
212 | {"rsc", PROCESSOR_PPC601, | |
938937d8 | 213 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
214 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
215 | {"rsc1", PROCESSOR_PPC601, | |
938937d8 | 216 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
217 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
218 | {"rios2", PROCESSOR_RIOS2, | |
938937d8 | 219 | MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2, |
db7f1e43 | 220 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
3cb999d8 DE |
221 | {"rs64a", PROCESSOR_RS64A, |
222 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
223 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
a3a1dbf6 MM |
224 | {"401", PROCESSOR_PPC403, |
225 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
226 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
49a0b204 | 227 | {"403", PROCESSOR_PPC403, |
daf11973 | 228 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN, |
49a0b204 | 229 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
cf27b467 MM |
230 | {"505", PROCESSOR_MPCCORE, |
231 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
232 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 233 | {"601", PROCESSOR_PPC601, |
938937d8 | 234 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING, |
68c49ffa | 235 | MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
1ec26da6 | 236 | {"602", PROCESSOR_PPC603, |
cf27b467 MM |
237 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
238 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
5248c961 | 239 | {"603", PROCESSOR_PPC603, |
68c49ffa RK |
240 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
241 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a MM |
242 | {"603e", PROCESSOR_PPC603, |
243 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
244 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b5370a88 | 245 | {"ec603e", PROCESSOR_PPC603, |
a3a1dbf6 MM |
246 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
247 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 248 | {"604", PROCESSOR_PPC604, |
b6c9286a MM |
249 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
250 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
cac8ce95 | 251 | {"604e", PROCESSOR_PPC604e, |
07e6159a MM |
252 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
253 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a | 254 | {"620", PROCESSOR_PPC620, |
68c49ffa | 255 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
a260abc9 | 256 | POWER_MASKS | MASK_PPC_GPOPT}, |
3cb999d8 DE |
257 | {"630", PROCESSOR_PPC630, |
258 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
259 | POWER_MASKS | MASK_PPC_GPOPT}, | |
bef84347 VM |
260 | {"740", PROCESSOR_PPC750, |
261 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
262 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
263 | {"750", PROCESSOR_PPC750, | |
264 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
265 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
07e6159a MM |
266 | {"801", PROCESSOR_MPCCORE, |
267 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
268 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
269 | {"821", PROCESSOR_MPCCORE, |
270 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
271 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
07e6159a MM |
272 | {"823", PROCESSOR_MPCCORE, |
273 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
274 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
275 | {"860", PROCESSOR_MPCCORE, |
276 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
277 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}}; | |
5248c961 | 278 | |
c4d38ccb | 279 | size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt); |
5248c961 | 280 | |
8a61d227 | 281 | int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */ |
938937d8 | 282 | int string = TARGET_STRING; /* save current -mstring/-mno-string status */ |
8a61d227 | 283 | |
5248c961 RK |
284 | profile_block_flag = 0; |
285 | ||
286 | /* Identify the processor type */ | |
8e3f41e7 | 287 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 288 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 289 | |
b6a1cbae | 290 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 291 | { |
8e3f41e7 MM |
292 | ptr = &rs6000_select[i]; |
293 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 294 | { |
8e3f41e7 MM |
295 | for (j = 0; j < ptt_size; j++) |
296 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
297 | { | |
298 | if (ptr->set_tune_p) | |
299 | rs6000_cpu = processor_target_table[j].processor; | |
300 | ||
301 | if (ptr->set_arch_p) | |
302 | { | |
303 | target_flags |= processor_target_table[j].target_enable; | |
304 | target_flags &= ~processor_target_table[j].target_disable; | |
305 | } | |
306 | break; | |
307 | } | |
308 | ||
4406229e | 309 | if (j == ptt_size) |
8e3f41e7 | 310 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
311 | } |
312 | } | |
8a61d227 | 313 | |
ef792183 MM |
314 | /* If we are optimizing big endian systems for space, use the |
315 | store multiple instructions. */ | |
316 | if (BYTES_BIG_ENDIAN && optimize_size) | |
317 | target_flags |= MASK_MULTIPLE; | |
318 | ||
8a61d227 MM |
319 | /* If -mmultiple or -mno-multiple was explicitly used, don't |
320 | override with the processor default */ | |
321 | if (TARGET_MULTIPLE_SET) | |
322 | target_flags = (target_flags & ~MASK_MULTIPLE) | multiple; | |
7e69e155 | 323 | |
938937d8 MM |
324 | /* If -mstring or -mno-string was explicitly used, don't |
325 | override with the processor default */ | |
326 | if (TARGET_STRING_SET) | |
1f5515bf | 327 | target_flags = (target_flags & ~MASK_STRING) | string; |
938937d8 | 328 | |
bef84347 VM |
329 | /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu |
330 | is a 750, because the hardware doesn't support the instructions used in | |
331 | little endian mode, and causes an alignment trap. The 750 does not cause | |
332 | an alignment trap (except when the target is unaligned). */ | |
333 | ||
bfc79d3b | 334 | if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
335 | { |
336 | if (TARGET_MULTIPLE) | |
337 | { | |
338 | target_flags &= ~MASK_MULTIPLE; | |
339 | if (TARGET_MULTIPLE_SET) | |
340 | warning ("-mmultiple is not supported on little endian systems"); | |
341 | } | |
342 | ||
343 | if (TARGET_STRING) | |
344 | { | |
345 | target_flags &= ~MASK_STRING; | |
938937d8 MM |
346 | if (TARGET_STRING_SET) |
347 | warning ("-mstring is not supported on little endian systems"); | |
7e69e155 MM |
348 | } |
349 | } | |
3933e0e1 | 350 | |
a260abc9 DE |
351 | if (flag_pic && (DEFAULT_ABI == ABI_AIX)) |
352 | { | |
353 | warning ("-f%s ignored for AIX (all code is position independent)", | |
354 | (flag_pic > 1) ? "PIC" : "pic"); | |
355 | flag_pic = 0; | |
356 | } | |
357 | ||
9861b0c9 DE |
358 | if (flag_function_sections && (write_symbols != NO_DEBUG) |
359 | && (DEFAULT_ABI == ABI_AIX)) | |
360 | { | |
361 | warning ("-ffunction-sections disabled on AIX when debugging"); | |
362 | flag_function_sections = 0; | |
363 | } | |
364 | ||
365 | if (flag_data_sections && (DEFAULT_ABI == ABI_AIX)) | |
366 | { | |
367 | warning ("-fdata-sections not supported on AIX"); | |
368 | flag_data_sections = 0; | |
369 | } | |
370 | ||
38c1f2d7 MM |
371 | /* Set debug flags */ |
372 | if (rs6000_debug_name) | |
373 | { | |
bfc79d3b | 374 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 375 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 376 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 377 | rs6000_debug_stack = 1; |
bfc79d3b | 378 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
379 | rs6000_debug_arg = 1; |
380 | else | |
381 | error ("Unknown -mdebug-%s switch", rs6000_debug_name); | |
382 | } | |
383 | ||
c81bebd7 MM |
384 | #ifdef TARGET_REGNAMES |
385 | /* If the user desires alternate register names, copy in the alternate names | |
386 | now. */ | |
387 | if (TARGET_REGNAMES) | |
4e135bdd | 388 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
389 | #endif |
390 | ||
3933e0e1 MM |
391 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
392 | SUBTARGET_OVERRIDE_OPTIONS; | |
393 | #endif | |
c8023011 MM |
394 | |
395 | /* Register global variables with the garbage collector. */ | |
396 | rs6000_add_gc_roots (); | |
9ebbca7d GK |
397 | |
398 | /* Allocate an alias set for register saves & restores from stack. */ | |
399 | rs6000_sr_alias_set = new_alias_set (); | |
400 | ||
401 | if (TARGET_TOC) | |
402 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); | |
5248c961 | 403 | } |
5accd822 DE |
404 | |
405 | void | |
406 | optimization_options (level, size) | |
e2c953b6 | 407 | int level ATTRIBUTE_UNUSED; |
5accd822 DE |
408 | int size ATTRIBUTE_UNUSED; |
409 | { | |
5accd822 | 410 | } |
3cfa4909 MM |
411 | \f |
412 | /* Do anything needed at the start of the asm file. */ | |
413 | ||
414 | void | |
415 | rs6000_file_start (file, default_cpu) | |
416 | FILE *file; | |
d330fd93 | 417 | const char *default_cpu; |
3cfa4909 | 418 | { |
c4d38ccb | 419 | size_t i; |
3cfa4909 | 420 | char buffer[80]; |
d330fd93 | 421 | const char *start = buffer; |
3cfa4909 MM |
422 | struct rs6000_cpu_select *ptr; |
423 | ||
424 | if (flag_verbose_asm) | |
425 | { | |
426 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
427 | rs6000_select[0].string = default_cpu; | |
428 | ||
b6a1cbae | 429 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
430 | { |
431 | ptr = &rs6000_select[i]; | |
432 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
433 | { | |
434 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
435 | start = ""; | |
436 | } | |
437 | } | |
438 | ||
439 | #ifdef USING_SVR4_H | |
440 | switch (rs6000_sdata) | |
441 | { | |
442 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
443 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
444 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
445 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
446 | } | |
447 | ||
448 | if (rs6000_sdata && g_switch_value) | |
449 | { | |
450 | fprintf (file, "%s -G %d", start, g_switch_value); | |
451 | start = ""; | |
452 | } | |
453 | #endif | |
454 | ||
455 | if (*start == '\0') | |
949ea356 | 456 | putc ('\n', file); |
3cfa4909 MM |
457 | } |
458 | } | |
459 | ||
24d304eb RK |
460 | \f |
461 | /* Create a CONST_DOUBLE from a string. */ | |
462 | ||
463 | struct rtx_def * | |
464 | rs6000_float_const (string, mode) | |
d330fd93 | 465 | const char *string; |
24d304eb RK |
466 | enum machine_mode mode; |
467 | { | |
468 | REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode); | |
469 | return immed_real_const_1 (value, mode); | |
470 | } | |
5248c961 | 471 | \f |
9878760c RK |
472 | /* Return non-zero if this function is known to have a null epilogue. */ |
473 | ||
474 | int | |
475 | direct_return () | |
476 | { | |
4697a36c MM |
477 | if (reload_completed) |
478 | { | |
479 | rs6000_stack_t *info = rs6000_stack_info (); | |
480 | ||
481 | if (info->first_gp_reg_save == 32 | |
482 | && info->first_fp_reg_save == 64 | |
c81fc13e DE |
483 | && ! info->lr_save_p |
484 | && ! info->cr_save_p | |
485 | && ! info->push_p) | |
4697a36c MM |
486 | return 1; |
487 | } | |
488 | ||
489 | return 0; | |
9878760c RK |
490 | } |
491 | ||
492 | /* Returns 1 always. */ | |
493 | ||
494 | int | |
495 | any_operand (op, mode) | |
296b8152 KG |
496 | register rtx op ATTRIBUTE_UNUSED; |
497 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
9878760c RK |
498 | { |
499 | return 1; | |
500 | } | |
501 | ||
b6c9286a | 502 | /* Returns 1 if op is the count register */ |
38c1f2d7 MM |
503 | int |
504 | count_register_operand(op, mode) | |
b6c9286a | 505 | register rtx op; |
296b8152 | 506 | enum machine_mode mode ATTRIBUTE_UNUSED; |
b6c9286a MM |
507 | { |
508 | if (GET_CODE (op) != REG) | |
509 | return 0; | |
510 | ||
511 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
512 | return 1; | |
513 | ||
514 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
515 | return 1; | |
516 | ||
517 | return 0; | |
518 | } | |
519 | ||
38c1f2d7 | 520 | int |
9ebbca7d | 521 | xer_operand(op, mode) |
802a0058 | 522 | register rtx op; |
296b8152 | 523 | enum machine_mode mode ATTRIBUTE_UNUSED; |
802a0058 MM |
524 | { |
525 | if (GET_CODE (op) != REG) | |
526 | return 0; | |
527 | ||
9ebbca7d | 528 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
529 | return 1; |
530 | ||
802a0058 MM |
531 | return 0; |
532 | } | |
533 | ||
9878760c RK |
534 | /* Return 1 if OP is a constant that can fit in a D field. */ |
535 | ||
536 | int | |
537 | short_cint_operand (op, mode) | |
538 | register rtx op; | |
296b8152 | 539 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 540 | { |
5f59ecb7 DE |
541 | return (GET_CODE (op) == CONST_INT |
542 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
543 | } |
544 | ||
545 | /* Similar for a unsigned D field. */ | |
546 | ||
547 | int | |
548 | u_short_cint_operand (op, mode) | |
549 | register rtx op; | |
296b8152 | 550 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 551 | { |
19684119 | 552 | return (GET_CODE (op) == CONST_INT |
5f59ecb7 | 553 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')); |
9878760c RK |
554 | } |
555 | ||
dcfedcd0 RK |
556 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
557 | ||
558 | int | |
559 | non_short_cint_operand (op, mode) | |
560 | register rtx op; | |
296b8152 | 561 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
562 | { |
563 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 564 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
565 | } |
566 | ||
9878760c RK |
567 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
568 | ctr, or lr). */ | |
569 | ||
570 | int | |
cd2b37d9 | 571 | gpc_reg_operand (op, mode) |
9878760c RK |
572 | register rtx op; |
573 | enum machine_mode mode; | |
574 | { | |
575 | return (register_operand (op, mode) | |
802a0058 | 576 | && (GET_CODE (op) != REG |
9ebbca7d GK |
577 | || (REGNO (op) >= ARG_POINTER_REGNUM |
578 | && !XER_REGNO_P (REGNO (op))) | |
579 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
580 | } |
581 | ||
582 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
583 | CR field. */ | |
584 | ||
585 | int | |
586 | cc_reg_operand (op, mode) | |
587 | register rtx op; | |
588 | enum machine_mode mode; | |
589 | { | |
590 | return (register_operand (op, mode) | |
591 | && (GET_CODE (op) != REG | |
592 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
593 | || CR_REGNO_P (REGNO (op)))); | |
594 | } | |
595 | ||
815cdc52 MM |
596 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
597 | CR field that isn't CR0. */ | |
598 | ||
599 | int | |
600 | cc_reg_not_cr0_operand (op, mode) | |
601 | register rtx op; | |
602 | enum machine_mode mode; | |
603 | { | |
604 | return (register_operand (op, mode) | |
605 | && (GET_CODE (op) != REG | |
606 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
607 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
608 | } | |
609 | ||
9878760c RK |
610 | /* Returns 1 if OP is either a constant integer valid for a D-field or a |
611 | non-special register. If a register, it must be in the proper mode unless | |
612 | MODE is VOIDmode. */ | |
613 | ||
614 | int | |
615 | reg_or_short_operand (op, mode) | |
616 | register rtx op; | |
617 | enum machine_mode mode; | |
618 | { | |
f5a28898 | 619 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
620 | } |
621 | ||
622 | /* Similar, except check if the negation of the constant would be valid for | |
623 | a D-field. */ | |
624 | ||
625 | int | |
626 | reg_or_neg_short_operand (op, mode) | |
627 | register rtx op; | |
628 | enum machine_mode mode; | |
629 | { | |
630 | if (GET_CODE (op) == CONST_INT) | |
631 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'); | |
632 | ||
cd2b37d9 | 633 | return gpc_reg_operand (op, mode); |
9878760c RK |
634 | } |
635 | ||
636 | /* Return 1 if the operand is either a register or an integer whose high-order | |
637 | 16 bits are zero. */ | |
638 | ||
639 | int | |
640 | reg_or_u_short_operand (op, mode) | |
641 | register rtx op; | |
642 | enum machine_mode mode; | |
643 | { | |
e675f625 | 644 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
645 | } |
646 | ||
647 | /* Return 1 is the operand is either a non-special register or ANY | |
648 | constant integer. */ | |
649 | ||
650 | int | |
651 | reg_or_cint_operand (op, mode) | |
652 | register rtx op; | |
653 | enum machine_mode mode; | |
654 | { | |
f6bf7de2 DE |
655 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
656 | } | |
657 | ||
658 | /* Return 1 is the operand is either a non-special register or ANY | |
659 | 32-bit signed constant integer. */ | |
660 | ||
661 | int | |
662 | reg_or_arith_cint_operand (op, mode) | |
663 | register rtx op; | |
664 | enum machine_mode mode; | |
665 | { | |
666 | return (gpc_reg_operand (op, mode) | |
667 | || (GET_CODE (op) == CONST_INT | |
668 | #if HOST_BITS_PER_WIDE_INT != 32 | |
669 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) | |
670 | < 0x100000000u) | |
671 | #endif | |
672 | )); | |
9878760c RK |
673 | } |
674 | ||
9ebbca7d GK |
675 | /* Return 1 is the operand is either a non-special register or ANY |
676 | 32-bit unsigned constant integer. */ | |
677 | ||
678 | int | |
1d328b19 | 679 | reg_or_logical_cint_operand (op, mode) |
9ebbca7d GK |
680 | register rtx op; |
681 | enum machine_mode mode; | |
682 | { | |
1d328b19 GK |
683 | if (GET_CODE (op) == CONST_INT) |
684 | { | |
685 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
686 | { | |
687 | if (GET_MODE_BITSIZE (mode) <= 32) | |
688 | abort(); | |
689 | ||
690 | if (INTVAL (op) < 0) | |
691 | return 0; | |
692 | } | |
693 | ||
694 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 695 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
696 | } |
697 | else if (GET_CODE (op) == CONST_DOUBLE) | |
698 | { | |
699 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
700 | || mode != DImode) | |
701 | abort(); | |
702 | ||
703 | return CONST_DOUBLE_HIGH (op) == 0; | |
704 | } | |
705 | else | |
706 | return gpc_reg_operand (op, mode); | |
9ebbca7d GK |
707 | } |
708 | ||
766a866c MM |
709 | /* Return 1 if the operand is an operand that can be loaded via the GOT */ |
710 | ||
711 | int | |
712 | got_operand (op, mode) | |
713 | register rtx op; | |
296b8152 | 714 | enum machine_mode mode ATTRIBUTE_UNUSED; |
766a866c MM |
715 | { |
716 | return (GET_CODE (op) == SYMBOL_REF | |
717 | || GET_CODE (op) == CONST | |
718 | || GET_CODE (op) == LABEL_REF); | |
719 | } | |
720 | ||
38c1f2d7 MM |
721 | /* Return 1 if the operand is a simple references that can be loaded via |
722 | the GOT (labels involving addition aren't allowed). */ | |
723 | ||
724 | int | |
725 | got_no_const_operand (op, mode) | |
726 | register rtx op; | |
296b8152 | 727 | enum machine_mode mode ATTRIBUTE_UNUSED; |
38c1f2d7 MM |
728 | { |
729 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
730 | } | |
731 | ||
4e74d8ec MM |
732 | /* Return the number of instructions it takes to form a constant in an |
733 | integer register. */ | |
734 | ||
735 | static int | |
736 | num_insns_constant_wide (value) | |
737 | HOST_WIDE_INT value; | |
738 | { | |
739 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 740 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
741 | return 1; |
742 | ||
4e74d8ec | 743 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 744 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
745 | return 1; |
746 | ||
5f59ecb7 | 747 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 748 | else if (TARGET_POWERPC64) |
4e74d8ec | 749 | { |
0858c623 | 750 | unsigned HOST_WIDE_INT low = value & 0xffffffff; |
4e74d8ec MM |
751 | HOST_WIDE_INT high = value >> 32; |
752 | ||
0858c623 | 753 | if (high == 0 && (low & 0x80000000) == 0) |
4e74d8ec MM |
754 | return 2; |
755 | ||
0858c623 | 756 | else if (high == -1 && (low & 0x80000000) != 0) |
4e74d8ec MM |
757 | return 2; |
758 | ||
c81fc13e | 759 | else if (! low) |
4e74d8ec MM |
760 | return num_insns_constant_wide (high) + 1; |
761 | ||
762 | else | |
763 | return (num_insns_constant_wide (high) | |
e396202a | 764 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
765 | } |
766 | #endif | |
767 | ||
768 | else | |
769 | return 2; | |
770 | } | |
771 | ||
772 | int | |
773 | num_insns_constant (op, mode) | |
774 | rtx op; | |
775 | enum machine_mode mode; | |
776 | { | |
4e74d8ec MM |
777 | if (GET_CODE (op) == CONST_INT) |
778 | return num_insns_constant_wide (INTVAL (op)); | |
779 | ||
6fc48950 MM |
780 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
781 | { | |
782 | long l; | |
783 | REAL_VALUE_TYPE rv; | |
784 | ||
785 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
786 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
787 | return num_insns_constant_wide ((HOST_WIDE_INT)l); | |
788 | } | |
789 | ||
47ad8c61 | 790 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 791 | { |
47ad8c61 MM |
792 | HOST_WIDE_INT low; |
793 | HOST_WIDE_INT high; | |
794 | long l[2]; | |
795 | REAL_VALUE_TYPE rv; | |
796 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 797 | |
47ad8c61 MM |
798 | if (mode == VOIDmode || mode == DImode) |
799 | { | |
800 | high = CONST_DOUBLE_HIGH (op); | |
801 | low = CONST_DOUBLE_LOW (op); | |
802 | } | |
803 | else | |
804 | { | |
805 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
806 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
807 | high = l[endian]; | |
808 | low = l[1 - endian]; | |
809 | } | |
4e74d8ec | 810 | |
47ad8c61 MM |
811 | if (TARGET_32BIT) |
812 | return (num_insns_constant_wide (low) | |
813 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
814 | |
815 | else | |
47ad8c61 | 816 | { |
0858c623 | 817 | if (high == 0 && (low & 0x80000000) == 0) |
47ad8c61 MM |
818 | return num_insns_constant_wide (low); |
819 | ||
0858c623 | 820 | else if (high == -1 && (low & 0x80000000) != 0) |
47ad8c61 MM |
821 | return num_insns_constant_wide (low); |
822 | ||
a260abc9 DE |
823 | else if (mask64_operand (op, mode)) |
824 | return 2; | |
825 | ||
47ad8c61 MM |
826 | else if (low == 0) |
827 | return num_insns_constant_wide (high) + 1; | |
828 | ||
829 | else | |
830 | return (num_insns_constant_wide (high) | |
831 | + num_insns_constant_wide (low) + 1); | |
832 | } | |
4e74d8ec MM |
833 | } |
834 | ||
835 | else | |
836 | abort (); | |
837 | } | |
838 | ||
6f2f8311 RK |
839 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register |
840 | with one instruction per word. We only do this if we can safely read | |
841 | CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
842 | |
843 | int | |
844 | easy_fp_constant (op, mode) | |
845 | register rtx op; | |
846 | register enum machine_mode mode; | |
847 | { | |
9878760c RK |
848 | if (GET_CODE (op) != CONST_DOUBLE |
849 | || GET_MODE (op) != mode | |
4e74d8ec | 850 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
851 | return 0; |
852 | ||
b6c9286a | 853 | /* Consider all constants with -msoft-float to be easy */ |
4e74d8ec | 854 | if (TARGET_SOFT_FLOAT && mode != DImode) |
b6c9286a MM |
855 | return 1; |
856 | ||
a7273471 MM |
857 | /* If we are using V.4 style PIC, consider all constants to be hard */ |
858 | if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)) | |
859 | return 0; | |
860 | ||
5ae4759c MM |
861 | #ifdef TARGET_RELOCATABLE |
862 | /* Similarly if we are using -mrelocatable, consider all constants to be hard */ | |
863 | if (TARGET_RELOCATABLE) | |
864 | return 0; | |
865 | #endif | |
866 | ||
042259f2 DE |
867 | if (mode == DFmode) |
868 | { | |
869 | long k[2]; | |
870 | REAL_VALUE_TYPE rv; | |
871 | ||
872 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
873 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 874 | |
4e74d8ec MM |
875 | return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1 |
876 | && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1); | |
042259f2 | 877 | } |
4e74d8ec MM |
878 | |
879 | else if (mode == SFmode) | |
042259f2 DE |
880 | { |
881 | long l; | |
882 | REAL_VALUE_TYPE rv; | |
883 | ||
884 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
885 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 886 | |
4e74d8ec | 887 | return num_insns_constant_wide (l) == 1; |
042259f2 | 888 | } |
4e74d8ec | 889 | |
a260abc9 | 890 | else if (mode == DImode) |
c81fc13e | 891 | return ((TARGET_POWERPC64 |
a260abc9 DE |
892 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
893 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 894 | |
a9098fd0 GK |
895 | else if (mode == SImode) |
896 | return 1; | |
4e74d8ec MM |
897 | else |
898 | abort (); | |
9878760c | 899 | } |
8f75773e | 900 | |
b6c9286a MM |
901 | /* Return 1 if the operand is in volatile memory. Note that during the |
902 | RTL generation phase, memory_operand does not return TRUE for | |
903 | volatile memory references. So this function allows us to | |
904 | recognize volatile references where its safe. */ | |
905 | ||
906 | int | |
907 | volatile_mem_operand (op, mode) | |
908 | register rtx op; | |
909 | enum machine_mode mode; | |
910 | { | |
911 | if (GET_CODE (op) != MEM) | |
912 | return 0; | |
913 | ||
914 | if (!MEM_VOLATILE_P (op)) | |
915 | return 0; | |
916 | ||
917 | if (mode != GET_MODE (op)) | |
918 | return 0; | |
919 | ||
920 | if (reload_completed) | |
921 | return memory_operand (op, mode); | |
922 | ||
923 | if (reload_in_progress) | |
924 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
925 | ||
926 | return memory_address_p (mode, XEXP (op, 0)); | |
927 | } | |
928 | ||
97f6e72f | 929 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
930 | |
931 | int | |
97f6e72f | 932 | offsettable_mem_operand (op, mode) |
914c2e77 RK |
933 | register rtx op; |
934 | enum machine_mode mode; | |
935 | { | |
97f6e72f | 936 | return ((GET_CODE (op) == MEM) |
677a9668 | 937 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 938 | mode, XEXP (op, 0))); |
914c2e77 RK |
939 | } |
940 | ||
9878760c RK |
941 | /* Return 1 if the operand is either an easy FP constant (see above) or |
942 | memory. */ | |
943 | ||
944 | int | |
945 | mem_or_easy_const_operand (op, mode) | |
946 | register rtx op; | |
947 | enum machine_mode mode; | |
948 | { | |
949 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
950 | } | |
951 | ||
952 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 953 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
954 | |
955 | int | |
956 | add_operand (op, mode) | |
957 | register rtx op; | |
958 | enum machine_mode mode; | |
959 | { | |
960 | return (reg_or_short_operand (op, mode) | |
19684119 | 961 | || (GET_CODE (op) == CONST_INT |
5f59ecb7 | 962 | && CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'))); |
9878760c RK |
963 | } |
964 | ||
dcfedcd0 RK |
965 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
966 | ||
967 | int | |
968 | non_add_cint_operand (op, mode) | |
969 | register rtx op; | |
296b8152 | 970 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
971 | { |
972 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 973 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000 |
5f59ecb7 | 974 | && ! CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')); |
dcfedcd0 RK |
975 | } |
976 | ||
9878760c RK |
977 | /* Return 1 if the operand is a non-special register or a constant that |
978 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
979 | ||
980 | int | |
981 | logical_operand (op, mode) | |
982 | register rtx op; | |
983 | enum machine_mode mode; | |
984 | { | |
1d328b19 GK |
985 | /* an unsigned representation of 'op'. */ |
986 | unsigned HOST_WIDE_INT opl, oph; | |
987 | ||
dfbdccdb GK |
988 | if (gpc_reg_operand (op, mode)) |
989 | return 1; | |
1d328b19 | 990 | |
dfbdccdb GK |
991 | if (GET_CODE (op) == CONST_INT) |
992 | { | |
1d328b19 GK |
993 | opl = INTVAL (op) & GET_MODE_MASK (mode); |
994 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
995 | oph = 0; | |
996 | else | |
997 | oph = INTVAL (op) >> (HOST_BITS_PER_WIDE_INT - 1); | |
dfbdccdb GK |
998 | } |
999 | else if (GET_CODE (op) == CONST_DOUBLE) | |
1000 | { | |
1d328b19 GK |
1001 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
1002 | abort(); | |
1003 | ||
1004 | opl = CONST_DOUBLE_LOW (op); | |
1005 | oph = CONST_DOUBLE_HIGH (op); | |
dfbdccdb GK |
1006 | } |
1007 | else | |
1008 | return 0; | |
1d328b19 GK |
1009 | |
1010 | return (oph == 0 | |
1011 | && ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 | |
0858c623 | 1012 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0)); |
9878760c RK |
1013 | } |
1014 | ||
dcfedcd0 | 1015 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 1016 | above), but could be split into one. */ |
dcfedcd0 RK |
1017 | |
1018 | int | |
1019 | non_logical_cint_operand (op, mode) | |
1020 | register rtx op; | |
5f59ecb7 | 1021 | enum machine_mode mode; |
dcfedcd0 | 1022 | { |
dfbdccdb | 1023 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
1024 | && ! logical_operand (op, mode) |
1025 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
1026 | } |
1027 | ||
19ba8161 | 1028 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
1029 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
1030 | Reject all ones and all zeros, since these should have been optimized | |
1031 | away and confuse the making of MB and ME. */ | |
1032 | ||
1033 | int | |
19ba8161 DE |
1034 | mask_operand (op, mode) |
1035 | register rtx op; | |
1036 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
9878760c | 1037 | { |
19ba8161 | 1038 | HOST_WIDE_INT c; |
9878760c RK |
1039 | int i; |
1040 | int last_bit_value; | |
1041 | int transitions = 0; | |
1042 | ||
19ba8161 DE |
1043 | if (GET_CODE (op) != CONST_INT) |
1044 | return 0; | |
1045 | ||
1046 | c = INTVAL (op); | |
1047 | ||
9878760c RK |
1048 | if (c == 0 || c == ~0) |
1049 | return 0; | |
1050 | ||
1051 | last_bit_value = c & 1; | |
1052 | ||
1053 | for (i = 1; i < 32; i++) | |
1054 | if (((c >>= 1) & 1) != last_bit_value) | |
1055 | last_bit_value ^= 1, transitions++; | |
1056 | ||
1057 | return transitions <= 2; | |
1058 | } | |
1059 | ||
a260abc9 DE |
1060 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
1061 | It is if there are no more than one 1->0 or 0->1 transitions. | |
1062 | Reject all ones and all zeros, since these should have been optimized | |
1063 | away and confuse the making of MB and ME. */ | |
9878760c RK |
1064 | |
1065 | int | |
a260abc9 DE |
1066 | mask64_operand (op, mode) |
1067 | register rtx op; | |
1068 | enum machine_mode mode; | |
1069 | { | |
1070 | if (GET_CODE (op) == CONST_INT) | |
1071 | { | |
1072 | HOST_WIDE_INT c = INTVAL (op); | |
1073 | int i; | |
1074 | int last_bit_value; | |
1075 | int transitions = 0; | |
1076 | ||
1077 | if (c == 0 || c == ~0) | |
1078 | return 0; | |
1079 | ||
1080 | last_bit_value = c & 1; | |
1081 | ||
1082 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1083 | if (((c >>= 1) & 1) != last_bit_value) | |
1084 | last_bit_value ^= 1, transitions++; | |
1085 | ||
e2c953b6 DE |
1086 | return transitions <= 1; |
1087 | } | |
1088 | else if (GET_CODE (op) == CONST_DOUBLE | |
1089 | && (mode == VOIDmode || mode == DImode)) | |
1090 | { | |
1091 | HOST_WIDE_INT low = CONST_DOUBLE_LOW (op); | |
1092 | #if HOST_BITS_PER_WIDE_INT == 32 | |
1093 | HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op); | |
1094 | #endif | |
1095 | int i; | |
1096 | int last_bit_value; | |
1097 | int transitions = 0; | |
1098 | ||
1099 | if ((low == 0 | |
1100 | #if HOST_BITS_PER_WIDE_INT == 32 | |
1101 | && high == 0 | |
1102 | #endif | |
1103 | ) | |
1104 | || (low == ~0 | |
1105 | #if HOST_BITS_PER_WIDE_INT == 32 | |
1106 | && high == ~0 | |
1107 | #endif | |
1108 | )) | |
1109 | return 0; | |
1110 | ||
1111 | last_bit_value = low & 1; | |
1112 | ||
1113 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1114 | if (((low >>= 1) & 1) != last_bit_value) | |
1115 | last_bit_value ^= 1, transitions++; | |
1116 | ||
a238cd8b | 1117 | #if HOST_BITS_PER_WIDE_INT == 32 |
e2c953b6 DE |
1118 | if ((high & 1) != last_bit_value) |
1119 | last_bit_value ^= 1, transitions++; | |
1120 | ||
1121 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1122 | if (((high >>= 1) & 1) != last_bit_value) | |
1123 | last_bit_value ^= 1, transitions++; | |
a260abc9 DE |
1124 | #endif |
1125 | ||
1126 | return transitions <= 1; | |
1127 | } | |
e2c953b6 DE |
1128 | else |
1129 | return 0; | |
1130 | } | |
1131 | ||
1132 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. | |
1133 | It is if there are no more than two 1->0 or 0->1 transitions. | |
1134 | Reject all ones and all zeros, since these should have been optimized | |
1135 | away and confuse the making of MB and ME. */ | |
1136 | ||
1137 | int | |
1138 | rldic_operand (op, mode) | |
1139 | register rtx op; | |
1140 | enum machine_mode mode; | |
1141 | { | |
1142 | if (GET_CODE (op) == CONST_INT) | |
1143 | { | |
1144 | HOST_WIDE_INT c = INTVAL (op); | |
1145 | int i; | |
1146 | int last_bit_value; | |
1147 | int transitions = 0; | |
1148 | ||
1149 | if (c == 0 || c == ~0) | |
1150 | return 0; | |
1151 | ||
1152 | last_bit_value = c & 1; | |
1153 | ||
1154 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1155 | if (((c >>= 1) & 1) != last_bit_value) | |
1156 | last_bit_value ^= 1, transitions++; | |
1157 | ||
1158 | return transitions <= 2; | |
1159 | } | |
a260abc9 DE |
1160 | else if (GET_CODE (op) == CONST_DOUBLE |
1161 | && (mode == VOIDmode || mode == DImode)) | |
1162 | { | |
1163 | HOST_WIDE_INT low = CONST_DOUBLE_LOW (op); | |
a238cd8b | 1164 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1165 | HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op); |
1166 | #endif | |
1167 | int i; | |
1168 | int last_bit_value; | |
1169 | int transitions = 0; | |
1170 | ||
1171 | if ((low == 0 | |
a238cd8b | 1172 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1173 | && high == 0 |
1174 | #endif | |
1175 | ) | |
1176 | || (low == ~0 | |
a238cd8b | 1177 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1178 | && high == ~0 |
1179 | #endif | |
1180 | )) | |
1181 | return 0; | |
1182 | ||
1183 | last_bit_value = low & 1; | |
1184 | ||
1185 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1186 | if (((low >>= 1) & 1) != last_bit_value) | |
1187 | last_bit_value ^= 1, transitions++; | |
1188 | ||
a238cd8b | 1189 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1190 | if ((high & 1) != last_bit_value) |
1191 | last_bit_value ^= 1, transitions++; | |
1192 | ||
1193 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1194 | if (((high >>= 1) & 1) != last_bit_value) | |
1195 | last_bit_value ^= 1, transitions++; | |
1196 | #endif | |
1197 | ||
e2c953b6 | 1198 | return transitions <= 2; |
a260abc9 DE |
1199 | } |
1200 | else | |
1201 | return 0; | |
1202 | } | |
1203 | ||
1204 | /* Return 1 if the operand is either a non-special register or a constant | |
1205 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
1206 | ||
1207 | int | |
1208 | and64_operand (op, mode) | |
9878760c RK |
1209 | register rtx op; |
1210 | enum machine_mode mode; | |
1211 | { | |
9ebbca7d | 1212 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
1213 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
1214 | ||
1215 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
1216 | } |
1217 | ||
a260abc9 DE |
1218 | /* Return 1 if the operand is either a non-special register or a |
1219 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
1220 | |
1221 | int | |
a260abc9 DE |
1222 | and_operand (op, mode) |
1223 | register rtx op; | |
1224 | enum machine_mode mode; | |
dcfedcd0 | 1225 | { |
9ebbca7d | 1226 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
1227 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
1228 | ||
1229 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
1230 | } |
1231 | ||
9878760c RK |
1232 | /* Return 1 if the operand is a general register or memory operand. */ |
1233 | ||
1234 | int | |
1235 | reg_or_mem_operand (op, mode) | |
1236 | register rtx op; | |
1237 | register enum machine_mode mode; | |
1238 | { | |
b6c9286a MM |
1239 | return (gpc_reg_operand (op, mode) |
1240 | || memory_operand (op, mode) | |
1241 | || volatile_mem_operand (op, mode)); | |
9878760c RK |
1242 | } |
1243 | ||
a7a813f7 | 1244 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 1245 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
1246 | instruction. */ |
1247 | ||
1248 | int | |
1249 | lwa_operand (op, mode) | |
1250 | register rtx op; | |
1251 | register enum machine_mode mode; | |
1252 | { | |
1253 | rtx inner = op; | |
1254 | ||
1255 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
1256 | inner = SUBREG_REG (inner); | |
1257 | ||
1258 | return gpc_reg_operand (inner, mode) | |
1259 | || (memory_operand (inner, mode) | |
1260 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
1261 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC); | |
1262 | } | |
1263 | ||
9878760c RK |
1264 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
1265 | to CALL. This is a SYMBOL_REF or a pseudo-register, which will be | |
1266 | forced to lr. */ | |
1267 | ||
1268 | int | |
1269 | call_operand (op, mode) | |
1270 | register rtx op; | |
1271 | enum machine_mode mode; | |
1272 | { | |
1273 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
1274 | return 0; | |
1275 | ||
1276 | return (GET_CODE (op) == SYMBOL_REF | |
1277 | || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER)); | |
1278 | } | |
1279 | ||
2af3d377 RK |
1280 | |
1281 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in | |
8f1b829e | 1282 | this file and the function is not weakly defined. */ |
2af3d377 RK |
1283 | |
1284 | int | |
1285 | current_file_function_operand (op, mode) | |
1286 | register rtx op; | |
296b8152 | 1287 | enum machine_mode mode ATTRIBUTE_UNUSED; |
2af3d377 RK |
1288 | { |
1289 | return (GET_CODE (op) == SYMBOL_REF | |
1290 | && (SYMBOL_REF_FLAG (op) | |
8f1b829e | 1291 | || (op == XEXP (DECL_RTL (current_function_decl), 0) |
c81fc13e | 1292 | && ! DECL_WEAK (current_function_decl)))); |
2af3d377 RK |
1293 | } |
1294 | ||
1295 | ||
9878760c RK |
1296 | /* Return 1 if this operand is a valid input for a move insn. */ |
1297 | ||
1298 | int | |
1299 | input_operand (op, mode) | |
1300 | register rtx op; | |
1301 | enum machine_mode mode; | |
1302 | { | |
eb4e8003 | 1303 | /* Memory is always valid. */ |
9878760c RK |
1304 | if (memory_operand (op, mode)) |
1305 | return 1; | |
1306 | ||
34792e82 | 1307 | /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */ |
01b4cf2b | 1308 | if (GET_CODE (op) == CONSTANT_P_RTX) |
34792e82 JL |
1309 | return 1; |
1310 | ||
eb4e8003 RK |
1311 | /* For floating-point, easy constants are valid. */ |
1312 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
1313 | && CONSTANT_P (op) | |
1314 | && easy_fp_constant (op, mode)) | |
1315 | return 1; | |
1316 | ||
4e74d8ec MM |
1317 | /* Allow any integer constant. */ |
1318 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 1319 | && (GET_CODE (op) == CONST_INT |
e675f625 | 1320 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
1321 | return 1; |
1322 | ||
eb4e8003 RK |
1323 | /* For floating-point or multi-word mode, the only remaining valid type |
1324 | is a register. */ | |
9878760c RK |
1325 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
1326 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 1327 | return register_operand (op, mode); |
9878760c | 1328 | |
88fe15a1 RK |
1329 | /* The only cases left are integral modes one word or smaller (we |
1330 | do not get called for MODE_CC values). These can be in any | |
1331 | register. */ | |
1332 | if (register_operand (op, mode)) | |
a8b3aeda | 1333 | return 1; |
88fe15a1 | 1334 | |
84cf9dda | 1335 | /* A SYMBOL_REF referring to the TOC is valid. */ |
7fec4abd | 1336 | if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op)) |
84cf9dda RK |
1337 | return 1; |
1338 | ||
9ebbca7d GK |
1339 | /* A constant pool expression (relative to the TOC) is valid */ |
1340 | if (TOC_RELATIVE_EXPR_P (op)) | |
b6c9286a MM |
1341 | return 1; |
1342 | ||
88228c4b MM |
1343 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
1344 | to be valid. */ | |
c81bebd7 | 1345 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
88228c4b MM |
1346 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
1347 | && small_data_operand (op, Pmode)) | |
1348 | return 1; | |
1349 | ||
042259f2 | 1350 | return 0; |
9878760c | 1351 | } |
7509c759 MM |
1352 | |
1353 | /* Return 1 for an operand in small memory on V.4/eabi */ | |
1354 | ||
1355 | int | |
1356 | small_data_operand (op, mode) | |
296b8152 KG |
1357 | rtx op ATTRIBUTE_UNUSED; |
1358 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
7509c759 | 1359 | { |
38c1f2d7 | 1360 | #if TARGET_ELF |
5f59ecb7 | 1361 | rtx sym_ref; |
7509c759 | 1362 | |
d9407988 | 1363 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 1364 | return 0; |
a54d04b7 | 1365 | |
5b9d9a0c | 1366 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
7509c759 MM |
1367 | return 0; |
1368 | ||
88228c4b MM |
1369 | if (GET_CODE (op) == SYMBOL_REF) |
1370 | sym_ref = op; | |
1371 | ||
1372 | else if (GET_CODE (op) != CONST | |
1373 | || GET_CODE (XEXP (op, 0)) != PLUS | |
1374 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
1375 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
1376 | return 0; |
1377 | ||
88228c4b | 1378 | else |
dbf55e53 MM |
1379 | { |
1380 | rtx sum = XEXP (op, 0); | |
1381 | HOST_WIDE_INT summand; | |
1382 | ||
1383 | /* We have to be careful here, because it is the referenced address | |
1384 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
1385 | summand = INTVAL (XEXP (sum, 1)); | |
1386 | if (summand < 0 || summand > g_switch_value) | |
1387 | return 0; | |
1388 | ||
1389 | sym_ref = XEXP (sum, 0); | |
1390 | } | |
88228c4b MM |
1391 | |
1392 | if (*XSTR (sym_ref, 0) != '@') | |
7509c759 MM |
1393 | return 0; |
1394 | ||
1395 | return 1; | |
d9407988 MM |
1396 | |
1397 | #else | |
1398 | return 0; | |
1399 | #endif | |
7509c759 | 1400 | } |
9ebbca7d GK |
1401 | \f |
1402 | static int | |
1403 | constant_pool_expr_1 (op, have_sym, have_toc) | |
1404 | rtx op; | |
1405 | int *have_sym; | |
1406 | int *have_toc; | |
1407 | { | |
1408 | switch (GET_CODE(op)) | |
1409 | { | |
1410 | case SYMBOL_REF: | |
1411 | if (CONSTANT_POOL_ADDRESS_P (op)) | |
1412 | { | |
a9098fd0 | 1413 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) |
9ebbca7d GK |
1414 | { |
1415 | *have_sym = 1; | |
1416 | return 1; | |
1417 | } | |
1418 | else | |
1419 | return 0; | |
1420 | } | |
1421 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
1422 | { | |
1423 | *have_toc = 1; | |
1424 | return 1; | |
1425 | } | |
1426 | else | |
1427 | return 0; | |
1428 | case PLUS: | |
1429 | case MINUS: | |
1430 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) && | |
1431 | constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc); | |
1432 | case CONST: | |
1433 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); | |
1434 | case CONST_INT: | |
1435 | return 1; | |
1436 | default: | |
1437 | return 0; | |
1438 | } | |
1439 | } | |
1440 | ||
1441 | int | |
1442 | constant_pool_expr_p (op) | |
1443 | rtx op; | |
1444 | { | |
1445 | int have_sym = 0; | |
1446 | int have_toc = 0; | |
1447 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
1448 | } | |
1449 | ||
1450 | int | |
1451 | toc_relative_expr_p (op) | |
1452 | rtx op; | |
1453 | { | |
1454 | int have_sym = 0; | |
1455 | int have_toc = 0; | |
1456 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
1457 | } | |
1458 | ||
1459 | /* Try machine-dependent ways of modifying an illegitimate address | |
1460 | to be legitimate. If we find one, return the new, valid address. | |
1461 | This is used from only one place: `memory_address' in explow.c. | |
1462 | ||
1463 | OLDX is the address as it was before break_out_memory_refs was called. | |
1464 | In some cases it is useful to look at this to decide what needs to be done. | |
1465 | ||
1466 | MODE is passed so that this macro can use GO_IF_LEGITIMATE_ADDRESS. | |
1467 | ||
1468 | It is always safe for this macro to do nothing. It exists to recognize | |
1469 | opportunities to optimize the output. | |
1470 | ||
1471 | On RS/6000, first check for the sum of a register with a constant | |
1472 | integer that is out of range. If so, generate code to add the | |
1473 | constant with the low-order 16 bits masked to the register and force | |
1474 | this result into another register (this can be done with `cau'). | |
1475 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
1476 | possibility of bit 16 being a one. | |
1477 | ||
1478 | Then check for the sum of a register and something not constant, try to | |
1479 | load the other things into a register and return the sum. */ | |
1480 | rtx | |
1481 | rs6000_legitimize_address (x, oldx, mode) | |
1482 | rtx x; | |
1483 | rtx oldx ATTRIBUTE_UNUSED; | |
1484 | enum machine_mode mode; | |
1485 | { | |
1486 | if (GET_CODE (x) == PLUS | |
1487 | && GET_CODE (XEXP (x, 0)) == REG | |
1488 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1489 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
1490 | { | |
1491 | HOST_WIDE_INT high_int, low_int; | |
1492 | rtx sum; | |
1493 | high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff); | |
1494 | low_int = INTVAL (XEXP (x, 1)) & 0xffff; | |
1495 | if (low_int & 0x8000) | |
1496 | high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16; | |
1497 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
1498 | GEN_INT (high_int)), 0); | |
1499 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
1500 | } | |
1501 | else if (GET_CODE (x) == PLUS | |
1502 | && GET_CODE (XEXP (x, 0)) == REG | |
1503 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
1504 | && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode) | |
1505 | && (TARGET_POWERPC64 || mode != DImode) | |
1506 | && mode != TImode) | |
1507 | { | |
1508 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
1509 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
1510 | } | |
1511 | else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic | |
1512 | && GET_CODE (x) != CONST_INT | |
1513 | && GET_CODE (x) != CONST_DOUBLE | |
1514 | && CONSTANT_P (x) | |
1515 | && (TARGET_HARD_FLOAT || mode != DFmode) | |
1516 | && mode != DImode | |
1517 | && mode != TImode) | |
1518 | { | |
1519 | rtx reg = gen_reg_rtx (Pmode); | |
1520 | emit_insn (gen_elf_high (reg, (x))); | |
1521 | return gen_rtx_LO_SUM (Pmode, reg, (x)); | |
1522 | } | |
1523 | else if (TARGET_TOC | |
1524 | && CONSTANT_POOL_EXPR_P (x) | |
a9098fd0 | 1525 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
1526 | { |
1527 | return create_TOC_reference (x); | |
1528 | } | |
1529 | else | |
1530 | return NULL_RTX; | |
1531 | } | |
fb4d4348 GK |
1532 | \f |
1533 | /* Emit a move from SOURCE to DEST in mode MODE. */ | |
1534 | void | |
1535 | rs6000_emit_move (dest, source, mode) | |
1536 | rtx dest; | |
1537 | rtx source; | |
1538 | enum machine_mode mode; | |
1539 | { | |
1540 | rtx operands[2]; | |
1541 | operands[0] = dest; | |
1542 | operands[1] = source; | |
1543 | ||
1544 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ | |
1545 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
1546 | && ! FLOAT_MODE_P (mode) | |
1547 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
1548 | { | |
1549 | /* FIXME. This should never happen. */ | |
1550 | /* Since it seems that it does, do the safe thing and convert | |
1551 | to a CONST_INT. */ | |
1552 | operands[1] = | |
1553 | GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode)); | |
1554 | } | |
1555 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
1556 | && ! FLOAT_MODE_P (mode) | |
1557 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
1558 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
1559 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
1560 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
1561 | abort (); | |
1562 | ||
1563 | if (! no_new_pseudos && GET_CODE (operands[0]) != REG) | |
1564 | operands[1] = force_reg (mode, operands[1]); | |
a9098fd0 | 1565 | |
ffc14f31 GK |
1566 | if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT |
1567 | && GET_CODE (operands[0]) == MEM) | |
fb4d4348 | 1568 | { |
ffc14f31 GK |
1569 | int regnum; |
1570 | ||
1571 | if (reload_in_progress || reload_completed) | |
1572 | regnum = true_regnum (operands[1]); | |
1573 | else if (GET_CODE (operands[1]) == REG) | |
1574 | regnum = REGNO (operands[1]); | |
1575 | else | |
1576 | regnum = -1; | |
fb4d4348 GK |
1577 | |
1578 | /* If operands[1] is a register, on POWER it may have | |
1579 | double-precision data in it, so truncate it to single | |
1580 | precision. */ | |
1581 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
1582 | { | |
1583 | rtx newreg; | |
1584 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
1585 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
1586 | operands[1] = newreg; | |
1587 | } | |
1588 | } | |
1589 | ||
a9098fd0 GK |
1590 | /* Handle the case where reload calls us with an invalid address; |
1591 | and the case of CONSTANT_P_RTX. */ | |
1592 | if (! general_operand (operands[1], mode) | |
1593 | || ! nonimmediate_operand (operands[0], mode) | |
1594 | || GET_CODE (operands[1]) == CONSTANT_P_RTX) | |
fb4d4348 GK |
1595 | { |
1596 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
1597 | return; | |
1598 | } | |
a9098fd0 | 1599 | |
fb4d4348 GK |
1600 | /* FIXME: In the long term, this switch statement should go away |
1601 | and be replaced by a sequence of tests based on things like | |
1602 | mode == Pmode. */ | |
1603 | switch (mode) | |
1604 | { | |
1605 | case HImode: | |
1606 | case QImode: | |
1607 | if (CONSTANT_P (operands[1]) | |
1608 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 1609 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
1610 | break; |
1611 | ||
1612 | case DFmode: | |
1613 | case SFmode: | |
1614 | if (CONSTANT_P (operands[1]) | |
1615 | && ! easy_fp_constant (operands[1], mode)) | |
a9098fd0 | 1616 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
1617 | break; |
1618 | ||
1619 | case SImode: | |
a9098fd0 | 1620 | case DImode: |
fb4d4348 GK |
1621 | /* Use default pattern for address of ELF small data */ |
1622 | if (TARGET_ELF | |
a9098fd0 | 1623 | && mode == Pmode |
fb4d4348 | 1624 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
a9098fd0 GK |
1625 | && (GET_CODE (operands[1]) == SYMBOL_REF |
1626 | || GET_CODE (operands[1]) == CONST) | |
1627 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
1628 | { |
1629 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
1630 | return; | |
1631 | } | |
1632 | ||
1633 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
a9098fd0 GK |
1634 | && mode == Pmode && mode == SImode |
1635 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
1636 | { |
1637 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
1638 | return; | |
1639 | } | |
1640 | ||
a9098fd0 GK |
1641 | if (TARGET_ELF && TARGET_NO_TOC && ! flag_pic |
1642 | && mode == Pmode | |
fb4d4348 GK |
1643 | && CONSTANT_P (operands[1]) |
1644 | && GET_CODE (operands[1]) != HIGH | |
1645 | && GET_CODE (operands[1]) != CONST_INT) | |
1646 | { | |
a9098fd0 | 1647 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
1648 | |
1649 | /* If this is a function address on -mcall-aixdesc, | |
1650 | convert it to the address of the descriptor. */ | |
1651 | if (DEFAULT_ABI == ABI_AIX | |
1652 | && GET_CODE (operands[1]) == SYMBOL_REF | |
1653 | && XSTR (operands[1], 0)[0] == '.') | |
1654 | { | |
1655 | const char *name = XSTR (operands[1], 0); | |
1656 | rtx new_ref; | |
1657 | while (*name == '.') | |
1658 | name++; | |
1659 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
1660 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
1661 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
1662 | SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]); | |
1663 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); | |
1664 | operands[1] = new_ref; | |
1665 | } | |
7509c759 | 1666 | |
fb4d4348 GK |
1667 | emit_insn (gen_elf_high (target, operands[1])); |
1668 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
1669 | return; | |
1670 | } | |
1671 | ||
a9098fd0 GK |
1672 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
1673 | and we have put it in the TOC, we just need to make a TOC-relative | |
1674 | reference to it. */ | |
1675 | if (TARGET_TOC | |
1676 | && GET_CODE (operands[1]) == SYMBOL_REF | |
1677 | && CONSTANT_POOL_EXPR_P (operands[1]) | |
1678 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), | |
1679 | get_pool_mode (operands[1]))) | |
fb4d4348 | 1680 | { |
a9098fd0 | 1681 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 1682 | } |
a9098fd0 GK |
1683 | else if (mode == Pmode |
1684 | && CONSTANT_P (operands[1]) | |
1685 | && (((HOST_BITS_PER_WIDE_INT != 32 | |
1686 | || GET_CODE (operands[1]) != CONST_INT) | |
1687 | && ! easy_fp_constant (operands[1], mode)) | |
1688 | || (GET_CODE (operands[0]) == REG | |
1689 | && FP_REGNO_P (REGNO (operands[0])))) | |
1690 | && GET_CODE (operands[1]) != HIGH | |
1691 | && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]) | |
1692 | && ! TOC_RELATIVE_EXPR_P (operands[1])) | |
fb4d4348 | 1693 | { |
a9098fd0 GK |
1694 | int special_constant_p = 0; |
1695 | ||
fb4d4348 GK |
1696 | /* Emit a USE operation so that the constant isn't deleted if |
1697 | expensive optimizations are turned on because nobody | |
1698 | references it. This should only be done for operands that | |
1699 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
1700 | This should not be done for operands that contain LABEL_REFs. | |
1701 | For now, we just handle the obvious case. */ | |
1702 | if (GET_CODE (operands[1]) != LABEL_REF) | |
1703 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
1704 | ||
1705 | /* If we are to limit the number of things we put in the TOC and | |
1706 | this is a symbol plus a constant we can add in one insn, | |
1707 | just put the symbol in the TOC and add the constant. Don't do | |
1708 | this if reload is in progress. */ | |
1709 | if (GET_CODE (operands[1]) == CONST | |
1710 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
1711 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 1712 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
1713 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
1714 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
1715 | && ! side_effects_p (operands[0])) | |
1716 | { | |
a9098fd0 | 1717 | rtx sym = force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); |
fb4d4348 GK |
1718 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
1719 | ||
a9098fd0 GK |
1720 | sym = force_reg (mode, sym); |
1721 | if (mode == SImode) | |
1722 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
1723 | else | |
1724 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
1725 | return; |
1726 | } | |
1727 | ||
a9098fd0 | 1728 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
1729 | |
1730 | if (TARGET_TOC | |
a9098fd0 | 1731 | && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))) |
fb4d4348 | 1732 | { |
a9098fd0 GK |
1733 | rtx constant; |
1734 | enum machine_mode cmode; | |
fb4d4348 | 1735 | |
a9098fd0 GK |
1736 | constant = get_pool_constant (XEXP (operands[1], 0)); |
1737 | cmode = get_pool_mode (XEXP (operands[1], 0)); | |
1738 | special_constant_p = | |
1739 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (constant, cmode); | |
1740 | } | |
1741 | ||
1742 | if (special_constant_p) | |
1743 | { | |
1744 | operands[1] = gen_rtx_MEM (mode, | |
1745 | create_TOC_reference (XEXP (operands[1], 0))); | |
fb4d4348 GK |
1746 | MEM_ALIAS_SET (operands[1]) = get_TOC_alias_set (); |
1747 | RTX_UNCHANGING_P (operands[1]) = 1; | |
a9098fd0 | 1748 | } |
fb4d4348 GK |
1749 | } |
1750 | break; | |
a9098fd0 | 1751 | |
fb4d4348 GK |
1752 | case TImode: |
1753 | if (GET_CODE (operands[0]) == MEM | |
1754 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
1755 | && ! reload_in_progress) | |
1756 | operands[0] = change_address (operands[0], TImode, | |
1757 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
1758 | ||
1759 | if (GET_CODE (operands[1]) == MEM | |
1760 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
1761 | && ! reload_in_progress) | |
1762 | operands[1] = change_address (operands[1], TImode, | |
1763 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
1764 | break; | |
1765 | ||
1766 | default: | |
1767 | abort (); | |
1768 | } | |
1769 | ||
a9098fd0 GK |
1770 | /* Above, we may have called force_const_mem which may have returned |
1771 | an invalid address. If we can, fix this up; otherwise, reload will | |
1772 | have to deal with it. */ | |
1773 | if (GET_CODE (operands[1]) == MEM | |
1774 | && ! memory_address_p (mode, XEXP (operands[1], 0)) | |
1775 | && ! reload_in_progress) | |
1776 | operands[1] = change_address (operands[1], mode, | |
1777 | XEXP (operands[1], 0)); | |
1778 | ||
fb4d4348 GK |
1779 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
1780 | } | |
4697a36c MM |
1781 | \f |
1782 | /* Initialize a variable CUM of type CUMULATIVE_ARGS | |
1783 | for a call to a function whose data type is FNTYPE. | |
1784 | For a library call, FNTYPE is 0. | |
1785 | ||
1786 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 1787 | so we never return a PARALLEL. */ |
4697a36c MM |
1788 | |
1789 | void | |
1790 | init_cumulative_args (cum, fntype, libname, incoming) | |
1791 | CUMULATIVE_ARGS *cum; | |
1792 | tree fntype; | |
296b8152 | 1793 | rtx libname ATTRIBUTE_UNUSED; |
4697a36c MM |
1794 | int incoming; |
1795 | { | |
1796 | static CUMULATIVE_ARGS zero_cumulative; | |
1797 | ||
1798 | *cum = zero_cumulative; | |
1799 | cum->words = 0; | |
1800 | cum->fregno = FP_ARG_MIN_REG; | |
1801 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); | |
7509c759 | 1802 | cum->call_cookie = CALL_NORMAL; |
4cc833b7 | 1803 | cum->sysv_gregno = GP_ARG_MIN_REG; |
4697a36c MM |
1804 | |
1805 | if (incoming) | |
bd227acc | 1806 | cum->nargs_prototype = 1000; /* don't return a PARALLEL */ |
4697a36c MM |
1807 | |
1808 | else if (cum->prototype) | |
1809 | cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1 | |
1810 | + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode | |
1811 | || RETURN_IN_MEMORY (TREE_TYPE (fntype)))); | |
1812 | ||
1813 | else | |
1814 | cum->nargs_prototype = 0; | |
1815 | ||
1816 | cum->orig_nargs = cum->nargs_prototype; | |
7509c759 | 1817 | |
9ebbca7d GK |
1818 | /* Check for longcall's */ |
1819 | if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
1820 | cum->call_cookie = CALL_LONG; |
1821 | ||
4697a36c MM |
1822 | if (TARGET_DEBUG_ARG) |
1823 | { | |
1824 | fprintf (stderr, "\ninit_cumulative_args:"); | |
1825 | if (fntype) | |
1826 | { | |
1827 | tree ret_type = TREE_TYPE (fntype); | |
1828 | fprintf (stderr, " ret code = %s,", | |
1829 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
1830 | } | |
1831 | ||
6a4cee5f MM |
1832 | if (cum->call_cookie & CALL_LONG) |
1833 | fprintf (stderr, " longcall,"); | |
1834 | ||
4697a36c MM |
1835 | fprintf (stderr, " proto = %d, nargs = %d\n", |
1836 | cum->prototype, cum->nargs_prototype); | |
1837 | } | |
1838 | } | |
1839 | \f | |
c229cba9 DE |
1840 | /* If defined, a C expression which determines whether, and in which |
1841 | direction, to pad out an argument with extra space. The value | |
1842 | should be of type `enum direction': either `upward' to pad above | |
1843 | the argument, `downward' to pad below, or `none' to inhibit | |
1844 | padding. | |
1845 | ||
1846 | For the AIX ABI structs are always stored left shifted in their | |
1847 | argument slot. */ | |
1848 | ||
9ebbca7d | 1849 | enum direction |
c229cba9 DE |
1850 | function_arg_padding (mode, type) |
1851 | enum machine_mode mode; | |
1852 | tree type; | |
1853 | { | |
c85f7c16 | 1854 | if (type != 0 && AGGREGATE_TYPE_P (type)) |
9ebbca7d | 1855 | return upward; |
c229cba9 DE |
1856 | |
1857 | /* This is the default definition. */ | |
1858 | return (! BYTES_BIG_ENDIAN | |
9ebbca7d | 1859 | ? upward |
c229cba9 DE |
1860 | : ((mode == BLKmode |
1861 | ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST | |
1862 | && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT)) | |
1863 | : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY) | |
9ebbca7d | 1864 | ? downward : upward)); |
c229cba9 DE |
1865 | } |
1866 | ||
b6c9286a MM |
1867 | /* If defined, a C expression that gives the alignment boundary, in bits, |
1868 | of an argument with the specified mode and type. If it is not defined, | |
1869 | PARM_BOUNDARY is used for all arguments. | |
1870 | ||
2310f99a | 1871 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
1872 | |
1873 | int | |
1874 | function_arg_boundary (mode, type) | |
1875 | enum machine_mode mode; | |
9ebbca7d | 1876 | tree type ATTRIBUTE_UNUSED; |
b6c9286a | 1877 | { |
4cc833b7 RH |
1878 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
1879 | && (mode == DImode || mode == DFmode)) | |
e1f83b4d | 1880 | return 64; |
9ebbca7d | 1881 | else |
b6c9286a | 1882 | return PARM_BOUNDARY; |
b6c9286a MM |
1883 | } |
1884 | \f | |
4697a36c MM |
1885 | /* Update the data in CUM to advance over an argument |
1886 | of mode MODE and data type TYPE. | |
1887 | (TYPE is null for libcalls where that information may not be available.) */ | |
1888 | ||
1889 | void | |
1890 | function_arg_advance (cum, mode, type, named) | |
1891 | CUMULATIVE_ARGS *cum; | |
1892 | enum machine_mode mode; | |
1893 | tree type; | |
1894 | int named; | |
1895 | { | |
1896 | cum->nargs_prototype--; | |
1897 | ||
c81bebd7 | 1898 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4697a36c | 1899 | { |
4cc833b7 RH |
1900 | if (TARGET_HARD_FLOAT |
1901 | && (mode == SFmode || mode == DFmode)) | |
4697a36c | 1902 | { |
4cc833b7 RH |
1903 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
1904 | cum->fregno++; | |
1905 | else | |
1906 | { | |
1907 | if (mode == DFmode) | |
1908 | cum->words += cum->words & 1; | |
1909 | cum->words += RS6000_ARG_SIZE (mode, type, 1); | |
1910 | } | |
4697a36c | 1911 | } |
4cc833b7 RH |
1912 | else |
1913 | { | |
1914 | int n_words; | |
1915 | int gregno = cum->sysv_gregno; | |
1916 | ||
1917 | /* Aggregates and IEEE quad get passed by reference. */ | |
1918 | if ((type && AGGREGATE_TYPE_P (type)) | |
1919 | || mode == TFmode) | |
1920 | n_words = 1; | |
1921 | else | |
1922 | n_words = RS6000_ARG_SIZE (mode, type, 1); | |
1923 | ||
1924 | /* Long long is put in odd registers. */ | |
1925 | if (n_words == 2 && (gregno & 1) == 0) | |
1926 | gregno += 1; | |
1927 | ||
1928 | /* Long long is not split between registers and stack. */ | |
1929 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) | |
1930 | { | |
1931 | /* Long long is aligned on the stack. */ | |
1932 | if (n_words == 2) | |
1933 | cum->words += cum->words & 1; | |
1934 | cum->words += n_words; | |
1935 | } | |
4697a36c | 1936 | |
4cc833b7 RH |
1937 | /* Note: continuing to accumulate gregno past when we've started |
1938 | spilling to the stack indicates the fact that we've started | |
1939 | spilling to the stack to expand_builtin_saveregs. */ | |
1940 | cum->sysv_gregno = gregno + n_words; | |
1941 | } | |
4697a36c | 1942 | |
4cc833b7 RH |
1943 | if (TARGET_DEBUG_ARG) |
1944 | { | |
1945 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
1946 | cum->words, cum->fregno); | |
1947 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
1948 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
1949 | fprintf (stderr, "mode = %4s, named = %d\n", | |
1950 | GET_MODE_NAME (mode), named); | |
1951 | } | |
4697a36c MM |
1952 | } |
1953 | else | |
4cc833b7 RH |
1954 | { |
1955 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
1956 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
1957 | cum->words += align; | |
4697a36c | 1958 | |
4cc833b7 RH |
1959 | if (named) |
1960 | { | |
1961 | cum->words += RS6000_ARG_SIZE (mode, type, named); | |
1962 | if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT) | |
1963 | cum->fregno++; | |
1964 | } | |
1965 | ||
1966 | if (TARGET_DEBUG_ARG) | |
1967 | { | |
1968 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
1969 | cum->words, cum->fregno); | |
1970 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
1971 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
1972 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
1973 | } | |
1974 | } | |
4697a36c MM |
1975 | } |
1976 | \f | |
1977 | /* Determine where to put an argument to a function. | |
1978 | Value is zero to push the argument on the stack, | |
1979 | or a hard register in which to store the argument. | |
1980 | ||
1981 | MODE is the argument's machine mode. | |
1982 | TYPE is the data type of the argument (as a tree). | |
1983 | This is null for libcalls where that information may | |
1984 | not be available. | |
1985 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
1986 | the preceding args and about the function being called. | |
1987 | NAMED is nonzero if this argument is a named parameter | |
1988 | (otherwise it is an extra parameter matching an ellipsis). | |
1989 | ||
1990 | On RS/6000 the first eight words of non-FP are normally in registers | |
1991 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
1992 | Under V.4, the first 8 FP args are in registers. | |
1993 | ||
1994 | If this is floating-point and no prototype is specified, we use | |
1995 | both an FP and integer register (or possibly FP reg and stack). Library | |
1996 | functions (when TYPE is zero) always have the proper types for args, | |
1997 | so we can pass the FP value just in one register. emit_library_function | |
1c20ae99 | 1998 | doesn't support PARALLEL anyway. */ |
4697a36c MM |
1999 | |
2000 | struct rtx_def * | |
2001 | function_arg (cum, mode, type, named) | |
2002 | CUMULATIVE_ARGS *cum; | |
2003 | enum machine_mode mode; | |
2004 | tree type; | |
2005 | int named; | |
2006 | { | |
4cc833b7 | 2007 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 2008 | |
4cc833b7 RH |
2009 | /* Return a marker to indicate whether CR1 needs to set or clear the bit |
2010 | that V.4 uses to say fp args were passed in registers. Assume that we | |
2011 | don't need the marker for software floating point, or compiler generated | |
2012 | library calls. */ | |
4697a36c MM |
2013 | if (mode == VOIDmode) |
2014 | { | |
c81bebd7 | 2015 | if ((abi == ABI_V4 || abi == ABI_SOLARIS) |
7509c759 MM |
2016 | && TARGET_HARD_FLOAT |
2017 | && cum->nargs_prototype < 0 | |
4697a36c | 2018 | && type && (cum->prototype || TARGET_NO_PROTOTYPE)) |
7509c759 | 2019 | { |
6a4cee5f MM |
2020 | return GEN_INT (cum->call_cookie |
2021 | | ((cum->fregno == FP_ARG_MIN_REG) | |
2022 | ? CALL_V4_SET_FP_ARGS | |
2023 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 2024 | } |
4697a36c | 2025 | |
7509c759 | 2026 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
2027 | } |
2028 | ||
4cc833b7 | 2029 | if (abi == ABI_V4 || abi == ABI_SOLARIS) |
4697a36c | 2030 | { |
4cc833b7 RH |
2031 | if (TARGET_HARD_FLOAT |
2032 | && (mode == SFmode || mode == DFmode)) | |
2033 | { | |
2034 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
2035 | return gen_rtx_REG (mode, cum->fregno); | |
2036 | else | |
2037 | return NULL; | |
2038 | } | |
2039 | else | |
2040 | { | |
2041 | int n_words; | |
2042 | int gregno = cum->sysv_gregno; | |
2043 | ||
2044 | /* Aggregates and IEEE quad get passed by reference. */ | |
2045 | if ((type && AGGREGATE_TYPE_P (type)) | |
2046 | || mode == TFmode) | |
2047 | n_words = 1; | |
2048 | else | |
2049 | n_words = RS6000_ARG_SIZE (mode, type, 1); | |
2050 | ||
2051 | /* Long long is put in odd registers. */ | |
2052 | if (n_words == 2 && (gregno & 1) == 0) | |
2053 | gregno += 1; | |
2054 | ||
2055 | /* Long long is not split between registers and stack. */ | |
2056 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
2057 | return gen_rtx_REG (mode, gregno); | |
2058 | else | |
2059 | return NULL; | |
2060 | } | |
4697a36c | 2061 | } |
4cc833b7 RH |
2062 | else |
2063 | { | |
2064 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
2065 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
2066 | int align_words = cum->words + align; | |
4697a36c | 2067 | |
c81fc13e | 2068 | if (! named) |
4cc833b7 | 2069 | return NULL_RTX; |
4697a36c | 2070 | |
4cc833b7 RH |
2071 | if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
2072 | return NULL_RTX; | |
2073 | ||
2074 | if (USE_FP_FOR_ARG_P (*cum, mode, type)) | |
2075 | { | |
2076 | if (! type | |
2077 | || ((cum->nargs_prototype > 0) | |
2078 | /* IBM AIX extended its linkage convention definition always | |
2079 | to require FP args after register save area hole on the | |
2080 | stack. */ | |
2081 | && (DEFAULT_ABI != ABI_AIX | |
2082 | || ! TARGET_XL_CALL | |
2083 | || (align_words < GP_ARG_NUM_REG)))) | |
2084 | return gen_rtx_REG (mode, cum->fregno); | |
2085 | ||
2086 | return gen_rtx_PARALLEL (mode, | |
2087 | gen_rtvec (2, | |
39403d82 | 2088 | gen_rtx_EXPR_LIST (VOIDmode, |
1c20ae99 JW |
2089 | ((align_words >= GP_ARG_NUM_REG) |
2090 | ? NULL_RTX | |
2091 | : (align_words | |
2092 | + RS6000_ARG_SIZE (mode, type, named) | |
2093 | > GP_ARG_NUM_REG | |
2094 | /* If this is partially on the stack, then | |
2095 | we only include the portion actually | |
2096 | in registers here. */ | |
39403d82 | 2097 | ? gen_rtx_REG (SImode, |
1c20ae99 | 2098 | GP_ARG_MIN_REG + align_words) |
39403d82 | 2099 | : gen_rtx_REG (mode, |
1c20ae99 JW |
2100 | GP_ARG_MIN_REG + align_words))), |
2101 | const0_rtx), | |
39403d82 DE |
2102 | gen_rtx_EXPR_LIST (VOIDmode, |
2103 | gen_rtx_REG (mode, cum->fregno), | |
1c20ae99 | 2104 | const0_rtx))); |
4cc833b7 RH |
2105 | } |
2106 | else if (align_words < GP_ARG_NUM_REG) | |
2107 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
2108 | else | |
2109 | return NULL_RTX; | |
4697a36c | 2110 | } |
4697a36c MM |
2111 | } |
2112 | \f | |
2113 | /* For an arg passed partly in registers and partly in memory, | |
2114 | this is the number of registers used. | |
2115 | For args passed entirely in registers or entirely in memory, zero. */ | |
2116 | ||
2117 | int | |
2118 | function_arg_partial_nregs (cum, mode, type, named) | |
2119 | CUMULATIVE_ARGS *cum; | |
2120 | enum machine_mode mode; | |
2121 | tree type; | |
2122 | int named; | |
2123 | { | |
2124 | if (! named) | |
2125 | return 0; | |
2126 | ||
c81bebd7 | 2127 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4697a36c | 2128 | return 0; |
4697a36c MM |
2129 | |
2130 | if (USE_FP_FOR_ARG_P (*cum, mode, type)) | |
2131 | { | |
2132 | if (cum->nargs_prototype >= 0) | |
2133 | return 0; | |
2134 | } | |
2135 | ||
2136 | if (cum->words < GP_ARG_NUM_REG | |
2137 | && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named))) | |
2138 | { | |
2139 | int ret = GP_ARG_NUM_REG - cum->words; | |
2140 | if (ret && TARGET_DEBUG_ARG) | |
2141 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
2142 | ||
2143 | return ret; | |
2144 | } | |
2145 | ||
2146 | return 0; | |
2147 | } | |
2148 | \f | |
2149 | /* A C expression that indicates when an argument must be passed by | |
2150 | reference. If nonzero for an argument, a copy of that argument is | |
2151 | made in memory and a pointer to the argument is passed instead of | |
2152 | the argument itself. The pointer is passed in whatever way is | |
2153 | appropriate for passing a pointer to that type. | |
2154 | ||
2155 | Under V.4, structures and unions are passed by reference. */ | |
2156 | ||
2157 | int | |
2158 | function_arg_pass_by_reference (cum, mode, type, named) | |
296b8152 KG |
2159 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; |
2160 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4697a36c | 2161 | tree type; |
296b8152 | 2162 | int named ATTRIBUTE_UNUSED; |
4697a36c | 2163 | { |
c81bebd7 | 2164 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4cc833b7 RH |
2165 | && ((type && AGGREGATE_TYPE_P (type)) |
2166 | || mode == TFmode)) | |
4697a36c MM |
2167 | { |
2168 | if (TARGET_DEBUG_ARG) | |
2169 | fprintf (stderr, "function_arg_pass_by_reference: aggregate\n"); | |
2170 | ||
2171 | return 1; | |
2172 | } | |
4697a36c MM |
2173 | |
2174 | return 0; | |
2175 | } | |
4697a36c MM |
2176 | \f |
2177 | /* Perform any needed actions needed for a function that is receiving a | |
2178 | variable number of arguments. | |
2179 | ||
2180 | CUM is as above. | |
2181 | ||
2182 | MODE and TYPE are the mode and type of the current parameter. | |
2183 | ||
2184 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
2185 | that must be pushed by the prolog to pretend that our caller pushed | |
2186 | it. | |
2187 | ||
2188 | Normally, this macro will push all remaining incoming registers on the | |
2189 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
2190 | ||
2191 | void | |
2192 | setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl) | |
2193 | CUMULATIVE_ARGS *cum; | |
2194 | enum machine_mode mode; | |
2195 | tree type; | |
2196 | int *pretend_size; | |
2197 | int no_rtl; | |
2198 | ||
2199 | { | |
4cc833b7 RH |
2200 | CUMULATIVE_ARGS next_cum; |
2201 | int reg_size = TARGET_32BIT ? 4 : 8; | |
dfafc897 FS |
2202 | rtx save_area, mem; |
2203 | int first_reg_offset, set; | |
4697a36c | 2204 | |
60e2d0ca | 2205 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4697a36c | 2206 | { |
4cc833b7 RH |
2207 | tree fntype; |
2208 | int stdarg_p; | |
2209 | ||
2210 | fntype = TREE_TYPE (current_function_decl); | |
2211 | stdarg_p = (TYPE_ARG_TYPES (fntype) != 0 | |
2212 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
2213 | != void_type_node)); | |
2214 | ||
2215 | /* For varargs, we do not want to skip the dummy va_dcl argument. | |
2216 | For stdargs, we do want to skip the last named argument. */ | |
2217 | next_cum = *cum; | |
2218 | if (stdarg_p) | |
2219 | function_arg_advance (&next_cum, mode, type, 1); | |
2220 | ||
2221 | /* Indicate to allocate space on the stack for varargs save area. */ | |
2222 | /* ??? Does this really have to be located at a magic spot on the | |
2223 | stack, or can we allocate this with assign_stack_local instead. */ | |
4697a36c | 2224 | rs6000_sysv_varargs_p = 1; |
60e2d0ca | 2225 | if (! no_rtl) |
2c4974b7 | 2226 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 2227 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
2228 | |
2229 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 2230 | } |
60e2d0ca | 2231 | else |
4697a36c | 2232 | { |
4cc833b7 RH |
2233 | save_area = virtual_incoming_args_rtx; |
2234 | rs6000_sysv_varargs_p = 0; | |
4697a36c | 2235 | |
4cc833b7 | 2236 | first_reg_offset = cum->words; |
4697a36c MM |
2237 | if (MUST_PASS_IN_STACK (mode, type)) |
2238 | first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1); | |
4cc833b7 | 2239 | } |
4697a36c | 2240 | |
dfafc897 | 2241 | set = get_varargs_alias_set (); |
c81fc13e | 2242 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 2243 | { |
dfafc897 FS |
2244 | mem = gen_rtx_MEM (BLKmode, |
2245 | plus_constant (save_area, | |
2246 | first_reg_offset * reg_size)), | |
2247 | MEM_ALIAS_SET (mem) = set; | |
2248 | ||
4cc833b7 | 2249 | move_block_from_reg |
dfafc897 | 2250 | (GP_ARG_MIN_REG + first_reg_offset, mem, |
4cc833b7 RH |
2251 | GP_ARG_NUM_REG - first_reg_offset, |
2252 | (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD); | |
2253 | ||
2254 | /* ??? Does ABI_V4 need this at all? */ | |
4697a36c MM |
2255 | *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD; |
2256 | } | |
2257 | ||
4697a36c | 2258 | /* Save FP registers if needed. */ |
4cc833b7 | 2259 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
c81fc13e | 2260 | && TARGET_HARD_FLOAT && ! no_rtl |
4cc833b7 | 2261 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 2262 | { |
4cc833b7 | 2263 | int fregno = next_cum.fregno; |
9ebbca7d | 2264 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
2265 | rtx lab = gen_label_rtx (); |
2266 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 2267 | |
4cc833b7 | 2268 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 2269 | pc_rtx, |
39403d82 | 2270 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
2271 | gen_rtx_NE (VOIDmode, cr1, |
2272 | const0_rtx), | |
39403d82 | 2273 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
2274 | pc_rtx))); |
2275 | ||
4cc833b7 RH |
2276 | while (fregno <= FP_ARG_V4_MAX_REG) |
2277 | { | |
dfafc897 FS |
2278 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
2279 | MEM_ALIAS_SET (mem) = set; | |
2280 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); | |
4cc833b7 RH |
2281 | fregno++; |
2282 | off += 8; | |
4697a36c | 2283 | } |
4cc833b7 RH |
2284 | |
2285 | emit_label (lab); | |
4697a36c | 2286 | } |
4697a36c | 2287 | } |
4697a36c | 2288 | |
dfafc897 | 2289 | /* Create the va_list data type. */ |
2c4974b7 | 2290 | |
dfafc897 FS |
2291 | tree |
2292 | rs6000_build_va_list () | |
2293 | { | |
bab45a51 | 2294 | tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl; |
4697a36c | 2295 | |
9ebbca7d GK |
2296 | /* For AIX, prefer 'char *' because that's what the system |
2297 | header files like. */ | |
dfafc897 | 2298 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
9ebbca7d | 2299 | return build_pointer_type (char_type_node); |
dfafc897 | 2300 | |
0f4fd75d | 2301 | record = make_lang_type (RECORD_TYPE); |
bab45a51 | 2302 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 2303 | |
9ebbca7d GK |
2304 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
2305 | unsigned_char_type_node); | |
2306 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), | |
2307 | unsigned_char_type_node); | |
dfafc897 FS |
2308 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
2309 | ptr_type_node); | |
2310 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
2311 | ptr_type_node); | |
2312 | ||
2313 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
2314 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
2315 | DECL_FIELD_CONTEXT (f_ovf) = record; | |
2316 | DECL_FIELD_CONTEXT (f_sav) = record; | |
2317 | ||
bab45a51 FS |
2318 | TREE_CHAIN (record) = type_decl; |
2319 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
2320 | TYPE_FIELDS (record) = f_gpr; |
2321 | TREE_CHAIN (f_gpr) = f_fpr; | |
2322 | TREE_CHAIN (f_fpr) = f_ovf; | |
2323 | TREE_CHAIN (f_ovf) = f_sav; | |
2324 | ||
2325 | layout_type (record); | |
2326 | ||
2327 | /* The correct type is an array type of one element. */ | |
2328 | return build_array_type (record, build_index_type (size_zero_node)); | |
2329 | } | |
2330 | ||
2331 | /* Implement va_start. */ | |
2332 | ||
2333 | void | |
2334 | rs6000_va_start (stdarg_p, valist, nextarg) | |
2335 | int stdarg_p; | |
2336 | tree valist; | |
2337 | rtx nextarg; | |
4697a36c | 2338 | { |
dfafc897 FS |
2339 | HOST_WIDE_INT words, n_gpr, n_fpr; |
2340 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
2341 | tree gpr, fpr, ovf, sav, t; | |
2c4974b7 | 2342 | |
dfafc897 | 2343 | /* Only SVR4 needs something special. */ |
2c4974b7 | 2344 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
dfafc897 FS |
2345 | { |
2346 | std_expand_builtin_va_start (stdarg_p, valist, nextarg); | |
2347 | return; | |
2348 | } | |
2349 | ||
973a648b | 2350 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 FS |
2351 | f_fpr = TREE_CHAIN (f_gpr); |
2352 | f_ovf = TREE_CHAIN (f_fpr); | |
2353 | f_sav = TREE_CHAIN (f_ovf); | |
2354 | ||
8ebecc3b | 2355 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
2356 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
2357 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
2358 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
2359 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
2360 | ||
2361 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 2362 | words = current_function_args_info.words; |
dfafc897 FS |
2363 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
2364 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
2365 | ||
2366 | if (TARGET_DEBUG_ARG) | |
2367 | fprintf (stderr, "va_start: words = %d, n_gpr = %d, n_fpr = %d\n", | |
2368 | words, n_gpr, n_fpr); | |
2369 | ||
2370 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
2371 | TREE_SIDE_EFFECTS (t) = 1; | |
2372 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2373 | ||
2374 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
2375 | TREE_SIDE_EFFECTS (t) = 1; | |
2376 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2377 | ||
2378 | /* Find the overflow area. */ | |
2379 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
2380 | if (words != 0) | |
2381 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
2382 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
2383 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
2384 | TREE_SIDE_EFFECTS (t) = 1; | |
2385 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2386 | ||
2387 | /* Find the register save area. */ | |
2388 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
2389 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
2390 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
2391 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
2392 | TREE_SIDE_EFFECTS (t) = 1; | |
2393 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2394 | } | |
2395 | ||
2396 | /* Implement va_arg. */ | |
2397 | ||
2398 | rtx | |
2399 | rs6000_va_arg (valist, type) | |
2400 | tree valist, type; | |
2401 | { | |
2402 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
2403 | tree gpr, fpr, ovf, sav, reg, t, u; | |
2404 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
2405 | rtx lab_false, lab_over, addr_rtx, r; | |
2406 | ||
9ebbca7d GK |
2407 | /* For AIX, the rule is that structures are passed left-aligned in |
2408 | their stack slot. However, GCC does not presently do this: | |
2409 | structures which are the same size as integer types are passed | |
2410 | right-aligned, as if they were in fact integers. This only | |
2411 | matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */ | |
dfafc897 | 2412 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
9ebbca7d GK |
2413 | { |
2414 | HOST_WIDE_INT align, rounded_size; | |
2415 | enum machine_mode mode; | |
2416 | tree addr_tree; | |
2417 | ||
2418 | /* Compute the rounded size of the type. */ | |
2419 | align = PARM_BOUNDARY / BITS_PER_UNIT; | |
2420 | rounded_size = (((int_size_in_bytes (type) + align - 1) / align) | |
2421 | * align); | |
2422 | ||
2423 | addr_tree = valist; | |
2424 | ||
2425 | mode = TYPE_MODE (type); | |
2426 | if (mode != BLKmode) | |
2427 | { | |
2428 | HOST_WIDE_INT adj; | |
2429 | adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT; | |
2430 | if (rounded_size > align) | |
2431 | adj = rounded_size; | |
2432 | ||
2433 | addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree, | |
2434 | build_int_2 (rounded_size - adj, 0)); | |
2435 | } | |
2436 | ||
2437 | addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL); | |
2438 | addr_rtx = copy_to_reg (addr_rtx); | |
2439 | ||
2440 | /* Compute new value for AP. */ | |
2441 | t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, | |
2442 | build (PLUS_EXPR, TREE_TYPE (valist), valist, | |
2443 | build_int_2 (rounded_size, 0))); | |
2444 | TREE_SIDE_EFFECTS (t) = 1; | |
2445 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2446 | ||
2447 | return addr_rtx; | |
2448 | } | |
dfafc897 | 2449 | |
973a648b | 2450 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 FS |
2451 | f_fpr = TREE_CHAIN (f_gpr); |
2452 | f_ovf = TREE_CHAIN (f_fpr); | |
2453 | f_sav = TREE_CHAIN (f_ovf); | |
2454 | ||
8ebecc3b | 2455 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
2456 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
2457 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
2458 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
2459 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
2460 | ||
2461 | size = int_size_in_bytes (type); | |
2462 | rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
4cc833b7 | 2463 | |
dfafc897 | 2464 | if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode) |
4cc833b7 | 2465 | { |
dfafc897 FS |
2466 | /* Aggregates and long doubles are passed by reference. */ |
2467 | indirect_p = 1; | |
2468 | reg = gpr; | |
2469 | n_reg = 1; | |
2470 | sav_ofs = 0; | |
2471 | sav_scale = 4; | |
2472 | size = rsize = UNITS_PER_WORD; | |
2473 | } | |
2474 | else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT) | |
2475 | { | |
2476 | /* FP args go in FP registers, if present. */ | |
2477 | indirect_p = 0; | |
2478 | reg = fpr; | |
2479 | n_reg = 1; | |
2480 | sav_ofs = 8*4; | |
2481 | sav_scale = 8; | |
4cc833b7 | 2482 | } |
dfafc897 FS |
2483 | else |
2484 | { | |
2485 | /* Otherwise into GP registers. */ | |
2486 | indirect_p = 0; | |
2487 | reg = gpr; | |
2488 | n_reg = rsize; | |
2489 | sav_ofs = 0; | |
2490 | sav_scale = 4; | |
2491 | } | |
2492 | ||
2493 | /* | |
2494 | * Pull the value out of the saved registers ... | |
2495 | */ | |
2496 | ||
2497 | lab_false = gen_label_rtx (); | |
2498 | lab_over = gen_label_rtx (); | |
2499 | addr_rtx = gen_reg_rtx (Pmode); | |
2500 | ||
2501 | emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL), | |
2502 | GEN_INT (8 - n_reg + 1), | |
2503 | GE, const1_rtx, QImode, 1, 1, lab_false); | |
2c4974b7 | 2504 | |
dfafc897 FS |
2505 | /* Long long is aligned in the registers. */ |
2506 | if (n_reg > 1) | |
2c4974b7 | 2507 | { |
dfafc897 FS |
2508 | u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg, |
2509 | build_int_2 (n_reg - 1, 0)); | |
2510 | u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u); | |
2511 | u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u); | |
2512 | TREE_SIDE_EFFECTS (u) = 1; | |
2513 | expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2c4974b7 | 2514 | } |
dfafc897 FS |
2515 | |
2516 | if (sav_ofs) | |
2517 | t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
2c4974b7 | 2518 | else |
dfafc897 | 2519 | t = sav; |
2c4974b7 | 2520 | |
dfafc897 FS |
2521 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0)); |
2522 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 2523 | |
dfafc897 FS |
2524 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
2525 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 2526 | |
dfafc897 FS |
2527 | u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); |
2528 | TREE_SIDE_EFFECTS (u) = 1; | |
2529 | ||
2530 | t = build (PLUS_EXPR, ptr_type_node, t, u); | |
2531 | TREE_SIDE_EFFECTS (t) = 1; | |
2532 | ||
2533 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
2534 | if (r != addr_rtx) | |
2535 | emit_move_insn (addr_rtx, r); | |
2536 | ||
2537 | emit_jump_insn (gen_jump (lab_over)); | |
2538 | emit_barrier (); | |
2539 | emit_label (lab_false); | |
2540 | ||
2541 | /* | |
2542 | * ... otherwise out of the overflow area. | |
2543 | */ | |
2544 | ||
2545 | /* Make sure we don't find reg 7 for the next int arg. */ | |
2546 | if (n_reg > 1) | |
2547 | { | |
2548 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
2549 | TREE_SIDE_EFFECTS (t) = 1; | |
2550 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2551 | } | |
2552 | ||
2553 | /* Care for on-stack alignment if needed. */ | |
2554 | if (rsize <= 1) | |
2555 | t = ovf; | |
2556 | else | |
2557 | { | |
2558 | t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0)); | |
2559 | t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1)); | |
2560 | } | |
2561 | t = save_expr (t); | |
2562 | ||
2563 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
2564 | if (r != addr_rtx) | |
2565 | emit_move_insn (addr_rtx, r); | |
2566 | ||
2567 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
2568 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
2569 | TREE_SIDE_EFFECTS (t) = 1; | |
2570 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2571 | ||
2572 | emit_label (lab_over); | |
2573 | ||
2574 | if (indirect_p) | |
2575 | { | |
2576 | r = gen_rtx_MEM (Pmode, addr_rtx); | |
2577 | MEM_ALIAS_SET (r) = get_varargs_alias_set (); | |
2578 | emit_move_insn (addr_rtx, r); | |
2579 | } | |
2580 | ||
2581 | return addr_rtx; | |
4697a36c | 2582 | } |
5b5040b9 RK |
2583 | \f |
2584 | /* Generate a memory reference for expand_block_move, copying volatile, | |
2585 | and other bits from an original memory reference. */ | |
2586 | ||
2587 | static rtx | |
2588 | expand_block_move_mem (mode, addr, orig_mem) | |
2589 | enum machine_mode mode; | |
2590 | rtx addr; | |
2591 | rtx orig_mem; | |
2592 | { | |
39403d82 | 2593 | rtx mem = gen_rtx_MEM (mode, addr); |
b6c9286a | 2594 | |
c6df88cb | 2595 | MEM_COPY_ATTRIBUTES (mem, orig_mem); |
b6c9286a MM |
2596 | #ifdef MEM_UNALIGNED_P |
2597 | MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem); | |
2598 | #endif | |
5b5040b9 RK |
2599 | return mem; |
2600 | } | |
2601 | ||
7e69e155 MM |
2602 | /* Expand a block move operation, and return 1 if successful. Return 0 |
2603 | if we should let the compiler generate normal code. | |
2604 | ||
2605 | operands[0] is the destination | |
2606 | operands[1] is the source | |
2607 | operands[2] is the length | |
2608 | operands[3] is the alignment */ | |
2609 | ||
3933e0e1 MM |
2610 | #define MAX_MOVE_REG 4 |
2611 | ||
7e69e155 MM |
2612 | int |
2613 | expand_block_move (operands) | |
2614 | rtx operands[]; | |
2615 | { | |
b6c9286a MM |
2616 | rtx orig_dest = operands[0]; |
2617 | rtx orig_src = operands[1]; | |
7e69e155 | 2618 | rtx bytes_rtx = operands[2]; |
7e69e155 | 2619 | rtx align_rtx = operands[3]; |
3933e0e1 | 2620 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 2621 | int align; |
3933e0e1 MM |
2622 | int bytes; |
2623 | int offset; | |
2624 | int num_reg; | |
2625 | int i; | |
7e69e155 MM |
2626 | rtx src_reg; |
2627 | rtx dest_reg; | |
3933e0e1 MM |
2628 | rtx src_addr; |
2629 | rtx dest_addr; | |
7e69e155 | 2630 | rtx tmp_reg; |
3933e0e1 | 2631 | rtx stores[MAX_MOVE_REG]; |
7e69e155 MM |
2632 | int move_bytes; |
2633 | ||
3933e0e1 | 2634 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 2635 | if (! constp) |
3933e0e1 MM |
2636 | return 0; |
2637 | ||
5ee95df6 FS |
2638 | /* If this is not a fixed size alignment, abort */ |
2639 | if (GET_CODE (align_rtx) != CONST_INT) | |
2640 | abort (); | |
2641 | align = INTVAL (align_rtx); | |
2642 | ||
7e69e155 | 2643 | /* Anything to move? */ |
3933e0e1 MM |
2644 | bytes = INTVAL (bytes_rtx); |
2645 | if (bytes <= 0) | |
7e69e155 MM |
2646 | return 1; |
2647 | ||
3933e0e1 MM |
2648 | /* Don't support real large moves. If string instructions are not used, |
2649 | then don't generate more than 8 loads. */ | |
2650 | if (TARGET_STRING) | |
2651 | { | |
c81fc13e | 2652 | if (bytes > 8*4) |
3933e0e1 MM |
2653 | return 0; |
2654 | } | |
cc0d9ba8 | 2655 | else if (! STRICT_ALIGNMENT) |
3933e0e1 | 2656 | { |
c81fc13e DE |
2657 | if (TARGET_POWERPC64 && align >= 4) |
2658 | { | |
2659 | if (bytes > 8*8) | |
2660 | return 0; | |
2661 | } | |
2662 | else | |
2663 | if (bytes > 8*4) | |
2664 | return 0; | |
3933e0e1 MM |
2665 | } |
2666 | else if (bytes > 8*align) | |
7e69e155 MM |
2667 | return 0; |
2668 | ||
2669 | /* Move the address into scratch registers. */ | |
b6c9286a MM |
2670 | dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0)); |
2671 | src_reg = copy_addr_to_reg (XEXP (orig_src, 0)); | |
7e69e155 | 2672 | |
3933e0e1 | 2673 | if (TARGET_STRING) /* string instructions are available */ |
7e69e155 | 2674 | { |
3933e0e1 | 2675 | for ( ; bytes > 0; bytes -= move_bytes) |
7e69e155 | 2676 | { |
3933e0e1 | 2677 | if (bytes > 24 /* move up to 32 bytes at a time */ |
cc0d9ba8 DE |
2678 | && ! fixed_regs[5] |
2679 | && ! fixed_regs[6] | |
2680 | && ! fixed_regs[7] | |
2681 | && ! fixed_regs[8] | |
2682 | && ! fixed_regs[9] | |
2683 | && ! fixed_regs[10] | |
2684 | && ! fixed_regs[11] | |
2685 | && ! fixed_regs[12]) | |
3933e0e1 MM |
2686 | { |
2687 | move_bytes = (bytes > 32) ? 32 : bytes; | |
cc0d9ba8 DE |
2688 | emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, |
2689 | dest_reg, | |
2690 | orig_dest), | |
2691 | expand_block_move_mem (BLKmode, | |
2692 | src_reg, | |
2693 | orig_src), | |
2694 | GEN_INT ((move_bytes == 32) | |
2695 | ? 0 : move_bytes), | |
4c64a852 | 2696 | align_rtx)); |
3933e0e1 MM |
2697 | } |
2698 | else if (bytes > 16 /* move up to 24 bytes at a time */ | |
f9562f27 DE |
2699 | && ! fixed_regs[5] |
2700 | && ! fixed_regs[6] | |
cc0d9ba8 DE |
2701 | && ! fixed_regs[7] |
2702 | && ! fixed_regs[8] | |
2703 | && ! fixed_regs[9] | |
f9562f27 | 2704 | && ! fixed_regs[10]) |
3933e0e1 MM |
2705 | { |
2706 | move_bytes = (bytes > 24) ? 24 : bytes; | |
cc0d9ba8 DE |
2707 | emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, |
2708 | dest_reg, | |
2709 | orig_dest), | |
2710 | expand_block_move_mem (BLKmode, | |
2711 | src_reg, | |
2712 | orig_src), | |
3933e0e1 | 2713 | GEN_INT (move_bytes), |
4c64a852 | 2714 | align_rtx)); |
3933e0e1 MM |
2715 | } |
2716 | else if (bytes > 8 /* move up to 16 bytes at a time */ | |
f9562f27 DE |
2717 | && ! fixed_regs[5] |
2718 | && ! fixed_regs[6] | |
2719 | && ! fixed_regs[7] | |
2720 | && ! fixed_regs[8]) | |
3933e0e1 MM |
2721 | { |
2722 | move_bytes = (bytes > 16) ? 16 : bytes; | |
cc0d9ba8 DE |
2723 | emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, |
2724 | dest_reg, | |
2725 | orig_dest), | |
2726 | expand_block_move_mem (BLKmode, | |
2727 | src_reg, | |
2728 | orig_src), | |
3933e0e1 | 2729 | GEN_INT (move_bytes), |
4c64a852 | 2730 | align_rtx)); |
3933e0e1 | 2731 | } |
acad7ed3 DE |
2732 | else if (bytes >= 8 && TARGET_POWERPC64 |
2733 | /* 64-bit loads and stores require word-aligned displacements. */ | |
2734 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) | |
2735 | { | |
2736 | move_bytes = 8; | |
2737 | tmp_reg = gen_reg_rtx (DImode); | |
2738 | emit_move_insn (tmp_reg, | |
2739 | expand_block_move_mem (DImode, | |
2eba1afa | 2740 | src_reg, orig_src)); |
acad7ed3 | 2741 | emit_move_insn (expand_block_move_mem (DImode, |
2eba1afa | 2742 | dest_reg, orig_dest), |
acad7ed3 DE |
2743 | tmp_reg); |
2744 | } | |
2745 | else if (bytes > 4) | |
3933e0e1 MM |
2746 | { /* move up to 8 bytes at a time */ |
2747 | move_bytes = (bytes > 8) ? 8 : bytes; | |
cc0d9ba8 DE |
2748 | emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, |
2749 | dest_reg, | |
2750 | orig_dest), | |
2751 | expand_block_move_mem (BLKmode, | |
2752 | src_reg, | |
2753 | orig_src), | |
3933e0e1 | 2754 | GEN_INT (move_bytes), |
4c64a852 | 2755 | align_rtx)); |
3933e0e1 | 2756 | } |
cc0d9ba8 | 2757 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
2758 | { /* move 4 bytes */ |
2759 | move_bytes = 4; | |
2760 | tmp_reg = gen_reg_rtx (SImode); | |
cc0d9ba8 DE |
2761 | emit_move_insn (tmp_reg, |
2762 | expand_block_move_mem (SImode, | |
2763 | src_reg, orig_src)); | |
2764 | emit_move_insn (expand_block_move_mem (SImode, | |
2765 | dest_reg, orig_dest), | |
2766 | tmp_reg); | |
3933e0e1 | 2767 | } |
cc0d9ba8 | 2768 | else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
2769 | { /* move 2 bytes */ |
2770 | move_bytes = 2; | |
2771 | tmp_reg = gen_reg_rtx (HImode); | |
cc0d9ba8 DE |
2772 | emit_move_insn (tmp_reg, |
2773 | expand_block_move_mem (HImode, | |
2774 | src_reg, orig_src)); | |
2775 | emit_move_insn (expand_block_move_mem (HImode, | |
2776 | dest_reg, orig_dest), | |
2777 | tmp_reg); | |
3933e0e1 MM |
2778 | } |
2779 | else if (bytes == 1) /* move 1 byte */ | |
2780 | { | |
2781 | move_bytes = 1; | |
2782 | tmp_reg = gen_reg_rtx (QImode); | |
cc0d9ba8 DE |
2783 | emit_move_insn (tmp_reg, |
2784 | expand_block_move_mem (QImode, | |
2785 | src_reg, orig_src)); | |
2786 | emit_move_insn (expand_block_move_mem (QImode, | |
2787 | dest_reg, orig_dest), | |
2788 | tmp_reg); | |
3933e0e1 MM |
2789 | } |
2790 | else | |
2791 | { /* move up to 4 bytes at a time */ | |
2792 | move_bytes = (bytes > 4) ? 4 : bytes; | |
cc0d9ba8 DE |
2793 | emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, |
2794 | dest_reg, | |
2795 | orig_dest), | |
2796 | expand_block_move_mem (BLKmode, | |
2797 | src_reg, | |
2798 | orig_src), | |
3933e0e1 | 2799 | GEN_INT (move_bytes), |
4c64a852 | 2800 | align_rtx)); |
3933e0e1 | 2801 | } |
4c64a852 | 2802 | |
015892ee RK |
2803 | if (bytes > move_bytes) |
2804 | { | |
cc0d9ba8 DE |
2805 | if (! TARGET_POWERPC64) |
2806 | { | |
2807 | emit_insn (gen_addsi3 (src_reg, src_reg, | |
2808 | GEN_INT (move_bytes))); | |
2809 | emit_insn (gen_addsi3 (dest_reg, dest_reg, | |
2810 | GEN_INT (move_bytes))); | |
2811 | } | |
2812 | else | |
2813 | { | |
2814 | emit_insn (gen_adddi3 (src_reg, src_reg, | |
2815 | GEN_INT (move_bytes))); | |
2816 | emit_insn (gen_adddi3 (dest_reg, dest_reg, | |
2817 | GEN_INT (move_bytes))); | |
2818 | } | |
015892ee | 2819 | } |
4c64a852 | 2820 | } |
3933e0e1 MM |
2821 | } |
2822 | ||
2823 | else /* string instructions not available */ | |
2824 | { | |
2825 | num_reg = offset = 0; | |
2826 | for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes)) | |
7e69e155 | 2827 | { |
3933e0e1 MM |
2828 | /* Calculate the correct offset for src/dest */ |
2829 | if (offset == 0) | |
7e69e155 | 2830 | { |
3933e0e1 MM |
2831 | src_addr = src_reg; |
2832 | dest_addr = dest_reg; | |
2833 | } | |
2834 | else | |
2835 | { | |
c5c76735 JL |
2836 | src_addr = plus_constant (src_reg, offset); |
2837 | dest_addr = plus_constant (dest_reg, offset); | |
3933e0e1 MM |
2838 | } |
2839 | ||
cc0d9ba8 DE |
2840 | /* Generate the appropriate load and store, saving the stores |
2841 | for later. */ | |
2842 | if (bytes >= 8 && TARGET_POWERPC64 | |
2843 | /* 64-bit loads and stores require word-aligned displacements. */ | |
2844 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) | |
b6c9286a MM |
2845 | { |
2846 | move_bytes = 8; | |
2847 | tmp_reg = gen_reg_rtx (DImode); | |
cc0d9ba8 DE |
2848 | emit_insn (gen_movdi (tmp_reg, |
2849 | expand_block_move_mem (DImode, | |
2850 | src_addr, | |
2851 | orig_src))); | |
2852 | stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode, | |
2853 | dest_addr, | |
2854 | orig_dest), | |
2855 | tmp_reg); | |
b6c9286a | 2856 | } |
cc0d9ba8 | 2857 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
2858 | { |
2859 | move_bytes = 4; | |
2860 | tmp_reg = gen_reg_rtx (SImode); | |
cc0d9ba8 DE |
2861 | emit_insn (gen_movsi (tmp_reg, |
2862 | expand_block_move_mem (SImode, | |
2863 | src_addr, | |
2864 | orig_src))); | |
2865 | stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode, | |
2866 | dest_addr, | |
2867 | orig_dest), | |
2868 | tmp_reg); | |
3933e0e1 | 2869 | } |
cc0d9ba8 | 2870 | else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
2871 | { |
2872 | move_bytes = 2; | |
2873 | tmp_reg = gen_reg_rtx (HImode); | |
c81fc13e | 2874 | emit_insn (gen_movhi (tmp_reg, |
cc0d9ba8 DE |
2875 | expand_block_move_mem (HImode, |
2876 | src_addr, | |
2877 | orig_src))); | |
2878 | stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode, | |
2879 | dest_addr, | |
2880 | orig_dest), | |
2881 | tmp_reg); | |
3933e0e1 MM |
2882 | } |
2883 | else | |
2884 | { | |
2885 | move_bytes = 1; | |
2886 | tmp_reg = gen_reg_rtx (QImode); | |
c81fc13e | 2887 | emit_insn (gen_movqi (tmp_reg, |
cc0d9ba8 DE |
2888 | expand_block_move_mem (QImode, |
2889 | src_addr, | |
2890 | orig_src))); | |
2891 | stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode, | |
2892 | dest_addr, | |
2893 | orig_dest), | |
2894 | tmp_reg); | |
3933e0e1 MM |
2895 | } |
2896 | ||
2897 | if (num_reg >= MAX_MOVE_REG) | |
2898 | { | |
2899 | for (i = 0; i < num_reg; i++) | |
2900 | emit_insn (stores[i]); | |
2901 | num_reg = 0; | |
7e69e155 MM |
2902 | } |
2903 | } | |
3933e0e1 | 2904 | |
b6c9286a MM |
2905 | for (i = 0; i < num_reg; i++) |
2906 | emit_insn (stores[i]); | |
7e69e155 MM |
2907 | } |
2908 | ||
2909 | return 1; | |
2910 | } | |
2911 | ||
9878760c RK |
2912 | \f |
2913 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
2914 | PARALLEL and the first section will be tested. */ | |
2915 | ||
2916 | int | |
2917 | load_multiple_operation (op, mode) | |
2918 | rtx op; | |
296b8152 | 2919 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
2920 | { |
2921 | int count = XVECLEN (op, 0); | |
e2c953b6 | 2922 | unsigned int dest_regno; |
9878760c RK |
2923 | rtx src_addr; |
2924 | int i; | |
2925 | ||
2926 | /* Perform a quick check so we don't blow up below. */ | |
2927 | if (count <= 1 | |
2928 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
2929 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
2930 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
2931 | return 0; | |
2932 | ||
2933 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
2934 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
2935 | ||
2936 | for (i = 1; i < count; i++) | |
2937 | { | |
2938 | rtx elt = XVECEXP (op, 0, i); | |
2939 | ||
2940 | if (GET_CODE (elt) != SET | |
2941 | || GET_CODE (SET_DEST (elt)) != REG | |
2942 | || GET_MODE (SET_DEST (elt)) != SImode | |
2943 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
2944 | || GET_CODE (SET_SRC (elt)) != MEM | |
2945 | || GET_MODE (SET_SRC (elt)) != SImode | |
2946 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
2947 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
2948 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
2949 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
2950 | return 0; | |
2951 | } | |
2952 | ||
2953 | return 1; | |
2954 | } | |
2955 | ||
2956 | /* Similar, but tests for store multiple. Here, the second vector element | |
2957 | is a CLOBBER. It will be tested later. */ | |
2958 | ||
2959 | int | |
2960 | store_multiple_operation (op, mode) | |
2961 | rtx op; | |
296b8152 | 2962 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
2963 | { |
2964 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 2965 | unsigned int src_regno; |
9878760c RK |
2966 | rtx dest_addr; |
2967 | int i; | |
2968 | ||
2969 | /* Perform a quick check so we don't blow up below. */ | |
2970 | if (count <= 1 | |
2971 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
2972 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
2973 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
2974 | return 0; | |
2975 | ||
2976 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
2977 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
2978 | ||
2979 | for (i = 1; i < count; i++) | |
2980 | { | |
2981 | rtx elt = XVECEXP (op, 0, i + 1); | |
2982 | ||
2983 | if (GET_CODE (elt) != SET | |
2984 | || GET_CODE (SET_SRC (elt)) != REG | |
2985 | || GET_MODE (SET_SRC (elt)) != SImode | |
2986 | || REGNO (SET_SRC (elt)) != src_regno + i | |
2987 | || GET_CODE (SET_DEST (elt)) != MEM | |
2988 | || GET_MODE (SET_DEST (elt)) != SImode | |
2989 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
2990 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
2991 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
2992 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
2993 | return 0; | |
2994 | } | |
2995 | ||
2996 | return 1; | |
2997 | } | |
9ebbca7d GK |
2998 | |
2999 | /* Return 1 for an PARALLEL suitable for mtcrf. */ | |
3000 | ||
3001 | int | |
3002 | mtcrf_operation (op, mode) | |
3003 | rtx op; | |
3004 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3005 | { | |
3006 | int count = XVECLEN (op, 0); | |
3007 | int i; | |
9ebbca7d GK |
3008 | rtx src_reg; |
3009 | ||
3010 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
3011 | if (count < 1 |
3012 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
3013 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
3014 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 3015 | return 0; |
e35b9579 | 3016 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
9ebbca7d GK |
3017 | |
3018 | if (GET_CODE (src_reg) != REG | |
3019 | || GET_MODE (src_reg) != SImode | |
3020 | || ! INT_REGNO_P (REGNO (src_reg))) | |
3021 | return 0; | |
3022 | ||
e35b9579 | 3023 | for (i = 0; i < count; i++) |
9ebbca7d GK |
3024 | { |
3025 | rtx exp = XVECEXP (op, 0, i); | |
3026 | rtx unspec; | |
3027 | int maskval; | |
3028 | ||
3029 | if (GET_CODE (exp) != SET | |
3030 | || GET_CODE (SET_DEST (exp)) != REG | |
3031 | || GET_MODE (SET_DEST (exp)) != CCmode | |
3032 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
3033 | return 0; | |
3034 | unspec = SET_SRC (exp); | |
3035 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
9ebbca7d GK |
3036 | |
3037 | if (GET_CODE (unspec) != UNSPEC | |
3038 | || XINT (unspec, 1) != 20 | |
3039 | || XVECLEN (unspec, 0) != 2 | |
3040 | || XVECEXP (unspec, 0, 0) != src_reg | |
3041 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
3042 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
3043 | return 0; | |
3044 | } | |
e35b9579 | 3045 | return 1; |
9ebbca7d GK |
3046 | } |
3047 | ||
3048 | /* Return 1 for an PARALLEL suitable for lmw. */ | |
3049 | ||
3050 | int | |
3051 | lmw_operation (op, mode) | |
3052 | rtx op; | |
3053 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3054 | { | |
3055 | int count = XVECLEN (op, 0); | |
e2c953b6 | 3056 | unsigned int dest_regno; |
9ebbca7d | 3057 | rtx src_addr; |
e2c953b6 | 3058 | unsigned int base_regno; |
9ebbca7d GK |
3059 | HOST_WIDE_INT offset; |
3060 | int i; | |
3061 | ||
3062 | /* Perform a quick check so we don't blow up below. */ | |
3063 | if (count <= 1 | |
3064 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
3065 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
3066 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
3067 | return 0; | |
3068 | ||
3069 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
3070 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
3071 | ||
3072 | if (dest_regno > 31 | |
e2c953b6 | 3073 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
3074 | return 0; |
3075 | ||
3076 | if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr)) | |
3077 | { | |
3078 | offset = 0; | |
3079 | base_regno = REGNO (src_addr); | |
3080 | if (base_regno == 0) | |
3081 | return 0; | |
3082 | } | |
3083 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr)) | |
3084 | { | |
3085 | offset = INTVAL (XEXP (src_addr, 1)); | |
3086 | base_regno = REGNO (XEXP (src_addr, 0)); | |
3087 | } | |
3088 | else | |
3089 | return 0; | |
3090 | ||
3091 | for (i = 0; i < count; i++) | |
3092 | { | |
3093 | rtx elt = XVECEXP (op, 0, i); | |
3094 | rtx newaddr; | |
3095 | rtx addr_reg; | |
3096 | HOST_WIDE_INT newoffset; | |
3097 | ||
3098 | if (GET_CODE (elt) != SET | |
3099 | || GET_CODE (SET_DEST (elt)) != REG | |
3100 | || GET_MODE (SET_DEST (elt)) != SImode | |
3101 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
3102 | || GET_CODE (SET_SRC (elt)) != MEM | |
3103 | || GET_MODE (SET_SRC (elt)) != SImode) | |
3104 | return 0; | |
3105 | newaddr = XEXP (SET_SRC (elt), 0); | |
3106 | if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr)) | |
3107 | { | |
3108 | newoffset = 0; | |
3109 | addr_reg = newaddr; | |
3110 | } | |
3111 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr)) | |
3112 | { | |
3113 | addr_reg = XEXP (newaddr, 0); | |
3114 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
3115 | } | |
3116 | else | |
3117 | return 0; | |
3118 | if (REGNO (addr_reg) != base_regno | |
3119 | || newoffset != offset + 4 * i) | |
3120 | return 0; | |
3121 | } | |
3122 | ||
3123 | return 1; | |
3124 | } | |
3125 | ||
3126 | /* Return 1 for an PARALLEL suitable for stmw. */ | |
3127 | ||
3128 | int | |
3129 | stmw_operation (op, mode) | |
3130 | rtx op; | |
3131 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3132 | { | |
3133 | int count = XVECLEN (op, 0); | |
e2c953b6 | 3134 | unsigned int src_regno; |
9ebbca7d | 3135 | rtx dest_addr; |
e2c953b6 | 3136 | unsigned int base_regno; |
9ebbca7d GK |
3137 | HOST_WIDE_INT offset; |
3138 | int i; | |
3139 | ||
3140 | /* Perform a quick check so we don't blow up below. */ | |
3141 | if (count <= 1 | |
3142 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
3143 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
3144 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
3145 | return 0; | |
3146 | ||
3147 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
3148 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
3149 | ||
3150 | if (src_regno > 31 | |
e2c953b6 | 3151 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
3152 | return 0; |
3153 | ||
3154 | if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr)) | |
3155 | { | |
3156 | offset = 0; | |
3157 | base_regno = REGNO (dest_addr); | |
3158 | if (base_regno == 0) | |
3159 | return 0; | |
3160 | } | |
3161 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr)) | |
3162 | { | |
3163 | offset = INTVAL (XEXP (dest_addr, 1)); | |
3164 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
3165 | } | |
3166 | else | |
3167 | return 0; | |
3168 | ||
3169 | for (i = 0; i < count; i++) | |
3170 | { | |
3171 | rtx elt = XVECEXP (op, 0, i); | |
3172 | rtx newaddr; | |
3173 | rtx addr_reg; | |
3174 | HOST_WIDE_INT newoffset; | |
3175 | ||
3176 | if (GET_CODE (elt) != SET | |
3177 | || GET_CODE (SET_SRC (elt)) != REG | |
3178 | || GET_MODE (SET_SRC (elt)) != SImode | |
3179 | || REGNO (SET_SRC (elt)) != src_regno + i | |
3180 | || GET_CODE (SET_DEST (elt)) != MEM | |
3181 | || GET_MODE (SET_DEST (elt)) != SImode) | |
3182 | return 0; | |
3183 | newaddr = XEXP (SET_DEST (elt), 0); | |
3184 | if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr)) | |
3185 | { | |
3186 | newoffset = 0; | |
3187 | addr_reg = newaddr; | |
3188 | } | |
3189 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr)) | |
3190 | { | |
3191 | addr_reg = XEXP (newaddr, 0); | |
3192 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
3193 | } | |
3194 | else | |
3195 | return 0; | |
3196 | if (REGNO (addr_reg) != base_regno | |
3197 | || newoffset != offset + 4 * i) | |
3198 | return 0; | |
3199 | } | |
3200 | ||
3201 | return 1; | |
3202 | } | |
9878760c | 3203 | \f |
39a10a29 GK |
3204 | |
3205 | /* A validation routine: say whether CODE, a condition code, | |
3206 | and MODE match. The other alternatives either don't make | |
3207 | sense or should never be generated. */ | |
3208 | static void | |
3209 | validate_condition_mode (code, mode) | |
3210 | enum rtx_code code; | |
3211 | enum machine_mode mode; | |
3212 | { | |
3213 | if (GET_RTX_CLASS (code) != '<' | |
3214 | || GET_MODE_CLASS (mode) != MODE_CC) | |
3215 | abort (); | |
3216 | ||
3217 | /* These don't make sense. */ | |
3218 | if ((code == GT || code == LT || code == GE || code == LE) | |
3219 | && mode == CCUNSmode) | |
3220 | abort (); | |
3221 | ||
3222 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
3223 | && mode != CCUNSmode) | |
3224 | abort (); | |
3225 | ||
3226 | if (mode != CCFPmode | |
3227 | && (code == ORDERED || code == UNORDERED | |
3228 | || code == UNEQ || code == LTGT | |
3229 | || code == UNGT || code == UNLT | |
3230 | || code == UNGE || code == UNLE)) | |
3231 | abort(); | |
3232 | ||
3233 | /* These should never be generated. */ | |
3234 | if (mode == CCFPmode | |
3235 | && (code == LE || code == GE | |
3236 | || code == UNEQ || code == LTGT | |
3237 | || code == UNGT || code == UNLT)) | |
3238 | abort (); | |
3239 | ||
3240 | /* These are invalid; the information is not there. */ | |
3241 | if (mode == CCEQmode | |
3242 | && code != EQ && code != NE) | |
3243 | abort (); | |
3244 | } | |
3245 | ||
9878760c RK |
3246 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
3247 | We only check the opcode against the mode of the CC value here. */ | |
3248 | ||
3249 | int | |
3250 | branch_comparison_operator (op, mode) | |
3251 | register rtx op; | |
296b8152 | 3252 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
3253 | { |
3254 | enum rtx_code code = GET_CODE (op); | |
3255 | enum machine_mode cc_mode; | |
3256 | ||
3257 | if (GET_RTX_CLASS (code) != '<') | |
3258 | return 0; | |
3259 | ||
3260 | cc_mode = GET_MODE (XEXP (op, 0)); | |
3261 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
3262 | return 0; | |
3263 | ||
39a10a29 | 3264 | validate_condition_mode (code, cc_mode); |
9878760c | 3265 | |
39a10a29 GK |
3266 | return 1; |
3267 | } | |
3268 | ||
3269 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
3270 | insn and which is true if the corresponding bit in the CC register | |
3271 | is set. */ | |
3272 | ||
3273 | int | |
3274 | branch_positive_comparison_operator (op, mode) | |
3275 | register rtx op; | |
3276 | enum machine_mode mode; | |
3277 | { | |
3278 | enum rtx_code code; | |
3279 | ||
3280 | if (! branch_comparison_operator (op, mode)) | |
9878760c RK |
3281 | return 0; |
3282 | ||
39a10a29 GK |
3283 | code = GET_CODE (op); |
3284 | return (code == EQ || code == LT || code == GT | |
3285 | || code == LTU || code == GTU | |
3286 | || code == UNORDERED); | |
9878760c RK |
3287 | } |
3288 | ||
39a10a29 | 3289 | |
9878760c RK |
3290 | /* Return 1 if OP is a comparison operation that is valid for an scc insn. |
3291 | We check the opcode against the mode of the CC value and disallow EQ or | |
3292 | NE comparisons for integers. */ | |
3293 | ||
3294 | int | |
3295 | scc_comparison_operator (op, mode) | |
3296 | register rtx op; | |
3297 | enum machine_mode mode; | |
3298 | { | |
3299 | enum rtx_code code = GET_CODE (op); | |
3300 | enum machine_mode cc_mode; | |
3301 | ||
3302 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3303 | return 0; | |
3304 | ||
3305 | if (GET_RTX_CLASS (code) != '<') | |
3306 | return 0; | |
3307 | ||
3308 | cc_mode = GET_MODE (XEXP (op, 0)); | |
3309 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
3310 | return 0; | |
3311 | ||
39a10a29 | 3312 | validate_condition_mode (code, cc_mode); |
9878760c | 3313 | |
39a10a29 | 3314 | if (code == NE && cc_mode != CCFPmode) |
c5defebb RK |
3315 | return 0; |
3316 | ||
9878760c RK |
3317 | return 1; |
3318 | } | |
e0cd0770 JC |
3319 | |
3320 | int | |
3321 | trap_comparison_operator (op, mode) | |
3322 | rtx op; | |
3323 | enum machine_mode mode; | |
3324 | { | |
3325 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
3326 | return 0; | |
39a10a29 | 3327 | return GET_RTX_CLASS (GET_CODE (op)) == '<'; |
e0cd0770 | 3328 | } |
dfbdccdb GK |
3329 | |
3330 | int | |
3331 | boolean_operator (op, mode) | |
3332 | rtx op; | |
3333 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3334 | { | |
3335 | enum rtx_code code = GET_CODE (op); | |
3336 | return (code == AND || code == IOR || code == XOR); | |
3337 | } | |
1d328b19 GK |
3338 | |
3339 | int | |
3340 | boolean_or_operator (op, mode) | |
3341 | rtx op; | |
3342 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3343 | { | |
3344 | enum rtx_code code = GET_CODE (op); | |
3345 | return (code == IOR || code == XOR); | |
3346 | } | |
9878760c RK |
3347 | \f |
3348 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
3349 | mask required to convert the result of a rotate insn into a shift | |
3350 | left insn of SHIFTOP bits. Both are known to be CONST_INT. */ | |
3351 | ||
3352 | int | |
3353 | includes_lshift_p (shiftop, andop) | |
3354 | register rtx shiftop; | |
3355 | register rtx andop; | |
3356 | { | |
e2c953b6 DE |
3357 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
3358 | ||
3359 | shift_mask <<= INTVAL (shiftop); | |
9878760c RK |
3360 | |
3361 | return (INTVAL (andop) & ~shift_mask) == 0; | |
3362 | } | |
3363 | ||
3364 | /* Similar, but for right shift. */ | |
3365 | ||
3366 | int | |
3367 | includes_rshift_p (shiftop, andop) | |
3368 | register rtx shiftop; | |
3369 | register rtx andop; | |
3370 | { | |
a7653a2c | 3371 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
3372 | |
3373 | shift_mask >>= INTVAL (shiftop); | |
3374 | ||
e2c953b6 DE |
3375 | return (INTVAL (andop) & ~shift_mask) == 0; |
3376 | } | |
3377 | ||
3378 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
3379 | mask required to convert the result of a rotate insn into a shift | |
3380 | left insn of SHIFTOP bits. */ | |
3381 | ||
3382 | int | |
3383 | includes_lshift64_p (shiftop, andop) | |
3384 | register rtx shiftop; | |
3385 | register rtx andop; | |
3386 | { | |
3387 | #if HOST_BITS_PER_WIDE_INT == 64 | |
3388 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; | |
3389 | ||
3390 | shift_mask <<= INTVAL (shiftop); | |
3391 | ||
3392 | return (INTVAL (andop) & ~shift_mask) == 0; | |
3393 | #else | |
3394 | unsigned HOST_WIDE_INT shift_mask_low = ~(unsigned HOST_WIDE_INT) 0; | |
3395 | unsigned HOST_WIDE_INT shift_mask_high = ~(unsigned HOST_WIDE_INT) 0; | |
3396 | ||
3397 | shift_mask_low <<= INTVAL (shiftop); | |
3398 | ||
3399 | if (INTVAL (shiftop) > 32) | |
3400 | shift_mask_high <<= (INTVAL (shiftop) - 32); | |
3401 | ||
3402 | if (GET_CODE (andop) == CONST_INT) | |
3403 | return (INTVAL (andop) & ~shift_mask_low) == 0; | |
3404 | else | |
3405 | return ((CONST_DOUBLE_HIGH (andop) & ~shift_mask_high) == 0 | |
3406 | && (CONST_DOUBLE_LOW (andop) & ~shift_mask_low) == 0); | |
3407 | #endif | |
9878760c | 3408 | } |
35068b43 RK |
3409 | |
3410 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates | |
3411 | for lfq and stfq insns. | |
3412 | ||
3413 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
3414 | abort if we are passed pseudo registers. */ | |
3415 | ||
3416 | int | |
3417 | registers_ok_for_quad_peep (reg1, reg2) | |
3418 | rtx reg1, reg2; | |
3419 | { | |
3420 | /* We might have been passed a SUBREG. */ | |
3421 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
3422 | return 0; | |
3423 | ||
3424 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
3425 | } | |
3426 | ||
3427 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and | |
3428 | addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */ | |
3429 | ||
3430 | int | |
3431 | addrs_ok_for_quad_peep (addr1, addr2) | |
3432 | register rtx addr1; | |
3433 | register rtx addr2; | |
3434 | { | |
e2c953b6 | 3435 | unsigned int reg1; |
35068b43 RK |
3436 | int offset1; |
3437 | ||
3438 | /* Extract an offset (if used) from the first addr. */ | |
3439 | if (GET_CODE (addr1) == PLUS) | |
3440 | { | |
3441 | /* If not a REG, return zero. */ | |
3442 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
3443 | return 0; | |
3444 | else | |
3445 | { | |
3446 | reg1 = REGNO (XEXP (addr1, 0)); | |
3447 | /* The offset must be constant! */ | |
3448 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
3449 | return 0; | |
3450 | offset1 = INTVAL (XEXP (addr1, 1)); | |
3451 | } | |
3452 | } | |
3453 | else if (GET_CODE (addr1) != REG) | |
3454 | return 0; | |
3455 | else | |
3456 | { | |
3457 | reg1 = REGNO (addr1); | |
3458 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
3459 | offset1 = 0; | |
3460 | } | |
3461 | ||
acad7ed3 | 3462 | /* Make sure the second address is a (mem (plus (reg) (const_int))). */ |
35068b43 RK |
3463 | if (GET_CODE (addr2) != PLUS) |
3464 | return 0; | |
3465 | ||
3466 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
3467 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
3468 | return 0; | |
3469 | ||
3470 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
3471 | return 0; | |
3472 | ||
3473 | /* The offset for the second addr must be 8 more than the first addr. */ | |
3474 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
3475 | return 0; | |
3476 | ||
3477 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
3478 | instructions. */ | |
3479 | return 1; | |
3480 | } | |
9878760c RK |
3481 | \f |
3482 | /* Return the register class of a scratch register needed to copy IN into | |
3483 | or out of a register in CLASS in MODE. If it can be done directly, | |
3484 | NO_REGS is returned. */ | |
3485 | ||
3486 | enum reg_class | |
3487 | secondary_reload_class (class, mode, in) | |
3488 | enum reg_class class; | |
296b8152 | 3489 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
3490 | rtx in; |
3491 | { | |
5accd822 | 3492 | int regno; |
9878760c | 3493 | |
3cb999d8 | 3494 | #if TARGET_ELF |
1427100a | 3495 | /* We can not copy a symbolic operand directly into anything other than |
e7b7998a JL |
3496 | BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS |
3497 | is needed as an intermediate register. */ | |
3cb999d8 | 3498 | if (class != BASE_REGS |
e7b7998a | 3499 | && (GET_CODE (in) == SYMBOL_REF |
201b6183 | 3500 | || GET_CODE (in) == HIGH |
e7b7998a JL |
3501 | || GET_CODE (in) == LABEL_REF |
3502 | || GET_CODE (in) == CONST)) | |
3503 | return BASE_REGS; | |
3cb999d8 | 3504 | #endif |
e7b7998a | 3505 | |
5accd822 DE |
3506 | if (GET_CODE (in) == REG) |
3507 | { | |
3508 | regno = REGNO (in); | |
3509 | if (regno >= FIRST_PSEUDO_REGISTER) | |
3510 | { | |
3511 | regno = true_regnum (in); | |
3512 | if (regno >= FIRST_PSEUDO_REGISTER) | |
3513 | regno = -1; | |
3514 | } | |
3515 | } | |
3516 | else if (GET_CODE (in) == SUBREG) | |
3517 | { | |
3518 | regno = true_regnum (in); | |
3519 | if (regno >= FIRST_PSEUDO_REGISTER) | |
3520 | regno = -1; | |
3521 | } | |
3522 | else | |
3523 | regno = -1; | |
3524 | ||
9878760c RK |
3525 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
3526 | into anything. */ | |
3527 | if (class == GENERAL_REGS || class == BASE_REGS | |
3528 | || (regno >= 0 && INT_REGNO_P (regno))) | |
3529 | return NO_REGS; | |
3530 | ||
3531 | /* Constants, memory, and FP registers can go into FP registers. */ | |
3532 | if ((regno == -1 || FP_REGNO_P (regno)) | |
3533 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
3534 | return NO_REGS; | |
3535 | ||
3536 | /* We can copy among the CR registers. */ | |
3537 | if ((class == CR_REGS || class == CR0_REGS) | |
3538 | && regno >= 0 && CR_REGNO_P (regno)) | |
3539 | return NO_REGS; | |
3540 | ||
3541 | /* Otherwise, we need GENERAL_REGS. */ | |
3542 | return GENERAL_REGS; | |
3543 | } | |
3544 | \f | |
3545 | /* Given a comparison operation, return the bit number in CCR to test. We | |
3546 | know this is a valid comparison. | |
3547 | ||
3548 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
3549 | used instead of %C, so the bits will be in different places. | |
3550 | ||
b4ac57ab | 3551 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
3552 | |
3553 | int | |
3554 | ccr_bit (op, scc_p) | |
3555 | register rtx op; | |
3556 | int scc_p; | |
3557 | { | |
3558 | enum rtx_code code = GET_CODE (op); | |
3559 | enum machine_mode cc_mode; | |
3560 | int cc_regnum; | |
3561 | int base_bit; | |
9ebbca7d | 3562 | rtx reg; |
9878760c RK |
3563 | |
3564 | if (GET_RTX_CLASS (code) != '<') | |
3565 | return -1; | |
3566 | ||
9ebbca7d GK |
3567 | reg = XEXP (op, 0); |
3568 | ||
3569 | if (GET_CODE (reg) != REG | |
3570 | || ! CR_REGNO_P (REGNO (reg))) | |
3571 | abort (); | |
3572 | ||
3573 | cc_mode = GET_MODE (reg); | |
3574 | cc_regnum = REGNO (reg); | |
3575 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 3576 | |
39a10a29 | 3577 | validate_condition_mode (code, cc_mode); |
c5defebb | 3578 | |
9878760c RK |
3579 | switch (code) |
3580 | { | |
3581 | case NE: | |
3582 | return scc_p ? base_bit + 3 : base_bit + 2; | |
3583 | case EQ: | |
3584 | return base_bit + 2; | |
1c882ea4 | 3585 | case GT: case GTU: case UNLE: |
9878760c | 3586 | return base_bit + 1; |
1c882ea4 | 3587 | case LT: case LTU: case UNGE: |
9878760c | 3588 | return base_bit; |
1c882ea4 GK |
3589 | case ORDERED: case UNORDERED: |
3590 | return base_bit + 3; | |
9878760c RK |
3591 | |
3592 | case GE: case GEU: | |
39a10a29 | 3593 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
3594 | unordered position. So test that bit. For integer, this is ! LT |
3595 | unless this is an scc insn. */ | |
39a10a29 | 3596 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
3597 | |
3598 | case LE: case LEU: | |
39a10a29 | 3599 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 3600 | |
9878760c RK |
3601 | default: |
3602 | abort (); | |
3603 | } | |
3604 | } | |
1ff7789b | 3605 | \f |
8d30c4ee | 3606 | /* Return the GOT register. */ |
1ff7789b MM |
3607 | |
3608 | struct rtx_def * | |
3609 | rs6000_got_register (value) | |
5f59ecb7 | 3610 | rtx value ATTRIBUTE_UNUSED; |
1ff7789b | 3611 | { |
8d30c4ee FS |
3612 | /* The second flow pass currently (June 1999) can't update regs_ever_live |
3613 | without disturbing other parts of the compiler, so update it here to | |
3614 | make the prolog/epilogue code happy. */ | |
3cb999d8 | 3615 | if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) |
8d30c4ee | 3616 | regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1; |
1ff7789b | 3617 | |
8d30c4ee | 3618 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 3619 | |
1ff7789b MM |
3620 | return pic_offset_table_rtx; |
3621 | } | |
a7df97e6 MM |
3622 | \f |
3623 | /* Define the structure for the machine field in struct function. */ | |
3624 | struct machine_function | |
3625 | { | |
3626 | int sysv_varargs_p; | |
a7df97e6 MM |
3627 | }; |
3628 | ||
9ebbca7d | 3629 | /* Functions to save and restore sysv_varargs_p. |
a7df97e6 MM |
3630 | These will be called, via pointer variables, |
3631 | from push_function_context and pop_function_context. */ | |
3632 | ||
3633 | void | |
3634 | rs6000_save_machine_status (p) | |
3635 | struct function *p; | |
3636 | { | |
3637 | struct machine_function *machine = | |
3638 | (struct machine_function *) xmalloc (sizeof (struct machine_function)); | |
3639 | ||
3640 | p->machine = machine; | |
3641 | machine->sysv_varargs_p = rs6000_sysv_varargs_p; | |
a7df97e6 MM |
3642 | } |
3643 | ||
3644 | void | |
3645 | rs6000_restore_machine_status (p) | |
3646 | struct function *p; | |
3647 | { | |
3648 | struct machine_function *machine = p->machine; | |
3649 | ||
3650 | rs6000_sysv_varargs_p = machine->sysv_varargs_p; | |
a7df97e6 MM |
3651 | |
3652 | free (machine); | |
3653 | p->machine = (struct machine_function *)0; | |
3654 | } | |
3655 | ||
3656 | /* Do anything needed before RTL is emitted for each function. */ | |
3657 | ||
3658 | void | |
3659 | rs6000_init_expanders () | |
3660 | { | |
9ebbca7d | 3661 | /* Reset varargs */ |
a7df97e6 | 3662 | rs6000_sysv_varargs_p = 0; |
a7df97e6 MM |
3663 | |
3664 | /* Arrange to save and restore machine status around nested functions. */ | |
3665 | save_machine_status = rs6000_save_machine_status; | |
3666 | restore_machine_status = rs6000_restore_machine_status; | |
3667 | } | |
3668 | ||
9878760c RK |
3669 | \f |
3670 | /* Print an operand. Recognize special options, documented below. */ | |
3671 | ||
38c1f2d7 | 3672 | #if TARGET_ELF |
d9407988 | 3673 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 3674 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
3675 | #else |
3676 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 3677 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
3678 | #endif |
3679 | ||
9878760c RK |
3680 | void |
3681 | print_operand (file, x, code) | |
3682 | FILE *file; | |
3683 | rtx x; | |
9ebbca7d | 3684 | int code; |
9878760c RK |
3685 | { |
3686 | int i; | |
a260abc9 | 3687 | HOST_WIDE_INT val; |
9878760c RK |
3688 | |
3689 | /* These macros test for integers and extract the low-order bits. */ | |
3690 | #define INT_P(X) \ | |
3691 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
3692 | && GET_MODE (X) == VOIDmode) | |
3693 | ||
3694 | #define INT_LOWPART(X) \ | |
3695 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
3696 | ||
3697 | switch (code) | |
3698 | { | |
a8b3aeda | 3699 | case '.': |
a85d226b RK |
3700 | /* Write out an instruction after the call which may be replaced |
3701 | with glue code by the loader. This depends on the AIX version. */ | |
3702 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
3703 | return; |
3704 | ||
c81bebd7 MM |
3705 | case '$': |
3706 | /* Write out either a '.' or '$' for the current location, depending | |
3707 | on whether this is Solaris or not. */ | |
3708 | putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file); | |
3709 | return; | |
3710 | ||
81eace42 GK |
3711 | /* %a is output_address. */ |
3712 | ||
9854d9ed RK |
3713 | case 'A': |
3714 | /* If X is a constant integer whose low-order 5 bits are zero, | |
3715 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 3716 | in the AIX assembler where "sri" with a zero shift count |
9854d9ed RK |
3717 | write a trash instruction. */ |
3718 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) | |
76229ac8 | 3719 | putc ('l', file); |
9854d9ed | 3720 | else |
76229ac8 | 3721 | putc ('r', file); |
9854d9ed RK |
3722 | return; |
3723 | ||
3724 | case 'b': | |
e2c953b6 DE |
3725 | /* If constant, low-order 16 bits of constant, unsigned. |
3726 | Otherwise, write normally. */ | |
3727 | if (INT_P (x)) | |
3728 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
3729 | else | |
3730 | print_operand (file, x, 0); | |
cad12a8d RK |
3731 | return; |
3732 | ||
a260abc9 DE |
3733 | case 'B': |
3734 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
3735 | for 64-bit mask direction. */ | |
296b8152 | 3736 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 3737 | return; |
a260abc9 | 3738 | |
81eace42 GK |
3739 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
3740 | output_operand. */ | |
3741 | ||
9854d9ed | 3742 | case 'D': |
39a10a29 GK |
3743 | /* There used to be a comment for 'C' reading "This is an |
3744 | optional cror needed for certain floating-point | |
3745 | comparisons. Otherwise write nothing." */ | |
3746 | ||
9854d9ed RK |
3747 | /* Similar, except that this is for an scc, so we must be able to |
3748 | encode the test in a single bit that is one. We do the above | |
3749 | for any LE, GE, GEU, or LEU and invert the bit for NE. */ | |
3750 | if (GET_CODE (x) == LE || GET_CODE (x) == GE | |
3751 | || GET_CODE (x) == LEU || GET_CODE (x) == GEU) | |
3752 | { | |
9ebbca7d | 3753 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); |
9854d9ed RK |
3754 | |
3755 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
3756 | base_bit + 2, | |
3757 | base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU)); | |
3758 | } | |
3759 | ||
3760 | else if (GET_CODE (x) == NE) | |
3761 | { | |
9ebbca7d | 3762 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); |
9854d9ed RK |
3763 | |
3764 | fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3, | |
3765 | base_bit + 2, base_bit + 2); | |
3766 | } | |
3767 | return; | |
3768 | ||
3769 | case 'E': | |
39a10a29 | 3770 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
3771 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
3772 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 3773 | else |
39a10a29 | 3774 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 3775 | return; |
9854d9ed RK |
3776 | |
3777 | case 'f': | |
3778 | /* X is a CR register. Print the shift count needed to move it | |
3779 | to the high-order four bits. */ | |
3780 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
3781 | output_operand_lossage ("invalid %%f value"); | |
3782 | else | |
9ebbca7d | 3783 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
3784 | return; |
3785 | ||
3786 | case 'F': | |
3787 | /* Similar, but print the count for the rotate in the opposite | |
3788 | direction. */ | |
3789 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
3790 | output_operand_lossage ("invalid %%F value"); | |
3791 | else | |
9ebbca7d | 3792 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
3793 | return; |
3794 | ||
3795 | case 'G': | |
3796 | /* X is a constant integer. If it is negative, print "m", | |
3797 | otherwise print "z". This is to make a aze or ame insn. */ | |
3798 | if (GET_CODE (x) != CONST_INT) | |
3799 | output_operand_lossage ("invalid %%G value"); | |
3800 | else if (INTVAL (x) >= 0) | |
76229ac8 | 3801 | putc ('z', file); |
9854d9ed | 3802 | else |
76229ac8 | 3803 | putc ('m', file); |
9854d9ed | 3804 | return; |
e2c953b6 | 3805 | |
9878760c | 3806 | case 'h': |
df3d94ed RK |
3807 | /* If constant, output low-order five bits. Otherwise, |
3808 | write normally. */ | |
9878760c | 3809 | if (INT_P (x)) |
5f59ecb7 | 3810 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
3811 | else |
3812 | print_operand (file, x, 0); | |
3813 | return; | |
3814 | ||
64305719 DE |
3815 | case 'H': |
3816 | /* If constant, output low-order six bits. Otherwise, | |
3817 | write normally. */ | |
3818 | if (INT_P (x)) | |
5f59ecb7 | 3819 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
3820 | else |
3821 | print_operand (file, x, 0); | |
3822 | return; | |
3823 | ||
9854d9ed RK |
3824 | case 'I': |
3825 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 3826 | if (INT_P (x)) |
76229ac8 | 3827 | putc ('i', file); |
9878760c RK |
3828 | return; |
3829 | ||
9854d9ed RK |
3830 | case 'j': |
3831 | /* Write the bit number in CCR for jump. */ | |
3832 | i = ccr_bit (x, 0); | |
3833 | if (i == -1) | |
3834 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 3835 | else |
9854d9ed | 3836 | fprintf (file, "%d", i); |
9878760c RK |
3837 | return; |
3838 | ||
9854d9ed RK |
3839 | case 'J': |
3840 | /* Similar, but add one for shift count in rlinm for scc and pass | |
3841 | scc flag to `ccr_bit'. */ | |
3842 | i = ccr_bit (x, 1); | |
3843 | if (i == -1) | |
3844 | output_operand_lossage ("invalid %%J code"); | |
3845 | else | |
a0466a68 RK |
3846 | /* If we want bit 31, write a shift count of zero, not 32. */ |
3847 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
3848 | return; |
3849 | ||
9854d9ed RK |
3850 | case 'k': |
3851 | /* X must be a constant. Write the 1's complement of the | |
3852 | constant. */ | |
9878760c | 3853 | if (! INT_P (x)) |
9854d9ed | 3854 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
3855 | else |
3856 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
3857 | return; |
3858 | ||
81eace42 | 3859 | case 'K': |
9ebbca7d GK |
3860 | /* X must be a symbolic constant on ELF. Write an |
3861 | expression suitable for an 'addi' that adds in the low 16 | |
3862 | bits of the MEM. */ | |
3863 | if (GET_CODE (x) != CONST) | |
3864 | { | |
3865 | print_operand_address (file, x); | |
3866 | fputs ("@l", file); | |
3867 | } | |
3868 | else | |
3869 | { | |
3870 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
3871 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
3872 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
3873 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 3874 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
3875 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
3876 | fputs ("@l", file); | |
3877 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); | |
3878 | } | |
81eace42 GK |
3879 | return; |
3880 | ||
3881 | /* %l is output_asm_label. */ | |
9ebbca7d | 3882 | |
9854d9ed RK |
3883 | case 'L': |
3884 | /* Write second word of DImode or DFmode reference. Works on register | |
3885 | or non-indexed memory only. */ | |
3886 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 3887 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
3888 | else if (GET_CODE (x) == MEM) |
3889 | { | |
3890 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 3891 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
3892 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
3893 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
19087b1c DE |
3894 | output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0), |
3895 | UNITS_PER_WORD)); | |
9854d9ed | 3896 | else |
19087b1c DE |
3897 | output_address (plus_constant_for_output (XEXP (x, 0), |
3898 | UNITS_PER_WORD)); | |
ba5e43aa | 3899 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
3900 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
3901 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 3902 | } |
9878760c | 3903 | return; |
9854d9ed | 3904 | |
9878760c RK |
3905 | case 'm': |
3906 | /* MB value for a mask operand. */ | |
3907 | if (! mask_operand (x, VOIDmode)) | |
3908 | output_operand_lossage ("invalid %%m value"); | |
3909 | ||
3910 | val = INT_LOWPART (x); | |
3911 | ||
3912 | /* If the high bit is set and the low bit is not, the value is zero. | |
3913 | If the high bit is zero, the value is the first 1 bit we find from | |
3914 | the left. */ | |
0858c623 | 3915 | if ((val & 0x80000000) && ((val & 1) == 0)) |
9878760c | 3916 | { |
19d2d16f | 3917 | putc ('0', file); |
9878760c RK |
3918 | return; |
3919 | } | |
0858c623 | 3920 | else if ((val & 0x80000000) == 0) |
9878760c RK |
3921 | { |
3922 | for (i = 1; i < 32; i++) | |
0858c623 | 3923 | if ((val <<= 1) & 0x80000000) |
9878760c RK |
3924 | break; |
3925 | fprintf (file, "%d", i); | |
3926 | return; | |
3927 | } | |
3928 | ||
3929 | /* Otherwise, look for the first 0 bit from the right. The result is its | |
3930 | number plus 1. We know the low-order bit is one. */ | |
3931 | for (i = 0; i < 32; i++) | |
3932 | if (((val >>= 1) & 1) == 0) | |
3933 | break; | |
3934 | ||
a260abc9 | 3935 | /* If we ended in ...01, i would be 0. The correct value is 31, so |
9878760c RK |
3936 | we want 31 - i. */ |
3937 | fprintf (file, "%d", 31 - i); | |
3938 | return; | |
3939 | ||
3940 | case 'M': | |
3941 | /* ME value for a mask operand. */ | |
3942 | if (! mask_operand (x, VOIDmode)) | |
a260abc9 | 3943 | output_operand_lossage ("invalid %%M value"); |
9878760c RK |
3944 | |
3945 | val = INT_LOWPART (x); | |
3946 | ||
3947 | /* If the low bit is set and the high bit is not, the value is 31. | |
3948 | If the low bit is zero, the value is the first 1 bit we find from | |
3949 | the right. */ | |
0858c623 | 3950 | if ((val & 1) && ((val & 0x80000000) == 0)) |
9878760c | 3951 | { |
76229ac8 | 3952 | fputs ("31", file); |
9878760c RK |
3953 | return; |
3954 | } | |
3955 | else if ((val & 1) == 0) | |
3956 | { | |
3957 | for (i = 0; i < 32; i++) | |
3958 | if ((val >>= 1) & 1) | |
3959 | break; | |
3960 | ||
a260abc9 | 3961 | /* If we had ....10, i would be 0. The result should be |
9878760c RK |
3962 | 30, so we need 30 - i. */ |
3963 | fprintf (file, "%d", 30 - i); | |
3964 | return; | |
3965 | } | |
3966 | ||
3967 | /* Otherwise, look for the first 0 bit from the left. The result is its | |
3968 | number minus 1. We know the high-order bit is one. */ | |
3969 | for (i = 0; i < 32; i++) | |
0858c623 | 3970 | if (((val <<= 1) & 0x80000000) == 0) |
9878760c RK |
3971 | break; |
3972 | ||
3973 | fprintf (file, "%d", i); | |
3974 | return; | |
3975 | ||
81eace42 GK |
3976 | /* %n outputs the negative of its operand. */ |
3977 | ||
9878760c RK |
3978 | case 'N': |
3979 | /* Write the number of elements in the vector times 4. */ | |
3980 | if (GET_CODE (x) != PARALLEL) | |
3981 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
3982 | else |
3983 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
3984 | return; |
3985 | ||
3986 | case 'O': | |
3987 | /* Similar, but subtract 1 first. */ | |
3988 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 3989 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
3990 | else |
3991 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
3992 | return; |
3993 | ||
9854d9ed RK |
3994 | case 'p': |
3995 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
3996 | if (! INT_P (x) | |
3997 | || (i = exact_log2 (INT_LOWPART (x))) < 0) | |
3998 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
3999 | else |
4000 | fprintf (file, "%d", i); | |
9854d9ed RK |
4001 | return; |
4002 | ||
9878760c RK |
4003 | case 'P': |
4004 | /* The operand must be an indirect memory reference. The result | |
4005 | is the register number. */ | |
4006 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG | |
4007 | || REGNO (XEXP (x, 0)) >= 32) | |
4008 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 DE |
4009 | else |
4010 | fprintf (file, "%d", REGNO (XEXP (x, 0))); | |
9878760c RK |
4011 | return; |
4012 | ||
dfbdccdb GK |
4013 | case 'q': |
4014 | /* This outputs the logical code corresponding to a boolean | |
4015 | expression. The expression may have one or both operands | |
39a10a29 GK |
4016 | negated (if one, only the first one). For condition register |
4017 | logical operations, it will also treat the negated | |
4018 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 4019 | { |
63bc1d05 | 4020 | const char *const *t = 0; |
dfbdccdb GK |
4021 | const char *s; |
4022 | enum rtx_code code = GET_CODE (x); | |
4023 | static const char * const tbl[3][3] = { | |
4024 | { "and", "andc", "nor" }, | |
4025 | { "or", "orc", "nand" }, | |
4026 | { "xor", "eqv", "xor" } }; | |
4027 | ||
4028 | if (code == AND) | |
4029 | t = tbl[0]; | |
4030 | else if (code == IOR) | |
4031 | t = tbl[1]; | |
4032 | else if (code == XOR) | |
4033 | t = tbl[2]; | |
4034 | else | |
4035 | output_operand_lossage ("invalid %%q value"); | |
4036 | ||
4037 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
4038 | s = t[0]; | |
4039 | else | |
4040 | { | |
4041 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
4042 | s = t[2]; | |
4043 | else | |
4044 | s = t[1]; | |
4045 | } | |
4046 | ||
4047 | fputs (s, file); | |
4048 | } | |
4049 | return; | |
4050 | ||
9854d9ed RK |
4051 | case 'R': |
4052 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
4053 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
4054 | output_operand_lossage ("invalid %%R value"); | |
4055 | else | |
9ebbca7d | 4056 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 4057 | return; |
9854d9ed RK |
4058 | |
4059 | case 's': | |
4060 | /* Low 5 bits of 32 - value */ | |
4061 | if (! INT_P (x)) | |
4062 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
4063 | else |
4064 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 4065 | return; |
9854d9ed | 4066 | |
a260abc9 DE |
4067 | case 'S': |
4068 | /* PowerPC64 mask position. All 0's and all 1's are excluded. | |
4069 | CONST_INT 32-bit mask is considered sign-extended so any | |
4070 | transition must occur within the CONST_INT, not on the boundary. */ | |
4071 | if (! mask64_operand (x, VOIDmode)) | |
4072 | output_operand_lossage ("invalid %%S value"); | |
4073 | ||
4074 | val = INT_LOWPART (x); | |
4075 | ||
4076 | if (val & 1) /* Clear Left */ | |
4077 | { | |
a238cd8b DE |
4078 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
4079 | if (!((val >>= 1) & 1)) | |
4080 | break; | |
a260abc9 | 4081 | |
a238cd8b DE |
4082 | #if HOST_BITS_PER_WIDE_INT == 32 |
4083 | if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
4084 | { | |
4085 | val = CONST_DOUBLE_HIGH (x); | |
4086 | ||
4087 | if (val == 0) | |
4088 | --i; | |
4089 | else | |
4090 | for (i = 32; i < 64; i++) | |
4091 | if (!((val >>= 1) & 1)) | |
4092 | break; | |
4093 | } | |
a260abc9 | 4094 | #endif |
a238cd8b DE |
4095 | /* i = index of last set bit from right |
4096 | mask begins at 63 - i from left */ | |
4097 | if (i > 63) | |
4098 | output_operand_lossage ("%%S computed all 1's mask"); | |
cccf3bdc | 4099 | |
a260abc9 DE |
4100 | fprintf (file, "%d", 63 - i); |
4101 | return; | |
4102 | } | |
4103 | else /* Clear Right */ | |
4104 | { | |
a238cd8b DE |
4105 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
4106 | if ((val >>= 1) & 1) | |
4107 | break; | |
a260abc9 | 4108 | |
a238cd8b | 4109 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
4110 | if (GET_CODE (x) == CONST_DOUBLE && i == 32) |
4111 | { | |
a238cd8b | 4112 | val = CONST_DOUBLE_HIGH (x); |
a260abc9 | 4113 | |
a238cd8b | 4114 | if (val == (HOST_WIDE_INT) -1) |
a260abc9 | 4115 | --i; |
a260abc9 | 4116 | else |
a238cd8b DE |
4117 | for (i = 32; i < 64; i++) |
4118 | if ((val >>= 1) & 1) | |
a260abc9 DE |
4119 | break; |
4120 | } | |
4121 | #endif | |
a238cd8b DE |
4122 | /* i = index of last clear bit from right |
4123 | mask ends at 62 - i from left */ | |
4124 | if (i > 62) | |
4125 | output_operand_lossage ("%%S computed all 0's mask"); | |
cccf3bdc | 4126 | |
a238cd8b | 4127 | fprintf (file, "%d", 62 - i); |
a260abc9 DE |
4128 | return; |
4129 | } | |
4130 | ||
cccf3bdc DE |
4131 | case 'T': |
4132 | /* Print the symbolic name of a branch target register. */ | |
4133 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
4134 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
4135 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 4136 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
4137 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
4138 | else | |
4139 | fputs ("ctr", file); | |
4140 | return; | |
4141 | ||
9854d9ed | 4142 | case 'u': |
802a0058 | 4143 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
4144 | if (! INT_P (x)) |
4145 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 DE |
4146 | else |
4147 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, | |
4148 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
4149 | return; |
4150 | ||
802a0058 MM |
4151 | case 'v': |
4152 | /* High-order 16 bits of constant for use in signed operand. */ | |
4153 | if (! INT_P (x)) | |
4154 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 DE |
4155 | else |
4156 | { | |
4157 | int value = (INT_LOWPART (x) >> 16) & 0xffff; | |
802a0058 | 4158 | |
e2c953b6 DE |
4159 | /* Solaris assembler doesn't like lis 0,0x8000 */ |
4160 | if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0) | |
4161 | fprintf (file, "%d", value | (~0 << 16)); | |
4162 | else | |
4163 | fprintf (file, "0x%x", value); | |
4164 | return; | |
4165 | } | |
802a0058 | 4166 | |
9854d9ed RK |
4167 | case 'U': |
4168 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
4169 | if (GET_CODE (x) == MEM | |
4170 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
4171 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 4172 | putc ('u', file); |
9854d9ed | 4173 | return; |
9878760c | 4174 | |
e0cd0770 JC |
4175 | case 'V': |
4176 | /* Print the trap code for this operand. */ | |
4177 | switch (GET_CODE (x)) | |
4178 | { | |
4179 | case EQ: | |
4180 | fputs ("eq", file); /* 4 */ | |
4181 | break; | |
4182 | case NE: | |
4183 | fputs ("ne", file); /* 24 */ | |
4184 | break; | |
4185 | case LT: | |
4186 | fputs ("lt", file); /* 16 */ | |
4187 | break; | |
4188 | case LE: | |
4189 | fputs ("le", file); /* 20 */ | |
4190 | break; | |
4191 | case GT: | |
4192 | fputs ("gt", file); /* 8 */ | |
4193 | break; | |
4194 | case GE: | |
4195 | fputs ("ge", file); /* 12 */ | |
4196 | break; | |
4197 | case LTU: | |
4198 | fputs ("llt", file); /* 2 */ | |
4199 | break; | |
4200 | case LEU: | |
4201 | fputs ("lle", file); /* 6 */ | |
4202 | break; | |
4203 | case GTU: | |
4204 | fputs ("lgt", file); /* 1 */ | |
4205 | break; | |
4206 | case GEU: | |
4207 | fputs ("lge", file); /* 5 */ | |
4208 | break; | |
4209 | default: | |
4210 | abort (); | |
4211 | } | |
4212 | break; | |
4213 | ||
9854d9ed RK |
4214 | case 'w': |
4215 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
4216 | normally. */ | |
4217 | if (INT_P (x)) | |
5f59ecb7 DE |
4218 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
4219 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
4220 | else |
4221 | print_operand (file, x, 0); | |
9878760c RK |
4222 | return; |
4223 | ||
9854d9ed | 4224 | case 'W': |
e2c953b6 DE |
4225 | /* MB value for a PowerPC64 rldic operand. */ |
4226 | if (! rldic_operand (x, VOIDmode)) | |
4227 | output_operand_lossage ("invalid %%W value"); | |
4228 | ||
4229 | val = (GET_CODE (x) == CONST_INT | |
4230 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
4231 | ||
4232 | if (val < 0) | |
4233 | i = -1; | |
9854d9ed | 4234 | else |
e2c953b6 DE |
4235 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
4236 | if ((val <<= 1) < 0) | |
4237 | break; | |
4238 | ||
4239 | #if HOST_BITS_PER_WIDE_INT == 32 | |
4240 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
4241 | i += 32; /* zero-extend high-part was all 0's */ | |
4242 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
4243 | { | |
4244 | val = CONST_DOUBLE_LOW (x); | |
4245 | ||
4246 | if (val == 0) | |
4247 | abort(); | |
4248 | else if (val < 0) | |
4249 | --i; | |
4250 | else | |
4251 | for ( ; i < 64; i++) | |
4252 | if ((val <<= 1) < 0) | |
4253 | break; | |
4254 | } | |
4255 | #endif | |
4256 | ||
4257 | fprintf (file, "%d", i + 1); | |
9854d9ed | 4258 | return; |
9878760c | 4259 | |
9854d9ed RK |
4260 | case 'X': |
4261 | if (GET_CODE (x) == MEM | |
4262 | && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0))) | |
76229ac8 | 4263 | putc ('x', file); |
9854d9ed | 4264 | return; |
9878760c | 4265 | |
9854d9ed RK |
4266 | case 'Y': |
4267 | /* Like 'L', for third word of TImode */ | |
4268 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 4269 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 4270 | else if (GET_CODE (x) == MEM) |
9878760c | 4271 | { |
9854d9ed RK |
4272 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
4273 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 4274 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 4275 | else |
a54d04b7 | 4276 | output_address (plus_constant (XEXP (x, 0), 8)); |
ba5e43aa | 4277 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
4278 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
4279 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
4280 | } |
4281 | return; | |
9854d9ed | 4282 | |
9878760c | 4283 | case 'z': |
b4ac57ab RS |
4284 | /* X is a SYMBOL_REF. Write out the name preceded by a |
4285 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
4286 | names. If we are configured for System V (or the embedded ABI) on |
4287 | the PowerPC, do not emit the period, since those systems do not use | |
4288 | TOCs and the like. */ | |
9878760c RK |
4289 | if (GET_CODE (x) != SYMBOL_REF) |
4290 | abort (); | |
4291 | ||
b6c9286a MM |
4292 | if (XSTR (x, 0)[0] != '.') |
4293 | { | |
4294 | switch (DEFAULT_ABI) | |
4295 | { | |
4296 | default: | |
4297 | abort (); | |
4298 | ||
4299 | case ABI_AIX: | |
4300 | putc ('.', file); | |
4301 | break; | |
4302 | ||
4303 | case ABI_V4: | |
4304 | case ABI_AIX_NODESC: | |
c81bebd7 | 4305 | case ABI_SOLARIS: |
b6c9286a | 4306 | break; |
b6c9286a MM |
4307 | } |
4308 | } | |
9ebbca7d | 4309 | #if TARGET_AIX |
9878760c | 4310 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); |
9ebbca7d GK |
4311 | #else |
4312 | assemble_name (file, XSTR (x, 0)); | |
4313 | #endif | |
9878760c RK |
4314 | return; |
4315 | ||
9854d9ed RK |
4316 | case 'Z': |
4317 | /* Like 'L', for last word of TImode. */ | |
4318 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 4319 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
4320 | else if (GET_CODE (x) == MEM) |
4321 | { | |
4322 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
4323 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 4324 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 4325 | else |
a54d04b7 | 4326 | output_address (plus_constant (XEXP (x, 0), 12)); |
ba5e43aa | 4327 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
4328 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
4329 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 4330 | } |
5c23c401 | 4331 | return; |
9854d9ed | 4332 | |
9878760c RK |
4333 | case 0: |
4334 | if (GET_CODE (x) == REG) | |
4335 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
4336 | else if (GET_CODE (x) == MEM) | |
4337 | { | |
4338 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
4339 | know the width from the mode. */ | |
4340 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
4341 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
4342 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 4343 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
4344 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
4345 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 4346 | else |
a54d04b7 | 4347 | output_address (XEXP (x, 0)); |
9878760c RK |
4348 | } |
4349 | else | |
a54d04b7 | 4350 | output_addr_const (file, x); |
a85d226b | 4351 | return; |
9878760c RK |
4352 | |
4353 | default: | |
4354 | output_operand_lossage ("invalid %%xn code"); | |
4355 | } | |
4356 | } | |
4357 | \f | |
4358 | /* Print the address of an operand. */ | |
4359 | ||
4360 | void | |
4361 | print_operand_address (file, x) | |
4362 | FILE *file; | |
4363 | register rtx x; | |
4364 | { | |
4365 | if (GET_CODE (x) == REG) | |
4697a36c | 4366 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
4367 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
4368 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
4369 | { |
4370 | output_addr_const (file, x); | |
ba5e43aa | 4371 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
4372 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
4373 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d GK |
4374 | else if (TARGET_TOC) |
4375 | abort(); | |
9878760c RK |
4376 | } |
4377 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
4378 | { | |
4379 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
4380 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
4381 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 4382 | else |
4697a36c MM |
4383 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
4384 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
4385 | } |
4386 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
5f59ecb7 DE |
4387 | { |
4388 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1))); | |
4389 | fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
4390 | } | |
3cb999d8 DE |
4391 | #if TARGET_ELF |
4392 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
4393 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
4394 | { |
4395 | output_addr_const (file, XEXP (x, 1)); | |
4396 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
4397 | } | |
3cb999d8 | 4398 | #endif |
9ebbca7d GK |
4399 | else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x)) |
4400 | { | |
4401 | if (TARGET_AIX) | |
4402 | { | |
4403 | rtx contains_minus = XEXP (x, 1); | |
4404 | rtx minus; | |
4405 | ||
4406 | /* Find the (minus (sym) (toc)) buried in X, and temporarily | |
4407 | turn it into (sym) for output_addr_const. */ | |
4408 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) | |
4409 | contains_minus = XEXP (contains_minus, 0); | |
4410 | ||
4411 | minus = XEXP (contains_minus, 0); | |
4412 | XEXP (contains_minus, 0) = XEXP (minus, 0); | |
4413 | output_addr_const (file, XEXP (x, 1)); | |
4414 | XEXP (contains_minus, 0) = minus; | |
4415 | } | |
4416 | else | |
4417 | output_addr_const (file, XEXP (x, 1)); | |
4418 | ||
4419 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
4420 | } | |
9878760c RK |
4421 | else |
4422 | abort (); | |
4423 | } | |
4424 | \f | |
39a10a29 GK |
4425 | enum rtx_code |
4426 | rs6000_reverse_condition (mode, code) | |
4427 | enum machine_mode mode; | |
4428 | enum rtx_code code; | |
4429 | { | |
4430 | /* Reversal of FP compares takes care -- an ordered compare | |
4431 | becomes an unordered compare and vice versa. */ | |
4432 | if (mode == CCFPmode) | |
bab6226b | 4433 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 4434 | else |
bab6226b | 4435 | return reverse_condition (code); |
39a10a29 GK |
4436 | } |
4437 | ||
4438 | ||
4439 | /* Generate a compare for CODE. Return a brand-new rtx that | |
4440 | represents the result of the compare. */ | |
4441 | static rtx | |
4442 | rs6000_generate_compare (code) | |
4443 | enum rtx_code code; | |
4444 | { | |
4445 | enum machine_mode comp_mode; | |
4446 | rtx compare_result; | |
4447 | ||
4448 | if (rs6000_compare_fp_p) | |
4449 | comp_mode = CCFPmode; | |
4450 | else if (code == GTU || code == LTU | |
4451 | || code == GEU || code == LEU) | |
4452 | comp_mode = CCUNSmode; | |
4453 | else | |
4454 | comp_mode = CCmode; | |
4455 | ||
4456 | /* First, the compare. */ | |
4457 | compare_result = gen_reg_rtx (comp_mode); | |
4458 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
4459 | gen_rtx_COMPARE (comp_mode, | |
4460 | rs6000_compare_op0, | |
4461 | rs6000_compare_op1))); | |
4462 | ||
4463 | /* Some kinds of FP comparisons need an OR operation. */ | |
4464 | if (rs6000_compare_fp_p | |
4465 | && (code == LE || code == GE | |
4466 | || code == UNEQ || code == LTGT | |
4467 | || code == UNGT || code == UNLT)) | |
4468 | { | |
4469 | enum rtx_code or1, or2; | |
4470 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
4471 | rtx or_result = gen_reg_rtx (CCEQmode); | |
4472 | ||
4473 | switch (code) | |
4474 | { | |
4475 | case LE: or1 = LT; or2 = EQ; break; | |
4476 | case GE: or1 = GT; or2 = EQ; break; | |
4477 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
4478 | case LTGT: or1 = LT; or2 = GT; break; | |
4479 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
4480 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
4481 | default: abort (); | |
4482 | } | |
4483 | validate_condition_mode (or1, comp_mode); | |
4484 | validate_condition_mode (or2, comp_mode); | |
4485 | or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx); | |
4486 | or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx); | |
4487 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, | |
4488 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
4489 | const_true_rtx); | |
4490 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
4491 | ||
4492 | compare_result = or_result; | |
4493 | code = EQ; | |
4494 | } | |
4495 | ||
4496 | validate_condition_mode (code, GET_MODE (compare_result)); | |
4497 | ||
4498 | return gen_rtx (code, VOIDmode, compare_result, const0_rtx); | |
4499 | } | |
4500 | ||
4501 | ||
4502 | /* Emit the RTL for an sCOND pattern. */ | |
4503 | ||
4504 | void | |
4505 | rs6000_emit_sCOND (code, result) | |
4506 | enum rtx_code code; | |
4507 | rtx result; | |
4508 | { | |
4509 | rtx condition_rtx; | |
4510 | enum machine_mode op_mode; | |
4511 | ||
4512 | condition_rtx = rs6000_generate_compare (code); | |
4513 | ||
4514 | op_mode = GET_MODE (rs6000_compare_op0); | |
4515 | if (op_mode == VOIDmode) | |
4516 | op_mode = GET_MODE (rs6000_compare_op1); | |
4517 | ||
4518 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
4519 | { | |
4520 | PUT_MODE (condition_rtx, DImode); | |
4521 | convert_move (result, condition_rtx, 0); | |
4522 | } | |
4523 | else | |
4524 | { | |
4525 | PUT_MODE (condition_rtx, SImode); | |
4526 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
4527 | } | |
4528 | } | |
4529 | ||
4530 | ||
4531 | /* Emit a branch of kind CODE to location LOC. */ | |
4532 | ||
4533 | void | |
4534 | rs6000_emit_cbranch (code, loc) | |
4535 | enum rtx_code code; | |
4536 | rtx loc; | |
4537 | { | |
4538 | rtx condition_rtx, loc_ref; | |
4539 | ||
4540 | condition_rtx = rs6000_generate_compare (code); | |
4541 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
4542 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
4543 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
4544 | loc_ref, pc_rtx))); | |
4545 | } | |
4546 | ||
4547 | ||
12a4e8c5 GK |
4548 | /* Return the string to output a conditional branch to LABEL, which is |
4549 | the operand number of the label, or -1 if the branch is really a | |
4550 | conditional return. | |
4551 | ||
4552 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
4553 | condition code register and its mode specifies what kind of | |
4554 | comparison we made. | |
4555 | ||
4556 | REVERSED is non-zero if we should reverse the sense of the comparison. | |
4557 | ||
4558 | INSN is the insn. */ | |
4559 | ||
4560 | char * | |
4561 | output_cbranch (op, label, reversed, insn) | |
4562 | rtx op; | |
4563 | const char * label; | |
4564 | int reversed; | |
4565 | rtx insn; | |
4566 | { | |
4567 | static char string[64]; | |
4568 | enum rtx_code code = GET_CODE (op); | |
4569 | rtx cc_reg = XEXP (op, 0); | |
4570 | enum machine_mode mode = GET_MODE (cc_reg); | |
4571 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 4572 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
4573 | int really_reversed = reversed ^ need_longbranch; |
4574 | char *s = string; | |
4575 | const char *ccode; | |
4576 | const char *pred; | |
4577 | rtx note; | |
4578 | ||
39a10a29 GK |
4579 | validate_condition_mode (code, mode); |
4580 | ||
4581 | /* Work out which way this really branches. We could use | |
4582 | reverse_condition_maybe_unordered here always but this | |
4583 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 4584 | if (really_reversed) |
39a10a29 | 4585 | code = rs6000_reverse_condition (mode, code); |
12a4e8c5 | 4586 | |
39a10a29 | 4587 | switch (code) |
12a4e8c5 GK |
4588 | { |
4589 | /* Not all of these are actually distinct opcodes, but | |
4590 | we distinguish them for clarity of the resulting assembler. */ | |
4591 | case NE: ccode = "ne"; break; | |
4592 | case EQ: ccode = "eq"; break; | |
4593 | case GE: case GEU: ccode = "ge"; break; | |
4594 | case GT: case GTU: ccode = "gt"; break; | |
4595 | case LE: case LEU: ccode = "le"; break; | |
4596 | case LT: case LTU: ccode = "lt"; break; | |
4597 | case UNORDERED: ccode = "un"; break; | |
4598 | case ORDERED: ccode = "nu"; break; | |
4599 | case UNGE: ccode = "nl"; break; | |
4600 | case UNLE: ccode = "ng"; break; | |
4601 | default: | |
4602 | abort(); | |
4603 | } | |
4604 | ||
94a54f47 GK |
4605 | /* Maybe we have a guess as to how likely the branch is. |
4606 | The old mnemonics don't have a way to specify this information. */ | |
12a4e8c5 GK |
4607 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
4608 | if (note != NULL_RTX) | |
4609 | { | |
4610 | /* PROB is the difference from 50%. */ | |
4611 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
4612 | ||
4613 | /* For branches that are very close to 50%, assume not-taken. */ | |
4614 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
4615 | && ((prob > 0) ^ need_longbranch)) | |
4616 | pred = "+"; | |
4617 | else | |
4618 | pred = "-"; | |
4619 | } | |
4620 | else | |
4621 | pred = ""; | |
4622 | ||
4623 | if (label == NULL) | |
94a54f47 | 4624 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 4625 | else |
94a54f47 | 4626 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 4627 | |
37c67319 GK |
4628 | /* We need to escape any '%' characters in the reg_names string. |
4629 | Assume they'd only be the first character... */ | |
4630 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') | |
4631 | *s++ = '%'; | |
94a54f47 | 4632 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
4633 | |
4634 | if (label != NULL) | |
4635 | { | |
4636 | /* If the branch distance was too far, we may have to use an | |
4637 | unconditional branch to go the distance. */ | |
4638 | if (need_longbranch) | |
4639 | s += sprintf (s, ",%c$+8 ; b %s", '%', label); | |
4640 | else | |
4641 | s += sprintf (s, ",%s", label); | |
4642 | } | |
4643 | ||
4644 | return string; | |
4645 | } | |
4646 | \f | |
9878760c RK |
4647 | /* This page contains routines that are used to determine what the function |
4648 | prologue and epilogue code will do and write them out. */ | |
4649 | ||
4650 | /* Return the first fixed-point register that is required to be saved. 32 if | |
4651 | none. */ | |
4652 | ||
4653 | int | |
4654 | first_reg_to_save () | |
4655 | { | |
4656 | int first_reg; | |
4657 | ||
4658 | /* Find lowest numbered live register. */ | |
4659 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
a38d360d GK |
4660 | if (regs_ever_live[first_reg] |
4661 | && (! call_used_regs[first_reg] | |
4662 | || (first_reg == PIC_OFFSET_TABLE_REGNUM | |
4663 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
4664 | && flag_pic == 1))) | |
9878760c RK |
4665 | break; |
4666 | ||
b5253831 DE |
4667 | if (profile_flag) |
4668 | { | |
4669 | /* AIX must save/restore every register that contains a parameter | |
4670 | before/after the .__mcount call plus an additional register | |
4671 | for the static chain, if needed; use registers from 30 down to 22 | |
4672 | to do this. */ | |
4673 | if (DEFAULT_ABI == ABI_AIX) | |
4674 | { | |
4675 | int last_parm_reg, profile_first_reg; | |
4676 | ||
4677 | /* Figure out last used parameter register. The proper thing | |
4678 | to do is to walk incoming args of the function. A function | |
4679 | might have live parameter registers even if it has no | |
4680 | incoming args. */ | |
4681 | for (last_parm_reg = 10; | |
4682 | last_parm_reg > 2 && ! regs_ever_live [last_parm_reg]; | |
4683 | last_parm_reg--) | |
4684 | ; | |
4685 | ||
4686 | /* Calculate first reg for saving parameter registers | |
4687 | and static chain. | |
4688 | Skip reg 31 which may contain the frame pointer. */ | |
4689 | profile_first_reg = (33 - last_parm_reg | |
4690 | - (current_function_needs_context ? 1 : 0)); | |
4691 | /* Do not save frame pointer if no parameters needs to be saved. */ | |
4692 | if (profile_first_reg == 31) | |
4693 | profile_first_reg = 32; | |
4694 | ||
4695 | if (first_reg > profile_first_reg) | |
4696 | first_reg = profile_first_reg; | |
4697 | } | |
e165f3f0 | 4698 | |
b5253831 DE |
4699 | /* SVR4 may need one register to preserve the static chain. */ |
4700 | else if (current_function_needs_context) | |
4701 | { | |
4702 | /* Skip reg 31 which may contain the frame pointer. */ | |
4703 | if (first_reg > 30) | |
4704 | first_reg = 30; | |
4705 | } | |
4706 | } | |
e165f3f0 | 4707 | |
9878760c RK |
4708 | return first_reg; |
4709 | } | |
4710 | ||
4711 | /* Similar, for FP regs. */ | |
4712 | ||
4713 | int | |
4714 | first_fp_reg_to_save () | |
4715 | { | |
4716 | int first_reg; | |
4717 | ||
4718 | /* Find lowest numbered live register. */ | |
4719 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
4720 | if (regs_ever_live[first_reg]) | |
4721 | break; | |
4722 | ||
4723 | return first_reg; | |
4724 | } | |
4697a36c MM |
4725 | \f |
4726 | /* Calculate the stack information for the current function. This is | |
4727 | complicated by having two separate calling sequences, the AIX calling | |
4728 | sequence and the V.4 calling sequence. | |
4729 | ||
4730 | AIX stack frames look like: | |
a260abc9 | 4731 | 32-bit 64-bit |
4697a36c | 4732 | SP----> +---------------------------------------+ |
a260abc9 | 4733 | | back chain to caller | 0 0 |
4697a36c | 4734 | +---------------------------------------+ |
a260abc9 | 4735 | | saved CR | 4 8 (8-11) |
4697a36c | 4736 | +---------------------------------------+ |
a260abc9 | 4737 | | saved LR | 8 16 |
4697a36c | 4738 | +---------------------------------------+ |
a260abc9 | 4739 | | reserved for compilers | 12 24 |
4697a36c | 4740 | +---------------------------------------+ |
a260abc9 | 4741 | | reserved for binders | 16 32 |
4697a36c | 4742 | +---------------------------------------+ |
a260abc9 | 4743 | | saved TOC pointer | 20 40 |
4697a36c | 4744 | +---------------------------------------+ |
a260abc9 | 4745 | | Parameter save area (P) | 24 48 |
4697a36c | 4746 | +---------------------------------------+ |
a260abc9 | 4747 | | Alloca space (A) | 24+P etc. |
802a0058 | 4748 | +---------------------------------------+ |
a7df97e6 | 4749 | | Local variable space (L) | 24+P+A |
4697a36c | 4750 | +---------------------------------------+ |
a7df97e6 | 4751 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 4752 | +---------------------------------------+ |
a7df97e6 | 4753 | | Save area for GP registers (G) | 24+P+A+X+L |
4697a36c | 4754 | +---------------------------------------+ |
a7df97e6 | 4755 | | Save area for FP registers (F) | 24+P+A+X+L+G |
4697a36c MM |
4756 | +---------------------------------------+ |
4757 | old SP->| back chain to caller's caller | | |
4758 | +---------------------------------------+ | |
4759 | ||
5376a30c KR |
4760 | The required alignment for AIX configurations is two words (i.e., 8 |
4761 | or 16 bytes). | |
4762 | ||
4763 | ||
4697a36c MM |
4764 | V.4 stack frames look like: |
4765 | ||
4766 | SP----> +---------------------------------------+ | |
4767 | | back chain to caller | 0 | |
4768 | +---------------------------------------+ | |
5eb387b8 | 4769 | | caller's saved LR | 4 |
4697a36c MM |
4770 | +---------------------------------------+ |
4771 | | Parameter save area (P) | 8 | |
4772 | +---------------------------------------+ | |
a7df97e6 MM |
4773 | | Alloca space (A) | 8+P |
4774 | +---------------------------------------+ | |
4775 | | Varargs save area (V) | 8+P+A | |
4776 | +---------------------------------------+ | |
4777 | | Local variable space (L) | 8+P+A+V | |
4778 | +---------------------------------------+ | |
4779 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 4780 | +---------------------------------------+ |
a7df97e6 MM |
4781 | | saved CR (C) | 8+P+A+V+L+X |
4782 | +---------------------------------------+ | |
4783 | | Save area for GP registers (G) | 8+P+A+V+L+X+C | |
4784 | +---------------------------------------+ | |
4785 | | Save area for FP registers (F) | 8+P+A+V+L+X+C+G | |
4697a36c MM |
4786 | +---------------------------------------+ |
4787 | old SP->| back chain to caller's caller | | |
4788 | +---------------------------------------+ | |
b6c9286a | 4789 | |
5376a30c KR |
4790 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
4791 | given. (But note below and in sysv4.h that we require only 8 and | |
4792 | may round up the size of our stack frame anyways. The historical | |
4793 | reason is early versions of powerpc-linux which didn't properly | |
4794 | align the stack at program startup. A happy side-effect is that | |
4795 | -mno-eabi libraries can be used with -meabi programs.) | |
4796 | ||
b6c9286a | 4797 | |
5376a30c KR |
4798 | The EABI configuration defaults to the V.4 layout, unless |
4799 | -mcall-aix is used, in which case the AIX layout is used. However, | |
4800 | the stack alignment requirements may differ. If -mno-eabi is not | |
4801 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
4802 | given, the required alignment is 16 bytes. (But see V.4 comment | |
4803 | above.) */ | |
4697a36c | 4804 | |
61b2fbe7 MM |
4805 | #ifndef ABI_STACK_BOUNDARY |
4806 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
4807 | #endif | |
4808 | ||
4697a36c MM |
4809 | rs6000_stack_t * |
4810 | rs6000_stack_info () | |
4811 | { | |
4812 | static rs6000_stack_t info, zero_info; | |
4813 | rs6000_stack_t *info_ptr = &info; | |
9ebbca7d | 4814 | int reg_size = TARGET_POWERPC64 ? 8 : 4; |
24d304eb | 4815 | enum rs6000_abi abi; |
b6c9286a | 4816 | int total_raw_size; |
4697a36c MM |
4817 | |
4818 | /* Zero all fields portably */ | |
4819 | info = zero_info; | |
4820 | ||
4821 | /* Select which calling sequence */ | |
b6c9286a | 4822 | info_ptr->abi = abi = DEFAULT_ABI; |
9878760c | 4823 | |
4697a36c MM |
4824 | /* Calculate which registers need to be saved & save area size */ |
4825 | info_ptr->first_gp_reg_save = first_reg_to_save (); | |
906fb125 GK |
4826 | /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM, |
4827 | even if it currently looks like we won't. */ | |
4828 | if (flag_pic == 1 | |
4829 | && (abi == ABI_V4 || abi == ABI_SOLARIS) | |
4830 | && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM) | |
4831 | info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM); | |
4832 | else | |
4833 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c MM |
4834 | |
4835 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); | |
4836 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
4837 | ||
4838 | /* Does this function call anything? */ | |
9ebbca7d | 4839 | info_ptr->calls_p = ! current_function_is_leaf; |
b6c9286a | 4840 | |
4697a36c | 4841 | /* Determine if we need to save the link register */ |
9ebbca7d | 4842 | if (regs_ever_live[LINK_REGISTER_REGNUM] |
38c1f2d7 | 4843 | || (DEFAULT_ABI == ABI_AIX && profile_flag) |
4697a36c MM |
4844 | #ifdef TARGET_RELOCATABLE |
4845 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
4846 | #endif | |
4847 | || (info_ptr->first_fp_reg_save != 64 | |
4848 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
24d304eb | 4849 | || (abi == ABI_V4 && current_function_calls_alloca) |
c81bebd7 | 4850 | || (abi == ABI_SOLARIS && current_function_calls_alloca) |
4697a36c MM |
4851 | || info_ptr->calls_p) |
4852 | { | |
4853 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 4854 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
4855 | } |
4856 | ||
9ebbca7d GK |
4857 | /* Determine if we need to save the condition code registers. */ |
4858 | if (regs_ever_live[CR2_REGNO] | |
4859 | || regs_ever_live[CR3_REGNO] | |
4860 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
4861 | { |
4862 | info_ptr->cr_save_p = 1; | |
9ebbca7d | 4863 | if (abi == ABI_V4 || abi == ABI_SOLARIS) |
4697a36c MM |
4864 | info_ptr->cr_size = reg_size; |
4865 | } | |
4866 | ||
4867 | /* Determine various sizes */ | |
4868 | info_ptr->reg_size = reg_size; | |
4869 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
4870 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 DE |
4871 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
4872 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8); | |
189e03e3 | 4873 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
b6c9286a MM |
4874 | + info_ptr->gp_size |
4875 | + info_ptr->cr_size | |
4876 | + info_ptr->lr_size | |
9ebbca7d | 4877 | + info_ptr->toc_size, 8); |
b6c9286a | 4878 | |
4697a36c | 4879 | /* Calculate the offsets */ |
24d304eb | 4880 | switch (abi) |
4697a36c | 4881 | { |
b6c9286a | 4882 | case ABI_NONE: |
24d304eb | 4883 | default: |
b6c9286a MM |
4884 | abort (); |
4885 | ||
4886 | case ABI_AIX: | |
4887 | case ABI_AIX_NODESC: | |
4888 | info_ptr->fp_save_offset = - info_ptr->fp_size; | |
4889 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a260abc9 DE |
4890 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
4891 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
4892 | break; |
4893 | ||
4894 | case ABI_V4: | |
c81bebd7 | 4895 | case ABI_SOLARIS: |
b6c9286a MM |
4896 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
4897 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 MM |
4898 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
4899 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
b6c9286a MM |
4900 | info_ptr->lr_save_offset = reg_size; |
4901 | break; | |
4697a36c MM |
4902 | } |
4903 | ||
ff381587 MM |
4904 | total_raw_size = (info_ptr->vars_size |
4905 | + info_ptr->parm_size | |
ff381587 MM |
4906 | + info_ptr->save_size |
4907 | + info_ptr->varargs_size | |
4908 | + info_ptr->fixed_size); | |
4909 | ||
4910 | info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
4911 | ||
4912 | /* Determine if we need to allocate any stack frame: | |
4913 | ||
4914 | For AIX we need to push the stack if a frame pointer is needed (because | |
4915 | the stack might be dynamically adjusted), if we are debugging, if we | |
9ebbca7d | 4916 | make calls, or if the sum of fp_save, gp_save, and local variables |
ff381587 | 4917 | are more than the space needed to save all non-volatile registers: |
bfc79d3b | 4918 | 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved). |
ff381587 MM |
4919 | |
4920 | For V.4 we don't have the stack cushion that AIX uses, but assume that | |
4921 | the debugger can handle stackless frames. */ | |
4922 | ||
4923 | if (info_ptr->calls_p) | |
4924 | info_ptr->push_p = 1; | |
4925 | ||
9ebbca7d | 4926 | else if (abi == ABI_V4 || abi == ABI_SOLARIS) |
ff381587 | 4927 | info_ptr->push_p = (total_raw_size > info_ptr->fixed_size |
9ebbca7d | 4928 | || info_ptr->calls_p); |
ff381587 MM |
4929 | |
4930 | else | |
4931 | info_ptr->push_p = (frame_pointer_needed | |
4932 | || write_symbols != NO_DEBUG | |
4933 | || ((total_raw_size - info_ptr->fixed_size) | |
bfc79d3b | 4934 | > (TARGET_32BIT ? 220 : 288))); |
ff381587 | 4935 | |
4697a36c | 4936 | /* Zero offsets if we're not saving those registers */ |
8dda1a21 | 4937 | if (info_ptr->fp_size == 0) |
4697a36c MM |
4938 | info_ptr->fp_save_offset = 0; |
4939 | ||
8dda1a21 | 4940 | if (info_ptr->gp_size == 0) |
4697a36c MM |
4941 | info_ptr->gp_save_offset = 0; |
4942 | ||
c81fc13e | 4943 | if (! info_ptr->lr_save_p) |
4697a36c MM |
4944 | info_ptr->lr_save_offset = 0; |
4945 | ||
c81fc13e | 4946 | if (! info_ptr->cr_save_p) |
4697a36c MM |
4947 | info_ptr->cr_save_offset = 0; |
4948 | ||
c81fc13e | 4949 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
4950 | info_ptr->toc_save_offset = 0; |
4951 | ||
4697a36c MM |
4952 | return info_ptr; |
4953 | } | |
4954 | ||
4955 | void | |
4956 | debug_stack_info (info) | |
4957 | rs6000_stack_t *info; | |
9878760c | 4958 | { |
d330fd93 | 4959 | const char *abi_string; |
24d304eb | 4960 | |
c81fc13e | 4961 | if (! info) |
4697a36c MM |
4962 | info = rs6000_stack_info (); |
4963 | ||
4964 | fprintf (stderr, "\nStack information for function %s:\n", | |
4965 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
4966 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
4967 | : "<unknown>")); | |
4968 | ||
24d304eb RK |
4969 | switch (info->abi) |
4970 | { | |
b6c9286a MM |
4971 | default: abi_string = "Unknown"; break; |
4972 | case ABI_NONE: abi_string = "NONE"; break; | |
4973 | case ABI_AIX: abi_string = "AIX"; break; | |
4974 | case ABI_AIX_NODESC: abi_string = "AIX"; break; | |
4975 | case ABI_V4: abi_string = "V.4"; break; | |
c81bebd7 | 4976 | case ABI_SOLARIS: abi_string = "Solaris"; break; |
24d304eb RK |
4977 | } |
4978 | ||
4979 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
4980 | ||
4697a36c MM |
4981 | if (info->first_gp_reg_save != 32) |
4982 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
4983 | ||
4984 | if (info->first_fp_reg_save != 64) | |
4985 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 4986 | |
4697a36c MM |
4987 | if (info->lr_save_p) |
4988 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 4989 | |
4697a36c MM |
4990 | if (info->cr_save_p) |
4991 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
4992 | ||
b6c9286a MM |
4993 | if (info->toc_save_p) |
4994 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
4995 | ||
4697a36c MM |
4996 | if (info->push_p) |
4997 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
4998 | ||
4999 | if (info->calls_p) | |
5000 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
5001 | ||
4697a36c MM |
5002 | if (info->gp_save_offset) |
5003 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
5004 | ||
5005 | if (info->fp_save_offset) | |
5006 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
5007 | ||
5008 | if (info->lr_save_offset) | |
5009 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
5010 | ||
5011 | if (info->cr_save_offset) | |
5012 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
5013 | ||
b6c9286a MM |
5014 | if (info->toc_save_offset) |
5015 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
5016 | ||
4697a36c MM |
5017 | if (info->varargs_save_offset) |
5018 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
5019 | ||
5020 | if (info->total_size) | |
5021 | fprintf (stderr, "\ttotal_size = %5d\n", info->total_size); | |
5022 | ||
5023 | if (info->varargs_size) | |
5024 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
5025 | ||
5026 | if (info->vars_size) | |
5027 | fprintf (stderr, "\tvars_size = %5d\n", info->vars_size); | |
5028 | ||
5029 | if (info->parm_size) | |
5030 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
5031 | ||
5032 | if (info->fixed_size) | |
5033 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
5034 | ||
5035 | if (info->gp_size) | |
5036 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
5037 | ||
5038 | if (info->fp_size) | |
5039 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
5040 | ||
b6c9286a MM |
5041 | if (info->lr_size) |
5042 | fprintf (stderr, "\tlr_size = %5d\n", info->cr_size); | |
5043 | ||
4697a36c MM |
5044 | if (info->cr_size) |
5045 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
5046 | ||
b6c9286a MM |
5047 | if (info->toc_size) |
5048 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); | |
5049 | ||
4697a36c MM |
5050 | if (info->save_size) |
5051 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
5052 | ||
5053 | if (info->reg_size != 4) | |
5054 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
5055 | ||
5056 | fprintf (stderr, "\n"); | |
9878760c | 5057 | } |
4697a36c | 5058 | \f |
8cd8f856 GK |
5059 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
5060 | static void | |
5061 | rs6000_maybe_dead (insn) | |
5062 | rtx insn; | |
5063 | { | |
5064 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
5065 | const0_rtx, | |
5066 | REG_NOTES (insn)); | |
5067 | } | |
5068 | ||
9ebbca7d | 5069 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 5070 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 5071 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
5072 | |
5073 | void | |
9ebbca7d GK |
5074 | rs6000_emit_load_toc_table (fromprolog) |
5075 | int fromprolog; | |
c7ca610e | 5076 | { |
9ebbca7d GK |
5077 | rtx dest; |
5078 | dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM); | |
c7ca610e | 5079 | |
9ebbca7d | 5080 | if (TARGET_ELF) |
c7ca610e | 5081 | { |
9ebbca7d GK |
5082 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
5083 | && flag_pic == 1) | |
38c1f2d7 | 5084 | { |
9ebbca7d GK |
5085 | rtx temp = (fromprolog |
5086 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
5087 | : gen_reg_rtx (Pmode)); | |
5088 | if (TARGET_32BIT) | |
8cd8f856 | 5089 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp))); |
9ebbca7d | 5090 | else |
8cd8f856 GK |
5091 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_di (temp))); |
5092 | rs6000_maybe_dead (emit_move_insn (dest, temp)); | |
38c1f2d7 | 5093 | } |
9ebbca7d GK |
5094 | else if (flag_pic == 2) |
5095 | { | |
5096 | char buf[30]; | |
5097 | rtx tempLR = (fromprolog | |
5098 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
5099 | : gen_reg_rtx (Pmode)); | |
5100 | rtx temp0 = (fromprolog | |
5101 | ? gen_rtx_REG (Pmode, 0) | |
5102 | : gen_reg_rtx (Pmode)); | |
5103 | rtx symF; | |
5104 | ||
5105 | /* possibly create the toc section */ | |
5106 | if (! toc_initialized) | |
5107 | { | |
5108 | toc_section (); | |
5109 | function_section (current_function_decl); | |
5110 | } | |
5111 | ||
5112 | if (fromprolog) | |
5113 | { | |
5114 | rtx symL; | |
5115 | ||
5116 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
5117 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1)); | |
38c1f2d7 | 5118 | |
9ebbca7d GK |
5119 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
5120 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1)); | |
38c1f2d7 | 5121 | |
8cd8f856 GK |
5122 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, |
5123 | symF))); | |
5124 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
5125 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
5126 | symL, | |
5127 | symF))); | |
9ebbca7d GK |
5128 | } |
5129 | else | |
5130 | { | |
5131 | rtx tocsym; | |
5132 | static int reload_toc_labelno = 0; | |
5133 | ||
5134 | tocsym = gen_rtx_SYMBOL_REF (Pmode, | |
5135 | ggc_alloc_string (toc_label_name, -1)); | |
38c1f2d7 | 5136 | |
9ebbca7d GK |
5137 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); |
5138 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1)); | |
5139 | ||
8cd8f856 GK |
5140 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR, |
5141 | symF, | |
5142 | tocsym))); | |
5143 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
5144 | rs6000_maybe_dead (emit_move_insn (temp0, | |
5145 | gen_rtx_MEM (Pmode, dest))); | |
9ebbca7d | 5146 | } |
8cd8f856 | 5147 | rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest))); |
9ebbca7d GK |
5148 | } |
5149 | else if (flag_pic == 0 && TARGET_MINIMAL_TOC) | |
5150 | { | |
5151 | /* This is for AIX code running in non-PIC ELF. */ | |
5152 | char buf[30]; | |
5153 | rtx realsym; | |
38c1f2d7 | 5154 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); |
9ebbca7d GK |
5155 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1)); |
5156 | ||
8cd8f856 GK |
5157 | rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym))); |
5158 | rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym))); | |
9ebbca7d GK |
5159 | } |
5160 | else | |
5161 | abort(); | |
5162 | } | |
5163 | else | |
5164 | { | |
5165 | if (TARGET_32BIT) | |
8cd8f856 | 5166 | rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest))); |
9ebbca7d | 5167 | else |
8cd8f856 | 5168 | rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest))); |
9ebbca7d GK |
5169 | } |
5170 | } | |
5171 | ||
5172 | int | |
5173 | get_TOC_alias_set () | |
5174 | { | |
5175 | static int set = -1; | |
5176 | if (set == -1) | |
5177 | set = new_alias_set (); | |
5178 | return set; | |
5179 | } | |
5180 | ||
5181 | /* This retuns nonzero if the current function uses the TOC. This is | |
5182 | determined by the presence of (unspec ... 7), which is generated by | |
5183 | the various load_toc_* patterns. */ | |
5184 | int | |
5185 | uses_TOC () | |
5186 | { | |
5187 | rtx insn; | |
38c1f2d7 | 5188 | |
9ebbca7d | 5189 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
2c3c49de | 5190 | if (INSN_P (insn)) |
9ebbca7d GK |
5191 | { |
5192 | rtx pat = PATTERN (insn); | |
5193 | int i; | |
5194 | ||
8cd8f856 | 5195 | if (GET_CODE (pat) == PARALLEL) |
9ebbca7d GK |
5196 | for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++) |
5197 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC | |
5198 | && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7) | |
5199 | return 1; | |
38c1f2d7 | 5200 | } |
9ebbca7d GK |
5201 | return 0; |
5202 | } | |
38c1f2d7 | 5203 | |
9ebbca7d GK |
5204 | rtx |
5205 | create_TOC_reference(symbol) | |
5206 | rtx symbol; | |
5207 | { | |
5208 | return gen_rtx_PLUS (Pmode, | |
5209 | gen_rtx_REG (Pmode, TOC_REGISTER), | |
5210 | gen_rtx_CONST (Pmode, | |
5211 | gen_rtx_MINUS (Pmode, symbol, | |
5212 | gen_rtx_SYMBOL_REF (Pmode, | |
5213 | ggc_alloc_string (toc_label_name, -1))))); | |
5214 | } | |
38c1f2d7 | 5215 | |
9ebbca7d GK |
5216 | #if TARGET_AIX |
5217 | /* __throw will restore its own return address to be the same as the | |
5218 | return address of the function that the throw is being made to. | |
5219 | This is unfortunate, because we want to check the original | |
5220 | return address to see if we need to restore the TOC. | |
5221 | So we have to squirrel it away here. | |
5222 | This is used only in compiling __throw and __rethrow. | |
c7ca610e | 5223 | |
9ebbca7d GK |
5224 | Most of this code should be removed by CSE. */ |
5225 | static rtx insn_after_throw; | |
c7ca610e | 5226 | |
9ebbca7d GK |
5227 | /* This does the saving... */ |
5228 | void | |
5229 | rs6000_aix_emit_builtin_unwind_init () | |
5230 | { | |
5231 | rtx mem; | |
5232 | rtx stack_top = gen_reg_rtx (Pmode); | |
5233 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
5234 | ||
5235 | insn_after_throw = gen_reg_rtx (SImode); | |
5236 | ||
5237 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
5238 | emit_move_insn (stack_top, mem); | |
5239 | ||
5240 | mem = gen_rtx_MEM (Pmode, | |
5241 | gen_rtx_PLUS (Pmode, stack_top, | |
5242 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); | |
5243 | emit_move_insn (opcode_addr, mem); | |
5244 | emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr)); | |
c7ca610e RK |
5245 | } |
5246 | ||
9ebbca7d GK |
5247 | /* Emit insns to _restore_ the TOC register, at runtime (specifically in _eh.o). |
5248 | Only used on AIX. | |
5249 | ||
5250 | The idea is that on AIX, function calls look like this: | |
5251 | bl somefunction-trampoline | |
5252 | lwz r2,20(sp) | |
5253 | ||
5254 | and later, | |
5255 | somefunction-trampoline: | |
5256 | stw r2,20(sp) | |
5257 | ... load function address in the count register ... | |
5258 | bctr | |
5259 | or like this, if the linker determines that this is not a cross-module call | |
5260 | and so the TOC need not be restored: | |
5261 | bl somefunction | |
5262 | nop | |
5263 | or like this, if the compiler could determine that this is not a | |
5264 | cross-module call: | |
5265 | bl somefunction | |
5266 | now, the tricky bit here is that register 2 is saved and restored | |
5267 | by the _linker_, so we can't readily generate debugging information | |
5268 | for it. So we need to go back up the call chain looking at the | |
5269 | insns at return addresses to see which calls saved the TOC register | |
5270 | and so see where it gets restored from. | |
5271 | ||
5272 | Oh, and all this gets done in RTL inside the eh_epilogue pattern, | |
5273 | just before the actual epilogue. | |
5274 | ||
5275 | On the bright side, this incurs no space or time overhead unless an | |
5276 | exception is thrown, except for the extra code in libgcc.a. | |
5277 | ||
5278 | The parameter STACKSIZE is a register containing (at runtime) | |
5279 | the amount to be popped off the stack in addition to the stack frame | |
5280 | of this routine (which will be __throw or __rethrow, and so is | |
5281 | guaranteed to have a stack frame). */ | |
5282 | void | |
5283 | rs6000_emit_eh_toc_restore (stacksize) | |
5284 | rtx stacksize; | |
5285 | { | |
5286 | rtx top_of_stack; | |
5287 | rtx bottom_of_stack = gen_reg_rtx (Pmode); | |
5288 | rtx tocompare = gen_reg_rtx (SImode); | |
5289 | rtx opcode = gen_reg_rtx (SImode); | |
5290 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
5291 | rtx mem; | |
5292 | rtx loop_start = gen_label_rtx (); | |
5293 | rtx no_toc_restore_needed = gen_label_rtx (); | |
5294 | rtx loop_exit = gen_label_rtx (); | |
5295 | ||
5296 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
5297 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5298 | emit_move_insn (bottom_of_stack, mem); | |
5299 | ||
5300 | top_of_stack = expand_binop (Pmode, add_optab, | |
5301 | bottom_of_stack, stacksize, | |
5302 | NULL_RTX, 1, OPTAB_WIDEN); | |
5303 | ||
5304 | emit_move_insn (tocompare, | |
5305 | GEN_INT (trunc_int_for_mode (TARGET_32BIT | |
5306 | ? 0x80410014 | |
5307 | : 0xE8410028, SImode))); | |
5308 | ||
5309 | if (insn_after_throw == NULL_RTX) | |
5310 | abort(); | |
5311 | emit_move_insn (opcode, insn_after_throw); | |
5312 | ||
5313 | emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG); | |
5314 | emit_label (loop_start); | |
5315 | ||
5316 | do_compare_rtx_and_jump (opcode, tocompare, NE, 1, | |
5317 | SImode, NULL_RTX, 0, NULL_RTX, | |
5318 | no_toc_restore_needed); | |
5319 | ||
5320 | mem = gen_rtx_MEM (Pmode, | |
5321 | gen_rtx_PLUS (Pmode, bottom_of_stack, | |
5322 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
5323 | emit_move_insn (gen_rtx_REG (Pmode, 2), mem); | |
5324 | ||
5325 | emit_label (no_toc_restore_needed); | |
5326 | do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1, | |
5327 | Pmode, NULL_RTX, 0, NULL_RTX, | |
5328 | loop_exit); | |
5329 | ||
5330 | mem = gen_rtx_MEM (Pmode, bottom_of_stack); | |
5331 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5332 | emit_move_insn (bottom_of_stack, mem); | |
5333 | ||
5334 | mem = gen_rtx_MEM (Pmode, | |
5335 | gen_rtx_PLUS (Pmode, bottom_of_stack, | |
5336 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); | |
5337 | emit_move_insn (opcode_addr, mem); | |
5338 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); | |
5339 | ||
5340 | emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT); | |
5341 | emit_jump (loop_start); | |
5342 | emit_note (NULL_PTR, NOTE_INSN_LOOP_END); | |
5343 | emit_label (loop_exit); | |
5344 | } | |
5345 | #endif /* TARGET_AIX */ | |
38c1f2d7 | 5346 | \f |
9ebbca7d GK |
5347 | /* This ties together stack memory |
5348 | (MEM with an alias set of rs6000_sr_alias_set) | |
5349 | and the change to the stack pointer. */ | |
5350 | static void | |
5351 | rs6000_emit_stack_tie () | |
5352 | { | |
5353 | rtx mem; | |
5354 | mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); | |
5355 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5356 | emit_insn (gen_stack_tie (mem)); | |
5357 | } | |
38c1f2d7 | 5358 | |
9ebbca7d GK |
5359 | /* Emit the correct code for allocating stack space, as insns. |
5360 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
5361 | The generated code may use hard register 0 as a temporary. */ | |
5362 | ||
5363 | static void | |
5364 | rs6000_emit_allocate_stack (size, copy_r12) | |
5365 | HOST_WIDE_INT size; | |
38c1f2d7 MM |
5366 | int copy_r12; |
5367 | { | |
9ebbca7d GK |
5368 | rtx insn; |
5369 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
5370 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
5371 | rtx todec = GEN_INT (-size); | |
a157febd GK |
5372 | |
5373 | if (current_function_limit_stack) | |
5374 | { | |
5375 | if (REG_P (stack_limit_rtx) | |
5376 | && REGNO (stack_limit_rtx) > 1 | |
5377 | && REGNO (stack_limit_rtx) <= 31) | |
5378 | { | |
9ebbca7d GK |
5379 | emit_insn (Pmode == SImode |
5380 | ? gen_addsi3 (tmp_reg, | |
5381 | stack_limit_rtx, | |
5382 | GEN_INT (size)) | |
5383 | : gen_adddi3 (tmp_reg, | |
5384 | stack_limit_rtx, | |
5385 | GEN_INT (size))); | |
5386 | ||
5387 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
5388 | const0_rtx)); | |
a157febd GK |
5389 | } |
5390 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 5391 | && TARGET_32BIT |
a157febd GK |
5392 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)) |
5393 | { | |
9ebbca7d GK |
5394 | rtx toload = gen_rtx_CONST (VOIDmode, |
5395 | gen_rtx_PLUS (Pmode, | |
5396 | stack_limit_rtx, | |
5397 | GEN_INT (size))); | |
5398 | ||
5399 | emit_insn (gen_elf_high (tmp_reg, toload)); | |
5400 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
5401 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
5402 | const0_rtx)); | |
a157febd GK |
5403 | } |
5404 | else | |
5405 | warning ("stack limit expression is not supported"); | |
5406 | } | |
5407 | ||
9ebbca7d GK |
5408 | if (copy_r12 || ! TARGET_UPDATE) |
5409 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
5410 | ||
38c1f2d7 MM |
5411 | if (TARGET_UPDATE) |
5412 | { | |
9ebbca7d | 5413 | if (size > 32767) |
38c1f2d7 | 5414 | { |
9ebbca7d GK |
5415 | /* Need a note here so that try_split doesn't get confused. */ |
5416 | if (get_last_insn() == NULL_RTX) | |
5417 | emit_note (0, NOTE_INSN_DELETED); | |
5418 | insn = emit_move_insn (tmp_reg, todec); | |
5419 | try_split (PATTERN (insn), insn, 0); | |
5420 | todec = tmp_reg; | |
38c1f2d7 | 5421 | } |
9ebbca7d GK |
5422 | |
5423 | if (Pmode == SImode) | |
5424 | insn = emit_insn (gen_movsi_update (stack_reg, stack_reg, | |
5425 | todec, stack_reg)); | |
5426 | else | |
5427 | insn = emit_insn (gen_movdi_update (stack_reg, stack_reg, | |
5428 | todec, stack_reg)); | |
38c1f2d7 MM |
5429 | } |
5430 | else | |
5431 | { | |
9ebbca7d GK |
5432 | if (Pmode == SImode) |
5433 | insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec)); | |
38c1f2d7 | 5434 | else |
9ebbca7d GK |
5435 | insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec)); |
5436 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), | |
5437 | gen_rtx_REG (Pmode, 12)); | |
5438 | } | |
5439 | ||
5440 | RTX_FRAME_RELATED_P (insn) = 1; | |
5441 | REG_NOTES (insn) = | |
5442 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
5443 | gen_rtx_SET (VOIDmode, stack_reg, | |
5444 | gen_rtx_PLUS (Pmode, stack_reg, | |
5445 | GEN_INT (-size))), | |
5446 | REG_NOTES (insn)); | |
5447 | } | |
5448 | ||
5449 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced with | |
5450 | (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 is not | |
5451 | NULL. | |
5452 | It would be nice if dwarf2out_frame_debug_expr could deduce these | |
5453 | equivalences by itself so it wasn't necessary to hold its hand so much. */ | |
5454 | ||
5455 | static void | |
5456 | rs6000_frame_related (insn, reg, val, reg2, rreg) | |
5457 | rtx insn; | |
5458 | rtx reg; | |
5459 | HOST_WIDE_INT val; | |
5460 | rtx reg2; | |
5461 | rtx rreg; | |
5462 | { | |
5463 | rtx real, temp; | |
5464 | ||
5465 | real = copy_rtx (PATTERN (insn)); | |
5466 | ||
5467 | real = replace_rtx (real, reg, | |
5468 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, | |
5469 | STACK_POINTER_REGNUM), | |
5470 | GEN_INT (val))); | |
5471 | ||
5472 | /* We expect that 'real' is either a SET or a PARALLEL containing | |
5473 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
5474 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
5475 | ||
5476 | if (GET_CODE (real) == SET) | |
5477 | { | |
5478 | rtx set = real; | |
5479 | ||
5480 | temp = simplify_rtx (SET_SRC (set)); | |
5481 | if (temp) | |
5482 | SET_SRC (set) = temp; | |
5483 | temp = simplify_rtx (SET_DEST (set)); | |
5484 | if (temp) | |
5485 | SET_DEST (set) = temp; | |
5486 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 5487 | { |
9ebbca7d GK |
5488 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
5489 | if (temp) | |
5490 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 5491 | } |
38c1f2d7 | 5492 | } |
9ebbca7d GK |
5493 | else if (GET_CODE (real) == PARALLEL) |
5494 | { | |
5495 | int i; | |
5496 | for (i = 0; i < XVECLEN (real, 0); i++) | |
5497 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
5498 | { | |
5499 | rtx set = XVECEXP (real, 0, i); | |
5500 | ||
5501 | temp = simplify_rtx (SET_SRC (set)); | |
5502 | if (temp) | |
5503 | SET_SRC (set) = temp; | |
5504 | temp = simplify_rtx (SET_DEST (set)); | |
5505 | if (temp) | |
5506 | SET_DEST (set) = temp; | |
5507 | if (GET_CODE (SET_DEST (set)) == MEM) | |
5508 | { | |
5509 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
5510 | if (temp) | |
5511 | XEXP (SET_DEST (set), 0) = temp; | |
5512 | } | |
5513 | RTX_FRAME_RELATED_P (set) = 1; | |
5514 | } | |
5515 | } | |
5516 | else | |
5517 | abort(); | |
5518 | ||
5519 | if (reg2 != NULL_RTX) | |
5520 | real = replace_rtx (real, reg2, rreg); | |
5521 | ||
5522 | RTX_FRAME_RELATED_P (insn) = 1; | |
5523 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
5524 | real, | |
5525 | REG_NOTES (insn)); | |
38c1f2d7 MM |
5526 | } |
5527 | ||
9ebbca7d GK |
5528 | /* Emit function prologue as insns. */ |
5529 | ||
9878760c | 5530 | void |
9ebbca7d | 5531 | rs6000_emit_prologue() |
9878760c | 5532 | { |
4697a36c | 5533 | rs6000_stack_t *info = rs6000_stack_info (); |
9ebbca7d GK |
5534 | enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode; |
5535 | int reg_size = TARGET_POWERPC64 ? 8 : 4; | |
5536 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
5537 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
5538 | rtx frame_reg_rtx = sp_reg_rtx; | |
5539 | rtx cr_save_rtx = NULL; | |
5540 | rtx insn; | |
5541 | int saving_FPRs_inline; | |
5542 | int using_store_multiple; | |
5543 | HOST_WIDE_INT sp_offset = 0; | |
5544 | ||
5545 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 | |
5546 | && info->first_gp_reg_save < 31); | |
5547 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
5548 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
5549 | ||
5550 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
5551 | if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)) | |
5552 | { | |
5553 | if (info->total_size < 32767) | |
5554 | sp_offset = info->total_size; | |
5555 | else | |
5556 | frame_reg_rtx = frame_ptr_rtx; | |
5557 | rs6000_emit_allocate_stack (info->total_size, | |
5558 | (frame_reg_rtx != sp_reg_rtx | |
5559 | && (info->cr_save_p | |
5560 | || info->lr_save_p | |
5561 | || info->first_fp_reg_save < 64 | |
5562 | || info->first_gp_reg_save < 32 | |
5563 | ))); | |
5564 | if (frame_reg_rtx != sp_reg_rtx) | |
5565 | rs6000_emit_stack_tie (); | |
5566 | } | |
5567 | ||
5568 | /* If we use the link register, get it into r0. */ | |
5569 | if (info->lr_save_p) | |
5570 | emit_move_insn (gen_rtx_REG (Pmode, 0), | |
5571 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
5572 | ||
5573 | /* If we need to save CR, put it into r12. */ | |
5574 | if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) | |
5575 | { | |
5576 | cr_save_rtx = gen_rtx_REG (SImode, 12); | |
5577 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
5578 | } | |
5579 | ||
5580 | /* Do any required saving of fpr's. If only one or two to save, do it | |
5581 | ourself. Otherwise, call function. */ | |
5582 | if (saving_FPRs_inline) | |
5583 | { | |
5584 | int i; | |
5585 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
5586 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
5587 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
5588 | { | |
5589 | rtx addr, reg, mem; | |
5590 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
5591 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5592 | GEN_INT (info->fp_save_offset | |
5593 | + sp_offset | |
5594 | + 8*i)); | |
5595 | mem = gen_rtx_MEM (DFmode, addr); | |
5596 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5597 | ||
5598 | insn = emit_move_insn (mem, reg); | |
5599 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
5600 | NULL_RTX, NULL_RTX); | |
5601 | } | |
5602 | } | |
5603 | else if (info->first_fp_reg_save != 64) | |
5604 | { | |
5605 | int i; | |
5606 | char rname[30]; | |
520a57c8 | 5607 | const char *alloc_rname; |
9ebbca7d GK |
5608 | rtvec p; |
5609 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
5610 | ||
5611 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
5612 | gen_rtx_REG (Pmode, | |
5613 | LINK_REGISTER_REGNUM)); | |
5614 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
5615 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
5616 | alloc_rname = ggc_alloc_string (rname, -1); | |
5617 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
5618 | gen_rtx_SYMBOL_REF (Pmode, | |
5619 | alloc_rname)); | |
5620 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
5621 | { | |
5622 | rtx addr, reg, mem; | |
5623 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
5624 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5625 | GEN_INT (info->fp_save_offset | |
5626 | + sp_offset + 8*i)); | |
5627 | mem = gen_rtx_MEM (DFmode, addr); | |
5628 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5629 | ||
5630 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
5631 | } | |
5632 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
5633 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
5634 | NULL_RTX, NULL_RTX); | |
5635 | } | |
b6c9286a | 5636 | |
9ebbca7d GK |
5637 | /* Save GPRs. This is done as a PARALLEL if we are using |
5638 | the store-multiple instructions. */ | |
5639 | if (using_store_multiple) | |
b6c9286a | 5640 | { |
9ebbca7d GK |
5641 | rtvec p, dwarfp; |
5642 | int i; | |
5643 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
5644 | dwarfp = rtvec_alloc (32 - info->first_gp_reg_save); | |
5645 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
5646 | { | |
5647 | rtx addr, reg, mem; | |
5648 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
5649 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5650 | GEN_INT (info->gp_save_offset | |
5651 | + sp_offset | |
5652 | + reg_size * i)); | |
5653 | mem = gen_rtx_MEM (reg_mode, addr); | |
5654 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5655 | ||
5656 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
5657 | } | |
5658 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
5659 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
5660 | NULL_RTX, NULL_RTX); | |
b6c9286a MM |
5661 | } |
5662 | else | |
5663 | { | |
9ebbca7d GK |
5664 | int i; |
5665 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
5666 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
5667 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
5668 | || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM | |
5669 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
5670 | && flag_pic == 1)) | |
5671 | { | |
5672 | rtx addr, reg, mem; | |
5673 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
5674 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5675 | GEN_INT (info->gp_save_offset | |
5676 | + sp_offset | |
5677 | + reg_size * i)); | |
5678 | mem = gen_rtx_MEM (reg_mode, addr); | |
5679 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5680 | ||
5681 | insn = emit_move_insn (mem, reg); | |
5682 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
5683 | NULL_RTX, NULL_RTX); | |
5684 | } | |
5685 | } | |
5686 | ||
5687 | /* Save lr if we used it. */ | |
5688 | if (info->lr_save_p) | |
5689 | { | |
5690 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5691 | GEN_INT (info->lr_save_offset + sp_offset)); | |
5692 | rtx reg = gen_rtx_REG (Pmode, 0); | |
5693 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
5694 | /* This should not be of rs6000_sr_alias_set, because of | |
5695 | __builtin_return_address. */ | |
5696 | ||
5697 | insn = emit_move_insn (mem, reg); | |
5698 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
5699 | reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
5700 | } | |
5701 | ||
5702 | /* Save CR if we use any that must be preserved. */ | |
5703 | if (info->cr_save_p) | |
5704 | { | |
5705 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5706 | GEN_INT (info->cr_save_offset + sp_offset)); | |
5707 | rtx mem = gen_rtx_MEM (SImode, addr); | |
5708 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5709 | ||
5710 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
5711 | that it's free. */ | |
5712 | if (REGNO (frame_reg_rtx) == 12) | |
5713 | { | |
5714 | cr_save_rtx = gen_rtx_REG (SImode, 0); | |
5715 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
5716 | } | |
5717 | insn = emit_move_insn (mem, cr_save_rtx); | |
5718 | ||
5719 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
5720 | to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's | |
5721 | OK. All we have to do is specify that _one_ condition code | |
5722 | register is saved in this stack slot. The thrower's epilogue | |
5723 | will then restore all the call-saved registers. */ | |
5724 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
5725 | cr_save_rtx, gen_rtx_REG (SImode, CR0_REGNO)); | |
5726 | } | |
5727 | ||
5728 | /* Update stack and set back pointer unless this is V.4, | |
5729 | for which it was done previously. */ | |
5730 | if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) | |
5731 | rs6000_emit_allocate_stack (info->total_size, FALSE); | |
5732 | ||
5733 | /* Set frame pointer, if needed. */ | |
5734 | if (frame_pointer_needed) | |
5735 | { | |
5736 | insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM), | |
5737 | sp_reg_rtx); | |
5738 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 5739 | } |
9878760c | 5740 | |
9ebbca7d GK |
5741 | /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
5742 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) | |
5743 | || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
5744 | && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])) | |
5745 | { | |
5746 | /* If emit_load_toc_table will use the link register, we need to save | |
5747 | it. We use R11 for this purpose because emit_load_toc_table | |
5748 | can use register 0. This allows us to use a plain 'blr' to return | |
5749 | from the procedure more often. */ | |
5750 | int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0 && | |
5751 | ! info->lr_save_p); | |
5752 | if (save_LR_around_toc_setup) | |
5753 | emit_move_insn (gen_rtx_REG (Pmode, 11), | |
5754 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
5755 | ||
5756 | rs6000_emit_load_toc_table (TRUE); | |
5757 | ||
5758 | if (save_LR_around_toc_setup) | |
5759 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), | |
5760 | gen_rtx_REG (Pmode, 11)); | |
5761 | } | |
5762 | } | |
5763 | ||
5764 | ||
5765 | /* Write function prologue. */ | |
5766 | void | |
5767 | output_prolog (file, size) | |
5768 | FILE *file; | |
5769 | int size ATTRIBUTE_UNUSED; | |
5770 | { | |
5771 | rs6000_stack_t *info = rs6000_stack_info (); | |
5772 | ||
4697a36c MM |
5773 | if (TARGET_DEBUG_STACK) |
5774 | debug_stack_info (info); | |
9878760c RK |
5775 | |
5776 | /* Write .extern for any function we will call to save and restore fp | |
5777 | values. */ | |
b6c9286a | 5778 | if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save)) |
4d30c363 | 5779 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c MM |
5780 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
5781 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
9878760c | 5782 | |
c764f757 RK |
5783 | /* Write .extern for AIX common mode routines, if needed. */ |
5784 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
5785 | { | |
f6709c70 JW |
5786 | fputs ("\t.extern __mulh\n", file); |
5787 | fputs ("\t.extern __mull\n", file); | |
5788 | fputs ("\t.extern __divss\n", file); | |
5789 | fputs ("\t.extern __divus\n", file); | |
5790 | fputs ("\t.extern __quoss\n", file); | |
5791 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
5792 | common_mode_defined = 1; |
5793 | } | |
9878760c | 5794 | |
9ebbca7d | 5795 | if (! HAVE_prologue) |
979721f8 | 5796 | { |
9ebbca7d GK |
5797 | start_sequence (); |
5798 | ||
5799 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
5800 | and end of the "toplevel" insn chain. */ | |
5801 | emit_note (0, NOTE_INSN_DELETED); | |
5802 | rs6000_emit_prologue (); | |
5803 | emit_note (0, NOTE_INSN_DELETED); | |
5804 | ||
5805 | if (TARGET_DEBUG_STACK) | |
5806 | debug_rtx_list (get_insns(), 100); | |
5807 | final (get_insns(), file, FALSE, FALSE); | |
5808 | end_sequence (); | |
979721f8 MM |
5809 | } |
5810 | ||
9ebbca7d GK |
5811 | rs6000_pic_labelno++; |
5812 | } | |
5813 | ||
5814 | /* Emit function epilogue as insns. | |
9878760c | 5815 | |
9ebbca7d GK |
5816 | At present, dwarf2out_frame_debug_expr doesn't understand |
5817 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
5818 | anywhere in the epilogue. Most of the insns below would in any case | |
5819 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 5820 | |
9ebbca7d GK |
5821 | void |
5822 | rs6000_emit_epilogue(sibcall) | |
5823 | int sibcall; | |
5824 | { | |
5825 | rs6000_stack_t *info; | |
5826 | int restoring_FPRs_inline; | |
5827 | int using_load_multiple; | |
5828 | int using_mfcr_multiple; | |
5829 | int use_backchain_to_restore_sp; | |
5830 | int sp_offset = 0; | |
5831 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
5832 | rtx frame_reg_rtx = sp_reg_rtx; | |
5833 | enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode; | |
5834 | int reg_size = TARGET_POWERPC64 ? 8 : 4; | |
5835 | int i; | |
5836 | ||
5837 | info = rs6000_stack_info (); | |
5838 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 | |
5839 | && info->first_gp_reg_save < 31); | |
5840 | restoring_FPRs_inline = (sibcall | |
5841 | || info->first_fp_reg_save == 64 | |
5842 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
5843 | use_backchain_to_restore_sp = (frame_pointer_needed | |
5844 | || current_function_calls_alloca | |
5845 | || info->total_size > 32767); | |
5846 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
5847 | || rs6000_cpu == PROCESSOR_PPC603 | |
5848 | || rs6000_cpu == PROCESSOR_PPC750 | |
5849 | || optimize_size); | |
5850 | ||
5851 | /* If we have a frame pointer, a call to alloca, or a large stack | |
5852 | frame, restore the old stack pointer using the backchain. Otherwise, | |
5853 | we know what size to update it with. */ | |
5854 | if (use_backchain_to_restore_sp) | |
bacbde18 | 5855 | { |
9ebbca7d GK |
5856 | /* Under V.4, don't reset the stack pointer until after we're done |
5857 | loading the saved registers. */ | |
5858 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
5859 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); | |
4697a36c | 5860 | |
9ebbca7d GK |
5861 | emit_move_insn (frame_reg_rtx, |
5862 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
5863 | ||
bacbde18 | 5864 | } |
9ebbca7d | 5865 | else if (info->push_p) |
85638c0d | 5866 | { |
9ebbca7d GK |
5867 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
5868 | sp_offset = info->total_size; | |
5869 | else | |
5870 | { | |
5871 | emit_insn (TARGET_32BIT | |
5872 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
5873 | GEN_INT (info->total_size)) | |
5874 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
5875 | GEN_INT (info->total_size))); | |
5876 | } | |
85638c0d | 5877 | } |
9ebbca7d GK |
5878 | |
5879 | /* Get the old lr if we saved it. */ | |
5880 | if (info->lr_save_p) | |
b6c9286a | 5881 | { |
9ebbca7d GK |
5882 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
5883 | GEN_INT (info->lr_save_offset + sp_offset)); | |
5884 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
5885 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
b6c9286a | 5886 | |
9ebbca7d | 5887 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 5888 | } |
9ebbca7d GK |
5889 | |
5890 | /* Get the old cr if we saved it. */ | |
5891 | if (info->cr_save_p) | |
5892 | { | |
5893 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5894 | GEN_INT (info->cr_save_offset + sp_offset)); | |
5895 | rtx mem = gen_rtx_MEM (SImode, addr); | |
5896 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
b6c9286a | 5897 | |
9ebbca7d GK |
5898 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
5899 | } | |
5900 | ||
5901 | /* Set LR here to try to overlap restores below. */ | |
4697a36c | 5902 | if (info->lr_save_p) |
9ebbca7d GK |
5903 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
5904 | gen_rtx_REG (Pmode, 0)); | |
5905 | ||
5906 | ||
5907 | /* Restore GPRs. This is done as a PARALLEL if we are using | |
5908 | the load-multiple instructions. */ | |
5909 | if (using_load_multiple) | |
979721f8 | 5910 | { |
9ebbca7d GK |
5911 | rtvec p; |
5912 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
5913 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 5914 | { |
9ebbca7d GK |
5915 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
5916 | GEN_INT (info->gp_save_offset | |
5917 | + sp_offset | |
5918 | + reg_size * i)); | |
5919 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
5920 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5921 | ||
5922 | RTVEC_ELT (p, i) = | |
5923 | gen_rtx_SET (VOIDmode, | |
5924 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
5925 | mem); | |
979721f8 | 5926 | } |
9ebbca7d | 5927 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 5928 | } |
9ebbca7d GK |
5929 | else |
5930 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
5931 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
5932 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
5933 | || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM | |
5934 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
5935 | && flag_pic == 1)) | |
5936 | { | |
5937 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5938 | GEN_INT (info->gp_save_offset | |
5939 | + sp_offset | |
5940 | + reg_size * i)); | |
5941 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
5942 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5943 | ||
5944 | emit_move_insn (gen_rtx_REG (reg_mode, | |
5945 | info->first_gp_reg_save + i), | |
5946 | mem); | |
5947 | } | |
9878760c | 5948 | |
9ebbca7d GK |
5949 | /* Restore fpr's if we need to do it without calling a function. */ |
5950 | if (restoring_FPRs_inline) | |
5951 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
5952 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
5953 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
5954 | { | |
5955 | rtx addr, mem; | |
5956 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
5957 | GEN_INT (info->fp_save_offset | |
5958 | + sp_offset | |
5959 | + 8*i)); | |
5960 | mem = gen_rtx_MEM (DFmode, addr); | |
5961 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
5962 | ||
5963 | emit_move_insn (gen_rtx_REG (DFmode, | |
5964 | info->first_fp_reg_save + i), | |
5965 | mem); | |
5966 | } | |
8d30c4ee | 5967 | |
9ebbca7d GK |
5968 | /* If we saved cr, restore it here. Just those that were used. */ |
5969 | if (info->cr_save_p) | |
979721f8 | 5970 | { |
9ebbca7d | 5971 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 5972 | int count = 0; |
9ebbca7d GK |
5973 | |
5974 | if (using_mfcr_multiple) | |
979721f8 | 5975 | { |
9ebbca7d GK |
5976 | for (i = 0; i < 8; i++) |
5977 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 5978 | count++; |
9ebbca7d | 5979 | if (count == 0) |
e35b9579 GK |
5980 | abort (); |
5981 | } | |
5982 | ||
5983 | if (using_mfcr_multiple && count > 1) | |
5984 | { | |
5985 | rtvec p; | |
5986 | int ndx; | |
9ebbca7d | 5987 | |
e35b9579 | 5988 | p = rtvec_alloc (count); |
9ebbca7d | 5989 | |
e35b9579 | 5990 | ndx = 0; |
9ebbca7d GK |
5991 | for (i = 0; i < 8; i++) |
5992 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
5993 | { | |
5994 | rtvec r = rtvec_alloc (2); | |
5995 | RTVEC_ELT (r, 0) = r12_rtx; | |
5996 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 5997 | RTVEC_ELT (p, ndx) = |
9ebbca7d GK |
5998 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
5999 | gen_rtx_UNSPEC (CCmode, r, 20)); | |
e35b9579 | 6000 | ndx++; |
9ebbca7d GK |
6001 | } |
6002 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
6003 | if (ndx != count) |
6004 | abort (); | |
979721f8 MM |
6005 | } |
6006 | else | |
9ebbca7d GK |
6007 | for (i = 0; i < 8; i++) |
6008 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 6009 | { |
9ebbca7d GK |
6010 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
6011 | CR0_REGNO+i), | |
6012 | r12_rtx)); | |
979721f8 | 6013 | } |
979721f8 MM |
6014 | } |
6015 | ||
9ebbca7d GK |
6016 | /* If this is V.4, unwind the stack pointer after all of the loads |
6017 | have been done. We need to emit a block here so that sched | |
6018 | doesn't decide to move the sp change before the register restores | |
6019 | (which may not have any obvious dependency on the stack). This | |
6020 | doesn't hurt performance, because there is no scheduling that can | |
6021 | be done after this point. */ | |
6022 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
b6c9286a | 6023 | { |
9ebbca7d GK |
6024 | if (frame_reg_rtx != sp_reg_rtx) |
6025 | rs6000_emit_stack_tie (); | |
b6c9286a | 6026 | |
9ebbca7d | 6027 | if (use_backchain_to_restore_sp) |
b6c9286a | 6028 | { |
9ebbca7d | 6029 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 6030 | } |
9ebbca7d | 6031 | else if (sp_offset != 0) |
13f1623b | 6032 | { |
9ebbca7d GK |
6033 | emit_insn (Pmode == SImode |
6034 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
6035 | GEN_INT (sp_offset)) | |
6036 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
6037 | GEN_INT (sp_offset))); | |
13f1623b | 6038 | } |
9ebbca7d | 6039 | } |
b6c9286a | 6040 | |
9ebbca7d GK |
6041 | if (!sibcall) |
6042 | { | |
6043 | rtvec p; | |
6044 | if (! restoring_FPRs_inline) | |
6045 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
6046 | else | |
6047 | p = rtvec_alloc (2); | |
b6c9286a | 6048 | |
e35b9579 GK |
6049 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
6050 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
9ebbca7d GK |
6051 | gen_rtx_REG (Pmode, |
6052 | LINK_REGISTER_REGNUM)); | |
9ebbca7d GK |
6053 | |
6054 | /* If we have to restore more than two FP registers, branch to the | |
6055 | restore function. It will return to our caller. */ | |
6056 | if (! restoring_FPRs_inline) | |
6057 | { | |
6058 | int i; | |
6059 | char rname[30]; | |
520a57c8 | 6060 | const char *alloc_rname; |
979721f8 | 6061 | |
9ebbca7d GK |
6062 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
6063 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
6064 | alloc_rname = ggc_alloc_string (rname, -1); | |
6065 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, | |
6066 | gen_rtx_SYMBOL_REF (Pmode, | |
6067 | alloc_rname)); | |
b6c9286a | 6068 | |
9ebbca7d GK |
6069 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
6070 | { | |
6071 | rtx addr, mem; | |
6072 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
6073 | GEN_INT (info->fp_save_offset + 8*i)); | |
6074 | mem = gen_rtx_MEM (DFmode, addr); | |
6075 | MEM_ALIAS_SET (mem) = rs6000_sr_alias_set; | |
6076 | ||
6077 | RTVEC_ELT (p, i+3) = | |
6078 | gen_rtx_SET (VOIDmode, | |
6079 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
6080 | mem); | |
b6c9286a MM |
6081 | } |
6082 | } | |
9ebbca7d GK |
6083 | |
6084 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
3daf36a4 | 6085 | } |
9878760c RK |
6086 | } |
6087 | ||
6088 | /* Write function epilogue. */ | |
6089 | ||
6090 | void | |
6091 | output_epilog (file, size) | |
6092 | FILE *file; | |
296b8152 | 6093 | int size ATTRIBUTE_UNUSED; |
9878760c | 6094 | { |
4697a36c | 6095 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 6096 | |
9ebbca7d | 6097 | if (! HAVE_epilogue) |
9878760c | 6098 | { |
9ebbca7d GK |
6099 | rtx insn = get_last_insn (); |
6100 | /* If the last insn was a BARRIER, we don't have to write anything except | |
6101 | the trace table. */ | |
6102 | if (GET_CODE (insn) == NOTE) | |
6103 | insn = prev_nonnote_insn (insn); | |
6104 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 6105 | { |
9ebbca7d GK |
6106 | /* This is slightly ugly, but at least we don't have two |
6107 | copies of the epilogue-emitting code. */ | |
6108 | start_sequence (); | |
6109 | ||
6110 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
6111 | and end of the "toplevel" insn chain. */ | |
6112 | emit_note (0, NOTE_INSN_DELETED); | |
6113 | rs6000_emit_epilogue (FALSE); | |
6114 | emit_note (0, NOTE_INSN_DELETED); | |
6115 | ||
6116 | if (TARGET_DEBUG_STACK) | |
6117 | debug_rtx_list (get_insns(), 100); | |
6118 | final (get_insns(), file, FALSE, FALSE); | |
6119 | end_sequence (); | |
4697a36c | 6120 | } |
9878760c | 6121 | } |
b4ac57ab | 6122 | |
9b30bae2 | 6123 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
6124 | on its format. |
6125 | ||
6126 | We don't output a traceback table if -finhibit-size-directive was | |
6127 | used. The documentation for -finhibit-size-directive reads | |
6128 | ``don't output a @code{.size} assembler directive, or anything | |
6129 | else that would cause trouble if the function is split in the | |
6130 | middle, and the two halves are placed at locations far apart in | |
6131 | memory.'' The traceback table has this property, since it | |
6132 | includes the offset from the start of the function to the | |
4d30c363 MM |
6133 | traceback table itself. |
6134 | ||
6135 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a MM |
6136 | different traceback table. */ |
6137 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive) | |
9b30bae2 | 6138 | { |
3cce094d | 6139 | const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); |
314fc5a9 ILT |
6140 | int fixed_parms, float_parms, parm_info; |
6141 | int i; | |
6142 | ||
b6c9286a MM |
6143 | while (*fname == '.') /* V.4 encodes . in the name */ |
6144 | fname++; | |
6145 | ||
314fc5a9 ILT |
6146 | /* Need label immediately before tbtab, so we can compute its offset |
6147 | from the function start. */ | |
6148 | if (*fname == '*') | |
6149 | ++fname; | |
6150 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
6151 | ASM_OUTPUT_LABEL (file, fname); | |
6152 | ||
6153 | /* The .tbtab pseudo-op can only be used for the first eight | |
6154 | expressions, since it can't handle the possibly variable | |
6155 | length fields that follow. However, if you omit the optional | |
6156 | fields, the assembler outputs zeros for all optional fields | |
6157 | anyways, giving each variable length field is minimum length | |
6158 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
6159 | pseudo-op at all. */ | |
6160 | ||
6161 | /* An all-zero word flags the start of the tbtab, for debuggers | |
6162 | that have to find it by searching forward from the entry | |
6163 | point or from the current pc. */ | |
19d2d16f | 6164 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
6165 | |
6166 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 6167 | fputs ("\t.byte 0,", file); |
314fc5a9 ILT |
6168 | |
6169 | /* Language type. Unfortunately, there doesn't seem to be any | |
6170 | official way to get this info, so we use language_string. C | |
6171 | is 0. C++ is 9. No number defined for Obj-C, so use the | |
9517ead8 | 6172 | value for C for now. There is no official value for Java, |
6f573ff9 JL |
6173 | although IBM appears to be using 13. There is no official value |
6174 | for Chill, so we've choosen 44 pseudo-randomly. */ | |
314fc5a9 | 6175 | if (! strcmp (language_string, "GNU C") |
e2c953b6 | 6176 | || ! strcmp (language_string, "GNU Objective-C")) |
314fc5a9 ILT |
6177 | i = 0; |
6178 | else if (! strcmp (language_string, "GNU F77")) | |
6179 | i = 1; | |
6180 | else if (! strcmp (language_string, "GNU Ada")) | |
6181 | i = 3; | |
8b83775b | 6182 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 ILT |
6183 | i = 2; |
6184 | else if (! strcmp (language_string, "GNU C++")) | |
6185 | i = 9; | |
9517ead8 AG |
6186 | else if (! strcmp (language_string, "GNU Java")) |
6187 | i = 13; | |
6f573ff9 JL |
6188 | else if (! strcmp (language_string, "GNU CHILL")) |
6189 | i = 44; | |
314fc5a9 ILT |
6190 | else |
6191 | abort (); | |
6192 | fprintf (file, "%d,", i); | |
6193 | ||
6194 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
6195 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
6196 | from start of procedure stored in tbtab, internal function, function | |
6197 | has controlled storage, function has no toc, function uses fp, | |
6198 | function logs/aborts fp operations. */ | |
6199 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
4697a36c | 6200 | fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1)); |
314fc5a9 ILT |
6201 | |
6202 | /* 6 bitfields: function is interrupt handler, name present in | |
6203 | proc table, function calls alloca, on condition directives | |
6204 | (controls stack walks, 3 bits), saves condition reg, saves | |
6205 | link reg. */ | |
6206 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
6207 | set up as a frame pointer, even when there is no alloca call. */ | |
6208 | fprintf (file, "%d,", | |
6209 | ((1 << 6) | (frame_pointer_needed << 5) | |
4697a36c | 6210 | | (info->cr_save_p << 1) | (info->lr_save_p))); |
314fc5a9 ILT |
6211 | |
6212 | /* 3 bitfields: saves backchain, spare bit, number of fpr saved | |
6213 | (6 bits). */ | |
6214 | fprintf (file, "%d,", | |
4697a36c | 6215 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
6216 | |
6217 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
6218 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
6219 | ||
6220 | { | |
6221 | /* Compute the parameter info from the function decl argument | |
6222 | list. */ | |
6223 | tree decl; | |
6224 | int next_parm_info_bit; | |
6225 | ||
6226 | next_parm_info_bit = 31; | |
6227 | parm_info = 0; | |
6228 | fixed_parms = 0; | |
6229 | float_parms = 0; | |
6230 | ||
6231 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
6232 | decl; decl = TREE_CHAIN (decl)) | |
6233 | { | |
6234 | rtx parameter = DECL_INCOMING_RTL (decl); | |
6235 | enum machine_mode mode = GET_MODE (parameter); | |
6236 | ||
6237 | if (GET_CODE (parameter) == REG) | |
6238 | { | |
6239 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
6240 | { | |
6241 | int bits; | |
6242 | ||
6243 | float_parms++; | |
6244 | ||
6245 | if (mode == SFmode) | |
6246 | bits = 0x2; | |
6247 | else if (mode == DFmode) | |
6248 | bits = 0x3; | |
6249 | else | |
6250 | abort (); | |
6251 | ||
6252 | /* If only one bit will fit, don't or in this entry. */ | |
6253 | if (next_parm_info_bit > 0) | |
6254 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
6255 | next_parm_info_bit -= 2; | |
6256 | } | |
6257 | else | |
6258 | { | |
6259 | fixed_parms += ((GET_MODE_SIZE (mode) | |
6260 | + (UNITS_PER_WORD - 1)) | |
6261 | / UNITS_PER_WORD); | |
6262 | next_parm_info_bit -= 1; | |
6263 | } | |
6264 | } | |
6265 | } | |
6266 | } | |
6267 | ||
6268 | /* Number of fixed point parameters. */ | |
6269 | /* This is actually the number of words of fixed point parameters; thus | |
6270 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
6271 | fprintf (file, "%d,", fixed_parms); | |
6272 | ||
6273 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
6274 | all on stack. */ | |
6275 | /* This is actually the number of fp registers that hold parameters; | |
6276 | and thus the maximum value is 13. */ | |
6277 | /* Set parameters on stack bit if parameters are not in their original | |
6278 | registers, regardless of whether they are on the stack? Xlc | |
6279 | seems to set the bit when not optimizing. */ | |
6280 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
6281 | ||
6282 | /* Optional fields follow. Some are variable length. */ | |
6283 | ||
6284 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
6285 | 11 double float. */ | |
6286 | /* There is an entry for each parameter in a register, in the order that | |
6287 | they occur in the parameter list. Any intervening arguments on the | |
6288 | stack are ignored. If the list overflows a long (max possible length | |
6289 | 34 bits) then completely leave off all elements that don't fit. */ | |
6290 | /* Only emit this long if there was at least one parameter. */ | |
6291 | if (fixed_parms || float_parms) | |
6292 | fprintf (file, "\t.long %d\n", parm_info); | |
6293 | ||
6294 | /* Offset from start of code to tb table. */ | |
19d2d16f | 6295 | fputs ("\t.long ", file); |
314fc5a9 | 6296 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
9ebbca7d | 6297 | #if TARGET_AIX |
314fc5a9 | 6298 | RS6000_OUTPUT_BASENAME (file, fname); |
9ebbca7d GK |
6299 | #else |
6300 | assemble_name (file, fname); | |
6301 | #endif | |
19d2d16f | 6302 | fputs ("-.", file); |
9ebbca7d | 6303 | #if TARGET_AIX |
314fc5a9 | 6304 | RS6000_OUTPUT_BASENAME (file, fname); |
9ebbca7d GK |
6305 | #else |
6306 | assemble_name (file, fname); | |
6307 | #endif | |
19d2d16f | 6308 | putc ('\n', file); |
314fc5a9 ILT |
6309 | |
6310 | /* Interrupt handler mask. */ | |
6311 | /* Omit this long, since we never set the interrupt handler bit | |
6312 | above. */ | |
6313 | ||
6314 | /* Number of CTL (controlled storage) anchors. */ | |
6315 | /* Omit this long, since the has_ctl bit is never set above. */ | |
6316 | ||
6317 | /* Displacement into stack of each CTL anchor. */ | |
6318 | /* Omit this list of longs, because there are no CTL anchors. */ | |
6319 | ||
6320 | /* Length of function name. */ | |
296b8152 | 6321 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
6322 | |
6323 | /* Function name. */ | |
6324 | assemble_string (fname, strlen (fname)); | |
6325 | ||
6326 | /* Register for alloca automatic storage; this is always reg 31. | |
6327 | Only emit this if the alloca bit was set above. */ | |
6328 | if (frame_pointer_needed) | |
19d2d16f | 6329 | fputs ("\t.byte 31\n", file); |
9b30bae2 | 6330 | } |
9878760c | 6331 | } |
17167fd8 MM |
6332 | \f |
6333 | /* A C compound statement that outputs the assembler code for a thunk function, | |
6334 | used to implement C++ virtual function calls with multiple inheritance. The | |
6335 | thunk acts as a wrapper around a virtual function, adjusting the implicit | |
6336 | object parameter before handing control off to the real function. | |
6337 | ||
6338 | First, emit code to add the integer DELTA to the location that contains the | |
6339 | incoming first argument. Assume that this argument contains a pointer, and | |
6340 | is the one used to pass the `this' pointer in C++. This is the incoming | |
6341 | argument *before* the function prologue, e.g. `%o0' on a sparc. The | |
6342 | addition must preserve the values of all other incoming arguments. | |
6343 | ||
6344 | After the addition, emit code to jump to FUNCTION, which is a | |
6345 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch | |
6346 | the return address. Hence returning from FUNCTION will return to whoever | |
6347 | called the current `thunk'. | |
6348 | ||
6349 | The effect must be as if FUNCTION had been called directly with the adjusted | |
6350 | first argument. This macro is responsible for emitting all of the code for | |
6351 | a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not | |
6352 | invoked. | |
6353 | ||
6354 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been | |
6355 | extracted from it.) It might possibly be useful on some targets, but | |
6356 | probably not. | |
6357 | ||
6358 | If you do not define this macro, the target-independent code in the C++ | |
6359 | frontend will generate a less efficient heavyweight thunk that calls | |
6360 | FUNCTION instead of jumping to it. The generic approach does not support | |
6361 | varargs. */ | |
6362 | ||
6363 | void | |
6364 | output_mi_thunk (file, thunk_fndecl, delta, function) | |
6365 | FILE *file; | |
d330fd93 | 6366 | tree thunk_fndecl ATTRIBUTE_UNUSED; |
17167fd8 MM |
6367 | int delta; |
6368 | tree function; | |
6369 | { | |
d330fd93 KG |
6370 | const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ]; |
6371 | const char *prefix; | |
3cce094d | 6372 | const char *fname; |
d330fd93 | 6373 | const char *r0 = reg_names[0]; |
d330fd93 KG |
6374 | const char *toc = reg_names[2]; |
6375 | const char *schain = reg_names[11]; | |
6376 | const char *r12 = reg_names[12]; | |
17167fd8 MM |
6377 | char buf[512]; |
6378 | static int labelno = 0; | |
6379 | ||
6380 | /* Small constants that can be done by one add instruction */ | |
6381 | if (delta >= -32768 && delta <= 32767) | |
6382 | { | |
22b4a3b0 | 6383 | if (! TARGET_NEW_MNEMONICS) |
17167fd8 MM |
6384 | fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg); |
6385 | else | |
6386 | fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta); | |
6387 | } | |
6388 | ||
6389 | /* Large constants that can be done by one addis instruction */ | |
6390 | else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1) | |
6391 | asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg, | |
6392 | delta >> 16); | |
6393 | ||
6394 | /* 32-bit constants that can be done by an add and addis instruction. */ | |
6395 | else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1) | |
6396 | { | |
22b4a3b0 | 6397 | /* Break into two pieces, propagating the sign bit from the low word to |
17167fd8 MM |
6398 | the upper word. */ |
6399 | int delta_high = delta >> 16; | |
6400 | int delta_low = delta & 0xffff; | |
6401 | if ((delta_low & 0x8000) != 0) | |
6402 | { | |
6403 | delta_high++; | |
6404 | delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */ | |
6405 | } | |
6406 | ||
6407 | asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg, | |
6408 | delta_high); | |
6409 | ||
22b4a3b0 | 6410 | if (! TARGET_NEW_MNEMONICS) |
17167fd8 MM |
6411 | fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg); |
6412 | else | |
6413 | fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low); | |
6414 | } | |
6415 | ||
6416 | /* 64-bit constants, fixme */ | |
6417 | else | |
6418 | abort (); | |
6419 | ||
6420 | /* Get the prefix in front of the names. */ | |
6421 | switch (DEFAULT_ABI) | |
6422 | { | |
6423 | default: | |
6424 | abort (); | |
6425 | ||
6426 | case ABI_AIX: | |
6427 | prefix = "."; | |
6428 | break; | |
6429 | ||
6430 | case ABI_V4: | |
6431 | case ABI_AIX_NODESC: | |
6432 | case ABI_SOLARIS: | |
6433 | prefix = ""; | |
6434 | break; | |
17167fd8 MM |
6435 | } |
6436 | ||
6437 | /* If the function is compiled in this module, jump to it directly. | |
6438 | Otherwise, load up its address and jump to it. */ | |
6439 | ||
6440 | fname = XSTR (XEXP (DECL_RTL (function), 0), 0); | |
42820a49 | 6441 | |
9ebbca7d | 6442 | if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode) |
22b4a3b0 FS |
6443 | && ! lookup_attribute ("longcall", |
6444 | TYPE_ATTRIBUTES (TREE_TYPE (function)))) | |
17167fd8 MM |
6445 | { |
6446 | fprintf (file, "\tb %s", prefix); | |
6447 | assemble_name (file, fname); | |
22b4a3b0 | 6448 | if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file); |
949ea356 | 6449 | putc ('\n', file); |
17167fd8 MM |
6450 | } |
6451 | ||
6452 | else | |
6453 | { | |
6454 | switch (DEFAULT_ABI) | |
6455 | { | |
6456 | default: | |
17167fd8 MM |
6457 | abort (); |
6458 | ||
6459 | case ABI_AIX: | |
6460 | /* Set up a TOC entry for the function. */ | |
6461 | ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno); | |
6462 | toc_section (); | |
6463 | ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno); | |
6464 | labelno++; | |
6465 | ||
6466 | /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since | |
6467 | there will be only one TOC entry for this function. */ | |
6468 | fputs ("\t.tc\t", file); | |
6469 | assemble_name (file, buf); | |
6470 | fputs ("[TC],", file); | |
6471 | assemble_name (file, buf); | |
6472 | putc ('\n', file); | |
6473 | text_section (); | |
6474 | asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12); | |
6475 | assemble_name (file, buf); | |
6476 | asm_fprintf (file, "(%s)\n", reg_names[2]); | |
6477 | asm_fprintf (file, | |
6478 | (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n", | |
6479 | r0, r12); | |
6480 | ||
6481 | asm_fprintf (file, | |
6482 | (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n", | |
6483 | toc, r12); | |
6484 | ||
6485 | asm_fprintf (file, "\tmtctr %s\n", r0); | |
6486 | asm_fprintf (file, | |
6487 | (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n", | |
6488 | schain, r12); | |
6489 | ||
6490 | asm_fprintf (file, "\tbctr\n"); | |
6491 | break; | |
6492 | ||
9ebbca7d GK |
6493 | case ABI_AIX_NODESC: |
6494 | case ABI_SOLARIS: | |
17167fd8 | 6495 | case ABI_V4: |
22b4a3b0 FS |
6496 | fprintf (file, "\tb %s", prefix); |
6497 | assemble_name (file, fname); | |
6498 | if (flag_pic) fputs ("@plt", file); | |
949ea356 | 6499 | putc ('\n', file); |
22b4a3b0 | 6500 | break; |
9ebbca7d GK |
6501 | } |
6502 | } | |
6503 | } | |
42820a49 | 6504 | |
9ebbca7d GK |
6505 | \f |
6506 | /* A quick summary of the various types of 'constant-pool tables' | |
6507 | under PowerPC: | |
6508 | ||
6509 | Target Flags Name One table per | |
6510 | AIX (none) AIX TOC object file | |
6511 | AIX -mfull-toc AIX TOC object file | |
6512 | AIX -mminimal-toc AIX minimal TOC translation unit | |
6513 | SVR4/EABI (none) SVR4 SDATA object file | |
6514 | SVR4/EABI -fpic SVR4 pic object file | |
6515 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
6516 | SVR4/EABI -mrelocatable EABI TOC function | |
6517 | SVR4/EABI -maix AIX TOC object file | |
6518 | SVR4/EABI -maix -mminimal-toc | |
6519 | AIX minimal TOC translation unit | |
6520 | ||
6521 | Name Reg. Set by entries contains: | |
6522 | made by addrs? fp? sum? | |
6523 | ||
6524 | AIX TOC 2 crt0 as Y option option | |
6525 | AIX minimal TOC 30 prolog gcc Y Y option | |
6526 | SVR4 SDATA 13 crt0 gcc N Y N | |
6527 | SVR4 pic 30 prolog ld Y not yet N | |
6528 | SVR4 PIC 30 prolog gcc Y option option | |
6529 | EABI TOC 30 prolog gcc Y option option | |
6530 | ||
6531 | */ | |
6532 | ||
6533 | /* Hash table stuff for keeping track of TOC entries. */ | |
6534 | ||
6535 | struct toc_hash_struct | |
6536 | { | |
6537 | /* `key' will satisfy CONSTANT_P; in fact, it will satisfy | |
6538 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */ | |
6539 | rtx key; | |
a9098fd0 | 6540 | enum machine_mode key_mode; |
9ebbca7d GK |
6541 | int labelno; |
6542 | }; | |
17167fd8 | 6543 | |
9ebbca7d GK |
6544 | static htab_t toc_hash_table; |
6545 | ||
6546 | /* Hash functions for the hash table. */ | |
6547 | ||
6548 | static unsigned | |
6549 | rs6000_hash_constant (k) | |
6550 | rtx k; | |
6551 | { | |
a9098fd0 | 6552 | unsigned result = (GET_CODE (k) << 3) ^ GET_MODE (k); |
9ebbca7d GK |
6553 | const char *format = GET_RTX_FORMAT (GET_CODE (k)); |
6554 | int flen = strlen (format); | |
6555 | int fidx; | |
6556 | ||
6557 | if (GET_CODE (k) == LABEL_REF) | |
832ea3b3 | 6558 | return result * 1231 + X0INT (XEXP (k, 0), 3); |
9ebbca7d GK |
6559 | |
6560 | if (GET_CODE (k) == CONST_DOUBLE) | |
6561 | fidx = 2; | |
6562 | else if (GET_CODE (k) == CODE_LABEL) | |
6563 | fidx = 3; | |
6564 | else | |
6565 | fidx = 0; | |
6566 | ||
6567 | for (; fidx < flen; fidx++) | |
6568 | switch (format[fidx]) | |
6569 | { | |
6570 | case 's': | |
6571 | { | |
6572 | unsigned i, len; | |
6573 | const char *str = XSTR (k, fidx); | |
6574 | len = strlen (str); | |
6575 | result = result * 613 + len; | |
6576 | for (i = 0; i < len; i++) | |
6577 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
6578 | break; |
6579 | } | |
9ebbca7d GK |
6580 | case 'u': |
6581 | case 'e': | |
6582 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
6583 | break; | |
6584 | case 'i': | |
6585 | case 'n': | |
6586 | result = result * 613 + (unsigned) XINT (k, fidx); | |
6587 | break; | |
6588 | case 'w': | |
6589 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
6590 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
6591 | else | |
6592 | { | |
6593 | size_t i; | |
6594 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
6595 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
6596 | >> CHAR_BIT * i); | |
6597 | } | |
6598 | break; | |
6599 | default: | |
6600 | abort(); | |
6601 | } | |
6602 | return result; | |
6603 | } | |
6604 | ||
6605 | static unsigned | |
6606 | toc_hash_function (hash_entry) | |
6607 | const void * hash_entry; | |
6608 | { | |
a9098fd0 GK |
6609 | const struct toc_hash_struct *thc = |
6610 | (const struct toc_hash_struct *) hash_entry; | |
6611 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
6612 | } |
6613 | ||
6614 | /* Compare H1 and H2 for equivalence. */ | |
6615 | ||
6616 | static int | |
6617 | toc_hash_eq (h1, h2) | |
6618 | const void * h1; | |
6619 | const void * h2; | |
6620 | { | |
6621 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
6622 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
6623 | ||
a9098fd0 GK |
6624 | if (((const struct toc_hash_struct *) h1)->key_mode |
6625 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
6626 | return 0; | |
6627 | ||
9ebbca7d GK |
6628 | /* Gotcha: One of these const_doubles will be in memory. |
6629 | The other may be on the constant-pool chain. | |
6630 | So rtx_equal_p will think they are different... */ | |
6631 | if (r1 == r2) | |
6632 | return 1; | |
6633 | if (GET_CODE (r1) != GET_CODE (r2) | |
6634 | || GET_MODE (r1) != GET_MODE (r2)) | |
6635 | return 0; | |
6636 | if (GET_CODE (r1) == CONST_DOUBLE) | |
6637 | { | |
6638 | int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE)); | |
6639 | int i; | |
6640 | for (i = 2; i < format_len; i++) | |
6641 | if (XWINT (r1, i) != XWINT (r2, i)) | |
6642 | return 0; | |
6643 | ||
6644 | return 1; | |
17167fd8 | 6645 | } |
9ebbca7d | 6646 | else if (GET_CODE (r1) == LABEL_REF) |
e4a0656f GK |
6647 | return (CODE_LABEL_NUMBER (XEXP (r1, 0)) |
6648 | == CODE_LABEL_NUMBER (XEXP (r2, 0))); | |
9ebbca7d GK |
6649 | else |
6650 | return rtx_equal_p (r1, r2); | |
6651 | } | |
6652 | ||
6653 | /* Mark the hash table-entry HASH_ENTRY. */ | |
6654 | ||
6655 | static int | |
6656 | toc_hash_mark_entry (hash_slot, unused) | |
2eba1afa | 6657 | void ** hash_slot; |
9ebbca7d GK |
6658 | void * unused ATTRIBUTE_UNUSED; |
6659 | { | |
6660 | const struct toc_hash_struct * hash_entry = | |
6661 | *(const struct toc_hash_struct **) hash_slot; | |
6662 | rtx r = hash_entry->key; | |
6663 | ggc_set_mark (hash_entry); | |
6664 | /* For CODE_LABELS, we don't want to drag in the whole insn chain... */ | |
6665 | if (GET_CODE (r) == LABEL_REF) | |
6666 | { | |
6667 | ggc_set_mark (r); | |
6668 | ggc_set_mark (XEXP (r, 0)); | |
6669 | } | |
6670 | else | |
6671 | ggc_mark_rtx (r); | |
6672 | return 1; | |
6673 | } | |
6674 | ||
6675 | /* Mark all the elements of the TOC hash-table *HT. */ | |
6676 | ||
6677 | static void | |
6678 | toc_hash_mark_table (vht) | |
6679 | void *vht; | |
6680 | { | |
6681 | htab_t *ht = vht; | |
6682 | ||
6683 | htab_traverse (*ht, toc_hash_mark_entry, (void *)0); | |
17167fd8 MM |
6684 | } |
6685 | ||
9878760c RK |
6686 | /* Output a TOC entry. We derive the entry name from what is |
6687 | being written. */ | |
6688 | ||
6689 | void | |
a9098fd0 | 6690 | output_toc (file, x, labelno, mode) |
9878760c RK |
6691 | FILE *file; |
6692 | rtx x; | |
6693 | int labelno; | |
a9098fd0 | 6694 | enum machine_mode mode; |
9878760c RK |
6695 | { |
6696 | char buf[256]; | |
3cce094d | 6697 | const char *name = buf; |
ec940faa | 6698 | const char *real_name; |
9878760c RK |
6699 | rtx base = x; |
6700 | int offset = 0; | |
6701 | ||
4697a36c MM |
6702 | if (TARGET_NO_TOC) |
6703 | abort (); | |
6704 | ||
9ebbca7d GK |
6705 | /* When the linker won't eliminate them, don't output duplicate |
6706 | TOC entries (this happens on AIX if there is any kind of TOC, | |
1f8f4a0b MM |
6707 | and on SVR4 under -fPIC or -mrelocatable). */ |
6708 | if (TARGET_TOC) | |
9ebbca7d GK |
6709 | { |
6710 | struct toc_hash_struct *h; | |
6711 | void * * found; | |
6712 | ||
6713 | h = ggc_alloc (sizeof (*h)); | |
6714 | h->key = x; | |
a9098fd0 | 6715 | h->key_mode = mode; |
9ebbca7d GK |
6716 | h->labelno = labelno; |
6717 | ||
6718 | found = htab_find_slot (toc_hash_table, h, 1); | |
6719 | if (*found == NULL) | |
6720 | *found = h; | |
6721 | else /* This is indeed a duplicate. | |
6722 | Set this label equal to that label. */ | |
6723 | { | |
6724 | fputs ("\t.set ", file); | |
6725 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
6726 | fprintf (file, "%d,", labelno); | |
6727 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
6728 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) | |
6729 | found)->labelno)); | |
6730 | return; | |
6731 | } | |
6732 | } | |
6733 | ||
6734 | /* If we're going to put a double constant in the TOC, make sure it's | |
6735 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
6736 | if (GET_CODE (x) == CONST_DOUBLE |
6737 | && STRICT_ALIGNMENT | |
a9098fd0 | 6738 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
6739 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
6740 | ASM_OUTPUT_ALIGN (file, 3); | |
6741 | } | |
6742 | ||
9ebbca7d | 6743 | ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno); |
9878760c | 6744 | |
37c37a57 RK |
6745 | /* Handle FP constants specially. Note that if we have a minimal |
6746 | TOC, things we put here aren't actually in the TOC, so we can allow | |
6747 | FP constants. */ | |
a9098fd0 | 6748 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) |
9878760c | 6749 | { |
042259f2 DE |
6750 | REAL_VALUE_TYPE rv; |
6751 | long k[2]; | |
0adc764e | 6752 | |
042259f2 DE |
6753 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
6754 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 6755 | |
13ded975 DE |
6756 | if (TARGET_64BIT) |
6757 | { | |
6758 | if (TARGET_MINIMAL_TOC) | |
6759 | fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]); | |
6760 | else | |
6761 | fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n", | |
0858c623 | 6762 | k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff); |
13ded975 DE |
6763 | return; |
6764 | } | |
1875cc88 | 6765 | else |
13ded975 DE |
6766 | { |
6767 | if (TARGET_MINIMAL_TOC) | |
31bfaa0b | 6768 | fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]); |
13ded975 | 6769 | else |
31bfaa0b | 6770 | fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n", |
13ded975 DE |
6771 | k[0], k[1], k[0], k[1]); |
6772 | return; | |
6773 | } | |
9878760c | 6774 | } |
a9098fd0 | 6775 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 6776 | { |
042259f2 DE |
6777 | REAL_VALUE_TYPE rv; |
6778 | long l; | |
9878760c | 6779 | |
042259f2 DE |
6780 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
6781 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
6782 | ||
31bfaa0b DE |
6783 | if (TARGET_64BIT) |
6784 | { | |
6785 | if (TARGET_MINIMAL_TOC) | |
6786 | fprintf (file, "\t.llong 0x%lx00000000\n", l); | |
6787 | else | |
6788 | fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l); | |
6789 | return; | |
6790 | } | |
042259f2 | 6791 | else |
31bfaa0b DE |
6792 | { |
6793 | if (TARGET_MINIMAL_TOC) | |
6794 | fprintf (file, "\t.long 0x%lx\n", l); | |
6795 | else | |
6796 | fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l); | |
6797 | return; | |
6798 | } | |
042259f2 | 6799 | } |
f176e826 | 6800 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 6801 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 6802 | { |
e2c953b6 | 6803 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
6804 | HOST_WIDE_INT high; |
6805 | ||
6806 | if (GET_CODE (x) == CONST_DOUBLE) | |
6807 | { | |
6808 | low = CONST_DOUBLE_LOW (x); | |
6809 | high = CONST_DOUBLE_HIGH (x); | |
6810 | } | |
6811 | else | |
6812 | #if HOST_BITS_PER_WIDE_INT == 32 | |
6813 | { | |
6814 | low = INTVAL (x); | |
0858c623 | 6815 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
6816 | } |
6817 | #else | |
6818 | { | |
0858c623 | 6819 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
6820 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
6821 | } | |
6822 | #endif | |
9878760c | 6823 | |
a9098fd0 GK |
6824 | /* TOC entries are always Pmode-sized, but since this |
6825 | is a bigendian machine then if we're putting smaller | |
6826 | integer constants in the TOC we have to pad them. | |
6827 | (This is still a win over putting the constants in | |
6828 | a separate constant pool, because then we'd have | |
6829 | to have both a TOC entry _and_ the actual constant.) */ | |
6830 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
6831 | abort ();/* It would be easy to make this work, but it doesn't now. */ | |
6832 | if (mode != Pmode) | |
6833 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), | |
6834 | POINTER_SIZE, &low, &high, 0); | |
6835 | ||
13ded975 DE |
6836 | if (TARGET_64BIT) |
6837 | { | |
6838 | if (TARGET_MINIMAL_TOC) | |
6839 | fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low); | |
6840 | else | |
6841 | fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n", | |
6842 | (long)high, (long)low, (long)high, (long)low); | |
6843 | return; | |
6844 | } | |
1875cc88 | 6845 | else |
13ded975 DE |
6846 | { |
6847 | if (TARGET_MINIMAL_TOC) | |
3cb999d8 | 6848 | fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", |
13ded975 DE |
6849 | (long)high, (long)low); |
6850 | else | |
3cb999d8 | 6851 | fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n", |
13ded975 DE |
6852 | (long)high, (long)low, (long)high, (long)low); |
6853 | return; | |
6854 | } | |
9878760c RK |
6855 | } |
6856 | ||
6857 | if (GET_CODE (x) == CONST) | |
6858 | { | |
6859 | base = XEXP (XEXP (x, 0), 0); | |
6860 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
6861 | } | |
6862 | ||
6863 | if (GET_CODE (base) == SYMBOL_REF) | |
6864 | name = XSTR (base, 0); | |
6865 | else if (GET_CODE (base) == LABEL_REF) | |
6866 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
6867 | else if (GET_CODE (base) == CODE_LABEL) | |
6868 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
6869 | else | |
6870 | abort (); | |
6871 | ||
2e4eb9b0 | 6872 | STRIP_NAME_ENCODING (real_name, name); |
1875cc88 | 6873 | if (TARGET_MINIMAL_TOC) |
13ded975 | 6874 | fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file); |
1875cc88 JW |
6875 | else |
6876 | { | |
b6c9286a | 6877 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 6878 | |
1875cc88 JW |
6879 | if (offset < 0) |
6880 | fprintf (file, ".N%d", - offset); | |
6881 | else if (offset) | |
6882 | fprintf (file, ".P%d", offset); | |
9878760c | 6883 | |
19d2d16f | 6884 | fputs ("[TC],", file); |
1875cc88 | 6885 | } |
581bc4de MM |
6886 | |
6887 | /* Currently C++ toc references to vtables can be emitted before it | |
6888 | is decided whether the vtable is public or private. If this is | |
6889 | the case, then the linker will eventually complain that there is | |
6890 | a TOC reference to an unknown section. Thus, for vtables only, | |
6891 | we emit the TOC reference to reference the symbol and not the | |
6892 | section. */ | |
89c01f0e | 6893 | if (strncmp ("_vt.", name, 4) == 0) |
581bc4de | 6894 | { |
89c01f0e | 6895 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
6896 | if (offset < 0) |
6897 | fprintf (file, "%d", offset); | |
6898 | else if (offset > 0) | |
6899 | fprintf (file, "+%d", offset); | |
6900 | } | |
6901 | else | |
6902 | output_addr_const (file, x); | |
19d2d16f | 6903 | putc ('\n', file); |
9878760c RK |
6904 | } |
6905 | \f | |
6906 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
6907 | starting at P to FILE. | |
6908 | ||
6909 | On the RS/6000, we have to do this using the .byte operation and | |
6910 | write out special characters outside the quoted string. | |
6911 | Also, the assembler is broken; very long strings are truncated, | |
6912 | so we must artificially break them up early. */ | |
6913 | ||
6914 | void | |
6915 | output_ascii (file, p, n) | |
6916 | FILE *file; | |
d330fd93 | 6917 | const char *p; |
9878760c RK |
6918 | int n; |
6919 | { | |
6920 | char c; | |
6921 | int i, count_string; | |
d330fd93 KG |
6922 | const char *for_string = "\t.byte \""; |
6923 | const char *for_decimal = "\t.byte "; | |
6924 | const char *to_close = NULL; | |
9878760c RK |
6925 | |
6926 | count_string = 0; | |
6927 | for (i = 0; i < n; i++) | |
6928 | { | |
6929 | c = *p++; | |
6930 | if (c >= ' ' && c < 0177) | |
6931 | { | |
6932 | if (for_string) | |
6933 | fputs (for_string, file); | |
6934 | putc (c, file); | |
6935 | ||
6936 | /* Write two quotes to get one. */ | |
6937 | if (c == '"') | |
6938 | { | |
6939 | putc (c, file); | |
6940 | ++count_string; | |
6941 | } | |
6942 | ||
6943 | for_string = NULL; | |
6944 | for_decimal = "\"\n\t.byte "; | |
6945 | to_close = "\"\n"; | |
6946 | ++count_string; | |
6947 | ||
6948 | if (count_string >= 512) | |
6949 | { | |
6950 | fputs (to_close, file); | |
6951 | ||
6952 | for_string = "\t.byte \""; | |
6953 | for_decimal = "\t.byte "; | |
6954 | to_close = NULL; | |
6955 | count_string = 0; | |
6956 | } | |
6957 | } | |
6958 | else | |
6959 | { | |
6960 | if (for_decimal) | |
6961 | fputs (for_decimal, file); | |
6962 | fprintf (file, "%d", c); | |
6963 | ||
6964 | for_string = "\n\t.byte \""; | |
6965 | for_decimal = ", "; | |
6966 | to_close = "\n"; | |
6967 | count_string = 0; | |
6968 | } | |
6969 | } | |
6970 | ||
6971 | /* Now close the string if we have written one. Then end the line. */ | |
6972 | if (to_close) | |
9ebbca7d | 6973 | fputs (to_close, file); |
9878760c RK |
6974 | } |
6975 | \f | |
6976 | /* Generate a unique section name for FILENAME for a section type | |
6977 | represented by SECTION_DESC. Output goes into BUF. | |
6978 | ||
6979 | SECTION_DESC can be any string, as long as it is different for each | |
6980 | possible section type. | |
6981 | ||
6982 | We name the section in the same manner as xlc. The name begins with an | |
6983 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
6984 | names) with the last period replaced by the string SECTION_DESC. If |
6985 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
6986 | the name. */ | |
9878760c RK |
6987 | |
6988 | void | |
6989 | rs6000_gen_section_name (buf, filename, section_desc) | |
6990 | char **buf; | |
9ebbca7d GK |
6991 | const char *filename; |
6992 | const char *section_desc; | |
9878760c | 6993 | { |
9ebbca7d | 6994 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
6995 | char *p; |
6996 | int len; | |
9878760c RK |
6997 | |
6998 | after_last_slash = filename; | |
6999 | for (q = filename; *q; q++) | |
11e5fe42 RK |
7000 | { |
7001 | if (*q == '/') | |
7002 | after_last_slash = q + 1; | |
7003 | else if (*q == '.') | |
7004 | last_period = q; | |
7005 | } | |
9878760c | 7006 | |
11e5fe42 | 7007 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
9878760c RK |
7008 | *buf = (char *) permalloc (len); |
7009 | ||
7010 | p = *buf; | |
7011 | *p++ = '_'; | |
7012 | ||
7013 | for (q = after_last_slash; *q; q++) | |
7014 | { | |
11e5fe42 | 7015 | if (q == last_period) |
9878760c RK |
7016 | { |
7017 | strcpy (p, section_desc); | |
7018 | p += strlen (section_desc); | |
9878760c RK |
7019 | } |
7020 | ||
e9a780ec | 7021 | else if (ISALNUM (*q)) |
9878760c RK |
7022 | *p++ = *q; |
7023 | } | |
7024 | ||
11e5fe42 | 7025 | if (last_period == 0) |
9878760c RK |
7026 | strcpy (p, section_desc); |
7027 | else | |
7028 | *p = '\0'; | |
7029 | } | |
e165f3f0 RK |
7030 | \f |
7031 | /* Write function profiler code. */ | |
7032 | ||
7033 | void | |
7034 | output_function_profiler (file, labelno) | |
7035 | FILE *file; | |
7036 | int labelno; | |
7037 | { | |
7038 | /* The last used parameter register. */ | |
7039 | int last_parm_reg; | |
7040 | int i, j; | |
3daf36a4 | 7041 | char buf[100]; |
e165f3f0 | 7042 | |
3daf36a4 | 7043 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 | 7044 | switch (DEFAULT_ABI) |
3daf36a4 | 7045 | { |
38c1f2d7 MM |
7046 | default: |
7047 | abort (); | |
7048 | ||
7049 | case ABI_V4: | |
7050 | case ABI_SOLARIS: | |
7051 | case ABI_AIX_NODESC: | |
7052 | fprintf (file, "\tmflr %s\n", reg_names[0]); | |
7053 | if (flag_pic == 1) | |
7054 | { | |
dfdfa60f DE |
7055 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
7056 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", | |
7057 | reg_names[0], reg_names[1]); | |
17167fd8 | 7058 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 7059 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 7060 | assemble_name (file, buf); |
17167fd8 | 7061 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 7062 | } |
9ebbca7d | 7063 | else if (flag_pic > 1) |
38c1f2d7 | 7064 | { |
dfdfa60f DE |
7065 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", |
7066 | reg_names[0], reg_names[1]); | |
9ebbca7d GK |
7067 | /* Now, we need to get the address of the label. */ |
7068 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 7069 | assemble_name (file, buf); |
9ebbca7d GK |
7070 | fputs ("-.\n1:", file); |
7071 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
7072 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", | |
7073 | reg_names[0], reg_names[11]); | |
7074 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
7075 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 7076 | } |
38c1f2d7 MM |
7077 | else |
7078 | { | |
17167fd8 | 7079 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 7080 | assemble_name (file, buf); |
dfdfa60f | 7081 | fputs ("@ha\n", file); |
b5253831 DE |
7082 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", |
7083 | reg_names[0], reg_names[1]); | |
a260abc9 | 7084 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 7085 | assemble_name (file, buf); |
17167fd8 | 7086 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
7087 | } |
7088 | ||
b5253831 DE |
7089 | if (current_function_needs_context) |
7090 | asm_fprintf (file, "\tmr %s,%s\n", | |
7091 | reg_names[30], reg_names[STATIC_CHAIN_REGNUM]); | |
38c1f2d7 | 7092 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); |
b5253831 DE |
7093 | if (current_function_needs_context) |
7094 | asm_fprintf (file, "\tmr %s,%s\n", | |
7095 | reg_names[STATIC_CHAIN_REGNUM], reg_names[30]); | |
38c1f2d7 MM |
7096 | break; |
7097 | ||
7098 | case ABI_AIX: | |
7099 | /* Set up a TOC entry for the profiler label. */ | |
7100 | toc_section (); | |
7101 | ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno); | |
7102 | if (TARGET_MINIMAL_TOC) | |
7103 | { | |
13ded975 | 7104 | fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file); |
38c1f2d7 MM |
7105 | assemble_name (file, buf); |
7106 | putc ('\n', file); | |
7107 | } | |
7108 | else | |
7109 | { | |
7110 | fputs ("\t.tc\t", file); | |
7111 | assemble_name (file, buf); | |
7112 | fputs ("[TC],", file); | |
7113 | assemble_name (file, buf); | |
7114 | putc ('\n', file); | |
7115 | } | |
7116 | text_section (); | |
e165f3f0 RK |
7117 | |
7118 | /* Figure out last used parameter register. The proper thing to do is | |
7119 | to walk incoming args of the function. A function might have live | |
7120 | parameter registers even if it has no incoming args. */ | |
7121 | ||
38c1f2d7 MM |
7122 | for (last_parm_reg = 10; |
7123 | last_parm_reg > 2 && ! regs_ever_live [last_parm_reg]; | |
7124 | last_parm_reg--) | |
7125 | ; | |
e165f3f0 | 7126 | |
b5253831 DE |
7127 | /* Save parameter registers in regs 23-30 and static chain in r22. |
7128 | Don't overwrite reg 31, since it might be set up as the frame pointer. */ | |
e165f3f0 | 7129 | |
38c1f2d7 MM |
7130 | for (i = 3, j = 30; i <= last_parm_reg; i++, j--) |
7131 | asm_fprintf (file, "\tmr %d,%d\n", j, i); | |
b5253831 DE |
7132 | if (current_function_needs_context) |
7133 | asm_fprintf (file, "\tmr %d,%d\n", j, STATIC_CHAIN_REGNUM); | |
e165f3f0 RK |
7134 | |
7135 | /* Load location address into r3, and call mcount. */ | |
7136 | ||
38c1f2d7 | 7137 | ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno); |
13ded975 DE |
7138 | asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,", |
7139 | reg_names[3]); | |
38c1f2d7 | 7140 | assemble_name (file, buf); |
13f1623b DE |
7141 | asm_fprintf (file, "(%s)\n\tbl %s\n\t", reg_names[2], RS6000_MCOUNT); |
7142 | asm_fprintf (file, RS6000_CALL_GLUE); | |
7143 | putc('\n', file); | |
e165f3f0 | 7144 | |
b5253831 | 7145 | /* Restore parameter registers and static chain. */ |
e165f3f0 | 7146 | |
38c1f2d7 MM |
7147 | for (i = 3, j = 30; i <= last_parm_reg; i++, j--) |
7148 | asm_fprintf (file, "\tmr %d,%d\n", i, j); | |
b5253831 DE |
7149 | if (current_function_needs_context) |
7150 | asm_fprintf (file, "\tmr %d,%d\n", STATIC_CHAIN_REGNUM, j); | |
7151 | ||
38c1f2d7 MM |
7152 | break; |
7153 | } | |
e165f3f0 | 7154 | } |
a251ffd0 TG |
7155 | |
7156 | /* Adjust the cost of a scheduling dependency. Return the new cost of | |
7157 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
7158 | ||
7159 | int | |
a06faf84 | 7160 | rs6000_adjust_cost (insn, link, dep_insn, cost) |
a251ffd0 TG |
7161 | rtx insn; |
7162 | rtx link; | |
296b8152 | 7163 | rtx dep_insn ATTRIBUTE_UNUSED; |
a251ffd0 TG |
7164 | int cost; |
7165 | { | |
7166 | if (! recog_memoized (insn)) | |
7167 | return 0; | |
7168 | ||
7169 | if (REG_NOTE_KIND (link) != 0) | |
7170 | return 0; | |
7171 | ||
7172 | if (REG_NOTE_KIND (link) == 0) | |
7173 | { | |
7174 | /* Data dependency; DEP_INSN writes a register that INSN reads some | |
7175 | cycles later. */ | |
7176 | ||
7177 | /* Tell the first scheduling pass about the latency between a mtctr | |
7178 | and bctr (and mtlr and br/blr). The first scheduling pass will not | |
7179 | know about this latency since the mtctr instruction, which has the | |
7180 | latency associated to it, will be generated by reload. */ | |
7181 | if (get_attr_type (insn) == TYPE_JMPREG) | |
7182 | return TARGET_POWER ? 5 : 4; | |
7183 | ||
7184 | /* Fall out to return default cost. */ | |
7185 | } | |
7186 | ||
7187 | return cost; | |
7188 | } | |
b6c9286a | 7189 | |
bef84347 VM |
7190 | /* A C statement (sans semicolon) to update the integer scheduling priority |
7191 | INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier, | |
7192 | increase the priority to execute INSN later. Do not define this macro if | |
7193 | you do not need to adjust the scheduling priorities of insns. */ | |
7194 | ||
7195 | int | |
7196 | rs6000_adjust_priority (insn, priority) | |
d330fd93 | 7197 | rtx insn ATTRIBUTE_UNUSED; |
bef84347 VM |
7198 | int priority; |
7199 | { | |
7200 | /* On machines (like the 750) which have asymetric integer units, where one | |
7201 | integer unit can do multiply and divides and the other can't, reduce the | |
7202 | priority of multiply/divide so it is scheduled before other integer | |
7203 | operationss. */ | |
7204 | ||
7205 | #if 0 | |
2c3c49de | 7206 | if (! INSN_P (insn)) |
bef84347 VM |
7207 | return priority; |
7208 | ||
7209 | if (GET_CODE (PATTERN (insn)) == USE) | |
7210 | return priority; | |
7211 | ||
7212 | switch (rs6000_cpu_attr) { | |
7213 | case CPU_PPC750: | |
7214 | switch (get_attr_type (insn)) | |
7215 | { | |
7216 | default: | |
7217 | break; | |
7218 | ||
7219 | case TYPE_IMUL: | |
7220 | case TYPE_IDIV: | |
3cb999d8 DE |
7221 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
7222 | priority, priority); | |
bef84347 VM |
7223 | if (priority >= 0 && priority < 0x01000000) |
7224 | priority >>= 3; | |
7225 | break; | |
7226 | } | |
7227 | } | |
7228 | #endif | |
7229 | ||
7230 | return priority; | |
7231 | } | |
7232 | ||
b6c9286a MM |
7233 | /* Return how many instructions the machine can issue per cycle */ |
7234 | int get_issue_rate() | |
7235 | { | |
7236 | switch (rs6000_cpu_attr) { | |
3cb999d8 DE |
7237 | case CPU_RIOS1: /* ? */ |
7238 | case CPU_RS64A: | |
7239 | case CPU_PPC601: /* ? */ | |
7240 | return 3; | |
b6c9286a | 7241 | case CPU_PPC603: |
bef84347 VM |
7242 | case CPU_PPC750: |
7243 | return 2; | |
3cb999d8 | 7244 | case CPU_RIOS2: |
b6c9286a | 7245 | case CPU_PPC604: |
19684119 | 7246 | case CPU_PPC604E: |
b6c9286a | 7247 | case CPU_PPC620: |
3cb999d8 | 7248 | case CPU_PPC630: |
b6c9286a MM |
7249 | return 4; |
7250 | default: | |
7251 | return 1; | |
7252 | } | |
7253 | } | |
7254 | ||
b6c9286a | 7255 | \f |
b6c9286a MM |
7256 | /* Length in units of the trampoline for entering a nested function. */ |
7257 | ||
7258 | int | |
7259 | rs6000_trampoline_size () | |
7260 | { | |
7261 | int ret = 0; | |
7262 | ||
7263 | switch (DEFAULT_ABI) | |
7264 | { | |
7265 | default: | |
7266 | abort (); | |
7267 | ||
7268 | case ABI_AIX: | |
8f802bfb | 7269 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
7270 | break; |
7271 | ||
7272 | case ABI_V4: | |
c81bebd7 | 7273 | case ABI_SOLARIS: |
b6c9286a | 7274 | case ABI_AIX_NODESC: |
03a7e1a5 | 7275 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 7276 | break; |
b6c9286a MM |
7277 | } |
7278 | ||
7279 | return ret; | |
7280 | } | |
7281 | ||
7282 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
7283 | FNADDR is an RTX for the address of the function's pure code. | |
7284 | CXT is an RTX for the static chain value for the function. */ | |
7285 | ||
7286 | void | |
7287 | rs6000_initialize_trampoline (addr, fnaddr, cxt) | |
7288 | rtx addr; | |
7289 | rtx fnaddr; | |
7290 | rtx cxt; | |
7291 | { | |
ac2a93a1 | 7292 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
7293 | int regsize = (TARGET_32BIT) ? 4 : 8; |
7294 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
7295 | |
7296 | switch (DEFAULT_ABI) | |
7297 | { | |
7298 | default: | |
7299 | abort (); | |
7300 | ||
8bd04c56 | 7301 | /* Macros to shorten the code expansions below. */ |
39403d82 | 7302 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
7303 | #define MEM_PLUS(addr,offset) \ |
7304 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 7305 | |
b6c9286a MM |
7306 | /* Under AIX, just build the 3 word function descriptor */ |
7307 | case ABI_AIX: | |
8bd04c56 MM |
7308 | { |
7309 | rtx fn_reg = gen_reg_rtx (pmode); | |
7310 | rtx toc_reg = gen_reg_rtx (pmode); | |
7311 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
7312 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4)); | |
7313 | emit_move_insn (MEM_DEREF (addr), fn_reg); | |
7314 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
7315 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
7316 | } | |
b6c9286a MM |
7317 | break; |
7318 | ||
eaf1bcf1 | 7319 | /* Under V.4/eabi, call __trampoline_setup to do the real work. */ |
b6c9286a | 7320 | case ABI_V4: |
c81bebd7 | 7321 | case ABI_SOLARIS: |
b6c9286a | 7322 | case ABI_AIX_NODESC: |
39403d82 | 7323 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
7324 | FALSE, VOIDmode, 4, |
7325 | addr, pmode, | |
7326 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
7327 | fnaddr, pmode, | |
7328 | ctx_reg, pmode); | |
b6c9286a | 7329 | break; |
b6c9286a MM |
7330 | } |
7331 | ||
7332 | return; | |
7333 | } | |
7509c759 MM |
7334 | |
7335 | \f | |
7336 | /* If defined, a C expression whose value is nonzero if IDENTIFIER | |
7337 | with arguments ARGS is a valid machine specific attribute for DECL. | |
7338 | The attributes in ATTRIBUTES have previously been assigned to DECL. */ | |
7339 | ||
7340 | int | |
7341 | rs6000_valid_decl_attribute_p (decl, attributes, identifier, args) | |
296b8152 KG |
7342 | tree decl ATTRIBUTE_UNUSED; |
7343 | tree attributes ATTRIBUTE_UNUSED; | |
7344 | tree identifier ATTRIBUTE_UNUSED; | |
7345 | tree args ATTRIBUTE_UNUSED; | |
7509c759 MM |
7346 | { |
7347 | return 0; | |
7348 | } | |
7349 | ||
7350 | /* If defined, a C expression whose value is nonzero if IDENTIFIER | |
7351 | with arguments ARGS is a valid machine specific attribute for TYPE. | |
7352 | The attributes in ATTRIBUTES have previously been assigned to TYPE. */ | |
7353 | ||
7354 | int | |
7355 | rs6000_valid_type_attribute_p (type, attributes, identifier, args) | |
7356 | tree type; | |
296b8152 | 7357 | tree attributes ATTRIBUTE_UNUSED; |
7509c759 MM |
7358 | tree identifier; |
7359 | tree args; | |
7360 | { | |
7361 | if (TREE_CODE (type) != FUNCTION_TYPE | |
7362 | && TREE_CODE (type) != FIELD_DECL | |
7363 | && TREE_CODE (type) != TYPE_DECL) | |
7364 | return 0; | |
7365 | ||
6a4cee5f MM |
7366 | /* Longcall attribute says that the function is not within 2**26 bytes |
7367 | of the current function, and to do an indirect call. */ | |
7368 | if (is_attribute_p ("longcall", identifier)) | |
7369 | return (args == NULL_TREE); | |
7370 | ||
7509c759 MM |
7371 | return 0; |
7372 | } | |
7373 | ||
7374 | /* If defined, a C expression whose value is zero if the attributes on | |
7375 | TYPE1 and TYPE2 are incompatible, one if they are compatible, and | |
7376 | two if they are nearly compatible (which causes a warning to be | |
7377 | generated). */ | |
7378 | ||
7379 | int | |
7380 | rs6000_comp_type_attributes (type1, type2) | |
296b8152 KG |
7381 | tree type1 ATTRIBUTE_UNUSED; |
7382 | tree type2 ATTRIBUTE_UNUSED; | |
7509c759 MM |
7383 | { |
7384 | return 1; | |
7385 | } | |
7386 | ||
7387 | /* If defined, a C statement that assigns default attributes to newly | |
7388 | defined TYPE. */ | |
7389 | ||
7390 | void | |
7391 | rs6000_set_default_type_attributes (type) | |
296b8152 | 7392 | tree type ATTRIBUTE_UNUSED; |
7509c759 | 7393 | { |
3cb999d8 | 7394 | return; |
7509c759 MM |
7395 | } |
7396 | ||
3cb999d8 DE |
7397 | /* Return a reference suitable for calling a function with the |
7398 | longcall attribute. */ | |
6a4cee5f MM |
7399 | struct rtx_def * |
7400 | rs6000_longcall_ref (call_ref) | |
7401 | rtx call_ref; | |
7402 | { | |
d330fd93 | 7403 | const char *call_name; |
6a4cee5f MM |
7404 | tree node; |
7405 | ||
7406 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
7407 | return call_ref; | |
7408 | ||
7409 | /* System V adds '.' to the internal name, so skip them. */ | |
7410 | call_name = XSTR (call_ref, 0); | |
7411 | if (*call_name == '.') | |
7412 | { | |
7413 | while (*call_name == '.') | |
7414 | call_name++; | |
7415 | ||
7416 | node = get_identifier (call_name); | |
39403d82 | 7417 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
7418 | } |
7419 | ||
7420 | return force_reg (Pmode, call_ref); | |
7421 | } | |
7422 | ||
7509c759 MM |
7423 | \f |
7424 | /* A C statement or statements to switch to the appropriate section | |
7425 | for output of RTX in mode MODE. You can assume that RTX is some | |
7426 | kind of constant in RTL. The argument MODE is redundant except in | |
7427 | the case of a `const_int' rtx. Select the section by calling | |
7428 | `text_section' or one of the alternatives for other sections. | |
7429 | ||
7430 | Do not define this macro if you put all constants in the read-only | |
7431 | data section. */ | |
7432 | ||
7433 | #ifdef USING_SVR4_H | |
7434 | ||
7435 | void | |
7436 | rs6000_select_rtx_section (mode, x) | |
a9098fd0 | 7437 | enum machine_mode mode; |
7509c759 MM |
7438 | rtx x; |
7439 | { | |
a9098fd0 | 7440 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 7441 | toc_section (); |
7509c759 MM |
7442 | else |
7443 | const_section (); | |
7444 | } | |
7445 | ||
7446 | /* A C statement or statements to switch to the appropriate | |
7447 | section for output of DECL. DECL is either a `VAR_DECL' node | |
7448 | or a constant of some sort. RELOC indicates whether forming | |
7449 | the initial value of DECL requires link-time relocations. */ | |
7450 | ||
7451 | void | |
7452 | rs6000_select_section (decl, reloc) | |
7453 | tree decl; | |
7454 | int reloc; | |
7455 | { | |
7456 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
63019373 GK |
7457 | int needs_sdata; |
7458 | int readonly; | |
7459 | static void (* const sec_funcs[4]) PARAMS ((void)) = { | |
7460 | &const_section, | |
7461 | &sdata2_section, | |
7462 | &data_section, | |
7463 | &sdata_section | |
7464 | }; | |
7465 | ||
7466 | needs_sdata = (size > 0 | |
7467 | && size <= g_switch_value | |
7468 | && rs6000_sdata != SDATA_NONE | |
7469 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))); | |
7509c759 MM |
7470 | |
7471 | if (TREE_CODE (decl) == STRING_CST) | |
63019373 | 7472 | readonly = ! flag_writable_strings; |
a9098fd0 | 7473 | else if (TREE_CODE (decl) == VAR_DECL) |
63019373 GK |
7474 | readonly = (! (flag_pic && reloc) |
7475 | && TREE_READONLY (decl) | |
7476 | && ! TREE_SIDE_EFFECTS (decl) | |
7477 | && DECL_INITIAL (decl) | |
7478 | && DECL_INITIAL (decl) != error_mark_node | |
7479 | && TREE_CONSTANT (DECL_INITIAL (decl))); | |
7509c759 | 7480 | else |
63019373 GK |
7481 | readonly = 1; |
7482 | if (needs_sdata && rs6000_sdata != SDATA_EABI) | |
7483 | readonly = 0; | |
7484 | ||
7485 | (*sec_funcs[(readonly ? 0 : 2) + (needs_sdata ? 1 : 0)])(); | |
7486 | } | |
7487 | ||
7488 | /* A C statement to build up a unique section name, expressed as a | |
7489 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
7490 | RELOC indicates whether the initial value of EXP requires | |
7491 | link-time relocations. If you do not define this macro, GCC will use | |
7492 | the symbol name prefixed by `.' as the section name. Note - this | |
7493 | macro can now be called for unitialised data items as well as | |
7494 | initialised data and functions. */ | |
7495 | ||
7496 | void | |
7497 | rs6000_unique_section (decl, reloc) | |
7498 | tree decl; | |
7499 | int reloc; | |
7500 | { | |
7501 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
7502 | int needs_sdata; | |
7503 | int readonly; | |
7504 | int len; | |
7505 | int sec; | |
7506 | const char *name; | |
7507 | char *string; | |
7508 | const char *prefix; | |
7509 | ||
7510 | static const char *const prefixes[7][2] = | |
7511 | { | |
7512 | { ".text.", ".gnu.linkonce.t." }, | |
7513 | { ".rodata.", ".gnu.linkonce.r." }, | |
7514 | { ".sdata2.", ".gnu.linkonce.s2." }, | |
7515 | { ".data.", ".gnu.linkonce.d." }, | |
7516 | { ".sdata.", ".gnu.linkonce.s." }, | |
7517 | { ".bss.", ".gnu.linkonce.b." }, | |
7518 | { ".sbss.", ".gnu.linkonce.sb." } | |
7519 | }; | |
7520 | ||
7521 | needs_sdata = (TREE_CODE (decl) != FUNCTION_DECL | |
7522 | && size > 0 | |
7523 | && size <= g_switch_value | |
7524 | && rs6000_sdata != SDATA_NONE | |
7525 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))); | |
7526 | ||
7527 | if (TREE_CODE (decl) == STRING_CST) | |
7528 | readonly = ! flag_writable_strings; | |
7529 | else if (TREE_CODE (decl) == VAR_DECL) | |
7530 | readonly = (! (flag_pic && reloc) | |
7531 | && TREE_READONLY (decl) | |
7532 | && ! TREE_SIDE_EFFECTS (decl) | |
7533 | && DECL_INITIAL (decl) | |
7534 | && DECL_INITIAL (decl) != error_mark_node | |
7535 | && TREE_CONSTANT (DECL_INITIAL (decl))); | |
7536 | else | |
7537 | readonly = 1; | |
7538 | if (needs_sdata && rs6000_sdata != SDATA_EABI) | |
7539 | readonly = 0; | |
7540 | ||
7541 | sec = ((TREE_CODE (decl) == FUNCTION_DECL ? 0 : 1) | |
7542 | + (readonly ? 0 : 2) | |
7543 | + (needs_sdata ? 1 : 0) | |
7544 | + (DECL_INITIAL (decl) == 0 | |
7545 | || DECL_INITIAL (decl) == error_mark_node) ? 4 : 0); | |
7546 | ||
7547 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
7548 | prefix = prefixes[sec][DECL_ONE_ONLY (decl)]; | |
7549 | len = strlen (name) + strlen (prefix); | |
7550 | string = alloca (len + 1); | |
7551 | ||
7552 | sprintf (string, "%s%s", prefix, name); | |
7553 | ||
7554 | DECL_SECTION_NAME (decl) = build_string (len, string); | |
7509c759 | 7555 | } |
d9407988 MM |
7556 | |
7557 | \f | |
d9407988 MM |
7558 | /* If we are referencing a function that is static or is known to be |
7559 | in this file, make the SYMBOL_REF special. We can use this to indicate | |
7560 | that we can branch to this function without emitting a no-op after the | |
9ebbca7d | 7561 | call. For real AIX calling sequences, we also replace the |
d9407988 MM |
7562 | function name with the real name (1 or 2 leading .'s), rather than |
7563 | the function descriptor name. This saves a lot of overriding code | |
a260abc9 | 7564 | to read the prefixes. */ |
d9407988 MM |
7565 | |
7566 | void | |
7567 | rs6000_encode_section_info (decl) | |
7568 | tree decl; | |
7569 | { | |
7570 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
7571 | { | |
7572 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
8f1b829e | 7573 | if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl)) |
c81fc13e | 7574 | && ! DECL_WEAK (decl)) |
d9407988 MM |
7575 | SYMBOL_REF_FLAG (sym_ref) = 1; |
7576 | ||
9ebbca7d | 7577 | if (DEFAULT_ABI == ABI_AIX) |
d9407988 | 7578 | { |
ff669a6c RH |
7579 | size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2; |
7580 | size_t len2 = strlen (XSTR (sym_ref, 0)); | |
520a57c8 | 7581 | char *str = alloca (len1 + len2 + 1); |
ff669a6c RH |
7582 | str[0] = '.'; |
7583 | str[1] = '.'; | |
7584 | memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1); | |
7585 | ||
520a57c8 | 7586 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2); |
d9407988 MM |
7587 | } |
7588 | } | |
7589 | else if (rs6000_sdata != SDATA_NONE | |
7590 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
7591 | && TREE_CODE (decl) == VAR_DECL) | |
7592 | { | |
7593 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
7594 | tree section_name = DECL_SECTION_NAME (decl); | |
d330fd93 | 7595 | const char *name = (char *)0; |
d9407988 MM |
7596 | int len = 0; |
7597 | ||
7598 | if (section_name) | |
7599 | { | |
7600 | if (TREE_CODE (section_name) == STRING_CST) | |
7601 | { | |
7602 | name = TREE_STRING_POINTER (section_name); | |
7603 | len = TREE_STRING_LENGTH (section_name); | |
7604 | } | |
7605 | else | |
7606 | abort (); | |
7607 | } | |
7608 | ||
7609 | if ((size > 0 && size <= g_switch_value) | |
7610 | || (name | |
5f59ecb7 | 7611 | && ((len == sizeof (".sdata") - 1 |
3cb999d8 | 7612 | && strcmp (name, ".sdata") == 0) |
5f59ecb7 | 7613 | || (len == sizeof (".sdata2") - 1 |
3cb999d8 | 7614 | && strcmp (name, ".sdata2") == 0) |
5f59ecb7 | 7615 | || (len == sizeof (".sbss") - 1 |
3cb999d8 | 7616 | && strcmp (name, ".sbss") == 0) |
5f59ecb7 | 7617 | || (len == sizeof (".sbss2") - 1 |
3cb999d8 | 7618 | && strcmp (name, ".sbss2") == 0) |
5f59ecb7 | 7619 | || (len == sizeof (".PPC.EMB.sdata0") - 1 |
3cb999d8 | 7620 | && strcmp (name, ".PPC.EMB.sdata0") == 0) |
5f59ecb7 | 7621 | || (len == sizeof (".PPC.EMB.sbss0") - 1 |
3cb999d8 | 7622 | && strcmp (name, ".PPC.EMB.sbss0") == 0)))) |
d9407988 MM |
7623 | { |
7624 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
ff669a6c | 7625 | size_t len = strlen (XSTR (sym_ref, 0)); |
520a57c8 | 7626 | char *str = alloca (len + 1); |
ff669a6c | 7627 | |
ff669a6c RH |
7628 | str[0] = '@'; |
7629 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
520a57c8 | 7630 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len); |
d9407988 MM |
7631 | } |
7632 | } | |
7633 | } | |
7634 | ||
7509c759 | 7635 | #endif /* USING_SVR4_H */ |
000034eb | 7636 | |
a6c2a102 | 7637 | \f |
000034eb | 7638 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
7639 | ADDR can be effectively incremented by incrementing REG. |
7640 | ||
7641 | r0 is special and we must not select it as an address | |
7642 | register by this routine since our caller will try to | |
7643 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
7644 | |
7645 | struct rtx_def * | |
7646 | find_addr_reg (addr) | |
7647 | rtx addr; | |
7648 | { | |
7649 | while (GET_CODE (addr) == PLUS) | |
7650 | { | |
02441cd6 JL |
7651 | if (GET_CODE (XEXP (addr, 0)) == REG |
7652 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 7653 | addr = XEXP (addr, 0); |
02441cd6 JL |
7654 | else if (GET_CODE (XEXP (addr, 1)) == REG |
7655 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
7656 | addr = XEXP (addr, 1); |
7657 | else if (CONSTANT_P (XEXP (addr, 0))) | |
7658 | addr = XEXP (addr, 1); | |
7659 | else if (CONSTANT_P (XEXP (addr, 1))) | |
7660 | addr = XEXP (addr, 0); | |
7661 | else | |
7662 | abort (); | |
7663 | } | |
02441cd6 | 7664 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
7665 | return addr; |
7666 | abort (); | |
7667 | } | |
7668 | ||
a6c2a102 DE |
7669 | void |
7670 | rs6000_fatal_bad_address (op) | |
7671 | rtx op; | |
7672 | { | |
7673 | fatal_insn ("bad address", op); | |
7674 | } | |
c8023011 MM |
7675 | |
7676 | /* Called to register all of our global variables with the garbage | |
7677 | collector. */ | |
7678 | ||
7679 | static void | |
7680 | rs6000_add_gc_roots () | |
7681 | { | |
7682 | ggc_add_rtx_root (&rs6000_compare_op0, 1); | |
7683 | ggc_add_rtx_root (&rs6000_compare_op1, 1); | |
9ebbca7d GK |
7684 | |
7685 | toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL); | |
7686 | ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table), | |
7687 | toc_hash_mark_table); | |
c8023011 | 7688 | } |