OSDN Git Service

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