* final.c (final_scan_insn): Run FINAL_PRESCAN_INSNS on asm insns
[official-gcc.git] / gcc / config / d30v / d30v.c
blob4093ab27abf75751e79de3825a80f03981519a8a
1 /* Definitions of target machine for Mitsubishi D30V.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
5 This file is part of GCC.
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 2, or (at your option)
10 any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "output.h"
34 #include "insn-attr.h"
35 #include "flags.h"
36 #include "recog.h"
37 #include "expr.h"
38 #include "obstack.h"
39 #include "tm_p.h"
40 #include "except.h"
41 #include "function.h"
42 #include "toplev.h"
43 #include "integrate.h"
44 #include "ggc.h"
45 #include "target.h"
46 #include "target-def.h"
47 #include "langhooks.h"
49 static void d30v_print_operand_memory_reference PARAMS ((FILE *, rtx));
50 static void d30v_build_long_insn PARAMS ((HOST_WIDE_INT, HOST_WIDE_INT,
51 rtx, rtx));
52 static struct machine_function * d30v_init_machine_status PARAMS ((void));
53 static void d30v_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
54 static void d30v_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
55 static int d30v_adjust_cost PARAMS ((rtx, rtx, rtx, int));
56 static int d30v_issue_rate PARAMS ((void));
57 static bool d30v_rtx_costs PARAMS ((rtx, int, int, int *));
59 /* Define the information needed to generate branch and scc insns. This is
60 stored from the compare operation. */
62 struct rtx_def *d30v_compare_op0;
63 struct rtx_def *d30v_compare_op1;
65 /* Cached value of d30v_stack_info */
66 static d30v_stack_t *d30v_stack_cache = (d30v_stack_t *)0;
68 /* Values of the -mbranch-cost=n string. */
69 int d30v_branch_cost = D30V_DEFAULT_BRANCH_COST;
70 const char *d30v_branch_cost_string = (const char *)0;
72 /* Values of the -mcond-exec=n string. */
73 int d30v_cond_exec = D30V_DEFAULT_MAX_CONDITIONAL_EXECUTE;
74 const char *d30v_cond_exec_string = (const char *)0;
76 /* Whether or not a hard register can accept a register */
77 unsigned char hard_regno_mode_ok[ (int)MAX_MACHINE_MODE ][FIRST_PSEUDO_REGISTER];
79 /* Whether to try and avoid moves between two different modes */
80 unsigned char modes_tieable_p[ (NUM_MACHINE_MODES) * (NUM_MACHINE_MODES) ];
82 /* Map register number to smallest register class. */
83 enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER];
85 /* Map class letter into register class */
86 enum reg_class reg_class_from_letter[256];
88 /* Initialize the GCC target structure. */
89 #undef TARGET_ASM_ALIGNED_HI_OP
90 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
91 #undef TARGET_ASM_ALIGNED_SI_OP
92 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
94 #undef TARGET_ASM_FUNCTION_PROLOGUE
95 #define TARGET_ASM_FUNCTION_PROLOGUE d30v_output_function_prologue
96 #undef TARGET_ASM_FUNCTION_EPILOGUE
97 #define TARGET_ASM_FUNCTION_EPILOGUE d30v_output_function_epilogue
98 #undef TARGET_SCHED_ADJUST_COST
99 #define TARGET_SCHED_ADJUST_COST d30v_adjust_cost
100 #undef TARGET_SCHED_ISSUE_RATE
101 #define TARGET_SCHED_ISSUE_RATE d30v_issue_rate
103 #undef TARGET_RTX_COSTS
104 #define TARGET_RTX_COSTS d30v_rtx_costs
105 #undef TARGET_ADDRESS_COST
106 #define TARGET_ADDRESS_COST hook_int_rtx_0
108 struct gcc_target targetm = TARGET_INITIALIZER;
110 /* Sometimes certain combinations of command options do not make
111 sense on a particular target machine. You can define a macro
112 `OVERRIDE_OPTIONS' to take account of this. This macro, if
113 defined, is executed once just after all the command options have
114 been parsed.
116 Don't use this macro to turn on various extra optimizations for
117 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
119 void
120 override_options ()
122 int regno, i, ok_p;
123 enum machine_mode mode1, mode2;
125 /* Set up the branch cost information */
126 if (d30v_branch_cost_string)
127 d30v_branch_cost = atoi (d30v_branch_cost_string);
129 /* Set up max # instructions to use with conditional execution */
130 if (d30v_cond_exec_string)
131 d30v_cond_exec = atoi (d30v_cond_exec_string);
133 /* Setup hard_regno_mode_ok/modes_tieable_p */
134 for (mode1 = VOIDmode;
135 (int)mode1 < NUM_MACHINE_MODES;
136 mode1 = (enum machine_mode)((int)mode1 + 1))
138 int size = GET_MODE_SIZE (mode1);
139 int large_p = size > UNITS_PER_WORD;
140 int int_p = GET_MODE_CLASS (mode1) == MODE_INT;
142 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
144 if (mode1 == VOIDmode)
145 ok_p = FALSE;
147 else if (GPR_P (regno))
149 if (!large_p)
150 ok_p = TRUE;
151 else
152 ok_p = (((regno - GPR_FIRST) & 1) == 0);
155 else if (FLAG_P (regno))
156 ok_p = (mode1 == CCmode);
158 else if (CR_P (regno))
159 ok_p = int_p && !large_p;
161 else if (ACCUM_P (regno))
162 ok_p = (mode1 == DImode);
164 else if (SPECIAL_REG_P (regno))
165 ok_p = (mode1 == SImode);
167 else
168 ok_p = FALSE;
170 hard_regno_mode_ok[ (int)mode1 ][ regno ] = ok_p;
173 /* A C expression that is nonzero if it is desirable to choose
174 register allocation so as to avoid move instructions between a
175 value of mode MODE1 and a value of mode MODE2.
177 If `HARD_REGNO_MODE_OK (R, MODE1)' and `HARD_REGNO_MODE_OK (R,
178 MODE2)' are ever different for any R, then `MODES_TIEABLE_P (MODE1,
179 MODE2)' must be zero. */
180 for (mode2 = VOIDmode;
181 (int)mode2 <= NUM_MACHINE_MODES;
182 mode2 = (enum machine_mode)((int)mode2 + 1))
184 if (mode1 == mode2)
185 ok_p = TRUE;
187 #if 0
188 else if (GET_MODE_CLASS (mode1) == MODE_INT
189 && GET_MODE_SIZE (mode1) <= UNITS_PER_WORD
190 && GET_MODE_CLASS (mode2) == MODE_INT
191 && GET_MODE_SIZE (mode2) <= UNITS_PER_WORD)
192 ok_p = TRUE;
193 #endif
195 else
196 ok_p = FALSE;
198 modes_tieable_p[ ((int)mode1 * (NUM_MACHINE_MODES)) + (int)mode2 ] = ok_p;
202 #if 0
203 for (mode1 = VOIDmode;
204 (int)mode1 < NUM_MACHINE_MODES;
205 mode1 = (enum machine_mode)((int)mode1 + 1))
207 for (mode2 = VOIDmode;
208 (int)mode2 <= NUM_MACHINE_MODES;
209 mode2 = (enum machine_mode)((int)mode2 + 1))
211 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
212 if (ok_p
213 && (hard_regno_mode_ok[(int)mode1][regno]
214 != hard_regno_mode_ok[(int)mode2][regno]))
215 error ("bad modes_tieable_p for register %s, mode1 %s, mode2 %s",
216 reg_names[regno], GET_MODE_NAME (mode1),
217 GET_MODE_NAME (mode2));
220 #endif
222 /* A C expression whose value is a register class containing hard
223 register REGNO. In general there is more than one such class;
224 choose a class which is "minimal", meaning that no smaller class
225 also contains the register. */
226 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
228 enum reg_class class;
230 if (GPR_P (regno))
231 class = (IN_RANGE_P (regno, GPR_FIRST+2, GPR_FIRST+62)
232 && ((regno - GPR_FIRST) & 1) == 0) ? EVEN_REGS : GPR_REGS;
234 else if (regno == FLAG_F0)
235 class = F0_REGS;
237 else if (regno == FLAG_F1)
238 class = F1_REGS;
240 else if (FLAG_P (regno))
241 class = OTHER_FLAG_REGS;
243 else if (ACCUM_P (regno))
244 class = ACCUM_REGS;
246 else if (regno == CR_RPT_C)
247 class = REPEAT_REGS;
249 else if (CR_P (regno))
250 class = CR_REGS;
252 else if (SPECIAL_REG_P (regno))
253 class = GPR_REGS;
255 else
256 class = NO_REGS;
258 regno_reg_class[regno] = class;
260 #if 0
262 static const char *const names[] = REG_CLASS_NAMES;
263 fprintf (stderr, "Register %s class is %s, can hold modes", reg_names[regno], names[class]);
264 for (mode1 = VOIDmode;
265 (int)mode1 < NUM_MACHINE_MODES;
266 mode1 = (enum machine_mode)((int)mode1 + 1))
268 if (hard_regno_mode_ok[ (int)mode1 ][ regno ])
269 fprintf (stderr, " %s", GET_MODE_NAME (mode1));
271 fprintf (stderr, "\n");
273 #endif
276 /* A C expression which defines the machine-dependent operand
277 constraint letters for register classes. If CHAR is such a
278 letter, the value should be the register class corresponding to
279 it. Otherwise, the value should be `NO_REGS'. The register
280 letter `r', corresponding to class `GENERAL_REGS', will not be
281 passed to this macro; you do not need to handle it.
283 The following letters are unavailable, due to being used as
284 constraints:
285 '0'..'9'
286 '<', '>'
287 'E', 'F', 'G', 'H'
288 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
289 'Q', 'R', 'S', 'T', 'U'
290 'V', 'X'
291 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
293 for (i = 0; i < 256; i++)
294 reg_class_from_letter[i] = NO_REGS;
296 reg_class_from_letter['a'] = ACCUM_REGS;
297 reg_class_from_letter['b'] = BR_FLAG_REGS;
298 reg_class_from_letter['c'] = CR_REGS;
299 reg_class_from_letter['d'] = GPR_REGS;
300 reg_class_from_letter['e'] = EVEN_REGS;
301 reg_class_from_letter['f'] = FLAG_REGS;
302 reg_class_from_letter['l'] = REPEAT_REGS;
303 reg_class_from_letter['x'] = F0_REGS;
304 reg_class_from_letter['y'] = F1_REGS;
305 reg_class_from_letter['z'] = OTHER_FLAG_REGS;
309 /* Return true if a memory operand is a short memory operand. */
312 short_memory_operand (op, mode)
313 register rtx op;
314 enum machine_mode mode;
316 if (GET_CODE (op) != MEM)
317 return FALSE;
319 if (GET_MODE (op) != mode && mode != VOIDmode)
320 return FALSE;
322 return (d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed)
323 == 1);
326 /* Return true if a memory operand is a long operand. */
329 long_memory_operand (op, mode)
330 rtx op;
331 enum machine_mode mode;
333 if (GET_CODE (op) != MEM)
334 return FALSE;
336 if (GET_MODE (op) != mode && mode != VOIDmode)
337 return FALSE;
339 return (d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed)
340 == 2);
343 /* Return true if a memory operand is valid for the D30V. */
346 d30v_memory_operand (op, mode)
347 rtx op;
348 enum machine_mode mode;
350 if (GET_CODE (op) != MEM)
351 return FALSE;
353 if (GET_MODE (op) != mode && mode != VOIDmode)
354 return FALSE;
356 return (d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed)
357 != 0);
360 /* Return true if a memory operand uses a single register for the
361 address. */
364 single_reg_memory_operand (op, mode)
365 rtx op;
366 enum machine_mode mode;
368 rtx addr;
370 if (GET_CODE (op) != MEM)
371 return FALSE;
373 if (GET_MODE (op) != mode && mode != VOIDmode)
374 return FALSE;
376 addr = XEXP (op, 0);
377 if (! d30v_legitimate_address_p (mode, addr, reload_completed))
378 return FALSE;
380 if (GET_CODE (addr) == SUBREG)
381 addr = SUBREG_REG (addr);
383 return (GET_CODE (addr) == REG);
386 /* Return true if a memory operand uses a constant address. */
389 const_addr_memory_operand (op, mode)
390 rtx op;
391 enum machine_mode mode;
393 if (GET_CODE (op) != MEM)
394 return FALSE;
396 if (GET_MODE (op) != mode && mode != VOIDmode)
397 return FALSE;
399 if (! d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed))
400 return FALSE;
402 switch (GET_CODE (XEXP (op, 0)))
404 default:
405 break;
407 case SYMBOL_REF:
408 case LABEL_REF:
409 case CONST_INT:
410 case CONST:
411 return TRUE;
414 return FALSE;
417 /* Return true if operand is a memory reference suitable for a call. */
420 call_operand (op, mode)
421 rtx op;
422 enum machine_mode mode;
424 if (GET_CODE (op) != MEM)
425 return FALSE;
427 if (GET_MODE (op) != mode && mode != VOIDmode)
428 return FALSE;
430 if (! d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed))
431 return FALSE;
433 switch (GET_CODE (XEXP (op, 0)))
435 default:
436 break;
438 case SUBREG:
439 op = SUBREG_REG (op);
440 if (GET_CODE (op) != REG)
441 return FALSE;
443 /* fall through */
445 case REG:
446 return (GPR_OR_PSEUDO_P (REGNO (XEXP (op, 0))));
448 case SYMBOL_REF:
449 case LABEL_REF:
450 case CONST_INT:
451 case CONST:
452 return TRUE;
455 return FALSE;
458 /* Return true if operand is a GPR register. */
461 gpr_operand (op, mode)
462 rtx op;
463 enum machine_mode mode;
465 if (GET_MODE (op) != mode && mode != VOIDmode)
466 return FALSE;
468 if (GET_CODE (op) == SUBREG)
470 if (GET_CODE (SUBREG_REG (op)) != REG)
471 return register_operand (op, mode);
473 op = SUBREG_REG (op);
476 if (GET_CODE (op) != REG)
477 return FALSE;
479 return GPR_OR_PSEUDO_P (REGNO (op));
482 /* Return true if operand is an accumulator register. */
485 accum_operand (op, mode)
486 rtx op;
487 enum machine_mode mode;
489 if (GET_MODE (op) != mode && mode != VOIDmode)
490 return FALSE;
492 if (GET_CODE (op) == SUBREG)
494 if (GET_CODE (SUBREG_REG (op)) != REG)
495 return register_operand (op, mode);
497 op = SUBREG_REG (op);
500 if (GET_CODE (op) != REG)
501 return FALSE;
503 return ACCUM_OR_PSEUDO_P (REGNO (op));
506 /* Return true if operand is a GPR or an accumulator register. */
509 gpr_or_accum_operand (op, mode)
510 rtx op;
511 enum machine_mode mode;
513 if (GET_MODE (op) != mode && mode != VOIDmode)
514 return FALSE;
516 if (GET_CODE (op) == SUBREG)
518 if (GET_CODE (SUBREG_REG (op)) != REG)
519 return register_operand (op, mode);
521 op = SUBREG_REG (op);
524 if (GET_CODE (op) != REG)
525 return FALSE;
527 if (ACCUM_P (REGNO (op)))
528 return TRUE;
530 return GPR_OR_PSEUDO_P (REGNO (op));
533 /* Return true if operand is a CR register. */
536 cr_operand (op, mode)
537 rtx op;
538 enum machine_mode mode;
540 if (GET_MODE (op) != mode && mode != VOIDmode)
541 return FALSE;
543 if (GET_CODE (op) == SUBREG)
545 if (GET_CODE (SUBREG_REG (op)) != REG)
546 return register_operand (op, mode);
548 op = SUBREG_REG (op);
551 if (GET_CODE (op) != REG)
552 return FALSE;
554 return CR_OR_PSEUDO_P (REGNO (op));
557 /* Return true if operand is the repeat count register. */
560 repeat_operand (op, mode)
561 rtx op;
562 enum machine_mode mode;
564 if (GET_MODE (op) != mode && mode != VOIDmode)
565 return FALSE;
567 if (GET_CODE (op) == SUBREG)
569 if (GET_CODE (SUBREG_REG (op)) != REG)
570 return register_operand (op, mode);
572 op = SUBREG_REG (op);
575 if (GET_CODE (op) != REG)
576 return FALSE;
578 return (REGNO (op) == CR_RPT_C || REGNO (op) >= FIRST_PSEUDO_REGISTER);
581 /* Return true if operand is a FLAG register. */
584 flag_operand (op, mode)
585 rtx op;
586 enum machine_mode mode;
588 if (GET_MODE (op) != mode && mode != VOIDmode)
589 return FALSE;
591 if (GET_CODE (op) == SUBREG)
593 if (GET_CODE (SUBREG_REG (op)) != REG)
594 return register_operand (op, mode);
596 op = SUBREG_REG (op);
599 if (GET_CODE (op) != REG)
600 return FALSE;
602 return FLAG_OR_PSEUDO_P (REGNO (op));
605 /* Return true if operand is either F0 or F1. */
608 br_flag_operand (op, mode)
609 rtx op;
610 enum machine_mode mode;
612 if (GET_MODE (op) != mode && mode != VOIDmode)
613 return FALSE;
615 if (GET_CODE (op) == SUBREG)
617 if (GET_CODE (SUBREG_REG (op)) != REG)
618 return register_operand (op, mode);
620 op = SUBREG_REG (op);
623 if (GET_CODE (op) != REG)
624 return FALSE;
626 return BR_FLAG_OR_PSEUDO_P (REGNO (op));
629 /* Return true if operand is either F0/F1 or the constants 0/1. */
632 br_flag_or_constant_operand (op, mode)
633 rtx op;
634 enum machine_mode mode;
636 if (GET_MODE (op) != mode && mode != VOIDmode)
637 return FALSE;
639 if (GET_CODE (op) == SUBREG)
641 if (GET_CODE (SUBREG_REG (op)) != REG)
642 return register_operand (op, mode);
644 op = SUBREG_REG (op);
647 if (GET_CODE (op) == CONST_INT)
648 return (INTVAL (op) == 0 || INTVAL (op) == 1);
650 if (GET_CODE (op) != REG)
651 return FALSE;
653 return BR_FLAG_OR_PSEUDO_P (REGNO (op));
656 /* Return true if operand is either F0 or F1, or a GPR register. */
659 gpr_or_br_flag_operand (op, mode)
660 rtx op;
661 enum machine_mode mode;
663 if (GET_MODE (op) != mode && mode != VOIDmode)
664 return FALSE;
666 if (GET_CODE (op) == SUBREG)
668 if (GET_CODE (SUBREG_REG (op)) != REG)
669 return register_operand (op, mode);
671 op = SUBREG_REG (op);
674 if (GET_CODE (op) != REG)
675 return FALSE;
677 return GPR_OR_PSEUDO_P (REGNO (op)) || BR_FLAG_P (REGNO (op));
680 /* Return true if operand is the F0 register. */
683 f0_operand (op, mode)
684 rtx op;
685 enum machine_mode mode;
687 if (GET_MODE (op) != mode && mode != VOIDmode)
688 return FALSE;
690 if (GET_CODE (op) == SUBREG)
692 if (GET_CODE (SUBREG_REG (op)) != REG)
693 return register_operand (op, mode);
695 op = SUBREG_REG (op);
698 if (GET_CODE (op) != REG)
699 return FALSE;
701 return (REGNO (op) == FLAG_F0 || REGNO (op) >= FIRST_PSEUDO_REGISTER);
704 /* Return true if operand is the F1 register. */
707 f1_operand (op, mode)
708 rtx op;
709 enum machine_mode mode;
711 if (GET_MODE (op) != mode && mode != VOIDmode)
712 return FALSE;
714 if (GET_CODE (op) == SUBREG)
716 if (GET_CODE (SUBREG_REG (op)) != REG)
717 return register_operand (op, mode);
719 op = SUBREG_REG (op);
722 if (GET_CODE (op) != REG)
723 return FALSE;
725 return (REGNO (op) == FLAG_F1 || REGNO (op) >= FIRST_PSEUDO_REGISTER);
728 /* Return true if operand is the F1 register. */
731 carry_operand (op, mode)
732 rtx op;
733 enum machine_mode mode;
735 if (GET_MODE (op) != mode && mode != VOIDmode)
736 return FALSE;
738 if (GET_CODE (op) == SUBREG)
740 if (GET_CODE (SUBREG_REG (op)) != REG)
741 return register_operand (op, mode);
743 op = SUBREG_REG (op);
746 if (GET_CODE (op) != REG)
747 return FALSE;
749 return (REGNO (op) == FLAG_CARRY || REGNO (op) >= FIRST_PSEUDO_REGISTER);
752 /* Return true if operand is a register of any flavor or a 0 of the
753 appropriate type. */
756 reg_or_0_operand (op, mode)
757 rtx op;
758 enum machine_mode mode;
760 switch (GET_CODE (op))
762 default:
763 break;
765 case REG:
766 case SUBREG:
767 if (GET_MODE (op) != mode && mode != VOIDmode)
768 return FALSE;
770 return register_operand (op, mode);
772 case CONST_INT:
773 return INTVAL (op) == 0;
775 case CONST_DOUBLE:
776 return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == 0;
779 return FALSE;
782 /* Return true if operand is a GPR register or a signed 6 bit immediate. */
785 gpr_or_signed6_operand (op, mode)
786 rtx op;
787 enum machine_mode mode;
789 if (GET_CODE (op) == SUBREG)
791 if (GET_CODE (SUBREG_REG (op)) != REG)
792 return register_operand (op, mode);
794 op = SUBREG_REG (op);
797 if (GET_CODE (op) == CONST_INT)
798 return IN_RANGE_P (INTVAL (op), -32, 31);
800 if (GET_CODE (op) != REG)
801 return FALSE;
803 if (GET_MODE (op) != mode && mode != VOIDmode)
804 return FALSE;
806 return GPR_OR_PSEUDO_P (REGNO (op));
809 /* Return true if operand is a GPR register or an unsigned 5 bit immediate. */
812 gpr_or_unsigned5_operand (op, mode)
813 rtx op;
814 enum machine_mode mode;
816 if (GET_CODE (op) == SUBREG)
818 if (GET_CODE (SUBREG_REG (op)) != REG)
819 return register_operand (op, mode);
821 op = SUBREG_REG (op);
824 if (GET_CODE (op) == CONST_INT)
825 return IN_RANGE_P (INTVAL (op), 0, 31);
827 if (GET_CODE (op) != REG)
828 return FALSE;
830 if (GET_MODE (op) != mode && mode != VOIDmode)
831 return FALSE;
833 return GPR_OR_PSEUDO_P (REGNO (op));
836 /* Return true if operand is a GPR register or an unsigned 6 bit immediate. */
839 gpr_or_unsigned6_operand (op, mode)
840 rtx op;
841 enum machine_mode mode;
843 if (GET_CODE (op) == SUBREG)
845 if (GET_CODE (SUBREG_REG (op)) != REG)
846 return register_operand (op, mode);
848 op = SUBREG_REG (op);
851 if (GET_CODE (op) == CONST_INT)
852 return IN_RANGE_P (INTVAL (op), 0, 63);
854 if (GET_CODE (op) != REG)
855 return FALSE;
857 if (GET_MODE (op) != mode && mode != VOIDmode)
858 return FALSE;
860 return GPR_OR_PSEUDO_P (REGNO (op));
863 /* Return true if operand is a GPR register or a constant of some form. */
866 gpr_or_constant_operand (op, mode)
867 rtx op;
868 enum machine_mode mode;
870 switch (GET_CODE (op))
872 default:
873 break;
875 case CONST_INT:
876 case SYMBOL_REF:
877 case LABEL_REF:
878 case CONST:
879 return TRUE;
881 case SUBREG:
882 if (GET_CODE (SUBREG_REG (op)) != REG)
883 return register_operand (op, mode);
885 op = SUBREG_REG (op);
886 /* fall through */
888 case REG:
889 if (GET_MODE (op) != mode && mode != VOIDmode)
890 return FALSE;
892 return GPR_OR_PSEUDO_P (REGNO (op));
895 return FALSE;
898 /* Return true if operand is a GPR register or a constant of some form,
899 including a CONST_DOUBLE, which gpr_or_constant_operand doesn't recognize. */
902 gpr_or_dbl_const_operand (op, mode)
903 rtx op;
904 enum machine_mode mode;
906 switch (GET_CODE (op))
908 default:
909 break;
911 case CONST_INT:
912 case CONST_DOUBLE:
913 case SYMBOL_REF:
914 case LABEL_REF:
915 case CONST:
916 return TRUE;
918 case SUBREG:
919 if (GET_CODE (SUBREG_REG (op)) != REG)
920 return register_operand (op, mode);
922 op = SUBREG_REG (op);
923 /* fall through */
925 case REG:
926 if (GET_MODE (op) != mode && mode != VOIDmode)
927 return FALSE;
929 return GPR_OR_PSEUDO_P (REGNO (op));
932 return FALSE;
935 /* Return true if operand is a gpr register or a valid memory operation. */
938 gpr_or_memory_operand (op, mode)
939 rtx op;
940 enum machine_mode mode;
942 switch (GET_CODE (op))
944 default:
945 break;
947 case SUBREG:
948 if (GET_CODE (SUBREG_REG (op)) != REG)
949 return register_operand (op, mode);
951 op = SUBREG_REG (op);
952 /* fall through */
954 case REG:
955 if (GET_MODE (op) != mode && mode != VOIDmode)
956 return FALSE;
958 return GPR_OR_PSEUDO_P (REGNO (op));
960 case MEM:
961 return d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed);
964 return FALSE;
967 /* Return true if operand is something that can be an input for a move
968 operation. */
971 move_input_operand (op, mode)
972 rtx op;
973 enum machine_mode mode;
975 rtx subreg;
976 enum rtx_code code;
978 switch (GET_CODE (op))
980 default:
981 break;
983 case CONST_INT:
984 case CONST_DOUBLE:
985 case SYMBOL_REF:
986 case LABEL_REF:
987 case CONST:
988 return TRUE;
990 case SUBREG:
991 if (GET_MODE (op) != mode && mode != VOIDmode)
992 return FALSE;
994 subreg = SUBREG_REG (op);
995 code = GET_CODE (subreg);
996 if (code == MEM)
997 return d30v_legitimate_address_p ((int)mode, XEXP (subreg, 0),
998 reload_completed);
1000 return (code == REG);
1002 case REG:
1003 if (GET_MODE (op) != mode && mode != VOIDmode)
1004 return FALSE;
1006 return TRUE;
1008 case MEM:
1009 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
1010 return TRUE;
1011 return d30v_legitimate_address_p (mode, XEXP (op, 0),
1012 reload_completed);
1015 return FALSE;
1018 /* Return true if operand is something that can be an output for a move
1019 operation. */
1022 move_output_operand (op, mode)
1023 rtx op;
1024 enum machine_mode mode;
1026 rtx subreg;
1027 enum rtx_code code;
1029 switch (GET_CODE (op))
1031 default:
1032 break;
1034 case SUBREG:
1035 if (GET_MODE (op) != mode && mode != VOIDmode)
1036 return FALSE;
1038 subreg = SUBREG_REG (op);
1039 code = GET_CODE (subreg);
1040 if (code == MEM)
1041 return d30v_legitimate_address_p ((int)mode, XEXP (subreg, 0),
1042 reload_completed);
1044 return (code == REG);
1046 case REG:
1047 if (GET_MODE (op) != mode && mode != VOIDmode)
1048 return FALSE;
1050 return TRUE;
1052 case MEM:
1053 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
1054 return TRUE;
1055 return d30v_legitimate_address_p (mode, XEXP (op, 0),
1056 reload_completed);
1059 return FALSE;
1062 /* Return true if operand is a signed 6 bit immediate. */
1065 signed6_operand (op, mode)
1066 rtx op;
1067 enum machine_mode mode ATTRIBUTE_UNUSED;
1069 if (GET_CODE (op) == CONST_INT)
1070 return IN_RANGE_P (INTVAL (op), -32, 31);
1072 return FALSE;
1075 /* Return true if operand is an unsigned 5 bit immediate. */
1078 unsigned5_operand (op, mode)
1079 rtx op;
1080 enum machine_mode mode ATTRIBUTE_UNUSED;
1082 if (GET_CODE (op) == CONST_INT)
1083 return IN_RANGE_P (INTVAL (op), 0, 31);
1085 return FALSE;
1088 /* Return true if operand is an unsigned 6 bit immediate. */
1091 unsigned6_operand (op, mode)
1092 rtx op;
1093 enum machine_mode mode ATTRIBUTE_UNUSED;
1095 if (GET_CODE (op) == CONST_INT)
1096 return IN_RANGE_P (INTVAL (op), 0, 63);
1098 return FALSE;
1101 /* Return true if operand is a constant with a single bit set. */
1104 bitset_operand (op, mode)
1105 rtx op;
1106 enum machine_mode mode ATTRIBUTE_UNUSED;
1108 if (GET_CODE (op) == CONST_INT)
1109 return IN_RANGE_P (exact_log2 (INTVAL (op)), 0, 31);
1111 return FALSE;
1114 /* Return true if the operator is a ==/!= test against f0 or f1 that can be
1115 used in conditional execution. */
1118 condexec_test_operator (op, mode)
1119 rtx op;
1120 enum machine_mode mode;
1122 rtx x0, x1;
1124 if (GET_MODE (op) != mode && mode != VOIDmode)
1125 return FALSE;
1127 if (GET_CODE (op) != EQ && GET_CODE (op) != NE)
1128 return FALSE;
1130 x0 = XEXP (op, 0);
1131 if (GET_CODE (x0) != REG || !BR_FLAG_OR_PSEUDO_P (REGNO (x0)))
1132 return FALSE;
1134 x1 = XEXP (op, 1);
1135 if (GET_CODE (x1) != CONST_INT || INTVAL (x1) != 0)
1136 return FALSE;
1138 return TRUE;
1141 /* Return true if the operator is a ==/!= test against f0, f1, or a general
1142 register that can be used in a branch instruction. */
1145 condexec_branch_operator (op, mode)
1146 rtx op;
1147 enum machine_mode mode;
1149 rtx x0, x1;
1151 if (GET_MODE (op) != mode && mode != VOIDmode)
1152 return FALSE;
1154 if (GET_CODE (op) != EQ && GET_CODE (op) != NE)
1155 return FALSE;
1157 x0 = XEXP (op, 0);
1158 if (GET_CODE (x0) == REG)
1160 int regno = REGNO (x0);
1161 if (!GPR_OR_PSEUDO_P (regno) && !BR_FLAG_P (regno))
1162 return FALSE;
1164 /* Allow the optimizer to generate things like:
1165 (if_then_else (ne (const_int 1) (const_int 0))) */
1166 else if (GET_CODE (x0) != CONST_INT)
1167 return FALSE;
1169 x1 = XEXP (op, 1);
1170 if (GET_CODE (x1) != CONST_INT || INTVAL (x1) != 0)
1171 return FALSE;
1173 return TRUE;
1176 /* Return true if the unary operator can be executed with conditional
1177 execution. */
1180 condexec_unary_operator (op, mode)
1181 rtx op;
1182 enum machine_mode mode ATTRIBUTE_UNUSED;
1184 rtx op0;
1186 /* Only do this after register allocation, so that we can look at the register # */
1187 if (!reload_completed)
1188 return FALSE;
1190 if (GET_RTX_CLASS (GET_CODE (op)) != '1')
1191 return FALSE;
1193 op0 = XEXP (op, 0);
1194 if (GET_CODE (op0) == SUBREG)
1195 op0 = SUBREG_REG (op0);
1197 switch (GET_CODE (op))
1199 default:
1200 break;
1202 case ABS:
1203 case NOT:
1204 if (GET_MODE (op) == SImode && GET_CODE (op0) == REG && GPR_P (REGNO (op0)))
1205 return TRUE;
1207 break;
1210 return FALSE;
1213 /* Return true if the add or subtraction can be executed with conditional
1214 execution. */
1217 condexec_addsub_operator (op, mode)
1218 rtx op;
1219 enum machine_mode mode ATTRIBUTE_UNUSED;
1221 rtx op0, op1;
1223 /* Only do this after register allocation, so that we can look at the register # */
1224 if (!reload_completed)
1225 return FALSE;
1227 if (GET_RTX_CLASS (GET_CODE (op)) != '2' && GET_RTX_CLASS (GET_CODE (op)) != 'c')
1228 return FALSE;
1230 op0 = XEXP (op, 0);
1231 op1 = XEXP (op, 1);
1233 if (GET_CODE (op0) == SUBREG)
1234 op0 = SUBREG_REG (op0);
1236 if (GET_CODE (op1) == SUBREG)
1237 op1 = SUBREG_REG (op1);
1239 if (GET_CODE (op0) != REG)
1240 return FALSE;
1242 switch (GET_CODE (op))
1244 default:
1245 break;
1247 case PLUS:
1248 case MINUS:
1249 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1250 && gpr_or_constant_operand (op1, SImode));
1253 return FALSE;
1256 /* Return true if the binary operator can be executed with conditional
1257 execution. We don't include add/sub here, since they have extra
1258 clobbers for the flags registers. */
1261 condexec_binary_operator (op, mode)
1262 rtx op;
1263 enum machine_mode mode ATTRIBUTE_UNUSED;
1265 rtx op0, op1;
1267 /* Only do this after register allocation, so that we can look at the register # */
1268 if (!reload_completed)
1269 return FALSE;
1271 if (GET_RTX_CLASS (GET_CODE (op)) != '2' && GET_RTX_CLASS (GET_CODE (op)) != 'c')
1272 return FALSE;
1274 op0 = XEXP (op, 0);
1275 op1 = XEXP (op, 1);
1277 if (GET_CODE (op0) == SUBREG)
1278 op0 = SUBREG_REG (op0);
1280 if (GET_CODE (op1) == SUBREG)
1281 op1 = SUBREG_REG (op1);
1283 if (GET_CODE (op0) != REG)
1284 return FALSE;
1286 /* MULT is not included here, because it is an IU only instruction. */
1287 switch (GET_CODE (op))
1289 default:
1290 break;
1292 case AND:
1293 case IOR:
1294 case XOR:
1295 case ASHIFTRT:
1296 case LSHIFTRT:
1297 case ROTATERT:
1298 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1299 && gpr_or_constant_operand (op1, SImode));
1301 case ASHIFT:
1302 case ROTATE:
1303 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1304 && GET_CODE (op1) == CONST_INT);
1307 return FALSE;
1310 /* Return true if the shift/rotate left operator can be executed with
1311 conditional execution. */
1314 condexec_shiftl_operator (op, mode)
1315 rtx op;
1316 enum machine_mode mode ATTRIBUTE_UNUSED;
1318 rtx op0, op1;
1320 /* Only do this after register allocation, so that we can look at the register # */
1321 if (!reload_completed)
1322 return FALSE;
1324 if (GET_RTX_CLASS (GET_CODE (op)) != '2' && GET_RTX_CLASS (GET_CODE (op)) != 'c')
1325 return FALSE;
1327 op0 = XEXP (op, 0);
1328 op1 = XEXP (op, 1);
1330 if (GET_CODE (op0) == SUBREG)
1331 op0 = SUBREG_REG (op0);
1333 if (GET_CODE (op1) == SUBREG)
1334 op1 = SUBREG_REG (op1);
1336 if (GET_CODE (op0) != REG)
1337 return FALSE;
1339 switch (GET_CODE (op))
1341 default:
1342 break;
1344 case ASHIFT:
1345 case ROTATE:
1346 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1347 && GET_CODE (op1) == NEG
1348 && GET_CODE (XEXP (op1, 0)) == REG
1349 && GPR_P (REGNO (XEXP (op1, 0))));
1352 return FALSE;
1355 /* Return true if the {sign,zero} extend operator from memory can be
1356 conditionally executed. */
1359 condexec_extend_operator (op, mode)
1360 rtx op;
1361 enum machine_mode mode ATTRIBUTE_UNUSED;
1363 /* Only do this after register allocation, so that we can look at the register # */
1364 if (!reload_completed)
1365 return FALSE;
1367 if (GET_RTX_CLASS (GET_CODE (op)) != '1')
1368 return FALSE;
1370 switch (GET_CODE (op))
1372 default:
1373 break;
1375 case SIGN_EXTEND:
1376 case ZERO_EXTEND:
1377 if ((GET_MODE (op) == SImode && GET_MODE (XEXP (op, 0)) == QImode)
1378 || (GET_MODE (op) == SImode && GET_MODE (XEXP (op, 0)) == HImode)
1379 || (GET_MODE (op) == HImode && GET_MODE (XEXP (op, 0)) == QImode))
1380 return TRUE;
1382 break;
1385 return FALSE;
1388 /* Return true for comparisons against 0 that can be turned into a
1389 bratnz/bratzr instruction. */
1392 branch_zero_operator (op, mode)
1393 rtx op;
1394 enum machine_mode mode;
1396 rtx x0, x1;
1398 if (GET_MODE (op) != mode && mode != VOIDmode)
1399 return FALSE;
1401 if (GET_CODE (op) != EQ && GET_CODE (op) != NE)
1402 return FALSE;
1404 x0 = XEXP (op, 0);
1405 if (GET_CODE (x0) != REG || !GPR_OR_PSEUDO_P (REGNO (x0)))
1406 return FALSE;
1408 x1 = XEXP (op, 1);
1409 if (GET_CODE (x1) != CONST_INT || INTVAL (x1) != 0)
1410 return FALSE;
1412 return TRUE;
1415 /* Return true if an operand is simple, suitable for use as the destination of
1416 a conditional move */
1419 cond_move_dest_operand (op, mode)
1420 register rtx op;
1421 enum machine_mode mode ATTRIBUTE_UNUSED;
1423 rtx addr;
1425 if (mode != QImode && mode != HImode && mode != SImode && mode != SFmode)
1426 return FALSE;
1428 switch (GET_CODE (op))
1430 default:
1431 break;
1433 case REG:
1434 case SUBREG:
1435 return gpr_operand (op, mode);
1437 /* Don't allow post dec/inc, since we might not get the side effects correct. */
1438 case MEM:
1439 addr = XEXP (op, 0);
1440 return (GET_CODE (addr) != POST_DEC
1441 && GET_CODE (addr) != POST_INC
1442 && d30v_legitimate_address_p (mode, addr, reload_completed));
1445 return FALSE;
1448 /* Return true if an operand is simple, suitable for use in a conditional move */
1451 cond_move_operand (op, mode)
1452 register rtx op;
1453 enum machine_mode mode ATTRIBUTE_UNUSED;
1455 rtx addr;
1457 if (mode != QImode && mode != HImode && mode != SImode && mode != SFmode)
1458 return FALSE;
1460 switch (GET_CODE (op))
1462 default:
1463 break;
1465 case REG:
1466 case SUBREG:
1467 return gpr_operand (op, mode);
1469 case CONST_DOUBLE:
1470 return GET_MODE (op) == SFmode;
1472 case CONST_INT:
1473 case SYMBOL_REF:
1474 case LABEL_REF:
1475 case CONST:
1476 return TRUE;
1478 /* Don't allow post dec/inc, since we might not get the side effects correct. */
1479 case MEM:
1480 addr = XEXP (op, 0);
1481 return (GET_CODE (addr) != POST_DEC
1482 && GET_CODE (addr) != POST_INC
1483 && d30v_legitimate_address_p (mode, addr, reload_completed));
1486 return FALSE;
1489 /* Return true if an operand is simple, suitable for use in conditional execution.
1490 Unlike cond_move, we can allow auto inc/dec. */
1493 cond_exec_operand (op, mode)
1494 register rtx op;
1495 enum machine_mode mode;
1497 if (mode != QImode && mode != HImode && mode != SImode && mode != SFmode)
1498 return FALSE;
1500 switch (GET_CODE (op))
1502 default:
1503 break;
1505 case REG:
1506 case SUBREG:
1507 return gpr_operand (op, mode);
1509 case CONST_DOUBLE:
1510 return GET_MODE (op) == SFmode;
1512 case CONST_INT:
1513 case SYMBOL_REF:
1514 case LABEL_REF:
1515 case CONST:
1516 return TRUE;
1518 case MEM:
1519 return memory_operand (op, mode);
1522 return FALSE;
1525 /* Return true if operand is a SI mode signed relational test. */
1528 srelational_si_operator (op, mode)
1529 register rtx op;
1530 enum machine_mode mode;
1532 rtx x0, x1;
1534 if (GET_MODE (op) != mode && mode != VOIDmode)
1535 return FALSE;
1537 switch (GET_CODE (op))
1539 default:
1540 return FALSE;
1542 case EQ:
1543 case NE:
1544 case LT:
1545 case LE:
1546 case GT:
1547 case GE:
1548 break;
1551 x0 = XEXP (op, 0);
1552 if (GET_CODE (x0) != REG && GET_CODE (x0) != SUBREG)
1553 return FALSE;
1555 if (GET_MODE (x0) != SImode)
1556 return FALSE;
1558 x1 = XEXP (op, 1);
1559 switch (GET_CODE (x1))
1561 default:
1562 return FALSE;
1564 case REG:
1565 case SUBREG:
1566 case CONST_INT:
1567 case LABEL_REF:
1568 case SYMBOL_REF:
1569 case CONST:
1570 break;
1573 return TRUE;
1576 /* Return true if operand is a SI mode unsigned relational test. */
1579 urelational_si_operator (op, mode)
1580 register rtx op;
1581 enum machine_mode mode;
1583 rtx x0, x1;
1585 if (GET_MODE (op) != mode && mode != VOIDmode)
1586 return FALSE;
1588 switch (GET_CODE (op))
1590 default:
1591 return FALSE;
1593 case LTU:
1594 case LEU:
1595 case GTU:
1596 case GEU:
1597 break;
1600 x0 = XEXP (op, 0);
1601 if (GET_CODE (x0) != REG && GET_CODE (x0) != SUBREG)
1602 return FALSE;
1604 if (GET_MODE (x0) != SImode)
1605 return FALSE;
1607 x1 = XEXP (op, 1);
1608 switch (GET_CODE (x1))
1610 default:
1611 return FALSE;
1613 case REG:
1614 case SUBREG:
1615 case CONST_INT:
1616 case LABEL_REF:
1617 case SYMBOL_REF:
1618 case CONST:
1619 break;
1622 return TRUE;
1625 /* Return true if operand is a DI mode relational test. */
1628 relational_di_operator (op, mode)
1629 register rtx op;
1630 enum machine_mode mode;
1632 rtx x0, x1;
1634 if (GET_MODE (op) != mode && mode != VOIDmode)
1635 return FALSE;
1637 if (GET_RTX_CLASS (GET_CODE (op)) != '<')
1638 return FALSE;
1640 x0 = XEXP (op, 0);
1641 if (GET_CODE (x0) != REG && GET_CODE (x0) != SUBREG)
1642 return FALSE;
1644 if (GET_MODE (x0) != DImode)
1645 return FALSE;
1647 x1 = XEXP (op, 1);
1648 if (GET_CODE (x1) != REG && GET_CODE (x1) != SUBREG
1649 && GET_CODE (x1) != CONST_INT && GET_CODE (x1) != CONST_DOUBLE)
1650 return FALSE;
1652 return TRUE;
1656 /* Calculate the stack information for the current function.
1658 D30V stack frames look like:
1660 high | .... |
1661 +-------------------------------+
1662 | Argument word #19 |
1663 +-------------------------------+
1664 | Argument word #18 |
1665 +-------------------------------+
1666 | Argument word #17 |
1667 +-------------------------------+
1668 | Argument word #16 |
1669 Prev sp +-------------------------------+
1671 | Save for arguments 1..16 if |
1672 | the func. uses stdarg/varargs |
1674 +-------------------------------+
1676 | Save area for GPR registers |
1678 +-------------------------------+
1680 | Save area for accumulators |
1682 +-------------------------------+
1684 | Local variables |
1686 +-------------------------------+
1688 | alloca space if used |
1690 +-------------------------------+
1692 | Space for outgoing arguments |
1694 low SP----> +-------------------------------+
1697 d30v_stack_t *
1698 d30v_stack_info ()
1700 static d30v_stack_t info, zero_info;
1701 d30v_stack_t *info_ptr = &info;
1702 tree fndecl = current_function_decl;
1703 tree fntype = TREE_TYPE (fndecl);
1704 int varargs_p = 0;
1705 tree cur_arg;
1706 tree next_arg;
1707 int saved_gprs;
1708 int saved_accs;
1709 int memrefs_2words;
1710 int memrefs_1word;
1711 unsigned char save_gpr_p[GPR_LAST];
1712 int i;
1714 /* If we've already calculated the values and reload is complete, just return now */
1715 if (d30v_stack_cache)
1716 return d30v_stack_cache;
1718 /* Zero all fields */
1719 info = zero_info;
1721 if (current_function_profile)
1722 regs_ever_live[GPR_LINK] = 1;
1724 /* Determine if this is a stdarg function */
1725 if (TYPE_ARG_TYPES (fntype) != 0
1726 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) != void_type_node))
1727 varargs_p = 1;
1728 else
1730 /* Find the last argument, and see if it is __builtin_va_alist. */
1731 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
1733 next_arg = TREE_CHAIN (cur_arg);
1734 if (next_arg == (tree)0)
1736 if (DECL_NAME (cur_arg)
1737 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
1738 varargs_p = 1;
1740 break;
1745 /* Calculate which registers need to be saved & save area size */
1746 saved_accs = 0;
1747 memrefs_2words = 0;
1748 memrefs_1word = 0;
1749 for (i = ACCUM_FIRST; i <= ACCUM_LAST; i++)
1751 if (regs_ever_live[i] && !call_used_regs[i])
1753 info_ptr->save_p[i] = 2;
1754 saved_accs++;
1755 memrefs_2words++;
1759 saved_gprs = 0;
1760 for (i = GPR_FIRST; i <= GPR_LAST; i++)
1762 if (regs_ever_live[i] && (!call_used_regs[i] || i == GPR_LINK))
1764 save_gpr_p[i] = 1;
1765 saved_gprs++;
1767 else
1768 save_gpr_p[i] = 0;
1771 /* Determine which register pairs can be saved together with ld2w/st2w */
1772 for (i = GPR_FIRST; i <= GPR_LAST; i++)
1774 if (((i - GPR_FIRST) & 1) == 0 && save_gpr_p[i] && save_gpr_p[i+1])
1776 memrefs_2words++;
1777 info_ptr->save_p[i++] = 2;
1779 else if (save_gpr_p[i])
1781 memrefs_1word++;
1782 info_ptr->save_p[i] = 1;
1786 /* Determine various sizes */
1787 info_ptr->varargs_p = varargs_p;
1788 info_ptr->varargs_size = ((varargs_p)
1789 ? (GPR_ARG_LAST + 1 - GPR_ARG_FIRST) * UNITS_PER_WORD
1790 : 0);
1792 info_ptr->accum_size = 2 * UNITS_PER_WORD * saved_accs;
1793 info_ptr->gpr_size = D30V_ALIGN (UNITS_PER_WORD * saved_gprs,
1794 2 * UNITS_PER_WORD);
1795 info_ptr->vars_size = D30V_ALIGN (get_frame_size (), 2 * UNITS_PER_WORD);
1796 info_ptr->parm_size = D30V_ALIGN (current_function_outgoing_args_size,
1797 2 * UNITS_PER_WORD);
1799 info_ptr->total_size = D30V_ALIGN ((info_ptr->gpr_size
1800 + info_ptr->accum_size
1801 + info_ptr->vars_size
1802 + info_ptr->parm_size
1803 + info_ptr->varargs_size
1804 + current_function_pretend_args_size),
1805 (STACK_BOUNDARY / BITS_PER_UNIT));
1807 info_ptr->save_offset = (info_ptr->total_size
1808 - (current_function_pretend_args_size
1809 + info_ptr->varargs_size
1810 + info_ptr->gpr_size
1811 + info_ptr->accum_size));
1813 /* The link register is the last GPR saved, but there might be some padding
1814 bytes after it, so account for that. */
1815 info_ptr->link_offset = (info_ptr->total_size
1816 - (current_function_pretend_args_size
1817 + info_ptr->varargs_size
1818 + (info_ptr->gpr_size
1819 - UNITS_PER_WORD * saved_gprs)
1820 + UNITS_PER_WORD));
1822 info_ptr->memrefs_varargs = info_ptr->varargs_size / (2 * UNITS_PER_WORD);
1823 info_ptr->memrefs_2words = memrefs_2words;
1824 info_ptr->memrefs_1word = memrefs_1word;
1826 if (reload_completed)
1827 d30v_stack_cache = info_ptr;
1829 return info_ptr;
1833 /* Internal function to print all of the information about the stack */
1835 void
1836 debug_stack_info (info)
1837 d30v_stack_t *info;
1839 int i;
1841 if (!info)
1842 info = d30v_stack_info ();
1844 fprintf (stderr, "\nStack information for function %s:\n",
1845 ((current_function_decl && DECL_NAME (current_function_decl))
1846 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1847 : "<unknown>"));
1849 fprintf (stderr, "\tsave_offset = %d\n", info->save_offset);
1850 fprintf (stderr, "\tmemrefs_varargs = %d\n", info->memrefs_varargs);
1851 fprintf (stderr, "\tmemrefs_2words = %d\n", info->memrefs_2words);
1852 fprintf (stderr, "\tmemrefs_1word = %d\n", info->memrefs_1word);
1853 fprintf (stderr, "\tvarargs_p = %d\n", info->varargs_p);
1854 fprintf (stderr, "\tvarargs_size = %d\n", info->varargs_size);
1855 fprintf (stderr, "\tvars_size = %d\n", info->vars_size);
1856 fprintf (stderr, "\tparm_size = %d\n", info->parm_size);
1857 fprintf (stderr, "\tgpr_size = %d\n", info->gpr_size);
1858 fprintf (stderr, "\taccum_size = %d\n", info->accum_size);
1859 fprintf (stderr, "\ttotal_size = %d\n", info->total_size);
1860 fprintf (stderr, "\tsaved registers =");
1862 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1864 if (info->save_p[i] == 2)
1866 fprintf (stderr, " %s-%s", reg_names[i], reg_names[i+1]);
1867 i++;
1869 else if (info->save_p[i])
1870 fprintf (stderr, " %s", reg_names[i]);
1873 putc ('\n', stderr);
1874 fflush (stderr);
1878 /* Return nonzero if this function is known to have a null or 1 instruction epilogue. */
1881 direct_return ()
1883 if (reload_completed)
1885 d30v_stack_t *info = d30v_stack_info ();
1887 /* If no epilogue code is needed, can use just a simple jump */
1888 if (info->total_size == 0)
1889 return 1;
1891 #if 0
1892 /* If just a small amount of local stack was allocated and no registers
1893 saved, skip forward branch */
1894 if (info->total_size == info->vars_size
1895 && IN_RANGE_P (info->total_size, 1, 31))
1896 return 1;
1897 #endif
1900 return 0;
1904 /* A C statement (sans semicolon) for initializing the variable CUM for the
1905 state at the beginning of the argument list. The variable has type
1906 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
1907 of the function which will receive the args, or 0 if the args are to a
1908 compiler support library function.
1910 The value of FNDECL is NULL for indirect calls (eg via a function pointer)
1911 and library calls. For direct calls, and when INIT_CUMULATIVE_ARGS is
1912 being used to find arguments for the function being compiled it contains
1913 the declaration node of FNTYPE.
1915 When processing a call to a compiler support library function, LIBNAME
1916 identifies which one. It is a `symbol_ref' rtx which contains the name of
1917 the function, as a string. LIBNAME is 0 when an ordinary C function call
1918 is being processed. Thus, each time this macro is called, either LIBNAME
1919 or FNTYPE is nonzero, but never both of them at once. */
1921 void
1922 d30v_init_cumulative_args (cum, fntype, libname, fndecl, incoming)
1923 CUMULATIVE_ARGS *cum;
1924 tree fntype;
1925 rtx libname;
1926 tree fndecl;
1927 int incoming;
1929 *cum = GPR_ARG_FIRST;
1931 if (TARGET_DEBUG_ARG)
1933 fprintf (stderr, "\ninit_cumulative_args:");
1934 if (!fndecl && fntype)
1935 fputs (" indirect", stderr);
1937 if (incoming)
1938 fputs (" incoming", stderr);
1940 if (fntype)
1942 tree ret_type = TREE_TYPE (fntype);
1943 fprintf (stderr, " return=%s,",
1944 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1947 if (libname && GET_CODE (libname) == SYMBOL_REF)
1948 fprintf (stderr, " libname=%s", XSTR (libname, 0));
1950 putc ('\n', stderr);
1955 /* If defined, a C expression that gives the alignment boundary, in bits, of an
1956 argument with the specified mode and type. If it is not defined,
1957 `PARM_BOUNDARY' is used for all arguments. */
1960 d30v_function_arg_boundary (mode, type)
1961 enum machine_mode mode;
1962 tree type;
1964 int size = ((mode == BLKmode && type)
1965 ? int_size_in_bytes (type)
1966 : (int) GET_MODE_SIZE (mode));
1968 return (size > UNITS_PER_WORD) ? 2*UNITS_PER_WORD : UNITS_PER_WORD;
1972 /* A C expression that controls whether a function argument is passed in a
1973 register, and which register.
1975 The arguments are CUM, which summarizes all the previous arguments; MODE,
1976 the machine mode of the argument; TYPE, the data type of the argument as a
1977 tree node or 0 if that is not known (which happens for C support library
1978 functions); and NAMED, which is 1 for an ordinary argument and 0 for
1979 nameless arguments that correspond to `...' in the called function's
1980 prototype.
1982 The value of the expression should either be a `reg' RTX for the hard
1983 register in which to pass the argument, or zero to pass the argument on the
1984 stack.
1986 For machines like the VAX and 68000, where normally all arguments are
1987 pushed, zero suffices as a definition.
1989 The usual way to make the ANSI library `stdarg.h' work on a machine where
1990 some arguments are usually passed in registers, is to cause nameless
1991 arguments to be passed on the stack instead. This is done by making
1992 `FUNCTION_ARG' return 0 whenever NAMED is 0.
1994 You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the definition of
1995 this macro to determine if this argument is of a type that must be passed in
1996 the stack. If `REG_PARM_STACK_SPACE' is not defined and `FUNCTION_ARG'
1997 returns nonzero for such an argument, the compiler will abort. If
1998 `REG_PARM_STACK_SPACE' is defined, the argument will be computed in the
1999 stack and then loaded into a register. */
2002 d30v_function_arg (cum, mode, type, named, incoming)
2003 CUMULATIVE_ARGS *cum;
2004 enum machine_mode mode;
2005 tree type;
2006 int named;
2007 int incoming ATTRIBUTE_UNUSED;
2009 int size = ((mode == BLKmode && type)
2010 ? int_size_in_bytes (type)
2011 : (int) GET_MODE_SIZE (mode));
2012 int adjust = (size > UNITS_PER_WORD && (*cum & 1) != 0);
2013 rtx ret;
2015 /* Return a marker for use in the call instruction. */
2016 if (mode == VOIDmode)
2017 ret = const0_rtx;
2019 else if (*cum + adjust <= GPR_ARG_LAST)
2020 ret = gen_rtx (REG, mode, *cum + adjust);
2022 else
2023 ret = NULL_RTX;
2025 if (TARGET_DEBUG_ARG)
2026 fprintf (stderr,
2027 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, adjust = %1d, arg = %s\n",
2028 *cum, GET_MODE_NAME (mode), named, size, adjust,
2029 (ret) ? ((ret == const0_rtx) ? "<0>" : reg_names[ REGNO (ret) ]) : "memory");
2031 return ret;
2035 /* A C expression for the number of words, at the beginning of an argument,
2036 must be put in registers. The value must be zero for arguments that are
2037 passed entirely in registers or that are entirely pushed on the stack.
2039 On some machines, certain arguments must be passed partially in registers
2040 and partially in memory. On these machines, typically the first N words of
2041 arguments are passed in registers, and the rest on the stack. If a
2042 multi-word argument (a `double' or a structure) crosses that boundary, its
2043 first few words must be passed in registers and the rest must be pushed.
2044 This macro tells the compiler when this occurs, and how many of the words
2045 should go in registers.
2047 `FUNCTION_ARG' for these arguments should return the first register to be
2048 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
2049 the called function. */
2052 d30v_function_arg_partial_nregs (cum, mode, type, named)
2053 CUMULATIVE_ARGS *cum;
2054 enum machine_mode mode;
2055 tree type;
2056 int named ATTRIBUTE_UNUSED;
2058 int bytes = ((mode == BLKmode)
2059 ? int_size_in_bytes (type)
2060 : (int) GET_MODE_SIZE (mode));
2061 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2062 int adjust = (bytes > UNITS_PER_WORD && (*cum & 1) != 0);
2063 int arg_num = *cum + adjust;
2064 int ret;
2066 ret = ((arg_num <= GPR_ARG_LAST && arg_num + words > GPR_ARG_LAST+1)
2067 ? GPR_ARG_LAST - arg_num + 1
2068 : 0);
2070 if (TARGET_DEBUG_ARG && ret)
2071 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2073 return ret;
2077 /* A C expression that indicates when an argument must be passed by reference.
2078 If nonzero for an argument, a copy of that argument is made in memory and a
2079 pointer to the argument is passed instead of the argument itself. The
2080 pointer is passed in whatever way is appropriate for passing a pointer to
2081 that type.
2083 On machines where `REG_PARM_STACK_SPACE' is not defined, a suitable
2084 definition of this macro might be
2085 #define FUNCTION_ARG_PASS_BY_REFERENCE\
2086 (CUM, MODE, TYPE, NAMED) \
2087 MUST_PASS_IN_STACK (MODE, TYPE) */
2090 d30v_function_arg_pass_by_reference (cum, mode, type, named)
2091 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2092 enum machine_mode mode;
2093 tree type;
2094 int named ATTRIBUTE_UNUSED;
2096 int ret = MUST_PASS_IN_STACK (mode, type);
2098 if (TARGET_DEBUG_ARG && ret)
2099 fprintf (stderr, "function_arg_pass_by_reference: %d\n", ret);
2101 return ret;
2105 /* A C statement (sans semicolon) to update the summarizer variable CUM to
2106 advance past an argument in the argument list. The values MODE, TYPE and
2107 NAMED describe that argument. Once this is done, the variable CUM is
2108 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
2110 This macro need not do anything if the argument in question was passed on
2111 the stack. The compiler knows how to track the amount of stack space used
2112 for arguments without any special help. */
2114 void
2115 d30v_function_arg_advance (cum, mode, type, named)
2116 CUMULATIVE_ARGS *cum;
2117 enum machine_mode mode;
2118 tree type;
2119 int named;
2121 int bytes = ((mode == BLKmode)
2122 ? int_size_in_bytes (type)
2123 : (int) GET_MODE_SIZE (mode));
2124 int words = D30V_ALIGN (bytes, UNITS_PER_WORD) / UNITS_PER_WORD;
2125 int adjust = (bytes > UNITS_PER_WORD && (*cum & 1) != 0);
2127 *cum += words + adjust;
2129 if (TARGET_DEBUG_ARG)
2130 fprintf (stderr,
2131 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d, adjust = %1d\n",
2132 *cum, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD, adjust);
2136 /* If defined, is a C expression that produces the machine-specific code for a
2137 call to `__builtin_saveregs'. This code will be moved to the very beginning
2138 of the function, before any parameter access are made. The return value of
2139 this function should be an RTX that contains the value to use as the return
2140 of `__builtin_saveregs'.
2142 If this macro is not defined, the compiler will output an ordinary call to
2143 the library function `__builtin_saveregs'. */
2146 d30v_expand_builtin_saveregs ()
2148 int offset = UNITS_PER_WORD * (GPR_ARG_LAST + 1 - GPR_ARG_FIRST);
2150 if (TARGET_DEBUG_ARG)
2151 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2152 offset);
2154 return gen_rtx (PLUS, Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2158 /* This macro offers an alternative to using `__builtin_saveregs' and defining
2159 the macro `EXPAND_BUILTIN_SAVEREGS'. Use it to store the anonymous register
2160 arguments into the stack so that all the arguments appear to have been
2161 passed consecutively on the stack. Once this is done, you can use the
2162 standard implementation of varargs that works for machines that pass all
2163 their arguments on the stack.
2165 The argument ARGS_SO_FAR is the `CUMULATIVE_ARGS' data structure, containing
2166 the values that obtain after processing of the named arguments. The
2167 arguments MODE and TYPE describe the last named argument--its machine mode
2168 and its data type as a tree node.
2170 The macro implementation should do two things: first, push onto the stack
2171 all the argument registers *not* used for the named arguments, and second,
2172 store the size of the data thus pushed into the `int'-valued variable whose
2173 name is supplied as the argument PRETEND_ARGS_SIZE. The value that you
2174 store here will serve as additional offset for setting up the stack frame.
2176 Because you must generate code to push the anonymous arguments at compile
2177 time without knowing their data types, `SETUP_INCOMING_VARARGS' is only
2178 useful on machines that have just a single category of argument register and
2179 use it uniformly for all data types.
2181 If the argument SECOND_TIME is nonzero, it means that the arguments of the
2182 function are being analyzed for the second time. This happens for an inline
2183 function, which is not actually compiled until the end of the source file.
2184 The macro `SETUP_INCOMING_VARARGS' should not generate any instructions in
2185 this case. */
2187 void
2188 d30v_setup_incoming_varargs (cum, mode, type, pretend_size, second_time)
2189 CUMULATIVE_ARGS *cum;
2190 enum machine_mode mode;
2191 tree type ATTRIBUTE_UNUSED;
2192 int *pretend_size ATTRIBUTE_UNUSED;
2193 int second_time;
2195 if (TARGET_DEBUG_ARG)
2196 fprintf (stderr,
2197 "setup_vararg: words = %2d, mode = %4s, second_time = %d\n",
2198 *cum, GET_MODE_NAME (mode), second_time);
2202 /* Create the va_list data type. */
2204 tree
2205 d30v_build_va_list ()
2207 tree f_arg_ptr, f_arg_num, record, type_decl;
2208 tree int_type_node;
2210 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
2211 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2212 int_type_node = make_signed_type (INT_TYPE_SIZE);
2214 f_arg_ptr = build_decl (FIELD_DECL, get_identifier ("__va_arg_ptr"),
2215 ptr_type_node);
2216 f_arg_num = build_decl (FIELD_DECL, get_identifier ("__va_arg_num"),
2217 int_type_node);
2219 DECL_FIELD_CONTEXT (f_arg_ptr) = record;
2220 DECL_FIELD_CONTEXT (f_arg_num) = record;
2222 TREE_CHAIN (record) = type_decl;
2223 TYPE_NAME (record) = type_decl;
2224 TYPE_FIELDS (record) = f_arg_ptr;
2225 TREE_CHAIN (f_arg_ptr) = f_arg_num;
2227 layout_type (record);
2229 /* The correct type is an array type of one element. */
2230 return build_array_type (record, build_index_type (size_zero_node));
2234 /* Expand __builtin_va_start to do the va_start macro. */
2236 void
2237 d30v_expand_builtin_va_start (valist, nextarg)
2238 tree valist;
2239 rtx nextarg ATTRIBUTE_UNUSED;
2241 HOST_WIDE_INT words;
2242 tree f_arg_ptr, f_arg_num;
2243 tree arg_ptr, arg_num, saveregs, t;
2245 f_arg_ptr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2246 f_arg_num = TREE_CHAIN (f_arg_ptr);
2248 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2249 arg_ptr = build (COMPONENT_REF, TREE_TYPE (f_arg_ptr), valist, f_arg_ptr);
2250 arg_num = build (COMPONENT_REF, TREE_TYPE (f_arg_num), valist, f_arg_num);
2252 words = current_function_args_info; /* __builtin_args_info (0) */
2254 /* (AP)->__va_arg_ptr = (int *) __builtin_saveregs (); */
2255 saveregs = make_tree (TREE_TYPE (arg_ptr), d30v_expand_builtin_saveregs ());
2256 t = build (MODIFY_EXPR, TREE_TYPE (arg_ptr), arg_ptr, saveregs);
2257 TREE_SIDE_EFFECTS (t) = 1;
2258 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2260 /* (AP)->__va_arg_num = __builtin_args_info (0) - 2; */
2261 t = build (PLUS_EXPR, TREE_TYPE (arg_num), build_int_2 (words, 0),
2262 build_int_2 (-GPR_ARG_FIRST, 0));
2263 t = build (MODIFY_EXPR, TREE_TYPE (arg_num), arg_num, t);
2264 TREE_SIDE_EFFECTS (t) = 1;
2265 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2269 /* Expand __builtin_va_arg to do the va_arg macro. */
2272 d30v_expand_builtin_va_arg(valist, type)
2273 tree valist;
2274 tree type;
2276 tree f_arg_ptr, f_arg_num;
2277 tree arg_ptr, arg_num, t, ptr;
2278 int num, size;
2279 rtx lab_false, ptr_rtx, r;
2281 f_arg_ptr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2282 f_arg_num = TREE_CHAIN (f_arg_ptr);
2284 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2285 arg_ptr = build (COMPONENT_REF, TREE_TYPE (f_arg_ptr), valist, f_arg_ptr);
2286 arg_num = build (COMPONENT_REF, TREE_TYPE (f_arg_num), valist, f_arg_num);
2288 size = int_size_in_bytes (type);
2290 lab_false = gen_label_rtx ();
2291 ptr_rtx = gen_reg_rtx (Pmode);
2293 /* if (sizeof (TYPE) > 4 && ((AP)->__va_arg_num & 1) != 0)
2294 (AP)->__va_arg_num++; */
2296 if (size > UNITS_PER_WORD)
2298 t = build (BIT_AND_EXPR, TREE_TYPE (arg_num), arg_num,
2299 build_int_2 (1, 0));
2301 emit_cmp_and_jump_insns (expand_expr (t, NULL_RTX, QImode, EXPAND_NORMAL),
2302 GEN_INT (0), EQ, const1_rtx, QImode, 1,
2303 lab_false);
2305 t = build (POSTINCREMENT_EXPR, TREE_TYPE (arg_num), arg_num,
2306 build_int_2 (1, 0));
2307 TREE_SIDE_EFFECTS (t) = 1;
2308 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2310 emit_label (lab_false);
2314 /* __ptr = (TYPE *)(((char *)(void *)((AP)->__va_arg_ptr
2315 + (AP)->__va_arg_num))); */
2317 t = build (MULT_EXPR, TREE_TYPE (arg_num), arg_num, build_int_2 (4, 0));
2318 t = build (PLUS_EXPR, ptr_type_node, arg_ptr, t);
2320 /* if (sizeof (TYPE) < 4)
2321 __ptr = (void *)__ptr + 4 - sizeof (TYPE); */
2323 if (size < UNITS_PER_WORD)
2324 t = build (PLUS_EXPR, ptr_type_node, t,
2325 build_int_2 (UNITS_PER_WORD - size, 0));
2327 TREE_SIDE_EFFECTS (t) = 1;
2329 ptr = build1 (NOP_EXPR, build_pointer_type (type), t);
2330 t = build (MODIFY_EXPR, type, ptr, t);
2332 r = expand_expr (t, ptr_rtx, Pmode, EXPAND_NORMAL);
2333 if (r != ptr_rtx)
2334 emit_move_insn (ptr_rtx, r);
2337 /* (AP)->__va_arg_num += (sizeof (TYPE) + 3) / 4; */
2338 num = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2339 t = build (POSTINCREMENT_EXPR, TREE_TYPE (arg_num), arg_num,
2340 build_int_2 (num, 0));
2341 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2343 return ptr_rtx;
2346 /* Generate the assembly code for function entry. FILE is a stdio
2347 stream to output the code to. SIZE is an int: how many units of
2348 temporary storage to allocate.
2350 Refer to the array `regs_ever_live' to determine which registers to
2351 save; `regs_ever_live[I]' is nonzero if register number I is ever
2352 used in the function. This function is responsible for knowing
2353 which registers should not be saved even if used. */
2355 static void
2356 d30v_output_function_prologue (stream, size)
2357 FILE *stream ATTRIBUTE_UNUSED;
2358 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
2360 /* For the d30v, move all of the prologue processing into separate
2361 insns. */
2365 /* Called after register allocation to add any instructions needed for
2366 the prologue. Using a prologue insn is favored compared to putting
2367 all of the instructions in output_function_prologue (), since it
2368 allows the scheduler to intermix instructions with the saves of the
2369 caller saved registers. In some cases, it might be necessary to
2370 emit a barrier instruction as the last insn to prevent such
2371 scheduling. */
2373 void
2374 d30v_expand_prologue ()
2376 rtx sp = stack_pointer_rtx;
2377 d30v_stack_t *info = d30v_stack_info ();
2378 int i;
2379 rtx mem_di = NULL_RTX;
2380 rtx mem_si = NULL_RTX;
2381 int num_memrefs = (info->memrefs_2words
2382 + info->memrefs_1word
2383 + info->memrefs_varargs);
2385 if (TARGET_DEBUG_STACK)
2386 debug_stack_info (info);
2388 /* Grow the stack. */
2389 if (info->total_size)
2390 emit_insn (gen_addsi3 (sp, sp, GEN_INT (- info->total_size)));
2392 /* If there is more than one save, use post-increment addressing which will
2393 result in smaller code, than would the normal references. If there is
2394 only one save, just do the store as normal. */
2396 if (num_memrefs > 1)
2398 rtx save_tmp = gen_rtx (REG, Pmode, GPR_STACK_TMP);
2399 rtx post_inc = gen_rtx (POST_INC, Pmode, save_tmp);
2400 mem_di = gen_rtx (MEM, DImode, post_inc);
2401 mem_si = gen_rtx (MEM, SImode, post_inc);
2402 emit_insn (gen_addsi3 (save_tmp, sp, GEN_INT (info->save_offset)));
2404 else if (num_memrefs == 1)
2406 rtx addr = plus_constant (sp, info->save_offset);
2407 mem_di = gen_rtx (MEM, DImode, addr);
2408 mem_si = gen_rtx (MEM, SImode, addr);
2411 /* Save the accumulators. */
2412 for (i = ACCUM_FIRST; i <= ACCUM_LAST; i++)
2413 if (info->save_p[i])
2415 rtx acc_tmp = gen_rtx (REG, DImode, GPR_ATMP_FIRST);
2416 emit_insn (gen_movdi (acc_tmp, gen_rtx (REG, DImode, i)));
2417 emit_insn (gen_movdi (mem_di, acc_tmp));
2420 /* Save the GPR registers that are adjacent to each other with st2w. */
2421 for (i = GPR_FIRST; i <= GPR_LAST; i += 2)
2422 if (info->save_p[i] == 2)
2423 emit_insn (gen_movdi (mem_di, gen_rtx (REG, DImode, i)));
2425 /* Save the GPR registers that need to be saved with a single word store. */
2426 for (i = GPR_FIRST; i <= GPR_LAST; i++)
2427 if (info->save_p[i] == 1)
2428 emit_insn (gen_movsi (mem_si, gen_rtx (REG, SImode, i)));
2430 /* Save the argument registers if this function accepts variable args. */
2431 if (info->varargs_p)
2433 /* Realign r22 if an odd # of GPRs were saved. */
2434 if ((info->memrefs_1word & 1) != 0)
2436 rtx save_tmp = XEXP (XEXP (mem_si, 0), 0);
2437 emit_insn (gen_addsi3 (save_tmp, save_tmp, GEN_INT (UNITS_PER_WORD)));
2440 for (i = GPR_ARG_FIRST; i <= GPR_ARG_LAST; i += 2)
2441 emit_insn (gen_movdi (mem_di, gen_rtx (REG, DImode, i)));
2444 /* Update the frame pointer. */
2445 if (frame_pointer_needed)
2446 emit_move_insn (frame_pointer_rtx, sp);
2448 /* Hack for now, to prevent scheduler from being too cleaver */
2449 emit_insn (gen_blockage ());
2453 /* This function generates the assembly code for function exit.
2454 Args are as for output_function_prologue ().
2456 The function epilogue should not depend on the current stack
2457 pointer! It should use the frame pointer only. This is mandatory
2458 because of alloca; we also take advantage of it to omit stack
2459 adjustments before returning. */
2461 static void
2462 d30v_output_function_epilogue (stream, size)
2463 FILE *stream ATTRIBUTE_UNUSED;
2464 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
2466 /* For the d30v, move all processing to be as insns, but do any
2467 cleanup here, since it is done after handling all of the insns. */
2468 d30v_stack_cache = (d30v_stack_t *)0; /* reset stack cache */
2473 /* Called after register allocation to add any instructions needed for
2474 the epilogue. Using an epilogue insn is favored compared to putting
2475 all of the instructions in output_function_prologue(), since it
2476 allows the scheduler to intermix instructions with the saves of the
2477 caller saved registers. In some cases, it might be necessary to
2478 emit a barrier instruction as the last insn to prevent such
2479 scheduling. */
2481 void
2482 d30v_expand_epilogue ()
2484 rtx sp = stack_pointer_rtx;
2485 d30v_stack_t *info = d30v_stack_info ();
2486 int i;
2487 rtx mem_di = NULL_RTX;
2488 rtx mem_si = NULL_RTX;
2489 rtx post_inc;
2490 int extra_stack;
2492 /* Hack for now, to prevent scheduler from being too cleaver */
2493 emit_insn (gen_blockage ());
2495 /* Restore sp from fp. */
2496 if (frame_pointer_needed)
2497 emit_move_insn (sp, frame_pointer_rtx);
2499 /* For the epilogue, use post-increment addressing all of the time. First
2500 adjust the sp, to eliminate all of the stack, except for the save area. */
2502 if (info->save_offset)
2503 emit_insn (gen_addsi3 (sp, sp, GEN_INT (info->save_offset)));
2505 post_inc = gen_rtx (POST_INC, Pmode, sp);
2506 mem_di = gen_rtx (MEM, DImode, post_inc);
2507 mem_si = gen_rtx (MEM, SImode, post_inc);
2509 /* Restore the accumulators. */
2510 for (i = ACCUM_FIRST; i <= ACCUM_LAST; i++)
2511 if (info->save_p[i])
2513 rtx acc_tmp = gen_rtx (REG, DImode, GPR_ATMP_FIRST);
2514 emit_insn (gen_movdi (acc_tmp, mem_di));
2515 emit_insn (gen_movdi (gen_rtx (REG, DImode, i), acc_tmp));
2518 /* Restore the GPR registers that are adjacent to each other with ld2w. */
2519 for (i = GPR_FIRST; i <= GPR_LAST; i += 2)
2520 if (info->save_p[i] == 2)
2521 emit_insn (gen_movdi (gen_rtx (REG, DImode, i), mem_di));
2523 /* Save the GPR registers that need to be saved with a single word store. */
2524 extra_stack = 0;
2525 for (i = GPR_FIRST; i <= GPR_LAST; i++)
2526 if (info->save_p[i] == 1)
2528 if (cfun->machine->eh_epilogue_sp_ofs && i == GPR_LINK)
2529 extra_stack = 4;
2530 else
2532 if (extra_stack)
2534 emit_insn (gen_addsi3 (sp, sp, GEN_INT (extra_stack)));
2535 extra_stack = 0;
2537 emit_insn (gen_movsi (gen_rtx (REG, SImode, i), mem_si));
2541 /* Release any remaining stack that was allocated for saving the
2542 varargs registers or because an odd # of registers were stored. */
2543 if ((info->memrefs_1word & 1) != 0)
2544 extra_stack += UNITS_PER_WORD;
2545 extra_stack += current_function_pretend_args_size + info->varargs_size;
2547 if (extra_stack)
2549 if (cfun->machine->eh_epilogue_sp_ofs)
2550 emit_insn (gen_addsi3 (cfun->machine->eh_epilogue_sp_ofs,
2551 cfun->machine->eh_epilogue_sp_ofs,
2552 GEN_INT (extra_stack)));
2553 else
2554 emit_insn (gen_addsi3 (sp, sp, GEN_INT (extra_stack)));
2556 if (cfun->machine->eh_epilogue_sp_ofs)
2557 emit_insn (gen_addsi3 (sp, sp, cfun->machine->eh_epilogue_sp_ofs));
2559 /* Now emit the return instruction. */
2560 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
2564 /* A C statement or compound statement to output to FILE some assembler code to
2565 call the profiling subroutine `mcount'. Before calling, the assembler code
2566 must load the address of a counter variable into a register where `mcount'
2567 expects to find the address. The name of this variable is `LP' followed by
2568 the number LABELNO, so you would generate the name using `LP%d' in a
2569 `fprintf'.
2571 The details of how the address should be passed to `mcount' are determined
2572 by your operating system environment, not by GCC. To figure them out,
2573 compile a small program for profiling using the system's installed C
2574 compiler and look at the assembler code that results. */
2576 void
2577 d30v_function_profiler (stream, labelno)
2578 FILE *stream;
2579 int labelno ATTRIBUTE_UNUSED;
2581 fprintf (stream, "# profile\n");
2585 /* Split a 64 bit item into an upper and a lower part. We specifically do not
2586 want to call gen_highpart/gen_lowpart on CONST_DOUBLEs since it will give us
2587 the wrong part for floating point in cross compilers, and split_double does
2588 not handle registers. Also abort if the register is not a general purpose
2589 register. */
2591 void
2592 d30v_split_double (value, p_high, p_low)
2593 rtx value;
2594 rtx *p_high;
2595 rtx *p_low;
2597 int offset = 0;
2598 int regno;
2600 if (!reload_completed)
2601 abort ();
2603 switch (GET_CODE (value))
2605 case SUBREG:
2606 if (GET_CODE (SUBREG_REG (value)) != REG)
2607 abort ();
2608 offset = subreg_regno_offset (REGNO (SUBREG_REG (value)),
2609 GET_MODE (SUBREG_REG (value)),
2610 SUBREG_BYTE (value),
2611 GET_MODE (value));
2612 value = SUBREG_REG (value);
2614 /* fall through */
2616 case REG:
2617 regno = REGNO (value) + offset;
2618 if (!GPR_P (regno))
2619 abort ();
2621 *p_high = gen_rtx (REG, SImode, regno);
2622 *p_low = gen_rtx (REG, SImode, regno+1);
2623 break;
2625 case CONST_INT:
2626 case CONST_DOUBLE:
2627 split_double (value, p_high, p_low);
2628 break;
2630 default:
2631 abort ();
2636 /* A C compound statement to output to stdio stream STREAM the assembler syntax
2637 for an instruction operand that is a memory reference whose address is X. X
2638 is an RTL expression. */
2640 void
2641 d30v_print_operand_address (stream, x)
2642 FILE *stream;
2643 rtx x;
2645 if (GET_CODE (x) == MEM)
2646 x = XEXP (x, 0);
2648 switch (GET_CODE (x))
2650 default:
2651 break;
2653 case REG:
2654 fputs (reg_names[ REGNO (x) ], stream);
2655 return;
2657 case CONST_INT:
2658 fprintf (stream, "%ld", (long) INTVAL (x));
2659 return;
2661 /* We wrap simple symbol refs inside a parenthesis, so that a name
2662 like `r2' is not taken for a register name. */
2663 case SYMBOL_REF:
2664 fputs ("(", stream);
2665 assemble_name (stream, XSTR (x, 0));
2666 fputs (")", stream);
2667 return;
2669 case LABEL_REF:
2670 case CONST:
2671 output_addr_const (stream, x);
2672 return;
2675 fatal_insn ("bad insn to d30v_print_operand_address:", x);
2679 /* Print a memory reference suitable for the ld/st instructions. */
2681 static void
2682 d30v_print_operand_memory_reference (stream, x)
2683 FILE *stream;
2684 rtx x;
2686 rtx x0 = NULL_RTX;
2687 rtx x1 = NULL_RTX;
2689 switch (GET_CODE (x))
2691 default:
2692 fatal_insn ("bad insn to d30v_print_operand_memory_reference:", x);
2693 break;
2695 case SUBREG:
2696 case REG:
2697 case POST_DEC:
2698 case POST_INC:
2699 x0 = x;
2700 break;
2702 case CONST_INT:
2703 case SYMBOL_REF:
2704 case LABEL_REF:
2705 case CONST:
2706 x1 = x;
2707 break;
2709 case PLUS:
2710 x0 = XEXP (x, 0);
2711 x1 = XEXP (x, 1);
2712 if (GET_CODE (x0) == CONST_INT || GET_CODE (x0) == SYMBOL_REF
2713 || GET_CODE (x0) == CONST || GET_CODE (x0) == LABEL_REF)
2715 x0 = XEXP (x, 1);
2716 x1 = XEXP (x, 0);
2718 break;
2721 fputs ("@(", stream);
2722 if (!x0)
2723 fputs (reg_names[GPR_R0], stream);
2725 else
2727 const char *suffix = "";
2728 int offset0 = 0;
2730 if (GET_CODE (x0) == SUBREG)
2732 offset0 = subreg_regno_offset (REGNO (SUBREG_REG (x0)),
2733 GET_MODE (SUBREG_REG (x0)),
2734 SUBREG_BYTE (x0),
2735 GET_MODE (x0));
2736 x0 = SUBREG_REG (x0);
2739 if (GET_CODE (x0) == POST_INC)
2741 x0 = XEXP (x0, 0);
2742 suffix = "+";
2744 else if (GET_CODE (x0) == POST_DEC)
2746 x0 = XEXP (x0, 0);
2747 suffix = "-";
2750 if (GET_CODE (x0) == REG && GPR_P (REGNO (x0)))
2751 fprintf (stream, "%s%s", reg_names[REGNO (x0) + offset0], suffix);
2752 else
2753 fatal_insn ("bad insn to d30v_print_operand_memory_reference:", x);
2756 fputs (",", stream);
2758 if (!x1)
2759 fputs (reg_names[GPR_R0], stream);
2761 else
2763 int offset1 = 0;
2765 switch (GET_CODE (x1))
2767 case SUBREG:
2768 offset1 = subreg_regno_offset (REGNO (SUBREG_REG (x1)),
2769 GET_MODE (SUBREG_REG (x1)),
2770 SUBREG_BYTE (x1),
2771 GET_MODE (x1));
2772 x1 = SUBREG_REG (x1);
2773 if (GET_CODE (x1) != REG)
2774 fatal_insn ("bad insn to d30v_print_operand_memory_reference:", x);
2776 /* fall through */
2777 case REG:
2778 fputs (reg_names[REGNO (x1) + offset1], stream);
2779 break;
2781 case CONST_INT:
2782 fprintf (stream, "%ld", (long) INTVAL (x1));
2783 break;
2785 case SYMBOL_REF:
2786 case LABEL_REF:
2787 case CONST:
2788 d30v_print_operand_address (stream, x1);
2789 break;
2791 default:
2792 fatal_insn ("bad insn to d30v_print_operand_memory_reference:", x);
2796 fputs (")", stream);
2800 /* A C compound statement to output to stdio stream STREAM the assembler syntax
2801 for an instruction operand X. X is an RTL expression.
2803 LETTER is a value that can be used to specify one of several ways of
2804 printing the operand. It is used when identical operands must be printed
2805 differently depending on the context. LETTER comes from the `%'
2806 specification that was used to request printing of the operand. If the
2807 specification was just `%DIGIT' then LETTER is 0; if the specification was
2808 `%LTR DIGIT' then LETTER is the ASCII code for LTR.
2810 If X is a register, this macro should print the register's name. The names
2811 can be found in an array `reg_names' whose type is `char *[]'. `reg_names'
2812 is initialized from `REGISTER_NAMES'.
2814 When the machine description has a specification `%PUNCT' (a `%' followed by
2815 a punctuation character), this macro is called with a null pointer for X and
2816 the punctuation character for LETTER.
2818 Standard operand flags that are handled elsewhere:
2819 `=' Output a number unique to each instruction in the compilation.
2820 `a' Substitute an operand as if it were a memory reference.
2821 `c' Omit the syntax that indicates an immediate operand.
2822 `l' Substitute a LABEL_REF into a jump instruction.
2823 `n' Like %cDIGIT, except negate the value before printing.
2825 The d30v specific operand flags are:
2826 `.' Print r0.
2827 `f' Print a SF constant as an int.
2828 `s' Subtract 32 and negate.
2829 `A' Print accumulator number without an `a' in front of it.
2830 `B' Print bit offset for BSET, etc. instructions.
2831 `E' Print u if this is zero extend, nothing if this is sign extend.
2832 `F' Emit /{f,t,x}{f,t,x} for executing a false condition.
2833 `L' Print the lower half of a 64 bit item.
2834 `M' Print a memory reference for ld/st instructions.
2835 `R' Return appropriate cmp instruction for relational test.
2836 `S' Subtract 32.
2837 `T' Emit /{f,t,x}{f,t,x} for executing a true condition.
2838 `U' Print the upper half of a 64 bit item. */
2840 void
2841 d30v_print_operand (stream, x, letter)
2842 FILE *stream;
2843 rtx x;
2844 int letter;
2846 enum rtx_code code = (x) ? GET_CODE (x) : NIL;
2847 rtx split_values[2];
2848 REAL_VALUE_TYPE rv;
2849 long num;
2850 int log;
2852 switch (letter)
2854 case '.': /* Output r0 */
2855 fputs (reg_names[GPR_R0], stream);
2856 break;
2858 case 'f': /* Print a SF floating constant as an int */
2859 if (GET_CODE (x) != CONST_DOUBLE)
2860 fatal_insn ("bad insn to d30v_print_operand, 'f' modifier:", x);
2862 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2863 REAL_VALUE_TO_TARGET_SINGLE (rv, num);
2864 fprintf (stream, "%ld", num);
2865 break;
2867 case 'A': /* Print accumulator number without an `a' in front of it. */
2868 if (GET_CODE (x) != REG || !ACCUM_P (REGNO (x)))
2869 fatal_insn ("bad insn to d30v_print_operand, 'A' modifier:", x);
2871 putc ('0' + REGNO (x) - ACCUM_FIRST, stream);
2872 break;
2874 case 'M': /* Print a memory reference for ld/st */
2875 if (GET_CODE (x) != MEM)
2876 fatal_insn ("bad insn to d30v_print_operand, 'M' modifier:", x);
2878 d30v_print_operand_memory_reference (stream, XEXP (x, 0));
2879 break;
2881 case 'L': /* print lower part of 64 bit item. */
2882 case 'U': /* print upper part of 64 bit item. */
2883 d30v_split_double (x, &split_values[0], &split_values[1]);
2884 d30v_print_operand (stream, split_values[ letter == 'L' ], '\0');
2885 break;
2887 case ':': /* Output the condition for the current insn. */
2888 x = current_insn_predicate;
2889 if (x == NULL_RTX)
2890 break;
2891 letter = 'T';
2892 /* FALLTHRU */
2894 case 'F': /* Print an appropriate suffix for a false comparison. */
2895 case 'T': /* Print an appropriate suffix for a true comparison. */
2896 /* Note that the sense of appropriate suffix is for conditional execution
2897 and opposite of what branches want. Branches just use the inverse
2898 operation. */
2899 if ((GET_CODE (x) == NE || GET_CODE (x) == EQ)
2900 && GET_MODE (x) == CCmode
2901 && GET_CODE (XEXP (x, 0)) == REG
2902 && (GPR_P (REGNO (XEXP (x, 0))) || BR_FLAG_P (REGNO (XEXP (x, 0))))
2903 && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
2905 int true_false = (letter == 'T');
2907 if (GET_CODE (x) == EQ)
2908 true_false = !true_false;
2910 if (REGNO (XEXP (x, 0)) == FLAG_F0)
2911 fprintf (stream, "/%cx", (true_false) ? 'f' : 't');
2913 else if (REGNO (XEXP (x, 0)) == FLAG_F1)
2914 fprintf (stream, "/x%c", (true_false) ? 'f' : 't');
2916 else
2917 fputs ((true_false) ? "tnz" : "tzr", stream);
2920 else if (GET_CODE (x) == REG && REGNO (x) == FLAG_F0)
2921 fprintf (stream, "/%cx", (letter == 'T') ? 't' : 'f');
2923 else if (GET_CODE (x) == REG && REGNO (x) == FLAG_F1)
2924 fprintf (stream, "/x%c", (letter == 'T') ? 't' : 'f');
2926 else if (GET_CODE (x) == REG && GPR_P (REGNO (x)))
2927 fputs ((letter == 'T') ? "tnz" : "tzr", stream);
2929 else
2930 fatal_insn ("bad insn to print_operand, 'F' or 'T' modifier:", x);
2931 break;
2933 case 'B': /* emit offset single bit to change */
2934 if (GET_CODE (x) == CONST_INT && (log = exact_log2 (INTVAL (x))) >= 0)
2935 fprintf (stream, "%d", 31 - log);
2937 else if (GET_CODE (x) == CONST_INT && (log = exact_log2 (~ INTVAL (x))) >= 0)
2938 fprintf (stream, "%d", 31 - log);
2940 else
2941 fatal_insn ("bad insn to print_operand, 'B' modifier:", x);
2942 break;
2944 case 'E': /* Print u if this is zero extend, nothing if sign extend. */
2945 if (GET_CODE (x) == ZERO_EXTEND)
2946 putc ('u', stream);
2947 else if (GET_CODE (x) != SIGN_EXTEND)
2948 fatal_insn ("bad insn to print_operand, 'E' modifier:", x);
2949 break;
2951 case 'R': /* Return appropriate cmp instruction for relational test. */
2952 switch (GET_CODE (x))
2954 case EQ: fputs ("cmpeq", stream); break;
2955 case NE: fputs ("cmpne", stream); break;
2956 case LT: fputs ("cmplt", stream); break;
2957 case LE: fputs ("cmple", stream); break;
2958 case GT: fputs ("cmpgt", stream); break;
2959 case GE: fputs ("cmpge", stream); break;
2960 case LTU: fputs ("cmpult", stream); break;
2961 case LEU: fputs ("cmpule", stream); break;
2962 case GTU: fputs ("cmpugt", stream); break;
2963 case GEU: fputs ("cmpuge", stream); break;
2965 default:
2966 fatal_insn ("bad insn to print_operand, 'R' modifier:", x);
2968 break;
2970 case 's': /* Subtract 32 and negate (for 64 bit shifts). */
2971 if (GET_CODE (x) == CONST_INT)
2972 fprintf (stream, "%d", (int) (32 - INTVAL (x)));
2974 else
2975 fatal_insn ("bad insn to print_operand, 's' modifier:", x);
2976 break;
2978 case 'S': /* Subtract 32. */
2979 if (GET_CODE (x) == CONST_INT)
2980 fprintf (stream, "%d", (int)(INTVAL (x) - 32));
2982 else
2983 fatal_insn ("bad insn to print_operand, 's' modifier:", x);
2984 break;
2987 case 'z': /* If arg is 0 or 0.0, print r0, otherwise print as normal */
2988 if ((GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
2989 || (GET_CODE (x) == CONST_DOUBLE && CONST_DOUBLE_LOW (x) == 0
2990 && CONST_DOUBLE_HIGH (x) == 0))
2992 fputs (reg_names[GPR_FIRST], stream);
2993 return;
2996 /* fall through */
2998 case '\0':
2999 if (code == REG)
3000 fputs (reg_names[ REGNO (x) ], stream);
3002 else if (code == CONST_INT)
3003 fprintf (stream, "%d", (int)INTVAL (x));
3005 else if (code == MEM)
3006 d30v_print_operand_address (stream, XEXP (x, 0));
3008 else if (CONSTANT_ADDRESS_P (x))
3009 d30v_print_operand_address (stream, x);
3011 else
3012 fatal_insn ("bad insn in d30v_print_operand, 0 case", x);
3014 return;
3016 default:
3018 char buf[80];
3020 sprintf (buf, "invalid asm template character '%%%c'", letter);
3021 fatal_insn (buf, x);
3027 /* A C expression for the size in bytes of the trampoline, as an integer. */
3030 d30v_trampoline_size ()
3032 return 16;
3036 /* Create a long instruction for building up a trampoline. */
3038 static void
3039 d30v_build_long_insn (high_bits, low_bits, imm, mem)
3040 HOST_WIDE_INT high_bits;
3041 HOST_WIDE_INT low_bits;
3042 rtx imm;
3043 rtx mem;
3045 rtx reg = gen_reg_rtx (DImode);
3046 rtx high_word = gen_highpart (SImode, reg);
3047 rtx low_word = gen_lowpart (SImode, reg);
3048 rtx tmp1 = gen_reg_rtx (SImode);
3049 rtx tmp2 = gen_reg_rtx (SImode);
3050 rtx tmp3 = gen_reg_rtx (SImode);
3051 rtx tmp4 = gen_reg_rtx (SImode);
3052 rtx tmp5 = gen_reg_rtx (SImode);
3053 rtx tmp6 = gen_reg_rtx (SImode);
3055 imm = force_reg (SImode, imm);
3057 /* Stuff top 6 bits of immediate value into high word */
3058 emit_insn (gen_lshrsi3 (tmp1, imm, GEN_INT (26)));
3059 emit_insn (gen_andsi3 (tmp2, tmp1, GEN_INT (0x3F)));
3060 emit_insn (gen_iorsi3 (high_word, tmp2, GEN_INT (high_bits)));
3062 /* Now get the next 8 bits for building the low word */
3063 emit_insn (gen_andsi3 (tmp3, imm, GEN_INT (0x03FC0000)));
3064 emit_insn (gen_ashlsi3 (tmp4, tmp3, GEN_INT (2)));
3066 /* And the bottom 18 bits */
3067 emit_insn (gen_andsi3 (tmp5, imm, GEN_INT (0x0003FFFF)));
3068 emit_insn (gen_iorsi3 (tmp6, tmp4, tmp5));
3069 emit_insn (gen_iorsi3 (low_word, tmp6, GEN_INT (low_bits)));
3071 /* Store the instruction */
3072 emit_insn (gen_movdi (mem, reg));
3076 /* A C statement to initialize the variable parts of a trampoline. ADDR is an
3077 RTX for the address of the trampoline; FNADDR is an RTX for the address of
3078 the nested function; STATIC_CHAIN is an RTX for the static chain value that
3079 should be passed to the function when it is called. */
3081 void
3082 d30v_initialize_trampoline (addr, fnaddr, static_chain)
3083 rtx addr;
3084 rtx fnaddr;
3085 rtx static_chain;
3087 /* The instruction space can only be accessed by ld2w/st2w.
3088 Generate on the fly:
3089 or r18,r0,<static-chain>
3090 jmp <fnaddr> */
3091 d30v_build_long_insn (0x83A80000 | ((STATIC_CHAIN_REGNUM - GPR_FIRST) << 12),
3092 0x80000000, static_chain,
3093 gen_rtx (MEM, DImode, addr));
3095 d30v_build_long_insn (0x80180000, 0x80000000, fnaddr,
3096 gen_rtx (MEM, DImode, plus_constant (addr, 8)));
3100 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3101 RTX) is a legitimate memory address on the target machine for a memory
3102 operand of mode MODE. */
3104 #define XREGNO_OK_FOR_BASE_P(REGNO, STRICT_P) \
3105 ((STRICT_P) \
3106 ? REGNO_OK_FOR_BASE_P (REGNO) \
3107 : GPR_OR_PSEUDO_P (REGNO))
3110 d30v_legitimate_address_p (mode, x, strict_p)
3111 enum machine_mode mode;
3112 rtx x;
3113 int strict_p;
3115 rtx x0, x1;
3116 int ret = 0;
3118 switch (GET_CODE (x))
3120 default:
3121 break;
3123 case SUBREG:
3124 x = SUBREG_REG (x);
3125 if (GET_CODE (x) != REG)
3126 break;
3128 /* fall through */
3130 case REG:
3131 ret = XREGNO_OK_FOR_BASE_P (REGNO (x), strict_p);
3132 break;
3134 case PLUS:
3135 x0 = XEXP (x, 0);
3136 x1 = XEXP (x, 1);
3138 if (GET_CODE (x0) == SUBREG)
3139 x0 = SUBREG_REG (x0);
3141 if (GET_CODE (x0) == POST_INC || GET_CODE (x0) == POST_DEC)
3142 x0 = XEXP (x0, 0);
3144 if (GET_CODE (x0) != REG || !XREGNO_OK_FOR_BASE_P (REGNO (x0), strict_p))
3145 break;
3147 switch (GET_CODE (x1))
3149 default:
3150 break;
3152 case SUBREG:
3153 x1 = SUBREG_REG (x1);
3154 if (GET_CODE (x1) != REG)
3155 break;
3157 /* fall through */
3159 case REG:
3160 ret = XREGNO_OK_FOR_BASE_P (REGNO (x1), strict_p);
3161 break;
3163 case CONST_INT:
3164 ret = (IN_RANGE_P (INTVAL (x1), -32, 31)) ? 1 : 2;
3165 break;
3167 case SYMBOL_REF:
3168 case LABEL_REF:
3169 case CONST:
3170 ret = 2;
3171 break;
3173 break;
3175 case CONST_INT:
3176 ret = (IN_RANGE_P (INTVAL (x), -32, 31)) ? 1 : 2;
3177 break;
3179 case SYMBOL_REF:
3180 case LABEL_REF:
3181 case CONST:
3182 ret = 2;
3183 break;
3185 case POST_INC:
3186 case POST_DEC:
3187 x0 = XEXP (x, 0);
3188 if (GET_CODE (x0) == REG && XREGNO_OK_FOR_BASE_P (REGNO (x0), strict_p))
3189 ret = 1;
3190 break;
3193 if (TARGET_DEBUG_ADDR)
3195 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict\n",
3196 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ");
3197 debug_rtx (x);
3200 return ret;
3204 /* A C compound statement that attempts to replace X with a valid memory
3205 address for an operand of mode MODE. WIN will be a C statement label
3206 elsewhere in the code; the macro definition may use
3208 GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
3210 to avoid further processing if the address has become legitimate.
3212 X will always be the result of a call to `break_out_memory_refs', and OLDX
3213 will be the operand that was given to that function to produce X.
3215 The code generated by this macro should not alter the substructure of X. If
3216 it transforms X into a more legitimate form, it should assign X (which will
3217 always be a C variable) a new value.
3219 It is not necessary for this macro to come up with a legitimate address.
3220 The compiler has standard ways of doing so in all cases. In fact, it is
3221 safe for this macro to do nothing. But often a machine-dependent strategy
3222 can generate better code. */
3225 d30v_legitimize_address (x, oldx, mode, strict_p)
3226 rtx x;
3227 rtx oldx ATTRIBUTE_UNUSED;
3228 enum machine_mode mode ATTRIBUTE_UNUSED;
3229 int strict_p ATTRIBUTE_UNUSED;
3231 rtx ret = NULL_RTX;
3233 if (TARGET_DEBUG_ADDR)
3235 if (ret)
3237 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, transformed:\n");
3238 debug_rtx (x);
3239 fprintf (stderr, "\ninto:\n");
3240 debug_rtx (ret);
3242 else
3244 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, did nothing with:\n");
3245 debug_rtx (x);
3249 return ret;
3253 /* A C statement or compound statement with a conditional `goto LABEL;'
3254 executed if memory address X (an RTX) can have different meanings depending
3255 on the machine mode of the memory reference it is used for or if the address
3256 is valid for some modes but not others.
3258 Autoincrement and autodecrement addresses typically have mode-dependent
3259 effects because the amount of the increment or decrement is the size of the
3260 operand being addressed. Some machines have other mode-dependent addresses.
3261 Many RISC machines have no mode-dependent addresses.
3263 You may assume that ADDR is a valid address for the machine. */
3266 d30v_mode_dependent_address_p (addr)
3267 rtx addr;
3269 switch (GET_CODE (addr))
3271 default:
3272 break;
3274 case POST_INC:
3275 case POST_DEC:
3276 return TRUE;
3279 return FALSE;
3283 /* Generate the appropriate comparison code for a test. */
3286 d30v_emit_comparison (test_int, result, arg1, arg2)
3287 int test_int;
3288 rtx result;
3289 rtx arg1;
3290 rtx arg2;
3292 enum rtx_code test = (enum rtx_code) test_int;
3293 enum machine_mode mode = GET_MODE (arg1);
3294 rtx rtx_test = gen_rtx (SET, VOIDmode, result, gen_rtx (test, CCmode, arg1, arg2));
3296 if (mode == SImode
3297 || (mode == DImode && (test == EQ || test == NE))
3298 || (mode == DImode && (test == LT || test == GE)
3299 && GET_CODE (arg2) == CONST_INT && INTVAL (arg2) == 0))
3300 return rtx_test;
3302 else if (mode == DImode)
3303 return gen_rtx (PARALLEL, VOIDmode,
3304 gen_rtvec (2,
3305 rtx_test,
3306 gen_rtx (CLOBBER, VOIDmode,
3307 gen_reg_rtx (CCmode))));
3309 else
3310 fatal_insn ("d30v_emit_comparison", rtx_test);
3314 /* Return appropriate code to move 2 words. Since DImode registers must start
3315 on even register numbers, there is no possibility of overlap. */
3317 const char *
3318 d30v_move_2words (operands, insn)
3319 rtx operands[];
3320 rtx insn;
3322 if (GET_CODE (operands[0]) == REG && GPR_P (REGNO (operands[0])))
3324 if (GET_CODE (operands[1]) == REG && GPR_P (REGNO (operands[1])))
3325 return "or %U0,%.,%U1\n\tor %L0,%.,%L1";
3327 else if (GET_CODE (operands[1]) == REG && ACCUM_P (REGNO (operands[1])))
3328 return "mvfacc %L0,%1,%.\n\tmvfacc %U0,%1,32";
3330 else if (GET_CODE (operands[1]) == MEM)
3331 return "ld2w %0,%M1";
3333 else if (GET_CODE (operands[1]) == CONST_INT
3334 || GET_CODE (operands[1]) == CONST_DOUBLE)
3335 return "or %U0,%.,%U1\n\tor %L0,%.,%L1";
3338 else if (GET_CODE (operands[0]) == REG && ACCUM_P (REGNO (operands[0])))
3340 if (GET_CODE (operands[1]) == REG
3341 && GPR_P (REGNO (operands[1])))
3342 return "mvtacc %0,%U1,%L1";
3344 if (GET_CODE (operands[1]) == CONST_INT
3345 && INTVAL (operands[1]) == 0)
3346 return "mvtacc %0,%.,%.";
3349 else if (GET_CODE (operands[0]) == MEM
3350 && GET_CODE (operands[1]) == REG
3351 && GPR_P (REGNO (operands[1])))
3352 return "st2w %1,%M0";
3354 fatal_insn ("bad call to d30v_move_2words", insn);
3358 /* Emit the code to do a conditional move instruction. Return FALSE
3359 if the conditional move could not be executed. */
3362 d30v_emit_cond_move (dest, test, true_value, false_value)
3363 rtx dest;
3364 rtx test;
3365 rtx true_value;
3366 rtx false_value;
3368 rtx br_reg;
3369 enum machine_mode mode = GET_MODE (dest);
3370 int two_mem_moves_p = FALSE;
3372 if (GET_CODE (dest) == MEM)
3374 if (!reg_or_0_operand (true_value, mode))
3375 return FALSE;
3377 if (rtx_equal_p (dest, false_value))
3378 two_mem_moves_p = TRUE;
3380 else if (!reg_or_0_operand (false_value, mode))
3381 return FALSE;
3384 /* We used to try to optimize setting 0/1 by using mvfsys, but that turns out
3385 to be slower than just doing the conditional execution. */
3387 br_reg = gen_reg_rtx (CCmode);
3388 emit_insn (d30v_emit_comparison (GET_CODE (test), br_reg,
3389 d30v_compare_op0, d30v_compare_op1));
3391 if (!two_mem_moves_p)
3392 emit_insn (gen_rtx_SET (VOIDmode,
3393 dest,
3394 gen_rtx_IF_THEN_ELSE (mode,
3395 gen_rtx_NE (CCmode, br_reg,
3396 const0_rtx),
3397 true_value,
3398 false_value)));
3399 else
3401 /* Emit conditional stores as two separate stores. This avoids a problem
3402 where you have a conditional store, and one of the arms of the
3403 conditional store is spilled to memory. */
3404 emit_insn (gen_rtx_SET (VOIDmode,
3405 dest,
3406 gen_rtx_IF_THEN_ELSE (mode,
3407 gen_rtx_NE (CCmode, br_reg,
3408 const0_rtx),
3409 true_value,
3410 dest)));
3412 emit_insn (gen_rtx_SET (VOIDmode,
3413 dest,
3414 gen_rtx_IF_THEN_ELSE (mode,
3415 gen_rtx_EQ (CCmode, br_reg,
3416 const0_rtx),
3417 false_value,
3418 dest)));
3422 return TRUE;
3426 /* A C statement (sans semicolon) to update the integer variable COST based on
3427 the relationship between INSN that is dependent on DEP_INSN through the
3428 dependence LINK. The default is to make no adjustment to COST. This can be
3429 used for example to specify to the scheduler that an output- or
3430 anti-dependence does not incur the same cost as a data-dependence. */
3432 /* For the d30v, try to insure that the source operands for a load/store are
3433 set 2 cycles before the memory reference. */
3435 static int
3436 d30v_adjust_cost (insn, link, dep_insn, cost)
3437 rtx insn;
3438 rtx link ATTRIBUTE_UNUSED;
3439 rtx dep_insn;
3440 int cost;
3442 rtx set_dep = single_set (dep_insn);
3443 rtx set_insn = single_set (insn);
3445 if (set_dep != NULL_RTX && set_insn != NULL_RTX
3446 && GET_CODE (SET_DEST (set_dep)) == REG)
3448 rtx reg = SET_DEST (set_dep);
3449 rtx mem;
3451 if ((GET_CODE (mem = SET_SRC (set_insn)) == MEM
3452 && reg_mentioned_p (reg, XEXP (mem, 0)))
3453 || (GET_CODE (mem = SET_DEST (set_insn)) == MEM
3454 && reg_mentioned_p (reg, XEXP (mem, 0))))
3456 return cost + 2;
3460 return cost;
3463 /* Function which returns the number of insns that can be
3464 scheduled in the same machine cycle. This must be constant
3465 over an entire compilation. The default is 1. */
3466 static int
3467 d30v_issue_rate ()
3469 return 2;
3473 /* Routine to allocate, mark and free a per-function,
3474 machine specific structure. */
3476 static struct machine_function *
3477 d30v_init_machine_status ()
3479 return ggc_alloc_cleared (sizeof (machine_function));
3482 /* Do anything needed before RTL is emitted for each function. */
3484 void
3485 d30v_init_expanders ()
3487 /* Arrange to save and restore machine status around nested functions. */
3488 init_machine_status = d30v_init_machine_status;
3491 /* Find the current function's return address.
3493 ??? It would be better to arrange things such that if we would ordinarily
3494 have been a leaf function and we didn't spill the hard reg that we
3495 wouldn't have to save the register in the prolog. But it's not clear
3496 how to get the right information at the right time. */
3499 d30v_return_addr ()
3501 return get_hard_reg_initial_val (Pmode, GPR_LINK);
3504 static bool
3505 d30v_rtx_costs (x, code, outer_code, total)
3506 rtx x;
3507 int code;
3508 int outer_code ATTRIBUTE_UNUSED;
3509 int *total;
3511 switch (code)
3513 case MULT:
3514 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT
3515 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
3516 ? 1 : 2);
3517 return true;
3519 default:
3520 return false;