1 /* Subroutines for insn-output.c for Tensilica's Xtensa architecture.
2 Copyright 2001, 2002, 2003, 2004, 2005 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, 51 Franklin Street, Fifth Floor, 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"
51 #include "tree-gimple.h"
54 /* Enumeration for all of the relational tests, so that we can build
55 arrays indexed by the test type, and not worry about the order
73 /* Cached operands, and operator to compare for use in set/branch on
77 /* what type of branch to use */
78 enum cmp_type branch_type
;
80 /* Array giving truth value on whether or not a given hard register
81 can support a given mode. */
82 char xtensa_hard_regno_mode_ok
[(int) MAX_MACHINE_MODE
][FIRST_PSEUDO_REGISTER
];
84 /* Current frame size calculated by compute_frame_size. */
85 unsigned xtensa_current_frame_size
;
87 /* Largest block move to handle in-line. */
88 #define LARGEST_MOVE_RATIO 15
90 /* Define the structure for the machine field in struct function. */
91 struct machine_function
GTY(())
93 int accesses_prev_frame
;
96 rtx set_frame_ptr_insn
;
99 /* Vector, indexed by hard register number, which contains 1 for a
100 register that is allowable in a candidate for leaf function
103 const char xtensa_leaf_regs
[FIRST_PSEUDO_REGISTER
] =
105 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
107 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
111 /* Map hard register number to register class */
112 const enum reg_class xtensa_regno_to_class
[FIRST_PSEUDO_REGISTER
] =
114 RL_REGS
, SP_REG
, RL_REGS
, RL_REGS
,
115 RL_REGS
, RL_REGS
, RL_REGS
, GR_REGS
,
116 RL_REGS
, RL_REGS
, RL_REGS
, RL_REGS
,
117 RL_REGS
, RL_REGS
, RL_REGS
, RL_REGS
,
118 AR_REGS
, AR_REGS
, BR_REGS
,
119 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
120 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
121 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
122 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
126 /* Map register constraint character to register class. */
127 enum reg_class xtensa_char_to_class
[256] =
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
,
190 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
191 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
192 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
195 static enum internal_test
map_test_to_internal_test (enum rtx_code
);
196 static rtx
gen_int_relational (enum rtx_code
, rtx
, rtx
, int *);
197 static rtx
gen_float_relational (enum rtx_code
, rtx
, rtx
);
198 static rtx
gen_conditional_move (rtx
);
199 static rtx
fixup_subreg_mem (rtx
);
200 static struct machine_function
* xtensa_init_machine_status (void);
201 static bool xtensa_return_in_msb (tree
);
202 static void printx (FILE *, signed int);
203 static void xtensa_function_epilogue (FILE *, HOST_WIDE_INT
);
204 static rtx
xtensa_builtin_saveregs (void);
205 static unsigned int xtensa_multibss_section_type_flags (tree
, const char *,
206 int) ATTRIBUTE_UNUSED
;
207 static section
*xtensa_select_rtx_section (enum machine_mode
, rtx
,
208 unsigned HOST_WIDE_INT
);
209 static bool xtensa_rtx_costs (rtx
, int, int, int *);
210 static tree
xtensa_build_builtin_va_list (void);
211 static bool xtensa_return_in_memory (tree
, tree
);
212 static tree
xtensa_gimplify_va_arg_expr (tree
, tree
, tree
*, tree
*);
214 static const int reg_nonleaf_alloc_order
[FIRST_PSEUDO_REGISTER
] =
218 /* This macro generates the assembly code for function exit,
219 on machines that need it. If FUNCTION_EPILOGUE is not defined
220 then individual return instructions are generated for each
221 return statement. Args are same as for FUNCTION_PROLOGUE. */
223 #undef TARGET_ASM_FUNCTION_EPILOGUE
224 #define TARGET_ASM_FUNCTION_EPILOGUE xtensa_function_epilogue
226 /* These hooks specify assembly directives for creating certain kinds
227 of integer object. */
229 #undef TARGET_ASM_ALIGNED_SI_OP
230 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
232 #undef TARGET_ASM_SELECT_RTX_SECTION
233 #define TARGET_ASM_SELECT_RTX_SECTION xtensa_select_rtx_section
235 #undef TARGET_DEFAULT_TARGET_FLAGS
236 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_FUSED_MADD)
238 #undef TARGET_RTX_COSTS
239 #define TARGET_RTX_COSTS xtensa_rtx_costs
240 #undef TARGET_ADDRESS_COST
241 #define TARGET_ADDRESS_COST hook_int_rtx_0
243 #undef TARGET_BUILD_BUILTIN_VA_LIST
244 #define TARGET_BUILD_BUILTIN_VA_LIST xtensa_build_builtin_va_list
246 #undef TARGET_PROMOTE_FUNCTION_ARGS
247 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
248 #undef TARGET_PROMOTE_FUNCTION_RETURN
249 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
250 #undef TARGET_PROMOTE_PROTOTYPES
251 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
253 #undef TARGET_RETURN_IN_MEMORY
254 #define TARGET_RETURN_IN_MEMORY xtensa_return_in_memory
255 #undef TARGET_SPLIT_COMPLEX_ARG
256 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
257 #undef TARGET_MUST_PASS_IN_STACK
258 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
260 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
261 #define TARGET_EXPAND_BUILTIN_SAVEREGS xtensa_builtin_saveregs
262 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
263 #define TARGET_GIMPLIFY_VA_ARG_EXPR xtensa_gimplify_va_arg_expr
265 #undef TARGET_RETURN_IN_MSB
266 #define TARGET_RETURN_IN_MSB xtensa_return_in_msb
268 struct gcc_target targetm
= TARGET_INITIALIZER
;
272 * Functions to test Xtensa immediate operand validity.
276 xtensa_simm8 (HOST_WIDE_INT v
)
278 return v
>= -128 && v
<= 127;
283 xtensa_simm8x256 (HOST_WIDE_INT v
)
285 return (v
& 255) == 0 && (v
>= -32768 && v
<= 32512);
290 xtensa_simm12b (HOST_WIDE_INT v
)
292 return v
>= -2048 && v
<= 2047;
297 xtensa_uimm8 (HOST_WIDE_INT v
)
299 return v
>= 0 && v
<= 255;
304 xtensa_uimm8x2 (HOST_WIDE_INT v
)
306 return (v
& 1) == 0 && (v
>= 0 && v
<= 510);
311 xtensa_uimm8x4 (HOST_WIDE_INT v
)
313 return (v
& 3) == 0 && (v
>= 0 && v
<= 1020);
318 xtensa_b4const (HOST_WIDE_INT v
)
345 xtensa_b4const_or_zero (HOST_WIDE_INT v
)
349 return xtensa_b4const (v
);
354 xtensa_b4constu (HOST_WIDE_INT v
)
381 xtensa_mask_immediate (HOST_WIDE_INT v
)
383 #define MAX_MASK_SIZE 16
386 for (mask_size
= 1; mask_size
<= MAX_MASK_SIZE
; mask_size
++)
400 xtensa_const_ok_for_letter_p (HOST_WIDE_INT v
, int c
)
404 case 'I': return xtensa_simm12b (v
);
405 case 'J': return xtensa_simm8 (v
);
406 case 'K': return (v
== 0 || xtensa_b4const (v
));
407 case 'L': return xtensa_b4constu (v
);
408 case 'M': return (v
>= -32 && v
<= 95);
409 case 'N': return xtensa_simm8x256 (v
);
410 case 'O': return (v
== -1 || (v
>= 1 && v
<= 15));
411 case 'P': return xtensa_mask_immediate (v
);
418 /* This is just like the standard true_regnum() function except that it
419 works even when reg_renumber is not initialized. */
422 xt_true_regnum (rtx x
)
424 if (GET_CODE (x
) == REG
)
427 && REGNO (x
) >= FIRST_PSEUDO_REGISTER
428 && reg_renumber
[REGNO (x
)] >= 0)
429 return reg_renumber
[REGNO (x
)];
432 if (GET_CODE (x
) == SUBREG
)
434 int base
= xt_true_regnum (SUBREG_REG (x
));
435 if (base
>= 0 && base
< FIRST_PSEUDO_REGISTER
)
436 return base
+ subreg_regno_offset (REGNO (SUBREG_REG (x
)),
437 GET_MODE (SUBREG_REG (x
)),
438 SUBREG_BYTE (x
), GET_MODE (x
));
445 xtensa_valid_move (enum machine_mode mode
, rtx
*operands
)
447 /* Either the destination or source must be a register, and the
448 MAC16 accumulator doesn't count. */
450 if (register_operand (operands
[0], mode
))
452 int dst_regnum
= xt_true_regnum (operands
[0]);
454 /* The stack pointer can only be assigned with a MOVSP opcode. */
455 if (dst_regnum
== STACK_POINTER_REGNUM
)
456 return (mode
== SImode
457 && register_operand (operands
[1], mode
)
458 && !ACC_REG_P (xt_true_regnum (operands
[1])));
460 if (!ACC_REG_P (dst_regnum
))
463 if (register_operand (operands
[1], mode
))
465 int src_regnum
= xt_true_regnum (operands
[1]);
466 if (!ACC_REG_P (src_regnum
))
474 smalloffset_mem_p (rtx op
)
476 if (GET_CODE (op
) == MEM
)
478 rtx addr
= XEXP (op
, 0);
479 if (GET_CODE (addr
) == REG
)
480 return REG_OK_FOR_BASE_P (addr
);
481 if (GET_CODE (addr
) == PLUS
)
483 rtx offset
= XEXP (addr
, 0);
485 if (GET_CODE (offset
) != CONST_INT
)
486 offset
= XEXP (addr
, 1);
487 if (GET_CODE (offset
) != CONST_INT
)
490 val
= INTVAL (offset
);
491 return (val
& 3) == 0 && (val
>= 0 && val
<= 60);
499 constantpool_address_p (rtx addr
)
503 if (GET_CODE (addr
) == CONST
)
507 /* Only handle (PLUS (SYM, OFFSET)) form. */
508 addr
= XEXP (addr
, 0);
509 if (GET_CODE (addr
) != PLUS
)
512 /* Make sure the address is word aligned. */
513 offset
= XEXP (addr
, 1);
514 if ((GET_CODE (offset
) != CONST_INT
)
515 || ((INTVAL (offset
) & 3) != 0))
518 sym
= XEXP (addr
, 0);
521 if ((GET_CODE (sym
) == SYMBOL_REF
)
522 && CONSTANT_POOL_ADDRESS_P (sym
))
529 constantpool_mem_p (rtx op
)
531 if (GET_CODE (op
) == MEM
)
532 return constantpool_address_p (XEXP (op
, 0));
538 xtensa_extend_reg (rtx dst
, rtx src
)
540 rtx temp
= gen_reg_rtx (SImode
);
541 rtx shift
= GEN_INT (BITS_PER_WORD
- GET_MODE_BITSIZE (GET_MODE (src
)));
543 /* Generate paradoxical subregs as needed so that the modes match. */
544 src
= simplify_gen_subreg (SImode
, src
, GET_MODE (src
), 0);
545 dst
= simplify_gen_subreg (SImode
, dst
, GET_MODE (dst
), 0);
547 emit_insn (gen_ashlsi3 (temp
, src
, shift
));
548 emit_insn (gen_ashrsi3 (dst
, temp
, shift
));
553 xtensa_mem_offset (unsigned v
, enum machine_mode mode
)
558 /* Handle the worst case for block moves. See xtensa_expand_block_move
559 where we emit an optimized block move operation if the block can be
560 moved in < "move_ratio" pieces. The worst case is when the block is
561 aligned but has a size of (3 mod 4) (does this happen?) so that the
562 last piece requires a byte load/store. */
563 return (xtensa_uimm8 (v
)
564 && xtensa_uimm8 (v
+ MOVE_MAX
* LARGEST_MOVE_RATIO
));
567 return xtensa_uimm8 (v
);
570 return xtensa_uimm8x2 (v
);
573 return (xtensa_uimm8x4 (v
) && xtensa_uimm8x4 (v
+ 4));
579 return xtensa_uimm8x4 (v
);
584 xtensa_extra_constraint (rtx op
, int c
)
586 /* Allow pseudo registers during reload. */
587 if (GET_CODE (op
) != MEM
)
588 return (c
>= 'R' && c
<= 'U'
589 && reload_in_progress
&& GET_CODE (op
) == REG
590 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
);
594 case 'R': return smalloffset_mem_p (op
);
595 case 'T': return !TARGET_CONST16
&& constantpool_mem_p (op
);
596 case 'U': return !constantpool_mem_p (op
);
603 /* Make normal rtx_code into something we can index from an array. */
605 static enum internal_test
606 map_test_to_internal_test (enum rtx_code test_code
)
608 enum internal_test test
= ITEST_MAX
;
613 case EQ
: test
= ITEST_EQ
; break;
614 case NE
: test
= ITEST_NE
; break;
615 case GT
: test
= ITEST_GT
; break;
616 case GE
: test
= ITEST_GE
; break;
617 case LT
: test
= ITEST_LT
; break;
618 case LE
: test
= ITEST_LE
; break;
619 case GTU
: test
= ITEST_GTU
; break;
620 case GEU
: test
= ITEST_GEU
; break;
621 case LTU
: test
= ITEST_LTU
; break;
622 case LEU
: test
= ITEST_LEU
; break;
629 /* Generate the code to compare two integer values. The return value is
630 the comparison expression. */
633 gen_int_relational (enum rtx_code test_code
, /* relational test (EQ, etc) */
634 rtx cmp0
, /* first operand to compare */
635 rtx cmp1
, /* second operand to compare */
636 int *p_invert
/* whether branch needs to reverse test */)
640 enum rtx_code test_code
; /* test code to use in insn */
641 bool (*const_range_p
) (HOST_WIDE_INT
); /* range check function */
642 int const_add
; /* constant to add (convert LE -> LT) */
643 int reverse_regs
; /* reverse registers in test */
644 int invert_const
; /* != 0 if invert value if cmp1 is constant */
645 int invert_reg
; /* != 0 if invert value if cmp1 is register */
646 int unsignedp
; /* != 0 for unsigned comparisons. */
649 static struct cmp_info info
[ (int)ITEST_MAX
] = {
651 { EQ
, xtensa_b4const_or_zero
, 0, 0, 0, 0, 0 }, /* EQ */
652 { NE
, xtensa_b4const_or_zero
, 0, 0, 0, 0, 0 }, /* NE */
654 { LT
, xtensa_b4const_or_zero
, 1, 1, 1, 0, 0 }, /* GT */
655 { GE
, xtensa_b4const_or_zero
, 0, 0, 0, 0, 0 }, /* GE */
656 { LT
, xtensa_b4const_or_zero
, 0, 0, 0, 0, 0 }, /* LT */
657 { GE
, xtensa_b4const_or_zero
, 1, 1, 1, 0, 0 }, /* LE */
659 { LTU
, xtensa_b4constu
, 1, 1, 1, 0, 1 }, /* GTU */
660 { GEU
, xtensa_b4constu
, 0, 0, 0, 0, 1 }, /* GEU */
661 { LTU
, xtensa_b4constu
, 0, 0, 0, 0, 1 }, /* LTU */
662 { GEU
, xtensa_b4constu
, 1, 1, 1, 0, 1 }, /* LEU */
665 enum internal_test test
;
666 enum machine_mode mode
;
667 struct cmp_info
*p_info
;
669 test
= map_test_to_internal_test (test_code
);
670 gcc_assert (test
!= ITEST_MAX
);
672 p_info
= &info
[ (int)test
];
674 mode
= GET_MODE (cmp0
);
675 if (mode
== VOIDmode
)
676 mode
= GET_MODE (cmp1
);
678 /* Make sure we can handle any constants given to us. */
679 if (GET_CODE (cmp1
) == CONST_INT
)
681 HOST_WIDE_INT value
= INTVAL (cmp1
);
682 unsigned HOST_WIDE_INT uvalue
= (unsigned HOST_WIDE_INT
)value
;
684 /* if the immediate overflows or does not fit in the immediate field,
685 spill it to a register */
687 if ((p_info
->unsignedp
?
688 (uvalue
+ p_info
->const_add
> uvalue
) :
689 (value
+ p_info
->const_add
> value
)) != (p_info
->const_add
> 0))
691 cmp1
= force_reg (mode
, cmp1
);
693 else if (!(p_info
->const_range_p
) (value
+ p_info
->const_add
))
695 cmp1
= force_reg (mode
, cmp1
);
698 else if ((GET_CODE (cmp1
) != REG
) && (GET_CODE (cmp1
) != SUBREG
))
700 cmp1
= force_reg (mode
, cmp1
);
703 /* See if we need to invert the result. */
704 *p_invert
= ((GET_CODE (cmp1
) == CONST_INT
)
705 ? p_info
->invert_const
706 : p_info
->invert_reg
);
708 /* Comparison to constants, may involve adding 1 to change a LT into LE.
709 Comparison between two registers, may involve switching operands. */
710 if (GET_CODE (cmp1
) == CONST_INT
)
712 if (p_info
->const_add
!= 0)
713 cmp1
= GEN_INT (INTVAL (cmp1
) + p_info
->const_add
);
716 else if (p_info
->reverse_regs
)
723 return gen_rtx_fmt_ee (p_info
->test_code
, VOIDmode
, cmp0
, cmp1
);
727 /* Generate the code to compare two float values. The return value is
728 the comparison expression. */
731 gen_float_relational (enum rtx_code test_code
, /* relational test (EQ, etc) */
732 rtx cmp0
, /* first operand to compare */
733 rtx cmp1
/* second operand to compare */)
735 rtx (*gen_fn
) (rtx
, rtx
, rtx
);
737 int reverse_regs
, invert
;
741 case EQ
: reverse_regs
= 0; invert
= 0; gen_fn
= gen_seq_sf
; break;
742 case NE
: reverse_regs
= 0; invert
= 1; gen_fn
= gen_seq_sf
; break;
743 case LE
: reverse_regs
= 0; invert
= 0; gen_fn
= gen_sle_sf
; break;
744 case GT
: reverse_regs
= 1; invert
= 0; gen_fn
= gen_slt_sf
; break;
745 case LT
: reverse_regs
= 0; invert
= 0; gen_fn
= gen_slt_sf
; break;
746 case GE
: reverse_regs
= 1; invert
= 0; gen_fn
= gen_sle_sf
; break;
748 fatal_insn ("bad test", gen_rtx_fmt_ee (test_code
, VOIDmode
, cmp0
, cmp1
));
749 reverse_regs
= 0; invert
= 0; gen_fn
= 0; /* avoid compiler warnings */
759 brtmp
= gen_rtx_REG (CCmode
, FPCC_REGNUM
);
760 emit_insn (gen_fn (brtmp
, cmp0
, cmp1
));
762 return gen_rtx_fmt_ee (invert
? EQ
: NE
, VOIDmode
, brtmp
, const0_rtx
);
767 xtensa_expand_conditional_branch (rtx
*operands
, enum rtx_code test_code
)
769 enum cmp_type type
= branch_type
;
770 rtx cmp0
= branch_cmp
[0];
771 rtx cmp1
= branch_cmp
[1];
780 fatal_insn ("bad test", gen_rtx_fmt_ee (test_code
, VOIDmode
, cmp0
, cmp1
));
784 cmp
= gen_int_relational (test_code
, cmp0
, cmp1
, &invert
);
788 if (!TARGET_HARD_FLOAT
)
789 fatal_insn ("bad test", gen_rtx_fmt_ee (test_code
, VOIDmode
, cmp0
, cmp1
));
791 cmp
= gen_float_relational (test_code
, cmp0
, cmp1
);
795 /* Generate the branch. */
797 label1
= gen_rtx_LABEL_REF (VOIDmode
, operands
[0]);
806 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
,
807 gen_rtx_IF_THEN_ELSE (VOIDmode
, cmp
,
814 gen_conditional_move (rtx cmp
)
816 enum rtx_code code
= GET_CODE (cmp
);
817 rtx op0
= branch_cmp
[0];
818 rtx op1
= branch_cmp
[1];
820 if (branch_type
== CMP_SI
)
822 /* Jump optimization calls get_condition() which canonicalizes
823 comparisons like (GE x <const>) to (GT x <const-1>).
824 Transform those comparisons back to GE, since that is the
825 comparison supported in Xtensa. We shouldn't have to
826 transform <LE x const> comparisons, because neither
827 xtensa_expand_conditional_branch() nor get_condition() will
830 if ((code
== GT
) && (op1
== constm1_rtx
))
835 cmp
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
837 if (boolean_operator (cmp
, VOIDmode
))
839 /* Swap the operands to make const0 second. */
840 if (op0
== const0_rtx
)
846 /* If not comparing against zero, emit a comparison (subtract). */
847 if (op1
!= const0_rtx
)
849 op0
= expand_binop (SImode
, sub_optab
, op0
, op1
,
850 0, 0, OPTAB_LIB_WIDEN
);
854 else if (branch_operator (cmp
, VOIDmode
))
856 /* Swap the operands to make const0 second. */
857 if (op0
== const0_rtx
)
864 case LT
: code
= GE
; break;
865 case GE
: code
= LT
; break;
866 default: gcc_unreachable ();
870 if (op1
!= const0_rtx
)
876 return gen_rtx_fmt_ee (code
, VOIDmode
, op0
, op1
);
879 if (TARGET_HARD_FLOAT
&& (branch_type
== CMP_SF
))
880 return gen_float_relational (code
, op0
, op1
);
887 xtensa_expand_conditional_move (rtx
*operands
, int isflt
)
890 rtx (*gen_fn
) (rtx
, rtx
, rtx
, rtx
, rtx
);
892 if (!(cmp
= gen_conditional_move (operands
[1])))
896 gen_fn
= (branch_type
== CMP_SI
897 ? gen_movsfcc_internal0
898 : gen_movsfcc_internal1
);
900 gen_fn
= (branch_type
== CMP_SI
901 ? gen_movsicc_internal0
902 : gen_movsicc_internal1
);
904 emit_insn (gen_fn (operands
[0], XEXP (cmp
, 0),
905 operands
[2], operands
[3], cmp
));
911 xtensa_expand_scc (rtx
*operands
)
913 rtx dest
= operands
[0];
914 rtx cmp
= operands
[1];
915 rtx one_tmp
, zero_tmp
;
916 rtx (*gen_fn
) (rtx
, rtx
, rtx
, rtx
, rtx
);
918 if (!(cmp
= gen_conditional_move (cmp
)))
921 one_tmp
= gen_reg_rtx (SImode
);
922 zero_tmp
= gen_reg_rtx (SImode
);
923 emit_insn (gen_movsi (one_tmp
, const_true_rtx
));
924 emit_insn (gen_movsi (zero_tmp
, const0_rtx
));
926 gen_fn
= (branch_type
== CMP_SI
927 ? gen_movsicc_internal0
928 : gen_movsicc_internal1
);
929 emit_insn (gen_fn (dest
, XEXP (cmp
, 0), one_tmp
, zero_tmp
, cmp
));
934 /* Split OP[1] into OP[2,3] and likewise for OP[0] into OP[0,1]. MODE is
935 for the output, i.e., the input operands are twice as big as MODE. */
938 xtensa_split_operand_pair (rtx operands
[4], enum machine_mode mode
)
940 switch (GET_CODE (operands
[1]))
943 operands
[3] = gen_rtx_REG (mode
, REGNO (operands
[1]) + 1);
944 operands
[2] = gen_rtx_REG (mode
, REGNO (operands
[1]));
948 operands
[3] = adjust_address (operands
[1], mode
, GET_MODE_SIZE (mode
));
949 operands
[2] = adjust_address (operands
[1], mode
, 0);
954 split_double (operands
[1], &operands
[2], &operands
[3]);
961 switch (GET_CODE (operands
[0]))
964 operands
[1] = gen_rtx_REG (mode
, REGNO (operands
[0]) + 1);
965 operands
[0] = gen_rtx_REG (mode
, REGNO (operands
[0]));
969 operands
[1] = adjust_address (operands
[0], mode
, GET_MODE_SIZE (mode
));
970 operands
[0] = adjust_address (operands
[0], mode
, 0);
979 /* Emit insns to move operands[1] into operands[0].
980 Return 1 if we have written out everything that needs to be done to
981 do the move. Otherwise, return 0 and the caller will emit the move
985 xtensa_emit_move_sequence (rtx
*operands
, enum machine_mode mode
)
987 if (CONSTANT_P (operands
[1])
988 && (GET_CODE (operands
[1]) != CONST_INT
989 || !xtensa_simm12b (INTVAL (operands
[1]))))
992 operands
[1] = force_const_mem (SImode
, operands
[1]);
994 /* PC-relative loads are always SImode, and CONST16 is only
995 supported in the movsi pattern, so add a SUBREG for any other
1000 if (register_operand (operands
[0], mode
))
1002 operands
[0] = simplify_gen_subreg (SImode
, operands
[0], mode
, 0);
1003 emit_move_insn (operands
[0], operands
[1]);
1008 operands
[1] = force_reg (SImode
, operands
[1]);
1009 operands
[1] = gen_lowpart_SUBREG (mode
, operands
[1]);
1014 if (!(reload_in_progress
| reload_completed
)
1015 && !xtensa_valid_move (mode
, operands
))
1016 operands
[1] = force_reg (mode
, operands
[1]);
1018 operands
[1] = xtensa_copy_incoming_a7 (operands
[1]);
1020 /* During reload we don't want to emit (subreg:X (mem:Y)) since that
1021 instruction won't be recognized after reload, so we remove the
1022 subreg and adjust mem accordingly. */
1023 if (reload_in_progress
)
1025 operands
[0] = fixup_subreg_mem (operands
[0]);
1026 operands
[1] = fixup_subreg_mem (operands
[1]);
1033 fixup_subreg_mem (rtx x
)
1035 if (GET_CODE (x
) == SUBREG
1036 && GET_CODE (SUBREG_REG (x
)) == REG
1037 && REGNO (SUBREG_REG (x
)) >= FIRST_PSEUDO_REGISTER
)
1040 gen_rtx_SUBREG (GET_MODE (x
),
1041 reg_equiv_mem
[REGNO (SUBREG_REG (x
))],
1043 x
= alter_subreg (&temp
);
1049 /* Check if an incoming argument in a7 is expected to be used soon and
1050 if OPND is a register or register pair that includes a7. If so,
1051 create a new pseudo and copy a7 into that pseudo at the very
1052 beginning of the function, followed by the special "set_frame_ptr"
1053 unspec_volatile insn. The return value is either the original
1054 operand, if it is not a7, or the new pseudo containing a copy of
1055 the incoming argument. This is necessary because the register
1056 allocator will ignore conflicts with a7 and may either assign some
1057 other pseudo to a7 or use a7 as the hard_frame_pointer, clobbering
1058 the incoming argument in a7. By copying the argument out of a7 as
1059 the very first thing, and then immediately following that with an
1060 unspec_volatile to keep the scheduler away, we should avoid any
1061 problems. Putting the set_frame_ptr insn at the beginning, with
1062 only the a7 copy before it, also makes it easier for the prologue
1063 expander to initialize the frame pointer after the a7 copy and to
1064 fix up the a7 copy to use the stack pointer instead of the frame
1068 xtensa_copy_incoming_a7 (rtx opnd
)
1070 rtx entry_insns
= 0;
1072 enum machine_mode mode
;
1074 if (!cfun
->machine
->need_a7_copy
)
1077 /* This function should never be called again once a7 has been copied. */
1078 gcc_assert (!cfun
->machine
->set_frame_ptr_insn
);
1080 mode
= GET_MODE (opnd
);
1082 /* The operand using a7 may come in a later instruction, so just return
1083 the original operand if it doesn't use a7. */
1085 if (GET_CODE (reg
) == SUBREG
)
1087 gcc_assert (SUBREG_BYTE (reg
) == 0);
1088 reg
= SUBREG_REG (reg
);
1090 if (GET_CODE (reg
) != REG
1091 || REGNO (reg
) > A7_REG
1092 || REGNO (reg
) + HARD_REGNO_NREGS (A7_REG
, mode
) <= A7_REG
)
1095 /* 1-word args will always be in a7; 2-word args in a6/a7. */
1096 gcc_assert (REGNO (reg
) + HARD_REGNO_NREGS (A7_REG
, mode
) - 1 == A7_REG
);
1098 cfun
->machine
->need_a7_copy
= false;
1100 /* Copy a7 to a new pseudo at the function entry. Use gen_raw_REG to
1101 create the REG for a7 so that hard_frame_pointer_rtx is not used. */
1103 push_to_sequence (entry_insns
);
1104 tmp
= gen_reg_rtx (mode
);
1110 emit_insn (gen_movsi_internal (gen_rtx_SUBREG (SImode
, tmp
, 0),
1111 gen_rtx_REG (SImode
, A7_REG
- 1)));
1112 emit_insn (gen_movsi_internal (gen_rtx_SUBREG (SImode
, tmp
, 4),
1113 gen_raw_REG (SImode
, A7_REG
)));
1116 emit_insn (gen_movsf_internal (tmp
, gen_raw_REG (mode
, A7_REG
)));
1119 emit_insn (gen_movsi_internal (tmp
, gen_raw_REG (mode
, A7_REG
)));
1122 emit_insn (gen_movhi_internal (tmp
, gen_raw_REG (mode
, A7_REG
)));
1125 emit_insn (gen_movqi_internal (tmp
, gen_raw_REG (mode
, A7_REG
)));
1131 cfun
->machine
->set_frame_ptr_insn
= emit_insn (gen_set_frame_ptr ());
1132 entry_insns
= get_insns ();
1135 if (cfun
->machine
->vararg_a7
)
1137 /* This is called from within builtin_savereg, so we're already
1138 inside a start_sequence that will be placed at the start of
1140 emit_insn (entry_insns
);
1144 /* Put entry_insns after the NOTE that starts the function. If
1145 this is inside a start_sequence, make the outer-level insn
1146 chain current, so the code is placed at the start of the
1148 push_topmost_sequence ();
1149 emit_insn_after (entry_insns
, get_insns ());
1150 pop_topmost_sequence ();
1157 /* Try to expand a block move operation to a sequence of RTL move
1158 instructions. If not optimizing, or if the block size is not a
1159 constant, or if the block is too large, the expansion fails and GCC
1160 falls back to calling memcpy().
1162 operands[0] is the destination
1163 operands[1] is the source
1164 operands[2] is the length
1165 operands[3] is the alignment */
1168 xtensa_expand_block_move (rtx
*operands
)
1170 static const enum machine_mode mode_from_align
[] =
1172 VOIDmode
, QImode
, HImode
, VOIDmode
, SImode
,
1175 rtx dst_mem
= operands
[0];
1176 rtx src_mem
= operands
[1];
1177 HOST_WIDE_INT bytes
, align
;
1178 int num_pieces
, move_ratio
;
1180 enum machine_mode mode
[2];
1189 /* If this is not a fixed size move, just call memcpy. */
1190 if (!optimize
|| (GET_CODE (operands
[2]) != CONST_INT
))
1193 bytes
= INTVAL (operands
[2]);
1194 align
= INTVAL (operands
[3]);
1196 /* Anything to move? */
1200 if (align
> MOVE_MAX
)
1203 /* Decide whether to expand inline based on the optimization level. */
1206 move_ratio
= LARGEST_MOVE_RATIO
;
1207 num_pieces
= (bytes
/ align
) + (bytes
% align
); /* Close enough anyway. */
1208 if (num_pieces
> move_ratio
)
1211 x
= XEXP (dst_mem
, 0);
1214 x
= force_reg (Pmode
, x
);
1215 dst_mem
= replace_equiv_address (dst_mem
, x
);
1218 x
= XEXP (src_mem
, 0);
1221 x
= force_reg (Pmode
, x
);
1222 src_mem
= replace_equiv_address (src_mem
, x
);
1225 active
[0] = active
[1] = false;
1236 next_amount
= (bytes
>= 4 ? 4 : (bytes
>= 2 ? 2 : 1));
1237 next_amount
= MIN (next_amount
, align
);
1239 amount
[next
] = next_amount
;
1240 mode
[next
] = mode_from_align
[next_amount
];
1241 temp
[next
] = gen_reg_rtx (mode
[next
]);
1243 x
= adjust_address (src_mem
, mode
[next
], offset_ld
);
1244 emit_insn (gen_rtx_SET (VOIDmode
, temp
[next
], x
));
1246 offset_ld
+= next_amount
;
1247 bytes
-= next_amount
;
1248 active
[next
] = true;
1253 active
[phase
] = false;
1255 x
= adjust_address (dst_mem
, mode
[phase
], offset_st
);
1256 emit_insn (gen_rtx_SET (VOIDmode
, x
, temp
[phase
]));
1258 offset_st
+= amount
[phase
];
1261 while (active
[next
]);
1268 xtensa_expand_nonlocal_goto (rtx
*operands
)
1270 rtx goto_handler
= operands
[1];
1271 rtx containing_fp
= operands
[3];
1273 /* Generate a call to "__xtensa_nonlocal_goto" (in libgcc); the code
1274 is too big to generate in-line. */
1276 if (GET_CODE (containing_fp
) != REG
)
1277 containing_fp
= force_reg (Pmode
, containing_fp
);
1279 goto_handler
= replace_rtx (copy_rtx (goto_handler
),
1280 virtual_stack_vars_rtx
,
1283 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "__xtensa_nonlocal_goto"),
1285 containing_fp
, Pmode
,
1286 goto_handler
, Pmode
);
1290 static struct machine_function
*
1291 xtensa_init_machine_status (void)
1293 return ggc_alloc_cleared (sizeof (struct machine_function
));
1298 xtensa_setup_frame_addresses (void)
1300 /* Set flag to cause FRAME_POINTER_REQUIRED to be set. */
1301 cfun
->machine
->accesses_prev_frame
= 1;
1304 (gen_rtx_SYMBOL_REF (Pmode
, "__xtensa_libgcc_window_spill"),
1309 /* Emit the assembly for the end of a zero-cost loop. Normally we just emit
1310 a comment showing where the end of the loop is. However, if there is a
1311 label or a branch at the end of the loop then we need to place a nop
1312 there. If the loop ends with a label we need the nop so that branches
1313 targeting that label will target the nop (and thus remain in the loop),
1314 instead of targeting the instruction after the loop (and thus exiting
1315 the loop). If the loop ends with a branch, we need the nop in case the
1316 branch is targeting a location inside the loop. When the branch
1317 executes it will cause the loop count to be decremented even if it is
1318 taken (because it is the last instruction in the loop), so we need to
1319 nop after the branch to prevent the loop count from being decremented
1320 when the branch is taken. */
1323 xtensa_emit_loop_end (rtx insn
, rtx
*operands
)
1327 for (insn
= PREV_INSN (insn
); insn
&& !done
; insn
= PREV_INSN (insn
))
1329 switch (GET_CODE (insn
))
1336 output_asm_insn (TARGET_DENSITY
? "nop.n" : "nop", operands
);
1342 rtx body
= PATTERN (insn
);
1344 if (GET_CODE (body
) == JUMP_INSN
)
1346 output_asm_insn (TARGET_DENSITY
? "nop.n" : "nop", operands
);
1349 else if ((GET_CODE (body
) != USE
)
1350 && (GET_CODE (body
) != CLOBBER
))
1357 output_asm_insn ("# loop end for %0", operands
);
1362 xtensa_emit_call (int callop
, rtx
*operands
)
1364 static char result
[64];
1365 rtx tgt
= operands
[callop
];
1367 if (GET_CODE (tgt
) == CONST_INT
)
1368 sprintf (result
, "call8\t0x%lx", INTVAL (tgt
));
1369 else if (register_operand (tgt
, VOIDmode
))
1370 sprintf (result
, "callx8\t%%%d", callop
);
1372 sprintf (result
, "call8\t%%%d", callop
);
1378 /* Return the debugger register number to use for 'regno'. */
1381 xtensa_dbx_register_number (int regno
)
1385 if (GP_REG_P (regno
))
1387 regno
-= GP_REG_FIRST
;
1390 else if (BR_REG_P (regno
))
1392 regno
-= BR_REG_FIRST
;
1395 else if (FP_REG_P (regno
))
1397 regno
-= FP_REG_FIRST
;
1400 else if (ACC_REG_P (regno
))
1402 first
= 0x200; /* Start of Xtensa special registers. */
1403 regno
= 16; /* ACCLO is special register 16. */
1406 /* When optimizing, we sometimes get asked about pseudo-registers
1407 that don't represent hard registers. Return 0 for these. */
1411 return first
+ regno
;
1415 /* Argument support functions. */
1417 /* Initialize CUMULATIVE_ARGS for a function. */
1420 init_cumulative_args (CUMULATIVE_ARGS
*cum
, int incoming
)
1423 cum
->incoming
= incoming
;
1427 /* Advance the argument to the next argument position. */
1430 function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
)
1435 arg_words
= &cum
->arg_words
;
1436 max
= MAX_ARGS_IN_REGISTERS
;
1438 words
= (((mode
!= BLKmode
)
1439 ? (int) GET_MODE_SIZE (mode
)
1440 : int_size_in_bytes (type
)) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1442 if (*arg_words
< max
1443 && (targetm
.calls
.must_pass_in_stack (mode
, type
)
1444 || *arg_words
+ words
> max
))
1447 *arg_words
+= words
;
1451 /* Return an RTL expression containing the register for the given mode,
1452 or 0 if the argument is to be passed on the stack. INCOMING_P is nonzero
1453 if this is an incoming argument to the current function. */
1456 function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
1459 int regbase
, words
, max
;
1463 arg_words
= &cum
->arg_words
;
1464 regbase
= (incoming_p
? GP_ARG_FIRST
: GP_OUTGOING_ARG_FIRST
);
1465 max
= MAX_ARGS_IN_REGISTERS
;
1467 words
= (((mode
!= BLKmode
)
1468 ? (int) GET_MODE_SIZE (mode
)
1469 : int_size_in_bytes (type
)) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1471 if (type
&& (TYPE_ALIGN (type
) > BITS_PER_WORD
))
1473 int align
= TYPE_ALIGN (type
) / BITS_PER_WORD
;
1474 *arg_words
= (*arg_words
+ align
- 1) & -align
;
1477 if (*arg_words
+ words
> max
)
1480 regno
= regbase
+ *arg_words
;
1482 if (cum
->incoming
&& regno
<= A7_REG
&& regno
+ words
> A7_REG
)
1483 cfun
->machine
->need_a7_copy
= true;
1485 return gen_rtx_REG (mode
, regno
);
1490 xtensa_return_in_msb (tree valtype
)
1492 return (TARGET_BIG_ENDIAN
1493 && AGGREGATE_TYPE_P (valtype
)
1494 && int_size_in_bytes (valtype
) >= UNITS_PER_WORD
);
1499 override_options (void)
1502 enum machine_mode mode
;
1504 if (!TARGET_BOOLEANS
&& TARGET_HARD_FLOAT
)
1505 error ("boolean registers required for the floating-point option");
1507 xtensa_char_to_class
['q'] = SP_REG
;
1508 xtensa_char_to_class
['a'] = GR_REGS
;
1509 xtensa_char_to_class
['b'] = ((TARGET_BOOLEANS
) ? BR_REGS
: NO_REGS
);
1510 xtensa_char_to_class
['f'] = ((TARGET_HARD_FLOAT
) ? FP_REGS
: NO_REGS
);
1511 xtensa_char_to_class
['A'] = ((TARGET_MAC16
) ? ACC_REG
: NO_REGS
);
1512 xtensa_char_to_class
['B'] = ((TARGET_SEXT
) ? GR_REGS
: NO_REGS
);
1513 xtensa_char_to_class
['C'] = ((TARGET_MUL16
) ? GR_REGS
: NO_REGS
);
1514 xtensa_char_to_class
['D'] = ((TARGET_DENSITY
) ? GR_REGS
: NO_REGS
);
1515 xtensa_char_to_class
['d'] = ((TARGET_DENSITY
) ? AR_REGS
: NO_REGS
);
1516 xtensa_char_to_class
['W'] = ((TARGET_CONST16
) ? GR_REGS
: NO_REGS
);
1518 /* Set up array giving whether a given register can hold a given mode. */
1519 for (mode
= VOIDmode
;
1520 mode
!= MAX_MACHINE_MODE
;
1521 mode
= (enum machine_mode
) ((int) mode
+ 1))
1523 int size
= GET_MODE_SIZE (mode
);
1524 enum mode_class
class = GET_MODE_CLASS (mode
);
1526 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1530 if (ACC_REG_P (regno
))
1531 temp
= (TARGET_MAC16
1532 && (class == MODE_INT
) && (size
<= UNITS_PER_WORD
));
1533 else if (GP_REG_P (regno
))
1534 temp
= ((regno
& 1) == 0 || (size
<= UNITS_PER_WORD
));
1535 else if (FP_REG_P (regno
))
1536 temp
= (TARGET_HARD_FLOAT
&& (mode
== SFmode
));
1537 else if (BR_REG_P (regno
))
1538 temp
= (TARGET_BOOLEANS
&& (mode
== CCmode
));
1542 xtensa_hard_regno_mode_ok
[(int) mode
][regno
] = temp
;
1546 init_machine_status
= xtensa_init_machine_status
;
1548 /* Check PIC settings. PIC is only supported when using L32R
1549 instructions, and some targets need to always use PIC. */
1550 if (flag_pic
&& TARGET_CONST16
)
1551 error ("-f%s is not supported with CONST16 instructions",
1552 (flag_pic
> 1 ? "PIC" : "pic"));
1553 else if (XTENSA_ALWAYS_PIC
)
1556 error ("PIC is required but not supported with CONST16 instructions");
1559 /* There's no need for -fPIC (as opposed to -fpic) on Xtensa. */
1563 /* Hot/cold partitioning does not work on this architecture, because of
1564 constant pools (the load instruction cannot necessarily reach that far).
1565 Therefore disable it on this architecture. */
1566 if (flag_reorder_blocks_and_partition
)
1568 flag_reorder_blocks_and_partition
= 0;
1569 flag_reorder_blocks
= 1;
1574 /* A C compound statement to output to stdio stream STREAM the
1575 assembler syntax for an instruction operand X. X is an RTL
1578 CODE is a value that can be used to specify one of several ways
1579 of printing the operand. It is used when identical operands
1580 must be printed differently depending on the context. CODE
1581 comes from the '%' specification that was used to request
1582 printing of the operand. If the specification was just '%DIGIT'
1583 then CODE is 0; if the specification was '%LTR DIGIT' then CODE
1584 is the ASCII code for LTR.
1586 If X is a register, this macro should print the register's name.
1587 The names can be found in an array 'reg_names' whose type is
1588 'char *[]'. 'reg_names' is initialized from 'REGISTER_NAMES'.
1590 When the machine description has a specification '%PUNCT' (a '%'
1591 followed by a punctuation character), this macro is called with
1592 a null pointer for X and the punctuation character for CODE.
1594 'a', 'c', 'l', and 'n' are reserved.
1596 The Xtensa specific codes are:
1598 'd' CONST_INT, print as signed decimal
1599 'x' CONST_INT, print as signed hexadecimal
1600 'K' CONST_INT, print number of bits in mask for EXTUI
1601 'R' CONST_INT, print (X & 0x1f)
1602 'L' CONST_INT, print ((32 - X) & 0x1f)
1603 'D' REG, print second register of double-word register operand
1604 'N' MEM, print address of next word following a memory operand
1605 'v' MEM, if memory reference is volatile, output a MEMW before it
1606 't' any constant, add "@h" suffix for top 16 bits
1607 'b' any constant, add "@l" suffix for bottom 16 bits
1611 printx (FILE *file
, signed int val
)
1613 /* Print a hexadecimal value in a nice way. */
1614 if ((val
> -0xa) && (val
< 0xa))
1615 fprintf (file
, "%d", val
);
1617 fprintf (file
, "-0x%x", -val
);
1619 fprintf (file
, "0x%x", val
);
1624 print_operand (FILE *file
, rtx x
, int letter
)
1627 error ("PRINT_OPERAND null pointer");
1632 if (GET_CODE (x
) == REG
|| GET_CODE (x
) == SUBREG
)
1633 fprintf (file
, "%s", reg_names
[xt_true_regnum (x
) + 1]);
1635 output_operand_lossage ("invalid %%D value");
1639 if (GET_CODE (x
) == MEM
)
1641 /* For a volatile memory reference, emit a MEMW before the
1643 if (MEM_VOLATILE_P (x
))
1644 fprintf (file
, "memw\n\t");
1647 output_operand_lossage ("invalid %%v value");
1651 if (GET_CODE (x
) == MEM
1652 && (GET_MODE (x
) == DFmode
|| GET_MODE (x
) == DImode
))
1654 x
= adjust_address (x
, GET_MODE (x
) == DFmode
? SFmode
: SImode
, 4);
1655 output_address (XEXP (x
, 0));
1658 output_operand_lossage ("invalid %%N value");
1662 if (GET_CODE (x
) == CONST_INT
)
1665 unsigned val
= INTVAL (x
);
1671 if ((val
!= 0) || (num_bits
== 0) || (num_bits
> 16))
1672 fatal_insn ("invalid mask", x
);
1674 fprintf (file
, "%d", num_bits
);
1677 output_operand_lossage ("invalid %%K value");
1681 if (GET_CODE (x
) == CONST_INT
)
1682 fprintf (file
, "%ld", (32 - INTVAL (x
)) & 0x1f);
1684 output_operand_lossage ("invalid %%L value");
1688 if (GET_CODE (x
) == CONST_INT
)
1689 fprintf (file
, "%ld", INTVAL (x
) & 0x1f);
1691 output_operand_lossage ("invalid %%R value");
1695 if (GET_CODE (x
) == CONST_INT
)
1696 printx (file
, INTVAL (x
));
1698 output_operand_lossage ("invalid %%x value");
1702 if (GET_CODE (x
) == CONST_INT
)
1703 fprintf (file
, "%ld", INTVAL (x
));
1705 output_operand_lossage ("invalid %%d value");
1710 if (GET_CODE (x
) == CONST_INT
)
1712 printx (file
, INTVAL (x
));
1713 fputs (letter
== 't' ? "@h" : "@l", file
);
1715 else if (GET_CODE (x
) == CONST_DOUBLE
)
1718 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
1719 if (GET_MODE (x
) == SFmode
)
1722 REAL_VALUE_TO_TARGET_SINGLE (r
, l
);
1723 fprintf (file
, "0x%08lx@%c", l
, letter
== 't' ? 'h' : 'l');
1726 output_operand_lossage ("invalid %%t/%%b value");
1728 else if (GET_CODE (x
) == CONST
)
1730 /* X must be a symbolic constant on ELF. Write an expression
1731 suitable for 'const16' that sets the high or low 16 bits. */
1732 if (GET_CODE (XEXP (x
, 0)) != PLUS
1733 || (GET_CODE (XEXP (XEXP (x
, 0), 0)) != SYMBOL_REF
1734 && GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
1735 || GET_CODE (XEXP (XEXP (x
, 0), 1)) != CONST_INT
)
1736 output_operand_lossage ("invalid %%t/%%b value");
1737 print_operand (file
, XEXP (XEXP (x
, 0), 0), 0);
1738 fputs (letter
== 't' ? "@h" : "@l", file
);
1739 /* There must be a non-alphanumeric character between 'h' or 'l'
1740 and the number. The '-' is added by print_operand() already. */
1741 if (INTVAL (XEXP (XEXP (x
, 0), 1)) >= 0)
1743 print_operand (file
, XEXP (XEXP (x
, 0), 1), 0);
1747 output_addr_const (file
, x
);
1748 fputs (letter
== 't' ? "@h" : "@l", file
);
1753 if (GET_CODE (x
) == REG
|| GET_CODE (x
) == SUBREG
)
1754 fprintf (file
, "%s", reg_names
[xt_true_regnum (x
)]);
1755 else if (GET_CODE (x
) == MEM
)
1756 output_address (XEXP (x
, 0));
1757 else if (GET_CODE (x
) == CONST_INT
)
1758 fprintf (file
, "%ld", INTVAL (x
));
1760 output_addr_const (file
, x
);
1765 /* A C compound statement to output to stdio stream STREAM the
1766 assembler syntax for an instruction operand that is a memory
1767 reference whose address is ADDR. ADDR is an RTL expression. */
1770 print_operand_address (FILE *file
, rtx addr
)
1773 error ("PRINT_OPERAND_ADDRESS, null pointer");
1775 switch (GET_CODE (addr
))
1778 fatal_insn ("invalid address", addr
);
1782 fprintf (file
, "%s, 0", reg_names
[REGNO (addr
)]);
1788 rtx offset
= (rtx
)0;
1789 rtx arg0
= XEXP (addr
, 0);
1790 rtx arg1
= XEXP (addr
, 1);
1792 if (GET_CODE (arg0
) == REG
)
1797 else if (GET_CODE (arg1
) == REG
)
1803 fatal_insn ("no register in address", addr
);
1805 if (CONSTANT_P (offset
))
1807 fprintf (file
, "%s, ", reg_names
[REGNO (reg
)]);
1808 output_addr_const (file
, offset
);
1811 fatal_insn ("address offset not a constant", addr
);
1819 output_addr_const (file
, addr
);
1826 xtensa_output_literal (FILE *file
, rtx x
, enum machine_mode mode
, int labelno
)
1832 fprintf (file
, "\t.literal .LC%u, ", (unsigned) labelno
);
1834 switch (GET_MODE_CLASS (mode
))
1837 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
1839 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
1843 REAL_VALUE_TO_TARGET_SINGLE (r
, value_long
[0]);
1844 fprintf (file
, "0x%08lx\n", value_long
[0]);
1848 REAL_VALUE_TO_TARGET_DOUBLE (r
, value_long
);
1849 fprintf (file
, "0x%08lx, 0x%08lx\n",
1850 value_long
[0], value_long
[1]);
1860 case MODE_PARTIAL_INT
:
1861 size
= GET_MODE_SIZE (mode
);
1865 output_addr_const (file
, x
);
1870 output_addr_const (file
, operand_subword (x
, 0, 0, DImode
));
1872 output_addr_const (file
, operand_subword (x
, 1, 0, DImode
));
1887 /* Return the bytes needed to compute the frame pointer from the current
1890 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
1891 #define XTENSA_STACK_ALIGN(LOC) (((LOC) + STACK_BYTES-1) & ~(STACK_BYTES-1))
1894 compute_frame_size (int size
)
1896 /* Add space for the incoming static chain value. */
1897 if (cfun
->static_chain_decl
!= NULL
)
1898 size
+= (1 * UNITS_PER_WORD
);
1900 xtensa_current_frame_size
=
1901 XTENSA_STACK_ALIGN (size
1902 + current_function_outgoing_args_size
1903 + (WINDOW_SIZE
* UNITS_PER_WORD
));
1904 return xtensa_current_frame_size
;
1909 xtensa_frame_pointer_required (void)
1911 /* The code to expand builtin_frame_addr and builtin_return_addr
1912 currently uses the hard_frame_pointer instead of frame_pointer.
1913 This seems wrong but maybe it's necessary for other architectures.
1914 This function is derived from the i386 code. */
1916 if (cfun
->machine
->accesses_prev_frame
)
1924 xtensa_expand_prologue (void)
1926 HOST_WIDE_INT total_size
;
1929 total_size
= compute_frame_size (get_frame_size ());
1930 size_rtx
= GEN_INT (total_size
);
1932 if (total_size
< (1 << (12+3)))
1933 emit_insn (gen_entry (size_rtx
, size_rtx
));
1936 /* Use a8 as a temporary since a0-a7 may be live. */
1937 rtx tmp_reg
= gen_rtx_REG (Pmode
, A8_REG
);
1938 emit_insn (gen_entry (size_rtx
, GEN_INT (MIN_FRAME_SIZE
)));
1939 emit_move_insn (tmp_reg
, GEN_INT (total_size
- MIN_FRAME_SIZE
));
1940 emit_insn (gen_subsi3 (tmp_reg
, stack_pointer_rtx
, tmp_reg
));
1941 emit_move_insn (stack_pointer_rtx
, tmp_reg
);
1944 if (frame_pointer_needed
)
1946 if (cfun
->machine
->set_frame_ptr_insn
)
1950 push_topmost_sequence ();
1951 first
= get_insns ();
1952 pop_topmost_sequence ();
1954 /* For all instructions prior to set_frame_ptr_insn, replace
1955 hard_frame_pointer references with stack_pointer. */
1957 insn
!= cfun
->machine
->set_frame_ptr_insn
;
1958 insn
= NEXT_INSN (insn
))
1961 PATTERN (insn
) = replace_rtx (copy_rtx (PATTERN (insn
)),
1962 hard_frame_pointer_rtx
,
1967 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
1972 /* Clear variables at function end. */
1975 xtensa_function_epilogue (FILE *file ATTRIBUTE_UNUSED
,
1976 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
1978 xtensa_current_frame_size
= 0;
1983 xtensa_return_addr (int count
, rtx frame
)
1985 rtx result
, retaddr
;
1988 retaddr
= gen_rtx_REG (Pmode
, A0_REG
);
1991 rtx addr
= plus_constant (frame
, -4 * UNITS_PER_WORD
);
1992 addr
= memory_address (Pmode
, addr
);
1993 retaddr
= gen_reg_rtx (Pmode
);
1994 emit_move_insn (retaddr
, gen_rtx_MEM (Pmode
, addr
));
1997 /* The 2 most-significant bits of the return address on Xtensa hold
1998 the register window size. To get the real return address, these
1999 bits must be replaced with the high bits from the current PC. */
2001 result
= gen_reg_rtx (Pmode
);
2002 emit_insn (gen_fix_return_addr (result
, retaddr
));
2007 /* Create the va_list data type.
2009 This structure is set up by __builtin_saveregs. The __va_reg field
2010 points to a stack-allocated region holding the contents of the
2011 incoming argument registers. The __va_ndx field is an index
2012 initialized to the position of the first unnamed (variable)
2013 argument. This same index is also used to address the arguments
2014 passed in memory. Thus, the __va_stk field is initialized to point
2015 to the position of the first argument in memory offset to account
2016 for the arguments passed in registers and to account for the size
2017 of the argument registers not being 16-byte aligned. E.G., there
2018 are 6 argument registers of 4 bytes each, but we want the __va_ndx
2019 for the first stack argument to have the maximal alignment of 16
2020 bytes, so we offset the __va_stk address by 32 bytes so that
2021 __va_stk[32] references the first argument on the stack. */
2024 xtensa_build_builtin_va_list (void)
2026 tree f_stk
, f_reg
, f_ndx
, record
, type_decl
;
2028 record
= (*lang_hooks
.types
.make_type
) (RECORD_TYPE
);
2029 type_decl
= build_decl (TYPE_DECL
, get_identifier ("__va_list_tag"), record
);
2031 f_stk
= build_decl (FIELD_DECL
, get_identifier ("__va_stk"),
2033 f_reg
= build_decl (FIELD_DECL
, get_identifier ("__va_reg"),
2035 f_ndx
= build_decl (FIELD_DECL
, get_identifier ("__va_ndx"),
2038 DECL_FIELD_CONTEXT (f_stk
) = record
;
2039 DECL_FIELD_CONTEXT (f_reg
) = record
;
2040 DECL_FIELD_CONTEXT (f_ndx
) = record
;
2042 TREE_CHAIN (record
) = type_decl
;
2043 TYPE_NAME (record
) = type_decl
;
2044 TYPE_FIELDS (record
) = f_stk
;
2045 TREE_CHAIN (f_stk
) = f_reg
;
2046 TREE_CHAIN (f_reg
) = f_ndx
;
2048 layout_type (record
);
2053 /* Save the incoming argument registers on the stack. Returns the
2054 address of the saved registers. */
2057 xtensa_builtin_saveregs (void)
2060 int arg_words
= current_function_args_info
.arg_words
;
2061 int gp_left
= MAX_ARGS_IN_REGISTERS
- arg_words
;
2066 /* Allocate the general-purpose register space. */
2067 gp_regs
= assign_stack_local
2068 (BLKmode
, MAX_ARGS_IN_REGISTERS
* UNITS_PER_WORD
, -1);
2069 set_mem_alias_set (gp_regs
, get_varargs_alias_set ());
2071 /* Now store the incoming registers. */
2072 dest
= change_address (gp_regs
, SImode
,
2073 plus_constant (XEXP (gp_regs
, 0),
2074 arg_words
* UNITS_PER_WORD
));
2075 cfun
->machine
->need_a7_copy
= true;
2076 cfun
->machine
->vararg_a7
= true;
2077 move_block_from_reg (GP_ARG_FIRST
+ arg_words
, dest
, gp_left
);
2079 return XEXP (gp_regs
, 0);
2083 /* Implement `va_start' for varargs and stdarg. We look at the
2084 current function to fill in an initial va_list. */
2087 xtensa_va_start (tree valist
, rtx nextarg ATTRIBUTE_UNUSED
)
2095 arg_words
= current_function_args_info
.arg_words
;
2097 f_stk
= TYPE_FIELDS (va_list_type_node
);
2098 f_reg
= TREE_CHAIN (f_stk
);
2099 f_ndx
= TREE_CHAIN (f_reg
);
2101 stk
= build3 (COMPONENT_REF
, TREE_TYPE (f_stk
), valist
, f_stk
, NULL_TREE
);
2102 reg
= build3 (COMPONENT_REF
, TREE_TYPE (f_reg
), valist
, f_reg
, NULL_TREE
);
2103 ndx
= build3 (COMPONENT_REF
, TREE_TYPE (f_ndx
), valist
, f_ndx
, NULL_TREE
);
2105 /* Call __builtin_saveregs; save the result in __va_reg */
2106 u
= make_tree (ptr_type_node
, expand_builtin_saveregs ());
2107 t
= build2 (MODIFY_EXPR
, ptr_type_node
, reg
, u
);
2108 TREE_SIDE_EFFECTS (t
) = 1;
2109 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2111 /* Set the __va_stk member to ($arg_ptr - 32). */
2112 u
= make_tree (ptr_type_node
, virtual_incoming_args_rtx
);
2113 u
= fold_build2 (PLUS_EXPR
, ptr_type_node
, u
,
2114 build_int_cst (NULL_TREE
, -32));
2115 t
= build2 (MODIFY_EXPR
, ptr_type_node
, stk
, u
);
2116 TREE_SIDE_EFFECTS (t
) = 1;
2117 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2119 /* Set the __va_ndx member. If the first variable argument is on
2120 the stack, adjust __va_ndx by 2 words to account for the extra
2121 alignment offset for __va_stk. */
2122 if (arg_words
>= MAX_ARGS_IN_REGISTERS
)
2124 u
= build_int_cst (NULL_TREE
, arg_words
* UNITS_PER_WORD
);
2125 t
= build2 (MODIFY_EXPR
, integer_type_node
, ndx
, u
);
2126 TREE_SIDE_EFFECTS (t
) = 1;
2127 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2131 /* Implement `va_arg'. */
2134 xtensa_gimplify_va_arg_expr (tree valist
, tree type
, tree
*pre_p
,
2135 tree
*post_p ATTRIBUTE_UNUSED
)
2140 tree type_size
, array
, orig_ndx
, addr
, size
, va_size
, t
;
2141 tree lab_false
, lab_over
, lab_false2
;
2144 indirect
= pass_by_reference (NULL
, TYPE_MODE (type
), type
, false);
2146 type
= build_pointer_type (type
);
2148 /* Handle complex values as separate real and imaginary parts. */
2149 if (TREE_CODE (type
) == COMPLEX_TYPE
)
2151 tree real_part
, imag_part
;
2153 real_part
= xtensa_gimplify_va_arg_expr (valist
, TREE_TYPE (type
),
2155 real_part
= get_initialized_tmp_var (real_part
, pre_p
, NULL
);
2157 imag_part
= xtensa_gimplify_va_arg_expr (valist
, TREE_TYPE (type
),
2159 imag_part
= get_initialized_tmp_var (imag_part
, pre_p
, NULL
);
2161 return build2 (COMPLEX_EXPR
, type
, real_part
, imag_part
);
2164 f_stk
= TYPE_FIELDS (va_list_type_node
);
2165 f_reg
= TREE_CHAIN (f_stk
);
2166 f_ndx
= TREE_CHAIN (f_reg
);
2168 stk
= build3 (COMPONENT_REF
, TREE_TYPE (f_stk
), valist
, f_stk
, NULL_TREE
);
2169 reg
= build3 (COMPONENT_REF
, TREE_TYPE (f_reg
), valist
, f_reg
, NULL_TREE
);
2170 ndx
= build3 (COMPONENT_REF
, TREE_TYPE (f_ndx
), valist
, f_ndx
, NULL_TREE
);
2172 type_size
= size_in_bytes (type
);
2173 va_size
= round_up (type_size
, UNITS_PER_WORD
);
2174 gimplify_expr (&va_size
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
2177 /* First align __va_ndx if necessary for this arg:
2179 orig_ndx = (AP).__va_ndx;
2180 if (__alignof__ (TYPE) > 4 )
2181 orig_ndx = ((orig_ndx + __alignof__ (TYPE) - 1)
2182 & -__alignof__ (TYPE)); */
2184 orig_ndx
= get_initialized_tmp_var (ndx
, pre_p
, NULL
);
2186 if (TYPE_ALIGN (type
) > BITS_PER_WORD
)
2188 int align
= TYPE_ALIGN (type
) / BITS_PER_UNIT
;
2190 t
= build2 (PLUS_EXPR
, integer_type_node
, orig_ndx
,
2191 build_int_cst (NULL_TREE
, align
- 1));
2192 t
= build2 (BIT_AND_EXPR
, integer_type_node
, t
,
2193 build_int_cst (NULL_TREE
, -align
));
2194 t
= build2 (MODIFY_EXPR
, integer_type_node
, orig_ndx
, t
);
2195 gimplify_and_add (t
, pre_p
);
2199 /* Increment __va_ndx to point past the argument:
2201 (AP).__va_ndx = orig_ndx + __va_size (TYPE); */
2203 t
= fold_convert (integer_type_node
, va_size
);
2204 t
= build2 (PLUS_EXPR
, integer_type_node
, orig_ndx
, t
);
2205 t
= build2 (MODIFY_EXPR
, integer_type_node
, ndx
, t
);
2206 gimplify_and_add (t
, pre_p
);
2209 /* Check if the argument is in registers:
2211 if ((AP).__va_ndx <= __MAX_ARGS_IN_REGISTERS * 4
2212 && !must_pass_in_stack (type))
2213 __array = (AP).__va_reg; */
2215 array
= create_tmp_var (ptr_type_node
, NULL
);
2218 if (!targetm
.calls
.must_pass_in_stack (TYPE_MODE (type
), type
))
2220 lab_false
= create_artificial_label ();
2221 lab_over
= create_artificial_label ();
2223 t
= build_int_cst (NULL_TREE
, MAX_ARGS_IN_REGISTERS
* UNITS_PER_WORD
);
2224 t
= build2 (GT_EXPR
, boolean_type_node
, ndx
, t
);
2225 t
= build3 (COND_EXPR
, void_type_node
, t
,
2226 build1 (GOTO_EXPR
, void_type_node
, lab_false
),
2228 gimplify_and_add (t
, pre_p
);
2230 t
= build2 (MODIFY_EXPR
, void_type_node
, array
, reg
);
2231 gimplify_and_add (t
, pre_p
);
2233 t
= build1 (GOTO_EXPR
, void_type_node
, lab_over
);
2234 gimplify_and_add (t
, pre_p
);
2236 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false
);
2237 gimplify_and_add (t
, pre_p
);
2241 /* ...otherwise, the argument is on the stack (never split between
2242 registers and the stack -- change __va_ndx if necessary):
2246 if (orig_ndx <= __MAX_ARGS_IN_REGISTERS * 4)
2247 (AP).__va_ndx = 32 + __va_size (TYPE);
2248 __array = (AP).__va_stk;
2251 lab_false2
= create_artificial_label ();
2253 t
= build_int_cst (NULL_TREE
, MAX_ARGS_IN_REGISTERS
* UNITS_PER_WORD
);
2254 t
= build2 (GT_EXPR
, boolean_type_node
, orig_ndx
, t
);
2255 t
= build3 (COND_EXPR
, void_type_node
, t
,
2256 build1 (GOTO_EXPR
, void_type_node
, lab_false2
),
2258 gimplify_and_add (t
, pre_p
);
2260 t
= size_binop (PLUS_EXPR
, va_size
, size_int (32));
2261 t
= fold_convert (integer_type_node
, t
);
2262 t
= build2 (MODIFY_EXPR
, integer_type_node
, ndx
, t
);
2263 gimplify_and_add (t
, pre_p
);
2265 t
= build1 (LABEL_EXPR
, void_type_node
, lab_false2
);
2266 gimplify_and_add (t
, pre_p
);
2268 t
= build2 (MODIFY_EXPR
, void_type_node
, array
, stk
);
2269 gimplify_and_add (t
, pre_p
);
2273 t
= build1 (LABEL_EXPR
, void_type_node
, lab_over
);
2274 gimplify_and_add (t
, pre_p
);
2278 /* Given the base array pointer (__array) and index to the subsequent
2279 argument (__va_ndx), find the address:
2281 __array + (AP).__va_ndx - (BYTES_BIG_ENDIAN && sizeof (TYPE) < 4
2285 The results are endian-dependent because values smaller than one word
2286 are aligned differently. */
2289 if (BYTES_BIG_ENDIAN
&& TREE_CODE (type_size
) == INTEGER_CST
)
2291 t
= size_int (PARM_BOUNDARY
/ BITS_PER_UNIT
);
2292 t
= fold_build2 (GE_EXPR
, boolean_type_node
, type_size
, t
);
2293 t
= fold_build3 (COND_EXPR
, sizetype
, t
, va_size
, type_size
);
2299 t
= fold_convert (ptr_type_node
, ndx
);
2300 addr
= build2 (PLUS_EXPR
, ptr_type_node
, array
, t
);
2301 t
= fold_convert (ptr_type_node
, size
);
2302 addr
= build2 (MINUS_EXPR
, ptr_type_node
, addr
, t
);
2304 addr
= fold_convert (build_pointer_type (type
), addr
);
2306 addr
= build_va_arg_indirect_ref (addr
);
2307 return build_va_arg_indirect_ref (addr
);
2312 xtensa_preferred_reload_class (rtx x
, enum reg_class
class, int isoutput
)
2314 if (!isoutput
&& CONSTANT_P (x
) && GET_CODE (x
) == CONST_DOUBLE
)
2317 /* Don't use the stack pointer or hard frame pointer for reloads!
2318 The hard frame pointer would normally be OK except that it may
2319 briefly hold an incoming argument in the prologue, and reload
2320 won't know that it is live because the hard frame pointer is
2321 treated specially. */
2323 if (class == AR_REGS
|| class == GR_REGS
)
2331 xtensa_secondary_reload_class (enum reg_class
class,
2332 enum machine_mode mode ATTRIBUTE_UNUSED
,
2333 rtx x
, int isoutput
)
2337 if (GET_CODE (x
) == SIGN_EXTEND
)
2339 regno
= xt_true_regnum (x
);
2343 if (class == FP_REGS
&& constantpool_mem_p (x
))
2347 if (ACC_REG_P (regno
))
2348 return ((class == GR_REGS
|| class == RL_REGS
) ? NO_REGS
: RL_REGS
);
2349 if (class == ACC_REG
)
2350 return (GP_REG_P (regno
) ? NO_REGS
: RL_REGS
);
2357 order_regs_for_local_alloc (void)
2359 if (!leaf_function_p ())
2361 memcpy (reg_alloc_order
, reg_nonleaf_alloc_order
,
2362 FIRST_PSEUDO_REGISTER
* sizeof (int));
2366 int i
, num_arg_regs
;
2369 /* Use the AR registers in increasing order (skipping a0 and a1)
2370 but save the incoming argument registers for a last resort. */
2371 num_arg_regs
= current_function_args_info
.arg_words
;
2372 if (num_arg_regs
> MAX_ARGS_IN_REGISTERS
)
2373 num_arg_regs
= MAX_ARGS_IN_REGISTERS
;
2374 for (i
= GP_ARG_FIRST
; i
< 16 - num_arg_regs
; i
++)
2375 reg_alloc_order
[nxt
++] = i
+ num_arg_regs
;
2376 for (i
= 0; i
< num_arg_regs
; i
++)
2377 reg_alloc_order
[nxt
++] = GP_ARG_FIRST
+ i
;
2379 /* List the coprocessor registers in order. */
2380 for (i
= 0; i
< BR_REG_NUM
; i
++)
2381 reg_alloc_order
[nxt
++] = BR_REG_FIRST
+ i
;
2383 /* List the FP registers in order for now. */
2384 for (i
= 0; i
< 16; i
++)
2385 reg_alloc_order
[nxt
++] = FP_REG_FIRST
+ i
;
2387 /* GCC requires that we list *all* the registers.... */
2388 reg_alloc_order
[nxt
++] = 0; /* a0 = return address */
2389 reg_alloc_order
[nxt
++] = 1; /* a1 = stack pointer */
2390 reg_alloc_order
[nxt
++] = 16; /* pseudo frame pointer */
2391 reg_alloc_order
[nxt
++] = 17; /* pseudo arg pointer */
2393 reg_alloc_order
[nxt
++] = ACC_REG_FIRST
; /* MAC16 accumulator */
2398 /* Some Xtensa targets support multiple bss sections. If the section
2399 name ends with ".bss", add SECTION_BSS to the flags. */
2402 xtensa_multibss_section_type_flags (tree decl
, const char *name
, int reloc
)
2404 unsigned int flags
= default_section_type_flags (decl
, name
, reloc
);
2407 suffix
= strrchr (name
, '.');
2408 if (suffix
&& strcmp (suffix
, ".bss") == 0)
2410 if (!decl
|| (TREE_CODE (decl
) == VAR_DECL
2411 && DECL_INITIAL (decl
) == NULL_TREE
))
2412 flags
|= SECTION_BSS
; /* @nobits */
2414 warning (0, "only uninitialized variables can be placed in a "
2422 /* The literal pool stays with the function. */
2425 xtensa_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
2426 rtx x ATTRIBUTE_UNUSED
,
2427 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
2429 return function_section (current_function_decl
);
2433 /* Compute a (partial) cost for rtx X. Return true if the complete
2434 cost has been computed, and false if subexpressions should be
2435 scanned. In either case, *TOTAL contains the cost result. */
2438 xtensa_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2446 if (xtensa_simm12b (INTVAL (x
)))
2453 if (xtensa_simm8 (INTVAL (x
))
2454 || xtensa_simm8x256 (INTVAL (x
)))
2461 if (xtensa_mask_immediate (INTVAL (x
)))
2468 if ((INTVAL (x
) == 0) || xtensa_b4const (INTVAL (x
)))
2479 /* No way to tell if X is the 2nd operand so be conservative. */
2482 if (xtensa_simm12b (INTVAL (x
)))
2484 else if (TARGET_CONST16
)
2485 *total
= COSTS_N_INSNS (2);
2494 *total
= COSTS_N_INSNS (2);
2501 *total
= COSTS_N_INSNS (4);
2509 (GET_MODE_SIZE (GET_MODE (x
)) > UNITS_PER_WORD
) ? 2 : 1;
2511 if (memory_address_p (GET_MODE (x
), XEXP ((x
), 0)))
2512 *total
= COSTS_N_INSNS (num_words
);
2514 *total
= COSTS_N_INSNS (2*num_words
);
2519 *total
= COSTS_N_INSNS (TARGET_NSA
? 5 : 50);
2523 *total
= COSTS_N_INSNS ((GET_MODE (x
) == DImode
) ? 3 : 2);
2529 if (GET_MODE (x
) == DImode
)
2530 *total
= COSTS_N_INSNS (2);
2532 *total
= COSTS_N_INSNS (1);
2538 if (GET_MODE (x
) == DImode
)
2539 *total
= COSTS_N_INSNS (50);
2541 *total
= COSTS_N_INSNS (1);
2546 enum machine_mode xmode
= GET_MODE (x
);
2547 if (xmode
== SFmode
)
2548 *total
= COSTS_N_INSNS (TARGET_HARD_FLOAT
? 1 : 50);
2549 else if (xmode
== DFmode
)
2550 *total
= COSTS_N_INSNS (50);
2552 *total
= COSTS_N_INSNS (4);
2559 enum machine_mode xmode
= GET_MODE (x
);
2560 if (xmode
== SFmode
)
2561 *total
= COSTS_N_INSNS (TARGET_HARD_FLOAT
? 1 : 50);
2562 else if (xmode
== DFmode
|| xmode
== DImode
)
2563 *total
= COSTS_N_INSNS (50);
2565 *total
= COSTS_N_INSNS (1);
2570 *total
= COSTS_N_INSNS ((GET_MODE (x
) == DImode
) ? 4 : 2);
2575 enum machine_mode xmode
= GET_MODE (x
);
2576 if (xmode
== SFmode
)
2577 *total
= COSTS_N_INSNS (TARGET_HARD_FLOAT
? 4 : 50);
2578 else if (xmode
== DFmode
|| xmode
== DImode
)
2579 *total
= COSTS_N_INSNS (50);
2580 else if (TARGET_MUL32
)
2581 *total
= COSTS_N_INSNS (4);
2582 else if (TARGET_MAC16
)
2583 *total
= COSTS_N_INSNS (16);
2584 else if (TARGET_MUL16
)
2585 *total
= COSTS_N_INSNS (12);
2587 *total
= COSTS_N_INSNS (50);
2594 enum machine_mode xmode
= GET_MODE (x
);
2595 if (xmode
== SFmode
)
2597 *total
= COSTS_N_INSNS (TARGET_HARD_FLOAT_DIV
? 8 : 50);
2600 else if (xmode
== DFmode
)
2602 *total
= COSTS_N_INSNS (50);
2611 enum machine_mode xmode
= GET_MODE (x
);
2612 if (xmode
== DImode
)
2613 *total
= COSTS_N_INSNS (50);
2614 else if (TARGET_DIV32
)
2615 *total
= COSTS_N_INSNS (32);
2617 *total
= COSTS_N_INSNS (50);
2622 if (GET_MODE (x
) == SFmode
)
2623 *total
= COSTS_N_INSNS (TARGET_HARD_FLOAT_SQRT
? 8 : 50);
2625 *total
= COSTS_N_INSNS (50);
2632 *total
= COSTS_N_INSNS (TARGET_MINMAX
? 1 : 50);
2637 *total
= COSTS_N_INSNS (TARGET_SEXT
? 1 : 2);
2642 *total
= COSTS_N_INSNS (1);
2650 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2653 xtensa_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
2655 return ((unsigned HOST_WIDE_INT
) int_size_in_bytes (type
)
2656 > 4 * UNITS_PER_WORD
);
2659 #include "gt-xtensa.h"