]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
(STARTFILE_SPEC, LIB_SPEC): Define.
[thirdparty/gcc.git] / gcc / config / rs6000 / rs6000.c
CommitLineData
9878760c 1/* Subroutines used for code generation on IBM RS/6000.
fab3bcc3
RK
2 Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
9878760c
RK
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#include <stdio.h>
22#include "config.h"
23#include "rtl.h"
24#include "regs.h"
25#include "hard-reg-set.h"
26#include "real.h"
27#include "insn-config.h"
28#include "conditions.h"
29#include "insn-flags.h"
30#include "output.h"
31#include "insn-attr.h"
32#include "flags.h"
33#include "recog.h"
34#include "expr.h"
35#include "obstack.h"
9b30bae2
JW
36#include "tree.h"
37
38extern char *language_string;
5248c961 39extern int profile_block_flag;
9878760c
RK
40
41#define min(A,B) ((A) < (B) ? (A) : (B))
42#define max(A,B) ((A) > (B) ? (A) : (B))
43
5248c961
RK
44/* Target cpu type */
45
46enum processor_type rs6000_cpu;
47char *rs6000_cpu_string;
48
9878760c
RK
49/* Set to non-zero by "fix" operation to indicate that itrunc and
50 uitrunc must be defined. */
51
52int rs6000_trunc_used;
53
54/* Set to non-zero once they have been defined. */
55
56static int trunc_defined;
57
c764f757
RK
58/* Set to non-zero once AIX common-mode calls have been defined. */
59static int common_mode_defined;
9878760c
RK
60/* Save information from a "cmpxx" operation until the branch or scc is
61 emitted. */
62
63rtx rs6000_compare_op0, rs6000_compare_op1;
64int rs6000_compare_fp_p;
65\f
5248c961
RK
66/* Override command line options. Mostly we process the processor
67 type and sometimes adjust other TARGET_ options. */
68
69void
70rs6000_override_options ()
71{
72 int i;
73
85638c0d
RK
74 /* Simplify the entries below by making a mask for any POWER
75 variant and any PowerPC variant. */
76
77#define POWER_MASKS (MASK_POWER | MASK_POWER2)
fab3bcc3 78#define POWERPC_MASKS (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64)
85638c0d 79
5248c961
RK
80 static struct ptt
81 {
82 char *name; /* Canonical processor name. */
83 enum processor_type processor; /* Processor type enum value. */
84 int target_enable; /* Target flags to enable. */
85 int target_disable; /* Target flags to disable. */
86 } processor_target_table[]
db7f1e43
RK
87 = {{"common", PROCESSOR_COMMON, 0, POWER_MASKS | POWERPC_MASKS},
88 {"power", PROCESSOR_POWER,
89 MASK_POWER,
90 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
91 {"powerpc", PROCESSOR_POWERPC,
92 MASK_POWERPC | MASK_NEW_MNEMONICS,
93 POWER_MASKS | MASK_PPCFPX | MASK_POWERPC64},
94 {"rios", PROCESSOR_RIOS1,
95 MASK_POWER,
96 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
97 {"rios1", PROCESSOR_RIOS1,
98 MASK_POWER,
99 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
100 {"rsc", PROCESSOR_PPC601,
101 MASK_POWER,
102 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
103 {"rsc1", PROCESSOR_PPC601,
104 MASK_POWER,
105 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
106 {"rios2", PROCESSOR_RIOS2,
107 MASK_POWER | MASK_POWER2,
108 POWERPC_MASKS | MASK_NEW_MNEMONICS},
5248c961 109 {"601", PROCESSOR_PPC601,
85638c0d 110 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
fab3bcc3 111 MASK_POWER2 | MASK_PPCFPX | MASK_POWERPC64},
49947f18 112 {"mpc601", PROCESSOR_PPC601,
85638c0d 113 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
fab3bcc3 114 MASK_POWER2 | MASK_PPCFPX | MASK_POWERPC64},
85638c0d
RK
115 {"ppc601", PROCESSOR_PPC601,
116 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
fab3bcc3 117 MASK_POWER2 | MASK_PPCFPX | MASK_POWERPC64},
5248c961 118 {"603", PROCESSOR_PPC603,
fab3bcc3 119 MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS,
85638c0d 120 POWER_MASKS | MASK_POWERPC64},
49947f18 121 {"mpc603", PROCESSOR_PPC603,
fab3bcc3 122 MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS,
85638c0d
RK
123 POWER_MASKS | MASK_POWERPC64},
124 {"ppc603", PROCESSOR_PPC603,
fab3bcc3 125 MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS,
85638c0d 126 POWER_MASKS | MASK_POWERPC64},
5248c961 127 {"604", PROCESSOR_PPC604,
fab3bcc3 128 MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS,
85638c0d 129 POWER_MASKS | MASK_POWERPC64},
49947f18 130 {"mpc604", PROCESSOR_PPC604,
fab3bcc3 131 MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS,
85638c0d
RK
132 POWER_MASKS | MASK_POWERPC64},
133 {"ppc604", PROCESSOR_PPC604,
fab3bcc3 134 MASK_POWERPC | MASK_PPCFPX | MASK_NEW_MNEMONICS,
85638c0d 135 POWER_MASKS | MASK_POWERPC64},
5248c961 136 {"620", PROCESSOR_PPC620,
fab3bcc3 137 (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64
85638c0d
RK
138 | MASK_NEW_MNEMONICS),
139 POWER_MASKS},
49947f18 140 {"mpc620", PROCESSOR_PPC620,
fab3bcc3 141 (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64
85638c0d
RK
142 | MASK_NEW_MNEMONICS),
143 POWER_MASKS},
144 {"ppc620", PROCESSOR_PPC620,
fab3bcc3 145 (MASK_POWERPC | MASK_PPCFPX | MASK_POWERPC64
85638c0d
RK
146 | MASK_NEW_MNEMONICS),
147 POWER_MASKS}};
5248c961
RK
148
149 int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
150
151 profile_block_flag = 0;
152
153 /* Identify the processor type */
154 if (rs6000_cpu_string == 0)
155 rs6000_cpu = PROCESSOR_DEFAULT;
156 else
157 {
158 for (i = 0; i < ptt_size; i++)
159 if (! strcmp (rs6000_cpu_string, processor_target_table[i].name))
160 {
161 rs6000_cpu = processor_target_table[i].processor;
162 target_flags |= processor_target_table[i].target_enable;
163 target_flags &= ~processor_target_table[i].target_disable;
164 break;
165 }
166
167 if (i == ptt_size)
168 {
169 error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string);
170 rs6000_cpu_string = "default";
171 rs6000_cpu = PROCESSOR_DEFAULT;
172 }
173 }
174}
175\f
9878760c
RK
176/* Return non-zero if this function is known to have a null epilogue. */
177
178int
179direct_return ()
180{
181 return (reload_completed
182 && first_reg_to_save () == 32
183 && first_fp_reg_to_save () == 64
184 && ! regs_ever_live[65]
185 && ! rs6000_pushes_stack ());
186}
187
188/* Returns 1 always. */
189
190int
191any_operand (op, mode)
192 register rtx op;
193 enum machine_mode mode;
194{
195 return 1;
196}
197
198/* Return 1 if OP is a constant that can fit in a D field. */
199
200int
201short_cint_operand (op, mode)
202 register rtx op;
203 enum machine_mode mode;
204{
205 return (GET_CODE (op) == CONST_INT
206 && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
207}
208
209/* Similar for a unsigned D field. */
210
211int
212u_short_cint_operand (op, mode)
213 register rtx op;
214 enum machine_mode mode;
215{
216 return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
217}
218
dcfedcd0
RK
219/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
220
221int
222non_short_cint_operand (op, mode)
223 register rtx op;
224 enum machine_mode mode;
225{
226 return (GET_CODE (op) == CONST_INT
227 && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
228}
229
9878760c
RK
230/* Returns 1 if OP is a register that is not special (i.e., not MQ,
231 ctr, or lr). */
232
233int
cd2b37d9 234gpc_reg_operand (op, mode)
9878760c
RK
235 register rtx op;
236 enum machine_mode mode;
237{
238 return (register_operand (op, mode)
239 && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
240}
241
242/* Returns 1 if OP is either a pseudo-register or a register denoting a
243 CR field. */
244
245int
246cc_reg_operand (op, mode)
247 register rtx op;
248 enum machine_mode mode;
249{
250 return (register_operand (op, mode)
251 && (GET_CODE (op) != REG
252 || REGNO (op) >= FIRST_PSEUDO_REGISTER
253 || CR_REGNO_P (REGNO (op))));
254}
255
256/* Returns 1 if OP is either a constant integer valid for a D-field or a
257 non-special register. If a register, it must be in the proper mode unless
258 MODE is VOIDmode. */
259
260int
261reg_or_short_operand (op, mode)
262 register rtx op;
263 enum machine_mode mode;
264{
f5a28898 265 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
266}
267
268/* Similar, except check if the negation of the constant would be valid for
269 a D-field. */
270
271int
272reg_or_neg_short_operand (op, mode)
273 register rtx op;
274 enum machine_mode mode;
275{
276 if (GET_CODE (op) == CONST_INT)
277 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
278
cd2b37d9 279 return gpc_reg_operand (op, mode);
9878760c
RK
280}
281
282/* Return 1 if the operand is either a register or an integer whose high-order
283 16 bits are zero. */
284
285int
286reg_or_u_short_operand (op, mode)
287 register rtx op;
288 enum machine_mode mode;
289{
290 if (GET_CODE (op) == CONST_INT
291 && (INTVAL (op) & 0xffff0000) == 0)
292 return 1;
293
cd2b37d9 294 return gpc_reg_operand (op, mode);
9878760c
RK
295}
296
297/* Return 1 is the operand is either a non-special register or ANY
298 constant integer. */
299
300int
301reg_or_cint_operand (op, mode)
302 register rtx op;
303 enum machine_mode mode;
304{
cd2b37d9 305 return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
9878760c
RK
306}
307
6f2f8311
RK
308/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
309 with one instruction per word. We only do this if we can safely read
310 CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
311
312int
313easy_fp_constant (op, mode)
314 register rtx op;
315 register enum machine_mode mode;
316{
317 rtx low, high;
318
319 if (GET_CODE (op) != CONST_DOUBLE
320 || GET_MODE (op) != mode
321 || GET_MODE_CLASS (mode) != MODE_FLOAT)
322 return 0;
323
324 high = operand_subword (op, 0, 0, mode);
325 low = operand_subword (op, 1, 0, mode);
326
6f2f8311 327 if (high == 0 || ! input_operand (high, word_mode))
9878760c
RK
328 return 0;
329
330 return (mode == SFmode
6f2f8311 331 || (low != 0 && input_operand (low, word_mode)));
9878760c
RK
332}
333
334/* Return 1 if the operand is either a floating-point register, a pseudo
335 register, or memory. */
336
337int
338fp_reg_or_mem_operand (op, mode)
339 register rtx op;
340 enum machine_mode mode;
341{
342 return (memory_operand (op, mode)
343 || (register_operand (op, mode)
344 && (GET_CODE (op) != REG
345 || REGNO (op) >= FIRST_PSEUDO_REGISTER
346 || FP_REGNO_P (REGNO (op)))));
347}
348
349/* Return 1 if the operand is either an easy FP constant (see above) or
350 memory. */
351
352int
353mem_or_easy_const_operand (op, mode)
354 register rtx op;
355 enum machine_mode mode;
356{
357 return memory_operand (op, mode) || easy_fp_constant (op, mode);
358}
359
360/* Return 1 if the operand is either a non-special register or an item
361 that can be used as the operand of an SI add insn. */
362
363int
364add_operand (op, mode)
365 register rtx op;
366 enum machine_mode mode;
367{
368 return (reg_or_short_operand (op, mode)
369 || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
370}
371
dcfedcd0
RK
372/* Return 1 if OP is a constant but not a valid add_operand. */
373
374int
375non_add_cint_operand (op, mode)
376 register rtx op;
377 enum machine_mode mode;
378{
379 return (GET_CODE (op) == CONST_INT
380 && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
381 && (INTVAL (op) & 0xffff) != 0);
382}
383
9878760c
RK
384/* Return 1 if the operand is a non-special register or a constant that
385 can be used as the operand of an OR or XOR insn on the RS/6000. */
386
387int
388logical_operand (op, mode)
389 register rtx op;
390 enum machine_mode mode;
391{
cd2b37d9 392 return (gpc_reg_operand (op, mode)
9878760c
RK
393 || (GET_CODE (op) == CONST_INT
394 && ((INTVAL (op) & 0xffff0000) == 0
395 || (INTVAL (op) & 0xffff) == 0)));
396}
397
dcfedcd0
RK
398/* Return 1 if C is a constant that is not a logical operand (as
399 above). */
400
401int
402non_logical_cint_operand (op, mode)
403 register rtx op;
404 enum machine_mode mode;
405{
406 return (GET_CODE (op) == CONST_INT
407 && (INTVAL (op) & 0xffff0000) != 0
408 && (INTVAL (op) & 0xffff) != 0);
409}
410
9878760c
RK
411/* Return 1 if C is a constant that can be encoded in a mask on the
412 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
413 Reject all ones and all zeros, since these should have been optimized
414 away and confuse the making of MB and ME. */
415
416int
417mask_constant (c)
418 register int c;
419{
420 int i;
421 int last_bit_value;
422 int transitions = 0;
423
424 if (c == 0 || c == ~0)
425 return 0;
426
427 last_bit_value = c & 1;
428
429 for (i = 1; i < 32; i++)
430 if (((c >>= 1) & 1) != last_bit_value)
431 last_bit_value ^= 1, transitions++;
432
433 return transitions <= 2;
434}
435
436/* Return 1 if the operand is a constant that is a mask on the RS/6000. */
437
438int
439mask_operand (op, mode)
440 register rtx op;
441 enum machine_mode mode;
442{
443 return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
444}
445
446/* Return 1 if the operand is either a non-special register or a
447 constant that can be used as the operand of an RS/6000 logical AND insn. */
448
449int
450and_operand (op, mode)
451 register rtx op;
452 enum machine_mode mode;
453{
454 return (reg_or_short_operand (op, mode)
455 || logical_operand (op, mode)
456 || mask_operand (op, mode));
457}
458
dcfedcd0
RK
459/* Return 1 if the operand is a constant but not a valid operand for an AND
460 insn. */
461
462int
463non_and_cint_operand (op, mode)
464 register rtx op;
465 enum machine_mode mode;
466{
467 return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
468}
469
9878760c
RK
470/* Return 1 if the operand is a general register or memory operand. */
471
472int
473reg_or_mem_operand (op, mode)
474 register rtx op;
475 register enum machine_mode mode;
476{
cd2b37d9 477 return gpc_reg_operand (op, mode) || memory_operand (op, mode);
9878760c
RK
478}
479
480/* Return 1 if the operand, used inside a MEM, is a valid first argument
481 to CALL. This is a SYMBOL_REF or a pseudo-register, which will be
482 forced to lr. */
483
484int
485call_operand (op, mode)
486 register rtx op;
487 enum machine_mode mode;
488{
489 if (mode != VOIDmode && GET_MODE (op) != mode)
490 return 0;
491
492 return (GET_CODE (op) == SYMBOL_REF
493 || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
494}
495
2af3d377
RK
496
497/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
498 this file. */
499
500int
501current_file_function_operand (op, mode)
502 register rtx op;
503 enum machine_mode mode;
504{
505 return (GET_CODE (op) == SYMBOL_REF
506 && (SYMBOL_REF_FLAG (op)
507 || op == XEXP (DECL_RTL (current_function_decl), 0)));
508}
509
510
9878760c
RK
511/* Return 1 if this operand is a valid input for a move insn. */
512
513int
514input_operand (op, mode)
515 register rtx op;
516 enum machine_mode mode;
517{
eb4e8003 518 /* Memory is always valid. */
9878760c
RK
519 if (memory_operand (op, mode))
520 return 1;
521
eb4e8003
RK
522 /* For floating-point, easy constants are valid. */
523 if (GET_MODE_CLASS (mode) == MODE_FLOAT
524 && CONSTANT_P (op)
525 && easy_fp_constant (op, mode))
526 return 1;
527
528 /* For floating-point or multi-word mode, the only remaining valid type
529 is a register. */
9878760c
RK
530 if (GET_MODE_CLASS (mode) == MODE_FLOAT
531 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 532 return register_operand (op, mode);
9878760c 533
88fe15a1
RK
534 /* The only cases left are integral modes one word or smaller (we
535 do not get called for MODE_CC values). These can be in any
536 register. */
537 if (register_operand (op, mode))
a8b3aeda 538 return 1;
88fe15a1
RK
539
540 /* For HImode and QImode, any constant is valid. */
541 if ((mode == HImode || mode == QImode)
542 && GET_CODE (op) == CONST_INT)
9878760c
RK
543 return 1;
544
9878760c
RK
545 /* Otherwise, we will be doing this SET with an add, so anything valid
546 for an add will be valid. */
547 return add_operand (op, mode);
548}
549\f
550/* Return 1 if OP is a load multiple operation. It is known to be a
551 PARALLEL and the first section will be tested. */
552
553int
554load_multiple_operation (op, mode)
555 rtx op;
556 enum machine_mode mode;
557{
558 int count = XVECLEN (op, 0);
559 int dest_regno;
560 rtx src_addr;
561 int i;
562
563 /* Perform a quick check so we don't blow up below. */
564 if (count <= 1
565 || GET_CODE (XVECEXP (op, 0, 0)) != SET
566 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
567 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
568 return 0;
569
570 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
571 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
572
573 for (i = 1; i < count; i++)
574 {
575 rtx elt = XVECEXP (op, 0, i);
576
577 if (GET_CODE (elt) != SET
578 || GET_CODE (SET_DEST (elt)) != REG
579 || GET_MODE (SET_DEST (elt)) != SImode
580 || REGNO (SET_DEST (elt)) != dest_regno + i
581 || GET_CODE (SET_SRC (elt)) != MEM
582 || GET_MODE (SET_SRC (elt)) != SImode
583 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
584 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
585 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
586 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
587 return 0;
588 }
589
590 return 1;
591}
592
593/* Similar, but tests for store multiple. Here, the second vector element
594 is a CLOBBER. It will be tested later. */
595
596int
597store_multiple_operation (op, mode)
598 rtx op;
599 enum machine_mode mode;
600{
601 int count = XVECLEN (op, 0) - 1;
602 int src_regno;
603 rtx dest_addr;
604 int i;
605
606 /* Perform a quick check so we don't blow up below. */
607 if (count <= 1
608 || GET_CODE (XVECEXP (op, 0, 0)) != SET
609 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
610 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
611 return 0;
612
613 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
614 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
615
616 for (i = 1; i < count; i++)
617 {
618 rtx elt = XVECEXP (op, 0, i + 1);
619
620 if (GET_CODE (elt) != SET
621 || GET_CODE (SET_SRC (elt)) != REG
622 || GET_MODE (SET_SRC (elt)) != SImode
623 || REGNO (SET_SRC (elt)) != src_regno + i
624 || GET_CODE (SET_DEST (elt)) != MEM
625 || GET_MODE (SET_DEST (elt)) != SImode
626 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
627 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
628 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
629 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
630 return 0;
631 }
632
633 return 1;
634}
635\f
636/* Return 1 if OP is a comparison operation that is valid for a branch insn.
637 We only check the opcode against the mode of the CC value here. */
638
639int
640branch_comparison_operator (op, mode)
641 register rtx op;
642 enum machine_mode mode;
643{
644 enum rtx_code code = GET_CODE (op);
645 enum machine_mode cc_mode;
646
647 if (GET_RTX_CLASS (code) != '<')
648 return 0;
649
650 cc_mode = GET_MODE (XEXP (op, 0));
651 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
652 return 0;
653
654 if ((code == GT || code == LT || code == GE || code == LE)
655 && cc_mode == CCUNSmode)
656 return 0;
657
658 if ((code == GTU || code == LTU || code == GEU || code == LEU)
659 && (cc_mode != CCUNSmode))
660 return 0;
661
662 return 1;
663}
664
665/* Return 1 if OP is a comparison operation that is valid for an scc insn.
666 We check the opcode against the mode of the CC value and disallow EQ or
667 NE comparisons for integers. */
668
669int
670scc_comparison_operator (op, mode)
671 register rtx op;
672 enum machine_mode mode;
673{
674 enum rtx_code code = GET_CODE (op);
675 enum machine_mode cc_mode;
676
677 if (GET_MODE (op) != mode && mode != VOIDmode)
678 return 0;
679
680 if (GET_RTX_CLASS (code) != '<')
681 return 0;
682
683 cc_mode = GET_MODE (XEXP (op, 0));
684 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
685 return 0;
686
687 if (code == NE && cc_mode != CCFPmode)
688 return 0;
689
690 if ((code == GT || code == LT || code == GE || code == LE)
691 && cc_mode == CCUNSmode)
692 return 0;
693
694 if ((code == GTU || code == LTU || code == GEU || code == LEU)
695 && (cc_mode != CCUNSmode))
696 return 0;
697
c5defebb
RK
698 if (cc_mode == CCEQmode && code != EQ && code != NE)
699 return 0;
700
9878760c
RK
701 return 1;
702}
703\f
704/* Return 1 if ANDOP is a mask that has no bits on that are not in the
705 mask required to convert the result of a rotate insn into a shift
706 left insn of SHIFTOP bits. Both are known to be CONST_INT. */
707
708int
709includes_lshift_p (shiftop, andop)
710 register rtx shiftop;
711 register rtx andop;
712{
713 int shift_mask = (~0 << INTVAL (shiftop));
714
715 return (INTVAL (andop) & ~shift_mask) == 0;
716}
717
718/* Similar, but for right shift. */
719
720int
721includes_rshift_p (shiftop, andop)
722 register rtx shiftop;
723 register rtx andop;
724{
725 unsigned shift_mask = ~0;
726
727 shift_mask >>= INTVAL (shiftop);
728
729 return (INTVAL (andop) & ~ shift_mask) == 0;
730}
731\f
732/* Return the register class of a scratch register needed to copy IN into
733 or out of a register in CLASS in MODE. If it can be done directly,
734 NO_REGS is returned. */
735
736enum reg_class
737secondary_reload_class (class, mode, in)
738 enum reg_class class;
739 enum machine_mode mode;
740 rtx in;
741{
742 int regno = true_regnum (in);
743
744 if (regno >= FIRST_PSEUDO_REGISTER)
745 regno = -1;
746
747 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
748 into anything. */
749 if (class == GENERAL_REGS || class == BASE_REGS
750 || (regno >= 0 && INT_REGNO_P (regno)))
751 return NO_REGS;
752
753 /* Constants, memory, and FP registers can go into FP registers. */
754 if ((regno == -1 || FP_REGNO_P (regno))
755 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
756 return NO_REGS;
757
758 /* We can copy among the CR registers. */
759 if ((class == CR_REGS || class == CR0_REGS)
760 && regno >= 0 && CR_REGNO_P (regno))
761 return NO_REGS;
762
763 /* Otherwise, we need GENERAL_REGS. */
764 return GENERAL_REGS;
765}
766\f
767/* Given a comparison operation, return the bit number in CCR to test. We
768 know this is a valid comparison.
769
770 SCC_P is 1 if this is for an scc. That means that %D will have been
771 used instead of %C, so the bits will be in different places.
772
b4ac57ab 773 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
774
775int
776ccr_bit (op, scc_p)
777 register rtx op;
778 int scc_p;
779{
780 enum rtx_code code = GET_CODE (op);
781 enum machine_mode cc_mode;
782 int cc_regnum;
783 int base_bit;
784
785 if (GET_RTX_CLASS (code) != '<')
786 return -1;
787
788 cc_mode = GET_MODE (XEXP (op, 0));
789 cc_regnum = REGNO (XEXP (op, 0));
790 base_bit = 4 * (cc_regnum - 68);
791
c5defebb
RK
792 /* In CCEQmode cases we have made sure that the result is always in the
793 third bit of the CR field. */
794
795 if (cc_mode == CCEQmode)
796 return base_bit + 3;
797
9878760c
RK
798 switch (code)
799 {
800 case NE:
801 return scc_p ? base_bit + 3 : base_bit + 2;
802 case EQ:
803 return base_bit + 2;
804 case GT: case GTU:
805 return base_bit + 1;
806 case LT: case LTU:
807 return base_bit;
808
809 case GE: case GEU:
810 /* If floating-point, we will have done a cror to put the bit in the
811 unordered position. So test that bit. For integer, this is ! LT
812 unless this is an scc insn. */
813 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
814
815 case LE: case LEU:
816 return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
817
818 default:
819 abort ();
820 }
821}
822\f
823/* Print an operand. Recognize special options, documented below. */
824
825void
826print_operand (file, x, code)
827 FILE *file;
828 rtx x;
829 char code;
830{
831 int i;
832 int val;
833
834 /* These macros test for integers and extract the low-order bits. */
835#define INT_P(X) \
836((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
837 && GET_MODE (X) == VOIDmode)
838
839#define INT_LOWPART(X) \
840 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
841
842 switch (code)
843 {
a8b3aeda 844 case '.':
a85d226b
RK
845 /* Write out an instruction after the call which may be replaced
846 with glue code by the loader. This depends on the AIX version. */
847 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
848 return;
849
9854d9ed
RK
850 case 'A':
851 /* If X is a constant integer whose low-order 5 bits are zero,
852 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 853 in the AIX assembler where "sri" with a zero shift count
9854d9ed
RK
854 write a trash instruction. */
855 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 856 putc ('l', file);
9854d9ed 857 else
76229ac8 858 putc ('r', file);
9854d9ed
RK
859 return;
860
861 case 'b':
862 /* Low-order 16 bits of constant, unsigned. */
cad12a8d 863 if (! INT_P (x))
9854d9ed 864 output_operand_lossage ("invalid %%b value");
cad12a8d 865
9854d9ed 866 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
cad12a8d
RK
867 return;
868
9854d9ed
RK
869 case 'C':
870 /* This is an optional cror needed for LE or GE floating-point
871 comparisons. Otherwise write nothing. */
872 if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
873 && GET_MODE (XEXP (x, 0)) == CCFPmode)
874 {
875 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
876
877 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
878 base_bit + 2, base_bit + (GET_CODE (x) == GE));
879 }
880 return;
881
882 case 'D':
883 /* Similar, except that this is for an scc, so we must be able to
884 encode the test in a single bit that is one. We do the above
885 for any LE, GE, GEU, or LEU and invert the bit for NE. */
886 if (GET_CODE (x) == LE || GET_CODE (x) == GE
887 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
888 {
889 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
890
891 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
892 base_bit + 2,
893 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
894 }
895
896 else if (GET_CODE (x) == NE)
897 {
898 int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
899
900 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
901 base_bit + 2, base_bit + 2);
902 }
903 return;
904
905 case 'E':
906 /* X is a CR register. Print the number of the third bit of the CR */
907 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
908 output_operand_lossage ("invalid %%E value");
909
910 fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
a85d226b 911 return;
9854d9ed
RK
912
913 case 'f':
914 /* X is a CR register. Print the shift count needed to move it
915 to the high-order four bits. */
916 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
917 output_operand_lossage ("invalid %%f value");
918 else
919 fprintf (file, "%d", 4 * (REGNO (x) - 68));
920 return;
921
922 case 'F':
923 /* Similar, but print the count for the rotate in the opposite
924 direction. */
925 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
926 output_operand_lossage ("invalid %%F value");
927 else
928 fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
929 return;
930
931 case 'G':
932 /* X is a constant integer. If it is negative, print "m",
933 otherwise print "z". This is to make a aze or ame insn. */
934 if (GET_CODE (x) != CONST_INT)
935 output_operand_lossage ("invalid %%G value");
936 else if (INTVAL (x) >= 0)
76229ac8 937 putc ('z', file);
9854d9ed 938 else
76229ac8 939 putc ('m', file);
9854d9ed
RK
940 return;
941
9878760c 942 case 'h':
df3d94ed
RK
943 /* If constant, output low-order five bits. Otherwise,
944 write normally. */
9878760c
RK
945 if (INT_P (x))
946 fprintf (file, "%d", INT_LOWPART (x) & 31);
947 else
948 print_operand (file, x, 0);
949 return;
950
951 case 'H':
df3d94ed 952 /* X must be a constant. Output the low order 5 bits plus 24. */
9878760c
RK
953 if (! INT_P (x))
954 output_operand_lossage ("invalid %%H value");
955
956 fprintf (file, "%d", (INT_LOWPART (x) + 24) & 31);
957 return;
958
9854d9ed
RK
959 case 'I':
960 /* Print `i' if this is a constant, else nothing. */
9878760c 961 if (INT_P (x))
76229ac8 962 putc ('i', file);
9878760c
RK
963 return;
964
9854d9ed
RK
965 case 'j':
966 /* Write the bit number in CCR for jump. */
967 i = ccr_bit (x, 0);
968 if (i == -1)
969 output_operand_lossage ("invalid %%j code");
9878760c 970 else
9854d9ed 971 fprintf (file, "%d", i);
9878760c
RK
972 return;
973
9854d9ed
RK
974 case 'J':
975 /* Similar, but add one for shift count in rlinm for scc and pass
976 scc flag to `ccr_bit'. */
977 i = ccr_bit (x, 1);
978 if (i == -1)
979 output_operand_lossage ("invalid %%J code");
980 else
a0466a68
RK
981 /* If we want bit 31, write a shift count of zero, not 32. */
982 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
983 return;
984
9854d9ed
RK
985 case 'k':
986 /* X must be a constant. Write the 1's complement of the
987 constant. */
9878760c 988 if (! INT_P (x))
9854d9ed 989 output_operand_lossage ("invalid %%k value");
9878760c 990
9854d9ed 991 fprintf (file, "%d", ~ INT_LOWPART (x));
9878760c
RK
992 return;
993
9854d9ed
RK
994 case 'L':
995 /* Write second word of DImode or DFmode reference. Works on register
996 or non-indexed memory only. */
997 if (GET_CODE (x) == REG)
998 fprintf (file, "%d", REGNO (x) + 1);
999 else if (GET_CODE (x) == MEM)
1000 {
1001 /* Handle possible auto-increment. Since it is pre-increment and
1002 we have already done it, we can just use an offset of four. */
1003 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1004 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1005 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
1006 else
1007 output_address (plus_constant (XEXP (x, 0), 4));
1008 }
9878760c 1009 return;
9854d9ed 1010
9878760c
RK
1011 case 'm':
1012 /* MB value for a mask operand. */
1013 if (! mask_operand (x, VOIDmode))
1014 output_operand_lossage ("invalid %%m value");
1015
1016 val = INT_LOWPART (x);
1017
1018 /* If the high bit is set and the low bit is not, the value is zero.
1019 If the high bit is zero, the value is the first 1 bit we find from
1020 the left. */
1021 if (val < 0 && (val & 1) == 0)
1022 {
1023 fprintf (file, "0");
1024 return;
1025 }
1026 else if (val >= 0)
1027 {
1028 for (i = 1; i < 32; i++)
1029 if ((val <<= 1) < 0)
1030 break;
1031 fprintf (file, "%d", i);
1032 return;
1033 }
1034
1035 /* Otherwise, look for the first 0 bit from the right. The result is its
1036 number plus 1. We know the low-order bit is one. */
1037 for (i = 0; i < 32; i++)
1038 if (((val >>= 1) & 1) == 0)
1039 break;
1040
1041 /* If we ended in ...01, I would be 0. The correct value is 31, so
1042 we want 31 - i. */
1043 fprintf (file, "%d", 31 - i);
1044 return;
1045
1046 case 'M':
1047 /* ME value for a mask operand. */
1048 if (! mask_operand (x, VOIDmode))
1049 output_operand_lossage ("invalid %%m value");
1050
1051 val = INT_LOWPART (x);
1052
1053 /* If the low bit is set and the high bit is not, the value is 31.
1054 If the low bit is zero, the value is the first 1 bit we find from
1055 the right. */
1056 if ((val & 1) && val >= 0)
1057 {
76229ac8 1058 fputs ("31", file);
9878760c
RK
1059 return;
1060 }
1061 else if ((val & 1) == 0)
1062 {
1063 for (i = 0; i < 32; i++)
1064 if ((val >>= 1) & 1)
1065 break;
1066
1067 /* If we had ....10, I would be 0. The result should be
1068 30, so we need 30 - i. */
1069 fprintf (file, "%d", 30 - i);
1070 return;
1071 }
1072
1073 /* Otherwise, look for the first 0 bit from the left. The result is its
1074 number minus 1. We know the high-order bit is one. */
1075 for (i = 0; i < 32; i++)
1076 if ((val <<= 1) >= 0)
1077 break;
1078
1079 fprintf (file, "%d", i);
1080 return;
1081
9878760c
RK
1082 case 'N':
1083 /* Write the number of elements in the vector times 4. */
1084 if (GET_CODE (x) != PARALLEL)
1085 output_operand_lossage ("invalid %%N value");
1086
1087 fprintf (file, "%d", XVECLEN (x, 0) * 4);
1088 return;
1089
1090 case 'O':
1091 /* Similar, but subtract 1 first. */
1092 if (GET_CODE (x) != PARALLEL)
1093 output_operand_lossage ("invalid %%N value");
1094
1095 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
1096 return;
1097
9854d9ed
RK
1098 case 'p':
1099 /* X is a CONST_INT that is a power of two. Output the logarithm. */
1100 if (! INT_P (x)
1101 || (i = exact_log2 (INT_LOWPART (x))) < 0)
1102 output_operand_lossage ("invalid %%p value");
1103
1104 fprintf (file, "%d", i);
1105 return;
1106
9878760c
RK
1107 case 'P':
1108 /* The operand must be an indirect memory reference. The result
1109 is the register number. */
1110 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
1111 || REGNO (XEXP (x, 0)) >= 32)
1112 output_operand_lossage ("invalid %%P value");
1113
1114 fprintf (file, "%d", REGNO (XEXP (x, 0)));
1115 return;
1116
9854d9ed
RK
1117 case 'R':
1118 /* X is a CR register. Print the mask for `mtcrf'. */
1119 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1120 output_operand_lossage ("invalid %%R value");
1121 else
1122 fprintf (file, "%d", 128 >> (REGNO (x) - 68));
9878760c 1123 return;
9854d9ed
RK
1124
1125 case 's':
1126 /* Low 5 bits of 32 - value */
1127 if (! INT_P (x))
1128 output_operand_lossage ("invalid %%s value");
1129
1130 fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
9878760c 1131 return;
9854d9ed
RK
1132
1133 case 'S':
1134 /* Low 5 bits of 31 - value */
1135 if (! INT_P (x))
1136 output_operand_lossage ("invalid %%S value");
1137
1138 fprintf (file, "%d", (31 - INT_LOWPART (x)) & 31);
9878760c 1139 return;
9854d9ed 1140
9878760c
RK
1141 case 't':
1142 /* Write 12 if this jump operation will branch if true, 4 otherwise.
1143 All floating-point operations except NE branch true and integer
1144 EQ, LT, GT, LTU and GTU also branch true. */
1145 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
1146 output_operand_lossage ("invalid %%t value");
1147
1148 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
1149 && GET_CODE (x) != NE)
1150 || GET_CODE (x) == EQ
1151 || GET_CODE (x) == LT || GET_CODE (x) == GT
1152 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
76229ac8 1153 fputs ("12", file);
9878760c 1154 else
76229ac8 1155 putc ('4', file);
9878760c
RK
1156 return;
1157
1158 case 'T':
1159 /* Opposite of 't': write 4 if this jump operation will branch if true,
1160 12 otherwise. */
1161 if (GET_RTX_CLASS (GET_CODE (x)) != '<')
1162 output_operand_lossage ("invalid %%t value");
1163
1164 else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
1165 && GET_CODE (x) != NE)
1166 || GET_CODE (x) == EQ
1167 || GET_CODE (x) == LT || GET_CODE (x) == GT
1168 || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
76229ac8 1169 putc ('4', file);
9878760c 1170 else
76229ac8 1171 fputs ("12", file);
9878760c
RK
1172 return;
1173
9854d9ed
RK
1174 case 'u':
1175 /* High-order 16 bits of constant. */
1176 if (! INT_P (x))
1177 output_operand_lossage ("invalid %%u value");
9878760c 1178
76229ac8 1179 fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
1180 return;
1181
9854d9ed
RK
1182 case 'U':
1183 /* Print `u' if this has an auto-increment or auto-decrement. */
1184 if (GET_CODE (x) == MEM
1185 && (GET_CODE (XEXP (x, 0)) == PRE_INC
1186 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 1187 putc ('u', file);
9854d9ed 1188 return;
9878760c 1189
9854d9ed
RK
1190 case 'w':
1191 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
1192 normally. */
1193 if (INT_P (x))
1194 fprintf (file, "%d",
1195 (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
1196 else
1197 print_operand (file, x, 0);
9878760c
RK
1198 return;
1199
9854d9ed
RK
1200 case 'W':
1201 /* If constant, low-order 16 bits of constant, unsigned.
1202 Otherwise, write normally. */
1203 if (INT_P (x))
1204 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
1205 else
1206 print_operand (file, x, 0);
1207 return;
9878760c 1208
9854d9ed
RK
1209 case 'X':
1210 if (GET_CODE (x) == MEM
1211 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
76229ac8 1212 putc ('x', file);
9854d9ed 1213 return;
9878760c 1214
9854d9ed
RK
1215 case 'Y':
1216 /* Like 'L', for third word of TImode */
1217 if (GET_CODE (x) == REG)
1218 fprintf (file, "%d", REGNO (x) + 2);
1219 else if (GET_CODE (x) == MEM)
9878760c 1220 {
9854d9ed
RK
1221 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1222 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1223 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
1224 else
1225 output_address (plus_constant (XEXP (x, 0), 8));
9878760c
RK
1226 }
1227 return;
9854d9ed 1228
9878760c 1229 case 'z':
b4ac57ab
RS
1230 /* X is a SYMBOL_REF. Write out the name preceded by a
1231 period and without any trailing data in brackets. Used for function
9878760c
RK
1232 names. */
1233 if (GET_CODE (x) != SYMBOL_REF)
1234 abort ();
1235
76229ac8 1236 putc ('.', file);
9878760c
RK
1237 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
1238 return;
1239
9854d9ed
RK
1240 case 'Z':
1241 /* Like 'L', for last word of TImode. */
1242 if (GET_CODE (x) == REG)
1243 fprintf (file, "%d", REGNO (x) + 3);
1244 else if (GET_CODE (x) == MEM)
1245 {
1246 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1247 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1248 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
1249 else
1250 output_address (plus_constant (XEXP (x, 0), 12));
1251 }
5c23c401 1252 return;
9854d9ed 1253
9878760c
RK
1254 case 0:
1255 if (GET_CODE (x) == REG)
1256 fprintf (file, "%s", reg_names[REGNO (x)]);
1257 else if (GET_CODE (x) == MEM)
1258 {
1259 /* We need to handle PRE_INC and PRE_DEC here, since we need to
1260 know the width from the mode. */
1261 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
1262 fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
1263 REGNO (XEXP (XEXP (x, 0), 0)));
1264 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
1265 fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
1266 REGNO (XEXP (XEXP (x, 0), 0)));
1267 else
1268 output_address (XEXP (x, 0));
1269 }
1270 else
1271 output_addr_const (file, x);
a85d226b 1272 return;
9878760c
RK
1273
1274 default:
1275 output_operand_lossage ("invalid %%xn code");
1276 }
1277}
1278\f
1279/* Print the address of an operand. */
1280
1281void
1282print_operand_address (file, x)
1283 FILE *file;
1284 register rtx x;
1285{
1286 if (GET_CODE (x) == REG)
1287 fprintf (file, "0(%d)", REGNO (x));
1288 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
1289 {
1290 output_addr_const (file, x);
1875cc88
JW
1291 /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
1292 of the toc pointer. */
1293 if (TARGET_MINIMAL_TOC)
1294 fprintf (file, "(30)");
1295 else
1296 fprintf (file, "(2)");
9878760c
RK
1297 }
1298 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
1299 {
1300 if (REGNO (XEXP (x, 0)) == 0)
1301 fprintf (file, "%d,%d", REGNO (XEXP (x, 1)), REGNO (XEXP (x, 0)));
1302 else
1303 fprintf (file, "%d,%d", REGNO (XEXP (x, 0)), REGNO (XEXP (x, 1)));
1304 }
1305 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
1306 fprintf (file, "%d(%d)", INTVAL (XEXP (x, 1)), REGNO (XEXP (x, 0)));
1307 else
1308 abort ();
1309}
1310\f
1311/* This page contains routines that are used to determine what the function
1312 prologue and epilogue code will do and write them out. */
1313
1314/* Return the first fixed-point register that is required to be saved. 32 if
1315 none. */
1316
1317int
1318first_reg_to_save ()
1319{
1320 int first_reg;
1321
1322 /* Find lowest numbered live register. */
1323 for (first_reg = 13; first_reg <= 31; first_reg++)
1324 if (regs_ever_live[first_reg])
1325 break;
1326
e165f3f0
RK
1327 /* If profiling, then we must save/restore every register that contains
1328 a parameter before/after the .mcount call. Use registers from 30 down
1329 to 23 to do this. Don't use the frame pointer in reg 31.
1330
1331 For now, save enough room for all of the parameter registers. */
1332 if (profile_flag)
1333 if (first_reg > 23)
1334 first_reg = 23;
1335
9878760c
RK
1336 return first_reg;
1337}
1338
1339/* Similar, for FP regs. */
1340
1341int
1342first_fp_reg_to_save ()
1343{
1344 int first_reg;
1345
1346 /* Find lowest numbered live register. */
1347 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
1348 if (regs_ever_live[first_reg])
1349 break;
1350
1351 return first_reg;
1352}
1353
1354/* Return 1 if we need to save CR. */
1355
1356int
1357must_save_cr ()
1358{
1359 return regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72];
1360}
1361
1362/* Compute the size of the save area in the stack, including the space for
1363 the fixed area. */
1364
1365int
1366rs6000_sa_size ()
1367{
1368 int size;
9878760c
RK
1369
1370 /* We have the six fixed words, plus the size of the register save
1371 areas, rounded to a double-word. */
1372 size = 6 + (32 - first_reg_to_save ()) + (64 - first_fp_reg_to_save ()) * 2;
1373 if (size & 1)
1374 size++;
1375
1376 return size * 4;
1377}
1378
1379/* Return non-zero if this function makes calls. */
1380
1381int
1382rs6000_makes_calls ()
1383{
1384 rtx insn;
1385
0c61c946
RK
1386 /* If we are profiling, we will be making a call to mcount. */
1387 if (profile_flag)
1388 return 1;
1389
9878760c
RK
1390 for (insn = get_insns (); insn; insn = next_insn (insn))
1391 if (GET_CODE (insn) == CALL_INSN)
1392 return 1;
1393
1394 return 0;
1395}
1396
1397/* Return non-zero if this function needs to push space on the stack. */
1398
1399int
1400rs6000_pushes_stack ()
1401{
1402 int total_size = (rs6000_sa_size () + get_frame_size ()
1403 + current_function_outgoing_args_size);
1404
1405 /* We need to push the stack if a frame pointer is needed (because the
1406 stack might be dynamically adjusted), if we are debugging, if the
1407 total stack size is more than 220 bytes, or if we make calls. */
1408
1409 return (frame_pointer_needed || write_symbols != NO_DEBUG
1410 || total_size > 220
1411 || rs6000_makes_calls ());
1412}
1413
1414/* Write function prologue. */
1415
1416void
1417output_prolog (file, size)
1418 FILE *file;
1419 int size;
1420{
1421 int first_reg = first_reg_to_save ();
1422 int must_push = rs6000_pushes_stack ();
1423 int first_fp_reg = first_fp_reg_to_save ();
1424 int basic_size = rs6000_sa_size ();
1425 int total_size = (basic_size + size + current_function_outgoing_args_size);
1426
1427 /* Round size to multiple of 8 bytes. */
1428 total_size = (total_size + 7) & ~7;
1429
1430 /* Write .extern for any function we will call to save and restore fp
1431 values. */
1432 if (first_fp_reg < 62)
1433 fprintf (file, "\t.extern ._savef%d\n\t.extern ._restf%d\n",
1434 first_fp_reg - 32, first_fp_reg - 32);
1435
1436 /* Write .extern for truncation routines, if needed. */
1437 if (rs6000_trunc_used && ! trunc_defined)
1438 {
e138174b
ILT
1439 fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
1440 RS6000_ITRUNC, RS6000_UITRUNC);
9878760c
RK
1441 trunc_defined = 1;
1442 }
c764f757
RK
1443 /* Write .extern for AIX common mode routines, if needed. */
1444 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
1445 {
1446 fputs ("\t.extern __mulh\n"
1447 "\t.extern __mull\n"
1448 "\t.extern __divss\n"
1449 "\t.extern __divus\n"
1450 "\t.extern __quoss\n"
1451 "\t.extern __quous\n",
1452 file);
1453 common_mode_defined = 1;
1454 }
9878760c 1455
e165f3f0
RK
1456 /* If we have to call a function to save fpr's, or if we are doing profiling,
1457 then we will be using LR. */
1458 if (first_fp_reg < 62 || profile_flag)
9878760c
RK
1459 regs_ever_live[65] = 1;
1460
1461 /* If we use the link register, get it into r0. */
1462 if (regs_ever_live[65])
85638c0d 1463 asm_fprintf (file, "\tmflr 0\n");
9878760c
RK
1464
1465 /* If we need to save CR, put it into r12. */
1466 if (must_save_cr ())
85638c0d 1467 asm_fprintf (file, "\tmfcr 12\n");
9878760c
RK
1468
1469 /* Do any required saving of fpr's. If only one or two to save, do it
53322b0c
RK
1470 ourself. Otherwise, call function. Note that since they are statically
1471 linked, we do not need a nop following them. */
9878760c 1472 if (first_fp_reg == 62)
85638c0d 1473 asm_fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n");
9878760c 1474 else if (first_fp_reg == 63)
85638c0d 1475 asm_fprintf (file, "\tstfd 31,-8(1)\n");
9878760c 1476 else if (first_fp_reg != 64)
85638c0d 1477 asm_fprintf (file, "\tbl ._savef%d\n", first_fp_reg - 32);
9878760c
RK
1478
1479 /* Now save gpr's. */
85638c0d
RK
1480 if (! TARGET_POWER || first_reg == 31)
1481 {
1482 int regno, loc;
1483
1484 for (regno = first_reg,
1485 loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
1486 regno < 32;
1487 regno++, loc += 4)
1488 asm_fprintf (file, "\t{st|stw} %d,%d(1)\n", regno, loc);
1489 }
1490
9878760c 1491 else if (first_reg != 32)
85638c0d 1492 asm_fprintf (file, "\t{stm|stmw} %d,%d(1)\n", first_reg,
9878760c
RK
1493 - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
1494
1495 /* Save lr if we used it. */
1496 if (regs_ever_live[65])
85638c0d 1497 asm_fprintf (file, "\t{st|stw} 0,8(1)\n");
9878760c
RK
1498
1499 /* Save CR if we use any that must be preserved. */
1500 if (must_save_cr ())
85638c0d 1501 asm_fprintf (file, "\t{st|stw} 12,4(1)\n");
9878760c
RK
1502
1503 /* Update stack and set back pointer. */
1504 if (must_push)
1505 {
1506 if (total_size < 32767)
85638c0d 1507 asm_fprintf (file, "\t{stu|stwu} 1,%d(1)\n", - total_size);
9878760c
RK
1508 else
1509 {
1f5f71ae 1510 asm_fprintf (file, "\t{cau 0,0,%d|lis 0,%d}\n\t{oril 0,0,%d|li 0,%d}\n",
9878760c 1511 (total_size >> 16) & 0xffff, total_size & 0xffff);
1f5f71ae
RK
1512 if (TARGET_POWERPC)
1513 asm_fprintf (file, "\tsubf 12,0,1\n");
1514 else
1515 asm_fprintf (file, "\t{sf|subfc} 12,0,1\n");
1516 asm_fprintf (file, "\t{st|stw} 1,0(12)\n\tmr 1,12\n");
9878760c
RK
1517 }
1518 }
1519
1520 /* Set frame pointer, if needed. */
1521 if (frame_pointer_needed)
1f5f71ae 1522 asm_fprintf (file, "\tmr 31,1\n");
1875cc88
JW
1523
1524 /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
1525 TOC_TABLE address into register 30. */
1526 if (TARGET_MINIMAL_TOC && get_pool_size () != 0)
3daf36a4
ILT
1527 {
1528 char buf[100];
1529
1530 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
1531 asm_fprintf (file, "\t{l|lwz} 30,");
1532 assemble_name (file, buf);
1533 asm_fprintf (file, "(2)\n");
1534 }
9878760c
RK
1535}
1536
1537/* Write function epilogue. */
1538
1539void
1540output_epilog (file, size)
1541 FILE *file;
1542 int size;
1543{
1544 int first_reg = first_reg_to_save ();
1545 int must_push = rs6000_pushes_stack ();
1546 int first_fp_reg = first_fp_reg_to_save ();
1547 int basic_size = rs6000_sa_size ();
1548 int total_size = (basic_size + size + current_function_outgoing_args_size);
1549 rtx insn = get_last_insn ();
1550
1551 /* Round size to multiple of 8 bytes. */
1552 total_size = (total_size + 7) & ~7;
1553
1554 /* If the last insn was a BARRIER, we don't have to write anything except
1555 the trace table. */
1556 if (GET_CODE (insn) == NOTE)
1557 insn = prev_nonnote_insn (insn);
1558 if (insn == 0 || GET_CODE (insn) != BARRIER)
1559 {
1560 /* If we have a frame pointer, a call to alloca, or a large stack
1561 frame, restore the old stack pointer using the backchain. Otherwise,
1562 we know what size to update it with. */
1563 if (frame_pointer_needed || current_function_calls_alloca
1564 || total_size > 32767)
85638c0d 1565 asm_fprintf (file, "\t{l|lwz} 1,0(1)\n");
9878760c 1566 else if (must_push)
1f5f71ae 1567 asm_fprintf (file, "\t{cal 1,%d(1)|addi 1,1,%d}\n", total_size);
9878760c 1568
b4ac57ab 1569 /* Get the old lr if we saved it. */
9878760c 1570 if (regs_ever_live[65])
85638c0d 1571 asm_fprintf (file, "\t{l|lwz} 0,8(1)\n");
9878760c
RK
1572
1573 /* Get the old cr if we saved it. */
1574 if (must_save_cr ())
85638c0d 1575 asm_fprintf (file, "\t{l|lwz} 12,4(1)\n");
9878760c 1576
b4ac57ab
RS
1577 /* Set LR here to try to overlap restores below. */
1578 if (regs_ever_live[65])
85638c0d 1579 asm_fprintf (file, "\tmtlr 0\n");
b4ac57ab 1580
9878760c 1581 /* Restore gpr's. */
85638c0d
RK
1582 if (! TARGET_POWER || first_reg == 31)
1583 {
1584 int regno, loc;
1585
1586 for (regno = first_reg,
1587 loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
1588 regno < 32;
1589 regno++, loc += 4)
1590 asm_fprintf (file, "\t{l|lwz} %d,%d(1)\n", regno, loc);
1591 }
1592
9878760c 1593 else if (first_reg != 32)
85638c0d
RK
1594 asm_fprintf (file, "\t{lm|lmw} %d,%d(1)\n", first_reg,
1595 - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
9878760c 1596
b4ac57ab 1597 /* Restore fpr's if we can do it without calling a function. */
9878760c 1598 if (first_fp_reg == 62)
85638c0d 1599 asm_fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n");
9878760c 1600 else if (first_fp_reg == 63)
85638c0d 1601 asm_fprintf (file, "\tlfd 31,-8(1)\n");
9878760c 1602
28edebac
RK
1603 /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4
1604 that were used. */
9878760c 1605 if (must_save_cr ())
85638c0d
RK
1606 asm_fprintf (file, "\tmtcrf %d,12\n",
1607 (regs_ever_live[70] != 0) * 0x20
1608 + (regs_ever_live[71] != 0) * 0x10
1609 + (regs_ever_live[72] != 0) * 0x8);
9878760c 1610
b4ac57ab
RS
1611 /* If we have to restore more than two FP registers, branch to the
1612 restore function. It will return to our caller. */
1613 if (first_fp_reg < 62)
85638c0d 1614 asm_fprintf (file, "\tb ._restf%d\n", first_fp_reg - 32);
b4ac57ab 1615 else
85638c0d 1616 asm_fprintf (file, "\t{br|blr}\n");
9878760c 1617 }
b4ac57ab 1618
9b30bae2 1619 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
1620 on its format.
1621
1622 We don't output a traceback table if -finhibit-size-directive was
1623 used. The documentation for -finhibit-size-directive reads
1624 ``don't output a @code{.size} assembler directive, or anything
1625 else that would cause trouble if the function is split in the
1626 middle, and the two halves are placed at locations far apart in
1627 memory.'' The traceback table has this property, since it
1628 includes the offset from the start of the function to the
1629 traceback table itself. */
1630 if (! flag_inhibit_size_directive)
9b30bae2 1631 {
314fc5a9
ILT
1632 char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
1633 int fixed_parms, float_parms, parm_info;
1634 int i;
1635
1636 /* Need label immediately before tbtab, so we can compute its offset
1637 from the function start. */
1638 if (*fname == '*')
1639 ++fname;
1640 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
1641 ASM_OUTPUT_LABEL (file, fname);
1642
1643 /* The .tbtab pseudo-op can only be used for the first eight
1644 expressions, since it can't handle the possibly variable
1645 length fields that follow. However, if you omit the optional
1646 fields, the assembler outputs zeros for all optional fields
1647 anyways, giving each variable length field is minimum length
1648 (as defined in sys/debug.h). Thus we can not use the .tbtab
1649 pseudo-op at all. */
1650
1651 /* An all-zero word flags the start of the tbtab, for debuggers
1652 that have to find it by searching forward from the entry
1653 point or from the current pc. */
1654 fprintf (file, "\t.long 0\n");
1655
1656 /* Tbtab format type. Use format type 0. */
1657 fprintf (file, "\t.byte 0,");
1658
1659 /* Language type. Unfortunately, there doesn't seem to be any
1660 official way to get this info, so we use language_string. C
1661 is 0. C++ is 9. No number defined for Obj-C, so use the
1662 value for C for now. */
1663 if (! strcmp (language_string, "GNU C")
1664 || ! strcmp (language_string, "GNU Obj-C"))
1665 i = 0;
1666 else if (! strcmp (language_string, "GNU F77"))
1667 i = 1;
1668 else if (! strcmp (language_string, "GNU Ada"))
1669 i = 3;
1670 else if (! strcmp (language_string, "GNU PASCAL"))
1671 i = 2;
1672 else if (! strcmp (language_string, "GNU C++"))
1673 i = 9;
1674 else
1675 abort ();
1676 fprintf (file, "%d,", i);
1677
1678 /* 8 single bit fields: global linkage (not set for C extern linkage,
1679 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
1680 from start of procedure stored in tbtab, internal function, function
1681 has controlled storage, function has no toc, function uses fp,
1682 function logs/aborts fp operations. */
1683 /* Assume that fp operations are used if any fp reg must be saved. */
1684 fprintf (file, "%d,", (1 << 5) | ((first_fp_reg != 64) << 1));
1685
1686 /* 6 bitfields: function is interrupt handler, name present in
1687 proc table, function calls alloca, on condition directives
1688 (controls stack walks, 3 bits), saves condition reg, saves
1689 link reg. */
1690 /* The `function calls alloca' bit seems to be set whenever reg 31 is
1691 set up as a frame pointer, even when there is no alloca call. */
1692 fprintf (file, "%d,",
1693 ((1 << 6) | (frame_pointer_needed << 5)
1694 | (must_save_cr () << 1) | (regs_ever_live[65])));
1695
1696 /* 3 bitfields: saves backchain, spare bit, number of fpr saved
1697 (6 bits). */
1698 fprintf (file, "%d,",
1699 (must_push << 7) | (64 - first_fp_reg_to_save ()));
1700
1701 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
1702 fprintf (file, "%d,", (32 - first_reg_to_save ()));
1703
1704 {
1705 /* Compute the parameter info from the function decl argument
1706 list. */
1707 tree decl;
1708 int next_parm_info_bit;
1709
1710 next_parm_info_bit = 31;
1711 parm_info = 0;
1712 fixed_parms = 0;
1713 float_parms = 0;
1714
1715 for (decl = DECL_ARGUMENTS (current_function_decl);
1716 decl; decl = TREE_CHAIN (decl))
1717 {
1718 rtx parameter = DECL_INCOMING_RTL (decl);
1719 enum machine_mode mode = GET_MODE (parameter);
1720
1721 if (GET_CODE (parameter) == REG)
1722 {
1723 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1724 {
1725 int bits;
1726
1727 float_parms++;
1728
1729 if (mode == SFmode)
1730 bits = 0x2;
1731 else if (mode == DFmode)
1732 bits = 0x3;
1733 else
1734 abort ();
1735
1736 /* If only one bit will fit, don't or in this entry. */
1737 if (next_parm_info_bit > 0)
1738 parm_info |= (bits << (next_parm_info_bit - 1));
1739 next_parm_info_bit -= 2;
1740 }
1741 else
1742 {
1743 fixed_parms += ((GET_MODE_SIZE (mode)
1744 + (UNITS_PER_WORD - 1))
1745 / UNITS_PER_WORD);
1746 next_parm_info_bit -= 1;
1747 }
1748 }
1749 }
1750 }
1751
1752 /* Number of fixed point parameters. */
1753 /* This is actually the number of words of fixed point parameters; thus
1754 an 8 byte struct counts as 2; and thus the maximum value is 8. */
1755 fprintf (file, "%d,", fixed_parms);
1756
1757 /* 2 bitfields: number of floating point parameters (7 bits), parameters
1758 all on stack. */
1759 /* This is actually the number of fp registers that hold parameters;
1760 and thus the maximum value is 13. */
1761 /* Set parameters on stack bit if parameters are not in their original
1762 registers, regardless of whether they are on the stack? Xlc
1763 seems to set the bit when not optimizing. */
1764 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
1765
1766 /* Optional fields follow. Some are variable length. */
1767
1768 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
1769 11 double float. */
1770 /* There is an entry for each parameter in a register, in the order that
1771 they occur in the parameter list. Any intervening arguments on the
1772 stack are ignored. If the list overflows a long (max possible length
1773 34 bits) then completely leave off all elements that don't fit. */
1774 /* Only emit this long if there was at least one parameter. */
1775 if (fixed_parms || float_parms)
1776 fprintf (file, "\t.long %d\n", parm_info);
1777
1778 /* Offset from start of code to tb table. */
1779 fprintf (file, "\t.long ");
1780 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
1781 RS6000_OUTPUT_BASENAME (file, fname);
1782 fprintf (file, "-.");
1783 RS6000_OUTPUT_BASENAME (file, fname);
1784 fprintf (file, "\n");
1785
1786 /* Interrupt handler mask. */
1787 /* Omit this long, since we never set the interrupt handler bit
1788 above. */
1789
1790 /* Number of CTL (controlled storage) anchors. */
1791 /* Omit this long, since the has_ctl bit is never set above. */
1792
1793 /* Displacement into stack of each CTL anchor. */
1794 /* Omit this list of longs, because there are no CTL anchors. */
1795
1796 /* Length of function name. */
1797 fprintf (file, "\t.short %d\n", strlen (fname));
1798
1799 /* Function name. */
1800 assemble_string (fname, strlen (fname));
1801
1802 /* Register for alloca automatic storage; this is always reg 31.
1803 Only emit this if the alloca bit was set above. */
1804 if (frame_pointer_needed)
1805 fprintf (file, "\t.byte 31\n");
9b30bae2 1806 }
9878760c
RK
1807}
1808\f
1809/* Output a TOC entry. We derive the entry name from what is
1810 being written. */
1811
1812void
1813output_toc (file, x, labelno)
1814 FILE *file;
1815 rtx x;
1816 int labelno;
1817{
1818 char buf[256];
1819 char *name = buf;
1820 rtx base = x;
1821 int offset = 0;
1822
1823 ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
1824
37c37a57
RK
1825 /* Handle FP constants specially. Note that if we have a minimal
1826 TOC, things we put here aren't actually in the TOC, so we can allow
1827 FP constants. */
9878760c
RK
1828 if (GET_CODE (x) == CONST_DOUBLE
1829 && GET_MODE (x) == DFmode
1830 && TARGET_FLOAT_FORMAT == HOST_FLOAT_FORMAT
1831 && BITS_PER_WORD == HOST_BITS_PER_INT
37c37a57 1832 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
9878760c 1833 {
1875cc88
JW
1834 if (TARGET_MINIMAL_TOC)
1835 fprintf (file, "\t.long %d\n\t.long %d\n",
1836 CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
1837 else
1838 fprintf (file, "\t.tc FD_%x_%x[TC],%d,%d\n",
1839 CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
1840 CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
9878760c
RK
1841 return;
1842 }
1843 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
37c37a57 1844 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
9878760c
RK
1845 {
1846 rtx val = operand_subword (x, 0, 0, SFmode);
1847
1848 if (val == 0 || GET_CODE (val) != CONST_INT)
1849 abort ();
1850
1875cc88
JW
1851 if (TARGET_MINIMAL_TOC)
1852 fprintf (file, "\t.long %d\n", INTVAL (val));
1853 else
1854 fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
9878760c
RK
1855 return;
1856 }
1857
1858 if (GET_CODE (x) == CONST)
1859 {
1860 base = XEXP (XEXP (x, 0), 0);
1861 offset = INTVAL (XEXP (XEXP (x, 0), 1));
1862 }
1863
1864 if (GET_CODE (base) == SYMBOL_REF)
1865 name = XSTR (base, 0);
1866 else if (GET_CODE (base) == LABEL_REF)
1867 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
1868 else if (GET_CODE (base) == CODE_LABEL)
1869 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
1870 else
1871 abort ();
1872
1875cc88
JW
1873 if (TARGET_MINIMAL_TOC)
1874 fprintf (file, "\t.long ");
1875 else
1876 {
1877 fprintf (file, "\t.tc ");
1878 RS6000_OUTPUT_BASENAME (file, name);
9878760c 1879
1875cc88
JW
1880 if (offset < 0)
1881 fprintf (file, ".N%d", - offset);
1882 else if (offset)
1883 fprintf (file, ".P%d", offset);
9878760c 1884
1875cc88
JW
1885 fprintf (file, "[TC],");
1886 }
9878760c
RK
1887 output_addr_const (file, x);
1888 fprintf (file, "\n");
1889}
1890\f
1891/* Output an assembler pseudo-op to write an ASCII string of N characters
1892 starting at P to FILE.
1893
1894 On the RS/6000, we have to do this using the .byte operation and
1895 write out special characters outside the quoted string.
1896 Also, the assembler is broken; very long strings are truncated,
1897 so we must artificially break them up early. */
1898
1899void
1900output_ascii (file, p, n)
1901 FILE *file;
1902 char *p;
1903 int n;
1904{
1905 char c;
1906 int i, count_string;
1907 char *for_string = "\t.byte \"";
1908 char *for_decimal = "\t.byte ";
1909 char *to_close = NULL;
1910
1911 count_string = 0;
1912 for (i = 0; i < n; i++)
1913 {
1914 c = *p++;
1915 if (c >= ' ' && c < 0177)
1916 {
1917 if (for_string)
1918 fputs (for_string, file);
1919 putc (c, file);
1920
1921 /* Write two quotes to get one. */
1922 if (c == '"')
1923 {
1924 putc (c, file);
1925 ++count_string;
1926 }
1927
1928 for_string = NULL;
1929 for_decimal = "\"\n\t.byte ";
1930 to_close = "\"\n";
1931 ++count_string;
1932
1933 if (count_string >= 512)
1934 {
1935 fputs (to_close, file);
1936
1937 for_string = "\t.byte \"";
1938 for_decimal = "\t.byte ";
1939 to_close = NULL;
1940 count_string = 0;
1941 }
1942 }
1943 else
1944 {
1945 if (for_decimal)
1946 fputs (for_decimal, file);
1947 fprintf (file, "%d", c);
1948
1949 for_string = "\n\t.byte \"";
1950 for_decimal = ", ";
1951 to_close = "\n";
1952 count_string = 0;
1953 }
1954 }
1955
1956 /* Now close the string if we have written one. Then end the line. */
1957 if (to_close)
1958 fprintf (file, to_close);
1959}
1960\f
1961/* Generate a unique section name for FILENAME for a section type
1962 represented by SECTION_DESC. Output goes into BUF.
1963
1964 SECTION_DESC can be any string, as long as it is different for each
1965 possible section type.
1966
1967 We name the section in the same manner as xlc. The name begins with an
1968 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
1969 names) with the last period replaced by the string SECTION_DESC. If
1970 FILENAME does not contain a period, SECTION_DESC is appended to the end of
1971 the name. */
9878760c
RK
1972
1973void
1974rs6000_gen_section_name (buf, filename, section_desc)
1975 char **buf;
1976 char *filename;
1977 char *section_desc;
1978{
11e5fe42 1979 char *q, *after_last_slash, *last_period;
9878760c
RK
1980 char *p;
1981 int len;
9878760c
RK
1982
1983 after_last_slash = filename;
1984 for (q = filename; *q; q++)
11e5fe42
RK
1985 {
1986 if (*q == '/')
1987 after_last_slash = q + 1;
1988 else if (*q == '.')
1989 last_period = q;
1990 }
9878760c 1991
11e5fe42 1992 len = strlen (after_last_slash) + strlen (section_desc) + 2;
9878760c
RK
1993 *buf = (char *) permalloc (len);
1994
1995 p = *buf;
1996 *p++ = '_';
1997
1998 for (q = after_last_slash; *q; q++)
1999 {
11e5fe42 2000 if (q == last_period)
9878760c
RK
2001 {
2002 strcpy (p, section_desc);
2003 p += strlen (section_desc);
9878760c
RK
2004 }
2005
2006 else if (isalnum (*q))
2007 *p++ = *q;
2008 }
2009
11e5fe42 2010 if (last_period == 0)
9878760c
RK
2011 strcpy (p, section_desc);
2012 else
2013 *p = '\0';
2014}
e165f3f0
RK
2015\f
2016/* Write function profiler code. */
2017
2018void
2019output_function_profiler (file, labelno)
2020 FILE *file;
2021 int labelno;
2022{
2023 /* The last used parameter register. */
2024 int last_parm_reg;
2025 int i, j;
3daf36a4 2026 char buf[100];
e165f3f0
RK
2027
2028 /* Set up a TOC entry for the profiler label. */
2029 toc_section ();
3daf36a4
ILT
2030 ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
2031 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
35fc1624 2032 if (TARGET_MINIMAL_TOC)
3daf36a4
ILT
2033 {
2034 fprintf (file, "\t.long ");
2035 assemble_name (file, buf);
2036 fprintf (file, "\n");
2037 }
35fc1624 2038 else
3daf36a4
ILT
2039 {
2040 fprintf (file, "\t.tc\t");
2041 assemble_name (file, buf);
2042 fprintf (file, "[TC],");
2043 assemble_name (file, buf);
2044 fprintf (file, "\n");
2045 }
e165f3f0
RK
2046 text_section ();
2047
2048 /* Figure out last used parameter register. The proper thing to do is
2049 to walk incoming args of the function. A function might have live
2050 parameter registers even if it has no incoming args. */
2051
2052 for (last_parm_reg = 10;
2053 last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
2054 last_parm_reg--)
2055 ;
2056
2057 /* Save parameter registers in regs 23-30. Don't overwrite reg 31, since
2058 it might be set up as the frame pointer. */
2059
2060 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
2061 fprintf (file, "\tai %d,%d,0\n", j, i);
2062
2063 /* Load location address into r3, and call mcount. */
2064
3daf36a4
ILT
2065 ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
2066 fprintf (file, "\tl 3,");
2067 assemble_name (file, buf);
2068 fprintf (file, "(2)\n\tbl .mcount\n");
e165f3f0
RK
2069
2070 /* Restore parameter registers. */
2071
2072 for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
2073 fprintf (file, "\tai %d,%d,0\n", i, j);
2074}
a251ffd0
TG
2075
2076/* Adjust the cost of a scheduling dependency. Return the new cost of
2077 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
2078
2079int
a06faf84 2080rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
2081 rtx insn;
2082 rtx link;
2083 rtx dep_insn;
2084 int cost;
2085{
2086 if (! recog_memoized (insn))
2087 return 0;
2088
2089 if (REG_NOTE_KIND (link) != 0)
2090 return 0;
2091
2092 if (REG_NOTE_KIND (link) == 0)
2093 {
2094 /* Data dependency; DEP_INSN writes a register that INSN reads some
2095 cycles later. */
2096
2097 /* Tell the first scheduling pass about the latency between a mtctr
2098 and bctr (and mtlr and br/blr). The first scheduling pass will not
2099 know about this latency since the mtctr instruction, which has the
2100 latency associated to it, will be generated by reload. */
2101 if (get_attr_type (insn) == TYPE_JMPREG)
2102 return TARGET_POWER ? 5 : 4;
2103
2104 /* Fall out to return default cost. */
2105 }
2106
2107 return cost;
2108}