1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC 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 GNU CC 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 GNU CC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
33 #include "insn-attr.h"
40 #include "integrate.h"
43 #include "target-def.h"
46 #define streq(a,b) (strcmp (a, b) == 0)
49 /* Function prototypes for stupid compilers: */
50 static void const_double_split
PARAMS ((rtx
, HOST_WIDE_INT
*, HOST_WIDE_INT
*));
51 static int const_costs_int
PARAMS ((HOST_WIDE_INT
, int));
52 static void substitute_ep_register
PARAMS ((rtx
, rtx
, int, int, rtx
*, rtx
*));
53 static int ep_memory_offset
PARAMS ((enum machine_mode
, int));
54 static void v850_set_data_area
PARAMS ((tree
, v850_data_area
));
55 const struct attribute_spec v850_attribute_table
[];
56 static tree v850_handle_interrupt_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
57 static tree v850_handle_data_area_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
58 static void v850_insert_attributes
PARAMS ((tree
, tree
*));
59 static void v850_select_section
PARAMS ((tree
, int, unsigned HOST_WIDE_INT
));
60 static void v850_encode_data_area
PARAMS ((tree
));
61 static void v850_encode_section_info
PARAMS ((tree
, int));
62 static const char *v850_strip_name_encoding
PARAMS ((const char *));
64 /* True if the current function has anonymous arguments. */
65 int current_function_anonymous_args
;
67 /* Information about the various small memory areas. */
68 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
70 /* name value max physical max */
71 { "tda", (char *)0, 0, 256 },
72 { "sda", (char *)0, 0, 65536 },
73 { "zda", (char *)0, 0, 32768 },
76 /* Names of the various data areas used on the v850. */
77 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
78 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
80 /* Track the current data area set by the data area pragma (which
81 can be nested). Tested by check_default_data_area. */
82 data_area_stack_element
* data_area_stack
= NULL
;
84 /* True if we don't need to check any more if the current
85 function is an interrupt handler. */
86 static int v850_interrupt_cache_p
= FALSE
;
88 /* Whether current function is an interrupt handler. */
89 static int v850_interrupt_p
= FALSE
;
91 /* Initialize the GCC target structure. */
92 #undef TARGET_ASM_ALIGNED_HI_OP
93 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
95 #undef TARGET_ATTRIBUTE_TABLE
96 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
98 #undef TARGET_INSERT_ATTRIBUTES
99 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
101 #undef TARGET_ASM_SELECT_SECTION
102 #define TARGET_ASM_SELECT_SECTION v850_select_section
104 #undef TARGET_ENCODE_SECTION_INFO
105 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
106 #undef TARGET_STRIP_NAME_ENCODING
107 #define TARGET_STRIP_NAME_ENCODING v850_strip_name_encoding
109 struct gcc_target targetm
= TARGET_INITIALIZER
;
111 /* Sometimes certain combinations of command options do not make
112 sense on a particular target machine. You can define a macro
113 `OVERRIDE_OPTIONS' to take account of this. This macro, if
114 defined, is executed once just after all the command options have
117 Don't use this macro to turn on various extra optimizations for
118 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
124 extern int atoi
PARAMS ((const char *));
126 /* Parse -m{s,t,z}da=nnn switches */
127 for (i
= 0; i
< (int)SMALL_MEMORY_max
; i
++)
129 if (small_memory
[i
].value
)
131 if (!ISDIGIT (*small_memory
[i
].value
))
132 error ("%s=%s is not numeric",
133 small_memory
[i
].name
,
134 small_memory
[i
].value
);
137 small_memory
[i
].max
= atoi (small_memory
[i
].value
);
138 if (small_memory
[i
].max
> small_memory
[i
].physical_max
)
139 error ("%s=%s is too large",
140 small_memory
[i
].name
,
141 small_memory
[i
].value
);
146 /* Make sure that the US_BIT_SET mask has been correctly initialised. */
147 if ((target_flags
& MASK_US_MASK_SET
) == 0)
149 target_flags
|= MASK_US_MASK_SET
;
150 target_flags
&= ~MASK_US_BIT_SET
;
155 /* Output assembly code for the start of the file. */
158 asm_file_start (file
)
161 output_file_directive (file
, main_input_filename
);
165 /* Return an RTX to represent where a value with mode MODE will be returned
166 from a function. If the result is 0, the argument is pushed. */
169 function_arg (cum
, mode
, type
, named
)
170 CUMULATIVE_ARGS
*cum
;
171 enum machine_mode mode
;
178 if (TARGET_GHS
&& !named
)
182 size
= int_size_in_bytes (type
);
184 size
= GET_MODE_SIZE (mode
);
190 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
194 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
196 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
199 if (type
== NULL_TREE
200 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
203 switch (cum
->nbytes
/ UNITS_PER_WORD
)
206 result
= gen_rtx_REG (mode
, 6);
209 result
= gen_rtx_REG (mode
, 7);
212 result
= gen_rtx_REG (mode
, 8);
215 result
= gen_rtx_REG (mode
, 9);
225 /* Return the number of words which must be put into registers
226 for values which are part in registers and part in memory. */
229 function_arg_partial_nregs (cum
, mode
, type
, named
)
230 CUMULATIVE_ARGS
*cum
;
231 enum machine_mode mode
;
237 if (TARGET_GHS
&& !named
)
241 size
= int_size_in_bytes (type
);
243 size
= GET_MODE_SIZE (mode
);
246 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
250 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
252 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
255 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
258 if (type
== NULL_TREE
259 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
262 return (4 * UNITS_PER_WORD
- cum
->nbytes
) / UNITS_PER_WORD
;
266 /* Return the high and low words of a CONST_DOUBLE */
269 const_double_split (x
, p_high
, p_low
)
271 HOST_WIDE_INT
*p_high
;
272 HOST_WIDE_INT
*p_low
;
274 if (GET_CODE (x
) == CONST_DOUBLE
)
279 switch (GET_MODE (x
))
282 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
283 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
284 *p_high
= t
[1]; /* since v850 is little endian */
285 *p_low
= t
[0]; /* high is second word */
289 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
290 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
296 *p_high
= CONST_DOUBLE_HIGH (x
);
297 *p_low
= CONST_DOUBLE_LOW (x
);
305 fatal_insn ("const_double_split got a bad insn:", x
);
309 /* Return the cost of the rtx R with code CODE. */
312 const_costs_int (value
, zero_cost
)
316 if (CONST_OK_FOR_I (value
))
318 else if (CONST_OK_FOR_J (value
))
320 else if (CONST_OK_FOR_K (value
))
331 HOST_WIDE_INT high
, low
;
336 return const_costs_int (INTVAL (r
), 0);
339 const_double_split (r
, &high
, &low
);
340 if (GET_MODE (r
) == SFmode
)
341 return const_costs_int (high
, 1);
343 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
359 /* Print operand X using operand code CODE to assembly language output file
363 print_operand (file
, x
, code
)
368 HOST_WIDE_INT high
, low
;
373 /* We use 'c' operands with symbols for .vtinherit */
374 if (GET_CODE (x
) == SYMBOL_REF
)
376 output_addr_const(file
, x
);
383 switch ((code
== 'B' || code
== 'C')
384 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
387 if (code
== 'c' || code
== 'C')
388 fprintf (file
, "nz");
390 fprintf (file
, "ne");
393 if (code
== 'c' || code
== 'C')
399 fprintf (file
, "ge");
402 fprintf (file
, "gt");
405 fprintf (file
, "le");
408 fprintf (file
, "lt");
411 fprintf (file
, "nl");
417 fprintf (file
, "nh");
426 case 'F': /* high word of CONST_DOUBLE */
427 if (GET_CODE (x
) == CONST_INT
)
428 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
429 else if (GET_CODE (x
) == CONST_DOUBLE
)
431 const_double_split (x
, &high
, &low
);
432 fprintf (file
, "%ld", (long) high
);
437 case 'G': /* low word of CONST_DOUBLE */
438 if (GET_CODE (x
) == CONST_INT
)
439 fprintf (file
, "%ld", (long) INTVAL (x
));
440 else if (GET_CODE (x
) == CONST_DOUBLE
)
442 const_double_split (x
, &high
, &low
);
443 fprintf (file
, "%ld", (long) low
);
449 fprintf (file
, "%d\n", INTVAL (x
) & 0xffff);
452 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
455 if (special_symbolref_operand (x
, VOIDmode
))
459 if (GET_CODE (x
) == SYMBOL_REF
)
461 else if (GET_CODE (x
) == CONST
)
462 name
= XSTR (XEXP (XEXP (x
, 0), 0), 0);
466 if (ZDA_NAME_P (name
))
467 fprintf (file
, "zdaoff");
468 else if (SDA_NAME_P (name
))
469 fprintf (file
, "sdaoff");
470 else if (TDA_NAME_P (name
))
471 fprintf (file
, "tdaoff");
479 if (special_symbolref_operand (x
, VOIDmode
))
480 output_addr_const (file
, x
);
485 if (special_symbolref_operand (x
, VOIDmode
))
489 if (GET_CODE (x
) == SYMBOL_REF
)
491 else if (GET_CODE (x
) == CONST
)
492 name
= XSTR (XEXP (XEXP (x
, 0), 0), 0);
496 if (ZDA_NAME_P (name
))
497 fprintf (file
, "r0");
498 else if (SDA_NAME_P (name
))
499 fprintf (file
, "gp");
500 else if (TDA_NAME_P (name
))
501 fprintf (file
, "ep");
508 case 'R': /* 2nd word of a double. */
509 switch (GET_CODE (x
))
512 fprintf (file
, reg_names
[REGNO (x
) + 1]);
515 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
516 print_operand_address (file
, x
);
517 if (GET_CODE (x
) == CONST_INT
)
518 fprintf (file
, "[r0]");
527 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
528 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
535 /* Like an 'S' operand above, but for unsigned loads only. */
536 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
541 case 'W': /* print the instruction suffix */
542 switch (GET_MODE (x
))
547 case QImode
: fputs (".b", file
); break;
548 case HImode
: fputs (".h", file
); break;
549 case SImode
: fputs (".w", file
); break;
550 case SFmode
: fputs (".w", file
); break;
553 case '.': /* register r0 */
554 fputs (reg_names
[0], file
);
556 case 'z': /* reg or zero */
558 fputs (reg_names
[0], file
);
559 else if (GET_CODE (x
) == REG
)
560 fputs (reg_names
[REGNO (x
)], file
);
565 switch (GET_CODE (x
))
568 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
569 output_address (gen_rtx_PLUS (SImode
, gen_rtx (REG
, SImode
, 0),
572 output_address (XEXP (x
, 0));
576 fputs (reg_names
[REGNO (x
)], file
);
579 fputs (reg_names
[subreg_regno (x
)], file
);
586 print_operand_address (file
, x
);
597 /* Output assembly language output for the address ADDR to FILE. */
600 print_operand_address (file
, addr
)
604 switch (GET_CODE (addr
))
607 fprintf (file
, "0[");
608 print_operand (file
, addr
, 0);
612 if (GET_CODE (XEXP (addr
, 0)) == REG
)
615 fprintf (file
, "lo(");
616 print_operand (file
, XEXP (addr
, 1), 0);
617 fprintf (file
, ")[");
618 print_operand (file
, XEXP (addr
, 0), 0);
623 if (GET_CODE (XEXP (addr
, 0)) == REG
624 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
627 print_operand (file
, XEXP (addr
, 1), 0);
629 print_operand (file
, XEXP (addr
, 0), 0);
634 print_operand (file
, XEXP (addr
, 0), 0);
636 print_operand (file
, XEXP (addr
, 1), 0);
640 if (ENCODED_NAME_P (XSTR (addr
, 0)))
642 const char *name
= XSTR (addr
, 0);
643 const char *off_name
;
644 const char *reg_name
;
646 if (ZDA_NAME_P (name
))
651 else if (SDA_NAME_P (name
))
656 else if (TDA_NAME_P (name
))
664 fprintf (file
, "%s(", off_name
);
665 output_addr_const (file
, addr
);
666 fprintf (file
, ")[%s]", reg_name
);
669 output_addr_const (file
, addr
);
672 if (special_symbolref_operand (addr
, VOIDmode
))
674 const char *name
= XSTR (XEXP (XEXP (addr
, 0), 0), 0);
675 const char *off_name
;
676 const char *reg_name
;
678 if (ZDA_NAME_P (name
))
683 else if (SDA_NAME_P (name
))
688 else if (TDA_NAME_P (name
))
696 fprintf (file
, "%s(", off_name
);
697 output_addr_const (file
, addr
);
698 fprintf (file
, ")[%s]", reg_name
);
701 output_addr_const (file
, addr
);
704 output_addr_const (file
, addr
);
709 /* When assemble_integer is used to emit the offsets for a switch
710 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
711 output_addr_const will normally barf at this, but it is OK to omit
712 the truncate and just emit the difference of the two labels. The
713 .hword directive will automatically handle the truncation for us.
715 Returns 1 if rtx was handled, 0 otherwise. */
718 v850_output_addr_const_extra (file
, x
)
722 if (GET_CODE (x
) != TRUNCATE
)
727 /* We must also handle the case where the switch table was passed a
728 constant value and so has been collapsed. In this case the first
729 label will have been deleted. In such a case it is OK to emit
730 nothing, since the table will not be used.
731 (cf gcc.c-torture/compile/990801-1.c). */
732 if (GET_CODE (x
) == MINUS
733 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
734 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
735 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
738 output_addr_const (file
, x
);
742 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
746 output_move_single (operands
)
749 rtx dst
= operands
[0];
750 rtx src
= operands
[1];
757 else if (GET_CODE (src
) == CONST_INT
)
759 HOST_WIDE_INT value
= INTVAL (src
);
761 if (CONST_OK_FOR_J (value
)) /* Signed 5 bit immediate. */
764 else if (CONST_OK_FOR_K (value
)) /* Signed 16 bit immediate. */
765 return "movea lo(%1),%.,%0";
767 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
768 return "movhi hi(%1),%.,%0";
770 /* A random constant. */
771 else if (TARGET_V850E
)
774 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
777 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
779 HOST_WIDE_INT high
, low
;
781 const_double_split (src
, &high
, &low
);
783 if (CONST_OK_FOR_J (high
)) /* Signed 5 bit immediate. */
786 else if (CONST_OK_FOR_K (high
)) /* Signed 16 bit immediate. */
787 return "movea lo(%F1),%.,%0";
789 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
790 return "movhi hi(%F1),%.,%0";
792 /* A random constant. */
793 else if (TARGET_V850E
)
797 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
800 else if (GET_CODE (src
) == MEM
)
801 return "%S1ld%W1 %1,%0";
803 else if (special_symbolref_operand (src
, VOIDmode
))
804 return "movea %O1(%P1),%Q1,%0";
806 else if (GET_CODE (src
) == LABEL_REF
807 || GET_CODE (src
) == SYMBOL_REF
808 || GET_CODE (src
) == CONST
)
811 return "mov hilo(%1),%0";
813 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
816 else if (GET_CODE (src
) == HIGH
)
817 return "movhi hi(%1),%.,%0";
819 else if (GET_CODE (src
) == LO_SUM
)
821 operands
[2] = XEXP (src
, 0);
822 operands
[3] = XEXP (src
, 1);
823 return "movea lo(%3),%2,%0";
827 else if (GET_CODE (dst
) == MEM
)
830 return "%S0st%W0 %1,%0";
832 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
833 return "%S0st%W0 %.,%0";
835 else if (GET_CODE (src
) == CONST_DOUBLE
836 && CONST0_RTX (GET_MODE (dst
)) == src
)
837 return "%S0st%W0 %.,%0";
840 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
845 /* Return appropriate code to load up an 8 byte integer or
846 floating point value */
849 output_move_double (operands
)
852 enum machine_mode mode
= GET_MODE (operands
[0]);
853 rtx dst
= operands
[0];
854 rtx src
= operands
[1];
856 if (register_operand (dst
, mode
)
857 && register_operand (src
, mode
))
859 if (REGNO (src
) + 1 == REGNO (dst
))
860 return "mov %R1,%R0\n\tmov %1,%0";
862 return "mov %1,%0\n\tmov %R1,%R0";
866 if (GET_CODE (dst
) == MEM
867 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
868 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
869 return "st.w %.,%0\n\tst.w %.,%R0";
871 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
873 HOST_WIDE_INT high_low
[2];
877 if (GET_CODE (src
) == CONST_DOUBLE
)
878 const_double_split (src
, &high_low
[1], &high_low
[0]);
881 high_low
[0] = INTVAL (src
);
882 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
885 for (i
= 0; i
< 2; i
++)
887 xop
[0] = gen_rtx_REG (SImode
, REGNO (dst
)+i
);
888 xop
[1] = GEN_INT (high_low
[i
]);
889 output_asm_insn (output_move_single (xop
), xop
);
895 if (GET_CODE (src
) == MEM
)
898 int dreg
= REGNO (dst
);
899 rtx inside
= XEXP (src
, 0);
901 if (GET_CODE (inside
) == REG
)
902 ptrreg
= REGNO (inside
);
903 else if (GET_CODE (inside
) == SUBREG
)
904 ptrreg
= subreg_regno (inside
);
905 else if (GET_CODE (inside
) == PLUS
)
906 ptrreg
= REGNO (XEXP (inside
, 0));
907 else if (GET_CODE (inside
) == LO_SUM
)
908 ptrreg
= REGNO (XEXP (inside
, 0));
911 return "ld.w %R1,%R0\n\tld.w %1,%0";
914 if (GET_CODE (src
) == MEM
)
915 return "ld.w %1,%0\n\tld.w %R1,%R0";
917 if (GET_CODE (dst
) == MEM
)
918 return "st.w %1,%0\n\tst.w %R1,%R0";
920 return "mov %1,%0\n\tmov %R1,%R0";
924 /* Return maximum offset supported for a short EP memory reference of mode
925 MODE and signedness UNSIGNEDP. */
928 ep_memory_offset (mode
, unsignedp
)
929 enum machine_mode mode
;
930 int ATTRIBUTE_UNUSED unsignedp
;
937 if (TARGET_SMALL_SLD
)
938 max_offset
= (1 << 4);
939 else if (TARGET_V850E
940 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
941 || (! unsignedp
&& TARGET_US_BIT_SET
)))
942 max_offset
= (1 << 4);
944 max_offset
= (1 << 7);
948 if (TARGET_SMALL_SLD
)
949 max_offset
= (1 << 5);
950 else if (TARGET_V850E
951 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
952 || (! unsignedp
&& TARGET_US_BIT_SET
)))
953 max_offset
= (1 << 5);
955 max_offset
= (1 << 8);
960 max_offset
= (1 << 8);
970 /* Return true if OP is a valid short EP memory reference */
973 ep_memory_operand (op
, mode
, unsigned_load
)
975 enum machine_mode mode
;
982 if (GET_CODE (op
) != MEM
)
985 max_offset
= ep_memory_offset (mode
, unsigned_load
);
987 mask
= GET_MODE_SIZE (mode
) - 1;
990 if (GET_CODE (addr
) == CONST
)
991 addr
= XEXP (addr
, 0);
993 switch (GET_CODE (addr
))
999 return TDA_NAME_P (XSTR (addr
, 0));
1002 return REGNO (addr
) == EP_REGNUM
;
1005 op0
= XEXP (addr
, 0);
1006 op1
= XEXP (addr
, 1);
1007 if (GET_CODE (op1
) == CONST_INT
1008 && INTVAL (op1
) < max_offset
1009 && INTVAL (op1
) >= 0
1010 && (INTVAL (op1
) & mask
) == 0)
1012 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1015 if (GET_CODE (op0
) == SYMBOL_REF
&& TDA_NAME_P (XSTR (op0
, 0)))
1024 /* Return true if OP is either a register or 0 */
1027 reg_or_0_operand (op
, mode
)
1029 enum machine_mode mode
;
1031 if (GET_CODE (op
) == CONST_INT
)
1032 return INTVAL (op
) == 0;
1034 else if (GET_CODE (op
) == CONST_DOUBLE
)
1035 return CONST_DOUBLE_OK_FOR_G (op
);
1038 return register_operand (op
, mode
);
1041 /* Return true if OP is either a register or a signed five bit integer */
1044 reg_or_int5_operand (op
, mode
)
1046 enum machine_mode mode
;
1048 if (GET_CODE (op
) == CONST_INT
)
1049 return CONST_OK_FOR_J (INTVAL (op
));
1052 return register_operand (op
, mode
);
1055 /* Return true if OP is either a register or a signed nine bit integer. */
1058 reg_or_int9_operand (op
, mode
)
1060 enum machine_mode mode
;
1062 if (GET_CODE (op
) == CONST_INT
)
1063 return CONST_OK_FOR_O (INTVAL (op
));
1065 return register_operand (op
, mode
);
1068 /* Return true if OP is either a register or a const integer. */
1071 reg_or_const_operand (op
, mode
)
1073 enum machine_mode mode
;
1075 if (GET_CODE (op
) == CONST_INT
)
1078 return register_operand (op
, mode
);
1081 /* Return true if OP is a valid call operand. */
1084 call_address_operand (op
, mode
)
1086 enum machine_mode ATTRIBUTE_UNUSED mode
;
1088 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1089 if (TARGET_LONG_CALLS
)
1090 return GET_CODE (op
) == REG
;
1091 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == REG
);
1095 special_symbolref_operand (op
, mode
)
1097 enum machine_mode ATTRIBUTE_UNUSED mode
;
1099 if (GET_CODE (op
) == SYMBOL_REF
)
1100 return ENCODED_NAME_P (XSTR (op
, 0));
1102 else if (GET_CODE (op
) == CONST
)
1103 return (GET_CODE (XEXP (op
, 0)) == PLUS
1104 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
1105 && ENCODED_NAME_P (XSTR (XEXP (XEXP (op
, 0), 0), 0))
1106 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
1107 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op
, 0), 1))));
1113 movsi_source_operand (op
, mode
)
1115 enum machine_mode mode
;
1117 /* Some constants, as well as symbolic operands
1118 must be done with HIGH & LO_SUM patterns. */
1120 && GET_CODE (op
) != HIGH
1121 && GET_CODE (op
) != CONSTANT_P_RTX
1122 && !(GET_CODE (op
) == CONST_INT
1123 && (CONST_OK_FOR_J (INTVAL (op
))
1124 || CONST_OK_FOR_K (INTVAL (op
))
1125 || CONST_OK_FOR_L (INTVAL (op
)))))
1126 return special_symbolref_operand (op
, mode
);
1128 return general_operand (op
, mode
);
1132 power_of_two_operand (op
, mode
)
1134 enum machine_mode ATTRIBUTE_UNUSED mode
;
1136 if (GET_CODE (op
) != CONST_INT
)
1139 if (exact_log2 (INTVAL (op
)) == -1)
1145 not_power_of_two_operand (op
, mode
)
1147 enum machine_mode mode
;
1153 else if (mode
== HImode
)
1155 else if (mode
== SImode
)
1160 if (GET_CODE (op
) != CONST_INT
)
1163 if (exact_log2 (~INTVAL (op
) & mask
) == -1)
1169 /* Substitute memory references involving a pointer, to use the ep pointer,
1170 taking care to save and preserve the ep. */
1173 substitute_ep_register (first_insn
, last_insn
, uses
, regno
, p_r1
, p_ep
)
1181 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1186 regs_ever_live
[1] = 1;
1187 *p_r1
= gen_rtx_REG (Pmode
, 1);
1188 *p_ep
= gen_rtx_REG (Pmode
, 30);
1193 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1194 2 * (uses
- 3), uses
, reg_names
[regno
],
1195 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1196 INSN_UID (first_insn
), INSN_UID (last_insn
));
1198 if (GET_CODE (first_insn
) == NOTE
)
1199 first_insn
= next_nonnote_insn (first_insn
);
1201 last_insn
= next_nonnote_insn (last_insn
);
1202 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1204 if (GET_CODE (insn
) == INSN
)
1206 rtx pattern
= single_set (insn
);
1208 /* Replace the memory references. */
1212 /* Memory operands are signed by default. */
1213 int unsignedp
= FALSE
;
1215 if (GET_CODE (SET_DEST (pattern
)) == MEM
1216 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1219 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1220 p_mem
= &SET_DEST (pattern
);
1222 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1223 p_mem
= &SET_SRC (pattern
);
1225 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1226 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1227 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1229 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1230 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1232 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1240 rtx addr
= XEXP (*p_mem
, 0);
1242 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1243 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1245 else if (GET_CODE (addr
) == PLUS
1246 && GET_CODE (XEXP (addr
, 0)) == REG
1247 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1248 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1249 && ((INTVAL (XEXP (addr
, 1)))
1250 < ep_memory_offset (GET_MODE (*p_mem
),
1252 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1253 *p_mem
= change_address (*p_mem
, VOIDmode
,
1254 gen_rtx_PLUS (Pmode
,
1262 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1263 insn
= prev_nonnote_insn (first_insn
);
1264 if (insn
&& GET_CODE (insn
) == INSN
1265 && GET_CODE (PATTERN (insn
)) == SET
1266 && SET_DEST (PATTERN (insn
)) == *p_ep
1267 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1270 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1272 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1273 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1277 /* In rare cases, correct code generation requires extra machine
1278 dependent processing between the second jump optimization pass and
1279 delayed branch scheduling. On those machines, define this macro
1280 as a C statement to act on the code starting at INSN.
1282 On the 850, we use it to implement the -mep mode to copy heavily used
1283 pointers to ep to use the implicit addressing. */
1285 void v850_reorg (start_insn
)
1294 regs
[FIRST_PSEUDO_REGISTER
];
1303 /* If not ep mode, just return now. */
1307 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1310 regs
[i
].first_insn
= NULL_RTX
;
1311 regs
[i
].last_insn
= NULL_RTX
;
1314 for (insn
= start_insn
; insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1316 switch (GET_CODE (insn
))
1318 /* End of basic block */
1325 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1327 if (max_uses
< regs
[i
].uses
)
1329 max_uses
= regs
[i
].uses
;
1335 substitute_ep_register (regs
[max_regno
].first_insn
,
1336 regs
[max_regno
].last_insn
,
1337 max_uses
, max_regno
, &r1
, &ep
);
1341 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1344 regs
[i
].first_insn
= NULL_RTX
;
1345 regs
[i
].last_insn
= NULL_RTX
;
1353 pattern
= single_set (insn
);
1355 /* See if there are any memory references we can shorten */
1358 rtx src
= SET_SRC (pattern
);
1359 rtx dest
= SET_DEST (pattern
);
1361 /* Memory operands are signed by default. */
1362 int unsignedp
= FALSE
;
1364 /* We might have (SUBREG (MEM)) here, so just get rid of the
1365 subregs to make this code simpler. */
1366 if (GET_CODE (dest
) == SUBREG
1367 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1368 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1369 alter_subreg (&dest
);
1370 if (GET_CODE (src
) == SUBREG
1371 && (GET_CODE (SUBREG_REG (src
)) == MEM
1372 || GET_CODE (SUBREG_REG (src
)) == REG
))
1373 alter_subreg (&src
);
1375 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1378 else if (GET_CODE (dest
) == MEM
)
1381 else if (GET_CODE (src
) == MEM
)
1384 else if (GET_CODE (src
) == SIGN_EXTEND
1385 && GET_CODE (XEXP (src
, 0)) == MEM
)
1386 mem
= XEXP (src
, 0);
1388 else if (GET_CODE (src
) == ZERO_EXTEND
1389 && GET_CODE (XEXP (src
, 0)) == MEM
)
1391 mem
= XEXP (src
, 0);
1397 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1400 else if (!use_ep
&& mem
1401 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1403 rtx addr
= XEXP (mem
, 0);
1407 if (GET_CODE (addr
) == REG
)
1410 regno
= REGNO (addr
);
1413 else if (GET_CODE (addr
) == PLUS
1414 && GET_CODE (XEXP (addr
, 0)) == REG
1415 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1416 && ((INTVAL (XEXP (addr
, 1)))
1417 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1418 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1421 regno
= REGNO (XEXP (addr
, 0));
1430 regs
[regno
].last_insn
= insn
;
1431 if (!regs
[regno
].first_insn
)
1432 regs
[regno
].first_insn
= insn
;
1436 /* Loading up a register in the basic block zaps any savings
1438 if (GET_CODE (dest
) == REG
)
1440 enum machine_mode mode
= GET_MODE (dest
);
1444 regno
= REGNO (dest
);
1445 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1449 /* See if we can use the pointer before this
1454 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1456 if (max_uses
< regs
[i
].uses
)
1458 max_uses
= regs
[i
].uses
;
1464 && max_regno
>= regno
1465 && max_regno
< endregno
)
1467 substitute_ep_register (regs
[max_regno
].first_insn
,
1468 regs
[max_regno
].last_insn
,
1469 max_uses
, max_regno
, &r1
,
1472 /* Since we made a substitution, zap all remembered
1474 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1477 regs
[i
].first_insn
= NULL_RTX
;
1478 regs
[i
].last_insn
= NULL_RTX
;
1483 for (i
= regno
; i
< endregno
; i
++)
1486 regs
[i
].first_insn
= NULL_RTX
;
1487 regs
[i
].last_insn
= NULL_RTX
;
1496 /* # of registers saved by the interrupt handler. */
1497 #define INTERRUPT_FIXED_NUM 4
1499 /* # of bytes for registers saved by the interrupt handler. */
1500 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1502 /* # of registers saved in register parameter area. */
1503 #define INTERRUPT_REGPARM_NUM 4
1504 /* # of words saved for other registers. */
1505 #define INTERRUPT_ALL_SAVE_NUM \
1506 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1508 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1511 compute_register_save_size (p_reg_saved
)
1516 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1517 int call_p
= regs_ever_live
[LINK_POINTER_REGNUM
];
1520 /* Count the return pointer if we need to save it. */
1521 if (current_function_profile
&& !call_p
)
1522 regs_ever_live
[LINK_POINTER_REGNUM
] = call_p
= 1;
1524 /* Count space for the register saves. */
1525 if (interrupt_handler
)
1527 for (i
= 0; i
<= 31; i
++)
1531 if (regs_ever_live
[i
] || call_p
)
1534 reg_saved
|= 1L << i
;
1538 /* We don't save/restore r0 or the stack pointer */
1540 case STACK_POINTER_REGNUM
:
1543 /* For registers with fixed use, we save them, set them to the
1544 appropriate value, and then restore them.
1545 These registers are handled specially, so don't list them
1546 on the list of registers to save in the prologue. */
1547 case 1: /* temp used to hold ep */
1549 case 10: /* temp used to call interrupt save/restore */
1550 case EP_REGNUM
: /* ep */
1557 /* Find the first register that needs to be saved. */
1558 for (i
= 0; i
<= 31; i
++)
1559 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1560 || i
== LINK_POINTER_REGNUM
))
1563 /* If it is possible that an out-of-line helper function might be
1564 used to generate the prologue for the current function, then we
1565 need to cover the possibility that such a helper function will
1566 be used, despite the fact that there might be gaps in the list of
1567 registers that need to be saved. To detect this we note that the
1568 helper functions always push at least register r29 (provided
1569 that the function is not an interrupt handler). */
1571 if (TARGET_PROLOG_FUNCTION
1572 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1577 reg_saved
|= 1L << i
;
1582 /* Helper functions save all registers between the starting
1583 register and the last register, regardless of whether they
1584 are actually used by the function or not. */
1585 for (; i
<= 29; i
++)
1588 reg_saved
|= 1L << i
;
1591 if (regs_ever_live
[LINK_POINTER_REGNUM
])
1594 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1599 for (; i
<= 31; i
++)
1600 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1601 || i
== LINK_POINTER_REGNUM
))
1604 reg_saved
|= 1L << i
;
1610 *p_reg_saved
= reg_saved
;
1616 compute_frame_size (size
, p_reg_saved
)
1621 + compute_register_save_size (p_reg_saved
)
1622 + current_function_outgoing_args_size
);
1631 unsigned int size
= get_frame_size ();
1632 unsigned int actual_fsize
;
1633 unsigned int init_stack_alloc
= 0;
1636 unsigned int num_save
;
1637 unsigned int default_stack
;
1639 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1642 actual_fsize
= compute_frame_size (size
, ®_saved
);
1644 /* Save/setup global registers for interrupt functions right now. */
1645 if (interrupt_handler
)
1647 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1648 emit_insn (gen_callt_save_interrupt ());
1650 emit_insn (gen_save_interrupt ());
1652 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1654 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1655 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1658 /* Save arg registers to the stack if necessary. */
1659 else if (current_function_anonymous_args
)
1661 if (TARGET_PROLOG_FUNCTION
)
1663 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1664 emit_insn (gen_save_r6_r9_v850e ());
1666 emit_insn (gen_save_r6_r9 ());
1671 for (i
= 6; i
< 10; i
++)
1673 emit_move_insn (gen_rtx_MEM (SImode
,
1674 plus_constant (stack_pointer_rtx
,
1676 gen_rtx_REG (SImode
, i
));
1682 /* Identify all of the saved registers. */
1685 for (i
= 1; i
< 31; i
++)
1687 if (((1L << i
) & reg_saved
) != 0)
1688 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1691 /* If the return pointer is saved, the helper functions also allocate
1692 16 bytes of stack for arguments to be saved in. */
1693 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1695 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1699 /* See if we have an insn that allocates stack space and saves the particular
1700 registers we want to. */
1701 save_all
= NULL_RTX
;
1702 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1704 int alloc_stack
= (4 * num_save
) + default_stack
;
1705 int unalloc_stack
= actual_fsize
- alloc_stack
;
1706 int save_func_len
= 4;
1707 int save_normal_len
;
1710 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1712 /* see if we would have used ep to save the stack */
1713 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1714 save_normal_len
= (3 * 2) + (2 * num_save
);
1716 save_normal_len
= 4 * num_save
;
1718 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1720 /* Don't bother checking if we don't actually save any space.
1721 This happens for instance if one register is saved and additional
1722 stack space is allocated. */
1723 if (save_func_len
< save_normal_len
)
1725 save_all
= gen_rtx_PARALLEL
1727 rtvec_alloc (num_save
+ (TARGET_V850
? 2 : 1)));
1729 XVECEXP (save_all
, 0, 0)
1730 = gen_rtx_SET (VOIDmode
,
1732 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1736 XVECEXP (save_all
, 0, num_save
+1)
1737 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1740 offset
= - default_stack
;
1741 for (i
= 0; i
< num_save
; i
++)
1743 XVECEXP (save_all
, 0, i
+1)
1744 = gen_rtx_SET (VOIDmode
,
1746 plus_constant (stack_pointer_rtx
,
1752 code
= recog (save_all
, NULL_RTX
, NULL
);
1755 rtx insn
= emit_insn (save_all
);
1756 INSN_CODE (insn
) = code
;
1757 actual_fsize
-= alloc_stack
;
1761 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1762 save_normal_len
- save_func_len
,
1763 save_normal_len
, save_func_len
,
1764 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1767 save_all
= NULL_RTX
;
1771 /* If no prolog save function is available, store the registers the old
1772 fashioned way (one by one). */
1775 /* Special case interrupt functions that save all registers for a call. */
1776 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1778 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1779 emit_insn (gen_callt_save_all_interrupt ());
1781 emit_insn (gen_save_all_interrupt ());
1785 /* If the stack is too big, allocate it in chunks so we can do the
1786 register saves. We use the register save size so we use the ep
1788 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1789 init_stack_alloc
= compute_register_save_size (NULL
);
1791 init_stack_alloc
= actual_fsize
;
1793 /* Save registers at the beginning of the stack frame */
1794 offset
= init_stack_alloc
- 4;
1796 if (init_stack_alloc
)
1797 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1799 GEN_INT (-init_stack_alloc
)));
1801 /* Save the return pointer first. */
1802 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1804 emit_move_insn (gen_rtx_MEM (SImode
,
1805 plus_constant (stack_pointer_rtx
,
1807 save_regs
[--num_save
]);
1811 for (i
= 0; i
< num_save
; i
++)
1813 emit_move_insn (gen_rtx_MEM (SImode
,
1814 plus_constant (stack_pointer_rtx
,
1822 /* Allocate the rest of the stack that was not allocated above (either it is
1823 > 32K or we just called a function to save the registers and needed more
1825 if (actual_fsize
> init_stack_alloc
)
1827 int diff
= actual_fsize
- init_stack_alloc
;
1828 if (CONST_OK_FOR_K (diff
))
1829 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1834 rtx reg
= gen_rtx_REG (Pmode
, 12);
1835 emit_move_insn (reg
, GEN_INT (-diff
));
1836 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1840 /* If we need a frame pointer, set it up now. */
1841 if (frame_pointer_needed
)
1842 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1851 unsigned int size
= get_frame_size ();
1853 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1854 unsigned int init_stack_free
= 0;
1855 rtx restore_regs
[32];
1857 unsigned int num_restore
;
1858 unsigned int default_stack
;
1860 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1862 /* Eliminate the initial stack stored by interrupt functions. */
1863 if (interrupt_handler
)
1865 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1866 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1867 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1870 /* Cut off any dynamic stack created. */
1871 if (frame_pointer_needed
)
1872 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1874 /* Identify all of the saved registers. */
1877 for (i
= 1; i
< 31; i
++)
1879 if (((1L << i
) & reg_saved
) != 0)
1880 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1883 /* If the return pointer is saved, the helper functions also allocate
1884 16 bytes of stack for arguments to be saved in. */
1885 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1887 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1891 /* See if we have an insn that restores the particular registers we
1893 restore_all
= NULL_RTX
;
1895 if (TARGET_PROLOG_FUNCTION
1897 && actual_fsize
>= default_stack
1898 && !interrupt_handler
)
1900 int alloc_stack
= (4 * num_restore
) + default_stack
;
1901 int unalloc_stack
= actual_fsize
- alloc_stack
;
1902 int restore_func_len
= 4;
1903 int restore_normal_len
;
1906 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1908 /* See if we would have used ep to restore the registers. */
1909 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1910 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1912 restore_normal_len
= 4 * num_restore
;
1914 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1916 /* Don't bother checking if we don't actually save any space. */
1917 if (restore_func_len
< restore_normal_len
)
1919 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1920 rtvec_alloc (num_restore
+ 2));
1921 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1922 XVECEXP (restore_all
, 0, 1)
1923 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1924 gen_rtx_PLUS (Pmode
,
1926 GEN_INT (alloc_stack
)));
1928 offset
= alloc_stack
- 4;
1929 for (i
= 0; i
< num_restore
; i
++)
1931 XVECEXP (restore_all
, 0, i
+2)
1932 = gen_rtx_SET (VOIDmode
,
1935 plus_constant (stack_pointer_rtx
,
1940 code
= recog (restore_all
, NULL_RTX
, NULL
);
1946 actual_fsize
-= alloc_stack
;
1949 if (CONST_OK_FOR_K (actual_fsize
))
1950 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1952 GEN_INT (actual_fsize
)));
1955 rtx reg
= gen_rtx_REG (Pmode
, 12);
1956 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1957 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1963 insn
= emit_jump_insn (restore_all
);
1964 INSN_CODE (insn
) = code
;
1968 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1969 restore_normal_len
- restore_func_len
,
1970 restore_normal_len
, restore_func_len
,
1971 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1974 restore_all
= NULL_RTX
;
1978 /* If no epilog save function is available, restore the registers the
1979 old fashioned way (one by one). */
1982 /* If the stack is large, we need to cut it down in 2 pieces. */
1983 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1984 init_stack_free
= 4 * num_restore
;
1986 init_stack_free
= actual_fsize
;
1988 /* Deallocate the rest of the stack if it is > 32K. */
1989 if (actual_fsize
> init_stack_free
)
1993 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
1995 if (CONST_OK_FOR_K (diff
))
1996 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2001 rtx reg
= gen_rtx_REG (Pmode
, 12);
2002 emit_move_insn (reg
, GEN_INT (diff
));
2003 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2009 /* Special case interrupt functions that save all registers
2011 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
2013 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2014 emit_insn (gen_callt_restore_all_interrupt ());
2016 emit_insn (gen_restore_all_interrupt ());
2020 /* Restore registers from the beginning of the stack frame. */
2021 offset
= init_stack_free
- 4;
2023 /* Restore the return pointer first. */
2025 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
2027 emit_move_insn (restore_regs
[--num_restore
],
2028 gen_rtx_MEM (SImode
,
2029 plus_constant (stack_pointer_rtx
,
2034 for (i
= 0; i
< num_restore
; i
++)
2036 emit_move_insn (restore_regs
[i
],
2037 gen_rtx_MEM (SImode
,
2038 plus_constant (stack_pointer_rtx
,
2041 emit_insn (gen_rtx_USE (VOIDmode
, restore_regs
[i
]));
2045 /* Cut back the remainder of the stack. */
2046 if (init_stack_free
)
2047 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2049 GEN_INT (init_stack_free
)));
2052 /* And return or use reti for interrupt handlers. */
2053 if (interrupt_handler
)
2055 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2056 emit_insn (gen_callt_return_interrupt ());
2058 emit_jump_insn (gen_return_interrupt ());
2060 else if (actual_fsize
)
2061 emit_jump_insn (gen_return_internal ());
2063 emit_jump_insn (gen_return ());
2066 current_function_anonymous_args
= 0;
2067 v850_interrupt_cache_p
= FALSE
;
2068 v850_interrupt_p
= FALSE
;
2072 /* Update the condition code from the insn. */
2075 notice_update_cc (body
, insn
)
2079 switch (get_attr_cc (insn
))
2082 /* Insn does not affect CC at all. */
2086 /* Insn does not change CC, but the 0'th operand has been changed. */
2087 if (cc_status
.value1
!= 0
2088 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2089 cc_status
.value1
= 0;
2093 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2094 V,C is in an unusable state. */
2096 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2097 cc_status
.value1
= recog_data
.operand
[0];
2101 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2102 C is in an unusable state. */
2104 cc_status
.flags
|= CC_NO_CARRY
;
2105 cc_status
.value1
= recog_data
.operand
[0];
2109 /* The insn is a compare instruction. */
2111 cc_status
.value1
= SET_SRC (body
);
2115 /* Insn doesn't leave CC in a usable state. */
2121 /* Retrieve the data area that has been chosen for the given decl. */
2124 v850_get_data_area (decl
)
2127 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2128 return DATA_AREA_SDA
;
2130 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2131 return DATA_AREA_TDA
;
2133 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2134 return DATA_AREA_ZDA
;
2136 return DATA_AREA_NORMAL
;
2139 /* Store the indicated data area in the decl's attributes. */
2142 v850_set_data_area (decl
, data_area
)
2144 v850_data_area data_area
;
2150 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2151 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2152 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2157 DECL_ATTRIBUTES (decl
) = tree_cons
2158 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2161 const struct attribute_spec v850_attribute_table
[] =
2163 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2164 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2165 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2166 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2167 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2168 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2169 { NULL
, 0, 0, false, false, false, NULL
}
2172 /* Handle an "interrupt" attribute; arguments as in
2173 struct attribute_spec.handler. */
2175 v850_handle_interrupt_attribute (node
, name
, args
, flags
, no_add_attrs
)
2178 tree args ATTRIBUTE_UNUSED
;
2179 int flags ATTRIBUTE_UNUSED
;
2182 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2184 warning ("`%s' attribute only applies to functions",
2185 IDENTIFIER_POINTER (name
));
2186 *no_add_attrs
= true;
2192 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2193 struct attribute_spec.handler. */
2195 v850_handle_data_area_attribute (node
, name
, args
, flags
, no_add_attrs
)
2198 tree args ATTRIBUTE_UNUSED
;
2199 int flags ATTRIBUTE_UNUSED
;
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_with_decl (decl
, "\
2222 a data area attribute cannot be specified for local variables");
2223 *no_add_attrs
= true;
2229 area
= v850_get_data_area (decl
);
2230 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2232 error_with_decl (decl
, "\
2233 data area of '%s' 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 (func
)
2256 if (v850_interrupt_cache_p
)
2257 return v850_interrupt_p
;
2259 if (TREE_CODE (func
) != FUNCTION_DECL
)
2262 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2268 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2269 ret
= a
!= NULL_TREE
;
2272 /* Its not safe to trust global variables until after function inlining has
2274 if (reload_completed
| reload_in_progress
)
2275 v850_interrupt_p
= ret
;
2282 v850_encode_data_area (decl
)
2285 const char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2286 int len
= strlen (str
);
2289 /* Map explict sections into the appropriate attribute */
2290 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2292 if (DECL_SECTION_NAME (decl
))
2294 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2296 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2297 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2299 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2300 v850_set_data_area (decl
, DATA_AREA_SDA
);
2302 else if (streq (name
, ".tdata"))
2303 v850_set_data_area (decl
, DATA_AREA_TDA
);
2306 /* If no attribute, support -m{zda,sda,tda}=n */
2309 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2313 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2314 v850_set_data_area (decl
, DATA_AREA_TDA
);
2316 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2317 v850_set_data_area (decl
, DATA_AREA_SDA
);
2319 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2320 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2323 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2327 newstr
= alloca (len
+ 2);
2329 strcpy (newstr
+ 1, str
);
2331 switch (v850_get_data_area (decl
))
2333 case DATA_AREA_ZDA
: *newstr
= ZDA_NAME_FLAG_CHAR
; break;
2334 case DATA_AREA_TDA
: *newstr
= TDA_NAME_FLAG_CHAR
; break;
2335 case DATA_AREA_SDA
: *newstr
= SDA_NAME_FLAG_CHAR
; break;
2339 XSTR (XEXP (DECL_RTL (decl
), 0), 0) = ggc_alloc_string (newstr
, len
+ 2);
2343 v850_encode_section_info (decl
, first
)
2347 if (first
&& TREE_CODE (decl
) == VAR_DECL
2348 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2349 v850_encode_data_area (decl
);
2353 v850_strip_name_encoding (str
)
2356 return str
+ (ENCODED_NAME_P (str
) || *str
== '*');
2359 /* Return true if the given RTX is a register which can be restored
2360 by a function epilogue. */
2362 register_is_ok_for_epilogue (op
, mode
)
2364 enum machine_mode ATTRIBUTE_UNUSED mode
;
2366 /* The save/restore routines can only cope with registers 20 - 31. */
2367 return ((GET_CODE (op
) == REG
)
2368 && (((REGNO (op
) >= 20) && REGNO (op
) <= 31)));
2371 /* Return non-zero if the given RTX is suitable for collapsing into
2372 jump to a function epilogue. */
2374 pattern_is_ok_for_epilogue (op
, mode
)
2376 enum machine_mode ATTRIBUTE_UNUSED mode
;
2378 int count
= XVECLEN (op
, 0);
2381 /* If there are no registers to restore then the function epilogue
2386 /* The pattern matching has already established that we are performing a
2387 function epilogue and that we are popping at least one register. We must
2388 now check the remaining entries in the vector to make sure that they are
2389 also register pops. There is no good reason why there should ever be
2390 anything else in this vector, but being paranoid always helps...
2392 The test below performs the C equivalent of this machine description
2395 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2396 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2399 for (i
= 3; i
< count
; i
++)
2401 rtx vector_element
= XVECEXP (op
, 0, i
);
2406 if (GET_CODE (vector_element
) != SET
)
2409 dest
= SET_DEST (vector_element
);
2410 src
= SET_SRC (vector_element
);
2412 if (GET_CODE (dest
) != REG
2413 || GET_MODE (dest
) != SImode
2414 || ! register_is_ok_for_epilogue (dest
, SImode
)
2415 || GET_CODE (src
) != MEM
2416 || GET_MODE (src
) != SImode
)
2419 plus
= XEXP (src
, 0);
2421 if (GET_CODE (plus
) != PLUS
2422 || GET_CODE (XEXP (plus
, 0)) != REG
2423 || GET_MODE (XEXP (plus
, 0)) != SImode
2424 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2425 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2432 /* Construct a JR instruction to a routine that will perform the equivalent of
2433 the RTL passed in as an argument. This RTL is a function epilogue that
2434 pops registers off the stack and possibly releases some extra stack space
2435 as well. The code has already verified that the RTL matches these
2438 construct_restore_jr (op
)
2441 int count
= XVECLEN (op
, 0);
2443 unsigned long int mask
;
2444 unsigned long int first
;
2445 unsigned long int last
;
2447 static char buff
[100]; /* XXX */
2451 error ("bogus JR construction: %d\n", count
);
2455 /* Work out how many bytes to pop off the stack before retrieving
2457 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2459 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2461 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2464 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2466 /* Each pop will remove 4 bytes from the stack... */
2467 stack_bytes
-= (count
- 2) * 4;
2469 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2470 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2472 error ("bad amount of stack space removal: %d", stack_bytes
);
2476 /* Now compute the bit mask of registers to push. */
2478 for (i
= 2; i
< count
; i
++)
2480 rtx vector_element
= XVECEXP (op
, 0, i
);
2482 if (GET_CODE (vector_element
) != SET
)
2484 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2486 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
2489 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2492 /* Scan for the first register to pop. */
2493 for (first
= 0; first
< 32; first
++)
2495 if (mask
& (1 << first
))
2502 /* Discover the last register to pop. */
2503 if (mask
& (1 << LINK_POINTER_REGNUM
))
2505 if (stack_bytes
!= 16)
2508 last
= LINK_POINTER_REGNUM
;
2512 if (stack_bytes
!= 0)
2515 if ((mask
& (1 << 29)) == 0)
2521 /* Note, it is possible to have gaps in the register mask.
2522 We ignore this here, and generate a JR anyway. We will
2523 be popping more registers than is strictly necessary, but
2524 it does save code space. */
2526 if (TARGET_LONG_CALLS
)
2531 sprintf (name
, "__return_%s", reg_names
[first
]);
2533 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2535 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2541 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2543 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2550 /* Return non-zero if the given RTX is suitable for collapsing into
2551 a jump to a function prologue. */
2553 pattern_is_ok_for_prologue (op
, mode
)
2555 enum machine_mode ATTRIBUTE_UNUSED mode
;
2557 int count
= XVECLEN (op
, 0);
2561 /* If there are no registers to save then the function prologue
2566 /* The pattern matching has already established that we are adjusting the
2567 stack and pushing at least one register. We must now check that the
2568 remaining entries in the vector to make sure that they are also register
2569 pushes, except for the last entry which should be a CLOBBER of r10.
2571 The test below performs the C equivalent of this machine description
2574 (set (mem:SI (plus:SI (reg:SI 3)
2575 (match_operand:SI 2 "immediate_operand" "i")))
2576 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2580 for (i
= 2; i
< count
- 1; i
++)
2586 vector_element
= XVECEXP (op
, 0, i
);
2588 if (GET_CODE (vector_element
) != SET
)
2591 dest
= SET_DEST (vector_element
);
2592 src
= SET_SRC (vector_element
);
2594 if (GET_CODE (dest
) != MEM
2595 || GET_MODE (dest
) != SImode
2596 || GET_CODE (src
) != REG
2597 || GET_MODE (src
) != SImode
2598 || ! register_is_ok_for_epilogue (src
, SImode
))
2601 plus
= XEXP (dest
, 0);
2603 if ( GET_CODE (plus
) != PLUS
2604 || GET_CODE (XEXP (plus
, 0)) != REG
2605 || GET_MODE (XEXP (plus
, 0)) != SImode
2606 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2607 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2610 /* If the register is being pushed somewhere other than the stack
2611 space just acquired by the first operand then abandon this quest.
2612 Note: the test is <= because both values are negative. */
2613 if (INTVAL (XEXP (plus
, 1))
2614 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
2620 /* Make sure that the last entry in the vector is a clobber. */
2621 vector_element
= XVECEXP (op
, 0, i
);
2623 if (GET_CODE (vector_element
) != CLOBBER
2624 || GET_CODE (XEXP (vector_element
, 0)) != REG
2625 || REGNO (XEXP (vector_element
, 0)) != 10)
2631 /* Construct a JARL instruction to a routine that will perform the equivalent
2632 of the RTL passed as a parameter. This RTL is a function prologue that
2633 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2634 some stack space as well. The code has already verified that the RTL
2635 matches these requirements. */
2637 construct_save_jarl (op
)
2640 int count
= XVECLEN (op
, 0);
2642 unsigned long int mask
;
2643 unsigned long int first
;
2644 unsigned long int last
;
2646 static char buff
[100]; /* XXX */
2650 error ("bogus JARL construction: %d\n", count
);
2655 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2657 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2659 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) != REG
)
2661 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2664 /* Work out how many bytes to push onto the stack after storing the
2666 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2668 /* Each push will put 4 bytes from the stack... */
2669 stack_bytes
+= (count
- 2) * 4;
2671 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2672 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2674 error ("bad amount of stack space removal: %d", stack_bytes
);
2678 /* Now compute the bit mask of registers to push. */
2680 for (i
= 1; i
< count
- 1; i
++)
2682 rtx vector_element
= XVECEXP (op
, 0, i
);
2684 if (GET_CODE (vector_element
) != SET
)
2686 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2688 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2691 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2694 /* Scan for the first register to push. */
2695 for (first
= 0; first
< 32; first
++)
2697 if (mask
& (1 << first
))
2704 /* Discover the last register to push. */
2705 if (mask
& (1 << LINK_POINTER_REGNUM
))
2707 if (stack_bytes
!= -16)
2710 last
= LINK_POINTER_REGNUM
;
2714 if (stack_bytes
!= 0)
2716 if ((mask
& (1 << 29)) == 0)
2722 /* Note, it is possible to have gaps in the register mask.
2723 We ignore this here, and generate a JARL anyway. We will
2724 be pushing more registers than is strictly necessary, but
2725 it does save code space. */
2727 if (TARGET_LONG_CALLS
)
2732 sprintf (name
, "__save_%s", reg_names
[first
]);
2734 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2736 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2742 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2744 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2751 extern tree last_assemble_variable_decl
;
2752 extern int size_directive_output
;
2754 /* A version of asm_output_aligned_bss() that copes with the special
2755 data areas of the v850. */
2757 v850_output_aligned_bss (file
, decl
, name
, size
, align
)
2764 (*targetm
.asm_out
.globalize_label
) (file
, name
);
2766 switch (v850_get_data_area (decl
))
2784 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2785 #ifdef ASM_DECLARE_OBJECT_NAME
2786 last_assemble_variable_decl
= decl
;
2787 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2789 /* Standard thing is just output label for the object. */
2790 ASM_OUTPUT_LABEL (file
, name
);
2791 #endif /* ASM_DECLARE_OBJECT_NAME */
2792 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2795 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2797 v850_output_common (file
, decl
, name
, size
, align
)
2804 if (decl
== NULL_TREE
)
2806 fprintf (file
, "%s", COMMON_ASM_OP
);
2810 switch (v850_get_data_area (decl
))
2813 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2817 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2821 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2825 fprintf (file
, "%s", COMMON_ASM_OP
);
2830 assemble_name (file
, name
);
2831 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2834 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2836 v850_output_local (file
, decl
, name
, size
, align
)
2843 fprintf (file
, "%s", LOCAL_ASM_OP
);
2844 assemble_name (file
, name
);
2845 fprintf (file
, "\n");
2847 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2850 /* Add data area to the given declaration if a ghs data area pragma is
2851 currently in effect (#pragma ghs startXXX/endXXX). */
2853 v850_insert_attributes (decl
, attr_ptr
)
2855 tree
*attr_ptr ATTRIBUTE_UNUSED
;
2858 && data_area_stack
->data_area
2859 && current_function_decl
== NULL_TREE
2860 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2861 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2862 v850_set_data_area (decl
, data_area_stack
->data_area
);
2864 /* Initialise the default names of the v850 specific sections,
2865 if this has not been done before. */
2867 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2869 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2870 = build_string (sizeof (".sdata")-1, ".sdata");
2872 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2873 = build_string (sizeof (".rosdata")-1, ".rosdata");
2875 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2876 = build_string (sizeof (".tdata")-1, ".tdata");
2878 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2879 = build_string (sizeof (".zdata")-1, ".zdata");
2881 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2882 = build_string (sizeof (".rozdata")-1, ".rozdata");
2885 if (current_function_decl
== NULL_TREE
2886 && (TREE_CODE (decl
) == VAR_DECL
2887 || TREE_CODE (decl
) == CONST_DECL
2888 || TREE_CODE (decl
) == FUNCTION_DECL
)
2889 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2890 && !DECL_SECTION_NAME (decl
))
2892 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2893 tree chosen_section
;
2895 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2896 kind
= GHS_SECTION_KIND_TEXT
;
2899 /* First choose a section kind based on the data area of the decl. */
2900 switch (v850_get_data_area (decl
))
2906 kind
= ((TREE_READONLY (decl
))
2907 ? GHS_SECTION_KIND_ROSDATA
2908 : GHS_SECTION_KIND_SDATA
);
2912 kind
= GHS_SECTION_KIND_TDATA
;
2916 kind
= ((TREE_READONLY (decl
))
2917 ? GHS_SECTION_KIND_ROZDATA
2918 : GHS_SECTION_KIND_ZDATA
);
2921 case DATA_AREA_NORMAL
: /* default data area */
2922 if (TREE_READONLY (decl
))
2923 kind
= GHS_SECTION_KIND_RODATA
;
2924 else if (DECL_INITIAL (decl
))
2925 kind
= GHS_SECTION_KIND_DATA
;
2927 kind
= GHS_SECTION_KIND_BSS
;
2931 /* Now, if the section kind has been explicitly renamed,
2932 then attach a section attribute. */
2933 chosen_section
= GHS_current_section_names
[(int) kind
];
2935 /* Otherwise, if this kind of section needs an explicit section
2936 attribute, then also attach one. */
2937 if (chosen_section
== NULL
)
2938 chosen_section
= GHS_default_section_names
[(int) kind
];
2942 /* Only set the section name if specified by a pragma, because
2943 otherwise it will force those variables to get allocated storage
2944 in this module, rather than by the linker. */
2945 DECL_SECTION_NAME (decl
) = chosen_section
;
2950 /* Return non-zero if the given RTX is suitable
2951 for collapsing into a DISPOSE instruction. */
2954 pattern_is_ok_for_dispose (op
, mode
)
2956 enum machine_mode mode ATTRIBUTE_UNUSED
;
2958 int count
= XVECLEN (op
, 0);
2961 /* If there are no registers to restore then
2962 the dispose instruction is not suitable. */
2966 /* The pattern matching has already established that we are performing a
2967 function epilogue and that we are popping at least one register. We must
2968 now check the remaining entries in the vector to make sure that they are
2969 also register pops. There is no good reason why there should ever be
2970 anything else in this vector, but being paranoid always helps...
2972 The test below performs the C equivalent of this machine description
2975 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2976 (mem:SI (plus:SI (reg:SI 3)
2977 (match_operand:SI n "immediate_operand" "i"))))
2980 for (i
= 3; i
< count
; i
++)
2982 rtx vector_element
= XVECEXP (op
, 0, i
);
2987 if (GET_CODE (vector_element
) != SET
)
2990 dest
= SET_DEST (vector_element
);
2991 src
= SET_SRC (vector_element
);
2993 if ( GET_CODE (dest
) != REG
2994 || GET_MODE (dest
) != SImode
2995 || ! register_is_ok_for_epilogue (dest
, SImode
)
2996 || GET_CODE (src
) != MEM
2997 || GET_MODE (src
) != SImode
)
3000 plus
= XEXP (src
, 0);
3002 if ( GET_CODE (plus
) != PLUS
3003 || GET_CODE (XEXP (plus
, 0)) != REG
3004 || GET_MODE (XEXP (plus
, 0)) != SImode
3005 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3006 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3013 /* Construct a DISPOSE instruction that is the equivalent of
3014 the given RTX. We have already verified that this should
3018 construct_dispose_instruction (op
)
3021 int count
= XVECLEN (op
, 0);
3023 unsigned long int mask
;
3025 static char buff
[ 100 ]; /* XXX */
3030 error ("Bogus DISPOSE construction: %d\n", count
);
3034 /* Work out how many bytes to pop off the
3035 stack before retrieving registers. */
3036 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
3038 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
3040 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
3043 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
3045 /* Each pop will remove 4 bytes from the stack... */
3046 stack_bytes
-= (count
- 2) * 4;
3048 /* Make sure that the amount we are popping
3049 will fit into the DISPOSE instruction. */
3050 if (stack_bytes
> 128)
3052 error ("Too much stack space to dispose of: %d", stack_bytes
);
3056 /* Now compute the bit mask of registers to push. */
3059 for (i
= 2; i
< count
; i
++)
3061 rtx vector_element
= XVECEXP (op
, 0, i
);
3063 if (GET_CODE (vector_element
) != SET
)
3065 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
3067 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
3070 if (REGNO (SET_DEST (vector_element
)) == 2)
3073 mask
|= 1 << REGNO (SET_DEST (vector_element
));
3076 if (! TARGET_DISABLE_CALLT
3077 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
3081 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
3086 for (i
= 20; i
< 32; i
++)
3087 if (mask
& (1 << i
))
3091 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
3093 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
3094 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3099 static char regs
[100]; /* XXX */
3102 /* Generate the DISPOSE instruction. Note we could just issue the
3103 bit mask as a number as the assembler can cope with this, but for
3104 the sake of our readers we turn it into a textual description. */
3108 for (i
= 20; i
< 32; i
++)
3110 if (mask
& (1 << i
))
3115 strcat (regs
, ", ");
3120 strcat (regs
, reg_names
[ first
]);
3122 for (i
++; i
< 32; i
++)
3123 if ((mask
& (1 << i
)) == 0)
3128 strcat (regs
, " - ");
3129 strcat (regs
, reg_names
[ i
- 1 ] );
3134 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
3140 /* Return non-zero if the given RTX is suitable
3141 for collapsing into a PREPARE instruction. */
3144 pattern_is_ok_for_prepare (op
, mode
)
3146 enum machine_mode mode ATTRIBUTE_UNUSED
;
3148 int count
= XVECLEN (op
, 0);
3151 /* If there are no registers to restore then the prepare instruction
3156 /* The pattern matching has already established that we are adjusting the
3157 stack and pushing at least one register. We must now check that the
3158 remaining entries in the vector to make sure that they are also register
3161 The test below performs the C equivalent of this machine description
3164 (set (mem:SI (plus:SI (reg:SI 3)
3165 (match_operand:SI 2 "immediate_operand" "i")))
3166 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3170 for (i
= 2; i
< count
; i
++)
3172 rtx vector_element
= XVECEXP (op
, 0, i
);
3177 if (GET_CODE (vector_element
) != SET
)
3180 dest
= SET_DEST (vector_element
);
3181 src
= SET_SRC (vector_element
);
3183 if ( GET_CODE (dest
) != MEM
3184 || GET_MODE (dest
) != SImode
3185 || GET_CODE (src
) != REG
3186 || GET_MODE (src
) != SImode
3187 || ! register_is_ok_for_epilogue (src
, SImode
)
3191 plus
= XEXP (dest
, 0);
3193 if ( GET_CODE (plus
) != PLUS
3194 || GET_CODE (XEXP (plus
, 0)) != REG
3195 || GET_MODE (XEXP (plus
, 0)) != SImode
3196 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3197 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3200 /* If the register is being pushed somewhere other than the stack
3201 space just aquired by the first operand then abandon this quest.
3202 Note: the test is <= becuase both values are negative. */
3203 if (INTVAL (XEXP (plus
, 1))
3204 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
3211 /* Construct a PREPARE instruction that is the equivalent of
3212 the given RTL. We have already verified that this should
3216 construct_prepare_instruction (op
)
3219 int count
= XVECLEN (op
, 0);
3221 unsigned long int mask
;
3223 static char buff
[ 100 ]; /* XXX */
3228 error ("Bogus PREPEARE construction: %d\n", count
);
3232 /* Work out how many bytes to push onto
3233 the stack after storing the registers. */
3234 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
3236 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
3238 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
3241 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
3243 /* Each push will put 4 bytes from the stack. */
3244 stack_bytes
+= (count
- 1) * 4;
3246 /* Make sure that the amount we are popping
3247 will fit into the DISPOSE instruction. */
3248 if (stack_bytes
< -128)
3250 error ("Too much stack space to prepare: %d", stack_bytes
);
3254 /* Now compute the bit mask of registers to push. */
3256 for (i
= 1; i
< count
; i
++)
3258 rtx vector_element
= XVECEXP (op
, 0, i
);
3260 if (GET_CODE (vector_element
) != SET
)
3262 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
3264 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
3267 if (REGNO (SET_SRC (vector_element
)) == 2)
3270 mask
|= 1 << REGNO (SET_SRC (vector_element
));
3273 if ((! TARGET_DISABLE_CALLT
)
3274 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
3278 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
3282 for (i
= 20; i
< 32; i
++)
3283 if (mask
& (1 << i
))
3287 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
3289 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
3290 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3294 static char regs
[100]; /* XXX */
3298 /* Generate the PREPARE instruction. Note we could just issue the
3299 bit mask as a number as the assembler can cope with this, but for
3300 the sake of our readers we turn it into a textual description. */
3304 for (i
= 20; i
< 32; i
++)
3306 if (mask
& (1 << i
))
3311 strcat (regs
, ", ");
3316 strcat (regs
, reg_names
[ first
]);
3318 for (i
++; i
< 32; i
++)
3319 if ((mask
& (1 << i
)) == 0)
3324 strcat (regs
, " - ");
3325 strcat (regs
, reg_names
[ i
- 1 ] );
3330 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
3336 /* Implement `va_arg'. */
3339 v850_va_arg (valist
, type
)
3342 HOST_WIDE_INT size
, rsize
;
3347 /* Round up sizeof(type) to a word. */
3348 size
= int_size_in_bytes (type
);
3349 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
3354 size
= rsize
= UNITS_PER_WORD
;
3358 addr
= save_expr (valist
);
3359 incr
= fold (build (PLUS_EXPR
, ptr_type_node
, addr
,
3360 build_int_2 (rsize
, 0)));
3362 incr
= build (MODIFY_EXPR
, ptr_type_node
, valist
, incr
);
3363 TREE_SIDE_EFFECTS (incr
) = 1;
3364 expand_expr (incr
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3366 addr_rtx
= expand_expr (addr
, NULL
, Pmode
, EXPAND_NORMAL
);
3370 addr_rtx
= force_reg (Pmode
, addr_rtx
);
3371 addr_rtx
= gen_rtx_MEM (Pmode
, addr_rtx
);
3372 set_mem_alias_set (addr_rtx
, get_varargs_alias_set ());
3378 /* Return an RTX indicating where the return address to the
3379 calling function can be found. */
3382 v850_return_addr (count
)
3388 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
3392 v850_select_section (exp
, reloc
, align
)
3394 int reloc ATTRIBUTE_UNUSED
;
3395 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
3397 if (TREE_CODE (exp
) == VAR_DECL
)
3400 if (!TREE_READONLY (exp
)
3401 || TREE_SIDE_EFFECTS (exp
)
3402 || !DECL_INITIAL (exp
)
3403 || (DECL_INITIAL (exp
) != error_mark_node
3404 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
3409 switch (v850_get_data_area (exp
))
3431 readonly_data_section ();
3437 else if (TREE_CODE (exp
) == STRING_CST
)
3439 if (! flag_writable_strings
)
3440 readonly_data_section ();
3445 readonly_data_section ();