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