]> gcc.gnu.org Git - gcc.git/blame - gcc/config/sparc/sparc.c
Initial revision
[gcc.git] / gcc / config / sparc / sparc.c
CommitLineData
ab835497
RK
1/* Subroutines for insn-output.c for Sun SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
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 "expr.h"
34#include "recog.h"
35
36/* Global variables for machine-dependent things. */
37
38/* Save the operands last given to a compare for use when we
39 generate a scc or bcc insn. */
40
41rtx sparc_compare_op0, sparc_compare_op1;
42
43/* We may need an epilogue if we spill too many registers.
44 If this is non-zero, then we branch here for the epilogue. */
45static rtx leaf_label;
46
47#ifdef LEAF_REGISTERS
48
49/* Vector to say how input registers are mapped to output
50 registers. FRAME_POINTER_REGNUM cannot be remapped by
51 this function to eliminate it. You must use -fomit-frame-pointer
52 to get that. */
53char leaf_reg_remap[] =
54{ 0, 1, 2, 3, 4, 5, 6, 7,
55 -1, -1, -1, -1, -1, -1, 14, -1,
56 -1, -1, -1, -1, -1, -1, -1, -1,
57 8, 9, 10, 11, 12, 13, -1, 15,
58
59 32, 33, 34, 35, 36, 37, 38, 39,
60 40, 41, 42, 43, 44, 45, 46, 47,
61 48, 49, 50, 51, 52, 53, 54, 55,
62 56, 57, 58, 59, 60, 61, 62, 63};
63
64char leaf_reg_backmap[] =
65{ 0, 1, 2, 3, 4, 5, 6, 7,
66 24, 25, 26, 27, 28, 29, 14, 31,
67 -1, -1, -1, -1, -1, -1, -1, -1,
68 -1, -1, -1, -1, -1, -1, -1, -1,
69
70 32, 33, 34, 35, 36, 37, 38, 39,
71 40, 41, 42, 43, 44, 45, 46, 47,
72 48, 49, 50, 51, 52, 53, 54, 55,
73 56, 57, 58, 59, 60, 61, 62, 63};
74#endif
75
76/* Global variables set by FUNCTION_PROLOGUE. */
77/* Size of frame. Need to know this to emit return insns from
78 leaf procedures. */
79int apparent_fsize;
80int actual_fsize;
81
82/* Name of where we pretend to think the frame pointer points.
83 Normally, this is "%fp", but if we are in a leaf procedure,
84 this is "%sp+something". */
85char *frame_base_name;
86
87static rtx find_addr_reg ();
88
89/* Return non-zero only if OP is a register of mode MODE,
90 or const0_rtx. */
91int
92reg_or_0_operand (op, mode)
93 rtx op;
94 enum machine_mode mode;
95{
96 if (op == const0_rtx || register_operand (op, mode))
97 return 1;
98 if (GET_CODE (op) == CONST_DOUBLE
99 && CONST_DOUBLE_HIGH (op) == 0
100 && CONST_DOUBLE_LOW (op) == 0)
101 return 1;
102 return 0;
103}
104
105/* Nonzero if OP can appear as the dest of a RESTORE insn. */
106int
107restore_operand (op, mode)
108 rtx op;
109 enum machine_mode mode;
110{
111 return (GET_CODE (op) == REG && GET_MODE (op) == mode
112 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
113}
114
115/* PC-relative call insn on SPARC is independent of `memory_operand'. */
116
117int
118call_operand (op, mode)
119 rtx op;
120 enum machine_mode mode;
121{
122 if (GET_CODE (op) != MEM)
123 abort ();
124 op = XEXP (op, 0);
125 return (REG_P (op) || CONSTANT_P (op));
126}
127
128int
129call_operand_address (op, mode)
130 rtx op;
131 enum machine_mode mode;
132{
133 return (REG_P (op) || CONSTANT_P (op));
134}
135
136/* Returns 1 if OP is either a symbol reference or a sum of a symbol
137 reference and a constant. */
138
139int
140symbolic_operand (op, mode)
141 register rtx op;
142 enum machine_mode mode;
143{
144 switch (GET_CODE (op))
145 {
146 case SYMBOL_REF:
147 case LABEL_REF:
148 return 1;
149
150 case CONST:
151 op = XEXP (op, 0);
152 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
153 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
154 && GET_CODE (XEXP (op, 1)) == CONST_INT);
155
156 /* This clause seems to be irrelevant. */
157 case CONST_DOUBLE:
158 return GET_MODE (op) == mode;
159
160 default:
161 return 0;
162 }
163}
164
165/* Return truth value of statement that OP is a symbolic memory
166 operand of mode MODE. */
167
168int
169symbolic_memory_operand (op, mode)
170 rtx op;
171 enum machine_mode mode;
172{
173 if (GET_CODE (op) == SUBREG)
174 op = SUBREG_REG (op);
175 if (GET_CODE (op) != MEM)
176 return 0;
177 op = XEXP (op, 0);
178 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
179 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
180}
181
182/* Return 1 if the operand is either a register or a memory operand that is
183 not symbolic. */
184
185int
186reg_or_nonsymb_mem_operand (op, mode)
187 register rtx op;
188 enum machine_mode mode;
189{
190 if (register_operand (op, mode))
191 return 1;
192
193 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
194 return 1;
195
196 return 0;
197}
198
199int
200sparc_operand (op, mode)
201 rtx op;
202 enum machine_mode mode;
203{
204 if (register_operand (op, mode))
205 return 1;
206 if (GET_CODE (op) == CONST_INT)
207 return SMALL_INT (op);
208 if (GET_MODE (op) != mode)
209 return 0;
210 if (GET_CODE (op) == SUBREG)
211 op = SUBREG_REG (op);
212 if (GET_CODE (op) != MEM)
213 return 0;
214
215 op = XEXP (op, 0);
216 if (GET_CODE (op) == LO_SUM)
217 return (GET_CODE (XEXP (op, 0)) == REG
218 && symbolic_operand (XEXP (op, 1), Pmode));
219 return memory_address_p (mode, op);
220}
221
222int
223move_operand (op, mode)
224 rtx op;
225 enum machine_mode mode;
226{
227 if (mode == DImode && arith_double_operand (op, mode))
228 return 1;
229 if (register_operand (op, mode))
230 return 1;
231 if (GET_CODE (op) == CONST_INT)
232 return (SMALL_INT (op) || (INTVAL (op) & 0x3ff) == 0);
233
234 if (GET_MODE (op) != mode)
235 return 0;
236 if (GET_CODE (op) == SUBREG)
237 op = SUBREG_REG (op);
238 if (GET_CODE (op) != MEM)
239 return 0;
240 op = XEXP (op, 0);
241 if (GET_CODE (op) == LO_SUM)
242 return (register_operand (XEXP (op, 0), Pmode)
243 && CONSTANT_P (XEXP (op, 1)));
244 return memory_address_p (mode, op);
245}
246
247int
248move_pic_label (op, mode)
249 rtx op;
250 enum machine_mode mode;
251{
252 /* Special case for PIC. */
253 if (flag_pic && GET_CODE (op) == LABEL_REF)
254 return 1;
255 return 0;
256}
257\f
258/* The rtx for the global offset table which is a special form
259 that *is* a position independent symbolic constant. */
260rtx pic_pc_rtx;
261
262/* Ensure that we are not using patterns that are not OK with PIC. */
263
264int
265check_pic (i)
266 int i;
267{
268 switch (flag_pic)
269 {
270 case 1:
271 if (GET_CODE (recog_operand[i]) == SYMBOL_REF
272 || (GET_CODE (recog_operand[i]) == CONST
273 && ! rtx_equal_p (pic_pc_rtx, recog_operand[i])))
274 abort ();
275 case 2:
276 default:
277 return 1;
278 }
279}
280
281/* Return true if X is an address which needs a temporary register when
282 reloaded while generating PIC code. */
283
284int
285pic_address_needs_scratch (x)
286 rtx x;
287{
288 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
289 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
290 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
291 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
292 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
293 return 1;
294
295 return 0;
296}
297
298int
299memop (op, mode)
300 rtx op;
301 enum machine_mode mode;
302{
303 if (GET_CODE (op) == MEM)
304 return (mode == VOIDmode || mode == GET_MODE (op));
305 return 0;
306}
307
308/* Return truth value of whether OP is EQ or NE. */
309
310int
311eq_or_neq (op, mode)
312 rtx op;
313 enum machine_mode mode;
314{
315 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
316}
317
318/* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
319 or LTU for non-floating-point. We handle those specially. */
320
321int
322normal_comp_operator (op, mode)
323 rtx op;
324 enum machine_mode mode;
325{
326 enum rtx_code code = GET_CODE (op);
327
328 if (GET_RTX_CLASS (code) != '<')
329 return 0;
330
331 if (GET_MODE (XEXP (op, 0)) == CCFPmode)
332 return 1;
333
334 return (code != NE && code != EQ && code != GEU && code != LTU);
335}
336
337/* Return 1 if this is a comparison operator. This allows the use of
338 MATCH_OPERATOR to recognize all the branch insns. */
339
340int
341noov_compare_op (op, mode)
342 register rtx op;
343 enum machine_mode mode;
344{
345 enum rtx_code code = GET_CODE (op);
346
347 if (GET_RTX_CLASS (code) != '<')
348 return 0;
349
350 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode)
351 /* These are the only branches which work with CC_NOOVmode. */
352 return (code == EQ || code == NE || code == GE || code == LT);
353 return 1;
354}
355
356/* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
357
358int
359extend_op (op, mode)
360 rtx op;
361 enum machine_mode mode;
362{
363 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
364}
365
366/* Return nonzero if OP is an operator of mode MODE which can set
367 the condition codes explicitly. We do not include PLUS and MINUS
368 because these require CC_NOOVmode, which we handle explicitly. */
369
370int
371cc_arithop (op, mode)
372 rtx op;
373 enum machine_mode mode;
374{
375 if (GET_CODE (op) == AND
376 || GET_CODE (op) == IOR
377 || GET_CODE (op) == XOR)
378 return 1;
379
380 return 0;
381}
382
383/* Return nonzero if OP is an operator of mode MODE which can bitwise
384 complement its second operand and set the condition codes explicitly. */
385
386int
387cc_arithopn (op, mode)
388 rtx op;
389 enum machine_mode mode;
390{
391 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
392 and (xor ... (not ...)) to (not (xor ...)). */
393 return (GET_CODE (op) == AND
394 || GET_CODE (op) == IOR);
395}
396\f
397/* Return truth value of whether OP can be used as an operands in a three
398 address arithmetic insn (such as add %o1,7,%l2) of mode MODE. */
399
400int
401arith_operand (op, mode)
402 rtx op;
403 enum machine_mode mode;
404{
405 return (register_operand (op, mode)
406 || (GET_CODE (op) == CONST_INT && SMALL_INT (op)));
407}
408
409/* Return truth value of whether OP can be used as an operand in a two
410 address arithmetic insn (such as set 123456,%o4) of mode MODE. */
411
412int
413arith32_operand (op, mode)
414 rtx op;
415 enum machine_mode mode;
416{
417 return (register_operand (op, mode) || GET_CODE (op) == CONST_INT);
418}
419
420/* Return truth value of whether OP is a register or a CONST_DOUBLE. */
421
422int
423arith_double_operand (op, mode)
424 rtx op;
425 enum machine_mode mode;
426{
427 return (register_operand (op, mode)
428 || (GET_CODE (op) == CONST_DOUBLE
429 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
430 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
431 && ((CONST_DOUBLE_HIGH (op) == -1
432 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
433 || (CONST_DOUBLE_HIGH (op) == 0
434 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0)))
435 || (GET_CODE (op) == CONST_INT
436 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
437 && (unsigned) (INTVAL (op) + 0x1000) < 0x2000));
438}
439
440/* Return truth value of whether OP is a integer which fits the
441 range constraining immediate operands in three-address insns. */
442
443int
444small_int (op, mode)
445 rtx op;
446 enum machine_mode mode;
447{
448 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
449}
450
451/* Return truth value of statement that OP is a call-clobbered register. */
452int
453clobbered_register (op, mode)
454 rtx op;
455 enum machine_mode mode;
456{
457 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
458}
459\f
460/* X and Y are two things to compare using CODE. Emit the compare insn and
461 return the rtx for register 0 in the proper mode. */
462
463rtx
464gen_compare_reg (code, x, y)
465 enum rtx_code code;
466 rtx x, y;
467{
468 enum machine_mode mode = SELECT_CC_MODE (code, x);
469 rtx cc_reg = gen_rtx (REG, mode, 0);
470
471 emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
472 gen_rtx (COMPARE, mode, x, y)));
473
474 return cc_reg;
475}
476\f
477/* Return nonzero if a return peephole merging return with
478 setting of output register is ok. */
479int
480leaf_return_peephole_ok ()
481{
482 return (actual_fsize == 0);
483}
484
485/* Return nonzero if TRIAL can go into the function epilogue's
486 delay slot. SLOT is the slot we are trying to fill. */
487
488int
489eligible_for_epilogue_delay (trial, slot)
490 rtx trial;
491 int slot;
492{
493 static char *this_function_name;
494 rtx pat, src;
495
496 if (slot >= 1)
497 return 0;
498 if (GET_CODE (trial) != INSN
499 || GET_CODE (PATTERN (trial)) != SET)
500 return 0;
501 if (get_attr_length (trial) != 1)
502 return 0;
503
504 /* In the case of a true leaf function, anything can
505 go into the delay slot. */
506 if (leaf_function)
507 {
508 if (leaf_return_peephole_ok ())
509 return (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_TRUE);
510 return 0;
511 }
512
513 /* Otherwise, only operations which can be done in tandem with
514 a `restore' insn can go into the delay slot. */
515 pat = PATTERN (trial);
516 if (GET_CODE (SET_DEST (pat)) != REG
517 || REGNO (SET_DEST (pat)) == 0
518 || (leaf_function
519 && REGNO (SET_DEST (pat)) < 32
520 && REGNO (SET_DEST (pat)) >= 16)
521 || (! leaf_function
522 && (REGNO (SET_DEST (pat)) >= 32
523 || REGNO (SET_DEST (pat)) < 24)))
524 return 0;
525 src = SET_SRC (pat);
526 if (arith_operand (src, GET_MODE (src)))
527 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
528 if (arith_double_operand (src, GET_MODE (src)))
529 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
530 if (GET_CODE (src) == PLUS)
531 {
532 if (register_operand (XEXP (src, 0), SImode)
533 && arith_operand (XEXP (src, 1), SImode))
534 return 1;
535 if (register_operand (XEXP (src, 1), SImode)
536 && arith_operand (XEXP (src, 0), SImode))
537 return 1;
538 if (register_operand (XEXP (src, 0), DImode)
539 && arith_double_operand (XEXP (src, 1), DImode))
540 return 1;
541 if (register_operand (XEXP (src, 1), DImode)
542 && arith_double_operand (XEXP (src, 0), DImode))
543 return 1;
544 }
545 if (GET_CODE (src) == MINUS
546 && register_operand (XEXP (src, 0), SImode)
547 && small_int (XEXP (src, 1), VOIDmode))
548 return 1;
549 if (GET_CODE (src) == MINUS
550 && register_operand (XEXP (src, 0), DImode)
551 && !register_operand (XEXP (src, 1), DImode)
552 && arith_double_operand (XEXP (src, 1), DImode))
553 return 1;
554 return 0;
555}
556
557int
558short_branch (uid1, uid2)
559 int uid1, uid2;
560{
561 unsigned int delta = insn_addresses[uid1] - insn_addresses[uid2];
562 if (delta + 1024 < 2048)
563 return 1;
564 /* warning ("long branch, distance %d", delta); */
565 return 0;
566}
567
568/* Return non-zero if REG is not used after INSN.
569 We assume REG is a reload reg, and therefore does
570 not live past labels or calls or jumps. */
571int
572reg_unused_after (reg, insn)
573 rtx reg;
574 rtx insn;
575{
576 enum rtx_code code, prev_code = UNKNOWN;
577
578 while (insn = NEXT_INSN (insn))
579 {
580 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
581 return 1;
582
583 code = GET_CODE (insn);
584 if (GET_CODE (insn) == CODE_LABEL)
585 return 1;
586
587 if (GET_RTX_CLASS (code) == 'i')
588 {
589 rtx set = single_set (insn);
590 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
591 if (set && in_src)
592 return 0;
593 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
594 return 1;
595 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
596 return 0;
597 }
598 prev_code = code;
599 }
600 return 1;
601}
602\f
603/* Legitimize PIC addresses. If the address is already position-independent,
604 we return ORIG. Newly generated position-independent addresses go into a
605 reg. This is REG if non zero, otherwise we allocate register(s) as
606 necessary. If this is called during reload, and we need a second temp
607 register, then we use SCRATCH, which is provided via the
608 SECONDARY_INPUT_RELOAD_CLASS mechanism. */
609
610rtx
611legitimize_pic_address (orig, mode, reg, scratch)
612 rtx orig;
613 enum machine_mode mode;
614 rtx reg, scratch;
615{
616 if (GET_CODE (orig) == SYMBOL_REF)
617 {
618 rtx pic_ref, address;
619 rtx insn;
620
621 if (reg == 0)
622 {
01c0e9dc 623 if (reload_in_progress || reload_completed)
ab835497
RK
624 abort ();
625 else
626 reg = gen_reg_rtx (Pmode);
627 }
628
629 if (flag_pic == 2)
630 {
631 /* If not during reload, allocate another temp reg here for loading
632 in the address, so that these instructions can be optimized
633 properly. */
01c0e9dc
JW
634 rtx temp_reg = ((reload_in_progress || reload_completed)
635 ? reg : gen_reg_rtx (Pmode));
ab835497
RK
636
637 emit_insn (gen_rtx (SET, VOIDmode, temp_reg,
638 gen_rtx (HIGH, Pmode, orig)));
639 emit_insn (gen_rtx (SET, VOIDmode, temp_reg,
640 gen_rtx (LO_SUM, Pmode, temp_reg, orig)));
641 address = temp_reg;
642 }
643 else
644 address = orig;
645
646 pic_ref = gen_rtx (MEM, Pmode,
647 gen_rtx (PLUS, Pmode,
648 pic_offset_table_rtx, address));
649 current_function_uses_pic_offset_table = 1;
650 RTX_UNCHANGING_P (pic_ref) = 1;
651 insn = emit_move_insn (reg, pic_ref);
652 /* Put a REG_EQUAL note on this insn, so that it can be optimized
653 by loop. */
654 REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, orig,
655 REG_NOTES (insn));
656 return reg;
657 }
658 else if (GET_CODE (orig) == CONST)
659 {
660 rtx base, offset;
661
662 if (GET_CODE (XEXP (orig, 0)) == PLUS
663 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
664 return orig;
665
666 if (reg == 0)
667 {
01c0e9dc 668 if (reload_in_progress || reload_completed)
ab835497
RK
669 abort ();
670 else
671 reg = gen_reg_rtx (Pmode);
672 }
673
674 if (GET_CODE (XEXP (orig, 0)) == PLUS)
675 {
676 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode,
677 reg, 0);
678 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
679 base == reg ? 0 : reg, 0);
680 }
681 else
682 abort ();
683
684 if (GET_CODE (offset) == CONST_INT)
685 {
686 if (SMALL_INT (offset))
687 return plus_constant_for_output (base, INTVAL (offset));
01c0e9dc 688 else if (! reload_in_progress && ! reload_completed)
ab835497
RK
689 offset = force_reg (Pmode, offset);
690 /* We can't create any new registers during reload, so use the
691 SCRATCH reg provided by the reload_insi pattern. */
692 else if (scratch)
693 {
694 emit_move_insn (scratch, offset);
695 offset = scratch;
696 }
697 else
698 /* If we reach here, then the SECONDARY_INPUT_RELOAD_CLASS
699 macro needs to be adjusted so that a scratch reg is provided
700 for this address. */
701 abort ();
702 }
703 return gen_rtx (PLUS, Pmode, base, offset);
704 }
705 else if (GET_CODE (orig) == LABEL_REF)
706 current_function_uses_pic_offset_table = 1;
707
708 return orig;
709}
710
711/* Set up PIC-specific rtl. This should not cause any insns
712 to be emitted. */
713
714void
715initialize_pic ()
716{
717}
718
719/* Emit special PIC prologues and epilogues. */
720
721void
722finalize_pic ()
723{
724 /* The table we use to reference PIC data. */
725 rtx global_offset_table;
726 /* Labels to get the PC in the prologue of this function. */
727 rtx l1, l2;
728 rtx seq;
729 int orig_flag_pic = flag_pic;
730
731 if (current_function_uses_pic_offset_table == 0)
732 return;
733
734 if (! flag_pic)
735 abort ();
736
737 flag_pic = 0;
738 l1 = gen_label_rtx ();
739 l2 = gen_label_rtx ();
740
741 start_sequence ();
742
743 emit_label (l1);
744 /* Note that we pun calls and jumps here! */
745 emit_jump_insn (gen_rtx (PARALLEL, VOIDmode,
746 gen_rtvec (2,
747 gen_rtx (SET, VOIDmode, pc_rtx, gen_rtx (LABEL_REF, VOIDmode, l2)),
748 gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, 15), gen_rtx (LABEL_REF, VOIDmode, l2)))));
749 emit_label (l2);
750
751 /* Initialize every time through, since we can't easily
752 know this to be permanent. */
753 global_offset_table = gen_rtx (SYMBOL_REF, Pmode, "*__GLOBAL_OFFSET_TABLE_");
754 pic_pc_rtx = gen_rtx (CONST, Pmode,
755 gen_rtx (MINUS, Pmode,
756 global_offset_table,
757 gen_rtx (CONST, Pmode,
758 gen_rtx (MINUS, Pmode,
759 gen_rtx (LABEL_REF, VOIDmode, l1),
760 pc_rtx))));
761
762 emit_insn (gen_rtx (SET, VOIDmode, pic_offset_table_rtx,
763 gen_rtx (HIGH, Pmode, pic_pc_rtx)));
764 emit_insn (gen_rtx (SET, VOIDmode,
765 pic_offset_table_rtx,
766 gen_rtx (LO_SUM, Pmode,
767 pic_offset_table_rtx, pic_pc_rtx)));
768 emit_insn (gen_rtx (SET, VOIDmode,
769 pic_offset_table_rtx,
770 gen_rtx (PLUS, Pmode,
771 pic_offset_table_rtx, gen_rtx (REG, Pmode, 15))));
772 /* emit_insn (gen_rtx (ASM_INPUT, VOIDmode, "!#PROLOGUE# 1")); */
773 LABEL_PRESERVE_P (l1) = 1;
774 LABEL_PRESERVE_P (l2) = 1;
775 flag_pic = orig_flag_pic;
776
777 seq = gen_sequence ();
778 end_sequence ();
779 emit_insn_after (seq, get_insns ());
780
781 /* Need to emit this whether or not we obey regdecls,
782 since setjmp/longjmp can cause life info to screw up. */
783 emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx));
784}
785\f
786/* For the SPARC, REG and REG+CONST is cost 0, REG+REG is cost 1,
787 and addresses involving symbolic constants are cost 2.
788
789 We make REG+REG slightly more expensive because it might keep
790 a register live for longer than we might like.
791
792 PIC addresses are very expensive.
793
794 It is no coincidence that this has the same structure
795 as GO_IF_LEGITIMATE_ADDRESS. */
796int
797sparc_address_cost (X)
798 rtx X;
799{
800#if 0
801 /* Handled before calling here. */
802 if (GET_CODE (X) == REG)
803 { return 1; }
804#endif
805 if (GET_CODE (X) == PLUS)
806 {
807 if (GET_CODE (XEXP (X, 0)) == REG
808 && GET_CODE (XEXP (X, 1)) == REG)
809 return 2;
810 return 1;
811 }
812 else if (GET_CODE (X) == LO_SUM)
813 return 1;
814 else if (GET_CODE (X) == HIGH)
815 return 2;
816 return 4;
817}
818\f
819/* Emit insns to move operands[1] into operands[0].
820
821 Return 1 if we have written out everything that needs to be done to
822 do the move. Otherwise, return 0 and the caller will emit the move
823 normally.
824
825 SCRATCH_REG if non zero can be used as a scratch register for the move
826 operation. It is provided by a SECONDARY_RELOAD_* macro if needed. */
827
828int
829emit_move_sequence (operands, mode, scratch_reg)
830 rtx *operands;
831 enum machine_mode mode;
832 rtx scratch_reg;
833{
834 register rtx operand0 = operands[0];
835 register rtx operand1 = operands[1];
836
837 /* Handle most common case first: storing into a register. */
838 if (register_operand (operand0, mode))
839 {
840 if (register_operand (operand1, mode)
841 || (GET_CODE (operand1) == CONST_INT && SMALL_INT (operand1))
842 || (GET_CODE (operand1) == CONST_DOUBLE
843 && arith_double_operand (operand1, DImode))
844 || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) != DImode)
845 /* Only `general_operands' can come here, so MEM is ok. */
846 || GET_CODE (operand1) == MEM)
847 {
848 /* Run this case quickly. */
849 emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1));
850 return 1;
851 }
852 }
853 else if (GET_CODE (operand0) == MEM)
854 {
855 if (register_operand (operand1, mode) || operand1 == const0_rtx)
856 {
857 /* Run this case quickly. */
858 emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1));
859 return 1;
860 }
861 if (! reload_in_progress)
862 {
863 operands[0] = validize_mem (operand0);
864 operands[1] = operand1 = force_reg (mode, operand1);
865 }
866 }
867
868 /* Simplify the source if we need to. Must handle DImode HIGH operators
869 here because such a move needs a clobber added. */
870 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
871 || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) == DImode))
872 {
873 if (flag_pic && symbolic_operand (operand1, mode))
874 {
875 rtx temp_reg = reload_in_progress ? operand0 : 0;
876
877 operands[1] = legitimize_pic_address (operand1, mode, temp_reg,
878 scratch_reg);
879 }
880 else if (GET_CODE (operand1) == CONST_INT
881 ? (! SMALL_INT (operand1)
882 && (INTVAL (operand1) & 0x3ff) != 0)
883 : (GET_CODE (operand1) == CONST_DOUBLE
884 ? ! arith_double_operand (operand1, DImode)
885 : 1))
886 {
887 /* For DImode values, temp must be operand0 because of the way
888 HI and LO_SUM work. The LO_SUM operator only copies half of
889 the LSW from the dest of the HI operator. If the LO_SUM dest is
890 not the same as the HI dest, then the MSW of the LO_SUM dest will
891 never be set.
892
893 ??? The real problem here is that the ...(HI:DImode pattern emits
894 multiple instructions, and the ...(LO_SUM:DImode pattern emits
895 one instruction. This fails, because the compiler assumes that
896 LO_SUM copies all bits of the first operand to its dest. Better
897 would be to have the HI pattern emit one instruction and the
898 LO_SUM pattern multiple instructions. Even better would be
899 to use four rtl insns. */
900 rtx temp = ((reload_in_progress || mode == DImode)
901 ? operand0 : gen_reg_rtx (mode));
902
903 emit_insn (gen_rtx (SET, VOIDmode, temp,
904 gen_rtx (HIGH, mode, operand1)));
905 operands[1] = gen_rtx (LO_SUM, mode, temp, operand1);
906 }
907 }
908
909 if (GET_CODE (operand1) == LABEL_REF && flag_pic)
910 {
911 /* The procedure for doing this involves using a call instruction to
912 get the pc into o7. We need to indicate this explicitly because
913 the tablejump pattern assumes that it can use this value also. */
914 emit_insn (gen_rtx (PARALLEL, VOIDmode,
915 gen_rtvec (2,
916 gen_rtx (SET, VOIDmode, operand0,
917 operand1),
918 gen_rtx (SET, VOIDmode,
919 gen_rtx (REG, mode, 15),
920 pc_rtx))));
921 return 1;
922 }
923
924 /* Now have insn-emit do whatever it normally does. */
925 return 0;
926}
927\f
928/* Return the best assembler insn template
929 for moving operands[1] into operands[0] as a fullword. */
930
931char *
932singlemove_string (operands)
933 rtx *operands;
934{
935 if (GET_CODE (operands[0]) == MEM)
936 {
937 if (GET_CODE (operands[1]) != MEM)
938 return "st %r1,%0";
939 else
940 abort ();
941 }
942 if (GET_CODE (operands[1]) == MEM)
943 return "ld %1,%0";
944 if (GET_CODE (operands[1]) == CONST_INT
945 && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'I'))
946 {
947 int i = INTVAL (operands[1]);
948
949 /* If all low order 12 bits are clear, then we only need a single
950 sethi insn to load the constant. */
951 if (i & 0x00000FFF)
952 return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0";
953 else
954 return "sethi %%hi(%a1),%0";
955 }
956 /* ??? Wrong if target is DImode? */
957 return "mov %1,%0";
958}
959\f
960/* Output assembler code to perform a doubleword move insn
961 with operands OPERANDS. */
962
963char *
964output_move_double (operands)
965 rtx *operands;
966{
967 enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
968 rtx latehalf[2];
969 rtx addreg0 = 0, addreg1 = 0;
970
971 /* First classify both operands. */
972
973 if (REG_P (operands[0]))
974 optype0 = REGOP;
975 else if (offsettable_memref_p (operands[0]))
976 optype0 = OFFSOP;
977 else if (GET_CODE (operands[0]) == MEM)
978 optype0 = MEMOP;
979 else
980 optype0 = RNDOP;
981
982 if (REG_P (operands[1]))
983 optype1 = REGOP;
984 else if (CONSTANT_P (operands[1]))
985 optype1 = CNSTOP;
986 else if (offsettable_memref_p (operands[1]))
987 optype1 = OFFSOP;
988 else if (GET_CODE (operands[1]) == MEM)
989 optype1 = MEMOP;
990 else
991 optype1 = RNDOP;
992
993 /* Check for the cases that the operand constraints are not
994 supposed to allow to happen. Abort if we get one,
995 because generating code for these cases is painful. */
996
997 if (optype0 == RNDOP || optype1 == RNDOP)
998 abort ();
999
1000 /* If an operand is an unoffsettable memory ref, find a register
1001 we can increment temporarily to make it refer to the second word. */
1002
1003 if (optype0 == MEMOP)
1004 addreg0 = find_addr_reg (XEXP (operands[0], 0));
1005
1006 if (optype1 == MEMOP)
1007 addreg1 = find_addr_reg (XEXP (operands[1], 0));
1008
1009 /* Ok, we can do one word at a time.
1010 Normally we do the low-numbered word first,
1011 but if either operand is autodecrementing then we
1012 do the high-numbered word first.
1013
1014 In either case, set up in LATEHALF the operands to use for the
1015 high-numbered (least significant) word and in some cases alter the
1016 operands in OPERANDS to be suitable for the low-numbered word. */
1017
1018 if (optype0 == REGOP)
1019 latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
1020 else if (optype0 == OFFSOP)
1021 latehalf[0] = adj_offsettable_operand (operands[0], 4);
1022 else
1023 latehalf[0] = operands[0];
1024
1025 if (optype1 == REGOP)
1026 latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
1027 else if (optype1 == OFFSOP)
1028 latehalf[1] = adj_offsettable_operand (operands[1], 4);
1029 else if (optype1 == CNSTOP)
1030 split_double (operands[1], &operands[1], &latehalf[1]);
1031 else
1032 latehalf[1] = operands[1];
1033
1034 /* If the first move would clobber the source of the second one,
1035 do them in the other order.
1036
1037 RMS says "This happens only for registers;
1038 such overlap can't happen in memory unless the user explicitly
1039 sets it up, and that is an undefined circumstance."
1040
1041 but it happens on the sparc when loading parameter registers,
1042 so I am going to define that circumstance, and make it work
1043 as expected. */
1044
1045 /* Easy case: try moving both words at once. */
1046 /* First check for moving between an even/odd register pair
1047 and a memory location. */
1048 if ((optype0 == REGOP && optype1 != REGOP && optype1 != CNSTOP
1049 && (REGNO (operands[0]) & 1) == 0)
1050 || (optype0 != REGOP && optype0 != CNSTOP && optype1 == REGOP
1051 && (REGNO (operands[1]) & 1) == 0))
1052 {
1053 rtx op1, op2;
1054 rtx base = 0, offset = const0_rtx;
1055
1056 /* OP1 gets the register pair, and OP2 gets the memory address. */
1057 if (optype0 == REGOP)
1058 op1 = operands[0], op2 = operands[1];
1059 else
1060 op1 = operands[1], op2 = operands[0];
1061
1062 /* Now see if we can trust the address to be 8-byte aligned. */
1063 /* Trust global variables. */
1064
1065 if (GET_CODE (op2) == LO_SUM)
1066 {
1067 operands[0] = op1;
1068 operands[1] = op2;
1069
1070 if (final_sequence)
1071 abort ();
1072 return "ldd %1,%0";
1073 }
1074
1075 if (GET_CODE (XEXP (op2, 0)) == PLUS)
1076 {
1077 rtx temp = XEXP (op2, 0);
1078 if (GET_CODE (XEXP (temp, 0)) == REG)
1079 base = XEXP (temp, 0), offset = XEXP (temp, 1);
1080 else if (GET_CODE (XEXP (temp, 1)) == REG)
1081 base = XEXP (temp, 1), offset = XEXP (temp, 0);
1082 }
1083
1084 /* Trust round enough offsets from the stack or frame pointer. */
1085 if (base
1086 && (REGNO (base) == FRAME_POINTER_REGNUM
1087 || REGNO (base) == STACK_POINTER_REGNUM))
1088 {
1089 if (GET_CODE (offset) == CONST_INT
1090 && (INTVAL (offset) & 0x7) == 0)
1091 {
1092 if (op1 == operands[0])
1093 return "ldd %1,%0";
1094 else
1095 return "std %1,%0";
1096 }
1097 }
1098 /* We know structs not on the stack are properly aligned. Since a
1099 double asks for 8-byte alignment, we know it must have got that
1100 if it is in a struct. But a DImode need not be 8-byte aligned,
1101 because it could be a struct containing two ints or pointers. */
1102 else if (GET_CODE (operands[1]) == MEM
1103 && GET_MODE (operands[1]) == DFmode
1104 && (CONSTANT_P (XEXP (operands[1], 0))
1105 /* Let user ask for it anyway. */
1106 || TARGET_ALIGN))
1107 return "ldd %1,%0";
1108 else if (GET_CODE (operands[0]) == MEM
1109 && GET_MODE (operands[0]) == DFmode
1110 && (CONSTANT_P (XEXP (operands[0], 0))
1111 || TARGET_ALIGN))
1112 return "std %1,%0";
1113 }
1114
1115 if (optype0 == REGOP && optype1 == REGOP
1116 && REGNO (operands[0]) == REGNO (latehalf[1]))
1117 {
1118 /* Make any unoffsettable addresses point at high-numbered word. */
1119 if (addreg0)
1120 output_asm_insn ("add %0,0x4,%0", &addreg0);
1121 if (addreg1)
1122 output_asm_insn ("add %0,0x4,%0", &addreg1);
1123
1124 /* Do that word. */
1125 output_asm_insn (singlemove_string (latehalf), latehalf);
1126
1127 /* Undo the adds we just did. */
1128 if (addreg0)
1129 output_asm_insn ("add %0,-0x4,%0", &addreg0);
1130 if (addreg1)
1131 output_asm_insn ("add %0,-0x4,%0", &addreg1);
1132
1133 /* Do low-numbered word. */
1134 return singlemove_string (operands);
1135 }
1136 else if (optype0 == REGOP && optype1 != REGOP
1137 && reg_overlap_mentioned_p (operands[0], operands[1]))
1138 {
1139 /* Do the late half first. */
1140 output_asm_insn (singlemove_string (latehalf), latehalf);
1141 /* Then clobber. */
1142 return singlemove_string (operands);
1143 }
1144
1145 /* Normal case: do the two words, low-numbered first. */
1146
1147 output_asm_insn (singlemove_string (operands), operands);
1148
1149 /* Make any unoffsettable addresses point at high-numbered word. */
1150 if (addreg0)
1151 output_asm_insn ("add %0,0x4,%0", &addreg0);
1152 if (addreg1)
1153 output_asm_insn ("add %0,0x4,%0", &addreg1);
1154
1155 /* Do that word. */
1156 output_asm_insn (singlemove_string (latehalf), latehalf);
1157
1158 /* Undo the adds we just did. */
1159 if (addreg0)
1160 output_asm_insn ("add %0,-0x4,%0", &addreg0);
1161 if (addreg1)
1162 output_asm_insn ("add %0,-0x4,%0", &addreg1);
1163
1164 return "";
1165}
1166\f
1167char *
1168output_fp_move_double (operands)
1169 rtx *operands;
1170{
1171 rtx addr;
1172
1173 if (FP_REG_P (operands[0]))
1174 {
1175 if (FP_REG_P (operands[1]))
1176 return "fmovs %1,%0\n\tfmovs %R1,%R0";
1177 if (GET_CODE (operands[1]) == REG)
1178 {
1179 if ((REGNO (operands[1]) & 1) == 0)
1180 return "std %1,[%@-8]\n\tldd [%@-8],%0";
1181 else
1182 return "st %R1,[%@-4]\n\tst %1,[%@-8]\n\tldd [%@-8],%0";
1183 }
1184 addr = XEXP (operands[1], 0);
1185
1186 /* Use ldd if known to be aligned. */
1187 if (TARGET_ALIGN
1188 || (GET_CODE (addr) == PLUS
1189 && (((XEXP (addr, 0) == frame_pointer_rtx
1190 || XEXP (addr, 0) == stack_pointer_rtx)
1191 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1192 && (INTVAL (XEXP (addr, 1)) & 0x7) == 0)
1193 /* Arrays are known to be aligned,
1194 and reg+reg addresses are used (on this machine)
1195 only for array accesses. */
1196 || (REG_P (XEXP (addr, 0)) && REG_P (XEXP (addr, 1)))))
1197 || (GET_MODE (operands[0]) == DFmode
1198 && (GET_CODE (addr) == LO_SUM || CONSTANT_P (addr))))
1199 return "ldd %1,%0";
1200
1201 /* Otherwise use two ld insns. */
1202 operands[2]
1203 = gen_rtx (MEM, GET_MODE (operands[1]),
1204 plus_constant_for_output (addr, 4));
1205 return "ld %1,%0\n\tld %2,%R0";
1206 }
1207 else if (FP_REG_P (operands[1]))
1208 {
1209 if (GET_CODE (operands[0]) == REG)
1210 {
1211 if ((REGNO (operands[0]) & 1) == 0)
1212 return "std %1,[%@-8]\n\tldd [%@-8],%0";
1213 else
1214 return "std %1,[%@-8]\n\tld [%@-4],%R0\n\tld [%@-8],%0";
1215 }
1216 addr = XEXP (operands[0], 0);
1217
1218 /* Use std if we can be sure it is well-aligned. */
1219 if (TARGET_ALIGN
1220 || (GET_CODE (addr) == PLUS
1221 && (((XEXP (addr, 0) == frame_pointer_rtx
1222 || XEXP (addr, 0) == stack_pointer_rtx)
1223 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1224 && (INTVAL (XEXP (addr, 1)) & 0x7) == 0)
1225 /* Arrays are known to be aligned,
1226 and reg+reg addresses are used (on this machine)
1227 only for array accesses. */
1228 || (REG_P (XEXP (addr, 0)) && REG_P (XEXP (addr, 1)))))
1229 || (GET_MODE (operands[1]) == DFmode
1230 && (GET_CODE (addr) == LO_SUM || CONSTANT_P (addr))))
1231 return "std %1,%0";
1232
1233 /* Otherwise use two st insns. */
1234 operands[2]
1235 = gen_rtx (MEM, GET_MODE (operands[0]),
1236 plus_constant_for_output (addr, 4));
1237 return "st %r1,%0\n\tst %R1,%2";
1238 }
1239 else abort ();
1240}
1241\f
1242/* Return a REG that occurs in ADDR with coefficient 1.
1243 ADDR can be effectively incremented by incrementing REG. */
1244
1245static rtx
1246find_addr_reg (addr)
1247 rtx addr;
1248{
1249 while (GET_CODE (addr) == PLUS)
1250 {
1251 /* We absolutely can not fudge the frame pointer here, because the
1252 frame pointer must always be 8 byte aligned. It also confuses
1253 debuggers. */
1254 if (GET_CODE (XEXP (addr, 0)) == REG
1255 && REGNO (XEXP (addr, 0)) != FRAME_POINTER_REGNUM)
1256 addr = XEXP (addr, 0);
1257 else if (GET_CODE (XEXP (addr, 1)) == REG
1258 && REGNO (XEXP (addr, 1)) != FRAME_POINTER_REGNUM)
1259 addr = XEXP (addr, 1);
1260 else if (CONSTANT_P (XEXP (addr, 0)))
1261 addr = XEXP (addr, 1);
1262 else if (CONSTANT_P (XEXP (addr, 1)))
1263 addr = XEXP (addr, 0);
1264 else
1265 abort ();
1266 }
1267 if (GET_CODE (addr) == REG)
1268 return addr;
1269 abort ();
1270}
1271
1272void
1273output_sized_memop (opname, mode, signedp)
1274 char *opname;
1275 enum machine_mode mode;
1276 int signedp;
1277{
1278 static char *ld_size_suffix_u[] = { "ub", "uh", "", "?", "d" };
1279 static char *ld_size_suffix_s[] = { "sb", "sh", "", "?", "d" };
1280 static char *st_size_suffix[] = { "b", "h", "", "?", "d" };
1281 char **opnametab, *modename;
1282
1283 if (opname[0] == 'l')
1284 if (signedp)
1285 opnametab = ld_size_suffix_s;
1286 else
1287 opnametab = ld_size_suffix_u;
1288 else
1289 opnametab = st_size_suffix;
1290 modename = opnametab[GET_MODE_SIZE (mode) >> 1];
1291
1292 fprintf (asm_out_file, "\t%s%s", opname, modename);
1293}
1294\f
1295void
1296output_move_with_extension (operands)
1297 rtx *operands;
1298{
1299 if (GET_MODE (operands[2]) == HImode)
1300 output_asm_insn ("sll %2,0x10,%0", operands);
1301 else if (GET_MODE (operands[2]) == QImode)
1302 output_asm_insn ("sll %2,0x18,%0", operands);
1303 else
1304 abort ();
1305}
1306\f
1307/* Load the address specified by OPERANDS[3] into the register
1308 specified by OPERANDS[0].
1309
1310 OPERANDS[3] may be the result of a sum, hence it could either be:
1311
1312 (1) CONST
1313 (2) REG
1314 (2) REG + CONST_INT
1315 (3) REG + REG + CONST_INT
1316 (4) REG + REG (special case of 3).
1317
1318 Note that (3) is not a legitimate address.
1319 All cases are handled here. */
1320
1321void
1322output_load_address (operands)
1323 rtx *operands;
1324{
1325 rtx base, offset;
1326
1327 if (CONSTANT_P (operands[3]))
1328 {
1329 output_asm_insn ("set %3,%0", operands);
1330 return;
1331 }
1332
1333 if (REG_P (operands[3]))
1334 {
1335 if (REGNO (operands[0]) != REGNO (operands[3]))
1336 output_asm_insn ("mov %3,%0", operands);
1337 return;
1338 }
1339
1340 if (GET_CODE (operands[3]) != PLUS)
1341 abort ();
1342
1343 base = XEXP (operands[3], 0);
1344 offset = XEXP (operands[3], 1);
1345
1346 if (GET_CODE (base) == CONST_INT)
1347 {
1348 rtx tmp = base;
1349 base = offset;
1350 offset = tmp;
1351 }
1352
1353 if (GET_CODE (offset) != CONST_INT)
1354 {
1355 /* Operand is (PLUS (REG) (REG)). */
1356 base = operands[3];
1357 offset = const0_rtx;
1358 }
1359
1360 if (REG_P (base))
1361 {
1362 operands[6] = base;
1363 operands[7] = offset;
1364 if (SMALL_INT (offset))
1365 output_asm_insn ("add %6,%7,%0", operands);
1366 else
1367 output_asm_insn ("set %7,%0\n\tadd %0,%6,%0", operands);
1368 }
1369 else if (GET_CODE (base) == PLUS)
1370 {
1371 operands[6] = XEXP (base, 0);
1372 operands[7] = XEXP (base, 1);
1373 operands[8] = offset;
1374
1375 if (SMALL_INT (offset))
1376 output_asm_insn ("add %6,%7,%0\n\tadd %0,%8,%0", operands);
1377 else
1378 output_asm_insn ("set %8,%0\n\tadd %0,%6,%0\n\tadd %0,%7,%0", operands);
1379 }
1380 else
1381 abort ();
1382}
1383
1384/* Output code to place a size count SIZE in register REG.
1385 ALIGN is the size of the unit of transfer.
1386
1387 Because block moves are pipelined, we don't include the
1388 first element in the transfer of SIZE to REG. */
1389
1390static void
1391output_size_for_block_move (size, reg, align)
1392 rtx size, reg;
1393 rtx align;
1394{
1395 rtx xoperands[3];
1396
1397 xoperands[0] = reg;
1398 xoperands[1] = size;
1399 xoperands[2] = align;
1400 if (GET_CODE (size) == REG)
1401 output_asm_insn ("sub %1,%2,%0", xoperands);
1402 else
1403 {
1404 xoperands[1]
1405 = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - INTVAL (align));
1406 output_asm_insn ("set %1,%0", xoperands);
1407 }
1408}
1409
1410/* Emit code to perform a block move.
1411
1412 OPERANDS[0] is the destination.
1413 OPERANDS[1] is the source.
1414 OPERANDS[2] is the size.
1415 OPERANDS[3] is the alignment safe to use.
1416 OPERANDS[4] is a register we can safely clobber as a temp. */
1417
1418char *
1419output_block_move (operands)
1420 rtx *operands;
1421{
1422 /* A vector for our computed operands. Note that load_output_address
1423 makes use of (and can clobber) up to the 8th element of this vector. */
1424 rtx xoperands[10];
1425 rtx zoperands[10];
1426 static int movstrsi_label = 0;
1427 int i;
1428 rtx temp1 = operands[4];
1429 rtx sizertx = operands[2];
1430 rtx alignrtx = operands[3];
1431 int align = INTVAL (alignrtx);
1432
1433 xoperands[0] = operands[0];
1434 xoperands[1] = operands[1];
1435 xoperands[2] = temp1;
1436
1437 /* We can't move more than this many bytes at a time
1438 because we have only one register to move them through. */
1439 if (align > GET_MODE_SIZE (GET_MODE (temp1)))
1440 {
1441 align = GET_MODE_SIZE (GET_MODE (temp1));
1442 alignrtx = gen_rtx (CONST_INT, VOIDmode, GET_MODE_SIZE (GET_MODE (temp1)));
1443 }
1444
1445 /* If the size isn't known to be a multiple of the alignment,
1446 we have to do it in smaller pieces. If we could determine that
1447 the size was a multiple of 2 (or whatever), we could be smarter
1448 about this. */
1449 if (GET_CODE (sizertx) != CONST_INT)
1450 align = 1;
1451 else
1452 {
1453 int size = INTVAL (sizertx);
1454 while (size % align)
1455 align >>= 1;
1456 }
1457
1458 if (align != INTVAL (alignrtx))
1459 alignrtx = gen_rtx (CONST_INT, VOIDmode, align);
1460
1461 /* Recognize special cases of block moves. These occur
1462 when GNU C++ is forced to treat something as BLKmode
1463 to keep it in memory, when its mode could be represented
1464 with something smaller.
1465
1466 We cannot do this for global variables, since we don't know
1467 what pages they don't cross. Sigh. */
1468 if (GET_CODE (sizertx) == CONST_INT && INTVAL (sizertx) <= 16)
1469 {
1470 int size = INTVAL (sizertx);
1471
1472 if (align == 1)
1473 {
1474 if (memory_address_p (QImode,
1475 plus_constant_for_output (xoperands[0], size))
1476 && memory_address_p (QImode,
1477 plus_constant_for_output (xoperands[1],
1478 size)))
1479 {
1480 /* We will store different integers into this particular RTX. */
1481 xoperands[2] = rtx_alloc (CONST_INT);
1482 PUT_MODE (xoperands[2], VOIDmode);
1483 for (i = size-1; i >= 0; i--)
1484 {
1485 INTVAL (xoperands[2]) = i;
1486 output_asm_insn ("ldub [%a1+%2],%%g1\n\tstb %%g1,[%a0+%2]",
1487 xoperands);
1488 }
1489 return "";
1490 }
1491 }
1492 else if (align == 2)
1493 {
1494 if (memory_address_p (HImode,
1495 plus_constant_for_output (xoperands[0], size))
1496 && memory_address_p (HImode,
1497 plus_constant_for_output (xoperands[1],
1498 size)))
1499 {
1500 /* We will store different integers into this particular RTX. */
1501 xoperands[2] = rtx_alloc (CONST_INT);
1502 PUT_MODE (xoperands[2], VOIDmode);
1503 for (i = (size>>1)-1; i >= 0; i--)
1504 {
1505 INTVAL (xoperands[2]) = i<<1;
1506 output_asm_insn ("lduh [%a1+%2],%%g1\n\tsth %%g1,[%a0+%2]",
1507 xoperands);
1508 }
1509 return "";
1510 }
1511 }
1512 else
1513 {
1514 if (memory_address_p (SImode,
1515 plus_constant_for_output (xoperands[0], size))
1516 && memory_address_p (SImode,
1517 plus_constant_for_output (xoperands[1],
1518 size)))
1519 {
1520 /* We will store different integers into this particular RTX. */
1521 xoperands[2] = rtx_alloc (CONST_INT);
1522 PUT_MODE (xoperands[2], VOIDmode);
1523 for (i = (size>>2)-1; i >= 0; i--)
1524 {
1525 INTVAL (xoperands[2]) = i<<2;
1526 output_asm_insn ("ld [%a1+%2],%%g1\n\tst %%g1,[%a0+%2]",
1527 xoperands);
1528 }
1529 return "";
1530 }
1531 }
1532 }
1533
1534 xoperands[3] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
1535 xoperands[4] = gen_rtx (CONST_INT, VOIDmode, align);
1536 xoperands[5] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
1537
1538 /* This is the size of the transfer.
1539 Either use the register which already contains the size,
1540 or use a free register (used by no operands).
1541 Also emit code to decrement the size value by ALIGN. */
1542 output_size_for_block_move (sizertx, temp1, alignrtx);
1543
1544 /* Must handle the case when the size is zero or negative, so the first thing
1545 we do is compare the size against zero, and only copy bytes if it is
1546 zero or greater. Note that we have already subtracted off the alignment
1547 once, so we must copy 1 alignment worth of bytes if the size is zero
1548 here.
1549
1550 The SUN assembler complains about labels in branch delay slots, so we
1551 do this before outputing the load address, so that there will always
1552 be a harmless insn between the branch here and the next label emitted
1553 below. */
1554
1555#ifdef NO_UNDERSCORES
1556 output_asm_insn ("cmp %2,0\n\tbl .Lm%5", xoperands);
1557#else
1558 output_asm_insn ("cmp %2,0\n\tbl Lm%5", xoperands);
1559#endif
1560
1561 zoperands[0] = operands[0];
1562 zoperands[3] = plus_constant_for_output (operands[0], align);
1563 output_load_address (zoperands);
1564
1565 /* ??? This might be much faster if the loops below were preconditioned
1566 and unrolled.
1567
1568 That is, at run time, copy enough bytes one at a time to ensure that the
1569 target and source addresses are aligned to the the largest possible
1570 alignment. Then use a preconditioned unrolled loop to copy say 16
1571 bytes at a time. Then copy bytes one at a time until finish the rest. */
1572
1573 /* Output the first label separately, so that it is spaced properly. */
1574
1575#ifdef NO_UNDERSCORES
1576 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, ".Lm", INTVAL (xoperands[3]));
1577#else
1578 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "Lm", INTVAL (xoperands[3]));
1579#endif
1580
1581#ifdef NO_UNDERSCORES
1582 if (align == 1)
1583 output_asm_insn ("ldub [%1+%2],%%g1\n\tsubcc %2,%4,%2\n\tbge .Lm%3\n\tstb %%g1,[%0+%2]\n.Lm%5:", xoperands);
1584 else if (align == 2)
1585 output_asm_insn ("lduh [%1+%2],%%g1\n\tsubcc %2,%4,%2\n\tbge .Lm%3\n\tsth %%g1,[%0+%2]\n.Lm%5:", xoperands);
1586 else
1587 output_asm_insn ("ld [%1+%2],%%g1\n\tsubcc %2,%4,%2\n\tbge .Lm%3\n\tst %%g1,[%0+%2]\n.Lm%5:", xoperands);
1588 return "";
1589#else
1590 if (align == 1)
1591 output_asm_insn ("ldub [%1+%2],%%g1\n\tsubcc %2,%4,%2\n\tbge Lm%3\n\tstb %%g1,[%0+%2]\nLm%5:", xoperands);
1592 else if (align == 2)
1593 output_asm_insn ("lduh [%1+%2],%%g1\n\tsubcc %2,%4,%2\n\tbge Lm%3\n\tsth %%g1,[%0+%2]\nLm%5:", xoperands);
1594 else
1595 output_asm_insn ("ld [%1+%2],%%g1\n\tsubcc %2,%4,%2\n\tbge Lm%3\n\tst %%g1,[%0+%2]\nLm%5:", xoperands);
1596 return "";
1597#endif
1598}
1599\f
1600/* Output reasonable peephole for set-on-condition-code insns.
1601 Note that these insns assume a particular way of defining
1602 labels. Therefore, *both* sparc.h and this function must
1603 be changed if a new syntax is needed. */
1604
1605char *
1606output_scc_insn (operands, insn)
1607 rtx operands[];
1608 rtx insn;
1609{
1610 static char string[100];
1611 rtx label = 0, next = insn;
1612 int need_label = 0;
1613
1614 /* Try doing a jump optimization which jump.c can't do for us
1615 because we did not expose that setcc works by using branches.
1616
1617 If this scc insn is followed by an unconditional branch, then have
1618 the jump insn emitted here jump to that location, instead of to
1619 the end of the scc sequence as usual. */
1620
1621 do
1622 {
1623 if (GET_CODE (next) == CODE_LABEL)
1624 label = next;
1625 next = NEXT_INSN (next);
1626 if (next == 0)
1627 break;
1628 }
1629 while (GET_CODE (next) == NOTE || GET_CODE (next) == CODE_LABEL);
1630
1631 /* If we are in a sequence, and the following insn is a sequence also,
1632 then just following the current insn's next field will take us to the
1633 first insn of the next sequence, which is the wrong place. We don't
1634 want to optimize with a branch that has had its delay slot filled.
1635 Avoid this by verifying that NEXT_INSN (PREV_INSN (next)) == next
1636 which fails only if NEXT is such a branch. */
1637
1638 if (next && GET_CODE (next) == JUMP_INSN && simplejump_p (next)
1639 && (! final_sequence || NEXT_INSN (PREV_INSN (next)) == next))
1640 label = JUMP_LABEL (next);
1641 /* If not optimizing, jump label fields are not set. To be safe, always
1642 check here to whether label is still zero. */
1643 if (label == 0)
1644 {
1645 label = gen_label_rtx ();
1646 need_label = 1;
1647 }
1648
1649 LABEL_NUSES (label) += 1;
1650
1651 operands[2] = label;
1652
1653 /* If we are in a delay slot, assume it is the delay slot of an fpcc
1654 insn since our type isn't allowed anywhere else. */
1655
1656 /* ??? Fpcc instructions no longer have delay slots, so this code is
1657 probably obsolete. */
1658
1659 /* The fastest way to emit code for this is an annulled branch followed
1660 by two move insns. This will take two cycles if the branch is taken,
1661 and three cycles if the branch is not taken.
1662
1663 However, if we are in the delay slot of another branch, this won't work,
1664 because we can't put a branch in the delay slot of another branch.
1665 The above sequence would effectively take 3 or 4 cycles respectively
1666 since a no op would have be inserted between the two branches.
1667 In this case, we want to emit a move, annulled branch, and then the
1668 second move. This sequence always takes 3 cycles, and hence is faster
1669 when we are in a branch delay slot. */
1670
1671 if (final_sequence)
1672 {
1673 strcpy (string, "mov 0,%0\n\t");
1674 strcat (string, output_cbranch (operands[1], 2, 0, 1, 0));
1675 strcat (string, "\n\tmov 1,%0");
1676 }
1677 else
1678 {
1679 strcpy (string, output_cbranch (operands[1], 2, 0, 1, 0));
1680 strcat (string, "\n\tmov 1,%0\n\tmov 0,%0");
1681 }
1682
1683 if (need_label)
1684 strcat (string, "\n%l2:");
1685
1686 return string;
1687}
1688\f
1689/* Vectors to keep interesting information about registers where
1690 it can easily be got. */
1691
1692/* Modes for condition codes. */
1693#define C_MODES \
1694 ((1 << (int) CCmode) | (1 << (int) CC_NOOVmode) | (1 << (int) CCFPmode))
1695
1696/* Modes for single-word (and smaller) quantities. */
1697#define S_MODES \
1698 (~C_MODES \
1699 & ~ ((1 << (int) DImode) | (1 << (int) TImode) \
1700 | (1 << (int) DFmode) | (1 << (int) TFmode)))
1701
1702/* Modes for double-word (and smaller) quantities. */
1703#define D_MODES \
1704 (~C_MODES \
1705 & ~ ((1 << (int) TImode) | (1 << (int) TFmode)))
1706
1707/* Modes for quad-word quantities. */
1708#define T_MODES (~C_MODES)
1709
1710/* Modes for single-float quantities. */
1711#define SF_MODES ((1 << (int) SFmode))
1712
1713/* Modes for double-float quantities. */
1714#define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode))
1715
1716/* Modes for quad-float quantities. */
1717#define TF_MODES (DF_MODES | (1 << (int) TFmode) | (1 << (int) DCmode))
1718
1719/* Value is 1 if register/mode pair is acceptable on sparc.
1720 The funny mixture of D and T modes is because integer operations
1721 do not specially operate on tetra quantities, so non-quad-aligned
1722 registers can hold quadword quantities (except %o4 and %i4 because
1723 they cross fixed registers. */
1724
1725int hard_regno_mode_ok[] = {
1726 C_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1727 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
1728 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1729 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
1730
1731 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
1732 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
1733 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
1734 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES};
1735\f
1736#ifdef __GNUC__
1737inline
1738#endif
1739static int
1740save_regs (file, low, high, base, offset, n_fregs)
1741 FILE *file;
1742 int low, high;
1743 char *base;
1744 int offset;
1745 int n_fregs;
1746{
1747 int i;
1748
1749 for (i = low; i < high; i += 2)
1750 {
1751 if (regs_ever_live[i] && ! call_used_regs[i])
1752 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1753 fprintf (file, "\tstd %s,[%s+%d]\n",
1754 reg_names[i], base, offset + 4 * n_fregs),
1755 n_fregs += 2;
1756 else
1757 fprintf (file, "\tst %s,[%s+%d]\n",
1758 reg_names[i], base, offset + 4 * n_fregs),
1759 n_fregs += 2;
1760 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1761 fprintf (file, "\tst %s,[%s+%d]\n",
1762 reg_names[i+1], base, offset + 4 * n_fregs),
1763 n_fregs += 2;
1764 }
1765 return n_fregs;
1766}
1767
1768#ifdef __GNUC__
1769inline
1770#endif
1771static int
1772restore_regs (file, low, high, base, offset, n_fregs)
1773 FILE *file;
1774 int low, high;
1775 char *base;
1776 int offset;
1777{
1778 int i;
1779
1780 for (i = low; i < high; i += 2)
1781 {
1782 if (regs_ever_live[i] && ! call_used_regs[i])
1783 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1784 fprintf (file, "\tldd [%s+%d], %s\n",
1785 base, offset + 4 * n_fregs, reg_names[i]),
1786 n_fregs += 2;
1787 else
1788 fprintf (file, "\tld [%s+%d],%s\n",
1789 base, offset + 4 * n_fregs, reg_names[i]),
1790 n_fregs += 2;
1791 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1792 fprintf (file, "\tld [%s+%d],%s\n",
1793 base, offset + 4 * n_fregs, reg_names[i+1]),
1794 n_fregs += 2;
1795 }
1796 return n_fregs;
1797}
1798
1799/* Static variables we want to share between prologue and epilogue. */
1800
1801/* Number of live floating point registers needed to be saved. */
1802static int num_fregs;
1803
1804/* Nonzero if any floating point register was ever used. */
1805static int fregs_ever_live;
1806
1807int
1808compute_frame_size (size, leaf_function)
1809 int size;
1810 int leaf_function;
1811{
1812 int fregs_ever_live = 0;
1813 int n_fregs = 0, i;
1814 int outgoing_args_size = (current_function_outgoing_args_size
1815 + REG_PARM_STACK_SPACE (current_function_decl));
1816
1817 apparent_fsize = ((size) + 7 - STARTING_FRAME_OFFSET) & -8;
1818 for (i = 32; i < FIRST_PSEUDO_REGISTER; i += 2)
1819 fregs_ever_live |= regs_ever_live[i]|regs_ever_live[i+1];
1820
1821 if (TARGET_EPILOGUE && fregs_ever_live)
1822 {
1823 for (i = 32; i < FIRST_PSEUDO_REGISTER; i += 2)
1824 if ((regs_ever_live[i] && ! call_used_regs[i])
1825 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
1826 n_fregs += 2;
1827 }
1828
1829 /* Set up values for use in `function_epilogue'. */
1830 num_fregs = n_fregs;
1831
1832 apparent_fsize += (outgoing_args_size+7) & -8;
1833 if (leaf_function && n_fregs == 0
1834 && apparent_fsize == (REG_PARM_STACK_SPACE (current_function_decl)
1835 - STARTING_FRAME_OFFSET))
1836 apparent_fsize = 0;
1837
1838 actual_fsize = apparent_fsize + n_fregs*4;
1839
1840 /* Make sure nothing can clobber our register windows.
1841 If a SAVE must be done, or there is a stack-local variable,
1842 the register window area must be allocated. */
1843 if (leaf_function == 0 || size > 0)
1844 actual_fsize += (16 * UNITS_PER_WORD)+8;
1845
1846 return actual_fsize;
1847}
1848
1849void
1850output_function_prologue (file, size, leaf_function)
1851 FILE *file;
1852 int size;
1853{
1854 if (leaf_function)
1855 frame_base_name = "%sp+80";
1856 else
1857 frame_base_name = "%fp";
1858
1859 actual_fsize = compute_frame_size (size, leaf_function);
1860
1861 fprintf (file, "\t!#PROLOGUE# 0\n");
1862 if (actual_fsize == 0) /* do nothing. */ ;
1863 else if (actual_fsize < 4096)
1864 {
1865 if (! leaf_function)
1866 fprintf (file, "\tsave %%sp,-%d,%%sp\n", actual_fsize);
1867 else
1868 fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize);
1869 }
1870 else if (! leaf_function)
1871 {
1872 /* Need to use actual_fsize, since we are also allocating space for
1873 our callee (and our own register save area). */
1874 fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n",
1875 -actual_fsize, -actual_fsize);
1876 fprintf (file, "\tsave %%sp,%%g1,%%sp\n");
1877 }
1878 else
1879 {
1880 /* Put pointer to parameters into %g4, and allocate
1881 frame space using result computed into %g1. actual_fsize
1882 used instead of apparent_fsize for reasons stated above. */
1883 abort ();
1884
1885 fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n",
1886 -actual_fsize, -actual_fsize);
1887 fprintf (file, "\tadd %%sp,64,%%g4\n\tadd %%sp,%%g1,%%sp\n");
1888 }
1889
1890 /* If doing anything with PIC, do it now. */
1891 if (! flag_pic)
1892 fprintf (file, "\t!#PROLOGUE# 1\n");
1893
1894 /* Figure out where to save any special registers. */
1895 if (num_fregs)
1896 {
1897 int offset, n_fregs = num_fregs;
1898
1899 if (! leaf_function)
1900 offset = -apparent_fsize;
1901 else
1902 offset = 0;
1903
1904 if (TARGET_EPILOGUE && ! leaf_function)
1905 n_fregs = save_regs (file, 0, 16, frame_base_name, offset, 0);
1906 else if (leaf_function)
1907 n_fregs = save_regs (file, 0, 32, frame_base_name, offset, 0);
1908 if (TARGET_EPILOGUE)
1909 save_regs (file, 32, FIRST_PSEUDO_REGISTER,
1910 frame_base_name, offset, n_fregs);
1911 }
1912
1913 if (regs_ever_live[62])
1914 fprintf (file, "\tst %s,[%s-16]\n\tst %s,[%s-12]\n",
1915 reg_names[0], frame_base_name,
1916 reg_names[0], frame_base_name);
1917
1918 leaf_label = 0;
1919 if (leaf_function && actual_fsize != 0)
1920 {
1921 /* warning ("leaf procedure with frame size %d", actual_fsize); */
1922 if (! TARGET_EPILOGUE)
1923 leaf_label = gen_label_rtx ();
1924 }
1925}
1926
1927void
1928output_function_epilogue (file, size, leaf_function, true_epilogue)
1929 FILE *file;
1930 int size;
1931{
1932 int n_fregs, i;
1933 char *ret;
1934
1935 if (leaf_label)
1936 {
1937 if (leaf_function < 0)
1938 abort ();
1939 emit_label_after (leaf_label, get_last_insn ());
1940 final_scan_insn (get_last_insn (), file, 0, 0, 1);
1941 }
1942
1943 if (num_fregs)
1944 {
1945 int offset, n_fregs = num_fregs;
1946
1947 if (! leaf_function)
1948 offset = -apparent_fsize;
1949 else
1950 offset = 0;
1951
1952 if (TARGET_EPILOGUE && ! leaf_function)
1953 n_fregs = restore_regs (file, 0, 16, frame_base_name, offset, 0);
1954 else if (leaf_function)
1955 n_fregs = restore_regs (file, 0, 32, frame_base_name, offset, 0);
1956 if (TARGET_EPILOGUE)
1957 restore_regs (file, 32, FIRST_PSEUDO_REGISTER,
1958 frame_base_name, offset, n_fregs);
1959 }
1960
1961 /* Work out how to skip the caller's unimp instruction if required. */
1962 if (leaf_function)
1963 ret = (current_function_returns_struct ? "jmp %o7+12" : "retl");
1964 else
1965 ret = (current_function_returns_struct ? "jmp %i7+12" : "ret");
1966
1967 /* Tail calls have to do this work themselves. */
1968 if (leaf_function >= 0)
1969 {
1970 if (TARGET_EPILOGUE || leaf_label)
1971 {
1972 int old_target_epilogue = TARGET_EPILOGUE;
1973 target_flags &= ~old_target_epilogue;
1974
1975 if (! leaf_function)
1976 {
1977 /* If we wound up with things in our delay slot,
1978 flush them here. */
1979 if (current_function_epilogue_delay_list)
1980 {
1981 rtx insn = emit_jump_insn_after (gen_rtx (RETURN, VOIDmode),
1982 get_last_insn ());
1983 PATTERN (insn) = gen_rtx (PARALLEL, VOIDmode,
1984 gen_rtvec (2,
1985 PATTERN (XEXP (current_function_epilogue_delay_list, 0)),
1986 PATTERN (insn)));
1987 final_scan_insn (insn, file, 1, 0, 1);
1988 }
1989 else
1990 fprintf (file, "\t%s\n\trestore\n", ret);
1991 }
1992 else if (actual_fsize < 4096)
1993 {
1994 if (current_function_epilogue_delay_list)
1995 {
1996 fprintf (file, "\t%s\n", ret);
1997 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1998 file, 1, 0, 1);
1999 }
2000 else
2001 fprintf (file, "\t%s\n\tadd %%sp,%d,%%sp\n",
2002 ret, actual_fsize);
2003 }
2004 else
2005 {
2006 if (current_function_epilogue_delay_list)
2007 abort ();
2008 fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n",
2009 actual_fsize, actual_fsize, ret);
2010 }
2011 target_flags |= old_target_epilogue;
2012 }
2013 }
2014 else if (true_epilogue)
2015 {
2016 /* We may still need a return insn! Somebody could jump around
2017 the tail-calls that this function makes. */
2018 if (TARGET_EPILOGUE)
2019 {
2020 rtx last = get_last_insn ();
2021
2022 last = prev_nonnote_insn (last);
2023 if (last == 0
2024 || (GET_CODE (last) != JUMP_INSN && GET_CODE (last) != BARRIER))
2025 fprintf (file, "\t%s\n\tnop\n", ret);
2026 }
2027 }
2028}
2029\f
2030/* Return the string to output a conditional branch to LABEL, which is
2031 the operand number of the label. OP is the conditional expression. The
2032 mode of register 0 says what kind of comparison we made.
2033
2034 REVERSED is non-zero if we should reverse the sense of the comparison.
2035
2036 ANNUL is non-zero if we should generate an annulling branch.
2037
2038 NOOP is non-zero if we have to follow this branch by a noop. */
2039
2040char *
2041output_cbranch (op, label, reversed, annul, noop)
2042 rtx op;
2043 int label;
2044 int reversed, annul, noop;
2045{
2046 static char string[20];
2047 enum rtx_code code = GET_CODE (op);
2048 enum machine_mode mode = GET_MODE (XEXP (op, 0));
2049 static char labelno[] = " %lX";
2050
2051 /* ??? FP branches can not be preceeded by another floating point insn.
2052 Because there is currently no concept of pre-delay slots, we can fix
2053 this only by always emitting a nop before a floating point branch. */
2054
2055 if (mode == CCFPmode)
2056 strcpy (string, "nop\n\t");
2057
2058 /* If not floating-point or if EQ or NE, we can just reverse the code. */
2059 if (reversed && (mode != CCFPmode || code == EQ || code == NE))
2060 code = reverse_condition (code), reversed = 0;
2061
2062 /* Start by writing the branch condition. */
2063 switch (code)
2064 {
2065 case NE:
2066 if (mode == CCFPmode)
2067 strcat (string, "fbne");
2068 else
2069 strcpy (string, "bne");
2070 break;
2071
2072 case EQ:
2073 if (mode == CCFPmode)
2074 strcat (string, "fbe");
2075 else
2076 strcpy (string, "be");
2077 break;
2078
2079 case GE:
2080 if (mode == CCFPmode)
2081 {
2082 if (reversed)
2083 strcat (string, "fbul");
2084 else
2085 strcat (string, "fbge");
2086 }
2087 else if (mode == CC_NOOVmode)
2088 strcpy (string, "bpos");
2089 else
2090 strcpy (string, "bge");
2091 break;
2092
2093 case GT:
2094 if (mode == CCFPmode)
2095 {
2096 if (reversed)
2097 strcat (string, "fbule");
2098 else
2099 strcat (string, "fbg");
2100 }
2101 else
2102 strcpy (string, "bg");
2103 break;
2104
2105 case LE:
2106 if (mode == CCFPmode)
2107 {
2108 if (reversed)
2109 strcat (string, "fbug");
2110 else
2111 strcat (string, "fble");
2112 }
2113 else
2114 strcpy (string, "ble");
2115 break;
2116
2117 case LT:
2118 if (mode == CCFPmode)
2119 {
2120 if (reversed)
2121 strcat (string, "fbuge");
2122 else
2123 strcat (string, "fbl");
2124 }
2125 else if (mode == CC_NOOVmode)
2126 strcpy (string, "bneg");
2127 else
2128 strcpy (string, "bl");
2129 break;
2130
2131 case GEU:
2132 strcpy (string, "bgeu");
2133 break;
2134
2135 case GTU:
2136 strcpy (string, "bgu");
2137 break;
2138
2139 case LEU:
2140 strcpy (string, "bleu");
2141 break;
2142
2143 case LTU:
2144 strcpy (string, "blu");
2145 break;
2146 }
2147
2148 /* Now add the annulling, the label, and a possible noop. */
2149 if (annul)
2150 strcat (string, ",a");
2151
2152 labelno[3] = label + '0';
2153 strcat (string, labelno);
2154
2155 if (noop)
2156 strcat (string, "\n\tnop");
2157
2158 return string;
2159}
2160
2161char *
2162output_return (operands)
2163 rtx *operands;
2164{
2165 if (leaf_label)
2166 {
2167 operands[0] = leaf_label;
2168 return "b,a %l0";
2169 }
2170 else if (leaf_function)
2171 {
2172 operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize);
2173 if (actual_fsize < 4096)
2174 {
2175 if (current_function_returns_struct)
2176 return "jmp %%o7+12\n\tadd %%sp,%0,%%sp";
2177 else
2178 return "retl\n\tadd %%sp,%0,%%sp";
2179 }
2180 else
2181 {
2182 if (current_function_returns_struct)
2183 return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp";
2184 else
2185 return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp";
2186 }
2187 }
2188 else
2189 {
2190 if (current_function_returns_struct)
2191 return "jmp %%i7+12\n\trestore";
2192 else
2193 return "ret\n\trestore";
2194 }
2195}
2196
2197char *
2198output_floatsisf2 (operands)
2199 rtx *operands;
2200{
2201 if (GET_CODE (operands[1]) == MEM)
2202 return "ld %1,%0\n\tfitos %0,%0";
2203 else if (FP_REG_P (operands[1]))
2204 return "fitos %1,%0";
2205 return "st %r1,[%%fp-4]\n\tld [%%fp-4],%0\n\tfitos %0,%0";
2206}
2207
2208char *
2209output_floatsidf2 (operands)
2210 rtx *operands;
2211{
2212 if (GET_CODE (operands[1]) == MEM)
2213 return "ld %1,%0\n\tfitod %0,%0";
2214 else if (FP_REG_P (operands[1]))
2215 return "fitod %1,%0";
2216 return "st %r1,[%%fp-4]\n\tld [%%fp-4],%0\n\tfitod %0,%0";
2217}
2218
2219int
2220tail_call_valid_p ()
2221{
2222 static int checked = 0;
2223 static int valid_p = 0;
2224
2225 if (! checked)
2226 {
2227 register int i;
2228
2229 checked = 1;
2230 for (i = 32; i < FIRST_PSEUDO_REGISTER; i++)
2231 if (! fixed_regs[i] && ! call_used_regs[i])
2232 return 0;
2233 valid_p = 1;
2234 }
2235 return valid_p;
2236}
2237\f
2238/* Leaf functions and non-leaf functions have different needs. */
2239
2240static int
2241reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
2242
2243static int
2244reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
2245
2246static int *reg_alloc_orders[] = {
2247 reg_leaf_alloc_order,
2248 reg_nonleaf_alloc_order};
2249
2250void
2251order_regs_for_local_alloc ()
2252{
2253 static int last_order_nonleaf = 1;
2254
2255 if (regs_ever_live[15] != last_order_nonleaf)
2256 {
2257 last_order_nonleaf = !last_order_nonleaf;
2258 bcopy (reg_alloc_orders[last_order_nonleaf], reg_alloc_order,
2259 FIRST_PSEUDO_REGISTER * sizeof (int));
2260 }
2261}
2262\f
2263/* Machine dependent routines for the branch probability, arc profiling
2264 code. */
2265
2266/* The label used by the arc profiling code. */
2267
2268static rtx profiler_label;
2269
2270void
2271init_arc_profiler ()
2272{
2273 /* Generate and save a copy of this so it can be shared. */
2274 profiler_label = gen_rtx (SYMBOL_REF, Pmode, "*LPBX2");
2275}
2276
2277void
2278output_arc_profiler (arcno, insert_after)
2279 int arcno;
2280 rtx insert_after;
2281{
2282 rtx profiler_target_addr
2283 = gen_rtx (CONST, Pmode,
2284 gen_rtx (PLUS, Pmode, profiler_label,
2285 gen_rtx (CONST_INT, VOIDmode, 4 * arcno)));
2286 register rtx profiler_reg = gen_reg_rtx (SImode);
2287 register rtx temp = gen_reg_rtx (Pmode);
2288 register rtx profiler_target = gen_rtx (MEM, SImode,
2289 gen_rtx (LO_SUM, Pmode, temp,
2290 profiler_target_addr));
2291 /* The insns are emitted from last to first after the insn insert_after.
2292 Emit_insn_after is used because sometimes we want to put the
2293 instrumentation code after the last insn of the function. */
2294 emit_insn_after (gen_rtx (SET, VOIDmode, profiler_target, profiler_reg),
2295 insert_after);
2296 emit_insn_after (gen_rtx (SET, VOIDmode, profiler_reg,
2297 gen_rtx (PLUS, SImode, profiler_reg, const1_rtx)),
2298 insert_after);
2299 emit_insn_after (gen_rtx (SET, VOIDmode, profiler_reg, profiler_target),
2300 insert_after);
2301 emit_insn_after (gen_rtx (SET, VOIDmode, temp,
2302 gen_rtx (HIGH, Pmode, profiler_target_addr)),
2303 insert_after);
2304}
2305\f
2306/* All the remaining routines in this file have been turned off. */
2307#if 0
2308char *
2309output_tail_call (operands, insn)
2310 rtx *operands;
2311 rtx insn;
2312{
2313 int this_fsize = actual_fsize;
2314 rtx next;
2315 int need_nop_at_end = 0;
2316
2317 next = next_real_insn (insn);
2318 while (next && GET_CODE (next) == CODE_LABEL)
2319 next = next_real_insn (insn);
2320
2321 if (final_sequence && this_fsize > 0)
2322 {
2323 rtx xoperands[1];
2324
2325 /* If we have to restore any registers, don't take any chances
2326 restoring a register before we discharge it into
2327 its home. If the frame size is only 88, we are guaranteed
2328 that the epilogue will fit in the delay slot. */
2329 rtx delay_insn = XVECEXP (final_sequence, 0, 1);
2330 if (GET_CODE (PATTERN (delay_insn)) == SET)
2331 {
2332 rtx dest = SET_DEST (PATTERN (delay_insn));
2333 if (GET_CODE (dest) == REG
2334 && reg_mentioned_p (dest, insn))
2335 abort ();
2336 }
2337 else if (GET_CODE (PATTERN (delay_insn)) == PARALLEL)
2338 abort ();
2339 xoperands[0] = operands[0];
2340 final_scan_insn (delay_insn, asm_out_file, 0, 0, 1);
2341 operands[0] = xoperands[0];
2342 final_sequence = 0;
2343 }
2344
2345 /* Make sure we are clear to return. */
2346 output_function_epilogue (asm_out_file, get_frame_size (), -1, 0);
2347
2348 /* Strip the MEM. */
2349 operands[0] = XEXP (operands[0], 0);
2350
2351 if (final_sequence == 0
2352 && (next == 0
2353 || GET_CODE (next) == CALL_INSN
2354 || GET_CODE (next) == JUMP_INSN))
2355 need_nop_at_end = 1;
2356
2357 if (flag_pic)
2358 return output_pic_sequence_2 (2, 3, 0, "jmpl %%g1+%3", operands, need_nop_at_end);
2359
2360 if (GET_CODE (operands[0]) == REG)
2361 output_asm_insn ("jmpl %a0,%%g0", operands);
2362 else if (TARGET_TAIL_CALL)
2363 {
2364 /* We assume all labels will be within 16 MB of our call. */
2365 if (need_nop_at_end || final_sequence)
2366 output_asm_insn ("b %a0", operands);
2367 else
2368 output_asm_insn ("b,a %a0", operands);
2369 }
2370 else if (! final_sequence)
2371 {
2372 output_asm_insn ("sethi %%hi(%a0),%%g1\n\tjmpl %%g1+%%lo(%a0),%%g1",
2373 operands);
2374 }
2375 else
2376 {
2377 int i;
2378 rtx x = PATTERN (XVECEXP (final_sequence, 0, 1));
2379 for (i = 1; i < 32; i++)
2380 if ((i == 1 || ! fixed_regs[i])
2381 && call_used_regs[i]
2382 && ! refers_to_regno_p (i, i+1, x, 0))
2383 break;
2384 if (i == 32)
2385 abort ();
2386 operands[1] = gen_rtx (REG, SImode, i);
2387 output_asm_insn ("sethi %%hi(%a0),%1\n\tjmpl %1+%%lo(%a0),%1", operands);
2388 }
2389 return (need_nop_at_end ? "nop" : "");
2390}
2391#endif
2392\f
2393/* Print operand X (an rtx) in assembler syntax to file FILE.
2394 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2395 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2396
2397void
2398print_operand (file, x, code)
2399 FILE *file;
2400 rtx x;
2401 int code;
2402{
2403 switch (code)
2404 {
2405 case '#':
2406 /* Output a 'nop' if there's nothing for the delay slot. */
2407 if (dbr_sequence_length () == 0)
2408 fputs ("\n\tnop", file);
2409 return;
2410 case '*':
2411 /* Output an annul flag if there's nothing for the delay slot. */
2412 if (dbr_sequence_length () == 0)
2413 fputs (",a", file);
2414 return;
2415 case 'Y':
2416 /* Adjust the operand to take into account a RESTORE operation. */
2417 if (GET_CODE (x) != REG)
2418 abort ();
2419 if (REGNO (x) < 8)
2420 fputs (reg_names[REGNO (x)], file);
2421 else if (REGNO (x) >= 24 && REGNO (x) < 32)
2422 fputs (reg_names[REGNO (x)-16], file);
2423 else
2424 abort ();
2425 return;
2426 case '@':
2427 /* Print out what we are using as the frame pointer. This might
2428 be %fp, or might be %sp+offset. */
2429 fputs (frame_base_name, file);
2430 return;
2431 case 'R':
2432 /* Print out the second register name of a register pair.
2433 I.e., R (%o0) => %o1. */
2434 fputs (reg_names[REGNO (x)+1], file);
2435 return;
2436 case 'm':
2437 /* Print the operand's address only. */
2438 output_address (XEXP (x, 0));
2439 return;
2440 case 'r':
2441 /* In this case we need a register. Use %g0 if the
2442 operand in const0_rtx. */
2443 if (x == const0_rtx)
2444 {
2445 fputs ("%g0", file);
2446 return;
2447 }
2448 else
2449 break;
2450
2451 case 'A':
2452 switch (GET_CODE (x))
2453 {
2454 case IOR: fputs ("or", file); break;
2455 case AND: fputs ("and", file); break;
2456 case XOR: fputs ("xor", file); break;
2457 default: abort ();
2458 }
2459 return;
2460
2461 case 'B':
2462 switch (GET_CODE (x))
2463 {
2464 case IOR: fputs ("orn", file); break;
2465 case AND: fputs ("andn", file); break;
2466 case XOR: fputs ("xnor", file); break;
2467 default: abort ();
2468 }
2469 return;
2470
2471 case 'b':
2472 {
2473 /* Print a sign-extended character. */
2474 int i = INTVAL (x) & 0xff;
2475 if (i & 0x80)
2476 i |= 0xffffff00;
2477 fprintf (file, "%d", i);
2478 return;
2479 }
2480
2481 case 0:
2482 /* Do nothing special. */
2483 break;
2484
2485 default:
2486 /* Undocumented flag. */
2487 abort ();
2488 }
2489
2490 if (GET_CODE (x) == REG)
2491 fputs (reg_names[REGNO (x)], file);
2492 else if (GET_CODE (x) == MEM)
2493 {
2494 fputc ('[', file);
2495 if (CONSTANT_P (XEXP (x, 0)))
2496 /* Poor Sun assembler doesn't understand absolute addressing. */
2497 fputs ("%g0+", file);
2498 output_address (XEXP (x, 0));
2499 fputc (']', file);
2500 }
2501 else if (GET_CODE (x) == HIGH)
2502 {
2503 fputs ("%hi(", file);
2504 output_addr_const (file, XEXP (x, 0));
2505 fputc (')', file);
2506 }
2507 else if (GET_CODE (x) == LO_SUM)
2508 {
2509 print_operand (file, XEXP (x, 0), 0);
2510 fputs ("+%lo(", file);
2511 output_addr_const (file, XEXP (x, 1));
2512 fputc (')', file);
2513 }
2514 else if (GET_CODE (x) == CONST_DOUBLE)
2515 {
2516 if (CONST_DOUBLE_HIGH (x) == 0)
2517 fprintf (file, "%u", CONST_DOUBLE_LOW (x));
2518 else if (CONST_DOUBLE_HIGH (x) == -1
2519 && CONST_DOUBLE_LOW (x) < 0)
2520 fprintf (file, "%d", CONST_DOUBLE_LOW (x));
2521 else
2522 abort ();
2523 }
2524 else { output_addr_const (file, x); }
2525}
2526\f
2527/* This function outputs assembler code for VALUE to FILE, where VALUE is
2528 a 64 bit (DImode) value. */
2529
2530/* ??? If there is a 64 bit counterpart to .word that the assembler
2531 understands, then using that would simply this code greatly. */
2532
2533void
2534output_double_int (file, value)
2535 FILE *file;
2536 rtx value;
2537{
2538 if (GET_CODE (value) == CONST_INT)
2539 {
2540 if (INTVAL (value) < 0)
2541 ASM_OUTPUT_INT (file, constm1_rtx);
2542 else
2543 ASM_OUTPUT_INT (file, const0_rtx);
2544 ASM_OUTPUT_INT (file, value);
2545 }
2546 else if (GET_CODE (value) == CONST_DOUBLE)
2547 {
2548 ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode,
2549 CONST_DOUBLE_HIGH (value)));
2550 ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode,
2551 CONST_DOUBLE_LOW (value)));
2552 }
2553 else if (GET_CODE (value) == SYMBOL_REF
2554 || GET_CODE (value) == CONST
2555 || GET_CODE (value) == PLUS)
2556 {
2557 /* Addresses are only 32 bits. */
2558 ASM_OUTPUT_INT (file, const0_rtx);
2559 ASM_OUTPUT_INT (file, value);
2560 }
2561 else
2562 abort ();
2563}
2564
This page took 0.267552 seconds and 5 git commands to generate.