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
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
PARAMS ((rtx
, HOST_WIDE_INT
*, HOST_WIDE_INT
*));
53 static int const_costs_int
PARAMS ((HOST_WIDE_INT
, int));
54 static void substitute_ep_register
PARAMS ((rtx
, rtx
, int, int, rtx
*, rtx
*));
55 static int ep_memory_offset
PARAMS ((enum machine_mode
, int));
56 static void v850_set_data_area
PARAMS ((tree
, v850_data_area
));
57 const struct attribute_spec v850_attribute_table
[];
58 static tree v850_handle_interrupt_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
59 static tree v850_handle_data_area_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
60 static void v850_insert_attributes
PARAMS ((tree
, tree
*));
61 static void v850_select_section
PARAMS ((tree
, int, unsigned HOST_WIDE_INT
));
62 static void v850_encode_data_area
PARAMS ((tree
));
63 static void v850_encode_section_info
PARAMS ((tree
, int));
64 static const char *v850_strip_name_encoding
PARAMS ((const char *));
66 /* Information about the various small memory areas. */
67 struct small_memory_info small_memory
[ (int)SMALL_MEMORY_max
] =
69 /* name value max physical max */
70 { "tda", (char *)0, 0, 256 },
71 { "sda", (char *)0, 0, 65536 },
72 { "zda", (char *)0, 0, 32768 },
75 /* Names of the various data areas used on the v850. */
76 tree GHS_default_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
77 tree GHS_current_section_names
[(int) COUNT_OF_GHS_SECTION_KINDS
];
79 /* Track the current data area set by the data area pragma (which
80 can be nested). Tested by check_default_data_area. */
81 data_area_stack_element
* data_area_stack
= NULL
;
83 /* True if we don't need to check any more if the current
84 function is an interrupt handler. */
85 static int v850_interrupt_cache_p
= FALSE
;
87 /* Whether current function is an interrupt handler. */
88 static int v850_interrupt_p
= FALSE
;
90 /* Initialize the GCC target structure. */
91 #undef TARGET_ASM_ALIGNED_HI_OP
92 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
94 #undef TARGET_ATTRIBUTE_TABLE
95 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
97 #undef TARGET_INSERT_ATTRIBUTES
98 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
100 #undef TARGET_ASM_SELECT_SECTION
101 #define TARGET_ASM_SELECT_SECTION v850_select_section
103 #undef TARGET_ENCODE_SECTION_INFO
104 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
105 #undef TARGET_STRIP_NAME_ENCODING
106 #define TARGET_STRIP_NAME_ENCODING v850_strip_name_encoding
108 struct gcc_target targetm
= TARGET_INITIALIZER
;
110 /* Sometimes certain combinations of command options do not make
111 sense on a particular target machine. You can define a macro
112 `OVERRIDE_OPTIONS' to take account of this. This macro, if
113 defined, is executed once just after all the command options have
116 Don't use this macro to turn on various extra optimizations for
117 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
123 extern int atoi
PARAMS ((const char *));
125 /* Parse -m{s,t,z}da=nnn switches */
126 for (i
= 0; i
< (int)SMALL_MEMORY_max
; i
++)
128 if (small_memory
[i
].value
)
130 if (!ISDIGIT (*small_memory
[i
].value
))
131 error ("%s=%s is not numeric",
132 small_memory
[i
].name
,
133 small_memory
[i
].value
);
136 small_memory
[i
].max
= atoi (small_memory
[i
].value
);
137 if (small_memory
[i
].max
> small_memory
[i
].physical_max
)
138 error ("%s=%s is too large",
139 small_memory
[i
].name
,
140 small_memory
[i
].value
);
145 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
146 if ((target_flags
& MASK_US_MASK_SET
) == 0)
148 target_flags
|= MASK_US_MASK_SET
;
149 target_flags
&= ~MASK_US_BIT_SET
;
154 /* Output assembly code for the start of the file. */
157 asm_file_start (file
)
160 output_file_directive (file
, main_input_filename
);
164 /* Return an RTX to represent where a value with mode MODE will be returned
165 from a function. If the result is 0, the argument is pushed. */
168 function_arg (cum
, mode
, type
, named
)
169 CUMULATIVE_ARGS
*cum
;
170 enum machine_mode mode
;
177 if (TARGET_GHS
&& !named
)
181 size
= int_size_in_bytes (type
);
183 size
= GET_MODE_SIZE (mode
);
189 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
193 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
195 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
198 if (type
== NULL_TREE
199 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
202 switch (cum
->nbytes
/ UNITS_PER_WORD
)
205 result
= gen_rtx_REG (mode
, 6);
208 result
= gen_rtx_REG (mode
, 7);
211 result
= gen_rtx_REG (mode
, 8);
214 result
= gen_rtx_REG (mode
, 9);
224 /* Return the number of words which must be put into registers
225 for values which are part in registers and part in memory. */
228 function_arg_partial_nregs (cum
, mode
, type
, named
)
229 CUMULATIVE_ARGS
*cum
;
230 enum machine_mode mode
;
236 if (TARGET_GHS
&& !named
)
240 size
= int_size_in_bytes (type
);
242 size
= GET_MODE_SIZE (mode
);
245 align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
249 cum
->nbytes
= (cum
->nbytes
+ align
- 1) &~(align
- 1);
251 if (cum
->nbytes
> 4 * UNITS_PER_WORD
)
254 if (cum
->nbytes
+ size
<= 4 * UNITS_PER_WORD
)
257 if (type
== NULL_TREE
258 && cum
->nbytes
+ size
> 4 * UNITS_PER_WORD
)
261 return (4 * UNITS_PER_WORD
- cum
->nbytes
) / UNITS_PER_WORD
;
265 /* Return the high and low words of a CONST_DOUBLE */
268 const_double_split (x
, p_high
, p_low
)
270 HOST_WIDE_INT
*p_high
;
271 HOST_WIDE_INT
*p_low
;
273 if (GET_CODE (x
) == CONST_DOUBLE
)
278 switch (GET_MODE (x
))
281 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
282 REAL_VALUE_TO_TARGET_DOUBLE (rv
, t
);
283 *p_high
= t
[1]; /* since v850 is little endian */
284 *p_low
= t
[0]; /* high is second word */
288 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
289 REAL_VALUE_TO_TARGET_SINGLE (rv
, *p_high
);
295 *p_high
= CONST_DOUBLE_HIGH (x
);
296 *p_low
= CONST_DOUBLE_LOW (x
);
304 fatal_insn ("const_double_split got a bad insn:", x
);
308 /* Return the cost of the rtx R with code CODE. */
311 const_costs_int (value
, zero_cost
)
315 if (CONST_OK_FOR_I (value
))
317 else if (CONST_OK_FOR_J (value
))
319 else if (CONST_OK_FOR_K (value
))
330 HOST_WIDE_INT high
, low
;
335 return const_costs_int (INTVAL (r
), 0);
338 const_double_split (r
, &high
, &low
);
339 if (GET_MODE (r
) == SFmode
)
340 return const_costs_int (high
, 1);
342 return const_costs_int (high
, 1) + const_costs_int (low
, 1);
358 /* Print operand X using operand code CODE to assembly language output file
362 print_operand (file
, x
, code
)
367 HOST_WIDE_INT high
, low
;
372 /* We use 'c' operands with symbols for .vtinherit */
373 if (GET_CODE (x
) == SYMBOL_REF
)
375 output_addr_const(file
, x
);
382 switch ((code
== 'B' || code
== 'C')
383 ? reverse_condition (GET_CODE (x
)) : GET_CODE (x
))
386 if (code
== 'c' || code
== 'C')
387 fprintf (file
, "nz");
389 fprintf (file
, "ne");
392 if (code
== 'c' || code
== 'C')
398 fprintf (file
, "ge");
401 fprintf (file
, "gt");
404 fprintf (file
, "le");
407 fprintf (file
, "lt");
410 fprintf (file
, "nl");
416 fprintf (file
, "nh");
425 case 'F': /* high word of CONST_DOUBLE */
426 if (GET_CODE (x
) == CONST_INT
)
427 fprintf (file
, "%d", (INTVAL (x
) >= 0) ? 0 : -1);
428 else if (GET_CODE (x
) == CONST_DOUBLE
)
430 const_double_split (x
, &high
, &low
);
431 fprintf (file
, "%ld", (long) high
);
436 case 'G': /* low word of CONST_DOUBLE */
437 if (GET_CODE (x
) == CONST_INT
)
438 fprintf (file
, "%ld", (long) INTVAL (x
));
439 else if (GET_CODE (x
) == CONST_DOUBLE
)
441 const_double_split (x
, &high
, &low
);
442 fprintf (file
, "%ld", (long) low
);
448 fprintf (file
, "%d\n", INTVAL (x
) & 0xffff);
451 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
454 if (special_symbolref_operand (x
, VOIDmode
))
458 if (GET_CODE (x
) == SYMBOL_REF
)
460 else if (GET_CODE (x
) == CONST
)
461 name
= XSTR (XEXP (XEXP (x
, 0), 0), 0);
465 if (ZDA_NAME_P (name
))
466 fprintf (file
, "zdaoff");
467 else if (SDA_NAME_P (name
))
468 fprintf (file
, "sdaoff");
469 else if (TDA_NAME_P (name
))
470 fprintf (file
, "tdaoff");
478 if (special_symbolref_operand (x
, VOIDmode
))
479 output_addr_const (file
, x
);
484 if (special_symbolref_operand (x
, VOIDmode
))
488 if (GET_CODE (x
) == SYMBOL_REF
)
490 else if (GET_CODE (x
) == CONST
)
491 name
= XSTR (XEXP (XEXP (x
, 0), 0), 0);
495 if (ZDA_NAME_P (name
))
496 fprintf (file
, "r0");
497 else if (SDA_NAME_P (name
))
498 fprintf (file
, "gp");
499 else if (TDA_NAME_P (name
))
500 fprintf (file
, "ep");
507 case 'R': /* 2nd word of a double. */
508 switch (GET_CODE (x
))
511 fprintf (file
, reg_names
[REGNO (x
) + 1]);
514 x
= XEXP (adjust_address (x
, SImode
, 4), 0);
515 print_operand_address (file
, x
);
516 if (GET_CODE (x
) == CONST_INT
)
517 fprintf (file
, "[r0]");
526 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
527 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), FALSE
))
534 /* Like an 'S' operand above, but for unsigned loads only. */
535 if (GET_CODE (x
) == MEM
&& ep_memory_operand (x
, GET_MODE (x
), TRUE
))
540 case 'W': /* print the instruction suffix */
541 switch (GET_MODE (x
))
546 case QImode
: fputs (".b", file
); break;
547 case HImode
: fputs (".h", file
); break;
548 case SImode
: fputs (".w", file
); break;
549 case SFmode
: fputs (".w", file
); break;
552 case '.': /* register r0 */
553 fputs (reg_names
[0], file
);
555 case 'z': /* reg or zero */
557 fputs (reg_names
[0], file
);
558 else if (GET_CODE (x
) == REG
)
559 fputs (reg_names
[REGNO (x
)], file
);
564 switch (GET_CODE (x
))
567 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
568 output_address (gen_rtx_PLUS (SImode
, gen_rtx (REG
, SImode
, 0),
571 output_address (XEXP (x
, 0));
575 fputs (reg_names
[REGNO (x
)], file
);
578 fputs (reg_names
[subreg_regno (x
)], file
);
585 print_operand_address (file
, x
);
596 /* Output assembly language output for the address ADDR to FILE. */
599 print_operand_address (file
, addr
)
603 switch (GET_CODE (addr
))
606 fprintf (file
, "0[");
607 print_operand (file
, addr
, 0);
611 if (GET_CODE (XEXP (addr
, 0)) == REG
)
614 fprintf (file
, "lo(");
615 print_operand (file
, XEXP (addr
, 1), 0);
616 fprintf (file
, ")[");
617 print_operand (file
, XEXP (addr
, 0), 0);
622 if (GET_CODE (XEXP (addr
, 0)) == REG
623 || GET_CODE (XEXP (addr
, 0)) == SUBREG
)
626 print_operand (file
, XEXP (addr
, 1), 0);
628 print_operand (file
, XEXP (addr
, 0), 0);
633 print_operand (file
, XEXP (addr
, 0), 0);
635 print_operand (file
, XEXP (addr
, 1), 0);
639 if (ENCODED_NAME_P (XSTR (addr
, 0)))
641 const char *name
= XSTR (addr
, 0);
642 const char *off_name
;
643 const char *reg_name
;
645 if (ZDA_NAME_P (name
))
650 else if (SDA_NAME_P (name
))
655 else if (TDA_NAME_P (name
))
663 fprintf (file
, "%s(", off_name
);
664 output_addr_const (file
, addr
);
665 fprintf (file
, ")[%s]", reg_name
);
668 output_addr_const (file
, addr
);
671 if (special_symbolref_operand (addr
, VOIDmode
))
673 const char *name
= XSTR (XEXP (XEXP (addr
, 0), 0), 0);
674 const char *off_name
;
675 const char *reg_name
;
677 if (ZDA_NAME_P (name
))
682 else if (SDA_NAME_P (name
))
687 else if (TDA_NAME_P (name
))
695 fprintf (file
, "%s(", off_name
);
696 output_addr_const (file
, addr
);
697 fprintf (file
, ")[%s]", reg_name
);
700 output_addr_const (file
, addr
);
703 output_addr_const (file
, addr
);
708 /* When assemble_integer is used to emit the offsets for a switch
709 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
710 output_addr_const will normally barf at this, but it is OK to omit
711 the truncate and just emit the difference of the two labels. The
712 .hword directive will automatically handle the truncation for us.
714 Returns 1 if rtx was handled, 0 otherwise. */
717 v850_output_addr_const_extra (file
, x
)
721 if (GET_CODE (x
) != TRUNCATE
)
726 /* We must also handle the case where the switch table was passed a
727 constant value and so has been collapsed. In this case the first
728 label will have been deleted. In such a case it is OK to emit
729 nothing, since the table will not be used.
730 (cf gcc.c-torture/compile/990801-1.c). */
731 if (GET_CODE (x
) == MINUS
732 && GET_CODE (XEXP (x
, 0)) == LABEL_REF
733 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == CODE_LABEL
734 && INSN_DELETED_P (XEXP (XEXP (x
, 0), 0)))
737 output_addr_const (file
, x
);
741 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
745 output_move_single (operands
)
748 rtx dst
= operands
[0];
749 rtx src
= operands
[1];
756 else if (GET_CODE (src
) == CONST_INT
)
758 HOST_WIDE_INT value
= INTVAL (src
);
760 if (CONST_OK_FOR_J (value
)) /* Signed 5 bit immediate. */
763 else if (CONST_OK_FOR_K (value
)) /* Signed 16 bit immediate. */
764 return "movea lo(%1),%.,%0";
766 else if (CONST_OK_FOR_L (value
)) /* Upper 16 bits were set. */
767 return "movhi hi(%1),%.,%0";
769 /* A random constant. */
770 else if (TARGET_V850E
)
773 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
776 else if (GET_CODE (src
) == CONST_DOUBLE
&& GET_MODE (src
) == SFmode
)
778 HOST_WIDE_INT high
, low
;
780 const_double_split (src
, &high
, &low
);
782 if (CONST_OK_FOR_J (high
)) /* Signed 5 bit immediate. */
785 else if (CONST_OK_FOR_K (high
)) /* Signed 16 bit immediate. */
786 return "movea lo(%F1),%.,%0";
788 else if (CONST_OK_FOR_L (high
)) /* Upper 16 bits were set. */
789 return "movhi hi(%F1),%.,%0";
791 /* A random constant. */
792 else if (TARGET_V850E
)
796 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
799 else if (GET_CODE (src
) == MEM
)
800 return "%S1ld%W1 %1,%0";
802 else if (special_symbolref_operand (src
, VOIDmode
))
803 return "movea %O1(%P1),%Q1,%0";
805 else if (GET_CODE (src
) == LABEL_REF
806 || GET_CODE (src
) == SYMBOL_REF
807 || GET_CODE (src
) == CONST
)
810 return "mov hilo(%1),%0";
812 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
815 else if (GET_CODE (src
) == HIGH
)
816 return "movhi hi(%1),%.,%0";
818 else if (GET_CODE (src
) == LO_SUM
)
820 operands
[2] = XEXP (src
, 0);
821 operands
[3] = XEXP (src
, 1);
822 return "movea lo(%3),%2,%0";
826 else if (GET_CODE (dst
) == MEM
)
829 return "%S0st%W0 %1,%0";
831 else if (GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
832 return "%S0st%W0 %.,%0";
834 else if (GET_CODE (src
) == CONST_DOUBLE
835 && CONST0_RTX (GET_MODE (dst
)) == src
)
836 return "%S0st%W0 %.,%0";
839 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode
, dst
, src
));
844 /* Return appropriate code to load up an 8 byte integer or
845 floating point value */
848 output_move_double (operands
)
851 enum machine_mode mode
= GET_MODE (operands
[0]);
852 rtx dst
= operands
[0];
853 rtx src
= operands
[1];
855 if (register_operand (dst
, mode
)
856 && register_operand (src
, mode
))
858 if (REGNO (src
) + 1 == REGNO (dst
))
859 return "mov %R1,%R0\n\tmov %1,%0";
861 return "mov %1,%0\n\tmov %R1,%R0";
865 if (GET_CODE (dst
) == MEM
866 && ((GET_CODE (src
) == CONST_INT
&& INTVAL (src
) == 0)
867 || (GET_CODE (src
) == CONST_DOUBLE
&& CONST_DOUBLE_OK_FOR_G (src
))))
868 return "st.w %.,%0\n\tst.w %.,%R0";
870 if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
872 HOST_WIDE_INT high_low
[2];
876 if (GET_CODE (src
) == CONST_DOUBLE
)
877 const_double_split (src
, &high_low
[1], &high_low
[0]);
880 high_low
[0] = INTVAL (src
);
881 high_low
[1] = (INTVAL (src
) >= 0) ? 0 : -1;
884 for (i
= 0; i
< 2; i
++)
886 xop
[0] = gen_rtx_REG (SImode
, REGNO (dst
)+i
);
887 xop
[1] = GEN_INT (high_low
[i
]);
888 output_asm_insn (output_move_single (xop
), xop
);
894 if (GET_CODE (src
) == MEM
)
897 int dreg
= REGNO (dst
);
898 rtx inside
= XEXP (src
, 0);
900 if (GET_CODE (inside
) == REG
)
901 ptrreg
= REGNO (inside
);
902 else if (GET_CODE (inside
) == SUBREG
)
903 ptrreg
= subreg_regno (inside
);
904 else if (GET_CODE (inside
) == PLUS
)
905 ptrreg
= REGNO (XEXP (inside
, 0));
906 else if (GET_CODE (inside
) == LO_SUM
)
907 ptrreg
= REGNO (XEXP (inside
, 0));
910 return "ld.w %R1,%R0\n\tld.w %1,%0";
913 if (GET_CODE (src
) == MEM
)
914 return "ld.w %1,%0\n\tld.w %R1,%R0";
916 if (GET_CODE (dst
) == MEM
)
917 return "st.w %1,%0\n\tst.w %R1,%R0";
919 return "mov %1,%0\n\tmov %R1,%R0";
923 /* Return maximum offset supported for a short EP memory reference of mode
924 MODE and signedness UNSIGNEDP. */
927 ep_memory_offset (mode
, unsignedp
)
928 enum machine_mode mode
;
929 int ATTRIBUTE_UNUSED unsignedp
;
936 if (TARGET_SMALL_SLD
)
937 max_offset
= (1 << 4);
938 else if (TARGET_V850E
939 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
940 || (! unsignedp
&& TARGET_US_BIT_SET
)))
941 max_offset
= (1 << 4);
943 max_offset
= (1 << 7);
947 if (TARGET_SMALL_SLD
)
948 max_offset
= (1 << 5);
949 else if (TARGET_V850E
950 && ( ( unsignedp
&& ! TARGET_US_BIT_SET
)
951 || (! unsignedp
&& TARGET_US_BIT_SET
)))
952 max_offset
= (1 << 5);
954 max_offset
= (1 << 8);
959 max_offset
= (1 << 8);
969 /* Return true if OP is a valid short EP memory reference */
972 ep_memory_operand (op
, mode
, unsigned_load
)
974 enum machine_mode mode
;
981 if (GET_CODE (op
) != MEM
)
984 max_offset
= ep_memory_offset (mode
, unsigned_load
);
986 mask
= GET_MODE_SIZE (mode
) - 1;
989 if (GET_CODE (addr
) == CONST
)
990 addr
= XEXP (addr
, 0);
992 switch (GET_CODE (addr
))
998 return TDA_NAME_P (XSTR (addr
, 0));
1001 return REGNO (addr
) == EP_REGNUM
;
1004 op0
= XEXP (addr
, 0);
1005 op1
= XEXP (addr
, 1);
1006 if (GET_CODE (op1
) == CONST_INT
1007 && INTVAL (op1
) < max_offset
1008 && INTVAL (op1
) >= 0
1009 && (INTVAL (op1
) & mask
) == 0)
1011 if (GET_CODE (op0
) == REG
&& REGNO (op0
) == EP_REGNUM
)
1014 if (GET_CODE (op0
) == SYMBOL_REF
&& TDA_NAME_P (XSTR (op0
, 0)))
1023 /* Return true if OP is either a register or 0 */
1026 reg_or_0_operand (op
, mode
)
1028 enum machine_mode mode
;
1030 if (GET_CODE (op
) == CONST_INT
)
1031 return INTVAL (op
) == 0;
1033 else if (GET_CODE (op
) == CONST_DOUBLE
)
1034 return CONST_DOUBLE_OK_FOR_G (op
);
1037 return register_operand (op
, mode
);
1040 /* Return true if OP is either a register or a signed five bit integer */
1043 reg_or_int5_operand (op
, mode
)
1045 enum machine_mode mode
;
1047 if (GET_CODE (op
) == CONST_INT
)
1048 return CONST_OK_FOR_J (INTVAL (op
));
1051 return register_operand (op
, mode
);
1054 /* Return true if OP is either a register or a signed nine bit integer. */
1057 reg_or_int9_operand (op
, mode
)
1059 enum machine_mode mode
;
1061 if (GET_CODE (op
) == CONST_INT
)
1062 return CONST_OK_FOR_O (INTVAL (op
));
1064 return register_operand (op
, mode
);
1067 /* Return true if OP is either a register or a const integer. */
1070 reg_or_const_operand (op
, mode
)
1072 enum machine_mode mode
;
1074 if (GET_CODE (op
) == CONST_INT
)
1077 return register_operand (op
, mode
);
1080 /* Return true if OP is a valid call operand. */
1083 call_address_operand (op
, mode
)
1085 enum machine_mode ATTRIBUTE_UNUSED mode
;
1087 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1088 if (TARGET_LONG_CALLS
)
1089 return GET_CODE (op
) == REG
;
1090 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == REG
);
1094 special_symbolref_operand (op
, mode
)
1096 enum machine_mode ATTRIBUTE_UNUSED mode
;
1098 if (GET_CODE (op
) == SYMBOL_REF
)
1099 return ENCODED_NAME_P (XSTR (op
, 0));
1101 else if (GET_CODE (op
) == CONST
)
1102 return (GET_CODE (XEXP (op
, 0)) == PLUS
1103 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
1104 && ENCODED_NAME_P (XSTR (XEXP (XEXP (op
, 0), 0), 0))
1105 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
1106 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op
, 0), 1))));
1112 movsi_source_operand (op
, mode
)
1114 enum machine_mode mode
;
1116 /* Some constants, as well as symbolic operands
1117 must be done with HIGH & LO_SUM patterns. */
1119 && GET_CODE (op
) != HIGH
1120 && GET_CODE (op
) != CONSTANT_P_RTX
1121 && !(GET_CODE (op
) == CONST_INT
1122 && (CONST_OK_FOR_J (INTVAL (op
))
1123 || CONST_OK_FOR_K (INTVAL (op
))
1124 || CONST_OK_FOR_L (INTVAL (op
)))))
1125 return special_symbolref_operand (op
, mode
);
1127 return general_operand (op
, mode
);
1131 power_of_two_operand (op
, mode
)
1133 enum machine_mode ATTRIBUTE_UNUSED mode
;
1135 if (GET_CODE (op
) != CONST_INT
)
1138 if (exact_log2 (INTVAL (op
)) == -1)
1144 not_power_of_two_operand (op
, mode
)
1146 enum machine_mode mode
;
1152 else if (mode
== HImode
)
1154 else if (mode
== SImode
)
1159 if (GET_CODE (op
) != CONST_INT
)
1162 if (exact_log2 (~INTVAL (op
) & mask
) == -1)
1168 /* Substitute memory references involving a pointer, to use the ep pointer,
1169 taking care to save and preserve the ep. */
1172 substitute_ep_register (first_insn
, last_insn
, uses
, regno
, p_r1
, p_ep
)
1180 rtx reg
= gen_rtx_REG (Pmode
, regno
);
1185 regs_ever_live
[1] = 1;
1186 *p_r1
= gen_rtx_REG (Pmode
, 1);
1187 *p_ep
= gen_rtx_REG (Pmode
, 30);
1192 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1193 2 * (uses
- 3), uses
, reg_names
[regno
],
1194 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
1195 INSN_UID (first_insn
), INSN_UID (last_insn
));
1197 if (GET_CODE (first_insn
) == NOTE
)
1198 first_insn
= next_nonnote_insn (first_insn
);
1200 last_insn
= next_nonnote_insn (last_insn
);
1201 for (insn
= first_insn
; insn
&& insn
!= last_insn
; insn
= NEXT_INSN (insn
))
1203 if (GET_CODE (insn
) == INSN
)
1205 rtx pattern
= single_set (insn
);
1207 /* Replace the memory references. */
1211 /* Memory operands are signed by default. */
1212 int unsignedp
= FALSE
;
1214 if (GET_CODE (SET_DEST (pattern
)) == MEM
1215 && GET_CODE (SET_SRC (pattern
)) == MEM
)
1218 else if (GET_CODE (SET_DEST (pattern
)) == MEM
)
1219 p_mem
= &SET_DEST (pattern
);
1221 else if (GET_CODE (SET_SRC (pattern
)) == MEM
)
1222 p_mem
= &SET_SRC (pattern
);
1224 else if (GET_CODE (SET_SRC (pattern
)) == SIGN_EXTEND
1225 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1226 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1228 else if (GET_CODE (SET_SRC (pattern
)) == ZERO_EXTEND
1229 && GET_CODE (XEXP (SET_SRC (pattern
), 0)) == MEM
)
1231 p_mem
= &XEXP (SET_SRC (pattern
), 0);
1239 rtx addr
= XEXP (*p_mem
, 0);
1241 if (GET_CODE (addr
) == REG
&& REGNO (addr
) == (unsigned) regno
)
1242 *p_mem
= change_address (*p_mem
, VOIDmode
, *p_ep
);
1244 else if (GET_CODE (addr
) == PLUS
1245 && GET_CODE (XEXP (addr
, 0)) == REG
1246 && REGNO (XEXP (addr
, 0)) == (unsigned) regno
1247 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1248 && ((INTVAL (XEXP (addr
, 1)))
1249 < ep_memory_offset (GET_MODE (*p_mem
),
1251 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1252 *p_mem
= change_address (*p_mem
, VOIDmode
,
1253 gen_rtx_PLUS (Pmode
,
1261 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1262 insn
= prev_nonnote_insn (first_insn
);
1263 if (insn
&& GET_CODE (insn
) == INSN
1264 && GET_CODE (PATTERN (insn
)) == SET
1265 && SET_DEST (PATTERN (insn
)) == *p_ep
1266 && SET_SRC (PATTERN (insn
)) == *p_r1
)
1269 emit_insn_before (gen_rtx_SET (Pmode
, *p_r1
, *p_ep
), first_insn
);
1271 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, reg
), first_insn
);
1272 emit_insn_before (gen_rtx_SET (Pmode
, *p_ep
, *p_r1
), last_insn
);
1276 /* In rare cases, correct code generation requires extra machine
1277 dependent processing between the second jump optimization pass and
1278 delayed branch scheduling. On those machines, define this macro
1279 as a C statement to act on the code starting at INSN.
1281 On the 850, we use it to implement the -mep mode to copy heavily used
1282 pointers to ep to use the implicit addressing. */
1284 void v850_reorg (start_insn
)
1293 regs
[FIRST_PSEUDO_REGISTER
];
1302 /* If not ep mode, just return now. */
1306 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1309 regs
[i
].first_insn
= NULL_RTX
;
1310 regs
[i
].last_insn
= NULL_RTX
;
1313 for (insn
= start_insn
; insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1315 switch (GET_CODE (insn
))
1317 /* End of basic block */
1324 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1326 if (max_uses
< regs
[i
].uses
)
1328 max_uses
= regs
[i
].uses
;
1334 substitute_ep_register (regs
[max_regno
].first_insn
,
1335 regs
[max_regno
].last_insn
,
1336 max_uses
, max_regno
, &r1
, &ep
);
1340 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1343 regs
[i
].first_insn
= NULL_RTX
;
1344 regs
[i
].last_insn
= NULL_RTX
;
1352 pattern
= single_set (insn
);
1354 /* See if there are any memory references we can shorten */
1357 rtx src
= SET_SRC (pattern
);
1358 rtx dest
= SET_DEST (pattern
);
1360 /* Memory operands are signed by default. */
1361 int unsignedp
= FALSE
;
1363 /* We might have (SUBREG (MEM)) here, so just get rid of the
1364 subregs to make this code simpler. */
1365 if (GET_CODE (dest
) == SUBREG
1366 && (GET_CODE (SUBREG_REG (dest
)) == MEM
1367 || GET_CODE (SUBREG_REG (dest
)) == REG
))
1368 alter_subreg (&dest
);
1369 if (GET_CODE (src
) == SUBREG
1370 && (GET_CODE (SUBREG_REG (src
)) == MEM
1371 || GET_CODE (SUBREG_REG (src
)) == REG
))
1372 alter_subreg (&src
);
1374 if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == MEM
)
1377 else if (GET_CODE (dest
) == MEM
)
1380 else if (GET_CODE (src
) == MEM
)
1383 else if (GET_CODE (src
) == SIGN_EXTEND
1384 && GET_CODE (XEXP (src
, 0)) == MEM
)
1385 mem
= XEXP (src
, 0);
1387 else if (GET_CODE (src
) == ZERO_EXTEND
1388 && GET_CODE (XEXP (src
, 0)) == MEM
)
1390 mem
= XEXP (src
, 0);
1396 if (mem
&& ep_memory_operand (mem
, GET_MODE (mem
), unsignedp
))
1399 else if (!use_ep
&& mem
1400 && GET_MODE_SIZE (GET_MODE (mem
)) <= UNITS_PER_WORD
)
1402 rtx addr
= XEXP (mem
, 0);
1406 if (GET_CODE (addr
) == REG
)
1409 regno
= REGNO (addr
);
1412 else if (GET_CODE (addr
) == PLUS
1413 && GET_CODE (XEXP (addr
, 0)) == REG
1414 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1415 && ((INTVAL (XEXP (addr
, 1)))
1416 < ep_memory_offset (GET_MODE (mem
), unsignedp
))
1417 && ((INTVAL (XEXP (addr
, 1))) >= 0))
1420 regno
= REGNO (XEXP (addr
, 0));
1429 regs
[regno
].last_insn
= insn
;
1430 if (!regs
[regno
].first_insn
)
1431 regs
[regno
].first_insn
= insn
;
1435 /* Loading up a register in the basic block zaps any savings
1437 if (GET_CODE (dest
) == REG
)
1439 enum machine_mode mode
= GET_MODE (dest
);
1443 regno
= REGNO (dest
);
1444 endregno
= regno
+ HARD_REGNO_NREGS (regno
, mode
);
1448 /* See if we can use the pointer before this
1453 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1455 if (max_uses
< regs
[i
].uses
)
1457 max_uses
= regs
[i
].uses
;
1463 && max_regno
>= regno
1464 && max_regno
< endregno
)
1466 substitute_ep_register (regs
[max_regno
].first_insn
,
1467 regs
[max_regno
].last_insn
,
1468 max_uses
, max_regno
, &r1
,
1471 /* Since we made a substitution, zap all remembered
1473 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1476 regs
[i
].first_insn
= NULL_RTX
;
1477 regs
[i
].last_insn
= NULL_RTX
;
1482 for (i
= regno
; i
< endregno
; i
++)
1485 regs
[i
].first_insn
= NULL_RTX
;
1486 regs
[i
].last_insn
= NULL_RTX
;
1495 /* # of registers saved by the interrupt handler. */
1496 #define INTERRUPT_FIXED_NUM 4
1498 /* # of bytes for registers saved by the interrupt handler. */
1499 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1501 /* # of registers saved in register parameter area. */
1502 #define INTERRUPT_REGPARM_NUM 4
1503 /* # of words saved for other registers. */
1504 #define INTERRUPT_ALL_SAVE_NUM \
1505 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1507 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1510 compute_register_save_size (p_reg_saved
)
1515 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1516 int call_p
= regs_ever_live
[LINK_POINTER_REGNUM
];
1519 /* Count the return pointer if we need to save it. */
1520 if (current_function_profile
&& !call_p
)
1521 regs_ever_live
[LINK_POINTER_REGNUM
] = call_p
= 1;
1523 /* Count space for the register saves. */
1524 if (interrupt_handler
)
1526 for (i
= 0; i
<= 31; i
++)
1530 if (regs_ever_live
[i
] || call_p
)
1533 reg_saved
|= 1L << i
;
1537 /* We don't save/restore r0 or the stack pointer */
1539 case STACK_POINTER_REGNUM
:
1542 /* For registers with fixed use, we save them, set them to the
1543 appropriate value, and then restore them.
1544 These registers are handled specially, so don't list them
1545 on the list of registers to save in the prologue. */
1546 case 1: /* temp used to hold ep */
1548 case 10: /* temp used to call interrupt save/restore */
1549 case EP_REGNUM
: /* ep */
1556 /* Find the first register that needs to be saved. */
1557 for (i
= 0; i
<= 31; i
++)
1558 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1559 || i
== LINK_POINTER_REGNUM
))
1562 /* If it is possible that an out-of-line helper function might be
1563 used to generate the prologue for the current function, then we
1564 need to cover the possibility that such a helper function will
1565 be used, despite the fact that there might be gaps in the list of
1566 registers that need to be saved. To detect this we note that the
1567 helper functions always push at least register r29 (provided
1568 that the function is not an interrupt handler). */
1570 if (TARGET_PROLOG_FUNCTION
1571 && (i
== 2 || ((i
>= 20) && (i
< 30))))
1576 reg_saved
|= 1L << i
;
1581 /* Helper functions save all registers between the starting
1582 register and the last register, regardless of whether they
1583 are actually used by the function or not. */
1584 for (; i
<= 29; i
++)
1587 reg_saved
|= 1L << i
;
1590 if (regs_ever_live
[LINK_POINTER_REGNUM
])
1593 reg_saved
|= 1L << LINK_POINTER_REGNUM
;
1598 for (; i
<= 31; i
++)
1599 if (regs_ever_live
[i
] && ((! call_used_regs
[i
])
1600 || i
== LINK_POINTER_REGNUM
))
1603 reg_saved
|= 1L << i
;
1609 *p_reg_saved
= reg_saved
;
1615 compute_frame_size (size
, p_reg_saved
)
1620 + compute_register_save_size (p_reg_saved
)
1621 + current_function_outgoing_args_size
);
1630 unsigned int size
= get_frame_size ();
1631 unsigned int actual_fsize
;
1632 unsigned int init_stack_alloc
= 0;
1635 unsigned int num_save
;
1636 unsigned int default_stack
;
1638 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1641 actual_fsize
= compute_frame_size (size
, ®_saved
);
1643 /* Save/setup global registers for interrupt functions right now. */
1644 if (interrupt_handler
)
1646 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1647 emit_insn (gen_callt_save_interrupt ());
1649 emit_insn (gen_save_interrupt ());
1651 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1653 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1654 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1657 /* Save arg registers to the stack if necessary. */
1658 else if (current_function_args_info
.anonymous_args
)
1660 if (TARGET_PROLOG_FUNCTION
)
1662 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1663 emit_insn (gen_save_r6_r9_v850e ());
1665 emit_insn (gen_save_r6_r9 ());
1670 for (i
= 6; i
< 10; i
++)
1672 emit_move_insn (gen_rtx_MEM (SImode
,
1673 plus_constant (stack_pointer_rtx
,
1675 gen_rtx_REG (SImode
, i
));
1681 /* Identify all of the saved registers. */
1684 for (i
= 1; i
< 31; i
++)
1686 if (((1L << i
) & reg_saved
) != 0)
1687 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, i
);
1690 /* If the return pointer is saved, the helper functions also allocate
1691 16 bytes of stack for arguments to be saved in. */
1692 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1694 save_regs
[num_save
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1698 /* See if we have an insn that allocates stack space and saves the particular
1699 registers we want to. */
1700 save_all
= NULL_RTX
;
1701 if (TARGET_PROLOG_FUNCTION
&& num_save
> 0 && actual_fsize
>= default_stack
)
1703 int alloc_stack
= (4 * num_save
) + default_stack
;
1704 int unalloc_stack
= actual_fsize
- alloc_stack
;
1705 int save_func_len
= 4;
1706 int save_normal_len
;
1709 save_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1711 /* see if we would have used ep to save the stack */
1712 if (TARGET_EP
&& num_save
> 3 && (unsigned)actual_fsize
< 255)
1713 save_normal_len
= (3 * 2) + (2 * num_save
);
1715 save_normal_len
= 4 * num_save
;
1717 save_normal_len
+= CONST_OK_FOR_J (actual_fsize
) ? 2 : 4;
1719 /* Don't bother checking if we don't actually save any space.
1720 This happens for instance if one register is saved and additional
1721 stack space is allocated. */
1722 if (save_func_len
< save_normal_len
)
1724 save_all
= gen_rtx_PARALLEL
1726 rtvec_alloc (num_save
+ (TARGET_V850
? 2 : 1)));
1728 XVECEXP (save_all
, 0, 0)
1729 = gen_rtx_SET (VOIDmode
,
1731 plus_constant (stack_pointer_rtx
, -alloc_stack
));
1735 XVECEXP (save_all
, 0, num_save
+1)
1736 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (Pmode
, 10));
1739 offset
= - default_stack
;
1740 for (i
= 0; i
< num_save
; i
++)
1742 XVECEXP (save_all
, 0, i
+1)
1743 = gen_rtx_SET (VOIDmode
,
1745 plus_constant (stack_pointer_rtx
,
1751 code
= recog (save_all
, NULL_RTX
, NULL
);
1754 rtx insn
= emit_insn (save_all
);
1755 INSN_CODE (insn
) = code
;
1756 actual_fsize
-= alloc_stack
;
1760 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1761 save_normal_len
- save_func_len
,
1762 save_normal_len
, save_func_len
,
1763 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1766 save_all
= NULL_RTX
;
1770 /* If no prolog save function is available, store the registers the old
1771 fashioned way (one by one). */
1774 /* Special case interrupt functions that save all registers for a call. */
1775 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1777 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
1778 emit_insn (gen_callt_save_all_interrupt ());
1780 emit_insn (gen_save_all_interrupt ());
1784 /* If the stack is too big, allocate it in chunks so we can do the
1785 register saves. We use the register save size so we use the ep
1787 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1788 init_stack_alloc
= compute_register_save_size (NULL
);
1790 init_stack_alloc
= actual_fsize
;
1792 /* Save registers at the beginning of the stack frame */
1793 offset
= init_stack_alloc
- 4;
1795 if (init_stack_alloc
)
1796 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1798 GEN_INT (-init_stack_alloc
)));
1800 /* Save the return pointer first. */
1801 if (num_save
> 0 && REGNO (save_regs
[num_save
-1]) == LINK_POINTER_REGNUM
)
1803 emit_move_insn (gen_rtx_MEM (SImode
,
1804 plus_constant (stack_pointer_rtx
,
1806 save_regs
[--num_save
]);
1810 for (i
= 0; i
< num_save
; i
++)
1812 emit_move_insn (gen_rtx_MEM (SImode
,
1813 plus_constant (stack_pointer_rtx
,
1821 /* Allocate the rest of the stack that was not allocated above (either it is
1822 > 32K or we just called a function to save the registers and needed more
1824 if (actual_fsize
> init_stack_alloc
)
1826 int diff
= actual_fsize
- init_stack_alloc
;
1827 if (CONST_OK_FOR_K (diff
))
1828 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1833 rtx reg
= gen_rtx_REG (Pmode
, 12);
1834 emit_move_insn (reg
, GEN_INT (-diff
));
1835 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, reg
));
1839 /* If we need a frame pointer, set it up now. */
1840 if (frame_pointer_needed
)
1841 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1850 unsigned int size
= get_frame_size ();
1852 unsigned int actual_fsize
= compute_frame_size (size
, ®_saved
);
1853 unsigned int init_stack_free
= 0;
1854 rtx restore_regs
[32];
1856 unsigned int num_restore
;
1857 unsigned int default_stack
;
1859 int interrupt_handler
= v850_interrupt_function_p (current_function_decl
);
1861 /* Eliminate the initial stack stored by interrupt functions. */
1862 if (interrupt_handler
)
1864 actual_fsize
-= INTERRUPT_FIXED_SAVE_SIZE
;
1865 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1866 actual_fsize
-= INTERRUPT_ALL_SAVE_SIZE
;
1869 /* Cut off any dynamic stack created. */
1870 if (frame_pointer_needed
)
1871 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
1873 /* Identify all of the saved registers. */
1876 for (i
= 1; i
< 31; i
++)
1878 if (((1L << i
) & reg_saved
) != 0)
1879 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, i
);
1882 /* If the return pointer is saved, the helper functions also allocate
1883 16 bytes of stack for arguments to be saved in. */
1884 if (((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
1886 restore_regs
[num_restore
++] = gen_rtx_REG (Pmode
, LINK_POINTER_REGNUM
);
1890 /* See if we have an insn that restores the particular registers we
1892 restore_all
= NULL_RTX
;
1894 if (TARGET_PROLOG_FUNCTION
1896 && actual_fsize
>= default_stack
1897 && !interrupt_handler
)
1899 int alloc_stack
= (4 * num_restore
) + default_stack
;
1900 int unalloc_stack
= actual_fsize
- alloc_stack
;
1901 int restore_func_len
= 4;
1902 int restore_normal_len
;
1905 restore_func_len
+= CONST_OK_FOR_J (unalloc_stack
) ? 2 : 4;
1907 /* See if we would have used ep to restore the registers. */
1908 if (TARGET_EP
&& num_restore
> 3 && (unsigned)actual_fsize
< 255)
1909 restore_normal_len
= (3 * 2) + (2 * num_restore
);
1911 restore_normal_len
= 4 * num_restore
;
1913 restore_normal_len
+= (CONST_OK_FOR_J (actual_fsize
) ? 2 : 4) + 2;
1915 /* Don't bother checking if we don't actually save any space. */
1916 if (restore_func_len
< restore_normal_len
)
1918 restore_all
= gen_rtx_PARALLEL (VOIDmode
,
1919 rtvec_alloc (num_restore
+ 2));
1920 XVECEXP (restore_all
, 0, 0) = gen_rtx_RETURN (VOIDmode
);
1921 XVECEXP (restore_all
, 0, 1)
1922 = gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
1923 gen_rtx_PLUS (Pmode
,
1925 GEN_INT (alloc_stack
)));
1927 offset
= alloc_stack
- 4;
1928 for (i
= 0; i
< num_restore
; i
++)
1930 XVECEXP (restore_all
, 0, i
+2)
1931 = gen_rtx_SET (VOIDmode
,
1934 plus_constant (stack_pointer_rtx
,
1939 code
= recog (restore_all
, NULL_RTX
, NULL
);
1945 actual_fsize
-= alloc_stack
;
1948 if (CONST_OK_FOR_K (actual_fsize
))
1949 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1951 GEN_INT (actual_fsize
)));
1954 rtx reg
= gen_rtx_REG (Pmode
, 12);
1955 emit_move_insn (reg
, GEN_INT (actual_fsize
));
1956 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1962 insn
= emit_jump_insn (restore_all
);
1963 INSN_CODE (insn
) = code
;
1967 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1968 restore_normal_len
- restore_func_len
,
1969 restore_normal_len
, restore_func_len
,
1970 IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)));
1973 restore_all
= NULL_RTX
;
1977 /* If no epilog save function is available, restore the registers the
1978 old fashioned way (one by one). */
1981 /* If the stack is large, we need to cut it down in 2 pieces. */
1982 if (actual_fsize
&& !CONST_OK_FOR_K (-actual_fsize
))
1983 init_stack_free
= 4 * num_restore
;
1985 init_stack_free
= actual_fsize
;
1987 /* Deallocate the rest of the stack if it is > 32K. */
1988 if (actual_fsize
> init_stack_free
)
1992 diff
= actual_fsize
- ((interrupt_handler
) ? 0 : init_stack_free
);
1994 if (CONST_OK_FOR_K (diff
))
1995 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2000 rtx reg
= gen_rtx_REG (Pmode
, 12);
2001 emit_move_insn (reg
, GEN_INT (diff
));
2002 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2008 /* Special case interrupt functions that save all registers
2010 if (interrupt_handler
&& ((1L << LINK_POINTER_REGNUM
) & reg_saved
) != 0)
2012 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2013 emit_insn (gen_callt_restore_all_interrupt ());
2015 emit_insn (gen_restore_all_interrupt ());
2019 /* Restore registers from the beginning of the stack frame. */
2020 offset
= init_stack_free
- 4;
2022 /* Restore the return pointer first. */
2024 && REGNO (restore_regs
[num_restore
- 1]) == LINK_POINTER_REGNUM
)
2026 emit_move_insn (restore_regs
[--num_restore
],
2027 gen_rtx_MEM (SImode
,
2028 plus_constant (stack_pointer_rtx
,
2033 for (i
= 0; i
< num_restore
; i
++)
2035 emit_move_insn (restore_regs
[i
],
2036 gen_rtx_MEM (SImode
,
2037 plus_constant (stack_pointer_rtx
,
2040 emit_insn (gen_rtx_USE (VOIDmode
, restore_regs
[i
]));
2044 /* Cut back the remainder of the stack. */
2045 if (init_stack_free
)
2046 emit_insn (gen_addsi3 (stack_pointer_rtx
,
2048 GEN_INT (init_stack_free
)));
2051 /* And return or use reti for interrupt handlers. */
2052 if (interrupt_handler
)
2054 if (TARGET_V850E
&& ! TARGET_DISABLE_CALLT
)
2055 emit_insn (gen_callt_return_interrupt ());
2057 emit_jump_insn (gen_return_interrupt ());
2059 else if (actual_fsize
)
2060 emit_jump_insn (gen_return_internal ());
2062 emit_jump_insn (gen_return ());
2065 v850_interrupt_cache_p
= FALSE
;
2066 v850_interrupt_p
= FALSE
;
2070 /* Update the condition code from the insn. */
2073 notice_update_cc (body
, insn
)
2077 switch (get_attr_cc (insn
))
2080 /* Insn does not affect CC at all. */
2084 /* Insn does not change CC, but the 0'th operand has been changed. */
2085 if (cc_status
.value1
!= 0
2086 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2087 cc_status
.value1
= 0;
2091 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2092 V,C is in an unusable state. */
2094 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2095 cc_status
.value1
= recog_data
.operand
[0];
2099 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2100 C is in an unusable state. */
2102 cc_status
.flags
|= CC_NO_CARRY
;
2103 cc_status
.value1
= recog_data
.operand
[0];
2107 /* The insn is a compare instruction. */
2109 cc_status
.value1
= SET_SRC (body
);
2113 /* Insn doesn't leave CC in a usable state. */
2119 /* Retrieve the data area that has been chosen for the given decl. */
2122 v850_get_data_area (decl
)
2125 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2126 return DATA_AREA_SDA
;
2128 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2129 return DATA_AREA_TDA
;
2131 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl
)) != NULL_TREE
)
2132 return DATA_AREA_ZDA
;
2134 return DATA_AREA_NORMAL
;
2137 /* Store the indicated data area in the decl's attributes. */
2140 v850_set_data_area (decl
, data_area
)
2142 v850_data_area data_area
;
2148 case DATA_AREA_SDA
: name
= get_identifier ("sda"); break;
2149 case DATA_AREA_TDA
: name
= get_identifier ("tda"); break;
2150 case DATA_AREA_ZDA
: name
= get_identifier ("zda"); break;
2155 DECL_ATTRIBUTES (decl
) = tree_cons
2156 (name
, NULL
, DECL_ATTRIBUTES (decl
));
2159 const struct attribute_spec v850_attribute_table
[] =
2161 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2162 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2163 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute
},
2164 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2165 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2166 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute
},
2167 { NULL
, 0, 0, false, false, false, NULL
}
2170 /* Handle an "interrupt" attribute; arguments as in
2171 struct attribute_spec.handler. */
2173 v850_handle_interrupt_attribute (node
, name
, args
, flags
, no_add_attrs
)
2176 tree args ATTRIBUTE_UNUSED
;
2177 int flags ATTRIBUTE_UNUSED
;
2180 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2182 warning ("`%s' attribute only applies to functions",
2183 IDENTIFIER_POINTER (name
));
2184 *no_add_attrs
= true;
2190 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2191 struct attribute_spec.handler. */
2193 v850_handle_data_area_attribute (node
, name
, args
, flags
, no_add_attrs
)
2196 tree args ATTRIBUTE_UNUSED
;
2197 int flags ATTRIBUTE_UNUSED
;
2200 v850_data_area data_area
;
2201 v850_data_area area
;
2204 /* Implement data area attribute. */
2205 if (is_attribute_p ("sda", name
))
2206 data_area
= DATA_AREA_SDA
;
2207 else if (is_attribute_p ("tda", name
))
2208 data_area
= DATA_AREA_TDA
;
2209 else if (is_attribute_p ("zda", name
))
2210 data_area
= DATA_AREA_ZDA
;
2214 switch (TREE_CODE (decl
))
2217 if (current_function_decl
!= NULL_TREE
)
2219 error_with_decl (decl
, "\
2220 a data area attribute cannot be specified for local variables");
2221 *no_add_attrs
= true;
2227 area
= v850_get_data_area (decl
);
2228 if (area
!= DATA_AREA_NORMAL
&& data_area
!= area
)
2230 error_with_decl (decl
, "\
2231 data area of '%s' conflicts with previous declaration");
2232 *no_add_attrs
= true;
2244 /* Return nonzero if FUNC is an interrupt function as specified
2245 by the "interrupt" attribute. */
2248 v850_interrupt_function_p (func
)
2254 if (v850_interrupt_cache_p
)
2255 return v850_interrupt_p
;
2257 if (TREE_CODE (func
) != FUNCTION_DECL
)
2260 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
2266 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
2267 ret
= a
!= NULL_TREE
;
2270 /* Its not safe to trust global variables until after function inlining has
2272 if (reload_completed
| reload_in_progress
)
2273 v850_interrupt_p
= ret
;
2280 v850_encode_data_area (decl
)
2283 const char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2284 int len
= strlen (str
);
2287 /* Map explict sections into the appropriate attribute */
2288 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2290 if (DECL_SECTION_NAME (decl
))
2292 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
2294 if (streq (name
, ".zdata") || streq (name
, ".zbss"))
2295 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2297 else if (streq (name
, ".sdata") || streq (name
, ".sbss"))
2298 v850_set_data_area (decl
, DATA_AREA_SDA
);
2300 else if (streq (name
, ".tdata"))
2301 v850_set_data_area (decl
, DATA_AREA_TDA
);
2304 /* If no attribute, support -m{zda,sda,tda}=n */
2307 int size
= int_size_in_bytes (TREE_TYPE (decl
));
2311 else if (size
<= small_memory
[(int) SMALL_MEMORY_TDA
].max
)
2312 v850_set_data_area (decl
, DATA_AREA_TDA
);
2314 else if (size
<= small_memory
[(int) SMALL_MEMORY_SDA
].max
)
2315 v850_set_data_area (decl
, DATA_AREA_SDA
);
2317 else if (size
<= small_memory
[(int) SMALL_MEMORY_ZDA
].max
)
2318 v850_set_data_area (decl
, DATA_AREA_ZDA
);
2321 if (v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2325 newstr
= alloca (len
+ 2);
2327 strcpy (newstr
+ 1, str
);
2329 switch (v850_get_data_area (decl
))
2331 case DATA_AREA_ZDA
: *newstr
= ZDA_NAME_FLAG_CHAR
; break;
2332 case DATA_AREA_TDA
: *newstr
= TDA_NAME_FLAG_CHAR
; break;
2333 case DATA_AREA_SDA
: *newstr
= SDA_NAME_FLAG_CHAR
; break;
2337 XSTR (XEXP (DECL_RTL (decl
), 0), 0) = ggc_alloc_string (newstr
, len
+ 2);
2341 v850_encode_section_info (decl
, first
)
2345 if (first
&& TREE_CODE (decl
) == VAR_DECL
2346 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
2347 v850_encode_data_area (decl
);
2351 v850_strip_name_encoding (str
)
2354 return str
+ (ENCODED_NAME_P (str
) || *str
== '*');
2357 /* Return true if the given RTX is a register which can be restored
2358 by a function epilogue. */
2360 register_is_ok_for_epilogue (op
, mode
)
2362 enum machine_mode ATTRIBUTE_UNUSED mode
;
2364 /* The save/restore routines can only cope with registers 20 - 31. */
2365 return ((GET_CODE (op
) == REG
)
2366 && (((REGNO (op
) >= 20) && REGNO (op
) <= 31)));
2369 /* Return nonzero if the given RTX is suitable for collapsing into
2370 jump to a function epilogue. */
2372 pattern_is_ok_for_epilogue (op
, mode
)
2374 enum machine_mode ATTRIBUTE_UNUSED mode
;
2376 int count
= XVECLEN (op
, 0);
2379 /* If there are no registers to restore then the function epilogue
2384 /* The pattern matching has already established that we are performing a
2385 function epilogue and that we are popping at least one register. We must
2386 now check the remaining entries in the vector to make sure that they are
2387 also register pops. There is no good reason why there should ever be
2388 anything else in this vector, but being paranoid always helps...
2390 The test below performs the C equivalent of this machine description
2393 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2394 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2397 for (i
= 3; i
< count
; i
++)
2399 rtx vector_element
= XVECEXP (op
, 0, i
);
2404 if (GET_CODE (vector_element
) != SET
)
2407 dest
= SET_DEST (vector_element
);
2408 src
= SET_SRC (vector_element
);
2410 if (GET_CODE (dest
) != REG
2411 || GET_MODE (dest
) != SImode
2412 || ! register_is_ok_for_epilogue (dest
, SImode
)
2413 || GET_CODE (src
) != MEM
2414 || GET_MODE (src
) != SImode
)
2417 plus
= XEXP (src
, 0);
2419 if (GET_CODE (plus
) != PLUS
2420 || GET_CODE (XEXP (plus
, 0)) != REG
2421 || GET_MODE (XEXP (plus
, 0)) != SImode
2422 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2423 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2430 /* Construct a JR instruction to a routine that will perform the equivalent of
2431 the RTL passed in as an argument. This RTL is a function epilogue that
2432 pops registers off the stack and possibly releases some extra stack space
2433 as well. The code has already verified that the RTL matches these
2436 construct_restore_jr (op
)
2439 int count
= XVECLEN (op
, 0);
2441 unsigned long int mask
;
2442 unsigned long int first
;
2443 unsigned long int last
;
2445 static char buff
[100]; /* XXX */
2449 error ("bogus JR construction: %d\n", count
);
2453 /* Work out how many bytes to pop off the stack before retrieving
2455 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
2457 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
2459 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
2462 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
2464 /* Each pop will remove 4 bytes from the stack... */
2465 stack_bytes
-= (count
- 2) * 4;
2467 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2468 if (stack_bytes
!= 0 && stack_bytes
!= 16)
2470 error ("bad amount of stack space removal: %d", stack_bytes
);
2474 /* Now compute the bit mask of registers to push. */
2476 for (i
= 2; i
< count
; i
++)
2478 rtx vector_element
= XVECEXP (op
, 0, i
);
2480 if (GET_CODE (vector_element
) != SET
)
2482 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
2484 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
2487 mask
|= 1 << REGNO (SET_DEST (vector_element
));
2490 /* Scan for the first register to pop. */
2491 for (first
= 0; first
< 32; first
++)
2493 if (mask
& (1 << first
))
2500 /* Discover the last register to pop. */
2501 if (mask
& (1 << LINK_POINTER_REGNUM
))
2503 if (stack_bytes
!= 16)
2506 last
= LINK_POINTER_REGNUM
;
2510 if (stack_bytes
!= 0)
2513 if ((mask
& (1 << 29)) == 0)
2519 /* Note, it is possible to have gaps in the register mask.
2520 We ignore this here, and generate a JR anyway. We will
2521 be popping more registers than is strictly necessary, but
2522 it does save code space. */
2524 if (TARGET_LONG_CALLS
)
2529 sprintf (name
, "__return_%s", reg_names
[first
]);
2531 sprintf (name
, "__return_%s_%s", reg_names
[first
], reg_names
[last
]);
2533 sprintf (buff
, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2539 sprintf (buff
, "jr __return_%s", reg_names
[first
]);
2541 sprintf (buff
, "jr __return_%s_%s", reg_names
[first
], reg_names
[last
]);
2548 /* Return nonzero if the given RTX is suitable for collapsing into
2549 a jump to a function prologue. */
2551 pattern_is_ok_for_prologue (op
, mode
)
2553 enum machine_mode ATTRIBUTE_UNUSED mode
;
2555 int count
= XVECLEN (op
, 0);
2559 /* If there are no registers to save then the function prologue
2564 /* The pattern matching has already established that we are adjusting the
2565 stack and pushing at least one register. We must now check that the
2566 remaining entries in the vector to make sure that they are also register
2567 pushes, except for the last entry which should be a CLOBBER of r10.
2569 The test below performs the C equivalent of this machine description
2572 (set (mem:SI (plus:SI (reg:SI 3)
2573 (match_operand:SI 2 "immediate_operand" "i")))
2574 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2578 for (i
= 2; i
< count
- 1; i
++)
2584 vector_element
= XVECEXP (op
, 0, i
);
2586 if (GET_CODE (vector_element
) != SET
)
2589 dest
= SET_DEST (vector_element
);
2590 src
= SET_SRC (vector_element
);
2592 if (GET_CODE (dest
) != MEM
2593 || GET_MODE (dest
) != SImode
2594 || GET_CODE (src
) != REG
2595 || GET_MODE (src
) != SImode
2596 || ! register_is_ok_for_epilogue (src
, SImode
))
2599 plus
= XEXP (dest
, 0);
2601 if ( GET_CODE (plus
) != PLUS
2602 || GET_CODE (XEXP (plus
, 0)) != REG
2603 || GET_MODE (XEXP (plus
, 0)) != SImode
2604 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
2605 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
2608 /* If the register is being pushed somewhere other than the stack
2609 space just acquired by the first operand then abandon this quest.
2610 Note: the test is <= because both values are negative. */
2611 if (INTVAL (XEXP (plus
, 1))
2612 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
2618 /* Make sure that the last entry in the vector is a clobber. */
2619 vector_element
= XVECEXP (op
, 0, i
);
2621 if (GET_CODE (vector_element
) != CLOBBER
2622 || GET_CODE (XEXP (vector_element
, 0)) != REG
2623 || REGNO (XEXP (vector_element
, 0)) != 10)
2629 /* Construct a JARL instruction to a routine that will perform the equivalent
2630 of the RTL passed as a parameter. This RTL is a function prologue that
2631 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2632 some stack space as well. The code has already verified that the RTL
2633 matches these requirements. */
2635 construct_save_jarl (op
)
2638 int count
= XVECLEN (op
, 0);
2640 unsigned long int mask
;
2641 unsigned long int first
;
2642 unsigned long int last
;
2644 static char buff
[100]; /* XXX */
2648 error ("bogus JARL construction: %d\n", count
);
2653 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2655 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
2657 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 0)) != REG
)
2659 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
2662 /* Work out how many bytes to push onto the stack after storing the
2664 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
2666 /* Each push will put 4 bytes from the stack... */
2667 stack_bytes
+= (count
- 2) * 4;
2669 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2670 if (stack_bytes
!= 0 && stack_bytes
!= -16)
2672 error ("bad amount of stack space removal: %d", stack_bytes
);
2676 /* Now compute the bit mask of registers to push. */
2678 for (i
= 1; i
< count
- 1; i
++)
2680 rtx vector_element
= XVECEXP (op
, 0, i
);
2682 if (GET_CODE (vector_element
) != SET
)
2684 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
2686 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
2689 mask
|= 1 << REGNO (SET_SRC (vector_element
));
2692 /* Scan for the first register to push. */
2693 for (first
= 0; first
< 32; first
++)
2695 if (mask
& (1 << first
))
2702 /* Discover the last register to push. */
2703 if (mask
& (1 << LINK_POINTER_REGNUM
))
2705 if (stack_bytes
!= -16)
2708 last
= LINK_POINTER_REGNUM
;
2712 if (stack_bytes
!= 0)
2714 if ((mask
& (1 << 29)) == 0)
2720 /* Note, it is possible to have gaps in the register mask.
2721 We ignore this here, and generate a JARL anyway. We will
2722 be pushing more registers than is strictly necessary, but
2723 it does save code space. */
2725 if (TARGET_LONG_CALLS
)
2730 sprintf (name
, "__save_%s", reg_names
[first
]);
2732 sprintf (name
, "__save_%s_%s", reg_names
[first
], reg_names
[last
]);
2734 sprintf (buff
, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2740 sprintf (buff
, "jarl __save_%s, r10", reg_names
[first
]);
2742 sprintf (buff
, "jarl __save_%s_%s, r10", reg_names
[first
],
2749 extern tree last_assemble_variable_decl
;
2750 extern int size_directive_output
;
2752 /* A version of asm_output_aligned_bss() that copes with the special
2753 data areas of the v850. */
2755 v850_output_aligned_bss (file
, decl
, name
, size
, align
)
2762 (*targetm
.asm_out
.globalize_label
) (file
, name
);
2764 switch (v850_get_data_area (decl
))
2782 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
2783 #ifdef ASM_DECLARE_OBJECT_NAME
2784 last_assemble_variable_decl
= decl
;
2785 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
2787 /* Standard thing is just output label for the object. */
2788 ASM_OUTPUT_LABEL (file
, name
);
2789 #endif /* ASM_DECLARE_OBJECT_NAME */
2790 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
2793 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2795 v850_output_common (file
, decl
, name
, size
, align
)
2802 if (decl
== NULL_TREE
)
2804 fprintf (file
, "%s", COMMON_ASM_OP
);
2808 switch (v850_get_data_area (decl
))
2811 fprintf (file
, "%s", ZCOMMON_ASM_OP
);
2815 fprintf (file
, "%s", SCOMMON_ASM_OP
);
2819 fprintf (file
, "%s", TCOMMON_ASM_OP
);
2823 fprintf (file
, "%s", COMMON_ASM_OP
);
2828 assemble_name (file
, name
);
2829 fprintf (file
, ",%u,%u\n", size
, align
/ BITS_PER_UNIT
);
2832 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2834 v850_output_local (file
, decl
, name
, size
, align
)
2841 fprintf (file
, "%s", LOCAL_ASM_OP
);
2842 assemble_name (file
, name
);
2843 fprintf (file
, "\n");
2845 ASM_OUTPUT_ALIGNED_DECL_COMMON (file
, decl
, name
, size
, align
);
2848 /* Add data area to the given declaration if a ghs data area pragma is
2849 currently in effect (#pragma ghs startXXX/endXXX). */
2851 v850_insert_attributes (decl
, attr_ptr
)
2853 tree
*attr_ptr ATTRIBUTE_UNUSED
;
2856 && data_area_stack
->data_area
2857 && current_function_decl
== NULL_TREE
2858 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
2859 && v850_get_data_area (decl
) == DATA_AREA_NORMAL
)
2860 v850_set_data_area (decl
, data_area_stack
->data_area
);
2862 /* Initialize the default names of the v850 specific sections,
2863 if this has not been done before. */
2865 if (GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
] == NULL
)
2867 GHS_default_section_names
[(int) GHS_SECTION_KIND_SDATA
]
2868 = build_string (sizeof (".sdata")-1, ".sdata");
2870 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROSDATA
]
2871 = build_string (sizeof (".rosdata")-1, ".rosdata");
2873 GHS_default_section_names
[(int) GHS_SECTION_KIND_TDATA
]
2874 = build_string (sizeof (".tdata")-1, ".tdata");
2876 GHS_default_section_names
[(int) GHS_SECTION_KIND_ZDATA
]
2877 = build_string (sizeof (".zdata")-1, ".zdata");
2879 GHS_default_section_names
[(int) GHS_SECTION_KIND_ROZDATA
]
2880 = build_string (sizeof (".rozdata")-1, ".rozdata");
2883 if (current_function_decl
== NULL_TREE
2884 && (TREE_CODE (decl
) == VAR_DECL
2885 || TREE_CODE (decl
) == CONST_DECL
2886 || TREE_CODE (decl
) == FUNCTION_DECL
)
2887 && (!DECL_EXTERNAL (decl
) || DECL_INITIAL (decl
))
2888 && !DECL_SECTION_NAME (decl
))
2890 enum GHS_section_kind kind
= GHS_SECTION_KIND_DEFAULT
;
2891 tree chosen_section
;
2893 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2894 kind
= GHS_SECTION_KIND_TEXT
;
2897 /* First choose a section kind based on the data area of the decl. */
2898 switch (v850_get_data_area (decl
))
2904 kind
= ((TREE_READONLY (decl
))
2905 ? GHS_SECTION_KIND_ROSDATA
2906 : GHS_SECTION_KIND_SDATA
);
2910 kind
= GHS_SECTION_KIND_TDATA
;
2914 kind
= ((TREE_READONLY (decl
))
2915 ? GHS_SECTION_KIND_ROZDATA
2916 : GHS_SECTION_KIND_ZDATA
);
2919 case DATA_AREA_NORMAL
: /* default data area */
2920 if (TREE_READONLY (decl
))
2921 kind
= GHS_SECTION_KIND_RODATA
;
2922 else if (DECL_INITIAL (decl
))
2923 kind
= GHS_SECTION_KIND_DATA
;
2925 kind
= GHS_SECTION_KIND_BSS
;
2929 /* Now, if the section kind has been explicitly renamed,
2930 then attach a section attribute. */
2931 chosen_section
= GHS_current_section_names
[(int) kind
];
2933 /* Otherwise, if this kind of section needs an explicit section
2934 attribute, then also attach one. */
2935 if (chosen_section
== NULL
)
2936 chosen_section
= GHS_default_section_names
[(int) kind
];
2940 /* Only set the section name if specified by a pragma, because
2941 otherwise it will force those variables to get allocated storage
2942 in this module, rather than by the linker. */
2943 DECL_SECTION_NAME (decl
) = chosen_section
;
2948 /* Return nonzero if the given RTX is suitable
2949 for collapsing into a DISPOSE instruction. */
2952 pattern_is_ok_for_dispose (op
, mode
)
2954 enum machine_mode mode ATTRIBUTE_UNUSED
;
2956 int count
= XVECLEN (op
, 0);
2959 /* If there are no registers to restore then
2960 the dispose instruction is not suitable. */
2964 /* The pattern matching has already established that we are performing a
2965 function epilogue and that we are popping at least one register. We must
2966 now check the remaining entries in the vector to make sure that they are
2967 also register pops. There is no good reason why there should ever be
2968 anything else in this vector, but being paranoid always helps...
2970 The test below performs the C equivalent of this machine description
2973 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2974 (mem:SI (plus:SI (reg:SI 3)
2975 (match_operand:SI n "immediate_operand" "i"))))
2978 for (i
= 3; i
< count
; i
++)
2980 rtx vector_element
= XVECEXP (op
, 0, i
);
2985 if (GET_CODE (vector_element
) != SET
)
2988 dest
= SET_DEST (vector_element
);
2989 src
= SET_SRC (vector_element
);
2991 if ( GET_CODE (dest
) != REG
2992 || GET_MODE (dest
) != SImode
2993 || ! register_is_ok_for_epilogue (dest
, SImode
)
2994 || GET_CODE (src
) != MEM
2995 || GET_MODE (src
) != SImode
)
2998 plus
= XEXP (src
, 0);
3000 if ( GET_CODE (plus
) != PLUS
3001 || GET_CODE (XEXP (plus
, 0)) != REG
3002 || GET_MODE (XEXP (plus
, 0)) != SImode
3003 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3004 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3011 /* Construct a DISPOSE instruction that is the equivalent of
3012 the given RTX. We have already verified that this should
3016 construct_dispose_instruction (op
)
3019 int count
= XVECLEN (op
, 0);
3021 unsigned long int mask
;
3023 static char buff
[ 100 ]; /* XXX */
3028 error ("Bogus DISPOSE construction: %d\n", count
);
3032 /* Work out how many bytes to pop off the
3033 stack before retrieving registers. */
3034 if (GET_CODE (XVECEXP (op
, 0, 1)) != SET
)
3036 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 1))) != PLUS
)
3038 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1)) != CONST_INT
)
3041 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1));
3043 /* Each pop will remove 4 bytes from the stack... */
3044 stack_bytes
-= (count
- 2) * 4;
3046 /* Make sure that the amount we are popping
3047 will fit into the DISPOSE instruction. */
3048 if (stack_bytes
> 128)
3050 error ("Too much stack space to dispose of: %d", stack_bytes
);
3054 /* Now compute the bit mask of registers to push. */
3057 for (i
= 2; i
< count
; i
++)
3059 rtx vector_element
= XVECEXP (op
, 0, i
);
3061 if (GET_CODE (vector_element
) != SET
)
3063 if (GET_CODE (SET_DEST (vector_element
)) != REG
)
3065 if (! register_is_ok_for_epilogue (SET_DEST (vector_element
), SImode
))
3068 if (REGNO (SET_DEST (vector_element
)) == 2)
3071 mask
|= 1 << REGNO (SET_DEST (vector_element
));
3074 if (! TARGET_DISABLE_CALLT
3075 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== 16))
3079 sprintf (buff
, "callt ctoff(__callt_return_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29);
3084 for (i
= 20; i
< 32; i
++)
3085 if (mask
& (1 << i
))
3089 sprintf (buff
, "callt ctoff(__callt_return_r31c)");
3091 sprintf (buff
, "callt ctoff(__callt_return_r%d_r%d%s)",
3092 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3097 static char regs
[100]; /* XXX */
3100 /* Generate the DISPOSE instruction. Note we could just issue the
3101 bit mask as a number as the assembler can cope with this, but for
3102 the sake of our readers we turn it into a textual description. */
3106 for (i
= 20; i
< 32; i
++)
3108 if (mask
& (1 << i
))
3113 strcat (regs
, ", ");
3118 strcat (regs
, reg_names
[ first
]);
3120 for (i
++; i
< 32; i
++)
3121 if ((mask
& (1 << i
)) == 0)
3126 strcat (regs
, " - ");
3127 strcat (regs
, reg_names
[ i
- 1 ] );
3132 sprintf (buff
, "dispose %d {%s}, r31", stack_bytes
/ 4, regs
);
3138 /* Return nonzero if the given RTX is suitable
3139 for collapsing into a PREPARE instruction. */
3142 pattern_is_ok_for_prepare (op
, mode
)
3144 enum machine_mode mode ATTRIBUTE_UNUSED
;
3146 int count
= XVECLEN (op
, 0);
3149 /* If there are no registers to restore then the prepare instruction
3154 /* The pattern matching has already established that we are adjusting the
3155 stack and pushing at least one register. We must now check that the
3156 remaining entries in the vector to make sure that they are also register
3159 The test below performs the C equivalent of this machine description
3162 (set (mem:SI (plus:SI (reg:SI 3)
3163 (match_operand:SI 2 "immediate_operand" "i")))
3164 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3168 for (i
= 2; i
< count
; i
++)
3170 rtx vector_element
= XVECEXP (op
, 0, i
);
3175 if (GET_CODE (vector_element
) != SET
)
3178 dest
= SET_DEST (vector_element
);
3179 src
= SET_SRC (vector_element
);
3181 if ( GET_CODE (dest
) != MEM
3182 || GET_MODE (dest
) != SImode
3183 || GET_CODE (src
) != REG
3184 || GET_MODE (src
) != SImode
3185 || ! register_is_ok_for_epilogue (src
, SImode
)
3189 plus
= XEXP (dest
, 0);
3191 if ( GET_CODE (plus
) != PLUS
3192 || GET_CODE (XEXP (plus
, 0)) != REG
3193 || GET_MODE (XEXP (plus
, 0)) != SImode
3194 || REGNO (XEXP (plus
, 0)) != STACK_POINTER_REGNUM
3195 || GET_CODE (XEXP (plus
, 1)) != CONST_INT
)
3198 /* If the register is being pushed somewhere other than the stack
3199 space just aquired by the first operand then abandon this quest.
3200 Note: the test is <= becuase both values are negative. */
3201 if (INTVAL (XEXP (plus
, 1))
3202 <= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)))
3209 /* Construct a PREPARE instruction that is the equivalent of
3210 the given RTL. We have already verified that this should
3214 construct_prepare_instruction (op
)
3217 int count
= XVECLEN (op
, 0);
3219 unsigned long int mask
;
3221 static char buff
[ 100 ]; /* XXX */
3226 error ("Bogus PREPEARE construction: %d\n", count
);
3230 /* Work out how many bytes to push onto
3231 the stack after storing the registers. */
3232 if (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
3234 if (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != PLUS
)
3236 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1)) != CONST_INT
)
3239 stack_bytes
= INTVAL (XEXP (SET_SRC (XVECEXP (op
, 0, 0)), 1));
3241 /* Each push will put 4 bytes from the stack. */
3242 stack_bytes
+= (count
- 1) * 4;
3244 /* Make sure that the amount we are popping
3245 will fit into the DISPOSE instruction. */
3246 if (stack_bytes
< -128)
3248 error ("Too much stack space to prepare: %d", stack_bytes
);
3252 /* Now compute the bit mask of registers to push. */
3254 for (i
= 1; i
< count
; i
++)
3256 rtx vector_element
= XVECEXP (op
, 0, i
);
3258 if (GET_CODE (vector_element
) != SET
)
3260 if (GET_CODE (SET_SRC (vector_element
)) != REG
)
3262 if (! register_is_ok_for_epilogue (SET_SRC (vector_element
), SImode
))
3265 if (REGNO (SET_SRC (vector_element
)) == 2)
3268 mask
|= 1 << REGNO (SET_SRC (vector_element
));
3271 if ((! TARGET_DISABLE_CALLT
)
3272 && (use_callt
|| stack_bytes
== 0 || stack_bytes
== -16))
3276 sprintf (buff
, "callt ctoff(__callt_save_r2_r%d)", (mask
& (1 << 31)) ? 31 : 29 );
3280 for (i
= 20; i
< 32; i
++)
3281 if (mask
& (1 << i
))
3285 sprintf (buff
, "callt ctoff(__callt_save_r31c)");
3287 sprintf (buff
, "callt ctoff(__callt_save_r%d_r%d%s)",
3288 i
, (mask
& (1 << 31)) ? 31 : 29, stack_bytes
? "c" : "");
3292 static char regs
[100]; /* XXX */
3296 /* Generate the PREPARE instruction. Note we could just issue the
3297 bit mask as a number as the assembler can cope with this, but for
3298 the sake of our readers we turn it into a textual description. */
3302 for (i
= 20; i
< 32; i
++)
3304 if (mask
& (1 << i
))
3309 strcat (regs
, ", ");
3314 strcat (regs
, reg_names
[ first
]);
3316 for (i
++; i
< 32; i
++)
3317 if ((mask
& (1 << i
)) == 0)
3322 strcat (regs
, " - ");
3323 strcat (regs
, reg_names
[ i
- 1 ] );
3328 sprintf (buff
, "prepare {%s}, %d", regs
, (- stack_bytes
) / 4);
3334 /* Implement `va_arg'. */
3337 v850_va_arg (valist
, type
)
3340 HOST_WIDE_INT size
, rsize
;
3345 /* Round up sizeof(type) to a word. */
3346 size
= int_size_in_bytes (type
);
3347 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
3352 size
= rsize
= UNITS_PER_WORD
;
3356 addr
= save_expr (valist
);
3357 incr
= fold (build (PLUS_EXPR
, ptr_type_node
, addr
,
3358 build_int_2 (rsize
, 0)));
3360 incr
= build (MODIFY_EXPR
, ptr_type_node
, valist
, incr
);
3361 TREE_SIDE_EFFECTS (incr
) = 1;
3362 expand_expr (incr
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3364 addr_rtx
= expand_expr (addr
, NULL
, Pmode
, EXPAND_NORMAL
);
3368 addr_rtx
= force_reg (Pmode
, addr_rtx
);
3369 addr_rtx
= gen_rtx_MEM (Pmode
, addr_rtx
);
3370 set_mem_alias_set (addr_rtx
, get_varargs_alias_set ());
3376 /* Return an RTX indicating where the return address to the
3377 calling function can be found. */
3380 v850_return_addr (count
)
3386 return get_hard_reg_initial_val (Pmode
, LINK_POINTER_REGNUM
);
3390 v850_select_section (exp
, reloc
, align
)
3392 int reloc ATTRIBUTE_UNUSED
;
3393 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
3395 if (TREE_CODE (exp
) == VAR_DECL
)
3398 if (!TREE_READONLY (exp
)
3399 || TREE_SIDE_EFFECTS (exp
)
3400 || !DECL_INITIAL (exp
)
3401 || (DECL_INITIAL (exp
) != error_mark_node
3402 && !TREE_CONSTANT (DECL_INITIAL (exp
))))
3407 switch (v850_get_data_area (exp
))
3429 readonly_data_section ();
3435 else if (TREE_CODE (exp
) == STRING_CST
)
3437 if (! flag_writable_strings
)
3438 readonly_data_section ();
3443 readonly_data_section ();