]> gcc.gnu.org Git - gcc.git/blob - gcc/config/rs6000/rs6000.c
update PowerPC support
[gcc.git] / gcc / config / rs6000 / rs6000.c
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 1993, 1994, 1995 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
40 extern char *language_string;
41 extern int profile_block_flag;
42
43 #define min(A,B) ((A) < (B) ? (A) : (B))
44 #define max(A,B) ((A) > (B) ? (A) : (B))
45
46 /* Target cpu type */
47
48 enum processor_type rs6000_cpu;
49 char *rs6000_cpu_string;
50
51 /* Set to non-zero by "fix" operation to indicate that itrunc and
52 uitrunc must be defined. */
53
54 int rs6000_trunc_used;
55
56 /* Set to non-zero once they have been defined. */
57
58 static int trunc_defined;
59
60 /* Set to non-zero once AIX common-mode calls have been defined. */
61 static int common_mode_defined;
62 /* Save information from a "cmpxx" operation until the branch or scc is
63 emitted. */
64
65 rtx rs6000_compare_op0, rs6000_compare_op1;
66 int rs6000_compare_fp_p;
67
68 #ifdef USING_SVR4_H
69 /* Label number of label created for -mrelocatable, to call to so we can
70 get the address of the GOT section */
71 int rs6000_pic_labelno;
72 #endif
73
74 /* Whether a System V.4 varargs area was created. */
75 int rs6000_sysv_varargs_p;
76
77 /* Whether we need to save the TOC register. */
78 int rs6000_save_toc_p;
79
80 /* ABI enumeration available for subtarget to use. */
81 enum rs6000_abi rs6000_current_abi;
82
83 /* Temporary memory used to convert integer -> float */
84 static rtx stack_temps[NUM_MACHINE_MODES];
85
86 \f
87 /* Print the options used in the assembly file. */
88
89 extern char *version_string, *language_string;
90
91 struct asm_option
92 {
93 char *string;
94 int *variable;
95 int on_value;
96 };
97
98 #define MAX_LINE 79
99
100 static int
101 output_option (file, type, name, pos)
102 FILE *file;
103 char *type;
104 char *name;
105 int pos;
106 {
107 int type_len = strlen (type);
108 int name_len = strlen (name);
109
110 if (1 + type_len + name_len + pos > MAX_LINE)
111 {
112 fprintf (file, "\n # %s%s", type, name);
113 return 3 + type_len + name_len;
114 }
115 fprintf (file, " %s%s", type, name);
116 return pos + 1 + type_len + name_len;
117 }
118
119 static struct { char *name; int value; } m_options[] = TARGET_SWITCHES;
120
121 void
122 output_options (file, f_options, f_len, W_options, W_len)
123 FILE *file;
124 struct asm_option *f_options;
125 int f_len;
126 struct asm_option *W_options;
127 int W_len;
128 {
129 int j;
130 int flags = target_flags;
131 int pos = 32767;
132
133 fprintf (file, " # %s %s", language_string, version_string);
134
135 if (optimize)
136 {
137 char opt_string[20];
138 sprintf (opt_string, "%d", optimize);
139 pos = output_option (file, "-O", opt_string, pos);
140 }
141
142 if (profile_flag)
143 pos = output_option (file, "-p", "", pos);
144
145 if (profile_block_flag)
146 pos = output_option (file, "-a", "", pos);
147
148 if (inhibit_warnings)
149 pos = output_option (file, "-w", "", pos);
150
151 for (j = 0; j < f_len; j++)
152 {
153 if (*f_options[j].variable == f_options[j].on_value)
154 pos = output_option (file, "-f", f_options[j].string, pos);
155 }
156
157 for (j = 0; j < W_len; j++)
158 {
159 if (*W_options[j].variable == W_options[j].on_value)
160 pos = output_option (file, "-W", W_options[j].string, pos);
161 }
162
163 for (j = 0; j < sizeof m_options / sizeof m_options[0]; j++)
164 {
165 if (m_options[j].name[0] != '\0'
166 && m_options[j].value > 0
167 && ((m_options[j].value & flags) == m_options[j].value))
168 {
169 pos = output_option (file, "-m", m_options[j].name, pos);
170 flags &= ~ m_options[j].value;
171 }
172 }
173
174 if (rs6000_cpu_string != (char *)0)
175 pos = output_option (file, "-mcpu=", rs6000_cpu_string, pos);
176
177 fputs ("\n\n", file);
178 }
179
180 \f
181 /* Override command line options. Mostly we process the processor
182 type and sometimes adjust other TARGET_ options. */
183
184 void
185 rs6000_override_options ()
186 {
187 int i;
188
189 /* Simplify the entries below by making a mask for any POWER
190 variant and any PowerPC variant. */
191
192 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
193 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
194 | MASK_PPC_GFXOPT | MASK_POWERPC64)
195 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
196
197 static struct ptt
198 {
199 char *name; /* Canonical processor name. */
200 enum processor_type processor; /* Processor type enum value. */
201 int target_enable; /* Target flags to enable. */
202 int target_disable; /* Target flags to disable. */
203 } processor_target_table[]
204 = {{"common", PROCESSOR_COMMON, 0, POWER_MASKS | POWERPC_MASKS},
205 {"power", PROCESSOR_POWER,
206 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
207 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
208 {"powerpc", PROCESSOR_POWERPC,
209 MASK_POWERPC | MASK_NEW_MNEMONICS,
210 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
211 {"rios", PROCESSOR_RIOS1,
212 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
213 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
214 {"rios1", PROCESSOR_RIOS1,
215 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
216 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
217 {"rsc", PROCESSOR_PPC601,
218 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
219 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
220 {"rsc1", PROCESSOR_PPC601,
221 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
222 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
223 {"rios2", PROCESSOR_RIOS2,
224 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
225 POWERPC_MASKS | MASK_NEW_MNEMONICS},
226 {"403", PROCESSOR_PPC403,
227 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
228 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
229 {"601", PROCESSOR_PPC601,
230 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
231 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
232 {"602", PROCESSOR_PPC602,
233 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
234 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
235 {"603", PROCESSOR_PPC603,
236 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
237 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
238 {"603e", PROCESSOR_PPC603,
239 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
240 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
241 {"604", PROCESSOR_PPC604,
242 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
243 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
244 {"620", PROCESSOR_PPC620,
245 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
246 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}};
247
248 int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
249
250 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
251 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
252
253 profile_block_flag = 0;
254
255 /* Identify the processor type */
256 if (rs6000_cpu_string == 0)
257 rs6000_cpu = PROCESSOR_DEFAULT;
258 else
259 {
260 for (i = 0; i < ptt_size; i++)
261 if (! strcmp (rs6000_cpu_string, processor_target_table[i].name))
262 {
263 rs6000_cpu = processor_target_table[i].processor;
264 target_flags |= processor_target_table[i].target_enable;
265 target_flags &= ~processor_target_table[i].target_disable;
266 break;
267 }
268
269 if (i == ptt_size)
270 {
271 error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string);
272 rs6000_cpu_string = "default";
273 rs6000_cpu = PROCESSOR_DEFAULT;
274 }
275 }
276
277 /* If -mmultiple or -mno-multiple was explicitly used, don't
278 override with the processor default */
279 if (TARGET_MULTIPLE_SET)
280 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
281
282 /* If -mstring or -mno-string was explicitly used, don't
283 override with the processor default */
284 if (TARGET_STRING_SET)
285 target_flags = (target_flags & ~MASK_STRING) | string;
286
287 /* Don't allow -mmultiple or -mstring on little endian systems, because the
288 hardware doesn't support the instructions used in little endian mode */
289 if (!BYTES_BIG_ENDIAN)
290 {
291 if (TARGET_MULTIPLE)
292 {
293 target_flags &= ~MASK_MULTIPLE;
294 if (TARGET_MULTIPLE_SET)
295 warning ("-mmultiple is not supported on little endian systems");
296 }
297
298 if (TARGET_STRING)
299 {
300 target_flags &= ~MASK_STRING;
301 if (TARGET_STRING_SET)
302 warning ("-mstring is not supported on little endian systems");
303 }
304 }
305
306 #ifdef SUBTARGET_OVERRIDE_OPTIONS
307 SUBTARGET_OVERRIDE_OPTIONS;
308 #endif
309 }
310 \f
311 /* Create a CONST_DOUBLE from a string. */
312
313 struct rtx_def *
314 rs6000_float_const (string, mode)
315 char *string;
316 enum machine_mode mode;
317 {
318 REAL_VALUE_TYPE value = REAL_VALUE_ATOF (string, mode);
319 return immed_real_const_1 (value, mode);
320 }
321
322 \f
323 /* Create a CONST_DOUBLE like immed_double_const, except reverse the
324 two parts of the constant if the target is little endian. */
325
326 struct rtx_def *
327 rs6000_immed_double_const (i0, i1, mode)
328 HOST_WIDE_INT i0, i1;
329 enum machine_mode mode;
330 {
331 if (! WORDS_BIG_ENDIAN)
332 return immed_double_const (i1, i0, mode);
333
334 return immed_double_const (i0, i1, mode);
335 }
336
337 \f
338 /* Return non-zero if this function is known to have a null epilogue. */
339
340 int
341 direct_return ()
342 {
343 if (reload_completed)
344 {
345 rs6000_stack_t *info = rs6000_stack_info ();
346
347 if (info->first_gp_reg_save == 32
348 && info->first_fp_reg_save == 64
349 && !info->lr_save_p
350 && !info->cr_save_p
351 && !info->push_p)
352 return 1;
353 }
354
355 return 0;
356 }
357
358 /* Returns 1 always. */
359
360 int
361 any_operand (op, mode)
362 register rtx op;
363 enum machine_mode mode;
364 {
365 return 1;
366 }
367
368 /* Returns 1 if op is the count register */
369 int count_register_operand(op, mode)
370 register rtx op;
371 enum machine_mode mode;
372 {
373 if (GET_CODE (op) != REG)
374 return 0;
375
376 if (REGNO (op) == COUNT_REGISTER_REGNUM)
377 return 1;
378
379 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
380 return 1;
381
382 return 0;
383 }
384
385 /* Return 1 if OP is a constant that can fit in a D field. */
386
387 int
388 short_cint_operand (op, mode)
389 register rtx op;
390 enum machine_mode mode;
391 {
392 return (GET_CODE (op) == CONST_INT
393 && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
394 }
395
396 /* Similar for a unsigned D field. */
397
398 int
399 u_short_cint_operand (op, mode)
400 register rtx op;
401 enum machine_mode mode;
402 {
403 return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
404 }
405
406 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
407
408 int
409 non_short_cint_operand (op, mode)
410 register rtx op;
411 enum machine_mode mode;
412 {
413 return (GET_CODE (op) == CONST_INT
414 && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
415 }
416
417 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
418 ctr, or lr). */
419
420 int
421 gpc_reg_operand (op, mode)
422 register rtx op;
423 enum machine_mode mode;
424 {
425 return (register_operand (op, mode)
426 && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
427 }
428
429 /* Returns 1 if OP is either a pseudo-register or a register denoting a
430 CR field. */
431
432 int
433 cc_reg_operand (op, mode)
434 register rtx op;
435 enum machine_mode mode;
436 {
437 return (register_operand (op, mode)
438 && (GET_CODE (op) != REG
439 || REGNO (op) >= FIRST_PSEUDO_REGISTER
440 || CR_REGNO_P (REGNO (op))));
441 }
442
443 /* Returns 1 if OP is either a constant integer valid for a D-field or a
444 non-special register. If a register, it must be in the proper mode unless
445 MODE is VOIDmode. */
446
447 int
448 reg_or_short_operand (op, mode)
449 register rtx op;
450 enum machine_mode mode;
451 {
452 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
453 }
454
455 /* Similar, except check if the negation of the constant would be valid for
456 a D-field. */
457
458 int
459 reg_or_neg_short_operand (op, mode)
460 register rtx op;
461 enum machine_mode mode;
462 {
463 if (GET_CODE (op) == CONST_INT)
464 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
465
466 return gpc_reg_operand (op, mode);
467 }
468
469 /* Return 1 if the operand is either a register or an integer whose high-order
470 16 bits are zero. */
471
472 int
473 reg_or_u_short_operand (op, mode)
474 register rtx op;
475 enum machine_mode mode;
476 {
477 if (GET_CODE (op) == CONST_INT
478 && (INTVAL (op) & 0xffff0000) == 0)
479 return 1;
480
481 return gpc_reg_operand (op, mode);
482 }
483
484 /* Return 1 is the operand is either a non-special register or ANY
485 constant integer. */
486
487 int
488 reg_or_cint_operand (op, mode)
489 register rtx op;
490 enum machine_mode mode;
491 {
492 return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
493 }
494
495 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
496 with one instruction per word. We only do this if we can safely read
497 CONST_DOUBLE_{LOW,HIGH}. */
498
499 int
500 easy_fp_constant (op, mode)
501 register rtx op;
502 register enum machine_mode mode;
503 {
504 rtx low, high;
505
506 if (GET_CODE (op) != CONST_DOUBLE
507 || GET_MODE (op) != mode
508 || GET_MODE_CLASS (mode) != MODE_FLOAT)
509 return 0;
510
511 /* Consider all constants with -msoft-float to be easy */
512 if (TARGET_SOFT_FLOAT)
513 return 1;
514
515 high = operand_subword (op, 0, 0, mode);
516 low = operand_subword (op, 1, 0, mode);
517
518 if (high == 0 || ! input_operand (high, word_mode))
519 return 0;
520
521 return (mode == SFmode
522 || (low != 0 && input_operand (low, word_mode)));
523 }
524
525 /* Return 1 if the operand is in volatile memory. Note that during the
526 RTL generation phase, memory_operand does not return TRUE for
527 volatile memory references. So this function allows us to
528 recognize volatile references where its safe. */
529
530 int
531 volatile_mem_operand (op, mode)
532 register rtx op;
533 enum machine_mode mode;
534 {
535 if (GET_CODE (op) != MEM)
536 return 0;
537
538 if (!MEM_VOLATILE_P (op))
539 return 0;
540
541 if (mode != GET_MODE (op))
542 return 0;
543
544 if (reload_completed)
545 return memory_operand (op, mode);
546
547 if (reload_in_progress)
548 return strict_memory_address_p (mode, XEXP (op, 0));
549
550 return memory_address_p (mode, XEXP (op, 0));
551 }
552
553 /* Return 1 if the operand is an offsettable memory address. */
554
555 int
556 offsettable_addr_operand (op, mode)
557 register rtx op;
558 enum machine_mode mode;
559 {
560 return offsettable_address_p (reload_completed | reload_in_progress,
561 mode, op);
562 }
563
564 /* Return 1 if the operand is either a floating-point register, a pseudo
565 register, or memory. */
566
567 int
568 fp_reg_or_mem_operand (op, mode)
569 register rtx op;
570 enum machine_mode mode;
571 {
572 return (memory_operand (op, mode)
573 || volatile_mem_operand (op, mode)
574 || (register_operand (op, mode)
575 && (GET_CODE (op) != REG
576 || REGNO (op) >= FIRST_PSEUDO_REGISTER
577 || FP_REGNO_P (REGNO (op)))));
578 }
579
580 /* Return 1 if the operand is either an easy FP constant (see above) or
581 memory. */
582
583 int
584 mem_or_easy_const_operand (op, mode)
585 register rtx op;
586 enum machine_mode mode;
587 {
588 return memory_operand (op, mode) || easy_fp_constant (op, mode);
589 }
590
591 /* Return 1 if the operand is either a non-special register or an item
592 that can be used as the operand of an SI add insn. */
593
594 int
595 add_operand (op, mode)
596 register rtx op;
597 enum machine_mode mode;
598 {
599 return (reg_or_short_operand (op, mode)
600 || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
601 }
602
603 /* Return 1 if OP is a constant but not a valid add_operand. */
604
605 int
606 non_add_cint_operand (op, mode)
607 register rtx op;
608 enum machine_mode mode;
609 {
610 return (GET_CODE (op) == CONST_INT
611 && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
612 && (INTVAL (op) & 0xffff) != 0);
613 }
614
615 /* Return 1 if the operand is a non-special register or a constant that
616 can be used as the operand of an OR or XOR insn on the RS/6000. */
617
618 int
619 logical_operand (op, mode)
620 register rtx op;
621 enum machine_mode mode;
622 {
623 return (gpc_reg_operand (op, mode)
624 || (GET_CODE (op) == CONST_INT
625 && ((INTVAL (op) & 0xffff0000) == 0
626 || (INTVAL (op) & 0xffff) == 0)));
627 }
628
629 /* Return 1 if C is a constant that is not a logical operand (as
630 above). */
631
632 int
633 non_logical_cint_operand (op, mode)
634 register rtx op;
635 enum machine_mode mode;
636 {
637 return (GET_CODE (op) == CONST_INT
638 && (INTVAL (op) & 0xffff0000) != 0
639 && (INTVAL (op) & 0xffff) != 0);
640 }
641
642 /* Return 1 if C is a constant that can be encoded in a mask on the
643 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
644 Reject all ones and all zeros, since these should have been optimized
645 away and confuse the making of MB and ME. */
646
647 int
648 mask_constant (c)
649 register int c;
650 {
651 int i;
652 int last_bit_value;
653 int transitions = 0;
654
655 if (c == 0 || c == ~0)
656 return 0;
657
658 last_bit_value = c & 1;
659
660 for (i = 1; i < 32; i++)
661 if (((c >>= 1) & 1) != last_bit_value)
662 last_bit_value ^= 1, transitions++;
663
664 return transitions <= 2;
665 }
666
667 /* Return 1 if the operand is a constant that is a mask on the RS/6000. */
668
669 int
670 mask_operand (op, mode)
671 register rtx op;
672 enum machine_mode mode;
673 {
674 return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
675 }
676
677 /* Return 1 if the operand is either a non-special register or a
678 constant that can be used as the operand of an RS/6000 logical AND insn. */
679
680 int
681 and_operand (op, mode)
682 register rtx op;
683 enum machine_mode mode;
684 {
685 return (reg_or_short_operand (op, mode)
686 || logical_operand (op, mode)
687 || mask_operand (op, mode));
688 }
689
690 /* Return 1 if the operand is a constant but not a valid operand for an AND
691 insn. */
692
693 int
694 non_and_cint_operand (op, mode)
695 register rtx op;
696 enum machine_mode mode;
697 {
698 return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
699 }
700
701 /* Return 1 if the operand is a general register or memory operand. */
702
703 int
704 reg_or_mem_operand (op, mode)
705 register rtx op;
706 register enum machine_mode mode;
707 {
708 return (gpc_reg_operand (op, mode)
709 || memory_operand (op, mode)
710 || volatile_mem_operand (op, mode));
711 }
712
713 /* Return 1 if the operand is a general register or memory operand without
714 pre-inc or pre_dec which produces invalid form of PowerPC lwa
715 instruction. */
716
717 int
718 lwa_operand (op, mode)
719 register rtx op;
720 register enum machine_mode mode;
721 {
722 rtx inner = op;
723
724 if (reload_completed && GET_CODE (inner) == SUBREG)
725 inner = SUBREG_REG (inner);
726
727 return gpc_reg_operand (inner, mode)
728 || (memory_operand (inner, mode)
729 && GET_CODE (XEXP (inner, 0)) != PRE_INC
730 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
731 }
732
733 /* Return 1 if the operand, used inside a MEM, is a valid first argument
734 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
735 forced to lr. */
736
737 int
738 call_operand (op, mode)
739 register rtx op;
740 enum machine_mode mode;
741 {
742 if (mode != VOIDmode && GET_MODE (op) != mode)
743 return 0;
744
745 return (GET_CODE (op) == SYMBOL_REF
746 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
747 }
748
749
750 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
751 this file. */
752
753 int
754 current_file_function_operand (op, mode)
755 register rtx op;
756 enum machine_mode mode;
757 {
758 return (GET_CODE (op) == SYMBOL_REF
759 && (SYMBOL_REF_FLAG (op)
760 || op == XEXP (DECL_RTL (current_function_decl), 0)));
761 }
762
763
764 /* Return 1 if this operand is a valid input for a move insn. */
765
766 int
767 input_operand (op, mode)
768 register rtx op;
769 enum machine_mode mode;
770 {
771 /* Memory is always valid. */
772 if (memory_operand (op, mode))
773 return 1;
774
775 /* For floating-point, easy constants are valid. */
776 if (GET_MODE_CLASS (mode) == MODE_FLOAT
777 && CONSTANT_P (op)
778 && easy_fp_constant (op, mode))
779 return 1;
780
781 /* For floating-point or multi-word mode, the only remaining valid type
782 is a register. */
783 if (GET_MODE_CLASS (mode) == MODE_FLOAT
784 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
785 return register_operand (op, mode);
786
787 /* The only cases left are integral modes one word or smaller (we
788 do not get called for MODE_CC values). These can be in any
789 register. */
790 if (register_operand (op, mode))
791 return 1;
792
793 /* For HImode and QImode, any constant is valid. */
794 if ((mode == HImode || mode == QImode)
795 && GET_CODE (op) == CONST_INT)
796 return 1;
797
798 /* A SYMBOL_REF referring to the TOC is valid. */
799 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
800 return 1;
801
802 /* Windows NT allows SYMBOL_REFs and LABEL_REFs against the TOC
803 directly in the instruction stream */
804 if (DEFAULT_ABI == ABI_NT
805 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF))
806 return 1;
807
808 /* Otherwise, we will be doing this SET with an add, so anything valid
809 for an add will be valid. */
810 return add_operand (op, mode);
811 }
812 \f
813 /* Initialize a variable CUM of type CUMULATIVE_ARGS
814 for a call to a function whose data type is FNTYPE.
815 For a library call, FNTYPE is 0.
816
817 For incoming args we set the number of arguments in the prototype large
818 so we never return an EXPR_LIST. */
819
820 void
821 init_cumulative_args (cum, fntype, libname, incoming)
822 CUMULATIVE_ARGS *cum;
823 tree fntype;
824 rtx libname;
825 int incoming;
826 {
827 static CUMULATIVE_ARGS zero_cumulative;
828
829 *cum = zero_cumulative;
830 cum->words = 0;
831 cum->fregno = FP_ARG_MIN_REG;
832 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
833
834 if (incoming)
835 {
836 cum->nargs_prototype = 1000; /* don't return an EXPR_LIST */
837 #ifdef TARGET_V4_CALLS
838 if (TARGET_V4_CALLS)
839 cum->varargs_offset = RS6000_VARARGS_OFFSET;
840 #endif
841 }
842
843 else if (cum->prototype)
844 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
845 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
846 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
847
848 else
849 cum->nargs_prototype = 0;
850
851 cum->orig_nargs = cum->nargs_prototype;
852 if (TARGET_DEBUG_ARG)
853 {
854 fprintf (stderr, "\ninit_cumulative_args:");
855 if (fntype)
856 {
857 tree ret_type = TREE_TYPE (fntype);
858 fprintf (stderr, " ret code = %s,",
859 tree_code_name[ (int)TREE_CODE (ret_type) ]);
860 }
861
862 #ifdef TARGET_V4_CALLS
863 if (TARGET_V4_CALLS && incoming)
864 fprintf (stderr, " varargs = %d, ", cum->varargs_offset);
865 #endif
866
867 fprintf (stderr, " proto = %d, nargs = %d\n",
868 cum->prototype, cum->nargs_prototype);
869 }
870 }
871 \f
872 /* If defined, a C expression that gives the alignment boundary, in bits,
873 of an argument with the specified mode and type. If it is not defined,
874 PARM_BOUNDARY is used for all arguments.
875
876 Windows NT wants anything >= 8 bytes to be double word aligned. */
877
878 int
879 function_arg_boundary (mode, type)
880 enum machine_mode mode;
881 tree type;
882 {
883 if (DEFAULT_ABI != ABI_NT || TARGET_64BIT)
884 return PARM_BOUNDARY;
885
886 if (mode != BLKmode)
887 return (GET_MODE_SIZE (mode)) >= 8 ? 64 : 32;
888
889 return (int_size_in_bytes (type) >= 8) ? 64 : 32;
890 }
891 \f
892 /* Update the data in CUM to advance over an argument
893 of mode MODE and data type TYPE.
894 (TYPE is null for libcalls where that information may not be available.) */
895
896 void
897 function_arg_advance (cum, mode, type, named)
898 CUMULATIVE_ARGS *cum;
899 enum machine_mode mode;
900 tree type;
901 int named;
902 {
903 int align = ((cum->words & 1) != 0 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
904 cum->words += align;
905 cum->nargs_prototype--;
906
907 #ifdef TARGET_V4_CALLS
908 if (TARGET_V4_CALLS)
909 {
910 /* Long longs must not be split between registers and stack */
911 if ((GET_MODE_CLASS (mode) != MODE_FLOAT || TARGET_SOFT_FLOAT)
912 && type && !AGGREGATE_TYPE_P (type)
913 && cum->words < GP_ARG_NUM_REG
914 && cum->words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
915 {
916 cum->words = GP_ARG_NUM_REG;
917 }
918
919 /* Aggregates get passed as pointers */
920 if (type && AGGREGATE_TYPE_P (type))
921 cum->words++;
922
923 /* Floats go in registers, & don't occupy space in the GP registers
924 like they do for AIX unless software floating point. */
925 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
926 && TARGET_HARD_FLOAT
927 && cum->fregno <= FP_ARG_V4_MAX_REG)
928 cum->fregno++;
929
930 else
931 cum->words += RS6000_ARG_SIZE (mode, type, 1);
932 }
933 else
934 #endif
935 if (named)
936 {
937 cum->words += RS6000_ARG_SIZE (mode, type, named);
938 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
939 cum->fregno++;
940 }
941
942 if (TARGET_DEBUG_ARG)
943 fprintf (stderr,
944 "function_adv: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
945 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
946 }
947 \f
948 /* Determine where to put an argument to a function.
949 Value is zero to push the argument on the stack,
950 or a hard register in which to store the argument.
951
952 MODE is the argument's machine mode.
953 TYPE is the data type of the argument (as a tree).
954 This is null for libcalls where that information may
955 not be available.
956 CUM is a variable of type CUMULATIVE_ARGS which gives info about
957 the preceding args and about the function being called.
958 NAMED is nonzero if this argument is a named parameter
959 (otherwise it is an extra parameter matching an ellipsis).
960
961 On RS/6000 the first eight words of non-FP are normally in registers
962 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
963 Under V.4, the first 8 FP args are in registers.
964
965 If this is floating-point and no prototype is specified, we use
966 both an FP and integer register (or possibly FP reg and stack). Library
967 functions (when TYPE is zero) always have the proper types for args,
968 so we can pass the FP value just in one register. emit_library_function
969 doesn't support EXPR_LIST anyway. */
970
971 struct rtx_def *
972 function_arg (cum, mode, type, named)
973 CUMULATIVE_ARGS *cum;
974 enum machine_mode mode;
975 tree type;
976 int named;
977 {
978 int align = ((cum->words & 1) != 0 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
979 int align_words = cum->words + align;
980
981 if (TARGET_DEBUG_ARG)
982 fprintf (stderr,
983 "function_arg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
984 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
985
986 /* Return a marker to indicate whether CR1 needs to set or clear the bit that V.4
987 uses to say fp args were passed in registers. Assume that we don't need the
988 marker for software floating point, or compiler generated library calls. */
989 if (mode == VOIDmode)
990 {
991 #ifdef TARGET_V4_CALLS
992 if (TARGET_V4_CALLS && TARGET_HARD_FLOAT && cum->nargs_prototype < 0
993 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
994 return GEN_INT ((cum->fregno == FP_ARG_MIN_REG) ? -1 : 1);
995 #endif
996
997 return GEN_INT (0);
998 }
999
1000 if (!named)
1001 {
1002 #ifdef TARGET_V4_CALLS
1003 if (!TARGET_V4_CALLS)
1004 #endif
1005 return NULL_RTX;
1006 }
1007
1008 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1009 return NULL_RTX;
1010
1011 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1012 {
1013 if ((cum->nargs_prototype > 0)
1014 #ifdef TARGET_V4_CALLS
1015 || TARGET_V4_CALLS /* V.4 never passes FP values in GP registers */
1016 #endif
1017 || !type)
1018 return gen_rtx (REG, mode, cum->fregno);
1019
1020 return gen_rtx (EXPR_LIST, VOIDmode,
1021 ((align_words < GP_ARG_NUM_REG)
1022 ? gen_rtx (REG, mode, GP_ARG_MIN_REG + align_words)
1023 : NULL_RTX),
1024 gen_rtx (REG, mode, cum->fregno));
1025 }
1026
1027 #ifdef TARGET_V4_CALLS
1028 /* Long longs won't be split between register and stack */
1029 else if (TARGET_V4_CALLS &&
1030 align_words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
1031 {
1032 return NULL_RTX;
1033 }
1034 #endif
1035
1036 else if (align_words < GP_ARG_NUM_REG)
1037 return gen_rtx (REG, mode, GP_ARG_MIN_REG + align_words);
1038
1039 return NULL_RTX;
1040 }
1041 \f
1042 /* For an arg passed partly in registers and partly in memory,
1043 this is the number of registers used.
1044 For args passed entirely in registers or entirely in memory, zero. */
1045
1046 int
1047 function_arg_partial_nregs (cum, mode, type, named)
1048 CUMULATIVE_ARGS *cum;
1049 enum machine_mode mode;
1050 tree type;
1051 int named;
1052 {
1053 if (! named)
1054 return 0;
1055
1056 #ifdef TARGET_V4_CALLS
1057 if (TARGET_V4_CALLS)
1058 return 0;
1059 #endif
1060
1061 if (USE_FP_FOR_ARG_P (*cum, mode, type))
1062 {
1063 if (cum->nargs_prototype >= 0)
1064 return 0;
1065 }
1066
1067 if (cum->words < GP_ARG_NUM_REG
1068 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type, named)))
1069 {
1070 int ret = GP_ARG_NUM_REG - cum->words;
1071 if (ret && TARGET_DEBUG_ARG)
1072 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
1073
1074 return ret;
1075 }
1076
1077 return 0;
1078 }
1079 \f
1080 /* A C expression that indicates when an argument must be passed by
1081 reference. If nonzero for an argument, a copy of that argument is
1082 made in memory and a pointer to the argument is passed instead of
1083 the argument itself. The pointer is passed in whatever way is
1084 appropriate for passing a pointer to that type.
1085
1086 Under V.4, structures and unions are passed by reference. */
1087
1088 int
1089 function_arg_pass_by_reference (cum, mode, type, named)
1090 CUMULATIVE_ARGS *cum;
1091 enum machine_mode mode;
1092 tree type;
1093 int named;
1094 {
1095 #ifdef TARGET_V4_CALLS
1096 if (TARGET_V4_CALLS && type && AGGREGATE_TYPE_P (type))
1097 {
1098 if (TARGET_DEBUG_ARG)
1099 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
1100
1101 return 1;
1102 }
1103 #endif
1104
1105 return 0;
1106 }
1107
1108 \f
1109 /* Perform any needed actions needed for a function that is receiving a
1110 variable number of arguments.
1111
1112 CUM is as above.
1113
1114 MODE and TYPE are the mode and type of the current parameter.
1115
1116 PRETEND_SIZE is a variable that should be set to the amount of stack
1117 that must be pushed by the prolog to pretend that our caller pushed
1118 it.
1119
1120 Normally, this macro will push all remaining incoming registers on the
1121 stack and set PRETEND_SIZE to the length of the registers pushed. */
1122
1123 void
1124 setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
1125 CUMULATIVE_ARGS *cum;
1126 enum machine_mode mode;
1127 tree type;
1128 int *pretend_size;
1129 int no_rtl;
1130
1131 {
1132 rtx save_area = virtual_incoming_args_rtx;
1133 int reg_size = (TARGET_64BIT) ? 8 : 4;
1134
1135 if (TARGET_DEBUG_ARG)
1136 fprintf (stderr,
1137 "setup_vararg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, no_rtl= %d\n",
1138 cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), no_rtl);
1139
1140 #ifdef TARGET_V4_CALLS
1141 if (TARGET_V4_CALLS && !no_rtl)
1142 {
1143 rs6000_sysv_varargs_p = 1;
1144 save_area = plus_constant (frame_pointer_rtx, RS6000_VARARGS_OFFSET);
1145 }
1146 #endif
1147
1148 if (cum->words < 8)
1149 {
1150 int first_reg_offset = cum->words;
1151
1152 if (MUST_PASS_IN_STACK (mode, type))
1153 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type, 1);
1154
1155 if (first_reg_offset > GP_ARG_NUM_REG)
1156 first_reg_offset = GP_ARG_NUM_REG;
1157
1158 if (!no_rtl && first_reg_offset != GP_ARG_NUM_REG)
1159 move_block_from_reg
1160 (GP_ARG_MIN_REG + first_reg_offset,
1161 gen_rtx (MEM, BLKmode,
1162 plus_constant (save_area, first_reg_offset * reg_size)),
1163 GP_ARG_NUM_REG - first_reg_offset,
1164 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
1165
1166 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
1167 }
1168
1169 #ifdef TARGET_V4_CALLS
1170 /* Save FP registers if needed. */
1171 if (TARGET_V4_CALLS && TARGET_HARD_FLOAT && !no_rtl)
1172 {
1173 int fregno = cum->fregno;
1174 int num_fp_reg = FP_ARG_V4_MAX_REG + 1 - fregno;
1175
1176 if (num_fp_reg >= 0)
1177 {
1178 rtx cr1 = gen_rtx (REG, CCmode, 69);
1179 rtx lab = gen_label_rtx ();
1180 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
1181
1182 emit_jump_insn (gen_rtx (SET, VOIDmode,
1183 pc_rtx,
1184 gen_rtx (IF_THEN_ELSE, VOIDmode,
1185 gen_rtx (NE, VOIDmode, cr1, const0_rtx),
1186 gen_rtx (LABEL_REF, VOIDmode, lab),
1187 pc_rtx)));
1188
1189 while ( num_fp_reg-- >= 0)
1190 {
1191 emit_move_insn (gen_rtx (MEM, DFmode, plus_constant (save_area, off)),
1192 gen_rtx (REG, DFmode, fregno++));
1193 off += 8;
1194 }
1195
1196 emit_label (lab);
1197 }
1198 }
1199 #endif
1200 }
1201 \f
1202 /* If defined, is a C expression that produces the machine-specific
1203 code for a call to `__builtin_saveregs'. This code will be moved
1204 to the very beginning of the function, before any parameter access
1205 are made. The return value of this function should be an RTX that
1206 contains the value to use as the return of `__builtin_saveregs'.
1207
1208 The argument ARGS is a `tree_list' containing the arguments that
1209 were passed to `__builtin_saveregs'.
1210
1211 If this macro is not defined, the compiler will output an ordinary
1212 call to the library function `__builtin_saveregs'.
1213
1214 On the Power/PowerPC return the address of the area on the stack
1215 used to hold arguments. Under AIX, this includes the 8 word register
1216 save area. Under V.4 this does not. */
1217
1218 struct rtx_def *
1219 expand_builtin_saveregs (args)
1220 tree args;
1221 {
1222 return virtual_incoming_args_rtx;
1223 }
1224
1225 \f
1226 /* Allocate a stack temp. Only allocate one stack temp per type for a
1227 function. */
1228
1229 struct rtx_def *
1230 rs6000_stack_temp (mode, size)
1231 enum machine_mode mode;
1232 int size;
1233 {
1234 rtx temp = stack_temps[ (int)mode ];
1235 rtx addr;
1236
1237 if (temp == NULL_RTX)
1238 {
1239 temp = assign_stack_local (mode, size, 0);
1240 addr = XEXP (temp, 0);
1241
1242 if ((size > 4 && !offsettable_address_p (0, mode, addr))
1243 || (size <= 4 && !memory_address_p (mode, addr)))
1244 {
1245 XEXP (temp, 0) = copy_addr_to_reg (addr);
1246 }
1247
1248 stack_temps[ (int)mode ] = temp;
1249 }
1250
1251 return temp;
1252 }
1253
1254 \f
1255 /* Generate a memory reference for expand_block_move, copying volatile,
1256 and other bits from an original memory reference. */
1257
1258 static rtx
1259 expand_block_move_mem (mode, addr, orig_mem)
1260 enum machine_mode mode;
1261 rtx addr;
1262 rtx orig_mem;
1263 {
1264 rtx mem = gen_rtx (MEM, mode, addr);
1265
1266 RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (orig_mem);
1267 MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (orig_mem);
1268 MEM_IN_STRUCT_P (mem) = MEM_IN_STRUCT_P (orig_mem);
1269 #ifdef MEM_UNALIGNED_P
1270 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
1271 #endif
1272 return mem;
1273 }
1274
1275 /* Expand a block move operation, and return 1 if successful. Return 0
1276 if we should let the compiler generate normal code.
1277
1278 operands[0] is the destination
1279 operands[1] is the source
1280 operands[2] is the length
1281 operands[3] is the alignment */
1282
1283 #define MAX_MOVE_REG 4
1284
1285 int
1286 expand_block_move (operands)
1287 rtx operands[];
1288 {
1289 rtx orig_dest = operands[0];
1290 rtx orig_src = operands[1];
1291 rtx bytes_rtx = operands[2];
1292 rtx align_rtx = operands[3];
1293 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
1294 int align = XINT (align_rtx, 0);
1295 int bytes;
1296 int offset;
1297 int num_reg;
1298 int i;
1299 rtx src_reg;
1300 rtx dest_reg;
1301 rtx src_addr;
1302 rtx dest_addr;
1303 rtx tmp_reg;
1304 rtx stores[MAX_MOVE_REG];
1305 int move_bytes;
1306
1307 /* If this is not a fixed size move, just call memcpy */
1308 if (!constp)
1309 return 0;
1310
1311 /* Anything to move? */
1312 bytes = INTVAL (bytes_rtx);
1313 if (bytes <= 0)
1314 return 1;
1315
1316 /* Don't support real large moves. If string instructions are not used,
1317 then don't generate more than 8 loads. */
1318 if (TARGET_STRING)
1319 {
1320 if (bytes > 4*8)
1321 return 0;
1322 }
1323 else if (!STRICT_ALIGNMENT)
1324 {
1325 if (bytes > 4*8)
1326 return 0;
1327 }
1328 else if (bytes > 8*align)
1329 return 0;
1330
1331 /* Move the address into scratch registers. */
1332 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
1333 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
1334
1335 if (TARGET_STRING) /* string instructions are available */
1336 {
1337 for ( ; bytes > 0; bytes -= move_bytes)
1338 {
1339 if (bytes > 24 /* move up to 32 bytes at a time */
1340 && !fixed_regs[5]
1341 && !fixed_regs[6]
1342 && !fixed_regs[7]
1343 && !fixed_regs[8]
1344 && !fixed_regs[9]
1345 && !fixed_regs[10]
1346 && !fixed_regs[11]
1347 && !fixed_regs[12])
1348 {
1349 move_bytes = (bytes > 32) ? 32 : bytes;
1350 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1351 expand_block_move_mem (BLKmode, src_reg, orig_src),
1352 GEN_INT ((move_bytes == 32) ? 0 : move_bytes),
1353 align_rtx));
1354 }
1355 else if (bytes > 16 /* move up to 24 bytes at a time */
1356 && !fixed_regs[7]
1357 && !fixed_regs[8]
1358 && !fixed_regs[9]
1359 && !fixed_regs[10]
1360 && !fixed_regs[11]
1361 && !fixed_regs[12])
1362 {
1363 move_bytes = (bytes > 24) ? 24 : bytes;
1364 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1365 expand_block_move_mem (BLKmode, src_reg, orig_src),
1366 GEN_INT (move_bytes),
1367 align_rtx));
1368 }
1369 else if (bytes > 8 /* move up to 16 bytes at a time */
1370 && !fixed_regs[9]
1371 && !fixed_regs[10]
1372 && !fixed_regs[11]
1373 && !fixed_regs[12])
1374 {
1375 move_bytes = (bytes > 16) ? 16 : bytes;
1376 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1377 expand_block_move_mem (BLKmode, src_reg, orig_src),
1378 GEN_INT (move_bytes),
1379 align_rtx));
1380 }
1381 else if (bytes > 4 && !TARGET_64BIT)
1382 { /* move up to 8 bytes at a time */
1383 move_bytes = (bytes > 8) ? 8 : bytes;
1384 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1385 expand_block_move_mem (BLKmode, src_reg, orig_src),
1386 GEN_INT (move_bytes),
1387 align_rtx));
1388 }
1389 else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
1390 { /* move 4 bytes */
1391 move_bytes = 4;
1392 tmp_reg = gen_reg_rtx (SImode);
1393 emit_move_insn (tmp_reg, expand_block_move_mem (SImode, src_reg, orig_src));
1394 emit_move_insn (expand_block_move_mem (SImode, dest_reg, orig_dest), tmp_reg);
1395 }
1396 else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT))
1397 { /* move 2 bytes */
1398 move_bytes = 2;
1399 tmp_reg = gen_reg_rtx (HImode);
1400 emit_move_insn (tmp_reg, expand_block_move_mem (HImode, src_reg, orig_src));
1401 emit_move_insn (expand_block_move_mem (HImode, dest_reg, orig_dest), tmp_reg);
1402 }
1403 else if (bytes == 1) /* move 1 byte */
1404 {
1405 move_bytes = 1;
1406 tmp_reg = gen_reg_rtx (QImode);
1407 emit_move_insn (tmp_reg, expand_block_move_mem (QImode, src_reg, orig_src));
1408 emit_move_insn (expand_block_move_mem (QImode, dest_reg, orig_dest), tmp_reg);
1409 }
1410 else
1411 { /* move up to 4 bytes at a time */
1412 move_bytes = (bytes > 4) ? 4 : bytes;
1413 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
1414 expand_block_move_mem (BLKmode, src_reg, orig_src),
1415 GEN_INT (move_bytes),
1416 align_rtx));
1417 }
1418
1419 if (bytes > move_bytes)
1420 {
1421 emit_insn (gen_addsi3 (src_reg, src_reg, GEN_INT (move_bytes)));
1422 emit_insn (gen_addsi3 (dest_reg, dest_reg, GEN_INT (move_bytes)));
1423 }
1424 }
1425 }
1426
1427 else /* string instructions not available */
1428 {
1429 num_reg = offset = 0;
1430 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
1431 {
1432 /* Calculate the correct offset for src/dest */
1433 if (offset == 0)
1434 {
1435 src_addr = src_reg;
1436 dest_addr = dest_reg;
1437 }
1438 else
1439 {
1440 src_addr = gen_rtx (PLUS, Pmode, src_reg, GEN_INT (offset));
1441 dest_addr = gen_rtx (PLUS, Pmode, dest_reg, GEN_INT (offset));
1442 }
1443
1444 /* Generate the appropriate load and store, saving the stores for later */
1445 if (bytes >= 8 && TARGET_64BIT && (align >= 8 || !STRICT_ALIGNMENT))
1446 {
1447 move_bytes = 8;
1448 tmp_reg = gen_reg_rtx (DImode);
1449 emit_insn (gen_movdi (tmp_reg, expand_block_move_mem (DImode, src_addr, orig_src)));
1450 stores[ num_reg++ ] = gen_movdi (expand_block_move_mem (DImode, dest_addr, orig_dest), tmp_reg);
1451 }
1452 else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
1453 {
1454 move_bytes = 4;
1455 tmp_reg = gen_reg_rtx (SImode);
1456 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (SImode, src_addr, orig_src)));
1457 stores[ num_reg++ ] = gen_movsi (expand_block_move_mem (SImode, dest_addr, orig_dest), tmp_reg);
1458 }
1459 else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT))
1460 {
1461 move_bytes = 2;
1462 tmp_reg = gen_reg_rtx (HImode);
1463 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (HImode, src_addr, orig_src)));
1464 stores[ num_reg++ ] = gen_movhi (expand_block_move_mem (HImode, dest_addr, orig_dest), tmp_reg);
1465 }
1466 else
1467 {
1468 move_bytes = 1;
1469 tmp_reg = gen_reg_rtx (QImode);
1470 emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (QImode, src_addr, orig_src)));
1471 stores[ num_reg++ ] = gen_movqi (expand_block_move_mem (QImode, dest_addr, orig_dest), tmp_reg);
1472 }
1473
1474 if (num_reg >= MAX_MOVE_REG)
1475 {
1476 for (i = 0; i < num_reg; i++)
1477 emit_insn (stores[i]);
1478 num_reg = 0;
1479 }
1480 }
1481
1482 for (i = 0; i < num_reg; i++)
1483 emit_insn (stores[i]);
1484 }
1485
1486 return 1;
1487 }
1488
1489 \f
1490 /* Return 1 if OP is a load multiple operation. It is known to be a
1491 PARALLEL and the first section will be tested. */
1492
1493 int
1494 load_multiple_operation (op, mode)
1495 rtx op;
1496 enum machine_mode mode;
1497 {
1498 int count = XVECLEN (op, 0);
1499 int dest_regno;
1500 rtx src_addr;
1501 int i;
1502
1503 /* Perform a quick check so we don't blow up below. */
1504 if (count <= 1
1505 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1506 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1507 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1508 return 0;
1509
1510 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1511 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1512
1513 for (i = 1; i < count; i++)
1514 {
1515 rtx elt = XVECEXP (op, 0, i);
1516
1517 if (GET_CODE (elt) != SET
1518 || GET_CODE (SET_DEST (elt)) != REG
1519 || GET_MODE (SET_DEST (elt)) != SImode
1520 || REGNO (SET_DEST (elt)) != dest_regno + i
1521 || GET_CODE (SET_SRC (elt)) != MEM
1522 || GET_MODE (SET_SRC (elt)) != SImode
1523 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
1524 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
1525 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
1526 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
1527 return 0;
1528 }
1529
1530 return 1;
1531 }
1532
1533 /* Similar, but tests for store multiple. Here, the second vector element
1534 is a CLOBBER. It will be tested later. */
1535
1536 int
1537 store_multiple_operation (op, mode)
1538 rtx op;
1539 enum machine_mode mode;
1540 {
1541 int count = XVECLEN (op, 0) - 1;
1542 int src_regno;
1543 rtx dest_addr;
1544 int i;
1545
1546 /* Perform a quick check so we don't blow up below. */
1547 if (count <= 1
1548 || GET_CODE (XVECEXP (op, 0, 0)) != SET
1549 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1550 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1551 return 0;
1552
1553 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1554 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1555
1556 for (i = 1; i < count; i++)
1557 {
1558 rtx elt = XVECEXP (op, 0, i + 1);
1559
1560 if (GET_CODE (elt) != SET
1561 || GET_CODE (SET_SRC (elt)) != REG
1562 || GET_MODE (SET_SRC (elt)) != SImode
1563 || REGNO (SET_SRC (elt)) != src_regno + i
1564 || GET_CODE (SET_DEST (elt)) != MEM
1565 || GET_MODE (SET_DEST (elt)) != SImode
1566 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
1567 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
1568 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
1569 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
1570 return 0;
1571 }
1572
1573 return 1;
1574 }
1575 \f
1576 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
1577 We only check the opcode against the mode of the CC value here. */
1578
1579 int
1580 branch_comparison_operator (op, mode)
1581 register rtx op;
1582 enum machine_mode mode;
1583 {
1584 enum rtx_code code = GET_CODE (op);
1585 enum machine_mode cc_mode;
1586
1587 if (GET_RTX_CLASS (code) != '<')
1588 return 0;
1589
1590 cc_mode = GET_MODE (XEXP (op, 0));
1591 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
1592 return 0;
1593
1594 if ((code == GT || code == LT || code == GE || code == LE)
1595 && cc_mode == CCUNSmode)
1596 return 0;
1597
1598 if ((code == GTU || code == LTU || code == GEU || code == LEU)
1599 && (cc_mode != CCUNSmode))
1600 return 0;
1601
1602 return 1;
1603 }
1604
1605 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
1606 We check the opcode against the mode of the CC value and disallow EQ or
1607 NE comparisons for integers. */
1608
1609 int
1610 scc_comparison_operator (op, mode)
1611 register rtx op;
1612 enum machine_mode mode;
1613 {
1614 enum rtx_code code = GET_CODE (op);
1615 enum machine_mode cc_mode;
1616
1617 if (GET_MODE (op) != mode && mode != VOIDmode)
1618 return 0;
1619
1620 if (GET_RTX_CLASS (code) != '<')
1621 return 0;
1622
1623 cc_mode = GET_MODE (XEXP (op, 0));
1624 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
1625 return 0;
1626
1627 if (code == NE && cc_mode != CCFPmode)
1628 return 0;
1629
1630 if ((code == GT || code == LT || code == GE || code == LE)
1631 && cc_mode == CCUNSmode)
1632 return 0;
1633
1634 if ((code == GTU || code == LTU || code == GEU || code == LEU)
1635 && (cc_mode != CCUNSmode))
1636 return 0;
1637
1638 if (cc_mode == CCEQmode && code != EQ && code != NE)
1639 return 0;
1640
1641 return 1;
1642 }
1643 \f
1644 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
1645 mask required to convert the result of a rotate insn into a shift
1646 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
1647
1648 int
1649 includes_lshift_p (shiftop, andop)
1650 register rtx shiftop;
1651 register rtx andop;
1652 {
1653 int shift_mask = (~0 << INTVAL (shiftop));
1654
1655 return (INTVAL (andop) & ~shift_mask) == 0;
1656 }
1657
1658 /* Similar, but for right shift. */
1659
1660 int
1661 includes_rshift_p (shiftop, andop)
1662 register rtx shiftop;
1663 register rtx andop;
1664 {
1665 unsigned shift_mask = ~0;
1666
1667 shift_mask >>= INTVAL (shiftop);
1668
1669 return (INTVAL (andop) & ~ shift_mask) == 0;
1670 }
1671
1672 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
1673 for lfq and stfq insns.
1674
1675 Note reg1 and reg2 *must* be hard registers. To be sure we will
1676 abort if we are passed pseudo registers. */
1677
1678 int
1679 registers_ok_for_quad_peep (reg1, reg2)
1680 rtx reg1, reg2;
1681 {
1682 /* We might have been passed a SUBREG. */
1683 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
1684 return 0;
1685
1686 return (REGNO (reg1) == REGNO (reg2) - 1);
1687 }
1688
1689 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
1690 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
1691
1692 int
1693 addrs_ok_for_quad_peep (addr1, addr2)
1694 register rtx addr1;
1695 register rtx addr2;
1696 {
1697 int reg1;
1698 int offset1;
1699
1700 /* Extract an offset (if used) from the first addr. */
1701 if (GET_CODE (addr1) == PLUS)
1702 {
1703 /* If not a REG, return zero. */
1704 if (GET_CODE (XEXP (addr1, 0)) != REG)
1705 return 0;
1706 else
1707 {
1708 reg1 = REGNO (XEXP (addr1, 0));
1709 /* The offset must be constant! */
1710 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
1711 return 0;
1712 offset1 = INTVAL (XEXP (addr1, 1));
1713 }
1714 }
1715 else if (GET_CODE (addr1) != REG)
1716 return 0;
1717 else
1718 {
1719 reg1 = REGNO (addr1);
1720 /* This was a simple (mem (reg)) expression. Offset is 0. */
1721 offset1 = 0;
1722 }
1723
1724 /* Make sure the second address is a (mem (plus (reg) (const_int). */
1725 if (GET_CODE (addr2) != PLUS)
1726 return 0;
1727
1728 if (GET_CODE (XEXP (addr2, 0)) != REG
1729 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
1730 return 0;
1731
1732 if (reg1 != REGNO (XEXP (addr2, 0)))
1733 return 0;
1734
1735 /* The offset for the second addr must be 8 more than the first addr. */
1736 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
1737 return 0;
1738
1739 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
1740 instructions. */
1741 return 1;
1742 }
1743 \f
1744 /* Return the register class of a scratch register needed to copy IN into
1745 or out of a register in CLASS in MODE. If it can be done directly,
1746 NO_REGS is returned. */
1747
1748 enum reg_class
1749 secondary_reload_class (class, mode, in)
1750 enum reg_class class;
1751 enum machine_mode mode;
1752 rtx in;
1753 {
1754 int regno = true_regnum (in);
1755
1756 if (regno >= FIRST_PSEUDO_REGISTER)
1757 regno = -1;
1758
1759 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
1760 into anything. */
1761 if (class == GENERAL_REGS || class == BASE_REGS
1762 || (regno >= 0 && INT_REGNO_P (regno)))
1763 return NO_REGS;
1764
1765 /* Constants, memory, and FP registers can go into FP registers. */
1766 if ((regno == -1 || FP_REGNO_P (regno))
1767 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
1768 return NO_REGS;
1769
1770 /* We can copy among the CR registers. */
1771 if ((class == CR_REGS || class == CR0_REGS)
1772 && regno >= 0 && CR_REGNO_P (regno))
1773 return NO_REGS;
1774
1775 /* Otherwise, we need GENERAL_REGS. */
1776 return GENERAL_REGS;
1777 }
1778 \f
1779 /* Given a comparison operation, return the bit number in CCR to test. We
1780 know this is a valid comparison.
1781
1782 SCC_P is 1 if this is for an scc. That means that %D will have been
1783 used instead of %C, so the bits will be in different places.
1784
1785 Return -1 if OP isn't a valid comparison for some reason. */
1786
1787 int
1788 ccr_bit (op, scc_p)
1789 register rtx op;
1790 int scc_p;
1791 {
1792 enum rtx_code code = GET_CODE (op);
1793 enum machine_mode cc_mode;
1794 int cc_regnum;
1795 int base_bit;
1796
1797 if (GET_RTX_CLASS (code) != '<')
1798 return -1;
1799
1800 cc_mode = GET_MODE (XEXP (op, 0));
1801 cc_regnum = REGNO (XEXP (op, 0));
1802 base_bit = 4 * (cc_regnum - 68);
1803
1804 /* In CCEQmode cases we have made sure that the result is always in the
1805 third bit of the CR field. */
1806
1807 if (cc_mode == CCEQmode)
1808 return base_bit + 3;
1809
1810 switch (code)
1811 {
1812 case NE:
1813 return scc_p ? base_bit + 3 : base_bit + 2;
1814 case EQ:
1815 return base_bit + 2;
1816 case GT: case GTU:
1817 return base_bit + 1;
1818 case LT: case LTU:
1819 return base_bit;
1820
1821 case GE: case GEU:
1822 /* If floating-point, we will have done a cror to put the bit in the
1823 unordered position. So test that bit. For integer, this is ! LT
1824 unless this is an scc insn. */
1825 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
1826
1827 case LE: case LEU:
1828 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
1829
1830 default:
1831 abort ();
1832 }
1833 }
1834 \f
1835 /* Print an operand. Recognize special options, documented below. */
1836
1837 void
1838 print_operand (file, x, code)
1839 FILE *file;
1840 rtx x;
1841 char code;
1842 {
1843 int i;
1844 int val;
1845
1846 /* These macros test for integers and extract the low-order bits. */
1847 #define INT_P(X) \
1848 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
1849 && GET_MODE (X) == VOIDmode)
1850
1851 #define INT_LOWPART(X) \
1852 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
1853
1854 switch (code)
1855 {
1856 case '.':
1857 /* Write out an instruction after the call which may be replaced
1858 with glue code by the loader. This depends on the AIX version. */
1859 asm_fprintf (file, RS6000_CALL_GLUE);
1860 return;
1861
1862 case '*':
1863 /* Write the register number of the TOC register. */
1864 fputs (TARGET_MINIMAL_TOC ? reg_names[30] : reg_names[2], file);
1865 return;
1866
1867 case 'A':
1868 /* If X is a constant integer whose low-order 5 bits are zero,
1869 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
1870 in the AIX assembler where "sri" with a zero shift count
1871 write a trash instruction. */
1872 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
1873 putc ('l', file);
1874 else
1875 putc ('r', file);
1876 return;
1877
1878 case 'b':
1879 /* Low-order 16 bits of constant, unsigned. */
1880 if (! INT_P (x))
1881 output_operand_lossage ("invalid %%b value");
1882
1883 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
1884 return;
1885
1886 case 'C':
1887 /* This is an optional cror needed for LE or GE floating-point
1888 comparisons. Otherwise write nothing. */
1889 if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
1890 && GET_MODE (XEXP (x, 0)) == CCFPmode)
1891 {
1892 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
1893
1894 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
1895 base_bit + 2, base_bit + (GET_CODE (x) == GE));
1896 }
1897 return;
1898
1899 case 'D':
1900 /* Similar, except that this is for an scc, so we must be able to
1901 encode the test in a single bit that is one. We do the above
1902 for any LE, GE, GEU, or LEU and invert the bit for NE. */
1903 if (GET_CODE (x) == LE || GET_CODE (x) == GE
1904 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
1905 {
1906 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
1907
1908 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
1909 base_bit + 2,
1910 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
1911 }
1912
1913 else if (GET_CODE (x) == NE)
1914 {
1915 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
1916
1917 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
1918 base_bit + 2, base_bit + 2);
1919 }
1920 return;
1921
1922 case 'E':
1923 /* X is a CR register. Print the number of the third bit of the CR */
1924 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1925 output_operand_lossage ("invalid %%E value");
1926
1927 fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
1928 return;
1929
1930 case 'f':
1931 /* X is a CR register. Print the shift count needed to move it
1932 to the high-order four bits. */
1933 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1934 output_operand_lossage ("invalid %%f value");
1935 else
1936 fprintf (file, "%d", 4 * (REGNO (x) - 68));
1937 return;
1938
1939 case 'F':
1940 /* Similar, but print the count for the rotate in the opposite
1941 direction. */
1942 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1943 output_operand_lossage ("invalid %%F value");
1944 else
1945 fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
1946 return;
1947
1948 case 'G':
1949 /* X is a constant integer. If it is negative, print "m",
1950 otherwise print "z". This is to make a aze or ame insn. */
1951 if (GET_CODE (x) != CONST_INT)
1952 output_operand_lossage ("invalid %%G value");
1953 else if (INTVAL (x) >= 0)
1954 putc ('z', file);
1955 else
1956 putc ('m', file);
1957 return;
1958
1959 case 'h':
1960 /* If constant, output low-order five bits. Otherwise,
1961 write normally. */
1962 if (INT_P (x))
1963 fprintf (file, "%d", INT_LOWPART (x) & 31);
1964 else
1965 print_operand (file, x, 0);
1966 return;
1967
1968 case 'I':
1969 /* Print `i' if this is a constant, else nothing. */
1970 if (INT_P (x))
1971 putc ('i', file);
1972 return;
1973
1974 case 'j':
1975 /* Write the bit number in CCR for jump. */
1976 i = ccr_bit (x, 0);
1977 if (i == -1)
1978 output_operand_lossage ("invalid %%j code");
1979 else
1980 fprintf (file, "%d", i);
1981 return;
1982
1983 case 'J':
1984 /* Similar, but add one for shift count in rlinm for scc and pass
1985 scc flag to `ccr_bit'. */
1986 i = ccr_bit (x, 1);
1987 if (i == -1)
1988 output_operand_lossage ("invalid %%J code");
1989 else
1990 /* If we want bit 31, write a shift count of zero, not 32. */
1991 fprintf (file, "%d", i == 31 ? 0 : i + 1);
1992 return;
1993
1994 case 'k':
1995 /* X must be a constant. Write the 1's complement of the
1996 constant. */
1997 if (! INT_P (x))
1998 output_operand_lossage ("invalid %%k value");
1999
2000 fprintf (file, "%d", ~ INT_LOWPART (x));
2001 return;
2002
2003 case 'L':
2004 /* Write second word of DImode or DFmode reference. Works on register
2005 or non-indexed memory only. */
2006 if (GET_CODE (x) == REG)
2007 fprintf (file, "%d", REGNO (x) + 1);
2008 else if (GET_CODE (x) == MEM)
2009 {
2010 /* Handle possible auto-increment. Since it is pre-increment and
2011 we have already done it, we can just use an offset of four. */
2012 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2013 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2014 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
2015 else
2016 output_address (plus_constant (XEXP (x, 0), 4));
2017 }
2018 return;
2019
2020 case 'm':
2021 /* MB value for a mask operand. */
2022 if (! mask_operand (x, VOIDmode))
2023 output_operand_lossage ("invalid %%m value");
2024
2025 val = INT_LOWPART (x);
2026
2027 /* If the high bit is set and the low bit is not, the value is zero.
2028 If the high bit is zero, the value is the first 1 bit we find from
2029 the left. */
2030 if (val < 0 && (val & 1) == 0)
2031 {
2032 fprintf (file, "0");
2033 return;
2034 }
2035 else if (val >= 0)
2036 {
2037 for (i = 1; i < 32; i++)
2038 if ((val <<= 1) < 0)
2039 break;
2040 fprintf (file, "%d", i);
2041 return;
2042 }
2043
2044 /* Otherwise, look for the first 0 bit from the right. The result is its
2045 number plus 1. We know the low-order bit is one. */
2046 for (i = 0; i < 32; i++)
2047 if (((val >>= 1) & 1) == 0)
2048 break;
2049
2050 /* If we ended in ...01, I would be 0. The correct value is 31, so
2051 we want 31 - i. */
2052 fprintf (file, "%d", 31 - i);
2053 return;
2054
2055 case 'M':
2056 /* ME value for a mask operand. */
2057 if (! mask_operand (x, VOIDmode))
2058 output_operand_lossage ("invalid %%m value");
2059
2060 val = INT_LOWPART (x);
2061
2062 /* If the low bit is set and the high bit is not, the value is 31.
2063 If the low bit is zero, the value is the first 1 bit we find from
2064 the right. */
2065 if ((val & 1) && val >= 0)
2066 {
2067 fputs ("31", file);
2068 return;
2069 }
2070 else if ((val & 1) == 0)
2071 {
2072 for (i = 0; i < 32; i++)
2073 if ((val >>= 1) & 1)
2074 break;
2075
2076 /* If we had ....10, I would be 0. The result should be
2077 30, so we need 30 - i. */
2078 fprintf (file, "%d", 30 - i);
2079 return;
2080 }
2081
2082 /* Otherwise, look for the first 0 bit from the left. The result is its
2083 number minus 1. We know the high-order bit is one. */
2084 for (i = 0; i < 32; i++)
2085 if ((val <<= 1) >= 0)
2086 break;
2087
2088 fprintf (file, "%d", i);
2089 return;
2090
2091 case 'N':
2092 /* Write the number of elements in the vector times 4. */
2093 if (GET_CODE (x) != PARALLEL)
2094 output_operand_lossage ("invalid %%N value");
2095
2096 fprintf (file, "%d", XVECLEN (x, 0) * 4);
2097 return;
2098
2099 case 'O':
2100 /* Similar, but subtract 1 first. */
2101 if (GET_CODE (x) != PARALLEL)
2102 output_operand_lossage ("invalid %%N value");
2103
2104 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
2105 return;
2106
2107 case 'p':
2108 /* X is a CONST_INT that is a power of two. Output the logarithm. */
2109 if (! INT_P (x)
2110 || (i = exact_log2 (INT_LOWPART (x))) < 0)
2111 output_operand_lossage ("invalid %%p value");
2112
2113 fprintf (file, "%d", i);
2114 return;
2115
2116 case 'P':
2117 /* The operand must be an indirect memory reference. The result
2118 is the register number. */
2119 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
2120 || REGNO (XEXP (x, 0)) >= 32)
2121 output_operand_lossage ("invalid %%P value");
2122
2123 fprintf (file, "%d", REGNO (XEXP (x, 0)));
2124 return;
2125
2126 case 'R':
2127 /* X is a CR register. Print the mask for `mtcrf'. */
2128 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
2129 output_operand_lossage ("invalid %%R value");
2130 else
2131 fprintf (file, "%d", 128 >> (REGNO (x) - 68));
2132 return;
2133
2134 case 's':
2135 /* Low 5 bits of 32 - value */
2136 if (! INT_P (x))
2137 output_operand_lossage ("invalid %%s value");
2138
2139 fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
2140 return;
2141
2142 case 't':
2143 /* Write 12 if this jump operation will branch if true, 4 otherwise.
2144 All floating-point operations except NE branch true and integer
2145 EQ, LT, GT, LTU and GTU also branch true. */
2146 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
2147 output_operand_lossage ("invalid %%t value");
2148
2149 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
2150 && GET_CODE (x) != NE)
2151 || GET_CODE (x) == EQ
2152 || GET_CODE (x) == LT || GET_CODE (x) == GT
2153 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
2154 fputs ("12", file);
2155 else
2156 putc ('4', file);
2157 return;
2158
2159 case 'T':
2160 /* Opposite of 't': write 4 if this jump operation will branch if true,
2161 12 otherwise. */
2162 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
2163 output_operand_lossage ("invalid %%t value");
2164
2165 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
2166 && GET_CODE (x) != NE)
2167 || GET_CODE (x) == EQ
2168 || GET_CODE (x) == LT || GET_CODE (x) == GT
2169 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
2170 putc ('4', file);
2171 else
2172 fputs ("12", file);
2173 return;
2174
2175 case 'u':
2176 /* High-order 16 bits of constant. */
2177 if (! INT_P (x))
2178 output_operand_lossage ("invalid %%u value");
2179
2180 fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
2181 return;
2182
2183 case 'U':
2184 /* Print `u' if this has an auto-increment or auto-decrement. */
2185 if (GET_CODE (x) == MEM
2186 && (GET_CODE (XEXP (x, 0)) == PRE_INC
2187 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
2188 putc ('u', file);
2189 return;
2190
2191 case 'w':
2192 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
2193 normally. */
2194 if (INT_P (x))
2195 fprintf (file, "%d",
2196 (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
2197 else
2198 print_operand (file, x, 0);
2199 return;
2200
2201 case 'W':
2202 /* If constant, low-order 16 bits of constant, unsigned.
2203 Otherwise, write normally. */
2204 if (INT_P (x))
2205 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
2206 else
2207 print_operand (file, x, 0);
2208 return;
2209
2210 case 'X':
2211 if (GET_CODE (x) == MEM
2212 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
2213 putc ('x', file);
2214 return;
2215
2216 case 'Y':
2217 /* Like 'L', for third word of TImode */
2218 if (GET_CODE (x) == REG)
2219 fprintf (file, "%d", REGNO (x) + 2);
2220 else if (GET_CODE (x) == MEM)
2221 {
2222 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2223 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2224 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
2225 else
2226 output_address (plus_constant (XEXP (x, 0), 8));
2227 }
2228 return;
2229
2230 case 'z':
2231 /* X is a SYMBOL_REF. Write out the name preceded by a
2232 period and without any trailing data in brackets. Used for function
2233 names. If we are configured for System V (or the embedded ABI) on
2234 the PowerPC, do not emit the period, since those systems do not use
2235 TOCs and the like. */
2236 if (GET_CODE (x) != SYMBOL_REF)
2237 abort ();
2238
2239 if (XSTR (x, 0)[0] != '.')
2240 {
2241 switch (DEFAULT_ABI)
2242 {
2243 default:
2244 abort ();
2245
2246 case ABI_AIX:
2247 putc ('.', file);
2248 break;
2249
2250 case ABI_V4:
2251 case ABI_AIX_NODESC:
2252 break;
2253
2254 case ABI_NT:
2255 fputs ("..", file);
2256 break;
2257 }
2258 }
2259 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
2260 return;
2261
2262 case 'Z':
2263 /* Like 'L', for last word of TImode. */
2264 if (GET_CODE (x) == REG)
2265 fprintf (file, "%d", REGNO (x) + 3);
2266 else if (GET_CODE (x) == MEM)
2267 {
2268 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2269 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2270 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
2271 else
2272 output_address (plus_constant (XEXP (x, 0), 12));
2273 }
2274 return;
2275
2276 case 0:
2277 if (GET_CODE (x) == REG)
2278 fprintf (file, "%s", reg_names[REGNO (x)]);
2279 else if (GET_CODE (x) == MEM)
2280 {
2281 /* We need to handle PRE_INC and PRE_DEC here, since we need to
2282 know the width from the mode. */
2283 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
2284 fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
2285 REGNO (XEXP (XEXP (x, 0), 0)));
2286 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
2287 fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
2288 REGNO (XEXP (XEXP (x, 0), 0)));
2289 else
2290 output_address (XEXP (x, 0));
2291 }
2292 else
2293 output_addr_const (file, x);
2294 return;
2295
2296 default:
2297 output_operand_lossage ("invalid %%xn code");
2298 }
2299 }
2300 \f
2301 /* Print the address of an operand. */
2302
2303 void
2304 print_operand_address (file, x)
2305 FILE *file;
2306 register rtx x;
2307 {
2308 if (GET_CODE (x) == REG)
2309 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
2310 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2311 {
2312 output_addr_const (file, x);
2313 /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
2314 of the toc pointer. */
2315 #ifdef TARGET_NO_TOC
2316 if (TARGET_NO_TOC)
2317 ;
2318 else
2319 #endif
2320 fprintf (file, "(%s)", reg_names[ TARGET_MINIMAL_TOC ? 30 : 2 ]);
2321 }
2322 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
2323 {
2324 if (REGNO (XEXP (x, 0)) == 0)
2325 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
2326 reg_names[ REGNO (XEXP (x, 0)) ]);
2327 else
2328 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
2329 reg_names[ REGNO (XEXP (x, 1)) ]);
2330 }
2331 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2332 fprintf (file, "%d(%s)", INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
2333 else if (TARGET_ELF && !TARGET_64BIT && GET_CODE (x) == LO_SUM
2334 && GET_CODE (XEXP (x, 0)) == REG && CONSTANT_P (XEXP (x, 1)))
2335 {
2336 output_addr_const (file, XEXP (x, 1));
2337 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
2338 }
2339 else
2340 abort ();
2341 }
2342 \f
2343 /* This page contains routines that are used to determine what the function
2344 prologue and epilogue code will do and write them out. */
2345
2346 /* Return the first fixed-point register that is required to be saved. 32 if
2347 none. */
2348
2349 int
2350 first_reg_to_save ()
2351 {
2352 int first_reg;
2353
2354 /* Find lowest numbered live register. */
2355 for (first_reg = 13; first_reg <= 31; first_reg++)
2356 if (regs_ever_live[first_reg])
2357 break;
2358
2359 /* If profiling, then we must save/restore every register that contains
2360 a parameter before/after the .mcount call. Use registers from 30 down
2361 to 23 to do this. Don't use the frame pointer in reg 31.
2362
2363 For now, save enough room for all of the parameter registers. */
2364 if (DEFAULT_ABI == ABI_AIX && profile_flag)
2365 if (first_reg > 23)
2366 first_reg = 23;
2367
2368 return first_reg;
2369 }
2370
2371 /* Similar, for FP regs. */
2372
2373 int
2374 first_fp_reg_to_save ()
2375 {
2376 int first_reg;
2377
2378 /* Find lowest numbered live register. */
2379 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
2380 if (regs_ever_live[first_reg])
2381 break;
2382
2383 return first_reg;
2384 }
2385
2386 /* Return non-zero if this function makes calls. */
2387
2388 int
2389 rs6000_makes_calls ()
2390 {
2391 rtx insn;
2392
2393 /* If we are profiling, we will be making a call to mcount. */
2394 if (profile_flag)
2395 return 1;
2396
2397 for (insn = get_insns (); insn; insn = next_insn (insn))
2398 if (GET_CODE (insn) == CALL_INSN)
2399 return 1;
2400
2401 return 0;
2402 }
2403
2404 \f
2405 /* Calculate the stack information for the current function. This is
2406 complicated by having two separate calling sequences, the AIX calling
2407 sequence and the V.4 calling sequence.
2408
2409 AIX stack frames look like:
2410
2411 SP----> +---------------------------------------+
2412 | back chain to caller | 0
2413 +---------------------------------------+
2414 | saved CR | 4
2415 +---------------------------------------+
2416 | saved LR | 8
2417 +---------------------------------------+
2418 | reserved for compilers | 12
2419 +---------------------------------------+
2420 | reserved for binders | 16
2421 +---------------------------------------+
2422 | saved TOC pointer | 20
2423 +---------------------------------------+
2424 | Parameter save area (P) | 24
2425 +---------------------------------------+
2426 | Alloca space (A) | 24+P
2427 +---------------------------------------+
2428 | Local variable space (L) | 24+P+A
2429 +---------------------------------------+
2430 | Save area for GP registers (G) | 24+P+A+L
2431 +---------------------------------------+
2432 | Save area for FP registers (F) | 24+P+A+L+G
2433 +---------------------------------------+
2434 old SP->| back chain to caller's caller |
2435 +---------------------------------------+
2436
2437 V.4 stack frames look like:
2438
2439 SP----> +---------------------------------------+
2440 | back chain to caller | 0
2441 +---------------------------------------+
2442 | caller's saved LR | 4
2443 +---------------------------------------+
2444 | Parameter save area (P) | 8
2445 +---------------------------------------+
2446 | Alloca space (A) | 8+P
2447 +---------------------------------------+
2448 | Varargs save area (V) | 8+P+A
2449 +---------------------------------------+
2450 | Local variable space (L) | 8+P+A+V
2451 +---------------------------------------+
2452 | saved CR (C) | 8+P+A+V+L
2453 +---------------------------------------+
2454 | Save area for GP registers (G) | 8+P+A+V+L+C
2455 +---------------------------------------+
2456 | Save area for FP registers (F) | 8+P+A+V+L+C+G
2457 +---------------------------------------+
2458 old SP->| back chain to caller's caller |
2459 +---------------------------------------+
2460
2461
2462 A PowerPC Windows/NT frame looks like:
2463
2464 SP----> +---------------------------------------+
2465 | back chain to caller | 0
2466 +---------------------------------------+
2467 | reserved | 4
2468 +---------------------------------------+
2469 | reserved | 8
2470 +---------------------------------------+
2471 | reserved | 12
2472 +---------------------------------------+
2473 | reserved | 16
2474 +---------------------------------------+
2475 | reserved | 20
2476 +---------------------------------------+
2477 | Parameter save area (P) | 24
2478 +---------------------------------------+
2479 | Alloca space (A) | 24+P
2480 +---------------------------------------+
2481 | Local variable space (L) | 24+P+A
2482 +---------------------------------------+
2483 | Save area for FP registers (F) | 24+P+A+L
2484 +---------------------------------------+
2485 | Possible alignment area (X) | 24+P+A+L+F
2486 +---------------------------------------+
2487 | Save area for GP registers (G) | 24+P+A+L+F+X
2488 +---------------------------------------+
2489 | Save area for CR (C) | 24+P+A+L+F+X+G
2490 +---------------------------------------+
2491 | Save area for TOC (T) | 24+P+A+L+F+X+G+C
2492 +---------------------------------------+
2493 | Save area for LR (R) | 24+P+A+L+F+X+G+C+T
2494 +---------------------------------------+
2495 old SP->| back chain to caller's caller |
2496 +---------------------------------------+
2497
2498 For NT, there is no specific order to save the registers, but in
2499 order to support __builtin_return_address, the save area for the
2500 link register needs to be in a known place, so we use -4 off of the
2501 old SP. To support calls through pointers, we also allocate a
2502 fixed slot to store the TOC, -8 off the old SP. */
2503
2504 rs6000_stack_t *
2505 rs6000_stack_info ()
2506 {
2507 static rs6000_stack_t info, zero_info;
2508 rs6000_stack_t *info_ptr = &info;
2509 int reg_size = TARGET_64BIT ? 8 : 4;
2510 enum rs6000_abi abi;
2511 int total_raw_size;
2512
2513 /* Zero all fields portably */
2514 info = zero_info;
2515
2516 /* Select which calling sequence */
2517 info_ptr->abi = abi = DEFAULT_ABI;
2518
2519 /* Calculate which registers need to be saved & save area size */
2520 info_ptr->first_gp_reg_save = first_reg_to_save ();
2521 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
2522
2523 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
2524 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
2525
2526 /* Does this function call anything? */
2527 info_ptr->calls_p = rs6000_makes_calls ();
2528
2529 /* Do we need to allocate space to save the toc? */
2530 if (rs6000_save_toc_p)
2531 {
2532 info_ptr->toc_save_p = 1;
2533 info_ptr->toc_size = reg_size;
2534 }
2535
2536 /* If this is main and we need to call a function to set things up,
2537 save main's arguments around the call. */
2538 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main") == 0)
2539 {
2540 info_ptr->main_p = 1;
2541
2542 #ifdef NAME__MAIN
2543 if (DECL_ARGUMENTS (current_function_decl))
2544 {
2545 int i;
2546 tree arg;
2547
2548 info_ptr->main_save_p = 1;
2549 info_ptr->main_size = 0;
2550 info_ptr->calls_p = 1;
2551
2552 for ((i = 0), (arg = DECL_ARGUMENTS (current_function_decl));
2553 arg != NULL_TREE && i < 8;
2554 (arg = TREE_CHAIN (arg)), i++)
2555 {
2556 info_ptr->main_size += reg_size;
2557 }
2558 }
2559 #endif
2560 }
2561
2562 /* Determine if we need to save the link register */
2563 if (regs_ever_live[65] || profile_flag
2564 #ifdef TARGET_RELOCATABLE
2565 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
2566 #endif
2567 || (info_ptr->first_fp_reg_save != 64
2568 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
2569 || (abi == ABI_V4 && current_function_calls_alloca)
2570 || info_ptr->calls_p)
2571 {
2572 info_ptr->lr_save_p = 1;
2573 regs_ever_live[65] = 1;
2574 if (abi == ABI_NT)
2575 info_ptr->lr_size = reg_size;
2576 }
2577
2578 /* Determine if we need to save the condition code registers */
2579 if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72])
2580 {
2581 info_ptr->cr_save_p = 1;
2582 if (abi == ABI_V4 || abi == ABI_NT)
2583 info_ptr->cr_size = reg_size;
2584 }
2585
2586 /* Determine various sizes */
2587 info_ptr->reg_size = reg_size;
2588 info_ptr->fixed_size = RS6000_SAVE_AREA;
2589 info_ptr->varargs_size = RS6000_VARARGS_AREA;
2590 info_ptr->vars_size = ALIGN (get_frame_size (), 8);
2591 info_ptr->parm_size = ALIGN (current_function_outgoing_args_size, 8);
2592 info_ptr->save_size = ALIGN (info_ptr->fp_size
2593 + info_ptr->gp_size
2594 + info_ptr->cr_size
2595 + info_ptr->lr_size
2596 + info_ptr->toc_size
2597 + info_ptr->main_size, 8);
2598
2599 total_raw_size = (info_ptr->vars_size
2600 + info_ptr->parm_size
2601 + info_ptr->save_size
2602 + info_ptr->varargs_size
2603 + info_ptr->fixed_size);
2604
2605 info_ptr->total_size = ALIGN (total_raw_size, STACK_BOUNDARY / BITS_PER_UNIT);
2606
2607 /* Determine if we need to allocate any stack frame.
2608 For AIX We need to push the stack if a frame pointer is needed (because
2609 the stack might be dynamically adjusted), if we are debugging, if the
2610 total stack size is more than 220 bytes, or if we make calls.
2611
2612 For V.4 we don't have the stack cushion that AIX uses, but assume that
2613 the debugger can handle stackless frames. */
2614
2615 if (info_ptr->calls_p)
2616 info_ptr->push_p = 1;
2617
2618 else if (abi == ABI_V4 || abi == ABI_NT)
2619 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
2620 || info_ptr->lr_save_p);
2621
2622 else
2623 info_ptr->push_p = (frame_pointer_needed
2624 || write_symbols != NO_DEBUG
2625 || info_ptr->total_size > 220);
2626
2627 /* Calculate the offsets */
2628 switch (abi)
2629 {
2630 case ABI_NONE:
2631 default:
2632 abort ();
2633
2634 case ABI_AIX:
2635 case ABI_AIX_NODESC:
2636 info_ptr->fp_save_offset = - info_ptr->fp_size;
2637 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
2638 info_ptr->main_save_offset = info_ptr->gp_save_offset - info_ptr->main_size;
2639 info_ptr->cr_save_offset = 4;
2640 info_ptr->lr_save_offset = 8;
2641 break;
2642
2643 case ABI_V4:
2644 info_ptr->fp_save_offset = - info_ptr->fp_size;
2645 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
2646 info_ptr->cr_save_offset = info_ptr->gp_save_offset - reg_size;
2647 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->cr_size;
2648 info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size;
2649 info_ptr->lr_save_offset = reg_size;
2650 break;
2651
2652 case ABI_NT:
2653 info_ptr->lr_save_offset = -4;
2654 info_ptr->toc_save_offset = info_ptr->lr_save_offset - info_ptr->lr_size;
2655 info_ptr->cr_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size;
2656 info_ptr->gp_save_offset = info_ptr->cr_save_offset - info_ptr->cr_size - info_ptr->gp_size + reg_size;
2657 info_ptr->fp_save_offset = info_ptr->gp_save_offset - info_ptr->fp_size;
2658 if (info_ptr->fp_size && ((- info_ptr->fp_save_offset) % 8) != 0)
2659 info_ptr->fp_save_offset -= 4;
2660
2661 info_ptr->main_save_offset = info_ptr->fp_save_offset - info_ptr->main_size;
2662 break;
2663 }
2664
2665 /* Zero offsets if we're not saving those registers */
2666 if (!info_ptr->fp_size)
2667 info_ptr->fp_save_offset = 0;
2668
2669 if (!info_ptr->gp_size)
2670 info_ptr->gp_save_offset = 0;
2671
2672 if (!info_ptr->lr_save_p)
2673 info_ptr->lr_save_offset = 0;
2674
2675 if (!info_ptr->cr_save_p)
2676 info_ptr->cr_save_offset = 0;
2677
2678 if (!info_ptr->toc_save_p)
2679 info_ptr->toc_save_offset = 0;
2680
2681 if (!info_ptr->main_save_p)
2682 info_ptr->main_save_offset = 0;
2683
2684 return info_ptr;
2685 }
2686
2687 void
2688 debug_stack_info (info)
2689 rs6000_stack_t *info;
2690 {
2691 char *abi_string;
2692
2693 if (!info)
2694 info = rs6000_stack_info ();
2695
2696 fprintf (stderr, "\nStack information for function %s:\n",
2697 ((current_function_decl && DECL_NAME (current_function_decl))
2698 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
2699 : "<unknown>"));
2700
2701 switch (info->abi)
2702 {
2703 default: abi_string = "Unknown"; break;
2704 case ABI_NONE: abi_string = "NONE"; break;
2705 case ABI_AIX: abi_string = "AIX"; break;
2706 case ABI_AIX_NODESC: abi_string = "AIX"; break;
2707 case ABI_V4: abi_string = "V.4"; break;
2708 case ABI_NT: abi_string = "NT"; break;
2709 }
2710
2711 fprintf (stderr, "\tABI = %5s\n", abi_string);
2712
2713 if (info->first_gp_reg_save != 32)
2714 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
2715
2716 if (info->first_fp_reg_save != 64)
2717 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
2718
2719 if (info->lr_save_p)
2720 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
2721
2722 if (info->cr_save_p)
2723 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
2724
2725 if (info->toc_save_p)
2726 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
2727
2728 if (info->push_p)
2729 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
2730
2731 if (info->calls_p)
2732 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
2733
2734 if (info->main_p)
2735 fprintf (stderr, "\tmain_p = %5d\n", info->main_p);
2736
2737 if (info->main_save_p)
2738 fprintf (stderr, "\tmain_save_p = %5d\n", info->main_save_p);
2739
2740 if (info->gp_save_offset)
2741 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
2742
2743 if (info->fp_save_offset)
2744 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
2745
2746 if (info->lr_save_offset)
2747 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
2748
2749 if (info->cr_save_offset)
2750 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
2751
2752 if (info->toc_save_offset)
2753 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
2754
2755 if (info->varargs_save_offset)
2756 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
2757
2758 if (info->main_save_offset)
2759 fprintf (stderr, "\tmain_save_offset = %5d\n", info->main_save_offset);
2760
2761 if (info->total_size)
2762 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
2763
2764 if (info->varargs_size)
2765 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
2766
2767 if (info->vars_size)
2768 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
2769
2770 if (info->parm_size)
2771 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
2772
2773 if (info->fixed_size)
2774 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
2775
2776 if (info->gp_size)
2777 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
2778
2779 if (info->fp_size)
2780 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
2781
2782 if (info->lr_size)
2783 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
2784
2785 if (info->cr_size)
2786 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
2787
2788 if (info->toc_size)
2789 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
2790
2791 if (info->main_size)
2792 fprintf (stderr, "\tmain_size = %5d\n", info->main_size);
2793
2794 if (info->save_size)
2795 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
2796
2797 if (info->reg_size != 4)
2798 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
2799
2800 fprintf (stderr, "\n");
2801 }
2802
2803 \f
2804 /* Write function prologue. */
2805 void
2806 output_prolog (file, size)
2807 FILE *file;
2808 int size;
2809 {
2810 rs6000_stack_t *info = rs6000_stack_info ();
2811 int reg_size = info->reg_size;
2812 char *store_reg;
2813 char *load_reg;
2814
2815 if (TARGET_64BIT)
2816 {
2817 store_reg = "\tstd %s,%d(%s)";
2818 load_reg = "\tlld %s,%d(%s)";
2819 }
2820 else
2821 {
2822 store_reg = "\t{st|stw} %s,%d(%s)\n";
2823 load_reg = "\t{l|lwz} %s,%d(%s)\n";
2824 }
2825
2826 if (TARGET_DEBUG_STACK)
2827 debug_stack_info (info);
2828
2829 /* Write .extern for any function we will call to save and restore fp
2830 values. */
2831 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
2832 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
2833 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
2834 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
2835
2836 /* Write .extern for truncation routines, if needed. */
2837 if (rs6000_trunc_used && ! trunc_defined)
2838 {
2839 fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
2840 RS6000_ITRUNC, RS6000_UITRUNC);
2841 trunc_defined = 1;
2842 }
2843
2844 /* Write .extern for AIX common mode routines, if needed. */
2845 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
2846 {
2847 fputs ("\t.extern __mulh\n", file);
2848 fputs ("\t.extern __mull\n", file);
2849 fputs ("\t.extern __divss\n", file);
2850 fputs ("\t.extern __divus\n", file);
2851 fputs ("\t.extern __quoss\n", file);
2852 fputs ("\t.extern __quous\n", file);
2853 common_mode_defined = 1;
2854 }
2855
2856 /* If we use the link register, get it into r0. */
2857 if (info->lr_save_p)
2858 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
2859
2860 /* If we need to save CR, put it into r12. */
2861 if (info->cr_save_p)
2862 asm_fprintf (file, "\tmfcr %s\n", reg_names[12]);
2863
2864 /* Do any required saving of fpr's. If only one or two to save, do it
2865 ourself. Otherwise, call function. Note that since they are statically
2866 linked, we do not need a nop following them. */
2867 if (FP_SAVE_INLINE (info->first_fp_reg_save))
2868 {
2869 int regno = info->first_fp_reg_save;
2870 int loc = info->fp_save_offset;
2871
2872 for ( ; regno < 64; regno++, loc += 8)
2873 asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[1]);
2874 }
2875 else if (info->first_fp_reg_save != 64)
2876 asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX,
2877 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
2878
2879 /* Now save gpr's. */
2880 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
2881 {
2882 int regno = info->first_gp_reg_save;
2883 int loc = info->gp_save_offset;
2884
2885 for ( ; regno < 32; regno++, loc += reg_size)
2886 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[1]);
2887 }
2888
2889 else if (info->first_gp_reg_save != 32)
2890 asm_fprintf (file, "\t{stm|stmw} %s,%d(%s)\n",
2891 reg_names[info->first_gp_reg_save],
2892 info->gp_save_offset,
2893 reg_names[1]);
2894
2895 /* Save main's arguments if we need to call a function */
2896 #ifdef NAME__MAIN
2897 if (info->main_save_p)
2898 {
2899 int regno;
2900 int loc = info->main_save_offset;
2901 int size = info->main_size;
2902
2903 for (regno = 3; size > 0; regno++, loc -= reg_size, size -= reg_size)
2904 asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[1]);
2905 }
2906 #endif
2907
2908 /* Save lr if we used it. */
2909 if (info->lr_save_p)
2910 asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset, reg_names[1]);
2911
2912 /* Save CR if we use any that must be preserved. */
2913 if (info->cr_save_p)
2914 asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset, reg_names[1]);
2915
2916 if (info->toc_save_p)
2917 asm_fprintf (file, store_reg, reg_names[2], info->toc_save_offset, reg_names[1]);
2918
2919 /* Update stack and set back pointer. */
2920 if (info->push_p)
2921 {
2922 if (info->total_size < 32767)
2923 asm_fprintf (file,
2924 (TARGET_64BIT) ? "\tstdu %s,%d(%s)\n" : "\t{stu|stwu} %s,%d(%s)\n",
2925 reg_names[1], - info->total_size, reg_names[1]);
2926 else
2927 {
2928 int neg_size = - info->total_size;
2929 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
2930 reg_names[0], (neg_size >> 16) & 0xffff,
2931 reg_names[0], reg_names[0], neg_size & 0xffff);
2932 asm_fprintf (file,
2933 (TARGET_64BIT) ? "\tstdux %s,%s,%s\n" : "\t{stux|stwux} %s,%s,%s\n",
2934 reg_names[1], reg_names[1], reg_names[0]);
2935 }
2936 }
2937
2938 /* Set frame pointer, if needed. */
2939 if (frame_pointer_needed)
2940 asm_fprintf (file, "\tmr %s,%s\n", reg_names[31], reg_names[1]);
2941
2942 #ifdef NAME__MAIN
2943 /* If we need to call a function to set things up for main, do so now
2944 before dealing with the TOC. */
2945 if (info->main_p)
2946 {
2947 char *prefix = "";
2948
2949 switch (DEFAULT_ABI)
2950 {
2951 case ABI_AIX: prefix = "."; break;
2952 case ABI_NT: prefix = ".."; break;
2953 }
2954
2955 fprintf (file, "\tbl %s%s\n", prefix, NAME__MAIN);
2956 #ifdef RS6000_CALL_GLUE2
2957 fprintf (file, "\t%s%s%s\n", RS6000_CALL_GLUE2, prefix, NAME_MAIN);
2958 #else
2959 #ifdef RS6000_CALL_GLUE
2960 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
2961 fprintf (file, "\t%s\n", RS6000_CALL_GLUE);
2962 #endif
2963 #endif
2964
2965 if (info->main_save_p)
2966 {
2967 int regno;
2968 int loc;
2969 int size = info->main_size;
2970
2971 if (info->total_size < 32767)
2972 {
2973 loc = info->total_size + info->main_save_offset;
2974 for (regno = 3; size > 0; regno++, size -= reg_size, loc -= reg_size)
2975 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
2976 }
2977 else
2978 { /* for large frames, reg 0 above contains -frame size */
2979 loc = info->main_save_offset;
2980 asm_fprintf (file, "\t{sf|subf} %s,%s,%s\n", reg_names[0], reg_names[0],
2981 reg_names[1]);
2982
2983 for (regno = 3; size > 0; regno++, size -= reg_size, loc -= reg_size)
2984 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[0]);
2985 }
2986 }
2987 }
2988 #endif
2989
2990
2991 /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
2992 TOC_TABLE address into register 30. */
2993 if (TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
2994 {
2995 char buf[256];
2996
2997 #ifdef TARGET_RELOCATABLE
2998 if (TARGET_RELOCATABLE)
2999 {
3000 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3001 fprintf (file, "\tbl ");
3002 assemble_name (file, buf);
3003 fprintf (file, "\n");
3004
3005 ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
3006 fprintf (file, "\tmflr %s\n", reg_names[30]);
3007
3008 asm_fprintf (file, TARGET_64BIT ? "\tld" : "\t{l|lwz}");
3009 fprintf (file, " %s,(", reg_names[0]);
3010 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
3011 assemble_name (file, buf);
3012 fprintf (file, "-");
3013 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
3014 assemble_name (file, buf);
3015 fprintf (file, ")(%s)\n", reg_names[30]);
3016 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
3017 reg_names[30], reg_names[0], reg_names[30]);
3018 rs6000_pic_labelno++;
3019 }
3020 else
3021 #endif
3022
3023 switch (DEFAULT_ABI)
3024 {
3025 case ABI_V4:
3026 case ABI_AIX_NODESC:
3027 if (!TARGET_64BIT)
3028 {
3029 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
3030 asm_fprintf (file, "\t{cau|addis} %s,%s,", reg_names[30], reg_names[0]);
3031 assemble_name (file, buf);
3032 asm_fprintf (file, "@ha\n");
3033 if (TARGET_NEW_MNEMONICS)
3034 {
3035 asm_fprintf (file, "\taddi %s,%s,", reg_names[30], reg_names[30]);
3036 assemble_name (file, buf);
3037 asm_fprintf (file, "@l\n");
3038 }
3039 else
3040 {
3041 asm_fprintf (file, "\tcal %s,", reg_names[30]);
3042 assemble_name (file, buf);
3043 asm_fprintf (file, "@l(%s)\n", reg_names[30]);
3044 }
3045 }
3046 else
3047 abort ();
3048
3049 break;
3050
3051 case ABI_NT:
3052 case ABI_AIX:
3053 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
3054 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[30]);
3055 assemble_name (file, buf);
3056 asm_fprintf (file, "(%s)\n", reg_names[2]);
3057 break;
3058 }
3059 }
3060
3061 if (DEFAULT_ABI == ABI_NT)
3062 {
3063 assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3064 fputs (".b:\n", file);
3065 }
3066 }
3067
3068 /* Write function epilogue. */
3069
3070 void
3071 output_epilog (file, size)
3072 FILE *file;
3073 int size;
3074 {
3075 rs6000_stack_t *info = rs6000_stack_info ();
3076 char *load_reg = (TARGET_64BIT) ? "\tld %s,%d(%s)" : "\t{l|lwz} %s,%d(%s)\n";
3077 rtx insn = get_last_insn ();
3078 int i;
3079
3080 /* Forget about any temporaries created */
3081 for (i = 0; i < NUM_MACHINE_MODES; i++)
3082 stack_temps[i] = NULL_RTX;
3083
3084 /* If the last insn was a BARRIER, we don't have to write anything except
3085 the trace table. */
3086 if (GET_CODE (insn) == NOTE)
3087 insn = prev_nonnote_insn (insn);
3088 if (insn == 0 || GET_CODE (insn) != BARRIER)
3089 {
3090 /* If we have a frame pointer, a call to alloca, or a large stack
3091 frame, restore the old stack pointer using the backchain. Otherwise,
3092 we know what size to update it with. */
3093 if (frame_pointer_needed || current_function_calls_alloca
3094 || info->total_size > 32767)
3095 asm_fprintf (file, load_reg, reg_names[1], 0, reg_names[1]);
3096 else if (info->push_p)
3097 {
3098 if (TARGET_NEW_MNEMONICS)
3099 asm_fprintf (file, "\taddi %s,%s,%d\n", reg_names[1], reg_names[1], info->total_size);
3100 else
3101 asm_fprintf (file, "\tcal %s,%d(%s)\n", reg_names[1], info->total_size, reg_names[1]);
3102 }
3103
3104 /* Get the old lr if we saved it. */
3105 if (info->lr_save_p)
3106 asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset, reg_names[1]);
3107
3108 /* Get the old cr if we saved it. */
3109 if (info->cr_save_p)
3110 asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset, reg_names[1]);
3111
3112 /* Set LR here to try to overlap restores below. */
3113 if (info->lr_save_p)
3114 asm_fprintf (file, "\tmtlr %s\n", reg_names[0]);
3115
3116 /* Restore gpr's. */
3117 if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
3118 {
3119 int regno = info->first_gp_reg_save;
3120 int loc = info->gp_save_offset;
3121 int reg_size = (TARGET_64BIT) ? 8 : 4;
3122
3123 for ( ; regno < 32; regno++, loc += reg_size)
3124 asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
3125 }
3126
3127 else if (info->first_gp_reg_save != 32)
3128 asm_fprintf (file, "\t{lm|lmw} %s,%d(%s)\n",
3129 reg_names[info->first_gp_reg_save],
3130 info->gp_save_offset,
3131 reg_names[1]);
3132
3133 /* Restore fpr's if we can do it without calling a function. */
3134 if (FP_SAVE_INLINE (info->first_fp_reg_save))
3135 {
3136 int regno = info->first_fp_reg_save;
3137 int loc = info->fp_save_offset;
3138
3139 for ( ; regno < 64; regno++, loc += 8)
3140 asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[1]);
3141 }
3142
3143 /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4
3144 that were used. */
3145 if (info->cr_save_p)
3146 asm_fprintf (file, "\tmtcrf %d,%s\n",
3147 (regs_ever_live[70] != 0) * 0x20
3148 + (regs_ever_live[71] != 0) * 0x10
3149 + (regs_ever_live[72] != 0) * 0x8, reg_names[12]);
3150
3151 /* If we have to restore more than two FP registers, branch to the
3152 restore function. It will return to our caller. */
3153 if (info->first_fp_reg_save != 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
3154 asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX,
3155 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
3156 else
3157 asm_fprintf (file, "\t{br|blr}\n");
3158 }
3159
3160 /* Output a traceback table here. See /usr/include/sys/debug.h for info
3161 on its format.
3162
3163 We don't output a traceback table if -finhibit-size-directive was
3164 used. The documentation for -finhibit-size-directive reads
3165 ``don't output a @code{.size} assembler directive, or anything
3166 else that would cause trouble if the function is split in the
3167 middle, and the two halves are placed at locations far apart in
3168 memory.'' The traceback table has this property, since it
3169 includes the offset from the start of the function to the
3170 traceback table itself.
3171
3172 System V.4 Powerpc's (and the embedded ABI derived from it) use a
3173 different traceback table. */
3174 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
3175 {
3176 char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3177 int fixed_parms, float_parms, parm_info;
3178 int i;
3179
3180 while (*fname == '.') /* V.4 encodes . in the name */
3181 fname++;
3182
3183 /* Need label immediately before tbtab, so we can compute its offset
3184 from the function start. */
3185 if (*fname == '*')
3186 ++fname;
3187 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
3188 ASM_OUTPUT_LABEL (file, fname);
3189
3190 /* The .tbtab pseudo-op can only be used for the first eight
3191 expressions, since it can't handle the possibly variable
3192 length fields that follow. However, if you omit the optional
3193 fields, the assembler outputs zeros for all optional fields
3194 anyways, giving each variable length field is minimum length
3195 (as defined in sys/debug.h). Thus we can not use the .tbtab
3196 pseudo-op at all. */
3197
3198 /* An all-zero word flags the start of the tbtab, for debuggers
3199 that have to find it by searching forward from the entry
3200 point or from the current pc. */
3201 fprintf (file, "\t.long 0\n");
3202
3203 /* Tbtab format type. Use format type 0. */
3204 fprintf (file, "\t.byte 0,");
3205
3206 /* Language type. Unfortunately, there doesn't seem to be any
3207 official way to get this info, so we use language_string. C
3208 is 0. C++ is 9. No number defined for Obj-C, so use the
3209 value for C for now. */
3210 if (! strcmp (language_string, "GNU C")
3211 || ! strcmp (language_string, "GNU Obj-C"))
3212 i = 0;
3213 else if (! strcmp (language_string, "GNU F77"))
3214 i = 1;
3215 else if (! strcmp (language_string, "GNU Ada"))
3216 i = 3;
3217 else if (! strcmp (language_string, "GNU PASCAL"))
3218 i = 2;
3219 else if (! strcmp (language_string, "GNU C++"))
3220 i = 9;
3221 else
3222 abort ();
3223 fprintf (file, "%d,", i);
3224
3225 /* 8 single bit fields: global linkage (not set for C extern linkage,
3226 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
3227 from start of procedure stored in tbtab, internal function, function
3228 has controlled storage, function has no toc, function uses fp,
3229 function logs/aborts fp operations. */
3230 /* Assume that fp operations are used if any fp reg must be saved. */
3231 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
3232
3233 /* 6 bitfields: function is interrupt handler, name present in
3234 proc table, function calls alloca, on condition directives
3235 (controls stack walks, 3 bits), saves condition reg, saves
3236 link reg. */
3237 /* The `function calls alloca' bit seems to be set whenever reg 31 is
3238 set up as a frame pointer, even when there is no alloca call. */
3239 fprintf (file, "%d,",
3240 ((1 << 6) | (frame_pointer_needed << 5)
3241 | (info->cr_save_p << 1) | (info->lr_save_p)));
3242
3243 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
3244 (6 bits). */
3245 fprintf (file, "%d,",
3246 (info->push_p << 7) | (64 - info->first_fp_reg_save));
3247
3248 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
3249 fprintf (file, "%d,", (32 - first_reg_to_save ()));
3250
3251 {
3252 /* Compute the parameter info from the function decl argument
3253 list. */
3254 tree decl;
3255 int next_parm_info_bit;
3256
3257 next_parm_info_bit = 31;
3258 parm_info = 0;
3259 fixed_parms = 0;
3260 float_parms = 0;
3261
3262 for (decl = DECL_ARGUMENTS (current_function_decl);
3263 decl; decl = TREE_CHAIN (decl))
3264 {
3265 rtx parameter = DECL_INCOMING_RTL (decl);
3266 enum machine_mode mode = GET_MODE (parameter);
3267
3268 if (GET_CODE (parameter) == REG)
3269 {
3270 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
3271 {
3272 int bits;
3273
3274 float_parms++;
3275
3276 if (mode == SFmode)
3277 bits = 0x2;
3278 else if (mode == DFmode)
3279 bits = 0x3;
3280 else
3281 abort ();
3282
3283 /* If only one bit will fit, don't or in this entry. */
3284 if (next_parm_info_bit > 0)
3285 parm_info |= (bits << (next_parm_info_bit - 1));
3286 next_parm_info_bit -= 2;
3287 }
3288 else
3289 {
3290 fixed_parms += ((GET_MODE_SIZE (mode)
3291 + (UNITS_PER_WORD - 1))
3292 / UNITS_PER_WORD);
3293 next_parm_info_bit -= 1;
3294 }
3295 }
3296 }
3297 }
3298
3299 /* Number of fixed point parameters. */
3300 /* This is actually the number of words of fixed point parameters; thus
3301 an 8 byte struct counts as 2; and thus the maximum value is 8. */
3302 fprintf (file, "%d,", fixed_parms);
3303
3304 /* 2 bitfields: number of floating point parameters (7 bits), parameters
3305 all on stack. */
3306 /* This is actually the number of fp registers that hold parameters;
3307 and thus the maximum value is 13. */
3308 /* Set parameters on stack bit if parameters are not in their original
3309 registers, regardless of whether they are on the stack? Xlc
3310 seems to set the bit when not optimizing. */
3311 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
3312
3313 /* Optional fields follow. Some are variable length. */
3314
3315 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
3316 11 double float. */
3317 /* There is an entry for each parameter in a register, in the order that
3318 they occur in the parameter list. Any intervening arguments on the
3319 stack are ignored. If the list overflows a long (max possible length
3320 34 bits) then completely leave off all elements that don't fit. */
3321 /* Only emit this long if there was at least one parameter. */
3322 if (fixed_parms || float_parms)
3323 fprintf (file, "\t.long %d\n", parm_info);
3324
3325 /* Offset from start of code to tb table. */
3326 fprintf (file, "\t.long ");
3327 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
3328 RS6000_OUTPUT_BASENAME (file, fname);
3329 fprintf (file, "-.");
3330 RS6000_OUTPUT_BASENAME (file, fname);
3331 fprintf (file, "\n");
3332
3333 /* Interrupt handler mask. */
3334 /* Omit this long, since we never set the interrupt handler bit
3335 above. */
3336
3337 /* Number of CTL (controlled storage) anchors. */
3338 /* Omit this long, since the has_ctl bit is never set above. */
3339
3340 /* Displacement into stack of each CTL anchor. */
3341 /* Omit this list of longs, because there are no CTL anchors. */
3342
3343 /* Length of function name. */
3344 fprintf (file, "\t.short %d\n", strlen (fname));
3345
3346 /* Function name. */
3347 assemble_string (fname, strlen (fname));
3348
3349 /* Register for alloca automatic storage; this is always reg 31.
3350 Only emit this if the alloca bit was set above. */
3351 if (frame_pointer_needed)
3352 fprintf (file, "\t.byte 31\n");
3353 }
3354
3355 /* Reset varargs and save TOC indicator */
3356 rs6000_sysv_varargs_p = 0;
3357 rs6000_save_toc_p = 0;
3358
3359 if (DEFAULT_ABI == ABI_NT)
3360 {
3361 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3362 fputs (".e:\nFE_MOT_RESVD..", file);
3363 RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3364 fputs (":\n", file);
3365 }
3366 }
3367 \f
3368 /* Output a TOC entry. We derive the entry name from what is
3369 being written. */
3370
3371 void
3372 output_toc (file, x, labelno)
3373 FILE *file;
3374 rtx x;
3375 int labelno;
3376 {
3377 char buf[256];
3378 char *name = buf;
3379 char *real_name;
3380 rtx base = x;
3381 int offset = 0;
3382
3383 if (TARGET_NO_TOC)
3384 abort ();
3385
3386 /* if we're going to put a double constant in the TOC, make sure it's
3387 aligned properly when strict alignment is on. */
3388 if (GET_CODE (x) == CONST_DOUBLE
3389 && STRICT_ALIGNMENT
3390 && GET_MODE (x) == DFmode
3391 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
3392 ASM_OUTPUT_ALIGN (file, 3);
3393 }
3394
3395
3396 if (TARGET_ELF && TARGET_MINIMAL_TOC)
3397 {
3398 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
3399 fprintf (file, "%d = .-", labelno);
3400 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
3401 fprintf (file, "1\n");
3402 }
3403 else
3404 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
3405
3406 /* Handle FP constants specially. Note that if we have a minimal
3407 TOC, things we put here aren't actually in the TOC, so we can allow
3408 FP constants. */
3409 if (GET_CODE (x) == CONST_DOUBLE
3410 && GET_MODE (x) == DFmode
3411 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
3412 {
3413 REAL_VALUE_TYPE r;
3414 long l[2];
3415
3416 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3417 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3418 if (TARGET_MINIMAL_TOC)
3419 fprintf (file, "\t.long %ld\n\t.long %ld\n", l[0], l[1]);
3420 else
3421 fprintf (file, "\t.tc FD_%lx_%lx[TC],%ld,%ld\n",
3422 l[0], l[1], l[0], l[1]);
3423 return;
3424 }
3425 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
3426 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
3427 {
3428 rtx val = operand_subword (x, 0, 0, SFmode);
3429
3430 if (val == 0 || GET_CODE (val) != CONST_INT)
3431 abort ();
3432
3433 if (TARGET_MINIMAL_TOC)
3434 fprintf (file, "\t.long %d\n", INTVAL (val));
3435 else
3436 fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
3437 return;
3438 }
3439
3440 if (GET_CODE (x) == CONST)
3441 {
3442 base = XEXP (XEXP (x, 0), 0);
3443 offset = INTVAL (XEXP (XEXP (x, 0), 1));
3444 }
3445
3446 if (GET_CODE (base) == SYMBOL_REF)
3447 name = XSTR (base, 0);
3448 else if (GET_CODE (base) == LABEL_REF)
3449 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
3450 else if (GET_CODE (base) == CODE_LABEL)
3451 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
3452 else
3453 abort ();
3454
3455 if (TARGET_MINIMAL_TOC)
3456 fprintf (file, "\t.long ");
3457 else
3458 {
3459 STRIP_NAME_ENCODING (real_name, name);
3460 fprintf (file, "\t.tc %s", real_name);
3461
3462 if (offset < 0)
3463 fprintf (file, ".N%d", - offset);
3464 else if (offset)
3465 fprintf (file, ".P%d", offset);
3466
3467 fprintf (file, "[TC],");
3468 }
3469 output_addr_const (file, x);
3470 fprintf (file, "\n");
3471 }
3472 \f
3473 /* Output an assembler pseudo-op to write an ASCII string of N characters
3474 starting at P to FILE.
3475
3476 On the RS/6000, we have to do this using the .byte operation and
3477 write out special characters outside the quoted string.
3478 Also, the assembler is broken; very long strings are truncated,
3479 so we must artificially break them up early. */
3480
3481 void
3482 output_ascii (file, p, n)
3483 FILE *file;
3484 char *p;
3485 int n;
3486 {
3487 char c;
3488 int i, count_string;
3489 char *for_string = "\t.byte \"";
3490 char *for_decimal = "\t.byte ";
3491 char *to_close = NULL;
3492
3493 count_string = 0;
3494 for (i = 0; i < n; i++)
3495 {
3496 c = *p++;
3497 if (c >= ' ' && c < 0177)
3498 {
3499 if (for_string)
3500 fputs (for_string, file);
3501 putc (c, file);
3502
3503 /* Write two quotes to get one. */
3504 if (c == '"')
3505 {
3506 putc (c, file);
3507 ++count_string;
3508 }
3509
3510 for_string = NULL;
3511 for_decimal = "\"\n\t.byte ";
3512 to_close = "\"\n";
3513 ++count_string;
3514
3515 if (count_string >= 512)
3516 {
3517 fputs (to_close, file);
3518
3519 for_string = "\t.byte \"";
3520 for_decimal = "\t.byte ";
3521 to_close = NULL;
3522 count_string = 0;
3523 }
3524 }
3525 else
3526 {
3527 if (for_decimal)
3528 fputs (for_decimal, file);
3529 fprintf (file, "%d", c);
3530
3531 for_string = "\n\t.byte \"";
3532 for_decimal = ", ";
3533 to_close = "\n";
3534 count_string = 0;
3535 }
3536 }
3537
3538 /* Now close the string if we have written one. Then end the line. */
3539 if (to_close)
3540 fprintf (file, to_close);
3541 }
3542 \f
3543 /* Generate a unique section name for FILENAME for a section type
3544 represented by SECTION_DESC. Output goes into BUF.
3545
3546 SECTION_DESC can be any string, as long as it is different for each
3547 possible section type.
3548
3549 We name the section in the same manner as xlc. The name begins with an
3550 underscore followed by the filename (after stripping any leading directory
3551 names) with the last period replaced by the string SECTION_DESC. If
3552 FILENAME does not contain a period, SECTION_DESC is appended to the end of
3553 the name. */
3554
3555 void
3556 rs6000_gen_section_name (buf, filename, section_desc)
3557 char **buf;
3558 char *filename;
3559 char *section_desc;
3560 {
3561 char *q, *after_last_slash, *last_period;
3562 char *p;
3563 int len;
3564
3565 after_last_slash = filename;
3566 for (q = filename; *q; q++)
3567 {
3568 if (*q == '/')
3569 after_last_slash = q + 1;
3570 else if (*q == '.')
3571 last_period = q;
3572 }
3573
3574 len = strlen (after_last_slash) + strlen (section_desc) + 2;
3575 *buf = (char *) permalloc (len);
3576
3577 p = *buf;
3578 *p++ = '_';
3579
3580 for (q = after_last_slash; *q; q++)
3581 {
3582 if (q == last_period)
3583 {
3584 strcpy (p, section_desc);
3585 p += strlen (section_desc);
3586 }
3587
3588 else if (isalnum (*q))
3589 *p++ = *q;
3590 }
3591
3592 if (last_period == 0)
3593 strcpy (p, section_desc);
3594 else
3595 *p = '\0';
3596 }
3597 \f
3598 /* Write function profiler code. */
3599
3600 void
3601 output_function_profiler (file, labelno)
3602 FILE *file;
3603 int labelno;
3604 {
3605 /* The last used parameter register. */
3606 int last_parm_reg;
3607 int i, j;
3608 char buf[100];
3609
3610 if (DEFAULT_ABI != ABI_AIX)
3611 abort ();
3612
3613 /* Set up a TOC entry for the profiler label. */
3614 toc_section ();
3615 ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
3616 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
3617 if (TARGET_MINIMAL_TOC)
3618 {
3619 fprintf (file, "\t.long ");
3620 assemble_name (file, buf);
3621 fprintf (file, "\n");
3622 }
3623 else
3624 {
3625 fprintf (file, "\t.tc\t");
3626 assemble_name (file, buf);
3627 fprintf (file, "[TC],");
3628 assemble_name (file, buf);
3629 fprintf (file, "\n");
3630 }
3631 text_section ();
3632
3633 /* Figure out last used parameter register. The proper thing to do is
3634 to walk incoming args of the function. A function might have live
3635 parameter registers even if it has no incoming args. */
3636
3637 for (last_parm_reg = 10;
3638 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
3639 last_parm_reg--)
3640 ;
3641
3642 /* Save parameter registers in regs 23-30. Don't overwrite reg 31, since
3643 it might be set up as the frame pointer. */
3644
3645 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
3646 fprintf (file, "\tai %d,%d,0\n", j, i);
3647
3648 /* Load location address into r3, and call mcount. */
3649
3650 ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
3651 fprintf (file, "\tl 3,");
3652 assemble_name (file, buf);
3653 fprintf (file, "(2)\n\tbl .mcount\n");
3654
3655 /* Restore parameter registers. */
3656
3657 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
3658 fprintf (file, "\tai %d,%d,0\n", i, j);
3659 }
3660
3661 /* Adjust the cost of a scheduling dependency. Return the new cost of
3662 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
3663
3664 int
3665 rs6000_adjust_cost (insn, link, dep_insn, cost)
3666 rtx insn;
3667 rtx link;
3668 rtx dep_insn;
3669 int cost;
3670 {
3671 if (! recog_memoized (insn))
3672 return 0;
3673
3674 if (REG_NOTE_KIND (link) != 0)
3675 return 0;
3676
3677 if (REG_NOTE_KIND (link) == 0)
3678 {
3679 /* Data dependency; DEP_INSN writes a register that INSN reads some
3680 cycles later. */
3681
3682 /* Tell the first scheduling pass about the latency between a mtctr
3683 and bctr (and mtlr and br/blr). The first scheduling pass will not
3684 know about this latency since the mtctr instruction, which has the
3685 latency associated to it, will be generated by reload. */
3686 if (get_attr_type (insn) == TYPE_JMPREG)
3687 return TARGET_POWER ? 5 : 4;
3688
3689 /* Fall out to return default cost. */
3690 }
3691
3692 return cost;
3693 }
3694
3695 /* Return how many instructions the machine can issue per cycle */
3696 int get_issue_rate()
3697 {
3698 switch (rs6000_cpu_attr) {
3699 case CPU_RIOS1:
3700 return 3; /* ? */
3701 case CPU_RIOS2:
3702 return 4;
3703 case CPU_PPC601:
3704 return 3; /* ? */
3705 case CPU_PPC602:
3706 return 1;
3707 case CPU_PPC603:
3708 return 2;
3709 case CPU_PPC604:
3710 return 4;
3711 case CPU_PPC620:
3712 return 4;
3713 default:
3714 return 1;
3715 }
3716 }
3717
3718 \f
3719 /* Output insns to flush the {data|instruction} caches after building a
3720 trampoline. */
3721
3722 static void
3723 rs6000_sync_trampoline (addr)
3724 rtx addr;
3725 {
3726 enum machine_mode pmode = Pmode;
3727 rtx reg = gen_reg_rtx (pmode);
3728 rtx mem2;
3729 rtx mem1;
3730 int size = rs6000_trampoline_size ();
3731 rtx (*sub_fcn) PROTO ((rtx, rtx, rtx));
3732 rtx (*cmp_fcn) PROTO ((rtx, rtx));
3733 rtx label;
3734
3735 if (TARGET_64BIT)
3736 {
3737 abort (); /* no cmpdi function yet */
3738 }
3739 else
3740 {
3741 sub_fcn = gen_subsi3;
3742 cmp_fcn = gen_cmpsi;
3743 }
3744
3745 addr = force_reg (pmode, addr);
3746 mem2 = gen_rtx (MEM, pmode, gen_rtx (PLUS, pmode, addr, reg));
3747 mem1 = gen_rtx (MEM, pmode, addr);
3748
3749 /* Issue a loop of dcbst's to flush the data cache */
3750 emit_move_insn (reg, GEN_INT (size-4));
3751 label = gen_label_rtx ();
3752 emit_label (label);
3753 emit_insn (gen_dcbst (mem2, addr, reg));
3754 emit_insn ((*sub_fcn) (reg, reg, GEN_INT (4)));
3755 emit_insn ((*cmp_fcn) (reg, const0_rtx));
3756 emit_jump_insn (gen_bgt (label));
3757
3758 /* Issue a sync after the dcbst's to let things settle down */
3759 emit_insn (gen_sync (mem1));
3760
3761 /* Issue a loop of icbi's to flush the instruction cache */
3762 emit_move_insn (reg, GEN_INT (size-4));
3763 label = gen_label_rtx ();
3764 emit_label (label);
3765 emit_insn (gen_icbi (mem2, addr, reg));
3766 emit_insn ((*sub_fcn) (reg, reg, GEN_INT (4)));
3767 emit_insn ((*cmp_fcn) (reg, const0_rtx));
3768 emit_jump_insn (gen_bgt (label));
3769
3770 /* Issue a sync after the icbi's to let things settle down */
3771 emit_insn (gen_sync (mem1));
3772
3773 /* Finally issue an isync to synchronize the icache */
3774 emit_insn (gen_isync (mem1));
3775 }
3776
3777 \f
3778 /* Output assembler code for a block containing the constant parts
3779 of a trampoline, leaving space for the variable parts.
3780
3781 The trampoline should set the static chain pointer to value placed
3782 into the trampoline and should branch to the specified routine. */
3783
3784 void
3785 rs6000_trampoline_template (file)
3786 FILE *file;
3787 {
3788 char *sc = reg_names[STATIC_CHAIN_REGNUM];
3789 char *r0 = reg_names[0];
3790
3791 switch (DEFAULT_ABI)
3792 {
3793 default:
3794 abort ();
3795
3796 /* Under AIX, this is not code at all, but merely a data area,
3797 since that is the way all functions are called. The first word is
3798 the address of the function, the second word is the TOC pointer (r2),
3799 and the third word is the static chain value. */
3800 case ABI_AIX:
3801 fprintf (file, "\t.long %s\n", (TARGET_64BIT) ? "0,0,0,0,0,0" : "0,0,0");
3802 break;
3803
3804
3805 /* V.4/eabi function pointers are just a single pointer, so we need to
3806 do the full gory code to load up the static chain. */
3807 case ABI_V4:
3808 case ABI_AIX_NODESC:
3809 if (STATIC_CHAIN_REGNUM == 0 || !TARGET_NEW_MNEMONICS)
3810 abort ();
3811
3812 if (TARGET_64BIT)
3813 {
3814 fprintf (file, "\tmflr %s\n", r0); /* offset 0 */
3815 fprintf (file, "\tbl .LTRAMP1\n"); /* offset 4 */
3816 fprintf (file, "\t.long 0,0,0,0\n"); /* offset 8 */
3817 fprintf (file, ".LTRAMP1:\n");
3818 fprintf (file, "\tmflr %s\n", sc); /* offset 28 */
3819 fprintf (file, "\tmtlr %s\n", r0); /* offset 32 */
3820 fprintf (file, "\tld %s,0(%s)\n", r0, sc); /* offset 36 */
3821 fprintf (file, "\tld %s,8(%s)\n", sc, sc); /* offset 40 */
3822 fprintf (file, "\tmtctr %s\n", r0); /* offset 44 */
3823 fprintf (file, "\tbctr\n"); /* offset 48 */
3824 }
3825 else
3826 {
3827 fprintf (file, "\tmflr %s\n", r0); /* offset 0 */
3828 fprintf (file, "\tbl .LTRAMP1\n"); /* offset 4 */
3829 fprintf (file, "\t.long 0,0\n"); /* offset 8 */
3830 fprintf (file, ".LTRAMP1:\n");
3831 fprintf (file, "\tmflr %s\n", sc); /* offset 20 */
3832 fprintf (file, "\tmtlr %s\n", r0); /* offset 24 */
3833 fprintf (file, "\tlwz %s,0(%s)\n", r0, sc); /* offset 28 */
3834 fprintf (file, "\tlwz %s,4(%s)\n", sc, sc); /* offset 32 */
3835 fprintf (file, "\tmtctr %s\n", r0); /* offset 36 */
3836 fprintf (file, "\tbctr\n"); /* offset 40 */
3837 }
3838 break;
3839
3840 /* NT function pointers point to a two word area (real address, TOC)
3841 which unfortunately does not include a static chain field. So we
3842 need to have a 2 word area followed by the code to load up the
3843 static chain. */
3844 case ABI_NT:
3845 if (STATIC_CHAIN_REGNUM == 0 || !TARGET_NEW_MNEMONICS || TARGET_64BIT)
3846 abort ();
3847
3848 fprintf (file, "\t.ualong 0,0\n"); /* offset 0 */
3849 fprintf (file, "\tmflr %s\n", r0); /* offset 8 */
3850 fprintf (file, "\tbl .LTRAMP1\n"); /* offset 12 */
3851 fprintf (file, "\t.ualong 0,0\n"); /* offset 16 */
3852 fprintf (file, ".LTRAMP1:\n");
3853 fprintf (file, "\tmflr %s\n", sc); /* offset 28 */
3854 fprintf (file, "\tmtlr %s\n", r0); /* offset 32 */
3855 fprintf (file, "\tlwz %s,0(%s)\n", r0, sc); /* offset 36 */
3856 fprintf (file, "\tlwz %s,4(%s)\n", sc, sc); /* offset 40 */
3857 fprintf (file, "\tmtctr %s\n", r0); /* offset 44 */
3858 fprintf (file, "\tbctr\n"); /* offset 48 */
3859 break;
3860 }
3861
3862 return;
3863 }
3864
3865 /* Length in units of the trampoline for entering a nested function. */
3866
3867 int
3868 rs6000_trampoline_size ()
3869 {
3870 int ret = 0;
3871
3872 switch (DEFAULT_ABI)
3873 {
3874 default:
3875 abort ();
3876
3877 case ABI_AIX:
3878 ret = (TARGET_64BIT) ? 24 : 12;
3879 break;
3880
3881 case ABI_V4:
3882 case ABI_AIX_NODESC:
3883 ret = (TARGET_64BIT ? 48 : 40);
3884 break;
3885
3886 case ABI_NT:
3887 ret = 52;
3888 break;
3889 }
3890
3891 return ret;
3892 }
3893
3894 /* Emit RTL insns to initialize the variable parts of a trampoline.
3895 FNADDR is an RTX for the address of the function's pure code.
3896 CXT is an RTX for the static chain value for the function. */
3897
3898 void
3899 rs6000_initialize_trampoline (addr, fnaddr, cxt)
3900 rtx addr;
3901 rtx fnaddr;
3902 rtx cxt;
3903 {
3904 rtx reg, reg2, reg3;
3905
3906 switch (DEFAULT_ABI)
3907 {
3908 default:
3909 abort ();
3910
3911 /* Under AIX, just build the 3 word function descriptor */
3912 case ABI_AIX:
3913 emit_move_insn (gen_rtx (MEM, SImode,
3914 memory_address (SImode, (addr))),
3915 gen_rtx (MEM, SImode,
3916 memory_address (SImode, (fnaddr))));
3917 emit_move_insn (gen_rtx (MEM, SImode,
3918 memory_address (SImode,
3919 plus_constant ((addr), 4))),
3920 gen_rtx (MEM, SImode,
3921 memory_address (SImode,
3922 plus_constant ((fnaddr), 4))));
3923 emit_move_insn (gen_rtx (MEM, SImode,
3924 memory_address (SImode,
3925 plus_constant ((addr), 8))),
3926 force_reg (SImode, (cxt)));
3927 break;
3928
3929 /* Under V.4/eabi, update the two words after the bl to have the real
3930 function address and the static chain. */
3931 case ABI_V4:
3932 case ABI_AIX_NODESC:
3933 reg = gen_reg_rtx (Pmode);
3934
3935 emit_move_insn (reg, fnaddr);
3936 emit_move_insn (gen_rtx (MEM, Pmode, plus_constant (addr, 8)), reg);
3937 emit_move_insn (gen_rtx (MEM, Pmode,
3938 plus_constant (addr, (TARGET_64BIT ? 16 : 12))),
3939 cxt);
3940
3941 rs6000_sync_trampoline (addr);
3942 break;
3943
3944 /* Under NT, update the first 2 words to look like a normal descriptor, and
3945 then fill in the fields with the function address and static chain after
3946 the bl instruction. */
3947 case ABI_NT:
3948 reg = gen_reg_rtx (Pmode);
3949 reg2 = gen_reg_rtx (Pmode);
3950 reg3 = gen_reg_rtx (Pmode);
3951
3952 emit_move_insn (gen_rtx (MEM, Pmode, plus_constant (addr, 4)),
3953 gen_rtx (REG, Pmode, 2));
3954 emit_move_insn (reg, fnaddr);
3955 emit_move_insn (reg2, gen_rtx (MEM, Pmode, reg));
3956 emit_move_insn (reg3, plus_constant (addr, 8));
3957 emit_move_insn (gen_rtx (MEM, Pmode, plus_constant (addr, 16)), reg);
3958 emit_move_insn (gen_rtx (MEM, Pmode, addr), reg3);
3959 emit_move_insn (gen_rtx (MEM, Pmode, plus_constant (addr, 20)), cxt);
3960 rs6000_sync_trampoline (addr);
3961 break;
3962 }
3963
3964 return;
3965 }
This page took 0.230216 seconds and 6 git commands to generate.