1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
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"
44 #include "target-def.h"
47 #define streq(a,b) (strcmp (a, b) == 0)
50 /* Function prototypes for stupid compilers: */
51 static void const_double_split PARAMS ((rtx, HOST_WIDE_INT *, HOST_WIDE_INT *));
52 static int const_costs_int PARAMS ((HOST_WIDE_INT, int));
53 static void substitute_ep_register PARAMS ((rtx, rtx, int, int, rtx *, rtx *));
54 static int ep_memory_offset PARAMS ((enum machine_mode, int));
55 static void v850_set_data_area PARAMS ((tree, v850_data_area));
56 static int v850_valid_decl_attribute PARAMS ((tree, tree, tree, tree));
57 static void v850_insert_attributes PARAMS ((tree, tree *));
59 /* True if the current function has anonymous arguments. */
60 int current_function_anonymous_args;
62 /* Information about the various small memory areas. */
63 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
65 /* name value max physical max */
66 { "tda", (char *)0, 0, 256 },
67 { "sda", (char *)0, 0, 65536 },
68 { "zda", (char *)0, 0, 32768 },
71 /* Names of the various data areas used on the v850. */
72 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
73 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
75 /* Track the current data area set by the data area pragma (which
76 can be nested). Tested by check_default_data_area. */
77 data_area_stack_element * data_area_stack = NULL;
79 /* True if we don't need to check any more if the current
80 function is an interrupt handler. */
81 static int v850_interrupt_cache_p = FALSE;
83 /* Whether current function is an interrupt handler. */
84 static int v850_interrupt_p = FALSE;
86 /* Initialize the GCC target structure. */
87 #undef TARGET_VALID_DECL_ATTRIBUTE
88 #define TARGET_VALID_DECL_ATTRIBUTE v850_valid_decl_attribute
90 #undef TARGET_INSERT_ATTRIBUTES
91 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
93 struct gcc_target targetm = TARGET_INITIALIZER;
95 /* Sometimes certain combinations of command options do not make
96 sense on a particular target machine. You can define a macro
97 `OVERRIDE_OPTIONS' to take account of this. This macro, if
98 defined, is executed once just after all the command options have
101 Don't use this macro to turn on various extra optimizations for
102 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
108 extern int atoi PARAMS ((const char *));
110 /* Parse -m{s,t,z}da=nnn switches */
111 for (i = 0; i < (int)SMALL_MEMORY_max; i++)
113 if (small_memory[i].value)
115 if (!ISDIGIT (*small_memory[i].value))
116 error ("%s=%s is not numeric.",
117 small_memory[i].name,
118 small_memory[i].value);
121 small_memory[i].max = atoi (small_memory[i].value);
122 if (small_memory[i].max > small_memory[i].physical_max)
123 error ("%s=%s is too large.",
124 small_memory[i].name,
125 small_memory[i].value);
132 /* Output assembly code for the start of the file. */
135 asm_file_start (file)
138 output_file_directive (file, main_input_filename);
142 /* Return an RTX to represent where a value with mode MODE will be returned
143 from a function. If the result is 0, the argument is pushed. */
146 function_arg (cum, mode, type, named)
147 CUMULATIVE_ARGS *cum;
148 enum machine_mode mode;
155 if (TARGET_GHS && !named)
159 size = int_size_in_bytes (type);
161 size = GET_MODE_SIZE (mode);
164 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
168 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
170 if (cum->nbytes > 4 * UNITS_PER_WORD)
173 if (type == NULL_TREE
174 && cum->nbytes + size > 4 * UNITS_PER_WORD)
177 switch (cum->nbytes / UNITS_PER_WORD)
180 result = gen_rtx_REG (mode, 6);
183 result = gen_rtx_REG (mode, 7);
186 result = gen_rtx_REG (mode, 8);
189 result = gen_rtx_REG (mode, 9);
199 /* Return the number of words which must be put into registers
200 for values which are part in registers and part in memory. */
203 function_arg_partial_nregs (cum, mode, type, named)
204 CUMULATIVE_ARGS *cum;
205 enum machine_mode mode;
211 if (TARGET_GHS && !named)
215 size = int_size_in_bytes (type);
217 size = GET_MODE_SIZE (mode);
220 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
224 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
226 if (cum->nbytes > 4 * UNITS_PER_WORD)
229 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
232 if (type == NULL_TREE
233 && cum->nbytes + size > 4 * UNITS_PER_WORD)
236 return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
240 /* Return the high and low words of a CONST_DOUBLE */
243 const_double_split (x, p_high, p_low)
245 HOST_WIDE_INT *p_high;
246 HOST_WIDE_INT *p_low;
248 if (GET_CODE (x) == CONST_DOUBLE)
253 switch (GET_MODE (x))
256 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
257 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
258 *p_high = t[1]; /* since v850 is little endian */
259 *p_low = t[0]; /* high is second word */
263 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
264 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
270 *p_high = CONST_DOUBLE_HIGH (x);
271 *p_low = CONST_DOUBLE_LOW (x);
279 fatal_insn ("const_double_split got a bad insn:", x);
283 /* Return the cost of the rtx R with code CODE. */
286 const_costs_int (value, zero_cost)
290 if (CONST_OK_FOR_I (value))
292 else if (CONST_OK_FOR_J (value))
294 else if (CONST_OK_FOR_K (value))
305 HOST_WIDE_INT high, low;
310 return const_costs_int (INTVAL (r), 0);
313 const_double_split (r, &high, &low);
314 if (GET_MODE (r) == SFmode)
315 return const_costs_int (high, 1);
317 return const_costs_int (high, 1) + const_costs_int (low, 1);
333 /* Print operand X using operand code CODE to assembly language output file
337 print_operand (file, x, code)
342 HOST_WIDE_INT high, low;
347 /* We use 'c' operands with symbols for .vtinherit */
348 if (GET_CODE (x) == SYMBOL_REF)
350 output_addr_const(file, x);
357 switch ((code == 'B' || code == 'C')
358 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
361 if (code == 'c' || code == 'C')
362 fprintf (file, "nz");
364 fprintf (file, "ne");
367 if (code == 'c' || code == 'C')
373 fprintf (file, "ge");
376 fprintf (file, "gt");
379 fprintf (file, "le");
382 fprintf (file, "lt");
385 fprintf (file, "nl");
391 fprintf (file, "nh");
400 case 'F': /* high word of CONST_DOUBLE */
401 if (GET_CODE (x) == CONST_INT)
402 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
403 else if (GET_CODE (x) == CONST_DOUBLE)
405 const_double_split (x, &high, &low);
406 fprintf (file, "%ld", (long) high);
411 case 'G': /* low word of CONST_DOUBLE */
412 if (GET_CODE (x) == CONST_INT)
413 fprintf (file, "%ld", (long) INTVAL (x));
414 else if (GET_CODE (x) == CONST_DOUBLE)
416 const_double_split (x, &high, &low);
417 fprintf (file, "%ld", (long) low);
423 fprintf (file, "%d\n", INTVAL (x) & 0xffff);
426 fprintf (file, "%d", exact_log2 (INTVAL (x)));
429 if (special_symbolref_operand (x, VOIDmode))
433 if (GET_CODE (x) == SYMBOL_REF)
435 else if (GET_CODE (x) == CONST)
436 name = XSTR (XEXP (XEXP (x, 0), 0), 0);
440 if (ZDA_NAME_P (name))
441 fprintf (file, "zdaoff");
442 else if (SDA_NAME_P (name))
443 fprintf (file, "sdaoff");
444 else if (TDA_NAME_P (name))
445 fprintf (file, "tdaoff");
453 if (special_symbolref_operand (x, VOIDmode))
454 output_addr_const (file, x);
459 if (special_symbolref_operand (x, VOIDmode))
463 if (GET_CODE (x) == SYMBOL_REF)
465 else if (GET_CODE (x) == CONST)
466 name = XSTR (XEXP (XEXP (x, 0), 0), 0);
470 if (ZDA_NAME_P (name))
471 fprintf (file, "r0");
472 else if (SDA_NAME_P (name))
473 fprintf (file, "gp");
474 else if (TDA_NAME_P (name))
475 fprintf (file, "ep");
482 case 'R': /* 2nd word of a double. */
483 switch (GET_CODE (x))
486 fprintf (file, reg_names[REGNO (x) + 1]);
489 x = XEXP (adjust_address (x, SImode, 4), 0);
490 print_operand_address (file, x);
491 if (GET_CODE (x) == CONST_INT)
492 fprintf (file, "[r0]");
501 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
502 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
509 /* Like an 'S' operand above, but for unsigned loads only. */
510 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
515 case 'W': /* print the instruction suffix */
516 switch (GET_MODE (x))
521 case QImode: fputs (".b", file); break;
522 case HImode: fputs (".h", file); break;
523 case SImode: fputs (".w", file); break;
524 case SFmode: fputs (".w", file); break;
527 case '.': /* register r0 */
528 fputs (reg_names[0], file);
530 case 'z': /* reg or zero */
532 fputs (reg_names[0], file);
533 else if (GET_CODE (x) == REG)
534 fputs (reg_names[REGNO (x)], file);
539 switch (GET_CODE (x))
542 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
543 output_address (gen_rtx_PLUS (SImode, gen_rtx (REG, SImode, 0),
546 output_address (XEXP (x, 0));
550 fputs (reg_names[REGNO (x)], file);
553 fputs (reg_names[subreg_regno (x)], file);
560 print_operand_address (file, x);
571 /* Output assembly language output for the address ADDR to FILE. */
574 print_operand_address (file, addr)
578 switch (GET_CODE (addr))
581 fprintf (file, "0[");
582 print_operand (file, addr, 0);
586 if (GET_CODE (XEXP (addr, 0)) == REG)
589 fprintf (file, "lo(");
590 print_operand (file, XEXP (addr, 1), 0);
591 fprintf (file, ")[");
592 print_operand (file, XEXP (addr, 0), 0);
597 if (GET_CODE (XEXP (addr, 0)) == REG
598 || GET_CODE (XEXP (addr, 0)) == SUBREG)
601 print_operand (file, XEXP (addr, 1), 0);
603 print_operand (file, XEXP (addr, 0), 0);
608 print_operand (file, XEXP (addr, 0), 0);
610 print_operand (file, XEXP (addr, 1), 0);
614 if (ENCODED_NAME_P (XSTR (addr, 0)))
616 const char *name = XSTR (addr, 0);
617 const char *off_name;
618 const char *reg_name;
620 if (ZDA_NAME_P (name))
625 else if (SDA_NAME_P (name))
630 else if (TDA_NAME_P (name))
638 fprintf (file, "%s(", off_name);
639 output_addr_const (file, addr);
640 fprintf (file, ")[%s]", reg_name);
643 output_addr_const (file, addr);
646 if (special_symbolref_operand (addr, VOIDmode))
648 const char *name = XSTR (XEXP (XEXP (addr, 0), 0), 0);
649 const char *off_name;
650 const char *reg_name;
652 if (ZDA_NAME_P (name))
657 else if (SDA_NAME_P (name))
662 else if (TDA_NAME_P (name))
670 fprintf (file, "%s(", off_name);
671 output_addr_const (file, addr);
672 fprintf (file, ")[%s]", reg_name);
675 output_addr_const (file, addr);
678 output_addr_const (file, addr);
684 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
688 output_move_single (operands)
691 rtx dst = operands[0];
692 rtx src = operands[1];
699 else if (GET_CODE (src) == CONST_INT)
701 HOST_WIDE_INT value = INTVAL (src);
703 if (CONST_OK_FOR_J (value)) /* signed 5 bit immediate */
706 else if (CONST_OK_FOR_K (value)) /* signed 16 bit immediate */
707 return "movea lo(%1),%.,%0";
709 else if (CONST_OK_FOR_L (value)) /* upper 16 bits were set */
710 return "movhi hi(%1),%.,%0";
712 else /* random constant */
713 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
716 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
718 HOST_WIDE_INT high, low;
720 const_double_split (src, &high, &low);
721 if (CONST_OK_FOR_J (high)) /* signed 5 bit immediate */
724 else if (CONST_OK_FOR_K (high)) /* signed 16 bit immediate */
725 return "movea lo(%F1),%.,%0";
727 else if (CONST_OK_FOR_L (high)) /* upper 16 bits were set */
728 return "movhi hi(%F1),%.,%0";
730 else /* random constant */
731 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
734 else if (GET_CODE (src) == MEM)
735 return "%S1ld%W1 %1,%0";
737 else if (special_symbolref_operand (src, VOIDmode))
738 return "movea %O1(%P1),%Q1,%0";
740 else if (GET_CODE (src) == LABEL_REF
741 || GET_CODE (src) == SYMBOL_REF
742 || GET_CODE (src) == CONST)
744 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
747 else if (GET_CODE (src) == HIGH)
748 return "movhi hi(%1),%.,%0";
750 else if (GET_CODE (src) == LO_SUM)
752 operands[2] = XEXP (src, 0);
753 operands[3] = XEXP (src, 1);
754 return "movea lo(%3),%2,%0";
758 else if (GET_CODE (dst) == MEM)
761 return "%S0st%W0 %1,%0";
763 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
764 return "%S0st%W0 %.,%0";
766 else if (GET_CODE (src) == CONST_DOUBLE
767 && CONST0_RTX (GET_MODE (dst)) == src)
768 return "%S0st%W0 %.,%0";
771 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
776 /* Return appropriate code to load up an 8 byte integer or
777 floating point value */
780 output_move_double (operands)
783 enum machine_mode mode = GET_MODE (operands[0]);
784 rtx dst = operands[0];
785 rtx src = operands[1];
787 if (register_operand (dst, mode)
788 && register_operand (src, mode))
790 if (REGNO (src) + 1 == REGNO (dst))
791 return "mov %R1,%R0\n\tmov %1,%0";
793 return "mov %1,%0\n\tmov %R1,%R0";
797 if (GET_CODE (dst) == MEM
798 && ((GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
799 || (GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src))))
800 return "st.w %.,%0\n\tst.w %.,%R0";
802 if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
804 HOST_WIDE_INT high_low[2];
808 if (GET_CODE (src) == CONST_DOUBLE)
809 const_double_split (src, &high_low[1], &high_low[0]);
812 high_low[0] = INTVAL (src);
813 high_low[1] = (INTVAL (src) >= 0) ? 0 : -1;
816 for (i = 0; i < 2; i++)
818 xop[0] = gen_rtx_REG (SImode, REGNO (dst)+i);
819 xop[1] = GEN_INT (high_low[i]);
820 output_asm_insn (output_move_single (xop), xop);
826 if (GET_CODE (src) == MEM)
829 int dreg = REGNO (dst);
830 rtx inside = XEXP (src, 0);
832 if (GET_CODE (inside) == REG)
833 ptrreg = REGNO (inside);
834 else if (GET_CODE (inside) == SUBREG)
835 ptrreg = subreg_regno (inside);
836 else if (GET_CODE (inside) == PLUS)
837 ptrreg = REGNO (XEXP (inside, 0));
838 else if (GET_CODE (inside) == LO_SUM)
839 ptrreg = REGNO (XEXP (inside, 0));
842 return "ld.w %R1,%R0\n\tld.w %1,%0";
845 if (GET_CODE (src) == MEM)
846 return "ld.w %1,%0\n\tld.w %R1,%R0";
848 if (GET_CODE (dst) == MEM)
849 return "st.w %1,%0\n\tst.w %R1,%R0";
851 return "mov %1,%0\n\tmov %R1,%R0";
855 /* Return maximum offset supported for a short EP memory reference of mode
856 MODE and signedness UNSIGNEDP. */
859 ep_memory_offset (mode, unsignedp)
860 enum machine_mode mode;
861 int ATTRIBUTE_UNUSED unsignedp;
868 max_offset = (1 << 7);
872 max_offset = (1 << 8);
877 max_offset = (1 << 8);
887 /* Return true if OP is a valid short EP memory reference */
890 ep_memory_operand (op, mode, unsigned_load)
892 enum machine_mode mode;
899 if (GET_CODE (op) != MEM)
902 max_offset = ep_memory_offset (mode, unsigned_load);
904 mask = GET_MODE_SIZE (mode) - 1;
907 if (GET_CODE (addr) == CONST)
908 addr = XEXP (addr, 0);
910 switch (GET_CODE (addr))
916 return TDA_NAME_P (XSTR (addr, 0));
919 return REGNO (addr) == EP_REGNUM;
922 op0 = XEXP (addr, 0);
923 op1 = XEXP (addr, 1);
924 if (GET_CODE (op1) == CONST_INT
925 && INTVAL (op1) < max_offset
927 && (INTVAL (op1) & mask) == 0)
929 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
932 if (GET_CODE (op0) == SYMBOL_REF && TDA_NAME_P (XSTR (op0, 0)))
941 /* Return true if OP is either a register or 0 */
944 reg_or_0_operand (op, mode)
946 enum machine_mode mode;
948 if (GET_CODE (op) == CONST_INT)
949 return INTVAL (op) == 0;
951 else if (GET_CODE (op) == CONST_DOUBLE)
952 return CONST_DOUBLE_OK_FOR_G (op);
955 return register_operand (op, mode);
958 /* Return true if OP is either a register or a signed five bit integer */
961 reg_or_int5_operand (op, mode)
963 enum machine_mode mode;
965 if (GET_CODE (op) == CONST_INT)
966 return CONST_OK_FOR_J (INTVAL (op));
969 return register_operand (op, mode);
972 /* Return true if OP is a valid call operand. */
975 call_address_operand (op, mode)
977 enum machine_mode ATTRIBUTE_UNUSED mode;
979 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
980 if (TARGET_LONG_CALLS)
981 return GET_CODE (op) == REG;
982 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
986 special_symbolref_operand (op, mode)
988 enum machine_mode ATTRIBUTE_UNUSED mode;
990 if (GET_CODE (op) == SYMBOL_REF)
991 return ENCODED_NAME_P (XSTR (op, 0));
993 else if (GET_CODE (op) == CONST)
994 return (GET_CODE (XEXP (op, 0)) == PLUS
995 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
996 && ENCODED_NAME_P (XSTR (XEXP (XEXP (op, 0), 0), 0))
997 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
998 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))));
1004 movsi_source_operand (op, mode)
1006 enum machine_mode mode;
1008 /* Some constants, as well as symbolic operands
1009 must be done with HIGH & LO_SUM patterns. */
1011 && GET_CODE (op) != HIGH
1012 && GET_CODE (op) != CONSTANT_P_RTX
1013 && !(GET_CODE (op) == CONST_INT
1014 && (CONST_OK_FOR_J (INTVAL (op))
1015 || CONST_OK_FOR_K (INTVAL (op))
1016 || CONST_OK_FOR_L (INTVAL (op)))))
1017 return special_symbolref_operand (op, mode);
1019 return general_operand (op, mode);
1023 power_of_two_operand (op, mode)
1025 enum machine_mode ATTRIBUTE_UNUSED mode;
1027 if (GET_CODE (op) != CONST_INT)
1030 if (exact_log2 (INTVAL (op)) == -1)
1036 not_power_of_two_operand (op, mode)
1038 enum machine_mode mode;
1044 else if (mode == HImode)
1046 else if (mode == SImode)
1051 if (GET_CODE (op) != CONST_INT)
1054 if (exact_log2 (~INTVAL (op) & mask) == -1)
1060 /* Substitute memory references involving a pointer, to use the ep pointer,
1061 taking care to save and preserve the ep. */
1064 substitute_ep_register (first_insn, last_insn, uses, regno, p_r1, p_ep)
1072 rtx reg = gen_rtx_REG (Pmode, regno);
1077 regs_ever_live[1] = 1;
1078 *p_r1 = gen_rtx_REG (Pmode, 1);
1079 *p_ep = gen_rtx_REG (Pmode, 30);
1084 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1085 2 * (uses - 3), uses, reg_names[regno],
1086 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1087 INSN_UID (first_insn), INSN_UID (last_insn));
1089 if (GET_CODE (first_insn) == NOTE)
1090 first_insn = next_nonnote_insn (first_insn);
1092 last_insn = next_nonnote_insn (last_insn);
1093 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1095 if (GET_CODE (insn) == INSN)
1097 rtx pattern = single_set (insn);
1099 /* Replace the memory references. */
1103 /* Memory operands are signed by default. */
1104 int unsignedp = FALSE;
1106 if (GET_CODE (SET_DEST (pattern)) == MEM
1107 && GET_CODE (SET_SRC (pattern)) == MEM)
1110 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1111 p_mem = &SET_DEST (pattern);
1113 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1114 p_mem = &SET_SRC (pattern);
1121 rtx addr = XEXP (*p_mem, 0);
1123 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1124 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1126 else if (GET_CODE (addr) == PLUS
1127 && GET_CODE (XEXP (addr, 0)) == REG
1128 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1129 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1130 && ((INTVAL (XEXP (addr, 1)))
1131 < ep_memory_offset (GET_MODE (*p_mem),
1133 && ((INTVAL (XEXP (addr, 1))) >= 0))
1134 *p_mem = change_address (*p_mem, VOIDmode,
1135 gen_rtx_PLUS (Pmode,
1143 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1144 insn = prev_nonnote_insn (first_insn);
1145 if (insn && GET_CODE (insn) == INSN
1146 && GET_CODE (PATTERN (insn)) == SET
1147 && SET_DEST (PATTERN (insn)) == *p_ep
1148 && SET_SRC (PATTERN (insn)) == *p_r1)
1151 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1153 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1154 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1158 /* In rare cases, correct code generation requires extra machine
1159 dependent processing between the second jump optimization pass and
1160 delayed branch scheduling. On those machines, define this macro
1161 as a C statement to act on the code starting at INSN.
1163 On the 850, we use it to implement the -mep mode to copy heavily used
1164 pointers to ep to use the implicit addressing. */
1166 void v850_reorg (start_insn)
1175 regs[FIRST_PSEUDO_REGISTER];
1184 /* If not ep mode, just return now. */
1188 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1191 regs[i].first_insn = NULL_RTX;
1192 regs[i].last_insn = NULL_RTX;
1195 for (insn = start_insn; insn != NULL_RTX; insn = NEXT_INSN (insn))
1197 switch (GET_CODE (insn))
1199 /* End of basic block */
1206 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1208 if (max_uses < regs[i].uses)
1210 max_uses = regs[i].uses;
1216 substitute_ep_register (regs[max_regno].first_insn,
1217 regs[max_regno].last_insn,
1218 max_uses, max_regno, &r1, &ep);
1222 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1225 regs[i].first_insn = NULL_RTX;
1226 regs[i].last_insn = NULL_RTX;
1234 pattern = single_set (insn);
1236 /* See if there are any memory references we can shorten */
1239 rtx src = SET_SRC (pattern);
1240 rtx dest = SET_DEST (pattern);
1242 /* Memory operands are signed by default. */
1243 int unsignedp = FALSE;
1245 /* We might have (SUBREG (MEM)) here, so just get rid of the
1246 subregs to make this code simpler. It is safe to call
1247 alter_subreg any time after reload. */
1248 if (GET_CODE (dest) == SUBREG)
1249 dest = alter_subreg (dest);
1250 if (GET_CODE (src) == SUBREG)
1251 src = alter_subreg (src);
1253 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1256 else if (GET_CODE (dest) == MEM)
1259 else if (GET_CODE (src) == MEM)
1265 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1268 else if (!use_ep && mem
1269 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1271 rtx addr = XEXP (mem, 0);
1275 if (GET_CODE (addr) == REG)
1278 regno = REGNO (addr);
1281 else if (GET_CODE (addr) == PLUS
1282 && GET_CODE (XEXP (addr, 0)) == REG
1283 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1284 && ((INTVAL (XEXP (addr, 1)))
1285 < ep_memory_offset (GET_MODE (mem), unsignedp))
1286 && ((INTVAL (XEXP (addr, 1))) >= 0))
1289 regno = REGNO (XEXP (addr, 0));
1298 regs[regno].last_insn = insn;
1299 if (!regs[regno].first_insn)
1300 regs[regno].first_insn = insn;
1304 /* Loading up a register in the basic block zaps any savings
1306 if (GET_CODE (dest) == REG)
1308 enum machine_mode mode = GET_MODE (dest);
1312 regno = REGNO (dest);
1313 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1317 /* See if we can use the pointer before this
1322 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1324 if (max_uses < regs[i].uses)
1326 max_uses = regs[i].uses;
1332 && max_regno >= regno
1333 && max_regno < endregno)
1335 substitute_ep_register (regs[max_regno].first_insn,
1336 regs[max_regno].last_insn,
1337 max_uses, max_regno, &r1,
1340 /* Since we made a substitution, zap all remembered
1342 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1345 regs[i].first_insn = NULL_RTX;
1346 regs[i].last_insn = NULL_RTX;
1351 for (i = regno; i < endregno; i++)
1354 regs[i].first_insn = NULL_RTX;
1355 regs[i].last_insn = NULL_RTX;
1364 /* # of registers saved by the interrupt handler. */
1365 #define INTERRUPT_FIXED_NUM 4
1367 /* # of bytes for registers saved by the interrupt handler. */
1368 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1370 /* # of registers saved in register parameter area. */
1371 #define INTERRUPT_REGPARM_NUM 4
1372 /* # of words saved for other registers. */
1373 #define INTERRUPT_ALL_SAVE_NUM \
1374 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1376 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1379 compute_register_save_size (p_reg_saved)
1384 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1385 int call_p = regs_ever_live [LINK_POINTER_REGNUM];
1388 /* Count the return pointer if we need to save it. */
1389 if (profile_flag && !call_p)
1390 regs_ever_live [LINK_POINTER_REGNUM] = call_p = 1;
1392 /* Count space for the register saves. */
1393 if (interrupt_handler)
1395 for (i = 0; i <= 31; i++)
1399 if (regs_ever_live[i] || call_p)
1402 reg_saved |= 1L << i;
1406 /* We don't save/restore r0 or the stack pointer */
1408 case STACK_POINTER_REGNUM:
1411 /* For registers with fixed use, we save them, set them to the
1412 appropriate value, and then restore them.
1413 These registers are handled specially, so don't list them
1414 on the list of registers to save in the prologue. */
1415 case 1: /* temp used to hold ep */
1417 case 10: /* temp used to call interrupt save/restore */
1418 case EP_REGNUM: /* ep */
1425 /* Find the first register that needs to be saved. */
1426 for (i = 0; i <= 31; i++)
1427 if (regs_ever_live[i] && ((! call_used_regs[i])
1428 || i == LINK_POINTER_REGNUM))
1431 /* If it is possible that an out-of-line helper function might be
1432 used to generate the prologue for the current function, then we
1433 need to cover the possibility that such a helper function will
1434 be used, despite the fact that there might be gaps in the list of
1435 registers that need to be saved. To detect this we note that the
1436 helper functions always push at least register r29 if the link
1437 register is not used, and at least registers r27 - r31 if the
1438 link register is used (and provided that the function is not an
1439 interrupt handler). */
1441 if (TARGET_PROLOG_FUNCTION
1442 && (i == 2 || i >= 20)
1443 && regs_ever_live[LINK_POINTER_REGNUM] ? (i < 28) : (i < 30))
1448 reg_saved |= 1L << i;
1453 /* Helper functions save all registers between the starting
1454 register and the last register, regardless of whether they
1455 are actually used by the function or not. */
1456 for (; i <= 29; i++)
1459 reg_saved |= 1L << i;
1462 if (regs_ever_live [LINK_POINTER_REGNUM])
1465 reg_saved |= 1L << LINK_POINTER_REGNUM;
1470 for (; i <= 31; i++)
1471 if (regs_ever_live[i] && ((! call_used_regs[i])
1472 || i == LINK_POINTER_REGNUM))
1475 reg_saved |= 1L << i;
1481 *p_reg_saved = reg_saved;
1487 compute_frame_size (size, p_reg_saved)
1492 + compute_register_save_size (p_reg_saved)
1493 + current_function_outgoing_args_size);
1502 unsigned int size = get_frame_size ();
1503 unsigned int actual_fsize;
1504 unsigned int init_stack_alloc = 0;
1507 unsigned int num_save;
1508 unsigned int default_stack;
1510 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1513 actual_fsize = compute_frame_size (size, ®_saved);
1515 /* Save/setup global registers for interrupt functions right now. */
1516 if (interrupt_handler)
1518 emit_insn (gen_save_interrupt ());
1520 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1522 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1523 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1526 /* Save arg registers to the stack if necessary. */
1527 else if (current_function_anonymous_args)
1529 if (TARGET_PROLOG_FUNCTION)
1531 emit_insn (gen_save_r6_r9 ());
1536 for (i = 6; i < 10; i++)
1538 emit_move_insn (gen_rtx_MEM (SImode,
1539 plus_constant (stack_pointer_rtx,
1541 gen_rtx_REG (SImode, i));
1547 /* Identify all of the saved registers. */
1550 for (i = 1; i < 31; i++)
1552 if (((1L << i) & reg_saved) != 0)
1553 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1556 /* If the return pointer is saved, the helper functions also allocate
1557 16 bytes of stack for arguments to be saved in. */
1558 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1560 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1564 /* See if we have an insn that allocates stack space and saves the particular
1565 registers we want to. */
1566 save_all = NULL_RTX;
1567 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1569 int alloc_stack = (4 * num_save) + default_stack;
1570 int unalloc_stack = actual_fsize - alloc_stack;
1571 int save_func_len = 4;
1572 int save_normal_len;
1575 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1577 /* see if we would have used ep to save the stack */
1578 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1579 save_normal_len = (3 * 2) + (2 * num_save);
1581 save_normal_len = 4 * num_save;
1583 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1585 /* Don't bother checking if we don't actually save any space.
1586 This happens for instance if one register is saved and additional
1587 stack space is allocated. */
1588 if (save_func_len < save_normal_len)
1590 save_all = gen_rtx_PARALLEL
1592 rtvec_alloc (num_save + (TARGET_V850 ? 2 : 1)));
1594 XVECEXP (save_all, 0, 0)
1595 = gen_rtx_SET (VOIDmode,
1597 plus_constant (stack_pointer_rtx, -alloc_stack));
1601 XVECEXP (save_all, 0, num_save+1)
1602 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1605 offset = - default_stack;
1606 for (i = 0; i < num_save; i++)
1608 XVECEXP (save_all, 0, i+1)
1609 = gen_rtx_SET (VOIDmode,
1611 plus_constant (stack_pointer_rtx,
1617 code = recog (save_all, NULL_RTX, NULL);
1620 rtx insn = emit_insn (save_all);
1621 INSN_CODE (insn) = code;
1622 actual_fsize -= alloc_stack;
1626 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1627 save_normal_len - save_func_len,
1628 save_normal_len, save_func_len,
1629 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1632 save_all = NULL_RTX;
1636 /* If no prolog save function is available, store the registers the old
1637 fashioned way (one by one). */
1640 /* Special case interrupt functions that save all registers for a call. */
1641 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1643 emit_insn (gen_save_all_interrupt ());
1647 /* If the stack is too big, allocate it in chunks so we can do the
1648 register saves. We use the register save size so we use the ep
1650 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1651 init_stack_alloc = compute_register_save_size (NULL);
1653 init_stack_alloc = actual_fsize;
1655 /* Save registers at the beginning of the stack frame */
1656 offset = init_stack_alloc - 4;
1658 if (init_stack_alloc)
1659 emit_insn (gen_addsi3 (stack_pointer_rtx,
1661 GEN_INT (-init_stack_alloc)));
1663 /* Save the return pointer first. */
1664 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1666 emit_move_insn (gen_rtx_MEM (SImode,
1667 plus_constant (stack_pointer_rtx,
1669 save_regs[--num_save]);
1673 for (i = 0; i < num_save; i++)
1675 emit_move_insn (gen_rtx_MEM (SImode,
1676 plus_constant (stack_pointer_rtx,
1684 /* Allocate the rest of the stack that was not allocated above (either it is
1685 > 32K or we just called a function to save the registers and needed more
1687 if (actual_fsize > init_stack_alloc)
1689 int diff = actual_fsize - init_stack_alloc;
1690 if (CONST_OK_FOR_K (diff))
1691 emit_insn (gen_addsi3 (stack_pointer_rtx,
1696 rtx reg = gen_rtx_REG (Pmode, 12);
1697 emit_move_insn (reg, GEN_INT (-diff));
1698 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1702 /* If we need a frame pointer, set it up now. */
1703 if (frame_pointer_needed)
1704 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1713 unsigned int size = get_frame_size ();
1715 unsigned int actual_fsize = compute_frame_size (size, ®_saved);
1716 unsigned int init_stack_free = 0;
1717 rtx restore_regs[32];
1719 unsigned int num_restore;
1720 unsigned int default_stack;
1722 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1724 /* Eliminate the initial stack stored by interrupt functions. */
1725 if (interrupt_handler)
1727 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1728 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1729 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1732 /* Cut off any dynamic stack created. */
1733 if (frame_pointer_needed)
1734 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1736 /* Identify all of the saved registers. */
1739 for (i = 1; i < 31; i++)
1741 if (((1L << i) & reg_saved) != 0)
1742 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1745 /* If the return pointer is saved, the helper functions also allocate
1746 16 bytes of stack for arguments to be saved in. */
1747 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1749 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1753 /* See if we have an insn that restores the particular registers we
1755 restore_all = NULL_RTX;
1757 if (TARGET_PROLOG_FUNCTION
1759 && actual_fsize >= default_stack
1760 && !interrupt_handler)
1762 int alloc_stack = (4 * num_restore) + default_stack;
1763 int unalloc_stack = actual_fsize - alloc_stack;
1764 int restore_func_len = 4;
1765 int restore_normal_len;
1768 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1770 /* See if we would have used ep to restore the registers. */
1771 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1772 restore_normal_len = (3 * 2) + (2 * num_restore);
1774 restore_normal_len = 4 * num_restore;
1776 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1778 /* Don't bother checking if we don't actually save any space. */
1779 if (restore_func_len < restore_normal_len)
1781 restore_all = gen_rtx_PARALLEL (VOIDmode,
1782 rtvec_alloc (num_restore + 2));
1783 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1784 XVECEXP (restore_all, 0, 1)
1785 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1786 gen_rtx_PLUS (Pmode,
1788 GEN_INT (alloc_stack)));
1790 offset = alloc_stack - 4;
1791 for (i = 0; i < num_restore; i++)
1793 XVECEXP (restore_all, 0, i+2)
1794 = gen_rtx_SET (VOIDmode,
1797 plus_constant (stack_pointer_rtx,
1802 code = recog (restore_all, NULL_RTX, NULL);
1808 actual_fsize -= alloc_stack;
1811 if (CONST_OK_FOR_K (actual_fsize))
1812 emit_insn (gen_addsi3 (stack_pointer_rtx,
1814 GEN_INT (actual_fsize)));
1817 rtx reg = gen_rtx_REG (Pmode, 12);
1818 emit_move_insn (reg, GEN_INT (actual_fsize));
1819 emit_insn (gen_addsi3 (stack_pointer_rtx,
1825 insn = emit_jump_insn (restore_all);
1826 INSN_CODE (insn) = code;
1830 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1831 restore_normal_len - restore_func_len,
1832 restore_normal_len, restore_func_len,
1833 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1836 restore_all = NULL_RTX;
1840 /* If no epilog save function is available, restore the registers the
1841 old fashioned way (one by one). */
1844 /* If the stack is large, we need to cut it down in 2 pieces. */
1845 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1846 init_stack_free = 4 * num_restore;
1848 init_stack_free = actual_fsize;
1850 /* Deallocate the rest of the stack if it is > 32K. */
1851 if (actual_fsize > init_stack_free)
1855 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1857 if (CONST_OK_FOR_K (diff))
1858 emit_insn (gen_addsi3 (stack_pointer_rtx,
1863 rtx reg = gen_rtx_REG (Pmode, 12);
1864 emit_move_insn (reg, GEN_INT (diff));
1865 emit_insn (gen_addsi3 (stack_pointer_rtx,
1871 /* Special case interrupt functions that save all registers
1873 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1875 emit_insn (gen_restore_all_interrupt ());
1879 /* Restore registers from the beginning of the stack frame. */
1880 offset = init_stack_free - 4;
1882 /* Restore the return pointer first. */
1884 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
1886 emit_move_insn (restore_regs[--num_restore],
1887 gen_rtx_MEM (SImode,
1888 plus_constant (stack_pointer_rtx,
1893 for (i = 0; i < num_restore; i++)
1895 emit_move_insn (restore_regs[i],
1896 gen_rtx_MEM (SImode,
1897 plus_constant (stack_pointer_rtx,
1900 emit_insn (gen_rtx_USE (VOIDmode, restore_regs[i]));
1904 /* Cut back the remainder of the stack. */
1905 if (init_stack_free)
1906 emit_insn (gen_addsi3 (stack_pointer_rtx,
1908 GEN_INT (init_stack_free)));
1911 /* And return or use reti for interrupt handlers. */
1912 if (interrupt_handler)
1913 emit_jump_insn (gen_restore_interrupt ());
1914 else if (actual_fsize)
1915 emit_jump_insn (gen_return_internal ());
1917 emit_jump_insn (gen_return ());
1920 current_function_anonymous_args = 0;
1921 v850_interrupt_cache_p = FALSE;
1922 v850_interrupt_p = FALSE;
1926 /* Update the condition code from the insn. */
1929 notice_update_cc (body, insn)
1933 switch (get_attr_cc (insn))
1936 /* Insn does not affect CC at all. */
1940 /* Insn does not change CC, but the 0'th operand has been changed. */
1941 if (cc_status.value1 != 0
1942 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1943 cc_status.value1 = 0;
1947 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1948 V,C is in an unusable state. */
1950 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1951 cc_status.value1 = recog_data.operand[0];
1955 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1956 C is in an unusable state. */
1958 cc_status.flags |= CC_NO_CARRY;
1959 cc_status.value1 = recog_data.operand[0];
1963 /* The insn is a compare instruction. */
1965 cc_status.value1 = SET_SRC (body);
1969 /* Insn doesn't leave CC in a usable state. */
1975 /* Retrieve the data area that has been chosen for the given decl. */
1978 v850_get_data_area (decl)
1981 if (lookup_attribute ("sda", DECL_MACHINE_ATTRIBUTES (decl)) != NULL_TREE)
1982 return DATA_AREA_SDA;
1984 if (lookup_attribute ("tda", DECL_MACHINE_ATTRIBUTES (decl)) != NULL_TREE)
1985 return DATA_AREA_TDA;
1987 if (lookup_attribute ("zda", DECL_MACHINE_ATTRIBUTES (decl)) != NULL_TREE)
1988 return DATA_AREA_ZDA;
1990 return DATA_AREA_NORMAL;
1993 /* Store the indicated data area in the decl's attributes. */
1996 v850_set_data_area (decl, data_area)
1998 v850_data_area data_area;
2004 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2005 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2006 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2011 DECL_MACHINE_ATTRIBUTES (decl) = tree_cons
2012 (name, NULL, DECL_MACHINE_ATTRIBUTES (decl));
2015 /* Return nonzero if ATTR is a valid attribute for DECL.
2016 ARGS are the arguments supplied with ATTR. */
2019 v850_valid_decl_attribute (decl, unused, attr, args)
2021 tree unused ATTRIBUTE_UNUSED;
2025 v850_data_area data_area;
2026 v850_data_area area;
2028 if (args != NULL_TREE)
2031 if (is_attribute_p ("interrupt_handler", attr)
2032 || is_attribute_p ("interrupt", attr))
2033 return TREE_CODE (decl) == FUNCTION_DECL;
2035 /* Implement data area attribute. */
2036 if (is_attribute_p ("sda", attr))
2037 data_area = DATA_AREA_SDA;
2038 else if (is_attribute_p ("tda", attr))
2039 data_area = DATA_AREA_TDA;
2040 else if (is_attribute_p ("zda", attr))
2041 data_area = DATA_AREA_ZDA;
2045 switch (TREE_CODE (decl))
2048 if (current_function_decl != NULL_TREE)
2049 error_with_decl (decl, "\
2050 a data area attribute cannot be specified for local variables");
2055 area = v850_get_data_area (decl);
2056 if (area != DATA_AREA_NORMAL && data_area != area)
2057 error_with_decl (decl, "\
2058 data area of '%s' conflicts with previous declaration");
2070 /* Return nonzero if FUNC is an interrupt function as specified
2071 by the "interrupt" attribute. */
2074 v850_interrupt_function_p (func)
2080 if (v850_interrupt_cache_p)
2081 return v850_interrupt_p;
2083 if (TREE_CODE (func) != FUNCTION_DECL)
2086 a = lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES (func));
2092 a = lookup_attribute ("interrupt", DECL_MACHINE_ATTRIBUTES (func));
2093 ret = a != NULL_TREE;
2096 /* Its not safe to trust global variables until after function inlining has
2098 if (reload_completed | reload_in_progress)
2099 v850_interrupt_p = ret;
2106 v850_encode_data_area (decl)
2109 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2110 int len = strlen (str);
2113 /* Map explict sections into the appropriate attribute */
2114 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2116 if (DECL_SECTION_NAME (decl))
2118 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2120 if (streq (name, ".zdata") || streq (name, ".zbss"))
2121 v850_set_data_area (decl, DATA_AREA_ZDA);
2123 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2124 v850_set_data_area (decl, DATA_AREA_SDA);
2126 else if (streq (name, ".tdata"))
2127 v850_set_data_area (decl, DATA_AREA_TDA);
2130 /* If no attribute, support -m{zda,sda,tda}=n */
2133 int size = int_size_in_bytes (TREE_TYPE (decl));
2137 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2138 v850_set_data_area (decl, DATA_AREA_TDA);
2140 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2141 v850_set_data_area (decl, DATA_AREA_SDA);
2143 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2144 v850_set_data_area (decl, DATA_AREA_ZDA);
2147 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2151 newstr = alloca (len + 2);
2153 strcpy (newstr + 1, str);
2155 switch (v850_get_data_area (decl))
2157 case DATA_AREA_ZDA: *newstr = ZDA_NAME_FLAG_CHAR; break;
2158 case DATA_AREA_TDA: *newstr = TDA_NAME_FLAG_CHAR; break;
2159 case DATA_AREA_SDA: *newstr = SDA_NAME_FLAG_CHAR; break;
2163 XSTR (XEXP (DECL_RTL (decl), 0), 0) = ggc_alloc_string (newstr, len + 2);
2166 /* Return true if the given RTX is a register which can be restored
2167 by a function epilogue. */
2169 register_is_ok_for_epilogue (op, mode)
2171 enum machine_mode ATTRIBUTE_UNUSED mode;
2173 /* The save/restore routines can only cope with registers 2, and 20 - 31 */
2174 return (GET_CODE (op) == REG)
2175 && (((REGNO (op) >= 20) && REGNO (op) <= 31)
2176 || REGNO (op) == 2);
2179 /* Return non-zero if the given RTX is suitable for collapsing into
2180 jump to a function epilogue. */
2182 pattern_is_ok_for_epilogue (op, mode)
2184 enum machine_mode ATTRIBUTE_UNUSED mode;
2186 int count = XVECLEN (op, 0);
2189 /* If there are no registers to restore then the function epilogue
2194 /* The pattern matching has already established that we are performing a
2195 function epilogue and that we are popping at least one register. We must
2196 now check the remaining entries in the vector to make sure that they are
2197 also register pops. There is no good reason why there should ever be
2198 anything else in this vector, but being paranoid always helps...
2200 The test below performs the C equivalent of this machine description
2203 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2204 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2207 for (i = 3; i < count; i++)
2209 rtx vector_element = XVECEXP (op, 0, i);
2214 if (GET_CODE (vector_element) != SET)
2217 dest = SET_DEST (vector_element);
2218 src = SET_SRC (vector_element);
2220 if (GET_CODE (dest) != REG
2221 || GET_MODE (dest) != SImode
2222 || ! register_is_ok_for_epilogue (dest, SImode)
2223 || GET_CODE (src) != MEM
2224 || GET_MODE (src) != SImode)
2227 plus = XEXP (src, 0);
2229 if (GET_CODE (plus) != PLUS
2230 || GET_CODE (XEXP (plus, 0)) != REG
2231 || GET_MODE (XEXP (plus, 0)) != SImode
2232 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2233 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2240 /* Construct a JR instruction to a routine that will perform the equivalent of
2241 the RTL passed in as an argument. This RTL is a function epilogue that
2242 pops registers off the stack and possibly releases some extra stack space
2243 as well. The code has already verified that the RTL matches these
2246 construct_restore_jr (op)
2249 int count = XVECLEN (op, 0);
2251 unsigned long int mask;
2252 unsigned long int first;
2253 unsigned long int last;
2255 static char buff [100]; /* XXX */
2259 error ("Bogus JR construction: %d\n", count);
2263 /* Work out how many bytes to pop off the stack before retrieving
2265 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2267 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2269 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2272 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2274 /* Each pop will remove 4 bytes from the stack... */
2275 stack_bytes -= (count - 2) * 4;
2277 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2278 if (stack_bytes != 0 && stack_bytes != 16)
2280 error ("Bad amount of stack space removal: %d", stack_bytes);
2284 /* Now compute the bit mask of registers to push. */
2286 for (i = 2; i < count; i++)
2288 rtx vector_element = XVECEXP (op, 0, i);
2290 if (GET_CODE (vector_element) != SET)
2292 if (GET_CODE (SET_DEST (vector_element)) != REG)
2294 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2297 mask |= 1 << REGNO (SET_DEST (vector_element));
2300 /* Scan for the first register to pop. */
2301 for (first = 0; first < 32; first++)
2303 if (mask & (1 << first))
2310 /* Discover the last register to pop. */
2311 if (mask & (1 << LINK_POINTER_REGNUM))
2313 if (stack_bytes != 16)
2316 last = LINK_POINTER_REGNUM;
2320 if (stack_bytes != 0)
2323 if ((mask & (1 << 29)) == 0)
2329 /* Note, it is possible to have gaps in the register mask.
2330 We ignore this here, and generate a JR anyway. We will
2331 be popping more registers than is strictly necessary, but
2332 it does save code space. */
2334 if (TARGET_LONG_CALLS)
2339 sprintf (name, "__return_%s", reg_names [first]);
2341 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2343 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2349 sprintf (buff, "jr __return_%s", reg_names [first]);
2351 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2358 /* Return non-zero if the given RTX is suitable for collapsing into
2359 a jump to a function prologue. */
2361 pattern_is_ok_for_prologue (op, mode)
2363 enum machine_mode ATTRIBUTE_UNUSED mode;
2365 int count = XVECLEN (op, 0);
2369 /* If there are no registers to save then the function prologue
2374 /* The pattern matching has already established that we are adjusting the
2375 stack and pushing at least one register. We must now check that the
2376 remaining entries in the vector to make sure that they are also register
2377 pushes, except for the last entry which should be a CLOBBER of r10.
2379 The test below performs the C equivalent of this machine description
2382 (set (mem:SI (plus:SI (reg:SI 3)
2383 (match_operand:SI 2 "immediate_operand" "i")))
2384 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2388 for (i = 2; i < count - 1; i++)
2394 vector_element = XVECEXP (op, 0, i);
2396 if (GET_CODE (vector_element) != SET)
2399 dest = SET_DEST (vector_element);
2400 src = SET_SRC (vector_element);
2402 if (GET_CODE (dest) != MEM
2403 || GET_MODE (dest) != SImode
2404 || GET_CODE (src) != REG
2405 || GET_MODE (src) != SImode
2406 || ! register_is_ok_for_epilogue (src, SImode))
2409 plus = XEXP (dest, 0);
2411 if ( GET_CODE (plus) != PLUS
2412 || GET_CODE (XEXP (plus, 0)) != REG
2413 || GET_MODE (XEXP (plus, 0)) != SImode
2414 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2415 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2418 /* If the register is being pushed somewhere other than the stack
2419 space just acquired by the first operand then abandon this quest.
2420 Note: the test is <= because both values are negative. */
2421 if (INTVAL (XEXP (plus, 1))
2422 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2428 /* Make sure that the last entry in the vector is a clobber. */
2429 vector_element = XVECEXP (op, 0, i);
2431 if (GET_CODE (vector_element) != CLOBBER
2432 || GET_CODE (XEXP (vector_element, 0)) != REG
2433 || REGNO (XEXP (vector_element, 0)) != 10)
2439 /* Construct a JARL instruction to a routine that will perform the equivalent
2440 of the RTL passed as a parameter. This RTL is a function prologue that
2441 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2442 some stack space as well. The code has already verified that the RTL
2443 matches these requirements. */
2445 construct_save_jarl (op)
2448 int count = XVECLEN (op, 0);
2450 unsigned long int mask;
2451 unsigned long int first;
2452 unsigned long int last;
2454 static char buff [100]; /* XXX */
2458 error ("Bogus JARL construction: %d\n", count);
2463 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2465 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2467 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2469 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2472 /* Work out how many bytes to push onto the stack after storing the
2474 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2476 /* Each push will put 4 bytes from the stack... */
2477 stack_bytes += (count - 2) * 4;
2479 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2480 if (stack_bytes != 0 && stack_bytes != -16)
2482 error ("Bad amount of stack space removal: %d", stack_bytes);
2486 /* Now compute the bit mask of registers to push. */
2488 for (i = 1; i < count - 1; i++)
2490 rtx vector_element = XVECEXP (op, 0, i);
2492 if (GET_CODE (vector_element) != SET)
2494 if (GET_CODE (SET_SRC (vector_element)) != REG)
2496 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2499 mask |= 1 << REGNO (SET_SRC (vector_element));
2502 /* Scan for the first register to push. */
2503 for (first = 0; first < 32; first++)
2505 if (mask & (1 << first))
2512 /* Discover the last register to push. */
2513 if (mask & (1 << LINK_POINTER_REGNUM))
2515 if (stack_bytes != -16)
2518 last = LINK_POINTER_REGNUM;
2522 if (stack_bytes != 0)
2524 if ((mask & (1 << 29)) == 0)
2530 /* Note, it is possible to have gaps in the register mask.
2531 We ignore this here, and generate a JARL anyway. We will
2532 be pushing more registers than is strictly necessary, but
2533 it does save code space. */
2535 if (TARGET_LONG_CALLS)
2540 sprintf (name, "__save_%s", reg_names [first]);
2542 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2544 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2550 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2552 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2559 extern tree last_assemble_variable_decl;
2560 extern int size_directive_output;
2562 /* A version of asm_output_aligned_bss() that copes with the special
2563 data areas of the v850. */
2565 v850_output_aligned_bss (file, decl, name, size, align)
2572 ASM_GLOBALIZE_LABEL (file, name);
2574 switch (v850_get_data_area (decl))
2592 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2593 #ifdef ASM_DECLARE_OBJECT_NAME
2594 last_assemble_variable_decl = decl;
2595 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2597 /* Standard thing is just output label for the object. */
2598 ASM_OUTPUT_LABEL (file, name);
2599 #endif /* ASM_DECLARE_OBJECT_NAME */
2600 ASM_OUTPUT_SKIP (file, size ? size : 1);
2603 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2605 v850_output_common (file, decl, name, size, align)
2612 if (decl == NULL_TREE)
2614 fprintf (file, "%s", COMMON_ASM_OP);
2618 switch (v850_get_data_area (decl))
2621 fprintf (file, "%s", ZCOMMON_ASM_OP);
2625 fprintf (file, "%s", SCOMMON_ASM_OP);
2629 fprintf (file, "%s", TCOMMON_ASM_OP);
2633 fprintf (file, "%s", COMMON_ASM_OP);
2638 assemble_name (file, name);
2639 fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2642 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2644 v850_output_local (file, decl, name, size, align)
2651 fprintf (file, "%s", LOCAL_ASM_OP);
2652 assemble_name (file, name);
2653 fprintf (file, "\n");
2655 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2658 /* Add data area to the given declaration if a ghs data area pragma is
2659 currently in effect (#pragma ghs startXXX/endXXX). */
2661 v850_insert_attributes (decl, attr_ptr)
2663 tree *attr_ptr ATTRIBUTE_UNUSED;
2666 && data_area_stack->data_area
2667 && current_function_decl == NULL_TREE
2668 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2669 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2670 v850_set_data_area (decl, data_area_stack->data_area);
2672 /* Initialise the default names of the v850 specific sections,
2673 if this has not been done before. */
2675 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2677 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2678 = build_string (sizeof (".sdata")-1, ".sdata");
2680 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2681 = build_string (sizeof (".rosdata")-1, ".rosdata");
2683 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2684 = build_string (sizeof (".tdata")-1, ".tdata");
2686 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2687 = build_string (sizeof (".zdata")-1, ".zdata");
2689 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2690 = build_string (sizeof (".rozdata")-1, ".rozdata");
2693 if (current_function_decl == NULL_TREE
2694 && (TREE_CODE (decl) == VAR_DECL
2695 || TREE_CODE (decl) == CONST_DECL
2696 || TREE_CODE (decl) == FUNCTION_DECL)
2697 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2698 && !DECL_SECTION_NAME (decl))
2700 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2701 tree chosen_section;
2703 if (TREE_CODE (decl) == FUNCTION_DECL)
2704 kind = GHS_SECTION_KIND_TEXT;
2707 /* First choose a section kind based on the data area of the decl. */
2708 switch (v850_get_data_area (decl))
2714 kind = ((TREE_READONLY (decl))
2715 ? GHS_SECTION_KIND_ROSDATA
2716 : GHS_SECTION_KIND_SDATA);
2720 kind = GHS_SECTION_KIND_TDATA;
2724 kind = ((TREE_READONLY (decl))
2725 ? GHS_SECTION_KIND_ROZDATA
2726 : GHS_SECTION_KIND_ZDATA);
2729 case DATA_AREA_NORMAL: /* default data area */
2730 if (TREE_READONLY (decl))
2731 kind = GHS_SECTION_KIND_RODATA;
2732 else if (DECL_INITIAL (decl))
2733 kind = GHS_SECTION_KIND_DATA;
2735 kind = GHS_SECTION_KIND_BSS;
2739 /* Now, if the section kind has been explicitly renamed,
2740 then attach a section attribute. */
2741 chosen_section = GHS_current_section_names [(int) kind];
2743 /* Otherwise, if this kind of section needs an explicit section
2744 attribute, then also attach one. */
2745 if (chosen_section == NULL)
2746 chosen_section = GHS_default_section_names [(int) kind];
2750 /* Only set the section name if specified by a pragma, because
2751 otherwise it will force those variables to get allocated storage
2752 in this module, rather than by the linker. */
2753 DECL_SECTION_NAME (decl) = chosen_section;
2758 /* Implement `va_arg'. */
2761 v850_va_arg (valist, type)
2764 HOST_WIDE_INT size, rsize;
2769 /* Round up sizeof(type) to a word. */
2770 size = int_size_in_bytes (type);
2771 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
2776 size = rsize = UNITS_PER_WORD;
2780 addr = save_expr (valist);
2781 incr = fold (build (PLUS_EXPR, ptr_type_node, valist,
2782 build_int_2 (rsize, 0)));
2784 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
2785 TREE_SIDE_EFFECTS (incr) = 1;
2786 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
2788 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
2792 addr_rtx = force_reg (Pmode, addr_rtx);
2793 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
2794 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
2800 /* Return an RTX indicating where the return address to the
2801 calling function can be found. */
2804 v850_return_addr (count)
2810 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);