1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
42 #include "integrate.h"
45 #include "target-def.h"
48 #define streq(a,b) (strcmp (a, b) == 0)
51 /* Function prototypes for stupid compilers: */
52 static void const_double_split (rtx
, HOST_WIDE_INT
*, HOST_WIDE_INT
*);
53 static int const_costs_int (HOST_WIDE_INT
, int);
54 static int const_costs (rtx
, enum rtx_code
);
55 static bool v850_rtx_costs (rtx
, int, int, int *);
56 static void substitute_ep_register (rtx
, rtx
, int, int, rtx
*, rtx
*);
57 static void v850_reorg (void);
58 static int ep_memory_offset (enum machine_mode
, int);
59 static void v850_set_data_area (tree
, v850_data_area
);
60 const struct attribute_spec v850_attribute_table
[];
61 static tree
v850_handle_interrupt_attribute (tree
*, tree
, tree
, int, bool *);
62 static tree
v850_handle_data_area_attribute (tree
*, tree
, tree
, int, bool *);
63 static void v850_insert_attributes (tree
, tree
*);
64 static void v850_select_section (tree
, int, unsigned HOST_WIDE_INT
);
65 static void v850_encode_data_area (tree
, rtx
);
66 static void v850_encode_section_info (tree
, rtx
, int);
67 static bool v850_return_in_memory (tree
, tree
);
68 static void v850_setup_incoming_varargs (CUMULATIVE_ARGS
*, enum machine_mode
,
71 /* Information about the various small memory areas. */
72 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
74 /* name value max physical max */
75 { "tda", (char *)0, 0, 256 },
76 { "sda", (char *)0, 0, 65536 },
77 { "zda", (char *)0, 0, 32768 },
80 /* Names of the various data areas used on the v850. */
81 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
82 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
84 /* Track the current data area set by the data area pragma (which
85 can be nested). Tested by check_default_data_area. */
86 data_area_stack_element
* data_area_stack
= NULL
;
88 /* True if we don't need to check any more if the current
89 function is an interrupt handler. */
90 static int v850_interrupt_cache_p
= FALSE
;
92 /* Whether current function is an interrupt handler. */
93 static int v850_interrupt_p
= FALSE
;
95 /* Initialize the GCC target structure. */
96 #undef TARGET_ASM_ALIGNED_HI_OP
97 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
99 #undef TARGET_ATTRIBUTE_TABLE
100 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
102 #undef TARGET_INSERT_ATTRIBUTES
103 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
105 #undef TARGET_ASM_SELECT_SECTION
106 #define TARGET_ASM_SELECT_SECTION v850_select_section
108 #undef TARGET_ENCODE_SECTION_INFO
109 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
111 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
112 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
114 #undef TARGET_RTX_COSTS
115 #define TARGET_RTX_COSTS v850_rtx_costs
116 #undef TARGET_ADDRESS_COST
117 #define TARGET_ADDRESS_COST hook_int_rtx_0
119 #undef TARGET_MACHINE_DEPENDENT_REORG
120 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
122 #undef TARGET_PROMOTE_PROTOTYPES
123 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
125 #undef TARGET_RETURN_IN_MEMORY
126 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
128 #undef TARGET_SETUP_INCOMING_VARARGS
129 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
131 struct gcc_target targetm
= TARGET_INITIALIZER
;
133 /* Sometimes certain combinations of command options do not make
134 sense on a particular target machine. You can define a macro
135 `OVERRIDE_OPTIONS' to take account of this. This macro, if
136 defined, is executed once just after all the command options have
139 Don't use this macro to turn on various extra optimizations for
140 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
143 override_options (void)
146 extern int atoi (const char *);
148 /* Parse -m{s,t,z}da=nnn switches */
149 for (i
= 0; i
< (int)SMALL_MEMORY_max
; i
++)
151 if (small_memory
[i
].value
)
153 if (!ISDIGIT (*small_memory
[i
].value
))
154 error ("%s=%s is not numeric",
155 small_memory
[i
].name
,
156 small_memory
[i
].value
);
159 small_memory
[i
].max
= atoi (small_memory
[i
].value
);
160 if (small_memory
[i
].max
> small_memory
[i
].physical_max
)
161 error ("%s=%s is too large",
162 small_memory
[i
].name
,
163 small_memory
[i
].value
);
168 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
169 if ((target_flags
& MASK_US_MASK_SET
) == 0)
171 target_flags
|= MASK_US_MASK_SET
;
172 target_flags
&= ~MASK_US_BIT_SET
;
178 /* Return an RTX to represent where a value with mode MODE will be returned
179 from a function. If the result is 0, the argument is pushed. */
182 function_arg (CUMULATIVE_ARGS
* cum
,
183 enum machine_mode mode
,
190 if (TARGET_GHS
&& !named
)
194 size
= int_size_in_bytes (type
);
196 size
= GET_MODE_SIZE (mode
);
202 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
206 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
208 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
211 if (type
== NULL_TREE
212 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
215 switch (cum
->nbytes
/ UNITS_PER_WORD
)
218 result
= gen_rtx_REG (mode
, 6);
221 result
= gen_rtx_REG (mode
, 7);
224 result
= gen_rtx_REG (mode
, 8);
227 result
= gen_rtx_REG (mode
, 9);
237 /* Return the number of words which must be put into registers
238 for values which are part in registers and part in memory. */
241 function_arg_partial_nregs (CUMULATIVE_ARGS
* cum
,
242 enum machine_mode mode
,
248 if (TARGET_GHS
&& !named
)
252 size
= int_size_in_bytes (type
);
254 size
= GET_MODE_SIZE (mode
);
257 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
261 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
263 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
266 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
269 if (type
== NULL_TREE
270 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
273 return (4 * UNITS_PER_WORD
- cum
->nbytes
) / UNITS_PER_WORD
;
277 /* Return the high and low words of a CONST_DOUBLE */
280 const_double_split (rtx x
, HOST_WIDE_INT
* p_high
, HOST_WIDE_INT
* p_low
)
282 if (GET_CODE (x
) == CONST_DOUBLE
)
287 switch (GET_MODE (x
))
290 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
291 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
292 *p_high
= t
[1]; /* since v850 is little endian */
293 *p_low
= t
[0]; /* high is second word */
297 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
298 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
304 *p_high
= CONST_DOUBLE_HIGH (x
);
305 *p_low
= CONST_DOUBLE_LOW (x
);
313 fatal_insn ("const_double_split got a bad insn:", x
);
317 /* Return the cost of the rtx R with code CODE. */
320 const_costs_int (HOST_WIDE_INT value
, int zero_cost
)
322 if (CONST_OK_FOR_I (value
))
324 else if (CONST_OK_FOR_J (value
))
326 else if (CONST_OK_FOR_K (value
))
333 const_costs (rtx r
, enum rtx_code c
)
335 HOST_WIDE_INT high
, low
;
340 return const_costs_int (INTVAL (r
), 0);
343 const_double_split (r
, &high
, &low
);
344 if (GET_MODE (r
) == SFmode
)
345 return const_costs_int (high
, 1);
347 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
363 v850_rtx_costs (rtx x
,
365 int outer_code ATTRIBUTE_UNUSED
,
375 *total
= COSTS_N_INSNS (const_costs (x
, code
));
382 if (TARGET_V850E
&& optimize_size
)
390 && ( GET_MODE (x
) == SImode
391 || GET_MODE (x
) == HImode
392 || GET_MODE (x
) == QImode
))
394 if (GET_CODE (XEXP (x
, 1)) == REG
)
396 else if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
398 if (CONST_OK_FOR_O (INTVAL (XEXP (x
, 1))))
400 else if (CONST_OK_FOR_K (INTVAL (XEXP (x
, 1))))
413 /* Print operand X using operand code CODE to assembly language output file
417 print_operand (FILE * file
, rtx x
, int code
)
419 HOST_WIDE_INT high
, low
;
424 /* We use 'c' operands with symbols for .vtinherit */
425 if (GET_CODE (x
) == SYMBOL_REF
)
427 output_addr_const(file
, x
);
434 switch ((code
== 'B' || code
== 'C')
435 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
438 if (code
== 'c' || code
== 'C')
439 fprintf (file
, "nz");
441 fprintf (file
, "ne");
444 if (code
== 'c' || code
== 'C')
450 fprintf (file
, "ge");
453 fprintf (file
, "gt");
456 fprintf (file
, "le");
459 fprintf (file
, "lt");
462 fprintf (file
, "nl");
468 fprintf (file
, "nh");
477 case 'F': /* high word of CONST_DOUBLE */
478 if (GET_CODE (x
) == CONST_INT
)
479 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
480 else if (GET_CODE (x
) == CONST_DOUBLE
)
482 const_double_split (x
, &high
, &low
);
483 fprintf (file
, "%ld", (long) high
);
488 case 'G': /* low word of CONST_DOUBLE */
489 if (GET_CODE (x
) == CONST_INT
)
490 fprintf (file
, "%ld", (long) INTVAL (x
));
491 else if (GET_CODE (x
) == CONST_DOUBLE
)
493 const_double_split (x
, &high
, &low
);
494 fprintf (file
, "%ld", (long) low
);
500 fprintf (file
, "%d\n", (int)(INTVAL (x
) & 0xffff));
503 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
506 if (special_symbolref_operand (x
, VOIDmode
))
508 if (GET_CODE (x
) == SYMBOL_REF
)
510 else if (GET_CODE (x
) == CONST
)
511 x
= XEXP (XEXP (x
, 0), 0);
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");
528 if (special_symbolref_operand (x
, VOIDmode
))
529 output_addr_const (file
, x
);
534 if (special_symbolref_operand (x
, VOIDmode
))
536 if (GET_CODE (x
) == SYMBOL_REF
)
538 else if (GET_CODE (x
) == CONST
)
539 x
= XEXP (XEXP (x
, 0), 0);
543 if (SYMBOL_REF_ZDA_P (x
))
544 fprintf (file
, "r0");
545 else if (SYMBOL_REF_SDA_P (x
))
546 fprintf (file
, "gp");
547 else if (SYMBOL_REF_TDA_P (x
))
548 fprintf (file
, "ep");
555 case 'R': /* 2nd word of a double. */
556 switch (GET_CODE (x
))
559 fprintf (file
, reg_names
[REGNO (x
) + 1]);
562 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
563 print_operand_address (file
, x
);
564 if (GET_CODE (x
) == CONST_INT
)
565 fprintf (file
, "[r0]");
574 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
575 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
582 /* Like an 'S' operand above, but for unsigned loads only. */
583 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
588 case 'W': /* print the instruction suffix */
589 switch (GET_MODE (x
))
594 case QImode
: fputs (".b", file
); break;
595 case HImode
: fputs (".h", file
); break;
596 case SImode
: fputs (".w", file
); break;
597 case SFmode
: fputs (".w", file
); break;
600 case '.': /* register r0 */
601 fputs (reg_names
[0], file
);
603 case 'z': /* reg or zero */
605 fputs (reg_names
[0], file
);
606 else if (GET_CODE (x
) == REG
)
607 fputs (reg_names
[REGNO (x
)], file
);
612 switch (GET_CODE (x
))
615 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
616 output_address (gen_rtx_PLUS (SImode
, gen_rtx_REG (SImode
, 0),
619 output_address (XEXP (x
, 0));
623 fputs (reg_names
[REGNO (x
)], file
);
626 fputs (reg_names
[subreg_regno (x
)], file
);
633 print_operand_address (file
, x
);
644 /* Output assembly language output for the address ADDR to FILE. */
647 print_operand_address (FILE * file
, rtx addr
)
649 switch (GET_CODE (addr
))
652 fprintf (file
, "0[");
653 print_operand (file
, addr
, 0);
657 if (GET_CODE (XEXP (addr
, 0)) == REG
)
660 fprintf (file
, "lo(");
661 print_operand (file
, XEXP (addr
, 1), 0);
662 fprintf (file
, ")[");
663 print_operand (file
, XEXP (addr
, 0), 0);
668 if (GET_CODE (XEXP (addr
, 0)) == REG
669 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
672 print_operand (file
, XEXP (addr
, 1), 0);
674 print_operand (file
, XEXP (addr
, 0), 0);
679 print_operand (file
, XEXP (addr
, 0), 0);
681 print_operand (file
, XEXP (addr
, 1), 0);
686 const char *off_name
= NULL
;
687 const char *reg_name
= NULL
;
689 if (SYMBOL_REF_ZDA_P (addr
))
694 else if (SYMBOL_REF_SDA_P (addr
))
699 else if (SYMBOL_REF_TDA_P (addr
))
706 fprintf (file
, "%s(", off_name
);
707 output_addr_const (file
, addr
);
709 fprintf (file
, ")[%s]", reg_name
);
713 if (special_symbolref_operand (addr
, VOIDmode
))
715 rtx x
= XEXP (XEXP (addr
, 0), 0);
716 const char *off_name
;
717 const char *reg_name
;
719 if (SYMBOL_REF_ZDA_P (x
))
724 else if (SYMBOL_REF_SDA_P (x
))
729 else if (SYMBOL_REF_TDA_P (x
))
737 fprintf (file
, "%s(", off_name
);
738 output_addr_const (file
, addr
);
739 fprintf (file
, ")[%s]", reg_name
);
742 output_addr_const (file
, addr
);
745 output_addr_const (file
, addr
);
750 /* When assemble_integer is used to emit the offsets for a switch
751 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
752 output_addr_const will normally barf at this, but it is OK to omit
753 the truncate and just emit the difference of the two labels. The
754 .hword directive will automatically handle the truncation for us.
756 Returns 1 if rtx was handled, 0 otherwise. */
759 v850_output_addr_const_extra (FILE * file
, rtx x
)
761 if (GET_CODE (x
) != TRUNCATE
)
766 /* We must also handle the case where the switch table was passed a
767 constant value and so has been collapsed. In this case the first
768 label will have been deleted. In such a case it is OK to emit
769 nothing, since the table will not be used.
770 (cf gcc.c-torture/compile/990801-1.c). */
771 if (GET_CODE (x
) == MINUS
772 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
773 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
774 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
777 output_addr_const (file
, x
);
781 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
785 output_move_single (rtx
* operands
)
787 rtx dst
= operands
[0];
788 rtx src
= operands
[1];
795 else if (GET_CODE (src
) == CONST_INT
)
797 HOST_WIDE_INT value
= INTVAL (src
);
799 if (CONST_OK_FOR_J (value
)) /* Signed 5 bit immediate. */
802 else if (CONST_OK_FOR_K (value
)) /* Signed 16 bit immediate. */
803 return "movea lo(%1),%.,%0";
805 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
806 return "movhi hi(%1),%.,%0";
808 /* A random constant. */
809 else if (TARGET_V850E
)
812 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
815 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
817 HOST_WIDE_INT high
, low
;
819 const_double_split (src
, &high
, &low
);
821 if (CONST_OK_FOR_J (high
)) /* Signed 5 bit immediate. */
824 else if (CONST_OK_FOR_K (high
)) /* Signed 16 bit immediate. */
825 return "movea lo(%F1),%.,%0";
827 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
828 return "movhi hi(%F1),%.,%0";
830 /* A random constant. */
831 else if (TARGET_V850E
)
835 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
838 else if (GET_CODE (src
) == MEM
)
839 return "%S1ld%W1 %1,%0";
841 else if (special_symbolref_operand (src
, VOIDmode
))
842 return "movea %O1(%P1),%Q1,%0";
844 else if (GET_CODE (src
) == LABEL_REF
845 || GET_CODE (src
) == SYMBOL_REF
846 || GET_CODE (src
) == CONST
)
849 return "mov hilo(%1),%0";
851 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
854 else if (GET_CODE (src
) == HIGH
)
855 return "movhi hi(%1),%.,%0";
857 else if (GET_CODE (src
) == LO_SUM
)
859 operands
[2] = XEXP (src
, 0);
860 operands
[3] = XEXP (src
, 1);
861 return "movea lo(%3),%2,%0";
865 else if (GET_CODE (dst
) == MEM
)
868 return "%S0st%W0 %1,%0";
870 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
871 return "%S0st%W0 %.,%0";
873 else if (GET_CODE (src
) == CONST_DOUBLE
874 && CONST0_RTX (GET_MODE (dst
)) == src
)
875 return "%S0st%W0 %.,%0";
878 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
883 /* Return appropriate code to load up an 8 byte integer or
884 floating point value */
887 output_move_double (rtx
* operands
)
889 enum machine_mode mode
= GET_MODE (operands
[0]);
890 rtx dst
= operands
[0];
891 rtx src
= operands
[1];
893 if (register_operand (dst
, mode
)
894 && register_operand (src
, mode
))
896 if (REGNO (src
) + 1 == REGNO (dst
))
897 return "mov %R1,%R0\n\tmov %1,%0";
899 return "mov %1,%0\n\tmov %R1,%R0";
903 if (GET_CODE (dst
) == MEM
904 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
905 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
906 return "st.w %.,%0\n\tst.w %.,%R0";
908 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
910 HOST_WIDE_INT high_low
[2];
914 if (GET_CODE (src
) == CONST_DOUBLE
)
915 const_double_split (src
, &high_low
[1], &high_low
[0]);
918 high_low
[0] = INTVAL (src
);
919 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
922 for (i
= 0; i
< 2; i
++)
924 xop
[0] = gen_rtx_REG (SImode
, REGNO (dst
)+i
);
925 xop
[1] = GEN_INT (high_low
[i
]);
926 output_asm_insn (output_move_single (xop
), xop
);
932 if (GET_CODE (src
) == MEM
)
935 int dreg
= REGNO (dst
);
936 rtx inside
= XEXP (src
, 0);
938 if (GET_CODE (inside
) == REG
)
939 ptrreg
= REGNO (inside
);
940 else if (GET_CODE (inside
) == SUBREG
)
941 ptrreg
= subreg_regno (inside
);
942 else if (GET_CODE (inside
) == PLUS
)
943 ptrreg
= REGNO (XEXP (inside
, 0));
944 else if (GET_CODE (inside
) == LO_SUM
)
945 ptrreg
= REGNO (XEXP (inside
, 0));
948 return "ld.w %R1,%R0\n\tld.w %1,%0";
951 if (GET_CODE (src
) == MEM
)
952 return "ld.w %1,%0\n\tld.w %R1,%R0";
954 if (GET_CODE (dst
) == MEM
)
955 return "st.w %1,%0\n\tst.w %R1,%R0";
957 return "mov %1,%0\n\tmov %R1,%R0";
961 /* Return maximum offset supported for a short EP memory reference of mode
962 MODE and signedness UNSIGNEDP. */
965 ep_memory_offset (enum machine_mode mode
, int unsignedp ATTRIBUTE_UNUSED
)
972 if (TARGET_SMALL_SLD
)
973 max_offset
= (1 << 4);
974 else if (TARGET_V850E
975 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
976 || (! unsignedp
&& TARGET_US_BIT_SET
)))
977 max_offset
= (1 << 4);
979 max_offset
= (1 << 7);
983 if (TARGET_SMALL_SLD
)
984 max_offset
= (1 << 5);
985 else if (TARGET_V850E
986 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
987 || (! unsignedp
&& TARGET_US_BIT_SET
)))
988 max_offset
= (1 << 5);
990 max_offset
= (1 << 8);
995 max_offset
= (1 << 8);
1005 /* Return true if OP is a valid short EP memory reference */
1008 ep_memory_operand (rtx op
, enum machine_mode mode
, int unsigned_load
)
1014 if (GET_CODE (op
) != MEM
)
1017 max_offset
= ep_memory_offset (mode
, unsigned_load
);
1019 mask
= GET_MODE_SIZE (mode
) - 1;
1021 addr
= XEXP (op
, 0);
1022 if (GET_CODE (addr
) == CONST
)
1023 addr
= XEXP (addr
, 0);
1025 switch (GET_CODE (addr
))
1031 return SYMBOL_REF_TDA_P (addr
);
1034 return REGNO (addr
) == EP_REGNUM
;
1037 op0
= XEXP (addr
, 0);
1038 op1
= XEXP (addr
, 1);
1039 if (GET_CODE (op1
) == CONST_INT
1040 && INTVAL (op1
) < max_offset
1041 && INTVAL (op1
) >= 0
1042 && (INTVAL (op1
) & mask
) == 0)
1044 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1047 if (GET_CODE (op0
) == SYMBOL_REF
&& SYMBOL_REF_TDA_P (op0
))
1056 /* Return true if OP is either a register or 0 */
1059 reg_or_0_operand (rtx op
, enum machine_mode mode
)
1061 if (GET_CODE (op
) == CONST_INT
)
1062 return INTVAL (op
) == 0;
1064 else if (GET_CODE (op
) == CONST_DOUBLE
)
1065 return CONST_DOUBLE_OK_FOR_G (op
);
1068 return register_operand (op
, mode
);
1071 /* Return true if OP is either a register or a signed five bit integer */
1074 reg_or_int5_operand (rtx op
, enum machine_mode mode
)
1076 if (GET_CODE (op
) == CONST_INT
)
1077 return CONST_OK_FOR_J (INTVAL (op
));
1080 return register_operand (op
, mode
);
1083 /* Return true if OP is either a register or a signed nine bit integer. */
1086 reg_or_int9_operand (rtx op
, enum machine_mode mode
)
1088 if (GET_CODE (op
) == CONST_INT
)
1089 return CONST_OK_FOR_O (INTVAL (op
));
1091 return register_operand (op
, mode
);
1094 /* Return true if OP is either a register or a const integer. */
1097 reg_or_const_operand (rtx op
, enum machine_mode mode
)
1099 if (GET_CODE (op
) == CONST_INT
)
1102 return register_operand (op
, mode
);
1105 /* Return true if OP is a valid call operand. */
1108 call_address_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1110 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1111 if (TARGET_LONG_CALLS
)
1112 return GET_CODE (op
) == REG
;
1113 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == REG
);
1117 special_symbolref_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1119 if (GET_CODE (op
) == CONST
1120 && GET_CODE (XEXP (op
, 0)) == PLUS
1121 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
1122 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op
, 0), 1))))
1123 op
= XEXP (XEXP (op
, 0), 0);
1125 if (GET_CODE (op
) == SYMBOL_REF
)
1126 return (SYMBOL_REF_FLAGS (op
)
1127 & (SYMBOL_FLAG_ZDA
| SYMBOL_FLAG_TDA
| SYMBOL_FLAG_SDA
)) != 0;
1133 movsi_source_operand (rtx op
, enum machine_mode mode
)
1135 /* Some constants, as well as symbolic operands
1136 must be done with HIGH & LO_SUM patterns. */
1138 && GET_CODE (op
) != HIGH
1139 && GET_CODE (op
) != CONSTANT_P_RTX
1140 && !(GET_CODE (op
) == CONST_INT
1141 && (CONST_OK_FOR_J (INTVAL (op
))
1142 || CONST_OK_FOR_K (INTVAL (op
))
1143 || CONST_OK_FOR_L (INTVAL (op
)))))
1144 return special_symbolref_operand (op
, mode
);
1146 return general_operand (op
, mode
);
1150 power_of_two_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1152 if (GET_CODE (op
) != CONST_INT
)
1155 if (exact_log2 (INTVAL (op
)) == -1)
1161 not_power_of_two_operand (rtx op
, enum machine_mode mode
)
1167 else if (mode
== HImode
)
1169 else if (mode
== SImode
)
1174 if (GET_CODE (op
) != CONST_INT
)
1177 if (exact_log2 (~INTVAL (op
) & mask
) == -1)
1183 /* Substitute memory references involving a pointer, to use the ep pointer,
1184 taking care to save and preserve the ep. */
1187 substitute_ep_register (rtx first_insn
,
1194 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1199 regs_ever_live
[1] = 1;
1200 *p_r1
= gen_rtx_REG (Pmode
, 1);
1201 *p_ep
= gen_rtx_REG (Pmode
, 30);
1206 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1207 2 * (uses
- 3), uses
, reg_names
[regno
],
1208 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1209 INSN_UID (first_insn
), INSN_UID (last_insn
));
1211 if (GET_CODE (first_insn
) == NOTE
)
1212 first_insn
= next_nonnote_insn (first_insn
);
1214 last_insn
= next_nonnote_insn (last_insn
);
1215 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1217 if (GET_CODE (insn
) == INSN
)
1219 rtx pattern
= single_set (insn
);
1221 /* Replace the memory references. */
1225 /* Memory operands are signed by default. */
1226 int unsignedp
= FALSE
;
1228 if (GET_CODE (SET_DEST (pattern
)) == MEM
1229 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1232 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1233 p_mem
= &SET_DEST (pattern
);
1235 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1236 p_mem
= &SET_SRC (pattern
);
1238 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1239 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1240 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1242 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1243 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1245 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1253 rtx addr
= XEXP (*p_mem
, 0);
1255 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1256 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1258 else if (GET_CODE (addr
) == PLUS
1259 && GET_CODE (XEXP (addr
, 0)) == REG
1260 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1261 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1262 && ((INTVAL (XEXP (addr
, 1)))
1263 < ep_memory_offset (GET_MODE (*p_mem
),
1265 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1266 *p_mem
= change_address (*p_mem
, VOIDmode
,
1267 gen_rtx_PLUS (Pmode
,
1275 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1276 insn
= prev_nonnote_insn (first_insn
);
1277 if (insn
&& GET_CODE (insn
) == INSN
1278 && GET_CODE (PATTERN (insn
)) == SET
1279 && SET_DEST (PATTERN (insn
)) == *p_ep
1280 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1283 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1285 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1286 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1290 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1291 the -mep mode to copy heavily used pointers to ep to use the implicit
1303 regs
[FIRST_PSEUDO_REGISTER
];
1312 /* If not ep mode, just return now. */
1316 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1319 regs
[i
].first_insn
= NULL_RTX
;
1320 regs
[i
].last_insn
= NULL_RTX
;
1323 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1325 switch (GET_CODE (insn
))
1327 /* End of basic block */
1334 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1336 if (max_uses
< regs
[i
].uses
)
1338 max_uses
= regs
[i
].uses
;
1344 substitute_ep_register (regs
[max_regno
].first_insn
,
1345 regs
[max_regno
].last_insn
,
1346 max_uses
, max_regno
, &r1
, &ep
);
1350 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1353 regs
[i
].first_insn
= NULL_RTX
;
1354 regs
[i
].last_insn
= NULL_RTX
;
1362 pattern
= single_set (insn
);
1364 /* See if there are any memory references we can shorten */
1367 rtx src
= SET_SRC (pattern
);
1368 rtx dest
= SET_DEST (pattern
);
1370 /* Memory operands are signed by default. */
1371 int unsignedp
= FALSE
;
1373 /* We might have (SUBREG (MEM)) here, so just get rid of the
1374 subregs to make this code simpler. */
1375 if (GET_CODE (dest
) == SUBREG
1376 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1377 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1378 alter_subreg (&dest
);
1379 if (GET_CODE (src
) == SUBREG
1380 && (GET_CODE (SUBREG_REG (src
)) == MEM
1381 || GET_CODE (SUBREG_REG (src
)) == REG
))
1382 alter_subreg (&src
);
1384 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1387 else if (GET_CODE (dest
) == MEM
)
1390 else if (GET_CODE (src
) == MEM
)
1393 else if (GET_CODE (src
) == SIGN_EXTEND
1394 && GET_CODE (XEXP (src
, 0)) == MEM
)
1395 mem
= XEXP (src
, 0);
1397 else if (GET_CODE (src
) == ZERO_EXTEND
1398 && GET_CODE (XEXP (src
, 0)) == MEM
)
1400 mem
= XEXP (src
, 0);
1406 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1409 else if (!use_ep
&& mem
1410 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1412 rtx addr
= XEXP (mem
, 0);
1416 if (GET_CODE (addr
) == REG
)
1419 regno
= REGNO (addr
);
1422 else if (GET_CODE (addr
) == PLUS
1423 && GET_CODE (XEXP (addr
, 0)) == REG
1424 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1425 && ((INTVAL (XEXP (addr
, 1)))
1426 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1427 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1430 regno
= REGNO (XEXP (addr
, 0));
1439 regs
[regno
].last_insn
= insn
;
1440 if (!regs
[regno
].first_insn
)
1441 regs
[regno
].first_insn
= insn
;
1445 /* Loading up a register in the basic block zaps any savings
1447 if (GET_CODE (dest
) == REG
)
1449 enum machine_mode mode
= GET_MODE (dest
);
1453 regno
= REGNO (dest
);
1454 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1458 /* See if we can use the pointer before this
1463 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1465 if (max_uses
< regs
[i
].uses
)
1467 max_uses
= regs
[i
].uses
;
1473 && max_regno
>= regno
1474 && max_regno
< endregno
)
1476 substitute_ep_register (regs
[max_regno
].first_insn
,
1477 regs
[max_regno
].last_insn
,
1478 max_uses
, max_regno
, &r1
,
1481 /* Since we made a substitution, zap all remembered
1483 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1486 regs
[i
].first_insn
= NULL_RTX
;
1487 regs
[i
].last_insn
= NULL_RTX
;
1492 for (i
= regno
; i
< endregno
; i
++)
1495 regs
[i
].first_insn
= NULL_RTX
;
1496 regs
[i
].last_insn
= NULL_RTX
;
1505 /* # of registers saved by the interrupt handler. */
1506 #define INTERRUPT_FIXED_NUM 4
1508 /* # of bytes for registers saved by the interrupt handler. */
1509 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1511 /* # of registers saved in register parameter area. */
1512 #define INTERRUPT_REGPARM_NUM 4
1513 /* # of words saved for other registers. */
1514 #define INTERRUPT_ALL_SAVE_NUM \
1515 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1517 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1520 compute_register_save_size (long * p_reg_saved
)
1524 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1525 int call_p
= regs_ever_live
[LINK_POINTER_REGNUM
];
1528 /* Count the return pointer if we need to save it. */
1529 if (current_function_profile
&& !call_p
)
1530 regs_ever_live
[LINK_POINTER_REGNUM
] = call_p
= 1;
1532 /* Count space for the register saves. */
1533 if (interrupt_handler
)
1535 for (i
= 0; i
<= 31; i
++)
1539 if (regs_ever_live
[i
] || call_p
)
1542 reg_saved
|= 1L << i
;
1546 /* We don't save/restore r0 or the stack pointer */
1548 case STACK_POINTER_REGNUM
:
1551 /* For registers with fixed use, we save them, set them to the
1552 appropriate value, and then restore them.
1553 These registers are handled specially, so don't list them
1554 on the list of registers to save in the prologue. */
1555 case 1: /* temp used to hold ep */
1557 case 10: /* temp used to call interrupt save/restore */
1558 case EP_REGNUM
: /* ep */
1565 /* Find the first register that needs to be saved. */
1566 for (i
= 0; i
<= 31; i
++)
1567 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1568 || i
== LINK_POINTER_REGNUM
))
1571 /* If it is possible that an out-of-line helper function might be
1572 used to generate the prologue for the current function, then we
1573 need to cover the possibility that such a helper function will
1574 be used, despite the fact that there might be gaps in the list of
1575 registers that need to be saved. To detect this we note that the
1576 helper functions always push at least register r29 (provided
1577 that the function is not an interrupt handler). */
1579 if (TARGET_PROLOG_FUNCTION
1580 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1585 reg_saved
|= 1L << i
;
1590 /* Helper functions save all registers between the starting
1591 register and the last register, regardless of whether they
1592 are actually used by the function or not. */
1593 for (; i
<= 29; i
++)
1596 reg_saved
|= 1L << i
;
1599 if (regs_ever_live
[LINK_POINTER_REGNUM
])
1602 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1607 for (; i
<= 31; i
++)
1608 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1609 || i
== LINK_POINTER_REGNUM
))
1612 reg_saved
|= 1L << i
;
1618 *p_reg_saved
= reg_saved
;
1624 compute_frame_size (int size
, long * p_reg_saved
)
1627 + compute_register_save_size (p_reg_saved
)
1628 + current_function_outgoing_args_size
);
1633 expand_prologue (void)
1637 unsigned int size
= get_frame_size ();
1638 unsigned int actual_fsize
;
1639 unsigned int init_stack_alloc
= 0;
1642 unsigned int num_save
;
1643 unsigned int default_stack
;
1645 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1648 actual_fsize
= compute_frame_size (size
, ®_saved
);
1650 /* Save/setup global registers for interrupt functions right now. */
1651 if (interrupt_handler
)
1653 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1654 emit_insn (gen_callt_save_interrupt ());
1656 emit_insn (gen_save_interrupt ());
1658 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1660 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1661 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1664 /* Save arg registers to the stack if necessary. */
1665 else if (current_function_args_info
.anonymous_args
)
1667 if (TARGET_PROLOG_FUNCTION
&& TARGET_V850E
&& !TARGET_DISABLE_CALLT
)
1668 emit_insn (gen_save_r6_r9_v850e ());
1669 else if (TARGET_PROLOG_FUNCTION
&& ! TARGET_LONG_CALLS
)
1670 emit_insn (gen_save_r6_r9 ());
1674 for (i
= 6; i
< 10; i
++)
1676 emit_move_insn (gen_rtx_MEM (SImode
,
1677 plus_constant (stack_pointer_rtx
,
1679 gen_rtx_REG (SImode
, i
));
1685 /* Identify all of the saved registers. */
1688 for (i
= 1; i
< 31; i
++)
1690 if (((1L << i
) & reg_saved
) != 0)
1691 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1694 /* If the return pointer is saved, the helper functions also allocate
1695 16 bytes of stack for arguments to be saved in. */
1696 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1698 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1702 /* See if we have an insn that allocates stack space and saves the particular
1703 registers we want to. */
1704 save_all
= NULL_RTX
;
1705 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1707 int alloc_stack
= (4 * num_save
) + default_stack
;
1708 int unalloc_stack
= actual_fsize
- alloc_stack
;
1709 int save_func_len
= 4;
1710 int save_normal_len
;
1713 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1715 /* see if we would have used ep to save the stack */
1716 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1717 save_normal_len
= (3 * 2) + (2 * num_save
);
1719 save_normal_len
= 4 * num_save
;
1721 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1723 /* Don't bother checking if we don't actually save any space.
1724 This happens for instance if one register is saved and additional
1725 stack space is allocated. */
1726 if (save_func_len
< save_normal_len
)
1728 save_all
= gen_rtx_PARALLEL
1730 rtvec_alloc (num_save
+ 1
1731 + (TARGET_V850
? (TARGET_LONG_CALLS
? 2 : 1) : 0)));
1733 XVECEXP (save_all
, 0, 0)
1734 = gen_rtx_SET (VOIDmode
,
1736 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1738 offset
= - default_stack
;
1739 for (i
= 0; i
< num_save
; i
++)
1741 XVECEXP (save_all
, 0, i
+1)
1742 = gen_rtx_SET (VOIDmode
,
1744 plus_constant (stack_pointer_rtx
,
1752 XVECEXP (save_all
, 0, num_save
+ 1)
1753 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1755 if (TARGET_LONG_CALLS
)
1756 XVECEXP (save_all
, 0, num_save
+ 2)
1757 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 11));
1760 code
= recog (save_all
, NULL_RTX
, NULL
);
1763 rtx insn
= emit_insn (save_all
);
1764 INSN_CODE (insn
) = code
;
1765 actual_fsize
-= alloc_stack
;
1769 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1770 save_normal_len
- save_func_len
,
1771 save_normal_len
, save_func_len
,
1772 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1775 save_all
= NULL_RTX
;
1779 /* If no prolog save function is available, store the registers the old
1780 fashioned way (one by one). */
1783 /* Special case interrupt functions that save all registers for a call. */
1784 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1786 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1787 emit_insn (gen_callt_save_all_interrupt ());
1789 emit_insn (gen_save_all_interrupt ());
1793 /* If the stack is too big, allocate it in chunks so we can do the
1794 register saves. We use the register save size so we use the ep
1796 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1797 init_stack_alloc
= compute_register_save_size (NULL
);
1799 init_stack_alloc
= actual_fsize
;
1801 /* Save registers at the beginning of the stack frame. */
1802 offset
= init_stack_alloc
- 4;
1804 if (init_stack_alloc
)
1805 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1807 GEN_INT (-init_stack_alloc
)));
1809 /* Save the return pointer first. */
1810 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1812 emit_move_insn (gen_rtx_MEM (SImode
,
1813 plus_constant (stack_pointer_rtx
,
1815 save_regs
[--num_save
]);
1819 for (i
= 0; i
< num_save
; i
++)
1821 emit_move_insn (gen_rtx_MEM (SImode
,
1822 plus_constant (stack_pointer_rtx
,
1830 /* Allocate the rest of the stack that was not allocated above (either it is
1831 > 32K or we just called a function to save the registers and needed more
1833 if (actual_fsize
> init_stack_alloc
)
1835 int diff
= actual_fsize
- init_stack_alloc
;
1836 if (CONST_OK_FOR_K (diff
))
1837 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1842 rtx reg
= gen_rtx_REG (Pmode
, 12);
1843 emit_move_insn (reg
, GEN_INT (-diff
));
1844 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1848 /* If we need a frame pointer, set it up now. */
1849 if (frame_pointer_needed
)
1850 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1855 expand_epilogue (void)
1859 unsigned int size
= get_frame_size ();
1861 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1862 unsigned int init_stack_free
= 0;
1863 rtx restore_regs
[32];
1865 unsigned int num_restore
;
1866 unsigned int default_stack
;
1868 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1870 /* Eliminate the initial stack stored by interrupt functions. */
1871 if (interrupt_handler
)
1873 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1874 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1875 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1878 /* Cut off any dynamic stack created. */
1879 if (frame_pointer_needed
)
1880 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1882 /* Identify all of the saved registers. */
1885 for (i
= 1; i
< 31; i
++)
1887 if (((1L << i
) & reg_saved
) != 0)
1888 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1891 /* If the return pointer is saved, the helper functions also allocate
1892 16 bytes of stack for arguments to be saved in. */
1893 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1895 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1899 /* See if we have an insn that restores the particular registers we
1901 restore_all
= NULL_RTX
;
1903 if (TARGET_PROLOG_FUNCTION
1905 && actual_fsize
>= default_stack
1906 && !interrupt_handler
)
1908 int alloc_stack
= (4 * num_restore
) + default_stack
;
1909 int unalloc_stack
= actual_fsize
- alloc_stack
;
1910 int restore_func_len
= 4;
1911 int restore_normal_len
;
1914 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1916 /* See if we would have used ep to restore the registers. */
1917 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1918 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1920 restore_normal_len
= 4 * num_restore
;
1922 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1924 /* Don't bother checking if we don't actually save any space. */
1925 if (restore_func_len
< restore_normal_len
)
1927 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1928 rtvec_alloc (num_restore
+ 2));
1929 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1930 XVECEXP (restore_all
, 0, 1)
1931 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1932 gen_rtx_PLUS (Pmode
,
1934 GEN_INT (alloc_stack
)));
1936 offset
= alloc_stack
- 4;
1937 for (i
= 0; i
< num_restore
; i
++)
1939 XVECEXP (restore_all
, 0, i
+2)
1940 = gen_rtx_SET (VOIDmode
,
1943 plus_constant (stack_pointer_rtx
,
1948 code
= recog (restore_all
, NULL_RTX
, NULL
);
1954 actual_fsize
-= alloc_stack
;
1957 if (CONST_OK_FOR_K (actual_fsize
))
1958 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1960 GEN_INT (actual_fsize
)));
1963 rtx reg
= gen_rtx_REG (Pmode
, 12);
1964 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1965 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1971 insn
= emit_jump_insn (restore_all
);
1972 INSN_CODE (insn
) = code
;
1976 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1977 restore_normal_len
- restore_func_len
,
1978 restore_normal_len
, restore_func_len
,
1979 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1982 restore_all
= NULL_RTX
;
1986 /* If no epilog save function is available, restore the registers the
1987 old fashioned way (one by one). */
1990 /* If the stack is large, we need to cut it down in 2 pieces. */
1991 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1992 init_stack_free
= 4 * num_restore
;
1994 init_stack_free
= actual_fsize
;
1996 /* Deallocate the rest of the stack if it is > 32K. */
1997 if (actual_fsize
> init_stack_free
)
2001 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
2003 if (CONST_OK_FOR_K (diff
))
2004 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2009 rtx reg
= gen_rtx_REG (Pmode
, 12);
2010 emit_move_insn (reg
, GEN_INT (diff
));
2011 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2017 /* Special case interrupt functions that save all registers
2019 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
2021 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2022 emit_insn (gen_callt_restore_all_interrupt ());
2024 emit_insn (gen_restore_all_interrupt ());
2028 /* Restore registers from the beginning of the stack frame. */
2029 offset
= init_stack_free
- 4;
2031 /* Restore the return pointer first. */
2033 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
2035 emit_move_insn (restore_regs
[--num_restore
],
2036 gen_rtx_MEM (SImode
,
2037 plus_constant (stack_pointer_rtx
,
2042 for (i
= 0; i
< num_restore
; i
++)
2044 emit_move_insn (restore_regs
[i
],
2045 gen_rtx_MEM (SImode
,
2046 plus_constant (stack_pointer_rtx
,
2049 emit_insn (gen_rtx_USE (VOIDmode
, restore_regs
[i
]));
2053 /* Cut back the remainder of the stack. */
2054 if (init_stack_free
)
2055 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2057 GEN_INT (init_stack_free
)));
2060 /* And return or use reti for interrupt handlers. */
2061 if (interrupt_handler
)
2063 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2064 emit_insn (gen_callt_return_interrupt ());
2066 emit_jump_insn (gen_return_interrupt ());
2068 else if (actual_fsize
)
2069 emit_jump_insn (gen_return_internal ());
2071 emit_jump_insn (gen_return ());
2074 v850_interrupt_cache_p
= FALSE
;
2075 v850_interrupt_p
= FALSE
;
2079 /* Update the condition code from the insn. */
2082 notice_update_cc (rtx body
, rtx insn
)
2084 switch (get_attr_cc (insn
))
2087 /* Insn does not affect CC at all. */
2091 /* Insn does not change CC, but the 0'th operand has been changed. */
2092 if (cc_status
.value1
!= 0
2093 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2094 cc_status
.value1
= 0;
2098 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2099 V,C is in an unusable state. */
2101 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2102 cc_status
.value1
= recog_data
.operand
[0];
2106 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2107 C is in an unusable state. */
2109 cc_status
.flags
|= CC_NO_CARRY
;
2110 cc_status
.value1
= recog_data
.operand
[0];
2114 /* The insn is a compare instruction. */
2116 cc_status
.value1
= SET_SRC (body
);
2120 /* Insn doesn't leave CC in a usable state. */
2126 /* Retrieve the data area that has been chosen for the given decl. */
2129 v850_get_data_area (tree decl
)
2131 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2132 return DATA_AREA_SDA
;
2134 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2135 return DATA_AREA_TDA
;
2137 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2138 return DATA_AREA_ZDA
;
2140 return DATA_AREA_NORMAL
;
2143 /* Store the indicated data area in the decl's attributes. */
2146 v850_set_data_area (tree decl
, v850_data_area data_area
)
2152 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2153 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2154 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2159 DECL_ATTRIBUTES (decl
) = tree_cons
2160 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2163 const struct attribute_spec v850_attribute_table
[] =
2165 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2166 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2167 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2168 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2169 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2170 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2171 { NULL
, 0, 0, false, false, false, NULL
}
2174 /* Handle an "interrupt" attribute; arguments as in
2175 struct attribute_spec.handler. */
2177 v850_handle_interrupt_attribute (tree
* node
,
2179 tree args ATTRIBUTE_UNUSED
,
2180 int flags ATTRIBUTE_UNUSED
,
2181 bool * no_add_attrs
)
2183 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2185 warning ("`%s' attribute only applies to functions",
2186 IDENTIFIER_POINTER (name
));
2187 *no_add_attrs
= true;
2193 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2194 struct attribute_spec.handler. */
2196 v850_handle_data_area_attribute (tree
* node
,
2198 tree args ATTRIBUTE_UNUSED
,
2199 int flags ATTRIBUTE_UNUSED
,
2200 bool * no_add_attrs
)
2202 v850_data_area data_area
;
2203 v850_data_area area
;
2206 /* Implement data area attribute. */
2207 if (is_attribute_p ("sda", name
))
2208 data_area
= DATA_AREA_SDA
;
2209 else if (is_attribute_p ("tda", name
))
2210 data_area
= DATA_AREA_TDA
;
2211 else if (is_attribute_p ("zda", name
))
2212 data_area
= DATA_AREA_ZDA
;
2216 switch (TREE_CODE (decl
))
2219 if (current_function_decl
!= NULL_TREE
)
2221 error ("%Jdata area attributes cannot be specified for "
2222 "local variables", decl
, decl
);
2223 *no_add_attrs
= true;
2229 area
= v850_get_data_area (decl
);
2230 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2232 error ("%Jdata area of '%D' conflicts with previous declaration",
2234 *no_add_attrs
= true;
2246 /* Return nonzero if FUNC is an interrupt function as specified
2247 by the "interrupt" attribute. */
2250 v850_interrupt_function_p (tree func
)
2255 if (v850_interrupt_cache_p
)
2256 return v850_interrupt_p
;
2258 if (TREE_CODE (func
) != FUNCTION_DECL
)
2261 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2267 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2268 ret
= a
!= NULL_TREE
;
2271 /* Its not safe to trust global variables until after function inlining has
2273 if (reload_completed
| reload_in_progress
)
2274 v850_interrupt_p
= ret
;
2281 v850_encode_data_area (tree decl
, rtx symbol
)
2285 /* Map explicit sections into the appropriate attribute */
2286 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2288 if (DECL_SECTION_NAME (decl
))
2290 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2292 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2293 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2295 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2296 v850_set_data_area (decl
, DATA_AREA_SDA
);
2298 else if (streq (name
, ".tdata"))
2299 v850_set_data_area (decl
, DATA_AREA_TDA
);
2302 /* If no attribute, support -m{zda,sda,tda}=n */
2305 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2309 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2310 v850_set_data_area (decl
, DATA_AREA_TDA
);
2312 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2313 v850_set_data_area (decl
, DATA_AREA_SDA
);
2315 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2316 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2319 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2323 flags
= SYMBOL_REF_FLAGS (symbol
);
2324 switch (v850_get_data_area (decl
))
2326 case DATA_AREA_ZDA
: flags
|= SYMBOL_FLAG_ZDA
; break;
2327 case DATA_AREA_TDA
: flags
|= SYMBOL_FLAG_TDA
; break;
2328 case DATA_AREA_SDA
: flags
|= SYMBOL_FLAG_SDA
; break;
2331 SYMBOL_REF_FLAGS (symbol
) = flags
;
2335 v850_encode_section_info (tree decl
, rtx rtl
, int first
)
2337 default_encode_section_info (decl
, rtl
, first
);
2339 if (TREE_CODE (decl
) == VAR_DECL
2340 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2341 v850_encode_data_area (decl
, XEXP (rtl
, 0));
2344 /* Return true if the given RTX is a register which can be restored
2345 by a function epilogue. */
2347 register_is_ok_for_epilogue (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2349 /* The save/restore routines can only cope with registers 20 - 31. */
2350 return ((GET_CODE (op
) == REG
)
2351 && (((REGNO (op
) >= 20) && REGNO (op
) <= 31)));
2354 /* Return nonzero if the given RTX is suitable for collapsing into
2355 jump to a function epilogue. */
2357 pattern_is_ok_for_epilogue (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2359 int count
= XVECLEN (op
, 0);
2362 /* If there are no registers to restore then the function epilogue
2367 /* The pattern matching has already established that we are performing a
2368 function epilogue and that we are popping at least one register. We must
2369 now check the remaining entries in the vector to make sure that they are
2370 also register pops. There is no good reason why there should ever be
2371 anything else in this vector, but being paranoid always helps...
2373 The test below performs the C equivalent of this machine description
2376 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2377 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2380 for (i
= 3; i
< count
; i
++)
2382 rtx vector_element
= XVECEXP (op
, 0, i
);
2387 if (GET_CODE (vector_element
) != SET
)
2390 dest
= SET_DEST (vector_element
);
2391 src
= SET_SRC (vector_element
);
2393 if (GET_CODE (dest
) != REG
2394 || GET_MODE (dest
) != SImode
2395 || ! register_is_ok_for_epilogue (dest
, SImode
)
2396 || GET_CODE (src
) != MEM
2397 || GET_MODE (src
) != SImode
)
2400 plus
= XEXP (src
, 0);
2402 if (GET_CODE (plus
) != PLUS
2403 || GET_CODE (XEXP (plus
, 0)) != REG
2404 || GET_MODE (XEXP (plus
, 0)) != SImode
2405 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2406 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2413 /* Construct a JR instruction to a routine that will perform the equivalent of
2414 the RTL passed in as an argument. This RTL is a function epilogue that
2415 pops registers off the stack and possibly releases some extra stack space
2416 as well. The code has already verified that the RTL matches these
2419 construct_restore_jr (rtx op
)
2421 int count
= XVECLEN (op
, 0);
2423 unsigned long int mask
;
2424 unsigned long int first
;
2425 unsigned long int last
;
2427 static char buff
[100]; /* XXX */
2431 error ("bogus JR construction: %d\n", count
);
2435 /* Work out how many bytes to pop off the stack before retrieving
2437 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2439 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2441 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2444 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2446 /* Each pop will remove 4 bytes from the stack.... */
2447 stack_bytes
-= (count
- 2) * 4;
2449 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2450 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2452 error ("bad amount of stack space removal: %d", stack_bytes
);
2456 /* Now compute the bit mask of registers to push. */
2458 for (i
= 2; i
< count
; i
++)
2460 rtx vector_element
= XVECEXP (op
, 0, i
);
2462 if (GET_CODE (vector_element
) != SET
)
2464 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2466 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
2469 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2472 /* Scan for the first register to pop. */
2473 for (first
= 0; first
< 32; first
++)
2475 if (mask
& (1 << first
))
2482 /* Discover the last register to pop. */
2483 if (mask
& (1 << LINK_POINTER_REGNUM
))
2485 if (stack_bytes
!= 16)
2488 last
= LINK_POINTER_REGNUM
;
2492 if (stack_bytes
!= 0)
2495 if ((mask
& (1 << 29)) == 0)
2501 /* Note, it is possible to have gaps in the register mask.
2502 We ignore this here, and generate a JR anyway. We will
2503 be popping more registers than is strictly necessary, but
2504 it does save code space. */
2506 if (TARGET_LONG_CALLS
)
2511 sprintf (name
, "__return_%s", reg_names
[first
]);
2513 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2515 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2521 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2523 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2530 /* Return nonzero if the given RTX is suitable for collapsing into
2531 a jump to a function prologue. */
2533 pattern_is_ok_for_prologue (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2535 int count
= XVECLEN (op
, 0);
2539 /* If there are no registers to save then the function prologue
2544 /* The pattern matching has already established that we are adjusting the
2545 stack and pushing at least one register. We must now check that the
2546 remaining entries in the vector to make sure that they are also register
2547 pushes, except for the last entry which should be a CLOBBER of r10.
2549 The test below performs the C equivalent of this machine description
2552 (set (mem:SI (plus:SI (reg:SI 3)
2553 (match_operand:SI 2 "immediate_operand" "i")))
2554 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2558 for (i
= 2; i
< count
- (TARGET_LONG_CALLS
? 2: 1); i
++)
2564 vector_element
= XVECEXP (op
, 0, i
);
2566 if (GET_CODE (vector_element
) != SET
)
2569 dest
= SET_DEST (vector_element
);
2570 src
= SET_SRC (vector_element
);
2572 if (GET_CODE (dest
) != MEM
2573 || GET_MODE (dest
) != SImode
2574 || GET_CODE (src
) != REG
2575 || GET_MODE (src
) != SImode
2576 || ! register_is_ok_for_epilogue (src
, SImode
))
2579 plus
= XEXP (dest
, 0);
2581 if ( GET_CODE (plus
) != PLUS
2582 || GET_CODE (XEXP (plus
, 0)) != REG
2583 || GET_MODE (XEXP (plus
, 0)) != SImode
2584 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2585 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2588 /* If the register is being pushed somewhere other than the stack
2589 space just acquired by the first operand then abandon this quest.
2590 Note: the test is <= because both values are negative. */
2591 if (INTVAL (XEXP (plus
, 1))
2592 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
2598 /* Make sure that the last entries in the vector are clobbers. */
2599 for (; i
< count
; i
++)
2601 vector_element
= XVECEXP (op
, 0, i
);
2603 if (GET_CODE (vector_element
) != CLOBBER
2604 || GET_CODE (XEXP (vector_element
, 0)) != REG
2605 || !(REGNO (XEXP (vector_element
, 0)) == 10
2606 || (TARGET_LONG_CALLS
? (REGNO (XEXP (vector_element
, 0)) == 11) : 0 )))
2613 /* Construct a JARL instruction to a routine that will perform the equivalent
2614 of the RTL passed as a parameter. This RTL is a function prologue that
2615 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2616 some stack space as well. The code has already verified that the RTL
2617 matches these requirements. */
2619 construct_save_jarl (rtx op
)
2621 int count
= XVECLEN (op
, 0);
2623 unsigned long int mask
;
2624 unsigned long int first
;
2625 unsigned long int last
;
2627 static char buff
[100]; /* XXX */
2631 error ("bogus JARL construction: %d\n", count
);
2636 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2638 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2640 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) != REG
)
2642 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2645 /* Work out how many bytes to push onto the stack after storing the
2647 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2649 /* Each push will put 4 bytes from the stack.... */
2650 stack_bytes
+= (count
- (TARGET_LONG_CALLS
? 3 : 2)) * 4;
2652 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2653 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2655 error ("bad amount of stack space removal: %d", stack_bytes
);
2659 /* Now compute the bit mask of registers to push. */
2661 for (i
= 1; i
< count
- (TARGET_LONG_CALLS
? 2 : 1); i
++)
2663 rtx vector_element
= XVECEXP (op
, 0, i
);
2665 if (GET_CODE (vector_element
) != SET
)
2667 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2669 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2672 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2675 /* Scan for the first register to push. */
2676 for (first
= 0; first
< 32; first
++)
2678 if (mask
& (1 << first
))
2685 /* Discover the last register to push. */
2686 if (mask
& (1 << LINK_POINTER_REGNUM
))
2688 if (stack_bytes
!= -16)
2691 last
= LINK_POINTER_REGNUM
;
2695 if (stack_bytes
!= 0)
2697 if ((mask
& (1 << 29)) == 0)
2703 /* Note, it is possible to have gaps in the register mask.
2704 We ignore this here, and generate a JARL anyway. We will
2705 be pushing more registers than is strictly necessary, but
2706 it does save code space. */
2708 if (TARGET_LONG_CALLS
)
2713 sprintf (name
, "__save_%s", reg_names
[first
]);
2715 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2717 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2723 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2725 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2732 extern tree last_assemble_variable_decl
;
2733 extern int size_directive_output
;
2735 /* A version of asm_output_aligned_bss() that copes with the special
2736 data areas of the v850. */
2738 v850_output_aligned_bss (FILE * file
,
2744 switch (v850_get_data_area (decl
))
2762 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2763 #ifdef ASM_DECLARE_OBJECT_NAME
2764 last_assemble_variable_decl
= decl
;
2765 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2767 /* Standard thing is just output label for the object. */
2768 ASM_OUTPUT_LABEL (file
, name
);
2769 #endif /* ASM_DECLARE_OBJECT_NAME */
2770 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2773 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2775 v850_output_common (FILE * file
,
2781 if (decl
== NULL_TREE
)
2783 fprintf (file
, "%s", COMMON_ASM_OP
);
2787 switch (v850_get_data_area (decl
))
2790 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2794 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2798 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2802 fprintf (file
, "%s", COMMON_ASM_OP
);
2807 assemble_name (file
, name
);
2808 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2811 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2813 v850_output_local (FILE * file
,
2819 fprintf (file
, "%s", LOCAL_ASM_OP
);
2820 assemble_name (file
, name
);
2821 fprintf (file
, "\n");
2823 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2826 /* Add data area to the given declaration if a ghs data area pragma is
2827 currently in effect (#pragma ghs startXXX/endXXX). */
2829 v850_insert_attributes (tree decl
, tree
* attr_ptr ATTRIBUTE_UNUSED
)
2832 && data_area_stack
->data_area
2833 && current_function_decl
== NULL_TREE
2834 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2835 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2836 v850_set_data_area (decl
, data_area_stack
->data_area
);
2838 /* Initialize the default names of the v850 specific sections,
2839 if this has not been done before. */
2841 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2843 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2844 = build_string (sizeof (".sdata")-1, ".sdata");
2846 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2847 = build_string (sizeof (".rosdata")-1, ".rosdata");
2849 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2850 = build_string (sizeof (".tdata")-1, ".tdata");
2852 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2853 = build_string (sizeof (".zdata")-1, ".zdata");
2855 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2856 = build_string (sizeof (".rozdata")-1, ".rozdata");
2859 if (current_function_decl
== NULL_TREE
2860 && (TREE_CODE (decl
) == VAR_DECL
2861 || TREE_CODE (decl
) == CONST_DECL
2862 || TREE_CODE (decl
) == FUNCTION_DECL
)
2863 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2864 && !DECL_SECTION_NAME (decl
))
2866 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2867 tree chosen_section
;
2869 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2870 kind
= GHS_SECTION_KIND_TEXT
;
2873 /* First choose a section kind based on the data area of the decl. */
2874 switch (v850_get_data_area (decl
))
2880 kind
= ((TREE_READONLY (decl
))
2881 ? GHS_SECTION_KIND_ROSDATA
2882 : GHS_SECTION_KIND_SDATA
);
2886 kind
= GHS_SECTION_KIND_TDATA
;
2890 kind
= ((TREE_READONLY (decl
))
2891 ? GHS_SECTION_KIND_ROZDATA
2892 : GHS_SECTION_KIND_ZDATA
);
2895 case DATA_AREA_NORMAL
: /* default data area */
2896 if (TREE_READONLY (decl
))
2897 kind
= GHS_SECTION_KIND_RODATA
;
2898 else if (DECL_INITIAL (decl
))
2899 kind
= GHS_SECTION_KIND_DATA
;
2901 kind
= GHS_SECTION_KIND_BSS
;
2905 /* Now, if the section kind has been explicitly renamed,
2906 then attach a section attribute. */
2907 chosen_section
= GHS_current_section_names
[(int) kind
];
2909 /* Otherwise, if this kind of section needs an explicit section
2910 attribute, then also attach one. */
2911 if (chosen_section
== NULL
)
2912 chosen_section
= GHS_default_section_names
[(int) kind
];
2916 /* Only set the section name if specified by a pragma, because
2917 otherwise it will force those variables to get allocated storage
2918 in this module, rather than by the linker. */
2919 DECL_SECTION_NAME (decl
) = chosen_section
;
2924 /* Return nonzero if the given RTX is suitable
2925 for collapsing into a DISPOSE instruction. */
2928 pattern_is_ok_for_dispose (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2930 int count
= XVECLEN (op
, 0);
2933 /* If there are no registers to restore then
2934 the dispose instruction is not suitable. */
2938 /* The pattern matching has already established that we are performing a
2939 function epilogue and that we are popping at least one register. We must
2940 now check the remaining entries in the vector to make sure that they are
2941 also register pops. There is no good reason why there should ever be
2942 anything else in this vector, but being paranoid always helps...
2944 The test below performs the C equivalent of this machine description
2947 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2948 (mem:SI (plus:SI (reg:SI 3)
2949 (match_operand:SI n "immediate_operand" "i"))))
2952 for (i
= 3; i
< count
; i
++)
2954 rtx vector_element
= XVECEXP (op
, 0, i
);
2959 if (GET_CODE (vector_element
) != SET
)
2962 dest
= SET_DEST (vector_element
);
2963 src
= SET_SRC (vector_element
);
2965 if ( GET_CODE (dest
) != REG
2966 || GET_MODE (dest
) != SImode
2967 || ! register_is_ok_for_epilogue (dest
, SImode
)
2968 || GET_CODE (src
) != MEM
2969 || GET_MODE (src
) != SImode
)
2972 plus
= XEXP (src
, 0);
2974 if ( GET_CODE (plus
) != PLUS
2975 || GET_CODE (XEXP (plus
, 0)) != REG
2976 || GET_MODE (XEXP (plus
, 0)) != SImode
2977 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2978 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2985 /* Construct a DISPOSE instruction that is the equivalent of
2986 the given RTX. We have already verified that this should
2990 construct_dispose_instruction (rtx op
)
2992 int count
= XVECLEN (op
, 0);
2994 unsigned long int mask
;
2996 static char buff
[ 100 ]; /* XXX */
3001 error ("Bogus DISPOSE construction: %d\n", count
);
3005 /* Work out how many bytes to pop off the
3006 stack before retrieving registers. */
3007 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
3009 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
3011 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
3014 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
3016 /* Each pop will remove 4 bytes from the stack.... */
3017 stack_bytes
-= (count
- 2) * 4;
3019 /* Make sure that the amount we are popping
3020 will fit into the DISPOSE instruction. */
3021 if (stack_bytes
> 128)
3023 error ("Too much stack space to dispose of: %d", stack_bytes
);
3027 /* Now compute the bit mask of registers to push. */
3030 for (i
= 2; i
< count
; i
++)
3032 rtx vector_element
= XVECEXP (op
, 0, i
);
3034 if (GET_CODE (vector_element
) != SET
)
3036 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
3038 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
3041 if (REGNO (SET_DEST (vector_element
)) == 2)
3044 mask
|= 1 << REGNO (SET_DEST (vector_element
));
3047 if (! TARGET_DISABLE_CALLT
3048 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
3052 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
3057 for (i
= 20; i
< 32; i
++)
3058 if (mask
& (1 << i
))
3062 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
3064 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
3065 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3070 static char regs
[100]; /* XXX */
3073 /* Generate the DISPOSE instruction. Note we could just issue the
3074 bit mask as a number as the assembler can cope with this, but for
3075 the sake of our readers we turn it into a textual description. */
3079 for (i
= 20; i
< 32; i
++)
3081 if (mask
& (1 << i
))
3086 strcat (regs
, ", ");
3091 strcat (regs
, reg_names
[ first
]);
3093 for (i
++; i
< 32; i
++)
3094 if ((mask
& (1 << i
)) == 0)
3099 strcat (regs
, " - ");
3100 strcat (regs
, reg_names
[ i
- 1 ] );
3105 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
3111 /* Return nonzero if the given RTX is suitable
3112 for collapsing into a PREPARE instruction. */
3115 pattern_is_ok_for_prepare (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
3117 int count
= XVECLEN (op
, 0);
3120 /* If there are no registers to restore then the prepare instruction
3125 /* The pattern matching has already established that we are adjusting the
3126 stack and pushing at least one register. We must now check that the
3127 remaining entries in the vector to make sure that they are also register
3130 The test below performs the C equivalent of this machine description
3133 (set (mem:SI (plus:SI (reg:SI 3)
3134 (match_operand:SI 2 "immediate_operand" "i")))
3135 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3139 for (i
= 2; i
< count
; i
++)
3141 rtx vector_element
= XVECEXP (op
, 0, i
);
3146 if (GET_CODE (vector_element
) != SET
)
3149 dest
= SET_DEST (vector_element
);
3150 src
= SET_SRC (vector_element
);
3152 if ( GET_CODE (dest
) != MEM
3153 || GET_MODE (dest
) != SImode
3154 || GET_CODE (src
) != REG
3155 || GET_MODE (src
) != SImode
3156 || ! register_is_ok_for_epilogue (src
, SImode
)
3160 plus
= XEXP (dest
, 0);
3162 if ( GET_CODE (plus
) != PLUS
3163 || GET_CODE (XEXP (plus
, 0)) != REG
3164 || GET_MODE (XEXP (plus
, 0)) != SImode
3165 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3166 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3169 /* If the register is being pushed somewhere other than the stack
3170 space just acquired by the first operand then abandon this quest.
3171 Note: the test is <= because both values are negative. */
3172 if (INTVAL (XEXP (plus
, 1))
3173 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
3180 /* Construct a PREPARE instruction that is the equivalent of
3181 the given RTL. We have already verified that this should
3185 construct_prepare_instruction (rtx op
)
3187 int count
= XVECLEN (op
, 0);
3189 unsigned long int mask
;
3191 static char buff
[ 100 ]; /* XXX */
3196 error ("Bogus PREPEARE construction: %d\n", count
);
3200 /* Work out how many bytes to push onto
3201 the stack after storing the registers. */
3202 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
3204 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
3206 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
3209 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
3211 /* Each push will put 4 bytes from the stack. */
3212 stack_bytes
+= (count
- 1) * 4;
3214 /* Make sure that the amount we are popping
3215 will fit into the DISPOSE instruction. */
3216 if (stack_bytes
< -128)
3218 error ("Too much stack space to prepare: %d", stack_bytes
);
3222 /* Now compute the bit mask of registers to push. */
3224 for (i
= 1; i
< count
; i
++)
3226 rtx vector_element
= XVECEXP (op
, 0, i
);
3228 if (GET_CODE (vector_element
) != SET
)
3230 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
3232 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
3235 if (REGNO (SET_SRC (vector_element
)) == 2)
3238 mask
|= 1 << REGNO (SET_SRC (vector_element
));
3241 if ((! TARGET_DISABLE_CALLT
)
3242 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
3246 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
3250 for (i
= 20; i
< 32; i
++)
3251 if (mask
& (1 << i
))
3255 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
3257 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
3258 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3262 static char regs
[100]; /* XXX */
3266 /* Generate the PREPARE instruction. Note we could just issue the
3267 bit mask as a number as the assembler can cope with this, but for
3268 the sake of our readers we turn it into a textual description. */
3272 for (i
= 20; i
< 32; i
++)
3274 if (mask
& (1 << i
))
3279 strcat (regs
, ", ");
3284 strcat (regs
, reg_names
[ first
]);
3286 for (i
++; i
< 32; i
++)
3287 if ((mask
& (1 << i
)) == 0)
3292 strcat (regs
, " - ");
3293 strcat (regs
, reg_names
[ i
- 1 ] );
3298 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
3304 /* Implement `va_arg'. */
3307 v850_va_arg (tree valist
, tree type
)
3309 HOST_WIDE_INT size
, rsize
;
3314 /* Round up sizeof(type) to a word. */
3315 size
= int_size_in_bytes (type
);
3316 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
3321 size
= rsize
= UNITS_PER_WORD
;
3325 addr
= save_expr (valist
);
3326 incr
= fold (build (PLUS_EXPR
, ptr_type_node
, addr
,
3327 build_int_2 (rsize
, 0)));
3329 incr
= build (MODIFY_EXPR
, ptr_type_node
, valist
, incr
);
3330 TREE_SIDE_EFFECTS (incr
) = 1;
3331 expand_expr (incr
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3333 addr_rtx
= expand_expr (addr
, NULL
, Pmode
, EXPAND_NORMAL
);
3337 addr_rtx
= force_reg (Pmode
, addr_rtx
);
3338 addr_rtx
= gen_rtx_MEM (Pmode
, addr_rtx
);
3339 set_mem_alias_set (addr_rtx
, get_varargs_alias_set ());
3345 /* Return an RTX indicating where the return address to the
3346 calling function can be found. */
3349 v850_return_addr (int count
)
3354 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
3358 v850_select_section (tree exp
,
3359 int reloc ATTRIBUTE_UNUSED
,
3360 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
3362 if (TREE_CODE (exp
) == VAR_DECL
)
3365 if (!TREE_READONLY (exp
)
3366 || TREE_SIDE_EFFECTS (exp
)
3367 || !DECL_INITIAL (exp
)
3368 || (DECL_INITIAL (exp
) != error_mark_node
3369 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
3374 switch (v850_get_data_area (exp
))
3396 readonly_data_section ();
3403 readonly_data_section ();
3406 /* Worker function for TARGET_RETURN_IN_MEMORY. */
3409 v850_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
3411 /* Return values > 8 bytes in length in memory. */
3412 return int_size_in_bytes (type
) > 8 || TYPE_MODE (type
) == BLKmode
;
3415 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3418 v850_setup_incoming_varargs (CUMULATIVE_ARGS
*ca
,
3419 enum machine_mode mode ATTRIBUTE_UNUSED
,
3420 tree type ATTRIBUTE_UNUSED
,
3421 int *pretend_arg_size ATTRIBUTE_UNUSED
,
3422 int second_time ATTRIBUTE_UNUSED
)
3424 ca
->anonymous_args
= (!TARGET_GHS
? 1 : 0);