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