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"
41 /* The maximum number of insns skipped which will be conditionalised if
43 static int max_insns_skipped
= 5;
45 extern FILE * asm_out_file
;
46 /* Some function declarations. */
48 static HOST_WIDE_INT int_log2
PROTO ((HOST_WIDE_INT
));
49 static char *output_multi_immediate
PROTO ((rtx
*, char *, char *, int,
51 static int arm_gen_constant
PROTO ((enum rtx_code
, enum machine_mode
,
52 HOST_WIDE_INT
, rtx
, rtx
, int, int));
53 static int arm_naked_function_p
PROTO ((tree
));
54 static void init_fpa_table
PROTO ((void));
55 static enum machine_mode select_dominance_cc_mode
PROTO ((enum rtx_code
, rtx
,
57 static HOST_WIDE_INT add_constant
PROTO ((rtx
, enum machine_mode
, int *));
58 static void dump_table
PROTO ((rtx
));
59 static int fixit
PROTO ((rtx
, enum machine_mode
, int));
60 static rtx find_barrier
PROTO ((rtx
, int));
61 static int broken_move
PROTO ((rtx
));
62 static char *fp_const_from_val
PROTO ((REAL_VALUE_TYPE
*));
63 static int eliminate_lr2ip
PROTO ((rtx
*));
64 static char *shift_op
PROTO ((rtx
, HOST_WIDE_INT
*));
65 static int pattern_really_clobbers_lr
PROTO ((rtx
));
66 static int function_really_clobbers_lr
PROTO ((rtx
));
67 static void emit_multi_reg_push
PROTO ((int));
68 static void emit_sfm
PROTO ((int, int));
69 static enum arm_cond_code get_arm_condition_code
PROTO ((rtx
));
71 /* Define the information needed to generate branch insns. This is
72 stored from the compare operation. */
74 rtx arm_compare_op0
, arm_compare_op1
;
77 /* What type of floating point are we tuning for? */
78 enum floating_point_type arm_fpu
;
80 /* What type of floating point instructions are available? */
81 enum floating_point_type arm_fpu_arch
;
83 /* What program mode is the cpu running in? 26-bit mode or 32-bit mode */
84 enum prog_mode_type arm_prgmode
;
86 /* Set by the -mfp=... option */
87 char * target_fp_name
= NULL
;
89 /* Used to parse -mstructure_size_boundary command line option. */
90 char * structure_size_string
= NULL
;
91 int arm_structure_size_boundary
= 32; /* Used to be 8 */
93 /* Nonzero if this is an "M" variant of the processor. */
94 int arm_fast_multiply
= 0;
96 /* Nonzero if this chip supports the ARM Architecture 4 extensions */
99 /* Nonzero if this chip can benefit from laod scheduling. */
100 int arm_ld_sched
= 0;
102 /* Nonzero if this chip is a StrongARM. */
103 int arm_is_strong
= 0;
105 /* Nonzero if this chip is a an ARM6 or an ARM7. */
106 int arm_is_6_or_7
= 0;
108 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
109 must report the mode of the memory reference from PRINT_OPERAND to
110 PRINT_OPERAND_ADDRESS. */
111 enum machine_mode output_memory_reference_mode
;
113 /* Nonzero if the prologue must setup `fp'. */
114 int current_function_anonymous_args
;
116 /* The register number to be used for the PIC offset register. */
117 int arm_pic_register
= 9;
119 /* Location counter of .text segment. */
120 int arm_text_location
= 0;
122 /* Set to one if we think that lr is only saved because of subroutine calls,
123 but all of these can be `put after' return insns */
124 int lr_save_eliminated
;
126 /* Set to 1 when a return insn is output, this means that the epilogue
129 static int return_used_this_function
;
131 static int after_arm_reorg
= 0;
133 static int arm_constant_limit
= 3;
135 /* For an explanation of these variables, see final_prescan_insn below. */
137 enum arm_cond_code arm_current_cc
;
139 int arm_target_label
;
141 /* The condition codes of the ARM, and the inverse function. */
142 char * arm_condition_codes
[] =
144 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
145 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
148 static enum arm_cond_code
get_arm_condition_code ();
150 #define streq(string1, string2) (strcmp (string1, string2) == 0)
152 /* Initialization code */
154 #define FL_CO_PROC 0x01 /* Has external co-processor bus */
155 #define FL_FAST_MULT 0x02 /* Fast multiply */
156 #define FL_MODE26 0x04 /* 26-bit mode support */
157 #define FL_MODE32 0x08 /* 32-bit mode support */
158 #define FL_ARCH4 0x10 /* Architecture rel 4 */
159 #define FL_THUMB 0x20 /* Thumb aware */
160 #define FL_LDSCHED 0x40 /* Load scheduling necessary */
161 #define FL_STRONG 0x80 /* StrongARM */
169 /* Not all of these give usefully different compilation alternatives,
170 but there is no simple way of generalizing them. */
171 static struct processors all_cores
[] =
175 {"arm2", FL_CO_PROC
| FL_MODE26
},
176 {"arm250", FL_CO_PROC
| FL_MODE26
},
177 {"arm3", FL_CO_PROC
| FL_MODE26
},
178 {"arm6", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
179 {"arm60", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
180 {"arm600", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
181 {"arm610", FL_MODE26
| FL_MODE32
},
182 {"arm620", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
183 {"arm7", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
184 {"arm7m", FL_CO_PROC
| FL_MODE26
| FL_MODE32
| FL_FAST_MULT
}, /* arm7m doesn't exist on its own, */
185 {"arm7d", FL_CO_PROC
| FL_MODE26
| FL_MODE32
}, /* but only with D, (and I), */
186 {"arm7dm", FL_CO_PROC
| FL_MODE26
| FL_MODE32
| FL_FAST_MULT
}, /* but those don't alter the code, */
187 {"arm7di", FL_CO_PROC
| FL_MODE26
| FL_MODE32
}, /* so arm7m is sometimes used. */
188 {"arm7dmi", FL_CO_PROC
| FL_MODE26
| FL_MODE32
| FL_FAST_MULT
},
189 {"arm70", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
190 {"arm700", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
191 {"arm700i", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
192 {"arm710", FL_MODE26
| FL_MODE32
},
193 {"arm710c", FL_MODE26
| FL_MODE32
},
194 {"arm7100", FL_MODE26
| FL_MODE32
},
195 {"arm7500", FL_MODE26
| FL_MODE32
},
196 {"arm7500fe", FL_CO_PROC
| FL_MODE26
| FL_MODE32
}, /* Doesn't really have an external co-proc, but does have embedded fpu. */
197 {"arm7tdmi", FL_CO_PROC
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_THUMB
},
198 {"arm8", FL_MODE26
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_LDSCHED
},
199 {"arm810", FL_MODE26
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_LDSCHED
},
200 {"arm9", FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_THUMB
| FL_LDSCHED
},
201 {"arm9tdmi", FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_THUMB
| FL_LDSCHED
},
202 {"strongarm", FL_MODE26
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_LDSCHED
| FL_STRONG
},
203 {"strongarm110", FL_MODE26
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_LDSCHED
| FL_STRONG
},
204 {"strongarm1100", FL_MODE26
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_LDSCHED
| FL_STRONG
},
209 static struct processors all_architectures
[] =
211 /* ARM Architectures */
213 {"armv2", FL_CO_PROC
| FL_MODE26
},
214 {"armv2a", FL_CO_PROC
| FL_MODE26
},
215 {"armv3", FL_CO_PROC
| FL_MODE26
| FL_MODE32
},
216 {"armv3m", FL_CO_PROC
| FL_MODE26
| FL_MODE32
| FL_FAST_MULT
},
217 {"armv4", FL_CO_PROC
| FL_MODE26
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
},
218 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
219 implementations that support it, so we will leave it out for now. */
220 {"armv4t", FL_CO_PROC
| FL_MODE32
| FL_FAST_MULT
| FL_ARCH4
| FL_THUMB
},
224 /* This is a magic stucture. The 'string' field is magically filled in
225 with a pointer to the value specified by the user on the command line
226 assuming that the user has specified such a value. */
228 struct arm_cpu_select arm_select
[] =
230 /* string name processors */
231 { NULL
, "-mcpu=", all_cores
},
232 { NULL
, "-march=", all_architectures
},
233 { NULL
, "-mtune=", all_cores
}
236 /* Fix up any incompatible options that the user has specified.
237 This has now turned into a maze. */
239 arm_override_options ()
241 unsigned int flags
= 0;
243 struct arm_cpu_select
* ptr
;
245 /* Set up the flags based on the cpu/architecture selected by the user. */
246 for (i
= sizeof (arm_select
) / sizeof (arm_select
[0]); i
--;)
248 struct arm_cpu_select
* ptr
= arm_select
+ i
;
250 if (ptr
->string
!= NULL
&& ptr
->string
[0] != '\0')
252 struct processors
* sel
;
254 for (sel
= ptr
->processors
; sel
->name
!= NULL
; sel
++)
255 if (streq (ptr
->string
, sel
->name
))
259 /* We scan the arm_select array in the order:
261 So if we have been asked to tune for, say, an ARM8,
262 but we are told that the cpu is only an ARM6, then
263 we have problems. We detect this by seeing if the
264 flags bits accumulated so far can be supported by the
265 cpu/architecture type now being parsed. If they can,
266 then OR in any new bits. If they cannot then report
268 if ((flags
& sel
->flags
) != flags
)
269 error ("switch %s%s overridden by another switch",
270 ptr
->string
, sel
->name
);
278 if (sel
->name
== NULL
)
279 error ("bad value (%s) for %s switch", ptr
->string
, ptr
->name
);
283 /* If the user did not specify a processor, choose one for them. */
286 struct processors
* sel
;
289 if (TARGET_THUMB_INTERWORK
)
293 /* Force apcs-32 to be used for Thumb targets. */
294 target_flags
|= ARM_FLAG_APCS_32
;
297 if (! TARGET_APCS_32
)
302 for (sel
= all_cores
; sel
->name
!= NULL
; sel
++)
303 if ((sel
->flags
& sought
) == sought
)
309 if (sel
->name
== NULL
)
310 fatal ("Unable to select a cpu that matches command line specification");
314 /* The user did not specify any command line switches that require
315 a certain kind of CPU. Use TARGET_CPU_DEFAULT instead. */
317 static struct cpu_default
324 { TARGET_CPU_arm2
, "arm2" },
325 { TARGET_CPU_arm6
, "arm6" },
326 { TARGET_CPU_arm610
, "arm610" },
327 { TARGET_CPU_arm7m
, "arm7m" },
328 { TARGET_CPU_arm7500fe
, "arm7500fe" },
329 { TARGET_CPU_arm7tdmi
, "arm7tdmi" },
330 { TARGET_CPU_arm8
, "arm8" },
331 { TARGET_CPU_arm810
, "arm810" },
332 { TARGET_CPU_arm9
, "arm9" },
333 { TARGET_CPU_strongarm
, "strongarm" },
334 { TARGET_CPU_generic
, "arm" },
337 struct cpu_default
* def
;
339 /* Find the default. */
340 for (def
= cpu_defaults
; def
->name
; def
++)
341 if (def
->cpu
== TARGET_CPU_DEFAULT
)
344 if (def
->name
== NULL
)
347 /* Find the default CPU's flags. */
348 for (sel
= all_cores
; sel
->name
!= NULL
; sel
++)
349 if (streq (def
->name
, sel
->name
))
352 if (sel
->name
== NULL
)
359 /* Make sure that the processor choice does not conflict with any of the
360 other command line choices. */
361 if (TARGET_APCS_32
&& !(flags
& FL_MODE32
))
363 warning ("target CPU does not support APCS-32" );
364 target_flags
&= ~ ARM_FLAG_APCS_32
;
366 else if (! TARGET_APCS_32
&& !(flags
& FL_MODE26
))
368 warning ("target CPU does not support APCS-26" );
369 target_flags
|= ARM_FLAG_APCS_32
;
372 if (TARGET_THUMB_INTERWORK
&& !(flags
& FL_THUMB
))
374 warning ("target CPU does not support interworking" );
375 target_flags
&= ~ARM_FLAG_THUMB
;
378 /* If interworking is enabled then APCS-32 must be selected as well. */
379 if (TARGET_THUMB_INTERWORK
)
381 if (! TARGET_APCS_32
)
382 warning ("interworking forces APCS-32 to be used" );
383 target_flags
|= ARM_FLAG_APCS_32
;
386 if (TARGET_APCS_STACK
&& ! TARGET_APCS
)
388 warning ("-mapcs-stack-check incompatible with -mno-apcs-frame");
389 target_flags
|= ARM_FLAG_APCS_FRAME
;
392 if (write_symbols
!= NO_DEBUG
&& flag_omit_frame_pointer
)
393 warning ("-g with -fomit-frame-pointer may not give sensible debugging");
395 if (TARGET_POKE_FUNCTION_NAME
)
396 target_flags
|= ARM_FLAG_APCS_FRAME
;
398 if (TARGET_APCS_REENT
&& flag_pic
)
399 fatal ("-fpic and -mapcs-reent are incompatible");
401 if (TARGET_APCS_REENT
)
402 warning ("APCS reentrant code not supported. Ignored");
404 /* If stack checking is disabled, we can use r10 as the PIC register,
405 which keeps r9 available. */
406 if (flag_pic
&& ! TARGET_APCS_STACK
)
407 arm_pic_register
= 10;
409 /* Well, I'm about to have a go, but pic is NOT going to be compatible
410 with APCS reentrancy, since that requires too much support in the
411 assembler and linker, and the ARMASM assembler seems to lack some
412 required directives. */
414 warning ("Position independent code not supported");
416 if (TARGET_APCS_FLOAT
)
417 warning ("Passing floating point arguments in fp regs not yet supported");
419 /* Initialise booleans used elsewhere in this file, and in arm.md */
420 arm_fast_multiply
= (flags
& FL_FAST_MULT
) != 0;
421 arm_arch4
= (flags
& FL_ARCH4
) != 0;
422 arm_ld_sched
= (flags
& FL_LDSCHED
) != 0;
423 arm_is_strong
= (flags
& FL_STRONG
);
425 /* The arm.md file needs to know if theprocessor is an ARM6 or an ARM7 */
426 arm_is_6_or_7
= ((flags
& (FL_MODE26
| FL_MODE32
)) && !(flags
& FL_ARCH4
));
428 /* Default value for floating point code... if no co-processor
429 bus, then schedule for emulated floating point. Otherwise,
430 assume the user has an FPA.
431 Note: this does not prevent use of floating point instructions,
432 -msoft-float does that. */
433 if ((flags
& FL_CO_PROC
) == 0)
440 if (streq (target_fp_name
, "2"))
441 arm_fpu_arch
= FP_SOFT2
;
442 else if (streq (target_fp_name
, "3"))
443 arm_fpu_arch
= FP_SOFT3
;
445 fatal ("Invalid floating point emulation option: -mfpe-%s",
449 arm_fpu_arch
= FP_DEFAULT
;
451 if (TARGET_FPE
&& arm_fpu
!= FP_HARD
)
454 /* For arm2/3 there is no need to do any scheduling if there is only
455 a floating point emulator, or we are doing software floating-point. */
456 if ((TARGET_SOFT_FLOAT
|| arm_fpu
!= FP_HARD
) && (flags
& FL_MODE32
) == 0)
457 flag_schedule_insns
= flag_schedule_insns_after_reload
= 0;
459 arm_prog_mode
= TARGET_APCS_32
? PROG_MODE_PROG32
: PROG_MODE_PROG26
;
461 if (structure_size_string
!= NULL
)
463 int size
= strtol (structure_size_string
, NULL
, 0);
465 if (size
== 8 || size
== 32)
466 arm_structure_size_boundary
= size
;
468 warning ("Structure size boundary can only be set to 8 or 32");
471 /* If optimizing for space, don't synthesize constants.
472 For processors with load scheduling, it never costs more than 2 cycles
473 to load a constant, and the load scheduler may well reduce that to 1. */
474 if (optimize_size
|| (flags
& FL_LDSCHED
))
475 arm_constant_limit
= 1;
477 /* If optimizing for size, bump the number of instructions that we
478 are prepared to conditionally execute (even on a StrongARM).
479 Otherwise for the StrongARM, which has early execution of branches,
480 a sequence that is worth skipping is shorter. */
482 max_insns_skipped
= 6;
483 else if (arm_is_strong
)
484 max_insns_skipped
= 3;
487 /* Return 1 if it is possible to return using a single instruction */
490 use_return_insn (iscond
)
495 if (!reload_completed
496 || current_function_pretend_args_size
497 || current_function_anonymous_args
498 || ((get_frame_size () + current_function_outgoing_args_size
!= 0)
499 && !(TARGET_APCS
&& frame_pointer_needed
)))
502 /* Can't be done if interworking with Thumb, and any registers have been
503 stacked. Similarly, on StrongARM, conditional returns are expensive
504 if they aren't taken and registers have been stacked. */
505 if (iscond
&& arm_is_strong
&& frame_pointer_needed
)
507 if ((iscond
&& arm_is_strong
)
508 || TARGET_THUMB_INTERWORK
)
509 for (regno
= 0; regno
< 16; regno
++)
510 if (regs_ever_live
[regno
] && ! call_used_regs
[regno
])
513 /* Can't be done if any of the FPU regs are pushed, since this also
515 for (regno
= 16; regno
< 24; regno
++)
516 if (regs_ever_live
[regno
] && ! call_used_regs
[regno
])
519 /* If a function is naked, don't use the "return" insn. */
520 if (arm_naked_function_p (current_function_decl
))
526 /* Return TRUE if int I is a valid immediate ARM constant. */
532 unsigned HOST_WIDE_INT mask
= ~(unsigned HOST_WIDE_INT
)0xFF;
534 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
535 be all zero, or all one. */
536 if ((i
& ~(unsigned HOST_WIDE_INT
) 0xffffffff) != 0
537 && ((i
& ~(unsigned HOST_WIDE_INT
) 0xffffffff)
538 != ((~(unsigned HOST_WIDE_INT
) 0)
539 & ~(unsigned HOST_WIDE_INT
) 0xffffffff)))
542 /* Fast return for 0 and powers of 2 */
543 if ((i
& (i
- 1)) == 0)
548 if ((i
& mask
& (unsigned HOST_WIDE_INT
) 0xffffffff) == 0)
551 (mask
<< 2) | ((mask
& (unsigned HOST_WIDE_INT
) 0xffffffff)
552 >> (32 - 2)) | ~((unsigned HOST_WIDE_INT
) 0xffffffff);
553 } while (mask
!= ~(unsigned HOST_WIDE_INT
) 0xFF);
558 /* Return true if I is a valid constant for the operation CODE. */
560 const_ok_for_op (i
, code
, mode
)
563 enum machine_mode mode
;
565 if (const_ok_for_arm (i
))
571 return const_ok_for_arm (ARM_SIGN_EXTEND (-i
));
573 case MINUS
: /* Should only occur with (MINUS I reg) => rsb */
579 return const_ok_for_arm (ARM_SIGN_EXTEND (~i
));
586 /* Emit a sequence of insns to handle a large constant.
587 CODE is the code of the operation required, it can be any of SET, PLUS,
588 IOR, AND, XOR, MINUS;
589 MODE is the mode in which the operation is being performed;
590 VAL is the integer to operate on;
591 SOURCE is the other operand (a register, or a null-pointer for SET);
592 SUBTARGETS means it is safe to create scratch registers if that will
593 either produce a simpler sequence, or we will want to cse the values.
594 Return value is the number of insns emitted. */
597 arm_split_constant (code
, mode
, val
, target
, source
, subtargets
)
599 enum machine_mode mode
;
605 if (subtargets
|| code
== SET
606 || (GET_CODE (target
) == REG
&& GET_CODE (source
) == REG
607 && REGNO (target
) != REGNO (source
)))
609 /* After arm_reorg has been called, we can't fix up expensive
610 constants by pushing them into memory so we must synthesise
611 them in-line, regardless of the cost. This is only likely to
612 be more costly on chips that have load delay slots and we are
613 compiling without running the scheduler (so no splitting
614 occurred before the final instruction emission. */
615 if (! after_arm_reorg
616 && (arm_gen_constant (code
, mode
, val
, target
, source
, 1, 0)
617 > arm_constant_limit
+ (code
!= SET
)))
621 /* Currently SET is the only monadic value for CODE, all
622 the rest are diadic. */
623 emit_insn (gen_rtx_SET (VOIDmode
, target
, GEN_INT (val
)));
628 rtx temp
= subtargets
? gen_reg_rtx (mode
) : target
;
630 emit_insn (gen_rtx_SET (VOIDmode
, temp
, GEN_INT (val
)));
631 /* For MINUS, the value is subtracted from, since we never
632 have subtraction of a constant. */
634 emit_insn (gen_rtx_SET (VOIDmode
, target
,
635 gen_rtx (code
, mode
, temp
, source
)));
637 emit_insn (gen_rtx_SET (VOIDmode
, target
,
638 gen_rtx (code
, mode
, source
, temp
)));
644 return arm_gen_constant (code
, mode
, val
, target
, source
, subtargets
, 1);
647 /* As above, but extra parameter GENERATE which, if clear, suppresses
650 arm_gen_constant (code
, mode
, val
, target
, source
, subtargets
, generate
)
652 enum machine_mode mode
;
661 int can_negate_initial
= 0;
664 int num_bits_set
= 0;
665 int set_sign_bit_copies
= 0;
666 int clear_sign_bit_copies
= 0;
667 int clear_zero_bit_copies
= 0;
668 int set_zero_bit_copies
= 0;
670 unsigned HOST_WIDE_INT temp1
, temp2
;
671 unsigned HOST_WIDE_INT remainder
= val
& 0xffffffff;
673 /* find out which operations are safe for a given CODE. Also do a quick
674 check for degenerate cases; these can occur when DImode operations
686 can_negate_initial
= 1;
690 if (remainder
== 0xffffffff)
693 emit_insn (gen_rtx_SET (VOIDmode
, target
,
694 GEN_INT (ARM_SIGN_EXTEND (val
))));
699 if (reload_completed
&& rtx_equal_p (target
, source
))
702 emit_insn (gen_rtx_SET (VOIDmode
, target
, source
));
711 emit_insn (gen_rtx_SET (VOIDmode
, target
, const0_rtx
));
714 if (remainder
== 0xffffffff)
716 if (reload_completed
&& rtx_equal_p (target
, source
))
719 emit_insn (gen_rtx_SET (VOIDmode
, target
, source
));
728 if (reload_completed
&& rtx_equal_p (target
, source
))
731 emit_insn (gen_rtx_SET (VOIDmode
, target
, source
));
734 if (remainder
== 0xffffffff)
737 emit_insn (gen_rtx_SET (VOIDmode
, target
,
738 gen_rtx_NOT (mode
, source
)));
742 /* We don't know how to handle this yet below. */
746 /* We treat MINUS as (val - source), since (source - val) is always
747 passed as (source + (-val)). */
751 emit_insn (gen_rtx_SET (VOIDmode
, target
,
752 gen_rtx_NEG (mode
, source
)));
755 if (const_ok_for_arm (val
))
758 emit_insn (gen_rtx_SET (VOIDmode
, target
,
759 gen_rtx_MINUS (mode
, GEN_INT (val
),
771 /* If we can do it in one insn get out quickly */
772 if (const_ok_for_arm (val
)
773 || (can_negate_initial
&& const_ok_for_arm (-val
))
774 || (can_invert
&& const_ok_for_arm (~val
)))
777 emit_insn (gen_rtx_SET (VOIDmode
, target
,
778 (source
? gen_rtx (code
, mode
, source
,
785 /* Calculate a few attributes that may be useful for specific
788 for (i
= 31; i
>= 0; i
--)
790 if ((remainder
& (1 << i
)) == 0)
791 clear_sign_bit_copies
++;
796 for (i
= 31; i
>= 0; i
--)
798 if ((remainder
& (1 << i
)) != 0)
799 set_sign_bit_copies
++;
804 for (i
= 0; i
<= 31; i
++)
806 if ((remainder
& (1 << i
)) == 0)
807 clear_zero_bit_copies
++;
812 for (i
= 0; i
<= 31; i
++)
814 if ((remainder
& (1 << i
)) != 0)
815 set_zero_bit_copies
++;
823 /* See if we can do this by sign_extending a constant that is known
824 to be negative. This is a good, way of doing it, since the shift
825 may well merge into a subsequent insn. */
826 if (set_sign_bit_copies
> 1)
829 (temp1
= ARM_SIGN_EXTEND (remainder
830 << (set_sign_bit_copies
- 1))))
834 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
835 emit_insn (gen_rtx_SET (VOIDmode
, new_src
,
837 emit_insn (gen_ashrsi3 (target
, new_src
,
838 GEN_INT (set_sign_bit_copies
- 1)));
842 /* For an inverted constant, we will need to set the low bits,
843 these will be shifted out of harm's way. */
844 temp1
|= (1 << (set_sign_bit_copies
- 1)) - 1;
845 if (const_ok_for_arm (~temp1
))
849 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
850 emit_insn (gen_rtx_SET (VOIDmode
, new_src
,
852 emit_insn (gen_ashrsi3 (target
, new_src
,
853 GEN_INT (set_sign_bit_copies
- 1)));
859 /* See if we can generate this by setting the bottom (or the top)
860 16 bits, and then shifting these into the other half of the
861 word. We only look for the simplest cases, to do more would cost
862 too much. Be careful, however, not to generate this when the
863 alternative would take fewer insns. */
864 if (val
& 0xffff0000)
866 temp1
= remainder
& 0xffff0000;
867 temp2
= remainder
& 0x0000ffff;
869 /* Overlaps outside this range are best done using other methods. */
870 for (i
= 9; i
< 24; i
++)
872 if ((((temp2
| (temp2
<< i
)) & 0xffffffff) == remainder
)
873 && ! const_ok_for_arm (temp2
))
875 rtx new_src
= (subtargets
876 ? (generate
? gen_reg_rtx (mode
) : NULL_RTX
)
878 insns
= arm_gen_constant (code
, mode
, temp2
, new_src
,
879 source
, subtargets
, generate
);
882 emit_insn (gen_rtx_SET
885 gen_rtx_ASHIFT (mode
, source
,
892 /* Don't duplicate cases already considered. */
893 for (i
= 17; i
< 24; i
++)
895 if (((temp1
| (temp1
>> i
)) == remainder
)
896 && ! const_ok_for_arm (temp1
))
898 rtx new_src
= (subtargets
899 ? (generate
? gen_reg_rtx (mode
) : NULL_RTX
)
901 insns
= arm_gen_constant (code
, mode
, temp1
, new_src
,
902 source
, subtargets
, generate
);
906 (gen_rtx_SET (VOIDmode
, target
,
909 gen_rtx_LSHIFTRT (mode
, source
,
920 /* If we have IOR or XOR, and the constant can be loaded in a
921 single instruction, and we can find a temporary to put it in,
922 then this can be done in two instructions instead of 3-4. */
924 /* TARGET can't be NULL if SUBTARGETS is 0 */
925 || (reload_completed
&& ! reg_mentioned_p (target
, source
)))
927 if (const_ok_for_arm (ARM_SIGN_EXTEND (~ val
)))
931 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
933 emit_insn (gen_rtx_SET (VOIDmode
, sub
, GEN_INT (val
)));
934 emit_insn (gen_rtx_SET (VOIDmode
, target
,
935 gen_rtx (code
, mode
, source
, sub
)));
944 if (set_sign_bit_copies
> 8
945 && (val
& (-1 << (32 - set_sign_bit_copies
))) == val
)
949 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
950 rtx shift
= GEN_INT (set_sign_bit_copies
);
952 emit_insn (gen_rtx_SET (VOIDmode
, sub
,
954 gen_rtx_ASHIFT (mode
,
957 emit_insn (gen_rtx_SET (VOIDmode
, target
,
959 gen_rtx_LSHIFTRT (mode
, sub
,
965 if (set_zero_bit_copies
> 8
966 && (remainder
& ((1 << set_zero_bit_copies
) - 1)) == remainder
)
970 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
971 rtx shift
= GEN_INT (set_zero_bit_copies
);
973 emit_insn (gen_rtx_SET (VOIDmode
, sub
,
975 gen_rtx_LSHIFTRT (mode
,
978 emit_insn (gen_rtx_SET (VOIDmode
, target
,
980 gen_rtx_ASHIFT (mode
, sub
,
986 if (const_ok_for_arm (temp1
= ARM_SIGN_EXTEND (~ val
)))
990 rtx sub
= subtargets
? gen_reg_rtx (mode
) : target
;
991 emit_insn (gen_rtx_SET (VOIDmode
, sub
,
992 gen_rtx_NOT (mode
, source
)));
995 sub
= gen_reg_rtx (mode
);
996 emit_insn (gen_rtx_SET (VOIDmode
, sub
,
997 gen_rtx_AND (mode
, source
,
999 emit_insn (gen_rtx_SET (VOIDmode
, target
,
1000 gen_rtx_NOT (mode
, sub
)));
1007 /* See if two shifts will do 2 or more insn's worth of work. */
1008 if (clear_sign_bit_copies
>= 16 && clear_sign_bit_copies
< 24)
1010 HOST_WIDE_INT shift_mask
= ((0xffffffff
1011 << (32 - clear_sign_bit_copies
))
1014 if ((remainder
| shift_mask
) != 0xffffffff)
1018 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
1019 insns
= arm_gen_constant (AND
, mode
, remainder
| shift_mask
,
1020 new_src
, source
, subtargets
, 1);
1025 rtx targ
= subtargets
? NULL_RTX
: target
;
1026 insns
= arm_gen_constant (AND
, mode
, remainder
| shift_mask
,
1027 targ
, source
, subtargets
, 0);
1033 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
1034 rtx shift
= GEN_INT (clear_sign_bit_copies
);
1036 emit_insn (gen_ashlsi3 (new_src
, source
, shift
));
1037 emit_insn (gen_lshrsi3 (target
, new_src
, shift
));
1043 if (clear_zero_bit_copies
>= 16 && clear_zero_bit_copies
< 24)
1045 HOST_WIDE_INT shift_mask
= (1 << clear_zero_bit_copies
) - 1;
1047 if ((remainder
| shift_mask
) != 0xffffffff)
1051 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
1053 insns
= arm_gen_constant (AND
, mode
, remainder
| shift_mask
,
1054 new_src
, source
, subtargets
, 1);
1059 rtx targ
= subtargets
? NULL_RTX
: target
;
1061 insns
= arm_gen_constant (AND
, mode
, remainder
| shift_mask
,
1062 targ
, source
, subtargets
, 0);
1068 rtx new_src
= subtargets
? gen_reg_rtx (mode
) : target
;
1069 rtx shift
= GEN_INT (clear_zero_bit_copies
);
1071 emit_insn (gen_lshrsi3 (new_src
, source
, shift
));
1072 emit_insn (gen_ashlsi3 (target
, new_src
, shift
));
1084 for (i
= 0; i
< 32; i
++)
1085 if (remainder
& (1 << i
))
1088 if (code
== AND
|| (can_invert
&& num_bits_set
> 16))
1089 remainder
= (~remainder
) & 0xffffffff;
1090 else if (code
== PLUS
&& num_bits_set
> 16)
1091 remainder
= (-remainder
) & 0xffffffff;
1098 /* Now try and find a way of doing the job in either two or three
1100 We start by looking for the largest block of zeros that are aligned on
1101 a 2-bit boundary, we then fill up the temps, wrapping around to the
1102 top of the word when we drop off the bottom.
1103 In the worst case this code should produce no more than four insns. */
1106 int best_consecutive_zeros
= 0;
1108 for (i
= 0; i
< 32; i
+= 2)
1110 int consecutive_zeros
= 0;
1112 if (! (remainder
& (3 << i
)))
1114 while ((i
< 32) && ! (remainder
& (3 << i
)))
1116 consecutive_zeros
+= 2;
1119 if (consecutive_zeros
> best_consecutive_zeros
)
1121 best_consecutive_zeros
= consecutive_zeros
;
1122 best_start
= i
- consecutive_zeros
;
1128 /* Now start emitting the insns, starting with the one with the highest
1129 bit set: we do this so that the smallest number will be emitted last;
1130 this is more likely to be combinable with addressing insns. */
1138 if (remainder
& (3 << (i
- 2)))
1143 temp1
= remainder
& ((0x0ff << end
)
1144 | ((i
< end
) ? (0xff >> (32 - end
)) : 0));
1145 remainder
&= ~temp1
;
1152 emit_insn (gen_rtx_SET (VOIDmode
,
1153 new_src
= (subtargets
1154 ? gen_reg_rtx (mode
)
1157 ? ~temp1
: temp1
)));
1158 else if (code
== MINUS
)
1159 emit_insn (gen_rtx_SET (VOIDmode
,
1160 new_src
= (subtargets
1161 ? gen_reg_rtx (mode
)
1163 gen_rtx (code
, mode
, GEN_INT (temp1
),
1166 emit_insn (gen_rtx_SET (VOIDmode
,
1167 new_src
= (remainder
1169 ? gen_reg_rtx (mode
)
1172 gen_rtx (code
, mode
, source
,
1173 GEN_INT (can_invert
? ~temp1
1185 else if (code
== MINUS
)
1192 } while (remainder
);
1197 /* Canonicalize a comparison so that we are more likely to recognize it.
1198 This can be done for a few constant compares, where we can make the
1199 immediate value easier to load. */
1201 arm_canonicalize_comparison (code
, op1
)
1205 unsigned HOST_WIDE_INT i
= INTVAL (*op1
);
1215 if (i
!= ((((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1))
1217 && (const_ok_for_arm (i
+1) || const_ok_for_arm (- (i
+1))))
1219 *op1
= GEN_INT (i
+1);
1220 return code
== GT
? GE
: LT
;
1226 if (i
!= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1))
1227 && (const_ok_for_arm (i
-1) || const_ok_for_arm (- (i
-1))))
1229 *op1
= GEN_INT (i
-1);
1230 return code
== GE
? GT
: LE
;
1236 if (i
!= ~((unsigned HOST_WIDE_INT
) 0)
1237 && (const_ok_for_arm (i
+1) || const_ok_for_arm (- (i
+1))))
1239 *op1
= GEN_INT (i
+ 1);
1240 return code
== GTU
? GEU
: LTU
;
1247 && (const_ok_for_arm (i
- 1) || const_ok_for_arm (- (i
- 1))))
1249 *op1
= GEN_INT (i
- 1);
1250 return code
== GEU
? GTU
: LEU
;
1261 /* Decide whether a type should be returned in memory (true)
1262 or in a register (false). This is called by the macro
1263 RETURN_IN_MEMORY. */
1265 arm_return_in_memory (type
)
1268 if (! AGGREGATE_TYPE_P (type
))
1270 /* All simple types are returned in registers. */
1273 else if (int_size_in_bytes (type
) > 4)
1275 /* All structures/unions bigger than one word are returned in memory. */
1278 else if (TREE_CODE (type
) == RECORD_TYPE
)
1282 /* For a struct the APCS says that we must return in a register if
1283 every addressable element has an offset of zero. For practical
1284 purposes this means that the structure can have at most one non
1285 bit-field element and that this element must be the first one in
1288 /* Find the first field, ignoring non FIELD_DECL things which will
1289 have been created by C++. */
1290 for (field
= TYPE_FIELDS (type
);
1291 field
&& TREE_CODE (field
) != FIELD_DECL
;
1292 field
= TREE_CHAIN (field
))
1296 return 0; /* An empty structure. Allowed by an extension to ANSI C. */
1298 /* Now check the remaining fields, if any. */
1299 for (field
= TREE_CHAIN (field
);
1301 field
= TREE_CHAIN (field
))
1303 if (TREE_CODE (field
) != FIELD_DECL
)
1306 if (! DECL_BIT_FIELD_TYPE (field
))
1312 else if (TREE_CODE (type
) == UNION_TYPE
)
1316 /* Unions can be returned in registers if every element is
1317 integral, or can be returned in an integer register. */
1318 for (field
= TYPE_FIELDS (type
);
1320 field
= TREE_CHAIN (field
))
1322 if (TREE_CODE (field
) != FIELD_DECL
)
1325 if (FLOAT_TYPE_P (TREE_TYPE (field
)))
1328 if (RETURN_IN_MEMORY (TREE_TYPE (field
)))
1335 /* XXX Not sure what should be done for other aggregates, so put them in
1341 legitimate_pic_operand_p (x
)
1344 if (CONSTANT_P (x
) && flag_pic
1345 && (GET_CODE (x
) == SYMBOL_REF
1346 || (GET_CODE (x
) == CONST
1347 && GET_CODE (XEXP (x
, 0)) == PLUS
1348 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
)))
1355 legitimize_pic_address (orig
, mode
, reg
)
1357 enum machine_mode mode
;
1360 if (GET_CODE (orig
) == SYMBOL_REF
)
1362 rtx pic_ref
, address
;
1368 if (reload_in_progress
|| reload_completed
)
1371 reg
= gen_reg_rtx (Pmode
);
1376 #ifdef AOF_ASSEMBLER
1377 /* The AOF assembler can generate relocations for these directly, and
1378 understands that the PIC register has to be added into the offset.
1380 insn
= emit_insn (gen_pic_load_addr_based (reg
, orig
));
1383 address
= gen_reg_rtx (Pmode
);
1387 emit_insn (gen_pic_load_addr (address
, orig
));
1389 pic_ref
= gen_rtx_MEM (Pmode
,
1390 gen_rtx_PLUS (Pmode
, pic_offset_table_rtx
,
1392 RTX_UNCHANGING_P (pic_ref
) = 1;
1393 insn
= emit_move_insn (reg
, pic_ref
);
1395 current_function_uses_pic_offset_table
= 1;
1396 /* Put a REG_EQUAL note on this insn, so that it can be optimized
1398 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_EQUAL
, orig
,
1402 else if (GET_CODE (orig
) == CONST
)
1406 if (GET_CODE (XEXP (orig
, 0)) == PLUS
1407 && XEXP (XEXP (orig
, 0), 0) == pic_offset_table_rtx
)
1412 if (reload_in_progress
|| reload_completed
)
1415 reg
= gen_reg_rtx (Pmode
);
1418 if (GET_CODE (XEXP (orig
, 0)) == PLUS
)
1420 base
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 0), Pmode
, reg
);
1421 offset
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 1), Pmode
,
1422 base
== reg
? 0 : reg
);
1427 if (GET_CODE (offset
) == CONST_INT
)
1429 /* The base register doesn't really matter, we only want to
1430 test the index for the appropriate mode. */
1431 GO_IF_LEGITIMATE_INDEX (mode
, 0, offset
, win
);
1433 if (! reload_in_progress
&& ! reload_completed
)
1434 offset
= force_reg (Pmode
, offset
);
1439 if (GET_CODE (offset
) == CONST_INT
)
1440 return plus_constant_for_output (base
, INTVAL (offset
));
1443 if (GET_MODE_SIZE (mode
) > 4
1444 && (GET_MODE_CLASS (mode
) == MODE_INT
1445 || TARGET_SOFT_FLOAT
))
1447 emit_insn (gen_addsi3 (reg
, base
, offset
));
1451 return gen_rtx_PLUS (Pmode
, base
, offset
);
1453 else if (GET_CODE (orig
) == LABEL_REF
)
1454 current_function_uses_pic_offset_table
= 1;
1473 #ifndef AOF_ASSEMBLER
1474 rtx l1
, pic_tmp
, pic_tmp2
, seq
;
1475 rtx global_offset_table
;
1477 if (current_function_uses_pic_offset_table
== 0)
1484 l1
= gen_label_rtx ();
1486 global_offset_table
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
1487 /* On the ARM the PC register contains 'dot + 8' at the time of the
1489 pic_tmp
= plus_constant (gen_rtx_LABEL_REF (Pmode
, l1
), 8);
1490 pic_tmp2
= gen_rtx_CONST (VOIDmode
,
1491 gen_rtx_PLUS (Pmode
, global_offset_table
, pc_rtx
));
1493 pic_rtx
= gen_rtx_CONST (Pmode
, gen_rtx_MINUS (Pmode
, pic_tmp2
, pic_tmp
));
1495 emit_insn (gen_pic_load_addr (pic_offset_table_rtx
, pic_rtx
));
1496 emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx
, l1
));
1498 seq
= gen_sequence ();
1500 emit_insn_after (seq
, get_insns ());
1502 /* Need to emit this whether or not we obey regdecls,
1503 since setjmp/longjmp can cause life info to screw up. */
1504 emit_insn (gen_rtx_USE (VOIDmode
, pic_offset_table_rtx
));
1505 #endif /* AOF_ASSEMBLER */
1508 #define REG_OR_SUBREG_REG(X) \
1509 (GET_CODE (X) == REG \
1510 || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
1512 #define REG_OR_SUBREG_RTX(X) \
1513 (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
1515 #define ARM_FRAME_RTX(X) \
1516 ((X) == frame_pointer_rtx || (X) == stack_pointer_rtx \
1517 || (X) == arg_pointer_rtx)
1520 arm_rtx_costs (x
, code
, outer_code
)
1522 enum rtx_code code
, outer_code
;
1524 enum machine_mode mode
= GET_MODE (x
);
1525 enum rtx_code subcode
;
1531 /* Memory costs quite a lot for the first word, but subsequent words
1532 load at the equivalent of a single insn each. */
1533 return (10 + 4 * ((GET_MODE_SIZE (mode
) - 1) / UNITS_PER_WORD
)
1534 + (CONSTANT_POOL_ADDRESS_P (x
) ? 4 : 0));
1541 if (mode
== SImode
&& GET_CODE (XEXP (x
, 1)) == REG
)
1548 case ASHIFT
: case LSHIFTRT
: case ASHIFTRT
:
1550 return (8 + (GET_CODE (XEXP (x
, 1)) == CONST_INT
? 0 : 8)
1551 + ((GET_CODE (XEXP (x
, 0)) == REG
1552 || (GET_CODE (XEXP (x
, 0)) == SUBREG
1553 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == REG
))
1555 return (1 + ((GET_CODE (XEXP (x
, 0)) == REG
1556 || (GET_CODE (XEXP (x
, 0)) == SUBREG
1557 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == REG
))
1559 + ((GET_CODE (XEXP (x
, 1)) == REG
1560 || (GET_CODE (XEXP (x
, 1)) == SUBREG
1561 && GET_CODE (SUBREG_REG (XEXP (x
, 1))) == REG
)
1562 || (GET_CODE (XEXP (x
, 1)) == CONST_INT
))
1567 return (4 + (REG_OR_SUBREG_REG (XEXP (x
, 1)) ? 0 : 8)
1568 + ((REG_OR_SUBREG_REG (XEXP (x
, 0))
1569 || (GET_CODE (XEXP (x
, 0)) == CONST_INT
1570 && const_ok_for_arm (INTVAL (XEXP (x
, 0)))))
1573 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
1574 return (2 + ((REG_OR_SUBREG_REG (XEXP (x
, 1))
1575 || (GET_CODE (XEXP (x
, 1)) == CONST_DOUBLE
1576 && const_double_rtx_ok_for_fpu (XEXP (x
, 1))))
1578 + ((REG_OR_SUBREG_REG (XEXP (x
, 0))
1579 || (GET_CODE (XEXP (x
, 0)) == CONST_DOUBLE
1580 && const_double_rtx_ok_for_fpu (XEXP (x
, 0))))
1583 if (((GET_CODE (XEXP (x
, 0)) == CONST_INT
1584 && const_ok_for_arm (INTVAL (XEXP (x
, 0)))
1585 && REG_OR_SUBREG_REG (XEXP (x
, 1))))
1586 || (((subcode
= GET_CODE (XEXP (x
, 1))) == ASHIFT
1587 || subcode
== ASHIFTRT
|| subcode
== LSHIFTRT
1588 || subcode
== ROTATE
|| subcode
== ROTATERT
1590 && GET_CODE (XEXP (XEXP (x
, 1), 1)) == CONST_INT
1591 && ((INTVAL (XEXP (XEXP (x
, 1), 1)) &
1592 (INTVAL (XEXP (XEXP (x
, 1), 1)) - 1)) == 0)))
1593 && REG_OR_SUBREG_REG (XEXP (XEXP (x
, 1), 0))
1594 && (REG_OR_SUBREG_REG (XEXP (XEXP (x
, 1), 1))
1595 || GET_CODE (XEXP (XEXP (x
, 1), 1)) == CONST_INT
)
1596 && REG_OR_SUBREG_REG (XEXP (x
, 0))))
1601 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
1602 return (2 + (REG_OR_SUBREG_REG (XEXP (x
, 0)) ? 0 : 8)
1603 + ((REG_OR_SUBREG_REG (XEXP (x
, 1))
1604 || (GET_CODE (XEXP (x
, 1)) == CONST_DOUBLE
1605 && const_double_rtx_ok_for_fpu (XEXP (x
, 1))))
1609 case AND
: case XOR
: case IOR
:
1612 /* Normally the frame registers will be spilt into reg+const during
1613 reload, so it is a bad idea to combine them with other instructions,
1614 since then they might not be moved outside of loops. As a compromise
1615 we allow integration with ops that have a constant as their second
1617 if ((REG_OR_SUBREG_REG (XEXP (x
, 0))
1618 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x
, 0)))
1619 && GET_CODE (XEXP (x
, 1)) != CONST_INT
)
1620 || (REG_OR_SUBREG_REG (XEXP (x
, 0))
1621 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x
, 0)))))
1625 return (4 + extra_cost
+ (REG_OR_SUBREG_REG (XEXP (x
, 0)) ? 0 : 8)
1626 + ((REG_OR_SUBREG_REG (XEXP (x
, 1))
1627 || (GET_CODE (XEXP (x
, 1)) == CONST_INT
1628 && const_ok_for_op (INTVAL (XEXP (x
, 1)), code
, mode
)))
1631 if (REG_OR_SUBREG_REG (XEXP (x
, 0)))
1632 return (1 + (GET_CODE (XEXP (x
, 1)) == CONST_INT
? 0 : extra_cost
)
1633 + ((REG_OR_SUBREG_REG (XEXP (x
, 1))
1634 || (GET_CODE (XEXP (x
, 1)) == CONST_INT
1635 && const_ok_for_op (INTVAL (XEXP (x
, 1)), code
, mode
)))
1638 else if (REG_OR_SUBREG_REG (XEXP (x
, 1)))
1639 return (1 + extra_cost
1640 + ((((subcode
= GET_CODE (XEXP (x
, 0))) == ASHIFT
1641 || subcode
== LSHIFTRT
|| subcode
== ASHIFTRT
1642 || subcode
== ROTATE
|| subcode
== ROTATERT
1644 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
1645 && ((INTVAL (XEXP (XEXP (x
, 0), 1)) &
1646 (INTVAL (XEXP (XEXP (x
, 0), 1)) - 1)) == 0)))
1647 && (REG_OR_SUBREG_REG (XEXP (XEXP (x
, 0), 0)))
1648 && ((REG_OR_SUBREG_REG (XEXP (XEXP (x
, 0), 1)))
1649 || GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
))
1655 /* There is no point basing this on the tuning, since it is always the
1656 fast variant if it exists at all */
1657 if (arm_fast_multiply
&& mode
== DImode
1658 && (GET_CODE (XEXP (x
, 0)) == GET_CODE (XEXP (x
, 1)))
1659 && (GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
1660 || GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
))
1663 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
1667 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
1669 unsigned HOST_WIDE_INT i
= (INTVAL (XEXP (x
, 1))
1670 & (unsigned HOST_WIDE_INT
) 0xffffffff);
1671 int add_cost
= const_ok_for_arm (i
) ? 4 : 8;
1673 /* Tune as appropriate */
1674 int booth_unit_size
= (arm_fast_multiply
? 8 : 2);
1676 for (j
= 0; i
&& j
< 32; j
+= booth_unit_size
)
1678 i
>>= booth_unit_size
;
1685 return ((arm_fast_multiply
? 8 : 30)
1686 + (REG_OR_SUBREG_REG (XEXP (x
, 0)) ? 0 : 4)
1687 + (REG_OR_SUBREG_REG (XEXP (x
, 1)) ? 0 : 4));
1690 if (arm_fast_multiply
&& mode
== SImode
1691 && GET_CODE (XEXP (x
, 0)) == LSHIFTRT
1692 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == MULT
1693 && (GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0))
1694 == GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 1)))
1695 && (GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == ZERO_EXTEND
1696 || GET_CODE (XEXP (XEXP (XEXP (x
, 0), 0), 0)) == SIGN_EXTEND
))
1701 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
1702 return 4 + (REG_OR_SUBREG_REG (XEXP (x
, 0)) ? 0 : 6);
1706 return 4 + (REG_OR_SUBREG_REG (XEXP (x
, 0)) ? 0 : 4);
1708 return 1 + (REG_OR_SUBREG_REG (XEXP (x
, 0)) ? 0 : 4);
1711 if (GET_CODE (XEXP (x
, 1)) == PC
|| GET_CODE (XEXP (x
, 2)) == PC
)
1719 return 4 + (mode
== DImode
? 4 : 0);
1722 if (GET_MODE (XEXP (x
, 0)) == QImode
)
1723 return (4 + (mode
== DImode
? 4 : 0)
1724 + (GET_CODE (XEXP (x
, 0)) == MEM
? 10 : 0));
1727 switch (GET_MODE (XEXP (x
, 0)))
1730 return (1 + (mode
== DImode
? 4 : 0)
1731 + (GET_CODE (XEXP (x
, 0)) == MEM
? 10 : 0));
1734 return (4 + (mode
== DImode
? 4 : 0)
1735 + (GET_CODE (XEXP (x
, 0)) == MEM
? 10 : 0));
1738 return (1 + (GET_CODE (XEXP (x
, 0)) == MEM
? 10 : 0));
1751 arm_adjust_cost (insn
, link
, dep
, cost
)
1759 /* XXX This is not strictly true for the FPA. */
1760 if (REG_NOTE_KIND(link
) == REG_DEP_ANTI
1761 || REG_NOTE_KIND(link
) == REG_DEP_OUTPUT
)
1764 if ((i_pat
= single_set (insn
)) != NULL
1765 && GET_CODE (SET_SRC (i_pat
)) == MEM
1766 && (d_pat
= single_set (dep
)) != NULL
1767 && GET_CODE (SET_DEST (d_pat
)) == MEM
)
1769 /* This is a load after a store, there is no conflict if the load reads
1770 from a cached area. Assume that loads from the stack, and from the
1771 constant pool are cached, and that others will miss. This is a
1774 /* debug_rtx (insn);
1777 fprintf (stderr, "costs %d\n", cost); */
1779 if (CONSTANT_POOL_ADDRESS_P (XEXP (SET_SRC (i_pat
), 0))
1780 || reg_mentioned_p (stack_pointer_rtx
, XEXP (SET_SRC (i_pat
), 0))
1781 || reg_mentioned_p (frame_pointer_rtx
, XEXP (SET_SRC (i_pat
), 0))
1782 || reg_mentioned_p (hard_frame_pointer_rtx
,
1783 XEXP (SET_SRC (i_pat
), 0)))
1785 /* fprintf (stderr, "***** Now 1\n"); */
1793 /* This code has been fixed for cross compilation. */
1795 static int fpa_consts_inited
= 0;
1797 char *strings_fpa
[8] = {
1799 "4", "5", "0.5", "10"
1802 static REAL_VALUE_TYPE values_fpa
[8];
1810 for (i
= 0; i
< 8; i
++)
1812 r
= REAL_VALUE_ATOF (strings_fpa
[i
], DFmode
);
1816 fpa_consts_inited
= 1;
1819 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1822 const_double_rtx_ok_for_fpu (x
)
1828 if (!fpa_consts_inited
)
1831 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
1832 if (REAL_VALUE_MINUS_ZERO (r
))
1835 for (i
= 0; i
< 8; i
++)
1836 if (REAL_VALUES_EQUAL (r
, values_fpa
[i
]))
1842 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1845 neg_const_double_rtx_ok_for_fpu (x
)
1851 if (!fpa_consts_inited
)
1854 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
1855 r
= REAL_VALUE_NEGATE (r
);
1856 if (REAL_VALUE_MINUS_ZERO (r
))
1859 for (i
= 0; i
< 8; i
++)
1860 if (REAL_VALUES_EQUAL (r
, values_fpa
[i
]))
1866 /* Predicates for `match_operand' and `match_operator'. */
1868 /* s_register_operand is the same as register_operand, but it doesn't accept
1871 This function exists because at the time it was put in it led to better
1872 code. SUBREG(MEM) always needs a reload in the places where
1873 s_register_operand is used, and this seemed to lead to excessive
1877 s_register_operand (op
, mode
)
1879 enum machine_mode mode
;
1881 if (GET_MODE (op
) != mode
&& mode
!= VOIDmode
)
1884 if (GET_CODE (op
) == SUBREG
)
1885 op
= SUBREG_REG (op
);
1887 /* We don't consider registers whose class is NO_REGS
1888 to be a register operand. */
1889 return (GET_CODE (op
) == REG
1890 && (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1891 || REGNO_REG_CLASS (REGNO (op
)) != NO_REGS
));
1894 /* Only accept reg, subreg(reg), const_int. */
1897 reg_or_int_operand (op
, mode
)
1899 enum machine_mode mode
;
1901 if (GET_CODE (op
) == CONST_INT
)
1904 if (GET_MODE (op
) != mode
&& mode
!= VOIDmode
)
1907 if (GET_CODE (op
) == SUBREG
)
1908 op
= SUBREG_REG (op
);
1910 /* We don't consider registers whose class is NO_REGS
1911 to be a register operand. */
1912 return (GET_CODE (op
) == REG
1913 && (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1914 || REGNO_REG_CLASS (REGNO (op
)) != NO_REGS
));
1917 /* Return 1 if OP is an item in memory, given that we are in reload. */
1920 reload_memory_operand (op
, mode
)
1922 enum machine_mode mode
;
1924 int regno
= true_regnum (op
);
1926 return (! CONSTANT_P (op
)
1928 || (GET_CODE (op
) == REG
1929 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
)));
1932 /* Return 1 if OP is a valid memory address, but not valid for a signed byte
1933 memory access (architecture V4) */
1935 bad_signed_byte_operand (op
, mode
)
1937 enum machine_mode mode
;
1939 if (! memory_operand (op
, mode
) || GET_CODE (op
) != MEM
)
1944 /* A sum of anything more complex than reg + reg or reg + const is bad */
1945 if ((GET_CODE (op
) == PLUS
|| GET_CODE (op
) == MINUS
)
1946 && (! s_register_operand (XEXP (op
, 0), VOIDmode
)
1947 || (! s_register_operand (XEXP (op
, 1), VOIDmode
)
1948 && GET_CODE (XEXP (op
, 1)) != CONST_INT
)))
1951 /* Big constants are also bad */
1952 if (GET_CODE (op
) == PLUS
&& GET_CODE (XEXP (op
, 1)) == CONST_INT
1953 && (INTVAL (XEXP (op
, 1)) > 0xff
1954 || -INTVAL (XEXP (op
, 1)) > 0xff))
1957 /* Everything else is good, or can will automatically be made so. */
1961 /* Return TRUE for valid operands for the rhs of an ARM instruction. */
1964 arm_rhs_operand (op
, mode
)
1966 enum machine_mode mode
;
1968 return (s_register_operand (op
, mode
)
1969 || (GET_CODE (op
) == CONST_INT
&& const_ok_for_arm (INTVAL (op
))));
1972 /* Return TRUE for valid operands for the rhs of an ARM instruction, or a load.
1976 arm_rhsm_operand (op
, mode
)
1978 enum machine_mode mode
;
1980 return (s_register_operand (op
, mode
)
1981 || (GET_CODE (op
) == CONST_INT
&& const_ok_for_arm (INTVAL (op
)))
1982 || memory_operand (op
, mode
));
1985 /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a
1986 constant that is valid when negated. */
1989 arm_add_operand (op
, mode
)
1991 enum machine_mode mode
;
1993 return (s_register_operand (op
, mode
)
1994 || (GET_CODE (op
) == CONST_INT
1995 && (const_ok_for_arm (INTVAL (op
))
1996 || const_ok_for_arm (-INTVAL (op
)))));
2000 arm_not_operand (op
, mode
)
2002 enum machine_mode mode
;
2004 return (s_register_operand (op
, mode
)
2005 || (GET_CODE (op
) == CONST_INT
2006 && (const_ok_for_arm (INTVAL (op
))
2007 || const_ok_for_arm (~INTVAL (op
)))));
2010 /* Return TRUE if the operand is a memory reference which contains an
2011 offsettable address. */
2013 offsettable_memory_operand (op
, mode
)
2015 enum machine_mode mode
;
2017 if (mode
== VOIDmode
)
2018 mode
= GET_MODE (op
);
2020 return (mode
== GET_MODE (op
)
2021 && GET_CODE (op
) == MEM
2022 && offsettable_address_p (reload_completed
| reload_in_progress
,
2023 mode
, XEXP (op
, 0)));
2026 /* Return TRUE if the operand is a memory reference which is, or can be
2027 made word aligned by adjusting the offset. */
2029 alignable_memory_operand (op
, mode
)
2031 enum machine_mode mode
;
2035 if (mode
== VOIDmode
)
2036 mode
= GET_MODE (op
);
2038 if (mode
!= GET_MODE (op
) || GET_CODE (op
) != MEM
)
2043 return ((GET_CODE (reg
= op
) == REG
2044 || (GET_CODE (op
) == SUBREG
2045 && GET_CODE (reg
= SUBREG_REG (op
)) == REG
)
2046 || (GET_CODE (op
) == PLUS
2047 && GET_CODE (XEXP (op
, 1)) == CONST_INT
2048 && (GET_CODE (reg
= XEXP (op
, 0)) == REG
2049 || (GET_CODE (XEXP (op
, 0)) == SUBREG
2050 && GET_CODE (reg
= SUBREG_REG (XEXP (op
, 0))) == REG
))))
2051 && REGNO_POINTER_ALIGN (REGNO (reg
)) >= 4);
2054 /* Similar to s_register_operand, but does not allow hard integer
2057 f_register_operand (op
, mode
)
2059 enum machine_mode mode
;
2061 if (GET_MODE (op
) != mode
&& mode
!= VOIDmode
)
2064 if (GET_CODE (op
) == SUBREG
)
2065 op
= SUBREG_REG (op
);
2067 /* We don't consider registers whose class is NO_REGS
2068 to be a register operand. */
2069 return (GET_CODE (op
) == REG
2070 && (REGNO (op
) >= FIRST_PSEUDO_REGISTER
2071 || REGNO_REG_CLASS (REGNO (op
)) == FPU_REGS
));
2074 /* Return TRUE for valid operands for the rhs of an FPU instruction. */
2077 fpu_rhs_operand (op
, mode
)
2079 enum machine_mode mode
;
2081 if (s_register_operand (op
, mode
))
2083 else if (GET_CODE (op
) == CONST_DOUBLE
)
2084 return (const_double_rtx_ok_for_fpu (op
));
2090 fpu_add_operand (op
, mode
)
2092 enum machine_mode mode
;
2094 if (s_register_operand (op
, mode
))
2096 else if (GET_CODE (op
) == CONST_DOUBLE
)
2097 return (const_double_rtx_ok_for_fpu (op
)
2098 || neg_const_double_rtx_ok_for_fpu (op
));
2103 /* Return nonzero if OP is a constant power of two. */
2106 power_of_two_operand (op
, mode
)
2108 enum machine_mode mode
;
2110 if (GET_CODE (op
) == CONST_INT
)
2112 HOST_WIDE_INT value
= INTVAL(op
);
2113 return value
!= 0 && (value
& (value
- 1)) == 0;
2118 /* Return TRUE for a valid operand of a DImode operation.
2119 Either: REG, CONST_DOUBLE or MEM(DImode_address).
2120 Note that this disallows MEM(REG+REG), but allows
2121 MEM(PRE/POST_INC/DEC(REG)). */
2124 di_operand (op
, mode
)
2126 enum machine_mode mode
;
2128 if (s_register_operand (op
, mode
))
2131 switch (GET_CODE (op
))
2138 return memory_address_p (DImode
, XEXP (op
, 0));
2145 /* Return TRUE for a valid operand of a DFmode operation when -msoft-float.
2146 Either: REG, CONST_DOUBLE or MEM(DImode_address).
2147 Note that this disallows MEM(REG+REG), but allows
2148 MEM(PRE/POST_INC/DEC(REG)). */
2151 soft_df_operand (op
, mode
)
2153 enum machine_mode mode
;
2155 if (s_register_operand (op
, mode
))
2158 switch (GET_CODE (op
))
2164 return memory_address_p (DFmode
, XEXP (op
, 0));
2171 /* Return TRUE for valid index operands. */
2174 index_operand (op
, mode
)
2176 enum machine_mode mode
;
2178 return (s_register_operand(op
, mode
)
2179 || (immediate_operand (op
, mode
)
2180 && INTVAL (op
) < 4096 && INTVAL (op
) > -4096));
2183 /* Return TRUE for valid shifts by a constant. This also accepts any
2184 power of two on the (somewhat overly relaxed) assumption that the
2185 shift operator in this case was a mult. */
2188 const_shift_operand (op
, mode
)
2190 enum machine_mode mode
;
2192 return (power_of_two_operand (op
, mode
)
2193 || (immediate_operand (op
, mode
)
2194 && (INTVAL (op
) < 32 && INTVAL (op
) > 0)));
2197 /* Return TRUE for arithmetic operators which can be combined with a multiply
2201 shiftable_operator (x
, mode
)
2203 enum machine_mode mode
;
2205 if (GET_MODE (x
) != mode
)
2209 enum rtx_code code
= GET_CODE (x
);
2211 return (code
== PLUS
|| code
== MINUS
2212 || code
== IOR
|| code
== XOR
|| code
== AND
);
2216 /* Return TRUE for shift operators. */
2219 shift_operator (x
, mode
)
2221 enum machine_mode mode
;
2223 if (GET_MODE (x
) != mode
)
2227 enum rtx_code code
= GET_CODE (x
);
2230 return power_of_two_operand (XEXP (x
, 1));
2232 return (code
== ASHIFT
|| code
== ASHIFTRT
|| code
== LSHIFTRT
2233 || code
== ROTATERT
);
2237 int equality_operator (x
, mode
)
2239 enum machine_mode mode
;
2241 return GET_CODE (x
) == EQ
|| GET_CODE (x
) == NE
;
2244 /* Return TRUE for SMIN SMAX UMIN UMAX operators. */
2247 minmax_operator (x
, mode
)
2249 enum machine_mode mode
;
2251 enum rtx_code code
= GET_CODE (x
);
2253 if (GET_MODE (x
) != mode
)
2256 return code
== SMIN
|| code
== SMAX
|| code
== UMIN
|| code
== UMAX
;
2259 /* return TRUE if x is EQ or NE */
2261 /* Return TRUE if this is the condition code register, if we aren't given
2262 a mode, accept any class CCmode register */
2265 cc_register (x
, mode
)
2267 enum machine_mode mode
;
2269 if (mode
== VOIDmode
)
2271 mode
= GET_MODE (x
);
2272 if (GET_MODE_CLASS (mode
) != MODE_CC
)
2276 if (mode
== GET_MODE (x
) && GET_CODE (x
) == REG
&& REGNO (x
) == 24)
2282 /* Return TRUE if this is the condition code register, if we aren't given
2283 a mode, accept any class CCmode register which indicates a dominance
2287 dominant_cc_register (x
, mode
)
2289 enum machine_mode mode
;
2291 if (mode
== VOIDmode
)
2293 mode
= GET_MODE (x
);
2294 if (GET_MODE_CLASS (mode
) != MODE_CC
)
2298 if (mode
!= CC_DNEmode
&& mode
!= CC_DEQmode
2299 && mode
!= CC_DLEmode
&& mode
!= CC_DLTmode
2300 && mode
!= CC_DGEmode
&& mode
!= CC_DGTmode
2301 && mode
!= CC_DLEUmode
&& mode
!= CC_DLTUmode
2302 && mode
!= CC_DGEUmode
&& mode
!= CC_DGTUmode
)
2305 if (mode
== GET_MODE (x
) && GET_CODE (x
) == REG
&& REGNO (x
) == 24)
2311 /* Return TRUE if X references a SYMBOL_REF. */
2313 symbol_mentioned_p (x
)
2319 if (GET_CODE (x
) == SYMBOL_REF
)
2322 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2323 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2329 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2330 if (symbol_mentioned_p (XVECEXP (x
, i
, j
)))
2333 else if (fmt
[i
] == 'e' && symbol_mentioned_p (XEXP (x
, i
)))
2340 /* Return TRUE if X references a LABEL_REF. */
2342 label_mentioned_p (x
)
2348 if (GET_CODE (x
) == LABEL_REF
)
2351 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2352 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2358 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2359 if (label_mentioned_p (XVECEXP (x
, i
, j
)))
2362 else if (fmt
[i
] == 'e' && label_mentioned_p (XEXP (x
, i
)))
2373 enum rtx_code code
= GET_CODE (x
);
2377 else if (code
== SMIN
)
2379 else if (code
== UMIN
)
2381 else if (code
== UMAX
)
2387 /* Return 1 if memory locations are adjacent */
2390 adjacent_mem_locations (a
, b
)
2393 int val0
= 0, val1
= 0;
2396 if ((GET_CODE (XEXP (a
, 0)) == REG
2397 || (GET_CODE (XEXP (a
, 0)) == PLUS
2398 && GET_CODE (XEXP (XEXP (a
, 0), 1)) == CONST_INT
))
2399 && (GET_CODE (XEXP (b
, 0)) == REG
2400 || (GET_CODE (XEXP (b
, 0)) == PLUS
2401 && GET_CODE (XEXP (XEXP (b
, 0), 1)) == CONST_INT
)))
2403 if (GET_CODE (XEXP (a
, 0)) == PLUS
)
2405 reg0
= REGNO (XEXP (XEXP (a
, 0), 0));
2406 val0
= INTVAL (XEXP (XEXP (a
, 0), 1));
2409 reg0
= REGNO (XEXP (a
, 0));
2410 if (GET_CODE (XEXP (b
, 0)) == PLUS
)
2412 reg1
= REGNO (XEXP (XEXP (b
, 0), 0));
2413 val1
= INTVAL (XEXP (XEXP (b
, 0), 1));
2416 reg1
= REGNO (XEXP (b
, 0));
2417 return (reg0
== reg1
) && ((val1
- val0
) == 4 || (val0
- val1
) == 4);
2422 /* Return 1 if OP is a load multiple operation. It is known to be
2423 parallel and the first section will be tested. */
2426 load_multiple_operation (op
, mode
)
2428 enum machine_mode mode
;
2430 HOST_WIDE_INT count
= XVECLEN (op
, 0);
2433 HOST_WIDE_INT i
= 1, base
= 0;
2437 || GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2440 /* Check to see if this might be a write-back */
2441 if (GET_CODE (SET_SRC (elt
= XVECEXP (op
, 0, 0))) == PLUS
)
2446 /* Now check it more carefully */
2447 if (GET_CODE (SET_DEST (elt
)) != REG
2448 || GET_CODE (XEXP (SET_SRC (elt
), 0)) != REG
2449 || REGNO (XEXP (SET_SRC (elt
), 0)) != REGNO (SET_DEST (elt
))
2450 || GET_CODE (XEXP (SET_SRC (elt
), 1)) != CONST_INT
2451 || INTVAL (XEXP (SET_SRC (elt
), 1)) != (count
- 2) * 4
2452 || GET_CODE (XVECEXP (op
, 0, count
- 1)) != CLOBBER
2453 || GET_CODE (XEXP (XVECEXP (op
, 0, count
- 1), 0)) != REG
2454 || REGNO (XEXP (XVECEXP (op
, 0, count
- 1), 0))
2455 != REGNO (SET_DEST (elt
)))
2461 /* Perform a quick check so we don't blow up below. */
2463 || GET_CODE (XVECEXP (op
, 0, i
- 1)) != SET
2464 || GET_CODE (SET_DEST (XVECEXP (op
, 0, i
- 1))) != REG
2465 || GET_CODE (SET_SRC (XVECEXP (op
, 0, i
- 1))) != MEM
)
2468 dest_regno
= REGNO (SET_DEST (XVECEXP (op
, 0, i
- 1)));
2469 src_addr
= XEXP (SET_SRC (XVECEXP (op
, 0, i
- 1)), 0);
2471 for (; i
< count
; i
++)
2473 elt
= XVECEXP (op
, 0, i
);
2475 if (GET_CODE (elt
) != SET
2476 || GET_CODE (SET_DEST (elt
)) != REG
2477 || GET_MODE (SET_DEST (elt
)) != SImode
2478 || REGNO (SET_DEST (elt
)) != dest_regno
+ i
- base
2479 || GET_CODE (SET_SRC (elt
)) != MEM
2480 || GET_MODE (SET_SRC (elt
)) != SImode
2481 || GET_CODE (XEXP (SET_SRC (elt
), 0)) != PLUS
2482 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt
), 0), 0), src_addr
)
2483 || GET_CODE (XEXP (XEXP (SET_SRC (elt
), 0), 1)) != CONST_INT
2484 || INTVAL (XEXP (XEXP (SET_SRC (elt
), 0), 1)) != (i
- base
) * 4)
2491 /* Return 1 if OP is a store multiple operation. It is known to be
2492 parallel and the first section will be tested. */
2495 store_multiple_operation (op
, mode
)
2497 enum machine_mode mode
;
2499 HOST_WIDE_INT count
= XVECLEN (op
, 0);
2502 HOST_WIDE_INT i
= 1, base
= 0;
2506 || GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2509 /* Check to see if this might be a write-back */
2510 if (GET_CODE (SET_SRC (elt
= XVECEXP (op
, 0, 0))) == PLUS
)
2515 /* Now check it more carefully */
2516 if (GET_CODE (SET_DEST (elt
)) != REG
2517 || GET_CODE (XEXP (SET_SRC (elt
), 0)) != REG
2518 || REGNO (XEXP (SET_SRC (elt
), 0)) != REGNO (SET_DEST (elt
))
2519 || GET_CODE (XEXP (SET_SRC (elt
), 1)) != CONST_INT
2520 || INTVAL (XEXP (SET_SRC (elt
), 1)) != (count
- 2) * 4
2521 || GET_CODE (XVECEXP (op
, 0, count
- 1)) != CLOBBER
2522 || GET_CODE (XEXP (XVECEXP (op
, 0, count
- 1), 0)) != REG
2523 || REGNO (XEXP (XVECEXP (op
, 0, count
- 1), 0))
2524 != REGNO (SET_DEST (elt
)))
2530 /* Perform a quick check so we don't blow up below. */
2532 || GET_CODE (XVECEXP (op
, 0, i
- 1)) != SET
2533 || GET_CODE (SET_DEST (XVECEXP (op
, 0, i
- 1))) != MEM
2534 || GET_CODE (SET_SRC (XVECEXP (op
, 0, i
- 1))) != REG
)
2537 src_regno
= REGNO (SET_SRC (XVECEXP (op
, 0, i
- 1)));
2538 dest_addr
= XEXP (SET_DEST (XVECEXP (op
, 0, i
- 1)), 0);
2540 for (; i
< count
; i
++)
2542 elt
= XVECEXP (op
, 0, i
);
2544 if (GET_CODE (elt
) != SET
2545 || GET_CODE (SET_SRC (elt
)) != REG
2546 || GET_MODE (SET_SRC (elt
)) != SImode
2547 || REGNO (SET_SRC (elt
)) != src_regno
+ i
- base
2548 || GET_CODE (SET_DEST (elt
)) != MEM
2549 || GET_MODE (SET_DEST (elt
)) != SImode
2550 || GET_CODE (XEXP (SET_DEST (elt
), 0)) != PLUS
2551 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt
), 0), 0), dest_addr
)
2552 || GET_CODE (XEXP (XEXP (SET_DEST (elt
), 0), 1)) != CONST_INT
2553 || INTVAL (XEXP (XEXP (SET_DEST (elt
), 0), 1)) != (i
- base
) * 4)
2561 load_multiple_sequence (operands
, nops
, regs
, base
, load_offset
)
2566 HOST_WIDE_INT
*load_offset
;
2568 int unsorted_regs
[4];
2569 HOST_WIDE_INT unsorted_offsets
[4];
2574 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2575 extended if required. */
2576 if (nops
< 2 || nops
> 4)
2579 /* Loop over the operands and check that the memory references are
2580 suitable (ie immediate offsets from the same base register). At
2581 the same time, extract the target register, and the memory
2583 for (i
= 0; i
< nops
; i
++)
2588 /* Convert a subreg of a mem into the mem itself. */
2589 if (GET_CODE (operands
[nops
+ i
]) == SUBREG
)
2590 operands
[nops
+ i
] = alter_subreg(operands
[nops
+ i
]);
2592 if (GET_CODE (operands
[nops
+ i
]) != MEM
)
2595 /* Don't reorder volatile memory references; it doesn't seem worth
2596 looking for the case where the order is ok anyway. */
2597 if (MEM_VOLATILE_P (operands
[nops
+ i
]))
2600 offset
= const0_rtx
;
2602 if ((GET_CODE (reg
= XEXP (operands
[nops
+ i
], 0)) == REG
2603 || (GET_CODE (reg
) == SUBREG
2604 && GET_CODE (reg
= SUBREG_REG (reg
)) == REG
))
2605 || (GET_CODE (XEXP (operands
[nops
+ i
], 0)) == PLUS
2606 && ((GET_CODE (reg
= XEXP (XEXP (operands
[nops
+ i
], 0), 0))
2608 || (GET_CODE (reg
) == SUBREG
2609 && GET_CODE (reg
= SUBREG_REG (reg
)) == REG
))
2610 && (GET_CODE (offset
= XEXP (XEXP (operands
[nops
+ i
], 0), 1))
2615 base_reg
= REGNO(reg
);
2616 unsorted_regs
[0] = (GET_CODE (operands
[i
]) == REG
2617 ? REGNO (operands
[i
])
2618 : REGNO (SUBREG_REG (operands
[i
])));
2623 if (base_reg
!= REGNO (reg
))
2624 /* Not addressed from the same base register. */
2627 unsorted_regs
[i
] = (GET_CODE (operands
[i
]) == REG
2628 ? REGNO (operands
[i
])
2629 : REGNO (SUBREG_REG (operands
[i
])));
2630 if (unsorted_regs
[i
] < unsorted_regs
[order
[0]])
2634 /* If it isn't an integer register, or if it overwrites the
2635 base register but isn't the last insn in the list, then
2636 we can't do this. */
2637 if (unsorted_regs
[i
] < 0 || unsorted_regs
[i
] > 14
2638 || (i
!= nops
- 1 && unsorted_regs
[i
] == base_reg
))
2641 unsorted_offsets
[i
] = INTVAL (offset
);
2644 /* Not a suitable memory address. */
2648 /* All the useful information has now been extracted from the
2649 operands into unsorted_regs and unsorted_offsets; additionally,
2650 order[0] has been set to the lowest numbered register in the
2651 list. Sort the registers into order, and check that the memory
2652 offsets are ascending and adjacent. */
2654 for (i
= 1; i
< nops
; i
++)
2658 order
[i
] = order
[i
- 1];
2659 for (j
= 0; j
< nops
; j
++)
2660 if (unsorted_regs
[j
] > unsorted_regs
[order
[i
- 1]]
2661 && (order
[i
] == order
[i
- 1]
2662 || unsorted_regs
[j
] < unsorted_regs
[order
[i
]]))
2665 /* Have we found a suitable register? if not, one must be used more
2667 if (order
[i
] == order
[i
- 1])
2670 /* Is the memory address adjacent and ascending? */
2671 if (unsorted_offsets
[order
[i
]] != unsorted_offsets
[order
[i
- 1]] + 4)
2679 for (i
= 0; i
< nops
; i
++)
2680 regs
[i
] = unsorted_regs
[order
[i
]];
2682 *load_offset
= unsorted_offsets
[order
[0]];
2685 if (unsorted_offsets
[order
[0]] == 0)
2686 return 1; /* ldmia */
2688 if (unsorted_offsets
[order
[0]] == 4)
2689 return 2; /* ldmib */
2691 if (unsorted_offsets
[order
[nops
- 1]] == 0)
2692 return 3; /* ldmda */
2694 if (unsorted_offsets
[order
[nops
- 1]] == -4)
2695 return 4; /* ldmdb */
2697 /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm if
2698 the offset isn't small enough. The reason 2 ldrs are faster is because
2699 these ARMs are able to do more than one cache access in a single cycle.
2700 The ARM9 and StrongARM have Harvard caches, whilst the ARM8 has a double
2701 bandwidth cache. This means that these cores can do both an instruction
2702 fetch and a data fetch in a single cycle, so the trick of calculating the
2703 address into a scratch register (one of the result regs) and then doing a
2704 load multiple actually becomes slower (and no smaller in code size). That
2705 is the transformation
2707 ldr rd1, [rbase + offset]
2708 ldr rd2, [rbase + offset + 4]
2712 add rd1, rbase, offset
2713 ldmia rd1, {rd1, rd2}
2715 produces worse code -- '3 cycles + any stalls on rd2' instead of '2 cycles
2716 + any stalls on rd2'. On ARMs with only one cache access per cycle, the
2717 first sequence could never complete in less than 6 cycles, whereas the ldm
2718 sequence would only take 5 and would make better use of sequential accesses
2719 if not hitting the cache.
2721 We cheat here and test 'arm_ld_sched' which we currently know to only be
2722 true for the ARM8, ARM9 and StrongARM. If this ever changes, then the test
2723 below needs to be reworked. */
2724 if (nops
== 2 && arm_ld_sched
)
2727 /* Can't do it without setting up the offset, only do this if it takes
2728 no more than one insn. */
2729 return (const_ok_for_arm (unsorted_offsets
[order
[0]])
2730 || const_ok_for_arm (-unsorted_offsets
[order
[0]])) ? 5 : 0;
2734 emit_ldm_seq (operands
, nops
)
2740 HOST_WIDE_INT offset
;
2744 switch (load_multiple_sequence (operands
, nops
, regs
, &base_reg
, &offset
))
2747 strcpy (buf
, "ldm%?ia\t");
2751 strcpy (buf
, "ldm%?ib\t");
2755 strcpy (buf
, "ldm%?da\t");
2759 strcpy (buf
, "ldm%?db\t");
2764 sprintf (buf
, "add%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX
,
2765 reg_names
[regs
[0]], REGISTER_PREFIX
, reg_names
[base_reg
],
2768 sprintf (buf
, "sub%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX
,
2769 reg_names
[regs
[0]], REGISTER_PREFIX
, reg_names
[base_reg
],
2771 output_asm_insn (buf
, operands
);
2773 strcpy (buf
, "ldm%?ia\t");
2780 sprintf (buf
+ strlen (buf
), "%s%s, {%s%s", REGISTER_PREFIX
,
2781 reg_names
[base_reg
], REGISTER_PREFIX
, reg_names
[regs
[0]]);
2783 for (i
= 1; i
< nops
; i
++)
2784 sprintf (buf
+ strlen (buf
), ", %s%s", REGISTER_PREFIX
,
2785 reg_names
[regs
[i
]]);
2787 strcat (buf
, "}\t%@ phole ldm");
2789 output_asm_insn (buf
, operands
);
2794 store_multiple_sequence (operands
, nops
, regs
, base
, load_offset
)
2799 HOST_WIDE_INT
*load_offset
;
2801 int unsorted_regs
[4];
2802 HOST_WIDE_INT unsorted_offsets
[4];
2807 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2808 extended if required. */
2809 if (nops
< 2 || nops
> 4)
2812 /* Loop over the operands and check that the memory references are
2813 suitable (ie immediate offsets from the same base register). At
2814 the same time, extract the target register, and the memory
2816 for (i
= 0; i
< nops
; i
++)
2821 /* Convert a subreg of a mem into the mem itself. */
2822 if (GET_CODE (operands
[nops
+ i
]) == SUBREG
)
2823 operands
[nops
+ i
] = alter_subreg(operands
[nops
+ i
]);
2825 if (GET_CODE (operands
[nops
+ i
]) != MEM
)
2828 /* Don't reorder volatile memory references; it doesn't seem worth
2829 looking for the case where the order is ok anyway. */
2830 if (MEM_VOLATILE_P (operands
[nops
+ i
]))
2833 offset
= const0_rtx
;
2835 if ((GET_CODE (reg
= XEXP (operands
[nops
+ i
], 0)) == REG
2836 || (GET_CODE (reg
) == SUBREG
2837 && GET_CODE (reg
= SUBREG_REG (reg
)) == REG
))
2838 || (GET_CODE (XEXP (operands
[nops
+ i
], 0)) == PLUS
2839 && ((GET_CODE (reg
= XEXP (XEXP (operands
[nops
+ i
], 0), 0))
2841 || (GET_CODE (reg
) == SUBREG
2842 && GET_CODE (reg
= SUBREG_REG (reg
)) == REG
))
2843 && (GET_CODE (offset
= XEXP (XEXP (operands
[nops
+ i
], 0), 1))
2848 base_reg
= REGNO(reg
);
2849 unsorted_regs
[0] = (GET_CODE (operands
[i
]) == REG
2850 ? REGNO (operands
[i
])
2851 : REGNO (SUBREG_REG (operands
[i
])));
2856 if (base_reg
!= REGNO (reg
))
2857 /* Not addressed from the same base register. */
2860 unsorted_regs
[i
] = (GET_CODE (operands
[i
]) == REG
2861 ? REGNO (operands
[i
])
2862 : REGNO (SUBREG_REG (operands
[i
])));
2863 if (unsorted_regs
[i
] < unsorted_regs
[order
[0]])
2867 /* If it isn't an integer register, then we can't do this. */
2868 if (unsorted_regs
[i
] < 0 || unsorted_regs
[i
] > 14)
2871 unsorted_offsets
[i
] = INTVAL (offset
);
2874 /* Not a suitable memory address. */
2878 /* All the useful information has now been extracted from the
2879 operands into unsorted_regs and unsorted_offsets; additionally,
2880 order[0] has been set to the lowest numbered register in the
2881 list. Sort the registers into order, and check that the memory
2882 offsets are ascending and adjacent. */
2884 for (i
= 1; i
< nops
; i
++)
2888 order
[i
] = order
[i
- 1];
2889 for (j
= 0; j
< nops
; j
++)
2890 if (unsorted_regs
[j
] > unsorted_regs
[order
[i
- 1]]
2891 && (order
[i
] == order
[i
- 1]
2892 || unsorted_regs
[j
] < unsorted_regs
[order
[i
]]))
2895 /* Have we found a suitable register? if not, one must be used more
2897 if (order
[i
] == order
[i
- 1])
2900 /* Is the memory address adjacent and ascending? */
2901 if (unsorted_offsets
[order
[i
]] != unsorted_offsets
[order
[i
- 1]] + 4)
2909 for (i
= 0; i
< nops
; i
++)
2910 regs
[i
] = unsorted_regs
[order
[i
]];
2912 *load_offset
= unsorted_offsets
[order
[0]];
2915 if (unsorted_offsets
[order
[0]] == 0)
2916 return 1; /* stmia */
2918 if (unsorted_offsets
[order
[0]] == 4)
2919 return 2; /* stmib */
2921 if (unsorted_offsets
[order
[nops
- 1]] == 0)
2922 return 3; /* stmda */
2924 if (unsorted_offsets
[order
[nops
- 1]] == -4)
2925 return 4; /* stmdb */
2931 emit_stm_seq (operands
, nops
)
2937 HOST_WIDE_INT offset
;
2941 switch (store_multiple_sequence (operands
, nops
, regs
, &base_reg
, &offset
))
2944 strcpy (buf
, "stm%?ia\t");
2948 strcpy (buf
, "stm%?ib\t");
2952 strcpy (buf
, "stm%?da\t");
2956 strcpy (buf
, "stm%?db\t");
2963 sprintf (buf
+ strlen (buf
), "%s%s, {%s%s", REGISTER_PREFIX
,
2964 reg_names
[base_reg
], REGISTER_PREFIX
, reg_names
[regs
[0]]);
2966 for (i
= 1; i
< nops
; i
++)
2967 sprintf (buf
+ strlen (buf
), ", %s%s", REGISTER_PREFIX
,
2968 reg_names
[regs
[i
]]);
2970 strcat (buf
, "}\t%@ phole stm");
2972 output_asm_insn (buf
, operands
);
2977 multi_register_push (op
, mode
)
2979 enum machine_mode mode
;
2981 if (GET_CODE (op
) != PARALLEL
2982 || (GET_CODE (XVECEXP (op
, 0, 0)) != SET
)
2983 || (GET_CODE (SET_SRC (XVECEXP (op
, 0, 0))) != UNSPEC
)
2984 || (XINT (SET_SRC (XVECEXP (op
, 0, 0)), 1) != 2))
2991 /* Routines for use with attributes */
2993 /* Return nonzero if ATTR is a valid attribute for DECL.
2994 ATTRIBUTES are any existing attributes and ARGS are the arguments
2997 Supported attributes:
2999 naked: don't output any prologue or epilogue code, the user is assumed
3000 to do the right thing. */
3003 arm_valid_machine_decl_attribute (decl
, attributes
, attr
, args
)
3009 if (args
!= NULL_TREE
)
3012 if (is_attribute_p ("naked", attr
))
3013 return TREE_CODE (decl
) == FUNCTION_DECL
;
3017 /* Return non-zero if FUNC is a naked function. */
3020 arm_naked_function_p (func
)
3025 if (TREE_CODE (func
) != FUNCTION_DECL
)
3028 a
= lookup_attribute ("naked", DECL_MACHINE_ATTRIBUTES (func
));
3029 return a
!= NULL_TREE
;
3032 /* Routines for use in generating RTL */
3035 arm_gen_load_multiple (base_regno
, count
, from
, up
, write_back
, unchanging_p
,
3036 in_struct_p
, scalar_p
)
3048 int sign
= up
? 1 : -1;
3051 result
= gen_rtx_PARALLEL (VOIDmode
,
3052 rtvec_alloc (count
+ (write_back
? 2 : 0)));
3055 XVECEXP (result
, 0, 0)
3056 = gen_rtx_SET (GET_MODE (from
), from
,
3057 plus_constant (from
, count
* 4 * sign
));
3062 for (j
= 0; i
< count
; i
++, j
++)
3064 mem
= gen_rtx_MEM (SImode
, plus_constant (from
, j
* 4 * sign
));
3065 RTX_UNCHANGING_P (mem
) = unchanging_p
;
3066 MEM_IN_STRUCT_P (mem
) = in_struct_p
;
3067 MEM_SCALAR_P (mem
) = scalar_p
;
3068 XVECEXP (result
, 0, i
)
3069 = gen_rtx_SET (VOIDmode
, gen_rtx_REG (SImode
, base_regno
+ j
), mem
);
3073 XVECEXP (result
, 0, i
) = gen_rtx_CLOBBER (SImode
, from
);
3079 arm_gen_store_multiple (base_regno
, count
, to
, up
, write_back
, unchanging_p
,
3080 in_struct_p
, scalar_p
)
3092 int sign
= up
? 1 : -1;
3095 result
= gen_rtx_PARALLEL (VOIDmode
,
3096 rtvec_alloc (count
+ (write_back
? 2 : 0)));
3099 XVECEXP (result
, 0, 0)
3100 = gen_rtx_SET (GET_MODE (to
), to
,
3101 plus_constant (to
, count
* 4 * sign
));
3106 for (j
= 0; i
< count
; i
++, j
++)
3108 mem
= gen_rtx_MEM (SImode
, plus_constant (to
, j
* 4 * sign
));
3109 RTX_UNCHANGING_P (mem
) = unchanging_p
;
3110 MEM_IN_STRUCT_P (mem
) = in_struct_p
;
3111 MEM_SCALAR_P (mem
) = scalar_p
;
3113 XVECEXP (result
, 0, i
)
3114 = gen_rtx_SET (VOIDmode
, mem
, gen_rtx_REG (SImode
, base_regno
+ j
));
3118 XVECEXP (result
, 0, i
) = gen_rtx_CLOBBER (SImode
, to
);
3124 arm_gen_movstrqi (operands
)
3127 HOST_WIDE_INT in_words_to_go
, out_words_to_go
, last_bytes
;
3130 rtx st_src
, st_dst
, fin_src
, fin_dst
;
3131 rtx part_bytes_reg
= NULL
;
3133 int dst_unchanging_p
, dst_in_struct_p
, src_unchanging_p
, src_in_struct_p
;
3134 int dst_scalar_p
, src_scalar_p
;
3136 if (GET_CODE (operands
[2]) != CONST_INT
3137 || GET_CODE (operands
[3]) != CONST_INT
3138 || INTVAL (operands
[2]) > 64
3139 || INTVAL (operands
[3]) & 3)
3142 st_dst
= XEXP (operands
[0], 0);
3143 st_src
= XEXP (operands
[1], 0);
3145 dst_unchanging_p
= RTX_UNCHANGING_P (operands
[0]);
3146 dst_in_struct_p
= MEM_IN_STRUCT_P (operands
[0]);
3147 dst_scalar_p
= MEM_SCALAR_P (operands
[0]);
3148 src_unchanging_p
= RTX_UNCHANGING_P (operands
[1]);
3149 src_in_struct_p
= MEM_IN_STRUCT_P (operands
[1]);
3150 src_scalar_p
= MEM_SCALAR_P (operands
[1]);
3152 fin_dst
= dst
= copy_to_mode_reg (SImode
, st_dst
);
3153 fin_src
= src
= copy_to_mode_reg (SImode
, st_src
);
3155 in_words_to_go
= (INTVAL (operands
[2]) + 3) / 4;
3156 out_words_to_go
= INTVAL (operands
[2]) / 4;
3157 last_bytes
= INTVAL (operands
[2]) & 3;
3159 if (out_words_to_go
!= in_words_to_go
&& ((in_words_to_go
- 1) & 3) != 0)
3160 part_bytes_reg
= gen_rtx_REG (SImode
, (in_words_to_go
- 1) & 3);
3162 for (i
= 0; in_words_to_go
>= 2; i
+=4)
3164 if (in_words_to_go
> 4)
3165 emit_insn (arm_gen_load_multiple (0, 4, src
, TRUE
, TRUE
,
3170 emit_insn (arm_gen_load_multiple (0, in_words_to_go
, src
, TRUE
,
3171 FALSE
, src_unchanging_p
,
3172 src_in_struct_p
, src_scalar_p
));
3174 if (out_words_to_go
)
3176 if (out_words_to_go
> 4)
3177 emit_insn (arm_gen_store_multiple (0, 4, dst
, TRUE
, TRUE
,
3181 else if (out_words_to_go
!= 1)
3182 emit_insn (arm_gen_store_multiple (0, out_words_to_go
,
3191 mem
= gen_rtx_MEM (SImode
, dst
);
3192 RTX_UNCHANGING_P (mem
) = dst_unchanging_p
;
3193 MEM_IN_STRUCT_P (mem
) = dst_in_struct_p
;
3194 MEM_SCALAR_P (mem
) = dst_scalar_p
;
3195 emit_move_insn (mem
, gen_rtx_REG (SImode
, 0));
3196 if (last_bytes
!= 0)
3197 emit_insn (gen_addsi3 (dst
, dst
, GEN_INT (4)));
3201 in_words_to_go
-= in_words_to_go
< 4 ? in_words_to_go
: 4;
3202 out_words_to_go
-= out_words_to_go
< 4 ? out_words_to_go
: 4;
3205 /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */
3206 if (out_words_to_go
)
3210 mem
= gen_rtx_MEM (SImode
, src
);
3211 RTX_UNCHANGING_P (mem
) = src_unchanging_p
;
3212 MEM_IN_STRUCT_P (mem
) = src_in_struct_p
;
3213 MEM_SCALAR_P (mem
) = src_scalar_p
;
3214 emit_move_insn (sreg
= gen_reg_rtx (SImode
), mem
);
3215 emit_move_insn (fin_src
= gen_reg_rtx (SImode
), plus_constant (src
, 4));
3217 mem
= gen_rtx_MEM (SImode
, dst
);
3218 RTX_UNCHANGING_P (mem
) = dst_unchanging_p
;
3219 MEM_IN_STRUCT_P (mem
) = dst_in_struct_p
;
3220 MEM_SCALAR_P (mem
) = dst_scalar_p
;
3221 emit_move_insn (mem
, sreg
);
3222 emit_move_insn (fin_dst
= gen_reg_rtx (SImode
), plus_constant (dst
, 4));
3225 if (in_words_to_go
) /* Sanity check */
3231 if (in_words_to_go
< 0)
3234 mem
= gen_rtx_MEM (SImode
, src
);
3235 RTX_UNCHANGING_P (mem
) = src_unchanging_p
;
3236 MEM_IN_STRUCT_P (mem
) = src_in_struct_p
;
3237 MEM_SCALAR_P (mem
) = src_scalar_p
;
3238 part_bytes_reg
= copy_to_mode_reg (SImode
, mem
);
3241 if (BYTES_BIG_ENDIAN
&& last_bytes
)
3243 rtx tmp
= gen_reg_rtx (SImode
);
3245 if (part_bytes_reg
== NULL
)
3248 /* The bytes we want are in the top end of the word */
3249 emit_insn (gen_lshrsi3 (tmp
, part_bytes_reg
,
3250 GEN_INT (8 * (4 - last_bytes
))));
3251 part_bytes_reg
= tmp
;
3255 mem
= gen_rtx_MEM (QImode
, plus_constant (dst
, last_bytes
- 1));
3256 RTX_UNCHANGING_P (mem
) = dst_unchanging_p
;
3257 MEM_IN_STRUCT_P (mem
) = dst_in_struct_p
;
3258 MEM_SCALAR_P (mem
) = dst_scalar_p
;
3259 emit_move_insn (mem
, gen_rtx_SUBREG (QImode
, part_bytes_reg
, 0));
3262 tmp
= gen_reg_rtx (SImode
);
3263 emit_insn (gen_lshrsi3 (tmp
, part_bytes_reg
, GEN_INT (8)));
3264 part_bytes_reg
= tmp
;
3273 if (part_bytes_reg
== NULL
)
3276 mem
= gen_rtx_MEM (QImode
, dst
);
3277 RTX_UNCHANGING_P (mem
) = dst_unchanging_p
;
3278 MEM_IN_STRUCT_P (mem
) = dst_in_struct_p
;
3279 MEM_SCALAR_P (mem
) = dst_scalar_p
;
3280 emit_move_insn (mem
, gen_rtx_SUBREG (QImode
, part_bytes_reg
, 0));
3283 rtx tmp
= gen_reg_rtx (SImode
);
3285 emit_insn (gen_addsi3 (dst
, dst
, const1_rtx
));
3286 emit_insn (gen_lshrsi3 (tmp
, part_bytes_reg
, GEN_INT (8)));
3287 part_bytes_reg
= tmp
;
3295 /* Generate a memory reference for a half word, such that it will be loaded
3296 into the top 16 bits of the word. We can assume that the address is
3297 known to be alignable and of the form reg, or plus (reg, const). */
3299 gen_rotated_half_load (memref
)
3302 HOST_WIDE_INT offset
= 0;
3303 rtx base
= XEXP (memref
, 0);
3305 if (GET_CODE (base
) == PLUS
)
3307 offset
= INTVAL (XEXP (base
, 1));
3308 base
= XEXP (base
, 0);
3311 /* If we aren't allowed to generate unaligned addresses, then fail. */
3312 if (TARGET_SHORT_BY_BYTES
3313 && ((BYTES_BIG_ENDIAN
? 1 : 0) ^ ((offset
& 2) == 0)))
3316 base
= gen_rtx_MEM (SImode
, plus_constant (base
, offset
& ~2));
3318 if ((BYTES_BIG_ENDIAN
? 1 : 0) ^ ((offset
& 2) == 2))
3321 return gen_rtx_ROTATE (SImode
, base
, GEN_INT (16));
3324 static enum machine_mode
3325 select_dominance_cc_mode (op
, x
, y
, cond_or
)
3329 HOST_WIDE_INT cond_or
;
3331 enum rtx_code cond1
, cond2
;
3334 /* Currently we will probably get the wrong result if the individual
3335 comparisons are not simple. This also ensures that it is safe to
3336 reverse a comparison if necessary. */
3337 if ((arm_select_cc_mode (cond1
= GET_CODE (x
), XEXP (x
, 0), XEXP (x
, 1))
3339 || (arm_select_cc_mode (cond2
= GET_CODE (y
), XEXP (y
, 0), XEXP (y
, 1))
3344 cond1
= reverse_condition (cond1
);
3346 /* If the comparisons are not equal, and one doesn't dominate the other,
3347 then we can't do this. */
3349 && ! comparison_dominates_p (cond1
, cond2
)
3350 && (swapped
= 1, ! comparison_dominates_p (cond2
, cond1
)))
3355 enum rtx_code temp
= cond1
;
3363 if (cond2
== EQ
|| ! cond_or
)
3368 case LE
: return CC_DLEmode
;
3369 case LEU
: return CC_DLEUmode
;
3370 case GE
: return CC_DGEmode
;
3371 case GEU
: return CC_DGEUmode
;
3378 if (cond2
== LT
|| ! cond_or
)
3387 if (cond2
== GT
|| ! cond_or
)
3396 if (cond2
== LTU
|| ! cond_or
)
3405 if (cond2
== GTU
|| ! cond_or
)
3413 /* The remaining cases only occur when both comparisons are the
3438 arm_select_cc_mode (op
, x
, y
)
3443 /* All floating point compares return CCFP if it is an equality
3444 comparison, and CCFPE otherwise. */
3445 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
3446 return (op
== EQ
|| op
== NE
) ? CCFPmode
: CCFPEmode
;
3448 /* A compare with a shifted operand. Because of canonicalization, the
3449 comparison will have to be swapped when we emit the assembler. */
3450 if (GET_MODE (y
) == SImode
&& GET_CODE (y
) == REG
3451 && (GET_CODE (x
) == ASHIFT
|| GET_CODE (x
) == ASHIFTRT
3452 || GET_CODE (x
) == LSHIFTRT
|| GET_CODE (x
) == ROTATE
3453 || GET_CODE (x
) == ROTATERT
))
3456 /* This is a special case that is used by combine to allow a
3457 comparison of a shifted byte load to be split into a zero-extend
3458 followed by a comparison of the shifted integer (only valid for
3459 equalities and unsigned inequalities). */
3460 if (GET_MODE (x
) == SImode
3461 && GET_CODE (x
) == ASHIFT
3462 && GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 24
3463 && GET_CODE (XEXP (x
, 0)) == SUBREG
3464 && GET_CODE (SUBREG_REG (XEXP (x
, 0))) == MEM
3465 && GET_MODE (SUBREG_REG (XEXP (x
, 0))) == QImode
3466 && (op
== EQ
|| op
== NE
3467 || op
== GEU
|| op
== GTU
|| op
== LTU
|| op
== LEU
)
3468 && GET_CODE (y
) == CONST_INT
)
3471 /* An operation that sets the condition codes as a side-effect, the
3472 V flag is not set correctly, so we can only use comparisons where
3473 this doesn't matter. (For LT and GE we can use "mi" and "pl"
3475 if (GET_MODE (x
) == SImode
3477 && (op
== EQ
|| op
== NE
|| op
== LT
|| op
== GE
)
3478 && (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
3479 || GET_CODE (x
) == AND
|| GET_CODE (x
) == IOR
3480 || GET_CODE (x
) == XOR
|| GET_CODE (x
) == MULT
3481 || GET_CODE (x
) == NOT
|| GET_CODE (x
) == NEG
3482 || GET_CODE (x
) == LSHIFTRT
3483 || GET_CODE (x
) == ASHIFT
|| GET_CODE (x
) == ASHIFTRT
3484 || GET_CODE (x
) == ROTATERT
|| GET_CODE (x
) == ZERO_EXTRACT
))
3487 /* A construct for a conditional compare, if the false arm contains
3488 0, then both conditions must be true, otherwise either condition
3489 must be true. Not all conditions are possible, so CCmode is
3490 returned if it can't be done. */
3491 if (GET_CODE (x
) == IF_THEN_ELSE
3492 && (XEXP (x
, 2) == const0_rtx
3493 || XEXP (x
, 2) == const1_rtx
)
3494 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == '<'
3495 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 1))) == '<')
3496 return select_dominance_cc_mode (op
, XEXP (x
, 0), XEXP (x
, 1),
3497 INTVAL (XEXP (x
, 2)));
3499 if (GET_MODE (x
) == QImode
&& (op
== EQ
|| op
== NE
))
3502 if (GET_MODE (x
) == SImode
&& (op
== LTU
|| op
== GEU
)
3503 && GET_CODE (x
) == PLUS
3504 && (rtx_equal_p (XEXP (x
, 0), y
) || rtx_equal_p (XEXP (x
, 1), y
)))
3510 /* X and Y are two things to compare using CODE. Emit the compare insn and
3511 return the rtx for register 0 in the proper mode. FP means this is a
3512 floating point compare: I don't think that it is needed on the arm. */
3515 gen_compare_reg (code
, x
, y
, fp
)
3520 enum machine_mode mode
= SELECT_CC_MODE (code
, x
, y
);
3521 rtx cc_reg
= gen_rtx_REG (mode
, 24);
3523 emit_insn (gen_rtx_SET (VOIDmode
, cc_reg
,
3524 gen_rtx_COMPARE (mode
, x
, y
)));
3530 arm_reload_in_hi (operands
)
3533 rtx base
= find_replacement (&XEXP (operands
[1], 0));
3535 emit_insn (gen_zero_extendqisi2 (operands
[2], gen_rtx_MEM (QImode
, base
)));
3536 /* Handle the case where the address is too complex to be offset by 1. */
3537 if (GET_CODE (base
) == MINUS
3538 || (GET_CODE (base
) == PLUS
&& GET_CODE (XEXP (base
, 1)) != CONST_INT
))
3540 rtx base_plus
= gen_rtx_REG (SImode
, REGNO (operands
[0]));
3542 emit_insn (gen_rtx_SET (VOIDmode
, base_plus
, base
));
3546 emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode
, operands
[0], 0),
3547 gen_rtx_MEM (QImode
,
3548 plus_constant (base
, 1))));
3549 if (BYTES_BIG_ENDIAN
)
3550 emit_insn (gen_rtx_SET (VOIDmode
, gen_rtx_SUBREG (SImode
, operands
[0], 0),
3551 gen_rtx_IOR (SImode
,
3554 gen_rtx_SUBREG (SImode
, operands
[0], 0),
3558 emit_insn (gen_rtx_SET (VOIDmode
, gen_rtx_SUBREG (SImode
, operands
[0], 0),
3559 gen_rtx_IOR (SImode
,
3560 gen_rtx_ASHIFT (SImode
, operands
[2],
3562 gen_rtx_SUBREG (SImode
, operands
[0],
3567 arm_reload_out_hi (operands
)
3570 rtx base
= find_replacement (&XEXP (operands
[0], 0));
3572 if (BYTES_BIG_ENDIAN
)
3574 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, plus_constant (base
, 1)),
3575 gen_rtx_SUBREG (QImode
, operands
[1], 0)));
3576 emit_insn (gen_lshrsi3 (operands
[2],
3577 gen_rtx_SUBREG (SImode
, operands
[1], 0),
3579 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, base
),
3580 gen_rtx_SUBREG (QImode
, operands
[2], 0)));
3584 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, base
),
3585 gen_rtx_SUBREG (QImode
, operands
[1], 0)));
3586 emit_insn (gen_lshrsi3 (operands
[2],
3587 gen_rtx_SUBREG (SImode
, operands
[1], 0),
3589 emit_insn (gen_movqi (gen_rtx_MEM (QImode
, plus_constant (base
, 1)),
3590 gen_rtx_SUBREG (QImode
, operands
[2], 0)));
3594 /* Routines for manipulation of the constant pool. */
3595 /* This is unashamedly hacked from the version in sh.c, since the problem is
3596 extremely similar. */
3598 /* Arm instructions cannot load a large constant into a register,
3599 constants have to come from a pc relative load. The reference of a pc
3600 relative load instruction must be less than 1k infront of the instruction.
3601 This means that we often have to dump a constant inside a function, and
3602 generate code to branch around it.
3604 It is important to minimize this, since the branches will slow things
3605 down and make things bigger.
3607 Worst case code looks like:
3623 We fix this by performing a scan before scheduling, which notices which
3624 instructions need to have their operands fetched from the constant table
3625 and builds the table.
3630 scan, find an instruction which needs a pcrel move. Look forward, find th
3631 last barrier which is within MAX_COUNT bytes of the requirement.
3632 If there isn't one, make one. Process all the instructions between
3633 the find and the barrier.
3635 In the above example, we can tell that L3 is within 1k of L1, so
3636 the first move can be shrunk from the 2 insn+constant sequence into
3637 just 1 insn, and the constant moved to L3 to make:
3648 Then the second move becomes the target for the shortening process.
3654 rtx value
; /* Value in table */
3655 HOST_WIDE_INT next_offset
;
3656 enum machine_mode mode
; /* Mode of value */
3659 /* The maximum number of constants that can fit into one pool, since
3660 the pc relative range is 0...1020 bytes and constants are at least 4
3663 #define MAX_POOL_SIZE (1020/4)
3664 static pool_node pool_vector
[MAX_POOL_SIZE
];
3665 static int pool_size
;
3666 static rtx pool_vector_label
;
3668 /* Add a constant to the pool and return its offset within the current
3671 X is the rtx we want to replace. MODE is its mode. On return,
3672 ADDRESS_ONLY will be non-zero if we really want the address of such
3673 a constant, not the constant itself. */
3674 static HOST_WIDE_INT
3675 add_constant (x
, mode
, address_only
)
3677 enum machine_mode mode
;
3681 HOST_WIDE_INT offset
;
3685 if (mode
== SImode
&& GET_CODE (x
) == MEM
&& CONSTANT_P (XEXP (x
, 0))
3686 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
3687 x
= get_pool_constant (XEXP (x
, 0));
3688 else if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P(x
))
3691 mode
= get_pool_mode (x
);
3692 x
= get_pool_constant (x
);
3694 #ifndef AOF_ASSEMBLER
3695 else if (GET_CODE (x
) == UNSPEC
&& XINT (x
, 1) == 3)
3696 x
= XVECEXP (x
, 0, 0);
3699 #ifdef AOF_ASSEMBLER
3700 /* PIC Symbol references need to be converted into offsets into the
3702 if (flag_pic
&& GET_CODE (x
) == SYMBOL_REF
)
3703 x
= aof_pic_entry (x
);
3704 #endif /* AOF_ASSEMBLER */
3706 /* First see if we've already got it */
3707 for (i
= 0; i
< pool_size
; i
++)
3709 if (GET_CODE (x
) == pool_vector
[i
].value
->code
3710 && mode
== pool_vector
[i
].mode
)
3712 if (GET_CODE (x
) == CODE_LABEL
)
3714 if (XINT (x
, 3) != XINT (pool_vector
[i
].value
, 3))
3717 if (rtx_equal_p (x
, pool_vector
[i
].value
))
3718 return pool_vector
[i
].next_offset
- GET_MODE_SIZE (mode
);
3722 /* Need a new one */
3723 pool_vector
[pool_size
].next_offset
= GET_MODE_SIZE (mode
);
3726 pool_vector_label
= gen_label_rtx ();
3728 pool_vector
[pool_size
].next_offset
3729 += (offset
= pool_vector
[pool_size
- 1].next_offset
);
3731 pool_vector
[pool_size
].value
= x
;
3732 pool_vector
[pool_size
].mode
= mode
;
3737 /* Output the literal table */
3744 scan
= emit_label_after (gen_label_rtx (), scan
);
3745 scan
= emit_insn_after (gen_align_4 (), scan
);
3746 scan
= emit_label_after (pool_vector_label
, scan
);
3748 for (i
= 0; i
< pool_size
; i
++)
3750 pool_node
*p
= pool_vector
+ i
;
3752 switch (GET_MODE_SIZE (p
->mode
))
3755 scan
= emit_insn_after (gen_consttable_4 (p
->value
), scan
);
3759 scan
= emit_insn_after (gen_consttable_8 (p
->value
), scan
);
3768 scan
= emit_insn_after (gen_consttable_end (), scan
);
3769 scan
= emit_barrier_after (scan
);
3773 /* Non zero if the src operand needs to be fixed up */
3775 fixit (src
, mode
, destreg
)
3777 enum machine_mode mode
;
3780 if (CONSTANT_P (src
))
3782 if (GET_CODE (src
) == CONST_INT
)
3783 return (! const_ok_for_arm (INTVAL (src
))
3784 && ! const_ok_for_arm (~INTVAL (src
)));
3785 if (GET_CODE (src
) == CONST_DOUBLE
)
3786 return (GET_MODE (src
) == VOIDmode
3788 || (! const_double_rtx_ok_for_fpu (src
)
3789 && ! neg_const_double_rtx_ok_for_fpu (src
)));
3790 return symbol_mentioned_p (src
);
3792 #ifndef AOF_ASSEMBLER
3793 else if (GET_CODE (src
) == UNSPEC
&& XINT (src
, 1) == 3)
3797 return (mode
== SImode
&& GET_CODE (src
) == MEM
3798 && GET_CODE (XEXP (src
, 0)) == SYMBOL_REF
3799 && CONSTANT_POOL_ADDRESS_P (XEXP (src
, 0)));
3802 /* Find the last barrier less than MAX_COUNT bytes from FROM, or create one. */
3804 find_barrier (from
, max_count
)
3809 rtx found_barrier
= 0;
3812 while (from
&& count
< max_count
)
3816 if (GET_CODE (from
) == BARRIER
)
3817 found_barrier
= from
;
3819 /* Count the length of this insn */
3820 if (GET_CODE (from
) == INSN
3821 && GET_CODE (PATTERN (from
)) == SET
3822 && CONSTANT_P (SET_SRC (PATTERN (from
)))
3823 && CONSTANT_POOL_ADDRESS_P (SET_SRC (PATTERN (from
))))
3825 /* Handle table jumps as a single entity. */
3826 else if (GET_CODE (from
) == JUMP_INSN
3827 && JUMP_LABEL (from
) != 0
3828 && ((tmp
= next_real_insn (JUMP_LABEL (from
)))
3829 == next_real_insn (from
))
3831 && GET_CODE (tmp
) == JUMP_INSN
3832 && (GET_CODE (PATTERN (tmp
)) == ADDR_VEC
3833 || GET_CODE (PATTERN (tmp
)) == ADDR_DIFF_VEC
))
3835 int elt
= GET_CODE (PATTERN (tmp
)) == ADDR_DIFF_VEC
? 1 : 0;
3836 count
+= (get_attr_length (from
)
3837 + GET_MODE_SIZE (SImode
) * XVECLEN (PATTERN (tmp
), elt
));
3838 /* Continue after the dispatch table. */
3840 from
= NEXT_INSN (tmp
);
3844 count
+= get_attr_length (from
);
3847 from
= NEXT_INSN (from
);
3850 if (! found_barrier
)
3852 /* We didn't find a barrier in time to
3853 dump our stuff, so we'll make one. */
3854 rtx label
= gen_label_rtx ();
3857 from
= PREV_INSN (last
);
3859 from
= get_last_insn ();
3861 /* Walk back to be just before any jump. */
3862 while (GET_CODE (from
) == JUMP_INSN
3863 || GET_CODE (from
) == NOTE
3864 || GET_CODE (from
) == CODE_LABEL
)
3865 from
= PREV_INSN (from
);
3867 from
= emit_jump_insn_after (gen_jump (label
), from
);
3868 JUMP_LABEL (from
) = label
;
3869 found_barrier
= emit_barrier_after (from
);
3870 emit_label_after (label
, found_barrier
);
3873 return found_barrier
;
3876 /* Non zero if the insn is a move instruction which needs to be fixed. */
3881 if (!INSN_DELETED_P (insn
)
3882 && GET_CODE (insn
) == INSN
3883 && GET_CODE (PATTERN (insn
)) == SET
)
3885 rtx pat
= PATTERN (insn
);
3886 rtx src
= SET_SRC (pat
);
3887 rtx dst
= SET_DEST (pat
);
3889 enum machine_mode mode
= GET_MODE (dst
);
3894 if (GET_CODE (dst
) == REG
)
3895 destreg
= REGNO (dst
);
3896 else if (GET_CODE (dst
) == SUBREG
&& GET_CODE (SUBREG_REG (dst
)) == REG
)
3897 destreg
= REGNO (SUBREG_REG (dst
));
3901 return fixit (src
, mode
, destreg
);
3914 /* The ldr instruction can work with up to a 4k offset, and most constants
3915 will be loaded with one of these instructions; however, the adr
3916 instruction and the ldf instructions only work with a 1k offset. This
3917 code needs to be rewritten to use the 4k offset when possible, and to
3918 adjust when a 1k offset is needed. For now we just use a 1k offset
3922 /* Floating point operands can't work further than 1024 bytes from the
3923 PC, so to make things simple we restrict all loads for such functions.
3925 if (TARGET_HARD_FLOAT
)
3929 for (regno
= 16; regno
< 24; regno
++)
3930 if (regs_ever_live
[regno
])
3940 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
3942 if (broken_move (insn
))
3944 /* This is a broken move instruction, scan ahead looking for
3945 a barrier to stick the constant table behind */
3947 rtx barrier
= find_barrier (insn
, count_size
);
3949 /* Now find all the moves between the points and modify them */
3950 for (scan
= insn
; scan
!= barrier
; scan
= NEXT_INSN (scan
))
3952 if (broken_move (scan
))
3954 /* This is a broken move instruction, add it to the pool */
3955 rtx pat
= PATTERN (scan
);
3956 rtx src
= SET_SRC (pat
);
3957 rtx dst
= SET_DEST (pat
);
3958 enum machine_mode mode
= GET_MODE (dst
);
3959 HOST_WIDE_INT offset
;
3966 /* If this is an HImode constant load, convert it into
3967 an SImode constant load. Since the register is always
3968 32 bits this is safe. We have to do this, since the
3969 load pc-relative instruction only does a 32-bit load. */
3973 if (GET_CODE (dst
) != REG
)
3975 PUT_MODE (dst
, SImode
);
3978 offset
= add_constant (src
, mode
, &address_only
);
3979 addr
= plus_constant (gen_rtx_LABEL_REF (VOIDmode
,
3983 /* If we only want the address of the pool entry, or
3984 for wide moves to integer regs we need to split
3985 the address calculation off into a separate insn.
3986 If necessary, the load can then be done with a
3987 load-multiple. This is safe, since we have
3988 already noted the length of such insns to be 8,
3989 and we are immediately over-writing the scratch
3990 we have grabbed with the final result. */
3991 if ((address_only
|| GET_MODE_SIZE (mode
) > 4)
3992 && (scratch
= REGNO (dst
)) < 16)
3999 reg
= gen_rtx_REG (SImode
, scratch
);
4001 newinsn
= emit_insn_after (gen_movaddr (reg
, addr
),
4008 newsrc
= gen_rtx_MEM (mode
, addr
);
4010 /* XXX Fixme -- I think the following is bogus. */
4011 /* Build a jump insn wrapper around the move instead
4012 of an ordinary insn, because we want to have room for
4013 the target label rtx in fld[7], which an ordinary
4014 insn doesn't have. */
4016 = emit_jump_insn_after (gen_rtx_SET (VOIDmode
, dst
,
4019 JUMP_LABEL (newinsn
) = pool_vector_label
;
4021 /* But it's still an ordinary insn */
4022 PUT_CODE (newinsn
, INSN
);
4030 dump_table (barrier
);
4035 after_arm_reorg
= 1;
4039 /* Routines to output assembly language. */
4041 /* If the rtx is the correct value then return the string of the number.
4042 In this way we can ensure that valid double constants are generated even
4043 when cross compiling. */
4045 fp_immediate_constant (x
)
4051 if (!fpa_consts_inited
)
4054 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
4055 for (i
= 0; i
< 8; i
++)
4056 if (REAL_VALUES_EQUAL (r
, values_fpa
[i
]))
4057 return strings_fpa
[i
];
4062 /* As for fp_immediate_constant, but value is passed directly, not in rtx. */
4064 fp_const_from_val (r
)
4069 if (! fpa_consts_inited
)
4072 for (i
= 0; i
< 8; i
++)
4073 if (REAL_VALUES_EQUAL (*r
, values_fpa
[i
]))
4074 return strings_fpa
[i
];
4079 /* Output the operands of a LDM/STM instruction to STREAM.
4080 MASK is the ARM register set mask of which only bits 0-15 are important.
4081 INSTR is the possibly suffixed base register. HAT unequals zero if a hat
4082 must follow the register list. */
4085 print_multi_reg (stream
, instr
, mask
, hat
)
4091 int not_first
= FALSE
;
4093 fputc ('\t', stream
);
4094 fprintf (stream
, instr
, REGISTER_PREFIX
);
4095 fputs (", {", stream
);
4096 for (i
= 0; i
< 16; i
++)
4097 if (mask
& (1 << i
))
4100 fprintf (stream
, ", ");
4101 fprintf (stream
, "%s%s", REGISTER_PREFIX
, reg_names
[i
]);
4105 fprintf (stream
, "}%s\n", hat
? "^" : "");
4108 /* Output a 'call' insn. */
4111 output_call (operands
)
4114 /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
4116 if (REGNO (operands
[0]) == 14)
4118 operands
[0] = gen_rtx_REG (SImode
, 12);
4119 output_asm_insn ("mov%?\t%0, %|lr", operands
);
4121 output_asm_insn ("mov%?\t%|lr, %|pc", operands
);
4123 if (TARGET_THUMB_INTERWORK
)
4124 output_asm_insn ("bx%?\t%0", operands
);
4126 output_asm_insn ("mov%?\t%|pc, %0", operands
);
4135 int something_changed
= 0;
4137 int code
= GET_CODE (x0
);
4144 if (REGNO (x0
) == 14)
4146 *x
= gen_rtx_REG (SImode
, 12);
4151 /* Scan through the sub-elements and change any references there */
4152 fmt
= GET_RTX_FORMAT (code
);
4153 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4155 something_changed
|= eliminate_lr2ip (&XEXP (x0
, i
));
4156 else if (fmt
[i
] == 'E')
4157 for (j
= 0; j
< XVECLEN (x0
, i
); j
++)
4158 something_changed
|= eliminate_lr2ip (&XVECEXP (x0
, i
, j
));
4159 return something_changed
;
4163 /* Output a 'call' insn that is a reference in memory. */
4166 output_call_mem (operands
)
4169 operands
[0] = copy_rtx (operands
[0]); /* Be ultra careful */
4170 /* Handle calls using lr by using ip (which may be clobbered in subr anyway).
4172 if (eliminate_lr2ip (&operands
[0]))
4173 output_asm_insn ("mov%?\t%|ip, %|lr", operands
);
4175 if (TARGET_THUMB_INTERWORK
)
4177 output_asm_insn ("ldr%?\t%|ip, %0", operands
);
4178 output_asm_insn ("mov%?\t%|lr, %|pc", operands
);
4179 output_asm_insn ("bx%?\t%|ip", operands
);
4183 output_asm_insn ("mov%?\t%|lr, %|pc", operands
);
4184 output_asm_insn ("ldr%?\t%|pc, %0", operands
);
4191 /* Output a move from arm registers to an fpu registers.
4192 OPERANDS[0] is an fpu register.
4193 OPERANDS[1] is the first registers of an arm register pair. */
4196 output_mov_long_double_fpu_from_arm (operands
)
4199 int arm_reg0
= REGNO (operands
[1]);
4205 ops
[0] = gen_rtx_REG (SImode
, arm_reg0
);
4206 ops
[1] = gen_rtx_REG (SImode
, 1 + arm_reg0
);
4207 ops
[2] = gen_rtx_REG (SImode
, 2 + arm_reg0
);
4209 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops
);
4210 output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands
);
4214 /* Output a move from an fpu register to arm registers.
4215 OPERANDS[0] is the first registers of an arm register pair.
4216 OPERANDS[1] is an fpu register. */
4219 output_mov_long_double_arm_from_fpu (operands
)
4222 int arm_reg0
= REGNO (operands
[0]);
4228 ops
[0] = gen_rtx_REG (SImode
, arm_reg0
);
4229 ops
[1] = gen_rtx_REG (SImode
, 1 + arm_reg0
);
4230 ops
[2] = gen_rtx_REG (SImode
, 2 + arm_reg0
);
4232 output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands
);
4233 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops
);
4237 /* Output a move from arm registers to arm registers of a long double
4238 OPERANDS[0] is the destination.
4239 OPERANDS[1] is the source. */
4241 output_mov_long_double_arm_from_arm (operands
)
4244 /* We have to be careful here because the two might overlap */
4245 int dest_start
= REGNO (operands
[0]);
4246 int src_start
= REGNO (operands
[1]);
4250 if (dest_start
< src_start
)
4252 for (i
= 0; i
< 3; i
++)
4254 ops
[0] = gen_rtx_REG (SImode
, dest_start
+ i
);
4255 ops
[1] = gen_rtx_REG (SImode
, src_start
+ i
);
4256 output_asm_insn ("mov%?\t%0, %1", ops
);
4261 for (i
= 2; i
>= 0; i
--)
4263 ops
[0] = gen_rtx_REG (SImode
, dest_start
+ i
);
4264 ops
[1] = gen_rtx_REG (SImode
, src_start
+ i
);
4265 output_asm_insn ("mov%?\t%0, %1", ops
);
4273 /* Output a move from arm registers to an fpu registers.
4274 OPERANDS[0] is an fpu register.
4275 OPERANDS[1] is the first registers of an arm register pair. */
4278 output_mov_double_fpu_from_arm (operands
)
4281 int arm_reg0
= REGNO (operands
[1]);
4286 ops
[0] = gen_rtx_REG (SImode
, arm_reg0
);
4287 ops
[1] = gen_rtx_REG (SImode
, 1 + arm_reg0
);
4288 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops
);
4289 output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands
);
4293 /* Output a move from an fpu register to arm registers.
4294 OPERANDS[0] is the first registers of an arm register pair.
4295 OPERANDS[1] is an fpu register. */
4298 output_mov_double_arm_from_fpu (operands
)
4301 int arm_reg0
= REGNO (operands
[0]);
4307 ops
[0] = gen_rtx_REG (SImode
, arm_reg0
);
4308 ops
[1] = gen_rtx_REG (SImode
, 1 + arm_reg0
);
4309 output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands
);
4310 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops
);
4314 /* Output a move between double words.
4315 It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM
4316 or MEM<-REG and all MEMs must be offsettable addresses. */
4319 output_move_double (operands
)
4322 enum rtx_code code0
= GET_CODE (operands
[0]);
4323 enum rtx_code code1
= GET_CODE (operands
[1]);
4328 int reg0
= REGNO (operands
[0]);
4330 otherops
[0] = gen_rtx_REG (SImode
, 1 + reg0
);
4333 int reg1
= REGNO (operands
[1]);
4337 /* Ensure the second source is not overwritten */
4338 if (reg1
== reg0
+ (WORDS_BIG_ENDIAN
? -1 : 1))
4339 output_asm_insn("mov%?\t%Q0, %Q1\n\tmov%?\t%R0, %R1", operands
);
4341 output_asm_insn("mov%?\t%R0, %R1\n\tmov%?\t%Q0, %Q1", operands
);
4343 else if (code1
== CONST_DOUBLE
)
4345 if (GET_MODE (operands
[1]) == DFmode
)
4348 union real_extract u
;
4350 bcopy ((char *) &CONST_DOUBLE_LOW (operands
[1]), (char *) &u
,
4352 REAL_VALUE_TO_TARGET_DOUBLE (u
.d
, l
);
4353 otherops
[1] = GEN_INT(l
[1]);
4354 operands
[1] = GEN_INT(l
[0]);
4356 else if (GET_MODE (operands
[1]) != VOIDmode
)
4358 else if (WORDS_BIG_ENDIAN
)
4361 otherops
[1] = GEN_INT (CONST_DOUBLE_LOW (operands
[1]));
4362 operands
[1] = GEN_INT (CONST_DOUBLE_HIGH (operands
[1]));
4367 otherops
[1] = GEN_INT (CONST_DOUBLE_HIGH (operands
[1]));
4368 operands
[1] = GEN_INT (CONST_DOUBLE_LOW (operands
[1]));
4370 output_mov_immediate (operands
);
4371 output_mov_immediate (otherops
);
4373 else if (code1
== CONST_INT
)
4375 #if HOST_BITS_PER_WIDE_INT > 32
4376 /* If HOST_WIDE_INT is more than 32 bits, the intval tells us
4377 what the upper word is. */
4378 if (WORDS_BIG_ENDIAN
)
4380 otherops
[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands
[1])));
4381 operands
[1] = GEN_INT (INTVAL (operands
[1]) >> 32);
4385 otherops
[1] = GEN_INT (INTVAL (operands
[1]) >> 32);
4386 operands
[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands
[1])));
4389 /* Sign extend the intval into the high-order word */
4390 if (WORDS_BIG_ENDIAN
)
4392 otherops
[1] = operands
[1];
4393 operands
[1] = (INTVAL (operands
[1]) < 0
4394 ? constm1_rtx
: const0_rtx
);
4397 otherops
[1] = INTVAL (operands
[1]) < 0 ? constm1_rtx
: const0_rtx
;
4399 output_mov_immediate (otherops
);
4400 output_mov_immediate (operands
);
4402 else if (code1
== MEM
)
4404 switch (GET_CODE (XEXP (operands
[1], 0)))
4407 output_asm_insn ("ldm%?ia\t%m1, %M0", operands
);
4411 abort (); /* Should never happen now */
4415 output_asm_insn ("ldm%?db\t%m1!, %M0", operands
);
4419 output_asm_insn ("ldm%?ia\t%m1!, %M0", operands
);
4423 abort (); /* Should never happen now */
4428 output_asm_insn ("adr%?\t%0, %1", operands
);
4429 output_asm_insn ("ldm%?ia\t%0, %M0", operands
);
4433 if (arm_add_operand (XEXP (XEXP (operands
[1], 0), 1)))
4435 otherops
[0] = operands
[0];
4436 otherops
[1] = XEXP (XEXP (operands
[1], 0), 0);
4437 otherops
[2] = XEXP (XEXP (operands
[1], 0), 1);
4438 if (GET_CODE (XEXP (operands
[1], 0)) == PLUS
)
4440 if (GET_CODE (otherops
[2]) == CONST_INT
)
4442 switch (INTVAL (otherops
[2]))
4445 output_asm_insn ("ldm%?db\t%1, %M0", otherops
);
4448 output_asm_insn ("ldm%?da\t%1, %M0", otherops
);
4451 output_asm_insn ("ldm%?ib\t%1, %M0", otherops
);
4454 if (!(const_ok_for_arm (INTVAL (otherops
[2]))))
4455 output_asm_insn ("sub%?\t%0, %1, #%n2", otherops
);
4457 output_asm_insn ("add%?\t%0, %1, %2", otherops
);
4460 output_asm_insn ("add%?\t%0, %1, %2", otherops
);
4463 output_asm_insn ("sub%?\t%0, %1, %2", otherops
);
4464 return "ldm%?ia\t%0, %M0";
4468 otherops
[1] = adj_offsettable_operand (operands
[1], 4);
4469 /* Take care of overlapping base/data reg. */
4470 if (reg_mentioned_p (operands
[0], operands
[1]))
4472 output_asm_insn ("ldr%?\t%0, %1", otherops
);
4473 output_asm_insn ("ldr%?\t%0, %1", operands
);
4477 output_asm_insn ("ldr%?\t%0, %1", operands
);
4478 output_asm_insn ("ldr%?\t%0, %1", otherops
);
4484 abort(); /* Constraints should prevent this */
4486 else if (code0
== MEM
&& code1
== REG
)
4488 if (REGNO (operands
[1]) == 12)
4491 switch (GET_CODE (XEXP (operands
[0], 0)))
4494 output_asm_insn ("stm%?ia\t%m0, %M1", operands
);
4498 abort (); /* Should never happen now */
4502 output_asm_insn ("stm%?db\t%m0!, %M1", operands
);
4506 output_asm_insn ("stm%?ia\t%m0!, %M1", operands
);
4510 abort (); /* Should never happen now */
4514 if (GET_CODE (XEXP (XEXP (operands
[0], 0), 1)) == CONST_INT
)
4516 switch (INTVAL (XEXP (XEXP (operands
[0], 0), 1)))
4519 output_asm_insn ("stm%?db\t%m0, %M1", operands
);
4523 output_asm_insn ("stm%?da\t%m0, %M1", operands
);
4527 output_asm_insn ("stm%?ib\t%m0, %M1", operands
);
4534 otherops
[0] = adj_offsettable_operand (operands
[0], 4);
4535 otherops
[1] = gen_rtx_REG (SImode
, 1 + REGNO (operands
[1]));
4536 output_asm_insn ("str%?\t%1, %0", operands
);
4537 output_asm_insn ("str%?\t%1, %0", otherops
);
4541 abort(); /* Constraints should prevent this */
4547 /* Output an arbitrary MOV reg, #n.
4548 OPERANDS[0] is a register. OPERANDS[1] is a const_int. */
4551 output_mov_immediate (operands
)
4554 HOST_WIDE_INT n
= INTVAL (operands
[1]);
4558 /* Try to use one MOV */
4559 if (const_ok_for_arm (n
))
4561 output_asm_insn ("mov%?\t%0, %1", operands
);
4565 /* Try to use one MVN */
4566 if (const_ok_for_arm (~n
))
4568 operands
[1] = GEN_INT (~n
);
4569 output_asm_insn ("mvn%?\t%0, %1", operands
);
4573 /* If all else fails, make it out of ORRs or BICs as appropriate. */
4575 for (i
=0; i
< 32; i
++)
4579 if (n_ones
> 16) /* Shorter to use MVN with BIC in this case. */
4580 output_multi_immediate(operands
, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1,
4583 output_multi_immediate(operands
, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1,
4590 /* Output an ADD r, s, #n where n may be too big for one instruction. If
4591 adding zero to one register, output nothing. */
4594 output_add_immediate (operands
)
4597 HOST_WIDE_INT n
= INTVAL (operands
[2]);
4599 if (n
!= 0 || REGNO (operands
[0]) != REGNO (operands
[1]))
4602 output_multi_immediate (operands
,
4603 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
4606 output_multi_immediate (operands
,
4607 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
4614 /* Output a multiple immediate operation.
4615 OPERANDS is the vector of operands referred to in the output patterns.
4616 INSTR1 is the output pattern to use for the first constant.
4617 INSTR2 is the output pattern to use for subsequent constants.
4618 IMMED_OP is the index of the constant slot in OPERANDS.
4619 N is the constant value. */
4622 output_multi_immediate (operands
, instr1
, instr2
, immed_op
, n
)
4624 char *instr1
, *instr2
;
4628 #if HOST_BITS_PER_WIDE_INT > 32
4634 operands
[immed_op
] = const0_rtx
;
4635 output_asm_insn (instr1
, operands
); /* Quick and easy output */
4640 char *instr
= instr1
;
4642 /* Note that n is never zero here (which would give no output) */
4643 for (i
= 0; i
< 32; i
+= 2)
4647 operands
[immed_op
] = GEN_INT (n
& (255 << i
));
4648 output_asm_insn (instr
, operands
);
4658 /* Return the appropriate ARM instruction for the operation code.
4659 The returned result should not be overwritten. OP is the rtx of the
4660 operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator
4664 arithmetic_instr (op
, shift_first_arg
)
4666 int shift_first_arg
;
4668 switch (GET_CODE (op
))
4674 return shift_first_arg
? "rsb" : "sub";
4691 /* Ensure valid constant shifts and return the appropriate shift mnemonic
4692 for the operation code. The returned result should not be overwritten.
4693 OP is the rtx code of the shift.
4694 On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
4698 shift_op (op
, amountp
)
4700 HOST_WIDE_INT
*amountp
;
4703 enum rtx_code code
= GET_CODE (op
);
4705 if (GET_CODE (XEXP (op
, 1)) == REG
|| GET_CODE (XEXP (op
, 1)) == SUBREG
)
4707 else if (GET_CODE (XEXP (op
, 1)) == CONST_INT
)
4708 *amountp
= INTVAL (XEXP (op
, 1));
4731 /* We never have to worry about the amount being other than a
4732 power of 2, since this case can never be reloaded from a reg. */
4734 *amountp
= int_log2 (*amountp
);
4745 /* This is not 100% correct, but follows from the desire to merge
4746 multiplication by a power of 2 with the recognizer for a
4747 shift. >=32 is not a valid shift for "asl", so we must try and
4748 output a shift that produces the correct arithmetical result.
4749 Using lsr #32 is identical except for the fact that the carry bit
4750 is not set correctly if we set the flags; but we never use the
4751 carry bit from such an operation, so we can ignore that. */
4752 if (code
== ROTATERT
)
4753 *amountp
&= 31; /* Rotate is just modulo 32 */
4754 else if (*amountp
!= (*amountp
& 31))
4761 /* Shifts of 0 are no-ops. */
4770 /* Obtain the shift from the POWER of two. */
4772 static HOST_WIDE_INT
4774 HOST_WIDE_INT power
;
4776 HOST_WIDE_INT shift
= 0;
4778 while (((((HOST_WIDE_INT
) 1) << shift
) & power
) == 0)
4788 /* Output a .ascii pseudo-op, keeping track of lengths. This is because
4789 /bin/as is horribly restrictive. */
4792 output_ascii_pseudo_op (stream
, p
, len
)
4798 int len_so_far
= 1000;
4799 int chars_so_far
= 0;
4801 for (i
= 0; i
< len
; i
++)
4803 register int c
= p
[i
];
4805 if (len_so_far
> 50)
4808 fputs ("\"\n", stream
);
4809 fputs ("\t.ascii\t\"", stream
);
4814 if (c
== '\"' || c
== '\\')
4820 if (c
>= ' ' && c
< 0177)
4827 fprintf (stream
, "\\%03o", c
);
4834 fputs ("\"\n", stream
);
4838 /* Try to determine whether a pattern really clobbers the link register.
4839 This information is useful when peepholing, so that lr need not be pushed
4840 if we combine a call followed by a return.
4841 NOTE: This code does not check for side-effect expressions in a SET_SRC:
4842 such a check should not be needed because these only update an existing
4843 value within a register; the register must still be set elsewhere within
4847 pattern_really_clobbers_lr (x
)
4852 switch (GET_CODE (x
))
4855 switch (GET_CODE (SET_DEST (x
)))
4858 return REGNO (SET_DEST (x
)) == 14;
4861 if (GET_CODE (XEXP (SET_DEST (x
), 0)) == REG
)
4862 return REGNO (XEXP (SET_DEST (x
), 0)) == 14;
4864 if (GET_CODE (XEXP (SET_DEST (x
), 0)) == MEM
)
4873 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
4874 if (pattern_really_clobbers_lr (XVECEXP (x
, 0, i
)))
4879 switch (GET_CODE (XEXP (x
, 0)))
4882 return REGNO (XEXP (x
, 0)) == 14;
4885 if (GET_CODE (XEXP (XEXP (x
, 0), 0)) == REG
)
4886 return REGNO (XEXP (XEXP (x
, 0), 0)) == 14;
4902 function_really_clobbers_lr (first
)
4907 for (insn
= first
; insn
; insn
= next_nonnote_insn (insn
))
4909 switch (GET_CODE (insn
))
4914 case JUMP_INSN
: /* Jump insns only change the PC (and conds) */
4919 if (pattern_really_clobbers_lr (PATTERN (insn
)))
4924 /* Don't yet know how to handle those calls that are not to a
4926 if (GET_CODE (PATTERN (insn
)) != PARALLEL
)
4929 switch (GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)))
4932 if (GET_CODE (XEXP (XEXP (XVECEXP (PATTERN (insn
), 0, 0), 0), 0))
4938 if (GET_CODE (XEXP (XEXP (SET_SRC (XVECEXP (PATTERN (insn
),
4944 default: /* Don't recognize it, be safe */
4948 /* A call can be made (by peepholing) not to clobber lr iff it is
4949 followed by a return. There may, however, be a use insn iff
4950 we are returning the result of the call.
4951 If we run off the end of the insn chain, then that means the
4952 call was at the end of the function. Unfortunately we don't
4953 have a return insn for the peephole to recognize, so we
4954 must reject this. (Can this be fixed by adding our own insn?) */
4955 if ((next
= next_nonnote_insn (insn
)) == NULL
)
4958 /* No need to worry about lr if the call never returns */
4959 if (GET_CODE (next
) == BARRIER
)
4962 if (GET_CODE (next
) == INSN
&& GET_CODE (PATTERN (next
)) == USE
4963 && (GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
4964 && (REGNO (SET_DEST (XVECEXP (PATTERN (insn
), 0, 0)))
4965 == REGNO (XEXP (PATTERN (next
), 0))))
4966 if ((next
= next_nonnote_insn (next
)) == NULL
)
4969 if (GET_CODE (next
) == JUMP_INSN
4970 && GET_CODE (PATTERN (next
)) == RETURN
)
4979 /* We have reached the end of the chain so lr was _not_ clobbered */
4984 output_return_instruction (operand
, really_return
, reverse
)
4990 int reg
, live_regs
= 0;
4991 int volatile_func
= (optimize
> 0
4992 && TREE_THIS_VOLATILE (current_function_decl
));
4994 return_used_this_function
= 1;
4999 /* If this function was declared non-returning, and we have found a tail
5000 call, then we have to trust that the called function won't return. */
5001 if (! really_return
)
5004 /* Otherwise, trap an attempted return by aborting. */
5006 ops
[1] = gen_rtx_SYMBOL_REF (Pmode
, "abort");
5007 assemble_external_libcall (ops
[1]);
5008 output_asm_insn (reverse
? "bl%D0\t%a1" : "bl%d0\t%a1", ops
);
5012 if (current_function_calls_alloca
&& ! really_return
)
5015 for (reg
= 0; reg
<= 10; reg
++)
5016 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5019 if (live_regs
|| (regs_ever_live
[14] && ! lr_save_eliminated
))
5022 if (frame_pointer_needed
)
5027 if (lr_save_eliminated
|| ! regs_ever_live
[14])
5030 if (frame_pointer_needed
)
5032 reverse
? "ldm%?%D0ea\t%|fp, {" : "ldm%?%d0ea\t%|fp, {");
5035 reverse
? "ldm%?%D0fd\t%|sp!, {" : "ldm%?%d0fd\t%|sp!, {");
5037 for (reg
= 0; reg
<= 10; reg
++)
5038 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5040 strcat (instr
, "%|");
5041 strcat (instr
, reg_names
[reg
]);
5043 strcat (instr
, ", ");
5046 if (frame_pointer_needed
)
5048 strcat (instr
, "%|");
5049 strcat (instr
, reg_names
[11]);
5050 strcat (instr
, ", ");
5051 strcat (instr
, "%|");
5052 strcat (instr
, reg_names
[13]);
5053 strcat (instr
, ", ");
5054 strcat (instr
, "%|");
5055 strcat (instr
, TARGET_THUMB_INTERWORK
|| (! really_return
)
5056 ? reg_names
[14] : reg_names
[15] );
5060 strcat (instr
, "%|");
5061 if (TARGET_THUMB_INTERWORK
&& really_return
)
5062 strcat (instr
, reg_names
[12]);
5064 strcat (instr
, really_return
? reg_names
[15] : reg_names
[14]);
5066 strcat (instr
, (TARGET_APCS_32
|| !really_return
) ? "}" : "}^");
5067 output_asm_insn (instr
, &operand
);
5069 if (TARGET_THUMB_INTERWORK
&& really_return
)
5071 strcpy (instr
, "bx%?");
5072 strcat (instr
, reverse
? "%D0" : "%d0");
5073 strcat (instr
, "\t%|");
5074 strcat (instr
, frame_pointer_needed
? "lr" : "ip");
5076 output_asm_insn (instr
, & operand
);
5079 else if (really_return
)
5081 if (TARGET_THUMB_INTERWORK
)
5082 sprintf (instr
, "bx%%?%%%s0\t%%|lr", reverse
? "D" : "d");
5084 sprintf (instr
, "mov%%?%%%s0%s\t%%|pc, %%|lr",
5085 reverse
? "D" : "d", TARGET_APCS_32
? "" : "s");
5087 output_asm_insn (instr
, & operand
);
5093 /* Return nonzero if optimizing and the current function is volatile.
5094 Such functions never return, and many memory cycles can be saved
5095 by not storing register values that will never be needed again.
5096 This optimization was added to speed up context switching in a
5097 kernel application. */
5100 arm_volatile_func ()
5102 return (optimize
> 0 && TREE_THIS_VOLATILE (current_function_decl
));
5105 /* The amount of stack adjustment that happens here, in output_return and in
5106 output_epilogue must be exactly the same as was calculated during reload,
5107 or things will point to the wrong place. The only time we can safely
5108 ignore this constraint is when a function has no arguments on the stack,
5109 no stack frame requirement and no live registers execpt for `lr'. If we
5110 can guarantee that by making all function calls into tail calls and that
5111 lr is not clobbered in any other way, then there is no need to push lr
5115 output_func_prologue (f
, frame_size
)
5119 int reg
, live_regs_mask
= 0;
5120 int volatile_func
= (optimize
> 0
5121 && TREE_THIS_VOLATILE (current_function_decl
));
5123 /* Nonzero if we must stuff some register arguments onto the stack as if
5124 they were passed there. */
5125 int store_arg_regs
= 0;
5127 if (arm_ccfsm_state
|| arm_target_insn
)
5128 abort (); /* Sanity check */
5130 if (arm_naked_function_p (current_function_decl
))
5133 return_used_this_function
= 0;
5134 lr_save_eliminated
= 0;
5136 fprintf (f
, "\t%s args = %d, pretend = %d, frame = %d\n",
5137 ASM_COMMENT_START
, current_function_args_size
,
5138 current_function_pretend_args_size
, frame_size
);
5139 fprintf (f
, "\t%s frame_needed = %d, current_function_anonymous_args = %d\n",
5140 ASM_COMMENT_START
, frame_pointer_needed
,
5141 current_function_anonymous_args
);
5144 fprintf (f
, "\t%s Volatile function.\n", ASM_COMMENT_START
);
5146 if (current_function_anonymous_args
&& current_function_pretend_args_size
)
5149 for (reg
= 0; reg
<= 10; reg
++)
5150 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5151 live_regs_mask
|= (1 << reg
);
5153 if (frame_pointer_needed
)
5154 live_regs_mask
|= 0xD800;
5155 else if (regs_ever_live
[14])
5157 if (! current_function_args_size
5158 && ! function_really_clobbers_lr (get_insns ()))
5159 lr_save_eliminated
= 1;
5161 live_regs_mask
|= 0x4000;
5166 /* if a di mode load/store multiple is used, and the base register
5167 is r3, then r4 can become an ever live register without lr
5168 doing so, in this case we need to push lr as well, or we
5169 will fail to get a proper return. */
5171 live_regs_mask
|= 0x4000;
5172 lr_save_eliminated
= 0;
5176 if (lr_save_eliminated
)
5177 fprintf (f
,"\t%s I don't think this function clobbers lr\n",
5180 #ifdef AOF_ASSEMBLER
5182 fprintf (f
, "\tmov\t%sip, %s%s\n", REGISTER_PREFIX
, REGISTER_PREFIX
,
5183 reg_names
[PIC_OFFSET_TABLE_REGNUM
]);
5189 output_func_epilogue (f
, frame_size
)
5193 int reg
, live_regs_mask
= 0;
5194 /* If we need this then it will always be at least this much */
5195 int floats_offset
= 12;
5197 int volatile_func
= (optimize
> 0
5198 && TREE_THIS_VOLATILE (current_function_decl
));
5200 if (use_return_insn (FALSE
) && return_used_this_function
)
5202 if ((frame_size
+ current_function_outgoing_args_size
) != 0
5203 && !(frame_pointer_needed
&& TARGET_APCS
))
5208 /* Naked functions don't have epilogues. */
5209 if (arm_naked_function_p (current_function_decl
))
5212 /* A volatile function should never return. Call abort. */
5213 if (TARGET_ABORT_NORETURN
&& volatile_func
)
5215 rtx op
= gen_rtx_SYMBOL_REF (Pmode
, "abort");
5216 assemble_external_libcall (op
);
5217 output_asm_insn ("bl\t%a0", &op
);
5221 for (reg
= 0; reg
<= 10; reg
++)
5222 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5224 live_regs_mask
|= (1 << reg
);
5228 if (frame_pointer_needed
)
5230 if (arm_fpu_arch
== FP_SOFT2
)
5232 for (reg
= 23; reg
> 15; reg
--)
5233 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5235 floats_offset
+= 12;
5236 fprintf (f
, "\tldfe\t%s%s, [%sfp, #-%d]\n", REGISTER_PREFIX
,
5237 reg_names
[reg
], REGISTER_PREFIX
, floats_offset
);
5244 for (reg
= 23; reg
> 15; reg
--)
5246 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5248 floats_offset
+= 12;
5249 /* We can't unstack more than four registers at once */
5250 if (start_reg
- reg
== 3)
5252 fprintf (f
, "\tlfm\t%s%s, 4, [%sfp, #-%d]\n",
5253 REGISTER_PREFIX
, reg_names
[reg
],
5254 REGISTER_PREFIX
, floats_offset
);
5255 start_reg
= reg
- 1;
5260 if (reg
!= start_reg
)
5261 fprintf (f
, "\tlfm\t%s%s, %d, [%sfp, #-%d]\n",
5262 REGISTER_PREFIX
, reg_names
[reg
+ 1],
5263 start_reg
- reg
, REGISTER_PREFIX
, floats_offset
);
5265 start_reg
= reg
- 1;
5269 /* Just in case the last register checked also needs unstacking. */
5270 if (reg
!= start_reg
)
5271 fprintf (f
, "\tlfm\t%s%s, %d, [%sfp, #-%d]\n",
5272 REGISTER_PREFIX
, reg_names
[reg
+ 1],
5273 start_reg
- reg
, REGISTER_PREFIX
, floats_offset
);
5276 if (TARGET_THUMB_INTERWORK
)
5278 live_regs_mask
|= 0x6800;
5279 print_multi_reg (f
, "ldmea\t%sfp", live_regs_mask
, FALSE
);
5280 fprintf (f
, "\tbx\t%slr\n", REGISTER_PREFIX
);
5284 live_regs_mask
|= 0xA800;
5285 print_multi_reg (f
, "ldmea\t%sfp", live_regs_mask
,
5286 TARGET_APCS_32
? FALSE
: TRUE
);
5291 /* Restore stack pointer if necessary. */
5292 if (frame_size
+ current_function_outgoing_args_size
!= 0)
5294 operands
[0] = operands
[1] = stack_pointer_rtx
;
5295 operands
[2] = GEN_INT (frame_size
5296 + current_function_outgoing_args_size
);
5297 output_add_immediate (operands
);
5300 if (arm_fpu_arch
== FP_SOFT2
)
5302 for (reg
= 16; reg
< 24; reg
++)
5303 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5304 fprintf (f
, "\tldfe\t%s%s, [%ssp], #12\n", REGISTER_PREFIX
,
5305 reg_names
[reg
], REGISTER_PREFIX
);
5311 for (reg
= 16; reg
< 24; reg
++)
5313 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5315 if (reg
- start_reg
== 3)
5317 fprintf (f
, "\tlfmfd\t%s%s, 4, [%ssp]!\n",
5318 REGISTER_PREFIX
, reg_names
[start_reg
],
5320 start_reg
= reg
+ 1;
5325 if (reg
!= start_reg
)
5326 fprintf (f
, "\tlfmfd\t%s%s, %d, [%ssp]!\n",
5327 REGISTER_PREFIX
, reg_names
[start_reg
],
5328 reg
- start_reg
, REGISTER_PREFIX
);
5330 start_reg
= reg
+ 1;
5334 /* Just in case the last register checked also needs unstacking. */
5335 if (reg
!= start_reg
)
5336 fprintf (f
, "\tlfmfd\t%s%s, %d, [%ssp]!\n",
5337 REGISTER_PREFIX
, reg_names
[start_reg
],
5338 reg
- start_reg
, REGISTER_PREFIX
);
5341 if (current_function_pretend_args_size
== 0 && regs_ever_live
[14])
5343 if (TARGET_THUMB_INTERWORK
)
5345 if (! lr_save_eliminated
)
5346 live_regs_mask
|= 0x4000;
5348 if (live_regs_mask
!= 0)
5349 print_multi_reg (f
, "ldmfd\t%ssp!", live_regs_mask
, FALSE
);
5351 fprintf (f
, "\tbx\t%slr\n", REGISTER_PREFIX
);
5353 else if (lr_save_eliminated
)
5354 fprintf (f
, (TARGET_APCS_32
? "\tmov\t%spc, %slr\n"
5355 : "\tmovs\t%spc, %slr\n"),
5356 REGISTER_PREFIX
, REGISTER_PREFIX
, f
);
5358 print_multi_reg (f
, "ldmfd\t%ssp!", live_regs_mask
| 0x8000,
5359 TARGET_APCS_32
? FALSE
: TRUE
);
5363 if (live_regs_mask
|| regs_ever_live
[14])
5365 /* Restore the integer regs, and the return address into lr */
5366 if (! lr_save_eliminated
)
5367 live_regs_mask
|= 0x4000;
5369 if (live_regs_mask
!= 0)
5370 print_multi_reg (f
, "ldmfd\t%ssp!", live_regs_mask
, FALSE
);
5373 if (current_function_pretend_args_size
)
5375 /* Unwind the pre-pushed regs */
5376 operands
[0] = operands
[1] = stack_pointer_rtx
;
5377 operands
[2] = GEN_INT (current_function_pretend_args_size
);
5378 output_add_immediate (operands
);
5380 /* And finally, go home */
5381 if (TARGET_THUMB_INTERWORK
)
5382 fprintf (f
, "\tbx\t%slr\n", REGISTER_PREFIX
);
5383 else if (TARGET_APCS_32
)
5384 fprintf (f
, "\tmov\t%spc, %slr\n", REGISTER_PREFIX
, REGISTER_PREFIX
);
5386 fprintf (f
, "\tmovs\t%spc, %slr\n", REGISTER_PREFIX
, REGISTER_PREFIX
);
5392 /* Reset the ARM-specific per-function variables. */
5393 current_function_anonymous_args
= 0;
5394 after_arm_reorg
= 0;
5398 emit_multi_reg_push (mask
)
5405 for (i
= 0; i
< 16; i
++)
5406 if (mask
& (1 << i
))
5409 if (num_regs
== 0 || num_regs
> 16)
5412 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num_regs
));
5414 for (i
= 0; i
< 16; i
++)
5416 if (mask
& (1 << i
))
5419 = gen_rtx_SET (VOIDmode
,
5420 gen_rtx_MEM (BLKmode
,
5421 gen_rtx_PRE_DEC (BLKmode
,
5422 stack_pointer_rtx
)),
5423 gen_rtx_UNSPEC (BLKmode
,
5425 gen_rtx_REG (SImode
, i
)),
5431 for (j
= 1, i
++; j
< num_regs
; i
++)
5433 if (mask
& (1 << i
))
5436 = gen_rtx_USE (VOIDmode
, gen_rtx_REG (SImode
, i
));
5445 emit_sfm (base_reg
, count
)
5452 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (count
));
5455 = gen_rtx_SET (VOIDmode
,
5456 gen_rtx_MEM (BLKmode
,
5457 gen_rtx_PRE_DEC (BLKmode
, stack_pointer_rtx
)),
5458 gen_rtx_UNSPEC (BLKmode
,
5459 gen_rtvec (1, gen_rtx_REG (XFmode
,
5462 for (i
= 1; i
< count
; i
++)
5463 XVECEXP (par
, 0, i
) = gen_rtx_USE (VOIDmode
,
5464 gen_rtx_REG (XFmode
, base_reg
++));
5470 arm_expand_prologue ()
5473 rtx amount
= GEN_INT (-(get_frame_size ()
5474 + current_function_outgoing_args_size
));
5475 int live_regs_mask
= 0;
5476 int store_arg_regs
= 0;
5477 int volatile_func
= (optimize
> 0
5478 && TREE_THIS_VOLATILE (current_function_decl
));
5480 /* Naked functions don't have prologues. */
5481 if (arm_naked_function_p (current_function_decl
))
5484 if (current_function_anonymous_args
&& current_function_pretend_args_size
)
5487 if (! volatile_func
)
5488 for (reg
= 0; reg
<= 10; reg
++)
5489 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5490 live_regs_mask
|= 1 << reg
;
5492 if (! volatile_func
&& regs_ever_live
[14])
5493 live_regs_mask
|= 0x4000;
5495 if (frame_pointer_needed
)
5497 live_regs_mask
|= 0xD800;
5498 emit_insn (gen_movsi (gen_rtx_REG (SImode
, 12),
5499 stack_pointer_rtx
));
5502 if (current_function_pretend_args_size
)
5505 emit_multi_reg_push ((0xf0 >> (current_function_pretend_args_size
/ 4))
5508 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
5509 GEN_INT (-current_function_pretend_args_size
)));
5514 /* If we have to push any regs, then we must push lr as well, or
5515 we won't get a proper return. */
5516 live_regs_mask
|= 0x4000;
5517 emit_multi_reg_push (live_regs_mask
);
5520 /* For now the integer regs are still pushed in output_func_epilogue (). */
5522 if (! volatile_func
)
5524 if (arm_fpu_arch
== FP_SOFT2
)
5526 for (reg
= 23; reg
> 15; reg
--)
5527 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5528 emit_insn (gen_rtx_SET
5530 gen_rtx_MEM (XFmode
,
5531 gen_rtx_PRE_DEC (XFmode
,
5532 stack_pointer_rtx
)),
5533 gen_rtx_REG (XFmode
, reg
)));
5539 for (reg
= 23; reg
> 15; reg
--)
5541 if (regs_ever_live
[reg
] && ! call_used_regs
[reg
])
5543 if (start_reg
- reg
== 3)
5546 start_reg
= reg
- 1;
5551 if (start_reg
!= reg
)
5552 emit_sfm (reg
+ 1, start_reg
- reg
);
5553 start_reg
= reg
- 1;
5557 if (start_reg
!= reg
)
5558 emit_sfm (reg
+ 1, start_reg
- reg
);
5562 if (frame_pointer_needed
)
5563 emit_insn (gen_addsi3 (hard_frame_pointer_rtx
, gen_rtx_REG (SImode
, 12),
5565 (-(4 + current_function_pretend_args_size
)))));
5567 if (amount
!= const0_rtx
)
5569 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, amount
));
5570 emit_insn (gen_rtx_CLOBBER (VOIDmode
,
5571 gen_rtx_MEM (BLKmode
, stack_pointer_rtx
)));
5574 /* If we are profiling, make sure no instructions are scheduled before
5575 the call to mcount. Similarly if the user has requested no
5576 scheduling in the prolog. */
5577 if (profile_flag
|| profile_block_flag
|| TARGET_NO_SCHED_PRO
)
5578 emit_insn (gen_blockage ());
5582 /* If CODE is 'd', then the X is a condition operand and the instruction
5583 should only be executed if the condition is true.
5584 if CODE is 'D', then the X is a condition operand and the instruction
5585 should only be executed if the condition is false: however, if the mode
5586 of the comparison is CCFPEmode, then always execute the instruction -- we
5587 do this because in these circumstances !GE does not necessarily imply LT;
5588 in these cases the instruction pattern will take care to make sure that
5589 an instruction containing %d will follow, thereby undoing the effects of
5590 doing this instruction unconditionally.
5591 If CODE is 'N' then X is a floating point operand that must be negated
5593 If CODE is 'B' then output a bitwise inverted value of X (a const int).
5594 If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */
5597 arm_print_operand (stream
, x
, code
)
5605 fputs (ASM_COMMENT_START
, stream
);
5609 fputs (REGISTER_PREFIX
, stream
);
5613 if (arm_ccfsm_state
== 3 || arm_ccfsm_state
== 4)
5614 fputs (arm_condition_codes
[arm_current_cc
], stream
);
5620 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
5621 r
= REAL_VALUE_NEGATE (r
);
5622 fprintf (stream
, "%s", fp_const_from_val (&r
));
5627 if (GET_CODE (x
) == CONST_INT
)
5629 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
5634 ARM_SIGN_EXTEND (~ INTVAL (x
)));
5638 output_addr_const (stream
, x
);
5643 fprintf (stream
, "%s", arithmetic_instr (x
, 1));
5647 fprintf (stream
, "%s", arithmetic_instr (x
, 0));
5653 char *shift
= shift_op (x
, &val
);
5657 fprintf (stream
, ", %s ", shift_op (x
, &val
));
5659 arm_print_operand (stream
, XEXP (x
, 1), 0);
5662 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
5675 fputs (REGISTER_PREFIX
, stream
);
5676 fputs (reg_names
[REGNO (x
) + (WORDS_BIG_ENDIAN
? 1 : 0)], stream
);
5682 fputs (REGISTER_PREFIX
, stream
);
5683 fputs (reg_names
[REGNO (x
) + (WORDS_BIG_ENDIAN
? 0 : 1)], stream
);
5687 fputs (REGISTER_PREFIX
, stream
);
5688 if (GET_CODE (XEXP (x
, 0)) == REG
)
5689 fputs (reg_names
[REGNO (XEXP (x
, 0))], stream
);
5691 fputs (reg_names
[REGNO (XEXP (XEXP (x
, 0), 0))], stream
);
5695 fprintf (stream
, "{%s%s-%s%s}", REGISTER_PREFIX
, reg_names
[REGNO (x
)],
5696 REGISTER_PREFIX
, reg_names
[REGNO (x
) - 1
5697 + ((GET_MODE_SIZE (GET_MODE (x
))
5698 + GET_MODE_SIZE (SImode
) - 1)
5699 / GET_MODE_SIZE (SImode
))]);
5704 fputs (arm_condition_codes
[get_arm_condition_code (x
)],
5710 fputs (arm_condition_codes
[ARM_INVERSE_CONDITION_CODE
5711 (get_arm_condition_code (x
))],
5719 if (GET_CODE (x
) == REG
)
5721 fputs (REGISTER_PREFIX
, stream
);
5722 fputs (reg_names
[REGNO (x
)], stream
);
5724 else if (GET_CODE (x
) == MEM
)
5726 output_memory_reference_mode
= GET_MODE (x
);
5727 output_address (XEXP (x
, 0));
5729 else if (GET_CODE (x
) == CONST_DOUBLE
)
5730 fprintf (stream
, "#%s", fp_immediate_constant (x
));
5731 else if (GET_CODE (x
) == NEG
)
5732 abort (); /* This should never happen now. */
5735 fputc ('#', stream
);
5736 output_addr_const (stream
, x
);
5742 /* A finite state machine takes care of noticing whether or not instructions
5743 can be conditionally executed, and thus decrease execution time and code
5744 size by deleting branch instructions. The fsm is controlled by
5745 final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */
5747 /* The state of the fsm controlling condition codes are:
5748 0: normal, do nothing special
5749 1: make ASM_OUTPUT_OPCODE not output this instruction
5750 2: make ASM_OUTPUT_OPCODE not output this instruction
5751 3: make instructions conditional
5752 4: make instructions conditional
5754 State transitions (state->state by whom under condition):
5755 0 -> 1 final_prescan_insn if the `target' is a label
5756 0 -> 2 final_prescan_insn if the `target' is an unconditional branch
5757 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
5758 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
5759 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL if the `target' label is reached
5760 (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
5761 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
5762 (the target insn is arm_target_insn).
5764 If the jump clobbers the conditions then we use states 2 and 4.
5766 A similar thing can be done with conditional return insns.
5768 XXX In case the `target' is an unconditional branch, this conditionalising
5769 of the instructions always reduces code size, but not always execution
5770 time. But then, I want to reduce the code size to somewhere near what
5771 /bin/cc produces. */
5773 /* Returns the index of the ARM condition code string in
5774 `arm_condition_codes'. COMPARISON should be an rtx like
5775 `(eq (...) (...))'. */
5777 static enum arm_cond_code
5778 get_arm_condition_code (comparison
)
5781 enum machine_mode mode
= GET_MODE (XEXP (comparison
, 0));
5783 register enum rtx_code comp_code
= GET_CODE (comparison
);
5785 if (GET_MODE_CLASS (mode
) != MODE_CC
)
5786 mode
= SELECT_CC_MODE (comp_code
, XEXP (comparison
, 0),
5787 XEXP (comparison
, 1));
5791 case CC_DNEmode
: code
= ARM_NE
; goto dominance
;
5792 case CC_DEQmode
: code
= ARM_EQ
; goto dominance
;
5793 case CC_DGEmode
: code
= ARM_GE
; goto dominance
;
5794 case CC_DGTmode
: code
= ARM_GT
; goto dominance
;
5795 case CC_DLEmode
: code
= ARM_LE
; goto dominance
;
5796 case CC_DLTmode
: code
= ARM_LT
; goto dominance
;
5797 case CC_DGEUmode
: code
= ARM_CS
; goto dominance
;
5798 case CC_DGTUmode
: code
= ARM_HI
; goto dominance
;
5799 case CC_DLEUmode
: code
= ARM_LS
; goto dominance
;
5800 case CC_DLTUmode
: code
= ARM_CC
;
5803 if (comp_code
!= EQ
&& comp_code
!= NE
)
5806 if (comp_code
== EQ
)
5807 return ARM_INVERSE_CONDITION_CODE (code
);
5813 case NE
: return ARM_NE
;
5814 case EQ
: return ARM_EQ
;
5815 case GE
: return ARM_PL
;
5816 case LT
: return ARM_MI
;
5824 case NE
: return ARM_NE
;
5825 case EQ
: return ARM_EQ
;
5832 case GE
: return ARM_GE
;
5833 case GT
: return ARM_GT
;
5834 case LE
: return ARM_LS
;
5835 case LT
: return ARM_MI
;
5842 case NE
: return ARM_NE
;
5843 case EQ
: return ARM_EQ
;
5844 case GE
: return ARM_LE
;
5845 case GT
: return ARM_LT
;
5846 case LE
: return ARM_GE
;
5847 case LT
: return ARM_GT
;
5848 case GEU
: return ARM_LS
;
5849 case GTU
: return ARM_CC
;
5850 case LEU
: return ARM_CS
;
5851 case LTU
: return ARM_HI
;
5858 case LTU
: return ARM_CS
;
5859 case GEU
: return ARM_CC
;
5866 case NE
: return ARM_NE
;
5867 case EQ
: return ARM_EQ
;
5868 case GE
: return ARM_GE
;
5869 case GT
: return ARM_GT
;
5870 case LE
: return ARM_LE
;
5871 case LT
: return ARM_LT
;
5872 case GEU
: return ARM_CS
;
5873 case GTU
: return ARM_HI
;
5874 case LEU
: return ARM_LS
;
5875 case LTU
: return ARM_CC
;
5887 final_prescan_insn (insn
, opvec
, noperands
)
5892 /* BODY will hold the body of INSN. */
5893 register rtx body
= PATTERN (insn
);
5895 /* This will be 1 if trying to repeat the trick, and things need to be
5896 reversed if it appears to fail. */
5899 /* JUMP_CLOBBERS will be one implies that the conditions if a branch is
5900 taken are clobbered, even if the rtl suggests otherwise. It also
5901 means that we have to grub around within the jump expression to find
5902 out what the conditions are when the jump isn't taken. */
5903 int jump_clobbers
= 0;
5905 /* If we start with a return insn, we only succeed if we find another one. */
5906 int seeking_return
= 0;
5908 /* START_INSN will hold the insn from where we start looking. This is the
5909 first insn after the following code_label if REVERSE is true. */
5910 rtx start_insn
= insn
;
5912 /* If in state 4, check if the target branch is reached, in order to
5913 change back to state 0. */
5914 if (arm_ccfsm_state
== 4)
5916 if (insn
== arm_target_insn
)
5918 arm_target_insn
= NULL
;
5919 arm_ccfsm_state
= 0;
5924 /* If in state 3, it is possible to repeat the trick, if this insn is an
5925 unconditional branch to a label, and immediately following this branch
5926 is the previous target label which is only used once, and the label this
5927 branch jumps to is not too far off. */
5928 if (arm_ccfsm_state
== 3)
5930 if (simplejump_p (insn
))
5932 start_insn
= next_nonnote_insn (start_insn
);
5933 if (GET_CODE (start_insn
) == BARRIER
)
5935 /* XXX Isn't this always a barrier? */
5936 start_insn
= next_nonnote_insn (start_insn
);
5938 if (GET_CODE (start_insn
) == CODE_LABEL
5939 && CODE_LABEL_NUMBER (start_insn
) == arm_target_label
5940 && LABEL_NUSES (start_insn
) == 1)
5945 else if (GET_CODE (body
) == RETURN
)
5947 start_insn
= next_nonnote_insn (start_insn
);
5948 if (GET_CODE (start_insn
) == BARRIER
)
5949 start_insn
= next_nonnote_insn (start_insn
);
5950 if (GET_CODE (start_insn
) == CODE_LABEL
5951 && CODE_LABEL_NUMBER (start_insn
) == arm_target_label
5952 && LABEL_NUSES (start_insn
) == 1)
5964 if (arm_ccfsm_state
!= 0 && !reverse
)
5966 if (GET_CODE (insn
) != JUMP_INSN
)
5969 /* This jump might be paralleled with a clobber of the condition codes
5970 the jump should always come first */
5971 if (GET_CODE (body
) == PARALLEL
&& XVECLEN (body
, 0) > 0)
5972 body
= XVECEXP (body
, 0, 0);
5975 /* If this is a conditional return then we don't want to know */
5976 if (GET_CODE (body
) == SET
&& GET_CODE (SET_DEST (body
)) == PC
5977 && GET_CODE (SET_SRC (body
)) == IF_THEN_ELSE
5978 && (GET_CODE (XEXP (SET_SRC (body
), 1)) == RETURN
5979 || GET_CODE (XEXP (SET_SRC (body
), 2)) == RETURN
))
5984 || (GET_CODE (body
) == SET
&& GET_CODE (SET_DEST (body
)) == PC
5985 && GET_CODE (SET_SRC (body
)) == IF_THEN_ELSE
))
5988 int fail
= FALSE
, succeed
= FALSE
;
5989 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
5990 int then_not_else
= TRUE
;
5991 rtx this_insn
= start_insn
, label
= 0;
5993 if (get_attr_conds (insn
) == CONDS_JUMP_CLOB
)
5995 /* The code below is wrong for these, and I haven't time to
5996 fix it now. So we just do the safe thing and return. This
5997 whole function needs re-writing anyway. */
6002 /* Register the insn jumped to. */
6005 if (!seeking_return
)
6006 label
= XEXP (SET_SRC (body
), 0);
6008 else if (GET_CODE (XEXP (SET_SRC (body
), 1)) == LABEL_REF
)
6009 label
= XEXP (XEXP (SET_SRC (body
), 1), 0);
6010 else if (GET_CODE (XEXP (SET_SRC (body
), 2)) == LABEL_REF
)
6012 label
= XEXP (XEXP (SET_SRC (body
), 2), 0);
6013 then_not_else
= FALSE
;
6015 else if (GET_CODE (XEXP (SET_SRC (body
), 1)) == RETURN
)
6017 else if (GET_CODE (XEXP (SET_SRC (body
), 2)) == RETURN
)
6020 then_not_else
= FALSE
;
6025 /* See how many insns this branch skips, and what kind of insns. If all
6026 insns are okay, and the label or unconditional branch to the same
6027 label is not too far away, succeed. */
6028 for (insns_skipped
= 0;
6029 !fail
&& !succeed
&& insns_skipped
++ < max_insns_skipped
;)
6033 this_insn
= next_nonnote_insn (this_insn
);
6037 switch (GET_CODE (this_insn
))
6040 /* Succeed if it is the target label, otherwise fail since
6041 control falls in from somewhere else. */
6042 if (this_insn
== label
)
6046 arm_ccfsm_state
= 2;
6047 this_insn
= next_nonnote_insn (this_insn
);
6050 arm_ccfsm_state
= 1;
6058 /* Succeed if the following insn is the target label.
6060 If return insns are used then the last insn in a function
6061 will be a barrier. */
6062 this_insn
= next_nonnote_insn (this_insn
);
6063 if (this_insn
&& this_insn
== label
)
6067 arm_ccfsm_state
= 2;
6068 this_insn
= next_nonnote_insn (this_insn
);
6071 arm_ccfsm_state
= 1;
6079 /* If using 32-bit addresses the cc is not preserved over
6083 /* Succeed if the following insn is the target label,
6084 or if the following two insns are a barrier and
6085 the target label. */
6086 this_insn
= next_nonnote_insn (this_insn
);
6087 if (this_insn
&& GET_CODE (this_insn
) == BARRIER
)
6088 this_insn
= next_nonnote_insn (this_insn
);
6090 if (this_insn
&& this_insn
== label
6091 && insns_skipped
< max_insns_skipped
)
6095 arm_ccfsm_state
= 2;
6096 this_insn
= next_nonnote_insn (this_insn
);
6099 arm_ccfsm_state
= 1;
6108 /* If this is an unconditional branch to the same label, succeed.
6109 If it is to another label, do nothing. If it is conditional,
6111 /* XXX Probably, the tests for SET and the PC are unnecessary. */
6113 scanbody
= PATTERN (this_insn
);
6114 if (GET_CODE (scanbody
) == SET
6115 && GET_CODE (SET_DEST (scanbody
)) == PC
)
6117 if (GET_CODE (SET_SRC (scanbody
)) == LABEL_REF
6118 && XEXP (SET_SRC (scanbody
), 0) == label
&& !reverse
)
6120 arm_ccfsm_state
= 2;
6123 else if (GET_CODE (SET_SRC (scanbody
)) == IF_THEN_ELSE
)
6126 /* Fail if a conditional return is undesirable (eg on a
6127 StrongARM), but still allow this if optimizing for size. */
6128 else if (GET_CODE (scanbody
) == RETURN
6129 && ! use_return_insn (TRUE
)
6132 else if (GET_CODE (scanbody
) == RETURN
6135 arm_ccfsm_state
= 2;
6138 else if (GET_CODE (scanbody
) == PARALLEL
)
6140 switch (get_attr_conds (this_insn
))
6152 /* Instructions using or affecting the condition codes make it
6154 scanbody
= PATTERN (this_insn
);
6155 if (! (GET_CODE (scanbody
) == SET
6156 || GET_CODE (scanbody
) == PARALLEL
)
6157 || get_attr_conds (this_insn
) != CONDS_NOCOND
)
6167 if ((!seeking_return
) && (arm_ccfsm_state
== 1 || reverse
))
6168 arm_target_label
= CODE_LABEL_NUMBER (label
);
6169 else if (seeking_return
|| arm_ccfsm_state
== 2)
6171 while (this_insn
&& GET_CODE (PATTERN (this_insn
)) == USE
)
6173 this_insn
= next_nonnote_insn (this_insn
);
6174 if (this_insn
&& (GET_CODE (this_insn
) == BARRIER
6175 || GET_CODE (this_insn
) == CODE_LABEL
))
6180 /* Oh, dear! we ran off the end.. give up */
6181 recog (PATTERN (insn
), insn
, NULL_PTR
);
6182 arm_ccfsm_state
= 0;
6183 arm_target_insn
= NULL
;
6186 arm_target_insn
= this_insn
;
6195 get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body
),
6197 if (GET_CODE (XEXP (XEXP (SET_SRC (body
), 0), 0)) == AND
)
6198 arm_current_cc
= ARM_INVERSE_CONDITION_CODE (arm_current_cc
);
6199 if (GET_CODE (XEXP (SET_SRC (body
), 0)) == NE
)
6200 arm_current_cc
= ARM_INVERSE_CONDITION_CODE (arm_current_cc
);
6204 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
6207 arm_current_cc
= get_arm_condition_code (XEXP (SET_SRC (body
),
6211 if (reverse
|| then_not_else
)
6212 arm_current_cc
= ARM_INVERSE_CONDITION_CODE (arm_current_cc
);
6214 /* restore recog_operand (getting the attributes of other insns can
6215 destroy this array, but final.c assumes that it remains intact
6216 across this call; since the insn has been recognized already we
6217 call recog direct). */
6218 recog (PATTERN (insn
), insn
, NULL_PTR
);
6222 #ifdef AOF_ASSEMBLER
6223 /* Special functions only needed when producing AOF syntax assembler. */
6225 rtx aof_pic_label
= NULL_RTX
;
6228 struct pic_chain
*next
;
6232 static struct pic_chain
*aof_pic_chain
= NULL
;
6238 struct pic_chain
**chainp
;
6241 if (aof_pic_label
== NULL_RTX
)
6243 /* This needs to persist throughout the compilation. */
6244 end_temporary_allocation ();
6245 aof_pic_label
= gen_rtx_SYMBOL_REF (Pmode
, "x$adcons");
6246 resume_temporary_allocation ();
6249 for (offset
= 0, chainp
= &aof_pic_chain
; *chainp
;
6250 offset
+= 4, chainp
= &(*chainp
)->next
)
6251 if ((*chainp
)->symname
== XSTR (x
, 0))
6252 return plus_constant (aof_pic_label
, offset
);
6254 *chainp
= (struct pic_chain
*) xmalloc (sizeof (struct pic_chain
));
6255 (*chainp
)->next
= NULL
;
6256 (*chainp
)->symname
= XSTR (x
, 0);
6257 return plus_constant (aof_pic_label
, offset
);
6261 aof_dump_pic_table (f
)
6264 struct pic_chain
*chain
;
6266 if (aof_pic_chain
== NULL
)
6269 fprintf (f
, "\tAREA |%s$$adcons|, BASED %s%s\n",
6270 reg_names
[PIC_OFFSET_TABLE_REGNUM
], REGISTER_PREFIX
,
6271 reg_names
[PIC_OFFSET_TABLE_REGNUM
]);
6272 fputs ("|x$adcons|\n", f
);
6274 for (chain
= aof_pic_chain
; chain
; chain
= chain
->next
)
6276 fputs ("\tDCD\t", f
);
6277 assemble_name (f
, chain
->symname
);
6282 int arm_text_section_count
= 1;
6287 static char buf
[100];
6288 sprintf (buf
, "\tAREA |C$$code%d|, CODE, READONLY",
6289 arm_text_section_count
++);
6291 strcat (buf
, ", PIC, REENTRANT");
6295 static int arm_data_section_count
= 1;
6300 static char buf
[100];
6301 sprintf (buf
, "\tAREA |C$$data%d|, DATA", arm_data_section_count
++);
6305 /* The AOF assembler is religiously strict about declarations of
6306 imported and exported symbols, so that it is impossible to declare
6307 a function as imported near the beginning of the file, and then to
6308 export it later on. It is, however, possible to delay the decision
6309 until all the functions in the file have been compiled. To get
6310 around this, we maintain a list of the imports and exports, and
6311 delete from it any that are subsequently defined. At the end of
6312 compilation we spit the remainder of the list out before the END
6317 struct import
*next
;
6321 static struct import
*imports_list
= NULL
;
6324 aof_add_import (name
)
6329 for (new = imports_list
; new; new = new->next
)
6330 if (new->name
== name
)
6333 new = (struct import
*) xmalloc (sizeof (struct import
));
6334 new->next
= imports_list
;
6340 aof_delete_import (name
)
6343 struct import
**old
;
6345 for (old
= &imports_list
; *old
; old
= & (*old
)->next
)
6347 if ((*old
)->name
== name
)
6349 *old
= (*old
)->next
;
6355 int arm_main_function
= 0;
6358 aof_dump_imports (f
)
6361 /* The AOF assembler needs this to cause the startup code to be extracted
6362 from the library. Brining in __main causes the whole thing to work
6364 if (arm_main_function
)
6367 fputs ("\tIMPORT __main\n", f
);
6368 fputs ("\tDCD __main\n", f
);
6371 /* Now dump the remaining imports. */
6372 while (imports_list
)
6374 fprintf (f
, "\tIMPORT\t");
6375 assemble_name (f
, imports_list
->name
);
6377 imports_list
= imports_list
->next
;
6380 #endif /* AOF_ASSEMBLER */