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