1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
42 #include "integrate.h"
45 #include "target-def.h"
48 #define streq(a,b) (strcmp (a, b) == 0)
51 /* Function prototypes for stupid compilers: */
52 static void const_double_split (rtx, HOST_WIDE_INT *, HOST_WIDE_INT *);
53 static int const_costs_int (HOST_WIDE_INT, int);
54 static int const_costs (rtx, enum rtx_code);
55 static bool v850_rtx_costs (rtx, int, int, int *);
56 static void substitute_ep_register (rtx, rtx, int, int, rtx *, rtx *);
57 static void v850_reorg (void);
58 static int ep_memory_offset (enum machine_mode, int);
59 static void v850_set_data_area (tree, v850_data_area);
60 const struct attribute_spec v850_attribute_table[];
61 static tree v850_handle_interrupt_attribute (tree *, tree, tree, int, bool *);
62 static tree v850_handle_data_area_attribute (tree *, tree, tree, int, bool *);
63 static void v850_insert_attributes (tree, tree *);
64 static void v850_select_section (tree, int, unsigned HOST_WIDE_INT);
65 static void v850_encode_data_area (tree, rtx);
66 static void v850_encode_section_info (tree, rtx, int);
67 static bool v850_return_in_memory (tree, tree);
68 static void v850_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
70 static bool v850_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
73 /* Information about the various small memory areas. */
74 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
76 /* name value max physical max */
77 { "tda", (char *)0, 0, 256 },
78 { "sda", (char *)0, 0, 65536 },
79 { "zda", (char *)0, 0, 32768 },
82 /* Names of the various data areas used on the v850. */
83 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
84 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
86 /* Track the current data area set by the data area pragma (which
87 can be nested). Tested by check_default_data_area. */
88 data_area_stack_element * data_area_stack = NULL;
90 /* True if we don't need to check any more if the current
91 function is an interrupt handler. */
92 static int v850_interrupt_cache_p = FALSE;
94 /* Whether current function is an interrupt handler. */
95 static int v850_interrupt_p = FALSE;
97 /* Initialize the GCC target structure. */
98 #undef TARGET_ASM_ALIGNED_HI_OP
99 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
101 #undef TARGET_ATTRIBUTE_TABLE
102 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
104 #undef TARGET_INSERT_ATTRIBUTES
105 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
107 #undef TARGET_ASM_SELECT_SECTION
108 #define TARGET_ASM_SELECT_SECTION v850_select_section
110 #undef TARGET_ENCODE_SECTION_INFO
111 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
113 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
114 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
116 #undef TARGET_RTX_COSTS
117 #define TARGET_RTX_COSTS v850_rtx_costs
119 #undef TARGET_ADDRESS_COST
120 #define TARGET_ADDRESS_COST hook_int_rtx_0
122 #undef TARGET_MACHINE_DEPENDENT_REORG
123 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
125 #undef TARGET_PROMOTE_PROTOTYPES
126 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
128 #undef TARGET_RETURN_IN_MEMORY
129 #define TARGET_RETURN_IN_MEMORY v850_return_in_memory
131 #undef TARGET_PASS_BY_REFERENCE
132 #define TARGET_PASS_BY_REFERENCE v850_pass_by_reference
134 #undef TARGET_SETUP_INCOMING_VARARGS
135 #define TARGET_SETUP_INCOMING_VARARGS v850_setup_incoming_varargs
137 struct gcc_target targetm = TARGET_INITIALIZER;
139 /* Sometimes certain combinations of command options do not make
140 sense on a particular target machine. You can define a macro
141 `OVERRIDE_OPTIONS' to take account of this. This macro, if
142 defined, is executed once just after all the command options have
145 Don't use this macro to turn on various extra optimizations for
146 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
149 override_options (void)
152 extern int atoi (const char *);
154 /* Parse -m{s,t,z}da=nnn switches */
155 for (i = 0; i < (int)SMALL_MEMORY_max; i++)
157 if (small_memory[i].value)
159 if (!ISDIGIT (*small_memory[i].value))
160 error ("%s=%s is not numeric",
161 small_memory[i].name,
162 small_memory[i].value);
165 small_memory[i].max = atoi (small_memory[i].value);
166 if (small_memory[i].max > small_memory[i].physical_max)
167 error ("%s=%s is too large",
168 small_memory[i].name,
169 small_memory[i].value);
174 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
175 if ((target_flags & MASK_US_MASK_SET) == 0)
177 target_flags |= MASK_US_MASK_SET;
178 target_flags &= ~MASK_US_BIT_SET;
184 v850_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
185 enum machine_mode mode, tree type,
186 bool named ATTRIBUTE_UNUSED)
188 unsigned HOST_WIDE_INT size;
191 size = int_size_in_bytes (type);
193 size = GET_MODE_SIZE (mode);
198 /* Return an RTX to represent where a value with mode MODE will be returned
199 from a function. If the result is 0, the argument is pushed. */
202 function_arg (CUMULATIVE_ARGS * cum,
203 enum machine_mode mode,
210 if (TARGET_GHS && !named)
214 size = int_size_in_bytes (type);
216 size = GET_MODE_SIZE (mode);
222 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
226 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
228 if (cum->nbytes > 4 * UNITS_PER_WORD)
231 if (type == NULL_TREE
232 && cum->nbytes + size > 4 * UNITS_PER_WORD)
235 switch (cum->nbytes / UNITS_PER_WORD)
238 result = gen_rtx_REG (mode, 6);
241 result = gen_rtx_REG (mode, 7);
244 result = gen_rtx_REG (mode, 8);
247 result = gen_rtx_REG (mode, 9);
257 /* Return the number of words which must be put into registers
258 for values which are part in registers and part in memory. */
261 function_arg_partial_nregs (CUMULATIVE_ARGS * cum,
262 enum machine_mode mode,
268 if (TARGET_GHS && !named)
272 size = int_size_in_bytes (type);
274 size = GET_MODE_SIZE (mode);
277 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
281 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
283 if (cum->nbytes > 4 * UNITS_PER_WORD)
286 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
289 if (type == NULL_TREE
290 && cum->nbytes + size > 4 * UNITS_PER_WORD)
293 return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
297 /* Return the high and low words of a CONST_DOUBLE */
300 const_double_split (rtx x, HOST_WIDE_INT * p_high, HOST_WIDE_INT * p_low)
302 if (GET_CODE (x) == CONST_DOUBLE)
307 switch (GET_MODE (x))
310 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
311 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
312 *p_high = t[1]; /* since v850 is little endian */
313 *p_low = t[0]; /* high is second word */
317 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
318 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
324 *p_high = CONST_DOUBLE_HIGH (x);
325 *p_low = CONST_DOUBLE_LOW (x);
333 fatal_insn ("const_double_split got a bad insn:", x);
337 /* Return the cost of the rtx R with code CODE. */
340 const_costs_int (HOST_WIDE_INT value, int zero_cost)
342 if (CONST_OK_FOR_I (value))
344 else if (CONST_OK_FOR_J (value))
346 else if (CONST_OK_FOR_K (value))
353 const_costs (rtx r, enum rtx_code c)
355 HOST_WIDE_INT high, low;
360 return const_costs_int (INTVAL (r), 0);
363 const_double_split (r, &high, &low);
364 if (GET_MODE (r) == SFmode)
365 return const_costs_int (high, 1);
367 return const_costs_int (high, 1) + const_costs_int (low, 1);
383 v850_rtx_costs (rtx x,
385 int outer_code ATTRIBUTE_UNUSED,
395 *total = COSTS_N_INSNS (const_costs (x, code));
402 if (TARGET_V850E && optimize_size)
410 && ( GET_MODE (x) == SImode
411 || GET_MODE (x) == HImode
412 || GET_MODE (x) == QImode))
414 if (GET_CODE (XEXP (x, 1)) == REG)
416 else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
418 if (CONST_OK_FOR_O (INTVAL (XEXP (x, 1))))
420 else if (CONST_OK_FOR_K (INTVAL (XEXP (x, 1))))
433 /* Print operand X using operand code CODE to assembly language output file
437 print_operand (FILE * file, rtx x, int code)
439 HOST_WIDE_INT high, low;
444 /* We use 'c' operands with symbols for .vtinherit */
445 if (GET_CODE (x) == SYMBOL_REF)
447 output_addr_const(file, x);
454 switch ((code == 'B' || code == 'C')
455 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
458 if (code == 'c' || code == 'C')
459 fprintf (file, "nz");
461 fprintf (file, "ne");
464 if (code == 'c' || code == 'C')
470 fprintf (file, "ge");
473 fprintf (file, "gt");
476 fprintf (file, "le");
479 fprintf (file, "lt");
482 fprintf (file, "nl");
488 fprintf (file, "nh");
497 case 'F': /* high word of CONST_DOUBLE */
498 if (GET_CODE (x) == CONST_INT)
499 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
500 else if (GET_CODE (x) == CONST_DOUBLE)
502 const_double_split (x, &high, &low);
503 fprintf (file, "%ld", (long) high);
508 case 'G': /* low word of CONST_DOUBLE */
509 if (GET_CODE (x) == CONST_INT)
510 fprintf (file, "%ld", (long) INTVAL (x));
511 else if (GET_CODE (x) == CONST_DOUBLE)
513 const_double_split (x, &high, &low);
514 fprintf (file, "%ld", (long) low);
520 fprintf (file, "%d\n", (int)(INTVAL (x) & 0xffff));
523 fprintf (file, "%d", exact_log2 (INTVAL (x)));
526 if (special_symbolref_operand (x, VOIDmode))
528 if (GET_CODE (x) == SYMBOL_REF)
530 else if (GET_CODE (x) == CONST)
531 x = XEXP (XEXP (x, 0), 0);
535 if (SYMBOL_REF_ZDA_P (x))
536 fprintf (file, "zdaoff");
537 else if (SYMBOL_REF_SDA_P (x))
538 fprintf (file, "sdaoff");
539 else if (SYMBOL_REF_TDA_P (x))
540 fprintf (file, "tdaoff");
548 if (special_symbolref_operand (x, VOIDmode))
549 output_addr_const (file, x);
554 if (special_symbolref_operand (x, VOIDmode))
556 if (GET_CODE (x) == SYMBOL_REF)
558 else if (GET_CODE (x) == CONST)
559 x = XEXP (XEXP (x, 0), 0);
563 if (SYMBOL_REF_ZDA_P (x))
564 fprintf (file, "r0");
565 else if (SYMBOL_REF_SDA_P (x))
566 fprintf (file, "gp");
567 else if (SYMBOL_REF_TDA_P (x))
568 fprintf (file, "ep");
575 case 'R': /* 2nd word of a double. */
576 switch (GET_CODE (x))
579 fprintf (file, reg_names[REGNO (x) + 1]);
582 x = XEXP (adjust_address (x, SImode, 4), 0);
583 print_operand_address (file, x);
584 if (GET_CODE (x) == CONST_INT)
585 fprintf (file, "[r0]");
594 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
595 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
602 /* Like an 'S' operand above, but for unsigned loads only. */
603 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
608 case 'W': /* print the instruction suffix */
609 switch (GET_MODE (x))
614 case QImode: fputs (".b", file); break;
615 case HImode: fputs (".h", file); break;
616 case SImode: fputs (".w", file); break;
617 case SFmode: fputs (".w", file); break;
620 case '.': /* register r0 */
621 fputs (reg_names[0], file);
623 case 'z': /* reg or zero */
625 fputs (reg_names[0], file);
626 else if (GET_CODE (x) == REG)
627 fputs (reg_names[REGNO (x)], file);
632 switch (GET_CODE (x))
635 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
636 output_address (gen_rtx_PLUS (SImode, gen_rtx_REG (SImode, 0),
639 output_address (XEXP (x, 0));
643 fputs (reg_names[REGNO (x)], file);
646 fputs (reg_names[subreg_regno (x)], file);
653 print_operand_address (file, x);
664 /* Output assembly language output for the address ADDR to FILE. */
667 print_operand_address (FILE * file, rtx addr)
669 switch (GET_CODE (addr))
672 fprintf (file, "0[");
673 print_operand (file, addr, 0);
677 if (GET_CODE (XEXP (addr, 0)) == REG)
680 fprintf (file, "lo(");
681 print_operand (file, XEXP (addr, 1), 0);
682 fprintf (file, ")[");
683 print_operand (file, XEXP (addr, 0), 0);
688 if (GET_CODE (XEXP (addr, 0)) == REG
689 || GET_CODE (XEXP (addr, 0)) == SUBREG)
692 print_operand (file, XEXP (addr, 1), 0);
694 print_operand (file, XEXP (addr, 0), 0);
699 print_operand (file, XEXP (addr, 0), 0);
701 print_operand (file, XEXP (addr, 1), 0);
706 const char *off_name = NULL;
707 const char *reg_name = NULL;
709 if (SYMBOL_REF_ZDA_P (addr))
714 else if (SYMBOL_REF_SDA_P (addr))
719 else if (SYMBOL_REF_TDA_P (addr))
726 fprintf (file, "%s(", off_name);
727 output_addr_const (file, addr);
729 fprintf (file, ")[%s]", reg_name);
733 if (special_symbolref_operand (addr, VOIDmode))
735 rtx x = XEXP (XEXP (addr, 0), 0);
736 const char *off_name;
737 const char *reg_name;
739 if (SYMBOL_REF_ZDA_P (x))
744 else if (SYMBOL_REF_SDA_P (x))
749 else if (SYMBOL_REF_TDA_P (x))
757 fprintf (file, "%s(", off_name);
758 output_addr_const (file, addr);
759 fprintf (file, ")[%s]", reg_name);
762 output_addr_const (file, addr);
765 output_addr_const (file, addr);
770 /* When assemble_integer is used to emit the offsets for a switch
771 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
772 output_addr_const will normally barf at this, but it is OK to omit
773 the truncate and just emit the difference of the two labels. The
774 .hword directive will automatically handle the truncation for us.
776 Returns 1 if rtx was handled, 0 otherwise. */
779 v850_output_addr_const_extra (FILE * file, rtx x)
781 if (GET_CODE (x) != TRUNCATE)
786 /* We must also handle the case where the switch table was passed a
787 constant value and so has been collapsed. In this case the first
788 label will have been deleted. In such a case it is OK to emit
789 nothing, since the table will not be used.
790 (cf gcc.c-torture/compile/990801-1.c). */
791 if (GET_CODE (x) == MINUS
792 && GET_CODE (XEXP (x, 0)) == LABEL_REF
793 && GET_CODE (XEXP (XEXP (x, 0), 0)) == CODE_LABEL
794 && INSN_DELETED_P (XEXP (XEXP (x, 0), 0)))
797 output_addr_const (file, x);
801 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
805 output_move_single (rtx * operands)
807 rtx dst = operands[0];
808 rtx src = operands[1];
815 else if (GET_CODE (src) == CONST_INT)
817 HOST_WIDE_INT value = INTVAL (src);
819 if (CONST_OK_FOR_J (value)) /* Signed 5 bit immediate. */
822 else if (CONST_OK_FOR_K (value)) /* Signed 16 bit immediate. */
823 return "movea lo(%1),%.,%0";
825 else if (CONST_OK_FOR_L (value)) /* Upper 16 bits were set. */
826 return "movhi hi(%1),%.,%0";
828 /* A random constant. */
829 else if (TARGET_V850E)
832 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
835 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
837 HOST_WIDE_INT high, low;
839 const_double_split (src, &high, &low);
841 if (CONST_OK_FOR_J (high)) /* Signed 5 bit immediate. */
844 else if (CONST_OK_FOR_K (high)) /* Signed 16 bit immediate. */
845 return "movea lo(%F1),%.,%0";
847 else if (CONST_OK_FOR_L (high)) /* Upper 16 bits were set. */
848 return "movhi hi(%F1),%.,%0";
850 /* A random constant. */
851 else if (TARGET_V850E)
855 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
858 else if (GET_CODE (src) == MEM)
859 return "%S1ld%W1 %1,%0";
861 else if (special_symbolref_operand (src, VOIDmode))
862 return "movea %O1(%P1),%Q1,%0";
864 else if (GET_CODE (src) == LABEL_REF
865 || GET_CODE (src) == SYMBOL_REF
866 || GET_CODE (src) == CONST)
869 return "mov hilo(%1),%0";
871 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
874 else if (GET_CODE (src) == HIGH)
875 return "movhi hi(%1),%.,%0";
877 else if (GET_CODE (src) == LO_SUM)
879 operands[2] = XEXP (src, 0);
880 operands[3] = XEXP (src, 1);
881 return "movea lo(%3),%2,%0";
885 else if (GET_CODE (dst) == MEM)
888 return "%S0st%W0 %1,%0";
890 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
891 return "%S0st%W0 %.,%0";
893 else if (GET_CODE (src) == CONST_DOUBLE
894 && CONST0_RTX (GET_MODE (dst)) == src)
895 return "%S0st%W0 %.,%0";
898 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
903 /* Return appropriate code to load up an 8 byte integer or
904 floating point value */
907 output_move_double (rtx * operands)
909 enum machine_mode mode = GET_MODE (operands[0]);
910 rtx dst = operands[0];
911 rtx src = operands[1];
913 if (register_operand (dst, mode)
914 && register_operand (src, mode))
916 if (REGNO (src) + 1 == REGNO (dst))
917 return "mov %R1,%R0\n\tmov %1,%0";
919 return "mov %1,%0\n\tmov %R1,%R0";
923 if (GET_CODE (dst) == MEM
924 && ((GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
925 || (GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src))))
926 return "st.w %.,%0\n\tst.w %.,%R0";
928 if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
930 HOST_WIDE_INT high_low[2];
934 if (GET_CODE (src) == CONST_DOUBLE)
935 const_double_split (src, &high_low[1], &high_low[0]);
938 high_low[0] = INTVAL (src);
939 high_low[1] = (INTVAL (src) >= 0) ? 0 : -1;
942 for (i = 0; i < 2; i++)
944 xop[0] = gen_rtx_REG (SImode, REGNO (dst)+i);
945 xop[1] = GEN_INT (high_low[i]);
946 output_asm_insn (output_move_single (xop), xop);
952 if (GET_CODE (src) == MEM)
955 int dreg = REGNO (dst);
956 rtx inside = XEXP (src, 0);
958 if (GET_CODE (inside) == REG)
959 ptrreg = REGNO (inside);
960 else if (GET_CODE (inside) == SUBREG)
961 ptrreg = subreg_regno (inside);
962 else if (GET_CODE (inside) == PLUS)
963 ptrreg = REGNO (XEXP (inside, 0));
964 else if (GET_CODE (inside) == LO_SUM)
965 ptrreg = REGNO (XEXP (inside, 0));
968 return "ld.w %R1,%R0\n\tld.w %1,%0";
971 if (GET_CODE (src) == MEM)
972 return "ld.w %1,%0\n\tld.w %R1,%R0";
974 if (GET_CODE (dst) == MEM)
975 return "st.w %1,%0\n\tst.w %R1,%R0";
977 return "mov %1,%0\n\tmov %R1,%R0";
981 /* Return maximum offset supported for a short EP memory reference of mode
982 MODE and signedness UNSIGNEDP. */
985 ep_memory_offset (enum machine_mode mode, int unsignedp ATTRIBUTE_UNUSED)
992 if (TARGET_SMALL_SLD)
993 max_offset = (1 << 4);
994 else if (TARGET_V850E
995 && ( ( unsignedp && ! TARGET_US_BIT_SET)
996 || (! unsignedp && TARGET_US_BIT_SET)))
997 max_offset = (1 << 4);
999 max_offset = (1 << 7);
1003 if (TARGET_SMALL_SLD)
1004 max_offset = (1 << 5);
1005 else if (TARGET_V850E
1006 && ( ( unsignedp && ! TARGET_US_BIT_SET)
1007 || (! unsignedp && TARGET_US_BIT_SET)))
1008 max_offset = (1 << 5);
1010 max_offset = (1 << 8);
1015 max_offset = (1 << 8);
1025 /* Return true if OP is a valid short EP memory reference */
1028 ep_memory_operand (rtx op, enum machine_mode mode, int unsigned_load)
1034 if (GET_CODE (op) != MEM)
1037 max_offset = ep_memory_offset (mode, unsigned_load);
1039 mask = GET_MODE_SIZE (mode) - 1;
1041 addr = XEXP (op, 0);
1042 if (GET_CODE (addr) == CONST)
1043 addr = XEXP (addr, 0);
1045 switch (GET_CODE (addr))
1051 return SYMBOL_REF_TDA_P (addr);
1054 return REGNO (addr) == EP_REGNUM;
1057 op0 = XEXP (addr, 0);
1058 op1 = XEXP (addr, 1);
1059 if (GET_CODE (op1) == CONST_INT
1060 && INTVAL (op1) < max_offset
1061 && INTVAL (op1) >= 0
1062 && (INTVAL (op1) & mask) == 0)
1064 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
1067 if (GET_CODE (op0) == SYMBOL_REF && SYMBOL_REF_TDA_P (op0))
1076 /* Return true if OP is either a register or 0 */
1079 reg_or_0_operand (rtx op, enum machine_mode mode)
1081 if (GET_CODE (op) == CONST_INT)
1082 return INTVAL (op) == 0;
1084 else if (GET_CODE (op) == CONST_DOUBLE)
1085 return CONST_DOUBLE_OK_FOR_G (op);
1088 return register_operand (op, mode);
1091 /* Return true if OP is either a register or a signed five bit integer */
1094 reg_or_int5_operand (rtx op, 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 (rtx op, enum machine_mode mode)
1108 if (GET_CODE (op) == CONST_INT)
1109 return CONST_OK_FOR_O (INTVAL (op));
1111 return register_operand (op, mode);
1114 /* Return true if OP is either a register or a const integer. */
1117 reg_or_const_operand (rtx op, enum machine_mode mode)
1119 if (GET_CODE (op) == CONST_INT)
1122 return register_operand (op, mode);
1125 /* Return true if OP is a valid call operand. */
1128 call_address_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1130 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1131 if (TARGET_LONG_CALLS)
1132 return GET_CODE (op) == REG;
1133 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
1137 special_symbolref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1139 if (GET_CODE (op) == CONST
1140 && GET_CODE (XEXP (op, 0)) == PLUS
1141 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
1142 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))))
1143 op = XEXP (XEXP (op, 0), 0);
1145 if (GET_CODE (op) == SYMBOL_REF)
1146 return (SYMBOL_REF_FLAGS (op)
1147 & (SYMBOL_FLAG_ZDA | SYMBOL_FLAG_TDA | SYMBOL_FLAG_SDA)) != 0;
1153 movsi_source_operand (rtx op, enum machine_mode mode)
1155 /* Some constants, as well as symbolic operands
1156 must be done with HIGH & LO_SUM patterns. */
1158 && GET_CODE (op) != HIGH
1159 && !(GET_CODE (op) == CONST_INT
1160 && (CONST_OK_FOR_J (INTVAL (op))
1161 || CONST_OK_FOR_K (INTVAL (op))
1162 || CONST_OK_FOR_L (INTVAL (op)))))
1163 return special_symbolref_operand (op, mode);
1165 return general_operand (op, mode);
1169 power_of_two_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1171 if (GET_CODE (op) != CONST_INT)
1174 if (exact_log2 (INTVAL (op)) == -1)
1180 not_power_of_two_operand (rtx op, enum machine_mode mode)
1186 else if (mode == HImode)
1188 else if (mode == SImode)
1193 if (GET_CODE (op) != CONST_INT)
1196 if (exact_log2 (~INTVAL (op) & mask) == -1)
1202 /* Substitute memory references involving a pointer, to use the ep pointer,
1203 taking care to save and preserve the ep. */
1206 substitute_ep_register (rtx first_insn,
1213 rtx reg = gen_rtx_REG (Pmode, regno);
1218 regs_ever_live[1] = 1;
1219 *p_r1 = gen_rtx_REG (Pmode, 1);
1220 *p_ep = gen_rtx_REG (Pmode, 30);
1225 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1226 2 * (uses - 3), uses, reg_names[regno],
1227 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1228 INSN_UID (first_insn), INSN_UID (last_insn));
1230 if (GET_CODE (first_insn) == NOTE)
1231 first_insn = next_nonnote_insn (first_insn);
1233 last_insn = next_nonnote_insn (last_insn);
1234 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1236 if (GET_CODE (insn) == INSN)
1238 rtx pattern = single_set (insn);
1240 /* Replace the memory references. */
1244 /* Memory operands are signed by default. */
1245 int unsignedp = FALSE;
1247 if (GET_CODE (SET_DEST (pattern)) == MEM
1248 && GET_CODE (SET_SRC (pattern)) == MEM)
1251 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1252 p_mem = &SET_DEST (pattern);
1254 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1255 p_mem = &SET_SRC (pattern);
1257 else if (GET_CODE (SET_SRC (pattern)) == SIGN_EXTEND
1258 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1259 p_mem = &XEXP (SET_SRC (pattern), 0);
1261 else if (GET_CODE (SET_SRC (pattern)) == ZERO_EXTEND
1262 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1264 p_mem = &XEXP (SET_SRC (pattern), 0);
1272 rtx addr = XEXP (*p_mem, 0);
1274 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1275 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1277 else if (GET_CODE (addr) == PLUS
1278 && GET_CODE (XEXP (addr, 0)) == REG
1279 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1280 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1281 && ((INTVAL (XEXP (addr, 1)))
1282 < ep_memory_offset (GET_MODE (*p_mem),
1284 && ((INTVAL (XEXP (addr, 1))) >= 0))
1285 *p_mem = change_address (*p_mem, VOIDmode,
1286 gen_rtx_PLUS (Pmode,
1294 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1295 insn = prev_nonnote_insn (first_insn);
1296 if (insn && GET_CODE (insn) == INSN
1297 && GET_CODE (PATTERN (insn)) == SET
1298 && SET_DEST (PATTERN (insn)) == *p_ep
1299 && SET_SRC (PATTERN (insn)) == *p_r1)
1302 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1304 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1305 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1309 /* TARGET_MACHINE_DEPENDENT_REORG. On the 850, we use it to implement
1310 the -mep mode to copy heavily used pointers to ep to use the implicit
1322 regs[FIRST_PSEUDO_REGISTER];
1331 /* If not ep mode, just return now. */
1335 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1338 regs[i].first_insn = NULL_RTX;
1339 regs[i].last_insn = NULL_RTX;
1342 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
1344 switch (GET_CODE (insn))
1346 /* End of basic block */
1353 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1355 if (max_uses < regs[i].uses)
1357 max_uses = regs[i].uses;
1363 substitute_ep_register (regs[max_regno].first_insn,
1364 regs[max_regno].last_insn,
1365 max_uses, max_regno, &r1, &ep);
1369 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1372 regs[i].first_insn = NULL_RTX;
1373 regs[i].last_insn = NULL_RTX;
1381 pattern = single_set (insn);
1383 /* See if there are any memory references we can shorten */
1386 rtx src = SET_SRC (pattern);
1387 rtx dest = SET_DEST (pattern);
1389 /* Memory operands are signed by default. */
1390 int unsignedp = FALSE;
1392 /* We might have (SUBREG (MEM)) here, so just get rid of the
1393 subregs to make this code simpler. */
1394 if (GET_CODE (dest) == SUBREG
1395 && (GET_CODE (SUBREG_REG (dest)) == MEM
1396 || GET_CODE (SUBREG_REG (dest)) == REG))
1397 alter_subreg (&dest);
1398 if (GET_CODE (src) == SUBREG
1399 && (GET_CODE (SUBREG_REG (src)) == MEM
1400 || GET_CODE (SUBREG_REG (src)) == REG))
1401 alter_subreg (&src);
1403 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1406 else if (GET_CODE (dest) == MEM)
1409 else if (GET_CODE (src) == MEM)
1412 else if (GET_CODE (src) == SIGN_EXTEND
1413 && GET_CODE (XEXP (src, 0)) == MEM)
1414 mem = XEXP (src, 0);
1416 else if (GET_CODE (src) == ZERO_EXTEND
1417 && GET_CODE (XEXP (src, 0)) == MEM)
1419 mem = XEXP (src, 0);
1425 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1428 else if (!use_ep && mem
1429 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1431 rtx addr = XEXP (mem, 0);
1435 if (GET_CODE (addr) == REG)
1438 regno = REGNO (addr);
1441 else if (GET_CODE (addr) == PLUS
1442 && GET_CODE (XEXP (addr, 0)) == REG
1443 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1444 && ((INTVAL (XEXP (addr, 1)))
1445 < ep_memory_offset (GET_MODE (mem), unsignedp))
1446 && ((INTVAL (XEXP (addr, 1))) >= 0))
1449 regno = REGNO (XEXP (addr, 0));
1458 regs[regno].last_insn = insn;
1459 if (!regs[regno].first_insn)
1460 regs[regno].first_insn = insn;
1464 /* Loading up a register in the basic block zaps any savings
1466 if (GET_CODE (dest) == REG)
1468 enum machine_mode mode = GET_MODE (dest);
1472 regno = REGNO (dest);
1473 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1477 /* See if we can use the pointer before this
1482 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1484 if (max_uses < regs[i].uses)
1486 max_uses = regs[i].uses;
1492 && max_regno >= regno
1493 && max_regno < endregno)
1495 substitute_ep_register (regs[max_regno].first_insn,
1496 regs[max_regno].last_insn,
1497 max_uses, max_regno, &r1,
1500 /* Since we made a substitution, zap all remembered
1502 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1505 regs[i].first_insn = NULL_RTX;
1506 regs[i].last_insn = NULL_RTX;
1511 for (i = regno; i < endregno; i++)
1514 regs[i].first_insn = NULL_RTX;
1515 regs[i].last_insn = NULL_RTX;
1524 /* # of registers saved by the interrupt handler. */
1525 #define INTERRUPT_FIXED_NUM 4
1527 /* # of bytes for registers saved by the interrupt handler. */
1528 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1530 /* # of registers saved in register parameter area. */
1531 #define INTERRUPT_REGPARM_NUM 4
1532 /* # of words saved for other registers. */
1533 #define INTERRUPT_ALL_SAVE_NUM \
1534 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1536 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1539 compute_register_save_size (long * p_reg_saved)
1543 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1544 int call_p = regs_ever_live [LINK_POINTER_REGNUM];
1547 /* Count the return pointer if we need to save it. */
1548 if (current_function_profile && !call_p)
1549 regs_ever_live [LINK_POINTER_REGNUM] = call_p = 1;
1551 /* Count space for the register saves. */
1552 if (interrupt_handler)
1554 for (i = 0; i <= 31; i++)
1558 if (regs_ever_live[i] || call_p)
1561 reg_saved |= 1L << i;
1565 /* We don't save/restore r0 or the stack pointer */
1567 case STACK_POINTER_REGNUM:
1570 /* For registers with fixed use, we save them, set them to the
1571 appropriate value, and then restore them.
1572 These registers are handled specially, so don't list them
1573 on the list of registers to save in the prologue. */
1574 case 1: /* temp used to hold ep */
1576 case 10: /* temp used to call interrupt save/restore */
1577 case EP_REGNUM: /* ep */
1584 /* Find the first register that needs to be saved. */
1585 for (i = 0; i <= 31; i++)
1586 if (regs_ever_live[i] && ((! call_used_regs[i])
1587 || i == LINK_POINTER_REGNUM))
1590 /* If it is possible that an out-of-line helper function might be
1591 used to generate the prologue for the current function, then we
1592 need to cover the possibility that such a helper function will
1593 be used, despite the fact that there might be gaps in the list of
1594 registers that need to be saved. To detect this we note that the
1595 helper functions always push at least register r29 (provided
1596 that the function is not an interrupt handler). */
1598 if (TARGET_PROLOG_FUNCTION
1599 && (i == 2 || ((i >= 20) && (i < 30))))
1604 reg_saved |= 1L << i;
1609 /* Helper functions save all registers between the starting
1610 register and the last register, regardless of whether they
1611 are actually used by the function or not. */
1612 for (; i <= 29; i++)
1615 reg_saved |= 1L << i;
1618 if (regs_ever_live [LINK_POINTER_REGNUM])
1621 reg_saved |= 1L << LINK_POINTER_REGNUM;
1626 for (; i <= 31; i++)
1627 if (regs_ever_live[i] && ((! call_used_regs[i])
1628 || i == LINK_POINTER_REGNUM))
1631 reg_saved |= 1L << i;
1637 *p_reg_saved = reg_saved;
1643 compute_frame_size (int size, long * p_reg_saved)
1646 + compute_register_save_size (p_reg_saved)
1647 + current_function_outgoing_args_size);
1652 expand_prologue (void)
1656 unsigned int size = get_frame_size ();
1657 unsigned int actual_fsize;
1658 unsigned int init_stack_alloc = 0;
1661 unsigned int num_save;
1662 unsigned int default_stack;
1664 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1667 actual_fsize = compute_frame_size (size, ®_saved);
1669 /* Save/setup global registers for interrupt functions right now. */
1670 if (interrupt_handler)
1672 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1673 emit_insn (gen_callt_save_interrupt ());
1675 emit_insn (gen_save_interrupt ());
1677 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1679 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1680 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1683 /* Save arg registers to the stack if necessary. */
1684 else if (current_function_args_info.anonymous_args)
1686 if (TARGET_PROLOG_FUNCTION && TARGET_V850E && !TARGET_DISABLE_CALLT)
1687 emit_insn (gen_save_r6_r9_v850e ());
1688 else if (TARGET_PROLOG_FUNCTION && ! TARGET_LONG_CALLS)
1689 emit_insn (gen_save_r6_r9 ());
1693 for (i = 6; i < 10; i++)
1695 emit_move_insn (gen_rtx_MEM (SImode,
1696 plus_constant (stack_pointer_rtx,
1698 gen_rtx_REG (SImode, i));
1704 /* Identify all of the saved registers. */
1707 for (i = 1; i < 31; i++)
1709 if (((1L << i) & reg_saved) != 0)
1710 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1713 /* If the return pointer is saved, the helper functions also allocate
1714 16 bytes of stack for arguments to be saved in. */
1715 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1717 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1721 /* See if we have an insn that allocates stack space and saves the particular
1722 registers we want to. */
1723 save_all = NULL_RTX;
1724 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1726 int alloc_stack = (4 * num_save) + default_stack;
1727 int unalloc_stack = actual_fsize - alloc_stack;
1728 int save_func_len = 4;
1729 int save_normal_len;
1732 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1734 /* see if we would have used ep to save the stack */
1735 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1736 save_normal_len = (3 * 2) + (2 * num_save);
1738 save_normal_len = 4 * num_save;
1740 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1742 /* Don't bother checking if we don't actually save any space.
1743 This happens for instance if one register is saved and additional
1744 stack space is allocated. */
1745 if (save_func_len < save_normal_len)
1747 save_all = gen_rtx_PARALLEL
1749 rtvec_alloc (num_save + 1
1750 + (TARGET_V850 ? (TARGET_LONG_CALLS ? 2 : 1) : 0)));
1752 XVECEXP (save_all, 0, 0)
1753 = gen_rtx_SET (VOIDmode,
1755 plus_constant (stack_pointer_rtx, -alloc_stack));
1757 offset = - default_stack;
1758 for (i = 0; i < num_save; i++)
1760 XVECEXP (save_all, 0, i+1)
1761 = gen_rtx_SET (VOIDmode,
1763 plus_constant (stack_pointer_rtx,
1771 XVECEXP (save_all, 0, num_save + 1)
1772 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1774 if (TARGET_LONG_CALLS)
1775 XVECEXP (save_all, 0, num_save + 2)
1776 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
1779 code = recog (save_all, NULL_RTX, NULL);
1782 rtx insn = emit_insn (save_all);
1783 INSN_CODE (insn) = code;
1784 actual_fsize -= alloc_stack;
1788 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1789 save_normal_len - save_func_len,
1790 save_normal_len, save_func_len,
1791 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1794 save_all = NULL_RTX;
1798 /* If no prolog save function is available, store the registers the old
1799 fashioned way (one by one). */
1802 /* Special case interrupt functions that save all registers for a call. */
1803 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1805 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1806 emit_insn (gen_callt_save_all_interrupt ());
1808 emit_insn (gen_save_all_interrupt ());
1812 /* If the stack is too big, allocate it in chunks so we can do the
1813 register saves. We use the register save size so we use the ep
1815 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1816 init_stack_alloc = compute_register_save_size (NULL);
1818 init_stack_alloc = actual_fsize;
1820 /* Save registers at the beginning of the stack frame. */
1821 offset = init_stack_alloc - 4;
1823 if (init_stack_alloc)
1824 emit_insn (gen_addsi3 (stack_pointer_rtx,
1826 GEN_INT (-init_stack_alloc)));
1828 /* Save the return pointer first. */
1829 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1831 emit_move_insn (gen_rtx_MEM (SImode,
1832 plus_constant (stack_pointer_rtx,
1834 save_regs[--num_save]);
1838 for (i = 0; i < num_save; i++)
1840 emit_move_insn (gen_rtx_MEM (SImode,
1841 plus_constant (stack_pointer_rtx,
1849 /* Allocate the rest of the stack that was not allocated above (either it is
1850 > 32K or we just called a function to save the registers and needed more
1852 if (actual_fsize > init_stack_alloc)
1854 int diff = actual_fsize - init_stack_alloc;
1855 if (CONST_OK_FOR_K (diff))
1856 emit_insn (gen_addsi3 (stack_pointer_rtx,
1861 rtx reg = gen_rtx_REG (Pmode, 12);
1862 emit_move_insn (reg, GEN_INT (-diff));
1863 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1867 /* If we need a frame pointer, set it up now. */
1868 if (frame_pointer_needed)
1869 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1874 expand_epilogue (void)
1878 unsigned int size = get_frame_size ();
1880 unsigned int actual_fsize = compute_frame_size (size, ®_saved);
1881 unsigned int init_stack_free = 0;
1882 rtx restore_regs[32];
1884 unsigned int num_restore;
1885 unsigned int default_stack;
1887 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1889 /* Eliminate the initial stack stored by interrupt functions. */
1890 if (interrupt_handler)
1892 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1893 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1894 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1897 /* Cut off any dynamic stack created. */
1898 if (frame_pointer_needed)
1899 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1901 /* Identify all of the saved registers. */
1904 for (i = 1; i < 31; i++)
1906 if (((1L << i) & reg_saved) != 0)
1907 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1910 /* If the return pointer is saved, the helper functions also allocate
1911 16 bytes of stack for arguments to be saved in. */
1912 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1914 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1918 /* See if we have an insn that restores the particular registers we
1920 restore_all = NULL_RTX;
1922 if (TARGET_PROLOG_FUNCTION
1924 && actual_fsize >= default_stack
1925 && !interrupt_handler)
1927 int alloc_stack = (4 * num_restore) + default_stack;
1928 int unalloc_stack = actual_fsize - alloc_stack;
1929 int restore_func_len = 4;
1930 int restore_normal_len;
1933 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1935 /* See if we would have used ep to restore the registers. */
1936 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1937 restore_normal_len = (3 * 2) + (2 * num_restore);
1939 restore_normal_len = 4 * num_restore;
1941 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1943 /* Don't bother checking if we don't actually save any space. */
1944 if (restore_func_len < restore_normal_len)
1946 restore_all = gen_rtx_PARALLEL (VOIDmode,
1947 rtvec_alloc (num_restore + 2));
1948 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1949 XVECEXP (restore_all, 0, 1)
1950 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1951 gen_rtx_PLUS (Pmode,
1953 GEN_INT (alloc_stack)));
1955 offset = alloc_stack - 4;
1956 for (i = 0; i < num_restore; i++)
1958 XVECEXP (restore_all, 0, i+2)
1959 = gen_rtx_SET (VOIDmode,
1962 plus_constant (stack_pointer_rtx,
1967 code = recog (restore_all, NULL_RTX, NULL);
1973 actual_fsize -= alloc_stack;
1976 if (CONST_OK_FOR_K (actual_fsize))
1977 emit_insn (gen_addsi3 (stack_pointer_rtx,
1979 GEN_INT (actual_fsize)));
1982 rtx reg = gen_rtx_REG (Pmode, 12);
1983 emit_move_insn (reg, GEN_INT (actual_fsize));
1984 emit_insn (gen_addsi3 (stack_pointer_rtx,
1990 insn = emit_jump_insn (restore_all);
1991 INSN_CODE (insn) = code;
1995 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1996 restore_normal_len - restore_func_len,
1997 restore_normal_len, restore_func_len,
1998 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
2001 restore_all = NULL_RTX;
2005 /* If no epilog save function is available, restore the registers the
2006 old fashioned way (one by one). */
2009 /* If the stack is large, we need to cut it down in 2 pieces. */
2010 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
2011 init_stack_free = 4 * num_restore;
2013 init_stack_free = actual_fsize;
2015 /* Deallocate the rest of the stack if it is > 32K. */
2016 if (actual_fsize > init_stack_free)
2020 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
2022 if (CONST_OK_FOR_K (diff))
2023 emit_insn (gen_addsi3 (stack_pointer_rtx,
2028 rtx reg = gen_rtx_REG (Pmode, 12);
2029 emit_move_insn (reg, GEN_INT (diff));
2030 emit_insn (gen_addsi3 (stack_pointer_rtx,
2036 /* Special case interrupt functions that save all registers
2038 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
2040 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
2041 emit_insn (gen_callt_restore_all_interrupt ());
2043 emit_insn (gen_restore_all_interrupt ());
2047 /* Restore registers from the beginning of the stack frame. */
2048 offset = init_stack_free - 4;
2050 /* Restore the return pointer first. */
2052 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
2054 emit_move_insn (restore_regs[--num_restore],
2055 gen_rtx_MEM (SImode,
2056 plus_constant (stack_pointer_rtx,
2061 for (i = 0; i < num_restore; i++)
2063 emit_move_insn (restore_regs[i],
2064 gen_rtx_MEM (SImode,
2065 plus_constant (stack_pointer_rtx,
2068 emit_insn (gen_rtx_USE (VOIDmode, restore_regs[i]));
2072 /* Cut back the remainder of the stack. */
2073 if (init_stack_free)
2074 emit_insn (gen_addsi3 (stack_pointer_rtx,
2076 GEN_INT (init_stack_free)));
2079 /* And return or use reti for interrupt handlers. */
2080 if (interrupt_handler)
2082 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
2083 emit_insn (gen_callt_return_interrupt ());
2085 emit_jump_insn (gen_return_interrupt ());
2087 else if (actual_fsize)
2088 emit_jump_insn (gen_return_internal ());
2090 emit_jump_insn (gen_return ());
2093 v850_interrupt_cache_p = FALSE;
2094 v850_interrupt_p = FALSE;
2098 /* Update the condition code from the insn. */
2101 notice_update_cc (rtx body, rtx insn)
2103 switch (get_attr_cc (insn))
2106 /* Insn does not affect CC at all. */
2110 /* Insn does not change CC, but the 0'th operand has been changed. */
2111 if (cc_status.value1 != 0
2112 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
2113 cc_status.value1 = 0;
2117 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2118 V,C is in an unusable state. */
2120 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
2121 cc_status.value1 = recog_data.operand[0];
2125 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2126 C is in an unusable state. */
2128 cc_status.flags |= CC_NO_CARRY;
2129 cc_status.value1 = recog_data.operand[0];
2133 /* The insn is a compare instruction. */
2135 cc_status.value1 = SET_SRC (body);
2139 /* Insn doesn't leave CC in a usable state. */
2145 /* Retrieve the data area that has been chosen for the given decl. */
2148 v850_get_data_area (tree decl)
2150 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2151 return DATA_AREA_SDA;
2153 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2154 return DATA_AREA_TDA;
2156 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2157 return DATA_AREA_ZDA;
2159 return DATA_AREA_NORMAL;
2162 /* Store the indicated data area in the decl's attributes. */
2165 v850_set_data_area (tree decl, v850_data_area data_area)
2171 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2172 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2173 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2178 DECL_ATTRIBUTES (decl) = tree_cons
2179 (name, NULL, DECL_ATTRIBUTES (decl));
2182 const struct attribute_spec v850_attribute_table[] =
2184 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2185 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2186 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2187 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2188 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2189 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2190 { NULL, 0, 0, false, false, false, NULL }
2193 /* Handle an "interrupt" attribute; arguments as in
2194 struct attribute_spec.handler. */
2196 v850_handle_interrupt_attribute (tree * node,
2198 tree args ATTRIBUTE_UNUSED,
2199 int flags ATTRIBUTE_UNUSED,
2200 bool * no_add_attrs)
2202 if (TREE_CODE (*node) != FUNCTION_DECL)
2204 warning ("`%s' attribute only applies to functions",
2205 IDENTIFIER_POINTER (name));
2206 *no_add_attrs = true;
2212 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2213 struct attribute_spec.handler. */
2215 v850_handle_data_area_attribute (tree* node,
2217 tree args ATTRIBUTE_UNUSED,
2218 int flags ATTRIBUTE_UNUSED,
2219 bool * no_add_attrs)
2221 v850_data_area data_area;
2222 v850_data_area area;
2225 /* Implement data area attribute. */
2226 if (is_attribute_p ("sda", name))
2227 data_area = DATA_AREA_SDA;
2228 else if (is_attribute_p ("tda", name))
2229 data_area = DATA_AREA_TDA;
2230 else if (is_attribute_p ("zda", name))
2231 data_area = DATA_AREA_ZDA;
2235 switch (TREE_CODE (decl))
2238 if (current_function_decl != NULL_TREE)
2240 error ("%Jdata area attributes cannot be specified for "
2241 "local variables", decl, decl);
2242 *no_add_attrs = true;
2248 area = v850_get_data_area (decl);
2249 if (area != DATA_AREA_NORMAL && data_area != area)
2251 error ("%Jdata area of '%D' conflicts with previous declaration",
2253 *no_add_attrs = true;
2265 /* Return nonzero if FUNC is an interrupt function as specified
2266 by the "interrupt" attribute. */
2269 v850_interrupt_function_p (tree func)
2274 if (v850_interrupt_cache_p)
2275 return v850_interrupt_p;
2277 if (TREE_CODE (func) != FUNCTION_DECL)
2280 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2286 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2287 ret = a != NULL_TREE;
2290 /* Its not safe to trust global variables until after function inlining has
2292 if (reload_completed | reload_in_progress)
2293 v850_interrupt_p = ret;
2300 v850_encode_data_area (tree decl, rtx symbol)
2304 /* Map explicit sections into the appropriate attribute */
2305 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2307 if (DECL_SECTION_NAME (decl))
2309 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2311 if (streq (name, ".zdata") || streq (name, ".zbss"))
2312 v850_set_data_area (decl, DATA_AREA_ZDA);
2314 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2315 v850_set_data_area (decl, DATA_AREA_SDA);
2317 else if (streq (name, ".tdata"))
2318 v850_set_data_area (decl, DATA_AREA_TDA);
2321 /* If no attribute, support -m{zda,sda,tda}=n */
2324 int size = int_size_in_bytes (TREE_TYPE (decl));
2328 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2329 v850_set_data_area (decl, DATA_AREA_TDA);
2331 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2332 v850_set_data_area (decl, DATA_AREA_SDA);
2334 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2335 v850_set_data_area (decl, DATA_AREA_ZDA);
2338 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2342 flags = SYMBOL_REF_FLAGS (symbol);
2343 switch (v850_get_data_area (decl))
2345 case DATA_AREA_ZDA: flags |= SYMBOL_FLAG_ZDA; break;
2346 case DATA_AREA_TDA: flags |= SYMBOL_FLAG_TDA; break;
2347 case DATA_AREA_SDA: flags |= SYMBOL_FLAG_SDA; break;
2350 SYMBOL_REF_FLAGS (symbol) = flags;
2354 v850_encode_section_info (tree decl, rtx rtl, int first)
2356 default_encode_section_info (decl, rtl, first);
2358 if (TREE_CODE (decl) == VAR_DECL
2359 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2360 v850_encode_data_area (decl, XEXP (rtl, 0));
2363 /* Return true if the given RTX is a register which can be restored
2364 by a function epilogue. */
2366 register_is_ok_for_epilogue (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2368 /* The save/restore routines can only cope with registers 20 - 31. */
2369 return ((GET_CODE (op) == REG)
2370 && (((REGNO (op) >= 20) && REGNO (op) <= 31)));
2373 /* Return nonzero if the given RTX is suitable for collapsing into
2374 jump to a function epilogue. */
2376 pattern_is_ok_for_epilogue (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2378 int count = XVECLEN (op, 0);
2381 /* If there are no registers to restore then the function epilogue
2386 /* The pattern matching has already established that we are performing a
2387 function epilogue and that we are popping at least one register. We must
2388 now check the remaining entries in the vector to make sure that they are
2389 also register pops. There is no good reason why there should ever be
2390 anything else in this vector, but being paranoid always helps...
2392 The test below performs the C equivalent of this machine description
2395 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2396 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2399 for (i = 3; i < count; i++)
2401 rtx vector_element = XVECEXP (op, 0, i);
2406 if (GET_CODE (vector_element) != SET)
2409 dest = SET_DEST (vector_element);
2410 src = SET_SRC (vector_element);
2412 if (GET_CODE (dest) != REG
2413 || GET_MODE (dest) != SImode
2414 || ! register_is_ok_for_epilogue (dest, SImode)
2415 || GET_CODE (src) != MEM
2416 || GET_MODE (src) != SImode)
2419 plus = XEXP (src, 0);
2421 if (GET_CODE (plus) != PLUS
2422 || GET_CODE (XEXP (plus, 0)) != REG
2423 || GET_MODE (XEXP (plus, 0)) != SImode
2424 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2425 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2432 /* Construct a JR instruction to a routine that will perform the equivalent of
2433 the RTL passed in as an argument. This RTL is a function epilogue that
2434 pops registers off the stack and possibly releases some extra stack space
2435 as well. The code has already verified that the RTL matches these
2438 construct_restore_jr (rtx op)
2440 int count = XVECLEN (op, 0);
2442 unsigned long int mask;
2443 unsigned long int first;
2444 unsigned long int last;
2446 static char buff [100]; /* XXX */
2450 error ("bogus JR construction: %d\n", count);
2454 /* Work out how many bytes to pop off the stack before retrieving
2456 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2458 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2460 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2463 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2465 /* Each pop will remove 4 bytes from the stack.... */
2466 stack_bytes -= (count - 2) * 4;
2468 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2469 if (stack_bytes != 0 && stack_bytes != 16)
2471 error ("bad amount of stack space removal: %d", stack_bytes);
2475 /* Now compute the bit mask of registers to push. */
2477 for (i = 2; i < count; i++)
2479 rtx vector_element = XVECEXP (op, 0, i);
2481 if (GET_CODE (vector_element) != SET)
2483 if (GET_CODE (SET_DEST (vector_element)) != REG)
2485 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2488 mask |= 1 << REGNO (SET_DEST (vector_element));
2491 /* Scan for the first register to pop. */
2492 for (first = 0; first < 32; first++)
2494 if (mask & (1 << first))
2501 /* Discover the last register to pop. */
2502 if (mask & (1 << LINK_POINTER_REGNUM))
2504 if (stack_bytes != 16)
2507 last = LINK_POINTER_REGNUM;
2511 if (stack_bytes != 0)
2514 if ((mask & (1 << 29)) == 0)
2520 /* Note, it is possible to have gaps in the register mask.
2521 We ignore this here, and generate a JR anyway. We will
2522 be popping more registers than is strictly necessary, but
2523 it does save code space. */
2525 if (TARGET_LONG_CALLS)
2530 sprintf (name, "__return_%s", reg_names [first]);
2532 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2534 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2540 sprintf (buff, "jr __return_%s", reg_names [first]);
2542 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2549 /* Return nonzero if the given RTX is suitable for collapsing into
2550 a jump to a function prologue. */
2552 pattern_is_ok_for_prologue (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2554 int count = XVECLEN (op, 0);
2558 /* If there are no registers to save then the function prologue
2563 /* The pattern matching has already established that we are adjusting the
2564 stack and pushing at least one register. We must now check that the
2565 remaining entries in the vector to make sure that they are also register
2566 pushes, except for the last entry which should be a CLOBBER of r10.
2568 The test below performs the C equivalent of this machine description
2571 (set (mem:SI (plus:SI (reg:SI 3)
2572 (match_operand:SI 2 "immediate_operand" "i")))
2573 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2577 for (i = 2; i < count - (TARGET_LONG_CALLS ? 2: 1); i++)
2583 vector_element = XVECEXP (op, 0, i);
2585 if (GET_CODE (vector_element) != SET)
2588 dest = SET_DEST (vector_element);
2589 src = SET_SRC (vector_element);
2591 if (GET_CODE (dest) != MEM
2592 || GET_MODE (dest) != SImode
2593 || GET_CODE (src) != REG
2594 || GET_MODE (src) != SImode
2595 || ! register_is_ok_for_epilogue (src, SImode))
2598 plus = XEXP (dest, 0);
2600 if ( GET_CODE (plus) != PLUS
2601 || GET_CODE (XEXP (plus, 0)) != REG
2602 || GET_MODE (XEXP (plus, 0)) != SImode
2603 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2604 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2607 /* If the register is being pushed somewhere other than the stack
2608 space just acquired by the first operand then abandon this quest.
2609 Note: the test is <= because both values are negative. */
2610 if (INTVAL (XEXP (plus, 1))
2611 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2617 /* Make sure that the last entries in the vector are clobbers. */
2618 for (; i < count; i++)
2620 vector_element = XVECEXP (op, 0, i);
2622 if (GET_CODE (vector_element) != CLOBBER
2623 || GET_CODE (XEXP (vector_element, 0)) != REG
2624 || !(REGNO (XEXP (vector_element, 0)) == 10
2625 || (TARGET_LONG_CALLS ? (REGNO (XEXP (vector_element, 0)) == 11) : 0 )))
2632 /* Construct a JARL instruction to a routine that will perform the equivalent
2633 of the RTL passed as a parameter. This RTL is a function prologue that
2634 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2635 some stack space as well. The code has already verified that the RTL
2636 matches these requirements. */
2638 construct_save_jarl (rtx op)
2640 int count = XVECLEN (op, 0);
2642 unsigned long int mask;
2643 unsigned long int first;
2644 unsigned long int last;
2646 static char buff [100]; /* XXX */
2650 error ("bogus JARL construction: %d\n", count);
2655 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2657 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2659 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2661 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2664 /* Work out how many bytes to push onto the stack after storing the
2666 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2668 /* Each push will put 4 bytes from the stack.... */
2669 stack_bytes += (count - (TARGET_LONG_CALLS ? 3 : 2)) * 4;
2671 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2672 if (stack_bytes != 0 && stack_bytes != -16)
2674 error ("bad amount of stack space removal: %d", stack_bytes);
2678 /* Now compute the bit mask of registers to push. */
2680 for (i = 1; i < count - (TARGET_LONG_CALLS ? 2 : 1); i++)
2682 rtx vector_element = XVECEXP (op, 0, i);
2684 if (GET_CODE (vector_element) != SET)
2686 if (GET_CODE (SET_SRC (vector_element)) != REG)
2688 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2691 mask |= 1 << REGNO (SET_SRC (vector_element));
2694 /* Scan for the first register to push. */
2695 for (first = 0; first < 32; first++)
2697 if (mask & (1 << first))
2704 /* Discover the last register to push. */
2705 if (mask & (1 << LINK_POINTER_REGNUM))
2707 if (stack_bytes != -16)
2710 last = LINK_POINTER_REGNUM;
2714 if (stack_bytes != 0)
2716 if ((mask & (1 << 29)) == 0)
2722 /* Note, it is possible to have gaps in the register mask.
2723 We ignore this here, and generate a JARL anyway. We will
2724 be pushing more registers than is strictly necessary, but
2725 it does save code space. */
2727 if (TARGET_LONG_CALLS)
2732 sprintf (name, "__save_%s", reg_names [first]);
2734 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2736 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2742 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2744 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2751 extern tree last_assemble_variable_decl;
2752 extern int size_directive_output;
2754 /* A version of asm_output_aligned_bss() that copes with the special
2755 data areas of the v850. */
2757 v850_output_aligned_bss (FILE * file,
2763 switch (v850_get_data_area (decl))
2781 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2782 #ifdef ASM_DECLARE_OBJECT_NAME
2783 last_assemble_variable_decl = decl;
2784 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2786 /* Standard thing is just output label for the object. */
2787 ASM_OUTPUT_LABEL (file, name);
2788 #endif /* ASM_DECLARE_OBJECT_NAME */
2789 ASM_OUTPUT_SKIP (file, size ? size : 1);
2792 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2794 v850_output_common (FILE * file,
2800 if (decl == NULL_TREE)
2802 fprintf (file, "%s", COMMON_ASM_OP);
2806 switch (v850_get_data_area (decl))
2809 fprintf (file, "%s", ZCOMMON_ASM_OP);
2813 fprintf (file, "%s", SCOMMON_ASM_OP);
2817 fprintf (file, "%s", TCOMMON_ASM_OP);
2821 fprintf (file, "%s", COMMON_ASM_OP);
2826 assemble_name (file, name);
2827 fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2830 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2832 v850_output_local (FILE * file,
2838 fprintf (file, "%s", LOCAL_ASM_OP);
2839 assemble_name (file, name);
2840 fprintf (file, "\n");
2842 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2845 /* Add data area to the given declaration if a ghs data area pragma is
2846 currently in effect (#pragma ghs startXXX/endXXX). */
2848 v850_insert_attributes (tree decl, tree * attr_ptr ATTRIBUTE_UNUSED )
2851 && data_area_stack->data_area
2852 && current_function_decl == NULL_TREE
2853 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2854 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2855 v850_set_data_area (decl, data_area_stack->data_area);
2857 /* Initialize the default names of the v850 specific sections,
2858 if this has not been done before. */
2860 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2862 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2863 = build_string (sizeof (".sdata")-1, ".sdata");
2865 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2866 = build_string (sizeof (".rosdata")-1, ".rosdata");
2868 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2869 = build_string (sizeof (".tdata")-1, ".tdata");
2871 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2872 = build_string (sizeof (".zdata")-1, ".zdata");
2874 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2875 = build_string (sizeof (".rozdata")-1, ".rozdata");
2878 if (current_function_decl == NULL_TREE
2879 && (TREE_CODE (decl) == VAR_DECL
2880 || TREE_CODE (decl) == CONST_DECL
2881 || TREE_CODE (decl) == FUNCTION_DECL)
2882 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2883 && !DECL_SECTION_NAME (decl))
2885 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2886 tree chosen_section;
2888 if (TREE_CODE (decl) == FUNCTION_DECL)
2889 kind = GHS_SECTION_KIND_TEXT;
2892 /* First choose a section kind based on the data area of the decl. */
2893 switch (v850_get_data_area (decl))
2899 kind = ((TREE_READONLY (decl))
2900 ? GHS_SECTION_KIND_ROSDATA
2901 : GHS_SECTION_KIND_SDATA);
2905 kind = GHS_SECTION_KIND_TDATA;
2909 kind = ((TREE_READONLY (decl))
2910 ? GHS_SECTION_KIND_ROZDATA
2911 : GHS_SECTION_KIND_ZDATA);
2914 case DATA_AREA_NORMAL: /* default data area */
2915 if (TREE_READONLY (decl))
2916 kind = GHS_SECTION_KIND_RODATA;
2917 else if (DECL_INITIAL (decl))
2918 kind = GHS_SECTION_KIND_DATA;
2920 kind = GHS_SECTION_KIND_BSS;
2924 /* Now, if the section kind has been explicitly renamed,
2925 then attach a section attribute. */
2926 chosen_section = GHS_current_section_names [(int) kind];
2928 /* Otherwise, if this kind of section needs an explicit section
2929 attribute, then also attach one. */
2930 if (chosen_section == NULL)
2931 chosen_section = GHS_default_section_names [(int) kind];
2935 /* Only set the section name if specified by a pragma, because
2936 otherwise it will force those variables to get allocated storage
2937 in this module, rather than by the linker. */
2938 DECL_SECTION_NAME (decl) = chosen_section;
2943 /* Return nonzero if the given RTX is suitable
2944 for collapsing into a DISPOSE instruction. */
2947 pattern_is_ok_for_dispose (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2949 int count = XVECLEN (op, 0);
2952 /* If there are no registers to restore then
2953 the dispose instruction is not suitable. */
2957 /* The pattern matching has already established that we are performing a
2958 function epilogue and that we are popping at least one register. We must
2959 now check the remaining entries in the vector to make sure that they are
2960 also register pops. There is no good reason why there should ever be
2961 anything else in this vector, but being paranoid always helps...
2963 The test below performs the C equivalent of this machine description
2966 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2967 (mem:SI (plus:SI (reg:SI 3)
2968 (match_operand:SI n "immediate_operand" "i"))))
2971 for (i = 3; i < count; i++)
2973 rtx vector_element = XVECEXP (op, 0, i);
2978 if (GET_CODE (vector_element) != SET)
2981 dest = SET_DEST (vector_element);
2982 src = SET_SRC (vector_element);
2984 if ( GET_CODE (dest) != REG
2985 || GET_MODE (dest) != SImode
2986 || ! register_is_ok_for_epilogue (dest, SImode)
2987 || GET_CODE (src) != MEM
2988 || GET_MODE (src) != SImode)
2991 plus = XEXP (src, 0);
2993 if ( GET_CODE (plus) != PLUS
2994 || GET_CODE (XEXP (plus, 0)) != REG
2995 || GET_MODE (XEXP (plus, 0)) != SImode
2996 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2997 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
3004 /* Construct a DISPOSE instruction that is the equivalent of
3005 the given RTX. We have already verified that this should
3009 construct_dispose_instruction (rtx op)
3011 int count = XVECLEN (op, 0);
3013 unsigned long int mask;
3015 static char buff[ 100 ]; /* XXX */
3020 error ("Bogus DISPOSE construction: %d\n", count);
3024 /* Work out how many bytes to pop off the
3025 stack before retrieving registers. */
3026 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
3028 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
3030 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
3033 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
3035 /* Each pop will remove 4 bytes from the stack.... */
3036 stack_bytes -= (count - 2) * 4;
3038 /* Make sure that the amount we are popping
3039 will fit into the DISPOSE instruction. */
3040 if (stack_bytes > 128)
3042 error ("Too much stack space to dispose of: %d", stack_bytes);
3046 /* Now compute the bit mask of registers to push. */
3049 for (i = 2; i < count; i++)
3051 rtx vector_element = XVECEXP (op, 0, i);
3053 if (GET_CODE (vector_element) != SET)
3055 if (GET_CODE (SET_DEST (vector_element)) != REG)
3057 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
3060 if (REGNO (SET_DEST (vector_element)) == 2)
3063 mask |= 1 << REGNO (SET_DEST (vector_element));
3066 if (! TARGET_DISABLE_CALLT
3067 && (use_callt || stack_bytes == 0 || stack_bytes == 16))
3071 sprintf (buff, "callt ctoff(__callt_return_r2_r%d)", (mask & (1 << 31)) ? 31 : 29);
3076 for (i = 20; i < 32; i++)
3077 if (mask & (1 << i))
3081 sprintf (buff, "callt ctoff(__callt_return_r31c)");
3083 sprintf (buff, "callt ctoff(__callt_return_r%d_r%d%s)",
3084 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
3089 static char regs [100]; /* XXX */
3092 /* Generate the DISPOSE instruction. Note we could just issue the
3093 bit mask as a number as the assembler can cope with this, but for
3094 the sake of our readers we turn it into a textual description. */
3098 for (i = 20; i < 32; i++)
3100 if (mask & (1 << i))
3105 strcat (regs, ", ");
3110 strcat (regs, reg_names[ first ]);
3112 for (i++; i < 32; i++)
3113 if ((mask & (1 << i)) == 0)
3118 strcat (regs, " - ");
3119 strcat (regs, reg_names[ i - 1 ] );
3124 sprintf (buff, "dispose %d {%s}, r31", stack_bytes / 4, regs);
3130 /* Return nonzero if the given RTX is suitable
3131 for collapsing into a PREPARE instruction. */
3134 pattern_is_ok_for_prepare (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3136 int count = XVECLEN (op, 0);
3139 /* If there are no registers to restore then the prepare instruction
3144 /* The pattern matching has already established that we are adjusting the
3145 stack and pushing at least one register. We must now check that the
3146 remaining entries in the vector to make sure that they are also register
3149 The test below performs the C equivalent of this machine description
3152 (set (mem:SI (plus:SI (reg:SI 3)
3153 (match_operand:SI 2 "immediate_operand" "i")))
3154 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3158 for (i = 2; i < count; i++)
3160 rtx vector_element = XVECEXP (op, 0, i);
3165 if (GET_CODE (vector_element) != SET)
3168 dest = SET_DEST (vector_element);
3169 src = SET_SRC (vector_element);
3171 if ( GET_CODE (dest) != MEM
3172 || GET_MODE (dest) != SImode
3173 || GET_CODE (src) != REG
3174 || GET_MODE (src) != SImode
3175 || ! register_is_ok_for_epilogue (src, SImode)
3179 plus = XEXP (dest, 0);
3181 if ( GET_CODE (plus) != PLUS
3182 || GET_CODE (XEXP (plus, 0)) != REG
3183 || GET_MODE (XEXP (plus, 0)) != SImode
3184 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
3185 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
3188 /* If the register is being pushed somewhere other than the stack
3189 space just acquired by the first operand then abandon this quest.
3190 Note: the test is <= because both values are negative. */
3191 if (INTVAL (XEXP (plus, 1))
3192 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
3199 /* Construct a PREPARE instruction that is the equivalent of
3200 the given RTL. We have already verified that this should
3204 construct_prepare_instruction (rtx op)
3206 int count = XVECLEN (op, 0);
3208 unsigned long int mask;
3210 static char buff[ 100 ]; /* XXX */
3215 error ("Bogus PREPEARE construction: %d\n", count);
3219 /* Work out how many bytes to push onto
3220 the stack after storing the registers. */
3221 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
3223 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
3225 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
3228 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
3230 /* Each push will put 4 bytes from the stack. */
3231 stack_bytes += (count - 1) * 4;
3233 /* Make sure that the amount we are popping
3234 will fit into the DISPOSE instruction. */
3235 if (stack_bytes < -128)
3237 error ("Too much stack space to prepare: %d", stack_bytes);
3241 /* Now compute the bit mask of registers to push. */
3243 for (i = 1; i < count; i++)
3245 rtx vector_element = XVECEXP (op, 0, i);
3247 if (GET_CODE (vector_element) != SET)
3249 if (GET_CODE (SET_SRC (vector_element)) != REG)
3251 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
3254 if (REGNO (SET_SRC (vector_element)) == 2)
3257 mask |= 1 << REGNO (SET_SRC (vector_element));
3260 if ((! TARGET_DISABLE_CALLT)
3261 && (use_callt || stack_bytes == 0 || stack_bytes == -16))
3265 sprintf (buff, "callt ctoff(__callt_save_r2_r%d)", (mask & (1 << 31)) ? 31 : 29 );
3269 for (i = 20; i < 32; i++)
3270 if (mask & (1 << i))
3274 sprintf (buff, "callt ctoff(__callt_save_r31c)");
3276 sprintf (buff, "callt ctoff(__callt_save_r%d_r%d%s)",
3277 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
3281 static char regs [100]; /* XXX */
3285 /* Generate the PREPARE instruction. Note we could just issue the
3286 bit mask as a number as the assembler can cope with this, but for
3287 the sake of our readers we turn it into a textual description. */
3291 for (i = 20; i < 32; i++)
3293 if (mask & (1 << i))
3298 strcat (regs, ", ");
3303 strcat (regs, reg_names[ first ]);
3305 for (i++; i < 32; i++)
3306 if ((mask & (1 << i)) == 0)
3311 strcat (regs, " - ");
3312 strcat (regs, reg_names[ i - 1 ] );
3317 sprintf (buff, "prepare {%s}, %d", regs, (- stack_bytes) / 4);
3323 /* Return an RTX indicating where the return address to the
3324 calling function can be found. */
3327 v850_return_addr (int count)
3332 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
3336 v850_select_section (tree exp,
3337 int reloc ATTRIBUTE_UNUSED,
3338 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
3340 if (TREE_CODE (exp) == VAR_DECL)
3343 if (!TREE_READONLY (exp)
3344 || TREE_SIDE_EFFECTS (exp)
3345 || !DECL_INITIAL (exp)
3346 || (DECL_INITIAL (exp) != error_mark_node
3347 && !TREE_CONSTANT (DECL_INITIAL (exp))))
3352 switch (v850_get_data_area (exp))
3374 readonly_data_section ();
3381 readonly_data_section ();
3384 /* Worker function for TARGET_RETURN_IN_MEMORY. */
3387 v850_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
3389 /* Return values > 8 bytes in length in memory. */
3390 return int_size_in_bytes (type) > 8 || TYPE_MODE (type) == BLKmode;
3393 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3396 v850_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
3397 enum machine_mode mode ATTRIBUTE_UNUSED,
3398 tree type ATTRIBUTE_UNUSED,
3399 int *pretend_arg_size ATTRIBUTE_UNUSED,
3400 int second_time ATTRIBUTE_UNUSED)
3402 ca->anonymous_args = (!TARGET_GHS ? 1 : 0);