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