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