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