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