rs6000.c (secondary_reload_class): Fix Darwin specific misuse of r0 as a reload address.
[gcc.git] / gcc / config / rs6000 / rs6000.c
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "real.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-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 "basic-block.h"
41 #include "toplev.h"
42 #include "ggc.h"
43 #include "hashtab.h"
44 #include "tm_p.h"
45
46 #ifndef TARGET_NO_PROTOTYPE
47 #define TARGET_NO_PROTOTYPE 0
48 #endif
49
50 extern int profile_block_flag;
51
52 #define min(A,B) ((A) < (B) ? (A) : (B))
53 #define max(A,B) ((A) > (B) ? (A) : (B))
54
55 /* Target cpu type */
56
57 enum processor_type rs6000_cpu;
58 struct rs6000_cpu_select rs6000_select[3] =
59 {
60 /* switch name, tune arch */
61 { (const char *)0, "--with-cpu=", 1, 1 },
62 { (const char *)0, "-mcpu=", 1, 1 },
63 { (const char *)0, "-mtune=", 1, 0 },
64 };
65
66 /* Set to non-zero once AIX common-mode calls have been defined. */
67 static int common_mode_defined;
68
69 /* Save information from a "cmpxx" operation until the branch or scc is
70 emitted. */
71 rtx rs6000_compare_op0, rs6000_compare_op1;
72 int rs6000_compare_fp_p;
73
74 /* Label number of label created for -mrelocatable, to call to so we can
75 get the address of the GOT section */
76 int rs6000_pic_labelno;
77
78 #ifdef USING_SVR4_H
79 /* Which abi to adhere to */
80 const char *rs6000_abi_name = RS6000_ABI_NAME;
81
82 /* Semantics of the small data area */
83 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
84
85 /* Which small data model to use */
86 const char *rs6000_sdata_name = (char *)0;
87
88 /* Counter for labels which are to be placed in .fixup. */
89 int fixuplabelno = 0;
90 #endif
91
92 /* ABI enumeration available for subtarget to use. */
93 enum rs6000_abi rs6000_current_abi;
94
95 /* Debug flags */
96 const char *rs6000_debug_name;
97 int rs6000_debug_stack; /* debug stack applications */
98 int rs6000_debug_arg; /* debug argument handling */
99
100 /* Flag to say the TOC is initialized */
101 int toc_initialized;
102 char toc_label_name[10];
103
104 /* Alias set for saves and restores from the rs6000 stack. */
105 static int rs6000_sr_alias_set;
106
107 static void rs6000_add_gc_roots PARAMS ((void));
108 static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
109 static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx));
110 static void validate_condition_mode
111 PARAMS ((enum rtx_code, enum machine_mode));
112 static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
113 static void rs6000_maybe_dead PARAMS ((rtx));
114 static void rs6000_emit_stack_tie PARAMS ((void));
115 static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
116 static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
117 static unsigned rs6000_hash_constant PARAMS ((rtx));
118 static unsigned toc_hash_function PARAMS ((const void *));
119 static int toc_hash_eq PARAMS ((const void *, const void *));
120 static int toc_hash_mark_entry PARAMS ((void **, void *));
121 static void toc_hash_mark_table PARAMS ((void *));
122 static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
123 static void rs6000_free_machine_status PARAMS ((struct function *));
124 static void rs6000_init_machine_status PARAMS ((struct function *));
125 static void rs6000_mark_machine_status PARAMS ((struct function *));
126 static int rs6000_ra_ever_killed PARAMS ((void));
127 \f
128 /* Default register names. */
129 char rs6000_reg_names[][8] =
130 {
131 "0", "1", "2", "3", "4", "5", "6", "7",
132 "8", "9", "10", "11", "12", "13", "14", "15",
133 "16", "17", "18", "19", "20", "21", "22", "23",
134 "24", "25", "26", "27", "28", "29", "30", "31",
135 "0", "1", "2", "3", "4", "5", "6", "7",
136 "8", "9", "10", "11", "12", "13", "14", "15",
137 "16", "17", "18", "19", "20", "21", "22", "23",
138 "24", "25", "26", "27", "28", "29", "30", "31",
139 "mq", "lr", "ctr","ap",
140 "0", "1", "2", "3", "4", "5", "6", "7",
141 "xer"
142 };
143
144 #ifdef TARGET_REGNAMES
145 static char alt_reg_names[][8] =
146 {
147 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
148 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
149 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
150 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
151 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
152 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
153 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
154 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
155 "mq", "lr", "ctr", "ap",
156 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
157 "xer"
158 };
159 #endif
160 \f
161 #ifndef MASK_STRICT_ALIGN
162 #define MASK_STRICT_ALIGN 0
163 #endif
164
165 /* Override command line options. Mostly we process the processor
166 type and sometimes adjust other TARGET_ options. */
167
168 void
169 rs6000_override_options (default_cpu)
170 const char *default_cpu;
171 {
172 size_t i, j;
173 struct rs6000_cpu_select *ptr;
174
175 /* Simplify the entries below by making a mask for any POWER
176 variant and any PowerPC variant. */
177
178 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
179 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
180 | MASK_PPC_GFXOPT | MASK_POWERPC64)
181 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
182
183 static struct ptt
184 {
185 const char *name; /* Canonical processor name. */
186 enum processor_type processor; /* Processor type enum value. */
187 int target_enable; /* Target flags to enable. */
188 int target_disable; /* Target flags to disable. */
189 } processor_target_table[]
190 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
191 POWER_MASKS | POWERPC_MASKS},
192 {"power", PROCESSOR_POWER,
193 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
194 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
195 {"power2", PROCESSOR_POWER,
196 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
197 POWERPC_MASKS | MASK_NEW_MNEMONICS},
198 {"power3", PROCESSOR_PPC630,
199 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
200 POWER_MASKS | MASK_PPC_GPOPT},
201 {"powerpc", PROCESSOR_POWERPC,
202 MASK_POWERPC | MASK_NEW_MNEMONICS,
203 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
204 {"powerpc64", PROCESSOR_POWERPC64,
205 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
206 POWER_MASKS | POWERPC_OPT_MASKS},
207 {"rios", PROCESSOR_RIOS1,
208 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
209 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
210 {"rios1", PROCESSOR_RIOS1,
211 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
212 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
213 {"rsc", PROCESSOR_PPC601,
214 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
215 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
216 {"rsc1", PROCESSOR_PPC601,
217 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
218 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
219 {"rios2", PROCESSOR_RIOS2,
220 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
221 POWERPC_MASKS | MASK_NEW_MNEMONICS},
222 {"rs64a", PROCESSOR_RS64A,
223 MASK_POWERPC | MASK_NEW_MNEMONICS,
224 POWER_MASKS | POWERPC_OPT_MASKS},
225 {"401", PROCESSOR_PPC403,
226 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
227 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
228 {"403", PROCESSOR_PPC403,
229 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
230 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
231 {"505", PROCESSOR_MPCCORE,
232 MASK_POWERPC | MASK_NEW_MNEMONICS,
233 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
234 {"601", PROCESSOR_PPC601,
235 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
236 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
237 {"602", PROCESSOR_PPC603,
238 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
239 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
240 {"603", PROCESSOR_PPC603,
241 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
242 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
243 {"603e", PROCESSOR_PPC603,
244 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
245 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
246 {"ec603e", PROCESSOR_PPC603,
247 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
248 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
249 {"604", PROCESSOR_PPC604,
250 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
251 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
252 {"604e", PROCESSOR_PPC604e,
253 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
254 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
255 {"620", PROCESSOR_PPC620,
256 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
257 POWER_MASKS | MASK_PPC_GPOPT},
258 {"630", PROCESSOR_PPC630,
259 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
260 POWER_MASKS | MASK_PPC_GPOPT},
261 {"740", PROCESSOR_PPC750,
262 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
263 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
264 {"750", PROCESSOR_PPC750,
265 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
266 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
267 {"801", PROCESSOR_MPCCORE,
268 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
269 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
270 {"821", PROCESSOR_MPCCORE,
271 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
272 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
273 {"823", PROCESSOR_MPCCORE,
274 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
275 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
276 {"860", PROCESSOR_MPCCORE,
277 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
278 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
279
280 size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
281
282 int multiple = TARGET_MULTIPLE; /* save current -mmultiple/-mno-multiple status */
283 int string = TARGET_STRING; /* save current -mstring/-mno-string status */
284
285 profile_block_flag = 0;
286
287 /* Identify the processor type */
288 rs6000_select[0].string = default_cpu;
289 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
290
291 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
292 {
293 ptr = &rs6000_select[i];
294 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
295 {
296 for (j = 0; j < ptt_size; j++)
297 if (! strcmp (ptr->string, processor_target_table[j].name))
298 {
299 if (ptr->set_tune_p)
300 rs6000_cpu = processor_target_table[j].processor;
301
302 if (ptr->set_arch_p)
303 {
304 target_flags |= processor_target_table[j].target_enable;
305 target_flags &= ~processor_target_table[j].target_disable;
306 }
307 break;
308 }
309
310 if (j == ptt_size)
311 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
312 }
313 }
314
315 /* If we are optimizing big endian systems for space, use the
316 store multiple instructions. */
317 if (BYTES_BIG_ENDIAN && optimize_size)
318 target_flags |= MASK_MULTIPLE;
319
320 /* If -mmultiple or -mno-multiple was explicitly used, don't
321 override with the processor default */
322 if (TARGET_MULTIPLE_SET)
323 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
324
325 /* If -mstring or -mno-string was explicitly used, don't
326 override with the processor default */
327 if (TARGET_STRING_SET)
328 target_flags = (target_flags & ~MASK_STRING) | string;
329
330 /* Don't allow -mmultiple or -mstring on little endian systems unless the cpu
331 is a 750, because the hardware doesn't support the instructions used in
332 little endian mode, and causes an alignment trap. The 750 does not cause
333 an alignment trap (except when the target is unaligned). */
334
335 if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
336 {
337 if (TARGET_MULTIPLE)
338 {
339 target_flags &= ~MASK_MULTIPLE;
340 if (TARGET_MULTIPLE_SET)
341 warning ("-mmultiple is not supported on little endian systems");
342 }
343
344 if (TARGET_STRING)
345 {
346 target_flags &= ~MASK_STRING;
347 if (TARGET_STRING_SET)
348 warning ("-mstring is not supported on little endian systems");
349 }
350 }
351
352 if (flag_pic && (DEFAULT_ABI == ABI_AIX))
353 {
354 warning ("-f%s ignored for AIX (all code is position independent)",
355 (flag_pic > 1) ? "PIC" : "pic");
356 flag_pic = 0;
357 }
358
359 if (flag_function_sections && (write_symbols != NO_DEBUG)
360 && (DEFAULT_ABI == ABI_AIX))
361 {
362 warning ("-ffunction-sections disabled on AIX when debugging");
363 flag_function_sections = 0;
364 }
365
366 if (flag_data_sections && (DEFAULT_ABI == ABI_AIX))
367 {
368 warning ("-fdata-sections not supported on AIX");
369 flag_data_sections = 0;
370 }
371
372 /* Set debug flags */
373 if (rs6000_debug_name)
374 {
375 if (! strcmp (rs6000_debug_name, "all"))
376 rs6000_debug_stack = rs6000_debug_arg = 1;
377 else if (! strcmp (rs6000_debug_name, "stack"))
378 rs6000_debug_stack = 1;
379 else if (! strcmp (rs6000_debug_name, "arg"))
380 rs6000_debug_arg = 1;
381 else
382 error ("Unknown -mdebug-%s switch", rs6000_debug_name);
383 }
384
385 #ifdef TARGET_REGNAMES
386 /* If the user desires alternate register names, copy in the alternate names
387 now. */
388 if (TARGET_REGNAMES)
389 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
390 #endif
391
392 #ifdef SUBTARGET_OVERRIDE_OPTIONS
393 SUBTARGET_OVERRIDE_OPTIONS;
394 #endif
395
396 /* Register global variables with the garbage collector. */
397 rs6000_add_gc_roots ();
398
399 /* Allocate an alias set for register saves & restores from stack. */
400 rs6000_sr_alias_set = new_alias_set ();
401
402 if (TARGET_TOC)
403 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
404
405 /* Arrange to save and restore machine status around nested functions. */
406 init_machine_status = rs6000_init_machine_status;
407 mark_machine_status = rs6000_mark_machine_status;
408 free_machine_status = rs6000_free_machine_status;
409 }
410
411 void
412 optimization_options (level, size)
413 int level ATTRIBUTE_UNUSED;
414 int size ATTRIBUTE_UNUSED;
415 {
416 }
417 \f
418 /* Do anything needed at the start of the asm file. */
419
420 void
421 rs6000_file_start (file, default_cpu)
422 FILE *file;
423 const char *default_cpu;
424 {
425 size_t i;
426 char buffer[80];
427 const char *start = buffer;
428 struct rs6000_cpu_select *ptr;
429
430 if (flag_verbose_asm)
431 {
432 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
433 rs6000_select[0].string = default_cpu;
434
435 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
436 {
437 ptr = &rs6000_select[i];
438 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
439 {
440 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
441 start = "";
442 }
443 }
444
445 #ifdef USING_SVR4_H
446 switch (rs6000_sdata)
447 {
448 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
449 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
450 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
451 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
452 }
453
454 if (rs6000_sdata && g_switch_value)
455 {
456 fprintf (file, "%s -G %d", start, g_switch_value);
457 start = "";
458 }
459 #endif
460
461 if (*start == '\0')
462 putc ('\n', file);
463 }
464 }
465
466 \f
467 /* Create a CONST_DOUBLE from a string. */
468
469 struct rtx_def *
470 rs6000_float_const (string, mode)
471 const char *string;
472 enum machine_mode mode;
473 {
474 REAL_VALUE_TYPE value;
475 value = REAL_VALUE_ATOF (string, mode);
476 return immed_real_const_1 (value, mode);
477 }
478 \f
479 /* Return non-zero if this function is known to have a null epilogue. */
480
481 int
482 direct_return ()
483 {
484 if (reload_completed)
485 {
486 rs6000_stack_t *info = rs6000_stack_info ();
487
488 if (info->first_gp_reg_save == 32
489 && info->first_fp_reg_save == 64
490 && ! info->lr_save_p
491 && ! info->cr_save_p
492 && ! info->push_p)
493 return 1;
494 }
495
496 return 0;
497 }
498
499 /* Returns 1 always. */
500
501 int
502 any_operand (op, mode)
503 register rtx op ATTRIBUTE_UNUSED;
504 enum machine_mode mode ATTRIBUTE_UNUSED;
505 {
506 return 1;
507 }
508
509 /* Returns 1 if op is the count register */
510 int
511 count_register_operand(op, mode)
512 register rtx op;
513 enum machine_mode mode ATTRIBUTE_UNUSED;
514 {
515 if (GET_CODE (op) != REG)
516 return 0;
517
518 if (REGNO (op) == COUNT_REGISTER_REGNUM)
519 return 1;
520
521 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
522 return 1;
523
524 return 0;
525 }
526
527 int
528 xer_operand(op, mode)
529 register rtx op;
530 enum machine_mode mode ATTRIBUTE_UNUSED;
531 {
532 if (GET_CODE (op) != REG)
533 return 0;
534
535 if (XER_REGNO_P (REGNO (op)))
536 return 1;
537
538 return 0;
539 }
540
541 /* Return 1 if OP is a constant that can fit in a D field. */
542
543 int
544 short_cint_operand (op, mode)
545 register rtx op;
546 enum machine_mode mode ATTRIBUTE_UNUSED;
547 {
548 return (GET_CODE (op) == CONST_INT
549 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
550 }
551
552 /* Similar for a unsigned D field. */
553
554 int
555 u_short_cint_operand (op, mode)
556 register rtx op;
557 enum machine_mode mode ATTRIBUTE_UNUSED;
558 {
559 return (GET_CODE (op) == CONST_INT
560 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'));
561 }
562
563 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
564
565 int
566 non_short_cint_operand (op, mode)
567 register rtx op;
568 enum machine_mode mode ATTRIBUTE_UNUSED;
569 {
570 return (GET_CODE (op) == CONST_INT
571 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
572 }
573
574 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
575 ctr, or lr). */
576
577 int
578 gpc_reg_operand (op, mode)
579 register rtx op;
580 enum machine_mode mode;
581 {
582 return (register_operand (op, mode)
583 && (GET_CODE (op) != REG
584 || (REGNO (op) >= ARG_POINTER_REGNUM
585 && !XER_REGNO_P (REGNO (op)))
586 || REGNO (op) < MQ_REGNO));
587 }
588
589 /* Returns 1 if OP is either a pseudo-register or a register denoting a
590 CR field. */
591
592 int
593 cc_reg_operand (op, mode)
594 register rtx op;
595 enum machine_mode mode;
596 {
597 return (register_operand (op, mode)
598 && (GET_CODE (op) != REG
599 || REGNO (op) >= FIRST_PSEUDO_REGISTER
600 || CR_REGNO_P (REGNO (op))));
601 }
602
603 /* Returns 1 if OP is either a pseudo-register or a register denoting a
604 CR field that isn't CR0. */
605
606 int
607 cc_reg_not_cr0_operand (op, mode)
608 register rtx op;
609 enum machine_mode mode;
610 {
611 return (register_operand (op, mode)
612 && (GET_CODE (op) != REG
613 || REGNO (op) >= FIRST_PSEUDO_REGISTER
614 || CR_REGNO_NOT_CR0_P (REGNO (op))));
615 }
616
617 /* Returns 1 if OP is either a constant integer valid for a D-field or a
618 non-special register. If a register, it must be in the proper mode unless
619 MODE is VOIDmode. */
620
621 int
622 reg_or_short_operand (op, mode)
623 register rtx op;
624 enum machine_mode mode;
625 {
626 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
627 }
628
629 /* Similar, except check if the negation of the constant would be valid for
630 a D-field. */
631
632 int
633 reg_or_neg_short_operand (op, mode)
634 register rtx op;
635 enum machine_mode mode;
636 {
637 if (GET_CODE (op) == CONST_INT)
638 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
639
640 return gpc_reg_operand (op, mode);
641 }
642
643 /* Return 1 if the operand is either a register or an integer whose high-order
644 16 bits are zero. */
645
646 int
647 reg_or_u_short_operand (op, mode)
648 register rtx op;
649 enum machine_mode mode;
650 {
651 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
652 }
653
654 /* Return 1 is the operand is either a non-special register or ANY
655 constant integer. */
656
657 int
658 reg_or_cint_operand (op, mode)
659 register rtx op;
660 enum machine_mode mode;
661 {
662 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
663 }
664
665 /* Return 1 is the operand is either a non-special register or ANY
666 32-bit signed constant integer. */
667
668 int
669 reg_or_arith_cint_operand (op, mode)
670 register rtx op;
671 enum machine_mode mode;
672 {
673 return (gpc_reg_operand (op, mode)
674 || (GET_CODE (op) == CONST_INT
675 #if HOST_BITS_PER_WIDE_INT != 32
676 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
677 < (unsigned HOST_WIDE_INT) 0x100000000ll)
678 #endif
679 ));
680 }
681
682 /* Return 1 is the operand is either a non-special register or ANY
683 32-bit unsigned constant integer. */
684
685 int
686 reg_or_logical_cint_operand (op, mode)
687 register rtx op;
688 enum machine_mode mode;
689 {
690 if (GET_CODE (op) == CONST_INT)
691 {
692 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
693 {
694 if (GET_MODE_BITSIZE (mode) <= 32)
695 abort();
696
697 if (INTVAL (op) < 0)
698 return 0;
699 }
700
701 return ((INTVAL (op) & GET_MODE_MASK (mode)
702 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
703 }
704 else if (GET_CODE (op) == CONST_DOUBLE)
705 {
706 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
707 || mode != DImode)
708 abort();
709
710 return CONST_DOUBLE_HIGH (op) == 0;
711 }
712 else
713 return gpc_reg_operand (op, mode);
714 }
715
716 /* Return 1 if the operand is an operand that can be loaded via the GOT */
717
718 int
719 got_operand (op, mode)
720 register rtx op;
721 enum machine_mode mode ATTRIBUTE_UNUSED;
722 {
723 return (GET_CODE (op) == SYMBOL_REF
724 || GET_CODE (op) == CONST
725 || GET_CODE (op) == LABEL_REF);
726 }
727
728 /* Return 1 if the operand is a simple references that can be loaded via
729 the GOT (labels involving addition aren't allowed). */
730
731 int
732 got_no_const_operand (op, mode)
733 register rtx op;
734 enum machine_mode mode ATTRIBUTE_UNUSED;
735 {
736 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
737 }
738
739 /* Return the number of instructions it takes to form a constant in an
740 integer register. */
741
742 static int
743 num_insns_constant_wide (value)
744 HOST_WIDE_INT value;
745 {
746 /* signed constant loadable with {cal|addi} */
747 if (CONST_OK_FOR_LETTER_P (value, 'I'))
748 return 1;
749
750 /* constant loadable with {cau|addis} */
751 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
752 return 1;
753
754 #if HOST_BITS_PER_WIDE_INT == 64
755 else if (TARGET_POWERPC64)
756 {
757 HOST_WIDE_INT low = value & 0xffffffff;
758 HOST_WIDE_INT high = value >> 32;
759
760 low = (low ^ 0x80000000) - 0x80000000; /* sign extend */
761
762 if (high == 0 && (low & 0x80000000) == 0)
763 return 2;
764
765 else if (high == -1 && (low & 0x80000000) != 0)
766 return 2;
767
768 else if (! low)
769 return num_insns_constant_wide (high) + 1;
770
771 else
772 return (num_insns_constant_wide (high)
773 + num_insns_constant_wide (low) + 1);
774 }
775 #endif
776
777 else
778 return 2;
779 }
780
781 int
782 num_insns_constant (op, mode)
783 rtx op;
784 enum machine_mode mode;
785 {
786 if (GET_CODE (op) == CONST_INT)
787 {
788 #if HOST_BITS_PER_WIDE_INT == 64
789 if (mask64_operand (op, mode))
790 return 2;
791 else
792 #endif
793 return num_insns_constant_wide (INTVAL (op));
794 }
795
796 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
797 {
798 long l;
799 REAL_VALUE_TYPE rv;
800
801 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
802 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
803 return num_insns_constant_wide ((HOST_WIDE_INT)l);
804 }
805
806 else if (GET_CODE (op) == CONST_DOUBLE)
807 {
808 HOST_WIDE_INT low;
809 HOST_WIDE_INT high;
810 long l[2];
811 REAL_VALUE_TYPE rv;
812 int endian = (WORDS_BIG_ENDIAN == 0);
813
814 if (mode == VOIDmode || mode == DImode)
815 {
816 high = CONST_DOUBLE_HIGH (op);
817 low = CONST_DOUBLE_LOW (op);
818 }
819 else
820 {
821 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
822 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
823 high = l[endian];
824 low = l[1 - endian];
825 }
826
827 if (TARGET_32BIT)
828 return (num_insns_constant_wide (low)
829 + num_insns_constant_wide (high));
830
831 else
832 {
833 if (high == 0 && (low & 0x80000000) == 0)
834 return num_insns_constant_wide (low);
835
836 else if (high == -1 && (low & 0x80000000) != 0)
837 return num_insns_constant_wide (low);
838
839 else if (mask64_operand (op, mode))
840 return 2;
841
842 else if (low == 0)
843 return num_insns_constant_wide (high) + 1;
844
845 else
846 return (num_insns_constant_wide (high)
847 + num_insns_constant_wide (low) + 1);
848 }
849 }
850
851 else
852 abort ();
853 }
854
855 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
856 with one instruction per word. We only do this if we can safely read
857 CONST_DOUBLE_{LOW,HIGH}. */
858
859 int
860 easy_fp_constant (op, mode)
861 register rtx op;
862 register enum machine_mode mode;
863 {
864 if (GET_CODE (op) != CONST_DOUBLE
865 || GET_MODE (op) != mode
866 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
867 return 0;
868
869 /* Consider all constants with -msoft-float to be easy */
870 if (TARGET_SOFT_FLOAT && mode != DImode)
871 return 1;
872
873 /* If we are using V.4 style PIC, consider all constants to be hard */
874 if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
875 return 0;
876
877 #ifdef TARGET_RELOCATABLE
878 /* Similarly if we are using -mrelocatable, consider all constants to be hard */
879 if (TARGET_RELOCATABLE)
880 return 0;
881 #endif
882
883 if (mode == DFmode)
884 {
885 long k[2];
886 REAL_VALUE_TYPE rv;
887
888 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
889 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
890
891 return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
892 && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
893 }
894
895 else if (mode == SFmode)
896 {
897 long l;
898 REAL_VALUE_TYPE rv;
899
900 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
901 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
902
903 return num_insns_constant_wide (l) == 1;
904 }
905
906 else if (mode == DImode)
907 return ((TARGET_POWERPC64
908 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
909 || (num_insns_constant (op, DImode) <= 2));
910
911 else if (mode == SImode)
912 return 1;
913 else
914 abort ();
915 }
916
917 /* Return 1 if the operand is in volatile memory. Note that during the
918 RTL generation phase, memory_operand does not return TRUE for
919 volatile memory references. So this function allows us to
920 recognize volatile references where its safe. */
921
922 int
923 volatile_mem_operand (op, mode)
924 register rtx op;
925 enum machine_mode mode;
926 {
927 if (GET_CODE (op) != MEM)
928 return 0;
929
930 if (!MEM_VOLATILE_P (op))
931 return 0;
932
933 if (mode != GET_MODE (op))
934 return 0;
935
936 if (reload_completed)
937 return memory_operand (op, mode);
938
939 if (reload_in_progress)
940 return strict_memory_address_p (mode, XEXP (op, 0));
941
942 return memory_address_p (mode, XEXP (op, 0));
943 }
944
945 /* Return 1 if the operand is an offsettable memory operand. */
946
947 int
948 offsettable_mem_operand (op, mode)
949 register rtx op;
950 enum machine_mode mode;
951 {
952 return ((GET_CODE (op) == MEM)
953 && offsettable_address_p (reload_completed || reload_in_progress,
954 mode, XEXP (op, 0)));
955 }
956
957 /* Return 1 if the operand is either an easy FP constant (see above) or
958 memory. */
959
960 int
961 mem_or_easy_const_operand (op, mode)
962 register rtx op;
963 enum machine_mode mode;
964 {
965 return memory_operand (op, mode) || easy_fp_constant (op, mode);
966 }
967
968 /* Return 1 if the operand is either a non-special register or an item
969 that can be used as the operand of a `mode' add insn. */
970
971 int
972 add_operand (op, mode)
973 register rtx op;
974 enum machine_mode mode;
975 {
976 return (reg_or_short_operand (op, mode)
977 || (GET_CODE (op) == CONST_INT
978 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')));
979 }
980
981 /* Return 1 if OP is a constant but not a valid add_operand. */
982
983 int
984 non_add_cint_operand (op, mode)
985 register rtx op;
986 enum machine_mode mode ATTRIBUTE_UNUSED;
987 {
988 return (GET_CODE (op) == CONST_INT
989 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
990 && ! CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
991 }
992
993 /* Return 1 if the operand is a non-special register or a constant that
994 can be used as the operand of an OR or XOR insn on the RS/6000. */
995
996 int
997 logical_operand (op, mode)
998 register rtx op;
999 enum machine_mode mode;
1000 {
1001 /* an unsigned representation of 'op'. */
1002 unsigned HOST_WIDE_INT opl, oph;
1003
1004 if (gpc_reg_operand (op, mode))
1005 return 1;
1006
1007 if (GET_CODE (op) == CONST_INT)
1008 opl = INTVAL (op);
1009 else if (GET_CODE (op) == CONST_DOUBLE)
1010 {
1011 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1012 abort();
1013
1014 opl = CONST_DOUBLE_LOW (op);
1015 oph = CONST_DOUBLE_HIGH (op);
1016
1017 if (oph != ((unsigned HOST_WIDE_INT)0
1018 - ((opl & ((unsigned HOST_WIDE_INT)1
1019 << (HOST_BITS_PER_WIDE_INT - 1))) != 0)))
1020 return 0;
1021 }
1022 else
1023 return 0;
1024
1025 /* This must really be SImode, not MODE. */
1026 if (opl != (unsigned HOST_WIDE_INT) trunc_int_for_mode (opl, SImode))
1027 return 0;
1028
1029 return ((opl & 0xffff) == 0
1030 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0);
1031 }
1032
1033 /* Return 1 if C is a constant that is not a logical operand (as
1034 above), but could be split into one. */
1035
1036 int
1037 non_logical_cint_operand (op, mode)
1038 register rtx op;
1039 enum machine_mode mode;
1040 {
1041 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1042 && ! logical_operand (op, mode)
1043 && reg_or_logical_cint_operand (op, mode));
1044 }
1045
1046 /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
1047 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1048 Reject all ones and all zeros, since these should have been optimized
1049 away and confuse the making of MB and ME. */
1050
1051 int
1052 mask_operand (op, mode)
1053 register rtx op;
1054 enum machine_mode mode ATTRIBUTE_UNUSED;
1055 {
1056 HOST_WIDE_INT c;
1057 int i;
1058 int last_bit_value;
1059 int transitions = 0;
1060
1061 if (GET_CODE (op) != CONST_INT)
1062 return 0;
1063
1064 c = INTVAL (op);
1065
1066 if (c == 0 || c == ~0)
1067 return 0;
1068
1069 last_bit_value = c & 1;
1070
1071 for (i = 1; i < 32; i++)
1072 if (((c >>= 1) & 1) != last_bit_value)
1073 last_bit_value ^= 1, transitions++;
1074
1075 return transitions <= 2;
1076 }
1077
1078 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
1079 It is if there are no more than one 1->0 or 0->1 transitions.
1080 Reject all ones and all zeros, since these should have been optimized
1081 away and confuse the making of MB and ME. */
1082
1083 int
1084 mask64_operand (op, mode)
1085 register rtx op;
1086 enum machine_mode mode;
1087 {
1088 if (GET_CODE (op) == CONST_INT)
1089 {
1090 HOST_WIDE_INT c = INTVAL (op);
1091 int i;
1092 int last_bit_value;
1093 int transitions = 0;
1094
1095 if (c == 0 || c == ~0)
1096 return 0;
1097
1098 last_bit_value = c & 1;
1099
1100 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1101 if (((c >>= 1) & 1) != last_bit_value)
1102 last_bit_value ^= 1, transitions++;
1103
1104 return transitions <= 1;
1105 }
1106 else if (GET_CODE (op) == CONST_DOUBLE
1107 && (mode == VOIDmode || mode == DImode))
1108 {
1109 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1110 #if HOST_BITS_PER_WIDE_INT == 32
1111 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1112 #endif
1113 int i;
1114 int last_bit_value;
1115 int transitions = 0;
1116
1117 if ((low == 0
1118 #if HOST_BITS_PER_WIDE_INT == 32
1119 && high == 0
1120 #endif
1121 )
1122 || (low == ~0
1123 #if HOST_BITS_PER_WIDE_INT == 32
1124 && high == ~0
1125 #endif
1126 ))
1127 return 0;
1128
1129 last_bit_value = low & 1;
1130
1131 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1132 if (((low >>= 1) & 1) != last_bit_value)
1133 last_bit_value ^= 1, transitions++;
1134
1135 #if HOST_BITS_PER_WIDE_INT == 32
1136 if ((high & 1) != last_bit_value)
1137 last_bit_value ^= 1, transitions++;
1138
1139 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1140 if (((high >>= 1) & 1) != last_bit_value)
1141 last_bit_value ^= 1, transitions++;
1142 #endif
1143
1144 return transitions <= 1;
1145 }
1146 else
1147 return 0;
1148 }
1149
1150 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
1151 It is if there are no more than two 1->0 or 0->1 transitions.
1152 Reject all ones and all zeros, since these should have been optimized
1153 away and confuse the making of MB and ME. */
1154
1155 int
1156 rldic_operand (op, mode)
1157 register rtx op;
1158 enum machine_mode mode;
1159 {
1160 if (GET_CODE (op) == CONST_INT)
1161 {
1162 HOST_WIDE_INT c = INTVAL (op);
1163 int i;
1164 int last_bit_value;
1165 int transitions = 0;
1166
1167 if (c == 0 || c == ~0)
1168 return 0;
1169
1170 last_bit_value = c & 1;
1171
1172 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1173 if (((c >>= 1) & 1) != last_bit_value)
1174 last_bit_value ^= 1, transitions++;
1175
1176 return transitions <= 2;
1177 }
1178 else if (GET_CODE (op) == CONST_DOUBLE
1179 && (mode == VOIDmode || mode == DImode))
1180 {
1181 HOST_WIDE_INT low = CONST_DOUBLE_LOW (op);
1182 #if HOST_BITS_PER_WIDE_INT == 32
1183 HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
1184 #endif
1185 int i;
1186 int last_bit_value;
1187 int transitions = 0;
1188
1189 if ((low == 0
1190 #if HOST_BITS_PER_WIDE_INT == 32
1191 && high == 0
1192 #endif
1193 )
1194 || (low == ~0
1195 #if HOST_BITS_PER_WIDE_INT == 32
1196 && high == ~0
1197 #endif
1198 ))
1199 return 0;
1200
1201 last_bit_value = low & 1;
1202
1203 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1204 if (((low >>= 1) & 1) != last_bit_value)
1205 last_bit_value ^= 1, transitions++;
1206
1207 #if HOST_BITS_PER_WIDE_INT == 32
1208 if ((high & 1) != last_bit_value)
1209 last_bit_value ^= 1, transitions++;
1210
1211 for (i = 1; i < HOST_BITS_PER_WIDE_INT; i++)
1212 if (((high >>= 1) & 1) != last_bit_value)
1213 last_bit_value ^= 1, transitions++;
1214 #endif
1215
1216 return transitions <= 2;
1217 }
1218 else
1219 return 0;
1220 }
1221
1222 /* Return 1 if the operand is either a non-special register or a constant
1223 that can be used as the operand of a PowerPC64 logical AND insn. */
1224
1225 int
1226 and64_operand (op, mode)
1227 register rtx op;
1228 enum machine_mode mode;
1229 {
1230 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1231 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1232
1233 return (logical_operand (op, mode) || mask64_operand (op, mode));
1234 }
1235
1236 /* Return 1 if the operand is either a non-special register or a
1237 constant that can be used as the operand of an RS/6000 logical AND insn. */
1238
1239 int
1240 and_operand (op, mode)
1241 register rtx op;
1242 enum machine_mode mode;
1243 {
1244 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1245 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1246
1247 return (logical_operand (op, mode) || mask_operand (op, mode));
1248 }
1249
1250 /* Return 1 if the operand is a general register or memory operand. */
1251
1252 int
1253 reg_or_mem_operand (op, mode)
1254 register rtx op;
1255 register enum machine_mode mode;
1256 {
1257 return (gpc_reg_operand (op, mode)
1258 || memory_operand (op, mode)
1259 || volatile_mem_operand (op, mode));
1260 }
1261
1262 /* Return 1 if the operand is a general register or memory operand without
1263 pre_inc or pre_dec which produces invalid form of PowerPC lwa
1264 instruction. */
1265
1266 int
1267 lwa_operand (op, mode)
1268 register rtx op;
1269 register enum machine_mode mode;
1270 {
1271 rtx inner = op;
1272
1273 if (reload_completed && GET_CODE (inner) == SUBREG)
1274 inner = SUBREG_REG (inner);
1275
1276 return gpc_reg_operand (inner, mode)
1277 || (memory_operand (inner, mode)
1278 && GET_CODE (XEXP (inner, 0)) != PRE_INC
1279 && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
1280 }
1281
1282 /* Return 1 if the operand, used inside a MEM, is a valid first argument
1283 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
1284 forced to lr. */
1285
1286 int
1287 call_operand (op, mode)
1288 register rtx op;
1289 enum machine_mode mode;
1290 {
1291 if (mode != VOIDmode && GET_MODE (op) != mode)
1292 return 0;
1293
1294 return (GET_CODE (op) == SYMBOL_REF
1295 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
1296 }
1297
1298
1299 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
1300 this file and the function is not weakly defined. */
1301
1302 int
1303 current_file_function_operand (op, mode)
1304 register rtx op;
1305 enum machine_mode mode ATTRIBUTE_UNUSED;
1306 {
1307 return (GET_CODE (op) == SYMBOL_REF
1308 && (SYMBOL_REF_FLAG (op)
1309 || (op == XEXP (DECL_RTL (current_function_decl), 0)
1310 && ! DECL_WEAK (current_function_decl))));
1311 }
1312
1313
1314 /* Return 1 if this operand is a valid input for a move insn. */
1315
1316 int
1317 input_operand (op, mode)
1318 register rtx op;
1319 enum machine_mode mode;
1320 {
1321 /* Memory is always valid. */
1322 if (memory_operand (op, mode))
1323 return 1;
1324
1325 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1326 if (GET_CODE (op) == CONSTANT_P_RTX)
1327 return 1;
1328
1329 /* For floating-point, easy constants are valid. */
1330 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1331 && CONSTANT_P (op)
1332 && easy_fp_constant (op, mode))
1333 return 1;
1334
1335 /* Allow any integer constant. */
1336 if (GET_MODE_CLASS (mode) == MODE_INT
1337 && (GET_CODE (op) == CONST_INT
1338 || GET_CODE (op) == CONST_DOUBLE))
1339 return 1;
1340
1341 /* For floating-point or multi-word mode, the only remaining valid type
1342 is a register. */
1343 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1344 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
1345 return register_operand (op, mode);
1346
1347 /* The only cases left are integral modes one word or smaller (we
1348 do not get called for MODE_CC values). These can be in any
1349 register. */
1350 if (register_operand (op, mode))
1351 return 1;
1352
1353 /* A SYMBOL_REF referring to the TOC is valid. */
1354 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
1355 return 1;
1356
1357 /* A constant pool expression (relative to the TOC) is valid */
1358 if (TOC_RELATIVE_EXPR_P (op))
1359 return 1;
1360
1361 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
1362 to be valid. */
1363 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1364 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
1365 && small_data_operand (op, Pmode))
1366 return 1;
1367
1368 return 0;
1369 }
1370
1371 /* Return 1 for an operand in small memory on V.4/eabi */
1372
1373 int
1374 small_data_operand (op, mode)
1375 rtx op ATTRIBUTE_UNUSED;
1376 enum machine_mode mode ATTRIBUTE_UNUSED;
1377 {
1378 #if TARGET_ELF
1379 rtx sym_ref;
1380
1381 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
1382 return 0;
1383
1384 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
1385 return 0;
1386
1387 if (GET_CODE (op) == SYMBOL_REF)
1388 sym_ref = op;
1389
1390 else if (GET_CODE (op) != CONST
1391 || GET_CODE (XEXP (op, 0)) != PLUS
1392 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
1393 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
1394 return 0;
1395
1396 else
1397 {
1398 rtx sum = XEXP (op, 0);
1399 HOST_WIDE_INT summand;
1400
1401 /* We have to be careful here, because it is the referenced address
1402 that must be 32k from _SDA_BASE_, not just the symbol. */
1403 summand = INTVAL (XEXP (sum, 1));
1404 if (summand < 0 || summand > g_switch_value)
1405 return 0;
1406
1407 sym_ref = XEXP (sum, 0);
1408 }
1409
1410 if (*XSTR (sym_ref, 0) != '@')
1411 return 0;
1412
1413 return 1;
1414
1415 #else
1416 return 0;
1417 #endif
1418 }
1419 \f
1420 static int
1421 constant_pool_expr_1 (op, have_sym, have_toc)
1422 rtx op;
1423 int *have_sym;
1424 int *have_toc;
1425 {
1426 switch (GET_CODE(op))
1427 {
1428 case SYMBOL_REF:
1429 if (CONSTANT_POOL_ADDRESS_P (op))
1430 {
1431 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
1432 {
1433 *have_sym = 1;
1434 return 1;
1435 }
1436 else
1437 return 0;
1438 }
1439 else if (! strcmp (XSTR (op, 0), toc_label_name))
1440 {
1441 *have_toc = 1;
1442 return 1;
1443 }
1444 else
1445 return 0;
1446 case PLUS:
1447 case MINUS:
1448 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) &&
1449 constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc);
1450 case CONST:
1451 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
1452 case CONST_INT:
1453 return 1;
1454 default:
1455 return 0;
1456 }
1457 }
1458
1459 int
1460 constant_pool_expr_p (op)
1461 rtx op;
1462 {
1463 int have_sym = 0;
1464 int have_toc = 0;
1465 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
1466 }
1467
1468 int
1469 toc_relative_expr_p (op)
1470 rtx op;
1471 {
1472 int have_sym = 0;
1473 int have_toc = 0;
1474 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
1475 }
1476
1477 /* Try machine-dependent ways of modifying an illegitimate address
1478 to be legitimate. If we find one, return the new, valid address.
1479 This is used from only one place: `memory_address' in explow.c.
1480
1481 OLDX is the address as it was before break_out_memory_refs was called.
1482 In some cases it is useful to look at this to decide what needs to be done.
1483
1484 MODE is passed so that this macro can use GO_IF_LEGITIMATE_ADDRESS.
1485
1486 It is always safe for this macro to do nothing. It exists to recognize
1487 opportunities to optimize the output.
1488
1489 On RS/6000, first check for the sum of a register with a constant
1490 integer that is out of range. If so, generate code to add the
1491 constant with the low-order 16 bits masked to the register and force
1492 this result into another register (this can be done with `cau').
1493 Then generate an address of REG+(CONST&0xffff), allowing for the
1494 possibility of bit 16 being a one.
1495
1496 Then check for the sum of a register and something not constant, try to
1497 load the other things into a register and return the sum. */
1498 rtx
1499 rs6000_legitimize_address (x, oldx, mode)
1500 rtx x;
1501 rtx oldx ATTRIBUTE_UNUSED;
1502 enum machine_mode mode;
1503 {
1504 if (GET_CODE (x) == PLUS
1505 && GET_CODE (XEXP (x, 0)) == REG
1506 && GET_CODE (XEXP (x, 1)) == CONST_INT
1507 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
1508 {
1509 HOST_WIDE_INT high_int, low_int;
1510 rtx sum;
1511 high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff);
1512 low_int = INTVAL (XEXP (x, 1)) & 0xffff;
1513 if (low_int & 0x8000)
1514 high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16;
1515 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
1516 GEN_INT (high_int)), 0);
1517 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
1518 }
1519 else if (GET_CODE (x) == PLUS
1520 && GET_CODE (XEXP (x, 0)) == REG
1521 && GET_CODE (XEXP (x, 1)) != CONST_INT
1522 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1523 && (TARGET_POWERPC64 || mode != DImode)
1524 && mode != TImode)
1525 {
1526 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
1527 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
1528 }
1529 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
1530 && GET_CODE (x) != CONST_INT
1531 && GET_CODE (x) != CONST_DOUBLE
1532 && CONSTANT_P (x)
1533 && (TARGET_HARD_FLOAT || mode != DFmode)
1534 && mode != DImode
1535 && mode != TImode)
1536 {
1537 rtx reg = gen_reg_rtx (Pmode);
1538 emit_insn (gen_elf_high (reg, (x)));
1539 return gen_rtx_LO_SUM (Pmode, reg, (x));
1540 }
1541 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
1542 && ! flag_pic
1543 && GET_CODE (x) != CONST_INT
1544 && GET_CODE (x) != CONST_DOUBLE
1545 && CONSTANT_P (x)
1546 && (TARGET_HARD_FLOAT || mode != DFmode)
1547 && mode != DImode
1548 && mode != TImode)
1549 {
1550 rtx reg = gen_reg_rtx (Pmode);
1551 emit_insn (gen_macho_high (reg, (x)));
1552 return gen_rtx_LO_SUM (Pmode, reg, (x));
1553 }
1554 else if (TARGET_TOC
1555 && CONSTANT_POOL_EXPR_P (x)
1556 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
1557 {
1558 return create_TOC_reference (x);
1559 }
1560 else
1561 return NULL_RTX;
1562 }
1563
1564 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
1565 that is a valid memory address for an instruction.
1566 The MODE argument is the machine mode for the MEM expression
1567 that wants to use this address.
1568
1569 On the RS/6000, there are four valid address: a SYMBOL_REF that
1570 refers to a constant pool entry of an address (or the sum of it
1571 plus a constant), a short (16-bit signed) constant plus a register,
1572 the sum of two registers, or a register indirect, possibly with an
1573 auto-increment. For DFmode and DImode with an constant plus register,
1574 we must ensure that both words are addressable or PowerPC64 with offset
1575 word aligned.
1576
1577 For modes spanning multiple registers (DFmode in 32-bit GPRs,
1578 32-bit DImode, TImode), indexed addressing cannot be used because
1579 adjacent memory cells are accessed by adding word-sized offsets
1580 during assembly output. */
1581 int
1582 rs6000_legitimate_address (mode, x, reg_ok_strict)
1583 enum machine_mode mode;
1584 rtx x;
1585 int reg_ok_strict;
1586 {
1587 if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict))
1588 return 1;
1589 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
1590 && TARGET_UPDATE
1591 && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict))
1592 return 1;
1593 if (LEGITIMATE_SMALL_DATA_P (mode, x))
1594 return 1;
1595 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
1596 return 1;
1597 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
1598 if (! reg_ok_strict
1599 && GET_CODE (x) == PLUS
1600 && GET_CODE (XEXP (x, 0)) == REG
1601 && XEXP (x, 0) == virtual_stack_vars_rtx
1602 && GET_CODE (XEXP (x, 1)) == CONST_INT)
1603 return 1;
1604 if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict))
1605 return 1;
1606 if (mode != TImode
1607 && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode)
1608 && (TARGET_POWERPC64 || mode != DImode)
1609 && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict))
1610 return 1;
1611 if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict))
1612 return 1;
1613 return 0;
1614 }
1615 \f
1616 /* Emit a move from SOURCE to DEST in mode MODE. */
1617 void
1618 rs6000_emit_move (dest, source, mode)
1619 rtx dest;
1620 rtx source;
1621 enum machine_mode mode;
1622 {
1623 rtx operands[2];
1624 operands[0] = dest;
1625 operands[1] = source;
1626
1627 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
1628 if (GET_CODE (operands[1]) == CONST_DOUBLE
1629 && ! FLOAT_MODE_P (mode)
1630 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1631 {
1632 /* FIXME. This should never happen. */
1633 /* Since it seems that it does, do the safe thing and convert
1634 to a CONST_INT. */
1635 operands[1] =
1636 GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode));
1637 }
1638 if (GET_CODE (operands[1]) == CONST_DOUBLE
1639 && ! FLOAT_MODE_P (mode)
1640 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
1641 && CONST_DOUBLE_LOW (operands[1]) >= 0)
1642 || (CONST_DOUBLE_HIGH (operands[1]) == -1
1643 && CONST_DOUBLE_LOW (operands[1]) < 0)))
1644 abort ();
1645
1646 if (! no_new_pseudos && GET_CODE (operands[0]) != REG)
1647 operands[1] = force_reg (mode, operands[1]);
1648
1649 if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT
1650 && GET_CODE (operands[0]) == MEM)
1651 {
1652 int regnum;
1653
1654 if (reload_in_progress || reload_completed)
1655 regnum = true_regnum (operands[1]);
1656 else if (GET_CODE (operands[1]) == REG)
1657 regnum = REGNO (operands[1]);
1658 else
1659 regnum = -1;
1660
1661 /* If operands[1] is a register, on POWER it may have
1662 double-precision data in it, so truncate it to single
1663 precision. */
1664 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
1665 {
1666 rtx newreg;
1667 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
1668 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
1669 operands[1] = newreg;
1670 }
1671 }
1672
1673 /* Handle the case where reload calls us with an invalid address;
1674 and the case of CONSTANT_P_RTX. */
1675 if (! general_operand (operands[1], mode)
1676 || ! nonimmediate_operand (operands[0], mode)
1677 || GET_CODE (operands[1]) == CONSTANT_P_RTX)
1678 {
1679 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1680 return;
1681 }
1682
1683 /* FIXME: In the long term, this switch statement should go away
1684 and be replaced by a sequence of tests based on things like
1685 mode == Pmode. */
1686 switch (mode)
1687 {
1688 case HImode:
1689 case QImode:
1690 if (CONSTANT_P (operands[1])
1691 && GET_CODE (operands[1]) != CONST_INT)
1692 operands[1] = force_const_mem (mode, operands[1]);
1693 break;
1694
1695 case DFmode:
1696 case SFmode:
1697 if (CONSTANT_P (operands[1])
1698 && ! easy_fp_constant (operands[1], mode))
1699 operands[1] = force_const_mem (mode, operands[1]);
1700 break;
1701
1702 case SImode:
1703 case DImode:
1704 /* Use default pattern for address of ELF small data */
1705 if (TARGET_ELF
1706 && mode == Pmode
1707 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1708 && (GET_CODE (operands[1]) == SYMBOL_REF
1709 || GET_CODE (operands[1]) == CONST)
1710 && small_data_operand (operands[1], mode))
1711 {
1712 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1713 return;
1714 }
1715
1716 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1717 && mode == Pmode && mode == SImode
1718 && flag_pic == 1 && got_operand (operands[1], mode))
1719 {
1720 emit_insn (gen_movsi_got (operands[0], operands[1]));
1721 return;
1722 }
1723
1724 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
1725 && TARGET_NO_TOC && ! flag_pic
1726 && mode == Pmode
1727 && CONSTANT_P (operands[1])
1728 && GET_CODE (operands[1]) != HIGH
1729 && GET_CODE (operands[1]) != CONST_INT)
1730 {
1731 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
1732
1733 /* If this is a function address on -mcall-aixdesc,
1734 convert it to the address of the descriptor. */
1735 if (DEFAULT_ABI == ABI_AIX
1736 && GET_CODE (operands[1]) == SYMBOL_REF
1737 && XSTR (operands[1], 0)[0] == '.')
1738 {
1739 const char *name = XSTR (operands[1], 0);
1740 rtx new_ref;
1741 while (*name == '.')
1742 name++;
1743 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
1744 CONSTANT_POOL_ADDRESS_P (new_ref)
1745 = CONSTANT_POOL_ADDRESS_P (operands[1]);
1746 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
1747 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
1748 operands[1] = new_ref;
1749 }
1750
1751 if (DEFAULT_ABI == ABI_DARWIN)
1752 {
1753 emit_insn (gen_macho_high (target, operands[1]));
1754 emit_insn (gen_macho_low (operands[0], target, operands[1]));
1755 return;
1756 }
1757
1758 emit_insn (gen_elf_high (target, operands[1]));
1759 emit_insn (gen_elf_low (operands[0], target, operands[1]));
1760 return;
1761 }
1762
1763 /* If this is a SYMBOL_REF that refers to a constant pool entry,
1764 and we have put it in the TOC, we just need to make a TOC-relative
1765 reference to it. */
1766 if (TARGET_TOC
1767 && GET_CODE (operands[1]) == SYMBOL_REF
1768 && CONSTANT_POOL_EXPR_P (operands[1])
1769 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
1770 get_pool_mode (operands[1])))
1771 {
1772 operands[1] = create_TOC_reference (operands[1]);
1773 }
1774 else if (mode == Pmode
1775 && CONSTANT_P (operands[1])
1776 && ((GET_CODE (operands[1]) != CONST_INT
1777 && ! easy_fp_constant (operands[1], mode))
1778 || (GET_CODE (operands[1]) == CONST_INT
1779 && num_insns_constant (operands[1], mode) > 2)
1780 || (GET_CODE (operands[0]) == REG
1781 && FP_REGNO_P (REGNO (operands[0]))))
1782 && GET_CODE (operands[1]) != HIGH
1783 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
1784 && ! TOC_RELATIVE_EXPR_P (operands[1]))
1785 {
1786 /* Emit a USE operation so that the constant isn't deleted if
1787 expensive optimizations are turned on because nobody
1788 references it. This should only be done for operands that
1789 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
1790 This should not be done for operands that contain LABEL_REFs.
1791 For now, we just handle the obvious case. */
1792 if (GET_CODE (operands[1]) != LABEL_REF)
1793 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
1794
1795 /* Darwin uses a special PIC legitimizer. */
1796 if (DEFAULT_ABI == ABI_DARWIN && flag_pic)
1797 {
1798 #if TARGET_MACHO
1799 rtx temp_reg = ((reload_in_progress || reload_completed)
1800 ? operands[0] : NULL);
1801
1802 operands[1] =
1803 rs6000_machopic_legitimize_pic_address (operands[1], mode,
1804 temp_reg);
1805 #endif
1806 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1807 return;
1808 }
1809
1810 /* If we are to limit the number of things we put in the TOC and
1811 this is a symbol plus a constant we can add in one insn,
1812 just put the symbol in the TOC and add the constant. Don't do
1813 this if reload is in progress. */
1814 if (GET_CODE (operands[1]) == CONST
1815 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
1816 && GET_CODE (XEXP (operands[1], 0)) == PLUS
1817 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
1818 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
1819 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
1820 && ! side_effects_p (operands[0]))
1821 {
1822 rtx sym = force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
1823 rtx other = XEXP (XEXP (operands[1], 0), 1);
1824
1825 sym = force_reg (mode, sym);
1826 if (mode == SImode)
1827 emit_insn (gen_addsi3 (operands[0], sym, other));
1828 else
1829 emit_insn (gen_adddi3 (operands[0], sym, other));
1830 return;
1831 }
1832
1833 operands[1] = force_const_mem (mode, operands[1]);
1834
1835 if (TARGET_TOC
1836 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
1837 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
1838 get_pool_constant (XEXP (operands[1], 0)),
1839 get_pool_mode (XEXP (operands[1], 0))))
1840 {
1841 operands[1] = gen_rtx_MEM (mode,
1842 create_TOC_reference (XEXP (operands[1], 0)));
1843 MEM_ALIAS_SET (operands[1]) = get_TOC_alias_set ();
1844 RTX_UNCHANGING_P (operands[1]) = 1;
1845 }
1846 }
1847 break;
1848
1849 case TImode:
1850 if (GET_CODE (operands[0]) == MEM
1851 && GET_CODE (XEXP (operands[0], 0)) != REG
1852 && ! reload_in_progress)
1853 operands[0] = change_address (operands[0], TImode,
1854 copy_addr_to_reg (XEXP (operands[0], 0)));
1855
1856 if (GET_CODE (operands[1]) == MEM
1857 && GET_CODE (XEXP (operands[1], 0)) != REG
1858 && ! reload_in_progress)
1859 operands[1] = change_address (operands[1], TImode,
1860 copy_addr_to_reg (XEXP (operands[1], 0)));
1861 break;
1862
1863 default:
1864 abort ();
1865 }
1866
1867 /* Above, we may have called force_const_mem which may have returned
1868 an invalid address. If we can, fix this up; otherwise, reload will
1869 have to deal with it. */
1870 if (GET_CODE (operands[1]) == MEM
1871 && ! memory_address_p (mode, XEXP (operands[1], 0))
1872 && ! reload_in_progress)
1873 operands[1] = change_address (operands[1], mode,
1874 XEXP (operands[1], 0));
1875
1876 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1877 return;
1878 }
1879 \f
1880 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1881 for a call to a function whose data type is FNTYPE.
1882 For a library call, FNTYPE is 0.
1883
1884 For incoming args we set the number of arguments in the prototype large
1885 so we never return a PARALLEL. */
1886
1887 void
1888 init_cumulative_args (cum, fntype, libname, incoming)
1889 CUMULATIVE_ARGS *cum;
1890 tree fntype;
1891 rtx libname ATTRIBUTE_UNUSED;
1892 int incoming;
1893 {
1894 static CUMULATIVE_ARGS zero_cumulative;
1895
1896 *cum = zero_cumulative;
1897 cum->words = 0;
1898 cum->fregno = FP_ARG_MIN_REG;
1899 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
1900 cum->call_cookie = CALL_NORMAL;
1901 cum->sysv_gregno = GP_ARG_MIN_REG;
1902
1903 if (incoming)
1904 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
1905
1906 else if (cum->prototype)
1907 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
1908 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
1909 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
1910
1911 else
1912 cum->nargs_prototype = 0;
1913
1914 cum->orig_nargs = cum->nargs_prototype;
1915
1916 /* Check for longcall's */
1917 if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
1918 cum->call_cookie = CALL_LONG;
1919
1920 if (TARGET_DEBUG_ARG)
1921 {
1922 fprintf (stderr, "\ninit_cumulative_args:");
1923 if (fntype)
1924 {
1925 tree ret_type = TREE_TYPE (fntype);
1926 fprintf (stderr, " ret code = %s,",
1927 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1928 }
1929
1930 if (cum->call_cookie & CALL_LONG)
1931 fprintf (stderr, " longcall,");
1932
1933 fprintf (stderr, " proto = %d, nargs = %d\n",
1934 cum->prototype, cum->nargs_prototype);
1935 }
1936 }
1937 \f
1938 /* If defined, a C expression which determines whether, and in which
1939 direction, to pad out an argument with extra space. The value
1940 should be of type `enum direction': either `upward' to pad above
1941 the argument, `downward' to pad below, or `none' to inhibit
1942 padding.
1943
1944 For the AIX ABI structs are always stored left shifted in their
1945 argument slot. */
1946
1947 enum direction
1948 function_arg_padding (mode, type)
1949 enum machine_mode mode;
1950 tree type;
1951 {
1952 if (type != 0 && AGGREGATE_TYPE_P (type))
1953 return upward;
1954
1955 /* This is the default definition. */
1956 return (! BYTES_BIG_ENDIAN
1957 ? upward
1958 : ((mode == BLKmode
1959 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
1960 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
1961 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
1962 ? downward : upward));
1963 }
1964
1965 /* If defined, a C expression that gives the alignment boundary, in bits,
1966 of an argument with the specified mode and type. If it is not defined,
1967 PARM_BOUNDARY is used for all arguments.
1968
1969 V.4 wants long longs to be double word aligned. */
1970
1971 int
1972 function_arg_boundary (mode, type)
1973 enum machine_mode mode;
1974 tree type ATTRIBUTE_UNUSED;
1975 {
1976 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1977 && (mode == DImode || mode == DFmode))
1978 return 64;
1979 else
1980 return PARM_BOUNDARY;
1981 }
1982 \f
1983 /* Update the data in CUM to advance over an argument
1984 of mode MODE and data type TYPE.
1985 (TYPE is null for libcalls where that information may not be available.) */
1986
1987 void
1988 function_arg_advance (cum, mode, type, named)
1989 CUMULATIVE_ARGS *cum;
1990 enum machine_mode mode;
1991 tree type;
1992 int named;
1993 {
1994 cum->nargs_prototype--;
1995
1996 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
1997 {
1998 if (TARGET_HARD_FLOAT
1999 && (mode == SFmode || mode == DFmode))
2000 {
2001 if (cum->fregno <= FP_ARG_V4_MAX_REG)
2002 cum->fregno++;
2003 else
2004 {
2005 if (mode == DFmode)
2006 cum->words += cum->words & 1;
2007 cum->words += RS6000_ARG_SIZE (mode, type);
2008 }
2009 }
2010 else
2011 {
2012 int n_words;
2013 int gregno = cum->sysv_gregno;
2014
2015 /* Aggregates and IEEE quad get passed by reference. */
2016 if ((type && AGGREGATE_TYPE_P (type))
2017 || mode == TFmode)
2018 n_words = 1;
2019 else
2020 n_words = RS6000_ARG_SIZE (mode, type);
2021
2022 /* Long long is put in odd registers. */
2023 if (n_words == 2 && (gregno & 1) == 0)
2024 gregno += 1;
2025
2026 /* Long long is not split between registers and stack. */
2027 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
2028 {
2029 /* Long long is aligned on the stack. */
2030 if (n_words == 2)
2031 cum->words += cum->words & 1;
2032 cum->words += n_words;
2033 }
2034
2035 /* Note: continuing to accumulate gregno past when we've started
2036 spilling to the stack indicates the fact that we've started
2037 spilling to the stack to expand_builtin_saveregs. */
2038 cum->sysv_gregno = gregno + n_words;
2039 }
2040
2041 if (TARGET_DEBUG_ARG)
2042 {
2043 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
2044 cum->words, cum->fregno);
2045 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
2046 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
2047 fprintf (stderr, "mode = %4s, named = %d\n",
2048 GET_MODE_NAME (mode), named);
2049 }
2050 }
2051 else
2052 {
2053 int align = (TARGET_32BIT && (cum->words & 1) != 0
2054 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2055 cum->words += align + RS6000_ARG_SIZE (mode, type);
2056
2057 if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT)
2058 cum->fregno++;
2059
2060 if (TARGET_DEBUG_ARG)
2061 {
2062 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
2063 cum->words, cum->fregno);
2064 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
2065 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
2066 fprintf (stderr, "named = %d, align = %d\n", named, align);
2067 }
2068 }
2069 }
2070 \f
2071 /* Determine where to put an argument to a function.
2072 Value is zero to push the argument on the stack,
2073 or a hard register in which to store the argument.
2074
2075 MODE is the argument's machine mode.
2076 TYPE is the data type of the argument (as a tree).
2077 This is null for libcalls where that information may
2078 not be available.
2079 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2080 the preceding args and about the function being called.
2081 NAMED is nonzero if this argument is a named parameter
2082 (otherwise it is an extra parameter matching an ellipsis).
2083
2084 On RS/6000 the first eight words of non-FP are normally in registers
2085 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
2086 Under V.4, the first 8 FP args are in registers.
2087
2088 If this is floating-point and no prototype is specified, we use
2089 both an FP and integer register (or possibly FP reg and stack). Library
2090 functions (when TYPE is zero) always have the proper types for args,
2091 so we can pass the FP value just in one register. emit_library_function
2092 doesn't support PARALLEL anyway. */
2093
2094 struct rtx_def *
2095 function_arg (cum, mode, type, named)
2096 CUMULATIVE_ARGS *cum;
2097 enum machine_mode mode;
2098 tree type;
2099 int named ATTRIBUTE_UNUSED;
2100 {
2101 enum rs6000_abi abi = DEFAULT_ABI;
2102
2103 /* Return a marker to indicate whether CR1 needs to set or clear the bit
2104 that V.4 uses to say fp args were passed in registers. Assume that we
2105 don't need the marker for software floating point, or compiler generated
2106 library calls. */
2107 if (mode == VOIDmode)
2108 {
2109 if ((abi == ABI_V4 || abi == ABI_SOLARIS)
2110 && TARGET_HARD_FLOAT
2111 && cum->nargs_prototype < 0
2112 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
2113 {
2114 return GEN_INT (cum->call_cookie
2115 | ((cum->fregno == FP_ARG_MIN_REG)
2116 ? CALL_V4_SET_FP_ARGS
2117 : CALL_V4_CLEAR_FP_ARGS));
2118 }
2119
2120 return GEN_INT (cum->call_cookie);
2121 }
2122
2123 if (abi == ABI_V4 || abi == ABI_SOLARIS)
2124 {
2125 if (TARGET_HARD_FLOAT
2126 && (mode == SFmode || mode == DFmode))
2127 {
2128 if (cum->fregno <= FP_ARG_V4_MAX_REG)
2129 return gen_rtx_REG (mode, cum->fregno);
2130 else
2131 return NULL;
2132 }
2133 else
2134 {
2135 int n_words;
2136 int gregno = cum->sysv_gregno;
2137
2138 /* Aggregates and IEEE quad get passed by reference. */
2139 if ((type && AGGREGATE_TYPE_P (type))
2140 || mode == TFmode)
2141 n_words = 1;
2142 else
2143 n_words = RS6000_ARG_SIZE (mode, type);
2144
2145 /* Long long is put in odd registers. */
2146 if (n_words == 2 && (gregno & 1) == 0)
2147 gregno += 1;
2148
2149 /* Long long is not split between registers and stack. */
2150 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
2151 return gen_rtx_REG (mode, gregno);
2152 else
2153 return NULL;
2154 }
2155 }
2156 else
2157 {
2158 int align = (TARGET_32BIT && (cum->words & 1) != 0
2159 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
2160 int align_words = cum->words + align;
2161
2162 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
2163 return NULL_RTX;
2164
2165 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2166 {
2167 if (! type
2168 || ((cum->nargs_prototype > 0)
2169 /* IBM AIX extended its linkage convention definition always
2170 to require FP args after register save area hole on the
2171 stack. */
2172 && (DEFAULT_ABI != ABI_AIX
2173 || ! TARGET_XL_CALL
2174 || (align_words < GP_ARG_NUM_REG))))
2175 return gen_rtx_REG (mode, cum->fregno);
2176
2177 return gen_rtx_PARALLEL (mode,
2178 gen_rtvec (2,
2179 gen_rtx_EXPR_LIST (VOIDmode,
2180 ((align_words >= GP_ARG_NUM_REG)
2181 ? NULL_RTX
2182 : (align_words
2183 + RS6000_ARG_SIZE (mode, type)
2184 > GP_ARG_NUM_REG
2185 /* If this is partially on the stack, then
2186 we only include the portion actually
2187 in registers here. */
2188 ? gen_rtx_REG (SImode,
2189 GP_ARG_MIN_REG + align_words)
2190 : gen_rtx_REG (mode,
2191 GP_ARG_MIN_REG + align_words))),
2192 const0_rtx),
2193 gen_rtx_EXPR_LIST (VOIDmode,
2194 gen_rtx_REG (mode, cum->fregno),
2195 const0_rtx)));
2196 }
2197 else if (align_words < GP_ARG_NUM_REG)
2198 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
2199 else
2200 return NULL_RTX;
2201 }
2202 }
2203 \f
2204 /* For an arg passed partly in registers and partly in memory,
2205 this is the number of registers used.
2206 For args passed entirely in registers or entirely in memory, zero. */
2207
2208 int
2209 function_arg_partial_nregs (cum, mode, type, named)
2210 CUMULATIVE_ARGS *cum;
2211 enum machine_mode mode;
2212 tree type;
2213 int named ATTRIBUTE_UNUSED;
2214 {
2215 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2216 return 0;
2217
2218 if (USE_FP_FOR_ARG_P (*cum, mode, type))
2219 {
2220 if (cum->nargs_prototype >= 0)
2221 return 0;
2222 }
2223
2224 if (cum->words < GP_ARG_NUM_REG
2225 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
2226 {
2227 int ret = GP_ARG_NUM_REG - cum->words;
2228 if (ret && TARGET_DEBUG_ARG)
2229 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2230
2231 return ret;
2232 }
2233
2234 return 0;
2235 }
2236 \f
2237 /* A C expression that indicates when an argument must be passed by
2238 reference. If nonzero for an argument, a copy of that argument is
2239 made in memory and a pointer to the argument is passed instead of
2240 the argument itself. The pointer is passed in whatever way is
2241 appropriate for passing a pointer to that type.
2242
2243 Under V.4, structures and unions are passed by reference. */
2244
2245 int
2246 function_arg_pass_by_reference (cum, mode, type, named)
2247 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2248 enum machine_mode mode ATTRIBUTE_UNUSED;
2249 tree type;
2250 int named ATTRIBUTE_UNUSED;
2251 {
2252 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2253 && ((type && AGGREGATE_TYPE_P (type))
2254 || mode == TFmode))
2255 {
2256 if (TARGET_DEBUG_ARG)
2257 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
2258
2259 return 1;
2260 }
2261
2262 return 0;
2263 }
2264 \f
2265 /* Perform any needed actions needed for a function that is receiving a
2266 variable number of arguments.
2267
2268 CUM is as above.
2269
2270 MODE and TYPE are the mode and type of the current parameter.
2271
2272 PRETEND_SIZE is a variable that should be set to the amount of stack
2273 that must be pushed by the prolog to pretend that our caller pushed
2274 it.
2275
2276 Normally, this macro will push all remaining incoming registers on the
2277 stack and set PRETEND_SIZE to the length of the registers pushed. */
2278
2279 void
2280 setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2281 CUMULATIVE_ARGS *cum;
2282 enum machine_mode mode;
2283 tree type;
2284 int *pretend_size;
2285 int no_rtl;
2286
2287 {
2288 CUMULATIVE_ARGS next_cum;
2289 int reg_size = TARGET_32BIT ? 4 : 8;
2290 rtx save_area = NULL_RTX, mem;
2291 int first_reg_offset, set;
2292 tree fntype;
2293 int stdarg_p;
2294
2295 fntype = TREE_TYPE (current_function_decl);
2296 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
2297 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
2298 != void_type_node));
2299
2300 /* For varargs, we do not want to skip the dummy va_dcl argument.
2301 For stdargs, we do want to skip the last named argument. */
2302 next_cum = *cum;
2303 if (stdarg_p)
2304 function_arg_advance (&next_cum, mode, type, 1);
2305
2306 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2307 {
2308 /* Indicate to allocate space on the stack for varargs save area. */
2309 /* ??? Does this really have to be located at a magic spot on the
2310 stack, or can we allocate this with assign_stack_local instead. */
2311 cfun->machine->sysv_varargs_p = 1;
2312 if (! no_rtl)
2313 save_area = plus_constant (virtual_stack_vars_rtx,
2314 - RS6000_VARARGS_SIZE);
2315
2316 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
2317 }
2318 else
2319 {
2320 first_reg_offset = next_cum.words;
2321 save_area = virtual_incoming_args_rtx;
2322 cfun->machine->sysv_varargs_p = 0;
2323
2324 if (MUST_PASS_IN_STACK (mode, type))
2325 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
2326 }
2327
2328 set = get_varargs_alias_set ();
2329 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
2330 {
2331 mem = gen_rtx_MEM (BLKmode,
2332 plus_constant (save_area,
2333 first_reg_offset * reg_size)),
2334 MEM_ALIAS_SET (mem) = set;
2335
2336 move_block_from_reg
2337 (GP_ARG_MIN_REG + first_reg_offset, mem,
2338 GP_ARG_NUM_REG - first_reg_offset,
2339 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
2340
2341 /* ??? Does ABI_V4 need this at all? */
2342 *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
2343 }
2344
2345 /* Save FP registers if needed. */
2346 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
2347 && TARGET_HARD_FLOAT && ! no_rtl
2348 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
2349 {
2350 int fregno = next_cum.fregno;
2351 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
2352 rtx lab = gen_label_rtx ();
2353 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
2354
2355 emit_jump_insn (gen_rtx_SET (VOIDmode,
2356 pc_rtx,
2357 gen_rtx_IF_THEN_ELSE (VOIDmode,
2358 gen_rtx_NE (VOIDmode, cr1,
2359 const0_rtx),
2360 gen_rtx_LABEL_REF (VOIDmode, lab),
2361 pc_rtx)));
2362
2363 while (fregno <= FP_ARG_V4_MAX_REG)
2364 {
2365 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
2366 MEM_ALIAS_SET (mem) = set;
2367 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
2368 fregno++;
2369 off += 8;
2370 }
2371
2372 emit_label (lab);
2373 }
2374 }
2375
2376 /* Create the va_list data type. */
2377
2378 tree
2379 rs6000_build_va_list ()
2380 {
2381 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
2382
2383 /* For AIX, prefer 'char *' because that's what the system
2384 header files like. */
2385 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2386 return build_pointer_type (char_type_node);
2387
2388 record = make_lang_type (RECORD_TYPE);
2389 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2390
2391 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
2392 unsigned_char_type_node);
2393 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
2394 unsigned_char_type_node);
2395 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
2396 ptr_type_node);
2397 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
2398 ptr_type_node);
2399
2400 DECL_FIELD_CONTEXT (f_gpr) = record;
2401 DECL_FIELD_CONTEXT (f_fpr) = record;
2402 DECL_FIELD_CONTEXT (f_ovf) = record;
2403 DECL_FIELD_CONTEXT (f_sav) = record;
2404
2405 TREE_CHAIN (record) = type_decl;
2406 TYPE_NAME (record) = type_decl;
2407 TYPE_FIELDS (record) = f_gpr;
2408 TREE_CHAIN (f_gpr) = f_fpr;
2409 TREE_CHAIN (f_fpr) = f_ovf;
2410 TREE_CHAIN (f_ovf) = f_sav;
2411
2412 layout_type (record);
2413
2414 /* The correct type is an array type of one element. */
2415 return build_array_type (record, build_index_type (size_zero_node));
2416 }
2417
2418 /* Implement va_start. */
2419
2420 void
2421 rs6000_va_start (stdarg_p, valist, nextarg)
2422 int stdarg_p;
2423 tree valist;
2424 rtx nextarg;
2425 {
2426 HOST_WIDE_INT words, n_gpr, n_fpr;
2427 tree f_gpr, f_fpr, f_ovf, f_sav;
2428 tree gpr, fpr, ovf, sav, t;
2429
2430 /* Only SVR4 needs something special. */
2431 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2432 {
2433 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
2434 return;
2435 }
2436
2437 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2438 f_fpr = TREE_CHAIN (f_gpr);
2439 f_ovf = TREE_CHAIN (f_fpr);
2440 f_sav = TREE_CHAIN (f_ovf);
2441
2442 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2443 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2444 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2445 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2446 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2447
2448 /* Count number of gp and fp argument registers used. */
2449 words = current_function_args_info.words;
2450 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
2451 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
2452
2453 if (TARGET_DEBUG_ARG)
2454 {
2455 fputs ("va_start: words = ", stderr);
2456 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words);
2457 fputs (", n_gpr = ", stderr);
2458 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr);
2459 fputs (", n_fpr = ", stderr);
2460 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr);
2461 putc ('\n', stderr);
2462 }
2463
2464 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
2465 TREE_SIDE_EFFECTS (t) = 1;
2466 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2467
2468 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
2469 TREE_SIDE_EFFECTS (t) = 1;
2470 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2471
2472 /* Find the overflow area. */
2473 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
2474 if (words != 0)
2475 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
2476 build_int_2 (words * UNITS_PER_WORD, 0));
2477 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2478 TREE_SIDE_EFFECTS (t) = 1;
2479 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2480
2481 /* Find the register save area. */
2482 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
2483 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
2484 build_int_2 (-RS6000_VARARGS_SIZE, -1));
2485 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
2486 TREE_SIDE_EFFECTS (t) = 1;
2487 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2488 }
2489
2490 /* Implement va_arg. */
2491
2492 rtx
2493 rs6000_va_arg (valist, type)
2494 tree valist, type;
2495 {
2496 tree f_gpr, f_fpr, f_ovf, f_sav;
2497 tree gpr, fpr, ovf, sav, reg, t, u;
2498 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
2499 rtx lab_false, lab_over, addr_rtx, r;
2500
2501 /* For AIX, the rule is that structures are passed left-aligned in
2502 their stack slot. However, GCC does not presently do this:
2503 structures which are the same size as integer types are passed
2504 right-aligned, as if they were in fact integers. This only
2505 matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */
2506 if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
2507 {
2508 HOST_WIDE_INT align, rounded_size;
2509 enum machine_mode mode;
2510 tree addr_tree;
2511
2512 /* Compute the rounded size of the type. */
2513 align = PARM_BOUNDARY / BITS_PER_UNIT;
2514 rounded_size = (((int_size_in_bytes (type) + align - 1) / align)
2515 * align);
2516
2517 addr_tree = valist;
2518
2519 mode = TYPE_MODE (type);
2520 if (mode != BLKmode)
2521 {
2522 HOST_WIDE_INT adj;
2523 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
2524 if (rounded_size > align)
2525 adj = rounded_size;
2526
2527 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
2528 build_int_2 (rounded_size - adj, 0));
2529 }
2530
2531 addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2532 addr_rtx = copy_to_reg (addr_rtx);
2533
2534 /* Compute new value for AP. */
2535 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2536 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2537 build_int_2 (rounded_size, 0)));
2538 TREE_SIDE_EFFECTS (t) = 1;
2539 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2540
2541 return addr_rtx;
2542 }
2543
2544 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2545 f_fpr = TREE_CHAIN (f_gpr);
2546 f_ovf = TREE_CHAIN (f_fpr);
2547 f_sav = TREE_CHAIN (f_ovf);
2548
2549 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2550 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
2551 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
2552 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
2553 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
2554
2555 size = int_size_in_bytes (type);
2556 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2557
2558 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
2559 {
2560 /* Aggregates and long doubles are passed by reference. */
2561 indirect_p = 1;
2562 reg = gpr;
2563 n_reg = 1;
2564 sav_ofs = 0;
2565 sav_scale = 4;
2566 size = rsize = UNITS_PER_WORD;
2567 }
2568 else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT)
2569 {
2570 /* FP args go in FP registers, if present. */
2571 indirect_p = 0;
2572 reg = fpr;
2573 n_reg = 1;
2574 sav_ofs = 8*4;
2575 sav_scale = 8;
2576 }
2577 else
2578 {
2579 /* Otherwise into GP registers. */
2580 indirect_p = 0;
2581 reg = gpr;
2582 n_reg = rsize;
2583 sav_ofs = 0;
2584 sav_scale = 4;
2585 }
2586
2587 /*
2588 * Pull the value out of the saved registers ...
2589 */
2590
2591 lab_false = gen_label_rtx ();
2592 lab_over = gen_label_rtx ();
2593 addr_rtx = gen_reg_rtx (Pmode);
2594
2595 emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
2596 GEN_INT (8 - n_reg + 1),
2597 GE, const1_rtx, QImode, 1, 1, lab_false);
2598
2599 /* Long long is aligned in the registers. */
2600 if (n_reg > 1)
2601 {
2602 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
2603 build_int_2 (n_reg - 1, 0));
2604 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
2605 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
2606 TREE_SIDE_EFFECTS (u) = 1;
2607 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
2608 }
2609
2610 if (sav_ofs)
2611 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2612 else
2613 t = sav;
2614
2615 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0));
2616 TREE_SIDE_EFFECTS (u) = 1;
2617
2618 u = build1 (CONVERT_EXPR, integer_type_node, u);
2619 TREE_SIDE_EFFECTS (u) = 1;
2620
2621 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
2622 TREE_SIDE_EFFECTS (u) = 1;
2623
2624 t = build (PLUS_EXPR, ptr_type_node, t, u);
2625 TREE_SIDE_EFFECTS (t) = 1;
2626
2627 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2628 if (r != addr_rtx)
2629 emit_move_insn (addr_rtx, r);
2630
2631 emit_jump_insn (gen_jump (lab_over));
2632 emit_barrier ();
2633 emit_label (lab_false);
2634
2635 /*
2636 * ... otherwise out of the overflow area.
2637 */
2638
2639 /* Make sure we don't find reg 7 for the next int arg. */
2640 if (n_reg > 1)
2641 {
2642 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
2643 TREE_SIDE_EFFECTS (t) = 1;
2644 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2645 }
2646
2647 /* Care for on-stack alignment if needed. */
2648 if (rsize <= 1)
2649 t = ovf;
2650 else
2651 {
2652 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0));
2653 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1));
2654 }
2655 t = save_expr (t);
2656
2657 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
2658 if (r != addr_rtx)
2659 emit_move_insn (addr_rtx, r);
2660
2661 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
2662 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
2663 TREE_SIDE_EFFECTS (t) = 1;
2664 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2665
2666 emit_label (lab_over);
2667
2668 if (indirect_p)
2669 {
2670 r = gen_rtx_MEM (Pmode, addr_rtx);
2671 MEM_ALIAS_SET (r) = get_varargs_alias_set ();
2672 emit_move_insn (addr_rtx, r);
2673 }
2674
2675 return addr_rtx;
2676 }
2677 \f
2678 /* Generate a memory reference for expand_block_move, copying volatile,
2679 and other bits from an original memory reference. */
2680
2681 static rtx
2682 expand_block_move_mem (mode, addr, orig_mem)
2683 enum machine_mode mode;
2684 rtx addr;
2685 rtx orig_mem;
2686 {
2687 rtx mem = gen_rtx_MEM (mode, addr);
2688
2689 MEM_COPY_ATTRIBUTES (mem, orig_mem);
2690 #ifdef MEM_UNALIGNED_P
2691 MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
2692 #endif
2693 return mem;
2694 }
2695
2696 /* Expand a block move operation, and return 1 if successful. Return 0
2697 if we should let the compiler generate normal code.
2698
2699 operands[0] is the destination
2700 operands[1] is the source
2701 operands[2] is the length
2702 operands[3] is the alignment */
2703
2704 #define MAX_MOVE_REG 4
2705
2706 int
2707 expand_block_move (operands)
2708 rtx operands[];
2709 {
2710 rtx orig_dest = operands[0];
2711 rtx orig_src = operands[1];
2712 rtx bytes_rtx = operands[2];
2713 rtx align_rtx = operands[3];
2714 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2715 int align;
2716 int bytes;
2717 int offset;
2718 int num_reg;
2719 int i;
2720 rtx src_reg;
2721 rtx dest_reg;
2722 rtx src_addr;
2723 rtx dest_addr;
2724 rtx tmp_reg;
2725 rtx stores[MAX_MOVE_REG];
2726 int move_bytes;
2727
2728 /* If this is not a fixed size move, just call memcpy */
2729 if (! constp)
2730 return 0;
2731
2732 /* If this is not a fixed size alignment, abort */
2733 if (GET_CODE (align_rtx) != CONST_INT)
2734 abort ();
2735 align = INTVAL (align_rtx);
2736
2737 /* Anything to move? */
2738 bytes = INTVAL (bytes_rtx);
2739 if (bytes <= 0)
2740 return 1;
2741
2742 /* Don't support real large moves. If string instructions are not used,
2743 then don't generate more than 8 loads. */
2744 if (TARGET_STRING)
2745 {
2746 if (bytes > 8*4)
2747 return 0;
2748 }
2749 else if (! STRICT_ALIGNMENT)
2750 {
2751 if (TARGET_POWERPC64 && align >= 4)
2752 {
2753 if (bytes > 8*8)
2754 return 0;
2755 }
2756 else
2757 if (bytes > 8*4)
2758 return 0;
2759 }
2760 else if (bytes > 8*align)
2761 return 0;
2762
2763 /* Move the address into scratch registers. */
2764 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2765 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2766
2767 if (TARGET_STRING) /* string instructions are available */
2768 {
2769 for ( ; bytes > 0; bytes -= move_bytes)
2770 {
2771 if (bytes > 24 /* move up to 32 bytes at a time */
2772 && ! fixed_regs[5]
2773 && ! fixed_regs[6]
2774 && ! fixed_regs[7]
2775 && ! fixed_regs[8]
2776 && ! fixed_regs[9]
2777 && ! fixed_regs[10]
2778 && ! fixed_regs[11]
2779 && ! fixed_regs[12])
2780 {
2781 move_bytes = (bytes > 32) ? 32 : bytes;
2782 emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode,
2783 dest_reg,
2784 orig_dest),
2785 expand_block_move_mem (BLKmode,
2786 src_reg,
2787 orig_src),
2788 GEN_INT ((move_bytes == 32)
2789 ? 0 : move_bytes),
2790 align_rtx));
2791 }
2792 else if (bytes > 16 /* move up to 24 bytes at a time */
2793 && ! fixed_regs[5]
2794 && ! fixed_regs[6]
2795 && ! fixed_regs[7]
2796 && ! fixed_regs[8]
2797 && ! fixed_regs[9]
2798 && ! fixed_regs[10])
2799 {
2800 move_bytes = (bytes > 24) ? 24 : bytes;
2801 emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode,
2802 dest_reg,
2803 orig_dest),
2804 expand_block_move_mem (BLKmode,
2805 src_reg,
2806 orig_src),
2807 GEN_INT (move_bytes),
2808 align_rtx));
2809 }
2810 else if (bytes > 8 /* move up to 16 bytes at a time */
2811 && ! fixed_regs[5]
2812 && ! fixed_regs[6]
2813 && ! fixed_regs[7]
2814 && ! fixed_regs[8])
2815 {
2816 move_bytes = (bytes > 16) ? 16 : bytes;
2817 emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode,
2818 dest_reg,
2819 orig_dest),
2820 expand_block_move_mem (BLKmode,
2821 src_reg,
2822 orig_src),
2823 GEN_INT (move_bytes),
2824 align_rtx));
2825 }
2826 else if (bytes >= 8 && TARGET_POWERPC64
2827 /* 64-bit loads and stores require word-aligned displacements. */
2828 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2829 {
2830 move_bytes = 8;
2831 tmp_reg = gen_reg_rtx (DImode);
2832 emit_move_insn (tmp_reg,
2833 expand_block_move_mem (DImode,
2834 src_reg, orig_src));
2835 emit_move_insn (expand_block_move_mem (DImode,
2836 dest_reg, orig_dest),
2837 tmp_reg);
2838 }
2839 else if (bytes > 4)
2840 { /* move up to 8 bytes at a time */
2841 move_bytes = (bytes > 8) ? 8 : bytes;
2842 emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode,
2843 dest_reg,
2844 orig_dest),
2845 expand_block_move_mem (BLKmode,
2846 src_reg,
2847 orig_src),
2848 GEN_INT (move_bytes),
2849 align_rtx));
2850 }
2851 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2852 { /* move 4 bytes */
2853 move_bytes = 4;
2854 tmp_reg = gen_reg_rtx (SImode);
2855 emit_move_insn (tmp_reg,
2856 expand_block_move_mem (SImode,
2857 src_reg, orig_src));
2858 emit_move_insn (expand_block_move_mem (SImode,
2859 dest_reg, orig_dest),
2860 tmp_reg);
2861 }
2862 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2863 { /* move 2 bytes */
2864 move_bytes = 2;
2865 tmp_reg = gen_reg_rtx (HImode);
2866 emit_move_insn (tmp_reg,
2867 expand_block_move_mem (HImode,
2868 src_reg, orig_src));
2869 emit_move_insn (expand_block_move_mem (HImode,
2870 dest_reg, orig_dest),
2871 tmp_reg);
2872 }
2873 else if (bytes == 1) /* move 1 byte */
2874 {
2875 move_bytes = 1;
2876 tmp_reg = gen_reg_rtx (QImode);
2877 emit_move_insn (tmp_reg,
2878 expand_block_move_mem (QImode,
2879 src_reg, orig_src));
2880 emit_move_insn (expand_block_move_mem (QImode,
2881 dest_reg, orig_dest),
2882 tmp_reg);
2883 }
2884 else
2885 { /* move up to 4 bytes at a time */
2886 move_bytes = (bytes > 4) ? 4 : bytes;
2887 emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode,
2888 dest_reg,
2889 orig_dest),
2890 expand_block_move_mem (BLKmode,
2891 src_reg,
2892 orig_src),
2893 GEN_INT (move_bytes),
2894 align_rtx));
2895 }
2896
2897 if (bytes > move_bytes)
2898 {
2899 if (! TARGET_POWERPC64)
2900 {
2901 emit_insn (gen_addsi3 (src_reg, src_reg,
2902 GEN_INT (move_bytes)));
2903 emit_insn (gen_addsi3 (dest_reg, dest_reg,
2904 GEN_INT (move_bytes)));
2905 }
2906 else
2907 {
2908 emit_insn (gen_adddi3 (src_reg, src_reg,
2909 GEN_INT (move_bytes)));
2910 emit_insn (gen_adddi3 (dest_reg, dest_reg,
2911 GEN_INT (move_bytes)));
2912 }
2913 }
2914 }
2915 }
2916
2917 else /* string instructions not available */
2918 {
2919 num_reg = offset = 0;
2920 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2921 {
2922 /* Calculate the correct offset for src/dest */
2923 if (offset == 0)
2924 {
2925 src_addr = src_reg;
2926 dest_addr = dest_reg;
2927 }
2928 else
2929 {
2930 src_addr = plus_constant (src_reg, offset);
2931 dest_addr = plus_constant (dest_reg, offset);
2932 }
2933
2934 /* Generate the appropriate load and store, saving the stores
2935 for later. */
2936 if (bytes >= 8 && TARGET_POWERPC64
2937 /* 64-bit loads and stores require word-aligned displacements. */
2938 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
2939 {
2940 move_bytes = 8;
2941 tmp_reg = gen_reg_rtx (DImode);
2942 emit_insn (gen_movdi (tmp_reg,
2943 expand_block_move_mem (DImode,
2944 src_addr,
2945 orig_src)));
2946 stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode,
2947 dest_addr,
2948 orig_dest),
2949 tmp_reg);
2950 }
2951 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
2952 {
2953 move_bytes = 4;
2954 tmp_reg = gen_reg_rtx (SImode);
2955 emit_insn (gen_movsi (tmp_reg,
2956 expand_block_move_mem (SImode,
2957 src_addr,
2958 orig_src)));
2959 stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode,
2960 dest_addr,
2961 orig_dest),
2962 tmp_reg);
2963 }
2964 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
2965 {
2966 move_bytes = 2;
2967 tmp_reg = gen_reg_rtx (HImode);
2968 emit_insn (gen_movhi (tmp_reg,
2969 expand_block_move_mem (HImode,
2970 src_addr,
2971 orig_src)));
2972 stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode,
2973 dest_addr,
2974 orig_dest),
2975 tmp_reg);
2976 }
2977 else
2978 {
2979 move_bytes = 1;
2980 tmp_reg = gen_reg_rtx (QImode);
2981 emit_insn (gen_movqi (tmp_reg,
2982 expand_block_move_mem (QImode,
2983 src_addr,
2984 orig_src)));
2985 stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode,
2986 dest_addr,
2987 orig_dest),
2988 tmp_reg);
2989 }
2990
2991 if (num_reg >= MAX_MOVE_REG)
2992 {
2993 for (i = 0; i < num_reg; i++)
2994 emit_insn (stores[i]);
2995 num_reg = 0;
2996 }
2997 }
2998
2999 for (i = 0; i < num_reg; i++)
3000 emit_insn (stores[i]);
3001 }
3002
3003 return 1;
3004 }
3005
3006 \f
3007 /* Return 1 if OP is a load multiple operation. It is known to be a
3008 PARALLEL and the first section will be tested. */
3009
3010 int
3011 load_multiple_operation (op, mode)
3012 rtx op;
3013 enum machine_mode mode ATTRIBUTE_UNUSED;
3014 {
3015 int count = XVECLEN (op, 0);
3016 unsigned int dest_regno;
3017 rtx src_addr;
3018 int i;
3019
3020 /* Perform a quick check so we don't blow up below. */
3021 if (count <= 1
3022 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3023 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
3024 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
3025 return 0;
3026
3027 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
3028 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
3029
3030 for (i = 1; i < count; i++)
3031 {
3032 rtx elt = XVECEXP (op, 0, i);
3033
3034 if (GET_CODE (elt) != SET
3035 || GET_CODE (SET_DEST (elt)) != REG
3036 || GET_MODE (SET_DEST (elt)) != SImode
3037 || REGNO (SET_DEST (elt)) != dest_regno + i
3038 || GET_CODE (SET_SRC (elt)) != MEM
3039 || GET_MODE (SET_SRC (elt)) != SImode
3040 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
3041 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
3042 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
3043 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
3044 return 0;
3045 }
3046
3047 return 1;
3048 }
3049
3050 /* Similar, but tests for store multiple. Here, the second vector element
3051 is a CLOBBER. It will be tested later. */
3052
3053 int
3054 store_multiple_operation (op, mode)
3055 rtx op;
3056 enum machine_mode mode ATTRIBUTE_UNUSED;
3057 {
3058 int count = XVECLEN (op, 0) - 1;
3059 unsigned int src_regno;
3060 rtx dest_addr;
3061 int i;
3062
3063 /* Perform a quick check so we don't blow up below. */
3064 if (count <= 1
3065 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3066 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
3067 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
3068 return 0;
3069
3070 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
3071 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
3072
3073 for (i = 1; i < count; i++)
3074 {
3075 rtx elt = XVECEXP (op, 0, i + 1);
3076
3077 if (GET_CODE (elt) != SET
3078 || GET_CODE (SET_SRC (elt)) != REG
3079 || GET_MODE (SET_SRC (elt)) != SImode
3080 || REGNO (SET_SRC (elt)) != src_regno + i
3081 || GET_CODE (SET_DEST (elt)) != MEM
3082 || GET_MODE (SET_DEST (elt)) != SImode
3083 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
3084 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
3085 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
3086 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
3087 return 0;
3088 }
3089
3090 return 1;
3091 }
3092
3093 /* Return 1 for an PARALLEL suitable for mtcrf. */
3094
3095 int
3096 mtcrf_operation (op, mode)
3097 rtx op;
3098 enum machine_mode mode ATTRIBUTE_UNUSED;
3099 {
3100 int count = XVECLEN (op, 0);
3101 int i;
3102 rtx src_reg;
3103
3104 /* Perform a quick check so we don't blow up below. */
3105 if (count < 1
3106 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3107 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
3108 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
3109 return 0;
3110 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
3111
3112 if (GET_CODE (src_reg) != REG
3113 || GET_MODE (src_reg) != SImode
3114 || ! INT_REGNO_P (REGNO (src_reg)))
3115 return 0;
3116
3117 for (i = 0; i < count; i++)
3118 {
3119 rtx exp = XVECEXP (op, 0, i);
3120 rtx unspec;
3121 int maskval;
3122
3123 if (GET_CODE (exp) != SET
3124 || GET_CODE (SET_DEST (exp)) != REG
3125 || GET_MODE (SET_DEST (exp)) != CCmode
3126 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
3127 return 0;
3128 unspec = SET_SRC (exp);
3129 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
3130
3131 if (GET_CODE (unspec) != UNSPEC
3132 || XINT (unspec, 1) != 20
3133 || XVECLEN (unspec, 0) != 2
3134 || XVECEXP (unspec, 0, 0) != src_reg
3135 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
3136 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
3137 return 0;
3138 }
3139 return 1;
3140 }
3141
3142 /* Return 1 for an PARALLEL suitable for lmw. */
3143
3144 int
3145 lmw_operation (op, mode)
3146 rtx op;
3147 enum machine_mode mode ATTRIBUTE_UNUSED;
3148 {
3149 int count = XVECLEN (op, 0);
3150 unsigned int dest_regno;
3151 rtx src_addr;
3152 unsigned int base_regno;
3153 HOST_WIDE_INT offset;
3154 int i;
3155
3156 /* Perform a quick check so we don't blow up below. */
3157 if (count <= 1
3158 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3159 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
3160 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
3161 return 0;
3162
3163 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
3164 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
3165
3166 if (dest_regno > 31
3167 || count != 32 - (int) dest_regno)
3168 return 0;
3169
3170 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0))
3171 {
3172 offset = 0;
3173 base_regno = REGNO (src_addr);
3174 if (base_regno == 0)
3175 return 0;
3176 }
3177 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0))
3178 {
3179 offset = INTVAL (XEXP (src_addr, 1));
3180 base_regno = REGNO (XEXP (src_addr, 0));
3181 }
3182 else
3183 return 0;
3184
3185 for (i = 0; i < count; i++)
3186 {
3187 rtx elt = XVECEXP (op, 0, i);
3188 rtx newaddr;
3189 rtx addr_reg;
3190 HOST_WIDE_INT newoffset;
3191
3192 if (GET_CODE (elt) != SET
3193 || GET_CODE (SET_DEST (elt)) != REG
3194 || GET_MODE (SET_DEST (elt)) != SImode
3195 || REGNO (SET_DEST (elt)) != dest_regno + i
3196 || GET_CODE (SET_SRC (elt)) != MEM
3197 || GET_MODE (SET_SRC (elt)) != SImode)
3198 return 0;
3199 newaddr = XEXP (SET_SRC (elt), 0);
3200 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
3201 {
3202 newoffset = 0;
3203 addr_reg = newaddr;
3204 }
3205 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
3206 {
3207 addr_reg = XEXP (newaddr, 0);
3208 newoffset = INTVAL (XEXP (newaddr, 1));
3209 }
3210 else
3211 return 0;
3212 if (REGNO (addr_reg) != base_regno
3213 || newoffset != offset + 4 * i)
3214 return 0;
3215 }
3216
3217 return 1;
3218 }
3219
3220 /* Return 1 for an PARALLEL suitable for stmw. */
3221
3222 int
3223 stmw_operation (op, mode)
3224 rtx op;
3225 enum machine_mode mode ATTRIBUTE_UNUSED;
3226 {
3227 int count = XVECLEN (op, 0);
3228 unsigned int src_regno;
3229 rtx dest_addr;
3230 unsigned int base_regno;
3231 HOST_WIDE_INT offset;
3232 int i;
3233
3234 /* Perform a quick check so we don't blow up below. */
3235 if (count <= 1
3236 || GET_CODE (XVECEXP (op, 0, 0)) != SET
3237 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
3238 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
3239 return 0;
3240
3241 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
3242 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
3243
3244 if (src_regno > 31
3245 || count != 32 - (int) src_regno)
3246 return 0;
3247
3248 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0))
3249 {
3250 offset = 0;
3251 base_regno = REGNO (dest_addr);
3252 if (base_regno == 0)
3253 return 0;
3254 }
3255 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0))
3256 {
3257 offset = INTVAL (XEXP (dest_addr, 1));
3258 base_regno = REGNO (XEXP (dest_addr, 0));
3259 }
3260 else
3261 return 0;
3262
3263 for (i = 0; i < count; i++)
3264 {
3265 rtx elt = XVECEXP (op, 0, i);
3266 rtx newaddr;
3267 rtx addr_reg;
3268 HOST_WIDE_INT newoffset;
3269
3270 if (GET_CODE (elt) != SET
3271 || GET_CODE (SET_SRC (elt)) != REG
3272 || GET_MODE (SET_SRC (elt)) != SImode
3273 || REGNO (SET_SRC (elt)) != src_regno + i
3274 || GET_CODE (SET_DEST (elt)) != MEM
3275 || GET_MODE (SET_DEST (elt)) != SImode)
3276 return 0;
3277 newaddr = XEXP (SET_DEST (elt), 0);
3278 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
3279 {
3280 newoffset = 0;
3281 addr_reg = newaddr;
3282 }
3283 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
3284 {
3285 addr_reg = XEXP (newaddr, 0);
3286 newoffset = INTVAL (XEXP (newaddr, 1));
3287 }
3288 else
3289 return 0;
3290 if (REGNO (addr_reg) != base_regno
3291 || newoffset != offset + 4 * i)
3292 return 0;
3293 }
3294
3295 return 1;
3296 }
3297 \f
3298
3299 /* A validation routine: say whether CODE, a condition code,
3300 and MODE match. The other alternatives either don't make
3301 sense or should never be generated. */
3302 static void
3303 validate_condition_mode (code, mode)
3304 enum rtx_code code;
3305 enum machine_mode mode;
3306 {
3307 if (GET_RTX_CLASS (code) != '<'
3308 || GET_MODE_CLASS (mode) != MODE_CC)
3309 abort ();
3310
3311 /* These don't make sense. */
3312 if ((code == GT || code == LT || code == GE || code == LE)
3313 && mode == CCUNSmode)
3314 abort ();
3315
3316 if ((code == GTU || code == LTU || code == GEU || code == LEU)
3317 && mode != CCUNSmode)
3318 abort ();
3319
3320 if (mode != CCFPmode
3321 && (code == ORDERED || code == UNORDERED
3322 || code == UNEQ || code == LTGT
3323 || code == UNGT || code == UNLT
3324 || code == UNGE || code == UNLE))
3325 abort();
3326
3327 /* These should never be generated except for
3328 flag_unsafe_math_optimizations. */
3329 if (mode == CCFPmode
3330 && ! flag_unsafe_math_optimizations
3331 && (code == LE || code == GE
3332 || code == UNEQ || code == LTGT
3333 || code == UNGT || code == UNLT))
3334 abort ();
3335
3336 /* These are invalid; the information is not there. */
3337 if (mode == CCEQmode
3338 && code != EQ && code != NE)
3339 abort ();
3340 }
3341
3342 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
3343 We only check the opcode against the mode of the CC value here. */
3344
3345 int
3346 branch_comparison_operator (op, mode)
3347 register rtx op;
3348 enum machine_mode mode ATTRIBUTE_UNUSED;
3349 {
3350 enum rtx_code code = GET_CODE (op);
3351 enum machine_mode cc_mode;
3352
3353 if (GET_RTX_CLASS (code) != '<')
3354 return 0;
3355
3356 cc_mode = GET_MODE (XEXP (op, 0));
3357 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3358 return 0;
3359
3360 validate_condition_mode (code, cc_mode);
3361
3362 return 1;
3363 }
3364
3365 /* Return 1 if OP is a comparison operation that is valid for a branch
3366 insn and which is true if the corresponding bit in the CC register
3367 is set. */
3368
3369 int
3370 branch_positive_comparison_operator (op, mode)
3371 register rtx op;
3372 enum machine_mode mode;
3373 {
3374 enum rtx_code code;
3375
3376 if (! branch_comparison_operator (op, mode))
3377 return 0;
3378
3379 code = GET_CODE (op);
3380 return (code == EQ || code == LT || code == GT
3381 || code == LTU || code == GTU
3382 || code == UNORDERED);
3383 }
3384
3385
3386 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
3387 We check the opcode against the mode of the CC value and disallow EQ or
3388 NE comparisons for integers. */
3389
3390 int
3391 scc_comparison_operator (op, mode)
3392 register rtx op;
3393 enum machine_mode mode;
3394 {
3395 enum rtx_code code = GET_CODE (op);
3396 enum machine_mode cc_mode;
3397
3398 if (GET_MODE (op) != mode && mode != VOIDmode)
3399 return 0;
3400
3401 if (GET_RTX_CLASS (code) != '<')
3402 return 0;
3403
3404 cc_mode = GET_MODE (XEXP (op, 0));
3405 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
3406 return 0;
3407
3408 validate_condition_mode (code, cc_mode);
3409
3410 if (code == NE && cc_mode != CCFPmode)
3411 return 0;
3412
3413 return 1;
3414 }
3415
3416 int
3417 trap_comparison_operator (op, mode)
3418 rtx op;
3419 enum machine_mode mode;
3420 {
3421 if (mode != VOIDmode && mode != GET_MODE (op))
3422 return 0;
3423 return GET_RTX_CLASS (GET_CODE (op)) == '<';
3424 }
3425
3426 int
3427 boolean_operator (op, mode)
3428 rtx op;
3429 enum machine_mode mode ATTRIBUTE_UNUSED;
3430 {
3431 enum rtx_code code = GET_CODE (op);
3432 return (code == AND || code == IOR || code == XOR);
3433 }
3434
3435 int
3436 boolean_or_operator (op, mode)
3437 rtx op;
3438 enum machine_mode mode ATTRIBUTE_UNUSED;
3439 {
3440 enum rtx_code code = GET_CODE (op);
3441 return (code == IOR || code == XOR);
3442 }
3443 \f
3444 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
3445 mask required to convert the result of a rotate insn into a shift
3446 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
3447
3448 int
3449 includes_lshift_p (shiftop, andop)
3450 register rtx shiftop;
3451 register rtx andop;
3452 {
3453 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3454
3455 shift_mask <<= INTVAL (shiftop);
3456
3457 return (INTVAL (andop) & ~shift_mask) == 0;
3458 }
3459
3460 /* Similar, but for right shift. */
3461
3462 int
3463 includes_rshift_p (shiftop, andop)
3464 register rtx shiftop;
3465 register rtx andop;
3466 {
3467 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3468
3469 shift_mask >>= INTVAL (shiftop);
3470
3471 return (INTVAL (andop) & ~shift_mask) == 0;
3472 }
3473
3474 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
3475 mask required to convert the result of a rotate insn into a shift
3476 left insn of SHIFTOP bits. */
3477
3478 int
3479 includes_lshift64_p (shiftop, andop)
3480 register rtx shiftop;
3481 register rtx andop;
3482 {
3483 #if HOST_BITS_PER_WIDE_INT == 64
3484 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
3485
3486 shift_mask <<= INTVAL (shiftop);
3487
3488 return (INTVAL (andop) & ~shift_mask) == 0;
3489 #else
3490 unsigned HOST_WIDE_INT shift_mask_low = ~(unsigned HOST_WIDE_INT) 0;
3491 unsigned HOST_WIDE_INT shift_mask_high = ~(unsigned HOST_WIDE_INT) 0;
3492
3493 shift_mask_low <<= INTVAL (shiftop);
3494
3495 if (INTVAL (shiftop) > 32)
3496 shift_mask_high <<= (INTVAL (shiftop) - 32);
3497
3498 if (GET_CODE (andop) == CONST_INT)
3499 return (INTVAL (andop) & ~shift_mask_low) == 0;
3500 else
3501 return ((CONST_DOUBLE_HIGH (andop) & ~shift_mask_high) == 0
3502 && (CONST_DOUBLE_LOW (andop) & ~shift_mask_low) == 0);
3503 #endif
3504 }
3505
3506 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
3507 for lfq and stfq insns.
3508
3509 Note reg1 and reg2 *must* be hard registers. To be sure we will
3510 abort if we are passed pseudo registers. */
3511
3512 int
3513 registers_ok_for_quad_peep (reg1, reg2)
3514 rtx reg1, reg2;
3515 {
3516 /* We might have been passed a SUBREG. */
3517 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
3518 return 0;
3519
3520 return (REGNO (reg1) == REGNO (reg2) - 1);
3521 }
3522
3523 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. addr1 and
3524 addr2 must be in consecutive memory locations (addr2 == addr1 + 8). */
3525
3526 int
3527 addrs_ok_for_quad_peep (addr1, addr2)
3528 register rtx addr1;
3529 register rtx addr2;
3530 {
3531 unsigned int reg1;
3532 int offset1;
3533
3534 /* Extract an offset (if used) from the first addr. */
3535 if (GET_CODE (addr1) == PLUS)
3536 {
3537 /* If not a REG, return zero. */
3538 if (GET_CODE (XEXP (addr1, 0)) != REG)
3539 return 0;
3540 else
3541 {
3542 reg1 = REGNO (XEXP (addr1, 0));
3543 /* The offset must be constant! */
3544 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
3545 return 0;
3546 offset1 = INTVAL (XEXP (addr1, 1));
3547 }
3548 }
3549 else if (GET_CODE (addr1) != REG)
3550 return 0;
3551 else
3552 {
3553 reg1 = REGNO (addr1);
3554 /* This was a simple (mem (reg)) expression. Offset is 0. */
3555 offset1 = 0;
3556 }
3557
3558 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
3559 if (GET_CODE (addr2) != PLUS)
3560 return 0;
3561
3562 if (GET_CODE (XEXP (addr2, 0)) != REG
3563 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
3564 return 0;
3565
3566 if (reg1 != REGNO (XEXP (addr2, 0)))
3567 return 0;
3568
3569 /* The offset for the second addr must be 8 more than the first addr. */
3570 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
3571 return 0;
3572
3573 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
3574 instructions. */
3575 return 1;
3576 }
3577 \f
3578 /* Return the register class of a scratch register needed to copy IN into
3579 or out of a register in CLASS in MODE. If it can be done directly,
3580 NO_REGS is returned. */
3581
3582 enum reg_class
3583 secondary_reload_class (class, mode, in)
3584 enum reg_class class;
3585 enum machine_mode mode ATTRIBUTE_UNUSED;
3586 rtx in;
3587 {
3588 int regno;
3589
3590 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN && flag_pic))
3591 {
3592 /* We cannot copy a symbolic operand directly into anything
3593 other than BASE_REGS for TARGET_ELF. So indicate that a
3594 register from BASE_REGS is needed as an intermediate
3595 register.
3596
3597 On Darwin, pic addresses require a load from memory, which
3598 needs a base register. */
3599 if (class != BASE_REGS
3600 && (GET_CODE (in) == SYMBOL_REF
3601 || GET_CODE (in) == HIGH
3602 || GET_CODE (in) == LABEL_REF
3603 || GET_CODE (in) == CONST))
3604 return BASE_REGS;
3605 }
3606
3607 if (GET_CODE (in) == REG)
3608 {
3609 regno = REGNO (in);
3610 if (regno >= FIRST_PSEUDO_REGISTER)
3611 {
3612 regno = true_regnum (in);
3613 if (regno >= FIRST_PSEUDO_REGISTER)
3614 regno = -1;
3615 }
3616 }
3617 else if (GET_CODE (in) == SUBREG)
3618 {
3619 regno = true_regnum (in);
3620 if (regno >= FIRST_PSEUDO_REGISTER)
3621 regno = -1;
3622 }
3623 else
3624 regno = -1;
3625
3626 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
3627 into anything. */
3628 if (class == GENERAL_REGS || class == BASE_REGS
3629 || (regno >= 0 && INT_REGNO_P (regno)))
3630 return NO_REGS;
3631
3632 /* Constants, memory, and FP registers can go into FP registers. */
3633 if ((regno == -1 || FP_REGNO_P (regno))
3634 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
3635 return NO_REGS;
3636
3637 /* We can copy among the CR registers. */
3638 if ((class == CR_REGS || class == CR0_REGS)
3639 && regno >= 0 && CR_REGNO_P (regno))
3640 return NO_REGS;
3641
3642 /* Otherwise, we need GENERAL_REGS. */
3643 return GENERAL_REGS;
3644 }
3645 \f
3646 /* Given a comparison operation, return the bit number in CCR to test. We
3647 know this is a valid comparison.
3648
3649 SCC_P is 1 if this is for an scc. That means that %D will have been
3650 used instead of %C, so the bits will be in different places.
3651
3652 Return -1 if OP isn't a valid comparison for some reason. */
3653
3654 int
3655 ccr_bit (op, scc_p)
3656 register rtx op;
3657 int scc_p;
3658 {
3659 enum rtx_code code = GET_CODE (op);
3660 enum machine_mode cc_mode;
3661 int cc_regnum;
3662 int base_bit;
3663 rtx reg;
3664
3665 if (GET_RTX_CLASS (code) != '<')
3666 return -1;
3667
3668 reg = XEXP (op, 0);
3669
3670 if (GET_CODE (reg) != REG
3671 || ! CR_REGNO_P (REGNO (reg)))
3672 abort ();
3673
3674 cc_mode = GET_MODE (reg);
3675 cc_regnum = REGNO (reg);
3676 base_bit = 4 * (cc_regnum - CR0_REGNO);
3677
3678 validate_condition_mode (code, cc_mode);
3679
3680 switch (code)
3681 {
3682 case NE:
3683 return scc_p ? base_bit + 3 : base_bit + 2;
3684 case EQ:
3685 return base_bit + 2;
3686 case GT: case GTU: case UNLE:
3687 return base_bit + 1;
3688 case LT: case LTU: case UNGE:
3689 return base_bit;
3690 case ORDERED: case UNORDERED:
3691 return base_bit + 3;
3692
3693 case GE: case GEU:
3694 /* If scc, we will have done a cror to put the bit in the
3695 unordered position. So test that bit. For integer, this is ! LT
3696 unless this is an scc insn. */
3697 return scc_p ? base_bit + 3 : base_bit;
3698
3699 case LE: case LEU:
3700 return scc_p ? base_bit + 3 : base_bit + 1;
3701
3702 default:
3703 abort ();
3704 }
3705 }
3706 \f
3707 /* Return the GOT register. */
3708
3709 struct rtx_def *
3710 rs6000_got_register (value)
3711 rtx value ATTRIBUTE_UNUSED;
3712 {
3713 /* The second flow pass currently (June 1999) can't update regs_ever_live
3714 without disturbing other parts of the compiler, so update it here to
3715 make the prolog/epilogue code happy. */
3716 if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
3717 regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1;
3718
3719 current_function_uses_pic_offset_table = 1;
3720
3721 return pic_offset_table_rtx;
3722 }
3723 \f
3724 /* Functions to init, mark and free struct machine_function.
3725 These will be called, via pointer variables,
3726 from push_function_context and pop_function_context. */
3727
3728 static void
3729 rs6000_init_machine_status (p)
3730 struct function *p;
3731 {
3732 p->machine = (machine_function *) xcalloc (1, sizeof (machine_function));
3733 }
3734
3735 static void
3736 rs6000_mark_machine_status (p)
3737 struct function *p;
3738 {
3739 if (p->machine)
3740 ggc_mark_rtx (p->machine->ra_rtx);
3741 }
3742
3743 static void
3744 rs6000_free_machine_status (p)
3745 struct function *p;
3746 {
3747 if (p->machine == NULL)
3748 return;
3749
3750 free (p->machine);
3751 p->machine = NULL;
3752 }
3753
3754 \f
3755 /* Print an operand. Recognize special options, documented below. */
3756
3757 #if TARGET_ELF
3758 #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
3759 #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
3760 #else
3761 #define SMALL_DATA_RELOC "sda21"
3762 #define SMALL_DATA_REG 0
3763 #endif
3764
3765 void
3766 print_operand (file, x, code)
3767 FILE *file;
3768 rtx x;
3769 int code;
3770 {
3771 int i;
3772 HOST_WIDE_INT val;
3773
3774 /* These macros test for integers and extract the low-order bits. */
3775 #define INT_P(X) \
3776 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
3777 && GET_MODE (X) == VOIDmode)
3778
3779 #define INT_LOWPART(X) \
3780 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
3781
3782 switch (code)
3783 {
3784 case '.':
3785 /* Write out an instruction after the call which may be replaced
3786 with glue code by the loader. This depends on the AIX version. */
3787 asm_fprintf (file, RS6000_CALL_GLUE);
3788 return;
3789
3790 case '$':
3791 /* Write out either a '.' or '$' for the current location, depending
3792 on whether this is Solaris or not. */
3793 putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
3794 return;
3795
3796 /* %a is output_address. */
3797
3798 case 'A':
3799 /* If X is a constant integer whose low-order 5 bits are zero,
3800 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
3801 in the AIX assembler where "sri" with a zero shift count
3802 write a trash instruction. */
3803 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
3804 putc ('l', file);
3805 else
3806 putc ('r', file);
3807 return;
3808
3809 case 'b':
3810 /* If constant, low-order 16 bits of constant, unsigned.
3811 Otherwise, write normally. */
3812 if (INT_P (x))
3813 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
3814 else
3815 print_operand (file, x, 0);
3816 return;
3817
3818 case 'B':
3819 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
3820 for 64-bit mask direction. */
3821 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
3822 return;
3823
3824 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
3825 output_operand. */
3826
3827 case 'D':
3828 /* There used to be a comment for 'C' reading "This is an
3829 optional cror needed for certain floating-point
3830 comparisons. Otherwise write nothing." */
3831
3832 /* Similar, except that this is for an scc, so we must be able to
3833 encode the test in a single bit that is one. We do the above
3834 for any LE, GE, GEU, or LEU and invert the bit for NE. */
3835 if (GET_CODE (x) == LE || GET_CODE (x) == GE
3836 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
3837 {
3838 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3839
3840 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
3841 base_bit + 2,
3842 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
3843 }
3844
3845 else if (GET_CODE (x) == NE)
3846 {
3847 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
3848
3849 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
3850 base_bit + 2, base_bit + 2);
3851 }
3852 return;
3853
3854 case 'E':
3855 /* X is a CR register. Print the number of the EQ bit of the CR */
3856 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3857 output_operand_lossage ("invalid %%E value");
3858 else
3859 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
3860 return;
3861
3862 case 'f':
3863 /* X is a CR register. Print the shift count needed to move it
3864 to the high-order four bits. */
3865 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3866 output_operand_lossage ("invalid %%f value");
3867 else
3868 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
3869 return;
3870
3871 case 'F':
3872 /* Similar, but print the count for the rotate in the opposite
3873 direction. */
3874 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
3875 output_operand_lossage ("invalid %%F value");
3876 else
3877 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
3878 return;
3879
3880 case 'G':
3881 /* X is a constant integer. If it is negative, print "m",
3882 otherwise print "z". This is to make a aze or ame insn. */
3883 if (GET_CODE (x) != CONST_INT)
3884 output_operand_lossage ("invalid %%G value");
3885 else if (INTVAL (x) >= 0)
3886 putc ('z', file);
3887 else
3888 putc ('m', file);
3889 return;
3890
3891 case 'h':
3892 /* If constant, output low-order five bits. Otherwise,
3893 write normally. */
3894 if (INT_P (x))
3895 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
3896 else
3897 print_operand (file, x, 0);
3898 return;
3899
3900 case 'H':
3901 /* If constant, output low-order six bits. Otherwise,
3902 write normally. */
3903 if (INT_P (x))
3904 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
3905 else
3906 print_operand (file, x, 0);
3907 return;
3908
3909 case 'I':
3910 /* Print `i' if this is a constant, else nothing. */
3911 if (INT_P (x))
3912 putc ('i', file);
3913 return;
3914
3915 case 'j':
3916 /* Write the bit number in CCR for jump. */
3917 i = ccr_bit (x, 0);
3918 if (i == -1)
3919 output_operand_lossage ("invalid %%j code");
3920 else
3921 fprintf (file, "%d", i);
3922 return;
3923
3924 case 'J':
3925 /* Similar, but add one for shift count in rlinm for scc and pass
3926 scc flag to `ccr_bit'. */
3927 i = ccr_bit (x, 1);
3928 if (i == -1)
3929 output_operand_lossage ("invalid %%J code");
3930 else
3931 /* If we want bit 31, write a shift count of zero, not 32. */
3932 fprintf (file, "%d", i == 31 ? 0 : i + 1);
3933 return;
3934
3935 case 'k':
3936 /* X must be a constant. Write the 1's complement of the
3937 constant. */
3938 if (! INT_P (x))
3939 output_operand_lossage ("invalid %%k value");
3940 else
3941 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
3942 return;
3943
3944 case 'K':
3945 /* X must be a symbolic constant on ELF. Write an
3946 expression suitable for an 'addi' that adds in the low 16
3947 bits of the MEM. */
3948 if (GET_CODE (x) != CONST)
3949 {
3950 print_operand_address (file, x);
3951 fputs ("@l", file);
3952 }
3953 else
3954 {
3955 if (GET_CODE (XEXP (x, 0)) != PLUS
3956 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
3957 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3958 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
3959 output_operand_lossage ("invalid %%K value");
3960 print_operand_address (file, XEXP (XEXP (x, 0), 0));
3961 fputs ("@l", file);
3962 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
3963 }
3964 return;
3965
3966 /* %l is output_asm_label. */
3967
3968 case 'L':
3969 /* Write second word of DImode or DFmode reference. Works on register
3970 or non-indexed memory only. */
3971 if (GET_CODE (x) == REG)
3972 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
3973 else if (GET_CODE (x) == MEM)
3974 {
3975 /* Handle possible auto-increment. Since it is pre-increment and
3976 we have already done it, we can just use an offset of word. */
3977 if (GET_CODE (XEXP (x, 0)) == PRE_INC
3978 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
3979 output_address (plus_constant_for_output (XEXP (XEXP (x, 0), 0),
3980 UNITS_PER_WORD));
3981 else
3982 output_address (plus_constant_for_output (XEXP (x, 0),
3983 UNITS_PER_WORD));
3984 if (small_data_operand (x, GET_MODE (x)))
3985 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
3986 reg_names[SMALL_DATA_REG]);
3987 }
3988 return;
3989
3990 case 'm':
3991 /* MB value for a mask operand. */
3992 if (! mask_operand (x, VOIDmode))
3993 output_operand_lossage ("invalid %%m value");
3994
3995 val = INT_LOWPART (x);
3996
3997 /* If the high bit is set and the low bit is not, the value is zero.
3998 If the high bit is zero, the value is the first 1 bit we find from
3999 the left. */
4000 if ((val & 0x80000000) && ((val & 1) == 0))
4001 {
4002 putc ('0', file);
4003 return;
4004 }
4005 else if ((val & 0x80000000) == 0)
4006 {
4007 for (i = 1; i < 32; i++)
4008 if ((val <<= 1) & 0x80000000)
4009 break;
4010 fprintf (file, "%d", i);
4011 return;
4012 }
4013
4014 /* Otherwise, look for the first 0 bit from the right. The result is its
4015 number plus 1. We know the low-order bit is one. */
4016 for (i = 0; i < 32; i++)
4017 if (((val >>= 1) & 1) == 0)
4018 break;
4019
4020 /* If we ended in ...01, i would be 0. The correct value is 31, so
4021 we want 31 - i. */
4022 fprintf (file, "%d", 31 - i);
4023 return;
4024
4025 case 'M':
4026 /* ME value for a mask operand. */
4027 if (! mask_operand (x, VOIDmode))
4028 output_operand_lossage ("invalid %%M value");
4029
4030 val = INT_LOWPART (x);
4031
4032 /* If the low bit is set and the high bit is not, the value is 31.
4033 If the low bit is zero, the value is the first 1 bit we find from
4034 the right. */
4035 if ((val & 1) && ((val & 0x80000000) == 0))
4036 {
4037 fputs ("31", file);
4038 return;
4039 }
4040 else if ((val & 1) == 0)
4041 {
4042 for (i = 0; i < 32; i++)
4043 if ((val >>= 1) & 1)
4044 break;
4045
4046 /* If we had ....10, i would be 0. The result should be
4047 30, so we need 30 - i. */
4048 fprintf (file, "%d", 30 - i);
4049 return;
4050 }
4051
4052 /* Otherwise, look for the first 0 bit from the left. The result is its
4053 number minus 1. We know the high-order bit is one. */
4054 for (i = 0; i < 32; i++)
4055 if (((val <<= 1) & 0x80000000) == 0)
4056 break;
4057
4058 fprintf (file, "%d", i);
4059 return;
4060
4061 /* %n outputs the negative of its operand. */
4062
4063 case 'N':
4064 /* Write the number of elements in the vector times 4. */
4065 if (GET_CODE (x) != PARALLEL)
4066 output_operand_lossage ("invalid %%N value");
4067 else
4068 fprintf (file, "%d", XVECLEN (x, 0) * 4);
4069 return;
4070
4071 case 'O':
4072 /* Similar, but subtract 1 first. */
4073 if (GET_CODE (x) != PARALLEL)
4074 output_operand_lossage ("invalid %%O value");
4075 else
4076 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
4077 return;
4078
4079 case 'p':
4080 /* X is a CONST_INT that is a power of two. Output the logarithm. */
4081 if (! INT_P (x)
4082 || (i = exact_log2 (INT_LOWPART (x))) < 0)
4083 output_operand_lossage ("invalid %%p value");
4084 else
4085 fprintf (file, "%d", i);
4086 return;
4087
4088 case 'P':
4089 /* The operand must be an indirect memory reference. The result
4090 is the register number. */
4091 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
4092 || REGNO (XEXP (x, 0)) >= 32)
4093 output_operand_lossage ("invalid %%P value");
4094 else
4095 fprintf (file, "%d", REGNO (XEXP (x, 0)));
4096 return;
4097
4098 case 'q':
4099 /* This outputs the logical code corresponding to a boolean
4100 expression. The expression may have one or both operands
4101 negated (if one, only the first one). For condition register
4102 logical operations, it will also treat the negated
4103 CR codes as NOTs, but not handle NOTs of them. */
4104 {
4105 const char *const *t = 0;
4106 const char *s;
4107 enum rtx_code code = GET_CODE (x);
4108 static const char * const tbl[3][3] = {
4109 { "and", "andc", "nor" },
4110 { "or", "orc", "nand" },
4111 { "xor", "eqv", "xor" } };
4112
4113 if (code == AND)
4114 t = tbl[0];
4115 else if (code == IOR)
4116 t = tbl[1];
4117 else if (code == XOR)
4118 t = tbl[2];
4119 else
4120 output_operand_lossage ("invalid %%q value");
4121
4122 if (GET_CODE (XEXP (x, 0)) != NOT)
4123 s = t[0];
4124 else
4125 {
4126 if (GET_CODE (XEXP (x, 1)) == NOT)
4127 s = t[2];
4128 else
4129 s = t[1];
4130 }
4131
4132 fputs (s, file);
4133 }
4134 return;
4135
4136 case 'R':
4137 /* X is a CR register. Print the mask for `mtcrf'. */
4138 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
4139 output_operand_lossage ("invalid %%R value");
4140 else
4141 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
4142 return;
4143
4144 case 's':
4145 /* Low 5 bits of 32 - value */
4146 if (! INT_P (x))
4147 output_operand_lossage ("invalid %%s value");
4148 else
4149 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
4150 return;
4151
4152 case 'S':
4153 /* PowerPC64 mask position. All 0's and all 1's are excluded.
4154 CONST_INT 32-bit mask is considered sign-extended so any
4155 transition must occur within the CONST_INT, not on the boundary. */
4156 if (! mask64_operand (x, VOIDmode))
4157 output_operand_lossage ("invalid %%S value");
4158
4159 val = INT_LOWPART (x);
4160
4161 if (val & 1) /* Clear Left */
4162 {
4163 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4164 if (!((val >>= 1) & 1))
4165 break;
4166
4167 #if HOST_BITS_PER_WIDE_INT == 32
4168 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4169 {
4170 val = CONST_DOUBLE_HIGH (x);
4171
4172 if (val == 0)
4173 --i;
4174 else
4175 for (i = 32; i < 64; i++)
4176 if (!((val >>= 1) & 1))
4177 break;
4178 }
4179 #endif
4180 /* i = index of last set bit from right
4181 mask begins at 63 - i from left */
4182 if (i > 63)
4183 output_operand_lossage ("%%S computed all 1's mask");
4184
4185 fprintf (file, "%d", 63 - i);
4186 return;
4187 }
4188 else /* Clear Right */
4189 {
4190 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4191 if ((val >>= 1) & 1)
4192 break;
4193
4194 #if HOST_BITS_PER_WIDE_INT == 32
4195 if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4196 {
4197 val = CONST_DOUBLE_HIGH (x);
4198
4199 if (val == (HOST_WIDE_INT) -1)
4200 --i;
4201 else
4202 for (i = 32; i < 64; i++)
4203 if ((val >>= 1) & 1)
4204 break;
4205 }
4206 #endif
4207 /* i = index of last clear bit from right
4208 mask ends at 62 - i from left */
4209 if (i > 62)
4210 output_operand_lossage ("%%S computed all 0's mask");
4211
4212 fprintf (file, "%d", 62 - i);
4213 return;
4214 }
4215
4216 case 'T':
4217 /* Print the symbolic name of a branch target register. */
4218 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
4219 && REGNO (x) != COUNT_REGISTER_REGNUM))
4220 output_operand_lossage ("invalid %%T value");
4221 else if (REGNO (x) == LINK_REGISTER_REGNUM)
4222 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
4223 else
4224 fputs ("ctr", file);
4225 return;
4226
4227 case 'u':
4228 /* High-order 16 bits of constant for use in unsigned operand. */
4229 if (! INT_P (x))
4230 output_operand_lossage ("invalid %%u value");
4231 else
4232 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
4233 (INT_LOWPART (x) >> 16) & 0xffff);
4234 return;
4235
4236 case 'v':
4237 /* High-order 16 bits of constant for use in signed operand. */
4238 if (! INT_P (x))
4239 output_operand_lossage ("invalid %%v value");
4240 else
4241 {
4242 int value = (INT_LOWPART (x) >> 16) & 0xffff;
4243
4244 /* Solaris assembler doesn't like lis 0,0x8000 */
4245 if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
4246 fprintf (file, "%d", value | (~0 << 16));
4247 else
4248 fprintf (file, "0x%x", value);
4249 return;
4250 }
4251
4252 case 'U':
4253 /* Print `u' if this has an auto-increment or auto-decrement. */
4254 if (GET_CODE (x) == MEM
4255 && (GET_CODE (XEXP (x, 0)) == PRE_INC
4256 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
4257 putc ('u', file);
4258 return;
4259
4260 case 'V':
4261 /* Print the trap code for this operand. */
4262 switch (GET_CODE (x))
4263 {
4264 case EQ:
4265 fputs ("eq", file); /* 4 */
4266 break;
4267 case NE:
4268 fputs ("ne", file); /* 24 */
4269 break;
4270 case LT:
4271 fputs ("lt", file); /* 16 */
4272 break;
4273 case LE:
4274 fputs ("le", file); /* 20 */
4275 break;
4276 case GT:
4277 fputs ("gt", file); /* 8 */
4278 break;
4279 case GE:
4280 fputs ("ge", file); /* 12 */
4281 break;
4282 case LTU:
4283 fputs ("llt", file); /* 2 */
4284 break;
4285 case LEU:
4286 fputs ("lle", file); /* 6 */
4287 break;
4288 case GTU:
4289 fputs ("lgt", file); /* 1 */
4290 break;
4291 case GEU:
4292 fputs ("lge", file); /* 5 */
4293 break;
4294 default:
4295 abort ();
4296 }
4297 break;
4298
4299 case 'w':
4300 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
4301 normally. */
4302 if (INT_P (x))
4303 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
4304 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
4305 else
4306 print_operand (file, x, 0);
4307 return;
4308
4309 case 'W':
4310 /* MB value for a PowerPC64 rldic operand. */
4311 if (! rldic_operand (x, VOIDmode))
4312 output_operand_lossage ("invalid %%W value");
4313
4314 val = (GET_CODE (x) == CONST_INT
4315 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
4316
4317 if (val < 0)
4318 i = -1;
4319 else
4320 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
4321 if ((val <<= 1) < 0)
4322 break;
4323
4324 #if HOST_BITS_PER_WIDE_INT == 32
4325 if (GET_CODE (x) == CONST_INT && i >= 0)
4326 i += 32; /* zero-extend high-part was all 0's */
4327 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
4328 {
4329 val = CONST_DOUBLE_LOW (x);
4330
4331 if (val == 0)
4332 abort();
4333 else if (val < 0)
4334 --i;
4335 else
4336 for ( ; i < 64; i++)
4337 if ((val <<= 1) < 0)
4338 break;
4339 }
4340 #endif
4341
4342 fprintf (file, "%d", i + 1);
4343 return;
4344
4345 case 'X':
4346 if (GET_CODE (x) == MEM
4347 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0))
4348 putc ('x', file);
4349 return;
4350
4351 case 'Y':
4352 /* Like 'L', for third word of TImode */
4353 if (GET_CODE (x) == REG)
4354 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
4355 else if (GET_CODE (x) == MEM)
4356 {
4357 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4358 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
4359 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
4360 else
4361 output_address (plus_constant (XEXP (x, 0), 8));
4362 if (small_data_operand (x, GET_MODE (x)))
4363 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4364 reg_names[SMALL_DATA_REG]);
4365 }
4366 return;
4367
4368 case 'z':
4369 /* X is a SYMBOL_REF. Write out the name preceded by a
4370 period and without any trailing data in brackets. Used for function
4371 names. If we are configured for System V (or the embedded ABI) on
4372 the PowerPC, do not emit the period, since those systems do not use
4373 TOCs and the like. */
4374 if (GET_CODE (x) != SYMBOL_REF)
4375 abort ();
4376
4377 if (XSTR (x, 0)[0] != '.')
4378 {
4379 switch (DEFAULT_ABI)
4380 {
4381 default:
4382 abort ();
4383
4384 case ABI_AIX:
4385 putc ('.', file);
4386 break;
4387
4388 case ABI_V4:
4389 case ABI_AIX_NODESC:
4390 case ABI_SOLARIS:
4391 case ABI_DARWIN:
4392 break;
4393 }
4394 }
4395 #if TARGET_AIX
4396 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
4397 #else
4398 assemble_name (file, XSTR (x, 0));
4399 #endif
4400 return;
4401
4402 case 'Z':
4403 /* Like 'L', for last word of TImode. */
4404 if (GET_CODE (x) == REG)
4405 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
4406 else if (GET_CODE (x) == MEM)
4407 {
4408 if (GET_CODE (XEXP (x, 0)) == PRE_INC
4409 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
4410 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
4411 else
4412 output_address (plus_constant (XEXP (x, 0), 12));
4413 if (small_data_operand (x, GET_MODE (x)))
4414 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4415 reg_names[SMALL_DATA_REG]);
4416 }
4417 return;
4418
4419 case 0:
4420 if (GET_CODE (x) == REG)
4421 fprintf (file, "%s", reg_names[REGNO (x)]);
4422 else if (GET_CODE (x) == MEM)
4423 {
4424 /* We need to handle PRE_INC and PRE_DEC here, since we need to
4425 know the width from the mode. */
4426 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
4427 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
4428 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
4429 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
4430 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
4431 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
4432 else
4433 output_address (XEXP (x, 0));
4434 }
4435 else
4436 output_addr_const (file, x);
4437 return;
4438
4439 default:
4440 output_operand_lossage ("invalid %%xn code");
4441 }
4442 }
4443 \f
4444 /* Print the address of an operand. */
4445
4446 void
4447 print_operand_address (file, x)
4448 FILE *file;
4449 register rtx x;
4450 {
4451 if (GET_CODE (x) == REG)
4452 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
4453 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
4454 || GET_CODE (x) == LABEL_REF)
4455 {
4456 output_addr_const (file, x);
4457 if (small_data_operand (x, GET_MODE (x)))
4458 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
4459 reg_names[SMALL_DATA_REG]);
4460 else if (TARGET_TOC)
4461 abort();
4462 }
4463 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
4464 {
4465 if (REGNO (XEXP (x, 0)) == 0)
4466 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
4467 reg_names[ REGNO (XEXP (x, 0)) ]);
4468 else
4469 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
4470 reg_names[ REGNO (XEXP (x, 1)) ]);
4471 }
4472 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4473 {
4474 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
4475 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4476 }
4477 #if TARGET_ELF
4478 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
4479 && CONSTANT_P (XEXP (x, 1)))
4480 {
4481 output_addr_const (file, XEXP (x, 1));
4482 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
4483 }
4484 #endif
4485 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
4486 {
4487 if (TARGET_AIX)
4488 {
4489 rtx contains_minus = XEXP (x, 1);
4490 rtx minus;
4491
4492 /* Find the (minus (sym) (toc)) buried in X, and temporarily
4493 turn it into (sym) for output_addr_const. */
4494 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
4495 contains_minus = XEXP (contains_minus, 0);
4496
4497 minus = XEXP (contains_minus, 0);
4498 XEXP (contains_minus, 0) = XEXP (minus, 0);
4499 output_addr_const (file, XEXP (x, 1));
4500 XEXP (contains_minus, 0) = minus;
4501 }
4502 else
4503 output_addr_const (file, XEXP (x, 1));
4504
4505 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
4506 }
4507 else
4508 abort ();
4509 }
4510 \f
4511 enum rtx_code
4512 rs6000_reverse_condition (mode, code)
4513 enum machine_mode mode;
4514 enum rtx_code code;
4515 {
4516 /* Reversal of FP compares takes care -- an ordered compare
4517 becomes an unordered compare and vice versa. */
4518 if (mode == CCFPmode)
4519 return reverse_condition_maybe_unordered (code);
4520 else
4521 return reverse_condition (code);
4522 }
4523
4524
4525 /* Generate a compare for CODE. Return a brand-new rtx that
4526 represents the result of the compare. */
4527 static rtx
4528 rs6000_generate_compare (code)
4529 enum rtx_code code;
4530 {
4531 enum machine_mode comp_mode;
4532 rtx compare_result;
4533
4534 if (rs6000_compare_fp_p)
4535 comp_mode = CCFPmode;
4536 else if (code == GTU || code == LTU
4537 || code == GEU || code == LEU)
4538 comp_mode = CCUNSmode;
4539 else
4540 comp_mode = CCmode;
4541
4542 /* First, the compare. */
4543 compare_result = gen_reg_rtx (comp_mode);
4544 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
4545 gen_rtx_COMPARE (comp_mode,
4546 rs6000_compare_op0,
4547 rs6000_compare_op1)));
4548
4549 /* Some kinds of FP comparisons need an OR operation;
4550 except for flag_unsafe_math_optimizations we don't bother. */
4551 if (rs6000_compare_fp_p
4552 && ! flag_unsafe_math_optimizations
4553 && (code == LE || code == GE
4554 || code == UNEQ || code == LTGT
4555 || code == UNGT || code == UNLT))
4556 {
4557 enum rtx_code or1, or2;
4558 rtx or1_rtx, or2_rtx, compare2_rtx;
4559 rtx or_result = gen_reg_rtx (CCEQmode);
4560
4561 switch (code)
4562 {
4563 case LE: or1 = LT; or2 = EQ; break;
4564 case GE: or1 = GT; or2 = EQ; break;
4565 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
4566 case LTGT: or1 = LT; or2 = GT; break;
4567 case UNGT: or1 = UNORDERED; or2 = GT; break;
4568 case UNLT: or1 = UNORDERED; or2 = LT; break;
4569 default: abort ();
4570 }
4571 validate_condition_mode (or1, comp_mode);
4572 validate_condition_mode (or2, comp_mode);
4573 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
4574 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
4575 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
4576 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
4577 const_true_rtx);
4578 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
4579
4580 compare_result = or_result;
4581 code = EQ;
4582 }
4583
4584 validate_condition_mode (code, GET_MODE (compare_result));
4585
4586 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
4587 }
4588
4589
4590 /* Emit the RTL for an sCOND pattern. */
4591
4592 void
4593 rs6000_emit_sCOND (code, result)
4594 enum rtx_code code;
4595 rtx result;
4596 {
4597 rtx condition_rtx;
4598 enum machine_mode op_mode;
4599
4600 condition_rtx = rs6000_generate_compare (code);
4601
4602 op_mode = GET_MODE (rs6000_compare_op0);
4603 if (op_mode == VOIDmode)
4604 op_mode = GET_MODE (rs6000_compare_op1);
4605
4606 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
4607 {
4608 PUT_MODE (condition_rtx, DImode);
4609 convert_move (result, condition_rtx, 0);
4610 }
4611 else
4612 {
4613 PUT_MODE (condition_rtx, SImode);
4614 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
4615 }
4616 }
4617
4618
4619 /* Emit a branch of kind CODE to location LOC. */
4620
4621 void
4622 rs6000_emit_cbranch (code, loc)
4623 enum rtx_code code;
4624 rtx loc;
4625 {
4626 rtx condition_rtx, loc_ref;
4627
4628 condition_rtx = rs6000_generate_compare (code);
4629 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
4630 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4631 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
4632 loc_ref, pc_rtx)));
4633 }
4634
4635
4636 /* Return the string to output a conditional branch to LABEL, which is
4637 the operand number of the label, or -1 if the branch is really a
4638 conditional return.
4639
4640 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
4641 condition code register and its mode specifies what kind of
4642 comparison we made.
4643
4644 REVERSED is non-zero if we should reverse the sense of the comparison.
4645
4646 INSN is the insn. */
4647
4648 char *
4649 output_cbranch (op, label, reversed, insn)
4650 rtx op;
4651 const char * label;
4652 int reversed;
4653 rtx insn;
4654 {
4655 static char string[64];
4656 enum rtx_code code = GET_CODE (op);
4657 rtx cc_reg = XEXP (op, 0);
4658 enum machine_mode mode = GET_MODE (cc_reg);
4659 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
4660 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
4661 int really_reversed = reversed ^ need_longbranch;
4662 char *s = string;
4663 const char *ccode;
4664 const char *pred;
4665 rtx note;
4666
4667 validate_condition_mode (code, mode);
4668
4669 /* Work out which way this really branches. We could use
4670 reverse_condition_maybe_unordered here always but this
4671 makes the resulting assembler clearer. */
4672 if (really_reversed)
4673 code = rs6000_reverse_condition (mode, code);
4674
4675 switch (code)
4676 {
4677 /* Not all of these are actually distinct opcodes, but
4678 we distinguish them for clarity of the resulting assembler. */
4679 case NE: ccode = "ne"; break;
4680 case EQ: ccode = "eq"; break;
4681 case GE: case GEU: ccode = "ge"; break;
4682 case GT: case GTU: ccode = "gt"; break;
4683 case LE: case LEU: ccode = "le"; break;
4684 case LT: case LTU: ccode = "lt"; break;
4685 case UNORDERED: ccode = "un"; break;
4686 case ORDERED: ccode = "nu"; break;
4687 case UNGE: ccode = "nl"; break;
4688 case UNLE: ccode = "ng"; break;
4689 default:
4690 abort();
4691 }
4692
4693 /* Maybe we have a guess as to how likely the branch is.
4694 The old mnemonics don't have a way to specify this information. */
4695 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
4696 if (note != NULL_RTX)
4697 {
4698 /* PROB is the difference from 50%. */
4699 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
4700
4701 /* For branches that are very close to 50%, assume not-taken. */
4702 if (abs (prob) > REG_BR_PROB_BASE / 20
4703 && ((prob > 0) ^ need_longbranch))
4704 pred = "+";
4705 else
4706 pred = "-";
4707 }
4708 else
4709 pred = "";
4710
4711 if (label == NULL)
4712 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
4713 else
4714 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
4715
4716 /* We need to escape any '%' characters in the reg_names string.
4717 Assume they'd only be the first character... */
4718 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
4719 *s++ = '%';
4720 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
4721
4722 if (label != NULL)
4723 {
4724 /* If the branch distance was too far, we may have to use an
4725 unconditional branch to go the distance. */
4726 if (need_longbranch)
4727 s += sprintf (s, ",%c$+8\n\tb %s", '%', label);
4728 else
4729 s += sprintf (s, ",%s", label);
4730 }
4731
4732 return string;
4733 }
4734 \f
4735 /* This page contains routines that are used to determine what the function
4736 prologue and epilogue code will do and write them out. */
4737
4738 /* Return the first fixed-point register that is required to be saved. 32 if
4739 none. */
4740
4741 int
4742 first_reg_to_save ()
4743 {
4744 int first_reg;
4745
4746 /* Find lowest numbered live register. */
4747 for (first_reg = 13; first_reg <= 31; first_reg++)
4748 if (regs_ever_live[first_reg]
4749 && (! call_used_regs[first_reg]
4750 || (first_reg == PIC_OFFSET_TABLE_REGNUM
4751 && (((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
4752 && flag_pic == 1)
4753 || (DEFAULT_ABI == ABI_DARWIN
4754 && flag_pic)))))
4755 break;
4756
4757 if (profile_flag)
4758 {
4759 /* AIX must save/restore every register that contains a parameter
4760 before/after the .__mcount call plus an additional register
4761 for the static chain, if needed; use registers from 30 down to 22
4762 to do this. */
4763 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
4764 {
4765 int last_parm_reg, profile_first_reg;
4766
4767 /* Figure out last used parameter register. The proper thing
4768 to do is to walk incoming args of the function. A function
4769 might have live parameter registers even if it has no
4770 incoming args. */
4771 for (last_parm_reg = 10;
4772 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
4773 last_parm_reg--)
4774 ;
4775
4776 /* Calculate first reg for saving parameter registers
4777 and static chain.
4778 Skip reg 31 which may contain the frame pointer. */
4779 profile_first_reg = (33 - last_parm_reg
4780 - (current_function_needs_context ? 1 : 0));
4781 #if TARGET_MACHO
4782 /* Need to skip another reg to account for R31 being PICBASE
4783 (when flag_pic is set) or R30 being used as the frame
4784 pointer (when flag_pic is not set). */
4785 --profile_first_reg;
4786 #endif
4787 /* Do not save frame pointer if no parameters needs to be saved. */
4788 if (profile_first_reg == 31)
4789 profile_first_reg = 32;
4790
4791 if (first_reg > profile_first_reg)
4792 first_reg = profile_first_reg;
4793 }
4794
4795 /* SVR4 may need one register to preserve the static chain. */
4796 else if (current_function_needs_context)
4797 {
4798 /* Skip reg 31 which may contain the frame pointer. */
4799 if (first_reg > 30)
4800 first_reg = 30;
4801 }
4802 }
4803
4804 #if TARGET_MACHO
4805 if (flag_pic && current_function_uses_pic_offset_table &&
4806 (first_reg > PIC_OFFSET_TABLE_REGNUM))
4807 return PIC_OFFSET_TABLE_REGNUM;
4808 #endif
4809
4810 return first_reg;
4811 }
4812
4813 /* Similar, for FP regs. */
4814
4815 int
4816 first_fp_reg_to_save ()
4817 {
4818 int first_reg;
4819
4820 /* Find lowest numbered live register. */
4821 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
4822 if (regs_ever_live[first_reg])
4823 break;
4824
4825 return first_reg;
4826 }
4827 \f
4828 /* Calculate the stack information for the current function. This is
4829 complicated by having two separate calling sequences, the AIX calling
4830 sequence and the V.4 calling sequence.
4831
4832 AIX (and Darwin/Mac OS) stack frames look like:
4833 32-bit 64-bit
4834 SP----> +---------------------------------------+
4835 | back chain to caller | 0 0
4836 +---------------------------------------+
4837 | saved CR | 4 8 (8-11)
4838 +---------------------------------------+
4839 | saved LR | 8 16
4840 +---------------------------------------+
4841 | reserved for compilers | 12 24
4842 +---------------------------------------+
4843 | reserved for binders | 16 32
4844 +---------------------------------------+
4845 | saved TOC pointer | 20 40
4846 +---------------------------------------+
4847 | Parameter save area (P) | 24 48
4848 +---------------------------------------+
4849 | Alloca space (A) | 24+P etc.
4850 +---------------------------------------+
4851 | Local variable space (L) | 24+P+A
4852 +---------------------------------------+
4853 | Float/int conversion temporary (X) | 24+P+A+L
4854 +---------------------------------------+
4855 | Save area for GP registers (G) | 24+P+A+X+L
4856 +---------------------------------------+
4857 | Save area for FP registers (F) | 24+P+A+X+L+G
4858 +---------------------------------------+
4859 old SP->| back chain to caller's caller |
4860 +---------------------------------------+
4861
4862 The required alignment for AIX configurations is two words (i.e., 8
4863 or 16 bytes).
4864
4865
4866 V.4 stack frames look like:
4867
4868 SP----> +---------------------------------------+
4869 | back chain to caller | 0
4870 +---------------------------------------+
4871 | caller's saved LR | 4
4872 +---------------------------------------+
4873 | Parameter save area (P) | 8
4874 +---------------------------------------+
4875 | Alloca space (A) | 8+P
4876 +---------------------------------------+
4877 | Varargs save area (V) | 8+P+A
4878 +---------------------------------------+
4879 | Local variable space (L) | 8+P+A+V
4880 +---------------------------------------+
4881 | Float/int conversion temporary (X) | 8+P+A+V+L
4882 +---------------------------------------+
4883 | saved CR (C) | 8+P+A+V+L+X
4884 +---------------------------------------+
4885 | Save area for GP registers (G) | 8+P+A+V+L+X+C
4886 +---------------------------------------+
4887 | Save area for FP registers (F) | 8+P+A+V+L+X+C+G
4888 +---------------------------------------+
4889 old SP->| back chain to caller's caller |
4890 +---------------------------------------+
4891
4892 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
4893 given. (But note below and in sysv4.h that we require only 8 and
4894 may round up the size of our stack frame anyways. The historical
4895 reason is early versions of powerpc-linux which didn't properly
4896 align the stack at program startup. A happy side-effect is that
4897 -mno-eabi libraries can be used with -meabi programs.)
4898
4899
4900 The EABI configuration defaults to the V.4 layout, unless
4901 -mcall-aix is used, in which case the AIX layout is used. However,
4902 the stack alignment requirements may differ. If -mno-eabi is not
4903 given, the required stack alignment is 8 bytes; if -mno-eabi is
4904 given, the required alignment is 16 bytes. (But see V.4 comment
4905 above.) */
4906
4907 #ifndef ABI_STACK_BOUNDARY
4908 #define ABI_STACK_BOUNDARY STACK_BOUNDARY
4909 #endif
4910
4911 rs6000_stack_t *
4912 rs6000_stack_info ()
4913 {
4914 static rs6000_stack_t info, zero_info;
4915 rs6000_stack_t *info_ptr = &info;
4916 int reg_size = TARGET_POWERPC64 ? 8 : 4;
4917 enum rs6000_abi abi;
4918 int ehrd_size;
4919 int total_raw_size;
4920
4921 /* Zero all fields portably */
4922 info = zero_info;
4923
4924 /* Select which calling sequence */
4925 info_ptr->abi = abi = DEFAULT_ABI;
4926
4927 /* Calculate which registers need to be saved & save area size */
4928 info_ptr->first_gp_reg_save = first_reg_to_save ();
4929 /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM,
4930 even if it currently looks like we won't. */
4931 if (((flag_pic == 1
4932 && (abi == ABI_V4 || abi == ABI_SOLARIS))
4933 || (flag_pic &&
4934 abi == ABI_DARWIN))
4935 && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM)
4936 info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM);
4937 else
4938 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4939
4940 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
4941 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
4942
4943 /* Does this function call anything? */
4944 info_ptr->calls_p = (! current_function_is_leaf
4945 || cfun->machine->ra_needs_full_frame);
4946
4947 /* Determine if we need to save the link register */
4948 if (rs6000_ra_ever_killed ()
4949 || (DEFAULT_ABI == ABI_AIX && profile_flag)
4950 #ifdef TARGET_RELOCATABLE
4951 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
4952 #endif
4953 || (info_ptr->first_fp_reg_save != 64
4954 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
4955 || (abi == ABI_V4 && current_function_calls_alloca)
4956 || (abi == ABI_SOLARIS && current_function_calls_alloca)
4957 || (DEFAULT_ABI == ABI_DARWIN && flag_pic && current_function_uses_pic_offset_table)
4958 || info_ptr->calls_p)
4959 {
4960 info_ptr->lr_save_p = 1;
4961 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4962 }
4963
4964 /* Determine if we need to save the condition code registers. */
4965 if (regs_ever_live[CR2_REGNO]
4966 || regs_ever_live[CR3_REGNO]
4967 || regs_ever_live[CR4_REGNO])
4968 {
4969 info_ptr->cr_save_p = 1;
4970 if (abi == ABI_V4 || abi == ABI_SOLARIS)
4971 info_ptr->cr_size = reg_size;
4972 }
4973
4974 /* If the current function calls __builtin_eh_return, then we need
4975 to allocate stack space for registers that will hold data for
4976 the exception handler. */
4977 if (current_function_calls_eh_return)
4978 {
4979 unsigned int i;
4980 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
4981 continue;
4982 ehrd_size = i * UNITS_PER_WORD;
4983 }
4984 else
4985 ehrd_size = 0;
4986
4987 /* Determine various sizes */
4988 info_ptr->reg_size = reg_size;
4989 info_ptr->fixed_size = RS6000_SAVE_AREA;
4990 info_ptr->varargs_size = RS6000_VARARGS_AREA;
4991 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
4992 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, 8);
4993 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
4994 + info_ptr->gp_size
4995 + ehrd_size
4996 + info_ptr->cr_size
4997 + info_ptr->lr_size
4998 + info_ptr->toc_size, 8);
4999 if (DEFAULT_ABI == ABI_DARWIN)
5000 info_ptr->save_size = RS6000_ALIGN (info_ptr->save_size, 16);
5001
5002 /* Calculate the offsets */
5003 switch (abi)
5004 {
5005 case ABI_NONE:
5006 default:
5007 abort ();
5008
5009 case ABI_AIX:
5010 case ABI_AIX_NODESC:
5011 case ABI_DARWIN:
5012 info_ptr->fp_save_offset = - info_ptr->fp_size;
5013 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
5014 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
5015 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
5016 info_ptr->lr_save_offset = 2*reg_size;
5017 break;
5018
5019 case ABI_V4:
5020 case ABI_SOLARIS:
5021 info_ptr->fp_save_offset = - info_ptr->fp_size;
5022 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
5023 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
5024 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
5025 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
5026 info_ptr->lr_save_offset = reg_size;
5027 break;
5028 }
5029
5030 total_raw_size = (info_ptr->vars_size
5031 + info_ptr->parm_size
5032 + info_ptr->save_size
5033 + info_ptr->varargs_size
5034 + info_ptr->fixed_size);
5035
5036 info_ptr->total_size = RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
5037
5038 /* Determine if we need to allocate any stack frame:
5039
5040 For AIX we need to push the stack if a frame pointer is needed (because
5041 the stack might be dynamically adjusted), if we are debugging, if we
5042 make calls, or if the sum of fp_save, gp_save, and local variables
5043 are more than the space needed to save all non-volatile registers:
5044 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 + 18*8 = 288 (GPR13 reserved).
5045
5046 For V.4 we don't have the stack cushion that AIX uses, but assume that
5047 the debugger can handle stackless frames. */
5048
5049 if (info_ptr->calls_p)
5050 info_ptr->push_p = 1;
5051
5052 else if (abi == ABI_V4 || abi == ABI_SOLARIS)
5053 info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
5054 || info_ptr->calls_p);
5055
5056 else
5057 info_ptr->push_p = (frame_pointer_needed
5058 || (abi != ABI_DARWIN && write_symbols != NO_DEBUG)
5059 || ((total_raw_size - info_ptr->fixed_size)
5060 > (TARGET_32BIT ? 220 : 288)));
5061
5062 /* Zero offsets if we're not saving those registers */
5063 if (info_ptr->fp_size == 0)
5064 info_ptr->fp_save_offset = 0;
5065
5066 if (info_ptr->gp_size == 0)
5067 info_ptr->gp_save_offset = 0;
5068
5069 if (! info_ptr->lr_save_p)
5070 info_ptr->lr_save_offset = 0;
5071
5072 if (! info_ptr->cr_save_p)
5073 info_ptr->cr_save_offset = 0;
5074
5075 if (! info_ptr->toc_save_p)
5076 info_ptr->toc_save_offset = 0;
5077
5078 return info_ptr;
5079 }
5080
5081 void
5082 debug_stack_info (info)
5083 rs6000_stack_t *info;
5084 {
5085 const char *abi_string;
5086
5087 if (! info)
5088 info = rs6000_stack_info ();
5089
5090 fprintf (stderr, "\nStack information for function %s:\n",
5091 ((current_function_decl && DECL_NAME (current_function_decl))
5092 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
5093 : "<unknown>"));
5094
5095 switch (info->abi)
5096 {
5097 default: abi_string = "Unknown"; break;
5098 case ABI_NONE: abi_string = "NONE"; break;
5099 case ABI_AIX: abi_string = "AIX"; break;
5100 case ABI_AIX_NODESC: abi_string = "AIX"; break;
5101 case ABI_DARWIN: abi_string = "Darwin"; break;
5102 case ABI_V4: abi_string = "V.4"; break;
5103 case ABI_SOLARIS: abi_string = "Solaris"; break;
5104 }
5105
5106 fprintf (stderr, "\tABI = %5s\n", abi_string);
5107
5108 if (info->first_gp_reg_save != 32)
5109 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
5110
5111 if (info->first_fp_reg_save != 64)
5112 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
5113
5114 if (info->lr_save_p)
5115 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
5116
5117 if (info->cr_save_p)
5118 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
5119
5120 if (info->toc_save_p)
5121 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
5122
5123 if (info->push_p)
5124 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
5125
5126 if (info->calls_p)
5127 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
5128
5129 if (info->gp_save_offset)
5130 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
5131
5132 if (info->fp_save_offset)
5133 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
5134
5135 if (info->lr_save_offset)
5136 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
5137
5138 if (info->cr_save_offset)
5139 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
5140
5141 if (info->toc_save_offset)
5142 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
5143
5144 if (info->varargs_save_offset)
5145 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
5146
5147 if (info->total_size)
5148 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
5149
5150 if (info->varargs_size)
5151 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
5152
5153 if (info->vars_size)
5154 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
5155
5156 if (info->parm_size)
5157 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
5158
5159 if (info->fixed_size)
5160 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
5161
5162 if (info->gp_size)
5163 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
5164
5165 if (info->fp_size)
5166 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
5167
5168 if (info->lr_size)
5169 fprintf (stderr, "\tlr_size = %5d\n", info->cr_size);
5170
5171 if (info->cr_size)
5172 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
5173
5174 if (info->toc_size)
5175 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
5176
5177 if (info->save_size)
5178 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
5179
5180 if (info->reg_size != 4)
5181 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
5182
5183 fprintf (stderr, "\n");
5184 }
5185
5186 rtx
5187 rs6000_return_addr (count, frame)
5188 int count;
5189 rtx frame;
5190 {
5191 rtx init, reg;
5192
5193 /* Currently we don't optimize very well between prolog and body code and
5194 for PIC code the code can be actually quite bad, so don't try to be
5195 too clever here. */
5196 if (count != 0
5197 || flag_pic != 0
5198 || DEFAULT_ABI == ABI_AIX
5199 || DEFAULT_ABI == ABI_AIX_NODESC)
5200 {
5201 cfun->machine->ra_needs_full_frame = 1;
5202 return
5203 gen_rtx_MEM (Pmode,
5204 memory_address (Pmode,
5205 plus_constant (copy_to_reg (gen_rtx_MEM (Pmode,
5206 memory_address (Pmode, frame))),
5207 RETURN_ADDRESS_OFFSET)));
5208 }
5209
5210 reg = cfun->machine->ra_rtx;
5211 if (reg == NULL)
5212 {
5213 /* No rtx yet. Invent one, and initialize it from LR in
5214 the prologue. */
5215 reg = gen_reg_rtx (Pmode);
5216 cfun->machine->ra_rtx = reg;
5217 init = gen_rtx_SET (VOIDmode, reg,
5218 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5219
5220 /* Emit the insn to the prologue with the other argument copies. */
5221 push_topmost_sequence ();
5222 emit_insn_after (init, get_insns ());
5223 pop_topmost_sequence ();
5224 }
5225
5226 return reg;
5227 }
5228
5229 static int
5230 rs6000_ra_ever_killed ()
5231 {
5232 rtx top;
5233
5234 #ifdef ASM_OUTPUT_MI_THUNK
5235 if (current_function_is_thunk)
5236 return 0;
5237 #endif
5238 if (!cfun->machine->ra_rtx || cfun->machine->ra_needs_full_frame)
5239 return regs_ever_live[LINK_REGISTER_REGNUM];
5240
5241 push_topmost_sequence ();
5242 top = get_insns ();
5243 pop_topmost_sequence ();
5244
5245 return reg_set_between_p (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5246 top, NULL_RTX);
5247 }
5248 \f
5249 /* Add a REG_MAYBE_DEAD note to the insn. */
5250 static void
5251 rs6000_maybe_dead (insn)
5252 rtx insn;
5253 {
5254 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
5255 const0_rtx,
5256 REG_NOTES (insn));
5257 }
5258
5259 /* Emit instructions needed to load the TOC register.
5260 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
5261 a constant pool; or for SVR4 -fpic. */
5262
5263 void
5264 rs6000_emit_load_toc_table (fromprolog)
5265 int fromprolog;
5266 {
5267 rtx dest;
5268 dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
5269
5270 if (TARGET_ELF)
5271 {
5272 if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5273 && flag_pic == 1)
5274 {
5275 rtx temp = (fromprolog
5276 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
5277 : gen_reg_rtx (Pmode));
5278 if (TARGET_32BIT)
5279 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
5280 else
5281 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_di (temp)));
5282 rs6000_maybe_dead (emit_move_insn (dest, temp));
5283 }
5284 else if (flag_pic == 2)
5285 {
5286 char buf[30];
5287 rtx tempLR = (fromprolog
5288 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
5289 : gen_reg_rtx (Pmode));
5290 rtx temp0 = (fromprolog
5291 ? gen_rtx_REG (Pmode, 0)
5292 : gen_reg_rtx (Pmode));
5293 rtx symF;
5294
5295 /* possibly create the toc section */
5296 if (! toc_initialized)
5297 {
5298 toc_section ();
5299 function_section (current_function_decl);
5300 }
5301
5302 if (fromprolog)
5303 {
5304 rtx symL;
5305
5306 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
5307 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5308
5309 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
5310 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5311
5312 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
5313 symF)));
5314 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
5315 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
5316 symL,
5317 symF)));
5318 }
5319 else
5320 {
5321 rtx tocsym;
5322 static int reload_toc_labelno = 0;
5323
5324 tocsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (toc_label_name));
5325
5326 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
5327 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5328
5329 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
5330 symF,
5331 tocsym)));
5332 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
5333 rs6000_maybe_dead (emit_move_insn (temp0,
5334 gen_rtx_MEM (Pmode, dest)));
5335 }
5336 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
5337 }
5338 else if (flag_pic == 0 && TARGET_MINIMAL_TOC)
5339 {
5340 /* This is for AIX code running in non-PIC ELF. */
5341 char buf[30];
5342 rtx realsym;
5343 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
5344 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
5345
5346 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
5347 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
5348 }
5349 else
5350 abort();
5351 }
5352 else
5353 {
5354 if (TARGET_32BIT)
5355 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
5356 else
5357 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
5358 }
5359 }
5360
5361 int
5362 get_TOC_alias_set ()
5363 {
5364 static int set = -1;
5365 if (set == -1)
5366 set = new_alias_set ();
5367 return set;
5368 }
5369
5370 /* This retuns nonzero if the current function uses the TOC. This is
5371 determined by the presence of (unspec ... 7), which is generated by
5372 the various load_toc_* patterns. */
5373 int
5374 uses_TOC ()
5375 {
5376 rtx insn;
5377
5378 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5379 if (INSN_P (insn))
5380 {
5381 rtx pat = PATTERN (insn);
5382 int i;
5383
5384 if (GET_CODE (pat) == PARALLEL)
5385 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
5386 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
5387 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
5388 return 1;
5389 }
5390 return 0;
5391 }
5392
5393 rtx
5394 create_TOC_reference(symbol)
5395 rtx symbol;
5396 {
5397 return gen_rtx_PLUS (Pmode,
5398 gen_rtx_REG (Pmode, TOC_REGISTER),
5399 gen_rtx_CONST (Pmode,
5400 gen_rtx_MINUS (Pmode, symbol,
5401 gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (toc_label_name)))));
5402 }
5403
5404 #if TARGET_AIX
5405 /* __throw will restore its own return address to be the same as the
5406 return address of the function that the throw is being made to.
5407 This is unfortunate, because we want to check the original
5408 return address to see if we need to restore the TOC.
5409 So we have to squirrel it away here.
5410 This is used only in compiling __throw and __rethrow.
5411
5412 Most of this code should be removed by CSE. */
5413 static rtx insn_after_throw;
5414
5415 /* This does the saving... */
5416 void
5417 rs6000_aix_emit_builtin_unwind_init ()
5418 {
5419 rtx mem;
5420 rtx stack_top = gen_reg_rtx (Pmode);
5421 rtx opcode_addr = gen_reg_rtx (Pmode);
5422
5423 insn_after_throw = gen_reg_rtx (SImode);
5424
5425 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5426 emit_move_insn (stack_top, mem);
5427
5428 mem = gen_rtx_MEM (Pmode,
5429 gen_rtx_PLUS (Pmode, stack_top,
5430 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5431 emit_move_insn (opcode_addr, mem);
5432 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
5433 }
5434
5435 /* Emit insns to _restore_ the TOC register, at runtime (specifically in _eh.o).
5436 Only used on AIX.
5437
5438 The idea is that on AIX, function calls look like this:
5439 bl somefunction-trampoline
5440 lwz r2,20(sp)
5441
5442 and later,
5443 somefunction-trampoline:
5444 stw r2,20(sp)
5445 ... load function address in the count register ...
5446 bctr
5447 or like this, if the linker determines that this is not a cross-module call
5448 and so the TOC need not be restored:
5449 bl somefunction
5450 nop
5451 or like this, if the compiler could determine that this is not a
5452 cross-module call:
5453 bl somefunction
5454 now, the tricky bit here is that register 2 is saved and restored
5455 by the _linker_, so we can't readily generate debugging information
5456 for it. So we need to go back up the call chain looking at the
5457 insns at return addresses to see which calls saved the TOC register
5458 and so see where it gets restored from.
5459
5460 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
5461 just before the actual epilogue.
5462
5463 On the bright side, this incurs no space or time overhead unless an
5464 exception is thrown, except for the extra code in libgcc.a.
5465
5466 The parameter STACKSIZE is a register containing (at runtime)
5467 the amount to be popped off the stack in addition to the stack frame
5468 of this routine (which will be __throw or __rethrow, and so is
5469 guaranteed to have a stack frame). */
5470 void
5471 rs6000_emit_eh_toc_restore (stacksize)
5472 rtx stacksize;
5473 {
5474 rtx top_of_stack;
5475 rtx bottom_of_stack = gen_reg_rtx (Pmode);
5476 rtx tocompare = gen_reg_rtx (SImode);
5477 rtx opcode = gen_reg_rtx (SImode);
5478 rtx opcode_addr = gen_reg_rtx (Pmode);
5479 rtx mem;
5480 rtx loop_start = gen_label_rtx ();
5481 rtx no_toc_restore_needed = gen_label_rtx ();
5482 rtx loop_exit = gen_label_rtx ();
5483
5484 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
5485 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5486 emit_move_insn (bottom_of_stack, mem);
5487
5488 top_of_stack = expand_binop (Pmode, add_optab,
5489 bottom_of_stack, stacksize,
5490 NULL_RTX, 1, OPTAB_WIDEN);
5491
5492 emit_move_insn (tocompare,
5493 GEN_INT (trunc_int_for_mode (TARGET_32BIT
5494 ? 0x80410014
5495 : 0xE8410028, SImode)));
5496
5497 if (insn_after_throw == NULL_RTX)
5498 abort();
5499 emit_move_insn (opcode, insn_after_throw);
5500
5501 emit_note (NULL, NOTE_INSN_LOOP_BEG);
5502 emit_label (loop_start);
5503
5504 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
5505 SImode, NULL_RTX, 0, NULL_RTX,
5506 no_toc_restore_needed);
5507
5508 mem = gen_rtx_MEM (Pmode,
5509 gen_rtx_PLUS (Pmode, bottom_of_stack,
5510 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
5511 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
5512
5513 emit_label (no_toc_restore_needed);
5514 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
5515 Pmode, NULL_RTX, 0, NULL_RTX,
5516 loop_exit);
5517
5518 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
5519 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5520 emit_move_insn (bottom_of_stack, mem);
5521
5522 mem = gen_rtx_MEM (Pmode,
5523 gen_rtx_PLUS (Pmode, bottom_of_stack,
5524 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
5525 emit_move_insn (opcode_addr, mem);
5526 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
5527
5528 emit_note (NULL, NOTE_INSN_LOOP_CONT);
5529 emit_jump (loop_start);
5530 emit_note (NULL, NOTE_INSN_LOOP_END);
5531 emit_label (loop_exit);
5532 }
5533 #endif /* TARGET_AIX */
5534 \f
5535 /* This ties together stack memory
5536 (MEM with an alias set of rs6000_sr_alias_set)
5537 and the change to the stack pointer. */
5538 static void
5539 rs6000_emit_stack_tie ()
5540 {
5541 rtx mem;
5542 mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
5543 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5544 emit_insn (gen_stack_tie (mem));
5545 }
5546
5547 /* Emit the correct code for allocating stack space, as insns.
5548 If COPY_R12, make sure a copy of the old frame is left in r12.
5549 The generated code may use hard register 0 as a temporary. */
5550
5551 static void
5552 rs6000_emit_allocate_stack (size, copy_r12)
5553 HOST_WIDE_INT size;
5554 int copy_r12;
5555 {
5556 rtx insn;
5557 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5558 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
5559 rtx todec = GEN_INT (-size);
5560
5561 if (current_function_limit_stack)
5562 {
5563 if (REG_P (stack_limit_rtx)
5564 && REGNO (stack_limit_rtx) > 1
5565 && REGNO (stack_limit_rtx) <= 31)
5566 {
5567 emit_insn (Pmode == SImode
5568 ? gen_addsi3 (tmp_reg,
5569 stack_limit_rtx,
5570 GEN_INT (size))
5571 : gen_adddi3 (tmp_reg,
5572 stack_limit_rtx,
5573 GEN_INT (size)));
5574
5575 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5576 const0_rtx));
5577 }
5578 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
5579 && TARGET_32BIT
5580 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5581 {
5582 rtx toload = gen_rtx_CONST (VOIDmode,
5583 gen_rtx_PLUS (Pmode,
5584 stack_limit_rtx,
5585 GEN_INT (size)));
5586
5587 emit_insn (gen_elf_high (tmp_reg, toload));
5588 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
5589 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
5590 const0_rtx));
5591 }
5592 else
5593 warning ("stack limit expression is not supported");
5594 }
5595
5596 if (copy_r12 || ! TARGET_UPDATE)
5597 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
5598
5599 if (TARGET_UPDATE)
5600 {
5601 if (size > 32767)
5602 {
5603 /* Need a note here so that try_split doesn't get confused. */
5604 if (get_last_insn() == NULL_RTX)
5605 emit_note (0, NOTE_INSN_DELETED);
5606 insn = emit_move_insn (tmp_reg, todec);
5607 try_split (PATTERN (insn), insn, 0);
5608 todec = tmp_reg;
5609 }
5610
5611 if (Pmode == SImode)
5612 insn = emit_insn (gen_movsi_update (stack_reg, stack_reg,
5613 todec, stack_reg));
5614 else
5615 insn = emit_insn (gen_movdi_update (stack_reg, stack_reg,
5616 todec, stack_reg));
5617 }
5618 else
5619 {
5620 if (Pmode == SImode)
5621 insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec));
5622 else
5623 insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec));
5624 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
5625 gen_rtx_REG (Pmode, 12));
5626 }
5627
5628 RTX_FRAME_RELATED_P (insn) = 1;
5629 REG_NOTES (insn) =
5630 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5631 gen_rtx_SET (VOIDmode, stack_reg,
5632 gen_rtx_PLUS (Pmode, stack_reg,
5633 GEN_INT (-size))),
5634 REG_NOTES (insn));
5635 }
5636
5637 /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced with
5638 (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 is not
5639 NULL.
5640 It would be nice if dwarf2out_frame_debug_expr could deduce these
5641 equivalences by itself so it wasn't necessary to hold its hand so much. */
5642
5643 static void
5644 rs6000_frame_related (insn, reg, val, reg2, rreg)
5645 rtx insn;
5646 rtx reg;
5647 HOST_WIDE_INT val;
5648 rtx reg2;
5649 rtx rreg;
5650 {
5651 rtx real, temp;
5652
5653 real = copy_rtx (PATTERN (insn));
5654
5655 real = replace_rtx (real, reg,
5656 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
5657 STACK_POINTER_REGNUM),
5658 GEN_INT (val)));
5659
5660 /* We expect that 'real' is either a SET or a PARALLEL containing
5661 SETs (and possibly other stuff). In a PARALLEL, all the SETs
5662 are important so they all have to be marked RTX_FRAME_RELATED_P. */
5663
5664 if (GET_CODE (real) == SET)
5665 {
5666 rtx set = real;
5667
5668 temp = simplify_rtx (SET_SRC (set));
5669 if (temp)
5670 SET_SRC (set) = temp;
5671 temp = simplify_rtx (SET_DEST (set));
5672 if (temp)
5673 SET_DEST (set) = temp;
5674 if (GET_CODE (SET_DEST (set)) == MEM)
5675 {
5676 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5677 if (temp)
5678 XEXP (SET_DEST (set), 0) = temp;
5679 }
5680 }
5681 else if (GET_CODE (real) == PARALLEL)
5682 {
5683 int i;
5684 for (i = 0; i < XVECLEN (real, 0); i++)
5685 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
5686 {
5687 rtx set = XVECEXP (real, 0, i);
5688
5689 temp = simplify_rtx (SET_SRC (set));
5690 if (temp)
5691 SET_SRC (set) = temp;
5692 temp = simplify_rtx (SET_DEST (set));
5693 if (temp)
5694 SET_DEST (set) = temp;
5695 if (GET_CODE (SET_DEST (set)) == MEM)
5696 {
5697 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
5698 if (temp)
5699 XEXP (SET_DEST (set), 0) = temp;
5700 }
5701 RTX_FRAME_RELATED_P (set) = 1;
5702 }
5703 }
5704 else
5705 abort();
5706
5707 if (reg2 != NULL_RTX)
5708 real = replace_rtx (real, reg2, rreg);
5709
5710 RTX_FRAME_RELATED_P (insn) = 1;
5711 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
5712 real,
5713 REG_NOTES (insn));
5714 }
5715
5716 /* Emit function prologue as insns. */
5717
5718 void
5719 rs6000_emit_prologue ()
5720 {
5721 rs6000_stack_t *info = rs6000_stack_info ();
5722 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
5723 int reg_size = TARGET_POWERPC64 ? 8 : 4;
5724 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
5725 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
5726 rtx frame_reg_rtx = sp_reg_rtx;
5727 rtx cr_save_rtx = NULL;
5728 rtx insn;
5729 int saving_FPRs_inline;
5730 int using_store_multiple;
5731 HOST_WIDE_INT sp_offset = 0;
5732
5733 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
5734 && info->first_gp_reg_save < 31);
5735 saving_FPRs_inline = (info->first_fp_reg_save == 64
5736 || FP_SAVE_INLINE (info->first_fp_reg_save));
5737
5738 /* For V.4, update stack before we do any saving and set back pointer. */
5739 if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
5740 {
5741 if (info->total_size < 32767)
5742 sp_offset = info->total_size;
5743 else
5744 frame_reg_rtx = frame_ptr_rtx;
5745 rs6000_emit_allocate_stack (info->total_size,
5746 (frame_reg_rtx != sp_reg_rtx
5747 && (info->cr_save_p
5748 || info->lr_save_p
5749 || info->first_fp_reg_save < 64
5750 || info->first_gp_reg_save < 32
5751 )));
5752 if (frame_reg_rtx != sp_reg_rtx)
5753 rs6000_emit_stack_tie ();
5754 }
5755
5756 /* If we use the link register, get it into r0. */
5757 if (info->lr_save_p)
5758 emit_move_insn (gen_rtx_REG (Pmode, 0),
5759 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5760
5761 /* If we need to save CR, put it into r12. */
5762 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
5763 {
5764 cr_save_rtx = gen_rtx_REG (SImode, 12);
5765 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5766 }
5767
5768 /* Do any required saving of fpr's. If only one or two to save, do it
5769 ourself. Otherwise, call function. */
5770 if (saving_FPRs_inline)
5771 {
5772 int i;
5773 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5774 if ((regs_ever_live[info->first_fp_reg_save+i]
5775 && ! call_used_regs[info->first_fp_reg_save+i]))
5776 {
5777 rtx addr, reg, mem;
5778 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5779 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5780 GEN_INT (info->fp_save_offset
5781 + sp_offset
5782 + 8*i));
5783 mem = gen_rtx_MEM (DFmode, addr);
5784 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5785
5786 insn = emit_move_insn (mem, reg);
5787 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5788 NULL_RTX, NULL_RTX);
5789 }
5790 }
5791 else if (info->first_fp_reg_save != 64)
5792 {
5793 int i;
5794 char rname[30];
5795 const char *alloc_rname;
5796 rtvec p;
5797 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
5798
5799 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
5800 gen_rtx_REG (Pmode,
5801 LINK_REGISTER_REGNUM));
5802 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
5803 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
5804 alloc_rname = ggc_strdup (rname);
5805 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
5806 gen_rtx_SYMBOL_REF (Pmode,
5807 alloc_rname));
5808 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
5809 {
5810 rtx addr, reg, mem;
5811 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
5812 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5813 GEN_INT (info->fp_save_offset
5814 + sp_offset + 8*i));
5815 mem = gen_rtx_MEM (DFmode, addr);
5816 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5817
5818 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
5819 }
5820 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5821 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5822 NULL_RTX, NULL_RTX);
5823 }
5824
5825 /* Save GPRs. This is done as a PARALLEL if we are using
5826 the store-multiple instructions. */
5827 if (using_store_multiple)
5828 {
5829 rtvec p, dwarfp;
5830 int i;
5831 p = rtvec_alloc (32 - info->first_gp_reg_save);
5832 dwarfp = rtvec_alloc (32 - info->first_gp_reg_save);
5833 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5834 {
5835 rtx addr, reg, mem;
5836 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5837 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5838 GEN_INT (info->gp_save_offset
5839 + sp_offset
5840 + reg_size * i));
5841 mem = gen_rtx_MEM (reg_mode, addr);
5842 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5843
5844 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
5845 }
5846 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
5847 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5848 NULL_RTX, NULL_RTX);
5849 }
5850 else
5851 {
5852 int i;
5853 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
5854 if ((regs_ever_live[info->first_gp_reg_save+i]
5855 && ! call_used_regs[info->first_gp_reg_save+i])
5856 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
5857 && (((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5858 && flag_pic == 1)
5859 || (DEFAULT_ABI == ABI_DARWIN
5860 && flag_pic))))
5861 {
5862 rtx addr, reg, mem;
5863 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
5864 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5865 GEN_INT (info->gp_save_offset
5866 + sp_offset
5867 + reg_size * i));
5868 mem = gen_rtx_MEM (reg_mode, addr);
5869 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5870
5871 insn = emit_move_insn (mem, reg);
5872 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5873 NULL_RTX, NULL_RTX);
5874 }
5875 }
5876
5877 /* ??? There's no need to emit actual instructions here, but it's the
5878 easiest way to get the frame unwind information emitted. */
5879 if (current_function_calls_eh_return)
5880 {
5881 unsigned int i, regno;
5882
5883 for (i = 0; ; ++i)
5884 {
5885 rtx addr, reg, mem;
5886
5887 regno = EH_RETURN_DATA_REGNO (i);
5888 if (regno == INVALID_REGNUM)
5889 break;
5890
5891 reg = gen_rtx_REG (reg_mode, regno);
5892 addr = plus_constant (frame_reg_rtx,
5893 info->ehrd_offset + sp_offset
5894 + reg_size * (int) i);
5895 mem = gen_rtx_MEM (reg_mode, addr);
5896 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5897
5898 insn = emit_move_insn (mem, reg);
5899 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5900 NULL_RTX, NULL_RTX);
5901 }
5902 }
5903
5904 /* Save lr if we used it. */
5905 if (info->lr_save_p)
5906 {
5907 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5908 GEN_INT (info->lr_save_offset + sp_offset));
5909 rtx reg = gen_rtx_REG (Pmode, 0);
5910 rtx mem = gen_rtx_MEM (Pmode, addr);
5911 /* This should not be of rs6000_sr_alias_set, because of
5912 __builtin_return_address. */
5913
5914 insn = emit_move_insn (mem, reg);
5915 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5916 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5917 }
5918
5919 /* Save CR if we use any that must be preserved. */
5920 if (info->cr_save_p)
5921 {
5922 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
5923 GEN_INT (info->cr_save_offset + sp_offset));
5924 rtx mem = gen_rtx_MEM (SImode, addr);
5925 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
5926
5927 /* If r12 was used to hold the original sp, copy cr into r0 now
5928 that it's free. */
5929 if (REGNO (frame_reg_rtx) == 12)
5930 {
5931 cr_save_rtx = gen_rtx_REG (SImode, 0);
5932 emit_insn (gen_movesi_from_cr (cr_save_rtx));
5933 }
5934 insn = emit_move_insn (mem, cr_save_rtx);
5935
5936 /* Now, there's no way that dwarf2out_frame_debug_expr is going
5937 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
5938 OK. All we have to do is specify that _one_ condition code
5939 register is saved in this stack slot. The thrower's epilogue
5940 will then restore all the call-saved registers. */
5941 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
5942 cr_save_rtx, gen_rtx_REG (SImode, CR0_REGNO));
5943 }
5944
5945 /* Update stack and set back pointer unless this is V.4,
5946 for which it was done previously. */
5947 if (info->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
5948 rs6000_emit_allocate_stack (info->total_size, FALSE);
5949
5950 /* Set frame pointer, if needed. */
5951 if (frame_pointer_needed)
5952 {
5953 insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM),
5954 sp_reg_rtx);
5955 RTX_FRAME_RELATED_P (insn) = 1;
5956 }
5957
5958 /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
5959 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
5960 || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
5961 && flag_pic == 1 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]))
5962 {
5963 /* If emit_load_toc_table will use the link register, we need to save
5964 it. We use R11 for this purpose because emit_load_toc_table
5965 can use register 0. This allows us to use a plain 'blr' to return
5966 from the procedure more often. */
5967 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0
5968 && ! info->lr_save_p
5969 && EXIT_BLOCK_PTR->pred != NULL);
5970 if (save_LR_around_toc_setup)
5971 emit_move_insn (gen_rtx_REG (Pmode, 11),
5972 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
5973
5974 rs6000_emit_load_toc_table (TRUE);
5975
5976 if (save_LR_around_toc_setup)
5977 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
5978 gen_rtx_REG (Pmode, 11));
5979 }
5980
5981 if (DEFAULT_ABI == ABI_DARWIN
5982 && flag_pic && current_function_uses_pic_offset_table)
5983 {
5984 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
5985
5986 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest)));
5987
5988 rs6000_maybe_dead (
5989 emit_move_insn (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM),
5990 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
5991 }
5992 }
5993
5994
5995 /* Write function prologue. */
5996 void
5997 output_prolog (file, size)
5998 FILE *file;
5999 int size ATTRIBUTE_UNUSED;
6000 {
6001 rs6000_stack_t *info = rs6000_stack_info ();
6002
6003 if (TARGET_DEBUG_STACK)
6004 debug_stack_info (info);
6005
6006 /* Write .extern for any function we will call to save and restore fp
6007 values. */
6008 if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
6009 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
6010 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
6011 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
6012
6013 /* Write .extern for AIX common mode routines, if needed. */
6014 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
6015 {
6016 fputs ("\t.extern __mulh\n", file);
6017 fputs ("\t.extern __mull\n", file);
6018 fputs ("\t.extern __divss\n", file);
6019 fputs ("\t.extern __divus\n", file);
6020 fputs ("\t.extern __quoss\n", file);
6021 fputs ("\t.extern __quous\n", file);
6022 common_mode_defined = 1;
6023 }
6024
6025 if (! HAVE_prologue)
6026 {
6027 start_sequence ();
6028
6029 /* A NOTE_INSN_DELETED is supposed to be at the start
6030 and end of the "toplevel" insn chain. */
6031 emit_note (0, NOTE_INSN_DELETED);
6032 rs6000_emit_prologue ();
6033 emit_note (0, NOTE_INSN_DELETED);
6034
6035 if (TARGET_DEBUG_STACK)
6036 debug_rtx_list (get_insns(), 100);
6037 final (get_insns(), file, FALSE, FALSE);
6038 end_sequence ();
6039 }
6040
6041 rs6000_pic_labelno++;
6042 }
6043
6044 /* Emit function epilogue as insns.
6045
6046 At present, dwarf2out_frame_debug_expr doesn't understand
6047 register restores, so we don't bother setting RTX_FRAME_RELATED_P
6048 anywhere in the epilogue. Most of the insns below would in any case
6049 need special notes to explain where r11 is in relation to the stack. */
6050
6051 void
6052 rs6000_emit_epilogue (sibcall)
6053 int sibcall;
6054 {
6055 rs6000_stack_t *info;
6056 int restoring_FPRs_inline;
6057 int using_load_multiple;
6058 int using_mfcr_multiple;
6059 int use_backchain_to_restore_sp;
6060 int sp_offset = 0;
6061 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
6062 rtx frame_reg_rtx = sp_reg_rtx;
6063 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
6064 int reg_size = TARGET_POWERPC64 ? 8 : 4;
6065 int i;
6066
6067 info = rs6000_stack_info ();
6068 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
6069 && info->first_gp_reg_save < 31);
6070 restoring_FPRs_inline = (sibcall
6071 || current_function_calls_eh_return
6072 || info->first_fp_reg_save == 64
6073 || FP_SAVE_INLINE (info->first_fp_reg_save));
6074 use_backchain_to_restore_sp = (frame_pointer_needed
6075 || current_function_calls_alloca
6076 || info->total_size > 32767);
6077 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
6078 || rs6000_cpu == PROCESSOR_PPC603
6079 || rs6000_cpu == PROCESSOR_PPC750
6080 || optimize_size);
6081
6082 /* If we have a frame pointer, a call to alloca, or a large stack
6083 frame, restore the old stack pointer using the backchain. Otherwise,
6084 we know what size to update it with. */
6085 if (use_backchain_to_restore_sp)
6086 {
6087 /* Under V.4, don't reset the stack pointer until after we're done
6088 loading the saved registers. */
6089 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6090 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
6091
6092 emit_move_insn (frame_reg_rtx,
6093 gen_rtx_MEM (Pmode, sp_reg_rtx));
6094
6095 }
6096 else if (info->push_p)
6097 {
6098 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6099 sp_offset = info->total_size;
6100 else
6101 {
6102 emit_insn (TARGET_32BIT
6103 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
6104 GEN_INT (info->total_size))
6105 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
6106 GEN_INT (info->total_size)));
6107 }
6108 }
6109
6110 /* Get the old lr if we saved it. */
6111 if (info->lr_save_p)
6112 {
6113 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6114 GEN_INT (info->lr_save_offset + sp_offset));
6115 rtx mem = gen_rtx_MEM (Pmode, addr);
6116 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6117
6118 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
6119 }
6120
6121 /* Get the old cr if we saved it. */
6122 if (info->cr_save_p)
6123 {
6124 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6125 GEN_INT (info->cr_save_offset + sp_offset));
6126 rtx mem = gen_rtx_MEM (SImode, addr);
6127 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6128
6129 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
6130 }
6131
6132 /* Set LR here to try to overlap restores below. */
6133 if (info->lr_save_p)
6134 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
6135 gen_rtx_REG (Pmode, 0));
6136
6137 /* Load exception handler data registers, if needed. */
6138 if (current_function_calls_eh_return)
6139 {
6140 unsigned int i, regno;
6141
6142 for (i = 0; ; ++i)
6143 {
6144 rtx addr, mem;
6145
6146 regno = EH_RETURN_DATA_REGNO (i);
6147 if (regno == INVALID_REGNUM)
6148 break;
6149
6150 addr = plus_constant (frame_reg_rtx,
6151 info->ehrd_offset + sp_offset
6152 + reg_size * (int) i);
6153 mem = gen_rtx_MEM (reg_mode, addr);
6154 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6155
6156 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
6157 }
6158 }
6159
6160 /* Restore GPRs. This is done as a PARALLEL if we are using
6161 the load-multiple instructions. */
6162 if (using_load_multiple)
6163 {
6164 rtvec p;
6165 p = rtvec_alloc (32 - info->first_gp_reg_save);
6166 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
6167 {
6168 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6169 GEN_INT (info->gp_save_offset
6170 + sp_offset
6171 + reg_size * i));
6172 rtx mem = gen_rtx_MEM (reg_mode, addr);
6173 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6174
6175 RTVEC_ELT (p, i) =
6176 gen_rtx_SET (VOIDmode,
6177 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
6178 mem);
6179 }
6180 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
6181 }
6182 else
6183 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
6184 if ((regs_ever_live[info->first_gp_reg_save+i]
6185 && ! call_used_regs[info->first_gp_reg_save+i])
6186 || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM
6187 && (((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6188 && flag_pic == 1)
6189 || (DEFAULT_ABI == ABI_DARWIN
6190 && flag_pic))))
6191 {
6192 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6193 GEN_INT (info->gp_save_offset
6194 + sp_offset
6195 + reg_size * i));
6196 rtx mem = gen_rtx_MEM (reg_mode, addr);
6197 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6198
6199 emit_move_insn (gen_rtx_REG (reg_mode,
6200 info->first_gp_reg_save + i),
6201 mem);
6202 }
6203
6204 /* Restore fpr's if we need to do it without calling a function. */
6205 if (restoring_FPRs_inline)
6206 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
6207 if ((regs_ever_live[info->first_fp_reg_save+i]
6208 && ! call_used_regs[info->first_fp_reg_save+i]))
6209 {
6210 rtx addr, mem;
6211 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
6212 GEN_INT (info->fp_save_offset
6213 + sp_offset
6214 + 8*i));
6215 mem = gen_rtx_MEM (DFmode, addr);
6216 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6217
6218 emit_move_insn (gen_rtx_REG (DFmode,
6219 info->first_fp_reg_save + i),
6220 mem);
6221 }
6222
6223 /* If we saved cr, restore it here. Just those that were used. */
6224 if (info->cr_save_p)
6225 {
6226 rtx r12_rtx = gen_rtx_REG (SImode, 12);
6227 int count = 0;
6228
6229 if (using_mfcr_multiple)
6230 {
6231 for (i = 0; i < 8; i++)
6232 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6233 count++;
6234 if (count == 0)
6235 abort ();
6236 }
6237
6238 if (using_mfcr_multiple && count > 1)
6239 {
6240 rtvec p;
6241 int ndx;
6242
6243 p = rtvec_alloc (count);
6244
6245 ndx = 0;
6246 for (i = 0; i < 8; i++)
6247 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6248 {
6249 rtvec r = rtvec_alloc (2);
6250 RTVEC_ELT (r, 0) = r12_rtx;
6251 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
6252 RTVEC_ELT (p, ndx) =
6253 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
6254 gen_rtx_UNSPEC (CCmode, r, 20));
6255 ndx++;
6256 }
6257 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
6258 if (ndx != count)
6259 abort ();
6260 }
6261 else
6262 for (i = 0; i < 8; i++)
6263 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
6264 {
6265 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
6266 CR0_REGNO+i),
6267 r12_rtx));
6268 }
6269 }
6270
6271 /* If this is V.4, unwind the stack pointer after all of the loads
6272 have been done. We need to emit a block here so that sched
6273 doesn't decide to move the sp change before the register restores
6274 (which may not have any obvious dependency on the stack). This
6275 doesn't hurt performance, because there is no scheduling that can
6276 be done after this point. */
6277 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
6278 {
6279 if (frame_reg_rtx != sp_reg_rtx)
6280 rs6000_emit_stack_tie ();
6281
6282 if (use_backchain_to_restore_sp)
6283 {
6284 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
6285 }
6286 else if (sp_offset != 0)
6287 {
6288 emit_insn (Pmode == SImode
6289 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
6290 GEN_INT (sp_offset))
6291 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
6292 GEN_INT (sp_offset)));
6293 }
6294 }
6295
6296 if (current_function_calls_eh_return)
6297 {
6298 rtx sa = EH_RETURN_STACKADJ_RTX;
6299 emit_insn (Pmode == SImode
6300 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
6301 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
6302 }
6303
6304 if (!sibcall)
6305 {
6306 rtvec p;
6307 if (! restoring_FPRs_inline)
6308 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
6309 else
6310 p = rtvec_alloc (2);
6311
6312 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
6313 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
6314 gen_rtx_REG (Pmode,
6315 LINK_REGISTER_REGNUM));
6316
6317 /* If we have to restore more than two FP registers, branch to the
6318 restore function. It will return to our caller. */
6319 if (! restoring_FPRs_inline)
6320 {
6321 int i;
6322 char rname[30];
6323 const char *alloc_rname;
6324
6325 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
6326 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
6327 alloc_rname = ggc_strdup (rname);
6328 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
6329 gen_rtx_SYMBOL_REF (Pmode,
6330 alloc_rname));
6331
6332 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
6333 {
6334 rtx addr, mem;
6335 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
6336 GEN_INT (info->fp_save_offset + 8*i));
6337 mem = gen_rtx_MEM (DFmode, addr);
6338 MEM_ALIAS_SET (mem) = rs6000_sr_alias_set;
6339
6340 RTVEC_ELT (p, i+3) =
6341 gen_rtx_SET (VOIDmode,
6342 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
6343 mem);
6344 }
6345 }
6346
6347 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
6348 }
6349 }
6350
6351 /* Write function epilogue. */
6352
6353 void
6354 output_epilog (file, size)
6355 FILE *file;
6356 int size ATTRIBUTE_UNUSED;
6357 {
6358 rs6000_stack_t *info = rs6000_stack_info ();
6359
6360 if (! HAVE_epilogue)
6361 {
6362 rtx insn = get_last_insn ();
6363 /* If the last insn was a BARRIER, we don't have to write anything except
6364 the trace table. */
6365 if (GET_CODE (insn) == NOTE)
6366 insn = prev_nonnote_insn (insn);
6367 if (insn == 0 || GET_CODE (insn) != BARRIER)
6368 {
6369 /* This is slightly ugly, but at least we don't have two
6370 copies of the epilogue-emitting code. */
6371 start_sequence ();
6372
6373 /* A NOTE_INSN_DELETED is supposed to be at the start
6374 and end of the "toplevel" insn chain. */
6375 emit_note (0, NOTE_INSN_DELETED);
6376 rs6000_emit_epilogue (FALSE);
6377 emit_note (0, NOTE_INSN_DELETED);
6378
6379 if (TARGET_DEBUG_STACK)
6380 debug_rtx_list (get_insns(), 100);
6381 final (get_insns(), file, FALSE, FALSE);
6382 end_sequence ();
6383 }
6384 }
6385
6386 /* Output a traceback table here. See /usr/include/sys/debug.h for info
6387 on its format.
6388
6389 We don't output a traceback table if -finhibit-size-directive was
6390 used. The documentation for -finhibit-size-directive reads
6391 ``don't output a @code{.size} assembler directive, or anything
6392 else that would cause trouble if the function is split in the
6393 middle, and the two halves are placed at locations far apart in
6394 memory.'' The traceback table has this property, since it
6395 includes the offset from the start of the function to the
6396 traceback table itself.
6397
6398 System V.4 Powerpc's (and the embedded ABI derived from it) use a
6399 different traceback table. */
6400 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
6401 {
6402 const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
6403 int fixed_parms, float_parms, parm_info;
6404 int i;
6405
6406 while (*fname == '.') /* V.4 encodes . in the name */
6407 fname++;
6408
6409 /* Need label immediately before tbtab, so we can compute its offset
6410 from the function start. */
6411 if (*fname == '*')
6412 ++fname;
6413 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
6414 ASM_OUTPUT_LABEL (file, fname);
6415
6416 /* The .tbtab pseudo-op can only be used for the first eight
6417 expressions, since it can't handle the possibly variable
6418 length fields that follow. However, if you omit the optional
6419 fields, the assembler outputs zeros for all optional fields
6420 anyways, giving each variable length field is minimum length
6421 (as defined in sys/debug.h). Thus we can not use the .tbtab
6422 pseudo-op at all. */
6423
6424 /* An all-zero word flags the start of the tbtab, for debuggers
6425 that have to find it by searching forward from the entry
6426 point or from the current pc. */
6427 fputs ("\t.long 0\n", file);
6428
6429 /* Tbtab format type. Use format type 0. */
6430 fputs ("\t.byte 0,", file);
6431
6432 /* Language type. Unfortunately, there doesn't seem to be any
6433 official way to get this info, so we use language_string. C
6434 is 0. C++ is 9. No number defined for Obj-C, so use the
6435 value for C for now. There is no official value for Java,
6436 although IBM appears to be using 13. There is no official value
6437 for Chill, so we've choosen 44 pseudo-randomly. */
6438 if (! strcmp (language_string, "GNU C")
6439 || ! strcmp (language_string, "GNU Objective-C"))
6440 i = 0;
6441 else if (! strcmp (language_string, "GNU F77"))
6442 i = 1;
6443 else if (! strcmp (language_string, "GNU Ada"))
6444 i = 3;
6445 else if (! strcmp (language_string, "GNU Pascal"))
6446 i = 2;
6447 else if (! strcmp (language_string, "GNU C++"))
6448 i = 9;
6449 else if (! strcmp (language_string, "GNU Java"))
6450 i = 13;
6451 else if (! strcmp (language_string, "GNU CHILL"))
6452 i = 44;
6453 else
6454 abort ();
6455 fprintf (file, "%d,", i);
6456
6457 /* 8 single bit fields: global linkage (not set for C extern linkage,
6458 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
6459 from start of procedure stored in tbtab, internal function, function
6460 has controlled storage, function has no toc, function uses fp,
6461 function logs/aborts fp operations. */
6462 /* Assume that fp operations are used if any fp reg must be saved. */
6463 fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1));
6464
6465 /* 6 bitfields: function is interrupt handler, name present in
6466 proc table, function calls alloca, on condition directives
6467 (controls stack walks, 3 bits), saves condition reg, saves
6468 link reg. */
6469 /* The `function calls alloca' bit seems to be set whenever reg 31 is
6470 set up as a frame pointer, even when there is no alloca call. */
6471 fprintf (file, "%d,",
6472 ((1 << 6) | (frame_pointer_needed << 5)
6473 | (info->cr_save_p << 1) | (info->lr_save_p)));
6474
6475 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
6476 (6 bits). */
6477 fprintf (file, "%d,",
6478 (info->push_p << 7) | (64 - info->first_fp_reg_save));
6479
6480 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
6481 fprintf (file, "%d,", (32 - first_reg_to_save ()));
6482
6483 {
6484 /* Compute the parameter info from the function decl argument
6485 list. */
6486 tree decl;
6487 int next_parm_info_bit;
6488
6489 next_parm_info_bit = 31;
6490 parm_info = 0;
6491 fixed_parms = 0;
6492 float_parms = 0;
6493
6494 for (decl = DECL_ARGUMENTS (current_function_decl);
6495 decl; decl = TREE_CHAIN (decl))
6496 {
6497 rtx parameter = DECL_INCOMING_RTL (decl);
6498 enum machine_mode mode = GET_MODE (parameter);
6499
6500 if (GET_CODE (parameter) == REG)
6501 {
6502 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6503 {
6504 int bits;
6505
6506 float_parms++;
6507
6508 if (mode == SFmode)
6509 bits = 0x2;
6510 else if (mode == DFmode)
6511 bits = 0x3;
6512 else
6513 abort ();
6514
6515 /* If only one bit will fit, don't or in this entry. */
6516 if (next_parm_info_bit > 0)
6517 parm_info |= (bits << (next_parm_info_bit - 1));
6518 next_parm_info_bit -= 2;
6519 }
6520 else
6521 {
6522 fixed_parms += ((GET_MODE_SIZE (mode)
6523 + (UNITS_PER_WORD - 1))
6524 / UNITS_PER_WORD);
6525 next_parm_info_bit -= 1;
6526 }
6527 }
6528 }
6529 }
6530
6531 /* Number of fixed point parameters. */
6532 /* This is actually the number of words of fixed point parameters; thus
6533 an 8 byte struct counts as 2; and thus the maximum value is 8. */
6534 fprintf (file, "%d,", fixed_parms);
6535
6536 /* 2 bitfields: number of floating point parameters (7 bits), parameters
6537 all on stack. */
6538 /* This is actually the number of fp registers that hold parameters;
6539 and thus the maximum value is 13. */
6540 /* Set parameters on stack bit if parameters are not in their original
6541 registers, regardless of whether they are on the stack? Xlc
6542 seems to set the bit when not optimizing. */
6543 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
6544
6545 /* Optional fields follow. Some are variable length. */
6546
6547 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
6548 11 double float. */
6549 /* There is an entry for each parameter in a register, in the order that
6550 they occur in the parameter list. Any intervening arguments on the
6551 stack are ignored. If the list overflows a long (max possible length
6552 34 bits) then completely leave off all elements that don't fit. */
6553 /* Only emit this long if there was at least one parameter. */
6554 if (fixed_parms || float_parms)
6555 fprintf (file, "\t.long %d\n", parm_info);
6556
6557 /* Offset from start of code to tb table. */
6558 fputs ("\t.long ", file);
6559 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
6560 #if TARGET_AIX
6561 RS6000_OUTPUT_BASENAME (file, fname);
6562 #else
6563 assemble_name (file, fname);
6564 #endif
6565 fputs ("-.", file);
6566 #if TARGET_AIX
6567 RS6000_OUTPUT_BASENAME (file, fname);
6568 #else
6569 assemble_name (file, fname);
6570 #endif
6571 putc ('\n', file);
6572
6573 /* Interrupt handler mask. */
6574 /* Omit this long, since we never set the interrupt handler bit
6575 above. */
6576
6577 /* Number of CTL (controlled storage) anchors. */
6578 /* Omit this long, since the has_ctl bit is never set above. */
6579
6580 /* Displacement into stack of each CTL anchor. */
6581 /* Omit this list of longs, because there are no CTL anchors. */
6582
6583 /* Length of function name. */
6584 fprintf (file, "\t.short %d\n", (int) strlen (fname));
6585
6586 /* Function name. */
6587 assemble_string (fname, strlen (fname));
6588
6589 /* Register for alloca automatic storage; this is always reg 31.
6590 Only emit this if the alloca bit was set above. */
6591 if (frame_pointer_needed)
6592 fputs ("\t.byte 31\n", file);
6593 }
6594 }
6595 \f
6596 /* A C compound statement that outputs the assembler code for a thunk function,
6597 used to implement C++ virtual function calls with multiple inheritance. The
6598 thunk acts as a wrapper around a virtual function, adjusting the implicit
6599 object parameter before handing control off to the real function.
6600
6601 First, emit code to add the integer DELTA to the location that contains the
6602 incoming first argument. Assume that this argument contains a pointer, and
6603 is the one used to pass the `this' pointer in C++. This is the incoming
6604 argument *before* the function prologue, e.g. `%o0' on a sparc. The
6605 addition must preserve the values of all other incoming arguments.
6606
6607 After the addition, emit code to jump to FUNCTION, which is a
6608 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
6609 the return address. Hence returning from FUNCTION will return to whoever
6610 called the current `thunk'.
6611
6612 The effect must be as if FUNCTION had been called directly with the adjusted
6613 first argument. This macro is responsible for emitting all of the code for
6614 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
6615 invoked.
6616
6617 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
6618 extracted from it.) It might possibly be useful on some targets, but
6619 probably not.
6620
6621 If you do not define this macro, the target-independent code in the C++
6622 frontend will generate a less efficient heavyweight thunk that calls
6623 FUNCTION instead of jumping to it. The generic approach does not support
6624 varargs. */
6625
6626 void
6627 output_mi_thunk (file, thunk_fndecl, delta, function)
6628 FILE *file;
6629 tree thunk_fndecl ATTRIBUTE_UNUSED;
6630 int delta;
6631 tree function;
6632 {
6633 const char *this_reg = reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ];
6634 const char *prefix;
6635 const char *fname;
6636 const char *r0 = reg_names[0];
6637 const char *toc = reg_names[2];
6638 const char *schain = reg_names[11];
6639 const char *r12 = reg_names[12];
6640 char buf[512];
6641 static int labelno = 0;
6642
6643 /* Small constants that can be done by one add instruction */
6644 if (delta >= -32768 && delta <= 32767)
6645 {
6646 if (! TARGET_NEW_MNEMONICS)
6647 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg);
6648 else
6649 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta);
6650 }
6651
6652 /* Large constants that can be done by one addis instruction */
6653 else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1)
6654 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6655 delta >> 16);
6656
6657 /* 32-bit constants that can be done by an add and addis instruction. */
6658 else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1)
6659 {
6660 /* Break into two pieces, propagating the sign bit from the low word to
6661 the upper word. */
6662 int delta_high = delta >> 16;
6663 int delta_low = delta & 0xffff;
6664 if ((delta_low & 0x8000) != 0)
6665 {
6666 delta_high++;
6667 delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */
6668 }
6669
6670 asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg,
6671 delta_high);
6672
6673 if (! TARGET_NEW_MNEMONICS)
6674 fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg);
6675 else
6676 fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low);
6677 }
6678
6679 /* 64-bit constants, fixme */
6680 else
6681 abort ();
6682
6683 /* Get the prefix in front of the names. */
6684 switch (DEFAULT_ABI)
6685 {
6686 default:
6687 abort ();
6688
6689 case ABI_AIX:
6690 prefix = ".";
6691 break;
6692
6693 case ABI_V4:
6694 case ABI_AIX_NODESC:
6695 case ABI_SOLARIS:
6696 prefix = "";
6697 break;
6698 }
6699
6700 /* If the function is compiled in this module, jump to it directly.
6701 Otherwise, load up its address and jump to it. */
6702
6703 fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
6704
6705 if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode)
6706 && ! lookup_attribute ("longcall",
6707 TYPE_ATTRIBUTES (TREE_TYPE (function))))
6708 {
6709 fprintf (file, "\tb %s", prefix);
6710 assemble_name (file, fname);
6711 if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file);
6712 putc ('\n', file);
6713 }
6714
6715 else
6716 {
6717 switch (DEFAULT_ABI)
6718 {
6719 default:
6720 abort ();
6721
6722 case ABI_AIX:
6723 /* Set up a TOC entry for the function. */
6724 ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno);
6725 toc_section ();
6726 ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno);
6727 labelno++;
6728
6729 /* Note, MINIMAL_TOC doesn't make sense in the case of a thunk, since
6730 there will be only one TOC entry for this function. */
6731 fputs ("\t.tc\t", file);
6732 assemble_name (file, buf);
6733 fputs ("[TC],", file);
6734 assemble_name (file, buf);
6735 putc ('\n', file);
6736 text_section ();
6737 asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s", r12);
6738 assemble_name (file, buf);
6739 asm_fprintf (file, "(%s)\n", reg_names[2]);
6740 asm_fprintf (file,
6741 (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n",
6742 r0, r12);
6743
6744 asm_fprintf (file,
6745 (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n",
6746 toc, r12);
6747
6748 asm_fprintf (file, "\tmtctr %s\n", r0);
6749 asm_fprintf (file,
6750 (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n",
6751 schain, r12);
6752
6753 asm_fprintf (file, "\tbctr\n");
6754 break;
6755
6756 case ABI_AIX_NODESC:
6757 case ABI_SOLARIS:
6758 case ABI_V4:
6759 fprintf (file, "\tb %s", prefix);
6760 assemble_name (file, fname);
6761 if (flag_pic) fputs ("@plt", file);
6762 putc ('\n', file);
6763 break;
6764
6765 #if TARGET_MACHO
6766 case ABI_DARWIN:
6767 fprintf (file, "\tb %s", prefix);
6768 if (flag_pic && !machopic_name_defined_p (fname))
6769 assemble_name (file, machopic_stub_name (fname));
6770 else
6771 assemble_name (file, fname);
6772 putc ('\n', file);
6773 break;
6774 #endif
6775 }
6776 }
6777 }
6778
6779 \f
6780 /* A quick summary of the various types of 'constant-pool tables'
6781 under PowerPC:
6782
6783 Target Flags Name One table per
6784 AIX (none) AIX TOC object file
6785 AIX -mfull-toc AIX TOC object file
6786 AIX -mminimal-toc AIX minimal TOC translation unit
6787 SVR4/EABI (none) SVR4 SDATA object file
6788 SVR4/EABI -fpic SVR4 pic object file
6789 SVR4/EABI -fPIC SVR4 PIC translation unit
6790 SVR4/EABI -mrelocatable EABI TOC function
6791 SVR4/EABI -maix AIX TOC object file
6792 SVR4/EABI -maix -mminimal-toc
6793 AIX minimal TOC translation unit
6794
6795 Name Reg. Set by entries contains:
6796 made by addrs? fp? sum?
6797
6798 AIX TOC 2 crt0 as Y option option
6799 AIX minimal TOC 30 prolog gcc Y Y option
6800 SVR4 SDATA 13 crt0 gcc N Y N
6801 SVR4 pic 30 prolog ld Y not yet N
6802 SVR4 PIC 30 prolog gcc Y option option
6803 EABI TOC 30 prolog gcc Y option option
6804
6805 */
6806
6807 /* Hash table stuff for keeping track of TOC entries. */
6808
6809 struct toc_hash_struct
6810 {
6811 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
6812 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
6813 rtx key;
6814 enum machine_mode key_mode;
6815 int labelno;
6816 };
6817
6818 static htab_t toc_hash_table;
6819
6820 /* Hash functions for the hash table. */
6821
6822 static unsigned
6823 rs6000_hash_constant (k)
6824 rtx k;
6825 {
6826 unsigned result = (GET_CODE (k) << 3) ^ GET_MODE (k);
6827 const char *format = GET_RTX_FORMAT (GET_CODE (k));
6828 int flen = strlen (format);
6829 int fidx;
6830
6831 if (GET_CODE (k) == LABEL_REF)
6832 return result * 1231 + X0INT (XEXP (k, 0), 3);
6833
6834 if (GET_CODE (k) == CONST_DOUBLE)
6835 fidx = 2;
6836 else if (GET_CODE (k) == CODE_LABEL)
6837 fidx = 3;
6838 else
6839 fidx = 0;
6840
6841 for (; fidx < flen; fidx++)
6842 switch (format[fidx])
6843 {
6844 case 's':
6845 {
6846 unsigned i, len;
6847 const char *str = XSTR (k, fidx);
6848 len = strlen (str);
6849 result = result * 613 + len;
6850 for (i = 0; i < len; i++)
6851 result = result * 613 + (unsigned) str[i];
6852 break;
6853 }
6854 case 'u':
6855 case 'e':
6856 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
6857 break;
6858 case 'i':
6859 case 'n':
6860 result = result * 613 + (unsigned) XINT (k, fidx);
6861 break;
6862 case 'w':
6863 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
6864 result = result * 613 + (unsigned) XWINT (k, fidx);
6865 else
6866 {
6867 size_t i;
6868 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
6869 result = result * 613 + (unsigned) (XWINT (k, fidx)
6870 >> CHAR_BIT * i);
6871 }
6872 break;
6873 default:
6874 abort();
6875 }
6876 return result;
6877 }
6878
6879 static unsigned
6880 toc_hash_function (hash_entry)
6881 const void * hash_entry;
6882 {
6883 const struct toc_hash_struct *thc =
6884 (const struct toc_hash_struct *) hash_entry;
6885 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
6886 }
6887
6888 /* Compare H1 and H2 for equivalence. */
6889
6890 static int
6891 toc_hash_eq (h1, h2)
6892 const void * h1;
6893 const void * h2;
6894 {
6895 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
6896 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
6897
6898 if (((const struct toc_hash_struct *) h1)->key_mode
6899 != ((const struct toc_hash_struct *) h2)->key_mode)
6900 return 0;
6901
6902 /* Gotcha: One of these const_doubles will be in memory.
6903 The other may be on the constant-pool chain.
6904 So rtx_equal_p will think they are different... */
6905 if (r1 == r2)
6906 return 1;
6907 if (GET_CODE (r1) != GET_CODE (r2)
6908 || GET_MODE (r1) != GET_MODE (r2))
6909 return 0;
6910 if (GET_CODE (r1) == CONST_DOUBLE)
6911 {
6912 int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE));
6913 int i;
6914 for (i = 2; i < format_len; i++)
6915 if (XWINT (r1, i) != XWINT (r2, i))
6916 return 0;
6917
6918 return 1;
6919 }
6920 else if (GET_CODE (r1) == LABEL_REF)
6921 return (CODE_LABEL_NUMBER (XEXP (r1, 0))
6922 == CODE_LABEL_NUMBER (XEXP (r2, 0)));
6923 else
6924 return rtx_equal_p (r1, r2);
6925 }
6926
6927 /* Mark the hash table-entry HASH_ENTRY. */
6928
6929 static int
6930 toc_hash_mark_entry (hash_slot, unused)
6931 void ** hash_slot;
6932 void * unused ATTRIBUTE_UNUSED;
6933 {
6934 const struct toc_hash_struct * hash_entry =
6935 *(const struct toc_hash_struct **) hash_slot;
6936 rtx r = hash_entry->key;
6937 ggc_set_mark (hash_entry);
6938 /* For CODE_LABELS, we don't want to drag in the whole insn chain... */
6939 if (GET_CODE (r) == LABEL_REF)
6940 {
6941 ggc_set_mark (r);
6942 ggc_set_mark (XEXP (r, 0));
6943 }
6944 else
6945 ggc_mark_rtx (r);
6946 return 1;
6947 }
6948
6949 /* Mark all the elements of the TOC hash-table *HT. */
6950
6951 static void
6952 toc_hash_mark_table (vht)
6953 void *vht;
6954 {
6955 htab_t *ht = vht;
6956
6957 htab_traverse (*ht, toc_hash_mark_entry, (void *)0);
6958 }
6959
6960 /* These are the names given by the C++ front-end to vtables, and
6961 vtable-like objects. Ideally, this logic should not be here;
6962 instead, there should be some programmatic way of inquiring as
6963 to whether or not an object is a vtable. */
6964
6965 #define VTABLE_NAME_P(NAME) \
6966 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
6967 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
6968 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
6969 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
6970
6971 void
6972 rs6000_output_symbol_ref (file, x)
6973 FILE *file;
6974 rtx x;
6975 {
6976 /* Currently C++ toc references to vtables can be emitted before it
6977 is decided whether the vtable is public or private. If this is
6978 the case, then the linker will eventually complain that there is
6979 a reference to an unknown section. Thus, for vtables only,
6980 we emit the TOC reference to reference the symbol and not the
6981 section. */
6982 const char *name = XSTR (x, 0);
6983
6984 if (VTABLE_NAME_P (name))
6985 {
6986 RS6000_OUTPUT_BASENAME (file, name);
6987 }
6988 else
6989 assemble_name (file, name);
6990 }
6991
6992 /* Output a TOC entry. We derive the entry name from what is
6993 being written. */
6994
6995 void
6996 output_toc (file, x, labelno, mode)
6997 FILE *file;
6998 rtx x;
6999 int labelno;
7000 enum machine_mode mode;
7001 {
7002 char buf[256];
7003 const char *name = buf;
7004 const char *real_name;
7005 rtx base = x;
7006 int offset = 0;
7007
7008 if (TARGET_NO_TOC)
7009 abort ();
7010
7011 /* When the linker won't eliminate them, don't output duplicate
7012 TOC entries (this happens on AIX if there is any kind of TOC,
7013 and on SVR4 under -fPIC or -mrelocatable). */
7014 if (TARGET_TOC)
7015 {
7016 struct toc_hash_struct *h;
7017 void * * found;
7018
7019 h = ggc_alloc (sizeof (*h));
7020 h->key = x;
7021 h->key_mode = mode;
7022 h->labelno = labelno;
7023
7024 found = htab_find_slot (toc_hash_table, h, 1);
7025 if (*found == NULL)
7026 *found = h;
7027 else /* This is indeed a duplicate.
7028 Set this label equal to that label. */
7029 {
7030 fputs ("\t.set ", file);
7031 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
7032 fprintf (file, "%d,", labelno);
7033 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
7034 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
7035 found)->labelno));
7036 return;
7037 }
7038 }
7039
7040 /* If we're going to put a double constant in the TOC, make sure it's
7041 aligned properly when strict alignment is on. */
7042 if (GET_CODE (x) == CONST_DOUBLE
7043 && STRICT_ALIGNMENT
7044 && GET_MODE_BITSIZE (mode) >= 64
7045 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
7046 ASM_OUTPUT_ALIGN (file, 3);
7047 }
7048
7049 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
7050
7051 /* Handle FP constants specially. Note that if we have a minimal
7052 TOC, things we put here aren't actually in the TOC, so we can allow
7053 FP constants. */
7054 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
7055 {
7056 REAL_VALUE_TYPE rv;
7057 long k[2];
7058
7059 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
7060 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
7061
7062 if (TARGET_64BIT)
7063 {
7064 if (TARGET_MINIMAL_TOC)
7065 fprintf (file, "\t.llong 0x%lx%08lx\n", k[0], k[1]);
7066 else
7067 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx%08lx\n",
7068 k[0], k[1], k[0] & 0xffffffff, k[1] & 0xffffffff);
7069 return;
7070 }
7071 else
7072 {
7073 if (TARGET_MINIMAL_TOC)
7074 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n", k[0], k[1]);
7075 else
7076 fprintf (file, "\t.tc FD_%lx_%lx[TC],0x%lx,0x%lx\n",
7077 k[0], k[1], k[0], k[1]);
7078 return;
7079 }
7080 }
7081 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
7082 {
7083 REAL_VALUE_TYPE rv;
7084 long l;
7085
7086 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
7087 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7088
7089 if (TARGET_64BIT)
7090 {
7091 if (TARGET_MINIMAL_TOC)
7092 fprintf (file, "\t.llong 0x%lx00000000\n", l);
7093 else
7094 fprintf (file, "\t.tc FS_%lx[TC],0x%lx00000000\n", l, l);
7095 return;
7096 }
7097 else
7098 {
7099 if (TARGET_MINIMAL_TOC)
7100 fprintf (file, "\t.long 0x%lx\n", l);
7101 else
7102 fprintf (file, "\t.tc FS_%lx[TC],0x%lx\n", l, l);
7103 return;
7104 }
7105 }
7106 else if (GET_MODE (x) == VOIDmode
7107 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
7108 {
7109 unsigned HOST_WIDE_INT low;
7110 HOST_WIDE_INT high;
7111
7112 if (GET_CODE (x) == CONST_DOUBLE)
7113 {
7114 low = CONST_DOUBLE_LOW (x);
7115 high = CONST_DOUBLE_HIGH (x);
7116 }
7117 else
7118 #if HOST_BITS_PER_WIDE_INT == 32
7119 {
7120 low = INTVAL (x);
7121 high = (low & 0x80000000) ? ~0 : 0;
7122 }
7123 #else
7124 {
7125 low = INTVAL (x) & 0xffffffff;
7126 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
7127 }
7128 #endif
7129
7130 /* TOC entries are always Pmode-sized, but since this
7131 is a bigendian machine then if we're putting smaller
7132 integer constants in the TOC we have to pad them.
7133 (This is still a win over putting the constants in
7134 a separate constant pool, because then we'd have
7135 to have both a TOC entry _and_ the actual constant.)
7136
7137 For a 32-bit target, CONST_INT values are loaded and shifted
7138 entirely within `low' and can be stored in one TOC entry. */
7139
7140 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
7141 abort ();/* It would be easy to make this work, but it doesn't now. */
7142
7143 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
7144 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
7145 POINTER_SIZE, &low, &high, 0);
7146
7147 if (TARGET_64BIT)
7148 {
7149 if (TARGET_MINIMAL_TOC)
7150 fprintf (file, "\t.llong 0x%lx%08lx\n", (long)high, (long)low);
7151 else
7152 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx%08lx\n",
7153 (long)high, (long)low, (long)high, (long)low);
7154 return;
7155 }
7156 else
7157 {
7158 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
7159 {
7160 if (TARGET_MINIMAL_TOC)
7161 fprintf (file, "\t.long 0x%lx\n\t.long 0x%lx\n",
7162 (long)high, (long)low);
7163 else
7164 fprintf (file, "\t.tc ID_%lx_%lx[TC],0x%lx,0x%lx\n",
7165 (long)high, (long)low, (long)high, (long)low);
7166 }
7167 else
7168 {
7169 if (TARGET_MINIMAL_TOC)
7170 fprintf (file, "\t.long 0x%lx\n",
7171 (long)low);
7172 else
7173 fprintf (file, "\t.tc IS_%lx[TC],0x%lx\n",
7174 (long)low, (long)low);
7175 }
7176 return;
7177 }
7178 }
7179
7180 if (GET_CODE (x) == CONST)
7181 {
7182 base = XEXP (XEXP (x, 0), 0);
7183 offset = INTVAL (XEXP (XEXP (x, 0), 1));
7184 }
7185
7186 if (GET_CODE (base) == SYMBOL_REF)
7187 name = XSTR (base, 0);
7188 else if (GET_CODE (base) == LABEL_REF)
7189 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
7190 else if (GET_CODE (base) == CODE_LABEL)
7191 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
7192 else
7193 abort ();
7194
7195 STRIP_NAME_ENCODING (real_name, name);
7196 if (TARGET_MINIMAL_TOC)
7197 fputs (TARGET_32BIT ? "\t.long " : "\t.llong ", file);
7198 else
7199 {
7200 fprintf (file, "\t.tc %s", real_name);
7201
7202 if (offset < 0)
7203 fprintf (file, ".N%d", - offset);
7204 else if (offset)
7205 fprintf (file, ".P%d", offset);
7206
7207 fputs ("[TC],", file);
7208 }
7209
7210 /* Currently C++ toc references to vtables can be emitted before it
7211 is decided whether the vtable is public or private. If this is
7212 the case, then the linker will eventually complain that there is
7213 a TOC reference to an unknown section. Thus, for vtables only,
7214 we emit the TOC reference to reference the symbol and not the
7215 section. */
7216 if (VTABLE_NAME_P (name))
7217 {
7218 RS6000_OUTPUT_BASENAME (file, name);
7219 if (offset < 0)
7220 fprintf (file, "%d", offset);
7221 else if (offset > 0)
7222 fprintf (file, "+%d", offset);
7223 }
7224 else
7225 output_addr_const (file, x);
7226 putc ('\n', file);
7227 }
7228 \f
7229 /* Output an assembler pseudo-op to write an ASCII string of N characters
7230 starting at P to FILE.
7231
7232 On the RS/6000, we have to do this using the .byte operation and
7233 write out special characters outside the quoted string.
7234 Also, the assembler is broken; very long strings are truncated,
7235 so we must artificially break them up early. */
7236
7237 void
7238 output_ascii (file, p, n)
7239 FILE *file;
7240 const char *p;
7241 int n;
7242 {
7243 char c;
7244 int i, count_string;
7245 const char *for_string = "\t.byte \"";
7246 const char *for_decimal = "\t.byte ";
7247 const char *to_close = NULL;
7248
7249 count_string = 0;
7250 for (i = 0; i < n; i++)
7251 {
7252 c = *p++;
7253 if (c >= ' ' && c < 0177)
7254 {
7255 if (for_string)
7256 fputs (for_string, file);
7257 putc (c, file);
7258
7259 /* Write two quotes to get one. */
7260 if (c == '"')
7261 {
7262 putc (c, file);
7263 ++count_string;
7264 }
7265
7266 for_string = NULL;
7267 for_decimal = "\"\n\t.byte ";
7268 to_close = "\"\n";
7269 ++count_string;
7270
7271 if (count_string >= 512)
7272 {
7273 fputs (to_close, file);
7274
7275 for_string = "\t.byte \"";
7276 for_decimal = "\t.byte ";
7277 to_close = NULL;
7278 count_string = 0;
7279 }
7280 }
7281 else
7282 {
7283 if (for_decimal)
7284 fputs (for_decimal, file);
7285 fprintf (file, "%d", c);
7286
7287 for_string = "\n\t.byte \"";
7288 for_decimal = ", ";
7289 to_close = "\n";
7290 count_string = 0;
7291 }
7292 }
7293
7294 /* Now close the string if we have written one. Then end the line. */
7295 if (to_close)
7296 fputs (to_close, file);
7297 }
7298 \f
7299 /* Generate a unique section name for FILENAME for a section type
7300 represented by SECTION_DESC. Output goes into BUF.
7301
7302 SECTION_DESC can be any string, as long as it is different for each
7303 possible section type.
7304
7305 We name the section in the same manner as xlc. The name begins with an
7306 underscore followed by the filename (after stripping any leading directory
7307 names) with the last period replaced by the string SECTION_DESC. If
7308 FILENAME does not contain a period, SECTION_DESC is appended to the end of
7309 the name. */
7310
7311 void
7312 rs6000_gen_section_name (buf, filename, section_desc)
7313 char **buf;
7314 const char *filename;
7315 const char *section_desc;
7316 {
7317 const char *q, *after_last_slash, *last_period = 0;
7318 char *p;
7319 int len;
7320
7321 after_last_slash = filename;
7322 for (q = filename; *q; q++)
7323 {
7324 if (*q == '/')
7325 after_last_slash = q + 1;
7326 else if (*q == '.')
7327 last_period = q;
7328 }
7329
7330 len = strlen (after_last_slash) + strlen (section_desc) + 2;
7331 *buf = (char *) permalloc (len);
7332
7333 p = *buf;
7334 *p++ = '_';
7335
7336 for (q = after_last_slash; *q; q++)
7337 {
7338 if (q == last_period)
7339 {
7340 strcpy (p, section_desc);
7341 p += strlen (section_desc);
7342 }
7343
7344 else if (ISALNUM (*q))
7345 *p++ = *q;
7346 }
7347
7348 if (last_period == 0)
7349 strcpy (p, section_desc);
7350 else
7351 *p = '\0';
7352 }
7353 \f
7354
7355 /* Emit profile function. */
7356 void
7357 output_profile_hook (labelno)
7358 int labelno;
7359 {
7360 if (DEFAULT_ABI == ABI_AIX)
7361 {
7362 char buf[30];
7363 char *label_name;
7364 rtx fun;
7365
7366 labelno += 1;
7367
7368 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7369 STRIP_NAME_ENCODING (label_name, ggc_strdup (buf));
7370 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
7371
7372 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
7373 fun, Pmode);
7374 }
7375 else if (DEFAULT_ABI == ABI_DARWIN)
7376 {
7377 const char *mcount_name = RS6000_MCOUNT;
7378 int caller_addr_regno = LINK_REGISTER_REGNUM;
7379
7380 /* Be conservative and always set this, at least for now. */
7381 current_function_uses_pic_offset_table = 1;
7382
7383 #if TARGET_MACHO
7384 /* For PIC code, set up a stub and collect the caller's address
7385 from r0, which is where the prologue puts it. */
7386 if (flag_pic)
7387 {
7388 mcount_name = machopic_stub_name (mcount_name);
7389 if (current_function_uses_pic_offset_table)
7390 caller_addr_regno = 0;
7391 }
7392 #endif
7393 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
7394 0, VOIDmode, 1,
7395 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
7396 }
7397 }
7398
7399 /* Write function profiler code. */
7400
7401 void
7402 output_function_profiler (file, labelno)
7403 FILE *file;
7404 int labelno;
7405 {
7406 char buf[100];
7407
7408 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
7409 switch (DEFAULT_ABI)
7410 {
7411 default:
7412 abort ();
7413
7414 case ABI_V4:
7415 case ABI_SOLARIS:
7416 case ABI_AIX_NODESC:
7417 fprintf (file, "\tmflr %s\n", reg_names[0]);
7418 if (flag_pic == 1)
7419 {
7420 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
7421 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7422 reg_names[0], reg_names[1]);
7423 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
7424 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
7425 assemble_name (file, buf);
7426 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
7427 }
7428 else if (flag_pic > 1)
7429 {
7430 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7431 reg_names[0], reg_names[1]);
7432 /* Now, we need to get the address of the label. */
7433 fputs ("\tbl 1f\n\t.long ", file);
7434 assemble_name (file, buf);
7435 fputs ("-.\n1:", file);
7436 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
7437 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
7438 reg_names[0], reg_names[11]);
7439 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
7440 reg_names[0], reg_names[0], reg_names[11]);
7441 }
7442 else
7443 {
7444 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
7445 assemble_name (file, buf);
7446 fputs ("@ha\n", file);
7447 asm_fprintf (file, "\t{st|stw} %s,4(%s)\n",
7448 reg_names[0], reg_names[1]);
7449 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
7450 assemble_name (file, buf);
7451 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
7452 }
7453
7454 if (current_function_needs_context)
7455 asm_fprintf (file, "\tmr %s,%s\n",
7456 reg_names[30], reg_names[STATIC_CHAIN_REGNUM]);
7457 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
7458 if (current_function_needs_context)
7459 asm_fprintf (file, "\tmr %s,%s\n",
7460 reg_names[STATIC_CHAIN_REGNUM], reg_names[30]);
7461 break;
7462
7463 case ABI_AIX:
7464 case ABI_DARWIN:
7465 /* Don't do anything, done in output_profile_hook (). */
7466 break;
7467
7468 }
7469 }
7470
7471 /* Adjust the cost of a scheduling dependency. Return the new cost of
7472 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7473
7474 int
7475 rs6000_adjust_cost (insn, link, dep_insn, cost)
7476 rtx insn;
7477 rtx link;
7478 rtx dep_insn ATTRIBUTE_UNUSED;
7479 int cost;
7480 {
7481 if (! recog_memoized (insn))
7482 return 0;
7483
7484 if (REG_NOTE_KIND (link) != 0)
7485 return 0;
7486
7487 if (REG_NOTE_KIND (link) == 0)
7488 {
7489 /* Data dependency; DEP_INSN writes a register that INSN reads some
7490 cycles later. */
7491
7492 /* Tell the first scheduling pass about the latency between a mtctr
7493 and bctr (and mtlr and br/blr). The first scheduling pass will not
7494 know about this latency since the mtctr instruction, which has the
7495 latency associated to it, will be generated by reload. */
7496 if (get_attr_type (insn) == TYPE_JMPREG)
7497 return TARGET_POWER ? 5 : 4;
7498
7499 /* Fall out to return default cost. */
7500 }
7501
7502 return cost;
7503 }
7504
7505 /* A C statement (sans semicolon) to update the integer scheduling priority
7506 INSN_PRIORITY (INSN). Reduce the priority to execute the INSN earlier,
7507 increase the priority to execute INSN later. Do not define this macro if
7508 you do not need to adjust the scheduling priorities of insns. */
7509
7510 int
7511 rs6000_adjust_priority (insn, priority)
7512 rtx insn ATTRIBUTE_UNUSED;
7513 int priority;
7514 {
7515 /* On machines (like the 750) which have asymetric integer units, where one
7516 integer unit can do multiply and divides and the other can't, reduce the
7517 priority of multiply/divide so it is scheduled before other integer
7518 operationss. */
7519
7520 #if 0
7521 if (! INSN_P (insn))
7522 return priority;
7523
7524 if (GET_CODE (PATTERN (insn)) == USE)
7525 return priority;
7526
7527 switch (rs6000_cpu_attr) {
7528 case CPU_PPC750:
7529 switch (get_attr_type (insn))
7530 {
7531 default:
7532 break;
7533
7534 case TYPE_IMUL:
7535 case TYPE_IDIV:
7536 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
7537 priority, priority);
7538 if (priority >= 0 && priority < 0x01000000)
7539 priority >>= 3;
7540 break;
7541 }
7542 }
7543 #endif
7544
7545 return priority;
7546 }
7547
7548 /* Return how many instructions the machine can issue per cycle */
7549 int get_issue_rate()
7550 {
7551 switch (rs6000_cpu_attr) {
7552 case CPU_RIOS1: /* ? */
7553 case CPU_RS64A:
7554 case CPU_PPC601: /* ? */
7555 return 3;
7556 case CPU_PPC603:
7557 case CPU_PPC750:
7558 return 2;
7559 case CPU_RIOS2:
7560 case CPU_PPC604:
7561 case CPU_PPC604E:
7562 case CPU_PPC620:
7563 case CPU_PPC630:
7564 return 4;
7565 default:
7566 return 1;
7567 }
7568 }
7569
7570 \f
7571 /* Length in units of the trampoline for entering a nested function. */
7572
7573 int
7574 rs6000_trampoline_size ()
7575 {
7576 int ret = 0;
7577
7578 switch (DEFAULT_ABI)
7579 {
7580 default:
7581 abort ();
7582
7583 case ABI_AIX:
7584 ret = (TARGET_32BIT) ? 12 : 24;
7585 break;
7586
7587 case ABI_V4:
7588 case ABI_SOLARIS:
7589 case ABI_AIX_NODESC:
7590 ret = (TARGET_32BIT) ? 40 : 48;
7591 break;
7592 }
7593
7594 return ret;
7595 }
7596
7597 /* Emit RTL insns to initialize the variable parts of a trampoline.
7598 FNADDR is an RTX for the address of the function's pure code.
7599 CXT is an RTX for the static chain value for the function. */
7600
7601 void
7602 rs6000_initialize_trampoline (addr, fnaddr, cxt)
7603 rtx addr;
7604 rtx fnaddr;
7605 rtx cxt;
7606 {
7607 enum machine_mode pmode = Pmode;
7608 int regsize = (TARGET_32BIT) ? 4 : 8;
7609 rtx ctx_reg = force_reg (pmode, cxt);
7610
7611 switch (DEFAULT_ABI)
7612 {
7613 default:
7614 abort ();
7615
7616 /* Macros to shorten the code expansions below. */
7617 #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
7618 #define MEM_PLUS(addr,offset) \
7619 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7620
7621 /* Under AIX, just build the 3 word function descriptor */
7622 case ABI_AIX:
7623 {
7624 rtx fn_reg = gen_reg_rtx (pmode);
7625 rtx toc_reg = gen_reg_rtx (pmode);
7626 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
7627 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
7628 emit_move_insn (MEM_DEREF (addr), fn_reg);
7629 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
7630 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
7631 }
7632 break;
7633
7634 /* Under V.4/eabi, call __trampoline_setup to do the real work. */
7635 case ABI_V4:
7636 case ABI_SOLARIS:
7637 case ABI_AIX_NODESC:
7638 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
7639 FALSE, VOIDmode, 4,
7640 addr, pmode,
7641 GEN_INT (rs6000_trampoline_size ()), SImode,
7642 fnaddr, pmode,
7643 ctx_reg, pmode);
7644 break;
7645 }
7646
7647 return;
7648 }
7649
7650 \f
7651 /* If defined, a C expression whose value is nonzero if IDENTIFIER
7652 with arguments ARGS is a valid machine specific attribute for DECL.
7653 The attributes in ATTRIBUTES have previously been assigned to DECL. */
7654
7655 int
7656 rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
7657 tree decl ATTRIBUTE_UNUSED;
7658 tree attributes ATTRIBUTE_UNUSED;
7659 tree identifier ATTRIBUTE_UNUSED;
7660 tree args ATTRIBUTE_UNUSED;
7661 {
7662 return 0;
7663 }
7664
7665 /* If defined, a C expression whose value is nonzero if IDENTIFIER
7666 with arguments ARGS is a valid machine specific attribute for TYPE.
7667 The attributes in ATTRIBUTES have previously been assigned to TYPE. */
7668
7669 int
7670 rs6000_valid_type_attribute_p (type, attributes, identifier, args)
7671 tree type;
7672 tree attributes ATTRIBUTE_UNUSED;
7673 tree identifier;
7674 tree args;
7675 {
7676 if (TREE_CODE (type) != FUNCTION_TYPE
7677 && TREE_CODE (type) != FIELD_DECL
7678 && TREE_CODE (type) != TYPE_DECL)
7679 return 0;
7680
7681 /* Longcall attribute says that the function is not within 2**26 bytes
7682 of the current function, and to do an indirect call. */
7683 if (is_attribute_p ("longcall", identifier))
7684 return (args == NULL_TREE);
7685
7686 return 0;
7687 }
7688
7689 /* If defined, a C expression whose value is zero if the attributes on
7690 TYPE1 and TYPE2 are incompatible, one if they are compatible, and
7691 two if they are nearly compatible (which causes a warning to be
7692 generated). */
7693
7694 int
7695 rs6000_comp_type_attributes (type1, type2)
7696 tree type1 ATTRIBUTE_UNUSED;
7697 tree type2 ATTRIBUTE_UNUSED;
7698 {
7699 return 1;
7700 }
7701
7702 /* If defined, a C statement that assigns default attributes to newly
7703 defined TYPE. */
7704
7705 void
7706 rs6000_set_default_type_attributes (type)
7707 tree type ATTRIBUTE_UNUSED;
7708 {
7709 return;
7710 }
7711
7712 /* Return a reference suitable for calling a function with the
7713 longcall attribute. */
7714 struct rtx_def *
7715 rs6000_longcall_ref (call_ref)
7716 rtx call_ref;
7717 {
7718 const char *call_name;
7719 tree node;
7720
7721 if (GET_CODE (call_ref) != SYMBOL_REF)
7722 return call_ref;
7723
7724 /* System V adds '.' to the internal name, so skip them. */
7725 call_name = XSTR (call_ref, 0);
7726 if (*call_name == '.')
7727 {
7728 while (*call_name == '.')
7729 call_name++;
7730
7731 node = get_identifier (call_name);
7732 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
7733 }
7734
7735 return force_reg (Pmode, call_ref);
7736 }
7737
7738 \f
7739 /* A C statement or statements to switch to the appropriate section
7740 for output of RTX in mode MODE. You can assume that RTX is some
7741 kind of constant in RTL. The argument MODE is redundant except in
7742 the case of a `const_int' rtx. Select the section by calling
7743 `text_section' or one of the alternatives for other sections.
7744
7745 Do not define this macro if you put all constants in the read-only
7746 data section. */
7747
7748 #ifdef USING_SVR4_H
7749
7750 void
7751 rs6000_select_rtx_section (mode, x)
7752 enum machine_mode mode;
7753 rtx x;
7754 {
7755 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7756 toc_section ();
7757 else
7758 const_section ();
7759 }
7760
7761 /* A C statement or statements to switch to the appropriate
7762 section for output of DECL. DECL is either a `VAR_DECL' node
7763 or a constant of some sort. RELOC indicates whether forming
7764 the initial value of DECL requires link-time relocations. */
7765
7766 void
7767 rs6000_select_section (decl, reloc)
7768 tree decl;
7769 int reloc;
7770 {
7771 int size = int_size_in_bytes (TREE_TYPE (decl));
7772 int needs_sdata;
7773 int readonly;
7774 static void (* const sec_funcs[4]) PARAMS ((void)) = {
7775 &const_section,
7776 &sdata2_section,
7777 &data_section,
7778 &sdata_section
7779 };
7780
7781 needs_sdata = (size > 0
7782 && size <= g_switch_value
7783 && rs6000_sdata != SDATA_NONE
7784 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7785
7786 if (TREE_CODE (decl) == STRING_CST)
7787 readonly = ! flag_writable_strings;
7788 else if (TREE_CODE (decl) == VAR_DECL)
7789 readonly = (! (flag_pic && reloc)
7790 && TREE_READONLY (decl)
7791 && ! TREE_SIDE_EFFECTS (decl)
7792 && DECL_INITIAL (decl)
7793 && DECL_INITIAL (decl) != error_mark_node
7794 && TREE_CONSTANT (DECL_INITIAL (decl)));
7795 else
7796 readonly = 1;
7797 if (needs_sdata && rs6000_sdata != SDATA_EABI)
7798 readonly = 0;
7799
7800 (*sec_funcs[(readonly ? 0 : 2) + (needs_sdata ? 1 : 0)])();
7801 }
7802
7803 /* A C statement to build up a unique section name, expressed as a
7804 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
7805 RELOC indicates whether the initial value of EXP requires
7806 link-time relocations. If you do not define this macro, GCC will use
7807 the symbol name prefixed by `.' as the section name. Note - this
7808 macro can now be called for unitialised data items as well as
7809 initialised data and functions. */
7810
7811 void
7812 rs6000_unique_section (decl, reloc)
7813 tree decl;
7814 int reloc;
7815 {
7816 int size = int_size_in_bytes (TREE_TYPE (decl));
7817 int needs_sdata;
7818 int readonly;
7819 int len;
7820 int sec;
7821 const char *name;
7822 char *string;
7823 const char *prefix;
7824
7825 static const char *const prefixes[7][2] =
7826 {
7827 { ".text.", ".gnu.linkonce.t." },
7828 { ".rodata.", ".gnu.linkonce.r." },
7829 { ".sdata2.", ".gnu.linkonce.s2." },
7830 { ".data.", ".gnu.linkonce.d." },
7831 { ".sdata.", ".gnu.linkonce.s." },
7832 { ".bss.", ".gnu.linkonce.b." },
7833 { ".sbss.", ".gnu.linkonce.sb." }
7834 };
7835
7836 needs_sdata = (TREE_CODE (decl) != FUNCTION_DECL
7837 && size > 0
7838 && size <= g_switch_value
7839 && rs6000_sdata != SDATA_NONE
7840 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)));
7841
7842 if (TREE_CODE (decl) == STRING_CST)
7843 readonly = ! flag_writable_strings;
7844 else if (TREE_CODE (decl) == VAR_DECL)
7845 readonly = (! (flag_pic && reloc)
7846 && TREE_READONLY (decl)
7847 && ! TREE_SIDE_EFFECTS (decl)
7848 && DECL_INITIAL (decl)
7849 && DECL_INITIAL (decl) != error_mark_node
7850 && TREE_CONSTANT (DECL_INITIAL (decl)));
7851 else
7852 readonly = 1;
7853 if (needs_sdata && rs6000_sdata != SDATA_EABI)
7854 readonly = 0;
7855
7856 sec = ((TREE_CODE (decl) == FUNCTION_DECL ? 0 : 1)
7857 + (readonly ? 0 : 2)
7858 + (needs_sdata ? 1 : 0)
7859 + (DECL_INITIAL (decl) == 0
7860 || DECL_INITIAL (decl) == error_mark_node) ? 4 : 0);
7861
7862 STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7863 prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
7864 len = strlen (name) + strlen (prefix);
7865 string = alloca (len + 1);
7866
7867 sprintf (string, "%s%s", prefix, name);
7868
7869 DECL_SECTION_NAME (decl) = build_string (len, string);
7870 }
7871
7872 \f
7873 /* If we are referencing a function that is static or is known to be
7874 in this file, make the SYMBOL_REF special. We can use this to indicate
7875 that we can branch to this function without emitting a no-op after the
7876 call. For real AIX calling sequences, we also replace the
7877 function name with the real name (1 or 2 leading .'s), rather than
7878 the function descriptor name. This saves a lot of overriding code
7879 to read the prefixes. */
7880
7881 void
7882 rs6000_encode_section_info (decl)
7883 tree decl;
7884 {
7885 if (TREE_CODE (decl) == FUNCTION_DECL)
7886 {
7887 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
7888 if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
7889 && ! DECL_WEAK (decl))
7890 SYMBOL_REF_FLAG (sym_ref) = 1;
7891
7892 if (DEFAULT_ABI == ABI_AIX)
7893 {
7894 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
7895 size_t len2 = strlen (XSTR (sym_ref, 0));
7896 char *str = alloca (len1 + len2 + 1);
7897 str[0] = '.';
7898 str[1] = '.';
7899 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
7900
7901 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
7902 }
7903 }
7904 else if (rs6000_sdata != SDATA_NONE
7905 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
7906 && TREE_CODE (decl) == VAR_DECL)
7907 {
7908 int size = int_size_in_bytes (TREE_TYPE (decl));
7909 tree section_name = DECL_SECTION_NAME (decl);
7910 const char *name = (char *)0;
7911 int len = 0;
7912
7913 if (section_name)
7914 {
7915 if (TREE_CODE (section_name) == STRING_CST)
7916 {
7917 name = TREE_STRING_POINTER (section_name);
7918 len = TREE_STRING_LENGTH (section_name);
7919 }
7920 else
7921 abort ();
7922 }
7923
7924 if ((size > 0 && size <= g_switch_value)
7925 || (name
7926 && ((len == sizeof (".sdata") - 1
7927 && strcmp (name, ".sdata") == 0)
7928 || (len == sizeof (".sdata2") - 1
7929 && strcmp (name, ".sdata2") == 0)
7930 || (len == sizeof (".sbss") - 1
7931 && strcmp (name, ".sbss") == 0)
7932 || (len == sizeof (".sbss2") - 1
7933 && strcmp (name, ".sbss2") == 0)
7934 || (len == sizeof (".PPC.EMB.sdata0") - 1
7935 && strcmp (name, ".PPC.EMB.sdata0") == 0)
7936 || (len == sizeof (".PPC.EMB.sbss0") - 1
7937 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
7938 {
7939 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
7940 size_t len = strlen (XSTR (sym_ref, 0));
7941 char *str = alloca (len + 2);
7942
7943 str[0] = '@';
7944 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
7945 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
7946 }
7947 }
7948 }
7949
7950 #endif /* USING_SVR4_H */
7951
7952 \f
7953 /* Return a REG that occurs in ADDR with coefficient 1.
7954 ADDR can be effectively incremented by incrementing REG.
7955
7956 r0 is special and we must not select it as an address
7957 register by this routine since our caller will try to
7958 increment the returned register via an "la" instruction. */
7959
7960 struct rtx_def *
7961 find_addr_reg (addr)
7962 rtx addr;
7963 {
7964 while (GET_CODE (addr) == PLUS)
7965 {
7966 if (GET_CODE (XEXP (addr, 0)) == REG
7967 && REGNO (XEXP (addr, 0)) != 0)
7968 addr = XEXP (addr, 0);
7969 else if (GET_CODE (XEXP (addr, 1)) == REG
7970 && REGNO (XEXP (addr, 1)) != 0)
7971 addr = XEXP (addr, 1);
7972 else if (CONSTANT_P (XEXP (addr, 0)))
7973 addr = XEXP (addr, 1);
7974 else if (CONSTANT_P (XEXP (addr, 1)))
7975 addr = XEXP (addr, 0);
7976 else
7977 abort ();
7978 }
7979 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
7980 return addr;
7981 abort ();
7982 }
7983
7984 void
7985 rs6000_fatal_bad_address (op)
7986 rtx op;
7987 {
7988 fatal_insn ("bad address", op);
7989 }
7990
7991 /* Called to register all of our global variables with the garbage
7992 collector. */
7993
7994 static void
7995 rs6000_add_gc_roots ()
7996 {
7997 ggc_add_rtx_root (&rs6000_compare_op0, 1);
7998 ggc_add_rtx_root (&rs6000_compare_op1, 1);
7999
8000 toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL);
8001 ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table),
8002 toc_hash_mark_table);
8003
8004 #if TARGET_MACHO
8005 machopic_add_gc_roots ();
8006 #endif
8007 }
8008
8009 #if TARGET_MACHO
8010
8011 #if 0
8012 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
8013 reference and a constant. */
8014
8015 int
8016 symbolic_operand (op)
8017 register rtx op;
8018 {
8019 switch (GET_CODE (op))
8020 {
8021 case SYMBOL_REF:
8022 case LABEL_REF:
8023 return 1;
8024 case CONST:
8025 op = XEXP (op, 0);
8026 return (GET_CODE (op) == SYMBOL_REF ||
8027 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
8028 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
8029 && GET_CODE (XEXP (op, 1)) == CONST_INT);
8030 default:
8031 return 0;
8032 }
8033 }
8034 #endif
8035
8036 #ifdef RS6000_LONG_BRANCH
8037
8038 static tree stub_list = 0;
8039
8040 /* ADD_COMPILER_STUB adds the compiler generated stub for handling
8041 procedure calls to the linked list. */
8042
8043 void
8044 add_compiler_stub (label_name, function_name, line_number)
8045 tree label_name;
8046 tree function_name;
8047 int line_number;
8048 {
8049 tree stub = build_tree_list (function_name, label_name);
8050 TREE_TYPE (stub) = build_int_2 (line_number, 0);
8051 TREE_CHAIN (stub) = stub_list;
8052 stub_list = stub;
8053 }
8054
8055 #define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
8056 #define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
8057 #define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
8058
8059 /* OUTPUT_COMPILER_STUB outputs the compiler generated stub for handling
8060 procedure calls from the linked list and initializes the linked list. */
8061
8062 void output_compiler_stub ()
8063 {
8064 char tmp_buf[256];
8065 char label_buf[256];
8066 char *label;
8067 tree tmp_stub, stub;
8068
8069 if (!flag_pic)
8070 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
8071 {
8072 fprintf (asm_out_file,
8073 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
8074
8075 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
8076 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
8077 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
8078 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
8079
8080 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
8081 strcpy (label_buf,
8082 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
8083 else
8084 {
8085 label_buf[0] = '_';
8086 strcpy (label_buf+1,
8087 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
8088 }
8089
8090 strcpy (tmp_buf, "lis r12,hi16(");
8091 strcat (tmp_buf, label_buf);
8092 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
8093 strcat (tmp_buf, label_buf);
8094 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
8095 output_asm_insn (tmp_buf, 0);
8096
8097 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
8098 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
8099 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
8100 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
8101 }
8102
8103 stub_list = 0;
8104 }
8105
8106 /* NO_PREVIOUS_DEF checks in the link list whether the function name is
8107 already there or not. */
8108
8109 int no_previous_def (function_name)
8110 tree function_name;
8111 {
8112 tree stub;
8113 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
8114 if (function_name == STUB_FUNCTION_NAME (stub))
8115 return 0;
8116 return 1;
8117 }
8118
8119 /* GET_PREV_LABEL gets the label name from the previous definition of
8120 the function. */
8121
8122 tree get_prev_label (function_name)
8123 tree function_name;
8124 {
8125 tree stub;
8126 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
8127 if (function_name == STUB_FUNCTION_NAME (stub))
8128 return STUB_LABEL_NAME (stub);
8129 return 0;
8130 }
8131
8132 /* INSN is either a function call or a millicode call. It may have an
8133 unconditional jump in its delay slot.
8134
8135 CALL_DEST is the routine we are calling. */
8136
8137 char *
8138 output_call (insn, call_dest, operand_number)
8139 rtx insn;
8140 rtx call_dest;
8141 int operand_number;
8142 {
8143 static char buf[256];
8144 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
8145 {
8146 tree labelname;
8147 tree funname = get_identifier (XSTR (call_dest, 0));
8148
8149 if (no_previous_def (funname))
8150 {
8151 int line_number;
8152 rtx label_rtx = gen_label_rtx ();
8153 char *label_buf, temp_buf[256];
8154 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
8155 CODE_LABEL_NUMBER (label_rtx));
8156 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
8157 labelname = get_identifier (label_buf);
8158 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
8159 if (insn)
8160 line_number = NOTE_LINE_NUMBER (insn);
8161 add_compiler_stub (labelname, funname, line_number);
8162 }
8163 else
8164 labelname = get_prev_label (funname);
8165
8166 sprintf (buf, "jbsr %%z%d,%.246s",
8167 operand_number, IDENTIFIER_POINTER (labelname));
8168 return buf;
8169 }
8170 else
8171 {
8172 sprintf (buf, "bl %%z%d", operand_number);
8173 return buf;
8174 }
8175 }
8176
8177 #endif /* RS6000_LONG_BRANCH */
8178
8179 #define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
8180 do { \
8181 const char *symbol_ = (SYMBOL); \
8182 char *buffer_ = (BUF); \
8183 if (symbol_[0] == '"') \
8184 { \
8185 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
8186 } \
8187 else if (name_needs_quotes(symbol_)) \
8188 { \
8189 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
8190 } \
8191 else \
8192 { \
8193 sprintf(buffer_, "L%d$%s", (N), symbol_); \
8194 } \
8195 } while (0)
8196
8197
8198 /* Generate PIC and indirect symbol stubs. */
8199
8200 void
8201 machopic_output_stub (file, symb, stub)
8202 FILE *file;
8203 const char *symb, *stub;
8204 {
8205 unsigned int length;
8206 char *binder_name, *symbol_name, *lazy_ptr_name;
8207 char *local_label_0, *local_label_1, *local_label_2;
8208 static int label = 0;
8209
8210 label += 1;
8211
8212 length = strlen (stub);
8213 binder_name = alloca (length + 32);
8214 GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
8215
8216 length = strlen (symb);
8217 symbol_name = alloca (length + 32);
8218 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
8219
8220 lazy_ptr_name = alloca (length + 32);
8221 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
8222
8223 local_label_0 = alloca (length + 32);
8224 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
8225
8226 local_label_1 = alloca (length + 32);
8227 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_1, symb, length, 1);
8228
8229 local_label_2 = alloca (length + 32);
8230 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_2, symb, length, 2);
8231
8232 if (flag_pic == 2)
8233 machopic_picsymbol_stub_section ();
8234 else
8235 machopic_symbol_stub_section ();
8236
8237 fprintf (file, "%s:\n", stub);
8238 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
8239
8240 if (flag_pic == 2)
8241 {
8242 fprintf (file, "\tmflr r0\n");
8243 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
8244 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
8245 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
8246 lazy_ptr_name, local_label_0);
8247 fprintf (file, "\tmtlr r0\n");
8248 fprintf (file, "\tlwz r12,lo16(%s-%s)(r11)\n",
8249 lazy_ptr_name, local_label_0);
8250 fprintf (file, "\tmtctr r12\n");
8251 fprintf (file, "\taddi r11,r11,lo16(%s-%s)\n",
8252 lazy_ptr_name, local_label_0);
8253 fprintf (file, "\tbctr\n");
8254 }
8255 else
8256 fprintf (file, "non-pure not supported\n");
8257
8258 machopic_lazy_symbol_ptr_section ();
8259 fprintf (file, "%s:\n", lazy_ptr_name);
8260 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
8261 fprintf (file, "\t.long dyld_stub_binding_helper\n");
8262 }
8263
8264 /* Legitimize PIC addresses. If the address is already
8265 position-independent, we return ORIG. Newly generated
8266 position-independent addresses go into a reg. This is REG if non
8267 zero, otherwise we allocate register(s) as necessary. */
8268
8269 #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x4000) < 0x8000)
8270
8271 rtx
8272 rs6000_machopic_legitimize_pic_address (orig, mode, reg)
8273 rtx orig;
8274 enum machine_mode mode;
8275 rtx reg;
8276 {
8277 rtx base, offset;
8278
8279 if (reg == NULL && ! reload_in_progress && ! reload_completed)
8280 reg = gen_reg_rtx (Pmode);
8281
8282 if (GET_CODE (orig) == CONST)
8283 {
8284 if (GET_CODE (XEXP (orig, 0)) == PLUS
8285 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
8286 return orig;
8287
8288 if (GET_CODE (XEXP (orig, 0)) == PLUS)
8289 {
8290 base = rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
8291 Pmode, reg);
8292 offset = rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
8293 Pmode, reg);
8294 }
8295 else
8296 abort ();
8297
8298 if (GET_CODE (offset) == CONST_INT)
8299 {
8300 if (SMALL_INT (offset))
8301 return plus_constant_for_output (base, INTVAL (offset));
8302 else if (! reload_in_progress && ! reload_completed)
8303 offset = force_reg (Pmode, offset);
8304 else
8305 abort ();
8306 }
8307 return gen_rtx (PLUS, Pmode, base, offset);
8308 }
8309
8310 /* Fall back on generic machopic code. */
8311 return machopic_legitimize_pic_address (orig, mode, reg);
8312 }
8313
8314 /* This is just a placeholder to make linking work without having to
8315 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
8316 ever needed for Darwin (not too likely!) this would have to get a
8317 real definition. */
8318
8319 void
8320 toc_section ()
8321 {
8322 }
8323
8324 #endif /* TARGET_MACHO */