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