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