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