Initial revision
[official-gcc.git] / gcc / config / rs6000 / rs6000.c
blob60262a9aba4144acc3a6ea18b48ab18efb1d3474
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include <stdio.h>
23 #include <ctype.h>
24 #include "config.h"
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"
38 #include "tree.h"
39 #include "except.h"
40 #include "function.h"
42 #ifndef TARGET_NO_PROTOTYPE
43 #define TARGET_NO_PROTOTYPE 0
44 #endif
46 extern char *language_string;
47 extern int profile_block_flag;
49 #define min(A,B) ((A) < (B) ? (A) : (B))
50 #define max(A,B) ((A) > (B) ? (A) : (B))
52 /* Target cpu type */
54 enum processor_type rs6000_cpu;
55 struct rs6000_cpu_select rs6000_select[3] =
57 /* switch name, tune arch */
58 { (char *)0, "--with-cpu=", 1, 1 },
59 { (char *)0, "-mcpu=", 1, 1 },
60 { (char *)0, "-mtune=", 1, 0 },
63 /* Set to non-zero by "fix" operation to indicate that itrunc and
64 uitrunc must be defined. */
66 int rs6000_trunc_used;
68 /* Set to non-zero once they have been defined. */
70 static int trunc_defined;
72 /* Set to non-zero once AIX common-mode calls have been defined. */
73 static int common_mode_defined;
75 /* Save information from a "cmpxx" operation until the branch or scc is
76 emitted. */
77 rtx rs6000_compare_op0, rs6000_compare_op1;
78 int rs6000_compare_fp_p;
80 #ifdef USING_SVR4_H
81 /* Label number of label created for -mrelocatable, to call to so we can
82 get the address of the GOT section */
83 int rs6000_pic_labelno;
84 int rs6000_pic_func_labelno;
86 /* Which abi to adhere to */
87 char *rs6000_abi_name = RS6000_ABI_NAME;
89 /* Semantics of the small data area */
90 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
92 /* Which small data model to use */
93 char *rs6000_sdata_name = (char *)0;
94 #endif
96 /* Whether a System V.4 varargs area was created. */
97 int rs6000_sysv_varargs_p;
99 /* ABI enumeration available for subtarget to use. */
100 enum rs6000_abi rs6000_current_abi;
102 /* Offset & size for fpmem stack locations used for converting between
103 float and integral types. */
104 int rs6000_fpmem_offset;
105 int rs6000_fpmem_size;
107 /* Debug flags */
108 char *rs6000_debug_name;
109 int rs6000_debug_stack; /* debug stack applications */
110 int rs6000_debug_arg; /* debug argument handling */
112 /* Flag to say the TOC is initialized */
113 int toc_initialized;
116 /* Default register names. */
117 char rs6000_reg_names[][8] =
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"
132 #ifdef TARGET_REGNAMES
133 static char alt_reg_names[][8] =
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"
147 #endif
149 #ifndef MASK_STRICT_ALIGN
150 #define MASK_STRICT_ALIGN 0
151 #endif
153 /* Override command line options. Mostly we process the processor
154 type and sometimes adjust other TARGET_ options. */
156 void
157 rs6000_override_options (default_cpu)
158 char *default_cpu;
160 int i, j;
161 struct rs6000_cpu_select *ptr;
163 /* Simplify the entries below by making a mask for any POWER
164 variant and any PowerPC variant. */
166 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
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)
171 static struct ptt
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[]
178 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
179 POWER_MASKS | POWERPC_MASKS},
180 {"power", PROCESSOR_POWER,
181 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
182 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
183 {"power2", PROCESSOR_POWER,
184 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
185 POWERPC_MASKS | MASK_NEW_MNEMONICS},
186 {"powerpc", PROCESSOR_POWERPC,
187 MASK_POWERPC | MASK_NEW_MNEMONICS,
188 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
189 {"rios", PROCESSOR_RIOS1,
190 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
191 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
192 {"rios1", PROCESSOR_RIOS1,
193 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
194 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
195 {"rsc", PROCESSOR_PPC601,
196 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
197 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
198 {"rsc1", PROCESSOR_PPC601,
199 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
200 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
201 {"rios2", PROCESSOR_RIOS2,
202 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
203 POWERPC_MASKS | MASK_NEW_MNEMONICS},
204 {"403", PROCESSOR_PPC403,
205 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
206 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
207 {"505", PROCESSOR_MPCCORE,
208 MASK_POWERPC | MASK_NEW_MNEMONICS,
209 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
210 {"601", PROCESSOR_PPC601,
211 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
212 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
213 {"602", PROCESSOR_PPC603,
214 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
215 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
216 {"603", PROCESSOR_PPC603,
217 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
218 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
219 {"603e", PROCESSOR_PPC603,
220 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
221 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
222 {"604", PROCESSOR_PPC604,
223 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
224 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
225 {"604e", PROCESSOR_PPC604,
226 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
227 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
228 {"620", PROCESSOR_PPC620,
229 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
230 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
231 {"801", PROCESSOR_MPCCORE,
232 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
233 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
234 {"821", PROCESSOR_MPCCORE,
235 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
236 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
237 {"823", PROCESSOR_MPCCORE,
238 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
239 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
240 {"860", PROCESSOR_MPCCORE,
241 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
242 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
244 int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
246 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
247 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
249 profile_block_flag = 0;
251 /* Identify the processor type */
252 rs6000_select[0].string = default_cpu;
253 rs6000_cpu = PROCESSOR_DEFAULT;
255 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
257 ptr = &rs6000_select[i];
258 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
260 for (j = 0; j < ptt_size; j++)
261 if (! strcmp (ptr->string, processor_target_table[j].name))
263 if (ptr->set_tune_p)
264 rs6000_cpu = processor_target_table[j].processor;
266 if (ptr->set_arch_p)
268 target_flags |= processor_target_table[j].target_enable;
269 target_flags &= ~processor_target_table[j].target_disable;
271 break;
274 if (i == ptt_size)
275 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
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;
284 /* If -mstring or -mno-string was explicitly used, don't
285 override with the processor default */
286 if (TARGET_STRING_SET)
287 target_flags = (target_flags & ~MASK_STRING) | string;
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)
293 if (TARGET_MULTIPLE)
295 target_flags &= ~MASK_MULTIPLE;
296 if (TARGET_MULTIPLE_SET)
297 warning ("-mmultiple is not supported on little endian systems");
300 if (TARGET_STRING)
302 target_flags &= ~MASK_STRING;
303 if (TARGET_STRING_SET)
304 warning ("-mstring is not supported on little endian systems");
308 /* Set debug flags */
309 if (rs6000_debug_name)
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);
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
328 #ifdef SUBTARGET_OVERRIDE_OPTIONS
329 SUBTARGET_OVERRIDE_OPTIONS;
330 #endif
333 /* Do anything needed at the start of the asm file. */
335 void
336 rs6000_file_start (file, default_cpu)
337 FILE *file;
338 char *default_cpu;
340 int i;
341 char buffer[80];
342 char *start = buffer;
343 struct rs6000_cpu_select *ptr;
345 if (flag_verbose_asm)
347 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
348 rs6000_select[0].string = default_cpu;
350 for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
352 ptr = &rs6000_select[i];
353 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
355 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
356 start = "";
360 #ifdef USING_SVR4_H
361 switch (rs6000_sdata)
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;
369 if (rs6000_sdata && g_switch_value)
371 fprintf (file, "%s -G %d", start, g_switch_value);
372 start = "";
374 #endif
376 if (*start == '\0')
377 fputs ("\n", file);
382 /* Create a CONST_DOUBLE from a string. */
384 struct rtx_def *
385 rs6000_float_const (string, mode)
386 char *string;
387 enum machine_mode mode;
389 REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode);
390 return immed_real_const_1 (value, mode);
394 /* Create a CONST_DOUBLE like immed_double_const, except reverse the
395 two parts of the constant if the target is little endian. */
397 struct rtx_def *
398 rs6000_immed_double_const (i0, i1, mode)
399 HOST_WIDE_INT i0, i1;
400 enum machine_mode mode;
402 if (! WORDS_BIG_ENDIAN)
403 return immed_double_const (i1, i0, mode);
405 return immed_double_const (i0, i1, mode);
409 /* Return non-zero if this function is known to have a null epilogue. */
412 direct_return ()
414 if (reload_completed)
416 rs6000_stack_t *info = rs6000_stack_info ();
418 if (info->first_gp_reg_save == 32
419 && info->first_fp_reg_save == 64
420 && !info->lr_save_p
421 && !info->cr_save_p
422 && !info->push_p)
423 return 1;
426 return 0;
429 /* Returns 1 always. */
432 any_operand (op, mode)
433 register rtx op;
434 enum machine_mode mode;
436 return 1;
439 /* Returns 1 if op is the count register */
441 count_register_operand(op, mode)
442 register rtx op;
443 enum machine_mode mode;
445 if (GET_CODE (op) != REG)
446 return 0;
448 if (REGNO (op) == COUNT_REGISTER_REGNUM)
449 return 1;
451 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
452 return 1;
454 return 0;
457 /* Returns 1 if op is memory location for float/int conversions that masquerades
458 as a register. */
460 fpmem_operand(op, mode)
461 register rtx op;
462 enum machine_mode mode;
464 if (GET_CODE (op) != REG)
465 return 0;
467 if (FPMEM_REGNO_P (REGNO (op)))
468 return 1;
470 #if 0
471 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
472 return 1;
473 #endif
475 return 0;
478 /* Return 1 if OP is a constant that can fit in a D field. */
481 short_cint_operand (op, mode)
482 register rtx op;
483 enum machine_mode mode;
485 return (GET_CODE (op) == CONST_INT
486 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) < 0x10000);
489 /* Similar for a unsigned D field. */
492 u_short_cint_operand (op, mode)
493 register rtx op;
494 enum machine_mode mode;
496 return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
499 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
502 non_short_cint_operand (op, mode)
503 register rtx op;
504 enum machine_mode mode;
506 return (GET_CODE (op) == CONST_INT
507 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
510 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
511 ctr, or lr). */
514 gpc_reg_operand (op, mode)
515 register rtx op;
516 enum machine_mode mode;
518 return (register_operand (op, mode)
519 && (GET_CODE (op) != REG
520 || (REGNO (op) >= 67 && !FPMEM_REGNO_P (REGNO (op)))
521 || REGNO (op) < 64));
524 /* Returns 1 if OP is either a pseudo-register or a register denoting a
525 CR field. */
528 cc_reg_operand (op, mode)
529 register rtx op;
530 enum machine_mode mode;
532 return (register_operand (op, mode)
533 && (GET_CODE (op) != REG
534 || REGNO (op) >= FIRST_PSEUDO_REGISTER
535 || CR_REGNO_P (REGNO (op))));
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. */
543 reg_or_short_operand (op, mode)
544 register rtx op;
545 enum machine_mode mode;
547 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
550 /* Similar, except check if the negation of the constant would be valid for
551 a D-field. */
554 reg_or_neg_short_operand (op, mode)
555 register rtx op;
556 enum machine_mode mode;
558 if (GET_CODE (op) == CONST_INT)
559 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
561 return gpc_reg_operand (op, mode);
564 /* Return 1 if the operand is either a register or an integer whose high-order
565 16 bits are zero. */
568 reg_or_u_short_operand (op, mode)
569 register rtx op;
570 enum machine_mode mode;
572 if (GET_CODE (op) == CONST_INT
573 && (INTVAL (op) & 0xffff0000) == 0)
574 return 1;
576 return gpc_reg_operand (op, mode);
579 /* Return 1 is the operand is either a non-special register or ANY
580 constant integer. */
583 reg_or_cint_operand (op, mode)
584 register rtx op;
585 enum machine_mode mode;
587 return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
590 /* Return 1 if the operand is an operand that can be loaded via the GOT */
593 got_operand (op, mode)
594 register rtx op;
595 enum machine_mode mode;
597 return (GET_CODE (op) == SYMBOL_REF
598 || GET_CODE (op) == CONST
599 || GET_CODE (op) == LABEL_REF);
602 /* Return 1 if the operand is a simple references that can be loaded via
603 the GOT (labels involving addition aren't allowed). */
606 got_no_const_operand (op, mode)
607 register rtx op;
608 enum machine_mode mode;
610 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
613 /* Return the number of instructions it takes to form a constant in an
614 integer register. */
616 static int
617 num_insns_constant_wide (value)
618 HOST_WIDE_INT value;
620 /* signed constant loadable with {cal|addi} */
621 if (((unsigned HOST_WIDE_INT)value + 0x8000) < 0x10000)
622 return 1;
624 #if HOST_BITS_PER_WIDE_INT == 32
625 /* constant loadable with {cau|addis} */
626 else if ((value & 0xffff) == 0)
627 return 1;
629 #else
630 /* constant loadable with {cau|addis} */
631 else if ((value & 0xffff) == 0 && (value & ~0xffffffff) == 0)
632 return 1;
634 else if (TARGET_64BIT)
636 HOST_WIDE_INT low = value & 0xffffffff;
637 HOST_WIDE_INT high = value >> 32;
639 if (high == 0 && (low & 0x80000000) == 0)
640 return 2;
642 else if (high == 0xffffffff && (low & 0x80000000) != 0)
643 return 2;
645 else if (!low)
646 return num_insns_constant_wide (high) + 1;
648 else
649 return (num_insns_constant_wide (high)
650 + num_insns_constant_wide (low) + 1);
652 #endif
654 else
655 return 2;
659 num_insns_constant (op, mode)
660 rtx op;
661 enum machine_mode mode;
663 if (GET_CODE (op) == CONST_INT)
664 return num_insns_constant_wide (INTVAL (op));
666 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
668 long l;
669 REAL_VALUE_TYPE rv;
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);
676 else if (GET_CODE (op) == CONST_DOUBLE && TARGET_32BIT)
677 return (num_insns_constant_wide (CONST_DOUBLE_LOW (op))
678 + num_insns_constant_wide (CONST_DOUBLE_HIGH (op)));
680 else if (GET_CODE (op) == CONST_DOUBLE && TARGET_64BIT)
682 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
683 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
685 if (high == 0 && (low & 0x80000000) == 0)
686 return num_insns_constant_wide (low);
688 else if (((high & 0xffffffff) == 0xffffffff)
689 && ((low & 0x80000000) != 0))
690 return num_insns_constant_wide (low);
692 else if (low == 0)
693 return num_insns_constant_wide (high) + 1;
695 else
696 return (num_insns_constant_wide (high)
697 + num_insns_constant_wide (low) + 1);
700 else
701 abort ();
704 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
705 with one instruction per word. We only do this if we can safely read
706 CONST_DOUBLE_{LOW,HIGH}. */
709 easy_fp_constant (op, mode)
710 register rtx op;
711 register enum machine_mode mode;
713 if (GET_CODE (op) != CONST_DOUBLE
714 || GET_MODE (op) != mode
715 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
716 return 0;
718 /* Consider all constants with -msoft-float to be easy */
719 if (TARGET_SOFT_FLOAT && mode != DImode)
720 return 1;
722 /* If we are using V.4 style PIC, consider all constants to be hard */
723 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
724 return 0;
726 #ifdef TARGET_RELOCATABLE
727 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
728 if (TARGET_RELOCATABLE)
729 return 0;
730 #endif
732 if (mode == DFmode)
734 long k[2];
735 REAL_VALUE_TYPE rv;
737 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
738 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
740 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
741 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
744 else if (mode == SFmode)
746 long l;
747 REAL_VALUE_TYPE rv;
749 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
750 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
752 return num_insns_constant_wide (l) == 1;
755 else if (mode == DImode && TARGET_32BIT)
756 return num_insns_constant (op, DImode) == 2;
758 else
759 abort ();
762 /* Return 1 if the operand is in volatile memory. Note that during the
763 RTL generation phase, memory_operand does not return TRUE for
764 volatile memory references. So this function allows us to
765 recognize volatile references where its safe. */
768 volatile_mem_operand (op, mode)
769 register rtx op;
770 enum machine_mode mode;
772 if (GET_CODE (op) != MEM)
773 return 0;
775 if (!MEM_VOLATILE_P (op))
776 return 0;
778 if (mode != GET_MODE (op))
779 return 0;
781 if (reload_completed)
782 return memory_operand (op, mode);
784 if (reload_in_progress)
785 return strict_memory_address_p (mode, XEXP (op, 0));
787 return memory_address_p (mode, XEXP (op, 0));
790 /* Return 1 if the operand is an offsettable memory address. */
793 offsettable_addr_operand (op, mode)
794 register rtx op;
795 enum machine_mode mode;
797 return offsettable_address_p (reload_completed | reload_in_progress,
798 mode, op);
801 /* Return 1 if the operand is either an easy FP constant (see above) or
802 memory. */
805 mem_or_easy_const_operand (op, mode)
806 register rtx op;
807 enum machine_mode mode;
809 return memory_operand (op, mode) || easy_fp_constant (op, mode);
812 /* Return 1 if the operand is either a non-special register or an item
813 that can be used as the operand of an SI add insn. */
816 add_operand (op, mode)
817 register rtx op;
818 enum machine_mode mode;
820 return (reg_or_short_operand (op, mode)
821 || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
824 /* Return 1 if OP is a constant but not a valid add_operand. */
827 non_add_cint_operand (op, mode)
828 register rtx op;
829 enum machine_mode mode;
831 return (GET_CODE (op) == CONST_INT
832 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
833 && (INTVAL (op) & 0xffff) != 0);
836 /* Return 1 if the operand is a non-special register or a constant that
837 can be used as the operand of an OR or XOR insn on the RS/6000. */
840 logical_operand (op, mode)
841 register rtx op;
842 enum machine_mode mode;
844 return (gpc_reg_operand (op, mode)
845 || (GET_CODE (op) == CONST_INT
846 && ((INTVAL (op) & 0xffff0000) == 0
847 || (INTVAL (op) & 0xffff) == 0)));
850 /* Return 1 if C is a constant that is not a logical operand (as
851 above). */
854 non_logical_cint_operand (op, mode)
855 register rtx op;
856 enum machine_mode mode;
858 return (GET_CODE (op) == CONST_INT
859 && (INTVAL (op) & 0xffff0000) != 0
860 && (INTVAL (op) & 0xffff) != 0);
863 /* Return 1 if C is a constant that can be encoded in a mask on the
864 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
865 Reject all ones and all zeros, since these should have been optimized
866 away and confuse the making of MB and ME. */
869 mask_constant (c)
870 register int c;
872 int i;
873 int last_bit_value;
874 int transitions = 0;
876 if (c == 0 || c == ~0)
877 return 0;
879 last_bit_value = c & 1;
881 for (i = 1; i < 32; i++)
882 if (((c >>= 1) & 1) != last_bit_value)
883 last_bit_value ^= 1, transitions++;
885 return transitions <= 2;
888 /* Return 1 if the operand is a constant that is a mask on the RS/6000. */
891 mask_operand (op, mode)
892 register rtx op;
893 enum machine_mode mode;
895 return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
898 /* Return 1 if the operand is either a non-special register or a
899 constant that can be used as the operand of an RS/6000 logical AND insn. */
902 and_operand (op, mode)
903 register rtx op;
904 enum machine_mode mode;
906 return (logical_operand (op, mode)
907 || mask_operand (op, mode));
910 /* Return 1 if the operand is a constant but not a valid operand for an AND
911 insn. */
914 non_and_cint_operand (op, mode)
915 register rtx op;
916 enum machine_mode mode;
918 return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
921 /* Return 1 if the operand is a general register or memory operand. */
924 reg_or_mem_operand (op, mode)
925 register rtx op;
926 register enum machine_mode mode;
928 return (gpc_reg_operand (op, mode)
929 || memory_operand (op, mode)
930 || volatile_mem_operand (op, mode));
933 /* Return 1 if the operand is a general register or memory operand without
934 pre-inc or pre_dec which produces invalid form of PowerPC lwa
935 instruction. */
938 lwa_operand (op, mode)
939 register rtx op;
940 register enum machine_mode mode;
942 rtx inner = op;
944 if (reload_completed && GET_CODE (inner) == SUBREG)
945 inner = SUBREG_REG (inner);
947 return gpc_reg_operand (inner, mode)
948 || (memory_operand (inner, mode)
949 && GET_CODE (XEXP (inner, 0)) != PRE_INC
950 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
953 /* Return 1 if the operand, used inside a MEM, is a valid first argument
954 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
955 forced to lr. */
958 call_operand (op, mode)
959 register rtx op;
960 enum machine_mode mode;
962 if (mode != VOIDmode && GET_MODE (op) != mode)
963 return 0;
965 return (GET_CODE (op) == SYMBOL_REF
966 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
970 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
971 this file. */
974 current_file_function_operand (op, mode)
975 register rtx op;
976 enum machine_mode mode;
978 return (GET_CODE (op) == SYMBOL_REF
979 && (SYMBOL_REF_FLAG (op)
980 || op == XEXP (DECL_RTL (current_function_decl), 0)));
984 /* Return 1 if this operand is a valid input for a move insn. */
987 input_operand (op, mode)
988 register rtx op;
989 enum machine_mode mode;
991 /* Memory is always valid. */
992 if (memory_operand (op, mode))
993 return 1;
995 /* For floating-point, easy constants are valid. */
996 if (GET_MODE_CLASS (mode) == MODE_FLOAT
997 && CONSTANT_P (op)
998 && easy_fp_constant (op, mode))
999 return 1;
1001 /* Allow any integer constant. */
1002 if (GET_MODE_CLASS (mode) == MODE_INT
1003 && (GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE))
1004 return 1;
1006 /* For floating-point or multi-word mode, the only remaining valid type
1007 is a register. */
1008 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1009 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1010 return register_operand (op, mode);
1012 /* The only cases left are integral modes one word or smaller (we
1013 do not get called for MODE_CC values). These can be in any
1014 register. */
1015 if (register_operand (op, mode))
1016 return 1;
1018 /* A SYMBOL_REF referring to the TOC is valid. */
1019 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
1020 return 1;
1022 /* Windows NT allows SYMBOL_REFs and LABEL_REFs against the TOC
1023 directly in the instruction stream */
1024 if (DEFAULT_ABI == ABI_NT
1025 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF))
1026 return 1;
1028 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1029 to be valid. */
1030 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1031 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1032 && small_data_operand (op, Pmode))
1033 return 1;
1035 return 0;
1038 /* Return 1 for an operand in small memory on V.4/eabi */
1041 small_data_operand (op, mode)
1042 rtx op;
1043 enum machine_mode mode;
1045 #if TARGET_ELF
1046 rtx sym_ref, const_part;
1048 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
1049 return 0;
1051 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1052 return 0;
1054 if (GET_CODE (op) == SYMBOL_REF)
1055 sym_ref = op;
1057 else if (GET_CODE (op) != CONST
1058 || GET_CODE (XEXP (op, 0)) != PLUS
1059 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1060 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
1061 return 0;
1063 else
1064 sym_ref = XEXP (XEXP (op, 0), 0);
1066 if (*XSTR (sym_ref, 0) != '@')
1067 return 0;
1069 return 1;
1071 #else
1072 return 0;
1073 #endif
1077 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1078 for a call to a function whose data type is FNTYPE.
1079 For a library call, FNTYPE is 0.
1081 For incoming args we set the number of arguments in the prototype large
1082 so we never return a PARALLEL. */
1084 void
1085 init_cumulative_args (cum, fntype, libname, incoming)
1086 CUMULATIVE_ARGS *cum;
1087 tree fntype;
1088 rtx libname;
1089 int incoming;
1091 static CUMULATIVE_ARGS zero_cumulative;
1092 enum rs6000_abi abi = DEFAULT_ABI;
1094 *cum = zero_cumulative;
1095 cum->words = 0;
1096 cum->fregno = FP_ARG_MIN_REG;
1097 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
1098 cum->call_cookie = CALL_NORMAL;
1100 if (incoming)
1102 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
1103 if (abi == ABI_V4 || abi == ABI_SOLARIS)
1104 cum->varargs_offset = RS6000_VARARGS_OFFSET;
1107 else if (cum->prototype)
1108 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1109 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1110 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1112 else
1113 cum->nargs_prototype = 0;
1115 cum->orig_nargs = cum->nargs_prototype;
1117 /* Check for DLL import functions */
1118 if (abi == ABI_NT
1119 && fntype
1120 && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (fntype)))
1121 cum->call_cookie = CALL_NT_DLLIMPORT;
1123 /* Also check for longcall's */
1124 else if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
1125 cum->call_cookie = CALL_LONG;
1127 if (TARGET_DEBUG_ARG)
1129 fprintf (stderr, "\ninit_cumulative_args:");
1130 if (fntype)
1132 tree ret_type = TREE_TYPE (fntype);
1133 fprintf (stderr, " ret code = %s,",
1134 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1137 if ((abi == ABI_V4 || abi == ABI_SOLARIS) && incoming)
1138 fprintf (stderr, " varargs = %d, ", cum->varargs_offset);
1140 if (cum->call_cookie & CALL_NT_DLLIMPORT)
1141 fprintf (stderr, " dllimport,");
1143 if (cum->call_cookie & CALL_LONG)
1144 fprintf (stderr, " longcall,");
1146 fprintf (stderr, " proto = %d, nargs = %d\n",
1147 cum->prototype, cum->nargs_prototype);
1151 /* If defined, a C expression that gives the alignment boundary, in bits,
1152 of an argument with the specified mode and type. If it is not defined,
1153 PARM_BOUNDARY is used for all arguments.
1155 Windows NT wants anything >= 8 bytes to be double word aligned.
1157 V.4 wants long longs to be double word aligned. */
1160 function_arg_boundary (mode, type)
1161 enum machine_mode mode;
1162 tree type;
1164 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && mode == DImode)
1165 return 64;
1167 if (DEFAULT_ABI != ABI_NT || TARGET_64BIT)
1168 return PARM_BOUNDARY;
1170 if (mode != BLKmode)
1171 return (GET_MODE_SIZE (mode)) >= 8 ? 64 : 32;
1173 return (int_size_in_bytes (type) >= 8) ? 64 : 32;
1176 /* Update the data in CUM to advance over an argument
1177 of mode MODE and data type TYPE.
1178 (TYPE is null for libcalls where that information may not be available.) */
1180 void
1181 function_arg_advance (cum, mode, type, named)
1182 CUMULATIVE_ARGS *cum;
1183 enum machine_mode mode;
1184 tree type;
1185 int named;
1187 int align = ((cum->words & 1) != 0 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
1188 cum->words += align;
1189 cum->nargs_prototype--;
1191 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1193 /* Long longs must not be split between registers and stack */
1194 if ((GET_MODE_CLASS (mode) != MODE_FLOAT || TARGET_SOFT_FLOAT)
1195 && type && !AGGREGATE_TYPE_P (type)
1196 && cum->words < GP_ARG_NUM_REG
1197 && cum->words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
1199 cum->words = GP_ARG_NUM_REG;
1202 /* Aggregates get passed as pointers */
1203 if (type && AGGREGATE_TYPE_P (type))
1204 cum->words++;
1206 /* Floats go in registers, & don't occupy space in the GP registers
1207 like they do for AIX unless software floating point. */
1208 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
1209 && TARGET_HARD_FLOAT
1210 && cum->fregno <= FP_ARG_V4_MAX_REG)
1211 cum->fregno++;
1213 else
1214 cum->words += RS6000_ARG_SIZE (mode, type, 1);
1216 else
1217 if (named)
1219 cum->words += RS6000_ARG_SIZE (mode, type, named);
1220 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
1221 cum->fregno++;
1224 if (TARGET_DEBUG_ARG)
1225 fprintf (stderr,
1226 "function_adv: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
1227 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
1230 /* Determine where to put an argument to a function.
1231 Value is zero to push the argument on the stack,
1232 or a hard register in which to store the argument.
1234 MODE is the argument's machine mode.
1235 TYPE is the data type of the argument (as a tree).
1236 This is null for libcalls where that information may
1237 not be available.
1238 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1239 the preceding args and about the function being called.
1240 NAMED is nonzero if this argument is a named parameter
1241 (otherwise it is an extra parameter matching an ellipsis).
1243 On RS/6000 the first eight words of non-FP are normally in registers
1244 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
1245 Under V.4, the first 8 FP args are in registers.
1247 If this is floating-point and no prototype is specified, we use
1248 both an FP and integer register (or possibly FP reg and stack). Library
1249 functions (when TYPE is zero) always have the proper types for args,
1250 so we can pass the FP value just in one register. emit_library_function
1251 doesn't support PARALLEL anyway. */
1253 struct rtx_def *
1254 function_arg (cum, mode, type, named)
1255 CUMULATIVE_ARGS *cum;
1256 enum machine_mode mode;
1257 tree type;
1258 int named;
1260 int align = ((cum->words & 1) != 0 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
1261 int align_words = cum->words + align;
1263 if (TARGET_DEBUG_ARG)
1264 fprintf (stderr,
1265 "function_arg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
1266 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
1268 /* Return a marker to indicate whether CR1 needs to set or clear the bit that V.4
1269 uses to say fp args were passed in registers. Assume that we don't need the
1270 marker for software floating point, or compiler generated library calls. */
1271 if (mode == VOIDmode)
1273 enum rs6000_abi abi = DEFAULT_ABI;
1275 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
1276 && TARGET_HARD_FLOAT
1277 && cum->nargs_prototype < 0
1278 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
1280 return GEN_INT (cum->call_cookie
1281 | ((cum->fregno == FP_ARG_MIN_REG)
1282 ? CALL_V4_SET_FP_ARGS
1283 : CALL_V4_CLEAR_FP_ARGS));
1286 return GEN_INT (cum->call_cookie);
1289 if (!named)
1291 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1292 return NULL_RTX;
1295 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1296 return NULL_RTX;
1298 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1300 if (DEFAULT_ABI == ABI_V4 /* V.4 never passes FP values in GP registers */
1301 || DEFAULT_ABI == ABI_SOLARIS
1302 || ! type
1303 || ((cum->nargs_prototype > 0)
1304 /* IBM AIX extended its linkage convention definition always to
1305 require FP args after register save area hole on the stack. */
1306 && (DEFAULT_ABI != ABI_AIX
1307 || ! TARGET_XL_CALL
1308 || (align_words < GP_ARG_NUM_REG))))
1309 return gen_rtx (REG, mode, cum->fregno);
1311 return gen_rtx (PARALLEL, mode,
1312 gen_rtvec
1314 gen_rtx (EXPR_LIST, VOIDmode,
1315 ((align_words >= GP_ARG_NUM_REG)
1316 ? NULL_RTX
1317 : (align_words
1318 + RS6000_ARG_SIZE (mode, type, named)
1319 > GP_ARG_NUM_REG
1320 /* If this is partially on the stack, then
1321 we only include the portion actually
1322 in registers here. */
1323 ? gen_rtx (REG, SImode,
1324 GP_ARG_MIN_REG + align_words)
1325 : gen_rtx (REG, mode,
1326 GP_ARG_MIN_REG + align_words))),
1327 const0_rtx),
1328 gen_rtx (EXPR_LIST, VOIDmode,
1329 gen_rtx (REG, mode, cum->fregno),
1330 const0_rtx)));
1333 /* Long longs won't be split between register and stack */
1334 else if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) &&
1335 align_words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
1337 return NULL_RTX;
1340 else if (align_words < GP_ARG_NUM_REG)
1341 return gen_rtx (REG, mode, GP_ARG_MIN_REG + align_words);
1343 return NULL_RTX;
1346 /* For an arg passed partly in registers and partly in memory,
1347 this is the number of registers used.
1348 For args passed entirely in registers or entirely in memory, zero. */
1351 function_arg_partial_nregs (cum, mode, type, named)
1352 CUMULATIVE_ARGS *cum;
1353 enum machine_mode mode;
1354 tree type;
1355 int named;
1357 if (! named)
1358 return 0;
1360 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1361 return 0;
1363 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1365 if (cum->nargs_prototype >= 0)
1366 return 0;
1369 if (cum->words < GP_ARG_NUM_REG
1370 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named)))
1372 int ret = GP_ARG_NUM_REG - cum->words;
1373 if (ret && TARGET_DEBUG_ARG)
1374 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
1376 return ret;
1379 return 0;
1382 /* A C expression that indicates when an argument must be passed by
1383 reference. If nonzero for an argument, a copy of that argument is
1384 made in memory and a pointer to the argument is passed instead of
1385 the argument itself. The pointer is passed in whatever way is
1386 appropriate for passing a pointer to that type.
1388 Under V.4, structures and unions are passed by reference. */
1391 function_arg_pass_by_reference (cum, mode, type, named)
1392 CUMULATIVE_ARGS *cum;
1393 enum machine_mode mode;
1394 tree type;
1395 int named;
1397 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1398 && type && AGGREGATE_TYPE_P (type))
1400 if (TARGET_DEBUG_ARG)
1401 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
1403 return 1;
1406 return 0;
1410 /* Perform any needed actions needed for a function that is receiving a
1411 variable number of arguments.
1413 CUM is as above.
1415 MODE and TYPE are the mode and type of the current parameter.
1417 PRETEND_SIZE is a variable that should be set to the amount of stack
1418 that must be pushed by the prolog to pretend that our caller pushed
1421 Normally, this macro will push all remaining incoming registers on the
1422 stack and set PRETEND_SIZE to the length of the registers pushed. */
1424 void
1425 setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
1426 CUMULATIVE_ARGS *cum;
1427 enum machine_mode mode;
1428 tree type;
1429 int *pretend_size;
1430 int no_rtl;
1433 rtx save_area = virtual_incoming_args_rtx;
1434 int reg_size = (TARGET_64BIT) ? 8 : 4;
1436 if (TARGET_DEBUG_ARG)
1437 fprintf (stderr,
1438 "setup_vararg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, no_rtl= %d\n",
1439 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), no_rtl);
1441 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && !no_rtl)
1443 rs6000_sysv_varargs_p = 1;
1444 save_area = plus_constant (frame_pointer_rtx, RS6000_VARARGS_OFFSET);
1447 if (cum->words < 8)
1449 int first_reg_offset = cum->words;
1451 if (MUST_PASS_IN_STACK (mode, type))
1452 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1);
1454 if (first_reg_offset > GP_ARG_NUM_REG)
1455 first_reg_offset = GP_ARG_NUM_REG;
1457 if (!no_rtl && first_reg_offset != GP_ARG_NUM_REG)
1458 move_block_from_reg
1459 (GP_ARG_MIN_REG + first_reg_offset,
1460 gen_rtx (MEM, BLKmode,
1461 plus_constant (save_area, first_reg_offset * reg_size)),
1462 GP_ARG_NUM_REG - first_reg_offset,
1463 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
1465 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
1468 /* Save FP registers if needed. */
1469 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && TARGET_HARD_FLOAT && !no_rtl)
1471 int fregno = cum->fregno;
1472 int num_fp_reg = FP_ARG_V4_MAX_REG + 1 - fregno;
1474 if (num_fp_reg >= 0)
1476 rtx cr1 = gen_rtx (REG, CCmode, 69);
1477 rtx lab = gen_label_rtx ();
1478 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
1480 emit_jump_insn (gen_rtx (SET, VOIDmode,
1481 pc_rtx,
1482 gen_rtx (IF_THEN_ELSE, VOIDmode,
1483 gen_rtx (NE, VOIDmode, cr1, const0_rtx),
1484 gen_rtx (LABEL_REF, VOIDmode, lab),
1485 pc_rtx)));
1487 while ( num_fp_reg-- >= 0)
1489 emit_move_insn (gen_rtx (MEM, DFmode, plus_constant (save_area, off)),
1490 gen_rtx (REG, DFmode, fregno++));
1491 off += 8;
1494 emit_label (lab);
1499 /* If defined, is a C expression that produces the machine-specific
1500 code for a call to `__builtin_saveregs'. This code will be moved
1501 to the very beginning of the function, before any parameter access
1502 are made. The return value of this function should be an RTX that
1503 contains the value to use as the return of `__builtin_saveregs'.
1505 The argument ARGS is a `tree_list' containing the arguments that
1506 were passed to `__builtin_saveregs'.
1508 If this macro is not defined, the compiler will output an ordinary
1509 call to the library function `__builtin_saveregs'.
1511 On the Power/PowerPC return the address of the area on the stack
1512 used to hold arguments. Under AIX, this includes the 8 word register
1513 save area. Under V.4 this does not. */
1515 struct rtx_def *
1516 expand_builtin_saveregs (args)
1517 tree args;
1519 return virtual_incoming_args_rtx;
1523 /* Generate a memory reference for expand_block_move, copying volatile,
1524 and other bits from an original memory reference. */
1526 static rtx
1527 expand_block_move_mem (mode, addr, orig_mem)
1528 enum machine_mode mode;
1529 rtx addr;
1530 rtx orig_mem;
1532 rtx mem = gen_rtx (MEM, mode, addr);
1534 RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (orig_mem);
1535 MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (orig_mem);
1536 MEM_IN_STRUCT_P (mem) = MEM_IN_STRUCT_P (orig_mem);
1537 #ifdef MEM_UNALIGNED_P
1538 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
1539 #endif
1540 return mem;
1543 /* Expand a block move operation, and return 1 if successful. Return 0
1544 if we should let the compiler generate normal code.
1546 operands[0] is the destination
1547 operands[1] is the source
1548 operands[2] is the length
1549 operands[3] is the alignment */
1551 #define MAX_MOVE_REG 4
1554 expand_block_move (operands)
1555 rtx operands[];
1557 rtx orig_dest = operands[0];
1558 rtx orig_src = operands[1];
1559 rtx bytes_rtx = operands[2];
1560 rtx align_rtx = operands[3];
1561 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
1562 int align = XINT (align_rtx, 0);
1563 int bytes;
1564 int offset;
1565 int num_reg;
1566 int i;
1567 rtx src_reg;
1568 rtx dest_reg;
1569 rtx src_addr;
1570 rtx dest_addr;
1571 rtx tmp_reg;
1572 rtx stores[MAX_MOVE_REG];
1573 int move_bytes;
1575 /* If this is not a fixed size move, just call memcpy */
1576 if (!constp)
1577 return 0;
1579 /* Anything to move? */
1580 bytes = INTVAL (bytes_rtx);
1581 if (bytes <= 0)
1582 return 1;
1584 /* Don't support real large moves. If string instructions are not used,
1585 then don't generate more than 8 loads. */
1586 if (TARGET_STRING)
1588 if (bytes > 4*8)
1589 return 0;
1591 else if (!STRICT_ALIGNMENT)
1593 if (bytes > 4*8)
1594 return 0;
1596 else if (bytes > 8*align)
1597 return 0;
1599 /* Move the address into scratch registers. */
1600 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
1601 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
1603 if (TARGET_STRING) /* string instructions are available */
1605 for ( ; bytes > 0; bytes -= move_bytes)
1607 if (bytes > 24 /* move up to 32 bytes at a time */
1608 && !fixed_regs[5]
1609 && !fixed_regs[6]
1610 && !fixed_regs[7]
1611 && !fixed_regs[8]
1612 && !fixed_regs[9]
1613 && !fixed_regs[10]
1614 && !fixed_regs[11]
1615 && !fixed_regs[12])
1617 move_bytes = (bytes > 32) ? 32 : bytes;
1618 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1619 expand_block_move_mem (BLKmode, src_reg, orig_src),
1620 GEN_INT ((move_bytes == 32) ? 0 : move_bytes),
1621 align_rtx));
1623 else if (bytes > 16 /* move up to 24 bytes at a time */
1624 && !fixed_regs[7]
1625 && !fixed_regs[8]
1626 && !fixed_regs[9]
1627 && !fixed_regs[10]
1628 && !fixed_regs[11]
1629 && !fixed_regs[12])
1631 move_bytes = (bytes > 24) ? 24 : bytes;
1632 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1633 expand_block_move_mem (BLKmode, src_reg, orig_src),
1634 GEN_INT (move_bytes),
1635 align_rtx));
1637 else if (bytes > 8 /* move up to 16 bytes at a time */
1638 && !fixed_regs[9]
1639 && !fixed_regs[10]
1640 && !fixed_regs[11]
1641 && !fixed_regs[12])
1643 move_bytes = (bytes > 16) ? 16 : bytes;
1644 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1645 expand_block_move_mem (BLKmode, src_reg, orig_src),
1646 GEN_INT (move_bytes),
1647 align_rtx));
1649 else if (bytes > 4 && !TARGET_64BIT)
1650 { /* move up to 8 bytes at a time */
1651 move_bytes = (bytes > 8) ? 8 : bytes;
1652 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1653 expand_block_move_mem (BLKmode, src_reg, orig_src),
1654 GEN_INT (move_bytes),
1655 align_rtx));
1657 else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
1658 { /* move 4 bytes */
1659 move_bytes = 4;
1660 tmp_reg = gen_reg_rtx (SImode);
1661 emit_move_insn (tmp_reg, expand_block_move_mem (SImode, src_reg, orig_src));
1662 emit_move_insn (expand_block_move_mem (SImode, dest_reg, orig_dest), tmp_reg);
1664 else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT))
1665 { /* move 2 bytes */
1666 move_bytes = 2;
1667 tmp_reg = gen_reg_rtx (HImode);
1668 emit_move_insn (tmp_reg, expand_block_move_mem (HImode, src_reg, orig_src));
1669 emit_move_insn (expand_block_move_mem (HImode, dest_reg, orig_dest), tmp_reg);
1671 else if (bytes == 1) /* move 1 byte */
1673 move_bytes = 1;
1674 tmp_reg = gen_reg_rtx (QImode);
1675 emit_move_insn (tmp_reg, expand_block_move_mem (QImode, src_reg, orig_src));
1676 emit_move_insn (expand_block_move_mem (QImode, dest_reg, orig_dest), tmp_reg);
1678 else
1679 { /* move up to 4 bytes at a time */
1680 move_bytes = (bytes > 4) ? 4 : bytes;
1681 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1682 expand_block_move_mem (BLKmode, src_reg, orig_src),
1683 GEN_INT (move_bytes),
1684 align_rtx));
1687 if (bytes > move_bytes)
1689 emit_insn (gen_addsi3 (src_reg, src_reg, GEN_INT (move_bytes)));
1690 emit_insn (gen_addsi3 (dest_reg, dest_reg, GEN_INT (move_bytes)));
1695 else /* string instructions not available */
1697 num_reg = offset = 0;
1698 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
1700 /* Calculate the correct offset for src/dest */
1701 if (offset == 0)
1703 src_addr = src_reg;
1704 dest_addr = dest_reg;
1706 else
1708 src_addr = gen_rtx (PLUS, Pmode, src_reg, GEN_INT (offset));
1709 dest_addr = gen_rtx (PLUS, Pmode, dest_reg, GEN_INT (offset));
1712 /* Generate the appropriate load and store, saving the stores for later */
1713 if (bytes >= 8 && TARGET_64BIT && (align >= 8 || !STRICT_ALIGNMENT))
1715 move_bytes = 8;
1716 tmp_reg = gen_reg_rtx (DImode);
1717 emit_insn (gen_movdi (tmp_reg, expand_block_move_mem (DImode, src_addr, orig_src)));
1718 stores[ num_reg++ ] = gen_movdi (expand_block_move_mem (DImode, dest_addr, orig_dest), tmp_reg);
1720 else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
1722 move_bytes = 4;
1723 tmp_reg = gen_reg_rtx (SImode);
1724 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (SImode, src_addr, orig_src)));
1725 stores[ num_reg++ ] = gen_movsi (expand_block_move_mem (SImode, dest_addr, orig_dest), tmp_reg);
1727 else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT))
1729 move_bytes = 2;
1730 tmp_reg = gen_reg_rtx (HImode);
1731 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (HImode, src_addr, orig_src)));
1732 stores[ num_reg++ ] = gen_movhi (expand_block_move_mem (HImode, dest_addr, orig_dest), tmp_reg);
1734 else
1736 move_bytes = 1;
1737 tmp_reg = gen_reg_rtx (QImode);
1738 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (QImode, src_addr, orig_src)));
1739 stores[ num_reg++ ] = gen_movqi (expand_block_move_mem (QImode, dest_addr, orig_dest), tmp_reg);
1742 if (num_reg >= MAX_MOVE_REG)
1744 for (i = 0; i < num_reg; i++)
1745 emit_insn (stores[i]);
1746 num_reg = 0;
1750 for (i = 0; i < num_reg; i++)
1751 emit_insn (stores[i]);
1754 return 1;
1758 /* Return 1 if OP is a load multiple operation. It is known to be a
1759 PARALLEL and the first section will be tested. */
1762 load_multiple_operation (op, mode)
1763 rtx op;
1764 enum machine_mode mode;
1766 int count = XVECLEN (op, 0);
1767 int dest_regno;
1768 rtx src_addr;
1769 int i;
1771 /* Perform a quick check so we don't blow up below. */
1772 if (count <= 1
1773 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1774 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1775 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1776 return 0;
1778 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1779 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1781 for (i = 1; i < count; i++)
1783 rtx elt = XVECEXP (op, 0, i);
1785 if (GET_CODE (elt) != SET
1786 || GET_CODE (SET_DEST (elt)) != REG
1787 || GET_MODE (SET_DEST (elt)) != SImode
1788 || REGNO (SET_DEST (elt)) != dest_regno + i
1789 || GET_CODE (SET_SRC (elt)) != MEM
1790 || GET_MODE (SET_SRC (elt)) != SImode
1791 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
1792 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
1793 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
1794 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
1795 return 0;
1798 return 1;
1801 /* Similar, but tests for store multiple. Here, the second vector element
1802 is a CLOBBER. It will be tested later. */
1805 store_multiple_operation (op, mode)
1806 rtx op;
1807 enum machine_mode mode;
1809 int count = XVECLEN (op, 0) - 1;
1810 int src_regno;
1811 rtx dest_addr;
1812 int i;
1814 /* Perform a quick check so we don't blow up below. */
1815 if (count <= 1
1816 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1817 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1818 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1819 return 0;
1821 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1822 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1824 for (i = 1; i < count; i++)
1826 rtx elt = XVECEXP (op, 0, i + 1);
1828 if (GET_CODE (elt) != SET
1829 || GET_CODE (SET_SRC (elt)) != REG
1830 || GET_MODE (SET_SRC (elt)) != SImode
1831 || REGNO (SET_SRC (elt)) != src_regno + i
1832 || GET_CODE (SET_DEST (elt)) != MEM
1833 || GET_MODE (SET_DEST (elt)) != SImode
1834 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
1835 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
1836 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
1837 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
1838 return 0;
1841 return 1;
1844 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
1845 We only check the opcode against the mode of the CC value here. */
1848 branch_comparison_operator (op, mode)
1849 register rtx op;
1850 enum machine_mode mode;
1852 enum rtx_code code = GET_CODE (op);
1853 enum machine_mode cc_mode;
1855 if (GET_RTX_CLASS (code) != '<')
1856 return 0;
1858 cc_mode = GET_MODE (XEXP (op, 0));
1859 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
1860 return 0;
1862 if ((code == GT || code == LT || code == GE || code == LE)
1863 && cc_mode == CCUNSmode)
1864 return 0;
1866 if ((code == GTU || code == LTU || code == GEU || code == LEU)
1867 && (cc_mode != CCUNSmode))
1868 return 0;
1870 return 1;
1873 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
1874 We check the opcode against the mode of the CC value and disallow EQ or
1875 NE comparisons for integers. */
1878 scc_comparison_operator (op, mode)
1879 register rtx op;
1880 enum machine_mode mode;
1882 enum rtx_code code = GET_CODE (op);
1883 enum machine_mode cc_mode;
1885 if (GET_MODE (op) != mode && mode != VOIDmode)
1886 return 0;
1888 if (GET_RTX_CLASS (code) != '<')
1889 return 0;
1891 cc_mode = GET_MODE (XEXP (op, 0));
1892 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
1893 return 0;
1895 if (code == NE && cc_mode != CCFPmode)
1896 return 0;
1898 if ((code == GT || code == LT || code == GE || code == LE)
1899 && cc_mode == CCUNSmode)
1900 return 0;
1902 if ((code == GTU || code == LTU || code == GEU || code == LEU)
1903 && (cc_mode != CCUNSmode))
1904 return 0;
1906 if (cc_mode == CCEQmode && code != EQ && code != NE)
1907 return 0;
1909 return 1;
1912 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
1913 mask required to convert the result of a rotate insn into a shift
1914 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
1917 includes_lshift_p (shiftop, andop)
1918 register rtx shiftop;
1919 register rtx andop;
1921 int shift_mask = (~0 << INTVAL (shiftop));
1923 return (INTVAL (andop) & ~shift_mask) == 0;
1926 /* Similar, but for right shift. */
1929 includes_rshift_p (shiftop, andop)
1930 register rtx shiftop;
1931 register rtx andop;
1933 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
1935 shift_mask >>= INTVAL (shiftop);
1937 return (INTVAL (andop) & ~ shift_mask) == 0;
1940 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
1941 for lfq and stfq insns.
1943 Note reg1 and reg2 *must* be hard registers. To be sure we will
1944 abort if we are passed pseudo registers. */
1947 registers_ok_for_quad_peep (reg1, reg2)
1948 rtx reg1, reg2;
1950 /* We might have been passed a SUBREG. */
1951 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
1952 return 0;
1954 return (REGNO (reg1) == REGNO (reg2) - 1);
1957 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
1958 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
1961 addrs_ok_for_quad_peep (addr1, addr2)
1962 register rtx addr1;
1963 register rtx addr2;
1965 int reg1;
1966 int offset1;
1968 /* Extract an offset (if used) from the first addr. */
1969 if (GET_CODE (addr1) == PLUS)
1971 /* If not a REG, return zero. */
1972 if (GET_CODE (XEXP (addr1, 0)) != REG)
1973 return 0;
1974 else
1976 reg1 = REGNO (XEXP (addr1, 0));
1977 /* The offset must be constant! */
1978 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
1979 return 0;
1980 offset1 = INTVAL (XEXP (addr1, 1));
1983 else if (GET_CODE (addr1) != REG)
1984 return 0;
1985 else
1987 reg1 = REGNO (addr1);
1988 /* This was a simple (mem (reg)) expression. Offset is 0. */
1989 offset1 = 0;
1992 /* Make sure the second address is a (mem (plus (reg) (const_int). */
1993 if (GET_CODE (addr2) != PLUS)
1994 return 0;
1996 if (GET_CODE (XEXP (addr2, 0)) != REG
1997 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
1998 return 0;
2000 if (reg1 != REGNO (XEXP (addr2, 0)))
2001 return 0;
2003 /* The offset for the second addr must be 8 more than the first addr. */
2004 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
2005 return 0;
2007 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
2008 instructions. */
2009 return 1;
2012 /* Return the register class of a scratch register needed to copy IN into
2013 or out of a register in CLASS in MODE. If it can be done directly,
2014 NO_REGS is returned. */
2016 enum reg_class
2017 secondary_reload_class (class, mode, in)
2018 enum reg_class class;
2019 enum machine_mode mode;
2020 rtx in;
2022 int regno = true_regnum (in);
2024 if (regno >= FIRST_PSEUDO_REGISTER)
2025 regno = -1;
2027 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
2028 into anything. */
2029 if (class == GENERAL_REGS || class == BASE_REGS
2030 || (regno >= 0 && INT_REGNO_P (regno)))
2031 return NO_REGS;
2033 /* Constants, memory, and FP registers can go into FP registers. */
2034 if ((regno == -1 || FP_REGNO_P (regno))
2035 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
2036 return NO_REGS;
2038 /* We can copy among the CR registers. */
2039 if ((class == CR_REGS || class == CR0_REGS)
2040 && regno >= 0 && CR_REGNO_P (regno))
2041 return NO_REGS;
2043 /* Otherwise, we need GENERAL_REGS. */
2044 return GENERAL_REGS;
2047 /* Given a comparison operation, return the bit number in CCR to test. We
2048 know this is a valid comparison.
2050 SCC_P is 1 if this is for an scc. That means that %D will have been
2051 used instead of %C, so the bits will be in different places.
2053 Return -1 if OP isn't a valid comparison for some reason. */
2056 ccr_bit (op, scc_p)
2057 register rtx op;
2058 int scc_p;
2060 enum rtx_code code = GET_CODE (op);
2061 enum machine_mode cc_mode;
2062 int cc_regnum;
2063 int base_bit;
2065 if (GET_RTX_CLASS (code) != '<')
2066 return -1;
2068 cc_mode = GET_MODE (XEXP (op, 0));
2069 cc_regnum = REGNO (XEXP (op, 0));
2070 base_bit = 4 * (cc_regnum - 68);
2072 /* In CCEQmode cases we have made sure that the result is always in the
2073 third bit of the CR field. */
2075 if (cc_mode == CCEQmode)
2076 return base_bit + 3;
2078 switch (code)
2080 case NE:
2081 return scc_p ? base_bit + 3 : base_bit + 2;
2082 case EQ:
2083 return base_bit + 2;
2084 case GT: case GTU:
2085 return base_bit + 1;
2086 case LT: case LTU:
2087 return base_bit;
2089 case GE: case GEU:
2090 /* If floating-point, we will have done a cror to put the bit in the
2091 unordered position. So test that bit. For integer, this is ! LT
2092 unless this is an scc insn. */
2093 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
2095 case LE: case LEU:
2096 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
2098 default:
2099 abort ();
2103 /* Return the GOT register, creating it if needed. */
2105 struct rtx_def *
2106 rs6000_got_register (value)
2107 rtx value;
2109 if (!current_function_uses_pic_offset_table || !pic_offset_table_rtx)
2111 if (reload_in_progress || reload_completed)
2112 fatal_insn ("internal error -- needed new GOT register during reload phase to load:", value);
2114 current_function_uses_pic_offset_table = 1;
2115 pic_offset_table_rtx = gen_rtx (REG, Pmode, GOT_TOC_REGNUM);
2118 return pic_offset_table_rtx;
2122 /* Replace all occurances of register FROM with an new pseduo register in an insn X.
2123 Store the pseudo register used in REG.
2124 This is only safe during FINALIZE_PIC, since the registers haven't been setup
2125 yet. */
2127 static rtx
2128 rs6000_replace_regno (x, from, reg)
2129 rtx x;
2130 int from;
2131 rtx *reg;
2133 register int i, j;
2134 register char *fmt;
2136 /* Allow this function to make replacements in EXPR_LISTs. */
2137 if (!x)
2138 return x;
2140 switch (GET_CODE (x))
2142 case SCRATCH:
2143 case PC:
2144 case CC0:
2145 case CONST_INT:
2146 case CONST_DOUBLE:
2147 case CONST:
2148 case SYMBOL_REF:
2149 case LABEL_REF:
2150 return x;
2152 case REG:
2153 if (REGNO (x) == from)
2155 if (! *reg)
2156 *reg = pic_offset_table_rtx = gen_reg_rtx (Pmode);
2158 return *reg;
2161 return x;
2164 fmt = GET_RTX_FORMAT (GET_CODE (x));
2165 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2167 if (fmt[i] == 'e')
2168 XEXP (x, i) = rs6000_replace_regno (XEXP (x, i), from, reg);
2169 else if (fmt[i] == 'E')
2170 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2171 XVECEXP (x, i, j) = rs6000_replace_regno (XVECEXP (x, i, j), from, reg);
2174 return x;
2178 /* By generating position-independent code, when two different
2179 programs (A and B) share a common library (libC.a), the text of
2180 the library can be shared whether or not the library is linked at
2181 the same address for both programs. In some of these
2182 environments, position-independent code requires not only the use
2183 of different addressing modes, but also special code to enable the
2184 use of these addressing modes.
2186 The `FINALIZE_PIC' macro serves as a hook to emit these special
2187 codes once the function is being compiled into assembly code, but
2188 not before. (It is not done before, because in the case of
2189 compiling an inline function, it would lead to multiple PIC
2190 prologues being included in functions which used inline functions
2191 and were compiled to assembly language.) */
2193 void
2194 rs6000_finalize_pic ()
2196 /* Loop through all of the insns, replacing the special GOT_TOC_REGNUM
2197 with an appropriate pseduo register. If we find we need GOT/TOC,
2198 add the appropriate init code. */
2199 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
2201 rtx insn = get_insns ();
2202 rtx reg = NULL_RTX;
2203 rtx first_insn;
2204 rtx last_insn = NULL_RTX;
2206 if (GET_CODE (insn) == NOTE)
2207 insn = next_nonnote_insn (insn);
2209 first_insn = insn;
2210 for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
2212 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
2214 PATTERN (insn) = rs6000_replace_regno (PATTERN (insn),
2215 GOT_TOC_REGNUM,
2216 &reg);
2218 if (REG_NOTES (insn))
2219 REG_NOTES (insn) = rs6000_replace_regno (REG_NOTES (insn),
2220 GOT_TOC_REGNUM,
2221 &reg);
2224 if (GET_CODE (insn) != NOTE)
2225 last_insn = insn;
2228 if (reg)
2230 rtx init = gen_init_v4_pic (reg);
2231 emit_insn_before (init, first_insn);
2232 if (!optimize && last_insn)
2233 emit_insn_after (gen_rtx (USE, VOIDmode, reg), last_insn);
2239 /* Search for any occurrance of the GOT_TOC register marker that should
2240 have been eliminated, but may have crept back in. */
2242 void
2243 rs6000_reorg (insn)
2244 rtx insn;
2246 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
2248 rtx got_reg = gen_rtx (REG, Pmode, GOT_TOC_REGNUM);
2249 for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
2250 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2251 && reg_mentioned_p (got_reg, PATTERN (insn)))
2252 fatal_insn ("GOT/TOC register marker not removed:", PATTERN (insn));
2257 /* Define the structure for the machine field in struct function. */
2258 struct machine_function
2260 int sysv_varargs_p;
2261 int save_toc_p;
2262 int fpmem_size;
2263 int fpmem_offset;
2266 /* Functions to save and restore rs6000_fpmem_size.
2267 These will be called, via pointer variables,
2268 from push_function_context and pop_function_context. */
2270 void
2271 rs6000_save_machine_status (p)
2272 struct function *p;
2274 struct machine_function *machine =
2275 (struct machine_function *) xmalloc (sizeof (struct machine_function));
2277 p->machine = machine;
2278 machine->sysv_varargs_p = rs6000_sysv_varargs_p;
2279 machine->fpmem_size = rs6000_fpmem_size;
2280 machine->fpmem_offset = rs6000_fpmem_offset;
2283 void
2284 rs6000_restore_machine_status (p)
2285 struct function *p;
2287 struct machine_function *machine = p->machine;
2289 rs6000_sysv_varargs_p = machine->sysv_varargs_p;
2290 rs6000_fpmem_size = machine->fpmem_size;
2291 rs6000_fpmem_offset = machine->fpmem_offset;
2293 free (machine);
2294 p->machine = (struct machine_function *)0;
2297 /* Do anything needed before RTL is emitted for each function. */
2299 void
2300 rs6000_init_expanders ()
2302 /* Reset varargs and save TOC indicator */
2303 rs6000_sysv_varargs_p = 0;
2304 rs6000_fpmem_size = 0;
2305 rs6000_fpmem_offset = 0;
2306 pic_offset_table_rtx = (rtx)0;
2308 /* Arrange to save and restore machine status around nested functions. */
2309 save_machine_status = rs6000_save_machine_status;
2310 restore_machine_status = rs6000_restore_machine_status;
2314 /* Print an operand. Recognize special options, documented below. */
2316 #if TARGET_ELF
2317 #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
2318 #else
2319 #define SMALL_DATA_RELOC "sda21"
2320 #endif
2322 void
2323 print_operand (file, x, code)
2324 FILE *file;
2325 rtx x;
2326 char code;
2328 int i;
2329 int val;
2331 /* These macros test for integers and extract the low-order bits. */
2332 #define INT_P(X) \
2333 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
2334 && GET_MODE (X) == VOIDmode)
2336 #define INT_LOWPART(X) \
2337 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
2339 switch (code)
2341 case '.':
2342 /* Write out an instruction after the call which may be replaced
2343 with glue code by the loader. This depends on the AIX version. */
2344 asm_fprintf (file, RS6000_CALL_GLUE);
2345 return;
2347 case '*':
2348 /* Write the register number of the TOC register. */
2349 fputs (TARGET_MINIMAL_TOC ? reg_names[30] : reg_names[2], file);
2350 return;
2352 case '$':
2353 /* Write out either a '.' or '$' for the current location, depending
2354 on whether this is Solaris or not. */
2355 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
2356 return;
2358 case 'A':
2359 /* If X is a constant integer whose low-order 5 bits are zero,
2360 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
2361 in the AIX assembler where "sri" with a zero shift count
2362 write a trash instruction. */
2363 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
2364 putc ('l', file);
2365 else
2366 putc ('r', file);
2367 return;
2369 case 'b':
2370 /* Low-order 16 bits of constant, unsigned. */
2371 if (! INT_P (x))
2372 output_operand_lossage ("invalid %%b value");
2374 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
2375 return;
2377 case 'C':
2378 /* This is an optional cror needed for LE or GE floating-point
2379 comparisons. Otherwise write nothing. */
2380 if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
2381 && GET_MODE (XEXP (x, 0)) == CCFPmode)
2383 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2385 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
2386 base_bit + 2, base_bit + (GET_CODE (x) == GE));
2388 return;
2390 case 'D':
2391 /* Similar, except that this is for an scc, so we must be able to
2392 encode the test in a single bit that is one. We do the above
2393 for any LE, GE, GEU, or LEU and invert the bit for NE. */
2394 if (GET_CODE (x) == LE || GET_CODE (x) == GE
2395 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
2397 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2399 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
2400 base_bit + 2,
2401 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
2404 else if (GET_CODE (x) == NE)
2406 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
2408 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
2409 base_bit + 2, base_bit + 2);
2411 return;
2413 case 'E':
2414 /* X is a CR register. Print the number of the third bit of the CR */
2415 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2416 output_operand_lossage ("invalid %%E value");
2418 fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
2419 return;
2421 case 'f':
2422 /* X is a CR register. Print the shift count needed to move it
2423 to the high-order four bits. */
2424 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2425 output_operand_lossage ("invalid %%f value");
2426 else
2427 fprintf (file, "%d", 4 * (REGNO (x) - 68));
2428 return;
2430 case 'F':
2431 /* Similar, but print the count for the rotate in the opposite
2432 direction. */
2433 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2434 output_operand_lossage ("invalid %%F value");
2435 else
2436 fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
2437 return;
2439 case 'G':
2440 /* X is a constant integer. If it is negative, print "m",
2441 otherwise print "z". This is to make a aze or ame insn. */
2442 if (GET_CODE (x) != CONST_INT)
2443 output_operand_lossage ("invalid %%G value");
2444 else if (INTVAL (x) >= 0)
2445 putc ('z', file);
2446 else
2447 putc ('m', file);
2448 return;
2450 case 'h':
2451 /* If constant, output low-order five bits. Otherwise,
2452 write normally. */
2453 if (INT_P (x))
2454 fprintf (file, "%d", INT_LOWPART (x) & 31);
2455 else
2456 print_operand (file, x, 0);
2457 return;
2459 case 'H':
2460 /* If constant, output low-order six bits. Otherwise,
2461 write normally. */
2462 if (INT_P (x))
2463 fprintf (file, "%d", INT_LOWPART (x) & 63);
2464 else
2465 print_operand (file, x, 0);
2466 return;
2468 case 'I':
2469 /* Print `i' if this is a constant, else nothing. */
2470 if (INT_P (x))
2471 putc ('i', file);
2472 return;
2474 case 'j':
2475 /* Write the bit number in CCR for jump. */
2476 i = ccr_bit (x, 0);
2477 if (i == -1)
2478 output_operand_lossage ("invalid %%j code");
2479 else
2480 fprintf (file, "%d", i);
2481 return;
2483 case 'J':
2484 /* Similar, but add one for shift count in rlinm for scc and pass
2485 scc flag to `ccr_bit'. */
2486 i = ccr_bit (x, 1);
2487 if (i == -1)
2488 output_operand_lossage ("invalid %%J code");
2489 else
2490 /* If we want bit 31, write a shift count of zero, not 32. */
2491 fprintf (file, "%d", i == 31 ? 0 : i + 1);
2492 return;
2494 case 'k':
2495 /* X must be a constant. Write the 1's complement of the
2496 constant. */
2497 if (! INT_P (x))
2498 output_operand_lossage ("invalid %%k value");
2500 fprintf (file, "%d", ~ INT_LOWPART (x));
2501 return;
2503 case 'L':
2504 /* Write second word of DImode or DFmode reference. Works on register
2505 or non-indexed memory only. */
2506 if (GET_CODE (x) == REG)
2507 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
2508 else if (GET_CODE (x) == MEM)
2510 /* Handle possible auto-increment. Since it is pre-increment and
2511 we have already done it, we can just use an offset of four. */
2512 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2513 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2514 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
2515 else
2516 output_address (plus_constant (XEXP (x, 0), 4));
2517 if (small_data_operand (x, GET_MODE (x)))
2518 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
2520 return;
2522 case 'm':
2523 /* MB value for a mask operand. */
2524 if (! mask_operand (x, VOIDmode))
2525 output_operand_lossage ("invalid %%m value");
2527 val = INT_LOWPART (x);
2529 /* If the high bit is set and the low bit is not, the value is zero.
2530 If the high bit is zero, the value is the first 1 bit we find from
2531 the left. */
2532 if (val < 0 && (val & 1) == 0)
2534 putc ('0', file);
2535 return;
2537 else if (val >= 0)
2539 for (i = 1; i < 32; i++)
2540 if ((val <<= 1) < 0)
2541 break;
2542 fprintf (file, "%d", i);
2543 return;
2546 /* Otherwise, look for the first 0 bit from the right. The result is its
2547 number plus 1. We know the low-order bit is one. */
2548 for (i = 0; i < 32; i++)
2549 if (((val >>= 1) & 1) == 0)
2550 break;
2552 /* If we ended in ...01, I would be 0. The correct value is 31, so
2553 we want 31 - i. */
2554 fprintf (file, "%d", 31 - i);
2555 return;
2557 case 'M':
2558 /* ME value for a mask operand. */
2559 if (! mask_operand (x, VOIDmode))
2560 output_operand_lossage ("invalid %%m value");
2562 val = INT_LOWPART (x);
2564 /* If the low bit is set and the high bit is not, the value is 31.
2565 If the low bit is zero, the value is the first 1 bit we find from
2566 the right. */
2567 if ((val & 1) && val >= 0)
2569 fputs ("31", file);
2570 return;
2572 else if ((val & 1) == 0)
2574 for (i = 0; i < 32; i++)
2575 if ((val >>= 1) & 1)
2576 break;
2578 /* If we had ....10, I would be 0. The result should be
2579 30, so we need 30 - i. */
2580 fprintf (file, "%d", 30 - i);
2581 return;
2584 /* Otherwise, look for the first 0 bit from the left. The result is its
2585 number minus 1. We know the high-order bit is one. */
2586 for (i = 0; i < 32; i++)
2587 if ((val <<= 1) >= 0)
2588 break;
2590 fprintf (file, "%d", i);
2591 return;
2593 case 'N':
2594 /* Write the number of elements in the vector times 4. */
2595 if (GET_CODE (x) != PARALLEL)
2596 output_operand_lossage ("invalid %%N value");
2598 fprintf (file, "%d", XVECLEN (x, 0) * 4);
2599 return;
2601 case 'O':
2602 /* Similar, but subtract 1 first. */
2603 if (GET_CODE (x) != PARALLEL)
2604 output_operand_lossage ("invalid %%N value");
2606 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
2607 return;
2609 case 'p':
2610 /* X is a CONST_INT that is a power of two. Output the logarithm. */
2611 if (! INT_P (x)
2612 || (i = exact_log2 (INT_LOWPART (x))) < 0)
2613 output_operand_lossage ("invalid %%p value");
2615 fprintf (file, "%d", i);
2616 return;
2618 case 'P':
2619 /* The operand must be an indirect memory reference. The result
2620 is the register number. */
2621 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
2622 || REGNO (XEXP (x, 0)) >= 32)
2623 output_operand_lossage ("invalid %%P value");
2625 fprintf (file, "%d", REGNO (XEXP (x, 0)));
2626 return;
2628 case 'R':
2629 /* X is a CR register. Print the mask for `mtcrf'. */
2630 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2631 output_operand_lossage ("invalid %%R value");
2632 else
2633 fprintf (file, "%d", 128 >> (REGNO (x) - 68));
2634 return;
2636 case 's':
2637 /* Low 5 bits of 32 - value */
2638 if (! INT_P (x))
2639 output_operand_lossage ("invalid %%s value");
2641 fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
2642 return;
2644 case 't':
2645 /* Write 12 if this jump operation will branch if true, 4 otherwise.
2646 All floating-point operations except NE branch true and integer
2647 EQ, LT, GT, LTU and GTU also branch true. */
2648 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
2649 output_operand_lossage ("invalid %%t value");
2651 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
2652 && GET_CODE (x) != NE)
2653 || GET_CODE (x) == EQ
2654 || GET_CODE (x) == LT || GET_CODE (x) == GT
2655 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
2656 fputs ("12", file);
2657 else
2658 putc ('4', file);
2659 return;
2661 case 'T':
2662 /* Opposite of 't': write 4 if this jump operation will branch if true,
2663 12 otherwise. */
2664 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
2665 output_operand_lossage ("invalid %%t value");
2667 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
2668 && GET_CODE (x) != NE)
2669 || GET_CODE (x) == EQ
2670 || GET_CODE (x) == LT || GET_CODE (x) == GT
2671 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
2672 putc ('4', file);
2673 else
2674 fputs ("12", file);
2675 return;
2677 case 'u':
2678 /* High-order 16 bits of constant for use in unsigned operand. */
2679 if (! INT_P (x))
2680 output_operand_lossage ("invalid %%u value");
2682 fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
2683 return;
2685 case 'v':
2686 /* High-order 16 bits of constant for use in signed operand. */
2687 if (! INT_P (x))
2688 output_operand_lossage ("invalid %%v value");
2691 int value = (INT_LOWPART (x) >> 16) & 0xffff;
2693 /* Solaris assembler doesn't like lis 0,0x80000 */
2694 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
2695 fprintf (file, "%d", value | (~0 << 16));
2696 else
2697 fprintf (file, "0x%x", value);
2698 return;
2701 case 'U':
2702 /* Print `u' if this has an auto-increment or auto-decrement. */
2703 if (GET_CODE (x) == MEM
2704 && (GET_CODE (XEXP (x, 0)) == PRE_INC
2705 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
2706 putc ('u', file);
2707 return;
2709 case 'w':
2710 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
2711 normally. */
2712 if (INT_P (x))
2713 fprintf (file, "%d",
2714 (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
2715 else
2716 print_operand (file, x, 0);
2717 return;
2719 case 'W':
2720 /* If constant, low-order 16 bits of constant, unsigned.
2721 Otherwise, write normally. */
2722 if (INT_P (x))
2723 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
2724 else
2725 print_operand (file, x, 0);
2726 return;
2728 case 'X':
2729 if (GET_CODE (x) == MEM
2730 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
2731 putc ('x', file);
2732 return;
2734 case 'Y':
2735 /* Like 'L', for third word of TImode */
2736 if (GET_CODE (x) == REG)
2737 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
2738 else if (GET_CODE (x) == MEM)
2740 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2741 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2742 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
2743 else
2744 output_address (plus_constant (XEXP (x, 0), 8));
2745 if (small_data_operand (x, GET_MODE (x)))
2746 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
2748 return;
2750 case 'z':
2751 /* X is a SYMBOL_REF. Write out the name preceded by a
2752 period and without any trailing data in brackets. Used for function
2753 names. If we are configured for System V (or the embedded ABI) on
2754 the PowerPC, do not emit the period, since those systems do not use
2755 TOCs and the like. */
2756 if (GET_CODE (x) != SYMBOL_REF)
2757 abort ();
2759 if (XSTR (x, 0)[0] != '.')
2761 switch (DEFAULT_ABI)
2763 default:
2764 abort ();
2766 case ABI_AIX:
2767 putc ('.', file);
2768 break;
2770 case ABI_V4:
2771 case ABI_AIX_NODESC:
2772 case ABI_SOLARIS:
2773 break;
2775 case ABI_NT:
2776 fputs ("..", file);
2777 break;
2780 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
2781 return;
2783 case 'Z':
2784 /* Like 'L', for last word of TImode. */
2785 if (GET_CODE (x) == REG)
2786 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
2787 else if (GET_CODE (x) == MEM)
2789 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2790 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2791 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
2792 else
2793 output_address (plus_constant (XEXP (x, 0), 12));
2794 if (small_data_operand (x, GET_MODE (x)))
2795 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
2797 return;
2799 case 0:
2800 if (GET_CODE (x) == REG)
2801 fprintf (file, "%s", reg_names[REGNO (x)]);
2802 else if (GET_CODE (x) == MEM)
2804 /* We need to handle PRE_INC and PRE_DEC here, since we need to
2805 know the width from the mode. */
2806 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
2807 fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
2808 REGNO (XEXP (XEXP (x, 0), 0)));
2809 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
2810 fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
2811 REGNO (XEXP (XEXP (x, 0), 0)));
2812 else
2813 output_address (XEXP (x, 0));
2815 else
2816 output_addr_const (file, x);
2817 return;
2819 default:
2820 output_operand_lossage ("invalid %%xn code");
2824 /* Print the address of an operand. */
2826 void
2827 print_operand_address (file, x)
2828 FILE *file;
2829 register rtx x;
2831 if (GET_CODE (x) == REG)
2832 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
2833 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST || GET_CODE (x) == LABEL_REF)
2835 output_addr_const (file, x);
2836 if (small_data_operand (x, GET_MODE (x)))
2837 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
2839 #ifdef TARGET_NO_TOC
2840 else if (TARGET_NO_TOC)
2842 #endif
2843 else
2844 fprintf (file, "(%s)", reg_names[ TARGET_MINIMAL_TOC ? 30 : 2 ]);
2846 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
2848 if (REGNO (XEXP (x, 0)) == 0)
2849 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
2850 reg_names[ REGNO (XEXP (x, 0)) ]);
2851 else
2852 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
2853 reg_names[ REGNO (XEXP (x, 1)) ]);
2855 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2856 fprintf (file, "%d(%s)", INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
2857 else if (TARGET_ELF && !TARGET_64BIT && GET_CODE (x) == LO_SUM
2858 && GET_CODE (XEXP (x, 0)) == REG && CONSTANT_P (XEXP (x, 1)))
2860 output_addr_const (file, XEXP (x, 1));
2861 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
2863 else
2864 abort ();
2867 /* This page contains routines that are used to determine what the function
2868 prologue and epilogue code will do and write them out. */
2870 /* Return the first fixed-point register that is required to be saved. 32 if
2871 none. */
2874 first_reg_to_save ()
2876 int first_reg;
2878 /* Find lowest numbered live register. */
2879 for (first_reg = 13; first_reg <= 31; first_reg++)
2880 if (regs_ever_live[first_reg])
2881 break;
2883 /* If profiling, then we must save/restore every register that contains
2884 a parameter before/after the .__mcount call. Use registers from 30 down
2885 to 23 to do this. Don't use the frame pointer in reg 31.
2887 For now, save enough room for all of the parameter registers. */
2888 if (DEFAULT_ABI == ABI_AIX && profile_flag)
2889 if (first_reg > 23)
2890 first_reg = 23;
2892 return first_reg;
2895 /* Similar, for FP regs. */
2898 first_fp_reg_to_save ()
2900 int first_reg;
2902 /* Find lowest numbered live register. */
2903 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
2904 if (regs_ever_live[first_reg])
2905 break;
2907 return first_reg;
2910 /* Return non-zero if this function makes calls. */
2913 rs6000_makes_calls ()
2915 rtx insn;
2917 /* If we are profiling, we will be making a call to __mcount.
2918 Under the System V ABI's, we store the LR directly, so
2919 we don't need to do it here. */
2920 if (DEFAULT_ABI == ABI_AIX && profile_flag)
2921 return 1;
2923 for (insn = get_insns (); insn; insn = next_insn (insn))
2924 if (GET_CODE (insn) == CALL_INSN)
2925 return 1;
2927 return 0;
2931 /* Calculate the stack information for the current function. This is
2932 complicated by having two separate calling sequences, the AIX calling
2933 sequence and the V.4 calling sequence.
2935 AIX stack frames look like:
2937 SP----> +---------------------------------------+
2938 | back chain to caller | 0
2939 +---------------------------------------+
2940 | saved CR | 4
2941 +---------------------------------------+
2942 | saved LR | 8
2943 +---------------------------------------+
2944 | reserved for compilers | 12
2945 +---------------------------------------+
2946 | reserved for binders | 16
2947 +---------------------------------------+
2948 | saved TOC pointer | 20
2949 +---------------------------------------+
2950 | Parameter save area (P) | 24
2951 +---------------------------------------+
2952 | Alloca space (A) | 24+P
2953 +---------------------------------------+
2954 | Local variable space (L) | 24+P+A
2955 +---------------------------------------+
2956 | Float/int conversion temporary (X) | 24+P+A+L
2957 +---------------------------------------+
2958 | Save area for GP registers (G) | 24+P+A+X+L
2959 +---------------------------------------+
2960 | Save area for FP registers (F) | 24+P+A+X+L+G
2961 +---------------------------------------+
2962 old SP->| back chain to caller's caller |
2963 +---------------------------------------+
2965 V.4 stack frames look like:
2967 SP----> +---------------------------------------+
2968 | back chain to caller | 0
2969 +---------------------------------------+
2970 | caller's saved LR | 4
2971 +---------------------------------------+
2972 | Parameter save area (P) | 8
2973 +---------------------------------------+
2974 | Alloca space (A) | 8+P
2975 +---------------------------------------+
2976 | Varargs save area (V) | 8+P+A
2977 +---------------------------------------+
2978 | Local variable space (L) | 8+P+A+V
2979 +---------------------------------------+
2980 | Float/int conversion temporary (X) | 8+P+A+V+L
2981 +---------------------------------------+
2982 | saved CR (C) | 8+P+A+V+L+X
2983 +---------------------------------------+
2984 | Save area for GP registers (G) | 8+P+A+V+L+X+C
2985 +---------------------------------------+
2986 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
2987 +---------------------------------------+
2988 old SP->| back chain to caller's caller |
2989 +---------------------------------------+
2992 A PowerPC Windows/NT frame looks like:
2994 SP----> +---------------------------------------+
2995 | back chain to caller | 0
2996 +---------------------------------------+
2997 | reserved | 4
2998 +---------------------------------------+
2999 | reserved | 8
3000 +---------------------------------------+
3001 | reserved | 12
3002 +---------------------------------------+
3003 | reserved | 16
3004 +---------------------------------------+
3005 | reserved | 20
3006 +---------------------------------------+
3007 | Parameter save area (P) | 24
3008 +---------------------------------------+
3009 | Alloca space (A) | 24+P
3010 +---------------------------------------+
3011 | Local variable space (L) | 24+P+A
3012 +---------------------------------------+
3013 | Float/int conversion temporary (X) | 24+P+A+L
3014 +---------------------------------------+
3015 | Save area for FP registers (F) | 24+P+A+L+X
3016 +---------------------------------------+
3017 | Possible alignment area (Y) | 24+P+A+L+X+F
3018 +---------------------------------------+
3019 | Save area for GP registers (G) | 24+P+A+L+X+F+Y
3020 +---------------------------------------+
3021 | Save area for CR (C) | 24+P+A+L+X+F+Y+G
3022 +---------------------------------------+
3023 | Save area for TOC (T) | 24+P+A+L+X+F+Y+G+C
3024 +---------------------------------------+
3025 | Save area for LR (R) | 24+P+A+L+X+F+Y+G+C+T
3026 +---------------------------------------+
3027 old SP->| back chain to caller's caller |
3028 +---------------------------------------+
3030 For NT, there is no specific order to save the registers, but in
3031 order to support __builtin_return_address, the save area for the
3032 link register needs to be in a known place, so we use -4 off of the
3033 old SP. To support calls through pointers, we also allocate a
3034 fixed slot to store the TOC, -8 off the old SP. */
3036 #ifndef ABI_STACK_BOUNDARY
3037 #define ABI_STACK_BOUNDARY STACK_BOUNDARY
3038 #endif
3040 rs6000_stack_t *
3041 rs6000_stack_info ()
3043 static rs6000_stack_t info, zero_info;
3044 rs6000_stack_t *info_ptr = &info;
3045 int reg_size = TARGET_64BIT ? 8 : 4;
3046 enum rs6000_abi abi;
3047 int total_raw_size;
3049 /* Zero all fields portably */
3050 info = zero_info;
3052 /* Select which calling sequence */
3053 info_ptr->abi = abi = DEFAULT_ABI;
3055 /* Calculate which registers need to be saved & save area size */
3056 info_ptr->first_gp_reg_save = first_reg_to_save ();
3057 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
3059 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
3060 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
3062 /* Does this function call anything? */
3063 info_ptr->calls_p = rs6000_makes_calls ();
3065 /* Allocate space to save the toc. */
3066 if (abi == ABI_NT && info_ptr->calls_p)
3068 info_ptr->toc_save_p = 1;
3069 info_ptr->toc_size = reg_size;
3072 /* Does this machine need the float/int conversion area? */
3073 info_ptr->fpmem_p = regs_ever_live[FPMEM_REGNUM];
3075 /* If this is main and we need to call a function to set things up,
3076 save main's arguments around the call. */
3077 #ifdef TARGET_EABI
3078 if (TARGET_EABI)
3079 #endif
3081 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main") == 0
3082 && DECL_CONTEXT (current_function_decl) == NULL_TREE)
3084 info_ptr->main_p = 1;
3086 #ifdef NAME__MAIN
3087 info_ptr->calls_p = 1;
3089 if (DECL_ARGUMENTS (current_function_decl))
3091 int i;
3092 tree arg;
3094 info_ptr->main_save_p = 1;
3095 info_ptr->main_size = 0;
3097 for ((i = 0), (arg = DECL_ARGUMENTS (current_function_decl));
3098 arg != NULL_TREE && i < 8;
3099 (arg = TREE_CHAIN (arg)), i++)
3101 info_ptr->main_size += reg_size;
3104 #endif
3109 /* Determine if we need to save the link register */
3110 if (regs_ever_live[65]
3111 || (DEFAULT_ABI == ABI_AIX && profile_flag)
3112 #ifdef TARGET_RELOCATABLE
3113 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
3114 #endif
3115 || (info_ptr->first_fp_reg_save != 64
3116 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
3117 || (abi == ABI_V4 && current_function_calls_alloca)
3118 || (abi == ABI_SOLARIS && current_function_calls_alloca)
3119 || info_ptr->calls_p)
3121 info_ptr->lr_save_p = 1;
3122 regs_ever_live[65] = 1;
3123 if (abi == ABI_NT)
3124 info_ptr->lr_size = reg_size;
3127 /* Determine if we need to save the condition code registers */
3128 if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72])
3130 info_ptr->cr_save_p = 1;
3131 if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
3132 info_ptr->cr_size = reg_size;
3135 /* Determine various sizes */
3136 info_ptr->reg_size = reg_size;
3137 info_ptr->fixed_size = RS6000_SAVE_AREA;
3138 info_ptr->varargs_size = RS6000_VARARGS_AREA;
3139 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
3140 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
3141 info_ptr->fpmem_size = (info_ptr->fpmem_p) ? 8 : 0;
3142 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
3143 + info_ptr->gp_size
3144 + info_ptr->cr_size
3145 + info_ptr->lr_size
3146 + info_ptr->toc_size
3147 + info_ptr->main_size, 8);
3149 total_raw_size = (info_ptr->vars_size
3150 + info_ptr->parm_size
3151 + info_ptr->fpmem_size
3152 + info_ptr->save_size
3153 + info_ptr->varargs_size
3154 + info_ptr->fixed_size);
3156 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
3158 /* Determine if we need to allocate any stack frame.
3159 For AIX We need to push the stack if a frame pointer is needed (because
3160 the stack might be dynamically adjusted), if we are debugging, if the
3161 total stack size is more than 220 bytes, or if we make calls.
3163 For V.4 we don't have the stack cushion that AIX uses, but assume that
3164 the debugger can handle stackless frames. */
3166 if (info_ptr->calls_p)
3167 info_ptr->push_p = 1;
3169 else if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
3170 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
3171 || info_ptr->lr_save_p);
3173 else
3174 info_ptr->push_p = (frame_pointer_needed
3175 || write_symbols != NO_DEBUG
3176 || info_ptr->total_size > 220);
3178 /* Calculate the offsets */
3179 switch (abi)
3181 case ABI_NONE:
3182 default:
3183 abort ();
3185 case ABI_AIX:
3186 case ABI_AIX_NODESC:
3187 info_ptr->fp_save_offset = - info_ptr->fp_size;
3188 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
3189 info_ptr->main_save_offset = info_ptr->gp_save_offset - info_ptr->main_size;
3190 info_ptr->cr_save_offset = 4;
3191 info_ptr->lr_save_offset = 8;
3192 break;
3194 case ABI_V4:
3195 case ABI_SOLARIS:
3196 info_ptr->fp_save_offset = - info_ptr->fp_size;
3197 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
3198 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
3199 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
3200 info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->main_size;
3201 info_ptr->lr_save_offset = reg_size;
3202 break;
3204 case ABI_NT:
3205 info_ptr->lr_save_offset = -4;
3206 info_ptr->toc_save_offset = info_ptr->lr_save_offset - info_ptr->lr_size;
3207 info_ptr->cr_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size;
3208 info_ptr->gp_save_offset = info_ptr->cr_save_offset - info_ptr->cr_size - info_ptr->gp_size + reg_size;
3209 info_ptr->fp_save_offset = info_ptr->gp_save_offset - info_ptr->fp_size;
3210 if (info_ptr->fp_size && ((- info_ptr->fp_save_offset) % 8) != 0)
3211 info_ptr->fp_save_offset -= 4;
3213 info_ptr->main_save_offset = info_ptr->fp_save_offset - info_ptr->main_size;
3214 break;
3217 if (info_ptr->fpmem_p)
3218 info_ptr->fpmem_offset = STARTING_FRAME_OFFSET - info_ptr->total_size + info_ptr->vars_size;
3220 /* Zero offsets if we're not saving those registers */
3221 if (!info_ptr->fp_size)
3222 info_ptr->fp_save_offset = 0;
3224 if (!info_ptr->gp_size)
3225 info_ptr->gp_save_offset = 0;
3227 if (!info_ptr->lr_save_p)
3228 info_ptr->lr_save_offset = 0;
3230 if (!info_ptr->cr_save_p)
3231 info_ptr->cr_save_offset = 0;
3233 if (!info_ptr->toc_save_p)
3234 info_ptr->toc_save_offset = 0;
3236 if (!info_ptr->main_save_p)
3237 info_ptr->main_save_offset = 0;
3239 if (!info_ptr->fpmem_p)
3240 info_ptr->fpmem_offset = 0;
3241 else
3243 rs6000_fpmem_size = info_ptr->fpmem_size;
3244 rs6000_fpmem_offset = info_ptr->total_size + info_ptr->fpmem_offset;
3247 return info_ptr;
3250 void
3251 debug_stack_info (info)
3252 rs6000_stack_t *info;
3254 char *abi_string;
3256 if (!info)
3257 info = rs6000_stack_info ();
3259 fprintf (stderr, "\nStack information for function %s:\n",
3260 ((current_function_decl && DECL_NAME (current_function_decl))
3261 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
3262 : "<unknown>"));
3264 switch (info->abi)
3266 default: abi_string = "Unknown"; break;
3267 case ABI_NONE: abi_string = "NONE"; break;
3268 case ABI_AIX: abi_string = "AIX"; break;
3269 case ABI_AIX_NODESC: abi_string = "AIX"; break;
3270 case ABI_V4: abi_string = "V.4"; break;
3271 case ABI_SOLARIS: abi_string = "Solaris"; break;
3272 case ABI_NT: abi_string = "NT"; break;
3275 fprintf (stderr, "\tABI = %5s\n", abi_string);
3277 if (info->first_gp_reg_save != 32)
3278 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
3280 if (info->first_fp_reg_save != 64)
3281 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
3283 if (info->lr_save_p)
3284 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
3286 if (info->cr_save_p)
3287 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
3289 if (info->toc_save_p)
3290 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
3292 if (info->push_p)
3293 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
3295 if (info->calls_p)
3296 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
3298 if (info->main_p)
3299 fprintf (stderr, "\tmain_p = %5d\n", info->main_p);
3301 if (info->main_save_p)
3302 fprintf (stderr, "\tmain_save_p = %5d\n", info->main_save_p);
3304 if (info->fpmem_p)
3305 fprintf (stderr, "\tfpmem_p = %5d\n", info->fpmem_p);
3307 if (info->gp_save_offset)
3308 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
3310 if (info->fp_save_offset)
3311 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
3313 if (info->lr_save_offset)
3314 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
3316 if (info->cr_save_offset)
3317 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
3319 if (info->toc_save_offset)
3320 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
3322 if (info->varargs_save_offset)
3323 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
3325 if (info->main_save_offset)
3326 fprintf (stderr, "\tmain_save_offset = %5d\n", info->main_save_offset);
3328 if (info->fpmem_offset)
3329 fprintf (stderr, "\tfpmem_offset = %5d\n", info->fpmem_offset);
3331 if (info->total_size)
3332 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
3334 if (info->varargs_size)
3335 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
3337 if (info->vars_size)
3338 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
3340 if (info->parm_size)
3341 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
3343 if (info->fpmem_size)
3344 fprintf (stderr, "\tfpmem_size = %5d\n", info->fpmem_size);
3346 if (info->fixed_size)
3347 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
3349 if (info->gp_size)
3350 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
3352 if (info->fp_size)
3353 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
3355 if (info->lr_size)
3356 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
3358 if (info->cr_size)
3359 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
3361 if (info->toc_size)
3362 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
3364 if (info->main_size)
3365 fprintf (stderr, "\tmain_size = %5d\n", info->main_size);
3367 if (info->save_size)
3368 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
3370 if (info->reg_size != 4)
3371 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
3373 fprintf (stderr, "\n");
3376 /* Write out an instruction to load the TOC_TABLE address into register 30.
3377 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
3378 a constant pool. */
3380 void
3381 rs6000_output_load_toc_table (file, reg)
3382 FILE *file;
3383 int reg;
3385 char buf[256];
3387 #ifdef USING_SVR4_H
3388 if (TARGET_RELOCATABLE)
3390 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3391 fprintf (file, "\tbl ");
3392 assemble_name (file, buf);
3393 fprintf (file, "\n");
3395 /* possibly create the toc section */
3396 if (!toc_initialized)
3398 toc_section ();
3399 function_section (current_function_decl);
3402 /* If not first call in this function, we need to put the
3403 different between .LCTOC1 and the address we get to right
3404 after the bl. It will mess up disassembling the instructions
3405 but that can't be helped. We will later need to bias the
3406 address before loading. */
3407 if (rs6000_pic_func_labelno != rs6000_pic_labelno)
3409 char *init_ptr = (TARGET_64BIT) ? ".quad" : ".long";
3410 char *buf_ptr;
3412 ASM_OUTPUT_INTERNAL_LABEL (file, "LCL", rs6000_pic_labelno);
3414 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
3415 STRIP_NAME_ENCODING (buf_ptr, buf);
3416 fprintf (file, "\t%s %s-", init_ptr, buf_ptr);
3418 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3419 fprintf (file, "%s\n", buf_ptr);
3422 ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
3423 fprintf (file, "\tmflr %s\n", reg_names[reg]);
3425 if (rs6000_pic_func_labelno != rs6000_pic_labelno)
3427 if (TARGET_POWERPC64)
3428 fprintf (file, "\taddi %s,%s,8\n", reg_names[reg], reg_names[reg]);
3429 else if (TARGET_NEW_MNEMONICS)
3430 fprintf (file, "\taddi %s,%s,4\n", reg_names[reg], reg_names[reg]);
3431 else
3432 fprintf (file, "\tcal %s,4(%s)\n", reg_names[reg], reg_names[reg]);
3435 if (TARGET_POWERPC64)
3436 fprintf (file, "\tld");
3437 else if (TARGET_NEW_MNEMONICS)
3438 fprintf (file, "\tlwz");
3439 else
3440 fprintf (file, "\tl");
3442 fprintf (file, " %s,(", reg_names[0]);
3443 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
3444 assemble_name (file, buf);
3445 fprintf (file, "-");
3446 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3447 assemble_name (file, buf);
3448 fprintf (file, ")(%s)\n", reg_names[reg]);
3449 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
3450 reg_names[reg], reg_names[0], reg_names[reg]);
3451 rs6000_pic_labelno++;
3453 else if (!TARGET_64BIT)
3455 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
3456 asm_fprintf (file, "\t{cau|addis} %s,%s,", reg_names[reg], reg_names[0]);
3457 assemble_name (file, buf);
3458 asm_fprintf (file, "@ha\n");
3459 if (TARGET_NEW_MNEMONICS)
3461 asm_fprintf (file, "\taddi %s,%s,", reg_names[reg], reg_names[reg]);
3462 assemble_name (file, buf);
3463 asm_fprintf (file, "@l\n");
3465 else
3467 asm_fprintf (file, "\tcal %s,", reg_names[reg]);
3468 assemble_name (file, buf);
3469 asm_fprintf (file, "@l(%s)\n", reg_names[reg]);
3472 else
3473 abort ();
3475 #else /* !USING_SVR4_H */
3476 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
3477 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[reg]);
3478 assemble_name (file, buf);
3479 asm_fprintf (file, "(%s)\n", reg_names[2]);
3480 #endif /* USING_SVR4_H */
3484 /* Emit the correct code for allocating stack space. If COPY_R12, make sure a copy
3485 of the old frame is left in r12. */
3487 void
3488 rs6000_allocate_stack_space (file, size, copy_r12)
3489 FILE *file;
3490 int size;
3491 int copy_r12;
3493 int neg_size = -size;
3494 if (TARGET_UPDATE)
3496 if (size < 32767)
3497 asm_fprintf (file,
3498 (TARGET_32BIT) ? "\t{stu|stwu} %s,%d(%s)\n" : "\tstdu %s,%d(%s)\n",
3499 reg_names[1], neg_size, reg_names[1]);
3500 else
3502 if (copy_r12)
3503 fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
3505 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
3506 reg_names[0], (neg_size >> 16) & 0xffff,
3507 reg_names[0], reg_names[0], neg_size & 0xffff);
3508 asm_fprintf (file,
3509 (TARGET_32BIT) ? "\t{stux|stwux} %s,%s,%s\n" : "\tstdux %s,%s,%s\n",
3510 reg_names[1], reg_names[1], reg_names[0]);
3513 else
3515 fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
3516 if (size < 32767)
3518 if (TARGET_NEW_MNEMONICS)
3519 fprintf (file, "\taddi %s,%s,%d\n", reg_names[1], reg_names[1], neg_size);
3520 else
3521 fprintf (file, "\tcal %s,%d(%s)\n", reg_names[1], neg_size, reg_names[1]);
3523 else
3525 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
3526 reg_names[0], (neg_size >> 16) & 0xffff,
3527 reg_names[0], reg_names[0], neg_size & 0xffff);
3528 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", reg_names[1],
3529 reg_names[0], reg_names[1]);
3532 asm_fprintf (file,
3533 (TARGET_32BIT) ? "\t{st|stw} %s,0(%s)\n" : "\tstd %s,0(%s)\n",
3534 reg_names[12], reg_names[1]);
3539 /* Write function prologue. */
3540 void
3541 output_prolog (file, size)
3542 FILE *file;
3543 int size;
3545 rs6000_stack_t *info = rs6000_stack_info ();
3546 int reg_size = info->reg_size;
3547 char *store_reg;
3548 char *load_reg;
3549 int sp_reg = 1;
3550 int sp_offset = 0;
3552 if (TARGET_32BIT)
3554 store_reg = "\t{st|stw} %s,%d(%s)\n";
3555 load_reg = "\t{l|lwz} %s,%d(%s)\n";
3557 else
3559 store_reg = "\tstd %s,%d(%s)\n";
3560 load_reg = "\tlld %s,%d(%s)\n";
3563 if (TARGET_DEBUG_STACK)
3564 debug_stack_info (info);
3566 /* Write .extern for any function we will call to save and restore fp
3567 values. */
3568 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
3569 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
3570 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
3571 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
3573 /* Write .extern for truncation routines, if needed. */
3574 if (rs6000_trunc_used && ! trunc_defined)
3576 fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
3577 RS6000_ITRUNC, RS6000_UITRUNC);
3578 trunc_defined = 1;
3581 /* Write .extern for AIX common mode routines, if needed. */
3582 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
3584 fputs ("\t.extern __mulh\n", file);
3585 fputs ("\t.extern __mull\n", file);
3586 fputs ("\t.extern __divss\n", file);
3587 fputs ("\t.extern __divus\n", file);
3588 fputs ("\t.extern __quoss\n", file);
3589 fputs ("\t.extern __quous\n", file);
3590 common_mode_defined = 1;
3593 /* For V.4, update stack before we do any saving and set back pointer. */
3594 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
3596 if (info->total_size < 32767)
3597 sp_offset = info->total_size;
3598 else
3599 sp_reg = 12;
3600 rs6000_allocate_stack_space (file, info->total_size, sp_reg == 12);
3603 /* If we use the link register, get it into r0. */
3604 if (info->lr_save_p)
3605 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
3607 /* If we need to save CR, put it into r12. */
3608 if (info->cr_save_p && sp_reg != 12)
3609 asm_fprintf (file, "\tmfcr %s\n", reg_names[12]);
3611 /* Do any required saving of fpr's. If only one or two to save, do it
3612 ourself. Otherwise, call function. Note that since they are statically
3613 linked, we do not need a nop following them. */
3614 if (FP_SAVE_INLINE (info->first_fp_reg_save))
3616 int regno = info->first_fp_reg_save;
3617 int loc = info->fp_save_offset + sp_offset;
3619 for ( ; regno < 64; regno++, loc += 8)
3620 asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
3622 else if (info->first_fp_reg_save != 64)
3623 asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX,
3624 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
3626 /* Now save gpr's. */
3627 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
3629 int regno = info->first_gp_reg_save;
3630 int loc = info->gp_save_offset + sp_offset;
3632 for ( ; regno < 32; regno++, loc += reg_size)
3633 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
3636 else if (info->first_gp_reg_save != 32)
3637 asm_fprintf (file, "\t{stm|stmw} %s,%d(%s)\n",
3638 reg_names[info->first_gp_reg_save],
3639 info->gp_save_offset + sp_offset,
3640 reg_names[sp_reg]);
3642 /* Save main's arguments if we need to call a function */
3643 #ifdef NAME__MAIN
3644 if (info->main_save_p)
3646 int regno;
3647 int loc = info->main_save_offset + sp_offset;
3648 int size = info->main_size;
3650 for (regno = 3; size > 0; regno++, loc -= reg_size, size -= reg_size)
3651 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
3653 #endif
3655 /* Save lr if we used it. */
3656 if (info->lr_save_p)
3657 asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset + sp_offset,
3658 reg_names[sp_reg]);
3660 /* Save CR if we use any that must be preserved. */
3661 if (info->cr_save_p)
3663 if (sp_reg == 12) /* If r12 is used to hold the original sp, copy cr now */
3665 asm_fprintf (file, "\tmfcr %s\n", reg_names[0]);
3666 asm_fprintf (file, store_reg, reg_names[0],
3667 info->cr_save_offset + sp_offset,
3668 reg_names[sp_reg]);
3670 else
3671 asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset + sp_offset,
3672 reg_names[sp_reg]);
3675 /* NT needs us to probe the stack frame every 4k pages for large frames, so
3676 do it here. */
3677 if (DEFAULT_ABI == ABI_NT && info->total_size > 4096)
3679 if (info->total_size < 32768)
3681 int probe_offset = 4096;
3682 while (probe_offset < info->total_size)
3684 asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n", reg_names[0], -probe_offset, reg_names[1]);
3685 probe_offset += 4096;
3688 else
3690 int probe_iterations = info->total_size / 4096;
3691 static int probe_labelno = 0;
3692 char buf[256];
3694 if (probe_iterations < 32768)
3695 asm_fprintf (file, "\tli %s,%d\n", reg_names[12], probe_iterations);
3696 else
3698 asm_fprintf (file, "\tlis %s,%d\n", reg_names[12], probe_iterations >> 16);
3699 if (probe_iterations & 0xffff)
3700 asm_fprintf (file, "\tori %s,%s,%d\n", reg_names[12], reg_names[12],
3701 probe_iterations & 0xffff);
3703 asm_fprintf (file, "\tmtctr %s\n", reg_names[12]);
3704 asm_fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
3705 ASM_OUTPUT_INTERNAL_LABEL (file, "LCprobe", probe_labelno);
3706 asm_fprintf (file, "\t{lu|lwzu} %s,-4096(%s)\n", reg_names[0], reg_names[12]);
3707 ASM_GENERATE_INTERNAL_LABEL (buf, "LCprobe", probe_labelno++);
3708 fputs ("\tbdnz ", file);
3709 assemble_name (file, buf);
3710 fputs ("\n", file);
3714 /* Update stack and set back pointer unless this is V.4, which was done previously */
3715 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
3716 rs6000_allocate_stack_space (file, info->total_size, FALSE);
3718 /* Set frame pointer, if needed. */
3719 if (frame_pointer_needed)
3720 asm_fprintf (file, "\tmr %s,%s\n", reg_names[31], reg_names[1]);
3722 #ifdef NAME__MAIN
3723 /* If we need to call a function to set things up for main, do so now
3724 before dealing with the TOC. */
3725 if (info->main_p)
3727 char *prefix = "";
3729 switch (DEFAULT_ABI)
3731 case ABI_AIX: prefix = "."; break;
3732 case ABI_NT: prefix = ".."; break;
3735 fprintf (file, "\tbl %s%s\n", prefix, NAME__MAIN);
3736 #ifdef RS6000_CALL_GLUE2
3737 fprintf (file, "\t%s%s%s\n", RS6000_CALL_GLUE2, prefix, NAME_MAIN);
3738 #else
3739 #ifdef RS6000_CALL_GLUE
3740 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
3741 fprintf (file, "\t%s\n", RS6000_CALL_GLUE);
3742 #endif
3743 #endif
3745 if (info->main_save_p)
3747 int regno;
3748 int loc;
3749 int size = info->main_size;
3751 if (info->total_size < 32767)
3753 loc = info->total_size + info->main_save_offset;
3754 for (regno = 3; size > 0; regno++, size -= reg_size, loc -= reg_size)
3755 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
3757 else
3759 int neg_size = info->main_save_offset - info->total_size;
3760 loc = 0;
3761 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
3762 reg_names[0], (neg_size >> 16) & 0xffff,
3763 reg_names[0], reg_names[0], neg_size & 0xffff);
3765 asm_fprintf (file, "\t{sf|subf} %s,%s,%s\n", reg_names[0], reg_names[0],
3766 reg_names[1]);
3768 for (regno = 3; size > 0; regno++, size -= reg_size, loc -= reg_size)
3769 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[0]);
3773 #endif
3776 /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
3777 TOC_TABLE address into register 30. */
3778 if (TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
3780 #ifdef USING_SVR4_H
3781 if (!profile_flag)
3782 rs6000_pic_func_labelno = rs6000_pic_labelno;
3783 #endif
3784 rs6000_output_load_toc_table (file, 30);
3787 if (DEFAULT_ABI == ABI_NT)
3789 assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3790 fputs (".b:\n", file);
3794 /* Write function epilogue. */
3796 void
3797 output_epilog (file, size)
3798 FILE *file;
3799 int size;
3801 rs6000_stack_t *info = rs6000_stack_info ();
3802 char *load_reg = (TARGET_32BIT) ? "\t{l|lwz} %s,%d(%s)\n" : "\tld %s,%d(%s)\n";
3803 rtx insn = get_last_insn ();
3804 int sp_reg = 1;
3805 int sp_offset = 0;
3806 int i;
3808 /* If the last insn was a BARRIER, we don't have to write anything except
3809 the trace table. */
3810 if (GET_CODE (insn) == NOTE)
3811 insn = prev_nonnote_insn (insn);
3812 if (insn == 0 || GET_CODE (insn) != BARRIER)
3814 /* If we have a frame pointer, a call to alloca, or a large stack
3815 frame, restore the old stack pointer using the backchain. Otherwise,
3816 we know what size to update it with. */
3817 if (frame_pointer_needed || current_function_calls_alloca
3818 || info->total_size > 32767)
3820 /* Under V.4, don't reset the stack pointer until after we're done
3821 loading the saved registers. */
3822 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
3823 sp_reg = 11;
3825 asm_fprintf (file, load_reg, reg_names[sp_reg], 0, reg_names[1]);
3827 else if (info->push_p)
3829 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
3830 sp_offset = info->total_size;
3831 else if (TARGET_NEW_MNEMONICS)
3832 asm_fprintf (file, "\taddi %s,%s,%d\n", reg_names[1], reg_names[1], info->total_size);
3833 else
3834 asm_fprintf (file, "\tcal %s,%d(%s)\n", reg_names[1], info->total_size, reg_names[1]);
3837 /* Get the old lr if we saved it. */
3838 if (info->lr_save_p)
3839 asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset + sp_offset, reg_names[sp_reg]);
3841 /* Get the old cr if we saved it. */
3842 if (info->cr_save_p)
3843 asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset + sp_offset, reg_names[sp_reg]);
3845 /* Set LR here to try to overlap restores below. */
3846 if (info->lr_save_p)
3847 asm_fprintf (file, "\tmtlr %s\n", reg_names[0]);
3849 /* Restore gpr's. */
3850 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
3852 int regno = info->first_gp_reg_save;
3853 int loc = info->gp_save_offset + sp_offset;
3854 int reg_size = (TARGET_32BIT) ? 4 : 8;
3856 for ( ; regno < 32; regno++, loc += reg_size)
3857 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[sp_reg]);
3860 else if (info->first_gp_reg_save != 32)
3861 asm_fprintf (file, "\t{lm|lmw} %s,%d(%s)\n",
3862 reg_names[info->first_gp_reg_save],
3863 info->gp_save_offset + sp_offset,
3864 reg_names[sp_reg]);
3866 /* Restore fpr's if we can do it without calling a function. */
3867 if (FP_SAVE_INLINE (info->first_fp_reg_save))
3869 int regno = info->first_fp_reg_save;
3870 int loc = info->fp_save_offset + sp_offset;
3872 for ( ; regno < 64; regno++, loc += 8)
3873 asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
3876 /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4
3877 that were used. */
3878 if (info->cr_save_p)
3879 asm_fprintf (file, "\tmtcrf %d,%s\n",
3880 (regs_ever_live[70] != 0) * 0x20
3881 + (regs_ever_live[71] != 0) * 0x10
3882 + (regs_ever_live[72] != 0) * 0x8, reg_names[12]);
3884 /* If this is V.4, unwind the stack pointer after all of the loads have been done */
3885 if (sp_offset)
3887 if (TARGET_NEW_MNEMONICS)
3888 asm_fprintf (file, "\taddi %s,%s,%d\n", reg_names[1], reg_names[1], sp_offset);
3889 else
3890 asm_fprintf (file, "\tcal %s,%d(%s)\n", reg_names[1], sp_offset, reg_names[1]);
3892 else if (sp_reg != 1)
3893 asm_fprintf (file, "\tmr %s,%s\n", reg_names[1], reg_names[sp_reg]);
3895 /* If we have to restore more than two FP registers, branch to the
3896 restore function. It will return to our caller. */
3897 if (info->first_fp_reg_save != 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
3898 asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX,
3899 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
3900 else
3901 asm_fprintf (file, "\t{br|blr}\n");
3904 /* Output a traceback table here. See /usr/include/sys/debug.h for info
3905 on its format.
3907 We don't output a traceback table if -finhibit-size-directive was
3908 used. The documentation for -finhibit-size-directive reads
3909 ``don't output a @code{.size} assembler directive, or anything
3910 else that would cause trouble if the function is split in the
3911 middle, and the two halves are placed at locations far apart in
3912 memory.'' The traceback table has this property, since it
3913 includes the offset from the start of the function to the
3914 traceback table itself.
3916 System V.4 Powerpc's (and the embedded ABI derived from it) use a
3917 different traceback table. */
3918 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
3920 char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3921 int fixed_parms, float_parms, parm_info;
3922 int i;
3924 while (*fname == '.') /* V.4 encodes . in the name */
3925 fname++;
3927 /* Need label immediately before tbtab, so we can compute its offset
3928 from the function start. */
3929 if (*fname == '*')
3930 ++fname;
3931 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
3932 ASM_OUTPUT_LABEL (file, fname);
3934 /* The .tbtab pseudo-op can only be used for the first eight
3935 expressions, since it can't handle the possibly variable
3936 length fields that follow. However, if you omit the optional
3937 fields, the assembler outputs zeros for all optional fields
3938 anyways, giving each variable length field is minimum length
3939 (as defined in sys/debug.h). Thus we can not use the .tbtab
3940 pseudo-op at all. */
3942 /* An all-zero word flags the start of the tbtab, for debuggers
3943 that have to find it by searching forward from the entry
3944 point or from the current pc. */
3945 fputs ("\t.long 0\n", file);
3947 /* Tbtab format type. Use format type 0. */
3948 fputs ("\t.byte 0,", file);
3950 /* Language type. Unfortunately, there doesn't seem to be any
3951 official way to get this info, so we use language_string. C
3952 is 0. C++ is 9. No number defined for Obj-C, so use the
3953 value for C for now. */
3954 if (! strcmp (language_string, "GNU C")
3955 || ! strcmp (language_string, "GNU Obj-C"))
3956 i = 0;
3957 else if (! strcmp (language_string, "GNU F77"))
3958 i = 1;
3959 else if (! strcmp (language_string, "GNU Ada"))
3960 i = 3;
3961 else if (! strcmp (language_string, "GNU Pascal"))
3962 i = 2;
3963 else if (! strcmp (language_string, "GNU C++"))
3964 i = 9;
3965 else
3966 abort ();
3967 fprintf (file, "%d,", i);
3969 /* 8 single bit fields: global linkage (not set for C extern linkage,
3970 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
3971 from start of procedure stored in tbtab, internal function, function
3972 has controlled storage, function has no toc, function uses fp,
3973 function logs/aborts fp operations. */
3974 /* Assume that fp operations are used if any fp reg must be saved. */
3975 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
3977 /* 6 bitfields: function is interrupt handler, name present in
3978 proc table, function calls alloca, on condition directives
3979 (controls stack walks, 3 bits), saves condition reg, saves
3980 link reg. */
3981 /* The `function calls alloca' bit seems to be set whenever reg 31 is
3982 set up as a frame pointer, even when there is no alloca call. */
3983 fprintf (file, "%d,",
3984 ((1 << 6) | (frame_pointer_needed << 5)
3985 | (info->cr_save_p << 1) | (info->lr_save_p)));
3987 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
3988 (6 bits). */
3989 fprintf (file, "%d,",
3990 (info->push_p << 7) | (64 - info->first_fp_reg_save));
3992 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
3993 fprintf (file, "%d,", (32 - first_reg_to_save ()));
3996 /* Compute the parameter info from the function decl argument
3997 list. */
3998 tree decl;
3999 int next_parm_info_bit;
4001 next_parm_info_bit = 31;
4002 parm_info = 0;
4003 fixed_parms = 0;
4004 float_parms = 0;
4006 for (decl = DECL_ARGUMENTS (current_function_decl);
4007 decl; decl = TREE_CHAIN (decl))
4009 rtx parameter = DECL_INCOMING_RTL (decl);
4010 enum machine_mode mode = GET_MODE (parameter);
4012 if (GET_CODE (parameter) == REG)
4014 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
4016 int bits;
4018 float_parms++;
4020 if (mode == SFmode)
4021 bits = 0x2;
4022 else if (mode == DFmode)
4023 bits = 0x3;
4024 else
4025 abort ();
4027 /* If only one bit will fit, don't or in this entry. */
4028 if (next_parm_info_bit > 0)
4029 parm_info |= (bits << (next_parm_info_bit - 1));
4030 next_parm_info_bit -= 2;
4032 else
4034 fixed_parms += ((GET_MODE_SIZE (mode)
4035 + (UNITS_PER_WORD - 1))
4036 / UNITS_PER_WORD);
4037 next_parm_info_bit -= 1;
4043 /* Number of fixed point parameters. */
4044 /* This is actually the number of words of fixed point parameters; thus
4045 an 8 byte struct counts as 2; and thus the maximum value is 8. */
4046 fprintf (file, "%d,", fixed_parms);
4048 /* 2 bitfields: number of floating point parameters (7 bits), parameters
4049 all on stack. */
4050 /* This is actually the number of fp registers that hold parameters;
4051 and thus the maximum value is 13. */
4052 /* Set parameters on stack bit if parameters are not in their original
4053 registers, regardless of whether they are on the stack? Xlc
4054 seems to set the bit when not optimizing. */
4055 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
4057 /* Optional fields follow. Some are variable length. */
4059 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
4060 11 double float. */
4061 /* There is an entry for each parameter in a register, in the order that
4062 they occur in the parameter list. Any intervening arguments on the
4063 stack are ignored. If the list overflows a long (max possible length
4064 34 bits) then completely leave off all elements that don't fit. */
4065 /* Only emit this long if there was at least one parameter. */
4066 if (fixed_parms || float_parms)
4067 fprintf (file, "\t.long %d\n", parm_info);
4069 /* Offset from start of code to tb table. */
4070 fputs ("\t.long ", file);
4071 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
4072 RS6000_OUTPUT_BASENAME (file, fname);
4073 fputs ("-.", file);
4074 RS6000_OUTPUT_BASENAME (file, fname);
4075 putc ('\n', file);
4077 /* Interrupt handler mask. */
4078 /* Omit this long, since we never set the interrupt handler bit
4079 above. */
4081 /* Number of CTL (controlled storage) anchors. */
4082 /* Omit this long, since the has_ctl bit is never set above. */
4084 /* Displacement into stack of each CTL anchor. */
4085 /* Omit this list of longs, because there are no CTL anchors. */
4087 /* Length of function name. */
4088 fprintf (file, "\t.short %d\n", strlen (fname));
4090 /* Function name. */
4091 assemble_string (fname, strlen (fname));
4093 /* Register for alloca automatic storage; this is always reg 31.
4094 Only emit this if the alloca bit was set above. */
4095 if (frame_pointer_needed)
4096 fputs ("\t.byte 31\n", file);
4099 if (DEFAULT_ABI == ABI_NT)
4101 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4102 fputs (".e:\nFE_MOT_RESVD..", file);
4103 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
4104 fputs (":\n", file);
4108 /* Output a TOC entry. We derive the entry name from what is
4109 being written. */
4111 void
4112 output_toc (file, x, labelno)
4113 FILE *file;
4114 rtx x;
4115 int labelno;
4117 char buf[256];
4118 char *name = buf;
4119 char *real_name;
4120 rtx base = x;
4121 int offset = 0;
4123 if (TARGET_NO_TOC)
4124 abort ();
4126 /* if we're going to put a double constant in the TOC, make sure it's
4127 aligned properly when strict alignment is on. */
4128 if (GET_CODE (x) == CONST_DOUBLE
4129 && STRICT_ALIGNMENT
4130 && GET_MODE (x) == DFmode
4131 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
4132 ASM_OUTPUT_ALIGN (file, 3);
4136 if (TARGET_ELF && TARGET_MINIMAL_TOC)
4138 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
4139 fprintf (file, "%d = .-", labelno);
4140 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
4141 fputs ("1\n", file);
4143 else
4144 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
4146 /* Handle FP constants specially. Note that if we have a minimal
4147 TOC, things we put here aren't actually in the TOC, so we can allow
4148 FP constants. */
4149 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode
4150 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
4152 REAL_VALUE_TYPE rv;
4153 long k[2];
4155 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
4156 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
4157 if (TARGET_MINIMAL_TOC)
4158 fprintf (file, "\t.long %ld\n\t.long %ld\n", k[0], k[1]);
4159 else
4160 fprintf (file, "\t.tc FD_%lx_%lx[TC],%ld,%ld\n",
4161 k[0], k[1], k[0], k[1]);
4162 return;
4164 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
4165 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
4167 REAL_VALUE_TYPE rv;
4168 long l;
4170 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
4171 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
4173 if (TARGET_MINIMAL_TOC)
4174 fprintf (file, "\t.long %ld\n", l);
4175 else
4176 fprintf (file, "\t.tc FS_%lx[TC],%ld\n", l, l);
4177 return;
4179 else if (GET_MODE (x) == DImode
4180 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
4181 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
4183 HOST_WIDE_INT low;
4184 HOST_WIDE_INT high;
4186 if (GET_CODE (x) == CONST_DOUBLE)
4188 low = CONST_DOUBLE_LOW (x);
4189 high = CONST_DOUBLE_HIGH (x);
4191 else
4192 #if HOST_BITS_PER_WIDE_INT == 32
4194 low = INTVAL (x);
4195 high = (low < 0) ? ~0 : 0;
4197 #else
4199 low = INTVAL (x) & 0xffffffff;
4200 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
4202 #endif
4204 if (TARGET_MINIMAL_TOC)
4205 fprintf (file, "\t.long %ld\n\t.long %ld\n", (long)high, (long)low);
4206 else
4207 fprintf (file, "\t.tc ID_%lx_%lx[TC],%ld,%ld\n",
4208 (long)high, (long)low, (long)high, (long)low);
4209 return;
4212 if (GET_CODE (x) == CONST)
4214 base = XEXP (XEXP (x, 0), 0);
4215 offset = INTVAL (XEXP (XEXP (x, 0), 1));
4218 if (GET_CODE (base) == SYMBOL_REF)
4219 name = XSTR (base, 0);
4220 else if (GET_CODE (base) == LABEL_REF)
4221 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
4222 else if (GET_CODE (base) == CODE_LABEL)
4223 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
4224 else
4225 abort ();
4227 STRIP_NAME_ENCODING (real_name, name);
4228 if (TARGET_MINIMAL_TOC)
4229 fputs ("\t.long ", file);
4230 else
4232 fprintf (file, "\t.tc %s", real_name);
4234 if (offset < 0)
4235 fprintf (file, ".N%d", - offset);
4236 else if (offset)
4237 fprintf (file, ".P%d", offset);
4239 fputs ("[TC],", file);
4242 /* Currently C++ toc references to vtables can be emitted before it
4243 is decided whether the vtable is public or private. If this is
4244 the case, then the linker will eventually complain that there is
4245 a TOC reference to an unknown section. Thus, for vtables only,
4246 we emit the TOC reference to reference the symbol and not the
4247 section. */
4248 if (!strncmp ("_vt.", name, 4))
4250 RS6000_OUTPUT_BASENAME (file, name);
4251 if (offset < 0)
4252 fprintf (file, "%d", offset);
4253 else if (offset > 0)
4254 fprintf (file, "+%d", offset);
4256 else
4257 output_addr_const (file, x);
4258 putc ('\n', file);
4261 /* Output an assembler pseudo-op to write an ASCII string of N characters
4262 starting at P to FILE.
4264 On the RS/6000, we have to do this using the .byte operation and
4265 write out special characters outside the quoted string.
4266 Also, the assembler is broken; very long strings are truncated,
4267 so we must artificially break them up early. */
4269 void
4270 output_ascii (file, p, n)
4271 FILE *file;
4272 char *p;
4273 int n;
4275 char c;
4276 int i, count_string;
4277 char *for_string = "\t.byte \"";
4278 char *for_decimal = "\t.byte ";
4279 char *to_close = NULL;
4281 count_string = 0;
4282 for (i = 0; i < n; i++)
4284 c = *p++;
4285 if (c >= ' ' && c < 0177)
4287 if (for_string)
4288 fputs (for_string, file);
4289 putc (c, file);
4291 /* Write two quotes to get one. */
4292 if (c == '"')
4294 putc (c, file);
4295 ++count_string;
4298 for_string = NULL;
4299 for_decimal = "\"\n\t.byte ";
4300 to_close = "\"\n";
4301 ++count_string;
4303 if (count_string >= 512)
4305 fputs (to_close, file);
4307 for_string = "\t.byte \"";
4308 for_decimal = "\t.byte ";
4309 to_close = NULL;
4310 count_string = 0;
4313 else
4315 if (for_decimal)
4316 fputs (for_decimal, file);
4317 fprintf (file, "%d", c);
4319 for_string = "\n\t.byte \"";
4320 for_decimal = ", ";
4321 to_close = "\n";
4322 count_string = 0;
4326 /* Now close the string if we have written one. Then end the line. */
4327 if (to_close)
4328 fprintf (file, to_close);
4331 /* Generate a unique section name for FILENAME for a section type
4332 represented by SECTION_DESC. Output goes into BUF.
4334 SECTION_DESC can be any string, as long as it is different for each
4335 possible section type.
4337 We name the section in the same manner as xlc. The name begins with an
4338 underscore followed by the filename (after stripping any leading directory
4339 names) with the last period replaced by the string SECTION_DESC. If
4340 FILENAME does not contain a period, SECTION_DESC is appended to the end of
4341 the name. */
4343 void
4344 rs6000_gen_section_name (buf, filename, section_desc)
4345 char **buf;
4346 char *filename;
4347 char *section_desc;
4349 char *q, *after_last_slash, *last_period;
4350 char *p;
4351 int len;
4353 after_last_slash = filename;
4354 for (q = filename; *q; q++)
4356 if (*q == '/')
4357 after_last_slash = q + 1;
4358 else if (*q == '.')
4359 last_period = q;
4362 len = strlen (after_last_slash) + strlen (section_desc) + 2;
4363 *buf = (char *) permalloc (len);
4365 p = *buf;
4366 *p++ = '_';
4368 for (q = after_last_slash; *q; q++)
4370 if (q == last_period)
4372 strcpy (p, section_desc);
4373 p += strlen (section_desc);
4376 else if (isalnum (*q))
4377 *p++ = *q;
4380 if (last_period == 0)
4381 strcpy (p, section_desc);
4382 else
4383 *p = '\0';
4386 /* Write function profiler code. */
4388 void
4389 output_function_profiler (file, labelno)
4390 FILE *file;
4391 int labelno;
4393 /* The last used parameter register. */
4394 int last_parm_reg;
4395 int i, j;
4396 char buf[100];
4398 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
4399 switch (DEFAULT_ABI)
4401 default:
4402 abort ();
4404 case ABI_V4:
4405 case ABI_SOLARIS:
4406 case ABI_AIX_NODESC:
4407 fprintf (file, "\tmflr %s\n", reg_names[0]);
4408 if (flag_pic == 1)
4410 fprintf (file, "\tbl _GLOBAL_OFFSET_TABLE_@local-4\n");
4411 fprintf (file, "\tmflr %s\n", reg_names[11]);
4412 fprintf (file, "\t%s %s,", (TARGET_NEW_MNEMONICS) ? "lwz" : "l",
4413 reg_names[11]);
4414 assemble_name (file, buf);
4415 fprintf (file, "@got(%s)\n", reg_names[11]);
4417 #if TARGET_ELF
4418 else if (flag_pic > 1 || TARGET_RELOCATABLE)
4420 fprintf (file, "\tstw %s,4(%s)\n", reg_names[0], reg_names[1]);
4421 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
4422 assemble_name (file, buf);
4423 fprintf (file, "X = .-.LCTOC1\n");
4424 fprintf (file, "\t.long ");
4425 assemble_name (file, buf);
4426 fputs ("\n\t.previous\n", file);
4427 rs6000_pic_func_labelno = rs6000_pic_labelno;
4428 rs6000_output_load_toc_table (file, 11);
4429 fprintf (file, "\t%s %s,", (TARGET_NEW_MNEMONICS) ? "lwz" : "l",
4430 reg_names[11]);
4431 assemble_name (file, buf);
4432 fprintf (file, "X(%s)\n", reg_names[11]);
4434 #endif
4435 else if (TARGET_NEW_MNEMONICS)
4437 fprintf (file, "\taddis %s,%s,", reg_names[11], reg_names[11]);
4438 assemble_name (file, buf);
4439 fprintf (file, "@ha\n");
4440 fprintf (file, "\tstw %s,4(%s)\n", reg_names[0], reg_names[1]);
4441 fprintf (file, "\taddi %s,%s,", reg_names[11], reg_names[11]);
4442 assemble_name (file, buf);
4443 fputs ("@l\n", file);
4445 else
4447 fprintf (file, "\tcau %s,%s,", reg_names[11], reg_names[11]);
4448 assemble_name (file, buf);
4449 fprintf (file, "@ha\n");
4450 fprintf (file, "\tst %s,4(%s)\n", reg_names[0], reg_names[1]);
4451 fprintf (file, "\tcal %s,", reg_names[11]);
4452 assemble_name (file, buf);
4453 fprintf (file, "@l(%s)\n", reg_names[11]);
4456 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
4457 break;
4459 case ABI_AIX:
4460 /* Set up a TOC entry for the profiler label. */
4461 toc_section ();
4462 ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
4463 if (TARGET_MINIMAL_TOC)
4465 fputs ("\t.long ", file);
4466 assemble_name (file, buf);
4467 putc ('\n', file);
4469 else
4471 fputs ("\t.tc\t", file);
4472 assemble_name (file, buf);
4473 fputs ("[TC],", file);
4474 assemble_name (file, buf);
4475 putc ('\n', file);
4477 text_section ();
4479 /* Figure out last used parameter register. The proper thing to do is
4480 to walk incoming args of the function. A function might have live
4481 parameter registers even if it has no incoming args. */
4483 for (last_parm_reg = 10;
4484 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
4485 last_parm_reg--)
4488 /* Save parameter registers in regs 23-30. Don't overwrite reg 31, since
4489 it might be set up as the frame pointer. */
4491 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
4492 asm_fprintf (file, "\tmr %d,%d\n", j, i);
4494 /* Load location address into r3, and call mcount. */
4496 ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
4497 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[3]);
4498 assemble_name (file, buf);
4499 asm_fprintf (file, "(%s)\n\tbl %s\n", reg_names[2], RS6000_MCOUNT);
4501 /* Restore parameter registers. */
4503 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
4504 asm_fprintf (file, "\tmr %d,%d\n", i, j);
4505 break;
4509 /* Adjust the cost of a scheduling dependency. Return the new cost of
4510 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
4513 rs6000_adjust_cost (insn, link, dep_insn, cost)
4514 rtx insn;
4515 rtx link;
4516 rtx dep_insn;
4517 int cost;
4519 if (! recog_memoized (insn))
4520 return 0;
4522 if (REG_NOTE_KIND (link) != 0)
4523 return 0;
4525 if (REG_NOTE_KIND (link) == 0)
4527 /* Data dependency; DEP_INSN writes a register that INSN reads some
4528 cycles later. */
4530 /* Tell the first scheduling pass about the latency between a mtctr
4531 and bctr (and mtlr and br/blr). The first scheduling pass will not
4532 know about this latency since the mtctr instruction, which has the
4533 latency associated to it, will be generated by reload. */
4534 if (get_attr_type (insn) == TYPE_JMPREG)
4535 return TARGET_POWER ? 5 : 4;
4537 /* Fall out to return default cost. */
4540 return cost;
4543 /* Return how many instructions the machine can issue per cycle */
4544 int get_issue_rate()
4546 switch (rs6000_cpu_attr) {
4547 case CPU_RIOS1:
4548 return 3; /* ? */
4549 case CPU_RIOS2:
4550 return 4;
4551 case CPU_PPC601:
4552 return 3; /* ? */
4553 case CPU_PPC603:
4554 return 2;
4555 case CPU_PPC604:
4556 return 4;
4557 case CPU_PPC620:
4558 return 4;
4559 default:
4560 return 1;
4566 /* Output assembler code for a block containing the constant parts
4567 of a trampoline, leaving space for the variable parts.
4569 The trampoline should set the static chain pointer to value placed
4570 into the trampoline and should branch to the specified routine. */
4572 void
4573 rs6000_trampoline_template (file)
4574 FILE *file;
4576 char *sc = reg_names[STATIC_CHAIN_REGNUM];
4577 char *r0 = reg_names[0];
4578 char *r2 = reg_names[2];
4580 switch (DEFAULT_ABI)
4582 default:
4583 abort ();
4585 /* Under AIX, this is not code at all, but merely a data area,
4586 since that is the way all functions are called. The first word is
4587 the address of the function, the second word is the TOC pointer (r2),
4588 and the third word is the static chain value. */
4589 case ABI_AIX:
4590 break;
4593 /* V.4/eabi function pointers are just a single pointer, so we need to
4594 do the full gory code to load up the static chain. */
4595 case ABI_V4:
4596 case ABI_SOLARIS:
4597 case ABI_AIX_NODESC:
4598 break;
4600 /* NT function pointers point to a two word area (real address, TOC)
4601 which unfortunately does not include a static chain field. So we
4602 use the function field to point to ..LTRAMP1 and the toc field
4603 to point to the whole table. */
4604 case ABI_NT:
4605 if (STATIC_CHAIN_REGNUM == 0
4606 || STATIC_CHAIN_REGNUM == 2
4607 || TARGET_64BIT
4608 || !TARGET_NEW_MNEMONICS)
4609 abort ();
4611 fprintf (file, "\t.ualong 0\n"); /* offset 0 */
4612 fprintf (file, "\t.ualong 0\n"); /* offset 4 */
4613 fprintf (file, "\t.ualong 0\n"); /* offset 8 */
4614 fprintf (file, "\t.ualong 0\n"); /* offset 12 */
4615 fprintf (file, "\t.ualong 0\n"); /* offset 16 */
4616 fprintf (file, "..LTRAMP1..0:\n"); /* offset 20 */
4617 fprintf (file, "\tlwz %s,8(%s)\n", r0, r2); /* offset 24 */
4618 fprintf (file, "\tlwz %s,12(%s)\n", sc, r2); /* offset 28 */
4619 fprintf (file, "\tmtctr %s\n", r0); /* offset 32 */
4620 fprintf (file, "\tlwz %s,16(%s)\n", r2, r2); /* offset 36 */
4621 fprintf (file, "\tbctr\n"); /* offset 40 */
4622 break;
4625 return;
4628 /* Length in units of the trampoline for entering a nested function. */
4631 rs6000_trampoline_size ()
4633 int ret = 0;
4635 switch (DEFAULT_ABI)
4637 default:
4638 abort ();
4640 case ABI_AIX:
4641 ret = (TARGET_32BIT) ? 12 : 24;
4642 break;
4644 case ABI_V4:
4645 case ABI_SOLARIS:
4646 case ABI_AIX_NODESC:
4647 ret = (TARGET_32BIT) ? 40 : 48;
4648 break;
4650 case ABI_NT:
4651 ret = 20;
4652 break;
4655 return ret;
4658 /* Emit RTL insns to initialize the variable parts of a trampoline.
4659 FNADDR is an RTX for the address of the function's pure code.
4660 CXT is an RTX for the static chain value for the function. */
4662 void
4663 rs6000_initialize_trampoline (addr, fnaddr, cxt)
4664 rtx addr;
4665 rtx fnaddr;
4666 rtx cxt;
4668 enum machine_mode pmode = Pmode;
4669 int regsize = (TARGET_32BIT) ? 4 : 8;
4670 rtx ctx_reg = force_reg (pmode, cxt);
4672 switch (DEFAULT_ABI)
4674 default:
4675 abort ();
4677 /* Macros to shorten the code expansions below. */
4678 #define MEM_DEREF(addr) gen_rtx (MEM, pmode, memory_address (pmode, addr))
4679 #define MEM_PLUS(addr,offset) gen_rtx (MEM, pmode, memory_address (pmode, plus_constant (addr, offset)))
4681 /* Under AIX, just build the 3 word function descriptor */
4682 case ABI_AIX:
4684 rtx fn_reg = gen_reg_rtx (pmode);
4685 rtx toc_reg = gen_reg_rtx (pmode);
4686 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
4687 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
4688 emit_move_insn (MEM_DEREF (addr), fn_reg);
4689 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
4690 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
4692 break;
4694 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
4695 case ABI_V4:
4696 case ABI_SOLARIS:
4697 case ABI_AIX_NODESC:
4698 emit_library_call (gen_rtx (SYMBOL_REF, SImode, "__trampoline_setup"),
4699 FALSE, VOIDmode, 4,
4700 addr, pmode,
4701 GEN_INT (rs6000_trampoline_size ()), SImode,
4702 fnaddr, pmode,
4703 ctx_reg, pmode);
4704 break;
4706 /* Under NT, update the first word to point to the ..LTRAMP1..0 header,
4707 the second word will point to the whole trampoline, third-fifth words
4708 will then have the real address, static chain, and toc value. */
4709 case ABI_NT:
4711 rtx tramp_reg = gen_reg_rtx (pmode);
4712 rtx fn_reg = gen_reg_rtx (pmode);
4713 rtx toc_reg = gen_reg_rtx (pmode);
4715 emit_move_insn (tramp_reg, gen_rtx (SYMBOL_REF, pmode, "..LTRAMP1..0"));
4716 addr = force_reg (pmode, addr);
4717 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
4718 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
4719 emit_move_insn (MEM_DEREF (addr), tramp_reg);
4720 emit_move_insn (MEM_PLUS (addr, regsize), addr);
4721 emit_move_insn (MEM_PLUS (addr, 2*regsize), fn_reg);
4722 emit_move_insn (MEM_PLUS (addr, 3*regsize), ctx_reg);
4723 emit_move_insn (MEM_PLUS (addr, 4*regsize), gen_rtx (REG, pmode, 2));
4725 break;
4728 return;
4732 /* If defined, a C expression whose value is nonzero if IDENTIFIER
4733 with arguments ARGS is a valid machine specific attribute for DECL.
4734 The attributes in ATTRIBUTES have previously been assigned to DECL. */
4737 rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
4738 tree decl;
4739 tree attributes;
4740 tree identifier;
4741 tree args;
4743 return 0;
4746 /* If defined, a C expression whose value is nonzero if IDENTIFIER
4747 with arguments ARGS is a valid machine specific attribute for TYPE.
4748 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
4751 rs6000_valid_type_attribute_p (type, attributes, identifier, args)
4752 tree type;
4753 tree attributes;
4754 tree identifier;
4755 tree args;
4757 if (TREE_CODE (type) != FUNCTION_TYPE
4758 && TREE_CODE (type) != FIELD_DECL
4759 && TREE_CODE (type) != TYPE_DECL)
4760 return 0;
4762 /* Longcall attribute says that the function is not within 2**26 bytes
4763 of the current function, and to do an indirect call. */
4764 if (is_attribute_p ("longcall", identifier))
4765 return (args == NULL_TREE);
4767 if (DEFAULT_ABI == ABI_NT)
4769 /* Stdcall attribute says callee is responsible for popping arguments
4770 if they are not variable. */
4771 if (is_attribute_p ("stdcall", identifier))
4772 return (args == NULL_TREE);
4774 /* Cdecl attribute says the callee is a normal C declaration */
4775 if (is_attribute_p ("cdecl", identifier))
4776 return (args == NULL_TREE);
4778 /* Dllimport attribute says says the caller is to call the function
4779 indirectly through a __imp_<name> pointer. */
4780 if (is_attribute_p ("dllimport", identifier))
4781 return (args == NULL_TREE);
4783 /* Dllexport attribute says says the callee is to create a __imp_<name>
4784 pointer. */
4785 if (is_attribute_p ("dllexport", identifier))
4786 return (args == NULL_TREE);
4788 /* Exception attribute allows the user to specify 1-2 strings or identifiers
4789 that will fill in the 3rd and 4th fields of the structured exception
4790 table. */
4791 if (is_attribute_p ("exception", identifier))
4793 int i;
4795 if (args == NULL_TREE)
4796 return 0;
4798 for (i = 0; i < 2 && args != NULL_TREE; i++)
4800 tree this_arg = TREE_VALUE (args);
4801 args = TREE_PURPOSE (args);
4803 if (TREE_CODE (this_arg) != STRING_CST
4804 && TREE_CODE (this_arg) != IDENTIFIER_NODE)
4805 return 0;
4808 return (args == NULL_TREE);
4812 return 0;
4815 /* If defined, a C expression whose value is zero if the attributes on
4816 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
4817 two if they are nearly compatible (which causes a warning to be
4818 generated). */
4821 rs6000_comp_type_attributes (type1, type2)
4822 tree type1;
4823 tree type2;
4825 return 1;
4828 /* If defined, a C statement that assigns default attributes to newly
4829 defined TYPE. */
4831 void
4832 rs6000_set_default_type_attributes (type)
4833 tree type;
4837 /* Return a dll import reference corresponding to to a call's SYMBOL_REF */
4838 struct rtx_def *
4839 rs6000_dll_import_ref (call_ref)
4840 rtx call_ref;
4842 char *call_name;
4843 int len;
4844 char *p;
4845 rtx reg1, reg2;
4846 tree node;
4848 if (GET_CODE (call_ref) != SYMBOL_REF)
4849 abort ();
4851 call_name = XSTR (call_ref, 0);
4852 len = sizeof ("__imp_") + strlen (call_name);
4853 p = alloca (len);
4854 reg2 = gen_reg_rtx (Pmode);
4856 strcpy (p, "__imp_");
4857 strcat (p, call_name);
4858 node = get_identifier (p);
4860 reg1 = force_reg (Pmode, gen_rtx (SYMBOL_REF, VOIDmode, IDENTIFIER_POINTER (node)));
4861 emit_move_insn (reg2, gen_rtx (MEM, Pmode, reg1));
4863 return reg2;
4866 /* Return a reference suitable for calling a function with the longcall attribute. */
4867 struct rtx_def *
4868 rs6000_longcall_ref (call_ref)
4869 rtx call_ref;
4871 char *call_name;
4872 int len;
4873 char *p;
4874 rtx reg1, reg2;
4875 tree node;
4877 if (GET_CODE (call_ref) != SYMBOL_REF)
4878 return call_ref;
4880 /* System V adds '.' to the internal name, so skip them. */
4881 call_name = XSTR (call_ref, 0);
4882 if (*call_name == '.')
4884 while (*call_name == '.')
4885 call_name++;
4887 node = get_identifier (call_name);
4888 call_ref = gen_rtx (SYMBOL_REF, VOIDmode, IDENTIFIER_POINTER (node));
4891 return force_reg (Pmode, call_ref);
4895 /* A C statement or statements to switch to the appropriate section
4896 for output of RTX in mode MODE. You can assume that RTX is some
4897 kind of constant in RTL. The argument MODE is redundant except in
4898 the case of a `const_int' rtx. Select the section by calling
4899 `text_section' or one of the alternatives for other sections.
4901 Do not define this macro if you put all constants in the read-only
4902 data section. */
4904 #ifdef USING_SVR4_H
4906 void
4907 rs6000_select_rtx_section (mode, x)
4908 enum machine_mode mode;
4909 rtx x;
4911 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x))
4912 toc_section ();
4913 else
4914 const_section ();
4917 /* A C statement or statements to switch to the appropriate
4918 section for output of DECL. DECL is either a `VAR_DECL' node
4919 or a constant of some sort. RELOC indicates whether forming
4920 the initial value of DECL requires link-time relocations. */
4922 void
4923 rs6000_select_section (decl, reloc)
4924 tree decl;
4925 int reloc;
4927 int size = int_size_in_bytes (TREE_TYPE (decl));
4929 if (TREE_CODE (decl) == STRING_CST)
4931 if (! flag_writable_strings)
4932 const_section ();
4933 else
4934 data_section ();
4936 else if (TREE_CODE (decl) == VAR_DECL)
4938 if ((flag_pic && reloc)
4939 || !TREE_READONLY (decl)
4940 || TREE_SIDE_EFFECTS (decl)
4941 || !DECL_INITIAL (decl)
4942 || (DECL_INITIAL (decl) != error_mark_node
4943 && !TREE_CONSTANT (DECL_INITIAL (decl))))
4945 if (rs6000_sdata != SDATA_NONE && (size > 0) && (size <= g_switch_value))
4946 sdata_section ();
4947 else
4948 data_section ();
4950 else
4952 if (rs6000_sdata != SDATA_NONE && (size > 0) && (size <= g_switch_value))
4954 if (rs6000_sdata == SDATA_EABI)
4955 sdata2_section ();
4956 else
4957 sdata_section (); /* System V doesn't have .sdata2/.sbss2 */
4959 else
4960 const_section ();
4963 else
4964 const_section ();
4969 /* If we are referencing a function that is static or is known to be
4970 in this file, make the SYMBOL_REF special. We can use this to indicate
4971 that we can branch to this function without emitting a no-op after the
4972 call. For real AIX and NT calling sequences, we also replace the
4973 function name with the real name (1 or 2 leading .'s), rather than
4974 the function descriptor name. This saves a lot of overriding code
4975 to readd the prefixes. */
4977 void
4978 rs6000_encode_section_info (decl)
4979 tree decl;
4981 if (TREE_CODE (decl) == FUNCTION_DECL)
4983 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
4984 if (TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
4985 SYMBOL_REF_FLAG (sym_ref) = 1;
4987 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
4989 char *prefix = (DEFAULT_ABI == ABI_AIX) ? "." : "..";
4990 char *str = permalloc (strlen (prefix) + 1
4991 + strlen (XSTR (sym_ref, 0)));
4992 strcpy (str, prefix);
4993 strcat (str, XSTR (sym_ref, 0));
4994 XSTR (sym_ref, 0) = str;
4997 else if (rs6000_sdata != SDATA_NONE
4998 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4999 && TREE_CODE (decl) == VAR_DECL)
5001 int size = int_size_in_bytes (TREE_TYPE (decl));
5002 tree section_name = DECL_SECTION_NAME (decl);
5003 char *name = (char *)0;
5004 int len = 0;
5006 if (section_name)
5008 if (TREE_CODE (section_name) == STRING_CST)
5010 name = TREE_STRING_POINTER (section_name);
5011 len = TREE_STRING_LENGTH (section_name);
5013 else
5014 abort ();
5017 if ((size > 0 && size <= g_switch_value)
5018 || (name
5019 && ((len == sizeof (".sdata")-1 && strcmp (name, ".sdata") == 0)
5020 || (len == sizeof (".sdata2")-1 && strcmp (name, ".sdata2") == 0)
5021 || (len == sizeof (".sbss")-1 && strcmp (name, ".sbss") == 0)
5022 || (len == sizeof (".sbss2")-1 && strcmp (name, ".sbss2") == 0)
5023 || (len == sizeof (".PPC.EMB.sdata0")-1 && strcmp (name, ".PPC.EMB.sdata0") == 0)
5024 || (len == sizeof (".PPC.EMB.sbss0")-1 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
5026 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
5027 char *str = permalloc (2 + strlen (XSTR (sym_ref, 0)));
5028 strcpy (str, "@");
5029 strcat (str, XSTR (sym_ref, 0));
5030 XSTR (sym_ref, 0) = str;
5035 #endif /* USING_SVR4_H */