1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
34 #include "insn-attr.h"
41 #include "integrate.h"
44 #include "target-def.h"
48 #define streq(a,b) (strcmp (a, b) == 0)
51 /* Function prototypes for stupid compilers: */
52 static bool v850_handle_option (size_t, const char *, int);
53 static void const_double_split (rtx, HOST_WIDE_INT *, HOST_WIDE_INT *);
54 static int const_costs_int (HOST_WIDE_INT, int);
55 static int const_costs (rtx, enum rtx_code);
56 static bool v850_rtx_costs (rtx, int, int, int *, bool);
57 static void substitute_ep_register (rtx, rtx, int, int, rtx *, rtx *);
58 static void v850_reorg (void);
59 static int ep_memory_offset (enum machine_mode, int);
60 static void v850_set_data_area (tree, v850_data_area);
61 static tree v850_handle_interrupt_attribute (tree *, tree, tree, int, bool *);
62 static tree v850_handle_data_area_attribute (tree *, tree, tree, int, bool *);
63 static void v850_insert_attributes (tree, tree *);
64 static void v850_asm_init_sections (void);
65 static section *v850_select_section (tree, int, unsigned HOST_WIDE_INT);
66 static void v850_encode_data_area (tree, rtx);
67 static void v850_encode_section_info (tree, rtx, int);
68 static bool v850_return_in_memory (const_tree, const_tree);
69 static rtx v850_function_value (const_tree, const_tree, bool);
70 static void v850_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
72 static bool v850_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
74 static int v850_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
76 static bool v850_can_eliminate (const int, const int);
77 static void v850_asm_trampoline_template (FILE *);
78 static void v850_trampoline_init (rtx, tree, rtx);
80 /* Information about the various small memory areas. */
81 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
83 /* name max physical max */
89 /* Names of the various data areas used on the v850. */
90 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
91 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
93 /* Track the current data area set by the data area pragma (which
94 can be nested). Tested by check_default_data_area. */
95 data_area_stack_element * data_area_stack = NULL;
97 /* True if we don't need to check any more if the current
98 function is an interrupt handler. */
99 static int v850_interrupt_cache_p = FALSE;
101 /* Whether current function is an interrupt handler. */
102 static int v850_interrupt_p = FALSE;
104 static GTY(()) section *rosdata_section;
105 static GTY(()) section *rozdata_section;
106 static GTY(()) section *tdata_section;
107 static GTY(()) section *zdata_section;
108 static GTY(()) section *zbss_section;
110 /* V850 specific attributes. */
112 static const struct attribute_spec v850_attribute_table[] =
114 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
115 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute },
116 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute },
117 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute },
118 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute },
119 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute },
120 { NULL, 0, 0, false, false, false, NULL }
124 /* Initialize the GCC target structure. */
125 #undef TARGET_ASM_ALIGNED_HI_OP
126 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
128 #undef TARGET_ATTRIBUTE_TABLE
129 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
131 #undef TARGET_INSERT_ATTRIBUTES
132 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
134 #undef TARGET_ASM_SELECT_SECTION
135 #define TARGET_ASM_SELECT_SECTION v850_select_section
137 /* The assembler supports switchable .bss sections, but
138 v850_select_section doesn't yet make use of them. */
139 #undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
140 #define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS false
142 #undef TARGET_ENCODE_SECTION_INFO
143 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
145 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
146 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
148 #undef TARGET_DEFAULT_TARGET_FLAGS
149 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_DEFAULT | MASK_APP_REGS)
150 #undef TARGET_HANDLE_OPTION
151 #define TARGET_HANDLE_OPTION v850_handle_option
153 #undef TARGET_RTX_COSTS
154 #define TARGET_RTX_COSTS v850_rtx_costs
156 #undef TARGET_ADDRESS_COST
157 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
159 #undef TARGET_MACHINE_DEPENDENT_REORG
160 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
162 #undef TARGET_PROMOTE_PROTOTYPES
163 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
165 #undef TARGET_RETURN_IN_MEMORY
166 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
168 #undef TARGET_FUNCTION_VALUE
169 #define TARGET_FUNCTION_VALUE v850_function_value
171 #undef TARGET_PASS_BY_REFERENCE
172 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
174 #undef TARGET_CALLEE_COPIES
175 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
177 #undef TARGET_SETUP_INCOMING_VARARGS
178 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
180 #undef TARGET_ARG_PARTIAL_BYTES
181 #define TARGET_ARG_PARTIAL_BYTES v850_arg_partial_bytes
183 #undef TARGET_CAN_ELIMINATE
184 #define TARGET_CAN_ELIMINATE v850_can_eliminate
186 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
187 #define TARGET_ASM_TRAMPOLINE_TEMPLATE v850_asm_trampoline_template
188 #undef TARGET_TRAMPOLINE_INIT
189 #define TARGET_TRAMPOLINE_INIT v850_trampoline_init
191 struct gcc_target targetm = TARGET_INITIALIZER;
193 /* Set the maximum size of small memory area TYPE to the value given
194 by VALUE. Return true if VALUE was syntactically correct. VALUE
195 starts with the argument separator: either "-" or "=". */
198 v850_handle_memory_option (enum small_memory_type type, const char *value)
202 if (*value != '-' && *value != '=')
206 for (i = 0; value[i]; i++)
207 if (!ISDIGIT (value[i]))
211 if (size > small_memory[type].physical_max)
212 error ("value passed to %<-m%s%> is too large", small_memory[type].name);
214 small_memory[type].max = size;
218 /* Implement TARGET_HANDLE_OPTION. */
221 v850_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
226 target_flags |= MASK_EP | MASK_PROLOG_FUNCTION;
230 target_flags &= ~(MASK_CPU ^ MASK_V850);
235 target_flags &= ~(MASK_CPU ^ MASK_V850E);
239 return v850_handle_memory_option (SMALL_MEMORY_TDA, arg);
242 return v850_handle_memory_option (SMALL_MEMORY_SDA, arg);
245 return v850_handle_memory_option (SMALL_MEMORY_ZDA, arg);
253 v850_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
254 enum machine_mode mode, const_tree type,
255 bool named ATTRIBUTE_UNUSED)
257 unsigned HOST_WIDE_INT size;
260 size = int_size_in_bytes (type);
262 size = GET_MODE_SIZE (mode);
267 /* Return an RTX to represent where an argument with mode MODE
268 and type TYPE will be passed to a function. If the result
269 is NULL_RTX, the argument will be pushed. */
272 function_arg (CUMULATIVE_ARGS * cum,
273 enum machine_mode mode,
277 rtx result = NULL_RTX;
280 if (TARGET_GHS && !named)
284 size = int_size_in_bytes (type);
286 size = GET_MODE_SIZE (mode);
290 /* Once we have stopped using argument registers, do not start up again. */
291 cum->nbytes = 4 * UNITS_PER_WORD;
296 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
300 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
302 if (cum->nbytes > 4 * UNITS_PER_WORD)
305 if (type == NULL_TREE
306 && cum->nbytes + size > 4 * UNITS_PER_WORD)
309 switch (cum->nbytes / UNITS_PER_WORD)
312 result = gen_rtx_REG (mode, 6);
315 result = gen_rtx_REG (mode, 7);
318 result = gen_rtx_REG (mode, 8);
321 result = gen_rtx_REG (mode, 9);
331 /* Return the number of bytes which must be put into registers
332 for values which are part in registers and part in memory. */
335 v850_arg_partial_bytes (CUMULATIVE_ARGS * cum, enum machine_mode mode,
336 tree type, bool named)
340 if (TARGET_GHS && !named)
344 size = int_size_in_bytes (type);
346 size = GET_MODE_SIZE (mode);
352 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
356 cum->nbytes = (cum->nbytes + align - 1) & ~ (align - 1);
358 if (cum->nbytes > 4 * UNITS_PER_WORD)
361 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
364 if (type == NULL_TREE
365 && cum->nbytes + size > 4 * UNITS_PER_WORD)
368 return 4 * UNITS_PER_WORD - cum->nbytes;
372 /* Return the high and low words of a CONST_DOUBLE */
375 const_double_split (rtx x, HOST_WIDE_INT * p_high, HOST_WIDE_INT * p_low)
377 if (GET_CODE (x) == CONST_DOUBLE)
382 switch (GET_MODE (x))
385 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
386 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
387 *p_high = t[1]; /* since v850 is little endian */
388 *p_low = t[0]; /* high is second word */
392 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
393 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
399 *p_high = CONST_DOUBLE_HIGH (x);
400 *p_low = CONST_DOUBLE_LOW (x);
408 fatal_insn ("const_double_split got a bad insn:", x);
412 /* Return the cost of the rtx R with code CODE. */
415 const_costs_int (HOST_WIDE_INT value, int zero_cost)
417 if (CONST_OK_FOR_I (value))
419 else if (CONST_OK_FOR_J (value))
421 else if (CONST_OK_FOR_K (value))
428 const_costs (rtx r, enum rtx_code c)
430 HOST_WIDE_INT high, low;
435 return const_costs_int (INTVAL (r), 0);
438 const_double_split (r, &high, &low);
439 if (GET_MODE (r) == SFmode)
440 return const_costs_int (high, 1);
442 return const_costs_int (high, 1) + const_costs_int (low, 1);
458 v850_rtx_costs (rtx x,
460 int outer_code ATTRIBUTE_UNUSED,
461 int * total, bool speed)
463 enum rtx_code code = (enum rtx_code) codearg;
472 *total = COSTS_N_INSNS (const_costs (x, code));
479 if (TARGET_V850E && !speed)
487 && ( GET_MODE (x) == SImode
488 || GET_MODE (x) == HImode
489 || GET_MODE (x) == QImode))
491 if (GET_CODE (XEXP (x, 1)) == REG)
493 else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
495 if (CONST_OK_FOR_O (INTVAL (XEXP (x, 1))))
497 else if (CONST_OK_FOR_K (INTVAL (XEXP (x, 1))))
506 if (outer_code == COMPARE)
515 /* Print operand X using operand code CODE to assembly language output file
519 print_operand (FILE * file, rtx x, int code)
521 HOST_WIDE_INT high, low;
526 /* We use 'c' operands with symbols for .vtinherit */
527 if (GET_CODE (x) == SYMBOL_REF)
529 output_addr_const(file, x);
536 switch ((code == 'B' || code == 'C')
537 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
540 if (code == 'c' || code == 'C')
541 fprintf (file, "nz");
543 fprintf (file, "ne");
546 if (code == 'c' || code == 'C')
552 fprintf (file, "ge");
555 fprintf (file, "gt");
558 fprintf (file, "le");
561 fprintf (file, "lt");
564 fprintf (file, "nl");
570 fprintf (file, "nh");
579 case 'F': /* high word of CONST_DOUBLE */
580 switch (GET_CODE (x))
583 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
587 const_double_split (x, &high, &low);
588 fprintf (file, "%ld", (long) high);
595 case 'G': /* low word of CONST_DOUBLE */
596 switch (GET_CODE (x))
599 fprintf (file, "%ld", (long) INTVAL (x));
603 const_double_split (x, &high, &low);
604 fprintf (file, "%ld", (long) low);
612 fprintf (file, "%d\n", (int)(INTVAL (x) & 0xffff));
615 fprintf (file, "%d", exact_log2 (INTVAL (x)));
618 gcc_assert (special_symbolref_operand (x, VOIDmode));
620 if (GET_CODE (x) == CONST)
621 x = XEXP (XEXP (x, 0), 0);
623 gcc_assert (GET_CODE (x) == SYMBOL_REF);
625 if (SYMBOL_REF_ZDA_P (x))
626 fprintf (file, "zdaoff");
627 else if (SYMBOL_REF_SDA_P (x))
628 fprintf (file, "sdaoff");
629 else if (SYMBOL_REF_TDA_P (x))
630 fprintf (file, "tdaoff");
635 gcc_assert (special_symbolref_operand (x, VOIDmode));
636 output_addr_const (file, x);
639 gcc_assert (special_symbolref_operand (x, VOIDmode));
641 if (GET_CODE (x) == CONST)
642 x = XEXP (XEXP (x, 0), 0);
644 gcc_assert (GET_CODE (x) == SYMBOL_REF);
646 if (SYMBOL_REF_ZDA_P (x))
647 fprintf (file, "r0");
648 else if (SYMBOL_REF_SDA_P (x))
649 fprintf (file, "gp");
650 else if (SYMBOL_REF_TDA_P (x))
651 fprintf (file, "ep");
655 case 'R': /* 2nd word of a double. */
656 switch (GET_CODE (x))
659 fprintf (file, reg_names[REGNO (x) + 1]);
662 x = XEXP (adjust_address (x, SImode, 4), 0);
663 print_operand_address (file, x);
664 if (GET_CODE (x) == CONST_INT)
665 fprintf (file, "[r0]");
674 /* If it's a reference to a TDA variable, use sst/sld vs. st/ld. */
675 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
682 /* Like an 'S' operand above, but for unsigned loads only. */
683 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
688 case 'W': /* print the instruction suffix */
689 switch (GET_MODE (x))
694 case QImode: fputs (".b", file); break;
695 case HImode: fputs (".h", file); break;
696 case SImode: fputs (".w", file); break;
697 case SFmode: fputs (".w", file); break;
700 case '.': /* register r0 */
701 fputs (reg_names[0], file);
703 case 'z': /* reg or zero */
704 if (GET_CODE (x) == REG)
705 fputs (reg_names[REGNO (x)], file);
708 gcc_assert (x == const0_rtx);
709 fputs (reg_names[0], file);
713 switch (GET_CODE (x))
716 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
717 output_address (gen_rtx_PLUS (SImode, gen_rtx_REG (SImode, 0),
720 output_address (XEXP (x, 0));
724 fputs (reg_names[REGNO (x)], file);
727 fputs (reg_names[subreg_regno (x)], file);
734 print_operand_address (file, x);
745 /* Output assembly language output for the address ADDR to FILE. */
748 print_operand_address (FILE * file, rtx addr)
750 switch (GET_CODE (addr))
753 fprintf (file, "0[");
754 print_operand (file, addr, 0);
758 if (GET_CODE (XEXP (addr, 0)) == REG)
761 fprintf (file, "lo(");
762 print_operand (file, XEXP (addr, 1), 0);
763 fprintf (file, ")[");
764 print_operand (file, XEXP (addr, 0), 0);
769 if (GET_CODE (XEXP (addr, 0)) == REG
770 || GET_CODE (XEXP (addr, 0)) == SUBREG)
773 print_operand (file, XEXP (addr, 1), 0);
775 print_operand (file, XEXP (addr, 0), 0);
780 print_operand (file, XEXP (addr, 0), 0);
782 print_operand (file, XEXP (addr, 1), 0);
787 const char *off_name = NULL;
788 const char *reg_name = NULL;
790 if (SYMBOL_REF_ZDA_P (addr))
795 else if (SYMBOL_REF_SDA_P (addr))
800 else if (SYMBOL_REF_TDA_P (addr))
807 fprintf (file, "%s(", off_name);
808 output_addr_const (file, addr);
810 fprintf (file, ")[%s]", reg_name);
814 if (special_symbolref_operand (addr, VOIDmode))
816 rtx x = XEXP (XEXP (addr, 0), 0);
817 const char *off_name;
818 const char *reg_name;
820 if (SYMBOL_REF_ZDA_P (x))
825 else if (SYMBOL_REF_SDA_P (x))
830 else if (SYMBOL_REF_TDA_P (x))
838 fprintf (file, "%s(", off_name);
839 output_addr_const (file, addr);
840 fprintf (file, ")[%s]", reg_name);
843 output_addr_const (file, addr);
846 output_addr_const (file, addr);
851 /* When assemble_integer is used to emit the offsets for a switch
852 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
853 output_addr_const will normally barf at this, but it is OK to omit
854 the truncate and just emit the difference of the two labels. The
855 .hword directive will automatically handle the truncation for us.
857 Returns 1 if rtx was handled, 0 otherwise. */
860 v850_output_addr_const_extra (FILE * file, rtx x)
862 if (GET_CODE (x) != TRUNCATE)
867 /* We must also handle the case where the switch table was passed a
868 constant value and so has been collapsed. In this case the first
869 label will have been deleted. In such a case it is OK to emit
870 nothing, since the table will not be used.
871 (cf gcc.c-torture/compile/990801-1.c). */
872 if (GET_CODE (x) == MINUS
873 && GET_CODE (XEXP (x, 0)) == LABEL_REF
874 && GET_CODE (XEXP (XEXP (x, 0), 0)) == CODE_LABEL
875 && INSN_DELETED_P (XEXP (XEXP (x, 0), 0)))
878 output_addr_const (file, x);
882 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
886 output_move_single (rtx * operands)
888 rtx dst = operands[0];
889 rtx src = operands[1];
896 else if (GET_CODE (src) == CONST_INT)
898 HOST_WIDE_INT value = INTVAL (src);
900 if (CONST_OK_FOR_J (value)) /* Signed 5-bit immediate. */
903 else if (CONST_OK_FOR_K (value)) /* Signed 16-bit immediate. */
904 return "movea lo(%1),%.,%0";
906 else if (CONST_OK_FOR_L (value)) /* Upper 16 bits were set. */
907 return "movhi hi(%1),%.,%0";
909 /* A random constant. */
910 else if (TARGET_V850E)
913 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
916 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
918 HOST_WIDE_INT high, low;
920 const_double_split (src, &high, &low);
922 if (CONST_OK_FOR_J (high)) /* Signed 5-bit immediate. */
925 else if (CONST_OK_FOR_K (high)) /* Signed 16-bit immediate. */
926 return "movea lo(%F1),%.,%0";
928 else if (CONST_OK_FOR_L (high)) /* Upper 16 bits were set. */
929 return "movhi hi(%F1),%.,%0";
931 /* A random constant. */
932 else if (TARGET_V850E)
936 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
939 else if (GET_CODE (src) == MEM)
940 return "%S1ld%W1 %1,%0";
942 else if (special_symbolref_operand (src, VOIDmode))
943 return "movea %O1(%P1),%Q1,%0";
945 else if (GET_CODE (src) == LABEL_REF
946 || GET_CODE (src) == SYMBOL_REF
947 || GET_CODE (src) == CONST)
950 return "mov hilo(%1),%0";
952 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
955 else if (GET_CODE (src) == HIGH)
956 return "movhi hi(%1),%.,%0";
958 else if (GET_CODE (src) == LO_SUM)
960 operands[2] = XEXP (src, 0);
961 operands[3] = XEXP (src, 1);
962 return "movea lo(%3),%2,%0";
966 else if (GET_CODE (dst) == MEM)
969 return "%S0st%W0 %1,%0";
971 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
972 return "%S0st%W0 %.,%0";
974 else if (GET_CODE (src) == CONST_DOUBLE
975 && CONST0_RTX (GET_MODE (dst)) == src)
976 return "%S0st%W0 %.,%0";
979 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
984 /* Return maximum offset supported for a short EP memory reference of mode
985 MODE and signedness UNSIGNEDP. */
988 ep_memory_offset (enum machine_mode mode, int unsignedp ATTRIBUTE_UNUSED)
995 if (TARGET_SMALL_SLD)
996 max_offset = (1 << 4);
997 else if (TARGET_V850E
998 && ( ( unsignedp && ! TARGET_US_BIT_SET)
999 || (! unsignedp && TARGET_US_BIT_SET)))
1000 max_offset = (1 << 4);
1002 max_offset = (1 << 7);
1006 if (TARGET_SMALL_SLD)
1007 max_offset = (1 << 5);
1008 else if (TARGET_V850E
1009 && ( ( unsignedp && ! TARGET_US_BIT_SET)
1010 || (! unsignedp && TARGET_US_BIT_SET)))
1011 max_offset = (1 << 5);
1013 max_offset = (1 << 8);
1018 max_offset = (1 << 8);
1028 /* Return true if OP is a valid short EP memory reference */
1031 ep_memory_operand (rtx op, enum machine_mode mode, int unsigned_load)
1037 /* If we are not using the EP register on a per-function basis
1038 then do not allow this optimization at all. This is to
1039 prevent the use of the SLD/SST instructions which cannot be
1040 guaranteed to work properly due to a hardware bug. */
1044 if (GET_CODE (op) != MEM)
1047 max_offset = ep_memory_offset (mode, unsigned_load);
1049 mask = GET_MODE_SIZE (mode) - 1;
1051 addr = XEXP (op, 0);
1052 if (GET_CODE (addr) == CONST)
1053 addr = XEXP (addr, 0);
1055 switch (GET_CODE (addr))
1061 return SYMBOL_REF_TDA_P (addr);
1064 return REGNO (addr) == EP_REGNUM;
1067 op0 = XEXP (addr, 0);
1068 op1 = XEXP (addr, 1);
1069 if (GET_CODE (op1) == CONST_INT
1070 && INTVAL (op1) < max_offset
1071 && INTVAL (op1) >= 0
1072 && (INTVAL (op1) & mask) == 0)
1074 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
1077 if (GET_CODE (op0) == SYMBOL_REF && SYMBOL_REF_TDA_P (op0))
1086 /* Substitute memory references involving a pointer, to use the ep pointer,
1087 taking care to save and preserve the ep. */
1090 substitute_ep_register (rtx first_insn,
1097 rtx reg = gen_rtx_REG (Pmode, regno);
1102 df_set_regs_ever_live (1, true);
1103 *p_r1 = gen_rtx_REG (Pmode, 1);
1104 *p_ep = gen_rtx_REG (Pmode, 30);
1109 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1110 2 * (uses - 3), uses, reg_names[regno],
1111 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1112 INSN_UID (first_insn), INSN_UID (last_insn));
1114 if (GET_CODE (first_insn) == NOTE)
1115 first_insn = next_nonnote_insn (first_insn);
1117 last_insn = next_nonnote_insn (last_insn);
1118 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1120 if (GET_CODE (insn) == INSN)
1122 rtx pattern = single_set (insn);
1124 /* Replace the memory references. */
1128 /* Memory operands are signed by default. */
1129 int unsignedp = FALSE;
1131 if (GET_CODE (SET_DEST (pattern)) == MEM
1132 && GET_CODE (SET_SRC (pattern)) == MEM)
1135 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1136 p_mem = &SET_DEST (pattern);
1138 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1139 p_mem = &SET_SRC (pattern);
1141 else if (GET_CODE (SET_SRC (pattern)) == SIGN_EXTEND
1142 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1143 p_mem = &XEXP (SET_SRC (pattern), 0);
1145 else if (GET_CODE (SET_SRC (pattern)) == ZERO_EXTEND
1146 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1148 p_mem = &XEXP (SET_SRC (pattern), 0);
1156 rtx addr = XEXP (*p_mem, 0);
1158 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1159 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1161 else if (GET_CODE (addr) == PLUS
1162 && GET_CODE (XEXP (addr, 0)) == REG
1163 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1164 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1165 && ((INTVAL (XEXP (addr, 1)))
1166 < ep_memory_offset (GET_MODE (*p_mem),
1168 && ((INTVAL (XEXP (addr, 1))) >= 0))
1169 *p_mem = change_address (*p_mem, VOIDmode,
1170 gen_rtx_PLUS (Pmode,
1178 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1179 insn = prev_nonnote_insn (first_insn);
1180 if (insn && GET_CODE (insn) == INSN
1181 && GET_CODE (PATTERN (insn)) == SET
1182 && SET_DEST (PATTERN (insn)) == *p_ep
1183 && SET_SRC (PATTERN (insn)) == *p_r1)
1186 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1188 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1189 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1193 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1194 the -mep mode to copy heavily used pointers to ep to use the implicit
1206 regs[FIRST_PSEUDO_REGISTER];
1215 /* If not ep mode, just return now. */
1219 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1222 regs[i].first_insn = NULL_RTX;
1223 regs[i].last_insn = NULL_RTX;
1226 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
1228 switch (GET_CODE (insn))
1230 /* End of basic block */
1237 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1239 if (max_uses < regs[i].uses)
1241 max_uses = regs[i].uses;
1247 substitute_ep_register (regs[max_regno].first_insn,
1248 regs[max_regno].last_insn,
1249 max_uses, max_regno, &r1, &ep);
1253 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1256 regs[i].first_insn = NULL_RTX;
1257 regs[i].last_insn = NULL_RTX;
1265 pattern = single_set (insn);
1267 /* See if there are any memory references we can shorten */
1270 rtx src = SET_SRC (pattern);
1271 rtx dest = SET_DEST (pattern);
1273 /* Memory operands are signed by default. */
1274 int unsignedp = FALSE;
1276 /* We might have (SUBREG (MEM)) here, so just get rid of the
1277 subregs to make this code simpler. */
1278 if (GET_CODE (dest) == SUBREG
1279 && (GET_CODE (SUBREG_REG (dest)) == MEM
1280 || GET_CODE (SUBREG_REG (dest)) == REG))
1281 alter_subreg (&dest);
1282 if (GET_CODE (src) == SUBREG
1283 && (GET_CODE (SUBREG_REG (src)) == MEM
1284 || GET_CODE (SUBREG_REG (src)) == REG))
1285 alter_subreg (&src);
1287 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1290 else if (GET_CODE (dest) == MEM)
1293 else if (GET_CODE (src) == MEM)
1296 else if (GET_CODE (src) == SIGN_EXTEND
1297 && GET_CODE (XEXP (src, 0)) == MEM)
1298 mem = XEXP (src, 0);
1300 else if (GET_CODE (src) == ZERO_EXTEND
1301 && GET_CODE (XEXP (src, 0)) == MEM)
1303 mem = XEXP (src, 0);
1309 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1312 else if (!use_ep && mem
1313 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1315 rtx addr = XEXP (mem, 0);
1319 if (GET_CODE (addr) == REG)
1322 regno = REGNO (addr);
1325 else if (GET_CODE (addr) == PLUS
1326 && GET_CODE (XEXP (addr, 0)) == REG
1327 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1328 && ((INTVAL (XEXP (addr, 1)))
1329 < ep_memory_offset (GET_MODE (mem), unsignedp))
1330 && ((INTVAL (XEXP (addr, 1))) >= 0))
1333 regno = REGNO (XEXP (addr, 0));
1342 regs[regno].last_insn = insn;
1343 if (!regs[regno].first_insn)
1344 regs[regno].first_insn = insn;
1348 /* Loading up a register in the basic block zaps any savings
1350 if (GET_CODE (dest) == REG)
1352 enum machine_mode mode = GET_MODE (dest);
1356 regno = REGNO (dest);
1357 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1361 /* See if we can use the pointer before this
1366 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1368 if (max_uses < regs[i].uses)
1370 max_uses = regs[i].uses;
1376 && max_regno >= regno
1377 && max_regno < endregno)
1379 substitute_ep_register (regs[max_regno].first_insn,
1380 regs[max_regno].last_insn,
1381 max_uses, max_regno, &r1,
1384 /* Since we made a substitution, zap all remembered
1386 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1389 regs[i].first_insn = NULL_RTX;
1390 regs[i].last_insn = NULL_RTX;
1395 for (i = regno; i < endregno; i++)
1398 regs[i].first_insn = NULL_RTX;
1399 regs[i].last_insn = NULL_RTX;
1408 /* # of registers saved by the interrupt handler. */
1409 #define INTERRUPT_FIXED_NUM 4
1411 /* # of bytes for registers saved by the interrupt handler. */
1412 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1414 /* # of registers saved in register parameter area. */
1415 #define INTERRUPT_REGPARM_NUM 4
1416 /* # of words saved for other registers. */
1417 #define INTERRUPT_ALL_SAVE_NUM \
1418 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1420 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1423 compute_register_save_size (long * p_reg_saved)
1427 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1428 int call_p = df_regs_ever_live_p (LINK_POINTER_REGNUM);
1431 /* Count the return pointer if we need to save it. */
1432 if (crtl->profile && !call_p)
1434 df_set_regs_ever_live (LINK_POINTER_REGNUM, true);
1438 /* Count space for the register saves. */
1439 if (interrupt_handler)
1441 for (i = 0; i <= 31; i++)
1445 if (df_regs_ever_live_p (i) || call_p)
1448 reg_saved |= 1L << i;
1452 /* We don't save/restore r0 or the stack pointer */
1454 case STACK_POINTER_REGNUM:
1457 /* For registers with fixed use, we save them, set them to the
1458 appropriate value, and then restore them.
1459 These registers are handled specially, so don't list them
1460 on the list of registers to save in the prologue. */
1461 case 1: /* temp used to hold ep */
1463 case 10: /* temp used to call interrupt save/restore */
1464 case EP_REGNUM: /* ep */
1471 /* Find the first register that needs to be saved. */
1472 for (i = 0; i <= 31; i++)
1473 if (df_regs_ever_live_p (i) && ((! call_used_regs[i])
1474 || i == LINK_POINTER_REGNUM))
1477 /* If it is possible that an out-of-line helper function might be
1478 used to generate the prologue for the current function, then we
1479 need to cover the possibility that such a helper function will
1480 be used, despite the fact that there might be gaps in the list of
1481 registers that need to be saved. To detect this we note that the
1482 helper functions always push at least register r29 (provided
1483 that the function is not an interrupt handler). */
1485 if (TARGET_PROLOG_FUNCTION
1486 && (i == 2 || ((i >= 20) && (i < 30))))
1491 reg_saved |= 1L << i;
1496 /* Helper functions save all registers between the starting
1497 register and the last register, regardless of whether they
1498 are actually used by the function or not. */
1499 for (; i <= 29; i++)
1502 reg_saved |= 1L << i;
1505 if (df_regs_ever_live_p (LINK_POINTER_REGNUM))
1508 reg_saved |= 1L << LINK_POINTER_REGNUM;
1513 for (; i <= 31; i++)
1514 if (df_regs_ever_live_p (i) && ((! call_used_regs[i])
1515 || i == LINK_POINTER_REGNUM))
1518 reg_saved |= 1L << i;
1524 *p_reg_saved = reg_saved;
1530 compute_frame_size (int size, long * p_reg_saved)
1533 + compute_register_save_size (p_reg_saved)
1534 + crtl->outgoing_args_size);
1539 expand_prologue (void)
1543 unsigned int size = get_frame_size ();
1544 unsigned int actual_fsize;
1545 unsigned int init_stack_alloc = 0;
1548 unsigned int num_save;
1549 unsigned int default_stack;
1551 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1554 actual_fsize = compute_frame_size (size, ®_saved);
1556 /* Save/setup global registers for interrupt functions right now. */
1557 if (interrupt_handler)
1559 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1560 emit_insn (gen_callt_save_interrupt ());
1562 emit_insn (gen_save_interrupt ());
1564 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1566 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1567 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1570 /* Save arg registers to the stack if necessary. */
1571 else if (crtl->args.info.anonymous_args)
1573 if (TARGET_PROLOG_FUNCTION && TARGET_V850E && !TARGET_DISABLE_CALLT)
1574 emit_insn (gen_save_r6_r9_v850e ());
1575 else if (TARGET_PROLOG_FUNCTION && ! TARGET_LONG_CALLS)
1576 emit_insn (gen_save_r6_r9 ());
1580 for (i = 6; i < 10; i++)
1582 emit_move_insn (gen_rtx_MEM (SImode,
1583 plus_constant (stack_pointer_rtx,
1585 gen_rtx_REG (SImode, i));
1591 /* Identify all of the saved registers. */
1594 for (i = 1; i < 31; i++)
1596 if (((1L << i) & reg_saved) != 0)
1597 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1600 /* If the return pointer is saved, the helper functions also allocate
1601 16 bytes of stack for arguments to be saved in. */
1602 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1604 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1608 /* See if we have an insn that allocates stack space and saves the particular
1609 registers we want to. */
1610 save_all = NULL_RTX;
1611 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1613 int alloc_stack = (4 * num_save) + default_stack;
1614 int unalloc_stack = actual_fsize - alloc_stack;
1615 int save_func_len = 4;
1616 int save_normal_len;
1619 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1621 /* see if we would have used ep to save the stack */
1622 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1623 save_normal_len = (3 * 2) + (2 * num_save);
1625 save_normal_len = 4 * num_save;
1627 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1629 /* Don't bother checking if we don't actually save any space.
1630 This happens for instance if one register is saved and additional
1631 stack space is allocated. */
1632 if (save_func_len < save_normal_len)
1634 save_all = gen_rtx_PARALLEL
1636 rtvec_alloc (num_save + 1
1637 + (TARGET_V850 ? (TARGET_LONG_CALLS ? 2 : 1) : 0)));
1639 XVECEXP (save_all, 0, 0)
1640 = gen_rtx_SET (VOIDmode,
1642 plus_constant (stack_pointer_rtx, -alloc_stack));
1644 offset = - default_stack;
1645 for (i = 0; i < num_save; i++)
1647 XVECEXP (save_all, 0, i+1)
1648 = gen_rtx_SET (VOIDmode,
1650 plus_constant (stack_pointer_rtx,
1658 XVECEXP (save_all, 0, num_save + 1)
1659 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1661 if (TARGET_LONG_CALLS)
1662 XVECEXP (save_all, 0, num_save + 2)
1663 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
1666 code = recog (save_all, NULL_RTX, NULL);
1669 rtx insn = emit_insn (save_all);
1670 INSN_CODE (insn) = code;
1671 actual_fsize -= alloc_stack;
1675 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1676 save_normal_len - save_func_len,
1677 save_normal_len, save_func_len,
1678 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1681 save_all = NULL_RTX;
1685 /* If no prolog save function is available, store the registers the old
1686 fashioned way (one by one). */
1689 /* Special case interrupt functions that save all registers for a call. */
1690 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1692 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1693 emit_insn (gen_callt_save_all_interrupt ());
1695 emit_insn (gen_save_all_interrupt ());
1699 /* If the stack is too big, allocate it in chunks so we can do the
1700 register saves. We use the register save size so we use the ep
1702 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1703 init_stack_alloc = compute_register_save_size (NULL);
1705 init_stack_alloc = actual_fsize;
1707 /* Save registers at the beginning of the stack frame. */
1708 offset = init_stack_alloc - 4;
1710 if (init_stack_alloc)
1711 emit_insn (gen_addsi3 (stack_pointer_rtx,
1713 GEN_INT (- (signed) init_stack_alloc)));
1715 /* Save the return pointer first. */
1716 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1718 emit_move_insn (gen_rtx_MEM (SImode,
1719 plus_constant (stack_pointer_rtx,
1721 save_regs[--num_save]);
1725 for (i = 0; i < num_save; i++)
1727 emit_move_insn (gen_rtx_MEM (SImode,
1728 plus_constant (stack_pointer_rtx,
1736 /* Allocate the rest of the stack that was not allocated above (either it is
1737 > 32K or we just called a function to save the registers and needed more
1739 if (actual_fsize > init_stack_alloc)
1741 int diff = actual_fsize - init_stack_alloc;
1742 if (CONST_OK_FOR_K (diff))
1743 emit_insn (gen_addsi3 (stack_pointer_rtx,
1748 rtx reg = gen_rtx_REG (Pmode, 12);
1749 emit_move_insn (reg, GEN_INT (-diff));
1750 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1754 /* If we need a frame pointer, set it up now. */
1755 if (frame_pointer_needed)
1756 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1761 expand_epilogue (void)
1765 unsigned int size = get_frame_size ();
1767 int actual_fsize = compute_frame_size (size, ®_saved);
1768 unsigned int init_stack_free = 0;
1769 rtx restore_regs[32];
1771 unsigned int num_restore;
1772 unsigned int default_stack;
1774 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1776 /* Eliminate the initial stack stored by interrupt functions. */
1777 if (interrupt_handler)
1779 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1780 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1781 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1784 /* Cut off any dynamic stack created. */
1785 if (frame_pointer_needed)
1786 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1788 /* Identify all of the saved registers. */
1791 for (i = 1; i < 31; i++)
1793 if (((1L << i) & reg_saved) != 0)
1794 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1797 /* If the return pointer is saved, the helper functions also allocate
1798 16 bytes of stack for arguments to be saved in. */
1799 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1801 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1805 /* See if we have an insn that restores the particular registers we
1807 restore_all = NULL_RTX;
1809 if (TARGET_PROLOG_FUNCTION
1811 && actual_fsize >= (signed) default_stack
1812 && !interrupt_handler)
1814 int alloc_stack = (4 * num_restore) + default_stack;
1815 int unalloc_stack = actual_fsize - alloc_stack;
1816 int restore_func_len = 4;
1817 int restore_normal_len;
1820 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1822 /* See if we would have used ep to restore the registers. */
1823 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1824 restore_normal_len = (3 * 2) + (2 * num_restore);
1826 restore_normal_len = 4 * num_restore;
1828 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1830 /* Don't bother checking if we don't actually save any space. */
1831 if (restore_func_len < restore_normal_len)
1833 restore_all = gen_rtx_PARALLEL (VOIDmode,
1834 rtvec_alloc (num_restore + 2));
1835 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1836 XVECEXP (restore_all, 0, 1)
1837 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1838 gen_rtx_PLUS (Pmode,
1840 GEN_INT (alloc_stack)));
1842 offset = alloc_stack - 4;
1843 for (i = 0; i < num_restore; i++)
1845 XVECEXP (restore_all, 0, i+2)
1846 = gen_rtx_SET (VOIDmode,
1849 plus_constant (stack_pointer_rtx,
1854 code = recog (restore_all, NULL_RTX, NULL);
1860 actual_fsize -= alloc_stack;
1863 if (CONST_OK_FOR_K (actual_fsize))
1864 emit_insn (gen_addsi3 (stack_pointer_rtx,
1866 GEN_INT (actual_fsize)));
1869 rtx reg = gen_rtx_REG (Pmode, 12);
1870 emit_move_insn (reg, GEN_INT (actual_fsize));
1871 emit_insn (gen_addsi3 (stack_pointer_rtx,
1877 insn = emit_jump_insn (restore_all);
1878 INSN_CODE (insn) = code;
1882 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1883 restore_normal_len - restore_func_len,
1884 restore_normal_len, restore_func_len,
1885 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1888 restore_all = NULL_RTX;
1892 /* If no epilogue save function is available, restore the registers the
1893 old fashioned way (one by one). */
1896 /* If the stack is large, we need to cut it down in 2 pieces. */
1897 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1898 init_stack_free = 4 * num_restore;
1900 init_stack_free = (signed) actual_fsize;
1902 /* Deallocate the rest of the stack if it is > 32K. */
1903 if ((unsigned int) actual_fsize > init_stack_free)
1907 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1909 if (CONST_OK_FOR_K (diff))
1910 emit_insn (gen_addsi3 (stack_pointer_rtx,
1915 rtx reg = gen_rtx_REG (Pmode, 12);
1916 emit_move_insn (reg, GEN_INT (diff));
1917 emit_insn (gen_addsi3 (stack_pointer_rtx,
1923 /* Special case interrupt functions that save all registers
1925 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1927 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1928 emit_insn (gen_callt_restore_all_interrupt ());
1930 emit_insn (gen_restore_all_interrupt ());
1934 /* Restore registers from the beginning of the stack frame. */
1935 offset = init_stack_free - 4;
1937 /* Restore the return pointer first. */
1939 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
1941 emit_move_insn (restore_regs[--num_restore],
1942 gen_rtx_MEM (SImode,
1943 plus_constant (stack_pointer_rtx,
1948 for (i = 0; i < num_restore; i++)
1950 emit_move_insn (restore_regs[i],
1951 gen_rtx_MEM (SImode,
1952 plus_constant (stack_pointer_rtx,
1955 emit_use (restore_regs[i]);
1959 /* Cut back the remainder of the stack. */
1960 if (init_stack_free)
1961 emit_insn (gen_addsi3 (stack_pointer_rtx,
1963 GEN_INT (init_stack_free)));
1966 /* And return or use reti for interrupt handlers. */
1967 if (interrupt_handler)
1969 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1970 emit_insn (gen_callt_return_interrupt ());
1972 emit_jump_insn (gen_return_interrupt ());
1974 else if (actual_fsize)
1975 emit_jump_insn (gen_return_internal ());
1977 emit_jump_insn (gen_return_simple ());
1980 v850_interrupt_cache_p = FALSE;
1981 v850_interrupt_p = FALSE;
1985 /* Update the condition code from the insn. */
1988 notice_update_cc (rtx body, rtx insn)
1990 switch (get_attr_cc (insn))
1993 /* Insn does not affect CC at all. */
1997 /* Insn does not change CC, but the 0'th operand has been changed. */
1998 if (cc_status.value1 != 0
1999 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
2000 cc_status.value1 = 0;
2004 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2005 V,C is in an unusable state. */
2007 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
2008 cc_status.value1 = recog_data.operand[0];
2012 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2013 C is in an unusable state. */
2015 cc_status.flags |= CC_NO_CARRY;
2016 cc_status.value1 = recog_data.operand[0];
2020 /* The insn is a compare instruction. */
2022 cc_status.value1 = SET_SRC (body);
2026 /* Insn doesn't leave CC in a usable state. */
2032 /* Retrieve the data area that has been chosen for the given decl. */
2035 v850_get_data_area (tree decl)
2037 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2038 return DATA_AREA_SDA;
2040 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2041 return DATA_AREA_TDA;
2043 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2044 return DATA_AREA_ZDA;
2046 return DATA_AREA_NORMAL;
2049 /* Store the indicated data area in the decl's attributes. */
2052 v850_set_data_area (tree decl, v850_data_area data_area)
2058 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2059 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2060 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2065 DECL_ATTRIBUTES (decl) = tree_cons
2066 (name, NULL, DECL_ATTRIBUTES (decl));
2069 /* Handle an "interrupt" attribute; arguments as in
2070 struct attribute_spec.handler. */
2072 v850_handle_interrupt_attribute (tree * node,
2074 tree args ATTRIBUTE_UNUSED,
2075 int flags ATTRIBUTE_UNUSED,
2076 bool * no_add_attrs)
2078 if (TREE_CODE (*node) != FUNCTION_DECL)
2080 warning (OPT_Wattributes, "%qE attribute only applies to functions",
2082 *no_add_attrs = true;
2088 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2089 struct attribute_spec.handler. */
2091 v850_handle_data_area_attribute (tree* node,
2093 tree args ATTRIBUTE_UNUSED,
2094 int flags ATTRIBUTE_UNUSED,
2095 bool * no_add_attrs)
2097 v850_data_area data_area;
2098 v850_data_area area;
2101 /* Implement data area attribute. */
2102 if (is_attribute_p ("sda", name))
2103 data_area = DATA_AREA_SDA;
2104 else if (is_attribute_p ("tda", name))
2105 data_area = DATA_AREA_TDA;
2106 else if (is_attribute_p ("zda", name))
2107 data_area = DATA_AREA_ZDA;
2111 switch (TREE_CODE (decl))
2114 if (current_function_decl != NULL_TREE)
2116 error_at (DECL_SOURCE_LOCATION (decl),
2117 "data area attributes cannot be specified for "
2119 *no_add_attrs = true;
2125 area = v850_get_data_area (decl);
2126 if (area != DATA_AREA_NORMAL && data_area != area)
2128 error ("data area of %q+D conflicts with previous declaration",
2130 *no_add_attrs = true;
2142 /* Return nonzero if FUNC is an interrupt function as specified
2143 by the "interrupt" attribute. */
2146 v850_interrupt_function_p (tree func)
2151 if (v850_interrupt_cache_p)
2152 return v850_interrupt_p;
2154 if (TREE_CODE (func) != FUNCTION_DECL)
2157 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2163 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2164 ret = a != NULL_TREE;
2167 /* Its not safe to trust global variables until after function inlining has
2169 if (reload_completed | reload_in_progress)
2170 v850_interrupt_p = ret;
2177 v850_encode_data_area (tree decl, rtx symbol)
2181 /* Map explicit sections into the appropriate attribute */
2182 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2184 if (DECL_SECTION_NAME (decl))
2186 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2188 if (streq (name, ".zdata") || streq (name, ".zbss"))
2189 v850_set_data_area (decl, DATA_AREA_ZDA);
2191 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2192 v850_set_data_area (decl, DATA_AREA_SDA);
2194 else if (streq (name, ".tdata"))
2195 v850_set_data_area (decl, DATA_AREA_TDA);
2198 /* If no attribute, support -m{zda,sda,tda}=n */
2201 int size = int_size_in_bytes (TREE_TYPE (decl));
2205 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2206 v850_set_data_area (decl, DATA_AREA_TDA);
2208 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2209 v850_set_data_area (decl, DATA_AREA_SDA);
2211 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2212 v850_set_data_area (decl, DATA_AREA_ZDA);
2215 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2219 flags = SYMBOL_REF_FLAGS (symbol);
2220 switch (v850_get_data_area (decl))
2222 case DATA_AREA_ZDA: flags |= SYMBOL_FLAG_ZDA; break;
2223 case DATA_AREA_TDA: flags |= SYMBOL_FLAG_TDA; break;
2224 case DATA_AREA_SDA: flags |= SYMBOL_FLAG_SDA; break;
2225 default: gcc_unreachable ();
2227 SYMBOL_REF_FLAGS (symbol) = flags;
2231 v850_encode_section_info (tree decl, rtx rtl, int first)
2233 default_encode_section_info (decl, rtl, first);
2235 if (TREE_CODE (decl) == VAR_DECL
2236 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2237 v850_encode_data_area (decl, XEXP (rtl, 0));
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 (rtx op)
2248 int count = XVECLEN (op, 0);
2250 unsigned long int mask;
2251 unsigned long int first;
2252 unsigned long int last;
2254 static char buff [100]; /* XXX */
2258 error ("bogus JR construction: %d", count);
2262 /* Work out how many bytes to pop off the stack before retrieving
2264 gcc_assert (GET_CODE (XVECEXP (op, 0, 1)) == SET);
2265 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS);
2266 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) == CONST_INT);
2268 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2270 /* Each pop will remove 4 bytes from the stack.... */
2271 stack_bytes -= (count - 2) * 4;
2273 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2274 if (stack_bytes != 0 && stack_bytes != 16)
2276 error ("bad amount of stack space removal: %d", stack_bytes);
2280 /* Now compute the bit mask of registers to push. */
2282 for (i = 2; i < count; i++)
2284 rtx vector_element = XVECEXP (op, 0, i);
2286 gcc_assert (GET_CODE (vector_element) == SET);
2287 gcc_assert (GET_CODE (SET_DEST (vector_element)) == REG);
2288 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element),
2291 mask |= 1 << REGNO (SET_DEST (vector_element));
2294 /* Scan for the first register to pop. */
2295 for (first = 0; first < 32; first++)
2297 if (mask & (1 << first))
2301 gcc_assert (first < 32);
2303 /* Discover the last register to pop. */
2304 if (mask & (1 << LINK_POINTER_REGNUM))
2306 gcc_assert (stack_bytes == 16);
2308 last = LINK_POINTER_REGNUM;
2312 gcc_assert (!stack_bytes);
2313 gcc_assert (mask & (1 << 29));
2318 /* Note, it is possible to have gaps in the register mask.
2319 We ignore this here, and generate a JR anyway. We will
2320 be popping more registers than is strictly necessary, but
2321 it does save code space. */
2323 if (TARGET_LONG_CALLS)
2328 sprintf (name, "__return_%s", reg_names [first]);
2330 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2332 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2338 sprintf (buff, "jr __return_%s", reg_names [first]);
2340 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2347 /* Construct a JARL instruction to a routine that will perform the equivalent
2348 of the RTL passed as a parameter. This RTL is a function prologue that
2349 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2350 some stack space as well. The code has already verified that the RTL
2351 matches these requirements. */
2353 construct_save_jarl (rtx op)
2355 int count = XVECLEN (op, 0);
2357 unsigned long int mask;
2358 unsigned long int first;
2359 unsigned long int last;
2361 static char buff [100]; /* XXX */
2365 error ("bogus JARL construction: %d\n", count);
2370 gcc_assert (GET_CODE (XVECEXP (op, 0, 0)) == SET);
2371 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) == PLUS);
2372 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) == REG);
2373 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) == CONST_INT);
2375 /* Work out how many bytes to push onto the stack after storing the
2377 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2379 /* Each push will put 4 bytes from the stack.... */
2380 stack_bytes += (count - (TARGET_LONG_CALLS ? 3 : 2)) * 4;
2382 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2383 if (stack_bytes != 0 && stack_bytes != -16)
2385 error ("bad amount of stack space removal: %d", stack_bytes);
2389 /* Now compute the bit mask of registers to push. */
2391 for (i = 1; i < count - (TARGET_LONG_CALLS ? 2 : 1); i++)
2393 rtx vector_element = XVECEXP (op, 0, i);
2395 gcc_assert (GET_CODE (vector_element) == SET);
2396 gcc_assert (GET_CODE (SET_SRC (vector_element)) == REG);
2397 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element),
2400 mask |= 1 << REGNO (SET_SRC (vector_element));
2403 /* Scan for the first register to push. */
2404 for (first = 0; first < 32; first++)
2406 if (mask & (1 << first))
2410 gcc_assert (first < 32);
2412 /* Discover the last register to push. */
2413 if (mask & (1 << LINK_POINTER_REGNUM))
2415 gcc_assert (stack_bytes == -16);
2417 last = LINK_POINTER_REGNUM;
2421 gcc_assert (!stack_bytes);
2422 gcc_assert (mask & (1 << 29));
2427 /* Note, it is possible to have gaps in the register mask.
2428 We ignore this here, and generate a JARL anyway. We will
2429 be pushing more registers than is strictly necessary, but
2430 it does save code space. */
2432 if (TARGET_LONG_CALLS)
2437 sprintf (name, "__save_%s", reg_names [first]);
2439 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2441 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2447 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2449 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2456 extern tree last_assemble_variable_decl;
2457 extern int size_directive_output;
2459 /* A version of asm_output_aligned_bss() that copes with the special
2460 data areas of the v850. */
2462 v850_output_aligned_bss (FILE * file,
2465 unsigned HOST_WIDE_INT size,
2468 switch (v850_get_data_area (decl))
2471 switch_to_section (zbss_section);
2475 switch_to_section (sbss_section);
2479 switch_to_section (tdata_section);
2482 switch_to_section (bss_section);
2486 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2487 #ifdef ASM_DECLARE_OBJECT_NAME
2488 last_assemble_variable_decl = decl;
2489 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2491 /* Standard thing is just output label for the object. */
2492 ASM_OUTPUT_LABEL (file, name);
2493 #endif /* ASM_DECLARE_OBJECT_NAME */
2494 ASM_OUTPUT_SKIP (file, size ? size : 1);
2497 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2499 v850_output_common (FILE * file,
2505 if (decl == NULL_TREE)
2507 fprintf (file, "%s", COMMON_ASM_OP);
2511 switch (v850_get_data_area (decl))
2514 fprintf (file, "%s", ZCOMMON_ASM_OP);
2518 fprintf (file, "%s", SCOMMON_ASM_OP);
2522 fprintf (file, "%s", TCOMMON_ASM_OP);
2526 fprintf (file, "%s", COMMON_ASM_OP);
2531 assemble_name (file, name);
2532 fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2535 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2537 v850_output_local (FILE * file,
2543 fprintf (file, "%s", LOCAL_ASM_OP);
2544 assemble_name (file, name);
2545 fprintf (file, "\n");
2547 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2550 /* Add data area to the given declaration if a ghs data area pragma is
2551 currently in effect (#pragma ghs startXXX/endXXX). */
2553 v850_insert_attributes (tree decl, tree * attr_ptr ATTRIBUTE_UNUSED )
2556 && data_area_stack->data_area
2557 && current_function_decl == NULL_TREE
2558 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2559 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2560 v850_set_data_area (decl, data_area_stack->data_area);
2562 /* Initialize the default names of the v850 specific sections,
2563 if this has not been done before. */
2565 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2567 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2568 = build_string (sizeof (".sdata")-1, ".sdata");
2570 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2571 = build_string (sizeof (".rosdata")-1, ".rosdata");
2573 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2574 = build_string (sizeof (".tdata")-1, ".tdata");
2576 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2577 = build_string (sizeof (".zdata")-1, ".zdata");
2579 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2580 = build_string (sizeof (".rozdata")-1, ".rozdata");
2583 if (current_function_decl == NULL_TREE
2584 && (TREE_CODE (decl) == VAR_DECL
2585 || TREE_CODE (decl) == CONST_DECL
2586 || TREE_CODE (decl) == FUNCTION_DECL)
2587 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2588 && !DECL_SECTION_NAME (decl))
2590 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2591 tree chosen_section;
2593 if (TREE_CODE (decl) == FUNCTION_DECL)
2594 kind = GHS_SECTION_KIND_TEXT;
2597 /* First choose a section kind based on the data area of the decl. */
2598 switch (v850_get_data_area (decl))
2604 kind = ((TREE_READONLY (decl))
2605 ? GHS_SECTION_KIND_ROSDATA
2606 : GHS_SECTION_KIND_SDATA);
2610 kind = GHS_SECTION_KIND_TDATA;
2614 kind = ((TREE_READONLY (decl))
2615 ? GHS_SECTION_KIND_ROZDATA
2616 : GHS_SECTION_KIND_ZDATA);
2619 case DATA_AREA_NORMAL: /* default data area */
2620 if (TREE_READONLY (decl))
2621 kind = GHS_SECTION_KIND_RODATA;
2622 else if (DECL_INITIAL (decl))
2623 kind = GHS_SECTION_KIND_DATA;
2625 kind = GHS_SECTION_KIND_BSS;
2629 /* Now, if the section kind has been explicitly renamed,
2630 then attach a section attribute. */
2631 chosen_section = GHS_current_section_names [(int) kind];
2633 /* Otherwise, if this kind of section needs an explicit section
2634 attribute, then also attach one. */
2635 if (chosen_section == NULL)
2636 chosen_section = GHS_default_section_names [(int) kind];
2640 /* Only set the section name if specified by a pragma, because
2641 otherwise it will force those variables to get allocated storage
2642 in this module, rather than by the linker. */
2643 DECL_SECTION_NAME (decl) = chosen_section;
2648 /* Construct a DISPOSE instruction that is the equivalent of
2649 the given RTX. We have already verified that this should
2653 construct_dispose_instruction (rtx op)
2655 int count = XVECLEN (op, 0);
2657 unsigned long int mask;
2659 static char buff[ 100 ]; /* XXX */
2664 error ("bogus DISPOSE construction: %d", count);
2668 /* Work out how many bytes to pop off the
2669 stack before retrieving registers. */
2670 gcc_assert (GET_CODE (XVECEXP (op, 0, 1)) == SET);
2671 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS);
2672 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) == CONST_INT);
2674 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2676 /* Each pop will remove 4 bytes from the stack.... */
2677 stack_bytes -= (count - 2) * 4;
2679 /* Make sure that the amount we are popping
2680 will fit into the DISPOSE instruction. */
2681 if (stack_bytes > 128)
2683 error ("too much stack space to dispose of: %d", stack_bytes);
2687 /* Now compute the bit mask of registers to push. */
2690 for (i = 2; i < count; i++)
2692 rtx vector_element = XVECEXP (op, 0, i);
2694 gcc_assert (GET_CODE (vector_element) == SET);
2695 gcc_assert (GET_CODE (SET_DEST (vector_element)) == REG);
2696 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element),
2699 if (REGNO (SET_DEST (vector_element)) == 2)
2702 mask |= 1 << REGNO (SET_DEST (vector_element));
2705 if (! TARGET_DISABLE_CALLT
2706 && (use_callt || stack_bytes == 0 || stack_bytes == 16))
2710 sprintf (buff, "callt ctoff(__callt_return_r2_r%d)", (mask & (1 << 31)) ? 31 : 29);
2715 for (i = 20; i < 32; i++)
2716 if (mask & (1 << i))
2720 sprintf (buff, "callt ctoff(__callt_return_r31c)");
2722 sprintf (buff, "callt ctoff(__callt_return_r%d_r%d%s)",
2723 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
2728 static char regs [100]; /* XXX */
2731 /* Generate the DISPOSE instruction. Note we could just issue the
2732 bit mask as a number as the assembler can cope with this, but for
2733 the sake of our readers we turn it into a textual description. */
2737 for (i = 20; i < 32; i++)
2739 if (mask & (1 << i))
2744 strcat (regs, ", ");
2749 strcat (regs, reg_names[ first ]);
2751 for (i++; i < 32; i++)
2752 if ((mask & (1 << i)) == 0)
2757 strcat (regs, " - ");
2758 strcat (regs, reg_names[ i - 1 ] );
2763 sprintf (buff, "dispose %d {%s}, r31", stack_bytes / 4, regs);
2769 /* Construct a PREPARE instruction that is the equivalent of
2770 the given RTL. We have already verified that this should
2774 construct_prepare_instruction (rtx op)
2776 int count = XVECLEN (op, 0);
2778 unsigned long int mask;
2780 static char buff[ 100 ]; /* XXX */
2785 error ("bogus PREPEARE construction: %d", count);
2789 /* Work out how many bytes to push onto
2790 the stack after storing the registers. */
2791 gcc_assert (GET_CODE (XVECEXP (op, 0, 0)) == SET);
2792 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) == PLUS);
2793 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) == CONST_INT);
2795 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2797 /* Each push will put 4 bytes from the stack. */
2798 stack_bytes += (count - 1) * 4;
2800 /* Make sure that the amount we are popping
2801 will fit into the DISPOSE instruction. */
2802 if (stack_bytes < -128)
2804 error ("too much stack space to prepare: %d", stack_bytes);
2808 /* Now compute the bit mask of registers to push. */
2810 for (i = 1; i < count; i++)
2812 rtx vector_element = XVECEXP (op, 0, i);
2814 gcc_assert (GET_CODE (vector_element) == SET);
2815 gcc_assert (GET_CODE (SET_SRC (vector_element)) == REG);
2816 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element),
2819 if (REGNO (SET_SRC (vector_element)) == 2)
2822 mask |= 1 << REGNO (SET_SRC (vector_element));
2825 if ((! TARGET_DISABLE_CALLT)
2826 && (use_callt || stack_bytes == 0 || stack_bytes == -16))
2830 sprintf (buff, "callt ctoff(__callt_save_r2_r%d)", (mask & (1 << 31)) ? 31 : 29 );
2834 for (i = 20; i < 32; i++)
2835 if (mask & (1 << i))
2839 sprintf (buff, "callt ctoff(__callt_save_r31c)");
2841 sprintf (buff, "callt ctoff(__callt_save_r%d_r%d%s)",
2842 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
2846 static char regs [100]; /* XXX */
2850 /* Generate the PREPARE instruction. Note we could just issue the
2851 bit mask as a number as the assembler can cope with this, but for
2852 the sake of our readers we turn it into a textual description. */
2856 for (i = 20; i < 32; i++)
2858 if (mask & (1 << i))
2863 strcat (regs, ", ");
2868 strcat (regs, reg_names[ first ]);
2870 for (i++; i < 32; i++)
2871 if ((mask & (1 << i)) == 0)
2876 strcat (regs, " - ");
2877 strcat (regs, reg_names[ i - 1 ] );
2882 sprintf (buff, "prepare {%s}, %d", regs, (- stack_bytes) / 4);
2888 /* Return an RTX indicating where the return address to the
2889 calling function can be found. */
2892 v850_return_addr (int count)
2897 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
2900 /* Implement TARGET_ASM_INIT_SECTIONS. */
2903 v850_asm_init_sections (void)
2906 = get_unnamed_section (0, output_section_asm_op,
2907 "\t.section .rosdata,\"a\"");
2910 = get_unnamed_section (0, output_section_asm_op,
2911 "\t.section .rozdata,\"a\"");
2914 = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
2915 "\t.section .tdata,\"aw\"");
2918 = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
2919 "\t.section .zdata,\"aw\"");
2922 = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
2923 output_section_asm_op,
2924 "\t.section .zbss,\"aw\"");
2928 v850_select_section (tree exp,
2929 int reloc ATTRIBUTE_UNUSED,
2930 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
2932 if (TREE_CODE (exp) == VAR_DECL)
2935 if (!TREE_READONLY (exp)
2936 || TREE_SIDE_EFFECTS (exp)
2937 || !DECL_INITIAL (exp)
2938 || (DECL_INITIAL (exp) != error_mark_node
2939 && !TREE_CONSTANT (DECL_INITIAL (exp))))
2944 switch (v850_get_data_area (exp))
2947 return is_const ? rozdata_section : zdata_section;
2950 return tdata_section;
2953 return is_const ? rosdata_section : sdata_section;
2956 return is_const ? readonly_data_section : data_section;
2959 return readonly_data_section;
2962 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2965 v850_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
2967 /* Return values > 8 bytes in length in memory. */
2968 return int_size_in_bytes (type) > 8 || TYPE_MODE (type) == BLKmode;
2971 /* Worker function for TARGET_FUNCTION_VALUE. */
2974 v850_function_value (const_tree valtype,
2975 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
2976 bool outgoing ATTRIBUTE_UNUSED)
2978 return gen_rtx_REG (TYPE_MODE (valtype), 10);
2982 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2985 v850_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
2986 enum machine_mode mode ATTRIBUTE_UNUSED,
2987 tree type ATTRIBUTE_UNUSED,
2988 int *pretend_arg_size ATTRIBUTE_UNUSED,
2989 int second_time ATTRIBUTE_UNUSED)
2991 ca->anonymous_args = (!TARGET_GHS ? 1 : 0);
2994 /* Worker function for TARGET_CAN_ELIMINATE. */
2997 v850_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
2999 return (to == STACK_POINTER_REGNUM ? ! frame_pointer_needed : true);
3003 /* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE. */
3006 v850_asm_trampoline_template (FILE *f)
3008 fprintf (f, "\tjarl .+4,r12\n");
3009 fprintf (f, "\tld.w 12[r12],r20\n");
3010 fprintf (f, "\tld.w 16[r12],r12\n");
3011 fprintf (f, "\tjmp [r12]\n");
3012 fprintf (f, "\tnop\n");
3013 fprintf (f, "\t.long 0\n");
3014 fprintf (f, "\t.long 0\n");
3017 /* Worker function for TARGET_TRAMPOLINE_INIT. */
3020 v850_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
3022 rtx mem, fnaddr = XEXP (DECL_RTL (fndecl), 0);
3024 emit_block_move (m_tramp, assemble_trampoline_template (),
3025 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
3027 mem = adjust_address (m_tramp, SImode, 16);
3028 emit_move_insn (mem, chain_value);
3029 mem = adjust_address (m_tramp, SImode, 20);
3030 emit_move_insn (mem, fnaddr);
3033 #include "gt-v850.h"