1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 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
,
72 static int v850_arg_partial_bytes (CUMULATIVE_ARGS
*, enum machine_mode
,
75 /* Information about the various small memory areas. */
76 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
78 /* name value max physical max */
79 { "tda", (char *)0, 0, 256 },
80 { "sda", (char *)0, 0, 65536 },
81 { "zda", (char *)0, 0, 32768 },
84 /* Names of the various data areas used on the v850. */
85 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
86 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
88 /* Track the current data area set by the data area pragma (which
89 can be nested). Tested by check_default_data_area. */
90 data_area_stack_element
* data_area_stack
= NULL
;
92 /* True if we don't need to check any more if the current
93 function is an interrupt handler. */
94 static int v850_interrupt_cache_p
= FALSE
;
96 /* Whether current function is an interrupt handler. */
97 static int v850_interrupt_p
= FALSE
;
99 /* Initialize the GCC target structure. */
100 #undef TARGET_ASM_ALIGNED_HI_OP
101 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
103 #undef TARGET_ATTRIBUTE_TABLE
104 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
106 #undef TARGET_INSERT_ATTRIBUTES
107 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
109 #undef TARGET_ASM_SELECT_SECTION
110 #define TARGET_ASM_SELECT_SECTION v850_select_section
112 #undef TARGET_ENCODE_SECTION_INFO
113 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
115 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
116 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
118 #undef TARGET_RTX_COSTS
119 #define TARGET_RTX_COSTS v850_rtx_costs
121 #undef TARGET_ADDRESS_COST
122 #define TARGET_ADDRESS_COST hook_int_rtx_0
124 #undef TARGET_MACHINE_DEPENDENT_REORG
125 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
127 #undef TARGET_PROMOTE_PROTOTYPES
128 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
130 #undef TARGET_RETURN_IN_MEMORY
131 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
133 #undef TARGET_PASS_BY_REFERENCE
134 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
136 #undef TARGET_CALLEE_COPIES
137 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
139 #undef TARGET_SETUP_INCOMING_VARARGS
140 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
142 #undef TARGET_ARG_PARTIAL_BYTES
143 #define TARGET_ARG_PARTIAL_BYTES v850_arg_partial_bytes
145 struct gcc_target targetm
= TARGET_INITIALIZER
;
147 /* Sometimes certain combinations of command options do not make
148 sense on a particular target machine. You can define a macro
149 `OVERRIDE_OPTIONS' to take account of this. This macro, if
150 defined, is executed once just after all the command options have
153 Don't use this macro to turn on various extra optimizations for
154 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
157 override_options (void)
160 extern int atoi (const char *);
162 /* Parse -m{s,t,z}da=nnn switches */
163 for (i
= 0; i
< (int)SMALL_MEMORY_max
; i
++)
165 if (small_memory
[i
].value
)
167 if (!ISDIGIT (*small_memory
[i
].value
))
168 error ("%s=%s is not numeric",
169 small_memory
[i
].name
,
170 small_memory
[i
].value
);
173 small_memory
[i
].max
= atoi (small_memory
[i
].value
);
174 if (small_memory
[i
].max
> small_memory
[i
].physical_max
)
175 error ("%s=%s is too large",
176 small_memory
[i
].name
,
177 small_memory
[i
].value
);
182 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
183 if ((target_flags
& MASK_US_MASK_SET
) == 0)
185 target_flags
|= MASK_US_MASK_SET
;
186 target_flags
&= ~MASK_US_BIT_SET
;
192 v850_pass_by_reference (CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
193 enum machine_mode mode
, tree type
,
194 bool named ATTRIBUTE_UNUSED
)
196 unsigned HOST_WIDE_INT size
;
199 size
= int_size_in_bytes (type
);
201 size
= GET_MODE_SIZE (mode
);
206 /* Return an RTX to represent where a value with mode MODE will be returned
207 from a function. If the result is 0, the argument is pushed. */
210 function_arg (CUMULATIVE_ARGS
* cum
,
211 enum machine_mode mode
,
218 if (TARGET_GHS
&& !named
)
222 size
= int_size_in_bytes (type
);
224 size
= GET_MODE_SIZE (mode
);
230 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
234 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
236 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
239 if (type
== NULL_TREE
240 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
243 switch (cum
->nbytes
/ UNITS_PER_WORD
)
246 result
= gen_rtx_REG (mode
, 6);
249 result
= gen_rtx_REG (mode
, 7);
252 result
= gen_rtx_REG (mode
, 8);
255 result
= gen_rtx_REG (mode
, 9);
265 /* Return the number of bytes which must be put into registers
266 for values which are part in registers and part in memory. */
269 v850_arg_partial_bytes (CUMULATIVE_ARGS
* cum
, enum machine_mode mode
,
270 tree type
, bool named
)
274 if (TARGET_GHS
&& !named
)
278 size
= int_size_in_bytes (type
);
280 size
= GET_MODE_SIZE (mode
);
283 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
287 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
289 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
292 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
295 if (type
== NULL_TREE
296 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
299 return 4 * UNITS_PER_WORD
- cum
->nbytes
;
303 /* Return the high and low words of a CONST_DOUBLE */
306 const_double_split (rtx x
, HOST_WIDE_INT
* p_high
, HOST_WIDE_INT
* p_low
)
308 if (GET_CODE (x
) == CONST_DOUBLE
)
313 switch (GET_MODE (x
))
316 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
317 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
318 *p_high
= t
[1]; /* since v850 is little endian */
319 *p_low
= t
[0]; /* high is second word */
323 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
324 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
330 *p_high
= CONST_DOUBLE_HIGH (x
);
331 *p_low
= CONST_DOUBLE_LOW (x
);
339 fatal_insn ("const_double_split got a bad insn:", x
);
343 /* Return the cost of the rtx R with code CODE. */
346 const_costs_int (HOST_WIDE_INT value
, int zero_cost
)
348 if (CONST_OK_FOR_I (value
))
350 else if (CONST_OK_FOR_J (value
))
352 else if (CONST_OK_FOR_K (value
))
359 const_costs (rtx r
, enum rtx_code c
)
361 HOST_WIDE_INT high
, low
;
366 return const_costs_int (INTVAL (r
), 0);
369 const_double_split (r
, &high
, &low
);
370 if (GET_MODE (r
) == SFmode
)
371 return const_costs_int (high
, 1);
373 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
389 v850_rtx_costs (rtx x
,
391 int outer_code ATTRIBUTE_UNUSED
,
401 *total
= COSTS_N_INSNS (const_costs (x
, code
));
408 if (TARGET_V850E
&& optimize_size
)
416 && ( GET_MODE (x
) == SImode
417 || GET_MODE (x
) == HImode
418 || GET_MODE (x
) == QImode
))
420 if (GET_CODE (XEXP (x
, 1)) == REG
)
422 else if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
424 if (CONST_OK_FOR_O (INTVAL (XEXP (x
, 1))))
426 else if (CONST_OK_FOR_K (INTVAL (XEXP (x
, 1))))
439 /* Print operand X using operand code CODE to assembly language output file
443 print_operand (FILE * file
, rtx x
, int code
)
445 HOST_WIDE_INT high
, low
;
450 /* We use 'c' operands with symbols for .vtinherit */
451 if (GET_CODE (x
) == SYMBOL_REF
)
453 output_addr_const(file
, x
);
460 switch ((code
== 'B' || code
== 'C')
461 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
464 if (code
== 'c' || code
== 'C')
465 fprintf (file
, "nz");
467 fprintf (file
, "ne");
470 if (code
== 'c' || code
== 'C')
476 fprintf (file
, "ge");
479 fprintf (file
, "gt");
482 fprintf (file
, "le");
485 fprintf (file
, "lt");
488 fprintf (file
, "nl");
494 fprintf (file
, "nh");
503 case 'F': /* high word of CONST_DOUBLE */
504 if (GET_CODE (x
) == CONST_INT
)
505 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
506 else if (GET_CODE (x
) == CONST_DOUBLE
)
508 const_double_split (x
, &high
, &low
);
509 fprintf (file
, "%ld", (long) high
);
514 case 'G': /* low word of CONST_DOUBLE */
515 if (GET_CODE (x
) == CONST_INT
)
516 fprintf (file
, "%ld", (long) INTVAL (x
));
517 else if (GET_CODE (x
) == CONST_DOUBLE
)
519 const_double_split (x
, &high
, &low
);
520 fprintf (file
, "%ld", (long) low
);
526 fprintf (file
, "%d\n", (int)(INTVAL (x
) & 0xffff));
529 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
532 if (special_symbolref_operand (x
, VOIDmode
))
534 if (GET_CODE (x
) == SYMBOL_REF
)
536 else if (GET_CODE (x
) == CONST
)
537 x
= XEXP (XEXP (x
, 0), 0);
541 if (SYMBOL_REF_ZDA_P (x
))
542 fprintf (file
, "zdaoff");
543 else if (SYMBOL_REF_SDA_P (x
))
544 fprintf (file
, "sdaoff");
545 else if (SYMBOL_REF_TDA_P (x
))
546 fprintf (file
, "tdaoff");
554 if (special_symbolref_operand (x
, VOIDmode
))
555 output_addr_const (file
, x
);
560 if (special_symbolref_operand (x
, VOIDmode
))
562 if (GET_CODE (x
) == SYMBOL_REF
)
564 else if (GET_CODE (x
) == CONST
)
565 x
= XEXP (XEXP (x
, 0), 0);
569 if (SYMBOL_REF_ZDA_P (x
))
570 fprintf (file
, "r0");
571 else if (SYMBOL_REF_SDA_P (x
))
572 fprintf (file
, "gp");
573 else if (SYMBOL_REF_TDA_P (x
))
574 fprintf (file
, "ep");
581 case 'R': /* 2nd word of a double. */
582 switch (GET_CODE (x
))
585 fprintf (file
, reg_names
[REGNO (x
) + 1]);
588 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
589 print_operand_address (file
, x
);
590 if (GET_CODE (x
) == CONST_INT
)
591 fprintf (file
, "[r0]");
600 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
601 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
608 /* Like an 'S' operand above, but for unsigned loads only. */
609 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
614 case 'W': /* print the instruction suffix */
615 switch (GET_MODE (x
))
620 case QImode
: fputs (".b", file
); break;
621 case HImode
: fputs (".h", file
); break;
622 case SImode
: fputs (".w", file
); break;
623 case SFmode
: fputs (".w", file
); break;
626 case '.': /* register r0 */
627 fputs (reg_names
[0], file
);
629 case 'z': /* reg or zero */
631 fputs (reg_names
[0], file
);
632 else if (GET_CODE (x
) == REG
)
633 fputs (reg_names
[REGNO (x
)], file
);
638 switch (GET_CODE (x
))
641 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
642 output_address (gen_rtx_PLUS (SImode
, gen_rtx_REG (SImode
, 0),
645 output_address (XEXP (x
, 0));
649 fputs (reg_names
[REGNO (x
)], file
);
652 fputs (reg_names
[subreg_regno (x
)], file
);
659 print_operand_address (file
, x
);
670 /* Output assembly language output for the address ADDR to FILE. */
673 print_operand_address (FILE * file
, rtx addr
)
675 switch (GET_CODE (addr
))
678 fprintf (file
, "0[");
679 print_operand (file
, addr
, 0);
683 if (GET_CODE (XEXP (addr
, 0)) == REG
)
686 fprintf (file
, "lo(");
687 print_operand (file
, XEXP (addr
, 1), 0);
688 fprintf (file
, ")[");
689 print_operand (file
, XEXP (addr
, 0), 0);
694 if (GET_CODE (XEXP (addr
, 0)) == REG
695 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
698 print_operand (file
, XEXP (addr
, 1), 0);
700 print_operand (file
, XEXP (addr
, 0), 0);
705 print_operand (file
, XEXP (addr
, 0), 0);
707 print_operand (file
, XEXP (addr
, 1), 0);
712 const char *off_name
= NULL
;
713 const char *reg_name
= NULL
;
715 if (SYMBOL_REF_ZDA_P (addr
))
720 else if (SYMBOL_REF_SDA_P (addr
))
725 else if (SYMBOL_REF_TDA_P (addr
))
732 fprintf (file
, "%s(", off_name
);
733 output_addr_const (file
, addr
);
735 fprintf (file
, ")[%s]", reg_name
);
739 if (special_symbolref_operand (addr
, VOIDmode
))
741 rtx x
= XEXP (XEXP (addr
, 0), 0);
742 const char *off_name
;
743 const char *reg_name
;
745 if (SYMBOL_REF_ZDA_P (x
))
750 else if (SYMBOL_REF_SDA_P (x
))
755 else if (SYMBOL_REF_TDA_P (x
))
763 fprintf (file
, "%s(", off_name
);
764 output_addr_const (file
, addr
);
765 fprintf (file
, ")[%s]", reg_name
);
768 output_addr_const (file
, addr
);
771 output_addr_const (file
, addr
);
776 /* When assemble_integer is used to emit the offsets for a switch
777 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
778 output_addr_const will normally barf at this, but it is OK to omit
779 the truncate and just emit the difference of the two labels. The
780 .hword directive will automatically handle the truncation for us.
782 Returns 1 if rtx was handled, 0 otherwise. */
785 v850_output_addr_const_extra (FILE * file
, rtx x
)
787 if (GET_CODE (x
) != TRUNCATE
)
792 /* We must also handle the case where the switch table was passed a
793 constant value and so has been collapsed. In this case the first
794 label will have been deleted. In such a case it is OK to emit
795 nothing, since the table will not be used.
796 (cf gcc.c-torture/compile/990801-1.c). */
797 if (GET_CODE (x
) == MINUS
798 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
799 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
800 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
803 output_addr_const (file
, x
);
807 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
811 output_move_single (rtx
* operands
)
813 rtx dst
= operands
[0];
814 rtx src
= operands
[1];
821 else if (GET_CODE (src
) == CONST_INT
)
823 HOST_WIDE_INT value
= INTVAL (src
);
825 if (CONST_OK_FOR_J (value
)) /* Signed 5 bit immediate. */
828 else if (CONST_OK_FOR_K (value
)) /* Signed 16 bit immediate. */
829 return "movea lo(%1),%.,%0";
831 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
832 return "movhi hi(%1),%.,%0";
834 /* A random constant. */
835 else if (TARGET_V850E
)
838 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
841 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
843 HOST_WIDE_INT high
, low
;
845 const_double_split (src
, &high
, &low
);
847 if (CONST_OK_FOR_J (high
)) /* Signed 5 bit immediate. */
850 else if (CONST_OK_FOR_K (high
)) /* Signed 16 bit immediate. */
851 return "movea lo(%F1),%.,%0";
853 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
854 return "movhi hi(%F1),%.,%0";
856 /* A random constant. */
857 else if (TARGET_V850E
)
861 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
864 else if (GET_CODE (src
) == MEM
)
865 return "%S1ld%W1 %1,%0";
867 else if (special_symbolref_operand (src
, VOIDmode
))
868 return "movea %O1(%P1),%Q1,%0";
870 else if (GET_CODE (src
) == LABEL_REF
871 || GET_CODE (src
) == SYMBOL_REF
872 || GET_CODE (src
) == CONST
)
875 return "mov hilo(%1),%0";
877 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
880 else if (GET_CODE (src
) == HIGH
)
881 return "movhi hi(%1),%.,%0";
883 else if (GET_CODE (src
) == LO_SUM
)
885 operands
[2] = XEXP (src
, 0);
886 operands
[3] = XEXP (src
, 1);
887 return "movea lo(%3),%2,%0";
891 else if (GET_CODE (dst
) == MEM
)
894 return "%S0st%W0 %1,%0";
896 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
897 return "%S0st%W0 %.,%0";
899 else if (GET_CODE (src
) == CONST_DOUBLE
900 && CONST0_RTX (GET_MODE (dst
)) == src
)
901 return "%S0st%W0 %.,%0";
904 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
909 /* Return appropriate code to load up an 8 byte integer or
910 floating point value */
913 output_move_double (rtx
* operands
)
915 enum machine_mode mode
= GET_MODE (operands
[0]);
916 rtx dst
= operands
[0];
917 rtx src
= operands
[1];
919 if (register_operand (dst
, mode
)
920 && register_operand (src
, mode
))
922 if (REGNO (src
) + 1 == REGNO (dst
))
923 return "mov %R1,%R0\n\tmov %1,%0";
925 return "mov %1,%0\n\tmov %R1,%R0";
929 if (GET_CODE (dst
) == MEM
930 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
931 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
932 return "st.w %.,%0\n\tst.w %.,%R0";
934 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
936 HOST_WIDE_INT high_low
[2];
940 if (GET_CODE (src
) == CONST_DOUBLE
)
941 const_double_split (src
, &high_low
[1], &high_low
[0]);
944 high_low
[0] = INTVAL (src
);
945 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
948 for (i
= 0; i
< 2; i
++)
950 xop
[0] = gen_rtx_REG (SImode
, REGNO (dst
)+i
);
951 xop
[1] = GEN_INT (high_low
[i
]);
952 output_asm_insn (output_move_single (xop
), xop
);
958 if (GET_CODE (src
) == MEM
)
961 int dreg
= REGNO (dst
);
962 rtx inside
= XEXP (src
, 0);
964 if (GET_CODE (inside
) == REG
)
965 ptrreg
= REGNO (inside
);
966 else if (GET_CODE (inside
) == SUBREG
)
967 ptrreg
= subreg_regno (inside
);
968 else if (GET_CODE (inside
) == PLUS
)
969 ptrreg
= REGNO (XEXP (inside
, 0));
970 else if (GET_CODE (inside
) == LO_SUM
)
971 ptrreg
= REGNO (XEXP (inside
, 0));
974 return "ld.w %R1,%R0\n\tld.w %1,%0";
977 if (GET_CODE (src
) == MEM
)
978 return "ld.w %1,%0\n\tld.w %R1,%R0";
980 if (GET_CODE (dst
) == MEM
)
981 return "st.w %1,%0\n\tst.w %R1,%R0";
983 return "mov %1,%0\n\tmov %R1,%R0";
987 /* Return maximum offset supported for a short EP memory reference of mode
988 MODE and signedness UNSIGNEDP. */
991 ep_memory_offset (enum machine_mode mode
, int unsignedp ATTRIBUTE_UNUSED
)
998 if (TARGET_SMALL_SLD
)
999 max_offset
= (1 << 4);
1000 else if (TARGET_V850E
1001 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
1002 || (! unsignedp
&& TARGET_US_BIT_SET
)))
1003 max_offset
= (1 << 4);
1005 max_offset
= (1 << 7);
1009 if (TARGET_SMALL_SLD
)
1010 max_offset
= (1 << 5);
1011 else if (TARGET_V850E
1012 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
1013 || (! unsignedp
&& TARGET_US_BIT_SET
)))
1014 max_offset
= (1 << 5);
1016 max_offset
= (1 << 8);
1021 max_offset
= (1 << 8);
1031 /* Return true if OP is a valid short EP memory reference */
1034 ep_memory_operand (rtx op
, enum machine_mode mode
, int unsigned_load
)
1040 if (GET_CODE (op
) != MEM
)
1043 max_offset
= ep_memory_offset (mode
, unsigned_load
);
1045 mask
= GET_MODE_SIZE (mode
) - 1;
1047 addr
= XEXP (op
, 0);
1048 if (GET_CODE (addr
) == CONST
)
1049 addr
= XEXP (addr
, 0);
1051 switch (GET_CODE (addr
))
1057 return SYMBOL_REF_TDA_P (addr
);
1060 return REGNO (addr
) == EP_REGNUM
;
1063 op0
= XEXP (addr
, 0);
1064 op1
= XEXP (addr
, 1);
1065 if (GET_CODE (op1
) == CONST_INT
1066 && INTVAL (op1
) < max_offset
1067 && INTVAL (op1
) >= 0
1068 && (INTVAL (op1
) & mask
) == 0)
1070 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1073 if (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_TDA_P (op0
))
1082 /* Substitute memory references involving a pointer, to use the ep pointer,
1083 taking care to save and preserve the ep. */
1086 substitute_ep_register (rtx first_insn
,
1093 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1098 regs_ever_live
[1] = 1;
1099 *p_r1
= gen_rtx_REG (Pmode
, 1);
1100 *p_ep
= gen_rtx_REG (Pmode
, 30);
1105 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1106 2 * (uses
- 3), uses
, reg_names
[regno
],
1107 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1108 INSN_UID (first_insn
), INSN_UID (last_insn
));
1110 if (GET_CODE (first_insn
) == NOTE
)
1111 first_insn
= next_nonnote_insn (first_insn
);
1113 last_insn
= next_nonnote_insn (last_insn
);
1114 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1116 if (GET_CODE (insn
) == INSN
)
1118 rtx pattern
= single_set (insn
);
1120 /* Replace the memory references. */
1124 /* Memory operands are signed by default. */
1125 int unsignedp
= FALSE
;
1127 if (GET_CODE (SET_DEST (pattern
)) == MEM
1128 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1131 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1132 p_mem
= &SET_DEST (pattern
);
1134 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1135 p_mem
= &SET_SRC (pattern
);
1137 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1138 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1139 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1141 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1142 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1144 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1152 rtx addr
= XEXP (*p_mem
, 0);
1154 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1155 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1157 else if (GET_CODE (addr
) == PLUS
1158 && GET_CODE (XEXP (addr
, 0)) == REG
1159 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1160 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1161 && ((INTVAL (XEXP (addr
, 1)))
1162 < ep_memory_offset (GET_MODE (*p_mem
),
1164 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1165 *p_mem
= change_address (*p_mem
, VOIDmode
,
1166 gen_rtx_PLUS (Pmode
,
1174 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1175 insn
= prev_nonnote_insn (first_insn
);
1176 if (insn
&& GET_CODE (insn
) == INSN
1177 && GET_CODE (PATTERN (insn
)) == SET
1178 && SET_DEST (PATTERN (insn
)) == *p_ep
1179 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1182 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1184 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1185 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1189 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1190 the -mep mode to copy heavily used pointers to ep to use the implicit
1202 regs
[FIRST_PSEUDO_REGISTER
];
1211 /* If not ep mode, just return now. */
1215 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1218 regs
[i
].first_insn
= NULL_RTX
;
1219 regs
[i
].last_insn
= NULL_RTX
;
1222 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1224 switch (GET_CODE (insn
))
1226 /* End of basic block */
1233 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1235 if (max_uses
< regs
[i
].uses
)
1237 max_uses
= regs
[i
].uses
;
1243 substitute_ep_register (regs
[max_regno
].first_insn
,
1244 regs
[max_regno
].last_insn
,
1245 max_uses
, max_regno
, &r1
, &ep
);
1249 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1252 regs
[i
].first_insn
= NULL_RTX
;
1253 regs
[i
].last_insn
= NULL_RTX
;
1261 pattern
= single_set (insn
);
1263 /* See if there are any memory references we can shorten */
1266 rtx src
= SET_SRC (pattern
);
1267 rtx dest
= SET_DEST (pattern
);
1269 /* Memory operands are signed by default. */
1270 int unsignedp
= FALSE
;
1272 /* We might have (SUBREG (MEM)) here, so just get rid of the
1273 subregs to make this code simpler. */
1274 if (GET_CODE (dest
) == SUBREG
1275 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1276 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1277 alter_subreg (&dest
);
1278 if (GET_CODE (src
) == SUBREG
1279 && (GET_CODE (SUBREG_REG (src
)) == MEM
1280 || GET_CODE (SUBREG_REG (src
)) == REG
))
1281 alter_subreg (&src
);
1283 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1286 else if (GET_CODE (dest
) == MEM
)
1289 else if (GET_CODE (src
) == MEM
)
1292 else if (GET_CODE (src
) == SIGN_EXTEND
1293 && GET_CODE (XEXP (src
, 0)) == MEM
)
1294 mem
= XEXP (src
, 0);
1296 else if (GET_CODE (src
) == ZERO_EXTEND
1297 && GET_CODE (XEXP (src
, 0)) == MEM
)
1299 mem
= XEXP (src
, 0);
1305 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1308 else if (!use_ep
&& mem
1309 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1311 rtx addr
= XEXP (mem
, 0);
1315 if (GET_CODE (addr
) == REG
)
1318 regno
= REGNO (addr
);
1321 else if (GET_CODE (addr
) == PLUS
1322 && GET_CODE (XEXP (addr
, 0)) == REG
1323 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1324 && ((INTVAL (XEXP (addr
, 1)))
1325 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1326 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1329 regno
= REGNO (XEXP (addr
, 0));
1338 regs
[regno
].last_insn
= insn
;
1339 if (!regs
[regno
].first_insn
)
1340 regs
[regno
].first_insn
= insn
;
1344 /* Loading up a register in the basic block zaps any savings
1346 if (GET_CODE (dest
) == REG
)
1348 enum machine_mode mode
= GET_MODE (dest
);
1352 regno
= REGNO (dest
);
1353 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1357 /* See if we can use the pointer before this
1362 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1364 if (max_uses
< regs
[i
].uses
)
1366 max_uses
= regs
[i
].uses
;
1372 && max_regno
>= regno
1373 && max_regno
< endregno
)
1375 substitute_ep_register (regs
[max_regno
].first_insn
,
1376 regs
[max_regno
].last_insn
,
1377 max_uses
, max_regno
, &r1
,
1380 /* Since we made a substitution, zap all remembered
1382 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1385 regs
[i
].first_insn
= NULL_RTX
;
1386 regs
[i
].last_insn
= NULL_RTX
;
1391 for (i
= regno
; i
< endregno
; i
++)
1394 regs
[i
].first_insn
= NULL_RTX
;
1395 regs
[i
].last_insn
= NULL_RTX
;
1404 /* # of registers saved by the interrupt handler. */
1405 #define INTERRUPT_FIXED_NUM 4
1407 /* # of bytes for registers saved by the interrupt handler. */
1408 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1410 /* # of registers saved in register parameter area. */
1411 #define INTERRUPT_REGPARM_NUM 4
1412 /* # of words saved for other registers. */
1413 #define INTERRUPT_ALL_SAVE_NUM \
1414 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1416 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1419 compute_register_save_size (long * p_reg_saved
)
1423 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1424 int call_p
= regs_ever_live
[LINK_POINTER_REGNUM
];
1427 /* Count the return pointer if we need to save it. */
1428 if (current_function_profile
&& !call_p
)
1429 regs_ever_live
[LINK_POINTER_REGNUM
] = call_p
= 1;
1431 /* Count space for the register saves. */
1432 if (interrupt_handler
)
1434 for (i
= 0; i
<= 31; i
++)
1438 if (regs_ever_live
[i
] || call_p
)
1441 reg_saved
|= 1L << i
;
1445 /* We don't save/restore r0 or the stack pointer */
1447 case STACK_POINTER_REGNUM
:
1450 /* For registers with fixed use, we save them, set them to the
1451 appropriate value, and then restore them.
1452 These registers are handled specially, so don't list them
1453 on the list of registers to save in the prologue. */
1454 case 1: /* temp used to hold ep */
1456 case 10: /* temp used to call interrupt save/restore */
1457 case EP_REGNUM
: /* ep */
1464 /* Find the first register that needs to be saved. */
1465 for (i
= 0; i
<= 31; i
++)
1466 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1467 || i
== LINK_POINTER_REGNUM
))
1470 /* If it is possible that an out-of-line helper function might be
1471 used to generate the prologue for the current function, then we
1472 need to cover the possibility that such a helper function will
1473 be used, despite the fact that there might be gaps in the list of
1474 registers that need to be saved. To detect this we note that the
1475 helper functions always push at least register r29 (provided
1476 that the function is not an interrupt handler). */
1478 if (TARGET_PROLOG_FUNCTION
1479 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1484 reg_saved
|= 1L << i
;
1489 /* Helper functions save all registers between the starting
1490 register and the last register, regardless of whether they
1491 are actually used by the function or not. */
1492 for (; i
<= 29; i
++)
1495 reg_saved
|= 1L << i
;
1498 if (regs_ever_live
[LINK_POINTER_REGNUM
])
1501 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1506 for (; i
<= 31; i
++)
1507 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1508 || i
== LINK_POINTER_REGNUM
))
1511 reg_saved
|= 1L << i
;
1517 *p_reg_saved
= reg_saved
;
1523 compute_frame_size (int size
, long * p_reg_saved
)
1526 + compute_register_save_size (p_reg_saved
)
1527 + current_function_outgoing_args_size
);
1532 expand_prologue (void)
1536 unsigned int size
= get_frame_size ();
1537 unsigned int actual_fsize
;
1538 unsigned int init_stack_alloc
= 0;
1541 unsigned int num_save
;
1542 unsigned int default_stack
;
1544 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1547 actual_fsize
= compute_frame_size (size
, ®_saved
);
1549 /* Save/setup global registers for interrupt functions right now. */
1550 if (interrupt_handler
)
1552 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1553 emit_insn (gen_callt_save_interrupt ());
1555 emit_insn (gen_save_interrupt ());
1557 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1559 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1560 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1563 /* Save arg registers to the stack if necessary. */
1564 else if (current_function_args_info
.anonymous_args
)
1566 if (TARGET_PROLOG_FUNCTION
&& TARGET_V850E
&& !TARGET_DISABLE_CALLT
)
1567 emit_insn (gen_save_r6_r9_v850e ());
1568 else if (TARGET_PROLOG_FUNCTION
&& ! TARGET_LONG_CALLS
)
1569 emit_insn (gen_save_r6_r9 ());
1573 for (i
= 6; i
< 10; i
++)
1575 emit_move_insn (gen_rtx_MEM (SImode
,
1576 plus_constant (stack_pointer_rtx
,
1578 gen_rtx_REG (SImode
, i
));
1584 /* Identify all of the saved registers. */
1587 for (i
= 1; i
< 31; i
++)
1589 if (((1L << i
) & reg_saved
) != 0)
1590 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1593 /* If the return pointer is saved, the helper functions also allocate
1594 16 bytes of stack for arguments to be saved in. */
1595 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1597 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1601 /* See if we have an insn that allocates stack space and saves the particular
1602 registers we want to. */
1603 save_all
= NULL_RTX
;
1604 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1606 int alloc_stack
= (4 * num_save
) + default_stack
;
1607 int unalloc_stack
= actual_fsize
- alloc_stack
;
1608 int save_func_len
= 4;
1609 int save_normal_len
;
1612 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1614 /* see if we would have used ep to save the stack */
1615 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1616 save_normal_len
= (3 * 2) + (2 * num_save
);
1618 save_normal_len
= 4 * num_save
;
1620 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1622 /* Don't bother checking if we don't actually save any space.
1623 This happens for instance if one register is saved and additional
1624 stack space is allocated. */
1625 if (save_func_len
< save_normal_len
)
1627 save_all
= gen_rtx_PARALLEL
1629 rtvec_alloc (num_save
+ 1
1630 + (TARGET_V850
? (TARGET_LONG_CALLS
? 2 : 1) : 0)));
1632 XVECEXP (save_all
, 0, 0)
1633 = gen_rtx_SET (VOIDmode
,
1635 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1637 offset
= - default_stack
;
1638 for (i
= 0; i
< num_save
; i
++)
1640 XVECEXP (save_all
, 0, i
+1)
1641 = gen_rtx_SET (VOIDmode
,
1643 plus_constant (stack_pointer_rtx
,
1651 XVECEXP (save_all
, 0, num_save
+ 1)
1652 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1654 if (TARGET_LONG_CALLS
)
1655 XVECEXP (save_all
, 0, num_save
+ 2)
1656 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 11));
1659 code
= recog (save_all
, NULL_RTX
, NULL
);
1662 rtx insn
= emit_insn (save_all
);
1663 INSN_CODE (insn
) = code
;
1664 actual_fsize
-= alloc_stack
;
1668 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1669 save_normal_len
- save_func_len
,
1670 save_normal_len
, save_func_len
,
1671 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1674 save_all
= NULL_RTX
;
1678 /* If no prolog save function is available, store the registers the old
1679 fashioned way (one by one). */
1682 /* Special case interrupt functions that save all registers for a call. */
1683 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1685 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1686 emit_insn (gen_callt_save_all_interrupt ());
1688 emit_insn (gen_save_all_interrupt ());
1692 /* If the stack is too big, allocate it in chunks so we can do the
1693 register saves. We use the register save size so we use the ep
1695 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1696 init_stack_alloc
= compute_register_save_size (NULL
);
1698 init_stack_alloc
= actual_fsize
;
1700 /* Save registers at the beginning of the stack frame. */
1701 offset
= init_stack_alloc
- 4;
1703 if (init_stack_alloc
)
1704 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1706 GEN_INT (-init_stack_alloc
)));
1708 /* Save the return pointer first. */
1709 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1711 emit_move_insn (gen_rtx_MEM (SImode
,
1712 plus_constant (stack_pointer_rtx
,
1714 save_regs
[--num_save
]);
1718 for (i
= 0; i
< num_save
; i
++)
1720 emit_move_insn (gen_rtx_MEM (SImode
,
1721 plus_constant (stack_pointer_rtx
,
1729 /* Allocate the rest of the stack that was not allocated above (either it is
1730 > 32K or we just called a function to save the registers and needed more
1732 if (actual_fsize
> init_stack_alloc
)
1734 int diff
= actual_fsize
- init_stack_alloc
;
1735 if (CONST_OK_FOR_K (diff
))
1736 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1741 rtx reg
= gen_rtx_REG (Pmode
, 12);
1742 emit_move_insn (reg
, GEN_INT (-diff
));
1743 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1747 /* If we need a frame pointer, set it up now. */
1748 if (frame_pointer_needed
)
1749 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1754 expand_epilogue (void)
1758 unsigned int size
= get_frame_size ();
1760 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1761 unsigned int init_stack_free
= 0;
1762 rtx restore_regs
[32];
1764 unsigned int num_restore
;
1765 unsigned int default_stack
;
1767 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1769 /* Eliminate the initial stack stored by interrupt functions. */
1770 if (interrupt_handler
)
1772 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1773 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1774 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1777 /* Cut off any dynamic stack created. */
1778 if (frame_pointer_needed
)
1779 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1781 /* Identify all of the saved registers. */
1784 for (i
= 1; i
< 31; i
++)
1786 if (((1L << i
) & reg_saved
) != 0)
1787 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1790 /* If the return pointer is saved, the helper functions also allocate
1791 16 bytes of stack for arguments to be saved in. */
1792 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1794 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1798 /* See if we have an insn that restores the particular registers we
1800 restore_all
= NULL_RTX
;
1802 if (TARGET_PROLOG_FUNCTION
1804 && actual_fsize
>= default_stack
1805 && !interrupt_handler
)
1807 int alloc_stack
= (4 * num_restore
) + default_stack
;
1808 int unalloc_stack
= actual_fsize
- alloc_stack
;
1809 int restore_func_len
= 4;
1810 int restore_normal_len
;
1813 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1815 /* See if we would have used ep to restore the registers. */
1816 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1817 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1819 restore_normal_len
= 4 * num_restore
;
1821 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1823 /* Don't bother checking if we don't actually save any space. */
1824 if (restore_func_len
< restore_normal_len
)
1826 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1827 rtvec_alloc (num_restore
+ 2));
1828 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1829 XVECEXP (restore_all
, 0, 1)
1830 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1831 gen_rtx_PLUS (Pmode
,
1833 GEN_INT (alloc_stack
)));
1835 offset
= alloc_stack
- 4;
1836 for (i
= 0; i
< num_restore
; i
++)
1838 XVECEXP (restore_all
, 0, i
+2)
1839 = gen_rtx_SET (VOIDmode
,
1842 plus_constant (stack_pointer_rtx
,
1847 code
= recog (restore_all
, NULL_RTX
, NULL
);
1853 actual_fsize
-= alloc_stack
;
1856 if (CONST_OK_FOR_K (actual_fsize
))
1857 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1859 GEN_INT (actual_fsize
)));
1862 rtx reg
= gen_rtx_REG (Pmode
, 12);
1863 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1864 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1870 insn
= emit_jump_insn (restore_all
);
1871 INSN_CODE (insn
) = code
;
1875 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1876 restore_normal_len
- restore_func_len
,
1877 restore_normal_len
, restore_func_len
,
1878 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1881 restore_all
= NULL_RTX
;
1885 /* If no epilog save function is available, restore the registers the
1886 old fashioned way (one by one). */
1889 /* If the stack is large, we need to cut it down in 2 pieces. */
1890 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1891 init_stack_free
= 4 * num_restore
;
1893 init_stack_free
= actual_fsize
;
1895 /* Deallocate the rest of the stack if it is > 32K. */
1896 if (actual_fsize
> init_stack_free
)
1900 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
1902 if (CONST_OK_FOR_K (diff
))
1903 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1908 rtx reg
= gen_rtx_REG (Pmode
, 12);
1909 emit_move_insn (reg
, GEN_INT (diff
));
1910 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1916 /* Special case interrupt functions that save all registers
1918 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1920 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1921 emit_insn (gen_callt_restore_all_interrupt ());
1923 emit_insn (gen_restore_all_interrupt ());
1927 /* Restore registers from the beginning of the stack frame. */
1928 offset
= init_stack_free
- 4;
1930 /* Restore the return pointer first. */
1932 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
1934 emit_move_insn (restore_regs
[--num_restore
],
1935 gen_rtx_MEM (SImode
,
1936 plus_constant (stack_pointer_rtx
,
1941 for (i
= 0; i
< num_restore
; i
++)
1943 emit_move_insn (restore_regs
[i
],
1944 gen_rtx_MEM (SImode
,
1945 plus_constant (stack_pointer_rtx
,
1948 emit_insn (gen_rtx_USE (VOIDmode
, restore_regs
[i
]));
1952 /* Cut back the remainder of the stack. */
1953 if (init_stack_free
)
1954 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1956 GEN_INT (init_stack_free
)));
1959 /* And return or use reti for interrupt handlers. */
1960 if (interrupt_handler
)
1962 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1963 emit_insn (gen_callt_return_interrupt ());
1965 emit_jump_insn (gen_return_interrupt ());
1967 else if (actual_fsize
)
1968 emit_jump_insn (gen_return_internal ());
1970 emit_jump_insn (gen_return ());
1973 v850_interrupt_cache_p
= FALSE
;
1974 v850_interrupt_p
= FALSE
;
1978 /* Update the condition code from the insn. */
1981 notice_update_cc (rtx body
, rtx insn
)
1983 switch (get_attr_cc (insn
))
1986 /* Insn does not affect CC at all. */
1990 /* Insn does not change CC, but the 0'th operand has been changed. */
1991 if (cc_status
.value1
!= 0
1992 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
1993 cc_status
.value1
= 0;
1997 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1998 V,C is in an unusable state. */
2000 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2001 cc_status
.value1
= recog_data
.operand
[0];
2005 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2006 C is in an unusable state. */
2008 cc_status
.flags
|= CC_NO_CARRY
;
2009 cc_status
.value1
= recog_data
.operand
[0];
2013 /* The insn is a compare instruction. */
2015 cc_status
.value1
= SET_SRC (body
);
2019 /* Insn doesn't leave CC in a usable state. */
2025 /* Retrieve the data area that has been chosen for the given decl. */
2028 v850_get_data_area (tree decl
)
2030 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2031 return DATA_AREA_SDA
;
2033 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2034 return DATA_AREA_TDA
;
2036 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2037 return DATA_AREA_ZDA
;
2039 return DATA_AREA_NORMAL
;
2042 /* Store the indicated data area in the decl's attributes. */
2045 v850_set_data_area (tree decl
, v850_data_area data_area
)
2051 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2052 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2053 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2058 DECL_ATTRIBUTES (decl
) = tree_cons
2059 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2062 const struct attribute_spec v850_attribute_table
[] =
2064 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2065 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2066 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2067 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2068 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2069 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2070 { NULL
, 0, 0, false, false, false, NULL
}
2073 /* Handle an "interrupt" attribute; arguments as in
2074 struct attribute_spec.handler. */
2076 v850_handle_interrupt_attribute (tree
* node
,
2078 tree args ATTRIBUTE_UNUSED
,
2079 int flags ATTRIBUTE_UNUSED
,
2080 bool * no_add_attrs
)
2082 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2084 warning ("%qs attribute only applies to functions",
2085 IDENTIFIER_POINTER (name
));
2086 *no_add_attrs
= true;
2092 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2093 struct attribute_spec.handler. */
2095 v850_handle_data_area_attribute (tree
* node
,
2097 tree args ATTRIBUTE_UNUSED
,
2098 int flags ATTRIBUTE_UNUSED
,
2099 bool * no_add_attrs
)
2101 v850_data_area data_area
;
2102 v850_data_area area
;
2105 /* Implement data area attribute. */
2106 if (is_attribute_p ("sda", name
))
2107 data_area
= DATA_AREA_SDA
;
2108 else if (is_attribute_p ("tda", name
))
2109 data_area
= DATA_AREA_TDA
;
2110 else if (is_attribute_p ("zda", name
))
2111 data_area
= DATA_AREA_ZDA
;
2115 switch (TREE_CODE (decl
))
2118 if (current_function_decl
!= NULL_TREE
)
2120 error ("%Jdata area attributes cannot be specified for "
2121 "local variables", decl
, decl
);
2122 *no_add_attrs
= true;
2128 area
= v850_get_data_area (decl
);
2129 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2131 error ("%Jdata area of '%D' conflicts with previous declaration",
2133 *no_add_attrs
= true;
2145 /* Return nonzero if FUNC is an interrupt function as specified
2146 by the "interrupt" attribute. */
2149 v850_interrupt_function_p (tree func
)
2154 if (v850_interrupt_cache_p
)
2155 return v850_interrupt_p
;
2157 if (TREE_CODE (func
) != FUNCTION_DECL
)
2160 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2166 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2167 ret
= a
!= NULL_TREE
;
2170 /* Its not safe to trust global variables until after function inlining has
2172 if (reload_completed
| reload_in_progress
)
2173 v850_interrupt_p
= ret
;
2180 v850_encode_data_area (tree decl
, rtx symbol
)
2184 /* Map explicit sections into the appropriate attribute */
2185 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2187 if (DECL_SECTION_NAME (decl
))
2189 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2191 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2192 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2194 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2195 v850_set_data_area (decl
, DATA_AREA_SDA
);
2197 else if (streq (name
, ".tdata"))
2198 v850_set_data_area (decl
, DATA_AREA_TDA
);
2201 /* If no attribute, support -m{zda,sda,tda}=n */
2204 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2208 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2209 v850_set_data_area (decl
, DATA_AREA_TDA
);
2211 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2212 v850_set_data_area (decl
, DATA_AREA_SDA
);
2214 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2215 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2218 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2222 flags
= SYMBOL_REF_FLAGS (symbol
);
2223 switch (v850_get_data_area (decl
))
2225 case DATA_AREA_ZDA
: flags
|= SYMBOL_FLAG_ZDA
; break;
2226 case DATA_AREA_TDA
: flags
|= SYMBOL_FLAG_TDA
; break;
2227 case DATA_AREA_SDA
: flags
|= SYMBOL_FLAG_SDA
; break;
2230 SYMBOL_REF_FLAGS (symbol
) = flags
;
2234 v850_encode_section_info (tree decl
, rtx rtl
, int first
)
2236 default_encode_section_info (decl
, rtl
, first
);
2238 if (TREE_CODE (decl
) == VAR_DECL
2239 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2240 v850_encode_data_area (decl
, XEXP (rtl
, 0));
2243 /* Construct a JR instruction to a routine that will perform the equivalent of
2244 the RTL passed in as an argument. This RTL is a function epilogue that
2245 pops registers off the stack and possibly releases some extra stack space
2246 as well. The code has already verified that the RTL matches these
2249 construct_restore_jr (rtx op
)
2251 int count
= XVECLEN (op
, 0);
2253 unsigned long int mask
;
2254 unsigned long int first
;
2255 unsigned long int last
;
2257 static char buff
[100]; /* XXX */
2261 error ("bogus JR construction: %d\n", count
);
2265 /* Work out how many bytes to pop off the stack before retrieving
2267 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2269 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2271 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2274 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2276 /* Each pop will remove 4 bytes from the stack.... */
2277 stack_bytes
-= (count
- 2) * 4;
2279 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2280 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2282 error ("bad amount of stack space removal: %d", stack_bytes
);
2286 /* Now compute the bit mask of registers to push. */
2288 for (i
= 2; i
< count
; i
++)
2290 rtx vector_element
= XVECEXP (op
, 0, i
);
2292 if (GET_CODE (vector_element
) != SET
)
2294 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2296 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
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
))
2312 /* Discover the last register to pop. */
2313 if (mask
& (1 << LINK_POINTER_REGNUM
))
2315 if (stack_bytes
!= 16)
2318 last
= LINK_POINTER_REGNUM
;
2322 if (stack_bytes
!= 0)
2325 if ((mask
& (1 << 29)) == 0)
2331 /* Note, it is possible to have gaps in the register mask.
2332 We ignore this here, and generate a JR anyway. We will
2333 be popping more registers than is strictly necessary, but
2334 it does save code space. */
2336 if (TARGET_LONG_CALLS
)
2341 sprintf (name
, "__return_%s", reg_names
[first
]);
2343 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2345 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2351 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2353 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2360 /* Construct a JARL instruction to a routine that will perform the equivalent
2361 of the RTL passed as a parameter. This RTL is a function prologue that
2362 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2363 some stack space as well. The code has already verified that the RTL
2364 matches these requirements. */
2366 construct_save_jarl (rtx op
)
2368 int count
= XVECLEN (op
, 0);
2370 unsigned long int mask
;
2371 unsigned long int first
;
2372 unsigned long int last
;
2374 static char buff
[100]; /* XXX */
2378 error ("bogus JARL construction: %d\n", count
);
2383 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2385 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2387 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) != REG
)
2389 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2392 /* Work out how many bytes to push onto the stack after storing the
2394 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2396 /* Each push will put 4 bytes from the stack.... */
2397 stack_bytes
+= (count
- (TARGET_LONG_CALLS
? 3 : 2)) * 4;
2399 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2400 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2402 error ("bad amount of stack space removal: %d", stack_bytes
);
2406 /* Now compute the bit mask of registers to push. */
2408 for (i
= 1; i
< count
- (TARGET_LONG_CALLS
? 2 : 1); i
++)
2410 rtx vector_element
= XVECEXP (op
, 0, i
);
2412 if (GET_CODE (vector_element
) != SET
)
2414 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2416 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2419 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2422 /* Scan for the first register to push. */
2423 for (first
= 0; first
< 32; first
++)
2425 if (mask
& (1 << first
))
2432 /* Discover the last register to push. */
2433 if (mask
& (1 << LINK_POINTER_REGNUM
))
2435 if (stack_bytes
!= -16)
2438 last
= LINK_POINTER_REGNUM
;
2442 if (stack_bytes
!= 0)
2444 if ((mask
& (1 << 29)) == 0)
2450 /* Note, it is possible to have gaps in the register mask.
2451 We ignore this here, and generate a JARL anyway. We will
2452 be pushing more registers than is strictly necessary, but
2453 it does save code space. */
2455 if (TARGET_LONG_CALLS
)
2460 sprintf (name
, "__save_%s", reg_names
[first
]);
2462 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2464 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2470 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2472 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2479 extern tree last_assemble_variable_decl
;
2480 extern int size_directive_output
;
2482 /* A version of asm_output_aligned_bss() that copes with the special
2483 data areas of the v850. */
2485 v850_output_aligned_bss (FILE * file
,
2491 switch (v850_get_data_area (decl
))
2509 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2510 #ifdef ASM_DECLARE_OBJECT_NAME
2511 last_assemble_variable_decl
= decl
;
2512 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2514 /* Standard thing is just output label for the object. */
2515 ASM_OUTPUT_LABEL (file
, name
);
2516 #endif /* ASM_DECLARE_OBJECT_NAME */
2517 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2520 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2522 v850_output_common (FILE * file
,
2528 if (decl
== NULL_TREE
)
2530 fprintf (file
, "%s", COMMON_ASM_OP
);
2534 switch (v850_get_data_area (decl
))
2537 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2541 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2545 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2549 fprintf (file
, "%s", COMMON_ASM_OP
);
2554 assemble_name (file
, name
);
2555 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2558 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2560 v850_output_local (FILE * file
,
2566 fprintf (file
, "%s", LOCAL_ASM_OP
);
2567 assemble_name (file
, name
);
2568 fprintf (file
, "\n");
2570 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2573 /* Add data area to the given declaration if a ghs data area pragma is
2574 currently in effect (#pragma ghs startXXX/endXXX). */
2576 v850_insert_attributes (tree decl
, tree
* attr_ptr ATTRIBUTE_UNUSED
)
2579 && data_area_stack
->data_area
2580 && current_function_decl
== NULL_TREE
2581 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2582 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2583 v850_set_data_area (decl
, data_area_stack
->data_area
);
2585 /* Initialize the default names of the v850 specific sections,
2586 if this has not been done before. */
2588 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2590 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2591 = build_string (sizeof (".sdata")-1, ".sdata");
2593 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2594 = build_string (sizeof (".rosdata")-1, ".rosdata");
2596 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2597 = build_string (sizeof (".tdata")-1, ".tdata");
2599 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2600 = build_string (sizeof (".zdata")-1, ".zdata");
2602 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2603 = build_string (sizeof (".rozdata")-1, ".rozdata");
2606 if (current_function_decl
== NULL_TREE
2607 && (TREE_CODE (decl
) == VAR_DECL
2608 || TREE_CODE (decl
) == CONST_DECL
2609 || TREE_CODE (decl
) == FUNCTION_DECL
)
2610 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2611 && !DECL_SECTION_NAME (decl
))
2613 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2614 tree chosen_section
;
2616 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2617 kind
= GHS_SECTION_KIND_TEXT
;
2620 /* First choose a section kind based on the data area of the decl. */
2621 switch (v850_get_data_area (decl
))
2627 kind
= ((TREE_READONLY (decl
))
2628 ? GHS_SECTION_KIND_ROSDATA
2629 : GHS_SECTION_KIND_SDATA
);
2633 kind
= GHS_SECTION_KIND_TDATA
;
2637 kind
= ((TREE_READONLY (decl
))
2638 ? GHS_SECTION_KIND_ROZDATA
2639 : GHS_SECTION_KIND_ZDATA
);
2642 case DATA_AREA_NORMAL
: /* default data area */
2643 if (TREE_READONLY (decl
))
2644 kind
= GHS_SECTION_KIND_RODATA
;
2645 else if (DECL_INITIAL (decl
))
2646 kind
= GHS_SECTION_KIND_DATA
;
2648 kind
= GHS_SECTION_KIND_BSS
;
2652 /* Now, if the section kind has been explicitly renamed,
2653 then attach a section attribute. */
2654 chosen_section
= GHS_current_section_names
[(int) kind
];
2656 /* Otherwise, if this kind of section needs an explicit section
2657 attribute, then also attach one. */
2658 if (chosen_section
== NULL
)
2659 chosen_section
= GHS_default_section_names
[(int) kind
];
2663 /* Only set the section name if specified by a pragma, because
2664 otherwise it will force those variables to get allocated storage
2665 in this module, rather than by the linker. */
2666 DECL_SECTION_NAME (decl
) = chosen_section
;
2671 /* Construct a DISPOSE instruction that is the equivalent of
2672 the given RTX. We have already verified that this should
2676 construct_dispose_instruction (rtx op
)
2678 int count
= XVECLEN (op
, 0);
2680 unsigned long int mask
;
2682 static char buff
[ 100 ]; /* XXX */
2687 error ("Bogus DISPOSE construction: %d\n", count
);
2691 /* Work out how many bytes to pop off the
2692 stack before retrieving registers. */
2693 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2695 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2697 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2700 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2702 /* Each pop will remove 4 bytes from the stack.... */
2703 stack_bytes
-= (count
- 2) * 4;
2705 /* Make sure that the amount we are popping
2706 will fit into the DISPOSE instruction. */
2707 if (stack_bytes
> 128)
2709 error ("Too much stack space to dispose of: %d", stack_bytes
);
2713 /* Now compute the bit mask of registers to push. */
2716 for (i
= 2; i
< count
; i
++)
2718 rtx vector_element
= XVECEXP (op
, 0, i
);
2720 if (GET_CODE (vector_element
) != SET
)
2722 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2724 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
2727 if (REGNO (SET_DEST (vector_element
)) == 2)
2730 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2733 if (! TARGET_DISABLE_CALLT
2734 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
2738 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
2743 for (i
= 20; i
< 32; i
++)
2744 if (mask
& (1 << i
))
2748 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
2750 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
2751 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
2756 static char regs
[100]; /* XXX */
2759 /* Generate the DISPOSE instruction. Note we could just issue the
2760 bit mask as a number as the assembler can cope with this, but for
2761 the sake of our readers we turn it into a textual description. */
2765 for (i
= 20; i
< 32; i
++)
2767 if (mask
& (1 << i
))
2772 strcat (regs
, ", ");
2777 strcat (regs
, reg_names
[ first
]);
2779 for (i
++; i
< 32; i
++)
2780 if ((mask
& (1 << i
)) == 0)
2785 strcat (regs
, " - ");
2786 strcat (regs
, reg_names
[ i
- 1 ] );
2791 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
2797 /* Construct a PREPARE instruction that is the equivalent of
2798 the given RTL. We have already verified that this should
2802 construct_prepare_instruction (rtx op
)
2804 int count
= XVECLEN (op
, 0);
2806 unsigned long int mask
;
2808 static char buff
[ 100 ]; /* XXX */
2813 error ("Bogus PREPEARE construction: %d\n", count
);
2817 /* Work out how many bytes to push onto
2818 the stack after storing the registers. */
2819 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2821 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2823 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2826 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2828 /* Each push will put 4 bytes from the stack. */
2829 stack_bytes
+= (count
- 1) * 4;
2831 /* Make sure that the amount we are popping
2832 will fit into the DISPOSE instruction. */
2833 if (stack_bytes
< -128)
2835 error ("Too much stack space to prepare: %d", stack_bytes
);
2839 /* Now compute the bit mask of registers to push. */
2841 for (i
= 1; i
< count
; i
++)
2843 rtx vector_element
= XVECEXP (op
, 0, i
);
2845 if (GET_CODE (vector_element
) != SET
)
2847 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2849 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2852 if (REGNO (SET_SRC (vector_element
)) == 2)
2855 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2858 if ((! TARGET_DISABLE_CALLT
)
2859 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
2863 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
2867 for (i
= 20; i
< 32; i
++)
2868 if (mask
& (1 << i
))
2872 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
2874 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
2875 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
2879 static char regs
[100]; /* XXX */
2883 /* Generate the PREPARE instruction. Note we could just issue the
2884 bit mask as a number as the assembler can cope with this, but for
2885 the sake of our readers we turn it into a textual description. */
2889 for (i
= 20; i
< 32; i
++)
2891 if (mask
& (1 << i
))
2896 strcat (regs
, ", ");
2901 strcat (regs
, reg_names
[ first
]);
2903 for (i
++; i
< 32; i
++)
2904 if ((mask
& (1 << i
)) == 0)
2909 strcat (regs
, " - ");
2910 strcat (regs
, reg_names
[ i
- 1 ] );
2915 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
2921 /* Return an RTX indicating where the return address to the
2922 calling function can be found. */
2925 v850_return_addr (int count
)
2930 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
2934 v850_select_section (tree exp
,
2935 int reloc ATTRIBUTE_UNUSED
,
2936 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
2938 if (TREE_CODE (exp
) == VAR_DECL
)
2941 if (!TREE_READONLY (exp
)
2942 || TREE_SIDE_EFFECTS (exp
)
2943 || !DECL_INITIAL (exp
)
2944 || (DECL_INITIAL (exp
) != error_mark_node
2945 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
2950 switch (v850_get_data_area (exp
))
2972 readonly_data_section ();
2979 readonly_data_section ();
2982 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2985 v850_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
2987 /* Return values > 8 bytes in length in memory. */
2988 return int_size_in_bytes (type
) > 8 || TYPE_MODE (type
) == BLKmode
;
2991 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2994 v850_setup_incoming_varargs (CUMULATIVE_ARGS
*ca
,
2995 enum machine_mode mode ATTRIBUTE_UNUSED
,
2996 tree type ATTRIBUTE_UNUSED
,
2997 int *pretend_arg_size ATTRIBUTE_UNUSED
,
2998 int second_time ATTRIBUTE_UNUSED
)
3000 ca
->anonymous_args
= (!TARGET_GHS
? 1 : 0);