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) == CONST_INT
959 && (CONST_OK_FOR_J (INTVAL (op))
960 || CONST_OK_FOR_K (INTVAL (op))
961 || CONST_OK_FOR_L (INTVAL (op)))))
962 return special_symbolref_operand (op, mode);
964 return general_operand (op, mode);
968 power_of_two_operand (op, mode)
970 enum machine_mode mode;
972 if (GET_CODE (op) != CONST_INT)
975 if (exact_log2 (INTVAL (op)) == -1)
981 not_power_of_two_operand (op, mode)
983 enum machine_mode mode;
989 else if (mode == HImode)
991 else if (mode == SImode)
996 if (GET_CODE (op) != CONST_INT)
999 if (exact_log2 (~INTVAL (op) & mask) == -1)
1005 /* Substitute memory references involving a pointer, to use the ep pointer,
1006 taking care to save and preserve the ep. */
1009 substitute_ep_register (first_insn, last_insn, uses, regno, p_r1, p_ep)
1017 rtx reg = gen_rtx (REG, Pmode, regno);
1023 regs_ever_live[1] = 1;
1024 *p_r1 = gen_rtx (REG, Pmode, 1);
1025 *p_ep = gen_rtx (REG, Pmode, 30);
1029 fprintf (stderr, "Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1030 2 * (uses - 3), uses, reg_names[regno],
1031 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1032 INSN_UID (first_insn), INSN_UID (last_insn));
1034 if (GET_CODE (first_insn) == NOTE)
1035 first_insn = next_nonnote_insn (first_insn);
1037 last_insn = next_nonnote_insn (last_insn);
1038 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1040 if (GET_CODE (insn) == INSN)
1042 rtx pattern = single_set (insn);
1044 /* Replace the memory references. */
1048 /* Memory operands are signed by default. */
1049 int unsignedp = FALSE;
1051 if (GET_CODE (SET_DEST (pattern)) == MEM
1052 && GET_CODE (SET_SRC (pattern)) == MEM)
1055 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1056 p_mem = &SET_DEST (pattern);
1058 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1059 p_mem = &SET_SRC (pattern);
1066 rtx addr = XEXP (*p_mem, 0);
1068 if (GET_CODE (addr) == REG && REGNO (addr) == regno)
1069 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1071 else if (GET_CODE (addr) == PLUS
1072 && GET_CODE (XEXP (addr, 0)) == REG
1073 && REGNO (XEXP (addr, 0)) == regno
1074 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1075 && (((unsigned)INTVAL (XEXP (addr, 1)))
1076 < ep_memory_offset (GET_MODE (*p_mem),
1078 *p_mem = change_address (*p_mem, VOIDmode,
1079 gen_rtx (PLUS, Pmode,
1080 *p_ep, XEXP (addr, 1)));
1086 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1087 insn = prev_nonnote_insn (first_insn);
1088 if (insn && GET_CODE (insn) == INSN
1089 && GET_CODE (PATTERN (insn)) == SET
1090 && SET_DEST (PATTERN (insn)) == *p_ep
1091 && SET_SRC (PATTERN (insn)) == *p_r1)
1094 emit_insn_before (gen_rtx (SET, Pmode, *p_r1, *p_ep), first_insn);
1096 emit_insn_before (gen_rtx (SET, Pmode, *p_ep, reg), first_insn);
1097 emit_insn_before (gen_rtx (SET, Pmode, *p_ep, *p_r1), last_insn);
1101 /* In rare cases, correct code generation requires extra machine
1102 dependent processing between the second jump optimization pass and
1103 delayed branch scheduling. On those machines, define this macro
1104 as a C statement to act on the code starting at INSN.
1106 On the 850, we use it to implement the -mep mode to copy heavily used
1107 pointers to ep to use the implicit addressing */
1109 void v850_reorg (start_insn)
1116 } regs[FIRST_PSEUDO_REGISTER];
1125 /* If not ep mode, just return now */
1129 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1132 regs[i].first_insn = NULL_RTX;
1133 regs[i].last_insn = NULL_RTX;
1136 for (insn = start_insn; insn != NULL_RTX; insn = NEXT_INSN (insn))
1138 switch (GET_CODE (insn))
1140 /* End of basic block */
1147 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1149 if (max_uses < regs[i].uses)
1151 max_uses = regs[i].uses;
1157 substitute_ep_register (regs[max_regno].first_insn,
1158 regs[max_regno].last_insn,
1159 max_uses, max_regno, &r1, &ep);
1163 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1166 regs[i].first_insn = NULL_RTX;
1167 regs[i].last_insn = NULL_RTX;
1175 pattern = single_set (insn);
1177 /* See if there are any memory references we can shorten */
1180 rtx src = SET_SRC (pattern);
1181 rtx dest = SET_DEST (pattern);
1183 /* Memory operands are signed by default. */
1184 int unsignedp = FALSE;
1186 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1189 else if (GET_CODE (dest) == MEM)
1192 else if (GET_CODE (src) == MEM)
1198 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1201 else if (!use_ep && mem
1202 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1204 rtx addr = XEXP (mem, 0);
1208 if (GET_CODE (addr) == REG)
1211 regno = REGNO (addr);
1214 else if (GET_CODE (addr) == PLUS
1215 && GET_CODE (XEXP (addr, 0)) == REG
1216 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1217 && (((unsigned)INTVAL (XEXP (addr, 1)))
1218 < ep_memory_offset (GET_MODE (mem), unsignedp)))
1221 regno = REGNO (XEXP (addr, 0));
1230 regs[regno].last_insn = insn;
1231 if (!regs[regno].first_insn)
1232 regs[regno].first_insn = insn;
1236 /* Loading up a register in the basic block zaps any savings
1238 if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG)
1240 enum machine_mode mode = GET_MODE (dest);
1245 while (GET_CODE (dest) == SUBREG)
1247 word = SUBREG_WORD (dest);
1248 dest = SUBREG_REG (dest);
1251 regno = REGNO (dest) + word;
1252 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1256 /* See if we can use the pointer before this
1261 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1263 if (max_uses < regs[i].uses)
1265 max_uses = regs[i].uses;
1271 && max_regno >= regno
1272 && max_regno < endregno)
1274 substitute_ep_register (regs[max_regno].first_insn,
1275 regs[max_regno].last_insn,
1276 max_uses, max_regno, &r1, &ep);
1278 /* Since we made a substitution, zap all remembered
1280 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1283 regs[i].first_insn = NULL_RTX;
1284 regs[i].last_insn = NULL_RTX;
1289 for (i = regno; i < endregno; i++)
1292 regs[i].first_insn = NULL_RTX;
1293 regs[i].last_insn = NULL_RTX;
1302 /* # of registers saved by the interrupt handler. */
1303 #define INTERRUPT_FIXED_NUM 4
1305 /* # of bytes for registers saved by the interrupt handler. */
1306 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1308 /* # of registers saved in register parameter area. */
1309 #define INTERRUPT_REGPARM_NUM 4
1310 /* # of words saved for other registers. */
1311 #define INTERRUPT_ALL_SAVE_NUM \
1312 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1314 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1317 compute_register_save_size (p_reg_saved)
1322 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1323 int call_p = regs_ever_live[31];
1326 /* Count the return pointer if we need to save it. */
1327 if (profile_flag && !call_p)
1328 regs_ever_live[31] = call_p = 1;
1330 /* Count space for the register saves. */
1331 if (interrupt_handler)
1333 for (i = 0; i <= 31; i++)
1337 if (regs_ever_live[i] || call_p)
1340 reg_saved |= 1L << i;
1344 /* We don't save/restore r0 or the stack pointer */
1346 case STACK_POINTER_REGNUM:
1349 /* For registers with fixed use, we save them, set them to the
1350 appropriate value, and then restore them.
1351 These registers are handled specially, so don't list them
1352 on the list of registers to save in the prologue. */
1353 case 1: /* temp used to hold ep */
1355 case 10: /* temp used to call interrupt save/restore */
1356 case EP_REGNUM: /* ep */
1363 for (i = 0; i <= 31; i++)
1364 if (regs_ever_live[i] && ((! call_used_regs[i]) || i == 31))
1367 reg_saved |= 1L << i;
1371 *p_reg_saved = reg_saved;
1377 compute_frame_size (size, p_reg_saved)
1381 extern int current_function_outgoing_args_size;
1384 + compute_register_save_size (p_reg_saved)
1385 + current_function_outgoing_args_size);
1394 unsigned int size = get_frame_size ();
1395 unsigned int actual_fsize;
1396 unsigned int init_stack_alloc = 0;
1402 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1405 actual_fsize = compute_frame_size (size, ®_saved);
1407 /* Save/setup global registers for interrupt functions right now */
1408 if (interrupt_handler)
1410 emit_insn (gen_save_interrupt ());
1411 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1412 if (((1L << 31) & reg_saved) != 0)
1413 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1416 /* Save arg registers to the stack if necessary. */
1417 else if (current_function_anonymous_args)
1419 if (TARGET_PROLOG_FUNCTION)
1420 emit_insn (gen_save_r6_r9 ());
1424 for (i = 6; i < 10; i++)
1426 emit_move_insn (gen_rtx (MEM, SImode,
1427 plus_constant (stack_pointer_rtx,
1429 gen_rtx (REG, SImode, i));
1435 /* Identify all of the saved registers */
1438 for (i = 1; i < 31; i++)
1440 if (((1L << i) & reg_saved) != 0)
1441 save_regs[num_save++] = gen_rtx (REG, Pmode, i);
1444 /* If the return pointer is saved, the helper functions also allocate
1445 16 bytes of stack for arguments to be saved in. */
1446 if (((1L << 31) & reg_saved) != 0)
1448 save_regs[num_save++] = gen_rtx (REG, Pmode, 31);
1452 /* See if we have an insn that allocates stack space and saves the particular
1453 registers we want to. */
1454 save_all = NULL_RTX;
1455 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1457 int alloc_stack = (4 * num_save) + default_stack;
1458 int unalloc_stack = actual_fsize - alloc_stack;
1459 int save_func_len = 4;
1460 int save_normal_len;
1463 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1465 /* see if we would have used ep to save the stack */
1466 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1467 save_normal_len = (3 * 2) + (2 * num_save);
1469 save_normal_len = 4 * num_save;
1471 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1473 /* Don't bother checking if we don't actually save any space.
1474 This happens for instance if one register is saved and additional
1475 stack space is allocated. */
1476 if (save_func_len < save_normal_len)
1478 save_all = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num_save + (TARGET_V850 ? 2 : 1)));
1479 XVECEXP (save_all, 0, 0) = gen_rtx (SET, VOIDmode,
1481 gen_rtx (PLUS, Pmode,
1483 GEN_INT (-alloc_stack)));
1487 XVECEXP (save_all, 0, num_save+1)
1488 = gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, Pmode, 10));
1491 offset = - default_stack;
1492 for (i = 0; i < num_save; i++)
1494 XVECEXP (save_all, 0, i+1)
1495 = gen_rtx (SET, VOIDmode,
1496 gen_rtx (MEM, Pmode,
1497 plus_constant (stack_pointer_rtx, offset)),
1502 code = recog (save_all, NULL_RTX, NULL_PTR);
1505 rtx insn = emit_insn (save_all);
1506 INSN_CODE (insn) = code;
1507 actual_fsize -= alloc_stack;
1510 fprintf (stderr, "Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1511 save_normal_len - save_func_len,
1512 save_normal_len, save_func_len,
1513 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1516 save_all = NULL_RTX;
1520 /* If no prolog save function is available, store the registers the old fashioned
1521 way (one by one). */
1524 /* Special case interrupt functions that save all registers for a call. */
1525 if (interrupt_handler && ((1L << 31) & reg_saved) != 0)
1526 emit_insn (gen_save_all_interrupt ());
1530 /* If the stack is too big, allocate it in chunks so we can do the
1531 register saves. We use the register save size so we use the ep
1533 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1534 init_stack_alloc = compute_register_save_size (NULL);
1536 init_stack_alloc = actual_fsize;
1538 /* Save registers at the beginning of the stack frame */
1539 offset = init_stack_alloc - 4;
1541 if (init_stack_alloc)
1542 emit_insn (gen_addsi3 (stack_pointer_rtx,
1544 GEN_INT (-init_stack_alloc)));
1546 /* Save the return pointer first. */
1547 if (num_save > 0 && REGNO (save_regs[num_save-1]) == 31)
1549 emit_move_insn (gen_rtx (MEM, SImode,
1550 plus_constant (stack_pointer_rtx,
1552 save_regs[--num_save]);
1556 for (i = 0; i < num_save; i++)
1558 emit_move_insn (gen_rtx (MEM, SImode,
1559 plus_constant (stack_pointer_rtx,
1567 /* Allocate the rest of the stack that was not allocated above (either it is
1568 > 32K or we just called a function to save the registers and needed more
1570 if (actual_fsize > init_stack_alloc)
1572 int diff = actual_fsize - init_stack_alloc;
1573 if (CONST_OK_FOR_K (diff))
1574 emit_insn (gen_addsi3 (stack_pointer_rtx,
1579 rtx reg = gen_rtx (REG, Pmode, 12);
1580 emit_move_insn (reg, GEN_INT (-diff));
1581 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1585 /* If we need a frame pointer, set it up now. */
1586 if (frame_pointer_needed)
1587 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1596 unsigned int size = get_frame_size ();
1598 unsigned int actual_fsize = compute_frame_size (size, ®_saved);
1599 unsigned int init_stack_free = 0;
1600 rtx restore_regs[32];
1605 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1607 /* Eliminate the initial stack stored by interrupt functions. */
1608 if (interrupt_handler)
1610 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1611 if (((1L << 31) & reg_saved) != 0)
1612 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1615 /* Cut off any dynamic stack created. */
1616 if (frame_pointer_needed)
1617 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1619 /* Identify all of the saved registers */
1622 for (i = 1; i < 31; i++)
1624 if (((1L << i) & reg_saved) != 0)
1625 restore_regs[num_restore++] = gen_rtx (REG, Pmode, i);
1628 /* If the return pointer is saved, the helper functions also allocate
1629 16 bytes of stack for arguments to be saved in. */
1630 if (((1L << 31) & reg_saved) != 0)
1632 restore_regs[num_restore++] = gen_rtx (REG, Pmode, 31);
1636 /* See if we have an insn that restores the particular registers we
1638 restore_all = NULL_RTX;
1639 if (TARGET_PROLOG_FUNCTION && num_restore > 0 && actual_fsize >= default_stack
1640 && !interrupt_handler)
1642 int alloc_stack = (4 * num_restore) + default_stack;
1643 int unalloc_stack = actual_fsize - alloc_stack;
1644 int restore_func_len = 4;
1645 int restore_normal_len;
1648 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1650 /* see if we would have used ep to restore the registers */
1651 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1652 restore_normal_len = (3 * 2) + (2 * num_restore);
1654 restore_normal_len = 4 * num_restore;
1656 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1658 /* Don't bother checking if we don't actually save any space. */
1659 if (restore_func_len < restore_normal_len)
1661 restore_all = gen_rtx (PARALLEL, VOIDmode,
1662 rtvec_alloc (num_restore + 2));
1663 XVECEXP (restore_all, 0, 0) = gen_rtx (RETURN, VOIDmode);
1664 XVECEXP (restore_all, 0, 1)
1665 = gen_rtx (SET, VOIDmode, stack_pointer_rtx,
1666 gen_rtx (PLUS, Pmode,
1668 GEN_INT (alloc_stack)));
1670 offset = alloc_stack - 4;
1671 for (i = 0; i < num_restore; i++)
1673 XVECEXP (restore_all, 0, i+2)
1674 = gen_rtx (SET, VOIDmode,
1676 gen_rtx (MEM, Pmode,
1677 plus_constant (stack_pointer_rtx, offset)));
1681 code = recog (restore_all, NULL_RTX, NULL_PTR);
1686 actual_fsize -= alloc_stack;
1689 if (CONST_OK_FOR_K (actual_fsize))
1690 emit_insn (gen_addsi3 (stack_pointer_rtx,
1692 GEN_INT (actual_fsize)));
1695 rtx reg = gen_rtx (REG, Pmode, 12);
1696 emit_move_insn (reg, GEN_INT (actual_fsize));
1697 emit_insn (gen_addsi3 (stack_pointer_rtx,
1703 insn = emit_jump_insn (restore_all);
1704 INSN_CODE (insn) = code;
1707 fprintf (stderr, "Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1708 restore_normal_len - restore_func_len,
1709 restore_normal_len, restore_func_len,
1710 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1713 restore_all = NULL_RTX;
1717 /* If no epilog save function is available, restore the registers the
1718 old fashioned way (one by one). */
1721 /* If the stack is large, we need to cut it down in 2 pieces. */
1722 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1723 init_stack_free = 4 * num_restore;
1725 init_stack_free = actual_fsize;
1727 /* Deallocate the rest of the stack if it is > 32K or if extra stack
1728 was allocated for an interrupt handler that makes a call. */
1729 if (actual_fsize > init_stack_free || (interrupt_handler && actual_fsize))
1731 int diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1732 if (CONST_OK_FOR_K (diff))
1733 emit_insn (gen_addsi3 (stack_pointer_rtx,
1738 rtx reg = gen_rtx (REG, Pmode, 12);
1739 emit_move_insn (reg, GEN_INT (diff));
1740 emit_insn (gen_addsi3 (stack_pointer_rtx,
1746 /* Special case interrupt functions that save all registers
1748 if (interrupt_handler && ((1L << 31) & reg_saved) != 0)
1749 emit_insn (gen_restore_all_interrupt ());
1752 /* Restore registers from the beginning of the stack frame */
1753 offset = init_stack_free - 4;
1755 /* Restore the return pointer first. */
1756 if (num_restore > 0 && REGNO (restore_regs[num_restore-1]) == 31)
1758 emit_move_insn (restore_regs[--num_restore],
1759 gen_rtx (MEM, SImode,
1760 plus_constant (stack_pointer_rtx,
1765 for (i = 0; i < num_restore; i++)
1767 emit_move_insn (restore_regs[i],
1768 gen_rtx (MEM, SImode,
1769 plus_constant (stack_pointer_rtx,
1775 /* Cut back the remainder of the stack. */
1776 if (init_stack_free)
1777 emit_insn (gen_addsi3 (stack_pointer_rtx,
1779 GEN_INT (init_stack_free)));
1782 /* And return or use reti for interrupt handlers. */
1783 if (interrupt_handler)
1784 emit_jump_insn (gen_restore_interrupt ());
1785 else if (actual_fsize)
1786 emit_jump_insn (gen_return_internal ());
1788 emit_jump_insn (gen_return ());
1791 current_function_anonymous_args = 0;
1792 v850_interrupt_cache_p = FALSE;
1793 v850_interrupt_p = FALSE;
1797 /* Update the condition code from the insn. */
1800 notice_update_cc (body, insn)
1804 switch (get_attr_cc (insn))
1807 /* Insn does not affect CC at all. */
1811 /* Insn does not change CC, but the 0'th operand has been changed. */
1812 if (cc_status.value1 != 0
1813 && reg_overlap_mentioned_p (recog_operand[0], cc_status.value1))
1814 cc_status.value1 = 0;
1818 /* Insn sets the Z,N flags of CC to recog_operand[0].
1819 V,C is in an unusable state. */
1821 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1822 cc_status.value1 = recog_operand[0];
1826 /* Insn sets the Z,N,V flags of CC to recog_operand[0].
1827 C is in an unusable state. */
1829 cc_status.flags |= CC_NO_CARRY;
1830 cc_status.value1 = recog_operand[0];
1834 /* The insn is a compare instruction. */
1836 cc_status.value1 = SET_SRC (body);
1840 /* Insn doesn't leave CC in a usable state. */
1847 /* Return nonzero if ATTR is a valid attribute for DECL.
1848 ATTRIBUTES are any existing attributes and ARGS are the arguments
1851 Supported attributes:
1853 interrupt_handler or interrupt: output a prologue and epilogue suitable
1854 for an interrupt handler. */
1857 v850_valid_machine_decl_attribute (decl, attributes, attr, args)
1863 if (args != NULL_TREE)
1866 if (is_attribute_p ("interrupt_handler", attr)
1867 || is_attribute_p ("interrupt", attr))
1868 return TREE_CODE (decl) == FUNCTION_DECL;
1874 /* Return nonzero if FUNC is an interrupt function as specified
1875 by the "interrupt" attribute. */
1878 v850_interrupt_function_p (func)
1884 if (v850_interrupt_cache_p)
1885 return v850_interrupt_p;
1887 if (TREE_CODE (func) != FUNCTION_DECL)
1890 a = lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES (func));
1896 a = lookup_attribute ("interrupt", DECL_MACHINE_ATTRIBUTES (func));
1897 ret = a != NULL_TREE;
1900 /* Its not safe to trust global variables until after function inlining has
1902 if (reload_completed | reload_in_progress)
1903 v850_interrupt_p = ret;
1909 extern struct obstack *saveable_obstack;
1911 v850_encode_data_area (decl)
1914 char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1915 int len = strlen (str);
1918 /* In the Cygnus sources we actually do something; this is just
1919 here to make merges easier. */
1923 /* Return true if the given RTX is a register which can be restored
1924 by a function epilogue. */
1926 register_is_ok_for_epilogue (op, mode)
1928 enum machine_mode mode;
1930 /* The save/restore routines can only cope with registers 2, and 20 - 31 */
1931 return (GET_CODE (op) == REG)
1932 && (((REGNO (op) >= 20) && REGNO (op) <= 31)
1933 || REGNO (op) == 2);
1936 /* Return non-zero if the given RTX is suitable for collapsing into
1937 jump to a function epilogue. */
1939 pattern_is_ok_for_epilogue (op, mode)
1941 enum machine_mode mode;
1943 int count = XVECLEN (op, 0);
1946 /* If there are no registers to restore then the function epilogue
1951 /* The pattern matching has already established that we are performing a
1952 function epilogue and that we are popping at least one register. We must
1953 now check the remaining entries in the vector to make sure that they are
1954 also register pops. There is no good reason why there should ever be
1955 anything else in this vector, but being paranoid always helps...
1957 The test below performs the C equivalent of this machine description
1960 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
1961 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
1964 for (i = 3; i < count; i++)
1966 rtx vector_element = XVECEXP (op, 0, i);
1971 if (GET_CODE (vector_element) != SET)
1974 dest = SET_DEST (vector_element);
1975 src = SET_SRC (vector_element);
1977 if (GET_CODE (dest) != REG
1978 || GET_MODE (dest) != SImode
1979 || ! register_is_ok_for_epilogue (dest, SImode)
1980 || GET_CODE (src) != MEM
1981 || GET_MODE (src) != SImode)
1984 plus = XEXP (src, 0);
1986 if (GET_CODE (plus) != PLUS
1987 || GET_CODE (XEXP (plus, 0)) != REG
1988 || GET_MODE (XEXP (plus, 0)) != SImode
1989 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
1990 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
1997 /* Construct a JR instruction to a routine that will perform the equivalent of
1998 the RTL passed in as an argument. This RTL is a function epilogue that
1999 pops registers off the stack and possibly releases some extra stack space
2000 as well. The code has already verified that the RTL matches these
2003 construct_restore_jr (op)
2006 int count = XVECLEN (op, 0);
2008 unsigned long int mask;
2009 unsigned long int first;
2010 unsigned long int last;
2012 static char buff [100]; /* XXX */
2016 error ("Bogus JR construction: %d\n", count);
2020 /* Work out how many bytes to pop off the stack before retrieving
2022 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2024 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2026 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2029 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2031 /* Each pop will remove 4 bytes from the stack... */
2032 stack_bytes -= (count - 2) * 4;
2034 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2035 if (stack_bytes != 0 && stack_bytes != 16)
2037 error ("Bad amount of stack space removal: %d", stack_bytes);
2041 /* Now compute the bit mask of registers to push. */
2043 for (i = 2; i < count; i++)
2045 rtx vector_element = XVECEXP (op, 0, i);
2047 if (GET_CODE (vector_element) != SET)
2049 if (GET_CODE (SET_DEST (vector_element)) != REG)
2051 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2054 mask |= 1 << REGNO (SET_DEST (vector_element));
2057 /* Scan for the first register to pop. */
2058 for (first = 0; first < 32; first++)
2060 if (mask & (1 << first))
2067 /* Discover the last register to pop. */
2068 if (mask & (1 << 31))
2070 if (stack_bytes != 16)
2077 if (stack_bytes != 0)
2079 if ((mask & (1 << 29)) == 0)
2085 /* Note, it is possible to have gaps in the register mask.
2086 We ignore this here, and generate a JR anyway. We will
2087 be popping more registers thatn is strictly necessary, but
2088 it does save code space. */
2091 sprintf (buff, "jr __return_%s", reg_names [first]);
2093 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2099 /* Return non-zero if the given RTX is suitable for collapsing into
2100 a jump to a function prologue. */
2102 pattern_is_ok_for_prologue (op, mode)
2104 enum machine_mode mode;
2106 int count = XVECLEN (op, 0);
2110 /* If there are no registers to save then the function prologue
2115 /* The pattern matching has already established that we are adjusting the
2116 stack and pushing at least one register. We must now check that the
2117 remaining entries in the vector to make sure that they are also register
2118 pushes, except for the last entry which should be a CLOBBER of r10.
2120 The test below performs the C equivalent of this machine description
2123 (set (mem:SI (plus:SI (reg:SI 3)
2124 (match_operand:SI 2 "immediate_operand" "i")))
2125 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2129 for (i = 2; i < count - 1; i++)
2135 vector_element = XVECEXP (op, 0, i);
2137 if (GET_CODE (vector_element) != SET)
2140 dest = SET_DEST (vector_element);
2141 src = SET_SRC (vector_element);
2143 if (GET_CODE (dest) != MEM
2144 || GET_MODE (dest) != SImode
2145 || GET_CODE (src) != REG
2146 || GET_MODE (src) != SImode
2147 || ! register_is_ok_for_epilogue (src, SImode))
2150 plus = XEXP (dest, 0);
2152 if ( GET_CODE (plus) != PLUS
2153 || GET_CODE (XEXP (plus, 0)) != REG
2154 || GET_MODE (XEXP (plus, 0)) != SImode
2155 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2156 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2159 /* If the register is being pushed somewhere other than the stack
2160 space just acquired by the first operand then abandon this quest.
2161 Note: the test is <= because both values are negative. */
2162 if (INTVAL (XEXP (plus, 1))
2163 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2169 /* Make sure that the last entry in the vector is a clobber. */
2170 vector_element = XVECEXP (op, 0, i);
2172 if (GET_CODE (vector_element) != CLOBBER
2173 || GET_CODE (XEXP (vector_element, 0)) != REG
2174 || REGNO (XEXP (vector_element, 0)) != 10)
2180 /* Construct a JARL instruction to a routine that will perform the equivalent
2181 of the RTL passed as a parameter. This RTL is a function prologue that
2182 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2183 some stack space as well. The code has already verified that the RTL
2184 matches these requirements. */
2186 construct_save_jarl (op)
2189 int count = XVECLEN (op, 0);
2191 unsigned long int mask;
2192 unsigned long int first;
2193 unsigned long int last;
2195 static char buff [100]; /* XXX */
2199 error ("Bogus JARL construction: %d\n", count);
2204 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2206 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2208 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2210 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2213 /* Work out how many bytes to push onto the stack after storing the
2215 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2217 /* Each push will put 4 bytes from the stack... */
2218 stack_bytes += (count - 2) * 4;
2220 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2221 if (stack_bytes != 0 && stack_bytes != -16)
2223 error ("Bad amount of stack space removal: %d", stack_bytes);
2227 /* Now compute the bit mask of registers to push. */
2229 for (i = 1; i < count - 1; i++)
2231 rtx vector_element = XVECEXP (op, 0, i);
2233 if (GET_CODE (vector_element) != SET)
2235 if (GET_CODE (SET_SRC (vector_element)) != REG)
2237 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2240 mask |= 1 << REGNO (SET_SRC (vector_element));
2243 /* Scan for the first register to push. */
2244 for (first = 0; first < 32; first++)
2246 if (mask & (1 << first))
2253 /* Discover the last register to push. */
2254 if (mask & (1 << 31))
2256 if (stack_bytes != -16)
2263 if (stack_bytes != 0)
2265 if ((mask & (1 << 29)) == 0)
2271 /* Note, it is possible to have gaps in the register mask.
2272 We ignore this here, and generate a JARL anyway. We will
2273 be pushing more registers thatn is strictly necessary, but
2274 it does save code space. */
2277 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2279 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],