1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
33 #include "insn-attr.h"
42 #include "integrate.h"
45 #include "target-def.h"
48 #define streq(a,b) (strcmp (a, b) == 0)
51 /* Function prototypes for stupid compilers: */
52 static void const_double_split PARAMS ((rtx, HOST_WIDE_INT *, HOST_WIDE_INT *));
53 static int const_costs_int PARAMS ((HOST_WIDE_INT, int));
54 static void substitute_ep_register PARAMS ((rtx, rtx, int, int, rtx *, rtx *));
55 static int ep_memory_offset PARAMS ((enum machine_mode, int));
56 static void v850_set_data_area PARAMS ((tree, v850_data_area));
57 const struct attribute_spec v850_attribute_table[];
58 static tree v850_handle_interrupt_attribute PARAMS ((tree *, tree, tree, int, bool *));
59 static tree v850_handle_data_area_attribute PARAMS ((tree *, tree, tree, int, bool *));
60 static void v850_insert_attributes PARAMS ((tree, tree *));
61 static void v850_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT));
62 static void v850_encode_data_area PARAMS ((tree));
63 static void v850_encode_section_info PARAMS ((tree, int));
65 /* True if the current function has anonymous arguments. */
66 int current_function_anonymous_args;
68 /* Information about the various small memory areas. */
69 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
71 /* name value max physical max */
72 { "tda", (char *)0, 0, 256 },
73 { "sda", (char *)0, 0, 65536 },
74 { "zda", (char *)0, 0, 32768 },
77 /* Names of the various data areas used on the v850. */
78 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
79 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
81 /* Track the current data area set by the data area pragma (which
82 can be nested). Tested by check_default_data_area. */
83 data_area_stack_element * data_area_stack = NULL;
85 /* True if we don't need to check any more if the current
86 function is an interrupt handler. */
87 static int v850_interrupt_cache_p = FALSE;
89 /* Whether current function is an interrupt handler. */
90 static int v850_interrupt_p = FALSE;
92 /* Initialize the GCC target structure. */
93 #undef TARGET_ASM_ALIGNED_HI_OP
94 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
96 #undef TARGET_ATTRIBUTE_TABLE
97 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
99 #undef TARGET_INSERT_ATTRIBUTES
100 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
102 #undef TARGET_ASM_SELECT_SECTION
103 #define TARGET_ASM_SELECT_SECTION v850_select_section
105 #undef TARGET_ENCODE_SECTION_INFO
106 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
108 struct gcc_target targetm = TARGET_INITIALIZER;
110 /* Sometimes certain combinations of command options do not make
111 sense on a particular target machine. You can define a macro
112 `OVERRIDE_OPTIONS' to take account of this. This macro, if
113 defined, is executed once just after all the command options have
116 Don't use this macro to turn on various extra optimizations for
117 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
123 extern int atoi PARAMS ((const char *));
125 /* Parse -m{s,t,z}da=nnn switches */
126 for (i = 0; i < (int)SMALL_MEMORY_max; i++)
128 if (small_memory[i].value)
130 if (!ISDIGIT (*small_memory[i].value))
131 error ("%s=%s is not numeric",
132 small_memory[i].name,
133 small_memory[i].value);
136 small_memory[i].max = atoi (small_memory[i].value);
137 if (small_memory[i].max > small_memory[i].physical_max)
138 error ("%s=%s is too large",
139 small_memory[i].name,
140 small_memory[i].value);
147 /* Output assembly code for the start of the file. */
150 asm_file_start (file)
153 output_file_directive (file, main_input_filename);
157 /* Return an RTX to represent where a value with mode MODE will be returned
158 from a function. If the result is 0, the argument is pushed. */
161 function_arg (cum, mode, type, named)
162 CUMULATIVE_ARGS *cum;
163 enum machine_mode mode;
170 if (TARGET_GHS && !named)
174 size = int_size_in_bytes (type);
176 size = GET_MODE_SIZE (mode);
179 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
183 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
185 if (cum->nbytes > 4 * UNITS_PER_WORD)
188 if (type == NULL_TREE
189 && cum->nbytes + size > 4 * UNITS_PER_WORD)
192 switch (cum->nbytes / UNITS_PER_WORD)
195 result = gen_rtx_REG (mode, 6);
198 result = gen_rtx_REG (mode, 7);
201 result = gen_rtx_REG (mode, 8);
204 result = gen_rtx_REG (mode, 9);
214 /* Return the number of words which must be put into registers
215 for values which are part in registers and part in memory. */
218 function_arg_partial_nregs (cum, mode, type, named)
219 CUMULATIVE_ARGS *cum;
220 enum machine_mode mode;
226 if (TARGET_GHS && !named)
230 size = int_size_in_bytes (type);
232 size = GET_MODE_SIZE (mode);
235 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
239 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
241 if (cum->nbytes > 4 * UNITS_PER_WORD)
244 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
247 if (type == NULL_TREE
248 && cum->nbytes + size > 4 * UNITS_PER_WORD)
251 return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
255 /* Return the high and low words of a CONST_DOUBLE */
258 const_double_split (x, p_high, p_low)
260 HOST_WIDE_INT *p_high;
261 HOST_WIDE_INT *p_low;
263 if (GET_CODE (x) == CONST_DOUBLE)
268 switch (GET_MODE (x))
271 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
272 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
273 *p_high = t[1]; /* since v850 is little endian */
274 *p_low = t[0]; /* high is second word */
278 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
279 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
285 *p_high = CONST_DOUBLE_HIGH (x);
286 *p_low = CONST_DOUBLE_LOW (x);
294 fatal_insn ("const_double_split got a bad insn:", x);
298 /* Return the cost of the rtx R with code CODE. */
301 const_costs_int (value, zero_cost)
305 if (CONST_OK_FOR_I (value))
307 else if (CONST_OK_FOR_J (value))
309 else if (CONST_OK_FOR_K (value))
320 HOST_WIDE_INT high, low;
325 return const_costs_int (INTVAL (r), 0);
328 const_double_split (r, &high, &low);
329 if (GET_MODE (r) == SFmode)
330 return const_costs_int (high, 1);
332 return const_costs_int (high, 1) + const_costs_int (low, 1);
348 /* Print operand X using operand code CODE to assembly language output file
352 print_operand (file, x, code)
357 HOST_WIDE_INT high, low;
362 /* We use 'c' operands with symbols for .vtinherit */
363 if (GET_CODE (x) == SYMBOL_REF)
365 output_addr_const(file, x);
372 switch ((code == 'B' || code == 'C')
373 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
376 if (code == 'c' || code == 'C')
377 fprintf (file, "nz");
379 fprintf (file, "ne");
382 if (code == 'c' || code == 'C')
388 fprintf (file, "ge");
391 fprintf (file, "gt");
394 fprintf (file, "le");
397 fprintf (file, "lt");
400 fprintf (file, "nl");
406 fprintf (file, "nh");
415 case 'F': /* high word of CONST_DOUBLE */
416 if (GET_CODE (x) == CONST_INT)
417 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
418 else if (GET_CODE (x) == CONST_DOUBLE)
420 const_double_split (x, &high, &low);
421 fprintf (file, "%ld", (long) high);
426 case 'G': /* low word of CONST_DOUBLE */
427 if (GET_CODE (x) == CONST_INT)
428 fprintf (file, "%ld", (long) INTVAL (x));
429 else if (GET_CODE (x) == CONST_DOUBLE)
431 const_double_split (x, &high, &low);
432 fprintf (file, "%ld", (long) low);
438 fprintf (file, "%d\n", INTVAL (x) & 0xffff);
441 fprintf (file, "%d", exact_log2 (INTVAL (x)));
444 if (special_symbolref_operand (x, VOIDmode))
448 if (GET_CODE (x) == SYMBOL_REF)
450 else if (GET_CODE (x) == CONST)
451 name = XSTR (XEXP (XEXP (x, 0), 0), 0);
455 if (ZDA_NAME_P (name))
456 fprintf (file, "zdaoff");
457 else if (SDA_NAME_P (name))
458 fprintf (file, "sdaoff");
459 else if (TDA_NAME_P (name))
460 fprintf (file, "tdaoff");
468 if (special_symbolref_operand (x, VOIDmode))
469 output_addr_const (file, x);
474 if (special_symbolref_operand (x, VOIDmode))
478 if (GET_CODE (x) == SYMBOL_REF)
480 else if (GET_CODE (x) == CONST)
481 name = XSTR (XEXP (XEXP (x, 0), 0), 0);
485 if (ZDA_NAME_P (name))
486 fprintf (file, "r0");
487 else if (SDA_NAME_P (name))
488 fprintf (file, "gp");
489 else if (TDA_NAME_P (name))
490 fprintf (file, "ep");
497 case 'R': /* 2nd word of a double. */
498 switch (GET_CODE (x))
501 fprintf (file, reg_names[REGNO (x) + 1]);
504 x = XEXP (adjust_address (x, SImode, 4), 0);
505 print_operand_address (file, x);
506 if (GET_CODE (x) == CONST_INT)
507 fprintf (file, "[r0]");
516 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
517 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
524 /* Like an 'S' operand above, but for unsigned loads only. */
525 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
530 case 'W': /* print the instruction suffix */
531 switch (GET_MODE (x))
536 case QImode: fputs (".b", file); break;
537 case HImode: fputs (".h", file); break;
538 case SImode: fputs (".w", file); break;
539 case SFmode: fputs (".w", file); break;
542 case '.': /* register r0 */
543 fputs (reg_names[0], file);
545 case 'z': /* reg or zero */
547 fputs (reg_names[0], file);
548 else if (GET_CODE (x) == REG)
549 fputs (reg_names[REGNO (x)], file);
554 switch (GET_CODE (x))
557 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
558 output_address (gen_rtx_PLUS (SImode, gen_rtx (REG, SImode, 0),
561 output_address (XEXP (x, 0));
565 fputs (reg_names[REGNO (x)], file);
568 fputs (reg_names[subreg_regno (x)], file);
575 print_operand_address (file, x);
586 /* Output assembly language output for the address ADDR to FILE. */
589 print_operand_address (file, addr)
593 switch (GET_CODE (addr))
596 fprintf (file, "0[");
597 print_operand (file, addr, 0);
601 if (GET_CODE (XEXP (addr, 0)) == REG)
604 fprintf (file, "lo(");
605 print_operand (file, XEXP (addr, 1), 0);
606 fprintf (file, ")[");
607 print_operand (file, XEXP (addr, 0), 0);
612 if (GET_CODE (XEXP (addr, 0)) == REG
613 || GET_CODE (XEXP (addr, 0)) == SUBREG)
616 print_operand (file, XEXP (addr, 1), 0);
618 print_operand (file, XEXP (addr, 0), 0);
623 print_operand (file, XEXP (addr, 0), 0);
625 print_operand (file, XEXP (addr, 1), 0);
629 if (ENCODED_NAME_P (XSTR (addr, 0)))
631 const char *name = XSTR (addr, 0);
632 const char *off_name;
633 const char *reg_name;
635 if (ZDA_NAME_P (name))
640 else if (SDA_NAME_P (name))
645 else if (TDA_NAME_P (name))
653 fprintf (file, "%s(", off_name);
654 output_addr_const (file, addr);
655 fprintf (file, ")[%s]", reg_name);
658 output_addr_const (file, addr);
661 if (special_symbolref_operand (addr, VOIDmode))
663 const char *name = XSTR (XEXP (XEXP (addr, 0), 0), 0);
664 const char *off_name;
665 const char *reg_name;
667 if (ZDA_NAME_P (name))
672 else if (SDA_NAME_P (name))
677 else if (TDA_NAME_P (name))
685 fprintf (file, "%s(", off_name);
686 output_addr_const (file, addr);
687 fprintf (file, ")[%s]", reg_name);
690 output_addr_const (file, addr);
693 output_addr_const (file, addr);
699 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
703 output_move_single (operands)
706 rtx dst = operands[0];
707 rtx src = operands[1];
714 else if (GET_CODE (src) == CONST_INT)
716 HOST_WIDE_INT value = INTVAL (src);
718 if (CONST_OK_FOR_J (value)) /* signed 5 bit immediate */
721 else if (CONST_OK_FOR_K (value)) /* signed 16 bit immediate */
722 return "movea lo(%1),%.,%0";
724 else if (CONST_OK_FOR_L (value)) /* upper 16 bits were set */
725 return "movhi hi(%1),%.,%0";
727 else /* random constant */
728 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
731 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
733 HOST_WIDE_INT high, low;
735 const_double_split (src, &high, &low);
736 if (CONST_OK_FOR_J (high)) /* signed 5 bit immediate */
739 else if (CONST_OK_FOR_K (high)) /* signed 16 bit immediate */
740 return "movea lo(%F1),%.,%0";
742 else if (CONST_OK_FOR_L (high)) /* upper 16 bits were set */
743 return "movhi hi(%F1),%.,%0";
745 else /* random constant */
746 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
749 else if (GET_CODE (src) == MEM)
750 return "%S1ld%W1 %1,%0";
752 else if (special_symbolref_operand (src, VOIDmode))
753 return "movea %O1(%P1),%Q1,%0";
755 else if (GET_CODE (src) == LABEL_REF
756 || GET_CODE (src) == SYMBOL_REF
757 || GET_CODE (src) == CONST)
759 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
762 else if (GET_CODE (src) == HIGH)
763 return "movhi hi(%1),%.,%0";
765 else if (GET_CODE (src) == LO_SUM)
767 operands[2] = XEXP (src, 0);
768 operands[3] = XEXP (src, 1);
769 return "movea lo(%3),%2,%0";
773 else if (GET_CODE (dst) == MEM)
776 return "%S0st%W0 %1,%0";
778 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
779 return "%S0st%W0 %.,%0";
781 else if (GET_CODE (src) == CONST_DOUBLE
782 && CONST0_RTX (GET_MODE (dst)) == src)
783 return "%S0st%W0 %.,%0";
786 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
791 /* Return appropriate code to load up an 8 byte integer or
792 floating point value */
795 output_move_double (operands)
798 enum machine_mode mode = GET_MODE (operands[0]);
799 rtx dst = operands[0];
800 rtx src = operands[1];
802 if (register_operand (dst, mode)
803 && register_operand (src, mode))
805 if (REGNO (src) + 1 == REGNO (dst))
806 return "mov %R1,%R0\n\tmov %1,%0";
808 return "mov %1,%0\n\tmov %R1,%R0";
812 if (GET_CODE (dst) == MEM
813 && ((GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
814 || (GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src))))
815 return "st.w %.,%0\n\tst.w %.,%R0";
817 if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
819 HOST_WIDE_INT high_low[2];
823 if (GET_CODE (src) == CONST_DOUBLE)
824 const_double_split (src, &high_low[1], &high_low[0]);
827 high_low[0] = INTVAL (src);
828 high_low[1] = (INTVAL (src) >= 0) ? 0 : -1;
831 for (i = 0; i < 2; i++)
833 xop[0] = gen_rtx_REG (SImode, REGNO (dst)+i);
834 xop[1] = GEN_INT (high_low[i]);
835 output_asm_insn (output_move_single (xop), xop);
841 if (GET_CODE (src) == MEM)
844 int dreg = REGNO (dst);
845 rtx inside = XEXP (src, 0);
847 if (GET_CODE (inside) == REG)
848 ptrreg = REGNO (inside);
849 else if (GET_CODE (inside) == SUBREG)
850 ptrreg = subreg_regno (inside);
851 else if (GET_CODE (inside) == PLUS)
852 ptrreg = REGNO (XEXP (inside, 0));
853 else if (GET_CODE (inside) == LO_SUM)
854 ptrreg = REGNO (XEXP (inside, 0));
857 return "ld.w %R1,%R0\n\tld.w %1,%0";
860 if (GET_CODE (src) == MEM)
861 return "ld.w %1,%0\n\tld.w %R1,%R0";
863 if (GET_CODE (dst) == MEM)
864 return "st.w %1,%0\n\tst.w %R1,%R0";
866 return "mov %1,%0\n\tmov %R1,%R0";
870 /* Return maximum offset supported for a short EP memory reference of mode
871 MODE and signedness UNSIGNEDP. */
874 ep_memory_offset (mode, unsignedp)
875 enum machine_mode mode;
876 int ATTRIBUTE_UNUSED unsignedp;
883 max_offset = (1 << 7);
887 max_offset = (1 << 8);
892 max_offset = (1 << 8);
902 /* Return true if OP is a valid short EP memory reference */
905 ep_memory_operand (op, mode, unsigned_load)
907 enum machine_mode mode;
914 if (GET_CODE (op) != MEM)
917 max_offset = ep_memory_offset (mode, unsigned_load);
919 mask = GET_MODE_SIZE (mode) - 1;
922 if (GET_CODE (addr) == CONST)
923 addr = XEXP (addr, 0);
925 switch (GET_CODE (addr))
931 return TDA_NAME_P (XSTR (addr, 0));
934 return REGNO (addr) == EP_REGNUM;
937 op0 = XEXP (addr, 0);
938 op1 = XEXP (addr, 1);
939 if (GET_CODE (op1) == CONST_INT
940 && INTVAL (op1) < max_offset
942 && (INTVAL (op1) & mask) == 0)
944 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
947 if (GET_CODE (op0) == SYMBOL_REF && TDA_NAME_P (XSTR (op0, 0)))
956 /* Return true if OP is either a register or 0 */
959 reg_or_0_operand (op, mode)
961 enum machine_mode mode;
963 if (GET_CODE (op) == CONST_INT)
964 return INTVAL (op) == 0;
966 else if (GET_CODE (op) == CONST_DOUBLE)
967 return CONST_DOUBLE_OK_FOR_G (op);
970 return register_operand (op, mode);
973 /* Return true if OP is either a register or a signed five bit integer */
976 reg_or_int5_operand (op, mode)
978 enum machine_mode mode;
980 if (GET_CODE (op) == CONST_INT)
981 return CONST_OK_FOR_J (INTVAL (op));
984 return register_operand (op, mode);
987 /* Return true if OP is a valid call operand. */
990 call_address_operand (op, mode)
992 enum machine_mode ATTRIBUTE_UNUSED mode;
994 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
995 if (TARGET_LONG_CALLS)
996 return GET_CODE (op) == REG;
997 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
1001 special_symbolref_operand (op, mode)
1003 enum machine_mode ATTRIBUTE_UNUSED mode;
1005 if (GET_CODE (op) == SYMBOL_REF)
1006 return ENCODED_NAME_P (XSTR (op, 0));
1008 else if (GET_CODE (op) == CONST)
1009 return (GET_CODE (XEXP (op, 0)) == PLUS
1010 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
1011 && ENCODED_NAME_P (XSTR (XEXP (XEXP (op, 0), 0), 0))
1012 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
1013 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))));
1019 movsi_source_operand (op, mode)
1021 enum machine_mode mode;
1023 /* Some constants, as well as symbolic operands
1024 must be done with HIGH & LO_SUM patterns. */
1026 && GET_CODE (op) != HIGH
1027 && GET_CODE (op) != CONSTANT_P_RTX
1028 && !(GET_CODE (op) == CONST_INT
1029 && (CONST_OK_FOR_J (INTVAL (op))
1030 || CONST_OK_FOR_K (INTVAL (op))
1031 || CONST_OK_FOR_L (INTVAL (op)))))
1032 return special_symbolref_operand (op, mode);
1034 return general_operand (op, mode);
1038 power_of_two_operand (op, mode)
1040 enum machine_mode ATTRIBUTE_UNUSED mode;
1042 if (GET_CODE (op) != CONST_INT)
1045 if (exact_log2 (INTVAL (op)) == -1)
1051 not_power_of_two_operand (op, mode)
1053 enum machine_mode mode;
1059 else if (mode == HImode)
1061 else if (mode == SImode)
1066 if (GET_CODE (op) != CONST_INT)
1069 if (exact_log2 (~INTVAL (op) & mask) == -1)
1075 /* Substitute memory references involving a pointer, to use the ep pointer,
1076 taking care to save and preserve the ep. */
1079 substitute_ep_register (first_insn, last_insn, uses, regno, p_r1, p_ep)
1087 rtx reg = gen_rtx_REG (Pmode, regno);
1092 regs_ever_live[1] = 1;
1093 *p_r1 = gen_rtx_REG (Pmode, 1);
1094 *p_ep = gen_rtx_REG (Pmode, 30);
1099 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1100 2 * (uses - 3), uses, reg_names[regno],
1101 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1102 INSN_UID (first_insn), INSN_UID (last_insn));
1104 if (GET_CODE (first_insn) == NOTE)
1105 first_insn = next_nonnote_insn (first_insn);
1107 last_insn = next_nonnote_insn (last_insn);
1108 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1110 if (GET_CODE (insn) == INSN)
1112 rtx pattern = single_set (insn);
1114 /* Replace the memory references. */
1118 /* Memory operands are signed by default. */
1119 int unsignedp = FALSE;
1121 if (GET_CODE (SET_DEST (pattern)) == MEM
1122 && GET_CODE (SET_SRC (pattern)) == MEM)
1125 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1126 p_mem = &SET_DEST (pattern);
1128 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1129 p_mem = &SET_SRC (pattern);
1136 rtx addr = XEXP (*p_mem, 0);
1138 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1139 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1141 else if (GET_CODE (addr) == PLUS
1142 && GET_CODE (XEXP (addr, 0)) == REG
1143 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1144 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1145 && ((INTVAL (XEXP (addr, 1)))
1146 < ep_memory_offset (GET_MODE (*p_mem),
1148 && ((INTVAL (XEXP (addr, 1))) >= 0))
1149 *p_mem = change_address (*p_mem, VOIDmode,
1150 gen_rtx_PLUS (Pmode,
1158 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1159 insn = prev_nonnote_insn (first_insn);
1160 if (insn && GET_CODE (insn) == INSN
1161 && GET_CODE (PATTERN (insn)) == SET
1162 && SET_DEST (PATTERN (insn)) == *p_ep
1163 && SET_SRC (PATTERN (insn)) == *p_r1)
1166 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1168 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1169 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1173 /* In rare cases, correct code generation requires extra machine
1174 dependent processing between the second jump optimization pass and
1175 delayed branch scheduling. On those machines, define this macro
1176 as a C statement to act on the code starting at INSN.
1178 On the 850, we use it to implement the -mep mode to copy heavily used
1179 pointers to ep to use the implicit addressing. */
1181 void v850_reorg (start_insn)
1190 regs[FIRST_PSEUDO_REGISTER];
1199 /* If not ep mode, just return now. */
1203 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1206 regs[i].first_insn = NULL_RTX;
1207 regs[i].last_insn = NULL_RTX;
1210 for (insn = start_insn; insn != NULL_RTX; insn = NEXT_INSN (insn))
1212 switch (GET_CODE (insn))
1214 /* End of basic block */
1221 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1223 if (max_uses < regs[i].uses)
1225 max_uses = regs[i].uses;
1231 substitute_ep_register (regs[max_regno].first_insn,
1232 regs[max_regno].last_insn,
1233 max_uses, max_regno, &r1, &ep);
1237 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1240 regs[i].first_insn = NULL_RTX;
1241 regs[i].last_insn = NULL_RTX;
1249 pattern = single_set (insn);
1251 /* See if there are any memory references we can shorten */
1254 rtx src = SET_SRC (pattern);
1255 rtx dest = SET_DEST (pattern);
1257 /* Memory operands are signed by default. */
1258 int unsignedp = FALSE;
1260 /* We might have (SUBREG (MEM)) here, so just get rid of the
1261 subregs to make this code simpler. */
1262 if (GET_CODE (dest) == SUBREG
1263 && (GET_CODE (SUBREG_REG (dest)) == MEM
1264 || GET_CODE (SUBREG_REG (dest)) == REG))
1265 alter_subreg (&dest);
1266 if (GET_CODE (src) == SUBREG
1267 && (GET_CODE (SUBREG_REG (src)) == MEM
1268 || GET_CODE (SUBREG_REG (src)) == REG))
1269 alter_subreg (&src);
1271 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1274 else if (GET_CODE (dest) == MEM)
1277 else if (GET_CODE (src) == MEM)
1283 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1286 else if (!use_ep && mem
1287 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1289 rtx addr = XEXP (mem, 0);
1293 if (GET_CODE (addr) == REG)
1296 regno = REGNO (addr);
1299 else if (GET_CODE (addr) == PLUS
1300 && GET_CODE (XEXP (addr, 0)) == REG
1301 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1302 && ((INTVAL (XEXP (addr, 1)))
1303 < ep_memory_offset (GET_MODE (mem), unsignedp))
1304 && ((INTVAL (XEXP (addr, 1))) >= 0))
1307 regno = REGNO (XEXP (addr, 0));
1316 regs[regno].last_insn = insn;
1317 if (!regs[regno].first_insn)
1318 regs[regno].first_insn = insn;
1322 /* Loading up a register in the basic block zaps any savings
1324 if (GET_CODE (dest) == REG)
1326 enum machine_mode mode = GET_MODE (dest);
1330 regno = REGNO (dest);
1331 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1335 /* See if we can use the pointer before this
1340 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1342 if (max_uses < regs[i].uses)
1344 max_uses = regs[i].uses;
1350 && max_regno >= regno
1351 && max_regno < endregno)
1353 substitute_ep_register (regs[max_regno].first_insn,
1354 regs[max_regno].last_insn,
1355 max_uses, max_regno, &r1,
1358 /* Since we made a substitution, zap all remembered
1360 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1363 regs[i].first_insn = NULL_RTX;
1364 regs[i].last_insn = NULL_RTX;
1369 for (i = regno; i < endregno; i++)
1372 regs[i].first_insn = NULL_RTX;
1373 regs[i].last_insn = NULL_RTX;
1382 /* # of registers saved by the interrupt handler. */
1383 #define INTERRUPT_FIXED_NUM 4
1385 /* # of bytes for registers saved by the interrupt handler. */
1386 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1388 /* # of registers saved in register parameter area. */
1389 #define INTERRUPT_REGPARM_NUM 4
1390 /* # of words saved for other registers. */
1391 #define INTERRUPT_ALL_SAVE_NUM \
1392 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1394 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1397 compute_register_save_size (p_reg_saved)
1402 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1403 int call_p = regs_ever_live [LINK_POINTER_REGNUM];
1406 /* Count the return pointer if we need to save it. */
1407 if (current_function_profile && !call_p)
1408 regs_ever_live [LINK_POINTER_REGNUM] = call_p = 1;
1410 /* Count space for the register saves. */
1411 if (interrupt_handler)
1413 for (i = 0; i <= 31; i++)
1417 if (regs_ever_live[i] || call_p)
1420 reg_saved |= 1L << i;
1424 /* We don't save/restore r0 or the stack pointer */
1426 case STACK_POINTER_REGNUM:
1429 /* For registers with fixed use, we save them, set them to the
1430 appropriate value, and then restore them.
1431 These registers are handled specially, so don't list them
1432 on the list of registers to save in the prologue. */
1433 case 1: /* temp used to hold ep */
1435 case 10: /* temp used to call interrupt save/restore */
1436 case EP_REGNUM: /* ep */
1443 /* Find the first register that needs to be saved. */
1444 for (i = 0; i <= 31; i++)
1445 if (regs_ever_live[i] && ((! call_used_regs[i])
1446 || i == LINK_POINTER_REGNUM))
1449 /* If it is possible that an out-of-line helper function might be
1450 used to generate the prologue for the current function, then we
1451 need to cover the possibility that such a helper function will
1452 be used, despite the fact that there might be gaps in the list of
1453 registers that need to be saved. To detect this we note that the
1454 helper functions always push at least register r29 (provided
1455 that the function is not an interrupt handler). */
1457 if (TARGET_PROLOG_FUNCTION
1458 && (i == 2 || ((i >= 20) && (i < 30))))
1463 reg_saved |= 1L << i;
1468 /* Helper functions save all registers between the starting
1469 register and the last register, regardless of whether they
1470 are actually used by the function or not. */
1471 for (; i <= 29; i++)
1474 reg_saved |= 1L << i;
1477 if (regs_ever_live [LINK_POINTER_REGNUM])
1480 reg_saved |= 1L << LINK_POINTER_REGNUM;
1485 for (; i <= 31; i++)
1486 if (regs_ever_live[i] && ((! call_used_regs[i])
1487 || i == LINK_POINTER_REGNUM))
1490 reg_saved |= 1L << i;
1496 *p_reg_saved = reg_saved;
1502 compute_frame_size (size, p_reg_saved)
1507 + compute_register_save_size (p_reg_saved)
1508 + current_function_outgoing_args_size);
1517 unsigned int size = get_frame_size ();
1518 unsigned int actual_fsize;
1519 unsigned int init_stack_alloc = 0;
1522 unsigned int num_save;
1523 unsigned int default_stack;
1525 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1528 actual_fsize = compute_frame_size (size, ®_saved);
1530 /* Save/setup global registers for interrupt functions right now. */
1531 if (interrupt_handler)
1533 emit_insn (gen_save_interrupt ());
1535 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1537 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1538 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1541 /* Save arg registers to the stack if necessary. */
1542 else if (current_function_anonymous_args)
1544 if (TARGET_PROLOG_FUNCTION)
1546 emit_insn (gen_save_r6_r9 ());
1551 for (i = 6; i < 10; i++)
1553 emit_move_insn (gen_rtx_MEM (SImode,
1554 plus_constant (stack_pointer_rtx,
1556 gen_rtx_REG (SImode, i));
1562 /* Identify all of the saved registers. */
1565 for (i = 1; i < 31; i++)
1567 if (((1L << i) & reg_saved) != 0)
1568 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1571 /* If the return pointer is saved, the helper functions also allocate
1572 16 bytes of stack for arguments to be saved in. */
1573 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1575 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1579 /* See if we have an insn that allocates stack space and saves the particular
1580 registers we want to. */
1581 save_all = NULL_RTX;
1582 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1584 int alloc_stack = (4 * num_save) + default_stack;
1585 int unalloc_stack = actual_fsize - alloc_stack;
1586 int save_func_len = 4;
1587 int save_normal_len;
1590 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1592 /* see if we would have used ep to save the stack */
1593 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1594 save_normal_len = (3 * 2) + (2 * num_save);
1596 save_normal_len = 4 * num_save;
1598 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1600 /* Don't bother checking if we don't actually save any space.
1601 This happens for instance if one register is saved and additional
1602 stack space is allocated. */
1603 if (save_func_len < save_normal_len)
1605 save_all = gen_rtx_PARALLEL
1607 rtvec_alloc (num_save + (TARGET_V850 ? 2 : 1)));
1609 XVECEXP (save_all, 0, 0)
1610 = gen_rtx_SET (VOIDmode,
1612 plus_constant (stack_pointer_rtx, -alloc_stack));
1616 XVECEXP (save_all, 0, num_save+1)
1617 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1620 offset = - default_stack;
1621 for (i = 0; i < num_save; i++)
1623 XVECEXP (save_all, 0, i+1)
1624 = gen_rtx_SET (VOIDmode,
1626 plus_constant (stack_pointer_rtx,
1632 code = recog (save_all, NULL_RTX, NULL);
1635 rtx insn = emit_insn (save_all);
1636 INSN_CODE (insn) = code;
1637 actual_fsize -= alloc_stack;
1641 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1642 save_normal_len - save_func_len,
1643 save_normal_len, save_func_len,
1644 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1647 save_all = NULL_RTX;
1651 /* If no prolog save function is available, store the registers the old
1652 fashioned way (one by one). */
1655 /* Special case interrupt functions that save all registers for a call. */
1656 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1658 emit_insn (gen_save_all_interrupt ());
1662 /* If the stack is too big, allocate it in chunks so we can do the
1663 register saves. We use the register save size so we use the ep
1665 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1666 init_stack_alloc = compute_register_save_size (NULL);
1668 init_stack_alloc = actual_fsize;
1670 /* Save registers at the beginning of the stack frame */
1671 offset = init_stack_alloc - 4;
1673 if (init_stack_alloc)
1674 emit_insn (gen_addsi3 (stack_pointer_rtx,
1676 GEN_INT (-init_stack_alloc)));
1678 /* Save the return pointer first. */
1679 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1681 emit_move_insn (gen_rtx_MEM (SImode,
1682 plus_constant (stack_pointer_rtx,
1684 save_regs[--num_save]);
1688 for (i = 0; i < num_save; i++)
1690 emit_move_insn (gen_rtx_MEM (SImode,
1691 plus_constant (stack_pointer_rtx,
1699 /* Allocate the rest of the stack that was not allocated above (either it is
1700 > 32K or we just called a function to save the registers and needed more
1702 if (actual_fsize > init_stack_alloc)
1704 int diff = actual_fsize - init_stack_alloc;
1705 if (CONST_OK_FOR_K (diff))
1706 emit_insn (gen_addsi3 (stack_pointer_rtx,
1711 rtx reg = gen_rtx_REG (Pmode, 12);
1712 emit_move_insn (reg, GEN_INT (-diff));
1713 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1717 /* If we need a frame pointer, set it up now. */
1718 if (frame_pointer_needed)
1719 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1728 unsigned int size = get_frame_size ();
1730 unsigned int actual_fsize = compute_frame_size (size, ®_saved);
1731 unsigned int init_stack_free = 0;
1732 rtx restore_regs[32];
1734 unsigned int num_restore;
1735 unsigned int default_stack;
1737 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1739 /* Eliminate the initial stack stored by interrupt functions. */
1740 if (interrupt_handler)
1742 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1743 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1744 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1747 /* Cut off any dynamic stack created. */
1748 if (frame_pointer_needed)
1749 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1751 /* Identify all of the saved registers. */
1754 for (i = 1; i < 31; i++)
1756 if (((1L << i) & reg_saved) != 0)
1757 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1760 /* If the return pointer is saved, the helper functions also allocate
1761 16 bytes of stack for arguments to be saved in. */
1762 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1764 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1768 /* See if we have an insn that restores the particular registers we
1770 restore_all = NULL_RTX;
1772 if (TARGET_PROLOG_FUNCTION
1774 && actual_fsize >= default_stack
1775 && !interrupt_handler)
1777 int alloc_stack = (4 * num_restore) + default_stack;
1778 int unalloc_stack = actual_fsize - alloc_stack;
1779 int restore_func_len = 4;
1780 int restore_normal_len;
1783 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1785 /* See if we would have used ep to restore the registers. */
1786 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1787 restore_normal_len = (3 * 2) + (2 * num_restore);
1789 restore_normal_len = 4 * num_restore;
1791 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1793 /* Don't bother checking if we don't actually save any space. */
1794 if (restore_func_len < restore_normal_len)
1796 restore_all = gen_rtx_PARALLEL (VOIDmode,
1797 rtvec_alloc (num_restore + 2));
1798 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1799 XVECEXP (restore_all, 0, 1)
1800 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1801 gen_rtx_PLUS (Pmode,
1803 GEN_INT (alloc_stack)));
1805 offset = alloc_stack - 4;
1806 for (i = 0; i < num_restore; i++)
1808 XVECEXP (restore_all, 0, i+2)
1809 = gen_rtx_SET (VOIDmode,
1812 plus_constant (stack_pointer_rtx,
1817 code = recog (restore_all, NULL_RTX, NULL);
1823 actual_fsize -= alloc_stack;
1826 if (CONST_OK_FOR_K (actual_fsize))
1827 emit_insn (gen_addsi3 (stack_pointer_rtx,
1829 GEN_INT (actual_fsize)));
1832 rtx reg = gen_rtx_REG (Pmode, 12);
1833 emit_move_insn (reg, GEN_INT (actual_fsize));
1834 emit_insn (gen_addsi3 (stack_pointer_rtx,
1840 insn = emit_jump_insn (restore_all);
1841 INSN_CODE (insn) = code;
1845 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1846 restore_normal_len - restore_func_len,
1847 restore_normal_len, restore_func_len,
1848 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1851 restore_all = NULL_RTX;
1855 /* If no epilog save function is available, restore the registers the
1856 old fashioned way (one by one). */
1859 /* If the stack is large, we need to cut it down in 2 pieces. */
1860 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1861 init_stack_free = 4 * num_restore;
1863 init_stack_free = actual_fsize;
1865 /* Deallocate the rest of the stack if it is > 32K. */
1866 if (actual_fsize > init_stack_free)
1870 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1872 if (CONST_OK_FOR_K (diff))
1873 emit_insn (gen_addsi3 (stack_pointer_rtx,
1878 rtx reg = gen_rtx_REG (Pmode, 12);
1879 emit_move_insn (reg, GEN_INT (diff));
1880 emit_insn (gen_addsi3 (stack_pointer_rtx,
1886 /* Special case interrupt functions that save all registers
1888 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1890 emit_insn (gen_restore_all_interrupt ());
1894 /* Restore registers from the beginning of the stack frame. */
1895 offset = init_stack_free - 4;
1897 /* Restore the return pointer first. */
1899 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
1901 emit_move_insn (restore_regs[--num_restore],
1902 gen_rtx_MEM (SImode,
1903 plus_constant (stack_pointer_rtx,
1908 for (i = 0; i < num_restore; i++)
1910 emit_move_insn (restore_regs[i],
1911 gen_rtx_MEM (SImode,
1912 plus_constant (stack_pointer_rtx,
1915 emit_insn (gen_rtx_USE (VOIDmode, restore_regs[i]));
1919 /* Cut back the remainder of the stack. */
1920 if (init_stack_free)
1921 emit_insn (gen_addsi3 (stack_pointer_rtx,
1923 GEN_INT (init_stack_free)));
1926 /* And return or use reti for interrupt handlers. */
1927 if (interrupt_handler)
1928 emit_jump_insn (gen_restore_interrupt ());
1929 else if (actual_fsize)
1930 emit_jump_insn (gen_return_internal ());
1932 emit_jump_insn (gen_return ());
1935 current_function_anonymous_args = 0;
1936 v850_interrupt_cache_p = FALSE;
1937 v850_interrupt_p = FALSE;
1941 /* Update the condition code from the insn. */
1944 notice_update_cc (body, insn)
1948 switch (get_attr_cc (insn))
1951 /* Insn does not affect CC at all. */
1955 /* Insn does not change CC, but the 0'th operand has been changed. */
1956 if (cc_status.value1 != 0
1957 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1958 cc_status.value1 = 0;
1962 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1963 V,C is in an unusable state. */
1965 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1966 cc_status.value1 = recog_data.operand[0];
1970 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1971 C is in an unusable state. */
1973 cc_status.flags |= CC_NO_CARRY;
1974 cc_status.value1 = recog_data.operand[0];
1978 /* The insn is a compare instruction. */
1980 cc_status.value1 = SET_SRC (body);
1984 /* Insn doesn't leave CC in a usable state. */
1990 /* Retrieve the data area that has been chosen for the given decl. */
1993 v850_get_data_area (decl)
1996 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
1997 return DATA_AREA_SDA;
1999 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2000 return DATA_AREA_TDA;
2002 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2003 return DATA_AREA_ZDA;
2005 return DATA_AREA_NORMAL;
2008 /* Store the indicated data area in the decl's attributes. */
2011 v850_set_data_area (decl, data_area)
2013 v850_data_area data_area;
2019 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2020 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2021 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2026 DECL_ATTRIBUTES (decl) = tree_cons
2027 (name, NULL, DECL_ATTRIBUTES (decl));
2030 const struct attribute_spec v850_attribute_table[] =
2032 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2033 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2034 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2035 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2036 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2037 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2038 { NULL, 0, 0, false, false, false, NULL }
2041 /* Handle an "interrupt" attribute; arguments as in
2042 struct attribute_spec.handler. */
2044 v850_handle_interrupt_attribute (node, name, args, flags, no_add_attrs)
2047 tree args ATTRIBUTE_UNUSED;
2048 int flags ATTRIBUTE_UNUSED;
2051 if (TREE_CODE (*node) != FUNCTION_DECL)
2053 warning ("`%s' attribute only applies to functions",
2054 IDENTIFIER_POINTER (name));
2055 *no_add_attrs = true;
2061 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2062 struct attribute_spec.handler. */
2064 v850_handle_data_area_attribute (node, name, args, flags, no_add_attrs)
2067 tree args ATTRIBUTE_UNUSED;
2068 int flags ATTRIBUTE_UNUSED;
2071 v850_data_area data_area;
2072 v850_data_area area;
2075 /* Implement data area attribute. */
2076 if (is_attribute_p ("sda", name))
2077 data_area = DATA_AREA_SDA;
2078 else if (is_attribute_p ("tda", name))
2079 data_area = DATA_AREA_TDA;
2080 else if (is_attribute_p ("zda", name))
2081 data_area = DATA_AREA_ZDA;
2085 switch (TREE_CODE (decl))
2088 if (current_function_decl != NULL_TREE)
2090 error_with_decl (decl, "\
2091 a data area attribute cannot be specified for local variables");
2092 *no_add_attrs = true;
2098 area = v850_get_data_area (decl);
2099 if (area != DATA_AREA_NORMAL && data_area != area)
2101 error_with_decl (decl, "\
2102 data area of '%s' conflicts with previous declaration");
2103 *no_add_attrs = true;
2115 /* Return nonzero if FUNC is an interrupt function as specified
2116 by the "interrupt" attribute. */
2119 v850_interrupt_function_p (func)
2125 if (v850_interrupt_cache_p)
2126 return v850_interrupt_p;
2128 if (TREE_CODE (func) != FUNCTION_DECL)
2131 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2137 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2138 ret = a != NULL_TREE;
2141 /* Its not safe to trust global variables until after function inlining has
2143 if (reload_completed | reload_in_progress)
2144 v850_interrupt_p = ret;
2151 v850_encode_data_area (decl)
2154 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2155 int len = strlen (str);
2158 /* Map explict sections into the appropriate attribute */
2159 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2161 if (DECL_SECTION_NAME (decl))
2163 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2165 if (streq (name, ".zdata") || streq (name, ".zbss"))
2166 v850_set_data_area (decl, DATA_AREA_ZDA);
2168 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2169 v850_set_data_area (decl, DATA_AREA_SDA);
2171 else if (streq (name, ".tdata"))
2172 v850_set_data_area (decl, DATA_AREA_TDA);
2175 /* If no attribute, support -m{zda,sda,tda}=n */
2178 int size = int_size_in_bytes (TREE_TYPE (decl));
2182 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2183 v850_set_data_area (decl, DATA_AREA_TDA);
2185 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2186 v850_set_data_area (decl, DATA_AREA_SDA);
2188 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2189 v850_set_data_area (decl, DATA_AREA_ZDA);
2192 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2196 newstr = alloca (len + 2);
2198 strcpy (newstr + 1, str);
2200 switch (v850_get_data_area (decl))
2202 case DATA_AREA_ZDA: *newstr = ZDA_NAME_FLAG_CHAR; break;
2203 case DATA_AREA_TDA: *newstr = TDA_NAME_FLAG_CHAR; break;
2204 case DATA_AREA_SDA: *newstr = SDA_NAME_FLAG_CHAR; break;
2208 XSTR (XEXP (DECL_RTL (decl), 0), 0) = ggc_alloc_string (newstr, len + 2);
2212 v850_encode_section_info (decl, first)
2216 if (first && TREE_CODE (decl) == VAR_DECL
2217 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2218 v850_encode_data_area (decl);
2221 /* Return true if the given RTX is a register which can be restored
2222 by a function epilogue. */
2224 register_is_ok_for_epilogue (op, mode)
2226 enum machine_mode ATTRIBUTE_UNUSED mode;
2228 /* The save/restore routines can only cope with registers 2, and 20 - 31 */
2229 return (GET_CODE (op) == REG)
2230 && (((REGNO (op) >= 20) && REGNO (op) <= 31)
2231 || REGNO (op) == 2);
2234 /* Return non-zero if the given RTX is suitable for collapsing into
2235 jump to a function epilogue. */
2237 pattern_is_ok_for_epilogue (op, mode)
2239 enum machine_mode ATTRIBUTE_UNUSED mode;
2241 int count = XVECLEN (op, 0);
2244 /* If there are no registers to restore then the function epilogue
2249 /* The pattern matching has already established that we are performing a
2250 function epilogue and that we are popping at least one register. We must
2251 now check the remaining entries in the vector to make sure that they are
2252 also register pops. There is no good reason why there should ever be
2253 anything else in this vector, but being paranoid always helps...
2255 The test below performs the C equivalent of this machine description
2258 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2259 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2262 for (i = 3; i < count; i++)
2264 rtx vector_element = XVECEXP (op, 0, i);
2269 if (GET_CODE (vector_element) != SET)
2272 dest = SET_DEST (vector_element);
2273 src = SET_SRC (vector_element);
2275 if (GET_CODE (dest) != REG
2276 || GET_MODE (dest) != SImode
2277 || ! register_is_ok_for_epilogue (dest, SImode)
2278 || GET_CODE (src) != MEM
2279 || GET_MODE (src) != SImode)
2282 plus = XEXP (src, 0);
2284 if (GET_CODE (plus) != PLUS
2285 || GET_CODE (XEXP (plus, 0)) != REG
2286 || GET_MODE (XEXP (plus, 0)) != SImode
2287 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2288 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2295 /* Construct a JR instruction to a routine that will perform the equivalent of
2296 the RTL passed in as an argument. This RTL is a function epilogue that
2297 pops registers off the stack and possibly releases some extra stack space
2298 as well. The code has already verified that the RTL matches these
2301 construct_restore_jr (op)
2304 int count = XVECLEN (op, 0);
2306 unsigned long int mask;
2307 unsigned long int first;
2308 unsigned long int last;
2310 static char buff [100]; /* XXX */
2314 error ("bogus JR construction: %d\n", count);
2318 /* Work out how many bytes to pop off the stack before retrieving
2320 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2322 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2324 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2327 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2329 /* Each pop will remove 4 bytes from the stack... */
2330 stack_bytes -= (count - 2) * 4;
2332 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2333 if (stack_bytes != 0 && stack_bytes != 16)
2335 error ("bad amount of stack space removal: %d", stack_bytes);
2339 /* Now compute the bit mask of registers to push. */
2341 for (i = 2; i < count; i++)
2343 rtx vector_element = XVECEXP (op, 0, i);
2345 if (GET_CODE (vector_element) != SET)
2347 if (GET_CODE (SET_DEST (vector_element)) != REG)
2349 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2352 mask |= 1 << REGNO (SET_DEST (vector_element));
2355 /* Scan for the first register to pop. */
2356 for (first = 0; first < 32; first++)
2358 if (mask & (1 << first))
2365 /* Discover the last register to pop. */
2366 if (mask & (1 << LINK_POINTER_REGNUM))
2368 if (stack_bytes != 16)
2371 last = LINK_POINTER_REGNUM;
2375 if (stack_bytes != 0)
2378 if ((mask & (1 << 29)) == 0)
2384 /* Note, it is possible to have gaps in the register mask.
2385 We ignore this here, and generate a JR anyway. We will
2386 be popping more registers than is strictly necessary, but
2387 it does save code space. */
2389 if (TARGET_LONG_CALLS)
2394 sprintf (name, "__return_%s", reg_names [first]);
2396 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2398 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2404 sprintf (buff, "jr __return_%s", reg_names [first]);
2406 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2413 /* Return non-zero if the given RTX is suitable for collapsing into
2414 a jump to a function prologue. */
2416 pattern_is_ok_for_prologue (op, mode)
2418 enum machine_mode ATTRIBUTE_UNUSED mode;
2420 int count = XVECLEN (op, 0);
2424 /* If there are no registers to save then the function prologue
2429 /* The pattern matching has already established that we are adjusting the
2430 stack and pushing at least one register. We must now check that the
2431 remaining entries in the vector to make sure that they are also register
2432 pushes, except for the last entry which should be a CLOBBER of r10.
2434 The test below performs the C equivalent of this machine description
2437 (set (mem:SI (plus:SI (reg:SI 3)
2438 (match_operand:SI 2 "immediate_operand" "i")))
2439 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2443 for (i = 2; i < count - 1; i++)
2449 vector_element = XVECEXP (op, 0, i);
2451 if (GET_CODE (vector_element) != SET)
2454 dest = SET_DEST (vector_element);
2455 src = SET_SRC (vector_element);
2457 if (GET_CODE (dest) != MEM
2458 || GET_MODE (dest) != SImode
2459 || GET_CODE (src) != REG
2460 || GET_MODE (src) != SImode
2461 || ! register_is_ok_for_epilogue (src, SImode))
2464 plus = XEXP (dest, 0);
2466 if ( GET_CODE (plus) != PLUS
2467 || GET_CODE (XEXP (plus, 0)) != REG
2468 || GET_MODE (XEXP (plus, 0)) != SImode
2469 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2470 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2473 /* If the register is being pushed somewhere other than the stack
2474 space just acquired by the first operand then abandon this quest.
2475 Note: the test is <= because both values are negative. */
2476 if (INTVAL (XEXP (plus, 1))
2477 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2483 /* Make sure that the last entry in the vector is a clobber. */
2484 vector_element = XVECEXP (op, 0, i);
2486 if (GET_CODE (vector_element) != CLOBBER
2487 || GET_CODE (XEXP (vector_element, 0)) != REG
2488 || REGNO (XEXP (vector_element, 0)) != 10)
2494 /* Construct a JARL instruction to a routine that will perform the equivalent
2495 of the RTL passed as a parameter. This RTL is a function prologue that
2496 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2497 some stack space as well. The code has already verified that the RTL
2498 matches these requirements. */
2500 construct_save_jarl (op)
2503 int count = XVECLEN (op, 0);
2505 unsigned long int mask;
2506 unsigned long int first;
2507 unsigned long int last;
2509 static char buff [100]; /* XXX */
2513 error ("bogus JARL construction: %d\n", count);
2518 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2520 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2522 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2524 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2527 /* Work out how many bytes to push onto the stack after storing the
2529 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2531 /* Each push will put 4 bytes from the stack... */
2532 stack_bytes += (count - 2) * 4;
2534 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2535 if (stack_bytes != 0 && stack_bytes != -16)
2537 error ("bad amount of stack space removal: %d", stack_bytes);
2541 /* Now compute the bit mask of registers to push. */
2543 for (i = 1; i < count - 1; i++)
2545 rtx vector_element = XVECEXP (op, 0, i);
2547 if (GET_CODE (vector_element) != SET)
2549 if (GET_CODE (SET_SRC (vector_element)) != REG)
2551 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2554 mask |= 1 << REGNO (SET_SRC (vector_element));
2557 /* Scan for the first register to push. */
2558 for (first = 0; first < 32; first++)
2560 if (mask & (1 << first))
2567 /* Discover the last register to push. */
2568 if (mask & (1 << LINK_POINTER_REGNUM))
2570 if (stack_bytes != -16)
2573 last = LINK_POINTER_REGNUM;
2577 if (stack_bytes != 0)
2579 if ((mask & (1 << 29)) == 0)
2585 /* Note, it is possible to have gaps in the register mask.
2586 We ignore this here, and generate a JARL anyway. We will
2587 be pushing more registers than is strictly necessary, but
2588 it does save code space. */
2590 if (TARGET_LONG_CALLS)
2595 sprintf (name, "__save_%s", reg_names [first]);
2597 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2599 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2605 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2607 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2614 extern tree last_assemble_variable_decl;
2615 extern int size_directive_output;
2617 /* A version of asm_output_aligned_bss() that copes with the special
2618 data areas of the v850. */
2620 v850_output_aligned_bss (file, decl, name, size, align)
2627 ASM_GLOBALIZE_LABEL (file, name);
2629 switch (v850_get_data_area (decl))
2647 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2648 #ifdef ASM_DECLARE_OBJECT_NAME
2649 last_assemble_variable_decl = decl;
2650 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2652 /* Standard thing is just output label for the object. */
2653 ASM_OUTPUT_LABEL (file, name);
2654 #endif /* ASM_DECLARE_OBJECT_NAME */
2655 ASM_OUTPUT_SKIP (file, size ? size : 1);
2658 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2660 v850_output_common (file, decl, name, size, align)
2667 if (decl == NULL_TREE)
2669 fprintf (file, "%s", COMMON_ASM_OP);
2673 switch (v850_get_data_area (decl))
2676 fprintf (file, "%s", ZCOMMON_ASM_OP);
2680 fprintf (file, "%s", SCOMMON_ASM_OP);
2684 fprintf (file, "%s", TCOMMON_ASM_OP);
2688 fprintf (file, "%s", COMMON_ASM_OP);
2693 assemble_name (file, name);
2694 fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2697 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2699 v850_output_local (file, decl, name, size, align)
2706 fprintf (file, "%s", LOCAL_ASM_OP);
2707 assemble_name (file, name);
2708 fprintf (file, "\n");
2710 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2713 /* Add data area to the given declaration if a ghs data area pragma is
2714 currently in effect (#pragma ghs startXXX/endXXX). */
2716 v850_insert_attributes (decl, attr_ptr)
2718 tree *attr_ptr ATTRIBUTE_UNUSED;
2721 && data_area_stack->data_area
2722 && current_function_decl == NULL_TREE
2723 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2724 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2725 v850_set_data_area (decl, data_area_stack->data_area);
2727 /* Initialise the default names of the v850 specific sections,
2728 if this has not been done before. */
2730 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2732 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2733 = build_string (sizeof (".sdata")-1, ".sdata");
2735 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2736 = build_string (sizeof (".rosdata")-1, ".rosdata");
2738 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2739 = build_string (sizeof (".tdata")-1, ".tdata");
2741 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2742 = build_string (sizeof (".zdata")-1, ".zdata");
2744 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2745 = build_string (sizeof (".rozdata")-1, ".rozdata");
2748 if (current_function_decl == NULL_TREE
2749 && (TREE_CODE (decl) == VAR_DECL
2750 || TREE_CODE (decl) == CONST_DECL
2751 || TREE_CODE (decl) == FUNCTION_DECL)
2752 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2753 && !DECL_SECTION_NAME (decl))
2755 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2756 tree chosen_section;
2758 if (TREE_CODE (decl) == FUNCTION_DECL)
2759 kind = GHS_SECTION_KIND_TEXT;
2762 /* First choose a section kind based on the data area of the decl. */
2763 switch (v850_get_data_area (decl))
2769 kind = ((TREE_READONLY (decl))
2770 ? GHS_SECTION_KIND_ROSDATA
2771 : GHS_SECTION_KIND_SDATA);
2775 kind = GHS_SECTION_KIND_TDATA;
2779 kind = ((TREE_READONLY (decl))
2780 ? GHS_SECTION_KIND_ROZDATA
2781 : GHS_SECTION_KIND_ZDATA);
2784 case DATA_AREA_NORMAL: /* default data area */
2785 if (TREE_READONLY (decl))
2786 kind = GHS_SECTION_KIND_RODATA;
2787 else if (DECL_INITIAL (decl))
2788 kind = GHS_SECTION_KIND_DATA;
2790 kind = GHS_SECTION_KIND_BSS;
2794 /* Now, if the section kind has been explicitly renamed,
2795 then attach a section attribute. */
2796 chosen_section = GHS_current_section_names [(int) kind];
2798 /* Otherwise, if this kind of section needs an explicit section
2799 attribute, then also attach one. */
2800 if (chosen_section == NULL)
2801 chosen_section = GHS_default_section_names [(int) kind];
2805 /* Only set the section name if specified by a pragma, because
2806 otherwise it will force those variables to get allocated storage
2807 in this module, rather than by the linker. */
2808 DECL_SECTION_NAME (decl) = chosen_section;
2813 /* Implement `va_arg'. */
2816 v850_va_arg (valist, type)
2819 HOST_WIDE_INT size, rsize;
2824 /* Round up sizeof(type) to a word. */
2825 size = int_size_in_bytes (type);
2826 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
2831 size = rsize = UNITS_PER_WORD;
2835 addr = save_expr (valist);
2836 incr = fold (build (PLUS_EXPR, ptr_type_node, addr,
2837 build_int_2 (rsize, 0)));
2839 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
2840 TREE_SIDE_EFFECTS (incr) = 1;
2841 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
2843 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
2847 addr_rtx = force_reg (Pmode, addr_rtx);
2848 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
2849 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
2855 /* Return an RTX indicating where the return address to the
2856 calling function can be found. */
2859 v850_return_addr (count)
2865 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
2869 v850_select_section (exp, reloc, align)
2872 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
2874 if (TREE_CODE (exp) == VAR_DECL)
2877 if (!TREE_READONLY (exp)
2878 || TREE_SIDE_EFFECTS (exp)
2879 || !DECL_INITIAL (exp)
2880 || (DECL_INITIAL (exp) != error_mark_node
2881 && !TREE_CONSTANT (DECL_INITIAL (exp))))
2886 switch (v850_get_data_area (exp))
2908 readonly_data_section ();
2914 else if (TREE_CODE (exp) == STRING_CST)
2916 if (! flag_writable_strings)
2917 readonly_data_section ();
2922 readonly_data_section ();