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 const struct attribute_spec v850_attribute_table
[];
62 static tree
v850_handle_interrupt_attribute (tree
*, tree
, tree
, int, bool *);
63 static tree
v850_handle_data_area_attribute (tree
*, tree
, tree
, int, bool *);
64 static void v850_insert_attributes (tree
, tree
*);
65 static void v850_asm_init_sections (void);
66 static section
*v850_select_section (tree
, int, unsigned HOST_WIDE_INT
);
67 static void v850_encode_data_area (tree
, rtx
);
68 static void v850_encode_section_info (tree
, rtx
, int);
69 static bool v850_return_in_memory (const_tree
, const_tree
);
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
,
77 /* Information about the various small memory areas. */
78 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
80 /* name max physical max */
86 /* Names of the various data areas used on the v850. */
87 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
88 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
90 /* Track the current data area set by the data area pragma (which
91 can be nested). Tested by check_default_data_area. */
92 data_area_stack_element
* data_area_stack
= NULL
;
94 /* True if we don't need to check any more if the current
95 function is an interrupt handler. */
96 static int v850_interrupt_cache_p
= FALSE
;
98 /* Whether current function is an interrupt handler. */
99 static int v850_interrupt_p
= FALSE
;
101 static GTY(()) section
*rosdata_section
;
102 static GTY(()) section
*rozdata_section
;
103 static GTY(()) section
*tdata_section
;
104 static GTY(()) section
*zdata_section
;
105 static GTY(()) section
*zbss_section
;
107 /* Initialize the GCC target structure. */
108 #undef TARGET_ASM_ALIGNED_HI_OP
109 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
111 #undef TARGET_ATTRIBUTE_TABLE
112 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
114 #undef TARGET_INSERT_ATTRIBUTES
115 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
117 #undef TARGET_ASM_SELECT_SECTION
118 #define TARGET_ASM_SELECT_SECTION v850_select_section
120 /* The assembler supports switchable .bss sections, but
121 v850_select_section doesn't yet make use of them. */
122 #undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
123 #define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS false
125 #undef TARGET_ENCODE_SECTION_INFO
126 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
128 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
129 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
131 #undef TARGET_DEFAULT_TARGET_FLAGS
132 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_DEFAULT | MASK_APP_REGS)
133 #undef TARGET_HANDLE_OPTION
134 #define TARGET_HANDLE_OPTION v850_handle_option
136 #undef TARGET_RTX_COSTS
137 #define TARGET_RTX_COSTS v850_rtx_costs
139 #undef TARGET_ADDRESS_COST
140 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
142 #undef TARGET_MACHINE_DEPENDENT_REORG
143 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
145 #undef TARGET_PROMOTE_PROTOTYPES
146 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
148 #undef TARGET_RETURN_IN_MEMORY
149 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
151 #undef TARGET_PASS_BY_REFERENCE
152 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
154 #undef TARGET_CALLEE_COPIES
155 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
157 #undef TARGET_SETUP_INCOMING_VARARGS
158 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
160 #undef TARGET_ARG_PARTIAL_BYTES
161 #define TARGET_ARG_PARTIAL_BYTES v850_arg_partial_bytes
163 struct gcc_target targetm
= TARGET_INITIALIZER
;
165 /* Set the maximum size of small memory area TYPE to the value given
166 by VALUE. Return true if VALUE was syntactically correct. VALUE
167 starts with the argument separator: either "-" or "=". */
170 v850_handle_memory_option (enum small_memory_type type
, const char *value
)
174 if (*value
!= '-' && *value
!= '=')
178 for (i
= 0; value
[i
]; i
++)
179 if (!ISDIGIT (value
[i
]))
183 if (size
> small_memory
[type
].physical_max
)
184 error ("value passed to %<-m%s%> is too large", small_memory
[type
].name
);
186 small_memory
[type
].max
= size
;
190 /* Implement TARGET_HANDLE_OPTION. */
193 v850_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
198 target_flags
|= MASK_EP
| MASK_PROLOG_FUNCTION
;
202 target_flags
&= ~(MASK_CPU
^ MASK_V850
);
207 target_flags
&= ~(MASK_CPU
^ MASK_V850E
);
211 return v850_handle_memory_option (SMALL_MEMORY_TDA
, arg
);
214 return v850_handle_memory_option (SMALL_MEMORY_SDA
, arg
);
217 return v850_handle_memory_option (SMALL_MEMORY_ZDA
, arg
);
225 v850_pass_by_reference (CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
226 enum machine_mode mode
, const_tree type
,
227 bool named ATTRIBUTE_UNUSED
)
229 unsigned HOST_WIDE_INT size
;
232 size
= int_size_in_bytes (type
);
234 size
= GET_MODE_SIZE (mode
);
239 /* Return an RTX to represent where a value with mode MODE will be returned
240 from a function. If the result is 0, the argument is pushed. */
243 function_arg (CUMULATIVE_ARGS
* cum
,
244 enum machine_mode mode
,
251 if (TARGET_GHS
&& !named
)
255 size
= int_size_in_bytes (type
);
257 size
= GET_MODE_SIZE (mode
);
263 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
267 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
269 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
272 if (type
== NULL_TREE
273 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
276 switch (cum
->nbytes
/ UNITS_PER_WORD
)
279 result
= gen_rtx_REG (mode
, 6);
282 result
= gen_rtx_REG (mode
, 7);
285 result
= gen_rtx_REG (mode
, 8);
288 result
= gen_rtx_REG (mode
, 9);
298 /* Return the number of bytes which must be put into registers
299 for values which are part in registers and part in memory. */
302 v850_arg_partial_bytes (CUMULATIVE_ARGS
* cum
, enum machine_mode mode
,
303 tree type
, bool named
)
307 if (TARGET_GHS
&& !named
)
311 size
= int_size_in_bytes (type
);
313 size
= GET_MODE_SIZE (mode
);
316 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
320 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
322 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
325 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
328 if (type
== NULL_TREE
329 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
332 return 4 * UNITS_PER_WORD
- cum
->nbytes
;
336 /* Return the high and low words of a CONST_DOUBLE */
339 const_double_split (rtx x
, HOST_WIDE_INT
* p_high
, HOST_WIDE_INT
* p_low
)
341 if (GET_CODE (x
) == CONST_DOUBLE
)
346 switch (GET_MODE (x
))
349 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
350 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
351 *p_high
= t
[1]; /* since v850 is little endian */
352 *p_low
= t
[0]; /* high is second word */
356 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
357 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
363 *p_high
= CONST_DOUBLE_HIGH (x
);
364 *p_low
= CONST_DOUBLE_LOW (x
);
372 fatal_insn ("const_double_split got a bad insn:", x
);
376 /* Return the cost of the rtx R with code CODE. */
379 const_costs_int (HOST_WIDE_INT value
, int zero_cost
)
381 if (CONST_OK_FOR_I (value
))
383 else if (CONST_OK_FOR_J (value
))
385 else if (CONST_OK_FOR_K (value
))
392 const_costs (rtx r
, enum rtx_code c
)
394 HOST_WIDE_INT high
, low
;
399 return const_costs_int (INTVAL (r
), 0);
402 const_double_split (r
, &high
, &low
);
403 if (GET_MODE (r
) == SFmode
)
404 return const_costs_int (high
, 1);
406 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
422 v850_rtx_costs (rtx x
,
424 int outer_code ATTRIBUTE_UNUSED
,
425 int * total
, bool speed
)
434 *total
= COSTS_N_INSNS (const_costs (x
, code
));
441 if (TARGET_V850E
&& !speed
)
449 && ( GET_MODE (x
) == SImode
450 || GET_MODE (x
) == HImode
451 || GET_MODE (x
) == QImode
))
453 if (GET_CODE (XEXP (x
, 1)) == REG
)
455 else if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
457 if (CONST_OK_FOR_O (INTVAL (XEXP (x
, 1))))
459 else if (CONST_OK_FOR_K (INTVAL (XEXP (x
, 1))))
468 if (outer_code
== COMPARE
)
477 /* Print operand X using operand code CODE to assembly language output file
481 print_operand (FILE * file
, rtx x
, int code
)
483 HOST_WIDE_INT high
, low
;
488 /* We use 'c' operands with symbols for .vtinherit */
489 if (GET_CODE (x
) == SYMBOL_REF
)
491 output_addr_const(file
, x
);
498 switch ((code
== 'B' || code
== 'C')
499 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
502 if (code
== 'c' || code
== 'C')
503 fprintf (file
, "nz");
505 fprintf (file
, "ne");
508 if (code
== 'c' || code
== 'C')
514 fprintf (file
, "ge");
517 fprintf (file
, "gt");
520 fprintf (file
, "le");
523 fprintf (file
, "lt");
526 fprintf (file
, "nl");
532 fprintf (file
, "nh");
541 case 'F': /* high word of CONST_DOUBLE */
542 switch (GET_CODE (x
))
545 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
549 const_double_split (x
, &high
, &low
);
550 fprintf (file
, "%ld", (long) high
);
557 case 'G': /* low word of CONST_DOUBLE */
558 switch (GET_CODE (x
))
561 fprintf (file
, "%ld", (long) INTVAL (x
));
565 const_double_split (x
, &high
, &low
);
566 fprintf (file
, "%ld", (long) low
);
574 fprintf (file
, "%d\n", (int)(INTVAL (x
) & 0xffff));
577 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
580 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
582 if (GET_CODE (x
) == CONST
)
583 x
= XEXP (XEXP (x
, 0), 0);
585 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
587 if (SYMBOL_REF_ZDA_P (x
))
588 fprintf (file
, "zdaoff");
589 else if (SYMBOL_REF_SDA_P (x
))
590 fprintf (file
, "sdaoff");
591 else if (SYMBOL_REF_TDA_P (x
))
592 fprintf (file
, "tdaoff");
597 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
598 output_addr_const (file
, x
);
601 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
603 if (GET_CODE (x
) == CONST
)
604 x
= XEXP (XEXP (x
, 0), 0);
606 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
608 if (SYMBOL_REF_ZDA_P (x
))
609 fprintf (file
, "r0");
610 else if (SYMBOL_REF_SDA_P (x
))
611 fprintf (file
, "gp");
612 else if (SYMBOL_REF_TDA_P (x
))
613 fprintf (file
, "ep");
617 case 'R': /* 2nd word of a double. */
618 switch (GET_CODE (x
))
621 fprintf (file
, reg_names
[REGNO (x
) + 1]);
624 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
625 print_operand_address (file
, x
);
626 if (GET_CODE (x
) == CONST_INT
)
627 fprintf (file
, "[r0]");
636 /* If it's a reference to a TDA variable, use sst/sld vs. st/ld. */
637 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
644 /* Like an 'S' operand above, but for unsigned loads only. */
645 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
650 case 'W': /* print the instruction suffix */
651 switch (GET_MODE (x
))
656 case QImode
: fputs (".b", file
); break;
657 case HImode
: fputs (".h", file
); break;
658 case SImode
: fputs (".w", file
); break;
659 case SFmode
: fputs (".w", file
); break;
662 case '.': /* register r0 */
663 fputs (reg_names
[0], file
);
665 case 'z': /* reg or zero */
666 if (GET_CODE (x
) == REG
)
667 fputs (reg_names
[REGNO (x
)], file
);
670 gcc_assert (x
== const0_rtx
);
671 fputs (reg_names
[0], file
);
675 switch (GET_CODE (x
))
678 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
679 output_address (gen_rtx_PLUS (SImode
, gen_rtx_REG (SImode
, 0),
682 output_address (XEXP (x
, 0));
686 fputs (reg_names
[REGNO (x
)], file
);
689 fputs (reg_names
[subreg_regno (x
)], file
);
696 print_operand_address (file
, x
);
707 /* Output assembly language output for the address ADDR to FILE. */
710 print_operand_address (FILE * file
, rtx addr
)
712 switch (GET_CODE (addr
))
715 fprintf (file
, "0[");
716 print_operand (file
, addr
, 0);
720 if (GET_CODE (XEXP (addr
, 0)) == REG
)
723 fprintf (file
, "lo(");
724 print_operand (file
, XEXP (addr
, 1), 0);
725 fprintf (file
, ")[");
726 print_operand (file
, XEXP (addr
, 0), 0);
731 if (GET_CODE (XEXP (addr
, 0)) == REG
732 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
735 print_operand (file
, XEXP (addr
, 1), 0);
737 print_operand (file
, XEXP (addr
, 0), 0);
742 print_operand (file
, XEXP (addr
, 0), 0);
744 print_operand (file
, XEXP (addr
, 1), 0);
749 const char *off_name
= NULL
;
750 const char *reg_name
= NULL
;
752 if (SYMBOL_REF_ZDA_P (addr
))
757 else if (SYMBOL_REF_SDA_P (addr
))
762 else if (SYMBOL_REF_TDA_P (addr
))
769 fprintf (file
, "%s(", off_name
);
770 output_addr_const (file
, addr
);
772 fprintf (file
, ")[%s]", reg_name
);
776 if (special_symbolref_operand (addr
, VOIDmode
))
778 rtx x
= XEXP (XEXP (addr
, 0), 0);
779 const char *off_name
;
780 const char *reg_name
;
782 if (SYMBOL_REF_ZDA_P (x
))
787 else if (SYMBOL_REF_SDA_P (x
))
792 else if (SYMBOL_REF_TDA_P (x
))
800 fprintf (file
, "%s(", off_name
);
801 output_addr_const (file
, addr
);
802 fprintf (file
, ")[%s]", reg_name
);
805 output_addr_const (file
, addr
);
808 output_addr_const (file
, addr
);
813 /* When assemble_integer is used to emit the offsets for a switch
814 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
815 output_addr_const will normally barf at this, but it is OK to omit
816 the truncate and just emit the difference of the two labels. The
817 .hword directive will automatically handle the truncation for us.
819 Returns 1 if rtx was handled, 0 otherwise. */
822 v850_output_addr_const_extra (FILE * file
, rtx x
)
824 if (GET_CODE (x
) != TRUNCATE
)
829 /* We must also handle the case where the switch table was passed a
830 constant value and so has been collapsed. In this case the first
831 label will have been deleted. In such a case it is OK to emit
832 nothing, since the table will not be used.
833 (cf gcc.c-torture/compile/990801-1.c). */
834 if (GET_CODE (x
) == MINUS
835 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
836 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
837 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
840 output_addr_const (file
, x
);
844 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
848 output_move_single (rtx
* operands
)
850 rtx dst
= operands
[0];
851 rtx src
= operands
[1];
858 else if (GET_CODE (src
) == CONST_INT
)
860 HOST_WIDE_INT value
= INTVAL (src
);
862 if (CONST_OK_FOR_J (value
)) /* Signed 5-bit immediate. */
865 else if (CONST_OK_FOR_K (value
)) /* Signed 16-bit immediate. */
866 return "movea lo(%1),%.,%0";
868 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
869 return "movhi hi(%1),%.,%0";
871 /* A random constant. */
872 else if (TARGET_V850E
)
875 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
878 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
880 HOST_WIDE_INT high
, low
;
882 const_double_split (src
, &high
, &low
);
884 if (CONST_OK_FOR_J (high
)) /* Signed 5-bit immediate. */
887 else if (CONST_OK_FOR_K (high
)) /* Signed 16-bit immediate. */
888 return "movea lo(%F1),%.,%0";
890 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
891 return "movhi hi(%F1),%.,%0";
893 /* A random constant. */
894 else if (TARGET_V850E
)
898 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
901 else if (GET_CODE (src
) == MEM
)
902 return "%S1ld%W1 %1,%0";
904 else if (special_symbolref_operand (src
, VOIDmode
))
905 return "movea %O1(%P1),%Q1,%0";
907 else if (GET_CODE (src
) == LABEL_REF
908 || GET_CODE (src
) == SYMBOL_REF
909 || GET_CODE (src
) == CONST
)
912 return "mov hilo(%1),%0";
914 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
917 else if (GET_CODE (src
) == HIGH
)
918 return "movhi hi(%1),%.,%0";
920 else if (GET_CODE (src
) == LO_SUM
)
922 operands
[2] = XEXP (src
, 0);
923 operands
[3] = XEXP (src
, 1);
924 return "movea lo(%3),%2,%0";
928 else if (GET_CODE (dst
) == MEM
)
931 return "%S0st%W0 %1,%0";
933 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
934 return "%S0st%W0 %.,%0";
936 else if (GET_CODE (src
) == CONST_DOUBLE
937 && CONST0_RTX (GET_MODE (dst
)) == src
)
938 return "%S0st%W0 %.,%0";
941 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
946 /* Return maximum offset supported for a short EP memory reference of mode
947 MODE and signedness UNSIGNEDP. */
950 ep_memory_offset (enum machine_mode mode
, int unsignedp ATTRIBUTE_UNUSED
)
957 if (TARGET_SMALL_SLD
)
958 max_offset
= (1 << 4);
959 else if (TARGET_V850E
960 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
961 || (! unsignedp
&& TARGET_US_BIT_SET
)))
962 max_offset
= (1 << 4);
964 max_offset
= (1 << 7);
968 if (TARGET_SMALL_SLD
)
969 max_offset
= (1 << 5);
970 else if (TARGET_V850E
971 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
972 || (! unsignedp
&& TARGET_US_BIT_SET
)))
973 max_offset
= (1 << 5);
975 max_offset
= (1 << 8);
980 max_offset
= (1 << 8);
990 /* Return true if OP is a valid short EP memory reference */
993 ep_memory_operand (rtx op
, enum machine_mode mode
, int unsigned_load
)
999 /* If we are not using the EP register on a per-function basis
1000 then do not allow this optimization at all. This is to
1001 prevent the use of the SLD/SST instructions which cannot be
1002 guaranteed to work properly due to a hardware bug. */
1006 if (GET_CODE (op
) != MEM
)
1009 max_offset
= ep_memory_offset (mode
, unsigned_load
);
1011 mask
= GET_MODE_SIZE (mode
) - 1;
1013 addr
= XEXP (op
, 0);
1014 if (GET_CODE (addr
) == CONST
)
1015 addr
= XEXP (addr
, 0);
1017 switch (GET_CODE (addr
))
1023 return SYMBOL_REF_TDA_P (addr
);
1026 return REGNO (addr
) == EP_REGNUM
;
1029 op0
= XEXP (addr
, 0);
1030 op1
= XEXP (addr
, 1);
1031 if (GET_CODE (op1
) == CONST_INT
1032 && INTVAL (op1
) < max_offset
1033 && INTVAL (op1
) >= 0
1034 && (INTVAL (op1
) & mask
) == 0)
1036 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1039 if (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_TDA_P (op0
))
1048 /* Substitute memory references involving a pointer, to use the ep pointer,
1049 taking care to save and preserve the ep. */
1052 substitute_ep_register (rtx first_insn
,
1059 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1064 df_set_regs_ever_live (1, true);
1065 *p_r1
= gen_rtx_REG (Pmode
, 1);
1066 *p_ep
= gen_rtx_REG (Pmode
, 30);
1071 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1072 2 * (uses
- 3), uses
, reg_names
[regno
],
1073 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1074 INSN_UID (first_insn
), INSN_UID (last_insn
));
1076 if (GET_CODE (first_insn
) == NOTE
)
1077 first_insn
= next_nonnote_insn (first_insn
);
1079 last_insn
= next_nonnote_insn (last_insn
);
1080 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1082 if (GET_CODE (insn
) == INSN
)
1084 rtx pattern
= single_set (insn
);
1086 /* Replace the memory references. */
1090 /* Memory operands are signed by default. */
1091 int unsignedp
= FALSE
;
1093 if (GET_CODE (SET_DEST (pattern
)) == MEM
1094 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1097 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1098 p_mem
= &SET_DEST (pattern
);
1100 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1101 p_mem
= &SET_SRC (pattern
);
1103 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1104 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1105 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1107 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1108 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1110 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1118 rtx addr
= XEXP (*p_mem
, 0);
1120 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1121 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1123 else if (GET_CODE (addr
) == PLUS
1124 && GET_CODE (XEXP (addr
, 0)) == REG
1125 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1126 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1127 && ((INTVAL (XEXP (addr
, 1)))
1128 < ep_memory_offset (GET_MODE (*p_mem
),
1130 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1131 *p_mem
= change_address (*p_mem
, VOIDmode
,
1132 gen_rtx_PLUS (Pmode
,
1140 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1141 insn
= prev_nonnote_insn (first_insn
);
1142 if (insn
&& GET_CODE (insn
) == INSN
1143 && GET_CODE (PATTERN (insn
)) == SET
1144 && SET_DEST (PATTERN (insn
)) == *p_ep
1145 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1148 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1150 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1151 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1155 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1156 the -mep mode to copy heavily used pointers to ep to use the implicit
1168 regs
[FIRST_PSEUDO_REGISTER
];
1177 /* If not ep mode, just return now. */
1181 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1184 regs
[i
].first_insn
= NULL_RTX
;
1185 regs
[i
].last_insn
= NULL_RTX
;
1188 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1190 switch (GET_CODE (insn
))
1192 /* End of basic block */
1199 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1201 if (max_uses
< regs
[i
].uses
)
1203 max_uses
= regs
[i
].uses
;
1209 substitute_ep_register (regs
[max_regno
].first_insn
,
1210 regs
[max_regno
].last_insn
,
1211 max_uses
, max_regno
, &r1
, &ep
);
1215 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1218 regs
[i
].first_insn
= NULL_RTX
;
1219 regs
[i
].last_insn
= NULL_RTX
;
1227 pattern
= single_set (insn
);
1229 /* See if there are any memory references we can shorten */
1232 rtx src
= SET_SRC (pattern
);
1233 rtx dest
= SET_DEST (pattern
);
1235 /* Memory operands are signed by default. */
1236 int unsignedp
= FALSE
;
1238 /* We might have (SUBREG (MEM)) here, so just get rid of the
1239 subregs to make this code simpler. */
1240 if (GET_CODE (dest
) == SUBREG
1241 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1242 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1243 alter_subreg (&dest
);
1244 if (GET_CODE (src
) == SUBREG
1245 && (GET_CODE (SUBREG_REG (src
)) == MEM
1246 || GET_CODE (SUBREG_REG (src
)) == REG
))
1247 alter_subreg (&src
);
1249 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1252 else if (GET_CODE (dest
) == MEM
)
1255 else if (GET_CODE (src
) == MEM
)
1258 else if (GET_CODE (src
) == SIGN_EXTEND
1259 && GET_CODE (XEXP (src
, 0)) == MEM
)
1260 mem
= XEXP (src
, 0);
1262 else if (GET_CODE (src
) == ZERO_EXTEND
1263 && GET_CODE (XEXP (src
, 0)) == MEM
)
1265 mem
= XEXP (src
, 0);
1271 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1274 else if (!use_ep
&& mem
1275 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1277 rtx addr
= XEXP (mem
, 0);
1281 if (GET_CODE (addr
) == REG
)
1284 regno
= REGNO (addr
);
1287 else if (GET_CODE (addr
) == PLUS
1288 && GET_CODE (XEXP (addr
, 0)) == REG
1289 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1290 && ((INTVAL (XEXP (addr
, 1)))
1291 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1292 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1295 regno
= REGNO (XEXP (addr
, 0));
1304 regs
[regno
].last_insn
= insn
;
1305 if (!regs
[regno
].first_insn
)
1306 regs
[regno
].first_insn
= insn
;
1310 /* Loading up a register in the basic block zaps any savings
1312 if (GET_CODE (dest
) == REG
)
1314 enum machine_mode mode
= GET_MODE (dest
);
1318 regno
= REGNO (dest
);
1319 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1323 /* See if we can use the pointer before this
1328 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1330 if (max_uses
< regs
[i
].uses
)
1332 max_uses
= regs
[i
].uses
;
1338 && max_regno
>= regno
1339 && max_regno
< endregno
)
1341 substitute_ep_register (regs
[max_regno
].first_insn
,
1342 regs
[max_regno
].last_insn
,
1343 max_uses
, max_regno
, &r1
,
1346 /* Since we made a substitution, zap all remembered
1348 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1351 regs
[i
].first_insn
= NULL_RTX
;
1352 regs
[i
].last_insn
= NULL_RTX
;
1357 for (i
= regno
; i
< endregno
; i
++)
1360 regs
[i
].first_insn
= NULL_RTX
;
1361 regs
[i
].last_insn
= NULL_RTX
;
1370 /* # of registers saved by the interrupt handler. */
1371 #define INTERRUPT_FIXED_NUM 4
1373 /* # of bytes for registers saved by the interrupt handler. */
1374 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1376 /* # of registers saved in register parameter area. */
1377 #define INTERRUPT_REGPARM_NUM 4
1378 /* # of words saved for other registers. */
1379 #define INTERRUPT_ALL_SAVE_NUM \
1380 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1382 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1385 compute_register_save_size (long * p_reg_saved
)
1389 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1390 int call_p
= df_regs_ever_live_p (LINK_POINTER_REGNUM
);
1393 /* Count the return pointer if we need to save it. */
1394 if (crtl
->profile
&& !call_p
)
1396 df_set_regs_ever_live (LINK_POINTER_REGNUM
, true);
1400 /* Count space for the register saves. */
1401 if (interrupt_handler
)
1403 for (i
= 0; i
<= 31; i
++)
1407 if (df_regs_ever_live_p (i
) || call_p
)
1410 reg_saved
|= 1L << i
;
1414 /* We don't save/restore r0 or the stack pointer */
1416 case STACK_POINTER_REGNUM
:
1419 /* For registers with fixed use, we save them, set them to the
1420 appropriate value, and then restore them.
1421 These registers are handled specially, so don't list them
1422 on the list of registers to save in the prologue. */
1423 case 1: /* temp used to hold ep */
1425 case 10: /* temp used to call interrupt save/restore */
1426 case EP_REGNUM
: /* ep */
1433 /* Find the first register that needs to be saved. */
1434 for (i
= 0; i
<= 31; i
++)
1435 if (df_regs_ever_live_p (i
) && ((! call_used_regs
[i
])
1436 || i
== LINK_POINTER_REGNUM
))
1439 /* If it is possible that an out-of-line helper function might be
1440 used to generate the prologue for the current function, then we
1441 need to cover the possibility that such a helper function will
1442 be used, despite the fact that there might be gaps in the list of
1443 registers that need to be saved. To detect this we note that the
1444 helper functions always push at least register r29 (provided
1445 that the function is not an interrupt handler). */
1447 if (TARGET_PROLOG_FUNCTION
1448 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1453 reg_saved
|= 1L << i
;
1458 /* Helper functions save all registers between the starting
1459 register and the last register, regardless of whether they
1460 are actually used by the function or not. */
1461 for (; i
<= 29; i
++)
1464 reg_saved
|= 1L << i
;
1467 if (df_regs_ever_live_p (LINK_POINTER_REGNUM
))
1470 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1475 for (; i
<= 31; i
++)
1476 if (df_regs_ever_live_p (i
) && ((! call_used_regs
[i
])
1477 || i
== LINK_POINTER_REGNUM
))
1480 reg_saved
|= 1L << i
;
1486 *p_reg_saved
= reg_saved
;
1492 compute_frame_size (int size
, long * p_reg_saved
)
1495 + compute_register_save_size (p_reg_saved
)
1496 + crtl
->outgoing_args_size
);
1501 expand_prologue (void)
1505 unsigned int size
= get_frame_size ();
1506 unsigned int actual_fsize
;
1507 unsigned int init_stack_alloc
= 0;
1510 unsigned int num_save
;
1511 unsigned int default_stack
;
1513 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1516 actual_fsize
= compute_frame_size (size
, ®_saved
);
1518 /* Save/setup global registers for interrupt functions right now. */
1519 if (interrupt_handler
)
1521 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1522 emit_insn (gen_callt_save_interrupt ());
1524 emit_insn (gen_save_interrupt ());
1526 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1528 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1529 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1532 /* Save arg registers to the stack if necessary. */
1533 else if (crtl
->args
.info
.anonymous_args
)
1535 if (TARGET_PROLOG_FUNCTION
&& TARGET_V850E
&& !TARGET_DISABLE_CALLT
)
1536 emit_insn (gen_save_r6_r9_v850e ());
1537 else if (TARGET_PROLOG_FUNCTION
&& ! TARGET_LONG_CALLS
)
1538 emit_insn (gen_save_r6_r9 ());
1542 for (i
= 6; i
< 10; i
++)
1544 emit_move_insn (gen_rtx_MEM (SImode
,
1545 plus_constant (stack_pointer_rtx
,
1547 gen_rtx_REG (SImode
, i
));
1553 /* Identify all of the saved registers. */
1556 for (i
= 1; i
< 31; i
++)
1558 if (((1L << i
) & reg_saved
) != 0)
1559 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1562 /* If the return pointer is saved, the helper functions also allocate
1563 16 bytes of stack for arguments to be saved in. */
1564 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1566 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1570 /* See if we have an insn that allocates stack space and saves the particular
1571 registers we want to. */
1572 save_all
= NULL_RTX
;
1573 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1575 int alloc_stack
= (4 * num_save
) + default_stack
;
1576 int unalloc_stack
= actual_fsize
- alloc_stack
;
1577 int save_func_len
= 4;
1578 int save_normal_len
;
1581 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1583 /* see if we would have used ep to save the stack */
1584 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1585 save_normal_len
= (3 * 2) + (2 * num_save
);
1587 save_normal_len
= 4 * num_save
;
1589 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1591 /* Don't bother checking if we don't actually save any space.
1592 This happens for instance if one register is saved and additional
1593 stack space is allocated. */
1594 if (save_func_len
< save_normal_len
)
1596 save_all
= gen_rtx_PARALLEL
1598 rtvec_alloc (num_save
+ 1
1599 + (TARGET_V850
? (TARGET_LONG_CALLS
? 2 : 1) : 0)));
1601 XVECEXP (save_all
, 0, 0)
1602 = gen_rtx_SET (VOIDmode
,
1604 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1606 offset
= - default_stack
;
1607 for (i
= 0; i
< num_save
; i
++)
1609 XVECEXP (save_all
, 0, i
+1)
1610 = gen_rtx_SET (VOIDmode
,
1612 plus_constant (stack_pointer_rtx
,
1620 XVECEXP (save_all
, 0, num_save
+ 1)
1621 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1623 if (TARGET_LONG_CALLS
)
1624 XVECEXP (save_all
, 0, num_save
+ 2)
1625 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 11));
1628 code
= recog (save_all
, NULL_RTX
, NULL
);
1631 rtx insn
= emit_insn (save_all
);
1632 INSN_CODE (insn
) = code
;
1633 actual_fsize
-= alloc_stack
;
1637 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1638 save_normal_len
- save_func_len
,
1639 save_normal_len
, save_func_len
,
1640 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1643 save_all
= NULL_RTX
;
1647 /* If no prolog save function is available, store the registers the old
1648 fashioned way (one by one). */
1651 /* Special case interrupt functions that save all registers for a call. */
1652 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1654 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1655 emit_insn (gen_callt_save_all_interrupt ());
1657 emit_insn (gen_save_all_interrupt ());
1661 /* If the stack is too big, allocate it in chunks so we can do the
1662 register saves. We use the register save size so we use the ep
1664 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1665 init_stack_alloc
= compute_register_save_size (NULL
);
1667 init_stack_alloc
= actual_fsize
;
1669 /* Save registers at the beginning of the stack frame. */
1670 offset
= init_stack_alloc
- 4;
1672 if (init_stack_alloc
)
1673 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1675 GEN_INT (- (signed) init_stack_alloc
)));
1677 /* Save the return pointer first. */
1678 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1680 emit_move_insn (gen_rtx_MEM (SImode
,
1681 plus_constant (stack_pointer_rtx
,
1683 save_regs
[--num_save
]);
1687 for (i
= 0; i
< num_save
; i
++)
1689 emit_move_insn (gen_rtx_MEM (SImode
,
1690 plus_constant (stack_pointer_rtx
,
1698 /* Allocate the rest of the stack that was not allocated above (either it is
1699 > 32K or we just called a function to save the registers and needed more
1701 if (actual_fsize
> init_stack_alloc
)
1703 int diff
= actual_fsize
- init_stack_alloc
;
1704 if (CONST_OK_FOR_K (diff
))
1705 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1710 rtx reg
= gen_rtx_REG (Pmode
, 12);
1711 emit_move_insn (reg
, GEN_INT (-diff
));
1712 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1716 /* If we need a frame pointer, set it up now. */
1717 if (frame_pointer_needed
)
1718 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1723 expand_epilogue (void)
1727 unsigned int size
= get_frame_size ();
1729 int actual_fsize
= compute_frame_size (size
, ®_saved
);
1730 unsigned int init_stack_free
= 0;
1731 rtx restore_regs
[32];
1733 unsigned int num_restore
;
1734 unsigned int default_stack
;
1736 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1738 /* Eliminate the initial stack stored by interrupt functions. */
1739 if (interrupt_handler
)
1741 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1742 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1743 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1746 /* Cut off any dynamic stack created. */
1747 if (frame_pointer_needed
)
1748 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1750 /* Identify all of the saved registers. */
1753 for (i
= 1; i
< 31; i
++)
1755 if (((1L << i
) & reg_saved
) != 0)
1756 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1759 /* If the return pointer is saved, the helper functions also allocate
1760 16 bytes of stack for arguments to be saved in. */
1761 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1763 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1767 /* See if we have an insn that restores the particular registers we
1769 restore_all
= NULL_RTX
;
1771 if (TARGET_PROLOG_FUNCTION
1773 && actual_fsize
>= (signed) default_stack
1774 && !interrupt_handler
)
1776 int alloc_stack
= (4 * num_restore
) + default_stack
;
1777 int unalloc_stack
= actual_fsize
- alloc_stack
;
1778 int restore_func_len
= 4;
1779 int restore_normal_len
;
1782 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1784 /* See if we would have used ep to restore the registers. */
1785 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1786 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1788 restore_normal_len
= 4 * num_restore
;
1790 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1792 /* Don't bother checking if we don't actually save any space. */
1793 if (restore_func_len
< restore_normal_len
)
1795 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1796 rtvec_alloc (num_restore
+ 2));
1797 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1798 XVECEXP (restore_all
, 0, 1)
1799 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1800 gen_rtx_PLUS (Pmode
,
1802 GEN_INT (alloc_stack
)));
1804 offset
= alloc_stack
- 4;
1805 for (i
= 0; i
< num_restore
; i
++)
1807 XVECEXP (restore_all
, 0, i
+2)
1808 = gen_rtx_SET (VOIDmode
,
1811 plus_constant (stack_pointer_rtx
,
1816 code
= recog (restore_all
, NULL_RTX
, NULL
);
1822 actual_fsize
-= alloc_stack
;
1825 if (CONST_OK_FOR_K (actual_fsize
))
1826 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1828 GEN_INT (actual_fsize
)));
1831 rtx reg
= gen_rtx_REG (Pmode
, 12);
1832 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1833 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1839 insn
= emit_jump_insn (restore_all
);
1840 INSN_CODE (insn
) = code
;
1844 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1845 restore_normal_len
- restore_func_len
,
1846 restore_normal_len
, restore_func_len
,
1847 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1850 restore_all
= NULL_RTX
;
1854 /* If no epilogue save function is available, restore the registers the
1855 old fashioned way (one by one). */
1858 /* If the stack is large, we need to cut it down in 2 pieces. */
1859 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1860 init_stack_free
= 4 * num_restore
;
1862 init_stack_free
= (signed) actual_fsize
;
1864 /* Deallocate the rest of the stack if it is > 32K. */
1865 if (actual_fsize
> init_stack_free
)
1869 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
1871 if (CONST_OK_FOR_K (diff
))
1872 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1877 rtx reg
= gen_rtx_REG (Pmode
, 12);
1878 emit_move_insn (reg
, GEN_INT (diff
));
1879 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1885 /* Special case interrupt functions that save all registers
1887 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1889 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1890 emit_insn (gen_callt_restore_all_interrupt ());
1892 emit_insn (gen_restore_all_interrupt ());
1896 /* Restore registers from the beginning of the stack frame. */
1897 offset
= init_stack_free
- 4;
1899 /* Restore the return pointer first. */
1901 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
1903 emit_move_insn (restore_regs
[--num_restore
],
1904 gen_rtx_MEM (SImode
,
1905 plus_constant (stack_pointer_rtx
,
1910 for (i
= 0; i
< num_restore
; i
++)
1912 emit_move_insn (restore_regs
[i
],
1913 gen_rtx_MEM (SImode
,
1914 plus_constant (stack_pointer_rtx
,
1917 emit_use (restore_regs
[i
]);
1921 /* Cut back the remainder of the stack. */
1922 if (init_stack_free
)
1923 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1925 GEN_INT (init_stack_free
)));
1928 /* And return or use reti for interrupt handlers. */
1929 if (interrupt_handler
)
1931 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1932 emit_insn (gen_callt_return_interrupt ());
1934 emit_jump_insn (gen_return_interrupt ());
1936 else if (actual_fsize
)
1937 emit_jump_insn (gen_return_internal ());
1939 emit_jump_insn (gen_return_simple ());
1942 v850_interrupt_cache_p
= FALSE
;
1943 v850_interrupt_p
= FALSE
;
1947 /* Update the condition code from the insn. */
1950 notice_update_cc (rtx body
, rtx insn
)
1952 switch (get_attr_cc (insn
))
1955 /* Insn does not affect CC at all. */
1959 /* Insn does not change CC, but the 0'th operand has been changed. */
1960 if (cc_status
.value1
!= 0
1961 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
1962 cc_status
.value1
= 0;
1966 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1967 V,C is in an unusable state. */
1969 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
1970 cc_status
.value1
= recog_data
.operand
[0];
1974 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1975 C is in an unusable state. */
1977 cc_status
.flags
|= CC_NO_CARRY
;
1978 cc_status
.value1
= recog_data
.operand
[0];
1982 /* The insn is a compare instruction. */
1984 cc_status
.value1
= SET_SRC (body
);
1988 /* Insn doesn't leave CC in a usable state. */
1994 /* Retrieve the data area that has been chosen for the given decl. */
1997 v850_get_data_area (tree decl
)
1999 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2000 return DATA_AREA_SDA
;
2002 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2003 return DATA_AREA_TDA
;
2005 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2006 return DATA_AREA_ZDA
;
2008 return DATA_AREA_NORMAL
;
2011 /* Store the indicated data area in the decl's attributes. */
2014 v850_set_data_area (tree decl
, v850_data_area data_area
)
2020 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2021 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2022 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2027 DECL_ATTRIBUTES (decl
) = tree_cons
2028 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2031 const struct attribute_spec v850_attribute_table
[] =
2033 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2034 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2035 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2036 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2037 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2038 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2039 { NULL
, 0, 0, false, false, false, NULL
}
2042 /* Handle an "interrupt" attribute; arguments as in
2043 struct attribute_spec.handler. */
2045 v850_handle_interrupt_attribute (tree
* node
,
2047 tree args ATTRIBUTE_UNUSED
,
2048 int flags ATTRIBUTE_UNUSED
,
2049 bool * no_add_attrs
)
2051 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2053 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
2055 *no_add_attrs
= true;
2061 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2062 struct attribute_spec.handler. */
2064 v850_handle_data_area_attribute (tree
* node
,
2066 tree args ATTRIBUTE_UNUSED
,
2067 int flags ATTRIBUTE_UNUSED
,
2068 bool * no_add_attrs
)
2070 v850_data_area data_area
;
2071 v850_data_area area
;
2074 /* Implement data area attribute. */
2075 if (is_attribute_p ("sda", name
))
2076 data_area
= DATA_AREA_SDA
;
2077 else if (is_attribute_p ("tda", name
))
2078 data_area
= DATA_AREA_TDA
;
2079 else if (is_attribute_p ("zda", name
))
2080 data_area
= DATA_AREA_ZDA
;
2084 switch (TREE_CODE (decl
))
2087 if (current_function_decl
!= NULL_TREE
)
2089 error ("%Jdata area attributes cannot be specified for "
2090 "local variables", decl
);
2091 *no_add_attrs
= true;
2097 area
= v850_get_data_area (decl
);
2098 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2100 error ("data area of %q+D conflicts with previous declaration",
2102 *no_add_attrs
= true;
2114 /* Return nonzero if FUNC is an interrupt function as specified
2115 by the "interrupt" attribute. */
2118 v850_interrupt_function_p (tree func
)
2123 if (v850_interrupt_cache_p
)
2124 return v850_interrupt_p
;
2126 if (TREE_CODE (func
) != FUNCTION_DECL
)
2129 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2135 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2136 ret
= a
!= NULL_TREE
;
2139 /* Its not safe to trust global variables until after function inlining has
2141 if (reload_completed
| reload_in_progress
)
2142 v850_interrupt_p
= ret
;
2149 v850_encode_data_area (tree decl
, rtx symbol
)
2153 /* Map explicit sections into the appropriate attribute */
2154 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2156 if (DECL_SECTION_NAME (decl
))
2158 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2160 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2161 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2163 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2164 v850_set_data_area (decl
, DATA_AREA_SDA
);
2166 else if (streq (name
, ".tdata"))
2167 v850_set_data_area (decl
, DATA_AREA_TDA
);
2170 /* If no attribute, support -m{zda,sda,tda}=n */
2173 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2177 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2178 v850_set_data_area (decl
, DATA_AREA_TDA
);
2180 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2181 v850_set_data_area (decl
, DATA_AREA_SDA
);
2183 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2184 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2187 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2191 flags
= SYMBOL_REF_FLAGS (symbol
);
2192 switch (v850_get_data_area (decl
))
2194 case DATA_AREA_ZDA
: flags
|= SYMBOL_FLAG_ZDA
; break;
2195 case DATA_AREA_TDA
: flags
|= SYMBOL_FLAG_TDA
; break;
2196 case DATA_AREA_SDA
: flags
|= SYMBOL_FLAG_SDA
; break;
2197 default: gcc_unreachable ();
2199 SYMBOL_REF_FLAGS (symbol
) = flags
;
2203 v850_encode_section_info (tree decl
, rtx rtl
, int first
)
2205 default_encode_section_info (decl
, rtl
, first
);
2207 if (TREE_CODE (decl
) == VAR_DECL
2208 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2209 v850_encode_data_area (decl
, XEXP (rtl
, 0));
2212 /* Construct a JR instruction to a routine that will perform the equivalent of
2213 the RTL passed in as an argument. This RTL is a function epilogue that
2214 pops registers off the stack and possibly releases some extra stack space
2215 as well. The code has already verified that the RTL matches these
2218 construct_restore_jr (rtx op
)
2220 int count
= XVECLEN (op
, 0);
2222 unsigned long int mask
;
2223 unsigned long int first
;
2224 unsigned long int last
;
2226 static char buff
[100]; /* XXX */
2230 error ("bogus JR construction: %d", count
);
2234 /* Work out how many bytes to pop off the stack before retrieving
2236 gcc_assert (GET_CODE (XVECEXP (op
, 0, 1)) == SET
);
2237 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) == PLUS
);
2238 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) == CONST_INT
);
2240 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2242 /* Each pop will remove 4 bytes from the stack.... */
2243 stack_bytes
-= (count
- 2) * 4;
2245 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2246 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2248 error ("bad amount of stack space removal: %d", stack_bytes
);
2252 /* Now compute the bit mask of registers to push. */
2254 for (i
= 2; i
< count
; i
++)
2256 rtx vector_element
= XVECEXP (op
, 0, i
);
2258 gcc_assert (GET_CODE (vector_element
) == SET
);
2259 gcc_assert (GET_CODE (SET_DEST (vector_element
)) == REG
);
2260 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element
),
2263 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2266 /* Scan for the first register to pop. */
2267 for (first
= 0; first
< 32; first
++)
2269 if (mask
& (1 << first
))
2273 gcc_assert (first
< 32);
2275 /* Discover the last register to pop. */
2276 if (mask
& (1 << LINK_POINTER_REGNUM
))
2278 gcc_assert (stack_bytes
== 16);
2280 last
= LINK_POINTER_REGNUM
;
2284 gcc_assert (!stack_bytes
);
2285 gcc_assert (mask
& (1 << 29));
2290 /* Note, it is possible to have gaps in the register mask.
2291 We ignore this here, and generate a JR anyway. We will
2292 be popping more registers than is strictly necessary, but
2293 it does save code space. */
2295 if (TARGET_LONG_CALLS
)
2300 sprintf (name
, "__return_%s", reg_names
[first
]);
2302 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2304 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2310 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2312 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2319 /* Construct a JARL instruction to a routine that will perform the equivalent
2320 of the RTL passed as a parameter. This RTL is a function prologue that
2321 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2322 some stack space as well. The code has already verified that the RTL
2323 matches these requirements. */
2325 construct_save_jarl (rtx op
)
2327 int count
= XVECLEN (op
, 0);
2329 unsigned long int mask
;
2330 unsigned long int first
;
2331 unsigned long int last
;
2333 static char buff
[100]; /* XXX */
2337 error ("bogus JARL construction: %d\n", count
);
2342 gcc_assert (GET_CODE (XVECEXP (op
, 0, 0)) == SET
);
2343 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) == PLUS
);
2344 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) == REG
);
2345 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) == CONST_INT
);
2347 /* Work out how many bytes to push onto the stack after storing the
2349 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2351 /* Each push will put 4 bytes from the stack.... */
2352 stack_bytes
+= (count
- (TARGET_LONG_CALLS
? 3 : 2)) * 4;
2354 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2355 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2357 error ("bad amount of stack space removal: %d", stack_bytes
);
2361 /* Now compute the bit mask of registers to push. */
2363 for (i
= 1; i
< count
- (TARGET_LONG_CALLS
? 2 : 1); i
++)
2365 rtx vector_element
= XVECEXP (op
, 0, i
);
2367 gcc_assert (GET_CODE (vector_element
) == SET
);
2368 gcc_assert (GET_CODE (SET_SRC (vector_element
)) == REG
);
2369 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element
),
2372 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2375 /* Scan for the first register to push. */
2376 for (first
= 0; first
< 32; first
++)
2378 if (mask
& (1 << first
))
2382 gcc_assert (first
< 32);
2384 /* Discover the last register to push. */
2385 if (mask
& (1 << LINK_POINTER_REGNUM
))
2387 gcc_assert (stack_bytes
== -16);
2389 last
= LINK_POINTER_REGNUM
;
2393 gcc_assert (!stack_bytes
);
2394 gcc_assert (mask
& (1 << 29));
2399 /* Note, it is possible to have gaps in the register mask.
2400 We ignore this here, and generate a JARL anyway. We will
2401 be pushing more registers than is strictly necessary, but
2402 it does save code space. */
2404 if (TARGET_LONG_CALLS
)
2409 sprintf (name
, "__save_%s", reg_names
[first
]);
2411 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2413 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2419 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2421 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2428 extern tree last_assemble_variable_decl
;
2429 extern int size_directive_output
;
2431 /* A version of asm_output_aligned_bss() that copes with the special
2432 data areas of the v850. */
2434 v850_output_aligned_bss (FILE * file
,
2437 unsigned HOST_WIDE_INT size
,
2440 switch (v850_get_data_area (decl
))
2443 switch_to_section (zbss_section
);
2447 switch_to_section (sbss_section
);
2451 switch_to_section (tdata_section
);
2454 switch_to_section (bss_section
);
2458 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2459 #ifdef ASM_DECLARE_OBJECT_NAME
2460 last_assemble_variable_decl
= decl
;
2461 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2463 /* Standard thing is just output label for the object. */
2464 ASM_OUTPUT_LABEL (file
, name
);
2465 #endif /* ASM_DECLARE_OBJECT_NAME */
2466 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2469 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2471 v850_output_common (FILE * file
,
2477 if (decl
== NULL_TREE
)
2479 fprintf (file
, "%s", COMMON_ASM_OP
);
2483 switch (v850_get_data_area (decl
))
2486 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2490 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2494 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2498 fprintf (file
, "%s", COMMON_ASM_OP
);
2503 assemble_name (file
, name
);
2504 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2507 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2509 v850_output_local (FILE * file
,
2515 fprintf (file
, "%s", LOCAL_ASM_OP
);
2516 assemble_name (file
, name
);
2517 fprintf (file
, "\n");
2519 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2522 /* Add data area to the given declaration if a ghs data area pragma is
2523 currently in effect (#pragma ghs startXXX/endXXX). */
2525 v850_insert_attributes (tree decl
, tree
* attr_ptr ATTRIBUTE_UNUSED
)
2528 && data_area_stack
->data_area
2529 && current_function_decl
== NULL_TREE
2530 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2531 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2532 v850_set_data_area (decl
, data_area_stack
->data_area
);
2534 /* Initialize the default names of the v850 specific sections,
2535 if this has not been done before. */
2537 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2539 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2540 = build_string (sizeof (".sdata")-1, ".sdata");
2542 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2543 = build_string (sizeof (".rosdata")-1, ".rosdata");
2545 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2546 = build_string (sizeof (".tdata")-1, ".tdata");
2548 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2549 = build_string (sizeof (".zdata")-1, ".zdata");
2551 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2552 = build_string (sizeof (".rozdata")-1, ".rozdata");
2555 if (current_function_decl
== NULL_TREE
2556 && (TREE_CODE (decl
) == VAR_DECL
2557 || TREE_CODE (decl
) == CONST_DECL
2558 || TREE_CODE (decl
) == FUNCTION_DECL
)
2559 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2560 && !DECL_SECTION_NAME (decl
))
2562 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2563 tree chosen_section
;
2565 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2566 kind
= GHS_SECTION_KIND_TEXT
;
2569 /* First choose a section kind based on the data area of the decl. */
2570 switch (v850_get_data_area (decl
))
2576 kind
= ((TREE_READONLY (decl
))
2577 ? GHS_SECTION_KIND_ROSDATA
2578 : GHS_SECTION_KIND_SDATA
);
2582 kind
= GHS_SECTION_KIND_TDATA
;
2586 kind
= ((TREE_READONLY (decl
))
2587 ? GHS_SECTION_KIND_ROZDATA
2588 : GHS_SECTION_KIND_ZDATA
);
2591 case DATA_AREA_NORMAL
: /* default data area */
2592 if (TREE_READONLY (decl
))
2593 kind
= GHS_SECTION_KIND_RODATA
;
2594 else if (DECL_INITIAL (decl
))
2595 kind
= GHS_SECTION_KIND_DATA
;
2597 kind
= GHS_SECTION_KIND_BSS
;
2601 /* Now, if the section kind has been explicitly renamed,
2602 then attach a section attribute. */
2603 chosen_section
= GHS_current_section_names
[(int) kind
];
2605 /* Otherwise, if this kind of section needs an explicit section
2606 attribute, then also attach one. */
2607 if (chosen_section
== NULL
)
2608 chosen_section
= GHS_default_section_names
[(int) kind
];
2612 /* Only set the section name if specified by a pragma, because
2613 otherwise it will force those variables to get allocated storage
2614 in this module, rather than by the linker. */
2615 DECL_SECTION_NAME (decl
) = chosen_section
;
2620 /* Construct a DISPOSE instruction that is the equivalent of
2621 the given RTX. We have already verified that this should
2625 construct_dispose_instruction (rtx op
)
2627 int count
= XVECLEN (op
, 0);
2629 unsigned long int mask
;
2631 static char buff
[ 100 ]; /* XXX */
2636 error ("bogus DISPOSE construction: %d", count
);
2640 /* Work out how many bytes to pop off the
2641 stack before retrieving registers. */
2642 gcc_assert (GET_CODE (XVECEXP (op
, 0, 1)) == SET
);
2643 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) == PLUS
);
2644 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) == CONST_INT
);
2646 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2648 /* Each pop will remove 4 bytes from the stack.... */
2649 stack_bytes
-= (count
- 2) * 4;
2651 /* Make sure that the amount we are popping
2652 will fit into the DISPOSE instruction. */
2653 if (stack_bytes
> 128)
2655 error ("too much stack space to dispose of: %d", stack_bytes
);
2659 /* Now compute the bit mask of registers to push. */
2662 for (i
= 2; i
< count
; i
++)
2664 rtx vector_element
= XVECEXP (op
, 0, i
);
2666 gcc_assert (GET_CODE (vector_element
) == SET
);
2667 gcc_assert (GET_CODE (SET_DEST (vector_element
)) == REG
);
2668 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element
),
2671 if (REGNO (SET_DEST (vector_element
)) == 2)
2674 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2677 if (! TARGET_DISABLE_CALLT
2678 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
2682 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
2687 for (i
= 20; i
< 32; i
++)
2688 if (mask
& (1 << i
))
2692 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
2694 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
2695 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
2700 static char regs
[100]; /* XXX */
2703 /* Generate the DISPOSE instruction. Note we could just issue the
2704 bit mask as a number as the assembler can cope with this, but for
2705 the sake of our readers we turn it into a textual description. */
2709 for (i
= 20; i
< 32; i
++)
2711 if (mask
& (1 << i
))
2716 strcat (regs
, ", ");
2721 strcat (regs
, reg_names
[ first
]);
2723 for (i
++; i
< 32; i
++)
2724 if ((mask
& (1 << i
)) == 0)
2729 strcat (regs
, " - ");
2730 strcat (regs
, reg_names
[ i
- 1 ] );
2735 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
2741 /* Construct a PREPARE instruction that is the equivalent of
2742 the given RTL. We have already verified that this should
2746 construct_prepare_instruction (rtx op
)
2748 int count
= XVECLEN (op
, 0);
2750 unsigned long int mask
;
2752 static char buff
[ 100 ]; /* XXX */
2757 error ("bogus PREPEARE construction: %d", count
);
2761 /* Work out how many bytes to push onto
2762 the stack after storing the registers. */
2763 gcc_assert (GET_CODE (XVECEXP (op
, 0, 0)) == SET
);
2764 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) == PLUS
);
2765 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) == CONST_INT
);
2767 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2769 /* Each push will put 4 bytes from the stack. */
2770 stack_bytes
+= (count
- 1) * 4;
2772 /* Make sure that the amount we are popping
2773 will fit into the DISPOSE instruction. */
2774 if (stack_bytes
< -128)
2776 error ("too much stack space to prepare: %d", stack_bytes
);
2780 /* Now compute the bit mask of registers to push. */
2782 for (i
= 1; i
< count
; i
++)
2784 rtx vector_element
= XVECEXP (op
, 0, i
);
2786 gcc_assert (GET_CODE (vector_element
) == SET
);
2787 gcc_assert (GET_CODE (SET_SRC (vector_element
)) == REG
);
2788 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element
),
2791 if (REGNO (SET_SRC (vector_element
)) == 2)
2794 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2797 if ((! TARGET_DISABLE_CALLT
)
2798 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
2802 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
2806 for (i
= 20; i
< 32; i
++)
2807 if (mask
& (1 << i
))
2811 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
2813 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
2814 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
2818 static char regs
[100]; /* XXX */
2822 /* Generate the PREPARE instruction. Note we could just issue the
2823 bit mask as a number as the assembler can cope with this, but for
2824 the sake of our readers we turn it into a textual description. */
2828 for (i
= 20; i
< 32; i
++)
2830 if (mask
& (1 << i
))
2835 strcat (regs
, ", ");
2840 strcat (regs
, reg_names
[ first
]);
2842 for (i
++; i
< 32; i
++)
2843 if ((mask
& (1 << i
)) == 0)
2848 strcat (regs
, " - ");
2849 strcat (regs
, reg_names
[ i
- 1 ] );
2854 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
2860 /* Return an RTX indicating where the return address to the
2861 calling function can be found. */
2864 v850_return_addr (int count
)
2869 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
2872 /* Implement TARGET_ASM_INIT_SECTIONS. */
2875 v850_asm_init_sections (void)
2878 = get_unnamed_section (0, output_section_asm_op
,
2879 "\t.section .rosdata,\"a\"");
2882 = get_unnamed_section (0, output_section_asm_op
,
2883 "\t.section .rozdata,\"a\"");
2886 = get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
2887 "\t.section .tdata,\"aw\"");
2890 = get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
2891 "\t.section .zdata,\"aw\"");
2894 = get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
2895 output_section_asm_op
,
2896 "\t.section .zbss,\"aw\"");
2900 v850_select_section (tree exp
,
2901 int reloc ATTRIBUTE_UNUSED
,
2902 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
2904 if (TREE_CODE (exp
) == VAR_DECL
)
2907 if (!TREE_READONLY (exp
)
2908 || TREE_SIDE_EFFECTS (exp
)
2909 || !DECL_INITIAL (exp
)
2910 || (DECL_INITIAL (exp
) != error_mark_node
2911 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
2916 switch (v850_get_data_area (exp
))
2919 return is_const
? rozdata_section
: zdata_section
;
2922 return tdata_section
;
2925 return is_const
? rosdata_section
: sdata_section
;
2928 return is_const
? readonly_data_section
: data_section
;
2931 return readonly_data_section
;
2934 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2937 v850_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
2939 /* Return values > 8 bytes in length in memory. */
2940 return int_size_in_bytes (type
) > 8 || TYPE_MODE (type
) == BLKmode
;
2943 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2946 v850_setup_incoming_varargs (CUMULATIVE_ARGS
*ca
,
2947 enum machine_mode mode ATTRIBUTE_UNUSED
,
2948 tree type ATTRIBUTE_UNUSED
,
2949 int *pretend_arg_size ATTRIBUTE_UNUSED
,
2950 int second_time ATTRIBUTE_UNUSED
)
2952 ca
->anonymous_args
= (!TARGET_GHS
? 1 : 0);
2955 #include "gt-v850.h"