1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
42 #include "integrate.h"
45 #include "target-def.h"
48 #define streq(a,b) (strcmp (a, b) == 0)
51 /* Function prototypes for stupid compilers: */
52 static 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 *);
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 (tree
, 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 #undef TARGET_ENCODE_SECTION_INFO
121 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
123 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
124 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
126 #undef TARGET_DEFAULT_TARGET_FLAGS
127 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_DEFAULT | MASK_APP_REGS)
128 #undef TARGET_HANDLE_OPTION
129 #define TARGET_HANDLE_OPTION v850_handle_option
131 #undef TARGET_RTX_COSTS
132 #define TARGET_RTX_COSTS v850_rtx_costs
134 #undef TARGET_ADDRESS_COST
135 #define TARGET_ADDRESS_COST hook_int_rtx_0
137 #undef TARGET_MACHINE_DEPENDENT_REORG
138 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
140 #undef TARGET_PROMOTE_PROTOTYPES
141 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
143 #undef TARGET_RETURN_IN_MEMORY
144 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
146 #undef TARGET_PASS_BY_REFERENCE
147 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
149 #undef TARGET_CALLEE_COPIES
150 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
152 #undef TARGET_SETUP_INCOMING_VARARGS
153 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
155 #undef TARGET_ARG_PARTIAL_BYTES
156 #define TARGET_ARG_PARTIAL_BYTES v850_arg_partial_bytes
158 struct gcc_target targetm
= TARGET_INITIALIZER
;
160 /* Set the maximum size of small memory area TYPE to the value given
161 by VALUE. Return true if VALUE was syntactically correct. VALUE
162 starts with the argument separator: either "-" or "=". */
165 v850_handle_memory_option (enum small_memory_type type
, const char *value
)
169 if (*value
!= '-' && *value
!= '=')
173 for (i
= 0; value
[i
]; i
++)
174 if (!ISDIGIT (value
[i
]))
178 if (size
> small_memory
[type
].physical_max
)
179 error ("value passed to %<-m%s%> is too large", small_memory
[type
].name
);
181 small_memory
[type
].max
= size
;
185 /* Implement TARGET_HANDLE_OPTION. */
188 v850_handle_option (size_t code
, const char *arg
, int value ATTRIBUTE_UNUSED
)
193 target_flags
|= MASK_EP
| MASK_PROLOG_FUNCTION
;
197 target_flags
&= ~(MASK_CPU
^ MASK_V850
);
202 target_flags
&= ~(MASK_CPU
^ MASK_V850E
);
206 return v850_handle_memory_option (SMALL_MEMORY_TDA
, arg
);
209 return v850_handle_memory_option (SMALL_MEMORY_SDA
, arg
);
212 return v850_handle_memory_option (SMALL_MEMORY_ZDA
, arg
);
220 v850_pass_by_reference (CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
221 enum machine_mode mode
, tree type
,
222 bool named ATTRIBUTE_UNUSED
)
224 unsigned HOST_WIDE_INT size
;
227 size
= int_size_in_bytes (type
);
229 size
= GET_MODE_SIZE (mode
);
234 /* Return an RTX to represent where a value with mode MODE will be returned
235 from a function. If the result is 0, the argument is pushed. */
238 function_arg (CUMULATIVE_ARGS
* cum
,
239 enum machine_mode mode
,
246 if (TARGET_GHS
&& !named
)
250 size
= int_size_in_bytes (type
);
252 size
= GET_MODE_SIZE (mode
);
258 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
262 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
264 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
267 if (type
== NULL_TREE
268 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
271 switch (cum
->nbytes
/ UNITS_PER_WORD
)
274 result
= gen_rtx_REG (mode
, 6);
277 result
= gen_rtx_REG (mode
, 7);
280 result
= gen_rtx_REG (mode
, 8);
283 result
= gen_rtx_REG (mode
, 9);
293 /* Return the number of bytes which must be put into registers
294 for values which are part in registers and part in memory. */
297 v850_arg_partial_bytes (CUMULATIVE_ARGS
* cum
, enum machine_mode mode
,
298 tree type
, bool named
)
302 if (TARGET_GHS
&& !named
)
306 size
= int_size_in_bytes (type
);
308 size
= GET_MODE_SIZE (mode
);
311 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
315 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
317 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
320 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
323 if (type
== NULL_TREE
324 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
327 return 4 * UNITS_PER_WORD
- cum
->nbytes
;
331 /* Return the high and low words of a CONST_DOUBLE */
334 const_double_split (rtx x
, HOST_WIDE_INT
* p_high
, HOST_WIDE_INT
* p_low
)
336 if (GET_CODE (x
) == CONST_DOUBLE
)
341 switch (GET_MODE (x
))
344 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
345 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
346 *p_high
= t
[1]; /* since v850 is little endian */
347 *p_low
= t
[0]; /* high is second word */
351 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
352 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
358 *p_high
= CONST_DOUBLE_HIGH (x
);
359 *p_low
= CONST_DOUBLE_LOW (x
);
367 fatal_insn ("const_double_split got a bad insn:", x
);
371 /* Return the cost of the rtx R with code CODE. */
374 const_costs_int (HOST_WIDE_INT value
, int zero_cost
)
376 if (CONST_OK_FOR_I (value
))
378 else if (CONST_OK_FOR_J (value
))
380 else if (CONST_OK_FOR_K (value
))
387 const_costs (rtx r
, enum rtx_code c
)
389 HOST_WIDE_INT high
, low
;
394 return const_costs_int (INTVAL (r
), 0);
397 const_double_split (r
, &high
, &low
);
398 if (GET_MODE (r
) == SFmode
)
399 return const_costs_int (high
, 1);
401 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
417 v850_rtx_costs (rtx x
,
419 int outer_code ATTRIBUTE_UNUSED
,
429 *total
= COSTS_N_INSNS (const_costs (x
, code
));
436 if (TARGET_V850E
&& optimize_size
)
444 && ( GET_MODE (x
) == SImode
445 || GET_MODE (x
) == HImode
446 || GET_MODE (x
) == QImode
))
448 if (GET_CODE (XEXP (x
, 1)) == REG
)
450 else if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
452 if (CONST_OK_FOR_O (INTVAL (XEXP (x
, 1))))
454 else if (CONST_OK_FOR_K (INTVAL (XEXP (x
, 1))))
467 /* Print operand X using operand code CODE to assembly language output file
471 print_operand (FILE * file
, rtx x
, int code
)
473 HOST_WIDE_INT high
, low
;
478 /* We use 'c' operands with symbols for .vtinherit */
479 if (GET_CODE (x
) == SYMBOL_REF
)
481 output_addr_const(file
, x
);
488 switch ((code
== 'B' || code
== 'C')
489 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
492 if (code
== 'c' || code
== 'C')
493 fprintf (file
, "nz");
495 fprintf (file
, "ne");
498 if (code
== 'c' || code
== 'C')
504 fprintf (file
, "ge");
507 fprintf (file
, "gt");
510 fprintf (file
, "le");
513 fprintf (file
, "lt");
516 fprintf (file
, "nl");
522 fprintf (file
, "nh");
531 case 'F': /* high word of CONST_DOUBLE */
532 switch (GET_CODE (x
))
535 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
539 const_double_split (x
, &high
, &low
);
540 fprintf (file
, "%ld", (long) high
);
547 case 'G': /* low word of CONST_DOUBLE */
548 switch (GET_CODE (x
))
551 fprintf (file
, "%ld", (long) INTVAL (x
));
555 const_double_split (x
, &high
, &low
);
556 fprintf (file
, "%ld", (long) low
);
564 fprintf (file
, "%d\n", (int)(INTVAL (x
) & 0xffff));
567 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
570 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
572 if (GET_CODE (x
) == CONST
)
573 x
= XEXP (XEXP (x
, 0), 0);
575 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
577 if (SYMBOL_REF_ZDA_P (x
))
578 fprintf (file
, "zdaoff");
579 else if (SYMBOL_REF_SDA_P (x
))
580 fprintf (file
, "sdaoff");
581 else if (SYMBOL_REF_TDA_P (x
))
582 fprintf (file
, "tdaoff");
587 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
588 output_addr_const (file
, x
);
591 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
593 if (GET_CODE (x
) == CONST
)
594 x
= XEXP (XEXP (x
, 0), 0);
596 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
598 if (SYMBOL_REF_ZDA_P (x
))
599 fprintf (file
, "r0");
600 else if (SYMBOL_REF_SDA_P (x
))
601 fprintf (file
, "gp");
602 else if (SYMBOL_REF_TDA_P (x
))
603 fprintf (file
, "ep");
607 case 'R': /* 2nd word of a double. */
608 switch (GET_CODE (x
))
611 fprintf (file
, reg_names
[REGNO (x
) + 1]);
614 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
615 print_operand_address (file
, x
);
616 if (GET_CODE (x
) == CONST_INT
)
617 fprintf (file
, "[r0]");
626 /* If it's a reference to a TDA variable, use sst/sld vs. st/ld. */
627 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
634 /* Like an 'S' operand above, but for unsigned loads only. */
635 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
640 case 'W': /* print the instruction suffix */
641 switch (GET_MODE (x
))
646 case QImode
: fputs (".b", file
); break;
647 case HImode
: fputs (".h", file
); break;
648 case SImode
: fputs (".w", file
); break;
649 case SFmode
: fputs (".w", file
); break;
652 case '.': /* register r0 */
653 fputs (reg_names
[0], file
);
655 case 'z': /* reg or zero */
656 if (GET_CODE (x
) == REG
)
657 fputs (reg_names
[REGNO (x
)], file
);
660 gcc_assert (x
== const0_rtx
);
661 fputs (reg_names
[0], file
);
665 switch (GET_CODE (x
))
668 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
669 output_address (gen_rtx_PLUS (SImode
, gen_rtx_REG (SImode
, 0),
672 output_address (XEXP (x
, 0));
676 fputs (reg_names
[REGNO (x
)], file
);
679 fputs (reg_names
[subreg_regno (x
)], file
);
686 print_operand_address (file
, x
);
697 /* Output assembly language output for the address ADDR to FILE. */
700 print_operand_address (FILE * file
, rtx addr
)
702 switch (GET_CODE (addr
))
705 fprintf (file
, "0[");
706 print_operand (file
, addr
, 0);
710 if (GET_CODE (XEXP (addr
, 0)) == REG
)
713 fprintf (file
, "lo(");
714 print_operand (file
, XEXP (addr
, 1), 0);
715 fprintf (file
, ")[");
716 print_operand (file
, XEXP (addr
, 0), 0);
721 if (GET_CODE (XEXP (addr
, 0)) == REG
722 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
725 print_operand (file
, XEXP (addr
, 1), 0);
727 print_operand (file
, XEXP (addr
, 0), 0);
732 print_operand (file
, XEXP (addr
, 0), 0);
734 print_operand (file
, XEXP (addr
, 1), 0);
739 const char *off_name
= NULL
;
740 const char *reg_name
= NULL
;
742 if (SYMBOL_REF_ZDA_P (addr
))
747 else if (SYMBOL_REF_SDA_P (addr
))
752 else if (SYMBOL_REF_TDA_P (addr
))
759 fprintf (file
, "%s(", off_name
);
760 output_addr_const (file
, addr
);
762 fprintf (file
, ")[%s]", reg_name
);
766 if (special_symbolref_operand (addr
, VOIDmode
))
768 rtx x
= XEXP (XEXP (addr
, 0), 0);
769 const char *off_name
;
770 const char *reg_name
;
772 if (SYMBOL_REF_ZDA_P (x
))
777 else if (SYMBOL_REF_SDA_P (x
))
782 else if (SYMBOL_REF_TDA_P (x
))
790 fprintf (file
, "%s(", off_name
);
791 output_addr_const (file
, addr
);
792 fprintf (file
, ")[%s]", reg_name
);
795 output_addr_const (file
, addr
);
798 output_addr_const (file
, addr
);
803 /* When assemble_integer is used to emit the offsets for a switch
804 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
805 output_addr_const will normally barf at this, but it is OK to omit
806 the truncate and just emit the difference of the two labels. The
807 .hword directive will automatically handle the truncation for us.
809 Returns 1 if rtx was handled, 0 otherwise. */
812 v850_output_addr_const_extra (FILE * file
, rtx x
)
814 if (GET_CODE (x
) != TRUNCATE
)
819 /* We must also handle the case where the switch table was passed a
820 constant value and so has been collapsed. In this case the first
821 label will have been deleted. In such a case it is OK to emit
822 nothing, since the table will not be used.
823 (cf gcc.c-torture/compile/990801-1.c). */
824 if (GET_CODE (x
) == MINUS
825 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
826 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
827 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
830 output_addr_const (file
, x
);
834 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
838 output_move_single (rtx
* operands
)
840 rtx dst
= operands
[0];
841 rtx src
= operands
[1];
848 else if (GET_CODE (src
) == CONST_INT
)
850 HOST_WIDE_INT value
= INTVAL (src
);
852 if (CONST_OK_FOR_J (value
)) /* Signed 5 bit immediate. */
855 else if (CONST_OK_FOR_K (value
)) /* Signed 16 bit immediate. */
856 return "movea lo(%1),%.,%0";
858 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
859 return "movhi hi(%1),%.,%0";
861 /* A random constant. */
862 else if (TARGET_V850E
)
865 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
868 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
870 HOST_WIDE_INT high
, low
;
872 const_double_split (src
, &high
, &low
);
874 if (CONST_OK_FOR_J (high
)) /* Signed 5 bit immediate. */
877 else if (CONST_OK_FOR_K (high
)) /* Signed 16 bit immediate. */
878 return "movea lo(%F1),%.,%0";
880 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
881 return "movhi hi(%F1),%.,%0";
883 /* A random constant. */
884 else if (TARGET_V850E
)
888 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
891 else if (GET_CODE (src
) == MEM
)
892 return "%S1ld%W1 %1,%0";
894 else if (special_symbolref_operand (src
, VOIDmode
))
895 return "movea %O1(%P1),%Q1,%0";
897 else if (GET_CODE (src
) == LABEL_REF
898 || GET_CODE (src
) == SYMBOL_REF
899 || GET_CODE (src
) == CONST
)
902 return "mov hilo(%1),%0";
904 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
907 else if (GET_CODE (src
) == HIGH
)
908 return "movhi hi(%1),%.,%0";
910 else if (GET_CODE (src
) == LO_SUM
)
912 operands
[2] = XEXP (src
, 0);
913 operands
[3] = XEXP (src
, 1);
914 return "movea lo(%3),%2,%0";
918 else if (GET_CODE (dst
) == MEM
)
921 return "%S0st%W0 %1,%0";
923 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
924 return "%S0st%W0 %.,%0";
926 else if (GET_CODE (src
) == CONST_DOUBLE
927 && CONST0_RTX (GET_MODE (dst
)) == src
)
928 return "%S0st%W0 %.,%0";
931 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
936 /* Return appropriate code to load up an 8 byte integer or
937 floating point value */
940 output_move_double (rtx
* operands
)
942 enum machine_mode mode
= GET_MODE (operands
[0]);
943 rtx dst
= operands
[0];
944 rtx src
= operands
[1];
946 if (register_operand (dst
, mode
)
947 && register_operand (src
, mode
))
949 if (REGNO (src
) + 1 == REGNO (dst
))
950 return "mov %R1,%R0\n\tmov %1,%0";
952 return "mov %1,%0\n\tmov %R1,%R0";
956 if (GET_CODE (dst
) == MEM
957 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
958 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
959 return "st.w %.,%0\n\tst.w %.,%R0";
961 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
963 HOST_WIDE_INT high_low
[2];
967 if (GET_CODE (src
) == CONST_DOUBLE
)
968 const_double_split (src
, &high_low
[1], &high_low
[0]);
971 high_low
[0] = INTVAL (src
);
972 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
975 for (i
= 0; i
< 2; i
++)
977 xop
[0] = gen_rtx_REG (SImode
, REGNO (dst
)+i
);
978 xop
[1] = GEN_INT (high_low
[i
]);
979 output_asm_insn (output_move_single (xop
), xop
);
985 if (GET_CODE (src
) == MEM
)
988 int dreg
= REGNO (dst
);
989 rtx inside
= XEXP (src
, 0);
991 if (GET_CODE (inside
) == REG
)
992 ptrreg
= REGNO (inside
);
993 else if (GET_CODE (inside
) == SUBREG
)
994 ptrreg
= subreg_regno (inside
);
995 else if (GET_CODE (inside
) == PLUS
)
996 ptrreg
= REGNO (XEXP (inside
, 0));
997 else if (GET_CODE (inside
) == LO_SUM
)
998 ptrreg
= REGNO (XEXP (inside
, 0));
1001 return "ld.w %R1,%R0\n\tld.w %1,%0";
1004 if (GET_CODE (src
) == MEM
)
1005 return "ld.w %1,%0\n\tld.w %R1,%R0";
1007 if (GET_CODE (dst
) == MEM
)
1008 return "st.w %1,%0\n\tst.w %R1,%R0";
1010 return "mov %1,%0\n\tmov %R1,%R0";
1014 /* Return maximum offset supported for a short EP memory reference of mode
1015 MODE and signedness UNSIGNEDP. */
1018 ep_memory_offset (enum machine_mode mode
, int unsignedp ATTRIBUTE_UNUSED
)
1025 if (TARGET_SMALL_SLD
)
1026 max_offset
= (1 << 4);
1027 else if (TARGET_V850E
1028 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
1029 || (! unsignedp
&& TARGET_US_BIT_SET
)))
1030 max_offset
= (1 << 4);
1032 max_offset
= (1 << 7);
1036 if (TARGET_SMALL_SLD
)
1037 max_offset
= (1 << 5);
1038 else if (TARGET_V850E
1039 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
1040 || (! unsignedp
&& TARGET_US_BIT_SET
)))
1041 max_offset
= (1 << 5);
1043 max_offset
= (1 << 8);
1048 max_offset
= (1 << 8);
1058 /* Return true if OP is a valid short EP memory reference */
1061 ep_memory_operand (rtx op
, enum machine_mode mode
, int unsigned_load
)
1067 /* If we are not using the EP register on a per-function basis
1068 then do not allow this optimisation at all. This is to
1069 prevent the use of the SLD/SST instructions which cannot be
1070 guaranteed to work properly due to a hardware bug. */
1074 if (GET_CODE (op
) != MEM
)
1077 max_offset
= ep_memory_offset (mode
, unsigned_load
);
1079 mask
= GET_MODE_SIZE (mode
) - 1;
1081 addr
= XEXP (op
, 0);
1082 if (GET_CODE (addr
) == CONST
)
1083 addr
= XEXP (addr
, 0);
1085 switch (GET_CODE (addr
))
1091 return SYMBOL_REF_TDA_P (addr
);
1094 return REGNO (addr
) == EP_REGNUM
;
1097 op0
= XEXP (addr
, 0);
1098 op1
= XEXP (addr
, 1);
1099 if (GET_CODE (op1
) == CONST_INT
1100 && INTVAL (op1
) < max_offset
1101 && INTVAL (op1
) >= 0
1102 && (INTVAL (op1
) & mask
) == 0)
1104 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1107 if (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_TDA_P (op0
))
1116 /* Substitute memory references involving a pointer, to use the ep pointer,
1117 taking care to save and preserve the ep. */
1120 substitute_ep_register (rtx first_insn
,
1127 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1132 regs_ever_live
[1] = 1;
1133 *p_r1
= gen_rtx_REG (Pmode
, 1);
1134 *p_ep
= gen_rtx_REG (Pmode
, 30);
1139 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1140 2 * (uses
- 3), uses
, reg_names
[regno
],
1141 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1142 INSN_UID (first_insn
), INSN_UID (last_insn
));
1144 if (GET_CODE (first_insn
) == NOTE
)
1145 first_insn
= next_nonnote_insn (first_insn
);
1147 last_insn
= next_nonnote_insn (last_insn
);
1148 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1150 if (GET_CODE (insn
) == INSN
)
1152 rtx pattern
= single_set (insn
);
1154 /* Replace the memory references. */
1158 /* Memory operands are signed by default. */
1159 int unsignedp
= FALSE
;
1161 if (GET_CODE (SET_DEST (pattern
)) == MEM
1162 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1165 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1166 p_mem
= &SET_DEST (pattern
);
1168 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1169 p_mem
= &SET_SRC (pattern
);
1171 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1172 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1173 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1175 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1176 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1178 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1186 rtx addr
= XEXP (*p_mem
, 0);
1188 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1189 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1191 else if (GET_CODE (addr
) == PLUS
1192 && GET_CODE (XEXP (addr
, 0)) == REG
1193 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1194 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1195 && ((INTVAL (XEXP (addr
, 1)))
1196 < ep_memory_offset (GET_MODE (*p_mem
),
1198 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1199 *p_mem
= change_address (*p_mem
, VOIDmode
,
1200 gen_rtx_PLUS (Pmode
,
1208 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1209 insn
= prev_nonnote_insn (first_insn
);
1210 if (insn
&& GET_CODE (insn
) == INSN
1211 && GET_CODE (PATTERN (insn
)) == SET
1212 && SET_DEST (PATTERN (insn
)) == *p_ep
1213 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1216 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1218 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1219 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1223 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1224 the -mep mode to copy heavily used pointers to ep to use the implicit
1236 regs
[FIRST_PSEUDO_REGISTER
];
1245 /* If not ep mode, just return now. */
1249 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1252 regs
[i
].first_insn
= NULL_RTX
;
1253 regs
[i
].last_insn
= NULL_RTX
;
1256 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1258 switch (GET_CODE (insn
))
1260 /* End of basic block */
1267 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1269 if (max_uses
< regs
[i
].uses
)
1271 max_uses
= regs
[i
].uses
;
1277 substitute_ep_register (regs
[max_regno
].first_insn
,
1278 regs
[max_regno
].last_insn
,
1279 max_uses
, max_regno
, &r1
, &ep
);
1283 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1286 regs
[i
].first_insn
= NULL_RTX
;
1287 regs
[i
].last_insn
= NULL_RTX
;
1295 pattern
= single_set (insn
);
1297 /* See if there are any memory references we can shorten */
1300 rtx src
= SET_SRC (pattern
);
1301 rtx dest
= SET_DEST (pattern
);
1303 /* Memory operands are signed by default. */
1304 int unsignedp
= FALSE
;
1306 /* We might have (SUBREG (MEM)) here, so just get rid of the
1307 subregs to make this code simpler. */
1308 if (GET_CODE (dest
) == SUBREG
1309 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1310 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1311 alter_subreg (&dest
);
1312 if (GET_CODE (src
) == SUBREG
1313 && (GET_CODE (SUBREG_REG (src
)) == MEM
1314 || GET_CODE (SUBREG_REG (src
)) == REG
))
1315 alter_subreg (&src
);
1317 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1320 else if (GET_CODE (dest
) == MEM
)
1323 else if (GET_CODE (src
) == MEM
)
1326 else if (GET_CODE (src
) == SIGN_EXTEND
1327 && GET_CODE (XEXP (src
, 0)) == MEM
)
1328 mem
= XEXP (src
, 0);
1330 else if (GET_CODE (src
) == ZERO_EXTEND
1331 && GET_CODE (XEXP (src
, 0)) == MEM
)
1333 mem
= XEXP (src
, 0);
1339 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1342 else if (!use_ep
&& mem
1343 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1345 rtx addr
= XEXP (mem
, 0);
1349 if (GET_CODE (addr
) == REG
)
1352 regno
= REGNO (addr
);
1355 else if (GET_CODE (addr
) == PLUS
1356 && GET_CODE (XEXP (addr
, 0)) == REG
1357 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1358 && ((INTVAL (XEXP (addr
, 1)))
1359 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1360 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1363 regno
= REGNO (XEXP (addr
, 0));
1372 regs
[regno
].last_insn
= insn
;
1373 if (!regs
[regno
].first_insn
)
1374 regs
[regno
].first_insn
= insn
;
1378 /* Loading up a register in the basic block zaps any savings
1380 if (GET_CODE (dest
) == REG
)
1382 enum machine_mode mode
= GET_MODE (dest
);
1386 regno
= REGNO (dest
);
1387 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1391 /* See if we can use the pointer before this
1396 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1398 if (max_uses
< regs
[i
].uses
)
1400 max_uses
= regs
[i
].uses
;
1406 && max_regno
>= regno
1407 && max_regno
< endregno
)
1409 substitute_ep_register (regs
[max_regno
].first_insn
,
1410 regs
[max_regno
].last_insn
,
1411 max_uses
, max_regno
, &r1
,
1414 /* Since we made a substitution, zap all remembered
1416 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1419 regs
[i
].first_insn
= NULL_RTX
;
1420 regs
[i
].last_insn
= NULL_RTX
;
1425 for (i
= regno
; i
< endregno
; i
++)
1428 regs
[i
].first_insn
= NULL_RTX
;
1429 regs
[i
].last_insn
= NULL_RTX
;
1438 /* # of registers saved by the interrupt handler. */
1439 #define INTERRUPT_FIXED_NUM 4
1441 /* # of bytes for registers saved by the interrupt handler. */
1442 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1444 /* # of registers saved in register parameter area. */
1445 #define INTERRUPT_REGPARM_NUM 4
1446 /* # of words saved for other registers. */
1447 #define INTERRUPT_ALL_SAVE_NUM \
1448 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1450 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1453 compute_register_save_size (long * p_reg_saved
)
1457 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1458 int call_p
= regs_ever_live
[LINK_POINTER_REGNUM
];
1461 /* Count the return pointer if we need to save it. */
1462 if (current_function_profile
&& !call_p
)
1463 regs_ever_live
[LINK_POINTER_REGNUM
] = call_p
= 1;
1465 /* Count space for the register saves. */
1466 if (interrupt_handler
)
1468 for (i
= 0; i
<= 31; i
++)
1472 if (regs_ever_live
[i
] || call_p
)
1475 reg_saved
|= 1L << i
;
1479 /* We don't save/restore r0 or the stack pointer */
1481 case STACK_POINTER_REGNUM
:
1484 /* For registers with fixed use, we save them, set them to the
1485 appropriate value, and then restore them.
1486 These registers are handled specially, so don't list them
1487 on the list of registers to save in the prologue. */
1488 case 1: /* temp used to hold ep */
1490 case 10: /* temp used to call interrupt save/restore */
1491 case EP_REGNUM
: /* ep */
1498 /* Find the first register that needs to be saved. */
1499 for (i
= 0; i
<= 31; i
++)
1500 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1501 || i
== LINK_POINTER_REGNUM
))
1504 /* If it is possible that an out-of-line helper function might be
1505 used to generate the prologue for the current function, then we
1506 need to cover the possibility that such a helper function will
1507 be used, despite the fact that there might be gaps in the list of
1508 registers that need to be saved. To detect this we note that the
1509 helper functions always push at least register r29 (provided
1510 that the function is not an interrupt handler). */
1512 if (TARGET_PROLOG_FUNCTION
1513 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1518 reg_saved
|= 1L << i
;
1523 /* Helper functions save all registers between the starting
1524 register and the last register, regardless of whether they
1525 are actually used by the function or not. */
1526 for (; i
<= 29; i
++)
1529 reg_saved
|= 1L << i
;
1532 if (regs_ever_live
[LINK_POINTER_REGNUM
])
1535 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1540 for (; i
<= 31; i
++)
1541 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1542 || i
== LINK_POINTER_REGNUM
))
1545 reg_saved
|= 1L << i
;
1551 *p_reg_saved
= reg_saved
;
1557 compute_frame_size (int size
, long * p_reg_saved
)
1560 + compute_register_save_size (p_reg_saved
)
1561 + current_function_outgoing_args_size
);
1566 expand_prologue (void)
1570 unsigned int size
= get_frame_size ();
1571 unsigned int actual_fsize
;
1572 unsigned int init_stack_alloc
= 0;
1575 unsigned int num_save
;
1576 unsigned int default_stack
;
1578 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1581 actual_fsize
= compute_frame_size (size
, ®_saved
);
1583 /* Save/setup global registers for interrupt functions right now. */
1584 if (interrupt_handler
)
1586 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1587 emit_insn (gen_callt_save_interrupt ());
1589 emit_insn (gen_save_interrupt ());
1591 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1593 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1594 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1597 /* Save arg registers to the stack if necessary. */
1598 else if (current_function_args_info
.anonymous_args
)
1600 if (TARGET_PROLOG_FUNCTION
&& TARGET_V850E
&& !TARGET_DISABLE_CALLT
)
1601 emit_insn (gen_save_r6_r9_v850e ());
1602 else if (TARGET_PROLOG_FUNCTION
&& ! TARGET_LONG_CALLS
)
1603 emit_insn (gen_save_r6_r9 ());
1607 for (i
= 6; i
< 10; i
++)
1609 emit_move_insn (gen_rtx_MEM (SImode
,
1610 plus_constant (stack_pointer_rtx
,
1612 gen_rtx_REG (SImode
, i
));
1618 /* Identify all of the saved registers. */
1621 for (i
= 1; i
< 31; i
++)
1623 if (((1L << i
) & reg_saved
) != 0)
1624 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1627 /* If the return pointer is saved, the helper functions also allocate
1628 16 bytes of stack for arguments to be saved in. */
1629 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1631 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1635 /* See if we have an insn that allocates stack space and saves the particular
1636 registers we want to. */
1637 save_all
= NULL_RTX
;
1638 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1640 int alloc_stack
= (4 * num_save
) + default_stack
;
1641 int unalloc_stack
= actual_fsize
- alloc_stack
;
1642 int save_func_len
= 4;
1643 int save_normal_len
;
1646 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1648 /* see if we would have used ep to save the stack */
1649 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1650 save_normal_len
= (3 * 2) + (2 * num_save
);
1652 save_normal_len
= 4 * num_save
;
1654 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1656 /* Don't bother checking if we don't actually save any space.
1657 This happens for instance if one register is saved and additional
1658 stack space is allocated. */
1659 if (save_func_len
< save_normal_len
)
1661 save_all
= gen_rtx_PARALLEL
1663 rtvec_alloc (num_save
+ 1
1664 + (TARGET_V850
? (TARGET_LONG_CALLS
? 2 : 1) : 0)));
1666 XVECEXP (save_all
, 0, 0)
1667 = gen_rtx_SET (VOIDmode
,
1669 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1671 offset
= - default_stack
;
1672 for (i
= 0; i
< num_save
; i
++)
1674 XVECEXP (save_all
, 0, i
+1)
1675 = gen_rtx_SET (VOIDmode
,
1677 plus_constant (stack_pointer_rtx
,
1685 XVECEXP (save_all
, 0, num_save
+ 1)
1686 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1688 if (TARGET_LONG_CALLS
)
1689 XVECEXP (save_all
, 0, num_save
+ 2)
1690 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 11));
1693 code
= recog (save_all
, NULL_RTX
, NULL
);
1696 rtx insn
= emit_insn (save_all
);
1697 INSN_CODE (insn
) = code
;
1698 actual_fsize
-= alloc_stack
;
1702 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1703 save_normal_len
- save_func_len
,
1704 save_normal_len
, save_func_len
,
1705 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1708 save_all
= NULL_RTX
;
1712 /* If no prolog save function is available, store the registers the old
1713 fashioned way (one by one). */
1716 /* Special case interrupt functions that save all registers for a call. */
1717 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1719 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1720 emit_insn (gen_callt_save_all_interrupt ());
1722 emit_insn (gen_save_all_interrupt ());
1726 /* If the stack is too big, allocate it in chunks so we can do the
1727 register saves. We use the register save size so we use the ep
1729 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1730 init_stack_alloc
= compute_register_save_size (NULL
);
1732 init_stack_alloc
= actual_fsize
;
1734 /* Save registers at the beginning of the stack frame. */
1735 offset
= init_stack_alloc
- 4;
1737 if (init_stack_alloc
)
1738 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1740 GEN_INT (-init_stack_alloc
)));
1742 /* Save the return pointer first. */
1743 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1745 emit_move_insn (gen_rtx_MEM (SImode
,
1746 plus_constant (stack_pointer_rtx
,
1748 save_regs
[--num_save
]);
1752 for (i
= 0; i
< num_save
; i
++)
1754 emit_move_insn (gen_rtx_MEM (SImode
,
1755 plus_constant (stack_pointer_rtx
,
1763 /* Allocate the rest of the stack that was not allocated above (either it is
1764 > 32K or we just called a function to save the registers and needed more
1766 if (actual_fsize
> init_stack_alloc
)
1768 int diff
= actual_fsize
- init_stack_alloc
;
1769 if (CONST_OK_FOR_K (diff
))
1770 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1775 rtx reg
= gen_rtx_REG (Pmode
, 12);
1776 emit_move_insn (reg
, GEN_INT (-diff
));
1777 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1781 /* If we need a frame pointer, set it up now. */
1782 if (frame_pointer_needed
)
1783 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1788 expand_epilogue (void)
1792 unsigned int size
= get_frame_size ();
1794 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1795 unsigned int init_stack_free
= 0;
1796 rtx restore_regs
[32];
1798 unsigned int num_restore
;
1799 unsigned int default_stack
;
1801 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1803 /* Eliminate the initial stack stored by interrupt functions. */
1804 if (interrupt_handler
)
1806 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1807 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1808 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1811 /* Cut off any dynamic stack created. */
1812 if (frame_pointer_needed
)
1813 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1815 /* Identify all of the saved registers. */
1818 for (i
= 1; i
< 31; i
++)
1820 if (((1L << i
) & reg_saved
) != 0)
1821 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1824 /* If the return pointer is saved, the helper functions also allocate
1825 16 bytes of stack for arguments to be saved in. */
1826 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1828 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1832 /* See if we have an insn that restores the particular registers we
1834 restore_all
= NULL_RTX
;
1836 if (TARGET_PROLOG_FUNCTION
1838 && actual_fsize
>= default_stack
1839 && !interrupt_handler
)
1841 int alloc_stack
= (4 * num_restore
) + default_stack
;
1842 int unalloc_stack
= actual_fsize
- alloc_stack
;
1843 int restore_func_len
= 4;
1844 int restore_normal_len
;
1847 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1849 /* See if we would have used ep to restore the registers. */
1850 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1851 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1853 restore_normal_len
= 4 * num_restore
;
1855 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1857 /* Don't bother checking if we don't actually save any space. */
1858 if (restore_func_len
< restore_normal_len
)
1860 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1861 rtvec_alloc (num_restore
+ 2));
1862 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1863 XVECEXP (restore_all
, 0, 1)
1864 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1865 gen_rtx_PLUS (Pmode
,
1867 GEN_INT (alloc_stack
)));
1869 offset
= alloc_stack
- 4;
1870 for (i
= 0; i
< num_restore
; i
++)
1872 XVECEXP (restore_all
, 0, i
+2)
1873 = gen_rtx_SET (VOIDmode
,
1876 plus_constant (stack_pointer_rtx
,
1881 code
= recog (restore_all
, NULL_RTX
, NULL
);
1887 actual_fsize
-= alloc_stack
;
1890 if (CONST_OK_FOR_K (actual_fsize
))
1891 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1893 GEN_INT (actual_fsize
)));
1896 rtx reg
= gen_rtx_REG (Pmode
, 12);
1897 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1898 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1904 insn
= emit_jump_insn (restore_all
);
1905 INSN_CODE (insn
) = code
;
1909 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1910 restore_normal_len
- restore_func_len
,
1911 restore_normal_len
, restore_func_len
,
1912 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1915 restore_all
= NULL_RTX
;
1919 /* If no epilog save function is available, restore the registers the
1920 old fashioned way (one by one). */
1923 /* If the stack is large, we need to cut it down in 2 pieces. */
1924 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1925 init_stack_free
= 4 * num_restore
;
1927 init_stack_free
= actual_fsize
;
1929 /* Deallocate the rest of the stack if it is > 32K. */
1930 if (actual_fsize
> init_stack_free
)
1934 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
1936 if (CONST_OK_FOR_K (diff
))
1937 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1942 rtx reg
= gen_rtx_REG (Pmode
, 12);
1943 emit_move_insn (reg
, GEN_INT (diff
));
1944 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1950 /* Special case interrupt functions that save all registers
1952 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1954 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1955 emit_insn (gen_callt_restore_all_interrupt ());
1957 emit_insn (gen_restore_all_interrupt ());
1961 /* Restore registers from the beginning of the stack frame. */
1962 offset
= init_stack_free
- 4;
1964 /* Restore the return pointer first. */
1966 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
1968 emit_move_insn (restore_regs
[--num_restore
],
1969 gen_rtx_MEM (SImode
,
1970 plus_constant (stack_pointer_rtx
,
1975 for (i
= 0; i
< num_restore
; i
++)
1977 emit_move_insn (restore_regs
[i
],
1978 gen_rtx_MEM (SImode
,
1979 plus_constant (stack_pointer_rtx
,
1982 emit_insn (gen_rtx_USE (VOIDmode
, restore_regs
[i
]));
1986 /* Cut back the remainder of the stack. */
1987 if (init_stack_free
)
1988 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1990 GEN_INT (init_stack_free
)));
1993 /* And return or use reti for interrupt handlers. */
1994 if (interrupt_handler
)
1996 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1997 emit_insn (gen_callt_return_interrupt ());
1999 emit_jump_insn (gen_return_interrupt ());
2001 else if (actual_fsize
)
2002 emit_jump_insn (gen_return_internal ());
2004 emit_jump_insn (gen_return ());
2007 v850_interrupt_cache_p
= FALSE
;
2008 v850_interrupt_p
= FALSE
;
2012 /* Update the condition code from the insn. */
2015 notice_update_cc (rtx body
, rtx insn
)
2017 switch (get_attr_cc (insn
))
2020 /* Insn does not affect CC at all. */
2024 /* Insn does not change CC, but the 0'th operand has been changed. */
2025 if (cc_status
.value1
!= 0
2026 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2027 cc_status
.value1
= 0;
2031 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2032 V,C is in an unusable state. */
2034 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2035 cc_status
.value1
= recog_data
.operand
[0];
2039 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2040 C is in an unusable state. */
2042 cc_status
.flags
|= CC_NO_CARRY
;
2043 cc_status
.value1
= recog_data
.operand
[0];
2047 /* The insn is a compare instruction. */
2049 cc_status
.value1
= SET_SRC (body
);
2053 /* Insn doesn't leave CC in a usable state. */
2059 /* Retrieve the data area that has been chosen for the given decl. */
2062 v850_get_data_area (tree decl
)
2064 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2065 return DATA_AREA_SDA
;
2067 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2068 return DATA_AREA_TDA
;
2070 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2071 return DATA_AREA_ZDA
;
2073 return DATA_AREA_NORMAL
;
2076 /* Store the indicated data area in the decl's attributes. */
2079 v850_set_data_area (tree decl
, v850_data_area data_area
)
2085 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2086 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2087 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2092 DECL_ATTRIBUTES (decl
) = tree_cons
2093 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2096 const struct attribute_spec v850_attribute_table
[] =
2098 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2099 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2100 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2101 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2102 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2103 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2104 { NULL
, 0, 0, false, false, false, NULL
}
2107 /* Handle an "interrupt" attribute; arguments as in
2108 struct attribute_spec.handler. */
2110 v850_handle_interrupt_attribute (tree
* node
,
2112 tree args ATTRIBUTE_UNUSED
,
2113 int flags ATTRIBUTE_UNUSED
,
2114 bool * no_add_attrs
)
2116 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2118 warning (OPT_Wattributes
, "%qs attribute only applies to functions",
2119 IDENTIFIER_POINTER (name
));
2120 *no_add_attrs
= true;
2126 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2127 struct attribute_spec.handler. */
2129 v850_handle_data_area_attribute (tree
* node
,
2131 tree args ATTRIBUTE_UNUSED
,
2132 int flags ATTRIBUTE_UNUSED
,
2133 bool * no_add_attrs
)
2135 v850_data_area data_area
;
2136 v850_data_area area
;
2139 /* Implement data area attribute. */
2140 if (is_attribute_p ("sda", name
))
2141 data_area
= DATA_AREA_SDA
;
2142 else if (is_attribute_p ("tda", name
))
2143 data_area
= DATA_AREA_TDA
;
2144 else if (is_attribute_p ("zda", name
))
2145 data_area
= DATA_AREA_ZDA
;
2149 switch (TREE_CODE (decl
))
2152 if (current_function_decl
!= NULL_TREE
)
2154 error ("%Jdata area attributes cannot be specified for "
2155 "local variables", decl
);
2156 *no_add_attrs
= true;
2162 area
= v850_get_data_area (decl
);
2163 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2165 error ("data area of %q+D conflicts with previous declaration",
2167 *no_add_attrs
= true;
2179 /* Return nonzero if FUNC is an interrupt function as specified
2180 by the "interrupt" attribute. */
2183 v850_interrupt_function_p (tree func
)
2188 if (v850_interrupt_cache_p
)
2189 return v850_interrupt_p
;
2191 if (TREE_CODE (func
) != FUNCTION_DECL
)
2194 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2200 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2201 ret
= a
!= NULL_TREE
;
2204 /* Its not safe to trust global variables until after function inlining has
2206 if (reload_completed
| reload_in_progress
)
2207 v850_interrupt_p
= ret
;
2214 v850_encode_data_area (tree decl
, rtx symbol
)
2218 /* Map explicit sections into the appropriate attribute */
2219 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2221 if (DECL_SECTION_NAME (decl
))
2223 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2225 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2226 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2228 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2229 v850_set_data_area (decl
, DATA_AREA_SDA
);
2231 else if (streq (name
, ".tdata"))
2232 v850_set_data_area (decl
, DATA_AREA_TDA
);
2235 /* If no attribute, support -m{zda,sda,tda}=n */
2238 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2242 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2243 v850_set_data_area (decl
, DATA_AREA_TDA
);
2245 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2246 v850_set_data_area (decl
, DATA_AREA_SDA
);
2248 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2249 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2252 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2256 flags
= SYMBOL_REF_FLAGS (symbol
);
2257 switch (v850_get_data_area (decl
))
2259 case DATA_AREA_ZDA
: flags
|= SYMBOL_FLAG_ZDA
; break;
2260 case DATA_AREA_TDA
: flags
|= SYMBOL_FLAG_TDA
; break;
2261 case DATA_AREA_SDA
: flags
|= SYMBOL_FLAG_SDA
; break;
2262 default: gcc_unreachable ();
2264 SYMBOL_REF_FLAGS (symbol
) = flags
;
2268 v850_encode_section_info (tree decl
, rtx rtl
, int first
)
2270 default_encode_section_info (decl
, rtl
, first
);
2272 if (TREE_CODE (decl
) == VAR_DECL
2273 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2274 v850_encode_data_area (decl
, XEXP (rtl
, 0));
2277 /* Construct a JR instruction to a routine that will perform the equivalent of
2278 the RTL passed in as an argument. This RTL is a function epilogue that
2279 pops registers off the stack and possibly releases some extra stack space
2280 as well. The code has already verified that the RTL matches these
2283 construct_restore_jr (rtx op
)
2285 int count
= XVECLEN (op
, 0);
2287 unsigned long int mask
;
2288 unsigned long int first
;
2289 unsigned long int last
;
2291 static char buff
[100]; /* XXX */
2295 error ("bogus JR construction: %d", count
);
2299 /* Work out how many bytes to pop off the stack before retrieving
2301 gcc_assert (GET_CODE (XVECEXP (op
, 0, 1)) == SET
);
2302 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) == PLUS
);
2303 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) == CONST_INT
);
2305 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2307 /* Each pop will remove 4 bytes from the stack.... */
2308 stack_bytes
-= (count
- 2) * 4;
2310 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2311 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2313 error ("bad amount of stack space removal: %d", stack_bytes
);
2317 /* Now compute the bit mask of registers to push. */
2319 for (i
= 2; i
< count
; i
++)
2321 rtx vector_element
= XVECEXP (op
, 0, i
);
2323 gcc_assert (GET_CODE (vector_element
) == SET
);
2324 gcc_assert (GET_CODE (SET_DEST (vector_element
)) == REG
);
2325 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element
),
2328 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2331 /* Scan for the first register to pop. */
2332 for (first
= 0; first
< 32; first
++)
2334 if (mask
& (1 << first
))
2338 gcc_assert (first
< 32);
2340 /* Discover the last register to pop. */
2341 if (mask
& (1 << LINK_POINTER_REGNUM
))
2343 gcc_assert (stack_bytes
== 16);
2345 last
= LINK_POINTER_REGNUM
;
2349 gcc_assert (!stack_bytes
);
2350 gcc_assert (mask
& (1 << 29));
2355 /* Note, it is possible to have gaps in the register mask.
2356 We ignore this here, and generate a JR anyway. We will
2357 be popping more registers than is strictly necessary, but
2358 it does save code space. */
2360 if (TARGET_LONG_CALLS
)
2365 sprintf (name
, "__return_%s", reg_names
[first
]);
2367 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2369 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2375 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2377 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2384 /* Construct a JARL instruction to a routine that will perform the equivalent
2385 of the RTL passed as a parameter. This RTL is a function prologue that
2386 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2387 some stack space as well. The code has already verified that the RTL
2388 matches these requirements. */
2390 construct_save_jarl (rtx op
)
2392 int count
= XVECLEN (op
, 0);
2394 unsigned long int mask
;
2395 unsigned long int first
;
2396 unsigned long int last
;
2398 static char buff
[100]; /* XXX */
2402 error ("bogus JARL construction: %d\n", count
);
2407 gcc_assert (GET_CODE (XVECEXP (op
, 0, 0)) == SET
);
2408 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) == PLUS
);
2409 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) == REG
);
2410 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) == CONST_INT
);
2412 /* Work out how many bytes to push onto the stack after storing the
2414 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2416 /* Each push will put 4 bytes from the stack.... */
2417 stack_bytes
+= (count
- (TARGET_LONG_CALLS
? 3 : 2)) * 4;
2419 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2420 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2422 error ("bad amount of stack space removal: %d", stack_bytes
);
2426 /* Now compute the bit mask of registers to push. */
2428 for (i
= 1; i
< count
- (TARGET_LONG_CALLS
? 2 : 1); i
++)
2430 rtx vector_element
= XVECEXP (op
, 0, i
);
2432 gcc_assert (GET_CODE (vector_element
) == SET
);
2433 gcc_assert (GET_CODE (SET_SRC (vector_element
)) == REG
);
2434 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element
),
2437 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2440 /* Scan for the first register to push. */
2441 for (first
= 0; first
< 32; first
++)
2443 if (mask
& (1 << first
))
2447 gcc_assert (first
< 32);
2449 /* Discover the last register to push. */
2450 if (mask
& (1 << LINK_POINTER_REGNUM
))
2452 gcc_assert (stack_bytes
== -16);
2454 last
= LINK_POINTER_REGNUM
;
2458 gcc_assert (!stack_bytes
);
2459 gcc_assert (mask
& (1 << 29));
2464 /* Note, it is possible to have gaps in the register mask.
2465 We ignore this here, and generate a JARL anyway. We will
2466 be pushing more registers than is strictly necessary, but
2467 it does save code space. */
2469 if (TARGET_LONG_CALLS
)
2474 sprintf (name
, "__save_%s", reg_names
[first
]);
2476 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2478 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2484 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2486 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2493 extern tree last_assemble_variable_decl
;
2494 extern int size_directive_output
;
2496 /* A version of asm_output_aligned_bss() that copes with the special
2497 data areas of the v850. */
2499 v850_output_aligned_bss (FILE * file
,
2502 unsigned HOST_WIDE_INT size
,
2505 switch (v850_get_data_area (decl
))
2508 switch_to_section (zbss_section
);
2512 switch_to_section (sbss_section
);
2516 switch_to_section (tdata_section
);
2519 switch_to_section (bss_section
);
2523 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2524 #ifdef ASM_DECLARE_OBJECT_NAME
2525 last_assemble_variable_decl
= decl
;
2526 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2528 /* Standard thing is just output label for the object. */
2529 ASM_OUTPUT_LABEL (file
, name
);
2530 #endif /* ASM_DECLARE_OBJECT_NAME */
2531 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2534 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2536 v850_output_common (FILE * file
,
2542 if (decl
== NULL_TREE
)
2544 fprintf (file
, "%s", COMMON_ASM_OP
);
2548 switch (v850_get_data_area (decl
))
2551 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2555 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2559 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2563 fprintf (file
, "%s", COMMON_ASM_OP
);
2568 assemble_name (file
, name
);
2569 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2572 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2574 v850_output_local (FILE * file
,
2580 fprintf (file
, "%s", LOCAL_ASM_OP
);
2581 assemble_name (file
, name
);
2582 fprintf (file
, "\n");
2584 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2587 /* Add data area to the given declaration if a ghs data area pragma is
2588 currently in effect (#pragma ghs startXXX/endXXX). */
2590 v850_insert_attributes (tree decl
, tree
* attr_ptr ATTRIBUTE_UNUSED
)
2593 && data_area_stack
->data_area
2594 && current_function_decl
== NULL_TREE
2595 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2596 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2597 v850_set_data_area (decl
, data_area_stack
->data_area
);
2599 /* Initialize the default names of the v850 specific sections,
2600 if this has not been done before. */
2602 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2604 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2605 = build_string (sizeof (".sdata")-1, ".sdata");
2607 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2608 = build_string (sizeof (".rosdata")-1, ".rosdata");
2610 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2611 = build_string (sizeof (".tdata")-1, ".tdata");
2613 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2614 = build_string (sizeof (".zdata")-1, ".zdata");
2616 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2617 = build_string (sizeof (".rozdata")-1, ".rozdata");
2620 if (current_function_decl
== NULL_TREE
2621 && (TREE_CODE (decl
) == VAR_DECL
2622 || TREE_CODE (decl
) == CONST_DECL
2623 || TREE_CODE (decl
) == FUNCTION_DECL
)
2624 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2625 && !DECL_SECTION_NAME (decl
))
2627 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2628 tree chosen_section
;
2630 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2631 kind
= GHS_SECTION_KIND_TEXT
;
2634 /* First choose a section kind based on the data area of the decl. */
2635 switch (v850_get_data_area (decl
))
2641 kind
= ((TREE_READONLY (decl
))
2642 ? GHS_SECTION_KIND_ROSDATA
2643 : GHS_SECTION_KIND_SDATA
);
2647 kind
= GHS_SECTION_KIND_TDATA
;
2651 kind
= ((TREE_READONLY (decl
))
2652 ? GHS_SECTION_KIND_ROZDATA
2653 : GHS_SECTION_KIND_ZDATA
);
2656 case DATA_AREA_NORMAL
: /* default data area */
2657 if (TREE_READONLY (decl
))
2658 kind
= GHS_SECTION_KIND_RODATA
;
2659 else if (DECL_INITIAL (decl
))
2660 kind
= GHS_SECTION_KIND_DATA
;
2662 kind
= GHS_SECTION_KIND_BSS
;
2666 /* Now, if the section kind has been explicitly renamed,
2667 then attach a section attribute. */
2668 chosen_section
= GHS_current_section_names
[(int) kind
];
2670 /* Otherwise, if this kind of section needs an explicit section
2671 attribute, then also attach one. */
2672 if (chosen_section
== NULL
)
2673 chosen_section
= GHS_default_section_names
[(int) kind
];
2677 /* Only set the section name if specified by a pragma, because
2678 otherwise it will force those variables to get allocated storage
2679 in this module, rather than by the linker. */
2680 DECL_SECTION_NAME (decl
) = chosen_section
;
2685 /* Construct a DISPOSE instruction that is the equivalent of
2686 the given RTX. We have already verified that this should
2690 construct_dispose_instruction (rtx op
)
2692 int count
= XVECLEN (op
, 0);
2694 unsigned long int mask
;
2696 static char buff
[ 100 ]; /* XXX */
2701 error ("bogus DISPOSE construction: %d", count
);
2705 /* Work out how many bytes to pop off the
2706 stack before retrieving registers. */
2707 gcc_assert (GET_CODE (XVECEXP (op
, 0, 1)) == SET
);
2708 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) == PLUS
);
2709 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) == CONST_INT
);
2711 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2713 /* Each pop will remove 4 bytes from the stack.... */
2714 stack_bytes
-= (count
- 2) * 4;
2716 /* Make sure that the amount we are popping
2717 will fit into the DISPOSE instruction. */
2718 if (stack_bytes
> 128)
2720 error ("too much stack space to dispose of: %d", stack_bytes
);
2724 /* Now compute the bit mask of registers to push. */
2727 for (i
= 2; i
< count
; i
++)
2729 rtx vector_element
= XVECEXP (op
, 0, i
);
2731 gcc_assert (GET_CODE (vector_element
) == SET
);
2732 gcc_assert (GET_CODE (SET_DEST (vector_element
)) == REG
);
2733 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element
),
2736 if (REGNO (SET_DEST (vector_element
)) == 2)
2739 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2742 if (! TARGET_DISABLE_CALLT
2743 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
2747 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
2752 for (i
= 20; i
< 32; i
++)
2753 if (mask
& (1 << i
))
2757 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
2759 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
2760 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
2765 static char regs
[100]; /* XXX */
2768 /* Generate the DISPOSE instruction. Note we could just issue the
2769 bit mask as a number as the assembler can cope with this, but for
2770 the sake of our readers we turn it into a textual description. */
2774 for (i
= 20; i
< 32; i
++)
2776 if (mask
& (1 << i
))
2781 strcat (regs
, ", ");
2786 strcat (regs
, reg_names
[ first
]);
2788 for (i
++; i
< 32; i
++)
2789 if ((mask
& (1 << i
)) == 0)
2794 strcat (regs
, " - ");
2795 strcat (regs
, reg_names
[ i
- 1 ] );
2800 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
2806 /* Construct a PREPARE instruction that is the equivalent of
2807 the given RTL. We have already verified that this should
2811 construct_prepare_instruction (rtx op
)
2813 int count
= XVECLEN (op
, 0);
2815 unsigned long int mask
;
2817 static char buff
[ 100 ]; /* XXX */
2822 error ("bogus PREPEARE construction: %d", count
);
2826 /* Work out how many bytes to push onto
2827 the stack after storing the registers. */
2828 gcc_assert (GET_CODE (XVECEXP (op
, 0, 0)) == SET
);
2829 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) == PLUS
);
2830 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) == CONST_INT
);
2832 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2834 /* Each push will put 4 bytes from the stack. */
2835 stack_bytes
+= (count
- 1) * 4;
2837 /* Make sure that the amount we are popping
2838 will fit into the DISPOSE instruction. */
2839 if (stack_bytes
< -128)
2841 error ("too much stack space to prepare: %d", stack_bytes
);
2845 /* Now compute the bit mask of registers to push. */
2847 for (i
= 1; i
< count
; i
++)
2849 rtx vector_element
= XVECEXP (op
, 0, i
);
2851 gcc_assert (GET_CODE (vector_element
) == SET
);
2852 gcc_assert (GET_CODE (SET_SRC (vector_element
)) == REG
);
2853 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element
),
2856 if (REGNO (SET_SRC (vector_element
)) == 2)
2859 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2862 if ((! TARGET_DISABLE_CALLT
)
2863 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
2867 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
2871 for (i
= 20; i
< 32; i
++)
2872 if (mask
& (1 << i
))
2876 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
2878 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
2879 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
2883 static char regs
[100]; /* XXX */
2887 /* Generate the PREPARE instruction. Note we could just issue the
2888 bit mask as a number as the assembler can cope with this, but for
2889 the sake of our readers we turn it into a textual description. */
2893 for (i
= 20; i
< 32; i
++)
2895 if (mask
& (1 << i
))
2900 strcat (regs
, ", ");
2905 strcat (regs
, reg_names
[ first
]);
2907 for (i
++; i
< 32; i
++)
2908 if ((mask
& (1 << i
)) == 0)
2913 strcat (regs
, " - ");
2914 strcat (regs
, reg_names
[ i
- 1 ] );
2919 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
2925 /* Return an RTX indicating where the return address to the
2926 calling function can be found. */
2929 v850_return_addr (int count
)
2934 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
2937 /* Implement TARGET_ASM_INIT_SECTIONS. */
2940 v850_asm_init_sections (void)
2943 = get_unnamed_section (0, output_section_asm_op
,
2944 "\t.section .rosdata,\"a\"");
2947 = get_unnamed_section (0, output_section_asm_op
,
2948 "\t.section .rozdata,\"a\"");
2951 = get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
2952 "\t.section .tdata,\"aw\"");
2955 = get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
2956 "\t.section .zdata,\"aw\"");
2959 = get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
2960 output_section_asm_op
,
2961 "\t.section .zbss,\"aw\"");
2965 v850_select_section (tree exp
,
2966 int reloc ATTRIBUTE_UNUSED
,
2967 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
2969 if (TREE_CODE (exp
) == VAR_DECL
)
2972 if (!TREE_READONLY (exp
)
2973 || TREE_SIDE_EFFECTS (exp
)
2974 || !DECL_INITIAL (exp
)
2975 || (DECL_INITIAL (exp
) != error_mark_node
2976 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
2981 switch (v850_get_data_area (exp
))
2984 return is_const
? rozdata_section
: zdata_section
;
2987 return tdata_section
;
2990 return is_const
? rosdata_section
: sdata_section
;
2993 return is_const
? readonly_data_section
: data_section
;
2996 return readonly_data_section
;
2999 /* Worker function for TARGET_RETURN_IN_MEMORY. */
3002 v850_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
3004 /* Return values > 8 bytes in length in memory. */
3005 return int_size_in_bytes (type
) > 8 || TYPE_MODE (type
) == BLKmode
;
3008 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3011 v850_setup_incoming_varargs (CUMULATIVE_ARGS
*ca
,
3012 enum machine_mode mode ATTRIBUTE_UNUSED
,
3013 tree type ATTRIBUTE_UNUSED
,
3014 int *pretend_arg_size ATTRIBUTE_UNUSED
,
3015 int second_time ATTRIBUTE_UNUSED
)
3017 ca
->anonymous_args
= (!TARGET_GHS
? 1 : 0);
3020 #include "gt-v850.h"