1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
42 #include "integrate.h"
45 #include "target-def.h"
48 #define streq(a,b) (strcmp (a, b) == 0)
51 /* Function prototypes for stupid compilers: */
52 static void const_double_split PARAMS ((rtx, HOST_WIDE_INT *, HOST_WIDE_INT *));
53 static int const_costs_int PARAMS ((HOST_WIDE_INT, int));
54 static int const_costs PARAMS ((rtx, enum rtx_code));
55 static bool v850_rtx_costs PARAMS ((rtx, int, int, int *));
56 static void substitute_ep_register PARAMS ((rtx, rtx, int, int, rtx *, rtx *));
57 static void v850_reorg PARAMS ((void));
58 static int ep_memory_offset PARAMS ((enum machine_mode, int));
59 static void v850_set_data_area PARAMS ((tree, v850_data_area));
60 const struct attribute_spec v850_attribute_table[];
61 static tree v850_handle_interrupt_attribute PARAMS ((tree *, tree, tree, int, bool *));
62 static tree v850_handle_data_area_attribute PARAMS ((tree *, tree, tree, int, bool *));
63 static void v850_insert_attributes PARAMS ((tree, tree *));
64 static void v850_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT));
65 static void v850_encode_data_area PARAMS ((tree, rtx));
66 static void v850_encode_section_info PARAMS ((tree, rtx, int));
68 /* Information about the various small memory areas. */
69 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
71 /* name value max physical max */
72 { "tda", (char *)0, 0, 256 },
73 { "sda", (char *)0, 0, 65536 },
74 { "zda", (char *)0, 0, 32768 },
77 /* Names of the various data areas used on the v850. */
78 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
79 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
81 /* Track the current data area set by the data area pragma (which
82 can be nested). Tested by check_default_data_area. */
83 data_area_stack_element * data_area_stack = NULL;
85 /* True if we don't need to check any more if the current
86 function is an interrupt handler. */
87 static int v850_interrupt_cache_p = FALSE;
89 /* Whether current function is an interrupt handler. */
90 static int v850_interrupt_p = FALSE;
92 /* Initialize the GCC target structure. */
93 #undef TARGET_ASM_ALIGNED_HI_OP
94 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
96 #undef TARGET_ATTRIBUTE_TABLE
97 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
99 #undef TARGET_INSERT_ATTRIBUTES
100 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
102 #undef TARGET_ASM_SELECT_SECTION
103 #define TARGET_ASM_SELECT_SECTION v850_select_section
105 #undef TARGET_ENCODE_SECTION_INFO
106 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
108 #undef TARGET_RTX_COSTS
109 #define TARGET_RTX_COSTS v850_rtx_costs
110 #undef TARGET_ADDRESS_COST
111 #define TARGET_ADDRESS_COST hook_int_rtx_0
113 #undef TARGET_MACHINE_DEPENDENT_REORG
114 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
116 struct gcc_target targetm = TARGET_INITIALIZER;
118 /* Sometimes certain combinations of command options do not make
119 sense on a particular target machine. You can define a macro
120 `OVERRIDE_OPTIONS' to take account of this. This macro, if
121 defined, is executed once just after all the command options have
124 Don't use this macro to turn on various extra optimizations for
125 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
131 extern int atoi PARAMS ((const char *));
133 /* Parse -m{s,t,z}da=nnn switches */
134 for (i = 0; i < (int)SMALL_MEMORY_max; i++)
136 if (small_memory[i].value)
138 if (!ISDIGIT (*small_memory[i].value))
139 error ("%s=%s is not numeric",
140 small_memory[i].name,
141 small_memory[i].value);
144 small_memory[i].max = atoi (small_memory[i].value);
145 if (small_memory[i].max > small_memory[i].physical_max)
146 error ("%s=%s is too large",
147 small_memory[i].name,
148 small_memory[i].value);
153 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
154 if ((target_flags & MASK_US_MASK_SET) == 0)
156 target_flags |= MASK_US_MASK_SET;
157 target_flags &= ~MASK_US_BIT_SET;
162 /* Output assembly code for the start of the file. */
165 asm_file_start (file)
168 output_file_directive (file, main_input_filename);
172 /* Return an RTX to represent where a value with mode MODE will be returned
173 from a function. If the result is 0, the argument is pushed. */
176 function_arg (cum, mode, type, named)
177 CUMULATIVE_ARGS *cum;
178 enum machine_mode mode;
185 if (TARGET_GHS && !named)
189 size = int_size_in_bytes (type);
191 size = GET_MODE_SIZE (mode);
197 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
201 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
203 if (cum->nbytes > 4 * UNITS_PER_WORD)
206 if (type == NULL_TREE
207 && cum->nbytes + size > 4 * UNITS_PER_WORD)
210 switch (cum->nbytes / UNITS_PER_WORD)
213 result = gen_rtx_REG (mode, 6);
216 result = gen_rtx_REG (mode, 7);
219 result = gen_rtx_REG (mode, 8);
222 result = gen_rtx_REG (mode, 9);
232 /* Return the number of words which must be put into registers
233 for values which are part in registers and part in memory. */
236 function_arg_partial_nregs (cum, mode, type, named)
237 CUMULATIVE_ARGS *cum;
238 enum machine_mode mode;
244 if (TARGET_GHS && !named)
248 size = int_size_in_bytes (type);
250 size = GET_MODE_SIZE (mode);
253 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
257 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
259 if (cum->nbytes > 4 * UNITS_PER_WORD)
262 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
265 if (type == NULL_TREE
266 && cum->nbytes + size > 4 * UNITS_PER_WORD)
269 return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
273 /* Return the high and low words of a CONST_DOUBLE */
276 const_double_split (x, p_high, p_low)
278 HOST_WIDE_INT *p_high;
279 HOST_WIDE_INT *p_low;
281 if (GET_CODE (x) == CONST_DOUBLE)
286 switch (GET_MODE (x))
289 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
290 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
291 *p_high = t[1]; /* since v850 is little endian */
292 *p_low = t[0]; /* high is second word */
296 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
297 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
303 *p_high = CONST_DOUBLE_HIGH (x);
304 *p_low = CONST_DOUBLE_LOW (x);
312 fatal_insn ("const_double_split got a bad insn:", x);
316 /* Return the cost of the rtx R with code CODE. */
319 const_costs_int (value, zero_cost)
323 if (CONST_OK_FOR_I (value))
325 else if (CONST_OK_FOR_J (value))
327 else if (CONST_OK_FOR_K (value))
338 HOST_WIDE_INT high, low;
343 return const_costs_int (INTVAL (r), 0);
346 const_double_split (r, &high, &low);
347 if (GET_MODE (r) == SFmode)
348 return const_costs_int (high, 1);
350 return const_costs_int (high, 1) + const_costs_int (low, 1);
366 v850_rtx_costs (x, code, outer_code, total)
368 int code, outer_code ATTRIBUTE_UNUSED, *total;
377 *total = COSTS_N_INSNS (const_costs (x, code));
384 if (TARGET_V850E && optimize_size)
392 && ( GET_MODE (x) == SImode
393 || GET_MODE (x) == HImode
394 || GET_MODE (x) == QImode))
396 if (GET_CODE (XEXP (x, 1)) == REG)
398 else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
400 if (CONST_OK_FOR_O (INTVAL (XEXP (x, 1))))
402 else if (CONST_OK_FOR_K (INTVAL (XEXP (x, 1))))
415 /* Print operand X using operand code CODE to assembly language output file
419 print_operand (file, x, code)
424 HOST_WIDE_INT high, low;
429 /* We use 'c' operands with symbols for .vtinherit */
430 if (GET_CODE (x) == SYMBOL_REF)
432 output_addr_const(file, x);
439 switch ((code == 'B' || code == 'C')
440 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
443 if (code == 'c' || code == 'C')
444 fprintf (file, "nz");
446 fprintf (file, "ne");
449 if (code == 'c' || code == 'C')
455 fprintf (file, "ge");
458 fprintf (file, "gt");
461 fprintf (file, "le");
464 fprintf (file, "lt");
467 fprintf (file, "nl");
473 fprintf (file, "nh");
482 case 'F': /* high word of CONST_DOUBLE */
483 if (GET_CODE (x) == CONST_INT)
484 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
485 else if (GET_CODE (x) == CONST_DOUBLE)
487 const_double_split (x, &high, &low);
488 fprintf (file, "%ld", (long) high);
493 case 'G': /* low word of CONST_DOUBLE */
494 if (GET_CODE (x) == CONST_INT)
495 fprintf (file, "%ld", (long) INTVAL (x));
496 else if (GET_CODE (x) == CONST_DOUBLE)
498 const_double_split (x, &high, &low);
499 fprintf (file, "%ld", (long) low);
505 fprintf (file, "%d\n", INTVAL (x) & 0xffff);
508 fprintf (file, "%d", exact_log2 (INTVAL (x)));
511 if (special_symbolref_operand (x, VOIDmode))
513 if (GET_CODE (x) == SYMBOL_REF)
515 else if (GET_CODE (x) == CONST)
516 x = XEXP (XEXP (x, 0), 0);
520 if (SYMBOL_REF_ZDA_P (x))
521 fprintf (file, "zdaoff");
522 else if (SYMBOL_REF_SDA_P (x))
523 fprintf (file, "sdaoff");
524 else if (SYMBOL_REF_TDA_P (x))
525 fprintf (file, "tdaoff");
533 if (special_symbolref_operand (x, VOIDmode))
534 output_addr_const (file, x);
539 if (special_symbolref_operand (x, VOIDmode))
541 if (GET_CODE (x) == SYMBOL_REF)
543 else if (GET_CODE (x) == CONST)
544 x = XEXP (XEXP (x, 0), 0);
548 if (SYMBOL_REF_ZDA_P (x))
549 fprintf (file, "r0");
550 else if (SYMBOL_REF_SDA_P (x))
551 fprintf (file, "gp");
552 else if (SYMBOL_REF_TDA_P (x))
553 fprintf (file, "ep");
560 case 'R': /* 2nd word of a double. */
561 switch (GET_CODE (x))
564 fprintf (file, reg_names[REGNO (x) + 1]);
567 x = XEXP (adjust_address (x, SImode, 4), 0);
568 print_operand_address (file, x);
569 if (GET_CODE (x) == CONST_INT)
570 fprintf (file, "[r0]");
579 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
580 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
587 /* Like an 'S' operand above, but for unsigned loads only. */
588 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
593 case 'W': /* print the instruction suffix */
594 switch (GET_MODE (x))
599 case QImode: fputs (".b", file); break;
600 case HImode: fputs (".h", file); break;
601 case SImode: fputs (".w", file); break;
602 case SFmode: fputs (".w", file); break;
605 case '.': /* register r0 */
606 fputs (reg_names[0], file);
608 case 'z': /* reg or zero */
610 fputs (reg_names[0], file);
611 else if (GET_CODE (x) == REG)
612 fputs (reg_names[REGNO (x)], file);
617 switch (GET_CODE (x))
620 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
621 output_address (gen_rtx_PLUS (SImode, gen_rtx (REG, SImode, 0),
624 output_address (XEXP (x, 0));
628 fputs (reg_names[REGNO (x)], file);
631 fputs (reg_names[subreg_regno (x)], file);
638 print_operand_address (file, x);
649 /* Output assembly language output for the address ADDR to FILE. */
652 print_operand_address (file, addr)
656 switch (GET_CODE (addr))
659 fprintf (file, "0[");
660 print_operand (file, addr, 0);
664 if (GET_CODE (XEXP (addr, 0)) == REG)
667 fprintf (file, "lo(");
668 print_operand (file, XEXP (addr, 1), 0);
669 fprintf (file, ")[");
670 print_operand (file, XEXP (addr, 0), 0);
675 if (GET_CODE (XEXP (addr, 0)) == REG
676 || GET_CODE (XEXP (addr, 0)) == SUBREG)
679 print_operand (file, XEXP (addr, 1), 0);
681 print_operand (file, XEXP (addr, 0), 0);
686 print_operand (file, XEXP (addr, 0), 0);
688 print_operand (file, XEXP (addr, 1), 0);
693 const char *off_name = NULL;
694 const char *reg_name = NULL;
696 if (SYMBOL_REF_ZDA_P (addr))
701 else if (SYMBOL_REF_SDA_P (addr))
706 else if (SYMBOL_REF_TDA_P (addr))
713 fprintf (file, "%s(", off_name);
714 output_addr_const (file, addr);
716 fprintf (file, ")[%s]", reg_name);
720 if (special_symbolref_operand (addr, VOIDmode))
722 rtx x = XEXP (XEXP (addr, 0), 0);
723 const char *off_name;
724 const char *reg_name;
726 if (SYMBOL_REF_ZDA_P (x))
731 else if (SYMBOL_REF_SDA_P (x))
736 else if (SYMBOL_REF_TDA_P (x))
744 fprintf (file, "%s(", off_name);
745 output_addr_const (file, addr);
746 fprintf (file, ")[%s]", reg_name);
749 output_addr_const (file, addr);
752 output_addr_const (file, addr);
757 /* When assemble_integer is used to emit the offsets for a switch
758 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
759 output_addr_const will normally barf at this, but it is OK to omit
760 the truncate and just emit the difference of the two labels. The
761 .hword directive will automatically handle the truncation for us.
763 Returns 1 if rtx was handled, 0 otherwise. */
766 v850_output_addr_const_extra (file, x)
770 if (GET_CODE (x) != TRUNCATE)
775 /* We must also handle the case where the switch table was passed a
776 constant value and so has been collapsed. In this case the first
777 label will have been deleted. In such a case it is OK to emit
778 nothing, since the table will not be used.
779 (cf gcc.c-torture/compile/990801-1.c). */
780 if (GET_CODE (x) == MINUS
781 && GET_CODE (XEXP (x, 0)) == LABEL_REF
782 && GET_CODE (XEXP (XEXP (x, 0), 0)) == CODE_LABEL
783 && INSN_DELETED_P (XEXP (XEXP (x, 0), 0)))
786 output_addr_const (file, x);
790 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
794 output_move_single (operands)
797 rtx dst = operands[0];
798 rtx src = operands[1];
805 else if (GET_CODE (src) == CONST_INT)
807 HOST_WIDE_INT value = INTVAL (src);
809 if (CONST_OK_FOR_J (value)) /* Signed 5 bit immediate. */
812 else if (CONST_OK_FOR_K (value)) /* Signed 16 bit immediate. */
813 return "movea lo(%1),%.,%0";
815 else if (CONST_OK_FOR_L (value)) /* Upper 16 bits were set. */
816 return "movhi hi(%1),%.,%0";
818 /* A random constant. */
819 else if (TARGET_V850E)
822 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
825 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
827 HOST_WIDE_INT high, low;
829 const_double_split (src, &high, &low);
831 if (CONST_OK_FOR_J (high)) /* Signed 5 bit immediate. */
834 else if (CONST_OK_FOR_K (high)) /* Signed 16 bit immediate. */
835 return "movea lo(%F1),%.,%0";
837 else if (CONST_OK_FOR_L (high)) /* Upper 16 bits were set. */
838 return "movhi hi(%F1),%.,%0";
840 /* A random constant. */
841 else if (TARGET_V850E)
845 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
848 else if (GET_CODE (src) == MEM)
849 return "%S1ld%W1 %1,%0";
851 else if (special_symbolref_operand (src, VOIDmode))
852 return "movea %O1(%P1),%Q1,%0";
854 else if (GET_CODE (src) == LABEL_REF
855 || GET_CODE (src) == SYMBOL_REF
856 || GET_CODE (src) == CONST)
859 return "mov hilo(%1),%0";
861 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
864 else if (GET_CODE (src) == HIGH)
865 return "movhi hi(%1),%.,%0";
867 else if (GET_CODE (src) == LO_SUM)
869 operands[2] = XEXP (src, 0);
870 operands[3] = XEXP (src, 1);
871 return "movea lo(%3),%2,%0";
875 else if (GET_CODE (dst) == MEM)
878 return "%S0st%W0 %1,%0";
880 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
881 return "%S0st%W0 %.,%0";
883 else if (GET_CODE (src) == CONST_DOUBLE
884 && CONST0_RTX (GET_MODE (dst)) == src)
885 return "%S0st%W0 %.,%0";
888 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
893 /* Return appropriate code to load up an 8 byte integer or
894 floating point value */
897 output_move_double (operands)
900 enum machine_mode mode = GET_MODE (operands[0]);
901 rtx dst = operands[0];
902 rtx src = operands[1];
904 if (register_operand (dst, mode)
905 && register_operand (src, mode))
907 if (REGNO (src) + 1 == REGNO (dst))
908 return "mov %R1,%R0\n\tmov %1,%0";
910 return "mov %1,%0\n\tmov %R1,%R0";
914 if (GET_CODE (dst) == MEM
915 && ((GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
916 || (GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src))))
917 return "st.w %.,%0\n\tst.w %.,%R0";
919 if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
921 HOST_WIDE_INT high_low[2];
925 if (GET_CODE (src) == CONST_DOUBLE)
926 const_double_split (src, &high_low[1], &high_low[0]);
929 high_low[0] = INTVAL (src);
930 high_low[1] = (INTVAL (src) >= 0) ? 0 : -1;
933 for (i = 0; i < 2; i++)
935 xop[0] = gen_rtx_REG (SImode, REGNO (dst)+i);
936 xop[1] = GEN_INT (high_low[i]);
937 output_asm_insn (output_move_single (xop), xop);
943 if (GET_CODE (src) == MEM)
946 int dreg = REGNO (dst);
947 rtx inside = XEXP (src, 0);
949 if (GET_CODE (inside) == REG)
950 ptrreg = REGNO (inside);
951 else if (GET_CODE (inside) == SUBREG)
952 ptrreg = subreg_regno (inside);
953 else if (GET_CODE (inside) == PLUS)
954 ptrreg = REGNO (XEXP (inside, 0));
955 else if (GET_CODE (inside) == LO_SUM)
956 ptrreg = REGNO (XEXP (inside, 0));
959 return "ld.w %R1,%R0\n\tld.w %1,%0";
962 if (GET_CODE (src) == MEM)
963 return "ld.w %1,%0\n\tld.w %R1,%R0";
965 if (GET_CODE (dst) == MEM)
966 return "st.w %1,%0\n\tst.w %R1,%R0";
968 return "mov %1,%0\n\tmov %R1,%R0";
972 /* Return maximum offset supported for a short EP memory reference of mode
973 MODE and signedness UNSIGNEDP. */
976 ep_memory_offset (mode, unsignedp)
977 enum machine_mode mode;
978 int ATTRIBUTE_UNUSED unsignedp;
985 if (TARGET_SMALL_SLD)
986 max_offset = (1 << 4);
987 else if (TARGET_V850E
988 && ( ( unsignedp && ! TARGET_US_BIT_SET)
989 || (! unsignedp && TARGET_US_BIT_SET)))
990 max_offset = (1 << 4);
992 max_offset = (1 << 7);
996 if (TARGET_SMALL_SLD)
997 max_offset = (1 << 5);
998 else if (TARGET_V850E
999 && ( ( unsignedp && ! TARGET_US_BIT_SET)
1000 || (! unsignedp && TARGET_US_BIT_SET)))
1001 max_offset = (1 << 5);
1003 max_offset = (1 << 8);
1008 max_offset = (1 << 8);
1018 /* Return true if OP is a valid short EP memory reference */
1021 ep_memory_operand (op, mode, unsigned_load)
1023 enum machine_mode mode;
1030 if (GET_CODE (op) != MEM)
1033 max_offset = ep_memory_offset (mode, unsigned_load);
1035 mask = GET_MODE_SIZE (mode) - 1;
1037 addr = XEXP (op, 0);
1038 if (GET_CODE (addr) == CONST)
1039 addr = XEXP (addr, 0);
1041 switch (GET_CODE (addr))
1047 return SYMBOL_REF_TDA_P (addr);
1050 return REGNO (addr) == EP_REGNUM;
1053 op0 = XEXP (addr, 0);
1054 op1 = XEXP (addr, 1);
1055 if (GET_CODE (op1) == CONST_INT
1056 && INTVAL (op1) < max_offset
1057 && INTVAL (op1) >= 0
1058 && (INTVAL (op1) & mask) == 0)
1060 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
1063 if (GET_CODE (op0) == SYMBOL_REF && SYMBOL_REF_TDA_P (op0))
1072 /* Return true if OP is either a register or 0 */
1075 reg_or_0_operand (op, mode)
1077 enum machine_mode mode;
1079 if (GET_CODE (op) == CONST_INT)
1080 return INTVAL (op) == 0;
1082 else if (GET_CODE (op) == CONST_DOUBLE)
1083 return CONST_DOUBLE_OK_FOR_G (op);
1086 return register_operand (op, mode);
1089 /* Return true if OP is either a register or a signed five bit integer */
1092 reg_or_int5_operand (op, mode)
1094 enum machine_mode mode;
1096 if (GET_CODE (op) == CONST_INT)
1097 return CONST_OK_FOR_J (INTVAL (op));
1100 return register_operand (op, mode);
1103 /* Return true if OP is either a register or a signed nine bit integer. */
1106 reg_or_int9_operand (op, mode)
1108 enum machine_mode mode;
1110 if (GET_CODE (op) == CONST_INT)
1111 return CONST_OK_FOR_O (INTVAL (op));
1113 return register_operand (op, mode);
1116 /* Return true if OP is either a register or a const integer. */
1119 reg_or_const_operand (op, mode)
1121 enum machine_mode mode;
1123 if (GET_CODE (op) == CONST_INT)
1126 return register_operand (op, mode);
1129 /* Return true if OP is a valid call operand. */
1132 call_address_operand (op, mode)
1134 enum machine_mode ATTRIBUTE_UNUSED mode;
1136 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1137 if (TARGET_LONG_CALLS)
1138 return GET_CODE (op) == REG;
1139 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
1143 special_symbolref_operand (op, mode)
1145 enum machine_mode ATTRIBUTE_UNUSED mode;
1147 if (GET_CODE (op) == CONST
1148 && GET_CODE (XEXP (op, 0)) == PLUS
1149 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
1150 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))))
1151 op = XEXP (XEXP (op, 0), 0);
1153 if (GET_CODE (op) == SYMBOL_REF)
1154 return (SYMBOL_REF_FLAGS (op)
1155 & (SYMBOL_FLAG_ZDA | SYMBOL_FLAG_TDA | SYMBOL_FLAG_SDA)) != 0;
1161 movsi_source_operand (op, mode)
1163 enum machine_mode mode;
1165 /* Some constants, as well as symbolic operands
1166 must be done with HIGH & LO_SUM patterns. */
1168 && GET_CODE (op) != HIGH
1169 && GET_CODE (op) != CONSTANT_P_RTX
1170 && !(GET_CODE (op) == CONST_INT
1171 && (CONST_OK_FOR_J (INTVAL (op))
1172 || CONST_OK_FOR_K (INTVAL (op))
1173 || CONST_OK_FOR_L (INTVAL (op)))))
1174 return special_symbolref_operand (op, mode);
1176 return general_operand (op, mode);
1180 power_of_two_operand (op, mode)
1182 enum machine_mode ATTRIBUTE_UNUSED mode;
1184 if (GET_CODE (op) != CONST_INT)
1187 if (exact_log2 (INTVAL (op)) == -1)
1193 not_power_of_two_operand (op, mode)
1195 enum machine_mode mode;
1201 else if (mode == HImode)
1203 else if (mode == SImode)
1208 if (GET_CODE (op) != CONST_INT)
1211 if (exact_log2 (~INTVAL (op) & mask) == -1)
1217 /* Substitute memory references involving a pointer, to use the ep pointer,
1218 taking care to save and preserve the ep. */
1221 substitute_ep_register (first_insn, last_insn, uses, regno, p_r1, p_ep)
1229 rtx reg = gen_rtx_REG (Pmode, regno);
1234 regs_ever_live[1] = 1;
1235 *p_r1 = gen_rtx_REG (Pmode, 1);
1236 *p_ep = gen_rtx_REG (Pmode, 30);
1241 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1242 2 * (uses - 3), uses, reg_names[regno],
1243 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1244 INSN_UID (first_insn), INSN_UID (last_insn));
1246 if (GET_CODE (first_insn) == NOTE)
1247 first_insn = next_nonnote_insn (first_insn);
1249 last_insn = next_nonnote_insn (last_insn);
1250 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1252 if (GET_CODE (insn) == INSN)
1254 rtx pattern = single_set (insn);
1256 /* Replace the memory references. */
1260 /* Memory operands are signed by default. */
1261 int unsignedp = FALSE;
1263 if (GET_CODE (SET_DEST (pattern)) == MEM
1264 && GET_CODE (SET_SRC (pattern)) == MEM)
1267 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1268 p_mem = &SET_DEST (pattern);
1270 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1271 p_mem = &SET_SRC (pattern);
1273 else if (GET_CODE (SET_SRC (pattern)) == SIGN_EXTEND
1274 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1275 p_mem = &XEXP (SET_SRC (pattern), 0);
1277 else if (GET_CODE (SET_SRC (pattern)) == ZERO_EXTEND
1278 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1280 p_mem = &XEXP (SET_SRC (pattern), 0);
1288 rtx addr = XEXP (*p_mem, 0);
1290 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1291 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1293 else if (GET_CODE (addr) == PLUS
1294 && GET_CODE (XEXP (addr, 0)) == REG
1295 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1296 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1297 && ((INTVAL (XEXP (addr, 1)))
1298 < ep_memory_offset (GET_MODE (*p_mem),
1300 && ((INTVAL (XEXP (addr, 1))) >= 0))
1301 *p_mem = change_address (*p_mem, VOIDmode,
1302 gen_rtx_PLUS (Pmode,
1310 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1311 insn = prev_nonnote_insn (first_insn);
1312 if (insn && GET_CODE (insn) == INSN
1313 && GET_CODE (PATTERN (insn)) == SET
1314 && SET_DEST (PATTERN (insn)) == *p_ep
1315 && SET_SRC (PATTERN (insn)) == *p_r1)
1318 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1320 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1321 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1325 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1326 the -mep mode to copy heavily used pointers to ep to use the implicit
1338 regs[FIRST_PSEUDO_REGISTER];
1347 /* If not ep mode, just return now. */
1351 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1354 regs[i].first_insn = NULL_RTX;
1355 regs[i].last_insn = NULL_RTX;
1358 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
1360 switch (GET_CODE (insn))
1362 /* End of basic block */
1369 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1371 if (max_uses < regs[i].uses)
1373 max_uses = regs[i].uses;
1379 substitute_ep_register (regs[max_regno].first_insn,
1380 regs[max_regno].last_insn,
1381 max_uses, max_regno, &r1, &ep);
1385 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1388 regs[i].first_insn = NULL_RTX;
1389 regs[i].last_insn = NULL_RTX;
1397 pattern = single_set (insn);
1399 /* See if there are any memory references we can shorten */
1402 rtx src = SET_SRC (pattern);
1403 rtx dest = SET_DEST (pattern);
1405 /* Memory operands are signed by default. */
1406 int unsignedp = FALSE;
1408 /* We might have (SUBREG (MEM)) here, so just get rid of the
1409 subregs to make this code simpler. */
1410 if (GET_CODE (dest) == SUBREG
1411 && (GET_CODE (SUBREG_REG (dest)) == MEM
1412 || GET_CODE (SUBREG_REG (dest)) == REG))
1413 alter_subreg (&dest);
1414 if (GET_CODE (src) == SUBREG
1415 && (GET_CODE (SUBREG_REG (src)) == MEM
1416 || GET_CODE (SUBREG_REG (src)) == REG))
1417 alter_subreg (&src);
1419 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1422 else if (GET_CODE (dest) == MEM)
1425 else if (GET_CODE (src) == MEM)
1428 else if (GET_CODE (src) == SIGN_EXTEND
1429 && GET_CODE (XEXP (src, 0)) == MEM)
1430 mem = XEXP (src, 0);
1432 else if (GET_CODE (src) == ZERO_EXTEND
1433 && GET_CODE (XEXP (src, 0)) == MEM)
1435 mem = XEXP (src, 0);
1441 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1444 else if (!use_ep && mem
1445 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1447 rtx addr = XEXP (mem, 0);
1451 if (GET_CODE (addr) == REG)
1454 regno = REGNO (addr);
1457 else if (GET_CODE (addr) == PLUS
1458 && GET_CODE (XEXP (addr, 0)) == REG
1459 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1460 && ((INTVAL (XEXP (addr, 1)))
1461 < ep_memory_offset (GET_MODE (mem), unsignedp))
1462 && ((INTVAL (XEXP (addr, 1))) >= 0))
1465 regno = REGNO (XEXP (addr, 0));
1474 regs[regno].last_insn = insn;
1475 if (!regs[regno].first_insn)
1476 regs[regno].first_insn = insn;
1480 /* Loading up a register in the basic block zaps any savings
1482 if (GET_CODE (dest) == REG)
1484 enum machine_mode mode = GET_MODE (dest);
1488 regno = REGNO (dest);
1489 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1493 /* See if we can use the pointer before this
1498 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1500 if (max_uses < regs[i].uses)
1502 max_uses = regs[i].uses;
1508 && max_regno >= regno
1509 && max_regno < endregno)
1511 substitute_ep_register (regs[max_regno].first_insn,
1512 regs[max_regno].last_insn,
1513 max_uses, max_regno, &r1,
1516 /* Since we made a substitution, zap all remembered
1518 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1521 regs[i].first_insn = NULL_RTX;
1522 regs[i].last_insn = NULL_RTX;
1527 for (i = regno; i < endregno; i++)
1530 regs[i].first_insn = NULL_RTX;
1531 regs[i].last_insn = NULL_RTX;
1540 /* # of registers saved by the interrupt handler. */
1541 #define INTERRUPT_FIXED_NUM 4
1543 /* # of bytes for registers saved by the interrupt handler. */
1544 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1546 /* # of registers saved in register parameter area. */
1547 #define INTERRUPT_REGPARM_NUM 4
1548 /* # of words saved for other registers. */
1549 #define INTERRUPT_ALL_SAVE_NUM \
1550 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1552 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1555 compute_register_save_size (p_reg_saved)
1560 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1561 int call_p = regs_ever_live [LINK_POINTER_REGNUM];
1564 /* Count the return pointer if we need to save it. */
1565 if (current_function_profile && !call_p)
1566 regs_ever_live [LINK_POINTER_REGNUM] = call_p = 1;
1568 /* Count space for the register saves. */
1569 if (interrupt_handler)
1571 for (i = 0; i <= 31; i++)
1575 if (regs_ever_live[i] || call_p)
1578 reg_saved |= 1L << i;
1582 /* We don't save/restore r0 or the stack pointer */
1584 case STACK_POINTER_REGNUM:
1587 /* For registers with fixed use, we save them, set them to the
1588 appropriate value, and then restore them.
1589 These registers are handled specially, so don't list them
1590 on the list of registers to save in the prologue. */
1591 case 1: /* temp used to hold ep */
1593 case 10: /* temp used to call interrupt save/restore */
1594 case EP_REGNUM: /* ep */
1601 /* Find the first register that needs to be saved. */
1602 for (i = 0; i <= 31; i++)
1603 if (regs_ever_live[i] && ((! call_used_regs[i])
1604 || i == LINK_POINTER_REGNUM))
1607 /* If it is possible that an out-of-line helper function might be
1608 used to generate the prologue for the current function, then we
1609 need to cover the possibility that such a helper function will
1610 be used, despite the fact that there might be gaps in the list of
1611 registers that need to be saved. To detect this we note that the
1612 helper functions always push at least register r29 (provided
1613 that the function is not an interrupt handler). */
1615 if (TARGET_PROLOG_FUNCTION
1616 && (i == 2 || ((i >= 20) && (i < 30))))
1621 reg_saved |= 1L << i;
1626 /* Helper functions save all registers between the starting
1627 register and the last register, regardless of whether they
1628 are actually used by the function or not. */
1629 for (; i <= 29; i++)
1632 reg_saved |= 1L << i;
1635 if (regs_ever_live [LINK_POINTER_REGNUM])
1638 reg_saved |= 1L << LINK_POINTER_REGNUM;
1643 for (; i <= 31; i++)
1644 if (regs_ever_live[i] && ((! call_used_regs[i])
1645 || i == LINK_POINTER_REGNUM))
1648 reg_saved |= 1L << i;
1654 *p_reg_saved = reg_saved;
1660 compute_frame_size (size, p_reg_saved)
1665 + compute_register_save_size (p_reg_saved)
1666 + current_function_outgoing_args_size);
1675 unsigned int size = get_frame_size ();
1676 unsigned int actual_fsize;
1677 unsigned int init_stack_alloc = 0;
1680 unsigned int num_save;
1681 unsigned int default_stack;
1683 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1686 actual_fsize = compute_frame_size (size, ®_saved);
1688 /* Save/setup global registers for interrupt functions right now. */
1689 if (interrupt_handler)
1691 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1692 emit_insn (gen_callt_save_interrupt ());
1694 emit_insn (gen_save_interrupt ());
1696 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1698 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1699 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1702 /* Save arg registers to the stack if necessary. */
1703 else if (current_function_args_info.anonymous_args)
1705 if (TARGET_PROLOG_FUNCTION && TARGET_V850E && !TARGET_DISABLE_CALLT)
1706 emit_insn (gen_save_r6_r9_v850e ());
1707 else if (TARGET_PROLOG_FUNCTION && ! TARGET_LONG_CALLS)
1708 emit_insn (gen_save_r6_r9 ());
1712 for (i = 6; i < 10; i++)
1714 emit_move_insn (gen_rtx_MEM (SImode,
1715 plus_constant (stack_pointer_rtx,
1717 gen_rtx_REG (SImode, i));
1723 /* Identify all of the saved registers. */
1726 for (i = 1; i < 31; i++)
1728 if (((1L << i) & reg_saved) != 0)
1729 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1732 /* If the return pointer is saved, the helper functions also allocate
1733 16 bytes of stack for arguments to be saved in. */
1734 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1736 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1740 /* See if we have an insn that allocates stack space and saves the particular
1741 registers we want to. */
1742 save_all = NULL_RTX;
1743 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1745 int alloc_stack = (4 * num_save) + default_stack;
1746 int unalloc_stack = actual_fsize - alloc_stack;
1747 int save_func_len = 4;
1748 int save_normal_len;
1751 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1753 /* see if we would have used ep to save the stack */
1754 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1755 save_normal_len = (3 * 2) + (2 * num_save);
1757 save_normal_len = 4 * num_save;
1759 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1761 /* Don't bother checking if we don't actually save any space.
1762 This happens for instance if one register is saved and additional
1763 stack space is allocated. */
1764 if (save_func_len < save_normal_len)
1766 save_all = gen_rtx_PARALLEL
1768 rtvec_alloc (num_save + 1
1769 + (TARGET_V850 ? (TARGET_LONG_CALLS ? 2 : 1) : 0)));
1771 XVECEXP (save_all, 0, 0)
1772 = gen_rtx_SET (VOIDmode,
1774 plus_constant (stack_pointer_rtx, -alloc_stack));
1776 offset = - default_stack;
1777 for (i = 0; i < num_save; i++)
1779 XVECEXP (save_all, 0, i+1)
1780 = gen_rtx_SET (VOIDmode,
1782 plus_constant (stack_pointer_rtx,
1790 XVECEXP (save_all, 0, num_save + 1)
1791 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1793 if (TARGET_LONG_CALLS)
1794 XVECEXP (save_all, 0, num_save + 2)
1795 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
1798 code = recog (save_all, NULL_RTX, NULL);
1801 rtx insn = emit_insn (save_all);
1802 INSN_CODE (insn) = code;
1803 actual_fsize -= alloc_stack;
1807 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1808 save_normal_len - save_func_len,
1809 save_normal_len, save_func_len,
1810 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1813 save_all = NULL_RTX;
1817 /* If no prolog save function is available, store the registers the old
1818 fashioned way (one by one). */
1821 /* Special case interrupt functions that save all registers for a call. */
1822 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1824 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1825 emit_insn (gen_callt_save_all_interrupt ());
1827 emit_insn (gen_save_all_interrupt ());
1831 /* If the stack is too big, allocate it in chunks so we can do the
1832 register saves. We use the register save size so we use the ep
1834 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1835 init_stack_alloc = compute_register_save_size (NULL);
1837 init_stack_alloc = actual_fsize;
1839 /* Save registers at the beginning of the stack frame */
1840 offset = init_stack_alloc - 4;
1842 if (init_stack_alloc)
1843 emit_insn (gen_addsi3 (stack_pointer_rtx,
1845 GEN_INT (-init_stack_alloc)));
1847 /* Save the return pointer first. */
1848 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1850 emit_move_insn (gen_rtx_MEM (SImode,
1851 plus_constant (stack_pointer_rtx,
1853 save_regs[--num_save]);
1857 for (i = 0; i < num_save; i++)
1859 emit_move_insn (gen_rtx_MEM (SImode,
1860 plus_constant (stack_pointer_rtx,
1868 /* Allocate the rest of the stack that was not allocated above (either it is
1869 > 32K or we just called a function to save the registers and needed more
1871 if (actual_fsize > init_stack_alloc)
1873 int diff = actual_fsize - init_stack_alloc;
1874 if (CONST_OK_FOR_K (diff))
1875 emit_insn (gen_addsi3 (stack_pointer_rtx,
1880 rtx reg = gen_rtx_REG (Pmode, 12);
1881 emit_move_insn (reg, GEN_INT (-diff));
1882 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1886 /* If we need a frame pointer, set it up now. */
1887 if (frame_pointer_needed)
1888 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1897 unsigned int size = get_frame_size ();
1899 unsigned int actual_fsize = compute_frame_size (size, ®_saved);
1900 unsigned int init_stack_free = 0;
1901 rtx restore_regs[32];
1903 unsigned int num_restore;
1904 unsigned int default_stack;
1906 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1908 /* Eliminate the initial stack stored by interrupt functions. */
1909 if (interrupt_handler)
1911 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1912 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1913 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1916 /* Cut off any dynamic stack created. */
1917 if (frame_pointer_needed)
1918 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1920 /* Identify all of the saved registers. */
1923 for (i = 1; i < 31; i++)
1925 if (((1L << i) & reg_saved) != 0)
1926 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1929 /* If the return pointer is saved, the helper functions also allocate
1930 16 bytes of stack for arguments to be saved in. */
1931 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1933 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1937 /* See if we have an insn that restores the particular registers we
1939 restore_all = NULL_RTX;
1941 if (TARGET_PROLOG_FUNCTION
1943 && actual_fsize >= default_stack
1944 && !interrupt_handler)
1946 int alloc_stack = (4 * num_restore) + default_stack;
1947 int unalloc_stack = actual_fsize - alloc_stack;
1948 int restore_func_len = 4;
1949 int restore_normal_len;
1952 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1954 /* See if we would have used ep to restore the registers. */
1955 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1956 restore_normal_len = (3 * 2) + (2 * num_restore);
1958 restore_normal_len = 4 * num_restore;
1960 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1962 /* Don't bother checking if we don't actually save any space. */
1963 if (restore_func_len < restore_normal_len)
1965 restore_all = gen_rtx_PARALLEL (VOIDmode,
1966 rtvec_alloc (num_restore + 2));
1967 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1968 XVECEXP (restore_all, 0, 1)
1969 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1970 gen_rtx_PLUS (Pmode,
1972 GEN_INT (alloc_stack)));
1974 offset = alloc_stack - 4;
1975 for (i = 0; i < num_restore; i++)
1977 XVECEXP (restore_all, 0, i+2)
1978 = gen_rtx_SET (VOIDmode,
1981 plus_constant (stack_pointer_rtx,
1986 code = recog (restore_all, NULL_RTX, NULL);
1992 actual_fsize -= alloc_stack;
1995 if (CONST_OK_FOR_K (actual_fsize))
1996 emit_insn (gen_addsi3 (stack_pointer_rtx,
1998 GEN_INT (actual_fsize)));
2001 rtx reg = gen_rtx_REG (Pmode, 12);
2002 emit_move_insn (reg, GEN_INT (actual_fsize));
2003 emit_insn (gen_addsi3 (stack_pointer_rtx,
2009 insn = emit_jump_insn (restore_all);
2010 INSN_CODE (insn) = code;
2014 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
2015 restore_normal_len - restore_func_len,
2016 restore_normal_len, restore_func_len,
2017 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
2020 restore_all = NULL_RTX;
2024 /* If no epilog save function is available, restore the registers the
2025 old fashioned way (one by one). */
2028 /* If the stack is large, we need to cut it down in 2 pieces. */
2029 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
2030 init_stack_free = 4 * num_restore;
2032 init_stack_free = actual_fsize;
2034 /* Deallocate the rest of the stack if it is > 32K. */
2035 if (actual_fsize > init_stack_free)
2039 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
2041 if (CONST_OK_FOR_K (diff))
2042 emit_insn (gen_addsi3 (stack_pointer_rtx,
2047 rtx reg = gen_rtx_REG (Pmode, 12);
2048 emit_move_insn (reg, GEN_INT (diff));
2049 emit_insn (gen_addsi3 (stack_pointer_rtx,
2055 /* Special case interrupt functions that save all registers
2057 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
2059 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
2060 emit_insn (gen_callt_restore_all_interrupt ());
2062 emit_insn (gen_restore_all_interrupt ());
2066 /* Restore registers from the beginning of the stack frame. */
2067 offset = init_stack_free - 4;
2069 /* Restore the return pointer first. */
2071 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
2073 emit_move_insn (restore_regs[--num_restore],
2074 gen_rtx_MEM (SImode,
2075 plus_constant (stack_pointer_rtx,
2080 for (i = 0; i < num_restore; i++)
2082 emit_move_insn (restore_regs[i],
2083 gen_rtx_MEM (SImode,
2084 plus_constant (stack_pointer_rtx,
2087 emit_insn (gen_rtx_USE (VOIDmode, restore_regs[i]));
2091 /* Cut back the remainder of the stack. */
2092 if (init_stack_free)
2093 emit_insn (gen_addsi3 (stack_pointer_rtx,
2095 GEN_INT (init_stack_free)));
2098 /* And return or use reti for interrupt handlers. */
2099 if (interrupt_handler)
2101 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
2102 emit_insn (gen_callt_return_interrupt ());
2104 emit_jump_insn (gen_return_interrupt ());
2106 else if (actual_fsize)
2107 emit_jump_insn (gen_return_internal ());
2109 emit_jump_insn (gen_return ());
2112 v850_interrupt_cache_p = FALSE;
2113 v850_interrupt_p = FALSE;
2117 /* Update the condition code from the insn. */
2120 notice_update_cc (body, insn)
2124 switch (get_attr_cc (insn))
2127 /* Insn does not affect CC at all. */
2131 /* Insn does not change CC, but the 0'th operand has been changed. */
2132 if (cc_status.value1 != 0
2133 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
2134 cc_status.value1 = 0;
2138 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2139 V,C is in an unusable state. */
2141 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
2142 cc_status.value1 = recog_data.operand[0];
2146 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2147 C is in an unusable state. */
2149 cc_status.flags |= CC_NO_CARRY;
2150 cc_status.value1 = recog_data.operand[0];
2154 /* The insn is a compare instruction. */
2156 cc_status.value1 = SET_SRC (body);
2160 /* Insn doesn't leave CC in a usable state. */
2166 /* Retrieve the data area that has been chosen for the given decl. */
2169 v850_get_data_area (decl)
2172 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2173 return DATA_AREA_SDA;
2175 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2176 return DATA_AREA_TDA;
2178 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2179 return DATA_AREA_ZDA;
2181 return DATA_AREA_NORMAL;
2184 /* Store the indicated data area in the decl's attributes. */
2187 v850_set_data_area (decl, data_area)
2189 v850_data_area data_area;
2195 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2196 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2197 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2202 DECL_ATTRIBUTES (decl) = tree_cons
2203 (name, NULL, DECL_ATTRIBUTES (decl));
2206 const struct attribute_spec v850_attribute_table[] =
2208 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2209 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2210 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2211 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2212 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2213 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2214 { NULL, 0, 0, false, false, false, NULL }
2217 /* Handle an "interrupt" attribute; arguments as in
2218 struct attribute_spec.handler. */
2220 v850_handle_interrupt_attribute (node, name, args, flags, no_add_attrs)
2223 tree args ATTRIBUTE_UNUSED;
2224 int flags ATTRIBUTE_UNUSED;
2227 if (TREE_CODE (*node) != FUNCTION_DECL)
2229 warning ("`%s' attribute only applies to functions",
2230 IDENTIFIER_POINTER (name));
2231 *no_add_attrs = true;
2237 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2238 struct attribute_spec.handler. */
2240 v850_handle_data_area_attribute (node, name, args, flags, no_add_attrs)
2243 tree args ATTRIBUTE_UNUSED;
2244 int flags ATTRIBUTE_UNUSED;
2247 v850_data_area data_area;
2248 v850_data_area area;
2251 /* Implement data area attribute. */
2252 if (is_attribute_p ("sda", name))
2253 data_area = DATA_AREA_SDA;
2254 else if (is_attribute_p ("tda", name))
2255 data_area = DATA_AREA_TDA;
2256 else if (is_attribute_p ("zda", name))
2257 data_area = DATA_AREA_ZDA;
2261 switch (TREE_CODE (decl))
2264 if (current_function_decl != NULL_TREE)
2266 error_with_decl (decl, "\
2267 a data area attribute cannot be specified for local variables");
2268 *no_add_attrs = true;
2274 area = v850_get_data_area (decl);
2275 if (area != DATA_AREA_NORMAL && data_area != area)
2277 error_with_decl (decl, "\
2278 data area of '%s' conflicts with previous declaration");
2279 *no_add_attrs = true;
2291 /* Return nonzero if FUNC is an interrupt function as specified
2292 by the "interrupt" attribute. */
2295 v850_interrupt_function_p (func)
2301 if (v850_interrupt_cache_p)
2302 return v850_interrupt_p;
2304 if (TREE_CODE (func) != FUNCTION_DECL)
2307 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2313 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2314 ret = a != NULL_TREE;
2317 /* Its not safe to trust global variables until after function inlining has
2319 if (reload_completed | reload_in_progress)
2320 v850_interrupt_p = ret;
2327 v850_encode_data_area (decl, symbol)
2333 /* Map explict sections into the appropriate attribute */
2334 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2336 if (DECL_SECTION_NAME (decl))
2338 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2340 if (streq (name, ".zdata") || streq (name, ".zbss"))
2341 v850_set_data_area (decl, DATA_AREA_ZDA);
2343 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2344 v850_set_data_area (decl, DATA_AREA_SDA);
2346 else if (streq (name, ".tdata"))
2347 v850_set_data_area (decl, DATA_AREA_TDA);
2350 /* If no attribute, support -m{zda,sda,tda}=n */
2353 int size = int_size_in_bytes (TREE_TYPE (decl));
2357 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2358 v850_set_data_area (decl, DATA_AREA_TDA);
2360 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2361 v850_set_data_area (decl, DATA_AREA_SDA);
2363 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2364 v850_set_data_area (decl, DATA_AREA_ZDA);
2367 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2371 flags = SYMBOL_REF_FLAGS (symbol);
2372 switch (v850_get_data_area (decl))
2374 case DATA_AREA_ZDA: flags |= SYMBOL_FLAG_ZDA; break;
2375 case DATA_AREA_TDA: flags |= SYMBOL_FLAG_TDA; break;
2376 case DATA_AREA_SDA: flags |= SYMBOL_FLAG_SDA; break;
2379 SYMBOL_REF_FLAGS (symbol) = flags;
2383 v850_encode_section_info (decl, rtl, first)
2388 default_encode_section_info (decl, rtl, first);
2390 if (TREE_CODE (decl) == VAR_DECL
2391 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2392 v850_encode_data_area (decl, XEXP (rtl, 0));
2395 /* Return true if the given RTX is a register which can be restored
2396 by a function epilogue. */
2398 register_is_ok_for_epilogue (op, mode)
2400 enum machine_mode ATTRIBUTE_UNUSED mode;
2402 /* The save/restore routines can only cope with registers 20 - 31. */
2403 return ((GET_CODE (op) == REG)
2404 && (((REGNO (op) >= 20) && REGNO (op) <= 31)));
2407 /* Return nonzero if the given RTX is suitable for collapsing into
2408 jump to a function epilogue. */
2410 pattern_is_ok_for_epilogue (op, mode)
2412 enum machine_mode ATTRIBUTE_UNUSED mode;
2414 int count = XVECLEN (op, 0);
2417 /* If there are no registers to restore then the function epilogue
2422 /* The pattern matching has already established that we are performing a
2423 function epilogue and that we are popping at least one register. We must
2424 now check the remaining entries in the vector to make sure that they are
2425 also register pops. There is no good reason why there should ever be
2426 anything else in this vector, but being paranoid always helps...
2428 The test below performs the C equivalent of this machine description
2431 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2432 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2435 for (i = 3; i < count; i++)
2437 rtx vector_element = XVECEXP (op, 0, i);
2442 if (GET_CODE (vector_element) != SET)
2445 dest = SET_DEST (vector_element);
2446 src = SET_SRC (vector_element);
2448 if (GET_CODE (dest) != REG
2449 || GET_MODE (dest) != SImode
2450 || ! register_is_ok_for_epilogue (dest, SImode)
2451 || GET_CODE (src) != MEM
2452 || GET_MODE (src) != SImode)
2455 plus = XEXP (src, 0);
2457 if (GET_CODE (plus) != PLUS
2458 || GET_CODE (XEXP (plus, 0)) != REG
2459 || GET_MODE (XEXP (plus, 0)) != SImode
2460 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2461 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2468 /* Construct a JR instruction to a routine that will perform the equivalent of
2469 the RTL passed in as an argument. This RTL is a function epilogue that
2470 pops registers off the stack and possibly releases some extra stack space
2471 as well. The code has already verified that the RTL matches these
2474 construct_restore_jr (op)
2477 int count = XVECLEN (op, 0);
2479 unsigned long int mask;
2480 unsigned long int first;
2481 unsigned long int last;
2483 static char buff [100]; /* XXX */
2487 error ("bogus JR construction: %d\n", count);
2491 /* Work out how many bytes to pop off the stack before retrieving
2493 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2495 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2497 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2500 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2502 /* Each pop will remove 4 bytes from the stack... */
2503 stack_bytes -= (count - 2) * 4;
2505 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2506 if (stack_bytes != 0 && stack_bytes != 16)
2508 error ("bad amount of stack space removal: %d", stack_bytes);
2512 /* Now compute the bit mask of registers to push. */
2514 for (i = 2; i < count; i++)
2516 rtx vector_element = XVECEXP (op, 0, i);
2518 if (GET_CODE (vector_element) != SET)
2520 if (GET_CODE (SET_DEST (vector_element)) != REG)
2522 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2525 mask |= 1 << REGNO (SET_DEST (vector_element));
2528 /* Scan for the first register to pop. */
2529 for (first = 0; first < 32; first++)
2531 if (mask & (1 << first))
2538 /* Discover the last register to pop. */
2539 if (mask & (1 << LINK_POINTER_REGNUM))
2541 if (stack_bytes != 16)
2544 last = LINK_POINTER_REGNUM;
2548 if (stack_bytes != 0)
2551 if ((mask & (1 << 29)) == 0)
2557 /* Note, it is possible to have gaps in the register mask.
2558 We ignore this here, and generate a JR anyway. We will
2559 be popping more registers than is strictly necessary, but
2560 it does save code space. */
2562 if (TARGET_LONG_CALLS)
2567 sprintf (name, "__return_%s", reg_names [first]);
2569 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2571 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2577 sprintf (buff, "jr __return_%s", reg_names [first]);
2579 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2586 /* Return nonzero if the given RTX is suitable for collapsing into
2587 a jump to a function prologue. */
2589 pattern_is_ok_for_prologue (op, mode)
2591 enum machine_mode ATTRIBUTE_UNUSED mode;
2593 int count = XVECLEN (op, 0);
2597 /* If there are no registers to save then the function prologue
2602 /* The pattern matching has already established that we are adjusting the
2603 stack and pushing at least one register. We must now check that the
2604 remaining entries in the vector to make sure that they are also register
2605 pushes, except for the last entry which should be a CLOBBER of r10.
2607 The test below performs the C equivalent of this machine description
2610 (set (mem:SI (plus:SI (reg:SI 3)
2611 (match_operand:SI 2 "immediate_operand" "i")))
2612 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2616 for (i = 2; i < count - (TARGET_LONG_CALLS ? 2: 1); i++)
2622 vector_element = XVECEXP (op, 0, i);
2624 if (GET_CODE (vector_element) != SET)
2627 dest = SET_DEST (vector_element);
2628 src = SET_SRC (vector_element);
2630 if (GET_CODE (dest) != MEM
2631 || GET_MODE (dest) != SImode
2632 || GET_CODE (src) != REG
2633 || GET_MODE (src) != SImode
2634 || ! register_is_ok_for_epilogue (src, SImode))
2637 plus = XEXP (dest, 0);
2639 if ( GET_CODE (plus) != PLUS
2640 || GET_CODE (XEXP (plus, 0)) != REG
2641 || GET_MODE (XEXP (plus, 0)) != SImode
2642 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2643 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2646 /* If the register is being pushed somewhere other than the stack
2647 space just acquired by the first operand then abandon this quest.
2648 Note: the test is <= because both values are negative. */
2649 if (INTVAL (XEXP (plus, 1))
2650 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2656 /* Make sure that the last entries in the vector are clobbers. */
2657 for (; i < count; i++)
2659 vector_element = XVECEXP (op, 0, i);
2661 if (GET_CODE (vector_element) != CLOBBER
2662 || GET_CODE (XEXP (vector_element, 0)) != REG
2663 || !(REGNO (XEXP (vector_element, 0)) == 10
2664 || (TARGET_LONG_CALLS ? (REGNO (XEXP (vector_element, 0)) == 11) : 0 )))
2671 /* Construct a JARL instruction to a routine that will perform the equivalent
2672 of the RTL passed as a parameter. This RTL is a function prologue that
2673 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2674 some stack space as well. The code has already verified that the RTL
2675 matches these requirements. */
2677 construct_save_jarl (op)
2680 int count = XVECLEN (op, 0);
2682 unsigned long int mask;
2683 unsigned long int first;
2684 unsigned long int last;
2686 static char buff [100]; /* XXX */
2690 error ("bogus JARL construction: %d\n", count);
2695 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2697 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2699 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2701 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2704 /* Work out how many bytes to push onto the stack after storing the
2706 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2708 /* Each push will put 4 bytes from the stack... */
2709 stack_bytes += (count - (TARGET_LONG_CALLS ? 3 : 2)) * 4;
2711 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2712 if (stack_bytes != 0 && stack_bytes != -16)
2714 error ("bad amount of stack space removal: %d", stack_bytes);
2718 /* Now compute the bit mask of registers to push. */
2720 for (i = 1; i < count - (TARGET_LONG_CALLS ? 2 : 1); i++)
2722 rtx vector_element = XVECEXP (op, 0, i);
2724 if (GET_CODE (vector_element) != SET)
2726 if (GET_CODE (SET_SRC (vector_element)) != REG)
2728 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2731 mask |= 1 << REGNO (SET_SRC (vector_element));
2734 /* Scan for the first register to push. */
2735 for (first = 0; first < 32; first++)
2737 if (mask & (1 << first))
2744 /* Discover the last register to push. */
2745 if (mask & (1 << LINK_POINTER_REGNUM))
2747 if (stack_bytes != -16)
2750 last = LINK_POINTER_REGNUM;
2754 if (stack_bytes != 0)
2756 if ((mask & (1 << 29)) == 0)
2762 /* Note, it is possible to have gaps in the register mask.
2763 We ignore this here, and generate a JARL anyway. We will
2764 be pushing more registers than is strictly necessary, but
2765 it does save code space. */
2767 if (TARGET_LONG_CALLS)
2772 sprintf (name, "__save_%s", reg_names [first]);
2774 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2776 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2782 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2784 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2791 extern tree last_assemble_variable_decl;
2792 extern int size_directive_output;
2794 /* A version of asm_output_aligned_bss() that copes with the special
2795 data areas of the v850. */
2797 v850_output_aligned_bss (file, decl, name, size, align)
2804 switch (v850_get_data_area (decl))
2822 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2823 #ifdef ASM_DECLARE_OBJECT_NAME
2824 last_assemble_variable_decl = decl;
2825 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2827 /* Standard thing is just output label for the object. */
2828 ASM_OUTPUT_LABEL (file, name);
2829 #endif /* ASM_DECLARE_OBJECT_NAME */
2830 ASM_OUTPUT_SKIP (file, size ? size : 1);
2833 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2835 v850_output_common (file, decl, name, size, align)
2842 if (decl == NULL_TREE)
2844 fprintf (file, "%s", COMMON_ASM_OP);
2848 switch (v850_get_data_area (decl))
2851 fprintf (file, "%s", ZCOMMON_ASM_OP);
2855 fprintf (file, "%s", SCOMMON_ASM_OP);
2859 fprintf (file, "%s", TCOMMON_ASM_OP);
2863 fprintf (file, "%s", COMMON_ASM_OP);
2868 assemble_name (file, name);
2869 fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2872 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2874 v850_output_local (file, decl, name, size, align)
2881 fprintf (file, "%s", LOCAL_ASM_OP);
2882 assemble_name (file, name);
2883 fprintf (file, "\n");
2885 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2888 /* Add data area to the given declaration if a ghs data area pragma is
2889 currently in effect (#pragma ghs startXXX/endXXX). */
2891 v850_insert_attributes (decl, attr_ptr)
2893 tree *attr_ptr ATTRIBUTE_UNUSED;
2896 && data_area_stack->data_area
2897 && current_function_decl == NULL_TREE
2898 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2899 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2900 v850_set_data_area (decl, data_area_stack->data_area);
2902 /* Initialize the default names of the v850 specific sections,
2903 if this has not been done before. */
2905 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2907 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2908 = build_string (sizeof (".sdata")-1, ".sdata");
2910 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2911 = build_string (sizeof (".rosdata")-1, ".rosdata");
2913 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2914 = build_string (sizeof (".tdata")-1, ".tdata");
2916 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2917 = build_string (sizeof (".zdata")-1, ".zdata");
2919 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2920 = build_string (sizeof (".rozdata")-1, ".rozdata");
2923 if (current_function_decl == NULL_TREE
2924 && (TREE_CODE (decl) == VAR_DECL
2925 || TREE_CODE (decl) == CONST_DECL
2926 || TREE_CODE (decl) == FUNCTION_DECL)
2927 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2928 && !DECL_SECTION_NAME (decl))
2930 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2931 tree chosen_section;
2933 if (TREE_CODE (decl) == FUNCTION_DECL)
2934 kind = GHS_SECTION_KIND_TEXT;
2937 /* First choose a section kind based on the data area of the decl. */
2938 switch (v850_get_data_area (decl))
2944 kind = ((TREE_READONLY (decl))
2945 ? GHS_SECTION_KIND_ROSDATA
2946 : GHS_SECTION_KIND_SDATA);
2950 kind = GHS_SECTION_KIND_TDATA;
2954 kind = ((TREE_READONLY (decl))
2955 ? GHS_SECTION_KIND_ROZDATA
2956 : GHS_SECTION_KIND_ZDATA);
2959 case DATA_AREA_NORMAL: /* default data area */
2960 if (TREE_READONLY (decl))
2961 kind = GHS_SECTION_KIND_RODATA;
2962 else if (DECL_INITIAL (decl))
2963 kind = GHS_SECTION_KIND_DATA;
2965 kind = GHS_SECTION_KIND_BSS;
2969 /* Now, if the section kind has been explicitly renamed,
2970 then attach a section attribute. */
2971 chosen_section = GHS_current_section_names [(int) kind];
2973 /* Otherwise, if this kind of section needs an explicit section
2974 attribute, then also attach one. */
2975 if (chosen_section == NULL)
2976 chosen_section = GHS_default_section_names [(int) kind];
2980 /* Only set the section name if specified by a pragma, because
2981 otherwise it will force those variables to get allocated storage
2982 in this module, rather than by the linker. */
2983 DECL_SECTION_NAME (decl) = chosen_section;
2988 /* Return nonzero if the given RTX is suitable
2989 for collapsing into a DISPOSE instruction. */
2992 pattern_is_ok_for_dispose (op, mode)
2994 enum machine_mode mode ATTRIBUTE_UNUSED;
2996 int count = XVECLEN (op, 0);
2999 /* If there are no registers to restore then
3000 the dispose instruction is not suitable. */
3004 /* The pattern matching has already established that we are performing a
3005 function epilogue and that we are popping at least one register. We must
3006 now check the remaining entries in the vector to make sure that they are
3007 also register pops. There is no good reason why there should ever be
3008 anything else in this vector, but being paranoid always helps...
3010 The test below performs the C equivalent of this machine description
3013 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
3014 (mem:SI (plus:SI (reg:SI 3)
3015 (match_operand:SI n "immediate_operand" "i"))))
3018 for (i = 3; i < count; i++)
3020 rtx vector_element = XVECEXP (op, 0, i);
3025 if (GET_CODE (vector_element) != SET)
3028 dest = SET_DEST (vector_element);
3029 src = SET_SRC (vector_element);
3031 if ( GET_CODE (dest) != REG
3032 || GET_MODE (dest) != SImode
3033 || ! register_is_ok_for_epilogue (dest, SImode)
3034 || GET_CODE (src) != MEM
3035 || GET_MODE (src) != SImode)
3038 plus = XEXP (src, 0);
3040 if ( GET_CODE (plus) != PLUS
3041 || GET_CODE (XEXP (plus, 0)) != REG
3042 || GET_MODE (XEXP (plus, 0)) != SImode
3043 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
3044 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
3051 /* Construct a DISPOSE instruction that is the equivalent of
3052 the given RTX. We have already verified that this should
3056 construct_dispose_instruction (op)
3059 int count = XVECLEN (op, 0);
3061 unsigned long int mask;
3063 static char buff[ 100 ]; /* XXX */
3068 error ("Bogus DISPOSE construction: %d\n", count);
3072 /* Work out how many bytes to pop off the
3073 stack before retrieving registers. */
3074 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
3076 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
3078 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
3081 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
3083 /* Each pop will remove 4 bytes from the stack... */
3084 stack_bytes -= (count - 2) * 4;
3086 /* Make sure that the amount we are popping
3087 will fit into the DISPOSE instruction. */
3088 if (stack_bytes > 128)
3090 error ("Too much stack space to dispose of: %d", stack_bytes);
3094 /* Now compute the bit mask of registers to push. */
3097 for (i = 2; i < count; i++)
3099 rtx vector_element = XVECEXP (op, 0, i);
3101 if (GET_CODE (vector_element) != SET)
3103 if (GET_CODE (SET_DEST (vector_element)) != REG)
3105 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
3108 if (REGNO (SET_DEST (vector_element)) == 2)
3111 mask |= 1 << REGNO (SET_DEST (vector_element));
3114 if (! TARGET_DISABLE_CALLT
3115 && (use_callt || stack_bytes == 0 || stack_bytes == 16))
3119 sprintf (buff, "callt ctoff(__callt_return_r2_r%d)", (mask & (1 << 31)) ? 31 : 29);
3124 for (i = 20; i < 32; i++)
3125 if (mask & (1 << i))
3129 sprintf (buff, "callt ctoff(__callt_return_r31c)");
3131 sprintf (buff, "callt ctoff(__callt_return_r%d_r%d%s)",
3132 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
3137 static char regs [100]; /* XXX */
3140 /* Generate the DISPOSE instruction. Note we could just issue the
3141 bit mask as a number as the assembler can cope with this, but for
3142 the sake of our readers we turn it into a textual description. */
3146 for (i = 20; i < 32; i++)
3148 if (mask & (1 << i))
3153 strcat (regs, ", ");
3158 strcat (regs, reg_names[ first ]);
3160 for (i++; i < 32; i++)
3161 if ((mask & (1 << i)) == 0)
3166 strcat (regs, " - ");
3167 strcat (regs, reg_names[ i - 1 ] );
3172 sprintf (buff, "dispose %d {%s}, r31", stack_bytes / 4, regs);
3178 /* Return nonzero if the given RTX is suitable
3179 for collapsing into a PREPARE instruction. */
3182 pattern_is_ok_for_prepare (op, mode)
3184 enum machine_mode mode ATTRIBUTE_UNUSED;
3186 int count = XVECLEN (op, 0);
3189 /* If there are no registers to restore then the prepare instruction
3194 /* The pattern matching has already established that we are adjusting the
3195 stack and pushing at least one register. We must now check that the
3196 remaining entries in the vector to make sure that they are also register
3199 The test below performs the C equivalent of this machine description
3202 (set (mem:SI (plus:SI (reg:SI 3)
3203 (match_operand:SI 2 "immediate_operand" "i")))
3204 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3208 for (i = 2; i < count; i++)
3210 rtx vector_element = XVECEXP (op, 0, i);
3215 if (GET_CODE (vector_element) != SET)
3218 dest = SET_DEST (vector_element);
3219 src = SET_SRC (vector_element);
3221 if ( GET_CODE (dest) != MEM
3222 || GET_MODE (dest) != SImode
3223 || GET_CODE (src) != REG
3224 || GET_MODE (src) != SImode
3225 || ! register_is_ok_for_epilogue (src, SImode)
3229 plus = XEXP (dest, 0);
3231 if ( GET_CODE (plus) != PLUS
3232 || GET_CODE (XEXP (plus, 0)) != REG
3233 || GET_MODE (XEXP (plus, 0)) != SImode
3234 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
3235 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
3238 /* If the register is being pushed somewhere other than the stack
3239 space just aquired by the first operand then abandon this quest.
3240 Note: the test is <= becuase both values are negative. */
3241 if (INTVAL (XEXP (plus, 1))
3242 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
3249 /* Construct a PREPARE instruction that is the equivalent of
3250 the given RTL. We have already verified that this should
3254 construct_prepare_instruction (op)
3257 int count = XVECLEN (op, 0);
3259 unsigned long int mask;
3261 static char buff[ 100 ]; /* XXX */
3266 error ("Bogus PREPEARE construction: %d\n", count);
3270 /* Work out how many bytes to push onto
3271 the stack after storing the registers. */
3272 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
3274 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
3276 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
3279 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
3281 /* Each push will put 4 bytes from the stack. */
3282 stack_bytes += (count - 1) * 4;
3284 /* Make sure that the amount we are popping
3285 will fit into the DISPOSE instruction. */
3286 if (stack_bytes < -128)
3288 error ("Too much stack space to prepare: %d", stack_bytes);
3292 /* Now compute the bit mask of registers to push. */
3294 for (i = 1; i < count; i++)
3296 rtx vector_element = XVECEXP (op, 0, i);
3298 if (GET_CODE (vector_element) != SET)
3300 if (GET_CODE (SET_SRC (vector_element)) != REG)
3302 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
3305 if (REGNO (SET_SRC (vector_element)) == 2)
3308 mask |= 1 << REGNO (SET_SRC (vector_element));
3311 if ((! TARGET_DISABLE_CALLT)
3312 && (use_callt || stack_bytes == 0 || stack_bytes == -16))
3316 sprintf (buff, "callt ctoff(__callt_save_r2_r%d)", (mask & (1 << 31)) ? 31 : 29 );
3320 for (i = 20; i < 32; i++)
3321 if (mask & (1 << i))
3325 sprintf (buff, "callt ctoff(__callt_save_r31c)");
3327 sprintf (buff, "callt ctoff(__callt_save_r%d_r%d%s)",
3328 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
3332 static char regs [100]; /* XXX */
3336 /* Generate the PREPARE instruction. Note we could just issue the
3337 bit mask as a number as the assembler can cope with this, but for
3338 the sake of our readers we turn it into a textual description. */
3342 for (i = 20; i < 32; i++)
3344 if (mask & (1 << i))
3349 strcat (regs, ", ");
3354 strcat (regs, reg_names[ first ]);
3356 for (i++; i < 32; i++)
3357 if ((mask & (1 << i)) == 0)
3362 strcat (regs, " - ");
3363 strcat (regs, reg_names[ i - 1 ] );
3368 sprintf (buff, "prepare {%s}, %d", regs, (- stack_bytes) / 4);
3374 /* Implement `va_arg'. */
3377 v850_va_arg (valist, type)
3380 HOST_WIDE_INT size, rsize;
3385 /* Round up sizeof(type) to a word. */
3386 size = int_size_in_bytes (type);
3387 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
3392 size = rsize = UNITS_PER_WORD;
3396 addr = save_expr (valist);
3397 incr = fold (build (PLUS_EXPR, ptr_type_node, addr,
3398 build_int_2 (rsize, 0)));
3400 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
3401 TREE_SIDE_EFFECTS (incr) = 1;
3402 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
3404 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
3408 addr_rtx = force_reg (Pmode, addr_rtx);
3409 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
3410 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
3416 /* Return an RTX indicating where the return address to the
3417 calling function can be found. */
3420 v850_return_addr (count)
3426 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
3430 v850_select_section (exp, reloc, align)
3432 int reloc ATTRIBUTE_UNUSED;
3433 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
3435 if (TREE_CODE (exp) == VAR_DECL)
3438 if (!TREE_READONLY (exp)
3439 || TREE_SIDE_EFFECTS (exp)
3440 || !DECL_INITIAL (exp)
3441 || (DECL_INITIAL (exp) != error_mark_node
3442 && !TREE_CONSTANT (DECL_INITIAL (exp))))
3447 switch (v850_get_data_area (exp))
3469 readonly_data_section ();
3475 else if (TREE_CODE (exp) == STRING_CST)
3477 if (! flag_writable_strings)
3478 readonly_data_section ();
3483 readonly_data_section ();