* config/i860/i860-protos.h (i860_va_arg): Remove.
[official-gcc.git] / gcc / config / i860 / i860.c
blob1dc58a400519f770a93c52258cb637152113b47a
1 /* Subroutines for insn-output.c for Intel i860
2 Copyright (C) 1989, 1991, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Derived from sparc.c.
6 Written by Richard Stallman (rms@ai.mit.edu).
8 Hacked substantially by Ron Guilmette (rfg@netcom.com) to cater
9 to the whims of the System V Release 4 assembler.
11 This file is part of GCC.
13 GCC is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
18 GCC is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GCC; see the file COPYING. If not, write to
25 the Free Software Foundation, 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "flags.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "regs.h"
37 #include "hard-reg-set.h"
38 #include "real.h"
39 #include "insn-config.h"
40 #include "conditions.h"
41 #include "output.h"
42 #include "recog.h"
43 #include "insn-attr.h"
44 #include "function.h"
45 #include "expr.h"
46 #include "optabs.h"
47 #include "toplev.h"
48 #include "tm_p.h"
49 #include "target.h"
50 #include "target-def.h"
51 #include "langhooks.h"
52 #include "tree-gimple.h"
54 static rtx find_addr_reg (rtx);
56 #ifndef I860_REG_PREFIX
57 #define I860_REG_PREFIX ""
58 #endif
60 const char *i860_reg_prefix = I860_REG_PREFIX;
62 /* Save information from a "cmpxx" operation until the branch is emitted. */
64 rtx i860_compare_op0, i860_compare_op1;
66 /* Return nonzero if this pattern, can be evaluated safely, even if it
67 was not asked for. */
68 int
69 safe_insn_src_p (rtx op, enum machine_mode mode)
71 /* Just experimenting. */
73 /* No floating point source is safe if it contains an arithmetic
74 operation, since that operation may trap. */
75 switch (GET_CODE (op))
77 case CONST_INT:
78 case LABEL_REF:
79 case SYMBOL_REF:
80 case CONST:
81 return 1;
83 case REG:
84 return 1;
86 case MEM:
87 return CONSTANT_ADDRESS_P (XEXP (op, 0));
89 /* We never need to negate or complement constants. */
90 case NEG:
91 return (mode != SFmode && mode != DFmode);
92 case NOT:
93 case ZERO_EXTEND:
94 return 1;
96 case EQ:
97 case NE:
98 case LT:
99 case GT:
100 case LE:
101 case GE:
102 case LTU:
103 case GTU:
104 case LEU:
105 case GEU:
106 case MINUS:
107 case PLUS:
108 return (mode != SFmode && mode != DFmode);
109 case AND:
110 case IOR:
111 case XOR:
112 case ASHIFT:
113 case ASHIFTRT:
114 case LSHIFTRT:
115 if ((GET_CODE (XEXP (op, 0)) == CONST_INT && ! SMALL_INT (XEXP (op, 0)))
116 || (GET_CODE (XEXP (op, 1)) == CONST_INT && ! SMALL_INT (XEXP (op, 1))))
117 return 0;
118 return 1;
120 default:
121 return 0;
125 /* Return 1 if REG is clobbered in IN.
126 Return 2 if REG is used in IN.
127 Return 3 if REG is both used and clobbered in IN.
128 Return 0 if none of the above. */
130 static int
131 reg_clobbered_p (rtx reg, rtx in)
133 register enum rtx_code code;
135 if (in == 0)
136 return 0;
138 code = GET_CODE (in);
140 if (code == SET || code == CLOBBER)
142 rtx dest = SET_DEST (in);
143 int set = 0;
144 int used = 0;
146 while (GET_CODE (dest) == STRICT_LOW_PART
147 || GET_CODE (dest) == SUBREG
148 || GET_CODE (dest) == SIGN_EXTRACT
149 || GET_CODE (dest) == ZERO_EXTRACT)
150 dest = XEXP (dest, 0);
152 if (dest == reg)
153 set = 1;
154 else if (GET_CODE (dest) == REG
155 && refers_to_regno_p (REGNO (reg),
156 REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
157 SET_DEST (in), 0))
159 set = 1;
160 /* Anything that sets just part of the register
161 is considered using as well as setting it.
162 But note that a straight SUBREG of a single-word value
163 clobbers the entire value. */
164 if (dest != SET_DEST (in)
165 && ! (GET_CODE (SET_DEST (in)) == SUBREG
166 || UNITS_PER_WORD >= GET_MODE_SIZE (GET_MODE (dest))))
167 used = 1;
170 if (code == SET)
172 if (set)
173 used = refers_to_regno_p (REGNO (reg),
174 REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
175 SET_SRC (in), 0);
176 else
177 used = refers_to_regno_p (REGNO (reg),
178 REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
179 in, 0);
182 return set + used * 2;
185 if (refers_to_regno_p (REGNO (reg),
186 REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
187 in, 0))
188 return 2;
189 return 0;
192 /* Return nonzero if OP can be written to without screwing up
193 GCC's model of what's going on. It is assumed that this operand
194 appears in the dest position of a SET insn in a conditional
195 branch's delay slot. AFTER is the label to start looking from. */
197 operand_clobbered_before_used_after (rtx op, rtx after)
199 /* Just experimenting. */
200 if (GET_CODE (op) == CC0)
201 return 1;
202 if (GET_CODE (op) == REG)
204 rtx insn;
206 if (op == stack_pointer_rtx)
207 return 0;
209 /* Scan forward from the label, to see if the value of OP
210 is clobbered before the first use. */
212 for (insn = NEXT_INSN (after); insn; insn = NEXT_INSN (insn))
214 if (GET_CODE (insn) == NOTE)
215 continue;
216 if (GET_CODE (insn) == INSN
217 || GET_CODE (insn) == JUMP_INSN
218 || GET_CODE (insn) == CALL_INSN)
220 switch (reg_clobbered_p (op, PATTERN (insn)))
222 default:
223 return 0;
224 case 1:
225 return 1;
226 case 0:
227 break;
230 /* If we reach another label without clobbering OP,
231 then we cannot safely write it here. */
232 else if (GET_CODE (insn) == CODE_LABEL)
233 return 0;
234 if (GET_CODE (insn) == JUMP_INSN)
236 if (condjump_p (insn))
237 return 0;
238 /* This is a jump insn which has already
239 been mangled. We can't tell what it does. */
240 if (GET_CODE (PATTERN (insn)) == PARALLEL)
241 return 0;
242 if (! JUMP_LABEL (insn))
243 return 0;
244 /* Keep following jumps. */
245 insn = JUMP_LABEL (insn);
248 return 1;
251 /* In both of these cases, the first insn executed
252 for this op will be a orh whatever%h,%r0,%r31,
253 which is tolerable. */
254 if (GET_CODE (op) == MEM)
255 return (CONSTANT_ADDRESS_P (XEXP (op, 0)));
257 return 0;
261 /* Return nonzero only if OP is a register of mode MODE,
262 or const0_rtx. */
264 reg_or_0_operand (rtx op, enum machine_mode mode)
266 return (op == const0_rtx || register_operand (op, mode)
267 || op == CONST0_RTX (mode));
270 /* Return truth value of whether OP can be used as an operands in a three
271 address add/subtract insn (such as add %o1,7,%l2) of mode MODE. */
274 arith_operand (rtx op, enum machine_mode mode)
276 return (register_operand (op, mode)
277 || (GET_CODE (op) == CONST_INT && SMALL_INT (op)));
280 /* Return 1 if OP is a valid first operand for a logical insn of mode MODE. */
283 logic_operand (rtx op, enum machine_mode mode)
285 return (register_operand (op, mode)
286 || (GET_CODE (op) == CONST_INT && LOGIC_INT (op)));
289 /* Return 1 if OP is a valid first operand for a shift insn of mode MODE. */
292 shift_operand (rtx op, enum machine_mode mode)
294 return (register_operand (op, mode)
295 || (GET_CODE (op) == CONST_INT));
298 /* Return 1 if OP is a valid first operand for either a logical insn
299 or an add insn of mode MODE. */
302 compare_operand (rtx op, enum machine_mode mode)
304 return (register_operand (op, mode)
305 || (GET_CODE (op) == CONST_INT && SMALL_INT (op) && LOGIC_INT (op)));
308 /* Return truth value of whether OP can be used as the 5-bit immediate
309 operand of a bte or btne insn. */
312 bte_operand (rtx op, enum machine_mode mode)
314 return (register_operand (op, mode)
315 || (GET_CODE (op) == CONST_INT
316 && (unsigned) INTVAL (op) < 0x20));
319 /* Return 1 if OP is an indexed memory reference of mode MODE. */
322 indexed_operand (rtx op, enum machine_mode mode)
324 return (GET_CODE (op) == MEM && GET_MODE (op) == mode
325 && GET_CODE (XEXP (op, 0)) == PLUS
326 && GET_MODE (XEXP (op, 0)) == SImode
327 && register_operand (XEXP (XEXP (op, 0), 0), SImode)
328 && register_operand (XEXP (XEXP (op, 0), 1), SImode));
331 /* Return 1 if OP is a suitable source operand for a load insn
332 with mode MODE. */
335 load_operand (rtx op, enum machine_mode mode)
337 return (memory_operand (op, mode) || indexed_operand (op, mode));
340 /* Return truth value of whether OP is an integer which fits the
341 range constraining immediate operands in add/subtract insns. */
344 small_int (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
346 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
349 /* Return truth value of whether OP is an integer which fits the
350 range constraining immediate operands in logic insns. */
353 logic_int (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
355 return (GET_CODE (op) == CONST_INT && LOGIC_INT (op));
358 /* Test for a valid operand for a call instruction.
359 Don't allow the arg pointer register or virtual regs
360 since they may change into reg + const, which the patterns
361 can't handle yet. */
364 call_insn_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
366 if (GET_CODE (op) == MEM
367 && (CONSTANT_ADDRESS_P (XEXP (op, 0))
368 || (GET_CODE (XEXP (op, 0)) == REG
369 && XEXP (op, 0) != arg_pointer_rtx
370 && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
371 && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
372 return 1;
373 return 0;
376 /* Return the best assembler insn template
377 for moving operands[1] into operands[0] as a fullword. */
379 static const char *
380 singlemove_string (rtx *operands)
382 if (GET_CODE (operands[0]) == MEM)
384 if (GET_CODE (operands[1]) != MEM)
385 if (CONSTANT_ADDRESS_P (XEXP (operands[0], 0)))
387 if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
388 && (cc_prev_status.flags & CC_HI_R31_ADJ)
389 && cc_prev_status.mdep == XEXP (operands[0], 0)))
391 CC_STATUS_INIT;
392 output_asm_insn ("orh %h0,%?r0,%?r31", operands);
394 cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
395 cc_status.mdep = XEXP (operands[0], 0);
396 return "st.l %r1,%L0(%?r31)";
398 else
399 return "st.l %r1,%0";
400 else
401 abort ();
402 #if 0
404 rtx xoperands[2];
406 cc_status.flags &= ~CC_F0_IS_0;
407 xoperands[0] = gen_rtx_REG (SFmode, 32);
408 xoperands[1] = operands[1];
409 output_asm_insn (singlemove_string (xoperands), xoperands);
410 xoperands[1] = xoperands[0];
411 xoperands[0] = operands[0];
412 output_asm_insn (singlemove_string (xoperands), xoperands);
413 return "";
415 #endif
417 if (GET_CODE (operands[1]) == MEM)
419 if (CONSTANT_ADDRESS_P (XEXP (operands[1], 0)))
421 if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
422 && (cc_prev_status.flags & CC_HI_R31_ADJ)
423 && cc_prev_status.mdep == XEXP (operands[1], 0)))
425 CC_STATUS_INIT;
426 output_asm_insn ("orh %h1,%?r0,%?r31", operands);
428 cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
429 cc_status.mdep = XEXP (operands[1], 0);
430 return "ld.l %L1(%?r31),%0";
432 return "ld.l %m1,%0";
434 if (GET_CODE (operands[1]) == CONST_INT)
436 if (operands[1] == const0_rtx)
437 return "mov %?r0,%0";
438 if((INTVAL (operands[1]) & 0xffff0000) == 0)
439 return "or %L1,%?r0,%0";
440 if((INTVAL (operands[1]) & 0xffff8000) == 0xffff8000)
441 return "adds %1,%?r0,%0";
442 if((INTVAL (operands[1]) & 0x0000ffff) == 0)
443 return "orh %H1,%?r0,%0";
445 return "orh %H1,%?r0,%0\n\tor %L1,%0,%0";
447 return "mov %1,%0";
450 /* Output assembler code to perform a doubleword move insn
451 with operands OPERANDS. */
453 const char *
454 output_move_double (rtx *operands)
456 enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
457 rtx latehalf[2];
458 rtx addreg0 = 0, addreg1 = 0;
459 int highest_first = 0;
460 int no_addreg1_decrement = 0;
462 /* First classify both operands. */
464 if (REG_P (operands[0]))
465 optype0 = REGOP;
466 else if (offsettable_memref_p (operands[0]))
467 optype0 = OFFSOP;
468 else if (GET_CODE (operands[0]) == MEM)
469 optype0 = MEMOP;
470 else
471 optype0 = RNDOP;
473 if (REG_P (operands[1]))
474 optype1 = REGOP;
475 else if (CONSTANT_P (operands[1]))
476 optype1 = CNSTOP;
477 else if (offsettable_memref_p (operands[1]))
478 optype1 = OFFSOP;
479 else if (GET_CODE (operands[1]) == MEM)
480 optype1 = MEMOP;
481 else
482 optype1 = RNDOP;
484 /* Check for the cases that the operand constraints are not
485 supposed to allow to happen. Abort if we get one,
486 because generating code for these cases is painful. */
488 if (optype0 == RNDOP || optype1 == RNDOP)
489 abort ();
491 /* If an operand is an unoffsettable memory reference, find a register
492 we can increment temporarily to make it refer to the second word. */
494 if (optype0 == MEMOP)
495 addreg0 = find_addr_reg (XEXP (operands[0], 0));
497 if (optype1 == MEMOP)
498 addreg1 = find_addr_reg (XEXP (operands[1], 0));
500 /* ??? Perhaps in some cases move double words
501 if there is a spare pair of floating regs. */
503 /* Ok, we can do one word at a time.
504 Normally we do the low-numbered word first,
505 but if either operand is autodecrementing then we
506 do the high-numbered word first.
508 In either case, set up in LATEHALF the operands to use
509 for the high-numbered word and in some cases alter the
510 operands in OPERANDS to be suitable for the low-numbered word. */
512 if (optype0 == REGOP)
513 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
514 else if (optype0 == OFFSOP)
515 latehalf[0] = adjust_address (operands[0], SImode, 4);
516 else
517 latehalf[0] = operands[0];
519 if (optype1 == REGOP)
520 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
521 else if (optype1 == OFFSOP)
522 latehalf[1] = adjust_address (operands[1], SImode, 4);
523 else if (optype1 == CNSTOP)
525 if (GET_CODE (operands[1]) == CONST_DOUBLE)
526 split_double (operands[1], &operands[1], &latehalf[1]);
527 #if 0
528 else if (CONSTANT_P (operands[1]))
529 latehalf[1] = const0_rtx;
530 #else
531 else if (CONSTANT_P (operands[1]))
532 split_double (operands[1], &operands[1], &latehalf[1]);
533 #endif
535 else
536 latehalf[1] = operands[1];
538 /* If the first move would clobber the source of the second one,
539 do them in the other order.
541 RMS says "This happens only for registers;
542 such overlap can't happen in memory unless the user explicitly
543 sets it up, and that is an undefined circumstance."
545 But it happens on the sparc when loading parameter registers,
546 so I am going to define that circumstance, and make it work
547 as expected. */
549 if (optype0 == REGOP && optype1 == REGOP
550 && REGNO (operands[0]) == REGNO (latehalf[1]))
552 CC_STATUS_PARTIAL_INIT;
553 /* Make any unoffsettable addresses point at high-numbered word. */
554 if (addreg0)
555 output_asm_insn ("adds 0x4,%0,%0", &addreg0);
556 if (addreg1)
557 output_asm_insn ("adds 0x4,%0,%0", &addreg1);
559 /* Do that word. */
560 output_asm_insn (singlemove_string (latehalf), latehalf);
562 /* Undo the adds we just did. */
563 if (addreg0)
564 output_asm_insn ("adds -0x4,%0,%0", &addreg0);
565 if (addreg1)
566 output_asm_insn ("adds -0x4,%0,%0", &addreg1);
568 /* Do low-numbered word. */
569 return singlemove_string (operands);
571 else if (optype0 == REGOP && optype1 != REGOP
572 && reg_overlap_mentioned_p (operands[0], operands[1]))
574 /* If both halves of dest are used in the src memory address,
575 add the two regs and put them in the low reg (operands[0]).
576 Then it works to load latehalf first. */
577 if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
578 && reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
580 rtx xops[2];
581 xops[0] = latehalf[0];
582 xops[1] = operands[0];
583 output_asm_insn ("adds %1,%0,%1", xops);
584 operands[1] = gen_rtx_MEM (DImode, operands[0]);
585 latehalf[1] = adjust_address (operands[1], SImode, 4);
586 addreg1 = 0;
587 highest_first = 1;
589 /* Only one register in the dest is used in the src memory address,
590 and this is the first register of the dest, so we want to do
591 the late half first here also. */
592 else if (! reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
593 highest_first = 1;
594 /* Only one register in the dest is used in the src memory address,
595 and this is the second register of the dest, so we want to do
596 the late half last. If addreg1 is set, and addreg1 is the same
597 register as latehalf, then we must suppress the trailing decrement,
598 because it would clobber the value just loaded. */
599 else if (addreg1 && reg_mentioned_p (addreg1, latehalf[0]))
600 no_addreg1_decrement = 1;
603 /* Normal case: do the two words, low-numbered first.
604 Overlap case (highest_first set): do high-numbered word first. */
606 if (! highest_first)
607 output_asm_insn (singlemove_string (operands), operands);
609 CC_STATUS_PARTIAL_INIT;
610 /* Make any unoffsettable addresses point at high-numbered word. */
611 if (addreg0)
612 output_asm_insn ("adds 0x4,%0,%0", &addreg0);
613 if (addreg1)
614 output_asm_insn ("adds 0x4,%0,%0", &addreg1);
616 /* Do that word. */
617 output_asm_insn (singlemove_string (latehalf), latehalf);
619 /* Undo the adds we just did. */
620 if (addreg0)
621 output_asm_insn ("adds -0x4,%0,%0", &addreg0);
622 if (addreg1 && !no_addreg1_decrement)
623 output_asm_insn ("adds -0x4,%0,%0", &addreg1);
625 if (highest_first)
626 output_asm_insn (singlemove_string (operands), operands);
628 return "";
631 const char *
632 output_fp_move_double (rtx *operands)
634 /* If the source operand is any sort of zero, use f0 instead. */
636 if (operands[1] == CONST0_RTX (GET_MODE (operands[1])))
637 operands[1] = gen_rtx_REG (DFmode, F0_REGNUM);
639 if (FP_REG_P (operands[0]))
641 if (FP_REG_P (operands[1]))
642 return "fmov.dd %1,%0";
643 if (GET_CODE (operands[1]) == REG)
645 output_asm_insn ("ixfr %1,%0", operands);
646 operands[0] = gen_rtx_REG (VOIDmode, REGNO (operands[0]) + 1);
647 operands[1] = gen_rtx_REG (VOIDmode, REGNO (operands[1]) + 1);
648 return "ixfr %1,%0";
650 if (operands[1] == CONST0_RTX (DFmode))
651 return "fmov.dd f0,%0";
652 if (CONSTANT_ADDRESS_P (XEXP (operands[1], 0)))
654 if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
655 && (cc_prev_status.flags & CC_HI_R31_ADJ)
656 && cc_prev_status.mdep == XEXP (operands[1], 0)))
658 CC_STATUS_INIT;
659 output_asm_insn ("orh %h1,%?r0,%?r31", operands);
661 cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
662 cc_status.mdep = XEXP (operands[1], 0);
663 return "fld.d %L1(%?r31),%0";
665 return "fld.d %1,%0";
667 else if (FP_REG_P (operands[1]))
669 if (GET_CODE (operands[0]) == REG)
671 output_asm_insn ("fxfr %1,%0", operands);
672 operands[0] = gen_rtx_REG (VOIDmode, REGNO (operands[0]) + 1);
673 operands[1] = gen_rtx_REG (VOIDmode, REGNO (operands[1]) + 1);
674 return "fxfr %1,%0";
676 if (CONSTANT_ADDRESS_P (XEXP (operands[0], 0)))
678 if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
679 && (cc_prev_status.flags & CC_HI_R31_ADJ)
680 && cc_prev_status.mdep == XEXP (operands[0], 0)))
682 CC_STATUS_INIT;
683 output_asm_insn ("orh %h0,%?r0,%?r31", operands);
685 cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
686 cc_status.mdep = XEXP (operands[0], 0);
687 return "fst.d %1,%L0(%?r31)";
689 return "fst.d %1,%0";
691 else
692 abort ();
693 /* NOTREACHED */
694 return NULL;
697 /* Return a REG that occurs in ADDR with coefficient 1.
698 ADDR can be effectively incremented by incrementing REG. */
700 static rtx
701 find_addr_reg (rtx addr)
703 while (GET_CODE (addr) == PLUS)
705 if (GET_CODE (XEXP (addr, 0)) == REG)
706 addr = XEXP (addr, 0);
707 else if (GET_CODE (XEXP (addr, 1)) == REG)
708 addr = XEXP (addr, 1);
709 else if (CONSTANT_P (XEXP (addr, 0)))
710 addr = XEXP (addr, 1);
711 else if (CONSTANT_P (XEXP (addr, 1)))
712 addr = XEXP (addr, 0);
713 else
714 abort ();
716 if (GET_CODE (addr) == REG)
717 return addr;
718 abort ();
719 /* NOTREACHED */
720 return NULL;
723 /* Return a template for a load instruction with mode MODE and
724 arguments from the string ARGS.
726 This string is in static storage. */
728 static const char *
729 load_opcode (enum machine_mode mode, const char *args, rtx reg)
731 static char buf[30];
732 const char *opcode;
734 switch (mode)
736 case QImode:
737 opcode = "ld.b";
738 break;
740 case HImode:
741 opcode = "ld.s";
742 break;
744 case SImode:
745 case SFmode:
746 if (FP_REG_P (reg))
747 opcode = "fld.l";
748 else
749 opcode = "ld.l";
750 break;
752 case DImode:
753 if (!FP_REG_P (reg))
754 abort ();
755 case DFmode:
756 opcode = "fld.d";
757 break;
759 default:
760 abort ();
763 sprintf (buf, "%s %s", opcode, args);
764 return buf;
767 /* Return a template for a store instruction with mode MODE and
768 arguments from the string ARGS.
770 This string is in static storage. */
772 static const char *
773 store_opcode (enum machine_mode mode, const char *args, rtx reg)
775 static char buf[30];
776 const char *opcode;
778 switch (mode)
780 case QImode:
781 opcode = "st.b";
782 break;
784 case HImode:
785 opcode = "st.s";
786 break;
788 case SImode:
789 case SFmode:
790 if (FP_REG_P (reg))
791 opcode = "fst.l";
792 else
793 opcode = "st.l";
794 break;
796 case DImode:
797 if (!FP_REG_P (reg))
798 abort ();
799 case DFmode:
800 opcode = "fst.d";
801 break;
803 default:
804 abort ();
807 sprintf (buf, "%s %s", opcode, args);
808 return buf;
811 /* Output a store-in-memory whose operands are OPERANDS[0,1].
812 OPERANDS[0] is a MEM, and OPERANDS[1] is a reg or zero.
814 This function returns a template for an insn.
815 This is in static storage.
817 It may also output some insns directly.
818 It may alter the values of operands[0] and operands[1]. */
820 const char *
821 output_store (rtx *operands)
823 enum machine_mode mode = GET_MODE (operands[0]);
824 rtx address = XEXP (operands[0], 0);
826 cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
827 cc_status.mdep = address;
829 if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
830 && (cc_prev_status.flags & CC_HI_R31_ADJ)
831 && address == cc_prev_status.mdep))
833 CC_STATUS_INIT;
834 output_asm_insn ("orh %h0,%?r0,%?r31", operands);
835 cc_prev_status.mdep = address;
838 /* Store zero in two parts when appropriate. */
839 if (mode == DFmode && operands[1] == CONST0_RTX (DFmode))
840 return store_opcode (DFmode, "%r1,%L0(%?r31)", operands[1]);
842 /* Code below isn't smart enough to move a doubleword in two parts,
843 so use output_move_double to do that in the cases that require it. */
844 if ((mode == DImode || mode == DFmode)
845 && ! FP_REG_P (operands[1]))
846 return output_move_double (operands);
848 return store_opcode (mode, "%r1,%L0(%?r31)", operands[1]);
851 /* Output a load-from-memory whose operands are OPERANDS[0,1].
852 OPERANDS[0] is a reg, and OPERANDS[1] is a mem.
854 This function returns a template for an insn.
855 This is in static storage.
857 It may also output some insns directly.
858 It may alter the values of operands[0] and operands[1]. */
860 const char *
861 output_load (rtx *operands)
863 enum machine_mode mode = GET_MODE (operands[0]);
864 rtx address = XEXP (operands[1], 0);
866 /* We don't bother trying to see if we know %hi(address).
867 This is because we are doing a load, and if we know the
868 %hi value, we probably also know that value in memory. */
869 cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
870 cc_status.mdep = address;
872 if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
873 && (cc_prev_status.flags & CC_HI_R31_ADJ)
874 && address == cc_prev_status.mdep
875 && cc_prev_status.mdep == cc_status.mdep))
877 CC_STATUS_INIT;
878 output_asm_insn ("orh %h1,%?r0,%?r31", operands);
879 cc_prev_status.mdep = address;
882 /* Code below isn't smart enough to move a doubleword in two parts,
883 so use output_move_double to do that in the cases that require it. */
884 if ((mode == DImode || mode == DFmode)
885 && ! FP_REG_P (operands[0]))
886 return output_move_double (operands);
888 return load_opcode (mode, "%L1(%?r31),%0", operands[0]);
891 #if 0
892 /* Load the address specified by OPERANDS[3] into the register
893 specified by OPERANDS[0].
895 OPERANDS[3] may be the result of a sum, hence it could either be:
897 (1) CONST
898 (2) REG
899 (2) REG + CONST_INT
900 (3) REG + REG + CONST_INT
901 (4) REG + REG (special case of 3).
903 Note that (3) is not a legitimate address.
904 All cases are handled here. */
906 void
907 output_load_address (rtx *operands)
909 rtx base, offset;
911 if (CONSTANT_P (operands[3]))
913 output_asm_insn ("mov %3,%0", operands);
914 return;
917 if (REG_P (operands[3]))
919 if (REGNO (operands[0]) != REGNO (operands[3]))
920 output_asm_insn ("shl %?r0,%3,%0", operands);
921 return;
924 if (GET_CODE (operands[3]) != PLUS)
925 abort ();
927 base = XEXP (operands[3], 0);
928 offset = XEXP (operands[3], 1);
930 if (GET_CODE (base) == CONST_INT)
932 rtx tmp = base;
933 base = offset;
934 offset = tmp;
937 if (GET_CODE (offset) != CONST_INT)
939 /* Operand is (PLUS (REG) (REG)). */
940 base = operands[3];
941 offset = const0_rtx;
944 if (REG_P (base))
946 operands[6] = base;
947 operands[7] = offset;
948 CC_STATUS_PARTIAL_INIT;
949 if (SMALL_INT (offset))
950 output_asm_insn ("adds %7,%6,%0", operands);
951 else
952 output_asm_insn ("mov %7,%0\n\tadds %0,%6,%0", operands);
954 else if (GET_CODE (base) == PLUS)
956 operands[6] = XEXP (base, 0);
957 operands[7] = XEXP (base, 1);
958 operands[8] = offset;
960 CC_STATUS_PARTIAL_INIT;
961 if (SMALL_INT (offset))
962 output_asm_insn ("adds %6,%7,%0\n\tadds %8,%0,%0", operands);
963 else
964 output_asm_insn ("mov %8,%0\n\tadds %0,%6,%0\n\tadds %0,%7,%0", operands);
966 else
967 abort ();
969 #endif
971 /* Output code to place a size count SIZE in register REG.
972 Because block moves are pipelined, we don't include the
973 first element in the transfer of SIZE to REG.
974 For this, we subtract ALIGN. (Actually, I think it is not
975 right to subtract on this machine, so right now we don't.) */
977 static void
978 output_size_for_block_move (rtx size, rtx reg, rtx align)
980 rtx xoperands[3];
982 xoperands[0] = reg;
983 xoperands[1] = size;
984 xoperands[2] = align;
986 #if 1
987 cc_status.flags &= ~ CC_KNOW_HI_R31;
988 output_asm_insn (singlemove_string (xoperands), xoperands);
989 #else
990 if (GET_CODE (size) == REG)
991 output_asm_insn ("sub %2,%1,%0", xoperands);
992 else
994 xoperands[1] = GEN_INT (INTVAL (size) - INTVAL (align));
995 cc_status.flags &= ~ CC_KNOW_HI_R31;
996 output_asm_insn ("mov %1,%0", xoperands);
998 #endif
1001 /* Emit code to perform a block move.
1003 OPERANDS[0] is the destination.
1004 OPERANDS[1] is the source.
1005 OPERANDS[2] is the size.
1006 OPERANDS[3] is the known safe alignment.
1007 OPERANDS[4..6] are pseudos we can safely clobber as temps. */
1009 const char *
1010 output_block_move (rtx *operands)
1012 /* A vector for our computed operands. Note that load_output_address
1013 makes use of (and can clobber) up to the 8th element of this vector. */
1014 rtx xoperands[10];
1015 #if 0
1016 rtx zoperands[10];
1017 #endif
1018 static int movmemsi_label = 0;
1019 int i;
1020 rtx temp1 = operands[4];
1021 rtx alignrtx = operands[3];
1022 int align = INTVAL (alignrtx);
1023 int chunk_size;
1025 xoperands[0] = operands[0];
1026 xoperands[1] = operands[1];
1027 xoperands[2] = temp1;
1029 /* We can't move more than four bytes at a time
1030 because we have only one register to move them through. */
1031 if (align > 4)
1033 align = 4;
1034 alignrtx = GEN_INT (4);
1037 /* Recognize special cases of block moves. These occur
1038 when GNU C++ is forced to treat something as BLKmode
1039 to keep it in memory, when its mode could be represented
1040 with something smaller.
1042 We cannot do this for global variables, since we don't know
1043 what pages they don't cross. Sigh. */
1044 if (GET_CODE (operands[2]) == CONST_INT
1045 && ! CONSTANT_ADDRESS_P (operands[0])
1046 && ! CONSTANT_ADDRESS_P (operands[1]))
1048 int size = INTVAL (operands[2]);
1049 rtx op0 = xoperands[0];
1050 rtx op1 = xoperands[1];
1052 if ((align & 3) == 0 && (size & 3) == 0 && (size >> 2) <= 16)
1054 if (memory_address_p (SImode, plus_constant (op0, size))
1055 && memory_address_p (SImode, plus_constant (op1, size)))
1057 cc_status.flags &= ~CC_KNOW_HI_R31;
1058 for (i = (size>>2)-1; i >= 0; i--)
1060 xoperands[0] = plus_constant (op0, i * 4);
1061 xoperands[1] = plus_constant (op1, i * 4);
1062 output_asm_insn ("ld.l %a1,%?r31\n\tst.l %?r31,%a0",
1063 xoperands);
1065 return "";
1068 else if ((align & 1) == 0 && (size & 1) == 0 && (size >> 1) <= 16)
1070 if (memory_address_p (HImode, plus_constant (op0, size))
1071 && memory_address_p (HImode, plus_constant (op1, size)))
1073 cc_status.flags &= ~CC_KNOW_HI_R31;
1074 for (i = (size>>1)-1; i >= 0; i--)
1076 xoperands[0] = plus_constant (op0, i * 2);
1077 xoperands[1] = plus_constant (op1, i * 2);
1078 output_asm_insn ("ld.s %a1,%?r31\n\tst.s %?r31,%a0",
1079 xoperands);
1081 return "";
1084 else if (size <= 16)
1086 if (memory_address_p (QImode, plus_constant (op0, size))
1087 && memory_address_p (QImode, plus_constant (op1, size)))
1089 cc_status.flags &= ~CC_KNOW_HI_R31;
1090 for (i = size-1; i >= 0; i--)
1092 xoperands[0] = plus_constant (op0, i);
1093 xoperands[1] = plus_constant (op1, i);
1094 output_asm_insn ("ld.b %a1,%?r31\n\tst.b %?r31,%a0",
1095 xoperands);
1097 return "";
1102 /* Since we clobber untold things, nix the condition codes. */
1103 CC_STATUS_INIT;
1105 /* This is the size of the transfer.
1106 Either use the register which already contains the size,
1107 or use a free register (used by no operands). */
1108 output_size_for_block_move (operands[2], operands[4], alignrtx);
1110 #if 0
1111 /* Also emit code to decrement the size value by ALIGN. */
1112 zoperands[0] = operands[0];
1113 zoperands[3] = plus_constant (operands[0], align);
1114 output_load_address (zoperands);
1115 #endif
1117 /* Generate number for unique label. */
1119 xoperands[3] = GEN_INT (movmemsi_label++);
1121 /* Calculate the size of the chunks we will be trying to move first. */
1123 #if 0
1124 if ((align & 3) == 0)
1125 chunk_size = 4;
1126 else if ((align & 1) == 0)
1127 chunk_size = 2;
1128 else
1129 #endif
1130 chunk_size = 1;
1132 /* Copy the increment (negative) to a register for bla insn. */
1134 xoperands[4] = GEN_INT (- chunk_size);
1135 xoperands[5] = operands[5];
1136 output_asm_insn ("adds %4,%?r0,%5", xoperands);
1138 /* Predecrement the loop counter. This happens again also in the `bla'
1139 instruction which precedes the loop, but we need to have it done
1140 two times before we enter the loop because of the bizarre semantics
1141 of the bla instruction. */
1143 output_asm_insn ("adds %5,%2,%2", xoperands);
1145 /* Check for the case where the original count was less than or equal to
1146 zero. Avoid going through the loop at all if the original count was
1147 indeed less than or equal to zero. Note that we treat the count as
1148 if it were a signed 32-bit quantity here, rather than an unsigned one,
1149 even though we really shouldn't. We have to do this because of the
1150 semantics of the `ble' instruction, which assume that the count is
1151 a signed 32-bit value. Anyway, in practice it won't matter because
1152 nobody is going to try to do a memcpy() of more than half of the
1153 entire address space (i.e. 2 gigabytes) anyway. */
1155 output_asm_insn ("bc .Le%3", xoperands);
1157 /* Make available a register which is a temporary. */
1159 xoperands[6] = operands[6];
1161 /* Now the actual loop.
1162 In xoperands, elements 1 and 0 are the input and output vectors.
1163 Element 2 is the loop index. Element 5 is the increment. */
1165 output_asm_insn ("subs %1,%5,%1", xoperands);
1166 output_asm_insn ("bla %5,%2,.Lm%3", xoperands);
1167 output_asm_insn ("adds %0,%2,%6", xoperands);
1168 output_asm_insn ("\n.Lm%3:", xoperands); /* Label for bla above. */
1169 output_asm_insn ("\n.Ls%3:", xoperands); /* Loop start label. */
1170 output_asm_insn ("adds %5,%6,%6", xoperands);
1172 /* NOTE: The code here which is supposed to handle the cases where the
1173 sources and destinations are known to start on a 4 or 2 byte boundary
1174 are currently broken. They fail to do anything about the overflow
1175 bytes which might still need to be copied even after we have copied
1176 some number of words or halfwords. Thus, for now we use the lowest
1177 common denominator, i.e. the code which just copies some number of
1178 totally unaligned individual bytes. (See the calculation of
1179 chunk_size above. */
1181 if (chunk_size == 4)
1183 output_asm_insn ("ld.l %2(%1),%?r31", xoperands);
1184 output_asm_insn ("bla %5,%2,.Ls%3", xoperands);
1185 output_asm_insn ("st.l %?r31,8(%6)", xoperands);
1187 else if (chunk_size == 2)
1189 output_asm_insn ("ld.s %2(%1),%?r31", xoperands);
1190 output_asm_insn ("bla %5,%2,.Ls%3", xoperands);
1191 output_asm_insn ("st.s %?r31,4(%6)", xoperands);
1193 else /* chunk_size == 1 */
1195 output_asm_insn ("ld.b %2(%1),%?r31", xoperands);
1196 output_asm_insn ("bla %5,%2,.Ls%3", xoperands);
1197 output_asm_insn ("st.b %?r31,2(%6)", xoperands);
1199 output_asm_insn ("\n.Le%3:", xoperands); /* Here if count <= 0. */
1201 return "";
1204 /* Special routine to convert an SFmode value represented as a
1205 CONST_DOUBLE into its equivalent unsigned long bit pattern.
1206 We convert the value from a double precision floating-point
1207 value to single precision first, and thence to a bit-wise
1208 equivalent unsigned long value. This routine is used when
1209 generating an immediate move of an SFmode value directly
1210 into a general register because the SVR4 assembler doesn't
1211 grok floating literals in instruction operand contexts. */
1213 unsigned long
1214 sfmode_constant_to_ulong (rtx x)
1216 REAL_VALUE_TYPE d;
1217 unsigned long l;
1219 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != SFmode)
1220 abort ();
1222 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1223 REAL_VALUE_TO_TARGET_SINGLE (d, l);
1224 return l;
1227 /* This function generates the assembly code for function entry.
1229 ASM_FILE is a stdio stream to output the code to.
1230 SIZE is an int: how many units of temporary storage to allocate.
1232 Refer to the array `regs_ever_live' to determine which registers
1233 to save; `regs_ever_live[I]' is nonzero if register number I
1234 is ever used in the function. This macro is responsible for
1235 knowing which registers should not be saved even if used.
1237 NOTE: `frame_lower_bytes' is the count of bytes which will lie
1238 between the new `fp' value and the new `sp' value after the
1239 prologue is done. `frame_upper_bytes' is the count of bytes
1240 that will lie between the new `fp' and the *old* `sp' value
1241 after the new `fp' is setup (in the prologue). The upper
1242 part of each frame always includes at least 2 words (8 bytes)
1243 to hold the saved frame pointer and the saved return address.
1245 The SVR4 ABI for the i860 now requires that the values of the
1246 stack pointer and frame pointer registers be kept aligned to
1247 16-byte boundaries at all times. We obey that restriction here.
1249 The SVR4 ABI for the i860 is entirely vague when it comes to specifying
1250 exactly where the "preserved" registers should be saved. The native
1251 SVR4 C compiler I now have doesn't help to clarify the requirements
1252 very much because it is plainly out-of-date and non-ABI-compliant
1253 (in at least one important way, i.e. how it generates function
1254 epilogues).
1256 The native SVR4 C compiler saves the "preserved" registers (i.e.
1257 r4-r15 and f2-f7) in the lower part of a frame (i.e. at negative
1258 offsets from the frame pointer).
1260 Previous versions of GCC also saved the "preserved" registers in the
1261 "negative" part of the frame, but they saved them using positive
1262 offsets from the (adjusted) stack pointer (after it had been adjusted
1263 to allocate space for the new frame). That's just plain wrong
1264 because if the current function calls alloca(), the stack pointer
1265 will get moved, and it will be impossible to restore the registers
1266 properly again after that.
1268 Both compilers handled parameter registers (i.e. r16-r27 and f8-f15)
1269 by copying their values either into various "preserved" registers or
1270 into stack slots in the lower part of the current frame (as seemed
1271 appropriate, depending upon subsequent usage of these values).
1273 Here we want to save the preserved registers at some offset from the
1274 frame pointer register so as to avoid any possible problems arising
1275 from calls to alloca(). We can either save them at small positive
1276 offsets from the frame pointer, or at small negative offsets from
1277 the frame pointer. If we save them at small negative offsets from
1278 the frame pointer (i.e. in the lower part of the frame) then we
1279 must tell the rest of GCC (via STARTING_FRAME_OFFSET) exactly how
1280 many bytes of space we plan to use in the lower part of the frame
1281 for this purpose. Since other parts of the compiler reference the
1282 value of STARTING_FRAME_OFFSET long before final() calls this function,
1283 we would have to go ahead and assume the worst-case storage requirements
1284 for saving all of the "preserved" registers (and use that number, i.e.
1285 `80', to define STARTING_FRAME_OFFSET) if we wanted to save them in
1286 the lower part of the frame. That could potentially be very wasteful,
1287 and that wastefulness could really hamper people compiling for embedded
1288 i860 targets with very tight limits on stack space. Thus, we choose
1289 here to save the preserved registers in the upper part of the
1290 frame, so that we can decide at the very last minute how much (or how
1291 little) space we must allocate for this purpose.
1293 To satisfy the needs of the SVR4 ABI "tdesc" scheme, preserved
1294 registers must always be saved so that the saved values of registers
1295 with higher numbers are at higher addresses. We obey that restriction
1296 here.
1298 There are two somewhat different ways that you can generate prologues
1299 here... i.e. pedantically ABI-compliant, and the "other" way. The
1300 "other" way is more consistent with what is currently generated by the
1301 "native" SVR4 C compiler for the i860. That's important if you want
1302 to use the current (as of 8/91) incarnation of SVR4 SDB for the i860.
1303 The SVR4 SDB for the i860 insists on having function prologues be
1304 non-ABI-compliant!
1306 To get fully ABI-compliant prologues, define I860_STRICT_ABI_PROLOGUES
1307 in the i860/sysv4.h file. (By default this is *not* defined).
1309 The differences between the ABI-compliant and non-ABI-compliant prologues
1310 are that (a) the ABI version seems to require the use of *signed*
1311 (rather than unsigned) adds and subtracts, and (b) the ordering of
1312 the various steps (e.g. saving preserved registers, saving the
1313 return address, setting up the new frame pointer value) is different.
1315 For strict ABI compliance, it seems to be the case that the very last
1316 thing that is supposed to happen in the prologue is getting the frame
1317 pointer set to its new value (but only after everything else has
1318 already been properly setup). We do that here, but only if the symbol
1319 I860_STRICT_ABI_PROLOGUES is defined. */
1321 #ifndef STACK_ALIGNMENT
1322 #define STACK_ALIGNMENT 16
1323 #endif
1325 const char *current_function_original_name;
1327 static int must_preserve_r1;
1328 static unsigned must_preserve_bytes;
1330 static void
1331 i860_output_function_prologue (FILE *asm_file, HOST_WIDE_INT local_bytes)
1333 register HOST_WIDE_INT frame_lower_bytes;
1334 register HOST_WIDE_INT frame_upper_bytes;
1335 register HOST_WIDE_INT total_fsize;
1336 register unsigned preserved_reg_bytes = 0;
1337 register unsigned i;
1338 register unsigned preserved_so_far = 0;
1340 must_preserve_r1 = (optimize < 2 || ! leaf_function_p ());
1341 must_preserve_bytes = 4 + (must_preserve_r1 ? 4 : 0);
1343 /* Count registers that need preserving. Ignore r0. It never needs
1344 preserving. */
1346 for (i = 1; i < FIRST_PSEUDO_REGISTER; i++)
1348 if (regs_ever_live[i] && ! call_used_regs[i])
1349 preserved_reg_bytes += 4;
1352 /* Round-up the frame_lower_bytes so that it's a multiple of 16. */
1354 frame_lower_bytes = (local_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1356 /* The upper part of each frame will contain the saved fp,
1357 the saved r1, and stack slots for all of the other "preserved"
1358 registers that we find we will need to save & restore. */
1360 frame_upper_bytes = must_preserve_bytes + preserved_reg_bytes;
1362 /* Round-up the frame_upper_bytes so that it's a multiple of 16. */
1364 frame_upper_bytes
1365 = (frame_upper_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1367 total_fsize = frame_upper_bytes + frame_lower_bytes;
1369 #ifndef I860_STRICT_ABI_PROLOGUES
1371 /* There are two kinds of function prologues.
1372 You use the "small" version if the total frame size is
1373 small enough so that it can fit into an immediate 16-bit
1374 value in one instruction. Otherwise, you use the "large"
1375 version of the function prologue. */
1377 if (total_fsize > 0x7fff)
1379 /* Adjust the stack pointer. The ABI specifies using `adds' for
1380 this, but the native C compiler on SVR4 uses `addu'. */
1382 fprintf (asm_file, "\taddu -" HOST_WIDE_INT_PRINT_DEC ",%ssp,%ssp\n",
1383 frame_upper_bytes, i860_reg_prefix, i860_reg_prefix);
1385 /* Save the old frame pointer. */
1387 fprintf (asm_file, "\tst.l %sfp,0(%ssp)\n",
1388 i860_reg_prefix, i860_reg_prefix);
1390 /* Setup the new frame pointer. The ABI specifies that this is to
1391 be done after preserving registers (using `adds'), but that's not
1392 what the native C compiler on SVR4 does. */
1394 fprintf (asm_file, "\taddu 0,%ssp,%sfp\n",
1395 i860_reg_prefix, i860_reg_prefix);
1397 /* Get the value of frame_lower_bytes into r31. */
1399 fprintf (asm_file, "\torh " HOST_WIDE_INT_PRINT_DEC ",%sr0,%sr31\n",
1400 frame_lower_bytes >> 16, i860_reg_prefix, i860_reg_prefix);
1401 fprintf (asm_file, "\tor " HOST_WIDE_INT_PRINT_DEC ",%sr31,%sr31\n",
1402 frame_lower_bytes & 0xffff, i860_reg_prefix, i860_reg_prefix);
1404 /* Now re-adjust the stack pointer using the value in r31.
1405 The ABI specifies that this is done with `subs' but SDB may
1406 prefer `subu'. */
1408 fprintf (asm_file, "\tsubu %ssp,%sr31,%ssp\n",
1409 i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1411 /* Preserve registers. The ABI specifies that this is to be done
1412 before setting up the new frame pointer, but that's not what the
1413 native C compiler on SVR4 does. */
1415 for (i = 1; i < 32; i++)
1416 if (regs_ever_live[i] && ! call_used_regs[i])
1417 fprintf (asm_file, "\tst.l %s%s,%d(%sfp)\n",
1418 i860_reg_prefix, reg_names[i],
1419 must_preserve_bytes + (4 * preserved_so_far++),
1420 i860_reg_prefix);
1422 for (i = 32; i < 64; i++)
1423 if (regs_ever_live[i] && ! call_used_regs[i])
1424 fprintf (asm_file, "\tfst.l %s%s,%d(%sfp)\n",
1425 i860_reg_prefix, reg_names[i],
1426 must_preserve_bytes + (4 * preserved_so_far++),
1427 i860_reg_prefix);
1429 /* Save the return address. */
1431 if (must_preserve_r1)
1432 fprintf (asm_file, "\tst.l %sr1,4(%sfp)\n",
1433 i860_reg_prefix, i860_reg_prefix);
1435 else
1437 /* Adjust the stack pointer. The ABI specifies using `adds' for this,
1438 but the native C compiler on SVR4 uses `addu'. */
1440 fprintf (asm_file, "\taddu -" HOST_WIDE_INT_PRINT_DEC ",%ssp,%ssp\n",
1441 total_fsize, i860_reg_prefix, i860_reg_prefix);
1443 /* Save the old frame pointer. */
1445 fprintf (asm_file, "\tst.l %sfp," HOST_WIDE_INT_PRINT_DEC "(%ssp)\n",
1446 i860_reg_prefix, frame_lower_bytes, i860_reg_prefix);
1448 /* Setup the new frame pointer. The ABI specifies that this is to be
1449 done after preserving registers and after saving the return address,
1450 (and to do it using `adds'), but that's not what the native C
1451 compiler on SVR4 does. */
1453 fprintf (asm_file, "\taddu " HOST_WIDE_INT_PRINT_DEC ",%ssp,%sfp\n",
1454 frame_lower_bytes, i860_reg_prefix, i860_reg_prefix);
1456 /* Preserve registers. The ABI specifies that this is to be done
1457 before setting up the new frame pointer, but that's not what the
1458 native compiler on SVR4 does. */
1460 for (i = 1; i < 32; i++)
1461 if (regs_ever_live[i] && ! call_used_regs[i])
1462 fprintf (asm_file, "\tst.l %s%s,%d(%sfp)\n",
1463 i860_reg_prefix, reg_names[i],
1464 must_preserve_bytes + (4 * preserved_so_far++),
1465 i860_reg_prefix);
1467 for (i = 32; i < 64; i++)
1468 if (regs_ever_live[i] && ! call_used_regs[i])
1469 fprintf (asm_file, "\tfst.l %s%s,%d(%sfp)\n",
1470 i860_reg_prefix, reg_names[i],
1471 must_preserve_bytes + (4 * preserved_so_far++),
1472 i860_reg_prefix);
1474 /* Save the return address. The ABI specifies that this is to be
1475 done earlier, and also via an offset from %sp, but the native C
1476 compiler on SVR4 does it later (i.e. now) and uses an offset from
1477 %fp. */
1479 if (must_preserve_r1)
1480 fprintf (asm_file, "\tst.l %sr1,4(%sfp)\n",
1481 i860_reg_prefix, i860_reg_prefix);
1484 #else /* defined(I860_STRICT_ABI_PROLOGUES) */
1486 /* There are two kinds of function prologues.
1487 You use the "small" version if the total frame size is
1488 small enough so that it can fit into an immediate 16-bit
1489 value in one instruction. Otherwise, you use the "large"
1490 version of the function prologue. */
1492 if (total_fsize > 0x7fff)
1494 /* Adjust the stack pointer (thereby allocating a new frame). */
1496 fprintf (asm_file, "\tadds -%d,%ssp,%ssp\n",
1497 frame_upper_bytes, i860_reg_prefix, i860_reg_prefix);
1499 /* Save the caller's frame pointer. */
1501 fprintf (asm_file, "\tst.l %sfp,0(%ssp)\n",
1502 i860_reg_prefix, i860_reg_prefix);
1504 /* Save return address. */
1506 if (must_preserve_r1)
1507 fprintf (asm_file, "\tst.l %sr1,4(%ssp)\n",
1508 i860_reg_prefix, i860_reg_prefix);
1510 /* Get the value of frame_lower_bytes into r31 for later use. */
1512 fprintf (asm_file, "\torh %d,%sr0,%sr31\n",
1513 frame_lower_bytes >> 16, i860_reg_prefix, i860_reg_prefix);
1514 fprintf (asm_file, "\tor %d,%sr31,%sr31\n",
1515 frame_lower_bytes & 0xffff, i860_reg_prefix, i860_reg_prefix);
1517 /* Now re-adjust the stack pointer using the value in r31. */
1519 fprintf (asm_file, "\tsubs %ssp,%sr31,%ssp\n",
1520 i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1522 /* Pre-compute value to be used as the new frame pointer. */
1524 fprintf (asm_file, "\tadds %ssp,%sr31,%sr31\n",
1525 i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1527 /* Preserve registers. */
1529 for (i = 1; i < 32; i++)
1530 if (regs_ever_live[i] && ! call_used_regs[i])
1531 fprintf (asm_file, "\tst.l %s%s,%d(%sr31)\n",
1532 i860_reg_prefix, reg_names[i],
1533 must_preserve_bytes + (4 * preserved_so_far++),
1534 i860_reg_prefix);
1536 for (i = 32; i < 64; i++)
1537 if (regs_ever_live[i] && ! call_used_regs[i])
1538 fprintf (asm_file, "\tfst.l %s%s,%d(%sr31)\n",
1539 i860_reg_prefix, reg_names[i],
1540 must_preserve_bytes + (4 * preserved_so_far++),
1541 i860_reg_prefix);
1543 /* Actually set the new value of the frame pointer. */
1545 fprintf (asm_file, "\tmov %sr31,%sfp\n",
1546 i860_reg_prefix, i860_reg_prefix);
1548 else
1550 /* Adjust the stack pointer. */
1552 fprintf (asm_file, "\tadds -%d,%ssp,%ssp\n",
1553 total_fsize, i860_reg_prefix, i860_reg_prefix);
1555 /* Save the caller's frame pointer. */
1557 fprintf (asm_file, "\tst.l %sfp,%d(%ssp)\n",
1558 i860_reg_prefix, frame_lower_bytes, i860_reg_prefix);
1560 /* Save the return address. */
1562 if (must_preserve_r1)
1563 fprintf (asm_file, "\tst.l %sr1,%d(%ssp)\n",
1564 i860_reg_prefix, frame_lower_bytes + 4, i860_reg_prefix);
1566 /* Preserve registers. */
1568 for (i = 1; i < 32; i++)
1569 if (regs_ever_live[i] && ! call_used_regs[i])
1570 fprintf (asm_file, "\tst.l %s%s,%d(%ssp)\n",
1571 i860_reg_prefix, reg_names[i],
1572 frame_lower_bytes + must_preserve_bytes + (4 * preserved_so_far++),
1573 i860_reg_prefix);
1575 for (i = 32; i < 64; i++)
1576 if (regs_ever_live[i] && ! call_used_regs[i])
1577 fprintf (asm_file, "\tfst.l %s%s,%d(%ssp)\n",
1578 i860_reg_prefix, reg_names[i],
1579 frame_lower_bytes + must_preserve_bytes + (4 * preserved_so_far++),
1580 i860_reg_prefix);
1582 /* Setup the new frame pointer. */
1584 fprintf (asm_file, "\tadds %d,%ssp,%sfp\n",
1585 frame_lower_bytes, i860_reg_prefix, i860_reg_prefix);
1587 #endif /* defined(I860_STRICT_ABI_PROLOGUES) */
1589 #ifdef ASM_OUTPUT_PROLOGUE_SUFFIX
1590 ASM_OUTPUT_PROLOGUE_SUFFIX (asm_file);
1591 #endif /* defined(ASM_OUTPUT_PROLOGUE_SUFFIX) */
1594 /* This function generates the assembly code for function exit.
1596 ASM_FILE is a stdio stream to output the code to.
1597 SIZE is an int: how many units of temporary storage to allocate.
1599 The function epilogue should not depend on the current stack pointer!
1600 It should use the frame pointer only. This is mandatory because
1601 of alloca; we also take advantage of it to omit stack adjustments
1602 before returning.
1604 Note that when we go to restore the preserved register values we must
1605 not try to address their slots by using offsets from the stack pointer.
1606 That's because the stack pointer may have been moved during the function
1607 execution due to a call to alloca(). Rather, we must restore all
1608 preserved registers via offsets from the frame pointer value.
1610 Note also that when the current frame is being "popped" (by adjusting
1611 the value of the stack pointer) on function exit, we must (for the
1612 sake of alloca) set the new value of the stack pointer based upon
1613 the current value of the frame pointer. We can't just add what we
1614 believe to be the (static) frame size to the stack pointer because
1615 if we did that, and alloca() had been called during this function,
1616 we would end up returning *without* having fully deallocated all of
1617 the space grabbed by alloca. If that happened, and a function
1618 containing one or more alloca() calls was called over and over again,
1619 then the stack would grow without limit!
1621 Finally note that the epilogues generated here are completely ABI
1622 compliant. They go out of their way to insure that the value in
1623 the frame pointer register is never less than the value in the stack
1624 pointer register. It's not clear why this relationship needs to be
1625 maintained at all times, but maintaining it only costs one extra
1626 instruction, so what the hell. */
1628 /* This corresponds to a version 4 TDESC structure. Lower numbered
1629 versions successively omit the last word of the structure. We
1630 don't try to handle version 5 here. */
1632 typedef struct TDESC_flags {
1633 int version:4;
1634 int reg_packing:1;
1635 int callable_block:1;
1636 int reserved:4;
1637 int fregs:6; /* fp regs 2-7 */
1638 int iregs:16; /* regs 0-15 */
1639 } TDESC_flags;
1641 typedef struct TDESC {
1642 TDESC_flags flags;
1643 int integer_reg_offset; /* same as must_preserve_bytes */
1644 int floating_point_reg_offset;
1645 unsigned int positive_frame_size; /* same as frame_upper_bytes */
1646 unsigned int negative_frame_size; /* same as frame_lower_bytes */
1647 } TDESC;
1649 static void
1650 i860_output_function_epilogue (FILE *asm_file, HOST_WIDE_INT local_bytes)
1652 register HOST_WIDE_INT frame_upper_bytes;
1653 register HOST_WIDE_INT frame_lower_bytes;
1654 register HOST_WIDE_INT preserved_reg_bytes = 0;
1655 register unsigned i;
1656 register unsigned restored_so_far = 0;
1657 register unsigned int_restored;
1658 register unsigned mask;
1659 unsigned intflags=0;
1660 register TDESC_flags *flags = (TDESC_flags *) &intflags;
1661 #ifdef OUTPUT_TDESC /* Output an ABI-compliant TDESC entry */
1662 const char *long_op = integer_asm_op (4, TRUE);
1663 #endif
1665 flags->version = 4;
1666 flags->reg_packing = 1;
1667 flags->iregs = 8; /* old fp always gets saved */
1669 /* Round-up the frame_lower_bytes so that it's a multiple of 16. */
1671 frame_lower_bytes = (local_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1673 /* Count the number of registers that were preserved in the prologue.
1674 Ignore r0. It is never preserved. */
1676 for (i = 1; i < FIRST_PSEUDO_REGISTER; i++)
1678 if (regs_ever_live[i] && ! call_used_regs[i])
1679 preserved_reg_bytes += 4;
1682 /* The upper part of each frame will contain only saved fp,
1683 the saved r1, and stack slots for all of the other "preserved"
1684 registers that we find we will need to save & restore. */
1686 frame_upper_bytes = must_preserve_bytes + preserved_reg_bytes;
1688 /* Round-up frame_upper_bytes so that t is a multiple of 16. */
1690 frame_upper_bytes
1691 = (frame_upper_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1693 /* Restore all of the "preserved" registers that need restoring. */
1695 mask = 2;
1697 for (i = 1; i < 32; i++, mask<<=1)
1698 if (regs_ever_live[i] && ! call_used_regs[i]) {
1699 fprintf (asm_file, "\tld.l %d(%sfp),%s%s\n",
1700 must_preserve_bytes + (4 * restored_so_far++),
1701 i860_reg_prefix, i860_reg_prefix, reg_names[i]);
1702 if (i > 3 && i < 16)
1703 flags->iregs |= mask;
1706 int_restored = restored_so_far;
1707 mask = 1;
1709 for (i = 32; i < 64; i++) {
1710 if (regs_ever_live[i] && ! call_used_regs[i]) {
1711 fprintf (asm_file, "\tfld.l %d(%sfp),%s%s\n",
1712 must_preserve_bytes + (4 * restored_so_far++),
1713 i860_reg_prefix, i860_reg_prefix, reg_names[i]);
1714 if (i > 33 && i < 40)
1715 flags->fregs |= mask;
1717 if (i > 33 && i < 40)
1718 mask<<=1;
1721 /* Get the value we plan to use to restore the stack pointer into r31. */
1723 fprintf (asm_file, "\tadds " HOST_WIDE_INT_PRINT_DEC ",%sfp,%sr31\n",
1724 frame_upper_bytes, i860_reg_prefix, i860_reg_prefix);
1726 /* Restore the return address and the old frame pointer. */
1728 if (must_preserve_r1) {
1729 fprintf (asm_file, "\tld.l 4(%sfp),%sr1\n",
1730 i860_reg_prefix, i860_reg_prefix);
1731 flags->iregs |= 2;
1734 fprintf (asm_file, "\tld.l 0(%sfp),%sfp\n",
1735 i860_reg_prefix, i860_reg_prefix);
1737 /* Return and restore the old stack pointer value. */
1739 fprintf (asm_file, "\tbri %sr1\n\tmov %sr31,%ssp\n",
1740 i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1742 #ifdef OUTPUT_TDESC /* Output an ABI-compliant TDESC entry. */
1743 if (! frame_lower_bytes) {
1744 flags->version--;
1745 if (! frame_upper_bytes) {
1746 flags->version--;
1747 if (restored_so_far == int_restored) /* No FP saves. */
1748 flags->version--;
1751 assemble_name(asm_file,current_function_original_name);
1752 fputs(".TDESC:\n", asm_file);
1753 fprintf(asm_file, "%s 0x%0x\n", long_op, intflags);
1754 fprintf(asm_file, "%s %d\n", long_op,
1755 int_restored ? must_preserve_bytes : 0);
1756 if (flags->version > 1) {
1757 fprintf(asm_file, "%s %d\n", long_op,
1758 (restored_so_far == int_restored) ? 0 : must_preserve_bytes +
1759 (4 * int_restored));
1760 if (flags->version > 2) {
1761 fprintf(asm_file, "%s %d\n", long_op, frame_upper_bytes);
1762 if (flags->version > 3)
1763 fprintf(asm_file, "%s %d\n", long_op, frame_lower_bytes);
1766 tdesc_section();
1767 fprintf(asm_file, "%s ", long_op);
1768 assemble_name(asm_file, current_function_original_name);
1769 fprintf(asm_file, "\n%s ", long_op);
1770 assemble_name(asm_file, current_function_original_name);
1771 fputs(".TDESC\n", asm_file);
1772 text_section();
1773 #endif
1777 /* Expand a library call to __builtin_saveregs. */
1779 static rtx
1780 i860_saveregs (void)
1782 rtx fn = gen_rtx_SYMBOL_REF (Pmode, "__builtin_saveregs");
1783 rtx save = gen_reg_rtx (Pmode);
1784 rtx valreg = LIBCALL_VALUE (Pmode);
1785 rtx ret;
1787 /* The return value register overlaps the first argument register.
1788 Save and restore it around the call. */
1789 emit_move_insn (save, valreg);
1790 ret = emit_library_call_value (fn, NULL_RTX, 1, Pmode, 0);
1791 if (GET_CODE (ret) != REG || REGNO (ret) < FIRST_PSEUDO_REGISTER)
1792 ret = copy_to_reg (ret);
1793 emit_move_insn (valreg, save);
1795 return ret;
1798 /* Create the va_list data type.
1799 The SVR4 ABI requires the following structure:
1800 typedef struct {
1801 unsigned long ireg_used;
1802 unsigned long freg_used;
1803 long *reg_base;
1804 long *mem_ptr;
1805 } va_list;
1807 Otherwise, this structure is used:
1808 typedef struct {
1809 long *reg_base;
1810 long *mem_ptr;
1811 unsigned long ireg_used;
1812 unsigned long freg_used;
1813 } va_list;
1815 The tree representing the va_list declaration is returned. */
1817 static tree
1818 i860_build_builtin_va_list (void)
1820 tree f_gpr, f_fpr, f_mem, f_sav, record, type_decl;
1822 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
1823 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
1825 f_gpr = build_decl (FIELD_DECL, get_identifier ("__ireg_used"),
1826 unsigned_type_node);
1827 f_fpr = build_decl (FIELD_DECL, get_identifier ("__freg_used"),
1828 unsigned_type_node);
1829 f_sav = build_decl (FIELD_DECL, get_identifier ("__reg_base"),
1830 ptr_type_node);
1831 f_mem = build_decl (FIELD_DECL, get_identifier ("__mem_ptr"),
1832 ptr_type_node);
1834 DECL_FIELD_CONTEXT (f_gpr) = record;
1835 DECL_FIELD_CONTEXT (f_fpr) = record;
1836 DECL_FIELD_CONTEXT (f_sav) = record;
1837 DECL_FIELD_CONTEXT (f_mem) = record;
1839 TREE_CHAIN (record) = type_decl;
1840 TYPE_NAME (record) = type_decl;
1842 #ifdef I860_SVR4_VA_LIST
1843 TYPE_FIELDS (record) = f_gpr;
1844 TREE_CHAIN (f_gpr) = f_fpr;
1845 TREE_CHAIN (f_fpr) = f_sav;
1846 TREE_CHAIN (f_sav) = f_mem;
1847 #else
1848 TYPE_FIELDS (record) = f_sav;
1849 TREE_CHAIN (f_sav) = f_mem;
1850 TREE_CHAIN (f_mem) = f_gpr;
1851 TREE_CHAIN (f_gpr) = f_fpr;
1852 #endif
1854 layout_type (record);
1855 return record;
1858 /* Initialize the va_list structure. */
1860 void
1861 i860_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
1863 tree saveregs, t;
1864 tree f_gpr, f_fpr, f_mem, f_sav;
1865 tree gpr, fpr, mem, sav;
1866 int off = 0;
1867 saveregs = make_tree (ptr_type_node, expand_builtin_saveregs ());
1869 #ifdef I860_SVR4_VA_LIST
1870 f_gpr = TYPE_FIELDS (va_list_type_node);
1871 f_fpr = TREE_CHAIN (f_gpr);
1872 f_sav = TREE_CHAIN (f_fpr);
1873 f_mem = TREE_CHAIN (f_sav);
1874 #else
1875 f_sav = TYPE_FIELDS (va_list_type_node);
1876 f_mem = TREE_CHAIN (f_sav);
1877 f_gpr = TREE_CHAIN (f_mem);
1878 f_fpr = TREE_CHAIN (f_gpr);
1879 #endif
1881 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
1882 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
1883 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
1884 mem = build (COMPONENT_REF, TREE_TYPE (f_mem), valist, f_mem, NULL_TREE);
1886 /* Initialize the `mem_ptr' field to the address of the first anonymous
1887 stack argument. */
1888 t = make_tree (TREE_TYPE (mem), virtual_incoming_args_rtx);
1889 off = INTVAL (current_function_arg_offset_rtx);
1890 off = off < 0 ? 0 : off;
1891 t = build (PLUS_EXPR, TREE_TYPE (mem), t, build_int_2 (off, 0));
1892 t = build (MODIFY_EXPR, TREE_TYPE (mem), mem, t);
1893 TREE_SIDE_EFFECTS (t) = 1;
1894 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1896 /* Initialize the `ireg_used' field. */
1897 t = build_int_2 (current_function_args_info.ints / UNITS_PER_WORD, 0);
1898 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, t);
1899 TREE_SIDE_EFFECTS (t) = 1;
1900 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1902 /* Initialize the `freg_used' field. */
1903 t = build_int_2 (current_function_args_info.floats / UNITS_PER_WORD, 0);
1904 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, t);
1905 TREE_SIDE_EFFECTS (t) = 1;
1906 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1908 /* Initialize the `reg_base' field. */
1909 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, saveregs);
1910 TREE_SIDE_EFFECTS (t) = 1;
1911 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1914 #define NUM_PARM_FREGS 8
1915 #define NUM_PARM_IREGS 12
1916 #ifdef I860_SVR4_VA_LIST
1917 #define FREG_OFFSET 0
1918 #define IREG_OFFSET (NUM_PARM_FREGS * UNITS_PER_WORD)
1919 #else
1920 #define FREG_OFFSET (NUM_PARM_IREGS * UNITS_PER_WORD)
1921 #define IREG_OFFSET 0
1922 #endif
1924 /* Update the VALIST structure as necessary for an
1925 argument of the given TYPE, and return the argument. */
1927 static tree
1928 i860_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
1930 tree f_gpr, f_fpr, f_mem, f_sav;
1931 tree gpr, fpr, mem, sav;
1932 tree size, t, u, addr, type_ptr;
1933 tree reg, n_reg, sav_ofs, lim_reg;
1934 HOST_WIDE_INT isize;
1936 #ifdef I860_SVR4_VA_LIST
1937 f_gpr = TYPE_FIELDS (va_list_type_node);
1938 f_fpr = TREE_CHAIN (f_gpr);
1939 f_sav = TREE_CHAIN (f_fpr);
1940 f_mem = TREE_CHAIN (f_sav);
1941 #else
1942 f_sav = TYPE_FIELDS (va_list_type_node);
1943 f_mem = TREE_CHAIN (f_sav);
1944 f_gpr = TREE_CHAIN (f_mem);
1945 f_fpr = TREE_CHAIN (f_gpr);
1946 #endif
1948 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
1949 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
1950 mem = build (COMPONENT_REF, TREE_TYPE (f_mem), valist, f_mem, NULL_TREE);
1951 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
1953 size = size_in_bytes (type);
1954 type_ptr = build_pointer_type (type);
1956 if (AGGREGATE_TYPE_P (type))
1958 /* Aggregates are passed on the stack. */
1959 HOST_WIDE_INT align;
1961 align = TYPE_ALIGN (type);
1962 if (align < BITS_PER_WORD)
1963 align = BITS_PER_WORD;
1964 align /= BITS_PER_UNIT;
1966 u = fold_convert (ptr_type_node, size_int (align - 1));
1967 t = build (PLUS_EXPR, ptr_type_node, mem, u);
1968 u = fold (build (BIT_NOT_EXPR, ptr_type_node, u));
1969 t = build (BIT_AND_EXPR, ptr_type_node, t, u);
1970 addr = get_initialized_tmp_var (t, pre_p, post_p);
1972 u = fold_convert (ptr_type_node, size);
1973 t = build (PLUS_EXPR, ptr_type_node, addr, size);
1974 t = build (MODIFY_EXPR, ptr_type_node, mem, t);
1975 gimplify_and_add (t, pre_p);
1977 else
1979 isize = tree_low_cst (size, 0);
1981 if (FLOAT_TYPE_P (type) || (INTEGRAL_TYPE_P (type) && isize == 8))
1983 /* Floats and long longs are passed in the fp registers. */
1984 reg = fpr;
1985 n_reg = size_int (isize / UNITS_PER_WORD);
1986 n_reg = fold_convert (unsigned_type_node, n_reg);
1987 lim_reg = size_int (NUM_PARM_FREGS - (isize / UNITS_PER_WORD));
1988 lim_reg = fold_convert (unsigned_type_node, lim_reg);
1989 sav_ofs = size_int (FREG_OFFSET);
1991 else
1993 /* Everything else is passed in general registers. */
1994 reg = gpr;
1995 if ((isize + UNITS_PER_WORD - 1) / UNITS_PER_WORD > 1)
1996 abort ();
1997 n_reg = fold_convert (unsigned_type_node, integer_one_node);
1998 lim_reg = size_int (NUM_PARM_IREGS - 1);
1999 lim_reg = fold_convert (unsigned_type_node, lim_reg);
2000 sav_ofs = size_int (IREG_OFFSET);
2003 u = build (LE_EXPR, boolean_type_node, reg, lim_reg);
2004 addr = build (COND_EXPR, ptr_type_node, u, NULL, NULL);
2006 /* The value was passed in a register, so read it from the register
2007 save area initialized by __builtin_saveregs. */
2009 sav_ofs = fold_convert (ptr_type_node, sav_ofs);
2010 sav_ofs = fold (build (PLUS_EXPR, ptr_type_node, sav, sav_ofs));
2012 u = fold_convert (unsigned_type_node, size_int (UNITS_PER_WORD));
2013 u = build (MULT_EXPR, unsigned_type_node, reg, u);
2014 u = fold_convert (ptr_type_node, u);
2015 u = build (PLUS_EXPR, ptr_type_node, sav_ofs, u);
2016 COND_EXPR_THEN (addr) = u;
2018 /* The value was passed in memory, so read it from the overflow area. */
2020 t = fold_convert (ptr_type_node, size);
2021 u = build (POSTINCREMENT_EXPR, ptr_type_node, mem, t);
2022 COND_EXPR_ELSE (addr) = u;
2024 /* Increment either the ireg_used or freg_used field. */
2026 t = build (PLUS_EXPR, unsigned_type_node, reg, n_reg);
2027 t = build (MODIFY_EXPR, unsigned_type_node, reg, t);
2028 gimplify_and_add (t, post_p);
2031 addr = fold_convert (type_ptr, addr);
2032 return build_fold_indirect_ref (addr);
2035 /* Compute a (partial) cost for rtx X. Return true if the complete
2036 cost has been computed, and false if subexpressions should be
2037 scanned. In either case, *TOTAL contains the cost result. */
2039 static bool
2040 i860_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, int *total)
2042 switch (code)
2044 case CONST_INT:
2045 if (INTVAL (x) == 0)
2046 *total = 0;
2047 else if (INTVAL (x) < 0x2000 && INTVAL (x) >= -0x2000)
2048 *total = 1;
2049 return true;
2050 case CONST:
2051 case LABEL_REF:
2052 case SYMBOL_REF:
2053 *total = 4;
2054 return true;
2055 case CONST_DOUBLE:
2056 *total = 6;
2057 return true;
2058 default:
2059 return false;
2063 static void
2064 i860_internal_label (FILE *stream, const char *prefix, unsigned long labelno)
2066 fprintf (stream, ".%s%ld:\n", prefix, labelno);
2069 static void
2070 i860_file_start (void)
2072 output_file_directive (asm_out_file, main_input_filename);
2073 fprintf (asm_out_file, "\t.version\t\"01.01\"\n");
2076 static void
2077 i860_init_libfuncs (void)
2079 set_optab_libfunc (sdiv_optab, SImode, "*.div");
2080 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
2081 set_optab_libfunc (smod_optab, SImode, "*.rem");
2082 set_optab_libfunc (umod_optab, SImode, "*.urem");
2085 static rtx
2086 i860_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2087 int incoming ATTRIBUTE_UNUSED)
2089 return gen_rtx_REG (Pmode, I860_STRUCT_VALUE_REGNUM);
2092 /* Initialize the GCC target structure. */
2093 #undef TARGET_RTX_COSTS
2094 #define TARGET_RTX_COSTS i860_rtx_costs
2096 #undef TARGET_ASM_INTERNAL_LABEL
2097 #define TARGET_ASM_INTERNAL_LABEL i860_internal_label
2099 #undef TARGET_ASM_FUNCTION_PROLOGUE
2100 #define TARGET_ASM_FUNCTION_PROLOGUE i860_output_function_prologue
2102 #undef TARGET_ASM_FUNCTION_EPILOGUE
2103 #define TARGET_ASM_FUNCTION_EPILOGUE i860_output_function_epilogue
2105 #undef TARGET_INIT_LIBFUNCS
2106 #define TARGET_INIT_LIBFUNCS i860_init_libfuncs
2108 #undef TARGET_BUILD_BUILTIN_VA_LIST
2109 #define TARGET_BUILD_BUILTIN_VA_LIST i860_build_builtin_va_list
2110 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
2111 #define TARGET_GIMPLIFY_VA_ARG_EXPR i860_gimplify_va_arg_expr
2113 #undef TARGET_STRUCT_VALUE_RTX
2114 #define TARGET_STRUCT_VALUE_RTX i860_struct_value_rtx
2116 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
2117 #define TARGET_EXPAND_BUILTIN_SAVEREGS i860_saveregs
2119 struct gcc_target targetm = TARGET_INITIALIZER;