1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996-2014 Free Software Foundation, Inc.
3 Contributed by Jeff Law (law@cygnus.com).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
26 #include "stringpool.h"
27 #include "stor-layout.h"
32 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
36 #include "insn-attr.h"
41 #include "diagnostic-core.h"
45 #include "target-def.h"
51 #define streq(a,b) (strcmp (a, b) == 0)
54 static void v850_print_operand_address (FILE *, rtx
);
56 /* Names of the various data areas used on the v850. */
57 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
58 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
60 /* Track the current data area set by the data area pragma (which
61 can be nested). Tested by check_default_data_area. */
62 data_area_stack_element
* data_area_stack
= NULL
;
64 /* True if we don't need to check any more if the current
65 function is an interrupt handler. */
66 static int v850_interrupt_cache_p
= FALSE
;
68 rtx v850_compare_op0
, v850_compare_op1
;
70 /* Whether current function is an interrupt handler. */
71 static int v850_interrupt_p
= FALSE
;
73 static GTY(()) section
* rosdata_section
;
74 static GTY(()) section
* rozdata_section
;
75 static GTY(()) section
* tdata_section
;
76 static GTY(()) section
* zdata_section
;
77 static GTY(()) section
* zbss_section
;
79 /* We use this to wrap all emitted insns in the prologue. */
83 if (GET_CODE (x
) != CLOBBER
)
84 RTX_FRAME_RELATED_P (x
) = 1;
88 /* Mark all the subexpressions of the PARALLEL rtx PAR as
89 frame-related. Return PAR.
91 dwarf2out.c:dwarf2out_frame_debug_expr ignores sub-expressions of a
92 PARALLEL rtx other than the first if they do not have the
93 FRAME_RELATED flag set on them. */
96 v850_all_frame_related (rtx par
)
98 int len
= XVECLEN (par
, 0);
101 gcc_assert (GET_CODE (par
) == PARALLEL
);
102 for (i
= 0; i
< len
; i
++)
103 F (XVECEXP (par
, 0, i
));
108 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
109 Specify whether to pass the argument by reference. */
112 v850_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED
,
113 enum machine_mode mode
, const_tree type
,
114 bool named ATTRIBUTE_UNUSED
)
116 unsigned HOST_WIDE_INT size
;
122 size
= int_size_in_bytes (type
);
124 size
= GET_MODE_SIZE (mode
);
129 /* Return an RTX to represent where an argument with mode MODE
130 and type TYPE will be passed to a function. If the result
131 is NULL_RTX, the argument will be pushed. */
134 v850_function_arg (cumulative_args_t cum_v
, enum machine_mode mode
,
135 const_tree type
, bool named
)
137 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
138 rtx result
= NULL_RTX
;
145 size
= int_size_in_bytes (type
);
147 size
= GET_MODE_SIZE (mode
);
149 size
= (size
+ UNITS_PER_WORD
-1) & ~(UNITS_PER_WORD
-1);
153 /* Once we have stopped using argument registers, do not start up again. */
154 cum
->nbytes
= 4 * UNITS_PER_WORD
;
159 align
= UNITS_PER_WORD
;
160 else if (size
<= UNITS_PER_WORD
&& type
)
161 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
165 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
167 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
170 if (type
== NULL_TREE
171 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
174 switch (cum
->nbytes
/ UNITS_PER_WORD
)
177 result
= gen_rtx_REG (mode
, 6);
180 result
= gen_rtx_REG (mode
, 7);
183 result
= gen_rtx_REG (mode
, 8);
186 result
= gen_rtx_REG (mode
, 9);
195 /* Return the number of bytes which must be put into registers
196 for values which are part in registers and part in memory. */
198 v850_arg_partial_bytes (cumulative_args_t cum_v
, enum machine_mode mode
,
199 tree type
, bool named
)
201 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
208 size
= int_size_in_bytes (type
);
210 size
= GET_MODE_SIZE (mode
);
216 align
= UNITS_PER_WORD
;
218 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
222 cum
->nbytes
= (cum
->nbytes
+ align
- 1) & ~ (align
- 1);
224 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
227 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
230 if (type
== NULL_TREE
231 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
234 return 4 * UNITS_PER_WORD
- cum
->nbytes
;
237 /* Update the data in CUM to advance over an argument
238 of mode MODE and data type TYPE.
239 (TYPE is null for libcalls where that information may not be available.) */
242 v850_function_arg_advance (cumulative_args_t cum_v
, enum machine_mode mode
,
243 const_tree type
, bool named ATTRIBUTE_UNUSED
)
245 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
248 cum
->nbytes
+= (((mode
!= BLKmode
249 ? GET_MODE_SIZE (mode
)
250 : int_size_in_bytes (type
)) + UNITS_PER_WORD
- 1)
253 cum
->nbytes
+= (((type
&& int_size_in_bytes (type
) > 8
254 ? GET_MODE_SIZE (Pmode
)
256 ? GET_MODE_SIZE (mode
)
257 : int_size_in_bytes (type
))) + UNITS_PER_WORD
- 1)
261 /* Return the high and low words of a CONST_DOUBLE */
264 const_double_split (rtx x
, HOST_WIDE_INT
* p_high
, HOST_WIDE_INT
* p_low
)
266 if (GET_CODE (x
) == CONST_DOUBLE
)
271 switch (GET_MODE (x
))
274 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
275 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
276 *p_high
= t
[1]; /* since v850 is little endian */
277 *p_low
= t
[0]; /* high is second word */
281 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
282 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
288 *p_high
= CONST_DOUBLE_HIGH (x
);
289 *p_low
= CONST_DOUBLE_LOW (x
);
297 fatal_insn ("const_double_split got a bad insn:", x
);
301 /* Return the cost of the rtx R with code CODE. */
304 const_costs_int (HOST_WIDE_INT value
, int zero_cost
)
306 if (CONST_OK_FOR_I (value
))
308 else if (CONST_OK_FOR_J (value
))
310 else if (CONST_OK_FOR_K (value
))
317 const_costs (rtx r
, enum rtx_code c
)
319 HOST_WIDE_INT high
, low
;
324 return const_costs_int (INTVAL (r
), 0);
327 const_double_split (r
, &high
, &low
);
328 if (GET_MODE (r
) == SFmode
)
329 return const_costs_int (high
, 1);
331 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
347 v850_rtx_costs (rtx x
,
349 int outer_code ATTRIBUTE_UNUSED
,
350 int opno ATTRIBUTE_UNUSED
,
351 int * total
, bool speed
)
353 enum rtx_code code
= (enum rtx_code
) codearg
;
362 *total
= COSTS_N_INSNS (const_costs (x
, code
));
369 if (TARGET_V850E
&& !speed
)
377 && ( GET_MODE (x
) == SImode
378 || GET_MODE (x
) == HImode
379 || GET_MODE (x
) == QImode
))
381 if (GET_CODE (XEXP (x
, 1)) == REG
)
383 else if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
385 if (CONST_OK_FOR_O (INTVAL (XEXP (x
, 1))))
387 else if (CONST_OK_FOR_K (INTVAL (XEXP (x
, 1))))
396 if (outer_code
== COMPARE
)
405 /* Print operand X using operand code CODE to assembly language output file
409 v850_print_operand (FILE * file
, rtx x
, int code
)
411 HOST_WIDE_INT high
, low
;
416 /* We use 'c' operands with symbols for .vtinherit. */
417 if (GET_CODE (x
) == SYMBOL_REF
)
419 output_addr_const(file
, x
);
426 switch ((code
== 'B' || code
== 'C')
427 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
430 if (code
== 'c' || code
== 'C')
431 fprintf (file
, "nz");
433 fprintf (file
, "ne");
436 if (code
== 'c' || code
== 'C')
442 fprintf (file
, "ge");
445 fprintf (file
, "gt");
448 fprintf (file
, "le");
451 fprintf (file
, "lt");
454 fprintf (file
, "nl");
460 fprintf (file
, "nh");
469 case 'F': /* High word of CONST_DOUBLE. */
470 switch (GET_CODE (x
))
473 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
477 const_double_split (x
, &high
, &low
);
478 fprintf (file
, "%ld", (long) high
);
485 case 'G': /* Low word of CONST_DOUBLE. */
486 switch (GET_CODE (x
))
489 fprintf (file
, "%ld", (long) INTVAL (x
));
493 const_double_split (x
, &high
, &low
);
494 fprintf (file
, "%ld", (long) low
);
502 fprintf (file
, "%d\n", (int)(INTVAL (x
) & 0xffff));
505 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
508 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
510 if (GET_CODE (x
) == CONST
)
511 x
= XEXP (XEXP (x
, 0), 0);
513 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
515 if (SYMBOL_REF_ZDA_P (x
))
516 fprintf (file
, "zdaoff");
517 else if (SYMBOL_REF_SDA_P (x
))
518 fprintf (file
, "sdaoff");
519 else if (SYMBOL_REF_TDA_P (x
))
520 fprintf (file
, "tdaoff");
525 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
526 output_addr_const (file
, x
);
529 gcc_assert (special_symbolref_operand (x
, VOIDmode
));
531 if (GET_CODE (x
) == CONST
)
532 x
= XEXP (XEXP (x
, 0), 0);
534 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
536 if (SYMBOL_REF_ZDA_P (x
))
537 fprintf (file
, "r0");
538 else if (SYMBOL_REF_SDA_P (x
))
539 fprintf (file
, "gp");
540 else if (SYMBOL_REF_TDA_P (x
))
541 fprintf (file
, "ep");
545 case 'R': /* 2nd word of a double. */
546 switch (GET_CODE (x
))
549 fprintf (file
, reg_names
[REGNO (x
) + 1]);
552 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
553 v850_print_operand_address (file
, x
);
554 if (GET_CODE (x
) == CONST_INT
)
555 fprintf (file
, "[r0]");
560 unsigned HOST_WIDE_INT v
= INTVAL (x
);
562 /* Trickery to avoid problems with shifting
563 32-bits at a time on a 32-bit host. */
566 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, v
);
571 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_HIGH (x
));
581 /* If it's a reference to a TDA variable, use sst/sld vs. st/ld. */
582 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
589 /* Like an 'S' operand above, but for unsigned loads only. */
590 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
595 case 'W': /* Print the instruction suffix. */
596 switch (GET_MODE (x
))
601 case QImode
: fputs (".b", file
); break;
602 case HImode
: fputs (".h", file
); break;
603 case SImode
: fputs (".w", file
); break;
604 case SFmode
: fputs (".w", file
); break;
607 case '.': /* Register r0. */
608 fputs (reg_names
[0], file
);
610 case 'z': /* Reg or zero. */
612 fputs (reg_names
[REGNO (x
)], file
);
613 else if ((GET_MODE(x
) == SImode
614 || GET_MODE(x
) == DFmode
615 || GET_MODE(x
) == SFmode
)
616 && x
== CONST0_RTX(GET_MODE(x
)))
617 fputs (reg_names
[0], file
);
620 gcc_assert (x
== const0_rtx
);
621 fputs (reg_names
[0], file
);
625 switch (GET_CODE (x
))
628 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
629 output_address (gen_rtx_PLUS (SImode
, gen_rtx_REG (SImode
, 0),
632 output_address (XEXP (x
, 0));
636 fputs (reg_names
[REGNO (x
)], file
);
639 fputs (reg_names
[subreg_regno (x
)], file
);
642 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_LOW (x
));
650 v850_print_operand_address (file
, x
);
661 /* Output assembly language output for the address ADDR to FILE. */
664 v850_print_operand_address (FILE * file
, rtx addr
)
666 switch (GET_CODE (addr
))
669 fprintf (file
, "0[");
670 v850_print_operand (file
, addr
, 0);
674 if (GET_CODE (XEXP (addr
, 0)) == REG
)
677 fprintf (file
, "lo(");
678 v850_print_operand (file
, XEXP (addr
, 1), 0);
679 fprintf (file
, ")[");
680 v850_print_operand (file
, XEXP (addr
, 0), 0);
685 if (GET_CODE (XEXP (addr
, 0)) == REG
686 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
689 v850_print_operand (file
, XEXP (addr
, 1), 0);
691 v850_print_operand (file
, XEXP (addr
, 0), 0);
696 v850_print_operand (file
, XEXP (addr
, 0), 0);
698 v850_print_operand (file
, XEXP (addr
, 1), 0);
703 const char *off_name
= NULL
;
704 const char *reg_name
= NULL
;
706 if (SYMBOL_REF_ZDA_P (addr
))
711 else if (SYMBOL_REF_SDA_P (addr
))
716 else if (SYMBOL_REF_TDA_P (addr
))
723 fprintf (file
, "%s(", off_name
);
724 output_addr_const (file
, addr
);
726 fprintf (file
, ")[%s]", reg_name
);
730 if (special_symbolref_operand (addr
, VOIDmode
))
732 rtx x
= XEXP (XEXP (addr
, 0), 0);
733 const char *off_name
;
734 const char *reg_name
;
736 if (SYMBOL_REF_ZDA_P (x
))
741 else if (SYMBOL_REF_SDA_P (x
))
746 else if (SYMBOL_REF_TDA_P (x
))
754 fprintf (file
, "%s(", off_name
);
755 output_addr_const (file
, addr
);
756 fprintf (file
, ")[%s]", reg_name
);
759 output_addr_const (file
, addr
);
762 output_addr_const (file
, addr
);
768 v850_print_operand_punct_valid_p (unsigned char code
)
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 true if rtx was handled, false 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 %1,%.,%0";
828 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
829 return "movhi hi0(%1),%.,%0";
831 /* A random constant. */
832 else if (TARGET_V850E_UP
)
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 %F1,%.,%0";
850 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
851 return "movhi hi0(%F1),%.,%0";
853 /* A random constant. */
854 else if (TARGET_V850E_UP
)
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 v850_select_cc_mode (enum rtx_code cond
, rtx op0
, rtx op1 ATTRIBUTE_UNUSED
)
908 if (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_FLOAT
)
913 return CC_FPU_LEmode
;
915 return CC_FPU_GEmode
;
917 return CC_FPU_LTmode
;
919 return CC_FPU_GTmode
;
921 return CC_FPU_EQmode
;
923 return CC_FPU_NEmode
;
932 v850_gen_float_compare (enum rtx_code cond
, enum machine_mode mode ATTRIBUTE_UNUSED
, rtx op0
, rtx op1
)
934 if (GET_MODE (op0
) == DFmode
)
939 emit_insn (gen_cmpdf_le_insn (op0
, op1
));
942 emit_insn (gen_cmpdf_ge_insn (op0
, op1
));
945 emit_insn (gen_cmpdf_lt_insn (op0
, op1
));
948 emit_insn (gen_cmpdf_gt_insn (op0
, op1
));
951 /* Note: There is no NE comparison operator. So we
952 perform an EQ comparison and invert the branch.
953 See v850_float_nz_comparison for how this is done. */
955 emit_insn (gen_cmpdf_eq_insn (op0
, op1
));
961 else if (GET_MODE (v850_compare_op0
) == SFmode
)
966 emit_insn (gen_cmpsf_le_insn(op0
, op1
));
969 emit_insn (gen_cmpsf_ge_insn(op0
, op1
));
972 emit_insn (gen_cmpsf_lt_insn(op0
, op1
));
975 emit_insn (gen_cmpsf_gt_insn(op0
, op1
));
978 /* Note: There is no NE comparison operator. So we
979 perform an EQ comparison and invert the branch.
980 See v850_float_nz_comparison for how this is done. */
982 emit_insn (gen_cmpsf_eq_insn(op0
, op1
));
991 return v850_select_cc_mode (cond
, op0
, op1
);
995 v850_gen_compare (enum rtx_code cond
, enum machine_mode mode
, rtx op0
, rtx op1
)
997 if (GET_MODE_CLASS(GET_MODE (op0
)) != MODE_FLOAT
)
999 emit_insn (gen_cmpsi_insn (op0
, op1
));
1000 return gen_rtx_fmt_ee (cond
, mode
, gen_rtx_REG(CCmode
, CC_REGNUM
), const0_rtx
);
1005 mode
= v850_gen_float_compare (cond
, mode
, op0
, op1
);
1006 cc_reg
= gen_rtx_REG (mode
, CC_REGNUM
);
1007 emit_insn (gen_rtx_SET(mode
, cc_reg
, gen_rtx_REG (mode
, FCC_REGNUM
)));
1009 return gen_rtx_fmt_ee (cond
, mode
, cc_reg
, const0_rtx
);
1013 /* Return maximum offset supported for a short EP memory reference of mode
1014 MODE and signedness UNSIGNEDP. */
1017 ep_memory_offset (enum machine_mode mode
, int unsignedp ATTRIBUTE_UNUSED
)
1024 if (TARGET_SMALL_SLD
)
1025 max_offset
= (1 << 4);
1026 else if ((TARGET_V850E_UP
)
1028 max_offset
= (1 << 4);
1030 max_offset
= (1 << 7);
1034 if (TARGET_SMALL_SLD
)
1035 max_offset
= (1 << 5);
1036 else if ((TARGET_V850E_UP
)
1038 max_offset
= (1 << 5);
1040 max_offset
= (1 << 8);
1045 max_offset
= (1 << 8);
1055 /* Return true if OP is a valid short EP memory reference */
1058 ep_memory_operand (rtx op
, enum machine_mode mode
, int unsigned_load
)
1064 /* If we are not using the EP register on a per-function basis
1065 then do not allow this optimization at all. This is to
1066 prevent the use of the SLD/SST instructions which cannot be
1067 guaranteed to work properly due to a hardware bug. */
1071 if (GET_CODE (op
) != MEM
)
1074 max_offset
= ep_memory_offset (mode
, unsigned_load
);
1076 mask
= GET_MODE_SIZE (mode
) - 1;
1078 addr
= XEXP (op
, 0);
1079 if (GET_CODE (addr
) == CONST
)
1080 addr
= XEXP (addr
, 0);
1082 switch (GET_CODE (addr
))
1088 return SYMBOL_REF_TDA_P (addr
);
1091 return REGNO (addr
) == EP_REGNUM
;
1094 op0
= XEXP (addr
, 0);
1095 op1
= XEXP (addr
, 1);
1096 if (GET_CODE (op1
) == CONST_INT
1097 && INTVAL (op1
) < max_offset
1098 && INTVAL (op1
) >= 0
1099 && (INTVAL (op1
) & mask
) == 0)
1101 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1104 if (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_TDA_P (op0
))
1113 /* Substitute memory references involving a pointer, to use the ep pointer,
1114 taking care to save and preserve the ep. */
1117 substitute_ep_register (rtx first_insn
,
1124 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1129 df_set_regs_ever_live (1, true);
1130 *p_r1
= gen_rtx_REG (Pmode
, 1);
1131 *p_ep
= gen_rtx_REG (Pmode
, 30);
1136 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1137 2 * (uses
- 3), uses
, reg_names
[regno
],
1138 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1139 INSN_UID (first_insn
), INSN_UID (last_insn
));
1141 if (NOTE_P (first_insn
))
1142 first_insn
= next_nonnote_insn (first_insn
);
1144 last_insn
= next_nonnote_insn (last_insn
);
1145 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1147 if (NONJUMP_INSN_P (insn
))
1149 rtx pattern
= single_set (insn
);
1151 /* Replace the memory references. */
1155 /* Memory operands are signed by default. */
1156 int unsignedp
= FALSE
;
1158 if (GET_CODE (SET_DEST (pattern
)) == MEM
1159 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1162 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1163 p_mem
= &SET_DEST (pattern
);
1165 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1166 p_mem
= &SET_SRC (pattern
);
1168 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1169 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1170 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1172 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1173 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1175 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1183 rtx addr
= XEXP (*p_mem
, 0);
1185 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1186 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1188 else if (GET_CODE (addr
) == PLUS
1189 && GET_CODE (XEXP (addr
, 0)) == REG
1190 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1191 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1192 && ((INTVAL (XEXP (addr
, 1)))
1193 < ep_memory_offset (GET_MODE (*p_mem
),
1195 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1196 *p_mem
= change_address (*p_mem
, VOIDmode
,
1197 gen_rtx_PLUS (Pmode
,
1205 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1206 insn
= prev_nonnote_insn (first_insn
);
1207 if (insn
&& NONJUMP_INSN_P (insn
)
1208 && GET_CODE (PATTERN (insn
)) == SET
1209 && SET_DEST (PATTERN (insn
)) == *p_ep
1210 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1213 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1215 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1216 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1220 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1221 the -mep mode to copy heavily used pointers to ep to use the implicit
1233 regs
[FIRST_PSEUDO_REGISTER
];
1242 /* If not ep mode, just return now. */
1246 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1249 regs
[i
].first_insn
= NULL_RTX
;
1250 regs
[i
].last_insn
= NULL_RTX
;
1253 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1255 switch (GET_CODE (insn
))
1257 /* End of basic block */
1264 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1266 if (max_uses
< regs
[i
].uses
)
1268 max_uses
= regs
[i
].uses
;
1274 substitute_ep_register (regs
[max_regno
].first_insn
,
1275 regs
[max_regno
].last_insn
,
1276 max_uses
, max_regno
, &r1
, &ep
);
1280 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1283 regs
[i
].first_insn
= NULL_RTX
;
1284 regs
[i
].last_insn
= NULL_RTX
;
1292 pattern
= single_set (insn
);
1294 /* See if there are any memory references we can shorten. */
1297 rtx src
= SET_SRC (pattern
);
1298 rtx dest
= SET_DEST (pattern
);
1300 /* Memory operands are signed by default. */
1301 int unsignedp
= FALSE
;
1303 /* We might have (SUBREG (MEM)) here, so just get rid of the
1304 subregs to make this code simpler. */
1305 if (GET_CODE (dest
) == SUBREG
1306 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1307 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1308 alter_subreg (&dest
, false);
1309 if (GET_CODE (src
) == SUBREG
1310 && (GET_CODE (SUBREG_REG (src
)) == MEM
1311 || GET_CODE (SUBREG_REG (src
)) == REG
))
1312 alter_subreg (&src
, false);
1314 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1317 else if (GET_CODE (dest
) == MEM
)
1320 else if (GET_CODE (src
) == MEM
)
1323 else if (GET_CODE (src
) == SIGN_EXTEND
1324 && GET_CODE (XEXP (src
, 0)) == MEM
)
1325 mem
= XEXP (src
, 0);
1327 else if (GET_CODE (src
) == ZERO_EXTEND
1328 && GET_CODE (XEXP (src
, 0)) == MEM
)
1330 mem
= XEXP (src
, 0);
1336 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1339 else if (!use_ep
&& mem
1340 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1342 rtx addr
= XEXP (mem
, 0);
1346 if (GET_CODE (addr
) == REG
)
1349 regno
= REGNO (addr
);
1352 else if (GET_CODE (addr
) == PLUS
1353 && GET_CODE (XEXP (addr
, 0)) == REG
1354 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1355 && ((INTVAL (XEXP (addr
, 1)))
1356 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1357 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1360 regno
= REGNO (XEXP (addr
, 0));
1369 regs
[regno
].last_insn
= insn
;
1370 if (!regs
[regno
].first_insn
)
1371 regs
[regno
].first_insn
= insn
;
1375 /* Loading up a register in the basic block zaps any savings
1377 if (GET_CODE (dest
) == REG
)
1379 enum machine_mode mode
= GET_MODE (dest
);
1383 regno
= REGNO (dest
);
1384 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1388 /* See if we can use the pointer before this
1393 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1395 if (max_uses
< regs
[i
].uses
)
1397 max_uses
= regs
[i
].uses
;
1403 && max_regno
>= regno
1404 && max_regno
< endregno
)
1406 substitute_ep_register (regs
[max_regno
].first_insn
,
1407 regs
[max_regno
].last_insn
,
1408 max_uses
, max_regno
, &r1
,
1411 /* Since we made a substitution, zap all remembered
1413 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1416 regs
[i
].first_insn
= NULL_RTX
;
1417 regs
[i
].last_insn
= NULL_RTX
;
1422 for (i
= regno
; i
< endregno
; i
++)
1425 regs
[i
].first_insn
= NULL_RTX
;
1426 regs
[i
].last_insn
= NULL_RTX
;
1434 /* # of registers saved by the interrupt handler. */
1435 #define INTERRUPT_FIXED_NUM 5
1437 /* # of bytes for registers saved by the interrupt handler. */
1438 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1440 /* # of words saved for other registers. */
1441 #define INTERRUPT_ALL_SAVE_NUM \
1442 (30 - INTERRUPT_FIXED_NUM)
1444 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1447 compute_register_save_size (long * p_reg_saved
)
1451 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1452 int call_p
= df_regs_ever_live_p (LINK_POINTER_REGNUM
);
1455 /* Count space for the register saves. */
1456 if (interrupt_handler
)
1458 for (i
= 0; i
<= 31; i
++)
1462 if (df_regs_ever_live_p (i
) || call_p
)
1465 reg_saved
|= 1L << i
;
1469 /* We don't save/restore r0 or the stack pointer */
1471 case STACK_POINTER_REGNUM
:
1474 /* For registers with fixed use, we save them, set them to the
1475 appropriate value, and then restore them.
1476 These registers are handled specially, so don't list them
1477 on the list of registers to save in the prologue. */
1478 case 1: /* temp used to hold ep */
1480 case 10: /* temp used to call interrupt save/restore */
1481 case 11: /* temp used to call interrupt save/restore (long call) */
1482 case EP_REGNUM
: /* ep */
1489 /* Find the first register that needs to be saved. */
1490 for (i
= 0; i
<= 31; i
++)
1491 if (df_regs_ever_live_p (i
) && ((! call_used_regs
[i
])
1492 || i
== LINK_POINTER_REGNUM
))
1495 /* If it is possible that an out-of-line helper function might be
1496 used to generate the prologue for the current function, then we
1497 need to cover the possibility that such a helper function will
1498 be used, despite the fact that there might be gaps in the list of
1499 registers that need to be saved. To detect this we note that the
1500 helper functions always push at least register r29 (provided
1501 that the function is not an interrupt handler). */
1503 if (TARGET_PROLOG_FUNCTION
1504 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1509 reg_saved
|= 1L << i
;
1514 /* Helper functions save all registers between the starting
1515 register and the last register, regardless of whether they
1516 are actually used by the function or not. */
1517 for (; i
<= 29; i
++)
1520 reg_saved
|= 1L << i
;
1523 if (df_regs_ever_live_p (LINK_POINTER_REGNUM
))
1526 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1531 for (; i
<= 31; i
++)
1532 if (df_regs_ever_live_p (i
) && ((! call_used_regs
[i
])
1533 || i
== LINK_POINTER_REGNUM
))
1536 reg_saved
|= 1L << i
;
1542 *p_reg_saved
= reg_saved
;
1547 /* Typical stack layout should looks like this after the function's prologue:
1552 | | arguments saved | Increasing
1553 | | on the stack | addresses
1554 PARENT arg pointer -> | | /
1555 -------------------------- ---- -------------------
1556 | | - space for argument split between regs & stack
1558 CHILD | | \ <-- (return address here)
1563 frame pointer -> | | \ ___
1570 | | arguments | | Decreasing
1571 (hard) frame pointer | | / | | addresses
1572 and stack pointer -> | | / _|_ |
1573 -------------------------- ---- ------------------ V */
1576 compute_frame_size (int size
, long * p_reg_saved
)
1579 + compute_register_save_size (p_reg_saved
)
1580 + crtl
->outgoing_args_size
);
1584 use_prolog_function (int num_save
, int frame_size
)
1586 int alloc_stack
= (4 * num_save
);
1587 int unalloc_stack
= frame_size
- alloc_stack
;
1588 int save_func_len
, restore_func_len
;
1589 int save_normal_len
, restore_normal_len
;
1591 if (! TARGET_DISABLE_CALLT
)
1592 save_func_len
= restore_func_len
= 2;
1594 save_func_len
= restore_func_len
= TARGET_LONG_CALLS
? (4+4+4+2+2) : 4;
1598 save_func_len
+= CONST_OK_FOR_J (-unalloc_stack
) ? 2 : 4;
1599 restore_func_len
+= CONST_OK_FOR_J (-unalloc_stack
) ? 2 : 4;
1602 /* See if we would have used ep to save the stack. */
1603 if (TARGET_EP
&& num_save
> 3 && (unsigned)frame_size
< 255)
1604 save_normal_len
= restore_normal_len
= (3 * 2) + (2 * num_save
);
1606 save_normal_len
= restore_normal_len
= 4 * num_save
;
1608 save_normal_len
+= CONST_OK_FOR_J (-frame_size
) ? 2 : 4;
1609 restore_normal_len
+= (CONST_OK_FOR_J (frame_size
) ? 2 : 4) + 2;
1611 /* Don't bother checking if we don't actually save any space.
1612 This happens for instance if one register is saved and additional
1613 stack space is allocated. */
1614 return ((save_func_len
+ restore_func_len
) < (save_normal_len
+ restore_normal_len
));
1618 increment_stack (signed int amount
, bool in_prologue
)
1625 inc
= GEN_INT (amount
);
1627 if (! CONST_OK_FOR_K (amount
))
1629 rtx reg
= gen_rtx_REG (Pmode
, 12);
1631 inc
= emit_move_insn (reg
, inc
);
1637 inc
= emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, inc
));
1643 expand_prologue (void)
1646 unsigned int size
= get_frame_size ();
1647 unsigned int actual_fsize
;
1648 unsigned int init_stack_alloc
= 0;
1651 unsigned int num_save
;
1653 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1656 actual_fsize
= compute_frame_size (size
, ®_saved
);
1658 if (flag_stack_usage_info
)
1659 current_function_static_stack_size
= actual_fsize
;
1661 /* Save/setup global registers for interrupt functions right now. */
1662 if (interrupt_handler
)
1664 if (! TARGET_DISABLE_CALLT
&& (TARGET_V850E_UP
))
1665 emit_insn (gen_callt_save_interrupt ());
1667 emit_insn (gen_save_interrupt ());
1669 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1671 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1672 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1674 /* Interrupt functions are not passed arguments, so no need to
1675 allocate space for split structure arguments. */
1676 gcc_assert (crtl
->args
.pretend_args_size
== 0);
1679 /* Identify all of the saved registers. */
1681 for (i
= 1; i
< 32; i
++)
1683 if (((1L << i
) & reg_saved
) != 0)
1684 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1687 if (crtl
->args
.pretend_args_size
)
1691 increment_stack (- (actual_fsize
+ crtl
->args
.pretend_args_size
), true);
1695 increment_stack (- crtl
->args
.pretend_args_size
, true);
1698 /* See if we have an insn that allocates stack space and saves the particular
1699 registers we want to. Note that the helpers won't
1700 allocate additional space for registers GCC saves to complete a
1701 "split" structure argument. */
1702 save_all
= NULL_RTX
;
1703 if (TARGET_PROLOG_FUNCTION
1704 && !crtl
->args
.pretend_args_size
1707 if (use_prolog_function (num_save
, actual_fsize
))
1709 int alloc_stack
= 4 * num_save
;
1712 save_all
= gen_rtx_PARALLEL
1714 rtvec_alloc (num_save
+ 1
1715 + (TARGET_DISABLE_CALLT
? (TARGET_LONG_CALLS
? 2 : 1) : 0)));
1717 XVECEXP (save_all
, 0, 0)
1718 = gen_rtx_SET (VOIDmode
,
1720 gen_rtx_PLUS (Pmode
,
1722 GEN_INT(-alloc_stack
)));
1723 for (i
= 0; i
< num_save
; i
++)
1726 XVECEXP (save_all
, 0, i
+1)
1727 = gen_rtx_SET (VOIDmode
,
1729 gen_rtx_PLUS (Pmode
,
1735 if (TARGET_DISABLE_CALLT
)
1737 XVECEXP (save_all
, 0, num_save
+ 1)
1738 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1740 if (TARGET_LONG_CALLS
)
1741 XVECEXP (save_all
, 0, num_save
+ 2)
1742 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 11));
1745 v850_all_frame_related (save_all
);
1747 code
= recog (save_all
, NULL_RTX
, NULL
);
1750 rtx insn
= emit_insn (save_all
);
1751 INSN_CODE (insn
) = code
;
1752 actual_fsize
-= alloc_stack
;
1756 save_all
= NULL_RTX
;
1760 /* If no prolog save function is available, store the registers the old
1761 fashioned way (one by one). */
1764 /* Special case interrupt functions that save all registers for a call. */
1765 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1767 if (! TARGET_DISABLE_CALLT
&& (TARGET_V850E_UP
))
1768 emit_insn (gen_callt_save_all_interrupt ());
1770 emit_insn (gen_save_all_interrupt ());
1775 /* If the stack is too big, allocate it in chunks so we can do the
1776 register saves. We use the register save size so we use the ep
1778 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1779 init_stack_alloc
= compute_register_save_size (NULL
);
1781 init_stack_alloc
= actual_fsize
;
1783 /* Save registers at the beginning of the stack frame. */
1784 offset
= init_stack_alloc
- 4;
1786 if (init_stack_alloc
)
1787 increment_stack (- (signed) init_stack_alloc
, true);
1789 /* Save the return pointer first. */
1790 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1792 F (emit_move_insn (gen_rtx_MEM (SImode
,
1793 plus_constant (Pmode
,
1796 save_regs
[--num_save
]));
1800 for (i
= 0; i
< num_save
; i
++)
1802 F (emit_move_insn (gen_rtx_MEM (SImode
,
1803 plus_constant (Pmode
,
1812 /* Allocate the rest of the stack that was not allocated above (either it is
1813 > 32K or we just called a function to save the registers and needed more
1815 if (actual_fsize
> init_stack_alloc
)
1816 increment_stack (init_stack_alloc
- actual_fsize
, true);
1818 /* If we need a frame pointer, set it up now. */
1819 if (frame_pointer_needed
)
1820 F (emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
));
1825 expand_epilogue (void)
1828 unsigned int size
= get_frame_size ();
1830 int actual_fsize
= compute_frame_size (size
, ®_saved
);
1831 rtx restore_regs
[32];
1833 unsigned int num_restore
;
1835 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1837 /* Eliminate the initial stack stored by interrupt functions. */
1838 if (interrupt_handler
)
1840 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1841 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1842 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1845 /* Cut off any dynamic stack created. */
1846 if (frame_pointer_needed
)
1847 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1849 /* Identify all of the saved registers. */
1851 for (i
= 1; i
< 32; i
++)
1853 if (((1L << i
) & reg_saved
) != 0)
1854 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1857 /* See if we have an insn that restores the particular registers we
1859 restore_all
= NULL_RTX
;
1861 if (TARGET_PROLOG_FUNCTION
1863 && !crtl
->args
.pretend_args_size
1864 && !interrupt_handler
)
1866 int alloc_stack
= (4 * num_restore
);
1868 /* Don't bother checking if we don't actually save any space. */
1869 if (use_prolog_function (num_restore
, actual_fsize
))
1872 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1873 rtvec_alloc (num_restore
+ 2));
1874 XVECEXP (restore_all
, 0, 0) = ret_rtx
;
1875 XVECEXP (restore_all
, 0, 1)
1876 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1877 gen_rtx_PLUS (Pmode
,
1879 GEN_INT (alloc_stack
)));
1881 offset
= alloc_stack
- 4;
1882 for (i
= 0; i
< num_restore
; i
++)
1884 XVECEXP (restore_all
, 0, i
+2)
1885 = gen_rtx_SET (VOIDmode
,
1888 gen_rtx_PLUS (Pmode
,
1894 code
= recog (restore_all
, NULL_RTX
, NULL
);
1900 actual_fsize
-= alloc_stack
;
1901 increment_stack (actual_fsize
, false);
1903 insn
= emit_jump_insn (restore_all
);
1904 INSN_CODE (insn
) = code
;
1907 restore_all
= NULL_RTX
;
1911 /* If no epilogue save function is available, restore the registers the
1912 old fashioned way (one by one). */
1915 unsigned int init_stack_free
;
1917 /* If the stack is large, we need to cut it down in 2 pieces. */
1918 if (interrupt_handler
)
1919 init_stack_free
= 0;
1920 else if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1921 init_stack_free
= 4 * num_restore
;
1923 init_stack_free
= (signed) actual_fsize
;
1925 /* Deallocate the rest of the stack if it is > 32K. */
1926 if ((unsigned int) actual_fsize
> init_stack_free
)
1927 increment_stack (actual_fsize
- init_stack_free
, false);
1929 /* Special case interrupt functions that save all registers
1931 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1933 if (! TARGET_DISABLE_CALLT
)
1934 emit_insn (gen_callt_restore_all_interrupt ());
1936 emit_insn (gen_restore_all_interrupt ());
1940 /* Restore registers from the beginning of the stack frame. */
1941 int offset
= init_stack_free
- 4;
1943 /* Restore the return pointer first. */
1945 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
1947 emit_move_insn (restore_regs
[--num_restore
],
1948 gen_rtx_MEM (SImode
,
1949 plus_constant (Pmode
,
1955 for (i
= 0; i
< num_restore
; i
++)
1957 emit_move_insn (restore_regs
[i
],
1958 gen_rtx_MEM (SImode
,
1959 plus_constant (Pmode
,
1963 emit_use (restore_regs
[i
]);
1967 /* Cut back the remainder of the stack. */
1968 increment_stack (init_stack_free
+ crtl
->args
.pretend_args_size
,
1972 /* And return or use reti for interrupt handlers. */
1973 if (interrupt_handler
)
1975 if (! TARGET_DISABLE_CALLT
&& (TARGET_V850E_UP
))
1976 emit_insn (gen_callt_return_interrupt ());
1978 emit_jump_insn (gen_return_interrupt ());
1980 else if (actual_fsize
)
1981 emit_jump_insn (gen_return_internal ());
1983 emit_jump_insn (gen_return_simple ());
1986 v850_interrupt_cache_p
= FALSE
;
1987 v850_interrupt_p
= FALSE
;
1990 /* Update the condition code from the insn. */
1992 notice_update_cc (rtx body
, rtx insn
)
1994 switch (get_attr_cc (insn
))
1997 /* Insn does not affect CC at all. */
2001 /* Insn does not change CC, but the 0'th operand has been changed. */
2002 if (cc_status
.value1
!= 0
2003 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2004 cc_status
.value1
= 0;
2008 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2009 V,C is in an unusable state. */
2011 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2012 cc_status
.value1
= recog_data
.operand
[0];
2016 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2017 C is in an unusable state. */
2019 cc_status
.flags
|= CC_NO_CARRY
;
2020 cc_status
.value1
= recog_data
.operand
[0];
2024 /* The insn is a compare instruction. */
2026 cc_status
.value1
= SET_SRC (body
);
2030 /* Insn doesn't leave CC in a usable state. */
2039 /* Retrieve the data area that has been chosen for the given decl. */
2042 v850_get_data_area (tree decl
)
2044 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2045 return DATA_AREA_SDA
;
2047 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2048 return DATA_AREA_TDA
;
2050 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2051 return DATA_AREA_ZDA
;
2053 return DATA_AREA_NORMAL
;
2056 /* Store the indicated data area in the decl's attributes. */
2059 v850_set_data_area (tree decl
, v850_data_area data_area
)
2065 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2066 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2067 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2072 DECL_ATTRIBUTES (decl
) = tree_cons
2073 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2076 /* Handle an "interrupt" attribute; arguments as in
2077 struct attribute_spec.handler. */
2079 v850_handle_interrupt_attribute (tree
* node
,
2081 tree args ATTRIBUTE_UNUSED
,
2082 int flags ATTRIBUTE_UNUSED
,
2083 bool * no_add_attrs
)
2085 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2087 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
2089 *no_add_attrs
= true;
2095 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2096 struct attribute_spec.handler. */
2098 v850_handle_data_area_attribute (tree
* node
,
2100 tree args ATTRIBUTE_UNUSED
,
2101 int flags ATTRIBUTE_UNUSED
,
2102 bool * no_add_attrs
)
2104 v850_data_area data_area
;
2105 v850_data_area area
;
2108 /* Implement data area attribute. */
2109 if (is_attribute_p ("sda", name
))
2110 data_area
= DATA_AREA_SDA
;
2111 else if (is_attribute_p ("tda", name
))
2112 data_area
= DATA_AREA_TDA
;
2113 else if (is_attribute_p ("zda", name
))
2114 data_area
= DATA_AREA_ZDA
;
2118 switch (TREE_CODE (decl
))
2121 if (current_function_decl
!= NULL_TREE
)
2123 error_at (DECL_SOURCE_LOCATION (decl
),
2124 "data area attributes cannot be specified for "
2126 *no_add_attrs
= true;
2132 area
= v850_get_data_area (decl
);
2133 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2135 error ("data area of %q+D conflicts with previous declaration",
2137 *no_add_attrs
= true;
2149 /* Return nonzero if FUNC is an interrupt function as specified
2150 by the "interrupt" attribute. */
2153 v850_interrupt_function_p (tree func
)
2158 if (v850_interrupt_cache_p
)
2159 return v850_interrupt_p
;
2161 if (TREE_CODE (func
) != FUNCTION_DECL
)
2164 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2170 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2171 ret
= a
!= NULL_TREE
;
2174 /* Its not safe to trust global variables until after function inlining has
2176 if (reload_completed
| reload_in_progress
)
2177 v850_interrupt_p
= ret
;
2184 v850_encode_data_area (tree decl
, rtx symbol
)
2188 /* Map explicit sections into the appropriate attribute */
2189 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2191 if (DECL_SECTION_NAME (decl
))
2193 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2195 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2196 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2198 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2199 v850_set_data_area (decl
, DATA_AREA_SDA
);
2201 else if (streq (name
, ".tdata"))
2202 v850_set_data_area (decl
, DATA_AREA_TDA
);
2205 /* If no attribute, support -m{zda,sda,tda}=n */
2208 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2212 else if (size
<= small_memory_max
[(int) SMALL_MEMORY_TDA
])
2213 v850_set_data_area (decl
, DATA_AREA_TDA
);
2215 else if (size
<= small_memory_max
[(int) SMALL_MEMORY_SDA
])
2216 v850_set_data_area (decl
, DATA_AREA_SDA
);
2218 else if (size
<= small_memory_max
[(int) SMALL_MEMORY_ZDA
])
2219 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2222 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2226 flags
= SYMBOL_REF_FLAGS (symbol
);
2227 switch (v850_get_data_area (decl
))
2229 case DATA_AREA_ZDA
: flags
|= SYMBOL_FLAG_ZDA
; break;
2230 case DATA_AREA_TDA
: flags
|= SYMBOL_FLAG_TDA
; break;
2231 case DATA_AREA_SDA
: flags
|= SYMBOL_FLAG_SDA
; break;
2232 default: gcc_unreachable ();
2234 SYMBOL_REF_FLAGS (symbol
) = flags
;
2238 v850_encode_section_info (tree decl
, rtx rtl
, int first
)
2240 default_encode_section_info (decl
, rtl
, first
);
2242 if (TREE_CODE (decl
) == VAR_DECL
2243 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2244 v850_encode_data_area (decl
, XEXP (rtl
, 0));
2247 /* Construct a JR instruction to a routine that will perform the equivalent of
2248 the RTL passed in as an argument. This RTL is a function epilogue that
2249 pops registers off the stack and possibly releases some extra stack space
2250 as well. The code has already verified that the RTL matches these
2254 construct_restore_jr (rtx op
)
2256 int count
= XVECLEN (op
, 0);
2258 unsigned long int mask
;
2259 unsigned long int first
;
2260 unsigned long int last
;
2262 static char buff
[100]; /* XXX */
2266 error ("bogus JR construction: %d", count
);
2270 /* Work out how many bytes to pop off the stack before retrieving
2272 gcc_assert (GET_CODE (XVECEXP (op
, 0, 1)) == SET
);
2273 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) == PLUS
);
2274 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) == CONST_INT
);
2276 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2278 /* Each pop will remove 4 bytes from the stack.... */
2279 stack_bytes
-= (count
- 2) * 4;
2281 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2282 if (stack_bytes
!= 0)
2284 error ("bad amount of stack space removal: %d", stack_bytes
);
2288 /* Now compute the bit mask of registers to push. */
2290 for (i
= 2; i
< count
; i
++)
2292 rtx vector_element
= XVECEXP (op
, 0, i
);
2294 gcc_assert (GET_CODE (vector_element
) == SET
);
2295 gcc_assert (GET_CODE (SET_DEST (vector_element
)) == REG
);
2296 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element
),
2299 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2302 /* Scan for the first register to pop. */
2303 for (first
= 0; first
< 32; first
++)
2305 if (mask
& (1 << first
))
2309 gcc_assert (first
< 32);
2311 /* Discover the last register to pop. */
2312 if (mask
& (1 << LINK_POINTER_REGNUM
))
2314 last
= LINK_POINTER_REGNUM
;
2318 gcc_assert (!stack_bytes
);
2319 gcc_assert (mask
& (1 << 29));
2324 /* Note, it is possible to have gaps in the register mask.
2325 We ignore this here, and generate a JR anyway. We will
2326 be popping more registers than is strictly necessary, but
2327 it does save code space. */
2329 if (TARGET_LONG_CALLS
)
2334 sprintf (name
, "__return_%s", reg_names
[first
]);
2336 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2338 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2344 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2346 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2353 /* Construct a JARL instruction to a routine that will perform the equivalent
2354 of the RTL passed as a parameter. This RTL is a function prologue that
2355 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2356 some stack space as well. The code has already verified that the RTL
2357 matches these requirements. */
2359 construct_save_jarl (rtx op
)
2361 int count
= XVECLEN (op
, 0);
2363 unsigned long int mask
;
2364 unsigned long int first
;
2365 unsigned long int last
;
2367 static char buff
[100]; /* XXX */
2369 if (count
<= (TARGET_LONG_CALLS
? 3 : 2))
2371 error ("bogus JARL construction: %d", count
);
2376 gcc_assert (GET_CODE (XVECEXP (op
, 0, 0)) == SET
);
2377 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) == PLUS
);
2378 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) == REG
);
2379 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) == CONST_INT
);
2381 /* Work out how many bytes to push onto the stack after storing the
2383 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2385 /* Each push will put 4 bytes from the stack.... */
2386 stack_bytes
+= (count
- (TARGET_LONG_CALLS
? 3 : 2)) * 4;
2388 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2389 if (stack_bytes
!= 0)
2391 error ("bad amount of stack space removal: %d", stack_bytes
);
2395 /* Now compute the bit mask of registers to push. */
2397 for (i
= 1; i
< count
- (TARGET_LONG_CALLS
? 2 : 1); i
++)
2399 rtx vector_element
= XVECEXP (op
, 0, i
);
2401 gcc_assert (GET_CODE (vector_element
) == SET
);
2402 gcc_assert (GET_CODE (SET_SRC (vector_element
)) == REG
);
2403 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element
),
2406 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2409 /* Scan for the first register to push. */
2410 for (first
= 0; first
< 32; first
++)
2412 if (mask
& (1 << first
))
2416 gcc_assert (first
< 32);
2418 /* Discover the last register to push. */
2419 if (mask
& (1 << LINK_POINTER_REGNUM
))
2421 last
= LINK_POINTER_REGNUM
;
2425 gcc_assert (!stack_bytes
);
2426 gcc_assert (mask
& (1 << 29));
2431 /* Note, it is possible to have gaps in the register mask.
2432 We ignore this here, and generate a JARL anyway. We will
2433 be pushing more registers than is strictly necessary, but
2434 it does save code space. */
2436 if (TARGET_LONG_CALLS
)
2441 sprintf (name
, "__save_%s", reg_names
[first
]);
2443 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2445 if (TARGET_V850E3V5_UP
)
2446 sprintf (buff
, "mov hilo(%s), r11\n\tjarl [r11], r10", name
);
2448 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2454 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2456 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2463 /* A version of asm_output_aligned_bss() that copes with the special
2464 data areas of the v850. */
2466 v850_output_aligned_bss (FILE * file
,
2469 unsigned HOST_WIDE_INT size
,
2472 switch (v850_get_data_area (decl
))
2475 switch_to_section (zbss_section
);
2479 switch_to_section (sbss_section
);
2483 switch_to_section (tdata_section
);
2486 switch_to_section (bss_section
);
2490 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2491 #ifdef ASM_DECLARE_OBJECT_NAME
2492 last_assemble_variable_decl
= decl
;
2493 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2495 /* Standard thing is just output label for the object. */
2496 ASM_OUTPUT_LABEL (file
, name
);
2497 #endif /* ASM_DECLARE_OBJECT_NAME */
2498 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2501 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2503 v850_output_common (FILE * file
,
2509 if (decl
== NULL_TREE
)
2511 fprintf (file
, "%s", COMMON_ASM_OP
);
2515 switch (v850_get_data_area (decl
))
2518 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2522 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2526 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2530 fprintf (file
, "%s", COMMON_ASM_OP
);
2535 assemble_name (file
, name
);
2536 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2539 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2541 v850_output_local (FILE * file
,
2547 fprintf (file
, "%s", LOCAL_ASM_OP
);
2548 assemble_name (file
, name
);
2549 fprintf (file
, "\n");
2551 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2554 /* Add data area to the given declaration if a ghs data area pragma is
2555 currently in effect (#pragma ghs startXXX/endXXX). */
2557 v850_insert_attributes (tree decl
, tree
* attr_ptr ATTRIBUTE_UNUSED
)
2560 && data_area_stack
->data_area
2561 && current_function_decl
== NULL_TREE
2562 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2563 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2564 v850_set_data_area (decl
, data_area_stack
->data_area
);
2566 /* Initialize the default names of the v850 specific sections,
2567 if this has not been done before. */
2569 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2571 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2572 = build_string (sizeof (".sdata")-1, ".sdata");
2574 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2575 = build_string (sizeof (".rosdata")-1, ".rosdata");
2577 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2578 = build_string (sizeof (".tdata")-1, ".tdata");
2580 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2581 = build_string (sizeof (".zdata")-1, ".zdata");
2583 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2584 = build_string (sizeof (".rozdata")-1, ".rozdata");
2587 if (current_function_decl
== NULL_TREE
2588 && (TREE_CODE (decl
) == VAR_DECL
2589 || TREE_CODE (decl
) == CONST_DECL
2590 || TREE_CODE (decl
) == FUNCTION_DECL
)
2591 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2592 && !DECL_SECTION_NAME (decl
))
2594 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2595 tree chosen_section
;
2597 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2598 kind
= GHS_SECTION_KIND_TEXT
;
2601 /* First choose a section kind based on the data area of the decl. */
2602 switch (v850_get_data_area (decl
))
2608 kind
= ((TREE_READONLY (decl
))
2609 ? GHS_SECTION_KIND_ROSDATA
2610 : GHS_SECTION_KIND_SDATA
);
2614 kind
= GHS_SECTION_KIND_TDATA
;
2618 kind
= ((TREE_READONLY (decl
))
2619 ? GHS_SECTION_KIND_ROZDATA
2620 : GHS_SECTION_KIND_ZDATA
);
2623 case DATA_AREA_NORMAL
: /* default data area */
2624 if (TREE_READONLY (decl
))
2625 kind
= GHS_SECTION_KIND_RODATA
;
2626 else if (DECL_INITIAL (decl
))
2627 kind
= GHS_SECTION_KIND_DATA
;
2629 kind
= GHS_SECTION_KIND_BSS
;
2633 /* Now, if the section kind has been explicitly renamed,
2634 then attach a section attribute. */
2635 chosen_section
= GHS_current_section_names
[(int) kind
];
2637 /* Otherwise, if this kind of section needs an explicit section
2638 attribute, then also attach one. */
2639 if (chosen_section
== NULL
)
2640 chosen_section
= GHS_default_section_names
[(int) kind
];
2644 /* Only set the section name if specified by a pragma, because
2645 otherwise it will force those variables to get allocated storage
2646 in this module, rather than by the linker. */
2647 DECL_SECTION_NAME (decl
) = chosen_section
;
2652 /* Construct a DISPOSE instruction that is the equivalent of
2653 the given RTX. We have already verified that this should
2657 construct_dispose_instruction (rtx op
)
2659 int count
= XVECLEN (op
, 0);
2661 unsigned long int mask
;
2663 static char buff
[ 100 ]; /* XXX */
2668 error ("bogus DISPOSE construction: %d", count
);
2672 /* Work out how many bytes to pop off the
2673 stack before retrieving registers. */
2674 gcc_assert (GET_CODE (XVECEXP (op
, 0, 1)) == SET
);
2675 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) == PLUS
);
2676 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) == CONST_INT
);
2678 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2680 /* Each pop will remove 4 bytes from the stack.... */
2681 stack_bytes
-= (count
- 2) * 4;
2683 /* Make sure that the amount we are popping
2684 will fit into the DISPOSE instruction. */
2685 if (stack_bytes
> 128)
2687 error ("too much stack space to dispose of: %d", stack_bytes
);
2691 /* Now compute the bit mask of registers to push. */
2694 for (i
= 2; i
< count
; i
++)
2696 rtx vector_element
= XVECEXP (op
, 0, i
);
2698 gcc_assert (GET_CODE (vector_element
) == SET
);
2699 gcc_assert (GET_CODE (SET_DEST (vector_element
)) == REG
);
2700 gcc_assert (register_is_ok_for_epilogue (SET_DEST (vector_element
),
2703 if (REGNO (SET_DEST (vector_element
)) == 2)
2706 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2709 if (! TARGET_DISABLE_CALLT
2710 && (use_callt
|| stack_bytes
== 0))
2714 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
2719 for (i
= 20; i
< 32; i
++)
2720 if (mask
& (1 << i
))
2724 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
2726 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%s)",
2727 i
, (mask
& (1 << 31)) ? "31c" : "29");
2732 static char regs
[100]; /* XXX */
2735 /* Generate the DISPOSE instruction. Note we could just issue the
2736 bit mask as a number as the assembler can cope with this, but for
2737 the sake of our readers we turn it into a textual description. */
2741 for (i
= 20; i
< 32; i
++)
2743 if (mask
& (1 << i
))
2748 strcat (regs
, ", ");
2753 strcat (regs
, reg_names
[ first
]);
2755 for (i
++; i
< 32; i
++)
2756 if ((mask
& (1 << i
)) == 0)
2761 strcat (regs
, " - ");
2762 strcat (regs
, reg_names
[ i
- 1 ] );
2767 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
2773 /* Construct a PREPARE instruction that is the equivalent of
2774 the given RTL. We have already verified that this should
2778 construct_prepare_instruction (rtx op
)
2782 unsigned long int mask
;
2784 static char buff
[ 100 ]; /* XXX */
2787 if (XVECLEN (op
, 0) <= 1)
2789 error ("bogus PREPEARE construction: %d", XVECLEN (op
, 0));
2793 /* Work out how many bytes to push onto
2794 the stack after storing the registers. */
2795 gcc_assert (GET_CODE (XVECEXP (op
, 0, 0)) == SET
);
2796 gcc_assert (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) == PLUS
);
2797 gcc_assert (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) == CONST_INT
);
2799 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2802 /* Make sure that the amount we are popping
2803 will fit into the DISPOSE instruction. */
2804 if (stack_bytes
< -128)
2806 error ("too much stack space to prepare: %d", stack_bytes
);
2810 /* Now compute the bit mask of registers to push. */
2813 for (i
= 1; i
< XVECLEN (op
, 0); i
++)
2815 rtx vector_element
= XVECEXP (op
, 0, i
);
2817 if (GET_CODE (vector_element
) == CLOBBER
)
2820 gcc_assert (GET_CODE (vector_element
) == SET
);
2821 gcc_assert (GET_CODE (SET_SRC (vector_element
)) == REG
);
2822 gcc_assert (register_is_ok_for_epilogue (SET_SRC (vector_element
),
2825 if (REGNO (SET_SRC (vector_element
)) == 2)
2828 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2832 stack_bytes
+= count
* 4;
2834 if ((! TARGET_DISABLE_CALLT
)
2835 && (use_callt
|| stack_bytes
== 0))
2839 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
2843 for (i
= 20; i
< 32; i
++)
2844 if (mask
& (1 << i
))
2848 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
2850 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%s)",
2851 i
, (mask
& (1 << 31)) ? "31c" : "29");
2855 static char regs
[100]; /* XXX */
2859 /* Generate the PREPARE instruction. Note we could just issue the
2860 bit mask as a number as the assembler can cope with this, but for
2861 the sake of our readers we turn it into a textual description. */
2865 for (i
= 20; i
< 32; i
++)
2867 if (mask
& (1 << i
))
2872 strcat (regs
, ", ");
2877 strcat (regs
, reg_names
[ first
]);
2879 for (i
++; i
< 32; i
++)
2880 if ((mask
& (1 << i
)) == 0)
2885 strcat (regs
, " - ");
2886 strcat (regs
, reg_names
[ i
- 1 ] );
2891 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
2897 /* Return an RTX indicating where the return address to the
2898 calling function can be found. */
2901 v850_return_addr (int count
)
2906 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
2909 /* Implement TARGET_ASM_INIT_SECTIONS. */
2912 v850_asm_init_sections (void)
2915 = get_unnamed_section (0, output_section_asm_op
,
2916 "\t.section .rosdata,\"a\"");
2919 = get_unnamed_section (0, output_section_asm_op
,
2920 "\t.section .rozdata,\"a\"");
2923 = get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
2924 "\t.section .tdata,\"aw\"");
2927 = get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
2928 "\t.section .zdata,\"aw\"");
2931 = get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
2932 output_section_asm_op
,
2933 "\t.section .zbss,\"aw\"");
2937 v850_select_section (tree exp
,
2938 int reloc ATTRIBUTE_UNUSED
,
2939 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
2941 if (TREE_CODE (exp
) == VAR_DECL
)
2944 if (!TREE_READONLY (exp
)
2945 || TREE_SIDE_EFFECTS (exp
)
2946 || !DECL_INITIAL (exp
)
2947 || (DECL_INITIAL (exp
) != error_mark_node
2948 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
2953 switch (v850_get_data_area (exp
))
2956 return is_const
? rozdata_section
: zdata_section
;
2959 return tdata_section
;
2962 return is_const
? rosdata_section
: sdata_section
;
2965 return is_const
? readonly_data_section
: data_section
;
2968 return readonly_data_section
;
2971 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P. */
2974 v850_function_value_regno_p (const unsigned int regno
)
2976 return (regno
== 10);
2979 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2982 v850_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
2984 /* Return values > 8 bytes in length in memory. */
2985 return int_size_in_bytes (type
) > 8
2986 || TYPE_MODE (type
) == BLKmode
2987 /* With the rh850 ABI return all aggregates in memory. */
2988 || ((! TARGET_GCC_ABI
) && AGGREGATE_TYPE_P (type
))
2992 /* Worker function for TARGET_FUNCTION_VALUE. */
2995 v850_function_value (const_tree valtype
,
2996 const_tree fn_decl_or_type ATTRIBUTE_UNUSED
,
2997 bool outgoing ATTRIBUTE_UNUSED
)
2999 return gen_rtx_REG (TYPE_MODE (valtype
), 10);
3003 /* Worker function for TARGET_CAN_ELIMINATE. */
3006 v850_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
3008 return (to
== STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
3011 /* Worker function for TARGET_CONDITIONAL_REGISTER_USAGE.
3013 If TARGET_APP_REGS is not defined then add r2 and r5 to
3014 the pool of fixed registers. See PR 14505. */
3017 v850_conditional_register_usage (void)
3019 if (TARGET_APP_REGS
)
3021 fixed_regs
[2] = 0; call_used_regs
[2] = 0;
3022 fixed_regs
[5] = 0; call_used_regs
[5] = 1;
3026 /* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE. */
3029 v850_asm_trampoline_template (FILE *f
)
3031 fprintf (f
, "\tjarl .+4,r12\n");
3032 fprintf (f
, "\tld.w 12[r12],r20\n");
3033 fprintf (f
, "\tld.w 16[r12],r12\n");
3034 fprintf (f
, "\tjmp [r12]\n");
3035 fprintf (f
, "\tnop\n");
3036 fprintf (f
, "\t.long 0\n");
3037 fprintf (f
, "\t.long 0\n");
3040 /* Worker function for TARGET_TRAMPOLINE_INIT. */
3043 v850_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
3045 rtx mem
, fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
3047 emit_block_move (m_tramp
, assemble_trampoline_template (),
3048 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
3050 mem
= adjust_address (m_tramp
, SImode
, 16);
3051 emit_move_insn (mem
, chain_value
);
3052 mem
= adjust_address (m_tramp
, SImode
, 20);
3053 emit_move_insn (mem
, fnaddr
);
3057 v850_issue_rate (void)
3059 return (TARGET_V850E2_UP
? 2 : 1);
3062 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
3065 v850_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
3067 return (GET_CODE (x
) == CONST_DOUBLE
3068 || !(GET_CODE (x
) == CONST
3069 && GET_CODE (XEXP (x
, 0)) == PLUS
3070 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
3071 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3072 && !CONST_OK_FOR_K (INTVAL (XEXP (XEXP (x
, 0), 1)))));
3076 v850_memory_move_cost (enum machine_mode mode
,
3077 reg_class_t reg_class ATTRIBUTE_UNUSED
,
3080 switch (GET_MODE_SIZE (mode
))
3090 return (GET_MODE_SIZE (mode
) / 2) * (in
? 3 : 1);
3095 v850_adjust_insn_length (rtx insn
, int length
)
3097 if (TARGET_V850E3V5_UP
)
3101 if (TARGET_LONG_CALLS
)
3103 /* call_internal_long, call_value_internal_long. */
3111 /* call_internal_short, call_value_internal_short. */
3120 /* V850 specific attributes. */
3122 static const struct attribute_spec v850_attribute_table
[] =
3124 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3125 affects_type_identity } */
3126 { "interrupt_handler", 0, 0, true, false, false,
3127 v850_handle_interrupt_attribute
, false },
3128 { "interrupt", 0, 0, true, false, false,
3129 v850_handle_interrupt_attribute
, false },
3130 { "sda", 0, 0, true, false, false,
3131 v850_handle_data_area_attribute
, false },
3132 { "tda", 0, 0, true, false, false,
3133 v850_handle_data_area_attribute
, false },
3134 { "zda", 0, 0, true, false, false,
3135 v850_handle_data_area_attribute
, false },
3136 { NULL
, 0, 0, false, false, false, NULL
, false }
3140 v850_option_override (void)
3142 if (flag_exceptions
|| flag_non_call_exceptions
)
3143 flag_omit_frame_pointer
= 0;
3145 /* The RH850 ABI does not (currently) support the use of the CALLT instruction. */
3146 if (! TARGET_GCC_ABI
)
3147 target_flags
|= MASK_DISABLE_CALLT
;
3151 v850_gen_movdi (rtx
* operands
)
3153 if (REG_P (operands
[0]))
3155 if (REG_P (operands
[1]))
3157 if (REGNO (operands
[0]) == (REGNO (operands
[1]) - 1))
3158 return "mov %1, %0; mov %R1, %R0";
3160 return "mov %R1, %R0; mov %1, %0";
3163 if (MEM_P (operands
[1]))
3165 if (REGNO (operands
[0]) & 1)
3166 /* Use two load word instructions to synthesise a load double. */
3167 return "ld.w %1, %0 ; ld.w %R1, %R0" ;
3169 return "ld.dw %1, %0";
3172 return "mov %1, %0; mov %R1, %R0";
3175 gcc_assert (REG_P (operands
[1]));
3177 if (REGNO (operands
[1]) & 1)
3178 /* Use two store word instructions to synthesise a store double. */
3179 return "st.w %1, %0 ; st.w %R1, %R0 ";
3181 return "st.dw %1, %0";
3184 /* Initialize the GCC target structure. */
3186 #undef TARGET_OPTION_OVERRIDE
3187 #define TARGET_OPTION_OVERRIDE v850_option_override
3189 #undef TARGET_MEMORY_MOVE_COST
3190 #define TARGET_MEMORY_MOVE_COST v850_memory_move_cost
3192 #undef TARGET_ASM_ALIGNED_HI_OP
3193 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
3195 #undef TARGET_PRINT_OPERAND
3196 #define TARGET_PRINT_OPERAND v850_print_operand
3197 #undef TARGET_PRINT_OPERAND_ADDRESS
3198 #define TARGET_PRINT_OPERAND_ADDRESS v850_print_operand_address
3199 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
3200 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P v850_print_operand_punct_valid_p
3202 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
3203 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA v850_output_addr_const_extra
3205 #undef TARGET_ATTRIBUTE_TABLE
3206 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
3208 #undef TARGET_INSERT_ATTRIBUTES
3209 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
3211 #undef TARGET_ASM_SELECT_SECTION
3212 #define TARGET_ASM_SELECT_SECTION v850_select_section
3214 /* The assembler supports switchable .bss sections, but
3215 v850_select_section doesn't yet make use of them. */
3216 #undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
3217 #define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS false
3219 #undef TARGET_ENCODE_SECTION_INFO
3220 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
3222 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
3223 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
3225 #undef TARGET_RTX_COSTS
3226 #define TARGET_RTX_COSTS v850_rtx_costs
3228 #undef TARGET_ADDRESS_COST
3229 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
3231 #undef TARGET_MACHINE_DEPENDENT_REORG
3232 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
3234 #undef TARGET_SCHED_ISSUE_RATE
3235 #define TARGET_SCHED_ISSUE_RATE v850_issue_rate
3237 #undef TARGET_FUNCTION_VALUE_REGNO_P
3238 #define TARGET_FUNCTION_VALUE_REGNO_P v850_function_value_regno_p
3239 #undef TARGET_FUNCTION_VALUE
3240 #define TARGET_FUNCTION_VALUE v850_function_value
3242 #undef TARGET_PROMOTE_PROTOTYPES
3243 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
3245 #undef TARGET_RETURN_IN_MEMORY
3246 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
3248 #undef TARGET_PASS_BY_REFERENCE
3249 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
3251 #undef TARGET_CALLEE_COPIES
3252 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
3254 #undef TARGET_ARG_PARTIAL_BYTES
3255 #define TARGET_ARG_PARTIAL_BYTES v850_arg_partial_bytes
3257 #undef TARGET_FUNCTION_ARG
3258 #define TARGET_FUNCTION_ARG v850_function_arg
3260 #undef TARGET_FUNCTION_ARG_ADVANCE
3261 #define TARGET_FUNCTION_ARG_ADVANCE v850_function_arg_advance
3263 #undef TARGET_CAN_ELIMINATE
3264 #define TARGET_CAN_ELIMINATE v850_can_eliminate
3266 #undef TARGET_CONDITIONAL_REGISTER_USAGE
3267 #define TARGET_CONDITIONAL_REGISTER_USAGE v850_conditional_register_usage
3269 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
3270 #define TARGET_ASM_TRAMPOLINE_TEMPLATE v850_asm_trampoline_template
3271 #undef TARGET_TRAMPOLINE_INIT
3272 #define TARGET_TRAMPOLINE_INIT v850_trampoline_init
3274 #undef TARGET_LEGITIMATE_CONSTANT_P
3275 #define TARGET_LEGITIMATE_CONSTANT_P v850_legitimate_constant_p
3277 #undef TARGET_CAN_USE_DOLOOP_P
3278 #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost
3280 struct gcc_target targetm
= TARGET_INITIALIZER
;
3282 #include "gt-v850.h"