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