Debian Codegraph @

gcc/config/fr30/fr30.cc

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