1 /* Subroutines for insn-output.c for NEC V850 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
33 #include "insn-attr.h"
40 #include "integrate.h"
43 #include "target-def.h"
46 #define streq(a,b) (strcmp (a, b) == 0)
49 /* Function prototypes for stupid compilers: */
50 static void const_double_split PARAMS ((rtx, HOST_WIDE_INT *, HOST_WIDE_INT *));
51 static int const_costs_int PARAMS ((HOST_WIDE_INT, int));
52 static void substitute_ep_register PARAMS ((rtx, rtx, int, int, rtx *, rtx *));
53 static int ep_memory_offset PARAMS ((enum machine_mode, int));
54 static void v850_set_data_area PARAMS ((tree, v850_data_area));
55 const struct attribute_spec v850_attribute_table[];
56 static tree v850_handle_interrupt_attribute PARAMS ((tree *, tree, tree, int, bool *));
57 static tree v850_handle_data_area_attribute PARAMS ((tree *, tree, tree, int, bool *));
58 static void v850_insert_attributes PARAMS ((tree, tree *));
59 static void v850_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT));
60 static void v850_encode_data_area PARAMS ((tree));
61 static void v850_encode_section_info PARAMS ((tree, int));
62 static const char *v850_strip_name_encoding PARAMS ((const char *));
64 /* Information about the various small memory areas. */
65 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
67 /* name value max physical max */
68 { "tda", (char *)0, 0, 256 },
69 { "sda", (char *)0, 0, 65536 },
70 { "zda", (char *)0, 0, 32768 },
73 /* Names of the various data areas used on the v850. */
74 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
75 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
77 /* Track the current data area set by the data area pragma (which
78 can be nested). Tested by check_default_data_area. */
79 data_area_stack_element * data_area_stack = NULL;
81 /* True if we don't need to check any more if the current
82 function is an interrupt handler. */
83 static int v850_interrupt_cache_p = FALSE;
85 /* Whether current function is an interrupt handler. */
86 static int v850_interrupt_p = FALSE;
88 /* Initialize the GCC target structure. */
89 #undef TARGET_ASM_ALIGNED_HI_OP
90 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
92 #undef TARGET_ATTRIBUTE_TABLE
93 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
95 #undef TARGET_INSERT_ATTRIBUTES
96 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
98 #undef TARGET_ASM_SELECT_SECTION
99 #define TARGET_ASM_SELECT_SECTION v850_select_section
101 #undef TARGET_ENCODE_SECTION_INFO
102 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
103 #undef TARGET_STRIP_NAME_ENCODING
104 #define TARGET_STRIP_NAME_ENCODING v850_strip_name_encoding
106 struct gcc_target targetm = TARGET_INITIALIZER;
108 /* Sometimes certain combinations of command options do not make
109 sense on a particular target machine. You can define a macro
110 `OVERRIDE_OPTIONS' to take account of this. This macro, if
111 defined, is executed once just after all the command options have
114 Don't use this macro to turn on various extra optimizations for
115 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
121 extern int atoi PARAMS ((const char *));
123 /* Parse -m{s,t,z}da=nnn switches */
124 for (i = 0; i < (int)SMALL_MEMORY_max; i++)
126 if (small_memory[i].value)
128 if (!ISDIGIT (*small_memory[i].value))
129 error ("%s=%s is not numeric",
130 small_memory[i].name,
131 small_memory[i].value);
134 small_memory[i].max = atoi (small_memory[i].value);
135 if (small_memory[i].max > small_memory[i].physical_max)
136 error ("%s=%s is too large",
137 small_memory[i].name,
138 small_memory[i].value);
143 /* Make sure that the US_BIT_SET mask has been correctly initialized. */
144 if ((target_flags & MASK_US_MASK_SET) == 0)
146 target_flags |= MASK_US_MASK_SET;
147 target_flags &= ~MASK_US_BIT_SET;
152 /* Output assembly code for the start of the file. */
155 asm_file_start (file)
158 output_file_directive (file, main_input_filename);
162 /* Return an RTX to represent where a value with mode MODE will be returned
163 from a function. If the result is 0, the argument is pushed. */
166 function_arg (cum, mode, type, named)
167 CUMULATIVE_ARGS *cum;
168 enum machine_mode mode;
175 if (TARGET_GHS && !named)
179 size = int_size_in_bytes (type);
181 size = GET_MODE_SIZE (mode);
187 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
191 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
193 if (cum->nbytes > 4 * UNITS_PER_WORD)
196 if (type == NULL_TREE
197 && cum->nbytes + size > 4 * UNITS_PER_WORD)
200 switch (cum->nbytes / UNITS_PER_WORD)
203 result = gen_rtx_REG (mode, 6);
206 result = gen_rtx_REG (mode, 7);
209 result = gen_rtx_REG (mode, 8);
212 result = gen_rtx_REG (mode, 9);
222 /* Return the number of words which must be put into registers
223 for values which are part in registers and part in memory. */
226 function_arg_partial_nregs (cum, mode, type, named)
227 CUMULATIVE_ARGS *cum;
228 enum machine_mode mode;
234 if (TARGET_GHS && !named)
238 size = int_size_in_bytes (type);
240 size = GET_MODE_SIZE (mode);
243 align = TYPE_ALIGN (type) / BITS_PER_UNIT;
247 cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
249 if (cum->nbytes > 4 * UNITS_PER_WORD)
252 if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
255 if (type == NULL_TREE
256 && cum->nbytes + size > 4 * UNITS_PER_WORD)
259 return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
263 /* Return the high and low words of a CONST_DOUBLE */
266 const_double_split (x, p_high, p_low)
268 HOST_WIDE_INT *p_high;
269 HOST_WIDE_INT *p_low;
271 if (GET_CODE (x) == CONST_DOUBLE)
276 switch (GET_MODE (x))
279 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
280 REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
281 *p_high = t[1]; /* since v850 is little endian */
282 *p_low = t[0]; /* high is second word */
286 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
287 REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
293 *p_high = CONST_DOUBLE_HIGH (x);
294 *p_low = CONST_DOUBLE_LOW (x);
302 fatal_insn ("const_double_split got a bad insn:", x);
306 /* Return the cost of the rtx R with code CODE. */
309 const_costs_int (value, zero_cost)
313 if (CONST_OK_FOR_I (value))
315 else if (CONST_OK_FOR_J (value))
317 else if (CONST_OK_FOR_K (value))
328 HOST_WIDE_INT high, low;
333 return const_costs_int (INTVAL (r), 0);
336 const_double_split (r, &high, &low);
337 if (GET_MODE (r) == SFmode)
338 return const_costs_int (high, 1);
340 return const_costs_int (high, 1) + const_costs_int (low, 1);
356 /* Print operand X using operand code CODE to assembly language output file
360 print_operand (file, x, code)
365 HOST_WIDE_INT high, low;
370 /* We use 'c' operands with symbols for .vtinherit */
371 if (GET_CODE (x) == SYMBOL_REF)
373 output_addr_const(file, x);
380 switch ((code == 'B' || code == 'C')
381 ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
384 if (code == 'c' || code == 'C')
385 fprintf (file, "nz");
387 fprintf (file, "ne");
390 if (code == 'c' || code == 'C')
396 fprintf (file, "ge");
399 fprintf (file, "gt");
402 fprintf (file, "le");
405 fprintf (file, "lt");
408 fprintf (file, "nl");
414 fprintf (file, "nh");
423 case 'F': /* high word of CONST_DOUBLE */
424 if (GET_CODE (x) == CONST_INT)
425 fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
426 else if (GET_CODE (x) == CONST_DOUBLE)
428 const_double_split (x, &high, &low);
429 fprintf (file, "%ld", (long) high);
434 case 'G': /* low word of CONST_DOUBLE */
435 if (GET_CODE (x) == CONST_INT)
436 fprintf (file, "%ld", (long) INTVAL (x));
437 else if (GET_CODE (x) == CONST_DOUBLE)
439 const_double_split (x, &high, &low);
440 fprintf (file, "%ld", (long) low);
446 fprintf (file, "%d\n", INTVAL (x) & 0xffff);
449 fprintf (file, "%d", exact_log2 (INTVAL (x)));
452 if (special_symbolref_operand (x, VOIDmode))
456 if (GET_CODE (x) == SYMBOL_REF)
458 else if (GET_CODE (x) == CONST)
459 name = XSTR (XEXP (XEXP (x, 0), 0), 0);
463 if (ZDA_NAME_P (name))
464 fprintf (file, "zdaoff");
465 else if (SDA_NAME_P (name))
466 fprintf (file, "sdaoff");
467 else if (TDA_NAME_P (name))
468 fprintf (file, "tdaoff");
476 if (special_symbolref_operand (x, VOIDmode))
477 output_addr_const (file, x);
482 if (special_symbolref_operand (x, VOIDmode))
486 if (GET_CODE (x) == SYMBOL_REF)
488 else if (GET_CODE (x) == CONST)
489 name = XSTR (XEXP (XEXP (x, 0), 0), 0);
493 if (ZDA_NAME_P (name))
494 fprintf (file, "r0");
495 else if (SDA_NAME_P (name))
496 fprintf (file, "gp");
497 else if (TDA_NAME_P (name))
498 fprintf (file, "ep");
505 case 'R': /* 2nd word of a double. */
506 switch (GET_CODE (x))
509 fprintf (file, reg_names[REGNO (x) + 1]);
512 x = XEXP (adjust_address (x, SImode, 4), 0);
513 print_operand_address (file, x);
514 if (GET_CODE (x) == CONST_INT)
515 fprintf (file, "[r0]");
524 /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
525 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
532 /* Like an 'S' operand above, but for unsigned loads only. */
533 if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
538 case 'W': /* print the instruction suffix */
539 switch (GET_MODE (x))
544 case QImode: fputs (".b", file); break;
545 case HImode: fputs (".h", file); break;
546 case SImode: fputs (".w", file); break;
547 case SFmode: fputs (".w", file); break;
550 case '.': /* register r0 */
551 fputs (reg_names[0], file);
553 case 'z': /* reg or zero */
555 fputs (reg_names[0], file);
556 else if (GET_CODE (x) == REG)
557 fputs (reg_names[REGNO (x)], file);
562 switch (GET_CODE (x))
565 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
566 output_address (gen_rtx_PLUS (SImode, gen_rtx (REG, SImode, 0),
569 output_address (XEXP (x, 0));
573 fputs (reg_names[REGNO (x)], file);
576 fputs (reg_names[subreg_regno (x)], file);
583 print_operand_address (file, x);
594 /* Output assembly language output for the address ADDR to FILE. */
597 print_operand_address (file, addr)
601 switch (GET_CODE (addr))
604 fprintf (file, "0[");
605 print_operand (file, addr, 0);
609 if (GET_CODE (XEXP (addr, 0)) == REG)
612 fprintf (file, "lo(");
613 print_operand (file, XEXP (addr, 1), 0);
614 fprintf (file, ")[");
615 print_operand (file, XEXP (addr, 0), 0);
620 if (GET_CODE (XEXP (addr, 0)) == REG
621 || GET_CODE (XEXP (addr, 0)) == SUBREG)
624 print_operand (file, XEXP (addr, 1), 0);
626 print_operand (file, XEXP (addr, 0), 0);
631 print_operand (file, XEXP (addr, 0), 0);
633 print_operand (file, XEXP (addr, 1), 0);
637 if (ENCODED_NAME_P (XSTR (addr, 0)))
639 const char *name = XSTR (addr, 0);
640 const char *off_name;
641 const char *reg_name;
643 if (ZDA_NAME_P (name))
648 else if (SDA_NAME_P (name))
653 else if (TDA_NAME_P (name))
661 fprintf (file, "%s(", off_name);
662 output_addr_const (file, addr);
663 fprintf (file, ")[%s]", reg_name);
666 output_addr_const (file, addr);
669 if (special_symbolref_operand (addr, VOIDmode))
671 const char *name = XSTR (XEXP (XEXP (addr, 0), 0), 0);
672 const char *off_name;
673 const char *reg_name;
675 if (ZDA_NAME_P (name))
680 else if (SDA_NAME_P (name))
685 else if (TDA_NAME_P (name))
693 fprintf (file, "%s(", off_name);
694 output_addr_const (file, addr);
695 fprintf (file, ")[%s]", reg_name);
698 output_addr_const (file, addr);
701 output_addr_const (file, addr);
706 /* When assemble_integer is used to emit the offsets for a switch
707 table it can encounter (TRUNCATE:HI (MINUS:SI (LABEL_REF:SI) (LABEL_REF:SI))).
708 output_addr_const will normally barf at this, but it is OK to omit
709 the truncate and just emit the difference of the two labels. The
710 .hword directive will automatically handle the truncation for us.
712 Returns 1 if rtx was handled, 0 otherwise. */
715 v850_output_addr_const_extra (file, x)
719 if (GET_CODE (x) != TRUNCATE)
724 /* We must also handle the case where the switch table was passed a
725 constant value and so has been collapsed. In this case the first
726 label will have been deleted. In such a case it is OK to emit
727 nothing, since the table will not be used.
728 (cf gcc.c-torture/compile/990801-1.c). */
729 if (GET_CODE (x) == MINUS
730 && GET_CODE (XEXP (x, 0)) == LABEL_REF
731 && GET_CODE (XEXP (XEXP (x, 0), 0)) == CODE_LABEL
732 && INSN_DELETED_P (XEXP (XEXP (x, 0), 0)))
735 output_addr_const (file, x);
739 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
743 output_move_single (operands)
746 rtx dst = operands[0];
747 rtx src = operands[1];
754 else if (GET_CODE (src) == CONST_INT)
756 HOST_WIDE_INT value = INTVAL (src);
758 if (CONST_OK_FOR_J (value)) /* Signed 5 bit immediate. */
761 else if (CONST_OK_FOR_K (value)) /* Signed 16 bit immediate. */
762 return "movea lo(%1),%.,%0";
764 else if (CONST_OK_FOR_L (value)) /* Upper 16 bits were set. */
765 return "movhi hi(%1),%.,%0";
767 /* A random constant. */
768 else if (TARGET_V850E)
771 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
774 else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
776 HOST_WIDE_INT high, low;
778 const_double_split (src, &high, &low);
780 if (CONST_OK_FOR_J (high)) /* Signed 5 bit immediate. */
783 else if (CONST_OK_FOR_K (high)) /* Signed 16 bit immediate. */
784 return "movea lo(%F1),%.,%0";
786 else if (CONST_OK_FOR_L (high)) /* Upper 16 bits were set. */
787 return "movhi hi(%F1),%.,%0";
789 /* A random constant. */
790 else if (TARGET_V850E)
794 return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
797 else if (GET_CODE (src) == MEM)
798 return "%S1ld%W1 %1,%0";
800 else if (special_symbolref_operand (src, VOIDmode))
801 return "movea %O1(%P1),%Q1,%0";
803 else if (GET_CODE (src) == LABEL_REF
804 || GET_CODE (src) == SYMBOL_REF
805 || GET_CODE (src) == CONST)
808 return "mov hilo(%1),%0";
810 return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
813 else if (GET_CODE (src) == HIGH)
814 return "movhi hi(%1),%.,%0";
816 else if (GET_CODE (src) == LO_SUM)
818 operands[2] = XEXP (src, 0);
819 operands[3] = XEXP (src, 1);
820 return "movea lo(%3),%2,%0";
824 else if (GET_CODE (dst) == MEM)
827 return "%S0st%W0 %1,%0";
829 else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
830 return "%S0st%W0 %.,%0";
832 else if (GET_CODE (src) == CONST_DOUBLE
833 && CONST0_RTX (GET_MODE (dst)) == src)
834 return "%S0st%W0 %.,%0";
837 fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
842 /* Return appropriate code to load up an 8 byte integer or
843 floating point value */
846 output_move_double (operands)
849 enum machine_mode mode = GET_MODE (operands[0]);
850 rtx dst = operands[0];
851 rtx src = operands[1];
853 if (register_operand (dst, mode)
854 && register_operand (src, mode))
856 if (REGNO (src) + 1 == REGNO (dst))
857 return "mov %R1,%R0\n\tmov %1,%0";
859 return "mov %1,%0\n\tmov %R1,%R0";
863 if (GET_CODE (dst) == MEM
864 && ((GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
865 || (GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src))))
866 return "st.w %.,%0\n\tst.w %.,%R0";
868 if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
870 HOST_WIDE_INT high_low[2];
874 if (GET_CODE (src) == CONST_DOUBLE)
875 const_double_split (src, &high_low[1], &high_low[0]);
878 high_low[0] = INTVAL (src);
879 high_low[1] = (INTVAL (src) >= 0) ? 0 : -1;
882 for (i = 0; i < 2; i++)
884 xop[0] = gen_rtx_REG (SImode, REGNO (dst)+i);
885 xop[1] = GEN_INT (high_low[i]);
886 output_asm_insn (output_move_single (xop), xop);
892 if (GET_CODE (src) == MEM)
895 int dreg = REGNO (dst);
896 rtx inside = XEXP (src, 0);
898 if (GET_CODE (inside) == REG)
899 ptrreg = REGNO (inside);
900 else if (GET_CODE (inside) == SUBREG)
901 ptrreg = subreg_regno (inside);
902 else if (GET_CODE (inside) == PLUS)
903 ptrreg = REGNO (XEXP (inside, 0));
904 else if (GET_CODE (inside) == LO_SUM)
905 ptrreg = REGNO (XEXP (inside, 0));
908 return "ld.w %R1,%R0\n\tld.w %1,%0";
911 if (GET_CODE (src) == MEM)
912 return "ld.w %1,%0\n\tld.w %R1,%R0";
914 if (GET_CODE (dst) == MEM)
915 return "st.w %1,%0\n\tst.w %R1,%R0";
917 return "mov %1,%0\n\tmov %R1,%R0";
921 /* Return maximum offset supported for a short EP memory reference of mode
922 MODE and signedness UNSIGNEDP. */
925 ep_memory_offset (mode, unsignedp)
926 enum machine_mode mode;
927 int ATTRIBUTE_UNUSED unsignedp;
934 if (TARGET_SMALL_SLD)
935 max_offset = (1 << 4);
936 else if (TARGET_V850E
937 && ( ( unsignedp && ! TARGET_US_BIT_SET)
938 || (! unsignedp && TARGET_US_BIT_SET)))
939 max_offset = (1 << 4);
941 max_offset = (1 << 7);
945 if (TARGET_SMALL_SLD)
946 max_offset = (1 << 5);
947 else if (TARGET_V850E
948 && ( ( unsignedp && ! TARGET_US_BIT_SET)
949 || (! unsignedp && TARGET_US_BIT_SET)))
950 max_offset = (1 << 5);
952 max_offset = (1 << 8);
957 max_offset = (1 << 8);
967 /* Return true if OP is a valid short EP memory reference */
970 ep_memory_operand (op, mode, unsigned_load)
972 enum machine_mode mode;
979 if (GET_CODE (op) != MEM)
982 max_offset = ep_memory_offset (mode, unsigned_load);
984 mask = GET_MODE_SIZE (mode) - 1;
987 if (GET_CODE (addr) == CONST)
988 addr = XEXP (addr, 0);
990 switch (GET_CODE (addr))
996 return TDA_NAME_P (XSTR (addr, 0));
999 return REGNO (addr) == EP_REGNUM;
1002 op0 = XEXP (addr, 0);
1003 op1 = XEXP (addr, 1);
1004 if (GET_CODE (op1) == CONST_INT
1005 && INTVAL (op1) < max_offset
1006 && INTVAL (op1) >= 0
1007 && (INTVAL (op1) & mask) == 0)
1009 if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
1012 if (GET_CODE (op0) == SYMBOL_REF && TDA_NAME_P (XSTR (op0, 0)))
1021 /* Return true if OP is either a register or 0 */
1024 reg_or_0_operand (op, mode)
1026 enum machine_mode mode;
1028 if (GET_CODE (op) == CONST_INT)
1029 return INTVAL (op) == 0;
1031 else if (GET_CODE (op) == CONST_DOUBLE)
1032 return CONST_DOUBLE_OK_FOR_G (op);
1035 return register_operand (op, mode);
1038 /* Return true if OP is either a register or a signed five bit integer */
1041 reg_or_int5_operand (op, mode)
1043 enum machine_mode mode;
1045 if (GET_CODE (op) == CONST_INT)
1046 return CONST_OK_FOR_J (INTVAL (op));
1049 return register_operand (op, mode);
1052 /* Return true if OP is either a register or a signed nine bit integer. */
1055 reg_or_int9_operand (op, mode)
1057 enum machine_mode mode;
1059 if (GET_CODE (op) == CONST_INT)
1060 return CONST_OK_FOR_O (INTVAL (op));
1062 return register_operand (op, mode);
1065 /* Return true if OP is either a register or a const integer. */
1068 reg_or_const_operand (op, mode)
1070 enum machine_mode mode;
1072 if (GET_CODE (op) == CONST_INT)
1075 return register_operand (op, mode);
1078 /* Return true if OP is a valid call operand. */
1081 call_address_operand (op, mode)
1083 enum machine_mode ATTRIBUTE_UNUSED mode;
1085 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
1086 if (TARGET_LONG_CALLS)
1087 return GET_CODE (op) == REG;
1088 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
1092 special_symbolref_operand (op, mode)
1094 enum machine_mode ATTRIBUTE_UNUSED mode;
1096 if (GET_CODE (op) == SYMBOL_REF)
1097 return ENCODED_NAME_P (XSTR (op, 0));
1099 else if (GET_CODE (op) == CONST)
1100 return (GET_CODE (XEXP (op, 0)) == PLUS
1101 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
1102 && ENCODED_NAME_P (XSTR (XEXP (XEXP (op, 0), 0), 0))
1103 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
1104 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))));
1110 movsi_source_operand (op, mode)
1112 enum machine_mode mode;
1114 /* Some constants, as well as symbolic operands
1115 must be done with HIGH & LO_SUM patterns. */
1117 && GET_CODE (op) != HIGH
1118 && GET_CODE (op) != CONSTANT_P_RTX
1119 && !(GET_CODE (op) == CONST_INT
1120 && (CONST_OK_FOR_J (INTVAL (op))
1121 || CONST_OK_FOR_K (INTVAL (op))
1122 || CONST_OK_FOR_L (INTVAL (op)))))
1123 return special_symbolref_operand (op, mode);
1125 return general_operand (op, mode);
1129 power_of_two_operand (op, mode)
1131 enum machine_mode ATTRIBUTE_UNUSED mode;
1133 if (GET_CODE (op) != CONST_INT)
1136 if (exact_log2 (INTVAL (op)) == -1)
1142 not_power_of_two_operand (op, mode)
1144 enum machine_mode mode;
1150 else if (mode == HImode)
1152 else if (mode == SImode)
1157 if (GET_CODE (op) != CONST_INT)
1160 if (exact_log2 (~INTVAL (op) & mask) == -1)
1166 /* Substitute memory references involving a pointer, to use the ep pointer,
1167 taking care to save and preserve the ep. */
1170 substitute_ep_register (first_insn, last_insn, uses, regno, p_r1, p_ep)
1178 rtx reg = gen_rtx_REG (Pmode, regno);
1183 regs_ever_live[1] = 1;
1184 *p_r1 = gen_rtx_REG (Pmode, 1);
1185 *p_ep = gen_rtx_REG (Pmode, 30);
1190 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1191 2 * (uses - 3), uses, reg_names[regno],
1192 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1193 INSN_UID (first_insn), INSN_UID (last_insn));
1195 if (GET_CODE (first_insn) == NOTE)
1196 first_insn = next_nonnote_insn (first_insn);
1198 last_insn = next_nonnote_insn (last_insn);
1199 for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1201 if (GET_CODE (insn) == INSN)
1203 rtx pattern = single_set (insn);
1205 /* Replace the memory references. */
1209 /* Memory operands are signed by default. */
1210 int unsignedp = FALSE;
1212 if (GET_CODE (SET_DEST (pattern)) == MEM
1213 && GET_CODE (SET_SRC (pattern)) == MEM)
1216 else if (GET_CODE (SET_DEST (pattern)) == MEM)
1217 p_mem = &SET_DEST (pattern);
1219 else if (GET_CODE (SET_SRC (pattern)) == MEM)
1220 p_mem = &SET_SRC (pattern);
1222 else if (GET_CODE (SET_SRC (pattern)) == SIGN_EXTEND
1223 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1224 p_mem = &XEXP (SET_SRC (pattern), 0);
1226 else if (GET_CODE (SET_SRC (pattern)) == ZERO_EXTEND
1227 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == MEM)
1229 p_mem = &XEXP (SET_SRC (pattern), 0);
1237 rtx addr = XEXP (*p_mem, 0);
1239 if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1240 *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1242 else if (GET_CODE (addr) == PLUS
1243 && GET_CODE (XEXP (addr, 0)) == REG
1244 && REGNO (XEXP (addr, 0)) == (unsigned) regno
1245 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1246 && ((INTVAL (XEXP (addr, 1)))
1247 < ep_memory_offset (GET_MODE (*p_mem),
1249 && ((INTVAL (XEXP (addr, 1))) >= 0))
1250 *p_mem = change_address (*p_mem, VOIDmode,
1251 gen_rtx_PLUS (Pmode,
1259 /* Optimize back to back cases of ep <- r1 & r1 <- ep. */
1260 insn = prev_nonnote_insn (first_insn);
1261 if (insn && GET_CODE (insn) == INSN
1262 && GET_CODE (PATTERN (insn)) == SET
1263 && SET_DEST (PATTERN (insn)) == *p_ep
1264 && SET_SRC (PATTERN (insn)) == *p_r1)
1267 emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1269 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1270 emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1274 /* In rare cases, correct code generation requires extra machine
1275 dependent processing between the second jump optimization pass and
1276 delayed branch scheduling. On those machines, define this macro
1277 as a C statement to act on the code starting at INSN.
1279 On the 850, we use it to implement the -mep mode to copy heavily used
1280 pointers to ep to use the implicit addressing. */
1282 void v850_reorg (start_insn)
1291 regs[FIRST_PSEUDO_REGISTER];
1300 /* If not ep mode, just return now. */
1304 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1307 regs[i].first_insn = NULL_RTX;
1308 regs[i].last_insn = NULL_RTX;
1311 for (insn = start_insn; insn != NULL_RTX; insn = NEXT_INSN (insn))
1313 switch (GET_CODE (insn))
1315 /* End of basic block */
1322 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1324 if (max_uses < regs[i].uses)
1326 max_uses = regs[i].uses;
1332 substitute_ep_register (regs[max_regno].first_insn,
1333 regs[max_regno].last_insn,
1334 max_uses, max_regno, &r1, &ep);
1338 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1341 regs[i].first_insn = NULL_RTX;
1342 regs[i].last_insn = NULL_RTX;
1350 pattern = single_set (insn);
1352 /* See if there are any memory references we can shorten */
1355 rtx src = SET_SRC (pattern);
1356 rtx dest = SET_DEST (pattern);
1358 /* Memory operands are signed by default. */
1359 int unsignedp = FALSE;
1361 /* We might have (SUBREG (MEM)) here, so just get rid of the
1362 subregs to make this code simpler. */
1363 if (GET_CODE (dest) == SUBREG
1364 && (GET_CODE (SUBREG_REG (dest)) == MEM
1365 || GET_CODE (SUBREG_REG (dest)) == REG))
1366 alter_subreg (&dest);
1367 if (GET_CODE (src) == SUBREG
1368 && (GET_CODE (SUBREG_REG (src)) == MEM
1369 || GET_CODE (SUBREG_REG (src)) == REG))
1370 alter_subreg (&src);
1372 if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1375 else if (GET_CODE (dest) == MEM)
1378 else if (GET_CODE (src) == MEM)
1381 else if (GET_CODE (src) == SIGN_EXTEND
1382 && GET_CODE (XEXP (src, 0)) == MEM)
1383 mem = XEXP (src, 0);
1385 else if (GET_CODE (src) == ZERO_EXTEND
1386 && GET_CODE (XEXP (src, 0)) == MEM)
1388 mem = XEXP (src, 0);
1394 if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1397 else if (!use_ep && mem
1398 && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1400 rtx addr = XEXP (mem, 0);
1404 if (GET_CODE (addr) == REG)
1407 regno = REGNO (addr);
1410 else if (GET_CODE (addr) == PLUS
1411 && GET_CODE (XEXP (addr, 0)) == REG
1412 && GET_CODE (XEXP (addr, 1)) == CONST_INT
1413 && ((INTVAL (XEXP (addr, 1)))
1414 < ep_memory_offset (GET_MODE (mem), unsignedp))
1415 && ((INTVAL (XEXP (addr, 1))) >= 0))
1418 regno = REGNO (XEXP (addr, 0));
1427 regs[regno].last_insn = insn;
1428 if (!regs[regno].first_insn)
1429 regs[regno].first_insn = insn;
1433 /* Loading up a register in the basic block zaps any savings
1435 if (GET_CODE (dest) == REG)
1437 enum machine_mode mode = GET_MODE (dest);
1441 regno = REGNO (dest);
1442 endregno = regno + HARD_REGNO_NREGS (regno, mode);
1446 /* See if we can use the pointer before this
1451 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1453 if (max_uses < regs[i].uses)
1455 max_uses = regs[i].uses;
1461 && max_regno >= regno
1462 && max_regno < endregno)
1464 substitute_ep_register (regs[max_regno].first_insn,
1465 regs[max_regno].last_insn,
1466 max_uses, max_regno, &r1,
1469 /* Since we made a substitution, zap all remembered
1471 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1474 regs[i].first_insn = NULL_RTX;
1475 regs[i].last_insn = NULL_RTX;
1480 for (i = regno; i < endregno; i++)
1483 regs[i].first_insn = NULL_RTX;
1484 regs[i].last_insn = NULL_RTX;
1493 /* # of registers saved by the interrupt handler. */
1494 #define INTERRUPT_FIXED_NUM 4
1496 /* # of bytes for registers saved by the interrupt handler. */
1497 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1499 /* # of registers saved in register parameter area. */
1500 #define INTERRUPT_REGPARM_NUM 4
1501 /* # of words saved for other registers. */
1502 #define INTERRUPT_ALL_SAVE_NUM \
1503 (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1505 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1508 compute_register_save_size (p_reg_saved)
1513 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1514 int call_p = regs_ever_live [LINK_POINTER_REGNUM];
1517 /* Count the return pointer if we need to save it. */
1518 if (current_function_profile && !call_p)
1519 regs_ever_live [LINK_POINTER_REGNUM] = call_p = 1;
1521 /* Count space for the register saves. */
1522 if (interrupt_handler)
1524 for (i = 0; i <= 31; i++)
1528 if (regs_ever_live[i] || call_p)
1531 reg_saved |= 1L << i;
1535 /* We don't save/restore r0 or the stack pointer */
1537 case STACK_POINTER_REGNUM:
1540 /* For registers with fixed use, we save them, set them to the
1541 appropriate value, and then restore them.
1542 These registers are handled specially, so don't list them
1543 on the list of registers to save in the prologue. */
1544 case 1: /* temp used to hold ep */
1546 case 10: /* temp used to call interrupt save/restore */
1547 case EP_REGNUM: /* ep */
1554 /* Find the first register that needs to be saved. */
1555 for (i = 0; i <= 31; i++)
1556 if (regs_ever_live[i] && ((! call_used_regs[i])
1557 || i == LINK_POINTER_REGNUM))
1560 /* If it is possible that an out-of-line helper function might be
1561 used to generate the prologue for the current function, then we
1562 need to cover the possibility that such a helper function will
1563 be used, despite the fact that there might be gaps in the list of
1564 registers that need to be saved. To detect this we note that the
1565 helper functions always push at least register r29 (provided
1566 that the function is not an interrupt handler). */
1568 if (TARGET_PROLOG_FUNCTION
1569 && (i == 2 || ((i >= 20) && (i < 30))))
1574 reg_saved |= 1L << i;
1579 /* Helper functions save all registers between the starting
1580 register and the last register, regardless of whether they
1581 are actually used by the function or not. */
1582 for (; i <= 29; i++)
1585 reg_saved |= 1L << i;
1588 if (regs_ever_live [LINK_POINTER_REGNUM])
1591 reg_saved |= 1L << LINK_POINTER_REGNUM;
1596 for (; i <= 31; i++)
1597 if (regs_ever_live[i] && ((! call_used_regs[i])
1598 || i == LINK_POINTER_REGNUM))
1601 reg_saved |= 1L << i;
1607 *p_reg_saved = reg_saved;
1613 compute_frame_size (size, p_reg_saved)
1618 + compute_register_save_size (p_reg_saved)
1619 + current_function_outgoing_args_size);
1628 unsigned int size = get_frame_size ();
1629 unsigned int actual_fsize;
1630 unsigned int init_stack_alloc = 0;
1633 unsigned int num_save;
1634 unsigned int default_stack;
1636 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1639 actual_fsize = compute_frame_size (size, ®_saved);
1641 /* Save/setup global registers for interrupt functions right now. */
1642 if (interrupt_handler)
1644 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1645 emit_insn (gen_callt_save_interrupt ());
1647 emit_insn (gen_save_interrupt ());
1649 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1651 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1652 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1655 /* Save arg registers to the stack if necessary. */
1656 else if (current_function_args_info.anonymous_args)
1658 if (TARGET_PROLOG_FUNCTION)
1660 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1661 emit_insn (gen_save_r6_r9_v850e ());
1663 emit_insn (gen_save_r6_r9 ());
1668 for (i = 6; i < 10; i++)
1670 emit_move_insn (gen_rtx_MEM (SImode,
1671 plus_constant (stack_pointer_rtx,
1673 gen_rtx_REG (SImode, i));
1679 /* Identify all of the saved registers. */
1682 for (i = 1; i < 31; i++)
1684 if (((1L << i) & reg_saved) != 0)
1685 save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1688 /* If the return pointer is saved, the helper functions also allocate
1689 16 bytes of stack for arguments to be saved in. */
1690 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1692 save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1696 /* See if we have an insn that allocates stack space and saves the particular
1697 registers we want to. */
1698 save_all = NULL_RTX;
1699 if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1701 int alloc_stack = (4 * num_save) + default_stack;
1702 int unalloc_stack = actual_fsize - alloc_stack;
1703 int save_func_len = 4;
1704 int save_normal_len;
1707 save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1709 /* see if we would have used ep to save the stack */
1710 if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1711 save_normal_len = (3 * 2) + (2 * num_save);
1713 save_normal_len = 4 * num_save;
1715 save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1717 /* Don't bother checking if we don't actually save any space.
1718 This happens for instance if one register is saved and additional
1719 stack space is allocated. */
1720 if (save_func_len < save_normal_len)
1722 save_all = gen_rtx_PARALLEL
1724 rtvec_alloc (num_save + (TARGET_V850 ? 2 : 1)));
1726 XVECEXP (save_all, 0, 0)
1727 = gen_rtx_SET (VOIDmode,
1729 plus_constant (stack_pointer_rtx, -alloc_stack));
1733 XVECEXP (save_all, 0, num_save+1)
1734 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1737 offset = - default_stack;
1738 for (i = 0; i < num_save; i++)
1740 XVECEXP (save_all, 0, i+1)
1741 = gen_rtx_SET (VOIDmode,
1743 plus_constant (stack_pointer_rtx,
1749 code = recog (save_all, NULL_RTX, NULL);
1752 rtx insn = emit_insn (save_all);
1753 INSN_CODE (insn) = code;
1754 actual_fsize -= alloc_stack;
1758 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1759 save_normal_len - save_func_len,
1760 save_normal_len, save_func_len,
1761 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1764 save_all = NULL_RTX;
1768 /* If no prolog save function is available, store the registers the old
1769 fashioned way (one by one). */
1772 /* Special case interrupt functions that save all registers for a call. */
1773 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1775 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
1776 emit_insn (gen_callt_save_all_interrupt ());
1778 emit_insn (gen_save_all_interrupt ());
1782 /* If the stack is too big, allocate it in chunks so we can do the
1783 register saves. We use the register save size so we use the ep
1785 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1786 init_stack_alloc = compute_register_save_size (NULL);
1788 init_stack_alloc = actual_fsize;
1790 /* Save registers at the beginning of the stack frame */
1791 offset = init_stack_alloc - 4;
1793 if (init_stack_alloc)
1794 emit_insn (gen_addsi3 (stack_pointer_rtx,
1796 GEN_INT (-init_stack_alloc)));
1798 /* Save the return pointer first. */
1799 if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1801 emit_move_insn (gen_rtx_MEM (SImode,
1802 plus_constant (stack_pointer_rtx,
1804 save_regs[--num_save]);
1808 for (i = 0; i < num_save; i++)
1810 emit_move_insn (gen_rtx_MEM (SImode,
1811 plus_constant (stack_pointer_rtx,
1819 /* Allocate the rest of the stack that was not allocated above (either it is
1820 > 32K or we just called a function to save the registers and needed more
1822 if (actual_fsize > init_stack_alloc)
1824 int diff = actual_fsize - init_stack_alloc;
1825 if (CONST_OK_FOR_K (diff))
1826 emit_insn (gen_addsi3 (stack_pointer_rtx,
1831 rtx reg = gen_rtx_REG (Pmode, 12);
1832 emit_move_insn (reg, GEN_INT (-diff));
1833 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1837 /* If we need a frame pointer, set it up now. */
1838 if (frame_pointer_needed)
1839 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1848 unsigned int size = get_frame_size ();
1850 unsigned int actual_fsize = compute_frame_size (size, ®_saved);
1851 unsigned int init_stack_free = 0;
1852 rtx restore_regs[32];
1854 unsigned int num_restore;
1855 unsigned int default_stack;
1857 int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1859 /* Eliminate the initial stack stored by interrupt functions. */
1860 if (interrupt_handler)
1862 actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1863 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1864 actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1867 /* Cut off any dynamic stack created. */
1868 if (frame_pointer_needed)
1869 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1871 /* Identify all of the saved registers. */
1874 for (i = 1; i < 31; i++)
1876 if (((1L << i) & reg_saved) != 0)
1877 restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1880 /* If the return pointer is saved, the helper functions also allocate
1881 16 bytes of stack for arguments to be saved in. */
1882 if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1884 restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1888 /* See if we have an insn that restores the particular registers we
1890 restore_all = NULL_RTX;
1892 if (TARGET_PROLOG_FUNCTION
1894 && actual_fsize >= default_stack
1895 && !interrupt_handler)
1897 int alloc_stack = (4 * num_restore) + default_stack;
1898 int unalloc_stack = actual_fsize - alloc_stack;
1899 int restore_func_len = 4;
1900 int restore_normal_len;
1903 restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1905 /* See if we would have used ep to restore the registers. */
1906 if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1907 restore_normal_len = (3 * 2) + (2 * num_restore);
1909 restore_normal_len = 4 * num_restore;
1911 restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1913 /* Don't bother checking if we don't actually save any space. */
1914 if (restore_func_len < restore_normal_len)
1916 restore_all = gen_rtx_PARALLEL (VOIDmode,
1917 rtvec_alloc (num_restore + 2));
1918 XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1919 XVECEXP (restore_all, 0, 1)
1920 = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1921 gen_rtx_PLUS (Pmode,
1923 GEN_INT (alloc_stack)));
1925 offset = alloc_stack - 4;
1926 for (i = 0; i < num_restore; i++)
1928 XVECEXP (restore_all, 0, i+2)
1929 = gen_rtx_SET (VOIDmode,
1932 plus_constant (stack_pointer_rtx,
1937 code = recog (restore_all, NULL_RTX, NULL);
1943 actual_fsize -= alloc_stack;
1946 if (CONST_OK_FOR_K (actual_fsize))
1947 emit_insn (gen_addsi3 (stack_pointer_rtx,
1949 GEN_INT (actual_fsize)));
1952 rtx reg = gen_rtx_REG (Pmode, 12);
1953 emit_move_insn (reg, GEN_INT (actual_fsize));
1954 emit_insn (gen_addsi3 (stack_pointer_rtx,
1960 insn = emit_jump_insn (restore_all);
1961 INSN_CODE (insn) = code;
1965 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1966 restore_normal_len - restore_func_len,
1967 restore_normal_len, restore_func_len,
1968 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1971 restore_all = NULL_RTX;
1975 /* If no epilog save function is available, restore the registers the
1976 old fashioned way (one by one). */
1979 /* If the stack is large, we need to cut it down in 2 pieces. */
1980 if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1981 init_stack_free = 4 * num_restore;
1983 init_stack_free = actual_fsize;
1985 /* Deallocate the rest of the stack if it is > 32K. */
1986 if (actual_fsize > init_stack_free)
1990 diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1992 if (CONST_OK_FOR_K (diff))
1993 emit_insn (gen_addsi3 (stack_pointer_rtx,
1998 rtx reg = gen_rtx_REG (Pmode, 12);
1999 emit_move_insn (reg, GEN_INT (diff));
2000 emit_insn (gen_addsi3 (stack_pointer_rtx,
2006 /* Special case interrupt functions that save all registers
2008 if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
2010 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
2011 emit_insn (gen_callt_restore_all_interrupt ());
2013 emit_insn (gen_restore_all_interrupt ());
2017 /* Restore registers from the beginning of the stack frame. */
2018 offset = init_stack_free - 4;
2020 /* Restore the return pointer first. */
2022 && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
2024 emit_move_insn (restore_regs[--num_restore],
2025 gen_rtx_MEM (SImode,
2026 plus_constant (stack_pointer_rtx,
2031 for (i = 0; i < num_restore; i++)
2033 emit_move_insn (restore_regs[i],
2034 gen_rtx_MEM (SImode,
2035 plus_constant (stack_pointer_rtx,
2038 emit_insn (gen_rtx_USE (VOIDmode, restore_regs[i]));
2042 /* Cut back the remainder of the stack. */
2043 if (init_stack_free)
2044 emit_insn (gen_addsi3 (stack_pointer_rtx,
2046 GEN_INT (init_stack_free)));
2049 /* And return or use reti for interrupt handlers. */
2050 if (interrupt_handler)
2052 if (TARGET_V850E && ! TARGET_DISABLE_CALLT)
2053 emit_insn (gen_callt_return_interrupt ());
2055 emit_jump_insn (gen_return_interrupt ());
2057 else if (actual_fsize)
2058 emit_jump_insn (gen_return_internal ());
2060 emit_jump_insn (gen_return ());
2063 v850_interrupt_cache_p = FALSE;
2064 v850_interrupt_p = FALSE;
2068 /* Update the condition code from the insn. */
2071 notice_update_cc (body, insn)
2075 switch (get_attr_cc (insn))
2078 /* Insn does not affect CC at all. */
2082 /* Insn does not change CC, but the 0'th operand has been changed. */
2083 if (cc_status.value1 != 0
2084 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
2085 cc_status.value1 = 0;
2089 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2090 V,C is in an unusable state. */
2092 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
2093 cc_status.value1 = recog_data.operand[0];
2097 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2098 C is in an unusable state. */
2100 cc_status.flags |= CC_NO_CARRY;
2101 cc_status.value1 = recog_data.operand[0];
2105 /* The insn is a compare instruction. */
2107 cc_status.value1 = SET_SRC (body);
2111 /* Insn doesn't leave CC in a usable state. */
2117 /* Retrieve the data area that has been chosen for the given decl. */
2120 v850_get_data_area (decl)
2123 if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2124 return DATA_AREA_SDA;
2126 if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2127 return DATA_AREA_TDA;
2129 if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2130 return DATA_AREA_ZDA;
2132 return DATA_AREA_NORMAL;
2135 /* Store the indicated data area in the decl's attributes. */
2138 v850_set_data_area (decl, data_area)
2140 v850_data_area data_area;
2146 case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2147 case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2148 case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2153 DECL_ATTRIBUTES (decl) = tree_cons
2154 (name, NULL, DECL_ATTRIBUTES (decl));
2157 const struct attribute_spec v850_attribute_table[] =
2159 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2160 { "interrupt_handler", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2161 { "interrupt", 0, 0, true, false, false, v850_handle_interrupt_attribute },
2162 { "sda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2163 { "tda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2164 { "zda", 0, 0, true, false, false, v850_handle_data_area_attribute },
2165 { NULL, 0, 0, false, false, false, NULL }
2168 /* Handle an "interrupt" attribute; arguments as in
2169 struct attribute_spec.handler. */
2171 v850_handle_interrupt_attribute (node, name, args, flags, no_add_attrs)
2174 tree args ATTRIBUTE_UNUSED;
2175 int flags ATTRIBUTE_UNUSED;
2178 if (TREE_CODE (*node) != FUNCTION_DECL)
2180 warning ("`%s' attribute only applies to functions",
2181 IDENTIFIER_POINTER (name));
2182 *no_add_attrs = true;
2188 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2189 struct attribute_spec.handler. */
2191 v850_handle_data_area_attribute (node, name, args, flags, no_add_attrs)
2194 tree args ATTRIBUTE_UNUSED;
2195 int flags ATTRIBUTE_UNUSED;
2198 v850_data_area data_area;
2199 v850_data_area area;
2202 /* Implement data area attribute. */
2203 if (is_attribute_p ("sda", name))
2204 data_area = DATA_AREA_SDA;
2205 else if (is_attribute_p ("tda", name))
2206 data_area = DATA_AREA_TDA;
2207 else if (is_attribute_p ("zda", name))
2208 data_area = DATA_AREA_ZDA;
2212 switch (TREE_CODE (decl))
2215 if (current_function_decl != NULL_TREE)
2217 error_with_decl (decl, "\
2218 a data area attribute cannot be specified for local variables");
2219 *no_add_attrs = true;
2225 area = v850_get_data_area (decl);
2226 if (area != DATA_AREA_NORMAL && data_area != area)
2228 error_with_decl (decl, "\
2229 data area of '%s' conflicts with previous declaration");
2230 *no_add_attrs = true;
2242 /* Return nonzero if FUNC is an interrupt function as specified
2243 by the "interrupt" attribute. */
2246 v850_interrupt_function_p (func)
2252 if (v850_interrupt_cache_p)
2253 return v850_interrupt_p;
2255 if (TREE_CODE (func) != FUNCTION_DECL)
2258 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2264 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2265 ret = a != NULL_TREE;
2268 /* Its not safe to trust global variables until after function inlining has
2270 if (reload_completed | reload_in_progress)
2271 v850_interrupt_p = ret;
2278 v850_encode_data_area (decl)
2281 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2282 int len = strlen (str);
2285 /* Map explict sections into the appropriate attribute */
2286 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2288 if (DECL_SECTION_NAME (decl))
2290 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2292 if (streq (name, ".zdata") || streq (name, ".zbss"))
2293 v850_set_data_area (decl, DATA_AREA_ZDA);
2295 else if (streq (name, ".sdata") || streq (name, ".sbss"))
2296 v850_set_data_area (decl, DATA_AREA_SDA);
2298 else if (streq (name, ".tdata"))
2299 v850_set_data_area (decl, DATA_AREA_TDA);
2302 /* If no attribute, support -m{zda,sda,tda}=n */
2305 int size = int_size_in_bytes (TREE_TYPE (decl));
2309 else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2310 v850_set_data_area (decl, DATA_AREA_TDA);
2312 else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2313 v850_set_data_area (decl, DATA_AREA_SDA);
2315 else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2316 v850_set_data_area (decl, DATA_AREA_ZDA);
2319 if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2323 newstr = alloca (len + 2);
2325 strcpy (newstr + 1, str);
2327 switch (v850_get_data_area (decl))
2329 case DATA_AREA_ZDA: *newstr = ZDA_NAME_FLAG_CHAR; break;
2330 case DATA_AREA_TDA: *newstr = TDA_NAME_FLAG_CHAR; break;
2331 case DATA_AREA_SDA: *newstr = SDA_NAME_FLAG_CHAR; break;
2335 XSTR (XEXP (DECL_RTL (decl), 0), 0) = ggc_alloc_string (newstr, len + 2);
2339 v850_encode_section_info (decl, first)
2343 if (first && TREE_CODE (decl) == VAR_DECL
2344 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2345 v850_encode_data_area (decl);
2349 v850_strip_name_encoding (str)
2352 return str + (ENCODED_NAME_P (str) || *str == '*');
2355 /* Return true if the given RTX is a register which can be restored
2356 by a function epilogue. */
2358 register_is_ok_for_epilogue (op, mode)
2360 enum machine_mode ATTRIBUTE_UNUSED mode;
2362 /* The save/restore routines can only cope with registers 20 - 31. */
2363 return ((GET_CODE (op) == REG)
2364 && (((REGNO (op) >= 20) && REGNO (op) <= 31)));
2367 /* Return nonzero if the given RTX is suitable for collapsing into
2368 jump to a function epilogue. */
2370 pattern_is_ok_for_epilogue (op, mode)
2372 enum machine_mode ATTRIBUTE_UNUSED mode;
2374 int count = XVECLEN (op, 0);
2377 /* If there are no registers to restore then the function epilogue
2382 /* The pattern matching has already established that we are performing a
2383 function epilogue and that we are popping at least one register. We must
2384 now check the remaining entries in the vector to make sure that they are
2385 also register pops. There is no good reason why there should ever be
2386 anything else in this vector, but being paranoid always helps...
2388 The test below performs the C equivalent of this machine description
2391 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2392 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2395 for (i = 3; i < count; i++)
2397 rtx vector_element = XVECEXP (op, 0, i);
2402 if (GET_CODE (vector_element) != SET)
2405 dest = SET_DEST (vector_element);
2406 src = SET_SRC (vector_element);
2408 if (GET_CODE (dest) != REG
2409 || GET_MODE (dest) != SImode
2410 || ! register_is_ok_for_epilogue (dest, SImode)
2411 || GET_CODE (src) != MEM
2412 || GET_MODE (src) != SImode)
2415 plus = XEXP (src, 0);
2417 if (GET_CODE (plus) != PLUS
2418 || GET_CODE (XEXP (plus, 0)) != REG
2419 || GET_MODE (XEXP (plus, 0)) != SImode
2420 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2421 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2428 /* Construct a JR instruction to a routine that will perform the equivalent of
2429 the RTL passed in as an argument. This RTL is a function epilogue that
2430 pops registers off the stack and possibly releases some extra stack space
2431 as well. The code has already verified that the RTL matches these
2434 construct_restore_jr (op)
2437 int count = XVECLEN (op, 0);
2439 unsigned long int mask;
2440 unsigned long int first;
2441 unsigned long int last;
2443 static char buff [100]; /* XXX */
2447 error ("bogus JR construction: %d\n", count);
2451 /* Work out how many bytes to pop off the stack before retrieving
2453 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2455 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2457 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2460 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2462 /* Each pop will remove 4 bytes from the stack... */
2463 stack_bytes -= (count - 2) * 4;
2465 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2466 if (stack_bytes != 0 && stack_bytes != 16)
2468 error ("bad amount of stack space removal: %d", stack_bytes);
2472 /* Now compute the bit mask of registers to push. */
2474 for (i = 2; i < count; i++)
2476 rtx vector_element = XVECEXP (op, 0, i);
2478 if (GET_CODE (vector_element) != SET)
2480 if (GET_CODE (SET_DEST (vector_element)) != REG)
2482 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2485 mask |= 1 << REGNO (SET_DEST (vector_element));
2488 /* Scan for the first register to pop. */
2489 for (first = 0; first < 32; first++)
2491 if (mask & (1 << first))
2498 /* Discover the last register to pop. */
2499 if (mask & (1 << LINK_POINTER_REGNUM))
2501 if (stack_bytes != 16)
2504 last = LINK_POINTER_REGNUM;
2508 if (stack_bytes != 0)
2511 if ((mask & (1 << 29)) == 0)
2517 /* Note, it is possible to have gaps in the register mask.
2518 We ignore this here, and generate a JR anyway. We will
2519 be popping more registers than is strictly necessary, but
2520 it does save code space. */
2522 if (TARGET_LONG_CALLS)
2527 sprintf (name, "__return_%s", reg_names [first]);
2529 sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2531 sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2537 sprintf (buff, "jr __return_%s", reg_names [first]);
2539 sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2546 /* Return nonzero if the given RTX is suitable for collapsing into
2547 a jump to a function prologue. */
2549 pattern_is_ok_for_prologue (op, mode)
2551 enum machine_mode ATTRIBUTE_UNUSED mode;
2553 int count = XVECLEN (op, 0);
2557 /* If there are no registers to save then the function prologue
2562 /* The pattern matching has already established that we are adjusting the
2563 stack and pushing at least one register. We must now check that the
2564 remaining entries in the vector to make sure that they are also register
2565 pushes, except for the last entry which should be a CLOBBER of r10.
2567 The test below performs the C equivalent of this machine description
2570 (set (mem:SI (plus:SI (reg:SI 3)
2571 (match_operand:SI 2 "immediate_operand" "i")))
2572 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2576 for (i = 2; i < count - 1; i++)
2582 vector_element = XVECEXP (op, 0, i);
2584 if (GET_CODE (vector_element) != SET)
2587 dest = SET_DEST (vector_element);
2588 src = SET_SRC (vector_element);
2590 if (GET_CODE (dest) != MEM
2591 || GET_MODE (dest) != SImode
2592 || GET_CODE (src) != REG
2593 || GET_MODE (src) != SImode
2594 || ! register_is_ok_for_epilogue (src, SImode))
2597 plus = XEXP (dest, 0);
2599 if ( GET_CODE (plus) != PLUS
2600 || GET_CODE (XEXP (plus, 0)) != REG
2601 || GET_MODE (XEXP (plus, 0)) != SImode
2602 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2603 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2606 /* If the register is being pushed somewhere other than the stack
2607 space just acquired by the first operand then abandon this quest.
2608 Note: the test is <= because both values are negative. */
2609 if (INTVAL (XEXP (plus, 1))
2610 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2616 /* Make sure that the last entry in the vector is a clobber. */
2617 vector_element = XVECEXP (op, 0, i);
2619 if (GET_CODE (vector_element) != CLOBBER
2620 || GET_CODE (XEXP (vector_element, 0)) != REG
2621 || REGNO (XEXP (vector_element, 0)) != 10)
2627 /* Construct a JARL instruction to a routine that will perform the equivalent
2628 of the RTL passed as a parameter. This RTL is a function prologue that
2629 saves some of the registers r20 - r31 onto the stack, and possibly acquires
2630 some stack space as well. The code has already verified that the RTL
2631 matches these requirements. */
2633 construct_save_jarl (op)
2636 int count = XVECLEN (op, 0);
2638 unsigned long int mask;
2639 unsigned long int first;
2640 unsigned long int last;
2642 static char buff [100]; /* XXX */
2646 error ("bogus JARL construction: %d\n", count);
2651 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2653 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2655 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2657 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2660 /* Work out how many bytes to push onto the stack after storing the
2662 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2664 /* Each push will put 4 bytes from the stack... */
2665 stack_bytes += (count - 2) * 4;
2667 /* Make sure that the amount we are popping either 0 or 16 bytes. */
2668 if (stack_bytes != 0 && stack_bytes != -16)
2670 error ("bad amount of stack space removal: %d", stack_bytes);
2674 /* Now compute the bit mask of registers to push. */
2676 for (i = 1; i < count - 1; i++)
2678 rtx vector_element = XVECEXP (op, 0, i);
2680 if (GET_CODE (vector_element) != SET)
2682 if (GET_CODE (SET_SRC (vector_element)) != REG)
2684 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2687 mask |= 1 << REGNO (SET_SRC (vector_element));
2690 /* Scan for the first register to push. */
2691 for (first = 0; first < 32; first++)
2693 if (mask & (1 << first))
2700 /* Discover the last register to push. */
2701 if (mask & (1 << LINK_POINTER_REGNUM))
2703 if (stack_bytes != -16)
2706 last = LINK_POINTER_REGNUM;
2710 if (stack_bytes != 0)
2712 if ((mask & (1 << 29)) == 0)
2718 /* Note, it is possible to have gaps in the register mask.
2719 We ignore this here, and generate a JARL anyway. We will
2720 be pushing more registers than is strictly necessary, but
2721 it does save code space. */
2723 if (TARGET_LONG_CALLS)
2728 sprintf (name, "__save_%s", reg_names [first]);
2730 sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2732 sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2738 sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2740 sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2747 extern tree last_assemble_variable_decl;
2748 extern int size_directive_output;
2750 /* A version of asm_output_aligned_bss() that copes with the special
2751 data areas of the v850. */
2753 v850_output_aligned_bss (file, decl, name, size, align)
2760 (*targetm.asm_out.globalize_label) (file, name);
2762 switch (v850_get_data_area (decl))
2780 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2781 #ifdef ASM_DECLARE_OBJECT_NAME
2782 last_assemble_variable_decl = decl;
2783 ASM_DECLARE_OBJECT_NAME (file, name, decl);
2785 /* Standard thing is just output label for the object. */
2786 ASM_OUTPUT_LABEL (file, name);
2787 #endif /* ASM_DECLARE_OBJECT_NAME */
2788 ASM_OUTPUT_SKIP (file, size ? size : 1);
2791 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2793 v850_output_common (file, decl, name, size, align)
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, decl, name, size, align)
2839 fprintf (file, "%s", LOCAL_ASM_OP);
2840 assemble_name (file, name);
2841 fprintf (file, "\n");
2843 ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2846 /* Add data area to the given declaration if a ghs data area pragma is
2847 currently in effect (#pragma ghs startXXX/endXXX). */
2849 v850_insert_attributes (decl, attr_ptr)
2851 tree *attr_ptr ATTRIBUTE_UNUSED;
2854 && data_area_stack->data_area
2855 && current_function_decl == NULL_TREE
2856 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2857 && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2858 v850_set_data_area (decl, data_area_stack->data_area);
2860 /* Initialize the default names of the v850 specific sections,
2861 if this has not been done before. */
2863 if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2865 GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2866 = build_string (sizeof (".sdata")-1, ".sdata");
2868 GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2869 = build_string (sizeof (".rosdata")-1, ".rosdata");
2871 GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2872 = build_string (sizeof (".tdata")-1, ".tdata");
2874 GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2875 = build_string (sizeof (".zdata")-1, ".zdata");
2877 GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2878 = build_string (sizeof (".rozdata")-1, ".rozdata");
2881 if (current_function_decl == NULL_TREE
2882 && (TREE_CODE (decl) == VAR_DECL
2883 || TREE_CODE (decl) == CONST_DECL
2884 || TREE_CODE (decl) == FUNCTION_DECL)
2885 && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2886 && !DECL_SECTION_NAME (decl))
2888 enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2889 tree chosen_section;
2891 if (TREE_CODE (decl) == FUNCTION_DECL)
2892 kind = GHS_SECTION_KIND_TEXT;
2895 /* First choose a section kind based on the data area of the decl. */
2896 switch (v850_get_data_area (decl))
2902 kind = ((TREE_READONLY (decl))
2903 ? GHS_SECTION_KIND_ROSDATA
2904 : GHS_SECTION_KIND_SDATA);
2908 kind = GHS_SECTION_KIND_TDATA;
2912 kind = ((TREE_READONLY (decl))
2913 ? GHS_SECTION_KIND_ROZDATA
2914 : GHS_SECTION_KIND_ZDATA);
2917 case DATA_AREA_NORMAL: /* default data area */
2918 if (TREE_READONLY (decl))
2919 kind = GHS_SECTION_KIND_RODATA;
2920 else if (DECL_INITIAL (decl))
2921 kind = GHS_SECTION_KIND_DATA;
2923 kind = GHS_SECTION_KIND_BSS;
2927 /* Now, if the section kind has been explicitly renamed,
2928 then attach a section attribute. */
2929 chosen_section = GHS_current_section_names [(int) kind];
2931 /* Otherwise, if this kind of section needs an explicit section
2932 attribute, then also attach one. */
2933 if (chosen_section == NULL)
2934 chosen_section = GHS_default_section_names [(int) kind];
2938 /* Only set the section name if specified by a pragma, because
2939 otherwise it will force those variables to get allocated storage
2940 in this module, rather than by the linker. */
2941 DECL_SECTION_NAME (decl) = chosen_section;
2946 /* Return nonzero if the given RTX is suitable
2947 for collapsing into a DISPOSE instruction. */
2950 pattern_is_ok_for_dispose (op, mode)
2952 enum machine_mode mode ATTRIBUTE_UNUSED;
2954 int count = XVECLEN (op, 0);
2957 /* If there are no registers to restore then
2958 the dispose instruction is not suitable. */
2962 /* The pattern matching has already established that we are performing a
2963 function epilogue and that we are popping at least one register. We must
2964 now check the remaining entries in the vector to make sure that they are
2965 also register pops. There is no good reason why there should ever be
2966 anything else in this vector, but being paranoid always helps...
2968 The test below performs the C equivalent of this machine description
2971 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2972 (mem:SI (plus:SI (reg:SI 3)
2973 (match_operand:SI n "immediate_operand" "i"))))
2976 for (i = 3; i < count; i++)
2978 rtx vector_element = XVECEXP (op, 0, i);
2983 if (GET_CODE (vector_element) != SET)
2986 dest = SET_DEST (vector_element);
2987 src = SET_SRC (vector_element);
2989 if ( GET_CODE (dest) != REG
2990 || GET_MODE (dest) != SImode
2991 || ! register_is_ok_for_epilogue (dest, SImode)
2992 || GET_CODE (src) != MEM
2993 || GET_MODE (src) != SImode)
2996 plus = XEXP (src, 0);
2998 if ( GET_CODE (plus) != PLUS
2999 || GET_CODE (XEXP (plus, 0)) != REG
3000 || GET_MODE (XEXP (plus, 0)) != SImode
3001 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
3002 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
3009 /* Construct a DISPOSE instruction that is the equivalent of
3010 the given RTX. We have already verified that this should
3014 construct_dispose_instruction (op)
3017 int count = XVECLEN (op, 0);
3019 unsigned long int mask;
3021 static char buff[ 100 ]; /* XXX */
3026 error ("Bogus DISPOSE construction: %d\n", count);
3030 /* Work out how many bytes to pop off the
3031 stack before retrieving registers. */
3032 if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
3034 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
3036 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
3039 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
3041 /* Each pop will remove 4 bytes from the stack... */
3042 stack_bytes -= (count - 2) * 4;
3044 /* Make sure that the amount we are popping
3045 will fit into the DISPOSE instruction. */
3046 if (stack_bytes > 128)
3048 error ("Too much stack space to dispose of: %d", stack_bytes);
3052 /* Now compute the bit mask of registers to push. */
3055 for (i = 2; i < count; i++)
3057 rtx vector_element = XVECEXP (op, 0, i);
3059 if (GET_CODE (vector_element) != SET)
3061 if (GET_CODE (SET_DEST (vector_element)) != REG)
3063 if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
3066 if (REGNO (SET_DEST (vector_element)) == 2)
3069 mask |= 1 << REGNO (SET_DEST (vector_element));
3072 if (! TARGET_DISABLE_CALLT
3073 && (use_callt || stack_bytes == 0 || stack_bytes == 16))
3077 sprintf (buff, "callt ctoff(__callt_return_r2_r%d)", (mask & (1 << 31)) ? 31 : 29);
3082 for (i = 20; i < 32; i++)
3083 if (mask & (1 << i))
3087 sprintf (buff, "callt ctoff(__callt_return_r31c)");
3089 sprintf (buff, "callt ctoff(__callt_return_r%d_r%d%s)",
3090 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
3095 static char regs [100]; /* XXX */
3098 /* Generate the DISPOSE instruction. Note we could just issue the
3099 bit mask as a number as the assembler can cope with this, but for
3100 the sake of our readers we turn it into a textual description. */
3104 for (i = 20; i < 32; i++)
3106 if (mask & (1 << i))
3111 strcat (regs, ", ");
3116 strcat (regs, reg_names[ first ]);
3118 for (i++; i < 32; i++)
3119 if ((mask & (1 << i)) == 0)
3124 strcat (regs, " - ");
3125 strcat (regs, reg_names[ i - 1 ] );
3130 sprintf (buff, "dispose %d {%s}, r31", stack_bytes / 4, regs);
3136 /* Return nonzero if the given RTX is suitable
3137 for collapsing into a PREPARE instruction. */
3140 pattern_is_ok_for_prepare (op, mode)
3142 enum machine_mode mode ATTRIBUTE_UNUSED;
3144 int count = XVECLEN (op, 0);
3147 /* If there are no registers to restore then the prepare instruction
3152 /* The pattern matching has already established that we are adjusting the
3153 stack and pushing at least one register. We must now check that the
3154 remaining entries in the vector to make sure that they are also register
3157 The test below performs the C equivalent of this machine description
3160 (set (mem:SI (plus:SI (reg:SI 3)
3161 (match_operand:SI 2 "immediate_operand" "i")))
3162 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
3166 for (i = 2; i < count; i++)
3168 rtx vector_element = XVECEXP (op, 0, i);
3173 if (GET_CODE (vector_element) != SET)
3176 dest = SET_DEST (vector_element);
3177 src = SET_SRC (vector_element);
3179 if ( GET_CODE (dest) != MEM
3180 || GET_MODE (dest) != SImode
3181 || GET_CODE (src) != REG
3182 || GET_MODE (src) != SImode
3183 || ! register_is_ok_for_epilogue (src, SImode)
3187 plus = XEXP (dest, 0);
3189 if ( GET_CODE (plus) != PLUS
3190 || GET_CODE (XEXP (plus, 0)) != REG
3191 || GET_MODE (XEXP (plus, 0)) != SImode
3192 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
3193 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
3196 /* If the register is being pushed somewhere other than the stack
3197 space just aquired by the first operand then abandon this quest.
3198 Note: the test is <= becuase both values are negative. */
3199 if (INTVAL (XEXP (plus, 1))
3200 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
3207 /* Construct a PREPARE instruction that is the equivalent of
3208 the given RTL. We have already verified that this should
3212 construct_prepare_instruction (op)
3215 int count = XVECLEN (op, 0);
3217 unsigned long int mask;
3219 static char buff[ 100 ]; /* XXX */
3224 error ("Bogus PREPEARE construction: %d\n", count);
3228 /* Work out how many bytes to push onto
3229 the stack after storing the registers. */
3230 if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
3232 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
3234 if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
3237 stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
3239 /* Each push will put 4 bytes from the stack. */
3240 stack_bytes += (count - 1) * 4;
3242 /* Make sure that the amount we are popping
3243 will fit into the DISPOSE instruction. */
3244 if (stack_bytes < -128)
3246 error ("Too much stack space to prepare: %d", stack_bytes);
3250 /* Now compute the bit mask of registers to push. */
3252 for (i = 1; i < count; i++)
3254 rtx vector_element = XVECEXP (op, 0, i);
3256 if (GET_CODE (vector_element) != SET)
3258 if (GET_CODE (SET_SRC (vector_element)) != REG)
3260 if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
3263 if (REGNO (SET_SRC (vector_element)) == 2)
3266 mask |= 1 << REGNO (SET_SRC (vector_element));
3269 if ((! TARGET_DISABLE_CALLT)
3270 && (use_callt || stack_bytes == 0 || stack_bytes == -16))
3274 sprintf (buff, "callt ctoff(__callt_save_r2_r%d)", (mask & (1 << 31)) ? 31 : 29 );
3278 for (i = 20; i < 32; i++)
3279 if (mask & (1 << i))
3283 sprintf (buff, "callt ctoff(__callt_save_r31c)");
3285 sprintf (buff, "callt ctoff(__callt_save_r%d_r%d%s)",
3286 i, (mask & (1 << 31)) ? 31 : 29, stack_bytes ? "c" : "");
3290 static char regs [100]; /* XXX */
3294 /* Generate the PREPARE instruction. Note we could just issue the
3295 bit mask as a number as the assembler can cope with this, but for
3296 the sake of our readers we turn it into a textual description. */
3300 for (i = 20; i < 32; i++)
3302 if (mask & (1 << i))
3307 strcat (regs, ", ");
3312 strcat (regs, reg_names[ first ]);
3314 for (i++; i < 32; i++)
3315 if ((mask & (1 << i)) == 0)
3320 strcat (regs, " - ");
3321 strcat (regs, reg_names[ i - 1 ] );
3326 sprintf (buff, "prepare {%s}, %d", regs, (- stack_bytes) / 4);
3332 /* Implement `va_arg'. */
3335 v850_va_arg (valist, type)
3338 HOST_WIDE_INT size, rsize;
3343 /* Round up sizeof(type) to a word. */
3344 size = int_size_in_bytes (type);
3345 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
3350 size = rsize = UNITS_PER_WORD;
3354 addr = save_expr (valist);
3355 incr = fold (build (PLUS_EXPR, ptr_type_node, addr,
3356 build_int_2 (rsize, 0)));
3358 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
3359 TREE_SIDE_EFFECTS (incr) = 1;
3360 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
3362 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
3366 addr_rtx = force_reg (Pmode, addr_rtx);
3367 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
3368 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
3374 /* Return an RTX indicating where the return address to the
3375 calling function can be found. */
3378 v850_return_addr (count)
3384 return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
3388 v850_select_section (exp, reloc, align)
3390 int reloc ATTRIBUTE_UNUSED;
3391 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
3393 if (TREE_CODE (exp) == VAR_DECL)
3396 if (!TREE_READONLY (exp)
3397 || TREE_SIDE_EFFECTS (exp)
3398 || !DECL_INITIAL (exp)
3399 || (DECL_INITIAL (exp) != error_mark_node
3400 && !TREE_CONSTANT (DECL_INITIAL (exp))))
3405 switch (v850_get_data_area (exp))
3427 readonly_data_section ();
3433 else if (TREE_CODE (exp) == STRING_CST)
3435 if (! flag_writable_strings)
3436 readonly_data_section ();
3441 readonly_data_section ();