1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Jeff Law (law@cygnus.com).
5 This file is part of GNU CC.
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)
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.
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. */
27 #include "hard-reg-set.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-flags.h"
33 #include "insn-attr.h"
40 /* True if the current function has anonymous arguments. */
41 int current_function_anonymous_args
;
43 /* Information about the various small memory areas. */
44 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
46 /* name value max physical max */
47 { "tda", (char *)0, 0, 256 },
48 { "sda", (char *)0, 0, 65536 },
49 { "zda", (char *)0, 0, 32768 },
52 /* True if we don't need to check any more if the current
53 function is an interrupt handler */
54 static int v850_interrupt_cache_p
= FALSE
;
56 /* Whether current function is an interrupt handler. */
57 static int v850_interrupt_p
= FALSE
;
60 /* Sometimes certain combinations of command options do not make
61 sense on a particular target machine. You can define a macro
62 `OVERRIDE_OPTIONS' to take account of this. This macro, if
63 defined, is executed once just after all the command options have
66 Don't use this macro to turn on various extra optimizations for
67 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
75 /* Parse -m{s,t,z}da=nnn switches */
76 for (i
= 0; i
< (int)SMALL_MEMORY_max
; i
++)
78 if (small_memory
[i
].value
)
80 if (!isdigit (*small_memory
[i
].value
))
81 error ("%s=%s is not numeric.",
83 small_memory
[i
].value
);
86 small_memory
[i
].max
= atoi (small_memory
[i
].value
);
87 if (small_memory
[i
].max
> small_memory
[i
].physical_max
)
88 error ("%s=%s is too large.",
90 small_memory
[i
].value
);
97 /* Output assembly code for the start of the file. */
100 asm_file_start (file
)
103 output_file_directive (file
, main_input_filename
);
107 /* Return an RTX to represent where a value with mode MODE will be returned
108 from a function. If the result is 0, the argument is pushed. */
111 function_arg (cum
, mode
, type
, named
)
112 CUMULATIVE_ARGS
*cum
;
113 enum machine_mode mode
;
120 if (TARGET_GHS
&& !named
)
124 size
= int_size_in_bytes (type
);
126 size
= GET_MODE_SIZE (mode
);
129 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
133 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
135 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
138 if (type
== NULL_TREE
139 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
142 switch (cum
->nbytes
/ UNITS_PER_WORD
)
145 result
= gen_rtx (REG
, mode
, 6);
148 result
= gen_rtx (REG
, mode
, 7);
151 result
= gen_rtx (REG
, mode
, 8);
154 result
= gen_rtx (REG
, mode
, 9);
164 /* Return the number of words which must be put into registers
165 for values which are part in registers and part in memory. */
168 function_arg_partial_nregs (cum
, mode
, type
, named
)
169 CUMULATIVE_ARGS
*cum
;
170 enum machine_mode mode
;
176 if (TARGET_GHS
&& !named
)
180 size
= int_size_in_bytes (type
);
182 size
= GET_MODE_SIZE (mode
);
185 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
189 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
191 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
194 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
197 if (type
== NULL_TREE
198 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
201 return (4 * UNITS_PER_WORD
- cum
->nbytes
) / UNITS_PER_WORD
;
205 /* Return the high and low words of a CONST_DOUBLE */
208 const_double_split (x
, p_high
, p_low
)
210 HOST_WIDE_INT
*p_high
;
211 HOST_WIDE_INT
*p_low
;
213 if (GET_CODE (x
) == CONST_DOUBLE
)
218 switch (GET_MODE (x
))
221 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
222 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
223 *p_high
= t
[1]; /* since v850 is little endian */
224 *p_low
= t
[0]; /* high is second word */
228 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
229 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
235 *p_high
= CONST_DOUBLE_HIGH (x
);
236 *p_low
= CONST_DOUBLE_LOW (x
);
241 fatal_insn ("const_double_split got a bad insn:", x
);
245 /* Return the cost of the rtx R with code CODE. */
248 const_costs_int (value
, zero_cost
)
252 if (CONST_OK_FOR_I (value
))
254 else if (CONST_OK_FOR_J (value
))
256 else if (CONST_OK_FOR_K (value
))
267 HOST_WIDE_INT high
, low
;
272 return const_costs_int (INTVAL (r
), 0);
275 const_double_split (r
, &high
, &low
);
276 if (GET_MODE (r
) == SFmode
)
277 return const_costs_int (high
, 1);
279 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
295 /* Print operand X using operand code CODE to assembly language output file
299 print_operand (file
, x
, code
)
304 HOST_WIDE_INT high
, low
;
312 switch ((code
== 'B' || code
== 'C')
313 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
316 if (code
== 'c' || code
== 'C')
317 fprintf (file
, "nz");
319 fprintf (file
, "ne");
322 if (code
== 'c' || code
== 'C')
328 fprintf (file
, "ge");
331 fprintf (file
, "gt");
334 fprintf (file
, "le");
337 fprintf (file
, "lt");
340 fprintf (file
, "nl");
346 fprintf (file
, "nh");
355 case 'F': /* high word of CONST_DOUBLE */
356 if (GET_CODE (x
) == CONST_INT
)
357 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
358 else if (GET_CODE (x
) == CONST_DOUBLE
)
360 const_double_split (x
, &high
, &low
);
361 fprintf (file
, "%ld", (long) high
);
366 case 'G': /* low word of CONST_DOUBLE */
367 if (GET_CODE (x
) == CONST_INT
)
368 fprintf (file
, "%ld", (long) INTVAL (x
));
369 else if (GET_CODE (x
) == CONST_DOUBLE
)
371 const_double_split (x
, &high
, &low
);
372 fprintf (file
, "%ld", (long) low
);
378 fprintf (file
, "%d\n", INTVAL (x
) & 0xffff);
381 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
384 if (special_symbolref_operand (x
, VOIDmode
))
388 if (GET_CODE (x
) == SYMBOL_REF
)
390 else if (GET_CODE (x
) == CONST
)
391 name
= XSTR (XEXP (XEXP (x
, 0), 0), 0);
395 if (ZDA_NAME_P (name
))
396 fprintf (file
, "zdaoff");
397 else if (SDA_NAME_P (name
))
398 fprintf (file
, "sdaoff");
399 else if (TDA_NAME_P (name
))
400 fprintf (file
, "tdaoff");
408 if (special_symbolref_operand (x
, VOIDmode
))
409 output_addr_const (file
, x
);
414 if (special_symbolref_operand (x
, VOIDmode
))
418 if (GET_CODE (x
) == SYMBOL_REF
)
420 else if (GET_CODE (x
) == CONST
)
421 name
= XSTR (XEXP (XEXP (x
, 0), 0), 0);
425 if (ZDA_NAME_P (name
))
426 fprintf (file
, "r0");
427 else if (SDA_NAME_P (name
))
428 fprintf (file
, "gp");
429 else if (TDA_NAME_P (name
))
430 fprintf (file
, "ep");
437 case 'R': /* 2nd word of a double. */
438 switch (GET_CODE (x
))
441 fprintf (file
, reg_names
[REGNO (x
) + 1]);
444 print_operand_address (file
,
445 XEXP (adj_offsettable_operand (x
, 4), 0));
451 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
452 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
459 /* Like an 'S' operand above, but for unsigned loads only. */
460 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
465 case 'W': /* print the instruction suffix */
466 switch (GET_MODE (x
))
471 case QImode
: fputs (".b", file
); break;
472 case HImode
: fputs (".h", file
); break;
473 case SImode
: fputs (".w", file
); break;
474 case SFmode
: fputs (".w", file
); break;
477 case '.': /* register r0 */
478 fputs (reg_names
[0], file
);
480 case 'z': /* reg or zero */
482 fputs (reg_names
[0], file
);
483 else if (GET_CODE (x
) == REG
)
484 fputs (reg_names
[REGNO (x
)], file
);
489 switch (GET_CODE (x
))
492 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
493 output_address (gen_rtx (PLUS
, SImode
,
494 gen_rtx (REG
, SImode
, 0),
497 output_address (XEXP (x
, 0));
501 fputs (reg_names
[REGNO (x
)], file
);
504 fputs (reg_names
[REGNO (SUBREG_REG (x
)) + SUBREG_WORD (x
)], file
);
511 print_operand_address (file
, x
);
522 /* Output assembly language output for the address ADDR to FILE. */
525 print_operand_address (file
, addr
)
529 switch (GET_CODE (addr
))
532 fprintf (file
, "0[");
533 print_operand (file
, addr
, 0);
537 if (GET_CODE (XEXP (addr
, 0)) == REG
)
540 fprintf (file
, "lo(");
541 print_operand (file
, XEXP (addr
, 1), 0);
542 fprintf (file
, ")[");
543 print_operand (file
, XEXP (addr
, 0), 0);
548 if (GET_CODE (XEXP (addr
, 0)) == REG
549 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
552 print_operand (file
, XEXP (addr
, 1), 0);
554 print_operand (file
, XEXP (addr
, 0), 0);
559 print_operand (file
, XEXP (addr
, 0), 0);
561 print_operand (file
, XEXP (addr
, 1), 0);
565 if (ENCODED_NAME_P (XSTR (addr
, 0)))
567 char* name
= XSTR (addr
, 0);
571 if (ZDA_NAME_P (name
))
576 else if (SDA_NAME_P (name
))
581 else if (TDA_NAME_P (name
))
589 fprintf (file
, "%s(", off_name
);
590 output_addr_const (file
, addr
);
591 fprintf (file
, ")[%s]", reg_name
);
594 output_addr_const (file
, addr
);
597 if (special_symbolref_operand (addr
, VOIDmode
))
599 char* name
= XSTR (XEXP (XEXP (addr
, 0), 0), 0);
603 if (ZDA_NAME_P (name
))
608 else if (SDA_NAME_P (name
))
613 else if (TDA_NAME_P (name
))
621 fprintf (file
, "%s(", off_name
);
622 output_addr_const (file
, addr
);
623 fprintf (file
, ")[%s]", reg_name
);
626 output_addr_const (file
, addr
);
629 output_addr_const (file
, addr
);
635 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
639 output_move_single (operands
)
642 rtx dst
= operands
[0];
643 rtx src
= operands
[1];
650 else if (GET_CODE (src
) == CONST_INT
)
652 HOST_WIDE_INT value
= INTVAL (src
);
654 if (CONST_OK_FOR_J (value
)) /* signed 5 bit immediate */
657 else if (CONST_OK_FOR_K (value
)) /* signed 16 bit immediate */
658 return "movea lo(%1),%.,%0";
660 else if (CONST_OK_FOR_L (value
)) /* upper 16 bits were set */
661 return "movhi hi(%1),%.,%0";
663 else /* random constant */
664 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
667 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
669 HOST_WIDE_INT high
, low
;
671 const_double_split (src
, &high
, &low
);
672 if (CONST_OK_FOR_J (high
)) /* signed 5 bit immediate */
675 else if (CONST_OK_FOR_K (high
)) /* signed 16 bit immediate */
676 return "movea lo(%F1),%.,%0";
678 else if (CONST_OK_FOR_L (high
)) /* upper 16 bits were set */
679 return "movhi hi(%F1),%.,%0";
681 else /* random constant */
682 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
685 else if (GET_CODE (src
) == MEM
)
686 return "%S1ld%W1 %1,%0";
688 else if (special_symbolref_operand (src
, VOIDmode
))
689 return "movea %O1(%P1),%Q1,%0";
691 else if (GET_CODE (src
) == LABEL_REF
692 || GET_CODE (src
) == SYMBOL_REF
693 || GET_CODE (src
) == CONST
)
695 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
698 else if (GET_CODE (src
) == HIGH
)
699 return "movhi hi(%1),%.,%0";
701 else if (GET_CODE (src
) == LO_SUM
)
703 operands
[2] = XEXP (src
, 0);
704 operands
[3] = XEXP (src
, 1);
705 return "movea lo(%3),%2,%0";
709 else if (GET_CODE (dst
) == MEM
)
712 return "%S0st%W0 %1,%0";
714 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
715 return "%S0st%W0 %.,%0";
717 else if (GET_CODE (src
) == CONST_DOUBLE
718 && CONST0_RTX (GET_MODE (dst
)) == src
)
719 return "%S0st%W0 %.,%0";
722 fatal_insn ("output_move_single:", gen_rtx (SET
, VOIDmode
, dst
, src
));
727 /* Return appropriate code to load up an 8 byte integer or floating point value */
730 output_move_double (operands
)
733 enum machine_mode mode
= GET_MODE (operands
[0]);
734 rtx dst
= operands
[0];
735 rtx src
= operands
[1];
737 if (register_operand (dst
, mode
)
738 && register_operand (src
, mode
))
740 if (REGNO (src
) + 1 == REGNO (dst
))
741 return "mov %R1,%R0\n\tmov %1,%0";
743 return "mov %1,%0\n\tmov %R1,%R0";
747 if (GET_CODE (dst
) == MEM
748 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
749 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
750 return "st.w %.,%0\n\tst.w %.,%R0";
752 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
754 HOST_WIDE_INT high_low
[2];
758 if (GET_CODE (src
) == CONST_DOUBLE
)
759 const_double_split (src
, &high_low
[1], &high_low
[0]);
762 high_low
[0] = INTVAL (src
);
763 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
766 for (i
= 0; i
< 2; i
++)
768 xop
[0] = gen_rtx (REG
, SImode
, REGNO (dst
)+i
);
769 xop
[1] = GEN_INT (high_low
[i
]);
770 output_asm_insn (output_move_single (xop
), xop
);
776 if (GET_CODE (src
) == MEM
)
779 int dreg
= REGNO (dst
);
780 rtx inside
= XEXP (src
, 0);
782 if (GET_CODE (inside
) == REG
)
783 ptrreg
= REGNO (inside
);
784 else if (GET_CODE (inside
) == SUBREG
)
785 ptrreg
= REGNO (SUBREG_REG (inside
)) + SUBREG_WORD (inside
);
786 else if (GET_CODE (inside
) == PLUS
)
787 ptrreg
= REGNO (XEXP (inside
, 0));
788 else if (GET_CODE (inside
) == LO_SUM
)
789 ptrreg
= REGNO (XEXP (inside
, 0));
792 return "ld.w %R1,%R0\n\tld.w %1,%0";
795 if (GET_CODE (src
) == MEM
)
796 return "ld.w %1,%0\n\tld.w %R1,%R0";
798 if (GET_CODE (dst
) == MEM
)
799 return "st.w %1,%0\n\tst.w %R1,%R0";
801 return "mov %1,%0\n\tmov %R1,%R0";
805 /* Return maximum offset supported for a short EP memory reference of mode
806 MODE and signedness UNSIGNEDP. */
809 ep_memory_offset (mode
, unsignedp
)
810 enum machine_mode mode
;
818 max_offset
= (1 << 7);
822 max_offset
= (1 << 8);
827 max_offset
= (1 << 8);
834 /* Return true if OP is a valid short EP memory reference */
837 ep_memory_operand (op
, mode
, unsigned_load
)
839 enum machine_mode mode
;
846 if (GET_CODE (op
) != MEM
)
849 max_offset
= ep_memory_offset (mode
, unsigned_load
);
851 mask
= GET_MODE_SIZE (mode
) - 1;
854 if (GET_CODE (addr
) == CONST
)
855 addr
= XEXP (addr
, 0);
857 switch (GET_CODE (addr
))
863 return TDA_NAME_P (XSTR (addr
, 0));
866 return REGNO (addr
) == EP_REGNUM
;
869 op0
= XEXP (addr
, 0);
870 op1
= XEXP (addr
, 1);
871 if (GET_CODE (op1
) == CONST_INT
872 && INTVAL (op1
) < max_offset
873 && (INTVAL (op1
) & mask
) == 0)
875 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
878 if (GET_CODE (op0
) == SYMBOL_REF
&& TDA_NAME_P (XSTR (op0
, 0)))
887 /* Return true if OP is either a register or 0 */
890 reg_or_0_operand (op
, mode
)
892 enum machine_mode mode
;
894 if (GET_CODE (op
) == CONST_INT
)
895 return INTVAL (op
) == 0;
897 else if (GET_CODE (op
) == CONST_DOUBLE
)
898 return CONST_DOUBLE_OK_FOR_G (op
);
901 return register_operand (op
, mode
);
904 /* Return true if OP is either a register or a signed five bit integer */
907 reg_or_int5_operand (op
, mode
)
909 enum machine_mode mode
;
911 if (GET_CODE (op
) == CONST_INT
)
912 return CONST_OK_FOR_J (INTVAL (op
));
915 return register_operand (op
, mode
);
918 /* Return true if OP is a valid call operand. */
921 call_address_operand (op
, mode
)
923 enum machine_mode mode
;
925 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
926 if (TARGET_LONG_CALLS
)
927 return GET_CODE (op
) == REG
;
928 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == REG
);
932 special_symbolref_operand (op
, mode
)
934 enum machine_mode mode
;
936 if (GET_CODE (op
) == SYMBOL_REF
)
937 return ENCODED_NAME_P (XSTR (op
, 0));
939 else if (GET_CODE (op
) == CONST
)
940 return (GET_CODE (XEXP (op
, 0)) == PLUS
941 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
942 && ENCODED_NAME_P (XSTR (XEXP (XEXP (op
, 0), 0), 0))
943 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
944 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op
, 0), 1))));
950 movsi_source_operand (op
, mode
)
952 enum machine_mode mode
;
954 /* Some constants, as well as symbolic operands
955 must be done with HIGH & LO_SUM patterns. */
957 && GET_CODE (op
) != HIGH
958 && GET_CODE (op
) != CONSTANT_P_RTX
959 && !(GET_CODE (op
) == CONST_INT
960 && (CONST_OK_FOR_J (INTVAL (op
))
961 || CONST_OK_FOR_K (INTVAL (op
))
962 || CONST_OK_FOR_L (INTVAL (op
)))))
963 return special_symbolref_operand (op
, mode
);
965 return general_operand (op
, mode
);
969 power_of_two_operand (op
, mode
)
971 enum machine_mode mode
;
973 if (GET_CODE (op
) != CONST_INT
)
976 if (exact_log2 (INTVAL (op
)) == -1)
982 not_power_of_two_operand (op
, mode
)
984 enum machine_mode mode
;
990 else if (mode
== HImode
)
992 else if (mode
== SImode
)
997 if (GET_CODE (op
) != CONST_INT
)
1000 if (exact_log2 (~INTVAL (op
) & mask
) == -1)
1006 /* Substitute memory references involving a pointer, to use the ep pointer,
1007 taking care to save and preserve the ep. */
1010 substitute_ep_register (first_insn
, last_insn
, uses
, regno
, p_r1
, p_ep
)
1018 rtx reg
= gen_rtx (REG
, Pmode
, regno
);
1024 regs_ever_live
[1] = 1;
1025 *p_r1
= gen_rtx (REG
, Pmode
, 1);
1026 *p_ep
= gen_rtx (REG
, Pmode
, 30);
1030 fprintf (stderr
, "Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1031 2 * (uses
- 3), uses
, reg_names
[regno
],
1032 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1033 INSN_UID (first_insn
), INSN_UID (last_insn
));
1035 if (GET_CODE (first_insn
) == NOTE
)
1036 first_insn
= next_nonnote_insn (first_insn
);
1038 last_insn
= next_nonnote_insn (last_insn
);
1039 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1041 if (GET_CODE (insn
) == INSN
)
1043 rtx pattern
= single_set (insn
);
1045 /* Replace the memory references. */
1049 /* Memory operands are signed by default. */
1050 int unsignedp
= FALSE
;
1052 if (GET_CODE (SET_DEST (pattern
)) == MEM
1053 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1056 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1057 p_mem
= &SET_DEST (pattern
);
1059 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1060 p_mem
= &SET_SRC (pattern
);
1067 rtx addr
= XEXP (*p_mem
, 0);
1069 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == regno
)
1070 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1072 else if (GET_CODE (addr
) == PLUS
1073 && GET_CODE (XEXP (addr
, 0)) == REG
1074 && REGNO (XEXP (addr
, 0)) == regno
1075 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1076 && (((unsigned)INTVAL (XEXP (addr
, 1)))
1077 < ep_memory_offset (GET_MODE (*p_mem
),
1079 *p_mem
= change_address (*p_mem
, VOIDmode
,
1080 gen_rtx (PLUS
, Pmode
,
1081 *p_ep
, XEXP (addr
, 1)));
1087 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1088 insn
= prev_nonnote_insn (first_insn
);
1089 if (insn
&& GET_CODE (insn
) == INSN
1090 && GET_CODE (PATTERN (insn
)) == SET
1091 && SET_DEST (PATTERN (insn
)) == *p_ep
1092 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1095 emit_insn_before (gen_rtx (SET
, Pmode
, *p_r1
, *p_ep
), first_insn
);
1097 emit_insn_before (gen_rtx (SET
, Pmode
, *p_ep
, reg
), first_insn
);
1098 emit_insn_before (gen_rtx (SET
, Pmode
, *p_ep
, *p_r1
), last_insn
);
1102 /* In rare cases, correct code generation requires extra machine
1103 dependent processing between the second jump optimization pass and
1104 delayed branch scheduling. On those machines, define this macro
1105 as a C statement to act on the code starting at INSN.
1107 On the 850, we use it to implement the -mep mode to copy heavily used
1108 pointers to ep to use the implicit addressing */
1110 void v850_reorg (start_insn
)
1117 } regs
[FIRST_PSEUDO_REGISTER
];
1126 /* If not ep mode, just return now */
1130 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1133 regs
[i
].first_insn
= NULL_RTX
;
1134 regs
[i
].last_insn
= NULL_RTX
;
1137 for (insn
= start_insn
; insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1139 switch (GET_CODE (insn
))
1141 /* End of basic block */
1148 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1150 if (max_uses
< regs
[i
].uses
)
1152 max_uses
= regs
[i
].uses
;
1158 substitute_ep_register (regs
[max_regno
].first_insn
,
1159 regs
[max_regno
].last_insn
,
1160 max_uses
, max_regno
, &r1
, &ep
);
1164 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1167 regs
[i
].first_insn
= NULL_RTX
;
1168 regs
[i
].last_insn
= NULL_RTX
;
1176 pattern
= single_set (insn
);
1178 /* See if there are any memory references we can shorten */
1181 rtx src
= SET_SRC (pattern
);
1182 rtx dest
= SET_DEST (pattern
);
1184 /* Memory operands are signed by default. */
1185 int unsignedp
= FALSE
;
1187 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1190 else if (GET_CODE (dest
) == MEM
)
1193 else if (GET_CODE (src
) == MEM
)
1199 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1202 else if (!use_ep
&& mem
1203 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1205 rtx addr
= XEXP (mem
, 0);
1209 if (GET_CODE (addr
) == REG
)
1212 regno
= REGNO (addr
);
1215 else if (GET_CODE (addr
) == PLUS
1216 && GET_CODE (XEXP (addr
, 0)) == REG
1217 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1218 && (((unsigned)INTVAL (XEXP (addr
, 1)))
1219 < ep_memory_offset (GET_MODE (mem
), unsignedp
)))
1222 regno
= REGNO (XEXP (addr
, 0));
1231 regs
[regno
].last_insn
= insn
;
1232 if (!regs
[regno
].first_insn
)
1233 regs
[regno
].first_insn
= insn
;
1237 /* Loading up a register in the basic block zaps any savings
1239 if (GET_CODE (dest
) == REG
|| GET_CODE (dest
) == SUBREG
)
1241 enum machine_mode mode
= GET_MODE (dest
);
1246 while (GET_CODE (dest
) == SUBREG
)
1248 word
= SUBREG_WORD (dest
);
1249 dest
= SUBREG_REG (dest
);
1252 regno
= REGNO (dest
) + word
;
1253 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1257 /* See if we can use the pointer before this
1262 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1264 if (max_uses
< regs
[i
].uses
)
1266 max_uses
= regs
[i
].uses
;
1272 && max_regno
>= regno
1273 && max_regno
< endregno
)
1275 substitute_ep_register (regs
[max_regno
].first_insn
,
1276 regs
[max_regno
].last_insn
,
1277 max_uses
, max_regno
, &r1
, &ep
);
1279 /* Since we made a substitution, zap all remembered
1281 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1284 regs
[i
].first_insn
= NULL_RTX
;
1285 regs
[i
].last_insn
= NULL_RTX
;
1290 for (i
= regno
; i
< endregno
; i
++)
1293 regs
[i
].first_insn
= NULL_RTX
;
1294 regs
[i
].last_insn
= NULL_RTX
;
1303 /* # of registers saved by the interrupt handler. */
1304 #define INTERRUPT_FIXED_NUM 4
1306 /* # of bytes for registers saved by the interrupt handler. */
1307 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1309 /* # of registers saved in register parameter area. */
1310 #define INTERRUPT_REGPARM_NUM 4
1311 /* # of words saved for other registers. */
1312 #define INTERRUPT_ALL_SAVE_NUM \
1313 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1315 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1318 compute_register_save_size (p_reg_saved
)
1323 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1324 int call_p
= regs_ever_live
[31];
1327 /* Count the return pointer if we need to save it. */
1328 if (profile_flag
&& !call_p
)
1329 regs_ever_live
[31] = call_p
= 1;
1331 /* Count space for the register saves. */
1332 if (interrupt_handler
)
1334 for (i
= 0; i
<= 31; i
++)
1338 if (regs_ever_live
[i
] || call_p
)
1341 reg_saved
|= 1L << i
;
1345 /* We don't save/restore r0 or the stack pointer */
1347 case STACK_POINTER_REGNUM
:
1350 /* For registers with fixed use, we save them, set them to the
1351 appropriate value, and then restore them.
1352 These registers are handled specially, so don't list them
1353 on the list of registers to save in the prologue. */
1354 case 1: /* temp used to hold ep */
1356 case 10: /* temp used to call interrupt save/restore */
1357 case EP_REGNUM
: /* ep */
1364 for (i
= 0; i
<= 31; i
++)
1365 if (regs_ever_live
[i
] && ((! call_used_regs
[i
]) || i
== 31))
1368 reg_saved
|= 1L << i
;
1372 *p_reg_saved
= reg_saved
;
1378 compute_frame_size (size
, p_reg_saved
)
1382 extern int current_function_outgoing_args_size
;
1385 + compute_register_save_size (p_reg_saved
)
1386 + current_function_outgoing_args_size
);
1395 unsigned int size
= get_frame_size ();
1396 unsigned int actual_fsize
;
1397 unsigned int init_stack_alloc
= 0;
1403 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1406 actual_fsize
= compute_frame_size (size
, ®_saved
);
1408 /* Save/setup global registers for interrupt functions right now */
1409 if (interrupt_handler
)
1411 emit_insn (gen_save_interrupt ());
1412 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1413 if (((1L << 31) & reg_saved
) != 0)
1414 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1417 /* Save arg registers to the stack if necessary. */
1418 else if (current_function_anonymous_args
)
1420 if (TARGET_PROLOG_FUNCTION
)
1421 emit_insn (gen_save_r6_r9 ());
1425 for (i
= 6; i
< 10; i
++)
1427 emit_move_insn (gen_rtx (MEM
, SImode
,
1428 plus_constant (stack_pointer_rtx
,
1430 gen_rtx (REG
, SImode
, i
));
1436 /* Identify all of the saved registers */
1439 for (i
= 1; i
< 31; i
++)
1441 if (((1L << i
) & reg_saved
) != 0)
1442 save_regs
[num_save
++] = gen_rtx (REG
, Pmode
, i
);
1445 /* If the return pointer is saved, the helper functions also allocate
1446 16 bytes of stack for arguments to be saved in. */
1447 if (((1L << 31) & reg_saved
) != 0)
1449 save_regs
[num_save
++] = gen_rtx (REG
, Pmode
, 31);
1453 /* See if we have an insn that allocates stack space and saves the particular
1454 registers we want to. */
1455 save_all
= NULL_RTX
;
1456 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1458 int alloc_stack
= (4 * num_save
) + default_stack
;
1459 int unalloc_stack
= actual_fsize
- alloc_stack
;
1460 int save_func_len
= 4;
1461 int save_normal_len
;
1464 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1466 /* see if we would have used ep to save the stack */
1467 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1468 save_normal_len
= (3 * 2) + (2 * num_save
);
1470 save_normal_len
= 4 * num_save
;
1472 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1474 /* Don't bother checking if we don't actually save any space.
1475 This happens for instance if one register is saved and additional
1476 stack space is allocated. */
1477 if (save_func_len
< save_normal_len
)
1479 save_all
= gen_rtx (PARALLEL
, VOIDmode
, rtvec_alloc (num_save
+ (TARGET_V850
? 2 : 1)));
1480 XVECEXP (save_all
, 0, 0) = gen_rtx (SET
, VOIDmode
,
1482 gen_rtx (PLUS
, Pmode
,
1484 GEN_INT (-alloc_stack
)));
1488 XVECEXP (save_all
, 0, num_save
+1)
1489 = gen_rtx (CLOBBER
, VOIDmode
, gen_rtx (REG
, Pmode
, 10));
1492 offset
= - default_stack
;
1493 for (i
= 0; i
< num_save
; i
++)
1495 XVECEXP (save_all
, 0, i
+1)
1496 = gen_rtx (SET
, VOIDmode
,
1497 gen_rtx (MEM
, Pmode
,
1498 plus_constant (stack_pointer_rtx
, offset
)),
1503 code
= recog (save_all
, NULL_RTX
, NULL_PTR
);
1506 rtx insn
= emit_insn (save_all
);
1507 INSN_CODE (insn
) = code
;
1508 actual_fsize
-= alloc_stack
;
1511 fprintf (stderr
, "Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1512 save_normal_len
- save_func_len
,
1513 save_normal_len
, save_func_len
,
1514 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1517 save_all
= NULL_RTX
;
1521 /* If no prolog save function is available, store the registers the old fashioned
1522 way (one by one). */
1525 /* Special case interrupt functions that save all registers for a call. */
1526 if (interrupt_handler
&& ((1L << 31) & reg_saved
) != 0)
1527 emit_insn (gen_save_all_interrupt ());
1531 /* If the stack is too big, allocate it in chunks so we can do the
1532 register saves. We use the register save size so we use the ep
1534 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1535 init_stack_alloc
= compute_register_save_size (NULL
);
1537 init_stack_alloc
= actual_fsize
;
1539 /* Save registers at the beginning of the stack frame */
1540 offset
= init_stack_alloc
- 4;
1542 if (init_stack_alloc
)
1543 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1545 GEN_INT (-init_stack_alloc
)));
1547 /* Save the return pointer first. */
1548 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == 31)
1550 emit_move_insn (gen_rtx (MEM
, SImode
,
1551 plus_constant (stack_pointer_rtx
,
1553 save_regs
[--num_save
]);
1557 for (i
= 0; i
< num_save
; i
++)
1559 emit_move_insn (gen_rtx (MEM
, SImode
,
1560 plus_constant (stack_pointer_rtx
,
1568 /* Allocate the rest of the stack that was not allocated above (either it is
1569 > 32K or we just called a function to save the registers and needed more
1571 if (actual_fsize
> init_stack_alloc
)
1573 int diff
= actual_fsize
- init_stack_alloc
;
1574 if (CONST_OK_FOR_K (diff
))
1575 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1580 rtx reg
= gen_rtx (REG
, Pmode
, 12);
1581 emit_move_insn (reg
, GEN_INT (-diff
));
1582 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1586 /* If we need a frame pointer, set it up now. */
1587 if (frame_pointer_needed
)
1588 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1597 unsigned int size
= get_frame_size ();
1599 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1600 unsigned int init_stack_free
= 0;
1601 rtx restore_regs
[32];
1606 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1608 /* Eliminate the initial stack stored by interrupt functions. */
1609 if (interrupt_handler
)
1611 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1612 if (((1L << 31) & reg_saved
) != 0)
1613 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1616 /* Cut off any dynamic stack created. */
1617 if (frame_pointer_needed
)
1618 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1620 /* Identify all of the saved registers */
1623 for (i
= 1; i
< 31; i
++)
1625 if (((1L << i
) & reg_saved
) != 0)
1626 restore_regs
[num_restore
++] = gen_rtx (REG
, Pmode
, i
);
1629 /* If the return pointer is saved, the helper functions also allocate
1630 16 bytes of stack for arguments to be saved in. */
1631 if (((1L << 31) & reg_saved
) != 0)
1633 restore_regs
[num_restore
++] = gen_rtx (REG
, Pmode
, 31);
1637 /* See if we have an insn that restores the particular registers we
1639 restore_all
= NULL_RTX
;
1640 if (TARGET_PROLOG_FUNCTION
&& num_restore
> 0 && actual_fsize
>= default_stack
1641 && !interrupt_handler
)
1643 int alloc_stack
= (4 * num_restore
) + default_stack
;
1644 int unalloc_stack
= actual_fsize
- alloc_stack
;
1645 int restore_func_len
= 4;
1646 int restore_normal_len
;
1649 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1651 /* see if we would have used ep to restore the registers */
1652 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1653 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1655 restore_normal_len
= 4 * num_restore
;
1657 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1659 /* Don't bother checking if we don't actually save any space. */
1660 if (restore_func_len
< restore_normal_len
)
1662 restore_all
= gen_rtx (PARALLEL
, VOIDmode
,
1663 rtvec_alloc (num_restore
+ 2));
1664 XVECEXP (restore_all
, 0, 0) = gen_rtx (RETURN
, VOIDmode
);
1665 XVECEXP (restore_all
, 0, 1)
1666 = gen_rtx (SET
, VOIDmode
, stack_pointer_rtx
,
1667 gen_rtx (PLUS
, Pmode
,
1669 GEN_INT (alloc_stack
)));
1671 offset
= alloc_stack
- 4;
1672 for (i
= 0; i
< num_restore
; i
++)
1674 XVECEXP (restore_all
, 0, i
+2)
1675 = gen_rtx (SET
, VOIDmode
,
1677 gen_rtx (MEM
, Pmode
,
1678 plus_constant (stack_pointer_rtx
, offset
)));
1682 code
= recog (restore_all
, NULL_RTX
, NULL_PTR
);
1687 actual_fsize
-= alloc_stack
;
1690 if (CONST_OK_FOR_K (actual_fsize
))
1691 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1693 GEN_INT (actual_fsize
)));
1696 rtx reg
= gen_rtx (REG
, Pmode
, 12);
1697 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1698 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1704 insn
= emit_jump_insn (restore_all
);
1705 INSN_CODE (insn
) = code
;
1708 fprintf (stderr
, "Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1709 restore_normal_len
- restore_func_len
,
1710 restore_normal_len
, restore_func_len
,
1711 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1714 restore_all
= NULL_RTX
;
1718 /* If no epilog save function is available, restore the registers the
1719 old fashioned way (one by one). */
1722 /* If the stack is large, we need to cut it down in 2 pieces. */
1723 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1724 init_stack_free
= 4 * num_restore
;
1726 init_stack_free
= actual_fsize
;
1728 /* Deallocate the rest of the stack if it is > 32K or if extra stack
1729 was allocated for an interrupt handler that makes a call. */
1730 if (actual_fsize
> init_stack_free
|| (interrupt_handler
&& actual_fsize
))
1732 int diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
1733 if (CONST_OK_FOR_K (diff
))
1734 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1739 rtx reg
= gen_rtx (REG
, Pmode
, 12);
1740 emit_move_insn (reg
, GEN_INT (diff
));
1741 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1747 /* Special case interrupt functions that save all registers
1749 if (interrupt_handler
&& ((1L << 31) & reg_saved
) != 0)
1750 emit_insn (gen_restore_all_interrupt ());
1753 /* Restore registers from the beginning of the stack frame */
1754 offset
= init_stack_free
- 4;
1756 /* Restore the return pointer first. */
1757 if (num_restore
> 0 && REGNO (restore_regs
[num_restore
-1]) == 31)
1759 emit_move_insn (restore_regs
[--num_restore
],
1760 gen_rtx (MEM
, SImode
,
1761 plus_constant (stack_pointer_rtx
,
1766 for (i
= 0; i
< num_restore
; i
++)
1768 emit_move_insn (restore_regs
[i
],
1769 gen_rtx (MEM
, SImode
,
1770 plus_constant (stack_pointer_rtx
,
1776 /* Cut back the remainder of the stack. */
1777 if (init_stack_free
)
1778 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1780 GEN_INT (init_stack_free
)));
1783 /* And return or use reti for interrupt handlers. */
1784 if (interrupt_handler
)
1785 emit_jump_insn (gen_restore_interrupt ());
1786 else if (actual_fsize
)
1787 emit_jump_insn (gen_return_internal ());
1789 emit_jump_insn (gen_return ());
1792 current_function_anonymous_args
= 0;
1793 v850_interrupt_cache_p
= FALSE
;
1794 v850_interrupt_p
= FALSE
;
1798 /* Update the condition code from the insn. */
1801 notice_update_cc (body
, insn
)
1805 switch (get_attr_cc (insn
))
1808 /* Insn does not affect CC at all. */
1812 /* Insn does not change CC, but the 0'th operand has been changed. */
1813 if (cc_status
.value1
!= 0
1814 && reg_overlap_mentioned_p (recog_operand
[0], cc_status
.value1
))
1815 cc_status
.value1
= 0;
1819 /* Insn sets the Z,N flags of CC to recog_operand[0].
1820 V,C is in an unusable state. */
1822 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
1823 cc_status
.value1
= recog_operand
[0];
1827 /* Insn sets the Z,N,V flags of CC to recog_operand[0].
1828 C is in an unusable state. */
1830 cc_status
.flags
|= CC_NO_CARRY
;
1831 cc_status
.value1
= recog_operand
[0];
1835 /* The insn is a compare instruction. */
1837 cc_status
.value1
= SET_SRC (body
);
1841 /* Insn doesn't leave CC in a usable state. */
1848 /* Return nonzero if ATTR is a valid attribute for DECL.
1849 ATTRIBUTES are any existing attributes and ARGS are the arguments
1852 Supported attributes:
1854 interrupt_handler or interrupt: output a prologue and epilogue suitable
1855 for an interrupt handler. */
1858 v850_valid_machine_decl_attribute (decl
, attributes
, attr
, args
)
1864 if (args
!= NULL_TREE
)
1867 if (is_attribute_p ("interrupt_handler", attr
)
1868 || is_attribute_p ("interrupt", attr
))
1869 return TREE_CODE (decl
) == FUNCTION_DECL
;
1875 /* Return nonzero if FUNC is an interrupt function as specified
1876 by the "interrupt" attribute. */
1879 v850_interrupt_function_p (func
)
1885 if (v850_interrupt_cache_p
)
1886 return v850_interrupt_p
;
1888 if (TREE_CODE (func
) != FUNCTION_DECL
)
1891 a
= lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES (func
));
1897 a
= lookup_attribute ("interrupt", DECL_MACHINE_ATTRIBUTES (func
));
1898 ret
= a
!= NULL_TREE
;
1901 /* Its not safe to trust global variables until after function inlining has
1903 if (reload_completed
| reload_in_progress
)
1904 v850_interrupt_p
= ret
;
1910 extern struct obstack
*saveable_obstack
;
1912 v850_encode_data_area (decl
)
1915 char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1916 int len
= strlen (str
);
1919 /* In the Cygnus sources we actually do something; this is just
1920 here to make merges easier. */
1924 /* Return true if the given RTX is a register which can be restored
1925 by a function epilogue. */
1927 register_is_ok_for_epilogue (op
, mode
)
1929 enum machine_mode mode
;
1931 /* The save/restore routines can only cope with registers 2, and 20 - 31 */
1932 return (GET_CODE (op
) == REG
)
1933 && (((REGNO (op
) >= 20) && REGNO (op
) <= 31)
1934 || REGNO (op
) == 2);
1937 /* Return non-zero if the given RTX is suitable for collapsing into
1938 jump to a function epilogue. */
1940 pattern_is_ok_for_epilogue (op
, mode
)
1942 enum machine_mode mode
;
1944 int count
= XVECLEN (op
, 0);
1947 /* If there are no registers to restore then the function epilogue
1952 /* The pattern matching has already established that we are performing a
1953 function epilogue and that we are popping at least one register. We must
1954 now check the remaining entries in the vector to make sure that they are
1955 also register pops. There is no good reason why there should ever be
1956 anything else in this vector, but being paranoid always helps...
1958 The test below performs the C equivalent of this machine description
1961 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
1962 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
1965 for (i
= 3; i
< count
; i
++)
1967 rtx vector_element
= XVECEXP (op
, 0, i
);
1972 if (GET_CODE (vector_element
) != SET
)
1975 dest
= SET_DEST (vector_element
);
1976 src
= SET_SRC (vector_element
);
1978 if (GET_CODE (dest
) != REG
1979 || GET_MODE (dest
) != SImode
1980 || ! register_is_ok_for_epilogue (dest
, SImode
)
1981 || GET_CODE (src
) != MEM
1982 || GET_MODE (src
) != SImode
)
1985 plus
= XEXP (src
, 0);
1987 if (GET_CODE (plus
) != PLUS
1988 || GET_CODE (XEXP (plus
, 0)) != REG
1989 || GET_MODE (XEXP (plus
, 0)) != SImode
1990 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
1991 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
1998 /* Construct a JR instruction to a routine that will perform the equivalent of
1999 the RTL passed in as an argument. This RTL is a function epilogue that
2000 pops registers off the stack and possibly releases some extra stack space
2001 as well. The code has already verified that the RTL matches these
2004 construct_restore_jr (op
)
2007 int count
= XVECLEN (op
, 0);
2009 unsigned long int mask
;
2010 unsigned long int first
;
2011 unsigned long int last
;
2013 static char buff
[100]; /* XXX */
2017 error ("Bogus JR construction: %d\n", count
);
2021 /* Work out how many bytes to pop off the stack before retrieving
2023 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2025 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2027 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2030 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2032 /* Each pop will remove 4 bytes from the stack... */
2033 stack_bytes
-= (count
- 2) * 4;
2035 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2036 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2038 error ("Bad amount of stack space removal: %d", stack_bytes
);
2042 /* Now compute the bit mask of registers to push. */
2044 for (i
= 2; i
< count
; i
++)
2046 rtx vector_element
= XVECEXP (op
, 0, i
);
2048 if (GET_CODE (vector_element
) != SET
)
2050 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2052 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
2055 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2058 /* Scan for the first register to pop. */
2059 for (first
= 0; first
< 32; first
++)
2061 if (mask
& (1 << first
))
2068 /* Discover the last register to pop. */
2069 if (mask
& (1 << 31))
2071 if (stack_bytes
!= 16)
2078 if (stack_bytes
!= 0)
2080 if ((mask
& (1 << 29)) == 0)
2086 /* Note, it is possible to have gaps in the register mask.
2087 We ignore this here, and generate a JR anyway. We will
2088 be popping more registers thatn is strictly necessary, but
2089 it does save code space. */
2092 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2094 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2100 /* Return non-zero if the given RTX is suitable for collapsing into
2101 a jump to a function prologue. */
2103 pattern_is_ok_for_prologue (op
, mode
)
2105 enum machine_mode mode
;
2107 int count
= XVECLEN (op
, 0);
2111 /* If there are no registers to save then the function prologue
2116 /* The pattern matching has already established that we are adjusting the
2117 stack and pushing at least one register. We must now check that the
2118 remaining entries in the vector to make sure that they are also register
2119 pushes, except for the last entry which should be a CLOBBER of r10.
2121 The test below performs the C equivalent of this machine description
2124 (set (mem:SI (plus:SI (reg:SI 3)
2125 (match_operand:SI 2 "immediate_operand" "i")))
2126 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2130 for (i
= 2; i
< count
- 1; i
++)
2136 vector_element
= XVECEXP (op
, 0, i
);
2138 if (GET_CODE (vector_element
) != SET
)
2141 dest
= SET_DEST (vector_element
);
2142 src
= SET_SRC (vector_element
);
2144 if (GET_CODE (dest
) != MEM
2145 || GET_MODE (dest
) != SImode
2146 || GET_CODE (src
) != REG
2147 || GET_MODE (src
) != SImode
2148 || ! register_is_ok_for_epilogue (src
, SImode
))
2151 plus
= XEXP (dest
, 0);
2153 if ( GET_CODE (plus
) != PLUS
2154 || GET_CODE (XEXP (plus
, 0)) != REG
2155 || GET_MODE (XEXP (plus
, 0)) != SImode
2156 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2157 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2160 /* If the register is being pushed somewhere other than the stack
2161 space just acquired by the first operand then abandon this quest.
2162 Note: the test is <= because both values are negative. */
2163 if (INTVAL (XEXP (plus
, 1))
2164 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
2170 /* Make sure that the last entry in the vector is a clobber. */
2171 vector_element
= XVECEXP (op
, 0, i
);
2173 if (GET_CODE (vector_element
) != CLOBBER
2174 || GET_CODE (XEXP (vector_element
, 0)) != REG
2175 || REGNO (XEXP (vector_element
, 0)) != 10)
2181 /* Construct a JARL instruction to a routine that will perform the equivalent
2182 of the RTL passed as a parameter. This RTL is a function prologue that
2183 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2184 some stack space as well. The code has already verified that the RTL
2185 matches these requirements. */
2187 construct_save_jarl (op
)
2190 int count
= XVECLEN (op
, 0);
2192 unsigned long int mask
;
2193 unsigned long int first
;
2194 unsigned long int last
;
2196 static char buff
[100]; /* XXX */
2200 error ("Bogus JARL construction: %d\n", count
);
2205 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2207 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2209 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) != REG
)
2211 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2214 /* Work out how many bytes to push onto the stack after storing the
2216 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2218 /* Each push will put 4 bytes from the stack... */
2219 stack_bytes
+= (count
- 2) * 4;
2221 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2222 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2224 error ("Bad amount of stack space removal: %d", stack_bytes
);
2228 /* Now compute the bit mask of registers to push. */
2230 for (i
= 1; i
< count
- 1; i
++)
2232 rtx vector_element
= XVECEXP (op
, 0, i
);
2234 if (GET_CODE (vector_element
) != SET
)
2236 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2238 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2241 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2244 /* Scan for the first register to push. */
2245 for (first
= 0; first
< 32; first
++)
2247 if (mask
& (1 << first
))
2254 /* Discover the last register to push. */
2255 if (mask
& (1 << 31))
2257 if (stack_bytes
!= -16)
2264 if (stack_bytes
!= 0)
2266 if ((mask
& (1 << 29)) == 0)
2272 /* Note, it is possible to have gaps in the register mask.
2273 We ignore this here, and generate a JARL anyway. We will
2274 be pushing more registers thatn is strictly necessary, but
2275 it does save code space. */
2278 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2280 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],