1 /* Output routines for GCC for ARM.
2 Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
3 Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
4 and Martin Simmons (@harleqn.co.uk).
5 More major hacks by Richard Earnshaw (rearnsha@arm.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-flags.h"
34 #include "insn-attr.h"
42 /* The maximum number of insns skipped which will be conditionalised if
44 static int max_insns_skipped = 5;
46 extern FILE * asm_out_file;
47 /* Some function declarations. */
49 static HOST_WIDE_INT int_log2 PROTO ((HOST_WIDE_INT));
50 static char * output_multi_immediate PROTO ((rtx *, char *, char *, int,
52 static int arm_gen_constant PROTO ((enum rtx_code, enum machine_mode,
53 HOST_WIDE_INT, rtx, rtx, int, int));
54 static int arm_naked_function_p PROTO ((tree));
55 static void init_fpa_table PROTO ((void));
56 static enum machine_mode select_dominance_cc_mode PROTO ((rtx, rtx,
58 static HOST_WIDE_INT add_constant PROTO ((rtx, enum machine_mode, int *));
59 static void dump_table PROTO ((rtx));
60 static int fixit PROTO ((rtx, enum machine_mode, int));
61 static rtx find_barrier PROTO ((rtx, int));
62 static int broken_move PROTO ((rtx));
63 static char * fp_const_from_val PROTO ((REAL_VALUE_TYPE *));
64 static int eliminate_lr2ip PROTO ((rtx *));
65 static char * shift_op PROTO ((rtx, HOST_WIDE_INT *));
66 static int pattern_really_clobbers_lr PROTO ((rtx));
67 static int function_really_clobbers_lr PROTO ((rtx));
68 static void emit_multi_reg_push PROTO ((int));
69 static void emit_sfm PROTO ((int, int));
70 static enum arm_cond_code get_arm_condition_code PROTO ((rtx));
71 static int const_ok_for_op RTX_CODE_PROTO ((HOST_WIDE_INT, Rcode));
73 /* True if we are currently building a constant table. */
74 int making_const_table;
76 /* Define the information needed to generate branch insns. This is
77 stored from the compare operation. */
78 rtx arm_compare_op0, arm_compare_op1;
80 /* What type of floating point are we tuning for? */
81 enum floating_point_type arm_fpu;
83 /* What type of floating point instructions are available? */
84 enum floating_point_type arm_fpu_arch;
86 /* What program mode is the cpu running in? 26-bit mode or 32-bit mode */
87 enum prog_mode_type arm_prgmode;
89 /* Set by the -mfp=... option */
90 const char * target_fp_name = NULL;
92 /* Used to parse -mstructure_size_boundary command line option. */
93 const char * structure_size_string = NULL;
94 int arm_structure_size_boundary = 32; /* Used to be 8 */
96 /* Bit values used to identify processor capabilities. */
97 #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */
98 #define FL_FAST_MULT (1 << 1) /* Fast multiply */
99 #define FL_MODE26 (1 << 2) /* 26-bit mode support */
100 #define FL_MODE32 (1 << 3) /* 32-bit mode support */
101 #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */
102 #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */
103 #define FL_THUMB (1 << 6) /* Thumb aware */
104 #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */
105 #define FL_STRONG (1 << 8) /* StrongARM */
107 /* The bits in this mask specify which instructions we are allowed to generate. */
108 static int insn_flags = 0;
109 /* The bits in this mask specify which instruction scheduling options should
110 be used. Note - there is an overlap with the FL_FAST_MULT. For some
111 hardware we want to be able to generate the multiply instructions, but to
112 tune as if they were not present in the architecture. */
113 static int tune_flags = 0;
115 /* The following are used in the arm.md file as equivalents to bits
116 in the above two flag variables. */
118 /* Nonzero if this is an "M" variant of the processor. */
119 int arm_fast_multiply = 0;
121 /* Nonzero if this chip supports the ARM Architecture 4 extensions */
124 /* Nonzero if this chip supports the ARM Architecture 5 extensions */
127 /* Nonzero if this chip can benefit from load scheduling. */
128 int arm_ld_sched = 0;
130 /* Nonzero if this chip is a StrongARM. */
131 int arm_is_strong = 0;
133 /* Nonzero if this chip is a an ARM6 or an ARM7. */
134 int arm_is_6_or_7 = 0;
136 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
137 must report the mode of the memory reference from PRINT_OPERAND to
138 PRINT_OPERAND_ADDRESS. */
139 enum machine_mode output_memory_reference_mode;
141 /* Nonzero if the prologue must setup `fp'. */
142 int current_function_anonymous_args;
144 /* The register number to be used for the PIC offset register. */
145 const char * arm_pic_register_string = NULL;
146 int arm_pic_register = 9;
148 /* Set to one if we think that lr is only saved because of subroutine calls,
149 but all of these can be `put after' return insns */
150 int lr_save_eliminated;
152 /* Set to 1 when a return insn is output, this means that the epilogue
154 static int return_used_this_function;
156 /* Set to 1 after arm_reorg has started. Reset to start at the start of
157 the next function. */
158 static int after_arm_reorg = 0;
160 /* The maximum number of insns to be used when loading a constant. */
161 static int arm_constant_limit = 3;
163 /* For an explanation of these variables, see final_prescan_insn below. */
165 enum arm_cond_code arm_current_cc;
167 int arm_target_label;
169 /* The condition codes of the ARM, and the inverse function. */
170 char * arm_condition_codes[] =
172 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
173 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
176 static enum arm_cond_code get_arm_condition_code ();
178 #define streq(string1, string2) (strcmp (string1, string2) == 0)
180 /* Initialization code */
188 /* Not all of these give usefully different compilation alternatives,
189 but there is no simple way of generalizing them. */
190 static struct processors all_cores[] =
194 {"arm2", FL_CO_PROC | FL_MODE26 },
195 {"arm250", FL_CO_PROC | FL_MODE26 },
196 {"arm3", FL_CO_PROC | FL_MODE26 },
197 {"arm6", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
198 {"arm60", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
199 {"arm600", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
200 {"arm610", FL_MODE26 | FL_MODE32 },
201 {"arm620", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
202 {"arm7", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
203 {"arm7m", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, /* arm7m doesn't exist on its own, */
204 {"arm7d", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, /* but only with D, (and I), */
205 {"arm7dm", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, /* but those don't alter the code, */
206 {"arm7di", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, /* so arm7m is sometimes used. */
207 {"arm7dmi", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT },
208 {"arm70", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
209 {"arm700", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
210 {"arm700i", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
211 {"arm710", FL_MODE26 | FL_MODE32 },
212 {"arm710c", FL_MODE26 | FL_MODE32 },
213 {"arm7100", FL_MODE26 | FL_MODE32 },
214 {"arm7500", FL_MODE26 | FL_MODE32 },
215 {"arm7500fe", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, /* Doesn't really have an external co-proc, but does have embedded fpu. */
216 {"arm7tdmi", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB },
217 {"arm8", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED },
218 {"arm810", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED },
219 {"arm9", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED },
220 {"arm920", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED },
221 {"arm920t", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED },
222 {"arm9tdmi", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED },
223 {"strongarm", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG },
224 {"strongarm110", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG },
225 {"strongarm1100", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG },
230 static struct processors all_architectures[] =
232 /* ARM Architectures */
234 { "armv2", FL_CO_PROC | FL_MODE26 },
235 { "armv2a", FL_CO_PROC | FL_MODE26 },
236 { "armv3", FL_CO_PROC | FL_MODE26 | FL_MODE32 },
237 { "armv3m", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT },
238 { "armv4", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 },
239 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
240 implementations that support it, so we will leave it out for now. */
241 { "armv4t", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB },
242 { "armv5", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_ARCH5 },
246 /* This is a magic stucture. The 'string' field is magically filled in
247 with a pointer to the value specified by the user on the command line
248 assuming that the user has specified such a value. */
250 struct arm_cpu_select arm_select[] =
252 /* string name processors */
253 { NULL, "-mcpu=", all_cores },
254 { NULL, "-march=", all_architectures },
255 { NULL, "-mtune=", all_cores }
258 /* Return the number of bits set in value' */
263 unsigned int count = 0;
267 value &= ~(value & - value);
274 /* Fix up any incompatible options that the user has specified.
275 This has now turned into a maze. */
277 arm_override_options ()
281 /* Set up the flags based on the cpu/architecture selected by the user. */
282 for (i = sizeof (arm_select) / sizeof (arm_select[0]); i--;)
284 struct arm_cpu_select * ptr = arm_select + i;
286 if (ptr->string != NULL && ptr->string[0] != '\0')
288 const struct processors * sel;
290 for (sel = ptr->processors; sel->name != NULL; sel ++)
291 if (streq (ptr->string, sel->name))
294 tune_flags = sel->flags;
297 /* If we have been given an architecture and a processor
298 make sure that they are compatible. We only generate
299 a warning though, and we prefer the CPU over the
301 if (insn_flags != 0 && (insn_flags ^ sel->flags))
302 warning ("switch -mcpu=%s conflicts with -march= switch",
305 insn_flags = sel->flags;
311 if (sel->name == NULL)
312 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
316 /* If the user did not specify a processor, choose one for them. */
319 struct processors * sel;
321 static struct cpu_default
328 { TARGET_CPU_arm2, "arm2" },
329 { TARGET_CPU_arm6, "arm6" },
330 { TARGET_CPU_arm610, "arm610" },
331 { TARGET_CPU_arm710, "arm710" },
332 { TARGET_CPU_arm7m, "arm7m" },
333 { TARGET_CPU_arm7500fe, "arm7500fe" },
334 { TARGET_CPU_arm7tdmi, "arm7tdmi" },
335 { TARGET_CPU_arm8, "arm8" },
336 { TARGET_CPU_arm810, "arm810" },
337 { TARGET_CPU_arm9, "arm9" },
338 { TARGET_CPU_strongarm, "strongarm" },
339 { TARGET_CPU_generic, "arm" },
342 struct cpu_default * def;
344 /* Find the default. */
345 for (def = cpu_defaults; def->name; def ++)
346 if (def->cpu == TARGET_CPU_DEFAULT)
349 /* Make sure we found the default CPU. */
350 if (def->name == NULL)
353 /* Find the default CPU's flags. */
354 for (sel = all_cores; sel->name != NULL; sel ++)
355 if (streq (def->name, sel->name))
358 if (sel->name == NULL)
361 insn_flags = sel->flags;
363 /* Now check to see if the user has specified some command line
364 switch that require certain abilities from the cpu. */
367 if (TARGET_INTERWORK)
369 sought |= (FL_THUMB | FL_MODE32);
371 /* Force apcs-32 to be used for interworking. */
372 target_flags |= ARM_FLAG_APCS_32;
374 /* There are no ARM processor that supports both APCS-26 and
375 interworking. Therefore we force FL_MODE26 to be removed
376 from insn_flags here (if it was set), so that the search
377 below will always be able to find a compatible processor. */
378 insn_flags &= ~ FL_MODE26;
381 if (! TARGET_APCS_32)
384 if (sought != 0 && ((sought & insn_flags) != sought))
386 /* Try to locate a CPU type that supports all of the abilities
387 of the default CPU, plus the extra abilities requested by
389 for (sel = all_cores; sel->name != NULL; sel ++)
390 if ((sel->flags & sought) == (sought | insn_flags))
393 if (sel->name == NULL)
395 unsigned int current_bit_count = 0;
396 struct processors * best_fit = NULL;
398 /* Ideally we would like to issue an error message here
399 saying that it was not possible to find a CPU compatible
400 with the default CPU, but which also supports the command
401 line options specified by the programmer, and so they
402 ought to use the -mcpu=<name> command line option to
403 override the default CPU type.
405 Unfortunately this does not work with multilibing. We
406 need to be able to support multilibs for -mapcs-26 and for
407 -mthumb-interwork and there is no CPU that can support both
408 options. Instead if we cannot find a cpu that has both the
409 characteristics of the default cpu and the given command line
410 options we scan the array again looking for a best match. */
411 for (sel = all_cores; sel->name != NULL; sel ++)
412 if ((sel->flags & sought) == sought)
416 count = bit_count (sel->flags & insn_flags);
418 if (count >= current_bit_count)
421 current_bit_count = count;
425 if (best_fit == NULL)
431 insn_flags = sel->flags;
435 /* If tuning has not been specified, tune for whichever processor or
436 architecture has been selected. */
438 tune_flags = insn_flags;
440 /* Make sure that the processor choice does not conflict with any of the
441 other command line choices. */
442 if (TARGET_APCS_32 && !(insn_flags & FL_MODE32))
444 /* If APCS-32 was not the default then it must have been set by the
445 user, so issue a warning message. If the user has specified
446 "-mapcs-32 -mcpu=arm2" then we loose here. */
447 if ((TARGET_DEFAULT & ARM_FLAG_APCS_32) == 0)
448 warning ("target CPU does not support APCS-32" );
449 target_flags &= ~ ARM_FLAG_APCS_32;
451 else if (! TARGET_APCS_32 && !(insn_flags & FL_MODE26))
453 warning ("target CPU does not support APCS-26" );
454 target_flags |= ARM_FLAG_APCS_32;
457 if (TARGET_INTERWORK && !(insn_flags & FL_THUMB))
459 warning ("target CPU does not support interworking" );
460 target_flags &= ~ARM_FLAG_INTERWORK;
463 /* If interworking is enabled then APCS-32 must be selected as well. */
464 if (TARGET_INTERWORK)
466 if (! TARGET_APCS_32)
467 warning ("interworking forces APCS-32 to be used" );
468 target_flags |= ARM_FLAG_APCS_32;
471 if (TARGET_APCS_STACK && ! TARGET_APCS)
473 warning ("-mapcs-stack-check incompatible with -mno-apcs-frame");
474 target_flags |= ARM_FLAG_APCS_FRAME;
477 if (TARGET_POKE_FUNCTION_NAME)
478 target_flags |= ARM_FLAG_APCS_FRAME;
480 if (TARGET_APCS_REENT && flag_pic)
481 fatal ("-fpic and -mapcs-reent are incompatible");
483 if (TARGET_APCS_REENT)
484 warning ("APCS reentrant code not supported. Ignored");
486 if (write_symbols != NO_DEBUG && flag_omit_frame_pointer)
487 warning ("-g with -fomit-frame-pointer may not give sensible debugging");
489 /* If stack checking is disabled, we can use r10 as the PIC register,
490 which keeps r9 available. */
491 if (flag_pic && ! TARGET_APCS_STACK)
492 arm_pic_register = 10;
494 if (TARGET_APCS_FLOAT)
495 warning ("Passing floating point arguments in fp regs not yet supported");
497 /* Initialise boolean versions of the flags, for use in the arm.md file. */
498 arm_fast_multiply = insn_flags & FL_FAST_MULT;
499 arm_arch4 = insn_flags & FL_ARCH4;
500 arm_arch5 = insn_flags & FL_ARCH5;
502 arm_ld_sched = tune_flags & FL_LDSCHED;
503 arm_is_strong = tune_flags & FL_STRONG;
504 arm_is_6_or_7 = ((tune_flags & (FL_MODE26 | FL_MODE32))
505 && !(tune_flags & FL_ARCH4));
507 /* Default value for floating point code... if no co-processor
508 bus, then schedule for emulated floating point. Otherwise,
509 assume the user has an FPA.
510 Note: this does not prevent use of floating point instructions,
511 -msoft-float does that. */
512 arm_fpu = (tune_flags & FL_CO_PROC) ? FP_HARD : FP_SOFT3;
516 if (streq (target_fp_name, "2"))
517 arm_fpu_arch = FP_SOFT2;
518 else if (streq (target_fp_name, "3"))
519 arm_fpu_arch = FP_SOFT3;
521 fatal ("Invalid floating point emulation option: -mfpe-%s",
525 arm_fpu_arch = FP_DEFAULT;
527 if (TARGET_FPE && arm_fpu != FP_HARD)
530 /* For arm2/3 there is no need to do any scheduling if there is only
531 a floating point emulator, or we are doing software floating-point. */
532 if ((TARGET_SOFT_FLOAT || arm_fpu != FP_HARD)
533 && (tune_flags & FL_MODE32) == 0)
534 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
536 arm_prog_mode = TARGET_APCS_32 ? PROG_MODE_PROG32 : PROG_MODE_PROG26;
538 if (structure_size_string != NULL)
540 int size = strtol (structure_size_string, NULL, 0);
542 if (size == 8 || size == 32)
543 arm_structure_size_boundary = size;
545 warning ("Structure size boundary can only be set to 8 or 32");
548 if (arm_pic_register_string != NULL)
553 warning ("-mpic-register= is useless without -fpic");
555 pic_register = decode_reg_name (arm_pic_register_string);
557 /* Prevent the user from choosing an obviously stupid PIC register. */
558 if (pic_register < 0 || call_used_regs[pic_register]
559 || pic_register == HARD_FRAME_POINTER_REGNUM
560 || pic_register == STACK_POINTER_REGNUM
561 || pic_register >= PC_REGNUM)
562 error ("Unable to use '%s' for PIC register", arm_pic_register_string);
564 arm_pic_register = pic_register;
567 /* If optimizing for space, don't synthesize constants.
568 For processors with load scheduling, it never costs more than 2 cycles
569 to load a constant, and the load scheduler may well reduce that to 1. */
570 if (optimize_size || (tune_flags & FL_LDSCHED))
571 arm_constant_limit = 1;
573 /* If optimizing for size, bump the number of instructions that we
574 are prepared to conditionally execute (even on a StrongARM).
575 Otherwise for the StrongARM, which has early execution of branches,
576 a sequence that is worth skipping is shorter. */
578 max_insns_skipped = 6;
579 else if (arm_is_strong)
580 max_insns_skipped = 3;
583 /* Return 1 if it is possible to return using a single instruction */
586 use_return_insn (iscond)
591 if (!reload_completed
592 || current_function_pretend_args_size
593 || current_function_anonymous_args
594 || ((get_frame_size () + current_function_outgoing_args_size != 0)
595 && !(TARGET_APCS && frame_pointer_needed)))
598 /* Can't be done if interworking with Thumb, and any registers have been
599 stacked. Similarly, on StrongARM, conditional returns are expensive
600 if they aren't taken and registers have been stacked. */
601 if (iscond && arm_is_strong && frame_pointer_needed)
603 if ((iscond && arm_is_strong)
606 for (regno = 0; regno < 16; regno++)
607 if (regs_ever_live[regno] && ! call_used_regs[regno])
610 if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
614 /* Can't be done if any of the FPU regs are pushed, since this also
616 for (regno = 16; regno < 24; regno++)
617 if (regs_ever_live[regno] && ! call_used_regs[regno])
620 /* If a function is naked, don't use the "return" insn. */
621 if (arm_naked_function_p (current_function_decl))
627 /* Return TRUE if int I is a valid immediate ARM constant. */
633 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT)0xFF;
635 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
636 be all zero, or all one. */
637 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
638 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
639 != ((~(unsigned HOST_WIDE_INT) 0)
640 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
643 /* Fast return for 0 and powers of 2 */
644 if ((i & (i - 1)) == 0)
649 if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)
652 (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)
653 >> (32 - 2)) | ~((unsigned HOST_WIDE_INT) 0xffffffff);
654 } while (mask != ~(unsigned HOST_WIDE_INT) 0xFF);
659 /* Return true if I is a valid constant for the operation CODE. */
661 const_ok_for_op (i, code)
665 if (const_ok_for_arm (i))
671 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
673 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
679 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
686 /* Emit a sequence of insns to handle a large constant.
687 CODE is the code of the operation required, it can be any of SET, PLUS,
688 IOR, AND, XOR, MINUS;
689 MODE is the mode in which the operation is being performed;
690 VAL is the integer to operate on;
691 SOURCE is the other operand (a register, or a null-pointer for SET);
692 SUBTARGETS means it is safe to create scratch registers if that will
693 either produce a simpler sequence, or we will want to cse the values.
694 Return value is the number of insns emitted. */
697 arm_split_constant (code, mode, val, target, source, subtargets)
699 enum machine_mode mode;
705 if (subtargets || code == SET
706 || (GET_CODE (target) == REG && GET_CODE (source) == REG
707 && REGNO (target) != REGNO (source)))
709 /* After arm_reorg has been called, we can't fix up expensive
710 constants by pushing them into memory so we must synthesise
711 them in-line, regardless of the cost. This is only likely to
712 be more costly on chips that have load delay slots and we are
713 compiling without running the scheduler (so no splitting
714 occurred before the final instruction emission).
716 Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c
718 if (! after_arm_reorg
719 && (arm_gen_constant (code, mode, val, target, source, 1, 0)
720 > arm_constant_limit + (code != SET)))
724 /* Currently SET is the only monadic value for CODE, all
725 the rest are diadic. */
726 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val)));
731 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
733 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val)));
734 /* For MINUS, the value is subtracted from, since we never
735 have subtraction of a constant. */
737 emit_insn (gen_rtx_SET (VOIDmode, target,
738 gen_rtx (code, mode, temp, source)));
740 emit_insn (gen_rtx_SET (VOIDmode, target,
741 gen_rtx (code, mode, source, temp)));
747 return arm_gen_constant (code, mode, val, target, source, subtargets, 1);
750 /* As above, but extra parameter GENERATE which, if clear, suppresses
753 arm_gen_constant (code, mode, val, target, source, subtargets, generate)
755 enum machine_mode mode;
764 int can_negate_initial = 0;
767 int num_bits_set = 0;
768 int set_sign_bit_copies = 0;
769 int clear_sign_bit_copies = 0;
770 int clear_zero_bit_copies = 0;
771 int set_zero_bit_copies = 0;
773 unsigned HOST_WIDE_INT temp1, temp2;
774 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
776 /* find out which operations are safe for a given CODE. Also do a quick
777 check for degenerate cases; these can occur when DImode operations
789 can_negate_initial = 1;
793 if (remainder == 0xffffffff)
796 emit_insn (gen_rtx_SET (VOIDmode, target,
797 GEN_INT (ARM_SIGN_EXTEND (val))));
802 if (reload_completed && rtx_equal_p (target, source))
805 emit_insn (gen_rtx_SET (VOIDmode, target, source));
814 emit_insn (gen_rtx_SET (VOIDmode, target, const0_rtx));
817 if (remainder == 0xffffffff)
819 if (reload_completed && rtx_equal_p (target, source))
822 emit_insn (gen_rtx_SET (VOIDmode, target, source));
831 if (reload_completed && rtx_equal_p (target, source))
834 emit_insn (gen_rtx_SET (VOIDmode, target, source));
837 if (remainder == 0xffffffff)
840 emit_insn (gen_rtx_SET (VOIDmode, target,
841 gen_rtx_NOT (mode, source)));
845 /* We don't know how to handle this yet below. */
849 /* We treat MINUS as (val - source), since (source - val) is always
850 passed as (source + (-val)). */
854 emit_insn (gen_rtx_SET (VOIDmode, target,
855 gen_rtx_NEG (mode, source)));
858 if (const_ok_for_arm (val))
861 emit_insn (gen_rtx_SET (VOIDmode, target,
862 gen_rtx_MINUS (mode, GEN_INT (val),
874 /* If we can do it in one insn get out quickly */
875 if (const_ok_for_arm (val)
876 || (can_negate_initial && const_ok_for_arm (-val))
877 || (can_invert && const_ok_for_arm (~val)))
880 emit_insn (gen_rtx_SET (VOIDmode, target,
881 (source ? gen_rtx (code, mode, source,
888 /* Calculate a few attributes that may be useful for specific
891 for (i = 31; i >= 0; i--)
893 if ((remainder & (1 << i)) == 0)
894 clear_sign_bit_copies++;
899 for (i = 31; i >= 0; i--)
901 if ((remainder & (1 << i)) != 0)
902 set_sign_bit_copies++;
907 for (i = 0; i <= 31; i++)
909 if ((remainder & (1 << i)) == 0)
910 clear_zero_bit_copies++;
915 for (i = 0; i <= 31; i++)
917 if ((remainder & (1 << i)) != 0)
918 set_zero_bit_copies++;
926 /* See if we can do this by sign_extending a constant that is known
927 to be negative. This is a good, way of doing it, since the shift
928 may well merge into a subsequent insn. */
929 if (set_sign_bit_copies > 1)
932 (temp1 = ARM_SIGN_EXTEND (remainder
933 << (set_sign_bit_copies - 1))))
937 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
938 emit_insn (gen_rtx_SET (VOIDmode, new_src,
940 emit_insn (gen_ashrsi3 (target, new_src,
941 GEN_INT (set_sign_bit_copies - 1)));
945 /* For an inverted constant, we will need to set the low bits,
946 these will be shifted out of harm's way. */
947 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
948 if (const_ok_for_arm (~temp1))
952 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
953 emit_insn (gen_rtx_SET (VOIDmode, new_src,
955 emit_insn (gen_ashrsi3 (target, new_src,
956 GEN_INT (set_sign_bit_copies - 1)));
962 /* See if we can generate this by setting the bottom (or the top)
963 16 bits, and then shifting these into the other half of the
964 word. We only look for the simplest cases, to do more would cost
965 too much. Be careful, however, not to generate this when the
966 alternative would take fewer insns. */
967 if (val & 0xffff0000)
969 temp1 = remainder & 0xffff0000;
970 temp2 = remainder & 0x0000ffff;
972 /* Overlaps outside this range are best done using other methods. */
973 for (i = 9; i < 24; i++)
975 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
976 && ! const_ok_for_arm (temp2))
978 rtx new_src = (subtargets
979 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
981 insns = arm_gen_constant (code, mode, temp2, new_src,
982 source, subtargets, generate);
985 emit_insn (gen_rtx_SET
988 gen_rtx_ASHIFT (mode, source,
995 /* Don't duplicate cases already considered. */
996 for (i = 17; i < 24; i++)
998 if (((temp1 | (temp1 >> i)) == remainder)
999 && ! const_ok_for_arm (temp1))
1001 rtx new_src = (subtargets
1002 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
1004 insns = arm_gen_constant (code, mode, temp1, new_src,
1005 source, subtargets, generate);
1009 (gen_rtx_SET (VOIDmode, target,
1012 gen_rtx_LSHIFTRT (mode, source,
1023 /* If we have IOR or XOR, and the constant can be loaded in a
1024 single instruction, and we can find a temporary to put it in,
1025 then this can be done in two instructions instead of 3-4. */
1027 /* TARGET can't be NULL if SUBTARGETS is 0 */
1028 || (reload_completed && ! reg_mentioned_p (target, source)))
1030 if (const_ok_for_arm (ARM_SIGN_EXTEND (~ val)))
1034 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1036 emit_insn (gen_rtx_SET (VOIDmode, sub, GEN_INT (val)));
1037 emit_insn (gen_rtx_SET (VOIDmode, target,
1038 gen_rtx (code, mode, source, sub)));
1047 if (set_sign_bit_copies > 8
1048 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
1052 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1053 rtx shift = GEN_INT (set_sign_bit_copies);
1055 emit_insn (gen_rtx_SET (VOIDmode, sub,
1057 gen_rtx_ASHIFT (mode,
1060 emit_insn (gen_rtx_SET (VOIDmode, target,
1062 gen_rtx_LSHIFTRT (mode, sub,
1068 if (set_zero_bit_copies > 8
1069 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
1073 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1074 rtx shift = GEN_INT (set_zero_bit_copies);
1076 emit_insn (gen_rtx_SET (VOIDmode, sub,
1078 gen_rtx_LSHIFTRT (mode,
1081 emit_insn (gen_rtx_SET (VOIDmode, target,
1083 gen_rtx_ASHIFT (mode, sub,
1089 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~ val)))
1093 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
1094 emit_insn (gen_rtx_SET (VOIDmode, sub,
1095 gen_rtx_NOT (mode, source)));
1098 sub = gen_reg_rtx (mode);
1099 emit_insn (gen_rtx_SET (VOIDmode, sub,
1100 gen_rtx_AND (mode, source,
1102 emit_insn (gen_rtx_SET (VOIDmode, target,
1103 gen_rtx_NOT (mode, sub)));
1110 /* See if two shifts will do 2 or more insn's worth of work. */
1111 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
1113 HOST_WIDE_INT shift_mask = ((0xffffffff
1114 << (32 - clear_sign_bit_copies))
1117 if ((remainder | shift_mask) != 0xffffffff)
1121 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1122 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1123 new_src, source, subtargets, 1);
1128 rtx targ = subtargets ? NULL_RTX : target;
1129 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1130 targ, source, subtargets, 0);
1136 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1137 rtx shift = GEN_INT (clear_sign_bit_copies);
1139 emit_insn (gen_ashlsi3 (new_src, source, shift));
1140 emit_insn (gen_lshrsi3 (target, new_src, shift));
1146 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
1148 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
1150 if ((remainder | shift_mask) != 0xffffffff)
1154 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1156 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1157 new_src, source, subtargets, 1);
1162 rtx targ = subtargets ? NULL_RTX : target;
1164 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
1165 targ, source, subtargets, 0);
1171 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
1172 rtx shift = GEN_INT (clear_zero_bit_copies);
1174 emit_insn (gen_lshrsi3 (new_src, source, shift));
1175 emit_insn (gen_ashlsi3 (target, new_src, shift));
1187 for (i = 0; i < 32; i++)
1188 if (remainder & (1 << i))
1191 if (code == AND || (can_invert && num_bits_set > 16))
1192 remainder = (~remainder) & 0xffffffff;
1193 else if (code == PLUS && num_bits_set > 16)
1194 remainder = (-remainder) & 0xffffffff;
1201 /* Now try and find a way of doing the job in either two or three
1203 We start by looking for the largest block of zeros that are aligned on
1204 a 2-bit boundary, we then fill up the temps, wrapping around to the
1205 top of the word when we drop off the bottom.
1206 In the worst case this code should produce no more than four insns. */
1209 int best_consecutive_zeros = 0;
1211 for (i = 0; i < 32; i += 2)
1213 int consecutive_zeros = 0;
1215 if (! (remainder & (3 << i)))
1217 while ((i < 32) && ! (remainder & (3 << i)))
1219 consecutive_zeros += 2;
1222 if (consecutive_zeros > best_consecutive_zeros)
1224 best_consecutive_zeros = consecutive_zeros;
1225 best_start = i - consecutive_zeros;
1231 /* Now start emitting the insns, starting with the one with the highest
1232 bit set: we do this so that the smallest number will be emitted last;
1233 this is more likely to be combinable with addressing insns. */
1241 if (remainder & (3 << (i - 2)))
1246 temp1 = remainder & ((0x0ff << end)
1247 | ((i < end) ? (0xff >> (32 - end)) : 0));
1248 remainder &= ~temp1;
1255 emit_insn (gen_rtx_SET (VOIDmode,
1256 new_src = (subtargets
1257 ? gen_reg_rtx (mode)
1260 ? ~temp1 : temp1)));
1261 else if (code == MINUS)
1262 emit_insn (gen_rtx_SET (VOIDmode,
1263 new_src = (subtargets
1264 ? gen_reg_rtx (mode)
1266 gen_rtx (code, mode, GEN_INT (temp1),
1269 emit_insn (gen_rtx_SET (VOIDmode,
1270 new_src = (remainder
1272 ? gen_reg_rtx (mode)
1275 gen_rtx (code, mode, source,
1276 GEN_INT (can_invert ? ~temp1
1288 else if (code == MINUS)
1295 } while (remainder);
1300 /* Canonicalize a comparison so that we are more likely to recognize it.
1301 This can be done for a few constant compares, where we can make the
1302 immediate value easier to load. */
1304 arm_canonicalize_comparison (code, op1)
1308 unsigned HOST_WIDE_INT i = INTVAL (*op1);
1318 if (i != ((((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
1320 && (const_ok_for_arm (i+1) || const_ok_for_arm (- (i+1))))
1322 *op1 = GEN_INT (i+1);
1323 return code == GT ? GE : LT;
1329 if (i != (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
1330 && (const_ok_for_arm (i-1) || const_ok_for_arm (- (i-1))))
1332 *op1 = GEN_INT (i-1);
1333 return code == GE ? GT : LE;
1339 if (i != ~((unsigned HOST_WIDE_INT) 0)
1340 && (const_ok_for_arm (i+1) || const_ok_for_arm (- (i+1))))
1342 *op1 = GEN_INT (i + 1);
1343 return code == GTU ? GEU : LTU;
1350 && (const_ok_for_arm (i - 1) || const_ok_for_arm (- (i - 1))))
1352 *op1 = GEN_INT (i - 1);
1353 return code == GEU ? GTU : LEU;
1364 /* Decide whether a type should be returned in memory (true)
1365 or in a register (false). This is called by the macro
1366 RETURN_IN_MEMORY. */
1368 arm_return_in_memory (type)
1371 if (! AGGREGATE_TYPE_P (type))
1373 /* All simple types are returned in registers. */
1376 else if (int_size_in_bytes (type) > 4)
1378 /* All structures/unions bigger than one word are returned in memory. */
1381 else if (TREE_CODE (type) == RECORD_TYPE)
1385 /* For a struct the APCS says that we must return in a register if
1386 every addressable element has an offset of zero. For practical
1387 purposes this means that the structure can have at most one non
1388 bit-field element and that this element must be the first one in
1391 /* Find the first field, ignoring non FIELD_DECL things which will
1392 have been created by C++. */
1393 for (field = TYPE_FIELDS (type);
1394 field && TREE_CODE (field) != FIELD_DECL;
1395 field = TREE_CHAIN (field))
1399 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
1401 /* Now check the remaining fields, if any. */
1402 for (field = TREE_CHAIN (field);
1404 field = TREE_CHAIN (field))
1406 if (TREE_CODE (field) != FIELD_DECL)
1409 if (! DECL_BIT_FIELD_TYPE (field))
1415 else if (TREE_CODE (type) == UNION_TYPE)
1419 /* Unions can be returned in registers if every element is
1420 integral, or can be returned in an integer register. */
1421 for (field = TYPE_FIELDS (type);
1423 field = TREE_CHAIN (field))
1425 if (TREE_CODE (field) != FIELD_DECL)
1428 if (FLOAT_TYPE_P (TREE_TYPE (field)))
1431 if (RETURN_IN_MEMORY (TREE_TYPE (field)))
1438 /* XXX Not sure what should be done for other aggregates, so put them in
1444 legitimate_pic_operand_p (x)
1447 if (CONSTANT_P (x) && flag_pic
1448 && (GET_CODE (x) == SYMBOL_REF
1449 || (GET_CODE (x) == CONST
1450 && GET_CODE (XEXP (x, 0)) == PLUS
1451 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)))
1458 legitimize_pic_address (orig, mode, reg)
1460 enum machine_mode mode;
1463 if (GET_CODE (orig) == SYMBOL_REF)
1465 rtx pic_ref, address;
1471 if (reload_in_progress || reload_completed)
1474 reg = gen_reg_rtx (Pmode);
1479 #ifdef AOF_ASSEMBLER
1480 /* The AOF assembler can generate relocations for these directly, and
1481 understands that the PIC register has to be added into the offset.
1483 insn = emit_insn (gen_pic_load_addr_based (reg, orig));
1486 address = gen_reg_rtx (Pmode);
1490 emit_insn (gen_pic_load_addr (address, orig));
1492 pic_ref = gen_rtx_MEM (Pmode,
1493 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
1495 RTX_UNCHANGING_P (pic_ref) = 1;
1496 insn = emit_move_insn (reg, pic_ref);
1498 current_function_uses_pic_offset_table = 1;
1499 /* Put a REG_EQUAL note on this insn, so that it can be optimized
1501 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
1505 else if (GET_CODE (orig) == CONST)
1509 if (GET_CODE (XEXP (orig, 0)) == PLUS
1510 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1515 if (reload_in_progress || reload_completed)
1518 reg = gen_reg_rtx (Pmode);
1521 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1523 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1524 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1525 base == reg ? 0 : reg);
1530 if (GET_CODE (offset) == CONST_INT)
1532 /* The base register doesn't really matter, we only want to
1533 test the index for the appropriate mode. */
1534 GO_IF_LEGITIMATE_INDEX (mode, 0, offset, win);
1536 if (! reload_in_progress && ! reload_completed)
1537 offset = force_reg (Pmode, offset);
1542 if (GET_CODE (offset) == CONST_INT)
1543 return plus_constant_for_output (base, INTVAL (offset));
1546 if (GET_MODE_SIZE (mode) > 4
1547 && (GET_MODE_CLASS (mode) == MODE_INT
1548 || TARGET_SOFT_FLOAT))
1550 emit_insn (gen_addsi3 (reg, base, offset));
1554 return gen_rtx_PLUS (Pmode, base, offset);
1556 else if (GET_CODE (orig) == LABEL_REF)
1557 current_function_uses_pic_offset_table = 1;
1576 #ifndef AOF_ASSEMBLER
1577 rtx l1, pic_tmp, pic_tmp2, seq;
1578 rtx global_offset_table;
1580 if (current_function_uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE)
1587 l1 = gen_label_rtx ();
1589 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
1590 /* On the ARM the PC register contains 'dot + 8' at the time of the
1592 pic_tmp = plus_constant (gen_rtx_LABEL_REF (Pmode, l1), 8);
1594 pic_tmp2 = gen_rtx_CONST (VOIDmode,
1595 gen_rtx_PLUS (Pmode, global_offset_table, pc_rtx));
1597 pic_tmp2 = gen_rtx_CONST (VOIDmode, global_offset_table);
1599 pic_rtx = gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, pic_tmp2, pic_tmp));
1601 emit_insn (gen_pic_load_addr (pic_offset_table_rtx, pic_rtx));
1602 emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx, l1));
1604 seq = gen_sequence ();
1606 emit_insn_after (seq, get_insns ());
1608 /* Need to emit this whether or not we obey regdecls,
1609 since setjmp/longjmp can cause life info to screw up. */
1610 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
1611 #endif /* AOF_ASSEMBLER */
1614 #define REG_OR_SUBREG_REG(X) \
1615 (GET_CODE (X) == REG \
1616 || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
1618 #define REG_OR_SUBREG_RTX(X) \
1619 (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
1621 #define ARM_FRAME_RTX(X) \
1622 ((X) == frame_pointer_rtx || (X) == stack_pointer_rtx \
1623 || (X) == arg_pointer_rtx)
1626 arm_rtx_costs (x, code)
1630 enum machine_mode mode = GET_MODE (x);
1631 enum rtx_code subcode;
1637 /* Memory costs quite a lot for the first word, but subsequent words
1638 load at the equivalent of a single insn each. */
1639 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
1640 + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
1647 if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG)
1654 case ASHIFT: case LSHIFTRT: case ASHIFTRT:
1656 return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8)
1657 + ((GET_CODE (XEXP (x, 0)) == REG
1658 || (GET_CODE (XEXP (x, 0)) == SUBREG
1659 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
1661 return (1 + ((GET_CODE (XEXP (x, 0)) == REG
1662 || (GET_CODE (XEXP (x, 0)) == SUBREG
1663 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
1665 + ((GET_CODE (XEXP (x, 1)) == REG
1666 || (GET_CODE (XEXP (x, 1)) == SUBREG
1667 && GET_CODE (SUBREG_REG (XEXP (x, 1))) == REG)
1668 || (GET_CODE (XEXP (x, 1)) == CONST_INT))
1673 return (4 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 8)
1674 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
1675 || (GET_CODE (XEXP (x, 0)) == CONST_INT
1676 && const_ok_for_arm (INTVAL (XEXP (x, 0)))))
1679 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1680 return (2 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1681 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
1682 && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
1684 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
1685 || (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE
1686 && const_double_rtx_ok_for_fpu (XEXP (x, 0))))
1689 if (((GET_CODE (XEXP (x, 0)) == CONST_INT
1690 && const_ok_for_arm (INTVAL (XEXP (x, 0)))
1691 && REG_OR_SUBREG_REG (XEXP (x, 1))))
1692 || (((subcode = GET_CODE (XEXP (x, 1))) == ASHIFT
1693 || subcode == ASHIFTRT || subcode == LSHIFTRT
1694 || subcode == ROTATE || subcode == ROTATERT
1696 && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
1697 && ((INTVAL (XEXP (XEXP (x, 1), 1)) &
1698 (INTVAL (XEXP (XEXP (x, 1), 1)) - 1)) == 0)))
1699 && REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 0))
1700 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 1))
1701 || GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT)
1702 && REG_OR_SUBREG_REG (XEXP (x, 0))))
1707 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1708 return (2 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
1709 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1710 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
1711 && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
1715 case AND: case XOR: case IOR:
1718 /* Normally the frame registers will be spilt into reg+const during
1719 reload, so it is a bad idea to combine them with other instructions,
1720 since then they might not be moved outside of loops. As a compromise
1721 we allow integration with ops that have a constant as their second
1723 if ((REG_OR_SUBREG_REG (XEXP (x, 0))
1724 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))
1725 && GET_CODE (XEXP (x, 1)) != CONST_INT)
1726 || (REG_OR_SUBREG_REG (XEXP (x, 0))
1727 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))))
1731 return (4 + extra_cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
1732 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1733 || (GET_CODE (XEXP (x, 1)) == CONST_INT
1734 && const_ok_for_op (INTVAL (XEXP (x, 1)), code)))
1737 if (REG_OR_SUBREG_REG (XEXP (x, 0)))
1738 return (1 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : extra_cost)
1739 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1740 || (GET_CODE (XEXP (x, 1)) == CONST_INT
1741 && const_ok_for_op (INTVAL (XEXP (x, 1)), code)))
1744 else if (REG_OR_SUBREG_REG (XEXP (x, 1)))
1745 return (1 + extra_cost
1746 + ((((subcode = GET_CODE (XEXP (x, 0))) == ASHIFT
1747 || subcode == LSHIFTRT || subcode == ASHIFTRT
1748 || subcode == ROTATE || subcode == ROTATERT
1750 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1751 && ((INTVAL (XEXP (XEXP (x, 0), 1)) &
1752 (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0)))
1753 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 0)))
1754 && ((REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 1)))
1755 || GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
1761 /* There is no point basing this on the tuning, since it is always the
1762 fast variant if it exists at all */
1763 if (arm_fast_multiply && mode == DImode
1764 && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1)))
1765 && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
1766 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND))
1769 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1773 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1775 unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1))
1776 & (unsigned HOST_WIDE_INT) 0xffffffff);
1777 int add_cost = const_ok_for_arm (i) ? 4 : 8;
1779 /* Tune as appropriate */
1780 int booth_unit_size = ((tune_flags & FL_FAST_MULT) ? 8 : 2);
1782 for (j = 0; i && j < 32; j += booth_unit_size)
1784 i >>= booth_unit_size;
1791 return (((tune_flags & FL_FAST_MULT) ? 8 : 30)
1792 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
1793 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4));
1796 if (arm_fast_multiply && mode == SImode
1797 && GET_CODE (XEXP (x, 0)) == LSHIFTRT
1798 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1799 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1800 == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1801 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
1802 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND))
1807 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1808 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 6);
1812 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
1814 return 1 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
1817 if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
1825 return 4 + (mode == DImode ? 4 : 0);
1828 if (GET_MODE (XEXP (x, 0)) == QImode)
1829 return (4 + (mode == DImode ? 4 : 0)
1830 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1833 switch (GET_MODE (XEXP (x, 0)))
1836 return (1 + (mode == DImode ? 4 : 0)
1837 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1840 return (4 + (mode == DImode ? 4 : 0)
1841 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1844 return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1857 arm_adjust_cost (insn, link, dep, cost)
1865 /* XXX This is not strictly true for the FPA. */
1866 if (REG_NOTE_KIND(link) == REG_DEP_ANTI
1867 || REG_NOTE_KIND(link) == REG_DEP_OUTPUT)
1870 if ((i_pat = single_set (insn)) != NULL
1871 && GET_CODE (SET_SRC (i_pat)) == MEM
1872 && (d_pat = single_set (dep)) != NULL
1873 && GET_CODE (SET_DEST (d_pat)) == MEM)
1875 /* This is a load after a store, there is no conflict if the load reads
1876 from a cached area. Assume that loads from the stack, and from the
1877 constant pool are cached, and that others will miss. This is a
1880 /* debug_rtx (insn);
1883 fprintf (stderr, "costs %d\n", cost); */
1885 if (CONSTANT_POOL_ADDRESS_P (XEXP (SET_SRC (i_pat), 0))
1886 || reg_mentioned_p (stack_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
1887 || reg_mentioned_p (frame_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
1888 || reg_mentioned_p (hard_frame_pointer_rtx,
1889 XEXP (SET_SRC (i_pat), 0)))
1891 /* fprintf (stderr, "***** Now 1\n"); */
1899 /* This code has been fixed for cross compilation. */
1901 static int fpa_consts_inited = 0;
1903 char * strings_fpa[8] =
1906 "4", "5", "0.5", "10"
1909 static REAL_VALUE_TYPE values_fpa[8];
1917 for (i = 0; i < 8; i++)
1919 r = REAL_VALUE_ATOF (strings_fpa[i], DFmode);
1923 fpa_consts_inited = 1;
1926 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1929 const_double_rtx_ok_for_fpu (x)
1935 if (!fpa_consts_inited)
1938 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
1939 if (REAL_VALUE_MINUS_ZERO (r))
1942 for (i = 0; i < 8; i++)
1943 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
1949 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1952 neg_const_double_rtx_ok_for_fpu (x)
1958 if (!fpa_consts_inited)
1961 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
1962 r = REAL_VALUE_NEGATE (r);
1963 if (REAL_VALUE_MINUS_ZERO (r))
1966 for (i = 0; i < 8; i++)
1967 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
1973 /* Predicates for `match_operand' and `match_operator'. */
1975 /* s_register_operand is the same as register_operand, but it doesn't accept
1978 This function exists because at the time it was put in it led to better
1979 code. SUBREG(MEM) always needs a reload in the places where
1980 s_register_operand is used, and this seemed to lead to excessive
1984 s_register_operand (op, mode)
1986 enum machine_mode mode;
1988 if (GET_MODE (op) != mode && mode != VOIDmode)
1991 if (GET_CODE (op) == SUBREG)
1992 op = SUBREG_REG (op);
1994 /* We don't consider registers whose class is NO_REGS
1995 to be a register operand. */
1996 return (GET_CODE (op) == REG
1997 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1998 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
2001 /* Only accept reg, subreg(reg), const_int. */
2004 reg_or_int_operand (op, mode)
2006 enum machine_mode mode;
2008 if (GET_CODE (op) == CONST_INT)
2011 if (GET_MODE (op) != mode && mode != VOIDmode)
2014 if (GET_CODE (op) == SUBREG)
2015 op = SUBREG_REG (op);
2017 /* We don't consider registers whose class is NO_REGS
2018 to be a register operand. */
2019 return (GET_CODE (op) == REG
2020 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
2021 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
2024 /* Return 1 if OP is an item in memory, given that we are in reload. */
2027 reload_memory_operand (op, mode)
2029 enum machine_mode mode ATTRIBUTE_UNUSED;
2031 int regno = true_regnum (op);
2033 return (! CONSTANT_P (op)
2035 || (GET_CODE (op) == REG
2036 && REGNO (op) >= FIRST_PSEUDO_REGISTER)));
2039 /* Return 1 if OP is a valid memory address, but not valid for a signed byte
2040 memory access (architecture V4) */
2042 bad_signed_byte_operand (op, mode)
2044 enum machine_mode mode;
2046 if (! memory_operand (op, mode) || GET_CODE (op) != MEM)
2051 /* A sum of anything more complex than reg + reg or reg + const is bad */
2052 if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS)
2053 && (! s_register_operand (XEXP (op, 0), VOIDmode)
2054 || (! s_register_operand (XEXP (op, 1), VOIDmode)
2055 && GET_CODE (XEXP (op, 1)) != CONST_INT)))
2058 /* Big constants are also bad */
2059 if (GET_CODE (op) == PLUS && GET_CODE (XEXP (op, 1)) == CONST_INT
2060 && (INTVAL (XEXP (op, 1)) > 0xff
2061 || -INTVAL (XEXP (op, 1)) > 0xff))
2064 /* Everything else is good, or can will automatically be made so. */
2068 /* Return TRUE for valid operands for the rhs of an ARM instruction. */
2071 arm_rhs_operand (op, mode)
2073 enum machine_mode mode;
2075 return (s_register_operand (op, mode)
2076 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op))));
2079 /* Return TRUE for valid operands for the rhs of an ARM instruction, or a load.
2083 arm_rhsm_operand (op, mode)
2085 enum machine_mode mode;
2087 return (s_register_operand (op, mode)
2088 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op)))
2089 || memory_operand (op, mode));
2092 /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a
2093 constant that is valid when negated. */
2096 arm_add_operand (op, mode)
2098 enum machine_mode mode;
2100 return (s_register_operand (op, mode)
2101 || (GET_CODE (op) == CONST_INT
2102 && (const_ok_for_arm (INTVAL (op))
2103 || const_ok_for_arm (-INTVAL (op)))));
2107 arm_not_operand (op, mode)
2109 enum machine_mode mode;
2111 return (s_register_operand (op, mode)
2112 || (GET_CODE (op) == CONST_INT
2113 && (const_ok_for_arm (INTVAL (op))
2114 || const_ok_for_arm (~INTVAL (op)))));
2117 /* Return TRUE if the operand is a memory reference which contains an
2118 offsettable address. */
2120 offsettable_memory_operand (op, mode)
2122 enum machine_mode mode;
2124 if (mode == VOIDmode)
2125 mode = GET_MODE (op);
2127 return (mode == GET_MODE (op)
2128 && GET_CODE (op) == MEM
2129 && offsettable_address_p (reload_completed | reload_in_progress,
2130 mode, XEXP (op, 0)));
2133 /* Return TRUE if the operand is a memory reference which is, or can be
2134 made word aligned by adjusting the offset. */
2136 alignable_memory_operand (op, mode)
2138 enum machine_mode mode;
2142 if (mode == VOIDmode)
2143 mode = GET_MODE (op);
2145 if (mode != GET_MODE (op) || GET_CODE (op) != MEM)
2150 return ((GET_CODE (reg = op) == REG
2151 || (GET_CODE (op) == SUBREG
2152 && GET_CODE (reg = SUBREG_REG (op)) == REG)
2153 || (GET_CODE (op) == PLUS
2154 && GET_CODE (XEXP (op, 1)) == CONST_INT
2155 && (GET_CODE (reg = XEXP (op, 0)) == REG
2156 || (GET_CODE (XEXP (op, 0)) == SUBREG
2157 && GET_CODE (reg = SUBREG_REG (XEXP (op, 0))) == REG))))
2158 && REGNO_POINTER_ALIGN (REGNO (reg)) >= 4);
2161 /* Similar to s_register_operand, but does not allow hard integer
2164 f_register_operand (op, mode)
2166 enum machine_mode mode;
2168 if (GET_MODE (op) != mode && mode != VOIDmode)
2171 if (GET_CODE (op) == SUBREG)
2172 op = SUBREG_REG (op);
2174 /* We don't consider registers whose class is NO_REGS
2175 to be a register operand. */
2176 return (GET_CODE (op) == REG
2177 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
2178 || REGNO_REG_CLASS (REGNO (op)) == FPU_REGS));
2181 /* Return TRUE for valid operands for the rhs of an FPU instruction. */
2184 fpu_rhs_operand (op, mode)
2186 enum machine_mode mode;
2188 if (s_register_operand (op, mode))
2190 else if (GET_CODE (op) == CONST_DOUBLE)
2191 return (const_double_rtx_ok_for_fpu (op));
2197 fpu_add_operand (op, mode)
2199 enum machine_mode mode;
2201 if (s_register_operand (op, mode))
2203 else if (GET_CODE (op) == CONST_DOUBLE)
2204 return (const_double_rtx_ok_for_fpu (op)
2205 || neg_const_double_rtx_ok_for_fpu (op));
2210 /* Return nonzero if OP is a constant power of two. */
2213 power_of_two_operand (op, mode)
2215 enum machine_mode mode ATTRIBUTE_UNUSED;
2217 if (GET_CODE (op) == CONST_INT)
2219 HOST_WIDE_INT value = INTVAL(op);
2220 return value != 0 && (value & (value - 1)) == 0;
2225 /* Return TRUE for a valid operand of a DImode operation.
2226 Either: REG, SUBREG, CONST_DOUBLE or MEM(DImode_address).
2227 Note that this disallows MEM(REG+REG), but allows
2228 MEM(PRE/POST_INC/DEC(REG)). */
2231 di_operand (op, mode)
2233 enum machine_mode mode;
2235 if (s_register_operand (op, mode))
2238 if (GET_CODE (op) == SUBREG)
2239 op = SUBREG_REG (op);
2241 switch (GET_CODE (op))
2248 return memory_address_p (DImode, XEXP (op, 0));
2255 /* Return TRUE for a valid operand of a DFmode operation when -msoft-float.
2256 Either: REG, SUBREG, CONST_DOUBLE or MEM(DImode_address).
2257 Note that this disallows MEM(REG+REG), but allows
2258 MEM(PRE/POST_INC/DEC(REG)). */
2261 soft_df_operand (op, mode)
2263 enum machine_mode mode;
2265 if (s_register_operand (op, mode))
2268 if (GET_CODE (op) == SUBREG)
2269 op = SUBREG_REG (op);
2271 switch (GET_CODE (op))
2277 return memory_address_p (DFmode, XEXP (op, 0));
2284 /* Return TRUE for valid index operands. */
2287 index_operand (op, mode)
2289 enum machine_mode mode;
2291 return (s_register_operand(op, mode)
2292 || (immediate_operand (op, mode)
2293 && INTVAL (op) < 4096 && INTVAL (op) > -4096));
2296 /* Return TRUE for valid shifts by a constant. This also accepts any
2297 power of two on the (somewhat overly relaxed) assumption that the
2298 shift operator in this case was a mult. */
2301 const_shift_operand (op, mode)
2303 enum machine_mode mode;
2305 return (power_of_two_operand (op, mode)
2306 || (immediate_operand (op, mode)
2307 && (INTVAL (op) < 32 && INTVAL (op) > 0)));
2310 /* Return TRUE for arithmetic operators which can be combined with a multiply
2314 shiftable_operator (x, mode)
2316 enum machine_mode mode;
2318 if (GET_MODE (x) != mode)
2322 enum rtx_code code = GET_CODE (x);
2324 return (code == PLUS || code == MINUS
2325 || code == IOR || code == XOR || code == AND);
2329 /* Return TRUE for shift operators. */
2332 shift_operator (x, mode)
2334 enum machine_mode mode;
2336 if (GET_MODE (x) != mode)
2340 enum rtx_code code = GET_CODE (x);
2343 return power_of_two_operand (XEXP (x, 1), mode);
2345 return (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT
2346 || code == ROTATERT);
2350 int equality_operator (x, mode)
2352 enum machine_mode mode ATTRIBUTE_UNUSED;
2354 return GET_CODE (x) == EQ || GET_CODE (x) == NE;
2357 /* Return TRUE for SMIN SMAX UMIN UMAX operators. */
2360 minmax_operator (x, mode)
2362 enum machine_mode mode;
2364 enum rtx_code code = GET_CODE (x);
2366 if (GET_MODE (x) != mode)
2369 return code == SMIN || code == SMAX || code == UMIN || code == UMAX;
2372 /* return TRUE if x is EQ or NE */
2374 /* Return TRUE if this is the condition code register, if we aren't given
2375 a mode, accept any class CCmode register */
2378 cc_register (x, mode)
2380 enum machine_mode mode;
2382 if (mode == VOIDmode)
2384 mode = GET_MODE (x);
2385 if (GET_MODE_CLASS (mode) != MODE_CC)
2389 if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
2395 /* Return TRUE if this is the condition code register, if we aren't given
2396 a mode, accept any class CCmode register which indicates a dominance
2400 dominant_cc_register (x, mode)
2402 enum machine_mode mode;
2404 if (mode == VOIDmode)
2406 mode = GET_MODE (x);
2407 if (GET_MODE_CLASS (mode) != MODE_CC)
2411 if (mode != CC_DNEmode && mode != CC_DEQmode
2412 && mode != CC_DLEmode && mode != CC_DLTmode
2413 && mode != CC_DGEmode && mode != CC_DGTmode
2414 && mode != CC_DLEUmode && mode != CC_DLTUmode
2415 && mode != CC_DGEUmode && mode != CC_DGTUmode)
2418 if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
2424 /* Return TRUE if X references a SYMBOL_REF. */
2426 symbol_mentioned_p (x)
2429 register char * fmt;
2432 if (GET_CODE (x) == SYMBOL_REF)
2435 fmt = GET_RTX_FORMAT (GET_CODE (x));
2436 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2442 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2443 if (symbol_mentioned_p (XVECEXP (x, i, j)))
2446 else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
2453 /* Return TRUE if X references a LABEL_REF. */
2455 label_mentioned_p (x)
2458 register char * fmt;
2461 if (GET_CODE (x) == LABEL_REF)
2464 fmt = GET_RTX_FORMAT (GET_CODE (x));
2465 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2471 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2472 if (label_mentioned_p (XVECEXP (x, i, j)))
2475 else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
2486 enum rtx_code code = GET_CODE (x);
2490 else if (code == SMIN)
2492 else if (code == UMIN)
2494 else if (code == UMAX)
2500 /* Return 1 if memory locations are adjacent */
2503 adjacent_mem_locations (a, b)
2506 int val0 = 0, val1 = 0;
2509 if ((GET_CODE (XEXP (a, 0)) == REG
2510 || (GET_CODE (XEXP (a, 0)) == PLUS
2511 && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT))
2512 && (GET_CODE (XEXP (b, 0)) == REG
2513 || (GET_CODE (XEXP (b, 0)) == PLUS
2514 && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT)))
2516 if (GET_CODE (XEXP (a, 0)) == PLUS)
2518 reg0 = REGNO (XEXP (XEXP (a, 0), 0));
2519 val0 = INTVAL (XEXP (XEXP (a, 0), 1));
2522 reg0 = REGNO (XEXP (a, 0));
2523 if (GET_CODE (XEXP (b, 0)) == PLUS)
2525 reg1 = REGNO (XEXP (XEXP (b, 0), 0));
2526 val1 = INTVAL (XEXP (XEXP (b, 0), 1));
2529 reg1 = REGNO (XEXP (b, 0));
2530 return (reg0 == reg1) && ((val1 - val0) == 4 || (val0 - val1) == 4);
2535 /* Return 1 if OP is a load multiple operation. It is known to be
2536 parallel and the first section will be tested. */
2539 load_multiple_operation (op, mode)
2541 enum machine_mode mode ATTRIBUTE_UNUSED;
2543 HOST_WIDE_INT count = XVECLEN (op, 0);
2546 HOST_WIDE_INT i = 1, base = 0;
2550 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
2553 /* Check to see if this might be a write-back */
2554 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
2559 /* Now check it more carefully */
2560 if (GET_CODE (SET_DEST (elt)) != REG
2561 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
2562 || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
2563 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
2564 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
2565 || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
2566 || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
2567 || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
2568 != REGNO (SET_DEST (elt)))
2574 /* Perform a quick check so we don't blow up below. */
2576 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
2577 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
2578 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM)
2581 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
2582 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
2584 for (; i < count; i++)
2586 elt = XVECEXP (op, 0, i);
2588 if (GET_CODE (elt) != SET
2589 || GET_CODE (SET_DEST (elt)) != REG
2590 || GET_MODE (SET_DEST (elt)) != SImode
2591 || REGNO (SET_DEST (elt)) != dest_regno + i - base
2592 || GET_CODE (SET_SRC (elt)) != MEM
2593 || GET_MODE (SET_SRC (elt)) != SImode
2594 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2595 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2596 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2597 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4)
2604 /* Return 1 if OP is a store multiple operation. It is known to be
2605 parallel and the first section will be tested. */
2608 store_multiple_operation (op, mode)
2610 enum machine_mode mode ATTRIBUTE_UNUSED;
2612 HOST_WIDE_INT count = XVECLEN (op, 0);
2615 HOST_WIDE_INT i = 1, base = 0;
2619 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
2622 /* Check to see if this might be a write-back */
2623 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
2628 /* Now check it more carefully */
2629 if (GET_CODE (SET_DEST (elt)) != REG
2630 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
2631 || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
2632 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
2633 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
2634 || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
2635 || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
2636 || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
2637 != REGNO (SET_DEST (elt)))
2643 /* Perform a quick check so we don't blow up below. */
2645 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
2646 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
2647 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG)
2650 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
2651 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
2653 for (; i < count; i++)
2655 elt = XVECEXP (op, 0, i);
2657 if (GET_CODE (elt) != SET
2658 || GET_CODE (SET_SRC (elt)) != REG
2659 || GET_MODE (SET_SRC (elt)) != SImode
2660 || REGNO (SET_SRC (elt)) != src_regno + i - base
2661 || GET_CODE (SET_DEST (elt)) != MEM
2662 || GET_MODE (SET_DEST (elt)) != SImode
2663 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
2664 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
2665 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
2666 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4)
2674 load_multiple_sequence (operands, nops, regs, base, load_offset)
2679 HOST_WIDE_INT * load_offset;
2681 int unsorted_regs[4];
2682 HOST_WIDE_INT unsorted_offsets[4];
2687 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2688 extended if required. */
2689 if (nops < 2 || nops > 4)
2692 /* Loop over the operands and check that the memory references are
2693 suitable (ie immediate offsets from the same base register). At
2694 the same time, extract the target register, and the memory
2696 for (i = 0; i < nops; i++)
2701 /* Convert a subreg of a mem into the mem itself. */
2702 if (GET_CODE (operands[nops + i]) == SUBREG)
2703 operands[nops + i] = alter_subreg(operands[nops + i]);
2705 if (GET_CODE (operands[nops + i]) != MEM)
2708 /* Don't reorder volatile memory references; it doesn't seem worth
2709 looking for the case where the order is ok anyway. */
2710 if (MEM_VOLATILE_P (operands[nops + i]))
2713 offset = const0_rtx;
2715 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
2716 || (GET_CODE (reg) == SUBREG
2717 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2718 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
2719 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
2721 || (GET_CODE (reg) == SUBREG
2722 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2723 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
2728 base_reg = REGNO(reg);
2729 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
2730 ? REGNO (operands[i])
2731 : REGNO (SUBREG_REG (operands[i])));
2736 if (base_reg != REGNO (reg))
2737 /* Not addressed from the same base register. */
2740 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
2741 ? REGNO (operands[i])
2742 : REGNO (SUBREG_REG (operands[i])));
2743 if (unsorted_regs[i] < unsorted_regs[order[0]])
2747 /* If it isn't an integer register, or if it overwrites the
2748 base register but isn't the last insn in the list, then
2749 we can't do this. */
2750 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14
2751 || (i != nops - 1 && unsorted_regs[i] == base_reg))
2754 unsorted_offsets[i] = INTVAL (offset);
2757 /* Not a suitable memory address. */
2761 /* All the useful information has now been extracted from the
2762 operands into unsorted_regs and unsorted_offsets; additionally,
2763 order[0] has been set to the lowest numbered register in the
2764 list. Sort the registers into order, and check that the memory
2765 offsets are ascending and adjacent. */
2767 for (i = 1; i < nops; i++)
2771 order[i] = order[i - 1];
2772 for (j = 0; j < nops; j++)
2773 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
2774 && (order[i] == order[i - 1]
2775 || unsorted_regs[j] < unsorted_regs[order[i]]))
2778 /* Have we found a suitable register? if not, one must be used more
2780 if (order[i] == order[i - 1])
2783 /* Is the memory address adjacent and ascending? */
2784 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
2792 for (i = 0; i < nops; i++)
2793 regs[i] = unsorted_regs[order[i]];
2795 *load_offset = unsorted_offsets[order[0]];
2798 if (unsorted_offsets[order[0]] == 0)
2799 return 1; /* ldmia */
2801 if (unsorted_offsets[order[0]] == 4)
2802 return 2; /* ldmib */
2804 if (unsorted_offsets[order[nops - 1]] == 0)
2805 return 3; /* ldmda */
2807 if (unsorted_offsets[order[nops - 1]] == -4)
2808 return 4; /* ldmdb */
2810 /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm if
2811 the offset isn't small enough. The reason 2 ldrs are faster is because
2812 these ARMs are able to do more than one cache access in a single cycle.
2813 The ARM9 and StrongARM have Harvard caches, whilst the ARM8 has a double
2814 bandwidth cache. This means that these cores can do both an instruction
2815 fetch and a data fetch in a single cycle, so the trick of calculating the
2816 address into a scratch register (one of the result regs) and then doing a
2817 load multiple actually becomes slower (and no smaller in code size). That
2818 is the transformation
2820 ldr rd1, [rbase + offset]
2821 ldr rd2, [rbase + offset + 4]
2825 add rd1, rbase, offset
2826 ldmia rd1, {rd1, rd2}
2828 produces worse code -- '3 cycles + any stalls on rd2' instead of '2 cycles
2829 + any stalls on rd2'. On ARMs with only one cache access per cycle, the
2830 first sequence could never complete in less than 6 cycles, whereas the ldm
2831 sequence would only take 5 and would make better use of sequential accesses
2832 if not hitting the cache.
2834 We cheat here and test 'arm_ld_sched' which we currently know to only be
2835 true for the ARM8, ARM9 and StrongARM. If this ever changes, then the test
2836 below needs to be reworked. */
2837 if (nops == 2 && arm_ld_sched)
2840 /* Can't do it without setting up the offset, only do this if it takes
2841 no more than one insn. */
2842 return (const_ok_for_arm (unsorted_offsets[order[0]])
2843 || const_ok_for_arm (-unsorted_offsets[order[0]])) ? 5 : 0;
2847 emit_ldm_seq (operands, nops)
2853 HOST_WIDE_INT offset;
2857 switch (load_multiple_sequence (operands, nops, regs, &base_reg, &offset))
2860 strcpy (buf, "ldm%?ia\t");
2864 strcpy (buf, "ldm%?ib\t");
2868 strcpy (buf, "ldm%?da\t");
2872 strcpy (buf, "ldm%?db\t");
2877 sprintf (buf, "add%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
2878 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
2881 sprintf (buf, "sub%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
2882 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
2884 output_asm_insn (buf, operands);
2886 strcpy (buf, "ldm%?ia\t");
2893 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
2894 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
2896 for (i = 1; i < nops; i++)
2897 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
2898 reg_names[regs[i]]);
2900 strcat (buf, "}\t%@ phole ldm");
2902 output_asm_insn (buf, operands);
2907 store_multiple_sequence (operands, nops, regs, base, load_offset)
2912 HOST_WIDE_INT * load_offset;
2914 int unsorted_regs[4];
2915 HOST_WIDE_INT unsorted_offsets[4];
2920 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2921 extended if required. */
2922 if (nops < 2 || nops > 4)
2925 /* Loop over the operands and check that the memory references are
2926 suitable (ie immediate offsets from the same base register). At
2927 the same time, extract the target register, and the memory
2929 for (i = 0; i < nops; i++)
2934 /* Convert a subreg of a mem into the mem itself. */
2935 if (GET_CODE (operands[nops + i]) == SUBREG)
2936 operands[nops + i] = alter_subreg(operands[nops + i]);
2938 if (GET_CODE (operands[nops + i]) != MEM)
2941 /* Don't reorder volatile memory references; it doesn't seem worth
2942 looking for the case where the order is ok anyway. */
2943 if (MEM_VOLATILE_P (operands[nops + i]))
2946 offset = const0_rtx;
2948 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
2949 || (GET_CODE (reg) == SUBREG
2950 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2951 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
2952 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
2954 || (GET_CODE (reg) == SUBREG
2955 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2956 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
2961 base_reg = REGNO (reg);
2962 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
2963 ? REGNO (operands[i])
2964 : REGNO (SUBREG_REG (operands[i])));
2969 if (base_reg != REGNO (reg))
2970 /* Not addressed from the same base register. */
2973 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
2974 ? REGNO (operands[i])
2975 : REGNO (SUBREG_REG (operands[i])));
2976 if (unsorted_regs[i] < unsorted_regs[order[0]])
2980 /* If it isn't an integer register, then we can't do this. */
2981 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14)
2984 unsorted_offsets[i] = INTVAL (offset);
2987 /* Not a suitable memory address. */
2991 /* All the useful information has now been extracted from the
2992 operands into unsorted_regs and unsorted_offsets; additionally,
2993 order[0] has been set to the lowest numbered register in the
2994 list. Sort the registers into order, and check that the memory
2995 offsets are ascending and adjacent. */
2997 for (i = 1; i < nops; i++)
3001 order[i] = order[i - 1];
3002 for (j = 0; j < nops; j++)
3003 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
3004 && (order[i] == order[i - 1]
3005 || unsorted_regs[j] < unsorted_regs[order[i]]))
3008 /* Have we found a suitable register? if not, one must be used more
3010 if (order[i] == order[i - 1])
3013 /* Is the memory address adjacent and ascending? */
3014 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
3022 for (i = 0; i < nops; i++)
3023 regs[i] = unsorted_regs[order[i]];
3025 *load_offset = unsorted_offsets[order[0]];
3028 if (unsorted_offsets[order[0]] == 0)
3029 return 1; /* stmia */
3031 if (unsorted_offsets[order[0]] == 4)
3032 return 2; /* stmib */
3034 if (unsorted_offsets[order[nops - 1]] == 0)
3035 return 3; /* stmda */
3037 if (unsorted_offsets[order[nops - 1]] == -4)
3038 return 4; /* stmdb */
3044 emit_stm_seq (operands, nops)
3050 HOST_WIDE_INT offset;
3054 switch (store_multiple_sequence (operands, nops, regs, &base_reg, &offset))
3057 strcpy (buf, "stm%?ia\t");
3061 strcpy (buf, "stm%?ib\t");
3065 strcpy (buf, "stm%?da\t");
3069 strcpy (buf, "stm%?db\t");
3076 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
3077 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
3079 for (i = 1; i < nops; i++)
3080 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
3081 reg_names[regs[i]]);
3083 strcat (buf, "}\t%@ phole stm");
3085 output_asm_insn (buf, operands);
3090 multi_register_push (op, mode)
3092 enum machine_mode mode ATTRIBUTE_UNUSED;
3094 if (GET_CODE (op) != PARALLEL
3095 || (GET_CODE (XVECEXP (op, 0, 0)) != SET)
3096 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
3097 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != 2))
3104 /* Routines for use with attributes */
3106 /* Return nonzero if ATTR is a valid attribute for DECL.
3107 ATTRIBUTES are any existing attributes and ARGS are the arguments
3110 Supported attributes:
3112 naked: don't output any prologue or epilogue code, the user is assumed
3113 to do the right thing. */
3116 arm_valid_machine_decl_attribute (decl, attr, args)
3121 if (args != NULL_TREE)
3124 if (is_attribute_p ("naked", attr))
3125 return TREE_CODE (decl) == FUNCTION_DECL;
3129 /* Return non-zero if FUNC is a naked function. */
3132 arm_naked_function_p (func)
3137 if (TREE_CODE (func) != FUNCTION_DECL)
3140 a = lookup_attribute ("naked", DECL_MACHINE_ATTRIBUTES (func));
3141 return a != NULL_TREE;
3144 /* Routines for use in generating RTL */
3147 arm_gen_load_multiple (base_regno, count, from, up, write_back, unchanging_p,
3148 in_struct_p, scalar_p)
3160 int sign = up ? 1 : -1;
3163 result = gen_rtx_PARALLEL (VOIDmode,
3164 rtvec_alloc (count + (write_back ? 2 : 0)));
3167 XVECEXP (result, 0, 0)
3168 = gen_rtx_SET (GET_MODE (from), from,
3169 plus_constant (from, count * 4 * sign));
3174 for (j = 0; i < count; i++, j++)
3176 mem = gen_rtx_MEM (SImode, plus_constant (from, j * 4 * sign));
3177 RTX_UNCHANGING_P (mem) = unchanging_p;
3178 MEM_IN_STRUCT_P (mem) = in_struct_p;
3179 MEM_SCALAR_P (mem) = scalar_p;
3180 XVECEXP (result, 0, i)
3181 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, base_regno + j), mem);
3185 XVECEXP (result, 0, i) = gen_rtx_CLOBBER (SImode, from);
3191 arm_gen_store_multiple (base_regno, count, to, up, write_back, unchanging_p,
3192 in_struct_p, scalar_p)
3204 int sign = up ? 1 : -1;
3207 result = gen_rtx_PARALLEL (VOIDmode,
3208 rtvec_alloc (count + (write_back ? 2 : 0)));
3211 XVECEXP (result, 0, 0)
3212 = gen_rtx_SET (GET_MODE (to), to,
3213 plus_constant (to, count * 4 * sign));
3218 for (j = 0; i < count; i++, j++)
3220 mem = gen_rtx_MEM (SImode, plus_constant (to, j * 4 * sign));
3221 RTX_UNCHANGING_P (mem) = unchanging_p;
3222 MEM_IN_STRUCT_P (mem) = in_struct_p;
3223 MEM_SCALAR_P (mem) = scalar_p;
3225 XVECEXP (result, 0, i)
3226 = gen_rtx_SET (VOIDmode, mem, gen_rtx_REG (SImode, base_regno + j));
3230 XVECEXP (result, 0, i) = gen_rtx_CLOBBER (SImode, to);
3236 arm_gen_movstrqi (operands)
3239 HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes;
3242 rtx st_src, st_dst, fin_src, fin_dst;
3243 rtx part_bytes_reg = NULL;
3245 int dst_unchanging_p, dst_in_struct_p, src_unchanging_p, src_in_struct_p;
3246 int dst_scalar_p, src_scalar_p;
3248 if (GET_CODE (operands[2]) != CONST_INT
3249 || GET_CODE (operands[3]) != CONST_INT
3250 || INTVAL (operands[2]) > 64
3251 || INTVAL (operands[3]) & 3)
3254 st_dst = XEXP (operands[0], 0);
3255 st_src = XEXP (operands[1], 0);
3257 dst_unchanging_p = RTX_UNCHANGING_P (operands[0]);
3258 dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]);
3259 dst_scalar_p = MEM_SCALAR_P (operands[0]);
3260 src_unchanging_p = RTX_UNCHANGING_P (operands[1]);
3261 src_in_struct_p = MEM_IN_STRUCT_P (operands[1]);
3262 src_scalar_p = MEM_SCALAR_P (operands[1]);
3264 fin_dst = dst = copy_to_mode_reg (SImode, st_dst);
3265 fin_src = src = copy_to_mode_reg (SImode, st_src);
3267 in_words_to_go = (INTVAL (operands[2]) + 3) / 4;
3268 out_words_to_go = INTVAL (operands[2]) / 4;
3269 last_bytes = INTVAL (operands[2]) & 3;
3271 if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0)
3272 part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3);
3274 for (i = 0; in_words_to_go >= 2; i+=4)
3276 if (in_words_to_go > 4)
3277 emit_insn (arm_gen_load_multiple (0, 4, src, TRUE, TRUE,
3282 emit_insn (arm_gen_load_multiple (0, in_words_to_go, src, TRUE,
3283 FALSE, src_unchanging_p,
3284 src_in_struct_p, src_scalar_p));
3286 if (out_words_to_go)
3288 if (out_words_to_go > 4)
3289 emit_insn (arm_gen_store_multiple (0, 4, dst, TRUE, TRUE,
3293 else if (out_words_to_go != 1)
3294 emit_insn (arm_gen_store_multiple (0, out_words_to_go,
3303 mem = gen_rtx_MEM (SImode, dst);
3304 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3305 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3306 MEM_SCALAR_P (mem) = dst_scalar_p;
3307 emit_move_insn (mem, gen_rtx_REG (SImode, 0));
3308 if (last_bytes != 0)
3309 emit_insn (gen_addsi3 (dst, dst, GEN_INT (4)));
3313 in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4;
3314 out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4;
3317 /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */
3318 if (out_words_to_go)
3322 mem = gen_rtx_MEM (SImode, src);
3323 RTX_UNCHANGING_P (mem) = src_unchanging_p;
3324 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
3325 MEM_SCALAR_P (mem) = src_scalar_p;
3326 emit_move_insn (sreg = gen_reg_rtx (SImode), mem);
3327 emit_move_insn (fin_src = gen_reg_rtx (SImode), plus_constant (src, 4));
3329 mem = gen_rtx_MEM (SImode, dst);
3330 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3331 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3332 MEM_SCALAR_P (mem) = dst_scalar_p;
3333 emit_move_insn (mem, sreg);
3334 emit_move_insn (fin_dst = gen_reg_rtx (SImode), plus_constant (dst, 4));
3337 if (in_words_to_go) /* Sanity check */
3343 if (in_words_to_go < 0)
3346 mem = gen_rtx_MEM (SImode, src);
3347 RTX_UNCHANGING_P (mem) = src_unchanging_p;
3348 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
3349 MEM_SCALAR_P (mem) = src_scalar_p;
3350 part_bytes_reg = copy_to_mode_reg (SImode, mem);
3353 if (BYTES_BIG_ENDIAN && last_bytes)
3355 rtx tmp = gen_reg_rtx (SImode);
3357 if (part_bytes_reg == NULL)
3360 /* The bytes we want are in the top end of the word */
3361 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg,
3362 GEN_INT (8 * (4 - last_bytes))));
3363 part_bytes_reg = tmp;
3367 mem = gen_rtx_MEM (QImode, plus_constant (dst, last_bytes - 1));
3368 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3369 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3370 MEM_SCALAR_P (mem) = dst_scalar_p;
3371 emit_move_insn (mem, gen_rtx_SUBREG (QImode, part_bytes_reg, 0));
3375 tmp = gen_reg_rtx (SImode);
3376 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
3377 part_bytes_reg = tmp;
3386 if (part_bytes_reg == NULL)
3389 mem = gen_rtx_MEM (QImode, dst);
3390 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3391 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3392 MEM_SCALAR_P (mem) = dst_scalar_p;
3393 emit_move_insn (mem, gen_rtx_SUBREG (QImode, part_bytes_reg, 0));
3397 rtx tmp = gen_reg_rtx (SImode);
3399 emit_insn (gen_addsi3 (dst, dst, const1_rtx));
3400 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
3401 part_bytes_reg = tmp;
3409 /* Generate a memory reference for a half word, such that it will be loaded
3410 into the top 16 bits of the word. We can assume that the address is
3411 known to be alignable and of the form reg, or plus (reg, const). */
3413 gen_rotated_half_load (memref)
3416 HOST_WIDE_INT offset = 0;
3417 rtx base = XEXP (memref, 0);
3419 if (GET_CODE (base) == PLUS)
3421 offset = INTVAL (XEXP (base, 1));
3422 base = XEXP (base, 0);
3425 /* If we aren't allowed to generate unaligned addresses, then fail. */
3426 if (TARGET_SHORT_BY_BYTES
3427 && ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 0)))
3430 base = gen_rtx_MEM (SImode, plus_constant (base, offset & ~2));
3432 if ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 2))
3435 return gen_rtx_ROTATE (SImode, base, GEN_INT (16));
3438 static enum machine_mode
3439 select_dominance_cc_mode (x, y, cond_or)
3442 HOST_WIDE_INT cond_or;
3444 enum rtx_code cond1, cond2;
3447 /* Currently we will probably get the wrong result if the individual
3448 comparisons are not simple. This also ensures that it is safe to
3449 reverse a comparison if necessary. */
3450 if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1))
3452 || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1))
3457 cond1 = reverse_condition (cond1);
3459 /* If the comparisons are not equal, and one doesn't dominate the other,
3460 then we can't do this. */
3462 && ! comparison_dominates_p (cond1, cond2)
3463 && (swapped = 1, ! comparison_dominates_p (cond2, cond1)))
3468 enum rtx_code temp = cond1;
3476 if (cond2 == EQ || ! cond_or)
3481 case LE: return CC_DLEmode;
3482 case LEU: return CC_DLEUmode;
3483 case GE: return CC_DGEmode;
3484 case GEU: return CC_DGEUmode;
3491 if (cond2 == LT || ! cond_or)
3500 if (cond2 == GT || ! cond_or)
3509 if (cond2 == LTU || ! cond_or)
3518 if (cond2 == GTU || ! cond_or)
3526 /* The remaining cases only occur when both comparisons are the
3551 arm_select_cc_mode (op, x, y)
3556 /* All floating point compares return CCFP if it is an equality
3557 comparison, and CCFPE otherwise. */
3558 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3559 return (op == EQ || op == NE) ? CCFPmode : CCFPEmode;
3561 /* A compare with a shifted operand. Because of canonicalization, the
3562 comparison will have to be swapped when we emit the assembler. */
3563 if (GET_MODE (y) == SImode && GET_CODE (y) == REG
3564 && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
3565 || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE
3566 || GET_CODE (x) == ROTATERT))
3569 /* This is a special case that is used by combine to allow a
3570 comparison of a shifted byte load to be split into a zero-extend
3571 followed by a comparison of the shifted integer (only valid for
3572 equalities and unsigned inequalities). */
3573 if (GET_MODE (x) == SImode
3574 && GET_CODE (x) == ASHIFT
3575 && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24
3576 && GET_CODE (XEXP (x, 0)) == SUBREG
3577 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM
3578 && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode
3579 && (op == EQ || op == NE
3580 || op == GEU || op == GTU || op == LTU || op == LEU)
3581 && GET_CODE (y) == CONST_INT)
3584 /* An operation that sets the condition codes as a side-effect, the
3585 V flag is not set correctly, so we can only use comparisons where
3586 this doesn't matter. (For LT and GE we can use "mi" and "pl"
3588 if (GET_MODE (x) == SImode
3590 && (op == EQ || op == NE || op == LT || op == GE)
3591 && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
3592 || GET_CODE (x) == AND || GET_CODE (x) == IOR
3593 || GET_CODE (x) == XOR || GET_CODE (x) == MULT
3594 || GET_CODE (x) == NOT || GET_CODE (x) == NEG
3595 || GET_CODE (x) == LSHIFTRT
3596 || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
3597 || GET_CODE (x) == ROTATERT || GET_CODE (x) == ZERO_EXTRACT))
3600 /* A construct for a conditional compare, if the false arm contains
3601 0, then both conditions must be true, otherwise either condition
3602 must be true. Not all conditions are possible, so CCmode is
3603 returned if it can't be done. */
3604 if (GET_CODE (x) == IF_THEN_ELSE
3605 && (XEXP (x, 2) == const0_rtx
3606 || XEXP (x, 2) == const1_rtx)
3607 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
3608 && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<')
3609 return select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1),
3610 INTVAL (XEXP (x, 2)));
3612 if (GET_MODE (x) == QImode && (op == EQ || op == NE))
3615 if (GET_MODE (x) == SImode && (op == LTU || op == GEU)
3616 && GET_CODE (x) == PLUS
3617 && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y)))
3623 /* X and Y are two things to compare using CODE. Emit the compare insn and
3624 return the rtx for register 0 in the proper mode. FP means this is a
3625 floating point compare: I don't think that it is needed on the arm. */
3628 gen_compare_reg (code, x, y)
3632 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
3633 rtx cc_reg = gen_rtx_REG (mode, 24);
3635 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
3636 gen_rtx_COMPARE (mode, x, y)));
3642 arm_reload_in_hi (operands)
3645 rtx ref = operands[1];
3647 HOST_WIDE_INT offset = 0;
3649 if (GET_CODE (ref) == SUBREG)
3651 offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
3652 if (BYTES_BIG_ENDIAN)
3653 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
3654 - MIN (UNITS_PER_WORD,
3655 GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
3656 ref = SUBREG_REG (ref);
3659 if (GET_CODE (ref) == REG)
3661 /* We have a pseudo which has been spilt onto the stack; there
3662 are two cases here: the first where there is a simple
3663 stack-slot replacement and a second where the stack-slot is
3664 out of range, or is used as a subreg. */
3665 if (reg_equiv_mem[REGNO (ref)])
3667 ref = reg_equiv_mem[REGNO (ref)];
3668 base = find_replacement (&XEXP (ref, 0));
3671 /* The slot is out of range, or was dressed up in a SUBREG */
3672 base = reg_equiv_address[REGNO (ref)];
3675 base = find_replacement (&XEXP (ref, 0));
3677 /* Handle the case where the address is too complex to be offset by 1. */
3678 if (GET_CODE (base) == MINUS
3679 || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT))
3681 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
3683 emit_insn (gen_rtx_SET (VOIDmode, base_plus, base));
3686 else if (GET_CODE (base) == PLUS)
3688 /* The addend must be CONST_INT, or we would have dealt with it above */
3689 HOST_WIDE_INT hi, lo;
3691 offset += INTVAL (XEXP (base, 1));
3692 base = XEXP (base, 0);
3694 /* Rework the address into a legal sequence of insns */
3695 /* Valid range for lo is -4095 -> 4095 */
3698 : -((-offset) & 0xfff));
3700 /* Corner case, if lo is the max offset then we would be out of range
3701 once we have added the additional 1 below, so bump the msb into the
3702 pre-loading insn(s). */
3706 hi = ((((offset - lo) & (HOST_WIDE_INT) 0xFFFFFFFF)
3707 ^ (HOST_WIDE_INT) 0x80000000)
3708 - (HOST_WIDE_INT) 0x80000000);
3710 if (hi + lo != offset)
3715 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
3717 /* Get the base address; addsi3 knows how to handle constants
3718 that require more than one insn */
3719 emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi)));
3725 scratch = gen_rtx_REG (SImode, REGNO (operands[2]));
3726 emit_insn (gen_zero_extendqisi2 (scratch,
3727 gen_rtx_MEM (QImode,
3728 plus_constant (base,
3730 emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0),
3731 gen_rtx_MEM (QImode,
3732 plus_constant (base,
3734 if (! BYTES_BIG_ENDIAN)
3735 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0),
3736 gen_rtx_IOR (SImode,
3739 gen_rtx_SUBREG (SImode, operands[0], 0),
3743 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0),
3744 gen_rtx_IOR (SImode,
3745 gen_rtx_ASHIFT (SImode, scratch,
3747 gen_rtx_SUBREG (SImode, operands[0],
3751 /* Handle storing a half-word to memory during reload by synthesising as two
3752 byte stores. Take care not to clobber the input values until after we
3753 have moved them somewhere safe. This code assumes that if the DImode
3754 scratch in operands[2] overlaps either the input value or output address
3755 in some way, then that value must die in this insn (we absolutely need
3756 two scratch registers for some corner cases). */
3758 arm_reload_out_hi (operands)
3761 rtx ref = operands[0];
3762 rtx outval = operands[1];
3764 HOST_WIDE_INT offset = 0;
3766 if (GET_CODE (ref) == SUBREG)
3768 offset = SUBREG_WORD (ref) * UNITS_PER_WORD;
3769 if (BYTES_BIG_ENDIAN)
3770 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref)))
3771 - MIN (UNITS_PER_WORD,
3772 GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref)))));
3773 ref = SUBREG_REG (ref);
3777 if (GET_CODE (ref) == REG)
3779 /* We have a pseudo which has been spilt onto the stack; there
3780 are two cases here: the first where there is a simple
3781 stack-slot replacement and a second where the stack-slot is
3782 out of range, or is used as a subreg. */
3783 if (reg_equiv_mem[REGNO (ref)])
3785 ref = reg_equiv_mem[REGNO (ref)];
3786 base = find_replacement (&XEXP (ref, 0));
3789 /* The slot is out of range, or was dressed up in a SUBREG */
3790 base = reg_equiv_address[REGNO (ref)];
3793 base = find_replacement (&XEXP (ref, 0));
3795 scratch = gen_rtx_REG (SImode, REGNO (operands[2]));
3797 /* Handle the case where the address is too complex to be offset by 1. */
3798 if (GET_CODE (base) == MINUS
3799 || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT))
3801 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
3803 /* Be careful not to destroy OUTVAL. */
3804 if (reg_overlap_mentioned_p (base_plus, outval))
3806 /* Updating base_plus might destroy outval, see if we can
3807 swap the scratch and base_plus. */
3808 if (! reg_overlap_mentioned_p (scratch, outval))
3811 scratch = base_plus;
3816 rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2]));
3818 /* Be conservative and copy OUTVAL into the scratch now,
3819 this should only be necessary if outval is a subreg
3820 of something larger than a word. */
3821 /* XXX Might this clobber base? I can't see how it can,
3822 since scratch is known to overlap with OUTVAL, and
3823 must be wider than a word. */
3824 emit_insn (gen_movhi (scratch_hi, outval));
3825 outval = scratch_hi;
3829 emit_insn (gen_rtx_SET (VOIDmode, base_plus, base));
3832 else if (GET_CODE (base) == PLUS)
3834 /* The addend must be CONST_INT, or we would have dealt with it above */
3835 HOST_WIDE_INT hi, lo;
3837 offset += INTVAL (XEXP (base, 1));
3838 base = XEXP (base, 0);
3840 /* Rework the address into a legal sequence of insns */
3841 /* Valid range for lo is -4095 -> 4095 */
3844 : -((-offset) & 0xfff));
3846 /* Corner case, if lo is the max offset then we would be out of range
3847 once we have added the additional 1 below, so bump the msb into the
3848 pre-loading insn(s). */
3852 hi = ((((offset - lo) & (HOST_WIDE_INT) 0xFFFFFFFF)
3853 ^ (HOST_WIDE_INT) 0x80000000)
3854 - (HOST_WIDE_INT) 0x80000000);
3856 if (hi + lo != offset)
3861 rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
3863 /* Be careful not to destroy OUTVAL. */
3864 if (reg_overlap_mentioned_p (base_plus, outval))
3866 /* Updating base_plus might destroy outval, see if we
3867 can swap the scratch and base_plus. */
3868 if (! reg_overlap_mentioned_p (scratch, outval))
3871 scratch = base_plus;
3876 rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2]));
3878 /* Be conservative and copy outval into scratch now,
3879 this should only be necessary if outval is a
3880 subreg of something larger than a word. */
3881 /* XXX Might this clobber base? I can't see how it
3882 can, since scratch is known to overlap with
3884 emit_insn (gen_movhi (scratch_hi, outval));
3885 outval = scratch_hi;
3889 /* Get the base address; addsi3 knows how to handle constants
3890 that require more than one insn */
3891 emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi)));
3897 if (BYTES_BIG_ENDIAN)
3899 emit_insn (gen_movqi (gen_rtx_MEM (QImode,
3900 plus_constant (base, offset + 1)),
3901 gen_rtx_SUBREG (QImode, outval, 0)));
3902 emit_insn (gen_lshrsi3 (scratch,
3903 gen_rtx_SUBREG (SImode, outval, 0),
3905 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)),
3906 gen_rtx_SUBREG (QImode, scratch, 0)));
3910 emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)),
3911 gen_rtx_SUBREG (QImode, outval, 0)));
3912 emit_insn (gen_lshrsi3 (scratch,
3913 gen_rtx_SUBREG (SImode, outval, 0),
3915 emit_insn (gen_movqi (gen_rtx_MEM (QImode,
3916 plus_constant (base, offset + 1)),
3917 gen_rtx_SUBREG (QImode, scratch, 0)));
3921 /* Routines for manipulation of the constant pool. */
3922 /* This is unashamedly hacked from the version in sh.c, since the problem is
3923 extremely similar. */
3925 /* Arm instructions cannot load a large constant into a register,
3926 constants have to come from a pc relative load. The reference of a pc
3927 relative load instruction must be less than 1k infront of the instruction.
3928 This means that we often have to dump a constant inside a function, and
3929 generate code to branch around it.
3931 It is important to minimize this, since the branches will slow things
3932 down and make things bigger.
3934 Worst case code looks like:
3950 We fix this by performing a scan before scheduling, which notices which
3951 instructions need to have their operands fetched from the constant table
3952 and builds the table.
3957 scan, find an instruction which needs a pcrel move. Look forward, find th
3958 last barrier which is within MAX_COUNT bytes of the requirement.
3959 If there isn't one, make one. Process all the instructions between
3960 the find and the barrier.
3962 In the above example, we can tell that L3 is within 1k of L1, so
3963 the first move can be shrunk from the 2 insn+constant sequence into
3964 just 1 insn, and the constant moved to L3 to make:
3975 Then the second move becomes the target for the shortening process.
3981 rtx value; /* Value in table */
3982 HOST_WIDE_INT next_offset;
3983 enum machine_mode mode; /* Mode of value */
3986 /* The maximum number of constants that can fit into one pool, since
3987 the pc relative range is 0...1020 bytes and constants are at least 4
3990 #define MAX_POOL_SIZE (1020/4)
3991 static pool_node pool_vector[MAX_POOL_SIZE];
3992 static int pool_size;
3993 static rtx pool_vector_label;
3995 /* Add a constant to the pool and return its offset within the current
3998 X is the rtx we want to replace. MODE is its mode. On return,
3999 ADDRESS_ONLY will be non-zero if we really want the address of such
4000 a constant, not the constant itself. */
4001 static HOST_WIDE_INT
4002 add_constant (x, mode, address_only)
4004 enum machine_mode mode;
4008 HOST_WIDE_INT offset;
4012 if (mode == SImode && GET_CODE (x) == MEM && CONSTANT_P (XEXP (x, 0))
4013 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
4014 x = get_pool_constant (XEXP (x, 0));
4015 else if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P(x))
4018 mode = get_pool_mode (x);
4019 x = get_pool_constant (x);
4021 #ifndef AOF_ASSEMBLER
4022 else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == 3)
4023 x = XVECEXP (x, 0, 0);
4026 #ifdef AOF_ASSEMBLER
4027 /* PIC Symbol references need to be converted into offsets into the
4029 if (flag_pic && GET_CODE (x) == SYMBOL_REF)
4030 x = aof_pic_entry (x);
4031 #endif /* AOF_ASSEMBLER */
4033 /* First see if we've already got it */
4034 for (i = 0; i < pool_size; i++)
4036 if (GET_CODE (x) == pool_vector[i].value->code
4037 && mode == pool_vector[i].mode)
4039 if (GET_CODE (x) == CODE_LABEL)
4041 if (XINT (x, 3) != XINT (pool_vector[i].value, 3))
4044 if (rtx_equal_p (x, pool_vector[i].value))
4045 return pool_vector[i].next_offset - GET_MODE_SIZE (mode);
4049 /* Need a new one */
4050 pool_vector[pool_size].next_offset = GET_MODE_SIZE (mode);
4053 pool_vector_label = gen_label_rtx ();
4055 pool_vector[pool_size].next_offset
4056 += (offset = pool_vector[pool_size - 1].next_offset);
4058 pool_vector[pool_size].value = x;
4059 pool_vector[pool_size].mode = mode;
4064 /* Output the literal table */
4071 scan = emit_label_after (gen_label_rtx (), scan);
4072 scan = emit_insn_after (gen_align_4 (), scan);
4073 scan = emit_label_after (pool_vector_label, scan);
4075 for (i = 0; i < pool_size; i++)
4077 pool_node * p = pool_vector + i;
4079 switch (GET_MODE_SIZE (p->mode))
4082 scan = emit_insn_after (gen_consttable_4 (p->value), scan);
4086 scan = emit_insn_after (gen_consttable_8 (p->value), scan);
4095 scan = emit_insn_after (gen_consttable_end (), scan);
4096 scan = emit_barrier_after (scan);
4100 /* Non zero if the src operand needs to be fixed up */
4102 fixit (src, mode, destreg)
4104 enum machine_mode mode;
4107 if (CONSTANT_P (src))
4109 if (GET_CODE (src) == CONST_INT)
4110 return (! const_ok_for_arm (INTVAL (src))
4111 && ! const_ok_for_arm (~INTVAL (src)));
4112 if (GET_CODE (src) == CONST_DOUBLE)
4113 return (GET_MODE (src) == VOIDmode
4115 || (! const_double_rtx_ok_for_fpu (src)
4116 && ! neg_const_double_rtx_ok_for_fpu (src)));
4117 return symbol_mentioned_p (src);
4119 #ifndef AOF_ASSEMBLER
4120 else if (GET_CODE (src) == UNSPEC && XINT (src, 1) == 3)
4124 return (mode == SImode && GET_CODE (src) == MEM
4125 && GET_CODE (XEXP (src, 0)) == SYMBOL_REF
4126 && CONSTANT_POOL_ADDRESS_P (XEXP (src, 0)));
4129 /* Find the last barrier less than MAX_COUNT bytes from FROM, or create one. */
4131 find_barrier (from, max_count)
4136 rtx found_barrier = 0;
4139 while (from && count < max_count)
4143 if (GET_CODE (from) == BARRIER)
4144 found_barrier = from;
4146 /* Count the length of this insn */
4147 if (GET_CODE (from) == INSN
4148 && GET_CODE (PATTERN (from)) == SET
4149 && CONSTANT_P (SET_SRC (PATTERN (from)))
4150 && CONSTANT_POOL_ADDRESS_P (SET_SRC (PATTERN (from))))
4152 /* Handle table jumps as a single entity. */
4153 else if (GET_CODE (from) == JUMP_INSN
4154 && JUMP_LABEL (from) != 0
4155 && ((tmp = next_real_insn (JUMP_LABEL (from)))
4156 == next_real_insn (from))
4158 && GET_CODE (tmp) == JUMP_INSN
4159 && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
4160 || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
4162 int elt = GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC ? 1 : 0;
4163 count += (get_attr_length (from)
4164 + GET_MODE_SIZE (SImode) * XVECLEN (PATTERN (tmp), elt));
4165 /* Continue after the dispatch table. */
4167 from = NEXT_INSN (tmp);
4171 count += get_attr_length (from);
4174 from = NEXT_INSN (from);
4177 if (! found_barrier)
4179 /* We didn't find a barrier in time to
4180 dump our stuff, so we'll make one. */
4181 rtx label = gen_label_rtx ();
4184 from = PREV_INSN (last);
4186 from = get_last_insn ();
4188 /* Walk back to be just before any jump. */
4189 while (GET_CODE (from) == JUMP_INSN
4190 || GET_CODE (from) == NOTE
4191 || GET_CODE (from) == CODE_LABEL)
4192 from = PREV_INSN (from);
4194 from = emit_jump_insn_after (gen_jump (label), from);
4195 JUMP_LABEL (from) = label;
4196 found_barrier = emit_barrier_after (from);
4197 emit_label_after (label, found_barrier);
4200 return found_barrier;
4203 /* Non zero if the insn is a move instruction which needs to be fixed. */
4208 if (!INSN_DELETED_P (insn)
4209 && GET_CODE (insn) == INSN
4210 && GET_CODE (PATTERN (insn)) == SET)
4212 rtx pat = PATTERN (insn);
4213 rtx src = SET_SRC (pat);
4214 rtx dst = SET_DEST (pat);
4216 enum machine_mode mode = GET_MODE (dst);
4221 if (GET_CODE (dst) == REG)
4222 destreg = REGNO (dst);
4223 else if (GET_CODE (dst) == SUBREG && GET_CODE (SUBREG_REG (dst)) == REG)
4224 destreg = REGNO (SUBREG_REG (dst));
4228 return fixit (src, mode, destreg);
4241 /* The ldr instruction can work with up to a 4k offset, and most constants
4242 will be loaded with one of these instructions; however, the adr
4243 instruction and the ldf instructions only work with a 1k offset. This
4244 code needs to be rewritten to use the 4k offset when possible, and to
4245 adjust when a 1k offset is needed. For now we just use a 1k offset
4249 /* Floating point operands can't work further than 1024 bytes from the
4250 PC, so to make things simple we restrict all loads for such functions.
4252 if (TARGET_HARD_FLOAT)
4256 for (regno = 16; regno < 24; regno++)
4257 if (regs_ever_live[regno])
4267 for (insn = first; insn; insn = NEXT_INSN (insn))
4269 if (broken_move (insn))
4271 /* This is a broken move instruction, scan ahead looking for
4272 a barrier to stick the constant table behind */
4274 rtx barrier = find_barrier (insn, count_size);
4276 /* Now find all the moves between the points and modify them */
4277 for (scan = insn; scan != barrier; scan = NEXT_INSN (scan))
4279 if (broken_move (scan))
4281 /* This is a broken move instruction, add it to the pool */
4282 rtx pat = PATTERN (scan);
4283 rtx src = SET_SRC (pat);
4284 rtx dst = SET_DEST (pat);
4285 enum machine_mode mode = GET_MODE (dst);
4286 HOST_WIDE_INT offset;
4293 /* If this is an HImode constant load, convert it into
4294 an SImode constant load. Since the register is always
4295 32 bits this is safe. We have to do this, since the
4296 load pc-relative instruction only does a 32-bit load. */
4300 if (GET_CODE (dst) != REG)
4302 PUT_MODE (dst, SImode);
4305 offset = add_constant (src, mode, &address_only);
4306 addr = plus_constant (gen_rtx_LABEL_REF (VOIDmode,
4310 /* If we only want the address of the pool entry, or
4311 for wide moves to integer regs we need to split
4312 the address calculation off into a separate insn.
4313 If necessary, the load can then be done with a
4314 load-multiple. This is safe, since we have
4315 already noted the length of such insns to be 8,
4316 and we are immediately over-writing the scratch
4317 we have grabbed with the final result. */
4318 if ((address_only || GET_MODE_SIZE (mode) > 4)
4319 && (scratch = REGNO (dst)) < 16)
4326 reg = gen_rtx_REG (SImode, scratch);
4328 newinsn = emit_insn_after (gen_movaddr (reg, addr),
4335 newsrc = gen_rtx_MEM (mode, addr);
4337 /* XXX Fixme -- I think the following is bogus. */
4338 /* Build a jump insn wrapper around the move instead
4339 of an ordinary insn, because we want to have room for
4340 the target label rtx in fld[7], which an ordinary
4341 insn doesn't have. */
4343 = emit_jump_insn_after (gen_rtx_SET (VOIDmode, dst,
4346 JUMP_LABEL (newinsn) = pool_vector_label;
4348 /* But it's still an ordinary insn */
4349 PUT_CODE (newinsn, INSN);
4357 dump_table (barrier);
4362 after_arm_reorg = 1;
4366 /* Routines to output assembly language. */
4368 /* If the rtx is the correct value then return the string of the number.
4369 In this way we can ensure that valid double constants are generated even
4370 when cross compiling. */
4372 fp_immediate_constant (x)
4378 if (!fpa_consts_inited)
4381 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
4382 for (i = 0; i < 8; i++)
4383 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
4384 return strings_fpa[i];
4389 /* As for fp_immediate_constant, but value is passed directly, not in rtx. */
4391 fp_const_from_val (r)
4392 REAL_VALUE_TYPE * r;
4396 if (! fpa_consts_inited)
4399 for (i = 0; i < 8; i++)
4400 if (REAL_VALUES_EQUAL (*r, values_fpa[i]))
4401 return strings_fpa[i];
4406 /* Output the operands of a LDM/STM instruction to STREAM.
4407 MASK is the ARM register set mask of which only bits 0-15 are important.
4408 INSTR is the possibly suffixed base register. HAT unequals zero if a hat
4409 must follow the register list. */
4412 print_multi_reg (stream, instr, reg, mask, hat)
4420 int not_first = FALSE;
4422 fputc ('\t', stream);
4423 asm_fprintf (stream, instr, reg);
4424 fputs (", {", stream);
4426 for (i = 0; i < 16; i++)
4427 if (mask & (1 << i))
4430 fprintf (stream, ", ");
4432 asm_fprintf (stream, "%r", i);
4436 fprintf (stream, "}%s\n", hat ? "^" : "");
4439 /* Output a 'call' insn. */
4442 output_call (operands)
4445 /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
4447 if (REGNO (operands[0]) == LR_REGNUM)
4449 operands[0] = gen_rtx_REG (SImode, IP_REGNUM);
4450 output_asm_insn ("mov%?\t%0, %|lr", operands);
4453 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
4455 if (TARGET_INTERWORK)
4456 output_asm_insn ("bx%?\t%0", operands);
4458 output_asm_insn ("mov%?\t%|pc, %0", operands);
4467 int something_changed = 0;
4469 int code = GET_CODE (x0);
4471 register char * fmt;
4476 if (REGNO (x0) == LR_REGNUM)
4478 *x = gen_rtx_REG (SImode, IP_REGNUM);
4483 /* Scan through the sub-elements and change any references there */
4484 fmt = GET_RTX_FORMAT (code);
4486 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4488 something_changed |= eliminate_lr2ip (&XEXP (x0, i));
4489 else if (fmt[i] == 'E')
4490 for (j = 0; j < XVECLEN (x0, i); j++)
4491 something_changed |= eliminate_lr2ip (&XVECEXP (x0, i, j));
4493 return something_changed;
4497 /* Output a 'call' insn that is a reference in memory. */
4500 output_call_mem (operands)
4503 operands[0] = copy_rtx (operands[0]); /* Be ultra careful */
4504 /* Handle calls using lr by using ip (which may be clobbered in subr anyway).
4506 if (eliminate_lr2ip (&operands[0]))
4507 output_asm_insn ("mov%?\t%|ip, %|lr", operands);
4509 if (TARGET_INTERWORK)
4511 output_asm_insn ("ldr%?\t%|ip, %0", operands);
4512 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
4513 output_asm_insn ("bx%?\t%|ip", operands);
4517 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
4518 output_asm_insn ("ldr%?\t%|pc, %0", operands);
4525 /* Output a move from arm registers to an fpu registers.
4526 OPERANDS[0] is an fpu register.
4527 OPERANDS[1] is the first registers of an arm register pair. */
4530 output_mov_long_double_fpu_from_arm (operands)
4533 int arm_reg0 = REGNO (operands[1]);
4536 if (arm_reg0 == IP_REGNUM)
4539 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4540 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4541 ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0);
4543 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops);
4544 output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands);
4549 /* Output a move from an fpu register to arm registers.
4550 OPERANDS[0] is the first registers of an arm register pair.
4551 OPERANDS[1] is an fpu register. */
4554 output_mov_long_double_arm_from_fpu (operands)
4557 int arm_reg0 = REGNO (operands[0]);
4560 if (arm_reg0 == IP_REGNUM)
4563 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4564 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4565 ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0);
4567 output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands);
4568 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops);
4572 /* Output a move from arm registers to arm registers of a long double
4573 OPERANDS[0] is the destination.
4574 OPERANDS[1] is the source. */
4576 output_mov_long_double_arm_from_arm (operands)
4579 /* We have to be careful here because the two might overlap */
4580 int dest_start = REGNO (operands[0]);
4581 int src_start = REGNO (operands[1]);
4585 if (dest_start < src_start)
4587 for (i = 0; i < 3; i++)
4589 ops[0] = gen_rtx_REG (SImode, dest_start + i);
4590 ops[1] = gen_rtx_REG (SImode, src_start + i);
4591 output_asm_insn ("mov%?\t%0, %1", ops);
4596 for (i = 2; i >= 0; i--)
4598 ops[0] = gen_rtx_REG (SImode, dest_start + i);
4599 ops[1] = gen_rtx_REG (SImode, src_start + i);
4600 output_asm_insn ("mov%?\t%0, %1", ops);
4608 /* Output a move from arm registers to an fpu registers.
4609 OPERANDS[0] is an fpu register.
4610 OPERANDS[1] is the first registers of an arm register pair. */
4613 output_mov_double_fpu_from_arm (operands)
4616 int arm_reg0 = REGNO (operands[1]);
4619 if (arm_reg0 == IP_REGNUM)
4622 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4623 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4624 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops);
4625 output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands);
4629 /* Output a move from an fpu register to arm registers.
4630 OPERANDS[0] is the first registers of an arm register pair.
4631 OPERANDS[1] is an fpu register. */
4634 output_mov_double_arm_from_fpu (operands)
4637 int arm_reg0 = REGNO (operands[0]);
4640 if (arm_reg0 == IP_REGNUM)
4643 ops[0] = gen_rtx_REG (SImode, arm_reg0);
4644 ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0);
4645 output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands);
4646 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops);
4650 /* Output a move between double words.
4651 It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM
4652 or MEM<-REG and all MEMs must be offsettable addresses. */
4655 output_move_double (operands)
4658 enum rtx_code code0 = GET_CODE (operands[0]);
4659 enum rtx_code code1 = GET_CODE (operands[1]);
4664 int reg0 = REGNO (operands[0]);
4666 otherops[0] = gen_rtx_REG (SImode, 1 + reg0);
4670 int reg1 = REGNO (operands[1]);
4671 if (reg1 == IP_REGNUM)
4674 /* Ensure the second source is not overwritten */
4675 if (reg1 == reg0 + (WORDS_BIG_ENDIAN ? -1 : 1))
4676 output_asm_insn ("mov%?\t%Q0, %Q1\n\tmov%?\t%R0, %R1", operands);
4678 output_asm_insn ("mov%?\t%R0, %R1\n\tmov%?\t%Q0, %Q1", operands);
4680 else if (code1 == CONST_DOUBLE)
4682 if (GET_MODE (operands[1]) == DFmode)
4685 union real_extract u;
4687 bcopy ((char *) &CONST_DOUBLE_LOW (operands[1]), (char *) &u,
4689 REAL_VALUE_TO_TARGET_DOUBLE (u.d, l);
4690 otherops[1] = GEN_INT(l[1]);
4691 operands[1] = GEN_INT(l[0]);
4693 else if (GET_MODE (operands[1]) != VOIDmode)
4695 else if (WORDS_BIG_ENDIAN)
4698 otherops[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4699 operands[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
4704 otherops[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
4705 operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4708 output_mov_immediate (operands);
4709 output_mov_immediate (otherops);
4711 else if (code1 == CONST_INT)
4713 #if HOST_BITS_PER_WIDE_INT > 32
4714 /* If HOST_WIDE_INT is more than 32 bits, the intval tells us
4715 what the upper word is. */
4716 if (WORDS_BIG_ENDIAN)
4718 otherops[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
4719 operands[1] = GEN_INT (INTVAL (operands[1]) >> 32);
4723 otherops[1] = GEN_INT (INTVAL (operands[1]) >> 32);
4724 operands[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
4727 /* Sign extend the intval into the high-order word */
4728 if (WORDS_BIG_ENDIAN)
4730 otherops[1] = operands[1];
4731 operands[1] = (INTVAL (operands[1]) < 0
4732 ? constm1_rtx : const0_rtx);
4735 otherops[1] = INTVAL (operands[1]) < 0 ? constm1_rtx : const0_rtx;
4737 output_mov_immediate (otherops);
4738 output_mov_immediate (operands);
4740 else if (code1 == MEM)
4742 switch (GET_CODE (XEXP (operands[1], 0)))
4745 output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
4749 abort (); /* Should never happen now */
4753 output_asm_insn ("ldm%?db\t%m1!, %M0", operands);
4757 output_asm_insn ("ldm%?ia\t%m1!, %M0", operands);
4761 abort (); /* Should never happen now */
4766 output_asm_insn ("adr%?\t%0, %1", operands);
4767 output_asm_insn ("ldm%?ia\t%0, %M0", operands);
4771 if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1),
4772 GET_MODE (XEXP (XEXP (operands[1], 0), 1))))
4774 otherops[0] = operands[0];
4775 otherops[1] = XEXP (XEXP (operands[1], 0), 0);
4776 otherops[2] = XEXP (XEXP (operands[1], 0), 1);
4777 if (GET_CODE (XEXP (operands[1], 0)) == PLUS)
4779 if (GET_CODE (otherops[2]) == CONST_INT)
4781 switch (INTVAL (otherops[2]))
4784 output_asm_insn ("ldm%?db\t%1, %M0", otherops);
4787 output_asm_insn ("ldm%?da\t%1, %M0", otherops);
4790 output_asm_insn ("ldm%?ib\t%1, %M0", otherops);
4793 if (!(const_ok_for_arm (INTVAL (otherops[2]))))
4794 output_asm_insn ("sub%?\t%0, %1, #%n2", otherops);
4796 output_asm_insn ("add%?\t%0, %1, %2", otherops);
4799 output_asm_insn ("add%?\t%0, %1, %2", otherops);
4802 output_asm_insn ("sub%?\t%0, %1, %2", otherops);
4804 return "ldm%?ia\t%0, %M0";
4808 otherops[1] = adj_offsettable_operand (operands[1], 4);
4809 /* Take care of overlapping base/data reg. */
4810 if (reg_mentioned_p (operands[0], operands[1]))
4812 output_asm_insn ("ldr%?\t%0, %1", otherops);
4813 output_asm_insn ("ldr%?\t%0, %1", operands);
4817 output_asm_insn ("ldr%?\t%0, %1", operands);
4818 output_asm_insn ("ldr%?\t%0, %1", otherops);
4824 abort (); /* Constraints should prevent this */
4826 else if (code0 == MEM && code1 == REG)
4828 if (REGNO (operands[1]) == IP_REGNUM)
4831 switch (GET_CODE (XEXP (operands[0], 0)))
4834 output_asm_insn ("stm%?ia\t%m0, %M1", operands);
4838 abort (); /* Should never happen now */
4842 output_asm_insn ("stm%?db\t%m0!, %M1", operands);
4846 output_asm_insn ("stm%?ia\t%m0!, %M1", operands);
4850 abort (); /* Should never happen now */
4854 if (GET_CODE (XEXP (XEXP (operands[0], 0), 1)) == CONST_INT)
4856 switch (INTVAL (XEXP (XEXP (operands[0], 0), 1)))
4859 output_asm_insn ("stm%?db\t%m0, %M1", operands);
4863 output_asm_insn ("stm%?da\t%m0, %M1", operands);
4867 output_asm_insn ("stm%?ib\t%m0, %M1", operands);
4874 otherops[0] = adj_offsettable_operand (operands[0], 4);
4875 otherops[1] = gen_rtx_REG (SImode, 1 + REGNO (operands[1]));
4876 output_asm_insn ("str%?\t%1, %0", operands);
4877 output_asm_insn ("str%?\t%1, %0", otherops);
4881 abort (); /* Constraints should prevent this */
4887 /* Output an arbitrary MOV reg, #n.
4888 OPERANDS[0] is a register. OPERANDS[1] is a const_int. */
4891 output_mov_immediate (operands)
4894 HOST_WIDE_INT n = INTVAL (operands[1]);
4898 /* Try to use one MOV */
4899 if (const_ok_for_arm (n))
4901 output_asm_insn ("mov%?\t%0, %1", operands);
4905 /* Try to use one MVN */
4906 if (const_ok_for_arm (~n))
4908 operands[1] = GEN_INT (~n);
4909 output_asm_insn ("mvn%?\t%0, %1", operands);
4913 /* If all else fails, make it out of ORRs or BICs as appropriate. */
4915 for (i=0; i < 32; i++)
4919 if (n_ones > 16) /* Shorter to use MVN with BIC in this case. */
4920 output_multi_immediate(operands, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1,
4923 output_multi_immediate(operands, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1,
4930 /* Output an ADD r, s, #n where n may be too big for one instruction. If
4931 adding zero to one register, output nothing. */
4934 output_add_immediate (operands)
4937 HOST_WIDE_INT n = INTVAL (operands[2]);
4939 if (n != 0 || REGNO (operands[0]) != REGNO (operands[1]))
4942 output_multi_immediate (operands,
4943 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
4946 output_multi_immediate (operands,
4947 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
4954 /* Output a multiple immediate operation.
4955 OPERANDS is the vector of operands referred to in the output patterns.
4956 INSTR1 is the output pattern to use for the first constant.
4957 INSTR2 is the output pattern to use for subsequent constants.
4958 IMMED_OP is the index of the constant slot in OPERANDS.
4959 N is the constant value. */
4962 output_multi_immediate (operands, instr1, instr2, immed_op, n)
4964 char * instr1, * instr2;
4968 #if HOST_BITS_PER_WIDE_INT > 32
4974 operands[immed_op] = const0_rtx;
4975 output_asm_insn (instr1, operands); /* Quick and easy output */
4980 char *instr = instr1;
4982 /* Note that n is never zero here (which would give no output) */
4983 for (i = 0; i < 32; i += 2)
4987 operands[immed_op] = GEN_INT (n & (255 << i));
4988 output_asm_insn (instr, operands);
4998 /* Return the appropriate ARM instruction for the operation code.
4999 The returned result should not be overwritten. OP is the rtx of the
5000 operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator
5004 arithmetic_instr (op, shift_first_arg)
5006 int shift_first_arg;
5008 switch (GET_CODE (op))
5014 return shift_first_arg ? "rsb" : "sub";
5031 /* Ensure valid constant shifts and return the appropriate shift mnemonic
5032 for the operation code. The returned result should not be overwritten.
5033 OP is the rtx code of the shift.
5034 On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
5038 shift_op (op, amountp)
5040 HOST_WIDE_INT *amountp;
5043 enum rtx_code code = GET_CODE (op);
5045 if (GET_CODE (XEXP (op, 1)) == REG || GET_CODE (XEXP (op, 1)) == SUBREG)
5047 else if (GET_CODE (XEXP (op, 1)) == CONST_INT)
5048 *amountp = INTVAL (XEXP (op, 1));
5071 /* We never have to worry about the amount being other than a
5072 power of 2, since this case can never be reloaded from a reg. */
5074 *amountp = int_log2 (*amountp);
5085 /* This is not 100% correct, but follows from the desire to merge
5086 multiplication by a power of 2 with the recognizer for a
5087 shift. >=32 is not a valid shift for "asl", so we must try and
5088 output a shift that produces the correct arithmetical result.
5089 Using lsr #32 is identical except for the fact that the carry bit
5090 is not set correctly if we set the flags; but we never use the
5091 carry bit from such an operation, so we can ignore that. */
5092 if (code == ROTATERT)
5093 *amountp &= 31; /* Rotate is just modulo 32 */
5094 else if (*amountp != (*amountp & 31))
5101 /* Shifts of 0 are no-ops. */
5110 /* Obtain the shift from the POWER of two. */
5112 static HOST_WIDE_INT
5114 HOST_WIDE_INT power;
5116 HOST_WIDE_INT shift = 0;
5118 while (((((HOST_WIDE_INT) 1) << shift) & power) == 0)
5128 /* Output a .ascii pseudo-op, keeping track of lengths. This is because
5129 /bin/as is horribly restrictive. */
5130 #define MAX_ASCII_LEN 51
5133 output_ascii_pseudo_op (stream, p, len)
5141 fputs ("\t.ascii\t\"", stream);
5143 for (i = 0; i < len; i++)
5145 register int c = p[i];
5147 if (len_so_far >= MAX_ASCII_LEN)
5149 fputs ("\"\n\t.ascii\t\"", stream);
5156 fputs ("\\t", stream);
5161 fputs ("\\f", stream);
5166 fputs ("\\b", stream);
5171 fputs ("\\r", stream);
5175 case TARGET_NEWLINE:
5176 fputs ("\\n", stream);
5178 if ((c >= ' ' && c <= '~')
5180 /* This is a good place for a line break. */
5181 len_so_far = MAX_ASCII_LEN;
5188 putc ('\\', stream);
5193 if (c >= ' ' && c <= '~')
5200 fprintf (stream, "\\%03o", c);
5207 fputs ("\"\n", stream);
5211 /* Try to determine whether a pattern really clobbers the link register.
5212 This information is useful when peepholing, so that lr need not be pushed
5213 if we combine a call followed by a return.
5214 NOTE: This code does not check for side-effect expressions in a SET_SRC:
5215 such a check should not be needed because these only update an existing
5216 value within a register; the register must still be set elsewhere within
5220 pattern_really_clobbers_lr (x)
5225 switch (GET_CODE (x))
5228 switch (GET_CODE (SET_DEST (x)))
5231 return REGNO (SET_DEST (x)) == LR_REGNUM;
5234 if (GET_CODE (XEXP (SET_DEST (x), 0)) == REG)
5235 return REGNO (XEXP (SET_DEST (x), 0)) == LR_REGNUM;
5237 if (GET_CODE (XEXP (SET_DEST (x), 0)) == MEM)
5246 for (i = 0; i < XVECLEN (x, 0); i++)
5247 if (pattern_really_clobbers_lr (XVECEXP (x, 0, i)))
5252 switch (GET_CODE (XEXP (x, 0)))
5255 return REGNO (XEXP (x, 0)) == LR_REGNUM;
5258 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG)
5259 return REGNO (XEXP (XEXP (x, 0), 0)) == LR_REGNUM;
5275 function_really_clobbers_lr (first)
5280 for (insn = first; insn; insn = next_nonnote_insn (insn))
5282 switch (GET_CODE (insn))
5287 case JUMP_INSN: /* Jump insns only change the PC (and conds) */
5292 if (pattern_really_clobbers_lr (PATTERN (insn)))
5297 /* Don't yet know how to handle those calls that are not to a
5299 if (GET_CODE (PATTERN (insn)) != PARALLEL)
5302 switch (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)))
5305 if (GET_CODE (XEXP (XEXP (XVECEXP (PATTERN (insn), 0, 0), 0), 0))
5311 if (GET_CODE (XEXP (XEXP (SET_SRC (XVECEXP (PATTERN (insn),
5317 default: /* Don't recognize it, be safe */
5321 /* A call can be made (by peepholing) not to clobber lr iff it is
5322 followed by a return. There may, however, be a use insn iff
5323 we are returning the result of the call.
5324 If we run off the end of the insn chain, then that means the
5325 call was at the end of the function. Unfortunately we don't
5326 have a return insn for the peephole to recognize, so we
5327 must reject this. (Can this be fixed by adding our own insn?) */
5328 if ((next = next_nonnote_insn (insn)) == NULL)
5331 /* No need to worry about lr if the call never returns */
5332 if (GET_CODE (next) == BARRIER)
5335 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == USE
5336 && (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
5337 && (REGNO (SET_DEST (XVECEXP (PATTERN (insn), 0, 0)))
5338 == REGNO (XEXP (PATTERN (next), 0))))
5339 if ((next = next_nonnote_insn (next)) == NULL)
5342 if (GET_CODE (next) == JUMP_INSN
5343 && GET_CODE (PATTERN (next)) == RETURN)
5352 /* We have reached the end of the chain so lr was _not_ clobbered */
5357 output_return_instruction (operand, really_return, reverse)
5363 int reg, live_regs = 0;
5364 int volatile_func = (optimize > 0
5365 && TREE_THIS_VOLATILE (current_function_decl));
5367 return_used_this_function = 1;
5369 if (TARGET_ABORT_NORETURN && volatile_func)
5372 /* If this function was declared non-returning, and we have found a tail
5373 call, then we have to trust that the called function won't return. */
5374 if (! really_return)
5377 /* Otherwise, trap an attempted return by aborting. */
5379 ops[1] = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)"
5381 assemble_external_libcall (ops[1]);
5382 output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops);
5386 if (current_function_calls_alloca && ! really_return)
5389 for (reg = 0; reg <= 10; reg++)
5390 if (regs_ever_live[reg] && ! call_used_regs[reg])
5393 if (flag_pic && ! TARGET_SINGLE_PIC_BASE
5394 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
5397 if (live_regs || (regs_ever_live[LR_REGNUM] && ! lr_save_eliminated))
5400 if (frame_pointer_needed)
5405 if (lr_save_eliminated || ! regs_ever_live[LR_REGNUM])
5408 if (frame_pointer_needed)
5410 reverse ? "ldm%?%D0ea\t%|fp, {" : "ldm%?%d0ea\t%|fp, {");
5413 reverse ? "ldm%?%D0fd\t%|sp!, {" : "ldm%?%d0fd\t%|sp!, {");
5415 for (reg = 0; reg <= 10; reg++)
5416 if (regs_ever_live[reg]
5417 && (! call_used_regs[reg]
5418 || (flag_pic && ! TARGET_SINGLE_PIC_BASE
5419 && reg == PIC_OFFSET_TABLE_REGNUM)))
5421 strcat (instr, "%|");
5422 strcat (instr, reg_names[reg]);
5424 strcat (instr, ", ");
5427 if (frame_pointer_needed)
5429 strcat (instr, "%|");
5430 strcat (instr, reg_names[11]);
5431 strcat (instr, ", ");
5432 strcat (instr, "%|");
5433 strcat (instr, reg_names[13]);
5434 strcat (instr, ", ");
5435 strcat (instr, "%|");
5436 strcat (instr, TARGET_INTERWORK || (! really_return)
5437 ? reg_names[LR_REGNUM] : reg_names[PC_REGNUM] );
5441 strcat (instr, "%|");
5442 if (TARGET_INTERWORK && really_return)
5443 strcat (instr, reg_names[IP_REGNUM]);
5445 strcat (instr, really_return ? reg_names[PC_REGNUM] : reg_names[LR_REGNUM]);
5447 strcat (instr, (TARGET_APCS_32 || !really_return) ? "}" : "}^");
5448 output_asm_insn (instr, &operand);
5450 if (TARGET_INTERWORK && really_return)
5452 strcpy (instr, "bx%?");
5453 strcat (instr, reverse ? "%D0" : "%d0");
5454 strcat (instr, "\t%|");
5455 strcat (instr, frame_pointer_needed ? "lr" : "ip");
5457 output_asm_insn (instr, & operand);
5460 else if (really_return)
5462 if (TARGET_INTERWORK)
5463 sprintf (instr, "bx%%?%%%s0\t%%|lr", reverse ? "D" : "d");
5465 sprintf (instr, "mov%%?%%%s0%s\t%%|pc, %%|lr",
5466 reverse ? "D" : "d", TARGET_APCS_32 ? "" : "s");
5468 output_asm_insn (instr, & operand);
5474 /* Return nonzero if optimizing and the current function is volatile.
5475 Such functions never return, and many memory cycles can be saved
5476 by not storing register values that will never be needed again.
5477 This optimization was added to speed up context switching in a
5478 kernel application. */
5481 arm_volatile_func ()
5483 return (optimize > 0 && TREE_THIS_VOLATILE (current_function_decl));
5486 /* Write the function name into the code section, directly preceding
5487 the function prologue.
5489 Code will be output similar to this:
5491 .ascii "arm_poke_function_name", 0
5494 .word 0xff000000 + (t1 - t0)
5495 arm_poke_function_name
5497 stmfd sp!, {fp, ip, lr, pc}
5500 When performing a stack backtrace, code can inspect the value
5501 of 'pc' stored at 'fp' + 0. If the trace function then looks
5502 at location pc - 12 and the top 8 bits are set, then we know
5503 that there is a function name embedded immediately preceding this
5504 location and has length ((pc[-3]) & 0xff000000).
5506 We assume that pc is declared as a pointer to an unsigned long.
5508 It is of no benefit to output the function name if we are assembling
5509 a leaf function. These function types will not contain a stack
5510 backtrace structure, therefore it is not possible to determine the
5514 arm_poke_function_name (stream, name)
5518 unsigned long alignlength;
5519 unsigned long length;
5522 length = strlen (name);
5523 alignlength = NUM_INTS (length + 1);
5525 ASM_OUTPUT_ASCII (stream, name, length + 1);
5526 ASM_OUTPUT_ALIGN (stream, 2);
5527 x = GEN_INT (0xff000000UL + alignlength);
5528 ASM_OUTPUT_INT (stream, x);
5531 /* The amount of stack adjustment that happens here, in output_return and in
5532 output_epilogue must be exactly the same as was calculated during reload,
5533 or things will point to the wrong place. The only time we can safely
5534 ignore this constraint is when a function has no arguments on the stack,
5535 no stack frame requirement and no live registers execpt for `lr'. If we
5536 can guarantee that by making all function calls into tail calls and that
5537 lr is not clobbered in any other way, then there is no need to push lr
5541 output_func_prologue (f, frame_size)
5545 int reg, live_regs_mask = 0;
5546 int volatile_func = (optimize > 0
5547 && TREE_THIS_VOLATILE (current_function_decl));
5549 /* Nonzero if we must stuff some register arguments onto the stack as if
5550 they were passed there. */
5551 int store_arg_regs = 0;
5553 if (arm_ccfsm_state || arm_target_insn)
5554 abort (); /* Sanity check */
5556 if (arm_naked_function_p (current_function_decl))
5559 return_used_this_function = 0;
5560 lr_save_eliminated = 0;
5562 asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %d\n",
5563 current_function_args_size,
5564 current_function_pretend_args_size, frame_size);
5565 asm_fprintf (f, "\t%@ frame_needed = %d, current_function_anonymous_args = %d\n",
5566 frame_pointer_needed,
5567 current_function_anonymous_args);
5570 asm_fprintf (f, "\t%@ Volatile function.\n");
5572 if (current_function_anonymous_args && current_function_pretend_args_size)
5575 for (reg = 0; reg <= 10; reg++)
5576 if (regs_ever_live[reg] && ! call_used_regs[reg])
5577 live_regs_mask |= (1 << reg);
5579 if (flag_pic && ! TARGET_SINGLE_PIC_BASE
5580 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
5581 live_regs_mask |= (1 << PIC_OFFSET_TABLE_REGNUM);
5583 if (frame_pointer_needed)
5584 live_regs_mask |= 0xD800;
5585 else if (regs_ever_live[LR_REGNUM])
5587 if (! current_function_args_size
5588 && ! function_really_clobbers_lr (get_insns ()))
5589 lr_save_eliminated = 1;
5591 live_regs_mask |= 1 << LR_REGNUM;
5596 /* if a di mode load/store multiple is used, and the base register
5597 is r3, then r4 can become an ever live register without lr
5598 doing so, in this case we need to push lr as well, or we
5599 will fail to get a proper return. */
5601 live_regs_mask |= 1 << LR_REGNUM;
5602 lr_save_eliminated = 0;
5606 if (lr_save_eliminated)
5607 asm_fprintf (f,"\t%@ I don't think this function clobbers lr\n");
5609 #ifdef AOF_ASSEMBLER
5611 asm_fprintf (f, "\tmov\t%r, %r\n", IP_REGNUM, PIC_OFFSET_TABLE_REGNUM);
5617 output_func_epilogue (f, frame_size)
5621 int reg, live_regs_mask = 0;
5622 /* If we need this then it will always be at least this much */
5623 int floats_offset = 12;
5625 int volatile_func = (optimize > 0
5626 && TREE_THIS_VOLATILE (current_function_decl));
5628 if (use_return_insn (FALSE) && return_used_this_function)
5630 if ((frame_size + current_function_outgoing_args_size) != 0
5631 && !(frame_pointer_needed && TARGET_APCS))
5636 /* Naked functions don't have epilogues. */
5637 if (arm_naked_function_p (current_function_decl))
5640 /* A volatile function should never return. Call abort. */
5641 if (TARGET_ABORT_NORETURN && volatile_func)
5644 op = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" : "abort");
5645 assemble_external_libcall (op);
5646 output_asm_insn ("bl\t%a0", &op);
5650 for (reg = 0; reg <= 10; reg++)
5651 if (regs_ever_live[reg] && ! call_used_regs[reg])
5653 live_regs_mask |= (1 << reg);
5657 /* If we aren't loading the PIC register, don't stack it even though it may
5659 if (flag_pic && ! TARGET_SINGLE_PIC_BASE
5660 && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
5662 live_regs_mask |= (1 << PIC_OFFSET_TABLE_REGNUM);
5666 if (frame_pointer_needed)
5668 if (arm_fpu_arch == FP_SOFT2)
5670 for (reg = 23; reg > 15; reg--)
5671 if (regs_ever_live[reg] && ! call_used_regs[reg])
5673 floats_offset += 12;
5674 asm_fprintf (f, "\tldfe\t%r, [%r, #-%d]\n",
5675 reg, FP_REGNUM, floats_offset);
5682 for (reg = 23; reg > 15; reg--)
5684 if (regs_ever_live[reg] && ! call_used_regs[reg])
5686 floats_offset += 12;
5688 /* We can't unstack more than four registers at once */
5689 if (start_reg - reg == 3)
5691 asm_fprintf (f, "\tlfm\t%r, 4, [%r, #-%d]\n",
5692 reg, FP_REGNUM, floats_offset);
5693 start_reg = reg - 1;
5698 if (reg != start_reg)
5699 asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n",
5700 reg + 1, start_reg - reg,
5701 FP_REGNUM, floats_offset);
5702 start_reg = reg - 1;
5706 /* Just in case the last register checked also needs unstacking. */
5707 if (reg != start_reg)
5708 asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n",
5709 reg + 1, start_reg - reg,
5710 FP_REGNUM, floats_offset);
5713 if (TARGET_INTERWORK)
5715 live_regs_mask |= 0x6800;
5716 print_multi_reg (f, "ldmea\t%r", FP_REGNUM, live_regs_mask, FALSE);
5717 asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM);
5721 live_regs_mask |= 0xA800;
5722 print_multi_reg (f, "ldmea\t%r", FP_REGNUM, live_regs_mask,
5723 TARGET_APCS_32 ? FALSE : TRUE);
5728 /* Restore stack pointer if necessary. */
5729 if (frame_size + current_function_outgoing_args_size != 0)
5731 operands[0] = operands[1] = stack_pointer_rtx;
5732 operands[2] = GEN_INT (frame_size
5733 + current_function_outgoing_args_size);
5734 output_add_immediate (operands);
5737 if (arm_fpu_arch == FP_SOFT2)
5739 for (reg = 16; reg < 24; reg++)
5740 if (regs_ever_live[reg] && ! call_used_regs[reg])
5741 asm_fprintf (f, "\tldfe\t%r, [%r], #12\n",
5748 for (reg = 16; reg < 24; reg++)
5750 if (regs_ever_live[reg] && ! call_used_regs[reg])
5752 if (reg - start_reg == 3)
5754 asm_fprintf (f, "\tlfmfd\t%r, 4, [%r]!\n",
5755 start_reg, SP_REGNUM);
5756 start_reg = reg + 1;
5761 if (reg != start_reg)
5762 asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n",
5763 start_reg, reg - start_reg,
5766 start_reg = reg + 1;
5770 /* Just in case the last register checked also needs unstacking. */
5771 if (reg != start_reg)
5772 asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n",
5773 start_reg, reg - start_reg, SP_REGNUM);
5776 if (current_function_pretend_args_size == 0 && regs_ever_live[LR_REGNUM])
5778 if (TARGET_INTERWORK)
5780 if (! lr_save_eliminated)
5781 live_regs_mask |= 1 << LR_REGNUM;
5783 if (live_regs_mask != 0)
5784 print_multi_reg (f, "ldmfd\t%r!", SP_REGNUM, live_regs_mask, FALSE);
5786 asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM);
5788 else if (lr_save_eliminated)
5789 asm_fprintf (f, "\tmov%c\t%r, %r\n",
5790 TARGET_APCS_32 ? ' ' : 's',
5791 PC_REGNUM, LR_REGNUM);
5793 print_multi_reg (f, "ldmfd\t%r!", SP_REGNUM, live_regs_mask | 0x8000,
5794 TARGET_APCS_32 ? FALSE : TRUE);
5798 if (live_regs_mask || regs_ever_live[LR_REGNUM])
5800 /* Restore the integer regs, and the return address into lr */
5801 if (! lr_save_eliminated)
5802 live_regs_mask |= 1 << LR_REGNUM;
5804 if (live_regs_mask != 0)
5805 print_multi_reg (f, "ldmfd\t%r!", SP_REGNUM, live_regs_mask, FALSE);
5808 if (current_function_pretend_args_size)
5810 /* Unwind the pre-pushed regs */
5811 operands[0] = operands[1] = stack_pointer_rtx;
5812 operands[2] = GEN_INT (current_function_pretend_args_size);
5813 output_add_immediate (operands);
5815 /* And finally, go home */
5816 if (TARGET_INTERWORK)
5817 asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM);
5818 else if (TARGET_APCS_32)
5819 asm_fprintf (f, "\tmov\t%r, %r\n", PC_REGNUM, LR_REGNUM);
5821 asm_fprintf (f, "\tmovs\t%r, %r\n", PC_REGNUM, LR_REGNUM);
5827 /* Reset the ARM-specific per-function variables. */
5828 current_function_anonymous_args = 0;
5829 after_arm_reorg = 0;
5833 emit_multi_reg_push (mask)
5840 for (i = 0; i < 16; i++)
5841 if (mask & (1 << i))
5844 if (num_regs == 0 || num_regs > 16)
5847 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs));
5849 for (i = 0; i < 16; i++)
5851 if (mask & (1 << i))
5854 = gen_rtx_SET (VOIDmode,
5855 gen_rtx_MEM (BLKmode,
5856 gen_rtx_PRE_DEC (BLKmode,
5857 stack_pointer_rtx)),
5858 gen_rtx_UNSPEC (BLKmode,
5860 gen_rtx_REG (SImode, i)),
5866 for (j = 1, i++; j < num_regs; i++)
5868 if (mask & (1 << i))
5871 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, i));
5880 emit_sfm (base_reg, count)
5887 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
5890 = gen_rtx_SET (VOIDmode,
5891 gen_rtx_MEM (BLKmode,
5892 gen_rtx_PRE_DEC (BLKmode, stack_pointer_rtx)),
5893 gen_rtx_UNSPEC (BLKmode,
5894 gen_rtvec (1, gen_rtx_REG (XFmode,
5897 for (i = 1; i < count; i++)
5898 XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode,
5899 gen_rtx_REG (XFmode, base_reg++));
5905 arm_expand_prologue ()
5908 rtx amount = GEN_INT (-(get_frame_size ()
5909 + current_function_outgoing_args_size));
5910 int live_regs_mask = 0;
5911 int store_arg_regs = 0;
5912 int volatile_func = (optimize > 0
5913 && TREE_THIS_VOLATILE (current_function_decl));
5915 /* Naked functions don't have prologues. */
5916 if (arm_naked_function_p (current_function_decl))
5919 if (current_function_anonymous_args && current_function_pretend_args_size)
5922 if (! volatile_func)
5924 for (reg = 0; reg <= 10; reg++)
5925 if (regs_ever_live[reg] && ! call_used_regs[reg])
5926 live_regs_mask |= 1 << reg;
5928 if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
5929 live_regs_mask |= 1 << PIC_OFFSET_TABLE_REGNUM;
5931 if (regs_ever_live[LR_REGNUM])
5932 live_regs_mask |= 1 << LR_REGNUM;
5935 if (frame_pointer_needed)
5937 live_regs_mask |= 0xD800;
5938 emit_insn (gen_movsi (gen_rtx_REG (SImode, IP_REGNUM),
5939 stack_pointer_rtx));
5942 if (current_function_pretend_args_size)
5945 emit_multi_reg_push ((0xf0 >> (current_function_pretend_args_size / 4))
5948 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
5949 GEN_INT (-current_function_pretend_args_size)));
5954 /* If we have to push any regs, then we must push lr as well, or
5955 we won't get a proper return. */
5956 live_regs_mask |= 1 << LR_REGNUM;
5957 emit_multi_reg_push (live_regs_mask);
5960 /* For now the integer regs are still pushed in output_func_epilogue (). */
5962 if (! volatile_func)
5964 if (arm_fpu_arch == FP_SOFT2)
5966 for (reg = 23; reg > 15; reg--)
5967 if (regs_ever_live[reg] && ! call_used_regs[reg])
5968 emit_insn (gen_rtx_SET
5970 gen_rtx_MEM (XFmode,
5971 gen_rtx_PRE_DEC (XFmode,
5972 stack_pointer_rtx)),
5973 gen_rtx_REG (XFmode, reg)));
5979 for (reg = 23; reg > 15; reg--)
5981 if (regs_ever_live[reg] && ! call_used_regs[reg])
5983 if (start_reg - reg == 3)
5986 start_reg = reg - 1;
5991 if (start_reg != reg)
5992 emit_sfm (reg + 1, start_reg - reg);
5993 start_reg = reg - 1;
5997 if (start_reg != reg)
5998 emit_sfm (reg + 1, start_reg - reg);
6002 if (frame_pointer_needed)
6003 emit_insn (gen_addsi3 (hard_frame_pointer_rtx, gen_rtx_REG (SImode, IP_REGNUM),
6005 (-(4 + current_function_pretend_args_size)))));
6007 if (amount != const0_rtx)
6009 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, amount));
6010 emit_insn (gen_rtx_CLOBBER (VOIDmode,
6011 gen_rtx_MEM (BLKmode, stack_pointer_rtx)));
6014 /* If we are profiling, make sure no instructions are scheduled before
6015 the call to mcount. Similarly if the user has requested no
6016 scheduling in the prolog. */
6017 if (profile_flag || profile_block_flag || TARGET_NO_SCHED_PRO)
6018 emit_insn (gen_blockage ());
6022 /* If CODE is 'd', then the X is a condition operand and the instruction
6023 should only be executed if the condition is true.
6024 if CODE is 'D', then the X is a condition operand and the instruction
6025 should only be executed if the condition is false: however, if the mode
6026 of the comparison is CCFPEmode, then always execute the instruction -- we
6027 do this because in these circumstances !GE does not necessarily imply LT;
6028 in these cases the instruction pattern will take care to make sure that
6029 an instruction containing %d will follow, thereby undoing the effects of
6030 doing this instruction unconditionally.
6031 If CODE is 'N' then X is a floating point operand that must be negated
6033 If CODE is 'B' then output a bitwise inverted value of X (a const int).
6034 If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */
6037 arm_print_operand (stream, x, code)
6045 fputs (ASM_COMMENT_START, stream);
6049 fputs (REGISTER_PREFIX, stream);
6053 if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4)
6054 fputs (arm_condition_codes[arm_current_cc], stream);
6060 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
6061 r = REAL_VALUE_NEGATE (r);
6062 fprintf (stream, "%s", fp_const_from_val (&r));
6067 if (GET_CODE (x) == CONST_INT)
6070 val = ARM_SIGN_EXTEND (~ INTVAL (x));
6071 fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val);
6076 output_addr_const (stream, x);
6081 fprintf (stream, "%s", arithmetic_instr (x, 1));
6085 fprintf (stream, "%s", arithmetic_instr (x, 0));
6091 char * shift = shift_op (x, & val);
6095 fprintf (stream, ", %s ", shift_op (x, & val));
6097 arm_print_operand (stream, XEXP (x, 1), 0);
6100 fputc ('#', stream);
6101 fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val);
6110 fputs (REGISTER_PREFIX, stream);
6111 fputs (reg_names[REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)], stream);
6117 fputs (REGISTER_PREFIX, stream);
6118 fputs (reg_names[REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)], stream);
6122 fputs (REGISTER_PREFIX, stream);
6123 if (GET_CODE (XEXP (x, 0)) == REG)
6124 fputs (reg_names[REGNO (XEXP (x, 0))], stream);
6126 fputs (reg_names[REGNO (XEXP (XEXP (x, 0), 0))], stream);
6130 asm_fprintf (stream, "{%r-%r}",
6131 REGNO (x), REGNO (x) + NUM_REGS (GET_MODE (x)) - 1);
6136 fputs (arm_condition_codes[get_arm_condition_code (x)],
6142 fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE
6143 (get_arm_condition_code (x))],
6151 if (GET_CODE (x) == REG)
6153 fputs (REGISTER_PREFIX, stream);
6154 fputs (reg_names[REGNO (x)], stream);
6156 else if (GET_CODE (x) == MEM)
6158 output_memory_reference_mode = GET_MODE (x);
6159 output_address (XEXP (x, 0));
6161 else if (GET_CODE (x) == CONST_DOUBLE)
6162 fprintf (stream, "#%s", fp_immediate_constant (x));
6163 else if (GET_CODE (x) == NEG)
6164 abort (); /* This should never happen now. */
6167 fputc ('#', stream);
6168 output_addr_const (stream, x);
6173 /* A finite state machine takes care of noticing whether or not instructions
6174 can be conditionally executed, and thus decrease execution time and code
6175 size by deleting branch instructions. The fsm is controlled by
6176 final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */
6178 /* The state of the fsm controlling condition codes are:
6179 0: normal, do nothing special
6180 1: make ASM_OUTPUT_OPCODE not output this instruction
6181 2: make ASM_OUTPUT_OPCODE not output this instruction
6182 3: make instructions conditional
6183 4: make instructions conditional
6185 State transitions (state->state by whom under condition):
6186 0 -> 1 final_prescan_insn if the `target' is a label
6187 0 -> 2 final_prescan_insn if the `target' is an unconditional branch
6188 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
6189 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
6190 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL if the `target' label is reached
6191 (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
6192 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
6193 (the target insn is arm_target_insn).
6195 If the jump clobbers the conditions then we use states 2 and 4.
6197 A similar thing can be done with conditional return insns.
6199 XXX In case the `target' is an unconditional branch, this conditionalising
6200 of the instructions always reduces code size, but not always execution
6201 time. But then, I want to reduce the code size to somewhere near what
6202 /bin/cc produces. */
6204 /* Returns the index of the ARM condition code string in
6205 `arm_condition_codes'. COMPARISON should be an rtx like
6206 `(eq (...) (...))'. */
6208 static enum arm_cond_code
6209 get_arm_condition_code (comparison)
6212 enum machine_mode mode = GET_MODE (XEXP (comparison, 0));
6214 register enum rtx_code comp_code = GET_CODE (comparison);
6216 if (GET_MODE_CLASS (mode) != MODE_CC)
6217 mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0),
6218 XEXP (comparison, 1));
6222 case CC_DNEmode: code = ARM_NE; goto dominance;
6223 case CC_DEQmode: code = ARM_EQ; goto dominance;
6224 case CC_DGEmode: code = ARM_GE; goto dominance;
6225 case CC_DGTmode: code = ARM_GT; goto dominance;
6226 case CC_DLEmode: code = ARM_LE; goto dominance;
6227 case CC_DLTmode: code = ARM_LT; goto dominance;
6228 case CC_DGEUmode: code = ARM_CS; goto dominance;
6229 case CC_DGTUmode: code = ARM_HI; goto dominance;
6230 case CC_DLEUmode: code = ARM_LS; goto dominance;
6231 case CC_DLTUmode: code = ARM_CC;
6234 if (comp_code != EQ && comp_code != NE)
6237 if (comp_code == EQ)
6238 return ARM_INVERSE_CONDITION_CODE (code);
6244 case NE: return ARM_NE;
6245 case EQ: return ARM_EQ;
6246 case GE: return ARM_PL;
6247 case LT: return ARM_MI;
6255 case NE: return ARM_NE;
6256 case EQ: return ARM_EQ;
6263 case GE: return ARM_GE;
6264 case GT: return ARM_GT;
6265 case LE: return ARM_LS;
6266 case LT: return ARM_MI;
6273 case NE: return ARM_NE;
6274 case EQ: return ARM_EQ;
6275 case GE: return ARM_LE;
6276 case GT: return ARM_LT;
6277 case LE: return ARM_GE;
6278 case LT: return ARM_GT;
6279 case GEU: return ARM_LS;
6280 case GTU: return ARM_CC;
6281 case LEU: return ARM_CS;
6282 case LTU: return ARM_HI;
6289 case LTU: return ARM_CS;
6290 case GEU: return ARM_CC;
6297 case NE: return ARM_NE;
6298 case EQ: return ARM_EQ;
6299 case GE: return ARM_GE;
6300 case GT: return ARM_GT;
6301 case LE: return ARM_LE;
6302 case LT: return ARM_LT;
6303 case GEU: return ARM_CS;
6304 case GTU: return ARM_HI;
6305 case LEU: return ARM_LS;
6306 case LTU: return ARM_CC;
6318 arm_final_prescan_insn (insn)
6321 /* BODY will hold the body of INSN. */
6322 register rtx body = PATTERN (insn);
6324 /* This will be 1 if trying to repeat the trick, and things need to be
6325 reversed if it appears to fail. */
6328 /* JUMP_CLOBBERS will be one implies that the conditions if a branch is
6329 taken are clobbered, even if the rtl suggests otherwise. It also
6330 means that we have to grub around within the jump expression to find
6331 out what the conditions are when the jump isn't taken. */
6332 int jump_clobbers = 0;
6334 /* If we start with a return insn, we only succeed if we find another one. */
6335 int seeking_return = 0;
6337 /* START_INSN will hold the insn from where we start looking. This is the
6338 first insn after the following code_label if REVERSE is true. */
6339 rtx start_insn = insn;
6341 /* If in state 4, check if the target branch is reached, in order to
6342 change back to state 0. */
6343 if (arm_ccfsm_state == 4)
6345 if (insn == arm_target_insn)
6347 arm_target_insn = NULL;
6348 arm_ccfsm_state = 0;
6353 /* If in state 3, it is possible to repeat the trick, if this insn is an
6354 unconditional branch to a label, and immediately following this branch
6355 is the previous target label which is only used once, and the label this
6356 branch jumps to is not too far off. */
6357 if (arm_ccfsm_state == 3)
6359 if (simplejump_p (insn))
6361 start_insn = next_nonnote_insn (start_insn);
6362 if (GET_CODE (start_insn) == BARRIER)
6364 /* XXX Isn't this always a barrier? */
6365 start_insn = next_nonnote_insn (start_insn);
6367 if (GET_CODE (start_insn) == CODE_LABEL
6368 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
6369 && LABEL_NUSES (start_insn) == 1)
6374 else if (GET_CODE (body) == RETURN)
6376 start_insn = next_nonnote_insn (start_insn);
6377 if (GET_CODE (start_insn) == BARRIER)
6378 start_insn = next_nonnote_insn (start_insn);
6379 if (GET_CODE (start_insn) == CODE_LABEL
6380 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
6381 && LABEL_NUSES (start_insn) == 1)
6393 if (arm_ccfsm_state != 0 && !reverse)
6395 if (GET_CODE (insn) != JUMP_INSN)
6398 /* This jump might be paralleled with a clobber of the condition codes
6399 the jump should always come first */
6400 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0)
6401 body = XVECEXP (body, 0, 0);
6404 /* If this is a conditional return then we don't want to know */
6405 if (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
6406 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
6407 && (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN
6408 || GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN))
6413 || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
6414 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE))
6417 int fail = FALSE, succeed = FALSE;
6418 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
6419 int then_not_else = TRUE;
6420 rtx this_insn = start_insn, label = 0;
6422 if (get_attr_conds (insn) == CONDS_JUMP_CLOB)
6424 /* The code below is wrong for these, and I haven't time to
6425 fix it now. So we just do the safe thing and return. This
6426 whole function needs re-writing anyway. */
6431 /* Register the insn jumped to. */
6434 if (!seeking_return)
6435 label = XEXP (SET_SRC (body), 0);
6437 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF)
6438 label = XEXP (XEXP (SET_SRC (body), 1), 0);
6439 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF)
6441 label = XEXP (XEXP (SET_SRC (body), 2), 0);
6442 then_not_else = FALSE;
6444 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN)
6446 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN)
6449 then_not_else = FALSE;
6454 /* See how many insns this branch skips, and what kind of insns. If all
6455 insns are okay, and the label or unconditional branch to the same
6456 label is not too far away, succeed. */
6457 for (insns_skipped = 0;
6458 !fail && !succeed && insns_skipped++ < max_insns_skipped;)
6462 this_insn = next_nonnote_insn (this_insn);
6466 switch (GET_CODE (this_insn))
6469 /* Succeed if it is the target label, otherwise fail since
6470 control falls in from somewhere else. */
6471 if (this_insn == label)
6475 arm_ccfsm_state = 2;
6476 this_insn = next_nonnote_insn (this_insn);
6479 arm_ccfsm_state = 1;
6487 /* Succeed if the following insn is the target label.
6489 If return insns are used then the last insn in a function
6490 will be a barrier. */
6491 this_insn = next_nonnote_insn (this_insn);
6492 if (this_insn && this_insn == label)
6496 arm_ccfsm_state = 2;
6497 this_insn = next_nonnote_insn (this_insn);
6500 arm_ccfsm_state = 1;
6508 /* If using 32-bit addresses the cc is not preserved over
6512 /* Succeed if the following insn is the target label,
6513 or if the following two insns are a barrier and
6514 the target label. */
6515 this_insn = next_nonnote_insn (this_insn);
6516 if (this_insn && GET_CODE (this_insn) == BARRIER)
6517 this_insn = next_nonnote_insn (this_insn);
6519 if (this_insn && this_insn == label
6520 && insns_skipped < max_insns_skipped)
6524 arm_ccfsm_state = 2;
6525 this_insn = next_nonnote_insn (this_insn);
6528 arm_ccfsm_state = 1;
6537 /* If this is an unconditional branch to the same label, succeed.
6538 If it is to another label, do nothing. If it is conditional,
6540 /* XXX Probably, the tests for SET and the PC are unnecessary. */
6542 scanbody = PATTERN (this_insn);
6543 if (GET_CODE (scanbody) == SET
6544 && GET_CODE (SET_DEST (scanbody)) == PC)
6546 if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF
6547 && XEXP (SET_SRC (scanbody), 0) == label && !reverse)
6549 arm_ccfsm_state = 2;
6552 else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE)
6555 /* Fail if a conditional return is undesirable (eg on a
6556 StrongARM), but still allow this if optimizing for size. */
6557 else if (GET_CODE (scanbody) == RETURN
6558 && ! use_return_insn (TRUE)
6561 else if (GET_CODE (scanbody) == RETURN
6564 arm_ccfsm_state = 2;
6567 else if (GET_CODE (scanbody) == PARALLEL)
6569 switch (get_attr_conds (this_insn))
6581 /* Instructions using or affecting the condition codes make it
6583 scanbody = PATTERN (this_insn);
6584 if (! (GET_CODE (scanbody) == SET
6585 || GET_CODE (scanbody) == PARALLEL)
6586 || get_attr_conds (this_insn) != CONDS_NOCOND)
6596 if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse))
6597 arm_target_label = CODE_LABEL_NUMBER (label);
6598 else if (seeking_return || arm_ccfsm_state == 2)
6600 while (this_insn && GET_CODE (PATTERN (this_insn)) == USE)
6602 this_insn = next_nonnote_insn (this_insn);
6603 if (this_insn && (GET_CODE (this_insn) == BARRIER
6604 || GET_CODE (this_insn) == CODE_LABEL))
6609 /* Oh, dear! we ran off the end.. give up */
6610 recog (PATTERN (insn), insn, NULL_PTR);
6611 arm_ccfsm_state = 0;
6612 arm_target_insn = NULL;
6615 arm_target_insn = this_insn;
6624 get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body),
6626 if (GET_CODE (XEXP (XEXP (SET_SRC (body), 0), 0)) == AND)
6627 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
6628 if (GET_CODE (XEXP (SET_SRC (body), 0)) == NE)
6629 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
6633 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
6636 arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body),
6640 if (reverse || then_not_else)
6641 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
6643 /* restore recog_operand (getting the attributes of other insns can
6644 destroy this array, but final.c assumes that it remains intact
6645 across this call; since the insn has been recognized already we
6646 call recog direct). */
6647 recog (PATTERN (insn), insn, NULL_PTR);
6651 #ifdef AOF_ASSEMBLER
6652 /* Special functions only needed when producing AOF syntax assembler. */
6654 rtx aof_pic_label = NULL_RTX;
6657 struct pic_chain * next;
6661 static struct pic_chain * aof_pic_chain = NULL;
6667 struct pic_chain ** chainp;
6670 if (aof_pic_label == NULL_RTX)
6672 /* This needs to persist throughout the compilation. */
6673 end_temporary_allocation ();
6674 aof_pic_label = gen_rtx_SYMBOL_REF (Pmode, "x$adcons");
6675 resume_temporary_allocation ();
6678 for (offset = 0, chainp = &aof_pic_chain; *chainp;
6679 offset += 4, chainp = &(*chainp)->next)
6680 if ((*chainp)->symname == XSTR (x, 0))
6681 return plus_constant (aof_pic_label, offset);
6683 *chainp = (struct pic_chain *) xmalloc (sizeof (struct pic_chain));
6684 (*chainp)->next = NULL;
6685 (*chainp)->symname = XSTR (x, 0);
6686 return plus_constant (aof_pic_label, offset);
6690 aof_dump_pic_table (f)
6693 struct pic_chain * chain;
6695 if (aof_pic_chain == NULL)
6698 asm_fprintf (f, "\tAREA |%r$$adcons|, BASED %r\n",
6699 PIC_OFFSET_TABLE_REGNUM,
6700 PIC_OFFSET_TABLE_REGNUM);
6701 fputs ("|x$adcons|\n", f);
6703 for (chain = aof_pic_chain; chain; chain = chain->next)
6705 fputs ("\tDCD\t", f);
6706 assemble_name (f, chain->symname);
6711 int arm_text_section_count = 1;
6716 static char buf[100];
6717 sprintf (buf, "\tAREA |C$$code%d|, CODE, READONLY",
6718 arm_text_section_count++);
6720 strcat (buf, ", PIC, REENTRANT");
6724 static int arm_data_section_count = 1;
6729 static char buf[100];
6730 sprintf (buf, "\tAREA |C$$data%d|, DATA", arm_data_section_count++);
6734 /* The AOF assembler is religiously strict about declarations of
6735 imported and exported symbols, so that it is impossible to declare
6736 a function as imported near the beginning of the file, and then to
6737 export it later on. It is, however, possible to delay the decision
6738 until all the functions in the file have been compiled. To get
6739 around this, we maintain a list of the imports and exports, and
6740 delete from it any that are subsequently defined. At the end of
6741 compilation we spit the remainder of the list out before the END
6746 struct import * next;
6750 static struct import * imports_list = NULL;
6753 aof_add_import (name)
6756 struct import * new;
6758 for (new = imports_list; new; new = new->next)
6759 if (new->name == name)
6762 new = (struct import *) xmalloc (sizeof (struct import));
6763 new->next = imports_list;
6769 aof_delete_import (name)
6772 struct import ** old;
6774 for (old = &imports_list; *old; old = & (*old)->next)
6776 if ((*old)->name == name)
6778 *old = (*old)->next;
6784 int arm_main_function = 0;
6787 aof_dump_imports (f)
6790 /* The AOF assembler needs this to cause the startup code to be extracted
6791 from the library. Brining in __main causes the whole thing to work
6793 if (arm_main_function)
6796 fputs ("\tIMPORT __main\n", f);
6797 fputs ("\tDCD __main\n", f);
6800 /* Now dump the remaining imports. */
6801 while (imports_list)
6803 fprintf (f, "\tIMPORT\t");
6804 assemble_name (f, imports_list->name);
6806 imports_list = imports_list->next;
6809 #endif /* AOF_ASSEMBLER */