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