]> gcc.gnu.org Git - gcc.git/blob - gcc/config/arm/arm.c
configure.in (arm*-*-eabi*): New target.
[gcc.git] / gcc / config / arm / arm.c
1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
5 and Martin Simmons (@harleqn.co.uk).
6 More major hacks by Richard Earnshaw (rearnsha@arm.com).
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published
12 by the Free Software Foundation; either version 2, or (at your
13 option) any later version.
14
15 GCC is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "rtl.h"
30 #include "tree.h"
31 #include "obstack.h"
32 #include "regs.h"
33 #include "hard-reg-set.h"
34 #include "real.h"
35 #include "insn-config.h"
36 #include "conditions.h"
37 #include "output.h"
38 #include "insn-attr.h"
39 #include "flags.h"
40 #include "reload.h"
41 #include "function.h"
42 #include "expr.h"
43 #include "optabs.h"
44 #include "toplev.h"
45 #include "recog.h"
46 #include "ggc.h"
47 #include "except.h"
48 #include "c-pragma.h"
49 #include "integrate.h"
50 #include "tm_p.h"
51 #include "target.h"
52 #include "target-def.h"
53 #include "debug.h"
54 #include "langhooks.h"
55
56 /* Forward definitions of types. */
57 typedef struct minipool_node Mnode;
58 typedef struct minipool_fixup Mfix;
59
60 const struct attribute_spec arm_attribute_table[];
61
62 /* Forward function declarations. */
63 static arm_stack_offsets *arm_get_frame_offsets (void);
64 static void arm_add_gc_roots (void);
65 static int arm_gen_constant (enum rtx_code, enum machine_mode, rtx,
66 HOST_WIDE_INT, rtx, rtx, int, int);
67 static unsigned bit_count (unsigned long);
68 static int arm_address_register_rtx_p (rtx, int);
69 static int arm_legitimate_index_p (enum machine_mode, rtx, RTX_CODE, int);
70 static int thumb_base_register_rtx_p (rtx, enum machine_mode, int);
71 inline static int thumb_index_register_rtx_p (rtx, int);
72 static int thumb_far_jump_used_p (void);
73 static int const_ok_for_op (HOST_WIDE_INT, enum rtx_code);
74 static rtx emit_multi_reg_push (int);
75 static rtx emit_sfm (int, int);
76 #ifndef AOF_ASSEMBLER
77 static bool arm_assemble_integer (rtx, unsigned int, int);
78 #endif
79 static const char *fp_const_from_val (REAL_VALUE_TYPE *);
80 static arm_cc get_arm_condition_code (rtx);
81 static HOST_WIDE_INT int_log2 (HOST_WIDE_INT);
82 static rtx is_jump_table (rtx);
83 static const char *output_multi_immediate (rtx *, const char *, const char *,
84 int, HOST_WIDE_INT);
85 static void print_multi_reg (FILE *, const char *, int, int);
86 static const char *shift_op (rtx, HOST_WIDE_INT *);
87 static struct machine_function *arm_init_machine_status (void);
88 static int number_of_first_bit_set (int);
89 static void replace_symbols_in_block (tree, rtx, rtx);
90 static void thumb_exit (FILE *, int);
91 static void thumb_pushpop (FILE *, int, int, int *, int);
92 static rtx is_jump_table (rtx);
93 static HOST_WIDE_INT get_jump_table_size (rtx);
94 static Mnode *move_minipool_fix_forward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
95 static Mnode *add_minipool_forward_ref (Mfix *);
96 static Mnode *move_minipool_fix_backward_ref (Mnode *, Mnode *, HOST_WIDE_INT);
97 static Mnode *add_minipool_backward_ref (Mfix *);
98 static void assign_minipool_offsets (Mfix *);
99 static void arm_print_value (FILE *, rtx);
100 static void dump_minipool (rtx);
101 static int arm_barrier_cost (rtx);
102 static Mfix *create_fix_barrier (Mfix *, HOST_WIDE_INT);
103 static void push_minipool_barrier (rtx, HOST_WIDE_INT);
104 static void push_minipool_fix (rtx, HOST_WIDE_INT, rtx *, enum machine_mode,
105 rtx);
106 static void arm_reorg (void);
107 static bool note_invalid_constants (rtx, HOST_WIDE_INT, int);
108 static int current_file_function_operand (rtx);
109 static unsigned long arm_compute_save_reg0_reg12_mask (void);
110 static unsigned long arm_compute_save_reg_mask (void);
111 static unsigned long arm_isr_value (tree);
112 static unsigned long arm_compute_func_type (void);
113 static tree arm_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
114 static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
115 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
116 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
117 static void thumb_output_function_prologue (FILE *, HOST_WIDE_INT);
118 static int arm_comp_type_attributes (tree, tree);
119 static void arm_set_default_type_attributes (tree);
120 static int arm_adjust_cost (rtx, rtx, rtx, int);
121 static int count_insns_for_constant (HOST_WIDE_INT, int);
122 static int arm_get_strip_length (int);
123 static bool arm_function_ok_for_sibcall (tree, tree);
124 static void arm_internal_label (FILE *, const char *, unsigned long);
125 static void arm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
126 tree);
127 static int arm_rtx_costs_1 (rtx, enum rtx_code, enum rtx_code);
128 static bool arm_slowmul_rtx_costs (rtx, int, int, int *);
129 static bool arm_fastmul_rtx_costs (rtx, int, int, int *);
130 static bool arm_xscale_rtx_costs (rtx, int, int, int *);
131 static bool arm_9e_rtx_costs (rtx, int, int, int *);
132 static int arm_address_cost (rtx);
133 static bool arm_memory_load_p (rtx);
134 static bool arm_cirrus_insn_p (rtx);
135 static void cirrus_reorg (rtx);
136 static void arm_init_builtins (void);
137 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
138 static void arm_init_iwmmxt_builtins (void);
139 static rtx safe_vector_operand (rtx, enum machine_mode);
140 static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
141 static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
142 static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
143 static void emit_constant_insn (rtx cond, rtx pattern);
144
145 #ifdef OBJECT_FORMAT_ELF
146 static void arm_elf_asm_named_section (const char *, unsigned int);
147 #endif
148 #ifndef ARM_PE
149 static void arm_encode_section_info (tree, rtx, int);
150 #endif
151 #ifdef AOF_ASSEMBLER
152 static void aof_globalize_label (FILE *, const char *);
153 static void aof_dump_imports (FILE *);
154 static void aof_dump_pic_table (FILE *);
155 static void aof_file_start (void);
156 static void aof_file_end (void);
157 #endif
158 static rtx arm_struct_value_rtx (tree, int);
159 static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
160 tree, int *, int);
161 static bool arm_pass_by_reference (CUMULATIVE_ARGS *,
162 enum machine_mode, tree, bool);
163 static bool arm_promote_prototypes (tree);
164 static bool arm_default_short_enums (void);
165 static bool arm_align_anon_bitfield (void);
166
167 static tree arm_cxx_guard_type (void);
168 static bool arm_cxx_guard_mask_bit (void);
169 static tree arm_get_cookie_size (tree);
170 static bool arm_cookie_has_size (void);
171 static bool arm_cxx_cdtor_returns_this (void);
172 static void arm_init_libfuncs (void);
173
174 \f
175 /* Initialize the GCC target structure. */
176 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
177 #undef TARGET_MERGE_DECL_ATTRIBUTES
178 #define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
179 #endif
180
181 #undef TARGET_ATTRIBUTE_TABLE
182 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
183
184 #ifdef AOF_ASSEMBLER
185 #undef TARGET_ASM_BYTE_OP
186 #define TARGET_ASM_BYTE_OP "\tDCB\t"
187 #undef TARGET_ASM_ALIGNED_HI_OP
188 #define TARGET_ASM_ALIGNED_HI_OP "\tDCW\t"
189 #undef TARGET_ASM_ALIGNED_SI_OP
190 #define TARGET_ASM_ALIGNED_SI_OP "\tDCD\t"
191 #undef TARGET_ASM_GLOBALIZE_LABEL
192 #define TARGET_ASM_GLOBALIZE_LABEL aof_globalize_label
193 #undef TARGET_ASM_FILE_START
194 #define TARGET_ASM_FILE_START aof_file_start
195 #undef TARGET_ASM_FILE_END
196 #define TARGET_ASM_FILE_END aof_file_end
197 #else
198 #undef TARGET_ASM_ALIGNED_SI_OP
199 #define TARGET_ASM_ALIGNED_SI_OP NULL
200 #undef TARGET_ASM_INTEGER
201 #define TARGET_ASM_INTEGER arm_assemble_integer
202 #endif
203
204 #undef TARGET_ASM_FUNCTION_PROLOGUE
205 #define TARGET_ASM_FUNCTION_PROLOGUE arm_output_function_prologue
206
207 #undef TARGET_ASM_FUNCTION_EPILOGUE
208 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
209
210 #undef TARGET_COMP_TYPE_ATTRIBUTES
211 #define TARGET_COMP_TYPE_ATTRIBUTES arm_comp_type_attributes
212
213 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
214 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES arm_set_default_type_attributes
215
216 #undef TARGET_SCHED_ADJUST_COST
217 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
218
219 #undef TARGET_ENCODE_SECTION_INFO
220 #ifdef ARM_PE
221 #define TARGET_ENCODE_SECTION_INFO arm_pe_encode_section_info
222 #else
223 #define TARGET_ENCODE_SECTION_INFO arm_encode_section_info
224 #endif
225
226 #undef TARGET_STRIP_NAME_ENCODING
227 #define TARGET_STRIP_NAME_ENCODING arm_strip_name_encoding
228
229 #undef TARGET_ASM_INTERNAL_LABEL
230 #define TARGET_ASM_INTERNAL_LABEL arm_internal_label
231
232 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
233 #define TARGET_FUNCTION_OK_FOR_SIBCALL arm_function_ok_for_sibcall
234
235 #undef TARGET_ASM_OUTPUT_MI_THUNK
236 #define TARGET_ASM_OUTPUT_MI_THUNK arm_output_mi_thunk
237 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
238 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
239
240 /* This will be overridden in arm_override_options. */
241 #undef TARGET_RTX_COSTS
242 #define TARGET_RTX_COSTS arm_slowmul_rtx_costs
243 #undef TARGET_ADDRESS_COST
244 #define TARGET_ADDRESS_COST arm_address_cost
245
246 #undef TARGET_MACHINE_DEPENDENT_REORG
247 #define TARGET_MACHINE_DEPENDENT_REORG arm_reorg
248
249 #undef TARGET_INIT_BUILTINS
250 #define TARGET_INIT_BUILTINS arm_init_builtins
251 #undef TARGET_EXPAND_BUILTIN
252 #define TARGET_EXPAND_BUILTIN arm_expand_builtin
253
254 #undef TARGET_INIT_LIBFUNCS
255 #define TARGET_INIT_LIBFUNCS arm_init_libfuncs
256
257 #undef TARGET_PROMOTE_FUNCTION_ARGS
258 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
259 #undef TARGET_PROMOTE_FUNCTION_RETURN
260 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
261 #undef TARGET_PROMOTE_PROTOTYPES
262 #define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
263 #undef TARGET_PASS_BY_REFERENCE
264 #define TARGET_PASS_BY_REFERENCE arm_pass_by_reference
265
266 #undef TARGET_STRUCT_VALUE_RTX
267 #define TARGET_STRUCT_VALUE_RTX arm_struct_value_rtx
268
269 #undef TARGET_SETUP_INCOMING_VARARGS
270 #define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
271
272 #undef TARGET_DEFAULT_SHORT_ENUMS
273 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
274
275 #undef TARGET_ALIGN_ANON_BITFIELD
276 #define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield
277
278 #undef TARGET_CXX_GUARD_TYPE
279 #define TARGET_CXX_GUARD_TYPE arm_cxx_guard_type
280
281 #undef TARGET_CXX_GUARD_MASK_BIT
282 #define TARGET_CXX_GUARD_MASK_BIT arm_cxx_guard_mask_bit
283
284 #undef TARGET_CXX_GET_COOKIE_SIZE
285 #define TARGET_CXX_GET_COOKIE_SIZE arm_get_cookie_size
286
287 #undef TARGET_CXX_COOKIE_HAS_SIZE
288 #define TARGET_CXX_COOKIE_HAS_SIZE arm_cookie_has_size
289
290 #undef TARGET_CXX_CDTOR_RETURNS_THIS
291 #define TARGET_CXX_CDTOR_RETURNS_THIS arm_cxx_cdtor_returns_this
292
293 struct gcc_target targetm = TARGET_INITIALIZER;
294 \f
295 /* Obstack for minipool constant handling. */
296 static struct obstack minipool_obstack;
297 static char * minipool_startobj;
298
299 /* The maximum number of insns skipped which
300 will be conditionalised if possible. */
301 static int max_insns_skipped = 5;
302
303 extern FILE * asm_out_file;
304
305 /* True if we are currently building a constant table. */
306 int making_const_table;
307
308 /* Define the information needed to generate branch insns. This is
309 stored from the compare operation. */
310 rtx arm_compare_op0, arm_compare_op1;
311
312 /* The processor for which instructions should be scheduled. */
313 enum processor_type arm_tune = arm_none;
314
315 /* Which floating point model to use. */
316 enum arm_fp_model arm_fp_model;
317
318 /* Which floating point hardware is available. */
319 enum fputype arm_fpu_arch;
320
321 /* Which floating point hardware to schedule for. */
322 enum fputype arm_fpu_tune;
323
324 /* Whether to use floating point hardware. */
325 enum float_abi_type arm_float_abi;
326
327 /* Which ABI to use. */
328 enum arm_abi_type arm_abi;
329
330 /* Set by the -mfpu=... option. */
331 const char * target_fpu_name = NULL;
332
333 /* Set by the -mfpe=... option. */
334 const char * target_fpe_name = NULL;
335
336 /* Set by the -mfloat-abi=... option. */
337 const char * target_float_abi_name = NULL;
338
339 /* Set by the -mabi=... option. */
340 const char * target_abi_name = NULL;
341
342 /* Used to parse -mstructure_size_boundary command line option. */
343 const char * structure_size_string = NULL;
344 int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY;
345
346 /* Bit values used to identify processor capabilities. */
347 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
348 #define FL_ARCH3M (1 << 1) /* Extended multiply */
349 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
350 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
351 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
352 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
353 #define FL_THUMB (1 << 6) /* Thumb aware */
354 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
355 #define FL_STRONG (1 << 8) /* StrongARM */
356 #define FL_ARCH5E (1 << 9) /* DSP extensions to v5 */
357 #define FL_XSCALE (1 << 10) /* XScale */
358 #define FL_CIRRUS (1 << 11) /* Cirrus/DSP. */
359 #define FL_ARCH6 (1 << 12) /* Architecture rel 6. Adds
360 media instructions. */
361 #define FL_VFPV2 (1 << 13) /* Vector Floating Point V2. */
362
363 #define FL_IWMMXT (1 << 29) /* XScale v2 or "Intel Wireless MMX technology". */
364
365 #define FL_FOR_ARCH2 0
366 #define FL_FOR_ARCH3 FL_MODE32
367 #define FL_FOR_ARCH3M (FL_FOR_ARCH3 | FL_ARCH3M)
368 #define FL_FOR_ARCH4 (FL_FOR_ARCH3M | FL_ARCH4)
369 #define FL_FOR_ARCH4T (FL_FOR_ARCH4 | FL_THUMB)
370 #define FL_FOR_ARCH5 (FL_FOR_ARCH4 | FL_ARCH5)
371 #define FL_FOR_ARCH5T (FL_FOR_ARCH5 | FL_THUMB)
372 #define FL_FOR_ARCH5E (FL_FOR_ARCH5 | FL_ARCH5E)
373 #define FL_FOR_ARCH5TE (FL_FOR_ARCH5E | FL_THUMB)
374 #define FL_FOR_ARCH5TEJ FL_FOR_ARCH5TE
375 #define FL_FOR_ARCH6 (FL_FOR_ARCH5TE | FL_ARCH6)
376 #define FL_FOR_ARCH6J FL_FOR_ARCH6
377
378 /* The bits in this mask specify which
379 instructions we are allowed to generate. */
380 static unsigned long insn_flags = 0;
381
382 /* The bits in this mask specify which instruction scheduling options should
383 be used. */
384 static unsigned long tune_flags = 0;
385
386 /* The following are used in the arm.md file as equivalents to bits
387 in the above two flag variables. */
388
389 /* Nonzero if this chip supports the ARM Architecture 3M extensions. */
390 int arm_arch3m = 0;
391
392 /* Nonzero if this chip supports the ARM Architecture 4 extensions. */
393 int arm_arch4 = 0;
394
395 /* Nonzero if this chip supports the ARM Architecture 4t extensions. */
396 int arm_arch4t = 0;
397
398 /* Nonzero if this chip supports the ARM Architecture 5 extensions. */
399 int arm_arch5 = 0;
400
401 /* Nonzero if this chip supports the ARM Architecture 5E extensions. */
402 int arm_arch5e = 0;
403
404 /* Nonzero if this chip supports the ARM Architecture 6 extensions. */
405 int arm_arch6 = 0;
406
407 /* Nonzero if this chip can benefit from load scheduling. */
408 int arm_ld_sched = 0;
409
410 /* Nonzero if this chip is a StrongARM. */
411 int arm_is_strong = 0;
412
413 /* Nonzero if this chip is a Cirrus variant. */
414 int arm_arch_cirrus = 0;
415
416 /* Nonzero if this chip supports Intel Wireless MMX technology. */
417 int arm_arch_iwmmxt = 0;
418
419 /* Nonzero if this chip is an XScale. */
420 int arm_arch_xscale = 0;
421
422 /* Nonzero if tuning for XScale */
423 int arm_tune_xscale = 0;
424
425 /* Nonzero if this chip is an ARM6 or an ARM7. */
426 int arm_is_6_or_7 = 0;
427
428 /* Nonzero if generating Thumb instructions. */
429 int thumb_code = 0;
430
431 /* Nonzero if we should define __THUMB_INTERWORK__ in the
432 preprocessor.
433 XXX This is a bit of a hack, it's intended to help work around
434 problems in GLD which doesn't understand that armv5t code is
435 interworking clean. */
436 int arm_cpp_interwork = 0;
437
438 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
439 must report the mode of the memory reference from PRINT_OPERAND to
440 PRINT_OPERAND_ADDRESS. */
441 enum machine_mode output_memory_reference_mode;
442
443 /* The register number to be used for the PIC offset register. */
444 const char * arm_pic_register_string = NULL;
445 int arm_pic_register = INVALID_REGNUM;
446
447 /* Set to 1 when a return insn is output, this means that the epilogue
448 is not needed. */
449 int return_used_this_function;
450
451 /* Set to 1 after arm_reorg has started. Reset to start at the start of
452 the next function. */
453 static int after_arm_reorg = 0;
454
455 /* The maximum number of insns to be used when loading a constant. */
456 static int arm_constant_limit = 3;
457
458 /* For an explanation of these variables, see final_prescan_insn below. */
459 int arm_ccfsm_state;
460 enum arm_cond_code arm_current_cc;
461 rtx arm_target_insn;
462 int arm_target_label;
463
464 /* The condition codes of the ARM, and the inverse function. */
465 static const char * const arm_condition_codes[] =
466 {
467 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
468 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
469 };
470
471 #define streq(string1, string2) (strcmp (string1, string2) == 0)
472 \f
473 /* Initialization code. */
474
475 struct processors
476 {
477 const char *const name;
478 enum processor_type core;
479 const char *arch;
480 const unsigned long flags;
481 bool (* rtx_costs) (rtx, int, int, int *);
482 };
483
484 /* Not all of these give usefully different compilation alternatives,
485 but there is no simple way of generalizing them. */
486 static const struct processors all_cores[] =
487 {
488 /* ARM Cores */
489 #define ARM_CORE(NAME, ARCH, FLAGS, COSTS) \
490 {#NAME, arm_none, #ARCH, FLAGS | FL_FOR_ARCH##ARCH, arm_##COSTS##_rtx_costs},
491 #include "arm-cores.def"
492 #undef ARM_CORE
493 {NULL, arm_none, NULL, 0, NULL}
494 };
495
496 static const struct processors all_architectures[] =
497 {
498 /* ARM Architectures */
499 /* We don't specify rtx_costs here as it will be figured out
500 from the core. */
501
502 {"armv2", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
503 {"armv2a", arm2, "2", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH2, NULL},
504 {"armv3", arm6, "3", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3, NULL},
505 {"armv3m", arm7m, "3M", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH3M, NULL},
506 {"armv4", arm7tdmi, "4", FL_CO_PROC | FL_MODE26 | FL_FOR_ARCH4, NULL},
507 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
508 implementations that support it, so we will leave it out for now. */
509 {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL},
510 {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL},
511 {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL},
512 {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL},
513 {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL},
514 {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL},
515 {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL},
516 {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
517 {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
518 {NULL, arm_none, NULL, 0 , NULL}
519 };
520
521 /* This is a magic structure. The 'string' field is magically filled in
522 with a pointer to the value specified by the user on the command line
523 assuming that the user has specified such a value. */
524
525 struct arm_cpu_select arm_select[] =
526 {
527 /* string name processors */
528 { NULL, "-mcpu=", all_cores },
529 { NULL, "-march=", all_architectures },
530 { NULL, "-mtune=", all_cores }
531 };
532
533
534 /* The name of the proprocessor macro to define for this architecture. */
535
536 char arm_arch_name[] = "__ARM_ARCH_0UNK__";
537
538 struct fpu_desc
539 {
540 const char * name;
541 enum fputype fpu;
542 };
543
544
545 /* Available values for for -mfpu=. */
546
547 static const struct fpu_desc all_fpus[] =
548 {
549 {"fpa", FPUTYPE_FPA},
550 {"fpe2", FPUTYPE_FPA_EMU2},
551 {"fpe3", FPUTYPE_FPA_EMU2},
552 {"maverick", FPUTYPE_MAVERICK},
553 {"vfp", FPUTYPE_VFP}
554 };
555
556
557 /* Floating point models used by the different hardware.
558 See fputype in arm.h. */
559
560 static const enum fputype fp_model_for_fpu[] =
561 {
562 /* No FP hardware. */
563 ARM_FP_MODEL_UNKNOWN, /* FPUTYPE_NONE */
564 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA */
565 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU2 */
566 ARM_FP_MODEL_FPA, /* FPUTYPE_FPA_EMU3 */
567 ARM_FP_MODEL_MAVERICK, /* FPUTYPE_MAVERICK */
568 ARM_FP_MODEL_VFP /* FPUTYPE_VFP */
569 };
570
571
572 struct float_abi
573 {
574 const char * name;
575 enum float_abi_type abi_type;
576 };
577
578
579 /* Available values for -mfloat-abi=. */
580
581 static const struct float_abi all_float_abis[] =
582 {
583 {"soft", ARM_FLOAT_ABI_SOFT},
584 {"softfp", ARM_FLOAT_ABI_SOFTFP},
585 {"hard", ARM_FLOAT_ABI_HARD}
586 };
587
588
589 struct abi_name
590 {
591 const char *name;
592 enum arm_abi_type abi_type;
593 };
594
595
596 /* Available values for -mabi=. */
597
598 static const struct abi_name arm_all_abis[] =
599 {
600 {"apcs-gnu", ARM_ABI_APCS},
601 {"atpcs", ARM_ABI_ATPCS},
602 {"aapcs", ARM_ABI_AAPCS},
603 {"iwmmxt", ARM_ABI_IWMMXT}
604 };
605
606 /* Return the number of bits set in VALUE. */
607 static unsigned
608 bit_count (unsigned long value)
609 {
610 unsigned long count = 0;
611
612 while (value)
613 {
614 count++;
615 value &= value - 1; /* Clear the least-significant set bit. */
616 }
617
618 return count;
619 }
620
621 /* Set up library functions uqniue to ARM. */
622
623 static void
624 arm_init_libfuncs (void)
625 {
626 /* There are no special library functions unless we are using the
627 ARM BPABI. */
628 if (!TARGET_BPABI)
629 return;
630
631 /* The functions below are described in Section 4 of the "Run-Time
632 ABI for the ARM architecture", Version 1.0. */
633
634 /* Double-precision floating-point arithmetic. Table 2. */
635 set_optab_libfunc (add_optab, DFmode, "__aeabi_dadd");
636 set_optab_libfunc (sdiv_optab, DFmode, "__aeabi_ddiv");
637 set_optab_libfunc (smul_optab, DFmode, "__aeabi_dmul");
638 set_optab_libfunc (neg_optab, DFmode, "__aeabi_dneg");
639 set_optab_libfunc (sub_optab, DFmode, "__aeabi_dsub");
640
641 /* Double-precision comparisions. Table 3. */
642 set_optab_libfunc (eq_optab, DFmode, "__aeabi_dcmpeq");
643 set_optab_libfunc (ne_optab, DFmode, NULL);
644 set_optab_libfunc (lt_optab, DFmode, "__aeabi_dcmplt");
645 set_optab_libfunc (le_optab, DFmode, "__aeabi_dcmple");
646 set_optab_libfunc (ge_optab, DFmode, "__aeabi_dcmpge");
647 set_optab_libfunc (gt_optab, DFmode, "__aeabi_dcmpgt");
648 set_optab_libfunc (unord_optab, DFmode, "__aeabi_dcmpun");
649
650 /* Single-precision floating-point arithmetic. Table 4. */
651 set_optab_libfunc (add_optab, SFmode, "__aeabi_fadd");
652 set_optab_libfunc (sdiv_optab, SFmode, "__aeabi_fdiv");
653 set_optab_libfunc (smul_optab, SFmode, "__aeabi_fmul");
654 set_optab_libfunc (neg_optab, SFmode, "__aeabi_fneg");
655 set_optab_libfunc (sub_optab, SFmode, "__aeabi_fsub");
656
657 /* Single-precision comparisions. Table 5. */
658 set_optab_libfunc (eq_optab, SFmode, "__aeabi_fcmpeq");
659 set_optab_libfunc (ne_optab, SFmode, NULL);
660 set_optab_libfunc (lt_optab, SFmode, "__aeabi_fcmplt");
661 set_optab_libfunc (le_optab, SFmode, "__aeabi_fcmple");
662 set_optab_libfunc (ge_optab, SFmode, "__aeabi_fcmpge");
663 set_optab_libfunc (gt_optab, SFmode, "__aeabi_fcmpgt");
664 set_optab_libfunc (unord_optab, SFmode, "__aeabi_fcmpun");
665
666 /* Floating-point to integer conversions. Table 6. */
667 set_conv_libfunc (sfix_optab, SImode, DFmode, "__aeabi_d2iz");
668 set_conv_libfunc (ufix_optab, SImode, DFmode, "__aeabi_d2uiz");
669 set_conv_libfunc (sfix_optab, DImode, DFmode, "__aeabi_d2lz");
670 set_conv_libfunc (ufix_optab, DImode, DFmode, "__aeabi_d2ulz");
671 set_conv_libfunc (sfix_optab, SImode, SFmode, "__aeabi_f2iz");
672 set_conv_libfunc (ufix_optab, SImode, SFmode, "__aeabi_f2uiz");
673 set_conv_libfunc (sfix_optab, DImode, SFmode, "__aeabi_f2lz");
674 set_conv_libfunc (ufix_optab, DImode, SFmode, "__aeabi_f2ulz");
675
676 /* Conversions between floating types. Table 7. */
677 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__aeabi_d2f");
678 set_conv_libfunc (sext_optab, DFmode, SFmode, "__aeabi_f2d");
679
680 /* Integer to floating-point converisons. Table 8. */
681 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__aeabi_i2d");
682 set_conv_libfunc (ufloat_optab, DFmode, SImode, "__aeabi_ui2d");
683 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__aeabi_l2d");
684 set_conv_libfunc (ufloat_optab, DFmode, DImode, "__aeabi_ul2d");
685 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__aeabi_i2f");
686 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__aeabi_ui2f");
687 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__aeabi_l2f");
688 set_conv_libfunc (ufloat_optab, SFmode, DImode, "__aeabi_ul2f");
689
690 /* Long long. Table 9. */
691 set_optab_libfunc (smul_optab, DImode, "__aeabi_lmul");
692 set_optab_libfunc (sdivmod_optab, DImode, "__aeabi_ldivmod");
693 set_optab_libfunc (udivmod_optab, DImode, "__aeabi_uldivmod");
694 set_optab_libfunc (ashl_optab, DImode, "__aeabi_llsl");
695 set_optab_libfunc (lshr_optab, DImode, "__aeabi_llsr");
696 set_optab_libfunc (ashr_optab, DImode, "__aeabi_lasr");
697 set_optab_libfunc (cmp_optab, DImode, "__aeabi_lcmp");
698 set_optab_libfunc (ucmp_optab, DImode, "__aeabi_ulcmp");
699
700 /* Integer (32/32->32) division. \S 4.3.1. */
701 set_optab_libfunc (sdivmod_optab, SImode, "__aeabi_idivmod");
702 set_optab_libfunc (udivmod_optab, SImode, "__aeabi_uidivmod");
703
704 /* The divmod functions are designed so that they can be used for
705 plain division, even though they return both the quotient and the
706 remainder. The quotient is returned in the usual location (i.e.,
707 r0 for SImode, {r0, r1} for DImode), just as would be expected
708 for an ordinary division routine. Because the AAPCS calling
709 conventions specify that all of { r0, r1, r2, r3 } are
710 callee-saved registers, there is no need to tell the compiler
711 explicitly that those registers are clobbered by these
712 routines. */
713 set_optab_libfunc (sdiv_optab, DImode, "__aeabi_ldivmod");
714 set_optab_libfunc (udiv_optab, DImode, "__aeabi_uldivmod");
715 set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idivmod");
716 set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidivmod");
717 }
718
719 /* Fix up any incompatible options that the user has specified.
720 This has now turned into a maze. */
721 void
722 arm_override_options (void)
723 {
724 unsigned i;
725
726 /* Set up the flags based on the cpu/architecture selected by the user. */
727 for (i = ARRAY_SIZE (arm_select); i--;)
728 {
729 struct arm_cpu_select * ptr = arm_select + i;
730
731 if (ptr->string != NULL && ptr->string[0] != '\0')
732 {
733 const struct processors * sel;
734
735 for (sel = ptr->processors; sel->name != NULL; sel++)
736 if (streq (ptr->string, sel->name))
737 {
738 /* Set the architecture define. */
739 if (i != 2)
740 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
741
742 /* Determine the processor core for which we should
743 tune code-generation. */
744 if (/* -mcpu= is a sensible default. */
745 i == 0
746 /* If -march= is used, and -mcpu= has not been used,
747 assume that we should tune for a representative
748 CPU from that architecture. */
749 || i == 1
750 /* -mtune= overrides -mcpu= and -march=. */
751 || i == 2)
752 arm_tune = (enum processor_type) (sel - ptr->processors);
753
754 if (i != 2)
755 {
756 /* If we have been given an architecture and a processor
757 make sure that they are compatible. We only generate
758 a warning though, and we prefer the CPU over the
759 architecture. */
760 if (insn_flags != 0 && (insn_flags ^ sel->flags))
761 warning ("switch -mcpu=%s conflicts with -march= switch",
762 ptr->string);
763
764 insn_flags = sel->flags;
765 }
766
767 break;
768 }
769
770 if (sel->name == NULL)
771 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
772 }
773 }
774
775 /* If the user did not specify a processor, choose one for them. */
776 if (insn_flags == 0)
777 {
778 const struct processors * sel;
779 unsigned int sought;
780 enum processor_type cpu;
781
782 cpu = TARGET_CPU_DEFAULT;
783 if (cpu == arm_none)
784 {
785 #ifdef SUBTARGET_CPU_DEFAULT
786 /* Use the subtarget default CPU if none was specified by
787 configure. */
788 cpu = SUBTARGET_CPU_DEFAULT;
789 #endif
790 /* Default to ARM6. */
791 if (cpu == arm_none)
792 cpu = arm6;
793 }
794 sel = &all_cores[cpu];
795
796 insn_flags = sel->flags;
797
798 /* Now check to see if the user has specified some command line
799 switch that require certain abilities from the cpu. */
800 sought = 0;
801
802 if (TARGET_INTERWORK || TARGET_THUMB)
803 {
804 sought |= (FL_THUMB | FL_MODE32);
805
806 /* There are no ARM processors that support both APCS-26 and
807 interworking. Therefore we force FL_MODE26 to be removed
808 from insn_flags here (if it was set), so that the search
809 below will always be able to find a compatible processor. */
810 insn_flags &= ~FL_MODE26;
811 }
812
813 if (sought != 0 && ((sought & insn_flags) != sought))
814 {
815 /* Try to locate a CPU type that supports all of the abilities
816 of the default CPU, plus the extra abilities requested by
817 the user. */
818 for (sel = all_cores; sel->name != NULL; sel++)
819 if ((sel->flags & sought) == (sought | insn_flags))
820 break;
821
822 if (sel->name == NULL)
823 {
824 unsigned current_bit_count = 0;
825 const struct processors * best_fit = NULL;
826
827 /* Ideally we would like to issue an error message here
828 saying that it was not possible to find a CPU compatible
829 with the default CPU, but which also supports the command
830 line options specified by the programmer, and so they
831 ought to use the -mcpu=<name> command line option to
832 override the default CPU type.
833
834 If we cannot find a cpu that has both the
835 characteristics of the default cpu and the given
836 command line options we scan the array again looking
837 for a best match. */
838 for (sel = all_cores; sel->name != NULL; sel++)
839 if ((sel->flags & sought) == sought)
840 {
841 unsigned count;
842
843 count = bit_count (sel->flags & insn_flags);
844
845 if (count >= current_bit_count)
846 {
847 best_fit = sel;
848 current_bit_count = count;
849 }
850 }
851
852 if (best_fit == NULL)
853 abort ();
854 else
855 sel = best_fit;
856 }
857
858 insn_flags = sel->flags;
859 }
860 sprintf (arm_arch_name, "__ARM_ARCH_%s__", sel->arch);
861 if (arm_tune == arm_none)
862 arm_tune = (enum processor_type) (sel - all_cores);
863 }
864
865 /* The processor for which we should tune should now have been
866 chosen. */
867 if (arm_tune == arm_none)
868 abort ();
869
870 tune_flags = all_cores[(int)arm_tune].flags;
871 targetm.rtx_costs = all_cores[(int)arm_tune].rtx_costs;
872
873 /* Make sure that the processor choice does not conflict with any of the
874 other command line choices. */
875 if (TARGET_INTERWORK && !(insn_flags & FL_THUMB))
876 {
877 warning ("target CPU does not support interworking" );
878 target_flags &= ~ARM_FLAG_INTERWORK;
879 }
880
881 if (TARGET_THUMB && !(insn_flags & FL_THUMB))
882 {
883 warning ("target CPU does not support THUMB instructions");
884 target_flags &= ~ARM_FLAG_THUMB;
885 }
886
887 if (TARGET_APCS_FRAME && TARGET_THUMB)
888 {
889 /* warning ("ignoring -mapcs-frame because -mthumb was used"); */
890 target_flags &= ~ARM_FLAG_APCS_FRAME;
891 }
892
893 /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done
894 from here where no function is being compiled currently. */
895 if ((target_flags & (THUMB_FLAG_LEAF_BACKTRACE | THUMB_FLAG_BACKTRACE))
896 && TARGET_ARM)
897 warning ("enabling backtrace support is only meaningful when compiling for the Thumb");
898
899 if (TARGET_ARM && TARGET_CALLEE_INTERWORKING)
900 warning ("enabling callee interworking support is only meaningful when compiling for the Thumb");
901
902 if (TARGET_ARM && TARGET_CALLER_INTERWORKING)
903 warning ("enabling caller interworking support is only meaningful when compiling for the Thumb");
904
905 if (TARGET_APCS_STACK && !TARGET_APCS_FRAME)
906 {
907 warning ("-mapcs-stack-check incompatible with -mno-apcs-frame");
908 target_flags |= ARM_FLAG_APCS_FRAME;
909 }
910
911 if (TARGET_POKE_FUNCTION_NAME)
912 target_flags |= ARM_FLAG_APCS_FRAME;
913
914 if (TARGET_APCS_REENT && flag_pic)
915 error ("-fpic and -mapcs-reent are incompatible");
916
917 if (TARGET_APCS_REENT)
918 warning ("APCS reentrant code not supported. Ignored");
919
920 /* If this target is normally configured to use APCS frames, warn if they
921 are turned off and debugging is turned on. */
922 if (TARGET_ARM
923 && write_symbols != NO_DEBUG
924 && !TARGET_APCS_FRAME
925 && (TARGET_DEFAULT & ARM_FLAG_APCS_FRAME))
926 warning ("-g with -mno-apcs-frame may not give sensible debugging");
927
928 /* If stack checking is disabled, we can use r10 as the PIC register,
929 which keeps r9 available. */
930 if (flag_pic)
931 arm_pic_register = TARGET_APCS_STACK ? 9 : 10;
932
933 if (TARGET_APCS_FLOAT)
934 warning ("passing floating point arguments in fp regs not yet supported");
935
936 /* Initialize boolean versions of the flags, for use in the arm.md file. */
937 arm_arch3m = (insn_flags & FL_ARCH3M) != 0;
938 arm_arch4 = (insn_flags & FL_ARCH4) != 0;
939 arm_arch4t = arm_arch4 & ((insn_flags & FL_THUMB) != 0);
940 arm_arch5 = (insn_flags & FL_ARCH5) != 0;
941 arm_arch5e = (insn_flags & FL_ARCH5E) != 0;
942 arm_arch6 = (insn_flags & FL_ARCH6) != 0;
943 arm_arch_xscale = (insn_flags & FL_XSCALE) != 0;
944 arm_arch_cirrus = (insn_flags & FL_CIRRUS) != 0;
945
946 arm_ld_sched = (tune_flags & FL_LDSCHED) != 0;
947 arm_is_strong = (tune_flags & FL_STRONG) != 0;
948 thumb_code = (TARGET_ARM == 0);
949 arm_is_6_or_7 = (((tune_flags & (FL_MODE26 | FL_MODE32))
950 && !(tune_flags & FL_ARCH4))) != 0;
951 arm_tune_xscale = (tune_flags & FL_XSCALE) != 0;
952 arm_arch_iwmmxt = (insn_flags & FL_IWMMXT) != 0;
953
954 /* V5 code we generate is completely interworking capable, so we turn off
955 TARGET_INTERWORK here to avoid many tests later on. */
956
957 /* XXX However, we must pass the right pre-processor defines to CPP
958 or GLD can get confused. This is a hack. */
959 if (TARGET_INTERWORK)
960 arm_cpp_interwork = 1;
961
962 if (arm_arch5)
963 target_flags &= ~ARM_FLAG_INTERWORK;
964
965 if (target_abi_name)
966 {
967 for (i = 0; i < ARRAY_SIZE (arm_all_abis); i++)
968 {
969 if (streq (arm_all_abis[i].name, target_abi_name))
970 {
971 arm_abi = arm_all_abis[i].abi_type;
972 break;
973 }
974 }
975 if (i == ARRAY_SIZE (arm_all_abis))
976 error ("invalid ABI option: -mabi=%s", target_abi_name);
977 }
978 else
979 arm_abi = ARM_DEFAULT_ABI;
980
981 if (TARGET_IWMMXT && !ARM_DOUBLEWORD_ALIGN)
982 error ("iwmmxt requires an AAPCS compatible ABI for proper operation");
983
984 if (TARGET_IWMMXT_ABI && !TARGET_IWMMXT)
985 error ("iwmmxt abi requires an iwmmxt capable cpu");
986
987 arm_fp_model = ARM_FP_MODEL_UNKNOWN;
988 if (target_fpu_name == NULL && target_fpe_name != NULL)
989 {
990 if (streq (target_fpe_name, "2"))
991 target_fpu_name = "fpe2";
992 else if (streq (target_fpe_name, "3"))
993 target_fpu_name = "fpe3";
994 else
995 error ("invalid floating point emulation option: -mfpe=%s",
996 target_fpe_name);
997 }
998 if (target_fpu_name != NULL)
999 {
1000 /* The user specified a FPU. */
1001 for (i = 0; i < ARRAY_SIZE (all_fpus); i++)
1002 {
1003 if (streq (all_fpus[i].name, target_fpu_name))
1004 {
1005 arm_fpu_arch = all_fpus[i].fpu;
1006 arm_fpu_tune = arm_fpu_arch;
1007 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1008 break;
1009 }
1010 }
1011 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1012 error ("invalid floating point option: -mfpu=%s", target_fpu_name);
1013 }
1014 else
1015 {
1016 #ifdef FPUTYPE_DEFAULT
1017 /* Use the default if it is specified for this platform. */
1018 arm_fpu_arch = FPUTYPE_DEFAULT;
1019 arm_fpu_tune = FPUTYPE_DEFAULT;
1020 #else
1021 /* Pick one based on CPU type. */
1022 /* ??? Some targets assume FPA is the default.
1023 if ((insn_flags & FL_VFP) != 0)
1024 arm_fpu_arch = FPUTYPE_VFP;
1025 else
1026 */
1027 if (arm_arch_cirrus)
1028 arm_fpu_arch = FPUTYPE_MAVERICK;
1029 else
1030 arm_fpu_arch = FPUTYPE_FPA_EMU2;
1031 #endif
1032 if (tune_flags & FL_CO_PROC && arm_fpu_arch == FPUTYPE_FPA_EMU2)
1033 arm_fpu_tune = FPUTYPE_FPA;
1034 else
1035 arm_fpu_tune = arm_fpu_arch;
1036 arm_fp_model = fp_model_for_fpu[arm_fpu_arch];
1037 if (arm_fp_model == ARM_FP_MODEL_UNKNOWN)
1038 abort ();
1039 }
1040
1041 if (target_float_abi_name != NULL)
1042 {
1043 /* The user specified a FP ABI. */
1044 for (i = 0; i < ARRAY_SIZE (all_float_abis); i++)
1045 {
1046 if (streq (all_float_abis[i].name, target_float_abi_name))
1047 {
1048 arm_float_abi = all_float_abis[i].abi_type;
1049 break;
1050 }
1051 }
1052 if (i == ARRAY_SIZE (all_float_abis))
1053 error ("invalid floating point abi: -mfloat-abi=%s",
1054 target_float_abi_name);
1055 }
1056 else
1057 {
1058 /* Use soft-float target flag. */
1059 if (target_flags & ARM_FLAG_SOFT_FLOAT)
1060 arm_float_abi = ARM_FLOAT_ABI_SOFT;
1061 else
1062 arm_float_abi = ARM_FLOAT_ABI_HARD;
1063 }
1064
1065 if (arm_float_abi == ARM_FLOAT_ABI_SOFTFP)
1066 sorry ("-mfloat-abi=softfp");
1067 /* If soft-float is specified then don't use FPU. */
1068 if (TARGET_SOFT_FLOAT)
1069 arm_fpu_arch = FPUTYPE_NONE;
1070
1071 /* For arm2/3 there is no need to do any scheduling if there is only
1072 a floating point emulator, or we are doing software floating-point. */
1073 if ((TARGET_SOFT_FLOAT
1074 || arm_fpu_tune == FPUTYPE_FPA_EMU2
1075 || arm_fpu_tune == FPUTYPE_FPA_EMU3)
1076 && (tune_flags & FL_MODE32) == 0)
1077 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
1078
1079 /* Override the default structure alignment for AAPCS ABI. */
1080 if (arm_abi == ARM_ABI_AAPCS)
1081 arm_structure_size_boundary = 8;
1082
1083 if (structure_size_string != NULL)
1084 {
1085 int size = strtol (structure_size_string, NULL, 0);
1086
1087 if (size == 8 || size == 32
1088 || (ARM_DOUBLEWORD_ALIGN && size == 64))
1089 arm_structure_size_boundary = size;
1090 else
1091 warning ("structure size boundary can only be set to %s",
1092 ARM_DOUBLEWORD_ALIGN ? "8, 32 or 64": "8 or 32");
1093 }
1094
1095 if (arm_pic_register_string != NULL)
1096 {
1097 int pic_register = decode_reg_name (arm_pic_register_string);
1098
1099 if (!flag_pic)
1100 warning ("-mpic-register= is useless without -fpic");
1101
1102 /* Prevent the user from choosing an obviously stupid PIC register. */
1103 else if (pic_register < 0 || call_used_regs[pic_register]
1104 || pic_register == HARD_FRAME_POINTER_REGNUM
1105 || pic_register == STACK_POINTER_REGNUM
1106 || pic_register >= PC_REGNUM)
1107 error ("unable to use '%s' for PIC register", arm_pic_register_string);
1108 else
1109 arm_pic_register = pic_register;
1110 }
1111
1112 if (TARGET_THUMB && flag_schedule_insns)
1113 {
1114 /* Don't warn since it's on by default in -O2. */
1115 flag_schedule_insns = 0;
1116 }
1117
1118 if (optimize_size)
1119 {
1120 /* There's some dispute as to whether this should be 1 or 2. However,
1121 experiments seem to show that in pathological cases a setting of
1122 1 degrades less severely than a setting of 2. This could change if
1123 other parts of the compiler change their behavior. */
1124 arm_constant_limit = 1;
1125
1126 /* If optimizing for size, bump the number of instructions that we
1127 are prepared to conditionally execute (even on a StrongARM). */
1128 max_insns_skipped = 6;
1129 }
1130 else
1131 {
1132 /* For processors with load scheduling, it never costs more than
1133 2 cycles to load a constant, and the load scheduler may well
1134 reduce that to 1. */
1135 if (tune_flags & FL_LDSCHED)
1136 arm_constant_limit = 1;
1137
1138 /* On XScale the longer latency of a load makes it more difficult
1139 to achieve a good schedule, so it's faster to synthesize
1140 constants that can be done in two insns. */
1141 if (arm_tune_xscale)
1142 arm_constant_limit = 2;
1143
1144 /* StrongARM has early execution of branches, so a sequence
1145 that is worth skipping is shorter. */
1146 if (arm_is_strong)
1147 max_insns_skipped = 3;
1148 }
1149
1150 /* Register global variables with the garbage collector. */
1151 arm_add_gc_roots ();
1152 }
1153
1154 static void
1155 arm_add_gc_roots (void)
1156 {
1157 gcc_obstack_init(&minipool_obstack);
1158 minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0);
1159 }
1160 \f
1161 /* A table of known ARM exception types.
1162 For use with the interrupt function attribute. */
1163
1164 typedef struct
1165 {
1166 const char *const arg;
1167 const unsigned long return_value;
1168 }
1169 isr_attribute_arg;
1170
1171 static const isr_attribute_arg isr_attribute_args [] =
1172 {
1173 { "IRQ", ARM_FT_ISR },
1174 { "irq", ARM_FT_ISR },
1175 { "FIQ", ARM_FT_FIQ },
1176 { "fiq", ARM_FT_FIQ },
1177 { "ABORT", ARM_FT_ISR },
1178 { "abort", ARM_FT_ISR },
1179 { "ABORT", ARM_FT_ISR },
1180 { "abort", ARM_FT_ISR },
1181 { "UNDEF", ARM_FT_EXCEPTION },
1182 { "undef", ARM_FT_EXCEPTION },
1183 { "SWI", ARM_FT_EXCEPTION },
1184 { "swi", ARM_FT_EXCEPTION },
1185 { NULL, ARM_FT_NORMAL }
1186 };
1187
1188 /* Returns the (interrupt) function type of the current
1189 function, or ARM_FT_UNKNOWN if the type cannot be determined. */
1190
1191 static unsigned long
1192 arm_isr_value (tree argument)
1193 {
1194 const isr_attribute_arg * ptr;
1195 const char * arg;
1196
1197 /* No argument - default to IRQ. */
1198 if (argument == NULL_TREE)
1199 return ARM_FT_ISR;
1200
1201 /* Get the value of the argument. */
1202 if (TREE_VALUE (argument) == NULL_TREE
1203 || TREE_CODE (TREE_VALUE (argument)) != STRING_CST)
1204 return ARM_FT_UNKNOWN;
1205
1206 arg = TREE_STRING_POINTER (TREE_VALUE (argument));
1207
1208 /* Check it against the list of known arguments. */
1209 for (ptr = isr_attribute_args; ptr->arg != NULL; ptr++)
1210 if (streq (arg, ptr->arg))
1211 return ptr->return_value;
1212
1213 /* An unrecognized interrupt type. */
1214 return ARM_FT_UNKNOWN;
1215 }
1216
1217 /* Computes the type of the current function. */
1218
1219 static unsigned long
1220 arm_compute_func_type (void)
1221 {
1222 unsigned long type = ARM_FT_UNKNOWN;
1223 tree a;
1224 tree attr;
1225
1226 if (TREE_CODE (current_function_decl) != FUNCTION_DECL)
1227 abort ();
1228
1229 /* Decide if the current function is volatile. Such functions
1230 never return, and many memory cycles can be saved by not storing
1231 register values that will never be needed again. This optimization
1232 was added to speed up context switching in a kernel application. */
1233 if (optimize > 0
1234 && TREE_NOTHROW (current_function_decl)
1235 && TREE_THIS_VOLATILE (current_function_decl))
1236 type |= ARM_FT_VOLATILE;
1237
1238 if (cfun->static_chain_decl != NULL)
1239 type |= ARM_FT_NESTED;
1240
1241 attr = DECL_ATTRIBUTES (current_function_decl);
1242
1243 a = lookup_attribute ("naked", attr);
1244 if (a != NULL_TREE)
1245 type |= ARM_FT_NAKED;
1246
1247 a = lookup_attribute ("isr", attr);
1248 if (a == NULL_TREE)
1249 a = lookup_attribute ("interrupt", attr);
1250
1251 if (a == NULL_TREE)
1252 type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL;
1253 else
1254 type |= arm_isr_value (TREE_VALUE (a));
1255
1256 return type;
1257 }
1258
1259 /* Returns the type of the current function. */
1260
1261 unsigned long
1262 arm_current_func_type (void)
1263 {
1264 if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN)
1265 cfun->machine->func_type = arm_compute_func_type ();
1266
1267 return cfun->machine->func_type;
1268 }
1269 \f
1270 /* Return 1 if it is possible to return using a single instruction.
1271 If SIBLING is non-null, this is a test for a return before a sibling
1272 call. SIBLING is the call insn, so we can examine its register usage. */
1273
1274 int
1275 use_return_insn (int iscond, rtx sibling)
1276 {
1277 int regno;
1278 unsigned int func_type;
1279 unsigned long saved_int_regs;
1280 unsigned HOST_WIDE_INT stack_adjust;
1281 arm_stack_offsets *offsets;
1282
1283 /* Never use a return instruction before reload has run. */
1284 if (!reload_completed)
1285 return 0;
1286
1287 func_type = arm_current_func_type ();
1288
1289 /* Naked functions and volatile functions need special
1290 consideration. */
1291 if (func_type & (ARM_FT_VOLATILE | ARM_FT_NAKED))
1292 return 0;
1293
1294 /* So do interrupt functions that use the frame pointer. */
1295 if (IS_INTERRUPT (func_type) && frame_pointer_needed)
1296 return 0;
1297
1298 offsets = arm_get_frame_offsets ();
1299 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
1300
1301 /* As do variadic functions. */
1302 if (current_function_pretend_args_size
1303 || cfun->machine->uses_anonymous_args
1304 /* Or if the function calls __builtin_eh_return () */
1305 || current_function_calls_eh_return
1306 /* Or if the function calls alloca */
1307 || current_function_calls_alloca
1308 /* Or if there is a stack adjustment. However, if the stack pointer
1309 is saved on the stack, we can use a pre-incrementing stack load. */
1310 || !(stack_adjust == 0 || (frame_pointer_needed && stack_adjust == 4)))
1311 return 0;
1312
1313 saved_int_regs = arm_compute_save_reg_mask ();
1314
1315 /* Unfortunately, the insn
1316
1317 ldmib sp, {..., sp, ...}
1318
1319 triggers a bug on most SA-110 based devices, such that the stack
1320 pointer won't be correctly restored if the instruction takes a
1321 page fault. We work around this problem by popping r3 along with
1322 the other registers, since that is never slower than executing
1323 another instruction.
1324
1325 We test for !arm_arch5 here, because code for any architecture
1326 less than this could potentially be run on one of the buggy
1327 chips. */
1328 if (stack_adjust == 4 && !arm_arch5)
1329 {
1330 /* Validate that r3 is a call-clobbered register (always true in
1331 the default abi) ... */
1332 if (!call_used_regs[3])
1333 return 0;
1334
1335 /* ... that it isn't being used for a return value (always true
1336 until we implement return-in-regs), or for a tail-call
1337 argument ... */
1338 if (sibling)
1339 {
1340 if (GET_CODE (sibling) != CALL_INSN)
1341 abort ();
1342
1343 if (find_regno_fusage (sibling, USE, 3))
1344 return 0;
1345 }
1346
1347 /* ... and that there are no call-saved registers in r0-r2
1348 (always true in the default ABI). */
1349 if (saved_int_regs & 0x7)
1350 return 0;
1351 }
1352
1353 /* Can't be done if interworking with Thumb, and any registers have been
1354 stacked. */
1355 if (TARGET_INTERWORK && saved_int_regs != 0)
1356 return 0;
1357
1358 /* On StrongARM, conditional returns are expensive if they aren't
1359 taken and multiple registers have been stacked. */
1360 if (iscond && arm_is_strong)
1361 {
1362 /* Conditional return when just the LR is stored is a simple
1363 conditional-load instruction, that's not expensive. */
1364 if (saved_int_regs != 0 && saved_int_regs != (1 << LR_REGNUM))
1365 return 0;
1366
1367 if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
1368 return 0;
1369 }
1370
1371 /* If there are saved registers but the LR isn't saved, then we need
1372 two instructions for the return. */
1373 if (saved_int_regs && !(saved_int_regs & (1 << LR_REGNUM)))
1374 return 0;
1375
1376 /* Can't be done if any of the FPA regs are pushed,
1377 since this also requires an insn. */
1378 if (TARGET_HARD_FLOAT && TARGET_FPA)
1379 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
1380 if (regs_ever_live[regno] && !call_used_regs[regno])
1381 return 0;
1382
1383 /* Likewise VFP regs. */
1384 if (TARGET_HARD_FLOAT && TARGET_VFP)
1385 for (regno = FIRST_VFP_REGNUM; regno <= LAST_VFP_REGNUM; regno++)
1386 if (regs_ever_live[regno] && !call_used_regs[regno])
1387 return 0;
1388
1389 if (TARGET_REALLY_IWMMXT)
1390 for (regno = FIRST_IWMMXT_REGNUM; regno <= LAST_IWMMXT_REGNUM; regno++)
1391 if (regs_ever_live[regno] && ! call_used_regs [regno])
1392 return 0;
1393
1394 return 1;
1395 }
1396
1397 /* Return TRUE if int I is a valid immediate ARM constant. */
1398
1399 int
1400 const_ok_for_arm (HOST_WIDE_INT i)
1401 {
1402 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT)0xFF;
1403
1404 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
1405 be all zero, or all one. */
1406 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
1407 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
1408 != ((~(unsigned HOST_WIDE_INT) 0)
1409 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
1410 return FALSE;
1411
1412 /* Fast return for 0 and powers of 2 */
1413 if ((i & (i - 1)) == 0)
1414 return TRUE;
1415
1416 do
1417 {
1418 if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)
1419 return TRUE;
1420 mask =
1421 (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)
1422 >> (32 - 2)) | ~(unsigned HOST_WIDE_INT) 0xffffffff;
1423 }
1424 while (mask != ~(unsigned HOST_WIDE_INT) 0xFF);
1425
1426 return FALSE;
1427 }
1428
1429 /* Return true if I is a valid constant for the operation CODE. */
1430 static int
1431 const_ok_for_op (HOST_WIDE_INT i, enum rtx_code code)
1432 {
1433 if (const_ok_for_arm (i))
1434 return 1;
1435
1436 switch (code)
1437 {
1438 case PLUS:
1439 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
1440
1441 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
1442 case XOR:
1443 case IOR:
1444 return 0;
1445
1446 case AND:
1447 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
1448
1449 default:
1450 abort ();
1451 }
1452 }
1453
1454 /* Emit a sequence of insns to handle a large constant.
1455 CODE is the code of the operation required, it can be any of SET, PLUS,
1456 IOR, AND, XOR, MINUS;
1457 MODE is the mode in which the operation is being performed;
1458 VAL is the integer to operate on;
1459 SOURCE is the other operand (a register, or a null-pointer for SET);
1460 SUBTARGETS means it is safe to create scratch registers if that will
1461 either produce a simpler sequence, or we will want to cse the values.
1462 Return value is the number of insns emitted. */
1463
1464 int
1465 arm_split_constant (enum rtx_code code, enum machine_mode mode, rtx insn,
1466 HOST_WIDE_INT val, rtx target, rtx source, int subtargets)
1467 {
1468 rtx cond;
1469
1470 if (insn && GET_CODE (PATTERN (insn)) == COND_EXEC)
1471 cond = COND_EXEC_TEST (PATTERN (insn));
1472 else
1473 cond = NULL_RTX;
1474
1475 if (subtargets || code == SET
1476 || (GET_CODE (target) == REG && GET_CODE (source) == REG
1477 && REGNO (target) != REGNO (source)))
1478 {
1479 /* After arm_reorg has been called, we can't fix up expensive
1480 constants by pushing them into memory so we must synthesize
1481 them in-line, regardless of the cost. This is only likely to
1482 be more costly on chips that have load delay slots and we are
1483 compiling without running the scheduler (so no splitting
1484 occurred before the final instruction emission).
1485
1486 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
1487 */
1488 if (!after_arm_reorg
1489 && !cond
1490 && (arm_gen_constant (code, mode, NULL_RTX, val, target, source,
1491 1, 0)
1492 > arm_constant_limit + (code != SET)))
1493 {
1494 if (code == SET)
1495 {
1496 /* Currently SET is the only monadic value for CODE, all
1497 the rest are diadic. */
1498 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val)));
1499 return 1;
1500 }
1501 else
1502 {
1503 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
1504
1505 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val)));
1506 /* For MINUS, the value is subtracted from, since we never
1507 have subtraction of a constant. */
1508 if (code == MINUS)
1509 emit_insn (gen_rtx_SET (VOIDmode, target,
1510 gen_rtx_MINUS (mode, temp, source)));
1511 else
1512 emit_insn (gen_rtx_SET (VOIDmode, target,
1513 gen_rtx_fmt_ee (code, mode, source, temp)));
1514 return 2;
1515 }
1516 }
1517 }
1518
1519 return arm_gen_constant (code, mode, cond, val, target, source, subtargets,
1520 1);
1521 }
1522
1523 static int
1524 count_insns_for_constant (HOST_WIDE_INT remainder, int i)
1525 {
1526 HOST_WIDE_INT temp1;
1527 int num_insns = 0;
1528 do
1529 {
1530 int end;
1531
1532 if (i <= 0)
1533 i += 32;
1534 if (remainder & (3 << (i - 2)))
1535 {
1536 end = i - 8;
1537 if (end < 0)
1538 end += 32;
1539 temp1 = remainder & ((0x0ff << end)
1540 | ((i < end) ? (0xff >> (32 - end)) : 0));
1541 remainder &= ~temp1;
1542 num_insns++;
1543 i -= 6;
1544 }
1545 i -= 2;
1546 } while (remainder);
1547 return num_insns;
1548 }
1549
1550 /* Emit an instruction with the indicated PATTERN. If COND is
1551 non-NULL, conditionalize the execution of the instruction on COND
1552 being true. */
1553
1554 static void
1555 emit_constant_insn (rtx cond, rtx pattern)
1556 {
1557 if (cond)
1558 pattern = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond), pattern);
1559 emit_insn (pattern);
1560 }
1561
1562 /* As above, but extra parameter GENERATE which, if clear, suppresses
1563 RTL generation. */
1564
1565 static int
1566 arm_gen_constant (enum rtx_code code, enum machine_mode mode, rtx cond,
1567 HOST_WIDE_INT val, rtx target, rtx source, int subtargets,
1568 int generate)
1569 {
1570 int can_invert = 0;
1571 int can_negate = 0;
1572 int can_negate_initial = 0;
1573 int can_shift = 0;
1574 int i;
1575 int num_bits_set = 0;
1576 int set_sign_bit_copies = 0;
1577 int clear_sign_bit_copies = 0;
1578 int clear_zero_bit_copies = 0;
1579 int set_zero_bit_copies = 0;
1580 int insns = 0;
1581 unsigned HOST_WIDE_INT temp1, temp2;
1582 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
1583
1584 /* Find out which operations are safe for a given CODE. Also do a quick
1585 check for degenerate cases; these can occur when DImode operations
1586 are split. */
1587 switch (code)
1588 {
1589 case SET:
1590 can_invert = 1;
1591 can_shift = 1;
1592 can_negate = 1;
1593 break;
1594
1595 case PLUS:
1596 can_negate = 1;
1597 can_negate_initial = 1;
1598 break;
1599
1600 case IOR:
1601 if (remainder == 0xffffffff)
1602 {
1603 if (generate)
1604 emit_constant_insn (cond,
1605 gen_rtx_SET (VOIDmode, target,
1606 GEN_INT (ARM_SIGN_EXTEND (val))));
1607 return 1;
1608 }
1609 if (remainder == 0)
1610 {
1611 if (reload_completed && rtx_equal_p (target, source))
1612 return 0;
1613 if (generate)
1614 emit_constant_insn (cond,
1615 gen_rtx_SET (VOIDmode, target, source));
1616 return 1;
1617 }
1618 break;
1619
1620 case AND:
1621 if (remainder == 0)
1622 {
1623 if (generate)
1624 emit_constant_insn (cond,
1625 gen_rtx_SET (VOIDmode, target, const0_rtx));
1626 return 1;
1627 }
1628 if (remainder == 0xffffffff)
1629 {
1630 if (reload_completed && rtx_equal_p (target, source))
1631 return 0;
1632 if (generate)
1633 emit_constant_insn (cond,
1634 gen_rtx_SET (VOIDmode, target, source));
1635 return 1;
1636 }
1637 can_invert = 1;
1638 break;
1639
1640 case XOR:
1641 if (remainder == 0)
1642 {
1643 if (reload_completed && rtx_equal_p (target, source))
1644 return 0;
1645 if (generate)
1646 emit_constant_insn (cond,
1647 gen_rtx_SET (VOIDmode, target, source));
1648 return 1;
1649 }
1650 if (remainder == 0xffffffff)
1651 {
1652 if (generate)
1653 emit_constant_insn (cond,
1654 gen_rtx_SET (VOIDmode, target,
1655 gen_rtx_NOT (mode, source)));
1656 return 1;
1657 }
1658
1659 /* We don't know how to handle this yet below. */
1660 abort ();
1661
1662 case MINUS:
1663 /* We treat MINUS as (val - source), since (source - val) is always
1664 passed as (source + (-val)). */
1665 if (remainder == 0)
1666 {
1667 if (generate)
1668 emit_constant_insn (cond,
1669 gen_rtx_SET (VOIDmode, target,
1670 gen_rtx_NEG (mode, source)));
1671 return 1;
1672 }
1673 if (const_ok_for_arm (val))
1674 {
1675 if (generate)
1676 emit_constant_insn (cond,
1677 gen_rtx_SET (VOIDmode, target,
1678 gen_rtx_MINUS (mode, GEN_INT (val),
1679 source)));
1680 return 1;
1681 }
1682 can_negate = 1;
1683
1684 break;
1685
1686 default:
1687 abort ();
1688 }
1689
1690 /* If we can do it in one insn get out quickly. */
1691 if (const_ok_for_arm (val)
1692 || (can_negate_initial && const_ok_for_arm (-val))
1693 || (can_invert && const_ok_for_arm (~val)))
1694 {
1695 if (generate)
1696 emit_constant_insn (cond,
1697 gen_rtx_SET (VOIDmode, target,
1698 (source
1699 ? gen_rtx_fmt_ee (code, mode, source,
1700 GEN_INT (val))
1701 : GEN_INT (val))));
1702 return 1;
1703 }
1704
1705 /* Calculate a few attributes that may be useful for specific
1706 optimizations. */
1707 for (i = 31; i >= 0; i--)
1708 {
1709 if ((remainder & (1 << i)) == 0)
1710 clear_sign_bit_copies++;
1711 else
1712 break;
1713 }
1714
1715 for (i = 31; i >= 0; i--)
1716 {
1717 if ((remainder & (1 << i)) != 0)
1718 set_sign_bit_copies++;
1719 else
1720 break;
1721 }
1722
1723 for (i = 0; i <= 31; i++)
1724 {
1725 if ((remainder & (1 << i)) == 0)
1726 clear_zero_bit_copies++;
1727 else
1728 break;
1729 }
1730
1731 for (i = 0; i <= 31; i++)
1732 {
1733 if ((remainder & (1 << i)) != 0)
1734 set_zero_bit_copies++;
1735 else
1736 break;
1737 }
1738
1739 switch (code)
1740 {
1741 case SET:
1742 /* See if we can do this by sign_extending a constant that is known
1743 to be negative. This is a good, way of doing it, since the shift
1744 may well merge into a subsequent insn. */
1745 if (set_sign_bit_copies > 1)
1746 {
1747 if (const_ok_for_arm
1748 (temp1 = ARM_SIGN_EXTEND (remainder
1749 << (set_sign_bit_copies - 1))))
1750 {
1751 if (generate)
1752 {
1753 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1754 emit_constant_insn (cond,
1755 gen_rtx_SET (VOIDmode, new_src,
1756 GEN_INT (temp1)));
1757 emit_constant_insn (cond,
1758 gen_ashrsi3 (target, new_src,
1759 GEN_INT (set_sign_bit_copies - 1)));
1760 }
1761 return 2;
1762 }
1763 /* For an inverted constant, we will need to set the low bits,
1764 these will be shifted out of harm's way. */
1765 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
1766 if (const_ok_for_arm (~temp1))
1767 {
1768 if (generate)
1769 {
1770 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1771 emit_constant_insn (cond,
1772 gen_rtx_SET (VOIDmode, new_src,
1773 GEN_INT (temp1)));
1774 emit_constant_insn (cond,
1775 gen_ashrsi3 (target, new_src,
1776 GEN_INT (set_sign_bit_copies - 1)));
1777 }
1778 return 2;
1779 }
1780 }
1781
1782 /* See if we can generate this by setting the bottom (or the top)
1783 16 bits, and then shifting these into the other half of the
1784 word. We only look for the simplest cases, to do more would cost
1785 too much. Be careful, however, not to generate this when the
1786 alternative would take fewer insns. */
1787 if (val & 0xffff0000)
1788 {
1789 temp1 = remainder & 0xffff0000;
1790 temp2 = remainder & 0x0000ffff;
1791
1792 /* Overlaps outside this range are best done using other methods. */
1793 for (i = 9; i < 24; i++)
1794 {
1795 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
1796 && !const_ok_for_arm (temp2))
1797 {
1798 rtx new_src = (subtargets
1799 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1800 : target);
1801 insns = arm_gen_constant (code, mode, cond, temp2, new_src,
1802 source, subtargets, generate);
1803 source = new_src;
1804 if (generate)
1805 emit_constant_insn
1806 (cond,
1807 gen_rtx_SET
1808 (VOIDmode, target,
1809 gen_rtx_IOR (mode,
1810 gen_rtx_ASHIFT (mode, source,
1811 GEN_INT (i)),
1812 source)));
1813 return insns + 1;
1814 }
1815 }
1816
1817 /* Don't duplicate cases already considered. */
1818 for (i = 17; i < 24; i++)
1819 {
1820 if (((temp1 | (temp1 >> i)) == remainder)
1821 && !const_ok_for_arm (temp1))
1822 {
1823 rtx new_src = (subtargets
1824 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1825 : target);
1826 insns = arm_gen_constant (code, mode, cond, temp1, new_src,
1827 source, subtargets, generate);
1828 source = new_src;
1829 if (generate)
1830 emit_constant_insn
1831 (cond,
1832 gen_rtx_SET (VOIDmode, target,
1833 gen_rtx_IOR
1834 (mode,
1835 gen_rtx_LSHIFTRT (mode, source,
1836 GEN_INT (i)),
1837 source)));
1838 return insns + 1;
1839 }
1840 }
1841 }
1842 break;
1843
1844 case IOR:
1845 case XOR:
1846 /* If we have IOR or XOR, and the constant can be loaded in a
1847 single instruction, and we can find a temporary to put it in,
1848 then this can be done in two instructions instead of 3-4. */
1849 if (subtargets
1850 /* TARGET can't be NULL if SUBTARGETS is 0 */
1851 || (reload_completed && !reg_mentioned_p (target, source)))
1852 {
1853 if (const_ok_for_arm (ARM_SIGN_EXTEND (~val)))
1854 {
1855 if (generate)
1856 {
1857 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1858
1859 emit_constant_insn (cond,
1860 gen_rtx_SET (VOIDmode, sub,
1861 GEN_INT (val)));
1862 emit_constant_insn (cond,
1863 gen_rtx_SET (VOIDmode, target,
1864 gen_rtx_fmt_ee (code, mode,
1865 source, sub)));
1866 }
1867 return 2;
1868 }
1869 }
1870
1871 if (code == XOR)
1872 break;
1873
1874 if (set_sign_bit_copies > 8
1875 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
1876 {
1877 if (generate)
1878 {
1879 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1880 rtx shift = GEN_INT (set_sign_bit_copies);
1881
1882 emit_constant_insn
1883 (cond,
1884 gen_rtx_SET (VOIDmode, sub,
1885 gen_rtx_NOT (mode,
1886 gen_rtx_ASHIFT (mode,
1887 source,
1888 shift))));
1889 emit_constant_insn
1890 (cond,
1891 gen_rtx_SET (VOIDmode, target,
1892 gen_rtx_NOT (mode,
1893 gen_rtx_LSHIFTRT (mode, sub,
1894 shift))));
1895 }
1896 return 2;
1897 }
1898
1899 if (set_zero_bit_copies > 8
1900 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
1901 {
1902 if (generate)
1903 {
1904 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1905 rtx shift = GEN_INT (set_zero_bit_copies);
1906
1907 emit_constant_insn
1908 (cond,
1909 gen_rtx_SET (VOIDmode, sub,
1910 gen_rtx_NOT (mode,
1911 gen_rtx_LSHIFTRT (mode,
1912 source,
1913 shift))));
1914 emit_constant_insn
1915 (cond,
1916 gen_rtx_SET (VOIDmode, target,
1917 gen_rtx_NOT (mode,
1918 gen_rtx_ASHIFT (mode, sub,
1919 shift))));
1920 }
1921 return 2;
1922 }
1923
1924 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val)))
1925 {
1926 if (generate)
1927 {
1928 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1929 emit_constant_insn (cond,
1930 gen_rtx_SET (VOIDmode, sub,
1931 gen_rtx_NOT (mode, source)));
1932 source = sub;
1933 if (subtargets)
1934 sub = gen_reg_rtx (mode);
1935 emit_constant_insn (cond,
1936 gen_rtx_SET (VOIDmode, sub,
1937 gen_rtx_AND (mode, source,
1938 GEN_INT (temp1))));
1939 emit_constant_insn (cond,
1940 gen_rtx_SET (VOIDmode, target,
1941 gen_rtx_NOT (mode, sub)));
1942 }
1943 return 3;
1944 }
1945 break;
1946
1947 case AND:
1948 /* See if two shifts will do 2 or more insn's worth of work. */
1949 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
1950 {
1951 HOST_WIDE_INT shift_mask = ((0xffffffff
1952 << (32 - clear_sign_bit_copies))
1953 & 0xffffffff);
1954
1955 if ((remainder | shift_mask) != 0xffffffff)
1956 {
1957 if (generate)
1958 {
1959 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1960 insns = arm_gen_constant (AND, mode, cond,
1961 remainder | shift_mask,
1962 new_src, source, subtargets, 1);
1963 source = new_src;
1964 }
1965 else
1966 {
1967 rtx targ = subtargets ? NULL_RTX : target;
1968 insns = arm_gen_constant (AND, mode, cond,
1969 remainder | shift_mask,
1970 targ, source, subtargets, 0);
1971 }
1972 }
1973
1974 if (generate)
1975 {
1976 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1977 rtx shift = GEN_INT (clear_sign_bit_copies);
1978
1979 emit_insn (gen_ashlsi3 (new_src, source, shift));
1980 emit_insn (gen_lshrsi3 (target, new_src, shift));
1981 }
1982
1983 return insns + 2;
1984 }
1985
1986 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
1987 {
1988 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
1989
1990 if ((remainder | shift_mask) != 0xffffffff)
1991 {
1992 if (generate)
1993 {
1994 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1995
1996 insns = arm_gen_constant (AND, mode, cond,
1997 remainder | shift_mask,
1998 new_src, source, subtargets, 1);
1999 source = new_src;
2000 }
2001 else
2002 {
2003 rtx targ = subtargets ? NULL_RTX : target;
2004
2005 insns = arm_gen_constant (AND, mode, cond,
2006 remainder | shift_mask,
2007 targ, source, subtargets, 0);
2008 }
2009 }
2010
2011 if (generate)
2012 {
2013 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
2014 rtx shift = GEN_INT (clear_zero_bit_copies);
2015
2016 emit_insn (gen_lshrsi3 (new_src, source, shift));
2017 emit_insn (gen_ashlsi3 (target, new_src, shift));
2018 }
2019
2020 return insns + 2;
2021 }
2022
2023 break;
2024
2025 default:
2026 break;
2027 }
2028
2029 for (i = 0; i < 32; i++)
2030 if (remainder & (1 << i))
2031 num_bits_set++;
2032
2033 if (code == AND || (can_invert && num_bits_set > 16))
2034 remainder = (~remainder) & 0xffffffff;
2035 else if (code == PLUS && num_bits_set > 16)
2036 remainder = (-remainder) & 0xffffffff;
2037 else
2038 {
2039 can_invert = 0;
2040 can_negate = 0;
2041 }
2042
2043 /* Now try and find a way of doing the job in either two or three
2044 instructions.
2045 We start by looking for the largest block of zeros that are aligned on
2046 a 2-bit boundary, we then fill up the temps, wrapping around to the
2047 top of the word when we drop off the bottom.
2048 In the worst case this code should produce no more than four insns. */
2049 {
2050 int best_start = 0;
2051 int best_consecutive_zeros = 0;
2052
2053 for (i = 0; i < 32; i += 2)
2054 {
2055 int consecutive_zeros = 0;
2056
2057 if (!(remainder & (3 << i)))
2058 {
2059 while ((i < 32) && !(remainder & (3 << i)))
2060 {
2061 consecutive_zeros += 2;
2062 i += 2;
2063 }
2064 if (consecutive_zeros > best_consecutive_zeros)
2065 {
2066 best_consecutive_zeros = consecutive_zeros;
2067 best_start = i - consecutive_zeros;
2068 }
2069 i -= 2;
2070 }
2071 }
2072
2073 /* So long as it won't require any more insns to do so, it's
2074 desirable to emit a small constant (in bits 0...9) in the last
2075 insn. This way there is more chance that it can be combined with
2076 a later addressing insn to form a pre-indexed load or store
2077 operation. Consider:
2078
2079 *((volatile int *)0xe0000100) = 1;
2080 *((volatile int *)0xe0000110) = 2;
2081
2082 We want this to wind up as:
2083
2084 mov rA, #0xe0000000
2085 mov rB, #1
2086 str rB, [rA, #0x100]
2087 mov rB, #2
2088 str rB, [rA, #0x110]
2089
2090 rather than having to synthesize both large constants from scratch.
2091
2092 Therefore, we calculate how many insns would be required to emit
2093 the constant starting from `best_start', and also starting from
2094 zero (ie with bit 31 first to be output). If `best_start' doesn't
2095 yield a shorter sequence, we may as well use zero. */
2096 if (best_start != 0
2097 && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder)
2098 && (count_insns_for_constant (remainder, 0) <=
2099 count_insns_for_constant (remainder, best_start)))
2100 best_start = 0;
2101
2102 /* Now start emitting the insns. */
2103 i = best_start;
2104 do
2105 {
2106 int end;
2107
2108 if (i <= 0)
2109 i += 32;
2110 if (remainder & (3 << (i - 2)))
2111 {
2112 end = i - 8;
2113 if (end < 0)
2114 end += 32;
2115 temp1 = remainder & ((0x0ff << end)
2116 | ((i < end) ? (0xff >> (32 - end)) : 0));
2117 remainder &= ~temp1;
2118
2119 if (generate)
2120 {
2121 rtx new_src, temp1_rtx;
2122
2123 if (code == SET || code == MINUS)
2124 {
2125 new_src = (subtargets ? gen_reg_rtx (mode) : target);
2126 if (can_invert && code != MINUS)
2127 temp1 = ~temp1;
2128 }
2129 else
2130 {
2131 if (remainder && subtargets)
2132 new_src = gen_reg_rtx (mode);
2133 else
2134 new_src = target;
2135 if (can_invert)
2136 temp1 = ~temp1;
2137 else if (can_negate)
2138 temp1 = -temp1;
2139 }
2140
2141 temp1 = trunc_int_for_mode (temp1, mode);
2142 temp1_rtx = GEN_INT (temp1);
2143
2144 if (code == SET)
2145 ;
2146 else if (code == MINUS)
2147 temp1_rtx = gen_rtx_MINUS (mode, temp1_rtx, source);
2148 else
2149 temp1_rtx = gen_rtx_fmt_ee (code, mode, source, temp1_rtx);
2150
2151 emit_constant_insn (cond,
2152 gen_rtx_SET (VOIDmode, new_src,
2153 temp1_rtx));
2154 source = new_src;
2155 }
2156
2157 if (code == SET)
2158 {
2159 can_invert = 0;
2160 code = PLUS;
2161 }
2162 else if (code == MINUS)
2163 code = PLUS;
2164
2165 insns++;
2166 i -= 6;
2167 }
2168 i -= 2;
2169 }
2170 while (remainder);
2171 }
2172
2173 return insns;
2174 }
2175
2176 /* Canonicalize a comparison so that we are more likely to recognize it.
2177 This can be done for a few constant compares, where we can make the
2178 immediate value easier to load. */
2179
2180 enum rtx_code
2181 arm_canonicalize_comparison (enum rtx_code code, rtx * op1)
2182 {
2183 unsigned HOST_WIDE_INT i = INTVAL (*op1);
2184
2185 switch (code)
2186 {
2187 case EQ:
2188 case NE:
2189 return code;
2190
2191 case GT:
2192 case LE:
2193 if (i != ((((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1)) - 1)
2194 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2195 {
2196 *op1 = GEN_INT (i + 1);
2197 return code == GT ? GE : LT;
2198 }
2199 break;
2200
2201 case GE:
2202 case LT:
2203 if (i != (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
2204 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2205 {
2206 *op1 = GEN_INT (i - 1);
2207 return code == GE ? GT : LE;
2208 }
2209 break;
2210
2211 case GTU:
2212 case LEU:
2213 if (i != ~((unsigned HOST_WIDE_INT) 0)
2214 && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1))))
2215 {
2216 *op1 = GEN_INT (i + 1);
2217 return code == GTU ? GEU : LTU;
2218 }
2219 break;
2220
2221 case GEU:
2222 case LTU:
2223 if (i != 0
2224 && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1))))
2225 {
2226 *op1 = GEN_INT (i - 1);
2227 return code == GEU ? GTU : LEU;
2228 }
2229 break;
2230
2231 default:
2232 abort ();
2233 }
2234
2235 return code;
2236 }
2237
2238
2239 /* Define how to find the value returned by a function. */
2240
2241 rtx arm_function_value(tree type, tree func ATTRIBUTE_UNUSED)
2242 {
2243 enum machine_mode mode;
2244 int unsignedp ATTRIBUTE_UNUSED;
2245 rtx r ATTRIBUTE_UNUSED;
2246
2247
2248 mode = TYPE_MODE (type);
2249 /* Promote integer types. */
2250 if (INTEGRAL_TYPE_P (type))
2251 PROMOTE_FUNCTION_MODE (mode, unsignedp, type);
2252 return LIBCALL_VALUE(mode);
2253 }
2254
2255
2256 /* Decide whether a type should be returned in memory (true)
2257 or in a register (false). This is called by the macro
2258 RETURN_IN_MEMORY. */
2259 int
2260 arm_return_in_memory (tree type)
2261 {
2262 HOST_WIDE_INT size;
2263
2264 if (!AGGREGATE_TYPE_P (type))
2265 /* All simple types are returned in registers. */
2266 return 0;
2267
2268 size = int_size_in_bytes (type);
2269
2270 if (arm_abi != ARM_ABI_APCS)
2271 {
2272 /* ATPCS and later return aggregate types in memory only if they are
2273 larger than a word (or are variable size). */
2274 return (size < 0 || size > UNITS_PER_WORD);
2275 }
2276
2277 /* For the arm-wince targets we choose to be compatible with Microsoft's
2278 ARM and Thumb compilers, which always return aggregates in memory. */
2279 #ifndef ARM_WINCE
2280 /* All structures/unions bigger than one word are returned in memory.
2281 Also catch the case where int_size_in_bytes returns -1. In this case
2282 the aggregate is either huge or of variable size, and in either case
2283 we will want to return it via memory and not in a register. */
2284 if (size < 0 || size > UNITS_PER_WORD)
2285 return 1;
2286
2287 if (TREE_CODE (type) == RECORD_TYPE)
2288 {
2289 tree field;
2290
2291 /* For a struct the APCS says that we only return in a register
2292 if the type is 'integer like' and every addressable element
2293 has an offset of zero. For practical purposes this means
2294 that the structure can have at most one non bit-field element
2295 and that this element must be the first one in the structure. */
2296
2297 /* Find the first field, ignoring non FIELD_DECL things which will
2298 have been created by C++. */
2299 for (field = TYPE_FIELDS (type);
2300 field && TREE_CODE (field) != FIELD_DECL;
2301 field = TREE_CHAIN (field))
2302 continue;
2303
2304 if (field == NULL)
2305 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
2306
2307 /* Check that the first field is valid for returning in a register. */
2308
2309 /* ... Floats are not allowed */
2310 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2311 return 1;
2312
2313 /* ... Aggregates that are not themselves valid for returning in
2314 a register are not allowed. */
2315 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2316 return 1;
2317
2318 /* Now check the remaining fields, if any. Only bitfields are allowed,
2319 since they are not addressable. */
2320 for (field = TREE_CHAIN (field);
2321 field;
2322 field = TREE_CHAIN (field))
2323 {
2324 if (TREE_CODE (field) != FIELD_DECL)
2325 continue;
2326
2327 if (!DECL_BIT_FIELD_TYPE (field))
2328 return 1;
2329 }
2330
2331 return 0;
2332 }
2333
2334 if (TREE_CODE (type) == UNION_TYPE)
2335 {
2336 tree field;
2337
2338 /* Unions can be returned in registers if every element is
2339 integral, or can be returned in an integer register. */
2340 for (field = TYPE_FIELDS (type);
2341 field;
2342 field = TREE_CHAIN (field))
2343 {
2344 if (TREE_CODE (field) != FIELD_DECL)
2345 continue;
2346
2347 if (FLOAT_TYPE_P (TREE_TYPE (field)))
2348 return 1;
2349
2350 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
2351 return 1;
2352 }
2353
2354 return 0;
2355 }
2356 #endif /* not ARM_WINCE */
2357
2358 /* Return all other types in memory. */
2359 return 1;
2360 }
2361
2362 /* Indicate whether or not words of a double are in big-endian order. */
2363
2364 int
2365 arm_float_words_big_endian (void)
2366 {
2367 if (TARGET_MAVERICK)
2368 return 0;
2369
2370 /* For FPA, float words are always big-endian. For VFP, floats words
2371 follow the memory system mode. */
2372
2373 if (TARGET_FPA)
2374 {
2375 return 1;
2376 }
2377
2378 if (TARGET_VFP)
2379 return (TARGET_BIG_END ? 1 : 0);
2380
2381 return 1;
2382 }
2383
2384 /* Initialize a variable CUM of type CUMULATIVE_ARGS
2385 for a call to a function whose data type is FNTYPE.
2386 For a library call, FNTYPE is NULL. */
2387 void
2388 arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype,
2389 rtx libname ATTRIBUTE_UNUSED,
2390 tree fndecl ATTRIBUTE_UNUSED)
2391 {
2392 /* On the ARM, the offset starts at 0. */
2393 pcum->nregs = ((fntype && aggregate_value_p (TREE_TYPE (fntype), fntype)) ? 1 : 0);
2394 pcum->iwmmxt_nregs = 0;
2395 pcum->can_split = true;
2396
2397 pcum->call_cookie = CALL_NORMAL;
2398
2399 if (TARGET_LONG_CALLS)
2400 pcum->call_cookie = CALL_LONG;
2401
2402 /* Check for long call/short call attributes. The attributes
2403 override any command line option. */
2404 if (fntype)
2405 {
2406 if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (fntype)))
2407 pcum->call_cookie = CALL_SHORT;
2408 else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (fntype)))
2409 pcum->call_cookie = CALL_LONG;
2410 }
2411
2412 /* Varargs vectors are treated the same as long long.
2413 named_count avoids having to change the way arm handles 'named' */
2414 pcum->named_count = 0;
2415 pcum->nargs = 0;
2416
2417 if (TARGET_REALLY_IWMMXT && fntype)
2418 {
2419 tree fn_arg;
2420
2421 for (fn_arg = TYPE_ARG_TYPES (fntype);
2422 fn_arg;
2423 fn_arg = TREE_CHAIN (fn_arg))
2424 pcum->named_count += 1;
2425
2426 if (! pcum->named_count)
2427 pcum->named_count = INT_MAX;
2428 }
2429 }
2430
2431
2432 /* Return true if mode/type need doubleword alignment. */
2433 bool
2434 arm_needs_doubleword_align (enum machine_mode mode, tree type)
2435 {
2436 return (GET_MODE_ALIGNMENT (mode) > PARM_BOUNDARY
2437 || (type && TYPE_ALIGN (type) > PARM_BOUNDARY));
2438 }
2439
2440
2441 /* Determine where to put an argument to a function.
2442 Value is zero to push the argument on the stack,
2443 or a hard register in which to store the argument.
2444
2445 MODE is the argument's machine mode.
2446 TYPE is the data type of the argument (as a tree).
2447 This is null for libcalls where that information may
2448 not be available.
2449 CUM is a variable of type CUMULATIVE_ARGS which gives info about
2450 the preceding args and about the function being called.
2451 NAMED is nonzero if this argument is a named parameter
2452 (otherwise it is an extra parameter matching an ellipsis). */
2453
2454 rtx
2455 arm_function_arg (CUMULATIVE_ARGS *pcum, enum machine_mode mode,
2456 tree type, int named)
2457 {
2458 int nregs;
2459
2460 /* Varargs vectors are treated the same as long long.
2461 named_count avoids having to change the way arm handles 'named' */
2462 if (TARGET_IWMMXT_ABI
2463 && VECTOR_MODE_SUPPORTED_P (mode)
2464 && pcum->named_count > pcum->nargs + 1)
2465 {
2466 if (pcum->iwmmxt_nregs <= 9)
2467 return gen_rtx_REG (mode, pcum->iwmmxt_nregs + FIRST_IWMMXT_REGNUM);
2468 else
2469 {
2470 pcum->can_split = false;
2471 return NULL_RTX;
2472 }
2473 }
2474
2475 /* Put doubleword aligned quantities in even register pairs. */
2476 if (pcum->nregs & 1
2477 && ARM_DOUBLEWORD_ALIGN
2478 && arm_needs_doubleword_align (mode, type))
2479 pcum->nregs++;
2480
2481 if (mode == VOIDmode)
2482 /* Compute operand 2 of the call insn. */
2483 return GEN_INT (pcum->call_cookie);
2484
2485 /* Only allow splitting an arg between regs and memory if all preceding
2486 args were allocated to regs. For args passed by reference we only count
2487 the reference pointer. */
2488 if (pcum->can_split)
2489 nregs = 1;
2490 else
2491 nregs = ARM_NUM_REGS2 (mode, type);
2492
2493 if (!named || pcum->nregs + nregs > NUM_ARG_REGS)
2494 return NULL_RTX;
2495
2496 return gen_rtx_REG (mode, pcum->nregs);
2497 }
2498
2499 /* Variable sized types are passed by reference. This is a GCC
2500 extension to the ARM ABI. */
2501
2502 static bool
2503 arm_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
2504 enum machine_mode mode ATTRIBUTE_UNUSED,
2505 tree type, bool named ATTRIBUTE_UNUSED)
2506 {
2507 return type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST;
2508 }
2509 \f
2510 /* Encode the current state of the #pragma [no_]long_calls. */
2511 typedef enum
2512 {
2513 OFF, /* No #pramgma [no_]long_calls is in effect. */
2514 LONG, /* #pragma long_calls is in effect. */
2515 SHORT /* #pragma no_long_calls is in effect. */
2516 } arm_pragma_enum;
2517
2518 static arm_pragma_enum arm_pragma_long_calls = OFF;
2519
2520 void
2521 arm_pr_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2522 {
2523 arm_pragma_long_calls = LONG;
2524 }
2525
2526 void
2527 arm_pr_no_long_calls (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2528 {
2529 arm_pragma_long_calls = SHORT;
2530 }
2531
2532 void
2533 arm_pr_long_calls_off (struct cpp_reader * pfile ATTRIBUTE_UNUSED)
2534 {
2535 arm_pragma_long_calls = OFF;
2536 }
2537 \f
2538 /* Table of machine attributes. */
2539 const struct attribute_spec arm_attribute_table[] =
2540 {
2541 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2542 /* Function calls made to this symbol must be done indirectly, because
2543 it may lie outside of the 26 bit addressing range of a normal function
2544 call. */
2545 { "long_call", 0, 0, false, true, true, NULL },
2546 /* Whereas these functions are always known to reside within the 26 bit
2547 addressing range. */
2548 { "short_call", 0, 0, false, true, true, NULL },
2549 /* Interrupt Service Routines have special prologue and epilogue requirements. */
2550 { "isr", 0, 1, false, false, false, arm_handle_isr_attribute },
2551 { "interrupt", 0, 1, false, false, false, arm_handle_isr_attribute },
2552 { "naked", 0, 0, true, false, false, arm_handle_fndecl_attribute },
2553 #ifdef ARM_PE
2554 /* ARM/PE has three new attributes:
2555 interfacearm - ?
2556 dllexport - for exporting a function/variable that will live in a dll
2557 dllimport - for importing a function/variable from a dll
2558
2559 Microsoft allows multiple declspecs in one __declspec, separating
2560 them with spaces. We do NOT support this. Instead, use __declspec
2561 multiple times.
2562 */
2563 { "dllimport", 0, 0, true, false, false, NULL },
2564 { "dllexport", 0, 0, true, false, false, NULL },
2565 { "interfacearm", 0, 0, true, false, false, arm_handle_fndecl_attribute },
2566 #elif TARGET_DLLIMPORT_DECL_ATTRIBUTES
2567 { "dllimport", 0, 0, false, false, false, handle_dll_attribute },
2568 { "dllexport", 0, 0, false, false, false, handle_dll_attribute },
2569 #endif
2570 { NULL, 0, 0, false, false, false, NULL }
2571 };
2572
2573 /* Handle an attribute requiring a FUNCTION_DECL;
2574 arguments as in struct attribute_spec.handler. */
2575 static tree
2576 arm_handle_fndecl_attribute (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
2577 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
2578 {
2579 if (TREE_CODE (*node) != FUNCTION_DECL)
2580 {
2581 warning ("`%s' attribute only applies to functions",
2582 IDENTIFIER_POINTER (name));
2583 *no_add_attrs = true;
2584 }
2585
2586 return NULL_TREE;
2587 }
2588
2589 /* Handle an "interrupt" or "isr" attribute;
2590 arguments as in struct attribute_spec.handler. */
2591 static tree
2592 arm_handle_isr_attribute (tree *node, tree name, tree args, int flags,
2593 bool *no_add_attrs)
2594 {
2595 if (DECL_P (*node))
2596 {
2597 if (TREE_CODE (*node) != FUNCTION_DECL)
2598 {
2599 warning ("`%s' attribute only applies to functions",
2600 IDENTIFIER_POINTER (name));
2601 *no_add_attrs = true;
2602 }
2603 /* FIXME: the argument if any is checked for type attributes;
2604 should it be checked for decl ones? */
2605 }
2606 else
2607 {
2608 if (TREE_CODE (*node) == FUNCTION_TYPE
2609 || TREE_CODE (*node) == METHOD_TYPE)
2610 {
2611 if (arm_isr_value (args) == ARM_FT_UNKNOWN)
2612 {
2613 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
2614 *no_add_attrs = true;
2615 }
2616 }
2617 else if (TREE_CODE (*node) == POINTER_TYPE
2618 && (TREE_CODE (TREE_TYPE (*node)) == FUNCTION_TYPE
2619 || TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
2620 && arm_isr_value (args) != ARM_FT_UNKNOWN)
2621 {
2622 *node = build_type_copy (*node);
2623 TREE_TYPE (*node) = build_type_attribute_variant
2624 (TREE_TYPE (*node),
2625 tree_cons (name, args, TYPE_ATTRIBUTES (TREE_TYPE (*node))));
2626 *no_add_attrs = true;
2627 }
2628 else
2629 {
2630 /* Possibly pass this attribute on from the type to a decl. */
2631 if (flags & ((int) ATTR_FLAG_DECL_NEXT
2632 | (int) ATTR_FLAG_FUNCTION_NEXT
2633 | (int) ATTR_FLAG_ARRAY_NEXT))
2634 {
2635 *no_add_attrs = true;
2636 return tree_cons (name, args, NULL_TREE);
2637 }
2638 else
2639 {
2640 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
2641 }
2642 }
2643 }
2644
2645 return NULL_TREE;
2646 }
2647
2648 /* Return 0 if the attributes for two types are incompatible, 1 if they
2649 are compatible, and 2 if they are nearly compatible (which causes a
2650 warning to be generated). */
2651 static int
2652 arm_comp_type_attributes (tree type1, tree type2)
2653 {
2654 int l1, l2, s1, s2;
2655
2656 /* Check for mismatch of non-default calling convention. */
2657 if (TREE_CODE (type1) != FUNCTION_TYPE)
2658 return 1;
2659
2660 /* Check for mismatched call attributes. */
2661 l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL;
2662 l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL;
2663 s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL;
2664 s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL;
2665
2666 /* Only bother to check if an attribute is defined. */
2667 if (l1 | l2 | s1 | s2)
2668 {
2669 /* If one type has an attribute, the other must have the same attribute. */
2670 if ((l1 != l2) || (s1 != s2))
2671 return 0;
2672
2673 /* Disallow mixed attributes. */
2674 if ((l1 & s2) || (l2 & s1))
2675 return 0;
2676 }
2677
2678 /* Check for mismatched ISR attribute. */
2679 l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL;
2680 if (! l1)
2681 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL;
2682 l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL;
2683 if (! l2)
2684 l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL;
2685 if (l1 != l2)
2686 return 0;
2687
2688 return 1;
2689 }
2690
2691 /* Encode long_call or short_call attribute by prefixing
2692 symbol name in DECL with a special character FLAG. */
2693 void
2694 arm_encode_call_attribute (tree decl, int flag)
2695 {
2696 const char * str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2697 int len = strlen (str);
2698 char * newstr;
2699
2700 /* Do not allow weak functions to be treated as short call. */
2701 if (DECL_WEAK (decl) && flag == SHORT_CALL_FLAG_CHAR)
2702 return;
2703
2704 newstr = alloca (len + 2);
2705 newstr[0] = flag;
2706 strcpy (newstr + 1, str);
2707
2708 newstr = (char *) ggc_alloc_string (newstr, len + 1);
2709 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
2710 }
2711
2712 /* Assigns default attributes to newly defined type. This is used to
2713 set short_call/long_call attributes for function types of
2714 functions defined inside corresponding #pragma scopes. */
2715 static void
2716 arm_set_default_type_attributes (tree type)
2717 {
2718 /* Add __attribute__ ((long_call)) to all functions, when
2719 inside #pragma long_calls or __attribute__ ((short_call)),
2720 when inside #pragma no_long_calls. */
2721 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
2722 {
2723 tree type_attr_list, attr_name;
2724 type_attr_list = TYPE_ATTRIBUTES (type);
2725
2726 if (arm_pragma_long_calls == LONG)
2727 attr_name = get_identifier ("long_call");
2728 else if (arm_pragma_long_calls == SHORT)
2729 attr_name = get_identifier ("short_call");
2730 else
2731 return;
2732
2733 type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list);
2734 TYPE_ATTRIBUTES (type) = type_attr_list;
2735 }
2736 }
2737 \f
2738 /* Return 1 if the operand is a SYMBOL_REF for a function known to be
2739 defined within the current compilation unit. If this cannot be
2740 determined, then 0 is returned. */
2741 static int
2742 current_file_function_operand (rtx sym_ref)
2743 {
2744 /* This is a bit of a fib. A function will have a short call flag
2745 applied to its name if it has the short call attribute, or it has
2746 already been defined within the current compilation unit. */
2747 if (ENCODED_SHORT_CALL_ATTR_P (XSTR (sym_ref, 0)))
2748 return 1;
2749
2750 /* The current function is always defined within the current compilation
2751 unit. if it s a weak definition however, then this may not be the real
2752 definition of the function, and so we have to say no. */
2753 if (sym_ref == XEXP (DECL_RTL (current_function_decl), 0)
2754 && !DECL_WEAK (current_function_decl))
2755 return 1;
2756
2757 /* We cannot make the determination - default to returning 0. */
2758 return 0;
2759 }
2760
2761 /* Return nonzero if a 32 bit "long_call" should be generated for
2762 this call. We generate a long_call if the function:
2763
2764 a. has an __attribute__((long call))
2765 or b. is within the scope of a #pragma long_calls
2766 or c. the -mlong-calls command line switch has been specified
2767
2768 However we do not generate a long call if the function:
2769
2770 d. has an __attribute__ ((short_call))
2771 or e. is inside the scope of a #pragma no_long_calls
2772 or f. has an __attribute__ ((section))
2773 or g. is defined within the current compilation unit.
2774
2775 This function will be called by C fragments contained in the machine
2776 description file. CALL_REF and CALL_COOKIE correspond to the matched
2777 rtl operands. CALL_SYMBOL is used to distinguish between
2778 two different callers of the function. It is set to 1 in the
2779 "call_symbol" and "call_symbol_value" patterns and to 0 in the "call"
2780 and "call_value" patterns. This is because of the difference in the
2781 SYM_REFs passed by these patterns. */
2782 int
2783 arm_is_longcall_p (rtx sym_ref, int call_cookie, int call_symbol)
2784 {
2785 if (!call_symbol)
2786 {
2787 if (GET_CODE (sym_ref) != MEM)
2788 return 0;
2789
2790 sym_ref = XEXP (sym_ref, 0);
2791 }
2792
2793 if (GET_CODE (sym_ref) != SYMBOL_REF)
2794 return 0;
2795
2796 if (call_cookie & CALL_SHORT)
2797 return 0;
2798
2799 if (TARGET_LONG_CALLS && flag_function_sections)
2800 return 1;
2801
2802 if (current_file_function_operand (sym_ref))
2803 return 0;
2804
2805 return (call_cookie & CALL_LONG)
2806 || ENCODED_LONG_CALL_ATTR_P (XSTR (sym_ref, 0))
2807 || TARGET_LONG_CALLS;
2808 }
2809
2810 /* Return nonzero if it is ok to make a tail-call to DECL. */
2811 static bool
2812 arm_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
2813 {
2814 int call_type = TARGET_LONG_CALLS ? CALL_LONG : CALL_NORMAL;
2815
2816 if (cfun->machine->sibcall_blocked)
2817 return false;
2818
2819 /* Never tailcall something for which we have no decl, or if we
2820 are in Thumb mode. */
2821 if (decl == NULL || TARGET_THUMB)
2822 return false;
2823
2824 /* Get the calling method. */
2825 if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
2826 call_type = CALL_SHORT;
2827 else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
2828 call_type = CALL_LONG;
2829
2830 /* Cannot tail-call to long calls, since these are out of range of
2831 a branch instruction. However, if not compiling PIC, we know
2832 we can reach the symbol if it is in this compilation unit. */
2833 if (call_type == CALL_LONG && (flag_pic || !TREE_ASM_WRITTEN (decl)))
2834 return false;
2835
2836 /* If we are interworking and the function is not declared static
2837 then we can't tail-call it unless we know that it exists in this
2838 compilation unit (since it might be a Thumb routine). */
2839 if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl))
2840 return false;
2841
2842 /* Never tailcall from an ISR routine - it needs a special exit sequence. */
2843 if (IS_INTERRUPT (arm_current_func_type ()))
2844 return false;
2845
2846 /* Everything else is ok. */
2847 return true;
2848 }
2849
2850 \f
2851 /* Addressing mode support functions. */
2852
2853 /* Return nonzero if X is a legitimate immediate operand when compiling
2854 for PIC. */
2855 int
2856 legitimate_pic_operand_p (rtx x)
2857 {
2858 if (CONSTANT_P (x)
2859 && flag_pic
2860 && (GET_CODE (x) == SYMBOL_REF
2861 || (GET_CODE (x) == CONST
2862 && GET_CODE (XEXP (x, 0)) == PLUS
2863 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)))
2864 return 0;
2865
2866 return 1;
2867 }
2868
2869 rtx
2870 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
2871 {
2872 if (GET_CODE (orig) == SYMBOL_REF
2873 || GET_CODE (orig) == LABEL_REF)
2874 {
2875 #ifndef AOF_ASSEMBLER
2876 rtx pic_ref, address;
2877 #endif
2878 rtx insn;
2879 int subregs = 0;
2880
2881 if (reg == 0)
2882 {
2883 if (no_new_pseudos)
2884 abort ();
2885 else
2886 reg = gen_reg_rtx (Pmode);
2887
2888 subregs = 1;
2889 }
2890
2891 #ifdef AOF_ASSEMBLER
2892 /* The AOF assembler can generate relocations for these directly, and
2893 understands that the PIC register has to be added into the offset. */
2894 insn = emit_insn (gen_pic_load_addr_based (reg, orig));
2895 #else
2896 if (subregs)
2897 address = gen_reg_rtx (Pmode);
2898 else
2899 address = reg;
2900
2901 if (TARGET_ARM)
2902 emit_insn (gen_pic_load_addr_arm (address, orig));
2903 else
2904 emit_insn (gen_pic_load_addr_thumb (address, orig));
2905
2906 if ((GET_CODE (orig) == LABEL_REF
2907 || (GET_CODE (orig) == SYMBOL_REF &&
2908 SYMBOL_REF_LOCAL_P (orig)))
2909 && NEED_GOT_RELOC)
2910 pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, address);
2911 else
2912 {
2913 pic_ref = gen_rtx_MEM (Pmode,
2914 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
2915 address));
2916 RTX_UNCHANGING_P (pic_ref) = 1;
2917 }
2918
2919 insn = emit_move_insn (reg, pic_ref);
2920 #endif
2921 current_function_uses_pic_offset_table = 1;
2922 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2923 by loop. */
2924 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
2925 REG_NOTES (insn));
2926 return reg;
2927 }
2928 else if (GET_CODE (orig) == CONST)
2929 {
2930 rtx base, offset;
2931
2932 if (GET_CODE (XEXP (orig, 0)) == PLUS
2933 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
2934 return orig;
2935
2936 if (reg == 0)
2937 {
2938 if (no_new_pseudos)
2939 abort ();
2940 else
2941 reg = gen_reg_rtx (Pmode);
2942 }
2943
2944 if (GET_CODE (XEXP (orig, 0)) == PLUS)
2945 {
2946 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
2947 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
2948 base == reg ? 0 : reg);
2949 }
2950 else
2951 abort ();
2952
2953 if (GET_CODE (offset) == CONST_INT)
2954 {
2955 /* The base register doesn't really matter, we only want to
2956 test the index for the appropriate mode. */
2957 if (!arm_legitimate_index_p (mode, offset, SET, 0))
2958 {
2959 if (!no_new_pseudos)
2960 offset = force_reg (Pmode, offset);
2961 else
2962 abort ();
2963 }
2964
2965 if (GET_CODE (offset) == CONST_INT)
2966 return plus_constant (base, INTVAL (offset));
2967 }
2968
2969 if (GET_MODE_SIZE (mode) > 4
2970 && (GET_MODE_CLASS (mode) == MODE_INT
2971 || TARGET_SOFT_FLOAT))
2972 {
2973 emit_insn (gen_addsi3 (reg, base, offset));
2974 return reg;
2975 }
2976
2977 return gen_rtx_PLUS (Pmode, base, offset);
2978 }
2979
2980 return orig;
2981 }
2982
2983 /* Generate code to load the PIC register. PROLOGUE is true if
2984 called from arm_expand_prologue (in which case we want the
2985 generated insns at the start of the function); false if called
2986 by an exception receiver that needs the PIC register reloaded
2987 (in which case the insns are just dumped at the current location). */
2988 void
2989 arm_finalize_pic (int prologue ATTRIBUTE_UNUSED)
2990 {
2991 #ifndef AOF_ASSEMBLER
2992 rtx l1, pic_tmp, pic_tmp2, seq, pic_rtx;
2993 rtx global_offset_table;
2994
2995 if (current_function_uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE)
2996 return;
2997
2998 if (!flag_pic)
2999 abort ();
3000
3001 start_sequence ();
3002 l1 = gen_label_rtx ();
3003
3004 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3005 /* On the ARM the PC register contains 'dot + 8' at the time of the
3006 addition, on the Thumb it is 'dot + 4'. */
3007 pic_tmp = plus_constant (gen_rtx_LABEL_REF (Pmode, l1), TARGET_ARM ? 8 : 4);
3008 if (GOT_PCREL)
3009 pic_tmp2 = gen_rtx_CONST (VOIDmode,
3010 gen_rtx_PLUS (Pmode, global_offset_table, pc_rtx));
3011 else
3012 pic_tmp2 = gen_rtx_CONST (VOIDmode, global_offset_table);
3013
3014 pic_rtx = gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, pic_tmp2, pic_tmp));
3015
3016 if (TARGET_ARM)
3017 {
3018 emit_insn (gen_pic_load_addr_arm (pic_offset_table_rtx, pic_rtx));
3019 emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx, l1));
3020 }
3021 else
3022 {
3023 emit_insn (gen_pic_load_addr_thumb (pic_offset_table_rtx, pic_rtx));
3024 emit_insn (gen_pic_add_dot_plus_four (pic_offset_table_rtx, l1));
3025 }
3026
3027 seq = get_insns ();
3028 end_sequence ();
3029 if (prologue)
3030 emit_insn_after (seq, get_insns ());
3031 else
3032 emit_insn (seq);
3033
3034 /* Need to emit this whether or not we obey regdecls,
3035 since setjmp/longjmp can cause life info to screw up. */
3036 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3037 #endif /* AOF_ASSEMBLER */
3038 }
3039
3040 /* Return nonzero if X is valid as an ARM state addressing register. */
3041 static int
3042 arm_address_register_rtx_p (rtx x, int strict_p)
3043 {
3044 int regno;
3045
3046 if (GET_CODE (x) != REG)
3047 return 0;
3048
3049 regno = REGNO (x);
3050
3051 if (strict_p)
3052 return ARM_REGNO_OK_FOR_BASE_P (regno);
3053
3054 return (regno <= LAST_ARM_REGNUM
3055 || regno >= FIRST_PSEUDO_REGISTER
3056 || regno == FRAME_POINTER_REGNUM
3057 || regno == ARG_POINTER_REGNUM);
3058 }
3059
3060 /* Return nonzero if X is a valid ARM state address operand. */
3061 int
3062 arm_legitimate_address_p (enum machine_mode mode, rtx x, RTX_CODE outer,
3063 int strict_p)
3064 {
3065 bool use_ldrd;
3066 enum rtx_code code = GET_CODE (x);
3067
3068 if (arm_address_register_rtx_p (x, strict_p))
3069 return 1;
3070
3071 use_ldrd = (TARGET_LDRD
3072 && (mode == DImode
3073 || (mode == DFmode && (TARGET_SOFT_FLOAT || TARGET_VFP))));
3074
3075 if (code == POST_INC || code == PRE_DEC
3076 || ((code == PRE_INC || code == POST_DEC)
3077 && (use_ldrd || GET_MODE_SIZE (mode) <= 4)))
3078 return arm_address_register_rtx_p (XEXP (x, 0), strict_p);
3079
3080 else if ((code == POST_MODIFY || code == PRE_MODIFY)
3081 && arm_address_register_rtx_p (XEXP (x, 0), strict_p)
3082 && GET_CODE (XEXP (x, 1)) == PLUS
3083 && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0)))
3084 {
3085 rtx addend = XEXP (XEXP (x, 1), 1);
3086
3087 /* Don't allow ldrd post increment by register becuase it's hard
3088 to fixup invalid register choices. */
3089 if (use_ldrd
3090 && GET_CODE (x) == POST_MODIFY
3091 && GET_CODE (addend) == REG)
3092 return 0;
3093
3094 return ((use_ldrd || GET_MODE_SIZE (mode) <= 4)
3095 && arm_legitimate_index_p (mode, addend, outer, strict_p));
3096 }
3097
3098 /* After reload constants split into minipools will have addresses
3099 from a LABEL_REF. */
3100 else if (reload_completed
3101 && (code == LABEL_REF
3102 || (code == CONST
3103 && GET_CODE (XEXP (x, 0)) == PLUS
3104 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3105 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
3106 return 1;
3107
3108 else if (mode == TImode)
3109 return 0;
3110
3111 else if (code == PLUS)
3112 {
3113 rtx xop0 = XEXP (x, 0);
3114 rtx xop1 = XEXP (x, 1);
3115
3116 return ((arm_address_register_rtx_p (xop0, strict_p)
3117 && arm_legitimate_index_p (mode, xop1, outer, strict_p))
3118 || (arm_address_register_rtx_p (xop1, strict_p)
3119 && arm_legitimate_index_p (mode, xop0, outer, strict_p)));
3120 }
3121
3122 #if 0
3123 /* Reload currently can't handle MINUS, so disable this for now */
3124 else if (GET_CODE (x) == MINUS)
3125 {
3126 rtx xop0 = XEXP (x, 0);
3127 rtx xop1 = XEXP (x, 1);
3128
3129 return (arm_address_register_rtx_p (xop0, strict_p)
3130 && arm_legitimate_index_p (mode, xop1, outer, strict_p));
3131 }
3132 #endif
3133
3134 else if (GET_MODE_CLASS (mode) != MODE_FLOAT
3135 && code == SYMBOL_REF
3136 && CONSTANT_POOL_ADDRESS_P (x)
3137 && ! (flag_pic
3138 && symbol_mentioned_p (get_pool_constant (x))))
3139 return 1;
3140
3141 return 0;
3142 }
3143
3144 /* Return nonzero if INDEX is valid for an address index operand in
3145 ARM state. */
3146 static int
3147 arm_legitimate_index_p (enum machine_mode mode, rtx index, RTX_CODE outer,
3148 int strict_p)
3149 {
3150 HOST_WIDE_INT range;
3151 enum rtx_code code = GET_CODE (index);
3152
3153 /* Standard coprocessor addressing modes. */
3154 if (TARGET_HARD_FLOAT
3155 && (TARGET_FPA || TARGET_MAVERICK)
3156 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3157 || (TARGET_MAVERICK && mode == DImode)))
3158 return (code == CONST_INT && INTVAL (index) < 1024
3159 && INTVAL (index) > -1024
3160 && (INTVAL (index) & 3) == 0);
3161
3162 if (TARGET_REALLY_IWMMXT && VALID_IWMMXT_REG_MODE (mode))
3163 return (code == CONST_INT
3164 && INTVAL (index) < 1024
3165 && INTVAL (index) > -1024
3166 && (INTVAL (index) & 3) == 0);
3167
3168 if (arm_address_register_rtx_p (index, strict_p)
3169 && (GET_MODE_SIZE (mode) <= 4))
3170 return 1;
3171
3172 if (mode == DImode || mode == DFmode)
3173 {
3174 if (code == CONST_INT)
3175 {
3176 HOST_WIDE_INT val = INTVAL (index);
3177
3178 if (TARGET_LDRD)
3179 return val > -256 && val < 256;
3180 else
3181 return val > -4096 && val < 4092;
3182 }
3183
3184 return TARGET_LDRD && arm_address_register_rtx_p (index, strict_p);
3185 }
3186
3187 if (GET_MODE_SIZE (mode) <= 4
3188 && ! (arm_arch4
3189 && (mode == HImode
3190 || (mode == QImode && outer == SIGN_EXTEND))))
3191 {
3192 if (code == MULT)
3193 {
3194 rtx xiop0 = XEXP (index, 0);
3195 rtx xiop1 = XEXP (index, 1);
3196
3197 return ((arm_address_register_rtx_p (xiop0, strict_p)
3198 && power_of_two_operand (xiop1, SImode))
3199 || (arm_address_register_rtx_p (xiop1, strict_p)
3200 && power_of_two_operand (xiop0, SImode)));
3201 }
3202 else if (code == LSHIFTRT || code == ASHIFTRT
3203 || code == ASHIFT || code == ROTATERT)
3204 {
3205 rtx op = XEXP (index, 1);
3206
3207 return (arm_address_register_rtx_p (XEXP (index, 0), strict_p)
3208 && GET_CODE (op) == CONST_INT
3209 && INTVAL (op) > 0
3210 && INTVAL (op) <= 31);
3211 }
3212 }
3213
3214 /* For ARM v4 we may be doing a sign-extend operation during the
3215 load. */
3216 if (arm_arch4)
3217 {
3218 if (mode == HImode || (outer == SIGN_EXTEND && mode == QImode))
3219 range = 256;
3220 else
3221 range = 4096;
3222 }
3223 else
3224 range = (mode == HImode) ? 4095 : 4096;
3225
3226 return (code == CONST_INT
3227 && INTVAL (index) < range
3228 && INTVAL (index) > -range);
3229 }
3230
3231 /* Return nonzero if X is valid as a Thumb state base register. */
3232 static int
3233 thumb_base_register_rtx_p (rtx x, enum machine_mode mode, int strict_p)
3234 {
3235 int regno;
3236
3237 if (GET_CODE (x) != REG)
3238 return 0;
3239
3240 regno = REGNO (x);
3241
3242 if (strict_p)
3243 return THUMB_REGNO_MODE_OK_FOR_BASE_P (regno, mode);
3244
3245 return (regno <= LAST_LO_REGNUM
3246 || regno > LAST_VIRTUAL_REGISTER
3247 || regno == FRAME_POINTER_REGNUM
3248 || (GET_MODE_SIZE (mode) >= 4
3249 && (regno == STACK_POINTER_REGNUM
3250 || regno >= FIRST_PSEUDO_REGISTER
3251 || x == hard_frame_pointer_rtx
3252 || x == arg_pointer_rtx)));
3253 }
3254
3255 /* Return nonzero if x is a legitimate index register. This is the case
3256 for any base register that can access a QImode object. */
3257 inline static int
3258 thumb_index_register_rtx_p (rtx x, int strict_p)
3259 {
3260 return thumb_base_register_rtx_p (x, QImode, strict_p);
3261 }
3262
3263 /* Return nonzero if x is a legitimate Thumb-state address.
3264
3265 The AP may be eliminated to either the SP or the FP, so we use the
3266 least common denominator, e.g. SImode, and offsets from 0 to 64.
3267
3268 ??? Verify whether the above is the right approach.
3269
3270 ??? Also, the FP may be eliminated to the SP, so perhaps that
3271 needs special handling also.
3272
3273 ??? Look at how the mips16 port solves this problem. It probably uses
3274 better ways to solve some of these problems.
3275
3276 Although it is not incorrect, we don't accept QImode and HImode
3277 addresses based on the frame pointer or arg pointer until the
3278 reload pass starts. This is so that eliminating such addresses
3279 into stack based ones won't produce impossible code. */
3280 int
3281 thumb_legitimate_address_p (enum machine_mode mode, rtx x, int strict_p)
3282 {
3283 /* ??? Not clear if this is right. Experiment. */
3284 if (GET_MODE_SIZE (mode) < 4
3285 && !(reload_in_progress || reload_completed)
3286 && (reg_mentioned_p (frame_pointer_rtx, x)
3287 || reg_mentioned_p (arg_pointer_rtx, x)
3288 || reg_mentioned_p (virtual_incoming_args_rtx, x)
3289 || reg_mentioned_p (virtual_outgoing_args_rtx, x)
3290 || reg_mentioned_p (virtual_stack_dynamic_rtx, x)
3291 || reg_mentioned_p (virtual_stack_vars_rtx, x)))
3292 return 0;
3293
3294 /* Accept any base register. SP only in SImode or larger. */
3295 else if (thumb_base_register_rtx_p (x, mode, strict_p))
3296 return 1;
3297
3298 /* This is PC relative data before arm_reorg runs. */
3299 else if (GET_MODE_SIZE (mode) >= 4 && CONSTANT_P (x)
3300 && GET_CODE (x) == SYMBOL_REF
3301 && CONSTANT_POOL_ADDRESS_P (x) && ! flag_pic)
3302 return 1;
3303
3304 /* This is PC relative data after arm_reorg runs. */
3305 else if (GET_MODE_SIZE (mode) >= 4 && reload_completed
3306 && (GET_CODE (x) == LABEL_REF
3307 || (GET_CODE (x) == CONST
3308 && GET_CODE (XEXP (x, 0)) == PLUS
3309 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3310 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
3311 return 1;
3312
3313 /* Post-inc indexing only supported for SImode and larger. */
3314 else if (GET_CODE (x) == POST_INC && GET_MODE_SIZE (mode) >= 4
3315 && thumb_index_register_rtx_p (XEXP (x, 0), strict_p))
3316 return 1;
3317
3318 else if (GET_CODE (x) == PLUS)
3319 {
3320 /* REG+REG address can be any two index registers. */
3321 /* We disallow FRAME+REG addressing since we know that FRAME
3322 will be replaced with STACK, and SP relative addressing only
3323 permits SP+OFFSET. */
3324 if (GET_MODE_SIZE (mode) <= 4
3325 && XEXP (x, 0) != frame_pointer_rtx
3326 && XEXP (x, 1) != frame_pointer_rtx
3327 && thumb_index_register_rtx_p (XEXP (x, 0), strict_p)
3328 && thumb_index_register_rtx_p (XEXP (x, 1), strict_p))
3329 return 1;
3330
3331 /* REG+const has 5-7 bit offset for non-SP registers. */
3332 else if ((thumb_index_register_rtx_p (XEXP (x, 0), strict_p)
3333 || XEXP (x, 0) == arg_pointer_rtx)
3334 && GET_CODE (XEXP (x, 1)) == CONST_INT
3335 && thumb_legitimate_offset_p (mode, INTVAL (XEXP (x, 1))))
3336 return 1;
3337
3338 /* REG+const has 10 bit offset for SP, but only SImode and
3339 larger is supported. */
3340 /* ??? Should probably check for DI/DFmode overflow here
3341 just like GO_IF_LEGITIMATE_OFFSET does. */
3342 else if (GET_CODE (XEXP (x, 0)) == REG
3343 && REGNO (XEXP (x, 0)) == STACK_POINTER_REGNUM
3344 && GET_MODE_SIZE (mode) >= 4
3345 && GET_CODE (XEXP (x, 1)) == CONST_INT
3346 && INTVAL (XEXP (x, 1)) >= 0
3347 && INTVAL (XEXP (x, 1)) + GET_MODE_SIZE (mode) <= 1024
3348 && (INTVAL (XEXP (x, 1)) & 3) == 0)
3349 return 1;
3350
3351 else if (GET_CODE (XEXP (x, 0)) == REG
3352 && REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM
3353 && GET_MODE_SIZE (mode) >= 4
3354 && GET_CODE (XEXP (x, 1)) == CONST_INT
3355 && (INTVAL (XEXP (x, 1)) & 3) == 0)
3356 return 1;
3357 }
3358
3359 else if (GET_MODE_CLASS (mode) != MODE_FLOAT
3360 && GET_MODE_SIZE (mode) == 4
3361 && GET_CODE (x) == SYMBOL_REF
3362 && CONSTANT_POOL_ADDRESS_P (x)
3363 && !(flag_pic
3364 && symbol_mentioned_p (get_pool_constant (x))))
3365 return 1;
3366
3367 return 0;
3368 }
3369
3370 /* Return nonzero if VAL can be used as an offset in a Thumb-state address
3371 instruction of mode MODE. */
3372 int
3373 thumb_legitimate_offset_p (enum machine_mode mode, HOST_WIDE_INT val)
3374 {
3375 switch (GET_MODE_SIZE (mode))
3376 {
3377 case 1:
3378 return val >= 0 && val < 32;
3379
3380 case 2:
3381 return val >= 0 && val < 64 && (val & 1) == 0;
3382
3383 default:
3384 return (val >= 0
3385 && (val + GET_MODE_SIZE (mode)) <= 128
3386 && (val & 3) == 0);
3387 }
3388 }
3389
3390 /* Try machine-dependent ways of modifying an illegitimate address
3391 to be legitimate. If we find one, return the new, valid address. */
3392 rtx
3393 arm_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
3394 {
3395 if (GET_CODE (x) == PLUS)
3396 {
3397 rtx xop0 = XEXP (x, 0);
3398 rtx xop1 = XEXP (x, 1);
3399
3400 if (CONSTANT_P (xop0) && !symbol_mentioned_p (xop0))
3401 xop0 = force_reg (SImode, xop0);
3402
3403 if (CONSTANT_P (xop1) && !symbol_mentioned_p (xop1))
3404 xop1 = force_reg (SImode, xop1);
3405
3406 if (ARM_BASE_REGISTER_RTX_P (xop0)
3407 && GET_CODE (xop1) == CONST_INT)
3408 {
3409 HOST_WIDE_INT n, low_n;
3410 rtx base_reg, val;
3411 n = INTVAL (xop1);
3412
3413 /* VFP addressing modes actually allow greater offsets, but for
3414 now we just stick with the lowest common denominator. */
3415 if (mode == DImode
3416 || ((TARGET_SOFT_FLOAT || TARGET_VFP) && mode == DFmode))
3417 {
3418 low_n = n & 0x0f;
3419 n &= ~0x0f;
3420 if (low_n > 4)
3421 {
3422 n += 16;
3423 low_n -= 16;
3424 }
3425 }
3426 else
3427 {
3428 low_n = ((mode) == TImode ? 0
3429 : n >= 0 ? (n & 0xfff) : -((-n) & 0xfff));
3430 n -= low_n;
3431 }
3432
3433 base_reg = gen_reg_rtx (SImode);
3434 val = force_operand (gen_rtx_PLUS (SImode, xop0,
3435 GEN_INT (n)), NULL_RTX);
3436 emit_move_insn (base_reg, val);
3437 x = (low_n == 0 ? base_reg
3438 : gen_rtx_PLUS (SImode, base_reg, GEN_INT (low_n)));
3439 }
3440 else if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1))
3441 x = gen_rtx_PLUS (SImode, xop0, xop1);
3442 }
3443
3444 /* XXX We don't allow MINUS any more -- see comment in
3445 arm_legitimate_address_p (). */
3446 else if (GET_CODE (x) == MINUS)
3447 {
3448 rtx xop0 = XEXP (x, 0);
3449 rtx xop1 = XEXP (x, 1);
3450
3451 if (CONSTANT_P (xop0))
3452 xop0 = force_reg (SImode, xop0);
3453
3454 if (CONSTANT_P (xop1) && ! symbol_mentioned_p (xop1))
3455 xop1 = force_reg (SImode, xop1);
3456
3457 if (xop0 != XEXP (x, 0) || xop1 != XEXP (x, 1))
3458 x = gen_rtx_MINUS (SImode, xop0, xop1);
3459 }
3460
3461 if (flag_pic)
3462 {
3463 /* We need to find and carefully transform any SYMBOL and LABEL
3464 references; so go back to the original address expression. */
3465 rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX);
3466
3467 if (new_x != orig_x)
3468 x = new_x;
3469 }
3470
3471 return x;
3472 }
3473
3474
3475 /* Try machine-dependent ways of modifying an illegitimate Thumb address
3476 to be legitimate. If we find one, return the new, valid address. */
3477 rtx
3478 thumb_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
3479 {
3480 if (GET_CODE (x) == PLUS
3481 && GET_CODE (XEXP (x, 1)) == CONST_INT
3482 && (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode)
3483 || INTVAL (XEXP (x, 1)) < 0))
3484 {
3485 rtx xop0 = XEXP (x, 0);
3486 rtx xop1 = XEXP (x, 1);
3487 HOST_WIDE_INT offset = INTVAL (xop1);
3488
3489 /* Try and fold the offset into a biasing of the base register and
3490 then offsetting that. Don't do this when optimizing for space
3491 since it can cause too many CSEs. */
3492 if (optimize_size && offset >= 0
3493 && offset < 256 + 31 * GET_MODE_SIZE (mode))
3494 {
3495 HOST_WIDE_INT delta;
3496
3497 if (offset >= 256)
3498 delta = offset - (256 - GET_MODE_SIZE (mode));
3499 else if (offset < 32 * GET_MODE_SIZE (mode) + 8)
3500 delta = 31 * GET_MODE_SIZE (mode);
3501 else
3502 delta = offset & (~31 * GET_MODE_SIZE (mode));
3503
3504 xop0 = force_operand (plus_constant (xop0, offset - delta),
3505 NULL_RTX);
3506 x = plus_constant (xop0, delta);
3507 }
3508 else if (offset < 0 && offset > -256)
3509 /* Small negative offsets are best done with a subtract before the
3510 dereference, forcing these into a register normally takes two
3511 instructions. */
3512 x = force_operand (x, NULL_RTX);
3513 else
3514 {
3515 /* For the remaining cases, force the constant into a register. */
3516 xop1 = force_reg (SImode, xop1);
3517 x = gen_rtx_PLUS (SImode, xop0, xop1);
3518 }
3519 }
3520 else if (GET_CODE (x) == PLUS
3521 && s_register_operand (XEXP (x, 1), SImode)
3522 && !s_register_operand (XEXP (x, 0), SImode))
3523 {
3524 rtx xop0 = force_operand (XEXP (x, 0), NULL_RTX);
3525
3526 x = gen_rtx_PLUS (SImode, xop0, XEXP (x, 1));
3527 }
3528
3529 if (flag_pic)
3530 {
3531 /* We need to find and carefully transform any SYMBOL and LABEL
3532 references; so go back to the original address expression. */
3533 rtx new_x = legitimize_pic_address (orig_x, mode, NULL_RTX);
3534
3535 if (new_x != orig_x)
3536 x = new_x;
3537 }
3538
3539 return x;
3540 }
3541
3542 \f
3543
3544 #define REG_OR_SUBREG_REG(X) \
3545 (GET_CODE (X) == REG \
3546 || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
3547
3548 #define REG_OR_SUBREG_RTX(X) \
3549 (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
3550
3551 #ifndef COSTS_N_INSNS
3552 #define COSTS_N_INSNS(N) ((N) * 4 - 2)
3553 #endif
3554 static inline int
3555 thumb_rtx_costs (rtx x, enum rtx_code code, enum rtx_code outer)
3556 {
3557 enum machine_mode mode = GET_MODE (x);
3558
3559 switch (code)
3560 {
3561 case ASHIFT:
3562 case ASHIFTRT:
3563 case LSHIFTRT:
3564 case ROTATERT:
3565 case PLUS:
3566 case MINUS:
3567 case COMPARE:
3568 case NEG:
3569 case NOT:
3570 return COSTS_N_INSNS (1);
3571
3572 case MULT:
3573 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3574 {
3575 int cycles = 0;
3576 unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1));
3577
3578 while (i)
3579 {
3580 i >>= 2;
3581 cycles++;
3582 }
3583 return COSTS_N_INSNS (2) + cycles;
3584 }
3585 return COSTS_N_INSNS (1) + 16;
3586
3587 case SET:
3588 return (COSTS_N_INSNS (1)
3589 + 4 * ((GET_CODE (SET_SRC (x)) == MEM)
3590 + GET_CODE (SET_DEST (x)) == MEM));
3591
3592 case CONST_INT:
3593 if (outer == SET)
3594 {
3595 if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256)
3596 return 0;
3597 if (thumb_shiftable_const (INTVAL (x)))
3598 return COSTS_N_INSNS (2);
3599 return COSTS_N_INSNS (3);
3600 }
3601 else if ((outer == PLUS || outer == COMPARE)
3602 && INTVAL (x) < 256 && INTVAL (x) > -256)
3603 return 0;
3604 else if (outer == AND
3605 && INTVAL (x) < 256 && INTVAL (x) >= -256)
3606 return COSTS_N_INSNS (1);
3607 else if (outer == ASHIFT || outer == ASHIFTRT
3608 || outer == LSHIFTRT)
3609 return 0;
3610 return COSTS_N_INSNS (2);
3611
3612 case CONST:
3613 case CONST_DOUBLE:
3614 case LABEL_REF:
3615 case SYMBOL_REF:
3616 return COSTS_N_INSNS (3);
3617
3618 case UDIV:
3619 case UMOD:
3620 case DIV:
3621 case MOD:
3622 return 100;
3623
3624 case TRUNCATE:
3625 return 99;
3626
3627 case AND:
3628 case XOR:
3629 case IOR:
3630 /* XXX guess. */
3631 return 8;
3632
3633 case MEM:
3634 /* XXX another guess. */
3635 /* Memory costs quite a lot for the first word, but subsequent words
3636 load at the equivalent of a single insn each. */
3637 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
3638 + ((GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
3639 ? 4 : 0));
3640
3641 case IF_THEN_ELSE:
3642 /* XXX a guess. */
3643 if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
3644 return 14;
3645 return 2;
3646
3647 case ZERO_EXTEND:
3648 /* XXX still guessing. */
3649 switch (GET_MODE (XEXP (x, 0)))
3650 {
3651 case QImode:
3652 return (1 + (mode == DImode ? 4 : 0)
3653 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3654
3655 case HImode:
3656 return (4 + (mode == DImode ? 4 : 0)
3657 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3658
3659 case SImode:
3660 return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3661
3662 default:
3663 return 99;
3664 }
3665
3666 default:
3667 return 99;
3668 }
3669 }
3670
3671
3672 /* Worker routine for arm_rtx_costs. */
3673 static inline int
3674 arm_rtx_costs_1 (rtx x, enum rtx_code code, enum rtx_code outer)
3675 {
3676 enum machine_mode mode = GET_MODE (x);
3677 enum rtx_code subcode;
3678 int extra_cost;
3679
3680 switch (code)
3681 {
3682 case MEM:
3683 /* Memory costs quite a lot for the first word, but subsequent words
3684 load at the equivalent of a single insn each. */
3685 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
3686 + (GET_CODE (x) == SYMBOL_REF
3687 && CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
3688
3689 case DIV:
3690 case MOD:
3691 case UDIV:
3692 case UMOD:
3693 return optimize_size ? COSTS_N_INSNS (2) : 100;
3694
3695 case ROTATE:
3696 if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG)
3697 return 4;
3698 /* Fall through */
3699 case ROTATERT:
3700 if (mode != SImode)
3701 return 8;
3702 /* Fall through */
3703 case ASHIFT: case LSHIFTRT: case ASHIFTRT:
3704 if (mode == DImode)
3705 return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8)
3706 + ((GET_CODE (XEXP (x, 0)) == REG
3707 || (GET_CODE (XEXP (x, 0)) == SUBREG
3708 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
3709 ? 0 : 8));
3710 return (1 + ((GET_CODE (XEXP (x, 0)) == REG
3711 || (GET_CODE (XEXP (x, 0)) == SUBREG
3712 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
3713 ? 0 : 4)
3714 + ((GET_CODE (XEXP (x, 1)) == REG
3715 || (GET_CODE (XEXP (x, 1)) == SUBREG
3716 && GET_CODE (SUBREG_REG (XEXP (x, 1))) == REG)
3717 || (GET_CODE (XEXP (x, 1)) == CONST_INT))
3718 ? 0 : 4));
3719
3720 case MINUS:
3721 if (mode == DImode)
3722 return (4 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 8)
3723 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
3724 || (GET_CODE (XEXP (x, 0)) == CONST_INT
3725 && const_ok_for_arm (INTVAL (XEXP (x, 0)))))
3726 ? 0 : 8));
3727
3728 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
3729 return (2 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
3730 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
3731 && arm_const_double_rtx (XEXP (x, 1))))
3732 ? 0 : 8)
3733 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
3734 || (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE
3735 && arm_const_double_rtx (XEXP (x, 0))))
3736 ? 0 : 8));
3737
3738 if (((GET_CODE (XEXP (x, 0)) == CONST_INT
3739 && const_ok_for_arm (INTVAL (XEXP (x, 0)))
3740 && REG_OR_SUBREG_REG (XEXP (x, 1))))
3741 || (((subcode = GET_CODE (XEXP (x, 1))) == ASHIFT
3742 || subcode == ASHIFTRT || subcode == LSHIFTRT
3743 || subcode == ROTATE || subcode == ROTATERT
3744 || (subcode == MULT
3745 && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
3746 && ((INTVAL (XEXP (XEXP (x, 1), 1)) &
3747 (INTVAL (XEXP (XEXP (x, 1), 1)) - 1)) == 0)))
3748 && REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 0))
3749 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 1))
3750 || GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT)
3751 && REG_OR_SUBREG_REG (XEXP (x, 0))))
3752 return 1;
3753 /* Fall through */
3754
3755 case PLUS:
3756 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
3757 return (2 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
3758 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
3759 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
3760 && arm_const_double_rtx (XEXP (x, 1))))
3761 ? 0 : 8));
3762
3763 /* Fall through */
3764 case AND: case XOR: case IOR:
3765 extra_cost = 0;
3766
3767 /* Normally the frame registers will be spilt into reg+const during
3768 reload, so it is a bad idea to combine them with other instructions,
3769 since then they might not be moved outside of loops. As a compromise
3770 we allow integration with ops that have a constant as their second
3771 operand. */
3772 if ((REG_OR_SUBREG_REG (XEXP (x, 0))
3773 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))
3774 && GET_CODE (XEXP (x, 1)) != CONST_INT)
3775 || (REG_OR_SUBREG_REG (XEXP (x, 0))
3776 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))))
3777 extra_cost = 4;
3778
3779 if (mode == DImode)
3780 return (4 + extra_cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
3781 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
3782 || (GET_CODE (XEXP (x, 1)) == CONST_INT
3783 && const_ok_for_op (INTVAL (XEXP (x, 1)), code)))
3784 ? 0 : 8));
3785
3786 if (REG_OR_SUBREG_REG (XEXP (x, 0)))
3787 return (1 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : extra_cost)
3788 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
3789 || (GET_CODE (XEXP (x, 1)) == CONST_INT
3790 && const_ok_for_op (INTVAL (XEXP (x, 1)), code)))
3791 ? 0 : 4));
3792
3793 else if (REG_OR_SUBREG_REG (XEXP (x, 1)))
3794 return (1 + extra_cost
3795 + ((((subcode = GET_CODE (XEXP (x, 0))) == ASHIFT
3796 || subcode == LSHIFTRT || subcode == ASHIFTRT
3797 || subcode == ROTATE || subcode == ROTATERT
3798 || (subcode == MULT
3799 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3800 && ((INTVAL (XEXP (XEXP (x, 0), 1)) &
3801 (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0)))
3802 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 0)))
3803 && ((REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 1)))
3804 || GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
3805 ? 0 : 4));
3806
3807 return 8;
3808
3809 case MULT:
3810 /* This should have been handled by the CPU specific routines. */
3811 abort ();
3812
3813 case TRUNCATE:
3814 if (arm_arch3m && mode == SImode
3815 && GET_CODE (XEXP (x, 0)) == LSHIFTRT
3816 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
3817 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
3818 == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)))
3819 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
3820 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND))
3821 return 8;
3822 return 99;
3823
3824 case NEG:
3825 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
3826 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 6);
3827 /* Fall through */
3828 case NOT:
3829 if (mode == DImode)
3830 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
3831
3832 return 1 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
3833
3834 case IF_THEN_ELSE:
3835 if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
3836 return 14;
3837 return 2;
3838
3839 case COMPARE:
3840 return 1;
3841
3842 case ABS:
3843 return 4 + (mode == DImode ? 4 : 0);
3844
3845 case SIGN_EXTEND:
3846 if (GET_MODE (XEXP (x, 0)) == QImode)
3847 return (4 + (mode == DImode ? 4 : 0)
3848 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3849 /* Fall through */
3850 case ZERO_EXTEND:
3851 switch (GET_MODE (XEXP (x, 0)))
3852 {
3853 case QImode:
3854 return (1 + (mode == DImode ? 4 : 0)
3855 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3856
3857 case HImode:
3858 return (4 + (mode == DImode ? 4 : 0)
3859 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3860
3861 case SImode:
3862 return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
3863
3864 case V8QImode:
3865 case V4HImode:
3866 case V2SImode:
3867 case V4QImode:
3868 case V2HImode:
3869 return 1;
3870
3871 default:
3872 break;
3873 }
3874 abort ();
3875
3876 case CONST_INT:
3877 if (const_ok_for_arm (INTVAL (x)))
3878 return outer == SET ? 2 : -1;
3879 else if (outer == AND
3880 && const_ok_for_arm (~INTVAL (x)))
3881 return -1;
3882 else if ((outer == COMPARE
3883 || outer == PLUS || outer == MINUS)
3884 && const_ok_for_arm (-INTVAL (x)))
3885 return -1;
3886 else
3887 return 5;
3888
3889 case CONST:
3890 case LABEL_REF:
3891 case SYMBOL_REF:
3892 return 6;
3893
3894 case CONST_DOUBLE:
3895 if (arm_const_double_rtx (x))
3896 return outer == SET ? 2 : -1;
3897 else if ((outer == COMPARE || outer == PLUS)
3898 && neg_const_double_rtx_ok_for_fpa (x))
3899 return -1;
3900 return 7;
3901
3902 default:
3903 return 99;
3904 }
3905 }
3906
3907 /* RTX costs for cores with a slow MUL implementation. */
3908
3909 static bool
3910 arm_slowmul_rtx_costs (rtx x, int code, int outer_code, int *total)
3911 {
3912 enum machine_mode mode = GET_MODE (x);
3913
3914 if (TARGET_THUMB)
3915 {
3916 *total = thumb_rtx_costs (x, code, outer_code);
3917 return true;
3918 }
3919
3920 switch (code)
3921 {
3922 case MULT:
3923 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3924 || mode == DImode)
3925 {
3926 *total = 30;
3927 return true;
3928 }
3929
3930 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3931 {
3932 unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1))
3933 & (unsigned HOST_WIDE_INT) 0xffffffff);
3934 int cost, const_ok = const_ok_for_arm (i);
3935 int j, booth_unit_size;
3936
3937 /* Tune as appropriate. */
3938 cost = const_ok ? 4 : 8;
3939 booth_unit_size = 2;
3940 for (j = 0; i && j < 32; j += booth_unit_size)
3941 {
3942 i >>= booth_unit_size;
3943 cost += 2;
3944 }
3945
3946 *total = cost;
3947 return true;
3948 }
3949
3950 *total = 30 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
3951 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4);
3952 return true;
3953
3954 default:
3955 *total = arm_rtx_costs_1 (x, code, outer_code);
3956 return true;
3957 }
3958 }
3959
3960
3961 /* RTX cost for cores with a fast multiply unit (M variants). */
3962
3963 static bool
3964 arm_fastmul_rtx_costs (rtx x, int code, int outer_code, int *total)
3965 {
3966 enum machine_mode mode = GET_MODE (x);
3967
3968 if (TARGET_THUMB)
3969 {
3970 *total = thumb_rtx_costs (x, code, outer_code);
3971 return true;
3972 }
3973
3974 switch (code)
3975 {
3976 case MULT:
3977 /* There is no point basing this on the tuning, since it is always the
3978 fast variant if it exists at all. */
3979 if (mode == DImode
3980 && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1)))
3981 && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
3982 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND))
3983 {
3984 *total = 8;
3985 return true;
3986 }
3987
3988
3989 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3990 || mode == DImode)
3991 {
3992 *total = 30;
3993 return true;
3994 }
3995
3996 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3997 {
3998 unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1))
3999 & (unsigned HOST_WIDE_INT) 0xffffffff);
4000 int cost, const_ok = const_ok_for_arm (i);
4001 int j, booth_unit_size;
4002
4003 /* Tune as appropriate. */
4004 cost = const_ok ? 4 : 8;
4005 booth_unit_size = 8;
4006 for (j = 0; i && j < 32; j += booth_unit_size)
4007 {
4008 i >>= booth_unit_size;
4009 cost += 2;
4010 }
4011
4012 *total = cost;
4013 return true;
4014 }
4015
4016 *total = 8 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
4017 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4);
4018 return true;
4019
4020 default:
4021 *total = arm_rtx_costs_1 (x, code, outer_code);
4022 return true;
4023 }
4024 }
4025
4026
4027 /* RTX cost for XScale CPUs. */
4028
4029 static bool
4030 arm_xscale_rtx_costs (rtx x, int code, int outer_code, int *total)
4031 {
4032 enum machine_mode mode = GET_MODE (x);
4033
4034 if (TARGET_THUMB)
4035 {
4036 *total = thumb_rtx_costs (x, code, outer_code);
4037 return true;
4038 }
4039
4040 switch (code)
4041 {
4042 case MULT:
4043 /* There is no point basing this on the tuning, since it is always the
4044 fast variant if it exists at all. */
4045 if (mode == DImode
4046 && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1)))
4047 && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
4048 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND))
4049 {
4050 *total = 8;
4051 return true;
4052 }
4053
4054
4055 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4056 || mode == DImode)
4057 {
4058 *total = 30;
4059 return true;
4060 }
4061
4062 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
4063 {
4064 unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1))
4065 & (unsigned HOST_WIDE_INT) 0xffffffff);
4066 int cost, const_ok = const_ok_for_arm (i);
4067 unsigned HOST_WIDE_INT masked_const;
4068
4069 /* The cost will be related to two insns.
4070 First a load of the constant (MOV or LDR), then a multiply. */
4071 cost = 2;
4072 if (! const_ok)
4073 cost += 1; /* LDR is probably more expensive because
4074 of longer result latency. */
4075 masked_const = i & 0xffff8000;
4076 if (masked_const != 0 && masked_const != 0xffff8000)
4077 {
4078 masked_const = i & 0xf8000000;
4079 if (masked_const == 0 || masked_const == 0xf8000000)
4080 cost += 1;
4081 else
4082 cost += 2;
4083 }
4084 *total = cost;
4085 return true;
4086 }
4087
4088 *total = 8 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
4089 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4);
4090 return true;
4091
4092 default:
4093 *total = arm_rtx_costs_1 (x, code, outer_code);
4094 return true;
4095 }
4096 }
4097
4098
4099 /* RTX costs for 9e (and later) cores. */
4100
4101 static bool
4102 arm_9e_rtx_costs (rtx x, int code, int outer_code, int *total)
4103 {
4104 enum machine_mode mode = GET_MODE (x);
4105 int nonreg_cost;
4106 int cost;
4107
4108 if (TARGET_THUMB)
4109 {
4110 switch (code)
4111 {
4112 case MULT:
4113 *total = COSTS_N_INSNS (3);
4114 return true;
4115
4116 default:
4117 *total = thumb_rtx_costs (x, code, outer_code);
4118 return true;
4119 }
4120 }
4121
4122 switch (code)
4123 {
4124 case MULT:
4125 /* There is no point basing this on the tuning, since it is always the
4126 fast variant if it exists at all. */
4127 if (mode == DImode
4128 && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1)))
4129 && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
4130 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND))
4131 {
4132 *total = 3;
4133 return true;
4134 }
4135
4136
4137 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
4138 {
4139 *total = 30;
4140 return true;
4141 }
4142 if (mode == DImode)
4143 {
4144 cost = 7;
4145 nonreg_cost = 8;
4146 }
4147 else
4148 {
4149 cost = 2;
4150 nonreg_cost = 4;
4151 }
4152
4153
4154 *total = cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : nonreg_cost)
4155 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : nonreg_cost);
4156 return true;
4157
4158 default:
4159 *total = arm_rtx_costs_1 (x, code, outer_code);
4160 return true;
4161 }
4162 }
4163 /* All address computations that can be done are free, but rtx cost returns
4164 the same for practically all of them. So we weight the different types
4165 of address here in the order (most pref first):
4166 PRE/POST_INC/DEC, SHIFT or NON-INT sum, INT sum, REG, MEM or LABEL. */
4167 static inline int
4168 arm_arm_address_cost (rtx x)
4169 {
4170 enum rtx_code c = GET_CODE (x);
4171
4172 if (c == PRE_INC || c == PRE_DEC || c == POST_INC || c == POST_DEC)
4173 return 0;
4174 if (c == MEM || c == LABEL_REF || c == SYMBOL_REF)
4175 return 10;
4176
4177 if (c == PLUS || c == MINUS)
4178 {
4179 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
4180 return 2;
4181
4182 if (ARITHMETIC_P (XEXP (x, 0)) || ARITHMETIC_P (XEXP (x, 1)))
4183 return 3;
4184
4185 return 4;
4186 }
4187
4188 return 6;
4189 }
4190
4191 static inline int
4192 arm_thumb_address_cost (rtx x)
4193 {
4194 enum rtx_code c = GET_CODE (x);
4195
4196 if (c == REG)
4197 return 1;
4198 if (c == PLUS
4199 && GET_CODE (XEXP (x, 0)) == REG
4200 && GET_CODE (XEXP (x, 1)) == CONST_INT)
4201 return 1;
4202
4203 return 2;
4204 }
4205
4206 static int
4207 arm_address_cost (rtx x)
4208 {
4209 return TARGET_ARM ? arm_arm_address_cost (x) : arm_thumb_address_cost (x);
4210 }
4211
4212 static int
4213 arm_adjust_cost (rtx insn, rtx link, rtx dep, int cost)
4214 {
4215 rtx i_pat, d_pat;
4216
4217 /* Some true dependencies can have a higher cost depending
4218 on precisely how certain input operands are used. */
4219 if (arm_tune_xscale
4220 && REG_NOTE_KIND (link) == 0
4221 && recog_memoized (insn) >= 0
4222 && recog_memoized (dep) >= 0)
4223 {
4224 int shift_opnum = get_attr_shift (insn);
4225 enum attr_type attr_type = get_attr_type (dep);
4226
4227 /* If nonzero, SHIFT_OPNUM contains the operand number of a shifted
4228 operand for INSN. If we have a shifted input operand and the
4229 instruction we depend on is another ALU instruction, then we may
4230 have to account for an additional stall. */
4231 if (shift_opnum != 0
4232 && (attr_type == TYPE_ALU_SHIFT || attr_type == TYPE_ALU_SHIFT_REG))
4233 {
4234 rtx shifted_operand;
4235 int opno;
4236
4237 /* Get the shifted operand. */
4238 extract_insn (insn);
4239 shifted_operand = recog_data.operand[shift_opnum];
4240
4241 /* Iterate over all the operands in DEP. If we write an operand
4242 that overlaps with SHIFTED_OPERAND, then we have increase the
4243 cost of this dependency. */
4244 extract_insn (dep);
4245 preprocess_constraints ();
4246 for (opno = 0; opno < recog_data.n_operands; opno++)
4247 {
4248 /* We can ignore strict inputs. */
4249 if (recog_data.operand_type[opno] == OP_IN)
4250 continue;
4251
4252 if (reg_overlap_mentioned_p (recog_data.operand[opno],
4253 shifted_operand))
4254 return 2;
4255 }
4256 }
4257 }
4258
4259 /* XXX This is not strictly true for the FPA. */
4260 if (REG_NOTE_KIND (link) == REG_DEP_ANTI
4261 || REG_NOTE_KIND (link) == REG_DEP_OUTPUT)
4262 return 0;
4263
4264 /* Call insns don't incur a stall, even if they follow a load. */
4265 if (REG_NOTE_KIND (link) == 0
4266 && GET_CODE (insn) == CALL_INSN)
4267 return 1;
4268
4269 if ((i_pat = single_set (insn)) != NULL
4270 && GET_CODE (SET_SRC (i_pat)) == MEM
4271 && (d_pat = single_set (dep)) != NULL
4272 && GET_CODE (SET_DEST (d_pat)) == MEM)
4273 {
4274 rtx src_mem = XEXP (SET_SRC (i_pat), 0);
4275 /* This is a load after a store, there is no conflict if the load reads
4276 from a cached area. Assume that loads from the stack, and from the
4277 constant pool are cached, and that others will miss. This is a
4278 hack. */
4279
4280 if ((GET_CODE (src_mem) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (src_mem))
4281 || reg_mentioned_p (stack_pointer_rtx, src_mem)
4282 || reg_mentioned_p (frame_pointer_rtx, src_mem)
4283 || reg_mentioned_p (hard_frame_pointer_rtx, src_mem))
4284 return 1;
4285 }
4286
4287 return cost;
4288 }
4289
4290 static int fp_consts_inited = 0;
4291
4292 /* Only zero is valid for VFP. Other values are also valid for FPA. */
4293 static const char * const strings_fp[8] =
4294 {
4295 "0", "1", "2", "3",
4296 "4", "5", "0.5", "10"
4297 };
4298
4299 static REAL_VALUE_TYPE values_fp[8];
4300
4301 static void
4302 init_fp_table (void)
4303 {
4304 int i;
4305 REAL_VALUE_TYPE r;
4306
4307 if (TARGET_VFP)
4308 fp_consts_inited = 1;
4309 else
4310 fp_consts_inited = 8;
4311
4312 for (i = 0; i < fp_consts_inited; i++)
4313 {
4314 r = REAL_VALUE_ATOF (strings_fp[i], DFmode);
4315 values_fp[i] = r;
4316 }
4317 }
4318
4319 /* Return TRUE if rtx X is a valid immediate FP constant. */
4320 int
4321 arm_const_double_rtx (rtx x)
4322 {
4323 REAL_VALUE_TYPE r;
4324 int i;
4325
4326 if (!fp_consts_inited)
4327 init_fp_table ();
4328
4329 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
4330 if (REAL_VALUE_MINUS_ZERO (r))
4331 return 0;
4332
4333 for (i = 0; i < fp_consts_inited; i++)
4334 if (REAL_VALUES_EQUAL (r, values_fp[i]))
4335 return 1;
4336
4337 return 0;
4338 }
4339
4340 /* Return TRUE if rtx X is a valid immediate FPA constant. */
4341 int
4342 neg_const_double_rtx_ok_for_fpa (rtx x)
4343 {
4344 REAL_VALUE_TYPE r;
4345 int i;
4346
4347 if (!fp_consts_inited)
4348 init_fp_table ();
4349
4350 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
4351 r = REAL_VALUE_NEGATE (r);
4352 if (REAL_VALUE_MINUS_ZERO (r))
4353 return 0;
4354
4355 for (i = 0; i < 8; i++)
4356 if (REAL_VALUES_EQUAL (r, values_fp[i]))
4357 return 1;
4358
4359 return 0;
4360 }
4361 \f
4362 /* Predicates for `match_operand' and `match_operator'. */
4363
4364 /* s_register_operand is the same as register_operand, but it doesn't accept
4365 (SUBREG (MEM)...).
4366
4367 This function exists because at the time it was put in it led to better
4368 code. SUBREG(MEM) always needs a reload in the places where
4369 s_register_operand is used, and this seemed to lead to excessive
4370 reloading. */
4371 int
4372 s_register_operand (rtx op, enum machine_mode mode)
4373 {
4374 if (GET_MODE (op) != mode && mode != VOIDmode)
4375 return 0;
4376
4377 if (GET_CODE (op) == SUBREG)
4378 op = SUBREG_REG (op);
4379
4380 /* We don't consider registers whose class is NO_REGS
4381 to be a register operand. */
4382 /* XXX might have to check for lo regs only for thumb ??? */
4383 return (GET_CODE (op) == REG
4384 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
4385 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
4386 }
4387
4388 /* A hard register operand (even before reload. */
4389 int
4390 arm_hard_register_operand (rtx op, enum machine_mode mode)
4391 {
4392 if (GET_MODE (op) != mode && mode != VOIDmode)
4393 return 0;
4394
4395 return (GET_CODE (op) == REG
4396 && REGNO (op) < FIRST_PSEUDO_REGISTER);
4397 }
4398
4399 /* An arm register operand. */
4400 int
4401 arm_general_register_operand (rtx op, enum machine_mode mode)
4402 {
4403 if (GET_MODE (op) != mode && mode != VOIDmode)
4404 return 0;
4405
4406 if (GET_CODE (op) == SUBREG)
4407 op = SUBREG_REG (op);
4408
4409 return (GET_CODE (op) == REG
4410 && (REGNO (op) <= LAST_ARM_REGNUM
4411 || REGNO (op) >= FIRST_PSEUDO_REGISTER));
4412 }
4413
4414 /* Only accept reg, subreg(reg), const_int. */
4415 int
4416 reg_or_int_operand (rtx op, enum machine_mode mode)
4417 {
4418 if (GET_CODE (op) == CONST_INT)
4419 return 1;
4420
4421 if (GET_MODE (op) != mode && mode != VOIDmode)
4422 return 0;
4423
4424 if (GET_CODE (op) == SUBREG)
4425 op = SUBREG_REG (op);
4426
4427 /* We don't consider registers whose class is NO_REGS
4428 to be a register operand. */
4429 return (GET_CODE (op) == REG
4430 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
4431 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
4432 }
4433
4434 /* Return 1 if OP is an item in memory, given that we are in reload. */
4435 int
4436 arm_reload_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
4437 {
4438 int regno = true_regnum (op);
4439
4440 return (!CONSTANT_P (op)
4441 && (regno == -1
4442 || (GET_CODE (op) == REG
4443 && REGNO (op) >= FIRST_PSEUDO_REGISTER)));
4444 }
4445
4446 /* Return TRUE for valid operands for the rhs of an ARM instruction. */
4447 int
4448 arm_rhs_operand (rtx op, enum machine_mode mode)
4449 {
4450 return (s_register_operand (op, mode)
4451 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op))));
4452 }
4453
4454 /* Return TRUE for valid operands for the
4455 rhs of an ARM instruction, or a load. */
4456 int
4457 arm_rhsm_operand (rtx op, enum machine_mode mode)
4458 {
4459 return (s_register_operand (op, mode)
4460 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op)))
4461 || memory_operand (op, mode));
4462 }
4463
4464 /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a
4465 constant that is valid when negated. */
4466 int
4467 arm_add_operand (rtx op, enum machine_mode mode)
4468 {
4469 if (TARGET_THUMB)
4470 return thumb_cmp_operand (op, mode);
4471
4472 return (s_register_operand (op, mode)
4473 || (GET_CODE (op) == CONST_INT
4474 && (const_ok_for_arm (INTVAL (op))
4475 || const_ok_for_arm (-INTVAL (op)))));
4476 }
4477
4478 /* Return TRUE for valid ARM constants (or when valid if negated). */
4479 int
4480 arm_addimm_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
4481 {
4482 return (GET_CODE (op) == CONST_INT
4483 && (const_ok_for_arm (INTVAL (op))
4484 || const_ok_for_arm (-INTVAL (op))));
4485 }
4486
4487 int
4488 arm_not_operand (rtx op, enum machine_mode mode)
4489 {
4490 return (s_register_operand (op, mode)
4491 || (GET_CODE (op) == CONST_INT
4492 && (const_ok_for_arm (INTVAL (op))
4493 || const_ok_for_arm (~INTVAL (op)))));
4494 }
4495
4496 /* Return TRUE if the operand is a memory reference which contains an
4497 offsettable address. */
4498 int
4499 offsettable_memory_operand (rtx op, enum machine_mode mode)
4500 {
4501 if (mode == VOIDmode)
4502 mode = GET_MODE (op);
4503
4504 return (mode == GET_MODE (op)
4505 && GET_CODE (op) == MEM
4506 && offsettable_address_p (reload_completed | reload_in_progress,
4507 mode, XEXP (op, 0)));
4508 }
4509
4510 /* Return TRUE if the operand is a memory reference which is, or can be
4511 made word aligned by adjusting the offset. */
4512 int
4513 alignable_memory_operand (rtx op, enum machine_mode mode)
4514 {
4515 rtx reg;
4516
4517 if (mode == VOIDmode)
4518 mode = GET_MODE (op);
4519
4520 if (mode != GET_MODE (op) || GET_CODE (op) != MEM)
4521 return 0;
4522
4523 op = XEXP (op, 0);
4524
4525 return ((GET_CODE (reg = op) == REG
4526 || (GET_CODE (op) == SUBREG
4527 && GET_CODE (reg = SUBREG_REG (op)) == REG)
4528 || (GET_CODE (op) == PLUS
4529 && GET_CODE (XEXP (op, 1)) == CONST_INT
4530 && (GET_CODE (reg = XEXP (op, 0)) == REG
4531 || (GET_CODE (XEXP (op, 0)) == SUBREG
4532 && GET_CODE (reg = SUBREG_REG (XEXP (op, 0))) == REG))))
4533 && REGNO_POINTER_ALIGN (REGNO (reg)) >= 32);
4534 }
4535
4536 /* Similar to s_register_operand, but does not allow hard integer
4537 registers. */
4538 int
4539 f_register_operand (rtx op, enum machine_mode mode)
4540 {
4541 if (GET_MODE (op) != mode && mode != VOIDmode)
4542 return 0;
4543
4544 if (GET_CODE (op) == SUBREG)
4545 op = SUBREG_REG (op);
4546
4547 /* We don't consider registers whose class is NO_REGS
4548 to be a register operand. */
4549 return (GET_CODE (op) == REG
4550 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
4551 || REGNO_REG_CLASS (REGNO (op)) == FPA_REGS));
4552 }
4553
4554 /* Return TRUE for valid operands for the rhs of an floating point insns.
4555 Allows regs or certain consts on FPA, just regs for everything else. */
4556 int
4557 arm_float_rhs_operand (rtx op, enum machine_mode mode)
4558 {
4559 if (s_register_operand (op, mode))
4560 return TRUE;
4561
4562 if (GET_MODE (op) != mode && mode != VOIDmode)
4563 return FALSE;
4564
4565 if (TARGET_FPA && GET_CODE (op) == CONST_DOUBLE)
4566 return arm_const_double_rtx (op);
4567
4568 return FALSE;
4569 }
4570
4571 int
4572 arm_float_add_operand (rtx op, enum machine_mode mode)
4573 {
4574 if (s_register_operand (op, mode))
4575 return TRUE;
4576
4577 if (GET_MODE (op) != mode && mode != VOIDmode)
4578 return FALSE;
4579
4580 if (TARGET_FPA && GET_CODE (op) == CONST_DOUBLE)
4581 return (arm_const_double_rtx (op)
4582 || neg_const_double_rtx_ok_for_fpa (op));
4583
4584 return FALSE;
4585 }
4586
4587
4588 /* Return TRUE if OP is suitable for the rhs of a floating point comparison.
4589 Depends which fpu we are targeting. */
4590
4591 int
4592 arm_float_compare_operand (rtx op, enum machine_mode mode)
4593 {
4594 if (TARGET_VFP)
4595 return vfp_compare_operand (op, mode);
4596 else
4597 return arm_float_rhs_operand (op, mode);
4598 }
4599
4600
4601 /* Return nonzero if OP is a valid Cirrus memory address pattern. */
4602 int
4603 cirrus_memory_offset (rtx op)
4604 {
4605 /* Reject eliminable registers. */
4606 if (! (reload_in_progress || reload_completed)
4607 && ( reg_mentioned_p (frame_pointer_rtx, op)
4608 || reg_mentioned_p (arg_pointer_rtx, op)
4609 || reg_mentioned_p (virtual_incoming_args_rtx, op)
4610 || reg_mentioned_p (virtual_outgoing_args_rtx, op)
4611 || reg_mentioned_p (virtual_stack_dynamic_rtx, op)
4612 || reg_mentioned_p (virtual_stack_vars_rtx, op)))
4613 return 0;
4614
4615 if (GET_CODE (op) == MEM)
4616 {
4617 rtx ind;
4618
4619 ind = XEXP (op, 0);
4620
4621 /* Match: (mem (reg)). */
4622 if (GET_CODE (ind) == REG)
4623 return 1;
4624
4625 /* Match:
4626 (mem (plus (reg)
4627 (const))). */
4628 if (GET_CODE (ind) == PLUS
4629 && GET_CODE (XEXP (ind, 0)) == REG
4630 && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode)
4631 && GET_CODE (XEXP (ind, 1)) == CONST_INT)
4632 return 1;
4633 }
4634
4635 return 0;
4636 }
4637
4638 int
4639 arm_extendqisi_mem_op (rtx op, enum machine_mode mode)
4640 {
4641 if (!memory_operand (op, mode))
4642 return 0;
4643
4644 return arm_legitimate_address_p (mode, XEXP (op, 0), SIGN_EXTEND, 0);
4645 }
4646
4647 /* Return nonzero if OP is a Cirrus or general register. */
4648 int
4649 cirrus_register_operand (rtx op, enum machine_mode mode)
4650 {
4651 if (GET_MODE (op) != mode && mode != VOIDmode)
4652 return FALSE;
4653
4654 if (GET_CODE (op) == SUBREG)
4655 op = SUBREG_REG (op);
4656
4657 return (GET_CODE (op) == REG
4658 && (REGNO_REG_CLASS (REGNO (op)) == CIRRUS_REGS
4659 || REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS));
4660 }
4661
4662 /* Return nonzero if OP is a cirrus FP register. */
4663 int
4664 cirrus_fp_register (rtx op, enum machine_mode mode)
4665 {
4666 if (GET_MODE (op) != mode && mode != VOIDmode)
4667 return FALSE;
4668
4669 if (GET_CODE (op) == SUBREG)
4670 op = SUBREG_REG (op);
4671
4672 return (GET_CODE (op) == REG
4673 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
4674 || REGNO_REG_CLASS (REGNO (op)) == CIRRUS_REGS));
4675 }
4676
4677 /* Return nonzero if OP is a 6bit constant (0..63). */
4678 int
4679 cirrus_shift_const (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
4680 {
4681 return (GET_CODE (op) == CONST_INT
4682 && INTVAL (op) >= 0
4683 && INTVAL (op) < 64);
4684 }
4685
4686
4687 /* Return TRUE if OP is a valid VFP memory address pattern.
4688 WB if true if writeback address modes are allowed. */
4689
4690 int
4691 arm_coproc_mem_operand (rtx op, bool wb)
4692 {
4693 rtx ind;
4694
4695 /* Reject eliminable registers. */
4696 if (! (reload_in_progress || reload_completed)
4697 && ( reg_mentioned_p (frame_pointer_rtx, op)
4698 || reg_mentioned_p (arg_pointer_rtx, op)
4699 || reg_mentioned_p (virtual_incoming_args_rtx, op)
4700 || reg_mentioned_p (virtual_outgoing_args_rtx, op)
4701 || reg_mentioned_p (virtual_stack_dynamic_rtx, op)
4702 || reg_mentioned_p (virtual_stack_vars_rtx, op)))
4703 return FALSE;
4704
4705 /* Constants are converted into offsets from labels. */
4706 if (GET_CODE (op) != MEM)
4707 return FALSE;
4708
4709 ind = XEXP (op, 0);
4710
4711 if (reload_completed
4712 && (GET_CODE (ind) == LABEL_REF
4713 || (GET_CODE (ind) == CONST
4714 && GET_CODE (XEXP (ind, 0)) == PLUS
4715 && GET_CODE (XEXP (XEXP (ind, 0), 0)) == LABEL_REF
4716 && GET_CODE (XEXP (XEXP (ind, 0), 1)) == CONST_INT)))
4717 return TRUE;
4718
4719 /* Match: (mem (reg)). */
4720 if (GET_CODE (ind) == REG)
4721 return arm_address_register_rtx_p (ind, 0);
4722
4723 /* Autoincremment addressing modes. */
4724 if (wb
4725 && (GET_CODE (ind) == PRE_INC
4726 || GET_CODE (ind) == POST_INC
4727 || GET_CODE (ind) == PRE_DEC
4728 || GET_CODE (ind) == POST_DEC))
4729 return arm_address_register_rtx_p (XEXP (ind, 0), 0);
4730
4731 if (wb
4732 && (GET_CODE (ind) == POST_MODIFY || GET_CODE (ind) == PRE_MODIFY)
4733 && arm_address_register_rtx_p (XEXP (ind, 0), 0)
4734 && GET_CODE (XEXP (ind, 1)) == PLUS
4735 && rtx_equal_p (XEXP (XEXP (ind, 1), 0), XEXP (ind, 0)))
4736 ind = XEXP (ind, 1);
4737
4738 /* Match:
4739 (plus (reg)
4740 (const)). */
4741 if (GET_CODE (ind) == PLUS
4742 && GET_CODE (XEXP (ind, 0)) == REG
4743 && REG_MODE_OK_FOR_BASE_P (XEXP (ind, 0), VOIDmode)
4744 && GET_CODE (XEXP (ind, 1)) == CONST_INT
4745 && INTVAL (XEXP (ind, 1)) > -1024
4746 && INTVAL (XEXP (ind, 1)) < 1024
4747 && (INTVAL (XEXP (ind, 1)) & 3) == 0)
4748 return TRUE;
4749
4750 return FALSE;
4751 }
4752
4753
4754 /* Return TRUE if OP is a REG or constant zero. */
4755 int
4756 vfp_compare_operand (rtx op, enum machine_mode mode)
4757 {
4758 if (s_register_operand (op, mode))
4759 return TRUE;
4760
4761 return (GET_CODE (op) == CONST_DOUBLE
4762 && arm_const_double_rtx (op));
4763 }
4764
4765
4766 /* Return GENERAL_REGS if a scratch register required to reload x to/from
4767 VFP registers. Otherwise return NO_REGS. */
4768
4769 enum reg_class
4770 vfp_secondary_reload_class (enum machine_mode mode, rtx x)
4771 {
4772 if (arm_coproc_mem_operand (x, FALSE) || s_register_operand (x, mode))
4773 return NO_REGS;
4774
4775 return GENERAL_REGS;
4776 }
4777
4778
4779 /* Returns TRUE if INSN is an "LDR REG, ADDR" instruction.
4780 Use by the Cirrus Maverick code which has to workaround
4781 a hardware bug triggered by such instructions. */
4782 static bool
4783 arm_memory_load_p (rtx insn)
4784 {
4785 rtx body, lhs, rhs;;
4786
4787 if (insn == NULL_RTX || GET_CODE (insn) != INSN)
4788 return false;
4789
4790 body = PATTERN (insn);
4791
4792 if (GET_CODE (body) != SET)
4793 return false;
4794
4795 lhs = XEXP (body, 0);
4796 rhs = XEXP (body, 1);
4797
4798 lhs = REG_OR_SUBREG_RTX (lhs);
4799
4800 /* If the destination is not a general purpose
4801 register we do not have to worry. */
4802 if (GET_CODE (lhs) != REG
4803 || REGNO_REG_CLASS (REGNO (lhs)) != GENERAL_REGS)
4804 return false;
4805
4806 /* As well as loads from memory we also have to react
4807 to loads of invalid constants which will be turned
4808 into loads from the minipool. */
4809 return (GET_CODE (rhs) == MEM
4810 || GET_CODE (rhs) == SYMBOL_REF
4811 || note_invalid_constants (insn, -1, false));
4812 }
4813
4814 /* Return TRUE if INSN is a Cirrus instruction. */
4815 static bool
4816 arm_cirrus_insn_p (rtx insn)
4817 {
4818 enum attr_cirrus attr;
4819
4820 /* get_attr aborts on USE and CLOBBER. */
4821 if (!insn
4822 || GET_CODE (insn) != INSN
4823 || GET_CODE (PATTERN (insn)) == USE
4824 || GET_CODE (PATTERN (insn)) == CLOBBER)
4825 return 0;
4826
4827 attr = get_attr_cirrus (insn);
4828
4829 return attr != CIRRUS_NOT;
4830 }
4831
4832 /* Cirrus reorg for invalid instruction combinations. */
4833 static void
4834 cirrus_reorg (rtx first)
4835 {
4836 enum attr_cirrus attr;
4837 rtx body = PATTERN (first);
4838 rtx t;
4839 int nops;
4840
4841 /* Any branch must be followed by 2 non Cirrus instructions. */
4842 if (GET_CODE (first) == JUMP_INSN && GET_CODE (body) != RETURN)
4843 {
4844 nops = 0;
4845 t = next_nonnote_insn (first);
4846
4847 if (arm_cirrus_insn_p (t))
4848 ++ nops;
4849
4850 if (arm_cirrus_insn_p (next_nonnote_insn (t)))
4851 ++ nops;
4852
4853 while (nops --)
4854 emit_insn_after (gen_nop (), first);
4855
4856 return;
4857 }
4858
4859 /* (float (blah)) is in parallel with a clobber. */
4860 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0)
4861 body = XVECEXP (body, 0, 0);
4862
4863 if (GET_CODE (body) == SET)
4864 {
4865 rtx lhs = XEXP (body, 0), rhs = XEXP (body, 1);
4866
4867 /* cfldrd, cfldr64, cfstrd, cfstr64 must
4868 be followed by a non Cirrus insn. */
4869 if (get_attr_cirrus (first) == CIRRUS_DOUBLE)
4870 {
4871 if (arm_cirrus_insn_p (next_nonnote_insn (first)))
4872 emit_insn_after (gen_nop (), first);
4873
4874 return;
4875 }
4876 else if (arm_memory_load_p (first))
4877 {
4878 unsigned int arm_regno;
4879
4880 /* Any ldr/cfmvdlr, ldr/cfmvdhr, ldr/cfmvsr, ldr/cfmv64lr,
4881 ldr/cfmv64hr combination where the Rd field is the same
4882 in both instructions must be split with a non Cirrus
4883 insn. Example:
4884
4885 ldr r0, blah
4886 nop
4887 cfmvsr mvf0, r0. */
4888
4889 /* Get Arm register number for ldr insn. */
4890 if (GET_CODE (lhs) == REG)
4891 arm_regno = REGNO (lhs);
4892 else if (GET_CODE (rhs) == REG)
4893 arm_regno = REGNO (rhs);
4894 else
4895 abort ();
4896
4897 /* Next insn. */
4898 first = next_nonnote_insn (first);
4899
4900 if (! arm_cirrus_insn_p (first))
4901 return;
4902
4903 body = PATTERN (first);
4904
4905 /* (float (blah)) is in parallel with a clobber. */
4906 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0))
4907 body = XVECEXP (body, 0, 0);
4908
4909 if (GET_CODE (body) == FLOAT)
4910 body = XEXP (body, 0);
4911
4912 if (get_attr_cirrus (first) == CIRRUS_MOVE
4913 && GET_CODE (XEXP (body, 1)) == REG
4914 && arm_regno == REGNO (XEXP (body, 1)))
4915 emit_insn_after (gen_nop (), first);
4916
4917 return;
4918 }
4919 }
4920
4921 /* get_attr aborts on USE and CLOBBER. */
4922 if (!first
4923 || GET_CODE (first) != INSN
4924 || GET_CODE (PATTERN (first)) == USE
4925 || GET_CODE (PATTERN (first)) == CLOBBER)
4926 return;
4927
4928 attr = get_attr_cirrus (first);
4929
4930 /* Any coprocessor compare instruction (cfcmps, cfcmpd, ...)
4931 must be followed by a non-coprocessor instruction. */
4932 if (attr == CIRRUS_COMPARE)
4933 {
4934 nops = 0;
4935
4936 t = next_nonnote_insn (first);
4937
4938 if (arm_cirrus_insn_p (t))
4939 ++ nops;
4940
4941 if (arm_cirrus_insn_p (next_nonnote_insn (t)))
4942 ++ nops;
4943
4944 while (nops --)
4945 emit_insn_after (gen_nop (), first);
4946
4947 return;
4948 }
4949 }
4950
4951 /* Return nonzero if OP is a constant power of two. */
4952 int
4953 power_of_two_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
4954 {
4955 if (GET_CODE (op) == CONST_INT)
4956 {
4957 HOST_WIDE_INT value = INTVAL (op);
4958
4959 return value != 0 && (value & (value - 1)) == 0;
4960 }
4961
4962 return FALSE;
4963 }
4964
4965 /* Return TRUE for a valid operand of a DImode operation.
4966 Either: REG, SUBREG, CONST_DOUBLE or MEM(DImode_address).
4967 Note that this disallows MEM(REG+REG), but allows
4968 MEM(PRE/POST_INC/DEC(REG)). */
4969 int
4970 di_operand (rtx op, enum machine_mode mode)
4971 {
4972 if (s_register_operand (op, mode))
4973 return TRUE;
4974
4975 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode)
4976 return FALSE;
4977
4978 if (GET_CODE (op) == SUBREG)
4979 op = SUBREG_REG (op);
4980
4981 switch (GET_CODE (op))
4982 {
4983 case CONST_DOUBLE:
4984 case CONST_INT:
4985 return TRUE;
4986
4987 case MEM:
4988 return memory_address_p (DImode, XEXP (op, 0));
4989
4990 default:
4991 return FALSE;
4992 }
4993 }
4994
4995 /* Like di_operand, but don't accept constants. */
4996 int
4997 nonimmediate_di_operand (rtx op, enum machine_mode mode)
4998 {
4999 if (s_register_operand (op, mode))
5000 return TRUE;
5001
5002 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode)
5003 return FALSE;
5004
5005 if (GET_CODE (op) == SUBREG)
5006 op = SUBREG_REG (op);
5007
5008 if (GET_CODE (op) == MEM)
5009 return memory_address_p (DImode, XEXP (op, 0));
5010
5011 return FALSE;
5012 }
5013
5014 /* Return TRUE for a valid operand of a DFmode operation when soft-float.
5015 Either: REG, SUBREG, CONST_DOUBLE or MEM(DImode_address).
5016 Note that this disallows MEM(REG+REG), but allows
5017 MEM(PRE/POST_INC/DEC(REG)). */
5018 int
5019 soft_df_operand (rtx op, enum machine_mode mode)
5020 {
5021 if (s_register_operand (op, mode))
5022 return TRUE;
5023
5024 if (mode != VOIDmode && GET_MODE (op) != mode)
5025 return FALSE;
5026
5027 if (GET_CODE (op) == SUBREG && CONSTANT_P (SUBREG_REG (op)))
5028 return FALSE;
5029
5030 if (GET_CODE (op) == SUBREG)
5031 op = SUBREG_REG (op);
5032
5033 switch (GET_CODE (op))
5034 {
5035 case CONST_DOUBLE:
5036 return TRUE;
5037
5038 case MEM:
5039 return memory_address_p (DFmode, XEXP (op, 0));
5040
5041 default:
5042 return FALSE;
5043 }
5044 }
5045
5046 /* Like soft_df_operand, but don't accept constants. */
5047 int
5048 nonimmediate_soft_df_operand (rtx op, enum machine_mode mode)
5049 {
5050 if (s_register_operand (op, mode))
5051 return TRUE;
5052
5053 if (mode != VOIDmode && GET_MODE (op) != mode)
5054 return FALSE;
5055
5056 if (GET_CODE (op) == SUBREG)
5057 op = SUBREG_REG (op);
5058
5059 if (GET_CODE (op) == MEM)
5060 return memory_address_p (DFmode, XEXP (op, 0));
5061 return FALSE;
5062 }
5063
5064 /* Return TRUE for valid index operands. */
5065 int
5066 index_operand (rtx op, enum machine_mode mode)
5067 {
5068 return (s_register_operand (op, mode)
5069 || (immediate_operand (op, mode)
5070 && (GET_CODE (op) != CONST_INT
5071 || (INTVAL (op) < 4096 && INTVAL (op) > -4096))));
5072 }
5073
5074 /* Return TRUE for valid shifts by a constant. This also accepts any
5075 power of two on the (somewhat overly relaxed) assumption that the
5076 shift operator in this case was a mult. */
5077 int
5078 const_shift_operand (rtx op, enum machine_mode mode)
5079 {
5080 return (power_of_two_operand (op, mode)
5081 || (immediate_operand (op, mode)
5082 && (GET_CODE (op) != CONST_INT
5083 || (INTVAL (op) < 32 && INTVAL (op) > 0))));
5084 }
5085
5086 /* Return TRUE for arithmetic operators which can be combined with a multiply
5087 (shift). */
5088 int
5089 shiftable_operator (rtx x, enum machine_mode mode)
5090 {
5091 enum rtx_code code;
5092
5093 if (GET_MODE (x) != mode)
5094 return FALSE;
5095
5096 code = GET_CODE (x);
5097
5098 return (code == PLUS || code == MINUS
5099 || code == IOR || code == XOR || code == AND);
5100 }
5101
5102 /* Return TRUE for binary logical operators. */
5103 int
5104 logical_binary_operator (rtx x, enum machine_mode mode)
5105 {
5106 enum rtx_code code;
5107
5108 if (GET_MODE (x) != mode)
5109 return FALSE;
5110
5111 code = GET_CODE (x);
5112
5113 return (code == IOR || code == XOR || code == AND);
5114 }
5115
5116 /* Return TRUE for shift operators. */
5117 int
5118 shift_operator (rtx x,enum machine_mode mode)
5119 {
5120 enum rtx_code code;
5121
5122 if (GET_MODE (x) != mode)
5123 return FALSE;
5124
5125 code = GET_CODE (x);
5126
5127 if (code == MULT)
5128 return power_of_two_operand (XEXP (x, 1), mode);
5129
5130 return (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT
5131 || code == ROTATERT);
5132 }
5133
5134 /* Return TRUE if x is EQ or NE. */
5135 int
5136 equality_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
5137 {
5138 return GET_CODE (x) == EQ || GET_CODE (x) == NE;
5139 }
5140
5141 /* Return TRUE if x is a comparison operator other than LTGT or UNEQ. */
5142 int
5143 arm_comparison_operator (rtx x, enum machine_mode mode)
5144 {
5145 return (comparison_operator (x, mode)
5146 && GET_CODE (x) != LTGT
5147 && GET_CODE (x) != UNEQ);
5148 }
5149
5150 /* Return TRUE for SMIN SMAX UMIN UMAX operators. */
5151 int
5152 minmax_operator (rtx x, enum machine_mode mode)
5153 {
5154 enum rtx_code code = GET_CODE (x);
5155
5156 if (GET_MODE (x) != mode)
5157 return FALSE;
5158
5159 return code == SMIN || code == SMAX || code == UMIN || code == UMAX;
5160 }
5161
5162 /* Return TRUE if this is the condition code register, if we aren't given
5163 a mode, accept any class CCmode register. */
5164 int
5165 cc_register (rtx x, enum machine_mode mode)
5166 {
5167 if (mode == VOIDmode)
5168 {
5169 mode = GET_MODE (x);
5170
5171 if (GET_MODE_CLASS (mode) != MODE_CC)
5172 return FALSE;
5173 }
5174
5175 if ( GET_MODE (x) == mode
5176 && GET_CODE (x) == REG
5177 && REGNO (x) == CC_REGNUM)
5178 return TRUE;
5179
5180 return FALSE;
5181 }
5182
5183 /* Return TRUE if this is the condition code register, if we aren't given
5184 a mode, accept any class CCmode register which indicates a dominance
5185 expression. */
5186 int
5187 dominant_cc_register (rtx x, enum machine_mode mode)
5188 {
5189 if (mode == VOIDmode)
5190 {
5191 mode = GET_MODE (x);
5192
5193 if (GET_MODE_CLASS (mode) != MODE_CC)
5194 return FALSE;
5195 }
5196
5197 if (mode != CC_DNEmode && mode != CC_DEQmode
5198 && mode != CC_DLEmode && mode != CC_DLTmode
5199 && mode != CC_DGEmode && mode != CC_DGTmode
5200 && mode != CC_DLEUmode && mode != CC_DLTUmode
5201 && mode != CC_DGEUmode && mode != CC_DGTUmode)
5202 return FALSE;
5203
5204 return cc_register (x, mode);
5205 }
5206
5207 /* Return TRUE if X references a SYMBOL_REF. */
5208 int
5209 symbol_mentioned_p (rtx x)
5210 {
5211 const char * fmt;
5212 int i;
5213
5214 if (GET_CODE (x) == SYMBOL_REF)
5215 return 1;
5216
5217 fmt = GET_RTX_FORMAT (GET_CODE (x));
5218
5219 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5220 {
5221 if (fmt[i] == 'E')
5222 {
5223 int j;
5224
5225 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5226 if (symbol_mentioned_p (XVECEXP (x, i, j)))
5227 return 1;
5228 }
5229 else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
5230 return 1;
5231 }
5232
5233 return 0;
5234 }
5235
5236 /* Return TRUE if X references a LABEL_REF. */
5237 int
5238 label_mentioned_p (rtx x)
5239 {
5240 const char * fmt;
5241 int i;
5242
5243 if (GET_CODE (x) == LABEL_REF)
5244 return 1;
5245
5246 fmt = GET_RTX_FORMAT (GET_CODE (x));
5247 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5248 {
5249 if (fmt[i] == 'E')
5250 {
5251 int j;
5252
5253 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5254 if (label_mentioned_p (XVECEXP (x, i, j)))
5255 return 1;
5256 }
5257 else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
5258 return 1;
5259 }
5260
5261 return 0;
5262 }
5263
5264 enum rtx_code
5265 minmax_code (rtx x)
5266 {
5267 enum rtx_code code = GET_CODE (x);
5268
5269 if (code == SMAX)
5270 return GE;
5271 else if (code == SMIN)
5272 return LE;
5273 else if (code == UMIN)
5274 return LEU;
5275 else if (code == UMAX)
5276 return GEU;
5277
5278 abort ();
5279 }
5280
5281 /* Return 1 if memory locations are adjacent. */
5282 int
5283 adjacent_mem_locations (rtx a, rtx b)
5284 {
5285 if ((GET_CODE (XEXP (a, 0)) == REG
5286 || (GET_CODE (XEXP (a, 0)) == PLUS
5287 && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT))
5288 && (GET_CODE (XEXP (b, 0)) == REG
5289 || (GET_CODE (XEXP (b, 0)) == PLUS
5290 && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT)))
5291 {
5292 int val0 = 0, val1 = 0;
5293 int reg0, reg1;
5294
5295 if (GET_CODE (XEXP (a, 0)) == PLUS)
5296 {
5297 reg0 = REGNO (XEXP (XEXP (a, 0), 0));
5298 val0 = INTVAL (XEXP (XEXP (a, 0), 1));
5299 }
5300 else
5301 reg0 = REGNO (XEXP (a, 0));
5302
5303 if (GET_CODE (XEXP (b, 0)) == PLUS)
5304 {
5305 reg1 = REGNO (XEXP (XEXP (b, 0), 0));
5306 val1 = INTVAL (XEXP (XEXP (b, 0), 1));
5307 }
5308 else
5309 reg1 = REGNO (XEXP (b, 0));
5310
5311 /* Don't accept any offset that will require multiple
5312 instructions to handle, since this would cause the
5313 arith_adjacentmem pattern to output an overlong sequence. */
5314 if (!const_ok_for_op (PLUS, val0) || !const_ok_for_op (PLUS, val1))
5315 return 0;
5316
5317 return (reg0 == reg1) && ((val1 - val0) == 4 || (val0 - val1) == 4);
5318 }
5319 return 0;
5320 }
5321
5322 /* Return 1 if OP is a load multiple operation. It is known to be
5323 parallel and the first section will be tested. */
5324 int
5325 load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
5326 {
5327 HOST_WIDE_INT count = XVECLEN (op, 0);
5328 int dest_regno;
5329 rtx src_addr;
5330 HOST_WIDE_INT i = 1, base = 0;
5331 rtx elt;
5332
5333 if (count <= 1
5334 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
5335 return 0;
5336
5337 /* Check to see if this might be a write-back. */
5338 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
5339 {
5340 i++;
5341 base = 1;
5342
5343 /* Now check it more carefully. */
5344 if (GET_CODE (SET_DEST (elt)) != REG
5345 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
5346 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
5347 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4)
5348 return 0;
5349 }
5350
5351 /* Perform a quick check so we don't blow up below. */
5352 if (count <= i
5353 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
5354 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
5355 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM)
5356 return 0;
5357
5358 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
5359 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
5360
5361 for (; i < count; i++)
5362 {
5363 elt = XVECEXP (op, 0, i);
5364
5365 if (GET_CODE (elt) != SET
5366 || GET_CODE (SET_DEST (elt)) != REG
5367 || GET_MODE (SET_DEST (elt)) != SImode
5368 || REGNO (SET_DEST (elt)) != (unsigned int)(dest_regno + i - base)
5369 || GET_CODE (SET_SRC (elt)) != MEM
5370 || GET_MODE (SET_SRC (elt)) != SImode
5371 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
5372 || !rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
5373 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
5374 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4)
5375 return 0;
5376 }
5377
5378 return 1;
5379 }
5380
5381 /* Return 1 if OP is a store multiple operation. It is known to be
5382 parallel and the first section will be tested. */
5383 int
5384 store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
5385 {
5386 HOST_WIDE_INT count = XVECLEN (op, 0);
5387 int src_regno;
5388 rtx dest_addr;
5389 HOST_WIDE_INT i = 1, base = 0;
5390 rtx elt;
5391
5392 if (count <= 1
5393 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
5394 return 0;
5395
5396 /* Check to see if this might be a write-back. */
5397 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
5398 {
5399 i++;
5400 base = 1;
5401
5402 /* Now check it more carefully. */
5403 if (GET_CODE (SET_DEST (elt)) != REG
5404 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
5405 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
5406 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4)
5407 return 0;
5408 }
5409
5410 /* Perform a quick check so we don't blow up below. */
5411 if (count <= i
5412 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
5413 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
5414 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG)
5415 return 0;
5416
5417 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
5418 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
5419
5420 for (; i < count; i++)
5421 {
5422 elt = XVECEXP (op, 0, i);
5423
5424 if (GET_CODE (elt) != SET
5425 || GET_CODE (SET_SRC (elt)) != REG
5426 || GET_MODE (SET_SRC (elt)) != SImode
5427 || REGNO (SET_SRC (elt)) != (unsigned int)(src_regno + i - base)
5428 || GET_CODE (SET_DEST (elt)) != MEM
5429 || GET_MODE (SET_DEST (elt)) != SImode
5430 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
5431 || !rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
5432 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
5433 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4)
5434 return 0;
5435 }
5436
5437 return 1;
5438 }
5439
5440 int
5441 load_multiple_sequence (rtx *operands, int nops, int *regs, int *base,
5442 HOST_WIDE_INT *load_offset)
5443 {
5444 int unsorted_regs[4];
5445 HOST_WIDE_INT unsorted_offsets[4];
5446 int order[4];
5447 int base_reg = -1;
5448 int i;
5449
5450 /* Can only handle 2, 3, or 4 insns at present,
5451 though could be easily extended if required. */
5452 if (nops < 2 || nops > 4)
5453 abort ();
5454
5455 /* Loop over the operands and check that the memory references are
5456 suitable (ie immediate offsets from the same base register). At
5457 the same time, extract the target register, and the memory
5458 offsets. */
5459 for (i = 0; i < nops; i++)
5460 {
5461 rtx reg;
5462 rtx offset;
5463
5464 /* Convert a subreg of a mem into the mem itself. */
5465 if (GET_CODE (operands[nops + i]) == SUBREG)
5466 operands[nops + i] = alter_subreg (operands + (nops + i));
5467
5468 if (GET_CODE (operands[nops + i]) != MEM)
5469 abort ();
5470
5471 /* Don't reorder volatile memory references; it doesn't seem worth
5472 looking for the case where the order is ok anyway. */
5473 if (MEM_VOLATILE_P (operands[nops + i]))
5474 return 0;
5475
5476 offset = const0_rtx;
5477
5478 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
5479 || (GET_CODE (reg) == SUBREG
5480 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
5481 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
5482 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
5483 == REG)
5484 || (GET_CODE (reg) == SUBREG
5485 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
5486 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
5487 == CONST_INT)))
5488 {
5489 if (i == 0)
5490 {
5491 base_reg = REGNO (reg);
5492 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
5493 ? REGNO (operands[i])
5494 : REGNO (SUBREG_REG (operands[i])));
5495 order[0] = 0;
5496 }
5497 else
5498 {
5499 if (base_reg != (int) REGNO (reg))
5500 /* Not addressed from the same base register. */
5501 return 0;
5502
5503 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
5504 ? REGNO (operands[i])
5505 : REGNO (SUBREG_REG (operands[i])));
5506 if (unsorted_regs[i] < unsorted_regs[order[0]])
5507 order[0] = i;
5508 }
5509
5510 /* If it isn't an integer register, or if it overwrites the
5511 base register but isn't the last insn in the list, then
5512 we can't do this. */
5513 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14
5514 || (i != nops - 1 && unsorted_regs[i] == base_reg))
5515 return 0;
5516
5517 unsorted_offsets[i] = INTVAL (offset);
5518 }
5519 else
5520 /* Not a suitable memory address. */
5521 return 0;
5522 }
5523
5524 /* All the useful information has now been extracted from the
5525 operands into unsorted_regs and unsorted_offsets; additionally,
5526 order[0] has been set to the lowest numbered register in the
5527 list. Sort the registers into order, and check that the memory
5528 offsets are ascending and adjacent. */
5529
5530 for (i = 1; i < nops; i++)
5531 {
5532 int j;
5533
5534 order[i] = order[i - 1];
5535 for (j = 0; j < nops; j++)
5536 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
5537 && (order[i] == order[i - 1]
5538 || unsorted_regs[j] < unsorted_regs[order[i]]))
5539 order[i] = j;
5540
5541 /* Have we found a suitable register? if not, one must be used more
5542 than once. */
5543 if (order[i] == order[i - 1])
5544 return 0;
5545
5546 /* Is the memory address adjacent and ascending? */
5547 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
5548 return 0;
5549 }
5550
5551 if (base)
5552 {
5553 *base = base_reg;
5554
5555 for (i = 0; i < nops; i++)
5556 regs[i] = unsorted_regs[order[i]];
5557
5558 *load_offset = unsorted_offsets[order[0]];
5559 }
5560
5561 if (unsorted_offsets[order[0]] == 0)
5562 return 1; /* ldmia */
5563
5564 if (unsorted_offsets[order[0]] == 4)
5565 return 2; /* ldmib */
5566
5567 if (unsorted_offsets[order[nops - 1]] == 0)
5568 return 3; /* ldmda */
5569
5570 if (unsorted_offsets[order[nops - 1]] == -4)
5571 return 4; /* ldmdb */
5572
5573 /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm
5574 if the offset isn't small enough. The reason 2 ldrs are faster
5575 is because these ARMs are able to do more than one cache access
5576 in a single cycle. The ARM9 and StrongARM have Harvard caches,
5577 whilst the ARM8 has a double bandwidth cache. This means that
5578 these cores can do both an instruction fetch and a data fetch in
5579 a single cycle, so the trick of calculating the address into a
5580 scratch register (one of the result regs) and then doing a load
5581 multiple actually becomes slower (and no smaller in code size).
5582 That is the transformation
5583
5584 ldr rd1, [rbase + offset]
5585 ldr rd2, [rbase + offset + 4]
5586
5587 to
5588
5589 add rd1, rbase, offset
5590 ldmia rd1, {rd1, rd2}
5591
5592 produces worse code -- '3 cycles + any stalls on rd2' instead of
5593 '2 cycles + any stalls on rd2'. On ARMs with only one cache
5594 access per cycle, the first sequence could never complete in less
5595 than 6 cycles, whereas the ldm sequence would only take 5 and
5596 would make better use of sequential accesses if not hitting the
5597 cache.
5598
5599 We cheat here and test 'arm_ld_sched' which we currently know to
5600 only be true for the ARM8, ARM9 and StrongARM. If this ever
5601 changes, then the test below needs to be reworked. */
5602 if (nops == 2 && arm_ld_sched)
5603 return 0;
5604
5605 /* Can't do it without setting up the offset, only do this if it takes
5606 no more than one insn. */
5607 return (const_ok_for_arm (unsorted_offsets[order[0]])
5608 || const_ok_for_arm (-unsorted_offsets[order[0]])) ? 5 : 0;
5609 }
5610
5611 const char *
5612 emit_ldm_seq (rtx *operands, int nops)
5613 {
5614 int regs[4];
5615 int base_reg;
5616 HOST_WIDE_INT offset;
5617 char buf[100];
5618 int i;
5619
5620 switch (load_multiple_sequence (operands, nops, regs, &base_reg, &offset))
5621 {
5622 case 1:
5623 strcpy (buf, "ldm%?ia\t");
5624 break;
5625
5626 case 2:
5627 strcpy (buf, "ldm%?ib\t");
5628 break;
5629
5630 case 3:
5631 strcpy (buf, "ldm%?da\t");
5632 break;
5633
5634 case 4:
5635 strcpy (buf, "ldm%?db\t");
5636 break;
5637
5638 case 5:
5639 if (offset >= 0)
5640 sprintf (buf, "add%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
5641 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
5642 (long) offset);
5643 else
5644 sprintf (buf, "sub%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
5645 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
5646 (long) -offset);
5647 output_asm_insn (buf, operands);
5648 base_reg = regs[0];
5649 strcpy (buf, "ldm%?ia\t");
5650 break;
5651
5652 default:
5653 abort ();
5654 }
5655
5656 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
5657 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
5658
5659 for (i = 1; i < nops; i++)
5660 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
5661 reg_names[regs[i]]);
5662
5663 strcat (buf, "}\t%@ phole ldm");
5664
5665 output_asm_insn (buf, operands);
5666 return "";
5667 }
5668
5669 int
5670 store_multiple_sequence (rtx *operands, int nops, int *regs, int *base,
5671 HOST_WIDE_INT * load_offset)
5672 {
5673 int unsorted_regs[4];
5674 HOST_WIDE_INT unsorted_offsets[4];
5675 int order[4];
5676 int base_reg = -1;
5677 int i;
5678
5679 /* Can only handle 2, 3, or 4 insns at present, though could be easily
5680 extended if required. */
5681 if (nops < 2 || nops > 4)
5682 abort ();
5683
5684 /* Loop over the operands and check that the memory references are
5685 suitable (ie immediate offsets from the same base register). At
5686 the same time, extract the target register, and the memory
5687 offsets. */
5688 for (i = 0; i < nops; i++)
5689 {
5690 rtx reg;
5691 rtx offset;
5692
5693 /* Convert a subreg of a mem into the mem itself. */
5694 if (GET_CODE (operands[nops + i]) == SUBREG)
5695 operands[nops + i] = alter_subreg (operands + (nops + i));
5696
5697 if (GET_CODE (operands[nops + i]) != MEM)
5698 abort ();
5699
5700 /* Don't reorder volatile memory references; it doesn't seem worth
5701 looking for the case where the order is ok anyway. */
5702 if (MEM_VOLATILE_P (operands[nops + i]))
5703 return 0;
5704
5705 offset = const0_rtx;
5706
5707 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
5708 || (GET_CODE (reg) == SUBREG
5709 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
5710 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
5711 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
5712 == REG)
5713 || (GET_CODE (reg) == SUBREG
5714 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
5715 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
5716 == CONST_INT)))
5717 {
5718 if (i == 0)
5719 {
5720 base_reg = REGNO (reg);
5721 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
5722 ? REGNO (operands[i])
5723 : REGNO (SUBREG_REG (operands[i])));
5724 order[0] = 0;
5725 }
5726 else
5727 {
5728 if (base_reg != (int) REGNO (reg))
5729 /* Not addressed from the same base register. */
5730 return 0;
5731
5732 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
5733 ? REGNO (operands[i])
5734 : REGNO (SUBREG_REG (operands[i])));
5735 if (unsorted_regs[i] < unsorted_regs[order[0]])
5736 order[0] = i;
5737 }
5738
5739 /* If it isn't an integer register, then we can't do this. */
5740 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14)
5741 return 0;
5742
5743 unsorted_offsets[i] = INTVAL (offset);
5744 }
5745 else
5746 /* Not a suitable memory address. */
5747 return 0;
5748 }
5749
5750 /* All the useful information has now been extracted from the
5751 operands into unsorted_regs and unsorted_offsets; additionally,
5752 order[0] has been set to the lowest numbered register in the
5753 list. Sort the registers into order, and check that the memory
5754 offsets are ascending and adjacent. */
5755
5756 for (i = 1; i < nops; i++)
5757 {
5758 int j;
5759
5760 order[i] = order[i - 1];
5761 for (j = 0; j < nops; j++)
5762 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
5763 && (order[i] == order[i - 1]
5764 || unsorted_regs[j] < unsorted_regs[order[i]]))
5765 order[i] = j;
5766
5767 /* Have we found a suitable register? if not, one must be used more
5768 than once. */
5769 if (order[i] == order[i - 1])
5770 return 0;
5771
5772 /* Is the memory address adjacent and ascending? */
5773 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
5774 return 0;
5775 }
5776
5777 if (base)
5778 {
5779 *base = base_reg;
5780
5781 for (i = 0; i < nops; i++)
5782 regs[i] = unsorted_regs[order[i]];
5783
5784 *load_offset = unsorted_offsets[order[0]];
5785 }
5786
5787 if (unsorted_offsets[order[0]] == 0)
5788 return 1; /* stmia */
5789
5790 if (unsorted_offsets[order[0]] == 4)
5791 return 2; /* stmib */
5792
5793 if (unsorted_offsets[order[nops - 1]] == 0)
5794 return 3; /* stmda */
5795
5796 if (unsorted_offsets[order[nops - 1]] == -4)
5797 return 4; /* stmdb */
5798
5799 return 0;
5800 }
5801
5802 const char *
5803 emit_stm_seq (rtx *operands, int nops)
5804 {
5805 int regs[4];
5806 int base_reg;
5807 HOST_WIDE_INT offset;
5808 char buf[100];
5809 int i;
5810
5811 switch (store_multiple_sequence (operands, nops, regs, &base_reg, &offset))
5812 {
5813 case 1:
5814 strcpy (buf, "stm%?ia\t");
5815 break;
5816
5817 case 2:
5818 strcpy (buf, "stm%?ib\t");
5819 break;
5820
5821 case 3:
5822 strcpy (buf, "stm%?da\t");
5823 break;
5824
5825 case 4:
5826 strcpy (buf, "stm%?db\t");
5827 break;
5828
5829 default:
5830 abort ();
5831 }
5832
5833 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
5834 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
5835
5836 for (i = 1; i < nops; i++)
5837 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
5838 reg_names[regs[i]]);
5839
5840 strcat (buf, "}\t%@ phole stm");
5841
5842 output_asm_insn (buf, operands);
5843 return "";
5844 }
5845
5846 int
5847 multi_register_push (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
5848 {
5849 if (GET_CODE (op) != PARALLEL
5850 || (GET_CODE (XVECEXP (op, 0, 0)) != SET)
5851 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
5852 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT))
5853 return 0;
5854
5855 return 1;
5856 }
5857 \f
5858 /* Routines for use in generating RTL. */
5859
5860 rtx
5861 arm_gen_load_multiple (int base_regno, int count, rtx from, int up,
5862 int write_back, int unchanging_p, int in_struct_p,
5863 int scalar_p)
5864 {
5865 int i = 0, j;
5866 rtx result;
5867 int sign = up ? 1 : -1;
5868 rtx mem;
5869
5870 /* XScale has load-store double instructions, but they have stricter
5871 alignment requirements than load-store multiple, so we can not
5872 use them.
5873
5874 For XScale ldm requires 2 + NREGS cycles to complete and blocks
5875 the pipeline until completion.
5876
5877 NREGS CYCLES
5878 1 3
5879 2 4
5880 3 5
5881 4 6
5882
5883 An ldr instruction takes 1-3 cycles, but does not block the
5884 pipeline.
5885
5886 NREGS CYCLES
5887 1 1-3
5888 2 2-6
5889 3 3-9
5890 4 4-12
5891
5892 Best case ldr will always win. However, the more ldr instructions
5893 we issue, the less likely we are to be able to schedule them well.
5894 Using ldr instructions also increases code size.
5895
5896 As a compromise, we use ldr for counts of 1 or 2 regs, and ldm
5897 for counts of 3 or 4 regs. */
5898 if (arm_tune_xscale && count <= 2 && ! optimize_size)
5899 {
5900 rtx seq;
5901
5902 start_sequence ();
5903
5904 for (i = 0; i < count; i++)
5905 {
5906 mem = gen_rtx_MEM (SImode, plus_constant (from, i * 4 * sign));
5907 RTX_UNCHANGING_P (mem) = unchanging_p;
5908 MEM_IN_STRUCT_P (mem) = in_struct_p;
5909 MEM_SCALAR_P (mem) = scalar_p;
5910 emit_move_insn (gen_rtx_REG (SImode, base_regno + i), mem);
5911 }
5912
5913 if (write_back)
5914 emit_move_insn (from, plus_constant (from, count * 4 * sign));
5915
5916 seq = get_insns ();
5917 end_sequence ();
5918
5919 return seq;
5920 }
5921
5922 result = gen_rtx_PARALLEL (VOIDmode,
5923 rtvec_alloc (count + (write_back ? 1 : 0)));
5924 if (write_back)
5925 {
5926 XVECEXP (result, 0, 0)
5927 = gen_rtx_SET (GET_MODE (from), from,
5928 plus_constant (from, count * 4 * sign));
5929 i = 1;
5930 count++;
5931 }
5932
5933 for (j = 0; i < count; i++, j++)
5934 {
5935 mem = gen_rtx_MEM (SImode, plus_constant (from, j * 4 * sign));
5936 RTX_UNCHANGING_P (mem) = unchanging_p;
5937 MEM_IN_STRUCT_P (mem) = in_struct_p;
5938 MEM_SCALAR_P (mem) = scalar_p;
5939 XVECEXP (result, 0, i)
5940 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, base_regno + j), mem);
5941 }
5942
5943 return result;
5944 }
5945
5946 rtx
5947 arm_gen_store_multiple (int base_regno, int count, rtx to, int up,
5948 int write_back, int unchanging_p, int in_struct_p,
5949 int scalar_p)
5950 {
5951 int i = 0, j;
5952 rtx result;
5953 int sign = up ? 1 : -1;
5954 rtx mem;
5955
5956 /* See arm_gen_load_multiple for discussion of
5957 the pros/cons of ldm/stm usage for XScale. */
5958 if (arm_tune_xscale && count <= 2 && ! optimize_size)
5959 {
5960 rtx seq;
5961
5962 start_sequence ();
5963
5964 for (i = 0; i < count; i++)
5965 {
5966 mem = gen_rtx_MEM (SImode, plus_constant (to, i * 4 * sign));
5967 RTX_UNCHANGING_P (mem) = unchanging_p;
5968 MEM_IN_STRUCT_P (mem) = in_struct_p;
5969 MEM_SCALAR_P (mem) = scalar_p;
5970 emit_move_insn (mem, gen_rtx_REG (SImode, base_regno + i));
5971 }
5972
5973 if (write_back)
5974 emit_move_insn (to, plus_constant (to, count * 4 * sign));
5975
5976 seq = get_insns ();
5977 end_sequence ();
5978
5979 return seq;
5980 }
5981
5982 result = gen_rtx_PARALLEL (VOIDmode,
5983 rtvec_alloc (count + (write_back ? 1 : 0)));
5984 if (write_back)
5985 {
5986 XVECEXP (result, 0, 0)
5987 = gen_rtx_SET (GET_MODE (to), to,
5988 plus_constant (to, count * 4 * sign));
5989 i = 1;
5990 count++;
5991 }
5992
5993 for (j = 0; i < count; i++, j++)
5994 {
5995 mem = gen_rtx_MEM (SImode, plus_constant (to, j * 4 * sign));
5996 RTX_UNCHANGING_P (mem) = unchanging_p;
5997 MEM_IN_STRUCT_P (mem) = in_struct_p;
5998 MEM_SCALAR_P (mem) = scalar_p;
5999
6000 XVECEXP (result, 0, i)
6001 = gen_rtx_SET (VOIDmode, mem, gen_rtx_REG (SImode, base_regno + j));
6002 }
6003
6004 return result;
6005 }
6006
6007 int
6008 arm_gen_movmemqi (rtx *operands)
6009 {
6010 HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes;
6011 int i;
6012 rtx src, dst;
6013 rtx st_src, st_dst, fin_src, fin_dst;
6014 rtx part_bytes_reg = NULL;
6015 rtx mem;
6016 int dst_unchanging_p, dst_in_struct_p, src_unchanging_p, src_in_struct_p;
6017 int dst_scalar_p, src_scalar_p;
6018
6019 if (GET_CODE (operands[2]) != CONST_INT
6020 || GET_CODE (operands[3]) != CONST_INT
6021 || INTVAL (operands[2]) > 64
6022 || INTVAL (operands[3]) & 3)
6023 return 0;
6024
6025 st_dst = XEXP (operands[0], 0);
6026 st_src = XEXP (operands[1], 0);
6027
6028 dst_unchanging_p = RTX_UNCHANGING_P (operands[0]);
6029 dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]);
6030 dst_scalar_p = MEM_SCALAR_P (operands[0]);
6031 src_unchanging_p = RTX_UNCHANGING_P (operands[1]);
6032 src_in_struct_p = MEM_IN_STRUCT_P (operands[1]);
6033 src_scalar_p = MEM_SCALAR_P (operands[1]);
6034
6035 fin_dst = dst = copy_to_mode_reg (SImode, st_dst);
6036 fin_src = src = copy_to_mode_reg (SImode, st_src);
6037
6038 in_words_to_go = ARM_NUM_INTS (INTVAL (operands[2]));
6039 out_words_to_go = INTVAL (operands[2]) / 4;
6040 last_bytes = INTVAL (operands[2]) & 3;
6041
6042 if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0)
6043 part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3);
6044
6045 for (i = 0; in_words_to_go >= 2; i+=4)
6046 {
6047 if (in_words_to_go > 4)
6048 emit_insn (arm_gen_load_multiple (0, 4, src, TRUE, TRUE,
6049 src_unchanging_p,
6050 src_in_struct_p,
6051 src_scalar_p));
6052 else
6053 emit_insn (arm_gen_load_multiple (0, in_words_to_go, src, TRUE,
6054 FALSE, src_unchanging_p,
6055 src_in_struct_p, src_scalar_p));
6056
6057 if (out_words_to_go)
6058 {
6059 if (out_words_to_go > 4)
6060 emit_insn (arm_gen_store_multiple (0, 4, dst, TRUE, TRUE,
6061 dst_unchanging_p,
6062 dst_in_struct_p,
6063 dst_scalar_p));
6064 else if (out_words_to_go != 1)
6065 emit_insn (arm_gen_store_multiple (0, out_words_to_go,
6066 dst, TRUE,
6067 (last_bytes == 0
6068 ? FALSE : TRUE),
6069 dst_unchanging_p,
6070 dst_in_struct_p,
6071 dst_scalar_p));
6072 else
6073 {
6074 mem = gen_rtx_MEM (SImode, dst);
6075 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
6076 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
6077 MEM_SCALAR_P (mem) = dst_scalar_p;
6078 emit_move_insn (mem, gen_rtx_REG (SImode, 0));
6079 if (last_bytes != 0)
6080 emit_insn (gen_addsi3 (dst, dst, GEN_INT (4)));
6081 }
6082 }
6083
6084 in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4;
6085 out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4;
6086 }
6087
6088 /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */
6089 if (out_words_to_go)
6090 {
6091 rtx sreg;
6092
6093 mem = gen_rtx_MEM (SImode, src);
6094 RTX_UNCHANGING_P (mem) = src_unchanging_p;
6095 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
6096 MEM_SCALAR_P (mem) = src_scalar_p;
6097 emit_move_insn (sreg = gen_reg_rtx (SImode), mem);
6098 emit_move_insn (fin_src = gen_reg_rtx (SImode), plus_constant (src, 4));
6099
6100 mem = gen_rtx_MEM (SImode, dst);
6101 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
6102 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
6103 MEM_SCALAR_P (mem) = dst_scalar_p;
6104 emit_move_insn (mem, sreg);
6105 emit_move_insn (fin_dst = gen_reg_rtx (SImode), plus_constant (dst, 4));
6106 in_words_to_go--;
6107
6108 if (in_words_to_go) /* Sanity check */
6109 abort ();
6110 }
6111
6112 if (in_words_to_go)
6113 {
6114 if (in_words_to_go < 0)
6115 abort ();
6116
6117 mem = gen_rtx_MEM (SImode, src);
6118 RTX_UNCHANGING_P (mem) = src_unchanging_p;
6119 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
6120 MEM_SCALAR_P (mem) = src_scalar_p;
6121 part_bytes_reg = copy_to_mode_reg (SImode, mem);
6122 }
6123
6124 if (last_bytes && part_bytes_reg == NULL)
6125 abort ();
6126
6127 if (BYTES_BIG_ENDIAN && last_bytes)
6128 {
6129 rtx tmp = gen_reg_rtx (SImode);
6130
6131 /* The bytes we want are in the top end of the word. */
6132 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg,
6133 GEN_INT (8 * (4 - last_bytes))));
6134 part_bytes_reg = tmp;
6135
6136 while (last_bytes)
6137 {
6138 mem = gen_rtx_MEM (QImode, plus_constant (dst, last_bytes - 1));
6139 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
6140 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
6141 MEM_SCALAR_P (mem) = dst_scalar_p;
6142 emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg));
6143
6144 if (--last_bytes)
6145 {
6146 tmp = gen_reg_rtx (SImode);
6147 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
6148 part_bytes_reg = tmp;
6149 }
6150 }
6151
6152 }
6153 else
6154 {
6155 if (last_bytes > 1)
6156 {
6157 mem = gen_rtx_MEM (HImode, dst);
6158 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
6159 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
6160 MEM_SCALAR_P (mem) = dst_scalar_p;
6161 emit_move_insn (mem, gen_lowpart (HImode, part_bytes_reg));
6162 last_bytes -= 2;
6163 if (last_bytes)
6164 {
6165 rtx tmp = gen_reg_rtx (SImode);
6166
6167 emit_insn (gen_addsi3 (dst, dst, const2_rtx));
6168 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (16)));
6169 part_bytes_reg = tmp;
6170 }
6171 }
6172
6173 if (last_bytes)
6174 {
6175 mem = gen_rtx_MEM (QImode, dst);
6176 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
6177 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
6178 MEM_SCALAR_P (mem) = dst_scalar_p;
6179 emit_move_insn (mem, gen_lowpart (QImode, part_bytes_reg));
6180 }
6181 }
6182
6183 return 1;
6184 }
6185
6186 /* Generate a memory reference for a half word, such that it will be loaded
6187 into the top 16 bits of the word. We can assume that the address is
6188 known to be alignable and of the form reg, or plus (reg, const). */
6189
6190 rtx
6191 arm_gen_rotated_half_load (rtx memref)
6192 {
6193 HOST_WIDE_INT offset = 0;
6194 rtx base = XEXP (memref, 0);
6195
6196 if (GET_CODE (base) == PLUS)
6197 {
6198 offset = INTVAL (XEXP (base, 1));
6199 base = XEXP (base, 0);
6200 }
6201
6202 /* If we aren't allowed to generate unaligned addresses, then fail. */
6203 if ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 0))
6204 return NULL;
6205
6206 base = gen_rtx_MEM (SImode, plus_constant (base, offset & ~2));
6207
6208 if ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 2))
6209 return base;
6210
6211 return gen_rtx_ROTATE (SImode, base, GEN_INT (16));
6212 }
6213
6214 /* Select a dominance comparison mode if possible for a test of the general
6215 form (OP (COND_OR (X) (Y)) (const_int 0)). We support three forms.
6216 COND_OR == DOM_CC_X_AND_Y => (X && Y)
6217 COND_OR == DOM_CC_NX_OR_Y => ((! X) || Y)
6218 COND_OR == DOM_CC_X_OR_Y => (X || Y)
6219 In all cases OP will be either EQ or NE, but we don't need to know which
6220 here. If we are unable to support a dominance comparison we return
6221 CC mode. This will then fail to match for the RTL expressions that
6222 generate this call. */
6223 enum machine_mode
6224 arm_select_dominance_cc_mode (rtx x, rtx y, HOST_WIDE_INT cond_or)
6225 {
6226 enum rtx_code cond1, cond2;
6227 int swapped = 0;
6228
6229 /* Currently we will probably get the wrong result if the individual
6230 comparisons are not simple. This also ensures that it is safe to
6231 reverse a comparison if necessary. */
6232 if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1))
6233 != CCmode)
6234 || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1))
6235 != CCmode))
6236 return CCmode;
6237
6238 /* The if_then_else variant of this tests the second condition if the
6239 first passes, but is true if the first fails. Reverse the first
6240 condition to get a true "inclusive-or" expression. */
6241 if (cond_or == DOM_CC_NX_OR_Y)
6242 cond1 = reverse_condition (cond1);
6243
6244 /* If the comparisons are not equal, and one doesn't dominate the other,
6245 then we can't do this. */
6246 if (cond1 != cond2
6247 && !comparison_dominates_p (cond1, cond2)
6248 && (swapped = 1, !comparison_dominates_p (cond2, cond1)))
6249 return CCmode;
6250
6251 if (swapped)
6252 {
6253 enum rtx_code temp = cond1;
6254 cond1 = cond2;
6255 cond2 = temp;
6256 }
6257
6258 switch (cond1)
6259 {
6260 case EQ:
6261 if (cond2 == EQ || cond_or == DOM_CC_X_AND_Y)
6262 return CC_DEQmode;
6263
6264 switch (cond2)
6265 {
6266 case LE: return CC_DLEmode;
6267 case LEU: return CC_DLEUmode;
6268 case GE: return CC_DGEmode;
6269 case GEU: return CC_DGEUmode;
6270 default: break;
6271 }
6272
6273 break;
6274
6275 case LT:
6276 if (cond2 == LT || cond_or == DOM_CC_X_AND_Y)
6277 return CC_DLTmode;
6278 if (cond2 == LE)
6279 return CC_DLEmode;
6280 if (cond2 == NE)
6281 return CC_DNEmode;
6282 break;
6283
6284 case GT:
6285 if (cond2 == GT || cond_or == DOM_CC_X_AND_Y)
6286 return CC_DGTmode;
6287 if (cond2 == GE)
6288 return CC_DGEmode;
6289 if (cond2 == NE)
6290 return CC_DNEmode;
6291 break;
6292
6293 case LTU:
6294 if (cond2 == LTU || cond_or == DOM_CC_X_AND_Y)
6295 return CC_DLTUmode;
6296 if (cond2 == LEU)
6297 return CC_DLEUmode;
6298 if (cond2 == NE)
6299 return CC_DNEmode;
6300 break;
6301
6302 case GTU:
6303 if (cond2 == GTU || cond_or == DOM_CC_X_AND_Y)
6304 return CC_DGTUmode;
6305 if (cond2 == GEU)
6306 return CC_DGEUmode;
6307 if (cond2 == NE)
6308 return CC_DNEmode;
6309 break;
6310
6311 /* The remaining cases only occur when both comparisons are the
6312 same. */
6313 case NE:
6314 return CC_DNEmode;
6315
6316 case LE:
6317 return CC_DLEmode;
6318
6319 case GE:
6320 return CC_DGEmode;
6321
6322 case LEU:
6323 return CC_DLEUmode;
6324
6325 case GEU:
6326 return CC_DGEUmode;
6327
6328 default:
6329 break;
6330 }
6331
6332 abort ();
6333 }
6334
6335 enum machine_mode
6336 arm_select_cc_mode (enum rtx_code op, rtx x, rtx y)
6337 {
6338 /* All floating point compares return CCFP if it is an equality
6339 comparison, and CCFPE otherwise. */
6340 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
6341 {
6342 switch (op)
6343 {
6344 case EQ:
6345 case NE:
6346 case UNORDERED:
6347 case ORDERED:
6348 case UNLT:
6349 case UNLE:
6350 case UNGT:
6351 case UNGE:
6352 case UNEQ:
6353 case LTGT:
6354 return CCFPmode;
6355
6356 case LT:
6357 case LE:
6358 case GT:
6359 case GE:
6360 if (TARGET_HARD_FLOAT && TARGET_MAVERICK)
6361 return CCFPmode;
6362 return CCFPEmode;
6363
6364 default:
6365 abort ();
6366 }
6367 }
6368
6369 /* A compare with a shifted operand. Because of canonicalization, the
6370 comparison will have to be swapped when we emit the assembler. */
6371 if (GET_MODE (y) == SImode && GET_CODE (y) == REG
6372 && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
6373 || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE
6374 || GET_CODE (x) == ROTATERT))
6375 return CC_SWPmode;
6376
6377 /* This is a special case that is used by combine to allow a
6378 comparison of a shifted byte load to be split into a zero-extend
6379 followed by a comparison of the shifted integer (only valid for
6380 equalities and unsigned inequalities). */
6381 if (GET_MODE (x) == SImode
6382 && GET_CODE (x) == ASHIFT
6383 && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24
6384 && GET_CODE (XEXP (x, 0)) == SUBREG
6385 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM
6386 && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode
6387 && (op == EQ || op == NE
6388 || op == GEU || op == GTU || op == LTU || op == LEU)
6389 && GET_CODE (y) == CONST_INT)
6390 return CC_Zmode;
6391
6392 /* A construct for a conditional compare, if the false arm contains
6393 0, then both conditions must be true, otherwise either condition
6394 must be true. Not all conditions are possible, so CCmode is
6395 returned if it can't be done. */
6396 if (GET_CODE (x) == IF_THEN_ELSE
6397 && (XEXP (x, 2) == const0_rtx
6398 || XEXP (x, 2) == const1_rtx)
6399 && COMPARISON_P (XEXP (x, 0))
6400 && COMPARISON_P (XEXP (x, 1)))
6401 return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1),
6402 INTVAL (XEXP (x, 2)));
6403
6404 /* Alternate canonicalizations of the above. These are somewhat cleaner. */
6405 if (GET_CODE (x) == AND
6406 && COMPARISON_P (XEXP (x, 0))
6407 && COMPARISON_P (XEXP (x, 1)))
6408 return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1),
6409 DOM_CC_X_AND_Y);
6410
6411 if (GET_CODE (x) == IOR
6412 && COMPARISON_P (XEXP (x, 0))
6413 && COMPARISON_P (XEXP (x, 1)))
6414 return arm_select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1),
6415 DOM_CC_X_OR_Y);
6416
6417 /* An operation (on Thumb) where we want to test for a single bit.
6418 This is done by shifting that bit up into the top bit of a
6419 scratch register; we can then branch on the sign bit. */
6420 if (TARGET_THUMB
6421 && GET_MODE (x) == SImode
6422 && (op == EQ || op == NE)
6423 && (GET_CODE (x) == ZERO_EXTRACT))
6424 return CC_Nmode;
6425
6426 /* An operation that sets the condition codes as a side-effect, the
6427 V flag is not set correctly, so we can only use comparisons where
6428 this doesn't matter. (For LT and GE we can use "mi" and "pl"
6429 instead.) */
6430 if (GET_MODE (x) == SImode
6431 && y == const0_rtx
6432 && (op == EQ || op == NE || op == LT || op == GE)
6433 && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
6434 || GET_CODE (x) == AND || GET_CODE (x) == IOR
6435 || GET_CODE (x) == XOR || GET_CODE (x) == MULT
6436 || GET_CODE (x) == NOT || GET_CODE (x) == NEG
6437 || GET_CODE (x) == LSHIFTRT
6438 || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
6439 || GET_CODE (x) == ROTATERT
6440 || (TARGET_ARM && GET_CODE (x) == ZERO_EXTRACT)))
6441 return CC_NOOVmode;
6442
6443 if (GET_MODE (x) == QImode && (op == EQ || op == NE))
6444 return CC_Zmode;
6445
6446 if (GET_MODE (x) == SImode && (op == LTU || op == GEU)
6447 && GET_CODE (x) == PLUS
6448 && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y)))
6449 return CC_Cmode;
6450
6451 return CCmode;
6452 }
6453
6454 /* X and Y are two things to compare using CODE. Emit the compare insn and
6455 return the rtx for register 0 in the proper mode. FP means this is a
6456 floating point compare: I don't think that it is needed on the arm. */
6457 rtx
6458 arm_gen_compare_reg (enum rtx_code code, rtx x, rtx y)
6459 {
6460 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
6461 rtx cc_reg = gen_rtx_REG (mode, CC_REGNUM);
6462
6463 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
6464 gen_rtx_COMPARE (mode, x, y)));
6465
6466 return cc_reg;
6467 }
6468
6469 /* Generate a sequence of insns that will generate the correct return
6470 address mask depending on the physical architecture that the program
6471 is running on. */
6472 rtx
6473 arm_gen_return_addr_mask (void)
6474 {
6475 rtx reg = gen_reg_rtx (Pmode);
6476
6477 emit_insn (gen_return_addr_mask (reg));
6478 return reg;
6479 }
6480
6481 void
6482 arm_reload_in_hi (rtx *operands)
6483 {
6484 rtx ref = operands[1];
6485 rtx base, scratch;
6486 HOST_WIDE_INT offset = 0;
6487
6488 if (GET_CODE (ref) == SUBREG)
6489 {
6490 offset = SUBREG_BYTE (ref);
6491 ref = SUBREG_REG (ref);
6492 }
6493
6494 if (GET_CODE (ref) == REG)
6495 {
6496 /* We have a pseudo which has been spilt onto the stack; there
6497 are two cases here: the first where there is a simple
6498 stack-slot replacement and a second where the stack-slot is
6499 out of range, or is used as a subreg. */
6500 if (reg_equiv_mem[REGNO (ref)])
6501 {
6502 ref = reg_equiv_mem[REGNO (ref)];
6503 base = find_replacement (&XEXP (ref, 0));
6504 }
6505 else
6506 /* The slot is out of range, or was dressed up in a SUBREG. */
6507 base = reg_equiv_address[REGNO (ref)];
6508 }
6509 else
6510 base = find_replacement (&XEXP (ref, 0));
6511
6512 /* Handle the case where the address is too complex to be offset by 1. */
6513 if (GET_CODE (base) == MINUS
6514 || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT))
6515 {
6516 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6517
6518 emit_insn (gen_rtx_SET (VOIDmode, base_plus, base));
6519 base = base_plus;
6520 }
6521 else if (GET_CODE (base) == PLUS)
6522 {
6523 /* The addend must be CONST_INT, or we would have dealt with it above. */
6524 HOST_WIDE_INT hi, lo;
6525
6526 offset += INTVAL (XEXP (base, 1));
6527 base = XEXP (base, 0);
6528
6529 /* Rework the address into a legal sequence of insns. */
6530 /* Valid range for lo is -4095 -> 4095 */
6531 lo = (offset >= 0
6532 ? (offset & 0xfff)
6533 : -((-offset) & 0xfff));
6534
6535 /* Corner case, if lo is the max offset then we would be out of range
6536 once we have added the additional 1 below, so bump the msb into the
6537 pre-loading insn(s). */
6538 if (lo == 4095)
6539 lo &= 0x7ff;
6540
6541 hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff)
6542 ^ (HOST_WIDE_INT) 0x80000000)
6543 - (HOST_WIDE_INT) 0x80000000);
6544
6545 if (hi + lo != offset)
6546 abort ();
6547
6548 if (hi != 0)
6549 {
6550 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6551
6552 /* Get the base address; addsi3 knows how to handle constants
6553 that require more than one insn. */
6554 emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi)));
6555 base = base_plus;
6556 offset = lo;
6557 }
6558 }
6559
6560 /* Operands[2] may overlap operands[0] (though it won't overlap
6561 operands[1]), that's why we asked for a DImode reg -- so we can
6562 use the bit that does not overlap. */
6563 if (REGNO (operands[2]) == REGNO (operands[0]))
6564 scratch = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6565 else
6566 scratch = gen_rtx_REG (SImode, REGNO (operands[2]));
6567
6568 emit_insn (gen_zero_extendqisi2 (scratch,
6569 gen_rtx_MEM (QImode,
6570 plus_constant (base,
6571 offset))));
6572 emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0),
6573 gen_rtx_MEM (QImode,
6574 plus_constant (base,
6575 offset + 1))));
6576 if (!BYTES_BIG_ENDIAN)
6577 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0),
6578 gen_rtx_IOR (SImode,
6579 gen_rtx_ASHIFT
6580 (SImode,
6581 gen_rtx_SUBREG (SImode, operands[0], 0),
6582 GEN_INT (8)),
6583 scratch)));
6584 else
6585 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0),
6586 gen_rtx_IOR (SImode,
6587 gen_rtx_ASHIFT (SImode, scratch,
6588 GEN_INT (8)),
6589 gen_rtx_SUBREG (SImode, operands[0],
6590 0))));
6591 }
6592
6593 /* Handle storing a half-word to memory during reload by synthesizing as two
6594 byte stores. Take care not to clobber the input values until after we
6595 have moved them somewhere safe. This code assumes that if the DImode
6596 scratch in operands[2] overlaps either the input value or output address
6597 in some way, then that value must die in this insn (we absolutely need
6598 two scratch registers for some corner cases). */
6599 void
6600 arm_reload_out_hi (rtx *operands)
6601 {
6602 rtx ref = operands[0];
6603 rtx outval = operands[1];
6604 rtx base, scratch;
6605 HOST_WIDE_INT offset = 0;
6606
6607 if (GET_CODE (ref) == SUBREG)
6608 {
6609 offset = SUBREG_BYTE (ref);
6610 ref = SUBREG_REG (ref);
6611 }
6612
6613 if (GET_CODE (ref) == REG)
6614 {
6615 /* We have a pseudo which has been spilt onto the stack; there
6616 are two cases here: the first where there is a simple
6617 stack-slot replacement and a second where the stack-slot is
6618 out of range, or is used as a subreg. */
6619 if (reg_equiv_mem[REGNO (ref)])
6620 {
6621 ref = reg_equiv_mem[REGNO (ref)];
6622 base = find_replacement (&XEXP (ref, 0));
6623 }
6624 else
6625 /* The slot is out of range, or was dressed up in a SUBREG. */
6626 base = reg_equiv_address[REGNO (ref)];
6627 }
6628 else
6629 base = find_replacement (&XEXP (ref, 0));
6630
6631 scratch = gen_rtx_REG (SImode, REGNO (operands[2]));
6632
6633 /* Handle the case where the address is too complex to be offset by 1. */
6634 if (GET_CODE (base) == MINUS
6635 || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT))
6636 {
6637 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6638
6639 /* Be careful not to destroy OUTVAL. */
6640 if (reg_overlap_mentioned_p (base_plus, outval))
6641 {
6642 /* Updating base_plus might destroy outval, see if we can
6643 swap the scratch and base_plus. */
6644 if (!reg_overlap_mentioned_p (scratch, outval))
6645 {
6646 rtx tmp = scratch;
6647 scratch = base_plus;
6648 base_plus = tmp;
6649 }
6650 else
6651 {
6652 rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2]));
6653
6654 /* Be conservative and copy OUTVAL into the scratch now,
6655 this should only be necessary if outval is a subreg
6656 of something larger than a word. */
6657 /* XXX Might this clobber base? I can't see how it can,
6658 since scratch is known to overlap with OUTVAL, and
6659 must be wider than a word. */
6660 emit_insn (gen_movhi (scratch_hi, outval));
6661 outval = scratch_hi;
6662 }
6663 }
6664
6665 emit_insn (gen_rtx_SET (VOIDmode, base_plus, base));
6666 base = base_plus;
6667 }
6668 else if (GET_CODE (base) == PLUS)
6669 {
6670 /* The addend must be CONST_INT, or we would have dealt with it above. */
6671 HOST_WIDE_INT hi, lo;
6672
6673 offset += INTVAL (XEXP (base, 1));
6674 base = XEXP (base, 0);
6675
6676 /* Rework the address into a legal sequence of insns. */
6677 /* Valid range for lo is -4095 -> 4095 */
6678 lo = (offset >= 0
6679 ? (offset & 0xfff)
6680 : -((-offset) & 0xfff));
6681
6682 /* Corner case, if lo is the max offset then we would be out of range
6683 once we have added the additional 1 below, so bump the msb into the
6684 pre-loading insn(s). */
6685 if (lo == 4095)
6686 lo &= 0x7ff;
6687
6688 hi = ((((offset - lo) & (HOST_WIDE_INT) 0xffffffff)
6689 ^ (HOST_WIDE_INT) 0x80000000)
6690 - (HOST_WIDE_INT) 0x80000000);
6691
6692 if (hi + lo != offset)
6693 abort ();
6694
6695 if (hi != 0)
6696 {
6697 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6698
6699 /* Be careful not to destroy OUTVAL. */
6700 if (reg_overlap_mentioned_p (base_plus, outval))
6701 {
6702 /* Updating base_plus might destroy outval, see if we
6703 can swap the scratch and base_plus. */
6704 if (!reg_overlap_mentioned_p (scratch, outval))
6705 {
6706 rtx tmp = scratch;
6707 scratch = base_plus;
6708 base_plus = tmp;
6709 }
6710 else
6711 {
6712 rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2]));
6713
6714 /* Be conservative and copy outval into scratch now,
6715 this should only be necessary if outval is a
6716 subreg of something larger than a word. */
6717 /* XXX Might this clobber base? I can't see how it
6718 can, since scratch is known to overlap with
6719 outval. */
6720 emit_insn (gen_movhi (scratch_hi, outval));
6721 outval = scratch_hi;
6722 }
6723 }
6724
6725 /* Get the base address; addsi3 knows how to handle constants
6726 that require more than one insn. */
6727 emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi)));
6728 base = base_plus;
6729 offset = lo;
6730 }
6731 }
6732
6733 if (BYTES_BIG_ENDIAN)
6734 {
6735 emit_insn (gen_movqi (gen_rtx_MEM (QImode,
6736 plus_constant (base, offset + 1)),
6737 gen_lowpart (QImode, outval)));
6738 emit_insn (gen_lshrsi3 (scratch,
6739 gen_rtx_SUBREG (SImode, outval, 0),
6740 GEN_INT (8)));
6741 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)),
6742 gen_lowpart (QImode, scratch)));
6743 }
6744 else
6745 {
6746 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)),
6747 gen_lowpart (QImode, outval)));
6748 emit_insn (gen_lshrsi3 (scratch,
6749 gen_rtx_SUBREG (SImode, outval, 0),
6750 GEN_INT (8)));
6751 emit_insn (gen_movqi (gen_rtx_MEM (QImode,
6752 plus_constant (base, offset + 1)),
6753 gen_lowpart (QImode, scratch)));
6754 }
6755 }
6756 \f
6757 /* Print a symbolic form of X to the debug file, F. */
6758 static void
6759 arm_print_value (FILE *f, rtx x)
6760 {
6761 switch (GET_CODE (x))
6762 {
6763 case CONST_INT:
6764 fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
6765 return;
6766
6767 case CONST_DOUBLE:
6768 fprintf (f, "<0x%lx,0x%lx>", (long)XWINT (x, 2), (long)XWINT (x, 3));
6769 return;
6770
6771 case CONST_VECTOR:
6772 {
6773 int i;
6774
6775 fprintf (f, "<");
6776 for (i = 0; i < CONST_VECTOR_NUNITS (x); i++)
6777 {
6778 fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (CONST_VECTOR_ELT (x, i)));
6779 if (i < (CONST_VECTOR_NUNITS (x) - 1))
6780 fputc (',', f);
6781 }
6782 fprintf (f, ">");
6783 }
6784 return;
6785
6786 case CONST_STRING:
6787 fprintf (f, "\"%s\"", XSTR (x, 0));
6788 return;
6789
6790 case SYMBOL_REF:
6791 fprintf (f, "`%s'", XSTR (x, 0));
6792 return;
6793
6794 case LABEL_REF:
6795 fprintf (f, "L%d", INSN_UID (XEXP (x, 0)));
6796 return;
6797
6798 case CONST:
6799 arm_print_value (f, XEXP (x, 0));
6800 return;
6801
6802 case PLUS:
6803 arm_print_value (f, XEXP (x, 0));
6804 fprintf (f, "+");
6805 arm_print_value (f, XEXP (x, 1));
6806 return;
6807
6808 case PC:
6809 fprintf (f, "pc");
6810 return;
6811
6812 default:
6813 fprintf (f, "????");
6814 return;
6815 }
6816 }
6817 \f
6818 /* Routines for manipulation of the constant pool. */
6819
6820 /* Arm instructions cannot load a large constant directly into a
6821 register; they have to come from a pc relative load. The constant
6822 must therefore be placed in the addressable range of the pc
6823 relative load. Depending on the precise pc relative load
6824 instruction the range is somewhere between 256 bytes and 4k. This
6825 means that we often have to dump a constant inside a function, and
6826 generate code to branch around it.
6827
6828 It is important to minimize this, since the branches will slow
6829 things down and make the code larger.
6830
6831 Normally we can hide the table after an existing unconditional
6832 branch so that there is no interruption of the flow, but in the
6833 worst case the code looks like this:
6834
6835 ldr rn, L1
6836 ...
6837 b L2
6838 align
6839 L1: .long value
6840 L2:
6841 ...
6842
6843 ldr rn, L3
6844 ...
6845 b L4
6846 align
6847 L3: .long value
6848 L4:
6849 ...
6850
6851 We fix this by performing a scan after scheduling, which notices
6852 which instructions need to have their operands fetched from the
6853 constant table and builds the table.
6854
6855 The algorithm starts by building a table of all the constants that
6856 need fixing up and all the natural barriers in the function (places
6857 where a constant table can be dropped without breaking the flow).
6858 For each fixup we note how far the pc-relative replacement will be
6859 able to reach and the offset of the instruction into the function.
6860
6861 Having built the table we then group the fixes together to form
6862 tables that are as large as possible (subject to addressing
6863 constraints) and emit each table of constants after the last
6864 barrier that is within range of all the instructions in the group.
6865 If a group does not contain a barrier, then we forcibly create one
6866 by inserting a jump instruction into the flow. Once the table has
6867 been inserted, the insns are then modified to reference the
6868 relevant entry in the pool.
6869
6870 Possible enhancements to the algorithm (not implemented) are:
6871
6872 1) For some processors and object formats, there may be benefit in
6873 aligning the pools to the start of cache lines; this alignment
6874 would need to be taken into account when calculating addressability
6875 of a pool. */
6876
6877 /* These typedefs are located at the start of this file, so that
6878 they can be used in the prototypes there. This comment is to
6879 remind readers of that fact so that the following structures
6880 can be understood more easily.
6881
6882 typedef struct minipool_node Mnode;
6883 typedef struct minipool_fixup Mfix; */
6884
6885 struct minipool_node
6886 {
6887 /* Doubly linked chain of entries. */
6888 Mnode * next;
6889 Mnode * prev;
6890 /* The maximum offset into the code that this entry can be placed. While
6891 pushing fixes for forward references, all entries are sorted in order
6892 of increasing max_address. */
6893 HOST_WIDE_INT max_address;
6894 /* Similarly for an entry inserted for a backwards ref. */
6895 HOST_WIDE_INT min_address;
6896 /* The number of fixes referencing this entry. This can become zero
6897 if we "unpush" an entry. In this case we ignore the entry when we
6898 come to emit the code. */
6899 int refcount;
6900 /* The offset from the start of the minipool. */
6901 HOST_WIDE_INT offset;
6902 /* The value in table. */
6903 rtx value;
6904 /* The mode of value. */
6905 enum machine_mode mode;
6906 /* The size of the value. With iWMMXt enabled
6907 sizes > 4 also imply an alignment of 8-bytes. */
6908 int fix_size;
6909 };
6910
6911 struct minipool_fixup
6912 {
6913 Mfix * next;
6914 rtx insn;
6915 HOST_WIDE_INT address;
6916 rtx * loc;
6917 enum machine_mode mode;
6918 int fix_size;
6919 rtx value;
6920 Mnode * minipool;
6921 HOST_WIDE_INT forwards;
6922 HOST_WIDE_INT backwards;
6923 };
6924
6925 /* Fixes less than a word need padding out to a word boundary. */
6926 #define MINIPOOL_FIX_SIZE(mode) \
6927 (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4)
6928
6929 static Mnode * minipool_vector_head;
6930 static Mnode * minipool_vector_tail;
6931 static rtx minipool_vector_label;
6932
6933 /* The linked list of all minipool fixes required for this function. */
6934 Mfix * minipool_fix_head;
6935 Mfix * minipool_fix_tail;
6936 /* The fix entry for the current minipool, once it has been placed. */
6937 Mfix * minipool_barrier;
6938
6939 /* Determines if INSN is the start of a jump table. Returns the end
6940 of the TABLE or NULL_RTX. */
6941 static rtx
6942 is_jump_table (rtx insn)
6943 {
6944 rtx table;
6945
6946 if (GET_CODE (insn) == JUMP_INSN
6947 && JUMP_LABEL (insn) != NULL
6948 && ((table = next_real_insn (JUMP_LABEL (insn)))
6949 == next_real_insn (insn))
6950 && table != NULL
6951 && GET_CODE (table) == JUMP_INSN
6952 && (GET_CODE (PATTERN (table)) == ADDR_VEC
6953 || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC))
6954 return table;
6955
6956 return NULL_RTX;
6957 }
6958
6959 #ifndef JUMP_TABLES_IN_TEXT_SECTION
6960 #define JUMP_TABLES_IN_TEXT_SECTION 0
6961 #endif
6962
6963 static HOST_WIDE_INT
6964 get_jump_table_size (rtx insn)
6965 {
6966 /* ADDR_VECs only take room if read-only data does into the text
6967 section. */
6968 if (JUMP_TABLES_IN_TEXT_SECTION
6969 #if !defined(READONLY_DATA_SECTION) && !defined(READONLY_DATA_SECTION_ASM_OP)
6970 || 1
6971 #endif
6972 )
6973 {
6974 rtx body = PATTERN (insn);
6975 int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
6976
6977 return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, elt);
6978 }
6979
6980 return 0;
6981 }
6982
6983 /* Move a minipool fix MP from its current location to before MAX_MP.
6984 If MAX_MP is NULL, then MP doesn't need moving, but the addressing
6985 constraints may need updating. */
6986 static Mnode *
6987 move_minipool_fix_forward_ref (Mnode *mp, Mnode *max_mp,
6988 HOST_WIDE_INT max_address)
6989 {
6990 /* This should never be true and the code below assumes these are
6991 different. */
6992 if (mp == max_mp)
6993 abort ();
6994
6995 if (max_mp == NULL)
6996 {
6997 if (max_address < mp->max_address)
6998 mp->max_address = max_address;
6999 }
7000 else
7001 {
7002 if (max_address > max_mp->max_address - mp->fix_size)
7003 mp->max_address = max_mp->max_address - mp->fix_size;
7004 else
7005 mp->max_address = max_address;
7006
7007 /* Unlink MP from its current position. Since max_mp is non-null,
7008 mp->prev must be non-null. */
7009 mp->prev->next = mp->next;
7010 if (mp->next != NULL)
7011 mp->next->prev = mp->prev;
7012 else
7013 minipool_vector_tail = mp->prev;
7014
7015 /* Re-insert it before MAX_MP. */
7016 mp->next = max_mp;
7017 mp->prev = max_mp->prev;
7018 max_mp->prev = mp;
7019
7020 if (mp->prev != NULL)
7021 mp->prev->next = mp;
7022 else
7023 minipool_vector_head = mp;
7024 }
7025
7026 /* Save the new entry. */
7027 max_mp = mp;
7028
7029 /* Scan over the preceding entries and adjust their addresses as
7030 required. */
7031 while (mp->prev != NULL
7032 && mp->prev->max_address > mp->max_address - mp->prev->fix_size)
7033 {
7034 mp->prev->max_address = mp->max_address - mp->prev->fix_size;
7035 mp = mp->prev;
7036 }
7037
7038 return max_mp;
7039 }
7040
7041 /* Add a constant to the minipool for a forward reference. Returns the
7042 node added or NULL if the constant will not fit in this pool. */
7043 static Mnode *
7044 add_minipool_forward_ref (Mfix *fix)
7045 {
7046 /* If set, max_mp is the first pool_entry that has a lower
7047 constraint than the one we are trying to add. */
7048 Mnode * max_mp = NULL;
7049 HOST_WIDE_INT max_address = fix->address + fix->forwards;
7050 Mnode * mp;
7051
7052 /* If this fix's address is greater than the address of the first
7053 entry, then we can't put the fix in this pool. We subtract the
7054 size of the current fix to ensure that if the table is fully
7055 packed we still have enough room to insert this value by suffling
7056 the other fixes forwards. */
7057 if (minipool_vector_head &&
7058 fix->address >= minipool_vector_head->max_address - fix->fix_size)
7059 return NULL;
7060
7061 /* Scan the pool to see if a constant with the same value has
7062 already been added. While we are doing this, also note the
7063 location where we must insert the constant if it doesn't already
7064 exist. */
7065 for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
7066 {
7067 if (GET_CODE (fix->value) == GET_CODE (mp->value)
7068 && fix->mode == mp->mode
7069 && (GET_CODE (fix->value) != CODE_LABEL
7070 || (CODE_LABEL_NUMBER (fix->value)
7071 == CODE_LABEL_NUMBER (mp->value)))
7072 && rtx_equal_p (fix->value, mp->value))
7073 {
7074 /* More than one fix references this entry. */
7075 mp->refcount++;
7076 return move_minipool_fix_forward_ref (mp, max_mp, max_address);
7077 }
7078
7079 /* Note the insertion point if necessary. */
7080 if (max_mp == NULL
7081 && mp->max_address > max_address)
7082 max_mp = mp;
7083
7084 /* If we are inserting an 8-bytes aligned quantity and
7085 we have not already found an insertion point, then
7086 make sure that all such 8-byte aligned quantities are
7087 placed at the start of the pool. */
7088 if (ARM_DOUBLEWORD_ALIGN
7089 && max_mp == NULL
7090 && fix->fix_size == 8
7091 && mp->fix_size != 8)
7092 {
7093 max_mp = mp;
7094 max_address = mp->max_address;
7095 }
7096 }
7097
7098 /* The value is not currently in the minipool, so we need to create
7099 a new entry for it. If MAX_MP is NULL, the entry will be put on
7100 the end of the list since the placement is less constrained than
7101 any existing entry. Otherwise, we insert the new fix before
7102 MAX_MP and, if necessary, adjust the constraints on the other
7103 entries. */
7104 mp = xmalloc (sizeof (* mp));
7105 mp->fix_size = fix->fix_size;
7106 mp->mode = fix->mode;
7107 mp->value = fix->value;
7108 mp->refcount = 1;
7109 /* Not yet required for a backwards ref. */
7110 mp->min_address = -65536;
7111
7112 if (max_mp == NULL)
7113 {
7114 mp->max_address = max_address;
7115 mp->next = NULL;
7116 mp->prev = minipool_vector_tail;
7117
7118 if (mp->prev == NULL)
7119 {
7120 minipool_vector_head = mp;
7121 minipool_vector_label = gen_label_rtx ();
7122 }
7123 else
7124 mp->prev->next = mp;
7125
7126 minipool_vector_tail = mp;
7127 }
7128 else
7129 {
7130 if (max_address > max_mp->max_address - mp->fix_size)
7131 mp->max_address = max_mp->max_address - mp->fix_size;
7132 else
7133 mp->max_address = max_address;
7134
7135 mp->next = max_mp;
7136 mp->prev = max_mp->prev;
7137 max_mp->prev = mp;
7138 if (mp->prev != NULL)
7139 mp->prev->next = mp;
7140 else
7141 minipool_vector_head = mp;
7142 }
7143
7144 /* Save the new entry. */
7145 max_mp = mp;
7146
7147 /* Scan over the preceding entries and adjust their addresses as
7148 required. */
7149 while (mp->prev != NULL
7150 && mp->prev->max_address > mp->max_address - mp->prev->fix_size)
7151 {
7152 mp->prev->max_address = mp->max_address - mp->prev->fix_size;
7153 mp = mp->prev;
7154 }
7155
7156 return max_mp;
7157 }
7158
7159 static Mnode *
7160 move_minipool_fix_backward_ref (Mnode *mp, Mnode *min_mp,
7161 HOST_WIDE_INT min_address)
7162 {
7163 HOST_WIDE_INT offset;
7164
7165 /* This should never be true, and the code below assumes these are
7166 different. */
7167 if (mp == min_mp)
7168 abort ();
7169
7170 if (min_mp == NULL)
7171 {
7172 if (min_address > mp->min_address)
7173 mp->min_address = min_address;
7174 }
7175 else
7176 {
7177 /* We will adjust this below if it is too loose. */
7178 mp->min_address = min_address;
7179
7180 /* Unlink MP from its current position. Since min_mp is non-null,
7181 mp->next must be non-null. */
7182 mp->next->prev = mp->prev;
7183 if (mp->prev != NULL)
7184 mp->prev->next = mp->next;
7185 else
7186 minipool_vector_head = mp->next;
7187
7188 /* Reinsert it after MIN_MP. */
7189 mp->prev = min_mp;
7190 mp->next = min_mp->next;
7191 min_mp->next = mp;
7192 if (mp->next != NULL)
7193 mp->next->prev = mp;
7194 else
7195 minipool_vector_tail = mp;
7196 }
7197
7198 min_mp = mp;
7199
7200 offset = 0;
7201 for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
7202 {
7203 mp->offset = offset;
7204 if (mp->refcount > 0)
7205 offset += mp->fix_size;
7206
7207 if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size)
7208 mp->next->min_address = mp->min_address + mp->fix_size;
7209 }
7210
7211 return min_mp;
7212 }
7213
7214 /* Add a constant to the minipool for a backward reference. Returns the
7215 node added or NULL if the constant will not fit in this pool.
7216
7217 Note that the code for insertion for a backwards reference can be
7218 somewhat confusing because the calculated offsets for each fix do
7219 not take into account the size of the pool (which is still under
7220 construction. */
7221 static Mnode *
7222 add_minipool_backward_ref (Mfix *fix)
7223 {
7224 /* If set, min_mp is the last pool_entry that has a lower constraint
7225 than the one we are trying to add. */
7226 Mnode *min_mp = NULL;
7227 /* This can be negative, since it is only a constraint. */
7228 HOST_WIDE_INT min_address = fix->address - fix->backwards;
7229 Mnode *mp;
7230
7231 /* If we can't reach the current pool from this insn, or if we can't
7232 insert this entry at the end of the pool without pushing other
7233 fixes out of range, then we don't try. This ensures that we
7234 can't fail later on. */
7235 if (min_address >= minipool_barrier->address
7236 || (minipool_vector_tail->min_address + fix->fix_size
7237 >= minipool_barrier->address))
7238 return NULL;
7239
7240 /* Scan the pool to see if a constant with the same value has
7241 already been added. While we are doing this, also note the
7242 location where we must insert the constant if it doesn't already
7243 exist. */
7244 for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev)
7245 {
7246 if (GET_CODE (fix->value) == GET_CODE (mp->value)
7247 && fix->mode == mp->mode
7248 && (GET_CODE (fix->value) != CODE_LABEL
7249 || (CODE_LABEL_NUMBER (fix->value)
7250 == CODE_LABEL_NUMBER (mp->value)))
7251 && rtx_equal_p (fix->value, mp->value)
7252 /* Check that there is enough slack to move this entry to the
7253 end of the table (this is conservative). */
7254 && (mp->max_address
7255 > (minipool_barrier->address
7256 + minipool_vector_tail->offset
7257 + minipool_vector_tail->fix_size)))
7258 {
7259 mp->refcount++;
7260 return move_minipool_fix_backward_ref (mp, min_mp, min_address);
7261 }
7262
7263 if (min_mp != NULL)
7264 mp->min_address += fix->fix_size;
7265 else
7266 {
7267 /* Note the insertion point if necessary. */
7268 if (mp->min_address < min_address)
7269 {
7270 /* For now, we do not allow the insertion of 8-byte alignment
7271 requiring nodes anywhere but at the start of the pool. */
7272 if (ARM_DOUBLEWORD_ALIGN
7273 && fix->fix_size == 8 && mp->fix_size != 8)
7274 return NULL;
7275 else
7276 min_mp = mp;
7277 }
7278 else if (mp->max_address
7279 < minipool_barrier->address + mp->offset + fix->fix_size)
7280 {
7281 /* Inserting before this entry would push the fix beyond
7282 its maximum address (which can happen if we have
7283 re-located a forwards fix); force the new fix to come
7284 after it. */
7285 min_mp = mp;
7286 min_address = mp->min_address + fix->fix_size;
7287 }
7288 /* If we are inserting an 8-bytes aligned quantity and
7289 we have not already found an insertion point, then
7290 make sure that all such 8-byte aligned quantities are
7291 placed at the start of the pool. */
7292 else if (ARM_DOUBLEWORD_ALIGN
7293 && min_mp == NULL
7294 && fix->fix_size == 8
7295 && mp->fix_size < 8)
7296 {
7297 min_mp = mp;
7298 min_address = mp->min_address + fix->fix_size;
7299 }
7300 }
7301 }
7302
7303 /* We need to create a new entry. */
7304 mp = xmalloc (sizeof (* mp));
7305 mp->fix_size = fix->fix_size;
7306 mp->mode = fix->mode;
7307 mp->value = fix->value;
7308 mp->refcount = 1;
7309 mp->max_address = minipool_barrier->address + 65536;
7310
7311 mp->min_address = min_address;
7312
7313 if (min_mp == NULL)
7314 {
7315 mp->prev = NULL;
7316 mp->next = minipool_vector_head;
7317
7318 if (mp->next == NULL)
7319 {
7320 minipool_vector_tail = mp;
7321 minipool_vector_label = gen_label_rtx ();
7322 }
7323 else
7324 mp->next->prev = mp;
7325
7326 minipool_vector_head = mp;
7327 }
7328 else
7329 {
7330 mp->next = min_mp->next;
7331 mp->prev = min_mp;
7332 min_mp->next = mp;
7333
7334 if (mp->next != NULL)
7335 mp->next->prev = mp;
7336 else
7337 minipool_vector_tail = mp;
7338 }
7339
7340 /* Save the new entry. */
7341 min_mp = mp;
7342
7343 if (mp->prev)
7344 mp = mp->prev;
7345 else
7346 mp->offset = 0;
7347
7348 /* Scan over the following entries and adjust their offsets. */
7349 while (mp->next != NULL)
7350 {
7351 if (mp->next->min_address < mp->min_address + mp->fix_size)
7352 mp->next->min_address = mp->min_address + mp->fix_size;
7353
7354 if (mp->refcount)
7355 mp->next->offset = mp->offset + mp->fix_size;
7356 else
7357 mp->next->offset = mp->offset;
7358
7359 mp = mp->next;
7360 }
7361
7362 return min_mp;
7363 }
7364
7365 static void
7366 assign_minipool_offsets (Mfix *barrier)
7367 {
7368 HOST_WIDE_INT offset = 0;
7369 Mnode *mp;
7370
7371 minipool_barrier = barrier;
7372
7373 for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
7374 {
7375 mp->offset = offset;
7376
7377 if (mp->refcount > 0)
7378 offset += mp->fix_size;
7379 }
7380 }
7381
7382 /* Output the literal table */
7383 static void
7384 dump_minipool (rtx scan)
7385 {
7386 Mnode * mp;
7387 Mnode * nmp;
7388 int align64 = 0;
7389
7390 if (ARM_DOUBLEWORD_ALIGN)
7391 for (mp = minipool_vector_head; mp != NULL; mp = mp->next)
7392 if (mp->refcount > 0 && mp->fix_size == 8)
7393 {
7394 align64 = 1;
7395 break;
7396 }
7397
7398 if (dump_file)
7399 fprintf (dump_file,
7400 ";; Emitting minipool after insn %u; address %ld; align %d (bytes)\n",
7401 INSN_UID (scan), (unsigned long) minipool_barrier->address, align64 ? 8 : 4);
7402
7403 scan = emit_label_after (gen_label_rtx (), scan);
7404 scan = emit_insn_after (align64 ? gen_align_8 () : gen_align_4 (), scan);
7405 scan = emit_label_after (minipool_vector_label, scan);
7406
7407 for (mp = minipool_vector_head; mp != NULL; mp = nmp)
7408 {
7409 if (mp->refcount > 0)
7410 {
7411 if (dump_file)
7412 {
7413 fprintf (dump_file,
7414 ";; Offset %u, min %ld, max %ld ",
7415 (unsigned) mp->offset, (unsigned long) mp->min_address,
7416 (unsigned long) mp->max_address);
7417 arm_print_value (dump_file, mp->value);
7418 fputc ('\n', dump_file);
7419 }
7420
7421 switch (mp->fix_size)
7422 {
7423 #ifdef HAVE_consttable_1
7424 case 1:
7425 scan = emit_insn_after (gen_consttable_1 (mp->value), scan);
7426 break;
7427
7428 #endif
7429 #ifdef HAVE_consttable_2
7430 case 2:
7431 scan = emit_insn_after (gen_consttable_2 (mp->value), scan);
7432 break;
7433
7434 #endif
7435 #ifdef HAVE_consttable_4
7436 case 4:
7437 scan = emit_insn_after (gen_consttable_4 (mp->value), scan);
7438 break;
7439
7440 #endif
7441 #ifdef HAVE_consttable_8
7442 case 8:
7443 scan = emit_insn_after (gen_consttable_8 (mp->value), scan);
7444 break;
7445
7446 #endif
7447 default:
7448 abort ();
7449 break;
7450 }
7451 }
7452
7453 nmp = mp->next;
7454 free (mp);
7455 }
7456
7457 minipool_vector_head = minipool_vector_tail = NULL;
7458 scan = emit_insn_after (gen_consttable_end (), scan);
7459 scan = emit_barrier_after (scan);
7460 }
7461
7462 /* Return the cost of forcibly inserting a barrier after INSN. */
7463 static int
7464 arm_barrier_cost (rtx insn)
7465 {
7466 /* Basing the location of the pool on the loop depth is preferable,
7467 but at the moment, the basic block information seems to be
7468 corrupt by this stage of the compilation. */
7469 int base_cost = 50;
7470 rtx next = next_nonnote_insn (insn);
7471
7472 if (next != NULL && GET_CODE (next) == CODE_LABEL)
7473 base_cost -= 20;
7474
7475 switch (GET_CODE (insn))
7476 {
7477 case CODE_LABEL:
7478 /* It will always be better to place the table before the label, rather
7479 than after it. */
7480 return 50;
7481
7482 case INSN:
7483 case CALL_INSN:
7484 return base_cost;
7485
7486 case JUMP_INSN:
7487 return base_cost - 10;
7488
7489 default:
7490 return base_cost + 10;
7491 }
7492 }
7493
7494 /* Find the best place in the insn stream in the range
7495 (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier.
7496 Create the barrier by inserting a jump and add a new fix entry for
7497 it. */
7498 static Mfix *
7499 create_fix_barrier (Mfix *fix, HOST_WIDE_INT max_address)
7500 {
7501 HOST_WIDE_INT count = 0;
7502 rtx barrier;
7503 rtx from = fix->insn;
7504 rtx selected = from;
7505 int selected_cost;
7506 HOST_WIDE_INT selected_address;
7507 Mfix * new_fix;
7508 HOST_WIDE_INT max_count = max_address - fix->address;
7509 rtx label = gen_label_rtx ();
7510
7511 selected_cost = arm_barrier_cost (from);
7512 selected_address = fix->address;
7513
7514 while (from && count < max_count)
7515 {
7516 rtx tmp;
7517 int new_cost;
7518
7519 /* This code shouldn't have been called if there was a natural barrier
7520 within range. */
7521 if (GET_CODE (from) == BARRIER)
7522 abort ();
7523
7524 /* Count the length of this insn. */
7525 count += get_attr_length (from);
7526
7527 /* If there is a jump table, add its length. */
7528 tmp = is_jump_table (from);
7529 if (tmp != NULL)
7530 {
7531 count += get_jump_table_size (tmp);
7532
7533 /* Jump tables aren't in a basic block, so base the cost on
7534 the dispatch insn. If we select this location, we will
7535 still put the pool after the table. */
7536 new_cost = arm_barrier_cost (from);
7537
7538 if (count < max_count && new_cost <= selected_cost)
7539 {
7540 selected = tmp;
7541 selected_cost = new_cost;
7542 selected_address = fix->address + count;
7543 }
7544
7545 /* Continue after the dispatch table. */
7546 from = NEXT_INSN (tmp);
7547 continue;
7548 }
7549
7550 new_cost = arm_barrier_cost (from);
7551
7552 if (count < max_count && new_cost <= selected_cost)
7553 {
7554 selected = from;
7555 selected_cost = new_cost;
7556 selected_address = fix->address + count;
7557 }
7558
7559 from = NEXT_INSN (from);
7560 }
7561
7562 /* Create a new JUMP_INSN that branches around a barrier. */
7563 from = emit_jump_insn_after (gen_jump (label), selected);
7564 JUMP_LABEL (from) = label;
7565 barrier = emit_barrier_after (from);
7566 emit_label_after (label, barrier);
7567
7568 /* Create a minipool barrier entry for the new barrier. */
7569 new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* new_fix));
7570 new_fix->insn = barrier;
7571 new_fix->address = selected_address;
7572 new_fix->next = fix->next;
7573 fix->next = new_fix;
7574
7575 return new_fix;
7576 }
7577
7578 /* Record that there is a natural barrier in the insn stream at
7579 ADDRESS. */
7580 static void
7581 push_minipool_barrier (rtx insn, HOST_WIDE_INT address)
7582 {
7583 Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix));
7584
7585 fix->insn = insn;
7586 fix->address = address;
7587
7588 fix->next = NULL;
7589 if (minipool_fix_head != NULL)
7590 minipool_fix_tail->next = fix;
7591 else
7592 minipool_fix_head = fix;
7593
7594 minipool_fix_tail = fix;
7595 }
7596
7597 /* Record INSN, which will need fixing up to load a value from the
7598 minipool. ADDRESS is the offset of the insn since the start of the
7599 function; LOC is a pointer to the part of the insn which requires
7600 fixing; VALUE is the constant that must be loaded, which is of type
7601 MODE. */
7602 static void
7603 push_minipool_fix (rtx insn, HOST_WIDE_INT address, rtx *loc,
7604 enum machine_mode mode, rtx value)
7605 {
7606 Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix));
7607
7608 #ifdef AOF_ASSEMBLER
7609 /* PIC symbol references need to be converted into offsets into the
7610 based area. */
7611 /* XXX This shouldn't be done here. */
7612 if (flag_pic && GET_CODE (value) == SYMBOL_REF)
7613 value = aof_pic_entry (value);
7614 #endif /* AOF_ASSEMBLER */
7615
7616 fix->insn = insn;
7617 fix->address = address;
7618 fix->loc = loc;
7619 fix->mode = mode;
7620 fix->fix_size = MINIPOOL_FIX_SIZE (mode);
7621 fix->value = value;
7622 fix->forwards = get_attr_pool_range (insn);
7623 fix->backwards = get_attr_neg_pool_range (insn);
7624 fix->minipool = NULL;
7625
7626 /* If an insn doesn't have a range defined for it, then it isn't
7627 expecting to be reworked by this code. Better to abort now than
7628 to generate duff assembly code. */
7629 if (fix->forwards == 0 && fix->backwards == 0)
7630 abort ();
7631
7632 /* With AAPCS/iWMMXt enabled, the pool is aligned to an 8-byte boundary.
7633 So there might be an empty word before the start of the pool.
7634 Hence we reduce the forward range by 4 to allow for this
7635 possibility. */
7636 if (ARM_DOUBLEWORD_ALIGN && fix->fix_size == 8)
7637 fix->forwards -= 4;
7638
7639 if (dump_file)
7640 {
7641 fprintf (dump_file,
7642 ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ",
7643 GET_MODE_NAME (mode),
7644 INSN_UID (insn), (unsigned long) address,
7645 -1 * (long)fix->backwards, (long)fix->forwards);
7646 arm_print_value (dump_file, fix->value);
7647 fprintf (dump_file, "\n");
7648 }
7649
7650 /* Add it to the chain of fixes. */
7651 fix->next = NULL;
7652
7653 if (minipool_fix_head != NULL)
7654 minipool_fix_tail->next = fix;
7655 else
7656 minipool_fix_head = fix;
7657
7658 minipool_fix_tail = fix;
7659 }
7660
7661 /* Scan INSN and note any of its operands that need fixing.
7662 If DO_PUSHES is false we do not actually push any of the fixups
7663 needed. The function returns TRUE is any fixups were needed/pushed.
7664 This is used by arm_memory_load_p() which needs to know about loads
7665 of constants that will be converted into minipool loads. */
7666 static bool
7667 note_invalid_constants (rtx insn, HOST_WIDE_INT address, int do_pushes)
7668 {
7669 bool result = false;
7670 int opno;
7671
7672 extract_insn (insn);
7673
7674 if (!constrain_operands (1))
7675 fatal_insn_not_found (insn);
7676
7677 if (recog_data.n_alternatives == 0)
7678 return false;
7679
7680 /* Fill in recog_op_alt with information about the constraints of this insn. */
7681 preprocess_constraints ();
7682
7683 for (opno = 0; opno < recog_data.n_operands; opno++)
7684 {
7685 /* Things we need to fix can only occur in inputs. */
7686 if (recog_data.operand_type[opno] != OP_IN)
7687 continue;
7688
7689 /* If this alternative is a memory reference, then any mention
7690 of constants in this alternative is really to fool reload
7691 into allowing us to accept one there. We need to fix them up
7692 now so that we output the right code. */
7693 if (recog_op_alt[opno][which_alternative].memory_ok)
7694 {
7695 rtx op = recog_data.operand[opno];
7696
7697 if (CONSTANT_P (op))
7698 {
7699 if (do_pushes)
7700 push_minipool_fix (insn, address, recog_data.operand_loc[opno],
7701 recog_data.operand_mode[opno], op);
7702 result = true;
7703 }
7704 else if (GET_CODE (op) == MEM
7705 && GET_CODE (XEXP (op, 0)) == SYMBOL_REF
7706 && CONSTANT_POOL_ADDRESS_P (XEXP (op, 0)))
7707 {
7708 if (do_pushes)
7709 {
7710 rtx cop = avoid_constant_pool_reference (op);
7711
7712 /* Casting the address of something to a mode narrower
7713 than a word can cause avoid_constant_pool_reference()
7714 to return the pool reference itself. That's no good to
7715 us here. Lets just hope that we can use the
7716 constant pool value directly. */
7717 if (op == cop)
7718 cop = get_pool_constant (XEXP (op, 0));
7719
7720 push_minipool_fix (insn, address,
7721 recog_data.operand_loc[opno],
7722 recog_data.operand_mode[opno], cop);
7723 }
7724
7725 result = true;
7726 }
7727 }
7728 }
7729
7730 return result;
7731 }
7732
7733 /* Gcc puts the pool in the wrong place for ARM, since we can only
7734 load addresses a limited distance around the pc. We do some
7735 special munging to move the constant pool values to the correct
7736 point in the code. */
7737 static void
7738 arm_reorg (void)
7739 {
7740 rtx insn;
7741 HOST_WIDE_INT address = 0;
7742 Mfix * fix;
7743
7744 minipool_fix_head = minipool_fix_tail = NULL;
7745
7746 /* The first insn must always be a note, or the code below won't
7747 scan it properly. */
7748 insn = get_insns ();
7749 if (GET_CODE (insn) != NOTE)
7750 abort ();
7751
7752 /* Scan all the insns and record the operands that will need fixing. */
7753 for (insn = next_nonnote_insn (insn); insn; insn = next_nonnote_insn (insn))
7754 {
7755 if (TARGET_CIRRUS_FIX_INVALID_INSNS
7756 && (arm_cirrus_insn_p (insn)
7757 || GET_CODE (insn) == JUMP_INSN
7758 || arm_memory_load_p (insn)))
7759 cirrus_reorg (insn);
7760
7761 if (GET_CODE (insn) == BARRIER)
7762 push_minipool_barrier (insn, address);
7763 else if (INSN_P (insn))
7764 {
7765 rtx table;
7766
7767 note_invalid_constants (insn, address, true);
7768 address += get_attr_length (insn);
7769
7770 /* If the insn is a vector jump, add the size of the table
7771 and skip the table. */
7772 if ((table = is_jump_table (insn)) != NULL)
7773 {
7774 address += get_jump_table_size (table);
7775 insn = table;
7776 }
7777 }
7778 }
7779
7780 fix = minipool_fix_head;
7781
7782 /* Now scan the fixups and perform the required changes. */
7783 while (fix)
7784 {
7785 Mfix * ftmp;
7786 Mfix * fdel;
7787 Mfix * last_added_fix;
7788 Mfix * last_barrier = NULL;
7789 Mfix * this_fix;
7790
7791 /* Skip any further barriers before the next fix. */
7792 while (fix && GET_CODE (fix->insn) == BARRIER)
7793 fix = fix->next;
7794
7795 /* No more fixes. */
7796 if (fix == NULL)
7797 break;
7798
7799 last_added_fix = NULL;
7800
7801 for (ftmp = fix; ftmp; ftmp = ftmp->next)
7802 {
7803 if (GET_CODE (ftmp->insn) == BARRIER)
7804 {
7805 if (ftmp->address >= minipool_vector_head->max_address)
7806 break;
7807
7808 last_barrier = ftmp;
7809 }
7810 else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL)
7811 break;
7812
7813 last_added_fix = ftmp; /* Keep track of the last fix added. */
7814 }
7815
7816 /* If we found a barrier, drop back to that; any fixes that we
7817 could have reached but come after the barrier will now go in
7818 the next mini-pool. */
7819 if (last_barrier != NULL)
7820 {
7821 /* Reduce the refcount for those fixes that won't go into this
7822 pool after all. */
7823 for (fdel = last_barrier->next;
7824 fdel && fdel != ftmp;
7825 fdel = fdel->next)
7826 {
7827 fdel->minipool->refcount--;
7828 fdel->minipool = NULL;
7829 }
7830
7831 ftmp = last_barrier;
7832 }
7833 else
7834 {
7835 /* ftmp is first fix that we can't fit into this pool and
7836 there no natural barriers that we could use. Insert a
7837 new barrier in the code somewhere between the previous
7838 fix and this one, and arrange to jump around it. */
7839 HOST_WIDE_INT max_address;
7840
7841 /* The last item on the list of fixes must be a barrier, so
7842 we can never run off the end of the list of fixes without
7843 last_barrier being set. */
7844 if (ftmp == NULL)
7845 abort ();
7846
7847 max_address = minipool_vector_head->max_address;
7848 /* Check that there isn't another fix that is in range that
7849 we couldn't fit into this pool because the pool was
7850 already too large: we need to put the pool before such an
7851 instruction. */
7852 if (ftmp->address < max_address)
7853 max_address = ftmp->address;
7854
7855 last_barrier = create_fix_barrier (last_added_fix, max_address);
7856 }
7857
7858 assign_minipool_offsets (last_barrier);
7859
7860 while (ftmp)
7861 {
7862 if (GET_CODE (ftmp->insn) != BARRIER
7863 && ((ftmp->minipool = add_minipool_backward_ref (ftmp))
7864 == NULL))
7865 break;
7866
7867 ftmp = ftmp->next;
7868 }
7869
7870 /* Scan over the fixes we have identified for this pool, fixing them
7871 up and adding the constants to the pool itself. */
7872 for (this_fix = fix; this_fix && ftmp != this_fix;
7873 this_fix = this_fix->next)
7874 if (GET_CODE (this_fix->insn) != BARRIER)
7875 {
7876 rtx addr
7877 = plus_constant (gen_rtx_LABEL_REF (VOIDmode,
7878 minipool_vector_label),
7879 this_fix->minipool->offset);
7880 *this_fix->loc = gen_rtx_MEM (this_fix->mode, addr);
7881 }
7882
7883 dump_minipool (last_barrier->insn);
7884 fix = ftmp;
7885 }
7886
7887 /* From now on we must synthesize any constants that we can't handle
7888 directly. This can happen if the RTL gets split during final
7889 instruction generation. */
7890 after_arm_reorg = 1;
7891
7892 /* Free the minipool memory. */
7893 obstack_free (&minipool_obstack, minipool_startobj);
7894 }
7895 \f
7896 /* Routines to output assembly language. */
7897
7898 /* If the rtx is the correct value then return the string of the number.
7899 In this way we can ensure that valid double constants are generated even
7900 when cross compiling. */
7901 const char *
7902 fp_immediate_constant (rtx x)
7903 {
7904 REAL_VALUE_TYPE r;
7905 int i;
7906
7907 if (!fp_consts_inited)
7908 init_fp_table ();
7909
7910 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
7911 for (i = 0; i < 8; i++)
7912 if (REAL_VALUES_EQUAL (r, values_fp[i]))
7913 return strings_fp[i];
7914
7915 abort ();
7916 }
7917
7918 /* As for fp_immediate_constant, but value is passed directly, not in rtx. */
7919 static const char *
7920 fp_const_from_val (REAL_VALUE_TYPE *r)
7921 {
7922 int i;
7923
7924 if (!fp_consts_inited)
7925 init_fp_table ();
7926
7927 for (i = 0; i < 8; i++)
7928 if (REAL_VALUES_EQUAL (*r, values_fp[i]))
7929 return strings_fp[i];
7930
7931 abort ();
7932 }
7933
7934 /* Output the operands of a LDM/STM instruction to STREAM.
7935 MASK is the ARM register set mask of which only bits 0-15 are important.
7936 REG is the base register, either the frame pointer or the stack pointer,
7937 INSTR is the possibly suffixed load or store instruction. */
7938 static void
7939 print_multi_reg (FILE *stream, const char *instr, int reg, int mask)
7940 {
7941 int i;
7942 int not_first = FALSE;
7943
7944 fputc ('\t', stream);
7945 asm_fprintf (stream, instr, reg);
7946 fputs (", {", stream);
7947
7948 for (i = 0; i <= LAST_ARM_REGNUM; i++)
7949 if (mask & (1 << i))
7950 {
7951 if (not_first)
7952 fprintf (stream, ", ");
7953
7954 asm_fprintf (stream, "%r", i);
7955 not_first = TRUE;
7956 }
7957
7958 fprintf (stream, "}\n");
7959 }
7960
7961
7962 /* Output a FLDMX instruction to STREAM.
7963 BASE if the register containing the address.
7964 REG and COUNT specify the register range.
7965 Extra registers may be added to avoid hardware bugs. */
7966
7967 static void
7968 arm_output_fldmx (FILE * stream, unsigned int base, int reg, int count)
7969 {
7970 int i;
7971
7972 /* Workaround ARM10 VFPr1 bug. */
7973 if (count == 2 && !arm_arch6)
7974 {
7975 if (reg == 15)
7976 reg--;
7977 count++;
7978 }
7979
7980 fputc ('\t', stream);
7981 asm_fprintf (stream, "fldmfdx\t%r!, {", base);
7982
7983 for (i = reg; i < reg + count; i++)
7984 {
7985 if (i > reg)
7986 fputs (", ", stream);
7987 asm_fprintf (stream, "d%d", i);
7988 }
7989 fputs ("}\n", stream);
7990
7991 }
7992
7993
7994 /* Output the assembly for a store multiple. */
7995
7996 const char *
7997 vfp_output_fstmx (rtx * operands)
7998 {
7999 char pattern[100];
8000 int p;
8001 int base;
8002 int i;
8003
8004 strcpy (pattern, "fstmfdx\t%m0!, {%P1");
8005 p = strlen (pattern);
8006
8007 if (GET_CODE (operands[1]) != REG)
8008 abort ();
8009
8010 base = (REGNO (operands[1]) - FIRST_VFP_REGNUM) / 2;
8011 for (i = 1; i < XVECLEN (operands[2], 0); i++)
8012 {
8013 p += sprintf (&pattern[p], ", d%d", base + i);
8014 }
8015 strcpy (&pattern[p], "}");
8016
8017 output_asm_insn (pattern, operands);
8018 return "";
8019 }
8020
8021
8022 /* Emit RTL to save block of VFP register pairs to the stack. Returns the
8023 number of bytes pushed. */
8024
8025 static int
8026 vfp_emit_fstmx (int base_reg, int count)
8027 {
8028 rtx par;
8029 rtx dwarf;
8030 rtx tmp, reg;
8031 int i;
8032
8033 /* Workaround ARM10 VFPr1 bug. Data corruption can occur when exactly two
8034 register pairs are stored by a store multiple insn. We avoid this
8035 by pushing an extra pair. */
8036 if (count == 2 && !arm_arch6)
8037 {
8038 if (base_reg == LAST_VFP_REGNUM - 3)
8039 base_reg -= 2;
8040 count++;
8041 }
8042
8043 /* ??? The frame layout is implementation defined. We describe
8044 standard format 1 (equivalent to a FSTMD insn and unused pad word).
8045 We really need some way of representing the whole block so that the
8046 unwinder can figure it out at runtime. */
8047 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8048 dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1));
8049
8050 reg = gen_rtx_REG (DFmode, base_reg);
8051 base_reg += 2;
8052
8053 XVECEXP (par, 0, 0)
8054 = gen_rtx_SET (VOIDmode,
8055 gen_rtx_MEM (BLKmode,
8056 gen_rtx_PRE_DEC (BLKmode, stack_pointer_rtx)),
8057 gen_rtx_UNSPEC (BLKmode,
8058 gen_rtvec (1, reg),
8059 UNSPEC_PUSH_MULT));
8060
8061 tmp = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
8062 gen_rtx_PLUS (SImode, stack_pointer_rtx,
8063 GEN_INT (-(count * 8 + 4))));
8064 RTX_FRAME_RELATED_P (tmp) = 1;
8065 XVECEXP (dwarf, 0, 0) = tmp;
8066
8067 tmp = gen_rtx_SET (VOIDmode,
8068 gen_rtx_MEM (DFmode, stack_pointer_rtx),
8069 reg);
8070 RTX_FRAME_RELATED_P (tmp) = 1;
8071 XVECEXP (dwarf, 0, 1) = tmp;
8072
8073 for (i = 1; i < count; i++)
8074 {
8075 reg = gen_rtx_REG (DFmode, base_reg);
8076 base_reg += 2;
8077 XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg);
8078
8079 tmp = gen_rtx_SET (VOIDmode,
8080 gen_rtx_MEM (DFmode,
8081 gen_rtx_PLUS (SImode,
8082 stack_pointer_rtx,
8083 GEN_INT (i * 8))),
8084 reg);
8085 RTX_FRAME_RELATED_P (tmp) = 1;
8086 XVECEXP (dwarf, 0, i + 1) = tmp;
8087 }
8088
8089 par = emit_insn (par);
8090 REG_NOTES (par) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
8091 REG_NOTES (par));
8092 RTX_FRAME_RELATED_P (par) = 1;
8093
8094 return count * 8 + 4;
8095 }
8096
8097
8098 /* Output a 'call' insn. */
8099 const char *
8100 output_call (rtx *operands)
8101 {
8102 if (arm_arch5)
8103 abort (); /* Patterns should call blx <reg> directly. */
8104
8105 /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
8106 if (REGNO (operands[0]) == LR_REGNUM)
8107 {
8108 operands[0] = gen_rtx_REG (SImode, IP_REGNUM);
8109 output_asm_insn ("mov%?\t%0, %|lr", operands);
8110 }
8111
8112 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
8113
8114 if (TARGET_INTERWORK || arm_arch4t)
8115 output_asm_insn ("bx%?\t%0", operands);
8116 else
8117 output_asm_insn ("mov%?\t%|pc, %0", operands);
8118
8119 return "";
8120 }
8121
8122 /* Output a 'call' insn that is a reference in memory. */
8123 const char *
8124 output_call_mem (rtx *operands)
8125 {
8126 if (TARGET_INTERWORK && !arm_arch5)
8127 {
8128 output_asm_insn ("ldr%?\t%|ip, %0", operands);
8129 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
8130 output_asm_insn ("bx%?\t%|ip", operands);
8131 }
8132 else if (regno_use_in (LR_REGNUM, operands[0]))
8133 {
8134 /* LR is used in the memory address. We load the address in the
8135 first instruction. It's safe to use IP as the target of the
8136 load since the call will kill it anyway. */
8137 output_asm_insn ("ldr%?\t%|ip, %0", operands);
8138 if (arm_arch5)
8139 output_asm_insn ("blx%?%|ip", operands);
8140 else
8141 {
8142 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
8143 if (arm_arch4t)
8144 output_asm_insn ("bx%?\t%|ip", operands);
8145 else
8146 output_asm_insn ("mov%?\t%|pc, %|ip", operands);
8147 }
8148 }
8149 else
8150 {
8151 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
8152 output_asm_insn ("ldr%?\t%|pc, %0", operands);
8153 }
8154
8155 return "";
8156 }
8157
8158
8159 /* Output a move from arm registers to an fpa registers.
8160 OPERANDS[0] is an fpa register.
8161 OPERANDS[1] is the first registers of an arm register pair. */
8162 const char *
8163 output_mov_long_double_fpa_from_arm (rtx *operands)
8164 {
8165 int arm_reg0 = REGNO (operands[1]);
8166 rtx ops[3];
8167
8168 if (arm_reg0 == IP_REGNUM)
8169 abort ();
8170
8171 ops[0] = gen_rtx_REG (SImode, arm_reg0);
8172 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
8173 ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0);
8174
8175 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops);
8176 output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands);
8177
8178 return "";
8179 }
8180
8181 /* Output a move from an fpa register to arm registers.
8182 OPERANDS[0] is the first registers of an arm register pair.
8183 OPERANDS[1] is an fpa register. */
8184 const char *
8185 output_mov_long_double_arm_from_fpa (rtx *operands)
8186 {
8187 int arm_reg0 = REGNO (operands[0]);
8188 rtx ops[3];
8189
8190 if (arm_reg0 == IP_REGNUM)
8191 abort ();
8192
8193 ops[0] = gen_rtx_REG (SImode, arm_reg0);
8194 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
8195 ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0);
8196
8197 output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands);
8198 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops);
8199 return "";
8200 }
8201
8202 /* Output a move from arm registers to arm registers of a long double
8203 OPERANDS[0] is the destination.
8204 OPERANDS[1] is the source. */
8205 const char *
8206 output_mov_long_double_arm_from_arm (rtx *operands)
8207 {
8208 /* We have to be careful here because the two might overlap. */
8209 int dest_start = REGNO (operands[0]);
8210 int src_start = REGNO (operands[1]);
8211 rtx ops[2];
8212 int i;
8213
8214 if (dest_start < src_start)
8215 {
8216 for (i = 0; i < 3; i++)
8217 {
8218 ops[0] = gen_rtx_REG (SImode, dest_start + i);
8219 ops[1] = gen_rtx_REG (SImode, src_start + i);
8220 output_asm_insn ("mov%?\t%0, %1", ops);
8221 }
8222 }
8223 else
8224 {
8225 for (i = 2; i >= 0; i--)
8226 {
8227 ops[0] = gen_rtx_REG (SImode, dest_start + i);
8228 ops[1] = gen_rtx_REG (SImode, src_start + i);
8229 output_asm_insn ("mov%?\t%0, %1", ops);
8230 }
8231 }
8232
8233 return "";
8234 }
8235
8236
8237 /* Output a move from arm registers to an fpa registers.
8238 OPERANDS[0] is an fpa register.
8239 OPERANDS[1] is the first registers of an arm register pair. */
8240 const char *
8241 output_mov_double_fpa_from_arm (rtx *operands)
8242 {
8243 int arm_reg0 = REGNO (operands[1]);
8244 rtx ops[2];
8245
8246 if (arm_reg0 == IP_REGNUM)
8247 abort ();
8248
8249 ops[0] = gen_rtx_REG (SImode, arm_reg0);
8250 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
8251 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops);
8252 output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands);
8253 return "";
8254 }
8255
8256 /* Output a move from an fpa register to arm registers.
8257 OPERANDS[0] is the first registers of an arm register pair.
8258 OPERANDS[1] is an fpa register. */
8259 const char *
8260 output_mov_double_arm_from_fpa (rtx *operands)
8261 {
8262 int arm_reg0 = REGNO (operands[0]);
8263 rtx ops[2];
8264
8265 if (arm_reg0 == IP_REGNUM)
8266 abort ();
8267
8268 ops[0] = gen_rtx_REG (SImode, arm_reg0);
8269 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
8270 output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands);
8271 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops);
8272 return "";
8273 }
8274
8275 /* Output a move between double words.
8276 It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM
8277 or MEM<-REG and all MEMs must be offsettable addresses. */
8278 const char *
8279 output_move_double (rtx *operands)
8280 {
8281 enum rtx_code code0 = GET_CODE (operands[0]);
8282 enum rtx_code code1 = GET_CODE (operands[1]);
8283 rtx otherops[3];
8284
8285 if (code0 == REG)
8286 {
8287 int reg0 = REGNO (operands[0]);
8288
8289 otherops[0] = gen_rtx_REG (SImode, 1 + reg0);
8290
8291 if (code1 == REG)
8292 {
8293 int reg1 = REGNO (operands[1]);
8294 if (reg1 == IP_REGNUM)
8295 abort ();
8296
8297 /* Ensure the second source is not overwritten. */
8298 if (reg1 == reg0 + (WORDS_BIG_ENDIAN ? -1 : 1))
8299 output_asm_insn ("mov%?\t%Q0, %Q1\n\tmov%?\t%R0, %R1", operands);
8300 else
8301 output_asm_insn ("mov%?\t%R0, %R1\n\tmov%?\t%Q0, %Q1", operands);
8302 }
8303 else if (code1 == CONST_VECTOR)
8304 {
8305 HOST_WIDE_INT hint = 0;
8306
8307 switch (GET_MODE (operands[1]))
8308 {
8309 case V2SImode:
8310 otherops[1] = GEN_INT (INTVAL (CONST_VECTOR_ELT (operands[1], 1)));
8311 operands[1] = GEN_INT (INTVAL (CONST_VECTOR_ELT (operands[1], 0)));
8312 break;
8313
8314 case V4HImode:
8315 if (BYTES_BIG_ENDIAN)
8316 {
8317 hint = INTVAL (CONST_VECTOR_ELT (operands[1], 2));
8318 hint <<= 16;
8319 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 3));
8320 }
8321 else
8322 {
8323 hint = INTVAL (CONST_VECTOR_ELT (operands[1], 3));
8324 hint <<= 16;
8325 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 2));
8326 }
8327
8328 otherops[1] = GEN_INT (hint);
8329 hint = 0;
8330
8331 if (BYTES_BIG_ENDIAN)
8332 {
8333 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 0));
8334 hint <<= 16;
8335 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 1));
8336 }
8337 else
8338 {
8339 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 1));
8340 hint <<= 16;
8341 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 0));
8342 }
8343
8344 operands[1] = GEN_INT (hint);
8345 break;
8346
8347 case V8QImode:
8348 if (BYTES_BIG_ENDIAN)
8349 {
8350 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 4));
8351 hint <<= 8;
8352 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 5));
8353 hint <<= 8;
8354 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 6));
8355 hint <<= 8;
8356 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 7));
8357 }
8358 else
8359 {
8360 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 7));
8361 hint <<= 8;
8362 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 6));
8363 hint <<= 8;
8364 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 5));
8365 hint <<= 8;
8366 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 4));
8367 }
8368
8369 otherops[1] = GEN_INT (hint);
8370 hint = 0;
8371
8372 if (BYTES_BIG_ENDIAN)
8373 {
8374 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 0));
8375 hint <<= 8;
8376 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 1));
8377 hint <<= 8;
8378 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 2));
8379 hint <<= 8;
8380 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 3));
8381 }
8382 else
8383 {
8384 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 3));
8385 hint <<= 8;
8386 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 2));
8387 hint <<= 8;
8388 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 1));
8389 hint <<= 8;
8390 hint |= INTVAL (CONST_VECTOR_ELT (operands[1], 0));
8391 }
8392
8393 operands[1] = GEN_INT (hint);
8394 break;
8395
8396 default:
8397 abort ();
8398 }
8399 output_mov_immediate (operands);
8400 output_mov_immediate (otherops);
8401 }
8402 else if (code1 == CONST_DOUBLE)
8403 {
8404 if (GET_MODE (operands[1]) == DFmode)
8405 {
8406 REAL_VALUE_TYPE r;
8407 long l[2];
8408
8409 REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
8410 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
8411 otherops[1] = GEN_INT (l[1]);
8412 operands[1] = GEN_INT (l[0]);
8413 }
8414 else if (GET_MODE (operands[1]) != VOIDmode)
8415 abort ();
8416 else if (WORDS_BIG_ENDIAN)
8417 {
8418 otherops[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8419 operands[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8420 }
8421 else
8422 {
8423 otherops[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8424 operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8425 }
8426
8427 output_mov_immediate (operands);
8428 output_mov_immediate (otherops);
8429 }
8430 else if (code1 == CONST_INT)
8431 {
8432 #if HOST_BITS_PER_WIDE_INT > 32
8433 /* If HOST_WIDE_INT is more than 32 bits, the intval tells us
8434 what the upper word is. */
8435 if (WORDS_BIG_ENDIAN)
8436 {
8437 otherops[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
8438 operands[1] = GEN_INT (INTVAL (operands[1]) >> 32);
8439 }
8440 else
8441 {
8442 otherops[1] = GEN_INT (INTVAL (operands[1]) >> 32);
8443 operands[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
8444 }
8445 #else
8446 /* Sign extend the intval into the high-order word. */
8447 if (WORDS_BIG_ENDIAN)
8448 {
8449 otherops[1] = operands[1];
8450 operands[1] = (INTVAL (operands[1]) < 0
8451 ? constm1_rtx : const0_rtx);
8452 }
8453 else
8454 otherops[1] = INTVAL (operands[1]) < 0 ? constm1_rtx : const0_rtx;
8455 #endif
8456 output_mov_immediate (otherops);
8457 output_mov_immediate (operands);
8458 }
8459 else if (code1 == MEM)
8460 {
8461 switch (GET_CODE (XEXP (operands[1], 0)))
8462 {
8463 case REG:
8464 output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
8465 break;
8466
8467 case PRE_INC:
8468 if (!TARGET_LDRD)
8469 abort (); /* Should never happen now. */
8470 output_asm_insn ("ldr%?d\t%0, [%m1, #8]!", operands);
8471 break;
8472
8473 case PRE_DEC:
8474 output_asm_insn ("ldm%?db\t%m1!, %M0", operands);
8475 break;
8476
8477 case POST_INC:
8478 output_asm_insn ("ldm%?ia\t%m1!, %M0", operands);
8479 break;
8480
8481 case POST_DEC:
8482 if (!TARGET_LDRD)
8483 abort (); /* Should never happen now. */
8484 output_asm_insn ("ldr%?d\t%0, [%m1], #-8", operands);
8485 break;
8486
8487 case PRE_MODIFY:
8488 case POST_MODIFY:
8489 otherops[0] = operands[0];
8490 otherops[1] = XEXP (XEXP (XEXP (operands[1], 0), 1), 0);
8491 otherops[2] = XEXP (XEXP (XEXP (operands[1], 0), 1), 1);
8492
8493 if (GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY)
8494 {
8495 if (reg_overlap_mentioned_p (otherops[0], otherops[2]))
8496 {
8497 /* Registers overlap so split out the increment. */
8498 output_asm_insn ("add%?\t%1, %1, %2", otherops);
8499 output_asm_insn ("ldr%?d\t%0, [%1] @split", otherops);
8500 }
8501 else
8502 output_asm_insn ("ldr%?d\t%0, [%1, %2]!", otherops);
8503 }
8504 else
8505 {
8506 /* We only allow constant increments, so this is safe. */
8507 output_asm_insn ("ldr%?d\t%0, [%1], %2", otherops);
8508 }
8509 break;
8510
8511 case LABEL_REF:
8512 case CONST:
8513 output_asm_insn ("adr%?\t%0, %1", operands);
8514 output_asm_insn ("ldm%?ia\t%0, %M0", operands);
8515 break;
8516
8517 default:
8518 if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1),
8519 GET_MODE (XEXP (XEXP (operands[1], 0), 1))))
8520 {
8521 otherops[0] = operands[0];
8522 otherops[1] = XEXP (XEXP (operands[1], 0), 0);
8523 otherops[2] = XEXP (XEXP (operands[1], 0), 1);
8524
8525 if (GET_CODE (XEXP (operands[1], 0)) == PLUS)
8526 {
8527 if (GET_CODE (otherops[2]) == CONST_INT)
8528 {
8529 switch ((int) INTVAL (otherops[2]))
8530 {
8531 case -8:
8532 output_asm_insn ("ldm%?db\t%1, %M0", otherops);
8533 return "";
8534 case -4:
8535 output_asm_insn ("ldm%?da\t%1, %M0", otherops);
8536 return "";
8537 case 4:
8538 output_asm_insn ("ldm%?ib\t%1, %M0", otherops);
8539 return "";
8540 }
8541 }
8542 if (TARGET_LDRD
8543 && (GET_CODE (otherops[2]) == REG
8544 || (GET_CODE (otherops[2]) == CONST_INT
8545 && INTVAL (otherops[2]) > -256
8546 && INTVAL (otherops[2]) < 256)))
8547 {
8548 if (reg_overlap_mentioned_p (otherops[0],
8549 otherops[2]))
8550 {
8551 /* Swap base and index registers over to
8552 avoid a conflict. */
8553 otherops[1] = XEXP (XEXP (operands[1], 0), 1);
8554 otherops[2] = XEXP (XEXP (operands[1], 0), 0);
8555
8556 }
8557 /* If both registers conflict, it will usually
8558 have been fixed by a splitter. */
8559 if (reg_overlap_mentioned_p (otherops[0],
8560 otherops[2]))
8561 {
8562 output_asm_insn ("add%?\t%1, %1, %2", otherops);
8563 output_asm_insn ("ldr%?d\t%0, [%1]",
8564 otherops);
8565 return "";
8566 }
8567 else
8568 {
8569 output_asm_insn ("ldr%?d\t%0, [%1, %2]",
8570 otherops);
8571 return "";
8572 }
8573 }
8574 if (GET_CODE (otherops[2]) == CONST_INT)
8575 {
8576 if (!(const_ok_for_arm (INTVAL (otherops[2]))))
8577 output_asm_insn ("sub%?\t%0, %1, #%n2", otherops);
8578 else
8579 output_asm_insn ("add%?\t%0, %1, %2", otherops);
8580 }
8581 else
8582 output_asm_insn ("add%?\t%0, %1, %2", otherops);
8583 }
8584 else
8585 output_asm_insn ("sub%?\t%0, %1, %2", otherops);
8586
8587 return "ldm%?ia\t%0, %M0";
8588 }
8589 else
8590 {
8591 otherops[1] = adjust_address (operands[1], SImode, 4);
8592 /* Take care of overlapping base/data reg. */
8593 if (reg_mentioned_p (operands[0], operands[1]))
8594 {
8595 output_asm_insn ("ldr%?\t%0, %1", otherops);
8596 output_asm_insn ("ldr%?\t%0, %1", operands);
8597 }
8598 else
8599 {
8600 output_asm_insn ("ldr%?\t%0, %1", operands);
8601 output_asm_insn ("ldr%?\t%0, %1", otherops);
8602 }
8603 }
8604 }
8605 }
8606 else
8607 abort (); /* Constraints should prevent this. */
8608 }
8609 else if (code0 == MEM && code1 == REG)
8610 {
8611 if (REGNO (operands[1]) == IP_REGNUM)
8612 abort ();
8613
8614 switch (GET_CODE (XEXP (operands[0], 0)))
8615 {
8616 case REG:
8617 output_asm_insn ("stm%?ia\t%m0, %M1", operands);
8618 break;
8619
8620 case PRE_INC:
8621 if (!TARGET_LDRD)
8622 abort (); /* Should never happen now. */
8623 output_asm_insn ("str%?d\t%1, [%m0, #8]!", operands);
8624 break;
8625
8626 case PRE_DEC:
8627 output_asm_insn ("stm%?db\t%m0!, %M1", operands);
8628 break;
8629
8630 case POST_INC:
8631 output_asm_insn ("stm%?ia\t%m0!, %M1", operands);
8632 break;
8633
8634 case POST_DEC:
8635 if (!TARGET_LDRD)
8636 abort (); /* Should never happen now. */
8637 output_asm_insn ("str%?d\t%1, [%m0], #-8", operands);
8638 break;
8639
8640 case PRE_MODIFY:
8641 case POST_MODIFY:
8642 otherops[0] = operands[1];
8643 otherops[1] = XEXP (XEXP (XEXP (operands[0], 0), 1), 0);
8644 otherops[2] = XEXP (XEXP (XEXP (operands[0], 0), 1), 1);
8645
8646 if (GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY)
8647 output_asm_insn ("str%?d\t%0, [%1, %2]!", otherops);
8648 else
8649 output_asm_insn ("str%?d\t%0, [%1], %2", otherops);
8650 break;
8651
8652 case PLUS:
8653 otherops[2] = XEXP (XEXP (operands[0], 0), 1);
8654 if (GET_CODE (otherops[2]) == CONST_INT)
8655 {
8656 switch ((int) INTVAL (XEXP (XEXP (operands[0], 0), 1)))
8657 {
8658 case -8:
8659 output_asm_insn ("stm%?db\t%m0, %M1", operands);
8660 return "";
8661
8662 case -4:
8663 output_asm_insn ("stm%?da\t%m0, %M1", operands);
8664 return "";
8665
8666 case 4:
8667 output_asm_insn ("stm%?ib\t%m0, %M1", operands);
8668 return "";
8669 }
8670 }
8671 if (TARGET_LDRD
8672 && (GET_CODE (otherops[2]) == REG
8673 || (GET_CODE (otherops[2]) == CONST_INT
8674 && INTVAL (otherops[2]) > -256
8675 && INTVAL (otherops[2]) < 256)))
8676 {
8677 otherops[0] = operands[1];
8678 otherops[1] = XEXP (XEXP (operands[0], 0), 0);
8679 output_asm_insn ("str%?d\t%0, [%1, %2]", otherops);
8680 return "";
8681 }
8682 /* Fall through */
8683
8684 default:
8685 otherops[0] = adjust_address (operands[0], SImode, 4);
8686 otherops[1] = gen_rtx_REG (SImode, 1 + REGNO (operands[1]));
8687 output_asm_insn ("str%?\t%1, %0", operands);
8688 output_asm_insn ("str%?\t%1, %0", otherops);
8689 }
8690 }
8691 else
8692 /* Constraints should prevent this. */
8693 abort ();
8694
8695 return "";
8696 }
8697
8698
8699 /* Output an arbitrary MOV reg, #n.
8700 OPERANDS[0] is a register. OPERANDS[1] is a const_int. */
8701 const char *
8702 output_mov_immediate (rtx *operands)
8703 {
8704 HOST_WIDE_INT n = INTVAL (operands[1]);
8705
8706 /* Try to use one MOV. */
8707 if (const_ok_for_arm (n))
8708 output_asm_insn ("mov%?\t%0, %1", operands);
8709
8710 /* Try to use one MVN. */
8711 else if (const_ok_for_arm (~n))
8712 {
8713 operands[1] = GEN_INT (~n);
8714 output_asm_insn ("mvn%?\t%0, %1", operands);
8715 }
8716 else
8717 {
8718 int n_ones = 0;
8719 int i;
8720
8721 /* If all else fails, make it out of ORRs or BICs as appropriate. */
8722 for (i = 0; i < 32; i++)
8723 if (n & 1 << i)
8724 n_ones++;
8725
8726 if (n_ones > 16) /* Shorter to use MVN with BIC in this case. */
8727 output_multi_immediate (operands, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1, ~ n);
8728 else
8729 output_multi_immediate (operands, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1, n);
8730 }
8731
8732 return "";
8733 }
8734
8735 /* Output an ADD r, s, #n where n may be too big for one instruction.
8736 If adding zero to one register, output nothing. */
8737 const char *
8738 output_add_immediate (rtx *operands)
8739 {
8740 HOST_WIDE_INT n = INTVAL (operands[2]);
8741
8742 if (n != 0 || REGNO (operands[0]) != REGNO (operands[1]))
8743 {
8744 if (n < 0)
8745 output_multi_immediate (operands,
8746 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
8747 -n);
8748 else
8749 output_multi_immediate (operands,
8750 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
8751 n);
8752 }
8753
8754 return "";
8755 }
8756
8757 /* Output a multiple immediate operation.
8758 OPERANDS is the vector of operands referred to in the output patterns.
8759 INSTR1 is the output pattern to use for the first constant.
8760 INSTR2 is the output pattern to use for subsequent constants.
8761 IMMED_OP is the index of the constant slot in OPERANDS.
8762 N is the constant value. */
8763 static const char *
8764 output_multi_immediate (rtx *operands, const char *instr1, const char *instr2,
8765 int immed_op, HOST_WIDE_INT n)
8766 {
8767 #if HOST_BITS_PER_WIDE_INT > 32
8768 n &= 0xffffffff;
8769 #endif
8770
8771 if (n == 0)
8772 {
8773 /* Quick and easy output. */
8774 operands[immed_op] = const0_rtx;
8775 output_asm_insn (instr1, operands);
8776 }
8777 else
8778 {
8779 int i;
8780 const char * instr = instr1;
8781
8782 /* Note that n is never zero here (which would give no output). */
8783 for (i = 0; i < 32; i += 2)
8784 {
8785 if (n & (3 << i))
8786 {
8787 operands[immed_op] = GEN_INT (n & (255 << i));
8788 output_asm_insn (instr, operands);
8789 instr = instr2;
8790 i += 6;
8791 }
8792 }
8793 }
8794
8795 return "";
8796 }
8797
8798 /* Return the appropriate ARM instruction for the operation code.
8799 The returned result should not be overwritten. OP is the rtx of the
8800 operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator
8801 was shifted. */
8802 const char *
8803 arithmetic_instr (rtx op, int shift_first_arg)
8804 {
8805 switch (GET_CODE (op))
8806 {
8807 case PLUS:
8808 return "add";
8809
8810 case MINUS:
8811 return shift_first_arg ? "rsb" : "sub";
8812
8813 case IOR:
8814 return "orr";
8815
8816 case XOR:
8817 return "eor";
8818
8819 case AND:
8820 return "and";
8821
8822 default:
8823 abort ();
8824 }
8825 }
8826
8827 /* Ensure valid constant shifts and return the appropriate shift mnemonic
8828 for the operation code. The returned result should not be overwritten.
8829 OP is the rtx code of the shift.
8830 On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
8831 shift. */
8832 static const char *
8833 shift_op (rtx op, HOST_WIDE_INT *amountp)
8834 {
8835 const char * mnem;
8836 enum rtx_code code = GET_CODE (op);
8837
8838 if (GET_CODE (XEXP (op, 1)) == REG || GET_CODE (XEXP (op, 1)) == SUBREG)
8839 *amountp = -1;
8840 else if (GET_CODE (XEXP (op, 1)) == CONST_INT)
8841 *amountp = INTVAL (XEXP (op, 1));
8842 else
8843 abort ();
8844
8845 switch (code)
8846 {
8847 case ASHIFT:
8848 mnem = "asl";
8849 break;
8850
8851 case ASHIFTRT:
8852 mnem = "asr";
8853 break;
8854
8855 case LSHIFTRT:
8856 mnem = "lsr";
8857 break;
8858
8859 case ROTATERT:
8860 mnem = "ror";
8861 break;
8862
8863 case MULT:
8864 /* We never have to worry about the amount being other than a
8865 power of 2, since this case can never be reloaded from a reg. */
8866 if (*amountp != -1)
8867 *amountp = int_log2 (*amountp);
8868 else
8869 abort ();
8870 return "asl";
8871
8872 default:
8873 abort ();
8874 }
8875
8876 if (*amountp != -1)
8877 {
8878 /* This is not 100% correct, but follows from the desire to merge
8879 multiplication by a power of 2 with the recognizer for a
8880 shift. >=32 is not a valid shift for "asl", so we must try and
8881 output a shift that produces the correct arithmetical result.
8882 Using lsr #32 is identical except for the fact that the carry bit
8883 is not set correctly if we set the flags; but we never use the
8884 carry bit from such an operation, so we can ignore that. */
8885 if (code == ROTATERT)
8886 /* Rotate is just modulo 32. */
8887 *amountp &= 31;
8888 else if (*amountp != (*amountp & 31))
8889 {
8890 if (code == ASHIFT)
8891 mnem = "lsr";
8892 *amountp = 32;
8893 }
8894
8895 /* Shifts of 0 are no-ops. */
8896 if (*amountp == 0)
8897 return NULL;
8898 }
8899
8900 return mnem;
8901 }
8902
8903 /* Obtain the shift from the POWER of two. */
8904
8905 static HOST_WIDE_INT
8906 int_log2 (HOST_WIDE_INT power)
8907 {
8908 HOST_WIDE_INT shift = 0;
8909
8910 while ((((HOST_WIDE_INT) 1 << shift) & power) == 0)
8911 {
8912 if (shift > 31)
8913 abort ();
8914 shift++;
8915 }
8916
8917 return shift;
8918 }
8919
8920 /* Output a .ascii pseudo-op, keeping track of lengths. This is because
8921 /bin/as is horribly restrictive. */
8922 #define MAX_ASCII_LEN 51
8923
8924 void
8925 output_ascii_pseudo_op (FILE *stream, const unsigned char *p, int len)
8926 {
8927 int i;
8928 int len_so_far = 0;
8929
8930 fputs ("\t.ascii\t\"", stream);
8931
8932 for (i = 0; i < len; i++)
8933 {
8934 int c = p[i];
8935
8936 if (len_so_far >= MAX_ASCII_LEN)
8937 {
8938 fputs ("\"\n\t.ascii\t\"", stream);
8939 len_so_far = 0;
8940 }
8941
8942 switch (c)
8943 {
8944 case TARGET_TAB:
8945 fputs ("\\t", stream);
8946 len_so_far += 2;
8947 break;
8948
8949 case TARGET_FF:
8950 fputs ("\\f", stream);
8951 len_so_far += 2;
8952 break;
8953
8954 case TARGET_BS:
8955 fputs ("\\b", stream);
8956 len_so_far += 2;
8957 break;
8958
8959 case TARGET_CR:
8960 fputs ("\\r", stream);
8961 len_so_far += 2;
8962 break;
8963
8964 case TARGET_NEWLINE:
8965 fputs ("\\n", stream);
8966 c = p [i + 1];
8967 if ((c >= ' ' && c <= '~')
8968 || c == TARGET_TAB)
8969 /* This is a good place for a line break. */
8970 len_so_far = MAX_ASCII_LEN;
8971 else
8972 len_so_far += 2;
8973 break;
8974
8975 case '\"':
8976 case '\\':
8977 putc ('\\', stream);
8978 len_so_far++;
8979 /* Drop through. */
8980
8981 default:
8982 if (c >= ' ' && c <= '~')
8983 {
8984 putc (c, stream);
8985 len_so_far++;
8986 }
8987 else
8988 {
8989 fprintf (stream, "\\%03o", c);
8990 len_so_far += 4;
8991 }
8992 break;
8993 }
8994 }
8995
8996 fputs ("\"\n", stream);
8997 }
8998 \f
8999 /* Compute the register save mask for registers 0 through 12
9000 inclusive. This code is used by arm_compute_save_reg_mask. */
9001 static unsigned long
9002 arm_compute_save_reg0_reg12_mask (void)
9003 {
9004 unsigned long func_type = arm_current_func_type ();
9005 unsigned int save_reg_mask = 0;
9006 unsigned int reg;
9007
9008 if (IS_INTERRUPT (func_type))
9009 {
9010 unsigned int max_reg;
9011 /* Interrupt functions must not corrupt any registers,
9012 even call clobbered ones. If this is a leaf function
9013 we can just examine the registers used by the RTL, but
9014 otherwise we have to assume that whatever function is
9015 called might clobber anything, and so we have to save
9016 all the call-clobbered registers as well. */
9017 if (ARM_FUNC_TYPE (func_type) == ARM_FT_FIQ)
9018 /* FIQ handlers have registers r8 - r12 banked, so
9019 we only need to check r0 - r7, Normal ISRs only
9020 bank r14 and r15, so we must check up to r12.
9021 r13 is the stack pointer which is always preserved,
9022 so we do not need to consider it here. */
9023 max_reg = 7;
9024 else
9025 max_reg = 12;
9026
9027 for (reg = 0; reg <= max_reg; reg++)
9028 if (regs_ever_live[reg]
9029 || (! current_function_is_leaf && call_used_regs [reg]))
9030 save_reg_mask |= (1 << reg);
9031 }
9032 else
9033 {
9034 /* In the normal case we only need to save those registers
9035 which are call saved and which are used by this function. */
9036 for (reg = 0; reg <= 10; reg++)
9037 if (regs_ever_live[reg] && ! call_used_regs [reg])
9038 save_reg_mask |= (1 << reg);
9039
9040 /* Handle the frame pointer as a special case. */
9041 if (! TARGET_APCS_FRAME
9042 && ! frame_pointer_needed
9043 && regs_ever_live[HARD_FRAME_POINTER_REGNUM]
9044 && ! call_used_regs[HARD_FRAME_POINTER_REGNUM])
9045 save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM;
9046
9047 /* If we aren't loading the PIC register,
9048 don't stack it even though it may be live. */
9049 if (flag_pic
9050 && ! TARGET_SINGLE_PIC_BASE
9051 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
9052 save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM;
9053 }
9054
9055 /* Save registers so the exception handler can modify them. */
9056 if (current_function_calls_eh_return)
9057 {
9058 unsigned int i;
9059
9060 for (i = 0; ; i++)
9061 {
9062 reg = EH_RETURN_DATA_REGNO (i);
9063 if (reg == INVALID_REGNUM)
9064 break;
9065 save_reg_mask |= 1 << reg;
9066 }
9067 }
9068
9069 return save_reg_mask;
9070 }
9071
9072 /* Compute a bit mask of which registers need to be
9073 saved on the stack for the current function. */
9074
9075 static unsigned long
9076 arm_compute_save_reg_mask (void)
9077 {
9078 unsigned int save_reg_mask = 0;
9079 unsigned long func_type = arm_current_func_type ();
9080
9081 if (IS_NAKED (func_type))
9082 /* This should never really happen. */
9083 return 0;
9084
9085 /* If we are creating a stack frame, then we must save the frame pointer,
9086 IP (which will hold the old stack pointer), LR and the PC. */
9087 if (frame_pointer_needed)
9088 save_reg_mask |=
9089 (1 << ARM_HARD_FRAME_POINTER_REGNUM)
9090 | (1 << IP_REGNUM)
9091 | (1 << LR_REGNUM)
9092 | (1 << PC_REGNUM);
9093
9094 /* Volatile functions do not return, so there
9095 is no need to save any other registers. */
9096 if (IS_VOLATILE (func_type))
9097 return save_reg_mask;
9098
9099 save_reg_mask |= arm_compute_save_reg0_reg12_mask ();
9100
9101 /* Decide if we need to save the link register.
9102 Interrupt routines have their own banked link register,
9103 so they never need to save it.
9104 Otherwise if we do not use the link register we do not need to save
9105 it. If we are pushing other registers onto the stack however, we
9106 can save an instruction in the epilogue by pushing the link register
9107 now and then popping it back into the PC. This incurs extra memory
9108 accesses though, so we only do it when optimizing for size, and only
9109 if we know that we will not need a fancy return sequence. */
9110 if (regs_ever_live [LR_REGNUM]
9111 || (save_reg_mask
9112 && optimize_size
9113 && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL
9114 && !current_function_calls_eh_return))
9115 save_reg_mask |= 1 << LR_REGNUM;
9116
9117 if (cfun->machine->lr_save_eliminated)
9118 save_reg_mask &= ~ (1 << LR_REGNUM);
9119
9120 if (TARGET_REALLY_IWMMXT
9121 && ((bit_count (save_reg_mask)
9122 + ARM_NUM_INTS (current_function_pretend_args_size)) % 2) != 0)
9123 {
9124 unsigned int reg;
9125
9126 /* The total number of registers that are going to be pushed
9127 onto the stack is odd. We need to ensure that the stack
9128 is 64-bit aligned before we start to save iWMMXt registers,
9129 and also before we start to create locals. (A local variable
9130 might be a double or long long which we will load/store using
9131 an iWMMXt instruction). Therefore we need to push another
9132 ARM register, so that the stack will be 64-bit aligned. We
9133 try to avoid using the arg registers (r0 -r3) as they might be
9134 used to pass values in a tail call. */
9135 for (reg = 4; reg <= 12; reg++)
9136 if ((save_reg_mask & (1 << reg)) == 0)
9137 break;
9138
9139 if (reg <= 12)
9140 save_reg_mask |= (1 << reg);
9141 else
9142 {
9143 cfun->machine->sibcall_blocked = 1;
9144 save_reg_mask |= (1 << 3);
9145 }
9146 }
9147
9148 return save_reg_mask;
9149 }
9150
9151
9152 /* Return the number of bytes required to save VFP registers. */
9153 static int
9154 arm_get_vfp_saved_size (void)
9155 {
9156 unsigned int regno;
9157 int count;
9158 int saved;
9159
9160 saved = 0;
9161 /* Space for saved VFP registers. */
9162 if (TARGET_HARD_FLOAT && TARGET_VFP)
9163 {
9164 count = 0;
9165 for (regno = FIRST_VFP_REGNUM;
9166 regno < LAST_VFP_REGNUM;
9167 regno += 2)
9168 {
9169 if ((!regs_ever_live[regno] || call_used_regs[regno])
9170 && (!regs_ever_live[regno + 1] || call_used_regs[regno + 1]))
9171 {
9172 if (count > 0)
9173 {
9174 /* Workaround ARM10 VFPr1 bug. */
9175 if (count == 2 && !arm_arch6)
9176 count++;
9177 saved += count * 8 + 4;
9178 }
9179 count = 0;
9180 }
9181 else
9182 count++;
9183 }
9184 if (count > 0)
9185 {
9186 if (count == 2 && !arm_arch6)
9187 count++;
9188 saved += count * 8 + 4;
9189 }
9190 }
9191 return saved;
9192 }
9193
9194
9195 /* Generate a function exit sequence. If REALLY_RETURN is false, then do
9196 everything bar the final return instruction. */
9197 const char *
9198 output_return_instruction (rtx operand, int really_return, int reverse)
9199 {
9200 char conditional[10];
9201 char instr[100];
9202 int reg;
9203 unsigned long live_regs_mask;
9204 unsigned long func_type;
9205 arm_stack_offsets *offsets;
9206
9207 func_type = arm_current_func_type ();
9208
9209 if (IS_NAKED (func_type))
9210 return "";
9211
9212 if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN)
9213 {
9214 /* If this function was declared non-returning, and we have
9215 found a tail call, then we have to trust that the called
9216 function won't return. */
9217 if (really_return)
9218 {
9219 rtx ops[2];
9220
9221 /* Otherwise, trap an attempted return by aborting. */
9222 ops[0] = operand;
9223 ops[1] = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)"
9224 : "abort");
9225 assemble_external_libcall (ops[1]);
9226 output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops);
9227 }
9228
9229 return "";
9230 }
9231
9232 if (current_function_calls_alloca && !really_return)
9233 abort ();
9234
9235 sprintf (conditional, "%%?%%%c0", reverse ? 'D' : 'd');
9236
9237 return_used_this_function = 1;
9238
9239 live_regs_mask = arm_compute_save_reg_mask ();
9240
9241 if (live_regs_mask)
9242 {
9243 const char * return_reg;
9244
9245 /* If we do not have any special requirements for function exit
9246 (eg interworking, or ISR) then we can load the return address
9247 directly into the PC. Otherwise we must load it into LR. */
9248 if (really_return
9249 && ! TARGET_INTERWORK)
9250 return_reg = reg_names[PC_REGNUM];
9251 else
9252 return_reg = reg_names[LR_REGNUM];
9253
9254 if ((live_regs_mask & (1 << IP_REGNUM)) == (1 << IP_REGNUM))
9255 {
9256 /* There are three possible reasons for the IP register
9257 being saved. 1) a stack frame was created, in which case
9258 IP contains the old stack pointer, or 2) an ISR routine
9259 corrupted it, or 3) it was saved to align the stack on
9260 iWMMXt. In case 1, restore IP into SP, otherwise just
9261 restore IP. */
9262 if (frame_pointer_needed)
9263 {
9264 live_regs_mask &= ~ (1 << IP_REGNUM);
9265 live_regs_mask |= (1 << SP_REGNUM);
9266 }
9267 else
9268 {
9269 if (! IS_INTERRUPT (func_type)
9270 && ! TARGET_REALLY_IWMMXT)
9271 abort ();
9272 }
9273 }
9274
9275 /* On some ARM architectures it is faster to use LDR rather than
9276 LDM to load a single register. On other architectures, the
9277 cost is the same. In 26 bit mode, or for exception handlers,
9278 we have to use LDM to load the PC so that the CPSR is also
9279 restored. */
9280 for (reg = 0; reg <= LAST_ARM_REGNUM; reg++)
9281 {
9282 if (live_regs_mask == (unsigned int)(1 << reg))
9283 break;
9284 }
9285 if (reg <= LAST_ARM_REGNUM
9286 && (reg != LR_REGNUM
9287 || ! really_return
9288 || ! IS_INTERRUPT (func_type)))
9289 {
9290 sprintf (instr, "ldr%s\t%%|%s, [%%|sp], #4", conditional,
9291 (reg == LR_REGNUM) ? return_reg : reg_names[reg]);
9292 }
9293 else
9294 {
9295 char *p;
9296 int first = 1;
9297
9298 /* Generate the load multiple instruction to restore the
9299 registers. Note we can get here, even if
9300 frame_pointer_needed is true, but only if sp already
9301 points to the base of the saved core registers. */
9302 if (live_regs_mask & (1 << SP_REGNUM))
9303 {
9304 unsigned HOST_WIDE_INT stack_adjust;
9305
9306 offsets = arm_get_frame_offsets ();
9307 stack_adjust = offsets->outgoing_args - offsets->saved_regs;
9308 if (stack_adjust != 0 && stack_adjust != 4)
9309 abort ();
9310
9311 if (stack_adjust && arm_arch5)
9312 sprintf (instr, "ldm%sib\t%%|sp, {", conditional);
9313 else
9314 {
9315 /* If we can't use ldmib (SA110 bug), then try to pop r3
9316 instead. */
9317 if (stack_adjust)
9318 live_regs_mask |= 1 << 3;
9319 sprintf (instr, "ldm%sfd\t%%|sp, {", conditional);
9320 }
9321 }
9322 else
9323 sprintf (instr, "ldm%sfd\t%%|sp!, {", conditional);
9324
9325 p = instr + strlen (instr);
9326
9327 for (reg = 0; reg <= SP_REGNUM; reg++)
9328 if (live_regs_mask & (1 << reg))
9329 {
9330 int l = strlen (reg_names[reg]);
9331
9332 if (first)
9333 first = 0;
9334 else
9335 {
9336 memcpy (p, ", ", 2);
9337 p += 2;
9338 }
9339
9340 memcpy (p, "%|", 2);
9341 memcpy (p + 2, reg_names[reg], l);
9342 p += l + 2;
9343 }
9344
9345 if (live_regs_mask & (1 << LR_REGNUM))
9346 {
9347 sprintf (p, "%s%%|%s}", first ? "" : ", ", return_reg);
9348 /* If returning from an interrupt, restore the CPSR. */
9349 if (IS_INTERRUPT (func_type))
9350 strcat (p, "^");
9351 }
9352 else
9353 strcpy (p, "}");
9354 }
9355
9356 output_asm_insn (instr, & operand);
9357
9358 /* See if we need to generate an extra instruction to
9359 perform the actual function return. */
9360 if (really_return
9361 && func_type != ARM_FT_INTERWORKED
9362 && (live_regs_mask & (1 << LR_REGNUM)) != 0)
9363 {
9364 /* The return has already been handled
9365 by loading the LR into the PC. */
9366 really_return = 0;
9367 }
9368 }
9369
9370 if (really_return)
9371 {
9372 switch ((int) ARM_FUNC_TYPE (func_type))
9373 {
9374 case ARM_FT_ISR:
9375 case ARM_FT_FIQ:
9376 sprintf (instr, "sub%ss\t%%|pc, %%|lr, #4", conditional);
9377 break;
9378
9379 case ARM_FT_INTERWORKED:
9380 sprintf (instr, "bx%s\t%%|lr", conditional);
9381 break;
9382
9383 case ARM_FT_EXCEPTION:
9384 sprintf (instr, "mov%ss\t%%|pc, %%|lr", conditional);
9385 break;
9386
9387 default:
9388 /* Use bx if it's available. */
9389 if (arm_arch5 || arm_arch4t)
9390 sprintf (instr, "bx%s\t%%|lr", conditional);
9391 else
9392 sprintf (instr, "mov%s\t%%|pc, %%|lr", conditional);
9393 break;
9394 }
9395
9396 output_asm_insn (instr, & operand);
9397 }
9398
9399 return "";
9400 }
9401
9402 /* Write the function name into the code section, directly preceding
9403 the function prologue.
9404
9405 Code will be output similar to this:
9406 t0
9407 .ascii "arm_poke_function_name", 0
9408 .align
9409 t1
9410 .word 0xff000000 + (t1 - t0)
9411 arm_poke_function_name
9412 mov ip, sp
9413 stmfd sp!, {fp, ip, lr, pc}
9414 sub fp, ip, #4
9415
9416 When performing a stack backtrace, code can inspect the value
9417 of 'pc' stored at 'fp' + 0. If the trace function then looks
9418 at location pc - 12 and the top 8 bits are set, then we know
9419 that there is a function name embedded immediately preceding this
9420 location and has length ((pc[-3]) & 0xff000000).
9421
9422 We assume that pc is declared as a pointer to an unsigned long.
9423
9424 It is of no benefit to output the function name if we are assembling
9425 a leaf function. These function types will not contain a stack
9426 backtrace structure, therefore it is not possible to determine the
9427 function name. */
9428 void
9429 arm_poke_function_name (FILE *stream, const char *name)
9430 {
9431 unsigned long alignlength;
9432 unsigned long length;
9433 rtx x;
9434
9435 length = strlen (name) + 1;
9436 alignlength = ROUND_UP_WORD (length);
9437
9438 ASM_OUTPUT_ASCII (stream, name, length);
9439 ASM_OUTPUT_ALIGN (stream, 2);
9440 x = GEN_INT ((unsigned HOST_WIDE_INT) 0xff000000 + alignlength);
9441 assemble_aligned_integer (UNITS_PER_WORD, x);
9442 }
9443
9444 /* Place some comments into the assembler stream
9445 describing the current function. */
9446 static void
9447 arm_output_function_prologue (FILE *f, HOST_WIDE_INT frame_size)
9448 {
9449 unsigned long func_type;
9450
9451 if (!TARGET_ARM)
9452 {
9453 thumb_output_function_prologue (f, frame_size);
9454 return;
9455 }
9456
9457 /* Sanity check. */
9458 if (arm_ccfsm_state || arm_target_insn)
9459 abort ();
9460
9461 func_type = arm_current_func_type ();
9462
9463 switch ((int) ARM_FUNC_TYPE (func_type))
9464 {
9465 default:
9466 case ARM_FT_NORMAL:
9467 break;
9468 case ARM_FT_INTERWORKED:
9469 asm_fprintf (f, "\t%@ Function supports interworking.\n");
9470 break;
9471 case ARM_FT_ISR:
9472 asm_fprintf (f, "\t%@ Interrupt Service Routine.\n");
9473 break;
9474 case ARM_FT_FIQ:
9475 asm_fprintf (f, "\t%@ Fast Interrupt Service Routine.\n");
9476 break;
9477 case ARM_FT_EXCEPTION:
9478 asm_fprintf (f, "\t%@ ARM Exception Handler.\n");
9479 break;
9480 }
9481
9482 if (IS_NAKED (func_type))
9483 asm_fprintf (f, "\t%@ Naked Function: prologue and epilogue provided by programmer.\n");
9484
9485 if (IS_VOLATILE (func_type))
9486 asm_fprintf (f, "\t%@ Volatile: function does not return.\n");
9487
9488 if (IS_NESTED (func_type))
9489 asm_fprintf (f, "\t%@ Nested: function declared inside another function.\n");
9490
9491 asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %wd\n",
9492 current_function_args_size,
9493 current_function_pretend_args_size, frame_size);
9494
9495 asm_fprintf (f, "\t%@ frame_needed = %d, uses_anonymous_args = %d\n",
9496 frame_pointer_needed,
9497 cfun->machine->uses_anonymous_args);
9498
9499 if (cfun->machine->lr_save_eliminated)
9500 asm_fprintf (f, "\t%@ link register save eliminated.\n");
9501
9502 if (current_function_calls_eh_return)
9503 asm_fprintf (f, "\t@ Calls __builtin_eh_return.\n");
9504
9505 #ifdef AOF_ASSEMBLER
9506 if (flag_pic)
9507 asm_fprintf (f, "\tmov\t%r, %r\n", IP_REGNUM, PIC_OFFSET_TABLE_REGNUM);
9508 #endif
9509
9510 return_used_this_function = 0;
9511 }
9512
9513 const char *
9514 arm_output_epilogue (rtx sibling)
9515 {
9516 int reg;
9517 unsigned long saved_regs_mask;
9518 unsigned long func_type;
9519 /* Floats_offset is the offset from the "virtual" frame. In an APCS
9520 frame that is $fp + 4 for a non-variadic function. */
9521 int floats_offset = 0;
9522 rtx operands[3];
9523 FILE * f = asm_out_file;
9524 unsigned int lrm_count = 0;
9525 int really_return = (sibling == NULL);
9526 int start_reg;
9527 arm_stack_offsets *offsets;
9528
9529 /* If we have already generated the return instruction
9530 then it is futile to generate anything else. */
9531 if (use_return_insn (FALSE, sibling) && return_used_this_function)
9532 return "";
9533
9534 func_type = arm_current_func_type ();
9535
9536 if (IS_NAKED (func_type))
9537 /* Naked functions don't have epilogues. */
9538 return "";
9539
9540 if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN)
9541 {
9542 rtx op;
9543
9544 /* A volatile function should never return. Call abort. */
9545 op = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" : "abort");
9546 assemble_external_libcall (op);
9547 output_asm_insn ("bl\t%a0", &op);
9548
9549 return "";
9550 }
9551
9552 if (current_function_calls_eh_return
9553 && ! really_return)
9554 /* If we are throwing an exception, then we really must
9555 be doing a return, so we can't tail-call. */
9556 abort ();
9557
9558 offsets = arm_get_frame_offsets ();
9559 saved_regs_mask = arm_compute_save_reg_mask ();
9560
9561 if (TARGET_IWMMXT)
9562 lrm_count = bit_count (saved_regs_mask);
9563
9564 floats_offset = offsets->saved_args;
9565 /* Compute how far away the floats will be. */
9566 for (reg = 0; reg <= LAST_ARM_REGNUM; reg++)
9567 if (saved_regs_mask & (1 << reg))
9568 floats_offset += 4;
9569
9570 if (frame_pointer_needed)
9571 {
9572 /* This variable is for the Virtual Frame Pointer, not VFP regs. */
9573 int vfp_offset = offsets->frame;
9574
9575 if (arm_fpu_arch == FPUTYPE_FPA_EMU2)
9576 {
9577 for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--)
9578 if (regs_ever_live[reg] && !call_used_regs[reg])
9579 {
9580 floats_offset += 12;
9581 asm_fprintf (f, "\tldfe\t%r, [%r, #-%d]\n",
9582 reg, FP_REGNUM, floats_offset - vfp_offset);
9583 }
9584 }
9585 else
9586 {
9587 start_reg = LAST_FPA_REGNUM;
9588
9589 for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--)
9590 {
9591 if (regs_ever_live[reg] && !call_used_regs[reg])
9592 {
9593 floats_offset += 12;
9594
9595 /* We can't unstack more than four registers at once. */
9596 if (start_reg - reg == 3)
9597 {
9598 asm_fprintf (f, "\tlfm\t%r, 4, [%r, #-%d]\n",
9599 reg, FP_REGNUM, floats_offset - vfp_offset);
9600 start_reg = reg - 1;
9601 }
9602 }
9603 else
9604 {
9605 if (reg != start_reg)
9606 asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n",
9607 reg + 1, start_reg - reg,
9608 FP_REGNUM, floats_offset - vfp_offset);
9609 start_reg = reg - 1;
9610 }
9611 }
9612
9613 /* Just in case the last register checked also needs unstacking. */
9614 if (reg != start_reg)
9615 asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n",
9616 reg + 1, start_reg - reg,
9617 FP_REGNUM, floats_offset - vfp_offset);
9618 }
9619
9620 if (TARGET_HARD_FLOAT && TARGET_VFP)
9621 {
9622 int saved_size;
9623
9624 /* The fldmx insn does not have base+offset addressing modes,
9625 so we use IP to hold the address. */
9626 saved_size = arm_get_vfp_saved_size ();
9627
9628 if (saved_size > 0)
9629 {
9630 floats_offset += saved_size;
9631 asm_fprintf (f, "\tsub\t%r, %r, #%d\n", IP_REGNUM,
9632 FP_REGNUM, floats_offset - vfp_offset);
9633 }
9634 start_reg = FIRST_VFP_REGNUM;
9635 for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2)
9636 {
9637 if ((!regs_ever_live[reg] || call_used_regs[reg])
9638 && (!regs_ever_live[reg + 1] || call_used_regs[reg + 1]))
9639 {
9640 if (start_reg != reg)
9641 arm_output_fldmx (f, IP_REGNUM,
9642 (start_reg - FIRST_VFP_REGNUM) / 2,
9643 (reg - start_reg) / 2);
9644 start_reg = reg + 2;
9645 }
9646 }
9647 if (start_reg != reg)
9648 arm_output_fldmx (f, IP_REGNUM,
9649 (start_reg - FIRST_VFP_REGNUM) / 2,
9650 (reg - start_reg) / 2);
9651 }
9652
9653 if (TARGET_IWMMXT)
9654 {
9655 /* The frame pointer is guaranteed to be non-double-word aligned.
9656 This is because it is set to (old_stack_pointer - 4) and the
9657 old_stack_pointer was double word aligned. Thus the offset to
9658 the iWMMXt registers to be loaded must also be non-double-word
9659 sized, so that the resultant address *is* double-word aligned.
9660 We can ignore floats_offset since that was already included in
9661 the live_regs_mask. */
9662 lrm_count += (lrm_count % 2 ? 2 : 1);
9663
9664 for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--)
9665 if (regs_ever_live[reg] && !call_used_regs[reg])
9666 {
9667 asm_fprintf (f, "\twldrd\t%r, [%r, #-%d]\n",
9668 reg, FP_REGNUM, lrm_count * 4);
9669 lrm_count += 2;
9670 }
9671 }
9672
9673 /* saved_regs_mask should contain the IP, which at the time of stack
9674 frame generation actually contains the old stack pointer. So a
9675 quick way to unwind the stack is just pop the IP register directly
9676 into the stack pointer. */
9677 if ((saved_regs_mask & (1 << IP_REGNUM)) == 0)
9678 abort ();
9679 saved_regs_mask &= ~ (1 << IP_REGNUM);
9680 saved_regs_mask |= (1 << SP_REGNUM);
9681
9682 /* There are two registers left in saved_regs_mask - LR and PC. We
9683 only need to restore the LR register (the return address), but to
9684 save time we can load it directly into the PC, unless we need a
9685 special function exit sequence, or we are not really returning. */
9686 if (really_return
9687 && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL
9688 && !current_function_calls_eh_return)
9689 /* Delete the LR from the register mask, so that the LR on
9690 the stack is loaded into the PC in the register mask. */
9691 saved_regs_mask &= ~ (1 << LR_REGNUM);
9692 else
9693 saved_regs_mask &= ~ (1 << PC_REGNUM);
9694
9695 /* We must use SP as the base register, because SP is one of the
9696 registers being restored. If an interrupt or page fault
9697 happens in the ldm instruction, the SP might or might not
9698 have been restored. That would be bad, as then SP will no
9699 longer indicate the safe area of stack, and we can get stack
9700 corruption. Using SP as the base register means that it will
9701 be reset correctly to the original value, should an interrupt
9702 occur. If the stack pointer already points at the right
9703 place, then omit the subtraction. */
9704 if (offsets->outgoing_args != (1 + (int) bit_count (saved_regs_mask))
9705 || current_function_calls_alloca)
9706 asm_fprintf (f, "\tsub\t%r, %r, #%d\n", SP_REGNUM, FP_REGNUM,
9707 4 * bit_count (saved_regs_mask));
9708 print_multi_reg (f, "ldmfd\t%r", SP_REGNUM, saved_regs_mask);
9709
9710 if (IS_INTERRUPT (func_type))
9711 /* Interrupt handlers will have pushed the
9712 IP onto the stack, so restore it now. */
9713 print_multi_reg (f, "ldmfd\t%r!", SP_REGNUM, 1 << IP_REGNUM);
9714 }
9715 else
9716 {
9717 /* Restore stack pointer if necessary. */
9718 if (offsets->outgoing_args != offsets->saved_regs)
9719 {
9720 operands[0] = operands[1] = stack_pointer_rtx;
9721 operands[2] = GEN_INT (offsets->outgoing_args - offsets->saved_regs);
9722 output_add_immediate (operands);
9723 }
9724
9725 if (arm_fpu_arch == FPUTYPE_FPA_EMU2)
9726 {
9727 for (reg = FIRST_FPA_REGNUM; reg <= LAST_FPA_REGNUM; reg++)
9728 if (regs_ever_live[reg] && !call_used_regs[reg])
9729 asm_fprintf (f, "\tldfe\t%r, [%r], #12\n",
9730 reg, SP_REGNUM);
9731 }
9732 else
9733 {
9734 start_reg = FIRST_FPA_REGNUM;
9735
9736 for (reg = FIRST_FPA_REGNUM; reg <= LAST_FPA_REGNUM; reg++)
9737 {
9738 if (regs_ever_live[reg] && !call_used_regs[reg])
9739 {
9740 if (reg - start_reg == 3)
9741 {
9742 asm_fprintf (f, "\tlfmfd\t%r, 4, [%r]!\n",
9743 start_reg, SP_REGNUM);
9744 start_reg = reg + 1;
9745 }
9746 }
9747 else
9748 {
9749 if (reg != start_reg)
9750 asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n",
9751 start_reg, reg - start_reg,
9752 SP_REGNUM);
9753
9754 start_reg = reg + 1;
9755 }
9756 }
9757
9758 /* Just in case the last register checked also needs unstacking. */
9759 if (reg != start_reg)
9760 asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n",
9761 start_reg, reg - start_reg, SP_REGNUM);
9762 }
9763
9764 if (TARGET_HARD_FLOAT && TARGET_VFP)
9765 {
9766 start_reg = FIRST_VFP_REGNUM;
9767 for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2)
9768 {
9769 if ((!regs_ever_live[reg] || call_used_regs[reg])
9770 && (!regs_ever_live[reg + 1] || call_used_regs[reg + 1]))
9771 {
9772 if (start_reg != reg)
9773 arm_output_fldmx (f, SP_REGNUM,
9774 (start_reg - FIRST_VFP_REGNUM) / 2,
9775 (reg - start_reg) / 2);
9776 start_reg = reg + 2;
9777 }
9778 }
9779 if (start_reg != reg)
9780 arm_output_fldmx (f, SP_REGNUM,
9781 (start_reg - FIRST_VFP_REGNUM) / 2,
9782 (reg - start_reg) / 2);
9783 }
9784 if (TARGET_IWMMXT)
9785 for (reg = FIRST_IWMMXT_REGNUM; reg <= LAST_IWMMXT_REGNUM; reg++)
9786 if (regs_ever_live[reg] && !call_used_regs[reg])
9787 asm_fprintf (f, "\twldrd\t%r, [%r], #8\n", reg, SP_REGNUM);
9788
9789 /* If we can, restore the LR into the PC. */
9790 if (ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL
9791 && really_return
9792 && current_function_pretend_args_size == 0
9793 && saved_regs_mask & (1 << LR_REGNUM)
9794 && !current_function_calls_eh_return)
9795 {
9796 saved_regs_mask &= ~ (1 << LR_REGNUM);
9797 saved_regs_mask |= (1 << PC_REGNUM);
9798 }
9799
9800 /* Load the registers off the stack. If we only have one register
9801 to load use the LDR instruction - it is faster. */
9802 if (saved_regs_mask == (1 << LR_REGNUM))
9803 {
9804 asm_fprintf (f, "\tldr\t%r, [%r], #4\n", LR_REGNUM, SP_REGNUM);
9805 }
9806 else if (saved_regs_mask)
9807 {
9808 if (saved_regs_mask & (1 << SP_REGNUM))
9809 /* Note - write back to the stack register is not enabled
9810 (ie "ldmfd sp!..."). We know that the stack pointer is
9811 in the list of registers and if we add writeback the
9812 instruction becomes UNPREDICTABLE. */
9813 print_multi_reg (f, "ldmfd\t%r", SP_REGNUM, saved_regs_mask);
9814 else
9815 print_multi_reg (f, "ldmfd\t%r!", SP_REGNUM, saved_regs_mask);
9816 }
9817
9818 if (current_function_pretend_args_size)
9819 {
9820 /* Unwind the pre-pushed regs. */
9821 operands[0] = operands[1] = stack_pointer_rtx;
9822 operands[2] = GEN_INT (current_function_pretend_args_size);
9823 output_add_immediate (operands);
9824 }
9825 }
9826
9827 /* We may have already restored PC directly from the stack. */
9828 if (!really_return || saved_regs_mask & (1 << PC_REGNUM))
9829 return "";
9830
9831 /* Stack adjustment for exception handler. */
9832 if (current_function_calls_eh_return)
9833 asm_fprintf (f, "\tadd\t%r, %r, %r\n", SP_REGNUM, SP_REGNUM,
9834 ARM_EH_STACKADJ_REGNUM);
9835
9836 /* Generate the return instruction. */
9837 switch ((int) ARM_FUNC_TYPE (func_type))
9838 {
9839 case ARM_FT_ISR:
9840 case ARM_FT_FIQ:
9841 asm_fprintf (f, "\tsubs\t%r, %r, #4\n", PC_REGNUM, LR_REGNUM);
9842 break;
9843
9844 case ARM_FT_EXCEPTION:
9845 asm_fprintf (f, "\tmovs\t%r, %r\n", PC_REGNUM, LR_REGNUM);
9846 break;
9847
9848 case ARM_FT_INTERWORKED:
9849 asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM);
9850 break;
9851
9852 default:
9853 if (arm_arch5 || arm_arch4t)
9854 asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM);
9855 else
9856 asm_fprintf (f, "\tmov\t%r, %r\n", PC_REGNUM, LR_REGNUM);
9857 break;
9858 }
9859
9860 return "";
9861 }
9862
9863 static void
9864 arm_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
9865 HOST_WIDE_INT frame_size ATTRIBUTE_UNUSED)
9866 {
9867 arm_stack_offsets *offsets;
9868
9869 if (TARGET_THUMB)
9870 {
9871 /* ??? Probably not safe to set this here, since it assumes that a
9872 function will be emitted as assembly immediately after we generate
9873 RTL for it. This does not happen for inline functions. */
9874 return_used_this_function = 0;
9875 }
9876 else
9877 {
9878 /* We need to take into account any stack-frame rounding. */
9879 offsets = arm_get_frame_offsets ();
9880
9881 if (use_return_insn (FALSE, NULL)
9882 && return_used_this_function
9883 && offsets->saved_regs != offsets->outgoing_args
9884 && !frame_pointer_needed)
9885 abort ();
9886
9887 /* Reset the ARM-specific per-function variables. */
9888 after_arm_reorg = 0;
9889 }
9890 }
9891
9892 /* Generate and emit an insn that we will recognize as a push_multi.
9893 Unfortunately, since this insn does not reflect very well the actual
9894 semantics of the operation, we need to annotate the insn for the benefit
9895 of DWARF2 frame unwind information. */
9896 static rtx
9897 emit_multi_reg_push (int mask)
9898 {
9899 int num_regs = 0;
9900 int num_dwarf_regs;
9901 int i, j;
9902 rtx par;
9903 rtx dwarf;
9904 int dwarf_par_index;
9905 rtx tmp, reg;
9906
9907 for (i = 0; i <= LAST_ARM_REGNUM; i++)
9908 if (mask & (1 << i))
9909 num_regs++;
9910
9911 if (num_regs == 0 || num_regs > 16)
9912 abort ();
9913
9914 /* We don't record the PC in the dwarf frame information. */
9915 num_dwarf_regs = num_regs;
9916 if (mask & (1 << PC_REGNUM))
9917 num_dwarf_regs--;
9918
9919 /* For the body of the insn we are going to generate an UNSPEC in
9920 parallel with several USEs. This allows the insn to be recognized
9921 by the push_multi pattern in the arm.md file. The insn looks
9922 something like this:
9923
9924 (parallel [
9925 (set (mem:BLK (pre_dec:BLK (reg:SI sp)))
9926 (unspec:BLK [(reg:SI r4)] UNSPEC_PUSH_MULT))
9927 (use (reg:SI 11 fp))
9928 (use (reg:SI 12 ip))
9929 (use (reg:SI 14 lr))
9930 (use (reg:SI 15 pc))
9931 ])
9932
9933 For the frame note however, we try to be more explicit and actually
9934 show each register being stored into the stack frame, plus a (single)
9935 decrement of the stack pointer. We do it this way in order to be
9936 friendly to the stack unwinding code, which only wants to see a single
9937 stack decrement per instruction. The RTL we generate for the note looks
9938 something like this:
9939
9940 (sequence [
9941 (set (reg:SI sp) (plus:SI (reg:SI sp) (const_int -20)))
9942 (set (mem:SI (reg:SI sp)) (reg:SI r4))
9943 (set (mem:SI (plus:SI (reg:SI sp) (const_int 4))) (reg:SI fp))
9944 (set (mem:SI (plus:SI (reg:SI sp) (const_int 8))) (reg:SI ip))
9945 (set (mem:SI (plus:SI (reg:SI sp) (const_int 12))) (reg:SI lr))
9946 ])
9947
9948 This sequence is used both by the code to support stack unwinding for
9949 exceptions handlers and the code to generate dwarf2 frame debugging. */
9950
9951 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs));
9952 dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_dwarf_regs + 1));
9953 dwarf_par_index = 1;
9954
9955 for (i = 0; i <= LAST_ARM_REGNUM; i++)
9956 {
9957 if (mask & (1 << i))
9958 {
9959 reg = gen_rtx_REG (SImode, i);
9960
9961 XVECEXP (par, 0, 0)
9962 = gen_rtx_SET (VOIDmode,
9963 gen_rtx_MEM (BLKmode,
9964 gen_rtx_PRE_DEC (BLKmode,
9965 stack_pointer_rtx)),
9966 gen_rtx_UNSPEC (BLKmode,
9967 gen_rtvec (1, reg),
9968 UNSPEC_PUSH_MULT));
9969
9970 if (i != PC_REGNUM)
9971 {
9972 tmp = gen_rtx_SET (VOIDmode,
9973 gen_rtx_MEM (SImode, stack_pointer_rtx),
9974 reg);
9975 RTX_FRAME_RELATED_P (tmp) = 1;
9976 XVECEXP (dwarf, 0, dwarf_par_index) = tmp;
9977 dwarf_par_index++;
9978 }
9979
9980 break;
9981 }
9982 }
9983
9984 for (j = 1, i++; j < num_regs; i++)
9985 {
9986 if (mask & (1 << i))
9987 {
9988 reg = gen_rtx_REG (SImode, i);
9989
9990 XVECEXP (par, 0, j) = gen_rtx_USE (VOIDmode, reg);
9991
9992 if (i != PC_REGNUM)
9993 {
9994 tmp = gen_rtx_SET (VOIDmode,
9995 gen_rtx_MEM (SImode,
9996 plus_constant (stack_pointer_rtx,
9997 4 * j)),
9998 reg);
9999 RTX_FRAME_RELATED_P (tmp) = 1;
10000 XVECEXP (dwarf, 0, dwarf_par_index++) = tmp;
10001 }
10002
10003 j++;
10004 }
10005 }
10006
10007 par = emit_insn (par);
10008
10009 tmp = gen_rtx_SET (SImode,
10010 stack_pointer_rtx,
10011 gen_rtx_PLUS (SImode,
10012 stack_pointer_rtx,
10013 GEN_INT (-4 * num_regs)));
10014 RTX_FRAME_RELATED_P (tmp) = 1;
10015 XVECEXP (dwarf, 0, 0) = tmp;
10016
10017 REG_NOTES (par) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
10018 REG_NOTES (par));
10019 return par;
10020 }
10021
10022 static rtx
10023 emit_sfm (int base_reg, int count)
10024 {
10025 rtx par;
10026 rtx dwarf;
10027 rtx tmp, reg;
10028 int i;
10029
10030 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
10031 dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1));
10032
10033 reg = gen_rtx_REG (XFmode, base_reg++);
10034
10035 XVECEXP (par, 0, 0)
10036 = gen_rtx_SET (VOIDmode,
10037 gen_rtx_MEM (BLKmode,
10038 gen_rtx_PRE_DEC (BLKmode, stack_pointer_rtx)),
10039 gen_rtx_UNSPEC (BLKmode,
10040 gen_rtvec (1, reg),
10041 UNSPEC_PUSH_MULT));
10042 tmp = gen_rtx_SET (VOIDmode,
10043 gen_rtx_MEM (XFmode, stack_pointer_rtx), reg);
10044 RTX_FRAME_RELATED_P (tmp) = 1;
10045 XVECEXP (dwarf, 0, 1) = tmp;
10046
10047 for (i = 1; i < count; i++)
10048 {
10049 reg = gen_rtx_REG (XFmode, base_reg++);
10050 XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg);
10051
10052 tmp = gen_rtx_SET (VOIDmode,
10053 gen_rtx_MEM (XFmode,
10054 plus_constant (stack_pointer_rtx,
10055 i * 12)),
10056 reg);
10057 RTX_FRAME_RELATED_P (tmp) = 1;
10058 XVECEXP (dwarf, 0, i + 1) = tmp;
10059 }
10060
10061 tmp = gen_rtx_SET (VOIDmode,
10062 stack_pointer_rtx,
10063 gen_rtx_PLUS (SImode,
10064 stack_pointer_rtx,
10065 GEN_INT (-12 * count)));
10066 RTX_FRAME_RELATED_P (tmp) = 1;
10067 XVECEXP (dwarf, 0, 0) = tmp;
10068
10069 par = emit_insn (par);
10070 REG_NOTES (par) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
10071 REG_NOTES (par));
10072 return par;
10073 }
10074
10075
10076 /* Return true if the current function needs to save/restore LR. */
10077
10078 static bool
10079 thumb_force_lr_save (void)
10080 {
10081 return !cfun->machine->lr_save_eliminated
10082 && (!leaf_function_p ()
10083 || thumb_far_jump_used_p ()
10084 || regs_ever_live [LR_REGNUM]);
10085 }
10086
10087
10088 /* Compute the distance from register FROM to register TO.
10089 These can be the arg pointer (26), the soft frame pointer (25),
10090 the stack pointer (13) or the hard frame pointer (11).
10091 In thumb mode r7 is used as the soft frame pointer, if needed.
10092 Typical stack layout looks like this:
10093
10094 old stack pointer -> | |
10095 ----
10096 | | \
10097 | | saved arguments for
10098 | | vararg functions
10099 | | /
10100 --
10101 hard FP & arg pointer -> | | \
10102 | | stack
10103 | | frame
10104 | | /
10105 --
10106 | | \
10107 | | call saved
10108 | | registers
10109 soft frame pointer -> | | /
10110 --
10111 | | \
10112 | | local
10113 | | variables
10114 | | /
10115 --
10116 | | \
10117 | | outgoing
10118 | | arguments
10119 current stack pointer -> | | /
10120 --
10121
10122 For a given function some or all of these stack components
10123 may not be needed, giving rise to the possibility of
10124 eliminating some of the registers.
10125
10126 The values returned by this function must reflect the behavior
10127 of arm_expand_prologue() and arm_compute_save_reg_mask().
10128
10129 The sign of the number returned reflects the direction of stack
10130 growth, so the values are positive for all eliminations except
10131 from the soft frame pointer to the hard frame pointer.
10132
10133 SFP may point just inside the local variables block to ensure correct
10134 alignment. */
10135
10136
10137 /* Calculate stack offsets. These are used to calculate register elimination
10138 offsets and in prologue/epilogue code. */
10139
10140 static arm_stack_offsets *
10141 arm_get_frame_offsets (void)
10142 {
10143 struct arm_stack_offsets *offsets;
10144 unsigned long func_type;
10145 int leaf;
10146 int saved;
10147 HOST_WIDE_INT frame_size;
10148
10149 offsets = &cfun->machine->stack_offsets;
10150
10151 /* We need to know if we are a leaf function. Unfortunately, it
10152 is possible to be called after start_sequence has been called,
10153 which causes get_insns to return the insns for the sequence,
10154 not the function, which will cause leaf_function_p to return
10155 the incorrect result.
10156
10157 to know about leaf functions once reload has completed, and the
10158 frame size cannot be changed after that time, so we can safely
10159 use the cached value. */
10160
10161 if (reload_completed)
10162 return offsets;
10163
10164 /* Initially this is the size of the local variables. It will translated
10165 into an offset once we have determined the size of preceding data. */
10166 frame_size = ROUND_UP_WORD (get_frame_size ());
10167
10168 leaf = leaf_function_p ();
10169
10170 /* Space for variadic functions. */
10171 offsets->saved_args = current_function_pretend_args_size;
10172
10173 offsets->frame = offsets->saved_args + (frame_pointer_needed ? 4 : 0);
10174
10175 if (TARGET_ARM)
10176 {
10177 unsigned int regno;
10178
10179 saved = bit_count (arm_compute_save_reg_mask ()) * 4;
10180
10181 /* We know that SP will be doubleword aligned on entry, and we must
10182 preserve that condition at any subroutine call. We also require the
10183 soft frame pointer to be doubleword aligned. */
10184
10185 if (TARGET_REALLY_IWMMXT)
10186 {
10187 /* Check for the call-saved iWMMXt registers. */
10188 for (regno = FIRST_IWMMXT_REGNUM;
10189 regno <= LAST_IWMMXT_REGNUM;
10190 regno++)
10191 if (regs_ever_live [regno] && ! call_used_regs [regno])
10192 saved += 8;
10193 }
10194
10195 func_type = arm_current_func_type ();
10196 if (! IS_VOLATILE (func_type))
10197 {
10198 /* Space for saved FPA registers. */
10199 for (regno = FIRST_FPA_REGNUM; regno <= LAST_FPA_REGNUM; regno++)
10200 if (regs_ever_live[regno] && ! call_used_regs[regno])
10201 saved += 12;
10202
10203 /* Space for saved VFP registers. */
10204 if (TARGET_HARD_FLOAT && TARGET_VFP)
10205 saved += arm_get_vfp_saved_size ();
10206 }
10207 }
10208 else /* TARGET_THUMB */
10209 {
10210 int reg;
10211 int count_regs;
10212
10213 saved = 0;
10214 count_regs = 0;
10215 for (reg = 8; reg < 13; reg ++)
10216 if (THUMB_REG_PUSHED_P (reg))
10217 count_regs ++;
10218 if (count_regs)
10219 saved += 4 * count_regs;
10220 count_regs = 0;
10221 for (reg = 0; reg <= LAST_LO_REGNUM; reg ++)
10222 if (THUMB_REG_PUSHED_P (reg))
10223 count_regs ++;
10224 if (count_regs || thumb_force_lr_save ())
10225 saved += 4 * (count_regs + 1);
10226 if (TARGET_BACKTRACE)
10227 {
10228 if ((count_regs & 0xFF) == 0 && (regs_ever_live[3] != 0))
10229 saved += 20;
10230 else
10231 saved += 16;
10232 }
10233 }
10234
10235 /* Saved registers include the stack frame. */
10236 offsets->saved_regs = offsets->saved_args + saved;
10237 offsets->soft_frame = offsets->saved_regs;
10238 /* A leaf function does not need any stack alignment if it has nothing
10239 on the stack. */
10240 if (leaf && frame_size == 0)
10241 {
10242 offsets->outgoing_args = offsets->soft_frame;
10243 return offsets;
10244 }
10245
10246 /* Ensure SFP has the correct alignment. */
10247 if (ARM_DOUBLEWORD_ALIGN
10248 && (offsets->soft_frame & 7))
10249 offsets->soft_frame += 4;
10250
10251 offsets->outgoing_args = offsets->soft_frame + frame_size
10252 + current_function_outgoing_args_size;
10253
10254 if (ARM_DOUBLEWORD_ALIGN)
10255 {
10256 /* Ensure SP remains doubleword aligned. */
10257 if (offsets->outgoing_args & 7)
10258 offsets->outgoing_args += 4;
10259 if (offsets->outgoing_args & 7)
10260 abort ();
10261 }
10262
10263 return offsets;
10264 }
10265
10266
10267 /* Calculate the relative offsets for the different stack pointers. Positive
10268 offsets are in the direction of stack growth. */
10269
10270 HOST_WIDE_INT
10271 arm_compute_initial_elimination_offset (unsigned int from, unsigned int to)
10272 {
10273 arm_stack_offsets *offsets;
10274
10275 offsets = arm_get_frame_offsets ();
10276
10277 /* OK, now we have enough information to compute the distances.
10278 There must be an entry in these switch tables for each pair
10279 of registers in ELIMINABLE_REGS, even if some of the entries
10280 seem to be redundant or useless. */
10281 switch (from)
10282 {
10283 case ARG_POINTER_REGNUM:
10284 switch (to)
10285 {
10286 case THUMB_HARD_FRAME_POINTER_REGNUM:
10287 return 0;
10288
10289 case FRAME_POINTER_REGNUM:
10290 /* This is the reverse of the soft frame pointer
10291 to hard frame pointer elimination below. */
10292 return offsets->soft_frame - offsets->saved_args;
10293
10294 case ARM_HARD_FRAME_POINTER_REGNUM:
10295 /* If there is no stack frame then the hard
10296 frame pointer and the arg pointer coincide. */
10297 if (offsets->frame == offsets->saved_regs)
10298 return 0;
10299 /* FIXME: Not sure about this. Maybe we should always return 0 ? */
10300 return (frame_pointer_needed
10301 && cfun->static_chain_decl != NULL
10302 && ! cfun->machine->uses_anonymous_args) ? 4 : 0;
10303
10304 case STACK_POINTER_REGNUM:
10305 /* If nothing has been pushed on the stack at all
10306 then this will return -4. This *is* correct! */
10307 return offsets->outgoing_args - (offsets->saved_args + 4);
10308
10309 default:
10310 abort ();
10311 }
10312 break;
10313
10314 case FRAME_POINTER_REGNUM:
10315 switch (to)
10316 {
10317 case THUMB_HARD_FRAME_POINTER_REGNUM:
10318 return 0;
10319
10320 case ARM_HARD_FRAME_POINTER_REGNUM:
10321 /* The hard frame pointer points to the top entry in the
10322 stack frame. The soft frame pointer to the bottom entry
10323 in the stack frame. If there is no stack frame at all,
10324 then they are identical. */
10325
10326 return offsets->frame - offsets->soft_frame;
10327
10328 case STACK_POINTER_REGNUM:
10329 return offsets->outgoing_args - offsets->soft_frame;
10330
10331 default:
10332 abort ();
10333 }
10334 break;
10335
10336 default:
10337 /* You cannot eliminate from the stack pointer.
10338 In theory you could eliminate from the hard frame
10339 pointer to the stack pointer, but this will never
10340 happen, since if a stack frame is not needed the
10341 hard frame pointer will never be used. */
10342 abort ();
10343 }
10344 }
10345
10346
10347 /* Generate the prologue instructions for entry into an ARM function. */
10348 void
10349 arm_expand_prologue (void)
10350 {
10351 int reg;
10352 rtx amount;
10353 rtx insn;
10354 rtx ip_rtx;
10355 unsigned long live_regs_mask;
10356 unsigned long func_type;
10357 int fp_offset = 0;
10358 int saved_pretend_args = 0;
10359 int saved_regs = 0;
10360 unsigned int args_to_push;
10361 arm_stack_offsets *offsets;
10362
10363 func_type = arm_current_func_type ();
10364
10365 /* Naked functions don't have prologues. */
10366 if (IS_NAKED (func_type))
10367 return;
10368
10369 /* Make a copy of c_f_p_a_s as we may need to modify it locally. */
10370 args_to_push = current_function_pretend_args_size;
10371
10372 /* Compute which register we will have to save onto the stack. */
10373 live_regs_mask = arm_compute_save_reg_mask ();
10374
10375 ip_rtx = gen_rtx_REG (SImode, IP_REGNUM);
10376
10377 if (frame_pointer_needed)
10378 {
10379 if (IS_INTERRUPT (func_type))
10380 {
10381 /* Interrupt functions must not corrupt any registers.
10382 Creating a frame pointer however, corrupts the IP
10383 register, so we must push it first. */
10384 insn = emit_multi_reg_push (1 << IP_REGNUM);
10385
10386 /* Do not set RTX_FRAME_RELATED_P on this insn.
10387 The dwarf stack unwinding code only wants to see one
10388 stack decrement per function, and this is not it. If
10389 this instruction is labeled as being part of the frame
10390 creation sequence then dwarf2out_frame_debug_expr will
10391 abort when it encounters the assignment of IP to FP
10392 later on, since the use of SP here establishes SP as
10393 the CFA register and not IP.
10394
10395 Anyway this instruction is not really part of the stack
10396 frame creation although it is part of the prologue. */
10397 }
10398 else if (IS_NESTED (func_type))
10399 {
10400 /* The Static chain register is the same as the IP register
10401 used as a scratch register during stack frame creation.
10402 To get around this need to find somewhere to store IP
10403 whilst the frame is being created. We try the following
10404 places in order:
10405
10406 1. The last argument register.
10407 2. A slot on the stack above the frame. (This only
10408 works if the function is not a varargs function).
10409 3. Register r3, after pushing the argument registers
10410 onto the stack.
10411
10412 Note - we only need to tell the dwarf2 backend about the SP
10413 adjustment in the second variant; the static chain register
10414 doesn't need to be unwound, as it doesn't contain a value
10415 inherited from the caller. */
10416
10417 if (regs_ever_live[3] == 0)
10418 {
10419 insn = gen_rtx_REG (SImode, 3);
10420 insn = gen_rtx_SET (SImode, insn, ip_rtx);
10421 insn = emit_insn (insn);
10422 }
10423 else if (args_to_push == 0)
10424 {
10425 rtx dwarf;
10426 insn = gen_rtx_PRE_DEC (SImode, stack_pointer_rtx);
10427 insn = gen_rtx_MEM (SImode, insn);
10428 insn = gen_rtx_SET (VOIDmode, insn, ip_rtx);
10429 insn = emit_insn (insn);
10430
10431 fp_offset = 4;
10432
10433 /* Just tell the dwarf backend that we adjusted SP. */
10434 dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10435 gen_rtx_PLUS (SImode, stack_pointer_rtx,
10436 GEN_INT (-fp_offset)));
10437 RTX_FRAME_RELATED_P (insn) = 1;
10438 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10439 dwarf, REG_NOTES (insn));
10440 }
10441 else
10442 {
10443 /* Store the args on the stack. */
10444 if (cfun->machine->uses_anonymous_args)
10445 insn = emit_multi_reg_push
10446 ((0xf0 >> (args_to_push / 4)) & 0xf);
10447 else
10448 insn = emit_insn
10449 (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
10450 GEN_INT (- args_to_push)));
10451
10452 RTX_FRAME_RELATED_P (insn) = 1;
10453
10454 saved_pretend_args = 1;
10455 fp_offset = args_to_push;
10456 args_to_push = 0;
10457
10458 /* Now reuse r3 to preserve IP. */
10459 insn = gen_rtx_REG (SImode, 3);
10460 insn = gen_rtx_SET (SImode, insn, ip_rtx);
10461 (void) emit_insn (insn);
10462 }
10463 }
10464
10465 if (fp_offset)
10466 {
10467 insn = gen_rtx_PLUS (SImode, stack_pointer_rtx, GEN_INT (fp_offset));
10468 insn = gen_rtx_SET (SImode, ip_rtx, insn);
10469 }
10470 else
10471 insn = gen_movsi (ip_rtx, stack_pointer_rtx);
10472
10473 insn = emit_insn (insn);
10474 RTX_FRAME_RELATED_P (insn) = 1;
10475 }
10476
10477 if (args_to_push)
10478 {
10479 /* Push the argument registers, or reserve space for them. */
10480 if (cfun->machine->uses_anonymous_args)
10481 insn = emit_multi_reg_push
10482 ((0xf0 >> (args_to_push / 4)) & 0xf);
10483 else
10484 insn = emit_insn
10485 (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
10486 GEN_INT (- args_to_push)));
10487 RTX_FRAME_RELATED_P (insn) = 1;
10488 }
10489
10490 /* If this is an interrupt service routine, and the link register
10491 is going to be pushed, and we are not creating a stack frame,
10492 (which would involve an extra push of IP and a pop in the epilogue)
10493 subtracting four from LR now will mean that the function return
10494 can be done with a single instruction. */
10495 if ((func_type == ARM_FT_ISR || func_type == ARM_FT_FIQ)
10496 && (live_regs_mask & (1 << LR_REGNUM)) != 0
10497 && ! frame_pointer_needed)
10498 emit_insn (gen_rtx_SET (SImode,
10499 gen_rtx_REG (SImode, LR_REGNUM),
10500 gen_rtx_PLUS (SImode,
10501 gen_rtx_REG (SImode, LR_REGNUM),
10502 GEN_INT (-4))));
10503
10504 if (live_regs_mask)
10505 {
10506 insn = emit_multi_reg_push (live_regs_mask);
10507 saved_regs += bit_count (live_regs_mask) * 4;
10508 RTX_FRAME_RELATED_P (insn) = 1;
10509 }
10510
10511 if (TARGET_IWMMXT)
10512 for (reg = LAST_IWMMXT_REGNUM; reg >= FIRST_IWMMXT_REGNUM; reg--)
10513 if (regs_ever_live[reg] && ! call_used_regs [reg])
10514 {
10515 insn = gen_rtx_PRE_DEC (V2SImode, stack_pointer_rtx);
10516 insn = gen_rtx_MEM (V2SImode, insn);
10517 insn = emit_insn (gen_rtx_SET (VOIDmode, insn,
10518 gen_rtx_REG (V2SImode, reg)));
10519 RTX_FRAME_RELATED_P (insn) = 1;
10520 saved_regs += 8;
10521 }
10522
10523 if (! IS_VOLATILE (func_type))
10524 {
10525 int start_reg;
10526
10527 /* Save any floating point call-saved registers used by this
10528 function. */
10529 if (arm_fpu_arch == FPUTYPE_FPA_EMU2)
10530 {
10531 for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--)
10532 if (regs_ever_live[reg] && !call_used_regs[reg])
10533 {
10534 insn = gen_rtx_PRE_DEC (XFmode, stack_pointer_rtx);
10535 insn = gen_rtx_MEM (XFmode, insn);
10536 insn = emit_insn (gen_rtx_SET (VOIDmode, insn,
10537 gen_rtx_REG (XFmode, reg)));
10538 RTX_FRAME_RELATED_P (insn) = 1;
10539 saved_regs += 12;
10540 }
10541 }
10542 else
10543 {
10544 start_reg = LAST_FPA_REGNUM;
10545
10546 for (reg = LAST_FPA_REGNUM; reg >= FIRST_FPA_REGNUM; reg--)
10547 {
10548 if (regs_ever_live[reg] && !call_used_regs[reg])
10549 {
10550 if (start_reg - reg == 3)
10551 {
10552 insn = emit_sfm (reg, 4);
10553 RTX_FRAME_RELATED_P (insn) = 1;
10554 saved_regs += 48;
10555 start_reg = reg - 1;
10556 }
10557 }
10558 else
10559 {
10560 if (start_reg != reg)
10561 {
10562 insn = emit_sfm (reg + 1, start_reg - reg);
10563 RTX_FRAME_RELATED_P (insn) = 1;
10564 saved_regs += (start_reg - reg) * 12;
10565 }
10566 start_reg = reg - 1;
10567 }
10568 }
10569
10570 if (start_reg != reg)
10571 {
10572 insn = emit_sfm (reg + 1, start_reg - reg);
10573 saved_regs += (start_reg - reg) * 12;
10574 RTX_FRAME_RELATED_P (insn) = 1;
10575 }
10576 }
10577 if (TARGET_HARD_FLOAT && TARGET_VFP)
10578 {
10579 start_reg = FIRST_VFP_REGNUM;
10580
10581 for (reg = FIRST_VFP_REGNUM; reg < LAST_VFP_REGNUM; reg += 2)
10582 {
10583 if ((!regs_ever_live[reg] || call_used_regs[reg])
10584 && (!regs_ever_live[reg + 1] || call_used_regs[reg + 1]))
10585 {
10586 if (start_reg != reg)
10587 saved_regs += vfp_emit_fstmx (start_reg,
10588 (reg - start_reg) / 2);
10589 start_reg = reg + 2;
10590 }
10591 }
10592 if (start_reg != reg)
10593 saved_regs += vfp_emit_fstmx (start_reg,
10594 (reg - start_reg) / 2);
10595 }
10596 }
10597
10598 if (frame_pointer_needed)
10599 {
10600 /* Create the new frame pointer. */
10601 insn = GEN_INT (-(4 + args_to_push + fp_offset));
10602 insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, ip_rtx, insn));
10603 RTX_FRAME_RELATED_P (insn) = 1;
10604
10605 if (IS_NESTED (func_type))
10606 {
10607 /* Recover the static chain register. */
10608 if (regs_ever_live [3] == 0
10609 || saved_pretend_args)
10610 insn = gen_rtx_REG (SImode, 3);
10611 else /* if (current_function_pretend_args_size == 0) */
10612 {
10613 insn = gen_rtx_PLUS (SImode, hard_frame_pointer_rtx,
10614 GEN_INT (4));
10615 insn = gen_rtx_MEM (SImode, insn);
10616 }
10617
10618 emit_insn (gen_rtx_SET (SImode, ip_rtx, insn));
10619 /* Add a USE to stop propagate_one_insn() from barfing. */
10620 emit_insn (gen_prologue_use (ip_rtx));
10621 }
10622 }
10623
10624 offsets = arm_get_frame_offsets ();
10625 if (offsets->outgoing_args != offsets->saved_args + saved_regs)
10626 {
10627 /* This add can produce multiple insns for a large constant, so we
10628 need to get tricky. */
10629 rtx last = get_last_insn ();
10630
10631 amount = GEN_INT (offsets->saved_args + saved_regs
10632 - offsets->outgoing_args);
10633
10634 insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
10635 amount));
10636 do
10637 {
10638 last = last ? NEXT_INSN (last) : get_insns ();
10639 RTX_FRAME_RELATED_P (last) = 1;
10640 }
10641 while (last != insn);
10642
10643 /* If the frame pointer is needed, emit a special barrier that
10644 will prevent the scheduler from moving stores to the frame
10645 before the stack adjustment. */
10646 if (frame_pointer_needed)
10647 insn = emit_insn (gen_stack_tie (stack_pointer_rtx,
10648 hard_frame_pointer_rtx));
10649 }
10650
10651 /* If we are profiling, make sure no instructions are scheduled before
10652 the call to mcount. Similarly if the user has requested no
10653 scheduling in the prolog. */
10654 if (current_function_profile || TARGET_NO_SCHED_PRO)
10655 emit_insn (gen_blockage ());
10656
10657 /* If the link register is being kept alive, with the return address in it,
10658 then make sure that it does not get reused by the ce2 pass. */
10659 if ((live_regs_mask & (1 << LR_REGNUM)) == 0)
10660 {
10661 emit_insn (gen_prologue_use (gen_rtx_REG (SImode, LR_REGNUM)));
10662 cfun->machine->lr_save_eliminated = 1;
10663 }
10664 }
10665 \f
10666 /* If CODE is 'd', then the X is a condition operand and the instruction
10667 should only be executed if the condition is true.
10668 if CODE is 'D', then the X is a condition operand and the instruction
10669 should only be executed if the condition is false: however, if the mode
10670 of the comparison is CCFPEmode, then always execute the instruction -- we
10671 do this because in these circumstances !GE does not necessarily imply LT;
10672 in these cases the instruction pattern will take care to make sure that
10673 an instruction containing %d will follow, thereby undoing the effects of
10674 doing this instruction unconditionally.
10675 If CODE is 'N' then X is a floating point operand that must be negated
10676 before output.
10677 If CODE is 'B' then output a bitwise inverted value of X (a const int).
10678 If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */
10679 void
10680 arm_print_operand (FILE *stream, rtx x, int code)
10681 {
10682 switch (code)
10683 {
10684 case '@':
10685 fputs (ASM_COMMENT_START, stream);
10686 return;
10687
10688 case '_':
10689 fputs (user_label_prefix, stream);
10690 return;
10691
10692 case '|':
10693 fputs (REGISTER_PREFIX, stream);
10694 return;
10695
10696 case '?':
10697 if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4)
10698 {
10699 if (TARGET_THUMB || current_insn_predicate != NULL)
10700 abort ();
10701
10702 fputs (arm_condition_codes[arm_current_cc], stream);
10703 }
10704 else if (current_insn_predicate)
10705 {
10706 enum arm_cond_code code;
10707
10708 if (TARGET_THUMB)
10709 abort ();
10710
10711 code = get_arm_condition_code (current_insn_predicate);
10712 fputs (arm_condition_codes[code], stream);
10713 }
10714 return;
10715
10716 case 'N':
10717 {
10718 REAL_VALUE_TYPE r;
10719 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
10720 r = REAL_VALUE_NEGATE (r);
10721 fprintf (stream, "%s", fp_const_from_val (&r));
10722 }
10723 return;
10724
10725 case 'B':
10726 if (GET_CODE (x) == CONST_INT)
10727 {
10728 HOST_WIDE_INT val;
10729 val = ARM_SIGN_EXTEND (~INTVAL (x));
10730 fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val);
10731 }
10732 else
10733 {
10734 putc ('~', stream);
10735 output_addr_const (stream, x);
10736 }
10737 return;
10738
10739 case 'i':
10740 fprintf (stream, "%s", arithmetic_instr (x, 1));
10741 return;
10742
10743 /* Truncate Cirrus shift counts. */
10744 case 's':
10745 if (GET_CODE (x) == CONST_INT)
10746 {
10747 fprintf (stream, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x3f);
10748 return;
10749 }
10750 arm_print_operand (stream, x, 0);
10751 return;
10752
10753 case 'I':
10754 fprintf (stream, "%s", arithmetic_instr (x, 0));
10755 return;
10756
10757 case 'S':
10758 {
10759 HOST_WIDE_INT val;
10760 const char * shift = shift_op (x, &val);
10761
10762 if (shift)
10763 {
10764 fprintf (stream, ", %s ", shift_op (x, &val));
10765 if (val == -1)
10766 arm_print_operand (stream, XEXP (x, 1), 0);
10767 else
10768 fprintf (stream, "#" HOST_WIDE_INT_PRINT_DEC, val);
10769 }
10770 }
10771 return;
10772
10773 /* An explanation of the 'Q', 'R' and 'H' register operands:
10774
10775 In a pair of registers containing a DI or DF value the 'Q'
10776 operand returns the register number of the register containing
10777 the least significant part of the value. The 'R' operand returns
10778 the register number of the register containing the most
10779 significant part of the value.
10780
10781 The 'H' operand returns the higher of the two register numbers.
10782 On a run where WORDS_BIG_ENDIAN is true the 'H' operand is the
10783 same as the 'Q' operand, since the most significant part of the
10784 value is held in the lower number register. The reverse is true
10785 on systems where WORDS_BIG_ENDIAN is false.
10786
10787 The purpose of these operands is to distinguish between cases
10788 where the endian-ness of the values is important (for example
10789 when they are added together), and cases where the endian-ness
10790 is irrelevant, but the order of register operations is important.
10791 For example when loading a value from memory into a register
10792 pair, the endian-ness does not matter. Provided that the value
10793 from the lower memory address is put into the lower numbered
10794 register, and the value from the higher address is put into the
10795 higher numbered register, the load will work regardless of whether
10796 the value being loaded is big-wordian or little-wordian. The
10797 order of the two register loads can matter however, if the address
10798 of the memory location is actually held in one of the registers
10799 being overwritten by the load. */
10800 case 'Q':
10801 if (REGNO (x) > LAST_ARM_REGNUM)
10802 abort ();
10803 asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0));
10804 return;
10805
10806 case 'R':
10807 if (REGNO (x) > LAST_ARM_REGNUM)
10808 abort ();
10809 asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1));
10810 return;
10811
10812 case 'H':
10813 if (REGNO (x) > LAST_ARM_REGNUM)
10814 abort ();
10815 asm_fprintf (stream, "%r", REGNO (x) + 1);
10816 return;
10817
10818 case 'm':
10819 asm_fprintf (stream, "%r",
10820 GET_CODE (XEXP (x, 0)) == REG
10821 ? REGNO (XEXP (x, 0)) : REGNO (XEXP (XEXP (x, 0), 0)));
10822 return;
10823
10824 case 'M':
10825 asm_fprintf (stream, "{%r-%r}",
10826 REGNO (x),
10827 REGNO (x) + ARM_NUM_REGS (GET_MODE (x)) - 1);
10828 return;
10829
10830 case 'd':
10831 /* CONST_TRUE_RTX means always -- that's the default. */
10832 if (x == const_true_rtx)
10833 return;
10834
10835 fputs (arm_condition_codes[get_arm_condition_code (x)],
10836 stream);
10837 return;
10838
10839 case 'D':
10840 /* CONST_TRUE_RTX means not always -- ie never. We shouldn't ever
10841 want to do that. */
10842 if (x == const_true_rtx)
10843 abort ();
10844
10845 fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE
10846 (get_arm_condition_code (x))],
10847 stream);
10848 return;
10849
10850 /* Cirrus registers can be accessed in a variety of ways:
10851 single floating point (f)
10852 double floating point (d)
10853 32bit integer (fx)
10854 64bit integer (dx). */
10855 case 'W': /* Cirrus register in F mode. */
10856 case 'X': /* Cirrus register in D mode. */
10857 case 'Y': /* Cirrus register in FX mode. */
10858 case 'Z': /* Cirrus register in DX mode. */
10859 if (GET_CODE (x) != REG || REGNO_REG_CLASS (REGNO (x)) != CIRRUS_REGS)
10860 abort ();
10861
10862 fprintf (stream, "mv%s%s",
10863 code == 'W' ? "f"
10864 : code == 'X' ? "d"
10865 : code == 'Y' ? "fx" : "dx", reg_names[REGNO (x)] + 2);
10866
10867 return;
10868
10869 /* Print cirrus register in the mode specified by the register's mode. */
10870 case 'V':
10871 {
10872 int mode = GET_MODE (x);
10873
10874 if (GET_CODE (x) != REG || REGNO_REG_CLASS (REGNO (x)) != CIRRUS_REGS)
10875 abort ();
10876
10877 fprintf (stream, "mv%s%s",
10878 mode == DFmode ? "d"
10879 : mode == SImode ? "fx"
10880 : mode == DImode ? "dx"
10881 : "f", reg_names[REGNO (x)] + 2);
10882
10883 return;
10884 }
10885
10886 case 'U':
10887 if (GET_CODE (x) != REG
10888 || REGNO (x) < FIRST_IWMMXT_GR_REGNUM
10889 || REGNO (x) > LAST_IWMMXT_GR_REGNUM)
10890 /* Bad value for wCG register number. */
10891 abort ();
10892 else
10893 fprintf (stream, "%d", REGNO (x) - FIRST_IWMMXT_GR_REGNUM);
10894 return;
10895
10896 /* Print an iWMMXt control register name. */
10897 case 'w':
10898 if (GET_CODE (x) != CONST_INT
10899 || INTVAL (x) < 0
10900 || INTVAL (x) >= 16)
10901 /* Bad value for wC register number. */
10902 abort ();
10903 else
10904 {
10905 static const char * wc_reg_names [16] =
10906 {
10907 "wCID", "wCon", "wCSSF", "wCASF",
10908 "wC4", "wC5", "wC6", "wC7",
10909 "wCGR0", "wCGR1", "wCGR2", "wCGR3",
10910 "wC12", "wC13", "wC14", "wC15"
10911 };
10912
10913 fprintf (stream, wc_reg_names [INTVAL (x)]);
10914 }
10915 return;
10916
10917 /* Print a VFP double precision register name. */
10918 case 'P':
10919 {
10920 int mode = GET_MODE (x);
10921 int num;
10922
10923 if (mode != DImode && mode != DFmode)
10924 abort ();
10925
10926 if (GET_CODE (x) != REG
10927 || !IS_VFP_REGNUM (REGNO (x)))
10928 abort ();
10929
10930 num = REGNO(x) - FIRST_VFP_REGNUM;
10931 if (num & 1)
10932 abort ();
10933
10934 fprintf (stream, "d%d", num >> 1);
10935 }
10936 return;
10937
10938 default:
10939 if (x == 0)
10940 abort ();
10941
10942 if (GET_CODE (x) == REG)
10943 asm_fprintf (stream, "%r", REGNO (x));
10944 else if (GET_CODE (x) == MEM)
10945 {
10946 output_memory_reference_mode = GET_MODE (x);
10947 output_address (XEXP (x, 0));
10948 }
10949 else if (GET_CODE (x) == CONST_DOUBLE)
10950 fprintf (stream, "#%s", fp_immediate_constant (x));
10951 else if (GET_CODE (x) == NEG)
10952 abort (); /* This should never happen now. */
10953 else
10954 {
10955 fputc ('#', stream);
10956 output_addr_const (stream, x);
10957 }
10958 }
10959 }
10960 \f
10961 #ifndef AOF_ASSEMBLER
10962 /* Target hook for assembling integer objects. The ARM version needs to
10963 handle word-sized values specially. */
10964 static bool
10965 arm_assemble_integer (rtx x, unsigned int size, int aligned_p)
10966 {
10967 if (size == UNITS_PER_WORD && aligned_p)
10968 {
10969 fputs ("\t.word\t", asm_out_file);
10970 output_addr_const (asm_out_file, x);
10971
10972 /* Mark symbols as position independent. We only do this in the
10973 .text segment, not in the .data segment. */
10974 if (NEED_GOT_RELOC && flag_pic && making_const_table &&
10975 (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF))
10976 {
10977 if (GET_CODE (x) == SYMBOL_REF
10978 && (CONSTANT_POOL_ADDRESS_P (x)
10979 || SYMBOL_REF_LOCAL_P (x)))
10980 fputs ("(GOTOFF)", asm_out_file);
10981 else if (GET_CODE (x) == LABEL_REF)
10982 fputs ("(GOTOFF)", asm_out_file);
10983 else
10984 fputs ("(GOT)", asm_out_file);
10985 }
10986 fputc ('\n', asm_out_file);
10987 return true;
10988 }
10989
10990 if (VECTOR_MODE_SUPPORTED_P (GET_MODE (x)))
10991 {
10992 int i, units;
10993
10994 if (GET_CODE (x) != CONST_VECTOR)
10995 abort ();
10996
10997 units = CONST_VECTOR_NUNITS (x);
10998
10999 switch (GET_MODE (x))
11000 {
11001 case V2SImode: size = 4; break;
11002 case V4HImode: size = 2; break;
11003 case V8QImode: size = 1; break;
11004 default:
11005 abort ();
11006 }
11007
11008 for (i = 0; i < units; i++)
11009 {
11010 rtx elt;
11011
11012 elt = CONST_VECTOR_ELT (x, i);
11013 assemble_integer
11014 (elt, size, i == 0 ? BIGGEST_ALIGNMENT : size * BITS_PER_UNIT, 1);
11015 }
11016
11017 return true;
11018 }
11019
11020 return default_assemble_integer (x, size, aligned_p);
11021 }
11022 #endif
11023 \f
11024 /* A finite state machine takes care of noticing whether or not instructions
11025 can be conditionally executed, and thus decrease execution time and code
11026 size by deleting branch instructions. The fsm is controlled by
11027 final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */
11028
11029 /* The state of the fsm controlling condition codes are:
11030 0: normal, do nothing special
11031 1: make ASM_OUTPUT_OPCODE not output this instruction
11032 2: make ASM_OUTPUT_OPCODE not output this instruction
11033 3: make instructions conditional
11034 4: make instructions conditional
11035
11036 State transitions (state->state by whom under condition):
11037 0 -> 1 final_prescan_insn if the `target' is a label
11038 0 -> 2 final_prescan_insn if the `target' is an unconditional branch
11039 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
11040 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
11041 3 -> 0 (*targetm.asm_out.internal_label) if the `target' label is reached
11042 (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
11043 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
11044 (the target insn is arm_target_insn).
11045
11046 If the jump clobbers the conditions then we use states 2 and 4.
11047
11048 A similar thing can be done with conditional return insns.
11049
11050 XXX In case the `target' is an unconditional branch, this conditionalising
11051 of the instructions always reduces code size, but not always execution
11052 time. But then, I want to reduce the code size to somewhere near what
11053 /bin/cc produces. */
11054
11055 /* Returns the index of the ARM condition code string in
11056 `arm_condition_codes'. COMPARISON should be an rtx like
11057 `(eq (...) (...))'. */
11058 static enum arm_cond_code
11059 get_arm_condition_code (rtx comparison)
11060 {
11061 enum machine_mode mode = GET_MODE (XEXP (comparison, 0));
11062 int code;
11063 enum rtx_code comp_code = GET_CODE (comparison);
11064
11065 if (GET_MODE_CLASS (mode) != MODE_CC)
11066 mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0),
11067 XEXP (comparison, 1));
11068
11069 switch (mode)
11070 {
11071 case CC_DNEmode: code = ARM_NE; goto dominance;
11072 case CC_DEQmode: code = ARM_EQ; goto dominance;
11073 case CC_DGEmode: code = ARM_GE; goto dominance;
11074 case CC_DGTmode: code = ARM_GT; goto dominance;
11075 case CC_DLEmode: code = ARM_LE; goto dominance;
11076 case CC_DLTmode: code = ARM_LT; goto dominance;
11077 case CC_DGEUmode: code = ARM_CS; goto dominance;
11078 case CC_DGTUmode: code = ARM_HI; goto dominance;
11079 case CC_DLEUmode: code = ARM_LS; goto dominance;
11080 case CC_DLTUmode: code = ARM_CC;
11081
11082 dominance:
11083 if (comp_code != EQ && comp_code != NE)
11084 abort ();
11085
11086 if (comp_code == EQ)
11087 return ARM_INVERSE_CONDITION_CODE (code);
11088 return code;
11089
11090 case CC_NOOVmode:
11091 switch (comp_code)
11092 {
11093 case NE: return ARM_NE;
11094 case EQ: return ARM_EQ;
11095 case GE: return ARM_PL;
11096 case LT: return ARM_MI;
11097 default: abort ();
11098 }
11099
11100 case CC_Zmode:
11101 switch (comp_code)
11102 {
11103 case NE: return ARM_NE;
11104 case EQ: return ARM_EQ;
11105 default: abort ();
11106 }
11107
11108 case CC_Nmode:
11109 switch (comp_code)
11110 {
11111 case NE: return ARM_MI;
11112 case EQ: return ARM_PL;
11113 default: abort ();
11114 }
11115
11116 case CCFPEmode:
11117 case CCFPmode:
11118 /* These encodings assume that AC=1 in the FPA system control
11119 byte. This allows us to handle all cases except UNEQ and
11120 LTGT. */
11121 switch (comp_code)
11122 {
11123 case GE: return ARM_GE;
11124 case GT: return ARM_GT;
11125 case LE: return ARM_LS;
11126 case LT: return ARM_MI;
11127 case NE: return ARM_NE;
11128 case EQ: return ARM_EQ;
11129 case ORDERED: return ARM_VC;
11130 case UNORDERED: return ARM_VS;
11131 case UNLT: return ARM_LT;
11132 case UNLE: return ARM_LE;
11133 case UNGT: return ARM_HI;
11134 case UNGE: return ARM_PL;
11135 /* UNEQ and LTGT do not have a representation. */
11136 case UNEQ: /* Fall through. */
11137 case LTGT: /* Fall through. */
11138 default: abort ();
11139 }
11140
11141 case CC_SWPmode:
11142 switch (comp_code)
11143 {
11144 case NE: return ARM_NE;
11145 case EQ: return ARM_EQ;
11146 case GE: return ARM_LE;
11147 case GT: return ARM_LT;
11148 case LE: return ARM_GE;
11149 case LT: return ARM_GT;
11150 case GEU: return ARM_LS;
11151 case GTU: return ARM_CC;
11152 case LEU: return ARM_CS;
11153 case LTU: return ARM_HI;
11154 default: abort ();
11155 }
11156
11157 case CC_Cmode:
11158 switch (comp_code)
11159 {
11160 case LTU: return ARM_CS;
11161 case GEU: return ARM_CC;
11162 default: abort ();
11163 }
11164
11165 case CCmode:
11166 switch (comp_code)
11167 {
11168 case NE: return ARM_NE;
11169 case EQ: return ARM_EQ;
11170 case GE: return ARM_GE;
11171 case GT: return ARM_GT;
11172 case LE: return ARM_LE;
11173 case LT: return ARM_LT;
11174 case GEU: return ARM_CS;
11175 case GTU: return ARM_HI;
11176 case LEU: return ARM_LS;
11177 case LTU: return ARM_CC;
11178 default: abort ();
11179 }
11180
11181 default: abort ();
11182 }
11183
11184 abort ();
11185 }
11186
11187 void
11188 arm_final_prescan_insn (rtx insn)
11189 {
11190 /* BODY will hold the body of INSN. */
11191 rtx body = PATTERN (insn);
11192
11193 /* This will be 1 if trying to repeat the trick, and things need to be
11194 reversed if it appears to fail. */
11195 int reverse = 0;
11196
11197 /* JUMP_CLOBBERS will be one implies that the conditions if a branch is
11198 taken are clobbered, even if the rtl suggests otherwise. It also
11199 means that we have to grub around within the jump expression to find
11200 out what the conditions are when the jump isn't taken. */
11201 int jump_clobbers = 0;
11202
11203 /* If we start with a return insn, we only succeed if we find another one. */
11204 int seeking_return = 0;
11205
11206 /* START_INSN will hold the insn from where we start looking. This is the
11207 first insn after the following code_label if REVERSE is true. */
11208 rtx start_insn = insn;
11209
11210 /* If in state 4, check if the target branch is reached, in order to
11211 change back to state 0. */
11212 if (arm_ccfsm_state == 4)
11213 {
11214 if (insn == arm_target_insn)
11215 {
11216 arm_target_insn = NULL;
11217 arm_ccfsm_state = 0;
11218 }
11219 return;
11220 }
11221
11222 /* If in state 3, it is possible to repeat the trick, if this insn is an
11223 unconditional branch to a label, and immediately following this branch
11224 is the previous target label which is only used once, and the label this
11225 branch jumps to is not too far off. */
11226 if (arm_ccfsm_state == 3)
11227 {
11228 if (simplejump_p (insn))
11229 {
11230 start_insn = next_nonnote_insn (start_insn);
11231 if (GET_CODE (start_insn) == BARRIER)
11232 {
11233 /* XXX Isn't this always a barrier? */
11234 start_insn = next_nonnote_insn (start_insn);
11235 }
11236 if (GET_CODE (start_insn) == CODE_LABEL
11237 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
11238 && LABEL_NUSES (start_insn) == 1)
11239 reverse = TRUE;
11240 else
11241 return;
11242 }
11243 else if (GET_CODE (body) == RETURN)
11244 {
11245 start_insn = next_nonnote_insn (start_insn);
11246 if (GET_CODE (start_insn) == BARRIER)
11247 start_insn = next_nonnote_insn (start_insn);
11248 if (GET_CODE (start_insn) == CODE_LABEL
11249 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
11250 && LABEL_NUSES (start_insn) == 1)
11251 {
11252 reverse = TRUE;
11253 seeking_return = 1;
11254 }
11255 else
11256 return;
11257 }
11258 else
11259 return;
11260 }
11261
11262 if (arm_ccfsm_state != 0 && !reverse)
11263 abort ();
11264 if (GET_CODE (insn) != JUMP_INSN)
11265 return;
11266
11267 /* This jump might be paralleled with a clobber of the condition codes
11268 the jump should always come first */
11269 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0)
11270 body = XVECEXP (body, 0, 0);
11271
11272 if (reverse
11273 || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
11274 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE))
11275 {
11276 int insns_skipped;
11277 int fail = FALSE, succeed = FALSE;
11278 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
11279 int then_not_else = TRUE;
11280 rtx this_insn = start_insn, label = 0;
11281
11282 /* If the jump cannot be done with one instruction, we cannot
11283 conditionally execute the instruction in the inverse case. */
11284 if (get_attr_conds (insn) == CONDS_JUMP_CLOB)
11285 {
11286 jump_clobbers = 1;
11287 return;
11288 }
11289
11290 /* Register the insn jumped to. */
11291 if (reverse)
11292 {
11293 if (!seeking_return)
11294 label = XEXP (SET_SRC (body), 0);
11295 }
11296 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF)
11297 label = XEXP (XEXP (SET_SRC (body), 1), 0);
11298 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF)
11299 {
11300 label = XEXP (XEXP (SET_SRC (body), 2), 0);
11301 then_not_else = FALSE;
11302 }
11303 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN)
11304 seeking_return = 1;
11305 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN)
11306 {
11307 seeking_return = 1;
11308 then_not_else = FALSE;
11309 }
11310 else
11311 abort ();
11312
11313 /* See how many insns this branch skips, and what kind of insns. If all
11314 insns are okay, and the label or unconditional branch to the same
11315 label is not too far away, succeed. */
11316 for (insns_skipped = 0;
11317 !fail && !succeed && insns_skipped++ < max_insns_skipped;)
11318 {
11319 rtx scanbody;
11320
11321 this_insn = next_nonnote_insn (this_insn);
11322 if (!this_insn)
11323 break;
11324
11325 switch (GET_CODE (this_insn))
11326 {
11327 case CODE_LABEL:
11328 /* Succeed if it is the target label, otherwise fail since
11329 control falls in from somewhere else. */
11330 if (this_insn == label)
11331 {
11332 if (jump_clobbers)
11333 {
11334 arm_ccfsm_state = 2;
11335 this_insn = next_nonnote_insn (this_insn);
11336 }
11337 else
11338 arm_ccfsm_state = 1;
11339 succeed = TRUE;
11340 }
11341 else
11342 fail = TRUE;
11343 break;
11344
11345 case BARRIER:
11346 /* Succeed if the following insn is the target label.
11347 Otherwise fail.
11348 If return insns are used then the last insn in a function
11349 will be a barrier. */
11350 this_insn = next_nonnote_insn (this_insn);
11351 if (this_insn && this_insn == label)
11352 {
11353 if (jump_clobbers)
11354 {
11355 arm_ccfsm_state = 2;
11356 this_insn = next_nonnote_insn (this_insn);
11357 }
11358 else
11359 arm_ccfsm_state = 1;
11360 succeed = TRUE;
11361 }
11362 else
11363 fail = TRUE;
11364 break;
11365
11366 case CALL_INSN:
11367 /* The AAPCS says that conditional calls should not be
11368 used since they make interworking inefficient (the
11369 linker can't transform BL<cond> into BLX). That's
11370 only a problem if the machine has BLX. */
11371 if (arm_arch5)
11372 {
11373 fail = TRUE;
11374 break;
11375 }
11376
11377 /* Succeed if the following insn is the target label, or
11378 if the following two insns are a barrier and the
11379 target label. */
11380 this_insn = next_nonnote_insn (this_insn);
11381 if (this_insn && GET_CODE (this_insn) == BARRIER)
11382 this_insn = next_nonnote_insn (this_insn);
11383
11384 if (this_insn && this_insn == label
11385 && insns_skipped < max_insns_skipped)
11386 {
11387 if (jump_clobbers)
11388 {
11389 arm_ccfsm_state = 2;
11390 this_insn = next_nonnote_insn (this_insn);
11391 }
11392 else
11393 arm_ccfsm_state = 1;
11394 succeed = TRUE;
11395 }
11396 else
11397 fail = TRUE;
11398 break;
11399
11400 case JUMP_INSN:
11401 /* If this is an unconditional branch to the same label, succeed.
11402 If it is to another label, do nothing. If it is conditional,
11403 fail. */
11404 /* XXX Probably, the tests for SET and the PC are
11405 unnecessary. */
11406
11407 scanbody = PATTERN (this_insn);
11408 if (GET_CODE (scanbody) == SET
11409 && GET_CODE (SET_DEST (scanbody)) == PC)
11410 {
11411 if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF
11412 && XEXP (SET_SRC (scanbody), 0) == label && !reverse)
11413 {
11414 arm_ccfsm_state = 2;
11415 succeed = TRUE;
11416 }
11417 else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE)
11418 fail = TRUE;
11419 }
11420 /* Fail if a conditional return is undesirable (eg on a
11421 StrongARM), but still allow this if optimizing for size. */
11422 else if (GET_CODE (scanbody) == RETURN
11423 && !use_return_insn (TRUE, NULL)
11424 && !optimize_size)
11425 fail = TRUE;
11426 else if (GET_CODE (scanbody) == RETURN
11427 && seeking_return)
11428 {
11429 arm_ccfsm_state = 2;
11430 succeed = TRUE;
11431 }
11432 else if (GET_CODE (scanbody) == PARALLEL)
11433 {
11434 switch (get_attr_conds (this_insn))
11435 {
11436 case CONDS_NOCOND:
11437 break;
11438 default:
11439 fail = TRUE;
11440 break;
11441 }
11442 }
11443 else
11444 fail = TRUE; /* Unrecognized jump (eg epilogue). */
11445
11446 break;
11447
11448 case INSN:
11449 /* Instructions using or affecting the condition codes make it
11450 fail. */
11451 scanbody = PATTERN (this_insn);
11452 if (!(GET_CODE (scanbody) == SET
11453 || GET_CODE (scanbody) == PARALLEL)
11454 || get_attr_conds (this_insn) != CONDS_NOCOND)
11455 fail = TRUE;
11456
11457 /* A conditional cirrus instruction must be followed by
11458 a non Cirrus instruction. However, since we
11459 conditionalize instructions in this function and by
11460 the time we get here we can't add instructions
11461 (nops), because shorten_branches() has already been
11462 called, we will disable conditionalizing Cirrus
11463 instructions to be safe. */
11464 if (GET_CODE (scanbody) != USE
11465 && GET_CODE (scanbody) != CLOBBER
11466 && get_attr_cirrus (this_insn) != CIRRUS_NOT)
11467 fail = TRUE;
11468 break;
11469
11470 default:
11471 break;
11472 }
11473 }
11474 if (succeed)
11475 {
11476 if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse))
11477 arm_target_label = CODE_LABEL_NUMBER (label);
11478 else if (seeking_return || arm_ccfsm_state == 2)
11479 {
11480 while (this_insn && GET_CODE (PATTERN (this_insn)) == USE)
11481 {
11482 this_insn = next_nonnote_insn (this_insn);
11483 if (this_insn && (GET_CODE (this_insn) == BARRIER
11484 || GET_CODE (this_insn) == CODE_LABEL))
11485 abort ();
11486 }
11487 if (!this_insn)
11488 {
11489 /* Oh, dear! we ran off the end.. give up. */
11490 recog (PATTERN (insn), insn, NULL);
11491 arm_ccfsm_state = 0;
11492 arm_target_insn = NULL;
11493 return;
11494 }
11495 arm_target_insn = this_insn;
11496 }
11497 else
11498 abort ();
11499 if (jump_clobbers)
11500 {
11501 if (reverse)
11502 abort ();
11503 arm_current_cc =
11504 get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body),
11505 0), 0), 1));
11506 if (GET_CODE (XEXP (XEXP (SET_SRC (body), 0), 0)) == AND)
11507 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
11508 if (GET_CODE (XEXP (SET_SRC (body), 0)) == NE)
11509 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
11510 }
11511 else
11512 {
11513 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
11514 what it was. */
11515 if (!reverse)
11516 arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body),
11517 0));
11518 }
11519
11520 if (reverse || then_not_else)
11521 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
11522 }
11523
11524 /* Restore recog_data (getting the attributes of other insns can
11525 destroy this array, but final.c assumes that it remains intact
11526 across this call; since the insn has been recognized already we
11527 call recog direct). */
11528 recog (PATTERN (insn), insn, NULL);
11529 }
11530 }
11531
11532 /* Returns true if REGNO is a valid register
11533 for holding a quantity of tyoe MODE. */
11534 int
11535 arm_hard_regno_mode_ok (unsigned int regno, enum machine_mode mode)
11536 {
11537 if (GET_MODE_CLASS (mode) == MODE_CC)
11538 return regno == CC_REGNUM || regno == VFPCC_REGNUM;
11539
11540 if (TARGET_THUMB)
11541 /* For the Thumb we only allow values bigger than SImode in
11542 registers 0 - 6, so that there is always a second low
11543 register available to hold the upper part of the value.
11544 We probably we ought to ensure that the register is the
11545 start of an even numbered register pair. */
11546 return (ARM_NUM_REGS (mode) < 2) || (regno < LAST_LO_REGNUM);
11547
11548 if (IS_CIRRUS_REGNUM (regno))
11549 /* We have outlawed SI values in Cirrus registers because they
11550 reside in the lower 32 bits, but SF values reside in the
11551 upper 32 bits. This causes gcc all sorts of grief. We can't
11552 even split the registers into pairs because Cirrus SI values
11553 get sign extended to 64bits-- aldyh. */
11554 return (GET_MODE_CLASS (mode) == MODE_FLOAT) || (mode == DImode);
11555
11556 if (IS_VFP_REGNUM (regno))
11557 {
11558 if (mode == SFmode || mode == SImode)
11559 return TRUE;
11560
11561 /* DFmode values are only valid in even register pairs. */
11562 if (mode == DFmode)
11563 return ((regno - FIRST_VFP_REGNUM) & 1) == 0;
11564 return FALSE;
11565 }
11566
11567 if (IS_IWMMXT_GR_REGNUM (regno))
11568 return mode == SImode;
11569
11570 if (IS_IWMMXT_REGNUM (regno))
11571 return VALID_IWMMXT_REG_MODE (mode);
11572
11573 /* We allow any value to be stored in the general registers.
11574 Restrict doubleword quantities to even register pairs so that we can
11575 use ldrd. */
11576 if (regno <= LAST_ARM_REGNUM)
11577 return !(TARGET_LDRD && GET_MODE_SIZE (mode) > 4 && (regno & 1) != 0);
11578
11579 if ( regno == FRAME_POINTER_REGNUM
11580 || regno == ARG_POINTER_REGNUM)
11581 /* We only allow integers in the fake hard registers. */
11582 return GET_MODE_CLASS (mode) == MODE_INT;
11583
11584 /* The only registers left are the FPA registers
11585 which we only allow to hold FP values. */
11586 return GET_MODE_CLASS (mode) == MODE_FLOAT
11587 && regno >= FIRST_FPA_REGNUM
11588 && regno <= LAST_FPA_REGNUM;
11589 }
11590
11591 int
11592 arm_regno_class (int regno)
11593 {
11594 if (TARGET_THUMB)
11595 {
11596 if (regno == STACK_POINTER_REGNUM)
11597 return STACK_REG;
11598 if (regno == CC_REGNUM)
11599 return CC_REG;
11600 if (regno < 8)
11601 return LO_REGS;
11602 return HI_REGS;
11603 }
11604
11605 if ( regno <= LAST_ARM_REGNUM
11606 || regno == FRAME_POINTER_REGNUM
11607 || regno == ARG_POINTER_REGNUM)
11608 return GENERAL_REGS;
11609
11610 if (regno == CC_REGNUM || regno == VFPCC_REGNUM)
11611 return NO_REGS;
11612
11613 if (IS_CIRRUS_REGNUM (regno))
11614 return CIRRUS_REGS;
11615
11616 if (IS_VFP_REGNUM (regno))
11617 return VFP_REGS;
11618
11619 if (IS_IWMMXT_REGNUM (regno))
11620 return IWMMXT_REGS;
11621
11622 if (IS_IWMMXT_GR_REGNUM (regno))
11623 return IWMMXT_GR_REGS;
11624
11625 return FPA_REGS;
11626 }
11627
11628 /* Handle a special case when computing the offset
11629 of an argument from the frame pointer. */
11630 int
11631 arm_debugger_arg_offset (int value, rtx addr)
11632 {
11633 rtx insn;
11634
11635 /* We are only interested if dbxout_parms() failed to compute the offset. */
11636 if (value != 0)
11637 return 0;
11638
11639 /* We can only cope with the case where the address is held in a register. */
11640 if (GET_CODE (addr) != REG)
11641 return 0;
11642
11643 /* If we are using the frame pointer to point at the argument, then
11644 an offset of 0 is correct. */
11645 if (REGNO (addr) == (unsigned) HARD_FRAME_POINTER_REGNUM)
11646 return 0;
11647
11648 /* If we are using the stack pointer to point at the
11649 argument, then an offset of 0 is correct. */
11650 if ((TARGET_THUMB || !frame_pointer_needed)
11651 && REGNO (addr) == SP_REGNUM)
11652 return 0;
11653
11654 /* Oh dear. The argument is pointed to by a register rather
11655 than being held in a register, or being stored at a known
11656 offset from the frame pointer. Since GDB only understands
11657 those two kinds of argument we must translate the address
11658 held in the register into an offset from the frame pointer.
11659 We do this by searching through the insns for the function
11660 looking to see where this register gets its value. If the
11661 register is initialized from the frame pointer plus an offset
11662 then we are in luck and we can continue, otherwise we give up.
11663
11664 This code is exercised by producing debugging information
11665 for a function with arguments like this:
11666
11667 double func (double a, double b, int c, double d) {return d;}
11668
11669 Without this code the stab for parameter 'd' will be set to
11670 an offset of 0 from the frame pointer, rather than 8. */
11671
11672 /* The if() statement says:
11673
11674 If the insn is a normal instruction
11675 and if the insn is setting the value in a register
11676 and if the register being set is the register holding the address of the argument
11677 and if the address is computing by an addition
11678 that involves adding to a register
11679 which is the frame pointer
11680 a constant integer
11681
11682 then... */
11683
11684 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11685 {
11686 if ( GET_CODE (insn) == INSN
11687 && GET_CODE (PATTERN (insn)) == SET
11688 && REGNO (XEXP (PATTERN (insn), 0)) == REGNO (addr)
11689 && GET_CODE (XEXP (PATTERN (insn), 1)) == PLUS
11690 && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 0)) == REG
11691 && REGNO (XEXP (XEXP (PATTERN (insn), 1), 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
11692 && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 1)) == CONST_INT
11693 )
11694 {
11695 value = INTVAL (XEXP (XEXP (PATTERN (insn), 1), 1));
11696
11697 break;
11698 }
11699 }
11700
11701 if (value == 0)
11702 {
11703 debug_rtx (addr);
11704 warning ("unable to compute real location of stacked parameter");
11705 value = 8; /* XXX magic hack */
11706 }
11707
11708 return value;
11709 }
11710 \f
11711 #define def_mbuiltin(MASK, NAME, TYPE, CODE) \
11712 do \
11713 { \
11714 if ((MASK) & insn_flags) \
11715 lang_hooks.builtin_function ((NAME), (TYPE), (CODE), \
11716 BUILT_IN_MD, NULL, NULL_TREE); \
11717 } \
11718 while (0)
11719
11720 struct builtin_description
11721 {
11722 const unsigned int mask;
11723 const enum insn_code icode;
11724 const char * const name;
11725 const enum arm_builtins code;
11726 const enum rtx_code comparison;
11727 const unsigned int flag;
11728 };
11729
11730 static const struct builtin_description bdesc_2arg[] =
11731 {
11732 #define IWMMXT_BUILTIN(code, string, builtin) \
11733 { FL_IWMMXT, CODE_FOR_##code, "__builtin_arm_" string, \
11734 ARM_BUILTIN_##builtin, 0, 0 },
11735
11736 IWMMXT_BUILTIN (addv8qi3, "waddb", WADDB)
11737 IWMMXT_BUILTIN (addv4hi3, "waddh", WADDH)
11738 IWMMXT_BUILTIN (addv2si3, "waddw", WADDW)
11739 IWMMXT_BUILTIN (subv8qi3, "wsubb", WSUBB)
11740 IWMMXT_BUILTIN (subv4hi3, "wsubh", WSUBH)
11741 IWMMXT_BUILTIN (subv2si3, "wsubw", WSUBW)
11742 IWMMXT_BUILTIN (ssaddv8qi3, "waddbss", WADDSSB)
11743 IWMMXT_BUILTIN (ssaddv4hi3, "waddhss", WADDSSH)
11744 IWMMXT_BUILTIN (ssaddv2si3, "waddwss", WADDSSW)
11745 IWMMXT_BUILTIN (sssubv8qi3, "wsubbss", WSUBSSB)
11746 IWMMXT_BUILTIN (sssubv4hi3, "wsubhss", WSUBSSH)
11747 IWMMXT_BUILTIN (sssubv2si3, "wsubwss", WSUBSSW)
11748 IWMMXT_BUILTIN (usaddv8qi3, "waddbus", WADDUSB)
11749 IWMMXT_BUILTIN (usaddv4hi3, "waddhus", WADDUSH)
11750 IWMMXT_BUILTIN (usaddv2si3, "waddwus", WADDUSW)
11751 IWMMXT_BUILTIN (ussubv8qi3, "wsubbus", WSUBUSB)
11752 IWMMXT_BUILTIN (ussubv4hi3, "wsubhus", WSUBUSH)
11753 IWMMXT_BUILTIN (ussubv2si3, "wsubwus", WSUBUSW)
11754 IWMMXT_BUILTIN (mulv4hi3, "wmulul", WMULUL)
11755 IWMMXT_BUILTIN (smulv4hi3_highpart, "wmulsm", WMULSM)
11756 IWMMXT_BUILTIN (umulv4hi3_highpart, "wmulum", WMULUM)
11757 IWMMXT_BUILTIN (eqv8qi3, "wcmpeqb", WCMPEQB)
11758 IWMMXT_BUILTIN (eqv4hi3, "wcmpeqh", WCMPEQH)
11759 IWMMXT_BUILTIN (eqv2si3, "wcmpeqw", WCMPEQW)
11760 IWMMXT_BUILTIN (gtuv8qi3, "wcmpgtub", WCMPGTUB)
11761 IWMMXT_BUILTIN (gtuv4hi3, "wcmpgtuh", WCMPGTUH)
11762 IWMMXT_BUILTIN (gtuv2si3, "wcmpgtuw", WCMPGTUW)
11763 IWMMXT_BUILTIN (gtv8qi3, "wcmpgtsb", WCMPGTSB)
11764 IWMMXT_BUILTIN (gtv4hi3, "wcmpgtsh", WCMPGTSH)
11765 IWMMXT_BUILTIN (gtv2si3, "wcmpgtsw", WCMPGTSW)
11766 IWMMXT_BUILTIN (umaxv8qi3, "wmaxub", WMAXUB)
11767 IWMMXT_BUILTIN (smaxv8qi3, "wmaxsb", WMAXSB)
11768 IWMMXT_BUILTIN (umaxv4hi3, "wmaxuh", WMAXUH)
11769 IWMMXT_BUILTIN (smaxv4hi3, "wmaxsh", WMAXSH)
11770 IWMMXT_BUILTIN (umaxv2si3, "wmaxuw", WMAXUW)
11771 IWMMXT_BUILTIN (smaxv2si3, "wmaxsw", WMAXSW)
11772 IWMMXT_BUILTIN (uminv8qi3, "wminub", WMINUB)
11773 IWMMXT_BUILTIN (sminv8qi3, "wminsb", WMINSB)
11774 IWMMXT_BUILTIN (uminv4hi3, "wminuh", WMINUH)
11775 IWMMXT_BUILTIN (sminv4hi3, "wminsh", WMINSH)
11776 IWMMXT_BUILTIN (uminv2si3, "wminuw", WMINUW)
11777 IWMMXT_BUILTIN (sminv2si3, "wminsw", WMINSW)
11778 IWMMXT_BUILTIN (iwmmxt_anddi3, "wand", WAND)
11779 IWMMXT_BUILTIN (iwmmxt_nanddi3, "wandn", WANDN)
11780 IWMMXT_BUILTIN (iwmmxt_iordi3, "wor", WOR)
11781 IWMMXT_BUILTIN (iwmmxt_xordi3, "wxor", WXOR)
11782 IWMMXT_BUILTIN (iwmmxt_uavgv8qi3, "wavg2b", WAVG2B)
11783 IWMMXT_BUILTIN (iwmmxt_uavgv4hi3, "wavg2h", WAVG2H)
11784 IWMMXT_BUILTIN (iwmmxt_uavgrndv8qi3, "wavg2br", WAVG2BR)
11785 IWMMXT_BUILTIN (iwmmxt_uavgrndv4hi3, "wavg2hr", WAVG2HR)
11786 IWMMXT_BUILTIN (iwmmxt_wunpckilb, "wunpckilb", WUNPCKILB)
11787 IWMMXT_BUILTIN (iwmmxt_wunpckilh, "wunpckilh", WUNPCKILH)
11788 IWMMXT_BUILTIN (iwmmxt_wunpckilw, "wunpckilw", WUNPCKILW)
11789 IWMMXT_BUILTIN (iwmmxt_wunpckihb, "wunpckihb", WUNPCKIHB)
11790 IWMMXT_BUILTIN (iwmmxt_wunpckihh, "wunpckihh", WUNPCKIHH)
11791 IWMMXT_BUILTIN (iwmmxt_wunpckihw, "wunpckihw", WUNPCKIHW)
11792 IWMMXT_BUILTIN (iwmmxt_wmadds, "wmadds", WMADDS)
11793 IWMMXT_BUILTIN (iwmmxt_wmaddu, "wmaddu", WMADDU)
11794
11795 #define IWMMXT_BUILTIN2(code, builtin) \
11796 { FL_IWMMXT, CODE_FOR_##code, NULL, ARM_BUILTIN_##builtin, 0, 0 },
11797
11798 IWMMXT_BUILTIN2 (iwmmxt_wpackhss, WPACKHSS)
11799 IWMMXT_BUILTIN2 (iwmmxt_wpackwss, WPACKWSS)
11800 IWMMXT_BUILTIN2 (iwmmxt_wpackdss, WPACKDSS)
11801 IWMMXT_BUILTIN2 (iwmmxt_wpackhus, WPACKHUS)
11802 IWMMXT_BUILTIN2 (iwmmxt_wpackwus, WPACKWUS)
11803 IWMMXT_BUILTIN2 (iwmmxt_wpackdus, WPACKDUS)
11804 IWMMXT_BUILTIN2 (ashlv4hi3_di, WSLLH)
11805 IWMMXT_BUILTIN2 (ashlv4hi3, WSLLHI)
11806 IWMMXT_BUILTIN2 (ashlv2si3_di, WSLLW)
11807 IWMMXT_BUILTIN2 (ashlv2si3, WSLLWI)
11808 IWMMXT_BUILTIN2 (ashldi3_di, WSLLD)
11809 IWMMXT_BUILTIN2 (ashldi3_iwmmxt, WSLLDI)
11810 IWMMXT_BUILTIN2 (lshrv4hi3_di, WSRLH)
11811 IWMMXT_BUILTIN2 (lshrv4hi3, WSRLHI)
11812 IWMMXT_BUILTIN2 (lshrv2si3_di, WSRLW)
11813 IWMMXT_BUILTIN2 (lshrv2si3, WSRLWI)
11814 IWMMXT_BUILTIN2 (lshrdi3_di, WSRLD)
11815 IWMMXT_BUILTIN2 (lshrdi3_iwmmxt, WSRLDI)
11816 IWMMXT_BUILTIN2 (ashrv4hi3_di, WSRAH)
11817 IWMMXT_BUILTIN2 (ashrv4hi3, WSRAHI)
11818 IWMMXT_BUILTIN2 (ashrv2si3_di, WSRAW)
11819 IWMMXT_BUILTIN2 (ashrv2si3, WSRAWI)
11820 IWMMXT_BUILTIN2 (ashrdi3_di, WSRAD)
11821 IWMMXT_BUILTIN2 (ashrdi3_iwmmxt, WSRADI)
11822 IWMMXT_BUILTIN2 (rorv4hi3_di, WRORH)
11823 IWMMXT_BUILTIN2 (rorv4hi3, WRORHI)
11824 IWMMXT_BUILTIN2 (rorv2si3_di, WRORW)
11825 IWMMXT_BUILTIN2 (rorv2si3, WRORWI)
11826 IWMMXT_BUILTIN2 (rordi3_di, WRORD)
11827 IWMMXT_BUILTIN2 (rordi3, WRORDI)
11828 IWMMXT_BUILTIN2 (iwmmxt_wmacuz, WMACUZ)
11829 IWMMXT_BUILTIN2 (iwmmxt_wmacsz, WMACSZ)
11830 };
11831
11832 static const struct builtin_description bdesc_1arg[] =
11833 {
11834 IWMMXT_BUILTIN (iwmmxt_tmovmskb, "tmovmskb", TMOVMSKB)
11835 IWMMXT_BUILTIN (iwmmxt_tmovmskh, "tmovmskh", TMOVMSKH)
11836 IWMMXT_BUILTIN (iwmmxt_tmovmskw, "tmovmskw", TMOVMSKW)
11837 IWMMXT_BUILTIN (iwmmxt_waccb, "waccb", WACCB)
11838 IWMMXT_BUILTIN (iwmmxt_wacch, "wacch", WACCH)
11839 IWMMXT_BUILTIN (iwmmxt_waccw, "waccw", WACCW)
11840 IWMMXT_BUILTIN (iwmmxt_wunpckehub, "wunpckehub", WUNPCKEHUB)
11841 IWMMXT_BUILTIN (iwmmxt_wunpckehuh, "wunpckehuh", WUNPCKEHUH)
11842 IWMMXT_BUILTIN (iwmmxt_wunpckehuw, "wunpckehuw", WUNPCKEHUW)
11843 IWMMXT_BUILTIN (iwmmxt_wunpckehsb, "wunpckehsb", WUNPCKEHSB)
11844 IWMMXT_BUILTIN (iwmmxt_wunpckehsh, "wunpckehsh", WUNPCKEHSH)
11845 IWMMXT_BUILTIN (iwmmxt_wunpckehsw, "wunpckehsw", WUNPCKEHSW)
11846 IWMMXT_BUILTIN (iwmmxt_wunpckelub, "wunpckelub", WUNPCKELUB)
11847 IWMMXT_BUILTIN (iwmmxt_wunpckeluh, "wunpckeluh", WUNPCKELUH)
11848 IWMMXT_BUILTIN (iwmmxt_wunpckeluw, "wunpckeluw", WUNPCKELUW)
11849 IWMMXT_BUILTIN (iwmmxt_wunpckelsb, "wunpckelsb", WUNPCKELSB)
11850 IWMMXT_BUILTIN (iwmmxt_wunpckelsh, "wunpckelsh", WUNPCKELSH)
11851 IWMMXT_BUILTIN (iwmmxt_wunpckelsw, "wunpckelsw", WUNPCKELSW)
11852 };
11853
11854 /* Set up all the iWMMXt builtins. This is
11855 not called if TARGET_IWMMXT is zero. */
11856
11857 static void
11858 arm_init_iwmmxt_builtins (void)
11859 {
11860 const struct builtin_description * d;
11861 size_t i;
11862 tree endlink = void_list_node;
11863
11864 tree V2SI_type_node = build_vector_type_for_mode (intSI_type_node, V2SImode);
11865 tree V4HI_type_node = build_vector_type_for_mode (intHI_type_node, V4HImode);
11866 tree V8QI_type_node = build_vector_type_for_mode (intQI_type_node, V8QImode);
11867
11868 tree int_ftype_int
11869 = build_function_type (integer_type_node,
11870 tree_cons (NULL_TREE, integer_type_node, endlink));
11871 tree v8qi_ftype_v8qi_v8qi_int
11872 = build_function_type (V8QI_type_node,
11873 tree_cons (NULL_TREE, V8QI_type_node,
11874 tree_cons (NULL_TREE, V8QI_type_node,
11875 tree_cons (NULL_TREE,
11876 integer_type_node,
11877 endlink))));
11878 tree v4hi_ftype_v4hi_int
11879 = build_function_type (V4HI_type_node,
11880 tree_cons (NULL_TREE, V4HI_type_node,
11881 tree_cons (NULL_TREE, integer_type_node,
11882 endlink)));
11883 tree v2si_ftype_v2si_int
11884 = build_function_type (V2SI_type_node,
11885 tree_cons (NULL_TREE, V2SI_type_node,
11886 tree_cons (NULL_TREE, integer_type_node,
11887 endlink)));
11888 tree v2si_ftype_di_di
11889 = build_function_type (V2SI_type_node,
11890 tree_cons (NULL_TREE, long_long_integer_type_node,
11891 tree_cons (NULL_TREE, long_long_integer_type_node,
11892 endlink)));
11893 tree di_ftype_di_int
11894 = build_function_type (long_long_integer_type_node,
11895 tree_cons (NULL_TREE, long_long_integer_type_node,
11896 tree_cons (NULL_TREE, integer_type_node,
11897 endlink)));
11898 tree di_ftype_di_int_int
11899 = build_function_type (long_long_integer_type_node,
11900 tree_cons (NULL_TREE, long_long_integer_type_node,
11901 tree_cons (NULL_TREE, integer_type_node,
11902 tree_cons (NULL_TREE,
11903 integer_type_node,
11904 endlink))));
11905 tree int_ftype_v8qi
11906 = build_function_type (integer_type_node,
11907 tree_cons (NULL_TREE, V8QI_type_node,
11908 endlink));
11909 tree int_ftype_v4hi
11910 = build_function_type (integer_type_node,
11911 tree_cons (NULL_TREE, V4HI_type_node,
11912 endlink));
11913 tree int_ftype_v2si
11914 = build_function_type (integer_type_node,
11915 tree_cons (NULL_TREE, V2SI_type_node,
11916 endlink));
11917 tree int_ftype_v8qi_int
11918 = build_function_type (integer_type_node,
11919 tree_cons (NULL_TREE, V8QI_type_node,
11920 tree_cons (NULL_TREE, integer_type_node,
11921 endlink)));
11922 tree int_ftype_v4hi_int
11923 = build_function_type (integer_type_node,
11924 tree_cons (NULL_TREE, V4HI_type_node,
11925 tree_cons (NULL_TREE, integer_type_node,
11926 endlink)));
11927 tree int_ftype_v2si_int
11928 = build_function_type (integer_type_node,
11929 tree_cons (NULL_TREE, V2SI_type_node,
11930 tree_cons (NULL_TREE, integer_type_node,
11931 endlink)));
11932 tree v8qi_ftype_v8qi_int_int
11933 = build_function_type (V8QI_type_node,
11934 tree_cons (NULL_TREE, V8QI_type_node,
11935 tree_cons (NULL_TREE, integer_type_node,
11936 tree_cons (NULL_TREE,
11937 integer_type_node,
11938 endlink))));
11939 tree v4hi_ftype_v4hi_int_int
11940 = build_function_type (V4HI_type_node,
11941 tree_cons (NULL_TREE, V4HI_type_node,
11942 tree_cons (NULL_TREE, integer_type_node,
11943 tree_cons (NULL_TREE,
11944 integer_type_node,
11945 endlink))));
11946 tree v2si_ftype_v2si_int_int
11947 = build_function_type (V2SI_type_node,
11948 tree_cons (NULL_TREE, V2SI_type_node,
11949 tree_cons (NULL_TREE, integer_type_node,
11950 tree_cons (NULL_TREE,
11951 integer_type_node,
11952 endlink))));
11953 /* Miscellaneous. */
11954 tree v8qi_ftype_v4hi_v4hi
11955 = build_function_type (V8QI_type_node,
11956 tree_cons (NULL_TREE, V4HI_type_node,
11957 tree_cons (NULL_TREE, V4HI_type_node,
11958 endlink)));
11959 tree v4hi_ftype_v2si_v2si
11960 = build_function_type (V4HI_type_node,
11961 tree_cons (NULL_TREE, V2SI_type_node,
11962 tree_cons (NULL_TREE, V2SI_type_node,
11963 endlink)));
11964 tree v2si_ftype_v4hi_v4hi
11965 = build_function_type (V2SI_type_node,
11966 tree_cons (NULL_TREE, V4HI_type_node,
11967 tree_cons (NULL_TREE, V4HI_type_node,
11968 endlink)));
11969 tree v2si_ftype_v8qi_v8qi
11970 = build_function_type (V2SI_type_node,
11971 tree_cons (NULL_TREE, V8QI_type_node,
11972 tree_cons (NULL_TREE, V8QI_type_node,
11973 endlink)));
11974 tree v4hi_ftype_v4hi_di
11975 = build_function_type (V4HI_type_node,
11976 tree_cons (NULL_TREE, V4HI_type_node,
11977 tree_cons (NULL_TREE,
11978 long_long_integer_type_node,
11979 endlink)));
11980 tree v2si_ftype_v2si_di
11981 = build_function_type (V2SI_type_node,
11982 tree_cons (NULL_TREE, V2SI_type_node,
11983 tree_cons (NULL_TREE,
11984 long_long_integer_type_node,
11985 endlink)));
11986 tree void_ftype_int_int
11987 = build_function_type (void_type_node,
11988 tree_cons (NULL_TREE, integer_type_node,
11989 tree_cons (NULL_TREE, integer_type_node,
11990 endlink)));
11991 tree di_ftype_void
11992 = build_function_type (long_long_unsigned_type_node, endlink);
11993 tree di_ftype_v8qi
11994 = build_function_type (long_long_integer_type_node,
11995 tree_cons (NULL_TREE, V8QI_type_node,
11996 endlink));
11997 tree di_ftype_v4hi
11998 = build_function_type (long_long_integer_type_node,
11999 tree_cons (NULL_TREE, V4HI_type_node,
12000 endlink));
12001 tree di_ftype_v2si
12002 = build_function_type (long_long_integer_type_node,
12003 tree_cons (NULL_TREE, V2SI_type_node,
12004 endlink));
12005 tree v2si_ftype_v4hi
12006 = build_function_type (V2SI_type_node,
12007 tree_cons (NULL_TREE, V4HI_type_node,
12008 endlink));
12009 tree v4hi_ftype_v8qi
12010 = build_function_type (V4HI_type_node,
12011 tree_cons (NULL_TREE, V8QI_type_node,
12012 endlink));
12013
12014 tree di_ftype_di_v4hi_v4hi
12015 = build_function_type (long_long_unsigned_type_node,
12016 tree_cons (NULL_TREE,
12017 long_long_unsigned_type_node,
12018 tree_cons (NULL_TREE, V4HI_type_node,
12019 tree_cons (NULL_TREE,
12020 V4HI_type_node,
12021 endlink))));
12022
12023 tree di_ftype_v4hi_v4hi
12024 = build_function_type (long_long_unsigned_type_node,
12025 tree_cons (NULL_TREE, V4HI_type_node,
12026 tree_cons (NULL_TREE, V4HI_type_node,
12027 endlink)));
12028
12029 /* Normal vector binops. */
12030 tree v8qi_ftype_v8qi_v8qi
12031 = build_function_type (V8QI_type_node,
12032 tree_cons (NULL_TREE, V8QI_type_node,
12033 tree_cons (NULL_TREE, V8QI_type_node,
12034 endlink)));
12035 tree v4hi_ftype_v4hi_v4hi
12036 = build_function_type (V4HI_type_node,
12037 tree_cons (NULL_TREE, V4HI_type_node,
12038 tree_cons (NULL_TREE, V4HI_type_node,
12039 endlink)));
12040 tree v2si_ftype_v2si_v2si
12041 = build_function_type (V2SI_type_node,
12042 tree_cons (NULL_TREE, V2SI_type_node,
12043 tree_cons (NULL_TREE, V2SI_type_node,
12044 endlink)));
12045 tree di_ftype_di_di
12046 = build_function_type (long_long_unsigned_type_node,
12047 tree_cons (NULL_TREE, long_long_unsigned_type_node,
12048 tree_cons (NULL_TREE,
12049 long_long_unsigned_type_node,
12050 endlink)));
12051
12052 /* Add all builtins that are more or less simple operations on two
12053 operands. */
12054 for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
12055 {
12056 /* Use one of the operands; the target can have a different mode for
12057 mask-generating compares. */
12058 enum machine_mode mode;
12059 tree type;
12060
12061 if (d->name == 0)
12062 continue;
12063
12064 mode = insn_data[d->icode].operand[1].mode;
12065
12066 switch (mode)
12067 {
12068 case V8QImode:
12069 type = v8qi_ftype_v8qi_v8qi;
12070 break;
12071 case V4HImode:
12072 type = v4hi_ftype_v4hi_v4hi;
12073 break;
12074 case V2SImode:
12075 type = v2si_ftype_v2si_v2si;
12076 break;
12077 case DImode:
12078 type = di_ftype_di_di;
12079 break;
12080
12081 default:
12082 abort ();
12083 }
12084
12085 def_mbuiltin (d->mask, d->name, type, d->code);
12086 }
12087
12088 /* Add the remaining MMX insns with somewhat more complicated types. */
12089 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wzero", di_ftype_void, ARM_BUILTIN_WZERO);
12090 def_mbuiltin (FL_IWMMXT, "__builtin_arm_setwcx", void_ftype_int_int, ARM_BUILTIN_SETWCX);
12091 def_mbuiltin (FL_IWMMXT, "__builtin_arm_getwcx", int_ftype_int, ARM_BUILTIN_GETWCX);
12092
12093 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllh", v4hi_ftype_v4hi_di, ARM_BUILTIN_WSLLH);
12094 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllw", v2si_ftype_v2si_di, ARM_BUILTIN_WSLLW);
12095 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wslld", di_ftype_di_di, ARM_BUILTIN_WSLLD);
12096 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllhi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSLLHI);
12097 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsllwi", v2si_ftype_v2si_int, ARM_BUILTIN_WSLLWI);
12098 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wslldi", di_ftype_di_int, ARM_BUILTIN_WSLLDI);
12099
12100 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlh", v4hi_ftype_v4hi_di, ARM_BUILTIN_WSRLH);
12101 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlw", v2si_ftype_v2si_di, ARM_BUILTIN_WSRLW);
12102 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrld", di_ftype_di_di, ARM_BUILTIN_WSRLD);
12103 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlhi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSRLHI);
12104 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrlwi", v2si_ftype_v2si_int, ARM_BUILTIN_WSRLWI);
12105 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrldi", di_ftype_di_int, ARM_BUILTIN_WSRLDI);
12106
12107 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrah", v4hi_ftype_v4hi_di, ARM_BUILTIN_WSRAH);
12108 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsraw", v2si_ftype_v2si_di, ARM_BUILTIN_WSRAW);
12109 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrad", di_ftype_di_di, ARM_BUILTIN_WSRAD);
12110 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrahi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSRAHI);
12111 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsrawi", v2si_ftype_v2si_int, ARM_BUILTIN_WSRAWI);
12112 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsradi", di_ftype_di_int, ARM_BUILTIN_WSRADI);
12113
12114 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorh", v4hi_ftype_v4hi_di, ARM_BUILTIN_WRORH);
12115 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorw", v2si_ftype_v2si_di, ARM_BUILTIN_WRORW);
12116 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrord", di_ftype_di_di, ARM_BUILTIN_WRORD);
12117 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorhi", v4hi_ftype_v4hi_int, ARM_BUILTIN_WRORHI);
12118 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrorwi", v2si_ftype_v2si_int, ARM_BUILTIN_WRORWI);
12119 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wrordi", di_ftype_di_int, ARM_BUILTIN_WRORDI);
12120
12121 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wshufh", v4hi_ftype_v4hi_int, ARM_BUILTIN_WSHUFH);
12122
12123 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadb", v2si_ftype_v8qi_v8qi, ARM_BUILTIN_WSADB);
12124 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadh", v2si_ftype_v4hi_v4hi, ARM_BUILTIN_WSADH);
12125 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadbz", v2si_ftype_v8qi_v8qi, ARM_BUILTIN_WSADBZ);
12126 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wsadhz", v2si_ftype_v4hi_v4hi, ARM_BUILTIN_WSADHZ);
12127
12128 def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmsb", int_ftype_v8qi_int, ARM_BUILTIN_TEXTRMSB);
12129 def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmsh", int_ftype_v4hi_int, ARM_BUILTIN_TEXTRMSH);
12130 def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmsw", int_ftype_v2si_int, ARM_BUILTIN_TEXTRMSW);
12131 def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmub", int_ftype_v8qi_int, ARM_BUILTIN_TEXTRMUB);
12132 def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmuh", int_ftype_v4hi_int, ARM_BUILTIN_TEXTRMUH);
12133 def_mbuiltin (FL_IWMMXT, "__builtin_arm_textrmuw", int_ftype_v2si_int, ARM_BUILTIN_TEXTRMUW);
12134 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tinsrb", v8qi_ftype_v8qi_int_int, ARM_BUILTIN_TINSRB);
12135 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tinsrh", v4hi_ftype_v4hi_int_int, ARM_BUILTIN_TINSRH);
12136 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tinsrw", v2si_ftype_v2si_int_int, ARM_BUILTIN_TINSRW);
12137
12138 def_mbuiltin (FL_IWMMXT, "__builtin_arm_waccb", di_ftype_v8qi, ARM_BUILTIN_WACCB);
12139 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wacch", di_ftype_v4hi, ARM_BUILTIN_WACCH);
12140 def_mbuiltin (FL_IWMMXT, "__builtin_arm_waccw", di_ftype_v2si, ARM_BUILTIN_WACCW);
12141
12142 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmovmskb", int_ftype_v8qi, ARM_BUILTIN_TMOVMSKB);
12143 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmovmskh", int_ftype_v4hi, ARM_BUILTIN_TMOVMSKH);
12144 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmovmskw", int_ftype_v2si, ARM_BUILTIN_TMOVMSKW);
12145
12146 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackhss", v8qi_ftype_v4hi_v4hi, ARM_BUILTIN_WPACKHSS);
12147 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackhus", v8qi_ftype_v4hi_v4hi, ARM_BUILTIN_WPACKHUS);
12148 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackwus", v4hi_ftype_v2si_v2si, ARM_BUILTIN_WPACKWUS);
12149 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackwss", v4hi_ftype_v2si_v2si, ARM_BUILTIN_WPACKWSS);
12150 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackdus", v2si_ftype_di_di, ARM_BUILTIN_WPACKDUS);
12151 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wpackdss", v2si_ftype_di_di, ARM_BUILTIN_WPACKDSS);
12152
12153 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehub", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKEHUB);
12154 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehuh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKEHUH);
12155 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehuw", di_ftype_v2si, ARM_BUILTIN_WUNPCKEHUW);
12156 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehsb", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKEHSB);
12157 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehsh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKEHSH);
12158 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckehsw", di_ftype_v2si, ARM_BUILTIN_WUNPCKEHSW);
12159 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelub", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKELUB);
12160 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckeluh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKELUH);
12161 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckeluw", di_ftype_v2si, ARM_BUILTIN_WUNPCKELUW);
12162 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelsb", v4hi_ftype_v8qi, ARM_BUILTIN_WUNPCKELSB);
12163 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelsh", v2si_ftype_v4hi, ARM_BUILTIN_WUNPCKELSH);
12164 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wunpckelsw", di_ftype_v2si, ARM_BUILTIN_WUNPCKELSW);
12165
12166 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacs", di_ftype_di_v4hi_v4hi, ARM_BUILTIN_WMACS);
12167 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacsz", di_ftype_v4hi_v4hi, ARM_BUILTIN_WMACSZ);
12168 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacu", di_ftype_di_v4hi_v4hi, ARM_BUILTIN_WMACU);
12169 def_mbuiltin (FL_IWMMXT, "__builtin_arm_wmacuz", di_ftype_v4hi_v4hi, ARM_BUILTIN_WMACUZ);
12170
12171 def_mbuiltin (FL_IWMMXT, "__builtin_arm_walign", v8qi_ftype_v8qi_v8qi_int, ARM_BUILTIN_WALIGN);
12172 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmia", di_ftype_di_int_int, ARM_BUILTIN_TMIA);
12173 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiaph", di_ftype_di_int_int, ARM_BUILTIN_TMIAPH);
12174 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiabb", di_ftype_di_int_int, ARM_BUILTIN_TMIABB);
12175 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiabt", di_ftype_di_int_int, ARM_BUILTIN_TMIABT);
12176 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiatb", di_ftype_di_int_int, ARM_BUILTIN_TMIATB);
12177 def_mbuiltin (FL_IWMMXT, "__builtin_arm_tmiatt", di_ftype_di_int_int, ARM_BUILTIN_TMIATT);
12178 }
12179
12180 static void
12181 arm_init_builtins (void)
12182 {
12183 if (TARGET_REALLY_IWMMXT)
12184 arm_init_iwmmxt_builtins ();
12185 }
12186
12187 /* Errors in the source file can cause expand_expr to return const0_rtx
12188 where we expect a vector. To avoid crashing, use one of the vector
12189 clear instructions. */
12190
12191 static rtx
12192 safe_vector_operand (rtx x, enum machine_mode mode)
12193 {
12194 if (x != const0_rtx)
12195 return x;
12196 x = gen_reg_rtx (mode);
12197
12198 emit_insn (gen_iwmmxt_clrdi (mode == DImode ? x
12199 : gen_rtx_SUBREG (DImode, x, 0)));
12200 return x;
12201 }
12202
12203 /* Subroutine of arm_expand_builtin to take care of binop insns. */
12204
12205 static rtx
12206 arm_expand_binop_builtin (enum insn_code icode,
12207 tree arglist, rtx target)
12208 {
12209 rtx pat;
12210 tree arg0 = TREE_VALUE (arglist);
12211 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
12212 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12213 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
12214 enum machine_mode tmode = insn_data[icode].operand[0].mode;
12215 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
12216 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
12217
12218 if (VECTOR_MODE_P (mode0))
12219 op0 = safe_vector_operand (op0, mode0);
12220 if (VECTOR_MODE_P (mode1))
12221 op1 = safe_vector_operand (op1, mode1);
12222
12223 if (! target
12224 || GET_MODE (target) != tmode
12225 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12226 target = gen_reg_rtx (tmode);
12227
12228 /* In case the insn wants input operands in modes different from
12229 the result, abort. */
12230 if (GET_MODE (op0) != mode0 || GET_MODE (op1) != mode1)
12231 abort ();
12232
12233 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12234 op0 = copy_to_mode_reg (mode0, op0);
12235 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
12236 op1 = copy_to_mode_reg (mode1, op1);
12237
12238 pat = GEN_FCN (icode) (target, op0, op1);
12239 if (! pat)
12240 return 0;
12241 emit_insn (pat);
12242 return target;
12243 }
12244
12245 /* Subroutine of arm_expand_builtin to take care of unop insns. */
12246
12247 static rtx
12248 arm_expand_unop_builtin (enum insn_code icode,
12249 tree arglist, rtx target, int do_load)
12250 {
12251 rtx pat;
12252 tree arg0 = TREE_VALUE (arglist);
12253 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12254 enum machine_mode tmode = insn_data[icode].operand[0].mode;
12255 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
12256
12257 if (! target
12258 || GET_MODE (target) != tmode
12259 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12260 target = gen_reg_rtx (tmode);
12261 if (do_load)
12262 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
12263 else
12264 {
12265 if (VECTOR_MODE_P (mode0))
12266 op0 = safe_vector_operand (op0, mode0);
12267
12268 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12269 op0 = copy_to_mode_reg (mode0, op0);
12270 }
12271
12272 pat = GEN_FCN (icode) (target, op0);
12273 if (! pat)
12274 return 0;
12275 emit_insn (pat);
12276 return target;
12277 }
12278
12279 /* Expand an expression EXP that calls a built-in function,
12280 with result going to TARGET if that's convenient
12281 (and in mode MODE if that's convenient).
12282 SUBTARGET may be used as the target for computing one of EXP's operands.
12283 IGNORE is nonzero if the value is to be ignored. */
12284
12285 static rtx
12286 arm_expand_builtin (tree exp,
12287 rtx target,
12288 rtx subtarget ATTRIBUTE_UNUSED,
12289 enum machine_mode mode ATTRIBUTE_UNUSED,
12290 int ignore ATTRIBUTE_UNUSED)
12291 {
12292 const struct builtin_description * d;
12293 enum insn_code icode;
12294 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
12295 tree arglist = TREE_OPERAND (exp, 1);
12296 tree arg0;
12297 tree arg1;
12298 tree arg2;
12299 rtx op0;
12300 rtx op1;
12301 rtx op2;
12302 rtx pat;
12303 int fcode = DECL_FUNCTION_CODE (fndecl);
12304 size_t i;
12305 enum machine_mode tmode;
12306 enum machine_mode mode0;
12307 enum machine_mode mode1;
12308 enum machine_mode mode2;
12309
12310 switch (fcode)
12311 {
12312 case ARM_BUILTIN_TEXTRMSB:
12313 case ARM_BUILTIN_TEXTRMUB:
12314 case ARM_BUILTIN_TEXTRMSH:
12315 case ARM_BUILTIN_TEXTRMUH:
12316 case ARM_BUILTIN_TEXTRMSW:
12317 case ARM_BUILTIN_TEXTRMUW:
12318 icode = (fcode == ARM_BUILTIN_TEXTRMSB ? CODE_FOR_iwmmxt_textrmsb
12319 : fcode == ARM_BUILTIN_TEXTRMUB ? CODE_FOR_iwmmxt_textrmub
12320 : fcode == ARM_BUILTIN_TEXTRMSH ? CODE_FOR_iwmmxt_textrmsh
12321 : fcode == ARM_BUILTIN_TEXTRMUH ? CODE_FOR_iwmmxt_textrmuh
12322 : CODE_FOR_iwmmxt_textrmw);
12323
12324 arg0 = TREE_VALUE (arglist);
12325 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
12326 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12327 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
12328 tmode = insn_data[icode].operand[0].mode;
12329 mode0 = insn_data[icode].operand[1].mode;
12330 mode1 = insn_data[icode].operand[2].mode;
12331
12332 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12333 op0 = copy_to_mode_reg (mode0, op0);
12334 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
12335 {
12336 /* @@@ better error message */
12337 error ("selector must be an immediate");
12338 return gen_reg_rtx (tmode);
12339 }
12340 if (target == 0
12341 || GET_MODE (target) != tmode
12342 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12343 target = gen_reg_rtx (tmode);
12344 pat = GEN_FCN (icode) (target, op0, op1);
12345 if (! pat)
12346 return 0;
12347 emit_insn (pat);
12348 return target;
12349
12350 case ARM_BUILTIN_TINSRB:
12351 case ARM_BUILTIN_TINSRH:
12352 case ARM_BUILTIN_TINSRW:
12353 icode = (fcode == ARM_BUILTIN_TINSRB ? CODE_FOR_iwmmxt_tinsrb
12354 : fcode == ARM_BUILTIN_TINSRH ? CODE_FOR_iwmmxt_tinsrh
12355 : CODE_FOR_iwmmxt_tinsrw);
12356 arg0 = TREE_VALUE (arglist);
12357 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
12358 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
12359 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12360 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
12361 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
12362 tmode = insn_data[icode].operand[0].mode;
12363 mode0 = insn_data[icode].operand[1].mode;
12364 mode1 = insn_data[icode].operand[2].mode;
12365 mode2 = insn_data[icode].operand[3].mode;
12366
12367 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12368 op0 = copy_to_mode_reg (mode0, op0);
12369 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
12370 op1 = copy_to_mode_reg (mode1, op1);
12371 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
12372 {
12373 /* @@@ better error message */
12374 error ("selector must be an immediate");
12375 return const0_rtx;
12376 }
12377 if (target == 0
12378 || GET_MODE (target) != tmode
12379 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12380 target = gen_reg_rtx (tmode);
12381 pat = GEN_FCN (icode) (target, op0, op1, op2);
12382 if (! pat)
12383 return 0;
12384 emit_insn (pat);
12385 return target;
12386
12387 case ARM_BUILTIN_SETWCX:
12388 arg0 = TREE_VALUE (arglist);
12389 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
12390 op0 = force_reg (SImode, expand_expr (arg0, NULL_RTX, VOIDmode, 0));
12391 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
12392 emit_insn (gen_iwmmxt_tmcr (op1, op0));
12393 return 0;
12394
12395 case ARM_BUILTIN_GETWCX:
12396 arg0 = TREE_VALUE (arglist);
12397 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12398 target = gen_reg_rtx (SImode);
12399 emit_insn (gen_iwmmxt_tmrc (target, op0));
12400 return target;
12401
12402 case ARM_BUILTIN_WSHUFH:
12403 icode = CODE_FOR_iwmmxt_wshufh;
12404 arg0 = TREE_VALUE (arglist);
12405 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
12406 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12407 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
12408 tmode = insn_data[icode].operand[0].mode;
12409 mode1 = insn_data[icode].operand[1].mode;
12410 mode2 = insn_data[icode].operand[2].mode;
12411
12412 if (! (*insn_data[icode].operand[1].predicate) (op0, mode1))
12413 op0 = copy_to_mode_reg (mode1, op0);
12414 if (! (*insn_data[icode].operand[2].predicate) (op1, mode2))
12415 {
12416 /* @@@ better error message */
12417 error ("mask must be an immediate");
12418 return const0_rtx;
12419 }
12420 if (target == 0
12421 || GET_MODE (target) != tmode
12422 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12423 target = gen_reg_rtx (tmode);
12424 pat = GEN_FCN (icode) (target, op0, op1);
12425 if (! pat)
12426 return 0;
12427 emit_insn (pat);
12428 return target;
12429
12430 case ARM_BUILTIN_WSADB:
12431 return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadb, arglist, target);
12432 case ARM_BUILTIN_WSADH:
12433 return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadh, arglist, target);
12434 case ARM_BUILTIN_WSADBZ:
12435 return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadbz, arglist, target);
12436 case ARM_BUILTIN_WSADHZ:
12437 return arm_expand_binop_builtin (CODE_FOR_iwmmxt_wsadhz, arglist, target);
12438
12439 /* Several three-argument builtins. */
12440 case ARM_BUILTIN_WMACS:
12441 case ARM_BUILTIN_WMACU:
12442 case ARM_BUILTIN_WALIGN:
12443 case ARM_BUILTIN_TMIA:
12444 case ARM_BUILTIN_TMIAPH:
12445 case ARM_BUILTIN_TMIATT:
12446 case ARM_BUILTIN_TMIATB:
12447 case ARM_BUILTIN_TMIABT:
12448 case ARM_BUILTIN_TMIABB:
12449 icode = (fcode == ARM_BUILTIN_WMACS ? CODE_FOR_iwmmxt_wmacs
12450 : fcode == ARM_BUILTIN_WMACU ? CODE_FOR_iwmmxt_wmacu
12451 : fcode == ARM_BUILTIN_TMIA ? CODE_FOR_iwmmxt_tmia
12452 : fcode == ARM_BUILTIN_TMIAPH ? CODE_FOR_iwmmxt_tmiaph
12453 : fcode == ARM_BUILTIN_TMIABB ? CODE_FOR_iwmmxt_tmiabb
12454 : fcode == ARM_BUILTIN_TMIABT ? CODE_FOR_iwmmxt_tmiabt
12455 : fcode == ARM_BUILTIN_TMIATB ? CODE_FOR_iwmmxt_tmiatb
12456 : fcode == ARM_BUILTIN_TMIATT ? CODE_FOR_iwmmxt_tmiatt
12457 : CODE_FOR_iwmmxt_walign);
12458 arg0 = TREE_VALUE (arglist);
12459 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
12460 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
12461 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
12462 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
12463 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
12464 tmode = insn_data[icode].operand[0].mode;
12465 mode0 = insn_data[icode].operand[1].mode;
12466 mode1 = insn_data[icode].operand[2].mode;
12467 mode2 = insn_data[icode].operand[3].mode;
12468
12469 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12470 op0 = copy_to_mode_reg (mode0, op0);
12471 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
12472 op1 = copy_to_mode_reg (mode1, op1);
12473 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
12474 op2 = copy_to_mode_reg (mode2, op2);
12475 if (target == 0
12476 || GET_MODE (target) != tmode
12477 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12478 target = gen_reg_rtx (tmode);
12479 pat = GEN_FCN (icode) (target, op0, op1, op2);
12480 if (! pat)
12481 return 0;
12482 emit_insn (pat);
12483 return target;
12484
12485 case ARM_BUILTIN_WZERO:
12486 target = gen_reg_rtx (DImode);
12487 emit_insn (gen_iwmmxt_clrdi (target));
12488 return target;
12489
12490 default:
12491 break;
12492 }
12493
12494 for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
12495 if (d->code == (const enum arm_builtins) fcode)
12496 return arm_expand_binop_builtin (d->icode, arglist, target);
12497
12498 for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
12499 if (d->code == (const enum arm_builtins) fcode)
12500 return arm_expand_unop_builtin (d->icode, arglist, target, 0);
12501
12502 /* @@@ Should really do something sensible here. */
12503 return NULL_RTX;
12504 }
12505 \f
12506 /* Recursively search through all of the blocks in a function
12507 checking to see if any of the variables created in that
12508 function match the RTX called 'orig'. If they do then
12509 replace them with the RTX called 'new'. */
12510 static void
12511 replace_symbols_in_block (tree block, rtx orig, rtx new)
12512 {
12513 for (; block; block = BLOCK_CHAIN (block))
12514 {
12515 tree sym;
12516
12517 if (!TREE_USED (block))
12518 continue;
12519
12520 for (sym = BLOCK_VARS (block); sym; sym = TREE_CHAIN (sym))
12521 {
12522 if ( (DECL_NAME (sym) == 0 && TREE_CODE (sym) != TYPE_DECL)
12523 || DECL_IGNORED_P (sym)
12524 || TREE_CODE (sym) != VAR_DECL
12525 || DECL_EXTERNAL (sym)
12526 || !rtx_equal_p (DECL_RTL (sym), orig)
12527 )
12528 continue;
12529
12530 SET_DECL_RTL (sym, new);
12531 }
12532
12533 replace_symbols_in_block (BLOCK_SUBBLOCKS (block), orig, new);
12534 }
12535 }
12536
12537 /* Return the number (counting from 0) of
12538 the least significant set bit in MASK. */
12539
12540 inline static int
12541 number_of_first_bit_set (int mask)
12542 {
12543 int bit;
12544
12545 for (bit = 0;
12546 (mask & (1 << bit)) == 0;
12547 ++bit)
12548 continue;
12549
12550 return bit;
12551 }
12552
12553 /* Generate code to return from a thumb function.
12554 If 'reg_containing_return_addr' is -1, then the return address is
12555 actually on the stack, at the stack pointer. */
12556 static void
12557 thumb_exit (FILE *f, int reg_containing_return_addr)
12558 {
12559 unsigned regs_available_for_popping;
12560 unsigned regs_to_pop;
12561 int pops_needed;
12562 unsigned available;
12563 unsigned required;
12564 int mode;
12565 int size;
12566 int restore_a4 = FALSE;
12567
12568 /* Compute the registers we need to pop. */
12569 regs_to_pop = 0;
12570 pops_needed = 0;
12571
12572 if (reg_containing_return_addr == -1)
12573 {
12574 regs_to_pop |= 1 << LR_REGNUM;
12575 ++pops_needed;
12576 }
12577
12578 if (TARGET_BACKTRACE)
12579 {
12580 /* Restore the (ARM) frame pointer and stack pointer. */
12581 regs_to_pop |= (1 << ARM_HARD_FRAME_POINTER_REGNUM) | (1 << SP_REGNUM);
12582 pops_needed += 2;
12583 }
12584
12585 /* If there is nothing to pop then just emit the BX instruction and
12586 return. */
12587 if (pops_needed == 0)
12588 {
12589 if (current_function_calls_eh_return)
12590 asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM);
12591
12592 asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr);
12593 return;
12594 }
12595 /* Otherwise if we are not supporting interworking and we have not created
12596 a backtrace structure and the function was not entered in ARM mode then
12597 just pop the return address straight into the PC. */
12598 else if (!TARGET_INTERWORK
12599 && !TARGET_BACKTRACE
12600 && !is_called_in_ARM_mode (current_function_decl)
12601 && !current_function_calls_eh_return)
12602 {
12603 asm_fprintf (f, "\tpop\t{%r}\n", PC_REGNUM);
12604 return;
12605 }
12606
12607 /* Find out how many of the (return) argument registers we can corrupt. */
12608 regs_available_for_popping = 0;
12609
12610 /* If returning via __builtin_eh_return, the bottom three registers
12611 all contain information needed for the return. */
12612 if (current_function_calls_eh_return)
12613 size = 12;
12614 else
12615 {
12616 /* If we can deduce the registers used from the function's
12617 return value. This is more reliable that examining
12618 regs_ever_live[] because that will be set if the register is
12619 ever used in the function, not just if the register is used
12620 to hold a return value. */
12621
12622 if (current_function_return_rtx != 0)
12623 mode = GET_MODE (current_function_return_rtx);
12624 else
12625 mode = DECL_MODE (DECL_RESULT (current_function_decl));
12626
12627 size = GET_MODE_SIZE (mode);
12628
12629 if (size == 0)
12630 {
12631 /* In a void function we can use any argument register.
12632 In a function that returns a structure on the stack
12633 we can use the second and third argument registers. */
12634 if (mode == VOIDmode)
12635 regs_available_for_popping =
12636 (1 << ARG_REGISTER (1))
12637 | (1 << ARG_REGISTER (2))
12638 | (1 << ARG_REGISTER (3));
12639 else
12640 regs_available_for_popping =
12641 (1 << ARG_REGISTER (2))
12642 | (1 << ARG_REGISTER (3));
12643 }
12644 else if (size <= 4)
12645 regs_available_for_popping =
12646 (1 << ARG_REGISTER (2))
12647 | (1 << ARG_REGISTER (3));
12648 else if (size <= 8)
12649 regs_available_for_popping =
12650 (1 << ARG_REGISTER (3));
12651 }
12652
12653 /* Match registers to be popped with registers into which we pop them. */
12654 for (available = regs_available_for_popping,
12655 required = regs_to_pop;
12656 required != 0 && available != 0;
12657 available &= ~(available & - available),
12658 required &= ~(required & - required))
12659 -- pops_needed;
12660
12661 /* If we have any popping registers left over, remove them. */
12662 if (available > 0)
12663 regs_available_for_popping &= ~available;
12664
12665 /* Otherwise if we need another popping register we can use
12666 the fourth argument register. */
12667 else if (pops_needed)
12668 {
12669 /* If we have not found any free argument registers and
12670 reg a4 contains the return address, we must move it. */
12671 if (regs_available_for_popping == 0
12672 && reg_containing_return_addr == LAST_ARG_REGNUM)
12673 {
12674 asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM);
12675 reg_containing_return_addr = LR_REGNUM;
12676 }
12677 else if (size > 12)
12678 {
12679 /* Register a4 is being used to hold part of the return value,
12680 but we have dire need of a free, low register. */
12681 restore_a4 = TRUE;
12682
12683 asm_fprintf (f, "\tmov\t%r, %r\n",IP_REGNUM, LAST_ARG_REGNUM);
12684 }
12685
12686 if (reg_containing_return_addr != LAST_ARG_REGNUM)
12687 {
12688 /* The fourth argument register is available. */
12689 regs_available_for_popping |= 1 << LAST_ARG_REGNUM;
12690
12691 --pops_needed;
12692 }
12693 }
12694
12695 /* Pop as many registers as we can. */
12696 thumb_pushpop (f, regs_available_for_popping, FALSE, NULL,
12697 regs_available_for_popping);
12698
12699 /* Process the registers we popped. */
12700 if (reg_containing_return_addr == -1)
12701 {
12702 /* The return address was popped into the lowest numbered register. */
12703 regs_to_pop &= ~(1 << LR_REGNUM);
12704
12705 reg_containing_return_addr =
12706 number_of_first_bit_set (regs_available_for_popping);
12707
12708 /* Remove this register for the mask of available registers, so that
12709 the return address will not be corrupted by further pops. */
12710 regs_available_for_popping &= ~(1 << reg_containing_return_addr);
12711 }
12712
12713 /* If we popped other registers then handle them here. */
12714 if (regs_available_for_popping)
12715 {
12716 int frame_pointer;
12717
12718 /* Work out which register currently contains the frame pointer. */
12719 frame_pointer = number_of_first_bit_set (regs_available_for_popping);
12720
12721 /* Move it into the correct place. */
12722 asm_fprintf (f, "\tmov\t%r, %r\n",
12723 ARM_HARD_FRAME_POINTER_REGNUM, frame_pointer);
12724
12725 /* (Temporarily) remove it from the mask of popped registers. */
12726 regs_available_for_popping &= ~(1 << frame_pointer);
12727 regs_to_pop &= ~(1 << ARM_HARD_FRAME_POINTER_REGNUM);
12728
12729 if (regs_available_for_popping)
12730 {
12731 int stack_pointer;
12732
12733 /* We popped the stack pointer as well,
12734 find the register that contains it. */
12735 stack_pointer = number_of_first_bit_set (regs_available_for_popping);
12736
12737 /* Move it into the stack register. */
12738 asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, stack_pointer);
12739
12740 /* At this point we have popped all necessary registers, so
12741 do not worry about restoring regs_available_for_popping
12742 to its correct value:
12743
12744 assert (pops_needed == 0)
12745 assert (regs_available_for_popping == (1 << frame_pointer))
12746 assert (regs_to_pop == (1 << STACK_POINTER)) */
12747 }
12748 else
12749 {
12750 /* Since we have just move the popped value into the frame
12751 pointer, the popping register is available for reuse, and
12752 we know that we still have the stack pointer left to pop. */
12753 regs_available_for_popping |= (1 << frame_pointer);
12754 }
12755 }
12756
12757 /* If we still have registers left on the stack, but we no longer have
12758 any registers into which we can pop them, then we must move the return
12759 address into the link register and make available the register that
12760 contained it. */
12761 if (regs_available_for_popping == 0 && pops_needed > 0)
12762 {
12763 regs_available_for_popping |= 1 << reg_containing_return_addr;
12764
12765 asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM,
12766 reg_containing_return_addr);
12767
12768 reg_containing_return_addr = LR_REGNUM;
12769 }
12770
12771 /* If we have registers left on the stack then pop some more.
12772 We know that at most we will want to pop FP and SP. */
12773 if (pops_needed > 0)
12774 {
12775 int popped_into;
12776 int move_to;
12777
12778 thumb_pushpop (f, regs_available_for_popping, FALSE, NULL,
12779 regs_available_for_popping);
12780
12781 /* We have popped either FP or SP.
12782 Move whichever one it is into the correct register. */
12783 popped_into = number_of_first_bit_set (regs_available_for_popping);
12784 move_to = number_of_first_bit_set (regs_to_pop);
12785
12786 asm_fprintf (f, "\tmov\t%r, %r\n", move_to, popped_into);
12787
12788 regs_to_pop &= ~(1 << move_to);
12789
12790 --pops_needed;
12791 }
12792
12793 /* If we still have not popped everything then we must have only
12794 had one register available to us and we are now popping the SP. */
12795 if (pops_needed > 0)
12796 {
12797 int popped_into;
12798
12799 thumb_pushpop (f, regs_available_for_popping, FALSE, NULL,
12800 regs_available_for_popping);
12801
12802 popped_into = number_of_first_bit_set (regs_available_for_popping);
12803
12804 asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, popped_into);
12805 /*
12806 assert (regs_to_pop == (1 << STACK_POINTER))
12807 assert (pops_needed == 1)
12808 */
12809 }
12810
12811 /* If necessary restore the a4 register. */
12812 if (restore_a4)
12813 {
12814 if (reg_containing_return_addr != LR_REGNUM)
12815 {
12816 asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM);
12817 reg_containing_return_addr = LR_REGNUM;
12818 }
12819
12820 asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM);
12821 }
12822
12823 if (current_function_calls_eh_return)
12824 asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, ARM_EH_STACKADJ_REGNUM);
12825
12826 /* Return to caller. */
12827 asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr);
12828 }
12829
12830 /* Emit code to push or pop registers to or from the stack. F is the
12831 assembly file. MASK is the registers to push or pop. PUSH is
12832 nonzero if we should push, and zero if we should pop. For debugging
12833 output, if pushing, adjust CFA_OFFSET by the amount of space added
12834 to the stack. REAL_REGS should have the same number of bits set as
12835 MASK, and will be used instead (in the same order) to describe which
12836 registers were saved - this is used to mark the save slots when we
12837 push high registers after moving them to low registers. */
12838 static void
12839 thumb_pushpop (FILE *f, int mask, int push, int *cfa_offset, int real_regs)
12840 {
12841 int regno;
12842 int lo_mask = mask & 0xFF;
12843 int pushed_words = 0;
12844
12845 if (lo_mask == 0 && !push && (mask & (1 << PC_REGNUM)))
12846 {
12847 /* Special case. Do not generate a POP PC statement here, do it in
12848 thumb_exit() */
12849 thumb_exit (f, -1);
12850 return;
12851 }
12852
12853 fprintf (f, "\t%s\t{", push ? "push" : "pop");
12854
12855 /* Look at the low registers first. */
12856 for (regno = 0; regno <= LAST_LO_REGNUM; regno++, lo_mask >>= 1)
12857 {
12858 if (lo_mask & 1)
12859 {
12860 asm_fprintf (f, "%r", regno);
12861
12862 if ((lo_mask & ~1) != 0)
12863 fprintf (f, ", ");
12864
12865 pushed_words++;
12866 }
12867 }
12868
12869 if (push && (mask & (1 << LR_REGNUM)))
12870 {
12871 /* Catch pushing the LR. */
12872 if (mask & 0xFF)
12873 fprintf (f, ", ");
12874
12875 asm_fprintf (f, "%r", LR_REGNUM);
12876
12877 pushed_words++;
12878 }
12879 else if (!push && (mask & (1 << PC_REGNUM)))
12880 {
12881 /* Catch popping the PC. */
12882 if (TARGET_INTERWORK || TARGET_BACKTRACE
12883 || current_function_calls_eh_return)
12884 {
12885 /* The PC is never poped directly, instead
12886 it is popped into r3 and then BX is used. */
12887 fprintf (f, "}\n");
12888
12889 thumb_exit (f, -1);
12890
12891 return;
12892 }
12893 else
12894 {
12895 if (mask & 0xFF)
12896 fprintf (f, ", ");
12897
12898 asm_fprintf (f, "%r", PC_REGNUM);
12899 }
12900 }
12901
12902 fprintf (f, "}\n");
12903
12904 if (push && pushed_words && dwarf2out_do_frame ())
12905 {
12906 char *l = dwarf2out_cfi_label ();
12907 int pushed_mask = real_regs;
12908
12909 *cfa_offset += pushed_words * 4;
12910 dwarf2out_def_cfa (l, SP_REGNUM, *cfa_offset);
12911
12912 pushed_words = 0;
12913 pushed_mask = real_regs;
12914 for (regno = 0; regno <= 14; regno++, pushed_mask >>= 1)
12915 {
12916 if (pushed_mask & 1)
12917 dwarf2out_reg_save (l, regno, 4 * pushed_words++ - *cfa_offset);
12918 }
12919 }
12920 }
12921 \f
12922 void
12923 thumb_final_prescan_insn (rtx insn)
12924 {
12925 if (flag_print_asm_name)
12926 asm_fprintf (asm_out_file, "%@ 0x%04x\n",
12927 INSN_ADDRESSES (INSN_UID (insn)));
12928 }
12929
12930 int
12931 thumb_shiftable_const (unsigned HOST_WIDE_INT val)
12932 {
12933 unsigned HOST_WIDE_INT mask = 0xff;
12934 int i;
12935
12936 if (val == 0) /* XXX */
12937 return 0;
12938
12939 for (i = 0; i < 25; i++)
12940 if ((val & (mask << i)) == val)
12941 return 1;
12942
12943 return 0;
12944 }
12945
12946 /* Returns nonzero if the current function contains,
12947 or might contain a far jump. */
12948 static int
12949 thumb_far_jump_used_p (void)
12950 {
12951 rtx insn;
12952
12953 /* This test is only important for leaf functions. */
12954 /* assert (!leaf_function_p ()); */
12955
12956 /* If we have already decided that far jumps may be used,
12957 do not bother checking again, and always return true even if
12958 it turns out that they are not being used. Once we have made
12959 the decision that far jumps are present (and that hence the link
12960 register will be pushed onto the stack) we cannot go back on it. */
12961 if (cfun->machine->far_jump_used)
12962 return 1;
12963
12964 /* If this function is not being called from the prologue/epilogue
12965 generation code then it must be being called from the
12966 INITIAL_ELIMINATION_OFFSET macro. */
12967 if (!(ARM_DOUBLEWORD_ALIGN || reload_completed))
12968 {
12969 /* In this case we know that we are being asked about the elimination
12970 of the arg pointer register. If that register is not being used,
12971 then there are no arguments on the stack, and we do not have to
12972 worry that a far jump might force the prologue to push the link
12973 register, changing the stack offsets. In this case we can just
12974 return false, since the presence of far jumps in the function will
12975 not affect stack offsets.
12976
12977 If the arg pointer is live (or if it was live, but has now been
12978 eliminated and so set to dead) then we do have to test to see if
12979 the function might contain a far jump. This test can lead to some
12980 false negatives, since before reload is completed, then length of
12981 branch instructions is not known, so gcc defaults to returning their
12982 longest length, which in turn sets the far jump attribute to true.
12983
12984 A false negative will not result in bad code being generated, but it
12985 will result in a needless push and pop of the link register. We
12986 hope that this does not occur too often.
12987
12988 If we need doubleword stack alignment this could affect the other
12989 elimination offsets so we can't risk getting it wrong. */
12990 if (regs_ever_live [ARG_POINTER_REGNUM])
12991 cfun->machine->arg_pointer_live = 1;
12992 else if (!cfun->machine->arg_pointer_live)
12993 return 0;
12994 }
12995
12996 /* Check to see if the function contains a branch
12997 insn with the far jump attribute set. */
12998 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
12999 {
13000 if (GET_CODE (insn) == JUMP_INSN
13001 /* Ignore tablejump patterns. */
13002 && GET_CODE (PATTERN (insn)) != ADDR_VEC
13003 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
13004 && get_attr_far_jump (insn) == FAR_JUMP_YES
13005 )
13006 {
13007 /* Record the fact that we have decided that
13008 the function does use far jumps. */
13009 cfun->machine->far_jump_used = 1;
13010 return 1;
13011 }
13012 }
13013
13014 return 0;
13015 }
13016
13017 /* Return nonzero if FUNC must be entered in ARM mode. */
13018 int
13019 is_called_in_ARM_mode (tree func)
13020 {
13021 if (TREE_CODE (func) != FUNCTION_DECL)
13022 abort ();
13023
13024 /* Ignore the problem about functions whoes address is taken. */
13025 if (TARGET_CALLEE_INTERWORKING && TREE_PUBLIC (func))
13026 return TRUE;
13027
13028 #ifdef ARM_PE
13029 return lookup_attribute ("interfacearm", DECL_ATTRIBUTES (func)) != NULL_TREE;
13030 #else
13031 return FALSE;
13032 #endif
13033 }
13034
13035 /* The bits which aren't usefully expanded as rtl. */
13036 const char *
13037 thumb_unexpanded_epilogue (void)
13038 {
13039 int regno;
13040 int live_regs_mask = 0;
13041 int high_regs_pushed = 0;
13042 int had_to_push_lr;
13043
13044 if (return_used_this_function)
13045 return "";
13046
13047 if (IS_NAKED (arm_current_func_type ()))
13048 return "";
13049
13050 for (regno = 0; regno <= LAST_LO_REGNUM; regno++)
13051 if (THUMB_REG_PUSHED_P (regno))
13052 live_regs_mask |= 1 << regno;
13053
13054 for (regno = 8; regno < 13; regno++)
13055 if (THUMB_REG_PUSHED_P (regno))
13056 high_regs_pushed++;
13057
13058 /* The prolog may have pushed some high registers to use as
13059 work registers. eg the testsuite file:
13060 gcc/testsuite/gcc/gcc.c-torture/execute/complex-2.c
13061 compiles to produce:
13062 push {r4, r5, r6, r7, lr}
13063 mov r7, r9
13064 mov r6, r8
13065 push {r6, r7}
13066 as part of the prolog. We have to undo that pushing here. */
13067
13068 if (high_regs_pushed)
13069 {
13070 int mask = live_regs_mask;
13071 int next_hi_reg;
13072 int size;
13073 int mode;
13074
13075 /* If we can deduce the registers used from the function's return value.
13076 This is more reliable that examining regs_ever_live[] because that
13077 will be set if the register is ever used in the function, not just if
13078 the register is used to hold a return value. */
13079
13080 if (current_function_return_rtx != 0)
13081 mode = GET_MODE (current_function_return_rtx);
13082 else
13083 mode = DECL_MODE (DECL_RESULT (current_function_decl));
13084
13085 size = GET_MODE_SIZE (mode);
13086
13087 /* Unless we are returning a type of size > 12 register r3 is
13088 available. */
13089 if (size < 13)
13090 mask |= 1 << 3;
13091
13092 if (mask == 0)
13093 /* Oh dear! We have no low registers into which we can pop
13094 high registers! */
13095 internal_error
13096 ("no low registers available for popping high registers");
13097
13098 for (next_hi_reg = 8; next_hi_reg < 13; next_hi_reg++)
13099 if (THUMB_REG_PUSHED_P (next_hi_reg))
13100 break;
13101
13102 while (high_regs_pushed)
13103 {
13104 /* Find lo register(s) into which the high register(s) can
13105 be popped. */
13106 for (regno = 0; regno <= LAST_LO_REGNUM; regno++)
13107 {
13108 if (mask & (1 << regno))
13109 high_regs_pushed--;
13110 if (high_regs_pushed == 0)
13111 break;
13112 }
13113
13114 mask &= (2 << regno) - 1; /* A noop if regno == 8 */
13115
13116 /* Pop the values into the low register(s). */
13117 thumb_pushpop (asm_out_file, mask, 0, NULL, mask);
13118
13119 /* Move the value(s) into the high registers. */
13120 for (regno = 0; regno <= LAST_LO_REGNUM; regno++)
13121 {
13122 if (mask & (1 << regno))
13123 {
13124 asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", next_hi_reg,
13125 regno);
13126
13127 for (next_hi_reg++; next_hi_reg < 13; next_hi_reg++)
13128 if (THUMB_REG_PUSHED_P (next_hi_reg))
13129 break;
13130 }
13131 }
13132 }
13133 }
13134
13135 had_to_push_lr = (live_regs_mask || thumb_force_lr_save ());
13136
13137 if (TARGET_BACKTRACE
13138 && ((live_regs_mask & 0xFF) == 0)
13139 && regs_ever_live [LAST_ARG_REGNUM] != 0)
13140 {
13141 /* The stack backtrace structure creation code had to
13142 push R7 in order to get a work register, so we pop
13143 it now. */
13144 live_regs_mask |= (1 << LAST_LO_REGNUM);
13145 }
13146
13147 if (current_function_pretend_args_size == 0 || TARGET_BACKTRACE)
13148 {
13149 if (had_to_push_lr
13150 && !is_called_in_ARM_mode (current_function_decl))
13151 live_regs_mask |= 1 << PC_REGNUM;
13152
13153 /* Either no argument registers were pushed or a backtrace
13154 structure was created which includes an adjusted stack
13155 pointer, so just pop everything. */
13156 if (live_regs_mask)
13157 thumb_pushpop (asm_out_file, live_regs_mask, FALSE, NULL,
13158 live_regs_mask);
13159
13160 /* We have either just popped the return address into the
13161 PC or it is was kept in LR for the entire function or
13162 it is still on the stack because we do not want to
13163 return by doing a pop {pc}. */
13164 if ((live_regs_mask & (1 << PC_REGNUM)) == 0)
13165 thumb_exit (asm_out_file,
13166 (had_to_push_lr
13167 && is_called_in_ARM_mode (current_function_decl)) ?
13168 -1 : LR_REGNUM);
13169 }
13170 else
13171 {
13172 /* Pop everything but the return address. */
13173 live_regs_mask &= ~(1 << PC_REGNUM);
13174
13175 if (live_regs_mask)
13176 thumb_pushpop (asm_out_file, live_regs_mask, FALSE, NULL,
13177 live_regs_mask);
13178
13179 if (had_to_push_lr)
13180 /* Get the return address into a temporary register. */
13181 thumb_pushpop (asm_out_file, 1 << LAST_ARG_REGNUM, 0, NULL,
13182 1 << LAST_ARG_REGNUM);
13183
13184 /* Remove the argument registers that were pushed onto the stack. */
13185 asm_fprintf (asm_out_file, "\tadd\t%r, %r, #%d\n",
13186 SP_REGNUM, SP_REGNUM,
13187 current_function_pretend_args_size);
13188
13189 thumb_exit (asm_out_file,
13190 had_to_push_lr ? LAST_ARG_REGNUM : LR_REGNUM);
13191 }
13192
13193 return "";
13194 }
13195
13196 /* Functions to save and restore machine-specific function data. */
13197 static struct machine_function *
13198 arm_init_machine_status (void)
13199 {
13200 struct machine_function *machine;
13201 machine = (machine_function *) ggc_alloc_cleared (sizeof (machine_function));
13202
13203 #if ARM_FT_UNKNOWN != 0
13204 machine->func_type = ARM_FT_UNKNOWN;
13205 #endif
13206 return machine;
13207 }
13208
13209 /* Return an RTX indicating where the return address to the
13210 calling function can be found. */
13211 rtx
13212 arm_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
13213 {
13214 if (count != 0)
13215 return NULL_RTX;
13216
13217 return get_hard_reg_initial_val (Pmode, LR_REGNUM);
13218 }
13219
13220 /* Do anything needed before RTL is emitted for each function. */
13221 void
13222 arm_init_expanders (void)
13223 {
13224 /* Arrange to initialize and mark the machine per-function status. */
13225 init_machine_status = arm_init_machine_status;
13226
13227 /* This is to stop the combine pass optimizing away the alignment
13228 adjustment of va_arg. */
13229 /* ??? It is claimed that this should not be necessary. */
13230 if (cfun)
13231 mark_reg_pointer (arg_pointer_rtx, PARM_BOUNDARY);
13232 }
13233
13234
13235 /* Like arm_compute_initial_elimination offset. Simpler because
13236 THUMB_HARD_FRAME_POINTER isn't actually the ABI specified frame pointer. */
13237
13238 HOST_WIDE_INT
13239 thumb_compute_initial_elimination_offset (unsigned int from, unsigned int to)
13240 {
13241 arm_stack_offsets *offsets;
13242
13243 offsets = arm_get_frame_offsets ();
13244
13245 switch (from)
13246 {
13247 case ARG_POINTER_REGNUM:
13248 switch (to)
13249 {
13250 case STACK_POINTER_REGNUM:
13251 return offsets->outgoing_args - offsets->saved_args;
13252
13253 case FRAME_POINTER_REGNUM:
13254 return offsets->soft_frame - offsets->saved_args;
13255
13256 case THUMB_HARD_FRAME_POINTER_REGNUM:
13257 case ARM_HARD_FRAME_POINTER_REGNUM:
13258 return offsets->saved_regs - offsets->saved_args;
13259
13260 default:
13261 abort();
13262 }
13263 break;
13264
13265 case FRAME_POINTER_REGNUM:
13266 switch (to)
13267 {
13268 case STACK_POINTER_REGNUM:
13269 return offsets->outgoing_args - offsets->soft_frame;
13270
13271 case THUMB_HARD_FRAME_POINTER_REGNUM:
13272 case ARM_HARD_FRAME_POINTER_REGNUM:
13273 return offsets->saved_regs - offsets->soft_frame;
13274
13275 default:
13276 abort();
13277 }
13278 break;
13279
13280 default:
13281 abort ();
13282 }
13283 }
13284
13285
13286 /* Generate the rest of a function's prologue. */
13287 void
13288 thumb_expand_prologue (void)
13289 {
13290 rtx insn, dwarf;
13291
13292 HOST_WIDE_INT amount;
13293 arm_stack_offsets *offsets;
13294 unsigned long func_type;
13295 int regno;
13296
13297 func_type = arm_current_func_type ();
13298
13299 /* Naked functions don't have prologues. */
13300 if (IS_NAKED (func_type))
13301 return;
13302
13303 if (IS_INTERRUPT (func_type))
13304 {
13305 error ("interrupt Service Routines cannot be coded in Thumb mode");
13306 return;
13307 }
13308
13309 offsets = arm_get_frame_offsets ();
13310
13311 if (frame_pointer_needed)
13312 {
13313 insn = emit_insn (gen_movsi (hard_frame_pointer_rtx,
13314 stack_pointer_rtx));
13315 RTX_FRAME_RELATED_P (insn) = 1;
13316 }
13317
13318 amount = offsets->outgoing_args - offsets->saved_regs;
13319 if (amount)
13320 {
13321 if (amount < 512)
13322 {
13323 insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
13324 GEN_INT (- amount)));
13325 RTX_FRAME_RELATED_P (insn) = 1;
13326 }
13327 else
13328 {
13329 rtx reg;
13330
13331 /* The stack decrement is too big for an immediate value in a single
13332 insn. In theory we could issue multiple subtracts, but after
13333 three of them it becomes more space efficient to place the full
13334 value in the constant pool and load into a register. (Also the
13335 ARM debugger really likes to see only one stack decrement per
13336 function). So instead we look for a scratch register into which
13337 we can load the decrement, and then we subtract this from the
13338 stack pointer. Unfortunately on the thumb the only available
13339 scratch registers are the argument registers, and we cannot use
13340 these as they may hold arguments to the function. Instead we
13341 attempt to locate a call preserved register which is used by this
13342 function. If we can find one, then we know that it will have
13343 been pushed at the start of the prologue and so we can corrupt
13344 it now. */
13345 for (regno = LAST_ARG_REGNUM + 1; regno <= LAST_LO_REGNUM; regno++)
13346 if (THUMB_REG_PUSHED_P (regno)
13347 && !(frame_pointer_needed
13348 && (regno == THUMB_HARD_FRAME_POINTER_REGNUM)))
13349 break;
13350
13351 if (regno > LAST_LO_REGNUM) /* Very unlikely. */
13352 {
13353 rtx spare = gen_rtx_REG (SImode, IP_REGNUM);
13354
13355 /* Choose an arbitrary, non-argument low register. */
13356 reg = gen_rtx_REG (SImode, LAST_LO_REGNUM);
13357
13358 /* Save it by copying it into a high, scratch register. */
13359 emit_insn (gen_movsi (spare, reg));
13360 /* Add a USE to stop propagate_one_insn() from barfing. */
13361 emit_insn (gen_prologue_use (spare));
13362
13363 /* Decrement the stack. */
13364 emit_insn (gen_movsi (reg, GEN_INT (- amount)));
13365 insn = emit_insn (gen_addsi3 (stack_pointer_rtx,
13366 stack_pointer_rtx, reg));
13367 RTX_FRAME_RELATED_P (insn) = 1;
13368 dwarf = gen_rtx_SET (SImode, stack_pointer_rtx,
13369 plus_constant (stack_pointer_rtx,
13370 -amount));
13371 RTX_FRAME_RELATED_P (dwarf) = 1;
13372 REG_NOTES (insn)
13373 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
13374 REG_NOTES (insn));
13375
13376 /* Restore the low register's original value. */
13377 emit_insn (gen_movsi (reg, spare));
13378
13379 /* Emit a USE of the restored scratch register, so that flow
13380 analysis will not consider the restore redundant. The
13381 register won't be used again in this function and isn't
13382 restored by the epilogue. */
13383 emit_insn (gen_prologue_use (reg));
13384 }
13385 else
13386 {
13387 reg = gen_rtx_REG (SImode, regno);
13388
13389 emit_insn (gen_movsi (reg, GEN_INT (- amount)));
13390
13391 insn = emit_insn (gen_addsi3 (stack_pointer_rtx,
13392 stack_pointer_rtx, reg));
13393 RTX_FRAME_RELATED_P (insn) = 1;
13394 dwarf = gen_rtx_SET (SImode, stack_pointer_rtx,
13395 plus_constant (stack_pointer_rtx,
13396 -amount));
13397 RTX_FRAME_RELATED_P (dwarf) = 1;
13398 REG_NOTES (insn)
13399 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf,
13400 REG_NOTES (insn));
13401 }
13402 }
13403 /* If the frame pointer is needed, emit a special barrier that
13404 will prevent the scheduler from moving stores to the frame
13405 before the stack adjustment. */
13406 if (frame_pointer_needed)
13407 emit_insn (gen_stack_tie (stack_pointer_rtx,
13408 hard_frame_pointer_rtx));
13409 }
13410
13411 if (current_function_profile || TARGET_NO_SCHED_PRO)
13412 emit_insn (gen_blockage ());
13413
13414 cfun->machine->lr_save_eliminated = !thumb_force_lr_save ();
13415 for (regno = 0; regno <= LAST_LO_REGNUM; regno++)
13416 {
13417 if (THUMB_REG_PUSHED_P (regno))
13418 {
13419 cfun->machine->lr_save_eliminated = 0;
13420 break;
13421 }
13422 }
13423
13424 /* If the link register is being kept alive, with the return address in it,
13425 then make sure that it does not get reused by the ce2 pass. */
13426 if (cfun->machine->lr_save_eliminated)
13427 emit_insn (gen_prologue_use (gen_rtx_REG (SImode, LR_REGNUM)));
13428 }
13429
13430 void
13431 thumb_expand_epilogue (void)
13432 {
13433 HOST_WIDE_INT amount;
13434 arm_stack_offsets *offsets;
13435 int regno;
13436
13437 /* Naked functions don't have prologues. */
13438 if (IS_NAKED (arm_current_func_type ()))
13439 return;
13440
13441 offsets = arm_get_frame_offsets ();
13442 amount = offsets->outgoing_args - offsets->saved_regs;
13443
13444 if (frame_pointer_needed)
13445 emit_insn (gen_movsi (stack_pointer_rtx, hard_frame_pointer_rtx));
13446 else if (amount)
13447 {
13448 if (amount < 512)
13449 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
13450 GEN_INT (amount)));
13451 else
13452 {
13453 /* r3 is always free in the epilogue. */
13454 rtx reg = gen_rtx_REG (SImode, LAST_ARG_REGNUM);
13455
13456 emit_insn (gen_movsi (reg, GEN_INT (amount)));
13457 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
13458 }
13459 }
13460
13461 /* Emit a USE (stack_pointer_rtx), so that
13462 the stack adjustment will not be deleted. */
13463 emit_insn (gen_prologue_use (stack_pointer_rtx));
13464
13465 if (current_function_profile || TARGET_NO_SCHED_PRO)
13466 emit_insn (gen_blockage ());
13467
13468 /* Emit a clobber for each insn that will be restored in the epilogue,
13469 so that flow2 will get register lifetimes correct. */
13470 for (regno = 0; regno < 13; regno++)
13471 if (regs_ever_live[regno] && !call_used_regs[regno])
13472 emit_insn (gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, regno)));
13473
13474 if (! regs_ever_live[LR_REGNUM])
13475 emit_insn (gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, LR_REGNUM)));
13476 }
13477
13478 static void
13479 thumb_output_function_prologue (FILE *f, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
13480 {
13481 int live_regs_mask = 0;
13482 int high_regs_pushed = 0;
13483 int cfa_offset = 0;
13484 int regno;
13485
13486 if (IS_NAKED (arm_current_func_type ()))
13487 return;
13488
13489 if (is_called_in_ARM_mode (current_function_decl))
13490 {
13491 const char * name;
13492
13493 if (GET_CODE (DECL_RTL (current_function_decl)) != MEM)
13494 abort ();
13495 if (GET_CODE (XEXP (DECL_RTL (current_function_decl), 0)) != SYMBOL_REF)
13496 abort ();
13497 name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
13498
13499 /* Generate code sequence to switch us into Thumb mode. */
13500 /* The .code 32 directive has already been emitted by
13501 ASM_DECLARE_FUNCTION_NAME. */
13502 asm_fprintf (f, "\torr\t%r, %r, #1\n", IP_REGNUM, PC_REGNUM);
13503 asm_fprintf (f, "\tbx\t%r\n", IP_REGNUM);
13504
13505 /* Generate a label, so that the debugger will notice the
13506 change in instruction sets. This label is also used by
13507 the assembler to bypass the ARM code when this function
13508 is called from a Thumb encoded function elsewhere in the
13509 same file. Hence the definition of STUB_NAME here must
13510 agree with the definition in gas/config/tc-arm.c. */
13511
13512 #define STUB_NAME ".real_start_of"
13513
13514 fprintf (f, "\t.code\t16\n");
13515 #ifdef ARM_PE
13516 if (arm_dllexport_name_p (name))
13517 name = arm_strip_name_encoding (name);
13518 #endif
13519 asm_fprintf (f, "\t.globl %s%U%s\n", STUB_NAME, name);
13520 fprintf (f, "\t.thumb_func\n");
13521 asm_fprintf (f, "%s%U%s:\n", STUB_NAME, name);
13522 }
13523
13524 if (current_function_pretend_args_size)
13525 {
13526 if (cfun->machine->uses_anonymous_args)
13527 {
13528 int num_pushes;
13529
13530 fprintf (f, "\tpush\t{");
13531
13532 num_pushes = ARM_NUM_INTS (current_function_pretend_args_size);
13533
13534 for (regno = LAST_ARG_REGNUM + 1 - num_pushes;
13535 regno <= LAST_ARG_REGNUM;
13536 regno++)
13537 asm_fprintf (f, "%r%s", regno,
13538 regno == LAST_ARG_REGNUM ? "" : ", ");
13539
13540 fprintf (f, "}\n");
13541 }
13542 else
13543 asm_fprintf (f, "\tsub\t%r, %r, #%d\n",
13544 SP_REGNUM, SP_REGNUM,
13545 current_function_pretend_args_size);
13546
13547 /* We don't need to record the stores for unwinding (would it
13548 help the debugger any if we did?), but record the change in
13549 the stack pointer. */
13550 if (dwarf2out_do_frame ())
13551 {
13552 char *l = dwarf2out_cfi_label ();
13553 cfa_offset = cfa_offset + current_function_pretend_args_size;
13554 dwarf2out_def_cfa (l, SP_REGNUM, cfa_offset);
13555 }
13556 }
13557
13558 for (regno = 0; regno <= LAST_LO_REGNUM; regno++)
13559 if (THUMB_REG_PUSHED_P (regno))
13560 live_regs_mask |= 1 << regno;
13561
13562 if (live_regs_mask || thumb_force_lr_save ())
13563 live_regs_mask |= 1 << LR_REGNUM;
13564
13565 if (TARGET_BACKTRACE)
13566 {
13567 int offset;
13568 int work_register = 0;
13569 int wr;
13570
13571 /* We have been asked to create a stack backtrace structure.
13572 The code looks like this:
13573
13574 0 .align 2
13575 0 func:
13576 0 sub SP, #16 Reserve space for 4 registers.
13577 2 push {R7} Get a work register.
13578 4 add R7, SP, #20 Get the stack pointer before the push.
13579 6 str R7, [SP, #8] Store the stack pointer (before reserving the space).
13580 8 mov R7, PC Get hold of the start of this code plus 12.
13581 10 str R7, [SP, #16] Store it.
13582 12 mov R7, FP Get hold of the current frame pointer.
13583 14 str R7, [SP, #4] Store it.
13584 16 mov R7, LR Get hold of the current return address.
13585 18 str R7, [SP, #12] Store it.
13586 20 add R7, SP, #16 Point at the start of the backtrace structure.
13587 22 mov FP, R7 Put this value into the frame pointer. */
13588
13589 if ((live_regs_mask & 0xFF) == 0)
13590 {
13591 /* See if the a4 register is free. */
13592
13593 if (regs_ever_live [LAST_ARG_REGNUM] == 0)
13594 work_register = LAST_ARG_REGNUM;
13595 else /* We must push a register of our own. */
13596 live_regs_mask |= (1 << LAST_LO_REGNUM);
13597 }
13598
13599 if (work_register == 0)
13600 {
13601 /* Select a register from the list that will be pushed to
13602 use as our work register. */
13603 for (work_register = (LAST_LO_REGNUM + 1); work_register--;)
13604 if ((1 << work_register) & live_regs_mask)
13605 break;
13606 }
13607
13608 asm_fprintf
13609 (f, "\tsub\t%r, %r, #16\t%@ Create stack backtrace structure\n",
13610 SP_REGNUM, SP_REGNUM);
13611
13612 if (dwarf2out_do_frame ())
13613 {
13614 char *l = dwarf2out_cfi_label ();
13615 cfa_offset = cfa_offset + 16;
13616 dwarf2out_def_cfa (l, SP_REGNUM, cfa_offset);
13617 }
13618
13619 if (live_regs_mask)
13620 thumb_pushpop (f, live_regs_mask, 1, &cfa_offset, live_regs_mask);
13621
13622 for (offset = 0, wr = 1 << 15; wr != 0; wr >>= 1)
13623 if (wr & live_regs_mask)
13624 offset += 4;
13625
13626 asm_fprintf (f, "\tadd\t%r, %r, #%d\n", work_register, SP_REGNUM,
13627 offset + 16 + current_function_pretend_args_size);
13628
13629 asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM,
13630 offset + 4);
13631
13632 /* Make sure that the instruction fetching the PC is in the right place
13633 to calculate "start of backtrace creation code + 12". */
13634 if (live_regs_mask)
13635 {
13636 asm_fprintf (f, "\tmov\t%r, %r\n", work_register, PC_REGNUM);
13637 asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM,
13638 offset + 12);
13639 asm_fprintf (f, "\tmov\t%r, %r\n", work_register,
13640 ARM_HARD_FRAME_POINTER_REGNUM);
13641 asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM,
13642 offset);
13643 }
13644 else
13645 {
13646 asm_fprintf (f, "\tmov\t%r, %r\n", work_register,
13647 ARM_HARD_FRAME_POINTER_REGNUM);
13648 asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM,
13649 offset);
13650 asm_fprintf (f, "\tmov\t%r, %r\n", work_register, PC_REGNUM);
13651 asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM,
13652 offset + 12);
13653 }
13654
13655 asm_fprintf (f, "\tmov\t%r, %r\n", work_register, LR_REGNUM);
13656 asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM,
13657 offset + 8);
13658 asm_fprintf (f, "\tadd\t%r, %r, #%d\n", work_register, SP_REGNUM,
13659 offset + 12);
13660 asm_fprintf (f, "\tmov\t%r, %r\t\t%@ Backtrace structure created\n",
13661 ARM_HARD_FRAME_POINTER_REGNUM, work_register);
13662 }
13663 else if (live_regs_mask)
13664 thumb_pushpop (f, live_regs_mask, 1, &cfa_offset, live_regs_mask);
13665
13666 for (regno = 8; regno < 13; regno++)
13667 if (THUMB_REG_PUSHED_P (regno))
13668 high_regs_pushed++;
13669
13670 if (high_regs_pushed)
13671 {
13672 int pushable_regs = 0;
13673 int mask = live_regs_mask & 0xff;
13674 int next_hi_reg;
13675
13676 for (next_hi_reg = 12; next_hi_reg > LAST_LO_REGNUM; next_hi_reg--)
13677 if (THUMB_REG_PUSHED_P (next_hi_reg))
13678 break;
13679
13680 pushable_regs = mask;
13681
13682 if (pushable_regs == 0)
13683 {
13684 /* Desperation time -- this probably will never happen. */
13685 if (THUMB_REG_PUSHED_P (LAST_ARG_REGNUM))
13686 asm_fprintf (f, "\tmov\t%r, %r\n", IP_REGNUM, LAST_ARG_REGNUM);
13687 mask = 1 << LAST_ARG_REGNUM;
13688 }
13689
13690 while (high_regs_pushed > 0)
13691 {
13692 int real_regs_mask = 0;
13693
13694 for (regno = LAST_LO_REGNUM; regno >= 0; regno--)
13695 {
13696 if (mask & (1 << regno))
13697 {
13698 asm_fprintf (f, "\tmov\t%r, %r\n", regno, next_hi_reg);
13699
13700 high_regs_pushed--;
13701 real_regs_mask |= (1 << next_hi_reg);
13702
13703 if (high_regs_pushed)
13704 {
13705 for (next_hi_reg--; next_hi_reg > LAST_LO_REGNUM;
13706 next_hi_reg--)
13707 if (THUMB_REG_PUSHED_P (next_hi_reg))
13708 break;
13709 }
13710 else
13711 {
13712 mask &= ~((1 << regno) - 1);
13713 break;
13714 }
13715 }
13716 }
13717
13718 thumb_pushpop (f, mask, 1, &cfa_offset, real_regs_mask);
13719 }
13720
13721 if (pushable_regs == 0
13722 && (THUMB_REG_PUSHED_P (LAST_ARG_REGNUM)))
13723 asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM);
13724 }
13725 }
13726
13727 /* Handle the case of a double word load into a low register from
13728 a computed memory address. The computed address may involve a
13729 register which is overwritten by the load. */
13730 const char *
13731 thumb_load_double_from_address (rtx *operands)
13732 {
13733 rtx addr;
13734 rtx base;
13735 rtx offset;
13736 rtx arg1;
13737 rtx arg2;
13738
13739 if (GET_CODE (operands[0]) != REG)
13740 abort ();
13741
13742 if (GET_CODE (operands[1]) != MEM)
13743 abort ();
13744
13745 /* Get the memory address. */
13746 addr = XEXP (operands[1], 0);
13747
13748 /* Work out how the memory address is computed. */
13749 switch (GET_CODE (addr))
13750 {
13751 case REG:
13752 operands[2] = gen_rtx_MEM (SImode,
13753 plus_constant (XEXP (operands[1], 0), 4));
13754
13755 if (REGNO (operands[0]) == REGNO (addr))
13756 {
13757 output_asm_insn ("ldr\t%H0, %2", operands);
13758 output_asm_insn ("ldr\t%0, %1", operands);
13759 }
13760 else
13761 {
13762 output_asm_insn ("ldr\t%0, %1", operands);
13763 output_asm_insn ("ldr\t%H0, %2", operands);
13764 }
13765 break;
13766
13767 case CONST:
13768 /* Compute <address> + 4 for the high order load. */
13769 operands[2] = gen_rtx_MEM (SImode,
13770 plus_constant (XEXP (operands[1], 0), 4));
13771
13772 output_asm_insn ("ldr\t%0, %1", operands);
13773 output_asm_insn ("ldr\t%H0, %2", operands);
13774 break;
13775
13776 case PLUS:
13777 arg1 = XEXP (addr, 0);
13778 arg2 = XEXP (addr, 1);
13779
13780 if (CONSTANT_P (arg1))
13781 base = arg2, offset = arg1;
13782 else
13783 base = arg1, offset = arg2;
13784
13785 if (GET_CODE (base) != REG)
13786 abort ();
13787
13788 /* Catch the case of <address> = <reg> + <reg> */
13789 if (GET_CODE (offset) == REG)
13790 {
13791 int reg_offset = REGNO (offset);
13792 int reg_base = REGNO (base);
13793 int reg_dest = REGNO (operands[0]);
13794
13795 /* Add the base and offset registers together into the
13796 higher destination register. */
13797 asm_fprintf (asm_out_file, "\tadd\t%r, %r, %r",
13798 reg_dest + 1, reg_base, reg_offset);
13799
13800 /* Load the lower destination register from the address in
13801 the higher destination register. */
13802 asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #0]",
13803 reg_dest, reg_dest + 1);
13804
13805 /* Load the higher destination register from its own address
13806 plus 4. */
13807 asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #4]",
13808 reg_dest + 1, reg_dest + 1);
13809 }
13810 else
13811 {
13812 /* Compute <address> + 4 for the high order load. */
13813 operands[2] = gen_rtx_MEM (SImode,
13814 plus_constant (XEXP (operands[1], 0), 4));
13815
13816 /* If the computed address is held in the low order register
13817 then load the high order register first, otherwise always
13818 load the low order register first. */
13819 if (REGNO (operands[0]) == REGNO (base))
13820 {
13821 output_asm_insn ("ldr\t%H0, %2", operands);
13822 output_asm_insn ("ldr\t%0, %1", operands);
13823 }
13824 else
13825 {
13826 output_asm_insn ("ldr\t%0, %1", operands);
13827 output_asm_insn ("ldr\t%H0, %2", operands);
13828 }
13829 }
13830 break;
13831
13832 case LABEL_REF:
13833 /* With no registers to worry about we can just load the value
13834 directly. */
13835 operands[2] = gen_rtx_MEM (SImode,
13836 plus_constant (XEXP (operands[1], 0), 4));
13837
13838 output_asm_insn ("ldr\t%H0, %2", operands);
13839 output_asm_insn ("ldr\t%0, %1", operands);
13840 break;
13841
13842 default:
13843 abort ();
13844 break;
13845 }
13846
13847 return "";
13848 }
13849
13850 const char *
13851 thumb_output_move_mem_multiple (int n, rtx *operands)
13852 {
13853 rtx tmp;
13854
13855 switch (n)
13856 {
13857 case 2:
13858 if (REGNO (operands[4]) > REGNO (operands[5]))
13859 {
13860 tmp = operands[4];
13861 operands[4] = operands[5];
13862 operands[5] = tmp;
13863 }
13864 output_asm_insn ("ldmia\t%1!, {%4, %5}", operands);
13865 output_asm_insn ("stmia\t%0!, {%4, %5}", operands);
13866 break;
13867
13868 case 3:
13869 if (REGNO (operands[4]) > REGNO (operands[5]))
13870 {
13871 tmp = operands[4];
13872 operands[4] = operands[5];
13873 operands[5] = tmp;
13874 }
13875 if (REGNO (operands[5]) > REGNO (operands[6]))
13876 {
13877 tmp = operands[5];
13878 operands[5] = operands[6];
13879 operands[6] = tmp;
13880 }
13881 if (REGNO (operands[4]) > REGNO (operands[5]))
13882 {
13883 tmp = operands[4];
13884 operands[4] = operands[5];
13885 operands[5] = tmp;
13886 }
13887
13888 output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands);
13889 output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands);
13890 break;
13891
13892 default:
13893 abort ();
13894 }
13895
13896 return "";
13897 }
13898
13899 /* Routines for generating rtl. */
13900 void
13901 thumb_expand_movmemqi (rtx *operands)
13902 {
13903 rtx out = copy_to_mode_reg (SImode, XEXP (operands[0], 0));
13904 rtx in = copy_to_mode_reg (SImode, XEXP (operands[1], 0));
13905 HOST_WIDE_INT len = INTVAL (operands[2]);
13906 HOST_WIDE_INT offset = 0;
13907
13908 while (len >= 12)
13909 {
13910 emit_insn (gen_movmem12b (out, in, out, in));
13911 len -= 12;
13912 }
13913
13914 if (len >= 8)
13915 {
13916 emit_insn (gen_movmem8b (out, in, out, in));
13917 len -= 8;
13918 }
13919
13920 if (len >= 4)
13921 {
13922 rtx reg = gen_reg_rtx (SImode);
13923 emit_insn (gen_movsi (reg, gen_rtx_MEM (SImode, in)));
13924 emit_insn (gen_movsi (gen_rtx_MEM (SImode, out), reg));
13925 len -= 4;
13926 offset += 4;
13927 }
13928
13929 if (len >= 2)
13930 {
13931 rtx reg = gen_reg_rtx (HImode);
13932 emit_insn (gen_movhi (reg, gen_rtx_MEM (HImode,
13933 plus_constant (in, offset))));
13934 emit_insn (gen_movhi (gen_rtx_MEM (HImode, plus_constant (out, offset)),
13935 reg));
13936 len -= 2;
13937 offset += 2;
13938 }
13939
13940 if (len)
13941 {
13942 rtx reg = gen_reg_rtx (QImode);
13943 emit_insn (gen_movqi (reg, gen_rtx_MEM (QImode,
13944 plus_constant (in, offset))));
13945 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (out, offset)),
13946 reg));
13947 }
13948 }
13949
13950 int
13951 thumb_cmp_operand (rtx op, enum machine_mode mode)
13952 {
13953 return ((GET_CODE (op) == CONST_INT
13954 && INTVAL (op) < 256
13955 && INTVAL (op) >= 0)
13956 || s_register_operand (op, mode));
13957 }
13958
13959 int
13960 thumb_cmpneg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
13961 {
13962 return (GET_CODE (op) == CONST_INT
13963 && INTVAL (op) < 0
13964 && INTVAL (op) > -256);
13965 }
13966
13967 /* Return TRUE if a result can be stored in OP without clobbering the
13968 condition code register. Prior to reload we only accept a
13969 register. After reload we have to be able to handle memory as
13970 well, since a pseudo may not get a hard reg and reload cannot
13971 handle output-reloads on jump insns.
13972
13973 We could possibly handle mem before reload as well, but that might
13974 complicate things with the need to handle increment
13975 side-effects. */
13976
13977 int
13978 thumb_cbrch_target_operand (rtx op, enum machine_mode mode)
13979 {
13980 return (s_register_operand (op, mode)
13981 || ((reload_in_progress || reload_completed)
13982 && memory_operand (op, mode)));
13983 }
13984
13985 /* Handle storing a half-word to memory during reload. */
13986 void
13987 thumb_reload_out_hi (rtx *operands)
13988 {
13989 emit_insn (gen_thumb_movhi_clobber (operands[0], operands[1], operands[2]));
13990 }
13991
13992 /* Handle reading a half-word from memory during reload. */
13993 void
13994 thumb_reload_in_hi (rtx *operands ATTRIBUTE_UNUSED)
13995 {
13996 abort ();
13997 }
13998
13999 /* Return the length of a function name prefix
14000 that starts with the character 'c'. */
14001 static int
14002 arm_get_strip_length (int c)
14003 {
14004 switch (c)
14005 {
14006 ARM_NAME_ENCODING_LENGTHS
14007 default: return 0;
14008 }
14009 }
14010
14011 /* Return a pointer to a function's name with any
14012 and all prefix encodings stripped from it. */
14013 const char *
14014 arm_strip_name_encoding (const char *name)
14015 {
14016 int skip;
14017
14018 while ((skip = arm_get_strip_length (* name)))
14019 name += skip;
14020
14021 return name;
14022 }
14023
14024 /* If there is a '*' anywhere in the name's prefix, then
14025 emit the stripped name verbatim, otherwise prepend an
14026 underscore if leading underscores are being used. */
14027 void
14028 arm_asm_output_labelref (FILE *stream, const char *name)
14029 {
14030 int skip;
14031 int verbatim = 0;
14032
14033 while ((skip = arm_get_strip_length (* name)))
14034 {
14035 verbatim |= (*name == '*');
14036 name += skip;
14037 }
14038
14039 if (verbatim)
14040 fputs (name, stream);
14041 else
14042 asm_fprintf (stream, "%U%s", name);
14043 }
14044
14045 rtx aof_pic_label;
14046
14047 #ifdef AOF_ASSEMBLER
14048 /* Special functions only needed when producing AOF syntax assembler. */
14049
14050 struct pic_chain
14051 {
14052 struct pic_chain * next;
14053 const char * symname;
14054 };
14055
14056 static struct pic_chain * aof_pic_chain = NULL;
14057
14058 rtx
14059 aof_pic_entry (rtx x)
14060 {
14061 struct pic_chain ** chainp;
14062 int offset;
14063
14064 if (aof_pic_label == NULL_RTX)
14065 {
14066 aof_pic_label = gen_rtx_SYMBOL_REF (Pmode, "x$adcons");
14067 }
14068
14069 for (offset = 0, chainp = &aof_pic_chain; *chainp;
14070 offset += 4, chainp = &(*chainp)->next)
14071 if ((*chainp)->symname == XSTR (x, 0))
14072 return plus_constant (aof_pic_label, offset);
14073
14074 *chainp = (struct pic_chain *) xmalloc (sizeof (struct pic_chain));
14075 (*chainp)->next = NULL;
14076 (*chainp)->symname = XSTR (x, 0);
14077 return plus_constant (aof_pic_label, offset);
14078 }
14079
14080 void
14081 aof_dump_pic_table (FILE *f)
14082 {
14083 struct pic_chain * chain;
14084
14085 if (aof_pic_chain == NULL)
14086 return;
14087
14088 asm_fprintf (f, "\tAREA |%r$$adcons|, BASED %r\n",
14089 PIC_OFFSET_TABLE_REGNUM,
14090 PIC_OFFSET_TABLE_REGNUM);
14091 fputs ("|x$adcons|\n", f);
14092
14093 for (chain = aof_pic_chain; chain; chain = chain->next)
14094 {
14095 fputs ("\tDCD\t", f);
14096 assemble_name (f, chain->symname);
14097 fputs ("\n", f);
14098 }
14099 }
14100
14101 int arm_text_section_count = 1;
14102
14103 char *
14104 aof_text_section (void )
14105 {
14106 static char buf[100];
14107 sprintf (buf, "\tAREA |C$$code%d|, CODE, READONLY",
14108 arm_text_section_count++);
14109 if (flag_pic)
14110 strcat (buf, ", PIC, REENTRANT");
14111 return buf;
14112 }
14113
14114 static int arm_data_section_count = 1;
14115
14116 char *
14117 aof_data_section (void)
14118 {
14119 static char buf[100];
14120 sprintf (buf, "\tAREA |C$$data%d|, DATA", arm_data_section_count++);
14121 return buf;
14122 }
14123
14124 /* The AOF assembler is religiously strict about declarations of
14125 imported and exported symbols, so that it is impossible to declare
14126 a function as imported near the beginning of the file, and then to
14127 export it later on. It is, however, possible to delay the decision
14128 until all the functions in the file have been compiled. To get
14129 around this, we maintain a list of the imports and exports, and
14130 delete from it any that are subsequently defined. At the end of
14131 compilation we spit the remainder of the list out before the END
14132 directive. */
14133
14134 struct import
14135 {
14136 struct import * next;
14137 const char * name;
14138 };
14139
14140 static struct import * imports_list = NULL;
14141
14142 void
14143 aof_add_import (const char *name)
14144 {
14145 struct import * new;
14146
14147 for (new = imports_list; new; new = new->next)
14148 if (new->name == name)
14149 return;
14150
14151 new = (struct import *) xmalloc (sizeof (struct import));
14152 new->next = imports_list;
14153 imports_list = new;
14154 new->name = name;
14155 }
14156
14157 void
14158 aof_delete_import (const char *name)
14159 {
14160 struct import ** old;
14161
14162 for (old = &imports_list; *old; old = & (*old)->next)
14163 {
14164 if ((*old)->name == name)
14165 {
14166 *old = (*old)->next;
14167 return;
14168 }
14169 }
14170 }
14171
14172 int arm_main_function = 0;
14173
14174 static void
14175 aof_dump_imports (FILE *f)
14176 {
14177 /* The AOF assembler needs this to cause the startup code to be extracted
14178 from the library. Brining in __main causes the whole thing to work
14179 automagically. */
14180 if (arm_main_function)
14181 {
14182 text_section ();
14183 fputs ("\tIMPORT __main\n", f);
14184 fputs ("\tDCD __main\n", f);
14185 }
14186
14187 /* Now dump the remaining imports. */
14188 while (imports_list)
14189 {
14190 fprintf (f, "\tIMPORT\t");
14191 assemble_name (f, imports_list->name);
14192 fputc ('\n', f);
14193 imports_list = imports_list->next;
14194 }
14195 }
14196
14197 static void
14198 aof_globalize_label (FILE *stream, const char *name)
14199 {
14200 default_globalize_label (stream, name);
14201 if (! strcmp (name, "main"))
14202 arm_main_function = 1;
14203 }
14204
14205 static void
14206 aof_file_start (void)
14207 {
14208 fputs ("__r0\tRN\t0\n", asm_out_file);
14209 fputs ("__a1\tRN\t0\n", asm_out_file);
14210 fputs ("__a2\tRN\t1\n", asm_out_file);
14211 fputs ("__a3\tRN\t2\n", asm_out_file);
14212 fputs ("__a4\tRN\t3\n", asm_out_file);
14213 fputs ("__v1\tRN\t4\n", asm_out_file);
14214 fputs ("__v2\tRN\t5\n", asm_out_file);
14215 fputs ("__v3\tRN\t6\n", asm_out_file);
14216 fputs ("__v4\tRN\t7\n", asm_out_file);
14217 fputs ("__v5\tRN\t8\n", asm_out_file);
14218 fputs ("__v6\tRN\t9\n", asm_out_file);
14219 fputs ("__sl\tRN\t10\n", asm_out_file);
14220 fputs ("__fp\tRN\t11\n", asm_out_file);
14221 fputs ("__ip\tRN\t12\n", asm_out_file);
14222 fputs ("__sp\tRN\t13\n", asm_out_file);
14223 fputs ("__lr\tRN\t14\n", asm_out_file);
14224 fputs ("__pc\tRN\t15\n", asm_out_file);
14225 fputs ("__f0\tFN\t0\n", asm_out_file);
14226 fputs ("__f1\tFN\t1\n", asm_out_file);
14227 fputs ("__f2\tFN\t2\n", asm_out_file);
14228 fputs ("__f3\tFN\t3\n", asm_out_file);
14229 fputs ("__f4\tFN\t4\n", asm_out_file);
14230 fputs ("__f5\tFN\t5\n", asm_out_file);
14231 fputs ("__f6\tFN\t6\n", asm_out_file);
14232 fputs ("__f7\tFN\t7\n", asm_out_file);
14233 text_section ();
14234 }
14235
14236 static void
14237 aof_file_end (void)
14238 {
14239 if (flag_pic)
14240 aof_dump_pic_table (asm_out_file);
14241 aof_dump_imports (asm_out_file);
14242 fputs ("\tEND\n", asm_out_file);
14243 }
14244 #endif /* AOF_ASSEMBLER */
14245
14246 #ifdef OBJECT_FORMAT_ELF
14247 /* Switch to an arbitrary section NAME with attributes as specified
14248 by FLAGS. ALIGN specifies any known alignment requirements for
14249 the section; 0 if the default should be used.
14250
14251 Differs from the default elf version only in the prefix character
14252 used before the section type. */
14253
14254 static void
14255 arm_elf_asm_named_section (const char *name, unsigned int flags)
14256 {
14257 char flagchars[10], *f = flagchars;
14258
14259 if (! named_section_first_declaration (name))
14260 {
14261 fprintf (asm_out_file, "\t.section\t%s\n", name);
14262 return;
14263 }
14264
14265 if (!(flags & SECTION_DEBUG))
14266 *f++ = 'a';
14267 if (flags & SECTION_WRITE)
14268 *f++ = 'w';
14269 if (flags & SECTION_CODE)
14270 *f++ = 'x';
14271 if (flags & SECTION_SMALL)
14272 *f++ = 's';
14273 if (flags & SECTION_MERGE)
14274 *f++ = 'M';
14275 if (flags & SECTION_STRINGS)
14276 *f++ = 'S';
14277 if (flags & SECTION_TLS)
14278 *f++ = 'T';
14279 *f = '\0';
14280
14281 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
14282
14283 if (!(flags & SECTION_NOTYPE))
14284 {
14285 const char *type;
14286
14287 if (flags & SECTION_BSS)
14288 type = "nobits";
14289 else
14290 type = "progbits";
14291
14292 fprintf (asm_out_file, ",%%%s", type);
14293
14294 if (flags & SECTION_ENTSIZE)
14295 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
14296 }
14297
14298 putc ('\n', asm_out_file);
14299 }
14300 #endif
14301
14302 #ifndef ARM_PE
14303 /* Symbols in the text segment can be accessed without indirecting via the
14304 constant pool; it may take an extra binary operation, but this is still
14305 faster than indirecting via memory. Don't do this when not optimizing,
14306 since we won't be calculating al of the offsets necessary to do this
14307 simplification. */
14308
14309 static void
14310 arm_encode_section_info (tree decl, rtx rtl, int first)
14311 {
14312 /* This doesn't work with AOF syntax, since the string table may be in
14313 a different AREA. */
14314 #ifndef AOF_ASSEMBLER
14315 if (optimize > 0 && TREE_CONSTANT (decl))
14316 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
14317 #endif
14318
14319 /* If we are referencing a function that is weak then encode a long call
14320 flag in the function name, otherwise if the function is static or
14321 or known to be defined in this file then encode a short call flag. */
14322 if (first && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
14323 {
14324 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_WEAK (decl))
14325 arm_encode_call_attribute (decl, LONG_CALL_FLAG_CHAR);
14326 else if (! TREE_PUBLIC (decl))
14327 arm_encode_call_attribute (decl, SHORT_CALL_FLAG_CHAR);
14328 }
14329 }
14330 #endif /* !ARM_PE */
14331
14332 static void
14333 arm_internal_label (FILE *stream, const char *prefix, unsigned long labelno)
14334 {
14335 if (arm_ccfsm_state == 3 && (unsigned) arm_target_label == labelno
14336 && !strcmp (prefix, "L"))
14337 {
14338 arm_ccfsm_state = 0;
14339 arm_target_insn = NULL;
14340 }
14341 default_internal_label (stream, prefix, labelno);
14342 }
14343
14344 /* Output code to add DELTA to the first argument, and then jump
14345 to FUNCTION. Used for C++ multiple inheritance. */
14346 static void
14347 arm_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
14348 HOST_WIDE_INT delta,
14349 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
14350 tree function)
14351 {
14352 static int thunk_label = 0;
14353 char label[256];
14354 int mi_delta = delta;
14355 const char *const mi_op = mi_delta < 0 ? "sub" : "add";
14356 int shift = 0;
14357 int this_regno = (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)
14358 ? 1 : 0);
14359 if (mi_delta < 0)
14360 mi_delta = - mi_delta;
14361 if (TARGET_THUMB)
14362 {
14363 int labelno = thunk_label++;
14364 ASM_GENERATE_INTERNAL_LABEL (label, "LTHUMBFUNC", labelno);
14365 fputs ("\tldr\tr12, ", file);
14366 assemble_name (file, label);
14367 fputc ('\n', file);
14368 }
14369 while (mi_delta != 0)
14370 {
14371 if ((mi_delta & (3 << shift)) == 0)
14372 shift += 2;
14373 else
14374 {
14375 asm_fprintf (file, "\t%s\t%r, %r, #%d\n",
14376 mi_op, this_regno, this_regno,
14377 mi_delta & (0xff << shift));
14378 mi_delta &= ~(0xff << shift);
14379 shift += 8;
14380 }
14381 }
14382 if (TARGET_THUMB)
14383 {
14384 fprintf (file, "\tbx\tr12\n");
14385 ASM_OUTPUT_ALIGN (file, 2);
14386 assemble_name (file, label);
14387 fputs (":\n", file);
14388 assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1);
14389 }
14390 else
14391 {
14392 fputs ("\tb\t", file);
14393 assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
14394 if (NEED_PLT_RELOC)
14395 fputs ("(PLT)", file);
14396 fputc ('\n', file);
14397 }
14398 }
14399
14400 int
14401 arm_emit_vector_const (FILE *file, rtx x)
14402 {
14403 int i;
14404 const char * pattern;
14405
14406 if (GET_CODE (x) != CONST_VECTOR)
14407 abort ();
14408
14409 switch (GET_MODE (x))
14410 {
14411 case V2SImode: pattern = "%08x"; break;
14412 case V4HImode: pattern = "%04x"; break;
14413 case V8QImode: pattern = "%02x"; break;
14414 default: abort ();
14415 }
14416
14417 fprintf (file, "0x");
14418 for (i = CONST_VECTOR_NUNITS (x); i--;)
14419 {
14420 rtx element;
14421
14422 element = CONST_VECTOR_ELT (x, i);
14423 fprintf (file, pattern, INTVAL (element));
14424 }
14425
14426 return 1;
14427 }
14428
14429 const char *
14430 arm_output_load_gr (rtx *operands)
14431 {
14432 rtx reg;
14433 rtx offset;
14434 rtx wcgr;
14435 rtx sum;
14436
14437 if (GET_CODE (operands [1]) != MEM
14438 || GET_CODE (sum = XEXP (operands [1], 0)) != PLUS
14439 || GET_CODE (reg = XEXP (sum, 0)) != REG
14440 || GET_CODE (offset = XEXP (sum, 1)) != CONST_INT
14441 || ((INTVAL (offset) < 1024) && (INTVAL (offset) > -1024)))
14442 return "wldrw%?\t%0, %1";
14443
14444 /* Fix up an out-of-range load of a GR register. */
14445 output_asm_insn ("str%?\t%0, [sp, #-4]!\t@ Start of GR load expansion", & reg);
14446 wcgr = operands[0];
14447 operands[0] = reg;
14448 output_asm_insn ("ldr%?\t%0, %1", operands);
14449
14450 operands[0] = wcgr;
14451 operands[1] = reg;
14452 output_asm_insn ("tmcr%?\t%0, %1", operands);
14453 output_asm_insn ("ldr%?\t%0, [sp], #4\t@ End of GR load expansion", & reg);
14454
14455 return "";
14456 }
14457
14458 static rtx
14459 arm_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
14460 int incoming ATTRIBUTE_UNUSED)
14461 {
14462 #if 0
14463 /* FIXME: The ARM backend has special code to handle structure
14464 returns, and will reserve its own hidden first argument. So
14465 if this macro is enabled a *second* hidden argument will be
14466 reserved, which will break binary compatibility with old
14467 toolchains and also thunk handling. One day this should be
14468 fixed. */
14469 return 0;
14470 #else
14471 /* Register in which address to store a structure value
14472 is passed to a function. */
14473 return gen_rtx_REG (Pmode, ARG_REGISTER (1));
14474 #endif
14475 }
14476
14477 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.
14478
14479 On the ARM, PRETEND_SIZE is set in order to have the prologue push the last
14480 named arg and all anonymous args onto the stack.
14481 XXX I know the prologue shouldn't be pushing registers, but it is faster
14482 that way. */
14483
14484 static void
14485 arm_setup_incoming_varargs (CUMULATIVE_ARGS *cum,
14486 enum machine_mode mode ATTRIBUTE_UNUSED,
14487 tree type ATTRIBUTE_UNUSED,
14488 int *pretend_size,
14489 int second_time ATTRIBUTE_UNUSED)
14490 {
14491 cfun->machine->uses_anonymous_args = 1;
14492 if (cum->nregs < NUM_ARG_REGS)
14493 *pretend_size = (NUM_ARG_REGS - cum->nregs) * UNITS_PER_WORD;
14494 }
14495
14496 /* Return nonzero if the CONSUMER instruction (a store) does not need
14497 PRODUCER's value to calculate the address. */
14498
14499 int
14500 arm_no_early_store_addr_dep (rtx producer, rtx consumer)
14501 {
14502 rtx value = PATTERN (producer);
14503 rtx addr = PATTERN (consumer);
14504
14505 if (GET_CODE (value) == COND_EXEC)
14506 value = COND_EXEC_CODE (value);
14507 if (GET_CODE (value) == PARALLEL)
14508 value = XVECEXP (value, 0, 0);
14509 value = XEXP (value, 0);
14510 if (GET_CODE (addr) == COND_EXEC)
14511 addr = COND_EXEC_CODE (addr);
14512 if (GET_CODE (addr) == PARALLEL)
14513 addr = XVECEXP (addr, 0, 0);
14514 addr = XEXP (addr, 0);
14515
14516 return !reg_overlap_mentioned_p (value, addr);
14517 }
14518
14519 /* Return nonzero if the CONSUMER instruction (an ALU op) does not
14520 have an early register shift value or amount dependency on the
14521 result of PRODUCER. */
14522
14523 int
14524 arm_no_early_alu_shift_dep (rtx producer, rtx consumer)
14525 {
14526 rtx value = PATTERN (producer);
14527 rtx op = PATTERN (consumer);
14528 rtx early_op;
14529
14530 if (GET_CODE (value) == COND_EXEC)
14531 value = COND_EXEC_CODE (value);
14532 if (GET_CODE (value) == PARALLEL)
14533 value = XVECEXP (value, 0, 0);
14534 value = XEXP (value, 0);
14535 if (GET_CODE (op) == COND_EXEC)
14536 op = COND_EXEC_CODE (op);
14537 if (GET_CODE (op) == PARALLEL)
14538 op = XVECEXP (op, 0, 0);
14539 op = XEXP (op, 1);
14540
14541 early_op = XEXP (op, 0);
14542 /* This is either an actual independent shift, or a shift applied to
14543 the first operand of another operation. We want the whole shift
14544 operation. */
14545 if (GET_CODE (early_op) == REG)
14546 early_op = op;
14547
14548 return !reg_overlap_mentioned_p (value, early_op);
14549 }
14550
14551 /* Return nonzero if the CONSUMER instruction (an ALU op) does not
14552 have an early register shift value dependency on the result of
14553 PRODUCER. */
14554
14555 int
14556 arm_no_early_alu_shift_value_dep (rtx producer, rtx consumer)
14557 {
14558 rtx value = PATTERN (producer);
14559 rtx op = PATTERN (consumer);
14560 rtx early_op;
14561
14562 if (GET_CODE (value) == COND_EXEC)
14563 value = COND_EXEC_CODE (value);
14564 if (GET_CODE (value) == PARALLEL)
14565 value = XVECEXP (value, 0, 0);
14566 value = XEXP (value, 0);
14567 if (GET_CODE (op) == COND_EXEC)
14568 op = COND_EXEC_CODE (op);
14569 if (GET_CODE (op) == PARALLEL)
14570 op = XVECEXP (op, 0, 0);
14571 op = XEXP (op, 1);
14572
14573 early_op = XEXP (op, 0);
14574
14575 /* This is either an actual independent shift, or a shift applied to
14576 the first operand of another operation. We want the value being
14577 shifted, in either case. */
14578 if (GET_CODE (early_op) != REG)
14579 early_op = XEXP (early_op, 0);
14580
14581 return !reg_overlap_mentioned_p (value, early_op);
14582 }
14583
14584 /* Return nonzero if the CONSUMER (a mul or mac op) does not
14585 have an early register mult dependency on the result of
14586 PRODUCER. */
14587
14588 int
14589 arm_no_early_mul_dep (rtx producer, rtx consumer)
14590 {
14591 rtx value = PATTERN (producer);
14592 rtx op = PATTERN (consumer);
14593
14594 if (GET_CODE (value) == COND_EXEC)
14595 value = COND_EXEC_CODE (value);
14596 if (GET_CODE (value) == PARALLEL)
14597 value = XVECEXP (value, 0, 0);
14598 value = XEXP (value, 0);
14599 if (GET_CODE (op) == COND_EXEC)
14600 op = COND_EXEC_CODE (op);
14601 if (GET_CODE (op) == PARALLEL)
14602 op = XVECEXP (op, 0, 0);
14603 op = XEXP (op, 1);
14604
14605 return (GET_CODE (op) == PLUS
14606 && !reg_overlap_mentioned_p (value, XEXP (op, 0)));
14607 }
14608
14609
14610 /* We can't rely on the caller doing the proper promotion when
14611 using APCS or ATPCS. */
14612
14613 static bool
14614 arm_promote_prototypes (tree t ATTRIBUTE_UNUSED)
14615 {
14616 return !TARGET_AAPCS_BASED;
14617 }
14618
14619
14620 /* AAPCS based ABIs use short enums by default. */
14621
14622 static bool
14623 arm_default_short_enums (void)
14624 {
14625 return TARGET_AAPCS_BASED;
14626 }
14627
14628
14629 /* AAPCS requires that anonymous bitfields affect structure alignment. */
14630
14631 static bool
14632 arm_align_anon_bitfield (void)
14633 {
14634 return TARGET_AAPCS_BASED;
14635 }
14636
14637
14638 /* The generic C++ ABI says 64-bit (long long). The EABI says 32-bit. */
14639
14640 static tree
14641 arm_cxx_guard_type (void)
14642 {
14643 return TARGET_AAPCS_BASED ? integer_type_node : long_long_integer_type_node;
14644 }
14645
14646
14647 /* The EABI says test the least significan bit of a guard variable. */
14648
14649 static bool
14650 arm_cxx_guard_mask_bit (void)
14651 {
14652 return TARGET_AAPCS_BASED;
14653 }
14654
14655
14656 /* The EABI specifies that all array cookies are 8 bytes long. */
14657
14658 static tree
14659 arm_get_cookie_size (tree type)
14660 {
14661 tree size;
14662
14663 if (!TARGET_AAPCS_BASED)
14664 return default_cxx_get_cookie_size (type);
14665
14666 size = build_int_2 (8, 0);
14667 TREE_TYPE (size) = sizetype;
14668 return size;
14669 }
14670
14671
14672 /* The EABI says that array cookies should also contain the element size. */
14673
14674 static bool
14675 arm_cookie_has_size (void)
14676 {
14677 return TARGET_AAPCS_BASED;
14678 }
14679
14680
14681 /* The EABI says constructors and destructors should return a pointer to
14682 the object constructed/destroyed. */
14683
14684 static bool
14685 arm_cxx_cdtor_returns_this (void)
14686 {
14687 return TARGET_AAPCS_BASED;
14688 }
14689
14690
14691 void
14692 arm_set_return_address (rtx source, rtx scratch)
14693 {
14694 arm_stack_offsets *offsets;
14695 HOST_WIDE_INT delta;
14696 rtx addr;
14697 unsigned long saved_regs;
14698
14699 saved_regs = arm_compute_save_reg_mask ();
14700
14701 if ((saved_regs & (1 << LR_REGNUM)) == 0)
14702 emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source);
14703 else
14704 {
14705 if (frame_pointer_needed)
14706 addr = plus_constant(hard_frame_pointer_rtx, -4);
14707 else
14708 {
14709 /* LR will be the first saved register. */
14710 offsets = arm_get_frame_offsets ();
14711 delta = offsets->outgoing_args - (offsets->frame + 4);
14712
14713
14714 if (delta >= 4096)
14715 {
14716 emit_insn (gen_addsi3 (scratch, stack_pointer_rtx,
14717 GEN_INT (delta & ~4095)));
14718 addr = scratch;
14719 delta &= 4095;
14720 }
14721 else
14722 addr = stack_pointer_rtx;
14723
14724 addr = plus_constant (addr, delta);
14725 }
14726 emit_move_insn (gen_rtx_MEM (Pmode, addr), source);
14727 }
14728 }
14729
14730
14731 void
14732 thumb_set_return_address (rtx source, rtx scratch)
14733 {
14734 arm_stack_offsets *offsets;
14735 bool lr_saved;
14736 HOST_WIDE_INT delta;
14737 int reg;
14738 rtx addr;
14739
14740 emit_insn (gen_rtx_USE (VOIDmode, source));
14741 lr_saved = FALSE;
14742 for (reg = 0; reg <= LAST_LO_REGNUM; reg++)
14743 {
14744 if (THUMB_REG_PUSHED_P (reg))
14745 {
14746 lr_saved = TRUE;
14747 break;
14748 }
14749 }
14750 lr_saved |= thumb_force_lr_save ();
14751
14752 if (lr_saved)
14753 {
14754 offsets = arm_get_frame_offsets ();
14755
14756 /* Find the saved regs. */
14757 if (frame_pointer_needed)
14758 {
14759 delta = offsets->soft_frame - offsets->saved_args;
14760 reg = THUMB_HARD_FRAME_POINTER_REGNUM;
14761 }
14762 else
14763 {
14764 delta = offsets->outgoing_args - offsets->saved_args;
14765 reg = SP_REGNUM;
14766 }
14767 /* Allow for the stack frame. */
14768 if (TARGET_BACKTRACE)
14769 delta -= 16;
14770 /* The link register is always the first saved register. */
14771 delta -= 4;
14772
14773 /* Construct the address. */
14774 addr = gen_rtx_REG (SImode, reg);
14775 if ((reg != SP_REGNUM && delta >= 128)
14776 || delta >= 1024)
14777 {
14778 emit_insn (gen_movsi (scratch, GEN_INT (delta)));
14779 emit_insn (gen_addsi3 (scratch, scratch, stack_pointer_rtx));
14780 addr = scratch;
14781 }
14782 else
14783 addr = plus_constant (addr, delta);
14784
14785 emit_move_insn (gen_rtx_MEM (Pmode, addr), source);
14786 }
14787 else
14788 emit_move_insn (gen_rtx_REG (Pmode, LR_REGNUM), source);
14789 }
14790
This page took 0.687596 seconds and 5 git commands to generate.