1 /* Subroutines for insn-output.c for Tensilica's Xtensa architecture.
2 Copyright 2001,2002,2003 Free Software Foundation, Inc.
3 Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
34 #include "insn-attr.h"
35 #include "insn-codes.h"
49 #include "target-def.h"
50 #include "langhooks.h"
52 /* Enumeration for all of the relational tests, so that we can build
53 arrays indexed by the test type, and not worry about the order
70 /* Cached operands, and operator to compare for use in set/branch on
74 /* what type of branch to use */
75 enum cmp_type branch_type;
77 /* Array giving truth value on whether or not a given hard register
78 can support a given mode. */
79 char xtensa_hard_regno_mode_ok[(int) MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
81 /* Current frame size calculated by compute_frame_size. */
82 unsigned xtensa_current_frame_size;
84 /* Tables of ld/st opcode names for block moves */
85 const char *xtensa_ld_opcodes[(int) MAX_MACHINE_MODE];
86 const char *xtensa_st_opcodes[(int) MAX_MACHINE_MODE];
87 #define LARGEST_MOVE_RATIO 15
89 /* Define the structure for the machine field in struct function. */
90 struct machine_function GTY(())
92 int accesses_prev_frame;
93 bool incoming_a7_copied;
96 /* Vector, indexed by hard register number, which contains 1 for a
97 register that is allowable in a candidate for leaf function
100 const char xtensa_leaf_regs[FIRST_PSEUDO_REGISTER] =
102 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
104 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
108 /* Map hard register number to register class */
109 const enum reg_class xtensa_regno_to_class[FIRST_PSEUDO_REGISTER] =
111 RL_REGS, SP_REG, RL_REGS, RL_REGS,
112 RL_REGS, RL_REGS, RL_REGS, GR_REGS,
113 RL_REGS, RL_REGS, RL_REGS, RL_REGS,
114 RL_REGS, RL_REGS, RL_REGS, RL_REGS,
115 AR_REGS, AR_REGS, BR_REGS,
116 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
117 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
118 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
119 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
123 /* Map register constraint character to register class. */
124 enum reg_class xtensa_char_to_class[256] =
126 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
127 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
128 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
129 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
130 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
131 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
132 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
133 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
134 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
135 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
136 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
137 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
138 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
139 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
140 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
141 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
142 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
143 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
144 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
145 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
146 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
147 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
148 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
149 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
150 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
151 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
152 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
153 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
154 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
155 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
156 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
157 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
158 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
159 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
160 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
161 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
162 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
163 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
164 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
165 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
166 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
167 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
168 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
169 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
170 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
171 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
172 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
173 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
174 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
175 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
176 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
177 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
178 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
179 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
180 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
181 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
182 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
183 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
184 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
185 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
186 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
187 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
188 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
189 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
192 static int b4const_or_zero PARAMS ((int));
193 static enum internal_test map_test_to_internal_test PARAMS ((enum rtx_code));
194 static rtx gen_int_relational PARAMS ((enum rtx_code, rtx, rtx, int *));
195 static rtx gen_float_relational PARAMS ((enum rtx_code, rtx, rtx));
196 static rtx gen_conditional_move PARAMS ((rtx));
197 static rtx fixup_subreg_mem PARAMS ((rtx x));
198 static enum machine_mode xtensa_find_mode_for_size PARAMS ((unsigned));
199 static struct machine_function * xtensa_init_machine_status PARAMS ((void));
200 static void printx PARAMS ((FILE *, signed int));
201 static void xtensa_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
202 static unsigned int xtensa_multibss_section_type_flags
203 PARAMS ((tree, const char *, int));
204 static void xtensa_select_rtx_section
205 PARAMS ((enum machine_mode, rtx, unsigned HOST_WIDE_INT));
206 static bool xtensa_rtx_costs PARAMS ((rtx, int, int, int *));
208 static int current_function_arg_words;
209 static const int reg_nonleaf_alloc_order[FIRST_PSEUDO_REGISTER] =
213 /* This macro generates the assembly code for function exit,
214 on machines that need it. If FUNCTION_EPILOGUE is not defined
215 then individual return instructions are generated for each
216 return statement. Args are same as for FUNCTION_PROLOGUE. */
218 #undef TARGET_ASM_FUNCTION_EPILOGUE
219 #define TARGET_ASM_FUNCTION_EPILOGUE xtensa_function_epilogue
221 /* These hooks specify assembly directives for creating certain kinds
222 of integer object. */
224 #undef TARGET_ASM_ALIGNED_SI_OP
225 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
227 #undef TARGET_ASM_SELECT_RTX_SECTION
228 #define TARGET_ASM_SELECT_RTX_SECTION xtensa_select_rtx_section
230 #undef TARGET_RTX_COSTS
231 #define TARGET_RTX_COSTS xtensa_rtx_costs
232 #undef TARGET_ADDRESS_COST
233 #define TARGET_ADDRESS_COST hook_int_rtx_0
235 struct gcc_target targetm = TARGET_INITIALIZER;
239 * Functions to test Xtensa immediate operand validity.
273 return (v & 255) == 0 && (v >= -32768 && v <= 32512);
280 return (v == -1 || (v >= 1 && v <= 15));
287 return v >= -32 && v <= 95;
321 return v >= -128 && v <= 127;
328 return (v >= 7 && v <= 22);
335 return (v & 3) == 0 && (v >= 0 && v <= 60);
342 return v >= -2048 && v <= 2047;
349 return v >= 0 && v <= 255;
356 return (v & 1) == 0 && (v >= 0 && v <= 510);
363 return (v & 3) == 0 && (v >= 0 && v <= 1020);
367 /* This is just like the standard true_regnum() function except that it
368 works even when reg_renumber is not initialized. */
374 if (GET_CODE (x) == REG)
377 && REGNO (x) >= FIRST_PSEUDO_REGISTER
378 && reg_renumber[REGNO (x)] >= 0)
379 return reg_renumber[REGNO (x)];
382 if (GET_CODE (x) == SUBREG)
384 int base = xt_true_regnum (SUBREG_REG (x));
385 if (base >= 0 && base < FIRST_PSEUDO_REGISTER)
386 return base + subreg_regno_offset (REGNO (SUBREG_REG (x)),
387 GET_MODE (SUBREG_REG (x)),
388 SUBREG_BYTE (x), GET_MODE (x));
395 add_operand (op, mode)
397 enum machine_mode mode;
399 if (GET_CODE (op) == CONST_INT)
400 return (xtensa_simm8 (INTVAL (op)) || xtensa_simm8x256 (INTVAL (op)));
402 return register_operand (op, mode);
407 arith_operand (op, mode)
409 enum machine_mode mode;
411 if (GET_CODE (op) == CONST_INT)
412 return xtensa_simm8 (INTVAL (op));
414 return register_operand (op, mode);
419 nonimmed_operand (op, mode)
421 enum machine_mode mode;
423 /* We cannot use the standard nonimmediate_operand() predicate because
424 it includes constant pool memory operands. */
426 if (memory_operand (op, mode))
427 return !constantpool_address_p (XEXP (op, 0));
429 return register_operand (op, mode);
434 mem_operand (op, mode)
436 enum machine_mode mode;
438 /* We cannot use the standard memory_operand() predicate because
439 it includes constant pool memory operands. */
441 if (memory_operand (op, mode))
442 return !constantpool_address_p (XEXP (op, 0));
449 xtensa_valid_move (mode, operands)
450 enum machine_mode mode;
453 /* Either the destination or source must be a register, and the
454 MAC16 accumulator doesn't count. */
456 if (register_operand (operands[0], mode))
458 int dst_regnum = xt_true_regnum (operands[0]);
460 /* The stack pointer can only be assigned with a MOVSP opcode. */
461 if (dst_regnum == STACK_POINTER_REGNUM)
462 return (mode == SImode
463 && register_operand (operands[1], mode)
464 && !ACC_REG_P (xt_true_regnum (operands[1])));
466 if (!ACC_REG_P (dst_regnum))
469 if (register_operand (operands[1], mode))
471 int src_regnum = xt_true_regnum (operands[1]);
472 if (!ACC_REG_P (src_regnum))
480 mask_operand (op, mode)
482 enum machine_mode mode;
484 if (GET_CODE (op) == CONST_INT)
485 return xtensa_mask_immediate (INTVAL (op));
487 return register_operand (op, mode);
492 extui_fldsz_operand (op, mode)
494 enum machine_mode mode ATTRIBUTE_UNUSED;
496 return ((GET_CODE (op) == CONST_INT)
497 && xtensa_mask_immediate ((1 << INTVAL (op)) - 1));
502 sext_operand (op, mode)
504 enum machine_mode mode;
507 return nonimmed_operand (op, mode);
508 return mem_operand (op, mode);
513 sext_fldsz_operand (op, mode)
515 enum machine_mode mode ATTRIBUTE_UNUSED;
517 return ((GET_CODE (op) == CONST_INT) && xtensa_tp7 (INTVAL (op) - 1));
522 lsbitnum_operand (op, mode)
524 enum machine_mode mode ATTRIBUTE_UNUSED;
526 if (GET_CODE (op) == CONST_INT)
528 return (BITS_BIG_ENDIAN
529 ? (INTVAL (op) == BITS_PER_WORD-1)
530 : (INTVAL (op) == 0));
542 return xtensa_b4const (v);
547 branch_operand (op, mode)
549 enum machine_mode mode;
551 if (GET_CODE (op) == CONST_INT)
552 return b4const_or_zero (INTVAL (op));
554 return register_operand (op, mode);
559 ubranch_operand (op, mode)
561 enum machine_mode mode;
563 if (GET_CODE (op) == CONST_INT)
564 return xtensa_b4constu (INTVAL (op));
566 return register_operand (op, mode);
571 call_insn_operand (op, mode)
573 enum machine_mode mode ATTRIBUTE_UNUSED;
575 if ((GET_CODE (op) == REG)
576 && (op != arg_pointer_rtx)
577 && ((REGNO (op) < FRAME_POINTER_REGNUM)
578 || (REGNO (op) > LAST_VIRTUAL_REGISTER)))
581 if (CONSTANT_ADDRESS_P (op))
583 /* Direct calls only allowed to static functions with PIC. */
585 || (GET_CODE (op) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (op)));
593 move_operand (op, mode)
595 enum machine_mode mode;
597 if (register_operand (op, mode)
598 || memory_operand (op, mode))
605 return TARGET_CONST16 && CONSTANT_P (op);
610 return CONSTANT_P (op);
615 /* Accept CONSTANT_P_RTX, since it will be gone by CSE1 and
617 if (GET_CODE (op) == CONSTANT_P_RTX)
620 if (GET_CODE (op) == CONST_INT && xtensa_simm12b (INTVAL (op)))
633 smalloffset_mem_p (op)
636 if (GET_CODE (op) == MEM)
638 rtx addr = XEXP (op, 0);
639 if (GET_CODE (addr) == REG)
640 return REG_OK_FOR_BASE_P (addr);
641 if (GET_CODE (addr) == PLUS)
643 rtx offset = XEXP (addr, 0);
644 if (GET_CODE (offset) != CONST_INT)
645 offset = XEXP (addr, 1);
646 if (GET_CODE (offset) != CONST_INT)
648 return xtensa_lsi4x4 (INTVAL (offset));
656 constantpool_address_p (addr)
661 if (GET_CODE (addr) == CONST)
665 /* only handle (PLUS (SYM, OFFSET)) form */
666 addr = XEXP (addr, 0);
667 if (GET_CODE (addr) != PLUS)
670 /* make sure the address is word aligned */
671 offset = XEXP (addr, 1);
672 if ((GET_CODE (offset) != CONST_INT)
673 || ((INTVAL (offset) & 3) != 0))
676 sym = XEXP (addr, 0);
679 if ((GET_CODE (sym) == SYMBOL_REF)
680 && CONSTANT_POOL_ADDRESS_P (sym))
687 constantpool_mem_p (op)
690 if (GET_CODE (op) == MEM)
691 return constantpool_address_p (XEXP (op, 0));
696 /* Accept the floating point constant 1 in the appropriate mode. */
699 const_float_1_operand (op, mode)
701 enum machine_mode mode;
704 static REAL_VALUE_TYPE onedf;
705 static REAL_VALUE_TYPE onesf;
706 static int one_initialized;
708 if ((GET_CODE (op) != CONST_DOUBLE)
709 || (mode != GET_MODE (op))
710 || (mode != DFmode && mode != SFmode))
713 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
715 if (! one_initialized)
717 onedf = REAL_VALUE_ATOF ("1.0", DFmode);
718 onesf = REAL_VALUE_ATOF ("1.0", SFmode);
719 one_initialized = TRUE;
723 return REAL_VALUES_EQUAL (d, onedf);
725 return REAL_VALUES_EQUAL (d, onesf);
730 fpmem_offset_operand (op, mode)
732 enum machine_mode mode ATTRIBUTE_UNUSED;
734 if (GET_CODE (op) == CONST_INT)
735 return xtensa_mem_offset (INTVAL (op), SFmode);
741 xtensa_extend_reg (dst, src)
745 rtx temp = gen_reg_rtx (SImode);
746 rtx shift = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (GET_MODE (src)));
748 /* generate paradoxical subregs as needed so that the modes match */
749 src = simplify_gen_subreg (SImode, src, GET_MODE (src), 0);
750 dst = simplify_gen_subreg (SImode, dst, GET_MODE (dst), 0);
752 emit_insn (gen_ashlsi3 (temp, src, shift));
753 emit_insn (gen_ashrsi3 (dst, temp, shift));
758 branch_operator (x, mode)
760 enum machine_mode mode;
762 if (GET_MODE (x) != mode)
765 switch (GET_CODE (x))
780 ubranch_operator (x, mode)
782 enum machine_mode mode;
784 if (GET_MODE (x) != mode)
787 switch (GET_CODE (x))
800 boolean_operator (x, mode)
802 enum machine_mode mode;
804 if (GET_MODE (x) != mode)
807 switch (GET_CODE (x))
820 xtensa_mask_immediate (v)
823 #define MAX_MASK_SIZE 16
826 for (mask_size = 1; mask_size <= MAX_MASK_SIZE; mask_size++)
840 xtensa_mem_offset (v, mode)
842 enum machine_mode mode;
847 /* Handle the worst case for block moves. See xtensa_expand_block_move
848 where we emit an optimized block move operation if the block can be
849 moved in < "move_ratio" pieces. The worst case is when the block is
850 aligned but has a size of (3 mod 4) (does this happen?) so that the
851 last piece requires a byte load/store. */
852 return (xtensa_uimm8 (v)
853 && xtensa_uimm8 (v + MOVE_MAX * LARGEST_MOVE_RATIO));
856 return xtensa_uimm8 (v);
859 return xtensa_uimm8x2 (v);
862 return (xtensa_uimm8x4 (v) && xtensa_uimm8x4 (v + 4));
868 return xtensa_uimm8x4 (v);
872 /* Make normal rtx_code into something we can index from an array */
874 static enum internal_test
875 map_test_to_internal_test (test_code)
876 enum rtx_code test_code;
878 enum internal_test test = ITEST_MAX;
883 case EQ: test = ITEST_EQ; break;
884 case NE: test = ITEST_NE; break;
885 case GT: test = ITEST_GT; break;
886 case GE: test = ITEST_GE; break;
887 case LT: test = ITEST_LT; break;
888 case LE: test = ITEST_LE; break;
889 case GTU: test = ITEST_GTU; break;
890 case GEU: test = ITEST_GEU; break;
891 case LTU: test = ITEST_LTU; break;
892 case LEU: test = ITEST_LEU; break;
899 /* Generate the code to compare two integer values. The return value is
900 the comparison expression. */
903 gen_int_relational (test_code, cmp0, cmp1, p_invert)
904 enum rtx_code test_code; /* relational test (EQ, etc) */
905 rtx cmp0; /* first operand to compare */
906 rtx cmp1; /* second operand to compare */
907 int *p_invert; /* whether branch needs to reverse its test */
910 enum rtx_code test_code; /* test code to use in insn */
911 int (*const_range_p) PARAMS ((int)); /* predicate function to check range */
912 int const_add; /* constant to add (convert LE -> LT) */
913 int reverse_regs; /* reverse registers in test */
914 int invert_const; /* != 0 if invert value if cmp1 is constant */
915 int invert_reg; /* != 0 if invert value if cmp1 is register */
916 int unsignedp; /* != 0 for unsigned comparisons. */
919 static struct cmp_info info[ (int)ITEST_MAX ] = {
921 { EQ, b4const_or_zero, 0, 0, 0, 0, 0 }, /* EQ */
922 { NE, b4const_or_zero, 0, 0, 0, 0, 0 }, /* NE */
924 { LT, b4const_or_zero, 1, 1, 1, 0, 0 }, /* GT */
925 { GE, b4const_or_zero, 0, 0, 0, 0, 0 }, /* GE */
926 { LT, b4const_or_zero, 0, 0, 0, 0, 0 }, /* LT */
927 { GE, b4const_or_zero, 1, 1, 1, 0, 0 }, /* LE */
929 { LTU, xtensa_b4constu, 1, 1, 1, 0, 1 }, /* GTU */
930 { GEU, xtensa_b4constu, 0, 0, 0, 0, 1 }, /* GEU */
931 { LTU, xtensa_b4constu, 0, 0, 0, 0, 1 }, /* LTU */
932 { GEU, xtensa_b4constu, 1, 1, 1, 0, 1 }, /* LEU */
935 enum internal_test test;
936 enum machine_mode mode;
937 struct cmp_info *p_info;
939 test = map_test_to_internal_test (test_code);
940 if (test == ITEST_MAX)
943 p_info = &info[ (int)test ];
945 mode = GET_MODE (cmp0);
946 if (mode == VOIDmode)
947 mode = GET_MODE (cmp1);
949 /* Make sure we can handle any constants given to us. */
950 if (GET_CODE (cmp1) == CONST_INT)
952 HOST_WIDE_INT value = INTVAL (cmp1);
953 unsigned HOST_WIDE_INT uvalue = (unsigned HOST_WIDE_INT)value;
955 /* if the immediate overflows or does not fit in the immediate field,
956 spill it to a register */
958 if ((p_info->unsignedp ?
959 (uvalue + p_info->const_add > uvalue) :
960 (value + p_info->const_add > value)) != (p_info->const_add > 0))
962 cmp1 = force_reg (mode, cmp1);
964 else if (!(p_info->const_range_p) (value + p_info->const_add))
966 cmp1 = force_reg (mode, cmp1);
969 else if ((GET_CODE (cmp1) != REG) && (GET_CODE (cmp1) != SUBREG))
971 cmp1 = force_reg (mode, cmp1);
974 /* See if we need to invert the result. */
975 *p_invert = ((GET_CODE (cmp1) == CONST_INT)
976 ? p_info->invert_const
977 : p_info->invert_reg);
979 /* Comparison to constants, may involve adding 1 to change a LT into LE.
980 Comparison between two registers, may involve switching operands. */
981 if (GET_CODE (cmp1) == CONST_INT)
983 if (p_info->const_add != 0)
984 cmp1 = GEN_INT (INTVAL (cmp1) + p_info->const_add);
987 else if (p_info->reverse_regs)
994 return gen_rtx (p_info->test_code, VOIDmode, cmp0, cmp1);
998 /* Generate the code to compare two float values. The return value is
999 the comparison expression. */
1002 gen_float_relational (test_code, cmp0, cmp1)
1003 enum rtx_code test_code; /* relational test (EQ, etc) */
1004 rtx cmp0; /* first operand to compare */
1005 rtx cmp1; /* second operand to compare */
1007 rtx (*gen_fn) PARAMS ((rtx, rtx, rtx));
1009 int reverse_regs, invert;
1013 case EQ: reverse_regs = 0; invert = 0; gen_fn = gen_seq_sf; break;
1014 case NE: reverse_regs = 0; invert = 1; gen_fn = gen_seq_sf; break;
1015 case LE: reverse_regs = 0; invert = 0; gen_fn = gen_sle_sf; break;
1016 case GT: reverse_regs = 1; invert = 0; gen_fn = gen_slt_sf; break;
1017 case LT: reverse_regs = 0; invert = 0; gen_fn = gen_slt_sf; break;
1018 case GE: reverse_regs = 1; invert = 0; gen_fn = gen_sle_sf; break;
1020 fatal_insn ("bad test", gen_rtx (test_code, VOIDmode, cmp0, cmp1));
1021 reverse_regs = 0; invert = 0; gen_fn = 0; /* avoid compiler warnings */
1031 brtmp = gen_rtx_REG (CCmode, FPCC_REGNUM);
1032 emit_insn (gen_fn (brtmp, cmp0, cmp1));
1034 return gen_rtx (invert ? EQ : NE, VOIDmode, brtmp, const0_rtx);
1039 xtensa_expand_conditional_branch (operands, test_code)
1041 enum rtx_code test_code;
1043 enum cmp_type type = branch_type;
1044 rtx cmp0 = branch_cmp[0];
1045 rtx cmp1 = branch_cmp[1];
1054 fatal_insn ("bad test", gen_rtx (test_code, VOIDmode, cmp0, cmp1));
1058 cmp = gen_int_relational (test_code, cmp0, cmp1, &invert);
1062 if (!TARGET_HARD_FLOAT)
1063 fatal_insn ("bad test", gen_rtx (test_code, VOIDmode, cmp0, cmp1));
1065 cmp = gen_float_relational (test_code, cmp0, cmp1);
1069 /* Generate the branch. */
1071 label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]);
1080 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
1081 gen_rtx_IF_THEN_ELSE (VOIDmode, cmp,
1088 gen_conditional_move (cmp)
1091 enum rtx_code code = GET_CODE (cmp);
1092 rtx op0 = branch_cmp[0];
1093 rtx op1 = branch_cmp[1];
1095 if (branch_type == CMP_SI)
1097 /* Jump optimization calls get_condition() which canonicalizes
1098 comparisons like (GE x <const>) to (GT x <const-1>).
1099 Transform those comparisons back to GE, since that is the
1100 comparison supported in Xtensa. We shouldn't have to
1101 transform <LE x const> comparisons, because neither
1102 xtensa_expand_conditional_branch() nor get_condition() will
1105 if ((code == GT) && (op1 == constm1_rtx))
1110 cmp = gen_rtx (code, VOIDmode, cc0_rtx, const0_rtx);
1112 if (boolean_operator (cmp, VOIDmode))
1114 /* swap the operands to make const0 second */
1115 if (op0 == const0_rtx)
1121 /* if not comparing against zero, emit a comparison (subtract) */
1122 if (op1 != const0_rtx)
1124 op0 = expand_binop (SImode, sub_optab, op0, op1,
1125 0, 0, OPTAB_LIB_WIDEN);
1129 else if (branch_operator (cmp, VOIDmode))
1131 /* swap the operands to make const0 second */
1132 if (op0 == const0_rtx)
1139 case LT: code = GE; break;
1140 case GE: code = LT; break;
1145 if (op1 != const0_rtx)
1151 return gen_rtx (code, VOIDmode, op0, op1);
1154 if (TARGET_HARD_FLOAT && (branch_type == CMP_SF))
1155 return gen_float_relational (code, op0, op1);
1162 xtensa_expand_conditional_move (operands, isflt)
1167 rtx (*gen_fn) PARAMS ((rtx, rtx, rtx, rtx, rtx));
1169 if (!(cmp = gen_conditional_move (operands[1])))
1173 gen_fn = (branch_type == CMP_SI
1174 ? gen_movsfcc_internal0
1175 : gen_movsfcc_internal1);
1177 gen_fn = (branch_type == CMP_SI
1178 ? gen_movsicc_internal0
1179 : gen_movsicc_internal1);
1181 emit_insn (gen_fn (operands[0], XEXP (cmp, 0),
1182 operands[2], operands[3], cmp));
1188 xtensa_expand_scc (operands)
1191 rtx dest = operands[0];
1192 rtx cmp = operands[1];
1193 rtx one_tmp, zero_tmp;
1194 rtx (*gen_fn) PARAMS ((rtx, rtx, rtx, rtx, rtx));
1196 if (!(cmp = gen_conditional_move (cmp)))
1199 one_tmp = gen_reg_rtx (SImode);
1200 zero_tmp = gen_reg_rtx (SImode);
1201 emit_insn (gen_movsi (one_tmp, const_true_rtx));
1202 emit_insn (gen_movsi (zero_tmp, const0_rtx));
1204 gen_fn = (branch_type == CMP_SI
1205 ? gen_movsicc_internal0
1206 : gen_movsicc_internal1);
1207 emit_insn (gen_fn (dest, XEXP (cmp, 0), one_tmp, zero_tmp, cmp));
1212 /* Split OP[1] into OP[2,3] and likewise for OP[0] into OP[0,1]. MODE is
1213 for the output, i.e., the input operands are twice as big as MODE. */
1216 xtensa_split_operand_pair (operands, mode)
1218 enum machine_mode mode;
1220 switch (GET_CODE (operands[1]))
1223 operands[3] = gen_rtx_REG (mode, REGNO (operands[1]) + 1);
1224 operands[2] = gen_rtx_REG (mode, REGNO (operands[1]));
1228 operands[3] = adjust_address (operands[1], mode, GET_MODE_SIZE (mode));
1229 operands[2] = adjust_address (operands[1], mode, 0);
1234 split_double (operands[1], &operands[2], &operands[3]);
1241 switch (GET_CODE (operands[0]))
1244 operands[1] = gen_rtx_REG (mode, REGNO (operands[0]) + 1);
1245 operands[0] = gen_rtx_REG (mode, REGNO (operands[0]));
1249 operands[1] = adjust_address (operands[0], mode, GET_MODE_SIZE (mode));
1250 operands[0] = adjust_address (operands[0], mode, 0);
1259 /* Emit insns to move operands[1] into operands[0].
1260 Return 1 if we have written out everything that needs to be done to
1261 do the move. Otherwise, return 0 and the caller will emit the move
1265 xtensa_emit_move_sequence (operands, mode)
1267 enum machine_mode mode;
1269 if (CONSTANT_P (operands[1])
1270 && GET_CODE (operands[1]) != CONSTANT_P_RTX
1271 && (GET_CODE (operands[1]) != CONST_INT
1272 || !xtensa_simm12b (INTVAL (operands[1]))))
1274 if (!TARGET_CONST16)
1275 operands[1] = force_const_mem (SImode, operands[1]);
1277 /* PC-relative loads are always SImode, and CONST16 is only
1278 supported in the movsi pattern, so add a SUBREG for any other
1283 if (register_operand (operands[0], mode))
1285 operands[0] = simplify_gen_subreg (SImode, operands[0], mode, 0);
1286 emit_move_insn (operands[0], operands[1]);
1291 operands[1] = force_reg (SImode, operands[1]);
1292 operands[1] = gen_lowpart_SUBREG (mode, operands[1]);
1297 if (!(reload_in_progress | reload_completed))
1299 if (!xtensa_valid_move (mode, operands))
1300 operands[1] = force_reg (mode, operands[1]);
1302 if (xtensa_copy_incoming_a7 (operands, mode))
1306 /* During reload we don't want to emit (subreg:X (mem:Y)) since that
1307 instruction won't be recognized after reload, so we remove the
1308 subreg and adjust mem accordingly. */
1309 if (reload_in_progress)
1311 operands[0] = fixup_subreg_mem (operands[0]);
1312 operands[1] = fixup_subreg_mem (operands[1]);
1319 fixup_subreg_mem (x)
1322 if (GET_CODE (x) == SUBREG
1323 && GET_CODE (SUBREG_REG (x)) == REG
1324 && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)
1327 gen_rtx_SUBREG (GET_MODE (x),
1328 reg_equiv_mem [REGNO (SUBREG_REG (x))],
1330 x = alter_subreg (&temp);
1336 /* Check if this move is copying an incoming argument in a7. If so,
1337 emit the move, followed by the special "set_frame_ptr"
1338 unspec_volatile insn, at the very beginning of the function. This
1339 is necessary because the register allocator will ignore conflicts
1340 with a7 and may assign some other pseudo to a7. If that pseudo was
1341 assigned prior to this move, it would clobber the incoming argument
1342 in a7. By copying the argument out of a7 as the very first thing,
1343 and then immediately following that with an unspec_volatile to keep
1344 the scheduler away, we should avoid any problems. */
1347 xtensa_copy_incoming_a7 (operands, mode)
1349 enum machine_mode mode;
1351 if (a7_overlap_mentioned_p (operands[1])
1352 && !cfun->machine->incoming_a7_copied)
1358 mov = gen_movdf_internal (operands[0], operands[1]);
1361 mov = gen_movsf_internal (operands[0], operands[1]);
1364 mov = gen_movdi_internal (operands[0], operands[1]);
1367 mov = gen_movsi_internal (operands[0], operands[1]);
1370 mov = gen_movhi_internal (operands[0], operands[1]);
1373 mov = gen_movqi_internal (operands[0], operands[1]);
1379 /* Insert the instructions before any other argument copies.
1380 (The set_frame_ptr insn comes _after_ the move, so push it
1382 push_topmost_sequence ();
1383 emit_insn_after (gen_set_frame_ptr (), get_insns ());
1384 emit_insn_after (mov, get_insns ());
1385 pop_topmost_sequence ();
1387 /* Ideally the incoming argument in a7 would only be copied
1388 once, since propagating a7 into the body of a function
1389 will almost certainly lead to errors. However, there is
1390 at least one harmless case (in GCSE) where the original
1391 copy from a7 is changed to copy into a new pseudo. Thus,
1392 we use a flag to only do this special treatment for the
1393 first copy of a7. */
1395 cfun->machine->incoming_a7_copied = true;
1404 /* Try to expand a block move operation to an RTL block move instruction.
1405 If not optimizing or if the block size is not a constant or if the
1406 block is small, the expansion fails and GCC falls back to calling
1409 operands[0] is the destination
1410 operands[1] is the source
1411 operands[2] is the length
1412 operands[3] is the alignment */
1415 xtensa_expand_block_move (operands)
1418 rtx dest = operands[0];
1419 rtx src = operands[1];
1420 int bytes = INTVAL (operands[2]);
1421 int align = XINT (operands[3], 0);
1422 int num_pieces, move_ratio;
1424 /* If this is not a fixed size move, just call memcpy */
1425 if (!optimize || (GET_CODE (operands[2]) != CONST_INT))
1428 /* Anything to move? */
1432 if (align > MOVE_MAX)
1435 /* decide whether to expand inline based on the optimization level */
1438 move_ratio = LARGEST_MOVE_RATIO;
1439 num_pieces = (bytes / align) + (bytes % align); /* close enough anyway */
1440 if (num_pieces >= move_ratio)
1443 /* make sure the memory addresses are valid */
1444 operands[0] = validize_mem (dest);
1445 operands[1] = validize_mem (src);
1447 emit_insn (gen_movstrsi_internal (operands[0], operands[1],
1448 operands[2], operands[3]));
1453 /* Emit a sequence of instructions to implement a block move, trying
1454 to hide load delay slots as much as possible. Load N values into
1455 temporary registers, store those N values, and repeat until the
1456 complete block has been moved. N=delay_slots+1 */
1464 xtensa_emit_block_move (operands, tmpregs, delay_slots)
1469 rtx dest = operands[0];
1470 rtx src = operands[1];
1471 int bytes = INTVAL (operands[2]);
1472 int align = XINT (operands[3], 0);
1473 rtx from_addr = XEXP (src, 0);
1474 rtx to_addr = XEXP (dest, 0);
1475 int from_struct = MEM_IN_STRUCT_P (src);
1476 int to_struct = MEM_IN_STRUCT_P (dest);
1478 int chunk_size, item_size;
1479 struct meminsnbuf *ldinsns, *stinsns;
1480 const char *ldname, *stname;
1481 enum machine_mode mode;
1483 if (align > MOVE_MAX)
1486 chunk_size = delay_slots + 1;
1488 ldinsns = (struct meminsnbuf *)
1489 alloca (chunk_size * sizeof (struct meminsnbuf));
1490 stinsns = (struct meminsnbuf *)
1491 alloca (chunk_size * sizeof (struct meminsnbuf));
1493 mode = xtensa_find_mode_for_size (item_size);
1494 item_size = GET_MODE_SIZE (mode);
1495 ldname = xtensa_ld_opcodes[(int) mode];
1496 stname = xtensa_st_opcodes[(int) mode];
1502 for (n = 0; n < chunk_size; n++)
1512 if (bytes < item_size)
1514 /* find a smaller item_size which we can load & store */
1516 mode = xtensa_find_mode_for_size (item_size);
1517 item_size = GET_MODE_SIZE (mode);
1518 ldname = xtensa_ld_opcodes[(int) mode];
1519 stname = xtensa_st_opcodes[(int) mode];
1522 /* record the load instruction opcode and operands */
1523 addr = plus_constant (from_addr, offset);
1524 mem = gen_rtx_MEM (mode, addr);
1525 if (! memory_address_p (mode, addr))
1527 MEM_IN_STRUCT_P (mem) = from_struct;
1528 ldinsns[n].operands[0] = tmpregs[n];
1529 ldinsns[n].operands[1] = mem;
1530 sprintf (ldinsns[n].template, "%s\t%%0, %%1", ldname);
1532 /* record the store instruction opcode and operands */
1533 addr = plus_constant (to_addr, offset);
1534 mem = gen_rtx_MEM (mode, addr);
1535 if (! memory_address_p (mode, addr))
1537 MEM_IN_STRUCT_P (mem) = to_struct;
1538 stinsns[n].operands[0] = tmpregs[n];
1539 stinsns[n].operands[1] = mem;
1540 sprintf (stinsns[n].template, "%s\t%%0, %%1", stname);
1542 offset += item_size;
1546 /* now output the loads followed by the stores */
1547 for (n = 0; n < chunk_size; n++)
1548 output_asm_insn (ldinsns[n].template, ldinsns[n].operands);
1549 for (n = 0; n < chunk_size; n++)
1550 output_asm_insn (stinsns[n].template, stinsns[n].operands);
1555 static enum machine_mode
1556 xtensa_find_mode_for_size (item_size)
1559 enum machine_mode mode, tmode;
1565 /* find mode closest to but not bigger than item_size */
1566 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1567 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1568 if (GET_MODE_SIZE (tmode) <= item_size)
1570 if (mode == VOIDmode)
1573 item_size = GET_MODE_SIZE (mode);
1575 if (xtensa_ld_opcodes[(int) mode]
1576 && xtensa_st_opcodes[(int) mode])
1579 /* cannot load & store this mode; try something smaller */
1588 xtensa_expand_nonlocal_goto (operands)
1591 rtx goto_handler = operands[1];
1592 rtx containing_fp = operands[3];
1594 /* generate a call to "__xtensa_nonlocal_goto" (in libgcc); the code
1595 is too big to generate in-line */
1597 if (GET_CODE (containing_fp) != REG)
1598 containing_fp = force_reg (Pmode, containing_fp);
1600 goto_handler = replace_rtx (copy_rtx (goto_handler),
1601 virtual_stack_vars_rtx,
1604 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__xtensa_nonlocal_goto"),
1606 containing_fp, Pmode,
1607 goto_handler, Pmode);
1611 static struct machine_function *
1612 xtensa_init_machine_status ()
1614 return ggc_alloc_cleared (sizeof (struct machine_function));
1619 xtensa_setup_frame_addresses ()
1621 /* Set flag to cause FRAME_POINTER_REQUIRED to be set. */
1622 cfun->machine->accesses_prev_frame = 1;
1625 (gen_rtx_SYMBOL_REF (Pmode, "__xtensa_libgcc_window_spill"),
1630 /* Emit the assembly for the end of a zero-cost loop. Normally we just emit
1631 a comment showing where the end of the loop is. However, if there is a
1632 label or a branch at the end of the loop then we need to place a nop
1633 there. If the loop ends with a label we need the nop so that branches
1634 targetting that label will target the nop (and thus remain in the loop),
1635 instead of targetting the instruction after the loop (and thus exiting
1636 the loop). If the loop ends with a branch, we need the nop in case the
1637 branch is targetting a location inside the loop. When the branch
1638 executes it will cause the loop count to be decremented even if it is
1639 taken (because it is the last instruction in the loop), so we need to
1640 nop after the branch to prevent the loop count from being decremented
1641 when the branch is taken. */
1644 xtensa_emit_loop_end (insn, operands)
1650 for (insn = PREV_INSN (insn); insn && !done; insn = PREV_INSN (insn))
1652 switch (GET_CODE (insn))
1659 output_asm_insn (TARGET_DENSITY ? "nop.n" : "nop", operands);
1665 rtx body = PATTERN (insn);
1667 if (GET_CODE (body) == JUMP_INSN)
1669 output_asm_insn (TARGET_DENSITY ? "nop.n" : "nop", operands);
1672 else if ((GET_CODE (body) != USE)
1673 && (GET_CODE (body) != CLOBBER))
1680 output_asm_insn ("# loop end for %0", operands);
1685 xtensa_emit_call (callop, operands)
1689 static char result[64];
1690 rtx tgt = operands[callop];
1692 if (GET_CODE (tgt) == CONST_INT)
1693 sprintf (result, "call8\t0x%lx", INTVAL (tgt));
1694 else if (register_operand (tgt, VOIDmode))
1695 sprintf (result, "callx8\t%%%d", callop);
1697 sprintf (result, "call8\t%%%d", callop);
1703 /* Return the stabs register number to use for 'regno'. */
1706 xtensa_dbx_register_number (regno)
1711 if (GP_REG_P (regno))
1713 regno -= GP_REG_FIRST;
1716 else if (BR_REG_P (regno))
1718 regno -= BR_REG_FIRST;
1721 else if (FP_REG_P (regno))
1723 regno -= FP_REG_FIRST;
1724 /* The current numbering convention is that TIE registers are
1725 numbered in libcc order beginning with 256. We can't guarantee
1726 that the FP registers will come first, so the following is just
1727 a guess. It seems like we should make a special case for FP
1728 registers and give them fixed numbers < 256. */
1731 else if (ACC_REG_P (regno))
1737 /* When optimizing, we sometimes get asked about pseudo-registers
1738 that don't represent hard registers. Return 0 for these. */
1742 return first + regno;
1746 /* Argument support functions. */
1748 /* Initialize CUMULATIVE_ARGS for a function. */
1751 init_cumulative_args (cum, fntype, libname)
1752 CUMULATIVE_ARGS *cum; /* argument info to initialize */
1753 tree fntype ATTRIBUTE_UNUSED; /* tree ptr for function decl */
1754 rtx libname ATTRIBUTE_UNUSED; /* SYMBOL_REF of library name or 0 */
1759 /* Advance the argument to the next argument position. */
1762 function_arg_advance (cum, mode, type)
1763 CUMULATIVE_ARGS *cum; /* current arg information */
1764 enum machine_mode mode; /* current arg mode */
1765 tree type; /* type of the argument or 0 if lib support */
1770 arg_words = &cum->arg_words;
1771 max = MAX_ARGS_IN_REGISTERS;
1773 words = (((mode != BLKmode)
1774 ? (int) GET_MODE_SIZE (mode)
1775 : int_size_in_bytes (type)) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1777 if ((*arg_words + words > max) && (*arg_words < max))
1780 *arg_words += words;
1784 /* Return an RTL expression containing the register for the given mode,
1785 or 0 if the argument is to be passed on the stack. */
1788 function_arg (cum, mode, type, incoming_p)
1789 CUMULATIVE_ARGS *cum; /* current arg information */
1790 enum machine_mode mode; /* current arg mode */
1791 tree type; /* type of the argument or 0 if lib support */
1792 int incoming_p; /* computing the incoming registers? */
1794 int regbase, words, max;
1797 enum machine_mode result_mode;
1799 arg_words = &cum->arg_words;
1800 regbase = (incoming_p ? GP_ARG_FIRST : GP_OUTGOING_ARG_FIRST);
1801 max = MAX_ARGS_IN_REGISTERS;
1803 words = (((mode != BLKmode)
1804 ? (int) GET_MODE_SIZE (mode)
1805 : int_size_in_bytes (type)) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1807 if (type && (TYPE_ALIGN (type) > BITS_PER_WORD))
1808 *arg_words += (*arg_words & 1);
1810 if (*arg_words + words > max)
1813 regno = regbase + *arg_words;
1814 result_mode = (mode == BLKmode ? TYPE_MODE (type) : mode);
1816 /* We need to make sure that references to a7 are represented with
1817 rtx that is not equal to hard_frame_pointer_rtx. For BLKmode and
1818 modes bigger than 2 words (because we only have patterns for
1819 modes of 2 words or smaller), we can't control the expansion
1820 unless we explicitly list the individual registers in a PARALLEL. */
1822 if ((mode == BLKmode || words > 2)
1824 && regno + words > A7_REG)
1829 result = gen_rtx_PARALLEL (result_mode, rtvec_alloc (words));
1830 for (n = 0; n < words; n++)
1832 XVECEXP (result, 0, n) =
1833 gen_rtx_EXPR_LIST (VOIDmode,
1834 gen_raw_REG (SImode, regno + n),
1835 GEN_INT (n * UNITS_PER_WORD));
1840 return gen_raw_REG (result_mode, regno);
1848 enum machine_mode mode;
1850 if (!TARGET_BOOLEANS && TARGET_HARD_FLOAT)
1851 error ("boolean registers required for the floating-point option");
1853 /* set up the tables of ld/st opcode names for block moves */
1854 xtensa_ld_opcodes[(int) SImode] = "l32i";
1855 xtensa_ld_opcodes[(int) HImode] = "l16ui";
1856 xtensa_ld_opcodes[(int) QImode] = "l8ui";
1857 xtensa_st_opcodes[(int) SImode] = "s32i";
1858 xtensa_st_opcodes[(int) HImode] = "s16i";
1859 xtensa_st_opcodes[(int) QImode] = "s8i";
1861 xtensa_char_to_class['q'] = SP_REG;
1862 xtensa_char_to_class['a'] = GR_REGS;
1863 xtensa_char_to_class['b'] = ((TARGET_BOOLEANS) ? BR_REGS : NO_REGS);
1864 xtensa_char_to_class['f'] = ((TARGET_HARD_FLOAT) ? FP_REGS : NO_REGS);
1865 xtensa_char_to_class['A'] = ((TARGET_MAC16) ? ACC_REG : NO_REGS);
1866 xtensa_char_to_class['B'] = ((TARGET_SEXT) ? GR_REGS : NO_REGS);
1867 xtensa_char_to_class['C'] = ((TARGET_MUL16) ? GR_REGS: NO_REGS);
1868 xtensa_char_to_class['D'] = ((TARGET_DENSITY) ? GR_REGS: NO_REGS);
1869 xtensa_char_to_class['d'] = ((TARGET_DENSITY) ? AR_REGS: NO_REGS);
1870 xtensa_char_to_class['W'] = ((TARGET_CONST16) ? GR_REGS: NO_REGS);
1872 /* Set up array giving whether a given register can hold a given mode. */
1873 for (mode = VOIDmode;
1874 mode != MAX_MACHINE_MODE;
1875 mode = (enum machine_mode) ((int) mode + 1))
1877 int size = GET_MODE_SIZE (mode);
1878 enum mode_class class = GET_MODE_CLASS (mode);
1880 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1884 if (ACC_REG_P (regno))
1885 temp = (TARGET_MAC16
1886 && (class == MODE_INT) && (size <= UNITS_PER_WORD));
1887 else if (GP_REG_P (regno))
1888 temp = ((regno & 1) == 0 || (size <= UNITS_PER_WORD));
1889 else if (FP_REG_P (regno))
1890 temp = (TARGET_HARD_FLOAT && (mode == SFmode));
1891 else if (BR_REG_P (regno))
1892 temp = (TARGET_BOOLEANS && (mode == CCmode));
1896 xtensa_hard_regno_mode_ok[(int) mode][regno] = temp;
1900 init_machine_status = xtensa_init_machine_status;
1902 /* Check PIC settings. PIC is only supported when using L32R
1903 instructions, and some targets need to always use PIC. */
1904 if (flag_pic && TARGET_CONST16)
1905 error ("-f%s is not supported with CONST16 instructions",
1906 (flag_pic > 1 ? "PIC" : "pic"));
1907 else if (XTENSA_ALWAYS_PIC)
1910 error ("PIC is required but not supported with CONST16 instructions");
1913 /* There's no need for -fPIC (as opposed to -fpic) on Xtensa. */
1919 /* A C compound statement to output to stdio stream STREAM the
1920 assembler syntax for an instruction operand X. X is an RTL
1923 CODE is a value that can be used to specify one of several ways
1924 of printing the operand. It is used when identical operands
1925 must be printed differently depending on the context. CODE
1926 comes from the '%' specification that was used to request
1927 printing of the operand. If the specification was just '%DIGIT'
1928 then CODE is 0; if the specification was '%LTR DIGIT' then CODE
1929 is the ASCII code for LTR.
1931 If X is a register, this macro should print the register's name.
1932 The names can be found in an array 'reg_names' whose type is
1933 'char *[]'. 'reg_names' is initialized from 'REGISTER_NAMES'.
1935 When the machine description has a specification '%PUNCT' (a '%'
1936 followed by a punctuation character), this macro is called with
1937 a null pointer for X and the punctuation character for CODE.
1939 'a', 'c', 'l', and 'n' are reserved.
1941 The Xtensa specific codes are:
1943 'd' CONST_INT, print as signed decimal
1944 'x' CONST_INT, print as signed hexadecimal
1945 'K' CONST_INT, print number of bits in mask for EXTUI
1946 'R' CONST_INT, print (X & 0x1f)
1947 'L' CONST_INT, print ((32 - X) & 0x1f)
1948 'D' REG, print second register of double-word register operand
1949 'N' MEM, print address of next word following a memory operand
1950 'v' MEM, if memory reference is volatile, output a MEMW before it
1951 't' any constant, add "@h" suffix for top 16 bits
1952 'b' any constant, add "@l" suffix for bottom 16 bits
1960 /* print a hexadecimal value in a nice way */
1961 if ((val > -0xa) && (val < 0xa))
1962 fprintf (file, "%d", val);
1964 fprintf (file, "-0x%x", -val);
1966 fprintf (file, "0x%x", val);
1971 print_operand (file, x, letter)
1972 FILE *file; /* file to write to */
1973 rtx x; /* operand to print */
1974 int letter; /* %<letter> or 0 */
1977 error ("PRINT_OPERAND null pointer");
1982 if (GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
1983 fprintf (file, "%s", reg_names[xt_true_regnum (x) + 1]);
1985 output_operand_lossage ("invalid %%D value");
1989 if (GET_CODE (x) == MEM)
1991 /* For a volatile memory reference, emit a MEMW before the
1993 if (MEM_VOLATILE_P (x))
1994 fprintf (file, "memw\n\t");
1997 output_operand_lossage ("invalid %%v value");
2001 if (GET_CODE (x) == MEM
2002 && (GET_MODE (x) == DFmode || GET_MODE (x) == DImode))
2004 x = adjust_address (x, GET_MODE (x) == DFmode ? SFmode : SImode, 4);
2005 output_address (XEXP (x, 0));
2008 output_operand_lossage ("invalid %%N value");
2012 if (GET_CODE (x) == CONST_INT)
2015 unsigned val = INTVAL (x);
2021 if ((val != 0) || (num_bits == 0) || (num_bits > 16))
2022 fatal_insn ("invalid mask", x);
2024 fprintf (file, "%d", num_bits);
2027 output_operand_lossage ("invalid %%K value");
2031 if (GET_CODE (x) == CONST_INT)
2032 fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
2034 output_operand_lossage ("invalid %%L value");
2038 if (GET_CODE (x) == CONST_INT)
2039 fprintf (file, "%ld", INTVAL (x) & 0x1f);
2041 output_operand_lossage ("invalid %%R value");
2045 if (GET_CODE (x) == CONST_INT)
2046 printx (file, INTVAL (x));
2048 output_operand_lossage ("invalid %%x value");
2052 if (GET_CODE (x) == CONST_INT)
2053 fprintf (file, "%ld", INTVAL (x));
2055 output_operand_lossage ("invalid %%d value");
2060 if (GET_CODE (x) == CONST_INT)
2062 printx (file, INTVAL (x));
2063 fputs (letter == 't' ? "@h" : "@l", file);
2065 else if (GET_CODE (x) == CONST_DOUBLE)
2068 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2069 if (GET_MODE (x) == SFmode)
2072 REAL_VALUE_TO_TARGET_SINGLE (r, l);
2073 fprintf (file, "0x%08lx@%c", l, letter == 't' ? 'h' : 'l');
2076 output_operand_lossage ("invalid %%t/%%b value");
2078 else if (GET_CODE (x) == CONST)
2080 /* X must be a symbolic constant on ELF. Write an expression
2081 suitable for 'const16' that sets the high or low 16 bits. */
2082 if (GET_CODE (XEXP (x, 0)) != PLUS
2083 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
2084 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
2085 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
2086 output_operand_lossage ("invalid %%t/%%b value");
2087 print_operand (file, XEXP (XEXP (x, 0), 0), 0);
2088 fputs (letter == 't' ? "@h" : "@l", file);
2089 /* There must be a non-alphanumeric character between 'h' or 'l'
2090 and the number. The '-' is added by print_operand() already. */
2091 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
2093 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
2097 output_addr_const (file, x);
2098 fputs (letter == 't' ? "@h" : "@l", file);
2103 if (GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2104 fprintf (file, "%s", reg_names[xt_true_regnum (x)]);
2105 else if (GET_CODE (x) == MEM)
2106 output_address (XEXP (x, 0));
2107 else if (GET_CODE (x) == CONST_INT)
2108 fprintf (file, "%ld", INTVAL (x));
2110 output_addr_const (file, x);
2115 /* A C compound statement to output to stdio stream STREAM the
2116 assembler syntax for an instruction operand that is a memory
2117 reference whose address is ADDR. ADDR is an RTL expression. */
2120 print_operand_address (file, addr)
2125 error ("PRINT_OPERAND_ADDRESS, null pointer");
2127 switch (GET_CODE (addr))
2130 fatal_insn ("invalid address", addr);
2134 fprintf (file, "%s, 0", reg_names [REGNO (addr)]);
2140 rtx offset = (rtx)0;
2141 rtx arg0 = XEXP (addr, 0);
2142 rtx arg1 = XEXP (addr, 1);
2144 if (GET_CODE (arg0) == REG)
2149 else if (GET_CODE (arg1) == REG)
2155 fatal_insn ("no register in address", addr);
2157 if (CONSTANT_P (offset))
2159 fprintf (file, "%s, ", reg_names [REGNO (reg)]);
2160 output_addr_const (file, offset);
2163 fatal_insn ("address offset not a constant", addr);
2171 output_addr_const (file, addr);
2178 xtensa_output_literal (file, x, mode, labelno)
2181 enum machine_mode mode;
2188 fprintf (file, "\t.literal .LC%u, ", (unsigned) labelno);
2190 switch (GET_MODE_CLASS (mode))
2193 if (GET_CODE (x) != CONST_DOUBLE)
2196 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2200 REAL_VALUE_TO_TARGET_SINGLE (r, value_long[0]);
2201 fprintf (file, "0x%08lx\n", value_long[0]);
2205 REAL_VALUE_TO_TARGET_DOUBLE (r, value_long);
2206 fprintf (file, "0x%08lx, 0x%08lx\n",
2207 value_long[0], value_long[1]);
2217 case MODE_PARTIAL_INT:
2218 size = GET_MODE_SIZE (mode);
2221 output_addr_const (file, x);
2226 output_addr_const (file, operand_subword (x, 0, 0, DImode));
2228 output_addr_const (file, operand_subword (x, 1, 0, DImode));
2241 /* Return the bytes needed to compute the frame pointer from the current
2244 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
2245 #define XTENSA_STACK_ALIGN(LOC) (((LOC) + STACK_BYTES-1) & ~(STACK_BYTES-1))
2248 compute_frame_size (size)
2249 int size; /* # of var. bytes allocated */
2251 /* add space for the incoming static chain value */
2252 if (current_function_needs_context)
2253 size += (1 * UNITS_PER_WORD);
2255 xtensa_current_frame_size =
2256 XTENSA_STACK_ALIGN (size
2257 + current_function_outgoing_args_size
2258 + (WINDOW_SIZE * UNITS_PER_WORD));
2259 return xtensa_current_frame_size;
2264 xtensa_frame_pointer_required ()
2266 /* The code to expand builtin_frame_addr and builtin_return_addr
2267 currently uses the hard_frame_pointer instead of frame_pointer.
2268 This seems wrong but maybe it's necessary for other architectures.
2269 This function is derived from the i386 code. */
2271 if (cfun->machine->accesses_prev_frame)
2279 xtensa_expand_prologue ()
2281 HOST_WIDE_INT total_size;
2284 total_size = compute_frame_size (get_frame_size ());
2285 size_rtx = GEN_INT (total_size);
2287 if (total_size < (1 << (12+3)))
2288 emit_insn (gen_entry (size_rtx, size_rtx));
2291 /* Use a8 as a temporary since a0-a7 may be live. */
2292 rtx tmp_reg = gen_rtx_REG (Pmode, A8_REG);
2293 emit_insn (gen_entry (size_rtx, GEN_INT (MIN_FRAME_SIZE)));
2294 emit_move_insn (tmp_reg, GEN_INT (total_size - MIN_FRAME_SIZE));
2295 emit_insn (gen_subsi3 (tmp_reg, stack_pointer_rtx, tmp_reg));
2296 emit_move_insn (stack_pointer_rtx, tmp_reg);
2299 if (frame_pointer_needed)
2301 rtx first, insn, set_frame_ptr_insn = 0;
2303 push_topmost_sequence ();
2304 first = get_insns ();
2305 pop_topmost_sequence ();
2307 /* Search all instructions, looking for the insn that sets up the
2308 frame pointer. This search will fail if the function does not
2309 have an incoming argument in $a7, but in that case, we can just
2310 set up the frame pointer at the very beginning of the
2313 for (insn = first; insn; insn = NEXT_INSN (insn))
2320 pat = PATTERN (insn);
2321 if (GET_CODE (pat) == SET
2322 && GET_CODE (SET_SRC (pat)) == UNSPEC_VOLATILE
2323 && (XINT (SET_SRC (pat), 1) == UNSPECV_SET_FP))
2325 set_frame_ptr_insn = insn;
2330 if (set_frame_ptr_insn)
2332 /* For all instructions prior to set_frame_ptr_insn, replace
2333 hard_frame_pointer references with stack_pointer. */
2335 insn != set_frame_ptr_insn;
2336 insn = NEXT_INSN (insn))
2339 PATTERN (insn) = replace_rtx (copy_rtx (PATTERN (insn)),
2340 hard_frame_pointer_rtx,
2345 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
2350 /* Clear variables at function end. */
2353 xtensa_function_epilogue (file, size)
2354 FILE *file ATTRIBUTE_UNUSED;
2355 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
2357 xtensa_current_frame_size = 0;
2362 xtensa_return_addr (count, frame)
2366 rtx result, retaddr;
2369 retaddr = gen_rtx_REG (Pmode, A0_REG);
2372 rtx addr = plus_constant (frame, -4 * UNITS_PER_WORD);
2373 addr = memory_address (Pmode, addr);
2374 retaddr = gen_reg_rtx (Pmode);
2375 emit_move_insn (retaddr, gen_rtx_MEM (Pmode, addr));
2378 /* The 2 most-significant bits of the return address on Xtensa hold
2379 the register window size. To get the real return address, these
2380 bits must be replaced with the high bits from the current PC. */
2382 result = gen_reg_rtx (Pmode);
2383 emit_insn (gen_fix_return_addr (result, retaddr));
2388 /* Create the va_list data type.
2389 This structure is set up by __builtin_saveregs. The __va_reg
2390 field points to a stack-allocated region holding the contents of the
2391 incoming argument registers. The __va_ndx field is an index initialized
2392 to the position of the first unnamed (variable) argument. This same index
2393 is also used to address the arguments passed in memory. Thus, the
2394 __va_stk field is initialized to point to the position of the first
2395 argument in memory offset to account for the arguments passed in
2396 registers. E.G., if there are 6 argument registers, and each register is
2397 4 bytes, then __va_stk is set to $sp - (6 * 4); then __va_reg[N*4]
2398 references argument word N for 0 <= N < 6, and __va_stk[N*4] references
2399 argument word N for N >= 6. */
2402 xtensa_build_va_list ()
2404 tree f_stk, f_reg, f_ndx, record, type_decl;
2406 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
2407 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2409 f_stk = build_decl (FIELD_DECL, get_identifier ("__va_stk"),
2411 f_reg = build_decl (FIELD_DECL, get_identifier ("__va_reg"),
2413 f_ndx = build_decl (FIELD_DECL, get_identifier ("__va_ndx"),
2416 DECL_FIELD_CONTEXT (f_stk) = record;
2417 DECL_FIELD_CONTEXT (f_reg) = record;
2418 DECL_FIELD_CONTEXT (f_ndx) = record;
2420 TREE_CHAIN (record) = type_decl;
2421 TYPE_NAME (record) = type_decl;
2422 TYPE_FIELDS (record) = f_stk;
2423 TREE_CHAIN (f_stk) = f_reg;
2424 TREE_CHAIN (f_reg) = f_ndx;
2426 layout_type (record);
2431 /* Save the incoming argument registers on the stack. Returns the
2432 address of the saved registers. */
2435 xtensa_builtin_saveregs ()
2438 int arg_words = current_function_arg_words;
2439 int gp_left = MAX_ARGS_IN_REGISTERS - arg_words;
2445 /* allocate the general-purpose register space */
2446 gp_regs = assign_stack_local
2447 (BLKmode, MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD, -1);
2448 set_mem_alias_set (gp_regs, get_varargs_alias_set ());
2450 /* Now store the incoming registers. */
2451 dest = change_address (gp_regs, SImode,
2452 plus_constant (XEXP (gp_regs, 0),
2453 arg_words * UNITS_PER_WORD));
2455 /* Note: Don't use move_block_from_reg() here because the incoming
2456 argument in a7 cannot be represented by hard_frame_pointer_rtx.
2457 Instead, call gen_raw_REG() directly so that we get a distinct
2458 instance of (REG:SI 7). */
2459 for (i = 0; i < gp_left; i++)
2461 emit_move_insn (operand_subword (dest, i, 1, BLKmode),
2462 gen_raw_REG (SImode, GP_ARG_FIRST + arg_words + i));
2465 return XEXP (gp_regs, 0);
2469 /* Implement `va_start' for varargs and stdarg. We look at the
2470 current function to fill in an initial va_list. */
2473 xtensa_va_start (valist, nextarg)
2475 rtx nextarg ATTRIBUTE_UNUSED;
2483 arg_words = current_function_args_info.arg_words;
2485 f_stk = TYPE_FIELDS (va_list_type_node);
2486 f_reg = TREE_CHAIN (f_stk);
2487 f_ndx = TREE_CHAIN (f_reg);
2489 stk = build (COMPONENT_REF, TREE_TYPE (f_stk), valist, f_stk);
2490 reg = build (COMPONENT_REF, TREE_TYPE (f_reg), valist, f_reg);
2491 ndx = build (COMPONENT_REF, TREE_TYPE (f_ndx), valist, f_ndx);
2493 /* Call __builtin_saveregs; save the result in __va_reg */
2494 current_function_arg_words = arg_words;
2495 u = make_tree (ptr_type_node, expand_builtin_saveregs ());
2496 t = build (MODIFY_EXPR, ptr_type_node, reg, u);
2497 TREE_SIDE_EFFECTS (t) = 1;
2498 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2500 /* Set the __va_stk member to $arg_ptr - (size of __va_reg area) */
2501 u = make_tree (ptr_type_node, virtual_incoming_args_rtx);
2502 u = fold (build (PLUS_EXPR, ptr_type_node, u,
2503 build_int_2 (-MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD, -1)));
2504 t = build (MODIFY_EXPR, ptr_type_node, stk, u);
2505 TREE_SIDE_EFFECTS (t) = 1;
2506 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2508 /* Set the __va_ndx member. */
2509 u = build_int_2 (arg_words * UNITS_PER_WORD, 0);
2510 t = build (MODIFY_EXPR, integer_type_node, ndx, u);
2511 TREE_SIDE_EFFECTS (t) = 1;
2512 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2516 /* Implement `va_arg'. */
2519 xtensa_va_arg (valist, type)
2525 tree tmp, addr_tree, type_size;
2526 rtx array, orig_ndx, r, addr, size, va_size;
2527 rtx lab_false, lab_over, lab_false2;
2529 f_stk = TYPE_FIELDS (va_list_type_node);
2530 f_reg = TREE_CHAIN (f_stk);
2531 f_ndx = TREE_CHAIN (f_reg);
2533 stk = build (COMPONENT_REF, TREE_TYPE (f_stk), valist, f_stk);
2534 reg = build (COMPONENT_REF, TREE_TYPE (f_reg), valist, f_reg);
2535 ndx = build (COMPONENT_REF, TREE_TYPE (f_ndx), valist, f_ndx);
2537 type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
2539 va_size = gen_reg_rtx (SImode);
2540 tmp = fold (build (MULT_EXPR, sizetype,
2541 fold (build (TRUNC_DIV_EXPR, sizetype,
2542 fold (build (PLUS_EXPR, sizetype,
2544 size_int (UNITS_PER_WORD - 1))),
2545 size_int (UNITS_PER_WORD))),
2546 size_int (UNITS_PER_WORD)));
2547 r = expand_expr (tmp, va_size, SImode, EXPAND_NORMAL);
2549 emit_move_insn (va_size, r);
2552 /* First align __va_ndx to a double word boundary if necessary for this arg:
2554 if (__alignof__ (TYPE) > 4)
2555 (AP).__va_ndx = (((AP).__va_ndx + 7) & -8)
2558 if (TYPE_ALIGN (type) > BITS_PER_WORD)
2560 tmp = build (PLUS_EXPR, integer_type_node, ndx,
2561 build_int_2 ((2 * UNITS_PER_WORD) - 1, 0));
2562 tmp = build (BIT_AND_EXPR, integer_type_node, tmp,
2563 build_int_2 (-2 * UNITS_PER_WORD, -1));
2564 tmp = build (MODIFY_EXPR, integer_type_node, ndx, tmp);
2565 TREE_SIDE_EFFECTS (tmp) = 1;
2566 expand_expr (tmp, const0_rtx, VOIDmode, EXPAND_NORMAL);
2570 /* Increment __va_ndx to point past the argument:
2572 orig_ndx = (AP).__va_ndx;
2573 (AP).__va_ndx += __va_size (TYPE);
2576 orig_ndx = gen_reg_rtx (SImode);
2577 r = expand_expr (ndx, orig_ndx, SImode, EXPAND_NORMAL);
2579 emit_move_insn (orig_ndx, r);
2581 tmp = build (PLUS_EXPR, integer_type_node, ndx,
2582 make_tree (intSI_type_node, va_size));
2583 tmp = build (MODIFY_EXPR, integer_type_node, ndx, tmp);
2584 TREE_SIDE_EFFECTS (tmp) = 1;
2585 expand_expr (tmp, const0_rtx, VOIDmode, EXPAND_NORMAL);
2588 /* Check if the argument is in registers:
2590 if ((AP).__va_ndx <= __MAX_ARGS_IN_REGISTERS * 4
2591 && !MUST_PASS_IN_STACK (type))
2592 __array = (AP).__va_reg;
2595 array = gen_reg_rtx (Pmode);
2597 lab_over = NULL_RTX;
2598 if (!MUST_PASS_IN_STACK (VOIDmode, type))
2600 lab_false = gen_label_rtx ();
2601 lab_over = gen_label_rtx ();
2603 emit_cmp_and_jump_insns (expand_expr (ndx, NULL_RTX, SImode,
2605 GEN_INT (MAX_ARGS_IN_REGISTERS
2607 GT, const1_rtx, SImode, 0, lab_false);
2609 r = expand_expr (reg, array, Pmode, EXPAND_NORMAL);
2611 emit_move_insn (array, r);
2613 emit_jump_insn (gen_jump (lab_over));
2615 emit_label (lab_false);
2618 /* ...otherwise, the argument is on the stack (never split between
2619 registers and the stack -- change __va_ndx if necessary):
2623 if (orig_ndx < __MAX_ARGS_IN_REGISTERS * 4)
2624 (AP).__va_ndx = __MAX_ARGS_IN_REGISTERS * 4 + __va_size (TYPE);
2625 __array = (AP).__va_stk;
2629 lab_false2 = gen_label_rtx ();
2630 emit_cmp_and_jump_insns (orig_ndx,
2631 GEN_INT (MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD),
2632 GE, const1_rtx, SImode, 0, lab_false2);
2634 tmp = build (PLUS_EXPR, sizetype, make_tree (intSI_type_node, va_size),
2635 build_int_2 (MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD, 0));
2636 tmp = build (MODIFY_EXPR, integer_type_node, ndx, tmp);
2637 TREE_SIDE_EFFECTS (tmp) = 1;
2638 expand_expr (tmp, const0_rtx, VOIDmode, EXPAND_NORMAL);
2640 emit_label (lab_false2);
2642 r = expand_expr (stk, array, Pmode, EXPAND_NORMAL);
2644 emit_move_insn (array, r);
2646 if (lab_over != NULL_RTX)
2647 emit_label (lab_over);
2650 /* Given the base array pointer (__array) and index to the subsequent
2651 argument (__va_ndx), find the address:
2653 __array + (AP).__va_ndx - (BYTES_BIG_ENDIAN && sizeof (TYPE) < 4
2657 The results are endian-dependent because values smaller than one word
2658 are aligned differently.
2661 size = gen_reg_rtx (SImode);
2662 emit_move_insn (size, va_size);
2664 if (BYTES_BIG_ENDIAN)
2666 rtx lab_use_va_size = gen_label_rtx ();
2668 emit_cmp_and_jump_insns (expand_expr (type_size, NULL_RTX, SImode,
2670 GEN_INT (PARM_BOUNDARY / BITS_PER_UNIT),
2671 GE, const1_rtx, SImode, 0, lab_use_va_size);
2673 r = expand_expr (type_size, size, SImode, EXPAND_NORMAL);
2675 emit_move_insn (size, r);
2677 emit_label (lab_use_va_size);
2680 addr_tree = build (PLUS_EXPR, ptr_type_node,
2681 make_tree (ptr_type_node, array),
2683 addr_tree = build (MINUS_EXPR, ptr_type_node, addr_tree,
2684 make_tree (intSI_type_node, size));
2685 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2686 addr = copy_to_reg (addr);
2692 xtensa_preferred_reload_class (x, class, isoutput)
2694 enum reg_class class;
2697 if (!isoutput && CONSTANT_P (x) && GET_CODE (x) == CONST_DOUBLE)
2700 /* Don't use the stack pointer or hard frame pointer for reloads!
2701 The hard frame pointer would normally be OK except that it may
2702 briefly hold an incoming argument in the prologue, and reload
2703 won't know that it is live because the hard frame pointer is
2704 treated specially. */
2706 if (class == AR_REGS || class == GR_REGS)
2714 xtensa_secondary_reload_class (class, mode, x, isoutput)
2715 enum reg_class class;
2716 enum machine_mode mode ATTRIBUTE_UNUSED;
2722 if (GET_CODE (x) == SIGN_EXTEND)
2724 regno = xt_true_regnum (x);
2728 if (class == FP_REGS && constantpool_mem_p (x))
2732 if (ACC_REG_P (regno))
2733 return ((class == GR_REGS || class == RL_REGS) ? NO_REGS : RL_REGS);
2734 if (class == ACC_REG)
2735 return (GP_REG_P (regno) ? NO_REGS : RL_REGS);
2742 order_regs_for_local_alloc ()
2744 if (!leaf_function_p ())
2746 memcpy (reg_alloc_order, reg_nonleaf_alloc_order,
2747 FIRST_PSEUDO_REGISTER * sizeof (int));
2751 int i, num_arg_regs;
2754 /* use the AR registers in increasing order (skipping a0 and a1)
2755 but save the incoming argument registers for a last resort */
2756 num_arg_regs = current_function_args_info.arg_words;
2757 if (num_arg_regs > MAX_ARGS_IN_REGISTERS)
2758 num_arg_regs = MAX_ARGS_IN_REGISTERS;
2759 for (i = GP_ARG_FIRST; i < 16 - num_arg_regs; i++)
2760 reg_alloc_order[nxt++] = i + num_arg_regs;
2761 for (i = 0; i < num_arg_regs; i++)
2762 reg_alloc_order[nxt++] = GP_ARG_FIRST + i;
2764 /* list the coprocessor registers in order */
2765 for (i = 0; i < BR_REG_NUM; i++)
2766 reg_alloc_order[nxt++] = BR_REG_FIRST + i;
2768 /* list the FP registers in order for now */
2769 for (i = 0; i < 16; i++)
2770 reg_alloc_order[nxt++] = FP_REG_FIRST + i;
2772 /* GCC requires that we list *all* the registers.... */
2773 reg_alloc_order[nxt++] = 0; /* a0 = return address */
2774 reg_alloc_order[nxt++] = 1; /* a1 = stack pointer */
2775 reg_alloc_order[nxt++] = 16; /* pseudo frame pointer */
2776 reg_alloc_order[nxt++] = 17; /* pseudo arg pointer */
2778 reg_alloc_order[nxt++] = ACC_REG_FIRST; /* MAC16 accumulator */
2783 /* A customized version of reg_overlap_mentioned_p that only looks for
2784 references to a7 (as opposed to hard_frame_pointer_rtx). */
2787 a7_overlap_mentioned_p (x)
2791 unsigned int x_regno;
2794 if (GET_CODE (x) == REG)
2796 x_regno = REGNO (x);
2797 return (x != hard_frame_pointer_rtx
2798 && x_regno < A7_REG + 1
2799 && x_regno + HARD_REGNO_NREGS (A7_REG, GET_MODE (x)) > A7_REG);
2802 if (GET_CODE (x) == SUBREG
2803 && GET_CODE (SUBREG_REG (x)) == REG
2804 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
2806 x_regno = subreg_regno (x);
2807 return (SUBREG_REG (x) != hard_frame_pointer_rtx
2808 && x_regno < A7_REG + 1
2809 && x_regno + HARD_REGNO_NREGS (A7_REG, GET_MODE (x)) > A7_REG);
2812 /* X does not match, so try its subexpressions. */
2813 fmt = GET_RTX_FORMAT (GET_CODE (x));
2814 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2818 if (a7_overlap_mentioned_p (XEXP (x, i)))
2821 else if (fmt[i] == 'E')
2823 for (j = XVECLEN (x, i) - 1; j >=0; j--)
2824 if (a7_overlap_mentioned_p (XVECEXP (x, i, j)))
2833 /* Some Xtensa targets support multiple bss sections. If the section
2834 name ends with ".bss", add SECTION_BSS to the flags. */
2837 xtensa_multibss_section_type_flags (decl, name, reloc)
2842 unsigned int flags = default_section_type_flags (decl, name, reloc);
2845 suffix = strrchr (name, '.');
2846 if (suffix && strcmp (suffix, ".bss") == 0)
2848 if (!decl || (TREE_CODE (decl) == VAR_DECL
2849 && DECL_INITIAL (decl) == NULL_TREE))
2850 flags |= SECTION_BSS; /* @nobits */
2852 warning ("only uninitialized variables can be placed in a "
2860 /* The literal pool stays with the function. */
2863 xtensa_select_rtx_section (mode, x, align)
2864 enum machine_mode mode ATTRIBUTE_UNUSED;
2865 rtx x ATTRIBUTE_UNUSED;
2866 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
2868 function_section (current_function_decl);
2871 /* Compute a (partial) cost for rtx X. Return true if the complete
2872 cost has been computed, and false if subexpressions should be
2873 scanned. In either case, *TOTAL contains the cost result. */
2876 xtensa_rtx_costs (x, code, outer_code, total)
2878 int code, outer_code;
2887 if (xtensa_simm12b (INTVAL (x)))
2894 if (xtensa_simm8 (INTVAL (x))
2895 || xtensa_simm8x256 (INTVAL (x)))
2902 if (xtensa_mask_immediate (INTVAL (x)))
2909 if ((INTVAL (x) == 0) || xtensa_b4const (INTVAL (x)))
2920 /* no way to tell if X is the 2nd operand so be conservative */
2923 if (xtensa_simm12b (INTVAL (x)))
2925 else if (TARGET_CONST16)
2926 *total = COSTS_N_INSNS (2);
2935 *total = COSTS_N_INSNS (2);
2942 *total = COSTS_N_INSNS (4);
2950 (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) ? 2 : 1;
2952 if (memory_address_p (GET_MODE (x), XEXP ((x), 0)))
2953 *total = COSTS_N_INSNS (num_words);
2955 *total = COSTS_N_INSNS (2*num_words);
2960 *total = COSTS_N_INSNS (TARGET_NSA ? 5 : 50);
2964 *total = COSTS_N_INSNS ((GET_MODE (x) == DImode) ? 3 : 2);
2970 if (GET_MODE (x) == DImode)
2971 *total = COSTS_N_INSNS (2);
2973 *total = COSTS_N_INSNS (1);
2979 if (GET_MODE (x) == DImode)
2980 *total = COSTS_N_INSNS (50);
2982 *total = COSTS_N_INSNS (1);
2987 enum machine_mode xmode = GET_MODE (x);
2988 if (xmode == SFmode)
2989 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT ? 1 : 50);
2990 else if (xmode == DFmode)
2991 *total = COSTS_N_INSNS (50);
2993 *total = COSTS_N_INSNS (4);
3000 enum machine_mode xmode = GET_MODE (x);
3001 if (xmode == SFmode)
3002 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT ? 1 : 50);
3003 else if (xmode == DFmode || xmode == DImode)
3004 *total = COSTS_N_INSNS (50);
3006 *total = COSTS_N_INSNS (1);
3011 *total = COSTS_N_INSNS ((GET_MODE (x) == DImode) ? 4 : 2);
3016 enum machine_mode xmode = GET_MODE (x);
3017 if (xmode == SFmode)
3018 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT ? 4 : 50);
3019 else if (xmode == DFmode || xmode == DImode)
3020 *total = COSTS_N_INSNS (50);
3021 else if (TARGET_MUL32)
3022 *total = COSTS_N_INSNS (4);
3023 else if (TARGET_MAC16)
3024 *total = COSTS_N_INSNS (16);
3025 else if (TARGET_MUL16)
3026 *total = COSTS_N_INSNS (12);
3028 *total = COSTS_N_INSNS (50);
3035 enum machine_mode xmode = GET_MODE (x);
3036 if (xmode == SFmode)
3038 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT_DIV ? 8 : 50);
3041 else if (xmode == DFmode)
3043 *total = COSTS_N_INSNS (50);
3052 enum machine_mode xmode = GET_MODE (x);
3053 if (xmode == DImode)
3054 *total = COSTS_N_INSNS (50);
3055 else if (TARGET_DIV32)
3056 *total = COSTS_N_INSNS (32);
3058 *total = COSTS_N_INSNS (50);
3063 if (GET_MODE (x) == SFmode)
3064 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT_SQRT ? 8 : 50);
3066 *total = COSTS_N_INSNS (50);
3073 *total = COSTS_N_INSNS (TARGET_MINMAX ? 1 : 50);
3078 *total = COSTS_N_INSNS (TARGET_SEXT ? 1 : 2);
3083 *total = COSTS_N_INSNS (1);
3091 #include "gt-xtensa.h"