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