]> gcc.gnu.org Git - gcc.git/blame - gcc/config/sparc/sparc.c
*** empty log message ***
[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"
210aa14a 23#include "tree.h"
ab835497
RK
24#include "rtl.h"
25#include "regs.h"
26#include "hard-reg-set.h"
27#include "real.h"
28#include "insn-config.h"
29#include "conditions.h"
30#include "insn-flags.h"
31#include "output.h"
32#include "insn-attr.h"
33#include "flags.h"
34#include "expr.h"
35#include "recog.h"
36
37/* Global variables for machine-dependent things. */
38
39/* Save the operands last given to a compare for use when we
40 generate a scc or bcc insn. */
41
42rtx sparc_compare_op0, sparc_compare_op1;
43
44/* We may need an epilogue if we spill too many registers.
45 If this is non-zero, then we branch here for the epilogue. */
46static rtx leaf_label;
47
48#ifdef LEAF_REGISTERS
49
50/* Vector to say how input registers are mapped to output
51 registers. FRAME_POINTER_REGNUM cannot be remapped by
52 this function to eliminate it. You must use -fomit-frame-pointer
53 to get that. */
54char leaf_reg_remap[] =
55{ 0, 1, 2, 3, 4, 5, 6, 7,
56 -1, -1, -1, -1, -1, -1, 14, -1,
57 -1, -1, -1, -1, -1, -1, -1, -1,
58 8, 9, 10, 11, 12, 13, -1, 15,
59
60 32, 33, 34, 35, 36, 37, 38, 39,
61 40, 41, 42, 43, 44, 45, 46, 47,
62 48, 49, 50, 51, 52, 53, 54, 55,
63 56, 57, 58, 59, 60, 61, 62, 63};
64
65char leaf_reg_backmap[] =
66{ 0, 1, 2, 3, 4, 5, 6, 7,
67 24, 25, 26, 27, 28, 29, 14, 31,
68 -1, -1, -1, -1, -1, -1, -1, -1,
69 -1, -1, -1, -1, -1, -1, -1, -1,
70
71 32, 33, 34, 35, 36, 37, 38, 39,
72 40, 41, 42, 43, 44, 45, 46, 47,
73 48, 49, 50, 51, 52, 53, 54, 55,
74 56, 57, 58, 59, 60, 61, 62, 63};
75#endif
76
77/* Global variables set by FUNCTION_PROLOGUE. */
78/* Size of frame. Need to know this to emit return insns from
79 leaf procedures. */
80int apparent_fsize;
81int actual_fsize;
82
83/* Name of where we pretend to think the frame pointer points.
84 Normally, this is "%fp", but if we are in a leaf procedure,
85 this is "%sp+something". */
86char *frame_base_name;
87
88static rtx find_addr_reg ();
89
90/* Return non-zero only if OP is a register of mode MODE,
91 or const0_rtx. */
92int
93reg_or_0_operand (op, mode)
94 rtx op;
95 enum machine_mode mode;
96{
97 if (op == const0_rtx || register_operand (op, mode))
98 return 1;
99 if (GET_CODE (op) == CONST_DOUBLE
100 && CONST_DOUBLE_HIGH (op) == 0
101 && CONST_DOUBLE_LOW (op) == 0)
102 return 1;
103 return 0;
104}
105
106/* Nonzero if OP can appear as the dest of a RESTORE insn. */
107int
108restore_operand (op, mode)
109 rtx op;
110 enum machine_mode mode;
111{
112 return (GET_CODE (op) == REG && GET_MODE (op) == mode
113 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
114}
115
116/* PC-relative call insn on SPARC is independent of `memory_operand'. */
117
118int
119call_operand (op, mode)
120 rtx op;
121 enum machine_mode mode;
122{
123 if (GET_CODE (op) != MEM)
124 abort ();
125 op = XEXP (op, 0);
126 return (REG_P (op) || CONSTANT_P (op));
127}
128
129int
130call_operand_address (op, mode)
131 rtx op;
132 enum machine_mode mode;
133{
134 return (REG_P (op) || CONSTANT_P (op));
135}
136
137/* Returns 1 if OP is either a symbol reference or a sum of a symbol
138 reference and a constant. */
139
140int
141symbolic_operand (op, mode)
142 register rtx op;
143 enum machine_mode mode;
144{
145 switch (GET_CODE (op))
146 {
147 case SYMBOL_REF:
148 case LABEL_REF:
149 return 1;
150
151 case CONST:
152 op = XEXP (op, 0);
153 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
154 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
155 && GET_CODE (XEXP (op, 1)) == CONST_INT);
156
157 /* This clause seems to be irrelevant. */
158 case CONST_DOUBLE:
159 return GET_MODE (op) == mode;
160
161 default:
162 return 0;
163 }
164}
165
166/* Return truth value of statement that OP is a symbolic memory
167 operand of mode MODE. */
168
169int
170symbolic_memory_operand (op, mode)
171 rtx op;
172 enum machine_mode mode;
173{
174 if (GET_CODE (op) == SUBREG)
175 op = SUBREG_REG (op);
176 if (GET_CODE (op) != MEM)
177 return 0;
178 op = XEXP (op, 0);
179 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
180 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
181}
182
183/* Return 1 if the operand is either a register or a memory operand that is
184 not symbolic. */
185
186int
187reg_or_nonsymb_mem_operand (op, mode)
188 register rtx op;
189 enum machine_mode mode;
190{
191 if (register_operand (op, mode))
192 return 1;
193
194 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
195 return 1;
196
197 return 0;
198}
199
200int
201sparc_operand (op, mode)
202 rtx op;
203 enum machine_mode mode;
204{
205 if (register_operand (op, mode))
206 return 1;
207 if (GET_CODE (op) == CONST_INT)
208 return SMALL_INT (op);
209 if (GET_MODE (op) != mode)
210 return 0;
211 if (GET_CODE (op) == SUBREG)
212 op = SUBREG_REG (op);
213 if (GET_CODE (op) != MEM)
214 return 0;
215
216 op = XEXP (op, 0);
217 if (GET_CODE (op) == LO_SUM)
218 return (GET_CODE (XEXP (op, 0)) == REG
219 && symbolic_operand (XEXP (op, 1), Pmode));
220 return memory_address_p (mode, op);
221}
222
223int
224move_operand (op, mode)
225 rtx op;
226 enum machine_mode mode;
227{
228 if (mode == DImode && arith_double_operand (op, mode))
229 return 1;
230 if (register_operand (op, mode))
231 return 1;
232 if (GET_CODE (op) == CONST_INT)
233 return (SMALL_INT (op) || (INTVAL (op) & 0x3ff) == 0);
234
235 if (GET_MODE (op) != mode)
236 return 0;
237 if (GET_CODE (op) == SUBREG)
238 op = SUBREG_REG (op);
239 if (GET_CODE (op) != MEM)
240 return 0;
241 op = XEXP (op, 0);
242 if (GET_CODE (op) == LO_SUM)
243 return (register_operand (XEXP (op, 0), Pmode)
244 && CONSTANT_P (XEXP (op, 1)));
245 return memory_address_p (mode, op);
246}
247
248int
249move_pic_label (op, mode)
250 rtx op;
251 enum machine_mode mode;
252{
253 /* Special case for PIC. */
254 if (flag_pic && GET_CODE (op) == LABEL_REF)
255 return 1;
256 return 0;
257}
258\f
259/* The rtx for the global offset table which is a special form
260 that *is* a position independent symbolic constant. */
261rtx pic_pc_rtx;
262
263/* Ensure that we are not using patterns that are not OK with PIC. */
264
265int
266check_pic (i)
267 int i;
268{
269 switch (flag_pic)
270 {
271 case 1:
272 if (GET_CODE (recog_operand[i]) == SYMBOL_REF
273 || (GET_CODE (recog_operand[i]) == CONST
274 && ! rtx_equal_p (pic_pc_rtx, recog_operand[i])))
275 abort ();
276 case 2:
277 default:
278 return 1;
279 }
280}
281
282/* Return true if X is an address which needs a temporary register when
283 reloaded while generating PIC code. */
284
285int
286pic_address_needs_scratch (x)
287 rtx x;
288{
289 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
290 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
291 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
292 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
293 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
294 return 1;
295
296 return 0;
297}
298
299int
300memop (op, mode)
301 rtx op;
302 enum machine_mode mode;
303{
304 if (GET_CODE (op) == MEM)
305 return (mode == VOIDmode || mode == GET_MODE (op));
306 return 0;
307}
308
309/* Return truth value of whether OP is EQ or NE. */
310
311int
312eq_or_neq (op, mode)
313 rtx op;
314 enum machine_mode mode;
315{
316 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
317}
318
319/* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
320 or LTU for non-floating-point. We handle those specially. */
321
322int
323normal_comp_operator (op, mode)
324 rtx op;
325 enum machine_mode mode;
326{
327 enum rtx_code code = GET_CODE (op);
328
329 if (GET_RTX_CLASS (code) != '<')
330 return 0;
331
332 if (GET_MODE (XEXP (op, 0)) == CCFPmode)
333 return 1;
334
335 return (code != NE && code != EQ && code != GEU && code != LTU);
336}
337
338/* Return 1 if this is a comparison operator. This allows the use of
339 MATCH_OPERATOR to recognize all the branch insns. */
340
341int
342noov_compare_op (op, mode)
343 register rtx op;
344 enum machine_mode mode;
345{
346 enum rtx_code code = GET_CODE (op);
347
348 if (GET_RTX_CLASS (code) != '<')
349 return 0;
350
351 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode)
352 /* These are the only branches which work with CC_NOOVmode. */
353 return (code == EQ || code == NE || code == GE || code == LT);
354 return 1;
355}
356
357/* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
358
359int
360extend_op (op, mode)
361 rtx op;
362 enum machine_mode mode;
363{
364 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
365}
366
367/* Return nonzero if OP is an operator of mode MODE which can set
368 the condition codes explicitly. We do not include PLUS and MINUS
369 because these require CC_NOOVmode, which we handle explicitly. */
370
371int
372cc_arithop (op, mode)
373 rtx op;
374 enum machine_mode mode;
375{
376 if (GET_CODE (op) == AND
377 || GET_CODE (op) == IOR
378 || GET_CODE (op) == XOR)
379 return 1;
380
381 return 0;
382}
383
384/* Return nonzero if OP is an operator of mode MODE which can bitwise
385 complement its second operand and set the condition codes explicitly. */
386
387int
388cc_arithopn (op, mode)
389 rtx op;
390 enum machine_mode mode;
391{
392 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
393 and (xor ... (not ...)) to (not (xor ...)). */
394 return (GET_CODE (op) == AND
395 || GET_CODE (op) == IOR);
396}
397\f
398/* Return truth value of whether OP can be used as an operands in a three
399 address arithmetic insn (such as add %o1,7,%l2) of mode MODE. */
400
401int
402arith_operand (op, mode)
403 rtx op;
404 enum machine_mode mode;
405{
406 return (register_operand (op, mode)
407 || (GET_CODE (op) == CONST_INT && SMALL_INT (op)));
408}
409
ab835497
RK
410/* Return truth value of whether OP is a register or a CONST_DOUBLE. */
411
412int
413arith_double_operand (op, mode)
414 rtx op;
415 enum machine_mode mode;
416{
417 return (register_operand (op, mode)
418 || (GET_CODE (op) == CONST_DOUBLE
419 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
420 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
421 && ((CONST_DOUBLE_HIGH (op) == -1
422 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
423 || (CONST_DOUBLE_HIGH (op) == 0
424 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0)))
425 || (GET_CODE (op) == CONST_INT
426 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
427 && (unsigned) (INTVAL (op) + 0x1000) < 0x2000));
428}
429
430/* Return truth value of whether OP is a integer which fits the
431 range constraining immediate operands in three-address insns. */
432
433int
434small_int (op, mode)
435 rtx op;
436 enum machine_mode mode;
437{
438 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
439}
440
441/* Return truth value of statement that OP is a call-clobbered register. */
442int
443clobbered_register (op, mode)
444 rtx op;
445 enum machine_mode mode;
446{
447 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
448}
449\f
450/* X and Y are two things to compare using CODE. Emit the compare insn and
451 return the rtx for register 0 in the proper mode. */
452
453rtx
454gen_compare_reg (code, x, y)
455 enum rtx_code code;
456 rtx x, y;
457{
458 enum machine_mode mode = SELECT_CC_MODE (code, x);
459 rtx cc_reg = gen_rtx (REG, mode, 0);
460
461 emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
462 gen_rtx (COMPARE, mode, x, y)));
463
464 return cc_reg;
465}
466\f
467/* Return nonzero if a return peephole merging return with
468 setting of output register is ok. */
469int
470leaf_return_peephole_ok ()
471{
472 return (actual_fsize == 0);
473}
474
475/* Return nonzero if TRIAL can go into the function epilogue's
476 delay slot. SLOT is the slot we are trying to fill. */
477
478int
479eligible_for_epilogue_delay (trial, slot)
480 rtx trial;
481 int slot;
482{
483 static char *this_function_name;
484 rtx pat, src;
485
486 if (slot >= 1)
487 return 0;
488 if (GET_CODE (trial) != INSN
489 || GET_CODE (PATTERN (trial)) != SET)
490 return 0;
491 if (get_attr_length (trial) != 1)
492 return 0;
493
494 /* In the case of a true leaf function, anything can
495 go into the delay slot. */
496 if (leaf_function)
497 {
498 if (leaf_return_peephole_ok ())
499 return (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_TRUE);
500 return 0;
501 }
502
503 /* Otherwise, only operations which can be done in tandem with
504 a `restore' insn can go into the delay slot. */
505 pat = PATTERN (trial);
506 if (GET_CODE (SET_DEST (pat)) != REG
507 || REGNO (SET_DEST (pat)) == 0
508 || (leaf_function
509 && REGNO (SET_DEST (pat)) < 32
510 && REGNO (SET_DEST (pat)) >= 16)
511 || (! leaf_function
512 && (REGNO (SET_DEST (pat)) >= 32
513 || REGNO (SET_DEST (pat)) < 24)))
514 return 0;
515 src = SET_SRC (pat);
516 if (arith_operand (src, GET_MODE (src)))
517 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
518 if (arith_double_operand (src, GET_MODE (src)))
519 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
520 if (GET_CODE (src) == PLUS)
521 {
522 if (register_operand (XEXP (src, 0), SImode)
523 && arith_operand (XEXP (src, 1), SImode))
524 return 1;
525 if (register_operand (XEXP (src, 1), SImode)
526 && arith_operand (XEXP (src, 0), SImode))
527 return 1;
528 if (register_operand (XEXP (src, 0), DImode)
529 && arith_double_operand (XEXP (src, 1), DImode))
530 return 1;
531 if (register_operand (XEXP (src, 1), DImode)
532 && arith_double_operand (XEXP (src, 0), DImode))
533 return 1;
534 }
535 if (GET_CODE (src) == MINUS
536 && register_operand (XEXP (src, 0), SImode)
537 && small_int (XEXP (src, 1), VOIDmode))
538 return 1;
539 if (GET_CODE (src) == MINUS
540 && register_operand (XEXP (src, 0), DImode)
541 && !register_operand (XEXP (src, 1), DImode)
542 && arith_double_operand (XEXP (src, 1), DImode))
543 return 1;
544 return 0;
545}
546
547int
548short_branch (uid1, uid2)
549 int uid1, uid2;
550{
551 unsigned int delta = insn_addresses[uid1] - insn_addresses[uid2];
552 if (delta + 1024 < 2048)
553 return 1;
554 /* warning ("long branch, distance %d", delta); */
555 return 0;
556}
557
558/* Return non-zero if REG is not used after INSN.
559 We assume REG is a reload reg, and therefore does
560 not live past labels or calls or jumps. */
561int
562reg_unused_after (reg, insn)
563 rtx reg;
564 rtx insn;
565{
566 enum rtx_code code, prev_code = UNKNOWN;
567
568 while (insn = NEXT_INSN (insn))
569 {
570 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
571 return 1;
572
573 code = GET_CODE (insn);
574 if (GET_CODE (insn) == CODE_LABEL)
575 return 1;
576
577 if (GET_RTX_CLASS (code) == 'i')
578 {
579 rtx set = single_set (insn);
580 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
581 if (set && in_src)
582 return 0;
583 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
584 return 1;
585 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
586 return 0;
587 }
588 prev_code = code;
589 }
590 return 1;
591}
592\f
593/* Legitimize PIC addresses. If the address is already position-independent,
594 we return ORIG. Newly generated position-independent addresses go into a
595 reg. This is REG if non zero, otherwise we allocate register(s) as
596 necessary. If this is called during reload, and we need a second temp
597 register, then we use SCRATCH, which is provided via the
598 SECONDARY_INPUT_RELOAD_CLASS mechanism. */
599
600rtx
601legitimize_pic_address (orig, mode, reg, scratch)
602 rtx orig;
603 enum machine_mode mode;
604 rtx reg, scratch;
605{
606 if (GET_CODE (orig) == SYMBOL_REF)
607 {
608 rtx pic_ref, address;
609 rtx insn;
610
611 if (reg == 0)
612 {
01c0e9dc 613 if (reload_in_progress || reload_completed)
ab835497
RK
614 abort ();
615 else
616 reg = gen_reg_rtx (Pmode);
617 }
618
619 if (flag_pic == 2)
620 {
621 /* If not during reload, allocate another temp reg here for loading
622 in the address, so that these instructions can be optimized
623 properly. */
01c0e9dc
JW
624 rtx temp_reg = ((reload_in_progress || reload_completed)
625 ? reg : gen_reg_rtx (Pmode));
ab835497 626
b4ac57ab
RS
627 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
628 won't get confused into thinking that these two instructions
629 are loading in the true address of the symbol. If in the
630 future a PIC rtx exists, that should be used instead. */
ab835497 631 emit_insn (gen_rtx (SET, VOIDmode, temp_reg,
b4ac57ab
RS
632 gen_rtx (HIGH, Pmode,
633 gen_rtx (UNSPEC, Pmode,
634 gen_rtvec (1, orig),
635 0))));
ab835497 636 emit_insn (gen_rtx (SET, VOIDmode, temp_reg,
b4ac57ab
RS
637 gen_rtx (LO_SUM, Pmode, temp_reg,
638 gen_rtx (UNSPEC, Pmode,
639 gen_rtvec (1, orig),
640 0))));
ab835497
RK
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. */
391b99c9 1063 /* Trust double-precision floats in global variables. */
ab835497 1064
391b99c9 1065 if (GET_CODE (XEXP (op2, 0)) == LO_SUM && GET_MODE (op2) == DFmode)
ab835497 1066 {
ab835497
RK
1067 if (final_sequence)
1068 abort ();
391b99c9 1069 return (op1 == operands[0] ? "ldd %1,%0" : "std %1,%0");
ab835497
RK
1070 }
1071
1072 if (GET_CODE (XEXP (op2, 0)) == PLUS)
1073 {
1074 rtx temp = XEXP (op2, 0);
1075 if (GET_CODE (XEXP (temp, 0)) == REG)
1076 base = XEXP (temp, 0), offset = XEXP (temp, 1);
1077 else if (GET_CODE (XEXP (temp, 1)) == REG)
1078 base = XEXP (temp, 1), offset = XEXP (temp, 0);
1079 }
1080
1081 /* Trust round enough offsets from the stack or frame pointer. */
1082 if (base
1083 && (REGNO (base) == FRAME_POINTER_REGNUM
1084 || REGNO (base) == STACK_POINTER_REGNUM))
1085 {
1086 if (GET_CODE (offset) == CONST_INT
1087 && (INTVAL (offset) & 0x7) == 0)
1088 {
1089 if (op1 == operands[0])
1090 return "ldd %1,%0";
1091 else
1092 return "std %1,%0";
1093 }
1094 }
1095 /* We know structs not on the stack are properly aligned. Since a
1096 double asks for 8-byte alignment, we know it must have got that
1097 if it is in a struct. But a DImode need not be 8-byte aligned,
1098 because it could be a struct containing two ints or pointers. */
1099 else if (GET_CODE (operands[1]) == MEM
1100 && GET_MODE (operands[1]) == DFmode
1101 && (CONSTANT_P (XEXP (operands[1], 0))
1102 /* Let user ask for it anyway. */
391b99c9 1103 || TARGET_HOPE_ALIGN))
ab835497
RK
1104 return "ldd %1,%0";
1105 else if (GET_CODE (operands[0]) == MEM
1106 && GET_MODE (operands[0]) == DFmode
1107 && (CONSTANT_P (XEXP (operands[0], 0))
391b99c9 1108 || TARGET_HOPE_ALIGN))
ab835497
RK
1109 return "std %1,%0";
1110 }
1111
1112 if (optype0 == REGOP && optype1 == REGOP
1113 && REGNO (operands[0]) == REGNO (latehalf[1]))
1114 {
1115 /* Make any unoffsettable addresses point at high-numbered word. */
1116 if (addreg0)
1117 output_asm_insn ("add %0,0x4,%0", &addreg0);
1118 if (addreg1)
1119 output_asm_insn ("add %0,0x4,%0", &addreg1);
1120
1121 /* Do that word. */
1122 output_asm_insn (singlemove_string (latehalf), latehalf);
1123
1124 /* Undo the adds we just did. */
1125 if (addreg0)
1126 output_asm_insn ("add %0,-0x4,%0", &addreg0);
1127 if (addreg1)
1128 output_asm_insn ("add %0,-0x4,%0", &addreg1);
1129
1130 /* Do low-numbered word. */
1131 return singlemove_string (operands);
1132 }
1133 else if (optype0 == REGOP && optype1 != REGOP
1134 && reg_overlap_mentioned_p (operands[0], operands[1]))
1135 {
1136 /* Do the late half first. */
1137 output_asm_insn (singlemove_string (latehalf), latehalf);
1138 /* Then clobber. */
1139 return singlemove_string (operands);
1140 }
1141
1142 /* Normal case: do the two words, low-numbered first. */
1143
1144 output_asm_insn (singlemove_string (operands), operands);
1145
1146 /* Make any unoffsettable addresses point at high-numbered word. */
1147 if (addreg0)
1148 output_asm_insn ("add %0,0x4,%0", &addreg0);
1149 if (addreg1)
1150 output_asm_insn ("add %0,0x4,%0", &addreg1);
1151
1152 /* Do that word. */
1153 output_asm_insn (singlemove_string (latehalf), latehalf);
1154
1155 /* Undo the adds we just did. */
1156 if (addreg0)
1157 output_asm_insn ("add %0,-0x4,%0", &addreg0);
1158 if (addreg1)
1159 output_asm_insn ("add %0,-0x4,%0", &addreg1);
1160
1161 return "";
1162}
1163\f
1164char *
1165output_fp_move_double (operands)
1166 rtx *operands;
1167{
1168 rtx addr;
1169
1170 if (FP_REG_P (operands[0]))
1171 {
1172 if (FP_REG_P (operands[1]))
1173 return "fmovs %1,%0\n\tfmovs %R1,%R0";
1174 if (GET_CODE (operands[1]) == REG)
1175 {
1176 if ((REGNO (operands[1]) & 1) == 0)
1177 return "std %1,[%@-8]\n\tldd [%@-8],%0";
1178 else
1179 return "st %R1,[%@-4]\n\tst %1,[%@-8]\n\tldd [%@-8],%0";
1180 }
1181 addr = XEXP (operands[1], 0);
1182
1183 /* Use ldd if known to be aligned. */
391b99c9 1184 if (TARGET_HOPE_ALIGN
ab835497
RK
1185 || (GET_CODE (addr) == PLUS
1186 && (((XEXP (addr, 0) == frame_pointer_rtx
1187 || XEXP (addr, 0) == stack_pointer_rtx)
1188 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1189 && (INTVAL (XEXP (addr, 1)) & 0x7) == 0)
1190 /* Arrays are known to be aligned,
1191 and reg+reg addresses are used (on this machine)
1192 only for array accesses. */
1193 || (REG_P (XEXP (addr, 0)) && REG_P (XEXP (addr, 1)))))
1194 || (GET_MODE (operands[0]) == DFmode
1195 && (GET_CODE (addr) == LO_SUM || CONSTANT_P (addr))))
1196 return "ldd %1,%0";
1197
1198 /* Otherwise use two ld insns. */
1199 operands[2]
1200 = gen_rtx (MEM, GET_MODE (operands[1]),
1201 plus_constant_for_output (addr, 4));
1202 return "ld %1,%0\n\tld %2,%R0";
1203 }
1204 else if (FP_REG_P (operands[1]))
1205 {
1206 if (GET_CODE (operands[0]) == REG)
1207 {
1208 if ((REGNO (operands[0]) & 1) == 0)
1209 return "std %1,[%@-8]\n\tldd [%@-8],%0";
1210 else
1211 return "std %1,[%@-8]\n\tld [%@-4],%R0\n\tld [%@-8],%0";
1212 }
1213 addr = XEXP (operands[0], 0);
1214
1215 /* Use std if we can be sure it is well-aligned. */
391b99c9 1216 if (TARGET_HOPE_ALIGN
ab835497
RK
1217 || (GET_CODE (addr) == PLUS
1218 && (((XEXP (addr, 0) == frame_pointer_rtx
1219 || XEXP (addr, 0) == stack_pointer_rtx)
1220 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1221 && (INTVAL (XEXP (addr, 1)) & 0x7) == 0)
1222 /* Arrays are known to be aligned,
1223 and reg+reg addresses are used (on this machine)
1224 only for array accesses. */
1225 || (REG_P (XEXP (addr, 0)) && REG_P (XEXP (addr, 1)))))
1226 || (GET_MODE (operands[1]) == DFmode
1227 && (GET_CODE (addr) == LO_SUM || CONSTANT_P (addr))))
1228 return "std %1,%0";
1229
1230 /* Otherwise use two st insns. */
1231 operands[2]
1232 = gen_rtx (MEM, GET_MODE (operands[0]),
1233 plus_constant_for_output (addr, 4));
1234 return "st %r1,%0\n\tst %R1,%2";
1235 }
1236 else abort ();
1237}
1238\f
1239/* Return a REG that occurs in ADDR with coefficient 1.
1240 ADDR can be effectively incremented by incrementing REG. */
1241
1242static rtx
1243find_addr_reg (addr)
1244 rtx addr;
1245{
1246 while (GET_CODE (addr) == PLUS)
1247 {
1248 /* We absolutely can not fudge the frame pointer here, because the
1249 frame pointer must always be 8 byte aligned. It also confuses
1250 debuggers. */
1251 if (GET_CODE (XEXP (addr, 0)) == REG
1252 && REGNO (XEXP (addr, 0)) != FRAME_POINTER_REGNUM)
1253 addr = XEXP (addr, 0);
1254 else if (GET_CODE (XEXP (addr, 1)) == REG
1255 && REGNO (XEXP (addr, 1)) != FRAME_POINTER_REGNUM)
1256 addr = XEXP (addr, 1);
1257 else if (CONSTANT_P (XEXP (addr, 0)))
1258 addr = XEXP (addr, 1);
1259 else if (CONSTANT_P (XEXP (addr, 1)))
1260 addr = XEXP (addr, 0);
1261 else
1262 abort ();
1263 }
1264 if (GET_CODE (addr) == REG)
1265 return addr;
1266 abort ();
1267}
1268
1269void
1270output_sized_memop (opname, mode, signedp)
1271 char *opname;
1272 enum machine_mode mode;
1273 int signedp;
1274{
1275 static char *ld_size_suffix_u[] = { "ub", "uh", "", "?", "d" };
1276 static char *ld_size_suffix_s[] = { "sb", "sh", "", "?", "d" };
1277 static char *st_size_suffix[] = { "b", "h", "", "?", "d" };
1278 char **opnametab, *modename;
1279
1280 if (opname[0] == 'l')
1281 if (signedp)
1282 opnametab = ld_size_suffix_s;
1283 else
1284 opnametab = ld_size_suffix_u;
1285 else
1286 opnametab = st_size_suffix;
1287 modename = opnametab[GET_MODE_SIZE (mode) >> 1];
1288
1289 fprintf (asm_out_file, "\t%s%s", opname, modename);
1290}
1291\f
1292void
1293output_move_with_extension (operands)
1294 rtx *operands;
1295{
1296 if (GET_MODE (operands[2]) == HImode)
1297 output_asm_insn ("sll %2,0x10,%0", operands);
1298 else if (GET_MODE (operands[2]) == QImode)
1299 output_asm_insn ("sll %2,0x18,%0", operands);
1300 else
1301 abort ();
1302}
1303\f
1304/* Load the address specified by OPERANDS[3] into the register
1305 specified by OPERANDS[0].
1306
1307 OPERANDS[3] may be the result of a sum, hence it could either be:
1308
1309 (1) CONST
1310 (2) REG
1311 (2) REG + CONST_INT
1312 (3) REG + REG + CONST_INT
1313 (4) REG + REG (special case of 3).
1314
1315 Note that (3) is not a legitimate address.
1316 All cases are handled here. */
1317
1318void
1319output_load_address (operands)
1320 rtx *operands;
1321{
1322 rtx base, offset;
1323
1324 if (CONSTANT_P (operands[3]))
1325 {
1326 output_asm_insn ("set %3,%0", operands);
1327 return;
1328 }
1329
1330 if (REG_P (operands[3]))
1331 {
1332 if (REGNO (operands[0]) != REGNO (operands[3]))
1333 output_asm_insn ("mov %3,%0", operands);
1334 return;
1335 }
1336
1337 if (GET_CODE (operands[3]) != PLUS)
1338 abort ();
1339
1340 base = XEXP (operands[3], 0);
1341 offset = XEXP (operands[3], 1);
1342
1343 if (GET_CODE (base) == CONST_INT)
1344 {
1345 rtx tmp = base;
1346 base = offset;
1347 offset = tmp;
1348 }
1349
1350 if (GET_CODE (offset) != CONST_INT)
1351 {
1352 /* Operand is (PLUS (REG) (REG)). */
1353 base = operands[3];
1354 offset = const0_rtx;
1355 }
1356
1357 if (REG_P (base))
1358 {
1359 operands[6] = base;
1360 operands[7] = offset;
1361 if (SMALL_INT (offset))
1362 output_asm_insn ("add %6,%7,%0", operands);
1363 else
1364 output_asm_insn ("set %7,%0\n\tadd %0,%6,%0", operands);
1365 }
1366 else if (GET_CODE (base) == PLUS)
1367 {
1368 operands[6] = XEXP (base, 0);
1369 operands[7] = XEXP (base, 1);
1370 operands[8] = offset;
1371
1372 if (SMALL_INT (offset))
1373 output_asm_insn ("add %6,%7,%0\n\tadd %0,%8,%0", operands);
1374 else
1375 output_asm_insn ("set %8,%0\n\tadd %0,%6,%0\n\tadd %0,%7,%0", operands);
1376 }
1377 else
1378 abort ();
1379}
1380
1381/* Output code to place a size count SIZE in register REG.
1382 ALIGN is the size of the unit of transfer.
1383
1384 Because block moves are pipelined, we don't include the
1385 first element in the transfer of SIZE to REG. */
1386
1387static void
1388output_size_for_block_move (size, reg, align)
1389 rtx size, reg;
1390 rtx align;
1391{
1392 rtx xoperands[3];
1393
1394 xoperands[0] = reg;
1395 xoperands[1] = size;
1396 xoperands[2] = align;
1397 if (GET_CODE (size) == REG)
1398 output_asm_insn ("sub %1,%2,%0", xoperands);
1399 else
1400 {
1401 xoperands[1]
1402 = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - INTVAL (align));
1403 output_asm_insn ("set %1,%0", xoperands);
1404 }
1405}
1406
1407/* Emit code to perform a block move.
1408
1409 OPERANDS[0] is the destination.
1410 OPERANDS[1] is the source.
1411 OPERANDS[2] is the size.
1412 OPERANDS[3] is the alignment safe to use.
1413 OPERANDS[4] is a register we can safely clobber as a temp. */
1414
1415char *
1416output_block_move (operands)
1417 rtx *operands;
1418{
1419 /* A vector for our computed operands. Note that load_output_address
1420 makes use of (and can clobber) up to the 8th element of this vector. */
1421 rtx xoperands[10];
1422 rtx zoperands[10];
1423 static int movstrsi_label = 0;
1424 int i;
1425 rtx temp1 = operands[4];
1426 rtx sizertx = operands[2];
1427 rtx alignrtx = operands[3];
1428 int align = INTVAL (alignrtx);
210aa14a 1429 char label3[30], label5[30];
ab835497
RK
1430
1431 xoperands[0] = operands[0];
1432 xoperands[1] = operands[1];
1433 xoperands[2] = temp1;
1434
391b99c9
RS
1435 /* We can't move more than this many bytes at a time because we have only
1436 one register, %g1, to move them through. */
1437 if (align > UNITS_PER_WORD)
ab835497 1438 {
391b99c9
RS
1439 align = UNITS_PER_WORD;
1440 alignrtx = gen_rtx (CONST_INT, VOIDmode, UNITS_PER_WORD);
ab835497
RK
1441 }
1442
391b99c9
RS
1443 /* We consider 8 ld/st pairs, for a total of 16 inline insns to be
1444 reasonable here. (Actually will emit a maximum of 18 inline insns for
1445 the case of size == 31 and align == 4). */
1446
1447 if (GET_CODE (sizertx) == CONST_INT && (INTVAL (sizertx) / align) <= 8
1448 && memory_address_p (QImode, plus_constant_for_output (xoperands[0],
1449 INTVAL (sizertx)))
1450 && memory_address_p (QImode, plus_constant_for_output (xoperands[1],
1451 INTVAL (sizertx))))
ab835497
RK
1452 {
1453 int size = INTVAL (sizertx);
391b99c9 1454 int offset = 0;
ab835497 1455
391b99c9
RS
1456 /* We will store different integers into this particular RTX. */
1457 xoperands[2] = rtx_alloc (CONST_INT);
1458 PUT_MODE (xoperands[2], VOIDmode);
ab835497 1459
391b99c9
RS
1460 /* This case is currently not handled. Abort instead of generating
1461 bad code. */
1462 if (align > 4)
1463 abort ();
ab835497 1464
391b99c9 1465 if (align >= 4)
ab835497 1466 {
391b99c9 1467 for (i = (size >> 2) - 1; i >= 0; i--)
ab835497 1468 {
391b99c9
RS
1469 INTVAL (xoperands[2]) = (i << 2) + offset;
1470 output_asm_insn ("ld [%a1+%2],%%g1\n\tst %%g1,[%a0+%2]",
1471 xoperands);
ab835497 1472 }
391b99c9
RS
1473 offset += (size & ~0x3);
1474 size = size & 0x3;
1475 if (size == 0)
1476 return "";
ab835497 1477 }
391b99c9
RS
1478
1479 if (align >= 2)
ab835497 1480 {
391b99c9 1481 for (i = (size >> 1) - 1; i >= 0; i--)
ab835497 1482 {
391b99c9
RS
1483 INTVAL (xoperands[2]) = (i << 1) + offset;
1484 output_asm_insn ("lduh [%a1+%2],%%g1\n\tsth %%g1,[%a0+%2]",
1485 xoperands);
ab835497 1486 }
391b99c9
RS
1487 offset += (size & ~0x1);
1488 size = size & 0x1;
1489 if (size == 0)
1490 return "";
ab835497 1491 }
391b99c9
RS
1492
1493 if (align >= 1)
ab835497 1494 {
391b99c9 1495 for (i = size - 1; i >= 0; i--)
ab835497 1496 {
391b99c9
RS
1497 INTVAL (xoperands[2]) = i + offset;
1498 output_asm_insn ("ldub [%a1+%2],%%g1\n\tstb %%g1,[%a0+%2]",
1499 xoperands);
ab835497 1500 }
391b99c9 1501 return "";
ab835497 1502 }
391b99c9
RS
1503
1504 /* We should never reach here. */
1505 abort ();
ab835497
RK
1506 }
1507
391b99c9
RS
1508 /* If the size isn't known to be a multiple of the alignment,
1509 we have to do it in smaller pieces. If we could determine that
1510 the size was a multiple of 2 (or whatever), we could be smarter
1511 about this. */
1512 if (GET_CODE (sizertx) != CONST_INT)
1513 align = 1;
1514 else
1515 {
1516 int size = INTVAL (sizertx);
1517 while (size % align)
1518 align >>= 1;
1519 }
1520
1521 if (align != INTVAL (alignrtx))
1522 alignrtx = gen_rtx (CONST_INT, VOIDmode, align);
1523
ab835497
RK
1524 xoperands[3] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
1525 xoperands[4] = gen_rtx (CONST_INT, VOIDmode, align);
1526 xoperands[5] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
1527
210aa14a
RS
1528 ASM_GENERATE_INTERNAL_LABEL (label3, "Lm", INTVAL (xoperands[3]));
1529 ASM_GENERATE_INTERNAL_LABEL (label5, "Lm", INTVAL (xoperands[5]));
1530
391b99c9
RS
1531 /* This is the size of the transfer. Emit code to decrement the size
1532 value by ALIGN, and store the result in the temp1 register. */
ab835497
RK
1533 output_size_for_block_move (sizertx, temp1, alignrtx);
1534
1535 /* Must handle the case when the size is zero or negative, so the first thing
1536 we do is compare the size against zero, and only copy bytes if it is
1537 zero or greater. Note that we have already subtracted off the alignment
1538 once, so we must copy 1 alignment worth of bytes if the size is zero
1539 here.
1540
1541 The SUN assembler complains about labels in branch delay slots, so we
b4ac57ab 1542 do this before outputting the load address, so that there will always
ab835497
RK
1543 be a harmless insn between the branch here and the next label emitted
1544 below. */
1545
210aa14a
RS
1546 {
1547 char pattern[100];
1548
1549 sprintf (pattern, "cmp %%2,0\n\tbl %s", &label5[1]);
1550 output_asm_insn (pattern, xoperands);
1551 }
ab835497
RK
1552
1553 zoperands[0] = operands[0];
1554 zoperands[3] = plus_constant_for_output (operands[0], align);
1555 output_load_address (zoperands);
1556
1557 /* ??? This might be much faster if the loops below were preconditioned
1558 and unrolled.
1559
1560 That is, at run time, copy enough bytes one at a time to ensure that the
1561 target and source addresses are aligned to the the largest possible
1562 alignment. Then use a preconditioned unrolled loop to copy say 16
1563 bytes at a time. Then copy bytes one at a time until finish the rest. */
1564
1565 /* Output the first label separately, so that it is spaced properly. */
1566
ab835497 1567 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "Lm", INTVAL (xoperands[3]));
ab835497 1568
210aa14a
RS
1569 {
1570 char pattern[200];
1571 register char *ld_suffix = (align == 1) ? "ub" : (align == 2) ? "uh" : "";
1572 register char *st_suffix = (align == 1) ? "b" : (align == 2) ? "h" : "";
1573
1574 sprintf (pattern, "ld%s [%%1+%%2],%%%%g1\n\tsubcc %%2,%%4,%%2\n\tbge %s\n\tst%s %%%%g1,[%%0+%%2]\n%s:", ld_suffix, &label3[1], st_suffix, &label5[1]);
1575 output_asm_insn (pattern, xoperands);
1576 }
1577
ab835497 1578 return "";
ab835497
RK
1579}
1580\f
1581/* Output reasonable peephole for set-on-condition-code insns.
1582 Note that these insns assume a particular way of defining
1583 labels. Therefore, *both* sparc.h and this function must
1584 be changed if a new syntax is needed. */
1585
1586char *
1587output_scc_insn (operands, insn)
1588 rtx operands[];
1589 rtx insn;
1590{
1591 static char string[100];
1592 rtx label = 0, next = insn;
1593 int need_label = 0;
1594
1595 /* Try doing a jump optimization which jump.c can't do for us
1596 because we did not expose that setcc works by using branches.
1597
1598 If this scc insn is followed by an unconditional branch, then have
1599 the jump insn emitted here jump to that location, instead of to
1600 the end of the scc sequence as usual. */
1601
1602 do
1603 {
1604 if (GET_CODE (next) == CODE_LABEL)
1605 label = next;
1606 next = NEXT_INSN (next);
1607 if (next == 0)
1608 break;
1609 }
1610 while (GET_CODE (next) == NOTE || GET_CODE (next) == CODE_LABEL);
1611
1612 /* If we are in a sequence, and the following insn is a sequence also,
1613 then just following the current insn's next field will take us to the
1614 first insn of the next sequence, which is the wrong place. We don't
1615 want to optimize with a branch that has had its delay slot filled.
1616 Avoid this by verifying that NEXT_INSN (PREV_INSN (next)) == next
1617 which fails only if NEXT is such a branch. */
1618
1619 if (next && GET_CODE (next) == JUMP_INSN && simplejump_p (next)
1620 && (! final_sequence || NEXT_INSN (PREV_INSN (next)) == next))
1621 label = JUMP_LABEL (next);
1622 /* If not optimizing, jump label fields are not set. To be safe, always
1623 check here to whether label is still zero. */
1624 if (label == 0)
1625 {
1626 label = gen_label_rtx ();
1627 need_label = 1;
1628 }
1629
1630 LABEL_NUSES (label) += 1;
1631
1632 operands[2] = label;
1633
1634 /* If we are in a delay slot, assume it is the delay slot of an fpcc
1635 insn since our type isn't allowed anywhere else. */
1636
1637 /* ??? Fpcc instructions no longer have delay slots, so this code is
1638 probably obsolete. */
1639
1640 /* The fastest way to emit code for this is an annulled branch followed
1641 by two move insns. This will take two cycles if the branch is taken,
1642 and three cycles if the branch is not taken.
1643
1644 However, if we are in the delay slot of another branch, this won't work,
1645 because we can't put a branch in the delay slot of another branch.
1646 The above sequence would effectively take 3 or 4 cycles respectively
1647 since a no op would have be inserted between the two branches.
1648 In this case, we want to emit a move, annulled branch, and then the
1649 second move. This sequence always takes 3 cycles, and hence is faster
1650 when we are in a branch delay slot. */
1651
1652 if (final_sequence)
1653 {
1654 strcpy (string, "mov 0,%0\n\t");
1655 strcat (string, output_cbranch (operands[1], 2, 0, 1, 0));
1656 strcat (string, "\n\tmov 1,%0");
1657 }
1658 else
1659 {
1660 strcpy (string, output_cbranch (operands[1], 2, 0, 1, 0));
1661 strcat (string, "\n\tmov 1,%0\n\tmov 0,%0");
1662 }
1663
1664 if (need_label)
1665 strcat (string, "\n%l2:");
1666
1667 return string;
1668}
1669\f
1670/* Vectors to keep interesting information about registers where
1671 it can easily be got. */
1672
1673/* Modes for condition codes. */
1674#define C_MODES \
1675 ((1 << (int) CCmode) | (1 << (int) CC_NOOVmode) | (1 << (int) CCFPmode))
1676
1677/* Modes for single-word (and smaller) quantities. */
1678#define S_MODES \
1679 (~C_MODES \
1680 & ~ ((1 << (int) DImode) | (1 << (int) TImode) \
1681 | (1 << (int) DFmode) | (1 << (int) TFmode)))
1682
1683/* Modes for double-word (and smaller) quantities. */
1684#define D_MODES \
1685 (~C_MODES \
1686 & ~ ((1 << (int) TImode) | (1 << (int) TFmode)))
1687
1688/* Modes for quad-word quantities. */
1689#define T_MODES (~C_MODES)
1690
1691/* Modes for single-float quantities. */
1692#define SF_MODES ((1 << (int) SFmode))
1693
1694/* Modes for double-float quantities. */
1695#define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode))
1696
1697/* Modes for quad-float quantities. */
1698#define TF_MODES (DF_MODES | (1 << (int) TFmode) | (1 << (int) DCmode))
1699
1700/* Value is 1 if register/mode pair is acceptable on sparc.
1701 The funny mixture of D and T modes is because integer operations
1702 do not specially operate on tetra quantities, so non-quad-aligned
1703 registers can hold quadword quantities (except %o4 and %i4 because
1704 they cross fixed registers. */
1705
1706int hard_regno_mode_ok[] = {
1707 C_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1708 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
1709 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1710 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
1711
1712 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
1713 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
1714 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
1715 TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES};
1716\f
1717#ifdef __GNUC__
1718inline
1719#endif
1720static int
1721save_regs (file, low, high, base, offset, n_fregs)
1722 FILE *file;
1723 int low, high;
1724 char *base;
1725 int offset;
1726 int n_fregs;
1727{
1728 int i;
1729
1730 for (i = low; i < high; i += 2)
1731 {
1732 if (regs_ever_live[i] && ! call_used_regs[i])
1733 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1734 fprintf (file, "\tstd %s,[%s+%d]\n",
1735 reg_names[i], base, offset + 4 * n_fregs),
1736 n_fregs += 2;
1737 else
1738 fprintf (file, "\tst %s,[%s+%d]\n",
1739 reg_names[i], base, offset + 4 * n_fregs),
1740 n_fregs += 2;
1741 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1742 fprintf (file, "\tst %s,[%s+%d]\n",
1743 reg_names[i+1], base, offset + 4 * n_fregs),
1744 n_fregs += 2;
1745 }
1746 return n_fregs;
1747}
1748
1749#ifdef __GNUC__
1750inline
1751#endif
1752static int
1753restore_regs (file, low, high, base, offset, n_fregs)
1754 FILE *file;
1755 int low, high;
1756 char *base;
1757 int offset;
1758{
1759 int i;
1760
1761 for (i = low; i < high; i += 2)
1762 {
1763 if (regs_ever_live[i] && ! call_used_regs[i])
1764 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1765 fprintf (file, "\tldd [%s+%d], %s\n",
1766 base, offset + 4 * n_fregs, reg_names[i]),
1767 n_fregs += 2;
1768 else
1769 fprintf (file, "\tld [%s+%d],%s\n",
1770 base, offset + 4 * n_fregs, reg_names[i]),
1771 n_fregs += 2;
1772 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
1773 fprintf (file, "\tld [%s+%d],%s\n",
1774 base, offset + 4 * n_fregs, reg_names[i+1]),
1775 n_fregs += 2;
1776 }
1777 return n_fregs;
1778}
1779
1780/* Static variables we want to share between prologue and epilogue. */
1781
1782/* Number of live floating point registers needed to be saved. */
1783static int num_fregs;
1784
1785/* Nonzero if any floating point register was ever used. */
1786static int fregs_ever_live;
1787
1788int
1789compute_frame_size (size, leaf_function)
1790 int size;
1791 int leaf_function;
1792{
1793 int fregs_ever_live = 0;
1794 int n_fregs = 0, i;
1795 int outgoing_args_size = (current_function_outgoing_args_size
1796 + REG_PARM_STACK_SPACE (current_function_decl));
1797
1798 apparent_fsize = ((size) + 7 - STARTING_FRAME_OFFSET) & -8;
1799 for (i = 32; i < FIRST_PSEUDO_REGISTER; i += 2)
1800 fregs_ever_live |= regs_ever_live[i]|regs_ever_live[i+1];
1801
1802 if (TARGET_EPILOGUE && fregs_ever_live)
1803 {
1804 for (i = 32; i < FIRST_PSEUDO_REGISTER; i += 2)
1805 if ((regs_ever_live[i] && ! call_used_regs[i])
1806 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
1807 n_fregs += 2;
1808 }
1809
1810 /* Set up values for use in `function_epilogue'. */
1811 num_fregs = n_fregs;
1812
1813 apparent_fsize += (outgoing_args_size+7) & -8;
1814 if (leaf_function && n_fregs == 0
1815 && apparent_fsize == (REG_PARM_STACK_SPACE (current_function_decl)
1816 - STARTING_FRAME_OFFSET))
1817 apparent_fsize = 0;
1818
1819 actual_fsize = apparent_fsize + n_fregs*4;
1820
1821 /* Make sure nothing can clobber our register windows.
1822 If a SAVE must be done, or there is a stack-local variable,
1823 the register window area must be allocated. */
1824 if (leaf_function == 0 || size > 0)
1825 actual_fsize += (16 * UNITS_PER_WORD)+8;
1826
1827 return actual_fsize;
1828}
1829
84c0bb63
RS
1830/* If this were a leaf function, how far would we have to reach
1831 from the stack pointer to the last arg on the stack?
1832
1833 If we don't know, return 4096 (i.e., "too far".) */
1834
1835int
1836compute_last_arg_offset ()
1837{
1838 if (GET_CODE (current_function_arg_offset_rtx) == CONST_INT)
1839 return (compute_frame_size (get_frame_size (), 1)
1840 + INTVAL (current_function_arg_offset_rtx));
1841 return 4096;
1842}
1843
ab835497
RK
1844void
1845output_function_prologue (file, size, leaf_function)
1846 FILE *file;
1847 int size;
1848{
1849 if (leaf_function)
1850 frame_base_name = "%sp+80";
1851 else
1852 frame_base_name = "%fp";
1853
1854 actual_fsize = compute_frame_size (size, leaf_function);
1855
1856 fprintf (file, "\t!#PROLOGUE# 0\n");
1857 if (actual_fsize == 0) /* do nothing. */ ;
1858 else if (actual_fsize < 4096)
1859 {
1860 if (! leaf_function)
1861 fprintf (file, "\tsave %%sp,-%d,%%sp\n", actual_fsize);
1862 else
1863 fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize);
1864 }
1865 else if (! leaf_function)
1866 {
1867 /* Need to use actual_fsize, since we are also allocating space for
1868 our callee (and our own register save area). */
1869 fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n",
1870 -actual_fsize, -actual_fsize);
1871 fprintf (file, "\tsave %%sp,%%g1,%%sp\n");
1872 }
1873 else
1874 {
84c0bb63
RS
1875 /* The rest of the support for this case hasn't been implemented,
1876 but FRAME_POINTER_REQUIRED is supposed to prevent it from arising,
1877 by checking the frame size. */
1878 abort ();
1879
ab835497
RK
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. */
ab835497
RK
1883 fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n",
1884 -actual_fsize, -actual_fsize);
1885 fprintf (file, "\tadd %%sp,64,%%g4\n\tadd %%sp,%%g1,%%sp\n");
1886 }
1887
1888 /* If doing anything with PIC, do it now. */
1889 if (! flag_pic)
1890 fprintf (file, "\t!#PROLOGUE# 1\n");
1891
1892 /* Figure out where to save any special registers. */
1893 if (num_fregs)
1894 {
1895 int offset, n_fregs = num_fregs;
1896
1897 if (! leaf_function)
1898 offset = -apparent_fsize;
1899 else
1900 offset = 0;
1901
1902 if (TARGET_EPILOGUE && ! leaf_function)
1903 n_fregs = save_regs (file, 0, 16, frame_base_name, offset, 0);
1904 else if (leaf_function)
1905 n_fregs = save_regs (file, 0, 32, frame_base_name, offset, 0);
1906 if (TARGET_EPILOGUE)
1907 save_regs (file, 32, FIRST_PSEUDO_REGISTER,
1908 frame_base_name, offset, n_fregs);
1909 }
1910
1911 if (regs_ever_live[62])
1912 fprintf (file, "\tst %s,[%s-16]\n\tst %s,[%s-12]\n",
1913 reg_names[0], frame_base_name,
1914 reg_names[0], frame_base_name);
1915
1916 leaf_label = 0;
1917 if (leaf_function && actual_fsize != 0)
1918 {
1919 /* warning ("leaf procedure with frame size %d", actual_fsize); */
1920 if (! TARGET_EPILOGUE)
1921 leaf_label = gen_label_rtx ();
1922 }
1923}
1924
1925void
ef8200df 1926output_function_epilogue (file, size, leaf_function)
ab835497
RK
1927 FILE *file;
1928 int size;
ef8200df 1929 int leaf_function;
ab835497
RK
1930{
1931 int n_fregs, i;
1932 char *ret;
1933
1934 if (leaf_label)
1935 {
ab835497
RK
1936 emit_label_after (leaf_label, get_last_insn ());
1937 final_scan_insn (get_last_insn (), file, 0, 0, 1);
1938 }
1939
1940 if (num_fregs)
1941 {
1942 int offset, n_fregs = num_fregs;
1943
1944 if (! leaf_function)
1945 offset = -apparent_fsize;
1946 else
1947 offset = 0;
1948
1949 if (TARGET_EPILOGUE && ! leaf_function)
1950 n_fregs = restore_regs (file, 0, 16, frame_base_name, offset, 0);
1951 else if (leaf_function)
1952 n_fregs = restore_regs (file, 0, 32, frame_base_name, offset, 0);
1953 if (TARGET_EPILOGUE)
1954 restore_regs (file, 32, FIRST_PSEUDO_REGISTER,
1955 frame_base_name, offset, n_fregs);
1956 }
1957
1958 /* Work out how to skip the caller's unimp instruction if required. */
1959 if (leaf_function)
1960 ret = (current_function_returns_struct ? "jmp %o7+12" : "retl");
1961 else
1962 ret = (current_function_returns_struct ? "jmp %i7+12" : "ret");
1963
ef8200df 1964 if (TARGET_EPILOGUE || leaf_label)
ab835497 1965 {
ef8200df
JW
1966 int old_target_epilogue = TARGET_EPILOGUE;
1967 target_flags &= ~old_target_epilogue;
ab835497 1968
ef8200df
JW
1969 if (! leaf_function)
1970 {
1971 /* If we wound up with things in our delay slot, flush them here. */
1972 if (current_function_epilogue_delay_list)
ab835497 1973 {
ef8200df
JW
1974 rtx insn = emit_jump_insn_after (gen_rtx (RETURN, VOIDmode),
1975 get_last_insn ());
1976 PATTERN (insn) = gen_rtx (PARALLEL, VOIDmode,
1977 gen_rtvec (2,
1978 PATTERN (XEXP (current_function_epilogue_delay_list, 0)),
1979 PATTERN (insn)));
1980 final_scan_insn (insn, file, 1, 0, 1);
ab835497
RK
1981 }
1982 else
ef8200df
JW
1983 fprintf (file, "\t%s\n\trestore\n", ret);
1984 }
1985 else if (actual_fsize < 4096)
1986 {
1987 if (current_function_epilogue_delay_list)
ab835497 1988 {
ef8200df
JW
1989 fprintf (file, "\t%s\n", ret);
1990 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1991 file, 1, 0, 1);
ab835497 1992 }
ef8200df
JW
1993 else
1994 fprintf (file, "\t%s\n\tadd %%sp,%d,%%sp\n", ret, actual_fsize);
ab835497 1995 }
ef8200df 1996 else
ab835497 1997 {
ef8200df
JW
1998 if (current_function_epilogue_delay_list)
1999 abort ();
2000 fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n",
2001 actual_fsize, actual_fsize, ret);
ab835497 2002 }
ef8200df 2003 target_flags |= old_target_epilogue;
ab835497
RK
2004 }
2005}
2006\f
2007/* Return the string to output a conditional branch to LABEL, which is
2008 the operand number of the label. OP is the conditional expression. The
2009 mode of register 0 says what kind of comparison we made.
2010
2011 REVERSED is non-zero if we should reverse the sense of the comparison.
2012
2013 ANNUL is non-zero if we should generate an annulling branch.
2014
2015 NOOP is non-zero if we have to follow this branch by a noop. */
2016
2017char *
2018output_cbranch (op, label, reversed, annul, noop)
2019 rtx op;
2020 int label;
2021 int reversed, annul, noop;
2022{
2023 static char string[20];
2024 enum rtx_code code = GET_CODE (op);
2025 enum machine_mode mode = GET_MODE (XEXP (op, 0));
2026 static char labelno[] = " %lX";
2027
b4ac57ab 2028 /* ??? FP branches can not be preceded by another floating point insn.
ab835497
RK
2029 Because there is currently no concept of pre-delay slots, we can fix
2030 this only by always emitting a nop before a floating point branch. */
2031
2032 if (mode == CCFPmode)
2033 strcpy (string, "nop\n\t");
2034
2035 /* If not floating-point or if EQ or NE, we can just reverse the code. */
2036 if (reversed && (mode != CCFPmode || code == EQ || code == NE))
2037 code = reverse_condition (code), reversed = 0;
2038
2039 /* Start by writing the branch condition. */
2040 switch (code)
2041 {
2042 case NE:
2043 if (mode == CCFPmode)
2044 strcat (string, "fbne");
2045 else
2046 strcpy (string, "bne");
2047 break;
2048
2049 case EQ:
2050 if (mode == CCFPmode)
2051 strcat (string, "fbe");
2052 else
2053 strcpy (string, "be");
2054 break;
2055
2056 case GE:
2057 if (mode == CCFPmode)
2058 {
2059 if (reversed)
2060 strcat (string, "fbul");
2061 else
2062 strcat (string, "fbge");
2063 }
2064 else if (mode == CC_NOOVmode)
2065 strcpy (string, "bpos");
2066 else
2067 strcpy (string, "bge");
2068 break;
2069
2070 case GT:
2071 if (mode == CCFPmode)
2072 {
2073 if (reversed)
2074 strcat (string, "fbule");
2075 else
2076 strcat (string, "fbg");
2077 }
2078 else
2079 strcpy (string, "bg");
2080 break;
2081
2082 case LE:
2083 if (mode == CCFPmode)
2084 {
2085 if (reversed)
2086 strcat (string, "fbug");
2087 else
2088 strcat (string, "fble");
2089 }
2090 else
2091 strcpy (string, "ble");
2092 break;
2093
2094 case LT:
2095 if (mode == CCFPmode)
2096 {
2097 if (reversed)
2098 strcat (string, "fbuge");
2099 else
2100 strcat (string, "fbl");
2101 }
2102 else if (mode == CC_NOOVmode)
2103 strcpy (string, "bneg");
2104 else
2105 strcpy (string, "bl");
2106 break;
2107
2108 case GEU:
2109 strcpy (string, "bgeu");
2110 break;
2111
2112 case GTU:
2113 strcpy (string, "bgu");
2114 break;
2115
2116 case LEU:
2117 strcpy (string, "bleu");
2118 break;
2119
2120 case LTU:
2121 strcpy (string, "blu");
2122 break;
2123 }
2124
2125 /* Now add the annulling, the label, and a possible noop. */
2126 if (annul)
2127 strcat (string, ",a");
2128
2129 labelno[3] = label + '0';
2130 strcat (string, labelno);
2131
2132 if (noop)
2133 strcat (string, "\n\tnop");
2134
2135 return string;
2136}
2137
2138char *
2139output_return (operands)
2140 rtx *operands;
2141{
2142 if (leaf_label)
2143 {
2144 operands[0] = leaf_label;
2145 return "b,a %l0";
2146 }
2147 else if (leaf_function)
2148 {
2149 operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize);
2150 if (actual_fsize < 4096)
2151 {
2152 if (current_function_returns_struct)
2153 return "jmp %%o7+12\n\tadd %%sp,%0,%%sp";
2154 else
2155 return "retl\n\tadd %%sp,%0,%%sp";
2156 }
2157 else
2158 {
2159 if (current_function_returns_struct)
2160 return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp";
2161 else
2162 return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp";
2163 }
2164 }
2165 else
2166 {
2167 if (current_function_returns_struct)
2168 return "jmp %%i7+12\n\trestore";
2169 else
2170 return "ret\n\trestore";
2171 }
2172}
2173
2174char *
2175output_floatsisf2 (operands)
2176 rtx *operands;
2177{
2178 if (GET_CODE (operands[1]) == MEM)
2179 return "ld %1,%0\n\tfitos %0,%0";
2180 else if (FP_REG_P (operands[1]))
2181 return "fitos %1,%0";
2182 return "st %r1,[%%fp-4]\n\tld [%%fp-4],%0\n\tfitos %0,%0";
2183}
2184
2185char *
2186output_floatsidf2 (operands)
2187 rtx *operands;
2188{
2189 if (GET_CODE (operands[1]) == MEM)
2190 return "ld %1,%0\n\tfitod %0,%0";
2191 else if (FP_REG_P (operands[1]))
2192 return "fitod %1,%0";
2193 return "st %r1,[%%fp-4]\n\tld [%%fp-4],%0\n\tfitod %0,%0";
2194}
ab835497
RK
2195\f
2196/* Leaf functions and non-leaf functions have different needs. */
2197
2198static int
2199reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
2200
2201static int
2202reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
2203
2204static int *reg_alloc_orders[] = {
2205 reg_leaf_alloc_order,
2206 reg_nonleaf_alloc_order};
2207
2208void
2209order_regs_for_local_alloc ()
2210{
2211 static int last_order_nonleaf = 1;
2212
2213 if (regs_ever_live[15] != last_order_nonleaf)
2214 {
2215 last_order_nonleaf = !last_order_nonleaf;
2216 bcopy (reg_alloc_orders[last_order_nonleaf], reg_alloc_order,
2217 FIRST_PSEUDO_REGISTER * sizeof (int));
2218 }
2219}
2220\f
2221/* Machine dependent routines for the branch probability, arc profiling
2222 code. */
2223
2224/* The label used by the arc profiling code. */
2225
2226static rtx profiler_label;
2227
2228void
2229init_arc_profiler ()
2230{
2231 /* Generate and save a copy of this so it can be shared. */
2232 profiler_label = gen_rtx (SYMBOL_REF, Pmode, "*LPBX2");
2233}
2234
2235void
2236output_arc_profiler (arcno, insert_after)
2237 int arcno;
2238 rtx insert_after;
2239{
2240 rtx profiler_target_addr
2241 = gen_rtx (CONST, Pmode,
2242 gen_rtx (PLUS, Pmode, profiler_label,
2243 gen_rtx (CONST_INT, VOIDmode, 4 * arcno)));
2244 register rtx profiler_reg = gen_reg_rtx (SImode);
b4ac57ab
RS
2245 register rtx address_reg = gen_reg_rtx (Pmode);
2246 rtx mem_ref;
2247
2248 insert_after = emit_insn_after (gen_rtx (SET, VOIDmode, address_reg,
2249 gen_rtx (HIGH, Pmode,
2250 profiler_target_addr)),
2251 insert_after);
2252
2253 mem_ref = gen_rtx (MEM, SImode, gen_rtx (LO_SUM, Pmode, address_reg,
2254 profiler_target_addr));
2255 insert_after = emit_insn_after (gen_rtx (SET, VOIDmode, profiler_reg,
2256 mem_ref),
2257 insert_after);
2258
2259 insert_after = emit_insn_after (gen_rtx (SET, VOIDmode, profiler_reg,
2260 gen_rtx (PLUS, SImode, profiler_reg,
2261 const1_rtx)),
2262 insert_after);
2263
2264 /* This is the same rtx as above, but it is not legal to share this rtx. */
2265 mem_ref = gen_rtx (MEM, SImode, gen_rtx (LO_SUM, Pmode, address_reg,
2266 profiler_target_addr));
2267 emit_insn_after (gen_rtx (SET, VOIDmode, mem_ref, profiler_reg),
ab835497
RK
2268 insert_after);
2269}
2270\f
ab835497
RK
2271/* Print operand X (an rtx) in assembler syntax to file FILE.
2272 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2273 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2274
2275void
2276print_operand (file, x, code)
2277 FILE *file;
2278 rtx x;
2279 int code;
2280{
2281 switch (code)
2282 {
2283 case '#':
2284 /* Output a 'nop' if there's nothing for the delay slot. */
2285 if (dbr_sequence_length () == 0)
2286 fputs ("\n\tnop", file);
2287 return;
2288 case '*':
2289 /* Output an annul flag if there's nothing for the delay slot. */
2290 if (dbr_sequence_length () == 0)
2291 fputs (",a", file);
2292 return;
2293 case 'Y':
2294 /* Adjust the operand to take into account a RESTORE operation. */
2295 if (GET_CODE (x) != REG)
2296 abort ();
2297 if (REGNO (x) < 8)
2298 fputs (reg_names[REGNO (x)], file);
2299 else if (REGNO (x) >= 24 && REGNO (x) < 32)
2300 fputs (reg_names[REGNO (x)-16], file);
2301 else
2302 abort ();
2303 return;
2304 case '@':
2305 /* Print out what we are using as the frame pointer. This might
2306 be %fp, or might be %sp+offset. */
2307 fputs (frame_base_name, file);
2308 return;
2309 case 'R':
2310 /* Print out the second register name of a register pair.
2311 I.e., R (%o0) => %o1. */
2312 fputs (reg_names[REGNO (x)+1], file);
2313 return;
2314 case 'm':
2315 /* Print the operand's address only. */
2316 output_address (XEXP (x, 0));
2317 return;
2318 case 'r':
2319 /* In this case we need a register. Use %g0 if the
2320 operand in const0_rtx. */
2321 if (x == const0_rtx)
2322 {
2323 fputs ("%g0", file);
2324 return;
2325 }
2326 else
2327 break;
2328
2329 case 'A':
2330 switch (GET_CODE (x))
2331 {
2332 case IOR: fputs ("or", file); break;
2333 case AND: fputs ("and", file); break;
2334 case XOR: fputs ("xor", file); break;
2335 default: abort ();
2336 }
2337 return;
2338
2339 case 'B':
2340 switch (GET_CODE (x))
2341 {
2342 case IOR: fputs ("orn", file); break;
2343 case AND: fputs ("andn", file); break;
2344 case XOR: fputs ("xnor", file); break;
2345 default: abort ();
2346 }
2347 return;
2348
2349 case 'b':
2350 {
2351 /* Print a sign-extended character. */
2352 int i = INTVAL (x) & 0xff;
2353 if (i & 0x80)
2354 i |= 0xffffff00;
2355 fprintf (file, "%d", i);
2356 return;
2357 }
2358
2359 case 0:
2360 /* Do nothing special. */
2361 break;
2362
2363 default:
2364 /* Undocumented flag. */
2365 abort ();
2366 }
2367
2368 if (GET_CODE (x) == REG)
2369 fputs (reg_names[REGNO (x)], file);
2370 else if (GET_CODE (x) == MEM)
2371 {
2372 fputc ('[', file);
2373 if (CONSTANT_P (XEXP (x, 0)))
2374 /* Poor Sun assembler doesn't understand absolute addressing. */
2375 fputs ("%g0+", file);
2376 output_address (XEXP (x, 0));
2377 fputc (']', file);
2378 }
2379 else if (GET_CODE (x) == HIGH)
2380 {
2381 fputs ("%hi(", file);
2382 output_addr_const (file, XEXP (x, 0));
2383 fputc (')', file);
2384 }
2385 else if (GET_CODE (x) == LO_SUM)
2386 {
2387 print_operand (file, XEXP (x, 0), 0);
2388 fputs ("+%lo(", file);
2389 output_addr_const (file, XEXP (x, 1));
2390 fputc (')', file);
2391 }
2392 else if (GET_CODE (x) == CONST_DOUBLE)
2393 {
2394 if (CONST_DOUBLE_HIGH (x) == 0)
2395 fprintf (file, "%u", CONST_DOUBLE_LOW (x));
2396 else if (CONST_DOUBLE_HIGH (x) == -1
2397 && CONST_DOUBLE_LOW (x) < 0)
2398 fprintf (file, "%d", CONST_DOUBLE_LOW (x));
2399 else
2400 abort ();
2401 }
2402 else { output_addr_const (file, x); }
2403}
2404\f
2405/* This function outputs assembler code for VALUE to FILE, where VALUE is
2406 a 64 bit (DImode) value. */
2407
2408/* ??? If there is a 64 bit counterpart to .word that the assembler
2409 understands, then using that would simply this code greatly. */
2410
2411void
2412output_double_int (file, value)
2413 FILE *file;
2414 rtx value;
2415{
2416 if (GET_CODE (value) == CONST_INT)
2417 {
2418 if (INTVAL (value) < 0)
2419 ASM_OUTPUT_INT (file, constm1_rtx);
2420 else
2421 ASM_OUTPUT_INT (file, const0_rtx);
2422 ASM_OUTPUT_INT (file, value);
2423 }
2424 else if (GET_CODE (value) == CONST_DOUBLE)
2425 {
2426 ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode,
2427 CONST_DOUBLE_HIGH (value)));
2428 ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode,
2429 CONST_DOUBLE_LOW (value)));
2430 }
2431 else if (GET_CODE (value) == SYMBOL_REF
2432 || GET_CODE (value) == CONST
2433 || GET_CODE (value) == PLUS)
2434 {
2435 /* Addresses are only 32 bits. */
2436 ASM_OUTPUT_INT (file, const0_rtx);
2437 ASM_OUTPUT_INT (file, value);
2438 }
2439 else
2440 abort ();
2441}
210aa14a
RS
2442\f
2443/* Compute the code to put in the .proc statement
2444 for a function that returns type TYPE. */
2445
2446unsigned long
2447sparc_type_code (type)
2448 register tree type;
2449{
2450 register unsigned long qualifiers = 0;
2451 register unsigned shift = 6;
2452
2453 for (;;)
2454 {
2455 switch (TREE_CODE (type))
2456 {
2457 case ERROR_MARK:
2458 return qualifiers;
2459
2460 case ARRAY_TYPE:
2461 qualifiers |= (3 << shift);
2462 shift += 2;
2463 type = TREE_TYPE (type);
2464 break;
2465
2466 case FUNCTION_TYPE:
2467 case METHOD_TYPE:
2468 qualifiers |= (2 << shift);
2469 shift += 2;
2470 type = TREE_TYPE (type);
2471 break;
2472
2473 case POINTER_TYPE:
2474 case REFERENCE_TYPE:
2475 case OFFSET_TYPE:
2476 qualifiers |= (1 << shift);
2477 shift += 2;
2478 type = TREE_TYPE (type);
2479 break;
ab835497 2480
210aa14a
RS
2481 case RECORD_TYPE:
2482 return (qualifiers | 8);
2483
2484 case UNION_TYPE:
2485 return (qualifiers | 9);
2486
2487 case ENUMERAL_TYPE:
2488 return (qualifiers | 10);
2489
2490 case VOID_TYPE:
2491 return (qualifiers | 16);
2492
2493 case INTEGER_TYPE:
2494 /* This return value is not always completely the same as Sun's
2495 but the Sun assembler's peephole optimizer probably doesn't
2496 care. */
2497 return (qualifiers | 4);
2498
2499 case REAL_TYPE:
2500 if (TYPE_PRECISION (type) == 32)
2501 return (qualifiers | 6);
2502 else
2503 return (qualifiers | 7); /* Who knows? */
2504
2505 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
2506 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
2507 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
2508 case FILE_TYPE: /* GNU Pascal FILE type. */
2509 case STRING_TYPE: /* GNU Fortran STRING type. */
2510 case LANG_TYPE: /* ? */
2511 abort ();
2512
2513 default:
2514 abort (); /* Not a type! */
2515 }
2516 }
2517}
This page took 0.272728 seconds and 5 git commands to generate.