]>
Commit | Line | Data |
---|---|---|
9878760c | 1 | /* Subroutines used for code generation on IBM RS/6000. |
34f94b1f | 2 | Copyright (C) 1991, 93-8, 1999 Free Software Foundation, Inc. |
fab3bcc3 | 3 | Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) |
9878760c RK |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
c15c9075 RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
9878760c | 21 | |
956d6950 | 22 | #include "config.h" |
c4d38ccb | 23 | #include "system.h" |
9878760c RK |
24 | #include "rtl.h" |
25 | #include "regs.h" | |
26 | #include "hard-reg-set.h" | |
27 | #include "real.h" | |
28 | #include "insn-config.h" | |
29 | #include "conditions.h" | |
30 | #include "insn-flags.h" | |
9878760c RK |
31 | #include "insn-attr.h" |
32 | #include "flags.h" | |
33 | #include "recog.h" | |
9878760c | 34 | #include "obstack.h" |
9b30bae2 | 35 | #include "tree.h" |
dfafc897 | 36 | #include "expr.h" |
2a430ec1 | 37 | #include "except.h" |
a7df97e6 | 38 | #include "function.h" |
296b8152 KG |
39 | #include "output.h" |
40 | #include "toplev.h" | |
9b30bae2 | 41 | |
7509c759 MM |
42 | #ifndef TARGET_NO_PROTOTYPE |
43 | #define TARGET_NO_PROTOTYPE 0 | |
44 | #endif | |
45 | ||
5248c961 | 46 | extern int profile_block_flag; |
9878760c RK |
47 | |
48 | #define min(A,B) ((A) < (B) ? (A) : (B)) | |
49 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
50 | ||
5248c961 RK |
51 | /* Target cpu type */ |
52 | ||
53 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
54 | struct rs6000_cpu_select rs6000_select[3] = |
55 | { | |
815cdc52 MM |
56 | /* switch name, tune arch */ |
57 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
58 | { (const char *)0, "-mcpu=", 1, 1 }, | |
59 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 60 | }; |
5248c961 | 61 | |
9878760c RK |
62 | /* Set to non-zero by "fix" operation to indicate that itrunc and |
63 | uitrunc must be defined. */ | |
64 | ||
65 | int rs6000_trunc_used; | |
66 | ||
67 | /* Set to non-zero once they have been defined. */ | |
68 | ||
69 | static int trunc_defined; | |
70 | ||
c764f757 RK |
71 | /* Set to non-zero once AIX common-mode calls have been defined. */ |
72 | static int common_mode_defined; | |
c81bebd7 | 73 | |
9878760c RK |
74 | /* Save information from a "cmpxx" operation until the branch or scc is |
75 | emitted. */ | |
9878760c RK |
76 | rtx rs6000_compare_op0, rs6000_compare_op1; |
77 | int rs6000_compare_fp_p; | |
874a0744 MM |
78 | |
79 | #ifdef USING_SVR4_H | |
80 | /* Label number of label created for -mrelocatable, to call to so we can | |
81 | get the address of the GOT section */ | |
82 | int rs6000_pic_labelno; | |
ab9eef41 | 83 | int rs6000_pic_func_labelno; |
c81bebd7 MM |
84 | |
85 | /* Which abi to adhere to */ | |
815cdc52 | 86 | const char *rs6000_abi_name = RS6000_ABI_NAME; |
d9407988 MM |
87 | |
88 | /* Semantics of the small data area */ | |
89 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
90 | ||
91 | /* Which small data model to use */ | |
815cdc52 | 92 | const char *rs6000_sdata_name = (char *)0; |
874a0744 | 93 | #endif |
4697a36c MM |
94 | |
95 | /* Whether a System V.4 varargs area was created. */ | |
96 | int rs6000_sysv_varargs_p; | |
8f75773e | 97 | |
b6c9286a MM |
98 | /* ABI enumeration available for subtarget to use. */ |
99 | enum rs6000_abi rs6000_current_abi; | |
100 | ||
802a0058 MM |
101 | /* Offset & size for fpmem stack locations used for converting between |
102 | float and integral types. */ | |
103 | int rs6000_fpmem_offset; | |
104 | int rs6000_fpmem_size; | |
105 | ||
38c1f2d7 | 106 | /* Debug flags */ |
815cdc52 | 107 | const char *rs6000_debug_name; |
38c1f2d7 MM |
108 | int rs6000_debug_stack; /* debug stack applications */ |
109 | int rs6000_debug_arg; /* debug argument handling */ | |
110 | ||
111 | /* Flag to say the TOC is initialized */ | |
112 | int toc_initialized; | |
113 | ||
c81bebd7 MM |
114 | \f |
115 | /* Default register names. */ | |
116 | char rs6000_reg_names[][8] = | |
117 | { | |
802a0058 MM |
118 | "0", "1", "2", "3", "4", "5", "6", "7", |
119 | "8", "9", "10", "11", "12", "13", "14", "15", | |
120 | "16", "17", "18", "19", "20", "21", "22", "23", | |
121 | "24", "25", "26", "27", "28", "29", "30", "31", | |
122 | "0", "1", "2", "3", "4", "5", "6", "7", | |
123 | "8", "9", "10", "11", "12", "13", "14", "15", | |
124 | "16", "17", "18", "19", "20", "21", "22", "23", | |
125 | "24", "25", "26", "27", "28", "29", "30", "31", | |
126 | "mq", "lr", "ctr","ap", | |
127 | "0", "1", "2", "3", "4", "5", "6", "7", | |
128 | "fpmem" | |
c81bebd7 MM |
129 | }; |
130 | ||
131 | #ifdef TARGET_REGNAMES | |
132 | static char alt_reg_names[][8] = | |
133 | { | |
802a0058 MM |
134 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
135 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
136 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
137 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
138 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
139 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
140 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
141 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
142 | "mq", "lr", "ctr", "ap", | |
143 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
144 | "fpmem" | |
c81bebd7 MM |
145 | }; |
146 | #endif | |
9878760c | 147 | \f |
daf11973 MM |
148 | #ifndef MASK_STRICT_ALIGN |
149 | #define MASK_STRICT_ALIGN 0 | |
150 | #endif | |
151 | ||
5248c961 RK |
152 | /* Override command line options. Mostly we process the processor |
153 | type and sometimes adjust other TARGET_ options. */ | |
154 | ||
155 | void | |
8e3f41e7 | 156 | rs6000_override_options (default_cpu) |
d330fd93 | 157 | const char *default_cpu; |
5248c961 | 158 | { |
c4d38ccb | 159 | size_t i, j; |
8e3f41e7 | 160 | struct rs6000_cpu_select *ptr; |
5248c961 | 161 | |
85638c0d RK |
162 | /* Simplify the entries below by making a mask for any POWER |
163 | variant and any PowerPC variant. */ | |
164 | ||
938937d8 | 165 | #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING) |
68c49ffa RK |
166 | #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \ |
167 | | MASK_PPC_GFXOPT | MASK_POWERPC64) | |
168 | #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT) | |
85638c0d | 169 | |
5248c961 RK |
170 | static struct ptt |
171 | { | |
d330fd93 | 172 | const char *name; /* Canonical processor name. */ |
5248c961 RK |
173 | enum processor_type processor; /* Processor type enum value. */ |
174 | int target_enable; /* Target flags to enable. */ | |
175 | int target_disable; /* Target flags to disable. */ | |
176 | } processor_target_table[] | |
cf27b467 MM |
177 | = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS, |
178 | POWER_MASKS | POWERPC_MASKS}, | |
db7f1e43 | 179 | {"power", PROCESSOR_POWER, |
938937d8 | 180 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 | 181 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
8e3f41e7 MM |
182 | {"power2", PROCESSOR_POWER, |
183 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
184 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, | |
db7f1e43 RK |
185 | {"powerpc", PROCESSOR_POWERPC, |
186 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
68c49ffa | 187 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
3cb999d8 DE |
188 | {"powerpc64", PROCESSOR_POWERPC64, |
189 | MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS, | |
190 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
db7f1e43 | 191 | {"rios", PROCESSOR_RIOS1, |
938937d8 | 192 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
193 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
194 | {"rios1", PROCESSOR_RIOS1, | |
938937d8 | 195 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
196 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
197 | {"rsc", PROCESSOR_PPC601, | |
938937d8 | 198 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
199 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
200 | {"rsc1", PROCESSOR_PPC601, | |
938937d8 | 201 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
202 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
203 | {"rios2", PROCESSOR_RIOS2, | |
938937d8 | 204 | MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2, |
db7f1e43 | 205 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
3cb999d8 DE |
206 | {"rs64a", PROCESSOR_RS64A, |
207 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
208 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
a3a1dbf6 MM |
209 | {"401", PROCESSOR_PPC403, |
210 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
211 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
49a0b204 | 212 | {"403", PROCESSOR_PPC403, |
daf11973 | 213 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN, |
49a0b204 | 214 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
cf27b467 MM |
215 | {"505", PROCESSOR_MPCCORE, |
216 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
217 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 218 | {"601", PROCESSOR_PPC601, |
938937d8 | 219 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING, |
68c49ffa | 220 | MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
1ec26da6 | 221 | {"602", PROCESSOR_PPC603, |
cf27b467 MM |
222 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
223 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
5248c961 | 224 | {"603", PROCESSOR_PPC603, |
68c49ffa RK |
225 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
226 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a MM |
227 | {"603e", PROCESSOR_PPC603, |
228 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
229 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b5370a88 | 230 | {"ec603e", PROCESSOR_PPC603, |
a3a1dbf6 MM |
231 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
232 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 233 | {"604", PROCESSOR_PPC604, |
b6c9286a MM |
234 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
235 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
cac8ce95 | 236 | {"604e", PROCESSOR_PPC604e, |
07e6159a MM |
237 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
238 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a | 239 | {"620", PROCESSOR_PPC620, |
68c49ffa | 240 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
a260abc9 | 241 | POWER_MASKS | MASK_PPC_GPOPT}, |
3cb999d8 DE |
242 | {"630", PROCESSOR_PPC630, |
243 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
244 | POWER_MASKS | MASK_PPC_GPOPT}, | |
bef84347 VM |
245 | {"740", PROCESSOR_PPC750, |
246 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
247 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
248 | {"750", PROCESSOR_PPC750, | |
249 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
250 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
07e6159a MM |
251 | {"801", PROCESSOR_MPCCORE, |
252 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
253 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
254 | {"821", PROCESSOR_MPCCORE, |
255 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
256 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
07e6159a MM |
257 | {"823", PROCESSOR_MPCCORE, |
258 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
259 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
260 | {"860", PROCESSOR_MPCCORE, |
261 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
262 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}}; | |
5248c961 | 263 | |
c4d38ccb | 264 | size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt); |
5248c961 | 265 | |
8a61d227 | 266 | int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */ |
938937d8 | 267 | int string = TARGET_STRING; /* save current -mstring/-mno-string status */ |
8a61d227 | 268 | |
5248c961 RK |
269 | profile_block_flag = 0; |
270 | ||
271 | /* Identify the processor type */ | |
8e3f41e7 | 272 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 273 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 MM |
274 | |
275 | for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++) | |
5248c961 | 276 | { |
8e3f41e7 MM |
277 | ptr = &rs6000_select[i]; |
278 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 279 | { |
8e3f41e7 MM |
280 | for (j = 0; j < ptt_size; j++) |
281 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
282 | { | |
283 | if (ptr->set_tune_p) | |
284 | rs6000_cpu = processor_target_table[j].processor; | |
285 | ||
286 | if (ptr->set_arch_p) | |
287 | { | |
288 | target_flags |= processor_target_table[j].target_enable; | |
289 | target_flags &= ~processor_target_table[j].target_disable; | |
290 | } | |
291 | break; | |
292 | } | |
293 | ||
4406229e | 294 | if (j == ptt_size) |
8e3f41e7 | 295 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
296 | } |
297 | } | |
8a61d227 | 298 | |
ef792183 MM |
299 | /* If we are optimizing big endian systems for space, use the |
300 | store multiple instructions. */ | |
301 | if (BYTES_BIG_ENDIAN && optimize_size) | |
302 | target_flags |= MASK_MULTIPLE; | |
303 | ||
8a61d227 MM |
304 | /* If -mmultiple or -mno-multiple was explicitly used, don't |
305 | override with the processor default */ | |
306 | if (TARGET_MULTIPLE_SET) | |
307 | target_flags = (target_flags & ~MASK_MULTIPLE) | multiple; | |
7e69e155 | 308 | |
938937d8 MM |
309 | /* If -mstring or -mno-string was explicitly used, don't |
310 | override with the processor default */ | |
311 | if (TARGET_STRING_SET) | |
1f5515bf | 312 | target_flags = (target_flags & ~MASK_STRING) | string; |
938937d8 | 313 | |
bef84347 VM |
314 | /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu |
315 | is a 750, because the hardware doesn't support the instructions used in | |
316 | little endian mode, and causes an alignment trap. The 750 does not cause | |
317 | an alignment trap (except when the target is unaligned). */ | |
318 | ||
bfc79d3b | 319 | if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
320 | { |
321 | if (TARGET_MULTIPLE) | |
322 | { | |
323 | target_flags &= ~MASK_MULTIPLE; | |
324 | if (TARGET_MULTIPLE_SET) | |
325 | warning ("-mmultiple is not supported on little endian systems"); | |
326 | } | |
327 | ||
328 | if (TARGET_STRING) | |
329 | { | |
330 | target_flags &= ~MASK_STRING; | |
938937d8 MM |
331 | if (TARGET_STRING_SET) |
332 | warning ("-mstring is not supported on little endian systems"); | |
7e69e155 MM |
333 | } |
334 | } | |
3933e0e1 | 335 | |
a260abc9 DE |
336 | if (flag_pic && (DEFAULT_ABI == ABI_AIX)) |
337 | { | |
338 | warning ("-f%s ignored for AIX (all code is position independent)", | |
339 | (flag_pic > 1) ? "PIC" : "pic"); | |
340 | flag_pic = 0; | |
341 | } | |
342 | ||
38c1f2d7 MM |
343 | /* Set debug flags */ |
344 | if (rs6000_debug_name) | |
345 | { | |
bfc79d3b | 346 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 347 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 348 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 349 | rs6000_debug_stack = 1; |
bfc79d3b | 350 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
351 | rs6000_debug_arg = 1; |
352 | else | |
353 | error ("Unknown -mdebug-%s switch", rs6000_debug_name); | |
354 | } | |
355 | ||
c81bebd7 MM |
356 | #ifdef TARGET_REGNAMES |
357 | /* If the user desires alternate register names, copy in the alternate names | |
358 | now. */ | |
359 | if (TARGET_REGNAMES) | |
bfc79d3b DE |
360 | bcopy ((char *)alt_reg_names, (char *)rs6000_reg_names, |
361 | sizeof (rs6000_reg_names)); | |
c81bebd7 MM |
362 | #endif |
363 | ||
3933e0e1 MM |
364 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
365 | SUBTARGET_OVERRIDE_OPTIONS; | |
366 | #endif | |
5248c961 | 367 | } |
5accd822 DE |
368 | |
369 | void | |
370 | optimization_options (level, size) | |
371 | int level; | |
372 | int size ATTRIBUTE_UNUSED; | |
373 | { | |
fca812fa | 374 | #ifdef HAVE_decrement_and_branch_on_count |
5accd822 DE |
375 | /* When optimizing, enable use of BCT instruction. */ |
376 | if (level >= 1) | |
377 | flag_branch_on_count_reg = 1; | |
378 | #endif | |
5accd822 | 379 | } |
3cfa4909 MM |
380 | \f |
381 | /* Do anything needed at the start of the asm file. */ | |
382 | ||
383 | void | |
384 | rs6000_file_start (file, default_cpu) | |
385 | FILE *file; | |
d330fd93 | 386 | const char *default_cpu; |
3cfa4909 | 387 | { |
c4d38ccb | 388 | size_t i; |
3cfa4909 | 389 | char buffer[80]; |
d330fd93 | 390 | const char *start = buffer; |
3cfa4909 MM |
391 | struct rs6000_cpu_select *ptr; |
392 | ||
393 | if (flag_verbose_asm) | |
394 | { | |
395 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
396 | rs6000_select[0].string = default_cpu; | |
397 | ||
398 | for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++) | |
399 | { | |
400 | ptr = &rs6000_select[i]; | |
401 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
402 | { | |
403 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
404 | start = ""; | |
405 | } | |
406 | } | |
407 | ||
408 | #ifdef USING_SVR4_H | |
409 | switch (rs6000_sdata) | |
410 | { | |
411 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
412 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
413 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
414 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
415 | } | |
416 | ||
417 | if (rs6000_sdata && g_switch_value) | |
418 | { | |
419 | fprintf (file, "%s -G %d", start, g_switch_value); | |
420 | start = ""; | |
421 | } | |
422 | #endif | |
423 | ||
424 | if (*start == '\0') | |
949ea356 | 425 | putc ('\n', file); |
3cfa4909 MM |
426 | } |
427 | } | |
428 | ||
24d304eb RK |
429 | \f |
430 | /* Create a CONST_DOUBLE from a string. */ | |
431 | ||
432 | struct rtx_def * | |
433 | rs6000_float_const (string, mode) | |
d330fd93 | 434 | const char *string; |
24d304eb RK |
435 | enum machine_mode mode; |
436 | { | |
437 | REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode); | |
438 | return immed_real_const_1 (value, mode); | |
439 | } | |
5248c961 | 440 | \f |
9878760c RK |
441 | /* Return non-zero if this function is known to have a null epilogue. */ |
442 | ||
443 | int | |
444 | direct_return () | |
445 | { | |
4697a36c MM |
446 | if (reload_completed) |
447 | { | |
448 | rs6000_stack_t *info = rs6000_stack_info (); | |
449 | ||
450 | if (info->first_gp_reg_save == 32 | |
451 | && info->first_fp_reg_save == 64 | |
452 | && !info->lr_save_p | |
1b4a2731 | 453 | && !info->cr_save_p |
4697a36c MM |
454 | && !info->push_p) |
455 | return 1; | |
456 | } | |
457 | ||
458 | return 0; | |
9878760c RK |
459 | } |
460 | ||
461 | /* Returns 1 always. */ | |
462 | ||
463 | int | |
464 | any_operand (op, mode) | |
296b8152 KG |
465 | register rtx op ATTRIBUTE_UNUSED; |
466 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
9878760c RK |
467 | { |
468 | return 1; | |
469 | } | |
470 | ||
b6c9286a | 471 | /* Returns 1 if op is the count register */ |
38c1f2d7 MM |
472 | int |
473 | count_register_operand(op, mode) | |
b6c9286a | 474 | register rtx op; |
296b8152 | 475 | enum machine_mode mode ATTRIBUTE_UNUSED; |
b6c9286a MM |
476 | { |
477 | if (GET_CODE (op) != REG) | |
478 | return 0; | |
479 | ||
480 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
481 | return 1; | |
482 | ||
483 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
484 | return 1; | |
485 | ||
486 | return 0; | |
487 | } | |
488 | ||
802a0058 MM |
489 | /* Returns 1 if op is memory location for float/int conversions that masquerades |
490 | as a register. */ | |
38c1f2d7 MM |
491 | int |
492 | fpmem_operand(op, mode) | |
802a0058 | 493 | register rtx op; |
296b8152 | 494 | enum machine_mode mode ATTRIBUTE_UNUSED; |
802a0058 MM |
495 | { |
496 | if (GET_CODE (op) != REG) | |
497 | return 0; | |
498 | ||
499 | if (FPMEM_REGNO_P (REGNO (op))) | |
500 | return 1; | |
501 | ||
502 | #if 0 | |
503 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
504 | return 1; | |
505 | #endif | |
506 | ||
507 | return 0; | |
508 | } | |
509 | ||
9878760c RK |
510 | /* Return 1 if OP is a constant that can fit in a D field. */ |
511 | ||
512 | int | |
513 | short_cint_operand (op, mode) | |
514 | register rtx op; | |
296b8152 | 515 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 516 | { |
5f59ecb7 DE |
517 | return (GET_CODE (op) == CONST_INT |
518 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
519 | } |
520 | ||
521 | /* Similar for a unsigned D field. */ | |
522 | ||
523 | int | |
524 | u_short_cint_operand (op, mode) | |
525 | register rtx op; | |
296b8152 | 526 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 527 | { |
19684119 | 528 | return (GET_CODE (op) == CONST_INT |
5f59ecb7 | 529 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')); |
9878760c RK |
530 | } |
531 | ||
dcfedcd0 RK |
532 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
533 | ||
534 | int | |
535 | non_short_cint_operand (op, mode) | |
536 | register rtx op; | |
296b8152 | 537 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
538 | { |
539 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 540 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
541 | } |
542 | ||
9878760c RK |
543 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
544 | ctr, or lr). */ | |
545 | ||
546 | int | |
cd2b37d9 | 547 | gpc_reg_operand (op, mode) |
9878760c RK |
548 | register rtx op; |
549 | enum machine_mode mode; | |
550 | { | |
551 | return (register_operand (op, mode) | |
802a0058 MM |
552 | && (GET_CODE (op) != REG |
553 | || (REGNO (op) >= 67 && !FPMEM_REGNO_P (REGNO (op))) | |
554 | || REGNO (op) < 64)); | |
9878760c RK |
555 | } |
556 | ||
557 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
558 | CR field. */ | |
559 | ||
560 | int | |
561 | cc_reg_operand (op, mode) | |
562 | register rtx op; | |
563 | enum machine_mode mode; | |
564 | { | |
565 | return (register_operand (op, mode) | |
566 | && (GET_CODE (op) != REG | |
567 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
568 | || CR_REGNO_P (REGNO (op)))); | |
569 | } | |
570 | ||
815cdc52 MM |
571 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
572 | CR field that isn't CR0. */ | |
573 | ||
574 | int | |
575 | cc_reg_not_cr0_operand (op, mode) | |
576 | register rtx op; | |
577 | enum machine_mode mode; | |
578 | { | |
579 | return (register_operand (op, mode) | |
580 | && (GET_CODE (op) != REG | |
581 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
582 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
583 | } | |
584 | ||
9878760c RK |
585 | /* Returns 1 if OP is either a constant integer valid for a D-field or a |
586 | non-special register. If a register, it must be in the proper mode unless | |
587 | MODE is VOIDmode. */ | |
588 | ||
589 | int | |
590 | reg_or_short_operand (op, mode) | |
591 | register rtx op; | |
592 | enum machine_mode mode; | |
593 | { | |
f5a28898 | 594 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
595 | } |
596 | ||
597 | /* Similar, except check if the negation of the constant would be valid for | |
598 | a D-field. */ | |
599 | ||
600 | int | |
601 | reg_or_neg_short_operand (op, mode) | |
602 | register rtx op; | |
603 | enum machine_mode mode; | |
604 | { | |
605 | if (GET_CODE (op) == CONST_INT) | |
606 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'); | |
607 | ||
cd2b37d9 | 608 | return gpc_reg_operand (op, mode); |
9878760c RK |
609 | } |
610 | ||
611 | /* Return 1 if the operand is either a register or an integer whose high-order | |
612 | 16 bits are zero. */ | |
613 | ||
614 | int | |
615 | reg_or_u_short_operand (op, mode) | |
616 | register rtx op; | |
617 | enum machine_mode mode; | |
618 | { | |
e675f625 | 619 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
620 | } |
621 | ||
622 | /* Return 1 is the operand is either a non-special register or ANY | |
623 | constant integer. */ | |
624 | ||
625 | int | |
626 | reg_or_cint_operand (op, mode) | |
627 | register rtx op; | |
628 | enum machine_mode mode; | |
629 | { | |
e675f625 | 630 | return (GET_CODE (op) == CONST_INT |
e675f625 | 631 | || gpc_reg_operand (op, mode)); |
9878760c RK |
632 | } |
633 | ||
766a866c MM |
634 | /* Return 1 if the operand is an operand that can be loaded via the GOT */ |
635 | ||
636 | int | |
637 | got_operand (op, mode) | |
638 | register rtx op; | |
296b8152 | 639 | enum machine_mode mode ATTRIBUTE_UNUSED; |
766a866c MM |
640 | { |
641 | return (GET_CODE (op) == SYMBOL_REF | |
642 | || GET_CODE (op) == CONST | |
643 | || GET_CODE (op) == LABEL_REF); | |
644 | } | |
645 | ||
38c1f2d7 MM |
646 | /* Return 1 if the operand is a simple references that can be loaded via |
647 | the GOT (labels involving addition aren't allowed). */ | |
648 | ||
649 | int | |
650 | got_no_const_operand (op, mode) | |
651 | register rtx op; | |
296b8152 | 652 | enum machine_mode mode ATTRIBUTE_UNUSED; |
38c1f2d7 MM |
653 | { |
654 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
655 | } | |
656 | ||
4e74d8ec MM |
657 | /* Return the number of instructions it takes to form a constant in an |
658 | integer register. */ | |
659 | ||
660 | static int | |
661 | num_insns_constant_wide (value) | |
662 | HOST_WIDE_INT value; | |
663 | { | |
664 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 665 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
666 | return 1; |
667 | ||
4e74d8ec | 668 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 669 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
670 | return 1; |
671 | ||
5f59ecb7 | 672 | #if HOST_BITS_PER_WIDE_INT == 64 |
4e74d8ec MM |
673 | else if (TARGET_64BIT) |
674 | { | |
675 | HOST_WIDE_INT low = value & 0xffffffff; | |
676 | HOST_WIDE_INT high = value >> 32; | |
677 | ||
678 | if (high == 0 && (low & 0x80000000) == 0) | |
679 | return 2; | |
680 | ||
681 | else if (high == 0xffffffff && (low & 0x80000000) != 0) | |
682 | return 2; | |
683 | ||
684 | else if (!low) | |
685 | return num_insns_constant_wide (high) + 1; | |
686 | ||
687 | else | |
688 | return (num_insns_constant_wide (high) | |
e396202a | 689 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
690 | } |
691 | #endif | |
692 | ||
693 | else | |
694 | return 2; | |
695 | } | |
696 | ||
697 | int | |
698 | num_insns_constant (op, mode) | |
699 | rtx op; | |
700 | enum machine_mode mode; | |
701 | { | |
4e74d8ec MM |
702 | if (GET_CODE (op) == CONST_INT) |
703 | return num_insns_constant_wide (INTVAL (op)); | |
704 | ||
6fc48950 MM |
705 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
706 | { | |
707 | long l; | |
708 | REAL_VALUE_TYPE rv; | |
709 | ||
710 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
711 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
712 | return num_insns_constant_wide ((HOST_WIDE_INT)l); | |
713 | } | |
714 | ||
47ad8c61 | 715 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 716 | { |
47ad8c61 MM |
717 | HOST_WIDE_INT low; |
718 | HOST_WIDE_INT high; | |
719 | long l[2]; | |
720 | REAL_VALUE_TYPE rv; | |
721 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 722 | |
47ad8c61 MM |
723 | if (mode == VOIDmode || mode == DImode) |
724 | { | |
725 | high = CONST_DOUBLE_HIGH (op); | |
726 | low = CONST_DOUBLE_LOW (op); | |
727 | } | |
728 | else | |
729 | { | |
730 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
731 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
732 | high = l[endian]; | |
733 | low = l[1 - endian]; | |
734 | } | |
4e74d8ec | 735 | |
47ad8c61 MM |
736 | if (TARGET_32BIT) |
737 | return (num_insns_constant_wide (low) | |
738 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
739 | |
740 | else | |
47ad8c61 MM |
741 | { |
742 | if (high == 0 && (low & 0x80000000) == 0) | |
743 | return num_insns_constant_wide (low); | |
744 | ||
745 | else if (((high & 0xffffffff) == 0xffffffff) | |
746 | && ((low & 0x80000000) != 0)) | |
747 | return num_insns_constant_wide (low); | |
748 | ||
a260abc9 DE |
749 | else if (mask64_operand (op, mode)) |
750 | return 2; | |
751 | ||
47ad8c61 MM |
752 | else if (low == 0) |
753 | return num_insns_constant_wide (high) + 1; | |
754 | ||
755 | else | |
756 | return (num_insns_constant_wide (high) | |
757 | + num_insns_constant_wide (low) + 1); | |
758 | } | |
4e74d8ec MM |
759 | } |
760 | ||
761 | else | |
762 | abort (); | |
763 | } | |
764 | ||
6f2f8311 RK |
765 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register |
766 | with one instruction per word. We only do this if we can safely read | |
767 | CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
768 | |
769 | int | |
770 | easy_fp_constant (op, mode) | |
771 | register rtx op; | |
772 | register enum machine_mode mode; | |
773 | { | |
9878760c RK |
774 | if (GET_CODE (op) != CONST_DOUBLE |
775 | || GET_MODE (op) != mode | |
4e74d8ec | 776 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
777 | return 0; |
778 | ||
b6c9286a | 779 | /* Consider all constants with -msoft-float to be easy */ |
4e74d8ec | 780 | if (TARGET_SOFT_FLOAT && mode != DImode) |
b6c9286a MM |
781 | return 1; |
782 | ||
a7273471 MM |
783 | /* If we are using V.4 style PIC, consider all constants to be hard */ |
784 | if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)) | |
785 | return 0; | |
786 | ||
5ae4759c MM |
787 | #ifdef TARGET_RELOCATABLE |
788 | /* Similarly if we are using -mrelocatable, consider all constants to be hard */ | |
789 | if (TARGET_RELOCATABLE) | |
790 | return 0; | |
791 | #endif | |
792 | ||
042259f2 DE |
793 | if (mode == DFmode) |
794 | { | |
795 | long k[2]; | |
796 | REAL_VALUE_TYPE rv; | |
797 | ||
798 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
799 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 800 | |
4e74d8ec MM |
801 | return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1 |
802 | && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1); | |
042259f2 | 803 | } |
4e74d8ec MM |
804 | |
805 | else if (mode == SFmode) | |
042259f2 DE |
806 | { |
807 | long l; | |
808 | REAL_VALUE_TYPE rv; | |
809 | ||
810 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
811 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 812 | |
4e74d8ec | 813 | return num_insns_constant_wide (l) == 1; |
042259f2 | 814 | } |
4e74d8ec | 815 | |
a260abc9 DE |
816 | else if (mode == DImode) |
817 | return ((TARGET_64BIT | |
818 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) | |
819 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec MM |
820 | |
821 | else | |
822 | abort (); | |
9878760c | 823 | } |
8f75773e | 824 | |
b6c9286a MM |
825 | /* Return 1 if the operand is in volatile memory. Note that during the |
826 | RTL generation phase, memory_operand does not return TRUE for | |
827 | volatile memory references. So this function allows us to | |
828 | recognize volatile references where its safe. */ | |
829 | ||
830 | int | |
831 | volatile_mem_operand (op, mode) | |
832 | register rtx op; | |
833 | enum machine_mode mode; | |
834 | { | |
835 | if (GET_CODE (op) != MEM) | |
836 | return 0; | |
837 | ||
838 | if (!MEM_VOLATILE_P (op)) | |
839 | return 0; | |
840 | ||
841 | if (mode != GET_MODE (op)) | |
842 | return 0; | |
843 | ||
844 | if (reload_completed) | |
845 | return memory_operand (op, mode); | |
846 | ||
847 | if (reload_in_progress) | |
848 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
849 | ||
850 | return memory_address_p (mode, XEXP (op, 0)); | |
851 | } | |
852 | ||
97f6e72f | 853 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
854 | |
855 | int | |
97f6e72f | 856 | offsettable_mem_operand (op, mode) |
914c2e77 RK |
857 | register rtx op; |
858 | enum machine_mode mode; | |
859 | { | |
97f6e72f | 860 | return ((GET_CODE (op) == MEM) |
677a9668 | 861 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 862 | mode, XEXP (op, 0))); |
914c2e77 RK |
863 | } |
864 | ||
9878760c RK |
865 | /* Return 1 if the operand is either an easy FP constant (see above) or |
866 | memory. */ | |
867 | ||
868 | int | |
869 | mem_or_easy_const_operand (op, mode) | |
870 | register rtx op; | |
871 | enum machine_mode mode; | |
872 | { | |
873 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
874 | } | |
875 | ||
876 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 877 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
878 | |
879 | int | |
880 | add_operand (op, mode) | |
881 | register rtx op; | |
882 | enum machine_mode mode; | |
883 | { | |
884 | return (reg_or_short_operand (op, mode) | |
19684119 | 885 | || (GET_CODE (op) == CONST_INT |
5f59ecb7 | 886 | && CONST_OK_FOR_LETTER_P (INTVAL(op), 'L'))); |
9878760c RK |
887 | } |
888 | ||
dcfedcd0 RK |
889 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
890 | ||
891 | int | |
892 | non_add_cint_operand (op, mode) | |
893 | register rtx op; | |
296b8152 | 894 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
895 | { |
896 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 897 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000 |
5f59ecb7 | 898 | && ! CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')); |
dcfedcd0 RK |
899 | } |
900 | ||
9878760c RK |
901 | /* Return 1 if the operand is a non-special register or a constant that |
902 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
903 | ||
904 | int | |
905 | logical_operand (op, mode) | |
906 | register rtx op; | |
907 | enum machine_mode mode; | |
908 | { | |
cd2b37d9 | 909 | return (gpc_reg_operand (op, mode) |
9878760c | 910 | || (GET_CODE (op) == CONST_INT |
5f59ecb7 DE |
911 | && ((INTVAL (op) & GET_MODE_MASK (mode) |
912 | & (~ (HOST_WIDE_INT) 0xffff)) == 0 | |
913 | || (INTVAL (op) & GET_MODE_MASK (mode) | |
914 | & (~ (HOST_WIDE_INT) 0xffff0000)) == 0))); | |
9878760c RK |
915 | } |
916 | ||
dcfedcd0 RK |
917 | /* Return 1 if C is a constant that is not a logical operand (as |
918 | above). */ | |
919 | ||
920 | int | |
921 | non_logical_cint_operand (op, mode) | |
922 | register rtx op; | |
5f59ecb7 | 923 | enum machine_mode mode; |
dcfedcd0 RK |
924 | { |
925 | return (GET_CODE (op) == CONST_INT | |
5f59ecb7 DE |
926 | && (INTVAL (op) & GET_MODE_MASK (mode) & |
927 | (~ (HOST_WIDE_INT) 0xffff)) != 0 | |
928 | && (INTVAL (op) & GET_MODE_MASK (mode) & | |
929 | (~ (HOST_WIDE_INT) 0xffff0000)) != 0); | |
dcfedcd0 RK |
930 | } |
931 | ||
19ba8161 | 932 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
933 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
934 | Reject all ones and all zeros, since these should have been optimized | |
935 | away and confuse the making of MB and ME. */ | |
936 | ||
937 | int | |
19ba8161 DE |
938 | mask_operand (op, mode) |
939 | register rtx op; | |
940 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
9878760c | 941 | { |
19ba8161 | 942 | HOST_WIDE_INT c; |
9878760c RK |
943 | int i; |
944 | int last_bit_value; | |
945 | int transitions = 0; | |
946 | ||
19ba8161 DE |
947 | if (GET_CODE (op) != CONST_INT) |
948 | return 0; | |
949 | ||
950 | c = INTVAL (op); | |
951 | ||
9878760c RK |
952 | if (c == 0 || c == ~0) |
953 | return 0; | |
954 | ||
955 | last_bit_value = c & 1; | |
956 | ||
957 | for (i = 1; i < 32; i++) | |
958 | if (((c >>= 1) & 1) != last_bit_value) | |
959 | last_bit_value ^= 1, transitions++; | |
960 | ||
961 | return transitions <= 2; | |
962 | } | |
963 | ||
a260abc9 DE |
964 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
965 | It is if there are no more than one 1->0 or 0->1 transitions. | |
966 | Reject all ones and all zeros, since these should have been optimized | |
967 | away and confuse the making of MB and ME. */ | |
9878760c RK |
968 | |
969 | int | |
a260abc9 DE |
970 | mask64_operand (op, mode) |
971 | register rtx op; | |
972 | enum machine_mode mode; | |
973 | { | |
974 | if (GET_CODE (op) == CONST_INT) | |
975 | { | |
976 | HOST_WIDE_INT c = INTVAL (op); | |
977 | int i; | |
978 | int last_bit_value; | |
979 | int transitions = 0; | |
980 | ||
981 | if (c == 0 || c == ~0) | |
982 | return 0; | |
983 | ||
984 | last_bit_value = c & 1; | |
985 | ||
986 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
987 | if (((c >>= 1) & 1) != last_bit_value) | |
988 | last_bit_value ^= 1, transitions++; | |
989 | ||
a238cd8b | 990 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
991 | /* Consider CONST_INT sign-extended. */ |
992 | transitions += (last_bit_value != 1); | |
993 | #endif | |
994 | ||
995 | return transitions <= 1; | |
996 | } | |
997 | else if (GET_CODE (op) == CONST_DOUBLE | |
998 | && (mode == VOIDmode || mode == DImode)) | |
999 | { | |
1000 | HOST_WIDE_INT low = CONST_DOUBLE_LOW (op); | |
a238cd8b | 1001 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1002 | HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op); |
1003 | #endif | |
1004 | int i; | |
1005 | int last_bit_value; | |
1006 | int transitions = 0; | |
1007 | ||
1008 | if ((low == 0 | |
a238cd8b | 1009 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1010 | && high == 0 |
1011 | #endif | |
1012 | ) | |
1013 | || (low == ~0 | |
a238cd8b | 1014 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1015 | && high == ~0 |
1016 | #endif | |
1017 | )) | |
1018 | return 0; | |
1019 | ||
1020 | last_bit_value = low & 1; | |
1021 | ||
1022 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1023 | if (((low >>= 1) & 1) != last_bit_value) | |
1024 | last_bit_value ^= 1, transitions++; | |
1025 | ||
a238cd8b | 1026 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
1027 | if ((high & 1) != last_bit_value) |
1028 | last_bit_value ^= 1, transitions++; | |
1029 | ||
1030 | for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++) | |
1031 | if (((high >>= 1) & 1) != last_bit_value) | |
1032 | last_bit_value ^= 1, transitions++; | |
1033 | #endif | |
1034 | ||
1035 | return transitions <= 1; | |
1036 | } | |
1037 | else | |
1038 | return 0; | |
1039 | } | |
1040 | ||
1041 | /* Return 1 if the operand is either a non-special register or a constant | |
1042 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
1043 | ||
1044 | int | |
1045 | and64_operand (op, mode) | |
9878760c RK |
1046 | register rtx op; |
1047 | enum machine_mode mode; | |
1048 | { | |
52d3af72 DE |
1049 | if (fixed_regs[68]) /* CR0 not available, don't do andi./andis. */ |
1050 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); | |
1051 | ||
1052 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
1053 | } |
1054 | ||
a260abc9 DE |
1055 | /* Return 1 if the operand is either a non-special register or a |
1056 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
1057 | |
1058 | int | |
a260abc9 DE |
1059 | and_operand (op, mode) |
1060 | register rtx op; | |
1061 | enum machine_mode mode; | |
dcfedcd0 | 1062 | { |
52d3af72 DE |
1063 | if (fixed_regs[68]) /* CR0 not available, don't do andi./andis. */ |
1064 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); | |
1065 | ||
1066 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
1067 | } |
1068 | ||
9878760c RK |
1069 | /* Return 1 if the operand is a general register or memory operand. */ |
1070 | ||
1071 | int | |
1072 | reg_or_mem_operand (op, mode) | |
1073 | register rtx op; | |
1074 | register enum machine_mode mode; | |
1075 | { | |
b6c9286a MM |
1076 | return (gpc_reg_operand (op, mode) |
1077 | || memory_operand (op, mode) | |
1078 | || volatile_mem_operand (op, mode)); | |
9878760c RK |
1079 | } |
1080 | ||
a7a813f7 | 1081 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 1082 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
1083 | instruction. */ |
1084 | ||
1085 | int | |
1086 | lwa_operand (op, mode) | |
1087 | register rtx op; | |
1088 | register enum machine_mode mode; | |
1089 | { | |
1090 | rtx inner = op; | |
1091 | ||
1092 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
1093 | inner = SUBREG_REG (inner); | |
1094 | ||
1095 | return gpc_reg_operand (inner, mode) | |
1096 | || (memory_operand (inner, mode) | |
1097 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
1098 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC); | |
1099 | } | |
1100 | ||
9878760c RK |
1101 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
1102 | to CALL. This is a SYMBOL_REF or a pseudo-register, which will be | |
1103 | forced to lr. */ | |
1104 | ||
1105 | int | |
1106 | call_operand (op, mode) | |
1107 | register rtx op; | |
1108 | enum machine_mode mode; | |
1109 | { | |
1110 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
1111 | return 0; | |
1112 | ||
1113 | return (GET_CODE (op) == SYMBOL_REF | |
1114 | || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER)); | |
1115 | } | |
1116 | ||
2af3d377 RK |
1117 | |
1118 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in | |
8f1b829e | 1119 | this file and the function is not weakly defined. */ |
2af3d377 RK |
1120 | |
1121 | int | |
1122 | current_file_function_operand (op, mode) | |
1123 | register rtx op; | |
296b8152 | 1124 | enum machine_mode mode ATTRIBUTE_UNUSED; |
2af3d377 RK |
1125 | { |
1126 | return (GET_CODE (op) == SYMBOL_REF | |
1127 | && (SYMBOL_REF_FLAG (op) | |
8f1b829e DJ |
1128 | || (op == XEXP (DECL_RTL (current_function_decl), 0) |
1129 | && !DECL_WEAK (current_function_decl)))); | |
2af3d377 RK |
1130 | } |
1131 | ||
1132 | ||
9878760c RK |
1133 | /* Return 1 if this operand is a valid input for a move insn. */ |
1134 | ||
1135 | int | |
1136 | input_operand (op, mode) | |
1137 | register rtx op; | |
1138 | enum machine_mode mode; | |
1139 | { | |
eb4e8003 | 1140 | /* Memory is always valid. */ |
9878760c RK |
1141 | if (memory_operand (op, mode)) |
1142 | return 1; | |
1143 | ||
34792e82 | 1144 | /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */ |
01b4cf2b | 1145 | if (GET_CODE (op) == CONSTANT_P_RTX) |
34792e82 JL |
1146 | return 1; |
1147 | ||
eb4e8003 RK |
1148 | /* For floating-point, easy constants are valid. */ |
1149 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
1150 | && CONSTANT_P (op) | |
1151 | && easy_fp_constant (op, mode)) | |
1152 | return 1; | |
1153 | ||
4e74d8ec MM |
1154 | /* Allow any integer constant. */ |
1155 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 1156 | && (GET_CODE (op) == CONST_INT |
e675f625 | 1157 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
1158 | return 1; |
1159 | ||
eb4e8003 RK |
1160 | /* For floating-point or multi-word mode, the only remaining valid type |
1161 | is a register. */ | |
9878760c RK |
1162 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
1163 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 1164 | return register_operand (op, mode); |
9878760c | 1165 | |
88fe15a1 RK |
1166 | /* The only cases left are integral modes one word or smaller (we |
1167 | do not get called for MODE_CC values). These can be in any | |
1168 | register. */ | |
1169 | if (register_operand (op, mode)) | |
a8b3aeda | 1170 | return 1; |
88fe15a1 | 1171 | |
84cf9dda | 1172 | /* A SYMBOL_REF referring to the TOC is valid. */ |
7fec4abd | 1173 | if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op)) |
84cf9dda RK |
1174 | return 1; |
1175 | ||
b6c9286a MM |
1176 | /* Windows NT allows SYMBOL_REFs and LABEL_REFs against the TOC |
1177 | directly in the instruction stream */ | |
1178 | if (DEFAULT_ABI == ABI_NT | |
1179 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)) | |
1180 | return 1; | |
1181 | ||
88228c4b MM |
1182 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
1183 | to be valid. */ | |
c81bebd7 | 1184 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
88228c4b MM |
1185 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
1186 | && small_data_operand (op, Pmode)) | |
1187 | return 1; | |
1188 | ||
042259f2 | 1189 | return 0; |
9878760c | 1190 | } |
7509c759 MM |
1191 | |
1192 | /* Return 1 for an operand in small memory on V.4/eabi */ | |
1193 | ||
1194 | int | |
1195 | small_data_operand (op, mode) | |
296b8152 KG |
1196 | rtx op ATTRIBUTE_UNUSED; |
1197 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
7509c759 | 1198 | { |
38c1f2d7 | 1199 | #if TARGET_ELF |
5f59ecb7 | 1200 | rtx sym_ref; |
7509c759 | 1201 | |
d9407988 | 1202 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 1203 | return 0; |
a54d04b7 | 1204 | |
5b9d9a0c | 1205 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
7509c759 MM |
1206 | return 0; |
1207 | ||
88228c4b MM |
1208 | if (GET_CODE (op) == SYMBOL_REF) |
1209 | sym_ref = op; | |
1210 | ||
1211 | else if (GET_CODE (op) != CONST | |
1212 | || GET_CODE (XEXP (op, 0)) != PLUS | |
1213 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
1214 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
1215 | return 0; |
1216 | ||
88228c4b | 1217 | else |
dbf55e53 MM |
1218 | { |
1219 | rtx sum = XEXP (op, 0); | |
1220 | HOST_WIDE_INT summand; | |
1221 | ||
1222 | /* We have to be careful here, because it is the referenced address | |
1223 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
1224 | summand = INTVAL (XEXP (sum, 1)); | |
1225 | if (summand < 0 || summand > g_switch_value) | |
1226 | return 0; | |
1227 | ||
1228 | sym_ref = XEXP (sum, 0); | |
1229 | } | |
88228c4b MM |
1230 | |
1231 | if (*XSTR (sym_ref, 0) != '@') | |
7509c759 MM |
1232 | return 0; |
1233 | ||
1234 | return 1; | |
d9407988 MM |
1235 | |
1236 | #else | |
1237 | return 0; | |
1238 | #endif | |
7509c759 MM |
1239 | } |
1240 | ||
4697a36c MM |
1241 | \f |
1242 | /* Initialize a variable CUM of type CUMULATIVE_ARGS | |
1243 | for a call to a function whose data type is FNTYPE. | |
1244 | For a library call, FNTYPE is 0. | |
1245 | ||
1246 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 1247 | so we never return a PARALLEL. */ |
4697a36c MM |
1248 | |
1249 | void | |
1250 | init_cumulative_args (cum, fntype, libname, incoming) | |
1251 | CUMULATIVE_ARGS *cum; | |
1252 | tree fntype; | |
296b8152 | 1253 | rtx libname ATTRIBUTE_UNUSED; |
4697a36c MM |
1254 | int incoming; |
1255 | { | |
1256 | static CUMULATIVE_ARGS zero_cumulative; | |
7509c759 | 1257 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c MM |
1258 | |
1259 | *cum = zero_cumulative; | |
1260 | cum->words = 0; | |
1261 | cum->fregno = FP_ARG_MIN_REG; | |
1262 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); | |
7509c759 | 1263 | cum->call_cookie = CALL_NORMAL; |
4cc833b7 | 1264 | cum->sysv_gregno = GP_ARG_MIN_REG; |
4697a36c MM |
1265 | |
1266 | if (incoming) | |
bd227acc | 1267 | cum->nargs_prototype = 1000; /* don't return a PARALLEL */ |
4697a36c MM |
1268 | |
1269 | else if (cum->prototype) | |
1270 | cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1 | |
1271 | + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode | |
1272 | || RETURN_IN_MEMORY (TREE_TYPE (fntype)))); | |
1273 | ||
1274 | else | |
1275 | cum->nargs_prototype = 0; | |
1276 | ||
1277 | cum->orig_nargs = cum->nargs_prototype; | |
7509c759 MM |
1278 | |
1279 | /* Check for DLL import functions */ | |
1280 | if (abi == ABI_NT | |
1281 | && fntype | |
1282 | && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (fntype))) | |
1283 | cum->call_cookie = CALL_NT_DLLIMPORT; | |
1284 | ||
6a4cee5f MM |
1285 | /* Also check for longcall's */ |
1286 | else if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))) | |
1287 | cum->call_cookie = CALL_LONG; | |
1288 | ||
4697a36c MM |
1289 | if (TARGET_DEBUG_ARG) |
1290 | { | |
1291 | fprintf (stderr, "\ninit_cumulative_args:"); | |
1292 | if (fntype) | |
1293 | { | |
1294 | tree ret_type = TREE_TYPE (fntype); | |
1295 | fprintf (stderr, " ret code = %s,", | |
1296 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
1297 | } | |
1298 | ||
6a4cee5f | 1299 | if (cum->call_cookie & CALL_NT_DLLIMPORT) |
7509c759 | 1300 | fprintf (stderr, " dllimport,"); |
4697a36c | 1301 | |
6a4cee5f MM |
1302 | if (cum->call_cookie & CALL_LONG) |
1303 | fprintf (stderr, " longcall,"); | |
1304 | ||
4697a36c MM |
1305 | fprintf (stderr, " proto = %d, nargs = %d\n", |
1306 | cum->prototype, cum->nargs_prototype); | |
1307 | } | |
1308 | } | |
1309 | \f | |
c229cba9 DE |
1310 | /* If defined, a C expression which determines whether, and in which |
1311 | direction, to pad out an argument with extra space. The value | |
1312 | should be of type `enum direction': either `upward' to pad above | |
1313 | the argument, `downward' to pad below, or `none' to inhibit | |
1314 | padding. | |
1315 | ||
1316 | For the AIX ABI structs are always stored left shifted in their | |
1317 | argument slot. */ | |
1318 | ||
c4d38ccb | 1319 | int |
c229cba9 DE |
1320 | function_arg_padding (mode, type) |
1321 | enum machine_mode mode; | |
1322 | tree type; | |
1323 | { | |
c85f7c16 | 1324 | if (type != 0 && AGGREGATE_TYPE_P (type)) |
c4d38ccb | 1325 | return (int)upward; |
c229cba9 DE |
1326 | |
1327 | /* This is the default definition. */ | |
1328 | return (! BYTES_BIG_ENDIAN | |
c4d38ccb | 1329 | ? (int)upward |
c229cba9 DE |
1330 | : ((mode == BLKmode |
1331 | ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST | |
1332 | && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT)) | |
1333 | : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY) | |
c4d38ccb | 1334 | ? (int)downward : (int)upward)); |
c229cba9 DE |
1335 | } |
1336 | ||
b6c9286a MM |
1337 | /* If defined, a C expression that gives the alignment boundary, in bits, |
1338 | of an argument with the specified mode and type. If it is not defined, | |
1339 | PARM_BOUNDARY is used for all arguments. | |
1340 | ||
e1f83b4d MM |
1341 | Windows NT wants anything >= 8 bytes to be double word aligned. |
1342 | ||
2310f99a | 1343 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
1344 | |
1345 | int | |
1346 | function_arg_boundary (mode, type) | |
1347 | enum machine_mode mode; | |
1348 | tree type; | |
1349 | { | |
4cc833b7 RH |
1350 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
1351 | && (mode == DImode || mode == DFmode)) | |
e1f83b4d MM |
1352 | return 64; |
1353 | ||
b6c9286a MM |
1354 | if (DEFAULT_ABI != ABI_NT || TARGET_64BIT) |
1355 | return PARM_BOUNDARY; | |
1356 | ||
1357 | if (mode != BLKmode) | |
1358 | return (GET_MODE_SIZE (mode)) >= 8 ? 64 : 32; | |
1359 | ||
1360 | return (int_size_in_bytes (type) >= 8) ? 64 : 32; | |
1361 | } | |
1362 | \f | |
4697a36c MM |
1363 | /* Update the data in CUM to advance over an argument |
1364 | of mode MODE and data type TYPE. | |
1365 | (TYPE is null for libcalls where that information may not be available.) */ | |
1366 | ||
1367 | void | |
1368 | function_arg_advance (cum, mode, type, named) | |
1369 | CUMULATIVE_ARGS *cum; | |
1370 | enum machine_mode mode; | |
1371 | tree type; | |
1372 | int named; | |
1373 | { | |
1374 | cum->nargs_prototype--; | |
1375 | ||
c81bebd7 | 1376 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4697a36c | 1377 | { |
4cc833b7 RH |
1378 | if (TARGET_HARD_FLOAT |
1379 | && (mode == SFmode || mode == DFmode)) | |
4697a36c | 1380 | { |
4cc833b7 RH |
1381 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
1382 | cum->fregno++; | |
1383 | else | |
1384 | { | |
1385 | if (mode == DFmode) | |
1386 | cum->words += cum->words & 1; | |
1387 | cum->words += RS6000_ARG_SIZE (mode, type, 1); | |
1388 | } | |
4697a36c | 1389 | } |
4cc833b7 RH |
1390 | else |
1391 | { | |
1392 | int n_words; | |
1393 | int gregno = cum->sysv_gregno; | |
1394 | ||
1395 | /* Aggregates and IEEE quad get passed by reference. */ | |
1396 | if ((type && AGGREGATE_TYPE_P (type)) | |
1397 | || mode == TFmode) | |
1398 | n_words = 1; | |
1399 | else | |
1400 | n_words = RS6000_ARG_SIZE (mode, type, 1); | |
1401 | ||
1402 | /* Long long is put in odd registers. */ | |
1403 | if (n_words == 2 && (gregno & 1) == 0) | |
1404 | gregno += 1; | |
1405 | ||
1406 | /* Long long is not split between registers and stack. */ | |
1407 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) | |
1408 | { | |
1409 | /* Long long is aligned on the stack. */ | |
1410 | if (n_words == 2) | |
1411 | cum->words += cum->words & 1; | |
1412 | cum->words += n_words; | |
1413 | } | |
4697a36c | 1414 | |
4cc833b7 RH |
1415 | /* Note: continuing to accumulate gregno past when we've started |
1416 | spilling to the stack indicates the fact that we've started | |
1417 | spilling to the stack to expand_builtin_saveregs. */ | |
1418 | cum->sysv_gregno = gregno + n_words; | |
1419 | } | |
4697a36c | 1420 | |
4cc833b7 RH |
1421 | if (TARGET_DEBUG_ARG) |
1422 | { | |
1423 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
1424 | cum->words, cum->fregno); | |
1425 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
1426 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
1427 | fprintf (stderr, "mode = %4s, named = %d\n", | |
1428 | GET_MODE_NAME (mode), named); | |
1429 | } | |
4697a36c MM |
1430 | } |
1431 | else | |
4cc833b7 RH |
1432 | { |
1433 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
1434 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
1435 | cum->words += align; | |
4697a36c | 1436 | |
4cc833b7 RH |
1437 | if (named) |
1438 | { | |
1439 | cum->words += RS6000_ARG_SIZE (mode, type, named); | |
1440 | if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT) | |
1441 | cum->fregno++; | |
1442 | } | |
1443 | ||
1444 | if (TARGET_DEBUG_ARG) | |
1445 | { | |
1446 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
1447 | cum->words, cum->fregno); | |
1448 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
1449 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
1450 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
1451 | } | |
1452 | } | |
4697a36c MM |
1453 | } |
1454 | \f | |
1455 | /* Determine where to put an argument to a function. | |
1456 | Value is zero to push the argument on the stack, | |
1457 | or a hard register in which to store the argument. | |
1458 | ||
1459 | MODE is the argument's machine mode. | |
1460 | TYPE is the data type of the argument (as a tree). | |
1461 | This is null for libcalls where that information may | |
1462 | not be available. | |
1463 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
1464 | the preceding args and about the function being called. | |
1465 | NAMED is nonzero if this argument is a named parameter | |
1466 | (otherwise it is an extra parameter matching an ellipsis). | |
1467 | ||
1468 | On RS/6000 the first eight words of non-FP are normally in registers | |
1469 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
1470 | Under V.4, the first 8 FP args are in registers. | |
1471 | ||
1472 | If this is floating-point and no prototype is specified, we use | |
1473 | both an FP and integer register (or possibly FP reg and stack). Library | |
1474 | functions (when TYPE is zero) always have the proper types for args, | |
1475 | so we can pass the FP value just in one register. emit_library_function | |
1c20ae99 | 1476 | doesn't support PARALLEL anyway. */ |
4697a36c MM |
1477 | |
1478 | struct rtx_def * | |
1479 | function_arg (cum, mode, type, named) | |
1480 | CUMULATIVE_ARGS *cum; | |
1481 | enum machine_mode mode; | |
1482 | tree type; | |
1483 | int named; | |
1484 | { | |
4cc833b7 | 1485 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 1486 | |
4cc833b7 RH |
1487 | /* Return a marker to indicate whether CR1 needs to set or clear the bit |
1488 | that V.4 uses to say fp args were passed in registers. Assume that we | |
1489 | don't need the marker for software floating point, or compiler generated | |
1490 | library calls. */ | |
4697a36c MM |
1491 | if (mode == VOIDmode) |
1492 | { | |
c81bebd7 | 1493 | if ((abi == ABI_V4 || abi == ABI_SOLARIS) |
7509c759 MM |
1494 | && TARGET_HARD_FLOAT |
1495 | && cum->nargs_prototype < 0 | |
4697a36c | 1496 | && type && (cum->prototype || TARGET_NO_PROTOTYPE)) |
7509c759 | 1497 | { |
6a4cee5f MM |
1498 | return GEN_INT (cum->call_cookie |
1499 | | ((cum->fregno == FP_ARG_MIN_REG) | |
1500 | ? CALL_V4_SET_FP_ARGS | |
1501 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 1502 | } |
4697a36c | 1503 | |
7509c759 | 1504 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
1505 | } |
1506 | ||
4cc833b7 | 1507 | if (abi == ABI_V4 || abi == ABI_SOLARIS) |
4697a36c | 1508 | { |
4cc833b7 RH |
1509 | if (TARGET_HARD_FLOAT |
1510 | && (mode == SFmode || mode == DFmode)) | |
1511 | { | |
1512 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
1513 | return gen_rtx_REG (mode, cum->fregno); | |
1514 | else | |
1515 | return NULL; | |
1516 | } | |
1517 | else | |
1518 | { | |
1519 | int n_words; | |
1520 | int gregno = cum->sysv_gregno; | |
1521 | ||
1522 | /* Aggregates and IEEE quad get passed by reference. */ | |
1523 | if ((type && AGGREGATE_TYPE_P (type)) | |
1524 | || mode == TFmode) | |
1525 | n_words = 1; | |
1526 | else | |
1527 | n_words = RS6000_ARG_SIZE (mode, type, 1); | |
1528 | ||
1529 | /* Long long is put in odd registers. */ | |
1530 | if (n_words == 2 && (gregno & 1) == 0) | |
1531 | gregno += 1; | |
1532 | ||
1533 | /* Long long is not split between registers and stack. */ | |
1534 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
1535 | return gen_rtx_REG (mode, gregno); | |
1536 | else | |
1537 | return NULL; | |
1538 | } | |
4697a36c | 1539 | } |
4cc833b7 RH |
1540 | else |
1541 | { | |
1542 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
1543 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
1544 | int align_words = cum->words + align; | |
4697a36c | 1545 | |
4cc833b7 RH |
1546 | if (!named) |
1547 | return NULL_RTX; | |
4697a36c | 1548 | |
4cc833b7 RH |
1549 | if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
1550 | return NULL_RTX; | |
1551 | ||
1552 | if (USE_FP_FOR_ARG_P (*cum, mode, type)) | |
1553 | { | |
1554 | if (! type | |
1555 | || ((cum->nargs_prototype > 0) | |
1556 | /* IBM AIX extended its linkage convention definition always | |
1557 | to require FP args after register save area hole on the | |
1558 | stack. */ | |
1559 | && (DEFAULT_ABI != ABI_AIX | |
1560 | || ! TARGET_XL_CALL | |
1561 | || (align_words < GP_ARG_NUM_REG)))) | |
1562 | return gen_rtx_REG (mode, cum->fregno); | |
1563 | ||
1564 | return gen_rtx_PARALLEL (mode, | |
1565 | gen_rtvec (2, | |
39403d82 | 1566 | gen_rtx_EXPR_LIST (VOIDmode, |
1c20ae99 JW |
1567 | ((align_words >= GP_ARG_NUM_REG) |
1568 | ? NULL_RTX | |
1569 | : (align_words | |
1570 | + RS6000_ARG_SIZE (mode, type, named) | |
1571 | > GP_ARG_NUM_REG | |
1572 | /* If this is partially on the stack, then | |
1573 | we only include the portion actually | |
1574 | in registers here. */ | |
39403d82 | 1575 | ? gen_rtx_REG (SImode, |
1c20ae99 | 1576 | GP_ARG_MIN_REG + align_words) |
39403d82 | 1577 | : gen_rtx_REG (mode, |
1c20ae99 JW |
1578 | GP_ARG_MIN_REG + align_words))), |
1579 | const0_rtx), | |
39403d82 DE |
1580 | gen_rtx_EXPR_LIST (VOIDmode, |
1581 | gen_rtx_REG (mode, cum->fregno), | |
1c20ae99 | 1582 | const0_rtx))); |
4cc833b7 RH |
1583 | } |
1584 | else if (align_words < GP_ARG_NUM_REG) | |
1585 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
1586 | else | |
1587 | return NULL_RTX; | |
4697a36c | 1588 | } |
4697a36c MM |
1589 | } |
1590 | \f | |
1591 | /* For an arg passed partly in registers and partly in memory, | |
1592 | this is the number of registers used. | |
1593 | For args passed entirely in registers or entirely in memory, zero. */ | |
1594 | ||
1595 | int | |
1596 | function_arg_partial_nregs (cum, mode, type, named) | |
1597 | CUMULATIVE_ARGS *cum; | |
1598 | enum machine_mode mode; | |
1599 | tree type; | |
1600 | int named; | |
1601 | { | |
1602 | if (! named) | |
1603 | return 0; | |
1604 | ||
c81bebd7 | 1605 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4697a36c | 1606 | return 0; |
4697a36c MM |
1607 | |
1608 | if (USE_FP_FOR_ARG_P (*cum, mode, type)) | |
1609 | { | |
1610 | if (cum->nargs_prototype >= 0) | |
1611 | return 0; | |
1612 | } | |
1613 | ||
1614 | if (cum->words < GP_ARG_NUM_REG | |
1615 | && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named))) | |
1616 | { | |
1617 | int ret = GP_ARG_NUM_REG - cum->words; | |
1618 | if (ret && TARGET_DEBUG_ARG) | |
1619 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
1620 | ||
1621 | return ret; | |
1622 | } | |
1623 | ||
1624 | return 0; | |
1625 | } | |
1626 | \f | |
1627 | /* A C expression that indicates when an argument must be passed by | |
1628 | reference. If nonzero for an argument, a copy of that argument is | |
1629 | made in memory and a pointer to the argument is passed instead of | |
1630 | the argument itself. The pointer is passed in whatever way is | |
1631 | appropriate for passing a pointer to that type. | |
1632 | ||
1633 | Under V.4, structures and unions are passed by reference. */ | |
1634 | ||
1635 | int | |
1636 | function_arg_pass_by_reference (cum, mode, type, named) | |
296b8152 KG |
1637 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; |
1638 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4697a36c | 1639 | tree type; |
296b8152 | 1640 | int named ATTRIBUTE_UNUSED; |
4697a36c | 1641 | { |
c81bebd7 | 1642 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4cc833b7 RH |
1643 | && ((type && AGGREGATE_TYPE_P (type)) |
1644 | || mode == TFmode)) | |
4697a36c MM |
1645 | { |
1646 | if (TARGET_DEBUG_ARG) | |
1647 | fprintf (stderr, "function_arg_pass_by_reference: aggregate\n"); | |
1648 | ||
1649 | return 1; | |
1650 | } | |
4697a36c MM |
1651 | |
1652 | return 0; | |
1653 | } | |
1654 | ||
1655 | \f | |
1656 | /* Perform any needed actions needed for a function that is receiving a | |
1657 | variable number of arguments. | |
1658 | ||
1659 | CUM is as above. | |
1660 | ||
1661 | MODE and TYPE are the mode and type of the current parameter. | |
1662 | ||
1663 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
1664 | that must be pushed by the prolog to pretend that our caller pushed | |
1665 | it. | |
1666 | ||
1667 | Normally, this macro will push all remaining incoming registers on the | |
1668 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
1669 | ||
1670 | void | |
1671 | setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl) | |
1672 | CUMULATIVE_ARGS *cum; | |
1673 | enum machine_mode mode; | |
1674 | tree type; | |
1675 | int *pretend_size; | |
1676 | int no_rtl; | |
1677 | ||
1678 | { | |
4cc833b7 RH |
1679 | CUMULATIVE_ARGS next_cum; |
1680 | int reg_size = TARGET_32BIT ? 4 : 8; | |
dfafc897 FS |
1681 | rtx save_area, mem; |
1682 | int first_reg_offset, set; | |
4697a36c | 1683 | |
60e2d0ca | 1684 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
4697a36c | 1685 | { |
4cc833b7 RH |
1686 | tree fntype; |
1687 | int stdarg_p; | |
1688 | ||
1689 | fntype = TREE_TYPE (current_function_decl); | |
1690 | stdarg_p = (TYPE_ARG_TYPES (fntype) != 0 | |
1691 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
1692 | != void_type_node)); | |
1693 | ||
1694 | /* For varargs, we do not want to skip the dummy va_dcl argument. | |
1695 | For stdargs, we do want to skip the last named argument. */ | |
1696 | next_cum = *cum; | |
1697 | if (stdarg_p) | |
1698 | function_arg_advance (&next_cum, mode, type, 1); | |
1699 | ||
1700 | /* Indicate to allocate space on the stack for varargs save area. */ | |
1701 | /* ??? Does this really have to be located at a magic spot on the | |
1702 | stack, or can we allocate this with assign_stack_local instead. */ | |
4697a36c | 1703 | rs6000_sysv_varargs_p = 1; |
60e2d0ca | 1704 | if (! no_rtl) |
2c4974b7 | 1705 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 1706 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
1707 | |
1708 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 1709 | } |
60e2d0ca | 1710 | else |
4697a36c | 1711 | { |
4cc833b7 RH |
1712 | save_area = virtual_incoming_args_rtx; |
1713 | rs6000_sysv_varargs_p = 0; | |
4697a36c | 1714 | |
4cc833b7 | 1715 | first_reg_offset = cum->words; |
4697a36c MM |
1716 | if (MUST_PASS_IN_STACK (mode, type)) |
1717 | first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1); | |
4cc833b7 | 1718 | } |
4697a36c | 1719 | |
dfafc897 | 1720 | set = get_varargs_alias_set (); |
4cc833b7 RH |
1721 | if (!no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
1722 | { | |
dfafc897 FS |
1723 | mem = gen_rtx_MEM (BLKmode, |
1724 | plus_constant (save_area, | |
1725 | first_reg_offset * reg_size)), | |
1726 | MEM_ALIAS_SET (mem) = set; | |
1727 | ||
4cc833b7 | 1728 | move_block_from_reg |
dfafc897 | 1729 | (GP_ARG_MIN_REG + first_reg_offset, mem, |
4cc833b7 RH |
1730 | GP_ARG_NUM_REG - first_reg_offset, |
1731 | (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD); | |
1732 | ||
1733 | /* ??? Does ABI_V4 need this at all? */ | |
4697a36c MM |
1734 | *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD; |
1735 | } | |
1736 | ||
4697a36c | 1737 | /* Save FP registers if needed. */ |
4cc833b7 RH |
1738 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
1739 | && TARGET_HARD_FLOAT && !no_rtl | |
1740 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) | |
4697a36c | 1741 | { |
4cc833b7 RH |
1742 | int fregno = next_cum.fregno; |
1743 | rtx cr1 = gen_rtx_REG (CCmode, 69); | |
1744 | rtx lab = gen_label_rtx (); | |
1745 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 1746 | |
4cc833b7 | 1747 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 1748 | pc_rtx, |
39403d82 | 1749 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
1750 | gen_rtx_NE (VOIDmode, cr1, |
1751 | const0_rtx), | |
39403d82 | 1752 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
1753 | pc_rtx))); |
1754 | ||
4cc833b7 RH |
1755 | while (fregno <= FP_ARG_V4_MAX_REG) |
1756 | { | |
dfafc897 FS |
1757 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
1758 | MEM_ALIAS_SET (mem) = set; | |
1759 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); | |
4cc833b7 RH |
1760 | fregno++; |
1761 | off += 8; | |
4697a36c | 1762 | } |
4cc833b7 RH |
1763 | |
1764 | emit_label (lab); | |
4697a36c | 1765 | } |
4697a36c | 1766 | } |
4697a36c | 1767 | |
dfafc897 | 1768 | /* Create the va_list data type. */ |
2c4974b7 | 1769 | |
dfafc897 FS |
1770 | tree |
1771 | rs6000_build_va_list () | |
1772 | { | |
1773 | tree f_gpr, f_fpr, f_ovf, f_sav, record; | |
1774 | tree uchar_type_node; | |
4697a36c | 1775 | |
dfafc897 FS |
1776 | /* Only SVR4 needs something special. */ |
1777 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) | |
1778 | return ptr_type_node; | |
1779 | ||
1780 | record = make_node (RECORD_TYPE); | |
1781 | uchar_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
1782 | ||
1783 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), uchar_type_node); | |
1784 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), uchar_type_node); | |
1785 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), | |
1786 | ptr_type_node); | |
1787 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
1788 | ptr_type_node); | |
1789 | ||
1790 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
1791 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
1792 | DECL_FIELD_CONTEXT (f_ovf) = record; | |
1793 | DECL_FIELD_CONTEXT (f_sav) = record; | |
1794 | ||
1795 | TYPE_FIELDS (record) = f_gpr; | |
1796 | TREE_CHAIN (f_gpr) = f_fpr; | |
1797 | TREE_CHAIN (f_fpr) = f_ovf; | |
1798 | TREE_CHAIN (f_ovf) = f_sav; | |
1799 | ||
1800 | layout_type (record); | |
1801 | ||
1802 | /* The correct type is an array type of one element. */ | |
1803 | return build_array_type (record, build_index_type (size_zero_node)); | |
1804 | } | |
1805 | ||
1806 | /* Implement va_start. */ | |
1807 | ||
1808 | void | |
1809 | rs6000_va_start (stdarg_p, valist, nextarg) | |
1810 | int stdarg_p; | |
1811 | tree valist; | |
1812 | rtx nextarg; | |
4697a36c | 1813 | { |
dfafc897 FS |
1814 | HOST_WIDE_INT words, n_gpr, n_fpr; |
1815 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
1816 | tree gpr, fpr, ovf, sav, t; | |
2c4974b7 | 1817 | |
dfafc897 | 1818 | /* Only SVR4 needs something special. */ |
2c4974b7 | 1819 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
dfafc897 FS |
1820 | { |
1821 | std_expand_builtin_va_start (stdarg_p, valist, nextarg); | |
1822 | return; | |
1823 | } | |
1824 | ||
1825 | f_gpr = TYPE_FIELDS (va_list_type_node); | |
1826 | f_fpr = TREE_CHAIN (f_gpr); | |
1827 | f_ovf = TREE_CHAIN (f_fpr); | |
1828 | f_sav = TREE_CHAIN (f_ovf); | |
1829 | ||
1830 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); | |
1831 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
1832 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
1833 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
1834 | ||
1835 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 1836 | words = current_function_args_info.words; |
dfafc897 FS |
1837 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
1838 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
1839 | ||
1840 | if (TARGET_DEBUG_ARG) | |
1841 | fprintf (stderr, "va_start: words = %d, n_gpr = %d, n_fpr = %d\n", | |
1842 | words, n_gpr, n_fpr); | |
1843 | ||
1844 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
1845 | TREE_SIDE_EFFECTS (t) = 1; | |
1846 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
1847 | ||
1848 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
1849 | TREE_SIDE_EFFECTS (t) = 1; | |
1850 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
1851 | ||
1852 | /* Find the overflow area. */ | |
1853 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
1854 | if (words != 0) | |
1855 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
1856 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
1857 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
1858 | TREE_SIDE_EFFECTS (t) = 1; | |
1859 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
1860 | ||
1861 | /* Find the register save area. */ | |
1862 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
1863 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
1864 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
1865 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
1866 | TREE_SIDE_EFFECTS (t) = 1; | |
1867 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
1868 | } | |
1869 | ||
1870 | /* Implement va_arg. */ | |
1871 | ||
1872 | rtx | |
1873 | rs6000_va_arg (valist, type) | |
1874 | tree valist, type; | |
1875 | { | |
1876 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
1877 | tree gpr, fpr, ovf, sav, reg, t, u; | |
1878 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
1879 | rtx lab_false, lab_over, addr_rtx, r; | |
1880 | ||
1881 | /* Only SVR4 needs something special. */ | |
1882 | if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) | |
1883 | return std_expand_builtin_va_arg (valist, type); | |
1884 | ||
1885 | f_gpr = TYPE_FIELDS (va_list_type_node); | |
1886 | f_fpr = TREE_CHAIN (f_gpr); | |
1887 | f_ovf = TREE_CHAIN (f_fpr); | |
1888 | f_sav = TREE_CHAIN (f_ovf); | |
1889 | ||
1890 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); | |
1891 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
1892 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
1893 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
1894 | ||
1895 | size = int_size_in_bytes (type); | |
1896 | rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
4cc833b7 | 1897 | |
dfafc897 | 1898 | if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode) |
4cc833b7 | 1899 | { |
dfafc897 FS |
1900 | /* Aggregates and long doubles are passed by reference. */ |
1901 | indirect_p = 1; | |
1902 | reg = gpr; | |
1903 | n_reg = 1; | |
1904 | sav_ofs = 0; | |
1905 | sav_scale = 4; | |
1906 | size = rsize = UNITS_PER_WORD; | |
1907 | } | |
1908 | else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT) | |
1909 | { | |
1910 | /* FP args go in FP registers, if present. */ | |
1911 | indirect_p = 0; | |
1912 | reg = fpr; | |
1913 | n_reg = 1; | |
1914 | sav_ofs = 8*4; | |
1915 | sav_scale = 8; | |
4cc833b7 | 1916 | } |
dfafc897 FS |
1917 | else |
1918 | { | |
1919 | /* Otherwise into GP registers. */ | |
1920 | indirect_p = 0; | |
1921 | reg = gpr; | |
1922 | n_reg = rsize; | |
1923 | sav_ofs = 0; | |
1924 | sav_scale = 4; | |
1925 | } | |
1926 | ||
1927 | /* | |
1928 | * Pull the value out of the saved registers ... | |
1929 | */ | |
1930 | ||
1931 | lab_false = gen_label_rtx (); | |
1932 | lab_over = gen_label_rtx (); | |
1933 | addr_rtx = gen_reg_rtx (Pmode); | |
1934 | ||
1935 | emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL), | |
1936 | GEN_INT (8 - n_reg + 1), | |
1937 | GE, const1_rtx, QImode, 1, 1, lab_false); | |
2c4974b7 | 1938 | |
dfafc897 FS |
1939 | /* Long long is aligned in the registers. */ |
1940 | if (n_reg > 1) | |
2c4974b7 | 1941 | { |
dfafc897 FS |
1942 | u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg, |
1943 | build_int_2 (n_reg - 1, 0)); | |
1944 | u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u); | |
1945 | u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u); | |
1946 | TREE_SIDE_EFFECTS (u) = 1; | |
1947 | expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2c4974b7 | 1948 | } |
dfafc897 FS |
1949 | |
1950 | if (sav_ofs) | |
1951 | t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
2c4974b7 | 1952 | else |
dfafc897 | 1953 | t = sav; |
2c4974b7 | 1954 | |
dfafc897 FS |
1955 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0)); |
1956 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 1957 | |
dfafc897 FS |
1958 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
1959 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 1960 | |
dfafc897 FS |
1961 | u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); |
1962 | TREE_SIDE_EFFECTS (u) = 1; | |
1963 | ||
1964 | t = build (PLUS_EXPR, ptr_type_node, t, u); | |
1965 | TREE_SIDE_EFFECTS (t) = 1; | |
1966 | ||
1967 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
1968 | if (r != addr_rtx) | |
1969 | emit_move_insn (addr_rtx, r); | |
1970 | ||
1971 | emit_jump_insn (gen_jump (lab_over)); | |
1972 | emit_barrier (); | |
1973 | emit_label (lab_false); | |
1974 | ||
1975 | /* | |
1976 | * ... otherwise out of the overflow area. | |
1977 | */ | |
1978 | ||
1979 | /* Make sure we don't find reg 7 for the next int arg. */ | |
1980 | if (n_reg > 1) | |
1981 | { | |
1982 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
1983 | TREE_SIDE_EFFECTS (t) = 1; | |
1984 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
1985 | } | |
1986 | ||
1987 | /* Care for on-stack alignment if needed. */ | |
1988 | if (rsize <= 1) | |
1989 | t = ovf; | |
1990 | else | |
1991 | { | |
1992 | t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0)); | |
1993 | t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1)); | |
1994 | } | |
1995 | t = save_expr (t); | |
1996 | ||
1997 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
1998 | if (r != addr_rtx) | |
1999 | emit_move_insn (addr_rtx, r); | |
2000 | ||
2001 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
2002 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
2003 | TREE_SIDE_EFFECTS (t) = 1; | |
2004 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2005 | ||
2006 | emit_label (lab_over); | |
2007 | ||
2008 | if (indirect_p) | |
2009 | { | |
2010 | r = gen_rtx_MEM (Pmode, addr_rtx); | |
2011 | MEM_ALIAS_SET (r) = get_varargs_alias_set (); | |
2012 | emit_move_insn (addr_rtx, r); | |
2013 | } | |
2014 | ||
2015 | return addr_rtx; | |
4697a36c | 2016 | } |
5b5040b9 RK |
2017 | \f |
2018 | /* Generate a memory reference for expand_block_move, copying volatile, | |
2019 | and other bits from an original memory reference. */ | |
2020 | ||
2021 | static rtx | |
2022 | expand_block_move_mem (mode, addr, orig_mem) | |
2023 | enum machine_mode mode; | |
2024 | rtx addr; | |
2025 | rtx orig_mem; | |
2026 | { | |
39403d82 | 2027 | rtx mem = gen_rtx_MEM (mode, addr); |
b6c9286a MM |
2028 | |
2029 | RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (orig_mem); | |
c6df88cb | 2030 | MEM_COPY_ATTRIBUTES (mem, orig_mem); |
b6c9286a MM |
2031 | #ifdef MEM_UNALIGNED_P |
2032 | MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem); | |
2033 | #endif | |
5b5040b9 RK |
2034 | return mem; |
2035 | } | |
2036 | ||
7e69e155 MM |
2037 | /* Expand a block move operation, and return 1 if successful. Return 0 |
2038 | if we should let the compiler generate normal code. | |
2039 | ||
2040 | operands[0] is the destination | |
2041 | operands[1] is the source | |
2042 | operands[2] is the length | |
2043 | operands[3] is the alignment */ | |
2044 | ||
3933e0e1 MM |
2045 | #define MAX_MOVE_REG 4 |
2046 | ||
7e69e155 MM |
2047 | int |
2048 | expand_block_move (operands) | |
2049 | rtx operands[]; | |
2050 | { | |
b6c9286a MM |
2051 | rtx orig_dest = operands[0]; |
2052 | rtx orig_src = operands[1]; | |
7e69e155 | 2053 | rtx bytes_rtx = operands[2]; |
7e69e155 | 2054 | rtx align_rtx = operands[3]; |
3933e0e1 | 2055 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
7e69e155 | 2056 | int align = XINT (align_rtx, 0); |
3933e0e1 MM |
2057 | int bytes; |
2058 | int offset; | |
2059 | int num_reg; | |
2060 | int i; | |
7e69e155 MM |
2061 | rtx src_reg; |
2062 | rtx dest_reg; | |
3933e0e1 MM |
2063 | rtx src_addr; |
2064 | rtx dest_addr; | |
7e69e155 | 2065 | rtx tmp_reg; |
3933e0e1 | 2066 | rtx stores[MAX_MOVE_REG]; |
7e69e155 MM |
2067 | int move_bytes; |
2068 | ||
3933e0e1 MM |
2069 | /* If this is not a fixed size move, just call memcpy */ |
2070 | if (!constp) | |
2071 | return 0; | |
2072 | ||
7e69e155 | 2073 | /* Anything to move? */ |
3933e0e1 MM |
2074 | bytes = INTVAL (bytes_rtx); |
2075 | if (bytes <= 0) | |
7e69e155 MM |
2076 | return 1; |
2077 | ||
3933e0e1 MM |
2078 | /* Don't support real large moves. If string instructions are not used, |
2079 | then don't generate more than 8 loads. */ | |
2080 | if (TARGET_STRING) | |
2081 | { | |
1cab3be1 | 2082 | if (bytes > 4*8) |
3933e0e1 MM |
2083 | return 0; |
2084 | } | |
2085 | else if (!STRICT_ALIGNMENT) | |
2086 | { | |
2087 | if (bytes > 4*8) | |
2088 | return 0; | |
2089 | } | |
2090 | else if (bytes > 8*align) | |
7e69e155 MM |
2091 | return 0; |
2092 | ||
2093 | /* Move the address into scratch registers. */ | |
b6c9286a MM |
2094 | dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0)); |
2095 | src_reg = copy_addr_to_reg (XEXP (orig_src, 0)); | |
7e69e155 | 2096 | |
3933e0e1 | 2097 | if (TARGET_STRING) /* string instructions are available */ |
7e69e155 | 2098 | { |
3933e0e1 | 2099 | for ( ; bytes > 0; bytes -= move_bytes) |
7e69e155 | 2100 | { |
3933e0e1 MM |
2101 | if (bytes > 24 /* move up to 32 bytes at a time */ |
2102 | && !fixed_regs[5] | |
2103 | && !fixed_regs[6] | |
2104 | && !fixed_regs[7] | |
2105 | && !fixed_regs[8] | |
2106 | && !fixed_regs[9] | |
2107 | && !fixed_regs[10] | |
2108 | && !fixed_regs[11] | |
2109 | && !fixed_regs[12]) | |
2110 | { | |
2111 | move_bytes = (bytes > 32) ? 32 : bytes; | |
b6c9286a MM |
2112 | emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest), |
2113 | expand_block_move_mem (BLKmode, src_reg, orig_src), | |
3933e0e1 | 2114 | GEN_INT ((move_bytes == 32) ? 0 : move_bytes), |
4c64a852 | 2115 | align_rtx)); |
3933e0e1 MM |
2116 | } |
2117 | else if (bytes > 16 /* move up to 24 bytes at a time */ | |
2118 | && !fixed_regs[7] | |
2119 | && !fixed_regs[8] | |
2120 | && !fixed_regs[9] | |
2121 | && !fixed_regs[10] | |
2122 | && !fixed_regs[11] | |
2123 | && !fixed_regs[12]) | |
2124 | { | |
2125 | move_bytes = (bytes > 24) ? 24 : bytes; | |
b6c9286a MM |
2126 | emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest), |
2127 | expand_block_move_mem (BLKmode, src_reg, orig_src), | |
3933e0e1 | 2128 | GEN_INT (move_bytes), |
4c64a852 | 2129 | align_rtx)); |
3933e0e1 MM |
2130 | } |
2131 | else if (bytes > 8 /* move up to 16 bytes at a time */ | |
2132 | && !fixed_regs[9] | |
2133 | && !fixed_regs[10] | |
2134 | && !fixed_regs[11] | |
2135 | && !fixed_regs[12]) | |
2136 | { | |
2137 | move_bytes = (bytes > 16) ? 16 : bytes; | |
b6c9286a MM |
2138 | emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest), |
2139 | expand_block_move_mem (BLKmode, src_reg, orig_src), | |
3933e0e1 | 2140 | GEN_INT (move_bytes), |
4c64a852 | 2141 | align_rtx)); |
3933e0e1 | 2142 | } |
d679bebf | 2143 | else if (bytes > 4 && !TARGET_64BIT) |
3933e0e1 MM |
2144 | { /* move up to 8 bytes at a time */ |
2145 | move_bytes = (bytes > 8) ? 8 : bytes; | |
b6c9286a MM |
2146 | emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest), |
2147 | expand_block_move_mem (BLKmode, src_reg, orig_src), | |
3933e0e1 | 2148 | GEN_INT (move_bytes), |
4c64a852 | 2149 | align_rtx)); |
3933e0e1 MM |
2150 | } |
2151 | else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT)) | |
2152 | { /* move 4 bytes */ | |
2153 | move_bytes = 4; | |
2154 | tmp_reg = gen_reg_rtx (SImode); | |
b6c9286a MM |
2155 | emit_move_insn (tmp_reg, expand_block_move_mem (SImode, src_reg, orig_src)); |
2156 | emit_move_insn (expand_block_move_mem (SImode, dest_reg, orig_dest), tmp_reg); | |
3933e0e1 MM |
2157 | } |
2158 | else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT)) | |
2159 | { /* move 2 bytes */ | |
2160 | move_bytes = 2; | |
2161 | tmp_reg = gen_reg_rtx (HImode); | |
b6c9286a MM |
2162 | emit_move_insn (tmp_reg, expand_block_move_mem (HImode, src_reg, orig_src)); |
2163 | emit_move_insn (expand_block_move_mem (HImode, dest_reg, orig_dest), tmp_reg); | |
3933e0e1 MM |
2164 | } |
2165 | else if (bytes == 1) /* move 1 byte */ | |
2166 | { | |
2167 | move_bytes = 1; | |
2168 | tmp_reg = gen_reg_rtx (QImode); | |
b6c9286a MM |
2169 | emit_move_insn (tmp_reg, expand_block_move_mem (QImode, src_reg, orig_src)); |
2170 | emit_move_insn (expand_block_move_mem (QImode, dest_reg, orig_dest), tmp_reg); | |
3933e0e1 MM |
2171 | } |
2172 | else | |
2173 | { /* move up to 4 bytes at a time */ | |
2174 | move_bytes = (bytes > 4) ? 4 : bytes; | |
b6c9286a MM |
2175 | emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest), |
2176 | expand_block_move_mem (BLKmode, src_reg, orig_src), | |
3933e0e1 | 2177 | GEN_INT (move_bytes), |
4c64a852 | 2178 | align_rtx)); |
3933e0e1 | 2179 | } |
4c64a852 | 2180 | |
015892ee RK |
2181 | if (bytes > move_bytes) |
2182 | { | |
2183 | emit_insn (gen_addsi3 (src_reg, src_reg, GEN_INT (move_bytes))); | |
2184 | emit_insn (gen_addsi3 (dest_reg, dest_reg, GEN_INT (move_bytes))); | |
2185 | } | |
4c64a852 | 2186 | } |
3933e0e1 MM |
2187 | } |
2188 | ||
2189 | else /* string instructions not available */ | |
2190 | { | |
2191 | num_reg = offset = 0; | |
2192 | for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes)) | |
7e69e155 | 2193 | { |
3933e0e1 MM |
2194 | /* Calculate the correct offset for src/dest */ |
2195 | if (offset == 0) | |
7e69e155 | 2196 | { |
3933e0e1 MM |
2197 | src_addr = src_reg; |
2198 | dest_addr = dest_reg; | |
2199 | } | |
2200 | else | |
2201 | { | |
39403d82 DE |
2202 | src_addr = gen_rtx_PLUS (Pmode, src_reg, GEN_INT (offset)); |
2203 | dest_addr = gen_rtx_PLUS (Pmode, dest_reg, GEN_INT (offset)); | |
3933e0e1 MM |
2204 | } |
2205 | ||
2206 | /* Generate the appropriate load and store, saving the stores for later */ | |
b6c9286a MM |
2207 | if (bytes >= 8 && TARGET_64BIT && (align >= 8 || !STRICT_ALIGNMENT)) |
2208 | { | |
2209 | move_bytes = 8; | |
2210 | tmp_reg = gen_reg_rtx (DImode); | |
2211 | emit_insn (gen_movdi (tmp_reg, expand_block_move_mem (DImode, src_addr, orig_src))); | |
2212 | stores[ num_reg++ ] = gen_movdi (expand_block_move_mem (DImode, dest_addr, orig_dest), tmp_reg); | |
2213 | } | |
2214 | else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT)) | |
3933e0e1 MM |
2215 | { |
2216 | move_bytes = 4; | |
2217 | tmp_reg = gen_reg_rtx (SImode); | |
b6c9286a MM |
2218 | emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (SImode, src_addr, orig_src))); |
2219 | stores[ num_reg++ ] = gen_movsi (expand_block_move_mem (SImode, dest_addr, orig_dest), tmp_reg); | |
3933e0e1 MM |
2220 | } |
2221 | else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT)) | |
2222 | { | |
2223 | move_bytes = 2; | |
2224 | tmp_reg = gen_reg_rtx (HImode); | |
b6c9286a MM |
2225 | emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (HImode, src_addr, orig_src))); |
2226 | stores[ num_reg++ ] = gen_movhi (expand_block_move_mem (HImode, dest_addr, orig_dest), tmp_reg); | |
3933e0e1 MM |
2227 | } |
2228 | else | |
2229 | { | |
2230 | move_bytes = 1; | |
2231 | tmp_reg = gen_reg_rtx (QImode); | |
b6c9286a MM |
2232 | emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (QImode, src_addr, orig_src))); |
2233 | stores[ num_reg++ ] = gen_movqi (expand_block_move_mem (QImode, dest_addr, orig_dest), tmp_reg); | |
3933e0e1 MM |
2234 | } |
2235 | ||
2236 | if (num_reg >= MAX_MOVE_REG) | |
2237 | { | |
2238 | for (i = 0; i < num_reg; i++) | |
2239 | emit_insn (stores[i]); | |
2240 | num_reg = 0; | |
7e69e155 MM |
2241 | } |
2242 | } | |
3933e0e1 | 2243 | |
b6c9286a MM |
2244 | for (i = 0; i < num_reg; i++) |
2245 | emit_insn (stores[i]); | |
7e69e155 MM |
2246 | } |
2247 | ||
2248 | return 1; | |
2249 | } | |
2250 | ||
9878760c RK |
2251 | \f |
2252 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
2253 | PARALLEL and the first section will be tested. */ | |
2254 | ||
2255 | int | |
2256 | load_multiple_operation (op, mode) | |
2257 | rtx op; | |
296b8152 | 2258 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
2259 | { |
2260 | int count = XVECLEN (op, 0); | |
2261 | int dest_regno; | |
2262 | rtx src_addr; | |
2263 | int i; | |
2264 | ||
2265 | /* Perform a quick check so we don't blow up below. */ | |
2266 | if (count <= 1 | |
2267 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
2268 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
2269 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
2270 | return 0; | |
2271 | ||
2272 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
2273 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
2274 | ||
2275 | for (i = 1; i < count; i++) | |
2276 | { | |
2277 | rtx elt = XVECEXP (op, 0, i); | |
2278 | ||
2279 | if (GET_CODE (elt) != SET | |
2280 | || GET_CODE (SET_DEST (elt)) != REG | |
2281 | || GET_MODE (SET_DEST (elt)) != SImode | |
2282 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
2283 | || GET_CODE (SET_SRC (elt)) != MEM | |
2284 | || GET_MODE (SET_SRC (elt)) != SImode | |
2285 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
2286 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
2287 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
2288 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
2289 | return 0; | |
2290 | } | |
2291 | ||
2292 | return 1; | |
2293 | } | |
2294 | ||
2295 | /* Similar, but tests for store multiple. Here, the second vector element | |
2296 | is a CLOBBER. It will be tested later. */ | |
2297 | ||
2298 | int | |
2299 | store_multiple_operation (op, mode) | |
2300 | rtx op; | |
296b8152 | 2301 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
2302 | { |
2303 | int count = XVECLEN (op, 0) - 1; | |
2304 | int src_regno; | |
2305 | rtx dest_addr; | |
2306 | int i; | |
2307 | ||
2308 | /* Perform a quick check so we don't blow up below. */ | |
2309 | if (count <= 1 | |
2310 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
2311 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
2312 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
2313 | return 0; | |
2314 | ||
2315 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
2316 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
2317 | ||
2318 | for (i = 1; i < count; i++) | |
2319 | { | |
2320 | rtx elt = XVECEXP (op, 0, i + 1); | |
2321 | ||
2322 | if (GET_CODE (elt) != SET | |
2323 | || GET_CODE (SET_SRC (elt)) != REG | |
2324 | || GET_MODE (SET_SRC (elt)) != SImode | |
2325 | || REGNO (SET_SRC (elt)) != src_regno + i | |
2326 | || GET_CODE (SET_DEST (elt)) != MEM | |
2327 | || GET_MODE (SET_DEST (elt)) != SImode | |
2328 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
2329 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
2330 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
2331 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
2332 | return 0; | |
2333 | } | |
2334 | ||
2335 | return 1; | |
2336 | } | |
2337 | \f | |
2338 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. | |
2339 | We only check the opcode against the mode of the CC value here. */ | |
2340 | ||
2341 | int | |
2342 | branch_comparison_operator (op, mode) | |
2343 | register rtx op; | |
296b8152 | 2344 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
2345 | { |
2346 | enum rtx_code code = GET_CODE (op); | |
2347 | enum machine_mode cc_mode; | |
2348 | ||
2349 | if (GET_RTX_CLASS (code) != '<') | |
2350 | return 0; | |
2351 | ||
2352 | cc_mode = GET_MODE (XEXP (op, 0)); | |
2353 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
2354 | return 0; | |
2355 | ||
2356 | if ((code == GT || code == LT || code == GE || code == LE) | |
2357 | && cc_mode == CCUNSmode) | |
2358 | return 0; | |
2359 | ||
2360 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
2361 | && (cc_mode != CCUNSmode)) | |
2362 | return 0; | |
2363 | ||
2364 | return 1; | |
2365 | } | |
2366 | ||
2367 | /* Return 1 if OP is a comparison operation that is valid for an scc insn. | |
2368 | We check the opcode against the mode of the CC value and disallow EQ or | |
2369 | NE comparisons for integers. */ | |
2370 | ||
2371 | int | |
2372 | scc_comparison_operator (op, mode) | |
2373 | register rtx op; | |
2374 | enum machine_mode mode; | |
2375 | { | |
2376 | enum rtx_code code = GET_CODE (op); | |
2377 | enum machine_mode cc_mode; | |
2378 | ||
2379 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
2380 | return 0; | |
2381 | ||
2382 | if (GET_RTX_CLASS (code) != '<') | |
2383 | return 0; | |
2384 | ||
2385 | cc_mode = GET_MODE (XEXP (op, 0)); | |
2386 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
2387 | return 0; | |
2388 | ||
2389 | if (code == NE && cc_mode != CCFPmode) | |
2390 | return 0; | |
2391 | ||
2392 | if ((code == GT || code == LT || code == GE || code == LE) | |
2393 | && cc_mode == CCUNSmode) | |
2394 | return 0; | |
2395 | ||
2396 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
2397 | && (cc_mode != CCUNSmode)) | |
2398 | return 0; | |
2399 | ||
c5defebb RK |
2400 | if (cc_mode == CCEQmode && code != EQ && code != NE) |
2401 | return 0; | |
2402 | ||
9878760c RK |
2403 | return 1; |
2404 | } | |
e0cd0770 JC |
2405 | |
2406 | int | |
2407 | trap_comparison_operator (op, mode) | |
2408 | rtx op; | |
2409 | enum machine_mode mode; | |
2410 | { | |
2411 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
2412 | return 0; | |
2413 | return (GET_RTX_CLASS (GET_CODE (op)) == '<' | |
2414 | || GET_CODE (op) == EQ || GET_CODE (op) == NE); | |
2415 | } | |
9878760c RK |
2416 | \f |
2417 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
2418 | mask required to convert the result of a rotate insn into a shift | |
2419 | left insn of SHIFTOP bits. Both are known to be CONST_INT. */ | |
2420 | ||
2421 | int | |
2422 | includes_lshift_p (shiftop, andop) | |
2423 | register rtx shiftop; | |
2424 | register rtx andop; | |
2425 | { | |
2426 | int shift_mask = (~0 << INTVAL (shiftop)); | |
2427 | ||
2428 | return (INTVAL (andop) & ~shift_mask) == 0; | |
2429 | } | |
2430 | ||
2431 | /* Similar, but for right shift. */ | |
2432 | ||
2433 | int | |
2434 | includes_rshift_p (shiftop, andop) | |
2435 | register rtx shiftop; | |
2436 | register rtx andop; | |
2437 | { | |
a7653a2c | 2438 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
2439 | |
2440 | shift_mask >>= INTVAL (shiftop); | |
2441 | ||
2442 | return (INTVAL (andop) & ~ shift_mask) == 0; | |
2443 | } | |
35068b43 RK |
2444 | |
2445 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates | |
2446 | for lfq and stfq insns. | |
2447 | ||
2448 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
2449 | abort if we are passed pseudo registers. */ | |
2450 | ||
2451 | int | |
2452 | registers_ok_for_quad_peep (reg1, reg2) | |
2453 | rtx reg1, reg2; | |
2454 | { | |
2455 | /* We might have been passed a SUBREG. */ | |
2456 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
2457 | return 0; | |
2458 | ||
2459 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
2460 | } | |
2461 | ||
2462 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and | |
2463 | addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */ | |
2464 | ||
2465 | int | |
2466 | addrs_ok_for_quad_peep (addr1, addr2) | |
2467 | register rtx addr1; | |
2468 | register rtx addr2; | |
2469 | { | |
2470 | int reg1; | |
2471 | int offset1; | |
2472 | ||
2473 | /* Extract an offset (if used) from the first addr. */ | |
2474 | if (GET_CODE (addr1) == PLUS) | |
2475 | { | |
2476 | /* If not a REG, return zero. */ | |
2477 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
2478 | return 0; | |
2479 | else | |
2480 | { | |
2481 | reg1 = REGNO (XEXP (addr1, 0)); | |
2482 | /* The offset must be constant! */ | |
2483 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
2484 | return 0; | |
2485 | offset1 = INTVAL (XEXP (addr1, 1)); | |
2486 | } | |
2487 | } | |
2488 | else if (GET_CODE (addr1) != REG) | |
2489 | return 0; | |
2490 | else | |
2491 | { | |
2492 | reg1 = REGNO (addr1); | |
2493 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
2494 | offset1 = 0; | |
2495 | } | |
2496 | ||
2497 | /* Make sure the second address is a (mem (plus (reg) (const_int). */ | |
2498 | if (GET_CODE (addr2) != PLUS) | |
2499 | return 0; | |
2500 | ||
2501 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
2502 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
2503 | return 0; | |
2504 | ||
2505 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
2506 | return 0; | |
2507 | ||
2508 | /* The offset for the second addr must be 8 more than the first addr. */ | |
2509 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
2510 | return 0; | |
2511 | ||
2512 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
2513 | instructions. */ | |
2514 | return 1; | |
2515 | } | |
9878760c RK |
2516 | \f |
2517 | /* Return the register class of a scratch register needed to copy IN into | |
2518 | or out of a register in CLASS in MODE. If it can be done directly, | |
2519 | NO_REGS is returned. */ | |
2520 | ||
2521 | enum reg_class | |
2522 | secondary_reload_class (class, mode, in) | |
2523 | enum reg_class class; | |
296b8152 | 2524 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
2525 | rtx in; |
2526 | { | |
5accd822 | 2527 | int regno; |
9878760c | 2528 | |
3cb999d8 | 2529 | #if TARGET_ELF |
1427100a | 2530 | /* We can not copy a symbolic operand directly into anything other than |
e7b7998a JL |
2531 | BASE_REGS for TARGET_ELF. So indicate that a register from BASE_REGS |
2532 | is needed as an intermediate register. */ | |
3cb999d8 | 2533 | if (class != BASE_REGS |
e7b7998a JL |
2534 | && (GET_CODE (in) == SYMBOL_REF |
2535 | || GET_CODE (in) == LABEL_REF | |
2536 | || GET_CODE (in) == CONST)) | |
2537 | return BASE_REGS; | |
3cb999d8 | 2538 | #endif |
e7b7998a | 2539 | |
5accd822 DE |
2540 | if (GET_CODE (in) == REG) |
2541 | { | |
2542 | regno = REGNO (in); | |
2543 | if (regno >= FIRST_PSEUDO_REGISTER) | |
2544 | { | |
2545 | regno = true_regnum (in); | |
2546 | if (regno >= FIRST_PSEUDO_REGISTER) | |
2547 | regno = -1; | |
2548 | } | |
2549 | } | |
2550 | else if (GET_CODE (in) == SUBREG) | |
2551 | { | |
2552 | regno = true_regnum (in); | |
2553 | if (regno >= FIRST_PSEUDO_REGISTER) | |
2554 | regno = -1; | |
2555 | } | |
2556 | else | |
2557 | regno = -1; | |
2558 | ||
9878760c RK |
2559 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
2560 | into anything. */ | |
2561 | if (class == GENERAL_REGS || class == BASE_REGS | |
2562 | || (regno >= 0 && INT_REGNO_P (regno))) | |
2563 | return NO_REGS; | |
2564 | ||
2565 | /* Constants, memory, and FP registers can go into FP registers. */ | |
2566 | if ((regno == -1 || FP_REGNO_P (regno)) | |
2567 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
2568 | return NO_REGS; | |
2569 | ||
2570 | /* We can copy among the CR registers. */ | |
2571 | if ((class == CR_REGS || class == CR0_REGS) | |
2572 | && regno >= 0 && CR_REGNO_P (regno)) | |
2573 | return NO_REGS; | |
2574 | ||
2575 | /* Otherwise, we need GENERAL_REGS. */ | |
2576 | return GENERAL_REGS; | |
2577 | } | |
2578 | \f | |
2579 | /* Given a comparison operation, return the bit number in CCR to test. We | |
2580 | know this is a valid comparison. | |
2581 | ||
2582 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
2583 | used instead of %C, so the bits will be in different places. | |
2584 | ||
b4ac57ab | 2585 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
2586 | |
2587 | int | |
2588 | ccr_bit (op, scc_p) | |
2589 | register rtx op; | |
2590 | int scc_p; | |
2591 | { | |
2592 | enum rtx_code code = GET_CODE (op); | |
2593 | enum machine_mode cc_mode; | |
2594 | int cc_regnum; | |
2595 | int base_bit; | |
2596 | ||
2597 | if (GET_RTX_CLASS (code) != '<') | |
2598 | return -1; | |
2599 | ||
2600 | cc_mode = GET_MODE (XEXP (op, 0)); | |
2601 | cc_regnum = REGNO (XEXP (op, 0)); | |
2602 | base_bit = 4 * (cc_regnum - 68); | |
2603 | ||
c5defebb RK |
2604 | /* In CCEQmode cases we have made sure that the result is always in the |
2605 | third bit of the CR field. */ | |
2606 | ||
2607 | if (cc_mode == CCEQmode) | |
2608 | return base_bit + 3; | |
2609 | ||
9878760c RK |
2610 | switch (code) |
2611 | { | |
2612 | case NE: | |
2613 | return scc_p ? base_bit + 3 : base_bit + 2; | |
2614 | case EQ: | |
2615 | return base_bit + 2; | |
2616 | case GT: case GTU: | |
2617 | return base_bit + 1; | |
2618 | case LT: case LTU: | |
2619 | return base_bit; | |
2620 | ||
2621 | case GE: case GEU: | |
2622 | /* If floating-point, we will have done a cror to put the bit in the | |
2623 | unordered position. So test that bit. For integer, this is ! LT | |
2624 | unless this is an scc insn. */ | |
2625 | return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit; | |
2626 | ||
2627 | case LE: case LEU: | |
2628 | return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1; | |
2629 | ||
2630 | default: | |
2631 | abort (); | |
2632 | } | |
2633 | } | |
1ff7789b | 2634 | \f |
8d30c4ee | 2635 | /* Return the GOT register. */ |
1ff7789b MM |
2636 | |
2637 | struct rtx_def * | |
2638 | rs6000_got_register (value) | |
5f59ecb7 | 2639 | rtx value ATTRIBUTE_UNUSED; |
1ff7789b | 2640 | { |
8d30c4ee FS |
2641 | /* The second flow pass currently (June 1999) can't update regs_ever_live |
2642 | without disturbing other parts of the compiler, so update it here to | |
2643 | make the prolog/epilogue code happy. */ | |
3cb999d8 | 2644 | if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) |
8d30c4ee | 2645 | regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1; |
1ff7789b | 2646 | |
8d30c4ee | 2647 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 2648 | |
1ff7789b MM |
2649 | return pic_offset_table_rtx; |
2650 | } | |
2651 | ||
956d6950 | 2652 | /* Search for any occurrence of the GOT_TOC register marker that should |
8d30c4ee FS |
2653 | have been eliminated, but may have crept back in. |
2654 | ||
2655 | This function could completely go away now (June 1999), but we leave it | |
2656 | in for a while until all the possible issues with the new -fpic handling | |
2657 | are resolved. */ | |
30ea98f1 MM |
2658 | |
2659 | void | |
2660 | rs6000_reorg (insn) | |
2661 | rtx insn; | |
2662 | { | |
2663 | if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)) | |
2664 | { | |
8d30c4ee | 2665 | rtx got_reg = gen_rtx_REG (Pmode, 2); |
30ea98f1 MM |
2666 | for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn)) |
2667 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' | |
2668 | && reg_mentioned_p (got_reg, PATTERN (insn))) | |
2669 | fatal_insn ("GOT/TOC register marker not removed:", PATTERN (insn)); | |
2670 | } | |
2671 | } | |
2672 | ||
a7df97e6 MM |
2673 | \f |
2674 | /* Define the structure for the machine field in struct function. */ | |
2675 | struct machine_function | |
2676 | { | |
2677 | int sysv_varargs_p; | |
2678 | int save_toc_p; | |
2679 | int fpmem_size; | |
2680 | int fpmem_offset; | |
2681 | }; | |
2682 | ||
2683 | /* Functions to save and restore rs6000_fpmem_size. | |
2684 | These will be called, via pointer variables, | |
2685 | from push_function_context and pop_function_context. */ | |
2686 | ||
2687 | void | |
2688 | rs6000_save_machine_status (p) | |
2689 | struct function *p; | |
2690 | { | |
2691 | struct machine_function *machine = | |
2692 | (struct machine_function *) xmalloc (sizeof (struct machine_function)); | |
2693 | ||
2694 | p->machine = machine; | |
2695 | machine->sysv_varargs_p = rs6000_sysv_varargs_p; | |
a7df97e6 MM |
2696 | machine->fpmem_size = rs6000_fpmem_size; |
2697 | machine->fpmem_offset = rs6000_fpmem_offset; | |
2698 | } | |
2699 | ||
2700 | void | |
2701 | rs6000_restore_machine_status (p) | |
2702 | struct function *p; | |
2703 | { | |
2704 | struct machine_function *machine = p->machine; | |
2705 | ||
2706 | rs6000_sysv_varargs_p = machine->sysv_varargs_p; | |
a7df97e6 MM |
2707 | rs6000_fpmem_size = machine->fpmem_size; |
2708 | rs6000_fpmem_offset = machine->fpmem_offset; | |
2709 | ||
2710 | free (machine); | |
2711 | p->machine = (struct machine_function *)0; | |
2712 | } | |
2713 | ||
2714 | /* Do anything needed before RTL is emitted for each function. */ | |
2715 | ||
2716 | void | |
2717 | rs6000_init_expanders () | |
2718 | { | |
2719 | /* Reset varargs and save TOC indicator */ | |
2720 | rs6000_sysv_varargs_p = 0; | |
a7df97e6 MM |
2721 | rs6000_fpmem_size = 0; |
2722 | rs6000_fpmem_offset = 0; | |
a7df97e6 MM |
2723 | |
2724 | /* Arrange to save and restore machine status around nested functions. */ | |
2725 | save_machine_status = rs6000_save_machine_status; | |
2726 | restore_machine_status = rs6000_restore_machine_status; | |
2727 | } | |
2728 | ||
9878760c RK |
2729 | \f |
2730 | /* Print an operand. Recognize special options, documented below. */ | |
2731 | ||
38c1f2d7 | 2732 | #if TARGET_ELF |
d9407988 | 2733 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 2734 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
2735 | #else |
2736 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 2737 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
2738 | #endif |
2739 | ||
9878760c RK |
2740 | void |
2741 | print_operand (file, x, code) | |
2742 | FILE *file; | |
2743 | rtx x; | |
2744 | char code; | |
2745 | { | |
2746 | int i; | |
a260abc9 | 2747 | HOST_WIDE_INT val; |
9878760c RK |
2748 | |
2749 | /* These macros test for integers and extract the low-order bits. */ | |
2750 | #define INT_P(X) \ | |
2751 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
2752 | && GET_MODE (X) == VOIDmode) | |
2753 | ||
2754 | #define INT_LOWPART(X) \ | |
2755 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
2756 | ||
2757 | switch (code) | |
2758 | { | |
a8b3aeda | 2759 | case '.': |
a85d226b RK |
2760 | /* Write out an instruction after the call which may be replaced |
2761 | with glue code by the loader. This depends on the AIX version. */ | |
2762 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
2763 | return; |
2764 | ||
cfaaaf2e RK |
2765 | case '*': |
2766 | /* Write the register number of the TOC register. */ | |
8d30c4ee | 2767 | fputs (TARGET_MINIMAL_TOC ? reg_names[30] : reg_names[2 /* PIC_OFFSET_TABLE_REGNUM? */ ], file); |
cfaaaf2e RK |
2768 | return; |
2769 | ||
c81bebd7 MM |
2770 | case '$': |
2771 | /* Write out either a '.' or '$' for the current location, depending | |
2772 | on whether this is Solaris or not. */ | |
2773 | putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file); | |
2774 | return; | |
2775 | ||
9854d9ed RK |
2776 | case 'A': |
2777 | /* If X is a constant integer whose low-order 5 bits are zero, | |
2778 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 2779 | in the AIX assembler where "sri" with a zero shift count |
9854d9ed RK |
2780 | write a trash instruction. */ |
2781 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) | |
76229ac8 | 2782 | putc ('l', file); |
9854d9ed | 2783 | else |
76229ac8 | 2784 | putc ('r', file); |
9854d9ed RK |
2785 | return; |
2786 | ||
2787 | case 'b': | |
2788 | /* Low-order 16 bits of constant, unsigned. */ | |
cad12a8d | 2789 | if (! INT_P (x)) |
9854d9ed | 2790 | output_operand_lossage ("invalid %%b value"); |
cad12a8d | 2791 | |
5f59ecb7 | 2792 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); |
cad12a8d RK |
2793 | return; |
2794 | ||
a260abc9 DE |
2795 | case 'B': |
2796 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
2797 | for 64-bit mask direction. */ | |
296b8152 | 2798 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 2799 | return; |
a260abc9 | 2800 | |
9854d9ed RK |
2801 | case 'C': |
2802 | /* This is an optional cror needed for LE or GE floating-point | |
2803 | comparisons. Otherwise write nothing. */ | |
2804 | if ((GET_CODE (x) == LE || GET_CODE (x) == GE) | |
2805 | && GET_MODE (XEXP (x, 0)) == CCFPmode) | |
2806 | { | |
2807 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68); | |
2808 | ||
2809 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
2810 | base_bit + 2, base_bit + (GET_CODE (x) == GE)); | |
2811 | } | |
2812 | return; | |
2813 | ||
2814 | case 'D': | |
2815 | /* Similar, except that this is for an scc, so we must be able to | |
2816 | encode the test in a single bit that is one. We do the above | |
2817 | for any LE, GE, GEU, or LEU and invert the bit for NE. */ | |
2818 | if (GET_CODE (x) == LE || GET_CODE (x) == GE | |
2819 | || GET_CODE (x) == LEU || GET_CODE (x) == GEU) | |
2820 | { | |
2821 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68); | |
2822 | ||
2823 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
2824 | base_bit + 2, | |
2825 | base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU)); | |
2826 | } | |
2827 | ||
2828 | else if (GET_CODE (x) == NE) | |
2829 | { | |
2830 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68); | |
2831 | ||
2832 | fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3, | |
2833 | base_bit + 2, base_bit + 2); | |
2834 | } | |
2835 | return; | |
2836 | ||
2837 | case 'E': | |
2838 | /* X is a CR register. Print the number of the third bit of the CR */ | |
2839 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
2840 | output_operand_lossage ("invalid %%E value"); | |
2841 | ||
2842 | fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3); | |
a85d226b | 2843 | return; |
9854d9ed RK |
2844 | |
2845 | case 'f': | |
2846 | /* X is a CR register. Print the shift count needed to move it | |
2847 | to the high-order four bits. */ | |
2848 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
2849 | output_operand_lossage ("invalid %%f value"); | |
2850 | else | |
2851 | fprintf (file, "%d", 4 * (REGNO (x) - 68)); | |
2852 | return; | |
2853 | ||
2854 | case 'F': | |
2855 | /* Similar, but print the count for the rotate in the opposite | |
2856 | direction. */ | |
2857 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
2858 | output_operand_lossage ("invalid %%F value"); | |
2859 | else | |
2860 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68)); | |
2861 | return; | |
2862 | ||
2863 | case 'G': | |
2864 | /* X is a constant integer. If it is negative, print "m", | |
2865 | otherwise print "z". This is to make a aze or ame insn. */ | |
2866 | if (GET_CODE (x) != CONST_INT) | |
2867 | output_operand_lossage ("invalid %%G value"); | |
2868 | else if (INTVAL (x) >= 0) | |
76229ac8 | 2869 | putc ('z', file); |
9854d9ed | 2870 | else |
76229ac8 | 2871 | putc ('m', file); |
9854d9ed RK |
2872 | return; |
2873 | ||
9878760c | 2874 | case 'h': |
df3d94ed RK |
2875 | /* If constant, output low-order five bits. Otherwise, |
2876 | write normally. */ | |
9878760c | 2877 | if (INT_P (x)) |
5f59ecb7 | 2878 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
2879 | else |
2880 | print_operand (file, x, 0); | |
2881 | return; | |
2882 | ||
64305719 DE |
2883 | case 'H': |
2884 | /* If constant, output low-order six bits. Otherwise, | |
2885 | write normally. */ | |
2886 | if (INT_P (x)) | |
5f59ecb7 | 2887 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
2888 | else |
2889 | print_operand (file, x, 0); | |
2890 | return; | |
2891 | ||
9854d9ed RK |
2892 | case 'I': |
2893 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 2894 | if (INT_P (x)) |
76229ac8 | 2895 | putc ('i', file); |
9878760c RK |
2896 | return; |
2897 | ||
9854d9ed RK |
2898 | case 'j': |
2899 | /* Write the bit number in CCR for jump. */ | |
2900 | i = ccr_bit (x, 0); | |
2901 | if (i == -1) | |
2902 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 2903 | else |
9854d9ed | 2904 | fprintf (file, "%d", i); |
9878760c RK |
2905 | return; |
2906 | ||
9854d9ed RK |
2907 | case 'J': |
2908 | /* Similar, but add one for shift count in rlinm for scc and pass | |
2909 | scc flag to `ccr_bit'. */ | |
2910 | i = ccr_bit (x, 1); | |
2911 | if (i == -1) | |
2912 | output_operand_lossage ("invalid %%J code"); | |
2913 | else | |
a0466a68 RK |
2914 | /* If we want bit 31, write a shift count of zero, not 32. */ |
2915 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
2916 | return; |
2917 | ||
9854d9ed RK |
2918 | case 'k': |
2919 | /* X must be a constant. Write the 1's complement of the | |
2920 | constant. */ | |
9878760c | 2921 | if (! INT_P (x)) |
9854d9ed | 2922 | output_operand_lossage ("invalid %%k value"); |
9878760c | 2923 | |
5f59ecb7 | 2924 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); |
9878760c RK |
2925 | return; |
2926 | ||
9854d9ed RK |
2927 | case 'L': |
2928 | /* Write second word of DImode or DFmode reference. Works on register | |
2929 | or non-indexed memory only. */ | |
2930 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 2931 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
2932 | else if (GET_CODE (x) == MEM) |
2933 | { | |
2934 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 2935 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
2936 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
2937 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
19087b1c DE |
2938 | output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0), |
2939 | UNITS_PER_WORD)); | |
9854d9ed | 2940 | else |
19087b1c DE |
2941 | output_address (plus_constant_for_output (XEXP (x, 0), |
2942 | UNITS_PER_WORD)); | |
ba5e43aa | 2943 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
2944 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
2945 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 2946 | } |
9878760c | 2947 | return; |
9854d9ed | 2948 | |
9878760c RK |
2949 | case 'm': |
2950 | /* MB value for a mask operand. */ | |
2951 | if (! mask_operand (x, VOIDmode)) | |
2952 | output_operand_lossage ("invalid %%m value"); | |
2953 | ||
2954 | val = INT_LOWPART (x); | |
2955 | ||
2956 | /* If the high bit is set and the low bit is not, the value is zero. | |
2957 | If the high bit is zero, the value is the first 1 bit we find from | |
2958 | the left. */ | |
34792e82 | 2959 | if ((val & 0x80000000) && ((val & 1) == 0)) |
9878760c | 2960 | { |
19d2d16f | 2961 | putc ('0', file); |
9878760c RK |
2962 | return; |
2963 | } | |
34792e82 | 2964 | else if ((val & 0x80000000) == 0) |
9878760c RK |
2965 | { |
2966 | for (i = 1; i < 32; i++) | |
34792e82 | 2967 | if ((val <<= 1) & 0x80000000) |
9878760c RK |
2968 | break; |
2969 | fprintf (file, "%d", i); | |
2970 | return; | |
2971 | } | |
2972 | ||
2973 | /* Otherwise, look for the first 0 bit from the right. The result is its | |
2974 | number plus 1. We know the low-order bit is one. */ | |
2975 | for (i = 0; i < 32; i++) | |
2976 | if (((val >>= 1) & 1) == 0) | |
2977 | break; | |
2978 | ||
a260abc9 | 2979 | /* If we ended in ...01, i would be 0. The correct value is 31, so |
9878760c RK |
2980 | we want 31 - i. */ |
2981 | fprintf (file, "%d", 31 - i); | |
2982 | return; | |
2983 | ||
2984 | case 'M': | |
2985 | /* ME value for a mask operand. */ | |
2986 | if (! mask_operand (x, VOIDmode)) | |
a260abc9 | 2987 | output_operand_lossage ("invalid %%M value"); |
9878760c RK |
2988 | |
2989 | val = INT_LOWPART (x); | |
2990 | ||
2991 | /* If the low bit is set and the high bit is not, the value is 31. | |
2992 | If the low bit is zero, the value is the first 1 bit we find from | |
2993 | the right. */ | |
34792e82 | 2994 | if ((val & 1) && ((val & 0x80000000) == 0)) |
9878760c | 2995 | { |
76229ac8 | 2996 | fputs ("31", file); |
9878760c RK |
2997 | return; |
2998 | } | |
2999 | else if ((val & 1) == 0) | |
3000 | { | |
3001 | for (i = 0; i < 32; i++) | |
3002 | if ((val >>= 1) & 1) | |
3003 | break; | |
3004 | ||
a260abc9 | 3005 | /* If we had ....10, i would be 0. The result should be |
9878760c RK |
3006 | 30, so we need 30 - i. */ |
3007 | fprintf (file, "%d", 30 - i); | |
3008 | return; | |
3009 | } | |
3010 | ||
3011 | /* Otherwise, look for the first 0 bit from the left. The result is its | |
3012 | number minus 1. We know the high-order bit is one. */ | |
3013 | for (i = 0; i < 32; i++) | |
34792e82 | 3014 | if (((val <<= 1) & 0x80000000) == 0) |
9878760c RK |
3015 | break; |
3016 | ||
3017 | fprintf (file, "%d", i); | |
3018 | return; | |
3019 | ||
9878760c RK |
3020 | case 'N': |
3021 | /* Write the number of elements in the vector times 4. */ | |
3022 | if (GET_CODE (x) != PARALLEL) | |
3023 | output_operand_lossage ("invalid %%N value"); | |
3024 | ||
3025 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
3026 | return; | |
3027 | ||
3028 | case 'O': | |
3029 | /* Similar, but subtract 1 first. */ | |
3030 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 3031 | output_operand_lossage ("invalid %%O value"); |
9878760c RK |
3032 | |
3033 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
3034 | return; | |
3035 | ||
9854d9ed RK |
3036 | case 'p': |
3037 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
3038 | if (! INT_P (x) | |
3039 | || (i = exact_log2 (INT_LOWPART (x))) < 0) | |
3040 | output_operand_lossage ("invalid %%p value"); | |
3041 | ||
3042 | fprintf (file, "%d", i); | |
3043 | return; | |
3044 | ||
9878760c RK |
3045 | case 'P': |
3046 | /* The operand must be an indirect memory reference. The result | |
3047 | is the register number. */ | |
3048 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG | |
3049 | || REGNO (XEXP (x, 0)) >= 32) | |
3050 | output_operand_lossage ("invalid %%P value"); | |
3051 | ||
3052 | fprintf (file, "%d", REGNO (XEXP (x, 0))); | |
3053 | return; | |
3054 | ||
9854d9ed RK |
3055 | case 'R': |
3056 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
3057 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
3058 | output_operand_lossage ("invalid %%R value"); | |
3059 | else | |
3060 | fprintf (file, "%d", 128 >> (REGNO (x) - 68)); | |
9878760c | 3061 | return; |
9854d9ed RK |
3062 | |
3063 | case 's': | |
3064 | /* Low 5 bits of 32 - value */ | |
3065 | if (! INT_P (x)) | |
3066 | output_operand_lossage ("invalid %%s value"); | |
3067 | ||
5f59ecb7 | 3068 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); |
9878760c | 3069 | return; |
9854d9ed | 3070 | |
a260abc9 DE |
3071 | case 'S': |
3072 | /* PowerPC64 mask position. All 0's and all 1's are excluded. | |
3073 | CONST_INT 32-bit mask is considered sign-extended so any | |
3074 | transition must occur within the CONST_INT, not on the boundary. */ | |
3075 | if (! mask64_operand (x, VOIDmode)) | |
3076 | output_operand_lossage ("invalid %%S value"); | |
3077 | ||
3078 | val = INT_LOWPART (x); | |
3079 | ||
3080 | if (val & 1) /* Clear Left */ | |
3081 | { | |
a238cd8b DE |
3082 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
3083 | if (!((val >>= 1) & 1)) | |
3084 | break; | |
a260abc9 | 3085 | |
a238cd8b DE |
3086 | #if HOST_BITS_PER_WIDE_INT == 32 |
3087 | if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
3088 | { | |
3089 | val = CONST_DOUBLE_HIGH (x); | |
3090 | ||
3091 | if (val == 0) | |
3092 | --i; | |
3093 | else | |
3094 | for (i = 32; i < 64; i++) | |
3095 | if (!((val >>= 1) & 1)) | |
3096 | break; | |
3097 | } | |
a260abc9 | 3098 | #endif |
a238cd8b DE |
3099 | /* i = index of last set bit from right |
3100 | mask begins at 63 - i from left */ | |
3101 | if (i > 63) | |
3102 | output_operand_lossage ("%%S computed all 1's mask"); | |
a260abc9 DE |
3103 | fprintf (file, "%d", 63 - i); |
3104 | return; | |
3105 | } | |
3106 | else /* Clear Right */ | |
3107 | { | |
a238cd8b DE |
3108 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
3109 | if ((val >>= 1) & 1) | |
3110 | break; | |
a260abc9 | 3111 | |
a238cd8b | 3112 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
3113 | if (GET_CODE (x) == CONST_DOUBLE && i == 32) |
3114 | { | |
a238cd8b | 3115 | val = CONST_DOUBLE_HIGH (x); |
a260abc9 | 3116 | |
a238cd8b | 3117 | if (val == (HOST_WIDE_INT) -1) |
a260abc9 | 3118 | --i; |
a260abc9 | 3119 | else |
a238cd8b DE |
3120 | for (i = 32; i < 64; i++) |
3121 | if ((val >>= 1) & 1) | |
a260abc9 DE |
3122 | break; |
3123 | } | |
3124 | #endif | |
a238cd8b DE |
3125 | /* i = index of last clear bit from right |
3126 | mask ends at 62 - i from left */ | |
3127 | if (i > 62) | |
3128 | output_operand_lossage ("%%S computed all 0's mask"); | |
3129 | fprintf (file, "%d", 62 - i); | |
a260abc9 DE |
3130 | return; |
3131 | } | |
3132 | ||
9878760c RK |
3133 | case 't': |
3134 | /* Write 12 if this jump operation will branch if true, 4 otherwise. | |
3135 | All floating-point operations except NE branch true and integer | |
3136 | EQ, LT, GT, LTU and GTU also branch true. */ | |
3137 | if (GET_RTX_CLASS (GET_CODE (x)) != '<') | |
3138 | output_operand_lossage ("invalid %%t value"); | |
3139 | ||
3140 | else if ((GET_MODE (XEXP (x, 0)) == CCFPmode | |
3141 | && GET_CODE (x) != NE) | |
3142 | || GET_CODE (x) == EQ | |
3143 | || GET_CODE (x) == LT || GET_CODE (x) == GT | |
3144 | || GET_CODE (x) == LTU || GET_CODE (x) == GTU) | |
76229ac8 | 3145 | fputs ("12", file); |
9878760c | 3146 | else |
76229ac8 | 3147 | putc ('4', file); |
9878760c RK |
3148 | return; |
3149 | ||
3150 | case 'T': | |
3151 | /* Opposite of 't': write 4 if this jump operation will branch if true, | |
3152 | 12 otherwise. */ | |
3153 | if (GET_RTX_CLASS (GET_CODE (x)) != '<') | |
1427100a | 3154 | output_operand_lossage ("invalid %%T value"); |
9878760c RK |
3155 | |
3156 | else if ((GET_MODE (XEXP (x, 0)) == CCFPmode | |
3157 | && GET_CODE (x) != NE) | |
3158 | || GET_CODE (x) == EQ | |
3159 | || GET_CODE (x) == LT || GET_CODE (x) == GT | |
3160 | || GET_CODE (x) == LTU || GET_CODE (x) == GTU) | |
76229ac8 | 3161 | putc ('4', file); |
9878760c | 3162 | else |
76229ac8 | 3163 | fputs ("12", file); |
9878760c RK |
3164 | return; |
3165 | ||
9854d9ed | 3166 | case 'u': |
802a0058 | 3167 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
3168 | if (! INT_P (x)) |
3169 | output_operand_lossage ("invalid %%u value"); | |
9878760c | 3170 | |
5f59ecb7 DE |
3171 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
3172 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
3173 | return; |
3174 | ||
802a0058 MM |
3175 | case 'v': |
3176 | /* High-order 16 bits of constant for use in signed operand. */ | |
3177 | if (! INT_P (x)) | |
3178 | output_operand_lossage ("invalid %%v value"); | |
3179 | ||
3180 | { | |
3181 | int value = (INT_LOWPART (x) >> 16) & 0xffff; | |
3182 | ||
9615f239 | 3183 | /* Solaris assembler doesn't like lis 0,0x8000 */ |
802a0058 MM |
3184 | if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0) |
3185 | fprintf (file, "%d", value | (~0 << 16)); | |
3186 | else | |
3187 | fprintf (file, "0x%x", value); | |
3188 | return; | |
3189 | } | |
3190 | ||
9854d9ed RK |
3191 | case 'U': |
3192 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
3193 | if (GET_CODE (x) == MEM | |
3194 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
3195 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 3196 | putc ('u', file); |
9854d9ed | 3197 | return; |
9878760c | 3198 | |
e0cd0770 JC |
3199 | case 'V': |
3200 | /* Print the trap code for this operand. */ | |
3201 | switch (GET_CODE (x)) | |
3202 | { | |
3203 | case EQ: | |
3204 | fputs ("eq", file); /* 4 */ | |
3205 | break; | |
3206 | case NE: | |
3207 | fputs ("ne", file); /* 24 */ | |
3208 | break; | |
3209 | case LT: | |
3210 | fputs ("lt", file); /* 16 */ | |
3211 | break; | |
3212 | case LE: | |
3213 | fputs ("le", file); /* 20 */ | |
3214 | break; | |
3215 | case GT: | |
3216 | fputs ("gt", file); /* 8 */ | |
3217 | break; | |
3218 | case GE: | |
3219 | fputs ("ge", file); /* 12 */ | |
3220 | break; | |
3221 | case LTU: | |
3222 | fputs ("llt", file); /* 2 */ | |
3223 | break; | |
3224 | case LEU: | |
3225 | fputs ("lle", file); /* 6 */ | |
3226 | break; | |
3227 | case GTU: | |
3228 | fputs ("lgt", file); /* 1 */ | |
3229 | break; | |
3230 | case GEU: | |
3231 | fputs ("lge", file); /* 5 */ | |
3232 | break; | |
3233 | default: | |
3234 | abort (); | |
3235 | } | |
3236 | break; | |
3237 | ||
9854d9ed RK |
3238 | case 'w': |
3239 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
3240 | normally. */ | |
3241 | if (INT_P (x)) | |
5f59ecb7 DE |
3242 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
3243 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
3244 | else |
3245 | print_operand (file, x, 0); | |
9878760c RK |
3246 | return; |
3247 | ||
9854d9ed RK |
3248 | case 'W': |
3249 | /* If constant, low-order 16 bits of constant, unsigned. | |
3250 | Otherwise, write normally. */ | |
3251 | if (INT_P (x)) | |
5f59ecb7 | 3252 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); |
9854d9ed RK |
3253 | else |
3254 | print_operand (file, x, 0); | |
3255 | return; | |
9878760c | 3256 | |
9854d9ed RK |
3257 | case 'X': |
3258 | if (GET_CODE (x) == MEM | |
3259 | && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0))) | |
76229ac8 | 3260 | putc ('x', file); |
9854d9ed | 3261 | return; |
9878760c | 3262 | |
9854d9ed RK |
3263 | case 'Y': |
3264 | /* Like 'L', for third word of TImode */ | |
3265 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 3266 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 3267 | else if (GET_CODE (x) == MEM) |
9878760c | 3268 | { |
9854d9ed RK |
3269 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
3270 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 3271 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 3272 | else |
a54d04b7 | 3273 | output_address (plus_constant (XEXP (x, 0), 8)); |
ba5e43aa | 3274 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
3275 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
3276 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
3277 | } |
3278 | return; | |
9854d9ed | 3279 | |
9878760c | 3280 | case 'z': |
b4ac57ab RS |
3281 | /* X is a SYMBOL_REF. Write out the name preceded by a |
3282 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
3283 | names. If we are configured for System V (or the embedded ABI) on |
3284 | the PowerPC, do not emit the period, since those systems do not use | |
3285 | TOCs and the like. */ | |
9878760c RK |
3286 | if (GET_CODE (x) != SYMBOL_REF) |
3287 | abort (); | |
3288 | ||
b6c9286a MM |
3289 | if (XSTR (x, 0)[0] != '.') |
3290 | { | |
3291 | switch (DEFAULT_ABI) | |
3292 | { | |
3293 | default: | |
3294 | abort (); | |
3295 | ||
3296 | case ABI_AIX: | |
3297 | putc ('.', file); | |
3298 | break; | |
3299 | ||
3300 | case ABI_V4: | |
3301 | case ABI_AIX_NODESC: | |
c81bebd7 | 3302 | case ABI_SOLARIS: |
b6c9286a MM |
3303 | break; |
3304 | ||
3305 | case ABI_NT: | |
3306 | fputs ("..", file); | |
3307 | break; | |
3308 | } | |
3309 | } | |
9878760c RK |
3310 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); |
3311 | return; | |
3312 | ||
9854d9ed RK |
3313 | case 'Z': |
3314 | /* Like 'L', for last word of TImode. */ | |
3315 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 3316 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
3317 | else if (GET_CODE (x) == MEM) |
3318 | { | |
3319 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
3320 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 3321 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 3322 | else |
a54d04b7 | 3323 | output_address (plus_constant (XEXP (x, 0), 12)); |
ba5e43aa | 3324 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
3325 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
3326 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 3327 | } |
5c23c401 | 3328 | return; |
9854d9ed | 3329 | |
9878760c RK |
3330 | case 0: |
3331 | if (GET_CODE (x) == REG) | |
3332 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
3333 | else if (GET_CODE (x) == MEM) | |
3334 | { | |
3335 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
3336 | know the width from the mode. */ | |
3337 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
3338 | fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)), | |
3339 | REGNO (XEXP (XEXP (x, 0), 0))); | |
3340 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
3341 | fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)), | |
3342 | REGNO (XEXP (XEXP (x, 0), 0))); | |
3343 | else | |
a54d04b7 | 3344 | output_address (XEXP (x, 0)); |
9878760c RK |
3345 | } |
3346 | else | |
a54d04b7 | 3347 | output_addr_const (file, x); |
a85d226b | 3348 | return; |
9878760c RK |
3349 | |
3350 | default: | |
3351 | output_operand_lossage ("invalid %%xn code"); | |
3352 | } | |
3353 | } | |
3354 | \f | |
3355 | /* Print the address of an operand. */ | |
3356 | ||
3357 | void | |
3358 | print_operand_address (file, x) | |
3359 | FILE *file; | |
3360 | register rtx x; | |
3361 | { | |
3362 | if (GET_CODE (x) == REG) | |
4697a36c | 3363 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
24f30767 | 3364 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST || GET_CODE (x) == LABEL_REF) |
9878760c RK |
3365 | { |
3366 | output_addr_const (file, x); | |
ba5e43aa | 3367 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
3368 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
3369 | reg_names[SMALL_DATA_REG]); | |
7509c759 | 3370 | |
4697a36c | 3371 | #ifdef TARGET_NO_TOC |
7509c759 | 3372 | else if (TARGET_NO_TOC) |
4697a36c | 3373 | ; |
4697a36c | 3374 | #endif |
7509c759 | 3375 | else |
8d30c4ee | 3376 | fprintf (file, "(%s)", reg_names[ TARGET_MINIMAL_TOC ? 30 : 2 /* PIC_OFFSET_TABLE_REGNUM? */ ]); |
9878760c RK |
3377 | } |
3378 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
3379 | { | |
3380 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
3381 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
3382 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 3383 | else |
4697a36c MM |
3384 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
3385 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
3386 | } |
3387 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
5f59ecb7 DE |
3388 | { |
3389 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1))); | |
3390 | fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
3391 | } | |
3cb999d8 DE |
3392 | #if TARGET_ELF |
3393 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
3394 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
3395 | { |
3396 | output_addr_const (file, XEXP (x, 1)); | |
3397 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
3398 | } | |
3cb999d8 | 3399 | #endif |
9878760c RK |
3400 | else |
3401 | abort (); | |
3402 | } | |
3403 | \f | |
3404 | /* This page contains routines that are used to determine what the function | |
3405 | prologue and epilogue code will do and write them out. */ | |
3406 | ||
3407 | /* Return the first fixed-point register that is required to be saved. 32 if | |
3408 | none. */ | |
3409 | ||
3410 | int | |
3411 | first_reg_to_save () | |
3412 | { | |
3413 | int first_reg; | |
3414 | ||
3415 | /* Find lowest numbered live register. */ | |
3416 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
3417 | if (regs_ever_live[first_reg]) | |
3418 | break; | |
3419 | ||
b5253831 DE |
3420 | if (profile_flag) |
3421 | { | |
3422 | /* AIX must save/restore every register that contains a parameter | |
3423 | before/after the .__mcount call plus an additional register | |
3424 | for the static chain, if needed; use registers from 30 down to 22 | |
3425 | to do this. */ | |
3426 | if (DEFAULT_ABI == ABI_AIX) | |
3427 | { | |
3428 | int last_parm_reg, profile_first_reg; | |
3429 | ||
3430 | /* Figure out last used parameter register. The proper thing | |
3431 | to do is to walk incoming args of the function. A function | |
3432 | might have live parameter registers even if it has no | |
3433 | incoming args. */ | |
3434 | for (last_parm_reg = 10; | |
3435 | last_parm_reg > 2 && ! regs_ever_live [last_parm_reg]; | |
3436 | last_parm_reg--) | |
3437 | ; | |
3438 | ||
3439 | /* Calculate first reg for saving parameter registers | |
3440 | and static chain. | |
3441 | Skip reg 31 which may contain the frame pointer. */ | |
3442 | profile_first_reg = (33 - last_parm_reg | |
3443 | - (current_function_needs_context ? 1 : 0)); | |
3444 | /* Do not save frame pointer if no parameters needs to be saved. */ | |
3445 | if (profile_first_reg == 31) | |
3446 | profile_first_reg = 32; | |
3447 | ||
3448 | if (first_reg > profile_first_reg) | |
3449 | first_reg = profile_first_reg; | |
3450 | } | |
e165f3f0 | 3451 | |
b5253831 DE |
3452 | /* SVR4 may need one register to preserve the static chain. */ |
3453 | else if (current_function_needs_context) | |
3454 | { | |
3455 | /* Skip reg 31 which may contain the frame pointer. */ | |
3456 | if (first_reg > 30) | |
3457 | first_reg = 30; | |
3458 | } | |
3459 | } | |
e165f3f0 | 3460 | |
9878760c RK |
3461 | return first_reg; |
3462 | } | |
3463 | ||
3464 | /* Similar, for FP regs. */ | |
3465 | ||
3466 | int | |
3467 | first_fp_reg_to_save () | |
3468 | { | |
3469 | int first_reg; | |
3470 | ||
3471 | /* Find lowest numbered live register. */ | |
3472 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
3473 | if (regs_ever_live[first_reg]) | |
3474 | break; | |
3475 | ||
3476 | return first_reg; | |
3477 | } | |
3478 | ||
9878760c RK |
3479 | /* Return non-zero if this function makes calls. */ |
3480 | ||
3481 | int | |
3482 | rs6000_makes_calls () | |
3483 | { | |
3484 | rtx insn; | |
3485 | ||
38c1f2d7 MM |
3486 | /* If we are profiling, we will be making a call to __mcount. |
3487 | Under the System V ABI's, we store the LR directly, so | |
3488 | we don't need to do it here. */ | |
3489 | if (DEFAULT_ABI == ABI_AIX && profile_flag) | |
0c61c946 RK |
3490 | return 1; |
3491 | ||
9878760c RK |
3492 | for (insn = get_insns (); insn; insn = next_insn (insn)) |
3493 | if (GET_CODE (insn) == CALL_INSN) | |
3494 | return 1; | |
3495 | ||
3496 | return 0; | |
3497 | } | |
3498 | ||
4697a36c MM |
3499 | \f |
3500 | /* Calculate the stack information for the current function. This is | |
3501 | complicated by having two separate calling sequences, the AIX calling | |
3502 | sequence and the V.4 calling sequence. | |
3503 | ||
3504 | AIX stack frames look like: | |
a260abc9 | 3505 | 32-bit 64-bit |
4697a36c | 3506 | SP----> +---------------------------------------+ |
a260abc9 | 3507 | | back chain to caller | 0 0 |
4697a36c | 3508 | +---------------------------------------+ |
a260abc9 | 3509 | | saved CR | 4 8 (8-11) |
4697a36c | 3510 | +---------------------------------------+ |
a260abc9 | 3511 | | saved LR | 8 16 |
4697a36c | 3512 | +---------------------------------------+ |
a260abc9 | 3513 | | reserved for compilers | 12 24 |
4697a36c | 3514 | +---------------------------------------+ |
a260abc9 | 3515 | | reserved for binders | 16 32 |
4697a36c | 3516 | +---------------------------------------+ |
a260abc9 | 3517 | | saved TOC pointer | 20 40 |
4697a36c | 3518 | +---------------------------------------+ |
a260abc9 | 3519 | | Parameter save area (P) | 24 48 |
4697a36c | 3520 | +---------------------------------------+ |
a260abc9 | 3521 | | Alloca space (A) | 24+P etc. |
802a0058 | 3522 | +---------------------------------------+ |
a7df97e6 | 3523 | | Local variable space (L) | 24+P+A |
4697a36c | 3524 | +---------------------------------------+ |
a7df97e6 | 3525 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 3526 | +---------------------------------------+ |
a7df97e6 | 3527 | | Save area for GP registers (G) | 24+P+A+X+L |
4697a36c | 3528 | +---------------------------------------+ |
a7df97e6 | 3529 | | Save area for FP registers (F) | 24+P+A+X+L+G |
4697a36c MM |
3530 | +---------------------------------------+ |
3531 | old SP->| back chain to caller's caller | | |
3532 | +---------------------------------------+ | |
3533 | ||
5376a30c KR |
3534 | The required alignment for AIX configurations is two words (i.e., 8 |
3535 | or 16 bytes). | |
3536 | ||
3537 | ||
4697a36c MM |
3538 | V.4 stack frames look like: |
3539 | ||
3540 | SP----> +---------------------------------------+ | |
3541 | | back chain to caller | 0 | |
3542 | +---------------------------------------+ | |
5eb387b8 | 3543 | | caller's saved LR | 4 |
4697a36c MM |
3544 | +---------------------------------------+ |
3545 | | Parameter save area (P) | 8 | |
3546 | +---------------------------------------+ | |
a7df97e6 MM |
3547 | | Alloca space (A) | 8+P |
3548 | +---------------------------------------+ | |
3549 | | Varargs save area (V) | 8+P+A | |
3550 | +---------------------------------------+ | |
3551 | | Local variable space (L) | 8+P+A+V | |
3552 | +---------------------------------------+ | |
3553 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 3554 | +---------------------------------------+ |
a7df97e6 MM |
3555 | | saved CR (C) | 8+P+A+V+L+X |
3556 | +---------------------------------------+ | |
3557 | | Save area for GP registers (G) | 8+P+A+V+L+X+C | |
3558 | +---------------------------------------+ | |
3559 | | Save area for FP registers (F) | 8+P+A+V+L+X+C+G | |
4697a36c MM |
3560 | +---------------------------------------+ |
3561 | old SP->| back chain to caller's caller | | |
3562 | +---------------------------------------+ | |
b6c9286a | 3563 | |
5376a30c KR |
3564 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
3565 | given. (But note below and in sysv4.h that we require only 8 and | |
3566 | may round up the size of our stack frame anyways. The historical | |
3567 | reason is early versions of powerpc-linux which didn't properly | |
3568 | align the stack at program startup. A happy side-effect is that | |
3569 | -mno-eabi libraries can be used with -meabi programs.) | |
3570 | ||
b6c9286a MM |
3571 | |
3572 | A PowerPC Windows/NT frame looks like: | |
3573 | ||
3574 | SP----> +---------------------------------------+ | |
3575 | | back chain to caller | 0 | |
3576 | +---------------------------------------+ | |
3577 | | reserved | 4 | |
3578 | +---------------------------------------+ | |
3579 | | reserved | 8 | |
3580 | +---------------------------------------+ | |
3581 | | reserved | 12 | |
3582 | +---------------------------------------+ | |
3583 | | reserved | 16 | |
3584 | +---------------------------------------+ | |
3585 | | reserved | 20 | |
3586 | +---------------------------------------+ | |
3587 | | Parameter save area (P) | 24 | |
3588 | +---------------------------------------+ | |
a7df97e6 MM |
3589 | | Alloca space (A) | 24+P |
3590 | +---------------------------------------+ | |
3591 | | Local variable space (L) | 24+P+A | |
3592 | +---------------------------------------+ | |
3593 | | Float/int conversion temporary (X) | 24+P+A+L | |
b6c9286a | 3594 | +---------------------------------------+ |
a7df97e6 MM |
3595 | | Save area for FP registers (F) | 24+P+A+L+X |
3596 | +---------------------------------------+ | |
3597 | | Possible alignment area (Y) | 24+P+A+L+X+F | |
3598 | +---------------------------------------+ | |
3599 | | Save area for GP registers (G) | 24+P+A+L+X+F+Y | |
3600 | +---------------------------------------+ | |
3601 | | Save area for CR (C) | 24+P+A+L+X+F+Y+G | |
3602 | +---------------------------------------+ | |
3603 | | Save area for TOC (T) | 24+P+A+L+X+F+Y+G+C | |
3604 | +---------------------------------------+ | |
3605 | | Save area for LR (R) | 24+P+A+L+X+F+Y+G+C+T | |
b6c9286a MM |
3606 | +---------------------------------------+ |
3607 | old SP->| back chain to caller's caller | | |
3608 | +---------------------------------------+ | |
3609 | ||
3610 | For NT, there is no specific order to save the registers, but in | |
3611 | order to support __builtin_return_address, the save area for the | |
3612 | link register needs to be in a known place, so we use -4 off of the | |
3613 | old SP. To support calls through pointers, we also allocate a | |
5376a30c KR |
3614 | fixed slot to store the TOC, -8 off the old SP. |
3615 | ||
3616 | The required alignment for NT is 16 bytes. | |
3617 | ||
3618 | ||
3619 | The EABI configuration defaults to the V.4 layout, unless | |
3620 | -mcall-aix is used, in which case the AIX layout is used. However, | |
3621 | the stack alignment requirements may differ. If -mno-eabi is not | |
3622 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
3623 | given, the required alignment is 16 bytes. (But see V.4 comment | |
3624 | above.) */ | |
4697a36c | 3625 | |
61b2fbe7 MM |
3626 | #ifndef ABI_STACK_BOUNDARY |
3627 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
3628 | #endif | |
3629 | ||
4697a36c MM |
3630 | rs6000_stack_t * |
3631 | rs6000_stack_info () | |
3632 | { | |
3633 | static rs6000_stack_t info, zero_info; | |
3634 | rs6000_stack_t *info_ptr = &info; | |
a260abc9 | 3635 | int reg_size = TARGET_32BIT ? 4 : 8; |
24d304eb | 3636 | enum rs6000_abi abi; |
b6c9286a | 3637 | int total_raw_size; |
4697a36c MM |
3638 | |
3639 | /* Zero all fields portably */ | |
3640 | info = zero_info; | |
3641 | ||
3642 | /* Select which calling sequence */ | |
b6c9286a | 3643 | info_ptr->abi = abi = DEFAULT_ABI; |
9878760c | 3644 | |
4697a36c MM |
3645 | /* Calculate which registers need to be saved & save area size */ |
3646 | info_ptr->first_gp_reg_save = first_reg_to_save (); | |
906fb125 GK |
3647 | /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM, |
3648 | even if it currently looks like we won't. */ | |
3649 | if (flag_pic == 1 | |
3650 | && (abi == ABI_V4 || abi == ABI_SOLARIS) | |
3651 | && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM) | |
3652 | info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM); | |
3653 | else | |
3654 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c MM |
3655 | |
3656 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); | |
3657 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
3658 | ||
3659 | /* Does this function call anything? */ | |
3660 | info_ptr->calls_p = rs6000_makes_calls (); | |
3661 | ||
62c0fb87 | 3662 | /* Allocate space to save the toc. */ |
82280d5e | 3663 | if (abi == ABI_NT && info_ptr->calls_p) |
b6c9286a MM |
3664 | { |
3665 | info_ptr->toc_save_p = 1; | |
3666 | info_ptr->toc_size = reg_size; | |
3667 | } | |
3668 | ||
802a0058 MM |
3669 | /* Does this machine need the float/int conversion area? */ |
3670 | info_ptr->fpmem_p = regs_ever_live[FPMEM_REGNUM]; | |
3671 | ||
b6c9286a MM |
3672 | /* If this is main and we need to call a function to set things up, |
3673 | save main's arguments around the call. */ | |
c81bebd7 MM |
3674 | #ifdef TARGET_EABI |
3675 | if (TARGET_EABI) | |
3676 | #endif | |
b6c9286a | 3677 | { |
30ccf55d MS |
3678 | if (strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main") == 0 |
3679 | && DECL_CONTEXT (current_function_decl) == NULL_TREE) | |
b6c9286a | 3680 | { |
c81bebd7 | 3681 | info_ptr->main_p = 1; |
b6c9286a | 3682 | |
c81bebd7 MM |
3683 | #ifdef NAME__MAIN |
3684 | info_ptr->calls_p = 1; | |
b6c9286a | 3685 | |
c81bebd7 | 3686 | if (DECL_ARGUMENTS (current_function_decl)) |
b6c9286a | 3687 | { |
c81bebd7 MM |
3688 | int i; |
3689 | tree arg; | |
3690 | ||
3691 | info_ptr->main_save_p = 1; | |
3692 | info_ptr->main_size = 0; | |
3693 | ||
3694 | for ((i = 0), (arg = DECL_ARGUMENTS (current_function_decl)); | |
3695 | arg != NULL_TREE && i < 8; | |
3696 | (arg = TREE_CHAIN (arg)), i++) | |
3697 | { | |
3698 | info_ptr->main_size += reg_size; | |
3699 | } | |
b6c9286a | 3700 | } |
b6c9286a | 3701 | #endif |
c81bebd7 | 3702 | } |
b6c9286a MM |
3703 | } |
3704 | ||
4697a36c | 3705 | /* Determine if we need to save the link register */ |
38c1f2d7 MM |
3706 | if (regs_ever_live[65] |
3707 | || (DEFAULT_ABI == ABI_AIX && profile_flag) | |
4697a36c MM |
3708 | #ifdef TARGET_RELOCATABLE |
3709 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
3710 | #endif | |
3711 | || (info_ptr->first_fp_reg_save != 64 | |
3712 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
24d304eb | 3713 | || (abi == ABI_V4 && current_function_calls_alloca) |
c81bebd7 | 3714 | || (abi == ABI_SOLARIS && current_function_calls_alloca) |
4697a36c MM |
3715 | || info_ptr->calls_p) |
3716 | { | |
3717 | info_ptr->lr_save_p = 1; | |
3718 | regs_ever_live[65] = 1; | |
b6c9286a MM |
3719 | if (abi == ABI_NT) |
3720 | info_ptr->lr_size = reg_size; | |
4697a36c MM |
3721 | } |
3722 | ||
3723 | /* Determine if we need to save the condition code registers */ | |
3724 | if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72]) | |
3725 | { | |
3726 | info_ptr->cr_save_p = 1; | |
c81bebd7 | 3727 | if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS) |
4697a36c MM |
3728 | info_ptr->cr_size = reg_size; |
3729 | } | |
3730 | ||
3731 | /* Determine various sizes */ | |
3732 | info_ptr->reg_size = reg_size; | |
3733 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
3734 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 DE |
3735 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
3736 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8); | |
802a0058 | 3737 | info_ptr->fpmem_size = (info_ptr->fpmem_p) ? 8 : 0; |
189e03e3 | 3738 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
b6c9286a MM |
3739 | + info_ptr->gp_size |
3740 | + info_ptr->cr_size | |
3741 | + info_ptr->lr_size | |
3742 | + info_ptr->toc_size | |
3743 | + info_ptr->main_size, 8); | |
3744 | ||
4697a36c | 3745 | /* Calculate the offsets */ |
24d304eb | 3746 | switch (abi) |
4697a36c | 3747 | { |
b6c9286a | 3748 | case ABI_NONE: |
24d304eb | 3749 | default: |
b6c9286a MM |
3750 | abort (); |
3751 | ||
3752 | case ABI_AIX: | |
3753 | case ABI_AIX_NODESC: | |
3754 | info_ptr->fp_save_offset = - info_ptr->fp_size; | |
3755 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
3756 | info_ptr->main_save_offset = info_ptr->gp_save_offset - info_ptr->main_size; | |
a260abc9 DE |
3757 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
3758 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
3759 | break; |
3760 | ||
3761 | case ABI_V4: | |
c81bebd7 | 3762 | case ABI_SOLARIS: |
b6c9286a MM |
3763 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
3764 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 MM |
3765 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
3766 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
3767 | info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->main_size; | |
b6c9286a MM |
3768 | info_ptr->lr_save_offset = reg_size; |
3769 | break; | |
3770 | ||
3771 | case ABI_NT: | |
a260abc9 | 3772 | info_ptr->lr_save_offset = -reg_size; |
b6c9286a MM |
3773 | info_ptr->toc_save_offset = info_ptr->lr_save_offset - info_ptr->lr_size; |
3774 | info_ptr->cr_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size; | |
3775 | info_ptr->gp_save_offset = info_ptr->cr_save_offset - info_ptr->cr_size - info_ptr->gp_size + reg_size; | |
3776 | info_ptr->fp_save_offset = info_ptr->gp_save_offset - info_ptr->fp_size; | |
3777 | if (info_ptr->fp_size && ((- info_ptr->fp_save_offset) % 8) != 0) | |
a260abc9 | 3778 | info_ptr->fp_save_offset -= reg_size; |
b6c9286a MM |
3779 | |
3780 | info_ptr->main_save_offset = info_ptr->fp_save_offset - info_ptr->main_size; | |
24d304eb | 3781 | break; |
4697a36c MM |
3782 | } |
3783 | ||
34792e82 | 3784 | /* Ensure that fpmem_offset will be aligned to an 8-byte boundary. */ |
ff381587 MM |
3785 | if (info_ptr->fpmem_p |
3786 | && (info_ptr->main_save_offset - info_ptr->fpmem_size) % 8) | |
3787 | info_ptr->fpmem_size += reg_size; | |
3788 | ||
3789 | total_raw_size = (info_ptr->vars_size | |
3790 | + info_ptr->parm_size | |
3791 | + info_ptr->fpmem_size | |
3792 | + info_ptr->save_size | |
3793 | + info_ptr->varargs_size | |
3794 | + info_ptr->fixed_size); | |
3795 | ||
3796 | info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
3797 | ||
3798 | /* Determine if we need to allocate any stack frame: | |
3799 | ||
3800 | For AIX we need to push the stack if a frame pointer is needed (because | |
3801 | the stack might be dynamically adjusted), if we are debugging, if we | |
3802 | make calls, or if the sum of fp_save, gp_save, fpmem, and local variables | |
3803 | are more than the space needed to save all non-volatile registers: | |
bfc79d3b | 3804 | 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved). |
ff381587 MM |
3805 | |
3806 | For V.4 we don't have the stack cushion that AIX uses, but assume that | |
3807 | the debugger can handle stackless frames. */ | |
3808 | ||
3809 | if (info_ptr->calls_p) | |
3810 | info_ptr->push_p = 1; | |
3811 | ||
3812 | else if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS) | |
3813 | info_ptr->push_p = (total_raw_size > info_ptr->fixed_size | |
3814 | || (abi == ABI_NT ? info_ptr->lr_save_p | |
3815 | : info_ptr->calls_p)); | |
3816 | ||
3817 | else | |
3818 | info_ptr->push_p = (frame_pointer_needed | |
3819 | || write_symbols != NO_DEBUG | |
3820 | || ((total_raw_size - info_ptr->fixed_size) | |
bfc79d3b | 3821 | > (TARGET_32BIT ? 220 : 288))); |
ff381587 | 3822 | |
a7df97e6 | 3823 | if (info_ptr->fpmem_p) |
db72d7a1 DE |
3824 | { |
3825 | info_ptr->fpmem_offset = info_ptr->main_save_offset - info_ptr->fpmem_size; | |
3826 | rs6000_fpmem_size = info_ptr->fpmem_size; | |
a260abc9 DE |
3827 | rs6000_fpmem_offset = (info_ptr->push_p |
3828 | ? info_ptr->total_size + info_ptr->fpmem_offset | |
3829 | : info_ptr->fpmem_offset); | |
db72d7a1 DE |
3830 | } |
3831 | else | |
3832 | info_ptr->fpmem_offset = 0; | |
a7df97e6 | 3833 | |
4697a36c | 3834 | /* Zero offsets if we're not saving those registers */ |
8dda1a21 | 3835 | if (info_ptr->fp_size == 0) |
4697a36c MM |
3836 | info_ptr->fp_save_offset = 0; |
3837 | ||
8dda1a21 | 3838 | if (info_ptr->gp_size == 0) |
4697a36c MM |
3839 | info_ptr->gp_save_offset = 0; |
3840 | ||
3841 | if (!info_ptr->lr_save_p) | |
3842 | info_ptr->lr_save_offset = 0; | |
3843 | ||
3844 | if (!info_ptr->cr_save_p) | |
3845 | info_ptr->cr_save_offset = 0; | |
3846 | ||
b6c9286a MM |
3847 | if (!info_ptr->toc_save_p) |
3848 | info_ptr->toc_save_offset = 0; | |
3849 | ||
3850 | if (!info_ptr->main_save_p) | |
3851 | info_ptr->main_save_offset = 0; | |
3852 | ||
4697a36c MM |
3853 | return info_ptr; |
3854 | } | |
3855 | ||
3856 | void | |
3857 | debug_stack_info (info) | |
3858 | rs6000_stack_t *info; | |
9878760c | 3859 | { |
d330fd93 | 3860 | const char *abi_string; |
24d304eb | 3861 | |
4697a36c MM |
3862 | if (!info) |
3863 | info = rs6000_stack_info (); | |
3864 | ||
3865 | fprintf (stderr, "\nStack information for function %s:\n", | |
3866 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
3867 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
3868 | : "<unknown>")); | |
3869 | ||
24d304eb RK |
3870 | switch (info->abi) |
3871 | { | |
b6c9286a MM |
3872 | default: abi_string = "Unknown"; break; |
3873 | case ABI_NONE: abi_string = "NONE"; break; | |
3874 | case ABI_AIX: abi_string = "AIX"; break; | |
3875 | case ABI_AIX_NODESC: abi_string = "AIX"; break; | |
3876 | case ABI_V4: abi_string = "V.4"; break; | |
c81bebd7 | 3877 | case ABI_SOLARIS: abi_string = "Solaris"; break; |
b6c9286a | 3878 | case ABI_NT: abi_string = "NT"; break; |
24d304eb RK |
3879 | } |
3880 | ||
3881 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
3882 | ||
4697a36c MM |
3883 | if (info->first_gp_reg_save != 32) |
3884 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
3885 | ||
3886 | if (info->first_fp_reg_save != 64) | |
3887 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 3888 | |
4697a36c MM |
3889 | if (info->lr_save_p) |
3890 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 3891 | |
4697a36c MM |
3892 | if (info->cr_save_p) |
3893 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
3894 | ||
b6c9286a MM |
3895 | if (info->toc_save_p) |
3896 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
3897 | ||
4697a36c MM |
3898 | if (info->push_p) |
3899 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
3900 | ||
3901 | if (info->calls_p) | |
3902 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
3903 | ||
b6c9286a MM |
3904 | if (info->main_p) |
3905 | fprintf (stderr, "\tmain_p = %5d\n", info->main_p); | |
3906 | ||
3907 | if (info->main_save_p) | |
3908 | fprintf (stderr, "\tmain_save_p = %5d\n", info->main_save_p); | |
3909 | ||
802a0058 MM |
3910 | if (info->fpmem_p) |
3911 | fprintf (stderr, "\tfpmem_p = %5d\n", info->fpmem_p); | |
3912 | ||
4697a36c MM |
3913 | if (info->gp_save_offset) |
3914 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
3915 | ||
3916 | if (info->fp_save_offset) | |
3917 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
3918 | ||
3919 | if (info->lr_save_offset) | |
3920 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
3921 | ||
3922 | if (info->cr_save_offset) | |
3923 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
3924 | ||
b6c9286a MM |
3925 | if (info->toc_save_offset) |
3926 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
3927 | ||
4697a36c MM |
3928 | if (info->varargs_save_offset) |
3929 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
3930 | ||
b6c9286a MM |
3931 | if (info->main_save_offset) |
3932 | fprintf (stderr, "\tmain_save_offset = %5d\n", info->main_save_offset); | |
3933 | ||
802a0058 MM |
3934 | if (info->fpmem_offset) |
3935 | fprintf (stderr, "\tfpmem_offset = %5d\n", info->fpmem_offset); | |
3936 | ||
4697a36c MM |
3937 | if (info->total_size) |
3938 | fprintf (stderr, "\ttotal_size = %5d\n", info->total_size); | |
3939 | ||
3940 | if (info->varargs_size) | |
3941 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
3942 | ||
3943 | if (info->vars_size) | |
3944 | fprintf (stderr, "\tvars_size = %5d\n", info->vars_size); | |
3945 | ||
3946 | if (info->parm_size) | |
3947 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
3948 | ||
802a0058 MM |
3949 | if (info->fpmem_size) |
3950 | fprintf (stderr, "\tfpmem_size = %5d\n", info->fpmem_size); | |
3951 | ||
4697a36c MM |
3952 | if (info->fixed_size) |
3953 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
3954 | ||
3955 | if (info->gp_size) | |
3956 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
3957 | ||
3958 | if (info->fp_size) | |
3959 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
3960 | ||
b6c9286a MM |
3961 | if (info->lr_size) |
3962 | fprintf (stderr, "\tlr_size = %5d\n", info->cr_size); | |
3963 | ||
4697a36c MM |
3964 | if (info->cr_size) |
3965 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
3966 | ||
b6c9286a MM |
3967 | if (info->toc_size) |
3968 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); | |
3969 | ||
3970 | if (info->main_size) | |
3971 | fprintf (stderr, "\tmain_size = %5d\n", info->main_size); | |
3972 | ||
4697a36c MM |
3973 | if (info->save_size) |
3974 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
3975 | ||
3976 | if (info->reg_size != 4) | |
3977 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
3978 | ||
3979 | fprintf (stderr, "\n"); | |
9878760c | 3980 | } |
4697a36c | 3981 | \f |
c7ca610e RK |
3982 | /* Write out an instruction to load the TOC_TABLE address into register 30. |
3983 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is | |
3984 | a constant pool. */ | |
3985 | ||
3986 | void | |
38c1f2d7 | 3987 | rs6000_output_load_toc_table (file, reg) |
c7ca610e | 3988 | FILE *file; |
38c1f2d7 | 3989 | int reg; |
c7ca610e RK |
3990 | { |
3991 | char buf[256]; | |
3992 | ||
3993 | #ifdef USING_SVR4_H | |
3994 | if (TARGET_RELOCATABLE) | |
3995 | { | |
3996 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
3997 | fprintf (file, "\tbl "); | |
3998 | assemble_name (file, buf); | |
3999 | fprintf (file, "\n"); | |
4000 | ||
38c1f2d7 MM |
4001 | /* possibly create the toc section */ |
4002 | if (!toc_initialized) | |
4003 | { | |
4004 | toc_section (); | |
4005 | function_section (current_function_decl); | |
4006 | } | |
4007 | ||
4008 | /* If not first call in this function, we need to put the | |
4009 | different between .LCTOC1 and the address we get to right | |
4010 | after the bl. It will mess up disassembling the instructions | |
4011 | but that can't be helped. We will later need to bias the | |
4012 | address before loading. */ | |
4013 | if (rs6000_pic_func_labelno != rs6000_pic_labelno) | |
4014 | { | |
d330fd93 | 4015 | const char *init_ptr = TARGET_32BIT ? ".long" : ".quad"; |
ec940faa | 4016 | const char *buf_ptr; |
38c1f2d7 MM |
4017 | |
4018 | ASM_OUTPUT_INTERNAL_LABEL (file, "LCL", rs6000_pic_labelno); | |
4019 | ||
4020 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
4021 | STRIP_NAME_ENCODING (buf_ptr, buf); | |
4022 | fprintf (file, "\t%s %s-", init_ptr, buf_ptr); | |
4023 | ||
4024 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
4025 | fprintf (file, "%s\n", buf_ptr); | |
4026 | } | |
4027 | ||
c7ca610e | 4028 | ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno); |
38c1f2d7 MM |
4029 | fprintf (file, "\tmflr %s\n", reg_names[reg]); |
4030 | ||
4031 | if (rs6000_pic_func_labelno != rs6000_pic_labelno) | |
a260abc9 DE |
4032 | asm_fprintf(file, "\t{cal|la} %s,%d(%s)\n", reg_names[reg], |
4033 | (TARGET_32BIT ? 4 : 8), reg_names[reg]); | |
c7ca610e | 4034 | |
a260abc9 DE |
4035 | asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s,(" : "\tld %s,(", |
4036 | reg_names[0]); | |
38c1f2d7 | 4037 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
c7ca610e | 4038 | assemble_name (file, buf); |
949ea356 | 4039 | putc ('-', file); |
c7ca610e RK |
4040 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); |
4041 | assemble_name (file, buf); | |
38c1f2d7 | 4042 | fprintf (file, ")(%s)\n", reg_names[reg]); |
c7ca610e | 4043 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", |
38c1f2d7 | 4044 | reg_names[reg], reg_names[0], reg_names[reg]); |
c7ca610e RK |
4045 | rs6000_pic_labelno++; |
4046 | } | |
9615f239 | 4047 | else if (! TARGET_64BIT) |
c7ca610e RK |
4048 | { |
4049 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
a260abc9 | 4050 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[reg]); |
c7ca610e | 4051 | assemble_name (file, buf); |
dfdfa60f | 4052 | fputs ("@ha\n", file); |
a260abc9 DE |
4053 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[reg]); |
4054 | assemble_name (file, buf); | |
4055 | asm_fprintf (file, "@l(%s)\n", reg_names[reg]); | |
c7ca610e RK |
4056 | } |
4057 | else | |
4058 | abort (); | |
4059 | ||
4060 | #else /* !USING_SVR4_H */ | |
4061 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0); | |
13ded975 DE |
4062 | asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,", |
4063 | reg_names[reg]); | |
c7ca610e RK |
4064 | assemble_name (file, buf); |
4065 | asm_fprintf (file, "(%s)\n", reg_names[2]); | |
4066 | #endif /* USING_SVR4_H */ | |
4067 | } | |
4068 | ||
38c1f2d7 MM |
4069 | \f |
4070 | /* Emit the correct code for allocating stack space. If COPY_R12, make sure a copy | |
4071 | of the old frame is left in r12. */ | |
4072 | ||
4073 | void | |
4074 | rs6000_allocate_stack_space (file, size, copy_r12) | |
4075 | FILE *file; | |
4076 | int size; | |
4077 | int copy_r12; | |
4078 | { | |
4079 | int neg_size = -size; | |
4080 | if (TARGET_UPDATE) | |
4081 | { | |
4082 | if (size < 32767) | |
4083 | asm_fprintf (file, | |
4084 | (TARGET_32BIT) ? "\t{stu|stwu} %s,%d(%s)\n" : "\tstdu %s,%d(%s)\n", | |
4085 | reg_names[1], neg_size, reg_names[1]); | |
4086 | else | |
4087 | { | |
4088 | if (copy_r12) | |
4089 | fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]); | |
4090 | ||
9615f239 | 4091 | asm_fprintf (file, "\t{liu|lis} %s,0x%x\n\t{oril|ori} %s,%s,%d\n", |
38c1f2d7 MM |
4092 | reg_names[0], (neg_size >> 16) & 0xffff, |
4093 | reg_names[0], reg_names[0], neg_size & 0xffff); | |
4094 | asm_fprintf (file, | |
4095 | (TARGET_32BIT) ? "\t{stux|stwux} %s,%s,%s\n" : "\tstdux %s,%s,%s\n", | |
4096 | reg_names[1], reg_names[1], reg_names[0]); | |
4097 | } | |
4098 | } | |
4099 | else | |
4100 | { | |
4101 | fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]); | |
4102 | if (size < 32767) | |
aa4201ad | 4103 | asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n", |
a260abc9 | 4104 | reg_names[1], neg_size, reg_names[1]); |
38c1f2d7 MM |
4105 | else |
4106 | { | |
9615f239 | 4107 | asm_fprintf (file, "\t{liu|lis} %s,0x%x\n\t{oril|ori} %s,%s,%d\n", |
38c1f2d7 MM |
4108 | reg_names[0], (neg_size >> 16) & 0xffff, |
4109 | reg_names[0], reg_names[0], neg_size & 0xffff); | |
4110 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", reg_names[1], | |
4111 | reg_names[0], reg_names[1]); | |
4112 | } | |
4113 | ||
4114 | asm_fprintf (file, | |
4115 | (TARGET_32BIT) ? "\t{st|stw} %s,0(%s)\n" : "\tstd %s,0(%s)\n", | |
4116 | reg_names[12], reg_names[1]); | |
4117 | } | |
4118 | } | |
4119 | ||
4120 | \f | |
9878760c | 4121 | /* Write function prologue. */ |
9878760c RK |
4122 | void |
4123 | output_prolog (file, size) | |
4124 | FILE *file; | |
296b8152 | 4125 | int size ATTRIBUTE_UNUSED; |
9878760c | 4126 | { |
4697a36c | 4127 | rs6000_stack_t *info = rs6000_stack_info (); |
b6c9286a | 4128 | int reg_size = info->reg_size; |
d330fd93 KG |
4129 | const char *store_reg; |
4130 | const char *load_reg; | |
979721f8 MM |
4131 | int sp_reg = 1; |
4132 | int sp_offset = 0; | |
b6c9286a | 4133 | |
8f802bfb | 4134 | if (TARGET_32BIT) |
b6c9286a | 4135 | { |
8f802bfb DE |
4136 | store_reg = "\t{st|stw} %s,%d(%s)\n"; |
4137 | load_reg = "\t{l|lwz} %s,%d(%s)\n"; | |
b6c9286a MM |
4138 | } |
4139 | else | |
4140 | { | |
8f802bfb DE |
4141 | store_reg = "\tstd %s,%d(%s)\n"; |
4142 | load_reg = "\tlld %s,%d(%s)\n"; | |
b6c9286a | 4143 | } |
9878760c | 4144 | |
4697a36c MM |
4145 | if (TARGET_DEBUG_STACK) |
4146 | debug_stack_info (info); | |
9878760c RK |
4147 | |
4148 | /* Write .extern for any function we will call to save and restore fp | |
4149 | values. */ | |
b6c9286a | 4150 | if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save)) |
4d30c363 | 4151 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c MM |
4152 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
4153 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
9878760c RK |
4154 | |
4155 | /* Write .extern for truncation routines, if needed. */ | |
4156 | if (rs6000_trunc_used && ! trunc_defined) | |
4157 | { | |
e138174b ILT |
4158 | fprintf (file, "\t.extern .%s\n\t.extern .%s\n", |
4159 | RS6000_ITRUNC, RS6000_UITRUNC); | |
9878760c RK |
4160 | trunc_defined = 1; |
4161 | } | |
4697a36c | 4162 | |
c764f757 RK |
4163 | /* Write .extern for AIX common mode routines, if needed. */ |
4164 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
4165 | { | |
f6709c70 JW |
4166 | fputs ("\t.extern __mulh\n", file); |
4167 | fputs ("\t.extern __mull\n", file); | |
4168 | fputs ("\t.extern __divss\n", file); | |
4169 | fputs ("\t.extern __divus\n", file); | |
4170 | fputs ("\t.extern __quoss\n", file); | |
4171 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
4172 | common_mode_defined = 1; |
4173 | } | |
9878760c | 4174 | |
979721f8 | 4175 | /* For V.4, update stack before we do any saving and set back pointer. */ |
c81bebd7 | 4176 | if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)) |
979721f8 MM |
4177 | { |
4178 | if (info->total_size < 32767) | |
38c1f2d7 | 4179 | sp_offset = info->total_size; |
979721f8 | 4180 | else |
38c1f2d7 MM |
4181 | sp_reg = 12; |
4182 | rs6000_allocate_stack_space (file, info->total_size, sp_reg == 12); | |
979721f8 MM |
4183 | } |
4184 | ||
9878760c | 4185 | /* If we use the link register, get it into r0. */ |
4697a36c MM |
4186 | if (info->lr_save_p) |
4187 | asm_fprintf (file, "\tmflr %s\n", reg_names[0]); | |
9878760c RK |
4188 | |
4189 | /* If we need to save CR, put it into r12. */ | |
979721f8 | 4190 | if (info->cr_save_p && sp_reg != 12) |
4697a36c | 4191 | asm_fprintf (file, "\tmfcr %s\n", reg_names[12]); |
9878760c RK |
4192 | |
4193 | /* Do any required saving of fpr's. If only one or two to save, do it | |
53322b0c RK |
4194 | ourself. Otherwise, call function. Note that since they are statically |
4195 | linked, we do not need a nop following them. */ | |
4697a36c | 4196 | if (FP_SAVE_INLINE (info->first_fp_reg_save)) |
bacbde18 | 4197 | { |
4697a36c | 4198 | int regno = info->first_fp_reg_save; |
979721f8 | 4199 | int loc = info->fp_save_offset + sp_offset; |
4697a36c MM |
4200 | |
4201 | for ( ; regno < 64; regno++, loc += 8) | |
979721f8 | 4202 | asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]); |
bacbde18 | 4203 | } |
4697a36c MM |
4204 | else if (info->first_fp_reg_save != 64) |
4205 | asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX, | |
4206 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
9878760c RK |
4207 | |
4208 | /* Now save gpr's. */ | |
4697a36c | 4209 | if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT) |
85638c0d | 4210 | { |
4697a36c | 4211 | int regno = info->first_gp_reg_save; |
979721f8 | 4212 | int loc = info->gp_save_offset + sp_offset; |
85638c0d | 4213 | |
4697a36c | 4214 | for ( ; regno < 32; regno++, loc += reg_size) |
979721f8 | 4215 | asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]); |
85638c0d RK |
4216 | } |
4217 | ||
4697a36c MM |
4218 | else if (info->first_gp_reg_save != 32) |
4219 | asm_fprintf (file, "\t{stm|stmw} %s,%d(%s)\n", | |
4220 | reg_names[info->first_gp_reg_save], | |
979721f8 MM |
4221 | info->gp_save_offset + sp_offset, |
4222 | reg_names[sp_reg]); | |
9878760c | 4223 | |
b6c9286a MM |
4224 | /* Save main's arguments if we need to call a function */ |
4225 | #ifdef NAME__MAIN | |
4226 | if (info->main_save_p) | |
4227 | { | |
4228 | int regno; | |
5ebfb2ba | 4229 | int loc = info->main_save_offset + sp_offset; |
b6c9286a MM |
4230 | int size = info->main_size; |
4231 | ||
2682eae9 | 4232 | for (regno = 3; size > 0; regno++, loc += reg_size, size -= reg_size) |
979721f8 | 4233 | asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]); |
b6c9286a MM |
4234 | } |
4235 | #endif | |
4236 | ||
9878760c | 4237 | /* Save lr if we used it. */ |
4697a36c | 4238 | if (info->lr_save_p) |
979721f8 MM |
4239 | asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset + sp_offset, |
4240 | reg_names[sp_reg]); | |
9878760c RK |
4241 | |
4242 | /* Save CR if we use any that must be preserved. */ | |
4697a36c | 4243 | if (info->cr_save_p) |
979721f8 MM |
4244 | { |
4245 | if (sp_reg == 12) /* If r12 is used to hold the original sp, copy cr now */ | |
4246 | { | |
4247 | asm_fprintf (file, "\tmfcr %s\n", reg_names[0]); | |
4248 | asm_fprintf (file, store_reg, reg_names[0], | |
4249 | info->cr_save_offset + sp_offset, | |
4250 | reg_names[sp_reg]); | |
4251 | } | |
4252 | else | |
4253 | asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset + sp_offset, | |
4254 | reg_names[sp_reg]); | |
4255 | } | |
9878760c | 4256 | |
8d30c4ee FS |
4257 | /* If we need PIC_OFFSET_TABLE_REGNUM, initialize it now */ |
4258 | if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
4259 | && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) | |
4260 | { | |
4261 | if (!info->lr_save_p) | |
4262 | asm_fprintf (file, "\tmflr %s\n", reg_names[0]); | |
4263 | ||
4264 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); | |
4265 | asm_fprintf (file, "\tmflr %s\n", reg_names[PIC_OFFSET_TABLE_REGNUM]); | |
4266 | ||
4267 | if (!info->lr_save_p) | |
4268 | asm_fprintf (file, "\tmtlr %s\n", reg_names[0]); | |
4269 | } | |
4270 | ||
979721f8 MM |
4271 | /* NT needs us to probe the stack frame every 4k pages for large frames, so |
4272 | do it here. */ | |
4273 | if (DEFAULT_ABI == ABI_NT && info->total_size > 4096) | |
4274 | { | |
4275 | if (info->total_size < 32768) | |
4276 | { | |
4277 | int probe_offset = 4096; | |
4278 | while (probe_offset < info->total_size) | |
4279 | { | |
4280 | asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n", reg_names[0], -probe_offset, reg_names[1]); | |
4281 | probe_offset += 4096; | |
4282 | } | |
4283 | } | |
4284 | else | |
4285 | { | |
4286 | int probe_iterations = info->total_size / 4096; | |
4287 | static int probe_labelno = 0; | |
4288 | char buf[256]; | |
4289 | ||
4290 | if (probe_iterations < 32768) | |
4291 | asm_fprintf (file, "\tli %s,%d\n", reg_names[12], probe_iterations); | |
4292 | else | |
4293 | { | |
4294 | asm_fprintf (file, "\tlis %s,%d\n", reg_names[12], probe_iterations >> 16); | |
4295 | if (probe_iterations & 0xffff) | |
4296 | asm_fprintf (file, "\tori %s,%s,%d\n", reg_names[12], reg_names[12], | |
4297 | probe_iterations & 0xffff); | |
4298 | } | |
4299 | asm_fprintf (file, "\tmtctr %s\n", reg_names[12]); | |
4300 | asm_fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]); | |
4301 | ASM_OUTPUT_INTERNAL_LABEL (file, "LCprobe", probe_labelno); | |
4302 | asm_fprintf (file, "\t{lu|lwzu} %s,-4096(%s)\n", reg_names[0], reg_names[12]); | |
2a50d6bc | 4303 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCprobe", probe_labelno++); |
979721f8 MM |
4304 | fputs ("\tbdnz ", file); |
4305 | assemble_name (file, buf); | |
949ea356 | 4306 | putc ('\n', file); |
979721f8 MM |
4307 | } |
4308 | } | |
4309 | ||
38c1f2d7 | 4310 | /* Update stack and set back pointer unless this is V.4, which was done previously */ |
c81bebd7 | 4311 | if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS) |
38c1f2d7 | 4312 | rs6000_allocate_stack_space (file, info->total_size, FALSE); |
9878760c RK |
4313 | |
4314 | /* Set frame pointer, if needed. */ | |
4315 | if (frame_pointer_needed) | |
4697a36c | 4316 | asm_fprintf (file, "\tmr %s,%s\n", reg_names[31], reg_names[1]); |
1875cc88 | 4317 | |
b6c9286a MM |
4318 | #ifdef NAME__MAIN |
4319 | /* If we need to call a function to set things up for main, do so now | |
4320 | before dealing with the TOC. */ | |
4321 | if (info->main_p) | |
4322 | { | |
d330fd93 | 4323 | const char *prefix = ""; |
b6c9286a MM |
4324 | |
4325 | switch (DEFAULT_ABI) | |
4326 | { | |
4327 | case ABI_AIX: prefix = "."; break; | |
4328 | case ABI_NT: prefix = ".."; break; | |
4329 | } | |
4330 | ||
4331 | fprintf (file, "\tbl %s%s\n", prefix, NAME__MAIN); | |
4332 | #ifdef RS6000_CALL_GLUE2 | |
4333 | fprintf (file, "\t%s%s%s\n", RS6000_CALL_GLUE2, prefix, NAME_MAIN); | |
4334 | #else | |
4335 | #ifdef RS6000_CALL_GLUE | |
4336 | if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT) | |
13f1623b DE |
4337 | { |
4338 | putc('\t', file); | |
4339 | asm_fprintf (file, RS6000_CALL_GLUE); | |
4340 | putc('\n', file); | |
4341 | } | |
b6c9286a MM |
4342 | #endif |
4343 | #endif | |
4344 | ||
4345 | if (info->main_save_p) | |
4346 | { | |
4347 | int regno; | |
4348 | int loc; | |
4349 | int size = info->main_size; | |
4350 | ||
4351 | if (info->total_size < 32767) | |
4352 | { | |
4353 | loc = info->total_size + info->main_save_offset; | |
2682eae9 | 4354 | for (regno = 3; size > 0; regno++, size -= reg_size, loc += reg_size) |
b6c9286a MM |
4355 | asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]); |
4356 | } | |
4357 | else | |
5ebfb2ba MM |
4358 | { |
4359 | int neg_size = info->main_save_offset - info->total_size; | |
4360 | loc = 0; | |
9615f239 | 4361 | asm_fprintf (file, "\t{liu|lis} %s,0x%x\n\t{oril|ori} %s,%s,%d\n", |
5ebfb2ba MM |
4362 | reg_names[0], (neg_size >> 16) & 0xffff, |
4363 | reg_names[0], reg_names[0], neg_size & 0xffff); | |
979721f8 | 4364 | |
b6c9286a MM |
4365 | asm_fprintf (file, "\t{sf|subf} %s,%s,%s\n", reg_names[0], reg_names[0], |
4366 | reg_names[1]); | |
4367 | ||
2682eae9 | 4368 | for (regno = 3; size > 0; regno++, size -= reg_size, loc += reg_size) |
b6c9286a MM |
4369 | asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[0]); |
4370 | } | |
4371 | } | |
4372 | } | |
4373 | #endif | |
4374 | ||
4375 | ||
1875cc88 JW |
4376 | /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the |
4377 | TOC_TABLE address into register 30. */ | |
4697a36c | 4378 | if (TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) |
ab9eef41 MM |
4379 | { |
4380 | #ifdef USING_SVR4_H | |
38c1f2d7 MM |
4381 | if (!profile_flag) |
4382 | rs6000_pic_func_labelno = rs6000_pic_labelno; | |
ab9eef41 | 4383 | #endif |
38c1f2d7 | 4384 | rs6000_output_load_toc_table (file, 30); |
ab9eef41 | 4385 | } |
4697a36c | 4386 | |
b6c9286a MM |
4387 | if (DEFAULT_ABI == ABI_NT) |
4388 | { | |
4389 | assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); | |
4390 | fputs (".b:\n", file); | |
3daf36a4 | 4391 | } |
9878760c RK |
4392 | } |
4393 | ||
4394 | /* Write function epilogue. */ | |
4395 | ||
4396 | void | |
4397 | output_epilog (file, size) | |
4398 | FILE *file; | |
296b8152 | 4399 | int size ATTRIBUTE_UNUSED; |
9878760c | 4400 | { |
4697a36c | 4401 | rs6000_stack_t *info = rs6000_stack_info (); |
d330fd93 | 4402 | const char *load_reg = (TARGET_32BIT) ? "\t{l|lwz} %s,%d(%s)\n" : "\tld %s,%d(%s)\n"; |
9878760c | 4403 | rtx insn = get_last_insn (); |
979721f8 MM |
4404 | int sp_reg = 1; |
4405 | int sp_offset = 0; | |
9878760c | 4406 | |
9878760c RK |
4407 | /* If the last insn was a BARRIER, we don't have to write anything except |
4408 | the trace table. */ | |
4409 | if (GET_CODE (insn) == NOTE) | |
4410 | insn = prev_nonnote_insn (insn); | |
4411 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4412 | { | |
4413 | /* If we have a frame pointer, a call to alloca, or a large stack | |
4414 | frame, restore the old stack pointer using the backchain. Otherwise, | |
4415 | we know what size to update it with. */ | |
4416 | if (frame_pointer_needed || current_function_calls_alloca | |
4697a36c | 4417 | || info->total_size > 32767) |
979721f8 MM |
4418 | { |
4419 | /* Under V.4, don't reset the stack pointer until after we're done | |
4420 | loading the saved registers. */ | |
c81bebd7 | 4421 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
979721f8 MM |
4422 | sp_reg = 11; |
4423 | ||
4424 | asm_fprintf (file, load_reg, reg_names[sp_reg], 0, reg_names[1]); | |
4425 | } | |
4697a36c MM |
4426 | else if (info->push_p) |
4427 | { | |
c81bebd7 | 4428 | if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) |
979721f8 | 4429 | sp_offset = info->total_size; |
4697a36c | 4430 | else |
a260abc9 DE |
4431 | asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n", |
4432 | reg_names[1], info->total_size, reg_names[1]); | |
4697a36c | 4433 | } |
9878760c | 4434 | |
b4ac57ab | 4435 | /* Get the old lr if we saved it. */ |
4697a36c | 4436 | if (info->lr_save_p) |
979721f8 | 4437 | asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset + sp_offset, reg_names[sp_reg]); |
9878760c RK |
4438 | |
4439 | /* Get the old cr if we saved it. */ | |
4697a36c | 4440 | if (info->cr_save_p) |
979721f8 | 4441 | asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset + sp_offset, reg_names[sp_reg]); |
9878760c | 4442 | |
b4ac57ab | 4443 | /* Set LR here to try to overlap restores below. */ |
4697a36c MM |
4444 | if (info->lr_save_p) |
4445 | asm_fprintf (file, "\tmtlr %s\n", reg_names[0]); | |
b4ac57ab | 4446 | |
9878760c | 4447 | /* Restore gpr's. */ |
4697a36c | 4448 | if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT) |
85638c0d | 4449 | { |
4697a36c | 4450 | int regno = info->first_gp_reg_save; |
979721f8 | 4451 | int loc = info->gp_save_offset + sp_offset; |
8f802bfb | 4452 | int reg_size = (TARGET_32BIT) ? 4 : 8; |
85638c0d | 4453 | |
4697a36c | 4454 | for ( ; regno < 32; regno++, loc += reg_size) |
979721f8 | 4455 | asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[sp_reg]); |
85638c0d RK |
4456 | } |
4457 | ||
4697a36c MM |
4458 | else if (info->first_gp_reg_save != 32) |
4459 | asm_fprintf (file, "\t{lm|lmw} %s,%d(%s)\n", | |
4460 | reg_names[info->first_gp_reg_save], | |
979721f8 MM |
4461 | info->gp_save_offset + sp_offset, |
4462 | reg_names[sp_reg]); | |
9878760c | 4463 | |
b4ac57ab | 4464 | /* Restore fpr's if we can do it without calling a function. */ |
4697a36c MM |
4465 | if (FP_SAVE_INLINE (info->first_fp_reg_save)) |
4466 | { | |
4467 | int regno = info->first_fp_reg_save; | |
979721f8 | 4468 | int loc = info->fp_save_offset + sp_offset; |
4697a36c MM |
4469 | |
4470 | for ( ; regno < 64; regno++, loc += 8) | |
979721f8 | 4471 | asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]); |
4697a36c | 4472 | } |
9878760c | 4473 | |
28edebac RK |
4474 | /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4 |
4475 | that were used. */ | |
4697a36c MM |
4476 | if (info->cr_save_p) |
4477 | asm_fprintf (file, "\tmtcrf %d,%s\n", | |
85638c0d RK |
4478 | (regs_ever_live[70] != 0) * 0x20 |
4479 | + (regs_ever_live[71] != 0) * 0x10 | |
4697a36c | 4480 | + (regs_ever_live[72] != 0) * 0x8, reg_names[12]); |
9878760c | 4481 | |
a6c2a102 DE |
4482 | /* If this is V.4, unwind the stack pointer after all of the loads |
4483 | have been done */ | |
4484 | if (sp_offset != 0) | |
a260abc9 DE |
4485 | asm_fprintf (file, "\t{cal|la} %s,%d(%s)\n", |
4486 | reg_names[1], sp_offset, reg_names[1]); | |
979721f8 MM |
4487 | else if (sp_reg != 1) |
4488 | asm_fprintf (file, "\tmr %s,%s\n", reg_names[1], reg_names[sp_reg]); | |
4489 | ||
b4ac57ab RS |
4490 | /* If we have to restore more than two FP registers, branch to the |
4491 | restore function. It will return to our caller. */ | |
4697a36c MM |
4492 | if (info->first_fp_reg_save != 64 && !FP_SAVE_INLINE (info->first_fp_reg_save)) |
4493 | asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX, | |
4494 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
b4ac57ab | 4495 | else |
85638c0d | 4496 | asm_fprintf (file, "\t{br|blr}\n"); |
9878760c | 4497 | } |
b4ac57ab | 4498 | |
9b30bae2 | 4499 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
4500 | on its format. |
4501 | ||
4502 | We don't output a traceback table if -finhibit-size-directive was | |
4503 | used. The documentation for -finhibit-size-directive reads | |
4504 | ``don't output a @code{.size} assembler directive, or anything | |
4505 | else that would cause trouble if the function is split in the | |
4506 | middle, and the two halves are placed at locations far apart in | |
4507 | memory.'' The traceback table has this property, since it | |
4508 | includes the offset from the start of the function to the | |
4d30c363 MM |
4509 | traceback table itself. |
4510 | ||
4511 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a MM |
4512 | different traceback table. */ |
4513 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive) | |
9b30bae2 | 4514 | { |
314fc5a9 ILT |
4515 | char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); |
4516 | int fixed_parms, float_parms, parm_info; | |
4517 | int i; | |
4518 | ||
b6c9286a MM |
4519 | while (*fname == '.') /* V.4 encodes . in the name */ |
4520 | fname++; | |
4521 | ||
314fc5a9 ILT |
4522 | /* Need label immediately before tbtab, so we can compute its offset |
4523 | from the function start. */ | |
4524 | if (*fname == '*') | |
4525 | ++fname; | |
4526 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
4527 | ASM_OUTPUT_LABEL (file, fname); | |
4528 | ||
4529 | /* The .tbtab pseudo-op can only be used for the first eight | |
4530 | expressions, since it can't handle the possibly variable | |
4531 | length fields that follow. However, if you omit the optional | |
4532 | fields, the assembler outputs zeros for all optional fields | |
4533 | anyways, giving each variable length field is minimum length | |
4534 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
4535 | pseudo-op at all. */ | |
4536 | ||
4537 | /* An all-zero word flags the start of the tbtab, for debuggers | |
4538 | that have to find it by searching forward from the entry | |
4539 | point or from the current pc. */ | |
19d2d16f | 4540 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
4541 | |
4542 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 4543 | fputs ("\t.byte 0,", file); |
314fc5a9 ILT |
4544 | |
4545 | /* Language type. Unfortunately, there doesn't seem to be any | |
4546 | official way to get this info, so we use language_string. C | |
4547 | is 0. C++ is 9. No number defined for Obj-C, so use the | |
9517ead8 | 4548 | value for C for now. There is no official value for Java, |
6f573ff9 JL |
4549 | although IBM appears to be using 13. There is no official value |
4550 | for Chill, so we've choosen 44 pseudo-randomly. */ | |
314fc5a9 ILT |
4551 | if (! strcmp (language_string, "GNU C") |
4552 | || ! strcmp (language_string, "GNU Obj-C")) | |
4553 | i = 0; | |
4554 | else if (! strcmp (language_string, "GNU F77")) | |
4555 | i = 1; | |
4556 | else if (! strcmp (language_string, "GNU Ada")) | |
4557 | i = 3; | |
8b83775b | 4558 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 ILT |
4559 | i = 2; |
4560 | else if (! strcmp (language_string, "GNU C++")) | |
4561 | i = 9; | |
9517ead8 AG |
4562 | else if (! strcmp (language_string, "GNU Java")) |
4563 | i = 13; | |
6f573ff9 JL |
4564 | else if (! strcmp (language_string, "GNU CHILL")) |
4565 | i = 44; | |
314fc5a9 ILT |
4566 | else |
4567 | abort (); | |
4568 | fprintf (file, "%d,", i); | |
4569 | ||
4570 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
4571 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
4572 | from start of procedure stored in tbtab, internal function, function | |
4573 | has controlled storage, function has no toc, function uses fp, | |
4574 | function logs/aborts fp operations. */ | |
4575 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
4697a36c | 4576 | fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1)); |
314fc5a9 ILT |
4577 | |
4578 | /* 6 bitfields: function is interrupt handler, name present in | |
4579 | proc table, function calls alloca, on condition directives | |
4580 | (controls stack walks, 3 bits), saves condition reg, saves | |
4581 | link reg. */ | |
4582 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
4583 | set up as a frame pointer, even when there is no alloca call. */ | |
4584 | fprintf (file, "%d,", | |
4585 | ((1 << 6) | (frame_pointer_needed << 5) | |
4697a36c | 4586 | | (info->cr_save_p << 1) | (info->lr_save_p))); |
314fc5a9 ILT |
4587 | |
4588 | /* 3 bitfields: saves backchain, spare bit, number of fpr saved | |
4589 | (6 bits). */ | |
4590 | fprintf (file, "%d,", | |
4697a36c | 4591 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
4592 | |
4593 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
4594 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
4595 | ||
4596 | { | |
4597 | /* Compute the parameter info from the function decl argument | |
4598 | list. */ | |
4599 | tree decl; | |
4600 | int next_parm_info_bit; | |
4601 | ||
4602 | next_parm_info_bit = 31; | |
4603 | parm_info = 0; | |
4604 | fixed_parms = 0; | |
4605 | float_parms = 0; | |
4606 | ||
4607 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
4608 | decl; decl = TREE_CHAIN (decl)) | |
4609 | { | |
4610 | rtx parameter = DECL_INCOMING_RTL (decl); | |
4611 | enum machine_mode mode = GET_MODE (parameter); | |
4612 | ||
4613 | if (GET_CODE (parameter) == REG) | |
4614 | { | |
4615 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
4616 | { | |
4617 | int bits; | |
4618 | ||
4619 | float_parms++; | |
4620 | ||
4621 | if (mode == SFmode) | |
4622 | bits = 0x2; | |
4623 | else if (mode == DFmode) | |
4624 | bits = 0x3; | |
4625 | else | |
4626 | abort (); | |
4627 | ||
4628 | /* If only one bit will fit, don't or in this entry. */ | |
4629 | if (next_parm_info_bit > 0) | |
4630 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
4631 | next_parm_info_bit -= 2; | |
4632 | } | |
4633 | else | |
4634 | { | |
4635 | fixed_parms += ((GET_MODE_SIZE (mode) | |
4636 | + (UNITS_PER_WORD - 1)) | |
4637 | / UNITS_PER_WORD); | |
4638 | next_parm_info_bit -= 1; | |
4639 | } | |
4640 | } | |
4641 | } | |
4642 | } | |
4643 | ||
4644 | /* Number of fixed point parameters. */ | |
4645 | /* This is actually the number of words of fixed point parameters; thus | |
4646 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
4647 | fprintf (file, "%d,", fixed_parms); | |
4648 | ||
4649 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
4650 | all on stack. */ | |
4651 | /* This is actually the number of fp registers that hold parameters; | |
4652 | and thus the maximum value is 13. */ | |
4653 | /* Set parameters on stack bit if parameters are not in their original | |
4654 | registers, regardless of whether they are on the stack? Xlc | |
4655 | seems to set the bit when not optimizing. */ | |
4656 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
4657 | ||
4658 | /* Optional fields follow. Some are variable length. */ | |
4659 | ||
4660 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
4661 | 11 double float. */ | |
4662 | /* There is an entry for each parameter in a register, in the order that | |
4663 | they occur in the parameter list. Any intervening arguments on the | |
4664 | stack are ignored. If the list overflows a long (max possible length | |
4665 | 34 bits) then completely leave off all elements that don't fit. */ | |
4666 | /* Only emit this long if there was at least one parameter. */ | |
4667 | if (fixed_parms || float_parms) | |
4668 | fprintf (file, "\t.long %d\n", parm_info); | |
4669 | ||
4670 | /* Offset from start of code to tb table. */ | |
19d2d16f | 4671 | fputs ("\t.long ", file); |
314fc5a9 ILT |
4672 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
4673 | RS6000_OUTPUT_BASENAME (file, fname); | |
19d2d16f | 4674 | fputs ("-.", file); |
314fc5a9 | 4675 | RS6000_OUTPUT_BASENAME (file, fname); |
19d2d16f | 4676 | putc ('\n', file); |
314fc5a9 ILT |
4677 | |
4678 | /* Interrupt handler mask. */ | |
4679 | /* Omit this long, since we never set the interrupt handler bit | |
4680 | above. */ | |
4681 | ||
4682 | /* Number of CTL (controlled storage) anchors. */ | |
4683 | /* Omit this long, since the has_ctl bit is never set above. */ | |
4684 | ||
4685 | /* Displacement into stack of each CTL anchor. */ | |
4686 | /* Omit this list of longs, because there are no CTL anchors. */ | |
4687 | ||
4688 | /* Length of function name. */ | |
296b8152 | 4689 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
4690 | |
4691 | /* Function name. */ | |
4692 | assemble_string (fname, strlen (fname)); | |
4693 | ||
4694 | /* Register for alloca automatic storage; this is always reg 31. | |
4695 | Only emit this if the alloca bit was set above. */ | |
4696 | if (frame_pointer_needed) | |
19d2d16f | 4697 | fputs ("\t.byte 31\n", file); |
9b30bae2 | 4698 | } |
4697a36c | 4699 | |
b6c9286a MM |
4700 | if (DEFAULT_ABI == ABI_NT) |
4701 | { | |
4702 | RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); | |
4703 | fputs (".e:\nFE_MOT_RESVD..", file); | |
4704 | RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); | |
4705 | fputs (":\n", file); | |
4706 | } | |
9878760c | 4707 | } |
17167fd8 MM |
4708 | \f |
4709 | /* A C compound statement that outputs the assembler code for a thunk function, | |
4710 | used to implement C++ virtual function calls with multiple inheritance. The | |
4711 | thunk acts as a wrapper around a virtual function, adjusting the implicit | |
4712 | object parameter before handing control off to the real function. | |
4713 | ||
4714 | First, emit code to add the integer DELTA to the location that contains the | |
4715 | incoming first argument. Assume that this argument contains a pointer, and | |
4716 | is the one used to pass the `this' pointer in C++. This is the incoming | |
4717 | argument *before* the function prologue, e.g. `%o0' on a sparc. The | |
4718 | addition must preserve the values of all other incoming arguments. | |
4719 | ||
4720 | After the addition, emit code to jump to FUNCTION, which is a | |
4721 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch | |
4722 | the return address. Hence returning from FUNCTION will return to whoever | |
4723 | called the current `thunk'. | |
4724 | ||
4725 | The effect must be as if FUNCTION had been called directly with the adjusted | |
4726 | first argument. This macro is responsible for emitting all of the code for | |
4727 | a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not | |
4728 | invoked. | |
4729 | ||
4730 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been | |
4731 | extracted from it.) It might possibly be useful on some targets, but | |
4732 | probably not. | |
4733 | ||
4734 | If you do not define this macro, the target-independent code in the C++ | |
4735 | frontend will generate a less efficient heavyweight thunk that calls | |
4736 | FUNCTION instead of jumping to it. The generic approach does not support | |
4737 | varargs. */ | |
4738 | ||
4739 | void | |
4740 | output_mi_thunk (file, thunk_fndecl, delta, function) | |
4741 | FILE *file; | |
d330fd93 | 4742 | tree thunk_fndecl ATTRIBUTE_UNUSED; |
17167fd8 MM |
4743 | int delta; |
4744 | tree function; | |
4745 | { | |
d330fd93 KG |
4746 | const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ]; |
4747 | const char *prefix; | |
17167fd8 | 4748 | char *fname; |
d330fd93 KG |
4749 | const char *r0 = reg_names[0]; |
4750 | const char *sp = reg_names[1]; | |
4751 | const char *toc = reg_names[2]; | |
4752 | const char *schain = reg_names[11]; | |
4753 | const char *r12 = reg_names[12]; | |
17167fd8 MM |
4754 | char buf[512]; |
4755 | static int labelno = 0; | |
4756 | ||
4757 | /* Small constants that can be done by one add instruction */ | |
4758 | if (delta >= -32768 && delta <= 32767) | |
4759 | { | |
22b4a3b0 | 4760 | if (! TARGET_NEW_MNEMONICS) |
17167fd8 MM |
4761 | fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg); |
4762 | else | |
4763 | fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta); | |
4764 | } | |
4765 | ||
4766 | /* Large constants that can be done by one addis instruction */ | |
4767 | else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1) | |
4768 | asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg, | |
4769 | delta >> 16); | |
4770 | ||
4771 | /* 32-bit constants that can be done by an add and addis instruction. */ | |
4772 | else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1) | |
4773 | { | |
22b4a3b0 | 4774 | /* Break into two pieces, propagating the sign bit from the low word to |
17167fd8 MM |
4775 | the upper word. */ |
4776 | int delta_high = delta >> 16; | |
4777 | int delta_low = delta & 0xffff; | |
4778 | if ((delta_low & 0x8000) != 0) | |
4779 | { | |
4780 | delta_high++; | |
4781 | delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */ | |
4782 | } | |
4783 | ||
4784 | asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg, | |
4785 | delta_high); | |
4786 | ||
22b4a3b0 | 4787 | if (! TARGET_NEW_MNEMONICS) |
17167fd8 MM |
4788 | fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg); |
4789 | else | |
4790 | fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low); | |
4791 | } | |
4792 | ||
4793 | /* 64-bit constants, fixme */ | |
4794 | else | |
4795 | abort (); | |
4796 | ||
4797 | /* Get the prefix in front of the names. */ | |
4798 | switch (DEFAULT_ABI) | |
4799 | { | |
4800 | default: | |
4801 | abort (); | |
4802 | ||
4803 | case ABI_AIX: | |
4804 | prefix = "."; | |
4805 | break; | |
4806 | ||
4807 | case ABI_V4: | |
4808 | case ABI_AIX_NODESC: | |
4809 | case ABI_SOLARIS: | |
4810 | prefix = ""; | |
4811 | break; | |
4812 | ||
4813 | case ABI_NT: | |
4814 | prefix = ".."; | |
4815 | break; | |
4816 | } | |
4817 | ||
4818 | /* If the function is compiled in this module, jump to it directly. | |
4819 | Otherwise, load up its address and jump to it. */ | |
4820 | ||
4821 | fname = XSTR (XEXP (DECL_RTL (function), 0), 0); | |
42820a49 | 4822 | |
efc97ef0 | 4823 | if (current_file_function_operand (XEXP (DECL_RTL (function), 0)) |
22b4a3b0 FS |
4824 | && ! lookup_attribute ("longcall", |
4825 | TYPE_ATTRIBUTES (TREE_TYPE (function)))) | |
17167fd8 MM |
4826 | { |
4827 | fprintf (file, "\tb %s", prefix); | |
4828 | assemble_name (file, fname); | |
22b4a3b0 | 4829 | if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file); |
949ea356 | 4830 | putc ('\n', file); |
17167fd8 MM |
4831 | } |
4832 | ||
4833 | else | |
4834 | { | |
4835 | switch (DEFAULT_ABI) | |
4836 | { | |
4837 | default: | |
4838 | case ABI_NT: | |
4839 | abort (); | |
4840 | ||
4841 | case ABI_AIX: | |
4842 | /* Set up a TOC entry for the function. */ | |
4843 | ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno); | |
4844 | toc_section (); | |
4845 | ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno); | |
4846 | labelno++; | |
4847 | ||
4848 | /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since | |
4849 | there will be only one TOC entry for this function. */ | |
4850 | fputs ("\t.tc\t", file); | |
4851 | assemble_name (file, buf); | |
4852 | fputs ("[TC],", file); | |
4853 | assemble_name (file, buf); | |
4854 | putc ('\n', file); | |
4855 | text_section (); | |
4856 | asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12); | |
4857 | assemble_name (file, buf); | |
4858 | asm_fprintf (file, "(%s)\n", reg_names[2]); | |
4859 | asm_fprintf (file, | |
4860 | (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n", | |
4861 | r0, r12); | |
4862 | ||
4863 | asm_fprintf (file, | |
4864 | (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n", | |
4865 | toc, r12); | |
4866 | ||
4867 | asm_fprintf (file, "\tmtctr %s\n", r0); | |
4868 | asm_fprintf (file, | |
4869 | (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n", | |
4870 | schain, r12); | |
4871 | ||
4872 | asm_fprintf (file, "\tbctr\n"); | |
4873 | break; | |
4874 | ||
17167fd8 | 4875 | case ABI_V4: |
22b4a3b0 FS |
4876 | fprintf (file, "\tb %s", prefix); |
4877 | assemble_name (file, fname); | |
4878 | if (flag_pic) fputs ("@plt", file); | |
949ea356 | 4879 | putc ('\n', file); |
22b4a3b0 FS |
4880 | break; |
4881 | ||
4882 | /* Don't use r11, that contains the static chain, just use r0/r12. */ | |
17167fd8 MM |
4883 | case ABI_AIX_NODESC: |
4884 | case ABI_SOLARIS: | |
4885 | if (flag_pic == 1) | |
4886 | { | |
4887 | fprintf (file, "\tmflr %s\n", r0); | |
4888 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); | |
4889 | asm_fprintf (file, "\tmflr %s\n", r12); | |
4890 | asm_fprintf (file, "\tmtlr %s\n", r0); | |
4891 | asm_fprintf (file, "\t{l|lwz} %s,", r0); | |
4892 | assemble_name (file, fname); | |
4893 | asm_fprintf (file, "@got(%s)\n", r12); | |
42820a49 MM |
4894 | asm_fprintf (file, "\tmtctr %s\n", r0); |
4895 | asm_fprintf (file, "\tbctr\n"); | |
17167fd8 MM |
4896 | } |
4897 | #if TARGET_ELF | |
4898 | else if (flag_pic > 1 || TARGET_RELOCATABLE) | |
4899 | { | |
4900 | ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno); | |
4901 | labelno++; | |
4902 | fprintf (file, "\tmflr %s\n", r0); | |
4903 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", r0, sp); | |
4904 | rs6000_pic_func_labelno = rs6000_pic_labelno; | |
4905 | rs6000_output_load_toc_table (file, 12); | |
4906 | asm_fprintf (file, "\t{l|lwz} %s,", r0); | |
4907 | assemble_name (file, buf); | |
4908 | asm_fprintf (file, "(%s)\n", r12); | |
4909 | asm_fprintf (file, "\t{l|lwz} %s,4(%s)\n", r12, sp); | |
4910 | asm_fprintf (file, "\tmtlr %s\n", r12); | |
42820a49 MM |
4911 | asm_fprintf (file, "\tmtctr %s\n", r0); |
4912 | asm_fprintf (file, "\tbctr\n"); | |
17167fd8 MM |
4913 | asm_fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); |
4914 | assemble_name (file, buf); | |
4915 | fputs (" = .-.LCTOC1\n", file); | |
4916 | fputs ("\t.long ", file); | |
4917 | assemble_name (file, fname); | |
4918 | fputs ("\n\t.previous\n", file); | |
4919 | } | |
42820a49 MM |
4920 | #endif /* TARGET_ELF */ |
4921 | ||
17167fd8 MM |
4922 | else |
4923 | { | |
42820a49 | 4924 | asm_fprintf (file, "\t{liu|lis} %s,", r12); |
17167fd8 MM |
4925 | assemble_name (file, fname); |
4926 | asm_fprintf (file, "@ha\n"); | |
42820a49 | 4927 | asm_fprintf (file, "\t{cal|la} %s,", r12); |
17167fd8 | 4928 | assemble_name (file, fname); |
42820a49 MM |
4929 | asm_fprintf (file, "@l(%s)\n", r12); |
4930 | asm_fprintf (file, "\tmtctr %s\n", r12); | |
4931 | asm_fprintf (file, "\tbctr\n"); | |
17167fd8 MM |
4932 | } |
4933 | ||
17167fd8 MM |
4934 | break; |
4935 | } | |
4936 | } | |
4937 | } | |
4938 | ||
9878760c RK |
4939 | \f |
4940 | /* Output a TOC entry. We derive the entry name from what is | |
4941 | being written. */ | |
4942 | ||
4943 | void | |
4944 | output_toc (file, x, labelno) | |
4945 | FILE *file; | |
4946 | rtx x; | |
4947 | int labelno; | |
4948 | { | |
4949 | char buf[256]; | |
4950 | char *name = buf; | |
ec940faa | 4951 | const char *real_name; |
9878760c RK |
4952 | rtx base = x; |
4953 | int offset = 0; | |
4954 | ||
4697a36c MM |
4955 | if (TARGET_NO_TOC) |
4956 | abort (); | |
4957 | ||
ff1720ed RK |
4958 | /* if we're going to put a double constant in the TOC, make sure it's |
4959 | aligned properly when strict alignment is on. */ | |
4960 | if (GET_CODE (x) == CONST_DOUBLE | |
4961 | && STRICT_ALIGNMENT | |
4962 | && GET_MODE (x) == DFmode | |
4963 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { | |
4964 | ASM_OUTPUT_ALIGN (file, 3); | |
4965 | } | |
4966 | ||
4967 | ||
b6c9286a | 4968 | if (TARGET_ELF && TARGET_MINIMAL_TOC) |
d14a6d05 MM |
4969 | { |
4970 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
4971 | fprintf (file, "%d = .-", labelno); | |
4972 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC"); | |
19d2d16f | 4973 | fputs ("1\n", file); |
d14a6d05 MM |
4974 | } |
4975 | else | |
d14a6d05 | 4976 | ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno); |
9878760c | 4977 | |
37c37a57 RK |
4978 | /* Handle FP constants specially. Note that if we have a minimal |
4979 | TOC, things we put here aren't actually in the TOC, so we can allow | |
4980 | FP constants. */ | |
042259f2 | 4981 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode |
37c37a57 | 4982 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) |
9878760c | 4983 | { |
042259f2 DE |
4984 | REAL_VALUE_TYPE rv; |
4985 | long k[2]; | |
0adc764e | 4986 | |
042259f2 DE |
4987 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
4988 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 4989 | |
13ded975 DE |
4990 | if (TARGET_64BIT) |
4991 | { | |
4992 | if (TARGET_MINIMAL_TOC) | |
4993 | fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]); | |
4994 | else | |
4995 | fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n", | |
4996 | k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff); | |
4997 | return; | |
4998 | } | |
1875cc88 | 4999 | else |
13ded975 DE |
5000 | { |
5001 | if (TARGET_MINIMAL_TOC) | |
31bfaa0b | 5002 | fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]); |
13ded975 | 5003 | else |
31bfaa0b | 5004 | fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n", |
13ded975 DE |
5005 | k[0], k[1], k[0], k[1]); |
5006 | return; | |
5007 | } | |
9878760c RK |
5008 | } |
5009 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode | |
37c37a57 | 5010 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) |
9878760c | 5011 | { |
042259f2 DE |
5012 | REAL_VALUE_TYPE rv; |
5013 | long l; | |
9878760c | 5014 | |
042259f2 DE |
5015 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
5016 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
5017 | ||
31bfaa0b DE |
5018 | if (TARGET_64BIT) |
5019 | { | |
5020 | if (TARGET_MINIMAL_TOC) | |
5021 | fprintf (file, "\t.llong 0x%lx00000000\n", l); | |
5022 | else | |
5023 | fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l); | |
5024 | return; | |
5025 | } | |
042259f2 | 5026 | else |
31bfaa0b DE |
5027 | { |
5028 | if (TARGET_MINIMAL_TOC) | |
5029 | fprintf (file, "\t.long 0x%lx\n", l); | |
5030 | else | |
5031 | fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l); | |
5032 | return; | |
5033 | } | |
042259f2 DE |
5034 | } |
5035 | else if (GET_MODE (x) == DImode | |
5036 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) | |
5037 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) | |
5038 | { | |
5039 | HOST_WIDE_INT low; | |
5040 | HOST_WIDE_INT high; | |
5041 | ||
5042 | if (GET_CODE (x) == CONST_DOUBLE) | |
5043 | { | |
5044 | low = CONST_DOUBLE_LOW (x); | |
5045 | high = CONST_DOUBLE_HIGH (x); | |
5046 | } | |
5047 | else | |
5048 | #if HOST_BITS_PER_WIDE_INT == 32 | |
5049 | { | |
5050 | low = INTVAL (x); | |
5051 | high = (low < 0) ? ~0 : 0; | |
5052 | } | |
5053 | #else | |
5054 | { | |
5055 | low = INTVAL (x) & 0xffffffff; | |
5056 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; | |
5057 | } | |
5058 | #endif | |
9878760c | 5059 | |
13ded975 DE |
5060 | if (TARGET_64BIT) |
5061 | { | |
5062 | if (TARGET_MINIMAL_TOC) | |
5063 | fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low); | |
5064 | else | |
5065 | fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n", | |
5066 | (long)high, (long)low, (long)high, (long)low); | |
5067 | return; | |
5068 | } | |
1875cc88 | 5069 | else |
13ded975 DE |
5070 | { |
5071 | if (TARGET_MINIMAL_TOC) | |
3cb999d8 | 5072 | fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", |
13ded975 DE |
5073 | (long)high, (long)low); |
5074 | else | |
3cb999d8 | 5075 | fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n", |
13ded975 DE |
5076 | (long)high, (long)low, (long)high, (long)low); |
5077 | return; | |
5078 | } | |
9878760c RK |
5079 | } |
5080 | ||
5081 | if (GET_CODE (x) == CONST) | |
5082 | { | |
5083 | base = XEXP (XEXP (x, 0), 0); | |
5084 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
5085 | } | |
5086 | ||
5087 | if (GET_CODE (base) == SYMBOL_REF) | |
5088 | name = XSTR (base, 0); | |
5089 | else if (GET_CODE (base) == LABEL_REF) | |
5090 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
5091 | else if (GET_CODE (base) == CODE_LABEL) | |
5092 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
5093 | else | |
5094 | abort (); | |
5095 | ||
2e4eb9b0 | 5096 | STRIP_NAME_ENCODING (real_name, name); |
1875cc88 | 5097 | if (TARGET_MINIMAL_TOC) |
13ded975 | 5098 | fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file); |
1875cc88 JW |
5099 | else |
5100 | { | |
b6c9286a | 5101 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 5102 | |
1875cc88 JW |
5103 | if (offset < 0) |
5104 | fprintf (file, ".N%d", - offset); | |
5105 | else if (offset) | |
5106 | fprintf (file, ".P%d", offset); | |
9878760c | 5107 | |
19d2d16f | 5108 | fputs ("[TC],", file); |
1875cc88 | 5109 | } |
581bc4de MM |
5110 | |
5111 | /* Currently C++ toc references to vtables can be emitted before it | |
5112 | is decided whether the vtable is public or private. If this is | |
5113 | the case, then the linker will eventually complain that there is | |
5114 | a TOC reference to an unknown section. Thus, for vtables only, | |
5115 | we emit the TOC reference to reference the symbol and not the | |
5116 | section. */ | |
3807773b | 5117 | if (!strncmp ("_vt.", name, 4)) |
581bc4de | 5118 | { |
3807773b | 5119 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
5120 | if (offset < 0) |
5121 | fprintf (file, "%d", offset); | |
5122 | else if (offset > 0) | |
5123 | fprintf (file, "+%d", offset); | |
5124 | } | |
5125 | else | |
5126 | output_addr_const (file, x); | |
19d2d16f | 5127 | putc ('\n', file); |
9878760c RK |
5128 | } |
5129 | \f | |
5130 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
5131 | starting at P to FILE. | |
5132 | ||
5133 | On the RS/6000, we have to do this using the .byte operation and | |
5134 | write out special characters outside the quoted string. | |
5135 | Also, the assembler is broken; very long strings are truncated, | |
5136 | so we must artificially break them up early. */ | |
5137 | ||
5138 | void | |
5139 | output_ascii (file, p, n) | |
5140 | FILE *file; | |
d330fd93 | 5141 | const char *p; |
9878760c RK |
5142 | int n; |
5143 | { | |
5144 | char c; | |
5145 | int i, count_string; | |
d330fd93 KG |
5146 | const char *for_string = "\t.byte \""; |
5147 | const char *for_decimal = "\t.byte "; | |
5148 | const char *to_close = NULL; | |
9878760c RK |
5149 | |
5150 | count_string = 0; | |
5151 | for (i = 0; i < n; i++) | |
5152 | { | |
5153 | c = *p++; | |
5154 | if (c >= ' ' && c < 0177) | |
5155 | { | |
5156 | if (for_string) | |
5157 | fputs (for_string, file); | |
5158 | putc (c, file); | |
5159 | ||
5160 | /* Write two quotes to get one. */ | |
5161 | if (c == '"') | |
5162 | { | |
5163 | putc (c, file); | |
5164 | ++count_string; | |
5165 | } | |
5166 | ||
5167 | for_string = NULL; | |
5168 | for_decimal = "\"\n\t.byte "; | |
5169 | to_close = "\"\n"; | |
5170 | ++count_string; | |
5171 | ||
5172 | if (count_string >= 512) | |
5173 | { | |
5174 | fputs (to_close, file); | |
5175 | ||
5176 | for_string = "\t.byte \""; | |
5177 | for_decimal = "\t.byte "; | |
5178 | to_close = NULL; | |
5179 | count_string = 0; | |
5180 | } | |
5181 | } | |
5182 | else | |
5183 | { | |
5184 | if (for_decimal) | |
5185 | fputs (for_decimal, file); | |
5186 | fprintf (file, "%d", c); | |
5187 | ||
5188 | for_string = "\n\t.byte \""; | |
5189 | for_decimal = ", "; | |
5190 | to_close = "\n"; | |
5191 | count_string = 0; | |
5192 | } | |
5193 | } | |
5194 | ||
5195 | /* Now close the string if we have written one. Then end the line. */ | |
5196 | if (to_close) | |
5197 | fprintf (file, to_close); | |
5198 | } | |
5199 | \f | |
5200 | /* Generate a unique section name for FILENAME for a section type | |
5201 | represented by SECTION_DESC. Output goes into BUF. | |
5202 | ||
5203 | SECTION_DESC can be any string, as long as it is different for each | |
5204 | possible section type. | |
5205 | ||
5206 | We name the section in the same manner as xlc. The name begins with an | |
5207 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
5208 | names) with the last period replaced by the string SECTION_DESC. If |
5209 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
5210 | the name. */ | |
9878760c RK |
5211 | |
5212 | void | |
5213 | rs6000_gen_section_name (buf, filename, section_desc) | |
5214 | char **buf; | |
5215 | char *filename; | |
5216 | char *section_desc; | |
5217 | { | |
d330fd93 | 5218 | char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
5219 | char *p; |
5220 | int len; | |
9878760c RK |
5221 | |
5222 | after_last_slash = filename; | |
5223 | for (q = filename; *q; q++) | |
11e5fe42 RK |
5224 | { |
5225 | if (*q == '/') | |
5226 | after_last_slash = q + 1; | |
5227 | else if (*q == '.') | |
5228 | last_period = q; | |
5229 | } | |
9878760c | 5230 | |
11e5fe42 | 5231 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
9878760c RK |
5232 | *buf = (char *) permalloc (len); |
5233 | ||
5234 | p = *buf; | |
5235 | *p++ = '_'; | |
5236 | ||
5237 | for (q = after_last_slash; *q; q++) | |
5238 | { | |
11e5fe42 | 5239 | if (q == last_period) |
9878760c RK |
5240 | { |
5241 | strcpy (p, section_desc); | |
5242 | p += strlen (section_desc); | |
9878760c RK |
5243 | } |
5244 | ||
e9a780ec | 5245 | else if (ISALNUM (*q)) |
9878760c RK |
5246 | *p++ = *q; |
5247 | } | |
5248 | ||
11e5fe42 | 5249 | if (last_period == 0) |
9878760c RK |
5250 | strcpy (p, section_desc); |
5251 | else | |
5252 | *p = '\0'; | |
5253 | } | |
e165f3f0 RK |
5254 | \f |
5255 | /* Write function profiler code. */ | |
5256 | ||
5257 | void | |
5258 | output_function_profiler (file, labelno) | |
5259 | FILE *file; | |
5260 | int labelno; | |
5261 | { | |
5262 | /* The last used parameter register. */ | |
5263 | int last_parm_reg; | |
5264 | int i, j; | |
3daf36a4 | 5265 | char buf[100]; |
e165f3f0 | 5266 | |
3daf36a4 | 5267 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 | 5268 | switch (DEFAULT_ABI) |
3daf36a4 | 5269 | { |
38c1f2d7 MM |
5270 | default: |
5271 | abort (); | |
5272 | ||
5273 | case ABI_V4: | |
5274 | case ABI_SOLARIS: | |
5275 | case ABI_AIX_NODESC: | |
5276 | fprintf (file, "\tmflr %s\n", reg_names[0]); | |
5277 | if (flag_pic == 1) | |
5278 | { | |
dfdfa60f DE |
5279 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
5280 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", | |
5281 | reg_names[0], reg_names[1]); | |
17167fd8 | 5282 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 5283 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 5284 | assemble_name (file, buf); |
17167fd8 | 5285 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 MM |
5286 | } |
5287 | #if TARGET_ELF | |
5288 | else if (flag_pic > 1 || TARGET_RELOCATABLE) | |
5289 | { | |
dfdfa60f DE |
5290 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", |
5291 | reg_names[0], reg_names[1]); | |
38c1f2d7 | 5292 | rs6000_pic_func_labelno = rs6000_pic_labelno; |
17167fd8 MM |
5293 | rs6000_output_load_toc_table (file, 12); |
5294 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[12]); | |
38c1f2d7 | 5295 | assemble_name (file, buf); |
17167fd8 | 5296 | asm_fprintf (file, "X(%s)\n", reg_names[12]); |
dfdfa60f | 5297 | asm_fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); |
034e84c4 | 5298 | assemble_name (file, buf); |
dfdfa60f DE |
5299 | fputs ("X = .-.LCTOC1\n", file); |
5300 | fputs ("\t.long ", file); | |
034e84c4 MM |
5301 | assemble_name (file, buf); |
5302 | fputs ("\n\t.previous\n", file); | |
38c1f2d7 MM |
5303 | } |
5304 | #endif | |
38c1f2d7 MM |
5305 | else |
5306 | { | |
17167fd8 | 5307 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 5308 | assemble_name (file, buf); |
dfdfa60f | 5309 | fputs ("@ha\n", file); |
b5253831 DE |
5310 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", |
5311 | reg_names[0], reg_names[1]); | |
a260abc9 | 5312 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 5313 | assemble_name (file, buf); |
17167fd8 | 5314 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
5315 | } |
5316 | ||
b5253831 DE |
5317 | if (current_function_needs_context) |
5318 | asm_fprintf (file, "\tmr %s,%s\n", | |
5319 | reg_names[30], reg_names[STATIC_CHAIN_REGNUM]); | |
38c1f2d7 | 5320 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); |
b5253831 DE |
5321 | if (current_function_needs_context) |
5322 | asm_fprintf (file, "\tmr %s,%s\n", | |
5323 | reg_names[STATIC_CHAIN_REGNUM], reg_names[30]); | |
38c1f2d7 MM |
5324 | break; |
5325 | ||
5326 | case ABI_AIX: | |
5327 | /* Set up a TOC entry for the profiler label. */ | |
5328 | toc_section (); | |
5329 | ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno); | |
5330 | if (TARGET_MINIMAL_TOC) | |
5331 | { | |
13ded975 | 5332 | fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file); |
38c1f2d7 MM |
5333 | assemble_name (file, buf); |
5334 | putc ('\n', file); | |
5335 | } | |
5336 | else | |
5337 | { | |
5338 | fputs ("\t.tc\t", file); | |
5339 | assemble_name (file, buf); | |
5340 | fputs ("[TC],", file); | |
5341 | assemble_name (file, buf); | |
5342 | putc ('\n', file); | |
5343 | } | |
5344 | text_section (); | |
e165f3f0 RK |
5345 | |
5346 | /* Figure out last used parameter register. The proper thing to do is | |
5347 | to walk incoming args of the function. A function might have live | |
5348 | parameter registers even if it has no incoming args. */ | |
5349 | ||
38c1f2d7 MM |
5350 | for (last_parm_reg = 10; |
5351 | last_parm_reg > 2 && ! regs_ever_live [last_parm_reg]; | |
5352 | last_parm_reg--) | |
5353 | ; | |
e165f3f0 | 5354 | |
b5253831 DE |
5355 | /* Save parameter registers in regs 23-30 and static chain in r22. |
5356 | Don't overwrite reg 31, since it might be set up as the frame pointer. */ | |
e165f3f0 | 5357 | |
38c1f2d7 MM |
5358 | for (i = 3, j = 30; i <= last_parm_reg; i++, j--) |
5359 | asm_fprintf (file, "\tmr %d,%d\n", j, i); | |
b5253831 DE |
5360 | if (current_function_needs_context) |
5361 | asm_fprintf (file, "\tmr %d,%d\n", j, STATIC_CHAIN_REGNUM); | |
e165f3f0 RK |
5362 | |
5363 | /* Load location address into r3, and call mcount. */ | |
5364 | ||
38c1f2d7 | 5365 | ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno); |
13ded975 DE |
5366 | asm_fprintf (file, TARGET_32BIT ? "\t{l|lwz} %s," : "\tld %s,", |
5367 | reg_names[3]); | |
38c1f2d7 | 5368 | assemble_name (file, buf); |
13f1623b DE |
5369 | asm_fprintf (file, "(%s)\n\tbl %s\n\t", reg_names[2], RS6000_MCOUNT); |
5370 | asm_fprintf (file, RS6000_CALL_GLUE); | |
5371 | putc('\n', file); | |
e165f3f0 | 5372 | |
b5253831 | 5373 | /* Restore parameter registers and static chain. */ |
e165f3f0 | 5374 | |
38c1f2d7 MM |
5375 | for (i = 3, j = 30; i <= last_parm_reg; i++, j--) |
5376 | asm_fprintf (file, "\tmr %d,%d\n", i, j); | |
b5253831 DE |
5377 | if (current_function_needs_context) |
5378 | asm_fprintf (file, "\tmr %d,%d\n", STATIC_CHAIN_REGNUM, j); | |
5379 | ||
38c1f2d7 MM |
5380 | break; |
5381 | } | |
e165f3f0 | 5382 | } |
a251ffd0 TG |
5383 | |
5384 | /* Adjust the cost of a scheduling dependency. Return the new cost of | |
5385 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
5386 | ||
5387 | int | |
a06faf84 | 5388 | rs6000_adjust_cost (insn, link, dep_insn, cost) |
a251ffd0 TG |
5389 | rtx insn; |
5390 | rtx link; | |
296b8152 | 5391 | rtx dep_insn ATTRIBUTE_UNUSED; |
a251ffd0 TG |
5392 | int cost; |
5393 | { | |
5394 | if (! recog_memoized (insn)) | |
5395 | return 0; | |
5396 | ||
5397 | if (REG_NOTE_KIND (link) != 0) | |
5398 | return 0; | |
5399 | ||
5400 | if (REG_NOTE_KIND (link) == 0) | |
5401 | { | |
5402 | /* Data dependency; DEP_INSN writes a register that INSN reads some | |
5403 | cycles later. */ | |
5404 | ||
5405 | /* Tell the first scheduling pass about the latency between a mtctr | |
5406 | and bctr (and mtlr and br/blr). The first scheduling pass will not | |
5407 | know about this latency since the mtctr instruction, which has the | |
5408 | latency associated to it, will be generated by reload. */ | |
5409 | if (get_attr_type (insn) == TYPE_JMPREG) | |
5410 | return TARGET_POWER ? 5 : 4; | |
5411 | ||
5412 | /* Fall out to return default cost. */ | |
5413 | } | |
5414 | ||
5415 | return cost; | |
5416 | } | |
b6c9286a | 5417 | |
bef84347 VM |
5418 | /* A C statement (sans semicolon) to update the integer scheduling priority |
5419 | INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier, | |
5420 | increase the priority to execute INSN later. Do not define this macro if | |
5421 | you do not need to adjust the scheduling priorities of insns. */ | |
5422 | ||
5423 | int | |
5424 | rs6000_adjust_priority (insn, priority) | |
d330fd93 | 5425 | rtx insn ATTRIBUTE_UNUSED; |
bef84347 VM |
5426 | int priority; |
5427 | { | |
5428 | /* On machines (like the 750) which have asymetric integer units, where one | |
5429 | integer unit can do multiply and divides and the other can't, reduce the | |
5430 | priority of multiply/divide so it is scheduled before other integer | |
5431 | operationss. */ | |
5432 | ||
5433 | #if 0 | |
5434 | if (GET_RTX_CLASS (GET_CODE (insn)) != 'i') | |
5435 | return priority; | |
5436 | ||
5437 | if (GET_CODE (PATTERN (insn)) == USE) | |
5438 | return priority; | |
5439 | ||
5440 | switch (rs6000_cpu_attr) { | |
5441 | case CPU_PPC750: | |
5442 | switch (get_attr_type (insn)) | |
5443 | { | |
5444 | default: | |
5445 | break; | |
5446 | ||
5447 | case TYPE_IMUL: | |
5448 | case TYPE_IDIV: | |
3cb999d8 DE |
5449 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
5450 | priority, priority); | |
bef84347 VM |
5451 | if (priority >= 0 && priority < 0x01000000) |
5452 | priority >>= 3; | |
5453 | break; | |
5454 | } | |
5455 | } | |
5456 | #endif | |
5457 | ||
5458 | return priority; | |
5459 | } | |
5460 | ||
b6c9286a MM |
5461 | /* Return how many instructions the machine can issue per cycle */ |
5462 | int get_issue_rate() | |
5463 | { | |
5464 | switch (rs6000_cpu_attr) { | |
3cb999d8 DE |
5465 | case CPU_RIOS1: /* ? */ |
5466 | case CPU_RS64A: | |
5467 | case CPU_PPC601: /* ? */ | |
5468 | return 3; | |
b6c9286a | 5469 | case CPU_PPC603: |
bef84347 VM |
5470 | case CPU_PPC750: |
5471 | return 2; | |
3cb999d8 | 5472 | case CPU_RIOS2: |
b6c9286a | 5473 | case CPU_PPC604: |
19684119 | 5474 | case CPU_PPC604E: |
b6c9286a | 5475 | case CPU_PPC620: |
3cb999d8 | 5476 | case CPU_PPC630: |
b6c9286a MM |
5477 | return 4; |
5478 | default: | |
5479 | return 1; | |
5480 | } | |
5481 | } | |
5482 | ||
b6c9286a MM |
5483 | \f |
5484 | /* Output assembler code for a block containing the constant parts | |
5485 | of a trampoline, leaving space for the variable parts. | |
5486 | ||
5487 | The trampoline should set the static chain pointer to value placed | |
5488 | into the trampoline and should branch to the specified routine. */ | |
5489 | ||
5490 | void | |
5491 | rs6000_trampoline_template (file) | |
5492 | FILE *file; | |
5493 | { | |
d330fd93 KG |
5494 | const char *sc = reg_names[STATIC_CHAIN_REGNUM]; |
5495 | const char *r0 = reg_names[0]; | |
5496 | const char *r2 = reg_names[2]; | |
b6c9286a MM |
5497 | |
5498 | switch (DEFAULT_ABI) | |
5499 | { | |
5500 | default: | |
5501 | abort (); | |
5502 | ||
5503 | /* Under AIX, this is not code at all, but merely a data area, | |
5504 | since that is the way all functions are called. The first word is | |
5505 | the address of the function, the second word is the TOC pointer (r2), | |
5506 | and the third word is the static chain value. */ | |
5507 | case ABI_AIX: | |
b6c9286a MM |
5508 | break; |
5509 | ||
5510 | ||
5511 | /* V.4/eabi function pointers are just a single pointer, so we need to | |
5512 | do the full gory code to load up the static chain. */ | |
5513 | case ABI_V4: | |
c81bebd7 | 5514 | case ABI_SOLARIS: |
b6c9286a | 5515 | case ABI_AIX_NODESC: |
b6c9286a MM |
5516 | break; |
5517 | ||
5518 | /* NT function pointers point to a two word area (real address, TOC) | |
5519 | which unfortunately does not include a static chain field. So we | |
7c59dc5d MM |
5520 | use the function field to point to ..LTRAMP1 and the toc field |
5521 | to point to the whole table. */ | |
b6c9286a | 5522 | case ABI_NT: |
7c59dc5d MM |
5523 | if (STATIC_CHAIN_REGNUM == 0 |
5524 | || STATIC_CHAIN_REGNUM == 2 | |
5525 | || TARGET_64BIT | |
5526 | || !TARGET_NEW_MNEMONICS) | |
b6c9286a MM |
5527 | abort (); |
5528 | ||
7c59dc5d MM |
5529 | fprintf (file, "\t.ualong 0\n"); /* offset 0 */ |
5530 | fprintf (file, "\t.ualong 0\n"); /* offset 4 */ | |
5531 | fprintf (file, "\t.ualong 0\n"); /* offset 8 */ | |
5532 | fprintf (file, "\t.ualong 0\n"); /* offset 12 */ | |
5533 | fprintf (file, "\t.ualong 0\n"); /* offset 16 */ | |
8bd04c56 | 5534 | fprintf (file, "..LTRAMP1..0:\n"); /* offset 20 */ |
7c59dc5d MM |
5535 | fprintf (file, "\tlwz %s,8(%s)\n", r0, r2); /* offset 24 */ |
5536 | fprintf (file, "\tlwz %s,12(%s)\n", sc, r2); /* offset 28 */ | |
5537 | fprintf (file, "\tmtctr %s\n", r0); /* offset 32 */ | |
5538 | fprintf (file, "\tlwz %s,16(%s)\n", r2, r2); /* offset 36 */ | |
5539 | fprintf (file, "\tbctr\n"); /* offset 40 */ | |
b6c9286a MM |
5540 | break; |
5541 | } | |
5542 | ||
5543 | return; | |
5544 | } | |
5545 | ||
5546 | /* Length in units of the trampoline for entering a nested function. */ | |
5547 | ||
5548 | int | |
5549 | rs6000_trampoline_size () | |
5550 | { | |
5551 | int ret = 0; | |
5552 | ||
5553 | switch (DEFAULT_ABI) | |
5554 | { | |
5555 | default: | |
5556 | abort (); | |
5557 | ||
5558 | case ABI_AIX: | |
8f802bfb | 5559 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
5560 | break; |
5561 | ||
5562 | case ABI_V4: | |
c81bebd7 | 5563 | case ABI_SOLARIS: |
b6c9286a | 5564 | case ABI_AIX_NODESC: |
03a7e1a5 | 5565 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a MM |
5566 | break; |
5567 | ||
5568 | case ABI_NT: | |
7c59dc5d | 5569 | ret = 20; |
b6c9286a MM |
5570 | break; |
5571 | } | |
5572 | ||
5573 | return ret; | |
5574 | } | |
5575 | ||
5576 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
5577 | FNADDR is an RTX for the address of the function's pure code. | |
5578 | CXT is an RTX for the static chain value for the function. */ | |
5579 | ||
5580 | void | |
5581 | rs6000_initialize_trampoline (addr, fnaddr, cxt) | |
5582 | rtx addr; | |
5583 | rtx fnaddr; | |
5584 | rtx cxt; | |
5585 | { | |
ac2a93a1 | 5586 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
5587 | int regsize = (TARGET_32BIT) ? 4 : 8; |
5588 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
5589 | |
5590 | switch (DEFAULT_ABI) | |
5591 | { | |
5592 | default: | |
5593 | abort (); | |
5594 | ||
8bd04c56 | 5595 | /* Macros to shorten the code expansions below. */ |
39403d82 DE |
5596 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
5597 | #define MEM_PLUS(addr,offset) gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 5598 | |
b6c9286a MM |
5599 | /* Under AIX, just build the 3 word function descriptor */ |
5600 | case ABI_AIX: | |
8bd04c56 MM |
5601 | { |
5602 | rtx fn_reg = gen_reg_rtx (pmode); | |
5603 | rtx toc_reg = gen_reg_rtx (pmode); | |
5604 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
5605 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4)); | |
5606 | emit_move_insn (MEM_DEREF (addr), fn_reg); | |
5607 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
5608 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
5609 | } | |
b6c9286a MM |
5610 | break; |
5611 | ||
eaf1bcf1 | 5612 | /* Under V.4/eabi, call __trampoline_setup to do the real work. */ |
b6c9286a | 5613 | case ABI_V4: |
c81bebd7 | 5614 | case ABI_SOLARIS: |
b6c9286a | 5615 | case ABI_AIX_NODESC: |
39403d82 | 5616 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
5617 | FALSE, VOIDmode, 4, |
5618 | addr, pmode, | |
5619 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
5620 | fnaddr, pmode, | |
5621 | ctx_reg, pmode); | |
b6c9286a MM |
5622 | break; |
5623 | ||
8bd04c56 MM |
5624 | /* Under NT, update the first word to point to the ..LTRAMP1..0 header, |
5625 | the second word will point to the whole trampoline, third-fifth words | |
7c59dc5d | 5626 | will then have the real address, static chain, and toc value. */ |
b6c9286a | 5627 | case ABI_NT: |
8bd04c56 MM |
5628 | { |
5629 | rtx tramp_reg = gen_reg_rtx (pmode); | |
5630 | rtx fn_reg = gen_reg_rtx (pmode); | |
5631 | rtx toc_reg = gen_reg_rtx (pmode); | |
5632 | ||
39403d82 | 5633 | emit_move_insn (tramp_reg, gen_rtx_SYMBOL_REF (pmode, "..LTRAMP1..0")); |
8bd04c56 MM |
5634 | addr = force_reg (pmode, addr); |
5635 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
5636 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); | |
5637 | emit_move_insn (MEM_DEREF (addr), tramp_reg); | |
5638 | emit_move_insn (MEM_PLUS (addr, regsize), addr); | |
5639 | emit_move_insn (MEM_PLUS (addr, 2*regsize), fn_reg); | |
5640 | emit_move_insn (MEM_PLUS (addr, 3*regsize), ctx_reg); | |
39403d82 | 5641 | emit_move_insn (MEM_PLUS (addr, 4*regsize), gen_rtx_REG (pmode, 2)); |
8bd04c56 | 5642 | } |
b6c9286a MM |
5643 | break; |
5644 | } | |
5645 | ||
5646 | return; | |
5647 | } | |
7509c759 MM |
5648 | |
5649 | \f | |
5650 | /* If defined, a C expression whose value is nonzero if IDENTIFIER | |
5651 | with arguments ARGS is a valid machine specific attribute for DECL. | |
5652 | The attributes in ATTRIBUTES have previously been assigned to DECL. */ | |
5653 | ||
5654 | int | |
5655 | rs6000_valid_decl_attribute_p (decl, attributes, identifier, args) | |
296b8152 KG |
5656 | tree decl ATTRIBUTE_UNUSED; |
5657 | tree attributes ATTRIBUTE_UNUSED; | |
5658 | tree identifier ATTRIBUTE_UNUSED; | |
5659 | tree args ATTRIBUTE_UNUSED; | |
7509c759 MM |
5660 | { |
5661 | return 0; | |
5662 | } | |
5663 | ||
5664 | /* If defined, a C expression whose value is nonzero if IDENTIFIER | |
5665 | with arguments ARGS is a valid machine specific attribute for TYPE. | |
5666 | The attributes in ATTRIBUTES have previously been assigned to TYPE. */ | |
5667 | ||
5668 | int | |
5669 | rs6000_valid_type_attribute_p (type, attributes, identifier, args) | |
5670 | tree type; | |
296b8152 | 5671 | tree attributes ATTRIBUTE_UNUSED; |
7509c759 MM |
5672 | tree identifier; |
5673 | tree args; | |
5674 | { | |
5675 | if (TREE_CODE (type) != FUNCTION_TYPE | |
5676 | && TREE_CODE (type) != FIELD_DECL | |
5677 | && TREE_CODE (type) != TYPE_DECL) | |
5678 | return 0; | |
5679 | ||
6a4cee5f MM |
5680 | /* Longcall attribute says that the function is not within 2**26 bytes |
5681 | of the current function, and to do an indirect call. */ | |
5682 | if (is_attribute_p ("longcall", identifier)) | |
5683 | return (args == NULL_TREE); | |
5684 | ||
7509c759 MM |
5685 | if (DEFAULT_ABI == ABI_NT) |
5686 | { | |
5687 | /* Stdcall attribute says callee is responsible for popping arguments | |
5688 | if they are not variable. */ | |
5689 | if (is_attribute_p ("stdcall", identifier)) | |
5690 | return (args == NULL_TREE); | |
5691 | ||
5692 | /* Cdecl attribute says the callee is a normal C declaration */ | |
5693 | if (is_attribute_p ("cdecl", identifier)) | |
5694 | return (args == NULL_TREE); | |
5695 | ||
38e01259 | 5696 | /* Dllimport attribute says the caller is to call the function |
7509c759 MM |
5697 | indirectly through a __imp_<name> pointer. */ |
5698 | if (is_attribute_p ("dllimport", identifier)) | |
5699 | return (args == NULL_TREE); | |
5700 | ||
38e01259 | 5701 | /* Dllexport attribute says the callee is to create a __imp_<name> |
7509c759 MM |
5702 | pointer. */ |
5703 | if (is_attribute_p ("dllexport", identifier)) | |
5704 | return (args == NULL_TREE); | |
e56bb9ed | 5705 | |
3cb999d8 DE |
5706 | /* Exception attribute allows the user to specify 1-2 strings |
5707 | or identifiers that will fill in the 3rd and 4th fields | |
5708 | of the structured exception table. */ | |
e56bb9ed MM |
5709 | if (is_attribute_p ("exception", identifier)) |
5710 | { | |
5711 | int i; | |
5712 | ||
5713 | if (args == NULL_TREE) | |
5714 | return 0; | |
5715 | ||
5716 | for (i = 0; i < 2 && args != NULL_TREE; i++) | |
5717 | { | |
5718 | tree this_arg = TREE_VALUE (args); | |
5719 | args = TREE_PURPOSE (args); | |
5720 | ||
5721 | if (TREE_CODE (this_arg) != STRING_CST | |
5722 | && TREE_CODE (this_arg) != IDENTIFIER_NODE) | |
5723 | return 0; | |
5724 | } | |
5725 | ||
5726 | return (args == NULL_TREE); | |
5727 | } | |
7509c759 MM |
5728 | } |
5729 | ||
5730 | return 0; | |
5731 | } | |
5732 | ||
5733 | /* If defined, a C expression whose value is zero if the attributes on | |
5734 | TYPE1 and TYPE2 are incompatible, one if they are compatible, and | |
5735 | two if they are nearly compatible (which causes a warning to be | |
5736 | generated). */ | |
5737 | ||
5738 | int | |
5739 | rs6000_comp_type_attributes (type1, type2) | |
296b8152 KG |
5740 | tree type1 ATTRIBUTE_UNUSED; |
5741 | tree type2 ATTRIBUTE_UNUSED; | |
7509c759 MM |
5742 | { |
5743 | return 1; | |
5744 | } | |
5745 | ||
5746 | /* If defined, a C statement that assigns default attributes to newly | |
5747 | defined TYPE. */ | |
5748 | ||
5749 | void | |
5750 | rs6000_set_default_type_attributes (type) | |
296b8152 | 5751 | tree type ATTRIBUTE_UNUSED; |
7509c759 | 5752 | { |
3cb999d8 | 5753 | return; |
7509c759 MM |
5754 | } |
5755 | ||
38e01259 | 5756 | /* Return a dll import reference corresponding to a call's SYMBOL_REF */ |
7509c759 MM |
5757 | struct rtx_def * |
5758 | rs6000_dll_import_ref (call_ref) | |
5759 | rtx call_ref; | |
5760 | { | |
d330fd93 | 5761 | const char *call_name; |
7509c759 MM |
5762 | int len; |
5763 | char *p; | |
5764 | rtx reg1, reg2; | |
5765 | tree node; | |
5766 | ||
5767 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
5768 | abort (); | |
5769 | ||
5770 | call_name = XSTR (call_ref, 0); | |
5771 | len = sizeof ("__imp_") + strlen (call_name); | |
5772 | p = alloca (len); | |
5773 | reg2 = gen_reg_rtx (Pmode); | |
5774 | ||
5775 | strcpy (p, "__imp_"); | |
5776 | strcat (p, call_name); | |
5777 | node = get_identifier (p); | |
5778 | ||
3cb999d8 DE |
5779 | reg1 = force_reg (Pmode, gen_rtx_SYMBOL_REF (VOIDmode, |
5780 | IDENTIFIER_POINTER (node))); | |
39403d82 | 5781 | emit_move_insn (reg2, gen_rtx_MEM (Pmode, reg1)); |
7509c759 MM |
5782 | |
5783 | return reg2; | |
5784 | } | |
5785 | ||
3cb999d8 DE |
5786 | /* Return a reference suitable for calling a function with the |
5787 | longcall attribute. */ | |
6a4cee5f MM |
5788 | struct rtx_def * |
5789 | rs6000_longcall_ref (call_ref) | |
5790 | rtx call_ref; | |
5791 | { | |
d330fd93 | 5792 | const char *call_name; |
6a4cee5f MM |
5793 | tree node; |
5794 | ||
5795 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
5796 | return call_ref; | |
5797 | ||
5798 | /* System V adds '.' to the internal name, so skip them. */ | |
5799 | call_name = XSTR (call_ref, 0); | |
5800 | if (*call_name == '.') | |
5801 | { | |
5802 | while (*call_name == '.') | |
5803 | call_name++; | |
5804 | ||
5805 | node = get_identifier (call_name); | |
39403d82 | 5806 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
5807 | } |
5808 | ||
5809 | return force_reg (Pmode, call_ref); | |
5810 | } | |
5811 | ||
7509c759 MM |
5812 | \f |
5813 | /* A C statement or statements to switch to the appropriate section | |
5814 | for output of RTX in mode MODE. You can assume that RTX is some | |
5815 | kind of constant in RTL. The argument MODE is redundant except in | |
5816 | the case of a `const_int' rtx. Select the section by calling | |
5817 | `text_section' or one of the alternatives for other sections. | |
5818 | ||
5819 | Do not define this macro if you put all constants in the read-only | |
5820 | data section. */ | |
5821 | ||
5822 | #ifdef USING_SVR4_H | |
5823 | ||
5824 | void | |
5825 | rs6000_select_rtx_section (mode, x) | |
5f59ecb7 | 5826 | enum machine_mode mode ATTRIBUTE_UNUSED; |
7509c759 MM |
5827 | rtx x; |
5828 | { | |
5829 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x)) | |
5830 | toc_section (); | |
7509c759 MM |
5831 | else |
5832 | const_section (); | |
5833 | } | |
5834 | ||
5835 | /* A C statement or statements to switch to the appropriate | |
5836 | section for output of DECL. DECL is either a `VAR_DECL' node | |
5837 | or a constant of some sort. RELOC indicates whether forming | |
5838 | the initial value of DECL requires link-time relocations. */ | |
5839 | ||
5840 | void | |
5841 | rs6000_select_section (decl, reloc) | |
5842 | tree decl; | |
5843 | int reloc; | |
5844 | { | |
5845 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
5846 | ||
5847 | if (TREE_CODE (decl) == STRING_CST) | |
5848 | { | |
88228c4b | 5849 | if (! flag_writable_strings) |
7509c759 | 5850 | const_section (); |
7509c759 MM |
5851 | else |
5852 | data_section (); | |
5853 | } | |
5854 | else if (TREE_CODE (decl) == VAR_DECL) | |
5855 | { | |
5856 | if ((flag_pic && reloc) | |
3cb999d8 | 5857 | || ! TREE_READONLY (decl) |
7509c759 | 5858 | || TREE_SIDE_EFFECTS (decl) |
3cb999d8 | 5859 | || ! DECL_INITIAL (decl) |
7509c759 | 5860 | || (DECL_INITIAL (decl) != error_mark_node |
3cb999d8 | 5861 | && ! TREE_CONSTANT (DECL_INITIAL (decl)))) |
7509c759 | 5862 | { |
3cb999d8 DE |
5863 | if (rs6000_sdata != SDATA_NONE && (size > 0) |
5864 | && (size <= g_switch_value)) | |
7509c759 MM |
5865 | sdata_section (); |
5866 | else | |
5867 | data_section (); | |
5868 | } | |
5869 | else | |
5870 | { | |
3cb999d8 DE |
5871 | if (rs6000_sdata != SDATA_NONE && (size > 0) |
5872 | && (size <= g_switch_value)) | |
c81bebd7 | 5873 | { |
d9407988 | 5874 | if (rs6000_sdata == SDATA_EABI) |
c81bebd7 MM |
5875 | sdata2_section (); |
5876 | else | |
3cb999d8 | 5877 | sdata_section (); /* System V doesn't have .sdata2/.sbss2 */ |
c81bebd7 | 5878 | } |
7509c759 MM |
5879 | else |
5880 | const_section (); | |
5881 | } | |
5882 | } | |
5883 | else | |
5884 | const_section (); | |
5885 | } | |
d9407988 MM |
5886 | |
5887 | \f | |
d9407988 MM |
5888 | /* If we are referencing a function that is static or is known to be |
5889 | in this file, make the SYMBOL_REF special. We can use this to indicate | |
5890 | that we can branch to this function without emitting a no-op after the | |
5891 | call. For real AIX and NT calling sequences, we also replace the | |
5892 | function name with the real name (1 or 2 leading .'s), rather than | |
5893 | the function descriptor name. This saves a lot of overriding code | |
a260abc9 | 5894 | to read the prefixes. */ |
d9407988 MM |
5895 | |
5896 | void | |
5897 | rs6000_encode_section_info (decl) | |
5898 | tree decl; | |
5899 | { | |
5900 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
5901 | { | |
5902 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
8f1b829e DJ |
5903 | if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl)) |
5904 | && !DECL_WEAK (decl)) | |
d9407988 MM |
5905 | SYMBOL_REF_FLAG (sym_ref) = 1; |
5906 | ||
5907 | if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT) | |
5908 | { | |
d330fd93 | 5909 | const char *prefix = (DEFAULT_ABI == ABI_AIX) ? "." : ".."; |
d9407988 MM |
5910 | char *str = permalloc (strlen (prefix) + 1 |
5911 | + strlen (XSTR (sym_ref, 0))); | |
5912 | strcpy (str, prefix); | |
5913 | strcat (str, XSTR (sym_ref, 0)); | |
5914 | XSTR (sym_ref, 0) = str; | |
5915 | } | |
5916 | } | |
5917 | else if (rs6000_sdata != SDATA_NONE | |
5918 | && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) | |
5919 | && TREE_CODE (decl) == VAR_DECL) | |
5920 | { | |
5921 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
5922 | tree section_name = DECL_SECTION_NAME (decl); | |
d330fd93 | 5923 | const char *name = (char *)0; |
d9407988 MM |
5924 | int len = 0; |
5925 | ||
5926 | if (section_name) | |
5927 | { | |
5928 | if (TREE_CODE (section_name) == STRING_CST) | |
5929 | { | |
5930 | name = TREE_STRING_POINTER (section_name); | |
5931 | len = TREE_STRING_LENGTH (section_name); | |
5932 | } | |
5933 | else | |
5934 | abort (); | |
5935 | } | |
5936 | ||
5937 | if ((size > 0 && size <= g_switch_value) | |
5938 | || (name | |
5f59ecb7 | 5939 | && ((len == sizeof (".sdata") - 1 |
3cb999d8 | 5940 | && strcmp (name, ".sdata") == 0) |
5f59ecb7 | 5941 | || (len == sizeof (".sdata2") - 1 |
3cb999d8 | 5942 | && strcmp (name, ".sdata2") == 0) |
5f59ecb7 | 5943 | || (len == sizeof (".sbss") - 1 |
3cb999d8 | 5944 | && strcmp (name, ".sbss") == 0) |
5f59ecb7 | 5945 | || (len == sizeof (".sbss2") - 1 |
3cb999d8 | 5946 | && strcmp (name, ".sbss2") == 0) |
5f59ecb7 | 5947 | || (len == sizeof (".PPC.EMB.sdata0") - 1 |
3cb999d8 | 5948 | && strcmp (name, ".PPC.EMB.sdata0") == 0) |
5f59ecb7 | 5949 | || (len == sizeof (".PPC.EMB.sbss0") - 1 |
3cb999d8 | 5950 | && strcmp (name, ".PPC.EMB.sbss0") == 0)))) |
d9407988 MM |
5951 | { |
5952 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
5953 | char *str = permalloc (2 + strlen (XSTR (sym_ref, 0))); | |
5954 | strcpy (str, "@"); | |
5955 | strcat (str, XSTR (sym_ref, 0)); | |
5956 | XSTR (sym_ref, 0) = str; | |
5957 | } | |
5958 | } | |
5959 | } | |
5960 | ||
7509c759 | 5961 | #endif /* USING_SVR4_H */ |
000034eb | 5962 | |
a6c2a102 | 5963 | \f |
000034eb | 5964 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
5965 | ADDR can be effectively incremented by incrementing REG. |
5966 | ||
5967 | r0 is special and we must not select it as an address | |
5968 | register by this routine since our caller will try to | |
5969 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
5970 | |
5971 | struct rtx_def * | |
5972 | find_addr_reg (addr) | |
5973 | rtx addr; | |
5974 | { | |
5975 | while (GET_CODE (addr) == PLUS) | |
5976 | { | |
02441cd6 JL |
5977 | if (GET_CODE (XEXP (addr, 0)) == REG |
5978 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 5979 | addr = XEXP (addr, 0); |
02441cd6 JL |
5980 | else if (GET_CODE (XEXP (addr, 1)) == REG |
5981 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
5982 | addr = XEXP (addr, 1); |
5983 | else if (CONSTANT_P (XEXP (addr, 0))) | |
5984 | addr = XEXP (addr, 1); | |
5985 | else if (CONSTANT_P (XEXP (addr, 1))) | |
5986 | addr = XEXP (addr, 0); | |
5987 | else | |
5988 | abort (); | |
5989 | } | |
02441cd6 | 5990 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
5991 | return addr; |
5992 | abort (); | |
5993 | } | |
5994 | ||
a6c2a102 DE |
5995 | void |
5996 | rs6000_fatal_bad_address (op) | |
5997 | rtx op; | |
5998 | { | |
5999 | fatal_insn ("bad address", op); | |
6000 | } |