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