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