hooks.h (hook_bool_const_int_const_int_true): Declare.
[platform/upstream/gcc.git] / gcc / config / fr30 / fr30.c
1 /* FR30 specific functions.
2    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009
3    Free Software Foundation, Inc.
4    Contributed by Cygnus Solutions.
5
6    This file is part of GCC.
7
8    GCC is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3, or (at your option)
11    any later version.
12
13    GCC is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GCC; see the file COPYING3.  If not see
20    <http://www.gnu.org/licenses/>.  */
21
22 /*{{{  Includes */ 
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "insn-attr.h"
35 #include "flags.h"
36 #include "recog.h"
37 #include "tree.h"
38 #include "output.h"
39 #include "expr.h"
40 #include "obstack.h"
41 #include "except.h"
42 #include "function.h"
43 #include "toplev.h"
44 #include "tm_p.h"
45 #include "target.h"
46 #include "target-def.h"
47
48 /*}}}*/
49 /*{{{  Function Prologues & Epilogues */ 
50
51 /* The FR30 stack looks like this:
52
53              Before call                       After call
54    FP ->|                       |       |                       |
55         +-----------------------+       +-----------------------+       high 
56         |                       |       |                       |       memory
57         |  local variables,     |       |  local variables,     |
58         |  reg save area, etc.  |       |  reg save area, etc.  |
59         |                       |       |                       |
60         +-----------------------+       +-----------------------+
61         |                       |       |                       |
62         | args to the func that |       |  args to this func.   |
63         | is being called that  |       |                       |
64    SP ->| do not fit in regs    |       |                       |
65         +-----------------------+       +-----------------------+
66                                         |  args that used to be |  \
67                                         | in regs; only created |   |  pretend_size 
68                                    AP-> |   for vararg funcs    |  /  
69                                         +-----------------------+    
70                                         |                       |  \  
71                                         |  register save area   |   |
72                                         |                       |   |
73                                         +-----------------------+   |  reg_size
74                                         |    return address     |   | 
75                                         +-----------------------+   |
76                                    FP ->|   previous frame ptr  |  /
77                                         +-----------------------+    
78                                         |                       |  \   
79                                         |  local variables      |   |  var_size 
80                                         |                       |  /  
81                                         +-----------------------+    
82                                         |                       |  \       
83      low                                |  room for args to     |   |
84      memory                             |  other funcs called   |   |  args_size     
85                                         |  from this one        |   |
86                                    SP ->|                       |  /  
87                                         +-----------------------+    
88    
89    Note, AP is a fake hard register.  It will be eliminated in favor of
90    SP or FP as appropriate.
91
92    Note, Some or all of the stack sections above may be omitted if they 
93    are not needed.  */
94
95 /* Structure to be filled in by fr30_compute_frame_size() with register
96    save masks, and offsets for the current function.  */
97 struct fr30_frame_info
98 {
99   unsigned int total_size;      /* # Bytes that the entire frame takes up.  */
100   unsigned int pretend_size;    /* # Bytes we push and pretend caller did.  */
101   unsigned int args_size;       /* # Bytes that outgoing arguments take up.  */
102   unsigned int reg_size;        /* # Bytes needed to store regs.  */
103   unsigned int var_size;        /* # Bytes that variables take up.  */
104   unsigned int frame_size;      /* # Bytes in current frame.  */
105   unsigned int gmask;           /* Mask of saved registers.  */
106   unsigned int save_fp;         /* Nonzero if frame pointer must be saved.  */
107   unsigned int save_rp;         /* Nonzero if return pointer must be saved.  */
108   int          initialised;     /* Nonzero if frame size already calculated.  */
109 };
110
111 /* Current frame information calculated by fr30_compute_frame_size().  */
112 static struct fr30_frame_info   current_frame_info;
113
114 /* Zero structure to initialize current_frame_info.  */
115 static struct fr30_frame_info   zero_frame_info;
116
117 static void fr30_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
118                                          tree, int *, int);
119 static bool fr30_must_pass_in_stack (enum machine_mode, const_tree);
120 static int fr30_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
121                                    tree, bool);
122 static bool fr30_frame_pointer_required (void);
123 static bool fr30_can_eliminate (const int, const int);
124
125 #define FRAME_POINTER_MASK      (1 << (FRAME_POINTER_REGNUM))
126 #define RETURN_POINTER_MASK     (1 << (RETURN_POINTER_REGNUM))
127
128 /* Tell prologue and epilogue if register REGNO should be saved / restored.
129    The return address and frame pointer are treated separately.
130    Don't consider them here.  */
131 #define MUST_SAVE_REGISTER(regno)      \
132   (   (regno) != RETURN_POINTER_REGNUM \
133    && (regno) != FRAME_POINTER_REGNUM  \
134    && df_regs_ever_live_p (regno)      \
135    && ! call_used_regs [regno]         )
136
137 #define MUST_SAVE_FRAME_POINTER  (df_regs_ever_live_p (FRAME_POINTER_REGNUM)  || frame_pointer_needed)
138 #define MUST_SAVE_RETURN_POINTER (df_regs_ever_live_p (RETURN_POINTER_REGNUM) || crtl->profile)
139
140 #if UNITS_PER_WORD == 4
141 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
142 #endif
143 \f
144 /* Initialize the GCC target structure.  */
145 #undef  TARGET_ASM_ALIGNED_HI_OP
146 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
147 #undef  TARGET_ASM_ALIGNED_SI_OP
148 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
149
150 #undef  TARGET_PROMOTE_PROTOTYPES
151 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
152 #undef  TARGET_PASS_BY_REFERENCE
153 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
154 #undef  TARGET_ARG_PARTIAL_BYTES
155 #define TARGET_ARG_PARTIAL_BYTES fr30_arg_partial_bytes
156
157 #undef  TARGET_SETUP_INCOMING_VARARGS
158 #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
159 #undef  TARGET_MUST_PASS_IN_STACK
160 #define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
161
162 #undef TARGET_FRAME_POINTER_REQUIRED
163 #define TARGET_FRAME_POINTER_REQUIRED fr30_frame_pointer_required
164
165 #undef TARGET_CAN_ELIMINATE
166 #define TARGET_CAN_ELIMINATE fr30_can_eliminate
167
168 struct gcc_target targetm = TARGET_INITIALIZER;
169 \f
170
171 /* Worker function for TARGET_CAN_ELIMINATE.  */
172
173 bool
174 fr30_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
175 {
176   return (to == FRAME_POINTER_REGNUM || ! frame_pointer_needed);
177 }
178
179 /* Returns the number of bytes offset between FROM_REG and TO_REG
180    for the current function.  As a side effect it fills in the 
181    current_frame_info structure, if the data is available.  */
182 unsigned int
183 fr30_compute_frame_size (int from_reg, int to_reg)
184 {
185   int           regno;
186   unsigned int  return_value;
187   unsigned int  var_size;
188   unsigned int  args_size;
189   unsigned int  pretend_size;
190   unsigned int  reg_size;
191   unsigned int  gmask;
192
193   var_size      = WORD_ALIGN (get_frame_size ());
194   args_size     = WORD_ALIGN (crtl->outgoing_args_size);
195   pretend_size  = crtl->args.pretend_args_size;
196
197   reg_size      = 0;
198   gmask         = 0;
199
200   /* Calculate space needed for registers.  */
201   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
202     {
203       if (MUST_SAVE_REGISTER (regno))
204         {
205           reg_size += UNITS_PER_WORD;
206           gmask |= 1 << regno;
207         }
208     }
209
210   current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
211   current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
212
213   reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
214                * UNITS_PER_WORD;
215
216   /* Save computed information.  */
217   current_frame_info.pretend_size = pretend_size;
218   current_frame_info.var_size     = var_size;
219   current_frame_info.args_size    = args_size;
220   current_frame_info.reg_size     = reg_size;
221   current_frame_info.frame_size   = args_size + var_size;
222   current_frame_info.total_size   = args_size + var_size + reg_size + pretend_size;
223   current_frame_info.gmask        = gmask;
224   current_frame_info.initialised  = reload_completed;
225
226   /* Calculate the required distance.  */
227   return_value = 0;
228   
229   if (to_reg == STACK_POINTER_REGNUM)
230     return_value += args_size + var_size;
231   
232   if (from_reg == ARG_POINTER_REGNUM)
233     return_value += reg_size;
234
235   return return_value;
236 }
237
238 /* Called after register allocation to add any instructions needed for the
239    prologue.  Using a prologue insn is favored compared to putting all of the
240    instructions in output_function_prologue(), since it allows the scheduler
241    to intermix instructions with the saves of the caller saved registers.  In
242    some cases, it might be necessary to emit a barrier instruction as the last
243    insn to prevent such scheduling.  */
244
245 void
246 fr30_expand_prologue (void)
247 {
248   int regno;
249   rtx insn;
250
251   if (! current_frame_info.initialised)
252     fr30_compute_frame_size (0, 0);
253
254   /* This cases shouldn't happen.  Catch it now.  */
255   gcc_assert (current_frame_info.total_size || !current_frame_info.gmask);
256
257   /* Allocate space for register arguments if this is a variadic function.  */
258   if (current_frame_info.pretend_size)
259     {
260       int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
261       
262       /* Push argument registers into the pretend arg area.  */
263       for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
264         {
265           insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
266           RTX_FRAME_RELATED_P (insn) = 1;
267         }
268     }
269
270   if (current_frame_info.gmask)
271     {
272       /* Save any needed call-saved regs.  */
273       for (regno = STACK_POINTER_REGNUM; regno--;)
274         {
275           if ((current_frame_info.gmask & (1 << regno)) != 0)
276             {
277               insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
278               RTX_FRAME_RELATED_P (insn) = 1;
279             }
280         }
281     }
282
283   /* Save return address if necessary.  */
284   if (current_frame_info.save_rp)
285     {
286       insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, 
287                                                      RETURN_POINTER_REGNUM)));
288       RTX_FRAME_RELATED_P (insn) = 1;
289     }
290
291   /* Save old frame pointer and create new one, if necessary.  */
292   if (current_frame_info.save_fp)
293     {
294       if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
295         {
296           int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
297           rtx pattern;
298           
299           insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
300           RTX_FRAME_RELATED_P (insn) = 1;
301           
302           pattern = PATTERN (insn);
303           
304           /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
305           if (GET_CODE (pattern) == PARALLEL)
306             {
307               int x;
308               for (x = XVECLEN (pattern, 0); x--;)
309                 {
310                   rtx part = XVECEXP (pattern, 0, x);
311                   
312                   /* One of the insns in the ENTER pattern updates the
313                      frame pointer.  If we do not actually need the frame
314                      pointer in this function then this is a side effect
315                      rather than a desired effect, so we do not mark that
316                      insn as being related to the frame set up.  Doing this
317                      allows us to compile the crash66.C test file in the
318                      G++ testsuite.  */
319                   if (! frame_pointer_needed
320                       && GET_CODE (part) == SET
321                       && SET_DEST (part) == hard_frame_pointer_rtx)
322                     RTX_FRAME_RELATED_P (part) = 0;
323                   else
324                     RTX_FRAME_RELATED_P (part) = 1;
325                 }
326             }
327         }
328       else
329         {
330           insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
331           RTX_FRAME_RELATED_P (insn) = 1;
332
333           if (frame_pointer_needed)
334             {
335               insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
336               RTX_FRAME_RELATED_P (insn) = 1;
337             }
338         }
339     }
340
341   /* Allocate the stack frame.  */
342   if (current_frame_info.frame_size == 0)
343     ; /* Nothing to do.  */
344   else if (current_frame_info.save_fp
345            && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
346     ; /* Nothing to do.  */
347   else if (current_frame_info.frame_size <= 512)
348     {
349       insn = emit_insn (gen_add_to_stack
350                          (GEN_INT (- (signed) current_frame_info.frame_size)));
351       RTX_FRAME_RELATED_P (insn) = 1;
352     }
353   else
354     {
355       rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
356       insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
357       RTX_FRAME_RELATED_P (insn) = 1;
358       insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
359       RTX_FRAME_RELATED_P (insn) = 1;
360     }
361
362   if (crtl->profile)
363     emit_insn (gen_blockage ());
364 }
365
366 /* Called after register allocation to add any instructions needed for the
367    epilogue.  Using an epilogue insn is favored compared to putting all of the
368    instructions in output_function_epilogue(), since it allows the scheduler
369    to intermix instructions with the restores of the caller saved registers.
370    In some cases, it might be necessary to emit a barrier instruction as the
371    first insn to prevent such scheduling.  */
372 void
373 fr30_expand_epilogue (void)
374 {
375   int regno;
376
377   /* Perform the inversion operations of the prologue.  */
378   gcc_assert (current_frame_info.initialised);
379   
380   /* Pop local variables and arguments off the stack.
381      If frame_pointer_needed is TRUE then the frame pointer register
382      has actually been used as a frame pointer, and we can recover
383      the stack pointer from it, otherwise we must unwind the stack
384      manually.  */
385   if (current_frame_info.frame_size > 0)
386     {
387       if (current_frame_info.save_fp && frame_pointer_needed)
388         {
389           emit_insn (gen_leave_func ());
390           current_frame_info.save_fp = 0;
391         }
392       else if (current_frame_info.frame_size <= 508)
393         emit_insn (gen_add_to_stack
394                    (GEN_INT (current_frame_info.frame_size)));
395       else
396         {
397           rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
398           emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
399           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
400         }
401     }
402   
403   if (current_frame_info.save_fp)
404     emit_insn (gen_movsi_pop (frame_pointer_rtx));
405   
406   /* Pop all the registers that were pushed.  */
407   if (current_frame_info.save_rp)
408     emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
409     
410   for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
411     if (current_frame_info.gmask & (1 << regno))
412       emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
413   
414   if (current_frame_info.pretend_size)
415     emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
416
417   /* Reset state info for each function.  */
418   current_frame_info = zero_frame_info;
419
420   emit_jump_insn (gen_return_from_func ());
421 }
422
423 /* Do any needed setup for a variadic function.  We must create a register
424    parameter block, and then copy any anonymous arguments, plus the last
425    named argument, from registers into memory.  * copying actually done in
426    fr30_expand_prologue().
427
428    ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
429    which has type TYPE and mode MODE, and we rely on this fact.  */
430 void
431 fr30_setup_incoming_varargs (CUMULATIVE_ARGS *arg_regs_used_so_far,
432                              enum machine_mode mode,
433                              tree type ATTRIBUTE_UNUSED,
434                              int *pretend_size,
435                              int second_time ATTRIBUTE_UNUSED)
436 {
437   int size;
438
439   /* All BLKmode values are passed by reference.  */
440   gcc_assert (mode != BLKmode);
441
442   /* ??? This run-time test as well as the code inside the if
443      statement is probably unnecessary.  */
444   if (targetm.calls.strict_argument_naming (arg_regs_used_so_far))
445     /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
446        arg must not be treated as an anonymous arg.  */
447     arg_regs_used_so_far += fr30_num_arg_regs (mode, type);
448
449   size = FR30_NUM_ARG_REGS - (* arg_regs_used_so_far);
450
451   if (size <= 0)
452     return;
453
454   * pretend_size = (size * UNITS_PER_WORD);
455 }
456
457 /*}}}*/
458 /*{{{  Printing operands */ 
459
460 /* Print a memory address as an operand to reference that memory location.  */
461
462 void
463 fr30_print_operand_address (FILE *stream, rtx address)
464 {
465   switch (GET_CODE (address))
466     {
467     case SYMBOL_REF:
468       output_addr_const (stream, address);
469       break;
470       
471     default:
472       fprintf (stderr, "code = %x\n", GET_CODE (address));
473       debug_rtx (address);
474       output_operand_lossage ("fr30_print_operand_address: unhandled address");
475       break;
476     }
477 }
478
479 /* Print an operand.  */
480
481 void
482 fr30_print_operand (FILE *file, rtx x, int code)
483 {
484   rtx x0;
485   
486   switch (code)
487     {
488     case '#':
489       /* Output a :D if this instruction is delayed.  */
490       if (dbr_sequence_length () != 0)
491         fputs (":D", file);
492       return;
493       
494     case 'p':
495       /* Compute the register name of the second register in a hi/lo
496          register pair.  */
497       if (GET_CODE (x) != REG)
498         output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
499       else
500         fprintf (file, "r%d", REGNO (x) + 1);
501       return;
502       
503     case 'b':
504       /* Convert GCC's comparison operators into FR30 comparison codes.  */
505       switch (GET_CODE (x))
506         {
507         case EQ:  fprintf (file, "eq"); break;
508         case NE:  fprintf (file, "ne"); break;
509         case LT:  fprintf (file, "lt"); break;
510         case LE:  fprintf (file, "le"); break;
511         case GT:  fprintf (file, "gt"); break;
512         case GE:  fprintf (file, "ge"); break;
513         case LTU: fprintf (file, "c"); break;
514         case LEU: fprintf (file, "ls"); break;
515         case GTU: fprintf (file, "hi"); break;
516         case GEU: fprintf (file, "nc");  break;
517         default:
518           output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
519           break;
520         }
521       return;
522       
523     case 'B':
524       /* Convert GCC's comparison operators into the complimentary FR30
525          comparison codes.  */
526       switch (GET_CODE (x))
527         {
528         case EQ:  fprintf (file, "ne"); break;
529         case NE:  fprintf (file, "eq"); break;
530         case LT:  fprintf (file, "ge"); break;
531         case LE:  fprintf (file, "gt"); break;
532         case GT:  fprintf (file, "le"); break;
533         case GE:  fprintf (file, "lt"); break;
534         case LTU: fprintf (file, "nc"); break;
535         case LEU: fprintf (file, "hi"); break;
536         case GTU: fprintf (file, "ls"); break;
537         case GEU: fprintf (file, "c"); break;
538         default:
539           output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
540           break;
541         }
542       return;
543
544     case 'A':
545       /* Print a signed byte value as an unsigned value.  */
546       if (GET_CODE (x) != CONST_INT)
547         output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
548       else
549         {
550           HOST_WIDE_INT val;
551           
552           val = INTVAL (x);
553
554           val &= 0xff;
555
556           fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
557         }
558       return;
559       
560     case 'x':
561       if (GET_CODE (x) != CONST_INT
562           || INTVAL (x) < 16
563           || INTVAL (x) > 32)
564         output_operand_lossage ("fr30_print_operand: invalid %%x code");
565       else
566         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
567       return;
568
569     case 'F':
570       if (GET_CODE (x) != CONST_DOUBLE)
571         output_operand_lossage ("fr30_print_operand: invalid %%F code");
572       else
573         {
574           char str[30];
575
576           real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
577                            sizeof (str), 0, 1);
578           fputs (str, file);
579         }
580       return;
581       
582     case 0:
583       /* Handled below.  */
584       break;
585       
586     default:
587       fprintf (stderr, "unknown code = %x\n", code);
588       output_operand_lossage ("fr30_print_operand: unknown code");
589       return;
590     }
591
592   switch (GET_CODE (x))
593     {
594     case REG:
595       fputs (reg_names [REGNO (x)], file);
596       break;
597
598     case MEM:
599       x0 = XEXP (x,0);
600       
601       switch (GET_CODE (x0))
602         {
603         case REG:
604           gcc_assert ((unsigned) REGNO (x0) < ARRAY_SIZE (reg_names));
605           fprintf (file, "@%s", reg_names [REGNO (x0)]);
606           break;
607
608         case PLUS:
609           if (GET_CODE (XEXP (x0, 0)) != REG
610               || REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
611               || REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
612               || GET_CODE (XEXP (x0, 1)) != CONST_INT)
613             {
614               fprintf (stderr, "bad INDEXed address:");
615               debug_rtx (x);
616               output_operand_lossage ("fr30_print_operand: unhandled MEM");
617             }
618           else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
619             {
620               HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
621               if (val < -(1 << 9) || val > ((1 << 9) - 4))
622                 {
623                   fprintf (stderr, "frame INDEX out of range:");
624                   debug_rtx (x);
625                   output_operand_lossage ("fr30_print_operand: unhandled MEM");
626                 }
627               fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
628             }
629           else
630             {
631               HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
632               if (val < 0 || val > ((1 << 6) - 4))
633                 {
634                   fprintf (stderr, "stack INDEX out of range:");
635                   debug_rtx (x);
636                   output_operand_lossage ("fr30_print_operand: unhandled MEM");
637                 }
638               fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
639             }
640           break;
641           
642         case SYMBOL_REF:
643           output_address (x0);
644           break;
645           
646         default:
647           fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
648           debug_rtx (x);
649           output_operand_lossage ("fr30_print_operand: unhandled MEM");
650           break;
651         }
652       break;
653       
654     case CONST_DOUBLE :
655       /* We handle SFmode constants here as output_addr_const doesn't.  */
656       if (GET_MODE (x) == SFmode)
657         {
658           REAL_VALUE_TYPE d;
659           long l;
660
661           REAL_VALUE_FROM_CONST_DOUBLE (d, x);
662           REAL_VALUE_TO_TARGET_SINGLE (d, l);
663           fprintf (file, "0x%08lx", l);
664           break;
665         }
666
667       /* Fall through.  Let output_addr_const deal with it.  */
668     default:
669       output_addr_const (file, x);
670       break;
671     }
672
673   return;
674 }
675
676 /*}}}*/
677 /*{{{  Function arguments */ 
678
679 /* Return true if we should pass an argument on the stack rather than
680    in registers.  */
681
682 static bool
683 fr30_must_pass_in_stack (enum machine_mode mode, const_tree type)
684 {
685   if (mode == BLKmode)
686     return true;
687   if (type == NULL)
688     return false;
689   return AGGREGATE_TYPE_P (type);
690 }
691
692 /* Compute the number of word sized registers needed to hold a
693    function argument of mode INT_MODE and tree type TYPE.  */
694 int
695 fr30_num_arg_regs (enum machine_mode mode, tree type)
696 {
697   int size;
698
699   if (targetm.calls.must_pass_in_stack (mode, type))
700     return 0;
701
702   if (type && mode == BLKmode)
703     size = int_size_in_bytes (type);
704   else
705     size = GET_MODE_SIZE (mode);
706
707   return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
708 }
709
710 /* Returns the number of bytes in which *part* of a parameter of machine
711    mode MODE and tree type TYPE (which may be NULL if the type is not known).
712    If the argument fits entirely in the argument registers, or entirely on
713    the stack, then 0 is returned.
714    CUM is the number of argument registers already used by earlier
715    parameters to the function.  */
716
717 static int
718 fr30_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
719                         tree type, bool named)
720 {
721   /* Unnamed arguments, i.e. those that are prototyped as ...
722      are always passed on the stack.
723      Also check here to see if all the argument registers are full.  */
724   if (named == 0 || *cum >= FR30_NUM_ARG_REGS)
725     return 0;
726
727   /* Work out how many argument registers would be needed if this
728      parameter were to be passed entirely in registers.  If there
729      are sufficient argument registers available (or if no registers
730      are needed because the parameter must be passed on the stack)
731      then return zero, as this parameter does not require partial
732      register, partial stack stack space.  */
733   if (*cum + fr30_num_arg_regs (mode, type) <= FR30_NUM_ARG_REGS)
734     return 0;
735   
736   return (FR30_NUM_ARG_REGS - *cum) * UNITS_PER_WORD;
737 }
738
739 /*}}}*/
740 /*{{{  Operand predicates */ 
741
742 #ifndef Mmode
743 #define Mmode enum machine_mode
744 #endif
745
746 /* Returns true iff all the registers in the operands array
747    are in descending or ascending order.  */
748 int
749 fr30_check_multiple_regs (rtx *operands, int num_operands, int descending)
750 {
751   if (descending)
752     {
753       unsigned int prev_regno = 0;
754       
755       while (num_operands --)
756         {
757           if (GET_CODE (operands [num_operands]) != REG)
758             return 0;
759           
760           if (REGNO (operands [num_operands]) < prev_regno)
761             return 0;
762           
763           prev_regno = REGNO (operands [num_operands]);
764         }
765     }
766   else
767     {
768       unsigned int prev_regno = CONDITION_CODE_REGNUM;
769       
770       while (num_operands --)
771         {
772           if (GET_CODE (operands [num_operands]) != REG)
773             return 0;
774           
775           if (REGNO (operands [num_operands]) > prev_regno)
776             return 0;
777           
778           prev_regno = REGNO (operands [num_operands]);
779         }
780     }
781
782   return 1;
783 }
784
785 int
786 fr30_const_double_is_zero (rtx operand)
787 {
788   REAL_VALUE_TYPE d;
789
790   if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
791     return 0;
792
793   REAL_VALUE_FROM_CONST_DOUBLE (d, operand);
794
795   return REAL_VALUES_EQUAL (d, dconst0);
796 }
797
798 /*}}}*/
799 /*{{{  Instruction Output Routines  */
800
801 /* Output a double word move.
802    It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
803    On the FR30 we are constrained by the fact that it does not
804    support offsetable addresses, and so we have to load the
805    address of the secnd word into the second destination register
806    before we can use it.  */
807
808 rtx
809 fr30_move_double (rtx * operands)
810 {
811   rtx src  = operands[1];
812   rtx dest = operands[0];
813   enum rtx_code src_code = GET_CODE (src);
814   enum rtx_code dest_code = GET_CODE (dest);
815   enum machine_mode mode = GET_MODE (dest);
816   rtx val;
817
818   start_sequence ();
819
820   if (dest_code == REG)
821     {
822       if (src_code == REG)
823         {
824           int reverse = (REGNO (dest) == REGNO (src) + 1);
825           
826           /* We normally copy the low-numbered register first.  However, if
827              the first register of operand 0 is the same as the second register
828              of operand 1, we must copy in the opposite order.  */
829           emit_insn (gen_rtx_SET (VOIDmode,
830                                   operand_subword (dest, reverse, TRUE, mode),
831                                   operand_subword (src,  reverse, TRUE, mode)));
832           
833           emit_insn (gen_rtx_SET (VOIDmode,
834                               operand_subword (dest, !reverse, TRUE, mode),
835                               operand_subword (src,  !reverse, TRUE, mode)));
836         }
837       else if (src_code == MEM)
838         {
839           rtx addr = XEXP (src, 0);
840           int dregno = REGNO (dest);
841           rtx dest0 = operand_subword (dest, 0, TRUE, mode);;
842           rtx dest1 = operand_subword (dest, 1, TRUE, mode);;
843           rtx new_mem;
844           
845           gcc_assert (GET_CODE (addr) == REG);
846           
847           /* Copy the address before clobbering it.  See PR 34174.  */
848           emit_insn (gen_rtx_SET (SImode, dest1, addr));
849           emit_insn (gen_rtx_SET (VOIDmode, dest0,
850                                   adjust_address (src, SImode, 0)));
851           emit_insn (gen_rtx_SET (SImode, dest1,
852                                   plus_constant (dest1, UNITS_PER_WORD)));
853
854           new_mem = gen_rtx_MEM (SImode, dest1);
855           MEM_COPY_ATTRIBUTES (new_mem, src);
856               
857           emit_insn (gen_rtx_SET (VOIDmode, dest1, new_mem));
858         }
859       else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
860         {
861           rtx words[2];
862           split_double (src, &words[0], &words[1]);
863           emit_insn (gen_rtx_SET (VOIDmode,
864                                   operand_subword (dest, 0, TRUE, mode),
865                                   words[0]));
866       
867           emit_insn (gen_rtx_SET (VOIDmode,
868                                   operand_subword (dest, 1, TRUE, mode),
869                                   words[1]));
870         }
871     }
872   else if (src_code == REG && dest_code == MEM)
873     {
874       rtx addr = XEXP (dest, 0);
875       rtx src0;
876       rtx src1;
877
878       gcc_assert (GET_CODE (addr) == REG);
879
880       src0 = operand_subword (src, 0, TRUE, mode);
881       src1 = operand_subword (src, 1, TRUE, mode);
882
883       emit_move_insn (adjust_address (dest, SImode, 0), src0);
884
885       if (REGNO (addr) == STACK_POINTER_REGNUM
886           || REGNO (addr) == FRAME_POINTER_REGNUM)
887         emit_insn (gen_rtx_SET (VOIDmode,
888                                 adjust_address (dest, SImode, UNITS_PER_WORD),
889                                 src1));
890       else
891         {
892           rtx new_mem;
893           rtx scratch_reg_r0 = gen_rtx_REG (SImode, 0);
894
895           /* We need a scratch register to hold the value of 'address + 4'.
896              We use r0 for this purpose. It is used for example for long
897              jumps and is already marked to not be used by normal register
898              allocation.  */
899           emit_insn (gen_movsi_internal (scratch_reg_r0, addr));
900           emit_insn (gen_addsi_small_int (scratch_reg_r0, scratch_reg_r0,
901                                           GEN_INT (UNITS_PER_WORD)));
902           new_mem = gen_rtx_MEM (SImode, scratch_reg_r0);
903           MEM_COPY_ATTRIBUTES (new_mem, dest);
904           emit_move_insn (new_mem, src1);
905           emit_insn (gen_blockage ());
906         }
907     }
908   else
909     /* This should have been prevented by the constraints on movdi_insn.  */
910     gcc_unreachable ();
911
912   val = get_insns ();
913   end_sequence ();
914
915   return val;
916 }
917
918 /* Implement TARGET_FRAME_POINTER_REQUIRED.  */
919
920 bool
921 fr30_frame_pointer_required (void)
922 {
923   return (flag_omit_frame_pointer == 0 || crtl->args.pretend_args_size > 0);
924 }
925
926 /*}}}*/
927 /* Local Variables: */
928 /* folded-file: t   */
929 /* End:             */