(i960_function_epilogue): Don't clear g14 for functions with an argument block.
[gcc.git] / gcc / config / i960 / i960.c
1 /* Subroutines used for code generation on intel 80960.
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
3 Contributed by Steven McGeady, Intel Corp.
4 Additional Work by Glenn Colon-Bonet, Jonathan Shapiro, Andy Wilson
5 Converted to GCC 2.0 by Jim Wilson and Michael Tiemann, Cygnus Support.
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24 #include <stdio.h>
25
26 #include "config.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
34 #include "output.h"
35 #include "insn-attr.h"
36 #include "flags.h"
37 #include "tree.h"
38 #include "insn-codes.h"
39 #include "assert.h"
40 #include "expr.h"
41 #include "function.h"
42 #include "recog.h"
43 #include <math.h>
44
45 /* Save the operands last given to a compare for use when we
46 generate a scc or bcc insn. */
47
48 rtx i960_compare_op0, i960_compare_op1;
49
50 /* Used to implement #pragma align/noalign. Initialized by OVERRIDE_OPTIONS
51 macro in i960.h. */
52
53 static int i960_maxbitalignment;
54 static int i960_last_maxbitalignment;
55
56 /* Used to implement switching between MEM and ALU insn types, for better
57 C series performance. */
58
59 enum insn_types i960_last_insn_type;
60
61 /* The leaf-procedure return register. Set only if this is a leaf routine. */
62
63 static int i960_leaf_ret_reg;
64
65 /* True if replacing tail calls with jumps is OK. */
66
67 static int tail_call_ok;
68
69 /* A string containing a list of insns to emit in the epilogue so as to
70 restore all registers saved by the prologue. Created by the prologue
71 code as it saves registers away. */
72
73 char epilogue_string[1000];
74
75 /* A unique number (per function) for return labels. */
76
77 static int ret_label = 0;
78
79 /* This is true if FNDECL is either a varargs or a stdarg function.
80 This is used to help identify functions that use an argument block. */
81
82 #define VARARGS_STDARG_FUNCTION(FNDECL) \
83 ((TYPE_ARG_TYPES (TREE_TYPE (FNDECL)) != 0 \
84 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \
85 || current_function_varargs)
86
87 /* Handle pragmas for compatibility with Intel's compilers. */
88
89 /* ??? This is incomplete, since it does not handle all pragmas that the
90 intel compilers understand. */
91
92 void
93 process_pragma (finput)
94 FILE *finput;
95 {
96 int c;
97 int i;
98
99 c = getc (finput);
100 while (c == ' ' || c == '\t')
101 c = getc (finput);
102
103 if (c == 'a'
104 && getc (finput) == 'l'
105 && getc (finput) == 'i'
106 && getc (finput) == 'g'
107 && getc (finput) == 'n'
108 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
109 {
110 char buf[20];
111 char *s = buf;
112 int align;
113
114 while (c == ' ' || c == '\t')
115 c = getc (finput);
116 if (c == '(')
117 c = getc (finput);
118 while (c >= '0' && c <= '9')
119 {
120 if (s < buf + sizeof buf - 1)
121 *s++ = c;
122 c = getc (finput);
123 }
124 *s = '\0';
125
126 align = atoi (buf);
127 switch (align)
128 {
129 case 0:
130 /* Return to last alignment. */
131 align = i960_last_maxbitalignment / 8;
132 /* Fall through. */
133 case 16:
134 case 8:
135 case 4:
136 case 2:
137 case 1:
138 i960_last_maxbitalignment = i960_maxbitalignment;
139 i960_maxbitalignment = align * 8;
140 break;
141
142 default:
143 /* Silently ignore bad values. */
144 break;
145 }
146
147 /* NOTE: ic960 R3.0 pragma align definition:
148
149 #pragma align [(size)] | (identifier=size[,...])
150 #pragma noalign [(identifier)[,...]]
151
152 (all parens are optional)
153
154 - size is [1,2,4,8,16]
155 - noalign means size==1
156 - applies only to component elements of a struct (and union?)
157 - identifier applies to structure tag (only)
158 - missing identifier means next struct
159
160 - alignment rules for bitfields need more investigation */
161 }
162
163 /* Should be pragma 'far' or equivalent for callx/balx here. */
164
165 ungetc (c, finput);
166 }
167
168 /* Initialize variables before compiling any files. */
169
170 void
171 i960_initialize ()
172 {
173 if (TARGET_IC_COMPAT2_0)
174 {
175 i960_maxbitalignment = 8;
176 i960_last_maxbitalignment = 128;
177 }
178 else
179 {
180 i960_maxbitalignment = 128;
181 i960_last_maxbitalignment = 8;
182 }
183 }
184 \f
185 /* Return true if OP can be used as the source of an fp move insn. */
186
187 int
188 fpmove_src_operand (op, mode)
189 rtx op;
190 enum machine_mode mode;
191 {
192 return (GET_CODE (op) == CONST_DOUBLE || general_operand (op, mode));
193 }
194
195 #if 0
196 /* Return true if OP is a register or zero. */
197
198 int
199 reg_or_zero_operand (op, mode)
200 rtx op;
201 enum machine_mode mode;
202 {
203 return register_operand (op, mode) || op == const0_rtx;
204 }
205 #endif
206
207 /* Return truth value of whether OP can be used as an operands in a three
208 address arithmetic insn (such as add %o1,7,%l2) of mode MODE. */
209
210 int
211 arith_operand (op, mode)
212 rtx op;
213 enum machine_mode mode;
214 {
215 return (register_operand (op, mode) || literal (op, mode));
216 }
217
218 /* Return true if OP is a register or a valid floating point literal. */
219
220 int
221 fp_arith_operand (op, mode)
222 rtx op;
223 enum machine_mode mode;
224 {
225 return (register_operand (op, mode) || fp_literal (op, mode));
226 }
227
228 /* Return true is OP is a register or a valid signed integer literal. */
229
230 int
231 signed_arith_operand (op, mode)
232 rtx op;
233 enum machine_mode mode;
234 {
235 return (register_operand (op, mode) || signed_literal (op, mode));
236 }
237
238 /* Return truth value of whether OP is a integer which fits the
239 range constraining immediate operands in three-address insns. */
240
241 int
242 literal (op, mode)
243 rtx op;
244 enum machine_mode mode;
245 {
246 return ((GET_CODE (op) == CONST_INT) && INTVAL(op) >= 0 && INTVAL(op) < 32);
247 }
248
249 /* Return true if OP is a float constant of 1. */
250
251 int
252 fp_literal_one (op, mode)
253 rtx op;
254 enum machine_mode mode;
255 {
256 return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST1_RTX (mode));
257 }
258
259 /* Return true if OP is a float constant of 0. */
260
261 int
262 fp_literal_zero (op, mode)
263 rtx op;
264 enum machine_mode mode;
265 {
266 return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST0_RTX (mode));
267 }
268
269 /* Return true if OP is a valid floating point literal. */
270
271 int
272 fp_literal(op, mode)
273 rtx op;
274 enum machine_mode mode;
275 {
276 return fp_literal_zero (op, mode) || fp_literal_one (op, mode);
277 }
278
279 /* Return true if OP is a valid signed immediate constant. */
280
281 int
282 signed_literal(op, mode)
283 rtx op;
284 enum machine_mode mode;
285 {
286 return ((GET_CODE (op) == CONST_INT) && INTVAL(op) > -32 && INTVAL(op) < 32);
287 }
288
289 /* Return truth value of statement that OP is a symbolic memory
290 operand of mode MODE. */
291
292 int
293 symbolic_memory_operand (op, mode)
294 rtx op;
295 enum machine_mode mode;
296 {
297 if (GET_CODE (op) == SUBREG)
298 op = SUBREG_REG (op);
299 if (GET_CODE (op) != MEM)
300 return 0;
301 op = XEXP (op, 0);
302 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
303 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
304 }
305
306 /* Return truth value of whether OP is EQ or NE. */
307
308 int
309 eq_or_neq (op, mode)
310 rtx op;
311 enum machine_mode mode;
312 {
313 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
314 }
315
316 /* OP is an integer register or a constant. */
317
318 int
319 arith32_operand (op, mode)
320 rtx op;
321 enum machine_mode mode;
322 {
323 if (register_operand (op, mode))
324 return 1;
325 return (CONSTANT_P (op));
326 }
327
328 /* Return true if OP is an integer constant which is a power of 2. */
329
330 int
331 power2_operand (op,mode)
332 rtx op;
333 enum machine_mode mode;
334 {
335 if (GET_CODE (op) != CONST_INT)
336 return 0;
337
338 return exact_log2 (INTVAL (op)) >= 0;
339 }
340
341 /* Return true if OP is an integer constant which is the complement of a
342 power of 2. */
343
344 int
345 cmplpower2_operand (op, mode)
346 rtx op;
347 enum machine_mode mode;
348 {
349 if (GET_CODE (op) != CONST_INT)
350 return 0;
351
352 return exact_log2 (~ INTVAL (op)) >= 0;
353 }
354
355 /* If VAL has only one bit set, return the index of that bit. Otherwise
356 return -1. */
357
358 int
359 bitpos (val)
360 unsigned int val;
361 {
362 register int i;
363
364 for (i = 0; val != 0; i++, val >>= 1)
365 {
366 if (val & 1)
367 {
368 if (val != 1)
369 return -1;
370 return i;
371 }
372 }
373 return -1;
374 }
375
376 /* Return non-zero if OP is a mask, i.e. all one bits are consecutive.
377 The return value indicates how many consecutive non-zero bits exist
378 if this is a mask. This is the same as the next function, except that
379 it does not indicate what the start and stop bit positions are. */
380
381 int
382 is_mask (val)
383 unsigned int val;
384 {
385 register int start, end, i;
386
387 start = -1;
388 for (i = 0; val != 0; val >>= 1, i++)
389 {
390 if (val & 1)
391 {
392 if (start < 0)
393 start = i;
394
395 end = i;
396 continue;
397 }
398 /* Still looking for the first bit. */
399 if (start < 0)
400 continue;
401
402 /* We've seen the start of a bit sequence, and now a zero. There
403 must be more one bits, otherwise we would have exited the loop.
404 Therefore, it is not a mask. */
405 if (val)
406 return 0;
407 }
408
409 /* The bit string has ones from START to END bit positions only. */
410 return end - start + 1;
411 }
412
413 /* If VAL is a mask, then return nonzero, with S set to the starting bit
414 position and E set to the ending bit position of the mask. The return
415 value indicates how many consecutive bits exist in the mask. This is
416 the same as the previous function, except that it also indicates the
417 start and end bit positions of the mask. */
418
419 int
420 bitstr (val, s, e)
421 unsigned int val;
422 int *s, *e;
423 {
424 register int start, end, i;
425
426 start = -1;
427 end = -1;
428 for (i = 0; val != 0; val >>= 1, i++)
429 {
430 if (val & 1)
431 {
432 if (start < 0)
433 start = i;
434
435 end = i;
436 continue;
437 }
438
439 /* Still looking for the first bit. */
440 if (start < 0)
441 continue;
442
443 /* We've seen the start of a bit sequence, and now a zero. There
444 must be more one bits, otherwise we would have exited the loop.
445 Therefor, it is not a mask. */
446 if (val)
447 {
448 start = -1;
449 end = -1;
450 break;
451 }
452 }
453
454 /* The bit string has ones from START to END bit positions only. */
455 *s = start;
456 *e = end;
457 return ((start < 0) ? 0 : end - start + 1);
458 }
459 \f
460 /* Return the machine mode to use for a comparison. */
461
462 enum machine_mode
463 select_cc_mode (op, x)
464 RTX_CODE op;
465 rtx x;
466 {
467 if (op == GTU || op == LTU || op == GEU || op == LEU)
468 return CC_UNSmode;
469 return CCmode;
470 }
471
472 /* X and Y are two things to compare using CODE. Emit the compare insn and
473 return the rtx for register 36 in the proper mode. */
474
475 rtx
476 gen_compare_reg (code, x, y)
477 enum rtx_code code;
478 rtx x, y;
479 {
480 rtx cc_reg;
481 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
482 enum machine_mode mode
483 = GET_MODE (x) == VOIDmode ? GET_MODE (y) : GET_MODE (x);
484
485 if (mode == SImode)
486 {
487 if (! arith_operand (x, mode))
488 x = force_reg (SImode, x);
489 if (! arith_operand (y, mode))
490 y = force_reg (SImode, y);
491 }
492
493 cc_reg = gen_rtx (REG, ccmode, 36);
494 emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
495 gen_rtx (COMPARE, ccmode, x, y)));
496
497 return cc_reg;
498 }
499
500 /* For the i960, REG is cost 1, REG+immed CONST is cost 2, REG+REG is cost 2,
501 REG+nonimmed CONST is cost 4. REG+SYMBOL_REF, SYMBOL_REF, and similar
502 are 4. Indexed addresses are cost 6. */
503
504 /* ??? Try using just RTX_COST, i.e. not defining ADDRESS_COST. */
505
506 int
507 i960_address_cost (x)
508 rtx x;
509 {
510 #if 0
511 /* Handled before calling here. */
512 if (GET_CODE (x) == REG)
513 return 1;
514 #endif
515 if (GET_CODE (x) == PLUS)
516 {
517 rtx base = XEXP (x, 0);
518 rtx offset = XEXP (x, 1);
519
520 if (GET_CODE (base) == SUBREG)
521 base = SUBREG_REG (base);
522 if (GET_CODE (offset) == SUBREG)
523 offset = SUBREG_REG (offset);
524
525 if (GET_CODE (base) == REG)
526 {
527 if (GET_CODE (offset) == REG)
528 return 2;
529 if (GET_CODE (offset) == CONST_INT)
530 {
531 if ((unsigned)INTVAL (offset) < 2047)
532 return 2;
533 return 4;
534 }
535 if (CONSTANT_P (offset))
536 return 4;
537 }
538 if (GET_CODE (base) == PLUS || GET_CODE (base) == MULT)
539 return 6;
540
541 /* This is an invalid address. The return value doesn't matter, but
542 for convenience we make this more expensive than anything else. */
543 return 12;
544 }
545 if (GET_CODE (x) == MULT)
546 return 6;
547
548 /* Symbol_refs and other unrecognized addresses are cost 4. */
549 return 4;
550 }
551 \f
552 /* Emit insns to move operands[1] into operands[0].
553
554 Return 1 if we have written out everything that needs to be done to
555 do the move. Otherwise, return 0 and the caller will emit the move
556 normally. */
557
558 int
559 emit_move_sequence (operands, mode)
560 rtx *operands;
561 enum machine_mode mode;
562 {
563 register rtx operand0 = operands[0];
564 register rtx operand1 = operands[1];
565
566 /* We can only store registers to memory. */
567
568 if (GET_CODE (operand0) == MEM && GET_CODE (operand1) != REG)
569 operands[1] = force_reg (mode, operand1);
570
571 return 0;
572 }
573 \f
574 /* Emit insns to load a constant to non-floating point registers.
575 Uses several strategies to try to use as few insns as possible. */
576
577 char *
578 i960_output_ldconst (dst, src)
579 register rtx dst, src;
580 {
581 register int rsrc1;
582 register unsigned rsrc2;
583 enum machine_mode mode = GET_MODE (dst);
584 rtx operands[4];
585
586 operands[0] = operands[2] = dst;
587 operands[1] = operands[3] = src;
588
589 /* Anything that isn't a compile time constant, such as a SYMBOL_REF,
590 must be a ldconst insn. */
591
592 if (GET_CODE (src) != CONST_INT && GET_CODE (src) != CONST_DOUBLE)
593 {
594 output_asm_insn ("ldconst %1,%0", operands);
595 return "";
596 }
597 else if (mode == XFmode)
598 {
599 REAL_VALUE_TYPE d;
600 long value_long[3];
601 int i;
602
603 if (fp_literal_zero (src, XFmode))
604 return "movt 0,%0";
605
606 REAL_VALUE_FROM_CONST_DOUBLE (d, src);
607 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, value_long);
608
609 output_asm_insn ("# ldconst %1,%0",operands);
610
611 for (i = 0; i < 3; i++)
612 {
613 operands[0] = gen_rtx (REG, SImode, REGNO (dst) + i);
614 operands[1] = GEN_INT (value_long[i]);
615 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
616 operands);
617 }
618
619 return "";
620 }
621 else if (mode == DFmode)
622 {
623 rtx first, second;
624
625 if (fp_literal_zero (src, DFmode))
626 return "movl 0,%0";
627
628 split_double (src, &first, &second);
629
630 output_asm_insn ("# ldconst %1,%0",operands);
631
632 operands[0] = gen_rtx (REG, SImode, REGNO (dst));
633 operands[1] = first;
634 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
635 operands);
636 operands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
637 operands[1] = second;
638 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
639 operands);
640 return "";
641 }
642 else if (mode == SFmode)
643 {
644 REAL_VALUE_TYPE d;
645 long value;
646
647 REAL_VALUE_FROM_CONST_DOUBLE (d, src);
648 REAL_VALUE_TO_TARGET_SINGLE (d, value);
649
650 output_asm_insn ("# ldconst %1,%0",operands);
651 operands[0] = gen_rtx (REG, SImode, REGNO (dst));
652 operands[1] = gen_rtx (CONST_INT, VOIDmode, value);
653 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
654 operands);
655 return "";
656 }
657 else if (mode == TImode)
658 {
659 /* ??? This is currently not handled at all. */
660 abort ();
661
662 /* Note: lowest order word goes in lowest numbered reg. */
663 rsrc1 = INTVAL (src);
664 if (rsrc1 >= 0 && rsrc1 < 32)
665 return "movq %1,%0";
666 else
667 output_asm_insn ("movq\t0,%0\t# ldconstq %1,%0",operands);
668 /* Go pick up the low-order word. */
669 }
670 else if (mode == DImode)
671 {
672 rtx upperhalf, lowerhalf, xoperands[2];
673
674 if (GET_CODE (src) == CONST_DOUBLE || GET_CODE (src) == CONST_INT)
675 split_double (src, &lowerhalf, &upperhalf);
676
677 else
678 abort ();
679
680 /* Note: lowest order word goes in lowest numbered reg. */
681 /* Numbers from 0 to 31 can be handled with a single insn. */
682 rsrc1 = INTVAL (lowerhalf);
683 if (upperhalf == const0_rtx && rsrc1 >= 0 && rsrc1 < 32)
684 return "movl %1,%0";
685
686 /* Output the upper half with a recursive call. */
687 xoperands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
688 xoperands[1] = upperhalf;
689 output_asm_insn (i960_output_ldconst (xoperands[0], xoperands[1]),
690 xoperands);
691 /* The lower word is emitted as normally. */
692 }
693 else
694 {
695 rsrc1 = INTVAL (src);
696 if (mode == QImode)
697 {
698 if (rsrc1 > 0xff)
699 rsrc1 &= 0xff;
700 }
701 else if (mode == HImode)
702 {
703 if (rsrc1 > 0xffff)
704 rsrc1 &= 0xffff;
705 }
706 }
707
708 if (rsrc1 >= 0)
709 {
710 /* ldconst 0..31,X -> mov 0..31,X */
711 if (rsrc1 < 32)
712 {
713 if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
714 return "lda %1,%0";
715 return "mov %1,%0";
716 }
717
718 /* ldconst 32..63,X -> add 31,nn,X */
719 if (rsrc1 < 63)
720 {
721 if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
722 return "lda %1,%0";
723 operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc1 - 31);
724 output_asm_insn ("addo\t31,%1,%0\t# ldconst %3,%0", operands);
725 return "";
726 }
727 }
728 else if (rsrc1 < 0)
729 {
730 /* ldconst -1..-31 -> sub 0,0..31,X */
731 if (rsrc1 >= -31)
732 {
733 /* return 'sub -(%1),0,%0' */
734 operands[1] = gen_rtx (CONST_INT, VOIDmode, - rsrc1);
735 output_asm_insn ("subo\t%1,0,%0\t# ldconst %3,%0", operands);
736 return "";
737 }
738
739 /* ldconst -32 -> not 31,X */
740 if (rsrc1 == -32)
741 {
742 operands[1] = gen_rtx (CONST_INT, VOIDmode, ~rsrc1);
743 output_asm_insn ("not\t%1,%0 # ldconst %3,%0", operands);
744 return "";
745 }
746 }
747
748 /* If const is a single bit. */
749 if (bitpos (rsrc1) >= 0)
750 {
751 operands[1] = gen_rtx (CONST_INT, VOIDmode, bitpos (rsrc1));
752 output_asm_insn ("setbit\t%1,0,%0\t# ldconst %3,%0", operands);
753 return "";
754 }
755
756 /* If const is a bit string of less than 6 bits (1..31 shifted). */
757 if (is_mask (rsrc1))
758 {
759 int s, e;
760
761 if (bitstr (rsrc1, &s, &e) < 6)
762 {
763 rsrc2 = ((unsigned int) rsrc1) >> s;
764 operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc2);
765 operands[2] = gen_rtx (CONST_INT, VOIDmode, s);
766 output_asm_insn ("shlo\t%2,%1,%0\t# ldconst %3,%0", operands);
767 return "";
768 }
769 }
770
771 /* Unimplemented cases:
772 const is in range 0..31 but rotated around end of word:
773 ror 31,3,g0 -> ldconst 0xe0000003,g0
774
775 and any 2 instruction cases that might be worthwhile */
776
777 output_asm_insn ("ldconst %1,%0", operands);
778 return "";
779 }
780
781 /* Determine if there is an opportunity for a bypass optimization.
782 Bypass succeeds on the 960K* if the destination of the previous
783 instruction is the second operand of the current instruction.
784 Bypass always succeeds on the C*.
785
786 Return 1 if the pattern should interchange the operands.
787
788 CMPBR_FLAG is true if this is for a compare-and-branch insn.
789 OP1 and OP2 are the two source operands of a 3 operand insn. */
790
791 int
792 i960_bypass (insn, op1, op2, cmpbr_flag)
793 register rtx insn, op1, op2;
794 int cmpbr_flag;
795 {
796 register rtx prev_insn, prev_dest;
797
798 if (TARGET_C_SERIES)
799 return 0;
800
801 /* Can't do this if op1 isn't a register. */
802 if (! REG_P (op1))
803 return 0;
804
805 /* Can't do this for a compare-and-branch if both ops aren't regs. */
806 if (cmpbr_flag && ! REG_P (op2))
807 return 0;
808
809 prev_insn = prev_real_insn (insn);
810
811 if (prev_insn && GET_CODE (prev_insn) == INSN
812 && GET_CODE (PATTERN (prev_insn)) == SET)
813 {
814 prev_dest = SET_DEST (PATTERN (prev_insn));
815 if ((GET_CODE (prev_dest) == REG && REGNO (prev_dest) == REGNO (op1))
816 || (GET_CODE (prev_dest) == SUBREG
817 && GET_CODE (SUBREG_REG (prev_dest)) == REG
818 && REGNO (SUBREG_REG (prev_dest)) == REGNO (op1)))
819 return 1;
820 }
821 return 0;
822 }
823 \f
824 /* Output the code which declares the function name. This also handles
825 leaf routines, which have special requirements, and initializes some
826 global variables. */
827
828 void
829 i960_function_name_declare (file, name, fndecl)
830 FILE *file;
831 char *name;
832 tree fndecl;
833 {
834 register int i, j;
835 int leaf_proc_ok;
836 rtx insn;
837
838 /* Increment global return label. */
839
840 ret_label++;
841
842 /* Compute whether tail calls and leaf routine optimizations can be performed
843 for this function. */
844
845 if (TARGET_TAILCALL)
846 tail_call_ok = 1;
847 else
848 tail_call_ok = 0;
849
850 if (TARGET_LEAFPROC)
851 leaf_proc_ok = 1;
852 else
853 leaf_proc_ok = 0;
854
855 /* Even if nobody uses extra parms, can't have leafproc or tail calls if
856 argblock, because argblock uses g14 implicitly. */
857
858 if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl))
859 {
860 tail_call_ok = 0;
861 leaf_proc_ok = 0;
862 }
863
864 /* See if caller passes in an address to return value. */
865
866 if (aggregate_value_p (DECL_RESULT (fndecl)))
867 {
868 tail_call_ok = 0;
869 leaf_proc_ok = 0;
870 }
871
872 /* Can not use tail calls or make this a leaf routine if there is a non
873 zero frame size. */
874
875 if (get_frame_size () != 0)
876 leaf_proc_ok = 0;
877
878 /* I don't understand this condition, and do not think that it is correct.
879 Apparently this is just checking whether the frame pointer is used, and
880 we can't trust regs_ever_live[fp] since it is (almost?) always set. */
881
882 if (tail_call_ok)
883 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
884 if (GET_CODE (insn) == INSN
885 && reg_mentioned_p (frame_pointer_rtx, insn))
886 {
887 tail_call_ok = 0;
888 break;
889 }
890
891 /* Check for CALL insns. Can not be a leaf routine if there are any. */
892
893 if (leaf_proc_ok)
894 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
895 if (GET_CODE (insn) == CALL_INSN)
896 {
897 leaf_proc_ok = 0;
898 break;
899 }
900
901 /* Can not be a leaf routine if any non-call clobbered registers are
902 used in this function. */
903
904 if (leaf_proc_ok)
905 for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
906 if (regs_ever_live[i]
907 && ((! call_used_regs[i]) || (i > 7 && i < 12)))
908 {
909 /* Global registers. */
910 if (i < 16 && i > 7 && i != 13)
911 leaf_proc_ok = 0;
912 /* Local registers. */
913 else if (i < 32)
914 leaf_proc_ok = 0;
915 }
916
917 /* Now choose a leaf return register, if we can find one, and if it is
918 OK for this to be a leaf routine. */
919
920 i960_leaf_ret_reg = -1;
921
922 if (optimize && leaf_proc_ok)
923 {
924 for (i960_leaf_ret_reg = -1, i = 0; i < 8; i++)
925 if (regs_ever_live[i] == 0)
926 {
927 i960_leaf_ret_reg = i;
928 regs_ever_live[i] = 1;
929 break;
930 }
931 }
932
933 /* Do this after choosing the leaf return register, so it will be listed
934 if one was chosen. */
935
936 fprintf (file, "\t# Function '%s'\n", (name[0] == '*' ? &name[1] : name));
937 fprintf (file, "\t# Registers used: ");
938
939 for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
940 {
941 if (regs_ever_live[i])
942 {
943 fprintf (file, "%s%s ", reg_names[i], call_used_regs[i] ? "" : "*");
944
945 if (i > 15 && j == 0)
946 {
947 fprintf (file,"\n\t#\t\t ");
948 j++;
949 }
950 }
951 }
952
953 fprintf (file, "\n");
954
955 if (i960_leaf_ret_reg >= 0)
956 {
957 /* Make it a leaf procedure. */
958
959 if (TREE_PUBLIC (fndecl))
960 fprintf (file,"\t.globl\t%s.lf\n", (name[0] == '*' ? &name[1] : name));
961
962 fprintf (file, "\t.leafproc\t");
963 assemble_name (file, name);
964 fprintf (file, ",%s.lf\n", (name[0] == '*' ? &name[1] : name));
965 ASM_OUTPUT_LABEL (file, name);
966 fprintf (file, "\tlda LR%d,g14\n", ret_label);
967 fprintf (file, "%s.lf:\n", (name[0] == '*' ? &name[1] : name));
968 fprintf (file, "\tmov g14,g%d\n", i960_leaf_ret_reg);
969
970 if (TARGET_C_SERIES)
971 {
972 fprintf (file, "\tlda 0,g14\n");
973 i960_last_insn_type = I_TYPE_MEM;
974 }
975 else
976 {
977 fprintf (file, "\tmov 0,g14\n");
978 i960_last_insn_type = I_TYPE_REG;
979 }
980 }
981 else
982 {
983 ASM_OUTPUT_LABEL (file, name);
984 i960_last_insn_type = I_TYPE_CTRL;
985 }
986 }
987 \f
988 /* Compute and return the frame size. */
989
990 int
991 compute_frame_size (size)
992 int size;
993 {
994 int actual_fsize;
995 int outgoing_args_size = current_function_outgoing_args_size;
996
997 /* The STARTING_FRAME_OFFSET is totally hidden to us as far
998 as size is concerned. */
999 actual_fsize = (size + 15) & -16;
1000 actual_fsize += (outgoing_args_size + 15) & -16;
1001
1002 return actual_fsize;
1003 }
1004
1005 /* Output code for the function prologue. */
1006
1007 void
1008 i960_function_prologue (file, size)
1009 FILE *file;
1010 unsigned int size;
1011 {
1012 register int i, j, nr;
1013 int n_iregs = 0;
1014 int rsize = 0;
1015 int actual_fsize, offset;
1016 char tmpstr[1000];
1017 /* -1 if reg must be saved on proc entry, 0 if available, 1 if saved
1018 somewhere. */
1019 int regs[FIRST_PSEUDO_REGISTER];
1020
1021 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1022 if (regs_ever_live[i]
1023 && ((! call_used_regs[i]) || (i > 7 && i < 12)))
1024 {
1025 regs[i] = -1;
1026 /* Count global registers that need saving. */
1027 if (i < 16)
1028 n_iregs++;
1029 }
1030 else
1031 regs[i] = 0;
1032
1033 epilogue_string[0] = '\0';
1034
1035 if (profile_flag || profile_block_flag)
1036 {
1037 /* When profiling, we may use registers 20 to 27 to save arguments, so
1038 they can't be used here for saving globals. J is the number of
1039 argument registers the mcount call will save. */
1040 for (j = 7; j >= 0 && ! regs_ever_live[j]; j--)
1041 ;
1042
1043 for (i = 20; i <= j + 20; i++)
1044 regs[i] = -1;
1045 }
1046
1047 /* First look for local registers to save globals in. */
1048 for (i = 0; i < 16; i++)
1049 {
1050 if (regs[i] == 0)
1051 continue;
1052
1053 /* Start at r4, not r3. */
1054 for (j = 20; j < 32; j++)
1055 {
1056 if (regs[j] != 0)
1057 continue;
1058
1059 regs[i] = 1;
1060 regs[j] = -1;
1061 regs_ever_live[j] = 1;
1062 nr = 1;
1063 if (i <= 14 && i % 2 == 0 && j <= 30 && j % 2 == 0
1064 && regs[i+1] != 0 && regs[j+1] == 0)
1065 {
1066 nr = 2;
1067 regs[i+1] = 1;
1068 regs[j+1] = -1;
1069 regs_ever_live[j+1] = 1;
1070 }
1071 if (nr == 2 && i <= 12 && i % 4 == 0 && j <= 28 && j % 4 == 0
1072 && regs[i+2] != 0 && regs[j+2] == 0)
1073 {
1074 nr = 3;
1075 regs[i+2] = 1;
1076 regs[j+2] = -1;
1077 regs_ever_live[j+2] = 1;
1078 }
1079 if (nr == 3 && regs[i+3] != 0 && regs[j+3] == 0)
1080 {
1081 nr = 4;
1082 regs[i+3] = 1;
1083 regs[j+3] = -1;
1084 regs_ever_live[j+3] = 1;
1085 }
1086
1087 fprintf (file, "\tmov%s %s,%s\n",
1088 ((nr == 4) ? "q" :
1089 (nr == 3) ? "t" :
1090 (nr == 2) ? "l" : ""),
1091 reg_names[i], reg_names[j]);
1092 sprintf (tmpstr, "\tmov%s %s,%s\n",
1093 ((nr == 4) ? "q" :
1094 (nr == 3) ? "t" :
1095 (nr == 2) ? "l" : ""),
1096 reg_names[j], reg_names[i]);
1097 strcat (epilogue_string, tmpstr);
1098
1099 n_iregs -= nr;
1100 i += nr-1;
1101 break;
1102 }
1103 }
1104
1105 /* N_iregs is now the number of global registers that haven't been saved
1106 yet. */
1107
1108 rsize = (n_iregs * 4);
1109 actual_fsize = compute_frame_size (size) + rsize;
1110 #if 0
1111 /* ??? The 1.2.1 compiler does this also. This is meant to round the frame
1112 size up to the nearest multiple of 16. I don't know whether this is
1113 necessary, or even desirable.
1114
1115 The frame pointer must be aligned, but the call instruction takes care of
1116 that. If we leave the stack pointer unaligned, we may save a little on
1117 dynamic stack allocation. And we don't lose, at least according to the
1118 i960CA manual. */
1119 actual_fsize = (actual_fsize + 15) & ~0xF;
1120 #endif
1121
1122 /* Allocate space for register save and locals. */
1123 if (actual_fsize > 0)
1124 {
1125 if (actual_fsize < 32)
1126 fprintf (file, "\taddo %d,sp,sp\n", actual_fsize);
1127 else
1128 fprintf (file, "\tlda\t%d(sp),sp\n", actual_fsize);
1129 }
1130
1131 /* Take hardware register save area created by the call instruction
1132 into account, but store them before the argument block area. */
1133 offset = 64 + actual_fsize - compute_frame_size (0) - rsize;
1134 /* Save registers on stack if needed. */
1135 for (i = 0, j = n_iregs; j > 0 && i < 16; i++)
1136 {
1137 if (regs[i] != -1)
1138 continue;
1139
1140 nr = 1;
1141
1142 if (i <= 14 && i % 2 == 0 && regs[i+1] == -1 && offset % 2 == 0)
1143 nr = 2;
1144
1145 if (nr == 2 && i <= 12 && i % 4 == 0 && regs[i+2] == -1
1146 && offset % 4 == 0)
1147 nr = 3;
1148
1149 if (nr == 3 && regs[i+3] == -1)
1150 nr = 4;
1151
1152 fprintf (file,"\tst%s %s,%d(fp)\n",
1153 ((nr == 4) ? "q" :
1154 (nr == 3) ? "t" :
1155 (nr == 2) ? "l" : ""),
1156 reg_names[i], offset);
1157 sprintf (tmpstr,"\tld%s %d(fp),%s\n",
1158 ((nr == 4) ? "q" :
1159 (nr == 3) ? "t" :
1160 (nr == 2) ? "l" : ""),
1161 offset, reg_names[i]);
1162 strcat (epilogue_string, tmpstr);
1163 i += nr-1;
1164 j -= nr;
1165 offset += nr * 4;
1166 }
1167
1168 if (actual_fsize == 0 && size == 0 && rsize == 0)
1169 return;
1170
1171 fprintf (file, "\t#Prologue stats:\n");
1172 fprintf (file, "\t# Total Frame Size: %d bytes\n", actual_fsize);
1173
1174 if (size)
1175 fprintf (file, "\t# Local Variable Size: %d bytes\n", size);
1176 if (rsize)
1177 fprintf (file, "\t# Register Save Size: %d regs, %d bytes\n",
1178 n_iregs, rsize);
1179 fprintf (file, "\t#End Prologue#\n");
1180 }
1181
1182 /* Output code for the function profiler. */
1183
1184 void
1185 output_function_profiler (file, labelno)
1186 FILE *file;
1187 int labelno;
1188 {
1189 /* The last used parameter register. */
1190 int last_parm_reg;
1191 int i, j, increment;
1192 int varargs_stdarg_function
1193 = VARARGS_STDARG_FUNCTION (current_function_decl);
1194
1195 /* Figure out the last used parameter register. The proper thing to do
1196 is to walk incoming args of the function. A function might have live
1197 parameter registers even if it has no incoming args. Note that we
1198 don't have to save parameter registers g8 to g11 because they are
1199 call preserved. */
1200
1201 /* See also output_function_prologue, which tries to use local registers
1202 for preserved call-saved global registers. */
1203
1204 for (last_parm_reg = 7;
1205 last_parm_reg >= 0 && ! regs_ever_live[last_parm_reg];
1206 last_parm_reg--)
1207 ;
1208
1209 /* Save parameter registers in regs r4 (20) to r11 (27). */
1210
1211 for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment)
1212 {
1213 if (i % 4 == 0 && (last_parm_reg - i) >= 3)
1214 increment = 4;
1215 else if (i % 4 == 0 && (last_parm_reg - i) >= 2)
1216 increment = 3;
1217 else if (i % 2 == 0 && (last_parm_reg - i) >= 1)
1218 increment = 2;
1219 else
1220 increment = 1;
1221
1222 fprintf (file, "\tmov%s g%d,r%d\n",
1223 (increment == 4 ? "q" : increment == 3 ? "t"
1224 : increment == 2 ? "l": ""), i, j);
1225 }
1226
1227 /* If this function uses the arg pointer, then save it in r3 and then
1228 set it to zero. */
1229
1230 if (current_function_args_size != 0 || varargs_stdarg_function)
1231 fprintf (file, "\tmov g14,r3\n\tmov 0,g14\n");
1232
1233 /* Load location address into g0 and call mcount. */
1234
1235 fprintf (file, "\tlda\tLP%d,g0\n\tcallx\tmcount\n", labelno);
1236
1237 /* If this function uses the arg pointer, restore it. */
1238
1239 if (current_function_args_size != 0 || varargs_stdarg_function)
1240 fprintf (file, "\tmov r3,g14\n");
1241
1242 /* Restore parameter registers. */
1243
1244 for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment)
1245 {
1246 if (i % 4 == 0 && (last_parm_reg - i) >= 3)
1247 increment = 4;
1248 else if (i % 4 == 0 && (last_parm_reg - i) >= 2)
1249 increment = 3;
1250 else if (i % 2 == 0 && (last_parm_reg - i) >= 1)
1251 increment = 2;
1252 else
1253 increment = 1;
1254
1255 fprintf (file, "\tmov%s r%d,g%d\n",
1256 (increment == 4 ? "q" : increment == 3 ? "t"
1257 : increment == 2 ? "l": ""), j, i);
1258 }
1259 }
1260
1261 /* Output code for the function epilogue. */
1262
1263 void
1264 i960_function_epilogue (file, size)
1265 FILE *file;
1266 unsigned int size;
1267 {
1268 if (i960_leaf_ret_reg >= 0)
1269 {
1270 fprintf (file, "LR%d: ret\n", ret_label);
1271 return;
1272 }
1273
1274 if (*epilogue_string == 0)
1275 {
1276 register rtx tmp;
1277
1278 /* Emit a return insn, but only if control can fall through to here. */
1279
1280 tmp = get_last_insn ();
1281 while (tmp)
1282 {
1283 if (GET_CODE (tmp) == BARRIER)
1284 return;
1285 if (GET_CODE (tmp) == CODE_LABEL)
1286 break;
1287 if (GET_CODE (tmp) == JUMP_INSN)
1288 {
1289 if (GET_CODE (PATTERN (tmp)) == RETURN)
1290 return;
1291 break;
1292 }
1293 if (GET_CODE (tmp) == NOTE)
1294 {
1295 tmp = PREV_INSN (tmp);
1296 continue;
1297 }
1298 break;
1299 }
1300 fprintf (file, "LR%d: ret\n", ret_label);
1301 return;
1302 }
1303
1304 fprintf (file, "LR%d:\n", ret_label);
1305
1306 fprintf (file, "\t#EPILOGUE#\n");
1307
1308 /* Output the string created by the prologue which will restore all
1309 registers saved by the prologue. */
1310
1311 if (epilogue_string[0] != '\0')
1312 fprintf (file, "%s", epilogue_string);
1313
1314 /* Must clear g14 on return if this function set it.
1315 Only varargs/stdarg functions modify g14. */
1316
1317 if (VARARGS_STDARG_FUNCTION (current_function_decl))
1318 fprintf (file, "\tmov 0,g14\n");
1319
1320 fprintf (file, "\tret\n");
1321 fprintf (file, "\t#End Epilogue#\n");
1322 }
1323
1324 /* Output code for a call insn. */
1325
1326 char *
1327 i960_output_call_insn (target, argsize_rtx, arg_pointer, insn)
1328 register rtx target, argsize_rtx, arg_pointer, insn;
1329 {
1330 int argsize = INTVAL (argsize_rtx);
1331 rtx nexti = next_real_insn (insn);
1332 rtx operands[2];
1333 int varargs_stdarg_function
1334 = VARARGS_STDARG_FUNCTION (current_function_decl);
1335
1336 operands[0] = target;
1337 operands[1] = arg_pointer;
1338
1339 if (current_function_args_size != 0 || varargs_stdarg_function)
1340 output_asm_insn ("mov g14,r3", operands);
1341
1342 if (argsize > 48)
1343 output_asm_insn ("lda %a1,g14", operands);
1344 else if (current_function_args_size != 0 || varargs_stdarg_function)
1345 output_asm_insn ("mov 0,g14", operands);
1346
1347 /* The code used to assume that calls to SYMBOL_REFs could not be more
1348 than 24 bits away (b vs bx, callj vs callx). This is not true. This
1349 feature is now implemented by relaxing in the GNU linker. It can convert
1350 bx to b if in range, and callx to calls/call/balx/bal as appropriate. */
1351
1352 /* Nexti could be zero if the called routine is volatile. */
1353 if (optimize && (*epilogue_string == 0) && argsize == 0 && tail_call_ok
1354 && (nexti == 0 || GET_CODE (PATTERN (nexti)) == RETURN))
1355 {
1356 /* Delete following return insn. */
1357 if (nexti && no_labels_between_p (insn, nexti))
1358 delete_insn (nexti);
1359 output_asm_insn ("bx %0", operands);
1360 return "# notreached";
1361 }
1362
1363 output_asm_insn ("callx %0", operands);
1364
1365 /* If the caller sets g14 to the address of the argblock, then the caller
1366 must clear it after the return. */
1367
1368 if (current_function_args_size != 0 || varargs_stdarg_function)
1369 output_asm_insn ("mov r3,g14", operands);
1370 else if (argsize > 48)
1371 output_asm_insn ("mov 0,g14", operands);
1372
1373 return "";
1374 }
1375
1376 /* Output code for a return insn. */
1377
1378 char *
1379 i960_output_ret_insn (insn)
1380 register rtx insn;
1381 {
1382 static char lbuf[20];
1383
1384 if (*epilogue_string != 0)
1385 {
1386 if (! TARGET_CODE_ALIGN && next_real_insn (insn) == 0)
1387 return "";
1388
1389 sprintf (lbuf, "b LR%d", ret_label);
1390 return lbuf;
1391 }
1392
1393 /* Must clear g14 on return if this function set it.
1394 Only varargs/stdarg functions modify g14. */
1395
1396 if (VARARGS_STDARG_FUNCTION (current_function_decl))
1397 output_asm_insn ("mov 0,g14", 0);
1398
1399 if (i960_leaf_ret_reg >= 0)
1400 {
1401 sprintf (lbuf, "bx (%s)", reg_names[i960_leaf_ret_reg]);
1402 return lbuf;
1403 }
1404 return "ret";
1405 }
1406 \f
1407 #if 0
1408 /* Return a character string representing the branch prediction
1409 opcode to be tacked on an instruction. This must at least
1410 return a null string. */
1411
1412 char *
1413 i960_br_predict_opcode (lab_ref, insn)
1414 rtx lab_ref, insn;
1415 {
1416 if (TARGET_BRANCH_PREDICT)
1417 {
1418 unsigned long label_uid;
1419
1420 if (GET_CODE (lab_ref) == CODE_LABEL)
1421 label_uid = INSN_UID (lab_ref);
1422 else if (GET_CODE (lab_ref) == LABEL_REF)
1423 label_uid = INSN_UID (XEXP (lab_ref, 0));
1424 else
1425 return ".f";
1426
1427 /* If not optimizing, then the insn_addresses array will not be
1428 valid. In this case, always return ".t" since most branches
1429 are taken. If optimizing, return .t for backward branches
1430 and .f for forward branches. */
1431 if (! optimize
1432 || insn_addresses[label_uid] < insn_addresses[INSN_UID (insn)])
1433 return ".t";
1434 return ".f";
1435 }
1436
1437 return "";
1438 }
1439 #endif
1440
1441 /* Print the operand represented by rtx X formatted by code CODE. */
1442
1443 void
1444 i960_print_operand (file, x, code)
1445 FILE *file;
1446 rtx x;
1447 char code;
1448 {
1449 enum rtx_code rtxcode = GET_CODE (x);
1450
1451 if (rtxcode == REG)
1452 {
1453 switch (code)
1454 {
1455 case 'D':
1456 /* Second reg of a double. */
1457 fprintf (file, "%s", reg_names[REGNO (x)+1]);
1458 break;
1459
1460 case 0:
1461 fprintf (file, "%s", reg_names[REGNO (x)]);
1462 break;
1463
1464 default:
1465 abort ();
1466 }
1467 return;
1468 }
1469 else if (rtxcode == MEM)
1470 {
1471 output_address (XEXP (x, 0));
1472 return;
1473 }
1474 else if (rtxcode == CONST_INT)
1475 {
1476 if (INTVAL (x) > 9999 || INTVAL (x) < -999)
1477 fprintf (file, "0x%x", INTVAL (x));
1478 else
1479 fprintf (file, "%d", INTVAL (x));
1480 return;
1481 }
1482 else if (rtxcode == CONST_DOUBLE)
1483 {
1484 REAL_VALUE_TYPE d;
1485 char dstr[30];
1486
1487 if (x == CONST0_RTX (GET_MODE (x)))
1488 {
1489 fprintf (file, "0f0.0");
1490 return;
1491 }
1492 else if (x == CONST1_RTX (GET_MODE (x)))
1493 {
1494 fprintf (file, "0f1.0");
1495 return;
1496 }
1497
1498 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1499 REAL_VALUE_TO_DECIMAL (d, "%#g", dstr);
1500 fprintf (file, "0f%s", dstr);
1501 return;
1502 }
1503
1504 switch(code)
1505 {
1506 case 'B':
1507 /* Branch or jump, depending on assembler. */
1508 if (TARGET_ASM_COMPAT)
1509 fputs ("j", file);
1510 else
1511 fputs ("b", file);
1512 break;
1513
1514 case 'S':
1515 /* Sign of condition. */
1516 if ((rtxcode == EQ) || (rtxcode == NE) || (rtxcode == GTU)
1517 || (rtxcode == LTU) || (rtxcode == GEU) || (rtxcode == LEU))
1518 fputs ("o", file);
1519 else if ((rtxcode == GT) || (rtxcode == LT)
1520 || (rtxcode == GE) || (rtxcode == LE))
1521 fputs ("i", file);
1522 else
1523 abort();
1524 break;
1525
1526 case 'I':
1527 /* Inverted condition. */
1528 rtxcode = reverse_condition (rtxcode);
1529 goto normal;
1530
1531 case 'X':
1532 /* Inverted condition w/ reversed operands. */
1533 rtxcode = reverse_condition (rtxcode);
1534 /* Fallthrough. */
1535
1536 case 'R':
1537 /* Reversed operand condition. */
1538 rtxcode = swap_condition (rtxcode);
1539 /* Fallthrough. */
1540
1541 case 'C':
1542 /* Normal condition. */
1543 normal:
1544 if (rtxcode == EQ) { fputs ("e", file); return; }
1545 else if (rtxcode == NE) { fputs ("ne", file); return; }
1546 else if (rtxcode == GT) { fputs ("g", file); return; }
1547 else if (rtxcode == GTU) { fputs ("g", file); return; }
1548 else if (rtxcode == LT) { fputs ("l", file); return; }
1549 else if (rtxcode == LTU) { fputs ("l", file); return; }
1550 else if (rtxcode == GE) { fputs ("ge", file); return; }
1551 else if (rtxcode == GEU) { fputs ("ge", file); return; }
1552 else if (rtxcode == LE) { fputs ("le", file); return; }
1553 else if (rtxcode == LEU) { fputs ("le", file); return; }
1554 else abort ();
1555 break;
1556
1557 case 0:
1558 output_addr_const (file, x);
1559 break;
1560
1561 default:
1562 abort ();
1563 }
1564
1565 return;
1566 }
1567 \f
1568 /* Print a memory address as an operand to reference that memory location.
1569
1570 This is exactly the same as legitimate_address_p, except that it the prints
1571 addresses instead of recognizing them. */
1572
1573 void
1574 i960_print_operand_addr (file, addr)
1575 FILE *file;
1576 register rtx addr;
1577 {
1578 rtx breg, ireg;
1579 rtx scale, offset;
1580
1581 ireg = 0;
1582 breg = 0;
1583 offset = 0;
1584 scale = const1_rtx;
1585
1586 if (GET_CODE (addr) == REG)
1587 breg = addr;
1588 else if (CONSTANT_P (addr))
1589 offset = addr;
1590 else if (GET_CODE (addr) == PLUS)
1591 {
1592 rtx op0, op1;
1593
1594 op0 = XEXP (addr, 0);
1595 op1 = XEXP (addr, 1);
1596
1597 if (GET_CODE (op0) == REG)
1598 {
1599 breg = op0;
1600 if (GET_CODE (op1) == REG)
1601 ireg = op1;
1602 else if (CONSTANT_P (op1))
1603 offset = op1;
1604 else
1605 abort ();
1606 }
1607 else if (GET_CODE (op0) == PLUS)
1608 {
1609 if (GET_CODE (XEXP (op0, 0)) == MULT)
1610 {
1611 ireg = XEXP (XEXP (op0, 0), 0);
1612 scale = XEXP (XEXP (op0, 0), 1);
1613 if (GET_CODE (XEXP (op0, 1)) == REG)
1614 {
1615 breg = XEXP (op0, 1);
1616 offset = op1;
1617 }
1618 else
1619 abort ();
1620 }
1621 else if (GET_CODE (XEXP (op0, 0)) == REG)
1622 {
1623 breg = XEXP (op0, 0);
1624 if (GET_CODE (XEXP (op0, 1)) == REG)
1625 {
1626 ireg = XEXP (op0, 1);
1627 offset = op1;
1628 }
1629 else
1630 abort ();
1631 }
1632 else
1633 abort ();
1634 }
1635 else if (GET_CODE (op0) == MULT)
1636 {
1637 ireg = XEXP (op0, 0);
1638 scale = XEXP (op0, 1);
1639 if (GET_CODE (op1) == REG)
1640 breg = op1;
1641 else if (CONSTANT_P (op1))
1642 offset = op1;
1643 else
1644 abort ();
1645 }
1646 else
1647 abort ();
1648 }
1649 else if (GET_CODE (addr) == MULT)
1650 {
1651 ireg = XEXP (addr, 0);
1652 scale = XEXP (addr, 1);
1653 }
1654 else
1655 abort ();
1656
1657 if (offset)
1658 output_addr_const (file, offset);
1659 if (breg)
1660 fprintf (file, "(%s)", reg_names[REGNO (breg)]);
1661 if (ireg)
1662 fprintf (file, "[%s*%d]", reg_names[REGNO (ireg)], INTVAL (scale));
1663 }
1664 \f
1665 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
1666 that is a valid memory address for an instruction.
1667 The MODE argument is the machine mode for the MEM expression
1668 that wants to use this address.
1669
1670 On 80960, legitimate addresses are:
1671 base ld (g0),r0
1672 disp (12 or 32 bit) ld foo,r0
1673 base + index ld (g0)[g1*1],r0
1674 base + displ ld 0xf00(g0),r0
1675 base + index*scale + displ ld 0xf00(g0)[g1*4],r0
1676 index*scale + base ld (g0)[g1*4],r0
1677 index*scale + displ ld 0xf00[g1*4],r0
1678 index*scale ld [g1*4],r0
1679 index + base + displ ld 0xf00(g0)[g1*1],r0
1680
1681 In each case, scale can be 1, 2, 4, 8, or 16. */
1682
1683 /* This is exactly the same as i960_print_operand_addr, except that
1684 it recognizes addresses instead of printing them.
1685
1686 It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should
1687 convert common non-canonical forms to canonical form so that they will
1688 be recognized. */
1689
1690 /* These two macros allow us to accept either a REG or a SUBREG anyplace
1691 where a register is valid. */
1692
1693 #define RTX_OK_FOR_BASE_P(X, STRICT) \
1694 ((GET_CODE (X) == REG \
1695 && (STRICT ? REG_OK_FOR_BASE_P_STRICT (X) : REG_OK_FOR_BASE_P (X))) \
1696 || (GET_CODE (X) == SUBREG \
1697 && GET_CODE (SUBREG_REG (X)) == REG \
1698 && (STRICT ? REG_OK_FOR_BASE_P_STRICT (SUBREG_REG (X)) \
1699 : REG_OK_FOR_BASE_P (SUBREG_REG (X)))))
1700
1701 #define RTX_OK_FOR_INDEX_P(X, STRICT) \
1702 ((GET_CODE (X) == REG \
1703 && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (X) : REG_OK_FOR_INDEX_P (X)))\
1704 || (GET_CODE (X) == SUBREG \
1705 && GET_CODE (SUBREG_REG (X)) == REG \
1706 && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (SUBREG_REG (X)) \
1707 : REG_OK_FOR_INDEX_P (SUBREG_REG (X)))))
1708
1709 int
1710 legitimate_address_p (mode, addr, strict)
1711 enum machine_mode mode;
1712 register rtx addr;
1713 int strict;
1714 {
1715 if (RTX_OK_FOR_BASE_P (addr, strict))
1716 return 1;
1717 else if (CONSTANT_P (addr))
1718 return 1;
1719 else if (GET_CODE (addr) == PLUS)
1720 {
1721 rtx op0, op1;
1722
1723 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1724 return 0;
1725
1726 op0 = XEXP (addr, 0);
1727 op1 = XEXP (addr, 1);
1728
1729 if (RTX_OK_FOR_BASE_P (op0, strict))
1730 {
1731 if (RTX_OK_FOR_INDEX_P (op1, strict))
1732 return 1;
1733 else if (CONSTANT_P (op1))
1734 return 1;
1735 else
1736 return 0;
1737 }
1738 else if (GET_CODE (op0) == PLUS)
1739 {
1740 if (GET_CODE (XEXP (op0, 0)) == MULT)
1741 {
1742 if (! (RTX_OK_FOR_INDEX_P (XEXP (XEXP (op0, 0), 0), strict)
1743 && SCALE_TERM_P (XEXP (XEXP (op0, 0), 1))))
1744 return 0;
1745
1746 if (RTX_OK_FOR_BASE_P (XEXP (op0, 1), strict)
1747 && CONSTANT_P (op1))
1748 return 1;
1749 else
1750 return 0;
1751 }
1752 else if (RTX_OK_FOR_BASE_P (XEXP (op0, 0), strict))
1753 {
1754 if (RTX_OK_FOR_INDEX_P (XEXP (op0, 1), strict)
1755 && CONSTANT_P (op1))
1756 return 1;
1757 else
1758 return 0;
1759 }
1760 else
1761 return 0;
1762 }
1763 else if (GET_CODE (op0) == MULT)
1764 {
1765 if (! (RTX_OK_FOR_INDEX_P (XEXP (op0, 0), strict)
1766 && SCALE_TERM_P (XEXP (op0, 1))))
1767 return 0;
1768
1769 if (RTX_OK_FOR_BASE_P (op1, strict))
1770 return 1;
1771 else if (CONSTANT_P (op1))
1772 return 1;
1773 else
1774 return 0;
1775 }
1776 else
1777 return 0;
1778 }
1779 else if (GET_CODE (addr) == MULT)
1780 {
1781 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1782 return 0;
1783
1784 return (RTX_OK_FOR_INDEX_P (XEXP (addr, 0), strict)
1785 && SCALE_TERM_P (XEXP (addr, 1)));
1786 }
1787 else
1788 return 0;
1789 }
1790
1791 /* Try machine-dependent ways of modifying an illegitimate address
1792 to be legitimate. If we find one, return the new, valid address.
1793 This macro is used in only one place: `memory_address' in explow.c.
1794
1795 This converts some non-canonical addresses to canonical form so they
1796 can be recognized. */
1797
1798 rtx
1799 legitimize_address (x, oldx, mode)
1800 register rtx x;
1801 register rtx oldx;
1802 enum machine_mode mode;
1803 {
1804 if (GET_CODE (x) == SYMBOL_REF)
1805 {
1806 abort ();
1807 x = copy_to_reg (x);
1808 }
1809
1810 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1811 return x;
1812
1813 /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
1814 into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be
1815 created by virtual register instantiation, register elimination, and
1816 similar optimizations. */
1817 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1818 && GET_CODE (XEXP (x, 1)) == PLUS)
1819 x = gen_rtx (PLUS, Pmode,
1820 gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)),
1821 XEXP (XEXP (x, 1), 1));
1822
1823 /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
1824 into (plus (plus (mult (reg) (const)) (reg)) (const)). */
1825 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
1826 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1827 && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
1828 && CONSTANT_P (XEXP (x, 1)))
1829 {
1830 rtx constant, other;
1831
1832 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1833 {
1834 constant = XEXP (x, 1);
1835 other = XEXP (XEXP (XEXP (x, 0), 1), 1);
1836 }
1837 else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
1838 {
1839 constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
1840 other = XEXP (x, 1);
1841 }
1842 else
1843 constant = 0;
1844
1845 if (constant)
1846 x = gen_rtx (PLUS, Pmode,
1847 gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
1848 XEXP (XEXP (XEXP (x, 0), 1), 0)),
1849 plus_constant (other, INTVAL (constant)));
1850 }
1851
1852 return x;
1853 }
1854 \f
1855 #if 0
1856 /* Return the most stringent alignment that we are willing to consider
1857 objects of size SIZE and known alignment ALIGN as having. */
1858
1859 int
1860 i960_alignment (size, align)
1861 int size;
1862 int align;
1863 {
1864 int i;
1865
1866 if (! TARGET_STRICT_ALIGN)
1867 if (TARGET_IC_COMPAT2_0 || align >= 4)
1868 {
1869 i = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
1870 if (i > align)
1871 align = i;
1872 }
1873
1874 return align;
1875 }
1876 #endif
1877 \f
1878 /* Modes for condition codes. */
1879 #define C_MODES \
1880 ((1 << (int) CCmode) | (1 << (int) CC_UNSmode) | (1<< (int) CC_CHKmode))
1881
1882 /* Modes for single-word (and smaller) quantities. */
1883 #define S_MODES \
1884 (~C_MODES \
1885 & ~ ((1 << (int) DImode) | (1 << (int) TImode) \
1886 | (1 << (int) DFmode) | (1 << (int) XFmode)))
1887
1888 /* Modes for double-word (and smaller) quantities. */
1889 #define D_MODES \
1890 (~C_MODES \
1891 & ~ ((1 << (int) TImode) | (1 << (int) XFmode)))
1892
1893 /* Modes for quad-word quantities. */
1894 #define T_MODES (~C_MODES)
1895
1896 /* Modes for single-float quantities. */
1897 #define SF_MODES ((1 << (int) SFmode))
1898
1899 /* Modes for double-float quantities. */
1900 #define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode))
1901
1902 /* Modes for quad-float quantities. */
1903 #define XF_MODES (DF_MODES | (1 << (int) XFmode) | (1 << (int) DCmode))
1904
1905 unsigned int hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] = {
1906 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1907 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1908 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1909 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1910
1911 XF_MODES, XF_MODES, XF_MODES, XF_MODES, C_MODES};
1912
1913 \f
1914 /* Return the minimum alignment of an expression rtx X in bytes. This takes
1915 advantage of machine specific facts, such as knowing that the frame pointer
1916 is always 16 byte aligned. */
1917
1918 int
1919 i960_expr_alignment (x, size)
1920 rtx x;
1921 int size;
1922 {
1923 int align = 1;
1924
1925 if (x == 0)
1926 return 1;
1927
1928 switch (GET_CODE(x))
1929 {
1930 case CONST_INT:
1931 align = INTVAL(x);
1932
1933 if ((align & 0xf) == 0)
1934 align = 16;
1935 else if ((align & 0x7) == 0)
1936 align = 8;
1937 else if ((align & 0x3) == 0)
1938 align = 4;
1939 else if ((align & 0x1) == 0)
1940 align = 2;
1941 else
1942 align = 1;
1943 break;
1944
1945 case PLUS:
1946 align = MIN (i960_expr_alignment (XEXP (x, 0), size),
1947 i960_expr_alignment (XEXP (x, 1), size));
1948 break;
1949
1950 case SYMBOL_REF:
1951 /* If this is a valid program, objects are guaranteed to be
1952 correctly aligned for whatever size the reference actually is. */
1953 align = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
1954 break;
1955
1956 case REG:
1957 if (REGNO (x) == FRAME_POINTER_REGNUM)
1958 align = 16;
1959 break;
1960
1961 case ASHIFT:
1962 align = i960_expr_alignment (XEXP (x, 0));
1963
1964 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1965 {
1966 align = align << INTVAL (XEXP (x, 1));
1967 align = MIN (align, 16);
1968 }
1969 break;
1970
1971 case MULT:
1972 align = (i960_expr_alignment (XEXP (x, 0), size) *
1973 i960_expr_alignment (XEXP (x, 1), size));
1974
1975 align = MIN (align, 16);
1976 break;
1977 }
1978
1979 return align;
1980 }
1981
1982 /* Return true if it is possible to reference both BASE and OFFSET, which
1983 have alignment at least as great as 4 byte, as if they had alignment valid
1984 for an object of size SIZE. */
1985
1986 int
1987 i960_improve_align (base, offset, size)
1988 rtx base;
1989 rtx offset;
1990 int size;
1991 {
1992 int i, j;
1993
1994 /* We have at least a word reference to the object, so we know it has to
1995 be aligned at least to 4 bytes. */
1996
1997 i = MIN (i960_expr_alignment (base, 4),
1998 i960_expr_alignment (offset, 4));
1999
2000 i = MAX (i, 4);
2001
2002 /* We know the size of the request. If strict align is not enabled, we
2003 can guess that the alignment is OK for the requested size. */
2004
2005 if (! TARGET_STRICT_ALIGN)
2006 if ((j = (i960_object_bytes_bitalign (size) / BITS_PER_UNIT)) > i)
2007 i = j;
2008
2009 return (i >= size);
2010 }
2011
2012 /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
2013 (SImode) alignment as if they had 16 byte (TImode) alignment. */
2014
2015 int
2016 i960_si_ti (base, offset)
2017 rtx base;
2018 rtx offset;
2019 {
2020 return i960_improve_align (base, offset, 16);
2021 }
2022
2023 /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
2024 (SImode) alignment as if they had 8 byte (DImode) alignment. */
2025
2026 int
2027 i960_si_di (base, offset)
2028 rtx base;
2029 rtx offset;
2030 {
2031 return i960_improve_align (base, offset, 8);
2032 }
2033 \f
2034 /* Return raw values of size and alignment (in words) for the data
2035 type being accessed. These values will be rounded by the caller. */
2036
2037 static void
2038 i960_arg_size_and_align (mode, type, size_out, align_out)
2039 enum machine_mode mode;
2040 tree type;
2041 int *size_out;
2042 int *align_out;
2043 {
2044 int size, align;
2045
2046 /* Use formal alignment requirements of type being passed, except make
2047 it at least a word. If we don't have a type, this is a library call,
2048 and the parm has to be of scalar type. In this case, consider its
2049 formal alignment requirement to be its size in words. */
2050
2051 if (mode == BLKmode)
2052 size = (int_size_in_bytes (type) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2053 else if (mode == VOIDmode)
2054 {
2055 /* End of parm list. */
2056 assert (type != 0 && TYPE_MODE (type) == VOIDmode);
2057 size = 1;
2058 }
2059 else
2060 size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2061
2062 if (type == 0)
2063 {
2064 /* ??? This is a hack to properly correct the alignment of XFmode
2065 values without affecting anything else. */
2066 if (size == 3)
2067 align = 4;
2068 else
2069 align = size;
2070 }
2071 else if (TYPE_ALIGN (type) >= BITS_PER_WORD)
2072 align = TYPE_ALIGN (type) / BITS_PER_WORD;
2073 else
2074 align = 1;
2075
2076 *size_out = size;
2077 *align_out = align;
2078 }
2079
2080 /* On the 80960 the first 12 args are in registers and the rest are pushed.
2081 Any arg that is bigger than 4 words is placed on the stack and all
2082 subsequent arguments are placed on the stack.
2083
2084 Additionally, parameters with an alignment requirement stronger than
2085 a word must be aligned appropriately. Note that this means that a
2086 64 bit object with a 32 bit alignment is not 64 bit aligned and may be
2087 passed in an odd/even register pair. */
2088
2089 /* Update CUM to advance past an argument described by MODE and TYPE. */
2090
2091 void
2092 i960_function_arg_advance (cum, mode, type, named)
2093 CUMULATIVE_ARGS *cum;
2094 enum machine_mode mode;
2095 tree type;
2096 int named;
2097 {
2098 int size, align;
2099
2100 i960_arg_size_and_align (mode, type, &size, &align);
2101
2102 if (size > 4 || cum->ca_nstackparms != 0
2103 || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS
2104 || MUST_PASS_IN_STACK (mode, type))
2105 {
2106 /* Indicate that all the registers are in use, even if all are not,
2107 so va_start will compute the right value. */
2108 cum->ca_nregparms = NPARM_REGS;
2109 cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align) + size;
2110 }
2111 else
2112 cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align) + size;
2113 }
2114
2115 /* Return the register that the argument described by MODE and TYPE is
2116 passed in, or else return 0 if it is passed on the stack. */
2117
2118 rtx
2119 i960_function_arg (cum, mode, type, named)
2120 CUMULATIVE_ARGS *cum;
2121 enum machine_mode mode;
2122 tree type;
2123 int named;
2124 {
2125 rtx ret;
2126 int size, align;
2127
2128 i960_arg_size_and_align (mode, type, &size, &align);
2129
2130 if (size > 4 || cum->ca_nstackparms != 0
2131 || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS
2132 || MUST_PASS_IN_STACK (mode, type))
2133 {
2134 cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align);
2135 ret = 0;
2136 }
2137 else
2138 {
2139 cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align);
2140 ret = gen_rtx (REG, mode, cum->ca_nregparms);
2141 }
2142
2143 return ret;
2144 }
2145 \f
2146 /* Floating-point support. */
2147
2148 void
2149 i960_output_long_double (file, value)
2150 FILE *file;
2151 REAL_VALUE_TYPE value;
2152 {
2153 long value_long[3];
2154 char dstr[30];
2155
2156 REAL_VALUE_TO_TARGET_LONG_DOUBLE (value, value_long);
2157 REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr);
2158
2159 fprintf (file,
2160 "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n\t.word\t0x%08lx\n",
2161 value_long[0], dstr, value_long[1], value_long[2]);
2162 fprintf (file, "\t.word\t0x0\n");
2163 }
2164
2165 void
2166 i960_output_double (file, value)
2167 FILE *file;
2168 REAL_VALUE_TYPE value;
2169 {
2170 long value_long[2];
2171 char dstr[30];
2172
2173 REAL_VALUE_TO_TARGET_DOUBLE (value, value_long);
2174 REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr);
2175
2176 fprintf (file, "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n",
2177 value_long[0], dstr, value_long[1]);
2178 }
2179
2180 void
2181 i960_output_float (file, value)
2182 FILE *file;
2183 REAL_VALUE_TYPE value;
2184 {
2185 long value_long;
2186 char dstr[30];
2187
2188 REAL_VALUE_TO_TARGET_SINGLE (value, value_long);
2189 REAL_VALUE_TO_DECIMAL (value, "%.12g", dstr);
2190
2191 fprintf (file, "\t.word\t0x%08lx\t\t# %s (float)\n", value_long, dstr);
2192 }
2193 \f
2194 /* Return the number of bits that an object of size N bytes is aligned to. */
2195
2196 int
2197 i960_object_bytes_bitalign (n)
2198 int n;
2199 {
2200 if (n > 8) n = 128;
2201 else if (n > 4) n = 64;
2202 else if (n > 2) n = 32;
2203 else if (n > 1) n = 16;
2204 else n = 8;
2205
2206 return n;
2207 }
2208
2209 /* Compute the alignment for an aggregate type TSIZE.
2210 Alignment is MAX (greatest member alignment,
2211 MIN (pragma align, structure size alignment)). */
2212
2213 int
2214 i960_round_align (align, tsize)
2215 int align;
2216 tree tsize;
2217 {
2218 int new_align;
2219
2220 if (TREE_CODE (tsize) != INTEGER_CST)
2221 return align;
2222
2223 new_align = i960_object_bytes_bitalign (TREE_INT_CST_LOW (tsize)
2224 / BITS_PER_UNIT);
2225 /* Handle #pragma align. */
2226 if (new_align > i960_maxbitalignment)
2227 new_align = i960_maxbitalignment;
2228
2229 if (align < new_align)
2230 align = new_align;
2231
2232 return align;
2233 }
2234 \f
2235 /* Do any needed setup for a varargs function. For the i960, we must
2236 create a register parameter block if one doesn't exist, and then copy
2237 all register parameters to memory. */
2238
2239 void
2240 i960_setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2241 CUMULATIVE_ARGS *cum;
2242 enum machine_mode mode;
2243 tree type;
2244 int *pretend_size;
2245 int no_rtl;
2246 {
2247 /* Note: for a varargs fn with only a va_alist argument, this is 0. */
2248 int first_reg = cum->ca_nregparms;
2249
2250 /* Copy only unnamed register arguments to memory. If there are
2251 any stack parms, there are no unnamed arguments in registers, and
2252 an argument block was already allocated by the caller.
2253 Remember that any arg bigger than 4 words is passed on the stack as
2254 are all subsequent args.
2255
2256 If there are no stack arguments but there are exactly NPARM_REGS
2257 registers, either there were no extra arguments or the caller
2258 allocated an argument block. */
2259
2260 if (cum->ca_nstackparms == 0 && first_reg < NPARM_REGS && !no_rtl)
2261 {
2262 rtx label = gen_label_rtx ();
2263 rtx regblock;
2264
2265 /* If arg_pointer_rtx == 0, no arguments were passed on the stack
2266 and we need to allocate a chunk to save the registers (if any
2267 arguments were passed on the stack the caller would allocate the
2268 48 bytes as well). We must allocate all 48 bytes (12*4) because
2269 va_start assumes it. */
2270 emit_insn (gen_cmpsi (arg_pointer_rtx, const0_rtx));
2271 emit_jump_insn (gen_bne (label));
2272 emit_insn (gen_rtx (SET, VOIDmode, arg_pointer_rtx,
2273 stack_pointer_rtx));
2274 emit_insn (gen_rtx (SET, VOIDmode, stack_pointer_rtx,
2275 memory_address (SImode,
2276 plus_constant (stack_pointer_rtx,
2277 48))));
2278 emit_label (label);
2279
2280 /* ??? Note that we unnecessarily store one extra register for stdarg
2281 fns. We could optimize this, but it's kept as for now. */
2282 regblock = gen_rtx (MEM, BLKmode,
2283 plus_constant (arg_pointer_rtx,
2284 first_reg * 4));
2285 move_block_from_reg (first_reg, regblock,
2286 NPARM_REGS - first_reg,
2287 (NPARM_REGS - first_reg) * UNITS_PER_WORD);
2288 }
2289 }
2290
2291 /* Calculate the final size of the reg parm stack space for the current
2292 function, based on how many bytes would be allocated on the stack. */
2293
2294 int
2295 i960_final_reg_parm_stack_space (const_size, var_size)
2296 int const_size;
2297 tree var_size;
2298 {
2299 if (var_size || const_size > 48)
2300 return 48;
2301 else
2302 return 0;
2303 }
2304
2305 /* Calculate the size of the reg parm stack space. This is a bit complicated
2306 on the i960. */
2307
2308 int
2309 i960_reg_parm_stack_space (fndecl)
2310 tree fndecl;
2311 {
2312 /* In this case, we are called from emit_library_call, and we don't need
2313 to pretend we have more space for parameters than what's apparent. */
2314 if (fndecl == 0)
2315 return 0;
2316
2317 /* In this case, we are called from locate_and_pad_parms when we're
2318 not IN_REGS, so we have an arg block. */
2319 if (fndecl != current_function_decl)
2320 return 48;
2321
2322 /* Otherwise, we have an arg block if the current function has more than
2323 48 bytes of parameters. */
2324 if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl))
2325 return 48;
2326 else
2327 return 0;
2328 }
2329 \f
2330 /* Return the register class of a scratch register needed to copy IN into
2331 or out of a register in CLASS in MODE. If it can be done directly,
2332 NO_REGS is returned. */
2333
2334 enum reg_class
2335 secondary_reload_class (class, mode, in)
2336 enum reg_class class;
2337 enum machine_mode mode;
2338 rtx in;
2339 {
2340 int regno = -1;
2341
2342 if (GET_CODE (in) == REG || GET_CODE (in) == SUBREG)
2343 regno = true_regnum (in);
2344
2345 /* We can place anything into LOCAL_OR_GLOBAL_REGS and can put
2346 LOCAL_OR_GLOBAL_REGS into anything. */
2347 if (class == LOCAL_OR_GLOBAL_REGS || class == LOCAL_REGS
2348 || class == GLOBAL_REGS || (regno >= 0 && regno < 32))
2349 return NO_REGS;
2350
2351 /* We can place any hard register, 0.0, and 1.0 into FP_REGS. */
2352 if (class == FP_REGS
2353 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
2354 || in == CONST0_RTX (mode) || in == CONST1_RTX (mode)))
2355 return NO_REGS;
2356
2357 return LOCAL_OR_GLOBAL_REGS;
2358 }
2359 \f
2360 /* Look at the opcode P, and set i96_last_insn_type to indicate which
2361 function unit it executed on. */
2362
2363 /* ??? This would make more sense as an attribute. */
2364
2365 void
2366 i960_scan_opcode (p)
2367 char *p;
2368 {
2369 switch (*p)
2370 {
2371 case 'a':
2372 case 'd':
2373 case 'e':
2374 case 'm':
2375 case 'n':
2376 case 'o':
2377 case 'r':
2378 /* Ret is not actually of type REG, but it won't matter, because no
2379 insn will ever follow it. */
2380 case 'u':
2381 case 'x':
2382 i960_last_insn_type = I_TYPE_REG;
2383 break;
2384
2385 case 'b':
2386 if (p[1] == 'x' || p[3] == 'x')
2387 i960_last_insn_type = I_TYPE_MEM;
2388 i960_last_insn_type = I_TYPE_CTRL;
2389 break;
2390
2391 case 'f':
2392 case 't':
2393 i960_last_insn_type = I_TYPE_CTRL;
2394 break;
2395
2396 case 'c':
2397 if (p[1] == 'a')
2398 {
2399 if (p[4] == 'x')
2400 i960_last_insn_type = I_TYPE_MEM;
2401 else
2402 i960_last_insn_type = I_TYPE_CTRL;
2403 }
2404 else if (p[1] == 'm')
2405 {
2406 if (p[3] == 'd')
2407 i960_last_insn_type = I_TYPE_REG;
2408 else if (p[4] == 'b' || p[4] == 'j')
2409 i960_last_insn_type = I_TYPE_CTRL;
2410 else
2411 i960_last_insn_type = I_TYPE_REG;
2412 }
2413 else
2414 i960_last_insn_type = I_TYPE_REG;
2415 break;
2416
2417 case 'l':
2418 i960_last_insn_type = I_TYPE_MEM;
2419 break;
2420
2421 case 's':
2422 if (p[1] == 't')
2423 i960_last_insn_type = I_TYPE_MEM;
2424 else
2425 i960_last_insn_type = I_TYPE_REG;
2426 break;
2427 }
2428 }