1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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, 59 Temple Place - Suite 330, 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 void const_double_split (rtx
, HOST_WIDE_INT
*, HOST_WIDE_INT
*);
53 static int const_costs_int (HOST_WIDE_INT
, int);
54 static int const_costs (rtx
, enum rtx_code
);
55 static bool v850_rtx_costs (rtx
, int, int, int *);
56 static void substitute_ep_register (rtx
, rtx
, int, int, rtx
*, rtx
*);
57 static void v850_reorg (void);
58 static int ep_memory_offset (enum machine_mode
, int);
59 static void v850_set_data_area (tree
, v850_data_area
);
60 const struct attribute_spec v850_attribute_table
[];
61 static tree
v850_handle_interrupt_attribute (tree
*, tree
, tree
, int, bool *);
62 static tree
v850_handle_data_area_attribute (tree
*, tree
, tree
, int, bool *);
63 static void v850_insert_attributes (tree
, tree
*);
64 static void v850_select_section (tree
, int, unsigned HOST_WIDE_INT
);
65 static void v850_encode_data_area (tree
, rtx
);
66 static void v850_encode_section_info (tree
, rtx
, int);
67 static bool v850_return_in_memory (tree
, tree
);
68 static void v850_setup_incoming_varargs (CUMULATIVE_ARGS
*, enum machine_mode
,
70 static bool v850_pass_by_reference (CUMULATIVE_ARGS
*, enum machine_mode
,
73 /* Information about the various small memory areas. */
74 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
76 /* name value max physical max */
77 { "tda", (char *)0, 0, 256 },
78 { "sda", (char *)0, 0, 65536 },
79 { "zda", (char *)0, 0, 32768 },
82 /* Names of the various data areas used on the v850. */
83 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
84 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
86 /* Track the current data area set by the data area pragma (which
87 can be nested). Tested by check_default_data_area. */
88 data_area_stack_element
* data_area_stack
= NULL
;
90 /* True if we don't need to check any more if the current
91 function is an interrupt handler. */
92 static int v850_interrupt_cache_p
= FALSE
;
94 /* Whether current function is an interrupt handler. */
95 static int v850_interrupt_p
= FALSE
;
97 /* Initialize the GCC target structure. */
98 #undef TARGET_ASM_ALIGNED_HI_OP
99 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
101 #undef TARGET_ATTRIBUTE_TABLE
102 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
104 #undef TARGET_INSERT_ATTRIBUTES
105 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
107 #undef TARGET_ASM_SELECT_SECTION
108 #define TARGET_ASM_SELECT_SECTION v850_select_section
110 #undef TARGET_ENCODE_SECTION_INFO
111 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
113 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
114 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
116 #undef TARGET_RTX_COSTS
117 #define TARGET_RTX_COSTS v850_rtx_costs
119 #undef TARGET_ADDRESS_COST
120 #define TARGET_ADDRESS_COST hook_int_rtx_0
122 #undef TARGET_MACHINE_DEPENDENT_REORG
123 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
125 #undef TARGET_PROMOTE_PROTOTYPES
126 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
128 #undef TARGET_RETURN_IN_MEMORY
129 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
131 #undef TARGET_PASS_BY_REFERENCE
132 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
134 #undef TARGET_CALLEE_COPIES
135 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
137 #undef TARGET_SETUP_INCOMING_VARARGS
138 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
140 struct gcc_target targetm
= TARGET_INITIALIZER
;
142 /* Sometimes certain combinations of command options do not make
143 sense on a particular target machine. You can define a macro
144 `OVERRIDE_OPTIONS' to take account of this. This macro, if
145 defined, is executed once just after all the command options have
148 Don't use this macro to turn on various extra optimizations for
149 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
152 override_options (void)
155 extern int atoi (const char *);
157 /* Parse -m{s,t,z}da=nnn switches */
158 for (i
= 0; i
< (int)SMALL_MEMORY_max
; i
++)
160 if (small_memory
[i
].value
)
162 if (!ISDIGIT (*small_memory
[i
].value
))
163 error ("%s=%s is not numeric",
164 small_memory
[i
].name
,
165 small_memory
[i
].value
);
168 small_memory
[i
].max
= atoi (small_memory
[i
].value
);
169 if (small_memory
[i
].max
> small_memory
[i
].physical_max
)
170 error ("%s=%s is too large",
171 small_memory
[i
].name
,
172 small_memory
[i
].value
);
177 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
178 if ((target_flags
& MASK_US_MASK_SET
) == 0)
180 target_flags
|= MASK_US_MASK_SET
;
181 target_flags
&= ~MASK_US_BIT_SET
;
187 v850_pass_by_reference (CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
188 enum machine_mode mode
, tree type
,
189 bool named ATTRIBUTE_UNUSED
)
191 unsigned HOST_WIDE_INT size
;
194 size
= int_size_in_bytes (type
);
196 size
= GET_MODE_SIZE (mode
);
201 /* Return an RTX to represent where a value with mode MODE will be returned
202 from a function. If the result is 0, the argument is pushed. */
205 function_arg (CUMULATIVE_ARGS
* cum
,
206 enum machine_mode mode
,
213 if (TARGET_GHS
&& !named
)
217 size
= int_size_in_bytes (type
);
219 size
= GET_MODE_SIZE (mode
);
225 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
229 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
231 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
234 if (type
== NULL_TREE
235 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
238 switch (cum
->nbytes
/ UNITS_PER_WORD
)
241 result
= gen_rtx_REG (mode
, 6);
244 result
= gen_rtx_REG (mode
, 7);
247 result
= gen_rtx_REG (mode
, 8);
250 result
= gen_rtx_REG (mode
, 9);
260 /* Return the number of words which must be put into registers
261 for values which are part in registers and part in memory. */
264 function_arg_partial_nregs (CUMULATIVE_ARGS
* cum
,
265 enum machine_mode mode
,
271 if (TARGET_GHS
&& !named
)
275 size
= int_size_in_bytes (type
);
277 size
= GET_MODE_SIZE (mode
);
280 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
284 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
286 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
289 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
292 if (type
== NULL_TREE
293 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
296 return (4 * UNITS_PER_WORD
- cum
->nbytes
) / UNITS_PER_WORD
;
300 /* Return the high and low words of a CONST_DOUBLE */
303 const_double_split (rtx x
, HOST_WIDE_INT
* p_high
, HOST_WIDE_INT
* p_low
)
305 if (GET_CODE (x
) == CONST_DOUBLE
)
310 switch (GET_MODE (x
))
313 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
314 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
315 *p_high
= t
[1]; /* since v850 is little endian */
316 *p_low
= t
[0]; /* high is second word */
320 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
321 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
327 *p_high
= CONST_DOUBLE_HIGH (x
);
328 *p_low
= CONST_DOUBLE_LOW (x
);
336 fatal_insn ("const_double_split got a bad insn:", x
);
340 /* Return the cost of the rtx R with code CODE. */
343 const_costs_int (HOST_WIDE_INT value
, int zero_cost
)
345 if (CONST_OK_FOR_I (value
))
347 else if (CONST_OK_FOR_J (value
))
349 else if (CONST_OK_FOR_K (value
))
356 const_costs (rtx r
, enum rtx_code c
)
358 HOST_WIDE_INT high
, low
;
363 return const_costs_int (INTVAL (r
), 0);
366 const_double_split (r
, &high
, &low
);
367 if (GET_MODE (r
) == SFmode
)
368 return const_costs_int (high
, 1);
370 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
386 v850_rtx_costs (rtx x
,
388 int outer_code ATTRIBUTE_UNUSED
,
398 *total
= COSTS_N_INSNS (const_costs (x
, code
));
405 if (TARGET_V850E
&& optimize_size
)
413 && ( GET_MODE (x
) == SImode
414 || GET_MODE (x
) == HImode
415 || GET_MODE (x
) == QImode
))
417 if (GET_CODE (XEXP (x
, 1)) == REG
)
419 else if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
421 if (CONST_OK_FOR_O (INTVAL (XEXP (x
, 1))))
423 else if (CONST_OK_FOR_K (INTVAL (XEXP (x
, 1))))
436 /* Print operand X using operand code CODE to assembly language output file
440 print_operand (FILE * file
, rtx x
, int code
)
442 HOST_WIDE_INT high
, low
;
447 /* We use 'c' operands with symbols for .vtinherit */
448 if (GET_CODE (x
) == SYMBOL_REF
)
450 output_addr_const(file
, x
);
457 switch ((code
== 'B' || code
== 'C')
458 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
461 if (code
== 'c' || code
== 'C')
462 fprintf (file
, "nz");
464 fprintf (file
, "ne");
467 if (code
== 'c' || code
== 'C')
473 fprintf (file
, "ge");
476 fprintf (file
, "gt");
479 fprintf (file
, "le");
482 fprintf (file
, "lt");
485 fprintf (file
, "nl");
491 fprintf (file
, "nh");
500 case 'F': /* high word of CONST_DOUBLE */
501 if (GET_CODE (x
) == CONST_INT
)
502 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
503 else if (GET_CODE (x
) == CONST_DOUBLE
)
505 const_double_split (x
, &high
, &low
);
506 fprintf (file
, "%ld", (long) high
);
511 case 'G': /* low word of CONST_DOUBLE */
512 if (GET_CODE (x
) == CONST_INT
)
513 fprintf (file
, "%ld", (long) INTVAL (x
));
514 else if (GET_CODE (x
) == CONST_DOUBLE
)
516 const_double_split (x
, &high
, &low
);
517 fprintf (file
, "%ld", (long) low
);
523 fprintf (file
, "%d\n", (int)(INTVAL (x
) & 0xffff));
526 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
529 if (special_symbolref_operand (x
, VOIDmode
))
531 if (GET_CODE (x
) == SYMBOL_REF
)
533 else if (GET_CODE (x
) == CONST
)
534 x
= XEXP (XEXP (x
, 0), 0);
538 if (SYMBOL_REF_ZDA_P (x
))
539 fprintf (file
, "zdaoff");
540 else if (SYMBOL_REF_SDA_P (x
))
541 fprintf (file
, "sdaoff");
542 else if (SYMBOL_REF_TDA_P (x
))
543 fprintf (file
, "tdaoff");
551 if (special_symbolref_operand (x
, VOIDmode
))
552 output_addr_const (file
, x
);
557 if (special_symbolref_operand (x
, VOIDmode
))
559 if (GET_CODE (x
) == SYMBOL_REF
)
561 else if (GET_CODE (x
) == CONST
)
562 x
= XEXP (XEXP (x
, 0), 0);
566 if (SYMBOL_REF_ZDA_P (x
))
567 fprintf (file
, "r0");
568 else if (SYMBOL_REF_SDA_P (x
))
569 fprintf (file
, "gp");
570 else if (SYMBOL_REF_TDA_P (x
))
571 fprintf (file
, "ep");
578 case 'R': /* 2nd word of a double. */
579 switch (GET_CODE (x
))
582 fprintf (file
, reg_names
[REGNO (x
) + 1]);
585 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
586 print_operand_address (file
, x
);
587 if (GET_CODE (x
) == CONST_INT
)
588 fprintf (file
, "[r0]");
597 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
598 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
605 /* Like an 'S' operand above, but for unsigned loads only. */
606 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
611 case 'W': /* print the instruction suffix */
612 switch (GET_MODE (x
))
617 case QImode
: fputs (".b", file
); break;
618 case HImode
: fputs (".h", file
); break;
619 case SImode
: fputs (".w", file
); break;
620 case SFmode
: fputs (".w", file
); break;
623 case '.': /* register r0 */
624 fputs (reg_names
[0], file
);
626 case 'z': /* reg or zero */
628 fputs (reg_names
[0], file
);
629 else if (GET_CODE (x
) == REG
)
630 fputs (reg_names
[REGNO (x
)], file
);
635 switch (GET_CODE (x
))
638 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
639 output_address (gen_rtx_PLUS (SImode
, gen_rtx_REG (SImode
, 0),
642 output_address (XEXP (x
, 0));
646 fputs (reg_names
[REGNO (x
)], file
);
649 fputs (reg_names
[subreg_regno (x
)], file
);
656 print_operand_address (file
, x
);
667 /* Output assembly language output for the address ADDR to FILE. */
670 print_operand_address (FILE * file
, rtx addr
)
672 switch (GET_CODE (addr
))
675 fprintf (file
, "0[");
676 print_operand (file
, addr
, 0);
680 if (GET_CODE (XEXP (addr
, 0)) == REG
)
683 fprintf (file
, "lo(");
684 print_operand (file
, XEXP (addr
, 1), 0);
685 fprintf (file
, ")[");
686 print_operand (file
, XEXP (addr
, 0), 0);
691 if (GET_CODE (XEXP (addr
, 0)) == REG
692 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
695 print_operand (file
, XEXP (addr
, 1), 0);
697 print_operand (file
, XEXP (addr
, 0), 0);
702 print_operand (file
, XEXP (addr
, 0), 0);
704 print_operand (file
, XEXP (addr
, 1), 0);
709 const char *off_name
= NULL
;
710 const char *reg_name
= NULL
;
712 if (SYMBOL_REF_ZDA_P (addr
))
717 else if (SYMBOL_REF_SDA_P (addr
))
722 else if (SYMBOL_REF_TDA_P (addr
))
729 fprintf (file
, "%s(", off_name
);
730 output_addr_const (file
, addr
);
732 fprintf (file
, ")[%s]", reg_name
);
736 if (special_symbolref_operand (addr
, VOIDmode
))
738 rtx x
= XEXP (XEXP (addr
, 0), 0);
739 const char *off_name
;
740 const char *reg_name
;
742 if (SYMBOL_REF_ZDA_P (x
))
747 else if (SYMBOL_REF_SDA_P (x
))
752 else if (SYMBOL_REF_TDA_P (x
))
760 fprintf (file
, "%s(", off_name
);
761 output_addr_const (file
, addr
);
762 fprintf (file
, ")[%s]", reg_name
);
765 output_addr_const (file
, addr
);
768 output_addr_const (file
, addr
);
773 /* When assemble_integer is used to emit the offsets for a switch
774 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
775 output_addr_const will normally barf at this, but it is OK to omit
776 the truncate and just emit the difference of the two labels. The
777 .hword directive will automatically handle the truncation for us.
779 Returns 1 if rtx was handled, 0 otherwise. */
782 v850_output_addr_const_extra (FILE * file
, rtx x
)
784 if (GET_CODE (x
) != TRUNCATE
)
789 /* We must also handle the case where the switch table was passed a
790 constant value and so has been collapsed. In this case the first
791 label will have been deleted. In such a case it is OK to emit
792 nothing, since the table will not be used.
793 (cf gcc.c-torture/compile/990801-1.c). */
794 if (GET_CODE (x
) == MINUS
795 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
796 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
797 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
800 output_addr_const (file
, x
);
804 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
808 output_move_single (rtx
* operands
)
810 rtx dst
= operands
[0];
811 rtx src
= operands
[1];
818 else if (GET_CODE (src
) == CONST_INT
)
820 HOST_WIDE_INT value
= INTVAL (src
);
822 if (CONST_OK_FOR_J (value
)) /* Signed 5 bit immediate. */
825 else if (CONST_OK_FOR_K (value
)) /* Signed 16 bit immediate. */
826 return "movea lo(%1),%.,%0";
828 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
829 return "movhi hi(%1),%.,%0";
831 /* A random constant. */
832 else if (TARGET_V850E
)
835 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
838 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
840 HOST_WIDE_INT high
, low
;
842 const_double_split (src
, &high
, &low
);
844 if (CONST_OK_FOR_J (high
)) /* Signed 5 bit immediate. */
847 else if (CONST_OK_FOR_K (high
)) /* Signed 16 bit immediate. */
848 return "movea lo(%F1),%.,%0";
850 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
851 return "movhi hi(%F1),%.,%0";
853 /* A random constant. */
854 else if (TARGET_V850E
)
858 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
861 else if (GET_CODE (src
) == MEM
)
862 return "%S1ld%W1 %1,%0";
864 else if (special_symbolref_operand (src
, VOIDmode
))
865 return "movea %O1(%P1),%Q1,%0";
867 else if (GET_CODE (src
) == LABEL_REF
868 || GET_CODE (src
) == SYMBOL_REF
869 || GET_CODE (src
) == CONST
)
872 return "mov hilo(%1),%0";
874 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
877 else if (GET_CODE (src
) == HIGH
)
878 return "movhi hi(%1),%.,%0";
880 else if (GET_CODE (src
) == LO_SUM
)
882 operands
[2] = XEXP (src
, 0);
883 operands
[3] = XEXP (src
, 1);
884 return "movea lo(%3),%2,%0";
888 else if (GET_CODE (dst
) == MEM
)
891 return "%S0st%W0 %1,%0";
893 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
894 return "%S0st%W0 %.,%0";
896 else if (GET_CODE (src
) == CONST_DOUBLE
897 && CONST0_RTX (GET_MODE (dst
)) == src
)
898 return "%S0st%W0 %.,%0";
901 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
906 /* Return appropriate code to load up an 8 byte integer or
907 floating point value */
910 output_move_double (rtx
* operands
)
912 enum machine_mode mode
= GET_MODE (operands
[0]);
913 rtx dst
= operands
[0];
914 rtx src
= operands
[1];
916 if (register_operand (dst
, mode
)
917 && register_operand (src
, mode
))
919 if (REGNO (src
) + 1 == REGNO (dst
))
920 return "mov %R1,%R0\n\tmov %1,%0";
922 return "mov %1,%0\n\tmov %R1,%R0";
926 if (GET_CODE (dst
) == MEM
927 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
928 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
929 return "st.w %.,%0\n\tst.w %.,%R0";
931 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
933 HOST_WIDE_INT high_low
[2];
937 if (GET_CODE (src
) == CONST_DOUBLE
)
938 const_double_split (src
, &high_low
[1], &high_low
[0]);
941 high_low
[0] = INTVAL (src
);
942 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
945 for (i
= 0; i
< 2; i
++)
947 xop
[0] = gen_rtx_REG (SImode
, REGNO (dst
)+i
);
948 xop
[1] = GEN_INT (high_low
[i
]);
949 output_asm_insn (output_move_single (xop
), xop
);
955 if (GET_CODE (src
) == MEM
)
958 int dreg
= REGNO (dst
);
959 rtx inside
= XEXP (src
, 0);
961 if (GET_CODE (inside
) == REG
)
962 ptrreg
= REGNO (inside
);
963 else if (GET_CODE (inside
) == SUBREG
)
964 ptrreg
= subreg_regno (inside
);
965 else if (GET_CODE (inside
) == PLUS
)
966 ptrreg
= REGNO (XEXP (inside
, 0));
967 else if (GET_CODE (inside
) == LO_SUM
)
968 ptrreg
= REGNO (XEXP (inside
, 0));
971 return "ld.w %R1,%R0\n\tld.w %1,%0";
974 if (GET_CODE (src
) == MEM
)
975 return "ld.w %1,%0\n\tld.w %R1,%R0";
977 if (GET_CODE (dst
) == MEM
)
978 return "st.w %1,%0\n\tst.w %R1,%R0";
980 return "mov %1,%0\n\tmov %R1,%R0";
984 /* Return maximum offset supported for a short EP memory reference of mode
985 MODE and signedness UNSIGNEDP. */
988 ep_memory_offset (enum machine_mode mode
, int unsignedp ATTRIBUTE_UNUSED
)
995 if (TARGET_SMALL_SLD
)
996 max_offset
= (1 << 4);
997 else if (TARGET_V850E
998 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
999 || (! unsignedp
&& TARGET_US_BIT_SET
)))
1000 max_offset
= (1 << 4);
1002 max_offset
= (1 << 7);
1006 if (TARGET_SMALL_SLD
)
1007 max_offset
= (1 << 5);
1008 else if (TARGET_V850E
1009 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
1010 || (! unsignedp
&& TARGET_US_BIT_SET
)))
1011 max_offset
= (1 << 5);
1013 max_offset
= (1 << 8);
1018 max_offset
= (1 << 8);
1028 /* Return true if OP is a valid short EP memory reference */
1031 ep_memory_operand (rtx op
, enum machine_mode mode
, int unsigned_load
)
1037 if (GET_CODE (op
) != MEM
)
1040 max_offset
= ep_memory_offset (mode
, unsigned_load
);
1042 mask
= GET_MODE_SIZE (mode
) - 1;
1044 addr
= XEXP (op
, 0);
1045 if (GET_CODE (addr
) == CONST
)
1046 addr
= XEXP (addr
, 0);
1048 switch (GET_CODE (addr
))
1054 return SYMBOL_REF_TDA_P (addr
);
1057 return REGNO (addr
) == EP_REGNUM
;
1060 op0
= XEXP (addr
, 0);
1061 op1
= XEXP (addr
, 1);
1062 if (GET_CODE (op1
) == CONST_INT
1063 && INTVAL (op1
) < max_offset
1064 && INTVAL (op1
) >= 0
1065 && (INTVAL (op1
) & mask
) == 0)
1067 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1070 if (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_TDA_P (op0
))
1079 /* Return true if OP is either a register or 0 */
1082 reg_or_0_operand (rtx op
, enum machine_mode mode
)
1084 if (GET_CODE (op
) == CONST_INT
)
1085 return INTVAL (op
) == 0;
1087 else if (GET_CODE (op
) == CONST_DOUBLE
)
1088 return CONST_DOUBLE_OK_FOR_G (op
);
1091 return register_operand (op
, mode
);
1094 /* Return true if OP is either a register or a signed five bit integer */
1097 reg_or_int5_operand (rtx op
, enum machine_mode mode
)
1099 if (GET_CODE (op
) == CONST_INT
)
1100 return CONST_OK_FOR_J (INTVAL (op
));
1103 return register_operand (op
, mode
);
1106 /* Return true if OP is either a register or a signed nine bit integer. */
1109 reg_or_int9_operand (rtx op
, enum machine_mode mode
)
1111 if (GET_CODE (op
) == CONST_INT
)
1112 return CONST_OK_FOR_O (INTVAL (op
));
1114 return register_operand (op
, mode
);
1117 /* Return true if OP is either a register or a const integer. */
1120 reg_or_const_operand (rtx op
, enum machine_mode mode
)
1122 if (GET_CODE (op
) == CONST_INT
)
1125 return register_operand (op
, mode
);
1128 /* Return true if OP is a valid call operand. */
1131 call_address_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1133 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1134 if (TARGET_LONG_CALLS
)
1135 return GET_CODE (op
) == REG
;
1136 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == REG
);
1140 special_symbolref_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1142 if (GET_CODE (op
) == CONST
1143 && GET_CODE (XEXP (op
, 0)) == PLUS
1144 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
1145 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op
, 0), 1))))
1146 op
= XEXP (XEXP (op
, 0), 0);
1148 if (GET_CODE (op
) == SYMBOL_REF
)
1149 return (SYMBOL_REF_FLAGS (op
)
1150 & (SYMBOL_FLAG_ZDA
| SYMBOL_FLAG_TDA
| SYMBOL_FLAG_SDA
)) != 0;
1156 movsi_source_operand (rtx op
, enum machine_mode mode
)
1158 /* Some constants, as well as symbolic operands
1159 must be done with HIGH & LO_SUM patterns. */
1161 && GET_CODE (op
) != HIGH
1162 && !(GET_CODE (op
) == CONST_INT
1163 && (CONST_OK_FOR_J (INTVAL (op
))
1164 || CONST_OK_FOR_K (INTVAL (op
))
1165 || CONST_OK_FOR_L (INTVAL (op
)))))
1166 return special_symbolref_operand (op
, mode
);
1168 return general_operand (op
, mode
);
1172 power_of_two_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1174 if (GET_CODE (op
) != CONST_INT
)
1177 if (exact_log2 (INTVAL (op
)) == -1)
1183 not_power_of_two_operand (rtx op
, enum machine_mode mode
)
1189 else if (mode
== HImode
)
1191 else if (mode
== SImode
)
1196 if (GET_CODE (op
) != CONST_INT
)
1199 if (exact_log2 (~INTVAL (op
) & mask
) == -1)
1205 /* Substitute memory references involving a pointer, to use the ep pointer,
1206 taking care to save and preserve the ep. */
1209 substitute_ep_register (rtx first_insn
,
1216 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1221 regs_ever_live
[1] = 1;
1222 *p_r1
= gen_rtx_REG (Pmode
, 1);
1223 *p_ep
= gen_rtx_REG (Pmode
, 30);
1228 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1229 2 * (uses
- 3), uses
, reg_names
[regno
],
1230 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1231 INSN_UID (first_insn
), INSN_UID (last_insn
));
1233 if (GET_CODE (first_insn
) == NOTE
)
1234 first_insn
= next_nonnote_insn (first_insn
);
1236 last_insn
= next_nonnote_insn (last_insn
);
1237 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1239 if (GET_CODE (insn
) == INSN
)
1241 rtx pattern
= single_set (insn
);
1243 /* Replace the memory references. */
1247 /* Memory operands are signed by default. */
1248 int unsignedp
= FALSE
;
1250 if (GET_CODE (SET_DEST (pattern
)) == MEM
1251 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1254 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1255 p_mem
= &SET_DEST (pattern
);
1257 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1258 p_mem
= &SET_SRC (pattern
);
1260 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1261 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1262 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1264 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1265 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1267 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1275 rtx addr
= XEXP (*p_mem
, 0);
1277 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1278 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1280 else if (GET_CODE (addr
) == PLUS
1281 && GET_CODE (XEXP (addr
, 0)) == REG
1282 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1283 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1284 && ((INTVAL (XEXP (addr
, 1)))
1285 < ep_memory_offset (GET_MODE (*p_mem
),
1287 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1288 *p_mem
= change_address (*p_mem
, VOIDmode
,
1289 gen_rtx_PLUS (Pmode
,
1297 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1298 insn
= prev_nonnote_insn (first_insn
);
1299 if (insn
&& GET_CODE (insn
) == INSN
1300 && GET_CODE (PATTERN (insn
)) == SET
1301 && SET_DEST (PATTERN (insn
)) == *p_ep
1302 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1305 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1307 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1308 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1312 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1313 the -mep mode to copy heavily used pointers to ep to use the implicit
1325 regs
[FIRST_PSEUDO_REGISTER
];
1334 /* If not ep mode, just return now. */
1338 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1341 regs
[i
].first_insn
= NULL_RTX
;
1342 regs
[i
].last_insn
= NULL_RTX
;
1345 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1347 switch (GET_CODE (insn
))
1349 /* End of basic block */
1356 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1358 if (max_uses
< regs
[i
].uses
)
1360 max_uses
= regs
[i
].uses
;
1366 substitute_ep_register (regs
[max_regno
].first_insn
,
1367 regs
[max_regno
].last_insn
,
1368 max_uses
, max_regno
, &r1
, &ep
);
1372 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1375 regs
[i
].first_insn
= NULL_RTX
;
1376 regs
[i
].last_insn
= NULL_RTX
;
1384 pattern
= single_set (insn
);
1386 /* See if there are any memory references we can shorten */
1389 rtx src
= SET_SRC (pattern
);
1390 rtx dest
= SET_DEST (pattern
);
1392 /* Memory operands are signed by default. */
1393 int unsignedp
= FALSE
;
1395 /* We might have (SUBREG (MEM)) here, so just get rid of the
1396 subregs to make this code simpler. */
1397 if (GET_CODE (dest
) == SUBREG
1398 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1399 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1400 alter_subreg (&dest
);
1401 if (GET_CODE (src
) == SUBREG
1402 && (GET_CODE (SUBREG_REG (src
)) == MEM
1403 || GET_CODE (SUBREG_REG (src
)) == REG
))
1404 alter_subreg (&src
);
1406 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1409 else if (GET_CODE (dest
) == MEM
)
1412 else if (GET_CODE (src
) == MEM
)
1415 else if (GET_CODE (src
) == SIGN_EXTEND
1416 && GET_CODE (XEXP (src
, 0)) == MEM
)
1417 mem
= XEXP (src
, 0);
1419 else if (GET_CODE (src
) == ZERO_EXTEND
1420 && GET_CODE (XEXP (src
, 0)) == MEM
)
1422 mem
= XEXP (src
, 0);
1428 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1431 else if (!use_ep
&& mem
1432 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1434 rtx addr
= XEXP (mem
, 0);
1438 if (GET_CODE (addr
) == REG
)
1441 regno
= REGNO (addr
);
1444 else if (GET_CODE (addr
) == PLUS
1445 && GET_CODE (XEXP (addr
, 0)) == REG
1446 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1447 && ((INTVAL (XEXP (addr
, 1)))
1448 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1449 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1452 regno
= REGNO (XEXP (addr
, 0));
1461 regs
[regno
].last_insn
= insn
;
1462 if (!regs
[regno
].first_insn
)
1463 regs
[regno
].first_insn
= insn
;
1467 /* Loading up a register in the basic block zaps any savings
1469 if (GET_CODE (dest
) == REG
)
1471 enum machine_mode mode
= GET_MODE (dest
);
1475 regno
= REGNO (dest
);
1476 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1480 /* See if we can use the pointer before this
1485 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1487 if (max_uses
< regs
[i
].uses
)
1489 max_uses
= regs
[i
].uses
;
1495 && max_regno
>= regno
1496 && max_regno
< endregno
)
1498 substitute_ep_register (regs
[max_regno
].first_insn
,
1499 regs
[max_regno
].last_insn
,
1500 max_uses
, max_regno
, &r1
,
1503 /* Since we made a substitution, zap all remembered
1505 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1508 regs
[i
].first_insn
= NULL_RTX
;
1509 regs
[i
].last_insn
= NULL_RTX
;
1514 for (i
= regno
; i
< endregno
; i
++)
1517 regs
[i
].first_insn
= NULL_RTX
;
1518 regs
[i
].last_insn
= NULL_RTX
;
1527 /* # of registers saved by the interrupt handler. */
1528 #define INTERRUPT_FIXED_NUM 4
1530 /* # of bytes for registers saved by the interrupt handler. */
1531 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1533 /* # of registers saved in register parameter area. */
1534 #define INTERRUPT_REGPARM_NUM 4
1535 /* # of words saved for other registers. */
1536 #define INTERRUPT_ALL_SAVE_NUM \
1537 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1539 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1542 compute_register_save_size (long * p_reg_saved
)
1546 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1547 int call_p
= regs_ever_live
[LINK_POINTER_REGNUM
];
1550 /* Count the return pointer if we need to save it. */
1551 if (current_function_profile
&& !call_p
)
1552 regs_ever_live
[LINK_POINTER_REGNUM
] = call_p
= 1;
1554 /* Count space for the register saves. */
1555 if (interrupt_handler
)
1557 for (i
= 0; i
<= 31; i
++)
1561 if (regs_ever_live
[i
] || call_p
)
1564 reg_saved
|= 1L << i
;
1568 /* We don't save/restore r0 or the stack pointer */
1570 case STACK_POINTER_REGNUM
:
1573 /* For registers with fixed use, we save them, set them to the
1574 appropriate value, and then restore them.
1575 These registers are handled specially, so don't list them
1576 on the list of registers to save in the prologue. */
1577 case 1: /* temp used to hold ep */
1579 case 10: /* temp used to call interrupt save/restore */
1580 case EP_REGNUM
: /* ep */
1587 /* Find the first register that needs to be saved. */
1588 for (i
= 0; i
<= 31; i
++)
1589 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1590 || i
== LINK_POINTER_REGNUM
))
1593 /* If it is possible that an out-of-line helper function might be
1594 used to generate the prologue for the current function, then we
1595 need to cover the possibility that such a helper function will
1596 be used, despite the fact that there might be gaps in the list of
1597 registers that need to be saved. To detect this we note that the
1598 helper functions always push at least register r29 (provided
1599 that the function is not an interrupt handler). */
1601 if (TARGET_PROLOG_FUNCTION
1602 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1607 reg_saved
|= 1L << i
;
1612 /* Helper functions save all registers between the starting
1613 register and the last register, regardless of whether they
1614 are actually used by the function or not. */
1615 for (; i
<= 29; i
++)
1618 reg_saved
|= 1L << i
;
1621 if (regs_ever_live
[LINK_POINTER_REGNUM
])
1624 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1629 for (; i
<= 31; i
++)
1630 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1631 || i
== LINK_POINTER_REGNUM
))
1634 reg_saved
|= 1L << i
;
1640 *p_reg_saved
= reg_saved
;
1646 compute_frame_size (int size
, long * p_reg_saved
)
1649 + compute_register_save_size (p_reg_saved
)
1650 + current_function_outgoing_args_size
);
1655 expand_prologue (void)
1659 unsigned int size
= get_frame_size ();
1660 unsigned int actual_fsize
;
1661 unsigned int init_stack_alloc
= 0;
1664 unsigned int num_save
;
1665 unsigned int default_stack
;
1667 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1670 actual_fsize
= compute_frame_size (size
, ®_saved
);
1672 /* Save/setup global registers for interrupt functions right now. */
1673 if (interrupt_handler
)
1675 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1676 emit_insn (gen_callt_save_interrupt ());
1678 emit_insn (gen_save_interrupt ());
1680 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1682 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1683 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1686 /* Save arg registers to the stack if necessary. */
1687 else if (current_function_args_info
.anonymous_args
)
1689 if (TARGET_PROLOG_FUNCTION
&& TARGET_V850E
&& !TARGET_DISABLE_CALLT
)
1690 emit_insn (gen_save_r6_r9_v850e ());
1691 else if (TARGET_PROLOG_FUNCTION
&& ! TARGET_LONG_CALLS
)
1692 emit_insn (gen_save_r6_r9 ());
1696 for (i
= 6; i
< 10; i
++)
1698 emit_move_insn (gen_rtx_MEM (SImode
,
1699 plus_constant (stack_pointer_rtx
,
1701 gen_rtx_REG (SImode
, i
));
1707 /* Identify all of the saved registers. */
1710 for (i
= 1; i
< 31; i
++)
1712 if (((1L << i
) & reg_saved
) != 0)
1713 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1716 /* If the return pointer is saved, the helper functions also allocate
1717 16 bytes of stack for arguments to be saved in. */
1718 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1720 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1724 /* See if we have an insn that allocates stack space and saves the particular
1725 registers we want to. */
1726 save_all
= NULL_RTX
;
1727 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1729 int alloc_stack
= (4 * num_save
) + default_stack
;
1730 int unalloc_stack
= actual_fsize
- alloc_stack
;
1731 int save_func_len
= 4;
1732 int save_normal_len
;
1735 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1737 /* see if we would have used ep to save the stack */
1738 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1739 save_normal_len
= (3 * 2) + (2 * num_save
);
1741 save_normal_len
= 4 * num_save
;
1743 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1745 /* Don't bother checking if we don't actually save any space.
1746 This happens for instance if one register is saved and additional
1747 stack space is allocated. */
1748 if (save_func_len
< save_normal_len
)
1750 save_all
= gen_rtx_PARALLEL
1752 rtvec_alloc (num_save
+ 1
1753 + (TARGET_V850
? (TARGET_LONG_CALLS
? 2 : 1) : 0)));
1755 XVECEXP (save_all
, 0, 0)
1756 = gen_rtx_SET (VOIDmode
,
1758 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1760 offset
= - default_stack
;
1761 for (i
= 0; i
< num_save
; i
++)
1763 XVECEXP (save_all
, 0, i
+1)
1764 = gen_rtx_SET (VOIDmode
,
1766 plus_constant (stack_pointer_rtx
,
1774 XVECEXP (save_all
, 0, num_save
+ 1)
1775 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1777 if (TARGET_LONG_CALLS
)
1778 XVECEXP (save_all
, 0, num_save
+ 2)
1779 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 11));
1782 code
= recog (save_all
, NULL_RTX
, NULL
);
1785 rtx insn
= emit_insn (save_all
);
1786 INSN_CODE (insn
) = code
;
1787 actual_fsize
-= alloc_stack
;
1791 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1792 save_normal_len
- save_func_len
,
1793 save_normal_len
, save_func_len
,
1794 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1797 save_all
= NULL_RTX
;
1801 /* If no prolog save function is available, store the registers the old
1802 fashioned way (one by one). */
1805 /* Special case interrupt functions that save all registers for a call. */
1806 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1808 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1809 emit_insn (gen_callt_save_all_interrupt ());
1811 emit_insn (gen_save_all_interrupt ());
1815 /* If the stack is too big, allocate it in chunks so we can do the
1816 register saves. We use the register save size so we use the ep
1818 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1819 init_stack_alloc
= compute_register_save_size (NULL
);
1821 init_stack_alloc
= actual_fsize
;
1823 /* Save registers at the beginning of the stack frame. */
1824 offset
= init_stack_alloc
- 4;
1826 if (init_stack_alloc
)
1827 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1829 GEN_INT (-init_stack_alloc
)));
1831 /* Save the return pointer first. */
1832 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1834 emit_move_insn (gen_rtx_MEM (SImode
,
1835 plus_constant (stack_pointer_rtx
,
1837 save_regs
[--num_save
]);
1841 for (i
= 0; i
< num_save
; i
++)
1843 emit_move_insn (gen_rtx_MEM (SImode
,
1844 plus_constant (stack_pointer_rtx
,
1852 /* Allocate the rest of the stack that was not allocated above (either it is
1853 > 32K or we just called a function to save the registers and needed more
1855 if (actual_fsize
> init_stack_alloc
)
1857 int diff
= actual_fsize
- init_stack_alloc
;
1858 if (CONST_OK_FOR_K (diff
))
1859 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1864 rtx reg
= gen_rtx_REG (Pmode
, 12);
1865 emit_move_insn (reg
, GEN_INT (-diff
));
1866 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1870 /* If we need a frame pointer, set it up now. */
1871 if (frame_pointer_needed
)
1872 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1877 expand_epilogue (void)
1881 unsigned int size
= get_frame_size ();
1883 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1884 unsigned int init_stack_free
= 0;
1885 rtx restore_regs
[32];
1887 unsigned int num_restore
;
1888 unsigned int default_stack
;
1890 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1892 /* Eliminate the initial stack stored by interrupt functions. */
1893 if (interrupt_handler
)
1895 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1896 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1897 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1900 /* Cut off any dynamic stack created. */
1901 if (frame_pointer_needed
)
1902 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1904 /* Identify all of the saved registers. */
1907 for (i
= 1; i
< 31; i
++)
1909 if (((1L << i
) & reg_saved
) != 0)
1910 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1913 /* If the return pointer is saved, the helper functions also allocate
1914 16 bytes of stack for arguments to be saved in. */
1915 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1917 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1921 /* See if we have an insn that restores the particular registers we
1923 restore_all
= NULL_RTX
;
1925 if (TARGET_PROLOG_FUNCTION
1927 && actual_fsize
>= default_stack
1928 && !interrupt_handler
)
1930 int alloc_stack
= (4 * num_restore
) + default_stack
;
1931 int unalloc_stack
= actual_fsize
- alloc_stack
;
1932 int restore_func_len
= 4;
1933 int restore_normal_len
;
1936 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1938 /* See if we would have used ep to restore the registers. */
1939 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1940 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1942 restore_normal_len
= 4 * num_restore
;
1944 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1946 /* Don't bother checking if we don't actually save any space. */
1947 if (restore_func_len
< restore_normal_len
)
1949 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1950 rtvec_alloc (num_restore
+ 2));
1951 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1952 XVECEXP (restore_all
, 0, 1)
1953 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1954 gen_rtx_PLUS (Pmode
,
1956 GEN_INT (alloc_stack
)));
1958 offset
= alloc_stack
- 4;
1959 for (i
= 0; i
< num_restore
; i
++)
1961 XVECEXP (restore_all
, 0, i
+2)
1962 = gen_rtx_SET (VOIDmode
,
1965 plus_constant (stack_pointer_rtx
,
1970 code
= recog (restore_all
, NULL_RTX
, NULL
);
1976 actual_fsize
-= alloc_stack
;
1979 if (CONST_OK_FOR_K (actual_fsize
))
1980 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1982 GEN_INT (actual_fsize
)));
1985 rtx reg
= gen_rtx_REG (Pmode
, 12);
1986 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1987 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1993 insn
= emit_jump_insn (restore_all
);
1994 INSN_CODE (insn
) = code
;
1998 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1999 restore_normal_len
- restore_func_len
,
2000 restore_normal_len
, restore_func_len
,
2001 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
2004 restore_all
= NULL_RTX
;
2008 /* If no epilog save function is available, restore the registers the
2009 old fashioned way (one by one). */
2012 /* If the stack is large, we need to cut it down in 2 pieces. */
2013 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
2014 init_stack_free
= 4 * num_restore
;
2016 init_stack_free
= actual_fsize
;
2018 /* Deallocate the rest of the stack if it is > 32K. */
2019 if (actual_fsize
> init_stack_free
)
2023 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
2025 if (CONST_OK_FOR_K (diff
))
2026 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2031 rtx reg
= gen_rtx_REG (Pmode
, 12);
2032 emit_move_insn (reg
, GEN_INT (diff
));
2033 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2039 /* Special case interrupt functions that save all registers
2041 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
2043 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2044 emit_insn (gen_callt_restore_all_interrupt ());
2046 emit_insn (gen_restore_all_interrupt ());
2050 /* Restore registers from the beginning of the stack frame. */
2051 offset
= init_stack_free
- 4;
2053 /* Restore the return pointer first. */
2055 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
2057 emit_move_insn (restore_regs
[--num_restore
],
2058 gen_rtx_MEM (SImode
,
2059 plus_constant (stack_pointer_rtx
,
2064 for (i
= 0; i
< num_restore
; i
++)
2066 emit_move_insn (restore_regs
[i
],
2067 gen_rtx_MEM (SImode
,
2068 plus_constant (stack_pointer_rtx
,
2071 emit_insn (gen_rtx_USE (VOIDmode
, restore_regs
[i
]));
2075 /* Cut back the remainder of the stack. */
2076 if (init_stack_free
)
2077 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2079 GEN_INT (init_stack_free
)));
2082 /* And return or use reti for interrupt handlers. */
2083 if (interrupt_handler
)
2085 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2086 emit_insn (gen_callt_return_interrupt ());
2088 emit_jump_insn (gen_return_interrupt ());
2090 else if (actual_fsize
)
2091 emit_jump_insn (gen_return_internal ());
2093 emit_jump_insn (gen_return ());
2096 v850_interrupt_cache_p
= FALSE
;
2097 v850_interrupt_p
= FALSE
;
2101 /* Update the condition code from the insn. */
2104 notice_update_cc (rtx body
, rtx insn
)
2106 switch (get_attr_cc (insn
))
2109 /* Insn does not affect CC at all. */
2113 /* Insn does not change CC, but the 0'th operand has been changed. */
2114 if (cc_status
.value1
!= 0
2115 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2116 cc_status
.value1
= 0;
2120 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2121 V,C is in an unusable state. */
2123 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2124 cc_status
.value1
= recog_data
.operand
[0];
2128 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2129 C is in an unusable state. */
2131 cc_status
.flags
|= CC_NO_CARRY
;
2132 cc_status
.value1
= recog_data
.operand
[0];
2136 /* The insn is a compare instruction. */
2138 cc_status
.value1
= SET_SRC (body
);
2142 /* Insn doesn't leave CC in a usable state. */
2148 /* Retrieve the data area that has been chosen for the given decl. */
2151 v850_get_data_area (tree decl
)
2153 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2154 return DATA_AREA_SDA
;
2156 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2157 return DATA_AREA_TDA
;
2159 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2160 return DATA_AREA_ZDA
;
2162 return DATA_AREA_NORMAL
;
2165 /* Store the indicated data area in the decl's attributes. */
2168 v850_set_data_area (tree decl
, v850_data_area data_area
)
2174 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2175 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2176 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2181 DECL_ATTRIBUTES (decl
) = tree_cons
2182 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2185 const struct attribute_spec v850_attribute_table
[] =
2187 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2188 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2189 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2190 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2191 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2192 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2193 { NULL
, 0, 0, false, false, false, NULL
}
2196 /* Handle an "interrupt" attribute; arguments as in
2197 struct attribute_spec.handler. */
2199 v850_handle_interrupt_attribute (tree
* node
,
2201 tree args ATTRIBUTE_UNUSED
,
2202 int flags ATTRIBUTE_UNUSED
,
2203 bool * no_add_attrs
)
2205 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2207 warning ("%qs attribute only applies to functions",
2208 IDENTIFIER_POINTER (name
));
2209 *no_add_attrs
= true;
2215 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2216 struct attribute_spec.handler. */
2218 v850_handle_data_area_attribute (tree
* node
,
2220 tree args ATTRIBUTE_UNUSED
,
2221 int flags ATTRIBUTE_UNUSED
,
2222 bool * no_add_attrs
)
2224 v850_data_area data_area
;
2225 v850_data_area area
;
2228 /* Implement data area attribute. */
2229 if (is_attribute_p ("sda", name
))
2230 data_area
= DATA_AREA_SDA
;
2231 else if (is_attribute_p ("tda", name
))
2232 data_area
= DATA_AREA_TDA
;
2233 else if (is_attribute_p ("zda", name
))
2234 data_area
= DATA_AREA_ZDA
;
2238 switch (TREE_CODE (decl
))
2241 if (current_function_decl
!= NULL_TREE
)
2243 error ("%Jdata area attributes cannot be specified for "
2244 "local variables", decl
, decl
);
2245 *no_add_attrs
= true;
2251 area
= v850_get_data_area (decl
);
2252 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2254 error ("%Jdata area of '%D' conflicts with previous declaration",
2256 *no_add_attrs
= true;
2268 /* Return nonzero if FUNC is an interrupt function as specified
2269 by the "interrupt" attribute. */
2272 v850_interrupt_function_p (tree func
)
2277 if (v850_interrupt_cache_p
)
2278 return v850_interrupt_p
;
2280 if (TREE_CODE (func
) != FUNCTION_DECL
)
2283 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2289 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2290 ret
= a
!= NULL_TREE
;
2293 /* Its not safe to trust global variables until after function inlining has
2295 if (reload_completed
| reload_in_progress
)
2296 v850_interrupt_p
= ret
;
2303 v850_encode_data_area (tree decl
, rtx symbol
)
2307 /* Map explicit sections into the appropriate attribute */
2308 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2310 if (DECL_SECTION_NAME (decl
))
2312 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2314 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2315 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2317 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2318 v850_set_data_area (decl
, DATA_AREA_SDA
);
2320 else if (streq (name
, ".tdata"))
2321 v850_set_data_area (decl
, DATA_AREA_TDA
);
2324 /* If no attribute, support -m{zda,sda,tda}=n */
2327 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2331 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2332 v850_set_data_area (decl
, DATA_AREA_TDA
);
2334 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2335 v850_set_data_area (decl
, DATA_AREA_SDA
);
2337 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2338 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2341 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2345 flags
= SYMBOL_REF_FLAGS (symbol
);
2346 switch (v850_get_data_area (decl
))
2348 case DATA_AREA_ZDA
: flags
|= SYMBOL_FLAG_ZDA
; break;
2349 case DATA_AREA_TDA
: flags
|= SYMBOL_FLAG_TDA
; break;
2350 case DATA_AREA_SDA
: flags
|= SYMBOL_FLAG_SDA
; break;
2353 SYMBOL_REF_FLAGS (symbol
) = flags
;
2357 v850_encode_section_info (tree decl
, rtx rtl
, int first
)
2359 default_encode_section_info (decl
, rtl
, first
);
2361 if (TREE_CODE (decl
) == VAR_DECL
2362 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2363 v850_encode_data_area (decl
, XEXP (rtl
, 0));
2366 /* Return true if the given RTX is a register which can be restored
2367 by a function epilogue. */
2369 register_is_ok_for_epilogue (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2371 /* The save/restore routines can only cope with registers 20 - 31. */
2372 return ((GET_CODE (op
) == REG
)
2373 && (((REGNO (op
) >= 20) && REGNO (op
) <= 31)));
2376 /* Return nonzero if the given RTX is suitable for collapsing into
2377 jump to a function epilogue. */
2379 pattern_is_ok_for_epilogue (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2381 int count
= XVECLEN (op
, 0);
2384 /* If there are no registers to restore then the function epilogue
2389 /* The pattern matching has already established that we are performing a
2390 function epilogue and that we are popping at least one register. We must
2391 now check the remaining entries in the vector to make sure that they are
2392 also register pops. There is no good reason why there should ever be
2393 anything else in this vector, but being paranoid always helps...
2395 The test below performs the C equivalent of this machine description
2398 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2399 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2402 for (i
= 3; i
< count
; i
++)
2404 rtx vector_element
= XVECEXP (op
, 0, i
);
2409 if (GET_CODE (vector_element
) != SET
)
2412 dest
= SET_DEST (vector_element
);
2413 src
= SET_SRC (vector_element
);
2415 if (GET_CODE (dest
) != REG
2416 || GET_MODE (dest
) != SImode
2417 || ! register_is_ok_for_epilogue (dest
, SImode
)
2418 || GET_CODE (src
) != MEM
2419 || GET_MODE (src
) != SImode
)
2422 plus
= XEXP (src
, 0);
2424 if (GET_CODE (plus
) != PLUS
2425 || GET_CODE (XEXP (plus
, 0)) != REG
2426 || GET_MODE (XEXP (plus
, 0)) != SImode
2427 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2428 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2435 /* Construct a JR instruction to a routine that will perform the equivalent of
2436 the RTL passed in as an argument. This RTL is a function epilogue that
2437 pops registers off the stack and possibly releases some extra stack space
2438 as well. The code has already verified that the RTL matches these
2441 construct_restore_jr (rtx op
)
2443 int count
= XVECLEN (op
, 0);
2445 unsigned long int mask
;
2446 unsigned long int first
;
2447 unsigned long int last
;
2449 static char buff
[100]; /* XXX */
2453 error ("bogus JR construction: %d\n", count
);
2457 /* Work out how many bytes to pop off the stack before retrieving
2459 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2461 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2463 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2466 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2468 /* Each pop will remove 4 bytes from the stack.... */
2469 stack_bytes
-= (count
- 2) * 4;
2471 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2472 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2474 error ("bad amount of stack space removal: %d", stack_bytes
);
2478 /* Now compute the bit mask of registers to push. */
2480 for (i
= 2; i
< count
; i
++)
2482 rtx vector_element
= XVECEXP (op
, 0, i
);
2484 if (GET_CODE (vector_element
) != SET
)
2486 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2488 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
2491 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2494 /* Scan for the first register to pop. */
2495 for (first
= 0; first
< 32; first
++)
2497 if (mask
& (1 << first
))
2504 /* Discover the last register to pop. */
2505 if (mask
& (1 << LINK_POINTER_REGNUM
))
2507 if (stack_bytes
!= 16)
2510 last
= LINK_POINTER_REGNUM
;
2514 if (stack_bytes
!= 0)
2517 if ((mask
& (1 << 29)) == 0)
2523 /* Note, it is possible to have gaps in the register mask.
2524 We ignore this here, and generate a JR anyway. We will
2525 be popping more registers than is strictly necessary, but
2526 it does save code space. */
2528 if (TARGET_LONG_CALLS
)
2533 sprintf (name
, "__return_%s", reg_names
[first
]);
2535 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2537 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2543 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2545 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2552 /* Return nonzero if the given RTX is suitable for collapsing into
2553 a jump to a function prologue. */
2555 pattern_is_ok_for_prologue (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2557 int count
= XVECLEN (op
, 0);
2561 /* If there are no registers to save then the function prologue
2566 /* The pattern matching has already established that we are adjusting the
2567 stack and pushing at least one register. We must now check that the
2568 remaining entries in the vector to make sure that they are also register
2569 pushes, except for the last entry which should be a CLOBBER of r10.
2571 The test below performs the C equivalent of this machine description
2574 (set (mem:SI (plus:SI (reg:SI 3)
2575 (match_operand:SI 2 "immediate_operand" "i")))
2576 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2580 for (i
= 2; i
< count
- (TARGET_LONG_CALLS
? 2: 1); i
++)
2586 vector_element
= XVECEXP (op
, 0, i
);
2588 if (GET_CODE (vector_element
) != SET
)
2591 dest
= SET_DEST (vector_element
);
2592 src
= SET_SRC (vector_element
);
2594 if (GET_CODE (dest
) != MEM
2595 || GET_MODE (dest
) != SImode
2596 || GET_CODE (src
) != REG
2597 || GET_MODE (src
) != SImode
2598 || ! register_is_ok_for_epilogue (src
, SImode
))
2601 plus
= XEXP (dest
, 0);
2603 if ( GET_CODE (plus
) != PLUS
2604 || GET_CODE (XEXP (plus
, 0)) != REG
2605 || GET_MODE (XEXP (plus
, 0)) != SImode
2606 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2607 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2610 /* If the register is being pushed somewhere other than the stack
2611 space just acquired by the first operand then abandon this quest.
2612 Note: the test is <= because both values are negative. */
2613 if (INTVAL (XEXP (plus
, 1))
2614 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
2620 /* Make sure that the last entries in the vector are clobbers. */
2621 for (; i
< count
; i
++)
2623 vector_element
= XVECEXP (op
, 0, i
);
2625 if (GET_CODE (vector_element
) != CLOBBER
2626 || GET_CODE (XEXP (vector_element
, 0)) != REG
2627 || !(REGNO (XEXP (vector_element
, 0)) == 10
2628 || (TARGET_LONG_CALLS
? (REGNO (XEXP (vector_element
, 0)) == 11) : 0 )))
2635 /* Construct a JARL instruction to a routine that will perform the equivalent
2636 of the RTL passed as a parameter. This RTL is a function prologue that
2637 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2638 some stack space as well. The code has already verified that the RTL
2639 matches these requirements. */
2641 construct_save_jarl (rtx op
)
2643 int count
= XVECLEN (op
, 0);
2645 unsigned long int mask
;
2646 unsigned long int first
;
2647 unsigned long int last
;
2649 static char buff
[100]; /* XXX */
2653 error ("bogus JARL construction: %d\n", count
);
2658 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2660 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2662 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) != REG
)
2664 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2667 /* Work out how many bytes to push onto the stack after storing the
2669 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2671 /* Each push will put 4 bytes from the stack.... */
2672 stack_bytes
+= (count
- (TARGET_LONG_CALLS
? 3 : 2)) * 4;
2674 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2675 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2677 error ("bad amount of stack space removal: %d", stack_bytes
);
2681 /* Now compute the bit mask of registers to push. */
2683 for (i
= 1; i
< count
- (TARGET_LONG_CALLS
? 2 : 1); i
++)
2685 rtx vector_element
= XVECEXP (op
, 0, i
);
2687 if (GET_CODE (vector_element
) != SET
)
2689 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2691 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2694 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2697 /* Scan for the first register to push. */
2698 for (first
= 0; first
< 32; first
++)
2700 if (mask
& (1 << first
))
2707 /* Discover the last register to push. */
2708 if (mask
& (1 << LINK_POINTER_REGNUM
))
2710 if (stack_bytes
!= -16)
2713 last
= LINK_POINTER_REGNUM
;
2717 if (stack_bytes
!= 0)
2719 if ((mask
& (1 << 29)) == 0)
2725 /* Note, it is possible to have gaps in the register mask.
2726 We ignore this here, and generate a JARL anyway. We will
2727 be pushing more registers than is strictly necessary, but
2728 it does save code space. */
2730 if (TARGET_LONG_CALLS
)
2735 sprintf (name
, "__save_%s", reg_names
[first
]);
2737 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2739 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2745 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2747 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2754 extern tree last_assemble_variable_decl
;
2755 extern int size_directive_output
;
2757 /* A version of asm_output_aligned_bss() that copes with the special
2758 data areas of the v850. */
2760 v850_output_aligned_bss (FILE * file
,
2766 switch (v850_get_data_area (decl
))
2784 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2785 #ifdef ASM_DECLARE_OBJECT_NAME
2786 last_assemble_variable_decl
= decl
;
2787 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2789 /* Standard thing is just output label for the object. */
2790 ASM_OUTPUT_LABEL (file
, name
);
2791 #endif /* ASM_DECLARE_OBJECT_NAME */
2792 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2795 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2797 v850_output_common (FILE * file
,
2803 if (decl
== NULL_TREE
)
2805 fprintf (file
, "%s", COMMON_ASM_OP
);
2809 switch (v850_get_data_area (decl
))
2812 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2816 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2820 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2824 fprintf (file
, "%s", COMMON_ASM_OP
);
2829 assemble_name (file
, name
);
2830 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2833 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2835 v850_output_local (FILE * file
,
2841 fprintf (file
, "%s", LOCAL_ASM_OP
);
2842 assemble_name (file
, name
);
2843 fprintf (file
, "\n");
2845 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2848 /* Add data area to the given declaration if a ghs data area pragma is
2849 currently in effect (#pragma ghs startXXX/endXXX). */
2851 v850_insert_attributes (tree decl
, tree
* attr_ptr ATTRIBUTE_UNUSED
)
2854 && data_area_stack
->data_area
2855 && current_function_decl
== NULL_TREE
2856 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2857 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2858 v850_set_data_area (decl
, data_area_stack
->data_area
);
2860 /* Initialize the default names of the v850 specific sections,
2861 if this has not been done before. */
2863 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2865 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2866 = build_string (sizeof (".sdata")-1, ".sdata");
2868 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2869 = build_string (sizeof (".rosdata")-1, ".rosdata");
2871 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2872 = build_string (sizeof (".tdata")-1, ".tdata");
2874 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2875 = build_string (sizeof (".zdata")-1, ".zdata");
2877 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2878 = build_string (sizeof (".rozdata")-1, ".rozdata");
2881 if (current_function_decl
== NULL_TREE
2882 && (TREE_CODE (decl
) == VAR_DECL
2883 || TREE_CODE (decl
) == CONST_DECL
2884 || TREE_CODE (decl
) == FUNCTION_DECL
)
2885 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2886 && !DECL_SECTION_NAME (decl
))
2888 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2889 tree chosen_section
;
2891 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2892 kind
= GHS_SECTION_KIND_TEXT
;
2895 /* First choose a section kind based on the data area of the decl. */
2896 switch (v850_get_data_area (decl
))
2902 kind
= ((TREE_READONLY (decl
))
2903 ? GHS_SECTION_KIND_ROSDATA
2904 : GHS_SECTION_KIND_SDATA
);
2908 kind
= GHS_SECTION_KIND_TDATA
;
2912 kind
= ((TREE_READONLY (decl
))
2913 ? GHS_SECTION_KIND_ROZDATA
2914 : GHS_SECTION_KIND_ZDATA
);
2917 case DATA_AREA_NORMAL
: /* default data area */
2918 if (TREE_READONLY (decl
))
2919 kind
= GHS_SECTION_KIND_RODATA
;
2920 else if (DECL_INITIAL (decl
))
2921 kind
= GHS_SECTION_KIND_DATA
;
2923 kind
= GHS_SECTION_KIND_BSS
;
2927 /* Now, if the section kind has been explicitly renamed,
2928 then attach a section attribute. */
2929 chosen_section
= GHS_current_section_names
[(int) kind
];
2931 /* Otherwise, if this kind of section needs an explicit section
2932 attribute, then also attach one. */
2933 if (chosen_section
== NULL
)
2934 chosen_section
= GHS_default_section_names
[(int) kind
];
2938 /* Only set the section name if specified by a pragma, because
2939 otherwise it will force those variables to get allocated storage
2940 in this module, rather than by the linker. */
2941 DECL_SECTION_NAME (decl
) = chosen_section
;
2946 /* Return nonzero if the given RTX is suitable
2947 for collapsing into a DISPOSE instruction. */
2950 pattern_is_ok_for_dispose (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2952 int count
= XVECLEN (op
, 0);
2955 /* If there are no registers to restore then
2956 the dispose instruction is not suitable. */
2960 /* The pattern matching has already established that we are performing a
2961 function epilogue and that we are popping at least one register. We must
2962 now check the remaining entries in the vector to make sure that they are
2963 also register pops. There is no good reason why there should ever be
2964 anything else in this vector, but being paranoid always helps...
2966 The test below performs the C equivalent of this machine description
2969 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2970 (mem:SI (plus:SI (reg:SI 3)
2971 (match_operand:SI n "immediate_operand" "i"))))
2974 for (i
= 3; i
< count
; i
++)
2976 rtx vector_element
= XVECEXP (op
, 0, i
);
2981 if (GET_CODE (vector_element
) != SET
)
2984 dest
= SET_DEST (vector_element
);
2985 src
= SET_SRC (vector_element
);
2987 if ( GET_CODE (dest
) != REG
2988 || GET_MODE (dest
) != SImode
2989 || ! register_is_ok_for_epilogue (dest
, SImode
)
2990 || GET_CODE (src
) != MEM
2991 || GET_MODE (src
) != SImode
)
2994 plus
= XEXP (src
, 0);
2996 if ( GET_CODE (plus
) != PLUS
2997 || GET_CODE (XEXP (plus
, 0)) != REG
2998 || GET_MODE (XEXP (plus
, 0)) != SImode
2999 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3000 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3007 /* Construct a DISPOSE instruction that is the equivalent of
3008 the given RTX. We have already verified that this should
3012 construct_dispose_instruction (rtx op
)
3014 int count
= XVECLEN (op
, 0);
3016 unsigned long int mask
;
3018 static char buff
[ 100 ]; /* XXX */
3023 error ("Bogus DISPOSE construction: %d\n", count
);
3027 /* Work out how many bytes to pop off the
3028 stack before retrieving registers. */
3029 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
3031 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
3033 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
3036 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
3038 /* Each pop will remove 4 bytes from the stack.... */
3039 stack_bytes
-= (count
- 2) * 4;
3041 /* Make sure that the amount we are popping
3042 will fit into the DISPOSE instruction. */
3043 if (stack_bytes
> 128)
3045 error ("Too much stack space to dispose of: %d", stack_bytes
);
3049 /* Now compute the bit mask of registers to push. */
3052 for (i
= 2; i
< count
; i
++)
3054 rtx vector_element
= XVECEXP (op
, 0, i
);
3056 if (GET_CODE (vector_element
) != SET
)
3058 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
3060 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
3063 if (REGNO (SET_DEST (vector_element
)) == 2)
3066 mask
|= 1 << REGNO (SET_DEST (vector_element
));
3069 if (! TARGET_DISABLE_CALLT
3070 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
3074 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
3079 for (i
= 20; i
< 32; i
++)
3080 if (mask
& (1 << i
))
3084 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
3086 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
3087 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3092 static char regs
[100]; /* XXX */
3095 /* Generate the DISPOSE instruction. Note we could just issue the
3096 bit mask as a number as the assembler can cope with this, but for
3097 the sake of our readers we turn it into a textual description. */
3101 for (i
= 20; i
< 32; i
++)
3103 if (mask
& (1 << i
))
3108 strcat (regs
, ", ");
3113 strcat (regs
, reg_names
[ first
]);
3115 for (i
++; i
< 32; i
++)
3116 if ((mask
& (1 << i
)) == 0)
3121 strcat (regs
, " - ");
3122 strcat (regs
, reg_names
[ i
- 1 ] );
3127 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
3133 /* Return nonzero if the given RTX is suitable
3134 for collapsing into a PREPARE instruction. */
3137 pattern_is_ok_for_prepare (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
3139 int count
= XVECLEN (op
, 0);
3142 /* If there are no registers to restore then the prepare instruction
3147 /* The pattern matching has already established that we are adjusting the
3148 stack and pushing at least one register. We must now check that the
3149 remaining entries in the vector to make sure that they are also register
3152 The test below performs the C equivalent of this machine description
3155 (set (mem:SI (plus:SI (reg:SI 3)
3156 (match_operand:SI 2 "immediate_operand" "i")))
3157 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3161 for (i
= 2; i
< count
; i
++)
3163 rtx vector_element
= XVECEXP (op
, 0, i
);
3168 if (GET_CODE (vector_element
) != SET
)
3171 dest
= SET_DEST (vector_element
);
3172 src
= SET_SRC (vector_element
);
3174 if ( GET_CODE (dest
) != MEM
3175 || GET_MODE (dest
) != SImode
3176 || GET_CODE (src
) != REG
3177 || GET_MODE (src
) != SImode
3178 || ! register_is_ok_for_epilogue (src
, SImode
)
3182 plus
= XEXP (dest
, 0);
3184 if ( GET_CODE (plus
) != PLUS
3185 || GET_CODE (XEXP (plus
, 0)) != REG
3186 || GET_MODE (XEXP (plus
, 0)) != SImode
3187 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3188 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3191 /* If the register is being pushed somewhere other than the stack
3192 space just acquired by the first operand then abandon this quest.
3193 Note: the test is <= because both values are negative. */
3194 if (INTVAL (XEXP (plus
, 1))
3195 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
3202 /* Construct a PREPARE instruction that is the equivalent of
3203 the given RTL. We have already verified that this should
3207 construct_prepare_instruction (rtx op
)
3209 int count
= XVECLEN (op
, 0);
3211 unsigned long int mask
;
3213 static char buff
[ 100 ]; /* XXX */
3218 error ("Bogus PREPEARE construction: %d\n", count
);
3222 /* Work out how many bytes to push onto
3223 the stack after storing the registers. */
3224 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
3226 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
3228 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
3231 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
3233 /* Each push will put 4 bytes from the stack. */
3234 stack_bytes
+= (count
- 1) * 4;
3236 /* Make sure that the amount we are popping
3237 will fit into the DISPOSE instruction. */
3238 if (stack_bytes
< -128)
3240 error ("Too much stack space to prepare: %d", stack_bytes
);
3244 /* Now compute the bit mask of registers to push. */
3246 for (i
= 1; i
< count
; i
++)
3248 rtx vector_element
= XVECEXP (op
, 0, i
);
3250 if (GET_CODE (vector_element
) != SET
)
3252 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
3254 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
3257 if (REGNO (SET_SRC (vector_element
)) == 2)
3260 mask
|= 1 << REGNO (SET_SRC (vector_element
));
3263 if ((! TARGET_DISABLE_CALLT
)
3264 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
3268 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
3272 for (i
= 20; i
< 32; i
++)
3273 if (mask
& (1 << i
))
3277 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
3279 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
3280 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3284 static char regs
[100]; /* XXX */
3288 /* Generate the PREPARE instruction. Note we could just issue the
3289 bit mask as a number as the assembler can cope with this, but for
3290 the sake of our readers we turn it into a textual description. */
3294 for (i
= 20; i
< 32; i
++)
3296 if (mask
& (1 << i
))
3301 strcat (regs
, ", ");
3306 strcat (regs
, reg_names
[ first
]);
3308 for (i
++; i
< 32; i
++)
3309 if ((mask
& (1 << i
)) == 0)
3314 strcat (regs
, " - ");
3315 strcat (regs
, reg_names
[ i
- 1 ] );
3320 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
3326 /* Return an RTX indicating where the return address to the
3327 calling function can be found. */
3330 v850_return_addr (int count
)
3335 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
3339 v850_select_section (tree exp
,
3340 int reloc ATTRIBUTE_UNUSED
,
3341 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
3343 if (TREE_CODE (exp
) == VAR_DECL
)
3346 if (!TREE_READONLY (exp
)
3347 || TREE_SIDE_EFFECTS (exp
)
3348 || !DECL_INITIAL (exp
)
3349 || (DECL_INITIAL (exp
) != error_mark_node
3350 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
3355 switch (v850_get_data_area (exp
))
3377 readonly_data_section ();
3384 readonly_data_section ();
3387 /* Worker function for TARGET_RETURN_IN_MEMORY. */
3390 v850_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
3392 /* Return values > 8 bytes in length in memory. */
3393 return int_size_in_bytes (type
) > 8 || TYPE_MODE (type
) == BLKmode
;
3396 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3399 v850_setup_incoming_varargs (CUMULATIVE_ARGS
*ca
,
3400 enum machine_mode mode ATTRIBUTE_UNUSED
,
3401 tree type ATTRIBUTE_UNUSED
,
3402 int *pretend_arg_size ATTRIBUTE_UNUSED
,
3403 int second_time ATTRIBUTE_UNUSED
)
3405 ca
->anonymous_args
= (!TARGET_GHS
? 1 : 0);