d30v: New port.
[gcc.git] / gcc / config / d30v / d30v.c
1 /* Definitions of target machine for Mitsubishi D30V.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
4
5 This file is part of GNU CC.
6
7 GNU CC 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.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "tree.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "real.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-flags.h"
32 #include "output.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "recog.h"
36 #include "expr.h"
37 #include "obstack.h"
38 #include "tm_p.h"
39 #include "except.h"
40 #include "function.h"
41 #include "toplev.h"
42 #include "ggc.h"
43
44 static void d30v_print_operand_memory_reference PARAMS ((FILE *, rtx));
45 static void d30v_build_long_insn PARAMS ((HOST_WIDE_INT, HOST_WIDE_INT,
46 rtx, rtx));
47 static void d30v_add_gc_roots PARAMS ((void));
48
49 /* Define the information needed to generate branch and scc insns. This is
50 stored from the compare operation. */
51
52 struct rtx_def *d30v_compare_op0;
53 struct rtx_def *d30v_compare_op1;
54
55 /* Define the information needed to modify the epilogue for EH. */
56
57 rtx d30v_eh_epilogue_sp_ofs;
58
59 /* Cached value of d30v_stack_info */
60 static d30v_stack_t *d30v_stack_cache = (d30v_stack_t *)0;
61
62 /* Cache for __builtin_return_addr */
63 static rtx d30v_return_addr_rtx;
64
65 /* Values of the -mbranch-cost=n string. */
66 int d30v_branch_cost = D30V_DEFAULT_BRANCH_COST;
67 const char *d30v_branch_cost_string = (const char *)0;
68
69 /* Values of the -mcond-exec=n string. */
70 int d30v_cond_exec = D30V_DEFAULT_MAX_CONDITIONAL_EXECUTE;
71 const char *d30v_cond_exec_string = (const char *)0;
72
73 /* Whether or not a hard register can accept a register */
74 unsigned char hard_regno_mode_ok[ (int)MAX_MACHINE_MODE ][FIRST_PSEUDO_REGISTER];
75
76 /* Whether to try and avoid moves between two different modes */
77 unsigned char modes_tieable_p[ (NUM_MACHINE_MODES) * (NUM_MACHINE_MODES) ];
78
79 /* Map register number to smallest register class. */
80 enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER];
81
82 /* Map class letter into register class */
83 enum reg_class reg_class_from_letter[256];
84
85 \f
86 /* Sometimes certain combinations of command options do not make
87 sense on a particular target machine. You can define a macro
88 `OVERRIDE_OPTIONS' to take account of this. This macro, if
89 defined, is executed once just after all the command options have
90 been parsed.
91
92 Don't use this macro to turn on various extra optimizations for
93 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
94
95 void
96 override_options ()
97 {
98 int regno, i, ok_p;
99 enum machine_mode mode1, mode2;
100
101 /* Set up the branch cost information */
102 if (d30v_branch_cost_string)
103 d30v_branch_cost = atoi (d30v_branch_cost_string);
104
105 /* Set up max # instructions to use with conditional execution */
106 if (d30v_cond_exec_string)
107 d30v_cond_exec = atoi (d30v_cond_exec_string);
108
109 /* Setup hard_regno_mode_ok/modes_tieable_p */
110 for (mode1 = VOIDmode;
111 (int)mode1 < NUM_MACHINE_MODES;
112 mode1 = (enum machine_mode)((int)mode1 + 1))
113 {
114 int size = GET_MODE_SIZE (mode1);
115 int large_p = size > UNITS_PER_WORD;
116 int int_p = GET_MODE_CLASS (mode1) == MODE_INT;
117
118 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
119 {
120 if (mode1 == VOIDmode)
121 ok_p = FALSE;
122
123 else if (GPR_P (regno))
124 {
125 if (!large_p)
126 ok_p = TRUE;
127 else
128 ok_p = (((regno - GPR_FIRST) & 1) == 0);
129 }
130
131 else if (FLAG_P (regno))
132 ok_p = (mode1 == CCmode);
133
134 else if (CR_P (regno))
135 ok_p = int_p && !large_p;
136
137 else if (ACCUM_P (regno))
138 ok_p = (mode1 == DImode);
139
140 else if (SPECIAL_REG_P (regno))
141 ok_p = (mode1 == SImode);
142
143 else
144 ok_p = FALSE;
145
146 hard_regno_mode_ok[ (int)mode1 ][ regno ] = ok_p;
147 }
148
149 /* A C expression that is nonzero if it is desirable to choose
150 register allocation so as to avoid move instructions between a
151 value of mode MODE1 and a value of mode MODE2.
152
153 If `HARD_REGNO_MODE_OK (R, MODE1)' and `HARD_REGNO_MODE_OK (R,
154 MODE2)' are ever different for any R, then `MODES_TIEABLE_P (MODE1,
155 MODE2)' must be zero. */
156 for (mode2 = VOIDmode;
157 (int)mode2 <= NUM_MACHINE_MODES;
158 mode2 = (enum machine_mode)((int)mode2 + 1))
159 {
160 if (mode1 == mode2)
161 ok_p = TRUE;
162
163 #if 0
164 else if (GET_MODE_CLASS (mode1) == MODE_INT
165 && GET_MODE_SIZE (mode1) <= UNITS_PER_WORD
166 && GET_MODE_CLASS (mode2) == MODE_INT
167 && GET_MODE_SIZE (mode2) <= UNITS_PER_WORD)
168 ok_p = TRUE;
169 #endif
170
171 else
172 ok_p = FALSE;
173
174 modes_tieable_p[ ((int)mode1 * (NUM_MACHINE_MODES)) + (int)mode2 ] = ok_p;
175 }
176 }
177
178 #if 0
179 for (mode1 = VOIDmode;
180 (int)mode1 < NUM_MACHINE_MODES;
181 mode1 = (enum machine_mode)((int)mode1 + 1))
182 {
183 for (mode2 = VOIDmode;
184 (int)mode2 <= NUM_MACHINE_MODES;
185 mode2 = (enum machine_mode)((int)mode2 + 1))
186 {
187 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
188 if (ok_p
189 && (hard_regno_mode_ok[(int)mode1][regno]
190 != hard_regno_mode_ok[(int)mode2][regno]))
191 error ("Bad modes_tieable_p for register %s, mode1 %s, mode2 %s",
192 reg_names[regno], GET_MODE_NAME (mode1),
193 GET_MODE_NAME (mode2));
194 }
195 }
196 #endif
197
198 /* A C expression whose value is a register class containing hard
199 register REGNO. In general there is more than one such class;
200 choose a class which is "minimal", meaning that no smaller class
201 also contains the register. */
202 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
203 {
204 enum reg_class class;
205
206 if (GPR_P (regno))
207 class = (IN_RANGE_P (regno, GPR_FIRST+2, GPR_FIRST+62)
208 && ((regno - GPR_FIRST) & 1) == 0) ? EVEN_REGS : GPR_REGS;
209
210 else if (regno == FLAG_F0)
211 class = F0_REGS;
212
213 else if (regno == FLAG_F1)
214 class = F1_REGS;
215
216 else if (FLAG_P (regno))
217 class = OTHER_FLAG_REGS;
218
219 else if (ACCUM_P (regno))
220 class = ACCUM_REGS;
221
222 else if (regno == CR_RPT_C)
223 class = REPEAT_REGS;
224
225 else if (CR_P (regno))
226 class = CR_REGS;
227
228 else if (SPECIAL_REG_P (regno))
229 class = GPR_REGS;
230
231 else
232 class = NO_REGS;
233
234 regno_reg_class[regno] = class;
235
236 #if 0
237 {
238 static char *names[] = REG_CLASS_NAMES;
239 fprintf (stderr, "Register %s class is %s, can hold modes", reg_names[regno], names[class]);
240 for (mode1 = VOIDmode;
241 (int)mode1 < NUM_MACHINE_MODES;
242 mode1 = (enum machine_mode)((int)mode1 + 1))
243 {
244 if (hard_regno_mode_ok[ (int)mode1 ][ regno ])
245 fprintf (stderr, " %s", GET_MODE_NAME (mode1));
246 }
247 fprintf (stderr, "\n");
248 }
249 #endif
250 }
251
252 /* A C expression which defines the machine-dependent operand
253 constraint letters for register classes. If CHAR is such a
254 letter, the value should be the register class corresponding to
255 it. Otherwise, the value should be `NO_REGS'. The register
256 letter `r', corresponding to class `GENERAL_REGS', will not be
257 passed to this macro; you do not need to handle it.
258
259 The following letters are unavailable, due to being used as
260 constraints:
261 '0'..'9'
262 '<', '>'
263 'E', 'F', 'G', 'H'
264 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
265 'Q', 'R', 'S', 'T', 'U'
266 'V', 'X'
267 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
268
269 for (i = 0; i < 256; i++)
270 reg_class_from_letter[i] = NO_REGS;
271
272 reg_class_from_letter['a'] = ACCUM_REGS;
273 reg_class_from_letter['b'] = BR_FLAG_REGS;
274 reg_class_from_letter['c'] = CR_REGS;
275 reg_class_from_letter['d'] = GPR_REGS;
276 reg_class_from_letter['e'] = EVEN_REGS;
277 reg_class_from_letter['f'] = FLAG_REGS;
278 reg_class_from_letter['l'] = REPEAT_REGS;
279 reg_class_from_letter['x'] = F0_REGS;
280 reg_class_from_letter['y'] = F1_REGS;
281 reg_class_from_letter['z'] = OTHER_FLAG_REGS;
282
283 d30v_add_gc_roots ();
284 }
285
286 \f
287 /* Return true if a memory operand is a short memory operand. */
288
289 int
290 short_memory_operand (op, mode)
291 register rtx op;
292 enum machine_mode mode;
293 {
294 if (GET_CODE (op) != MEM)
295 return FALSE;
296
297 if (GET_MODE (op) != mode && mode != VOIDmode)
298 return FALSE;
299
300 return (d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed)
301 == 1);
302 }
303
304 /* Return true if a memory operand is a long operand. */
305
306 int
307 long_memory_operand (op, mode)
308 rtx op;
309 enum machine_mode mode;
310 {
311 if (GET_CODE (op) != MEM)
312 return FALSE;
313
314 if (GET_MODE (op) != mode && mode != VOIDmode)
315 return FALSE;
316
317 return (d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed)
318 == 2);
319 }
320
321 /* Return true if a memory operand is valid for the D30V. */
322
323 int
324 d30v_memory_operand (op, mode)
325 rtx op;
326 enum machine_mode mode;
327 {
328 if (GET_CODE (op) != MEM)
329 return FALSE;
330
331 if (GET_MODE (op) != mode && mode != VOIDmode)
332 return FALSE;
333
334 return (d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed)
335 != 0);
336 }
337
338 /* Return true if a memory operand uses a single register for the
339 address. */
340
341 int
342 single_reg_memory_operand (op, mode)
343 rtx op;
344 enum machine_mode mode;
345 {
346 rtx addr;
347
348 if (GET_CODE (op) != MEM)
349 return FALSE;
350
351 if (GET_MODE (op) != mode && mode != VOIDmode)
352 return FALSE;
353
354 addr = XEXP (op, 0);
355 if (! d30v_legitimate_address_p (mode, addr, reload_completed))
356 return FALSE;
357
358 if (GET_CODE (addr) == SUBREG)
359 addr = SUBREG_REG (addr);
360
361 return (GET_CODE (addr) == REG);
362 }
363
364 /* Return true if a memory operand uses a constant address. */
365
366 int
367 const_addr_memory_operand (op, mode)
368 rtx op;
369 enum machine_mode mode;
370 {
371 if (GET_CODE (op) != MEM)
372 return FALSE;
373
374 if (GET_MODE (op) != mode && mode != VOIDmode)
375 return FALSE;
376
377 if (! d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed))
378 return FALSE;
379
380 switch (GET_CODE (XEXP (op, 0)))
381 {
382 default:
383 break;
384
385 case SYMBOL_REF:
386 case LABEL_REF:
387 case CONST_INT:
388 case CONST:
389 return TRUE;
390 }
391
392 return FALSE;
393 }
394
395 /* Return true if operand is a memory reference suitable for a call. */
396
397 int
398 call_operand (op, mode)
399 rtx op;
400 enum machine_mode mode;
401 {
402 if (GET_CODE (op) != MEM)
403 return FALSE;
404
405 if (GET_MODE (op) != mode && mode != VOIDmode)
406 return FALSE;
407
408 if (! d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed))
409 return FALSE;
410
411 switch (GET_CODE (XEXP (op, 0)))
412 {
413 default:
414 break;
415
416 case SUBREG:
417 op = SUBREG_REG (op);
418 if (GET_CODE (op) != REG)
419 return FALSE;
420
421 /* fall through */
422
423 case REG:
424 return (GPR_OR_PSEUDO_P (REGNO (XEXP (op, 0))));
425
426 case SYMBOL_REF:
427 case LABEL_REF:
428 case CONST_INT:
429 case CONST:
430 return TRUE;
431 }
432
433 return FALSE;
434 }
435
436 /* Return true if operand is a GPR register. */
437
438 int
439 gpr_operand (op, mode)
440 rtx op;
441 enum machine_mode mode;
442 {
443 if (GET_MODE (op) != mode && mode != VOIDmode)
444 return FALSE;
445
446 if (GET_CODE (op) == SUBREG)
447 {
448 if (GET_CODE (SUBREG_REG (op)) != REG)
449 return register_operand (op, mode);
450
451 op = SUBREG_REG (op);
452 }
453
454 if (GET_CODE (op) != REG)
455 return FALSE;
456
457 return GPR_OR_PSEUDO_P (REGNO (op));
458 }
459
460 /* Return true if operand is an accumulator register. */
461
462 int
463 accum_operand (op, mode)
464 rtx op;
465 enum machine_mode mode;
466 {
467 if (GET_MODE (op) != mode && mode != VOIDmode)
468 return FALSE;
469
470 if (GET_CODE (op) == SUBREG)
471 {
472 if (GET_CODE (SUBREG_REG (op)) != REG)
473 return register_operand (op, mode);
474
475 op = SUBREG_REG (op);
476 }
477
478 if (GET_CODE (op) != REG)
479 return FALSE;
480
481 return ACCUM_OR_PSEUDO_P (REGNO (op));
482 }
483
484 /* Return true if operand is a GPR or an accumulator register. */
485
486 int
487 gpr_or_accum_operand (op, mode)
488 rtx op;
489 enum machine_mode mode;
490 {
491 if (GET_MODE (op) != mode && mode != VOIDmode)
492 return FALSE;
493
494 if (GET_CODE (op) == SUBREG)
495 {
496 if (GET_CODE (SUBREG_REG (op)) != REG)
497 return register_operand (op, mode);
498
499 op = SUBREG_REG (op);
500 }
501
502 if (GET_CODE (op) != REG)
503 return FALSE;
504
505 if (ACCUM_P (REGNO (op)))
506 return TRUE;
507
508 return GPR_OR_PSEUDO_P (REGNO (op));
509 }
510
511 /* Return true if operand is a CR register. */
512
513 int
514 cr_operand (op, mode)
515 rtx op;
516 enum machine_mode mode;
517 {
518 if (GET_MODE (op) != mode && mode != VOIDmode)
519 return FALSE;
520
521 if (GET_CODE (op) == SUBREG)
522 {
523 if (GET_CODE (SUBREG_REG (op)) != REG)
524 return register_operand (op, mode);
525
526 op = SUBREG_REG (op);
527 }
528
529 if (GET_CODE (op) != REG)
530 return FALSE;
531
532 return CR_OR_PSEUDO_P (REGNO (op));
533 }
534
535 /* Return true if operand is the repeat count register. */
536
537 int
538 repeat_operand (op, mode)
539 rtx op;
540 enum machine_mode mode;
541 {
542 if (GET_MODE (op) != mode && mode != VOIDmode)
543 return FALSE;
544
545 if (GET_CODE (op) == SUBREG)
546 {
547 if (GET_CODE (SUBREG_REG (op)) != REG)
548 return register_operand (op, mode);
549
550 op = SUBREG_REG (op);
551 }
552
553 if (GET_CODE (op) != REG)
554 return FALSE;
555
556 return (REGNO (op) == CR_RPT_C || REGNO (op) >= FIRST_PSEUDO_REGISTER);
557 }
558
559 /* Return true if operand is a FLAG register. */
560
561 int
562 flag_operand (op, mode)
563 rtx op;
564 enum machine_mode mode;
565 {
566 if (GET_MODE (op) != mode && mode != VOIDmode)
567 return FALSE;
568
569 if (GET_CODE (op) == SUBREG)
570 {
571 if (GET_CODE (SUBREG_REG (op)) != REG)
572 return register_operand (op, mode);
573
574 op = SUBREG_REG (op);
575 }
576
577 if (GET_CODE (op) != REG)
578 return FALSE;
579
580 return FLAG_OR_PSEUDO_P (REGNO (op));
581 }
582
583 /* Return true if operand is either F0 or F1. */
584
585 int
586 br_flag_operand (op, mode)
587 rtx op;
588 enum machine_mode mode;
589 {
590 if (GET_MODE (op) != mode && mode != VOIDmode)
591 return FALSE;
592
593 if (GET_CODE (op) == SUBREG)
594 {
595 if (GET_CODE (SUBREG_REG (op)) != REG)
596 return register_operand (op, mode);
597
598 op = SUBREG_REG (op);
599 }
600
601 if (GET_CODE (op) != REG)
602 return FALSE;
603
604 return BR_FLAG_OR_PSEUDO_P (REGNO (op));
605 }
606
607 /* Return true if operand is either F0/F1 or the constants 0/1. */
608
609 int
610 br_flag_or_constant_operand (op, mode)
611 rtx op;
612 enum machine_mode mode;
613 {
614 if (GET_MODE (op) != mode && mode != VOIDmode)
615 return FALSE;
616
617 if (GET_CODE (op) == SUBREG)
618 {
619 if (GET_CODE (SUBREG_REG (op)) != REG)
620 return register_operand (op, mode);
621
622 op = SUBREG_REG (op);
623 }
624
625 if (GET_CODE (op) == CONST_INT)
626 return (INTVAL (op) == 0 || INTVAL (op) == 1);
627
628 if (GET_CODE (op) != REG)
629 return FALSE;
630
631 return BR_FLAG_OR_PSEUDO_P (REGNO (op));
632 }
633
634 /* Return true if operand is either F0 or F1, or a GPR register. */
635
636 int
637 gpr_or_br_flag_operand (op, mode)
638 rtx op;
639 enum machine_mode mode;
640 {
641 if (GET_MODE (op) != mode && mode != VOIDmode)
642 return FALSE;
643
644 if (GET_CODE (op) == SUBREG)
645 {
646 if (GET_CODE (SUBREG_REG (op)) != REG)
647 return register_operand (op, mode);
648
649 op = SUBREG_REG (op);
650 }
651
652 if (GET_CODE (op) != REG)
653 return FALSE;
654
655 return GPR_OR_PSEUDO_P (REGNO (op)) || BR_FLAG_P (REGNO (op));
656 }
657
658 /* Return true if operand is the F0 register. */
659
660 int
661 f0_operand (op, mode)
662 rtx op;
663 enum machine_mode mode;
664 {
665 if (GET_MODE (op) != mode && mode != VOIDmode)
666 return FALSE;
667
668 if (GET_CODE (op) == SUBREG)
669 {
670 if (GET_CODE (SUBREG_REG (op)) != REG)
671 return register_operand (op, mode);
672
673 op = SUBREG_REG (op);
674 }
675
676 if (GET_CODE (op) != REG)
677 return FALSE;
678
679 return (REGNO (op) == FLAG_F0 || REGNO (op) >= FIRST_PSEUDO_REGISTER);
680 }
681
682 /* Return true if operand is the F1 register. */
683
684 int
685 f1_operand (op, mode)
686 rtx op;
687 enum machine_mode mode;
688 {
689 if (GET_MODE (op) != mode && mode != VOIDmode)
690 return FALSE;
691
692 if (GET_CODE (op) == SUBREG)
693 {
694 if (GET_CODE (SUBREG_REG (op)) != REG)
695 return register_operand (op, mode);
696
697 op = SUBREG_REG (op);
698 }
699
700 if (GET_CODE (op) != REG)
701 return FALSE;
702
703 return (REGNO (op) == FLAG_F1 || REGNO (op) >= FIRST_PSEUDO_REGISTER);
704 }
705
706 /* Return true if operand is the F1 register. */
707
708 int
709 carry_operand (op, mode)
710 rtx op;
711 enum machine_mode mode;
712 {
713 if (GET_MODE (op) != mode && mode != VOIDmode)
714 return FALSE;
715
716 if (GET_CODE (op) == SUBREG)
717 {
718 if (GET_CODE (SUBREG_REG (op)) != REG)
719 return register_operand (op, mode);
720
721 op = SUBREG_REG (op);
722 }
723
724 if (GET_CODE (op) != REG)
725 return FALSE;
726
727 return (REGNO (op) == FLAG_CARRY || REGNO (op) >= FIRST_PSEUDO_REGISTER);
728 }
729
730 /* Return true if operand is a register of any flavor or a 0 of the
731 appropriate type. */
732
733 int
734 reg_or_0_operand (op, mode)
735 rtx op;
736 enum machine_mode mode;
737 {
738 switch (GET_CODE (op))
739 {
740 default:
741 break;
742
743 case REG:
744 case SUBREG:
745 if (GET_MODE (op) != mode && mode != VOIDmode)
746 return FALSE;
747
748 return register_operand (op, mode);
749
750 case CONST_INT:
751 return INTVAL (op) == 0;
752
753 case CONST_DOUBLE:
754 return CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == 0;
755 }
756
757 return FALSE;
758 }
759
760 /* Return true if operand is a GPR register or a signed 6 bit immediate. */
761
762 int
763 gpr_or_signed6_operand (op, mode)
764 rtx op;
765 enum machine_mode mode;
766 {
767 if (GET_CODE (op) == SUBREG)
768 {
769 if (GET_CODE (SUBREG_REG (op)) != REG)
770 return register_operand (op, mode);
771
772 op = SUBREG_REG (op);
773 }
774
775 if (GET_CODE (op) == CONST_INT)
776 return IN_RANGE_P (INTVAL (op), -32, 31);
777
778 if (GET_CODE (op) != REG)
779 return FALSE;
780
781 if (GET_MODE (op) != mode && mode != VOIDmode)
782 return FALSE;
783
784 return GPR_OR_PSEUDO_P (REGNO (op));
785 }
786
787 /* Return true if operand is a GPR register or an unsigned 5 bit immediate. */
788
789 int
790 gpr_or_unsigned5_operand (op, mode)
791 rtx op;
792 enum machine_mode mode;
793 {
794 if (GET_CODE (op) == SUBREG)
795 {
796 if (GET_CODE (SUBREG_REG (op)) != REG)
797 return register_operand (op, mode);
798
799 op = SUBREG_REG (op);
800 }
801
802 if (GET_CODE (op) == CONST_INT)
803 return IN_RANGE_P (INTVAL (op), 0, 31);
804
805 if (GET_CODE (op) != REG)
806 return FALSE;
807
808 if (GET_MODE (op) != mode && mode != VOIDmode)
809 return FALSE;
810
811 return GPR_OR_PSEUDO_P (REGNO (op));
812 }
813
814 /* Return true if operand is a GPR register or an unsigned 6 bit immediate. */
815
816 int
817 gpr_or_unsigned6_operand (op, mode)
818 rtx op;
819 enum machine_mode mode;
820 {
821 if (GET_CODE (op) == SUBREG)
822 {
823 if (GET_CODE (SUBREG_REG (op)) != REG)
824 return register_operand (op, mode);
825
826 op = SUBREG_REG (op);
827 }
828
829 if (GET_CODE (op) == CONST_INT)
830 return IN_RANGE_P (INTVAL (op), 0, 63);
831
832 if (GET_CODE (op) != REG)
833 return FALSE;
834
835 if (GET_MODE (op) != mode && mode != VOIDmode)
836 return FALSE;
837
838 return GPR_OR_PSEUDO_P (REGNO (op));
839 }
840
841 /* Return true if operand is a GPR register or a constant of some form. */
842
843 int
844 gpr_or_constant_operand (op, mode)
845 rtx op;
846 enum machine_mode mode;
847 {
848 switch (GET_CODE (op))
849 {
850 default:
851 break;
852
853 case CONST_INT:
854 case SYMBOL_REF:
855 case LABEL_REF:
856 case CONST:
857 return TRUE;
858
859 case SUBREG:
860 if (GET_CODE (SUBREG_REG (op)) != REG)
861 return register_operand (op, mode);
862
863 op = SUBREG_REG (op);
864 /* fall through */
865
866 case REG:
867 if (GET_MODE (op) != mode && mode != VOIDmode)
868 return FALSE;
869
870 return GPR_OR_PSEUDO_P (REGNO (op));
871 }
872
873 return FALSE;
874 }
875
876 /* Return true if operand is a GPR register or a constant of some form,
877 including a CONST_DOUBLE, which gpr_or_constant_operand doesn't recognize. */
878
879 int
880 gpr_or_dbl_const_operand (op, mode)
881 rtx op;
882 enum machine_mode mode;
883 {
884 switch (GET_CODE (op))
885 {
886 default:
887 break;
888
889 case CONST_INT:
890 case CONST_DOUBLE:
891 case SYMBOL_REF:
892 case LABEL_REF:
893 case CONST:
894 return TRUE;
895
896 case SUBREG:
897 if (GET_CODE (SUBREG_REG (op)) != REG)
898 return register_operand (op, mode);
899
900 op = SUBREG_REG (op);
901 /* fall through */
902
903 case REG:
904 if (GET_MODE (op) != mode && mode != VOIDmode)
905 return FALSE;
906
907 return GPR_OR_PSEUDO_P (REGNO (op));
908 }
909
910 return FALSE;
911 }
912
913 /* Return true if operand is a gpr register or a valid memory operation. */
914
915 int
916 gpr_or_memory_operand (op, mode)
917 rtx op;
918 enum machine_mode mode;
919 {
920 switch (GET_CODE (op))
921 {
922 default:
923 break;
924
925 case SUBREG:
926 if (GET_CODE (SUBREG_REG (op)) != REG)
927 return register_operand (op, mode);
928
929 op = SUBREG_REG (op);
930 /* fall through */
931
932 case REG:
933 if (GET_MODE (op) != mode && mode != VOIDmode)
934 return FALSE;
935
936 return GPR_OR_PSEUDO_P (REGNO (op));
937
938 case MEM:
939 return d30v_legitimate_address_p (mode, XEXP (op, 0), reload_completed);
940 }
941
942 return FALSE;
943 }
944
945 /* Return true if operand is something that can be an input for a move
946 operation. */
947
948 int
949 move_input_operand (op, mode)
950 rtx op;
951 enum machine_mode mode;
952 {
953 rtx subreg;
954 enum rtx_code code;
955
956 switch (GET_CODE (op))
957 {
958 default:
959 break;
960
961 case CONST_INT:
962 case CONST_DOUBLE:
963 case SYMBOL_REF:
964 case LABEL_REF:
965 case CONST:
966 return TRUE;
967
968 case SUBREG:
969 if (GET_MODE (op) != mode && mode != VOIDmode)
970 return FALSE;
971
972 subreg = SUBREG_REG (op);
973 code = GET_CODE (subreg);
974 if (code == MEM)
975 return d30v_legitimate_address_p ((int)mode, XEXP (subreg, 0),
976 reload_completed);
977
978 return (code == REG);
979
980 case REG:
981 if (GET_MODE (op) != mode && mode != VOIDmode)
982 return FALSE;
983
984 return TRUE;
985
986 case MEM:
987 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
988 return TRUE;
989 return d30v_legitimate_address_p (mode, XEXP (op, 0),
990 reload_completed);
991 }
992
993 return FALSE;
994 }
995
996 /* Return true if operand is something that can be an output for a move
997 operation. */
998
999 int
1000 move_output_operand (op, mode)
1001 rtx op;
1002 enum machine_mode mode;
1003 {
1004 rtx subreg;
1005 enum rtx_code code;
1006
1007 switch (GET_CODE (op))
1008 {
1009 default:
1010 break;
1011
1012 case SUBREG:
1013 if (GET_MODE (op) != mode && mode != VOIDmode)
1014 return FALSE;
1015
1016 subreg = SUBREG_REG (op);
1017 code = GET_CODE (subreg);
1018 if (code == MEM)
1019 return d30v_legitimate_address_p ((int)mode, XEXP (subreg, 0),
1020 reload_completed);
1021
1022 return (code == REG);
1023
1024 case REG:
1025 if (GET_MODE (op) != mode && mode != VOIDmode)
1026 return FALSE;
1027
1028 return TRUE;
1029
1030 case MEM:
1031 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
1032 return TRUE;
1033 return d30v_legitimate_address_p (mode, XEXP (op, 0),
1034 reload_completed);
1035 }
1036
1037 return FALSE;
1038 }
1039
1040 /* Return true if operand is a signed 6 bit immediate. */
1041
1042 int
1043 signed6_operand (op, mode)
1044 rtx op;
1045 enum machine_mode mode ATTRIBUTE_UNUSED;
1046 {
1047 if (GET_CODE (op) == CONST_INT)
1048 return IN_RANGE_P (INTVAL (op), -32, 31);
1049
1050 return FALSE;
1051 }
1052
1053 /* Return true if operand is an unsigned 5 bit immediate. */
1054
1055 int
1056 unsigned5_operand (op, mode)
1057 rtx op;
1058 enum machine_mode mode ATTRIBUTE_UNUSED;
1059 {
1060 if (GET_CODE (op) == CONST_INT)
1061 return IN_RANGE_P (INTVAL (op), 0, 31);
1062
1063 return FALSE;
1064 }
1065
1066 /* Return true if operand is an unsigned 6 bit immediate. */
1067
1068 int
1069 unsigned6_operand (op, mode)
1070 rtx op;
1071 enum machine_mode mode ATTRIBUTE_UNUSED;
1072 {
1073 if (GET_CODE (op) == CONST_INT)
1074 return IN_RANGE_P (INTVAL (op), 0, 63);
1075
1076 return FALSE;
1077 }
1078
1079 /* Return true if operand is a constant with a single bit set. */
1080
1081 int
1082 bitset_operand (op, mode)
1083 rtx op;
1084 enum machine_mode mode ATTRIBUTE_UNUSED;
1085 {
1086 if (GET_CODE (op) == CONST_INT)
1087 return IN_RANGE_P (exact_log2 (INTVAL (op)), 0, 31);
1088
1089 return FALSE;
1090 }
1091
1092 /* Return true if the operator is a ==/!= test against f0 or f1 that can be
1093 used in conditional execution. */
1094
1095 int
1096 condexec_test_operator (op, mode)
1097 rtx op;
1098 enum machine_mode mode;
1099 {
1100 rtx x0, x1;
1101
1102 if (GET_MODE (op) != mode && mode != VOIDmode)
1103 return FALSE;
1104
1105 if (GET_CODE (op) != EQ && GET_CODE (op) != NE)
1106 return FALSE;
1107
1108 x0 = XEXP (op, 0);
1109 if (GET_CODE (x0) != REG || !BR_FLAG_OR_PSEUDO_P (REGNO (x0)))
1110 return FALSE;
1111
1112 x1 = XEXP (op, 1);
1113 if (GET_CODE (x1) != CONST_INT || INTVAL (x1) != 0)
1114 return FALSE;
1115
1116 return TRUE;
1117 }
1118
1119 /* Return true if the operator is a ==/!= test against f0, f1, or a general
1120 register that can be used in a branch instruction. */
1121
1122 int
1123 condexec_branch_operator (op, mode)
1124 rtx op;
1125 enum machine_mode mode;
1126 {
1127 rtx x0, x1;
1128
1129 if (GET_MODE (op) != mode && mode != VOIDmode)
1130 return FALSE;
1131
1132 if (GET_CODE (op) != EQ && GET_CODE (op) != NE)
1133 return FALSE;
1134
1135 x0 = XEXP (op, 0);
1136 if (GET_CODE (x0) == REG)
1137 {
1138 int regno = REGNO (x0);
1139 if (!GPR_OR_PSEUDO_P (regno) && !BR_FLAG_P (regno))
1140 return FALSE;
1141 }
1142 /* Allow the optimizer to generate things like:
1143 (if_then_else (ne (const_int 1) (const_int 0))) */
1144 else if (GET_CODE (x0) != CONST_INT)
1145 return FALSE;
1146
1147 x1 = XEXP (op, 1);
1148 if (GET_CODE (x1) != CONST_INT || INTVAL (x1) != 0)
1149 return FALSE;
1150
1151 return TRUE;
1152 }
1153
1154 /* Return true if the unary operator can be executed with conditional
1155 execution. */
1156
1157 int
1158 condexec_unary_operator (op, mode)
1159 rtx op;
1160 enum machine_mode mode ATTRIBUTE_UNUSED;
1161 {
1162 rtx op0;
1163
1164 /* Only do this after register allocation, so that we can look at the register # */
1165 if (!reload_completed)
1166 return FALSE;
1167
1168 if (GET_RTX_CLASS (GET_CODE (op)) != '1')
1169 return FALSE;
1170
1171 op0 = XEXP (op, 0);
1172 if (GET_CODE (op0) == SUBREG)
1173 op0 = SUBREG_REG (op0);
1174
1175 switch (GET_CODE (op))
1176 {
1177 default:
1178 break;
1179
1180 case ABS:
1181 case NOT:
1182 if (GET_MODE (op) == SImode && GET_CODE (op0) == REG && GPR_P (REGNO (op0)))
1183 return TRUE;
1184
1185 break;
1186 }
1187
1188 return FALSE;
1189 }
1190
1191 /* Return true if the add or subtraction can be executed with conditional
1192 execution. */
1193
1194 int
1195 condexec_addsub_operator (op, mode)
1196 rtx op;
1197 enum machine_mode mode ATTRIBUTE_UNUSED;
1198 {
1199 rtx op0, op1;
1200
1201 /* Only do this after register allocation, so that we can look at the register # */
1202 if (!reload_completed)
1203 return FALSE;
1204
1205 if (GET_RTX_CLASS (GET_CODE (op)) != '2' && GET_RTX_CLASS (GET_CODE (op)) != 'c')
1206 return FALSE;
1207
1208 op0 = XEXP (op, 0);
1209 op1 = XEXP (op, 1);
1210
1211 if (GET_CODE (op0) == SUBREG)
1212 op0 = SUBREG_REG (op0);
1213
1214 if (GET_CODE (op1) == SUBREG)
1215 op1 = SUBREG_REG (op1);
1216
1217 if (GET_CODE (op0) != REG)
1218 return FALSE;
1219
1220 switch (GET_CODE (op))
1221 {
1222 default:
1223 break;
1224
1225 case PLUS:
1226 case MINUS:
1227 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1228 && gpr_or_constant_operand (op1, SImode));
1229 }
1230
1231 return FALSE;
1232 }
1233
1234 /* Return true if the binary operator can be executed with conditional
1235 execution. We don't include add/sub here, since they have extra
1236 clobbers for the flags registers. */
1237
1238 int
1239 condexec_binary_operator (op, mode)
1240 rtx op;
1241 enum machine_mode mode ATTRIBUTE_UNUSED;
1242 {
1243 rtx op0, op1;
1244
1245 /* Only do this after register allocation, so that we can look at the register # */
1246 if (!reload_completed)
1247 return FALSE;
1248
1249 if (GET_RTX_CLASS (GET_CODE (op)) != '2' && GET_RTX_CLASS (GET_CODE (op)) != 'c')
1250 return FALSE;
1251
1252 op0 = XEXP (op, 0);
1253 op1 = XEXP (op, 1);
1254
1255 if (GET_CODE (op0) == SUBREG)
1256 op0 = SUBREG_REG (op0);
1257
1258 if (GET_CODE (op1) == SUBREG)
1259 op1 = SUBREG_REG (op1);
1260
1261 if (GET_CODE (op0) != REG)
1262 return FALSE;
1263
1264 /* MULT is not included here, because it is an IU only instruction. */
1265 switch (GET_CODE (op))
1266 {
1267 default:
1268 break;
1269
1270 case AND:
1271 case IOR:
1272 case XOR:
1273 case ASHIFTRT:
1274 case LSHIFTRT:
1275 case ROTATERT:
1276 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1277 && gpr_or_constant_operand (op1, SImode));
1278
1279 case ASHIFT:
1280 case ROTATE:
1281 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1282 && GET_CODE (op1) == CONST_INT);
1283 }
1284
1285 return FALSE;
1286 }
1287
1288 /* Return true if the shift/rotate left operator can be executed with
1289 conditional execution. */
1290
1291 int
1292 condexec_shiftl_operator (op, mode)
1293 rtx op;
1294 enum machine_mode mode ATTRIBUTE_UNUSED;
1295 {
1296 rtx op0, op1;
1297
1298 /* Only do this after register allocation, so that we can look at the register # */
1299 if (!reload_completed)
1300 return FALSE;
1301
1302 if (GET_RTX_CLASS (GET_CODE (op)) != '2' && GET_RTX_CLASS (GET_CODE (op)) != 'c')
1303 return FALSE;
1304
1305 op0 = XEXP (op, 0);
1306 op1 = XEXP (op, 1);
1307
1308 if (GET_CODE (op0) == SUBREG)
1309 op0 = SUBREG_REG (op0);
1310
1311 if (GET_CODE (op1) == SUBREG)
1312 op1 = SUBREG_REG (op1);
1313
1314 if (GET_CODE (op0) != REG)
1315 return FALSE;
1316
1317 switch (GET_CODE (op))
1318 {
1319 default:
1320 break;
1321
1322 case ASHIFT:
1323 case ROTATE:
1324 return (GET_MODE (op) == SImode && GPR_P (REGNO (op0))
1325 && GET_CODE (op1) == NEG
1326 && GET_CODE (XEXP (op1, 0)) == REG
1327 && GPR_P (REGNO (XEXP (op1, 0))));
1328 }
1329
1330 return FALSE;
1331 }
1332
1333 /* Return true if the {sign,zero} extend operator from memory can be
1334 conditionally executed. */
1335
1336 int
1337 condexec_extend_operator (op, mode)
1338 rtx op;
1339 enum machine_mode mode ATTRIBUTE_UNUSED;
1340 {
1341 /* Only do this after register allocation, so that we can look at the register # */
1342 if (!reload_completed)
1343 return FALSE;
1344
1345 if (GET_RTX_CLASS (GET_CODE (op)) != '1')
1346 return FALSE;
1347
1348 switch (GET_CODE (op))
1349 {
1350 default:
1351 break;
1352
1353 case SIGN_EXTEND:
1354 case ZERO_EXTEND:
1355 if ((GET_MODE (op) == SImode && GET_MODE (XEXP (op, 0)) == QImode)
1356 || (GET_MODE (op) == SImode && GET_MODE (XEXP (op, 0)) == HImode)
1357 || (GET_MODE (op) == HImode && GET_MODE (XEXP (op, 0)) == QImode))
1358 return TRUE;
1359
1360 break;
1361 }
1362
1363 return FALSE;
1364 }
1365
1366 /* Return true for comparisons against 0 that can be turned into a
1367 bratnz/bratzr instruction. */
1368
1369 int
1370 branch_zero_operator (op, mode)
1371 rtx op;
1372 enum machine_mode mode;
1373 {
1374 rtx x0, x1;
1375
1376 if (GET_MODE (op) != mode && mode != VOIDmode)
1377 return FALSE;
1378
1379 if (GET_CODE (op) != EQ && GET_CODE (op) != NE)
1380 return FALSE;
1381
1382 x0 = XEXP (op, 0);
1383 if (GET_CODE (x0) != REG || !GPR_OR_PSEUDO_P (REGNO (x0)))
1384 return FALSE;
1385
1386 x1 = XEXP (op, 1);
1387 if (GET_CODE (x1) != CONST_INT || INTVAL (x1) != 0)
1388 return FALSE;
1389
1390 return TRUE;
1391 }
1392
1393 /* Return true if an operand is simple, suitable for use as the destination of
1394 a conditional move */
1395
1396 int
1397 cond_move_dest_operand (op, mode)
1398 register rtx op;
1399 enum machine_mode mode ATTRIBUTE_UNUSED;
1400 {
1401 rtx addr;
1402
1403 if (mode != QImode && mode != HImode && mode != SImode && mode != SFmode)
1404 return FALSE;
1405
1406 switch (GET_CODE (op))
1407 {
1408 default:
1409 break;
1410
1411 case REG:
1412 case SUBREG:
1413 return gpr_operand (op, mode);
1414
1415 /* Don't allow post dec/inc, since we might not get the side effects correct. */
1416 case MEM:
1417 addr = XEXP (op, 0);
1418 return (GET_CODE (addr) != POST_DEC
1419 && GET_CODE (addr) != POST_INC
1420 && d30v_legitimate_address_p (mode, addr, reload_completed));
1421 }
1422
1423 return FALSE;
1424 }
1425
1426 /* Return true if an operand is simple, suitable for use in a conditional move */
1427
1428 int
1429 cond_move_operand (op, mode)
1430 register rtx op;
1431 enum machine_mode mode ATTRIBUTE_UNUSED;
1432 {
1433 rtx addr;
1434
1435 if (mode != QImode && mode != HImode && mode != SImode && mode != SFmode)
1436 return FALSE;
1437
1438 switch (GET_CODE (op))
1439 {
1440 default:
1441 break;
1442
1443 case REG:
1444 case SUBREG:
1445 return gpr_operand (op, mode);
1446
1447 case CONST_DOUBLE:
1448 return GET_MODE (op) == SFmode;
1449
1450 case CONST_INT:
1451 case SYMBOL_REF:
1452 case LABEL_REF:
1453 case CONST:
1454 return TRUE;
1455
1456 /* Don't allow post dec/inc, since we might not get the side effects correct. */
1457 case MEM:
1458 addr = XEXP (op, 0);
1459 return (GET_CODE (addr) != POST_DEC
1460 && GET_CODE (addr) != POST_INC
1461 && d30v_legitimate_address_p (mode, addr, reload_completed));
1462 }
1463
1464 return FALSE;
1465 }
1466
1467 /* Return true if an operand is simple, suitable for use in conditional execution.
1468 Unlike cond_move, we can allow auto inc/dec. */
1469
1470 int
1471 cond_exec_operand (op, mode)
1472 register rtx op;
1473 enum machine_mode mode;
1474 {
1475 if (mode != QImode && mode != HImode && mode != SImode && mode != SFmode)
1476 return FALSE;
1477
1478 switch (GET_CODE (op))
1479 {
1480 default:
1481 break;
1482
1483 case REG:
1484 case SUBREG:
1485 return gpr_operand (op, mode);
1486
1487 case CONST_DOUBLE:
1488 return GET_MODE (op) == SFmode;
1489
1490 case CONST_INT:
1491 case SYMBOL_REF:
1492 case LABEL_REF:
1493 case CONST:
1494 return TRUE;
1495
1496 case MEM:
1497 return memory_operand (op, mode);
1498 }
1499
1500 return FALSE;
1501 }
1502
1503 /* Return true if operand is a SI mode signed relational test. */
1504
1505 int
1506 srelational_si_operator (op, mode)
1507 register rtx op;
1508 enum machine_mode mode;
1509 {
1510 rtx x0, x1;
1511
1512 if (GET_MODE (op) != mode && mode != VOIDmode)
1513 return FALSE;
1514
1515 switch (GET_CODE (op))
1516 {
1517 default:
1518 return FALSE;
1519
1520 case EQ:
1521 case NE:
1522 case LT:
1523 case LE:
1524 case GT:
1525 case GE:
1526 break;
1527 }
1528
1529 x0 = XEXP (op, 0);
1530 if (GET_CODE (x0) != REG && GET_CODE (x0) != SUBREG)
1531 return FALSE;
1532
1533 if (GET_MODE (x0) != SImode)
1534 return FALSE;
1535
1536 x1 = XEXP (op, 1);
1537 switch (GET_CODE (x1))
1538 {
1539 default:
1540 return FALSE;
1541
1542 case REG:
1543 case SUBREG:
1544 case CONST_INT:
1545 case LABEL_REF:
1546 case SYMBOL_REF:
1547 case CONST:
1548 break;
1549 }
1550
1551 return TRUE;
1552 }
1553
1554 /* Return true if operand is a SI mode unsigned relational test. */
1555
1556 int
1557 urelational_si_operator (op, mode)
1558 register rtx op;
1559 enum machine_mode mode;
1560 {
1561 rtx x0, x1;
1562
1563 if (GET_MODE (op) != mode && mode != VOIDmode)
1564 return FALSE;
1565
1566 switch (GET_CODE (op))
1567 {
1568 default:
1569 return FALSE;
1570
1571 case LTU:
1572 case LEU:
1573 case GTU:
1574 case GEU:
1575 break;
1576 }
1577
1578 x0 = XEXP (op, 0);
1579 if (GET_CODE (x0) != REG && GET_CODE (x0) != SUBREG)
1580 return FALSE;
1581
1582 if (GET_MODE (x0) != SImode)
1583 return FALSE;
1584
1585 x1 = XEXP (op, 1);
1586 switch (GET_CODE (x1))
1587 {
1588 default:
1589 return FALSE;
1590
1591 case REG:
1592 case SUBREG:
1593 case CONST_INT:
1594 case LABEL_REF:
1595 case SYMBOL_REF:
1596 case CONST:
1597 break;
1598 }
1599
1600 return TRUE;
1601 }
1602
1603 /* Return true if operand is a DI mode relational test. */
1604
1605 int
1606 relational_di_operator (op, mode)
1607 register rtx op;
1608 enum machine_mode mode;
1609 {
1610 rtx x0, x1;
1611
1612 if (GET_MODE (op) != mode && mode != VOIDmode)
1613 return FALSE;
1614
1615 if (GET_RTX_CLASS (GET_CODE (op)) != '<')
1616 return FALSE;
1617
1618 x0 = XEXP (op, 0);
1619 if (GET_CODE (x0) != REG && GET_CODE (x0) != SUBREG)
1620 return FALSE;
1621
1622 if (GET_MODE (x0) != DImode)
1623 return FALSE;
1624
1625 x1 = XEXP (op, 1);
1626 if (GET_CODE (x1) != REG && GET_CODE (x1) != SUBREG
1627 && GET_CODE (x1) != CONST_INT && GET_CODE (x1) != CONST_DOUBLE)
1628 return FALSE;
1629
1630 return TRUE;
1631 }
1632
1633 \f
1634 /* Calculate the stack information for the current function.
1635
1636 D30V stack frames look like:
1637
1638 high | .... |
1639 +-------------------------------+
1640 | Argument word #19 |
1641 +-------------------------------+
1642 | Argument word #18 |
1643 +-------------------------------+
1644 | Argument word #17 |
1645 +-------------------------------+
1646 | Argument word #16 |
1647 Prev sp +-------------------------------+
1648 | |
1649 | Save for arguments 1..16 if |
1650 | the func. uses stdarg/varargs |
1651 | |
1652 +-------------------------------+
1653 | |
1654 | Save area for GPR registers |
1655 | |
1656 +-------------------------------+
1657 | |
1658 | Save area for accumulators |
1659 | |
1660 +-------------------------------+
1661 | |
1662 | Local variables |
1663 | |
1664 +-------------------------------+
1665 | |
1666 | alloca space if used |
1667 | |
1668 +-------------------------------+
1669 | |
1670 | Space for outgoing arguments |
1671 | |
1672 low SP----> +-------------------------------+
1673 */
1674
1675 d30v_stack_t *
1676 d30v_stack_info ()
1677 {
1678 static d30v_stack_t info, zero_info;
1679 d30v_stack_t *info_ptr = &info;
1680 tree fndecl = current_function_decl;
1681 tree fntype = TREE_TYPE (fndecl);
1682 int varargs_p = 0;
1683 tree cur_arg;
1684 tree next_arg;
1685 int saved_gprs;
1686 int saved_accs;
1687 int memrefs_2words;
1688 int memrefs_1word;
1689 unsigned char save_gpr_p[GPR_LAST];
1690 int i;
1691
1692 /* If we've already calculated the values and reload is complete, just return now */
1693 if (d30v_stack_cache)
1694 return d30v_stack_cache;
1695
1696 /* Zero all fields */
1697 info = zero_info;
1698
1699 if (profile_flag)
1700 regs_ever_live[GPR_LINK] = 1;
1701
1702 /* Determine if this is a stdarg function */
1703 if (TYPE_ARG_TYPES (fntype) != 0
1704 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) != void_type_node))
1705 varargs_p = 1;
1706 else
1707 {
1708 /* Find the last argument, and see if it is __builtin_va_alist. */
1709 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
1710 {
1711 next_arg = TREE_CHAIN (cur_arg);
1712 if (next_arg == (tree)0)
1713 {
1714 if (DECL_NAME (cur_arg)
1715 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
1716 varargs_p = 1;
1717
1718 break;
1719 }
1720 }
1721 }
1722
1723 /* Calculate which registers need to be saved & save area size */
1724 saved_accs = 0;
1725 memrefs_2words = 0;
1726 memrefs_1word = 0;
1727 for (i = ACCUM_FIRST; i <= ACCUM_LAST; i++)
1728 {
1729 if (regs_ever_live[i] && !call_used_regs[i])
1730 {
1731 info_ptr->save_p[i] = 2;
1732 saved_accs++;
1733 memrefs_2words++;
1734 }
1735 }
1736
1737 saved_gprs = 0;
1738 for (i = GPR_FIRST; i <= GPR_LAST; i++)
1739 {
1740 if (regs_ever_live[i] && (!call_used_regs[i] || i == GPR_LINK))
1741 {
1742 save_gpr_p[i] = 1;
1743 saved_gprs++;
1744 }
1745 else
1746 save_gpr_p[i] = 0;
1747 }
1748
1749 /* Determine which register pairs can be saved together with ld2w/st2w */
1750 for (i = GPR_FIRST; i <= GPR_LAST; i++)
1751 {
1752 if (((i - GPR_FIRST) & 1) == 0 && save_gpr_p[i] && save_gpr_p[i+1])
1753 {
1754 memrefs_2words++;
1755 info_ptr->save_p[i++] = 2;
1756 }
1757 else if (save_gpr_p[i])
1758 {
1759 memrefs_1word++;
1760 info_ptr->save_p[i] = 1;
1761 }
1762 }
1763
1764 /* Determine various sizes */
1765 info_ptr->varargs_p = varargs_p;
1766 info_ptr->varargs_size = ((varargs_p)
1767 ? (GPR_ARG_LAST + 1 - GPR_ARG_FIRST) * UNITS_PER_WORD
1768 : 0);
1769
1770 info_ptr->accum_size = 2 * UNITS_PER_WORD * saved_accs;
1771 info_ptr->gpr_size = D30V_ALIGN (UNITS_PER_WORD * saved_gprs,
1772 2 * UNITS_PER_WORD);
1773 info_ptr->vars_size = D30V_ALIGN (get_frame_size (), 2 * UNITS_PER_WORD);
1774 info_ptr->parm_size = D30V_ALIGN (current_function_outgoing_args_size,
1775 2 * UNITS_PER_WORD);
1776
1777 info_ptr->total_size = D30V_ALIGN ((info_ptr->gpr_size
1778 + info_ptr->accum_size
1779 + info_ptr->vars_size
1780 + info_ptr->parm_size
1781 + info_ptr->varargs_size
1782 + current_function_pretend_args_size),
1783 (STACK_BOUNDARY / BITS_PER_UNIT));
1784
1785 info_ptr->save_offset = (info_ptr->total_size
1786 - (current_function_pretend_args_size
1787 + info_ptr->varargs_size
1788 + info_ptr->gpr_size
1789 + info_ptr->accum_size));
1790
1791 /* The link register is the last GPR saved, but there might be some padding
1792 bytes after it, so account for that. */
1793 info_ptr->link_offset = (info_ptr->total_size
1794 - (current_function_pretend_args_size
1795 + info_ptr->varargs_size
1796 + (info_ptr->gpr_size
1797 - UNITS_PER_WORD * saved_gprs)
1798 + UNITS_PER_WORD));
1799
1800 info_ptr->memrefs_varargs = info_ptr->varargs_size / (2 * UNITS_PER_WORD);
1801 info_ptr->memrefs_2words = memrefs_2words;
1802 info_ptr->memrefs_1word = memrefs_1word;
1803
1804 if (reload_completed)
1805 d30v_stack_cache = info_ptr;
1806
1807 return info_ptr;
1808 }
1809
1810 \f
1811 /* Internal function to print all of the information about the stack */
1812
1813 void
1814 debug_stack_info (info)
1815 d30v_stack_t *info;
1816 {
1817 int i;
1818
1819 if (!info)
1820 info = d30v_stack_info ();
1821
1822 fprintf (stderr, "\nStack information for function %s:\n",
1823 ((current_function_decl && DECL_NAME (current_function_decl))
1824 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1825 : "<unknown>"));
1826
1827 fprintf (stderr, "\tsave_offset = %d\n", info->save_offset);
1828 fprintf (stderr, "\tmemrefs_varargs = %d\n", info->memrefs_varargs);
1829 fprintf (stderr, "\tmemrefs_2words = %d\n", info->memrefs_2words);
1830 fprintf (stderr, "\tmemrefs_1word = %d\n", info->memrefs_1word);
1831 fprintf (stderr, "\tvarargs_p = %d\n", info->varargs_p);
1832 fprintf (stderr, "\tvarargs_size = %d\n", info->varargs_size);
1833 fprintf (stderr, "\tvars_size = %d\n", info->vars_size);
1834 fprintf (stderr, "\tparm_size = %d\n", info->parm_size);
1835 fprintf (stderr, "\tgpr_size = %d\n", info->gpr_size);
1836 fprintf (stderr, "\taccum_size = %d\n", info->accum_size);
1837 fprintf (stderr, "\ttotal_size = %d\n", info->total_size);
1838 fprintf (stderr, "\tsaved registers =");
1839
1840 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1841 {
1842 if (info->save_p[i] == 2)
1843 {
1844 fprintf (stderr, " %s-%s", reg_names[i], reg_names[i+1]);
1845 i++;
1846 }
1847 else if (info->save_p[i])
1848 fprintf (stderr, " %s", reg_names[i]);
1849 }
1850
1851 putc ('\n', stderr);
1852 fflush (stderr);
1853 }
1854
1855 \f
1856 /* Return non-zero if this function is known to have a null or 1 instruction epilogue. */
1857
1858 int
1859 direct_return ()
1860 {
1861 if (reload_completed)
1862 {
1863 d30v_stack_t *info = d30v_stack_info ();
1864
1865 /* If no epilogue code is needed, can use just a simple jump */
1866 if (info->total_size == 0)
1867 return 1;
1868
1869 #if 0
1870 /* If just a small amount of local stack was allocated and no registers
1871 saved, skip forward branch */
1872 if (info->total_size == info->vars_size
1873 && IN_RANGE_P (info->total_size, 1, 31))
1874 return 1;
1875 #endif
1876 }
1877
1878 return 0;
1879 }
1880
1881 \f
1882 /* A C statement (sans semicolon) for initializing the variable CUM for the
1883 state at the beginning of the argument list. The variable has type
1884 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
1885 of the function which will receive the args, or 0 if the args are to a
1886 compiler support library function. The value of INDIRECT is nonzero when
1887 processing an indirect call, for example a call through a function pointer.
1888 The value of INDIRECT is zero for a call to an explicitly named function, a
1889 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
1890 arguments for the function being compiled.
1891
1892 When processing a call to a compiler support library function, LIBNAME
1893 identifies which one. It is a `symbol_ref' rtx which contains the name of
1894 the function, as a string. LIBNAME is 0 when an ordinary C function call is
1895 being processed. Thus, each time this macro is called, either LIBNAME or
1896 FNTYPE is nonzero, but never both of them at once. */
1897
1898 void
1899 d30v_init_cumulative_args (cum, fntype, libname, indirect, incoming)
1900 CUMULATIVE_ARGS *cum;
1901 tree fntype;
1902 rtx libname;
1903 int indirect;
1904 int incoming;
1905 {
1906 *cum = GPR_ARG_FIRST;
1907
1908 if (TARGET_DEBUG_ARG)
1909 {
1910 fprintf (stderr, "\ninit_cumulative_args:");
1911 if (indirect)
1912 fputs (" indirect", stderr);
1913
1914 if (incoming)
1915 fputs (" incoming", stderr);
1916
1917 if (fntype)
1918 {
1919 tree ret_type = TREE_TYPE (fntype);
1920 fprintf (stderr, " return=%s,",
1921 tree_code_name[ (int)TREE_CODE (ret_type) ]);
1922 }
1923
1924 if (libname && GET_CODE (libname) == SYMBOL_REF)
1925 fprintf (stderr, " libname=%s", XSTR (libname, 0));
1926
1927 putc ('\n', stderr);
1928 }
1929 }
1930
1931 \f
1932 /* If defined, a C expression that gives the alignment boundary, in bits, of an
1933 argument with the specified mode and type. If it is not defined,
1934 `PARM_BOUNDARY' is used for all arguments. */
1935
1936 int
1937 d30v_function_arg_boundary (mode, type)
1938 enum machine_mode mode;
1939 tree type;
1940 {
1941 int size = ((mode == BLKmode && type)
1942 ? int_size_in_bytes (type)
1943 : GET_MODE_SIZE (mode));
1944
1945 return (size > UNITS_PER_WORD) ? 2*UNITS_PER_WORD : UNITS_PER_WORD;
1946 }
1947
1948 \f
1949 /* A C expression that controls whether a function argument is passed in a
1950 register, and which register.
1951
1952 The arguments are CUM, which summarizes all the previous arguments; MODE,
1953 the machine mode of the argument; TYPE, the data type of the argument as a
1954 tree node or 0 if that is not known (which happens for C support library
1955 functions); and NAMED, which is 1 for an ordinary argument and 0 for
1956 nameless arguments that correspond to `...' in the called function's
1957 prototype.
1958
1959 The value of the expression should either be a `reg' RTX for the hard
1960 register in which to pass the argument, or zero to pass the argument on the
1961 stack.
1962
1963 For machines like the Vax and 68000, where normally all arguments are
1964 pushed, zero suffices as a definition.
1965
1966 The usual way to make the ANSI library `stdarg.h' work on a machine where
1967 some arguments are usually passed in registers, is to cause nameless
1968 arguments to be passed on the stack instead. This is done by making
1969 `FUNCTION_ARG' return 0 whenever NAMED is 0.
1970
1971 You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the definition of
1972 this macro to determine if this argument is of a type that must be passed in
1973 the stack. If `REG_PARM_STACK_SPACE' is not defined and `FUNCTION_ARG'
1974 returns non-zero for such an argument, the compiler will abort. If
1975 `REG_PARM_STACK_SPACE' is defined, the argument will be computed in the
1976 stack and then loaded into a register. */
1977
1978 rtx
1979 d30v_function_arg (cum, mode, type, named, incoming)
1980 CUMULATIVE_ARGS *cum;
1981 enum machine_mode mode;
1982 tree type;
1983 int named;
1984 int incoming ATTRIBUTE_UNUSED;
1985 {
1986 int size = ((mode == BLKmode && type)
1987 ? int_size_in_bytes (type)
1988 : GET_MODE_SIZE (mode));
1989 int adjust = (size > UNITS_PER_WORD && (*cum & 1) != 0);
1990 rtx ret;
1991
1992 /* Return a marker for use in the call instruction. */
1993 if (mode == VOIDmode)
1994 ret = const0_rtx;
1995
1996 else if (*cum + adjust <= GPR_ARG_LAST)
1997 ret = gen_rtx (REG, mode, *cum + adjust);
1998
1999 else
2000 ret = NULL_RTX;
2001
2002 if (TARGET_DEBUG_ARG)
2003 fprintf (stderr,
2004 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, adjust = %1d, arg = %s\n",
2005 *cum, GET_MODE_NAME (mode), named, size, adjust,
2006 (ret) ? ((ret == const0_rtx) ? "<0>" : reg_names[ REGNO (ret) ]) : "memory");
2007
2008 return ret;
2009 }
2010
2011 \f
2012 /* A C expression for the number of words, at the beginning of an argument,
2013 must be put in registers. The value must be zero for arguments that are
2014 passed entirely in registers or that are entirely pushed on the stack.
2015
2016 On some machines, certain arguments must be passed partially in registers
2017 and partially in memory. On these machines, typically the first N words of
2018 arguments are passed in registers, and the rest on the stack. If a
2019 multi-word argument (a `double' or a structure) crosses that boundary, its
2020 first few words must be passed in registers and the rest must be pushed.
2021 This macro tells the compiler when this occurs, and how many of the words
2022 should go in registers.
2023
2024 `FUNCTION_ARG' for these arguments should return the first register to be
2025 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
2026 the called function. */
2027
2028 int
2029 d30v_function_arg_partial_nregs (cum, mode, type, named)
2030 CUMULATIVE_ARGS *cum;
2031 enum machine_mode mode;
2032 tree type;
2033 int named ATTRIBUTE_UNUSED;
2034 {
2035 int bytes = ((mode == BLKmode)
2036 ? int_size_in_bytes (type)
2037 : GET_MODE_SIZE (mode));
2038 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2039 int adjust = (bytes > UNITS_PER_WORD && (*cum & 1) != 0);
2040 int arg_num = *cum + adjust;
2041 int ret;
2042
2043 ret = ((arg_num <= GPR_ARG_LAST && arg_num + words > GPR_ARG_LAST+1)
2044 ? GPR_ARG_LAST - arg_num + 1
2045 : 0);
2046
2047 if (TARGET_DEBUG_ARG && ret)
2048 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
2049
2050 return ret;
2051 }
2052
2053 \f
2054 /* A C expression that indicates when an argument must be passed by reference.
2055 If nonzero for an argument, a copy of that argument is made in memory and a
2056 pointer to the argument is passed instead of the argument itself. The
2057 pointer is passed in whatever way is appropriate for passing a pointer to
2058 that type.
2059
2060 On machines where `REG_PARM_STACK_SPACE' is not defined, a suitable
2061 definition of this macro might be
2062 #define FUNCTION_ARG_PASS_BY_REFERENCE\
2063 (CUM, MODE, TYPE, NAMED) \
2064 MUST_PASS_IN_STACK (MODE, TYPE) */
2065
2066 int
2067 d30v_function_arg_pass_by_reference (cum, mode, type, named)
2068 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
2069 enum machine_mode mode;
2070 tree type;
2071 int named ATTRIBUTE_UNUSED;
2072 {
2073 int ret = MUST_PASS_IN_STACK (mode, type);
2074
2075 if (TARGET_DEBUG_ARG && ret)
2076 fprintf (stderr, "function_arg_pass_by_reference: %d\n", ret);
2077
2078 return ret;
2079 }
2080
2081 \f
2082 /* A C statement (sans semicolon) to update the summarizer variable CUM to
2083 advance past an argument in the argument list. The values MODE, TYPE and
2084 NAMED describe that argument. Once this is done, the variable CUM is
2085 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
2086
2087 This macro need not do anything if the argument in question was passed on
2088 the stack. The compiler knows how to track the amount of stack space used
2089 for arguments without any special help. */
2090
2091 void
2092 d30v_function_arg_advance (cum, mode, type, named)
2093 CUMULATIVE_ARGS *cum;
2094 enum machine_mode mode;
2095 tree type;
2096 int named;
2097 {
2098 int bytes = ((mode == BLKmode)
2099 ? int_size_in_bytes (type)
2100 : GET_MODE_SIZE (mode));
2101 int words = D30V_ALIGN (bytes, UNITS_PER_WORD) / UNITS_PER_WORD;
2102 int adjust = (bytes > UNITS_PER_WORD && (*cum & 1) != 0);
2103
2104 *cum += words + adjust;
2105
2106 if (TARGET_DEBUG_ARG)
2107 fprintf (stderr,
2108 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d, adjust = %1d\n",
2109 *cum, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD, adjust);
2110 }
2111
2112 \f
2113 /* If defined, is a C expression that produces the machine-specific code for a
2114 call to `__builtin_saveregs'. This code will be moved to the very beginning
2115 of the function, before any parameter access are made. The return value of
2116 this function should be an RTX that contains the value to use as the return
2117 of `__builtin_saveregs'.
2118
2119 If this macro is not defined, the compiler will output an ordinary call to
2120 the library function `__builtin_saveregs'. */
2121
2122 rtx
2123 d30v_expand_builtin_saveregs ()
2124 {
2125 int offset = UNITS_PER_WORD * (GPR_ARG_LAST + 1 - GPR_ARG_FIRST);
2126
2127 if (TARGET_DEBUG_ARG)
2128 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2129 offset);
2130
2131 return gen_rtx (PLUS, Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2132 }
2133
2134 \f
2135 /* This macro offers an alternative to using `__builtin_saveregs' and defining
2136 the macro `EXPAND_BUILTIN_SAVEREGS'. Use it to store the anonymous register
2137 arguments into the stack so that all the arguments appear to have been
2138 passed consecutively on the stack. Once this is done, you can use the
2139 standard implementation of varargs that works for machines that pass all
2140 their arguments on the stack.
2141
2142 The argument ARGS_SO_FAR is the `CUMULATIVE_ARGS' data structure, containing
2143 the values that obtain after processing of the named arguments. The
2144 arguments MODE and TYPE describe the last named argument--its machine mode
2145 and its data type as a tree node.
2146
2147 The macro implementation should do two things: first, push onto the stack
2148 all the argument registers *not* used for the named arguments, and second,
2149 store the size of the data thus pushed into the `int'-valued variable whose
2150 name is supplied as the argument PRETEND_ARGS_SIZE. The value that you
2151 store here will serve as additional offset for setting up the stack frame.
2152
2153 Because you must generate code to push the anonymous arguments at compile
2154 time without knowing their data types, `SETUP_INCOMING_VARARGS' is only
2155 useful on machines that have just a single category of argument register and
2156 use it uniformly for all data types.
2157
2158 If the argument SECOND_TIME is nonzero, it means that the arguments of the
2159 function are being analyzed for the second time. This happens for an inline
2160 function, which is not actually compiled until the end of the source file.
2161 The macro `SETUP_INCOMING_VARARGS' should not generate any instructions in
2162 this case. */
2163
2164 void
2165 d30v_setup_incoming_varargs (cum, mode, type, pretend_size, second_time)
2166 CUMULATIVE_ARGS *cum;
2167 enum machine_mode mode;
2168 tree type ATTRIBUTE_UNUSED;
2169 int *pretend_size ATTRIBUTE_UNUSED;
2170 int second_time;
2171 {
2172 if (TARGET_DEBUG_ARG)
2173 fprintf (stderr,
2174 "setup_vararg: words = %2d, mode = %4s, second_time = %d\n",
2175 *cum, GET_MODE_NAME (mode), second_time);
2176 }
2177
2178 \f
2179 /* Create the va_list data type. */
2180
2181 tree
2182 d30v_build_va_list ()
2183 {
2184 tree f_arg_ptr, f_arg_num, record, type_decl;
2185 tree int_type_node;
2186
2187 record = make_lang_type (RECORD_TYPE);
2188 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2189 int_type_node = make_signed_type (INT_TYPE_SIZE);
2190
2191 f_arg_ptr = build_decl (FIELD_DECL, get_identifier ("__va_arg_ptr"),
2192 ptr_type_node);
2193 f_arg_num = build_decl (FIELD_DECL, get_identifier ("__va_arg_num"),
2194 int_type_node);
2195
2196 DECL_FIELD_CONTEXT (f_arg_ptr) = record;
2197 DECL_FIELD_CONTEXT (f_arg_num) = record;
2198
2199 TREE_CHAIN (record) = type_decl;
2200 TYPE_NAME (record) = type_decl;
2201 TYPE_FIELDS (record) = f_arg_ptr;
2202 TREE_CHAIN (f_arg_ptr) = f_arg_num;
2203
2204 layout_type (record);
2205
2206 /* The correct type is an array type of one element. */
2207 return build_array_type (record, build_index_type (size_zero_node));
2208 }
2209
2210 \f
2211 /* Expand __builtin_va_start to do the va_start macro. */
2212
2213 void
2214 d30v_expand_builtin_va_start (stdarg_p, valist, nextarg)
2215 int stdarg_p ATTRIBUTE_UNUSED;
2216 tree valist;
2217 rtx nextarg ATTRIBUTE_UNUSED;
2218 {
2219 HOST_WIDE_INT words;
2220 tree f_arg_ptr, f_arg_num;
2221 tree arg_ptr, arg_num, saveregs, t;
2222
2223 f_arg_ptr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2224 f_arg_num = TREE_CHAIN (f_arg_ptr);
2225
2226 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2227 arg_ptr = build (COMPONENT_REF, TREE_TYPE (f_arg_ptr), valist, f_arg_ptr);
2228 arg_num = build (COMPONENT_REF, TREE_TYPE (f_arg_num), valist, f_arg_num);
2229
2230 words = current_function_args_info; /* __builtin_args_info (0) */
2231
2232 /* (AP)->__va_arg_ptr = (int *) __builtin_saveregs (); */
2233 saveregs = make_tree (TREE_TYPE (arg_ptr), d30v_expand_builtin_saveregs ());
2234 t = build (MODIFY_EXPR, TREE_TYPE (arg_ptr), arg_ptr, saveregs);
2235 TREE_SIDE_EFFECTS (t) = 1;
2236 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2237
2238 /* (AP)->__va_arg_num = __builtin_args_info (0) - 2; */
2239 t = build (PLUS_EXPR, TREE_TYPE (arg_num), build_int_2 (words, 0),
2240 build_int_2 (-GPR_ARG_FIRST, 0));
2241 t = build (MODIFY_EXPR, TREE_TYPE (arg_num), arg_num, t);
2242 TREE_SIDE_EFFECTS (t) = 1;
2243 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2244 }
2245
2246 \f
2247 /* Expand __builtin_va_arg to do the va_arg macro. */
2248
2249 rtx
2250 d30v_expand_builtin_va_arg(valist, type)
2251 tree valist;
2252 tree type;
2253 {
2254 tree f_arg_ptr, f_arg_num;
2255 tree arg_ptr, arg_num, t, ptr;
2256 int num, size;
2257 rtx lab_false, ptr_rtx, r;
2258
2259 f_arg_ptr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
2260 f_arg_num = TREE_CHAIN (f_arg_ptr);
2261
2262 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
2263 arg_ptr = build (COMPONENT_REF, TREE_TYPE (f_arg_ptr), valist, f_arg_ptr);
2264 arg_num = build (COMPONENT_REF, TREE_TYPE (f_arg_num), valist, f_arg_num);
2265
2266 size = int_size_in_bytes (type);
2267
2268 lab_false = gen_label_rtx ();
2269 ptr_rtx = gen_reg_rtx (Pmode);
2270
2271 /* if (sizeof (TYPE) > 4 && ((AP)->__va_arg_num & 1) != 0)
2272 (AP)->__va_arg_num++; */
2273
2274 if (size > UNITS_PER_WORD)
2275 {
2276 t = build (BIT_AND_EXPR, TREE_TYPE (arg_num), arg_num,
2277 build_int_2 (1, 0));
2278
2279 emit_cmp_and_jump_insns (expand_expr (t, NULL_RTX, QImode, EXPAND_NORMAL),
2280 GEN_INT (0), EQ, const1_rtx, QImode, 1, 1,
2281 lab_false);
2282
2283 t = build (POSTINCREMENT_EXPR, TREE_TYPE (arg_num), arg_num,
2284 build_int_2 (1, 0));
2285 TREE_SIDE_EFFECTS (t) = 1;
2286 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2287
2288 emit_label (lab_false);
2289 }
2290
2291
2292 /* __ptr = (TYPE *)(((char *)(void *)((AP)->__va_arg_ptr
2293 + (AP)->__va_arg_num))); */
2294
2295 t = build (MULT_EXPR, TREE_TYPE (arg_num), arg_num, build_int_2 (4, 0));
2296 t = build (PLUS_EXPR, ptr_type_node, arg_ptr, t);
2297
2298 /* if (sizeof (TYPE) < 4)
2299 __ptr = (void *)__ptr + 4 - sizeof (TYPE); */
2300
2301 if (size < UNITS_PER_WORD)
2302 t = build (PLUS_EXPR, ptr_type_node, t,
2303 build_int_2 (UNITS_PER_WORD - size, 0));
2304
2305 TREE_SIDE_EFFECTS (t) = 1;
2306
2307 ptr = build1 (NOP_EXPR, build_pointer_type (type), t);
2308 t = build (MODIFY_EXPR, type, ptr, t);
2309
2310 r = expand_expr (t, ptr_rtx, Pmode, EXPAND_NORMAL);
2311 if (r != ptr_rtx)
2312 emit_move_insn (ptr_rtx, r);
2313
2314
2315 /* (AP)->__va_arg_num += (sizeof (TYPE) + 3) / 4; */
2316 num = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2317 t = build (POSTINCREMENT_EXPR, TREE_TYPE (arg_num), arg_num,
2318 build_int_2 (num, 0));
2319 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2320
2321 return ptr_rtx;
2322 }
2323 \f
2324
2325 /* A C compound statement that outputs the assembler code for entry to a
2326 function. The prologue is responsible for setting up the stack frame,
2327 initializing the frame pointer register, saving registers that must be
2328 saved, and allocating SIZE additional bytes of storage for the local
2329 variables. SIZE is an integer. FILE is a stdio stream to which the
2330 assembler code should be output.
2331
2332 The label for the beginning of the function need not be output by this
2333 macro. That has already been done when the macro is run.
2334
2335 To determine which registers to save, the macro can refer to the array
2336 `regs_ever_live': element R is nonzero if hard register R is used anywhere
2337 within the function. This implies the function prologue should save
2338 register R, provided it is not one of the call-used registers.
2339 (`FUNCTION_EPILOGUE' must likewise use `regs_ever_live'.)
2340
2341 On machines that have "register windows", the function entry code does not
2342 save on the stack the registers that are in the windows, even if they are
2343 supposed to be preserved by function calls; instead it takes appropriate
2344 steps to "push" the register stack, if any non-call-used registers are used
2345 in the function.
2346
2347 On machines where functions may or may not have frame-pointers, the function
2348 entry code must vary accordingly; it must set up the frame pointer if one is
2349 wanted, and not otherwise. To determine whether a frame pointer is in
2350 wanted, the macro can refer to the variable `frame_pointer_needed'. The
2351 variable's value will be 1 at run time in a function that needs a frame
2352 pointer. *Note Elimination::.
2353
2354 The function entry code is responsible for allocating any stack space
2355 required for the function. This stack space consists of the regions listed
2356 below. In most cases, these regions are allocated in the order listed, with
2357 the last listed region closest to the top of the stack (the lowest address
2358 if `STACK_GROWS_DOWNWARD' is defined, and the highest address if it is not
2359 defined). You can use a different order for a machine if doing so is more
2360 convenient or required for compatibility reasons. Except in cases where
2361 required by standard or by a debugger, there is no reason why the stack
2362 layout used by GCC need agree with that used by other compilers for a
2363 machine.
2364
2365 * A region of `current_function_pretend_args_size' bytes of
2366 uninitialized space just underneath the first argument
2367 arriving on the stack. (This may not be at the very start of
2368 the allocated stack region if the calling sequence has pushed
2369 anything else since pushing the stack arguments. But
2370 usually, on such machines, nothing else has been pushed yet,
2371 because the function prologue itself does all the pushing.)
2372 This region is used on machines where an argument may be
2373 passed partly in registers and partly in memory, and, in some
2374 cases to support the features in `varargs.h' and `stdargs.h'.
2375
2376 * An area of memory used to save certain registers used by the
2377 function. The size of this area, which may also include
2378 space for such things as the return address and pointers to
2379 previous stack frames, is machine-specific and usually
2380 depends on which registers have been used in the function.
2381 Machines with register windows often do not require a save
2382 area.
2383
2384 * A region of at least SIZE bytes, possibly rounded up to an
2385 allocation boundary, to contain the local variables of the
2386 function. On some machines, this region and the save area
2387 may occur in the opposite order, with the save area closer to
2388 the top of the stack.
2389
2390 * Optionally, when `ACCUMULATE_OUTGOING_ARGS' is defined, a
2391 region of `current_function_outgoing_args_size' bytes to be
2392 used for outgoing argument lists of the function. *Note
2393 Stack Arguments::.
2394
2395 Normally, it is necessary for the macros `FUNCTION_PROLOGUE' and
2396 `FUNCTION_EPILOGUE' to treat leaf functions specially. The C variable
2397 `leaf_function' is nonzero for such a function. */
2398
2399 /* For the d30v, move all of the prologue processing into separate insns. */
2400 void
2401 d30v_function_prologue (stream, size)
2402 FILE *stream ATTRIBUTE_UNUSED;
2403 int size ATTRIBUTE_UNUSED;
2404 {
2405 }
2406
2407 \f
2408 /* Called after register allocation to add any instructions needed for the
2409 prologue. Using a prologue insn is favored compared to putting all of the
2410 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
2411 to intermix instructions with the saves of the caller saved registers. In
2412 some cases, it might be necessary to emit a barrier instruction as the last
2413 insn to prevent such scheduling. */
2414
2415 void
2416 d30v_expand_prologue ()
2417 {
2418 rtx sp = stack_pointer_rtx;
2419 d30v_stack_t *info = d30v_stack_info ();
2420 int i;
2421 rtx mem_di = NULL_RTX;
2422 rtx mem_si = NULL_RTX;
2423 int num_memrefs = (info->memrefs_2words
2424 + info->memrefs_1word
2425 + info->memrefs_varargs);
2426
2427 if (TARGET_DEBUG_STACK)
2428 debug_stack_info (info);
2429
2430 /* Grow the stack. */
2431 if (info->total_size)
2432 emit_insn (gen_addsi3 (sp, sp, GEN_INT (- info->total_size)));
2433
2434 /* If there is more than one save, use post-increment addressing which will
2435 result in smaller code, than would the normal references. If there is
2436 only one save, just do the store as normal. */
2437
2438 if (num_memrefs > 1)
2439 {
2440 rtx save_tmp = gen_rtx (REG, Pmode, GPR_STACK_TMP);
2441 rtx post_inc = gen_rtx (POST_INC, Pmode, save_tmp);
2442 mem_di = gen_rtx (MEM, DImode, post_inc);
2443 mem_si = gen_rtx (MEM, SImode, post_inc);
2444 emit_insn (gen_addsi3 (save_tmp, sp, GEN_INT (info->save_offset)));
2445 }
2446 else if (num_memrefs == 1)
2447 {
2448 rtx addr = plus_constant (sp, info->save_offset);
2449 mem_di = gen_rtx (MEM, DImode, addr);
2450 mem_si = gen_rtx (MEM, SImode, addr);
2451 }
2452
2453 /* Save the accumulators. */
2454 for (i = ACCUM_FIRST; i <= ACCUM_LAST; i++)
2455 if (info->save_p[i])
2456 {
2457 rtx acc_tmp = gen_rtx (REG, DImode, GPR_ATMP_FIRST);
2458 emit_insn (gen_movdi (acc_tmp, gen_rtx (REG, DImode, i)));
2459 emit_insn (gen_movdi (mem_di, acc_tmp));
2460 }
2461
2462 /* Save the GPR registers that are adjacent to each other with st2w. */
2463 for (i = GPR_FIRST; i <= GPR_LAST; i += 2)
2464 if (info->save_p[i] == 2)
2465 emit_insn (gen_movdi (mem_di, gen_rtx (REG, DImode, i)));
2466
2467 /* Save the GPR registers that need to be saved with a single word store. */
2468 for (i = GPR_FIRST; i <= GPR_LAST; i++)
2469 if (info->save_p[i] == 1)
2470 emit_insn (gen_movsi (mem_si, gen_rtx (REG, SImode, i)));
2471
2472 /* Save the argument registers if this function accepts variable args. */
2473 if (info->varargs_p)
2474 {
2475 /* Realign r22 if an odd # of GPRs were saved. */
2476 if ((info->memrefs_1word & 1) != 0)
2477 {
2478 rtx save_tmp = XEXP (XEXP (mem_si, 0), 0);
2479 emit_insn (gen_addsi3 (save_tmp, save_tmp, GEN_INT (UNITS_PER_WORD)));
2480 }
2481
2482 for (i = GPR_ARG_FIRST; i <= GPR_ARG_LAST; i += 2)
2483 emit_insn (gen_movdi (mem_di, gen_rtx (REG, DImode, i)));
2484 }
2485
2486 /* Update the frame pointer. */
2487 if (frame_pointer_needed)
2488 emit_move_insn (frame_pointer_rtx, sp);
2489
2490 /* Hack for now, to prevent scheduler from being too cleaver */
2491 emit_insn (gen_blockage ());
2492 }
2493
2494 \f
2495 /* A C compound statement that outputs the assembler code for exit from a
2496 function. The epilogue is responsible for restoring the saved registers and
2497 stack pointer to their values when the function was called, and returning
2498 control to the caller. This macro takes the same arguments as the macro
2499 `FUNCTION_PROLOGUE', and the registers to restore are determined from
2500 `regs_ever_live' and `CALL_USED_REGISTERS' in the same way.
2501
2502 On some machines, there is a single instruction that does all the work of
2503 returning from the function. On these machines, give that instruction the
2504 name `return' and do not define the macro `FUNCTION_EPILOGUE' at all.
2505
2506 Do not define a pattern named `return' if you want the `FUNCTION_EPILOGUE'
2507 to be used. If you want the target switches to control whether return
2508 instructions or epilogues are used, define a `return' pattern with a
2509 validity condition that tests the target switches appropriately. If the
2510 `return' pattern's validity condition is false, epilogues will be used.
2511
2512 On machines where functions may or may not have frame-pointers, the function
2513 exit code must vary accordingly. Sometimes the code for these two cases is
2514 completely different. To determine whether a frame pointer is wanted, the
2515 macro can refer to the variable `frame_pointer_needed'. The variable's
2516 value will be 1 when compiling a function that needs a frame pointer.
2517
2518 Normally, `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' must treat leaf
2519 functions specially. The C variable `leaf_function' is nonzero for such a
2520 function. *Note Leaf Functions::.
2521
2522 On some machines, some functions pop their arguments on exit while others
2523 leave that for the caller to do. For example, the 68020 when given `-mrtd'
2524 pops arguments in functions that take a fixed number of arguments.
2525
2526 Your definition of the macro `RETURN_POPS_ARGS' decides which functions pop
2527 their own arguments. `FUNCTION_EPILOGUE' needs to know what was decided.
2528 The variable that is called `current_function_pops_args' is the number of
2529 bytes of its arguments that a function should pop. *Note Scalar Return::. */
2530
2531 /* For the d30v, move all processing to be as insns, but do any cleanup
2532 here, since it is done after handling all of the insns. */
2533 void
2534 d30v_function_epilogue (stream, size)
2535 FILE *stream ATTRIBUTE_UNUSED;
2536 int size ATTRIBUTE_UNUSED;
2537 {
2538 d30v_stack_cache = (d30v_stack_t *)0; /* reset stack cache */
2539 }
2540
2541 \f
2542
2543 /* Called after register allocation to add any instructions needed for the
2544 epilogue. Using a epilogue insn is favored compared to putting all of the
2545 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
2546 to intermix instructions with the saves of the caller saved registers. In
2547 some cases, it might be necessary to emit a barrier instruction as the last
2548 insn to prevent such scheduling. */
2549
2550 void
2551 d30v_expand_epilogue ()
2552 {
2553 rtx sp = stack_pointer_rtx;
2554 d30v_stack_t *info = d30v_stack_info ();
2555 int i;
2556 rtx mem_di = NULL_RTX;
2557 rtx mem_si = NULL_RTX;
2558 rtx post_inc;
2559 int extra_stack;
2560
2561 /* Hack for now, to prevent scheduler from being too cleaver */
2562 emit_insn (gen_blockage ());
2563
2564 /* Restore sp from fp. */
2565 if (frame_pointer_needed)
2566 emit_move_insn (sp, frame_pointer_rtx);
2567
2568 /* For the epilogue, use post-increment addressing all of the time. First
2569 adjust the sp, to eliminate all of the stack, except for the save area. */
2570
2571 if (info->save_offset)
2572 emit_insn (gen_addsi3 (sp, sp, GEN_INT (info->save_offset)));
2573
2574 post_inc = gen_rtx (POST_INC, Pmode, sp);
2575 mem_di = gen_rtx (MEM, DImode, post_inc);
2576 mem_si = gen_rtx (MEM, SImode, post_inc);
2577
2578 /* Restore the accumulators. */
2579 for (i = ACCUM_FIRST; i <= ACCUM_LAST; i++)
2580 if (info->save_p[i])
2581 {
2582 rtx acc_tmp = gen_rtx (REG, DImode, GPR_ATMP_FIRST);
2583 emit_insn (gen_movdi (acc_tmp, mem_di));
2584 emit_insn (gen_movdi (gen_rtx (REG, DImode, i), acc_tmp));
2585 }
2586
2587 /* Restore the GPR registers that are adjacent to each other with ld2w. */
2588 for (i = GPR_FIRST; i <= GPR_LAST; i += 2)
2589 if (info->save_p[i] == 2)
2590 emit_insn (gen_movdi (gen_rtx (REG, DImode, i), mem_di));
2591
2592 /* Save the GPR registers that need to be saved with a single word store. */
2593 extra_stack = 0;
2594 for (i = GPR_FIRST; i <= GPR_LAST; i++)
2595 if (info->save_p[i] == 1)
2596 {
2597 if (d30v_eh_epilogue_sp_ofs && i == GPR_LINK)
2598 extra_stack = 4;
2599 else
2600 {
2601 if (extra_stack)
2602 {
2603 emit_insn (gen_addsi3 (sp, sp, GEN_INT (extra_stack)));
2604 extra_stack = 0;
2605 }
2606 emit_insn (gen_movsi (gen_rtx (REG, SImode, i), mem_si));
2607 }
2608 }
2609
2610 /* Release any remaining stack that was allocated for saving the
2611 varargs registers or because an odd # of registers were stored. */
2612 if ((info->memrefs_1word & 1) != 0)
2613 extra_stack += UNITS_PER_WORD;
2614 extra_stack += current_function_pretend_args_size + info->varargs_size;
2615
2616 if (extra_stack)
2617 {
2618 if (d30v_eh_epilogue_sp_ofs)
2619 emit_insn (gen_addsi3 (d30v_eh_epilogue_sp_ofs,
2620 d30v_eh_epilogue_sp_ofs,
2621 GEN_INT (extra_stack)));
2622 else
2623 emit_insn (gen_addsi3 (sp, sp, GEN_INT (extra_stack)));
2624 }
2625 if (d30v_eh_epilogue_sp_ofs)
2626 emit_insn (gen_addsi3 (sp, sp, d30v_eh_epilogue_sp_ofs));
2627
2628 /* Now emit the return instruction. */
2629 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
2630 }
2631
2632 \f
2633 /* A C statement or compound statement to output to FILE some assembler code to
2634 call the profiling subroutine `mcount'. Before calling, the assembler code
2635 must load the address of a counter variable into a register where `mcount'
2636 expects to find the address. The name of this variable is `LP' followed by
2637 the number LABELNO, so you would generate the name using `LP%d' in a
2638 `fprintf'.
2639
2640 The details of how the address should be passed to `mcount' are determined
2641 by your operating system environment, not by GNU CC. To figure them out,
2642 compile a small program for profiling using the system's installed C
2643 compiler and look at the assembler code that results. */
2644
2645 void
2646 d30v_function_profiler (stream, labelno)
2647 FILE *stream;
2648 int labelno ATTRIBUTE_UNUSED;
2649 {
2650 fprintf (stream, "# profile\n");
2651 }
2652
2653 \f
2654 /* Split a 64 bit item into an upper and a lower part. We specifically do not
2655 want to call gen_highpart/gen_lowpart on CONST_DOUBLEs since it will give us
2656 the wrong part for floating point in cross compilers, and split_double does
2657 not handle registers. Also abort if the register is not a general purpose
2658 register. */
2659
2660 void
2661 d30v_split_double (value, p_high, p_low)
2662 rtx value;
2663 rtx *p_high;
2664 rtx *p_low;
2665 {
2666 int offset = 0;
2667 int regno;
2668
2669 if (!reload_completed)
2670 abort ();
2671
2672 switch (GET_CODE (value))
2673 {
2674 case SUBREG:
2675 offset = SUBREG_WORD (value);
2676 value = SUBREG_REG (value);
2677 if (GET_CODE (value) != REG)
2678 abort ();
2679
2680 /* fall through */
2681
2682 case REG:
2683 regno = REGNO (value) + offset;
2684 if (!GPR_P (regno))
2685 abort ();
2686
2687 *p_high = gen_rtx (REG, SImode, regno);
2688 *p_low = gen_rtx (REG, SImode, regno+1);
2689 break;
2690
2691 case CONST_INT:
2692 case CONST_DOUBLE:
2693 split_double (value, p_high, p_low);
2694 break;
2695
2696 default:
2697 abort ();
2698 }
2699 }
2700
2701 \f
2702 /* A C compound statement to output to stdio stream STREAM the assembler syntax
2703 for an instruction operand that is a memory reference whose address is X. X
2704 is an RTL expression.
2705
2706 On some machines, the syntax for a symbolic address depends on the section
2707 that the address refers to. On these machines, define the macro
2708 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
2709 then check for it here. *Note Assembler Format::. */
2710
2711 void
2712 d30v_print_operand_address (stream, x)
2713 FILE *stream;
2714 rtx x;
2715 {
2716 if (GET_CODE (x) == MEM)
2717 x = XEXP (x, 0);
2718
2719 switch (GET_CODE (x))
2720 {
2721 default:
2722 break;
2723
2724 case REG:
2725 fputs (reg_names[ REGNO (x) ], stream);
2726 return;
2727
2728 case CONST_INT:
2729 fprintf (stream, "%ld", (long) INTVAL (x));
2730 return;
2731
2732 /* We wrap simple symbol refs inside a parenthesis, so that a name
2733 like `r2' is not taken for a register name. */
2734 case SYMBOL_REF:
2735 fputs ("(", stream);
2736 assemble_name (stream, XSTR (x, 0));
2737 fputs (")", stream);
2738 return;
2739
2740 case LABEL_REF:
2741 case CONST:
2742 output_addr_const (stream, x);
2743 return;
2744 }
2745
2746 fatal_insn ("Bad insn to d30v_print_operand_address:", x);
2747 }
2748
2749 \f
2750 /* Print a memory reference suitable for the ld/st instructions. */
2751
2752 static void
2753 d30v_print_operand_memory_reference (stream, x)
2754 FILE *stream;
2755 rtx x;
2756 {
2757 rtx x0 = NULL_RTX;
2758 rtx x1 = NULL_RTX;
2759
2760 switch (GET_CODE (x))
2761 {
2762 default:
2763 fatal_insn ("Bad insn to d30v_print_operand_memory_reference:", x);
2764 break;
2765
2766 case SUBREG:
2767 case REG:
2768 case POST_DEC:
2769 case POST_INC:
2770 x0 = x;
2771 break;
2772
2773 case CONST_INT:
2774 case SYMBOL_REF:
2775 case LABEL_REF:
2776 case CONST:
2777 x1 = x;
2778 break;
2779
2780 case PLUS:
2781 x0 = XEXP (x, 0);
2782 x1 = XEXP (x, 1);
2783 if (GET_CODE (x0) == CONST_INT || GET_CODE (x0) == SYMBOL_REF
2784 || GET_CODE (x0) == CONST || GET_CODE (x0) == LABEL_REF)
2785 {
2786 x0 = XEXP (x, 1);
2787 x1 = XEXP (x, 0);
2788 }
2789 break;
2790 }
2791
2792 fputs ("@(", stream);
2793 if (!x0)
2794 fputs (reg_names[GPR_R0], stream);
2795
2796 else
2797 {
2798 char *suffix = "";
2799 int offset0 = 0;
2800
2801 if (GET_CODE (x0) == SUBREG)
2802 {
2803 offset0 = SUBREG_WORD (x0);
2804 x0 = SUBREG_REG (x0);
2805 }
2806
2807 if (GET_CODE (x0) == POST_INC)
2808 {
2809 x0 = XEXP (x0, 0);
2810 suffix = "+";
2811 }
2812 else if (GET_CODE (x0) == POST_DEC)
2813 {
2814 x0 = XEXP (x0, 0);
2815 suffix = "-";
2816 }
2817
2818 if (GET_CODE (x0) == REG && GPR_P (REGNO (x0)))
2819 fprintf (stream, "%s%s", reg_names[REGNO (x0) + offset0], suffix);
2820 else
2821 fatal_insn ("Bad insn to d30v_print_operand_memory_reference:", x);
2822 }
2823
2824 fputs (",", stream);
2825
2826 if (!x1)
2827 fputs (reg_names[GPR_R0], stream);
2828
2829 else
2830 {
2831 int offset1 = 0;
2832
2833 switch (GET_CODE (x1))
2834 {
2835 case SUBREG:
2836 offset1 = SUBREG_WORD (x1);
2837 x1 = SUBREG_REG (x1);
2838 if (GET_CODE (x1) != REG)
2839 fatal_insn ("Bad insn to d30v_print_operand_memory_reference:", x);
2840
2841 /* fall through */
2842 case REG:
2843 fputs (reg_names[REGNO (x1) + offset1], stream);
2844 break;
2845
2846 case CONST_INT:
2847 fprintf (stream, "%ld", (long) INTVAL (x1));
2848 break;
2849
2850 case SYMBOL_REF:
2851 case LABEL_REF:
2852 case CONST:
2853 d30v_print_operand_address (stream, x1);
2854 break;
2855
2856 default:
2857 fatal_insn ("Bad insn to d30v_print_operand_memory_reference:", x);
2858 }
2859 }
2860
2861 fputs (")", stream);
2862 }
2863
2864 \f
2865 /* A C compound statement to output to stdio stream STREAM the assembler syntax
2866 for an instruction operand X. X is an RTL expression.
2867
2868 LETTER is a value that can be used to specify one of several ways of
2869 printing the operand. It is used when identical operands must be printed
2870 differently depending on the context. LETTER comes from the `%'
2871 specification that was used to request printing of the operand. If the
2872 specification was just `%DIGIT' then LETTER is 0; if the specification was
2873 `%LTR DIGIT' then LETTER is the ASCII code for LTR.
2874
2875 If X is a register, this macro should print the register's name. The names
2876 can be found in an array `reg_names' whose type is `char *[]'. `reg_names'
2877 is initialized from `REGISTER_NAMES'.
2878
2879 When the machine description has a specification `%PUNCT' (a `%' followed by
2880 a punctuation character), this macro is called with a null pointer for X and
2881 the punctuation character for LETTER.
2882
2883 Standard operand flags that are handled elsewhere:
2884 `=' Output a number unique to each instruction in the compilation.
2885 `a' Substitute an operand as if it were a memory reference.
2886 `c' Omit the syntax that indicates an immediate operand.
2887 `l' Substitute a LABEL_REF into a jump instruction.
2888 `n' Like %cDIGIT, except negate the value before printing.
2889
2890 The d30v specific operand flags are:
2891 `.' Print r0.
2892 `f' Print a SF constant as an int.
2893 `s' Subtract 32 and negate.
2894 `A' Print accumulator number without an `a' in front of it.
2895 `B' Print bit offset for BSET, etc. instructions.
2896 `E' Print u if this is zero extend, nothing if this is sign extend.
2897 `F' Emit /{f,t,x}{f,t,x} for executing a false condition.
2898 `L' Print the lower half of a 64 bit item.
2899 `M' Print a memory reference for ld/st instructions.
2900 `R' Return appropriate cmp instruction for relational test.
2901 `S' Subtract 32.
2902 `T' Emit /{f,t,x}{f,t,x} for executing a true condition.
2903 `U' Print the upper half of a 64 bit item. */
2904
2905 void
2906 d30v_print_operand (stream, x, letter)
2907 FILE *stream;
2908 rtx x;
2909 int letter;
2910 {
2911 enum rtx_code code = (x) ? GET_CODE (x) : NIL;
2912 rtx split_values[2];
2913 REAL_VALUE_TYPE rv;
2914 long num;
2915 int log;
2916
2917 switch (letter)
2918 {
2919 case '.': /* Output r0 */
2920 fputs (reg_names[GPR_R0], stream);
2921 break;
2922
2923 case 'f': /* Print a SF floating constant as an int */
2924 if (GET_CODE (x) != CONST_DOUBLE)
2925 fatal_insn ("Bad insn to d30v_print_operand, 'f' modifier:", x);
2926
2927 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2928 REAL_VALUE_TO_TARGET_SINGLE (rv, num);
2929 fprintf (stream, "%ld", num);
2930 break;
2931
2932 case 'A': /* Print accumulator number without an `a' in front of it. */
2933 if (GET_CODE (x) != REG || !ACCUM_P (REGNO (x)))
2934 fatal_insn ("Bad insn to d30v_print_operand, 'A' modifier:", x);
2935
2936 putc ('0' + REGNO (x) - ACCUM_FIRST, stream);
2937 break;
2938
2939 case 'M': /* Print a memory reference for ld/st */
2940 if (GET_CODE (x) != MEM)
2941 fatal_insn ("Bad insn to d30v_print_operand, 'M' modifier:", x);
2942
2943 d30v_print_operand_memory_reference (stream, XEXP (x, 0));
2944 break;
2945
2946 case 'L': /* print lower part of 64 bit item. */
2947 case 'U': /* print upper part of 64 bit item. */
2948 d30v_split_double (x, &split_values[0], &split_values[1]);
2949 d30v_print_operand (stream, split_values[ letter == 'L' ], '\0');
2950 break;
2951
2952 case 'F': /* Print an appropriate suffix for a false comparision. */
2953 case 'T': /* Print an appropriate suffix for a true comparision. */
2954 /* Note that the sense of appropriate suffix is for conditional execution
2955 and opposite of what branches want. Branches just use the inverse
2956 operation. */
2957 if ((GET_CODE (x) == NE || GET_CODE (x) == EQ)
2958 && GET_MODE (x) == CCmode
2959 && GET_CODE (XEXP (x, 0)) == REG
2960 && (GPR_P (REGNO (XEXP (x, 0))) || BR_FLAG_P (REGNO (XEXP (x, 0))))
2961 && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
2962 {
2963 int true_false = (letter == 'T');
2964
2965 if (GET_CODE (x) == EQ)
2966 true_false = !true_false;
2967
2968 if (REGNO (XEXP (x, 0)) == FLAG_F0)
2969 fprintf (stream, "/%cx", (true_false) ? 'f' : 't');
2970
2971 else if (REGNO (XEXP (x, 0)) == FLAG_F1)
2972 fprintf (stream, "/x%c", (true_false) ? 'f' : 't');
2973
2974 else
2975 fputs ((true_false) ? "tnz" : "tzr", stream);
2976 }
2977
2978 else if (GET_CODE (x) == REG && REGNO (x) == FLAG_F0)
2979 fprintf (stream, "/%cx", (letter == 'T') ? 't' : 'f');
2980
2981 else if (GET_CODE (x) == REG && REGNO (x) == FLAG_F1)
2982 fprintf (stream, "/x%c", (letter == 'T') ? 't' : 'f');
2983
2984 else if (GET_CODE (x) == REG && GPR_P (REGNO (x)))
2985 fputs ((letter == 'T') ? "tnz" : "tzr", stream);
2986
2987 else
2988 fatal_insn ("Bad insn to print_operand, 'F' or 'T' modifier:", x);
2989 break;
2990
2991 case 'B': /* emit offset single bit to change */
2992 if (GET_CODE (x) == CONST_INT && (log = exact_log2 (INTVAL (x))) >= 0)
2993 fprintf (stream, "%d", 31 - log);
2994
2995 else if (GET_CODE (x) == CONST_INT && (log = exact_log2 (~ INTVAL (x))) >= 0)
2996 fprintf (stream, "%d", 31 - log);
2997
2998 else
2999 fatal_insn ("Bad insn to print_operand, 'B' modifier:", x);
3000 break;
3001
3002 case 'E': /* Print u if this is zero extend, nothing if sign extend. */
3003 if (GET_CODE (x) == ZERO_EXTEND)
3004 putc ('u', stream);
3005 else if (GET_CODE (x) != SIGN_EXTEND)
3006 fatal_insn ("Bad insn to print_operand, 'E' modifier:", x);
3007 break;
3008
3009 case 'R': /* Return appropriate cmp instruction for relational test. */
3010 switch (GET_CODE (x))
3011 {
3012 case EQ: fputs ("cmpeq", stream); break;
3013 case NE: fputs ("cmpne", stream); break;
3014 case LT: fputs ("cmplt", stream); break;
3015 case LE: fputs ("cmple", stream); break;
3016 case GT: fputs ("cmpgt", stream); break;
3017 case GE: fputs ("cmpge", stream); break;
3018 case LTU: fputs ("cmpult", stream); break;
3019 case LEU: fputs ("cmpule", stream); break;
3020 case GTU: fputs ("cmpugt", stream); break;
3021 case GEU: fputs ("cmpuge", stream); break;
3022
3023 default:
3024 fatal_insn ("Bad insn to print_operand, 'R' modifier:", x);
3025 }
3026 break;
3027
3028 case 's': /* Subtract 32 and negate (for 64 bit shifts). */
3029 if (GET_CODE (x) == CONST_INT)
3030 fprintf (stream, "%d", (int) (32 - INTVAL (x)));
3031
3032 else
3033 fatal_insn ("Bad insn to print_operand, 's' modifier:", x);
3034 break;
3035
3036 case 'S': /* Subtract 32. */
3037 if (GET_CODE (x) == CONST_INT)
3038 fprintf (stream, "%d", (int)(INTVAL (x) - 32));
3039
3040 else
3041 fatal_insn ("Bad insn to print_operand, 's' modifier:", x);
3042 break;
3043
3044
3045 case 'z': /* If arg is 0 or 0.0, print r0, otherwise print as normal */
3046 if ((GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
3047 || (GET_CODE (x) == CONST_DOUBLE && CONST_DOUBLE_LOW (x) == 0
3048 && CONST_DOUBLE_HIGH (x) == 0))
3049 {
3050 fputs (reg_names[GPR_FIRST], stream);
3051 return;
3052 }
3053
3054 /* fall through */
3055
3056 case '\0':
3057 if (code == REG)
3058 fputs (reg_names[ REGNO (x) ], stream);
3059
3060 else if (code == CONST_INT)
3061 fprintf (stream, "%d", (int)INTVAL (x));
3062
3063 else if (code == MEM)
3064 d30v_print_operand_address (stream, XEXP (x, 0));
3065
3066 else if (CONSTANT_ADDRESS_P (x))
3067 d30v_print_operand_address (stream, x);
3068
3069 else
3070 fatal_insn ("Bad insn in d30v_print_operand, 0 case", x);
3071
3072 return;
3073
3074 default:
3075 {
3076 char buf[80];
3077
3078 sprintf (buf, "Invalid asm template character '%%%c'", letter);
3079 fatal_insn (buf, x);
3080 }
3081 }
3082 }
3083
3084 \f
3085 /* A C expression for the size in bytes of the trampoline, as an integer. */
3086
3087 int
3088 d30v_trampoline_size ()
3089 {
3090 return 16;
3091 }
3092
3093 \f
3094 /* Create a long instruction for building up a trampoline. */
3095
3096 static void
3097 d30v_build_long_insn (high_bits, low_bits, imm, mem)
3098 HOST_WIDE_INT high_bits;
3099 HOST_WIDE_INT low_bits;
3100 rtx imm;
3101 rtx mem;
3102 {
3103 rtx reg = gen_reg_rtx (DImode);
3104 rtx high_word = gen_highpart (SImode, reg);
3105 rtx low_word = gen_lowpart (SImode, reg);
3106 rtx tmp1 = gen_reg_rtx (SImode);
3107 rtx tmp2 = gen_reg_rtx (SImode);
3108 rtx tmp3 = gen_reg_rtx (SImode);
3109 rtx tmp4 = gen_reg_rtx (SImode);
3110 rtx tmp5 = gen_reg_rtx (SImode);
3111 rtx tmp6 = gen_reg_rtx (SImode);
3112
3113 imm = force_reg (SImode, imm);
3114
3115 /* Stuff top 6 bits of immediate value into high word */
3116 emit_insn (gen_lshrsi3 (tmp1, imm, GEN_INT (26)));
3117 emit_insn (gen_andsi3 (tmp2, tmp1, GEN_INT (0x3F)));
3118 emit_insn (gen_iorsi3 (high_word, tmp2, GEN_INT (high_bits)));
3119
3120 /* Now get the next 8 bits for building the low word */
3121 emit_insn (gen_andsi3 (tmp3, imm, GEN_INT (0x03FC0000)));
3122 emit_insn (gen_ashlsi3 (tmp4, tmp3, GEN_INT (2)));
3123
3124 /* And the bottom 18 bits */
3125 emit_insn (gen_andsi3 (tmp5, imm, GEN_INT (0x0003FFFF)));
3126 emit_insn (gen_iorsi3 (tmp6, tmp4, tmp5));
3127 emit_insn (gen_iorsi3 (low_word, tmp6, GEN_INT (low_bits)));
3128
3129 /* Store the instruction */
3130 emit_insn (gen_movdi (mem, reg));
3131 }
3132
3133 \f
3134 /* A C statement to initialize the variable parts of a trampoline. ADDR is an
3135 RTX for the address of the trampoline; FNADDR is an RTX for the address of
3136 the nested function; STATIC_CHAIN is an RTX for the static chain value that
3137 should be passed to the function when it is called. */
3138
3139 void
3140 d30v_initialize_trampoline (addr, fnaddr, static_chain)
3141 rtx addr;
3142 rtx fnaddr;
3143 rtx static_chain;
3144 {
3145 /* The instruction space can only be accessed by ld2w/st2w.
3146 Generate on the fly:
3147 or r18,r0,<static-chain>
3148 jmp <fnaddr> */
3149 d30v_build_long_insn (0x83A80000 | ((STATIC_CHAIN_REGNUM - GPR_FIRST) << 12),
3150 0x80000000, static_chain,
3151 gen_rtx (MEM, DImode, addr));
3152
3153 d30v_build_long_insn (0x80180000, 0x80000000, fnaddr,
3154 gen_rtx (MEM, DImode, plus_constant (addr, 8)));
3155 }
3156
3157 \f
3158 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3159 RTX) is a legitimate memory address on the target machine for a memory
3160 operand of mode MODE.
3161
3162 It usually pays to define several simpler macros to serve as subroutines for
3163 this one. Otherwise it may be too complicated to understand.
3164
3165 This macro must exist in two variants: a strict variant and a non-strict
3166 one. The strict variant is used in the reload pass. It must be defined so
3167 that any pseudo-register that has not been allocated a hard register is
3168 considered a memory reference. In contexts where some kind of register is
3169 required, a pseudo-register with no hard register must be rejected.
3170
3171 The non-strict variant is used in other passes. It must be defined to
3172 accept all pseudo-registers in every context where some kind of register is
3173 required.
3174
3175 Compiler source files that want to use the strict variant of this macro
3176 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3177 conditional to define the strict variant in that case and the non-strict
3178 variant otherwise.
3179
3180 Subroutines to check for acceptable registers for various purposes (one for
3181 base registers, one for index registers, and so on) are typically among the
3182 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3183 subroutine macros need have two variants; the higher levels of macros may be
3184 the same whether strict or not.
3185
3186 Normally, constant addresses which are the sum of a `symbol_ref' and an
3187 integer are stored inside a `const' RTX to mark them as constant.
3188 Therefore, there is no need to recognize such sums specifically as
3189 legitimate addresses. Normally you would simply recognize any `const' as
3190 legitimate.
3191
3192 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3193 are not marked with `const'. It assumes that a naked `plus' indicates
3194 indexing. If so, then you *must* reject such naked constant sums as
3195 illegitimate addresses, so that none of them will be given to
3196 `PRINT_OPERAND_ADDRESS'.
3197
3198 On some machines, whether a symbolic address is legitimate depends on the
3199 section that the address refers to. On these machines, define the macro
3200 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3201 then check for it here. When you see a `const', you will have to look
3202 inside it to find the `symbol_ref' in order to determine the section. *Note
3203 Assembler Format::.
3204
3205 The best way to modify the name string is by adding text to the beginning,
3206 with suitable punctuation to prevent any ambiguity. Allocate the new name
3207 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3208 remove and decode the added text and output the name accordingly, and define
3209 `STRIP_NAME_ENCODING' to access the original name string.
3210
3211 You can check the information stored here into the `symbol_ref' in the
3212 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3213 `PRINT_OPERAND_ADDRESS'.
3214
3215 Return 0 if the address is not legitimate, 1 if the address would fit
3216 in a short instruction, or 2 if the address would fit in a long
3217 instruction. */
3218
3219 #define XREGNO_OK_FOR_BASE_P(REGNO, STRICT_P) \
3220 ((STRICT_P) \
3221 ? REGNO_OK_FOR_BASE_P (REGNO) \
3222 : GPR_OR_PSEUDO_P (REGNO))
3223
3224 int
3225 d30v_legitimate_address_p (mode, x, strict_p)
3226 enum machine_mode mode;
3227 rtx x;
3228 int strict_p;
3229 {
3230 rtx x0, x1;
3231 int ret = 0;
3232
3233 switch (GET_CODE (x))
3234 {
3235 default:
3236 break;
3237
3238 case SUBREG:
3239 x = SUBREG_REG (x);
3240 if (GET_CODE (x) != REG)
3241 break;
3242
3243 /* fall through */
3244
3245 case REG:
3246 ret = XREGNO_OK_FOR_BASE_P (REGNO (x), strict_p);
3247 break;
3248
3249 case PLUS:
3250 x0 = XEXP (x, 0);
3251 x1 = XEXP (x, 1);
3252
3253 if (GET_CODE (x0) == SUBREG)
3254 x0 = SUBREG_REG (x0);
3255
3256 if (GET_CODE (x0) == POST_INC || GET_CODE (x0) == POST_DEC)
3257 x0 = XEXP (x0, 0);
3258
3259 if (GET_CODE (x0) != REG || !XREGNO_OK_FOR_BASE_P (REGNO (x0), strict_p))
3260 break;
3261
3262 switch (GET_CODE (x1))
3263 {
3264 default:
3265 break;
3266
3267 case SUBREG:
3268 x1 = SUBREG_REG (x1);
3269 if (GET_CODE (x1) != REG)
3270 break;
3271
3272 /* fall through */
3273
3274 case REG:
3275 ret = XREGNO_OK_FOR_BASE_P (REGNO (x1), strict_p);
3276 break;
3277
3278 case CONST_INT:
3279 ret = (IN_RANGE_P (INTVAL (x1), -32, 31)) ? 1 : 2;
3280 break;
3281
3282 case SYMBOL_REF:
3283 case LABEL_REF:
3284 case CONST:
3285 ret = 2;
3286 break;
3287 }
3288 break;
3289
3290 case CONST_INT:
3291 ret = (IN_RANGE_P (INTVAL (x), -32, 31)) ? 1 : 2;
3292 break;
3293
3294 case SYMBOL_REF:
3295 case LABEL_REF:
3296 case CONST:
3297 ret = 2;
3298 break;
3299
3300 case POST_INC:
3301 case POST_DEC:
3302 x0 = XEXP (x, 0);
3303 if (GET_CODE (x0) == REG && XREGNO_OK_FOR_BASE_P (REGNO (x0), strict_p))
3304 ret = 1;
3305 break;
3306 }
3307
3308 if (TARGET_DEBUG_ADDR)
3309 {
3310 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict\n",
3311 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ");
3312 debug_rtx (x);
3313 }
3314
3315 return ret;
3316 }
3317
3318 \f
3319 /* A C compound statement that attempts to replace X with a valid memory
3320 address for an operand of mode MODE. WIN will be a C statement label
3321 elsewhere in the code; the macro definition may use
3322
3323 GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
3324
3325 to avoid further processing if the address has become legitimate.
3326
3327 X will always be the result of a call to `break_out_memory_refs', and OLDX
3328 will be the operand that was given to that function to produce X.
3329
3330 The code generated by this macro should not alter the substructure of X. If
3331 it transforms X into a more legitimate form, it should assign X (which will
3332 always be a C variable) a new value.
3333
3334 It is not necessary for this macro to come up with a legitimate address.
3335 The compiler has standard ways of doing so in all cases. In fact, it is
3336 safe for this macro to do nothing. But often a machine-dependent strategy
3337 can generate better code. */
3338
3339 rtx
3340 d30v_legitimize_address (x, oldx, mode, strict_p)
3341 rtx x;
3342 rtx oldx ATTRIBUTE_UNUSED;
3343 enum machine_mode mode ATTRIBUTE_UNUSED;
3344 int strict_p ATTRIBUTE_UNUSED;
3345 {
3346 rtx ret = NULL_RTX;
3347
3348 if (TARGET_DEBUG_ADDR)
3349 {
3350 if (ret)
3351 {
3352 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, transformed:\n");
3353 debug_rtx (x);
3354 fprintf (stderr, "\ninto:\n");
3355 debug_rtx (ret);
3356 }
3357 else
3358 {
3359 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, did nothing with:\n");
3360 debug_rtx (x);
3361 }
3362 }
3363
3364 return ret;
3365 }
3366
3367 \f
3368 /* A C statement or compound statement with a conditional `goto LABEL;'
3369 executed if memory address X (an RTX) can have different meanings depending
3370 on the machine mode of the memory reference it is used for or if the address
3371 is valid for some modes but not others.
3372
3373 Autoincrement and autodecrement addresses typically have mode-dependent
3374 effects because the amount of the increment or decrement is the size of the
3375 operand being addressed. Some machines have other mode-dependent addresses.
3376 Many RISC machines have no mode-dependent addresses.
3377
3378 You may assume that ADDR is a valid address for the machine. */
3379
3380 int
3381 d30v_mode_dependent_address_p (addr)
3382 rtx addr;
3383 {
3384 switch (GET_CODE (addr))
3385 {
3386 default:
3387 break;
3388
3389 case POST_INC:
3390 case POST_DEC:
3391 return TRUE;
3392 }
3393
3394 return FALSE;
3395 }
3396
3397 \f
3398 /* Generate the appropriate comparison code for a test. */
3399
3400 rtx
3401 d30v_emit_comparison (test_int, result, arg1, arg2)
3402 int test_int;
3403 rtx result;
3404 rtx arg1;
3405 rtx arg2;
3406 {
3407 enum rtx_code test = (enum rtx_code) test_int;
3408 enum machine_mode mode = GET_MODE (arg1);
3409 rtx rtx_test = gen_rtx (SET, VOIDmode, result, gen_rtx (test, CCmode, arg1, arg2));
3410
3411 if (mode == SImode
3412 || (mode == DImode && (test == EQ || test == NE))
3413 || (mode == DImode && (test == LT || test == GE)
3414 && GET_CODE (arg2) == CONST_INT && INTVAL (arg2) == 0))
3415 return rtx_test;
3416
3417 else if (mode == DImode)
3418 return gen_rtx (PARALLEL, VOIDmode,
3419 gen_rtvec (2,
3420 rtx_test,
3421 gen_rtx (CLOBBER, VOIDmode,
3422 gen_reg_rtx (CCmode))));
3423
3424 else
3425 fatal_insn ("d30v_emit_comparison", rtx_test);
3426 }
3427
3428 \f
3429 /* Return appropriate code to move 2 words. Since DImode registers must start
3430 on even register numbers, there is no possibility of overlap. */
3431
3432 char *
3433 d30v_move_2words (operands, insn)
3434 rtx operands[];
3435 rtx insn;
3436 {
3437 if (GET_CODE (operands[0]) == REG && GPR_P (REGNO (operands[0])))
3438 {
3439 if (GET_CODE (operands[1]) == REG && GPR_P (REGNO (operands[1])))
3440 return "or %U0,%.,%U1\n\tor %L0,%.,%L1";
3441
3442 else if (GET_CODE (operands[1]) == REG && ACCUM_P (REGNO (operands[1])))
3443 return "mvfacc %L0,%1,%.\n\tmvfacc %U0,%1,32";
3444
3445 else if (GET_CODE (operands[1]) == MEM)
3446 return "ld2w %0,%M1";
3447
3448 else if (GET_CODE (operands[1]) == CONST_INT
3449 || GET_CODE (operands[1]) == CONST_DOUBLE)
3450 return "or %U0,%.,%U1\n\tor %L0,%.,%L1";
3451 }
3452
3453 else if (GET_CODE (operands[0]) == REG && ACCUM_P (REGNO (operands[0])))
3454 {
3455 if (GET_CODE (operands[1]) == REG
3456 && GPR_P (REGNO (operands[1])))
3457 return "mvtacc %0,%U1,%L1";
3458
3459 if (GET_CODE (operands[1]) == CONST_INT
3460 && INTVAL (operands[1]) == 0)
3461 return "mvtacc %0,%.,%.";
3462 }
3463
3464 else if (GET_CODE (operands[0]) == MEM
3465 && GET_CODE (operands[1]) == REG
3466 && GPR_P (REGNO (operands[1])))
3467 return "st2w %1,%M0";
3468
3469 fatal_insn ("Bad call to d30v_move_2words", insn);
3470 }
3471
3472 \f
3473 /* Emit the code to do a conditional move instruction. Return FALSE
3474 if the conditional move could not be executed. */
3475
3476 int
3477 d30v_emit_cond_move (dest, test, true_value, false_value)
3478 rtx dest;
3479 rtx test;
3480 rtx true_value;
3481 rtx false_value;
3482 {
3483 rtx br_reg;
3484 enum machine_mode mode = GET_MODE (dest);
3485 int two_mem_moves_p = FALSE;
3486
3487 if (GET_CODE (dest) == MEM)
3488 {
3489 if (!reg_or_0_operand (true_value, mode))
3490 return FALSE;
3491
3492 if (rtx_equal_p (dest, false_value))
3493 two_mem_moves_p = TRUE;
3494
3495 else if (!reg_or_0_operand (false_value, mode))
3496 return FALSE;
3497 }
3498
3499 /* We used to try to optimize setting 0/1 by using mvfsys, but that turns out
3500 to be slower than just doing the conditional execution. */
3501
3502 br_reg = gen_reg_rtx (CCmode);
3503 emit_insn (d30v_emit_comparison (GET_CODE (test), br_reg,
3504 d30v_compare_op0, d30v_compare_op1));
3505
3506 if (!two_mem_moves_p)
3507 emit_insn (gen_rtx_SET (VOIDmode,
3508 dest,
3509 gen_rtx_IF_THEN_ELSE (mode,
3510 gen_rtx_NE (CCmode, br_reg,
3511 const0_rtx),
3512 true_value,
3513 false_value)));
3514 else
3515 {
3516 /* Emit conditional stores as two separate stores. This avoids a problem
3517 where you have a conditional store, and one of the arms of the
3518 conditional store is spilled to memory. */
3519 emit_insn (gen_rtx_SET (VOIDmode,
3520 dest,
3521 gen_rtx_IF_THEN_ELSE (mode,
3522 gen_rtx_NE (CCmode, br_reg,
3523 const0_rtx),
3524 true_value,
3525 dest)));
3526
3527 emit_insn (gen_rtx_SET (VOIDmode,
3528 dest,
3529 gen_rtx_IF_THEN_ELSE (mode,
3530 gen_rtx_EQ (CCmode, br_reg,
3531 const0_rtx),
3532 false_value,
3533 dest)));
3534
3535 }
3536
3537 return TRUE;
3538 }
3539
3540 \f
3541 /* In rare cases, correct code generation requires extra machine dependent
3542 processing between the second jump optimization pass and delayed branch
3543 scheduling. On those machines, define this macro as a C statement to act on
3544 the code starting at INSN. */
3545
3546 void
3547 d30v_machine_dependent_reorg (insn)
3548 rtx insn ATTRIBUTE_UNUSED;
3549 {
3550 }
3551
3552 \f
3553 /* A C statement (sans semicolon) to update the integer variable COST based on
3554 the relationship between INSN that is dependent on DEP_INSN through the
3555 dependence LINK. The default is to make no adjustment to COST. This can be
3556 used for example to specify to the scheduler that an output- or
3557 anti-dependence does not incur the same cost as a data-dependence. */
3558
3559 /* For the d30v, try to insure that the source operands for a load/store are
3560 set 2 cycles before the memory reference. */
3561
3562 int
3563 d30v_adjust_cost (insn, link, dep_insn, cost)
3564 rtx insn;
3565 rtx link ATTRIBUTE_UNUSED;
3566 rtx dep_insn;
3567 int cost;
3568 {
3569 rtx set_dep = single_set (dep_insn);
3570 rtx set_insn = single_set (insn);
3571
3572 if (set_dep != NULL_RTX && set_insn != NULL_RTX
3573 && GET_CODE (SET_DEST (set_dep)) == REG)
3574 {
3575 rtx reg = SET_DEST (set_dep);
3576 rtx mem;
3577
3578 if ((GET_CODE (mem = SET_SRC (set_insn)) == MEM
3579 && reg_mentioned_p (reg, XEXP (mem, 0)))
3580 || (GET_CODE (mem = SET_DEST (set_insn)) == MEM
3581 && reg_mentioned_p (reg, XEXP (mem, 0))))
3582 {
3583 return cost + ((HAIFA_P) ? 2 : 4);
3584 }
3585 }
3586
3587 return cost;
3588 }
3589
3590 \f
3591 /* Functions to save and restore d30v_return_addr_rtx. */
3592
3593 struct machine_function
3594 {
3595 rtx ra_rtx;
3596 };
3597
3598 static void
3599 d30v_save_machine_status (p)
3600 struct function *p;
3601 {
3602 struct machine_function *machine =
3603 (struct machine_function *) xmalloc (sizeof (struct machine_function));
3604
3605 p->machine = machine;
3606 machine->ra_rtx = d30v_return_addr_rtx;
3607 }
3608
3609 static void
3610 d30v_restore_machine_status (p)
3611 struct function *p;
3612 {
3613 struct machine_function *machine = p->machine;
3614
3615 d30v_return_addr_rtx = machine->ra_rtx;
3616
3617 free (machine);
3618 p->machine = (struct machine_function *)0;
3619 }
3620
3621 /* Do anything needed before RTL is emitted for each function. */
3622
3623 void
3624 d30v_init_expanders ()
3625 {
3626 d30v_return_addr_rtx = NULL_RTX;
3627 d30v_eh_epilogue_sp_ofs = NULL_RTX;
3628
3629 /* Arrange to save and restore machine status around nested functions. */
3630 save_machine_status = d30v_save_machine_status;
3631 restore_machine_status = d30v_restore_machine_status;
3632 }
3633
3634 /* Find the current function's return address.
3635
3636 ??? It would be better to arrange things such that if we would ordinarily
3637 have been a leaf function and we didn't spill the hard reg that we
3638 wouldn't have to save the register in the prolog. But it's not clear
3639 how to get the right information at the right time. */
3640
3641 rtx
3642 d30v_return_addr ()
3643 {
3644 rtx ret;
3645
3646 if ((ret = d30v_return_addr_rtx) == NULL)
3647 {
3648 rtx init;
3649
3650 d30v_return_addr_rtx = ret = gen_reg_rtx (Pmode);
3651
3652 init = gen_rtx (SET, VOIDmode, ret, gen_rtx (REG, Pmode, GPR_LINK));
3653 push_topmost_sequence ();
3654 emit_insn_after (init, get_insns ());
3655 pop_topmost_sequence ();
3656 }
3657
3658 return ret;
3659 }
3660
3661 /* Called to register all of our global variables with the garbage
3662 collector. */
3663
3664 static void
3665 d30v_add_gc_roots ()
3666 {
3667 ggc_add_rtx_root (&d30v_compare_op0, 1);
3668 ggc_add_rtx_root (&d30v_compare_op1, 1);
3669 ggc_add_rtx_root (&d30v_eh_epilogue_sp_ofs, 1);
3670 ggc_add_rtx_root (&d30v_return_addr_rtx, 1);
3671 }