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