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 void v850_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
71 static bool v850_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
73 static int v850_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
76 /* Information about the various small memory areas. */
77 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
79 /* name max physical max */
85 /* Names of the various data areas used on the v850. */
86 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
87 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
89 /* Track the current data area set by the data area pragma (which
90 can be nested). Tested by check_default_data_area. */
91 data_area_stack_element * data_area_stack = NULL;
93 /* True if we don't need to check any more if the current
94 function is an interrupt handler. */
95 static int v850_interrupt_cache_p = FALSE;
97 /* Whether current function is an interrupt handler. */
98 static int v850_interrupt_p = FALSE;
100 static GTY(()) section *rosdata_section;
101 static GTY(()) section *rozdata_section;
102 static GTY(()) section *tdata_section;
103 static GTY(()) section *zdata_section;
104 static GTY(()) section *zbss_section;
106 /* V850 specific attributes. */
108 static const struct attribute_spec v850_attribute_table[] =
110 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
111 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute },
112 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute },
113 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute },
114 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute },
115 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute },
116 { NULL, 0, 0, false, false, false, NULL }
120 /* Initialize the GCC target structure. */
121 #undef TARGET_ASM_ALIGNED_HI_OP
122 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
124 #undef TARGET_ATTRIBUTE_TABLE
125 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
127 #undef TARGET_INSERT_ATTRIBUTES
128 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
130 #undef TARGET_ASM_SELECT_SECTION
131 #define TARGET_ASM_SELECT_SECTION v850_select_section
133 /* The assembler supports switchable .bss sections, but
134 v850_select_section doesn't yet make use of them. */
135 #undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
136 #define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS false
138 #undef TARGET_ENCODE_SECTION_INFO
139 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
141 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
142 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
144 #undef TARGET_DEFAULT_TARGET_FLAGS
145 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_DEFAULT | MASK_APP_REGS)
146 #undef TARGET_HANDLE_OPTION
147 #define TARGET_HANDLE_OPTION v850_handle_option
149 #undef TARGET_RTX_COSTS
150 #define TARGET_RTX_COSTS v850_rtx_costs
152 #undef TARGET_ADDRESS_COST
153 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
155 #undef TARGET_MACHINE_DEPENDENT_REORG
156 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
158 #undef TARGET_PROMOTE_PROTOTYPES
159 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
161 #undef TARGET_RETURN_IN_MEMORY
162 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
164 #undef TARGET_PASS_BY_REFERENCE
165 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
167 #undef TARGET_CALLEE_COPIES
168 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
170 #undef TARGET_SETUP_INCOMING_VARARGS
171 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
173 #undef TARGET_ARG_PARTIAL_BYTES
174 #define TARGET_ARG_PARTIAL_BYTES v850_arg_partial_bytes
176 struct gcc_target targetm = TARGET_INITIALIZER;
178 /* Set the maximum size of small memory area TYPE to the value given
179 by VALUE. Return true if VALUE was syntactically correct. VALUE
180 starts with the argument separator: either "-" or "=". */
183 v850_handle_memory_option (enum small_memory_type type, const char *value)
187 if (*value != '-' && *value != '=')
191 for (i = 0; value[i]; i++)
192 if (!ISDIGIT (value[i]))
196 if (size > small_memory[type].physical_max)
197 error ("value passed to %<-m%s%> is too large", small_memory[type].name);
199 small_memory[type].max = size;
203 /* Implement TARGET_HANDLE_OPTION. */
206 v850_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
211 target_flags |= MASK_EP | MASK_PROLOG_FUNCTION;
215 target_flags &= ~(MASK_CPU ^ MASK_V850);
220 target_flags &= ~(MASK_CPU ^ MASK_V850E);
224 return v850_handle_memory_option (SMALL_MEMORY_TDA, arg);
227 return v850_handle_memory_option (SMALL_MEMORY_SDA, arg);
230 return v850_handle_memory_option (SMALL_MEMORY_ZDA, arg);
238 v850_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
239 enum machine_mode mode, const_tree type,
240 bool named ATTRIBUTE_UNUSED)
242 unsigned HOST_WIDE_INT size;
245 size = int_size_in_bytes (type);
247 size = GET_MODE_SIZE (mode);
252 /* Return an RTX to represent where a value with mode MODE will be returned
253 from a function. If the result is 0, the argument is pushed. */
256 function_arg (CUMULATIVE_ARGS * cum,
257 enum machine_mode mode,
264 if (TARGET_GHS && !named)
268 size = int_size_in_bytes (type);
270 size = GET_MODE_SIZE (mode);
276 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
280 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
282 if (cum->nbytes > 4 * UNITS_PER_WORD)
285 if (type == NULL_TREE
286 && cum->nbytes + size > 4 * UNITS_PER_WORD)
289 switch (cum->nbytes / UNITS_PER_WORD)
292 result = gen_rtx_REG (mode, 6);
295 result = gen_rtx_REG (mode, 7);
298 result = gen_rtx_REG (mode, 8);
301 result = gen_rtx_REG (mode, 9);
311 /* Return the number of bytes which must be put into registers
312 for values which are part in registers and part in memory. */
315 v850_arg_partial_bytes (CUMULATIVE_ARGS * cum, enum machine_mode mode,
316 tree type, bool named)
320 if (TARGET_GHS && !named)
324 size = int_size_in_bytes (type);
326 size = GET_MODE_SIZE (mode);
329 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
333 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
335 if (cum->nbytes > 4 * UNITS_PER_WORD)
338 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
341 if (type == NULL_TREE
342 && cum->nbytes + size > 4 * UNITS_PER_WORD)
345 return 4 * UNITS_PER_WORD - cum->nbytes;
349 /* Return the high and low words of a CONST_DOUBLE */
352 const_double_split (rtx x, HOST_WIDE_INT * p_high, HOST_WIDE_INT * p_low)
354 if (GET_CODE (x) == CONST_DOUBLE)
359 switch (GET_MODE (x))
362 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
363 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
364 *p_high = t[1]; /* since v850 is little endian */
365 *p_low = t[0]; /* high is second word */
369 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
370 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
376 *p_high = CONST_DOUBLE_HIGH (x);
377 *p_low = CONST_DOUBLE_LOW (x);
385 fatal_insn ("const_double_split got a bad insn:", x);
389 /* Return the cost of the rtx R with code CODE. */
392 const_costs_int (HOST_WIDE_INT value, int zero_cost)
394 if (CONST_OK_FOR_I (value))
396 else if (CONST_OK_FOR_J (value))
398 else if (CONST_OK_FOR_K (value))
405 const_costs (rtx r, enum rtx_code c)
407 HOST_WIDE_INT high, low;
412 return const_costs_int (INTVAL (r), 0);
415 const_double_split (r, &high, &low);
416 if (GET_MODE (r) == SFmode)
417 return const_costs_int (high, 1);
419 return const_costs_int (high, 1) + const_costs_int (low, 1);
435 v850_rtx_costs (rtx x,
437 int outer_code ATTRIBUTE_UNUSED,
438 int * total, bool speed)
440 enum rtx_code code = (enum rtx_code) codearg;
449 *total = COSTS_N_INSNS (const_costs (x, code));
456 if (TARGET_V850E && !speed)
464 && ( GET_MODE (x) == SImode
465 || GET_MODE (x) == HImode
466 || GET_MODE (x) == QImode))
468 if (GET_CODE (XEXP (x, 1)) == REG)
470 else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
472 if (CONST_OK_FOR_O (INTVAL (XEXP (x, 1))))
474 else if (CONST_OK_FOR_K (INTVAL (XEXP (x, 1))))
483 if (outer_code == COMPARE)
492 /* Print operand X using operand code CODE to assembly language output file
496 print_operand (FILE * file, rtx x, int code)
498 HOST_WIDE_INT high, low;
503 /* We use 'c' operands with symbols for .vtinherit */
504 if (GET_CODE (x) == SYMBOL_REF)
506 output_addr_const(file, x);
513 switch ((code == 'B' || code == 'C')
514 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
517 if (code == 'c' || code == 'C')
518 fprintf (file, "nz");
520 fprintf (file, "ne");
523 if (code == 'c' || code == 'C')
529 fprintf (file, "ge");
532 fprintf (file, "gt");
535 fprintf (file, "le");
538 fprintf (file, "lt");
541 fprintf (file, "nl");
547 fprintf (file, "nh");
556 case 'F': /* high word of CONST_DOUBLE */
557 switch (GET_CODE (x))
560 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
564 const_double_split (x, &high, &low);
565 fprintf (file, "%ld", (long) high);
572 case 'G': /* low word of CONST_DOUBLE */
573 switch (GET_CODE (x))
576 fprintf (file, "%ld", (long) INTVAL (x));
580 const_double_split (x, &high, &low);
581 fprintf (file, "%ld", (long) low);
589 fprintf (file, "%d\n", (int)(INTVAL (x) & 0xffff));
592 fprintf (file, "%d", exact_log2 (INTVAL (x)));
595 gcc_assert (special_symbolref_operand (x, VOIDmode));
597 if (GET_CODE (x) == CONST)
598 x = XEXP (XEXP (x, 0), 0);
600 gcc_assert (GET_CODE (x) == SYMBOL_REF);
602 if (SYMBOL_REF_ZDA_P (x))
603 fprintf (file, "zdaoff");
604 else if (SYMBOL_REF_SDA_P (x))
605 fprintf (file, "sdaoff");
606 else if (SYMBOL_REF_TDA_P (x))
607 fprintf (file, "tdaoff");
612 gcc_assert (special_symbolref_operand (x, VOIDmode));
613 output_addr_const (file, x);
616 gcc_assert (special_symbolref_operand (x, VOIDmode));
618 if (GET_CODE (x) == CONST)
619 x = XEXP (XEXP (x, 0), 0);
621 gcc_assert (GET_CODE (x) == SYMBOL_REF);
623 if (SYMBOL_REF_ZDA_P (x))
624 fprintf (file, "r0");
625 else if (SYMBOL_REF_SDA_P (x))
626 fprintf (file, "gp");
627 else if (SYMBOL_REF_TDA_P (x))
628 fprintf (file, "ep");
632 case 'R': /* 2nd word of a double. */
633 switch (GET_CODE (x))
636 fprintf (file, reg_names[REGNO (x) + 1]);
639 x = XEXP (adjust_address (x, SImode, 4), 0);
640 print_operand_address (file, x);
641 if (GET_CODE (x) == CONST_INT)
642 fprintf (file, "[r0]");
651 /* If it's a reference to a TDA variable, use sst/sld vs. st/ld. */
652 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
659 /* Like an 'S' operand above, but for unsigned loads only. */
660 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
665 case 'W': /* print the instruction suffix */
666 switch (GET_MODE (x))
671 case QImode: fputs (".b", file); break;
672 case HImode: fputs (".h", file); break;
673 case SImode: fputs (".w", file); break;
674 case SFmode: fputs (".w", file); break;
677 case '.': /* register r0 */
678 fputs (reg_names[0], file);
680 case 'z': /* reg or zero */
681 if (GET_CODE (x) == REG)
682 fputs (reg_names[REGNO (x)], file);
685 gcc_assert (x == const0_rtx);
686 fputs (reg_names[0], file);
690 switch (GET_CODE (x))
693 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
694 output_address (gen_rtx_PLUS (SImode, gen_rtx_REG (SImode, 0),
697 output_address (XEXP (x, 0));
701 fputs (reg_names[REGNO (x)], file);
704 fputs (reg_names[subreg_regno (x)], file);
711 print_operand_address (file, x);
722 /* Output assembly language output for the address ADDR to FILE. */
725 print_operand_address (FILE * file, rtx addr)
727 switch (GET_CODE (addr))
730 fprintf (file, "0[");
731 print_operand (file, addr, 0);
735 if (GET_CODE (XEXP (addr, 0)) == REG)
738 fprintf (file, "lo(");
739 print_operand (file, XEXP (addr, 1), 0);
740 fprintf (file, ")[");
741 print_operand (file, XEXP (addr, 0), 0);
746 if (GET_CODE (XEXP (addr, 0)) == REG
747 || GET_CODE (XEXP (addr, 0)) == SUBREG)
750 print_operand (file, XEXP (addr, 1), 0);
752 print_operand (file, XEXP (addr, 0), 0);
757 print_operand (file, XEXP (addr, 0), 0);
759 print_operand (file, XEXP (addr, 1), 0);
764 const char *off_name = NULL;
765 const char *reg_name = NULL;
767 if (SYMBOL_REF_ZDA_P (addr))
772 else if (SYMBOL_REF_SDA_P (addr))
777 else if (SYMBOL_REF_TDA_P (addr))
784 fprintf (file, "%s(", off_name);
785 output_addr_const (file, addr);
787 fprintf (file, ")[%s]", reg_name);
791 if (special_symbolref_operand (addr, VOIDmode))
793 rtx x = XEXP (XEXP (addr, 0), 0);
794 const char *off_name;
795 const char *reg_name;
797 if (SYMBOL_REF_ZDA_P (x))
802 else if (SYMBOL_REF_SDA_P (x))
807 else if (SYMBOL_REF_TDA_P (x))
815 fprintf (file, "%s(", off_name);
816 output_addr_const (file, addr);
817 fprintf (file, ")[%s]", reg_name);
820 output_addr_const (file, addr);
823 output_addr_const (file, addr);
828 /* When assemble_integer is used to emit the offsets for a switch
829 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
830 output_addr_const will normally barf at this, but it is OK to omit
831 the truncate and just emit the difference of the two labels. The
832 .hword directive will automatically handle the truncation for us.
834 Returns 1 if rtx was handled, 0 otherwise. */
837 v850_output_addr_const_extra (FILE * file, rtx x)
839 if (GET_CODE (x) != TRUNCATE)
844 /* We must also handle the case where the switch table was passed a
845 constant value and so has been collapsed. In this case the first
846 label will have been deleted. In such a case it is OK to emit
847 nothing, since the table will not be used.
848 (cf gcc.c-torture/compile/990801-1.c). */
849 if (GET_CODE (x) == MINUS
850 && GET_CODE (XEXP (x, 0)) == LABEL_REF
851 && GET_CODE (XEXP (XEXP (x, 0), 0)) == CODE_LABEL
852 && INSN_DELETED_P (XEXP (XEXP (x, 0), 0)))
855 output_addr_const (file, x);
859 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
863 output_move_single (rtx * operands)
865 rtx dst = operands[0];
866 rtx src = operands[1];
873 else if (GET_CODE (src) == CONST_INT)
875 HOST_WIDE_INT value = INTVAL (src);
877 if (CONST_OK_FOR_J (value)) /* Signed 5-bit immediate. */
880 else if (CONST_OK_FOR_K (value)) /* Signed 16-bit immediate. */
881 return "movea lo(%1),%.,%0";
883 else if (CONST_OK_FOR_L (value)) /* Upper 16 bits were set. */
884 return "movhi hi(%1),%.,%0";
886 /* A random constant. */
887 else if (TARGET_V850E)
890 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
893 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
895 HOST_WIDE_INT high, low;
897 const_double_split (src, &high, &low);
899 if (CONST_OK_FOR_J (high)) /* Signed 5-bit immediate. */
902 else if (CONST_OK_FOR_K (high)) /* Signed 16-bit immediate. */
903 return "movea lo(%F1),%.,%0";
905 else if (CONST_OK_FOR_L (high)) /* Upper 16 bits were set. */
906 return "movhi hi(%F1),%.,%0";
908 /* A random constant. */
909 else if (TARGET_V850E)
913 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
916 else if (GET_CODE (src) == MEM)
917 return "%S1ld%W1 %1,%0";
919 else if (special_symbolref_operand (src, VOIDmode))
920 return "movea %O1(%P1),%Q1,%0";
922 else if (GET_CODE (src) == LABEL_REF
923 || GET_CODE (src) == SYMBOL_REF
924 || GET_CODE (src) == CONST)
927 return "mov hilo(%1),%0";
929 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
932 else if (GET_CODE (src) == HIGH)
933 return "movhi hi(%1),%.,%0";
935 else if (GET_CODE (src) == LO_SUM)
937 operands[2] = XEXP (src, 0);
938 operands[3] = XEXP (src, 1);
939 return "movea lo(%3),%2,%0";
943 else if (GET_CODE (dst) == MEM)
946 return "%S0st%W0 %1,%0";
948 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
949 return "%S0st%W0 %.,%0";
951 else if (GET_CODE (src) == CONST_DOUBLE
952 && CONST0_RTX (GET_MODE (dst)) == src)
953 return "%S0st%W0 %.,%0";
956 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
961 /* Return maximum offset supported for a short EP memory reference of mode
962 MODE and signedness UNSIGNEDP. */
965 ep_memory_offset (enum machine_mode mode, int unsignedp ATTRIBUTE_UNUSED)
972 if (TARGET_SMALL_SLD)
973 max_offset = (1 << 4);
974 else if (TARGET_V850E
975 && ( ( unsignedp && ! TARGET_US_BIT_SET)
976 || (! unsignedp && TARGET_US_BIT_SET)))
977 max_offset = (1 << 4);
979 max_offset = (1 << 7);
983 if (TARGET_SMALL_SLD)
984 max_offset = (1 << 5);
985 else if (TARGET_V850E
986 && ( ( unsignedp && ! TARGET_US_BIT_SET)
987 || (! unsignedp && TARGET_US_BIT_SET)))
988 max_offset = (1 << 5);
990 max_offset = (1 << 8);
995 max_offset = (1 << 8);
1005 /* Return true if OP is a valid short EP memory reference */
1008 ep_memory_operand (rtx op, enum machine_mode mode, int unsigned_load)
1014 /* If we are not using the EP register on a per-function basis
1015 then do not allow this optimization at all. This is to
1016 prevent the use of the SLD/SST instructions which cannot be
1017 guaranteed to work properly due to a hardware bug. */
1021 if (GET_CODE (op) != MEM)
1024 max_offset = ep_memory_offset (mode, unsigned_load);
1026 mask = GET_MODE_SIZE (mode) - 1;
1028 addr = XEXP (op, 0);
1029 if (GET_CODE (addr) == CONST)
1030 addr = XEXP (addr, 0);
1032 switch (GET_CODE (addr))
1038 return SYMBOL_REF_TDA_P (addr);
1041 return REGNO (addr) == EP_REGNUM;
1044 op0 = XEXP (addr, 0);
1045 op1 = XEXP (addr, 1);
1046 if (GET_CODE (op1) == CONST_INT
1047 && INTVAL (op1) < max_offset
1048 && INTVAL (op1) >= 0
1049 && (INTVAL (op1) & mask) == 0)
1051 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
1054 if (GET_CODE (op0) == SYMBOL_REF && SYMBOL_REF_TDA_P (op0))
1063 /* Substitute memory references involving a pointer, to use the ep pointer,
1064 taking care to save and preserve the ep. */
1067 substitute_ep_register (rtx first_insn,
1074 rtx reg = gen_rtx_REG (Pmode, regno);
1079 df_set_regs_ever_live (1, true);
1080 *p_r1 = gen_rtx_REG (Pmode, 1);
1081 *p_ep = gen_rtx_REG (Pmode, 30);
1086 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1087 2 * (uses - 3), uses, reg_names[regno],
1088 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1089 INSN_UID (first_insn), INSN_UID (last_insn));
1091 if (GET_CODE (first_insn) == NOTE)
1092 first_insn = next_nonnote_insn (first_insn);
1094 last_insn = next_nonnote_insn (last_insn);
1095 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1097 if (GET_CODE (insn) == INSN)
1099 rtx pattern = single_set (insn);
1101 /* Replace the memory references. */
1105 /* Memory operands are signed by default. */
1106 int unsignedp = FALSE;
1108 if (GET_CODE (SET_DEST (pattern)) == MEM
1109 && GET_CODE (SET_SRC (pattern)) == MEM)
1112 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1113 p_mem = &SET_DEST (pattern);
1115 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1116 p_mem = &SET_SRC (pattern);
1118 else if (GET_CODE (SET_SRC (pattern)) == SIGN_EXTEND
1119 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1120 p_mem = &XEXP (SET_SRC (pattern), 0);
1122 else if (GET_CODE (SET_SRC (pattern)) == ZERO_EXTEND
1123 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1125 p_mem = &XEXP (SET_SRC (pattern), 0);
1133 rtx addr = XEXP (*p_mem, 0);
1135 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1136 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1138 else if (GET_CODE (addr) == PLUS
1139 && GET_CODE (XEXP (addr, 0)) == REG
1140 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1141 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1142 && ((INTVAL (XEXP (addr, 1)))
1143 < ep_memory_offset (GET_MODE (*p_mem),
1145 && ((INTVAL (XEXP (addr, 1))) >= 0))
1146 *p_mem = change_address (*p_mem, VOIDmode,
1147 gen_rtx_PLUS (Pmode,
1155 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1156 insn = prev_nonnote_insn (first_insn);
1157 if (insn && GET_CODE (insn) == INSN
1158 && GET_CODE (PATTERN (insn)) == SET
1159 && SET_DEST (PATTERN (insn)) == *p_ep
1160 && SET_SRC (PATTERN (insn)) == *p_r1)
1163 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1165 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1166 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1170 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1171 the -mep mode to copy heavily used pointers to ep to use the implicit
1183 regs[FIRST_PSEUDO_REGISTER];
1192 /* If not ep mode, just return now. */
1196 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1199 regs[i].first_insn = NULL_RTX;
1200 regs[i].last_insn = NULL_RTX;
1203 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
1205 switch (GET_CODE (insn))
1207 /* End of basic block */
1214 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1216 if (max_uses < regs[i].uses)
1218 max_uses = regs[i].uses;
1224 substitute_ep_register (regs[max_regno].first_insn,
1225 regs[max_regno].last_insn,
1226 max_uses, max_regno, &r1, &ep);
1230 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1233 regs[i].first_insn = NULL_RTX;
1234 regs[i].last_insn = NULL_RTX;
1242 pattern = single_set (insn);
1244 /* See if there are any memory references we can shorten */
1247 rtx src = SET_SRC (pattern);
1248 rtx dest = SET_DEST (pattern);
1250 /* Memory operands are signed by default. */
1251 int unsignedp = FALSE;
1253 /* We might have (SUBREG (MEM)) here, so just get rid of the
1254 subregs to make this code simpler. */
1255 if (GET_CODE (dest) == SUBREG
1256 && (GET_CODE (SUBREG_REG (dest)) == MEM
1257 || GET_CODE (SUBREG_REG (dest)) == REG))
1258 alter_subreg (&dest);
1259 if (GET_CODE (src) == SUBREG
1260 && (GET_CODE (SUBREG_REG (src)) == MEM
1261 || GET_CODE (SUBREG_REG (src)) == REG))
1262 alter_subreg (&src);
1264 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1267 else if (GET_CODE (dest) == MEM)
1270 else if (GET_CODE (src) == MEM)
1273 else if (GET_CODE (src) == SIGN_EXTEND
1274 && GET_CODE (XEXP (src, 0)) == MEM)
1275 mem = XEXP (src, 0);
1277 else if (GET_CODE (src) == ZERO_EXTEND
1278 && GET_CODE (XEXP (src, 0)) == MEM)
1280 mem = XEXP (src, 0);
1286 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1289 else if (!use_ep && mem
1290 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1292 rtx addr = XEXP (mem, 0);
1296 if (GET_CODE (addr) == REG)
1299 regno = REGNO (addr);
1302 else if (GET_CODE (addr) == PLUS
1303 && GET_CODE (XEXP (addr, 0)) == REG
1304 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1305 && ((INTVAL (XEXP (addr, 1)))
1306 < ep_memory_offset (GET_MODE (mem), unsignedp))
1307 && ((INTVAL (XEXP (addr, 1))) >= 0))
1310 regno = REGNO (XEXP (addr, 0));
1319 regs[regno].last_insn = insn;
1320 if (!regs[regno].first_insn)
1321 regs[regno].first_insn = insn;
1325 /* Loading up a register in the basic block zaps any savings
1327 if (GET_CODE (dest) == REG)
1329 enum machine_mode mode = GET_MODE (dest);
1333 regno = REGNO (dest);
1334 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1338 /* See if we can use the pointer before this
1343 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1345 if (max_uses < regs[i].uses)
1347 max_uses = regs[i].uses;
1353 && max_regno >= regno
1354 && max_regno < endregno)
1356 substitute_ep_register (regs[max_regno].first_insn,
1357 regs[max_regno].last_insn,
1358 max_uses, max_regno, &r1,
1361 /* Since we made a substitution, zap all remembered
1363 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1366 regs[i].first_insn = NULL_RTX;
1367 regs[i].last_insn = NULL_RTX;
1372 for (i = regno; i < endregno; i++)
1375 regs[i].first_insn = NULL_RTX;
1376 regs[i].last_insn = NULL_RTX;
1385 /* # of registers saved by the interrupt handler. */
1386 #define INTERRUPT_FIXED_NUM 4
1388 /* # of bytes for registers saved by the interrupt handler. */
1389 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1391 /* # of registers saved in register parameter area. */
1392 #define INTERRUPT_REGPARM_NUM 4
1393 /* # of words saved for other registers. */
1394 #define INTERRUPT_ALL_SAVE_NUM \
1395 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1397 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1400 compute_register_save_size (long * p_reg_saved)
1404 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1405 int call_p = df_regs_ever_live_p (LINK_POINTER_REGNUM);
1408 /* Count the return pointer if we need to save it. */
1409 if (crtl->profile && !call_p)
1411 df_set_regs_ever_live (LINK_POINTER_REGNUM, true);
1415 /* Count space for the register saves. */
1416 if (interrupt_handler)
1418 for (i = 0; i <= 31; i++)
1422 if (df_regs_ever_live_p (i) || call_p)
1425 reg_saved |= 1L << i;
1429 /* We don't save/restore r0 or the stack pointer */
1431 case STACK_POINTER_REGNUM:
1434 /* For registers with fixed use, we save them, set them to the
1435 appropriate value, and then restore them.
1436 These registers are handled specially, so don't list them
1437 on the list of registers to save in the prologue. */
1438 case 1: /* temp used to hold ep */
1440 case 10: /* temp used to call interrupt save/restore */
1441 case EP_REGNUM: /* ep */
1448 /* Find the first register that needs to be saved. */
1449 for (i = 0; i <= 31; i++)
1450 if (df_regs_ever_live_p (i) && ((! call_used_regs[i])
1451 || i == LINK_POINTER_REGNUM))
1454 /* If it is possible that an out-of-line helper function might be
1455 used to generate the prologue for the current function, then we
1456 need to cover the possibility that such a helper function will
1457 be used, despite the fact that there might be gaps in the list of
1458 registers that need to be saved. To detect this we note that the
1459 helper functions always push at least register r29 (provided
1460 that the function is not an interrupt handler). */
1462 if (TARGET_PROLOG_FUNCTION
1463 && (i == 2 || ((i >= 20) && (i < 30))))
1468 reg_saved |= 1L << i;
1473 /* Helper functions save all registers between the starting
1474 register and the last register, regardless of whether they
1475 are actually used by the function or not. */
1476 for (; i <= 29; i++)
1479 reg_saved |= 1L << i;
1482 if (df_regs_ever_live_p (LINK_POINTER_REGNUM))
1485 reg_saved |= 1L << LINK_POINTER_REGNUM;
1490 for (; i <= 31; i++)
1491 if (df_regs_ever_live_p (i) && ((! call_used_regs[i])
1492 || i == LINK_POINTER_REGNUM))
1495 reg_saved |= 1L << i;
1501 *p_reg_saved = reg_saved;
1507 compute_frame_size (int size, long * p_reg_saved)
1510 + compute_register_save_size (p_reg_saved)
1511 + crtl->outgoing_args_size);
1516 expand_prologue (void)
1520 unsigned int size = get_frame_size ();
1521 unsigned int actual_fsize;
1522 unsigned int init_stack_alloc = 0;
1525 unsigned int num_save;
1526 unsigned int default_stack;
1528 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1531 actual_fsize = compute_frame_size (size, ®_saved);
1533 /* Save/setup global registers for interrupt functions right now. */
1534 if (interrupt_handler)
1536 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1537 emit_insn (gen_callt_save_interrupt ());
1539 emit_insn (gen_save_interrupt ());
1541 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1543 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1544 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1547 /* Save arg registers to the stack if necessary. */
1548 else if (crtl->args.info.anonymous_args)
1550 if (TARGET_PROLOG_FUNCTION && TARGET_V850E && !TARGET_DISABLE_CALLT)
1551 emit_insn (gen_save_r6_r9_v850e ());
1552 else if (TARGET_PROLOG_FUNCTION && ! TARGET_LONG_CALLS)
1553 emit_insn (gen_save_r6_r9 ());
1557 for (i = 6; i < 10; i++)
1559 emit_move_insn (gen_rtx_MEM (SImode,
1560 plus_constant (stack_pointer_rtx,
1562 gen_rtx_REG (SImode, i));
1568 /* Identify all of the saved registers. */
1571 for (i = 1; i < 31; i++)
1573 if (((1L << i) & reg_saved) != 0)
1574 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1577 /* If the return pointer is saved, the helper functions also allocate
1578 16 bytes of stack for arguments to be saved in. */
1579 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1581 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1585 /* See if we have an insn that allocates stack space and saves the particular
1586 registers we want to. */
1587 save_all = NULL_RTX;
1588 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1590 int alloc_stack = (4 * num_save) + default_stack;
1591 int unalloc_stack = actual_fsize - alloc_stack;
1592 int save_func_len = 4;
1593 int save_normal_len;
1596 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1598 /* see if we would have used ep to save the stack */
1599 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1600 save_normal_len = (3 * 2) + (2 * num_save);
1602 save_normal_len = 4 * num_save;
1604 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1606 /* Don't bother checking if we don't actually save any space.
1607 This happens for instance if one register is saved and additional
1608 stack space is allocated. */
1609 if (save_func_len < save_normal_len)
1611 save_all = gen_rtx_PARALLEL
1613 rtvec_alloc (num_save + 1
1614 + (TARGET_V850 ? (TARGET_LONG_CALLS ? 2 : 1) : 0)));
1616 XVECEXP (save_all, 0, 0)
1617 = gen_rtx_SET (VOIDmode,
1619 plus_constant (stack_pointer_rtx, -alloc_stack));
1621 offset = - default_stack;
1622 for (i = 0; i < num_save; i++)
1624 XVECEXP (save_all, 0, i+1)
1625 = gen_rtx_SET (VOIDmode,
1627 plus_constant (stack_pointer_rtx,
1635 XVECEXP (save_all, 0, num_save + 1)
1636 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1638 if (TARGET_LONG_CALLS)
1639 XVECEXP (save_all, 0, num_save + 2)
1640 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
1643 code = recog (save_all, NULL_RTX, NULL);
1646 rtx insn = emit_insn (save_all);
1647 INSN_CODE (insn) = code;
1648 actual_fsize -= alloc_stack;
1652 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1653 save_normal_len - save_func_len,
1654 save_normal_len, save_func_len,
1655 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1658 save_all = NULL_RTX;
1662 /* If no prolog save function is available, store the registers the old
1663 fashioned way (one by one). */
1666 /* Special case interrupt functions that save all registers for a call. */
1667 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1669 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1670 emit_insn (gen_callt_save_all_interrupt ());
1672 emit_insn (gen_save_all_interrupt ());
1676 /* If the stack is too big, allocate it in chunks so we can do the
1677 register saves. We use the register save size so we use the ep
1679 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1680 init_stack_alloc = compute_register_save_size (NULL);
1682 init_stack_alloc = actual_fsize;
1684 /* Save registers at the beginning of the stack frame. */
1685 offset = init_stack_alloc - 4;
1687 if (init_stack_alloc)
1688 emit_insn (gen_addsi3 (stack_pointer_rtx,
1690 GEN_INT (- (signed) init_stack_alloc)));
1692 /* Save the return pointer first. */
1693 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1695 emit_move_insn (gen_rtx_MEM (SImode,
1696 plus_constant (stack_pointer_rtx,
1698 save_regs[--num_save]);
1702 for (i = 0; i < num_save; i++)
1704 emit_move_insn (gen_rtx_MEM (SImode,
1705 plus_constant (stack_pointer_rtx,
1713 /* Allocate the rest of the stack that was not allocated above (either it is
1714 > 32K or we just called a function to save the registers and needed more
1716 if (actual_fsize > init_stack_alloc)
1718 int diff = actual_fsize - init_stack_alloc;
1719 if (CONST_OK_FOR_K (diff))
1720 emit_insn (gen_addsi3 (stack_pointer_rtx,
1725 rtx reg = gen_rtx_REG (Pmode, 12);
1726 emit_move_insn (reg, GEN_INT (-diff));
1727 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1731 /* If we need a frame pointer, set it up now. */
1732 if (frame_pointer_needed)
1733 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1738 expand_epilogue (void)
1742 unsigned int size = get_frame_size ();
1744 int actual_fsize = compute_frame_size (size, ®_saved);
1745 unsigned int init_stack_free = 0;
1746 rtx restore_regs[32];
1748 unsigned int num_restore;
1749 unsigned int default_stack;
1751 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1753 /* Eliminate the initial stack stored by interrupt functions. */
1754 if (interrupt_handler)
1756 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1757 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1758 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1761 /* Cut off any dynamic stack created. */
1762 if (frame_pointer_needed)
1763 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1765 /* Identify all of the saved registers. */
1768 for (i = 1; i < 31; i++)
1770 if (((1L << i) & reg_saved) != 0)
1771 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1774 /* If the return pointer is saved, the helper functions also allocate
1775 16 bytes of stack for arguments to be saved in. */
1776 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1778 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1782 /* See if we have an insn that restores the particular registers we
1784 restore_all = NULL_RTX;
1786 if (TARGET_PROLOG_FUNCTION
1788 && actual_fsize >= (signed) default_stack
1789 && !interrupt_handler)
1791 int alloc_stack = (4 * num_restore) + default_stack;
1792 int unalloc_stack = actual_fsize - alloc_stack;
1793 int restore_func_len = 4;
1794 int restore_normal_len;
1797 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1799 /* See if we would have used ep to restore the registers. */
1800 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1801 restore_normal_len = (3 * 2) + (2 * num_restore);
1803 restore_normal_len = 4 * num_restore;
1805 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1807 /* Don't bother checking if we don't actually save any space. */
1808 if (restore_func_len < restore_normal_len)
1810 restore_all = gen_rtx_PARALLEL (VOIDmode,
1811 rtvec_alloc (num_restore + 2));
1812 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1813 XVECEXP (restore_all, 0, 1)
1814 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1815 gen_rtx_PLUS (Pmode,
1817 GEN_INT (alloc_stack)));
1819 offset = alloc_stack - 4;
1820 for (i = 0; i < num_restore; i++)
1822 XVECEXP (restore_all, 0, i+2)
1823 = gen_rtx_SET (VOIDmode,
1826 plus_constant (stack_pointer_rtx,
1831 code = recog (restore_all, NULL_RTX, NULL);
1837 actual_fsize -= alloc_stack;
1840 if (CONST_OK_FOR_K (actual_fsize))
1841 emit_insn (gen_addsi3 (stack_pointer_rtx,
1843 GEN_INT (actual_fsize)));
1846 rtx reg = gen_rtx_REG (Pmode, 12);
1847 emit_move_insn (reg, GEN_INT (actual_fsize));
1848 emit_insn (gen_addsi3 (stack_pointer_rtx,
1854 insn = emit_jump_insn (restore_all);
1855 INSN_CODE (insn) = code;
1859 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1860 restore_normal_len - restore_func_len,
1861 restore_normal_len, restore_func_len,
1862 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1865 restore_all = NULL_RTX;
1869 /* If no epilogue save function is available, restore the registers the
1870 old fashioned way (one by one). */
1873 /* If the stack is large, we need to cut it down in 2 pieces. */
1874 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1875 init_stack_free = 4 * num_restore;
1877 init_stack_free = (signed) actual_fsize;
1879 /* Deallocate the rest of the stack if it is > 32K. */
1880 if ((unsigned int) actual_fsize > init_stack_free)
1884 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1886 if (CONST_OK_FOR_K (diff))
1887 emit_insn (gen_addsi3 (stack_pointer_rtx,
1892 rtx reg = gen_rtx_REG (Pmode, 12);
1893 emit_move_insn (reg, GEN_INT (diff));
1894 emit_insn (gen_addsi3 (stack_pointer_rtx,
1900 /* Special case interrupt functions that save all registers
1902 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1904 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1905 emit_insn (gen_callt_restore_all_interrupt ());
1907 emit_insn (gen_restore_all_interrupt ());
1911 /* Restore registers from the beginning of the stack frame. */
1912 offset = init_stack_free - 4;
1914 /* Restore the return pointer first. */
1916 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
1918 emit_move_insn (restore_regs[--num_restore],
1919 gen_rtx_MEM (SImode,
1920 plus_constant (stack_pointer_rtx,
1925 for (i = 0; i < num_restore; i++)
1927 emit_move_insn (restore_regs[i],
1928 gen_rtx_MEM (SImode,
1929 plus_constant (stack_pointer_rtx,
1932 emit_use (restore_regs[i]);
1936 /* Cut back the remainder of the stack. */
1937 if (init_stack_free)
1938 emit_insn (gen_addsi3 (stack_pointer_rtx,
1940 GEN_INT (init_stack_free)));
1943 /* And return or use reti for interrupt handlers. */
1944 if (interrupt_handler)
1946 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1947 emit_insn (gen_callt_return_interrupt ());
1949 emit_jump_insn (gen_return_interrupt ());
1951 else if (actual_fsize)
1952 emit_jump_insn (gen_return_internal ());
1954 emit_jump_insn (gen_return_simple ());
1957 v850_interrupt_cache_p = FALSE;
1958 v850_interrupt_p = FALSE;
1962 /* Update the condition code from the insn. */
1965 notice_update_cc (rtx body, rtx insn)
1967 switch (get_attr_cc (insn))
1970 /* Insn does not affect CC at all. */
1974 /* Insn does not change CC, but the 0'th operand has been changed. */
1975 if (cc_status.value1 != 0
1976 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1977 cc_status.value1 = 0;
1981 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1982 V,C is in an unusable state. */
1984 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1985 cc_status.value1 = recog_data.operand[0];
1989 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1990 C is in an unusable state. */
1992 cc_status.flags |= CC_NO_CARRY;
1993 cc_status.value1 = recog_data.operand[0];
1997 /* The insn is a compare instruction. */
1999 cc_status.value1 = SET_SRC (body);
2003 /* Insn doesn't leave CC in a usable state. */
2009 /* Retrieve the data area that has been chosen for the given decl. */
2012 v850_get_data_area (tree decl)
2014 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2015 return DATA_AREA_SDA;
2017 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2018 return DATA_AREA_TDA;
2020 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2021 return DATA_AREA_ZDA;
2023 return DATA_AREA_NORMAL;
2026 /* Store the indicated data area in the decl's attributes. */
2029 v850_set_data_area (tree decl, v850_data_area data_area)
2035 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2036 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2037 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2042 DECL_ATTRIBUTES (decl) = tree_cons
2043 (name, NULL, DECL_ATTRIBUTES (decl));
2046 /* Handle an "interrupt" attribute; arguments as in
2047 struct attribute_spec.handler. */
2049 v850_handle_interrupt_attribute (tree * node,
2051 tree args ATTRIBUTE_UNUSED,
2052 int flags ATTRIBUTE_UNUSED,
2053 bool * no_add_attrs)
2055 if (TREE_CODE (*node) != FUNCTION_DECL)
2057 warning (OPT_Wattributes, "%qE attribute only applies to functions",
2059 *no_add_attrs = true;
2065 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2066 struct attribute_spec.handler. */
2068 v850_handle_data_area_attribute (tree* node,
2070 tree args ATTRIBUTE_UNUSED,
2071 int flags ATTRIBUTE_UNUSED,
2072 bool * no_add_attrs)
2074 v850_data_area data_area;
2075 v850_data_area area;
2078 /* Implement data area attribute. */
2079 if (is_attribute_p ("sda", name))
2080 data_area = DATA_AREA_SDA;
2081 else if (is_attribute_p ("tda", name))
2082 data_area = DATA_AREA_TDA;
2083 else if (is_attribute_p ("zda", name))
2084 data_area = DATA_AREA_ZDA;
2088 switch (TREE_CODE (decl))
2091 if (current_function_decl != NULL_TREE)
2093 error ("%Jdata area attributes cannot be specified for "
2094 "local variables", decl);
2095 *no_add_attrs = true;
2101 area = v850_get_data_area (decl);
2102 if (area != DATA_AREA_NORMAL && data_area != area)
2104 error ("data area of %q+D conflicts with previous declaration",
2106 *no_add_attrs = true;
2118 /* Return nonzero if FUNC is an interrupt function as specified
2119 by the "interrupt" attribute. */
2122 v850_interrupt_function_p (tree func)
2127 if (v850_interrupt_cache_p)
2128 return v850_interrupt_p;
2130 if (TREE_CODE (func) != FUNCTION_DECL)
2133 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2139 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2140 ret = a != NULL_TREE;
2143 /* Its not safe to trust global variables until after function inlining has
2145 if (reload_completed | reload_in_progress)
2146 v850_interrupt_p = ret;
2153 v850_encode_data_area (tree decl, rtx symbol)
2157 /* Map explicit sections into the appropriate attribute */
2158 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2160 if (DECL_SECTION_NAME (decl))
2162 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2164 if (streq (name, ".zdata") || streq (name, ".zbss"))
2165 v850_set_data_area (decl, DATA_AREA_ZDA);
2167 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2168 v850_set_data_area (decl, DATA_AREA_SDA);
2170 else if (streq (name, ".tdata"))
2171 v850_set_data_area (decl, DATA_AREA_TDA);
2174 /* If no attribute, support -m{zda,sda,tda}=n */
2177 int size = int_size_in_bytes (TREE_TYPE (decl));
2181 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2182 v850_set_data_area (decl, DATA_AREA_TDA);
2184 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2185 v850_set_data_area (decl, DATA_AREA_SDA);
2187 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2188 v850_set_data_area (decl, DATA_AREA_ZDA);
2191 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2195 flags = SYMBOL_REF_FLAGS (symbol);
2196 switch (v850_get_data_area (decl))
2198 case DATA_AREA_ZDA: flags |= SYMBOL_FLAG_ZDA; break;
2199 case DATA_AREA_TDA: flags |= SYMBOL_FLAG_TDA; break;
2200 case DATA_AREA_SDA: flags |= SYMBOL_FLAG_SDA; break;
2201 default: gcc_unreachable ();
2203 SYMBOL_REF_FLAGS (symbol) = flags;
2207 v850_encode_section_info (tree decl, rtx rtl, int first)
2209 default_encode_section_info (decl, rtl, first);
2211 if (TREE_CODE (decl) == VAR_DECL
2212 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2213 v850_encode_data_area (decl, XEXP (rtl, 0));
2216 /* Construct a JR instruction to a routine that will perform the equivalent of
2217 the RTL passed in as an argument. This RTL is a function epilogue that
2218 pops registers off the stack and possibly releases some extra stack space
2219 as well. The code has already verified that the RTL matches these
2222 construct_restore_jr (rtx op)
2224 int count = XVECLEN (op, 0);
2226 unsigned long int mask;
2227 unsigned long int first;
2228 unsigned long int last;
2230 static char buff [100]; /* XXX */
2234 error ("bogus JR construction: %d", count);
2238 /* Work out how many bytes to pop off the stack before retrieving
2240 gcc_assert (GET_CODE (XVECEXP (op, 0, 1)) == SET);
2241 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS);
2242 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) == CONST_INT);
2244 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2246 /* Each pop will remove 4 bytes from the stack.... */
2247 stack_bytes -= (count - 2) * 4;
2249 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2250 if (stack_bytes != 0 && stack_bytes != 16)
2252 error ("bad amount of stack space removal: %d", stack_bytes);
2256 /* Now compute the bit mask of registers to push. */
2258 for (i = 2; i < count; i++)
2260 rtx vector_element = XVECEXP (op, 0, i);
2262 gcc_assert (GET_CODE (vector_element) == SET);
2263 gcc_assert (GET_CODE (SET_DEST (vector_element)) == REG);
2264 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element),
2267 mask |= 1 << REGNO (SET_DEST (vector_element));
2270 /* Scan for the first register to pop. */
2271 for (first = 0; first < 32; first++)
2273 if (mask & (1 << first))
2277 gcc_assert (first < 32);
2279 /* Discover the last register to pop. */
2280 if (mask & (1 << LINK_POINTER_REGNUM))
2282 gcc_assert (stack_bytes == 16);
2284 last = LINK_POINTER_REGNUM;
2288 gcc_assert (!stack_bytes);
2289 gcc_assert (mask & (1 << 29));
2294 /* Note, it is possible to have gaps in the register mask.
2295 We ignore this here, and generate a JR anyway. We will
2296 be popping more registers than is strictly necessary, but
2297 it does save code space. */
2299 if (TARGET_LONG_CALLS)
2304 sprintf (name, "__return_%s", reg_names [first]);
2306 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2308 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2314 sprintf (buff, "jr __return_%s", reg_names [first]);
2316 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2323 /* Construct a JARL instruction to a routine that will perform the equivalent
2324 of the RTL passed as a parameter. This RTL is a function prologue that
2325 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2326 some stack space as well. The code has already verified that the RTL
2327 matches these requirements. */
2329 construct_save_jarl (rtx op)
2331 int count = XVECLEN (op, 0);
2333 unsigned long int mask;
2334 unsigned long int first;
2335 unsigned long int last;
2337 static char buff [100]; /* XXX */
2341 error ("bogus JARL construction: %d\n", count);
2346 gcc_assert (GET_CODE (XVECEXP (op, 0, 0)) == SET);
2347 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) == PLUS);
2348 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) == REG);
2349 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) == CONST_INT);
2351 /* Work out how many bytes to push onto the stack after storing the
2353 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2355 /* Each push will put 4 bytes from the stack.... */
2356 stack_bytes += (count - (TARGET_LONG_CALLS ? 3 : 2)) * 4;
2358 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2359 if (stack_bytes != 0 && stack_bytes != -16)
2361 error ("bad amount of stack space removal: %d", stack_bytes);
2365 /* Now compute the bit mask of registers to push. */
2367 for (i = 1; i < count - (TARGET_LONG_CALLS ? 2 : 1); i++)
2369 rtx vector_element = XVECEXP (op, 0, i);
2371 gcc_assert (GET_CODE (vector_element) == SET);
2372 gcc_assert (GET_CODE (SET_SRC (vector_element)) == REG);
2373 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element),
2376 mask |= 1 << REGNO (SET_SRC (vector_element));
2379 /* Scan for the first register to push. */
2380 for (first = 0; first < 32; first++)
2382 if (mask & (1 << first))
2386 gcc_assert (first < 32);
2388 /* Discover the last register to push. */
2389 if (mask & (1 << LINK_POINTER_REGNUM))
2391 gcc_assert (stack_bytes == -16);
2393 last = LINK_POINTER_REGNUM;
2397 gcc_assert (!stack_bytes);
2398 gcc_assert (mask & (1 << 29));
2403 /* Note, it is possible to have gaps in the register mask.
2404 We ignore this here, and generate a JARL anyway. We will
2405 be pushing more registers than is strictly necessary, but
2406 it does save code space. */
2408 if (TARGET_LONG_CALLS)
2413 sprintf (name, "__save_%s", reg_names [first]);
2415 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2417 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2423 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2425 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2432 extern tree last_assemble_variable_decl;
2433 extern int size_directive_output;
2435 /* A version of asm_output_aligned_bss() that copes with the special
2436 data areas of the v850. */
2438 v850_output_aligned_bss (FILE * file,
2441 unsigned HOST_WIDE_INT size,
2444 switch (v850_get_data_area (decl))
2447 switch_to_section (zbss_section);
2451 switch_to_section (sbss_section);
2455 switch_to_section (tdata_section);
2458 switch_to_section (bss_section);
2462 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2463 #ifdef ASM_DECLARE_OBJECT_NAME
2464 last_assemble_variable_decl = decl;
2465 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2467 /* Standard thing is just output label for the object. */
2468 ASM_OUTPUT_LABEL (file, name);
2469 #endif /* ASM_DECLARE_OBJECT_NAME */
2470 ASM_OUTPUT_SKIP (file, size ? size : 1);
2473 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2475 v850_output_common (FILE * file,
2481 if (decl == NULL_TREE)
2483 fprintf (file, "%s", COMMON_ASM_OP);
2487 switch (v850_get_data_area (decl))
2490 fprintf (file, "%s", ZCOMMON_ASM_OP);
2494 fprintf (file, "%s", SCOMMON_ASM_OP);
2498 fprintf (file, "%s", TCOMMON_ASM_OP);
2502 fprintf (file, "%s", COMMON_ASM_OP);
2507 assemble_name (file, name);
2508 fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2511 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2513 v850_output_local (FILE * file,
2519 fprintf (file, "%s", LOCAL_ASM_OP);
2520 assemble_name (file, name);
2521 fprintf (file, "\n");
2523 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2526 /* Add data area to the given declaration if a ghs data area pragma is
2527 currently in effect (#pragma ghs startXXX/endXXX). */
2529 v850_insert_attributes (tree decl, tree * attr_ptr ATTRIBUTE_UNUSED )
2532 && data_area_stack->data_area
2533 && current_function_decl == NULL_TREE
2534 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2535 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2536 v850_set_data_area (decl, data_area_stack->data_area);
2538 /* Initialize the default names of the v850 specific sections,
2539 if this has not been done before. */
2541 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2543 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2544 = build_string (sizeof (".sdata")-1, ".sdata");
2546 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2547 = build_string (sizeof (".rosdata")-1, ".rosdata");
2549 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2550 = build_string (sizeof (".tdata")-1, ".tdata");
2552 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2553 = build_string (sizeof (".zdata")-1, ".zdata");
2555 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2556 = build_string (sizeof (".rozdata")-1, ".rozdata");
2559 if (current_function_decl == NULL_TREE
2560 && (TREE_CODE (decl) == VAR_DECL
2561 || TREE_CODE (decl) == CONST_DECL
2562 || TREE_CODE (decl) == FUNCTION_DECL)
2563 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2564 && !DECL_SECTION_NAME (decl))
2566 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2567 tree chosen_section;
2569 if (TREE_CODE (decl) == FUNCTION_DECL)
2570 kind = GHS_SECTION_KIND_TEXT;
2573 /* First choose a section kind based on the data area of the decl. */
2574 switch (v850_get_data_area (decl))
2580 kind = ((TREE_READONLY (decl))
2581 ? GHS_SECTION_KIND_ROSDATA
2582 : GHS_SECTION_KIND_SDATA);
2586 kind = GHS_SECTION_KIND_TDATA;
2590 kind = ((TREE_READONLY (decl))
2591 ? GHS_SECTION_KIND_ROZDATA
2592 : GHS_SECTION_KIND_ZDATA);
2595 case DATA_AREA_NORMAL: /* default data area */
2596 if (TREE_READONLY (decl))
2597 kind = GHS_SECTION_KIND_RODATA;
2598 else if (DECL_INITIAL (decl))
2599 kind = GHS_SECTION_KIND_DATA;
2601 kind = GHS_SECTION_KIND_BSS;
2605 /* Now, if the section kind has been explicitly renamed,
2606 then attach a section attribute. */
2607 chosen_section = GHS_current_section_names [(int) kind];
2609 /* Otherwise, if this kind of section needs an explicit section
2610 attribute, then also attach one. */
2611 if (chosen_section == NULL)
2612 chosen_section = GHS_default_section_names [(int) kind];
2616 /* Only set the section name if specified by a pragma, because
2617 otherwise it will force those variables to get allocated storage
2618 in this module, rather than by the linker. */
2619 DECL_SECTION_NAME (decl) = chosen_section;
2624 /* Construct a DISPOSE instruction that is the equivalent of
2625 the given RTX. We have already verified that this should
2629 construct_dispose_instruction (rtx op)
2631 int count = XVECLEN (op, 0);
2633 unsigned long int mask;
2635 static char buff[ 100 ]; /* XXX */
2640 error ("bogus DISPOSE construction: %d", count);
2644 /* Work out how many bytes to pop off the
2645 stack before retrieving registers. */
2646 gcc_assert (GET_CODE (XVECEXP (op, 0, 1)) == SET);
2647 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS);
2648 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) == CONST_INT);
2650 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2652 /* Each pop will remove 4 bytes from the stack.... */
2653 stack_bytes -= (count - 2) * 4;
2655 /* Make sure that the amount we are popping
2656 will fit into the DISPOSE instruction. */
2657 if (stack_bytes > 128)
2659 error ("too much stack space to dispose of: %d", stack_bytes);
2663 /* Now compute the bit mask of registers to push. */
2666 for (i = 2; i < count; i++)
2668 rtx vector_element = XVECEXP (op, 0, i);
2670 gcc_assert (GET_CODE (vector_element) == SET);
2671 gcc_assert (GET_CODE (SET_DEST (vector_element)) == REG);
2672 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element),
2675 if (REGNO (SET_DEST (vector_element)) == 2)
2678 mask |= 1 << REGNO (SET_DEST (vector_element));
2681 if (! TARGET_DISABLE_CALLT
2682 && (use_callt || stack_bytes == 0 || stack_bytes == 16))
2686 sprintf (buff, "callt ctoff(__callt_return_r2_r%d)", (mask & (1 << 31)) ? 31 : 29);
2691 for (i = 20; i < 32; i++)
2692 if (mask & (1 << i))
2696 sprintf (buff, "callt ctoff(__callt_return_r31c)");
2698 sprintf (buff, "callt ctoff(__callt_return_r%d_r%d%s)",
2699 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
2704 static char regs [100]; /* XXX */
2707 /* Generate the DISPOSE instruction. Note we could just issue the
2708 bit mask as a number as the assembler can cope with this, but for
2709 the sake of our readers we turn it into a textual description. */
2713 for (i = 20; i < 32; i++)
2715 if (mask & (1 << i))
2720 strcat (regs, ", ");
2725 strcat (regs, reg_names[ first ]);
2727 for (i++; i < 32; i++)
2728 if ((mask & (1 << i)) == 0)
2733 strcat (regs, " - ");
2734 strcat (regs, reg_names[ i - 1 ] );
2739 sprintf (buff, "dispose %d {%s}, r31", stack_bytes / 4, regs);
2745 /* Construct a PREPARE instruction that is the equivalent of
2746 the given RTL. We have already verified that this should
2750 construct_prepare_instruction (rtx op)
2752 int count = XVECLEN (op, 0);
2754 unsigned long int mask;
2756 static char buff[ 100 ]; /* XXX */
2761 error ("bogus PREPEARE construction: %d", count);
2765 /* Work out how many bytes to push onto
2766 the stack after storing the registers. */
2767 gcc_assert (GET_CODE (XVECEXP (op, 0, 0)) == SET);
2768 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) == PLUS);
2769 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) == CONST_INT);
2771 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2773 /* Each push will put 4 bytes from the stack. */
2774 stack_bytes += (count - 1) * 4;
2776 /* Make sure that the amount we are popping
2777 will fit into the DISPOSE instruction. */
2778 if (stack_bytes < -128)
2780 error ("too much stack space to prepare: %d", stack_bytes);
2784 /* Now compute the bit mask of registers to push. */
2786 for (i = 1; i < count; i++)
2788 rtx vector_element = XVECEXP (op, 0, i);
2790 gcc_assert (GET_CODE (vector_element) == SET);
2791 gcc_assert (GET_CODE (SET_SRC (vector_element)) == REG);
2792 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element),
2795 if (REGNO (SET_SRC (vector_element)) == 2)
2798 mask |= 1 << REGNO (SET_SRC (vector_element));
2801 if ((! TARGET_DISABLE_CALLT)
2802 && (use_callt || stack_bytes == 0 || stack_bytes == -16))
2806 sprintf (buff, "callt ctoff(__callt_save_r2_r%d)", (mask & (1 << 31)) ? 31 : 29 );
2810 for (i = 20; i < 32; i++)
2811 if (mask & (1 << i))
2815 sprintf (buff, "callt ctoff(__callt_save_r31c)");
2817 sprintf (buff, "callt ctoff(__callt_save_r%d_r%d%s)",
2818 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
2822 static char regs [100]; /* XXX */
2826 /* Generate the PREPARE instruction. Note we could just issue the
2827 bit mask as a number as the assembler can cope with this, but for
2828 the sake of our readers we turn it into a textual description. */
2832 for (i = 20; i < 32; i++)
2834 if (mask & (1 << i))
2839 strcat (regs, ", ");
2844 strcat (regs, reg_names[ first ]);
2846 for (i++; i < 32; i++)
2847 if ((mask & (1 << i)) == 0)
2852 strcat (regs, " - ");
2853 strcat (regs, reg_names[ i - 1 ] );
2858 sprintf (buff, "prepare {%s}, %d", regs, (- stack_bytes) / 4);
2864 /* Return an RTX indicating where the return address to the
2865 calling function can be found. */
2868 v850_return_addr (int count)
2873 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
2876 /* Implement TARGET_ASM_INIT_SECTIONS. */
2879 v850_asm_init_sections (void)
2882 = get_unnamed_section (0, output_section_asm_op,
2883 "\t.section .rosdata,\"a\"");
2886 = get_unnamed_section (0, output_section_asm_op,
2887 "\t.section .rozdata,\"a\"");
2890 = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
2891 "\t.section .tdata,\"aw\"");
2894 = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
2895 "\t.section .zdata,\"aw\"");
2898 = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
2899 output_section_asm_op,
2900 "\t.section .zbss,\"aw\"");
2904 v850_select_section (tree exp,
2905 int reloc ATTRIBUTE_UNUSED,
2906 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
2908 if (TREE_CODE (exp) == VAR_DECL)
2911 if (!TREE_READONLY (exp)
2912 || TREE_SIDE_EFFECTS (exp)
2913 || !DECL_INITIAL (exp)
2914 || (DECL_INITIAL (exp) != error_mark_node
2915 && !TREE_CONSTANT (DECL_INITIAL (exp))))
2920 switch (v850_get_data_area (exp))
2923 return is_const ? rozdata_section : zdata_section;
2926 return tdata_section;
2929 return is_const ? rosdata_section : sdata_section;
2932 return is_const ? readonly_data_section : data_section;
2935 return readonly_data_section;
2938 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2941 v850_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
2943 /* Return values > 8 bytes in length in memory. */
2944 return int_size_in_bytes (type) > 8 || TYPE_MODE (type) == BLKmode;
2947 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2950 v850_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
2951 enum machine_mode mode ATTRIBUTE_UNUSED,
2952 tree type ATTRIBUTE_UNUSED,
2953 int *pretend_arg_size ATTRIBUTE_UNUSED,
2954 int second_time ATTRIBUTE_UNUSED)
2956 ca->anonymous_args = (!TARGET_GHS ? 1 : 0);
2959 #include "gt-v850.h"